ml5.min.js 3.0 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ml5=e():t.ml5=e()}(window,function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:r})},n.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="/",n(n.s=693)}([function(t,e,n){"use strict";n.r(e),function(t,r,i,a){n.d(e,"AdadeltaOptimizer",function(){return Nd}),n.d(e,"AdagradOptimizer",function(){return Td}),n.d(e,"AdamOptimizer",function(){return Id}),n.d(e,"AdamaxOptimizer",function(){return Dd}),n.d(e,"Add",function(){return _r}),n.d(e,"AddN",function(){return Er}),n.d(e,"BroadcastTo",function(){return Ir}),n.d(e,"DataStorage",function(){return da}),n.d(e,"Div",function(){return Or}),n.d(e,"ENV",function(){return d}),n.d(e,"Environment",function(){return l}),n.d(e,"FromPixels",function(){return jr}),n.d(e,"FusedBatchNorm",function(){return Sr}),n.d(e,"Identity",function(){return Mr}),n.d(e,"KernelBackend",function(){return ha}),n.d(e,"MaxPoolWithArgmax",function(){return Pr}),n.d(e,"MomentumOptimizer",function(){return Rd}),n.d(e,"NonMaxSuppressionV5",function(){return Tr}),n.d(e,"OneHot",function(){return Dr}),n.d(e,"Optimizer",function(){return Ad}),n.d(e,"PadV2",function(){return Fr}),n.d(e,"RMSPropOptimizer",function(){return Fd}),n.d(e,"Rank",function(){return St}),n.d(e,"Reduction",function(){return pl}),n.d(e,"SGDOptimizer",function(){return Md}),n.d(e,"Square",function(){return Ar}),n.d(e,"SquaredDifference",function(){return Cr}),n.d(e,"Tensor",function(){return Ot}),n.d(e,"TensorBuffer",function(){return wt}),n.d(e,"Tile",function(){return Rr}),n.d(e,"Transpose",function(){return Nr}),n.d(e,"Variable",function(){return It}),n.d(e,"abs",function(){return Wr}),n.d(e,"acos",function(){return Vr}),n.d(e,"acosh",function(){return qr}),n.d(e,"add",function(){return Lr}),n.d(e,"addN",function(){return Ls}),n.d(e,"addStrict",function(){return ki}),n.d(e,"all",function(){return Mc}),n.d(e,"any",function(){return Rc}),n.d(e,"argMax",function(){return Fc}),n.d(e,"argMin",function(){return jc}),n.d(e,"asin",function(){return Hr}),n.d(e,"asinh",function(){return Gr}),n.d(e,"atan",function(){return $r}),n.d(e,"atan2",function(){return _i}),n.d(e,"atanh",function(){return Kr}),n.d(e,"avgPool",function(){return kc}),n.d(e,"avgPool3d",function(){return Oc}),n.d(e,"backend",function(){return mn}),n.d(e,"backend_util",function(){return Ta}),n.d(e,"basicLSTMCell",function(){return Zc}),n.d(e,"batchNorm",function(){return qs}),n.d(e,"batchNorm2d",function(){return $s}),n.d(e,"batchNorm3d",function(){return Ys}),n.d(e,"batchNorm4d",function(){return Qs}),n.d(e,"batchNormalization",function(){return Vs}),n.d(e,"batchNormalization2d",function(){return Gs}),n.d(e,"batchNormalization3d",function(){return Xs}),n.d(e,"batchNormalization4d",function(){return Zs}),n.d(e,"batchToSpaceND",function(){return sr}),n.d(e,"booleanMaskAsync",function(){return Yu}),n.d(e,"broadcastTo",function(){return tu}),n.d(e,"browser",function(){return wd}),n.d(e,"buffer",function(){return ar}),n.d(e,"cast",function(){return ur}),n.d(e,"ceil",function(){return Xr}),n.d(e,"clipByValue",function(){return Yr}),n.d(e,"clone",function(){return eu}),n.d(e,"complex",function(){return Mn}),n.d(e,"concat",function(){return Qn}),n.d(e,"concat1d",function(){return tr}),n.d(e,"concat2d",function(){return er}),n.d(e,"concat3d",function(){return nr}),n.d(e,"concat4d",function(){return rr}),n.d(e,"conv1d",function(){return tc}),n.d(e,"conv2d",function(){return ec}),n.d(e,"conv2dTranspose",function(){return cc}),n.d(e,"conv3d",function(){return nc}),n.d(e,"conv3dTranspose",function(){return lc}),n.d(e,"cos",function(){return Jr}),n.d(e,"cosh",function(){return Zr}),n.d(e,"cumsum",function(){return cr}),n.d(e,"customGrad",function(){return sa}),n.d(e,"deprecationWarn",function(){return Ze}),n.d(e,"depthToSpace",function(){return lr}),n.d(e,"depthwiseConv2d",function(){return ac}),n.d(e,"diag",function(){return fl}),n.d(e,"disableDeprecationWarnings",function(){return Je}),n.d(e,"dispose",function(){return an}),n.d(e,"disposeVariables",function(){return Qe}),n.d(e,"div",function(){return zi}),n.d(e,"divNoNan",function(){return uu}),n.d(e,"divStrict",function(){return Ei}),n.d(e,"dot",function(){return dc}),n.d(e,"dropout",function(){return dl}),n.d(e,"elu",function(){return qc}),n.d(e,"enableDebugMode",function(){return Ye}),n.d(e,"enableProdMode",function(){return Xe}),n.d(e,"engine",function(){return tn}),n.d(e,"env",function(){return f}),n.d(e,"equal",function(){return Ru}),n.d(e,"equalStrict",function(){return Fu}),n.d(e,"erf",function(){return Qr}),n.d(e,"exp",function(){return ti}),n.d(e,"expandDims",function(){return fr}),n.d(e,"expm1",function(){return ei}),n.d(e,"eye",function(){return lu}),n.d(e,"fft",function(){return il}),n.d(e,"fill",function(){return Kn}),n.d(e,"findBackend",function(){return dn}),n.d(e,"findBackendFactory",function(){return hn}),n.d(e,"floor",function(){return ni}),n.d(e,"floorDiv",function(){return Oi}),n.d(e,"frame",function(){return vl}),n.d(e,"fused",function(){return Yl}),n.d(e,"gather",function(){return Ku}),n.d(e,"gatherND",function(){return ll}),n.d(e,"gather_util",function(){return Ui}),n.d(e,"getBackend",function(){return ln}),n.d(e,"getGradient",function(){return g}),n.d(e,"getKernel",function(){return m}),n.d(e,"getKernelsForBackend",function(){return v}),n.d(e,"grad",function(){return na}),n.d(e,"grads",function(){return ra}),n.d(e,"greater",function(){return ju}),n.d(e,"greaterEqual",function(){return Pu}),n.d(e,"greaterEqualStrict",function(){return Lu}),n.d(e,"greaterStrict",function(){return zu}),n.d(e,"hammingWindow",function(){return gl}),n.d(e,"hannWindow",function(){return ml}),n.d(e,"ifft",function(){return al}),n.d(e,"imag",function(){return Fn}),n.d(e,"image",function(){return Wl}),n.d(e,"inTopKAsync",function(){return xl}),n.d(e,"io",function(){return vd}),n.d(e,"irfft",function(){return sl}),n.d(e,"isFinite",function(){return pi}),n.d(e,"isInf",function(){return hi}),n.d(e,"isNaN",function(){return di}),n.d(e,"keep",function(){return on}),n.d(e,"leakyRelu",function(){return Hc}),n.d(e,"less",function(){return Bu}),n.d(e,"lessEqual",function(){return Uu}),n.d(e,"lessEqualStrict",function(){return Wu}),n.d(e,"lessStrict",function(){return Vu}),n.d(e,"linalg",function(){return Fl}),n.d(e,"linspace",function(){return Xn}),n.d(e,"localResponseNormalization",function(){return Yc}),n.d(e,"log",function(){return ri}),n.d(e,"log1p",function(){return ii}),n.d(e,"logSigmoid",function(){return ai}),n.d(e,"logSoftmax",function(){return la}),n.d(e,"logSumExp",function(){return Pc}),n.d(e,"logicalAnd",function(){return nu}),n.d(e,"logicalNot",function(){return ru}),n.d(e,"logicalOr",function(){return iu}),n.d(e,"logicalXor",function(){return au}),n.d(e,"losses",function(){return Tl}),n.d(e,"matMul",function(){return fc}),n.d(e,"math",function(){return bd}),n.d(e,"max",function(){return Lc}),n.d(e,"maxPool",function(){return wc}),n.d(e,"maxPool3d",function(){return Ec}),n.d(e,"maxPoolWithArgmax",function(){return Sc}),n.d(e,"maximum",function(){return Si}),n.d(e,"maximumStrict",function(){return Ci}),n.d(e,"mean",function(){return zc}),n.d(e,"memory",function(){return en}),n.d(e,"min",function(){return Bc}),n.d(e,"minimum",function(){return Ai}),n.d(e,"minimumStrict",function(){return Ni}),n.d(e,"mod",function(){return Ti}),n.d(e,"modStrict",function(){return Ii}),n.d(e,"moments",function(){return Uc}),n.d(e,"movingAverage",function(){return tl}),n.d(e,"mul",function(){return Di}),n.d(e,"mulStrict",function(){return Mi}),n.d(e,"multiRNNCell",function(){return Qc}),n.d(e,"multinomial",function(){return fu}),n.d(e,"neg",function(){return oi}),n.d(e,"nextFrame",function(){return zd}),n.d(e,"norm",function(){return Jc}),n.d(e,"notEqual",function(){return qu}),n.d(e,"notEqualStrict",function(){return Hu}),n.d(e,"oneHot",function(){return du}),n.d(e,"ones",function(){return Gn}),n.d(e,"onesLike",function(){return Jn}),n.d(e,"op",function(){return Dn}),n.d(e,"outerProduct",function(){return hc}),n.d(e,"pad",function(){return hu}),n.d(e,"pad1d",function(){return pu}),n.d(e,"pad2d",function(){return mu}),n.d(e,"pad3d",function(){return gu}),n.d(e,"pad4d",function(){return vu}),n.d(e,"pool",function(){return _c}),n.d(e,"pow",function(){return Ri}),n.d(e,"powStrict",function(){return Fi}),n.d(e,"prelu",function(){return Gc}),n.d(e,"print",function(){return or}),n.d(e,"prod",function(){return Vc}),n.d(e,"profile",function(){return nn}),n.d(e,"rand",function(){return yu}),n.d(e,"randomGamma",function(){return Au}),n.d(e,"randomNormal",function(){return Nu}),n.d(e,"randomUniform",function(){return Tu}),n.d(e,"range",function(){return Yn}),n.d(e,"ready",function(){return cn}),n.d(e,"real",function(){return Rn}),n.d(e,"reciprocal",function(){return si}),n.d(e,"registerBackend",function(){return pn}),n.d(e,"registerGradient",function(){return b}),n.d(e,"registerKernel",function(){return y}),n.d(e,"relu",function(){return $c}),n.d(e,"relu6",function(){return Kc}),n.d(e,"removeBackend",function(){return fn}),n.d(e,"reshape",function(){return dr}),n.d(e,"reverse",function(){return pc}),n.d(e,"reverse1d",function(){return mc}),n.d(e,"reverse2d",function(){return gc}),n.d(e,"reverse3d",function(){return vc}),n.d(e,"reverse4d",function(){return yc}),n.d(e,"rfft",function(){return ol}),n.d(e,"round",function(){return ui}),n.d(e,"rsqrt",function(){return ci}),n.d(e,"scalar",function(){return Ln}),n.d(e,"scatterND",function(){return rl}),n.d(e,"scatter_util",function(){return $i}),n.d(e,"selu",function(){return Xc}),n.d(e,"separableConv2d",function(){return uc}),n.d(e,"serialization",function(){return Od}),n.d(e,"setBackend",function(){return un}),n.d(e,"setPlatform",function(){return gn}),n.d(e,"setdiff1dAsync",function(){return vr}),n.d(e,"sigmoid",function(){return li}),n.d(e,"sign",function(){return fi}),n.d(e,"signal",function(){return bl}),n.d(e,"sin",function(){return mi}),n.d(e,"sinh",function(){return gi}),n.d(e,"slice",function(){return Cc}),n.d(e,"slice1d",function(){return Ac}),n.d(e,"slice2d",function(){return Nc}),n.d(e,"slice3d",function(){return Tc}),n.d(e,"slice4d",function(){return Ic}),n.d(e,"slice_util",function(){return ea}),n.d(e,"softmax",function(){return ca}),n.d(e,"softplus",function(){return vi}),n.d(e,"spaceToBatchND",function(){return hr}),n.d(e,"sparseToDense",function(){return cl}),n.d(e,"spectral",function(){return ul}),n.d(e,"split",function(){return ir}),n.d(e,"sqrt",function(){return yi}),n.d(e,"square",function(){return Iu}),n.d(e,"squaredDifference",function(){return Du}),n.d(e,"squaredDifferenceStrict",function(){return ji}),n.d(e,"squeeze",function(){return pr}),n.d(e,"stack",function(){return mr}),n.d(e,"step",function(){return bi}),n.d(e,"stft",function(){return yl}),n.d(e,"stridedSlice",function(){return el}),n.d(e,"sub",function(){return Pi}),n.d(e,"subStrict",function(){return Li}),n.d(e,"sum",function(){return Wc}),n.d(e,"sumOutType",function(){return Rt}),n.d(e,"tan",function(){return xi}),n.d(e,"tanh",function(){return wi}),n.d(e,"tensor",function(){return jn}),n.d(e,"tensor1d",function(){return zn}),n.d(e,"tensor2d",function(){return Bn}),n.d(e,"tensor3d",function(){return Un}),n.d(e,"tensor4d",function(){return Wn}),n.d(e,"tensor5d",function(){return Vn}),n.d(e,"tensor6d",function(){return qn}),n.d(e,"tensor_util",function(){return zt}),n.d(e,"test_util",function(){return Eu}),n.d(e,"tidy",function(){return rn}),n.d(e,"tile",function(){return cu}),n.d(e,"time",function(){return sn}),n.d(e,"topk",function(){return nl}),n.d(e,"train",function(){return Pd}),n.d(e,"transpose",function(){return fa}),n.d(e,"truncatedNormal",function(){return Mu}),n.d(e,"unregisterGradient",function(){return w}),n.d(e,"unregisterKernel",function(){return x}),n.d(e,"unsortedSegmentSum",function(){return Xu}),n.d(e,"unstack",function(){return gr}),n.d(e,"util",function(){return dt}),n.d(e,"valueAndGrad",function(){return ia}),n.d(e,"valueAndGrads",function(){return aa}),n.d(e,"variable",function(){return Hn}),n.d(e,"variableGrads",function(){return oa}),n.d(e,"version_core",function(){return Sd}),n.d(e,"webgl",function(){return Cd}),n.d(e,"where",function(){return ou}),n.d(e,"whereAsync",function(){return su}),n.d(e,"zeros",function(){return $n}),n.d(e,"zerosLike",function(){return Zn});
  2. /**
  3. * @license
  4. * Copyright 2020 Google LLC. All Rights Reserved.
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. * =============================================================================
  17. */
  18. var o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function s(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function u(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})}function c(t,e){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=(i=o.trys).length>0&&i[i.length-1])&&(6===a[0]||2===a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}var l=function(){function t(t){this.global=t,this.flags={},this.flagRegistry={},this.urlFlags={},this.populateURLFlags()}return t.prototype.setPlatform=function(t,e){null!=this.platform&&console.warn("Platform "+this.platformName+" has already been set. Overwriting the platform with "+e+"."),this.platformName=t,this.platform=e},t.prototype.registerFlag=function(t,e,n){if(this.flagRegistry[t]={evaluationFn:e,setHook:n},null!=this.urlFlags[t]){var r=this.urlFlags[t];console.warn("Setting feature override from URL "+t+": "+r+"."),this.set(t,r)}},t.prototype.get=function(t){return t in this.flags?this.flags[t]:(this.flags[t]=this.evaluateFlag(t),this.flags[t])},t.prototype.getNumber=function(t){return this.get(t)},t.prototype.getBool=function(t){return this.get(t)},t.prototype.getFlags=function(){return this.flags},Object.defineProperty(t.prototype,"features",{get:function(){return this.flags},enumerable:!0,configurable:!0}),t.prototype.set=function(t,e){if(null==this.flagRegistry[t])throw new Error("Cannot set flag "+t+" as it has not been registered.");this.flags[t]=e,null!=this.flagRegistry[t].setHook&&this.flagRegistry[t].setHook(e)},t.prototype.evaluateFlag=function(t){if(null==this.flagRegistry[t])throw new Error("Cannot evaluate flag '"+t+"': no evaluation function found.");return this.flagRegistry[t].evaluationFn()},t.prototype.setFlags=function(t){this.flags=Object.assign({},t)},t.prototype.reset=function(){this.flags={},this.urlFlags={},this.populateURLFlags()},t.prototype.populateURLFlags=function(){var t=this;if(void 0!==this.global&&void 0!==this.global.location&&void 0!==this.global.location.search){var e,n,r=(e=this.global.location.search,n={},e.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g,function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];return function(t,e,n){t[decodeURIComponent(e)]=decodeURIComponent(n||"")}(n,e[0],e[1]),e.join("=")}),n);"tfjsflags"in r&&r.tfjsflags.split(",").forEach(function(e){var n=e.split(":"),r=n[0],i=n[1];t.urlFlags[r]=function(t,e){if("true"===(e=e.toLowerCase())||"false"===e)return"true"===e;if(""+ +e===e)return+e;throw new Error("Could not parse value flag value "+e+" for flag "+t+".")}(r,i)})}},t}();function f(){return d}var d=null,h=new Map,p=new Map;function m(t,e){var n=k(t,e);return h.get(n)}function g(t){return p.get(t)}function v(t){for(var e=h.entries(),n=[];;){var r=e.next(),i=r.done,a=r.value;if(i)break;var o=a[0],s=a[1];o.split("_")[0]===t&&n.push(s)}return n}function y(t){var e=t.kernelName,n=t.backendName,r=k(e,n);if(h.has(r))throw new Error("The kernel '"+e+"' for backend '"+n+"' is already registered");h.set(r,t)}function b(t){var e=t.kernelName;p.has(e)&&console.warn("Overriding the gradient for '"+e+"'"),p.set(e,t)}function x(t,e){var n=k(t,e);if(!h.has(n))throw new Error("The kernel '"+t+"' for backend '"+e+"' is not registered");h.delete(n)}function w(t){if(!p.has(t))throw new Error("The gradient '"+t+"' for backend is not registered");p.delete(t)}function k(t,e){return e+"_"+t}function _(t){for(var e=t.length,n=0,r=0;e>0;)r=Math.random()*e|0,n=t[--e],t[e]=t[r],t[r]=n}function E(t,e,n){return Math.max(t,Math.min(e,n))}function O(t){return t%2==0?t:t+1}function S(t){for(var e=0,n=0;n<t.length;n++)e+=t[n];return e}function C(t,e){if(!t)throw new Error("string"==typeof e?e:e())}function A(t,e,n){void 0===n&&(n=""),C(D(t,e),function(){return n+" Shapes "+t+" and "+e+" must match"})}function N(t){C(null!=t,function(){return"The input to the tensor constructor must be a non-null value."})}function T(t,e,n){if(void 0===e&&(e=[]),void 0===n&&(n=!1),null==e&&(e=[]),Array.isArray(t)||G(t)&&!n)for(var r=0;r<t.length;++r)T(t[r],e,n);else e.push(t);return e}function I(t){if(0===t.length)return 1;for(var e=t[0],n=1;n<t.length;n++)e*=t[n];return e}function D(t,e){if(t===e)return!0;if(null==t||null==e)return!1;if(t.length!==e.length)return!1;for(var n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}function M(t){return t%1==0}function R(t){if(null!=Math.tanh)return Math.tanh(t);if(t===1/0)return 1;if(t===-1/0)return-1;var e=Math.exp(2*t);return(e-1)/(e+1)}function F(t){var e=Math.ceil(Math.sqrt(t));return[e,Math.ceil(t/e)]}function j(t,e){return e<=t.length?t:t+" ".repeat(e-t.length)}function P(t,e,n){return void 0===e&&(e=function(t){return 0}),new Promise(function(r,i){var a=0,o=function(){if(t())r();else{var s=e(++a);null!=n&&a>=n?i():setTimeout(o,s)}};o()})}function L(t,e){for(var n=1,r=-1,i=0;i<t.length;++i)if(t[i]>=0)n*=t[i];else if(-1===t[i]){if(-1!==r)throw Error("Shapes can only have 1 implicit size. Found -1 at dim "+r+" and dim "+i);r=i}else if(t[i]<0)throw Error("Shapes can not be < 0. Found "+t[i]+" at dim "+i);if(-1===r){if(e>0&&e!==n)throw Error("Size("+e+") must match the product of shape "+t);return t}if(0===n)throw Error("Cannot infer the missing size in ["+t+"] when there are 0 elements");if(e%n!=0)throw Error("The implicit shape can't be a fractional number. Got "+e+" / "+n);var a=t.slice();return a[r]=e/n,a}function z(t,e){var n=e.length;return C((t=null==t?e.map(function(t,e){return e}):[].concat(t)).every(function(t){return t>=-n&&t<n}),function(){return"All values in axis param must be in range [-"+n+", "+n+") but got axis "+t}),C(t.every(function(t){return M(t)}),function(){return"All values in axis param must be integers but got axis "+t}),t.map(function(t){return t<0?n+t:t})}function B(t,e){for(var n=[],r=[],i=null!=e&&Array.isArray(e)&&0===e.length,a=null==e||i?null:z(e,t).sort(),o=0,s=0;s<t.length;++s){if(null!=a){if(a[o]===s&&1!==t[s])throw new Error("Can't squeeze axis "+s+" since its dim '"+t[s]+"' is not 1");(null==a[o]||a[o]>s)&&1===t[s]&&(n.push(t[s]),r.push(s)),a[o]<=s&&o++}1!==t[s]&&(n.push(t[s]),r.push(s))}return{newShape:n,keptDims:r}}function U(t,e){var n=null;if(null==t||"float32"===t)n=new Float32Array(e);else if("int32"===t)n=new Int32Array(e);else{if("bool"!==t)throw new Error("Unknown data type "+t);n=new Uint8Array(e)}return n}function W(t,e){var n=null;if(null==t||"float32"===t)n=new Float32Array(e);else if("int32"===t)n=new Int32Array(e);else if("bool"===t)n=new Uint8Array(e);else{if("string"!==t)throw new Error("Unknown data type "+t);n=new Array(e)}return n}function V(t,e){for(var n=0;n<t.length;n++){var r=t[n];if(isNaN(r)||!isFinite(r))throw Error("A tensor of type "+e+" being uploaded contains "+r+".")}}function q(t){return"bool"===t||"complex64"===t||"float32"===t||"int32"===t||"string"===t}function H(t,e){return!("complex64"===e||"float32"===e&&"complex64"!==t||"int32"===e&&"float32"!==t&&"complex64"!==t||"bool"===e&&"bool"===t)}function G(t){return t instanceof Float32Array||t instanceof Int32Array||t instanceof Uint8Array}function $(t){if("float32"===t||"int32"===t)return 4;if("complex64"===t)return 8;if("bool"===t)return 1;throw new Error("Unknown dtype "+t)}function K(t){if(null==t)return 0;var e=0;return t.forEach(function(t){return e+=t.length}),e}function X(t){return"string"==typeof t||t instanceof String}function Y(t){return"boolean"==typeof t}function J(t){return"number"==typeof t}function Z(t){return Array.isArray(t)?Z(t[0]):t instanceof Float32Array?"float32":t instanceof Int32Array||t instanceof Uint8Array?"int32":J(t)?"float32":X(t)?"string":Y(t)?"bool":"float32"}function Q(t){return!!(t&&t.constructor&&t.call&&t.apply)}function tt(t,e){for(var n=e;n<t;++n)if(t%n==0)return n;return t}function et(t){var e=t.length;if(e<2)return[];var n=new Array(e-1);n[e-2]=t[e-1];for(var r=e-3;r>=0;--r)n[r]=n[r+1]*t[r+1];return n}function nt(t,e,n){if("string"===e)throw new Error("Cannot convert a string[] to a TypedArray");if(Array.isArray(t)&&(t=T(t)),n&&V(t,e),function(t,e){return t instanceof Float32Array&&"float32"===e||t instanceof Int32Array&&"int32"===e||t instanceof Uint8Array&&"bool"===e}(t,e))return t;if(null==e||"float32"===e||"complex64"===e)return new Float32Array(t);if("int32"===e)return new Int32Array(t);if("bool"===e){for(var r=new Uint8Array(t.length),i=0;i<r.length;++i)0!==Math.round(t[i])&&(r[i]=1);return r}throw new Error("Unknown data type "+e)}function rt(t,e){if(0===t.length)return e[0];var n=t.reduce(function(t,e){return t*e});if(0===n)return[];if(n!==e.length)throw new Error("["+t+"] does not match the input size.");return function t(e,n,r){var i=new Array;if(1===n.length)for(var a=n[0],o=0;o<a;o++)i[o]=r[e+o];else{a=n[0];var s=n.slice(1),u=s.reduce(function(t,e){return t*e});for(o=0;o<a;o++)i[o]=t(e+o*u,s,r)}return i}(0,t,e)}function it(t,e){for(var n=at(t,e),r=0;r<n.length;r++)n[r]=1;return n}function at(t,e){if(null==e||"float32"===e||"complex64"===e)return new Float32Array(t);if("int32"===e)return new Int32Array(t);if("bool"===e)return new Uint8Array(t);throw new Error("Unknown data type "+e)}function ot(){return f().platform.now()}function st(t){t.forEach(function(e){C(Number.isInteger(e)&&e>=0,function(){return"Tensor must have a shape comprised of positive integers but got shape ["+t+"]."})})}function ut(t,e){return void 0===e&&(e="utf-8"),e=e||"utf-8",f().platform.encode(t,e)}function ct(t,e){return void 0===e&&(e="utf-8"),e=e||"utf-8",f().platform.decode(t,e)}function lt(t,e,n){if(0===e)return 0;if(1===e)return t[0];for(var r=t[t.length-1],i=0;i<t.length-1;++i)r+=n[i]*t[i];return r}function ft(t,e,n){if(0===e)return[];if(1===e)return[t];for(var r=new Array(e),i=0;i<r.length-1;++i)r[i]=Math.floor(t/n[i]),t-=r[i]*n[i];return r[r.length-1]=t,r}var dt=Object.freeze({shuffle:_,clamp:E,nearestLargerEven:O,sum:S,randUniform:function(t,e){var n=Math.random();return e*n+(1-n)*t},distSquared:function(t,e){for(var n=0,r=0;r<t.length;r++){var i=Number(t[r])-Number(e[r]);n+=i*i}return n},assert:C,assertShapesMatch:A,assertNonNull:N,flatten:T,sizeFromShape:I,isScalarShape:function(t){return 0===t.length},arraysEqual:D,isInt:M,tanh:R,sizeToSquarishShape:F,createShuffledIndices:function(t){for(var e=new Uint32Array(t),n=0;n<t;++n)e[n]=n;return _(e),e},rightPad:j,repeatedTry:P,inferFromImplicitShape:L,parseAxisParam:z,squeezeShape:B,getTypedArrayFromDType:U,getArrayFromDType:W,checkConversionForErrors:V,isValidDtype:q,hasEncodingLoss:H,isTypedArray:G,bytesPerElement:$,bytesFromStringArray:K,isString:X,isBoolean:Y,isNumber:J,inferDtype:Z,isFunction:Q,nearestDivisor:tt,computeStrides:et,toTypedArray:nt,toNestedArray:rt,makeOnesTypedArray:it,makeZerosTypedArray:at,now:ot,assertNonNegativeIntegerDimensions:st,fetch:function(t,e){return f().platform.fetch(t,e)},encodeString:ut,decodeString:ct,locToIndex:lt,indexToLoc:ft}),ht=function(){function t(t,e){this.backendTimer=t,this.logger=e,null==e&&(this.logger=new pt)}return t.prototype.profileKernel=function(t,e,n){var r,i=this,a=this.backendTimer.time(function(){r=n()});return r.forEach(function(n){n.data().then(function(r){!function(t,e,n){if("float32"!==e)return!1;for(var r=0;r<t.length;r++){var i=t[r];if(isNaN(i)||!isFinite(i))return console.warn("Found "+i+" in the result of '"+n+"'"),!0}}(r,n.dtype,t),a.then(function(a){var o="";null!=a.getExtraProfileInfo&&(o=a.getExtraProfileInfo()),i.logger.logKernelProfile(t,n,r,a.kernelMs,e,o)})})}),r},t}(),pt=function(){function t(){}return t.prototype.logKernelProfile=function(t,e,n,r,i,a){var o="number"==typeof r?j(r+"ms",9):r.error,s=j(t,25),u=e.rank,c=e.size,l=j(e.shape.toString(),14),f="";for(var d in i){var h=i[d].shape||e.shape,p=h.length;f+=d+": "+p+"D "+(p>0?h:"")+" "}console.log("%c"+s+"\t%c"+o+"\t%c"+u+"D "+l+"\t%c"+c+"\t%c"+f+"\t%c"+a,"font-weight:bold","color:red","color:blue","color: orange","color: green","color: steelblue")},t}(),mt=20,gt=3,vt=7;function yt(t,e,n){return j(Array.isArray(t)?parseFloat(t[0].toFixed(vt))+" + "+parseFloat(t[1].toFixed(vt))+"j":X(t)?"'"+t+"'":"bool"===n?bt(t):parseFloat(t.toFixed(vt)).toString(),e)}function bt(t){return 0===t?"false":"true"}function xt(t){for(var e=[],n=0;n<t.length;n+=2)e.push([t[n],t[n+1]]);return e}var wt=function(){function t(t,e,n){var r=this;if(this.dtype=e,this.shape=t.slice(),this.size=I(t),null!=n){var i=n.length;C(i===this.size,function(){return"Length of values '"+i+"' does not match the size inferred by the shape '"+r.size+"'."})}if("complex64"===e)throw new Error("complex64 dtype TensorBuffers are not supported. Please create a TensorBuffer for the real and imaginary parts separately and call tf.complex(real, imag).");this.values=n||W(e,this.size),this.strides=et(t)}return t.prototype.set=function(t){for(var e=this,n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];0===n.length&&(n=[0]),C(n.length===this.rank,function(){return"The number of provided coordinates ("+n.length+") must match the rank ("+e.rank+")"});var i=this.locToIndex(n);this.values[i]=t},t.prototype.get=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];0===t.length&&(t=[0]);for(var n=0,r=0,i=t;r<i.length;r++){var a=i[r];if(a<0||a>=this.shape[n]){var o="Requested out of range element at "+t+". Buffer shape="+this.shape;throw new Error(o)}n++}for(var s=t[t.length-1],u=0;u<t.length-1;++u)s+=this.strides[u]*t[u];return this.values[s]},t.prototype.locToIndex=function(t){if(0===this.rank)return 0;if(1===this.rank)return t[0];for(var e=t[t.length-1],n=0;n<t.length-1;++n)e+=this.strides[n]*t[n];return e},t.prototype.indexToLoc=function(t){if(0===this.rank)return[];if(1===this.rank)return[t];for(var e=new Array(this.shape.length),n=0;n<e.length-1;++n)e[n]=Math.floor(t/this.strides[n]),t-=e[n]*this.strides[n];return e[e.length-1]=t,e},Object.defineProperty(t.prototype,"rank",{get:function(){return this.shape.length},enumerable:!0,configurable:!0}),t.prototype.toTensor=function(){return kt().makeTensor(this.values,this.shape,this.dtype)},t}(),kt=null,_t=null,Et=null,Ot=function(){function t(t,e,n,r){this.kept=!1,this.isDisposedInternal=!1,this.shape=t.slice(),this.dtype=e||"float32",this.size=I(t),this.strides=et(t),this.dataId=n,this.id=r,this.rankType=this.rank<5?this.rank.toString():"higher"}return t.prototype.flatten=function(){return this.throwIfDisposed(),this.as1D()},t.prototype.asScalar=function(){return this.throwIfDisposed(),C(1===this.size,function(){return"The array must have only 1 element."}),this.reshape([])},t.prototype.as1D=function(){return this.throwIfDisposed(),this.reshape([this.size])},t.prototype.as2D=function(t,e){return this.throwIfDisposed(),this.reshape([t,e])},t.prototype.as3D=function(t,e,n){return this.throwIfDisposed(),this.reshape([t,e,n])},t.prototype.as4D=function(t,e,n,r){return this.throwIfDisposed(),this.reshape([t,e,n,r])},t.prototype.as5D=function(t,e,n,r,i){return this.throwIfDisposed(),this.reshape([t,e,n,r,i])},t.prototype.asType=function(t){return this.throwIfDisposed(),_t.cast(this,t)},Object.defineProperty(t.prototype,"rank",{get:function(){return this.shape.length},enumerable:!0,configurable:!0}),t.prototype.buffer=function(){return u(this,void 0,void 0,function(){var t;return c(this,function(e){switch(e.label){case 0:return[4,this.data()];case 1:return t=e.sent(),[2,_t.buffer(this.shape,this.dtype,t)]}})})},t.prototype.bufferSync=function(){return _t.buffer(this.shape,this.dtype,this.dataSync())},t.prototype.array=function(){return u(this,void 0,void 0,function(){var t;return c(this,function(e){switch(e.label){case 0:return[4,this.data()];case 1:return t=e.sent(),[2,rt(this.shape,t)]}})})},t.prototype.arraySync=function(){return rt(this.shape,this.dataSync())},t.prototype.data=function(){return u(this,void 0,void 0,function(){var t,e;return c(this,function(n){switch(n.label){case 0:return this.throwIfDisposed(),t=kt().read(this.dataId),"string"!==this.dtype?[3,2]:[4,t];case 1:e=n.sent();try{return[2,e.map(function(t){return ct(t)})]}catch(t){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}n.label=2;case 2:return[2,t]}})})},t.prototype.dataSync=function(){this.throwIfDisposed();var t=kt().readSync(this.dataId);if("string"===this.dtype)try{return t.map(function(t){return ct(t)})}catch(t){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}return t},t.prototype.bytes=function(){return u(this,void 0,void 0,function(){var t;return c(this,function(e){switch(e.label){case 0:return this.throwIfDisposed(),[4,kt().read(this.dataId)];case 1:return t=e.sent(),"string"===this.dtype?[2,t]:[2,new Uint8Array(t.buffer)]}})})},t.prototype.dispose=function(){this.isDisposed||(kt().disposeTensor(this),this.isDisposedInternal=!0)},Object.defineProperty(t.prototype,"isDisposed",{get:function(){return this.isDisposedInternal},enumerable:!0,configurable:!0}),t.prototype.throwIfDisposed=function(){if(this.isDisposed)throw new Error("Tensor is disposed.")},t.prototype.toFloat=function(){return this.asType("float32")},t.prototype.toInt=function(){return this.asType("int32")},t.prototype.toBool=function(){return this.asType("bool")},t.prototype.print=function(t){return void 0===t&&(t=!1),_t.print(this,t)},t.prototype.reshape=function(t){return this.throwIfDisposed(),_t.reshape(this,t)},t.prototype.reshapeAs=function(t){return this.throwIfDisposed(),this.reshape(t.shape)},t.prototype.expandDims=function(t){return void 0===t&&(t=0),_t.expandDims(this,t)},t.prototype.cumsum=function(t,e,n){return void 0===t&&(t=0),void 0===e&&(e=!1),void 0===n&&(n=!1),_t.cumsum(this,t,e,n)},t.prototype.squeeze=function(t){return this.throwIfDisposed(),_t.squeeze(this,t)},t.prototype.clone=function(){return this.throwIfDisposed(),_t.clone(this)},t.prototype.toString=function(t){return void 0===t&&(t=!1),function(t,e,n,r){var i=et(e),a=function(t,e,n,r){var i=I(e),a=r[r.length-1],o=new Array(a).fill(0),s=e.length,u="complex64"===n?xt(t):t;if(s>1)for(var c=0;c<i/a;c++)for(var l=c*a,f=0;f<a;f++)o[f]=Math.max(o[f],yt(u[l+f],0,n).length);return o}(t,e,n,i),o=e.length,s=function t(e,n,r,i,a,o){void 0===o&&(o=!0);var s="complex64"===r?2:1,u=n[0],c=n.length;if(0===c)return"complex64"===r?[yt(xt(e)[0],0,r)]:"bool"===r?[bt(e[0])]:[e[0].toString()];if(1===c){if(u>mt){var l=gt*s,f=Array.from(e.slice(0,l)),d=Array.from(e.slice((u-gt)*s,u*s));return"complex64"===r&&(f=xt(f),d=xt(d)),["["+f.map(function(t,e){return yt(t,a[e],r)}).join(", ")+", ..., "+d.map(function(t,e){return yt(t,a[u-gt+e],r)}).join(", ")+"]"]}return["["+("complex64"===r?xt(e):Array.from(e)).map(function(t,e){return yt(t,a[e],r)}).join(", ")+"]"]}var h=n.slice(1),p=i.slice(1),m=i[0]*s,g=[];if(u>mt){for(var v=0;v<gt;v++){var y=(b=v*m)+m;g.push.apply(g,t(e.slice(b,y),h,r,p,a,!1))}for(g.push("..."),v=u-gt;v<u;v++)y=(b=v*m)+m,g.push.apply(g,t(e.slice(b,y),h,r,p,a,v===u-1))}else for(v=0;v<u;v++){var b;y=(b=v*m)+m,g.push.apply(g,t(e.slice(b,y),h,r,p,a,v===u-1))}var x=2===c?",":"";for(g[0]="["+g[0]+x,v=1;v<g.length-1;v++)g[v]=" "+g[v]+x;var w=",\n";for(v=2;v<c;v++)w+="\n";return g[g.length-1]=" "+g[g.length-1]+"]"+(o?"":w),g}(t,e,n,i,a),u=["Tensor"];return r&&(u.push(" dtype: "+n),u.push(" rank: "+o),u.push(" shape: ["+e+"]"),u.push(" values:")),u.push(s.map(function(t){return" "+t}).join("\n")),u.join("\n")}(this.dataSync(),this.shape,this.dtype,t)},t.prototype.gather=function(t,e){return void 0===e&&(e=0),this.throwIfDisposed(),_t.gather(this,t,e)},t.prototype.matMul=function(t,e,n){return void 0===e&&(e=!1),void 0===n&&(n=!1),this.throwIfDisposed(),_t.matMul(this,t,e,n)},t.prototype.dot=function(t){return this.throwIfDisposed(),_t.dot(this,t)},t.prototype.norm=function(t,e,n){return void 0===t&&(t="euclidean"),void 0===e&&(e=null),void 0===n&&(n=!1),this.throwIfDisposed(),_t.norm(this,t,e,n)},t.prototype.slice=function(t,e){return this.throwIfDisposed(),_t.slice(this,t,e)},t.prototype.reverse=function(t){return this.throwIfDisposed(),_t.reverse(this,t)},t.prototype.concat=function(e,n){return void 0===n&&(n=0),this.throwIfDisposed(),e instanceof t&&(e=[e]),_t.concat([this].concat(e),n)},t.prototype.split=function(t,e){return void 0===e&&(e=0),this.throwIfDisposed(),_t.split(this,t,e)},t.prototype.stack=function(t,e){return void 0===e&&(e=0),_t.stack([this,t],e)},t.prototype.unstack=function(t){return void 0===t&&(t=0),_t.unstack(this,t)},t.prototype.batchNormalization=function(t,e,n,r,i){return void 0===n&&(n=.001),Et("tf.batchNormalization() is going away. Use tf.batchNorm() instead, and note the positional argument change of scale, offset, and varianceEpsilon"),this.batchNorm(t,e,i,r,n)},t.prototype.all=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),_t.all(this,t,e)},t.prototype.any=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),_t.any(this,t,e)},t.prototype.logSumExp=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),_t.logSumExp(this,t,e)},t.prototype.sum=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),_t.sum(this,t,e)},t.prototype.prod=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),_t.prod(this,t,e)},t.prototype.mean=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),_t.mean(this,t,e)},t.prototype.min=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),_t.min(this,t,e)},t.prototype.max=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),_t.max(this,t,e)},t.prototype.argMin=function(t){return void 0===t&&(t=null),this.throwIfDisposed(),_t.argMin(this,t)},t.prototype.argMax=function(t){return void 0===t&&(t=null),this.throwIfDisposed(),_t.argMax(this,t)},t.prototype.cast=function(t){return this.throwIfDisposed(),_t.cast(this,t)},t.prototype.addStrict=function(t){return this.throwIfDisposed(),_t.addStrict(this,t)},t.prototype.atan2=function(t){return this.throwIfDisposed(),_t.atan2(this,t)},t.prototype.sub=function(t){return this.throwIfDisposed(),_t.sub(this,t)},t.prototype.subStrict=function(t){return this.throwIfDisposed(),_t.subStrict(this,t)},t.prototype.pow=function(t){return this.throwIfDisposed(),_t.pow(this,t)},t.prototype.powStrict=function(t){return this.throwIfDisposed(),_t.powStrict(this,t)},t.prototype.mul=function(t){return this.throwIfDisposed(),_t.mul(this,t)},t.prototype.mulStrict=function(t){return this.throwIfDisposed(),_t.mulStrict(this,t)},t.prototype.floorDiv=function(t){return this.throwIfDisposed(),_t.floorDiv(this,t)},t.prototype.divStrict=function(t){return this.throwIfDisposed(),_t.divStrict(this,t)},t.prototype.minimum=function(t){return this.throwIfDisposed(),_t.minimum(this,t)},t.prototype.minimumStrict=function(t){return this.throwIfDisposed(),_t.minimumStrict(this,t)},t.prototype.maximum=function(t){return this.throwIfDisposed(),_t.maximum(this,t)},t.prototype.maximumStrict=function(t){return this.throwIfDisposed(),_t.maximumStrict(this,t)},t.prototype.mod=function(t){return this.throwIfDisposed(),_t.mod(this,t)},t.prototype.modStrict=function(t){return this.throwIfDisposed(),_t.modStrict(this,t)},t.prototype.squaredDifferenceStrict=function(t){return this.throwIfDisposed(),_t.squaredDifferenceStrict(this,t)},t.prototype.notEqual=function(t){return this.throwIfDisposed(),_t.notEqual(this,t)},t.prototype.notEqualStrict=function(t){return this.throwIfDisposed(),_t.notEqualStrict(this,t)},t.prototype.less=function(t){return this.throwIfDisposed(),_t.less(this,t)},t.prototype.lessStrict=function(t){return this.throwIfDisposed(),_t.lessStrict(this,t)},t.prototype.equal=function(t){return this.throwIfDisposed(),_t.equal(this,t)},t.prototype.equalStrict=function(t){return this.throwIfDisposed(),_t.equalStrict(this,t)},t.prototype.lessEqual=function(t){return this.throwIfDisposed(),_t.lessEqual(this,t)},t.prototype.lessEqualStrict=function(t){return this.throwIfDisposed(),_t.lessEqualStrict(this,t)},t.prototype.greater=function(t){return this.throwIfDisposed(),_t.greater(this,t)},t.prototype.greaterStrict=function(t){return this.throwIfDisposed(),_t.greaterStrict(this,t)},t.prototype.greaterEqual=function(t){return this.throwIfDisposed(),_t.greaterEqual(this,t)},t.prototype.greaterEqualStrict=function(t){return this.throwIfDisposed(),_t.greaterEqualStrict(this,t)},t.prototype.logicalAnd=function(t){return this.throwIfDisposed(),_t.logicalAnd(this,t)},t.prototype.logicalOr=function(t){return this.throwIfDisposed(),_t.logicalOr(this,t)},t.prototype.logicalNot=function(){return this.throwIfDisposed(),_t.logicalNot(this)},t.prototype.logicalXor=function(t){return this.throwIfDisposed(),_t.logicalXor(this,t)},t.prototype.where=function(t,e){return this.throwIfDisposed(),_t.where(t,this,e)},t.prototype.neg=function(){return this.throwIfDisposed(),_t.neg(this)},t.prototype.ceil=function(){return this.throwIfDisposed(),_t.ceil(this)},t.prototype.floor=function(){return this.throwIfDisposed(),_t.floor(this)},t.prototype.sign=function(){return this.throwIfDisposed(),_t.sign(this)},t.prototype.isNaN=function(){return this.throwIfDisposed(),_t.isNaN(this)},t.prototype.isInf=function(){return this.throwIfDisposed(),_t.isInf(this)},t.prototype.isFinite=function(){return this.throwIfDisposed(),_t.isFinite(this)},t.prototype.exp=function(){return this.throwIfDisposed(),_t.exp(this)},t.prototype.expm1=function(){return this.throwIfDisposed(),_t.expm1(this)},t.prototype.log=function(){return this.throwIfDisposed(),_t.log(this)},t.prototype.log1p=function(){return this.throwIfDisposed(),_t.log1p(this)},t.prototype.sqrt=function(){return this.throwIfDisposed(),_t.sqrt(this)},t.prototype.rsqrt=function(){return this.throwIfDisposed(),_t.rsqrt(this)},t.prototype.square=function(){return this.throwIfDisposed(),_t.square(this)},t.prototype.reciprocal=function(){return this.throwIfDisposed(),_t.reciprocal(this)},t.prototype.abs=function(){return this.throwIfDisposed(),_t.abs(this)},t.prototype.clipByValue=function(t,e){return this.throwIfDisposed(),_t.clipByValue(this,t,e)},t.prototype.relu=function(){return this.throwIfDisposed(),_t.relu(this)},t.prototype.relu6=function(){return this.throwIfDisposed(),_t.relu6(this)},t.prototype.elu=function(){return this.throwIfDisposed(),_t.elu(this)},t.prototype.selu=function(){return this.throwIfDisposed(),_t.selu(this)},t.prototype.leakyRelu=function(t){return void 0===t&&(t=.2),this.throwIfDisposed(),_t.leakyRelu(this,t)},t.prototype.prelu=function(t){return this.throwIfDisposed(),_t.prelu(this,t)},t.prototype.sigmoid=function(){return this.throwIfDisposed(),_t.sigmoid(this)},t.prototype.logSigmoid=function(){return this.throwIfDisposed(),_t.logSigmoid(this)},t.prototype.softplus=function(){return this.throwIfDisposed(),_t.softplus(this)},t.prototype.zerosLike=function(){return this.throwIfDisposed(),_t.zerosLike(this)},t.prototype.onesLike=function(){return this.throwIfDisposed(),_t.onesLike(this)},t.prototype.sin=function(){return this.throwIfDisposed(),_t.sin(this)},t.prototype.cos=function(){return this.throwIfDisposed(),_t.cos(this)},t.prototype.tan=function(){return this.throwIfDisposed(),_t.tan(this)},t.prototype.asin=function(){return this.throwIfDisposed(),_t.asin(this)},t.prototype.acos=function(){return this.throwIfDisposed(),_t.acos(this)},t.prototype.atan=function(){return this.throwIfDisposed(),_t.atan(this)},t.prototype.sinh=function(){return this.throwIfDisposed(),_t.sinh(this)},t.prototype.cosh=function(){return this.throwIfDisposed(),_t.cosh(this)},t.prototype.tanh=function(){return this.throwIfDisposed(),_t.tanh(this)},t.prototype.asinh=function(){return this.throwIfDisposed(),_t.asinh(this)},t.prototype.acosh=function(){return this.throwIfDisposed(),_t.acosh(this)},t.prototype.atanh=function(){return this.throwIfDisposed(),_t.atanh(this)},t.prototype.erf=function(){return this.throwIfDisposed(),_t.erf(this)},t.prototype.round=function(){return this.throwIfDisposed(),_t.round(this)},t.prototype.step=function(t){return void 0===t&&(t=0),this.throwIfDisposed(),_t.step(this,t)},t.prototype.softmax=function(t){return void 0===t&&(t=-1),this.throwIfDisposed(),_t.softmax(this,t)},t.prototype.logSoftmax=function(t){return void 0===t&&(t=-1),this.throwIfDisposed(),_t.logSoftmax(this,t)},t.prototype.resizeBilinear=function(t,e){return void 0===e&&(e=!1),this.throwIfDisposed(),_t.image.resizeBilinear(this,t,e)},t.prototype.resizeNearestNeighbor=function(t,e){return void 0===e&&(e=!1),this.throwIfDisposed(),_t.image.resizeNearestNeighbor(this,t,e)},t.prototype.conv1d=function(t,e,n,r,i,a){return void 0===r&&(r="NWC"),void 0===i&&(i=1),this.throwIfDisposed(),_t.conv1d(this,t,e,n,r,i,a)},t.prototype.conv2d=function(t,e,n,r,i,a){return void 0===r&&(r="NHWC"),void 0===i&&(i=[1,1]),this.throwIfDisposed(),_t.conv2d(this,t,e,n,r,i,a)},t.prototype.conv2dTranspose=function(t,e,n,r,i){return this.throwIfDisposed(),_t.conv2dTranspose(this,t,e,n,r,i)},t.prototype.depthwiseConv2D=function(t,e,n,r,i,a){return void 0===r&&(r="NHWC"),void 0===i&&(i=[1,1]),this.throwIfDisposed(),_t.depthwiseConv2d(this,t,e,n,r,i,a)},t.prototype.separableConv2d=function(t,e,n,r,i,a){return void 0===i&&(i=[1,1]),void 0===a&&(a="NHWC"),this.throwIfDisposed(),_t.separableConv2d(this,t,e,n,r,i,a)},t.prototype.avgPool=function(t,e,n,r){return this.throwIfDisposed(),_t.avgPool(this,t,e,n,r)},t.prototype.maxPool=function(t,e,n,r){return this.throwIfDisposed(),_t.maxPool(this,t,e,n,r)},t.prototype.localResponseNormalization=function(t,e,n,r){return void 0===t&&(t=5),void 0===e&&(e=1),void 0===n&&(n=1),void 0===r&&(r=.5),_t.localResponseNormalization(this,t,e,n,r)},t.prototype.pool=function(t,e,n,r,i){return this.throwIfDisposed(),_t.pool(this,t,e,n,r,i)},t.prototype.variable=function(t,e,n){return void 0===t&&(t=!0),this.throwIfDisposed(),kt().makeVariable(this,t,e,n)},t.prototype.unsortedSegmentSum=function(t,e){return this.throwIfDisposed(),_t.unsortedSegmentSum(this,t,e)},t.prototype.batchToSpaceND=function(t,e){return this.throwIfDisposed(),_t.batchToSpaceND(this,t,e)},t.prototype.spaceToBatchND=function(t,e){return this.throwIfDisposed(),_t.spaceToBatchND(this,t,e)},t.prototype.topk=function(t,e){return void 0===t&&(t=1),void 0===e&&(e=!0),this.throwIfDisposed(),_t.topk(this,t,e)},t.prototype.stridedSlice=function(t,e,n,r,i,a,o,s){return void 0===r&&(r=0),void 0===i&&(i=0),void 0===a&&(a=0),void 0===o&&(o=0),void 0===s&&(s=0),this.throwIfDisposed(),_t.stridedSlice(this,t,e,n,r,i,a,o,s)},t.prototype.depthToSpace=function(t,e){return this.throwIfDisposed(),_t.depthToSpace(this,t,e)},t.prototype.fft=function(){return this.throwIfDisposed(),_t.spectral.fft(this)},t.prototype.ifft=function(){return this.throwIfDisposed(),_t.spectral.ifft(this)},t.prototype.rfft=function(){return this.throwIfDisposed(),_t.spectral.rfft(this)},t.prototype.irfft=function(){return this.throwIfDisposed(),_t.spectral.irfft(this)},t}();Object.defineProperty(Ot,Symbol.hasInstance,{value:function(t){return!!t&&null!=t.dataId&&null!=t.shape&&null!=t.dtype}});var St,Ct,At,Nt,Tt,It=function(t){function e(e,n,r,i){var a=t.call(this,e.shape,e.dtype,e.dataId,i)||this;return a.trainable=n,a.name=r,a}return s(e,t),e.prototype.assign=function(t){if(t.dtype!==this.dtype)throw new Error("dtype of the new value ("+t.dtype+") and previous value ("+this.dtype+") must match");if(!D(t.shape,this.shape))throw new Error("shape of the new value ("+t.shape+") and previous value ("+this.shape+") must match");kt().disposeTensor(this),this.dataId=t.dataId,kt().incRef(this,null)},e.prototype.dispose=function(){kt().disposeVariable(this),this.isDisposedInternal=!0},e}(Ot);Object.defineProperty(It,Symbol.hasInstance,{value:function(t){return t instanceof Ot&&null!=t.assign&&t.assign instanceof Function}}),function(t){t.R0="R0",t.R1="R1",t.R2="R2",t.R3="R3",t.R4="R4",t.R5="R5",t.R6="R6"}(St||(St={})),function(t){t.float32="float32",t.int32="int32",t.bool="int32",t.complex64="complex64"}(Ct||(Ct={})),function(t){t.float32="float32",t.int32="int32",t.bool="bool",t.complex64="complex64"}(At||(At={})),function(t){t.float32="float32",t.int32="float32",t.bool="float32",t.complex64="complex64"}(Nt||(Nt={})),function(t){t.float32="complex64",t.int32="complex64",t.bool="complex64",t.complex64="complex64"}(Tt||(Tt={}));var Dt={float32:Nt,int32:Ct,bool:At,complex64:Tt};function Mt(t,e){if("string"===t||"string"===e){if("string"===t&&"string"===e)return"string";throw new Error("Can not upcast "+t+" with "+e)}return Dt[t][e]}function Rt(t){return Mt(t,"int32")}function Ft(t,e){if(t.dtype===e.dtype)return[t,e];var n=Mt(t.dtype,e.dtype);return[t.cast(n),e.cast(n)]}function jt(t,e){C(t.dtype===e.dtype,function(){return"The dtypes of the first("+t.dtype+") and second("+e.dtype+") input must match"})}function Pt(t){var e=[];return function t(e,n,r){if(null!=e)if(e instanceof Ot)n.push(e);else if(i=e,Array.isArray(i)||"object"==typeof i){var i,a=e;for(var o in a){var s=a[o];r.has(s)||(r.add(s),t(s,n,r))}}}(t,e,new Set),e}var Lt,zt=Object.freeze({makeTypesMatch:Ft,assertTypesMatch:jt,isTensorInList:function(t,e){return e.some(function(e){return e.id===t.id})},getTensorsInContainer:Pt}),Bt=function(){function t(){this.registeredVariables={},this.nextTapeNodeId=0,this.numBytes=0,this.numTensors=0,this.numStringTensors=0,this.numDataBuffers=0,this.gradientDepth=0,this.kernelDepth=0,this.scopeStack=[],this.numDataMovesStack=[],this.nextScopeId=0,this.tensorInfo=new WeakMap,this.profiling=!1,this.activeProfile={newBytes:0,newTensors:0,peakBytes:0,kernels:[],result:null}}return t.prototype.dispose=function(){for(var t in this.registeredVariables)this.registeredVariables[t].dispose()},t}(),Ut=function(){function t(t){this.ENV=t,this.registry={},this.registryFactory={},this.pendingBackendInitId=0,this.state=new Bt}return t.prototype.ready=function(){return u(this,void 0,void 0,function(){var t,e,n;return c(this,function(r){switch(r.label){case 0:if(null!=this.pendingBackendInit)return[2,this.pendingBackendInit.then(function(){})];if(null!=this.backendInstance)return[2];t=this.getSortedBackends(),e=0,r.label=1;case 1:return e<t.length?(n=t[e],[4,this.initializeBackend(n).success]):[3,5];case 2:return r.sent()?[4,this.setBackend(n)]:[3,4];case 3:return r.sent(),[2];case 4:return e++,[3,1];case 5:throw new Error("Could not initialize any backends, all backend initializations failed.")}})})},Object.defineProperty(t.prototype,"backend",{get:function(){if(null!=this.pendingBackendInit)throw new Error("Backend '"+this.backendName+"' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods");if(null==this.backendInstance){var t=this.initializeBackendsAndReturnBest(),e=t.name;if(t.asyncInit)throw new Error("The highest priority backend '"+e+"' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods");this.setBackend(e)}return this.backendInstance},enumerable:!0,configurable:!0}),t.prototype.backendNames=function(){return Object.keys(this.registryFactory)},t.prototype.findBackend=function(t){if(!(t in this.registry)){if(!(t in this.registryFactory))return null;if(this.initializeBackend(t).asyncInit)return null}return this.registry[t]},t.prototype.findBackendFactory=function(t){return t in this.registryFactory?this.registryFactory[t].factory:null},t.prototype.registerBackend=function(t,e,n){return void 0===n&&(n=1),t in this.registryFactory?(console.warn(t+" backend was already registered. Reusing existing backend factory."),!1):(this.registryFactory[t]={factory:e,priority:n},!0)},t.prototype.setBackend=function(t){return u(this,void 0,void 0,function(){var e,n,r;return c(this,function(i){switch(i.label){case 0:if(null==this.registryFactory[t])throw new Error("Backend name '"+t+"' not found in registry");return this.backendName=t,null!=this.registry[t]?[3,4]:(this.backendInstance=null,e=this.initializeBackend(t),n=e.success,e.asyncInit?[4,n]:[3,2]);case 1:return r=i.sent(),[3,3];case 2:r=n,i.label=3;case 3:if(!r)return[2,!1];i.label=4;case 4:return this.backendInstance=this.registry[t],this.setupRegisteredKernels(),this.profiler=new ht(this.backendInstance),[2,!0]}})})},t.prototype.setupRegisteredKernels=function(){var t=this;v(this.backendName).forEach(function(e){null!=e.setupFunc&&e.setupFunc(t.backendInstance)})},t.prototype.disposeRegisteredKernels=function(t){var e=this;v(t).forEach(function(n){null!=n.disposeFunc&&n.disposeFunc(e.registry[t])})},t.prototype.initializeBackend=function(t){var e=this,n=this.registryFactory[t];if(null==n)throw new Error("Cannot initialize backend "+t+", no registration found.");try{var r=n.factory();if(Promise.resolve(r)===r){var i=++this.pendingBackendInitId,a=r.then(function(n){return!(i<e.pendingBackendInitId||(e.registry[t]=n,e.pendingBackendInit=null,0))}).catch(function(n){return!(i<e.pendingBackendInitId||(e.pendingBackendInit=null,console.warn("Initialization of backend "+t+" failed"),console.warn(n.stack||n.message),1))});return this.pendingBackendInit=a,{success:a,asyncInit:!0}}return this.registry[t]=r,{success:!0,asyncInit:!1}}catch(e){return console.warn("Initialization of backend "+t+" failed"),console.warn(e.stack||e.message),{success:!1,asyncInit:!1}}},t.prototype.removeBackend=function(t){if(!(t in this.registryFactory))throw new Error(t+" backend not found in registry");this.backendName===t&&null!=this.pendingBackendInit&&this.pendingBackendInitId++,t in this.registry&&(this.disposeRegisteredKernels(t),this.registry[t].dispose(),delete this.registry[t]),delete this.registryFactory[t],this.backendName===t&&(this.pendingBackendInit=null,this.backendName=null,this.backendInstance=null)},t.prototype.getSortedBackends=function(){var t=this;if(0===Object.keys(this.registryFactory).length)throw new Error("No backend found in registry.");return Object.keys(this.registryFactory).sort(function(e,n){return t.registryFactory[n].priority-t.registryFactory[e].priority})},t.prototype.initializeBackendsAndReturnBest=function(){for(var t=this.getSortedBackends(),e=0;e<t.length;e++){var n=t[e],r=this.initializeBackend(n),i=r.success,a=r.asyncInit;if(a||i)return{name:n,asyncInit:a}}throw new Error("Could not initialize any backends, all backend initializations failed.")},t.prototype.moveData=function(t,e){var n=this.state.tensorInfo.get(e),r=n.backend,i=this.readSync(e);r.disposeData(e),n.backend=t,t.move(e,i,n.shape,n.dtype),this.shouldCheckForMemLeaks()&&this.state.numDataMovesStack[this.state.numDataMovesStack.length-1]++},t.prototype.tidy=function(t,e){var n,r=this,i=null;if(null==e){if("function"!=typeof t)throw new Error("Please provide a function to tidy()");e=t}else{if("string"!=typeof t&&!(t instanceof String))throw new Error("When calling with two arguments, the first argument to tidy() must be a string");if("function"!=typeof e)throw new Error("When calling with two arguments, the 2nd argument to tidy() must be a function");i=t}return this.scopedRun(function(){return r.startScope(i)},function(){return r.endScope(n)},function(){return(n=e())instanceof Promise&&console.error("Cannot return a Promise inside of tidy."),n})},t.prototype.scopedRun=function(t,e,n){t();try{var r=n();return e(),r}catch(t){throw e(),t}},t.prototype.nextTensorId=function(){return t.nextTensorId++},t.prototype.nextVariableId=function(){return t.nextVariableId++},t.prototype.clone=function(t){var e=this.makeTensorFromDataId(t.dataId,t.shape,t.dtype),n={x:t};return this.addTapeNode(this.state.activeScope.name,n,[e],function(t){return{x:function(){return t.toFloat()}}},[],{}),e},t.prototype.runKernel=function(t,e,n,r,i){return this.runKernelFunc(null,e,null,t,n,r,i)},t.prototype.shouldCheckForMemLeaks=function(){return this.ENV.getBool("IS_TEST")},t.prototype.checkKernelForMemLeak=function(t,e,n){var r=this.backend.numDataIds(),i=0;n.forEach(function(t){i+="complex64"===t.dtype?3:1});var a=this.state.numDataMovesStack[this.state.numDataMovesStack.length-1],o=r-e-i-a;if(o>0)throw new Error("Backend '"+this.backendName+"' has an internal memory leak ("+o+" data ids) after running '"+t+"'")},t.prototype.runKernelFunc=function(t,e,n,r,i,a,o){var s,u=this,c=[],l=this.isTapeOn();null==r&&(r=null!=this.state.activeScope?this.state.activeScope.name:"");var f,d=this.state.numBytes,h=this.state.numTensors;this.shouldCheckForMemLeaks()&&this.state.numDataMovesStack.push(0);var p,g=m(r,this.backendName);if(null!=g)f=function(){var t=u.backend.numDataIds();p=g.kernelFunc({inputs:e,attrs:i,backend:u.backend});var n=Array.isArray(p)?p:[p];u.shouldCheckForMemLeaks()&&u.checkKernelForMemLeak(r,t,n);var s=n.map(function(t){var e=t.dataId,n=t.shape,r=t.dtype;return u.makeTensorFromDataId(e,n,r)});if(l){var f=u.getTensorsForGradient(r,e,s);if(null==f){null==o&&(o=[]);var d=s.filter(function(t,e){return o[e]});f=(a||[]).slice().concat(d)}c=u.saveTensorsForBackwardMode(f)}return s};else{var v=function(t){l&&(c=t.map(function(t){return u.keep(u.clone(t))}))};f=function(){var e=u.backend.numDataIds();p=u.tidy(function(){return t(u.backend,v)});var n=Array.isArray(p)?p:[p];return u.shouldCheckForMemLeaks()&&u.checkKernelForMemLeak(r,e,n),n}}return this.scopedRun(function(){return u.state.kernelDepth++},function(){return u.state.kernelDepth--},function(){s=u.ENV.getBool("DEBUG")?u.profiler.profileKernel(r,e,function(){return f()}):f()}),l&&this.addTapeNode(r,e,s,n,c,i),this.state.profiling&&this.state.activeProfile.kernels.push({name:r,bytesAdded:this.state.numBytes-d,totalBytesSnapshot:this.state.numBytes,tensorsAdded:this.state.numTensors-h,totalTensorsSnapshot:this.state.numTensors,inputShapes:Object.keys(e).map(function(t){return e[t].shape}),outputShapes:s.map(function(t){return t.shape})}),Array.isArray(p)?s:s[0]},t.prototype.saveTensorsForBackwardMode=function(t){var e=this;return t.map(function(t){return e.keep(e.clone(t))})},t.prototype.getTensorsForGradient=function(t,e,n){var r=g(t);if(null!=r){var i=r.inputsToSave||[],a=r.outputsToSave||[],o=void 0;r.saveAllInputs?(C(Array.isArray(e),function(){return"saveAllInputs is true, expected inputs to be an array."}),o=Object.keys(e).map(function(t){return e[t]})):o=i.map(function(t){return e[t]});var s=n.filter(function(t,e){return a[e]});return o.concat(s)}return null},t.prototype.makeTensor=function(t,e,n,r){if(null==t)throw new Error("Values passed to engine.makeTensor() are null");n=n||"float32",r=r||this.backend;var i=t;"string"===n&&X(t[0])&&(i=t.map(function(t){return ut(t)}));var a=r.write(i,e,n),o=new Ot(e,n,a,this.nextTensorId());if(this.incRef(o,r),"string"===n){var s=this.state.tensorInfo.get(a),u=K(i);this.state.numBytes+=u-s.bytes,s.bytes=u}return o},t.prototype.makeTensorFromDataId=function(t,e,n,r){var i=new Ot(e,n=n||"float32",t,this.nextTensorId());return this.incRef(i,r),i},t.prototype.makeVariable=function(t,e,n,r){void 0===e&&(e=!0),n=n||this.nextVariableId().toString(),null!=r&&r!==t.dtype&&(t=t.asType(r));var i=new It(t,e,n,this.nextTensorId());if(null!=this.state.registeredVariables[i.name])throw new Error("Variable with name "+i.name+" was already registered");return this.state.registeredVariables[i.name]=i,this.incRef(i,this.backend),i},t.prototype.incRef=function(t,e){var n=this.state.tensorInfo.has(t.dataId)?this.state.tensorInfo.get(t.dataId).refCount:0;if(this.state.numTensors++,"string"===t.dtype&&this.state.numStringTensors++,0===n){this.state.numDataBuffers++;var r=0;"complex64"!==t.dtype&&"string"!==t.dtype&&(r=t.size*$(t.dtype)),this.state.tensorInfo.set(t.dataId,{backend:e||this.backend,dtype:t.dtype,shape:t.shape,bytes:r,refCount:0}),this.state.numBytes+=r}this.state.tensorInfo.get(t.dataId).refCount++,t instanceof It||this.track(t)},t.prototype.disposeTensor=function(t){if(this.state.tensorInfo.has(t.dataId)){this.state.numTensors--,"string"===t.dtype&&this.state.numStringTensors--;var e=this.state.tensorInfo.get(t.dataId);e.refCount<=1?("complex64"!==t.dtype&&(this.state.numBytes-=e.bytes),this.state.numDataBuffers--,e.backend.disposeData(t.dataId),this.state.tensorInfo.delete(t.dataId)):this.state.tensorInfo.get(t.dataId).refCount--}},t.prototype.disposeVariables=function(){for(var t in this.state.registeredVariables){var e=this.state.registeredVariables[t];this.disposeVariable(e)}},t.prototype.disposeVariable=function(t){this.disposeTensor(t),null!=this.state.registeredVariables[t.name]&&delete this.state.registeredVariables[t.name]},t.prototype.memory=function(){var t=this.backend.memory();return t.numTensors=this.state.numTensors,t.numDataBuffers=this.state.numDataBuffers,t.numBytes=this.state.numBytes,this.state.numStringTensors>0&&(t.unreliable=!0,null==t.reasons&&(t.reasons=[]),t.reasons.push("Memory usage by string tensors is approximate (2 bytes per character)")),t},t.prototype.profile=function(t){return u(this,void 0,void 0,function(){var e,n;return c(this,function(r){return this.state.profiling=!0,e=this.state.numBytes,n=this.state.numTensors,this.state.activeProfile.kernels=[],this.state.activeProfile.result=t(),this.state.profiling=!1,this.state.activeProfile.peakBytes=Math.max.apply(Math,this.state.activeProfile.kernels.map(function(t){return t.totalBytesSnapshot})),this.state.activeProfile.newBytes=this.state.numBytes-e,this.state.activeProfile.newTensors=this.state.numTensors-n,[2,this.state.activeProfile]})})},t.prototype.isTapeOn=function(){return this.state.gradientDepth>0&&0===this.state.kernelDepth},t.prototype.addTapeNode=function(t,e,n,r,i,a){var o=this,s={id:this.state.nextTapeNodeId++,kernelName:t,inputs:e,outputs:n,saved:i},u=g(t);null!=u&&(r=u.gradFunc),null!=r&&(s.gradient=function(t){return t=t.map(function(t,e){if(null==t){var r=n[e],i=at(r.size,r.dtype);return o.makeTensor(i,r.shape,r.dtype)}return t}),r(t.length>1?t:t[0],i,a)}),this.state.activeTape.push(s)},t.prototype.keep=function(t){return t.kept=!0,t},t.prototype.startTape=function(){0===this.state.gradientDepth&&(this.state.activeTape=[]),this.state.gradientDepth++},t.prototype.endTape=function(){this.state.gradientDepth--},t.prototype.startScope=function(t){var e={track:[],name:"unnamed scope",id:this.state.nextScopeId++};t&&(e.name=t),this.state.scopeStack.push(e),this.state.activeScope=e},t.prototype.endScope=function(t){for(var e=this,n=Pt(t),r=new Set(n.map(function(t){return t.id})),i=0;i<this.state.activeScope.track.length;i++){var a=this.state.activeScope.track[i];a.kept||r.has(a.id)||a.dispose()}var o=this.state.scopeStack.pop();this.state.activeScope=0===this.state.scopeStack.length?null:this.state.scopeStack[this.state.scopeStack.length-1],n.forEach(function(t){t.kept||t.scopeId!==o.id||e.track(t)})},t.prototype.gradients=function(t,e,n,r){var i=this;if(void 0===r&&(r=!1),C(e.length>0,function(){return"gradients() received an empty list of xs."}),null!=n&&"float32"!==n.dtype)throw new Error("dy must have 'float32' dtype, but has '"+n.dtype+"'");var a=this.scopedRun(function(){return i.startTape()},function(){return i.endTape()},function(){return i.tidy("forward",t)});C(a instanceof Ot,function(){return"The result y returned by f() must be a tensor."});var o=function(t,e,n){for(var r={},i={},a=0;a<e.length;a++)r[e[a].id]=!0;for(a=0;a<t.length;a++){var o=(p=t[a]).inputs;for(var s in o){for(var u=o[s],c=!1,l=0;l<e.length;l++)if(r[u.id]){p.outputs.forEach(function(t){return r[t.id]=!0}),c=!0,i[p.id]=!0;break}if(c)break}}var f={};f[n.id]=!0;var d={};for(a=t.length-1;a>=0;a--)for(o=(p=t[a]).inputs,l=0;l<p.outputs.length;l++)if(f[p.outputs[l].id]){for(var s in o)f[o[s].id]=!0,d[p.id]=!0;break}var h=[];for(a=0;a<t.length;a++){var p;if(i[(p=t[a]).id]&&d[p.id]){var m={};for(var s in p.inputs){var g=p.inputs[s];r[g.id]&&(m[s]=g)}var v=Object.assign({},p);v.inputs=m,v.outputs=p.outputs,h.push(v)}}return h}(this.state.activeTape,e,a);if(!r&&0===o.length&&e.length>0)throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that the f you passed encloses all operations that lead from x to y.");return this.tidy("backward",function(){var t,r,s={};s[a.id]=null==n?(r=it(I(t=a.shape),"float32"),Wt.makeTensor(r,t,"float32")):n,function(t,e,n){for(var r=function(r){var i=e[r],a=[];if(i.outputs.forEach(function(e){var n=t[e.id];null!=n?a.push(n):a.push(null)}),null==i.gradient)throw new Error("Cannot compute gradient: gradient function not found for "+i.kernelName+".");var o=i.gradient(a),s=function(e){if(!(e in o))throw new Error("Cannot backprop through input "+e+". Available gradients found: "+Object.keys(o)+".");var r=n(function(){return o[e]()});if("float32"!==r.dtype)throw new Error("Error in gradient for op "+i.kernelName+". The gradient of input "+e+" must have 'float32' dtype, but has '"+r.dtype+"'");var a=i.inputs[e];if(!D(r.shape,a.shape))throw new Error("Error in gradient for op "+i.kernelName+". The gradient of input '"+e+"' has shape '"+r.shape+"', which does not match the shape of the input '"+a.shape+"'");if(null==t[a.id])t[a.id]=r;else{var s=t[a.id];t[a.id]=s.add(r),s.dispose()}};for(var u in i.inputs)s(u)},i=e.length-1;i>=0;i--)r(i)}(s,o,function(t){return i.tidy(t)});var u=e.map(function(t){return s[t.id]});return 0===i.state.gradientDepth&&(i.state.activeTape.forEach(function(t){for(var e=0,n=t.saved;e<n.length;e++)n[e].dispose()}),i.state.activeTape=null),{value:a,grads:u}})},t.prototype.customGrad=function(t){var e=this;return C(Q(t),function(){return"The f passed in customGrad(f) must be a function."}),function(){for(var n,r=[],i=0;i<arguments.length;i++)r[i]=arguments[i];C(r.every(function(t){return t instanceof Ot}),function(){return"The args passed in customGrad(f)(x1, x2,...) must all be tensors"});var a={};return r.forEach(function(t,e){a[e]=t}),e.runKernelFunc(function(e,i){return C((n=t.apply(void 0,r.concat([i]))).value instanceof Ot,function(){return"The function f passed in customGrad(f) must return an object where `obj.value` is a tensor"}),C(Q(n.gradFunc),function(){return"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function."}),n.value},a,function(t,e){var i=n.gradFunc(t,e),a=Array.isArray(i)?i:[i];C(a.length===r.length,function(){return"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns the same number of tensors as inputs passed to f(...)."}),C(a.every(function(t){return t instanceof Ot}),function(){return"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns a list of only tensors."});var o={};return a.forEach(function(t,e){o[e]=function(){return t}}),o})}},t.prototype.readSync=function(t){return this.state.tensorInfo.get(t).backend.readSync(t)},t.prototype.read=function(t){return this.state.tensorInfo.get(t).backend.read(t)},t.prototype.time=function(t){return u(this,void 0,void 0,function(){var e,n;return c(this,function(r){switch(r.label){case 0:return e=ot(),[4,this.backend.time(t)];case 1:return(n=r.sent()).wallMs=ot()-e,[2,n]}})})},t.prototype.track=function(t){return null!=this.state.activeScope&&(t.scopeId=this.state.activeScope.id,this.state.activeScope.track.push(t)),t},Object.defineProperty(t.prototype,"registeredVariables",{get:function(){return this.state.registeredVariables},enumerable:!0,configurable:!0}),t.prototype.reset=function(){for(var t in this.pendingBackendInitId++,this.state.dispose(),this.ENV.reset(),this.state=new Bt,this.registry)this.disposeRegisteredKernels(t),this.registry[t].dispose(),delete this.registry[t];this.backendName=null,this.backendInstance=null,this.pendingBackendInit=null},t.nextTensorId=0,t.nextVariableId=0,t}(),Wt=function(){var e=function(){if(null==Lt){var e=void 0;if("undefined"!=typeof window)e=window;else if(void 0!==t)e=t;else if(void 0!==r)e=r;else{if("undefined"==typeof self)throw new Error("Could not find a global object");e=self}Lt=e}return Lt}();if(null==e._tfengine){var n=new l(e);e._tfengine=new Ut(n)}return function(t){d=t}(e._tfengine.ENV),kt=function(){return e._tfengine},e._tfengine}();function Vt(){return"undefined"!=typeof window&&null!=window.document||"undefined"!=typeof WorkerGlobalScope}var qt=f();qt.registerFlag("DEBUG",function(){return!1},function(t){t&&console.warn("Debugging mode is ON. The output of every math call will be downloaded to CPU and checked for NaNs. This significantly impacts performance.")}),qt.registerFlag("IS_BROWSER",function(){return Vt()}),qt.registerFlag("IS_NODE",function(){return void 0!==r&&void 0!==r.versions&&void 0!==r.versions.node}),qt.registerFlag("IS_CHROME",function(){return"undefined"!=typeof navigator&&null!=navigator&&null!=navigator.userAgent&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)}),qt.registerFlag("PROD",function(){return!1}),qt.registerFlag("TENSORLIKE_CHECK_SHAPE_CONSISTENCY",function(){return qt.getBool("DEBUG")}),qt.registerFlag("DEPRECATION_WARNINGS_ENABLED",function(){return!0}),qt.registerFlag("IS_TEST",function(){return!1});var Ht,Gt,$t,Kt={},Xt={alpha:!1,antialias:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!1,depth:!1,stencil:!1,failIfMajorPerformanceCaveat:!0};function Yt(t,e){Kt[t]=e}function Jt(t){t in Kt||(Kt[t]=function(t){if(1!==t&&2!==t)throw new Error("Cannot get WebGL rendering context, WebGL is disabled.");var e=function(t){if("undefined"!=typeof OffscreenCanvas&&2===t)return new OffscreenCanvas(300,150);if("undefined"!=typeof document)return document.createElement("canvas");throw new Error("Cannot create a canvas in this context")}(t);return e.addEventListener("webglcontextlost",function(e){e.preventDefault(),delete Kt[t]},!1),1===t?e.getContext("webgl",Xt)||e.getContext("experimental-webgl",Xt):e.getContext("webgl2",Xt)}(t));var e=Kt[t];return e.isContextLost()?(delete Kt[t],Jt(t)):(e.disable(e.DEPTH_TEST),e.disable(e.STENCIL_TEST),e.disable(e.BLEND),e.disable(e.DITHER),e.disable(e.POLYGON_OFFSET_FILL),e.disable(e.SAMPLE_COVERAGE),e.enable(e.SCISSOR_TEST),e.enable(e.CULL_FACE),e.cullFace(e.BACK),Kt[t])}function Zt(t,e){return[e,t]}function Qt(t){var e=I(t);return F(Math.ceil(e/4))}function te(t,e){return[Math.max(1,Math.ceil(e/2)),Math.max(1,Math.ceil(t/2))]}function ee(t,e){var n,r,i,a,o,s,u,c,l,d=t;return 2===f().getNumber("WEBGL_VERSION")?(n=d.R32F,r=d.R16F,i=d.RGBA16F,a=d.RGBA32F,o=d.RED,s=4,u=1,c=d.HALF_FLOAT,l=d.FLOAT):(n=t.RGBA,r=t.RGBA,i=t.RGBA,a=d.RGBA,o=t.RGBA,s=4,u=4,c=null!=e?e.HALF_FLOAT_OES:null,l=t.FLOAT),{internalFormatFloat:n,internalFormatHalfFloat:r,internalFormatPackedHalfFloat:i,internalFormatPackedFloat:a,textureFormatFloat:o,downloadTextureFormat:t.RGBA,downloadUnpackNumChannels:s,defaultNumChannels:u,textureTypeHalfFloat:c,textureTypeFloat:l}}function ne(t,e,n){var r=n();return e&&function(t){var e=t.getError();if(e!==t.NO_ERROR)throw new Error("WebGL Error: "+oe(t,e))}(t),r}!function(t){t[t.DENSE=0]="DENSE",t[t.SHARED_BATCH=1]="SHARED_BATCH"}(Ht||(Ht={})),function(t){t[t.RENDER=0]="RENDER",t[t.UPLOAD=1]="UPLOAD",t[t.PIXELS=2]="PIXELS",t[t.DOWNLOAD=3]="DOWNLOAD"}(Gt||(Gt={})),function(t){t[t.UNPACKED_FLOAT16=0]="UNPACKED_FLOAT16",t[t.UNPACKED_FLOAT32=1]="UNPACKED_FLOAT32",t[t.PACKED_4X1_UNSIGNED_BYTE=2]="PACKED_4X1_UNSIGNED_BYTE",t[t.PACKED_2X2_FLOAT32=3]="PACKED_2X2_FLOAT32",t[t.PACKED_2X2_FLOAT16=4]="PACKED_2X2_FLOAT16"}($t||($t={}));var re=5.96e-8,ie=65504;function ae(t){return!!(f().getBool("WEBGL_RENDER_FLOAT32_ENABLED")||0===t||re<Math.abs(t)&&Math.abs(t)<ie)}function oe(t,e){switch(e){case t.NO_ERROR:return"NO_ERROR";case t.INVALID_ENUM:return"INVALID_ENUM";case t.INVALID_VALUE:return"INVALID_VALUE";case t.INVALID_OPERATION:return"INVALID_OPERATION";case t.INVALID_FRAMEBUFFER_OPERATION:return"INVALID_FRAMEBUFFER_OPERATION";case t.OUT_OF_MEMORY:return"OUT_OF_MEMORY";case t.CONTEXT_LOST_WEBGL:return"CONTEXT_LOST_WEBGL";default:return"Unknown error code "+e}}function se(t,e,n){return Te(t,e,function(){return t.getExtension(n)},'Extension "'+n+'" not supported on this browser.')}function ue(t,e,n){var r=Te(t,e,function(){return t.createShader(t.VERTEX_SHADER)},"Unable to create vertex WebGLShader.");if(ne(t,e,function(){return t.shaderSource(r,n)}),ne(t,e,function(){return t.compileShader(r)}),!1===t.getShaderParameter(r,t.COMPILE_STATUS))throw console.log(t.getShaderInfoLog(r)),new Error("Failed to compile vertex shader.");return r}function ce(t,e,n){var r=Te(t,e,function(){return t.createShader(t.FRAGMENT_SHADER)},"Unable to create fragment WebGLShader.");if(ne(t,e,function(){return t.shaderSource(r,n)}),ne(t,e,function(){return t.compileShader(r)}),!1===t.getShaderParameter(r,t.COMPILE_STATUS))throw function(t,e){var n=de.exec(e);if(null==n)return console.log("Couldn't parse line number in error: "+e),void console.log(t);for(var r=+n[1],i=t.split("\n"),a=i.length.toString().length+2,o=i.map(function(t,e){return j((e+1).toString(),a)+t}),s=0,u=0;u<o.length;u++)s=Math.max(o[u].length,s);var c=o.slice(0,r-1),l=o.slice(r-1,r),f=o.slice(r);console.log(c.join("\n")),console.log(e.split("\n")[0]),console.log("%c "+j(l[0],s),"border:1px solid red; background-color:#e3d2d2; color:#a61717"),console.log(f.join("\n"))}(n,t.getShaderInfoLog(r)),new Error("Failed to compile fragment shader.");return r}var le,fe,de=/ERROR: [0-9]+:([0-9]+):/g;function he(t,e){return Te(t,e,function(){return t.createProgram()},"Unable to create WebGLProgram.")}function pe(t,e,n){if(ne(t,e,function(){return t.linkProgram(n)}),!1===t.getProgramParameter(n,t.LINK_STATUS))throw console.log(t.getProgramInfoLog(n)),new Error("Failed to link vertex and fragment shaders.")}function me(t,e,n){if(ne(t,e,function(){return t.validateProgram(n)}),!1===t.getProgramParameter(n,t.VALIDATE_STATUS))throw console.log(t.getProgramInfoLog(n)),new Error("Shader program validation failed.")}function ge(t,e,n){var r=Te(t,e,function(){return t.createBuffer()},"Unable to create WebGLBuffer");return ne(t,e,function(){return t.bindBuffer(t.ARRAY_BUFFER,r)}),ne(t,e,function(){return t.bufferData(t.ARRAY_BUFFER,n,t.STATIC_DRAW)}),r}function ve(t,e,n){var r=Te(t,e,function(){return t.createBuffer()},"Unable to create WebGLBuffer");return ne(t,e,function(){return t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,r)}),ne(t,e,function(){return t.bufferData(t.ELEMENT_ARRAY_BUFFER,n,t.STATIC_DRAW)}),r}function ye(t,e){return Te(t,e,function(){return t.createTexture()},"Unable to create WebGLTexture.")}function be(t,e){var n=f().getNumber("WEBGL_MAX_TEXTURE_SIZE");if(t<=0||e<=0){var r="["+t+"x"+e+"]";throw new Error("Requested texture size "+r+" is invalid.")}if(t>n||e>n)throw r="["+t+"x"+e+"]",new Error("Requested texture size "+r+" greater than WebGL maximum on this browser / GPU ["+n+"x"+n+"].")}function xe(t,e){return Te(t,e,function(){return t.createFramebuffer()},"Unable to create WebGLFramebuffer.")}function we(t,e,n,r,i,a,o,s){var u=t.getAttribLocation(n,r);return-1!==u&&(ne(t,e,function(){return t.bindBuffer(t.ARRAY_BUFFER,i)}),ne(t,e,function(){return t.vertexAttribPointer(u,a,t.FLOAT,!1,o,s)}),ne(t,e,function(){return t.enableVertexAttribArray(u)}),!0)}function ke(t,e,n,r){Ie(t,r),ne(t,e,function(){return t.activeTexture(t.TEXTURE0+r)}),ne(t,e,function(){return t.bindTexture(t.TEXTURE_2D,n)})}function _e(t,e,n,r){return Te(t,e,function(){return t.getUniformLocation(n,r)},'uniform "'+r+'" not present in program.')}function Ee(t,e,n){return t.getUniformLocation(e,n)}function Oe(t,e,n,r,i,a){ne(t,e,function(){return ke(t,e,r,a)}),ne(t,e,function(){return t.uniform1i(i,a)})}function Se(t,e,n,r){ne(t,e,function(){return t.bindFramebuffer(t.FRAMEBUFFER,r)}),ne(t,e,function(){return t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,n,0)})}function Ce(t,e,n){ne(t,e,function(){return t.bindFramebuffer(t.FRAMEBUFFER,n)}),ne(t,e,function(){return t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,null,0)})}function Ae(t){var e=t.checkFramebufferStatus(t.FRAMEBUFFER);if(e!==t.FRAMEBUFFER_COMPLETE)throw new Error("Error binding framebuffer: "+Ne(t,e))}function Ne(t,e){switch(e){case t.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case t.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case t.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:return"FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case t.FRAMEBUFFER_UNSUPPORTED:return"FRAMEBUFFER_UNSUPPORTED";default:return"unknown error "+e}}function Te(t,e,n,r){var i=ne(t,e,function(){return n()});if(null==i)throw new Error(r);return i}function Ie(t,e){var n=t.MAX_COMBINED_TEXTURE_IMAGE_UNITS-1,r=e+t.TEXTURE0;if(r<t.TEXTURE0||r>n)throw new Error("textureUnit must be in [gl.TEXTURE0, gl.TEXTURE"+n+"].")}function De(t,e){return void 0===e&&(e=2),I(t.slice(0,t.length-e))}function Me(t){if(0===t.length)throw Error("Cannot get rows and columns of an empty shape array.");return[t.length>1?t[t.length-2]:1,t[t.length-1]]}function Re(t){var e=[1,1,1];return 0===t.length||1===t.length&&1===t[0]||(e=[De(t)].concat(Me(t))),e}function Fe(t,e){var n;void 0===e&&(e=!1);var r=f().getNumber("WEBGL_MAX_TEXTURE_SIZE");if(e&&(r*=2,1===(t=t.map(function(e,n){return n>=t.length-2?O(t[n]):t[n]})).length&&(t=[2,t[0]])),2!==t.length){var i=B(t);t=i.newShape}var a=I(t);if(t.length<=1&&a<=r)return[1,a];if(2===t.length&&t[0]<=r&&t[1]<=r)return t;if(3===t.length&&t[0]*t[1]<=r&&t[2]<=r)return[t[0]*t[1],t[2]];if(3===t.length&&t[0]<=r&&t[1]*t[2]<=r)return[t[0],t[1]*t[2]];if(4===t.length&&t[0]*t[1]*t[2]<=r&&t[3]<=r)return[t[0]*t[1]*t[2],t[3]];if(4===t.length&&t[0]<=r&&t[1]*t[2]*t[3]<=r)return[t[0],t[1]*t[2]*t[3]];if(e){var o=De(t),s=2,u=2;return t.length&&(s=(n=Me(t))[0],u=n[1]),F(a=o*(s/2)*(u/2)).map(function(t){return 2*t})}return F(a)}function je(t){return t%2==0}function Pe(t,e){if(D(t=t.slice(-2),e=e.slice(-2)))return!0;if(!t.length||!e.length)return!0;if(0===t[0]||0===t[1]||0===e[0]||0===e[1])return!0;if(t.length!==e.length){var n=t.slice(-1)[0],r=e.slice(-1)[0];if(n===r)return!0;if(je(n)&&je(r)&&(1===t[0]||1===e[0]))return!0}return t[1]===e[1]&&je(t[0])&&je(e[0])}function Le(t){if(null==le){var e=Jt(t);le=e.getParameter(e.MAX_TEXTURE_SIZE)}return le}function ze(t){if(null==fe){var e=Jt(t);fe=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS)}return Math.min(16,fe)}function Be(t){if(0===t)return 0;var e=Jt(t);return Ue(e,"EXT_disjoint_timer_query_webgl2")&&2===t?2:Ue(e,"EXT_disjoint_timer_query")?1:0}function Ue(t,e){return null!=t.getExtension(e)}function We(t){try{if(null!=Jt(t))return!0}catch(t){return!1}return!1}function Ve(t){if(0===t)return!1;var e=Jt(t);if(1===t){if(!Ue(e,"OES_texture_float"))return!1}else if(!Ue(e,"EXT_color_buffer_float"))return!1;return He(e)}function qe(t){if(0===t)return!1;var e=Jt(t);return 1!==t?Ue(e,"EXT_color_buffer_float")?He(e):!!Ue(e,"EXT_color_buffer_half_float")&&function(t,e){var n=ee(t,e),r=t.createTexture();t.bindTexture(t.TEXTURE_2D,r),t.texImage2D(t.TEXTURE_2D,0,n.internalFormatHalfFloat,1,1,0,n.textureFormatFloat,n.textureTypeHalfFloat,null);var i=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,i),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,r,0);var a=t.checkFramebufferStatus(t.FRAMEBUFFER)===t.FRAMEBUFFER_COMPLETE;return t.bindTexture(t.TEXTURE_2D,null),t.bindFramebuffer(t.FRAMEBUFFER,null),t.deleteTexture(r),t.deleteFramebuffer(i),a}(e,e.getExtension("EXT_color_buffer_half_float")):!!Ue(e,"OES_texture_float")&&!!Ue(e,"WEBGL_color_buffer_float")&&He(e)}function He(t){var e=ee(t),n=t.createTexture();t.bindTexture(t.TEXTURE_2D,n),t.texImage2D(t.TEXTURE_2D,0,e.internalFormatFloat,1,1,0,e.textureFormatFloat,e.textureTypeFloat,null);var r=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,r),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,n,0);var i=t.checkFramebufferStatus(t.FRAMEBUFFER)===t.FRAMEBUFFER_COMPLETE;return t.bindTexture(t.TEXTURE_2D,null),t.bindFramebuffer(t.FRAMEBUFFER,null),t.deleteTexture(n),t.deleteFramebuffer(r),i}function Ge(t){return 2===t&&null!=Jt(t).fenceSync}var $e=Object.freeze({callAndCheck:ne,canBeRepresented:ae,getWebGLErrorMessage:oe,getExtensionOrThrow:se,createVertexShader:ue,createFragmentShader:ce,createProgram:he,linkProgram:pe,validateProgram:me,createStaticVertexBuffer:ge,createStaticIndexBuffer:ve,getNumChannels:function(){return 2===f().getNumber("WEBGL_VERSION")?1:4},createTexture:ye,validateTextureSize:be,createFramebuffer:xe,bindVertexBufferToProgramAttribute:we,bindTextureUnit:ke,unbindTextureUnit:function(t,e,n){Ie(t,n),ne(t,e,function(){return t.activeTexture(t.TEXTURE0+n)}),ne(t,e,function(){return t.bindTexture(t.TEXTURE_2D,null)})},getProgramUniformLocationOrThrow:_e,getProgramUniformLocation:Ee,bindTextureToProgramUniformSampler:Oe,bindCanvasToFramebuffer:function(t,e){ne(t,e,function(){return t.bindFramebuffer(t.FRAMEBUFFER,null)}),ne(t,e,function(){return t.viewport(0,0,t.canvas.width,t.canvas.height)}),ne(t,e,function(){return t.scissor(0,0,t.canvas.width,t.canvas.height)})},bindColorTextureToFramebuffer:Se,unbindColorTextureFromFramebuffer:Ce,validateFramebuffer:Ae,getFramebufferErrorMessage:Ne,getBatchDim:De,getRowsCols:Me,getShapeAs3D:Re,getTextureShapeFromLogicalShape:Fe,isReshapeFree:Pe,getWebGLMaxTextureSize:Le,resetMaxTextureSize:function(){le=null},resetMaxTexturesInShader:function(){fe=null},getMaxTexturesInShader:ze,getWebGLDisjointQueryTimerVersion:Be,hasExtension:Ue,isWebGLVersionEnabled:We,isCapableOfRenderingToFloatTexture:Ve,isDownloadFloatTextureEnabled:qe,isWebGLFenceEnabled:Ge}),Ke=f();function Xe(){f().set("PROD",!0)}function Ye(){f().set("DEBUG",!0)}function Je(){f().set("DEPRECATION_WARNINGS_ENABLED",!1),console.warn("TensorFlow.js deprecation warnings have been disabled.")}function Ze(t){f().getBool("DEPRECATION_WARNINGS_ENABLED")&&console.warn(t+" You can disable deprecation warnings with tf.disableDeprecationWarnings().")}function Qe(){Wt.disposeVariables()}function tn(){return Wt}function en(){return Wt.memory()}function nn(t){return Wt.profile(t)}function rn(t,e){return Wt.tidy(t,e)}function an(t){Pt(t).forEach(function(t){return t.dispose()})}function on(t){return Wt.keep(t)}function sn(t){return Wt.time(t)}function un(t){return Wt.setBackend(t)}function cn(){return Wt.ready()}function ln(){return Wt.backendName}function fn(t){Wt.removeBackend(t)}function dn(t){return Wt.findBackend(t)}function hn(t){return Wt.findBackendFactory(t)}function pn(t,e,n){return void 0===n&&(n=1),Wt.registerBackend(t,e,n)}function mn(){return Wt.backend}function gn(t,e){f().setPlatform(t,e)}function vn(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];f().getBool("IS_TEST")||console.warn.apply(console,t)}function yn(t,e){var n=t;if(G(t))return"string"===e?[]:[t.length];if(!Array.isArray(t))return[];for(var r=[];Array.isArray(n)||G(n)&&"string"!==e;)r.push(n.length),n=n[0];return Array.isArray(t)&&f().getBool("TENSORLIKE_CHECK_SHAPE_CONSISTENCY")&&function t(e,n,r){if(r=r||[],Array.isArray(e)||G(e)){C(n.length>0,function(){return"Element arr["+r.join("][")+"] should be a primitive, but is an array of "+e.length+" elements"}),C(e.length===n[0],function(){return"Element arr["+r.join("][")+"] should have "+n[0]+" elements, but has "+e.length+" elements"});for(var i=n.slice(1),a=0;a<e.length;++a)t(e[a],i,r.concat(a))}else C(0===n.length,function(){return"Element arr["+r.join("][")+"] is a primitive, but should be an array/TypedArray of "+n[0]+" elements"})}(t,r,[]),r}function bn(t,e,n,r){if(null!=t&&("numeric"!==t&&t!==e||"numeric"===t&&"string"===e))throw new Error("Argument '"+n+"' passed to '"+r+"' must be "+t+" tensor, but got "+e+" tensor")}function xn(t,e,n,r){if(void 0===r&&(r="numeric"),t instanceof Ot)return bn(r,t.dtype,e,n),t;var i=Z(t);if("string"!==i&&["bool","int32","float32"].indexOf(r)>=0&&(i=r),bn(r,i,e,n),null==t||!G(t)&&!Array.isArray(t)&&"number"!=typeof t&&"boolean"!=typeof t&&"string"!=typeof t){var a=null==t?"null":t.constructor.name;throw new Error("Argument '"+e+"' passed to '"+n+"' must be a Tensor or TensorLike, but got '"+a+"'")}var o=yn(t,i);G(t)||Array.isArray(t)||(t=[t]);var s="string"!==i?nt(t,i,f().getBool("DEBUG")):T(t,[],!0);return Wt.makeTensor(s,o,i)}function wn(t,e,n,r){if(void 0===r&&(r="numeric"),!Array.isArray(t))throw new Error("Argument "+e+" passed to "+n+" must be a `Tensor[]` or `TensorLike[]`");return t.map(function(t,r){return xn(t,e+"["+r+"]",n)},r)}function kn(t,e){for(var n=0;n<t.length;++n)if(t[t.length-n-1]!==e-1-n)return!1;return!0}function _n(t,e,n){for(var r=t.length+e.length,i=[],a=0,o=0,s=0;s<r;s++)-1===n.indexOf(s)?i.push(t[a++]):i.push(e[o++]);return i}function En(t,e){for(var n=[],r=t.length,i=0;i<r;i++)-1===e.indexOf(i)&&n.push(t[i]);return[n,e.map(function(e){return t[e]})]}function On(t,e){return _n(t,e.map(function(t){return 1}),e)}function Sn(t,e,n){C(kn(e,n),function(){return t+" supports only inner-most axes for now. Got axes "+e+" and rank-"+n+" input."})}function Cn(t,e){if(kn(t,e))return null;for(var n=[],r=0;r<e;++r)-1===t.indexOf(r)&&n.push(r);return t.forEach(function(t){return n.push(t)}),n}function An(t){return t.map(function(t,e){return[e,t]}).sort(function(t,e){return t[1]-e[1]}).map(function(t){return t[0]})}function Nn(t,e){for(var n=[],r=e-t;r<e;++r)n.push(r);return n}function Tn(t,e){var n=t[0].length;t.forEach(function(t,e){C(t.length===n,function(){return"Error in concat"+n+"D: rank of tensors["+e+"] must be the same as the rank of the rest ("+n+")"})}),C(e>=0&&e<n,function(){return"Error in concat"+n+"D: axis must be between 0 and "+(n-1)+"."});var r=t[0];t.forEach(function(t,i){for(var a=0;a<n;a++)C(a===e||t[a]===r[a],function(){return"Error in concat"+n+"D: Shape of tensors["+i+"] ("+t+") does not match the shape of the rest ("+r+") along the non-concatenated axis "+i+"."})})}function In(t,e){for(var n=t[0].slice(),r=1;r<t.length;r++)n[e]+=t[r][e];return n}function Dn(t){var e=Object.keys(t);if(1!==e.length)throw new Error("Please provide an object with a single key (operation name) mapping to a function. Got an object with "+e.length+" keys.");var n=e[0],r=t[n];n.endsWith("_")&&(n=n.substring(0,n.length-1));var i=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];Wt.startScope(n);try{var i=r.apply(void 0,t);return i instanceof Promise&&console.error("Cannot return a Promise inside of tidy."),Wt.endScope(i),i}catch(t){throw Wt.endScope(null),t}};return Object.defineProperty(i,"name",{value:n,configurable:!0}),i}Ke.registerFlag("HAS_WEBGL",function(){return Ke.getNumber("WEBGL_VERSION")>0}),Ke.registerFlag("WEBGL_VERSION",function(){return We(2)?2:We(1)?1:0}),Ke.registerFlag("WEBGL_BUFFER_SUPPORTED",function(){return 2===Ke.get("WEBGL_VERSION")}),Ke.registerFlag("WEBGL_CPU_FORWARD",function(){return!0}),Ke.registerFlag("WEBGL_FORCE_F16_TEXTURES",function(){return!1}),Ke.registerFlag("WEBGL_PACK",function(){return Ke.getBool("HAS_WEBGL")}),Ke.registerFlag("WEBGL_PACK_NORMALIZATION",function(){return Ke.getBool("WEBGL_PACK")}),Ke.registerFlag("WEBGL_PACK_CLIP",function(){return Ke.getBool("WEBGL_PACK")}),Ke.registerFlag("WEBGL_PACK_DEPTHWISECONV",function(){return!1}),Ke.registerFlag("WEBGL_PACK_BINARY_OPERATIONS",function(){return Ke.getBool("WEBGL_PACK")}),Ke.registerFlag("WEBGL_PACK_UNARY_OPERATIONS",function(){return Ke.getBool("WEBGL_PACK")}),Ke.registerFlag("WEBGL_PACK_ARRAY_OPERATIONS",function(){return Ke.getBool("WEBGL_PACK")}),Ke.registerFlag("WEBGL_PACK_IMAGE_OPERATIONS",function(){return Ke.getBool("WEBGL_PACK")}),Ke.registerFlag("WEBGL_PACK_REDUCE",function(){return Ke.getBool("WEBGL_PACK")}),Ke.registerFlag("WEBGL_LAZILY_UNPACK",function(){return Ke.getBool("WEBGL_PACK")}),Ke.registerFlag("WEBGL_CONV_IM2COL",function(){return Ke.getBool("WEBGL_PACK")}),Ke.registerFlag("WEBGL_MAX_TEXTURE_SIZE",function(){return Le(Ke.getNumber("WEBGL_VERSION"))}),Ke.registerFlag("WEBGL_MAX_TEXTURES_IN_SHADER",function(){return ze(Ke.getNumber("WEBGL_VERSION"))}),Ke.registerFlag("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION",function(){var t=Ke.getNumber("WEBGL_VERSION");return 0===t?0:Be(t)}),Ke.registerFlag("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE",function(){return Ke.getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")>0&&(t=navigator.userAgent||navigator.vendor||window.opera,!(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(t)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(t.substr(0,4))));var t}),Ke.registerFlag("WEBGL_RENDER_FLOAT32_CAPABLE",function(){return Ve(Ke.getNumber("WEBGL_VERSION"))}),Ke.registerFlag("WEBGL_RENDER_FLOAT32_ENABLED",function(){return!Ke.getBool("WEBGL_FORCE_F16_TEXTURES")&&Ke.getBool("WEBGL_RENDER_FLOAT32_CAPABLE")}),Ke.registerFlag("WEBGL_DOWNLOAD_FLOAT_ENABLED",function(){return qe(Ke.getNumber("WEBGL_VERSION"))}),Ke.registerFlag("WEBGL_FENCE_API_ENABLED",function(){return Ge(Ke.getNumber("WEBGL_VERSION"))}),Ke.registerFlag("WEBGL_SIZE_UPLOAD_UNIFORM",function(){return Ke.getBool("WEBGL_RENDER_FLOAT32_ENABLED")?4:0}),Et=Ze;var Mn=Dn({complex_:function(t,e){var n=xn(t,"real","complex"),r=xn(e,"imag","complex");return A(n.shape,r.shape,"real and imag shapes, "+n.shape+" and "+r.shape+", must match in call to tf.complex()."),Wt.runKernelFunc(function(t){return t.complex(n,r)},{$real:n,$imag:r})}}),Rn=Dn({real_:function(t){var e=xn(t,"input","real");return Wt.runKernelFunc(function(t){return t.real(e)},{$input:e})}}),Fn=Dn({imag_:function(t){var e=xn(t,"input","imag");return Wt.runKernelFunc(function(t){return t.imag(e)},{$input:e})}});function jn(t,e,n){return Pn(t,e,yn(t,n),n)}function Pn(t,e,n,r){if(null==r&&(r=Z(t)),"complex64"===r)throw new Error("Cannot construct a complex64 tensor directly. Please use tf.complex(real, imag).");if(!G(t)&&!Array.isArray(t)&&"number"!=typeof t&&"boolean"!=typeof t&&"string"!=typeof t)throw new Error("values passed to tensor(values) must be a number/boolean/string or an array of numbers/booleans/strings, or a TypedArray");if(null!=e){st(e);var i=I(e),a=I(n);C(i===a,function(){return"Based on the provided shape, ["+e+"], the tensor should have "+i+" values but has "+a});for(var o=0;o<n.length;++o){var s=n[o],u=o!==n.length-1||s!==I(e.slice(o));C(n[o]===e[o]||!u,function(){return"Error creating a new Tensor. Inferred shape ("+n+") does not match the provided shape ("+e+"). "})}}return G(t)||Array.isArray(t)||(t=[t]),e=e||n,t="string"!==r?nt(t,r,f().getBool("DEBUG")):T(t,[],!0),Wt.makeTensor(t,e,r)}function Ln(t,e){if((G(t)&&"string"!==e||Array.isArray(t))&&"complex64"!==e)throw new Error("Error creating a new Scalar: value must be a primitive (number|boolean|string)");if("string"===e&&G(t)&&!(t instanceof Uint8Array))throw new Error("When making a scalar from encoded string, the value must be `Uint8Array`.");return Pn(t,[],[],e)}function zn(t,e){N(t);var n=yn(t,e);if(1!==n.length)throw new Error("tensor1d() requires values to be a flat/TypedArray");return Pn(t,null,n,e)}function Bn(t,e,n){if(N(t),null!=e&&2!==e.length)throw new Error("tensor2d() requires shape to have two numbers");var r=yn(t,n);if(2!==r.length&&1!==r.length)throw new Error("tensor2d() requires values to be number[][] or flat/TypedArray");if(1===r.length&&null==e)throw new Error("tensor2d() requires shape to be provided when `values` are a flat/TypedArray");return Pn(t,e,r,n)}function Un(t,e,n){if(N(t),null!=e&&3!==e.length)throw new Error("tensor3d() requires shape to have three numbers");var r=yn(t,n);if(3!==r.length&&1!==r.length)throw new Error("tensor3d() requires values to be number[][][] or flat/TypedArray");if(1===r.length&&null==e)throw new Error("tensor3d() requires shape to be provided when `values` are a flat array");return Pn(t,e,r,n)}function Wn(t,e,n){if(N(t),null!=e&&4!==e.length)throw new Error("tensor4d() requires shape to have four numbers");var r=yn(t,n);if(4!==r.length&&1!==r.length)throw new Error("tensor4d() requires values to be number[][][][] or flat/TypedArray");if(1===r.length&&null==e)throw new Error("tensor4d() requires shape to be provided when `values` are a flat array");return Pn(t,e,r,n)}function Vn(t,e,n){if(N(t),null!=e&&5!==e.length)throw new Error("tensor5d() requires shape to have five numbers");var r=yn(t,n);if(5!==r.length&&1!==r.length)throw new Error("tensor5d() requires values to be number[][][][][] or flat/TypedArray");if(1===r.length&&null==e)throw new Error("tensor5d() requires shape to be provided when `values` are a flat array");return Pn(t,e,r,n)}function qn(t,e,n){if(N(t),null!=e&&6!==e.length)throw new Error("tensor6d() requires shape to have six numbers");var r=yn(t,n);if(6!==r.length&&1!==r.length)throw new Error("tensor6d() requires values to be number[][][][][][] or flat/TypedArray");if(1===r.length&&null==e)throw new Error("tensor6d() requires shape to be provided when `values` are a flat array");return Pn(t,e=e||r,r,n)}function Hn(t,e,n,r){return void 0===e&&(e=!0),Wt.makeVariable(t,e,n,r)}function Gn(t,e){if(void 0===e&&(e="float32"),"complex64"===e){var n=Gn(t,"float32"),r=$n(t,"float32");return Mn(n,r)}var i=it(I(t),e);return Wt.makeTensor(i,t,e)}function $n(t,e){if(void 0===e&&(e="float32"),"complex64"===e){var n=$n(t,"float32"),r=$n(t,"float32");return Mn(n,r)}var i=at(I(t),e);return Wt.makeTensor(i,t,e)}function Kn(t,e,n){return Wt.runKernelFunc(function(r){return r.fill(t,e,n)},{})}function Xn(t,e,n){if(n<=0)throw new Error("The number of values should be positive.");return Wt.runKernelFunc(function(r){return r.linspace(t,e,n)},{})}function Yn(t,e,n,r){if(void 0===n&&(n=1),void 0===r&&(r="float32"),0===n)throw new Error("Cannot have a step of zero");if(t===e||t<e&&n<0||e<t&&n>1)return $n([0],r);var i=at(Math.abs(Math.ceil((e-t)/n)),r);e<t&&1===n&&(n=-1),i[0]=t;for(var a=1;a<i.length;a++)i[a]=i[a-1]+n;return zn(i,r)}var Jn=Dn({onesLike_:function(t){var e=xn(t,"x","onesLike");if("complex64"===e.dtype){var n=Jn(Rn(e)),r=Zn(Fn(e));return Mn(n,r)}return Wt.runKernelFunc(function(t){return t.onesLike(e)},{x:e},function(t,e){return{x:function(){return Zn(t)}}},"OnesLike")}}),Zn=Dn({zerosLike_:function(t){var e=xn(t,"x","zerosLike");return Wt.runKernelFunc(function(t){return t.zerosLike(e)},{x:e},function(t,e){return{x:function(){return Zn(t)}}},"ZerosLike")}}),Qn=Dn({concat_:function(t,e){void 0===e&&(e=0),C(t.length>=1,function(){return"Pass at least one tensor to concat"});var n=wn(t,"tensors","concat");"complex64"===n[0].dtype&&n.forEach(function(t){if("complex64"!==t.dtype)throw new Error("Cannot concatenate complex64 tensors with a tensor\n with dtype "+t.dtype+". ")}),e=z(e,n[0].shape)[0];var r=In(n.map(function(t){return t.shape}),e);if(0===I(r))return jn([],r);if(1===(n=n.filter(function(t){return t.size>0})).length)return n[0];var i=n.map(function(t){return t.shape});Tn(i,e);var a=n,o={axis:e};return Wt.runKernelFunc(function(t){return t.concat(n,e)},a,function(t){var n=i.map(function(t){return t[e]});return ir(t,n,e).map(function(t){return function(){return t}})},"Concat",o)}}),tr=Dn({concat1d_:function(t){return Qn(t,0)}}),er=Dn({concat2d_:function(t,e){return Qn(t,e)}}),nr=Dn({concat3d_:function(t,e){return Qn(t,e)}}),rr=Dn({concat4d_:function(t,e){return Qn(t,e)}}),ir=Dn({split_:function(t,e,n){void 0===n&&(n=0);var r,i=xn(t,"x","split");return n=z(n,i.shape)[0],"number"==typeof e?(C(i.shape[n]%e==0,function(){return"Number of splits must evenly divide the axis."}),r=new Array(e).fill(i.shape[n]/e)):(C(i.shape[n]===e.reduce(function(t,e){return t+e}),function(){return"The sum of sizes must match the size of the axis dimension."}),r=e),Wt.runKernelFunc(function(t){return t.split(i,r,n)},{$x:i},function(t){return{$x:function(){return Qn(t,n)}}})}});function ar(t,e,n){return void 0===e&&(e="float32"),e=e||"float32",st(t),new wt(t,e,n)}function or(t,e){void 0===e&&(e=!1),console.log(t.toString(e))}var sr=Dn({batchToSpaceND_:function(t,e,n){var r=xn(t,"x","batchToSpaceND"),i=e.reduce(function(t,e){return t*e});return C(r.rank>=1+e.length,function(){return"input rank is "+r.rank+" but should be > than blockShape.length "+e.length}),C(n.length===e.length,function(){return"crops.length is "+n.length+" but should be equal to blockShape.length "+e.length}),C(r.shape[0]%i==0,function(){return"input tensor batch is "+r.shape[0]+" but is not divisible by the product of the elements of blockShape "+e.join(" * ")+" === "+i}),Wt.runKernelFunc(function(t){return t.batchToSpaceND(r,e,n)},{$x:r},function(t){return{$x:function(){return t.spaceToBatchND(e,n)}}})}}),ur=Dn({cast_:function(t,e){var n=xn(t,"x","cast");if(!q(e))throw new Error("Failed to cast to unknown dtype "+e);if("string"===e&&"string"!==n.dtype||"string"!==e&&"string"===n.dtype)throw new Error("Only strings can be casted to strings");var r={dtype:e};return Wt.runKernelFunc(function(t){return t.cast(n,e)},{x:n},function(t){return{x:function(){return t.clone()}}},"Cast",r)}}),cr=Dn({cumsum_:function(t,e,n,r){void 0===e&&(e=0),void 0===n&&(n=!1),void 0===r&&(r=!1);var i=xn(t,"x","cumsum"),a=Cn([e|=0],i.rank),o=i;null!=a&&(o=i.transpose(a));var s=Nn(1,i.rank)[0],u=Wt.runKernelFunc(function(t){return t.cumsum(o,s,n,r)},{permutedX:o},function(t){return{permutedX:function(){return t.cumsum(e,n,!r)}}});return null!=a&&(u=u.transpose(a)),u}}),lr=Dn({depthToSpace_:function(t,e,n){void 0===n&&(n="NHWC");var r=xn(t,"x","depthToSpace"),i="NHWC"===n?r.shape[1]:r.shape[2],a="NHWC"===n?r.shape[2]:r.shape[3],o="NHWC"===n?r.shape[3]:r.shape[1];return C(i*e>=0,function(){return"Negative dimension size caused by overflow when multiplying\n "+i+" and "+e+" for depthToSpace with input shape\n "+r.shape}),C(a*e>=0,function(){return"Negative dimension size caused by overflow when multiplying\n "+a+" and "+e+" for depthToSpace with input shape\n "+r.shape}),C(o%(e*e)==0,function(){return"Dimension size must be evenly divisible by "+e*e+" but is "+o+" for depthToSpace with input shape "+r.shape}),Wt.runKernelFunc(function(t){return t.depthToSpace(r,e,n)},{$x:r})}}),fr=Dn({expandDims_:function(t,e){void 0===e&&(e=0);var n=xn(t,"x","expandDims",null);C(e<=n.rank,function(){return"Axis must be <= rank of the tensor"});var r=n.shape.slice();return e<0&&(C(-(n.rank+1)<=e,function(){return"Axis must be in the interval ["+-(n.rank+1)+", "+n.rank+"]"}),e=n.rank+e+1),r.splice(e,0,1),dr(n,r)}}),dr=Dn({reshape_:function(t,e){var n=xn(t,"x","reshape",null);e=L(e,n.size),C(n.size===I(e),function(){return"new shape and old shape must have the same number of elements."});var r={shape:e};return Wt.runKernelFunc(function(t){return t.reshape(n,e)},{x:n},function(t){return{x:function(){return t.reshape(n.shape)}}},"Reshape",r)}}),hr=Dn({spaceToBatchND_:function(t,e,n){var r=xn(t,"x","spaceToBatchND");return C(r.rank>=1+e.length,function(){return"input rank "+r.rank+" should be > than [blockShape] "+e.length}),C(n.length===e.length,function(){return"paddings.shape[0] "+n.length+" must be equal to [blockShape] "+e.length}),C(r.shape.reduce(function(t,r,i){return i>0&&i<=e.length?t&&(r+n[i-1][0]+n[i-1][1])%e[i-1]==0:t},!0),function(){return"input spatial dimensions "+r.shape.slice(1)+" with paddings "+n.toString()+" must be divisible by blockShapes "+e.toString()}),Wt.runKernelFunc(function(t){return t.spaceToBatchND(r,e,n)},{$x:r},function(t){return{$x:function(){return t.batchToSpaceND(e,n)}}})}}),pr=Dn({squeeze_:function(t,e){var n=xn(t,"x","squeeze");return dr(n,B(n.shape,e).newShape)}}),mr=Dn({stack_:function(t,e){void 0===e&&(e=0);var n=wn(t,"tensors","stack");if(C(n.length>=1,function(){return"Pass at least one tensor to tf.stack"}),1===n.length)return n[0].expandDims(e);var r=n[0].rank,i=n[0].shape,a=n[0].dtype;C(e<=r,function(){return"Axis must be <= rank of the tensor"}),n.forEach(function(t){A(i,t.shape,"All tensors passed to stack must have matching shapes")}),n.forEach(function(t){C(a===t.dtype,function(){return"All tensors passed to stack must have matching dtypes"})});var o=n.map(function(t){return t.expandDims(e)});return Qn(o,e)}}),gr=Dn({unstack_:function(t,e){void 0===e&&(e=0),e=e||0;var n=xn(t,"x","unstack");C(e>=-n.shape.length&&e<n.shape.length,function(){return"Axis = "+e+" is not in [-"+n.shape.length+", "+n.shape.length+")"}),e<0&&(e+=n.shape.length);var r={axis:e};return Wt.runKernelFunc(function(t){return t.unstack(n,e)},{x:n},function(t){return{x:function(){return mr(t,e)}}},"Unpack",r)}}),vr=function(t,e){return u(this,void 0,void 0,function(){var n,r,i,a,o,s,u,l,f,d;return c(this,function(c){switch(c.label){case 0:return n=xn(t,"x","setdiff1d"),r=xn(e,"y","setdiff1d"),C(n.dtype===r.dtype,function(){return"x and y should have the same dtype, but got x ("+n.dtype+") and y ("+r.dtype+")."}),C(1===n.rank,function(){return"x should be 1D tensor, but got x ("+n.shape+")."}),C(1===r.rank,function(){return"y should be 1D tensor, but got y ("+r.shape+")."}),[4,n.data()];case 1:return i=c.sent(),[4,r.data()];case 2:for(a=c.sent(),o=new Set(a),s=0,f=0;f<i.length;f++)o.has(i[f])||s++;for(u=new wt([s],n.dtype),l=new wt([s],"int32"),f=0,d=0;f<i.length;f++)o.has(i[f])||(u.values[d]=i[f],l.values[d]=f,d++);return[2,[u.toTensor(),l.toTensor()]]}})})};function yr(t,e,n,r){void 0===r&&(r=!0);var i=[];if(r)(i=i.concat(e.slice(0))).push(t[0]/n),i=i.concat(t.slice(1));else{i=i.concat(t[0]);for(var a=e.length,o=0;o<a;++o)i=i.concat([t[o+1]/e[o],e[o]]);i=i.concat(t.slice(a+1))}return i}function br(t,e,n){void 0===n&&(n=!0);var r=[];if(n){r.push(e);for(var i=e+1;i<t;++i)i<=2*e?(r.push(i),r.push(i-(e+1))):r.push(i)}else{var a=[],o=[];for(i=1;i<t;++i)i>=2*e+1||i%2==1?o.push(i):a.push(i);r.push.apply(r,a),r.push(0),r.push.apply(r,o)}return r}function xr(t,e,n,r){void 0===r&&(r=!0);var i=[];r?i.push(t[0]/n):i.push(t[0]*n);for(var a=1;a<t.length;++a)a<=e.length?r?i.push(e[a-1]*t[a]):i.push(t[a]/e[a-1]):i.push(t[a]);return i}function wr(t,e){for(var n=[0],r=0;r<e;++r)n.push(t[r][0]);return n}function kr(t,e,n){for(var r=t.slice(0,1),i=0;i<n;++i)r.push(t[i+1]-e[i][0]-e[i][1]);return r}var _r="Add",Er="AddN",Or="Div",Sr="FusedBatchNorm",Cr="SquaredDifference",Ar="Square",Nr="Transpose",Tr="NonMaxSuppressionV5",Ir="BroadcastTo",Dr="OneHot",Mr="Identity",Rr="Tile",Fr="PadV2",jr="FromPixels",Pr="MaxPoolWithArgmax",Lr=Dn({add_:function(t,e){var n,r=xn(t,"a","add"),i=xn(e,"b","add");n=Ft(r,i),r=n[0],i=n[1];var a={a:r,b:i};return Wt.runKernelFunc(function(t,e){var n=t.add(r,i);return e([r,i]),n},a,null,_r)}});function zr(t,e){for(var n=t.length,r=[],i=0;i<n;i++){var a=n-1-i,o=t[a]||1;(e[e.length-1-i]||1)>1&&1===o&&r.unshift(a)}return r}function Br(t,e){for(var n=[],r=0;r<e.length;r++){var i=t[t.length-r-1],a=e.length-r-1,o=e[a];(null==i||1===i&&o>1)&&n.unshift(a)}return n}function Ur(t,e){for(var n=[],r=Math.max(t.length,e.length),i=0;i<r;i++){var a=t[t.length-i-1];null==a&&(a=1);var o=e[e.length-i-1];if(null==o&&(o=1),1===a)n.unshift(o);else if(1===o)n.unshift(a);else{if(a!==o)throw Error("Operands could not be broadcast together with shapes "+t+" and "+e+".");n.unshift(a)}}return n}var Wr=Dn({abs_:function(t){var e=xn(t,"x","abs");return"complex64"===e.dtype?Wt.runKernelFunc(function(t){return t.complexAbs(e)},{$x:e}):Wt.runKernelFunc(function(t,n){var r=t.abs(e);return n([e]),r},{x:e},function(t,e){var n=e[0];return{x:function(){return t.mul(n.toFloat().step(-1))}}},"Abs")}}),Vr=Dn({acos_:function(t){var e=xn(t,"x","acos");return Wt.runKernelFunc(function(t,n){var r=t.acos(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.divStrict(Ln(1).sub(n.toFloat().square()).sqrt()).neg()}}})}}),qr=Dn({acosh_:function(t){var e=xn(t,"x","acosh");return Wt.runKernelFunc(function(t,n){var r=t.acosh(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.divStrict(n.toFloat().square().sub(1).sqrt())}}})}}),Hr=Dn({asin_:function(t){var e=xn(t,"x","asin");return Wt.runKernelFunc(function(t,n){var r=t.asin(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.divStrict(Ln(1).sub(n.toFloat().square()).sqrt())}}})}}),Gr=Dn({asinh_:function(t){var e=xn(t,"x","asinh");return Wt.runKernelFunc(function(t,n){var r=t.asinh(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.divStrict(Ln(1).add(n.toFloat().square()).sqrt())}}})}}),$r=Dn({atan_:function(t){var e=xn(t,"x","atan");return Wt.runKernelFunc(function(t,n){var r=t.atan(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.div(n.toFloat().square().add(1))}}})}}),Kr=Dn({atanh_:function(t){var e=xn(t,"x","atanh");return Wt.runKernelFunc(function(t,n){var r=t.atanh(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.div(Ln(1).sub(n.toFloat().square()))}}})}}),Xr=Dn({ceil_:function(t){var e=xn(t,"x","ceil");return Wt.runKernelFunc(function(t){return t.ceil(e)},{$x:e},function(t){return{$x:function(){return Zn(t)}}})}}),Yr=Dn({clipByValue_:function(t,e,n){var r=xn(t,"x","clipByValue");C(e<=n,function(){return"Error in clip: min ("+e+") must be less than or equal to max ("+n+")."});var i=[r],a={min:e,max:n};return Wt.runKernelFunc(function(t,i){var a=t.clip(r,e,n);return i([r]),a},{x:r},function(t,r){var i=r[0];return{x:function(){return t.where(i.greaterEqual(e).logicalAnd(i.lessEqual(n)),Zn(t))}}},"ClipByValue",a,i)}}),Jr=Dn({cos_:function(t){var e=xn(t,"x","cos"),n=[e];return Wt.runKernelFunc(function(t,n){var r=t.cos(e);return n([e]),r},{x:e},function(t,e){var n=e[0];return{x:function(){return n.toFloat().sin().neg().mul(t)}}},"Cos",{},n)}}),Zr=Dn({cosh_:function(t){var e=xn(t,"x","cosh");return Wt.runKernelFunc(function(t,n){var r=t.cosh(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return n.toFloat().sinh().mulStrict(t)}}})}}),Qr=Dn({erf_:function(t){var e=xn(t,"x","erf");return C("int32"===e.dtype||"float32"===e.dtype,function(){return"Input dtype must be `int32` or `float32`."}),"int32"===e.dtype&&(e=e.toFloat()),Wt.runKernelFunc(function(t,n){var r=t.erf(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.mul(n.square().neg().exp().mul(2/Math.sqrt(Math.PI)))}}})}}),ti=Dn({exp_:function(t){var e=xn(t,"x","exp");return Wt.runKernelFunc(function(t,n){var r=t.exp(e);return n([r]),r},{x:e},function(t,e){return{x:function(){return t.mulStrict(e[0])}}},"Exp",{},[],[!0])}}),ei=Dn({expm1_:function(t){var e=xn(t,"x","expm1");return Wt.runKernelFunc(function(t,n){var r=t.expm1(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.mul(n.exp())}}})}}),ni=Dn({floor_:function(t){var e=xn(t,"x","floor");return Wt.runKernelFunc(function(t){return t.floor(e)},{$x:e},function(t){return{$x:function(){return Zn(t)}}})}}),ri=Dn({log_:function(t){var e=xn(t,"x","log"),n=[e];return Wt.runKernelFunc(function(t,n){var r=t.log(e);return n([e]),r},{x:e},function(t,e){var n=e[0];return{x:function(){return t.div(n.toFloat())}}},"Log",{},n)}}),ii=Dn({log1p_:function(t){var e=xn(t,"x","log1p");return Wt.runKernelFunc(function(t,n){var r=t.log1p(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.div(n.add(1))}}})}}),ai=Dn({logSigmoid_:function(t){var e=xn(t,"x","logSigmoid");return Wt.runKernelFunc(function(t,n){var r=t.softplus(e.neg()).neg();return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.mul(n.neg().sigmoid())}}})}}),oi=Dn({neg_:function(t){var e=xn(t,"x","neg"),n=[e];return Wt.runKernelFunc(function(t){return t.neg(e)},{x:e},function(t){return{x:function(){return t.neg()}}},"Neg",{},n)}}),si=Dn({reciprocal_:function(t){var e=xn(t,"x","reciprocal");return Wt.runKernelFunc(function(t,n){var r=t.reciprocal(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.div(n.square().neg())}}})}}),ui=Dn({round_:function(t){var e=xn(t,"x","round");return Wt.runKernelFunc(function(t){return t.round(e)},{$x:e},function(t){return{$x:function(){return Zn(t)}}})}}),ci=Dn({rsqrt_:function(t){var e=xn(t,"x","rsqrt"),n=[e];return Wt.runKernelFunc(function(t,n){var r=t.rsqrt(e);return n([e]),r},{x:e},function(t,e){var n=e[0];return{x:function(){return t.div(n.pow(1.5).mul(2)).neg()}}},"Rsqrt",{},n)}}),li=Dn({sigmoid_:function(t){var e=xn(t,"x","sigmoid");return Wt.runKernelFunc(function(t,n){var r=t.sigmoid(e);return n([r]),r},{x:e},function(t,e){var n=e[0];return{x:function(){return t.mul(n.mul(Ln(1).sub(n)))}}},"Sigmoid")}}),fi=Dn({sign_:function(t){var e=xn(t,"x","sign");return Wt.runKernelFunc(function(t){return t.sign(e)},{$x:e},function(t){return{$x:function(){return Zn(t)}}})}}),di=Dn({isNaN_:function(t){var e=xn(t,"x","isNaN");return Wt.runKernelFunc(function(t){return t.isNaN(e)},{$x:e},function(t){return{$x:function(){return Zn(t)}}})}}),hi=Dn({isInf_:function(t){var e=xn(t,"x","isInf");return Wt.runKernelFunc(function(t){return t.isInf(e)},{$x:e},function(t){return{$x:function(){return Zn(t)}}})}}),pi=Dn({isFinite_:function(t){var e=xn(t,"x","isFinite");return Wt.runKernelFunc(function(t){return t.isFinite(e)},{$x:e},function(t){return{$x:function(){return Zn(t)}}})}}),mi=Dn({sin_:function(t){var e=xn(t,"x","sin"),n=[e];return Wt.runKernelFunc(function(t,n){var r=t.sin(e);return n([e]),r},{x:e},function(t,e){var n=e[0];return{x:function(){return n.toFloat().cos().mul(t)}}},"Sin",{},n)}}),gi=Dn({sinh_:function(t){var e=xn(t,"x","sinh");return Wt.runKernelFunc(function(t,n){var r=t.sinh(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return n.toFloat().cosh().mulStrict(t)}}})}}),vi=Dn({softplus_:function(t){var e=xn(t,"x","softplus");return Wt.runKernelFunc(function(t,n){var r=t.softplus(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.mul(n.sigmoid())}}})}}),yi=Dn({sqrt_:function(t){var e=xn(t,"x","sqrt");return Wt.runKernelFunc(function(t,n){var r=t.sqrt(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.div(n.toFloat().sqrt().mul(2))}}})}}),bi=Dn({step_:function(t,e){void 0===e&&(e=0);var n=xn(t,"x","step");return Wt.runKernelFunc(function(t){return t.step(n,e)},{$x:n},function(t){return{$x:function(){return Zn(t)}}})}}),xi=Dn({tan_:function(t){var e=xn(t,"x","tan");return Wt.runKernelFunc(function(t,n){var r=t.tan(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.div(n.cos().square())}}})}}),wi=Dn({tanh_:function(t){var e=xn(t,"x","tanh");return Wt.runKernelFunc(function(t,n){var r=t.tanh(e);return n([r]),r},{x:e},function(t,e){var n=e[0];return{x:function(){return Ln(1).sub(n.square()).mulStrict(t)}}},"Tanh",{},null,[!0])}}),ki=Dn({addStrict_:function(t,e){var n=xn(t,"a","addStrict"),r=xn(e,"b","addStrict");return A(n.shape,r.shape,"Error in addStrict: "),n.add(r)}}),_i=Dn({atan2_:function(t,e){var n,r=xn(t,"a","atan2"),i=xn(e,"b","atan2");n=Ft(r,i),r=n[0],i=n[1];var a=Ur(r.shape,i.shape);return Wt.runKernelFunc(function(t,e){var n=t.atan2(r,i);return e([r,i]),n},{$a:r,$b:i},function(t,e){var n=e[0],r=e[1];return{$a:function(){var e=Lr(n.square(),r.square()),i=t.mul(r.div(e)),o=Br(n.shape,a);return o.length>0&&(i=i.sum(o)),i.reshape(n.shape)},$b:function(){var e=Lr(n.square(),r.square()),i=oi(t.mul(n.div(e))),o=Br(r.shape,a);return o.length>0&&(i=i.sum(o)),i.reshape(r.shape)}}})}}),Ei=Dn({divStrict_:function(t,e){var n=xn(t,"a","div"),r=xn(e,"b","div");return A(n.shape,r.shape,"Error in divideStrict: "),n.div(r)}}),Oi=Dn({floorDiv_:function(t,e){var n,r=xn(t,"a","floorDiv"),i=xn(e,"b","floorDiv");n=Ft(r,i),r=n[0],i=n[1];var a=Ur(r.shape,i.shape);return Wt.runKernelFunc(function(t,e){var n=t.floorDiv(r,i);return e([r,i]),n},{a:r,b:i},function(t,e){var n=e[0],r=e[1];return{a:function(){var e=t.div(r.toFloat()),i=Br(n.shape,a);return i.length>0?e.sum(i).reshape(n.shape):e},b:function(){var e=t.mul(n.toFloat()),i=Br(r.shape,a);i.length>0&&(e=e.sum(i).reshape(r.shape));var o=r.square();return e.div(o.toFloat()).neg()}}},"FloorDiv")}}),Si=Dn({maximum_:function(t,e){var n,r=xn(t,"a","maximum"),i=xn(e,"b","maximum");return n=Ft(r,i),r=n[0],i=n[1],"bool"===r.dtype&&(r=r.toInt(),i=i.toInt()),Ur(r.shape,i.shape),Wt.runKernelFunc(function(t,e){var n=t.maximum(r,i);return e([r,i]),n},{a:r,b:i},function(t,e){var n=e[0],r=e[1];return{a:function(){return t.mul(n.greaterEqual(r).toFloat())},b:function(){return t.mul(n.less(r).toFloat())}}},"Maximum")}}),Ci=Dn({maximumStrict_:function(t,e){var n=xn(t,"a","maximumStrict"),r=xn(e,"b","maximumStrict");return A(n.shape,r.shape,"Error in maximumStrict: "),n.maximum(r)}}),Ai=Dn({minimum_:function(t,e){var n,r=xn(t,"a","minimum"),i=xn(e,"b","minimum");return n=Ft(r,i),r=n[0],i=n[1],"bool"===r.dtype&&(r=r.toInt(),i=i.toInt()),Ur(r.shape,i.shape),Wt.runKernelFunc(function(t,e){var n=t.minimum(r,i);return e([r,i]),n},{a:r,b:i},function(t,e){var n=e[0],r=e[1];return{a:function(){return t.mul(n.lessEqual(r).toFloat())},b:function(){return t.mul(n.greater(r).toFloat())}}},"Minimum")}}),Ni=Dn({minimumStrict_:function(t,e){var n=xn(t,"a","minimumStrict"),r=xn(e,"b","minimumStrict");return A(n.shape,r.shape,"Error in minimumStrict: "),n.minimum(r)}}),Ti=Dn({mod_:function(t,e){var n,r=xn(t,"a","mod"),i=xn(e,"b","mod");n=Ft(r,i),r=n[0],i=n[1];var a=Ur(r.shape,i.shape);return Wt.runKernelFunc(function(t,e){var n=t.mod(r,i);return e([r,i]),n},{$a:r,$b:i},function(t,e){var n=e[0],r=e[1];return{$a:function(){var e=Br(n.shape,a);return e.length>0?t.sum(e).reshape(n.shape):t},$b:function(){var e=t.mul(n.div(r).floor().neg()),i=Br(r.shape,a);return i.length>0?e.sum(i).reshape(r.shape):e}}})}}),Ii=Dn({modStrict_:function(t,e){var n=xn(t,"a","modStrict"),r=xn(e,"b","modStrict");return A(n.shape,r.shape,"Error in modStrict: "),n.mod(r)}}),Di=Dn({mul_:function(t,e){var n,r=xn(t,"a","mul"),i=xn(e,"b","mul");n=Ft(r,i),r=n[0],i=n[1];var a=Ur(r.shape,i.shape);return Wt.runKernelFunc(function(t,e){var n=t.multiply(r,i);return e([r,i]),n},{a:r,b:i},function(t,e){var n=e[0],r=e[1];return{a:function(){var e=t.mul(r.toFloat()),i=Br(n.shape,a);return i.length>0?e.sum(i).reshape(n.shape):e},b:function(){var e=t.mul(n.toFloat()),i=Br(r.shape,a);return i.length>0?e.sum(i).reshape(r.shape):e}}},"Mul")}}),Mi=Dn({mulStrict_:function(t,e){var n=xn(t,"a","mul"),r=xn(e,"b","mul");return A(n.shape,r.shape,"Error in multiplyStrict: "),n.mul(r)}}),Ri=Dn({pow_:function(t,e){var n,r=xn(t,"base","pow"),i=xn(e,"exp","pow");n=Ft(r,i),r=n[0],i=n[1];var a=Ur(r.shape,i.shape),o=[r,i];return Wt.runKernelFunc(function(t,e){var n=t.pow(r,i);return e([r,i,n]),n},{a:r,b:i},function(t,e){var n=e[0],r=e[1],i=e[2];return{a:function(){var e=r.toFloat(),i=t.mul(e.mul(n.pow(e.sub(Ln(1))))),o=Br(n.shape,a);return o.length>0&&(i=i.sum(o)),i.reshape(n.shape)},b:function(){var e=n.greater(0),o=n.log().where(e,Zn(n)),s=t.mul(i.mul(o)),u=Br(r.shape,a);return u.length>0&&(s=s.sum(u)),s.reshape(r.shape)}}},"Pow",{},o,[!0])}}),Fi=Dn({powStrict_:function(t,e){return A(t.shape,e.shape,"Error in powStrict: "),t.pow(e)}}),ji=Dn({squaredDifferenceStrict_:function(t,e){var n=xn(t,"a","squaredDifferenceStrict"),r=xn(e,"b","squaredDifferenceStrict");return A(n.shape,r.shape,"Error in squaredDifferenceStrict: "),n.squaredDifference(r)}}),Pi=Dn({sub_:function(t,e){var n,r=xn(t,"a","sub"),i=xn(e,"b","sub");n=Ft(r,i),r=n[0],i=n[1];var a=Ur(r.shape,i.shape);return Wt.runKernelFunc(function(t){return t.subtract(r,i)},{a:r,b:i},function(t){return{a:function(){var e=t,n=Br(r.shape,a);return n.length>0&&(e=e.sum(n)),e.reshape(r.shape)},b:function(){var e=t,n=Br(i.shape,a);return n.length>0&&(e=e.sum(n)),e.neg().reshape(i.shape)}}},"Sub")}}),Li=Dn({subStrict_:function(t,e){var n=xn(t,"a","subStrict"),r=xn(e,"b","subStrict");return A(n.shape,r.shape,"Error in subStrict: "),n.sub(r)}}),zi=Dn({div_:function(t,e){var n,r=xn(t,"a","div"),i=xn(e,"b","div");if(n=Ft(r,i),r=n[0],i=n[1],"int32"===r.dtype&&"int32"===i.dtype)return Oi(r,i);var a={a:r,b:i};return Wt.runKernelFunc(function(t,e){var n=t.realDivide(r,i);return e([r,i]),n},a,null,Or,{})}});function Bi(t,e){if(t.rank<1)throw new Error("tf.gatherND() expects the input to be rank 1 or higher, but the rank was "+t.rank+".");if(e.rank<1)throw new Error("tf.gatherND() expects the indices to be rank 1 or higher, but the rank was "+e.rank+".");if("int32"!==e.dtype)throw new Error("tf.gatherND() expects the indices to be int32 type, but the dtype was "+e.dtype+".");if(e.shape[e.rank-1]>t.rank)throw new Error("index innermost dimension length must be <= tensor rank; saw: "+e.shape[e.rank-1]+" vs. "+t.rank);if(0===t.size)throw new Error("Requested more than 0 entries, but input is empty. Input shape: "+t.shape+".");for(var n=e.shape,r=n[n.length-1],i=1,a=0;a<n.length-1;++a)i*=n[a];var o=t.shape,s=n.slice();s.pop();var u=1;for(a=r;a<t.rank;++a)u*=o[a],s.push(o[a]);var c=et(t.shape).map(function(t){return t/u}).concat([1]).slice(0,r);return[s,i,u,c]}var Ui=Object.freeze({prepareAndValidate:Bi}),Wi=30;function Vi(t){return t<=Wi?t:tt(t,Math.floor(Math.sqrt(t)))}function qi(t,e,n){var r=e.rank>1?e.shape[e.rank-1]:1,i=e.rank>1?e.rank-1:1,a="Must have updates.shape = indices.shape[:batchDim] + shape[sliceDim:], got updates.shape: "+n.shape+", indices.shape: "+e.shape+", shape: "+t+", sliceDim: "+r+", and batchDim: "+i+".";if(n.rank<i)throw new Error(a+" update.rank < "+i+". ");if(t.length<r+(n.rank-i))throw new Error(a+" Output shape length < "+(r+(n.rank-i)));if(n.rank!==i+t.length-r)throw new Error(a+" update.rank != "+(i+t.length-r));for(var o=0;o<i;++o)if(n.shape[o]!==e.shape[o])throw new Error(a+" updates.shape["+o+"] ("+n.shape[o]+") != indices.shape["+o+"] ("+e.shape[o]+").");for(o=0;o<n.rank-i;++o)if(n.shape[o+i]!==t[o+r])throw new Error(a+" updates.shape["+(o+i)+"] ("+n.shape[o+i]+") != shape["+(o+i)+"] ("+t[o+i]+")")}function Hi(t,e,n){if(e.rank<1)throw new Error("tf.scatterND() expects the indices to be rank 1 or higher, but the rank was "+e.rank+".");if(t.rank<1)throw new Error("tf.scatterND() expects the updates to be rank 1 or higher, but the rank was "+t.rank+".");if("int32"!==e.dtype)throw new Error("The dtype of 'indices' should be int32, but got dtype: "+e.dtype);if(n.length<1)throw new Error("Output rank must be greater or equal to 1, but got shape: "+n);if(0===n.length){if(0===e.size)throw new Error("Indices specified for empty output. indices shape: "+e.shape);if(0===t.size)throw new Error("Updates specified for empty output. updates shape: "+t.shape)}qi(n,e,t)}function Gi(t,e,n){for(var r=e.shape.length,i=r>1?e.shape[r-1]:1,a=n.length,o=1,s=i;s<a;++s)o*=n[s];var u=i<1?1:i;return{sliceRank:i,numUpdates:I(e.shape)/u,sliceSize:o,strides:et(n.slice(0,i)).concat([1]),outputSize:I(n)}}var $i=Object.freeze({validateUpdateShape:qi,validateInput:Hi,calculateShapes:Gi});function Ki(t,e,n){C(t.rank===e.length,function(){return"Error in slice"+t.rank+"D: Length of begin "+e+" must match the rank of the array ("+t.rank+")."}),C(t.rank===n.length,function(){return"Error in slice"+t.rank+"D: Length of size "+n+" must match the rank of the array ("+t.rank+")."});for(var r=function(r){C(e[r]+n[r]<=t.shape[r],function(){return"Error in slice"+t.rank+"D: begin["+r+"] + size["+r+"] ("+(e[r]+n[r])+") would overflow input.shape["+r+"] ("+t.shape[r]+")"})},i=0;i<t.rank;++i)r(i)}function Xi(t){for(var e=[],n=0;t>0;)1&t&&e.push(n),t/=2,n++;return e}function Yi(t,e,n){for(var r=[],i=0;i<t.length;i++)r[i]=Math.ceil((e[i]-t[i])/n[i]);return r}function Ji(t,e,n,r,i){var a=e[i],o=n[i]||1;(t&1<<i||null==a)&&(a=o>0?Number.MIN_SAFE_INTEGER:Number.MAX_SAFE_INTEGER);var s=r[i];return a<0&&(a+=s),E(0,a,s-1)}function Zi(t,e,n,r,i){var a=e[i],o=n[i]||1;(t&1<<i||null==a)&&(a=o>0?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER);var s=r[i];return a<0&&(a+=s),o>0?E(0,a,s):E(-1,a,s-1)}function Qi(t,e,n){for(var r=n.length,i=0;i<n.length;i++)if(n[i]>1){r=i;break}for(i=r+1;i<n.length;i++)if(e[i]>0||n[i]!==t[i])return!1;return!0}function ta(t,e){for(var n=t.length>0?t[t.length-1]:1,r=0;r<t.length-1;r++)n+=t[r]*e[r];return n}var ea=Object.freeze({assertParamsValid:Ki,maskToAxes:Xi,computeOutShape:Yi,startForAxis:Ji,stopForAxis:Zi,isSliceContinous:Qi,computeFlatOffset:ta});function na(t){return C(Q(t),function(){return"The f passed in grad(f) must be a function"}),function(e,n){var r=xn(e,"x","tf.grad",null),i=null!=n?xn(n,"dy","tf.grad"):null;return Wt.tidy(function(){var e=Wt.gradients(function(){return t(r)},[r],i),n=e.value,a=e.grads;return null!=i&&A(n.shape,i.shape,"The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)"),ua(a),a[0]})}}function ra(t){return C(Q(t),function(){return"The f passed in grads(f) must be a function"}),function(e,n){C(Array.isArray(e),function(){return"The args passed in grads(f)(args) must be an array of `Tensor`s or `TensorLike`s"});var r=wn(e,"args","tf.grads",null),i=null!=n?xn(n,"dy","tf.grads"):null;return Wt.tidy(function(){var e=Wt.gradients(function(){return t.apply(void 0,r)},r,i),n=e.value,a=e.grads;return null!=i&&A(n.shape,i.shape,"The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),ua(a),a})}}function ia(t){return C(Q(t),function(){return"The f passed in valueAndGrad(f) must be a function"}),function(e,n){C(e instanceof Ot,function(){return"The x passed in valueAndGrad(f)(x) must be a tensor"}),C(null==n||n instanceof Ot,function(){return"The dy passed in valueAndGrad(f)(x, dy) must be a tensor"});var r=Wt.gradients(function(){return t(e)},[e],n),i=r.grads,a=r.value;return ua(i),{grad:i[0],value:a}}}function aa(t){return C(Q(t),function(){return"The f passed in valueAndGrads(f) must be a function"}),function(e,n){C(Array.isArray(e)&&e.every(function(t){return t instanceof Ot}),function(){return"The args passed in valueAndGrads(f)(args) must be array of tensors"}),C(null==n||n instanceof Ot,function(){return"The dy passed in valueAndGrads(f)(args, dy) must be a tensor"});var r=Wt.gradients(function(){return t.apply(void 0,e)},e,n);return null!=n&&A(r.value.shape,n.shape,"The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),ua(r.grads),r}}function oa(t,e){C(Q(t),function(){return"The f passed in variableGrads(f) must be a function"}),C(null==e||Array.isArray(e)&&e.every(function(t){return t instanceof It}),function(){return"The varList passed in variableGrads(f, varList) must be an array of variables"});var n=null!=e;if(!n)for(var r in e=[],Wt.registeredVariables)e.push(Wt.registeredVariables[r]);var i=n?e.filter(function(t){return!t.trainable}):null,a=e.length;C((e=e.filter(function(t){return t.trainable})).length>0,function(){return"variableGrads() expects at least one of the input variables to be trainable, but none of the "+a+" variables is trainable."});var o=Wt.gradients(t,e,null,!0),s=o.value,u=o.grads;C(u.some(function(t){return null!=t}),function(){return"Cannot find a connection between any variable and the result of the loss function y=f(x). Please make sure the operations that use variables are inside the function f passed to minimize()."}),C(0===s.rank,function(){return"The f passed in variableGrads(f) must return a scalar, but it returned a rank-"+s.rank+" tensor"});var c={};return e.forEach(function(t,e){null!=u[e]&&(c[t.name]=u[e])}),null!=i&&i.forEach(function(t){return c[t.name]=null}),{value:s,grads:c}}function sa(t){return Wt.customGrad(t)}function ua(t){if(t.filter(function(t){return null==t}).length>0)throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that\n the f you passed encloses all operations that lead from x to y.")}var ca=Dn({softmax_:function(t,e){void 0===e&&(e=-1);var n=xn(t,"logits","softmax","float32");if(-1===e&&(e=n.rank-1),e!==n.rank-1)throw Error("Softmax along a non-last dimension is not yet supported. Logits was rank "+n.rank+" and dim was "+e);return Wt.runKernelFunc(function(t,r){var i=t.softmax(n,e);return r([i]),i},{logits:n},function(t,n){var r=n[0],i=t.mul(r);return{logits:function(){return i.sub(i.sum([e],!0).mul(r))}}},"Softmax",{dim:e},[],[!0])}}),la=Dn({logSoftmax_:function(t,e){void 0===e&&(e=-1);var n=xn(t,"logits","logSoftmax");if(-1===e&&(e=n.rank-1),e!==n.rank-1)throw Error("Log Softmax along a non-last dimension is not yet supported. Logits was rank "+n.rank+" and axis was "+e);return sa(function(t,n){var r=t.max(e,!0),i=t.sub(r),a=i.toFloat().sub(i.exp().sum(e,!0).log());return n([a]),{value:a,gradFunc:function(t,n){var r=n[0].exp();return t.sub(t.sum(e,!0).mul(r))}}})(n)}}),fa=Dn({transpose_:function(t,e){var n=xn(t,"x","transpose");if(null==e&&(e=n.shape.map(function(t,e){return e}).reverse()),C(n.rank===e.length,function(){return"Error in transpose: rank of input "+n.rank+" must match length of perm "+e+"."}),e.forEach(function(t){C(t>=0&&t<n.rank,function(){return"All entries in 'perm' must be between 0 and "+(n.rank-1)+" but got "+e})}),n.rank<=1)return n.clone();var r={perm:e};return Wt.runKernelFunc(function(t){return t.transpose(n,e)},{x:n},null,"Transpose",r)}}),da=function(){function t(t,e){this.backend=t,this.dataMover=e,this.data=new WeakMap,this.dataIdsCount=0}return t.prototype.get=function(t){return this.data.has(t)||this.dataMover.moveData(this.backend,t),this.data.get(t)},t.prototype.set=function(t,e){this.dataIdsCount++,this.data.set(t,e)},t.prototype.has=function(t){return this.data.has(t)},t.prototype.delete=function(t){return this.dataIdsCount--,this.data.delete(t)},t.prototype.numDataIds=function(){return this.dataIdsCount},t}(),ha=function(){function t(){}return t.prototype.time=function(t){return pa("time")},t.prototype.read=function(t){return pa("read")},t.prototype.readSync=function(t){return pa("readSync")},t.prototype.numDataIds=function(){return pa("numDataIds")},t.prototype.disposeData=function(t){return pa("disposeData")},t.prototype.write=function(t,e,n){return pa("write")},t.prototype.move=function(t,e,n,r){return pa("move")},t.prototype.memory=function(){return pa("memory")},t.prototype.floatPrecision=function(){return pa("floatPrecision")},t.prototype.epsilon=function(){return 32===this.floatPrecision()?1e-7:1e-4},t.prototype.batchMatMul=function(t,e,n,r){return pa("batchMatMul")},t.prototype.fusedBatchMatMul=function(t){return t.a,t.b,t.transposeA,t.transposeB,t.bias,t.activation,t.preluActivationWeights,pa("fusedBatchMatMul")},t.prototype.slice=function(t,e,n){return pa("slice")},t.prototype.stridedSlice=function(t,e,n,r){return pa("stridedSlice")},t.prototype.unstack=function(t,e){return pa("unstack")},t.prototype.reverse=function(t,e){return pa("reverse")},t.prototype.concat=function(t,e){return pa("concat")},t.prototype.neg=function(t){return pa("neg")},t.prototype.add=function(t,e){return pa("add")},t.prototype.addN=function(t){return pa("addN")},t.prototype.subtract=function(t,e){return pa("subtract")},t.prototype.multiply=function(t,e){return pa("multiply")},t.prototype.realDivide=function(t,e){return pa("realDivide")},t.prototype.floorDiv=function(t,e){return pa("floorDiv")},t.prototype.sum=function(t,e){return pa("sum")},t.prototype.prod=function(t,e){return pa("prod")},t.prototype.unsortedSegmentSum=function(t,e,n){return pa("unsortedSegmentSum")},t.prototype.argMin=function(t,e){return pa("argMin")},t.prototype.argMax=function(t,e){return pa("argMax")},t.prototype.equal=function(t,e){return pa("equal")},t.prototype.notEqual=function(t,e){return pa("notEqual")},t.prototype.less=function(t,e){return pa("less")},t.prototype.lessEqual=function(t,e){return pa("lessEqual")},t.prototype.greater=function(t,e){return pa("greater")},t.prototype.greaterEqual=function(t,e){return pa("greaterEqual")},t.prototype.logicalNot=function(t){return pa("logicalNot")},t.prototype.logicalAnd=function(t,e){return pa("logicalAnd")},t.prototype.logicalOr=function(t,e){return pa("logicalOr")},t.prototype.where=function(t){return pa("where")},t.prototype.select=function(t,e,n){return pa("select")},t.prototype.topk=function(t,e,n){return pa("topk")},t.prototype.min=function(t,e){return pa("min")},t.prototype.minimum=function(t,e){return pa("minimum")},t.prototype.mod=function(t,e){return pa("mod")},t.prototype.max=function(t,e){return pa("max")},t.prototype.maximum=function(t,e){return pa("maximum")},t.prototype.all=function(t,e){return pa("all")},t.prototype.any=function(t,e){return pa("any")},t.prototype.squaredDifference=function(t,e){return pa("squaredDifference")},t.prototype.ceil=function(t){return pa("ceil")},t.prototype.floor=function(t){return pa("floor")},t.prototype.round=function(t){return pa("round")},t.prototype.sign=function(t){return pa("sign")},t.prototype.isNaN=function(t){return pa("isNaN")},t.prototype.isInf=function(t){return pa("isInf")},t.prototype.isFinite=function(t){return pa("isFinite")},t.prototype.pow=function(t,e){return pa("pow")},t.prototype.exp=function(t){return pa("exp")},t.prototype.expm1=function(t){return pa("expm1")},t.prototype.softmax=function(t,e){return pa("softmax")},t.prototype.log=function(t){return pa("log")},t.prototype.log1p=function(t){return pa("log1p")},t.prototype.sqrt=function(t){return pa("sqrt")},t.prototype.rsqrt=function(t){return pa("rsqrt")},t.prototype.square=function(t){return pa("square")},t.prototype.reciprocal=function(t){return pa("reciprocal")},t.prototype.relu=function(t){return pa("relu")},t.prototype.relu6=function(t){return pa("relu6")},t.prototype.prelu=function(t,e){return pa("prelu")},t.prototype.elu=function(t){return pa("elu")},t.prototype.eluDer=function(t,e){return pa("eluDer")},t.prototype.selu=function(t){return pa("selu")},t.prototype.int=function(t){return pa("int")},t.prototype.clip=function(t,e,n){return pa("clip")},t.prototype.abs=function(t){return pa("abs")},t.prototype.complexAbs=function(t){return pa("complexAbs")},t.prototype.sigmoid=function(t){return pa("sigmoid")},t.prototype.softplus=function(t){return pa("softplus")},t.prototype.sin=function(t){return pa("sin")},t.prototype.cos=function(t){return pa("cos")},t.prototype.tan=function(t){return pa("tan")},t.prototype.asin=function(t){return pa("asin")},t.prototype.acos=function(t){return pa("acos")},t.prototype.atan=function(t){return pa("atan")},t.prototype.atan2=function(t,e){return pa("atan2")},t.prototype.sinh=function(t){return pa("sinh")},t.prototype.cosh=function(t){return pa("cosh")},t.prototype.tanh=function(t){return pa("tanh")},t.prototype.asinh=function(t){return pa("asinh")},t.prototype.acosh=function(t){return pa("acosh")},t.prototype.atanh=function(t){return pa("atanh")},t.prototype.erf=function(t){return pa("erf")},t.prototype.step=function(t,e){return pa("step")},t.prototype.fusedConv2d=function(t){return t.input,t.filter,t.convInfo,t.bias,t.activation,t.preluActivationWeights,pa("fusedConv2d")},t.prototype.conv2d=function(t,e,n){return pa("conv2d")},t.prototype.conv2dDerInput=function(t,e,n){return pa("conv2dDerInput")},t.prototype.conv2dDerFilter=function(t,e,n){return pa("conv2dDerFilter")},t.prototype.fusedDepthwiseConv2D=function(t){return t.input,t.filter,t.convInfo,t.bias,t.activation,t.preluActivationWeights,pa("fusedDepthwiseConv2D")},t.prototype.depthwiseConv2D=function(t,e,n){return pa("depthwiseConv2D")},t.prototype.depthwiseConv2DDerInput=function(t,e,n){return pa("depthwiseConv2DDerInput")},t.prototype.depthwiseConv2DDerFilter=function(t,e,n){return pa("depthwiseConv2DDerFilter")},t.prototype.conv3d=function(t,e,n){return pa("conv3d")},t.prototype.conv3dDerInput=function(t,e,n){return pa("conv3dDerInput")},t.prototype.conv3dDerFilter=function(t,e,n){return pa("conv3dDerFilter")},t.prototype.maxPool=function(t,e){return pa("maxPool")},t.prototype.maxPoolBackprop=function(t,e,n,r){return pa("maxPoolBackprop")},t.prototype.avgPool=function(t,e){return pa("avgPool")},t.prototype.avgPoolBackprop=function(t,e,n){return pa("avgPoolBackprop")},t.prototype.avgPool3d=function(t,e){return pa("avgPool3d")},t.prototype.avgPool3dBackprop=function(t,e,n){return pa("avgPool3dBackprop")},t.prototype.maxPool3d=function(t,e){return pa("maxPool3d")},t.prototype.maxPool3dBackprop=function(t,e,n,r){return pa("maxPool3dBackprop")},t.prototype.reshape=function(t,e){return pa("reshape")},t.prototype.cast=function(t,e){return pa("cast")},t.prototype.tile=function(t,e){return pa("tile")},t.prototype.pad=function(t,e,n){return pa("pad")},t.prototype.transpose=function(t,e){return pa("transpose")},t.prototype.gather=function(t,e,n){return pa("gather")},t.prototype.gatherND=function(t,e){return pa("gatherND")},t.prototype.scatterND=function(t,e,n){return pa("scatterND")},t.prototype.batchToSpaceND=function(t,e,n){return pa("batchToSpaceND")},t.prototype.spaceToBatchND=function(t,e,n){return pa("spaceToBatchND")},t.prototype.resizeBilinear=function(t,e,n,r){return pa("resizeBilinear")},t.prototype.resizeBilinearBackprop=function(t,e,n){return pa("resizeBilinearBackprop")},t.prototype.resizeNearestNeighbor=function(t,e,n,r){return pa("resizeNearestNeighbor")},t.prototype.resizeNearestNeighborBackprop=function(t,e,n){return pa("resizeNearestNeighborBackprop")},t.prototype.batchNormalization=function(t,e,n,r,i,a){return pa("batchNormalization")},t.prototype.localResponseNormalization4D=function(t,e,n,r,i){return pa("localResponseNormalization4D")},t.prototype.LRNGrad=function(t,e,n,r,i,a,o){return pa("LRNGrad")},t.prototype.multinomial=function(t,e,n,r){return pa("multinomial")},t.prototype.oneHot=function(t,e,n,r){return pa("oneHot")},t.prototype.cumsum=function(t,e,n,r){return pa("cumsum")},t.prototype.nonMaxSuppression=function(t,e,n,r,i){return pa("nonMaxSuppression")},t.prototype.fft=function(t){return pa("fft")},t.prototype.ifft=function(t){return pa("ifft")},t.prototype.complex=function(t,e){return pa("complex")},t.prototype.real=function(t){return pa("real")},t.prototype.imag=function(t){return pa("imag")},t.prototype.cropAndResize=function(t,e,n,r,i,a){return pa("cropAndResize")},t.prototype.depthToSpace=function(t,e,n){return pa("depthToSpace")},t.prototype.split=function(t,e,n){return pa("split")},t.prototype.sparseToDense=function(t,e,n,r){return pa("sparseToDense")},t.prototype.diag=function(t){return pa("diag")},t.prototype.fill=function(t,e,n){return pa("fill")},t.prototype.onesLike=function(t){return pa("onesLike")},t.prototype.zerosLike=function(t){return pa("zerosLike")},t.prototype.linspace=function(t,e,n){return pa("linspace")},t.prototype.dispose=function(){return pa("dispose")},t}();function pa(t){throw new Error("'"+t+"' not yet implemented or not found in the registry. Did you forget to import the kernel?")}function ma(t,e,n,r,i,a,o){void 0===o&&(o="channelsLast");var s,u=xa(e),c=u[0],l=u[1];if("channelsLast"===o)s=[c,l,t[3],t[3]];else{if("channelsFirst"!==o)throw new Error("Unknown dataFormat "+o);s=[c,l,t[1],t[1]]}return va(t,s,n,r,i,a,!1,o)}function ga(t,e,n,r,i,a,o){void 0===o&&(o="NDHWC");var s,u,c=wa(e),l=c[0],f=c[1],d=c[2];if("NDHWC"===o)u="channelsLast",s=[l,f,d,t[4],t[4]];else{if("NCDHW"!==o)throw new Error("Unknown dataFormat "+o);u="channelsFirst",s=[l,f,d,t[1],t[1]]}return ya(t,s,n,r,i,!1,u,a)}function va(t,e,n,r,i,a,o,s){void 0===o&&(o=!1),void 0===s&&(s="channelsLast");var u=[-1,-1,-1,-1],c=u[0],l=u[1],f=u[2],d=u[3];if("channelsLast"===s)c=t[0],l=t[1],f=t[2],d=t[3];else{if("channelsFirst"!==s)throw new Error("Unknown dataFormat "+s);c=t[0],d=t[1],l=t[2],f=t[3]}var h,p=e[0],m=e[1],g=e[3],v=xa(n),y=v[0],b=v[1],x=xa(r),w=x[0],k=x[1],_=ka(p,w),E=ka(m,k),O=function(t,e,n,r,i,a,o,s){var u,c,l;if("number"==typeof t){u={top:t,bottom:t,left:t,right:t,type:0===t?"VALID":"NUMBER"};var f=function(t,e,n,r,i){null==r&&(r=ba(t,e,n));var a=t[1],o=_a((t[0]-e+2*r)/n+1,i);C(M(o),function(){return"The output # of rows ("+o+") must be an integer. Change the stride and/or zero pad parameters"});var s=_a((a-e+2*r)/n+1,i);return C(M(s),function(){return"The output # of columns ("+s+") must be an integer. Change the stride and/or zero pad parameters"}),[o,s]}([e,n],a,r,t,s);c=f[0],l=f[1]}else if("same"===t){c=Math.ceil(e/r),l=Math.ceil(n/i);var d=Math.max(0,(c-1)*r+a-e),h=Math.max(0,(l-1)*i+o-n),p=Math.floor(d/2),m=d-p,g=Math.floor(h/2);u={top:p,bottom:m,left:g,right:h-g,type:"SAME"}}else{if("valid"!==t)throw Error("Unknown padding parameter: "+t);u={top:0,bottom:0,left:0,right:0,type:"VALID"},c=Math.ceil((e-a+1)/r),l=Math.ceil((n-o+1)/i)}return{padInfo:u,outHeight:c,outWidth:l}}(i,l,f,y,b,_,E,a),S=O.padInfo,A=O.outHeight,N=O.outWidth,T=o?g*d:g;return"channelsFirst"===s?h=[c,T,A,N]:"channelsLast"===s&&(h=[c,A,N,T]),{batchSize:c,dataFormat:s,inHeight:l,inWidth:f,inChannels:d,outHeight:A,outWidth:N,outChannels:T,padInfo:S,strideHeight:y,strideWidth:b,filterHeight:p,filterWidth:m,effectiveFilterHeight:_,effectiveFilterWidth:E,dilationHeight:w,dilationWidth:k,inShape:t,outShape:h,filterShape:e}}function ya(t,e,n,r,i,a,o,s){void 0===a&&(a=!1),void 0===o&&(o="channelsLast");var u=[-1,-1,-1,-1,-1],c=u[0],l=u[1],f=u[2],d=u[3],h=u[4];if("channelsLast"===o)c=t[0],l=t[1],f=t[2],d=t[3],h=t[4];else{if("channelsFirst"!==o)throw new Error("Unknown dataFormat "+o);c=t[0],h=t[1],l=t[2],f=t[3],d=t[4]}var p,m=e[0],g=e[1],v=e[2],y=e[4],b=wa(n),x=b[0],w=b[1],k=b[2],_=wa(r),E=_[0],O=_[1],S=_[2],A=ka(m,E),N=ka(g,O),T=ka(v,S),I=function(t,e,n,r,i,a,o,s,u,c,l){var f,d,h,p;if("number"==typeof t){f={top:t,bottom:t,left:t,right:t,front:t,back:t,type:0===t?"VALID":"NUMBER"};var m=function(t,e,n,r,i,a){null==i&&(i=ba(t,e,r));var o=t[1],s=t[2],u=_a((t[0]-e+2*i)/r+1,a);C(M(u),function(){return"The output # of depths ("+u+") must be an integer. Change the stride and/or zero pad parameters"});var c=_a((o-e+2*i)/r+1,a);C(M(c),function(){return"The output # of rows ("+c+") must be an integer. Change the stride and/or zero pad parameters"});var l=_a((s-e+2*i)/r+1,a);return C(M(l),function(){return"The output # of columns ("+l+") must be an integer. Change the stride and/or zero pad parameters"}),[u,c,l,1]}([e,n,r,1],s,0,i,t,l);d=m[0],h=m[1],p=m[2]}else if("same"===t){var g=((d=Math.ceil(e/i))-1)*i+s-e,v=((h=Math.ceil(n/a))-1)*a+u-n,y=((p=Math.ceil(r/o))-1)*o+c-r,b=Math.floor(g/2),x=g-b,w=Math.floor(v/2),k=v-w,_=Math.floor(y/2);f={top:w,bottom:k,left:_,right:y-_,front:b,back:x,type:"SAME"}}else{if("valid"!==t)throw Error("Unknown padding parameter: "+t);f={top:0,bottom:0,left:0,right:0,front:0,back:0,type:"VALID"},d=Math.ceil((e-s+1)/i),h=Math.ceil((n-u+1)/a),p=Math.ceil((r-c+1)/o)}return{padInfo:f,outDepth:d,outHeight:h,outWidth:p}}(i,l,f,d,x,w,k,A,N,T,s),D=I.padInfo,R=I.outDepth,F=I.outHeight,j=I.outWidth,P=a?y*h:y;return"channelsFirst"===o?p=[c,P,R,F,j]:"channelsLast"===o&&(p=[c,R,F,j,P]),{batchSize:c,dataFormat:o,inDepth:l,inHeight:f,inWidth:d,inChannels:h,outDepth:R,outHeight:F,outWidth:j,outChannels:P,padInfo:D,strideDepth:x,strideHeight:w,strideWidth:k,filterDepth:m,filterHeight:g,filterWidth:v,effectiveFilterDepth:A,effectiveFilterHeight:N,effectiveFilterWidth:T,dilationDepth:E,dilationHeight:O,dilationWidth:S,inShape:t,outShape:p,filterShape:e}}function ba(t,e,n,r){void 0===r&&(r=1);var i=ka(e,r);return Math.floor((t[0]*(n-1)-n+i)/2)}function xa(t){return"number"==typeof t?[t,t,t]:2===t.length?[t[0],t[1],1]:t}function wa(t){return"number"==typeof t?[t,t,t]:t}function ka(t,e){return e<=1?t:t+(t-1)*(e-1)}function _a(t,e){if(!e)return t;switch(e){case"round":return Math.round(t);case"ceil":return Math.ceil(t);case"floor":return Math.floor(t);default:throw new Error("Unknown roundingMode "+e)}}function Ea(t){var e=xa(t),n=e[0],r=e[1],i=e[2];return 1===n&&1===r&&1===i}function Oa(t,e){return Ea(t)||Ea(e)}function Sa(t){if("NHWC"===t)return"channelsLast";if("NCHW"===t)return"channelsFirst";throw new Error("Unknown dataFormat "+t)}function Ca(t,e,n){if("complex64"===e){if("complex64"===t.dtype)return t.clone();var r=$n(t.shape),i=t.toFloat(),a=n.complex(i,r);return r.dispose(),i.dispose(),a}if(!H(t.dtype,e))return Wt.makeTensorFromDataId(t.dataId,t.shape,e);if("complex64"===t.dtype){var o=n.real(t);return a=o.cast(e),o.dispose(),a}if("int32"===e)return n.int(t);if("bool"===e){var s=Ln(0,t.dtype);return a=n.notEqual(t,s),s.dispose(),a}throw new Error("Error in Cast: failed to cast "+t.dtype+" to "+e)}function Aa(t,e){return Wt.makeTensorFromDataId(t.dataId,e,t.dtype)}function Na(t,e,n){var r=(e-t)/(n-1),i=at(n,"float32");i[0]=t;for(var a=1;a<i.length;a++)i[a]=i[a-1]+r;return zn(i,"float32")}var Ta=Object.freeze({castTensor:Ca,reshapeTensor:Aa,linspaceImpl:Na,upcastType:Mt,axesAreInnerMostDims:kn,combineLocations:_n,computeOutAndReduceShapes:En,expandShapeToKeepDim:On,assertAxesAreInnerMostDims:Sn,getAxesPermutation:Cn,getUndoAxesPermutation:An,getInnerMostAxes:Nn,getBroadcastDims:zr,getReductionAxes:Br,assertAndGetBroadcastShape:Ur,assertParamsConsistent:Tn,computeOutShape:In,computePool2DInfo:ma,computePool3DInfo:ga,computeConv2DInfo:va,computeConv3DInfo:ya,computeDefaultPad:ba,tupleValuesAreOne:Ea,eitherStridesOrDilationsAreOne:Oa,convertConv2DDataFormat:Sa,PARALLELIZE_THRESHOLD:Wi,computeOptimalWindowSize:Vi});function Ia(t,e){if(t.length!==e.length)throw new Error("Cannot merge real and imag arrays of different lengths. real:"+t.length+", imag: "+e.length+".");for(var n=new Float32Array(2*t.length),r=0;r<n.length;r+=2)n[r]=t[r/2],n[r+1]=e[r/2];return n}function Da(t,e){return{real:t[2*e],imag:t[2*e+1]}}function Ma(t,e,n,r){t[2*r]=e,t[2*r+1]=n}function Ra(t,e,n){var r=(n?2:-2)*Math.PI*(t/e);return{real:Math.cos(r),imag:Math.sin(r)}}function Fa(t,e,n){var r=function(t,e,n){return function(t,e,n){for(var r=0,i=t.length,a=0,o=!1;r<i;){var s=n(e,t[a=r+(i-r>>>1)]);s>0?r=a+1:(i=a,o=!s)}return o?r:-r-1}(t,e,n||ja)}(t,e,n),i=r<0?-(r+1):r;t.splice(i,0,e)}function ja(t,e){return t>e?1:t<e?-1:0}function Pa(t,e,n,r,i){return za(t,e,n,r,i,0).selectedIndices}function La(t,e,n,r,i,a){var o=za(t,e,n,r,i,a,!0);return o.numValidOutputs.dispose(),{selectedIndices:o.selectedIndices,selectedScores:o.selectedScores}}function za(t,e,n,r,i,a,o,s){void 0===o&&(o=!1),void 0===s&&(s=!1);for(var u=Array.from(e).map(function(t,e){return{score:t,boxIndex:e,suppressBeginIndex:0}}).filter(function(t){return t.score>i}).sort(Wa),c=a>0?-.5/a:0,l=[],f=[];l.length<n&&u.length>0;){var d=u.pop(),h=d.score,p=d.boxIndex,m=d.suppressBeginIndex;if(h<i)break;for(var g=!1,v=l.length-1;v>=m;--v){var y=Ba(t,p,l[v]);if(y>=r){g=!0;break}if(d.score=d.score*Ua(r,c,y),d.score<=i)break}d.suppressBeginIndex=l.length,g||(d.score===h?(l.push(p),f.push(d.score)):d.score>i&&Fa(u,d,Wa))}var b=l.length;return s&&(l.fill(0,b),f.fill(0,b)),{selectedIndices:zn(l,"int32"),selectedScores:zn(f,"float32"),numValidOutputs:Ln(b,"int32")}}function Ba(t,e,n){var r=t.subarray(4*e,4*e+4),i=t.subarray(4*n,4*n+4),a=Math.min(r[0],r[2]),o=Math.min(r[1],r[3]),s=Math.max(r[0],r[2]),u=Math.max(r[1],r[3]),c=Math.min(i[0],i[2]),l=Math.min(i[1],i[3]),f=Math.max(i[0],i[2]),d=Math.max(i[1],i[3]),h=(s-a)*(u-o),p=(f-c)*(d-l);if(h<=0||p<=0)return 0;var m=Math.max(a,c),g=Math.max(o,l),v=Math.min(s,f),y=Math.min(u,d),b=Math.max(v-m,0)*Math.max(y-g,0);return b/(h+p-b)}function Ua(t,e,n){var r=Math.exp(e*n*n);return n<=t?r:0}function Wa(t,e){return t.score-e.score||t.score===e.score&&e.boxIndex-t.boxIndex}function Va(t,e,n){var r=new Array(t.rank).fill(0),i=t.shape.slice();return e.map(function(e){i[n]=e;var a=t.slice(r,i);return r[n]+=e,a})}function qa(t,e){for(var n=new Array(t.rank),r=0;r<n.length;r++)n[r]=t.shape[r]*e[r];var i=ar(n,t.dtype);for(r=0;r<i.values.length;++r){for(var a=i.indexToLoc(r),o=new Array(t.rank),s=0;s<o.length;s++)o[s]=a[s]%t.shape[s];var u=t.locToIndex(o);i.values[r]=t.values[u]}return i.toTensor()}function Ha(t,e,n,r,i){for(var a=e[e.length-1],o=[t.length/a,a],s=o[0],u=o[1],c=U(n,s*r),l=U("int32",s*r),f=0;f<s;f++){for(var d=f*u,h=t.subarray(d,d+u),p=[],m=0;m<h.length;m++)p.push({value:h[m],index:m});p.sort(function(t,e){return e.value-t.value});var g=f*r,v=c.subarray(g,g+r),y=l.subarray(g,g+r);for(m=0;m<r;m++)v[m]=p[m].value,y[m]=p[m].index}var b=e.slice();return b[b.length-1]=r,[jn(c,b,n),jn(l,b,"int32")]}function Ga(t,e){for(var n=[],r=0;r<e.length;r++)e[r]&&n.push(r);var i=ar(t,"int32"),a=ar([n.length,t.length],"int32");for(r=0;r<n.length;r++){var o=i.indexToLoc(n[r]),s=r*t.length;a.values.set(o,s)}return a.toTensor()}function $a(t,e){return["x","y","z","w","u","v"].slice(0,e).map(function(e){return t+"."+e})}function Ka(t,e){return 1===e?[t]:$a(t,e)}function Xa(){var t,e,n,r,i,a,o,s,u,c;return 2===f().getNumber("WEBGL_VERSION")?(t="#version 300 es",e="in",n="out",r="in",i="texture",a="outputColor",o="out vec4 outputColor;",s="\n bool isnan_custom(float val) {\n return (val > 0.0 || val < 0.0) ? false : val != 0.0;\n }\n\n bvec4 isnan_custom(vec4 val) {\n return bvec4(isnan_custom(val.x),\n isnan_custom(val.y), isnan_custom(val.z), isnan_custom(val.w));\n }\n\n #define isnan(value) isnan_custom(value)\n ",u="",c="\n #define round(value) newRound(value)\n int newRound(float value) {\n return int(floor(value + 0.5));\n }\n\n ivec4 newRound(vec4 value) {\n return ivec4(floor(value + vec4(0.5)));\n }\n "):(t="",e="attribute",n="varying",r="varying",i="texture2D",a="gl_FragColor",o="",s="\n #define isnan(value) isnan_custom(value)\n bool isnan_custom(float val) {\n return (val > 0. || val < 1. || val == 0.) ? false : true;\n }\n bvec4 isnan_custom(vec4 val) {\n return bvec4(isnan(val.x), isnan(val.y), isnan(val.z), isnan(val.w));\n }\n ",u="\n uniform float INFINITY;\n\n bool isinf(float val) {\n return abs(val) == INFINITY;\n }\n bvec4 isinf(vec4 val) {\n return equal(abs(val), vec4(INFINITY));\n }\n ",c="\n int round(float value) {\n return int(floor(value + 0.5));\n }\n\n ivec4 round(vec4 value) {\n return ivec4(floor(value + vec4(0.5)));\n }\n "),{version:t,attribute:e,varyingVs:n,varyingFs:r,texture2D:i,output:a,defineOutput:o,defineSpecialNaN:s,defineSpecialInf:u,defineRound:c}}function Ya(t,e,n){void 0===n&&(n="index");var r=et(e);return r.map(function(e,i){return"int "+t[i]+" = "+n+" / "+e+"; "+(i===r.length-1?"int "+t[i+1]+" = "+n+" - "+t[i]+" * "+e:"index -= "+t[i]+" * "+e)+";"}).join("")}function Ja(t){var e=et(t).map(function(t){return t.toString()});return"\n int getFlatIndex(ivec3 coords) {\n return coords.x * "+e[0]+" + coords.y * "+e[1]+" + coords.z;\n }\n"}var Za="\n const float FLOAT_MAX = 1.70141184e38;\n const float FLOAT_MIN = 1.17549435e-38;\n\n lowp vec4 encode_float(highp float v) {\n if (isnan(v)) {\n return vec4(255, 255, 255, 255);\n }\n\n highp float av = abs(v);\n\n if(av < FLOAT_MIN) {\n return vec4(0.0, 0.0, 0.0, 0.0);\n } else if(v > FLOAT_MAX) {\n return vec4(0.0, 0.0, 128.0, 127.0) / 255.0;\n } else if(v < -FLOAT_MAX) {\n return vec4(0.0, 0.0, 128.0, 255.0) / 255.0;\n }\n\n highp vec4 c = vec4(0,0,0,0);\n\n highp float e = floor(log2(av));\n highp float m = exp2(fract(log2(av))) - 1.0;\n\n c[2] = floor(128.0 * m);\n m -= c[2] / 128.0;\n c[1] = floor(32768.0 * m);\n m -= c[1] / 32768.0;\n c[0] = floor(8388608.0 * m);\n\n highp float ebias = e + 127.0;\n c[3] = floor(ebias / 2.0);\n ebias -= c[3] * 2.0;\n c[2] += floor(ebias) * 128.0;\n\n c[3] += 128.0 * step(0.0, -v);\n\n return c / 255.0;\n }\n";function Qa(t,e,n,r){var i=[];t.forEach(function(t){var e=I(t.shapeInfo.logicalShape);t.shapeInfo.isUniform?i.push("uniform float "+t.name+(e>1?"["+e+"]":"")+";"):(i.push("uniform sampler2D "+t.name+";"),i.push("uniform int offset"+t.name+";"))});var a,o,s=i.join("\n"),u=t.map(function(t){return function(t,e,n){void 0===n&&(n=!1);var r="";r+=n?function t(e){var n,r,i;switch(e.shapeInfo.logicalShape.length){case 0:return n=e.name,r="get"+n.charAt(0).toUpperCase()+n.slice(1),i=Xa(),"\n vec4 "+r+"() {\n return "+i.texture2D+"("+n+", halfCR);\n }\n ";case 1:return function(t){var e=t.name,n="get"+e.charAt(0).toUpperCase()+e.slice(1),r=t.shapeInfo.texShape,i=[Math.ceil(r[0]/2),Math.ceil(r[1]/2)],a=Xa();return"\n vec4 "+n+"(int index) {\n vec2 uv = packedUVfrom1D(\n "+i[0]+", "+i[1]+", index);\n return "+a.texture2D+"("+e+", uv);\n }\n "}(e);case 2:return function(t){var e=t.shapeInfo.logicalShape,n=t.name,r="get"+n.charAt(0).toUpperCase()+n.slice(1),i=t.shapeInfo.texShape,a=i[0],o=i[1],s=Xa();if(null!=i&&D(e,i))return"\n vec4 "+r+"(int row, int col) {\n vec2 uv = (vec2(col, row) + halfCR) / vec2("+o+".0, "+a+".0);\n\n return "+s.texture2D+"("+n+", uv);\n }\n ";var u=[Math.ceil(i[0]/2),Math.ceil(i[1]/2)],c=Math.ceil(e[1]/2);return"\n vec4 "+r+"(int row, int col) {\n vec2 uv = packedUVfrom2D("+c+", "+u[0]+", "+u[1]+", row, col);\n return "+s.texture2D+"("+n+", uv);\n }\n "}(e);case 3:return function(e){var n=e.shapeInfo.logicalShape,r=e.name,i="get"+r.charAt(0).toUpperCase()+r.slice(1),a=e.shapeInfo.texShape,o=[Math.ceil(a[0]/2),Math.ceil(a[1]/2)];if(1===n[0]){var s=n.slice(1),u=so(e,s);return"\n "+t(u)+"\n vec4 "+i+"(int b, int row, int col) {\n return "+i+"("+uo(["b","row","col"],[1,2])+");\n }\n "}var c=o[0],l=o[1],f=Math.ceil(n[2]/2),d=f*Math.ceil(n[1]/2),h=Xa();return"\n vec4 "+i+"(int b, int row, int col) {\n vec2 uv = packedUVfrom3D(\n "+c+", "+l+", "+d+", "+f+", b, row, col);\n return "+h.texture2D+"("+r+", uv);\n }\n "}(e);default:return function(t){for(var e=t.shapeInfo.logicalShape,n=e.length,r=t.name,i="get"+r.charAt(0).toUpperCase()+r.slice(1),a=t.shapeInfo.texShape,o=[Math.ceil(a[0]/2),Math.ceil(a[1]/2)],s=o[0],u=o[1],c=Math.ceil(e[n-1]/2),l=c*Math.ceil(e[n-2]/2),f="int b, int row, int col",d="b * "+l+" + (row / 2) * "+c+" + (col / 2)",h=2;h<n-1;h++)f="int b"+h+", "+f,l*=e[n-h-1],d="b"+h+" * "+l+" + "+d;var p=Xa();return"\n vec4 "+i+"("+f+") {\n int index = "+d+";\n int texR = index / "+u+";\n int texC = index - texR * "+u+";\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2("+u+", "+s+");\n return "+p.texture2D+"("+r+", uv);\n }\n "}(e)}}(t):function t(e){var n=e.shapeInfo.logicalShape;switch(n.length){case 0:return function(t){var e=t.name,n="get"+e.charAt(0).toUpperCase()+e.slice(1);if(t.shapeInfo.isUniform)return"float "+n+"() {return "+e+";}";var r=t.shapeInfo.texShape,i=r[0],a=r[1];if(1===i&&1===a)return"\n float "+n+"() {\n return sampleTexture("+e+", halfCR);\n }\n ";var o=t.shapeInfo.texShape,s=o[0],u=o[1],c=io(e);return"\n float "+n+"() {\n vec2 uv = uvFromFlat("+s+", "+u+", "+c+");\n return sampleTexture("+e+", uv);\n }\n "}(e);case 1:return function(t){var e=t.name,n="get"+e.charAt(0).toUpperCase()+e.slice(1);if(t.shapeInfo.isUniform)return"\n float "+n+"(int index) {\n "+ao(t)+"\n }\n ";var r=t.shapeInfo.texShape,i=r[0],a=r[1];if(1===a&&1===i)return"\n float "+n+"(int index) {\n return sampleTexture("+e+", halfCR);\n }\n ";var o=io(e);return 1===a?"\n float "+n+"(int index) {\n vec2 uv = vec2(0.5, (float(index + "+o+") + 0.5) / "+i+".0);\n return sampleTexture("+e+", uv);\n }\n ":1===i?"\n float "+n+"(int index) {\n vec2 uv = vec2((float(index + "+o+") + 0.5) / "+a+".0, 0.5);\n return sampleTexture("+e+", uv);\n }\n ":"\n float "+n+"(int index) {\n vec2 uv = uvFromFlat("+i+", "+a+", index + "+o+");\n return sampleTexture("+e+", uv);\n }\n "}(e);case 2:return function(e){var n=e.shapeInfo.logicalShape,r=e.name,i="get"+r.charAt(0).toUpperCase()+r.slice(1),a=e.shapeInfo.texShape;if(null!=a&&D(n,a)){var o=a[0],s=a[1];return"\n float "+i+"(int row, int col) {\n vec2 uv = (vec2(col, row) + halfCR) / vec2("+s+".0, "+o+".0);\n return sampleTexture("+r+", uv);\n }\n "}var u=B(n),c=u.newShape,l=u.keptDims,f=c;if(f.length<n.length){var d=so(e,f);return"\n "+t(d)+"\n float "+i+"(int row, int col) {\n return "+i+"("+uo(["row","col"],l)+");\n }\n "}if(e.shapeInfo.isUniform)return"\n float "+i+"(int row, int col) {\n int index = round(dot(vec2(row, col), vec2("+n[1]+", 1)));\n "+ao(e)+"\n }\n ";var h=a[0],p=a[1],m=io(r);return 1===p?"\n float "+i+"(int row, int col) {\n float index = dot(vec3(row, col, "+m+"), vec3("+n[1]+", 1, 1));\n vec2 uv = vec2(0.5, (index + 0.5) / "+h+".0);\n return sampleTexture("+r+", uv);\n }\n ":1===h?"\n float "+i+"(int row, int col) {\n float index = dot(vec3(row, col, "+m+"), vec3("+n[1]+", 1, 1));\n vec2 uv = vec2((index + 0.5) / "+p+".0, 0.5);\n return sampleTexture("+r+", uv);\n }\n ":"\n float "+i+"(int row, int col) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * "+n[1]+" + col + "+m+";\n vec2 uv = uvFromFlat("+h+", "+p+", index);\n return sampleTexture("+r+", uv);\n }\n"}(e);case 3:return function(e){var n=e.shapeInfo.logicalShape,r=e.name,i="get"+r.charAt(0).toUpperCase()+r.slice(1),a=n[1]*n[2],o=n[2],s=B(n),u=s.newShape,c=s.keptDims,l=u;if(l.length<n.length){var f=so(e,l);return"\n "+t(f)+"\n float "+i+"(int row, int col, int depth) {\n return "+i+"("+uo(["row","col","depth"],c)+");\n }\n "}if(e.shapeInfo.isUniform)return"\n float "+i+"(int row, int col, int depth) {\n int index = round(dot(vec3(row, col, depth),\n vec3("+a+", "+o+", 1)));\n "+ao(e)+"\n }\n ";var d=e.shapeInfo.texShape,h=d[0],p=d[1],m=e.shapeInfo.flatOffset;if(p===a&&null==m)return"\n float "+i+"(int row, int col, int depth) {\n float texR = float(row);\n float texC = dot(vec2(col, depth), vec2("+o+", 1));\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2("+p+".0, "+h+".0);\n return sampleTexture("+r+", uv);\n }\n ";if(p===o&&null==m)return"\n float "+i+"(int row, int col, int depth) {\n float texR = dot(vec2(row, col), vec2("+n[1]+", 1));\n float texC = float(depth);\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2("+p+".0, "+h+".0);\n return sampleTexture("+r+", uv);\n }\n ";var g=io(r);return"\n float "+i+"(int row, int col, int depth) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * "+a+" + col * "+o+" + depth + "+g+";\n vec2 uv = uvFromFlat("+h+", "+p+", index);\n return sampleTexture("+r+", uv);\n }\n "}(e);case 4:return function(e){var n=e.shapeInfo.logicalShape,r=e.name,i="get"+r.charAt(0).toUpperCase()+r.slice(1),a=n[3],o=n[2]*a,s=n[1]*o,u=B(n),c=u.newShape,l=u.keptDims;if(c.length<n.length){var f=so(e,c);return"\n "+t(f)+"\n float "+i+"(int row, int col, int depth, int depth2) {\n return "+i+"("+uo(["row","col","depth","depth2"],l)+");\n }\n "}if(e.shapeInfo.isUniform)return"\n float "+i+"(int row, int col, int depth, int depth2) {\n int index = round(dot(vec4(row, col, depth, depth2),\n vec4("+s+", "+o+", "+a+", 1)));\n "+ao(e)+"\n }\n ";var d=e.shapeInfo.flatOffset,h=e.shapeInfo.texShape,p=h[0],m=h[1];if(m===s&&null==d)return"\n float "+i+"(int row, int col, int depth, int depth2) {\n float texR = float(row);\n float texC =\n dot(vec3(col, depth, depth2),\n vec3("+o+", "+a+", 1));\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2("+m+".0, "+p+".0);\n return sampleTexture("+r+", uv);\n }\n ";if(m===a&&null==d)return"\n float "+i+"(int row, int col, int depth, int depth2) {\n float texR = dot(vec3(row, col, depth),\n vec3("+n[1]*n[2]+", "+n[2]+", 1));\n float texC = float(depth2);\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2("+m+".0, "+p+".0);\n return sampleTexture("+r+", uv);\n }\n ";var g=io(r);return"\n float "+i+"(int row, int col, int depth, int depth2) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * "+s+" + col * "+o+" +\n depth * "+a+" + depth2;\n vec2 uv = uvFromFlat("+p+", "+m+", index + "+g+");\n return sampleTexture("+r+", uv);\n }\n "}(e);case 5:return function(e){var n=e.shapeInfo.logicalShape,r=e.name,i="get"+r.charAt(0).toUpperCase()+r.slice(1),a=n[4],o=n[3]*a,s=n[2]*o,u=n[1]*s,c=B(n),l=c.newShape,f=c.keptDims;if(l.length<n.length){var d=so(e,l);return"\n "+t(d)+"\n float "+i+"(int row, int col, int depth, int depth2, int depth3) {\n return "+i+"("+uo(["row","col","depth","depth2","depth3"],f)+");\n }\n "}if(e.shapeInfo.isUniform)return"\n float "+i+"(int row, int col, int depth, int depth2, int depth3) {\n float index = dot(\n vec4(row, col, depth, depth2),\n vec4("+u+", "+s+", "+o+", "+a+")) +\n depth3;\n "+ao(e)+"\n }\n ";var h=e.shapeInfo.flatOffset,p=e.shapeInfo.texShape,m=p[0],g=p[1];if(g===u&&null==h)return"\n float "+i+"(int row, int col, int depth, int depth2, int depth3) {\n int texR = row;\n float texC = dot(vec4(col, depth, depth2, depth3),\n vec4("+s+", "+o+", "+a+", 1));\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2("+g+".0, "+m+".0);\n return sampleTexture("+r+", uv);\n }\n ";if(g===a&&null==h)return"\n float "+i+"(int row, int col, int depth, int depth2, int depth3) {\n float texR = dot(\n vec4(row, col, depth, depth2),\n vec4("+n[1]*n[2]*n[3]+",\n "+n[2]*n[3]+", "+n[3]+", 1));\n int texC = depth3;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2("+g+".0, "+m+".0);\n return sampleTexture("+r+", uv);\n }\n ";var v=io(r);return"\n float "+i+"(int row, int col, int depth, int depth2, int depth3) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * "+u+" + col * "+s+" + depth * "+o+" +\n depth2 * "+a+" + depth3 + "+v+";\n vec2 uv = uvFromFlat("+m+", "+g+", index);\n return sampleTexture("+r+", uv);\n }\n "}(e);case 6:return function(e){var n=e.shapeInfo.logicalShape,r=e.name,i="get"+r.charAt(0).toUpperCase()+r.slice(1),a=B(n),o=a.newShape,s=a.keptDims;if(o.length<n.length){var u=so(e,o);return"\n "+t(u)+"\n float "+i+"(int row, int col, int depth,\n int depth2, int depth3, int depth4) {\n return "+i+"("+uo(["row","col","depth","depth2","depth3","depth4"],s)+");\n }\n "}var c=n[5],l=n[4]*c,f=n[3]*l,d=n[2]*f,h=n[1]*d;if(e.shapeInfo.isUniform)return"\n float "+i+"(int row, int col, int depth,\n int depth2, int depth3, int depth4) {\n int index = round(dot(\n vec4(row, col, depth, depth2),\n vec4("+h+", "+d+", "+f+", "+l+")) +\n dot(\n vec2(depth3, depth4),\n vec2("+c+", 1)));\n "+ao(e)+"\n }\n ";var p=e.shapeInfo.flatOffset,m=e.shapeInfo.texShape,g=m[0],v=m[1];if(v===h&&null==p)return"\n float "+i+"(int row, int col, int depth,\n int depth2, int depth3, int depth4) {\n int texR = row;\n float texC = dot(vec4(col, depth, depth2, depth3),\n vec4("+d+", "+f+", "+l+", "+c+")) +\n float(depth4);\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2("+v+".0, "+g+".0);\n return sampleTexture("+r+", uv);\n }\n ";if(v===c&&null==p)return"\n float "+i+"(int row, int col, int depth,\n int depth2, int depth3, int depth4) {\n float texR = dot(vec4(row, col, depth, depth2),\n vec4("+n[1]*n[2]*n[3]*n[4]+",\n "+n[2]*n[3]*n[4]+",\n "+n[3]*n[4]+",\n "+n[4]+")) + float(depth3);\n int texC = depth4;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2("+v+".0, "+g+".0);\n return sampleTexture("+r+", uv);\n }\n ";var y=io(r);return"\n float "+i+"(int row, int col, int depth,\n int depth2, int depth3, int depth4) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * "+h+" + col * "+d+" + depth * "+f+" +\n depth2 * "+l+" + depth3 * "+c+" + depth4 + "+y+";\n vec2 uv = uvFromFlat("+g+", "+v+", index);\n return sampleTexture("+r+", uv);\n }\n "}(e);default:throw new Error(n.length+"-D input sampling is not yet supported")}}(t);var i=t.shapeInfo.logicalShape,a=e.logicalShape;return i.length<=a.length&&(r+=n?function(t,e){var n,r=t.name,i=r.charAt(0).toUpperCase()+r.slice(1),a="get"+i+"AtOutCoords",o=t.shapeInfo.logicalShape.length,s=e.logicalShape.length,u=zr(t.shapeInfo.logicalShape,e.logicalShape),c=oo(s),l=s-o,f=["x","y","z","w","u","v"];n=0===o?"":s<2&&u.length>=1?"coords = 0;":u.map(function(t){return"coords."+f[t+l]+" = 0;"}).join("\n");var d;d=s<2&&o>0?"coords":t.shapeInfo.logicalShape.map(function(t,e){return"coords."+f[e+l]}).join(", ");var h="return outputValue;",p=1===I(t.shapeInfo.logicalShape),m=1===I(e.logicalShape);if(1!==o||p||m){if(p&&!m)h=1===s?"\n return vec4(outputValue.x, outputValue.x, 0., 0.);\n ":"\n return vec4(outputValue.x);\n ";else if(u.length){var g=o-2,v=o-1;u.indexOf(g)>-1&&u.indexOf(v)>-1?h="return vec4(outputValue.x);":u.indexOf(g)>-1?h="return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);":u.indexOf(v)>-1&&(h="return vec4(outputValue.xx, outputValue.zz);")}}else h="\n return vec4(outputValue.xy, outputValue.xy);\n ";return"\n vec4 "+a+"() {\n "+c+" coords = getOutputCoords();\n "+n+"\n vec4 outputValue = get"+i+"("+d+");\n "+h+"\n }\n "}(t,e):function(t,e){var n=t.name,r=n.charAt(0).toUpperCase()+n.slice(1),i="get"+r+"AtOutCoords",a=e.texShape,o=t.shapeInfo.texShape,s=t.shapeInfo.logicalShape.length,u=e.logicalShape.length;if(!t.shapeInfo.isUniform&&s===u&&null==t.shapeInfo.flatOffset&&D(o,a))return"\n float "+i+"() {\n return sampleTexture("+n+", resultUV);\n }\n ";var c=oo(u),l=zr(t.shapeInfo.logicalShape,e.logicalShape),f=u-s,d=["x","y","z","w","u","v"];return"\n float "+i+"() {\n "+c+" coords = getOutputCoords();\n "+(0===s?"":u<2&&l.length>=1?"coords = 0;":l.map(function(t){return"coords."+d[t+f]+" = 0;"}).join("\n"))+"\n return get"+r+"("+(u<2&&s>0?"coords":t.shapeInfo.logicalShape.map(function(t,e){return"coords."+d[e+f]}).join(", "))+");\n }\n "}(t,e)),r}(t,e,r)}).join("\n"),c=e.texShape,l=Xa(),f="\n float sampleTexture(sampler2D textureSampler, vec2 uv) {\n return "+l.texture2D+"(textureSampler, uv).r;\n }\n ",d=function(t){return t.version+"\n precision highp float;\n precision highp int;\n precision highp sampler2D;\n "+t.varyingFs+" vec2 resultUV;\n "+t.defineOutput+"\n const vec2 halfCR = vec2(0.5, 0.5);\n\n struct ivec5\n {\n int x;\n int y;\n int z;\n int w;\n int u;\n };\n\n struct ivec6\n {\n int x;\n int y;\n int z;\n int w;\n int u;\n int v;\n };\n\n uniform float NAN;\n "+t.defineSpecialNaN+"\n "+t.defineSpecialInf+"\n "+t.defineRound+"\n\n int imod(int x, int y) {\n return x - y * (x / y);\n }\n\n int idiv(int a, int b, float sign) {\n int res = a / b;\n int mod = imod(a, b);\n if (sign < 0. && mod != 0) {\n res -= 1;\n }\n return res;\n }\n\n //Based on the work of Dave Hoskins\n //https://www.shadertoy.com/view/4djSRW\n #define HASHSCALE1 443.8975\n float random(float seed){\n vec2 p = resultUV * seed;\n vec3 p3 = fract(vec3(p.xyx) * HASHSCALE1);\n p3 += dot(p3, p3.yzx + 19.19);\n return fract((p3.x + p3.y) * p3.z);\n }\n\n "+to+"\n "+eo+"\n "+no+"\n "}(l);return e.isPacked?(a=function(t,e){switch(t.length){case 0:return"\n int getOutputCoords() {\n return 0;\n }\n ";case 1:return function(t,e){var n=[Math.ceil(e[0]/2),Math.ceil(e[1]/2)];return 1===n[0]?"\n int getOutputCoords() {\n return 2 * int(resultUV.x * "+n[1]+".0);\n }\n ":1===n[1]?"\n int getOutputCoords() {\n return 2 * int(resultUV.y * "+n[0]+".0);\n }\n ":"\n int getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+n[0]+", "+n[1]+"));\n return 2 * (resTexRC.x * "+n[1]+" + resTexRC.y);\n }\n "}(0,e);case 2:return function(t,e){var n=[Math.ceil(e[0]/2),Math.ceil(e[1]/2)];if(D(t,e))return"\n ivec2 getOutputCoords() {\n return 2 * ivec2(resultUV.yx * vec2("+n[0]+", "+n[1]+"));\n }\n ";var r=Math.ceil(t[1]/2);return"\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+n[0]+", "+n[1]+"));\n\n int index = resTexRC.x * "+n[1]+" + resTexRC.y;\n int r = 2 * (index / "+r+");\n int c = imod(index, "+r+") * 2;\n\n return ivec2(r, c);\n }\n "}(t,e);case 3:return n=t,r=e,i=[Math.ceil(r[0]/2),Math.ceil(r[1]/2)],o=(a=Math.ceil(n[2]/2))*Math.ceil(n[1]/2),"\n ivec3 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+i[0]+", "+i[1]+"));\n int index = resTexRC.x * "+i[1]+" + resTexRC.y;\n\n int b = index / "+o+";\n index -= b * "+o+";\n\n int r = 2 * (index / "+a+");\n int c = imod(index, "+a+") * 2;\n\n return ivec3(b, r, c);\n }\n ";default:return function(t,e){for(var n=[Math.ceil(e[0]/2),Math.ceil(e[1]/2)],r=Math.ceil(t[t.length-1]/2),i=r*Math.ceil(t[t.length-2]/2),a=i,o="",s="b, r, c",u=2;u<t.length-1;u++)o="\n int b"+u+" = index / "+(a*=t[t.length-u-1])+";\n index -= b"+u+" * "+a+";\n "+o,s="b"+u+", "+s;return"\n ivec"+t.length+" getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+n[0]+", "+n[1]+"));\n int index = resTexRC.x * "+n[1]+" + resTexRC.y;\n\n "+o+"\n\n int b = index / "+i+";\n index -= b * "+i+";\n\n int r = 2 * (index / "+r+");\n int c = imod(index, "+r+") * 2;\n\n return ivec"+t.length+"("+s+");\n }\n "}(t,e)}var n,r,i,a,o}(e.logicalShape,c),o="\n void setOutput(vec4 val) {\n "+l.output+" = val;\n }\n "):(a=function(t,e){switch(t.length){case 0:return"\n int getOutputCoords() {\n return 0;\n }\n ";case 1:return function(t,e){return 1===e[0]?"\n int getOutputCoords() {\n return int(resultUV.x * "+e[1]+".0);\n }\n ":1===e[1]?"\n int getOutputCoords() {\n return int(resultUV.y * "+e[0]+".0);\n }\n ":"\n int getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+e[0]+", "+e[1]+"));\n return resTexRC.x * "+e[1]+" + resTexRC.y;\n }\n "}(0,e);case 2:return function(t,e){return D(t,e)?"\n ivec2 getOutputCoords() {\n return ivec2(resultUV.yx * vec2("+e[0]+", "+e[1]+"));\n }\n ":1===t[1]?"\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+e[0]+", "+e[1]+"));\n int index = resTexRC.x * "+e[1]+" + resTexRC.y;\n return ivec2(index, 0);\n }\n ":1===t[0]?"\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+e[0]+", "+e[1]+"));\n int index = resTexRC.x * "+e[1]+" + resTexRC.y;\n return ivec2(0, index);\n }\n ":"\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+e[0]+", "+e[1]+"));\n int index = resTexRC.x * "+e[1]+" + resTexRC.y;\n int r = index / "+t[1]+";\n int c = index - r * "+t[1]+";\n return ivec2(r, c);\n }\n "}(t,e);case 3:return n=e,r=Ya(["r","c","d"],t),"\n ivec3 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+n[0]+", "+n[1]+"));\n int index = resTexRC.x * "+n[1]+" + resTexRC.y;\n "+r+"\n return ivec3(r, c, d);\n }\n ";case 4:return function(t,e){var n=Ya(["r","c","d","d2"],t);return"\n ivec4 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+e[0]+", "+e[1]+"));\n int index = resTexRC.x * "+e[1]+" + resTexRC.y;\n "+n+"\n return ivec4(r, c, d, d2);\n }\n "}(t,e);case 5:return function(t,e){var n=Ya(["r","c","d","d2","d3"],t);return"\n ivec5 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx * vec2("+e[0]+",\n "+e[1]+"));\n\n int index = resTexRC.x * "+e[1]+" + resTexRC.y;\n\n "+n+"\n\n ivec5 outShape = ivec5(r, c, d, d2, d3);\n return outShape;\n }\n "}(t,e);case 6:return function(t,e){var n=Ya(["r","c","d","d2","d3","d4"],t);return"\n ivec6 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+e[0]+", "+e[1]+"));\n int index = resTexRC.x * "+e[1]+" + resTexRC.y;\n\n "+n+"\n\n ivec6 result = ivec6(r, c, d, d2, d3, d4);\n return result;\n }\n "}(t,e);default:throw new Error(t.length+"-D output sampling is not yet supported")}var n,r}(e.logicalShape,c),o="\n void setOutput(float val) {\n "+l.output+" = vec4(val, 0, 0, 0);\n }\n "),r&&(d+=ro),[d,f,o,s,a,u,n].join("\n")}var to="\nvec2 uvFromFlat(int texNumR, int texNumC, int index) {\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\nvec2 packedUVfrom1D(int texNumR, int texNumC, int index) {\n int texelIndex = index / 2;\n int texR = texelIndex / texNumC;\n int texC = texelIndex - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n",eo="\nvec2 packedUVfrom2D(int texelsInLogicalRow, int texNumR,\n int texNumC, int row, int col) {\n int texelIndex = (row / 2) * texelsInLogicalRow + (col / 2);\n int texR = texelIndex / texNumC;\n int texC = texelIndex - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n",no="\nvec2 packedUVfrom3D(int texNumR, int texNumC,\n int texelsInBatch, int texelsInLogicalRow, int b,\n int row, int col) {\n int index = b * texelsInBatch + (row / 2) * texelsInLogicalRow + (col / 2);\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n",ro="\n float getChannel(vec4 frag, vec2 innerDims) {\n vec2 modCoord = mod(innerDims, 2.);\n return modCoord.x == 0. ?\n (modCoord.y == 0. ? frag.r : frag.g) :\n (modCoord.y == 0. ? frag.b : frag.a);\n }\n float getChannel(vec4 frag, int dim) {\n float modCoord = mod(float(dim), 2.);\n return modCoord == 0. ? frag.r : frag.g;\n }\n";function io(t){return"offset"+t}function ao(t){var e=t.name,n=I(t.shapeInfo.logicalShape);return n<2?"return "+e+";":"\n for (int i = 0; i < "+n+"; i++) {\n if (i == index) {\n return "+e+"[i];\n }\n }\n "}function oo(t){if(t<=1)return"int";if(2===t)return"ivec2";if(3===t)return"ivec3";if(4===t)return"ivec4";if(5===t)return"ivec5";if(6===t)return"ivec6";throw Error("GPU for rank "+t+" is not yet supported")}function so(t,e){var n=JSON.parse(JSON.stringify(t));return n.shapeInfo.logicalShape=e,n}function uo(t,e){return e.map(function(e){return t[e]}).join(", ")}var co=function(t,e,n){this.variableNames=["AReal","AImag","BReal","BImag"],this.outputShape=Ur(e,n),this.userCode="\n float binaryOpComplex(\n float areal, float aimag, float breal, float bimag) {\n "+t+"\n }\n\n void main() {\n float areal = getARealAtOutCoords();\n float aimag = getAImagAtOutCoords();\n float breal = getBRealAtOutCoords();\n float bimag = getBImagAtOutCoords();\n setOutput(binaryOpComplex(areal, aimag, breal, bimag));\n }\n "},lo="return a + b;",fo="return a - b;",ho="return a * b;",po="return (a < 0.) ? b * a : a;",mo=function(t,e,n){this.variableNames=["A","B"],this.outputShape=Ur(e,n),this.userCode="\n float binaryOperation(float a, float b) {\n "+t+"\n }\n\n void main() {\n float a = getAAtOutCoords();\n float b = getBAtOutCoords();\n setOutput(binaryOperation(a, b));\n }\n "},go="\n vec4 aLessThanZero = vec4(lessThan(a, vec4(0.)));\n return (aLessThanZero * (b * a)) + ((vec4(1.0) - aLessThanZero) * a);\n",vo=function(t,e,n,r){void 0===r&&(r=!1),this.variableNames=["A","B"],this.supportsBroadcasting=!0,this.packedInputs=!0,this.packedOutput=!0,this.outputShape=Ur(e,n);var i=this.outputShape.length,a="";if(r)if(0===i||1===I(this.outputShape))a="\n result.y = 0.;\n result.z = 0.;\n result.w = 0.;\n ";else if(a="\n "+oo(i)+" coords = getOutputCoords();\n ",1===i)a+="\n result.y = (coords + 1) >= "+this.outputShape[0]+" ? 0. : result.y;\n result.z = 0.;\n result.w = 0.;\n ";else{var o=Ka("coords",i);a+="\n bool nextRowOutOfBounds =\n ("+o[i-2]+" + 1) >= "+this.outputShape[i-2]+";\n bool nextColOutOfBounds =\n ("+o[i-1]+" + 1) >= "+this.outputShape[i-1]+";\n result.y = nextColOutOfBounds ? 0. : result.y;\n result.z = nextRowOutOfBounds ? 0. : result.z;\n result.w = nextColOutOfBounds || nextRowOutOfBounds ? 0. : result.w;\n "}this.userCode="\n vec4 binaryOperation(vec4 a, vec4 b) {\n "+t+"\n }\n\n void main() {\n vec4 a = getAAtOutCoords();\n vec4 b = getBAtOutCoords();\n\n vec4 result = binaryOperation(a, b);\n "+a+"\n\n setOutput(result);\n }\n "},yo=function(){function t(t){this.variableNames=["A"],this.outputShape=t,this.userCode="\n uniform float minVal;\n uniform float maxVal;\n\n void main() {\n float value = getAAtOutCoords();\n if (isnan(value)) {\n setOutput(value);\n return;\n }\n\n setOutput(clamp(value, minVal, maxVal));\n }\n "}return t.prototype.getCustomSetupFunc=function(t,e){var n=this;return function(r,i){null==n.minLoc&&(n.minLoc=r.getUniformLocationNoThrow(i,"minVal"),n.maxLoc=r.getUniformLocationNoThrow(i,"maxVal")),r.gl.uniform1f(n.minLoc,t),r.gl.uniform1f(n.maxLoc,e)}},t}(),bo=function(){function t(t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t,this.userCode="\n uniform float minVal;\n uniform float maxVal;\n\n void main() {\n vec4 value = getAAtOutCoords();\n\n if (any(isnan(value))) {\n setOutput(value);\n return;\n }\n\n setOutput(clamp(value, vec4(minVal), vec4(maxVal)));\n }\n "}return t.prototype.getCustomSetupFunc=function(t,e){var n=this;return function(r,i){null==n.minLoc&&(n.minLoc=r.getUniformLocationNoThrow(i,"minVal"),n.maxLoc=r.getUniformLocationNoThrow(i,"maxVal")),r.gl.uniform1f(n.minLoc,t),r.gl.uniform1f(n.maxLoc,e)}},t}();function xo(t,e,n){var r=t.indexOf(e);return t.map(function(t,e){return e===r?t+" - "+n:t}).join()}var wo=function(t,e,n,r){void 0===e&&(e=!1),void 0===n&&(n=null),void 0===r&&(r=!1),this.variableNames=["x","W"],this.outputShape=t.outShape;var i=t.padInfo.top,a=t.padInfo.left,o=t.strideHeight,s=t.strideWidth,u=t.dilationHeight,c=t.dilationWidth,l=t.filterHeight,f=t.filterWidth,d=4*Math.floor(t.inChannels/4),h=t.inChannels%4,p="channelsLast"===t.dataFormat,m=p?1:2,g=p?2:3,v=p?3:1,y="",b="";n&&(y=r?"float activation(float a) {\n float b = getPreluActivationWeightsAtOutCoords();\n "+n+"\n }":"\n float activation(float x) {\n "+n+"\n }\n ",b="result = activation(result);");var x=e?"result += getBiasAtOutCoords();":"";e&&this.variableNames.push("bias"),r&&this.variableNames.push("preluActivationWeights"),this.userCode="\n "+y+"\n\n const ivec2 strides = ivec2("+o+", "+s+");\n const ivec2 pads = ivec2("+i+", "+a+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d2 = coords["+v+"];\n\n ivec2 xRCCorner =\n ivec2(coords["+m+"], coords["+g+"]) * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // Convolve x(?, ?, d1) with w(:, :, d1, d2) to get y(yR, yC, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < "+l+"; wR++) {\n int xR = xRCorner + wR * "+u+";\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int wC = 0; wC < "+f+"; wC++) {\n int xC = xCCorner + wC * "+c+";\n\n if (xC < 0 || xC >= "+t.inWidth+") {\n continue;\n }\n\n for (int d1 = 0; d1 < "+d+"; d1 += 4) {\n vec4 wValues = vec4(\n getW(wR, wC, d1, d2),\n getW(wR, wC, d1 + 1, d2),\n getW(wR, wC, d1 + 2, d2),\n getW(wR, wC, d1 + 3, d2)\n );\n\n if ("+p+") {\n vec4 xValues = vec4(\n getX(batch, xR, xC, d1),\n getX(batch, xR, xC, d1 + 1),\n getX(batch, xR, xC, d1 + 2),\n getX(batch, xR, xC, d1 + 3)\n );\n dotProd += dot(xValues, wValues);\n } else {\n vec4 xValues = vec4(\n getX(batch, d1, xR, xC),\n getX(batch, d1 + 1, xR, xC),\n getX(batch, d1 + 2, xR, xC),\n getX(batch, d1 + 3, xR, xC)\n );\n dotProd += dot(xValues, wValues);\n }\n }\n\n if ("+(1===h)+") {\n\n if ("+p+") {\n dotProd +=\n getX(batch, xR, xC, "+d+") *\n getW(wR, wC, "+d+", d2);\n } else {\n dotProd +=\n getX(batch, "+d+", xR, xC) *\n getW(wR, wC, "+d+", d2);\n }\n\n } else if ("+(2===h)+") {\n vec2 wValues = vec2(\n getW(wR, wC, "+d+", d2),\n getW(wR, wC, "+d+" + 1, d2)\n );\n\n if ("+p+") {\n vec2 xValues = vec2(\n getX(batch, xR, xC, "+d+"),\n getX(batch, xR, xC, "+d+" + 1)\n );\n dotProd += dot(xValues, wValues);\n } else {\n vec2 xValues = vec2(\n getX(batch, "+d+", xR, xC),\n getX(batch, "+d+" + 1, xR, xC)\n );\n dotProd += dot(xValues, wValues);\n }\n\n } else if ("+(3===h)+") {\n vec3 wValues = vec3(\n getW(wR, wC, "+d+", d2),\n getW(wR, wC, "+d+" + 1, d2),\n getW(wR, wC, "+d+" + 2, d2)\n );\n\n if ("+p+") {\n vec3 xValues = vec3(\n getX(batch, xR, xC, "+d+"),\n getX(batch, xR, xC, "+d+" + 1),\n getX(batch, xR, xC, "+d+" + 2)\n );\n dotProd += dot(xValues, wValues);\n } else {\n vec3 xValues = vec3(\n getX(batch, "+d+", xR, xC),\n getX(batch, "+d+" + 1, xR, xC),\n getX(batch, "+d+" + 2, xR, xC)\n );\n dotProd += dot(xValues, wValues);\n }\n\n }\n }\n }\n\n float result = dotProd;\n "+x+"\n "+b+"\n setOutput(result);\n }\n "},ko=function(t,e,n,r){void 0===e&&(e=!1),void 0===n&&(n=null),void 0===r&&(r=!1),this.variableNames=["x","W"],this.outputShape=t.outShape;var i=t.inHeight,a=t.inWidth,o=t.padInfo.top,s=t.padInfo.left,u=t.strideHeight,c=t.strideWidth,l=t.dilationHeight,f=t.dilationWidth,d=t.filterHeight,h=t.filterWidth,p=t.outChannels/t.inChannels,m="",g="";n&&(m=r?"float activation(float a) {\n float b = getPreluActivationWeightsAtOutCoords();\n "+n+"\n }":"\n float activation(float x) {\n "+n+"\n }\n ",g="result = activation(result);");var v=e?"result += getBiasAtOutCoords();":"";e&&this.variableNames.push("bias"),r&&this.variableNames.push("preluActivationWeights"),this.userCode="\n "+m+"\n\n const ivec2 strides = ivec2("+u+", "+c+");\n const ivec2 pads = ivec2("+o+", "+s+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords.x;\n ivec2 xRCCorner = coords.yz * strides - pads;\n int d2 = coords.w;\n int d1 = d2 / "+p+";\n int q = d2 - d1 * "+p+";\n\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // Convolve x(?, ?, d1) with w(:, :, d1, q) to get y(yR, yC, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n // TO DO(dsmilkov): Flatten the two for loops and vec4 the operations.\n for (int wR = 0; wR < "+d+"; wR++) {\n int xR = xRCorner + wR * "+l+";\n\n if (xR < 0 || xR >= "+i+") {\n continue;\n }\n\n for (int wC = 0; wC < "+h+"; wC++) {\n int xC = xCCorner + wC * "+f+";\n\n if (xC < 0 || xC >= "+a+") {\n continue;\n }\n\n float xVal = getX(batch, xR, xC, d1);\n float wVal = getW(wR, wC, d1, q);\n dotProd += xVal * wVal;\n }\n }\n\n float result = dotProd;\n "+v+"\n "+g+"\n setOutput(result);\n }\n "},_o=function(t,e,n,r){void 0===e&&(e=!1),void 0===n&&(n=null),void 0===r&&(r=!1),this.variableNames=["x","W"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t.outShape;for(var i=t.inHeight,a=t.inWidth,o=t.padInfo.top,s=t.padInfo.left,u=t.strideHeight,c=t.strideWidth,l=t.dilationHeight,f=t.dilationWidth,d=t.filterHeight,h=t.filterWidth,p=h,m="int xR; int xC; int xCOffset;",g=0;g<d;g++)for(var v=0;v<h;v++)m+="\n vec4 xTexelR"+g+"C"+2*v+" = vec4(0.);\n vec4 wR"+g+"C"+v+" = vec4(0.);\n vec4 xR"+g+"C"+v+" = vec4(0.);";for(g=0;g<d;g++)for(var y=0;y<p;y++){if(m+="\n xR = xRCorner + "+g*l+";\n xC = xCCorner + "+(v=2*y)*f+";\n ",1===c){if(v<h&&(m+=s%2==1?"\n xCOffset = xC + 1;\n if(xR >= 0 && xR < "+i+" && xCOffset >= 0 && xCOffset < "+a+") {\n xTexelR"+g+"C"+v+" = getX(batch, xR, xCOffset, d1);\n\n // Need to manually clear unused channels in case\n // we're reading from recycled texture.\n if(xCOffset + 1 >= "+a+") {\n xTexelR"+g+"C"+v+".zw = vec2(0.);\n }\n } else {\n xTexelR"+g+"C"+v+" = vec4(0.);\n }\n\n xCOffset = xC + 1 - 2;\n if(xR >= 0 && xR < "+i+" && xCOffset >= 0 && xCOffset < "+a+") {\n vec4 previous = getX(batch, xR, xCOffset, d1);\n\n // Need to manually clear unused channels in case\n // we're reading from recycled texture.\n if(xCOffset + 1 >= "+a+") {\n previous.zw = vec2(0.);\n }\n\n xR"+g+"C"+v+" = vec4(previous.zw, xTexelR"+g+"C"+v+".xy);\n } else {\n xR"+g+"C"+v+" = vec4(0, 0, xTexelR"+g+"C"+v+".xy);\n }\n ":"\n if(xR >= 0 && xR < "+i+" && xC >= 0 && xC < "+a+") {\n xTexelR"+g+"C"+v+" = getX(batch, xR, xC, d1);\n } else {\n xTexelR"+g+"C"+v+" = vec4(0.);\n }\n\n xR"+g+"C"+v+" = xTexelR"+g+"C"+v+";\n ",v+1<h)){var b=s%2==0?O(f):f;f%2==0&&s%2==1||f%2!=0&&s%2!=1?(m+="\n xCOffset = xC + "+s%2+" + "+b+";\n\n if(xR >= 0 && xR < "+i+" &&\n xCOffset >= 0 && xCOffset < "+a+") {\n xTexelR"+g+"C"+(v+2)+" = getX(batch, xR, xCOffset, d1);\n }\n ",f>1&&(m+="\n xCOffset -= 2;\n if(xR >= 0 && xR < "+i+" &&\n xCOffset >= 0 && xCOffset < "+a+") {\n xTexelR"+g+"C"+v+" = getX(batch, xR, xCOffset, d1);\n } else {\n xTexelR"+g+"C"+v+" = vec4(0.);\n }\n "),m+="\n xR"+g+"C"+(v+1)+" = vec4(\n xTexelR"+g+"C"+v+".zw, xTexelR"+g+"C"+(v+2)+".xy);\n "):m+="\n xCOffset = xC + "+b+";\n\n if(xR >= 0 && xR < "+i+" &&\n xCOffset >= 0 && xCOffset < "+a+") {\n xTexelR"+g+"C"+(v+2)+" = getX(batch, xR, xCOffset, d1);\n }\n\n xR"+g+"C"+(v+1)+" = xTexelR"+g+"C"+(v+2)+";\n "}}else v<h&&(m+="\n if(xR >= 0 && xR < "+i+") {\n ",s%2==1?(m+="\n xCOffset = xC + 1 - "+c+";\n if(xCOffset >= 0 && xCOffset < "+a+") {\n xTexelR"+g+"C"+v+" = getX(batch, xR, xCOffset, d1);\n } else {\n xTexelR"+g+"C"+v+" = vec4(0.);\n }\n\n if(xC + 1 >= 0 && xC + 1 < "+a+") {\n xTexelR"+g+"C"+(v+2)+" = getX(batch, xR, xC + 1, d1);\n } else {\n xTexelR"+g+"C"+(v+2)+" = vec4(0.);\n }\n\n xR"+g+"C"+v+" = vec4(\n xTexelR"+g+"C"+v+".zw, xTexelR"+g+"C"+(v+2)+".zw);\n ",v+1<h&&(m+="\n vec4 final = vec4(0.);\n xCOffset = xC + 1 + "+c+";\n if(xCOffset >= 0 && xCOffset < "+a+") {\n final = getX(batch, xR, xCOffset, d1);\n }\n xR"+g+"C"+(v+1)+" = vec4(xTexelR"+g+"C"+(v+2)+".xy, final.xy);\n ")):(m+="\n if(xC >= 0 && xC < "+a+") {\n xTexelR"+g+"C"+v+" = getX(batch, xR, xC, d1);\n } else {\n xTexelR"+g+"C"+v+" = vec4(0.);\n }\n\n xCOffset = xC + "+c+";\n if(xCOffset >= 0 && xCOffset < "+a+") {\n xTexelR"+g+"C"+(v+2)+" = getX(batch, xR, xCOffset, d1);\n } else {\n xTexelR"+g+"C"+(v+2)+" = vec4(0.);\n }\n\n xR"+g+"C"+v+" = vec4(\n xTexelR"+g+"C"+v+".xy, xTexelR"+g+"C"+(v+2)+".xy);\n ",v+1<h&&(m+="\n xR"+g+"C"+(v+1)+" = vec4(\n xTexelR"+g+"C"+v+".zw, xTexelR"+g+"C"+(v+2)+".zw);\n ")),m+="}");v<h&&(m+="\n vec4 wTexelR"+g+"C"+v+" = getW("+g+", "+v+", d1, q);\n wR"+g+"C"+v+" = vec4(wTexelR"+g+"C"+v+".xz, wTexelR"+g+"C"+v+".xz);\n ",v+1<h&&(m+="\n vec4 wTexelR"+g+"C"+(v+1)+" = getW("+g+", "+(v+1)+", d1, q);\n wR"+g+"C"+(v+1)+" =\n vec4(wTexelR"+g+"C"+(v+1)+".xz, wTexelR"+g+"C"+(v+1)+".xz);"))}for(g=0;g<d;g++)for(v=0;v<h;v++)m+="dotProd += xR"+g+"C"+v+" * wR"+g+"C"+v+";";var x="",w="";n&&(x=r?"vec4 activation(vec4 a) {\n vec4 b = getPreluActivationWeightsAtOutCoords();\n "+n+"\n }":"vec4 activation(vec4 x) {\n "+n+"\n }",w="result = activation(result);");var k=e?"result += getBiasAtOutCoords();":"";e&&this.variableNames.push("bias"),r&&this.variableNames.push("preluActivationWeights"),this.userCode="\n "+x+"\n\n const ivec2 strides = ivec2("+u+", "+c+");\n const ivec2 pads = ivec2("+o+", "+s+");\n\n void main() {\n\n ivec4 coords = getOutputCoords();\n int batch = coords.x;\n ivec2 xRCCorner = coords.yz * strides - pads;\n int d2 = coords.w;\n int d1 = d2;\n int q = 0;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n vec4 dotProd = vec4(0.);\n\n "+m+"\n\n vec4 result = dotProd;\n "+k+"\n "+w+"\n setOutput(result);\n }\n "};function Eo(t,e){if(1===t)return""+e;if(2===t)return e+".y";if(3===t)return e+".z";if(4===t)return e+".w";throw Error("Cumulative sum for rank "+t+" is not yet supported")}var Oo=function(){function t(t,e,n){this.variableNames=["x"],this.outputShape=[],this.outputShape=t,this.blockSize=e,this.dataFormat=n,this.userCode="\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int h = "+this.getHeightCoordString()+";\n int w = "+this.getWidthCoordString()+";\n int d = "+this.getDepthCoordString()+";\n\n int in_h = h / "+e+";\n int offset_h = imod(h, "+e+");\n int in_w = w / "+e+";\n int offset_w = imod(w, "+e+");\n int offset_d = (offset_h * "+e+" + offset_w) *\n "+this.getOutputDepthSize()+";\n int in_d = d + offset_d;\n\n float result = "+this.getInputSamplingString()+";\n setOutput(result);\n }\n "}return t.prototype.getHeightCoordString=function(){return"NHWC"===this.dataFormat?"coords[1]":"coords[2]"},t.prototype.getWidthCoordString=function(){return"NHWC"===this.dataFormat?"coords[2]":"coords[3]"},t.prototype.getDepthCoordString=function(){return"NHWC"===this.dataFormat?"coords[3]":"coords[1]"},t.prototype.getOutputDepthSize=function(){return"NHWC"===this.dataFormat?this.outputShape[3]:this.outputShape[1]},t.prototype.getInputSamplingString=function(){return"NHWC"===this.dataFormat?"getX(b, in_h, in_w, in_d)":"getX(b, in_d, in_h, in_w)"},t}(),So=function(t,e,n){this.variableNames=["real","imag"];var r=e[1];this.outputShape=e;var i=n?"2.0 * "+Math.PI:"-2.0 * "+Math.PI,a=n?r+".0":"1.0";this.userCode="\n const float exponentMultiplier = "+i+";\n\n float unaryOpComplex(float real, float expR, float imag, float expI) {\n "+t+"\n }\n\n float mulMatDFT(int batch, int index) {\n float indexRatio = float(index) / float("+r+");\n float exponentMultiplierTimesIndexRatio =\n exponentMultiplier * indexRatio;\n\n float result = 0.0;\n\n for (int i = 0; i < "+r+"; i++) {\n // x = (-2|2 * PI / N) * index * i;\n float x = exponentMultiplierTimesIndexRatio * float(i);\n float expR = cos(x);\n float expI = sin(x);\n float real = getReal(batch, i);\n float imag = getImag(batch, i);\n\n result +=\n unaryOpComplex(real, expR, imag, expI) / "+a+";\n }\n\n return result;\n }\n\n void main() {\n ivec2 coords = getOutputCoords();\n setOutput(mulMatDFT(coords[0], coords[1]));\n }\n "},Co=function(){function t(t,e){this.outputShape=[],this.variableNames=["x"],this.outputShape=t,this.userCode="\n uniform float value;\n void main() {\n // Input can be obtained from uniform value.\n setOutput(value);\n }\n "}return t.prototype.getCustomSetupFunc=function(t){var e=this;return function(n,r){null==e.valueLoc&&(e.valueLoc=n.getUniformLocationNoThrow(r,"value")),n.gl.uniform1f(e.valueLoc,t)}},t}();function Ao(t,e){var n=Xa();return ue(t,e,n.version+"\n precision highp float;\n "+n.attribute+" vec3 clipSpacePos;\n "+n.attribute+" vec2 uv;\n "+n.varyingVs+" vec2 resultUV;\n\n void main() {\n gl_Position = vec4(clipSpacePos, 1);\n resultUV = uv;\n }")}function No(t,e){return ge(t,e,new Float32Array([-1,1,0,0,1,-1,-1,0,0,0,1,1,0,1,1,1,-1,0,1,0]))}function To(t,e){return ve(t,e,new Uint16Array([0,1,2,2,1,3]))}function Io(t,e,n,r,i,a,o){be(n,r);var s=ye(t,e),u=t.TEXTURE_2D;return ne(t,e,function(){return t.bindTexture(u,s)}),ne(t,e,function(){return t.texParameteri(u,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE)}),ne(t,e,function(){return t.texParameteri(u,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE)}),ne(t,e,function(){return t.texParameteri(u,t.TEXTURE_MIN_FILTER,t.NEAREST)}),ne(t,e,function(){return t.texParameteri(u,t.TEXTURE_MAG_FILTER,t.NEAREST)}),ne(t,e,function(){return t.texImage2D(u,0,i,n,r,0,a,o,null)}),ne(t,e,function(){return t.bindTexture(t.TEXTURE_2D,null)}),s}function Do(t,e,n,r,i){var a=Zt(n,r);return Io(t,e,a[0],a[1],i.internalFormatFloat,i.textureFormatFloat,t.FLOAT)}function Mo(t,e,n,r,i){var a=Zt(n,r);return Io(t,e,a[0],a[1],i.internalFormatHalfFloat,i.textureFormatFloat,i.textureTypeHalfFloat)}function Ro(t,e,n,r,i){var a=Zt(n,r);return Io(t,e,a[0],a[1],t.RGBA,t.RGBA,t.UNSIGNED_BYTE)}function Fo(t,e,n,r,i){var a=te(n,r);return Io(t,e,a[0],a[1],i.internalFormatPackedFloat,t.RGBA,t.FLOAT)}function jo(t,e,n,r,i){var a=te(n,r);return Io(t,e,a[0],a[1],i.internalFormatPackedHalfFloat,t.RGBA,i.textureTypeHalfFloat)}function Po(t,e,n,r){return ne(t,e,function(){return t.bindBuffer(t.ARRAY_BUFFER,r)}),we(t,e,n,"clipSpacePos",r,3,20,0)&&we(t,e,n,"uv",r,2,20,12)}function Lo(t,e,n,r,i,a,o){var s,u,c;ne(t,e,function(){return t.bindTexture(t.TEXTURE_2D,n)}),a instanceof Uint8Array?(s=new Uint8Array(r*i*4),u=t.UNSIGNED_BYTE,c=t.RGBA):(s=new Float32Array(r*i*4),u=t.FLOAT,c=o.internalFormatPackedFloat),s.set(a),ne(t,e,function(){return t.texImage2D(t.TEXTURE_2D,0,c,r,i,0,t.RGBA,u,s)}),ne(t,e,function(){return t.bindTexture(t.TEXTURE_2D,null)})}function zo(t,e,n,r){ne(t,e,function(){return t.bindTexture(t.TEXTURE_2D,n)}),r.data instanceof Uint8Array?ne(t,e,function(){return t.texImage2D(t.TEXTURE_2D,0,t.RGBA,r.width,r.height,0,t.RGBA,t.UNSIGNED_BYTE,r.data)}):ne(t,e,function(){return t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,r)}),ne(t,e,function(){return t.bindTexture(t.TEXTURE_2D,null)})}function Bo(t,e,n,r,i){var a=t.createBuffer();ne(t,e,function(){return t.bindBuffer(t.PIXEL_PACK_BUFFER,a)});var o=16*n*r;return ne(t,e,function(){return t.bufferData(t.PIXEL_PACK_BUFFER,o,t.STREAM_READ)}),ne(t,e,function(){return t.readPixels(0,0,r,n,t.RGBA,t.FLOAT,0)}),ne(t,e,function(){return t.bindBuffer(t.PIXEL_PACK_BUFFER,null)}),a}function Uo(t,e,n){var r=t,i=new Float32Array(n);return r.bindBuffer(r.PIXEL_PACK_BUFFER,e),r.getBufferSubData(r.PIXEL_PACK_BUFFER,0,i),r.bindBuffer(r.PIXEL_PACK_BUFFER,null),i}function Wo(t,e,n,r,i){var a=Zt(n,r),o=a[0],s=a[1],u=new Uint8Array(n*r*4);return ne(t,e,function(){return t.readPixels(0,0,o,s,i.downloadTextureFormat,t.UNSIGNED_BYTE,u)}),new Float32Array(u.buffer)}function Vo(t,e,n,r,i,a,o,s){var u=t,c=new Float32Array(function(t,e){var n=te(a,o);return n[0]*n[1]*4}());return u.bindBuffer(u.PIXEL_PACK_BUFFER,e),u.getBufferSubData(u.PIXEL_PACK_BUFFER,0,c),u.bindBuffer(u.PIXEL_PACK_BUFFER,null),c}function qo(t,e,n,r){var i=new Float32Array(n*r*4);return ne(t,e,function(){return t.readPixels(0,0,r,n,t.RGBA,t.FLOAT,i)}),i}var Ho=Object.freeze({createVertexShader:Ao,createVertexBuffer:No,createIndexBuffer:To,createFloat32MatrixTexture:Do,createFloat16MatrixTexture:Mo,createUnsignedBytesMatrixTexture:Ro,createPackedMatrixTexture:Fo,createFloat16PackedMatrixTexture:jo,bindVertexProgramAttributeStreams:Po,uploadDenseMatrixToTexture:Lo,uploadPixelDataToTexture:zo,createBufferFromOutputTexture:Bo,downloadFloat32MatrixFromBuffer:Uo,downloadByteEncodedFloatMatrixFromOutputTexture:Wo,downloadPackedMatrixFromBuffer:Vo,downloadMatrixFromPackedOutputTexture:qo}),Go=function(){function t(t){this.outputTexture=null,this.program=null,this.disposed=!1,this.vertexAttrsAreBound=!1,this.itemsToPoll=[];var e=f().getNumber("WEBGL_VERSION");null!=t?(this.gl=t,Yt(e,t)):this.gl=Jt(e);var n="WEBGL_color_buffer_float";if(1===f().getNumber("WEBGL_VERSION")){if(this.textureFloatExtension=se(this.gl,this.debug,"OES_texture_float"),Ue(this.gl,"OES_texture_half_float"))this.textureHalfFloatExtension=se(this.gl,this.debug,"OES_texture_half_float");else if(f().get("WEBGL_FORCE_F16_TEXTURES"))throw new Error("GL context does not support half float textures, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true.");if(this.colorBufferFloatExtension=this.gl.getExtension(n),Ue(this.gl,"EXT_color_buffer_half_float"))this.colorBufferHalfFloatExtension=se(this.gl,this.debug,"EXT_color_buffer_half_float");else if(f().get("WEBGL_FORCE_F16_TEXTURES"))throw new Error("GL context does not support color renderable half floats, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true.")}else if(n="EXT_color_buffer_float",Ue(this.gl,n))this.colorBufferFloatExtension=this.gl.getExtension(n);else{if(!Ue(this.gl,"EXT_color_buffer_half_float"))throw new Error("GL context does not support color renderable floats");this.colorBufferHalfFloatExtension=this.gl.getExtension("EXT_color_buffer_half_float")}this.vertexBuffer=No(this.gl,this.debug),this.indexBuffer=To(this.gl,this.debug),this.framebuffer=xe(this.gl,this.debug),this.textureConfig=ee(this.gl,this.textureHalfFloatExtension)}return Object.defineProperty(t.prototype,"debug",{get:function(){return f().getBool("DEBUG")},enumerable:!0,configurable:!0}),t.prototype.dispose=function(){var t=this;if(!this.disposed){null!=this.program&&console.warn("Disposing a GPGPUContext that still has a bound WebGLProgram. This is probably a resource leak, delete the program with GPGPUContext.deleteProgram before disposing."),null!=this.outputTexture&&console.warn("Disposing a GPGPUContext that still has a bound output matrix texture. This is probably a resource leak, delete the output matrix texture with GPGPUContext.deleteMatrixTexture before disposing.");var e=this.gl;ne(e,this.debug,function(){return e.finish()}),ne(e,this.debug,function(){return e.bindFramebuffer(e.FRAMEBUFFER,null)}),ne(e,this.debug,function(){return e.deleteFramebuffer(t.framebuffer)}),ne(e,this.debug,function(){return e.bindBuffer(e.ARRAY_BUFFER,null)}),ne(e,this.debug,function(){return e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null)}),ne(e,this.debug,function(){return e.deleteBuffer(t.indexBuffer)}),this.disposed=!0}},t.prototype.createFloat32MatrixTexture=function(t,e){return this.throwIfDisposed(),Do(this.gl,this.debug,t,e,this.textureConfig)},t.prototype.createFloat16MatrixTexture=function(t,e){return this.throwIfDisposed(),Mo(this.gl,this.debug,t,e,this.textureConfig)},t.prototype.createUnsignedBytesMatrixTexture=function(t,e){return this.throwIfDisposed(),Ro(this.gl,this.debug,t,e,this.textureConfig)},t.prototype.uploadPixelDataToTexture=function(t,e){this.throwIfDisposed(),zo(this.gl,this.debug,t,e)},t.prototype.uploadDenseMatrixToTexture=function(t,e,n,r){this.throwIfDisposed(),Lo(this.gl,this.debug,t,e,n,r,this.textureConfig)},t.prototype.createFloat16PackedMatrixTexture=function(t,e){return this.throwIfDisposed(),jo(this.gl,this.debug,t,e,this.textureConfig)},t.prototype.createPackedMatrixTexture=function(t,e){return this.throwIfDisposed(),Fo(this.gl,this.debug,t,e,this.textureConfig)},t.prototype.deleteMatrixTexture=function(t){var e=this;this.throwIfDisposed(),this.outputTexture===t&&(Ce(this.gl,this.debug,this.framebuffer),this.outputTexture=null),ne(this.gl,this.debug,function(){return e.gl.deleteTexture(t)})},t.prototype.downloadByteEncodedFloatMatrixFromOutputTexture=function(t,e,n){var r=this;return this.downloadMatrixDriver(t,function(){return Wo(r.gl,r.debug,e,n,r.textureConfig)})},t.prototype.downloadPackedMatrixFromBuffer=function(t,e,n,r,i,a){return Vo(this.gl,t,0,0,0,i,a,this.textureConfig)},t.prototype.downloadFloat32MatrixFromBuffer=function(t,e){return Uo(this.gl,t,e)},t.prototype.createBufferFromTexture=function(t,e,n){this.bindTextureToFrameBuffer(t);var r=Bo(this.gl,this.debug,e,n,this.textureConfig);return this.unbindTextureToFrameBuffer(),r},t.prototype.createAndWaitForFence=function(){var t=this.createFence(this.gl);return this.pollFence(t)},t.prototype.createFence=function(t){var e,n,r=this;if(f().getBool("WEBGL_FENCE_API_ENABLED")){var i=t,a=i.fenceSync(i.SYNC_GPU_COMMANDS_COMPLETE,0);t.flush(),n=function(){var t=i.clientWaitSync(a,0,0);return t===i.ALREADY_SIGNALED||t===i.CONDITION_SATISFIED},e=a}else f().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")>0?(e=this.beginQuery(),this.endQuery(),n=function(){return r.isQueryAvailable(e,f().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))}):n=function(){return!0};return{query:e,isFencePassed:n}},t.prototype.downloadMatrixFromPackedTexture=function(t,e,n){var r=this;return this.downloadMatrixDriver(t,function(){return qo(r.gl,r.debug,e,n)})},t.prototype.createProgram=function(t){this.throwIfDisposed();var e=this.gl,n=ce(e,this.debug,t),r=Ao(e,this.debug),i=he(e,this.debug);return ne(e,this.debug,function(){return e.attachShader(i,r)}),ne(e,this.debug,function(){return e.attachShader(i,n)}),pe(e,this.debug,i),this.debug&&me(e,this.debug,i),this.vertexAttrsAreBound||(this.setProgram(i),this.vertexAttrsAreBound=Po(e,this.debug,this.program,this.vertexBuffer)),i},t.prototype.deleteProgram=function(t){var e=this;this.throwIfDisposed(),t===this.program&&(this.program=null),null!=t&&ne(this.gl,this.debug,function(){return e.gl.deleteProgram(t)})},t.prototype.setProgram=function(t){var e=this;this.throwIfDisposed(),this.program=t,null!=this.program&&this.debug&&me(this.gl,this.debug,this.program),ne(this.gl,this.debug,function(){return e.gl.useProgram(t)})},t.prototype.getUniformLocation=function(t,e,n){return void 0===n&&(n=!0),this.throwIfDisposed(),n?_e(this.gl,this.debug,t,e):Ee(this.gl,t,e)},t.prototype.getAttributeLocation=function(t,e){var n=this;return this.throwIfDisposed(),ne(this.gl,this.debug,function(){return n.gl.getAttribLocation(t,e)})},t.prototype.getUniformLocationNoThrow=function(t,e){return this.throwIfDisposed(),this.gl.getUniformLocation(t,e)},t.prototype.setInputMatrixTexture=function(t,e,n){this.throwIfDisposed(),this.throwIfNoProgram(),Oe(this.gl,this.debug,this.program,t,e,n)},t.prototype.setOutputMatrixTexture=function(t,e,n){this.setOutputMatrixTextureDriver(t,n,e)},t.prototype.setOutputPackedMatrixTexture=function(t,e,n){this.throwIfDisposed();var r=te(e,n),i=r[0],a=r[1];this.setOutputMatrixTextureDriver(t,i,a)},t.prototype.setOutputMatrixWriteRegion=function(t,e,n,r){this.setOutputMatrixWriteRegionDriver(n,t,r,e)},t.prototype.setOutputPackedMatrixWriteRegion=function(t,e,n,r){throw new Error("setOutputPackedMatrixWriteRegion not implemented.")},t.prototype.debugValidate=function(){null!=this.program&&me(this.gl,this.debug,this.program),Ae(this.gl)},t.prototype.executeProgram=function(){this.throwIfDisposed(),this.throwIfNoProgram();var t=this.gl;this.debug&&this.debugValidate(),ne(t,this.debug,function(){return t.drawElements(t.TRIANGLES,6,t.UNSIGNED_SHORT,0)})},t.prototype.blockUntilAllProgramsCompleted=function(){var t=this;this.throwIfDisposed(),ne(this.gl,this.debug,function(){return t.gl.finish()})},t.prototype.getQueryTimerExtension=function(){return null==this.disjointQueryTimerExtension&&(this.disjointQueryTimerExtension=se(this.gl,this.debug,2===f().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")?"EXT_disjoint_timer_query_webgl2":"EXT_disjoint_timer_query")),this.disjointQueryTimerExtension},t.prototype.getQueryTimerExtensionWebGL2=function(){return this.getQueryTimerExtension()},t.prototype.getQueryTimerExtensionWebGL1=function(){return this.getQueryTimerExtension()},t.prototype.beginQuery=function(){if(2===f().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")){var t=this.gl,e=this.getQueryTimerExtensionWebGL2(),n=t.createQuery();return t.beginQuery(e.TIME_ELAPSED_EXT,n),n}var r=this.getQueryTimerExtensionWebGL1(),i=r.createQueryEXT();return r.beginQueryEXT(r.TIME_ELAPSED_EXT,i),i},t.prototype.endQuery=function(){if(2!==f().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")){var t=this.getQueryTimerExtensionWebGL1();t.endQueryEXT(t.TIME_ELAPSED_EXT)}else{var e=this.gl,n=this.getQueryTimerExtensionWebGL2();e.endQuery(n.TIME_ELAPSED_EXT)}},t.prototype.waitForQueryAndGetTime=function(t){return u(this,void 0,void 0,function(){var e=this;return c(this,function(n){switch(n.label){case 0:return[4,P(function(){return e.disposed||e.isQueryAvailable(t,f().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))})];case 1:return n.sent(),[2,this.getQueryTime(t,f().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))]}})})},t.prototype.getQueryTime=function(t,e){if(0===e)return null;if(2===e){var n=this.gl;return n.getQueryParameter(t,n.QUERY_RESULT)/1e6}var r=this.getQueryTimerExtensionWebGL1();return r.getQueryObjectEXT(t,r.QUERY_RESULT_EXT)/1e6},t.prototype.isQueryAvailable=function(t,e){if(0===e)return!0;if(2===e){var n=this.gl,r=this.getQueryTimerExtensionWebGL2(),i=n.getQueryParameter(t,n.QUERY_RESULT_AVAILABLE);return null==this.disjoint&&(this.disjoint=this.gl.getParameter(r.GPU_DISJOINT_EXT)),i&&!this.disjoint}return i=(r=this.getQueryTimerExtensionWebGL1()).getQueryObjectEXT(t,r.QUERY_RESULT_AVAILABLE_EXT),null==this.disjoint&&(this.disjoint=this.gl.getParameter(r.GPU_DISJOINT_EXT)),i&&!this.disjoint},t.prototype.pollFence=function(t){var e=this;return new Promise(function(n){e.addItemToPoll(function(){return t.isFencePassed()},function(){return n()})})},t.prototype.pollItems=function(){for(var t=function(t){for(var e=0;e<t.length&&t[e]();++e);return e-1}(this.itemsToPoll.map(function(t){return t.isDoneFn})),e=0;e<=t;++e)(0,this.itemsToPoll[e].resolveFn)();this.itemsToPoll=this.itemsToPoll.slice(t+1)},t.prototype.addItemToPoll=function(t,e){var n=this;this.itemsToPoll.push({isDoneFn:t,resolveFn:e}),this.itemsToPoll.length>1||P(function(){return n.pollItems(),0===n.itemsToPoll.length})},t.prototype.bindTextureToFrameBuffer=function(t){this.throwIfDisposed(),Se(this.gl,this.debug,t,this.framebuffer),this.debug&&Ae(this.gl)},t.prototype.unbindTextureToFrameBuffer=function(){null!=this.outputTexture?(Se(this.gl,this.debug,this.outputTexture,this.framebuffer),this.debug&&Ae(this.gl)):Ce(this.gl,this.debug,this.framebuffer)},t.prototype.downloadMatrixDriver=function(t,e){this.bindTextureToFrameBuffer(t);var n=e();return this.unbindTextureToFrameBuffer(),n},t.prototype.setOutputMatrixTextureDriver=function(t,e,n){this.throwIfDisposed();var r=this.gl;Se(r,this.debug,t,this.framebuffer),this.debug&&Ae(r),this.outputTexture=t,ne(r,this.debug,function(){return r.viewport(0,0,e,n)}),ne(r,this.debug,function(){return r.scissor(0,0,e,n)})},t.prototype.setOutputMatrixWriteRegionDriver=function(t,e,n,r){var i=this;this.throwIfDisposed(),ne(this.gl,this.debug,function(){return i.gl.scissor(t,e,n,r)})},t.prototype.throwIfDisposed=function(){if(this.disposed)throw new Error("Attempted to use disposed GPGPUContext.")},t.prototype.throwIfNoProgram=function(){if(null==this.program)throw new Error("No GPU program is currently set.")},t}();function $o(t,e){if(t.length!==e.length)throw Error("Binary was compiled with "+t.length+" inputs, but was executed with "+e.length+" inputs");t.forEach(function(t,n){var r=t.logicalShape,i=e[n],a=i.shape;if(!D(r,a))throw Error("Binary was compiled with different shapes than the current args. Shapes "+r+" and "+a+" must match");if(!t.isUniform||!i.isUniform){var o=t.texShape,s=i.isUniform?null:i.texData.texShape;if(!D(o,s))throw Error("Binary was compiled with different texture shapes than the current args. Shape "+o+" and "+s+" must match")}})}var Ko=function(t,e,n,r,i,a,o){void 0===n&&(n=!1),void 0===r&&(r=!1),void 0===i&&(i=!1),void 0===a&&(a=null),void 0===o&&(o=!1),this.variableNames=["matrixA","matrixB"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e;var s=n?t[1]:t[2],u=Math.ceil(s/2),c=n?"i * 2, rc.y":"rc.y, i * 2",l=r?"rc.z, i * 2":"i * 2, rc.z",f=n?["a.xxyy","a.zzww"]:["a.xxzz","a.yyww"],d=r?["b.xzxz","b.ywyw"]:["b.xyxy","b.zwzw"],h="",p="";a&&(h=o?"vec4 activation(vec4 a) {\n vec4 b = getPreluActivationWeightsAtOutCoords();\n "+a+"\n }":"vec4 activation(vec4 x) {\n "+a+"\n }",p="result = activation(result);");var m=i?"result += getBiasAtOutCoords();":"";i&&this.variableNames.push("bias"),o&&this.variableNames.push("preluActivationWeights"),this.userCode="\n "+h+"\n\n const float sharedDimension = "+u+".0;\n\n vec4 dot2x2ARowBCol(ivec3 rc) {\n vec4 result = vec4(0);\n for (int i = 0; i < "+u+"; i++) {\n vec4 a = getMatrixA(rc.x, "+c+");\n vec4 b = getMatrixB(rc.x, "+l+");\n\n // These swizzled products need to be separately added.\n // See: https://github.com/tensorflow/tfjs/issues/1735\n result += ("+f[0]+" * "+d[0]+");\n result += ("+f[1]+" * "+d[1]+");\n }\n return result;\n }\n\n void main() {\n ivec3 rc = getOutputCoords();\n vec4 result = dot2x2ARowBCol(rc);\n\n "+m+"\n\n "+p+"\n\n setOutput(result);\n }\n "},Xo=function(){function t(t,e,n){this.variableNames=["probs"],this.outputShape=[t,n],this.userCode="\n uniform float seed;\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n\n float r = random(seed);\n float cdf = 0.0;\n\n for (int i = 0; i < "+(e-1)+"; i++) {\n cdf += getProbs(batch, i);\n\n if (r < cdf) {\n setOutput(float(i));\n return;\n }\n }\n\n // If no other event happened, last event happened.\n setOutput(float("+(e-1)+"));\n }\n "}return t.prototype.getCustomSetupFunc=function(t){var e=this;return function(n,r){null==e.seedLoc&&(e.seedLoc=n.getUniformLocation(r,"seed")),n.gl.uniform1f(e.seedLoc,t)}},t}(),Yo=function(t,e,n,r,i){if(void 0===r&&(r=!1),void 0===i&&(i=!1),this.variableNames=["x"],"avg"===e&&n)throw new Error("Cannot compute positions for average pool.");var a=t.filterWidth,o=t.strideHeight,s=t.strideWidth,u=t.dilationHeight,c=t.dilationWidth,l=t.effectiveFilterHeight,f=t.effectiveFilterWidth,d=t.padInfo.top,h=t.padInfo.left;this.outputShape=t.outShape;var p="avg"===e,m="((batch * "+t.inHeight+" + xR) * "+t.inWidth+" + xC) * "+t.inChannels+" + d",g="(xR * "+t.inWidth+" + xC) * "+t.inChannels+" + d",v="0.0";if(p||(v="-1.0 / 1e-20"),n)this.userCode="\n const ivec2 strides = ivec2("+o+", "+s+");\n const ivec2 pads = ivec2("+d+", "+h+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d = coords[3];\n\n ivec2 xRCCorner = coords.yz * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // max/min x(?, ?, d) to get y(yR, yC, d).\n // ? = to be determined\n float minMaxValue = 0.0;\n float minMaxValueFound = 0.0;\n int minMaxPosition = 0;\n float avgValue = 0.0;\n\n for (int wR = 0; wR < "+l+";\n wR += "+u+") {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int wC = 0; wC < "+f+";\n wC += "+c+") {\n int xC = xCCorner + wC;\n\n if (xC < 0 || xC >= "+t.inWidth+") {\n continue;\n }\n\n float value = getX(batch, xR, xC, d);\n\n // If a min / max value has already been found, use it. If not,\n // use the current value.\n float currMinMaxValue = mix(\n value, minMaxValue, minMaxValueFound);\n if (value >= currMinMaxValue) {\n minMaxValue = value;\n minMaxValueFound = 1.0;\n minMaxPosition = "+(r?i?m:g:"wR * "+f+" + wC")+";\n }\n }\n }\n setOutput(float(minMaxPosition));\n }\n ";else{var y=e+"("+e+"("+e+"(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";"avg"===e&&(y="avgValue / count");var b=4*Math.floor(a/4),x=a%4,w="\n if ("+p+") {\n avgValue += dot(values, ones);\n } else {\n minMaxValue = max(values, minMaxValue);\n }\n ";this.userCode="\n const ivec2 strides = ivec2("+o+", "+s+");\n const ivec2 pads = ivec2("+d+", "+h+");\n const float initializationValue = "+v+";\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n float count = 0.0;\n\n float getValue(int batch, int xR, int xC, int d) {\n if (xC < 0 || xC >= "+t.inWidth+") {\n return initializationValue;\n }\n count += 1.0;\n return getX(batch, xR, xC, d);\n }\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d = coords[3];\n\n ivec2 xRCCorner = coords.yz * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // max/min x(?, ?, d) to get y(yR, yC, d).\n // ? = to be determined\n vec4 minMaxValue = vec4("+v+");\n float avgValue = 0.0;\n count = 0.0;\n\n for (int wR = 0; wR < "+l+";\n wR += "+u+") {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int wC = 0; wC < "+b+"; wC += 4) {\n int xC = xCCorner + wC * "+c+";\n\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + "+c+", d),\n getValue(batch, xR, xC + 2 * "+c+", d),\n getValue(batch, xR, xC + 3 * "+c+", d)\n );\n\n "+w+"\n }\n\n int xC = xCCorner + "+b+";\n if ("+(1===x)+") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n initializationValue,\n initializationValue,\n initializationValue\n );\n\n "+w+"\n } else if ("+(2===x)+") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + "+c+", d),\n initializationValue,\n initializationValue\n );\n\n "+w+"\n } else if ("+(3===x)+") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + "+c+", d),\n getValue(batch, xR, xC + 2 * "+c+", d),\n initializationValue\n );\n\n "+w+"\n }\n }\n setOutput("+y+");\n }\n "}},Jo=function(t,e,n,r,i){if(void 0===r&&(r=!1),void 0===i&&(i=!1),this.variableNames=["x"],"avg"===e&&n)throw new Error("Cannot compute positions for average pool.");var a=t.filterWidth,o=t.strideDepth,s=t.strideHeight,u=t.strideWidth,c=t.dilationDepth,l=t.dilationHeight,f=t.dilationWidth,d=t.effectiveFilterDepth,h=t.effectiveFilterHeight,p=t.effectiveFilterWidth,m=t.padInfo.front,g=t.padInfo.top,v=t.padInfo.left;this.outputShape=t.outShape;var y="avg"===e,b="0.0";if(y||(b="-1.0 / 1e-20"),n)this.userCode="\n const ivec3 strides =\n ivec3("+o+", "+s+", "+u+");\n const ivec3 pads = ivec3("+m+", "+g+", "+v+");\n\n void main() {\n ivec5 coords = getOutputCoords();\n int batch = coords.x;\n int ch = coords.u;\n\n ivec3 xCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;\n int xDCorner = xCorner.x;\n int xRCorner = xCorner.y;\n int xCCorner = xCorner.z;\n\n // max/min x(?, ?, ?, ch) to get y(yD, yR, yC, ch).\n // ? = to be determined\n float minMaxValue = 0.0;\n float minMaxValueFound = 0.0;\n int minMaxPosition = 0;\n\n for (int wD = 0; wD < "+d+";\n wD += "+c+") {\n int xD = xDCorner + wD;\n\n if (xD < 0 || xD >= "+t.inDepth+") {\n continue;\n }\n\n for (int wR = 0; wR < "+h+";\n wR += "+l+") {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int wC = 0; wC < "+p+";\n wC += "+f+") {\n int xC = xCCorner + wC;\n\n if (xC < 0 || xC >= "+t.inWidth+") {\n continue;\n }\n\n float value = getX(batch, xD, xR, xC, ch);\n\n // If a min / max value has already been found, use it. If not,\n // use the current value.\n float currMinMaxValue = mix(\n value, minMaxValue, minMaxValueFound);\n if (value >= currMinMaxValue) {\n minMaxValue = value;\n minMaxValueFound = 1.0;\n minMaxPosition = "+(r?i?"(((batch * "+t.inDepth+" + xD) * "+t.inHeight+" + xR) * "+t.inWidth+" + xC) * "+t.inChannels+" + ch":"((xD * "+t.inHeight+" + xR) * "+t.inWidth+" + xC) * "+t.inChannels+" + ch":"wD * "+h+" * "+p+" +\n wR * "+p+" + wC")+";\n }\n }\n }\n }\n setOutput(float(minMaxPosition));\n }\n ";else{var x=e+"("+e+"("+e+"(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";"avg"===e&&(x="avgValue / count");var w=4*Math.floor(a/4),k=a%4,_="\n if ("+y+") {\n avgValue += dot(values, ones);\n } else {\n minMaxValue = max(values, minMaxValue);\n }\n ";this.userCode="\n const ivec3 strides =\n ivec3("+o+", "+s+", "+u+");\n const ivec3 pads = ivec3("+m+", "+g+", "+v+");\n const float initializationValue = "+b+";\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n float count = 0.0;\n\n float getValue(int batch, int xD, int xR, int xC, int ch) {\n if (xC < 0 || xC >= "+t.inWidth+") {\n return initializationValue;\n }\n count += 1.0;\n return getX(batch, xD, xR, xC, ch);\n }\n\n void main() {\n ivec5 coords = getOutputCoords();\n int batch = coords.x;\n int ch = coords.u;\n\n ivec3 xCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;\n int xDCorner = xCorner.x;\n int xRCorner = xCorner.y;\n int xCCorner = xCorner.z;\n\n // max/min x(?, ?, ?, d) to get y(yD, yR, yC, ch).\n // ? = to be determined\n vec4 minMaxValue = vec4("+b+");\n float avgValue = 0.0;\n count = 0.0;\n\n for (int wD = 0; wD < "+d+";\n wD += "+c+") {\n int xD = xDCorner + wD;\n\n if (xD < 0 || xD >= "+t.inDepth+") {\n continue;\n }\n\n for (int wR = 0; wR < "+h+";\n wR += "+l+") {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int wC = 0; wC < "+w+"; wC += 4) {\n int xC = xCCorner + wC * "+f+";\n\n vec4 values = vec4(\n getValue(batch, xD, xR, xC, ch),\n getValue(batch, xD, xR, xC + "+f+", ch),\n getValue(batch, xD, xR, xC + 2 * "+f+", ch),\n getValue(batch, xD, xR, xC + 3 * "+f+", ch)\n );\n\n "+_+"\n }\n\n int xC = xCCorner + "+w+";\n if ("+(1===k)+") {\n vec4 values = vec4(\n getValue(batch, xD, xR, xC, ch),\n initializationValue,\n initializationValue,\n initializationValue\n );\n\n "+_+"\n } else if ("+(2===k)+") {\n vec4 values = vec4(\n getValue(batch, xD, xR, xC, ch),\n getValue(batch, xD, xR, xC + "+f+", ch),\n initializationValue,\n initializationValue\n );\n\n "+_+"\n } else if ("+(3===k)+") {\n vec4 values = vec4(\n getValue(batch, xD, xR, xC, ch),\n getValue(batch, xD, xR, xC + "+f+", ch),\n getValue(batch, xD, xR, xC + 2 * "+f+", ch),\n initializationValue\n );\n\n "+_+"\n }\n }\n setOutput("+x+");\n }\n }\n "}},Zo=function(t,e,n,r,i,a,o){void 0===o&&(o=!0),this.variableNames=["updates","indices","defaultValue"],this.outputShape=a;var s=oo(i.length),u=oo(a.length),c="";1===n?c="i":2===n&&(c="i, j");var l="getIndices("+c+")",f="";1===r?f="i":2===r&&(f="i, coords[1]");var d="getUpdates("+f+")",h=e>1?"strides[j]":"strides";this.userCode="\n "+s+" strides = "+s+"("+i+");\n\n void main() {\n "+u+" coords = getOutputCoords();\n float sum = 0.0;\n bool found = false;\n for (int i = 0; i < "+t+"; i++) {\n int flattenedIndex = 0;\n for (int j = 0; j < "+e+"; j++) {\n int index = round("+l+");\n flattenedIndex += index * "+h+";\n }\n if (flattenedIndex == coords[0]) {\n sum += "+d+";\n found = true;\n }\n }\n setOutput(mix(getDefaultValue(), sum, float(found)));\n }\n "},Qo=function(){function t(t){this.variableNames=["source"],this.outputShape=t,this.rank=t.length;var e,n=oo(this.rank),r="uniform int start["+this.rank+"];",i=function(t){if(1===t)return"sourceLoc";if(t<=6)return ts.slice(0,t).map(function(t){return"sourceLoc."+t}).join(",");throw Error("Slicing for rank "+t+" is not yet supported")}(this.rank);e="\n "+n+" sourceLoc;\n "+n+" coords = getOutputCoords();\n "+t.map(function(t,e){return"sourceLoc."+ts[e]+" = start["+e+"] + coords."+ts[e]+";"}).join("\n")+"\n ",this.userCode="\n "+r+"\n void main() {\n "+e+"\n setOutput(getSource("+i+"));\n }\n "}return t.prototype.getCustomSetupFunc=function(t){var e=this;if(t.length!==this.rank)throw Error("The rank ("+this.rank+") of the program must match the length of start ("+t.length+")");return function(n,r){null==e.startLoc&&(e.startLoc=n.getUniformLocationNoThrow(r,"start"),null==e.startLoc)||n.gl.uniform1iv(e.startLoc,t)}},t}(),ts=["x","y","z","w","u","v"],es=function(){function t(t){this.variableNames=["source"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t,this.rank=t.length;var e=oo(this.rank),n=Ka("coords",this.rank),r=Ka("sourceLoc",this.rank),i=1===this.rank?"sourceLoc":"vec2("+r.slice(-2).join()+")",a="getChannel(getSource("+r.join()+"), "+i+")",o="\n result.x = "+a+";\n if (++"+n[this.rank-1]+" < "+t[this.rank-1]+") {\n ++"+r[this.rank-1]+";\n result.y = "+a+";\n --"+r[this.rank-1]+";\n }\n ",s=1===this.rank?"":"\n --"+n[this.rank-1]+";\n if (++"+n[this.rank-2]+" < "+t[this.rank-2]+") {\n ++"+r[this.rank-2]+";\n result.z = "+a+";\n if (++"+n[this.rank-1]+" < "+t[this.rank-1]+") {\n ++"+r[this.rank-1]+";\n result.w = "+a+";\n }\n }\n ",u=this.rank<=4?"sourceLoc = coords +\n "+e+"("+t.map(function(t,e){return"start["+e+"]"}).join()+");":t.map(function(t,e){return r[e]+" = "+n[e]+" + start["+e+"];"}).join("\n");this.userCode="\n uniform int start["+this.rank+"];\n void main() {\n "+e+" coords = getOutputCoords();\n "+e+" sourceLoc;\n "+u+"\n vec4 result = vec4(0.);\n "+o+"\n "+s+"\n setOutput(result);\n }\n "}return t.prototype.getCustomSetupFunc=function(t){var e=this;if(t.length!==this.rank)throw Error("The rank ("+this.rank+") of the program must match the length of start ("+t.length+")");return function(n,r){null==e.startLoc&&(e.startLoc=n.getUniformLocationNoThrow(r,"start"),null==e.startLoc)||n.gl.uniform1iv(e.startLoc,t)}},t}(),ns=function(){function t(t){this.gpgpu=t,this.numUsedTextures=0,this.numFreeTextures=0,this.freeTextures={},this.logEnabled=!1,this.usedTextures={}}return t.prototype.acquireTexture=function(t,e,n){var r,i=rs(e,n),a=is(t,i,n);if(a in this.freeTextures||(this.freeTextures[a]=[]),a in this.usedTextures||(this.usedTextures[a]=[]),this.freeTextures[a].length>0){this.numFreeTextures--,this.numUsedTextures++,this.log();var o=this.freeTextures[a].shift();return this.usedTextures[a].push(o),o}return this.numUsedTextures++,this.log(),i===$t.PACKED_2X2_FLOAT32?r=this.gpgpu.createPackedMatrixTexture(t[0],t[1]):i===$t.PACKED_2X2_FLOAT16?r=this.gpgpu.createFloat16PackedMatrixTexture(t[0],t[1]):i===$t.UNPACKED_FLOAT32?r=this.gpgpu.createFloat32MatrixTexture(t[0],t[1]):i===$t.UNPACKED_FLOAT16?r=this.gpgpu.createFloat16MatrixTexture(t[0],t[1]):i===$t.PACKED_4X1_UNSIGNED_BYTE&&(r=this.gpgpu.createUnsignedBytesMatrixTexture(t[0],t[1])),this.usedTextures[a].push(r),r},t.prototype.releaseTexture=function(t,e,n,r){if(null!=this.freeTextures){var i=is(e,rs(n,r),r);i in this.freeTextures||(this.freeTextures[i]=[]),this.freeTextures[i].push(t),this.numFreeTextures++,this.numUsedTextures--;var a=this.usedTextures[i],o=a.indexOf(t);if(o<0)throw new Error("Cannot release a texture that was never provided by this texture manager");a.splice(o,1),this.log()}},t.prototype.log=function(){if(this.logEnabled){var t=this.numFreeTextures+this.numUsedTextures;console.log("Free/Used",this.numFreeTextures+" / "+this.numUsedTextures,"("+t+")")}},t.prototype.getNumUsedTextures=function(){return this.numUsedTextures},t.prototype.getNumFreeTextures=function(){return this.numFreeTextures},t.prototype.dispose=function(){var t=this;if(null!=this.freeTextures){for(var e in this.freeTextures)this.freeTextures[e].forEach(function(e){t.gpgpu.deleteMatrixTexture(e)});for(var e in this.usedTextures)this.usedTextures[e].forEach(function(e){t.gpgpu.deleteMatrixTexture(e)});this.freeTextures=null,this.usedTextures=null,this.numUsedTextures=0,this.numFreeTextures=0}},t}();function rs(t,e){if(t===Gt.UPLOAD)return $t.PACKED_2X2_FLOAT32;if(t===Gt.RENDER||null==t)return function(t){return f().getBool("WEBGL_RENDER_FLOAT32_ENABLED")?t?$t.PACKED_2X2_FLOAT32:$t.UNPACKED_FLOAT32:t?$t.PACKED_2X2_FLOAT16:$t.UNPACKED_FLOAT16}(e);if(t===Gt.DOWNLOAD||t===Gt.PIXELS)return $t.PACKED_4X1_UNSIGNED_BYTE;throw new Error("Unknown logical texture type "+t)}function is(t,e,n){return t[0]+"_"+t[1]+"_"+e+"_"+n}var as=1.7580993408473768,os=1.0507009873554805,ss=function(t,e){this.variableNames=["A"],this.outputShape=t,this.userCode="\n float unaryOperation(float x) {\n "+e+"\n }\n\n void main() {\n float x = getAAtOutCoords();\n float y = unaryOperation(x);\n\n setOutput(y);\n }\n "},us="if (isnan(x)) return x;",cs="return x;",ls="return abs(x);",fs=us+"\n return (x < 0.0) ? 0.0 : x;\n",ds=us+"\n return (x < 0.0) ? 0.0 : min(6.0, x);\n",hs="return (x >= 0.0) ? x : (exp(x) - 1.0);",ps="return -x;",ms="return ceil(x);",gs="return floor(x);",vs="return exp(x);",ys="return exp(x) - 1.0;",bs="return x;",xs="return x;",ws="\n vec4 result = x * vec4(greaterThanEqual(x, vec4(0.0)));\n bvec4 isNaN = isnan(x);\n\n result.r = isNaN.r ? x.r : result.r;\n result.g = isNaN.g ? x.g : result.g;\n result.b = isNaN.b ? x.b : result.b;\n result.a = isNaN.a ? x.a : result.a;\n\n return result;\n",ks="\n vec4 result = min(x, vec4(6.)) * vec4(greaterThanEqual(x, vec4(0.0)));\n bvec4 isNaN = isnan(x);\n\n result.r = isNaN.r ? x.r : result.r;\n result.g = isNaN.g ? x.g : result.g;\n result.b = isNaN.b ? x.b : result.b;\n result.a = isNaN.a ? x.a : result.a;\n\n return result;\n",_s="\n vec4 result;\n\n result.r = (x.r >= 0.0) ? x.r : (exp(x.r) - 1.0);\n result.g = (x.g >= 0.0) ? x.g : (exp(x.g) - 1.0);\n result.b = (x.b >= 0.0) ? x.b : (exp(x.b) - 1.0);\n result.a = (x.a >= 0.0) ? x.a : (exp(x.a) - 1.0);\n\n return result;\n",Es=function(t,e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t,this.userCode="\n vec4 unaryOperation(vec4 x) {\n "+e+"\n }\n\n void main() {\n vec4 x = getAAtOutCoords();\n vec4 y = unaryOperation(x);\n\n setOutput(y);\n }\n "},Os={};function Ss(t,e){if(void 0===e&&(e=!1),"linear"===t)return e?xs:cs;if("relu"===t)return e?ws:fs;if("elu"===t)return e?_s:hs;if("relu6"===t)return e?ks:ds;if("prelu"===t)return e?go:po;throw new Error("Activation "+t+" has not been implemented for the WebGL backend.")}var Cs=600,As=function(t){function e(e){var n,r=t.call(this)||this;if(r.pendingRead=new WeakMap,r.pendingDisposal=new WeakSet,r.dataRefCount=new WeakMap,r.numBytesInGPU=0,r.uploadWaitMs=0,r.downloadWaitMs=0,r.warnedAboutMemory=!1,r.pendingDeletes=0,r.disposed=!1,!f().getBool("HAS_WEBGL"))throw new Error("WebGL is not supported on this device");if(null==e){var i=Jt(f().getNumber("WEBGL_VERSION"));r.binaryCache=(n=f().getNumber("WEBGL_VERSION"))in Os?Os[n]:(Os[n]={},Os[n]),r.gpgpu=new Go(i),r.canvas=i.canvas,r.gpgpuCreatedLocally=!0}else r.gpgpu=e,r.binaryCache={},r.gpgpuCreatedLocally=!1,r.canvas=e.gl.canvas;return r.textureManager=new ns(r.gpgpu),r.numMBBeforeWarning=null==f().global.screen?1024:f().global.screen.height*f().global.screen.width*window.devicePixelRatio*Cs/1024/1024,r.texData=new da(r,Wt),r}return s(e,t),e.prototype.numDataIds=function(){return this.texData.numDataIds()+(this.cpuBackend?this.cpuBackend.numDataIds():0)-this.pendingDeletes},e.prototype.write=function(t,e,n){if(f().getBool("DEBUG")&&this.checkNumericalProblems(t),"complex64"===n&&null!=t)throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");var r={};return this.texData.set(r,{shape:e,dtype:n,values:t,usage:Gt.UPLOAD}),r},e.prototype.move=function(t,e,n,r){if(f().getBool("DEBUG")&&this.checkNumericalProblems(e),"complex64"===r)throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");this.texData.set(t,{shape:n,dtype:r,values:e,usage:Gt.UPLOAD})},e.prototype.readSync=function(t){var e=this.texData.get(t),n=e.values,r=e.dtype,i=e.complexTensors,a=e.slice,o=e.shape,s=e.isPacked;if(null!=a){var u;u=s?new Es(o,bs):new ss(o,bs);var c=this.runWebGLProgram(u,[{dataId:t,shape:o,dtype:r}],r),l=this.readSync(c.dataId);return this.disposeData(c.dataId),l}if(null!=n)return this.convertAndCacheOnCPU(t);if("string"===r)return n;var f,d,h=null!=this.activeTimers;return h&&(f=ot()),d="complex64"===r?Ia(i.real.dataSync(),i.imag.dataSync()):this.getValuesFromTexture(t),h&&(this.downloadWaitMs+=ot()-f),this.convertAndCacheOnCPU(t,d)},e.prototype.read=function(t){return u(this,void 0,void 0,function(){var e,n,r,i,a,o,s,u,l,d,h,p,m,g,v,y,b,x,w,k,_,E;return c(this,function(c){switch(c.label){case 0:if(this.pendingRead.has(t))return e=this.pendingRead.get(t),[2,new Promise(function(t){return e.push(t)})];if(n=this.texData.get(t),r=n.values,i=n.shape,a=n.slice,o=n.dtype,s=n.complexTensors,u=n.isPacked,null!=a)return l=void 0,l=u?new Es(i,bs):new ss(i,bs),d=this.runWebGLProgram(l,[{dataId:t,shape:i,dtype:o}],o),h=this.read(d.dataId),this.disposeData(d.dataId),[2,h];if(null!=r)return[2,this.convertAndCacheOnCPU(t)];if(!f().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED")&&2===f().getNumber("WEBGL_VERSION"))throw new Error("tensor.data() with WEBGL_DOWNLOAD_FLOAT_ENABLED=false and WEBGL_VERSION=2 not yet supported.");return p=null,"complex64"!==o&&f().get("WEBGL_BUFFER_SUPPORTED")&&(m=this.decode(t),g=this.texData.get(m.dataId),p=(E=this.gpgpu).createBufferFromTexture.apply(E,[g.texture].concat(Qt(i)))),this.pendingRead.set(t,[]),"complex64"===o?[3,2]:[4,this.gpgpu.createAndWaitForFence()];case 1:c.sent(),c.label=2;case 2:return"complex64"!==o?[3,4]:[4,Promise.all([s.real.data(),s.imag.data()])];case 3:return y=c.sent(),b=y[0],x=y[1],v=Ia(b,x),[3,5];case 4:null==p?v=this.getValuesFromTexture(t):(w=I(i),v=this.gpgpu.downloadFloat32MatrixFromBuffer(p,w)),c.label=5;case 5:return null!=m&&this.disposeData(m.dataId),k=this.convertAndCacheOnCPU(t,v),_=this.pendingRead.get(t),this.pendingRead.delete(t),_.forEach(function(t){return t(k)}),this.pendingDisposal.has(t)&&(this.pendingDisposal.delete(t),this.disposeData(t),this.pendingDeletes--),[2,k]}})})},e.prototype.checkNumericalProblems=function(t){if(null!=t)for(var e=0;e<t.length;e++){var n=t[e];if(!ae(n)){if(f().getBool("WEBGL_RENDER_FLOAT32_CAPABLE"))throw Error("The value "+n+" cannot be represented with your current settings. Consider enabling float32 rendering: 'tf.env().set('WEBGL_RENDER_FLOAT32_ENABLED', true);'");throw Error("The value "+n+" cannot be represented on this device.")}}},e.prototype.getValuesFromTexture=function(t){var e,n=this.texData.get(t),r=n.shape,i=n.dtype,a=n.isPacked,o=I(r);if(f().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED")){var s=this.decode(t),u=this.texData.get(s.dataId),c=(e=this.gpgpu).downloadMatrixFromPackedTexture.apply(e,[u.texture].concat(Qt(r))).subarray(0,o);return this.disposeData(s.dataId),c}var l=f().getBool("WEBGL_PACK")&&!0===a,d=l?Re(r):r,h=l?new function(t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outTexUsage=Gt.DOWNLOAD;var e=Xa();this.outputShape=t,this.userCode="\n "+Za+"\n\n void main() {\n ivec3 coords = getOutputCoords();\n float x = getChannel(getAAtOutCoords(), vec2(coords.y, coords.z));\n "+e.output+" = encode_float(x);\n }\n "}(d):new function(t){this.variableNames=["A"],this.outTexUsage=Gt.DOWNLOAD;var e=Xa();this.outputShape=t,this.userCode="\n "+Za+"\n\n void main() {\n float x = getAAtOutCoords();\n "+e.output+" = encode_float(x);\n }\n "}(d),p=this.runWebGLProgram(h,[{shape:d,dtype:i,dataId:t}],"float32"),m=this.texData.get(p.dataId),g=this.gpgpu.downloadByteEncodedFloatMatrixFromOutputTexture(m.texture,m.texShape[0],m.texShape[1]).subarray(0,o);return this.disposeData(p.dataId),g},e.prototype.time=function(t){return u(this,void 0,void 0,function(){var e,n,r,i,a,o,s;return c(this,function(u){switch(u.label){case 0:return e=this.activeTimers,n=[],r=!1,null==this.programTimersStack?(this.programTimersStack=n,r=!0):this.activeTimers.push(n),this.activeTimers=n,t(),i=T(this.activeTimers.map(function(t){return t.query})).filter(function(t){return null!=t}),a=T(this.activeTimers.map(function(t){return t.name})).filter(function(t){return null!=t}),this.activeTimers=e,r&&(this.programTimersStack=null),o={uploadWaitMs:this.uploadWaitMs,downloadWaitMs:this.downloadWaitMs,kernelMs:null,wallMs:null},f().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?[4,Promise.all(i)]:[3,2];case 1:return s=u.sent(),o.kernelMs=S(s),o.getExtraProfileInfo=function(){return s.map(function(t,e){return{name:a[e],ms:t}}).map(function(t){return t.name+": "+t.ms}).join(", ")},[3,3];case 2:o.kernelMs={error:"WebGL query timers are not supported in this environment."},u.label=3;case 3:return this.uploadWaitMs=0,this.downloadWaitMs=0,[2,o]}})})},e.prototype.memory=function(){return{unreliable:!1,numBytesInGPU:this.numBytesInGPU}},e.prototype.startTimer=function(){return f().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?this.gpgpu.beginQuery():{startMs:ot(),endMs:null}},e.prototype.endTimer=function(t){return f().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?(this.gpgpu.endQuery(),t):(t.endMs=ot(),t)},e.prototype.getQueryTime=function(t){return u(this,void 0,void 0,function(){var e;return c(this,function(n){return f().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?[2,this.gpgpu.waitForQueryAndGetTime(t)]:[2,(e=t).endMs-e.startMs]})})},e.prototype.disposeData=function(t){if(!this.pendingDisposal.has(t)){if(this.pendingRead.has(t))return this.pendingDisposal.add(t),void this.pendingDeletes++;if(this.texData.has(t)){this.releaseGPUData(t);var e=this.texData.get(t).complexTensors;null!=e&&(e.real.dispose(),e.imag.dispose()),this.texData.delete(t)}}},e.prototype.releaseGPUData=function(t){var e=this.texData.get(t),n=e.texture,r=e.dtype,i=e.texShape,a=e.usage,o=e.isPacked,s=e.slice,u=s&&s.origDataId||t,c=this.dataRefCount.get(u);c>1?this.dataRefCount.set(u,c-1):(this.dataRefCount.delete(u),null!=n&&(this.numBytesInGPU-=this.computeBytes(i,r),this.textureManager.releaseTexture(n,i,a,o)));var l=this.texData.get(t);l.texture=null,l.texShape=null,l.isPacked=!1,l.slice=null},e.prototype.getTexture=function(t){return this.uploadToGPU(t),this.texData.get(t).texture},e.prototype.getDataInfo=function(t){return this.texData.get(t)},e.prototype.getCPUBackend=function(){return f().getBool("WEBGL_CPU_FORWARD")?(null==this.cpuBackend&&(this.cpuBackend=Wt.findBackend("cpu")),this.cpuBackend):null},e.prototype.shouldExecuteOnCPU=function(t,e){var n=this;return void 0===e&&(e=128),null!=this.getCPUBackend()&&t.every(function(t){return null==n.texData.get(t.dataId).texture&&I(t.shape)<e})},e.prototype.getGPGPUContext=function(){return this.gpgpu},e.prototype.complex=function(t,e){var n=this.makeOutput(t.shape,"complex64");return this.texData.get(n.dataId).complexTensors={real:Wt.keep(t.clone()),imag:Wt.keep(e.clone())},n},e.prototype.real=function(t){return this.texData.get(t.dataId).complexTensors.real.clone()},e.prototype.imag=function(t){return this.texData.get(t.dataId).complexTensors.imag.clone()},e.prototype.slice=function(t,e,n){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.slice(t,e,n);if(0===I(n))return jn([],n,t.dtype);var r=this.texData.get(t.dataId).isPacked,i=Qi(t.shape,e,n);if(r||!i){var a=f().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new es(n):new Qo(n),o=a.getCustomSetupFunc(e);return this.compileAndRun(a,[t],null,o)}return this.uploadToGPU(t.dataId),this.shallowSlice(t,e,n)},e.prototype.shallowSlice=function(t,e,n){var r=this.texData.get(t.dataId),i=this.makeOutput(n,t.dtype),a=this.texData.get(i.dataId);Object.assign(a,r),a.shape=n,a.dtype=t.dtype;var o=ta(e,t.strides);r.slice&&(o+=r.slice.flatOffset),a.slice={flatOffset:o,origDataId:r.slice&&r.slice.origDataId||t.dataId};var s=this.dataRefCount.get(a.slice.origDataId)||1;return this.dataRefCount.set(a.slice.origDataId,s+1),i},e.prototype.stridedSlice=function(t,e,n,r){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.stridedSlice(t,e,n,r);var i=Yi(e,n,r);if(i.some(function(t){return 0===t}))return jn([],i);var a=new function(t,e,n){this.variableNames=["x"],this.outputShape=n;var r=n.length,i=oo(n.length),a=oo(n.length),o="";if(1===r)o="coords * strides + begin";else{var s=0;o=n.map(function(t,e){return s++,1===n.length?"coords * strides["+e+"] + begin["+e+"]":"coords["+(s-1)+"] * strides["+e+"] + begin["+e+"]"}).join(",")}this.userCode="\n "+i+" begin = "+i+"("+t+");\n "+i+" strides = "+i+"("+e+");\n\n void main() {\n "+a+" coords = getOutputCoords();\n setOutput(getX("+o+"));\n }\n "}(e,r,i);return this.compileAndRun(a,[t])},e.prototype.reverse=function(t,e){var n=f().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new function(t,e){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0;var n=t.length;if(n>4)throw new Error("WebGL backend: Reverse of rank-"+n+" tensor is not yet supported");this.outputShape=t;var r=Ka("rc",n),i=r[n-1]+" + 1 < "+this.outputShape[n-1],a=r[n-2]+" + 1 < "+this.outputShape[n-2],o=oo(n);function s(n){var r=t.map(function(r,i){return function(n,r){return-1!==e.indexOf(n)&&1!==t[n]?t[n]+" - "+r[n]+" - 1":""+r[n]}(i,n)});return"getChannel(getX("+r.join(",")+"), vec2("+r.slice(-2).join(",")+"))"}this.userCode=1===n?"\n void main(){\n int rc = getOutputCoords();\n vec4 result = vec4(0.);\n result.r = getChannel(getX("+t[0]+" - rc - 1),\n "+t[0]+" - rc - 1);\n if("+i+"){\n result.g = getChannel(getX("+t[0]+" - (rc + 1) - 1),\n "+t[0]+" - (rc + 1) - 1);\n }\n setOutput(result);\n }\n ":"\n void main() {\n "+o+" rc = getOutputCoords();\n vec4 result = vec4(0.);\n result.r = "+s(r.slice())+";\n if("+i+"){\n result.g = "+function(t){return t[n-1]="("+t[n-1]+" + 1)",s(t)}(r.slice())+";\n }\n if("+a+") {\n result.b = "+function(t){return t[n-2]="("+t[n-2]+" + 1)",s(t)}(r.slice())+";\n if("+i+") {\n result.a = "+function(t){return t[n-1]="("+t[n-1]+" + 1)",t[n-2]="("+t[n-2]+" + 1)",s(t)}(r.slice())+";\n }\n }\n setOutput(result);\n }\n "}(t.shape,e):new function(t,e){this.variableNames=["x"];var n=t.length;if(n>4)throw new Error("WebGL backend: Reverse of rank-"+n+" tensor is not yet supported");if(this.outputShape=t,1!==n){var r=t.map(function(n,r){return function(n){return-1!==e.indexOf(n)&&1!==t[n]?t[n]+" - coords["+n+"] - 1":"coords["+n+"]"}(r)}).join(","),i=oo(n);this.userCode="\n void main() {\n "+i+" coords = getOutputCoords();\n setOutput(getX("+r+"));\n }\n "}else this.userCode="\n void main() {\n int coord = getOutputCoords();\n setOutput(getX("+t[0]+" - coord - 1));\n }\n "}(t.shape,e);return this.compileAndRun(n,[t])},e.prototype.concat=function(t,e){if("complex64"===t[0].dtype){var n=t.map(function(t){return Rn(t)}),r=t.map(function(t){return Fn(t)});return Mn(this.concat(n,e),this.concat(r,e))}if(this.shouldExecuteOnCPU(t))return this.cpuBackend.concat(t,e);if(1===t.length)return t[0];if(t.length>f().getNumber("WEBGL_MAX_TEXTURES_IN_SHADER")){var i=Math.floor(t.length/2),a=this.concat(t.slice(0,i),e),o=this.concat(t.slice(i),e);return this.concat([a,o],e)}if(f().getBool("WEBGL_PACK_ARRAY_OPERATIONS")&&t[0].rank>1){var s=new function(t,e){this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[],this.outputShape=In(t,e);var n=this.outputShape,r=n.length,i=oo(r),a=Ka("coords",r),o=["x","y","z","w","u","v"].slice(0,r);this.variableNames=t.map(function(t,e){return"T"+e});var s=new Array(t.length-1);s[0]=t[0][e];for(var u=1;u<s.length;u++)s[u]=s[u-1]+t[u][e];var c=o[e],l=o.slice(-2),f=o.join(),d="if ("+c+" < "+s[0]+") {\n return getChannel(\n getT0("+f+"), vec2("+l.join()+"));\n }";for(u=1;u<s.length;u++){var h=s[u-1];d+="\n if ("+c+" < "+s[u]+" && "+c+" >= "+s[u-1]+") {\n return getChannel(\n getT"+u+"("+xo(o,c,h)+"),\n vec2("+xo(l,c,h)+"));\n }"}var p=s.length,m=s[s.length-1];d+="\n return getChannel(\n getT"+p+"("+xo(o,c,m)+"),\n vec2("+xo(l,c,m)+"));",this.userCode="\n float getValue("+o.map(function(t){return"int "+t})+") {\n "+d+"\n }\n\n void main() {\n "+i+" coords = getOutputCoords();\n vec4 result = vec4(getValue("+a+"), 0., 0., 0.);\n\n "+a[r-1]+" = "+a[r-1]+" + 1;\n if ("+a[r-1]+" < "+n[r-1]+") {\n result.g = getValue("+a+");\n }\n\n "+a[r-2]+" = "+a[r-2]+" + 1;\n if ("+a[r-2]+" < "+n[r-2]+") {\n result.a = getValue("+a+");\n }\n\n "+a[r-1]+" = "+a[r-1]+" - 1;\n if ("+a[r-2]+" < "+n[r-2]+" &&\n "+a[r-1]+" < "+n[r-1]+") {\n result.b = getValue("+a+");\n }\n setOutput(result);\n }\n "}(t.map(function(t){return t.shape}),e);return this.compileAndRun(s,t)}var u=In(t.map(function(t){return t.shape}),e),c=t.map(function(t){return t.as2D(-1,I(t.shape.slice(e)))}),l=new function(t){this.outputShape=[],this.outputShape=In(t,1),this.variableNames=t.map(function(t,e){return"T"+e});var e=new Array(t.length-1);e[0]=t[0][1];for(var n=1;n<e.length;n++)e[n]=e[n-1]+t[n][1];var r=["if (yC < "+e[0]+") setOutput(getT0(yR, yC));"];for(n=1;n<e.length;n++){var i=e[n-1];r.push("else if (yC < "+e[n]+") setOutput(getT"+n+"(yR, yC-"+i+"));")}var a=e.length,o=e[e.length-1];r.push("else setOutput(getT"+a+"(yR, yC-"+o+"));"),this.userCode="\n void main() {\n ivec2 coords = getOutputCoords();\n int yR = coords.x;\n int yC = coords.y;\n\n "+r.join("\n ")+"\n }\n "}(c.map(function(t){return t.shape}));return this.compileAndRun(l,c).reshape(u)},e.prototype.neg=function(t){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.neg(t);if(f().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(t,ps,t.dtype);var e=new ss(t.shape,ps);return this.compileAndRun(e,[t])},e.prototype.batchMatMul=function(t,e,n,r){var i=n?t.shape[2]:t.shape[1],a=r?e.shape[1]:e.shape[2],o=n?t.shape[1]:t.shape[2],s=t.shape[0];if((1===i||1===a)&&o>1e3){n&&(t=fa(t,[0,2,1])),r&&(e=fa(e,[0,2,1]));var u=1===a?t:t.as3D(s,o,1),c=1===a?2:1,l=1===a?e.as3D(s,1,o):e;return this.multiply(u,l).sum(c,!0)}var f=Mt(t.dtype,e.dtype),d=new Ko(t.shape,[s,i,a],n,r);return this.compileAndRun(d,[t,e],f)},e.prototype.fusedBatchMatMul=function(t){var e=t.a,n=t.b,r=t.transposeA,i=t.transposeB,a=t.bias,o=t.activation,s=t.preluActivationWeights,u=r?e.shape[2]:e.shape[1],c=i?n.shape[1]:n.shape[2],l=e.shape[0],f=Mt(e.dtype,n.dtype),d=null!=a,h=null!=s,p=o?Ss(o,!0):null,m=new Ko(e.shape,[l,u,c],r,i,d,p,h),g=[e,n];return a&&g.push(a),s&&g.push(s),this.compileAndRun(m,g,f)},e.prototype.multiply=function(t,e){if("complex64"===t.dtype){var n=this.texData.get(t.dataId),r=this.texData.get(e.dataId),i=new co("return areal * breal - aimag * bimag;",t.shape,e.shape),a=new co("return areal * bimag + aimag * breal;",t.shape,e.shape),o=[this.makeComplexComponentTensorInfo(t,n.complexTensors.real),this.makeComplexComponentTensorInfo(t,n.complexTensors.imag),this.makeComplexComponentTensorInfo(e,r.complexTensors.real),this.makeComplexComponentTensorInfo(e,r.complexTensors.imag)],s=this.compileAndRun(i,o),u=this.compileAndRun(a,o),c=this.complex(s,u);return s.dispose(),u.dispose(),c}if(this.shouldExecuteOnCPU([t,e]))return this.cpuBackend.multiply(t,e);if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,ho,t.dtype);var l=new mo(ho,t.shape,e.shape);return this.compileAndRun(l,[t,e],t.dtype)},e.prototype.batchNormalization=function(t,e,n,r,i,a){var o=[t,e,n],s=null;null!=a&&(s=a.shape,o.push(a));var u=null;if(null!=i&&(u=i.shape,o.push(i)),f().getBool("WEBGL_PACK_NORMALIZATION")){var c=new function(t,e,n,r,i,a){this.packedInputs=!0,this.packedOutput=!0,this.variableNames=["x","mean","variance"],Ur(t,e),Ur(t,n);var o="vec4(0.0)";null!=r&&(Ur(t,r),this.variableNames.push("offset"),o="getOffsetAtOutCoords()");var s="vec4(1.0)";null!=i&&(Ur(t,i),this.variableNames.push("scale"),s="getScaleAtOutCoords()"),this.outputShape=t,this.userCode="\n void main() {\n vec4 offset = "+o+";\n vec4 scale = "+s+";\n\n vec4 x = getXAtOutCoords();\n vec4 mean = getMeanAtOutCoords();\n vec4 variance = getVarianceAtOutCoords();\n\n vec4 inv = scale * inversesqrt(variance + vec4("+a+"));\n\n setOutput((x - mean) * inv + offset);\n }\n "}(t.shape,e.shape,n.shape,s,u,r);return this.compileAndRun(c,o)}var l=new function(t,e,n,r,i,a){this.outputShape=[],this.variableNames=["x","mean","variance"],Ur(t,e),Ur(t,n);var o="0.0";null!=r&&(Ur(t,r),this.variableNames.push("offset"),o="getOffsetAtOutCoords()");var s="1.0";null!=i&&(Ur(t,i),this.variableNames.push("scale"),s="getScaleAtOutCoords()"),this.outputShape=t,this.userCode="\n void main() {\n float x = getXAtOutCoords();\n float mean = getMeanAtOutCoords();\n float variance = getVarianceAtOutCoords();\n float offset = "+o+";\n float scale = "+s+";\n float inv = scale * inversesqrt(variance + float("+a+"));\n setOutput(dot(vec3(x, -mean, offset), vec3(inv, inv, 1)));\n }\n "}(t.shape,e.shape,n.shape,s,u,r);return this.compileAndRun(l,o)},e.prototype.localResponseNormalization4D=function(t,e,n,r,i){var a=f().getBool("WEBGL_PACK_NORMALIZATION")?new function(t,e,n,r,i){this.variableNames=["x"],this.outputShape=[],this.packedInputs=!0,this.packedOutput=!0;var a,o=e,s=t[3]-1;this.outputShape=t;var u="float("+n+") + float("+r+") * sum";a=.5===i?"inversesqrt("+u+")":1===i?"1.0/("+u+")":"exp(log("+u+") * float(-"+i+"));",this.userCode="\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords.x;\n int r = coords.y;\n int c = coords.z;\n int d = coords.w;\n\n bool hasNextCol = d < "+this.outputShape[3]+";\n bool hasNextRow = c < "+this.outputShape[2]+";\n\n vec4 sum = vec4(0.);\n vec4 xFragAtOutputCoords = getX(b, r, c, d);\n\n vec4 xAtOutputCoords = vec4(\n getChannel(xFragAtOutputCoords, vec2(c, d)),\n hasNextCol ?\n getChannel(xFragAtOutputCoords, vec2(c, d + 1)) : 0.0,\n hasNextRow ?\n getChannel(xFragAtOutputCoords , vec2(c + 1, d)) : 0.0,\n (hasNextRow && hasNextCol) ?\n getChannel(xFragAtOutputCoords, vec2(c + 1, d + 1)) : 0.0\n );\n\n int firstChannel = d - "+o+";\n vec2 cache = vec2(0.);\n if(firstChannel >= 0){\n vec4 firstChannelFrag = getX(b, r, c, firstChannel);\n cache.x = getChannel(firstChannelFrag, vec2(c, firstChannel));\n if(hasNextRow){\n cache.y = getChannel(firstChannelFrag, vec2(c + 1, firstChannel));\n }\n }\n\n ivec2 depth = ivec2(d, d + 1);\n for (int j = - "+o+"; j <= "+o+"; j++) {\n ivec2 idx = depth + j;\n bvec2 aboveLowerBound = greaterThanEqual(idx, ivec2(0));\n bvec2 belowUpperBound = lessThanEqual(idx, ivec2("+s+"));\n\n bool depthInRange = aboveLowerBound.x && belowUpperBound.x;\n bool depthPlusOneInRange = aboveLowerBound.y && belowUpperBound.y;\n\n if(depthInRange || depthPlusOneInRange){\n vec4 z = vec4(0.);\n vec4 xFragAtCurrentDepth;\n z.xz = cache.xy;\n if(depthPlusOneInRange && hasNextCol){\n xFragAtCurrentDepth = idx.y != d ?\n getX(b, r, c, idx.y) : xFragAtOutputCoords;\n z.y = getChannel(xFragAtCurrentDepth, vec2(c, idx.y));\n if(hasNextRow){\n z.w = getChannel(xFragAtCurrentDepth, vec2(c + 1, idx.y));\n }\n }\n cache.xy = z.yw;\n sum += z * z;\n }\n }\n vec4 result = xAtOutputCoords * "+a+";\n setOutput(result);\n }\n "}(t.shape,e,n,r,i):new function(t,e,n,r,i){this.variableNames=["x"],this.outputShape=[];var a,o=e,s=t[3]-1;this.outputShape=t;var u="float("+n+") + float("+r+") * sum";a=.5===i?"inversesqrt("+u+")":1===i?"1.0/("+u+")":"exp(log("+u+") * float(-"+i+"));",this.userCode="\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int r = coords[1];\n int c = coords[2];\n int d = coords[3];\n float x = getX(b, r, c, d);\n float sum = 0.0;\n for (int j = -"+o+"; j <= "+o+"; j++) {\n int idx = d + j;\n if (idx >= 0 && idx <= "+s+") {\n float z = getX(b, r, c, idx);\n sum += z * z;\n }\n }\n float val = x * "+a+";\n setOutput(val);\n }\n "}(t.shape,e,n,r,i);return this.compileAndRun(a,[t])},e.prototype.LRNGrad=function(t,e,n,r,i,a,o){var s=new function(t,e,n,r,i){this.variableNames=["inputImage","outputImage","dy"],this.outputShape=[],this.outputShape=t,this.depth=t[3],this.depthRadius=e,this.bias=n,this.alpha=r,this.beta=i,this.userCode="\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int r = coords[1];\n int c = coords[2];\n\n float result = 0.0;\n for (int d = 0; d < "+this.depth+"; ++d) {\n int depthBegin = int(max(0.0, float(d - "+e+")));\n int depthEnd = int(min(float("+this.depth+"),\n float(d + "+e+" + 1)));\n\n const int MIN_DEPTH_BEGIN = 0;\n const int MAX_DEPTH_END = "+this.depth+";\n\n float norm = 0.0;\n for (int k = MIN_DEPTH_BEGIN; k < MAX_DEPTH_END; ++k) {\n if (k < depthBegin){\n continue;\n }\n else if (k >= depthBegin && k < depthEnd) {\n norm += getInputImage(b, r, c, k) * getInputImage(b, r, c, k);\n }\n else {\n break;\n }\n }\n\n norm = float("+r+") * norm + float("+n+");\n\n for(int k = MIN_DEPTH_BEGIN; k < MAX_DEPTH_END; ++k){\n if (k < depthBegin){\n continue;\n }\n else if (k >= depthBegin && k < depthEnd){\n float dyi = -2.0 * float("+r+")\n * float("+i+")\n * getInputImage(b ,r ,c, k) * getOutputImage(b, r, c, d)\n / norm;\n if (k == d) {\n dyi += pow(norm, -1.0 * "+i+");\n }\n if (k == coords[3]) {\n dyi *= getDy(b, r, c, d);\n result += dyi;\n }\n }\n else {\n break;\n }\n }\n }\n setOutput(result);\n }\n "}(e.shape,r,i,a,o);return this.compileAndRun(s,[e,n,t])},e.prototype.tile=function(t,e){if("string"===t.dtype){var n=this.readSync(t.dataId).map(function(t){return ct(t)});return qa(ar(t.shape,t.dtype,n),e)}var r=new function(t,e){this.variableNames=["A"];for(var n=new Array(t.length),r=0;r<n.length;r++)n[r]=t[r]*e[r];this.outputShape=n,this.rank=n.length;var i=oo(this.rank),a=function(t){var e=t.length;if(e>5)throw Error("Tile for rank "+e+" is not yet supported");if(1===e)return"imod(resRC, "+t[0]+")";for(var n=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u"],r=[],i=0;i<t.length;i++)r.push("imod("+n[i]+", "+t[i]+")");return r.join()}(t);this.userCode="\n void main() {\n "+i+" resRC = getOutputCoords();\n setOutput(getA("+a+"));\n }\n "}(t.shape,e);return this.compileAndRun(r,[t])},e.prototype.pad=function(t,e,n){var r=f().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new function(t,e,n){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e.map(function(e,n){return e[0]+t[n]+e[1]});for(var r=t.length,i=oo(r),a=e.map(function(t){return t[0]}).join(","),o=e.map(function(e,n){return e[0]+t[n]}).join(","),s=Ka("rc",r),u=Ka("source",r),c=s[r-1]+" < "+this.outputShape[r-1],l=1===r?"source":"vec2("+u.slice(-2).join()+")",f=[i+" rc = outputLoc;",s[r-1]+" += 1;\n if("+c+") {\n ",1===r?"":"}\n rc = outputLoc;\n "+s[r-2]+" += 1;\n if("+s[r-2]+" < "+this.outputShape[r-2]+") {",1===r?"":" "+s[r-1]+" += 1;\n if("+c+") {"],d=1===r?"rc < start || rc >= end":"any(lessThan(rc, start)) || any(greaterThanEqual(rc, end))",h="",p=0,m=1===r?2:4;p<m;p++)h+="\n "+f[p]+"\n if ("+d+") {\n result["+p+"] = float("+n+");\n } else {\n "+i+" source = rc - start;\n result["+p+"] = getChannel(getX("+u.join()+"), "+l+");\n }\n ";h+=1===r?"} ":"}}",this.userCode="\n const "+i+" start = "+i+"("+a+");\n const "+i+" end = "+i+"("+o+");\n\n void main() {\n "+i+" outputLoc = getOutputCoords();\n vec4 result = vec4(0.);\n "+h+"\n setOutput(result);\n }\n "}(t.shape,e,n):new function(t,e,n){this.variableNames=["x"],this.outputShape=e.map(function(e,n){return e[0]+t[n]+e[1]});var r=t.length,i=oo(r),a=e.map(function(t){return t[0]}).join(","),o=e.map(function(e,n){return e[0]+t[n]}).join(","),s=["coords[0]","coords[1]","coords[2]","coords[3]"].slice(0,r);this.userCode=1!==r?"\n "+i+" start = "+i+"("+a+");\n "+i+" end = "+i+"("+o+");\n\n void main() {\n "+i+" outC = getOutputCoords();\n if (any(lessThan(outC, start)) || any(greaterThanEqual(outC, end))) {\n setOutput(float("+n+"));\n } else {\n "+i+" coords = outC - start;\n setOutput(getX("+s+"));\n }\n }\n ":"\n int start = "+a+";\n int end = "+o+";\n\n void main() {\n int outC = getOutputCoords();\n if (outC < start || outC >= end) {\n setOutput(float("+n+"));\n } else {\n setOutput(getX(outC - start));\n }\n }\n "}(t.shape,e,n);return this.compileAndRun(r,[t])},e.prototype.gather=function(t,e,n){if(this.shouldExecuteOnCPU([t,e]))return this.cpuBackend.gather(t,e,n);var r=new function(t,e,n){this.variableNames=["A","indices"];var r=t.slice();r[n]=e,this.outputShape=r,this.rank=r.length;var i=oo(this.rank),a=function(t,e){var n=t.length;if(n>4)throw Error("Gather for rank "+n+" is not yet supported");if(1===n)return"int(getIndices(resRC))";for(var r=["resRC.x","resRC.y","resRC.z","resRC.w"],i=[],a=0;a<t.length;a++)a===e?i.push("int(getIndices("+r[a]+"))"):i.push(""+r[a]);return i.join()}(t,n);this.userCode="\n void main() {\n "+i+" resRC = getOutputCoords();\n setOutput(getA("+a+"));\n }\n "}(t.shape,e.size,n);return this.compileAndRun(r,[t,e])},e.prototype.batchToSpaceND=function(t,e,n){C(t.rank<=4,function(){return"batchToSpaceND for rank > 4 with a WebGL backend not implemented yet"});var r=e.reduce(function(t,e){return t*e}),i=yr(t.shape,e,r),a=br(i.length,e.length),o=xr(t.shape,e,r),s=wr(n,e.length),u=kr(o,n,e.length);return fa(t.reshape(i),a).reshape(o).slice(s,u)},e.prototype.spaceToBatchND=function(t,e,n){C(t.rank<=4,function(){return"spaceToBatchND for rank > 4 with a WebGL backend not implemented yet"});var r=e.reduce(function(t,e){return t*e}),i=[[0,0]];i.push.apply(i,n);for(var a=1+e.length;a<t.shape.length;++a)i.push([0,0]);var o=t.pad(i),s=yr(o.shape,e,r,!1),u=br(s.length,e.length,!1),c=xr(o.shape,e,r,!1);return fa(o.reshape(s),u).reshape(c)},e.prototype.reduce=function(t,e,n){var r=t.shape[0],i=t.shape[1],a=new function(t,e){this.variableNames=["x"];var n=t.windowSize,r=t.batchSize,i=t.inSize,a=Math.ceil(i/n);this.outputShape=[r,a];var o="0.0",s="";"prod"===e?o="1.0":"min"===e?(o="1.0 / 1e-20",s="min"):"max"===e&&(o="-1.0 / 1e-20",s="max");var u=e+"("+e+"("+e+"(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";"sum"===e?u="sumValue":"prod"===e?u="prodValue":"all"===e?u="allValue":"any"===e&&(u="anyValue");var c=4*Math.floor(n/4),l=n%4,f="\n if ("+("sum"===e)+") {\n sumValue += dot(values, ones);\n } else if ("+("prod"===e)+") {\n vec2 tmp = vec2(values[0], values[1]) * vec2(values[2], values[3]);\n prodValue *= tmp[0] * tmp[1];\n } else {\n minMaxValue = "+s+"(values, minMaxValue);\n }\n ",d="vec4";"all"===e?(o="1.0",f="\n bool reducedAllValue = all(values);\n float floatedReducedAllValue = float(reducedAllValue);\n allValue = float(allValue >= 1.0 && floatedReducedAllValue >= 1.0);\n ",d="bvec4"):"any"===e&&(o="0.0",f="\n bool reducedAnyValue = any(values);\n float floatedReducedAnyValue = float(reducedAnyValue);\n anyValue = float(anyValue >= 1.0 || floatedReducedAnyValue >= 1.0);\n ",d="bvec4");var h="";i%n>0&&(h="\n if (inIdx < 0 || inIdx >= "+i+") {\n return initializationValue;\n }\n "),this.userCode="\n const float initializationValue = "+o+";\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n float getValue(int batch, int inIdx) {\n "+h+"\n return getX(batch, inIdx);\n }\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n int outIdx = coords[1];\n int inOffset = outIdx * "+n+";\n\n vec4 minMaxValue = vec4("+o+");\n float prodValue = 1.0;\n float sumValue = 0.0;\n float allValue = 1.0;\n float anyValue = 0.0;\n\n for (int i = 0; i < "+c+"; i += 4) {\n int inIdx = inOffset + i;\n "+d+" values = "+d+"(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n getValue(batch, inIdx + 3)\n );\n\n "+f+"\n }\n\n int inIdx = inOffset + "+c+";\n if ("+(1===l)+") {\n "+d+" values = "+d+"(\n getValue(batch, inIdx),\n initializationValue,\n initializationValue,\n initializationValue\n );\n\n "+f+"\n } else if ("+(2===l)+") {\n "+d+" values = "+d+"(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n initializationValue,\n initializationValue\n );\n\n "+f+"\n } else if ("+(3===l)+") {\n "+d+" values = "+d+"(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n initializationValue\n );\n\n "+f+"\n }\n setOutput("+u+");\n }\n "}({windowSize:Vi(i),inSize:i,batchSize:r},e),o=this.compileAndRun(a,[t],n);return 1===o.shape[1]?o:this.reduce(o,e,n)},e.prototype.argReduce=function(t,e,n){void 0===n&&(n=null);var r=t.shape[0],i=t.shape[1];null!=n&&(r=n.shape[0],i=n.shape[1]);var a=new function(t,e,n){this.variableNames=["A"];var r=t.windowSize,i=t.batchSize,a=t.inSize,o=Math.ceil(a/r);n||this.variableNames.push("bestIndicesA"),this.outputShape=[i,o];var s="max"===e?">":"<",u=n?"inOffset + i;":"round(getBestIndicesA(batch, inOffset + i));";this.userCode="\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n int outIdx = coords[1];\n int inOffset = outIdx * "+r+";\n\n int bestIndex = inOffset;\n float bestValue = getA(batch, bestIndex);\n\n for (int i = 0; i < "+r+"; i++) {\n int inIdx = "+u+";\n float candidate = getA(batch, inIdx);\n if (candidate "+s+" bestValue) {\n bestValue = candidate;\n bestIndex = inIdx;\n }\n }\n setOutput(float(bestIndex));\n }\n "}({windowSize:Vi(i),inSize:i,batchSize:r},e,null==n),o=[t];null!=n&&o.push(n);var s=this.compileAndRun(a,o,"int32");return 1===s.shape[1]?s:this.argReduce(t,e,s)},e.prototype.argReducePacked=function(t,e,n){void 0===n&&(n=null);var r=null!=n?n.shape:t.shape,i=new function(t,e,n,r){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,C(t.length>2,function(){return"Packed arg"+(n.charAt(0).toUpperCase()+n.slice(1))+" supports only inputs with rank above 2."});var i=t[t.length-1],a=Math.ceil(i/e);this.outputShape=t.slice(0,-1),a>1&&this.outputShape.push(a),r||this.variableNames.push("bestIndicesA");var o,s,u=this.outputShape,c=u.length,l=oo(c),f=Ka("coords",c);if(1===a){var d=oo(s=c+1);o="\n "+d+" sourceLocR = "+d+"("+f.join()+", 0);\n ++"+f[c-1]+";\n "+d+" sourceLocG = "+d+"("+f.join()+", 0);\n ++"+f[c-2]+";\n "+d+" sourceLocA = "+d+"("+f.join()+", 0);\n --"+f[c-1]+";\n "+d+" sourceLocB = "+d+"("+f.join()+", 0);\n --"+f[c-2]+";"}else s=c,o="\n "+l+" sourceLocR = coords;\n ++"+f[c-1]+";\n "+l+" sourceLocG = coords;\n ++"+f[c-2]+";\n "+l+" sourceLocA = coords;\n --"+f[c-1]+";\n "+l+" sourceLocB = coords;\n --"+f[c-2]+";";var h=["x","y","z","w","u","v"].slice(0,s),p="."+h[s-1],m=h.map(function(t){return"int "+t}),g=Ka("sourceLocR",s-1).concat("inIdx.r"),v=Ka("sourceLocG",s-1).concat("inIdx.g"),y=Ka("sourceLocB",s-1).concat("inIdx.b"),b=Ka("sourceLocA",s-1).concat("inIdx.a"),x="max"===n?"greaterThan":"lessThan",w=r?"":"\n inIdx = round(vec4(getBestIndicesAChannel("+g.join()+"),\n getBestIndicesAChannel("+v.join()+"),\n getBestIndicesAChannel("+y.join()+"),\n getBestIndicesAChannel("+b.join()+")));",k="vec4(\n getAChannel("+g.join()+"),\n hasNextCol ? getAChannel("+v.join()+") : 0.,\n hasNextRow ? getAChannel("+y.join()+") : 0.,\n hasNextRow && hasNextCol ? getAChannel("+b.join()+") : 0.)",_=r?"":"\n float getBestIndicesAChannel("+m.join()+") {\n return getChannel(getBestIndicesA("+h.join()+"),\n vec2("+h.slice(-2).join()+"));\n }";this.userCode="\n float getAChannel("+m.join()+") {\n return getChannel(getA("+h.join()+"),\n vec2("+h.slice(-2).join()+"));\n }\n "+_+"\n void main() {\n "+l+" coords = getOutputCoords();\n bool hasNextCol = "+f[c-1]+" < "+(u[c-1]-1)+";\n bool hasNextRow = "+f[c-2]+" < "+(u[c-2]-1)+";\n "+o+"\n ivec4 srcIdx = ivec4(sourceLocR"+p+", sourceLocG"+p+",\n sourceLocB"+p+", sourceLocA"+p+") * "+e+";\n ivec4 inIdx = srcIdx;\n vec4 bestIndex = vec4(inIdx);\n vec4 bestValue = "+k+";\n\n for (int i = 0; i < "+e+"; i++) {\n inIdx = srcIdx;\n "+w+"\n vec4 candidate = "+k+";\n bvec4 nan = isnan(candidate);\n bvec4 replace = bvec4(\n vec4("+x+"(candidate, bestValue)) * (vec4(1.0) - vec4(nan)));\n\n bestValue = vec4(replace.x ? candidate.x : bestValue.x,\n replace.y ? candidate.y : bestValue.y,\n replace.z ? candidate.z : bestValue.z,\n replace.w ? candidate.w : bestValue.w);\n bestIndex = mix(bestIndex, vec4(inIdx), vec4(replace));\n srcIdx++;\n }\n setOutput(bestIndex);\n }\n "}(r,Vi(r[r.length-1]),e,null==n),a=null==n?[t]:[t,n],o=this.compileAndRun(i,a,"int32");return o.rank===t.rank?this.argReducePacked(t,e,o):o},e.prototype.sum=function(t,e){Sn("sum",e,t.rank);var n=En(t.shape,e),r=n[0],i=I(n[1]),a=t.as2D(-1,i),o=Rt(t.dtype);return this.reduce(a,"sum",o).reshape(r)},e.prototype.prod=function(t,e){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.prod(t,e);var n=En(t.shape,e),r=n[0],i=I(n[1]),a=t.as2D(-1,i),o=Rt(t.dtype);return this.reduce(a,"prod",o).reshape(r)},e.prototype.unsortedSegmentSum=function(t,e,n){var r=0,i=Cn([r],t.rank),a=t;null!=i&&(a=fa(t,i),r=Nn(1,t.rank)[0]);var o=function(t,e,n){for(var r=[],i=t.length,a=0;a<i;a++)a!==e?r.push(t[a]):r.push(n);return r}(a.shape,r,n),s=I([a.shape[r]]),u=a.as2D(-1,s),c=Rt(t.dtype),l=this.segOpCompute(u,"unsortedSegmentSum",e,c,n).reshape(o);return null!=i&&(l=fa(l,An(i))),l},e.prototype.segOpCompute=function(t,e,n,r,i){var a=t.shape[0],o=t.shape[1],s=function(t,e){var n,r=!1;for(t<=Wi?(n=t,r=!0):n=tt(t,Math.floor(Math.sqrt(t)));!r;)n>e||n===t?r=!0:n=tt(t,n+1);return n}(o,i),u=new function(t,e){this.variableNames=["x","segmentIds"];var n=t.windowSize,r=t.batchSize,i=t.inSize,a=t.numSegments,o=a*Math.ceil(i/n);this.outputShape=[r,o];var s=4*Math.floor(n/4),u=n%4,c="\n sumValue += dot(values, segFilter);\n ",l="";i%n>0&&(l="\n if (inIdx < 0 || inIdx >= "+i+") {\n return initializationValue;\n }\n ");var f="";i%n>0&&(f="\n if (inIdx < 0 || inIdx >= "+i+") {\n return -1.0;\n }\n "),this.userCode="\n const float initializationValue = 0.0;\n\n float getValue(int batch, int inIdx) {\n "+l+"\n return getX(batch, inIdx);\n }\n\n float getSegmentIdAtIndex(int inIdx) {\n "+f+"\n return getSegmentIds(inIdx);\n }\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n int outIdx = coords[1];\n int inOffset = int(floor(float(outIdx) / float(\n "+a+")) * float("+n+"));\n int currentSeg = int(mod(float(outIdx), float("+a+")));\n\n float sumValue = 0.0;\n\n for (int i = 0; i < "+s+"; i += 4) {\n int inIdx = inOffset + i;\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n getValue(batch, inIdx + 3)\n );\n\n vec4 segFilter = vec4(\n int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 2)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 3)) == currentSeg ? 1 : 0\n );\n\n "+c+"\n }\n\n int inIdx = inOffset + "+s+";\n if ("+(1===u)+") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n initializationValue,\n initializationValue,\n initializationValue\n );\n\n int inIdxSeg = int(getSegmentIdAtIndex(inIdx));\n\n vec4 segFilter = vec4(\n int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,\n 0,\n 0,\n 0\n );\n\n "+c+"\n } else if ("+(2===u)+") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n initializationValue,\n initializationValue\n );\n\n vec4 segFilter = vec4(\n int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,\n 0,\n 0\n );\n\n "+c+"\n } else if ("+(3===u)+") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n initializationValue\n );\n\n vec4 segFilter = vec4(\n int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 2)) == currentSeg ? 1 : 0,\n 0\n );\n\n "+c+"\n }\n setOutput(sumValue);\n }\n "}({windowSize:s,inSize:o,batchSize:a,numSegments:i},e),c=this.compileAndRun(u,[t,n],r);return c.shape[1]===i?c:(n=Yn(0,i).tile([o/s]),this.segOpCompute(c,e,n,r,i))},e.prototype.argMinMaxReduce=function(t,e,n){var r=[e];if(Sn("arg"+n.charAt(0).toUpperCase()+n.slice(1),r,t.rank),!f().getBool("WEBGL_PACK_REDUCE")||t.rank<=2){var i=En(t.shape,r),a=i[0],o=I(i[1]),s=t.as2D(-1,o);return this.argReduce(s,n).reshape(a)}return this.argReducePacked(t,n)},e.prototype.argMin=function(t,e){return this.argMinMaxReduce(t,e,"min")},e.prototype.argMax=function(t,e){return this.argMinMaxReduce(t,e,"max")},e.prototype.cumsum=function(t,e,n,r){if(e!==t.rank-1)throw new Error("WebGL cumsum shader expects an inner-most axis="+(t.rank-1)+" but got axis="+e);var i=new function(t,e,n){this.variableNames=["x"],this.outputShape=t;var r=t.length,i=t[t.length-1],a=n?"<":">";this.userCode="\n int getIndex(int i) {\n "+(n?"return "+i+" -i - 1;":"return i;")+"\n }\n\n void main() {\n "+oo(r)+" coords = getOutputCoords();\n int end = "+Eo(r,"coords")+";\n float val = 0.0;\n for (int i = "+i+" - 1; i >= 0; i -= 1) {\n int idx = getIndex(i);\n if (idx "+a+" end) {\n continue;\n }\n if (idx == end && "+e+") {\n continue;\n }\n "+Eo(r,"coords")+" = idx;\n val += getX("+function(t,e){if(1===t)return""+e;if(2===t)return e+".x, "+e+".y";if(3===t)return e+".x, "+e+".y, "+e+".z";if(4===t)return e+".x, "+e+".y, "+e+".z, "+e+".w";throw Error("Cumulative sum for rank "+t+" is not yet supported")}(r,"coords")+");\n }\n setOutput(val);\n }\n "}(t.shape,n,r);return this.compileAndRun(i,[t])},e.prototype.equal=function(t,e){if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n return vec4(equal(a, b));\n","bool");var n=new mo("return float(a == b);",t.shape,e.shape);return this.compileAndRun(n,[t,e],"bool")},e.prototype.notEqual=function(t,e){if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n return vec4(notEqual(a, b));\n","bool");var n=new mo("return float(a != b);",t.shape,e.shape);return this.compileAndRun(n,[t,e],"bool")},e.prototype.less=function(t,e){if(this.shouldExecuteOnCPU([t,e]))return this.cpuBackend.less(t,e);if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n return vec4(lessThan(a, b));\n","bool");var n=new mo("return float(a < b);",t.shape,e.shape);return this.compileAndRun(n,[t,e],"bool")},e.prototype.lessEqual=function(t,e){if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n return vec4(lessThanEqual(a, b));\n","bool");var n=new mo("return float(a <= b);",t.shape,e.shape);return this.compileAndRun(n,[t,e],"bool")},e.prototype.greater=function(t,e){if(this.shouldExecuteOnCPU([t,e]))return this.cpuBackend.greater(t,e);if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n return vec4(greaterThan(a, b));\n","bool");var n=new mo("return float(a > b);",t.shape,e.shape);return this.compileAndRun(n,[t,e],"bool")},e.prototype.greaterEqual=function(t,e){if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n return vec4(greaterThanEqual(a, b));\n","bool");var n=new mo("return float(a >= b);",t.shape,e.shape);return this.compileAndRun(n,[t,e],"bool")},e.prototype.logicalNot=function(t){var e=new ss(t.shape,"return float(!(x >= 1.0));");return this.compileAndRun(e,[t])},e.prototype.logicalAnd=function(t,e){if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n return vec4(\n vec4(greaterThanEqual(a, vec4(1.0))) *\n vec4(greaterThanEqual(b, vec4(1.0))));\n","bool");var n=new mo("return float(a >= 1.0 && b >= 1.0);",t.shape,e.shape);return this.compileAndRun(n,[t,e],"bool")},e.prototype.logicalOr=function(t,e){if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n return min(\n vec4(greaterThanEqual(a, vec4(1.0))) +\n vec4(greaterThanEqual(b, vec4(1.0))),\n vec4(1.0));\n","bool");var n=new mo("return float(a >= 1.0 || b >= 1.0);",t.shape,e.shape);return this.compileAndRun(n,[t,e],"bool")},e.prototype.select=function(t,e,n){var r=new function(t,e,n){var r,i;if(this.variableNames=["c","a","b"],this.outputShape=e,n>4)throw Error("Where for rank "+n+" is not yet supported");if(1===n)i="resRC",r="resRC";else{for(var a=["resRC.x","resRC.y","resRC.z","resRC.w"],o=[],s=[],u=0;u<e.length;u++)s.push(""+a[u]),u<t&&o.push(""+a[u]);r=o.join(),i=s.join()}var c=oo(n);this.userCode="\n void main() {\n "+c+" resRC = getOutputCoords();\n float cVal = getC("+r+");\n if (cVal >= 1.0) {\n setOutput(getA("+i+"));\n } else {\n setOutput(getB("+i+"));\n }\n }\n "}(t.rank,e.shape,e.rank);return this.compileAndRun(r,[t,e,n],Mt(e.dtype,n.dtype))},e.prototype.where=function(t){vn("tf.where() in webgl locks the UI thread. Call tf.whereAsync() instead");var e=t.dataSync();return Ga(t.shape,e)},e.prototype.topk=function(t,e,n){return Ha(t.dataSync(),t.shape,t.dtype,e)},e.prototype.min=function(t,e){Sn("min",e,t.rank);var n=En(t.shape,e),r=n[0],i=I(n[1]),a=t.as2D(-1,i);return this.reduce(a,"min",a.dtype).reshape(r)},e.prototype.minimum=function(t,e){if(this.shouldExecuteOnCPU([t,e]))return this.cpuBackend.minimum(t,e);var n=f().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new vo("\n vec4 result = vec4(min(a, b));\n vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));\n \n result.r = isNaN.r > 0. ? NAN : result.r;\n result.g = isNaN.g > 0. ? NAN : result.g;\n result.b = isNaN.b > 0. ? NAN : result.b;\n result.a = isNaN.a > 0. ? NAN : result.a;\n\n return result;\n",t.shape,e.shape):new mo("\n if (isnan(a)) return a;\n if (isnan(b)) return b;\n\n return min(a, b);\n",t.shape,e.shape);return this.compileAndRun(n,[t,e])},e.prototype.mod=function(t,e){var n=f().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new vo("\n vec4 result = mod(a, b);\n vec4 isNaN = vec4(equal(b, vec4(0.0)));\n \n result.r = isNaN.r > 0. ? NAN : result.r;\n result.g = isNaN.g > 0. ? NAN : result.g;\n result.b = isNaN.b > 0. ? NAN : result.b;\n result.a = isNaN.a > 0. ? NAN : result.a;\n\n return result;\n",t.shape,e.shape):new mo("if (b == 0.0) return NAN;\n return mod(a, b);",t.shape,e.shape);return this.compileAndRun(n,[t,e])},e.prototype.max=function(t,e){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.max(t,e);Sn("max",e,t.rank);var n=En(t.shape,e),r=n[0],i=I(n[1]),a=t.as2D(-1,i);return this.reduce(a,"max",a.dtype).reshape(r)},e.prototype.maximum=function(t,e){if(this.shouldExecuteOnCPU([t,e]))return this.cpuBackend.maximum(t,e);var n=f().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new vo("\n vec4 result = vec4(max(a, b));\n vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));\n \n result.r = isNaN.r > 0. ? NAN : result.r;\n result.g = isNaN.g > 0. ? NAN : result.g;\n result.b = isNaN.b > 0. ? NAN : result.b;\n result.a = isNaN.a > 0. ? NAN : result.a;\n\n return result;\n",t.shape,e.shape):new mo("\n if (isnan(a)) return a;\n if (isnan(b)) return b;\n\n return max(a, b);\n",t.shape,e.shape);return this.compileAndRun(n,[t,e])},e.prototype.all=function(t,e){Sn("all",e,t.rank);var n=En(t.shape,e),r=n[0],i=I(n[1]),a=t.as2D(-1,i);return this.reduce(a,"all",a.dtype).reshape(r)},e.prototype.any=function(t,e){Sn("any",e,t.rank);var n=En(t.shape,e),r=n[0],i=I(n[1]),a=t.as2D(-1,i);return this.reduce(a,"any",a.dtype).reshape(r)},e.prototype.floorDiv=function(t,e){if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n ivec4 ia = round(a);\n ivec4 ib = round(b);\n bvec4 cond = notEqual(ib, ivec4(0));\n ivec4 result = ivec4(0);\n vec4 s = sign(a) * sign(b);\n\n // Windows (D3D) wants guaranteed non-zero int division at compile-time.\n if (cond[0]) {\n result[0] = idiv(ia[0], ib[0], s[0]);\n }\n if (cond[1]) {\n result[1] = idiv(ia[1], ib[1], s[1]);\n }\n if (cond[2]) {\n result[2] = idiv(ia[2], ib[2], s[2]);\n }\n if (cond[3]) {\n result[3] = idiv(ia[3], ib[3], s[3]);\n }\n return vec4(result);\n","int32");var n=new mo("\n float s = sign(a) * sign(b);\n int ia = round(a);\n int ib = round(b);\n if (ib != 0) {\n // Windows (D3D) wants guaranteed non-zero int division at compile-time.\n return float(idiv(ia, ib, s));\n } else {\n return NAN;\n }\n",t.shape,e.shape);return this.compileAndRun(n,[t,e],"int32")},e.prototype.add=function(t,e){if("complex64"===t.dtype&&"complex64"===e.dtype)return this.complexSeparableBinaryOp(t,e,lo);if(this.shouldExecuteOnCPU([t,e]))return this.cpuBackend.add(t,e);var n=Mt(t.dtype,e.dtype);if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,lo,n);var r=new mo(lo,t.shape,e.shape);return this.compileAndRun(r,[t,e],n)},e.prototype.packedUnaryOp=function(t,e,n){var r=new Es(t.shape,e);return this.compileAndRun(r,[t],n)},e.prototype.packedBinaryOp=function(t,e,n,r,i){void 0===i&&(i=!1);var a=new vo(n,t.shape,e.shape,i);return this.compileAndRun(a,[t,e],r)},e.prototype.complexSeparableBinaryOp=function(t,e,n){var r=this,i=this.texData.get(t.dataId),a=this.texData.get(e.dataId),o=[[i.complexTensors.real,a.complexTensors.real],[i.complexTensors.imag,a.complexTensors.imag]].map(function(i){var a=i[0],o=i[1],s=r.makeComplexComponentTensorInfo(t,a),u=r.makeComplexComponentTensorInfo(e,o),c=new mo(n,t.shape,e.shape);return r.compileAndRun(c,[s,u],Mt(a.dtype,o.dtype))}),s=o[0],u=o[1],c=this.complex(s,u);return s.dispose(),u.dispose(),c},e.prototype.makeComplexComponentTensorInfo=function(t,e){return{dataId:e.dataId,dtype:e.dtype,shape:t.shape}},e.prototype.addN=function(t){if(1===t.length)return t[0];if(t.length>f().get("WEBGL_MAX_TEXTURES_IN_SHADER")){var e=Math.floor(t.length/2),n=this.addN(t.slice(0,e)),r=this.addN(t.slice(e));return this.addN([n,r])}var i=t.map(function(t){return t.dtype}).reduce(function(t,e){return Mt(t,e)}),a=t.map(function(t){return t.shape}),o=f().getBool("WEBGL_PACK")?new function(t,e){this.outputShape=[],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t,this.variableNames=e.map(function(t,e){return"T"+e});var n=[];this.variableNames.forEach(function(t){n.push("vec4 v"+t+" = get"+t+"AtOutCoords();")});var r=this.variableNames.map(function(t){return"v"+t}).join(" + ");this.userCode="\n void main() {\n "+n.join("\n ")+"\n\n vec4 result = "+r+";\n setOutput(result);\n }\n "}(t[0].shape,a):new function(t,e){this.outputShape=[],this.outputShape=t,this.variableNames=e.map(function(t,e){return"T"+e});var n=[];this.variableNames.forEach(function(t){n.push("float v"+t+" = get"+t+"AtOutCoords();")});var r=this.variableNames.map(function(t){return"v"+t}).join(" + ");this.userCode="\n void main() {\n "+n.join("\n ")+"\n\n float result = "+r+";\n setOutput(result);\n }\n "}(t[0].shape,a);return this.compileAndRun(o,t,i)},e.prototype.subtract=function(t,e){if("complex64"===t.dtype&&"complex64"===e.dtype)return this.complexSeparableBinaryOp(t,e,fo);if(this.shouldExecuteOnCPU([t,e]))return this.cpuBackend.subtract(t,e);var n=Mt(t.dtype,e.dtype);if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,fo,t.dtype);var r=new mo(fo,t.shape,e.shape);return this.compileAndRun(r,[t,e],n)},e.prototype.pow=function(t,e){var n=f().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new vo("\n // isModRound1 has 1 for components with round(mod(b, 2.0)) == 1, 0 otherwise.\n vec4 isModRound1 = vec4(equal(round(mod(b, 2.0)), ivec4(1)));\n vec4 multiplier = sign(a) * isModRound1 + (vec4(1.0) - isModRound1);\n vec4 result = multiplier * pow(abs(a), b);\n\n // Ensure that a^0 = 1, including 0^0 = 1 as this correspond to TF and JS\n bvec4 isExpZero = equal(b, vec4(0.0));\n result.r = isExpZero.r ? 1.0 : result.r;\n result.g = isExpZero.g ? 1.0 : result.g;\n result.b = isExpZero.b ? 1.0 : result.b;\n result.a = isExpZero.a ? 1.0 : result.a;\n\n vec4 isNaN = vec4(lessThan(a, vec4(0.0))) * vec4(lessThan(floor(b), b));\n \n result.r = isNaN.r > 0. ? NAN : result.r;\n result.g = isNaN.g > 0. ? NAN : result.g;\n result.b = isNaN.b > 0. ? NAN : result.b;\n result.a = isNaN.a > 0. ? NAN : result.a;\n\n return result;\n",t.shape,e.shape):new mo("\nif(a < 0.0 && floor(b) < b){\n return NAN;\n}\nif (b == 0.0) {\n return 1.0;\n}\nreturn (round(mod(b, 2.0)) != 1) ?\n pow(abs(a), b) : sign(a) * pow(abs(a), b);\n",t.shape,e.shape),r=Mt(t.dtype,e.dtype);return this.compileAndRun(n,[t,e],r)},e.prototype.ceil=function(t){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.ceil(t);if(f().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(t,ms,t.dtype);var e=new ss(t.shape,ms);return this.compileAndRun(e,[t])},e.prototype.floor=function(t){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.floor(t);if(f().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(t,gs,t.dtype);var e=new ss(t.shape,gs);return this.compileAndRun(e,[t])},e.prototype.sign=function(t){var e=new ss(t.shape,"\n if (isnan(x)) { return 0.0; }\n return sign(x);\n");return this.compileAndRun(e,[t])},e.prototype.isNaN=function(t){var e=new ss(t.shape,"return float(isnan(x));");return this.compileAndRun(e,[t],"bool")},e.prototype.isInf=function(t){var e=new ss(t.shape,"return float(isinf(x));");return this.compileAndRun(e,[t],"bool")},e.prototype.isFinite=function(t){var e=new ss(t.shape,"return float(!isnan(x) && !isinf(x));");return this.compileAndRun(e,[t],"bool")},e.prototype.round=function(t){var e=new ss(t.shape,"\n // OpenGL ES does not support round function.\n // The algorithm is based on banker's rounding.\n float base = floor(x);\n if ((x - base) < 0.5) {\n return floor(x);\n } else if ((x - base) > 0.5) {\n return ceil(x);\n } else {\n if (mod(base, 2.0) == 0.0) {\n return base;\n } else {\n return base + 1.0;\n }\n }\n");return this.compileAndRun(e,[t])},e.prototype.exp=function(t){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.exp(t);if(f().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(t,vs,t.dtype);var e=new ss(t.shape,vs);return this.compileAndRun(e,[t])},e.prototype.expm1=function(t){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.expm1(t);if(f().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(t,ys,t.dtype);var e=new ss(t.shape,ys);return this.compileAndRun(e,[t])},e.prototype.softmax=function(t,e){var n=z([e],t.shape),r=this.max(t,n),i=On(r.shape,n),a=this.subtract(t,r.reshape(i)),o=this.exp(a),s=this.sum(o,n).reshape(i);return zi(o,s)},e.prototype.log=function(t){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.log(t);if(f().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(t,"\n vec4 result = log(x);\n vec4 isNaN = vec4(lessThan(x, vec4(0.0)));\n result.r = isNaN.r == 1.0 ? NAN : result.r;\n result.g = isNaN.g == 1.0 ? NAN : result.g;\n result.b = isNaN.b == 1.0 ? NAN : result.b;\n result.a = isNaN.a == 1.0 ? NAN : result.a;\n\n return result;\n",t.dtype);var e=new ss(t.shape,"if (x < 0.0) return NAN;\n return log(x);");return this.compileAndRun(e,[t])},e.prototype.log1p=function(t){var e=new ss(t.shape,"return log(1.0 + x);");return this.compileAndRun(e,[t])},e.prototype.sqrt=function(t){var e=new ss(t.shape,"return sqrt(x);");return this.compileAndRun(e,[t])},e.prototype.rsqrt=function(t){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.rsqrt(t);var e=new ss(t.shape,"return inversesqrt(x);");return this.compileAndRun(e,[t])},e.prototype.reciprocal=function(t){var e=new ss(t.shape,"return 1.0 / x;");return this.compileAndRun(e,[t])},e.prototype.relu=function(t){var e;return e=f().getBool("WEBGL_PACK")?new Es(t.shape,ws):new ss(t.shape,fs),this.compileAndRun(e,[t])},e.prototype.relu6=function(t){var e;return e=f().getBool("WEBGL_PACK")?new Es(t.shape,ks):new ss(t.shape,ds),this.compileAndRun(e,[t])},e.prototype.prelu=function(t,e){var n=f().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new vo(go,t.shape,e.shape):new mo(po,t.shape,e.shape);return this.compileAndRun(n,[t,e])},e.prototype.elu=function(t){if(f().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(t,_s,t.dtype);var e=new ss(t.shape,hs);return this.compileAndRun(e,[t])},e.prototype.eluDer=function(t,e){var n=f().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new vo("\n vec4 bGTEZero = vec4(greaterThanEqual(b, vec4(0.)));\n return (bGTEZero * a) + ((vec4(1.0) - bGTEZero) * (a * (b + vec4(1.0))));\n",t.shape,e.shape):new mo("return (b >= 1.0) ? a : a * (b + 1.0);",t.shape,e.shape);return this.compileAndRun(n,[t,e])},e.prototype.selu=function(t){var e=new ss(t.shape,"\n // Stable and Attracting Fixed Point (0, 1) for Normalized Weights.\n // see: https://arxiv.org/abs/1706.02515\n float scaleAlpha = 1.7580993408473768;\n float scale = 1.0507009873554805;\n return (x >= 0.0) ? scale * x : scaleAlpha * (exp(x) - 1.0);\n");return this.compileAndRun(e,[t])},e.prototype.int=function(t){var e=new ss(t.shape,"return float(int(x));");return this.compileAndRun(e,[t],"int32")},e.prototype.clip=function(t,e,n){var r,i=(r=f().getBool("WEBGL_PACK_CLIP")?new bo(t.shape):new yo(t.shape)).getCustomSetupFunc(e,n);return this.compileAndRun(r,[t],null,i)},e.prototype.abs=function(t){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.abs(t);if(f().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(t,ls,t.dtype);var e=new ss(t.shape,ls);return this.compileAndRun(e,[t])},e.prototype.complexAbs=function(t){var e=this.texData.get(t.dataId),n=new function(t){this.variableNames=["real","imag"],this.outputShape=t,this.userCode="\n void main() {\n float re = abs(getRealAtOutCoords());\n float im = abs(getImagAtOutCoords());\n float mx = max(re, im);\n\n // sadly the length function in glsl is not underflow-safe\n // (at least not on Intel GPUs). So the safe solution is\n // to ensure underflow-safety in all cases.\n setOutput(\n mx == 0.0 ? 0.0 : mx * length(vec2(1, min(re, im)/mx))\n );\n }\n "}(t.shape),r=[this.makeComplexComponentTensorInfo(t,e.complexTensors.real),this.makeComplexComponentTensorInfo(t,e.complexTensors.imag)];return this.compileAndRun(n,r)},e.prototype.sigmoid=function(t){var e=new ss(t.shape,"return 1.0 / (1.0 + exp(-1.0 * x));");return this.compileAndRun(e,[t])},e.prototype.softplus=function(t){var e=new ss(t.shape,"\n float epsilon = 1.1920928955078125e-7;\n float threshold = log(epsilon) + 2.0;\n\n bool too_large = x > -threshold;\n bool too_small = x < threshold;\n\n float result;\n float exp_x = exp(x);\n\n if (too_large){\n result = x;\n }\n else if (too_small){\n result = exp_x;\n }\n else{\n result = log(exp_x + 1.0);\n }\n return result;\n");return this.compileAndRun(e,[t])},e.prototype.sin=function(t){var e=new ss(t.shape,"if (isnan(x)) return x;\n return sin(x);\n");return this.compileAndRun(e,[t])},e.prototype.cos=function(t){var e=new ss(t.shape,"if (isnan(x)) return x;\n return cos(x);\n");return this.compileAndRun(e,[t])},e.prototype.tan=function(t){var e=new ss(t.shape,"return tan(x);");return this.compileAndRun(e,[t])},e.prototype.asin=function(t){var e=new ss(t.shape,"if (isnan(x)) return x;\n if (abs(x) > 1.) {\n return NAN;\n }\n return asin(x);\n");return this.compileAndRun(e,[t])},e.prototype.acos=function(t){var e=new ss(t.shape,"if (isnan(x)) return x;\n if (abs(x) > 1.) {\n return NAN;\n }\n return acos(x);\n");return this.compileAndRun(e,[t])},e.prototype.atan=function(t){var e=new ss(t.shape,"if (isnan(x)) return x;\n return atan(x);\n");return this.compileAndRun(e,[t])},e.prototype.atan2=function(t,e){var n=f().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new vo("\n vec4 result = atan(a, b);\n vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));\n \n result.r = isNaN.r > 0. ? NAN : result.r;\n result.g = isNaN.g > 0. ? NAN : result.g;\n result.b = isNaN.b > 0. ? NAN : result.b;\n result.a = isNaN.a > 0. ? NAN : result.a;\n\n return result;\n",t.shape,e.shape):new mo("\n if (isnan(a)) return a;\n if (isnan(b)) return b;\n\n return atan(a, b);\n",t.shape,e.shape);return this.compileAndRun(n,[t,e])},e.prototype.sinh=function(t){var e=new ss(t.shape,"\n float e2x = exp(x);\n return (e2x - 1.0 / e2x) / 2.0;\n");return this.compileAndRun(e,[t])},e.prototype.cosh=function(t){var e=new ss(t.shape,"\n float e2x = exp(-x);\n return (e2x + 1.0 / e2x) / 2.0;\n");return this.compileAndRun(e,[t])},e.prototype.tanh=function(t){var e=new ss(t.shape,"\n float e2x = exp(-2.0 * abs(x));\n return sign(x) * (1.0 - e2x) / (1.0 + e2x);\n");return this.compileAndRun(e,[t])},e.prototype.asinh=function(t){var e=new ss(t.shape,"if (isnan(x)) return x;return log(x + sqrt(x * x + 1.0));");return this.compileAndRun(e,[t])},e.prototype.acosh=function(t){var e=new ss(t.shape,"if (isnan(x)) return x;\n if (x < 1.0) return NAN;\n return log(x + sqrt(x * x - 1.0));");return this.compileAndRun(e,[t])},e.prototype.atanh=function(t){var e=new ss(t.shape,"if (isnan(x)) return x;\n if ((x < -1.0) || (x > 1.0)) return NAN;\n return (log(1.0 + x) - log(1.0 - x)) / 2.0;");return this.compileAndRun(e,[t])},e.prototype.erf=function(t){var e=new ss(t.shape,'\n // Error function is calculated approximately with elementary function.\n // See "Handbook of Mathematical Functions with Formulas,\n // Graphs, and Mathematical Tables", Abramowitz and Stegun.\n float p = 0.3275911;\n float a1 = 0.254829592;\n float a2 = -0.284496736;\n float a3 = 1.421413741;\n float a4 = -1.453152027;\n float a5 = 1.061405429;\n\n float sign = sign(x);\n x = abs(x);\n float t = 1.0 / (1.0 + p * x);\n return sign * (1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x));\n');return this.compileAndRun(e,[t])},e.prototype.step=function(t,e){var n=new ss(t.shape,function(t){return void 0===t&&(t=0),us+"\n return x > 0.0 ? 1.0 : float("+t+");\n "}(e));return this.compileAndRun(n,[t])},e.prototype.conv2dByMatMul=function(t,e,n,r,i,a){var o=t.shape,s=this.texData.get(t.dataId),u=n.inChannels,c=o[0]*o[1]*o[2],l=n.outChannels,d="channelsLast"===n.dataFormat,h=(1===c||1===l)&&u>1e3,p=o[2]%2!=0&&!!s.isPacked;if(h||!f().getBool("WEBGL_LAZILY_UNPACK")||!f().getBool("WEBGL_PACK_BINARY_OPERATIONS")||!p){var m=d?o[0]*o[1]*o[2]:o[0]*o[2]*o[3],g=this.reshape(t,[1,m,n.inChannels]),v=this.reshape(e,[1,n.inChannels,n.outChannels]);return this.reshape(this.fusedBatchMatMul({a:g,b:v,transposeA:!1,transposeB:!1,bias:r,activation:i,preluActivationWeights:a}),n.outShape)}var y=d?o[0]*o[1]*(o[2]+1):o[0]*o[2]*(o[3]+1),b={dataId:t.dataId,shape:[1,y,n.inChannels],dtype:t.dtype},x=s.shape;s.shape=s.shape.slice(),s.shape[s.shape.length-2]++,C(Pe(s.shape,b.shape),function(){return"packed reshape "+s.shape+" to "+b.shape+" isn't free"});var w=this.reshape(e,[1,n.inChannels,n.outChannels]),k=this.fusedBatchMatMul({a:b,b:w,transposeA:!1,transposeB:!1,bias:r,activation:i,preluActivationWeights:a}),_=this.texData.get(k.dataId);return C(_.isPacked,function(){return"batchMatMul result is expected to be packed"}),s.shape=x,_.shape=n.outShape,Wt.makeTensorFromDataId(k.dataId,n.outShape,k.dtype)},e.prototype.conv2dWithIm2Row=function(t,e,n,r,i,a){var o=n.filterWidth,s=n.filterHeight,u=n.inChannels,c=n.outWidth,l=n.outHeight,f="channelsLast"===n.dataFormat,d=o*s*u,h=l*c,p=[d,h],m=t.squeeze([0]),g=e.reshape([1,d,-1]),v=new function(t,e,n){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t;for(var r=n.filterWidth,i=n.inChannels,a=n.strideWidth,o=n.strideHeight,s=n.padInfo,u=n.outWidth,c=n.dilationWidth,l=n.dilationHeight,f=n.dataFormat,d=s.left,h=s.top,p=i*r,m=Xa(),g="channelsLast"===f,v=g?0:1,y=g?1:2,b="",x=0;x<=1;x++)for(var w=0;w<=1;w++)b+="\n blockIndex = rc.y + "+w+";\n pos = rc.x + "+x+";\n\n if(blockIndex < "+t[1]+" && pos < "+t[0]+") {\n offsetY = int(blockIndex / ("+u+")) * "+o+" - "+h+";\n d0 = offsetY + "+l+" * (pos / "+p+");\n\n if(d0 < "+e[v]+" && d0 >= 0) {\n\n offsetX = int(mod(float(blockIndex), "+u+".) * "+a+". - "+d+".);\n d1 = offsetX + "+c+" * (int(mod(float(pos), "+p+".) / "+i+".));\n\n if(d1 < "+e[y]+" && d1 >= 0) {\n\n ch = int(mod(float(pos), "+i+".));\n\n if ("+g+") {\n innerDims = vec2(d1, ch);\n result["+(2*x+w)+"] = getChannel(\n getA(d0, int(innerDims.x),\n int(innerDims.y)), innerDims);\n } else {\n innerDims = vec2(d0, d1);\n result["+(2*x+w)+"] = getChannel(\n getA(ch, int(innerDims.x),\n int(innerDims.y)), innerDims);\n }\n }\n }\n }\n ";this.userCode="\n void main() {\n ivec2 rc = getOutputCoords();\n\n vec4 result = vec4(0);\n\n int blockIndex, pos, offsetY, d0, offsetX, d1, ch;\n vec2 innerDims;\n\n "+b+"\n\n "+m.output+" = result;\n }\n "}(p,m.shape,n),y=this.compileAndRun(v,[m]).reshape([1,p[0],p[1]]),b=null!=r,x=null!=a,w=i?Ss(i,!0):null,k=new Ko(y.shape,[1,h,n.outChannels],!0,!1,b,w,x),_=[y,g];r&&_.push(r),x&&_.push(a);var E=this.compileAndRun(k,_);return f?E.reshape([1,l,c,n.outChannels]):E.reshape([1,n.outChannels,l,c])},e.prototype.fusedConv2d=function(t){var e=t.input,n=t.filter,r=t.convInfo,i=t.bias,a=t.activation,o=t.preluActivationWeights;if(1===r.filterHeight&&1===r.filterWidth&&1===r.dilationHeight&&1===r.dilationWidth&&1===r.strideHeight&&1===r.strideWidth&&("SAME"===r.padInfo.type||"VALID"===r.padInfo.type))return this.conv2dByMatMul(e,n,r,i,a,o);if(f().getBool("WEBGL_CONV_IM2COL")&&1===e.shape[0])return this.conv2dWithIm2Row(e,n,r,i,a,o);var s=null!=i,u=null!=o,c=a?Ss(a,!1):null,l=new wo(r,s,c,u),d=[e,n];return i&&d.push(i),o&&d.push(o),this.compileAndRun(l,d)},e.prototype.conv2d=function(t,e,n){if(1===n.filterHeight&&1===n.filterWidth&&1===n.dilationHeight&&1===n.dilationWidth&&1===n.strideHeight&&1===n.strideWidth&&("SAME"===n.padInfo.type||"VALID"===n.padInfo.type))return this.conv2dByMatMul(t,e,n);if(f().getBool("WEBGL_CONV_IM2COL")&&1===t.shape[0])return this.conv2dWithIm2Row(t,e,n);var r=new wo(n);return this.compileAndRun(r,[t,e])},e.prototype.conv2dDerInput=function(t,e,n){var r=new function(t){this.variableNames=["dy","W"],this.outputShape=t.inShape;var e=t.filterHeight,n=t.filterWidth,r=t.strideHeight,i=t.strideWidth,a="channelsLast"===t.dataFormat,o=e-1-t.padInfo.top,s=n-1-t.padInfo.left,u=a?1:2,c=a?2:3,l=a?3:1;this.userCode="\n const ivec2 pads = ivec2("+o+", "+s+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d1 = coords["+l+"];\n\n ivec2 dyCorner = ivec2(coords["+u+"], coords["+c+"]) - pads;\n int dyRCorner = dyCorner.x;\n int dyCCorner = dyCorner.y;\n\n // Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < "+e+"; wR++) {\n float dyR = float(dyRCorner + wR) / "+r+".0;\n\n if (dyR < 0.0 || dyR >= "+t.outHeight+".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n int wRPerm = "+e+" - 1 - wR;\n\n for (int wC = 0; wC < "+n+"; wC++) {\n float dyC = float(dyCCorner + wC) / "+i+".0;\n\n if (dyC < 0.0 || dyC >= "+t.outWidth+".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n int wCPerm = "+n+" - 1 - wC;\n\n for (int d2 = 0; d2 < "+t.outChannels+"; d2++) {\n\n if ("+a+") {\n float xValue = getDy(batch, idyR, idyC, d2);\n float wValue = getW(wRPerm, wCPerm, d1, d2);\n dotProd += xValue * wValue;\n } else {\n float xValue = getDy(batch, d2, idyR, idyC);\n float wValue = getW(wRPerm, wCPerm, d1, d2);\n dotProd += xValue * wValue;\n }\n\n }\n }\n }\n setOutput(dotProd);\n }\n "}(n);return this.compileAndRun(r,[t,e])},e.prototype.conv2dDerFilter=function(t,e,n){var r=new function(t){this.variableNames=["x","dy"],this.outputShape=t.filterShape;var e=t.strideHeight,n=t.strideWidth,r=t.padInfo.top,i=t.padInfo.left,a="channelsLast"===t.dataFormat;this.userCode="\n void main() {\n ivec4 coords = getOutputCoords();\n int wR = coords.x;\n int wC = coords.y;\n int d1 = coords.z;\n int d2 = coords.w;\n\n // Convolve x(?, ?, d1) with dy(:, :, d2) to get dw(wR, wC, d1, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n\n for (int b = 0; b < "+t.batchSize+"; b++) {\n for (int yR = 0; yR < "+t.outHeight+"; yR++) {\n int xR = wR + yR * "+e+" - "+r+";\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int yC = 0; yC < "+t.outWidth+"; yC++) {\n int xC = wC + yC * "+n+" - "+i+";\n\n if (xC < 0 || xC >= "+t.inWidth+") {\n continue;\n }\n\n if ("+a+") {\n float dyValue = getDy(b, yR, yC, d2);\n float xValue = getX(b, xR, xC, d1);\n dotProd += (xValue * dyValue);\n } else {\n float dyValue = getDy(b, d2, yR, yC);\n float xValue = getX(b, d1, xR, xC);\n dotProd += (xValue * dyValue);\n }\n\n }\n }\n }\n setOutput(dotProd);\n }\n "}(n);return this.compileAndRun(r,[t,e])},e.prototype.fusedDepthwiseConv2D=function(t){var e,n=t.input,r=t.filter,i=t.convInfo,a=t.bias,o=t.activation,s=t.preluActivationWeights,u=f().getBool("WEBGL_PACK_DEPTHWISECONV")&&i.strideWidth<=2&&i.outChannels/i.inChannels==1,c=o?Ss(o,u):null,l=[n,r],d=null!=a,h=null!=s;return d&&l.push(a),h&&l.push(s),u?(e=new _o(i,d,c,h),this.compileAndRun(e,l)):(e=new ko(i,d,c,h),this.compileAndRun(e,l))},e.prototype.depthwiseConv2D=function(t,e,n){var r;return f().getBool("WEBGL_PACK_DEPTHWISECONV")&&n.strideWidth<=2&&n.outChannels/n.inChannels==1?(r=new _o(n),this.compileAndRun(r,[t,e])):(r=new ko(n),this.compileAndRun(r,[t,e]))},e.prototype.depthwiseConv2DDerInput=function(t,e,n){var r=new function(t){this.variableNames=["dy","W"],this.outputShape=t.inShape;var e=t.filterHeight,n=t.filterWidth,r=t.strideHeight,i=t.strideWidth,a=e-1-t.padInfo.top,o=n-1-t.padInfo.left,s=t.outChannels/t.inChannels;this.userCode="\n const ivec2 pads = ivec2("+a+", "+o+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d1 = coords[3];\n ivec2 dyCorner = coords.yz - pads;\n int dyRCorner = dyCorner.x;\n int dyCCorner = dyCorner.y;\n\n float dotProd = 0.0;\n\n for (int wR = 0; wR < "+e+"; wR++) {\n float dyR = float(dyRCorner + wR) / "+r+".0;\n\n if (dyR < 0.0 || dyR >= "+t.outHeight+".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n int wRPerm = "+e+" - 1 - wR;\n\n for (int wC = 0; wC < "+n+"; wC++) {\n float dyC = float(dyCCorner + wC) / "+i+".0;\n\n if (dyC < 0.0 || dyC >= "+t.outWidth+".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n int wCPerm = "+n+" - 1 - wC;\n\n // TO DO: Vec4 over the channelMul\n for (int dm = 0; dm < "+s+"; dm++) {\n int d2 = d1 * "+s+" + dm;\n float xValue = getDy(batch, idyR, idyC, d2);\n float wValue = getW(wRPerm, wCPerm, d1, dm);\n dotProd += xValue * wValue;\n }\n }\n }\n setOutput(dotProd);\n }\n "}(n);return this.compileAndRun(r,[t,e])},e.prototype.depthwiseConv2DDerFilter=function(t,e,n){var r=new function(t){this.variableNames=["x","dy"],this.outputShape=t.filterShape;var e=t.strideHeight,n=t.strideWidth,r=t.padInfo.top,i=t.padInfo.left,a=t.outChannels/t.inChannels;this.userCode="\n void main() {\n ivec4 coords = getOutputCoords();\n int wR = coords.x;\n int wC = coords.y;\n int d1 = coords.z;\n int dm = coords.w;\n int d2 = d1 * "+a+" + dm;\n\n float dotProd = 0.0;\n\n // TO DO: Vec4 over the batch size\n for (int b = 0; b < "+t.batchSize+"; b++) {\n for (int yR = 0; yR < "+t.outHeight+"; yR++) {\n int xR = wR + yR * "+e+" - "+r+";\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int yC = 0; yC < "+t.outWidth+"; yC++) {\n int xC = wC + yC * "+n+" - "+i+";\n\n if (xC < 0 || xC >= "+t.inWidth+") {\n continue;\n }\n\n float dyValue = getDy(b, yR, yC, d2);\n float xValue = getX(b, xR, xC, d1);\n dotProd += (xValue * dyValue);\n }\n }\n }\n setOutput(dotProd);\n }\n "}(n);return this.compileAndRun(r,[t,e])},e.prototype.conv3d=function(t,e,n){var r=new function(t){this.variableNames=["x","W"],this.outputShape=t.outShape;var e=t.padInfo.front,n=t.padInfo.top,r=t.padInfo.left,i=t.strideDepth,a=t.strideHeight,o=t.strideWidth,s=t.dilationDepth,u=t.dilationHeight,c=t.dilationWidth,l=t.filterDepth,f=t.filterHeight,d=t.filterWidth,h=4*Math.floor(t.inChannels/4),p=t.inChannels%4;this.userCode="\n const ivec3 strides = ivec3("+i+", "+a+", "+o+");\n const ivec3 pads = ivec3("+e+", "+n+", "+r+");\n\n void main() {\n ivec5 coords = getOutputCoords();\n int batch = coords.x;\n int d2 = coords.u;\n\n ivec3 xFRCCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;\n int xFCorner = xFRCCorner.x;\n int xRCorner = xFRCCorner.y;\n int xCCorner = xFRCCorner.z;\n\n // Convolve x(?, ?, ?, d1) with w(:, :, :, d1, d2) to get\n // y(yF, yR, yC, d2). ? = to be determined. : = across all\n // values in that axis.\n float dotProd = 0.0;\n for (int wF = 0; wF < "+l+"; wF++) {\n int xF = xFCorner + wF * "+s+";\n\n if (xF < 0 || xF >= "+t.inDepth+") {\n continue;\n }\n\n for (int wR = 0; wR < "+f+"; wR++) {\n int xR = xRCorner + wR * "+u+";\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int wC = 0; wC < "+d+"; wC++) {\n int xC = xCCorner + wC * "+c+";\n\n if (xC < 0 || xC >= "+t.inWidth+") {\n continue;\n }\n\n for (int d1 = 0; d1 < "+h+"; d1 += 4) {\n vec4 xValues = vec4(\n getX(batch, xF, xR, xC, d1),\n getX(batch, xF, xR, xC, d1 + 1),\n getX(batch, xF, xR, xC, d1 + 2),\n getX(batch, xF, xR, xC, d1 + 3)\n );\n vec4 wValues = vec4(\n getW(wF, wR, wC, d1, d2),\n getW(wF, wR, wC, d1 + 1, d2),\n getW(wF, wR, wC, d1 + 2, d2),\n getW(wF, wR, wC, d1 + 3, d2)\n );\n\n dotProd += dot(xValues, wValues);\n }\n\n if ("+(1===p)+") {\n dotProd +=\n getX(batch, xF, xR, xC, "+h+") *\n getW(wF, wR, wC, "+h+", d2);\n } else if ("+(2===p)+") {\n vec2 xValues = vec2(\n getX(batch, xF, xR, xC, "+h+"),\n getX(batch, xF, xR, xC, "+h+" + 1)\n );\n vec2 wValues = vec2(\n getW(wF, wR, wC, "+h+", d2),\n getW(wF, wR, wC, "+h+" + 1, d2)\n );\n dotProd += dot(xValues, wValues);\n } else if ("+(3===p)+") {\n vec3 xValues = vec3(\n getX(batch, xF, xR, xC, "+h+"),\n getX(batch, xF, xR, xC, "+h+" + 1),\n getX(batch, xF, xR, xC, "+h+" + 2)\n );\n vec3 wValues = vec3(\n getW(wF, wR, wC, "+h+", d2),\n getW(wF, wR, wC, "+h+" + 1, d2),\n getW(wF, wR, wC, "+h+" + 2, d2)\n );\n dotProd += dot(xValues, wValues);\n }\n }\n }\n }\n setOutput(dotProd);\n }\n "}(n);return this.compileAndRun(r,[t,e])},e.prototype.conv3dDerInput=function(t,e,n){var r=new function(t){this.variableNames=["dy","W"],this.outputShape=t.inShape;var e=t.filterDepth,n=t.filterHeight,r=t.filterWidth,i=t.strideDepth,a=t.strideHeight,o=t.strideWidth,s=e-1-t.padInfo.front,u=n-1-t.padInfo.top,c=r-1-t.padInfo.left;this.userCode="\n const ivec3 pads = ivec3("+s+", "+u+", "+c+");\n\n void main() {\n ivec5 coords = getOutputCoords();\n int batch = coords.x;\n int d1 = coords.u;\n\n\n ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;\n int dyFCorner = dyCorner.x;\n int dyRCorner = dyCorner.y;\n int dyCCorner = dyCorner.z;\n\n float dotProd = 0.0;\n for (int wF = 0; wF < "+e+"; wF++) {\n float dyF = float(dyFCorner + wF) / "+i+".0;\n\n if (dyF < 0.0 || dyF >= "+t.outDepth+".0 || fract(dyF) > 0.0) {\n continue;\n }\n int idyF = int(dyF);\n\n int wFPerm = "+e+" - 1 - wF;\n\n for (int wR = 0; wR < "+n+"; wR++) {\n float dyR = float(dyRCorner + wR) / "+a+".0;\n\n if (dyR < 0.0 || dyR >= "+t.outHeight+".0 ||\n fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n int wRPerm = "+n+" - 1 - wR;\n\n for (int wC = 0; wC < "+r+"; wC++) {\n float dyC = float(dyCCorner + wC) / "+o+".0;\n\n if (dyC < 0.0 || dyC >= "+t.outWidth+".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n int wCPerm = "+r+" - 1 - wC;\n\n for (int d2 = 0; d2 < "+t.outChannels+"; d2++) {\n float xValue = getDy(batch, idyF, idyR, idyC, d2);\n float wValue = getW(wFPerm, wRPerm, wCPerm, d1, d2);\n dotProd += xValue * wValue;\n }\n }\n }\n }\n setOutput(dotProd);\n }\n "}(n);return this.compileAndRun(r,[t,e])},e.prototype.conv3dDerFilter=function(t,e,n){var r=new function(t){this.variableNames=["x","dy"],this.outputShape=t.filterShape;var e=t.strideDepth,n=t.strideHeight,r=t.strideWidth,i=t.padInfo.front,a=t.padInfo.top,o=t.padInfo.left;this.userCode="\n void main() {\n ivec5 coords = getOutputCoords();\n int wF = coords.x;\n int wR = coords.y;\n int wC = coords.z;\n int d1 = coords.w;\n int d2 = coords.u;\n\n float dotProd = 0.0;\n\n for (int b = 0; b < "+t.batchSize+"; b++) {\n for (int yF = 0; yF < "+t.outDepth+"; yF++) {\n int xF = wF + yF * "+e+" - "+i+";\n\n if (xF < 0 || xF >= "+t.inDepth+") {\n continue;\n }\n\n for (int yR = 0; yR < "+t.outHeight+"; yR++) {\n int xR = wR + yR * "+n+" - "+a+";\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int yC = 0; yC < "+t.outWidth+"; yC++) {\n int xC = wC + yC * "+r+" - "+o+";\n\n if (xC < 0 || xC >= "+t.inWidth+") {\n continue;\n }\n\n float dyValue = getDy(b, yF, yR, yC, d2);\n float xValue = getX(b, xF, xR, xC, d1);\n dotProd += (xValue * dyValue);\n }\n }\n }\n }\n setOutput(dotProd);\n }\n "}(n);return this.compileAndRun(r,[t,e])},e.prototype.maxPool=function(t,e){var n=new Yo(e,"max",!1);return this.compileAndRun(n,[t])},e.prototype.avgPool=function(t,e){var n=new Yo(e,"avg",!1);return this.compileAndRun(n,[t],"float32")},e.prototype.maxPoolBackprop=function(t,e,n,r){var i=new Yo(r,"max",!0),a=this.compileAndRun(i,[e]),o=new function(t){this.variableNames=["dy","maxPos"],this.outputShape=t.inShape;var e=t.strideHeight,n=t.strideWidth,r=t.dilationHeight,i=t.effectiveFilterHeight,a=t.effectiveFilterWidth,o=i-1-t.padInfo.top,s=a-1-t.padInfo.left,u=i*a-1;this.userCode="\n const ivec2 pads = ivec2("+o+", "+s+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n\n ivec2 dyRCCorner = coords.yz - pads;\n int dyRCorner = dyRCCorner.x;\n int dyCCorner = dyRCCorner.y;\n\n // Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < "+i+";\n wR += "+r+") {\n float dyR = float(dyRCorner + wR) / "+e+".0;\n\n if (dyR < 0.0 || dyR >= "+t.outHeight+".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < "+a+"; wC++) {\n float dyC = float(dyCCorner + wC) / "+n+".0;\n\n if (dyC < 0.0 || dyC >= "+t.outWidth+".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(b, idyR, idyC, d);\n int maxPosValue = "+u+" - int(getMaxPos(b, idyR, idyC, d));\n\n // Get the current value, check it against the value from the\n // position matrix.\n int curPosValue = wR * "+a+" + wC;\n float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);\n\n dotProd += dyValue * mask;\n }\n }\n setOutput(dotProd);\n }\n "}(r),s=this.compileAndRun(o,[t,a],e.dtype);return a.dispose(),s},e.prototype.avgPoolBackprop=function(t,e,n){var r=new function(t){this.variableNames=["dy"],this.outputShape=t.inShape;var e=t.filterHeight,n=t.filterWidth,r=t.strideHeight,i=t.strideWidth,a=t.dilationHeight,o=t.dilationWidth,s=t.effectiveFilterHeight,u=t.effectiveFilterWidth,c=s-1-t.padInfo.top,l=u-1-t.padInfo.left,f=1/(e*n);this.userCode="\n const ivec2 pads = ivec2("+c+", "+l+");\n const float avgMultiplier = float("+f+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n\n ivec2 dyRCCorner = coords.yz - pads;\n int dyRCorner = dyRCCorner.x;\n int dyCCorner = dyRCCorner.y;\n\n // Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < "+s+";\n wR += "+a+") {\n float dyR = float(dyRCorner + wR) / "+r+".0;\n\n if (dyR < 0.0 || dyR >= "+t.outHeight+".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < "+u+";\n wC+= "+o+") {\n float dyC = float(dyCCorner + wC) / "+i+".0;\n\n if (dyC < 0.0 || dyC >= "+t.outWidth+".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(b, idyR, idyC, d);\n\n dotProd += dyValue * avgMultiplier;\n }\n }\n setOutput(dotProd);\n }\n "}(n);return this.compileAndRun(r,[t],e.dtype)},e.prototype.cast=function(t,e){return Ca(t,e,this)},e.prototype.unstack=function(t,e){for(var n=t.shape[e],r=new Array(t.rank-1),i=0,a=0;a<t.rank;a++)a!==e&&(r[i++]=t.shape[a]);var o=new Array(t.rank).fill(0),s=t.shape.slice();s[e]=1;var u=new Array(n);for(a=0;a<u.length;a++)o[e]=a,u[a]=this.slice(t,o,s).reshape(r);return u},e.prototype.avgPool3d=function(t,e){var n=new Jo(e,"avg",!1);return this.compileAndRun(n,[t],"float32")},e.prototype.avgPool3dBackprop=function(t,e,n){var r=new function(t){this.variableNames=["dy"],this.outputShape=t.inShape;var e=t.filterDepth,n=t.filterHeight,r=t.filterWidth,i=t.strideDepth,a=t.strideHeight,o=t.strideWidth,s=t.dilationDepth,u=t.dilationHeight,c=t.dilationWidth,l=t.effectiveFilterDepth,f=t.effectiveFilterHeight,d=t.effectiveFilterWidth,h=l-1-t.padInfo.front,p=f-1-t.padInfo.top,m=d-1-t.padInfo.left,g=1/(e*n*r);this.userCode="\n const ivec3 pads = ivec3("+h+", "+p+", "+m+");\n const float avgMultiplier = float("+g+");\n\n void main() {\n ivec5 coords = getOutputCoords();\n int batch = coords.x;\n int ch = coords.u;\n\n ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;\n int dyDCorner = dyCorner.x;\n int dyRCorner = dyCorner.y;\n int dyCCorner = dyCorner.z;\n\n // Convolve dy(?, ?, ?, d) with pos mask(:, :, :, ch) to get\n // dx(xD, xR, xC, ch).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n\n for (int wD = 0; wD < "+l+";\n wD += "+s+") {\n float dyD = float(dyDCorner + wD) / "+i+".0;\n\n if (dyD < 0.0 || dyD >= "+t.outDepth+".0 || fract(dyD) > 0.0) {\n continue;\n }\n int idyD = int(dyD);\n\n for (int wR = 0; wR < "+f+";\n wR += "+u+") {\n float dyR = float(dyRCorner + wR) / "+a+".0;\n\n if (dyR < 0.0 || dyR >= "+t.outHeight+".0 ||\n fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < "+d+";\n wC += "+c+") {\n float dyC = float(dyCCorner + wC) / "+o+".0;\n\n if (dyC < 0.0 || dyC >= "+t.outWidth+".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(batch, idyD, idyR, idyC, ch);\n\n dotProd += dyValue * avgMultiplier;\n }\n }\n }\n setOutput(dotProd);\n }\n "}(n);return this.compileAndRun(r,[t],e.dtype)},e.prototype.maxPool3d=function(t,e){var n=new Jo(e,"max",!1);return this.compileAndRun(n,[t],"float32")},e.prototype.maxPool3dBackprop=function(t,e,n,r){var i=new Jo(r,"max",!0),a=this.compileAndRun(i,[e]),o=new function(t){this.variableNames=["dy","maxPos"],this.outputShape=t.inShape;var e=t.strideDepth,n=t.strideHeight,r=t.strideWidth,i=t.dilationDepth,a=t.dilationHeight,o=t.dilationWidth,s=t.effectiveFilterDepth,u=t.effectiveFilterHeight,c=t.effectiveFilterWidth,l=s-1-t.padInfo.front,f=u-1-t.padInfo.top,d=c-1-t.padInfo.left,h=s*u*c-1;this.userCode="\n const ivec3 pads = ivec3("+l+", "+f+", "+d+");\n\n void main() {\n ivec5 coords = getOutputCoords();\n int batch = coords.x;\n int ch = coords.u;\n\n ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;\n int dyDCorner = dyCorner.x;\n int dyRCorner = dyCorner.y;\n int dyCCorner = dyCorner.z;\n\n // Convolve dy(?, ?, ?, ch) with pos mask(:, :, :, d) to get\n // dx(xD, xR, xC, ch).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n\n for (int wD = 0; wD < "+s+";\n wD += "+i+") {\n float dyD = float(dyDCorner + wD) / "+e+".0;\n\n if (dyD < 0.0 || dyD >= "+t.outDepth+".0 || fract(dyD) > 0.0) {\n continue;\n }\n int idyD = int(dyD);\n\n for (int wR = 0; wR < "+u+";\n wR += "+a+") {\n float dyR = float(dyRCorner + wR) / "+n+".0;\n\n if (dyR < 0.0 || dyR >= "+t.outHeight+".0 ||\n fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < "+c+";\n wC += "+o+") {\n float dyC = float(dyCCorner + wC) / "+r+".0;\n\n if (dyC < 0.0 || dyC >= "+t.outWidth+".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(batch, idyD, idyR, idyC, ch);\n int maxPosValue = "+h+" -\n int(getMaxPos(batch, idyD, idyR, idyC, ch));\n\n // Get the current value, check it against the value from the\n // position matrix.\n int curPosValue =\n wD * "+u+" * "+c+" +\n wR * "+c+" + wC;\n float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);\n\n dotProd += dyValue * mask;\n }\n }\n }\n setOutput(dotProd);\n }\n "}(r),s=this.compileAndRun(o,[t,a],e.dtype);return a.dispose(),s},e.prototype.reshape=function(t,e){var n=this.texData.get(t.dataId);if(n.isPacked&&!Pe(t.shape,e)&&(null===n.texture||!Pe(n.shape,e))){var r=this.packedReshape(t,e);return Wt.makeTensorFromDataId(r.dataId,r.shape,r.dtype)}return Aa(t,e)},e.prototype.resizeBilinear=function(t,e,n,r){var i=f().getBool("WEBGL_PACK_IMAGE_OPERATIONS")?new function(t,e,n,r){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[];var i=t[0],a=t[1],o=t[2],s=t[3];this.outputShape=[i,e,n,s];var u=[r&&e>1?a-1:a,r&&n>1?o-1:o],c=[r&&e>1?e-1:e,r&&n>1?n-1:n];this.userCode="\n const vec3 effectiveInputOverOutputRatioRC = vec3(\n "+u[0]/c[0]+",\n "+u[1]/c[1]+",\n "+u[1]/c[1]+");\n const vec3 inputShapeRC = vec3("+a+".0, "+o+".0,\n "+o+".0);\n\n float getAValue(int b, int r, int c, int d) {\n return getChannel(getA(b, r, c, d), vec2(c, d));\n }\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n // Calculate values for next column in yRC.z.\n ivec3 yRC = coords.yzz + ivec3(0, 0, 1);\n\n // Fractional source index.\n vec3 sourceFracIndexRC = vec3(yRC) * effectiveInputOverOutputRatioRC;\n\n // Compute the four integer indices.\n ivec3 sourceFloorRC = ivec3(sourceFracIndexRC);\n ivec3 sourceCeilRC = ivec3(\n min(inputShapeRC - 1.0, ceil(sourceFracIndexRC)));\n\n // Should we calculate next column and row elements in 2x2 packed cell.\n bool hasNextCol = d < "+(s-1)+";\n bool hasNextRow = coords.z < "+(n-1)+";\n\n // In parallel, construct four corners for all four components in\n // packed 2x2 cell.\n vec4 topLeft = vec4(\n getAValue(b, sourceFloorRC.x, sourceFloorRC.y, d),\n hasNextCol ? getAValue(b, sourceFloorRC.x, sourceFloorRC.y, d + 1)\n : 0.0,\n hasNextRow ? getAValue(b, sourceFloorRC.x, sourceFloorRC.z, d)\n : 0.0,\n (hasNextRow && hasNextCol) ?\n getAValue(b, sourceFloorRC.x, sourceFloorRC.z, d + 1) : 0.0);\n\n vec4 bottomLeft = vec4(\n getAValue(b, sourceCeilRC.x, sourceFloorRC.y, d),\n hasNextCol ? getAValue(b, sourceCeilRC.x, sourceFloorRC.y, d + 1)\n : 0.0,\n hasNextRow ? getAValue(b, sourceCeilRC.x, sourceFloorRC.z, d)\n : 0.0,\n (hasNextRow && hasNextCol) ?\n getAValue(b, sourceCeilRC.x, sourceFloorRC.z, d + 1) : 0.0);\n\n vec4 topRight = vec4(\n getAValue(b, sourceFloorRC.x, sourceCeilRC.y, d),\n hasNextCol ? getAValue(b, sourceFloorRC.x, sourceCeilRC.y, d + 1)\n : 0.0,\n hasNextRow ? getAValue(b, sourceFloorRC.x, sourceCeilRC.z, d)\n : 0.0,\n (hasNextRow && hasNextCol) ?\n getAValue(b, sourceFloorRC.x, sourceCeilRC.z, d + 1) : 0.0);\n\n vec4 bottomRight = vec4(\n getAValue(b, sourceCeilRC.x, sourceCeilRC.y, d),\n hasNextCol ? getAValue(b, sourceCeilRC.x, sourceCeilRC.y, d + 1)\n : 0.0,\n hasNextRow ? getAValue(b, sourceCeilRC.x, sourceCeilRC.z, d)\n : 0.0,\n (hasNextRow && hasNextCol) ?\n getAValue(b, sourceCeilRC.x, sourceCeilRC.z, d + 1) : 0.0);\n\n vec3 fracRC = sourceFracIndexRC - vec3(sourceFloorRC);\n\n vec4 top = mix(topLeft, topRight, fracRC.yyzz);\n vec4 bottom = mix(bottomLeft, bottomRight, fracRC.yyzz);\n vec4 newValue = mix(top, bottom, fracRC.x);\n\n setOutput(newValue);\n }\n "}(t.shape,e,n,r):new function(t,e,n,r){this.variableNames=["A"],this.outputShape=[];var i=t[0],a=t[1],o=t[2],s=t[3];this.outputShape=[i,e,n,s];var u=[r&&e>1?a-1:a,r&&n>1?o-1:o],c=[r&&e>1?e-1:e,r&&n>1?n-1:n];this.userCode="\n const vec2 effectiveInputOverOutputRatioRC = vec2(\n "+u[0]/c[0]+",\n "+u[1]/c[1]+");\n const vec2 inputShapeRC = vec2("+a+".0, "+o+".0);\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n ivec2 yRC = coords.yz;\n\n // Fractional source index.\n vec2 sourceFracIndexRC = vec2(yRC) * effectiveInputOverOutputRatioRC;\n\n // Compute the four integer indices.\n ivec2 sourceFloorRC = ivec2(sourceFracIndexRC);\n ivec2 sourceCeilRC = ivec2(\n min(inputShapeRC - 1.0, ceil(sourceFracIndexRC)));\n\n float topLeft = getA(b, sourceFloorRC.x, sourceFloorRC.y, d);\n float bottomLeft = getA(b, sourceCeilRC.x, sourceFloorRC.y, d);\n float topRight = getA(b, sourceFloorRC.x, sourceCeilRC.y, d);\n float bottomRight = getA(b, sourceCeilRC.x, sourceCeilRC.y, d);\n\n vec2 fracRC = sourceFracIndexRC - vec2(sourceFloorRC);\n\n float top = topLeft + (topRight - topLeft) * fracRC.y;\n float bottom = bottomLeft + (bottomRight - bottomLeft) * fracRC.y;\n float newValue = top + (bottom - top) * fracRC.x;\n\n setOutput(newValue);\n }\n "}(t.shape,e,n,r);return this.compileAndRun(i,[t],"float32")},e.prototype.resizeBilinearBackprop=function(t,e,n){var r=new function(t,e,n){this.variableNames=["dy"],this.outputShape=[],this.outputShape=e.shape;var r=e.shape,i=r[1],a=r[2],o=t.shape,s=o[1],u=o[2],c=[n&&s>1?i-1:i,n&&u>1?a-1:a],l=[n&&s>1?s-1:s,n&&u>1?u-1:u],f=c[0]/l[0],d=c[1]/l[1],h=1/f,p=1/d,m=2*Math.ceil(h)+2,g=2*Math.ceil(p)+2;this.userCode="\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n int r = coords[1];\n int c = coords[2];\n\n float accumulator = 0.0;\n\n const float heightScale = float("+f+");\n const float widthScale = float("+d+");\n\n const float invHeightScale = float("+h+");\n const float invWidthScale = float("+p+");\n\n const int winHeight = int("+m+");\n const int winWidth = int("+g+");\n\n // Compute bounds for where in dy we will look\n float startRLerp = floor(float(r) * invHeightScale);\n int startDyR = int(startRLerp - float(winHeight / 2));\n\n float startCLerp = floor(float(c) * invWidthScale);\n int startDyC = int(startCLerp - float(winWidth / 2));\n\n // Loop over dy\n for (int dyROffset = 0; dyROffset < winHeight; dyROffset++) {\n int dyR = dyROffset + startDyR;\n\n // Guard against the window exceeding the bounds of dy\n if (dyR < 0 || dyR >= "+s+") {\n continue;\n }\n\n for (int dyCOffset = 0; dyCOffset < winWidth; dyCOffset++) {\n int dyC = dyCOffset + startDyC;\n\n // Guard against the window exceeding the bounds of dy\n if (dyC < 0 || dyC >= "+u+") {\n continue;\n }\n\n float dxR = float(dyR) * heightScale;\n int topDxRIndex = int(floor(dxR));\n int bottomDxRIndex = int(min(ceil(dxR), "+(i-1)+".0));\n float dxRLerp = dxR - float(topDxRIndex);\n float inverseDxRLerp = 1.0 - dxRLerp;\n\n float dxC = float(dyC) * widthScale;\n int leftDxCIndex = int(floor(dxC));\n int rightDxCIndex = int(min(ceil(dxC), "+(a-1)+".0));\n float dxCLerp = dxC - float(leftDxCIndex);\n float inverseDxCLerp = 1.0 - dxCLerp;\n\n if (r == topDxRIndex && c == leftDxCIndex) {\n // topLeft\n accumulator +=\n getDy(b, dyR, dyC, d) * inverseDxRLerp * inverseDxCLerp;\n }\n\n if (r == topDxRIndex && c == rightDxCIndex) {\n // topRight\n accumulator += getDy(b, dyR, dyC, d) * inverseDxRLerp * dxCLerp;\n }\n\n if (r == bottomDxRIndex && c == leftDxCIndex) {\n // bottomLeft\n accumulator += getDy(b, dyR, dyC, d) * dxRLerp * inverseDxCLerp;\n }\n\n if (r == bottomDxRIndex && c == rightDxCIndex) {\n // bottomRight\n accumulator += getDy(b, dyR, dyC, d) * dxRLerp * dxCLerp;\n }\n }\n }\n // End loop over dy\n\n setOutput(accumulator);\n }\n "}(t,e,n);return this.compileAndRun(r,[t])},e.prototype.resizeNearestNeighbor=function(t,e,n,r){var i=new function(t,e,n,r){this.variableNames=["A"],this.outputShape=[];var i=t[0],a=t[1],o=t[2],s=t[3];this.outputShape=[i,e,n,s];var u=[r&&e>1?a-1:a,r&&n>1?o-1:o],c=[r&&e>1?e-1:e,r&&n>1?n-1:n],l=r?"0.5":"0.0";this.userCode="\n const vec2 effectiveInputOverOutputRatioRC = vec2(\n "+u[0]/c[0]+",\n "+u[1]/c[1]+");\n const vec2 inputShapeRC = vec2("+a+".0, "+o+".0);\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n ivec2 yRC = coords.yz;\n\n // Fractional source index.\n vec2 sourceFracIndexRC = vec2(yRC) * effectiveInputOverOutputRatioRC;\n\n // Compute the coordinators of nearest neighbor point.\n ivec2 sourceNearestRC = ivec2(\n min(inputShapeRC - 1.0, floor(sourceFracIndexRC + "+l+")));\n\n float newValue = getA(b, sourceNearestRC.x, sourceNearestRC.y, d);\n\n setOutput(newValue);\n }\n "}(t.shape,e,n,r);return this.compileAndRun(i,[t])},e.prototype.resizeNearestNeighborBackprop=function(t,e,n){var r=new function(t,e,n){this.variableNames=["dy"],this.outputShape=[],this.outputShape=e.shape;var r=e.shape,i=r[1],a=r[2],o=t.shape,s=o[1],u=o[2],c=[n&&s>1?i-1:i,n&&u>1?a-1:a],l=[n&&s>1?s-1:s,n&&u>1?u-1:u],f=c[0]/l[0],d=c[1]/l[1],h=1/f,p=1/d,m=2*Math.ceil(h)+2,g=2*Math.ceil(p)+2;this.userCode="\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n int r = coords[1];\n int c = coords[2];\n\n float accumulator = 0.0;\n\n const float heightScale = float("+f+");\n const float widthScale = float("+d+");\n\n const float invHeightScale = float("+h+");\n const float invWidthScale = float("+p+");\n\n const int winHeight = int("+m+");\n const int winWidth = int("+g+");\n\n // Compute bounds for where in dy we will look\n float startRLerp = floor(float(r) * invHeightScale);\n int startDyR = int(floor(startRLerp - float(winHeight / 2)));\n\n float startCLerp = floor(float(c) * invWidthScale);\n int startDyC = int(floor(startCLerp - float(winWidth / 2)));\n\n // Loop over dy\n for (int dyROffset = 0; dyROffset < winHeight; dyROffset++) {\n int dyR = dyROffset + startDyR;\n\n // Guard against the window exceeding the bounds of dy\n if (dyR < 0 || dyR >= "+s+") {\n continue;\n }\n\n for (int dyCOffset = 0; dyCOffset < winWidth; dyCOffset++) {\n int dyC = dyCOffset + startDyC;\n\n // Guard against the window exceeding the bounds of dy\n if (dyC < 0 || dyC >= "+u+") {\n continue;\n }\n\n float sourceFracRow =\n float("+c[0]+") *\n (float(dyR) / float("+l[0]+"));\n\n float sourceFracCol =\n float("+c[1]+") *\n (float(dyC) / float("+l[1]+"));\n\n int sourceNearestRow = int(min(\n float(int("+i+") - 1),\n "+n+" ? float(round(sourceFracRow)) :\n float(floor(sourceFracRow))));\n\n int sourceNearestCol = int(min(\n float(int("+a+") - 1),\n "+n+" ? float(round(sourceFracCol)) :\n float(floor(sourceFracCol))));\n\n if (r == sourceNearestRow && c == sourceNearestCol) {\n accumulator += getDy(b, dyR, dyC, d);\n }\n }\n }\n // End loop over dy\n\n setOutput(accumulator);\n }\n "}(t,e,n);return this.compileAndRun(r,[t])},e.prototype.multinomial=function(t,e,n,r){var i=e?t:ca(t),a=i.shape[0],o=i.shape[1],s=new Xo(a,o,n),u=s.getCustomSetupFunc(r);return this.compileAndRun(s,[i],"int32",u)},e.prototype.oneHot=function(t,e,n,r){var i=new function(t,e,n,r){this.variableNames=["indices"],this.outputShape=[t,e],this.userCode="\n void main() {\n ivec2 coords = getOutputCoords();\n int index = round(getIndices(coords.x));\n setOutput(mix(float("+r+"), float("+n+"),\n float(index == coords.y)));\n }\n "}(t.size,e,n,r);return this.compileAndRun(i,[t])},e.prototype.diag=function(t){var e=new function(t){this.variableNames=["X"],this.outputShape=[t,t],this.userCode="\n void main() {\n ivec2 coords = getOutputCoords();\n float val = coords[0] == coords[1] ? getX(coords[0]) : 0.0;\n setOutput(val);\n }\n "}(t.size);return this.compileAndRun(e,[t])},e.prototype.nonMaxSuppression=function(t,e,n,r,i){return vn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead"),Pa(t.dataSync(),e.dataSync(),n,r,i)},e.prototype.cropAndResize=function(t,e,n,r,i,a){var o=new function(t,e,n,r,i){this.variableNames=["Image","Boxes","BoxInd"],this.outputShape=[];var a=t[0],o=t[1],s=t[2],u=t[3],c=e[0],l=n[0],f=n[1];this.outputShape=[c,l,f,u];var d="bilinear"===r?1:0,h=[o-1+".0",s-1+".0"],p=h[0],m=h[1],g=l>1?[""+(o-1)/(l-1),"(y2-y1) * height_ratio","y1*"+p+" + float(y)*(height_scale)"]:["0.0","0.0","0.5 * (y1+y2) * "+p],v=g[0],y=g[1],b=g[2],x=f>1?[""+(s-1)/(f-1),"(x2-x1) * width_ratio","x1*"+m+" + float(x)*(width_scale)"]:["0.0","0.0","0.5 * (x1+x2) * "+m],w=x[0],k=x[1],_=x[2];this.userCode="\n const float height_ratio = float("+v+");\n const float width_ratio = float("+w+");\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int y = coords[1];\n int x = coords[2];\n int d = coords[3];\n\n // get box vals\n float y1 = getBoxes(b,0);\n float x1 = getBoxes(b,1);\n float y2 = getBoxes(b,2);\n float x2 = getBoxes(b,3);\n\n // get image in batch index\n int bInd = round(getBoxInd(b));\n if(bInd < 0 || bInd >= "+a+") {\n return;\n }\n\n float height_scale = "+y+";\n float width_scale = "+k+";\n\n float in_y = "+b+";\n if( in_y < 0.0 || in_y > "+p+" ) {\n setOutput(float("+i+"));\n return;\n }\n float in_x = "+_+";\n if( in_x < 0.0 || in_x > "+m+" ) {\n setOutput(float("+i+"));\n return;\n }\n\n vec2 sourceFracIndexCR = vec2(in_x,in_y);\n if("+d+" == 1) {\n // Compute the four integer indices.\n ivec2 sourceFloorCR = ivec2(sourceFracIndexCR);\n ivec2 sourceCeilCR = ivec2(ceil(sourceFracIndexCR));\n\n float topLeft = getImage(b, sourceFloorCR.y, sourceFloorCR.x, d);\n float bottomLeft = getImage(b, sourceCeilCR.y, sourceFloorCR.x, d);\n float topRight = getImage(b, sourceFloorCR.y, sourceCeilCR.x, d);\n float bottomRight = getImage(b, sourceCeilCR.y, sourceCeilCR.x, d);\n\n vec2 fracCR = sourceFracIndexCR - vec2(sourceFloorCR);\n\n float top = topLeft + (topRight - topLeft) * fracCR.x;\n float bottom = bottomLeft + (bottomRight - bottomLeft) * fracCR.x;\n float newValue = top + (bottom - top) * fracCR.y;\n setOutput(newValue);\n } else {\n // Compute the coordinators of nearest neighbor point.\n ivec2 sourceNearestCR = ivec2(floor(\n sourceFracIndexCR + vec2(0.5,0.5)));\n float newValue = getImage(b, sourceNearestCR.y, sourceNearestCR.x, d);\n setOutput(newValue);\n }\n }\n "}(t.shape,e.shape,r,i,a);return this.compileAndRun(o,[t,e,n],"float32")},e.prototype.depthToSpace=function(t,e,n){C(e>1,function(){return"blockSize should be > 1 for depthToSpace, but was: "+e});var r=t.shape[0],i="NHWC"===n?t.shape[1]:t.shape[2],a="NHWC"===n?t.shape[2]:t.shape[3],o="NHWC"===n?t.shape[3]:t.shape[1],s=i*e,u=a*e,c=o/(e*e),l=new Oo("NHWC"===n?[r,s,u,c]:[r,c,s,u],e,n);return this.compileAndRun(l,[t])},e.prototype.split=function(t,e,n){return Va(t,e,n)},e.prototype.scatterND=function(t,e,n){var r=Gi(0,t,n),i=r.sliceRank,a=r.numUpdates,o=r.sliceSize,s=r.strides,u=r.outputSize,c=[u/o,o],l=t.reshape([a,i]),f=e.reshape([a,o]);if(0===u)return Aa(jn([]),n);var d=Ln(0),h=new Zo(a,i,l.rank,f.rank,s,c);return this.compileAndRun(h,[f,l,d]).reshape(n)},e.prototype.sparseToDense=function(t,e,n,r){var i=Gi(0,t,n),a=i.sliceRank,o=i.numUpdates,s=i.strides,u=i.outputSize,c=new Zo(o,a,t.rank,e.rank,s,[u,1],!1);return this.compileAndRun(c,[e,t,r]).reshape(n)},e.prototype.fft=function(t){return this.fftImpl(t,!1)},e.prototype.ifft=function(t){return this.fftImpl(t,!0)},e.prototype.fftImpl=function(t,e){var n=this.texData.get(t.dataId),r=new So("return real * expR - imag * expI;",t.shape,e),i=new So("return real * expI + imag * expR;",t.shape,e),a=[this.makeComplexComponentTensorInfo(t,n.complexTensors.real),this.makeComplexComponentTensorInfo(t,n.complexTensors.imag)],o=this.compileAndRun(r,a),s=this.compileAndRun(i,a),u=this.complex(o,s).as2D(t.shape[0],t.shape[1]);return o.dispose(),s.dispose(),u},e.prototype.gatherND=function(t,e){var n=e.shape,r=n[n.length-1],i=Bi(t,e),a=i[0],o=i[1],s=i[2],u=i[3],c=e.reshape([o,r]),l=t.reshape([t.size/s,s]),f=new function(t,e,n){this.sliceDim=t,this.strides=e,this.variableNames=["x","indices"],this.outputShape=n;var r=oo(e.length),i=oo(n.length),a=this.sliceDim>1?"strides[j]":"strides";this.userCode="\n "+r+" strides = "+r+"("+this.strides+");\n void main() {\n "+i+" coords = getOutputCoords();\n int flattenIndex = 0;\n for (int j = 0; j < "+this.sliceDim+"; j++) {\n int index = round(getIndices(coords[0], j));\n flattenIndex += index * "+a+";\n }\n setOutput(getX(flattenIndex, coords[1]));\n }\n "}(r,u,[o,s]);return this.compileAndRun(f,[l,c]).reshape(a)},e.prototype.fill=function(t,e,n){if("string"===(n=n||Z(e))){var r=W(n,I(t));return r.fill(e),Wt.makeTensor(r,t,n,this)}var i=new Co(t,e),a=i.getCustomSetupFunc(e);return this.compileAndRun(i,[],n,a)},e.prototype.onesLike=function(t){if("string"===t.dtype)throw new Error("onesLike is not supported under string dtype");return this.fill(t.shape,1,t.dtype)},e.prototype.zerosLike=function(t){return this.fill(t.shape,"string"===t.dtype?"":0,t.dtype)},e.prototype.linspace=function(t,e,n){return Na(t,e,n)},e.prototype.makeTensorInfo=function(t,e){var n=this.write(null,t,e);return this.texData.get(n).usage=null,{dataId:n,shape:t,dtype:e}},e.prototype.makeOutput=function(t,e){var n=this.makeTensorInfo(t,e).dataId;return Wt.makeTensorFromDataId(n,t,e,this)},e.prototype.unpackTensor=function(t){var e=new function(t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outputShape=t;var e=t.length,n=Ka("rc",e),r=oo(e),i=function(t,e){if(1===t)return"rc";for(var n="",r=0;r<t;r++)n+=e[r],r<t-1&&(n+=",");return n}(e,n),a=n.slice(-2),o=e<=1?"rc":"vec2("+a.join(",")+")";this.userCode="\n void main() {\n "+r+" rc = getOutputCoords();\n vec4 packedInput = getA("+i+");\n\n setOutput(getChannel(packedInput, "+o+"));\n }\n "}(t.shape);return this.runWebGLProgram(e,[t],t.dtype)},e.prototype.packTensor=function(t){var e=new function(t){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0,this.outputShape=t;var e=t.length;if(0===e)this.userCode="\n void main() {\n setOutput(vec4(getA(), 0., 0., 0.));\n }\n ";else{var n=Ka("rc",e),r=oo(e),i=function(t,e,n){if(1===t)return"rc > "+e[0];for(var r="",i=t-2;i<t;i++)r+=n[i]+" >= "+e[i],i<t-1&&(r+="||");return r}(e,t,n),a=function(t,e,n,r){if(1===t)return"";var i=r.slice(-2);return"\n int r = "+i[0]+";\n int c = "+i[1]+";\n int rp1 = r + 1;\n int cp1 = c + 1;\n\n bool cEdge = cp1 >= "+e+";\n bool rEdge = rp1 >= "+n+";\n "}(e,t[t.length-1],t[t.length-2],n),o=function(t,e){var n=t.length,r=function(t,e){for(var n=[],r=0;r<=1;r++)for(var i=0;i<=1;i++){for(var a=(0===r?"r":"rp1")+", "+(0===i?"c":"cp1"),o=2;o<t;o++)a=e[e.length-1-o]+","+a;n.push(a)}return n}(n,e);return 1===n?"getA(rc),\n rc + 1 >= "+t[0]+" ? 0. : getA(rc + 1),\n 0, 0":"getA("+r[0]+"),\n cEdge ? 0. : getA("+r[1]+"),\n rEdge ? 0. : getA("+r[2]+"),\n rEdge || cEdge ? 0. : getA("+r[3]+")"}(t,n);this.userCode="\n void main() {\n "+r+" rc = getOutputCoords();\n\n if("+i+") {\n setOutput(vec4(0));\n } else {\n "+a+"\n\n setOutput(vec4("+o+"));\n }\n }\n "}}(t.shape);return this.runWebGLProgram(e,[t],t.dtype,null,!0)},e.prototype.packedReshape=function(t,e){var n=[De(t.shape)].concat(Me(t.shape)),r={dtype:t.dtype,shape:n,dataId:t.dataId},i=new function(t,e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t;for(var n="",r=0;r<4;r++){var i="thisRC = rc;";r%2==1&&(i+="thisRC.z += 1;"),r>1&&(i+="thisRC.y += 1;"),n+="\n "+i+"\n "+(r>0?"if(thisRC.y < rows && thisRC.z < cols){":"")+"\n int flatIndex = getFlatIndex(thisRC);\n\n ivec3 inputRC = inputCoordsFromReshapedOutCoords(flatIndex);\n vec2 inputRCInnerDims = vec2(float(inputRC.y),float(inputRC.z));\n\n result["+r+"] =\n getChannel(getA(inputRC.x, inputRC.y, inputRC.z), inputRCInnerDims);\n "+(r>0?"}":"")+"\n "}this.userCode="\n \n ivec3 inputCoordsFromReshapedOutCoords(int index) {\n "+Ya(["r","c","d"],e)+"\n return ivec3(r, c, d);\n }\n \n "+Ja(t)+"\n\n void main() {\n ivec3 rc = getOutputCoords();\n\n vec4 result = vec4(0.);\n\n ivec3 thisRC;\n int rows = "+t[1]+";\n int cols = "+t[2]+";\n\n "+n+"\n\n setOutput(result);\n }\n "}([De(e)].concat(Me(e)),n),a=this.runWebGLProgram(i,[r],t.dtype,null,!0);return{dataId:a.dataId,shape:e,dtype:a.dtype}},e.prototype.decode=function(t){var e,n=this.texData.get(t),r=n.isPacked,i=n.shape,a=n.dtype,o=Re(i);return e=r?new function(t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outPackingScheme=Ht.DENSE;var e=Qt(t),n=Xa();this.outputShape=t,this.userCode="\n ivec3 outCoordsFromFlatIndex(int index) {\n "+Ya(["r","c","d"],t)+"\n return ivec3(r, c, d);\n }\n\n void main() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+e[0]+", "+e[1]+"));\n int index = 4 * (resTexRC.x * "+e[1]+" + resTexRC.y);\n\n vec4 result = vec4(0.);\n\n for (int i=0; i<4; i++) {\n int flatIndex = index + i;\n ivec3 rc = outCoordsFromFlatIndex(flatIndex);\n result[i] = getChannel(getA(rc.x, rc.y, rc.z), vec2(rc.y, rc.z));\n }\n\n "+n.output+" = result;\n }\n "}(o):new function(t){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0,this.outPackingScheme=Ht.DENSE;var e=Qt(t),n=Xa();this.outputShape=t,this.userCode="\n ivec3 outCoordsFromFlatIndex(int index) {\n "+Ya(["r","c","d"],t)+"\n return ivec3(r, c, d);\n }\n\n void main() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+e[0]+", "+e[1]+"));\n int index = 4 * (resTexRC.x * "+e[1]+" + resTexRC.y);\n\n vec4 result = vec4(0.);\n\n for (int i=0; i<4; i++) {\n int flatIndex = index + i;\n ivec3 rc = outCoordsFromFlatIndex(flatIndex);\n result[i] = getA(rc.x, rc.y, rc.z);\n }\n\n "+n.output+" = result;\n }\n "}(o),{dtype:a,shape:i,dataId:this.runWebGLProgram(e,[{shape:o,dtype:a,dataId:t}],a,null,!0).dataId}},e.prototype.runWebGLProgram=function(t,e,n,r,i){var a=this;void 0===i&&(i=!1);var o=this.makeTensorInfo(t.outputShape,n),s=this.texData.get(o.dataId);if(t.packedOutput&&(s.isPacked=!0),t.outPackingScheme===Ht.DENSE){var u=Qt(t.outputShape);s.texShape=u.map(function(t){return 2*t})}if(null!=t.outTexUsage&&(s.usage=t.outTexUsage),0===I(o.shape))return s.values=U(o.dtype,0),o;var c=[],l=e.map(function(e){if("complex64"===e.dtype)throw new Error("GPGPUProgram does not support complex64 input. For complex64 dtypes, please separate the program into real and imaginary parts.");var n=a.texData.get(e.dataId);if(null==n.texture){if(!t.packedInputs&&I(e.shape)<=f().getNumber("WEBGL_SIZE_UPLOAD_UNIFORM"))return{shape:e.shape,texData:null,isUniform:!0,uniformValues:n.values};t.packedInputs&&(n.isPacked=!0,n.shape=e.shape)}else if(!!n.isPacked!=!!t.packedInputs)e=n.isPacked?a.unpackTensor(e):a.packTensor(e),c.push(e),n=a.texData.get(e.dataId);else if(n.isPacked&&!Pe(n.shape,e.shape)){var r=e,i=e.shape;e.shape=n.shape,e=a.packedReshape(e,i),c.push(e),n=a.texData.get(e.dataId),r.shape=i}return a.uploadToGPU(e.dataId),{shape:e.shape,texData:n,isUniform:!1}});this.uploadToGPU(o.dataId);var d,h={shape:o.shape,texData:s,isUniform:!1},p=function(t,e,n){var r="";l.concat(n).forEach(function(t){var e=null!=t.texData&&null!=t.texData.slice&&t.texData.slice.flatOffset>0,n=t.isUniform?"uniform":t.texData.texShape;r+=t.shape+"_"+n+"_"+e});var i=t.userCode;return t.constructor.name+"_"+r+"_"+i}(t,0,h),m=this.getAndSaveBinary(p,function(){return function(t,e,n,r){var i=e.userCode,a=n.map(function(t,n){var r={logicalShape:t.shape,texShape:t.isUniform?null:t.texData.texShape,isUniform:t.isUniform,isPacked:!t.isUniform&&t.texData.isPacked,flatOffset:null};return null!=t.texData&&null!=t.texData.slice&&t.texData.slice.flatOffset>0&&(r.flatOffset=t.texData.slice.flatOffset),{name:e.variableNames[n],shapeInfo:r}}),o=a.map(function(t){return t.shapeInfo}),s={logicalShape:r.shape,texShape:r.texData.texShape,isUniform:!1,isPacked:r.texData.isPacked,flatOffset:null},u=Qa(a,s,i,e.packedInputs),c=t.createProgram(u),l=null,d=t.getUniformLocation(c,"NAN",!1);1===f().getNumber("WEBGL_VERSION")&&(l=t.getUniformLocation(c,"INFINITY",!1));for(var h={},p=0;p<e.variableNames.length;p++){var m=e.variableNames[p];h[m]=t.getUniformLocation(c,m,!1),h["offset"+m]=t.getUniformLocation(c,"offset"+m,!1)}return{program:e,source:u,webGLProgram:c,uniformLocations:h,inShapeInfos:o,outShapeInfo:s,infLoc:l,nanLoc:d}}(a.gpgpu,t,l,h)}),g=null!=this.activeTimers;if(g&&(d=this.startTimer()),function(t,e,n,r,i){$o(e.inShapeInfos,n),$o([e.outShapeInfo],[r]);var a=r.texData.texture,o=r.texData.texShape;r.texData.isPacked?t.setOutputPackedMatrixTexture(a,o[0],o[1]):t.setOutputMatrixTexture(a,o[0],o[1]),t.setProgram(e.webGLProgram),1===f().getNumber("WEBGL_VERSION")&&null!==e.infLoc&&t.gl.uniform1f(e.infLoc,1/0),null!==e.nanLoc&&t.gl.uniform1f(e.nanLoc,NaN),n.forEach(function(n,r){var i=e.program.variableNames[r],a=e.uniformLocations[i],o=e.uniformLocations["offset"+i];if(null!=a)if(n.isUniform)if(I(n.shape)<2)t.gl.uniform1f(a,n.uniformValues[0]);else{var s=n.uniformValues;s instanceof Float32Array||(s=new Float32Array(s)),t.gl.uniform1fv(a,s)}else null!=n.texData.slice&&null!=o&&t.gl.uniform1i(o,n.texData.slice.flatOffset),t.setInputMatrixTexture(n.texData.texture,a,r)}),null!=i&&i(t,e.webGLProgram),t.executeProgram()}(this.gpgpu,m,l,h,r),c.forEach(function(t){return a.disposeData(t.dataId)}),g&&(d=this.endTimer(d),this.activeTimers.push({name:t.constructor.name,query:this.getQueryTime(d)})),!f().getBool("WEBGL_LAZILY_UNPACK")&&s.isPacked&&!1===i){var v=this.unpackTensor(o);return this.disposeData(o.dataId),v}return o},e.prototype.compileAndRun=function(t,e,n,r,i){void 0===i&&(i=!1),n=n||e[0].dtype;var a=this.runWebGLProgram(t,e,n,r,i);return Wt.makeTensorFromDataId(a.dataId,a.shape,a.dtype)},e.prototype.getAndSaveBinary=function(t,e){return t in this.binaryCache||(this.binaryCache[t]=e()),this.binaryCache[t]},e.prototype.getTextureManager=function(){return this.textureManager},e.prototype.dispose=function(){var t=this;this.disposed||(f().getBool("IS_TEST")||Object.keys(this.binaryCache).forEach(function(e){t.gpgpu.deleteProgram(t.binaryCache[e].webGLProgram),delete t.binaryCache[e]}),this.textureManager.dispose(),null!=this.canvas&&"undefined"!=typeof HTMLCanvasElement&&this.canvas instanceof HTMLCanvasElement?this.canvas.remove():this.canvas=null,this.gpgpuCreatedLocally&&(this.gpgpu.program=null,this.gpgpu.dispose()),this.disposed=!0)},e.prototype.floatPrecision=function(){var t=this;return null==this.floatPrecisionValue&&(this.floatPrecisionValue=rn(function(){if(!f().get("WEBGL_RENDER_FLOAT32_ENABLED")){var e=f().getBool("DEBUG");f().set("DEBUG",!1);var n=t.abs(Ln(1e-8)).dataSync()[0];if(f().set("DEBUG",e),n>0)return 32}return 16})),this.floatPrecisionValue},e.prototype.epsilon=function(){return 32===this.floatPrecision()?1e-7:1e-4},e.prototype.uploadToGPU=function(t){var e,n=this.texData.get(t),r=n.shape,i=n.dtype,a=n.values,o=n.texture,s=n.usage,u=n.isPacked;if(null==o){var c,l=null!=this.activeTimers;l&&(c=ot());var f=n.texShape;if(null==f&&(f=Fe(r,u),n.texShape=f),null!=a){var d=Re(r),h=void 0,p=f[1],m=f[0],g=a instanceof Uint8Array;u?(p=(e=te(f[0],f[1]))[0],h=new function(t,e,n){void 0===n&&(n=!1),this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0;var r=Xa(),i=e[0],a=e[1];this.outputShape=t;var o="",s="result";n&&(s="floor(result * 255. + 0.5)");for(var u=0;u<=1;u++)for(var c=0;c<=1;c++){var l=2*u+c;o+="\n localCoords = coords;\n if(localCoords[2] + "+c+" < "+t[2]+") {\n localCoords[2] += "+c+";\n if(localCoords[1] + "+u+" < "+t[1]+") {\n localCoords[1] += "+u+";\n\n flatIndex = getFlatIndex(localCoords);\n offset = imod(flatIndex, 4);\n\n flatIndex = idiv(flatIndex, 4, 1.);\n\n r = flatIndex / "+a+";\n c = imod(flatIndex, "+a+");\n uv = (vec2(c, r) + halfCR) / vec2("+a+".0, "+i+".0);\n values = "+r.texture2D+"(A, uv);\n\n if(offset == 0) {\n result["+l+"] = values[0];\n } else if(offset == 1) {\n result["+l+"] = values[1];\n } else if(offset == 2) {\n result["+l+"] = values[2];\n } else {\n result["+l+"] = values[3];\n }\n }\n }\n "}this.userCode="\n "+Ja(t)+"\n\n void main() {\n ivec3 coords = getOutputCoords();\n\n vec4 result = vec4(0.);\n int flatIndex, r, c, offset;\n ivec3 localCoords;\n vec2 uv;\n vec4 values;\n\n "+o+"\n\n "+r.output+" = "+s+";\n }\n "}(d,[m=e[1],p],g)):h=new function(t,e,n){void 0===n&&(n=!1),this.variableNames=["A"];var r=Xa(),i=e[0],a=e[1];this.outputShape=t;var o="result";n&&(o="floor(result * 255. + 0.5)"),this.userCode="\n "+Ja(t)+"\n\n void main() {\n ivec3 coords = getOutputCoords();\n\n int flatIndex = getFlatIndex(coords);\n int offset = imod(flatIndex, 4);\n\n flatIndex = idiv(flatIndex, 4, 1.);\n \n int r = flatIndex / "+a+";\n int c = imod(flatIndex, "+a+");\n vec2 uv = (vec2(c, r) + halfCR) / vec2("+a+".0, "+i+".0);\n vec4 values = "+r.texture2D+"(A, uv);\n\n float result;\n\n if(offset == 0) {\n result = values[0];\n } else if(offset == 1) {\n result = values[1];\n } else if(offset == 2) {\n result = values[2];\n } else {\n result = values[3];\n }\n\n "+r.output+" = vec4("+o+", 0., 0., 0.);\n }\n "}(d,[m,p],g);var v=this.makeTensorInfo([m,p],i);this.texData.get(v.dataId).usage=g?Gt.PIXELS:Gt.UPLOAD,this.gpgpu.uploadDenseMatrixToTexture(this.getTexture(v.dataId),p,m,a);var y=this.runWebGLProgram(h,[v],i,null,!0),b=this.texData.get(y.dataId);n.texture=b.texture,n.texShape=b.texShape,n.isPacked=b.isPacked,n.usage=b.usage,this.disposeData(v.dataId),this.texData.delete(y.dataId),n.values=null,l&&(this.uploadWaitMs+=ot()-c)}else{var x=this.acquireTexture(f,s,i,u);n.texture=x}}},e.prototype.convertAndCacheOnCPU=function(t,e){var n=this.texData.get(t),r=n.dtype;return this.releaseGPUData(t),null!=e&&(n.values=function(t,e){if("float32"===e||"complex64"===e)return t;if("int32"===e||"bool"===e){for(var n="int32"===e?new Int32Array(t.length):new Uint8Array(t.length),r=0;r<n.length;++r)n[r]=Math.round(t[r]);return n}throw new Error("Unknown dtype "+e)}(e,r)),n.values},e.prototype.acquireTexture=function(t,e,n,r){if(this.numBytesInGPU+=this.computeBytes(t,n),!this.warnedAboutMemory&&this.numBytesInGPU>1024*this.numMBBeforeWarning*1024){var i=(this.numBytesInGPU/1024/1024).toFixed(2);this.warnedAboutMemory=!0,console.warn("High memory usage in GPU: "+i+" MB, most likely due to a memory leak")}return this.textureManager.acquireTexture(t,e,r)},e.prototype.computeBytes=function(t,e){return t[0]*t[1]*$(e)},e}(ha);function Ns(t,e){return t(e={exports:{}},e.exports),e.exports}Vt()&&Wt.registerBackend("webgl",function(){return new As},2),"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:void 0!==t||"undefined"!=typeof self&&self;var Ts=Ns(function(t){!function(t,e,n){function r(t,e){return e.c=t.c,e.s0=t.s0,e.s1=t.s1,e.s2=t.s2,e}function i(t,e){var n=new function(t){var e,n=this,r=(e=4022871197,function(t){t=t.toString();for(var n=0;n<t.length;n++){var r=.02519603282416938*(e+=t.charCodeAt(n));r-=e=r>>>0,e=(r*=e)>>>0,e+=4294967296*(r-=e)}return 2.3283064365386963e-10*(e>>>0)});n.next=function(){var t=2091639*n.s0+2.3283064365386963e-10*n.c;return n.s0=n.s1,n.s1=n.s2,n.s2=t-(n.c=0|t)},n.c=1,n.s0=r(" "),n.s1=r(" "),n.s2=r(" "),n.s0-=r(t),n.s0<0&&(n.s0+=1),n.s1-=r(t),n.s1<0&&(n.s1+=1),n.s2-=r(t),n.s2<0&&(n.s2+=1),r=null}(t),i=e&&e.state,a=n.next;return a.int32=function(){return 4294967296*n.next()|0},a.double=function(){return a()+1.1102230246251565e-16*(2097152*a()|0)},a.quick=a,i&&("object"==typeof i&&r(i,n),a.state=function(){return r(n,{})}),a}e&&e.exports?e.exports=i:this.alea=i}(0,t)}),Is=Ns(function(t){!function(t,e,n){function r(t,e){return e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w,e}function i(t,e){var n=new function(t){var e=this,n="";e.x=0,e.y=0,e.z=0,e.w=0,e.next=function(){var t=e.x^e.x<<11;return e.x=e.y,e.y=e.z,e.z=e.w,e.w^=e.w>>>19^t^t>>>8},t===(0|t)?e.x=t:n+=t;for(var r=0;r<n.length+64;r++)e.x^=0|n.charCodeAt(r),e.next()}(t),i=e&&e.state,a=function(){return(n.next()>>>0)/4294967296};return a.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},a.int32=n.next,a.quick=a,i&&("object"==typeof i&&r(i,n),a.state=function(){return r(n,{})}),a}e&&e.exports?e.exports=i:this.xor128=i}(0,t)}),Ds=Ns(function(t){!function(t,e,n){function r(t,e){return e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w,e.v=t.v,e.d=t.d,e}function i(t,e){var n=new function(t){var e=this,n="";e.next=function(){var t=e.x^e.x>>>2;return e.x=e.y,e.y=e.z,e.z=e.w,e.w=e.v,(e.d=e.d+362437|0)+(e.v=e.v^e.v<<4^t^t<<1)|0},e.x=0,e.y=0,e.z=0,e.w=0,e.v=0,t===(0|t)?e.x=t:n+=t;for(var r=0;r<n.length+64;r++)e.x^=0|n.charCodeAt(r),r==n.length&&(e.d=e.x<<10^e.x>>>4),e.next()}(t),i=e&&e.state,a=function(){return(n.next()>>>0)/4294967296};return a.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},a.int32=n.next,a.quick=a,i&&("object"==typeof i&&r(i,n),a.state=function(){return r(n,{})}),a}e&&e.exports?e.exports=i:this.xorwow=i}(0,t)}),Ms=Ns(function(t){!function(t,e,n){function r(t,e){return e.x=t.x.slice(),e.i=t.i,e}function i(t,e){null==t&&(t=+new Date);var n=new function(t){var e=this;e.next=function(){var t,n,r=e.x,i=e.i;return t=r[i],n=(t^=t>>>7)^t<<24,n^=(t=r[i+1&7])^t>>>10,n^=(t=r[i+3&7])^t>>>3,n^=(t=r[i+4&7])^t<<7,t=r[i+7&7],n^=(t^=t<<13)^t<<9,r[i]=n,e.i=i+1&7,n},function(t,e){var n,r=[];if(e===(0|e))r[0]=e;else for(e=""+e,n=0;n<e.length;++n)r[7&n]=r[7&n]<<15^e.charCodeAt(n)+r[n+1&7]<<13;for(;r.length<8;)r.push(0);for(n=0;n<8&&0===r[n];++n);for(8==n?r[7]=-1:r[n],t.x=r,t.i=0,n=256;n>0;--n)t.next()}(e,t)}(t),i=e&&e.state,a=function(){return(n.next()>>>0)/4294967296};return a.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},a.int32=n.next,a.quick=a,i&&(i.x&&r(i,n),a.state=function(){return r(n,{})}),a}e&&e.exports?e.exports=i:this.xorshift7=i}(0,t)}),Rs=Ns(function(t){!function(t,e,n){function r(t,e){return e.i=t.i,e.w=t.w,e.X=t.X.slice(),e}function i(t,e){null==t&&(t=+new Date);var n=new function(t){var e=this;e.next=function(){var t,n,r=e.w,i=e.X,a=e.i;return e.w=r=r+1640531527|0,n=i[a+34&127],t=i[a=a+1&127],n^=n<<13,t^=t<<17,n^=n>>>15,t^=t>>>12,n=i[a]=n^t,e.i=a,n+(r^r>>>16)|0},function(t,e){var n,r,i,a,o,s=[],u=128;for(e===(0|e)?(r=e,e=null):(e+="\0",r=0,u=Math.max(u,e.length)),i=0,a=-32;a<u;++a)e&&(r^=e.charCodeAt((a+32)%e.length)),0===a&&(o=r),r^=r<<10,r^=r>>>15,r^=r<<4,r^=r>>>13,a>=0&&(o=o+1640531527|0,i=0==(n=s[127&a]^=r+o)?i+1:0);for(i>=128&&(s[127&(e&&e.length||0)]=-1),i=127,a=512;a>0;--a)r=s[i+34&127],n=s[i=i+1&127],r^=r<<13,n^=n<<17,r^=r>>>15,n^=n>>>12,s[i]=r^n;t.w=o,t.X=s,t.i=i}(e,t)}(t),i=e&&e.state,a=function(){return(n.next()>>>0)/4294967296};return a.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},a.int32=n.next,a.quick=a,i&&(i.X&&r(i,n),a.state=function(){return r(n,{})}),a}e&&e.exports?e.exports=i:this.xor4096=i}(0,t)}),Fs=Ns(function(t){!function(t,e,n){function r(t,e){return e.a=t.a,e.b=t.b,e.c=t.c,e.d=t.d,e}function i(t,e){var n=new function(t){var e=this,n="";e.next=function(){var t=e.b,n=e.c,r=e.d,i=e.a;return t=t<<25^t>>>7^n,n=n-r|0,r=r<<24^r>>>8^i,i=i-t|0,e.b=t=t<<20^t>>>12^n,e.c=n=n-r|0,e.d=r<<16^n>>>16^i,e.a=i-t|0},e.a=0,e.b=0,e.c=-1640531527,e.d=1367130551,t===Math.floor(t)?(e.a=t/4294967296|0,e.b=0|t):n+=t;for(var r=0;r<n.length+20;r++)e.b^=0|n.charCodeAt(r),e.next()}(t),i=e&&e.state,a=function(){return(n.next()>>>0)/4294967296};return a.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},a.int32=n.next,a.quick=a,i&&("object"==typeof i&&r(i,n),a.state=function(){return r(n,{})}),a}e&&e.exports?e.exports=i:this.tychei=i}(0,t)}),js=Ns(function(t){!function(e,r){var i,a=this,o=256,s=6,u="random",c=r.pow(o,s),l=r.pow(2,52),f=2*l,d=o-1;function h(t,n,d){var h=[],y=g(function t(e,n){var r,i=[],a=typeof e;if(n&&"object"==a)for(r in e)try{i.push(t(e[r],n-1))}catch(t){}return i.length?i:"string"==a?e:e+"\0"}((n=1==n?{entropy:!0}:n||{}).entropy?[t,v(e)]:null==t?function(){try{var t;return i&&(t=i.randomBytes)?t=t(o):(t=new Uint8Array(o),(a.crypto||a.msCrypto).getRandomValues(t)),v(t)}catch(t){var n=a.navigator,r=n&&n.plugins;return[+new Date,a,r,a.screen,v(e)]}}():t,3),h),b=new p(h),x=function(){for(var t=b.g(s),e=c,n=0;t<l;)t=(t+n)*o,e*=o,n=b.g(1);for(;t>=f;)t/=2,e/=2,n>>>=1;return(t+n)/e};return x.int32=function(){return 0|b.g(4)},x.quick=function(){return b.g(4)/4294967296},x.double=x,g(v(b.S),e),(n.pass||d||function(t,e,n,i){return i&&(i.S&&m(i,b),t.state=function(){return m(b,{})}),n?(r[u]=t,e):t})(x,y,"global"in n?n.global:this==r,n.state)}function p(t){var e,n=t.length,r=this,i=0,a=r.i=r.j=0,s=r.S=[];for(n||(t=[n++]);i<o;)s[i]=i++;for(i=0;i<o;i++)s[i]=s[a=d&a+t[i%n]+(e=s[i])],s[a]=e;(r.g=function(t){for(var e,n=0,i=r.i,a=r.j,s=r.S;t--;)e=s[i=d&i+1],n=n*o+s[d&(s[i]=s[a=d&a+e])+(s[a]=e)];return r.i=i,r.j=a,n})(o)}function m(t,e){return e.i=t.i,e.j=t.j,e.S=t.S.slice(),e}function g(t,e){for(var n,r=t+"",i=0;i<r.length;)e[d&i]=d&(n^=19*e[d&i])+r.charCodeAt(i++);return v(e)}function v(t){return String.fromCharCode.apply(0,t)}if(r["seed"+u]=h,g(r.random(),e),t.exports){t.exports=h;try{i=n(480)}catch(t){}}}([],Math)});js.alea=Ts,js.xor128=Is,js.xorwow=Ds,js.xorshift7=Ms,js.xor4096=Rs,js.tychei=Fs;var Ps=js.alea,Ls=Dn({addN_:function(t){C(Array.isArray(t),function(){return"The argument passed to tf.addN() must be a list of tensors"}),C(t.length>=1,function(){return"Must pass at least one tensor to tf.addN(), but got "+t.length});var e=t.map(function(t,e){return xn(t,"tensors"+e,"addN")}),n=e[0];e.forEach(function(t){if(t.dtype!==n.dtype)throw new Error("All tensors passed to tf.addN() must have the same dtype")}),e.forEach(function(t){if(!D(t.shape,n.shape))throw new Error("All tensors passed to tf.addN() must have the same shape")});var r=e;return Wt.runKernelFunc(function(t,n){return t.addN(e)},r,null,"AddN")}});function zs(){Ze("tf.batchNormalization() is going away. Use tf.batchNorm() instead, and note the positional argument change of scale, offset, and varianceEpsilon")}function Bs(t){return 0===t.rank||1===t.rank?t.as4D(1,1,1,t.size):2===t.rank?t.as4D(1,1,t.shape[0],t.shape[1]):3===t.rank?t.as4D(1,t.shape[0],t.shape[1],t.shape[2]):t}function Us(t,e,n,r,i,a){null==a&&(a=.001);var o,s,u=xn(t,"x","batchNorm"),c=xn(e,"mean","batchNorm"),l=xn(n,"variance","batchNorm");null!=i&&(o=xn(i,"scale","batchNorm")),null!=r&&(s=xn(r,"offset","batchNorm")),C(c.rank===l.rank,function(){return"Batch normalization gradient requires mean and variance to have equal ranks."}),C(null==s||c.rank===s.rank,function(){return"Batch normalization gradient requires mean and offset to have equal ranks."}),C(null==o||c.rank===o.rank,function(){return"Batch normalization gradient requires mean and scale to have equal ranks."});var f={x:u,scale:o,offset:s,mean:c,variance:l},d={varianceEpsilon:a};return Wt.runKernelFunc(function(t,e){var n=Bs(u),r=t.batchNormalization(n,Ws(c),Ws(l),a,Ws(o),Ws(s));return e([u,c,l,o]),r},f,null,"FusedBatchNorm",d).reshape(u.shape)}function Ws(t){return null==t?null:0===t.rank?t.as1D():1===t.rank?t:2===t.rank?t.as4D(1,1,t.shape[0],t.shape[1]):3===t.rank?t.as4D(1,t.shape[0],t.shape[1],t.shape[2]):t}var Vs=Dn({batchNormalization_:function(t,e,n,r,i,a){return void 0===r&&(r=.001),zs(),Us(t,e,n,a,i,r)}}),qs=Dn({batchNorm_:Us});function Hs(t,e,n,r,i,a){var o,s,u=xn(t,"x","batchNorm"),c=xn(e,"mean","batchNorm"),l=xn(n,"variance","batchNorm");return null!=i&&(o=xn(i,"scale","batchNorm")),null!=r&&(s=xn(r,"offset","batchNorm")),C(2===u.rank,function(){return"Error in batchNorm3D: x must be rank 3 but got rank "+u.rank+"."}),C(2===c.rank||1===c.rank,function(){return"Error in batchNorm2D: mean must be rank 2 or rank 1 but got rank "+c.rank+"."}),C(2===l.rank||1===l.rank,function(){return"Error in batchNorm2D: variance must be rank 2 or rank 1 but got rank "+l.rank+"."}),null!=o&&C(2===o.rank||1===o.rank,function(){return"Error in batchNorm2D: scale must be rank 2 or rank 1 but got rank "+o.rank+"."}),null!=s&&C(2===s.rank||1===s.rank,function(){return"Error in batchNorm2D: offset must be rank 2 or rank 1 but got rank "+s.rank+"."}),qs(u,c,l,s,o,a)}var Gs=Dn({batchNormalization2d_:function(t,e,n,r,i,a){return void 0===r&&(r=.001),zs(),Hs(t,e,n,a,i,r)}}),$s=Dn({batchNorm2d_:Hs});function Ks(t,e,n,r,i,a){var o,s,u=xn(t,"x","batchNorm"),c=xn(e,"mean","batchNorm"),l=xn(n,"variance","batchNorm");return null!=i&&(o=xn(i,"scale","batchNorm")),null!=r&&(s=xn(r,"offset","batchNorm")),C(3===u.rank,function(){return"Error in batchNorm3D: x must be rank 3 but got rank "+u.rank+"."}),C(3===c.rank||1===c.rank,function(){return"Error in batchNorm3D: mean must be rank 3 or rank 1 but got rank "+c.rank+"."}),C(3===l.rank||1===l.rank,function(){return"Error in batchNorm3D: variance must be rank 3 or rank 1 but got rank "+l.rank+"."}),null!=o&&C(3===o.rank||1===o.rank,function(){return"Error in batchNorm3D: scale must be rank 3 or rank 1 but got rank "+o.rank+"."}),null!=s&&C(3===s.rank||1===s.rank,function(){return"Error in batchNorm3D: offset must be rank 3 or rank 1 but got rank "+s.rank+"."}),qs(u,c,l,s,o,a)}var Xs=Dn({batchNormalization3d_:function(t,e,n,r,i,a){return void 0===r&&(r=.001),zs(),Ks(t,e,n,a,i,r)}}),Ys=Dn({batchNorm3d_:Ks});function Js(t,e,n,r,i,a){var o,s,u=xn(t,"x","batchNorm"),c=xn(e,"mean","batchNorm"),l=xn(n,"variance","batchNorm");return null!=i&&(o=xn(i,"scale","batchNorm")),null!=r&&(s=xn(r,"offset","batchNorm")),C(4===u.rank,function(){return"Error in batchNorm4D: x must be rank 4 but got rank "+u.rank+"."}),C(4===c.rank||1===c.rank,function(){return"Error in batchNorm4D: mean must be rank 4 or rank 1 but got rank "+c.rank+"."}),C(4===l.rank||1===l.rank,function(){return"Error in batchNorm4D: variance must be rank 4 or rank 1 but got rank "+l.rank+"."}),null!=o&&C(4===o.rank||1===o.rank,function(){return"Error in batchNorm4D: scale must be rank 4 or rank 1 but got rank "+o.rank+"."}),null!=s&&C(4===s.rank||1===s.rank,function(){return"Error in batchNorm4D: offset must be rank 4 or rank 1 but got rank "+s.rank+"."}),qs(u,c,l,s,o,a)}var Zs=Dn({batchNormalization4d_:function(t,e,n,r,i,a){return void 0===r&&(r=.001),zs(),Js(t,e,n,a,i,r)}}),Qs=Dn({batchNorm4d_:Js}),tu=Dn({broadcastTo_:function(t,e){var n=xn(t,"broadcastTo","x"),r=n.shape;if(e.some(function(t){return!(t>0)||t%1!=0}))throw new Error("broadcastTo(): Invalid broadcast shape ["+e+"].");if(e.length<n.rank)throw new Error("broadcastTo(): shape.length="+e.length+" < input.rank="+n.rank+".");if(e.length>n.rank){for(var i=n.shape.slice();i.length<e.length;)i.unshift(1);n=n.reshape(i)}for(var a=n.shape,o=Array.from(e),s=e.length-1;s>=0;s--)if(a[s]===e[s])o[s]=1;else if(1!==n.shape[s])throw new Error("broadcastTo(): ["+r+"] cannot be broadcast to ["+e+"].");var u=o.map(function(t,e){return t>1?e:-1}).filter(function(t){return t>=0});if(0===u.length)return n.clone();var c={x:n},l={shape:e,inputShape:a};return Wt.runKernelFunc(function(t){return t.tile(n,o)},c,function(t){return{x:function(){return t.sum(u,!0)}}},Ir,l)}}),eu=Dn({clone_:function(t){var e=xn(t,"x","clone",null);return Wt.runKernelFunc(function(){return Wt.makeTensorFromDataId(e.dataId,e.shape,e.dtype)},{x:e},null,Mr)}}),nu=Dn({logicalAnd_:function(t,e){var n=xn(t,"a","logicalAnd","bool"),r=xn(e,"b","logicalAnd","bool");return Ur(n.shape,r.shape),Wt.runKernelFunc(function(t){return t.logicalAnd(n,r)},{a:n,b:r},null,"LogicalAnd")}}),ru=Dn({logicalNot_:function(t){var e=xn(t,"x","logicalNot","bool");return Wt.runKernelFunc(function(t){return t.logicalNot(e)},{$x:e})}}),iu=Dn({logicalOr_:function(t,e){var n=xn(t,"a","logicalOr","bool"),r=xn(e,"b","logicalOr","bool");return Ur(n.shape,r.shape),Wt.runKernelFunc(function(t){return t.logicalOr(n,r)},{$a:n,$b:r})}}),au=Dn({logicalXor_:function(t,e){var n=xn(t,"a","logicalXor","bool"),r=xn(e,"b","logicalXor","bool");return Ur(n.shape,r.shape),iu(t,e).logicalAnd(nu(t,e).logicalNot())}}),ou=Dn({where_:function(t,e,n){var r=xn(e,"a","where"),i=xn(n,"b","where"),a=xn(t,"condition","where","bool");return A(r.shape,i.shape,"Error in where: "),1===a.rank?C(a.shape[0]===r.shape[0],function(){return"The first dimension of `a` must match the size of `condition`."}):A(a.shape,i.shape,"Error in where: "),Wt.runKernelFunc(function(t,e){var n=t.select(a,r,i);return e([a]),n},{$condition:a,$a:r,$b:i},function(t,e){var n=e[0];return{$condition:function(){return Zn(n).toFloat()},$a:function(){return t.mul(n.cast(t.dtype))},$b:function(){return t.mul(n.logicalNot().cast(t.dtype))}}})}}),su=function(t){return u(this,void 0,void 0,function(){var e,n,r;return c(this,function(i){switch(i.label){case 0:return[4,(e=xn(t,"condition","whereAsync","bool")).data()];case 1:return n=i.sent(),r=Ga(e.shape,n),t!==e&&e.dispose(),[2,r]}})})},uu=Dn({divNoNan_:function(t,e){var n,r=xn(t,"a","div"),i=xn(e,"b","div");r=(n=Ft(r,i))[0],i=n[1];var a=zi(r,i),o=Zn(a),s=i.equal(o);return ou(s,o,a)}}),cu=Dn({tile_:function(t,e){var n=xn(t,"x","tile",null);C(n.rank===e.length,function(){return"Error in transpose: rank of input "+n.rank+" must match length of reps "+e+"."});var r=[n],i={x:n},a={reps:e};return Wt.runKernelFunc(function(t,r){var i=t.tile(n,e);return r([n]),i},i,null,Rr,a,r)}}),lu=Dn({eye_:function(t,e,n,r){void 0===r&&(r="float32"),null==e&&(e=t);for(var i=ar([t,e],r),a=t<=e?t:e,o=0;o<a;++o)i.set(1,o,o);var s=i.toTensor().as2D(t,e);if(null==n)return s;if(1===n.length)return cu(fr(s,0),[n[0],1,1]);if(2===n.length)return cu(fr(fr(s,0),0),[n[0],n[1],1,1]);if(3===n.length)return cu(fr(fr(fr(s,0),0),0),[n[0],n[1],n[2],1,1]);throw new Error("eye() currently supports only 1D and 2D batchShapes, but received "+n.length+"D.")}}),fu=Dn({multinomial_:function(t,e,n,r){void 0===r&&(r=!1);var i=xn(t,"logits","multinomial"),a=i.size,o=i.rank;if(a<2)throw new Error("Error in multinomial: you need at least 2 outcomes, but got "+a+".");if(o>2)throw new Error("Rank of probabilities must be 1 or 2, but is "+o);n=n||Math.random();var s=1===o?i.as2D(1,-1):i,u=Wt.runKernelFunc(function(t){return t.multinomial(s,r,e,n)},{logits2D:s});return 1===o?u.as1D():u}}),du=Dn({oneHot_:function(t,e,n,r){if(void 0===n&&(n=1),void 0===r&&(r=0),e<2)throw new Error("Error in oneHot: depth must be >=2, but it is "+e);var i=xn(t,"indices","oneHot","int32"),a=i.shape.concat([e]),o={indices:i=i.flatten()},s={depth:e,onValue:n,offValue:r};return Wt.runKernelFunc(function(t,a){return a([i]),t.oneHot(i,e,n,r)},o,null,Dr,s).reshape(a)}}),hu=Dn({pad_:function(t,e,n){void 0===n&&(n=0);var r=xn(t,"x","pad");if(0===r.rank)throw new Error("pad(scalar) is not defined. Pass non-scalar to pad");var i={paddings:e,constantValue:n},a={x:r};return Wt.runKernelFunc(function(t,i){return i([r]),t.pad(r,e,n)},a,null,Fr,i)}}),pu=Dn({pad1d_:function(t,e,n){return void 0===n&&(n=0),C(2===e.length,function(){return"Invalid number of paddings. Must be length of 2."}),hu(t,[e],n)}}),mu=Dn({pad2d_:function(t,e,n){return void 0===n&&(n=0),C(2===e.length&&2===e[0].length&&2===e[1].length,function(){return"Invalid number of paddings. Must be length of 2 each."}),hu(t,e,n)}}),gu=Dn({pad3d_:function(t,e,n){return void 0===n&&(n=0),C(3===e.length&&2===e[0].length&&2===e[1].length&&2===e[2].length,function(){return"Invalid number of paddings. Must be length of 2 each."}),hu(t,e,n)}}),vu=Dn({pad4d_:function(t,e,n){return void 0===n&&(n=0),C(4===e.length&&2===e[0].length&&2===e[1].length&&2===e[2].length&&2===e[3].length,function(){return"Invalid number of paddings. Must be length of 2 each."}),hu(t,e,n)}}),yu=Dn({rand_:function(t,e,n){var r=I(t),i=null;if(null==n||"float32"===n)i=new Float32Array(r);else if("int32"===n)i=new Int32Array(r);else{if("bool"!==n)throw new Error("Unknown data type "+n);i=new Uint8Array(r)}for(var a=0;a<r;a++)i[a]=e();return Wt.makeTensor(i,t,n)}}),bu=.001,xu=.1;function wu(){return 32===Wt.backend.floatPrecision()?bu:xu}function ku(t,e,n){var r=!0;if((G(t)||G(e))&&(r=!1),G(t)&&G(e)&&(r=!0),r){var i=t.constructor.name,a=e.constructor.name;if(i!==a)throw new Error("Arrays are of different type. Actual: "+i+". Expected: "+a)}if(Array.isArray(t)&&Array.isArray(e)){var o=yn(t),s=yn(e);if(!D(o,s))throw new Error("Arrays have different shapes. Actual: ["+o+"]. Expected: ["+s+"]")}var u=G(t)?t:T(t),c=G(e)?e:T(e);if(u.length!==c.length)throw new Error("Arrays have different lengths actual: "+u.length+" vs expected: "+c.length+".\nActual: "+u+".\nExpected: "+c+".");for(var l=0;l<c.length;++l){var f=u[l],d=c[l];if(!n(f,d))throw new Error("Arrays differ: actual["+l+"] = "+f+", expected["+l+"] = "+d+".\nActual: "+u+".\nExpected: "+c+".")}}function _u(t,e,n){return!isFinite(t)&&!isFinite(e)||!(isNaN(t)||isNaN(e)||Math.abs(t-e)>n)}var Eu=Object.freeze({TEST_EPSILON_FLOAT16:xu,expectArraysClose:function(t,e,n){return null==n&&(n=wu()),ku(t,e,function(t,e){return _u(t,e,n)})},testEpsilon:wu,expectPromiseToFail:function(t,e){t().then(function(){return e.fail()},function(){return e()})},expectArraysEqual:function(t,e){var n="string"==typeof e||"number"==typeof e||"boolean"==typeof e?[e]:e;return X(t)||X(t[0])||X(e)||X(e[0])?ku(t,n,function(t,e){return t==e}):ku(t,e,function(t,e){return _u(t,e,0)})},expectNumbersClose:function(t,e,n){if(null==n&&(n=wu()),!_u(t,e,n))throw new Error("Numbers differ: actual === "+t+", expected === "+e)},expectValuesInRange:function(t,e,n){for(var r=0;r<t.length;r++)if(t[r]<e||t[r]>n)throw new Error("Value out of range:"+t[r]+" low: "+e+", high: "+n)},expectArrayBuffersEqual:function(t,e){expect(new Float32Array(t)).toEqual(new Float32Array(e))}}),Ou=function(){function t(t,e,n,r,i){this.mean=t,this.stdDev=e,this.dtype=n,this.nextVal=NaN,this.truncated=r,this.truncated&&(this.upper=this.mean+2*this.stdDev,this.lower=this.mean-2*this.stdDev);var a=i||Math.random();this.random=Ps(a.toString())}return t.prototype.nextValue=function(){if(!isNaN(this.nextVal)){var t=this.nextVal;return this.nextVal=NaN,t}for(var e,n,r=!1;!r;){var i=void 0,a=void 0,o=void 0;do{o=(i=2*this.random()-1)*i+(a=2*this.random()-1)*a}while(o>=1||0===o);var s=Math.sqrt(-2*Math.log(o)/o);e=this.mean+this.stdDev*i*s,n=this.mean+this.stdDev*a*s,this.truncated&&!this.isValidTruncated(e)||(r=!0)}return this.truncated&&!this.isValidTruncated(n)||(this.nextVal=this.convertValue(n)),this.convertValue(e)},t.prototype.convertValue=function(t){return null==this.dtype||"float32"===this.dtype?t:Math.round(t)},t.prototype.isValidTruncated=function(t){return t<=this.upper&&t>=this.lower},t}(),Su=function(){function t(t,e,n,r){this.alpha=t,this.beta=1/e,this.dtype=n;var i=r||Math.random();this.randu=Ps(i.toString()),this.randn=new Ou(0,1,n,!1,this.randu()),this.d=t<1?t+2/3:t-1/3,this.c=1/Math.sqrt(9*this.d)}return t.prototype.nextValue=function(){for(var t,e,n,r,i,a;;){do{r=this.randn.nextValue(),a=1+this.c*r}while(a<=0);if(a*=a*a,e=1-.331*(t=r*r)*t,n=.5*t+this.d*(1-a+Math.log(a)),(i=this.randu())<e||Math.log(i)<n)break}return a=1/this.beta*this.d*a,this.alpha<1&&(a*=Math.pow(this.randu(),1/this.alpha)),this.convertValue(a)},t.prototype.convertValue=function(t){return"float32"===this.dtype?t:Math.round(t)},t}(),Cu=function(){function t(t,e,n,r){var i=this;if(void 0===t&&(t=0),void 0===e&&(e=1),this.canReturnFloat=function(){return null==i.dtype||"float32"===i.dtype},this.min=t,this.range=e-t,this.dtype=n,null==r&&(r=Math.random()),"number"==typeof r&&(r=r.toString()),!this.canReturnFloat()&&this.range<=1)throw new Error("The difference between "+t+" - "+e+" <= 1 and dtype is not float");this.random=Ps(r)}return t.prototype.convertValue=function(t){return this.canReturnFloat()?t:Math.round(t)},t.prototype.nextValue=function(){return this.convertValue(this.min+this.range*this.random())},t}(),Au=Dn({randomGamma_:function(t,e,n,r,i){if(void 0===n&&(n=1),void 0===r&&(r="float32"),null==n&&(n=1),null==r&&(r="float32"),"float32"!==r&&"int32"!==r)throw new Error("Unsupported data type "+r);for(var a=new Su(e,n,r,i),o=ar(t,r),s=0;s<o.values.length;s++)o.values[s]=a.nextValue();return o.toTensor()}}),Nu=Dn({randomNormal_:function(t,e,n,r,i){if(void 0===e&&(e=0),void 0===n&&(n=1),null!=r&&"bool"===r)throw new Error("Unsupported data type "+r);for(var a=new Ou(e,n,r,!1,i),o=ar(t,r),s=0;s<o.values.length;s++)o.values[s]=a.nextValue();return o.toTensor()}}),Tu=Dn({randomUniform_:function(t,e,n,r,i){void 0===e&&(e=0),void 0===n&&(n=1),void 0===r&&(r="float32");for(var a=ar(t,r),o=new Cu(e,n,null,i),s=0;s<a.values.length;s++)a.values[s]=o.nextValue();return a.toTensor()}}),Iu=Dn({square_:function(t){var e=xn(t,"x","square"),n=[e];return Wt.runKernelFunc(function(t,n){return n([e]),t.square(e)},{x:e},null,"Square",{},n,[])}}),Du=Dn({squaredDifference_:function(t,e){var n,r=xn(t,"a","squaredDifference"),i=xn(e,"b","squaredDifference");n=Ft(r,i),r=n[0],i=n[1],Ur(r.shape,i.shape);var a={a:r,b:i},o=[r,i];return Wt.runKernelFunc(function(t,e){var n=t.squaredDifference(r,i);return e([r,i]),n},a,function(t,e){var n=e[0],r=e[1],i=Ln(2);return{a:function(){return t.mul(n.sub(r).mul(i))},b:function(){return t.mul(r.sub(n).mul(i))}}},Cr,{},o,[])}}),Mu=Dn({truncatedNormal_:function(t,e,n,r,i){if(void 0===e&&(e=0),void 0===n&&(n=1),null!=r&&"bool"===r)throw new Error("Unsupported data type $ { dtype }");for(var a=new Ou(e,n,r,!0,i),o=ar(t,r),s=0;s<o.values.length;s++)o.values[s]=a.nextValue();return o.toTensor()}}),Ru=Dn({equal_:function(t,e){var n,r=xn(t,"a","equal"),i=xn(e,"b","equal");return n=Ft(r,i),r=n[0],i=n[1],Ur(r.shape,i.shape),Wt.runKernelFunc(function(t){return t.equal(r,i)},{$a:r,$b:i})}}),Fu=Dn({equalStrict_:function(t,e){var n=xn(t,"a","equalStrict"),r=xn(e,"b","equalStrict");return A(n.shape,r.shape,"Error in equalStrict: "),n.equal(r)}}),ju=Dn({greater_:function(t,e){var n,r=xn(t,"a","greater"),i=xn(e,"b","greater");return n=Ft(r,i),r=n[0],i=n[1],Ur(r.shape,i.shape),Wt.runKernelFunc(function(t){return t.greater(r,i)},{a:r,b:i},null,"Greater")}}),Pu=Dn({greaterEqual_:function(t,e){var n,r=xn(t,"a","greaterEqual"),i=xn(e,"b","greaterEqual");return n=Ft(r,i),r=n[0],i=n[1],Ur(r.shape,i.shape),Wt.runKernelFunc(function(t,e){var n=t.greaterEqual(r,i);return e([r,i]),n},{a:r,b:i},function(t,e){var n=e[0],r=e[1];return{a:function(){return Zn(n)},b:function(){return Zn(r)}}},"GreaterEqual")}}),Lu=Dn({greaterEqualStrict_:function(t,e){var n=xn(t,"a","greaterEqualStrict"),r=xn(e,"b","greaterEqualStrict");return A(n.shape,r.shape,"Error in greaterEqualStrict: "),n.greaterEqual(r)}}),zu=Dn({greaterStrict_:function(t,e){var n=xn(t,"a","greaterStrict"),r=xn(e,"b","greaterStrict");return A(n.shape,r.shape,"Error in greaterStrict: "),n.greater(r)}}),Bu=Dn({less_:function(t,e){var n,r=xn(t,"a","less"),i=xn(e,"b","less");return n=Ft(r,i),r=n[0],i=n[1],Ur(r.shape,i.shape),Wt.runKernelFunc(function(t){return t.less(r,i)},{a:r,b:i},null,"Less")}}),Uu=Dn({lessEqual_:function(t,e){var n,r=xn(t,"a","lessEqual"),i=xn(e,"b","lessEqual");return n=Ft(r,i),r=n[0],i=n[1],Ur(r.shape,i.shape),Wt.runKernelFunc(function(t,e){var n=t.lessEqual(r,i);return e([r,i]),n},{a:r,b:i},null,"LessEqual")}}),Wu=Dn({lessEqualStrict_:function(t,e){var n=xn(t,"a","lessEqualStrict"),r=xn(e,"b","lessEqualStrict");return A(n.shape,r.shape,"Error in lessEqualStrict: "),n.lessEqual(r)}}),Vu=Dn({lessStrict_:function(t,e){var n=xn(t,"a","lessStrict"),r=xn(e,"b","lessStrict");return A(n.shape,r.shape,"Error in lessStrict: "),n.less(r)}}),qu=Dn({notEqual_:function(t,e){var n,r=xn(t,"a","notEqual"),i=xn(e,"b","notEqual");return n=Ft(r,i),r=n[0],i=n[1],Ur(r.shape,i.shape),Wt.runKernelFunc(function(t){return t.notEqual(r,i)},{a:r,b:i},null,"NotEqual")}}),Hu=Dn({notEqualStrict_:function(t,e){var n=xn(t,"a","notEqualStrict"),r=xn(e,"b","notEqualStrict");return A(n.shape,r.shape,"Error in notEqualStrict: "),n.notEqual(r)}});function Gu(t,e){for(var n=[],r=t;r<e;++r)n.push(r);return n}function $u(t){for(var e=[],n=0;n<t.length;++n)for(var r=0;r<t[n].length;++r)e.push(t[n][r]);return e}var Ku=Dn({gather_:function(t,e,n){void 0===n&&(n=0);var r=xn(t,"x","gather"),i=xn(e,"indices","gather","int32");n=z(n,r.shape)[0];var a=function(t,e,n){for(var r=t.shape[n],i=[],a=1,o=1,s=0;s<n;s++)i.push(t.shape[s]),a*=t.shape[s];for(s=0;s<e.rank;s++)i.push(e.shape[s]);for(s=n+1;s<t.rank;s++)i.push(t.shape[s]),o*=t.shape[s];return{batchSize:a,sliceSize:o,dimSize:r,outputShape:i}}(r,i,n);return Wt.runKernelFunc(function(t,e){var a=t.gather(r,i.flatten(),n);return e([i]),a},{x:r,indices:i},function(t,e){var i=e[0];return{x:function(){var e=r.shape,a=i.size,o=e.slice(0,n),s=o.length,u=e.slice(n,e.length).slice(1),c=u.length,l=Gu(0,s),f=Gu(s+1,s+1+c),d=$u([o,[a],u]),h=t.reshape(d),p=i.reshape([a]),m=$u([[s],l,f]),g=h.transpose(m),v=Xu(g,p,r.shape[n]),y=An(m);return v.transpose(y)},indices:function(){return i}}},"Gather",{axis:n}).reshape(a.outputShape)}}),Xu=Dn({unsortedSegmentSum_:function(t,e,n){var r=xn(t,"x","unsortedSegmentSum"),i=xn(e,"segmentIds","unsortedSegmentSum","int32");return C(M(n),function(){return"numSegments must be of dtype int"}),Wt.runKernelFunc(function(t,e){var a=t.unsortedSegmentSum(r,i,n);return e([i]),a},{$x:r},function(t,e){var n=e[0];return{$x:function(){return function(t,e){for(var n=Si(e,Zn(e)),r=Ku(t,n),i=Pu(e,Ln(0,"int32")),a=r.rank-i.rank,o=0;o<a;++o)i=fr(i,o+1);i=nu(i,Gn(r.shape,"bool"));var s=Zn(r);return ou(i,r,s)}(t,n)}}})}}),Yu=function(t,e,n){return u(this,void 0,void 0,function(){var r,i,a,o,s,u,l,f,d,h,p,m,g;return c(this,function(c){switch(c.label){case 0:for(r=xn(t,"tensor","boolMask"),i=xn(e,"mask","boolMask","bool"),a=null==n?0:n,o=i.rank,s=r.shape,C(o>0,function(){return"mask cannot be scalar"}),A(s.slice(a,a+o),i.shape,"mask's shape must match the first K dimensions of tensor's shape,"),u=1,l=a;l<a+o;l++)u*=s[l];return f=s.slice(0,a).concat([u],s.slice(a+o)),d=r.reshape(f),h=i.reshape([-1]),[4,su(h)];case 1:return p=c.sent(),m=p.squeeze([1]),g=Ku(d,m,a),t!==r&&r.dispose(),e!==i&&i.dispose(),m.dispose(),d.dispose(),h.dispose(),p.dispose(),[2,g]}})})};function Ju(t,e,n,r,i,a,o){void 0===a&&(a="NHWC"),C(t.length===e.rank,function(){return"Length of inShape ("+t.length+") and rank of dy ("+e.rank+") must match"});var s=t,u=e,c=!1;3===e.rank&&(c=!0,u=e.as4D(1,e.shape[0],e.shape[1],e.shape[2]),s=[1,t[0],t[1],t[2]]),C(4===s.length,function(){return"Error in conv2dDerInput: inShape must be length 4, but got length "+s.length+"."}),C(4===u.rank,function(){return"Error in conv2dDerInput: dy must be rank 4, but got rank "+u.rank}),C(4===n.rank,function(){return"Error in conv2dDerInput: filter must be rank 4, but got rank "+n.rank});var l="NHWC"===a?s[3]:s[1],f="NHWC"===a?u.shape[3]:u.shape[1];C(l===n.shape[2],function(){return"Error in conv2dDerInput: depth of input ("+l+") must match input depth for filter "+n.shape[2]+"."}),C(f===n.shape[3],function(){return"Error in conv2dDerInput: depth of output ("+f+") must match output depth for filter "+n.shape[3]+"."}),null!=o&&C(M(i),function(){return"Error in conv2dDerInput: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+i+"."});var d=Sa(a),h=va(s,n.shape,r,1,i,o,!1,d),p=Wt.runKernelFunc(function(t,e){var r=t.conv2dDerInput(u,n,h);return e([n,u]),r},{dy4D:u,filter:n},function(t,e){var n=e[0],s=e[1];return{dy4D:function(){return ec(t,n,r,i,a,1,o)},filter:function(){return rc(t,s,n.shape,r,i,a,o)}}});return c?p.as3D(p.shape[1],p.shape[2],p.shape[3]):p}function Zu(t){var e=function(t){return"number"==typeof t?[t,t,t]:2===t.length?[t[0],t[1],1]:t}(t),n=e[0],r=e[1],i=e[2];return 1===n&&1===r&&1===i}function Qu(t,e,n,r,i){C(t.length===e.rank,function(){return"Length of inShape ("+t.length+") and rank of dy ("+e.rank+") must match"});var a=t,o=e,s=!1;4===e.rank&&(s=!0,o=e.as5D(1,e.shape[0],e.shape[1],e.shape[2],e.shape[3]),a=[1,t[0],t[1],t[2],t[3]]);var u=a[4],c=o.shape[4];C(5===a.length,function(){return"Error in conv3dDerInput: inShape must be length 5, but got length "+a.length+"."}),C(5===o.rank,function(){return"Error in conv3dDerInput: dy must be rank 5, but got rank "+o.rank}),C(5===n.rank,function(){return"Error in conv3dDerInput: filter must be rank 5, but got rank "+n.rank}),C(u===n.shape[3],function(){return"Error in conv3dDerInput: depth of input ("+u+") must match input depth for filter "+n.shape[3]+"."}),C(c===n.shape[4],function(){return"Error in conv3dDerInput: depth of output ("+c+") must match output depth for filter "+n.shape[4]+"."});var l=ya(a,n.shape,r,1,i),f=Wt.runKernelFunc(function(t){return t.conv3dDerInput(o,n,l)},{dy5D:o});return s?f.as4D(f.shape[1],f.shape[2],f.shape[3],f.shape[4]):f}var tc=Dn({conv1d_:function(t,e,n,r,i,a,o){void 0===i&&(i="NWC"),void 0===a&&(a=1);var s=xn(t,"x","conv1d"),u=xn(e,"filter","conv1d"),c=s,l=!1;2===s.rank&&(l=!0,c=s.as3D(1,s.shape[0],s.shape[1])),C(3===c.rank,function(){return"Error in conv1d: input must be rank 3, but got rank "+c.rank+"."}),C(3===u.rank,function(){return"Error in conv1d: filter must be rank 3, but got rank "+u.rank+"."}),null!=o&&C(M(r),function(){return"Error in conv1d: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+r+"."}),C(c.shape[2]===u.shape[1],function(){return"Error in conv1d: depth of input ("+c.shape[2]+") must match input depth for filter "+u.shape[1]+"."}),C(Oa(n,a),function(){return"Error in conv1D: Either stride or dilation must be 1. Got stride "+n+" and dilation '"+a+"'"}),C("NWC"===i,function(){return"Error in conv1d: got dataFormat of "+i+" but only NWC is currently supported."});var f=u.as4D(1,u.shape[0],u.shape[1],u.shape[2]),d=c.as4D(c.shape[0],1,c.shape[1],c.shape[2]),h=ec(d,f,[1,n],r,"NHWC",[1,a],o);return l?h.as2D(h.shape[2],h.shape[3]):h.as3D(h.shape[0],h.shape[2],h.shape[3])}}),ec=Dn({conv2d_:function(t,e,n,r,i,a,o){void 0===i&&(i="NHWC"),void 0===a&&(a=[1,1]);var s=xn(t,"x","conv2d"),u=xn(e,"filter","conv2d"),c=s,l=!1;3===s.rank&&(l=!0,c=s.as4D(1,s.shape[0],s.shape[1],s.shape[2])),C(4===c.rank,function(){return"Error in conv2d: input must be rank 4, but got rank "+c.rank+"."}),C(4===u.rank,function(){return"Error in conv2d: filter must be rank 4, but got rank "+u.rank+"."}),null!=o&&C(M(r),function(){return"Error in conv2d: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+r+"."});var f="NHWC"===i?c.shape[3]:c.shape[1];C(f===u.shape[2],function(){return"Error in conv2d: depth of input ("+f+") must match input depth for filter "+u.shape[2]+"."}),C(Oa(n,a),function(){return"Error in conv2D: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+a+"'"});var d=Sa(i),h=va(c.shape,u.shape,n,a,r,o,!1,d),p=[u,c],m=Wt.runKernelFunc(function(t,e){var n=t.conv2d(c,u,h);return e([u,c]),n},{x:c,filter:u},function(t,e){var o=e,s=o[0],u=o[1];return C(Ea(a),function(){return"Error in gradient of conv2D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '"+a+"'"}),{x:function(){return ic(u.shape,t,s,n,r,i)},filter:function(){return rc(u,t,s.shape,n,r,i)}}},"Conv2D",h,p);return l?m.as3D(m.shape[1],m.shape[2],m.shape[3]):m}}),nc=Dn({conv3d_:function(t,e,n,r,i,a){void 0===i&&(i="NDHWC"),void 0===a&&(a=[1,1,1]);var o=xn(t,"x","conv3d"),s=xn(e,"filter","conv3d"),u=o,c=!1;4===o.rank&&(c=!0,u=o.as5D(1,o.shape[0],o.shape[1],o.shape[2],o.shape[3])),C(5===u.rank,function(){return"Error in conv3d: input must be rank 5, but got rank "+u.rank+"."}),C(5===s.rank,function(){return"Error in conv3d: filter must be rank 5, but got rank "+s.rank+"."}),C(u.shape[4]===s.shape[3],function(){return"Error in conv3d: depth of input ("+u.shape[4]+") must match input depth for filter "+s.shape[3]+"."}),C(function(t,e){return Zu(n)||Zu(e)}(0,a),function(){return"Error in conv3D: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+a+"'"}),C("NDHWC"===i,function(){return"Error in conv3d: got dataFormat of "+i+" but only NDHWC is currently supported."});var l=ya(u.shape,s.shape,n,a,r),f=Wt.runKernelFunc(function(t,e){var n=t.conv3d(u,s,l);return e([u,s]),n},{x:u,$filter:s},function(t,e){C(Zu(a),function(){return"Error in gradient of conv3D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '"+a+"'"});var i=e[0],o=e[1];return{x:function(){return Qu(i.shape,t,o,n,r)},$filter:function(){return function(t,e,n,r,i){var a=t;4===t.rank&&(a=t.as5D(1,t.shape[0],t.shape[1],t.shape[2],t.shape[3]));var o=e;4===o.rank&&(o=e.as5D(1,e.shape[0],e.shape[1],e.shape[2],e.shape[3])),C(5===a.rank,function(){return"Error in conv3dDerFilter: input must be rank 5, but got shape "+a.shape+"."}),C(5===o.rank,function(){return"Error in conv3dDerFilter: dy must be rank 5, but got shape "+o.shape+"."}),C(5===n.length,function(){return"Error in conv3dDerFilter: filterShape must be length 5, but got "+n+"."}),C(a.shape[4]===n[3],function(){return"Error in conv3dDerFilter: depth of input "+a.shape[4]+") must match input depth in filter ("+n[3]+"."}),C(o.shape[4]===n[4],function(){return"Error in conv3dDerFilter: depth of dy ("+o.shape[4]+") must match output depth for filter ("+n[4]+")."});var s=ya(a.shape,n,r,1,i);return Wt.runKernelFunc(function(t){return t.conv3dDerFilter(a,o,s)},{x5D:a,dy5D:o})}(i,t,o.shape,n,r)}}});return c?f.as4D(f.shape[1],f.shape[2],f.shape[3],f.shape[4]):f}}),rc=Dn({conv2dDerFilter_:function(t,e,n,r,i,a,o){void 0===a&&(a="NHWC");var s=t;3===t.rank&&(s=t.as4D(1,t.shape[0],t.shape[1],t.shape[2]));var u=e;3===u.rank&&(u=e.as4D(1,e.shape[0],e.shape[1],e.shape[2])),C(4===s.rank,function(){return"Error in conv2dDerFilter: input must be rank 4, but got shape "+s.shape+"."}),C(4===u.rank,function(){return"Error in conv2dDerFilter: dy must be rank 4, but got shape "+u.shape+"."}),C(4===n.length,function(){return"Error in conv2dDerFilter: filterShape must be length 4, but got "+n+"."});var c="NHWC"===a?s.shape[3]:s.shape[1],l="NHWC"===a?u.shape[3]:u.shape[1];C(c===n[2],function(){return"Error in conv2dDerFilter: depth of input "+c+") must match input depth in filter ("+n[2]+"."}),C(l===n[3],function(){return"Error in conv2dDerFilter: depth of dy ("+l+") must match output depth for filter ("+n[3]+")."}),null!=o&&C(M(i),function(){return"Error in conv2dDerFilter: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+i+"."});var f=Sa(a),d=va(s.shape,n,r,1,i,o,!1,f);return Wt.runKernelFunc(function(t){return t.conv2dDerFilter(s,u,d)},{x4D:s,dy4D:u})}}),ic=Dn({conv2dDerInput_:Ju}),ac=Dn({depthwiseConv2d_:function(t,e,n,r,i,a,o){void 0===i&&(i="NHWC"),void 0===a&&(a=[1,1]);var s=xn(t,"x","depthwiseConv2d"),u=xn(e,"filter","depthwiseConv2d"),c=s,l=!1;3===s.rank&&(l=!0,c=s.as4D(1,s.shape[0],s.shape[1],s.shape[2])),C(4===c.rank,function(){return"Error in depthwiseConv2d: input must be rank 4, but got rank "+c.rank+"."}),C(4===u.rank,function(){return"Error in depthwiseConv2d: filter must be rank 4, but got rank "+u.rank+"."}),C(c.shape[3]===u.shape[2],function(){return"Error in depthwiseConv2d: number of input channels ("+c.shape[3]+") must match the inChannels dimension in filter "+u.shape[2]+"."}),null==a&&(a=[1,1]),C(Oa(n,a),function(){return"Error in depthwiseConv2d: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+a+"'"}),null!=o&&C(M(r),function(){return"Error in depthwiseConv2d: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+r+"."});var f=va(c.shape,u.shape,n,a,r,o,!0),d=[c,u],h=Wt.runKernelFunc(function(t,e){var n=t.depthwiseConv2D(c,u,f);return e([c,u]),n},{x:c,filter:u},function(t,e){C(Ea(a),function(){return"Error in gradient of depthwiseConv2d: dilation rates greater than 1 are not yet supported. Got dilations '"+a+"'"});var n=e[0],r=e[1];return{x:function(){return oc(n.shape,t,r,f)},filter:function(){return sc(n,t,r.shape,f)}}},"DepthwiseConv2dNative",f,d);return l?h.as3D(h.shape[1],h.shape[2],h.shape[3]):h}}),oc=Dn({depthwiseConv2dDerInput_:function(t,e,n,r){var i=e,a=!1;3===e.rank&&(a=!0,i=e.as4D(1,e.shape[0],e.shape[1],e.shape[2]));var o=Wt.runKernelFunc(function(t){return t.depthwiseConv2DDerInput(i,n,r)},{dy4D:i});return a?o.as3D(o.shape[1],o.shape[2],o.shape[3]):o}}),sc=Dn({depthwiseConv2dDerFilter_:function(t,e,n,r){var i=t;3===t.rank&&(i=t.as4D(1,t.shape[0],t.shape[1],t.shape[2]));var a=e;return 3===a.rank&&(a=e.as4D(1,e.shape[0],e.shape[1],e.shape[2])),Wt.runKernelFunc(function(t){return t.depthwiseConv2DDerFilter(i,a,r)},{x4D:i,dy4D:a})}}),uc=Dn({separableConv2d_:function(t,e,n,r,i,a,o){void 0===a&&(a=[1,1]),void 0===o&&(o="NHWC");var s=xn(t,"x","separableConv2d"),u=xn(e,"depthwiseFilter","separableConv2d"),c=xn(n,"pointwiseFilter","separableConv2d"),l=s,f=!1;if(3===s.rank&&(f=!0,l=s.as4D(1,s.shape[0],s.shape[1],s.shape[2])),"NCHW"===o)throw new Error("separableConv2d currently does not support dataFormat NCHW; only NHWC is supported");C(4===l.rank,function(){return"Error in separableConv2d: input must be rank 4, but got rank "+l.rank+"."}),C(4===u.rank,function(){return"Error in separableConv2d: depthwise filter must be rank 4, but got rank "+u.rank+"."}),C(4===c.rank,function(){return"Error in separableConv2d: pointwise filter must be rank 4, but got rank "+u.rank+"."}),C(1===c.shape[0],function(){return"Error in separableConv2d: the first dimension of pointwise filter must be 1, but got "+c.shape[0]+"."}),C(1===c.shape[1],function(){return"Error in separableConv2d: the second dimension of pointwise filter must be 1, but got "+c.shape[1]+"."});var d=u.shape[2],h=u.shape[3];C(c.shape[2]===d*h,function(){return"Error in separableConv2d: the third dimension of pointwise filter must be "+d*h+", but got "+c.shape[2]+"."});var p=ac(l,u,r,i,o,a),m=ec(p,c,1,"valid",o);return f?m.as3D(m.shape[1],m.shape[2],m.shape[3]):m}}),cc=Dn({conv2dTranspose_:function(t,e,n,r,i,a){return Ju(n,xn(t,"x","conv2dTranspose"),xn(e,"filter","conv2dTranspose"),r,i,"NHWC",a)}}),lc=Dn({conv3dTranspose_:function(t,e,n,r,i){return Qu(n,xn(t,"x","conv3dTranspose"),xn(e,"filter","conv3dTranspose"),r,i)}}),fc=Dn({matMul_:function(t,e,n,r){var i;void 0===n&&(n=!1),void 0===r&&(r=!1);var a=xn(t,"a","matMul"),o=xn(e,"b","matMul");i=Ft(a,o),a=i[0],o=i[1];var s=n?a.shape[a.rank-2]:a.shape[a.rank-1],u=r?o.shape[o.rank-1]:o.shape[o.rank-2],c=n?a.shape[a.rank-1]:a.shape[a.rank-2],l=r?o.shape[o.rank-2]:o.shape[o.rank-1],f=a.shape.slice(0,-2),d=o.shape.slice(0,-2),h=I(f),p=I(d);C(a.rank>=2&&o.rank>=2&&a.rank===o.rank,function(){return"Error in matMul: inputs must have the same rank of at least 2, got ranks "+a.rank+" and "+o.rank+"."}),C(D(f,d),function(){return"Error in matMul: outer dimensions ("+f+") and ("+d+") of Tensors with shapes "+a.shape+" and "+o.shape+" must match."}),C(s===u,function(){return"Error in matMul: inner shapes ("+s+") and ("+u+") of Tensors with shapes "+a.shape+" and "+o.shape+" and transposeA="+n+" and transposeB="+r+" must match."});var m=a.shape.slice(0,-2).concat([c,l]),g=n?a.as3D(h,s,c):a.as3D(h,c,s),v=r?o.as3D(p,l,u):o.as3D(p,u,l),y={transposeA:n,transposeB:r};return Wt.runKernelFunc(function(t,e){var i=t.batchMatMul(g,v,n,r);return e([g,v]),i},{a:g,b:v},function(t,e){var i=e,a=i[0],o=i[1];return n||r?!n&&r?{a:function(){return t.matMul(o,!1,!1)},b:function(){return t.matMul(a,!0,!1)}}:n&&!r?{a:function(){return o.matMul(t,!1,!0)},b:function(){return a.matMul(t,!1,!1)}}:{a:function(){return o.matMul(t,!0,!0)},b:function(){return t.matMul(a,!0,!0)}}:{a:function(){return t.matMul(o,!1,!0)},b:function(){return a.matMul(t,!0,!1)}}},"BatchMatMul",y).reshape(m)}}),dc=Dn({dot_:function(t,e){var n=xn(t,"t1","dot"),r=xn(e,"t2","dot");C(!(1!==n.rank&&2!==n.rank||1!==r.rank&&2!==r.rank),function(){return"Error in dot: inputs must all be rank 1 or 2, but got ranks "+n.rank+" and "+r.rank+"."});var i=1===n.rank?n.size:n.shape[1],a=1===r.rank?r.size:r.shape[0];return C(i===a,function(){return"Error in dot: inner dimensions of inputs must match, but got "+i+" and "+a+"."}),1===n.rank&&1===r.rank?n.as2D(1,-1).matMul(r.as2D(-1,1)).asScalar():1===n.rank&&2===r.rank?n.as2D(1,-1).matMul(r.as2D(r.shape[0],r.shape[1])).as1D():2===n.rank&&1===r.rank?n.matMul(r.as2D(-1,1)).as1D():n.matMul(r.as2D(r.shape[0],r.shape[1]))}}),hc=Dn({outerProduct_:function(t,e){var n=xn(t,"v1","outerProduct"),r=xn(e,"v2","outerProduct");return C(1===n.rank&&1===r.rank,function(){return"Error in outerProduct: inputs must be rank 1, but got ranks "+n.rank+" and "+r.rank+"."}),n.as2D(-1,1).matMul(r.as2D(1,-1))}}),pc=Dn({reverse_:function(t,e){var n=xn(t,"x","reverse");if(0===n.rank)return n.clone();var r=z(e,n.shape);return Wt.runKernelFunc(function(t){return t.reverse(n,r)},{$x:n},function(t){return{$x:function(){return t.reverse(r)}}}).reshapeAs(n)}}),mc=Dn({reverse1d_:function(t){var e=xn(t,"x","reverse");return C(1===e.rank,function(){return"Error in reverse1D: x must be rank 1 but got rank "+e.rank+"."}),pc(e,0)}}),gc=Dn({reverse2d_:function(t,e){var n=xn(t,"x","reverse");return C(2===n.rank,function(){return"Error in reverse2D: x must be rank 2 but got rank "+n.rank+"."}),pc(n,e)}}),vc=Dn({reverse3d_:function(t,e){var n=xn(t,"x","reverse");return C(3===n.rank,function(){return"Error in reverse3D: x must be rank 3 but got rank "+n.rank+"."}),pc(n,e)}}),yc=Dn({reverse4d_:function(t,e){var n=xn(t,"x","reverse");return C(4===n.rank,function(){return"Error in reverse4D: x must be rank 4 but got rank "+n.rank+"."}),pc(n,e)}});function bc(t,e,n,r,i,a){var o=xn(t,"x","maxPool"),s=o,u=!1;3===o.rank&&(u=!0,s=o.as4D(1,o.shape[0],o.shape[1],o.shape[2])),null==r&&(r=[1,1]),C(4===s.rank,function(){return"Error in maxPool: input must be rank 4 but got rank "+s.rank+"."}),C(Oa(n,r),function(){return"Error in maxPool: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+r+"'"}),null!=a&&C(M(i),function(){return"Error in maxPool: pad must be an integer when using, dimRoundingMode "+a+" but got pad "+i+"."});var c=ma(s.shape,e,n,r,i,a);if(1===c.filterWidth&&1===c.filterHeight&&D(c.inShape,c.outShape))return o.clone();var l=[s],f=Wt.runKernelFunc(function(t,e){var n=t.maxPool(s,c);return e([s,n]),n},{x:s},function(t,a){var o=a[0],s=a[1];return{x:function(){return function(t,e,n,r,i,a,o,s){var u=xn(t,"dy","maxPoolBackprop"),c=xn(e,"input","maxPoolBackprop"),l=xn(n,"output","maxPoolBackprop");C(c.rank===u.rank,function(){return"Rank of input ("+c.rank+") does not match rank of dy ("+u.rank+")"}),null==a&&(a=[1,1]),C(Oa(i,a),function(){return"Error in maxPoolBackProp: Either strides or dilations must be 1. Got strides "+i+" and dilations '"+a+"'"}),C(4===u.rank,function(){return"Error in maxPoolBackprop: dy must be rank 4 but got rank "+u.rank+"."}),C(4===c.rank,function(){return"Error in maxPoolBackprop: input must be rank 4 but got rank "+c.rank+"."});var f=ma(c.shape,r,i,a,o,s);return Wt.runKernelFunc(function(t){return t.maxPoolBackprop(u,c,l,f)},{$dy:u,$input:c})}(t,o,s,e,n,r,i)}}},"MaxPool",c,l);return u?f.as3D(f.shape[1],f.shape[2],f.shape[3]):f}function xc(t,e,n,r,i,a){var o=xn(t,"x","avgPool","float32");null==r&&(r=[1,1]),C(Oa(n,r),function(){return"Error in avgPool: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+r+"'"});var s=o,u=!1;3===o.rank&&(u=!0,s=o.as4D(1,o.shape[0],o.shape[1],o.shape[2])),C(4===s.rank,function(){return"Error in avgPool: x must be rank 4 but got rank "+s.rank+"."}),null!=a&&C(M(i),function(){return"Error in avgPool: pad must be an integer when using, dimRoundingMode "+a+" but got pad "+i+"."});var c=ma(s.shape,e,n,r,i,a);if(1===c.filterWidth&&1===c.filterHeight&&D(c.inShape,c.outShape))return o.clone();var l=Wt.runKernelFunc(function(t){return t.avgPool(s,c)},{x:s},function(t){return{x:function(){return function(t,e,n,r,i,a){var o=xn(t,"dy","avgPoolBackprop"),s=xn(e,"input","avgPoolBackprop");C(s.rank===o.rank,function(){return"Rank of input ("+s.rank+") does not match rank of dy ("+o.rank+")"}),null==i&&(i=[1,1]),C(Oa(r,i),function(){return"Error in avgPoolBackprop: Either strides or dilations must be 1. Got strides "+r+" and dilations '"+i+"'"});var u=s,c=o,l=!1;3===s.rank&&(l=!0,u=s.as4D(1,s.shape[0],s.shape[1],s.shape[2]),c=o.as4D(1,o.shape[0],o.shape[1],o.shape[2])),C(4===c.rank,function(){return"Error in avgPoolBackprop: dy must be rank 4 but got rank "+c.rank+"."}),C(4===u.rank,function(){return"Error in avgPoolBackprop: input must be rank 4 but got rank "+u.rank+"."});var f=ma(u.shape,n,r,i,a),d=Wt.runKernelFunc(function(t){return t.avgPoolBackprop(c,u,f)},{dy4D:c,input4D:u});return l?d.as3D(d.shape[1],d.shape[2],d.shape[3]):d}(t,s,e,n,r,i)}}},"AvgPool",c);return l=l.cast(o.dtype),u?l.as3D(l.shape[1],l.shape[2],l.shape[3]):l}var wc=Dn({maxPool_:function(t,e,n,r,i){return bc(t,e,n,1,r,i)}}),kc=Dn({avgPool_:function(t,e,n,r,i){return xc(t,e,n,1,r,i)}}),_c=Dn({pool_:function(t,e,n,r,i,a){null==i&&(i=[1,1]),null==a&&(a=1),0===r&&(r="valid");var o=xn(t,"x","maxPool"),s=o,u=!1;3===o.rank&&(u=!0,s=o.as4D(1,o.shape[0],o.shape[1],o.shape[2])),C(Oa(a,i),function(){return"Error in pool: Either strides or dilations must be 1. Got strides "+a+" and dilations '"+i+"'"});var c,l=ma(s.shape,e,a,i,r),f=[l.dilationHeight,l.dilationWidth];c="same"===r?function(t,e){var n=t.map(function(t,n){return t+(t-1)*(e[n]-1)}).map(function(t){return t-1}),r=n.map(function(t){return Math.floor(t/2)}),i=n.map(function(t,e){return t-r[e]});return n.map(function(t,e){return[r[e],i[e]]})}([l.filterHeight,l.filterWidth],f):[[0,0],[0,0]];var d=1===f[0]&&1===f[1],h=function(t,e,n){var r=n.map(function(t){return t[0]}),i=n.map(function(t){return t[1]}),a=t.concat(r,i),o=e.map(function(t,e){return(t-a[e]%t)%t}),s=i.map(function(t,e){return t+o[e]});return[e.map(function(t,e){return[r[e],s[e]]}),e.map(function(t,e){return[0,o[e]]})]}([l.inHeight,l.inWidth],f,c),p=h[0],m=h[1],g=d?r:"valid",v=d?s:hr(s,f,p),y=("avg"===n?function(){return xc(v,e,a,1,g)}:function(){return bc(v,e,a,1,g)})(),b=d?y:sr(y,f,m);return u?b.as3D(b.shape[1],b.shape[2],b.shape[3]):b}}),Ec=Dn({maxPool3d_:function(t,e,n,r,i,a,o){void 0===a&&(a="NDHWC");var s=xn(t,"x","maxPool3d"),u=s,c=!1;4===s.rank&&(c=!0,u=s.as5D(1,s.shape[0],s.shape[1],s.shape[2],s.shape[3])),null==o&&(o=[1,1,1]),C(5===u.rank,function(){return"Error in maxPool3d: x must be rank 5 but got rank "+u.rank+"."}),C("NDHWC"===a,function(){return"Error in maxPool3d: Only NDHWC is currently supported, but got dataFormat of "+a}),C(Oa(n,o),function(){return"Error in maxPool3d: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+o+"'"}),null!=i&&C(M(r),function(){return"Error in maxPool3d: pad must be an integer when using, dimRoundingMode "+i+" but got pad "+r+"."});var l=ga(u.shape,e,n,o,r,i,a),f=Wt.runKernelFunc(function(t,e){var n=t.maxPool3d(u,l);return e([u,n]),n},{x:u},function(t,a){var s=a[0],u=a[1];return{x:function(){return function(t,e,n,r,i,a,o,s){var u=xn(t,"dy","maxPool3dBackprop"),c=xn(e,"input","maxPool3dBackprop"),l=xn(n,"output","maxPool3dBackprop"),f=u,d=c,h=l,p=!1;4===c.rank&&(p=!0,f=u.as5D(1,u.shape[0],u.shape[1],u.shape[2],u.shape[3]),d=c.as5D(1,c.shape[0],c.shape[1],c.shape[2],c.shape[3]),h=l.as5D(1,l.shape[0],l.shape[1],l.shape[2],l.shape[3])),C(5===f.rank,function(){return"Error in maxPool3dBackprop: dy must be rank 5 but got rank "+f.rank+"."}),C(5===d.rank,function(){return"Error in maxPool3dBackprop: input must be rank 5 but got rank "+d.rank+"."}),C(5===h.rank,function(){return"Error in maxPool3dBackprop: output must be rank 5 but got rank "+h.rank+"."}),null==a&&(a=[1,1,1]),C(Oa(i,a),function(){return"Error in maxPool3dBackprop: Either strides or dilations must be 1. Got strides "+i+" and dilations '"+a+"'"}),null!=s&&C(M(o),function(){return"Error in maxPool3dBackprop: pad must be an integer when using, dimRoundingMode "+s+" but got pad "+o+"."});var m=ga(d.shape,r,i,a,o,s),g=Wt.runKernelFunc(function(t){return t.maxPool3dBackprop(f,d,h,m)},{dy5D:f,input5D:d});return p?g.as4D(g.shape[1],g.shape[2],g.shape[3],g.shape[4]):g}(t,s,u,e,n,o,r,i)}}});return c?f.as4D(f.shape[1],f.shape[2],f.shape[3],f.shape[4]):f}}),Oc=Dn({avgPool3d_:function(t,e,n,r,i,a,o){void 0===a&&(a="NDHWC");var s=xn(t,"x","avgPool3d","float32"),u=s,c=!1;4===s.rank&&(c=!0,u=s.as5D(1,s.shape[0],s.shape[1],s.shape[2],s.shape[3])),null==o&&(o=[1,1,1]),C(5===u.rank,function(){return"Error in avgPool3d: x must be rank 5 but got rank "+u.rank+"."}),C("NDHWC"===a,function(){return"Error in avgPool3d: Only NDHWC is currently supported, but got dataFormat of "+a}),C(Oa(n,o),function(){return"Error in avgPool3d: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+o+"'"}),null!=i&&C(M(r),function(){return"Error in avgPool3d: pad must be an integer when using, dimRoundingMode "+i+" but got pad "+r+"."});var l=ga(u.shape,e,n,o,r,i,a),f=Wt.runKernelFunc(function(t){return t.avgPool3d(u,l)},{x:u},function(t){return{x:function(){return function(t,e,n,r,i,a,o){var s=xn(t,"dy","avgPool3dBackprop"),u=xn(e,"input","avgPool3dBackprop"),c=s,l=u,f=!1;4===u.rank&&(f=!0,c=s.as5D(1,s.shape[0],s.shape[1],s.shape[2],s.shape[3]),l=u.as5D(1,u.shape[0],u.shape[1],u.shape[2],u.shape[3])),C(5===c.rank,function(){return"Error in avgPool3dBackprop: dy must be rank 5 but got rank "+c.rank+"."}),C(5===l.rank,function(){return"Error in avgPool3dBackprop: input must be rank 5 but got rank "+l.rank+"."}),null==i&&(i=[1,1,1]),C(Oa(r,i),function(){return"Error in avgPool3dBackprop: Either strides or dilations must be 1. Got strides "+r+" and dilations '"+i+"'"}),null!=o&&C(M(a),function(){return"Error in maxPool3dBackprop: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+a+"."});var d=ga(l.shape,n,r,i,a,o),h=Wt.runKernelFunc(function(t){return t.avgPool3dBackprop(c,l,d)},{dy5D:c,input5D:l});return f?h.as4D(h.shape[1],h.shape[2],h.shape[3],h.shape[4]):h}(t,u,e,n,o,r,i)}}});return f=f.cast(u.dtype),c?f.as4D(f.shape[1],f.shape[2],f.shape[3],f.shape[4]):f}}),Sc=Dn({maxPoolWithArgmax_:function(t,e,n,r,i){void 0===i&&(i=!1);var a=xn(t,"x","maxPoolWithArgmax"),o={filterSize:e,strides:n,pad:r,includeBatchInIndex:i},s=Wt.runKernel("MaxPoolWithArgmax",{x:a},o);return{result:s[0],indexes:s[1]}}}),Cc=Dn({slice_:function(t,e,n){var r,i,a=xn(t,"x","slice");if(0===a.rank)throw new Error("Slicing scalar is not possible");(r="number"==typeof e?[e].concat(new Array(a.rank-1).fill(0)):e.length<a.rank?e.concat(new Array(a.rank-e.length).fill(0)):e.slice()).forEach(function(t){C(-1!==t,function(){return"slice() does not support negative begin indexing."})}),i=(i=null==n?new Array(a.rank).fill(-1):"number"==typeof n?[n].concat(new Array(a.rank-1).fill(-1)):n.length<a.rank?n.concat(new Array(a.rank-n.length).fill(-1)):n).map(function(t,e){return t>=0?t:(C(-1===t,function(){return"Negative size values should be exactly -1 but got "+t+" for the slice() size at index "+e+"."}),a.shape[e]-r[e])}),Ki(a,r,i);var o=a.shape,s={begin:r,size:i};return Wt.runKernelFunc(function(t){return t.slice(a,r,i)},{x:a},function(t){for(var e=[],n=0;n<t.rank;n++)e.push([r[n],o[n]-r[n]-i[n]]);return{x:function(){return hu(t,e)}}},"Slice",s)}}),Ac=Dn({slice1d_:function(t,e,n){var r=xn(t,"x","slice1d");return C(1===r.rank,function(){return"slice1d expects a rank-1 tensor, but got a rank-"+r.rank+" tensor"}),Cc(r,[e],[n])}}),Nc=Dn({slice2d_:function(t,e,n){var r=xn(t,"x","slice2d");return C(2===r.rank,function(){return"slice2d expects a rank-2 tensor, but got a rank-"+r.rank+" tensor"}),Cc(r,e,n)}}),Tc=Dn({slice3d_:function(t,e,n){var r=xn(t,"x","slice3d");return C(3===r.rank,function(){return"slice3d expects a rank-3 tensor, but got a rank-"+r.rank+" tensor"}),Cc(r,e,n)}}),Ic=Dn({slice4d_:function(t,e,n){var r=xn(t,"x","slice4d");return C(4===r.rank,function(){return"slice4d expects a rank-4 tensor, but got a rank-"+r.rank+" tensor"}),Cc(r,e,n)}});function Dc(t,e,n,r,i){return e.rank<n.rank&&(e=e.reshape(On(e.shape,r))),t.rank<n.rank&&(t=t.reshape(On(t.shape,r))),{x:function(){var r=t.mul(n.equal(e).cast(t.dtype));return null==i?r:r.transpose(i)}}}var Mc=Dn({all_:function(t,e,n){void 0===e&&(e=null),void 0===n&&(n=!1);var r=xn(t,"x","all","bool"),i=z(e,r.shape),a=i,o=Cn(a,r.rank);null!=o&&(r=r.transpose(o),a=Nn(a.length,r.rank));var s=Wt.runKernelFunc(function(t){return t.all(r,a)},{$x:r});if(n){var u=On(s.shape,i);return s.reshape(u)}return s}}),Rc=Dn({any_:function(t,e,n){void 0===e&&(e=null),void 0===n&&(n=!1);var r=xn(t,"x","any","bool"),i=z(e,r.shape),a=i,o=Cn(a,r.rank);null!=o&&(r=r.transpose(o),a=Nn(a.length,r.rank));var s=Wt.runKernelFunc(function(t){return t.any(r,a)},{$x:r});if(n){var u=On(s.shape,i);return s.reshape(u)}return s}}),Fc=Dn({argMax_:function(t,e){void 0===e&&(e=0);var n=xn(t,"x","argMax");null==e&&(e=0);var r=z(e,n.shape),i=Cn(r,n.rank);null!=i&&(n=n.transpose(i),r=Nn(r.length,n.rank));var a={axis:r[0]},o=[n];return Wt.runKernelFunc(function(t,e){var i=t.argMax(n,r[0]);return e([n]),i},{x:n},function(t,e){var n=e[0];return{x:function(){return Zn(n)}}},"ArgMax",a,o)}}),jc=Dn({argMin_:function(t,e){void 0===e&&(e=0);var n=xn(t,"x","argMin");null==e&&(e=0);var r=z(e,n.shape),i=Cn(r,n.rank);return null!=i&&(n=n.transpose(i),r=Nn(r.length,n.rank)),Wt.runKernelFunc(function(t,e){var i=t.argMin(n,r[0]);return e([n]),i},{$x:n},function(t,e){var n=e[0];return{$x:function(){return Zn(n)}}})}}),Pc=Dn({logSumExp_:function(t,e,n){void 0===e&&(e=null),void 0===n&&(n=!1);var r=xn(t,"x","logSumExp"),i=z(e,r.shape),a=r.max(i,!0),o=r.sub(a).exp().sum(i).log(),s=a.reshape(o.shape).add(o);if(n){var u=On(s.shape,i);return s.reshape(u)}return s}}),Lc=Dn({max_:function(t,e,n){void 0===e&&(e=null),void 0===n&&(n=!1);var r=xn(t,"x","max"),i=r,a=z(e,r.shape),o=a,s=Cn(o,r.rank);null!=s&&(r=r.transpose(s),o=Nn(o.length,r.rank));var u=[r],c=Wt.runKernelFunc(function(t,e){var n=t.max(r,o);return e([i,n]),n},{x:r},function(t,e){return Dc(t,e[1],e[0],a,s)},"Max",{axes:o},u,[!0]);if(n){var l=On(c.shape,a);c=c.reshape(l)}return c}}),zc=Dn({mean_:function(t,e,n){void 0===e&&(e=null),void 0===n&&(n=!1);var r=xn(t,"x","mean"),i=z(e,r.shape),a=I(En(r.shape,i)[1]);return sa(function(t){var r=Ln(a);return{value:(r.dtype===t.dtype?t:t.cast(r.dtype)).div(r).sum(e,n),gradFunc:function(e){var n=t.shape.slice();return i.forEach(function(t){n[t]=1}),e.reshape(n).mul(Gn(t.shape,"float32")).div(a)}}})(r)}}),Bc=Dn({min_:function(t,e,n){void 0===e&&(e=null),void 0===n&&(n=!1);var r=xn(t,"x","min"),i=r,a=z(e,r.shape),o=a,s=Cn(o,r.rank);null!=s&&(r=r.transpose(s),o=Nn(o.length,r.rank));var u=[r],c=Wt.runKernelFunc(function(t,e){var n=t.min(r,o);return e([i,n]),n},{x:r},function(t,e){return Dc(t,e[1],e[0],a,s)},"Min",{axes:o},u,[!0]);if(n){var l=On(c.shape,a);c=c.reshape(l)}return c}}),Uc=Dn({moments_:function(t,e,n){void 0===e&&(e=null),void 0===n&&(n=!1);var r=z(e,(t=xn(t,"x","moments")).shape),i=t.mean(r,n),a=i.shape;return n||(a=On(i.shape,r)),{mean:i,variance:t.toFloat().sub(i.reshape(a)).square().mean(r,n)}}}),Wc=Dn({sum_:function(t,e,n){void 0===e&&(e=null),void 0===n&&(n=!1);var r=xn(t,"x","sum");"bool"===r.dtype&&(r=r.toInt());var i=z(e,r.shape);return sa(function(t){var e=Cn(i,t.rank),r=i,a=t;null!=e&&(a=t.transpose(e),r=Nn(r.length,t.rank));var o=function(e){var n=t.shape.slice();return i.forEach(function(t){n[t]=1}),e.reshape(n).mul(Gn(t.shape,"float32"))},s={axes:r},u=Wt.runKernelFunc(function(t){return t.sum(a,r)},{x:a},function(t){return{x:function(){return o(t)}}},"Sum",s);if(n){var c=On(u.shape,i);u=u.reshape(c)}return{value:u,gradFunc:o}})(r)}}),Vc=Dn({prod_:function(t,e,n){void 0===e&&(e=null),void 0===n&&(n=!1);var r=xn(t,"x","prod");"bool"===r.dtype&&(r=r.toInt());var i=z(e,r.shape),a=Cn(i,r.rank),o=i,s=r;null!=a&&(s=r.transpose(a),o=Nn(o.length,r.rank));var u=Wt.runKernelFunc(function(t){return t.prod(s,o)},{permutedX:s});if(n){var c=On(u.shape,i);u=u.reshape(c)}return u}}),qc=Dn({elu_:function(t){var e=xn(t,"x","elu");return Wt.runKernelFunc(function(t,n){var r=t.elu(e);return n([r]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return Wt.runKernelFunc(function(e){return e.eluDer(t,n)},{dy:t,y:n})}}})}}),Hc=Dn({leakyRelu_:function(t,e){void 0===e&&(e=.2);var n=xn(t,"x","leakyRelu");return Si(Ln(e).mul(n),n)}}),Gc=Dn({prelu_:function(t,e){var n=xn(t,"x","prelu"),r=xn(e,"alpha","prelu");return Wt.runKernelFunc(function(t,e){var i=t.prelu(n,r);return e([n,r]),i},{x:n,alpha:r},function(t,e){var n=e[0],r=e[1],i=n.greater(0);return{x:function(){return ou(i,t,t.mul(r))},alpha:function(){var e=ou(i,Zn(t),t.mul(n)),a=Br(r.shape,t.shape);return a.length>0&&(e=e.sum(a)),e.reshape(r.shape)}}},"Prelu")}}),$c=Dn({relu_:function(t){var e=xn(t,"x","relu");return"bool"===e.dtype?e.toInt():Wt.runKernelFunc(function(t,n){var r=t.relu(e);return n([e]),r},{x:e},function(t,e){var n=e[0];return{x:function(){return t.mulStrict(n.step().toFloat())}}},"Relu")}}),Kc=Dn({relu6_:function(t){var e=xn(t,"x","relu6");return"bool"===e.dtype?e.toInt():Wt.runKernelFunc(function(t,n){var r=t.relu6(e);return n([e]),r},{x:e},function(t,e){var n=e[0],r=n.lessEqual(6).mul(n.step());return{x:function(){return t.mulStrict(r.toFloat())}}},"Relu6")}}),Xc=Dn({selu_:function(t){var e=xn(t,"x","selu");return Wt.runKernelFunc(function(t,n){var r=t.selu(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){var e=n.greater(Ln(0)),r=Ln(as),i=Ln(os),a=t.mul(i),o=t.mul(r).mul(n.toFloat().exp());return ou(e,a,o)}}})}}),Yc=Dn({localResponseNormalization_:function(t,e,n,r,i){void 0===e&&(e=5),void 0===n&&(n=1),void 0===r&&(r=1),void 0===i&&(i=.5);var a=xn(t,"x","localResponseNormalization");C(4===a.rank||3===a.rank,function(){return"Error in localResponseNormalization: x must be rank 3 or 4 but got\n rank "+a.rank+"."}),C(M(e),function(){return"Error in localResponseNormalization: depthRadius must be an integer but got depthRadius "+e+"."});var o=a,s=!1;3===a.rank&&(s=!0,o=a.as4D(1,a.shape[0],a.shape[1],a.shape[2]));var u=Wt.runKernelFunc(function(t,a){var s=t.localResponseNormalization4D(o,e,n,r,i);return a([o,s]),s},{x4D:o},function(t,a){var o=a[0],s=a[1];return{x4D:function(){return Wt.runKernelFunc(function(a){return a.LRNGrad(t,o,s,e,n,r,i)},{})}}});return s?u.as3D(u.shape[1],u.shape[2],u.shape[3]):u}}),Jc=Dn({norm_:function(t,e,n,r){void 0===e&&(e="euclidean"),void 0===n&&(n=null),void 0===r&&(r=!1);var i=function t(e,n,r){if(void 0===r&&(r=null),0===e.rank)return e.abs();if(1!==e.rank&&null===r)return t(e.reshape([-1]),n,r);if(1===e.rank||"number"==typeof r||Array.isArray(r)&&1===r.length){if(1===n)return e.abs().sum(r);if(n===1/0)return e.abs().max(r);if(n===-1/0)return e.abs().min(r);if("euclidean"===n||2===n)return e.abs().pow(Ln(2,"int32")).sum(r).sqrt();throw new Error("Error in norm: invalid ord value: "+n)}if(Array.isArray(r)&&2===r.length){if(1===n)return e.abs().sum(r[0]).max(r[1]-1);if(n===1/0)return e.abs().sum(r[1]).max(r[0]);if(n===-1/0)return e.abs().sum(r[1]).min(r[0]);if("fro"===n||"euclidean"===n)return e.square().sum(r).sqrt();throw new Error("Error in norm: invalid ord value: "+n)}throw new Error("Error in norm: invalid axis: "+r)}(t=xn(t,"x","norm"),e,n),a=i.shape;if(r){var o=z(n,t.shape);a=On(i.shape,o)}return i.reshape(a)}}),Zc=Dn({basicLSTMCell_:function(t,e,n,r,i,a){var o=xn(t,"forgetBias","basicLSTMCell"),s=xn(e,"lstmKernel","basicLSTMCell"),u=xn(n,"lstmBias","basicLSTMCell"),c=xn(r,"data","basicLSTMCell"),l=xn(i,"c","basicLSTMCell"),f=xn(a,"h","basicLSTMCell"),d=c.concat(f,1).matMul(s).add(u),h=d.shape[0],p=d.shape[1]/4,m=[h,p],g=d.slice([0,0],m),v=d.slice([0,p],m),y=d.slice([0,2*p],m),b=d.slice([0,3*p],m),x=g.sigmoid().mulStrict(v.tanh()).addStrict(l.mulStrict(o.add(y).sigmoid()));return[x,x.tanh().mulStrict(b.sigmoid())]}}),Qc=Dn({multiRNNCell_:function(t,e,n,r){for(var i=xn(e,"data","multiRNNCell"),a=wn(n,"c","multiRNNCell"),o=wn(r,"h","multiRNNCell"),s=i,u=[],c=0;c<t.length;c++){var l=t[c](s,a[c],o[c]);u.push(l[0]),u.push(l[1]),s=l[1]}var f=[],d=[];for(c=0;c<u.length;c+=2)f.push(u[c]),d.push(u[c+1]);return[f,d]}}),tl=Dn({movingAverage_:function(t,e,n,r,i){void 0===i&&(i=!0);var a=xn(t,"v","movingAverage"),o=xn(e,"x","movingAverage"),s=xn(n,"decay","movingAverage");jt(a,o),C(D(a.shape,o.shape),function(){return"Shape mismatch in v and x"});var u=Ln(1),c=u.sub(s),l=o.sub(a).mul(c);if(i){C(null!=r,function(){return"When using zeroDebias: true, step is required."});var f=xn(r,"step","movingAverage");l=l.div(u.sub(Ri(s,f)))}return a.add(l)}}),el=Dn({stridedSlice_:function(t,e,n,r,i,a,o,s,u){if(void 0===i&&(i=0),void 0===a&&(a=0),void 0===o&&(o=0),void 0===s&&(s=0),void 0===u&&(u=0),null==r&&(r=new Array(e.length)),0!==o)throw new Error("ellipsis mask is not yet supported");var c=xn(t,"x","stridedSlice"),l=Xi(s),f=c.shape.slice();l.forEach(function(t){e[t]=0,n[t]=1,f.splice(t,0,1)}),c=c.reshape(f);for(var d=0;d<c.rank;d++)e[d]=Ji(i,e,r,c.shape,d),n[d]=Zi(a,n,r,c.shape,d),r[d]=r[d]||1;var h=Xi(u);h.forEach(function(t){n[t]=e[t]+1,r[t]=1});var p=Yi(e,n,r),m=p.filter(function(t,e){return-1===h.indexOf(e)});return r.every(function(t){return 1===t})?Cc(c,e,p).reshape(m):Wt.runKernelFunc(function(t){return t.stridedSlice(c,e,n,r)},{$x:c}).reshape(m)}}),nl=Dn({topk_:function(t,e,n){void 0===e&&(e=1),void 0===n&&(n=!0);var r=xn(t,"x","topk");if(0===r.rank)throw new Error("topk() expects the input to be of rank 1 or higher");var i=r.shape[r.shape.length-1];if(e>i)throw new Error("'k' passed to topk() must be <= the last dimension ("+i+") but got "+e);var a=Wt.runKernelFunc(function(t){return t.topk(r,e,n)},{$x:r});return{values:a[0],indices:a[1]}}}),rl=Dn({scatterND_:function(t,e,n){var r=xn(t,"indices","scatterND","int32"),i=xn(e,"updates","scatterND");return Hi(i,r,n),Wt.runKernelFunc(function(t){return t.scatterND(r,i,n)},{indices:r,updates:i},null,"ScatterNd",{shape:n})}}),il=Dn({fft_:function(t){C("complex64"===t.dtype,function(){return"The dtype for tf.spectral.fft() must be complex64 but got "+t.dtype+"."});var e=t.shape[t.shape.length-1],n=t.size/e,r=t.as2D(n,e);return Wt.runKernelFunc(function(t){return t.fft(r)},{input:t}).reshape(t.shape)}}),al=Dn({ifft_:function(t){C("complex64"===t.dtype,function(){return"The dtype for tf.spectral.ifft() must be complex64 but got "+t.dtype+"."});var e=t.shape[t.shape.length-1],n=t.size/e,r=t.as2D(n,e);return Wt.runKernelFunc(function(t){return t.ifft(r)},{input:t}).reshape(t.shape)}}),ol=Dn({rfft_:function(t,e){C("float32"===t.dtype,function(){return"The dtype for rfft() must be real value but got "+t.dtype});var n,r=t.shape[t.shape.length-1],i=t.size/r;if(null!=e&&e<r){var a=t.shape.map(function(t){return 0}),o=t.shape.map(function(t){return t});o[t.shape.length-1]=e,n=t.slice(a,o),r=e}else if(null!=e&&e>r){var s=t.shape.map(function(t){return t});s[t.shape.length-1]=e-r,n=t.concat($n(s),t.shape.length-1),r=e}else n=t;var u=n.zerosLike(),c=Mn(n,u).as2D(i,r),l=il(c),f=Math.floor(r/2)+1,d=Rn(l),h=Fn(l),p=d.split([f,r-f],d.shape.length-1),m=h.split([f,r-f],h.shape.length-1),g=n.shape.slice();return g[n.shape.length-1]=f,Mn(p[0],m[0]).reshape(g)}}),sl=Dn({irfft_:function(t){var e=t.shape[t.shape.length-1],n=t.size/e;if(e<=2){var r=t.as2D(n,e),i=al(r);return Rn(i)}var a=[n,2*(e-1)],o=Rn(t).as2D(n,e),s=Fn(t).as2D(n,e),u=o.slice([0,1],[n,e-2]).reverse(1),c=s.slice([0,1],[n,e-2]).reverse(1).mul(Ln(-1)),l=o.concat(u,1),f=s.concat(c,1);return r=Mn(l,f).as2D(a[0],a[1]),i=al(r),Rn(i)}}),ul=Object.freeze({fft:il,ifft:al,rfft:ol,irfft:sl}),cl=Dn({sparseToDense_:function(t,e,n,r){void 0===r&&(r=0);var i=xn(t,"sparseIndices","sparseToDense","int32"),a=xn(e,"sparseValues","sparseToDense"),o=xn(r,"defaultValue","sparseToDense",a.dtype);return function(t,e,n,r){if("int32"!==t.dtype)throw new Error("tf.sparseToDense() expects the indices to be int32 type, but the dtype was "+t.dtype+".");if(t.rank>2)throw new Error("sparseIndices should be a scalar, vector, or matrix, but got shape "+t.shape+".");var i=t.rank>0?t.shape[0]:1,a=t.rank>1?t.shape[1]:1;if(n.length!==a)throw new Error("outputShape has incorrect number of elements:, "+n.length+", should be: "+a+".");var o=e.size;if(0!==e.rank&&(1!==e.rank||o!==i))throw new Error("sparseValues has incorrect shape "+e.shape+", should be [] or ["+i+"]");if(e.dtype!==r.dtype)throw new Error("sparseValues.dtype must match defaultValues.dtype")}(i,a,n,o),Wt.runKernelFunc(function(t){return t.sparseToDense(i,a,n,o)},{$sparseIndices:i,$sparseValues:a,$defaultValue:o})}}),ll=Dn({gatherND_:function(t,e){var n=xn(e,"indices","gatherND","int32"),r=xn(t,"x","gatherND");return Wt.runKernelFunc(function(t){return t.gatherND(r,n)},{x:r,indices:n},null,"GatherNd")}}),fl=Dn({diag_:function(t){var e=xn(t,"x","diag").flatten(),n=t.shape.concat(t.shape);return Wt.runKernelFunc(function(t){return t.diag(e)},{$x:e}).reshape(n)}}),dl=Dn({dropout_:function(t,e,n,r){var i=xn(t,"x","dropout");if(C("float32"===i.dtype,function(){return"x has to be a floating point tensor since it's going to be scaled, but got a "+i.dtype+" tensor instead."}),C(e>=0&&e<1,function(){return"rate must be a float in the range [0, 1), but got "+e+"."}),0===e)return t instanceof Ot?i.clone():i;var a=function(t,e){if(null==e)return t.shape.slice();if(D(t.shape,e))return e;if(t.shape.length===e.length){for(var n=[],r=0;r<t.shape.length;r++)null==e[r]&&null!=t.shape[r]?n.push(t.shape[r]):n.push(e[r]);return n}return e}(i,n),o=1-e,s=Tu(a,0,1,"float32",r).add(o).floor().div(o);return i.mul(s)}});function hl(t,e,n){for(var r=1-t%2,i=new Float32Array(t),a=0;a<t;++a){var o=2*Math.PI*a/(t+r-1);i[a]=e-n*Math.cos(o)}return zn(i,"float32")}var pl,ml=Dn({hannWindow_:function(t){return hl(t,.5,.5)}}),gl=Dn({hammingWindow_:function(t){return hl(t,.54,.46)}}),vl=Dn({frame_:function(t,e,n,r,i){void 0===r&&(r=!1),void 0===i&&(i=0);for(var a=0,o=[];a+e<=t.size;)o.push(Cc(t,a,e)),a+=n;if(r)for(;a<t.size;){var s=a+e-t.size,u=Qn([Cc(t,a,e-s),Kn([s],i)]);o.push(u),a+=n}return 0===o.length?Bn([],[0,e]):Qn(o).as2D(o.length,e)}}),yl=Dn({stft_:function(t,e,n,r,i){var a;void 0===i&&(i=ml),null==r&&(a=e,r=Math.floor(Math.pow(2,Math.ceil(Math.log(a)/Math.log(2)))));for(var o=vl(t,e,n),s=Di(o,i(e)),u=[],c=0;c<o.shape[0];c++)u.push(ol(s.slice([c,0],[1,e]),r));return Qn(u)}}),bl=Object.freeze({hannWindow:ml,hammingWindow:gl,frame:vl,stft:yl}),xl=function(t,e,n){return void 0===n&&(n=1),u(this,void 0,void 0,function(){var r,i,a,o,s,u,l,f,d,h,p,m,g,v;return c(this,function(c){switch(c.label){case 0:return r=xn(t,"predictions","inTopK"),i=xn(e,"targets","inTopK"),C(r.rank>1,function(){return"inTopK() expects the predictions to be of rank 2 or higher, but got "+r.rank}),C(r.rank-1===i.rank,function(){return"predictions rank should be 1 larger than targets rank, but got predictions rank "+r.rank+" and targets rank "+i.rank}),A(r.shape.slice(0,r.shape.length-1),i.shape,"predictions's shape should be align with the targets' shape, except the last dimension."),a=r.shape[r.shape.length-1],C(n>0&&n<=a,function(){return"'k' passed to inTopK() must be > 0 && <= the predictions last dimension ("+a+"), but got "+n}),[4,r.data()];case 1:return o=c.sent(),[4,i.data()];case 2:for(s=c.sent(),u=[o.length/a,a],f=u[1],d=U("bool",l=u[0]),h=0;h<l;h++){for(p=h*f,m=o.subarray(p,p+f),g=[],v=0;v<m.length;v++)g.push({value:m[v],index:v});for(g.sort(function(t,e){return e.value-t.value}),d[h]=0,v=0;v<n;v++)if(g[v].index===s[h]){d[h]=1;break}}return t!==r&&r.dispose(),e!==i&&i.dispose(),[2,jn(d,i.shape,"bool")]}})})};!function(t){t[t.NONE=0]="NONE",t[t.MEAN=1]="MEAN",t[t.SUM=2]="SUM",t[t.SUM_BY_NONZERO_WEIGHTS=3]="SUM_BY_NONZERO_WEIGHTS"}(pl||(pl={}));var wl=Dn({absoluteDifference_:function(t,e,n,r){void 0===r&&(r=pl.SUM_BY_NONZERO_WEIGHTS);var i=xn(t,"labels","absoluteDifference"),a=xn(e,"predictions","absoluteDifference"),o=null;null!=n&&(o=xn(n,"weights","absoluteDifference")),A(i.shape,a.shape,"Error in absoluteDifference: ");var s=i.sub(a).abs();return kl(s,o,r)}}),kl=Dn({computeWeightedLoss_:function(t,e,n){void 0===n&&(n=pl.SUM_BY_NONZERO_WEIGHTS);var r=xn(t,"losses","computeWeightedLoss"),i=null;null!=e&&(i=xn(e,"weights","computeWeightedLoss"));var a=null==i?r:r.mul(i);if(n===pl.NONE)return a;if(n===pl.SUM)return a.sum();if(n===pl.MEAN){if(null==i)return a.mean();var o=r.size/i.size,s=a.sum().div(i.sum());return o>1?s.div(Ln(o)):s}if(n===pl.SUM_BY_NONZERO_WEIGHTS){if(null==i)return a.sum().div(Ln(r.size));var u=i.mul(Gn(r.shape)).notEqual(Ln(0)).sum().toFloat();return a.sum().div(u)}throw Error("Unknown reduction: "+n)}}),_l=Dn({cosineDistance_:function(t,e,n,r,i){void 0===i&&(i=pl.SUM_BY_NONZERO_WEIGHTS);var a=xn(t,"labels","cosineDistance"),o=xn(e,"predictions","cosineDistance"),s=null;null!=r&&(s=xn(r,"weights","cosineDistance")),A(a.shape,o.shape,"Error in cosineDistance: ");var u=Ln(1).sub(a.mul(o).sum(n,!0));return kl(u,s,i)}}),El=Dn({hingeLoss_:function(t,e,n,r){void 0===r&&(r=pl.SUM_BY_NONZERO_WEIGHTS);var i=xn(t,"labels","hingeLoss"),a=xn(e,"predictions","hingeLoss"),o=null;null!=n&&(o=xn(n,"weights","hingeLoss")),A(i.shape,a.shape,"Error in hingeLoss: ");var s=Ln(1);i=Ln(2).mul(i).sub(s);var u=s.sub(i.mul(a)).relu();return kl(u,o,r)}}),Ol=Dn({huberLoss_:function(t,e,n,r,i){void 0===r&&(r=1),void 0===i&&(i=pl.SUM_BY_NONZERO_WEIGHTS);var a=xn(t,"labels","huberLoss"),o=xn(e,"predictions","huberLoss"),s=null;null!=n&&(s=xn(n,"weights","huberLoss")),A(a.shape,o.shape,"Error in huberLoss: ");var u=Ln(r),c=o.sub(a).abs(),l=Ai(c,u),f=c.sub(l),d=Ln(.5).mul(l.square()).add(u.mul(f));return kl(d,s,i)}}),Sl=Dn({logLoss_:function(t,e,n,r,i){void 0===r&&(r=1e-7),void 0===i&&(i=pl.SUM_BY_NONZERO_WEIGHTS);var a=xn(t,"labels","logLoss"),o=xn(e,"predictions","logLoss"),s=null;null!=n&&(s=xn(n,"weights","logLoss")),A(a.shape,o.shape,"Error in logLoss: ");var u=Ln(1),c=Ln(r),l=a.mul(o.add(c).log()).neg().sub(u.sub(a).mul(u.sub(o).add(c).log()));return kl(l,s,i)}}),Cl=Dn({meanSquaredError_:function(t,e,n,r){void 0===r&&(r=pl.SUM_BY_NONZERO_WEIGHTS);var i=xn(t,"labels","meanSquaredError"),a=xn(e,"predictions","meanSquaredError"),o=null;null!=n&&(o=xn(n,"weights","meanSquaredError")),A(i.shape,a.shape,"Error in meanSquaredError: ");var s=i.squaredDifference(a);return kl(s,o,r)}}),Al=Dn({sigmoidCrossEntropy_:function(t,e,n,r,i){void 0===r&&(r=0),void 0===i&&(i=pl.SUM_BY_NONZERO_WEIGHTS);var a=xn(t,"multiClassLabels","sigmoidCrossEntropy"),o=xn(e,"logits","sigmoidCrossEntropy"),s=null;if(null!=n&&(s=xn(n,"weights","sigmoidCrossEntropy")),A(a.shape,o.shape,"Error in sigmoidCrossEntropy: "),r>0){var u=Ln(r),c=Ln(1),l=Ln(.5);a=a.mul(c.sub(u)).add(l.mul(u))}var f=function(t,e){var n=xn(t,"labels","sigmoidCrossEntropyWithLogits"),r=xn(e,"logits","sigmoidCrossEntropyWithLogits");A(n.shape,r.shape,"Error in sigmoidCrossEntropyWithLogits: ");var i=r.relu(),a=r.mul(n),o=r.abs().neg().exp().log1p();return i.sub(a).add(o)}(a,o);return kl(f,s,i)}}),Nl=Dn({softmaxCrossEntropy_:function(t,e,n,r,i){void 0===r&&(r=0),void 0===i&&(i=pl.SUM_BY_NONZERO_WEIGHTS);var a=xn(t,"onehotLabels","softmaxCrossEntropy"),o=xn(e,"logits","softmaxCrossEntropy"),s=null;if(null!=n&&(s=xn(n,"weights","softmaxCrossEntropy")),A(a.shape,o.shape,"Error in softmaxCrossEntropy: "),r>0){var u=Ln(r),c=Ln(1),l=Ln(a.shape[1]);a=a.mul(c.sub(u)).add(u.div(l))}var f=function(t,e,n){if(void 0===n&&(n=-1),-1===n&&(n=e.rank-1),n!==e.rank-1)throw Error("Softmax cross entropy along a non-last dimension is not yet supported. Labels / logits was rank "+e.rank+" and dim was "+n);return sa(function(t,e,r){var i=e.logSumExp([n],!0),a=e.toFloat().sub(i);return r([t,a]),{value:a.mul(t).neg().sum([n]),gradFunc:function(t,e){var r=e[0],i=e[1],a=On(t.shape,[n]);return[t.reshape(a).mul(r.toFloat().sub(i.exp())),t.reshape(a).mul(i.exp().sub(r.toFloat()))]}}})(t,e)}(a,o);return kl(f,s,i)}}),Tl=Object.freeze({get Reduction(){return pl},absoluteDifference:wl,computeWeightedLoss:kl,cosineDistance:_l,hingeLoss:El,huberLoss:Ol,logLoss:Sl,meanSquaredError:Cl,sigmoidCrossEntropy:Al,softmaxCrossEntropy:Nl});function Il(t,e){return void 0===e&&(e=!1),Wt.tidy(function(){if(2!==t.shape.length)throw new Error("qr2d() requires a 2D Tensor, but got a "+t.shape.length+"D Tensor.");for(var n=t.shape[0],r=t.shape[1],i=lu(n),a=t.clone(),o=Bn([[1]],[1,1]),s=o.clone(),u=n>=r?r:n,c=function(t){var e,u=a,c=s,l=i;e=Wt.tidy(function(){var e=a.slice([t,t],[n-t,1]),u=e.norm(),c=a.slice([t,t],[1,1]),l=Bn([[-1]]).where(c.greater(0),Bn([[1]])),f=c.sub(l.mul(u)),d=e.div(f);s=1===d.shape[0]?o.clone():o.concat(d.slice([1,0],[d.shape[0]-1,d.shape[1]]),0);var h=l.matMul(f).div(u).neg(),p=a.slice([t,0],[n-t,r]),m=h.mul(s),g=s.transpose();if(0===t)a=p.sub(m.matMul(g.matMul(p)));else{var v=p.sub(m.matMul(g.matMul(p)));a=a.slice([0,0],[t,r]).concat(v,0)}var y=m.transpose(),b=i.slice([0,t],[n,i.shape[1]-t]);if(0===t)i=b.sub(b.matMul(s).matMul(y));else{var x=b.sub(b.matMul(s).matMul(y));i=i.slice([0,0],[n,t]).concat(x,1)}return[s,a,i]}),s=e[0],a=e[1],i=e[2],an([u,c,l])},l=0;l<u;++l)c(l);return!e&&n>r&&(i=i.slice([0,0],[n,r]),a=a.slice([0,0],[r,r])),[i,a]})}var Dl=Dn({bandPart_:function(t,e,n){if(e%1!=0)throw new Error("bandPart(): numLower must be an integer, got "+e+".");if(n%1!=0)throw new Error("bandPart(): numUpper must be an integer, got "+n+".");var r=xn(t,"a","bandPart");if(r.rank<2)throw new Error("bandPart(): Rank must be at least 2, got "+r.rank+".");var i=r.shape,a=r.shape.slice(-2),o=a[0],s=a[1];if(!(e<=o))throw new Error("bandPart(): numLower ("+e+") must not be greater than the number of rows ("+o+").");if(!(n<=s))throw new Error("bandPart(): numUpper ("+n+") must not be greater than the number of columns ("+s+").");e<0&&(e=o),n<0&&(n=s);var u=Yn(0,o,1,"int32").reshape([-1,1]),c=Yn(0,s,1,"int32"),l=Pi(u,c),f=nu(l.lessEqual(Ln(+e,"int32")),l.greaterEqual(Ln(-n,"int32"))),d=$n([o,s],r.dtype);return mr(gr(r.reshape([-1,o,s])).map(function(t){return ou(f,t,d)})).reshape(i)}}),Ml=Dn({gramSchmidt_:function(t){var e;if(Array.isArray(t)){e=!1,C(null!=t&&t.length>0,function(){return"Gram-Schmidt process: input must not be null, undefined, or empty"});for(var n=t[0].shape[0],r=function(e){C(t[e].shape[0]===n,function(){return"Gram-Schmidt: Non-unique lengths found in the input vectors: ("+t[e].shape[0]+" vs. "+n+")"})},i=1;i<t.length;++i)r(i)}else e=!0,t=ir(t,t.shape[0],0).map(function(t){return pr(t,[0])});C(t.length<=t[0].shape[0],function(){return"Gram-Schmidt: Number of vectors ("+t.length+") exceeds number of dimensions ("+t[0].shape[0]+")."});var a=[],o=t,s=function(t){a.push(Wt.tidy(function(){var e=o[t];if(t>0)for(var n=0;n<t;++n){var r=Wc(a[n].mulStrict(e)).mul(a[n]);e=e.sub(r)}return e.div(Jc(e,"euclidean"))}))};for(i=0;i<t.length;++i)s(i);return e?mr(a,0):a}}),Rl=Dn({qr_:function(t,e){if(void 0===e&&(e=!1),t.rank<2)throw new Error("qr() requires input tensor to have a rank >= 2, but got rank "+t.rank);if(2===t.rank)return Il(t,e);var n=t.shape.slice(0,t.shape.length-2).reduce(function(t,e){return t*e}),r=[],i=[];return gr(t.reshape([n,t.shape[t.shape.length-2],t.shape[t.shape.length-1]]),0).forEach(function(t){var n=Il(t,e),a=n[0],o=n[1];r.push(a),i.push(o)}),[mr(r,0).reshape(t.shape),mr(i,0).reshape(t.shape)]}}),Fl=Object.freeze({bandPart:Dl,gramSchmidt:Ml,qr:Rl});function jl(t,e,n,r,i,a){null==r&&(r=.5),null==i&&(i=Number.NEGATIVE_INFINITY),null==a&&(a=0);var o=t.shape[0];return n=Math.min(n,o),C(0<=r&&r<=1,function(){return"iouThreshold must be in [0, 1], but was '"+r+"'"}),C(2===t.rank,function(){return"boxes must be a 2D tensor, but was of rank '"+t.rank+"'"}),C(4===t.shape[1],function(){return"boxes must have 4 columns, but 2nd dimension was "+t.shape[1]}),C(1===e.rank,function(){return"scores must be a 1D tensor"}),C(e.shape[0]===o,function(){return"scores has incompatible shape with boxes. Expected "+o+", but was "+e.shape[0]}),C(0<=a&&a<=1,function(){return"softNmsSigma must be in [0, 1], but was '"+a+"'"}),{maxOutputSize:n,iouThreshold:r,scoreThreshold:i,softNmsSigma:a}}var Pl=Dn({resizeBilinear_:function(t,e,n){void 0===n&&(n=!1);var r=xn(t,"images","resizeBilinear");C(3===r.rank||4===r.rank,function(){return"Error in resizeBilinear: x must be rank 3 or 4, but got rank "+r.rank+"."}),C(2===e.length,function(){return"Error in resizeBilinear: new shape must 2D, but got shape "+e+"."});var i=r,a=!1;3===r.rank&&(a=!0,i=r.as4D(1,r.shape[0],r.shape[1],r.shape[2]));var o=e[0],s=e[1],u=Wt.runKernelFunc(function(t,e){return e([i]),t.resizeBilinear(i,o,s,n)},{x:i},function(t,e){return{x:function(){return Wt.runKernelFunc(function(r){return r.resizeBilinearBackprop(t,e[0],n)},{})}}},"ResizeBilinear",{alignCorners:n,newHeight:o,newWidth:s});return a?u.as3D(u.shape[1],u.shape[2],u.shape[3]):u}}),Ll=Dn({resizeNearestNeighbor_:function(t,e,n){void 0===n&&(n=!1);var r=xn(t,"images","resizeNearestNeighbor");C(3===r.rank||4===r.rank,function(){return"Error in resizeNearestNeighbor: x must be rank 3 or 4, but got rank "+r.rank+"."}),C(2===e.length,function(){return"Error in resizeNearestNeighbor: new shape must 2D, but got shape "+e+"."}),C("float32"===r.dtype||"int32"===r.dtype,function(){return"`images` must have `int32` or `float32` as dtype"});var i=r,a=!1;3===r.rank&&(a=!0,i=r.as4D(1,r.shape[0],r.shape[1],r.shape[2]));var o=e[0],s=e[1],u=Wt.runKernelFunc(function(t,e){return e([i]),t.resizeNearestNeighbor(i,o,s,n)},{batchImages:i},function(t,e){return{batchImages:function(){return Wt.runKernelFunc(function(r){return r.resizeNearestNeighborBackprop(t,e[0],n)},{})}}});return a?u.as3D(u.shape[1],u.shape[2],u.shape[3]):u}}),zl=Dn({nonMaxSuppression_:function(t,e,n,r,i){void 0===r&&(r=.5),void 0===i&&(i=Number.NEGATIVE_INFINITY);var a=xn(t,"boxes","nonMaxSuppression"),o=xn(e,"scores","nonMaxSuppression"),s=jl(a,o,n,r,i);n=s.maxOutputSize,r=s.iouThreshold,i=s.scoreThreshold;var u={maxOutputSize:n,iouThreshold:r,scoreThreshold:i};return Wt.runKernelFunc(function(t){return t.nonMaxSuppression(a,o,n,r,i)},{boxes:a,scores:o},null,"NonMaxSuppressionV3",u)}}),Bl=Dn({nonMaxSuppressionWithScore_:function(t,e,n,r,i,a){void 0===r&&(r=.5),void 0===i&&(i=Number.NEGATIVE_INFINITY),void 0===a&&(a=0);var o=xn(t,"boxes","nonMaxSuppression"),s=xn(e,"scores","nonMaxSuppression"),u=jl(o,s,n,r,i,a),c={maxOutputSize:n=u.maxOutputSize,iouThreshold:r=u.iouThreshold,scoreThreshold:i=u.scoreThreshold,softNmsSigma:a=u.softNmsSigma},l=Wt.runKernel("NonMaxSuppressionV5",{boxes:o,scores:s},c);return{selectedIndices:l[0],selectedScores:l[1]}}}),Ul=Dn({cropAndResize_:function(t,e,n,r,i,a){var o=xn(t,"image","cropAndResize"),s=xn(e,"boxes","cropAndResize","float32"),u=xn(n,"boxInd","cropAndResize","int32");i=i||"bilinear",a=a||0;var c=s.shape[0];return C(4===o.rank,function(){return"Error in cropAndResize: image must be rank 4,but got rank "+o.rank+"."}),C(2===s.rank&&4===s.shape[1],function(){return"Error in cropAndResize: boxes must be have size ["+c+",4] but had shape "+s.shape+"."}),C(1===u.rank&&u.shape[0]===c,function(){return"Error in cropAndResize: boxInd must be have size ["+c+"] but had shape "+s.shape+"."}),C(2===r.length,function(){return"Error in cropAndResize: cropSize must be of length 2, but got length "+r.length+"."}),C(r[0]>=1&&r[1]>=1,function(){return"cropSize must be atleast [1,1], but was "+r}),C("bilinear"===i||"nearest"===i,function(){return"method must be bilinear or nearest, but was "+i}),Wt.runKernelFunc(function(t,e){return t.cropAndResize(o,s,u,r,i,a)},{images:o,boxes:s,boxInd:u},null,"CropAndResize",{method:i,extrapolationValue:a,cropSize:r})}}),Wl=Object.freeze({resizeBilinear:Pl,resizeNearestNeighbor:Ll,nonMaxSuppression:zl,nonMaxSuppressionAsync:function(t,e,n,r,i){return void 0===r&&(r=.5),void 0===i&&(i=Number.NEGATIVE_INFINITY),u(this,void 0,void 0,function(){var a,o,s,u,l,f,d;return c(this,function(c){switch(c.label){case 0:return a=xn(t,"boxes","nonMaxSuppressionAsync"),o=xn(e,"scores","nonMaxSuppressionAsync"),s=jl(a,o,n,r,i),n=s.maxOutputSize,r=s.iouThreshold,i=s.scoreThreshold,[4,Promise.all([a.data(),o.data()])];case 1:return u=c.sent(),l=u[0],f=u[1],d=Pa(l,f,n,r,i),a!==t&&a.dispose(),o!==e&&o.dispose(),[2,d]}})})},nonMaxSuppressionWithScore:Bl,nonMaxSuppressionWithScoreAsync:function(t,e,n,r,i,a){return void 0===r&&(r=.5),void 0===i&&(i=Number.NEGATIVE_INFINITY),void 0===a&&(a=0),u(this,void 0,void 0,function(){var o,s,u,l,f,d,h;return c(this,function(c){switch(c.label){case 0:return o=xn(t,"boxes","nonMaxSuppressionAsync"),s=xn(e,"scores","nonMaxSuppressionAsync"),u=jl(o,s,n,r,i,a),n=u.maxOutputSize,r=u.iouThreshold,i=u.scoreThreshold,a=u.softNmsSigma,[4,Promise.all([o.data(),s.data()])];case 1:return l=c.sent(),f=l[0],d=l[1],h=La(f,d,n,r,i,a),o!==t&&o.dispose(),s!==e&&s.dispose(),[2,h]}})})},cropAndResize:Ul}),Vl=function(t,e){return!(t>0)||"linear"===e},ql=function(t,e,n){if(null==n||"linear"===n)return t;if("relu"===n)return t.mul(e.step());throw new Error("Gradient for activation "+n+" has not been implemented yet.")},Hl=function(t,e){var n=e,r=Br(t.shape,e.shape);return r.length>0&&(n=n.sum(r)),n.reshape(t.shape)},Gl=function(t,e,n){if("linear"===e)return t;if("relu"===e)return $c(t);if("elu"===e)return qc(t);if("relu6"===e)return Kc(t);if("prelu"===e)return Gc(t,n);throw new Error("Unknown fused activation "+e+".")},$l=Dn({fusedMatMul_:function(t){var e,n=t.a,r=t.b,i=t.transposeA,a=void 0!==i&&i,o=t.transposeB,s=void 0!==o&&o,u=t.bias,c=t.activation,l=void 0===c?"linear":c,f=t.preluActivationWeights;if(!1===Vl(Wt.state.gradientDepth,l)){var d=fc(n,r,a,s);return null!=u&&(d=Lr(d,u)),Gl(d,l,f)}var h=xn(n,"a","fused matMul"),p=xn(r,"b","fused matMul");e=Ft(h,p),h=e[0],p=e[1];var m=a?h.shape[h.rank-2]:h.shape[h.rank-1],g=s?p.shape[p.rank-1]:p.shape[p.rank-2],v=a?h.shape[h.rank-1]:h.shape[h.rank-2],y=s?p.shape[p.rank-2]:p.shape[p.rank-1],b=h.shape.slice(0,-2),x=p.shape.slice(0,-2),w=I(b),k=I(x);C(h.rank>=2&&p.rank>=2&&h.rank===p.rank,function(){return"Error in fused matMul: inputs must have the same rank of at least 2, got ranks "+h.rank+" and "+p.rank+"."}),C(D(b,x),function(){return"Error in fused matMul: outer dimensions ("+b+") and ("+x+") of Tensors with shapes "+h.shape+" and "+p.shape+" must match."}),C(m===g,function(){return"Error in fused matMul: inner shapes ("+m+") and ("+g+") of Tensors with shapes "+h.shape+" and "+p.shape+" and transposeA="+a+" and transposeB="+s+" must match."});var _,E,O=h.shape.slice(0,-2).concat([v,y]),S=a?h.as3D(w,m,v):h.as3D(w,v,m),A=s?p.as3D(k,y,g):p.as3D(k,g,y);null!=u&&Ur(O,(_=Ft(_=xn(u,"bias","fused matMul"),h)[0]).shape),null!=f&&(E=xn(f,"prelu weights","fused matMul"));var N={a:S,b:A};null!=u&&(N.bias=_),null!=f&&(N.preluActivationWeights=E);var T=[S,A];return Wt.runKernelFunc(function(t,e){var n=t.fusedBatchMatMul({a:S,b:A,transposeA:a,transposeB:s,bias:_,activation:l,preluActivationWeights:E});return e([S,A,n]),n},N,function(t,e){var n=e[0],r=e[1],i=e[2],o=ql(t,i,l),c={};return null!=u&&(c={bias:function(){return Hl(_,o)}}),a||s?!a&&s?Object.assign({a:function(){return o.matMul(r,!1,!1)},b:function(){return o.matMul(n,!0,!1)}},c):a&&!s?Object.assign({a:function(){return r.matMul(o,!1,!0)},b:function(){return n.matMul(o,!1,!1)}},c):Object.assign({a:function(){return r.matMul(o,!0,!0)},b:function(){return o.matMul(n,!0,!0)}},c):Object.assign({a:function(){return o.matMul(r,!1,!0)},b:function(){return n.matMul(o,!0,!1)}},c)},"_FusedMatMul",{transposeA:a,transposeB:s,activation:l},T,[!0]).reshape(O)}}),Kl=Dn({fusedConv2d_:function(t){var e=t.x,n=t.filter,r=t.strides,i=t.pad,a=t.dataFormat,o=void 0===a?"NHWC":a,s=t.dilations,u=void 0===s?[1,1]:s,c=t.dimRoundingMode,l=t.bias,f=t.activation,d=void 0===f?"linear":f,h=t.preluActivationWeights;if(d=d||"linear",!1===Vl(Wt.state.gradientDepth,d)){var p=ec(e,n,r,i,o,u,c);return null!=l&&(p=Lr(p,l)),Gl(p,d,h)}var m=xn(e,"x","conv2d"),g=xn(n,"filter","conv2d"),v=m,y=!1;3===m.rank&&(y=!0,v=m.as4D(1,m.shape[0],m.shape[1],m.shape[2])),C(4===v.rank,function(){return"Error in fused conv2d: input must be rank 4, but got rank "+v.rank+"."}),C(4===g.rank,function(){return"Error in fused conv2d: filter must be rank 4, but got rank "+g.rank+"."}),null!=c&&C(M(i),function(){return"Error in fused conv2d: pad must be an integer when using, dimRoundingMode "+c+" but got pad "+i+"."}),C(v.shape[3]===g.shape[2],function(){return"Error in conv2d: depth of input ("+v.shape[3]+") must match input depth for filter "+g.shape[2]+"."}),C(Oa(r,u),function(){return"Error in conv2D: Either strides or dilations must be 1. Got strides "+r+" and dilations '"+u+"'"}),C("NHWC"===o,function(){return"Error in conv2d: got dataFormat of "+o+" but only NHWC is currently supported."});var b,x,w=va(v.shape,g.shape,r,u,i,c);null!=l&&(b=Ft(b=xn(l,"bias","fused conv2d"),m)[0],Ur(w.outShape,b.shape)),null!=h&&(x=xn(h,"prelu weights","fused conv2d"));var k={x:v,filter:g};null!=l&&(k.bias=b),null!=h&&(k.preluActivationWeights=x);var _=[g,v],E=Wt.runKernelFunc(function(t,e){var n=t.fusedConv2d({input:v,filter:g,convInfo:w,bias:b,activation:d,preluActivationWeights:x});return e([g,v,n]),n},k,function(t,e){var n=e,a=n[0],o=n[1],s=n[2],c=ql(t,s,d);C(Ea(u),function(){return"Error in gradient of fused conv2D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '"+u+"'"});var f={};return null!=l&&(f={bias:function(){return Hl(b,c)}}),Object.assign({x:function(){return ic(o.shape,c,a,r,i)},filter:function(){return rc(o,c,a.shape,r,i)}},f)},"FusedConv2D",{convInfo:w,activation:d},_,[!0]);return y?E.as3D(E.shape[1],E.shape[2],E.shape[3]):E}}),Xl=Dn({fusedDepthwiseConv2d_:function(t){var e=t.x,n=t.filter,r=t.strides,i=t.pad,a=t.dataFormat,o=void 0===a?"NHWC":a,s=t.dilations,u=void 0===s?[1,1]:s,c=t.dimRoundingMode,l=t.bias,f=t.activation,d=void 0===f?"linear":f,h=t.preluActivationWeights;if(!1===Vl(Wt.state.gradientDepth,d)){var p=ac(e,n,r,i,o,u,c);return null!=l&&(p=Lr(p,l)),Gl(p,d,h)}var m=xn(e,"x","depthwiseConv2d"),g=xn(n,"filter","depthwiseConv2d"),v=m,y=!1;3===m.rank&&(y=!0,v=m.as4D(1,m.shape[0],m.shape[1],m.shape[2])),C(4===v.rank,function(){return"Error in fused depthwiseConv2d: input must be rank 4, but got rank "+v.rank+"."}),C(4===g.rank,function(){return"Error in fused depthwiseConv2d: filter must be rank 4, but got rank "+g.rank+"."}),C(v.shape[3]===g.shape[2],function(){return"Error in fused depthwiseConv2d: number of input channels ("+v.shape[3]+") must match the inChannels dimension in filter "+g.shape[2]+"."}),null==u&&(u=[1,1]),C(Oa(r,u),function(){return"Error in fused depthwiseConv2d: Either strides or dilations must be 1. Got strides "+r+" and dilations '"+u+"'"}),null!=c&&C(M(i),function(){return"Error in fused depthwiseConv2d: pad must be an integer when using dimRoundingMode "+c+" but got pad "+i+"."});var b,x,w=va(v.shape,g.shape,r,u,i,c,!0);null!=l&&(b=Ft(b=xn(l,"bias","fused conv2d"),m)[0],Ur(w.outShape,b.shape)),null!=h&&(x=xn(h,"prelu weights","fused depthwiseConv2d"));var k={x:v,filter:g};null!=l&&(k.bias=b),null!=h&&(k.preluActivationWeights=x);var _=[g,v],E=Wt.runKernelFunc(function(t,e){var n=t.fusedDepthwiseConv2D({input:v,filter:g,convInfo:w,bias:b,activation:d,preluActivationWeights:x});return e([g,v,n]),n},k,function(t,e){C(Ea(u),function(){return"Error in gradient of fused depthwiseConv2d: dilation rates greater than 1 are not yet supported. Got dilations '"+u+"'"});var n=e[0],r=e[1],i=e[2],a=ql(t,i,d),o={};return null!=l&&(o={bias:function(){return Hl(b,a)}}),Object.assign({x:function(){return oc(r.shape,a,n,w)},filter:function(){return sc(r,a,n.shape,w)}},o)},"FusedDepthwiseConv2D",{convInfo:w,activation:d},_,[!0]);return y?E.as3D(E.shape[1],E.shape[2],E.shape[3]):E}}),Yl=Object.freeze({matMul:$l,conv2d:Kl,depthwiseConv2d:Xl}),Jl=Object.freeze({image:Wl,linalg:Fl,losses:Tl,spectral:ul,fused:Yl,signal:bl,add:Lr,addN:Ls,batchNorm:qs,batchNormalization:Vs,batchNorm2d:$s,batchNormalization2d:Gs,batchNorm3d:Ys,batchNormalization3d:Xs,batchNorm4d:Qs,batchNormalization4d:Zs,broadcastTo:tu,clone:eu,div:zi,divNoNan:uu,eye:lu,multinomial:fu,oneHot:du,pad:hu,pad1d:pu,pad2d:mu,pad3d:gu,pad4d:vu,rand:yu,randomGamma:Au,randomNormal:Nu,randomUniform:Tu,square:Iu,squaredDifference:Du,tile:cu,truncatedNormal:Mu,conv1d:tc,conv2d:ec,conv3d:nc,depthwiseConv2d:ac,separableConv2d:uc,conv2dTranspose:cc,conv3dTranspose:lc,op:Dn,booleanMaskAsync:Yu,complex:Mn,real:Rn,imag:Fn,concat:Qn,concat1d:tr,concat2d:er,concat3d:nr,concat4d:rr,split:ir,matMul:fc,dot:dc,outerProduct:hc,reverse:pc,reverse1d:mc,reverse2d:gc,reverse3d:vc,reverse4d:yc,maxPool:wc,avgPool:kc,pool:_c,maxPool3d:Ec,avgPool3d:Oc,maxPoolWithArgmax:Sc,slice:Cc,slice1d:Ac,slice2d:Nc,slice3d:Tc,slice4d:Ic,abs:Wr,acos:Vr,acosh:qr,asin:Hr,asinh:Gr,atan:$r,atanh:Kr,ceil:Xr,clipByValue:Yr,cos:Jr,cosh:Zr,erf:Qr,exp:ti,expm1:ei,floor:ni,log:ri,log1p:ii,logSigmoid:ai,neg:oi,reciprocal:si,round:ui,rsqrt:ci,sigmoid:li,sign:fi,isNaN:di,isInf:hi,isFinite:pi,sin:mi,sinh:gi,softplus:vi,sqrt:yi,step:bi,tan:xi,tanh:wi,all:Mc,any:Rc,argMax:Fc,argMin:jc,logSumExp:Pc,max:Lc,mean:zc,min:Bc,moments:Uc,sum:Wc,prod:Vc,equal:Ru,equalStrict:Fu,greater:ju,greaterEqual:Pu,greaterEqualStrict:Lu,greaterStrict:zu,less:Bu,lessEqual:Uu,lessEqualStrict:Wu,lessStrict:Vu,notEqual:qu,notEqualStrict:Hu,addStrict:ki,atan2:_i,divStrict:Ei,floorDiv:Oi,maximum:Si,maximumStrict:Ci,minimum:Ai,minimumStrict:Ni,mod:Ti,modStrict:Ii,mul:Di,mulStrict:Mi,pow:Ri,powStrict:Fi,squaredDifferenceStrict:ji,sub:Pi,subStrict:Li,elu:qc,leakyRelu:Hc,prelu:Gc,relu:$c,relu6:Kc,selu:Xc,logicalAnd:nu,logicalNot:ru,logicalOr:iu,logicalXor:au,where:ou,whereAsync:su,buffer:ar,print:or,batchToSpaceND:sr,cast:ur,cumsum:cr,depthToSpace:lr,expandDims:fr,reshape:dr,spaceToBatchND:hr,squeeze:pr,stack:mr,unstack:gr,setdiff1dAsync:vr,fill:Kn,linspace:Xn,ones:Gn,range:Yn,scalar:Ln,tensor:jn,tensor1d:zn,tensor2d:Bn,tensor3d:Un,tensor4d:Wn,tensor5d:Vn,tensor6d:qn,variable:Hn,zeros:$n,onesLike:Jn,zerosLike:Zn,transpose:fa,softmax:ca,logSoftmax:la,localResponseNormalization:Yc,norm:Jc,gather:Ku,unsortedSegmentSum:Xu,basicLSTMCell:Zc,multiRNNCell:Qc,movingAverage:tl,stridedSlice:el,topk:nl,scatterND:rl,fft:il,ifft:al,rfft:ol,irfft:sl,sparseToDense:cl,gatherND:ll,diag:fl,dropout:dl,hannWindow:ml,hammingWindow:gl,frame:vl,stft:yl,inTopKAsync:xl});function Zl(t,e){Array.isArray(t)||(t=[t]),t.forEach(function(t){null!=t&&C("complex64"!==t.dtype,function(){return e+" does not support complex64 tensors."})})}function Ql(t,e,n,r,i,a){for(var o=i.strideHeight,s=i.strideWidth,u=i.dilationHeight,c=i.dilationWidth,l=i.effectiveFilterHeight,f=i.effectiveFilterWidth,d=i.padInfo.top,h=i.padInfo.left,p="max"===a?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,m=ar(i.outShape,n),g=m.values,v=i.outShape[1]*i.outShape[2]*i.outShape[3],y=i.outShape[2]*i.outShape[3],b=i.outShape[3],x=0;x<i.batchSize;++x)for(var w=x*v,k=x*r[0],_=0;_<i.inChannels;++_)for(var E=0;E<i.outHeight;++E)for(var O=E*o-d,S=Math.max(0,O),C=Math.min(i.inHeight,l+O),A=w+E*y,N=0;N<i.outWidth;++N){for(var T=N*s-h,I=Math.max(0,T),D=Math.min(i.inWidth,f+T),M=p,R=0,F=0,j=S;j<C;j+=u){for(var P=k+j*r[1],L=I;L<D;L+=c){var z=t[P+L*r[2]+_];"max"===a&&z>M?M=z:"avg"===a&&(R+=z,F++)}if(isNaN(M))break}g[A+N*b+_]="avg"===a?R/F:M}return m}function tf(t,e,n,r,i,a){void 0===i&&(i=!1),void 0===a&&(a=!1);for(var o=ar(r.outShape,"int32"),s=r.strideHeight,u=r.strideWidth,c=r.dilationHeight,l=r.dilationWidth,f=r.effectiveFilterHeight,d=r.effectiveFilterWidth,h=r.padInfo.top,p=r.padInfo.left,m=ar(e,n,t),g=0;g<r.batchSize;++g)for(var v=0;v<r.inChannels;++v)for(var y=0;y<r.outHeight;++y){for(var b=y*s-h,x=b;x<0;)x+=c;for(var w=Math.min(r.inHeight,f+b),k=0;k<r.outWidth;++k){for(var _=k*u-p,E=_;E<0;)E+=l;for(var O=Math.min(r.inWidth,d+_),S=Number.NEGATIVE_INFINITY,C=-1,A=x;A<w;A+=c)for(var N=A-b,T=E;T<O;T+=l){var I=T-_,D=m.get(g,A,T,v);D>S&&(S=D,C=i?a?((g*r.inHeight+A)*r.inWidth+T)*r.inChannels+v:(A*r.inWidth+T)*r.inChannels+v:N*d+I)}o.set(C,g,y,k,v)}}return o}function ef(t,e,n,r){if("linear"===n)return t.linear(e);if("relu"===n)return t.relu(e);if("elu"===n)return t.elu(e);if("relu6"===n)return t.relu6(e);if("prelu"===n)return t.prelu(e,r);throw new Error("Activation "+n+" has not been implemented for the CPU backend.")}var nf=function(t){function e(){var e=t.call(this)||this;return e.blockSize=48,e.firstUse=!0,e.data=new da(e,Wt),e}return s(e,t),e.prototype.write=function(t,e,n){this.firstUse&&(this.firstUse=!1,f().get("IS_NODE")&&vn("\n============================\nHi there 👋. Looks like you are running TensorFlow.js in Node.js. To speed things up dramatically, install our node backend, which binds to TensorFlow C++, by running npm i @tensorflow/tfjs-node, or npm i @tensorflow/tfjs-node-gpu if you have CUDA. Then call require('@tensorflow/tfjs-node'); (-gpu suffix for CUDA) at the start of your program. Visit https://github.com/tensorflow/tfjs-node for more details.\n============================"));var r={};return this.data.set(r,{values:t,dtype:n}),r},e.prototype.move=function(t,e,n,r){this.data.set(t,{values:e,dtype:r})},e.prototype.numDataIds=function(){return this.data.numDataIds()},e.prototype.read=function(t){return u(this,void 0,void 0,function(){return c(this,function(e){return[2,this.readSync(t)]})})},e.prototype.readSync=function(t){var e=this.data.get(t),n=e.dtype,r=e.complexTensors;return"complex64"===n?Ia(this.readSync(r.real.dataId),this.readSync(r.imag.dataId)):this.data.get(t).values},e.prototype.bufferSync=function(t){var e=this.readSync(t.dataId),n=e;if("string"===t.dtype)try{n=e.map(function(t){return ct(t)})}catch(t){throw new Error("Failed to decode encoded string bytes into utf-8")}return ar(t.shape,t.dtype,n)},e.prototype.makeOutput=function(t,e,n){var r=this.write(t,e,n);return Wt.makeTensorFromDataId(r,e,n,this)},e.prototype.disposeData=function(t){if(this.data.has(t)){var e=this.data.get(t).complexTensors;null!=e&&(e.real.dispose(),e.imag.dispose()),this.data.delete(t)}},e.prototype.time=function(t){return u(this,void 0,void 0,function(){var e;return c(this,function(n){return e=ot(),t(),[2,{kernelMs:ot()-e}]})})},e.prototype.memory=function(){return{unreliable:!0,reasons:["The reported memory is an upper bound. Due to automatic garbage collection, the true allocated memory may be less."]}},e.prototype.complex=function(t,e){var n=this.makeOutput(null,t.shape,"complex64");return this.data.get(n.dataId).complexTensors={real:Wt.keep(t.clone()),imag:Wt.keep(e.clone())},n},e.prototype.real=function(t){return this.data.get(t.dataId).complexTensors.real.clone()},e.prototype.imag=function(t){return this.data.get(t.dataId).complexTensors.imag.clone()},e.prototype.slice=function(t,e,n){if(Zl(t,"slice"),Qi(t.shape,e,n)){var r=ta(e,t.strides),i=I(n);return jn(this.readSync(t.dataId).subarray(r,r+i),n,t.dtype)}for(var a=ar(n,t.dtype),o=this.bufferSync(t),s=0;s<a.size;++s){var u=a.indexToLoc(s).map(function(t,n){return t+e[n]});a.values[s]=o.get.apply(o,u)}return a.toTensor()},e.prototype.stridedSlice=function(t,e,n,r){Zl(t,"stridedSlice");var i=Yi(e,n,r);if(i.some(function(t){return 0===t}))return jn([],i);for(var a=ar(i,t.dtype),o=this.bufferSync(t),s=0;s<a.size;s++){for(var u=a.indexToLoc(s),c=new Array(u.length),l=0;l<c.length;l++)c[l]=u[l]*r[l]+e[l];a.set.apply(a,[o.get.apply(o,c)].concat(u))}return a.toTensor()},e.prototype.diag=function(t){for(var e=this.readSync(t.dataId),n=ar([t.size,t.size],t.dtype),r=n.values,i=0;i<e.length;i++)r[i*t.size+i]=e[i];return n.toTensor()},e.prototype.unstack=function(t,e){for(var n=t.shape[e],r=new Array(t.rank-1),i=0,a=0;a<t.rank;a++)a!==e&&(r[i++]=t.shape[a]);var o=new Array(t.rank).fill(0),s=t.shape.slice();s[e]=1;var u=new Array(n);for(a=0;a<u.length;a++)o[e]=a,u[a]=this.slice(t,o,s).reshape(r);return u},e.prototype.reverse=function(t,e){Zl(t,"reverse");for(var n=ar(t.shape,t.dtype),r=this.bufferSync(t),i=function(i){var a=n.indexToLoc(i),o=a.slice();e.forEach(function(e){return o[e]=t.shape[e]-1-o[e]}),n.set.apply(n,[r.get.apply(r,o)].concat(a))},a=0;a<n.size;a++)i(a);return n.toTensor()},e.prototype.concat=function(t,e){var n=this;if("complex64"===t[0].dtype){var r=t.map(function(t){return Rn(t)}),i=t.map(function(t){return Fn(t)});return Mn(this.concat(r,e),this.concat(i,e))}var a=t.map(function(t){var n=I(t.shape.slice(e));return t.as2D(-1,n)}),o=In(a.map(function(t){return t.shape}),1),s=ar(o,t[0].dtype).values;if(1===a[0].shape[0]){var u=0;a.forEach(function(t){s.set(n.readSync(t.dataId),u),u+=t.size})}else{var c=0;a.forEach(function(t){for(var e=n.readSync(t.dataId),r=0,i=0;i<t.shape[0];++i)for(var a=i*o[1]+c,u=0;u<t.shape[1];++u)s[a+u]=e[r++];c+=t.shape[1]})}var l=In(t.map(function(t){return t.shape}),e);return jn(s,l,t[0].dtype)},e.prototype.neg=function(t){return Zl(t,"neg"),this.multiply(Ln(-1),t)},e.prototype.add=function(t,e){return"complex64"===t.dtype||"complex64"===e.dtype?this.broadcastedBinaryComplexOp(t.cast("complex64"),e.cast("complex64"),function(t,e,n,r){return{real:t+n,imag:e+r}}):this.broadcastedBinaryOp(t,e,Mt(t.dtype,e.dtype),function(t,e){return t+e})},e.prototype.addN=function(t){var e=this;Zl(t,"addN");for(var n=t.map(function(t){return e.readSync(t.dataId)}),r=ar(t[0].shape,t[0].dtype),i=r.values,a=0;a<t.length;a++)for(var o=n[a],s=0;s<i.length;s++)i[s]+=o[s];return r.toTensor()},e.prototype.softmax=function(t,e){var n=z([e],t.shape),r=this.max(t,n),i=On(r.shape,n),a=this.subtract(t,r.reshape(i)),o=this.exp(a),s=this.sum(o,n).reshape(i);return zi(o,s)},e.prototype.subtract=function(t,e){return"complex64"===t.dtype||"complex64"===e.dtype?this.broadcastedBinaryComplexOp(t.cast("complex64"),e.cast("complex64"),function(t,e,n,r){return{real:t-n,imag:e-r}}):this.broadcastedBinaryOp(t,e,Mt(t.dtype,e.dtype),function(t,e){return t-e})},e.prototype.pow=function(t,e){return Zl([t,e],"pow"),this.broadcastedBinaryOp(t,e,t.dtype,function(t,e){return Math.pow(t,e)})},e.prototype.batchMatMul=function(t,e,n,r){Zl([t,e],"matMul");for(var i=n?t.shape[1]:t.shape[2],a=n?t.shape[2]:t.shape[1],o=r?e.shape[1]:e.shape[2],s=t.shape[0],u=this.readSync(t.dataId),c=this.readSync(e.dataId),l=n?[t.strides[0],1,t.strides[1]]:[t.strides[0],t.strides[1],1],f=l[0],d=l[1],h=l[2],p=r?[1,e.strides[1],e.strides[0]]:[e.strides[1],1,e.strides[0]],m=p[0],g=p[1],v=p[2],y=a*o,b=ar([s,a,o],t.dtype),x=b.values,w=this.blockSize,k=0;k<s;k++)for(var _=0;_<a;_+=w)for(var E=0;E<o;E+=w)for(var O=0;O<i;O+=w)for(var S=Math.min(_+w,a),C=Math.min(E+w,o),A=Math.min(O+w,i),N=_;N<S;N++)for(var T=E;T<C;T++){for(var I=0,D=O;D<A;D++)I+=u[k*f+N*d+D*h]*c[D*m+T*g+k*v];x[k*y+(N*o+T)]+=I}return b.toTensor()},e.prototype.fusedBatchMatMul=function(t){var e=t.a,n=t.b,r=t.transposeA,i=t.transposeB,a=t.bias,o=t.activation,s=t.preluActivationWeights,u=this.batchMatMul(e,n,r,i);return a&&(u=this.add(u,a)),o&&(u=ef(this,u,o,s)),u},e.prototype.multiply=function(t,e){return"complex64"===t.dtype||"complex64"===e.dtype?this.broadcastedBinaryComplexOp(t.cast("complex64"),e.cast("complex64"),function(t,e,n,r){return{real:t*n-e*r,imag:t*r+e*n}}):this.broadcastedBinaryOp(t,e,Mt(t.dtype,e.dtype),function(t,e){return t*e})},e.prototype.floorDiv=function(t,e){return Zl([t,e],"floorDiv"),this.broadcastedBinaryOp(t,e,"int32",function(t,e){return Math.floor(t/e)})},e.prototype.sum=function(t,e){Zl(t,"sum"),Sn("sum",e,t.rank);for(var n=En(t.shape,e),r=n[0],i=n[1],a=$n(r,Mt(t.dtype,"int32")),o=I(i),s=this.readSync(a.dataId),u=this.readSync(t.dataId),c=0;c<s.length;++c){for(var l=c*o,f=0,d=0;d<o;++d)f+=u[l+d];s[c]=f}return a},e.prototype.prod=function(t,e){Zl(t,"sum");for(var n=En(t.shape,e),r=n[0],i=n[1],a=$n(r,Mt(t.dtype,"int32")),o=I(i),s=this.readSync(a.dataId),u=this.readSync(t.dataId),c=0;c<s.length;++c){for(var l=c*o,f=1,d=0;d<o;++d)f*=u[l+d];s[c]=f}return a},e.prototype.unsortedSegmentSum=function(t,e,n){Zl(t,"unsortedSegmentSum");for(var r=[],i=t.rank-e.rank,a=0;a<i;++a)e=e.expandDims(a+1);for(a=0;a<n;++a){var o=Ln(a,"int32"),s=Ru(o,e).asType("float32").mul(t).sum(0);r.push(s)}return mr(r)},e.prototype.argMin=function(t,e){Zl(t,"argMin");var n=[e];Sn("argMin",n,t.rank);for(var r=En(t.shape,n),i=r[0],a=r[1],o=$n(i,"int32"),s=I(a),u=this.readSync(o.dataId),c=this.readSync(t.dataId),l=0;l<u.length;++l){for(var f=l*s,d=c[f],h=0,p=0;p<s;++p){var m=c[f+p];m<d&&(d=m,h=p)}u[l]=h}return o},e.prototype.argMax=function(t,e){Zl(t,"argMax");var n=[e];Sn("argMax",n,t.rank);for(var r=En(t.shape,n),i=r[0],a=r[1],o=$n(i,"int32"),s=I(a),u=this.readSync(o.dataId),c=this.readSync(t.dataId),l=0;l<u.length;++l){for(var f=l*s,d=c[f],h=0,p=0;p<s;++p){var m=c[f+p];m>d&&(d=m,h=p)}u[l]=h}return o},e.prototype.cumsum=function(t,e,n,r){if(Zl(t,"cumsum"),e!==t.rank-1)throw new Error("backend.cumsum in CPU expects an inner-most axis="+(t.rank-1)+" but got axis="+e);for(var i=Mt(t.dtype,"int32"),a=$n(t.shape,i),o=this.readSync(a.dataId),s=this.readSync(t.dataId),u=t.shape[t.rank-1],c=r?function(t,e){return t+u-e-1}:function(t,e){return t+e},l=0;l<s.length;l+=u)for(var f=0;f<u;f++){var d=c(l,f);if(0===f)o[d]=n?0:s[d];else{var h=c(l,f-1);o[d]=n?s[h]+o[h]:s[d]+o[h]}}return a},e.prototype.equal=function(t,e){return Zl([t,e],"equal"),this.broadcastedBinaryOp(t,e,"bool",function(t,e){return t===e?1:0})},e.prototype.notEqual=function(t,e){return Zl([t,e],"notEqual"),this.broadcastedBinaryOp(t,e,"bool",function(t,e){return t!==e?1:0})},e.prototype.less=function(t,e){return Zl([t,e],"less"),this.broadcastedBinaryOp(t,e,"bool",function(t,e){return t<e?1:0})},e.prototype.lessEqual=function(t,e){return Zl([t,e],"lessEqual"),this.broadcastedBinaryOp(t,e,"bool",function(t,e){return t<=e?1:0})},e.prototype.greater=function(t,e){return Zl([t,e],"greater"),this.broadcastedBinaryOp(t,e,"bool",function(t,e){return t>e?1:0})},e.prototype.greaterEqual=function(t,e){return Zl([t,e],"greaterEqual"),this.broadcastedBinaryOp(t,e,"bool",function(t,e){return t>=e?1:0})},e.prototype.logicalNot=function(t){Zl(t,"logicalNot");for(var e=this.readSync(t.dataId),n=new Uint8Array(e.length),r=0;r<e.length;++r)n[r]=e[r]?0:1;return this.makeOutput(n,t.shape,"bool")},e.prototype.logicalAnd=function(t,e){return Zl([t,e],"logicalAnd"),this.broadcastedBinaryOp(t,e,"bool",function(t,e){return t&&e})},e.prototype.logicalOr=function(t,e){return Zl([t,e],"logicalOr"),this.broadcastedBinaryOp(t,e,"bool",function(t,e){return t||e})},e.prototype.select=function(t,e,n){Zl([t,e,n],"select");for(var r=this.readSync(t.dataId),i=this.readSync(e.dataId),a=this.readSync(n.dataId),o=$n(e.shape,Mt(e.dtype,n.dtype)),s=this.readSync(o.dataId),u=0,c=0===t.rank||t.rank>1||1===e.rank?1:I(e.shape.slice(1)),l=0;l<r.length;l++)for(var f=0;f<c;f++)1===r[l]?s[u++]=i[l]:s[u++]=a[l];return o},e.prototype.where=function(t){Zl([t],"where");var e=this.readSync(t.dataId);return Ga(t.shape,e)},e.prototype.topk=function(t,e,n){return Zl(t,"topk"),Ha(this.readSync(t.dataId),t.shape,t.dtype,e)},e.prototype.min=function(t,e){Zl(t,"min"),Sn("min",e,t.rank);for(var n=En(t.shape,e),r=n[0],i=n[1],a=$n(r,t.dtype),o=I(i),s=this.readSync(a.dataId),u=this.readSync(t.dataId),c=0;c<s.length;++c){for(var l=c*o,f=u[l],d=0;d<o;++d){var h=u[l+d];h<f&&(f=h)}s[c]=f}return a},e.prototype.minimum=function(t,e){return Zl([t,e],"minimum"),this.broadcastedBinaryOp(t,e,t.dtype,function(t,e){return Math.min(t,e)})},e.prototype.mod=function(t,e){return Zl([t,e],"mod"),this.broadcastedBinaryOp(t,e,t.dtype,function(t,e){var n=t%e;return t<0&&e<0||t>=0&&e>=0?n:(n+e)%e})},e.prototype.max=function(t,e){Zl(t,"max"),Sn("max",e,t.rank);for(var n=En(t.shape,e),r=n[0],i=n[1],a=$n(r,t.dtype),o=I(i),s=this.readSync(a.dataId),u=this.readSync(t.dataId),c=0;c<s.length;++c){for(var l=c*o,f=u[l],d=0;d<o;++d){var h=u[l+d];h>f&&(f=h)}s[c]=f}return a},e.prototype.maximum=function(t,e){return Zl([t,e],"maximum"),this.broadcastedBinaryOp(t,e,t.dtype,function(t,e){return Math.max(t,e)})},e.prototype.all=function(t,e){Zl(t,"all"),Sn("all",e,t.rank);for(var n=En(t.shape,e),r=n[0],i=n[1],a=$n(r,t.dtype),o=I(i),s=this.readSync(a.dataId),u=this.readSync(t.dataId),c=0;c<s.length;++c){for(var l=c*o,f=u[l],d=0;d<o;++d){var h=u[l+d];f=f&&h}s[c]=f}return a},e.prototype.any=function(t,e){Zl(t,"any"),Sn("any",e,t.rank);for(var n=En(t.shape,e),r=n[0],i=n[1],a=$n(r,t.dtype),o=I(i),s=this.readSync(a.dataId),u=this.readSync(t.dataId),c=0;c<s.length;++c){for(var l=c*o,f=u[l],d=0;d<o;++d){var h=u[l+d];f=f||h}s[c]=f}return a},e.prototype.squaredDifference=function(t,e){return Zl([t,e],"squaredDifference"),this.broadcastedBinaryOp(t,e,t.dtype,function(t,e){var n=t-e;return n*n})},e.prototype.ceil=function(t){Zl(t,"ceil");for(var e=this.readSync(t.dataId),n=new Float32Array(e.length),r=0;r<e.length;++r)n[r]=Math.ceil(e[r]);return this.makeOutput(n,t.shape,"float32")},e.prototype.floor=function(t){Zl(t,"floor");for(var e=this.readSync(t.dataId),n=new Float32Array(e.length),r=0;r<e.length;++r)n[r]=Math.floor(e[r]);return this.makeOutput(n,t.shape,"float32")},e.prototype.sign=function(t){Zl(t,"x");for(var e=this.readSync(t.dataId),n=new Float32Array(e.length),r=0;r<e.length;++r)e[r]<0?n[r]=-1:e[r]>0?n[r]=1:n[r]=0;return this.makeOutput(n,t.shape,"float32")},e.prototype.isNaN=function(t){Zl(t,"x");for(var e=this.readSync(t.dataId),n=new Uint8Array(e.length),r=0;r<e.length;++r)Number.isNaN(e[r])&&(n[r]=1);return this.makeOutput(n,t.shape,"bool")},e.prototype.isInf=function(t){Zl(t,"x");for(var e=this.readSync(t.dataId),n=new Uint8Array(e.length),r=0;r<e.length;++r)Math.abs(e[r])===1/0&&(n[r]=1);return this.makeOutput(n,t.shape,"bool")},e.prototype.isFinite=function(t){Zl(t,"x");for(var e=this.readSync(t.dataId),n=new Uint8Array(e.length),r=0;r<e.length;++r)Number.isFinite(e[r])&&(n[r]=1);return this.makeOutput(n,t.shape,"bool")},e.prototype.round=function(t){Zl(t,"round");for(var e=this.readSync(t.dataId),n=new Float32Array(e.length),r=0;r<e.length;++r){var i=Math.floor(e[r]);e[r]-i<.5?n[r]=Math.floor(e[r]):e[r]-i>.5?n[r]=Math.ceil(e[r]):n[r]=i%2==0?i:i+1}return this.makeOutput(n,t.shape,"float32")},e.prototype.exp=function(t){Zl(t,"exp");for(var e=this.readSync(t.dataId),n=new Float32Array(e.length),r=0;r<e.length;++r)n[r]=Math.exp(e[r]);return this.makeOutput(n,t.shape,"float32")},e.prototype.expm1=function(t){Zl(t,"expm1");for(var e=this.readSync(t.dataId),n=new Float32Array(e.length),r=0;r<e.length;++r)n[r]=Math.expm1(e[r]);return this.makeOutput(n,t.shape,"float32")},e.prototype.log=function(t){Zl(t,"log");for(var e=this.readSync(t.dataId),n=new Float32Array(e.length),r=0;r<e.length;++r){var i=e[r];n[r]=Math.log(i)}return this.makeOutput(n,t.shape,"float32")},e.prototype.log1p=function(t){Zl(t,"log1p");for(var e=this.readSync(t.dataId),n=new Float32Array(e.length),r=0;r<e.length;++r){var i=e[r];n[r]=Math.log1p(i)}return this.makeOutput(n,t.shape,"float32")},e.prototype.sqrt=function(t){Zl(t,"sqrt");for(var e=this.readSync(t.dataId),n=new Float32Array(e.length),r=0;r<e.length;++r){var i=e[r];n[r]=Math.sqrt(i)}return this.makeOutput(n,t.shape,"float32")},e.prototype.rsqrt=function(t){Zl(t,"rsqrt");for(var e=this.readSync(t.dataId),n=new Float32Array(e.length),r=0;r<e.length;++r){var i=e[r];n[r]=1/Math.sqrt(i)}return this.makeOutput(n,t.shape,"float32")},e.prototype.reciprocal=function(t){Zl(t,"reciprocal");for(var e=this.readSync(t.dataId),n=new Float32Array(e.length),r=0;r<e.length;++r)n[r]=1/e[r];return this.makeOutput(n,t.shape,"float32")},e.prototype.linear=function(t){return t},e.prototype.relu=function(t){Zl(t,"relu");for(var e=$n(t.shape,t.dtype),n=this.readSync(e.dataId),r=this.readSync(t.dataId),i=0;i<r.length;++i)n[i]=Math.max(0,r[i]);return e},e.prototype.relu6=function(t){Zl(t,"relu");for(var e=$n(t.shape,t.dtype),n=this.readSync(e.dataId),r=this.readSync(t.dataId),i=0;i<r.length;++i)n[i]=Math.min(Math.max(0,r[i]),6);return e},e.prototype.prelu=function(t,e){return Zl([t,e],"prelu"),this.broadcastedBinaryOp(t,e,t.dtype,function(t,e){return t<0?e*t:t})},e.prototype.elu=function(t){Zl(t,"elu");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r){var i=n[r];e[r]=i>=0?i:Math.exp(i)-1}return this.makeOutput(e,t.shape,"float32")},e.prototype.eluDer=function(t,e){Zl([t,e],"eluDer");for(var n=new Float32Array(e.size),r=this.readSync(e.dataId),i=this.readSync(t.dataId),a=0;a<r.length;++a){var o=r[a];n[a]=o>=1?i[a]:i[a]*(o+1)}return this.makeOutput(n,e.shape,"float32")},e.prototype.selu=function(t){Zl(t,"selu");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r){var i=n[r];e[r]=i>=0?1.0507009873554805*i:1.7580993408473768*(Math.exp(i)-1)}return this.makeOutput(e,t.shape,"float32")},e.prototype.clip=function(t,e,n){Zl(t,"clip");for(var r=new Float32Array(t.size),i=this.readSync(t.dataId),a=0;a<i.length;++a){var o=i[a];r[a]=o>n?n:o<e?e:o}return this.makeOutput(r,t.shape,"float32")},e.prototype.abs=function(t){for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.abs(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.complexAbs=function(t){for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<t.size;++r){var i=n[2*r],a=n[2*r+1];e[r]=Math.hypot(i,a)}return this.makeOutput(e,t.shape,"float32")},e.prototype.int=function(t){Zl(t,"int");for(var e=new Int32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=n[r];return this.makeOutput(e,t.shape,"int32")},e.prototype.sigmoid=function(t){Zl(t,"sigmoid");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=1/(1+Math.exp(-n[r]));return this.makeOutput(e,t.shape,"float32")},e.prototype.softplus=function(t){Zl(t,"softplus");for(var e=Math.log(1.1920928955078125e-7)+2,n=new Float32Array(t.size),r=this.readSync(t.dataId),i=0;i<r.length;++i){var a,o=r[i]>-e,s=r[i]<e,u=Math.exp(r[i]);a=s?u:o?r[i]:Math.log(1+u),n[i]=a}return this.makeOutput(n,t.shape,"float32")},e.prototype.sin=function(t){Zl(t,"sin");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.sin(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.cos=function(t){Zl(t,"cos");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.cos(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.tan=function(t){Zl(t,"tan");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.tan(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.asin=function(t){Zl(t,"asin");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.asin(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.acos=function(t){Zl(t,"acos");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.acos(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.atan=function(t){Zl(t,"atan");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.atan(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.atan2=function(t,e){return Zl([t,e],"atan2"),this.broadcastedBinaryOp(t,e,t.dtype,function(t,e){return Math.atan2(t,e)})},e.prototype.sinh=function(t){Zl(t,"sinh");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.sinh(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.cosh=function(t){Zl(t,"cosh");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.cosh(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.tanh=function(t){Zl(t,"tanh");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=R(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.asinh=function(t){Zl(t,"asinh");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.asinh(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.acosh=function(t){Zl(t,"acosh");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.acosh(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.atanh=function(t){Zl(t,"atanh");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.atanh(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.erf=function(t){Zl(t,"erf");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r){var i=Math.sign(n[r]),a=Math.abs(n[r]),o=1/(1+.3275911*a);e[r]=i*(1-((((1.061405429*o-1.453152027)*o+1.421413741)*o-.284496736)*o+.254829592)*o*Math.exp(-a*a))}return this.makeOutput(e,t.shape,"float32")},e.prototype.step=function(t,e){void 0===e&&(e=0),Zl(t,"step");for(var n=new Float32Array(t.size),r=this.readSync(t.dataId),i=0;i<r.length;++i){var a=r[i];isNaN(a)?n[i]=NaN:n[i]=a>0?1:e}return this.makeOutput(n,t.shape,"float32")},e.prototype.fusedConv2d=function(t){var e=t.input,n=t.filter,r=t.convInfo,i=t.bias,a=t.activation,o=t.preluActivationWeights,s=this.conv2d(e,n,r);return i&&(s=this.add(s,i)),a&&(s=ef(this,s,a,o)),s},e.prototype.conv2d=function(t,e,n){Zl([t,e],"conv2d");for(var r=n.filterHeight,i=n.filterWidth,a=n.dilationHeight,o=n.dilationWidth,s=n.padInfo.left,u=n.padInfo.top,c="channelsLast"===n.dataFormat,l=ar(n.outShape,t.dtype),f=t.strides[0],d=c?t.strides[1]:t.strides[2],h=c?t.strides[2]:1,p=c?1:t.strides[1],m=l.strides[0],g=c?l.strides[1]:l.strides[2],v=c?l.strides[2]:1,y=c?1:l.strides[1],b=this.readSync(t.dataId),x=this.readSync(e.dataId),w=l.values,k=0;k<n.batchSize;++k)for(var _=k*f,E=k*m,O=0;O<n.outHeight;++O)for(var S=E+O*g,C=O*n.strideHeight-u,A=0;A<r;A++){var N=C+A*a;if(!(N<0||N>=n.inHeight))for(var T=A*e.strides[0],I=_+N*d,D=0;D<n.outWidth;++D)for(var M=S+D*v,R=D*n.strideWidth-s,F=0;F<i;F++){var j=R+F*o;if(!(j<0||j>=n.inWidth))for(var P=I+j*h,L=T+F*e.strides[1],z=0;z<n.inChannels;++z){for(var B=b[P+z*p],U=0;U<n.outChannels;++U)w[M+U*y]+=B*x[L+U];L+=n.outChannels}}}return l.toTensor()},e.prototype.conv3d=function(t,e,n){for(var r=n.filterDepth,i=n.filterHeight,a=n.filterWidth,o=n.dilationDepth,s=n.dilationHeight,u=n.dilationWidth,c=n.padInfo.front,l=n.padInfo.left,f=n.padInfo.top,d=ar(n.outShape,t.dtype),h=this.readSync(t.dataId),p=this.readSync(e.dataId),m=d.values,g=0;g<n.batchSize;++g)for(var v=g*t.strides[0],y=g*d.strides[0],b=0;b<n.outDepth;++b)for(var x=y+b*d.strides[1],w=b*n.strideDepth-c,k=0;k<r;k++){var _=w+k*o;if(!(_<0||_>=n.inDepth))for(var E=k*e.strides[0],O=v+_*t.strides[1],S=0;S<n.outHeight;++S)for(var C=x+S*d.strides[2],A=S*n.strideHeight-f,N=0;N<i;N++){var T=A+N*s;if(!(T<0||T>=n.inHeight))for(var I=E+N*e.strides[1],D=O+T*t.strides[2],M=0;M<n.outWidth;++M)for(var R=C+M*n.outChannels,F=M*n.strideWidth-l,j=0;j<a;j++){var P=F+j*u;if(!(P<0||P>=n.inWidth))for(var L=I+j*e.strides[2],z=D+P*n.inChannels,B=L,U=0;U<n.inChannels;++U){for(var W=h[z+U],V=0;V<n.outChannels;++V)m[R+V]+=W*p[B+V];B+=n.outChannels}}}}return d.toTensor()},e.prototype.conv2dDerInput=function(t,e,n){Zl([t,e],"conv2dDerInput");for(var r=ar(n.inShape,"float32"),i=r.values,a=this.readSync(t.dataId),o=this.readSync(e.dataId),s=e.strides,u=s[0],c=s[1],l=s[2],f=n.batchSize,d=n.filterHeight,h=n.filterWidth,p=n.inChannels,m=n.inHeight,g=n.inWidth,v=n.outChannels,y=n.outHeight,b=n.outWidth,x=n.strideHeight,w=n.strideWidth,k=n.dataFormat,_=d-1-n.padInfo.top,E=h-1-n.padInfo.left,O="channelsLast"===k,S=r.strides[0],C=O?r.strides[1]:r.strides[2],A=O?r.strides[2]:1,N=O?1:r.strides[1],T=t.strides[0],I=O?t.strides[1]:t.strides[2],D=O?t.strides[2]:1,M=O?1:t.strides[1],R=0;R<f;++R)for(var F=0;F<p;++F)for(var j=0;j<m;++j)for(var P=j-_,L=Math.max(0,Math.ceil(P/x)),z=Math.min(y,(d+P)/x),B=0;B<g;++B){for(var U=B-E,W=Math.max(0,Math.ceil(U/w)),V=Math.min(b,(h+U)/w),q=0,H=L;H<z;++H)for(var G=H*x-P,$=W;$<V;++$)for(var K=T*R+I*H+D*$,X=u*(d-1-G)+c*(h-1-($*w-U))+l*F,Y=0;Y<v;++Y)q+=a[K+M*Y]*o[X+Y];i[S*R+C*j+A*B+N*F]=q}return r.toTensor()},e.prototype.conv3dDerInput=function(t,e,n){for(var r=ar(n.inShape,"float32"),i=r.values,a=r.strides,o=a[0],s=a[1],u=a[2],c=a[3],l=this.readSync(t.dataId),f=t.strides,d=f[0],h=f[1],p=f[2],m=f[3],g=this.readSync(e.dataId),v=e.strides,y=v[0],b=v[1],x=v[2],w=v[3],k=n.batchSize,_=n.filterDepth,E=n.filterHeight,O=n.filterWidth,S=n.inChannels,C=n.inDepth,A=n.inHeight,N=n.inWidth,T=n.outChannels,I=n.outDepth,D=n.outHeight,M=n.outWidth,R=n.strideDepth,F=n.strideHeight,j=n.strideWidth,P=_-1-n.padInfo.front,L=E-1-n.padInfo.top,z=O-1-n.padInfo.left,B=0;B<k;++B)for(var U=0;U<S;++U)for(var W=0;W<C;++W)for(var V=W-P,q=Math.max(0,Math.ceil(V/R)),H=Math.min(I,(_+V)/R),G=0;G<A;++G)for(var $=G-L,K=Math.max(0,Math.ceil($/F)),X=Math.min(D,(E+$)/F),Y=0;Y<N;++Y){for(var J=Y-z,Z=Math.max(0,Math.ceil(J/j)),Q=Math.min(M,(O+J)/j),tt=0,et=q;et<H;++et)for(var nt=et*R-V,rt=K;rt<X;++rt)for(var it=rt*F-$,at=Z;at<Q;++at)for(var ot=d*B+h*et+p*rt+m*at,st=y*(_-1-nt)+b*(E-1-it)+x*(O-1-(at*j-J))+w*U,ut=0;ut<T;++ut)tt+=l[ot+ut]*g[st+ut];i[o*B+s*W+u*G+c*Y+U]=tt}return r.toTensor()},e.prototype.conv2dDerFilter=function(t,e,n){Zl([t,e],"conv2dDerFilter");for(var r=n.strideHeight,i=n.strideWidth,a=n.filterHeight,o=n.filterWidth,s="channelsLast"===n.dataFormat,u=ar(n.filterShape,"float32"),c=n.padInfo.left,l=n.padInfo.top,f=this.bufferSync(t),d=this.bufferSync(e),h=0;h<a;++h)for(var p=Math.max(0,Math.ceil((l-h)/r)),m=Math.min(n.outHeight,(n.inHeight+l-h)/r),g=0;g<o;++g)for(var v=Math.max(0,Math.ceil((c-g)/i)),y=Math.min(n.outWidth,(n.inWidth+c-g)/i),b=0;b<n.inChannels;++b)for(var x=0;x<n.outChannels;++x){for(var w=0,k=0;k<n.batchSize;++k)for(var _=p;_<m;++_)for(var E=h+_*r-l,O=v;O<y;++O){var S=g+O*i-c;w+=s?f.get(k,E,S,b)*d.get(k,_,O,x):f.get(k,b,E,S)*d.get(k,x,_,O)}u.set(w,h,g,b,x)}return u.toTensor()},e.prototype.conv3dDerFilter=function(t,e,n){for(var r=n.strideDepth,i=n.strideHeight,a=n.strideWidth,o=n.filterDepth,s=n.filterHeight,u=n.filterWidth,c=ar(n.filterShape,"float32"),l=c.values,f=c.strides,d=f[0],h=f[1],p=f[2],m=f[3],g=this.readSync(e.dataId),v=e.strides,y=v[0],b=v[1],x=v[2],w=v[3],k=this.readSync(t.dataId),_=t.strides,E=_[0],O=_[1],S=_[2],C=_[3],A=n.padInfo.front,N=n.padInfo.left,T=n.padInfo.top,I=0;I<o;++I)for(var D=Math.max(0,Math.ceil((A-I)/r)),M=Math.min(n.outDepth,(n.inDepth+A-I)/r),R=I*d,F=0;F<s;++F)for(var j=Math.max(0,Math.ceil((T-F)/i)),P=Math.min(n.outHeight,(n.inHeight+T-F)/i),L=F*h+R,z=0;z<u;++z)for(var B=Math.max(0,Math.ceil((N-z)/a)),U=Math.min(n.outWidth,(n.inWidth+N-z)/a),W=z*p+L,V=0;V<n.inChannels;++V)for(var q=V*m+W,H=0;H<n.outChannels;++H){for(var G=0,$=0;$<n.batchSize;++$)for(var K=$*E,X=$*y,Y=D;Y<M;++Y)for(var J=(I+Y*r-A)*O+K,Z=Y*b+X,Q=j;Q<P;++Q)for(var tt=(F+Q*i-T)*S+J,et=Q*x+Z,nt=B;nt<U;++nt){var rt=nt*w+et;G+=k[(z+nt*a-N)*C+tt+V]*g[rt+H]}l[q+H]=G}return c.toTensor()},e.prototype.fusedDepthwiseConv2D=function(t){var e=t.input,n=t.filter,r=t.convInfo,i=t.bias,a=t.activation,o=t.preluActivationWeights,s=this.depthwiseConv2D(e,n,r);return i&&(s=this.add(s,i)),a&&(s=ef(this,s,a,o)),s},e.prototype.depthwiseConv2D=function(t,e,n){Zl([t,e],"depthwiseConv2D");for(var r=n.filterHeight,i=n.filterWidth,a=n.dilationHeight,o=n.dilationWidth,s=n.padInfo.left,u=n.padInfo.top,c=n.outChannels/n.inChannels,l=ar(n.outShape,t.dtype),f=this.readSync(t.dataId),d=this.readSync(e.dataId),h=l.values,p=0;p<n.batchSize;++p)for(var m=p*t.strides[0],g=p*l.strides[0],v=0;v<n.outHeight;++v)for(var y=g+v*l.strides[1],b=v*n.strideHeight-s,x=0;x<r;++x){var w=b+x*a;if(!(w<0||w>=n.inHeight))for(var k=x*e.strides[0],_=m+w*t.strides[1],E=0;E<n.outWidth;++E)for(var O=y+E*l.strides[2],S=E*n.strideWidth-u,C=0;C<i;++C){var A=S+C*o;if(!(A<0||A>=n.inWidth))for(var N=k+C*e.strides[1],T=_+A*n.inChannels,I=O,D=N,M=0;M<n.inChannels;++M){for(var R=f[T+M],F=0;F<c;++F)h[I+F]+=R*d[D+F];I+=c,D+=c}}}return l.toTensor()},e.prototype.depthwiseConv2DDerInput=function(t,e,n){Zl([t,e],"depthwiseConv2DDerInput");for(var r=ar(n.inShape,"float32"),i=r.values,a=r.strides,o=a[0],s=a[1],u=a[2],c=this.readSync(t.dataId),l=t.strides,f=l[0],d=l[1],h=l[2],p=this.readSync(e.dataId),m=e.strides,g=m[0],v=m[1],y=m[2],b=n.batchSize,x=n.filterHeight,w=n.filterWidth,k=n.inChannels,_=n.inHeight,E=n.inWidth,O=n.outChannels,S=n.outHeight,C=n.outWidth,A=n.strideHeight,N=n.strideWidth,T=x-1-n.padInfo.top,I=w-1-n.padInfo.left,D=O/k,M=0;M<b;++M)for(var R=0;R<k;++R)for(var F=0;F<_;++F)for(var j=F-T,P=Math.max(0,Math.ceil(j/A)),L=Math.min(S,(x+j)/A),z=0;z<E;++z){for(var B=z-I,U=Math.max(0,Math.ceil(B/N)),W=Math.min(C,(w+B)/N),V=0,q=P;q<L;++q)for(var H=q*A-j,G=U;G<W;++G)for(var $=f*M+d*q+h*G,K=g*(x-1-H)+v*(w-1-(G*N-B))+y*R,X=0;X<D;++X)V+=c[$+(R*D+X)]*p[K+X];i[o*M+s*F+u*z+R]=V}return r.toTensor()},e.prototype.depthwiseConv2DDerFilter=function(t,e,n){Zl([t,e],"depthwiseConv2DDerFilter");for(var r=n.strideHeight,i=n.strideWidth,a=n.filterHeight,o=n.filterWidth,s=ar(n.filterShape,"float32"),u=n.padInfo.left,c=n.padInfo.top,l=n.outChannels/n.inChannels,f=this.bufferSync(t),d=this.bufferSync(e),h=0;h<a;++h)for(var p=Math.max(0,Math.ceil((c-h)/r)),m=Math.min(n.outHeight,(n.inHeight+c-h)/r),g=0;g<o;++g)for(var v=Math.max(0,Math.ceil((u-g)/i)),y=Math.min(n.outWidth,(n.inWidth+u-g)/i),b=0;b<n.outChannels;++b){for(var x=Math.trunc(b/l),w=b%l,k=0,_=0;_<n.batchSize;++_)for(var E=p;E<m;++E)for(var O=h+E*r-c,S=v;S<y;++S){var C=g+S*i-u;k+=f.get(_,O,C,x)*d.get(_,E,S,b)}s.set(k,h,g,x,w)}return s.toTensor()},e.prototype.tile=function(t,e){return Zl(t,"tile"),qa(this.bufferSync(t),e)},e.prototype.pad=function(t,e,n){Zl(t,"pad");var r=e.map(function(e,n){return e[0]+t.shape[n]+e[1]}),i=e.map(function(t){return t[0]}),a=this.bufferSync(t),o=ar(r,t.dtype);0!==n&&o.values.fill(n);for(var s=0;s<t.size;s++){var u=a.indexToLoc(s),c=u.map(function(t,e){return t+i[e]});o.set.apply(o,[a.get.apply(a,u)].concat(c))}return o.toTensor()},e.prototype.gather=function(t,e,n){Zl([t,e],"gather");var r=t.shape.slice(),i=this.readSync(e.dataId);r[n]=i.length;for(var a=ar(r,t.dtype),o=this.bufferSync(t),s=0;s<a.size;++s){var u=a.indexToLoc(s),c=u.slice();c[n]=i[u[n]];var l=o.locToIndex(c);a.values[s]=o.values[l]}return a.toTensor()},e.prototype.batchToSpaceND=function(t,e,n){Zl([t],"batchToSpaceND");var r=e.reduce(function(t,e){return t*e}),i=yr(t.shape,e,r),a=br(i.length,e.length),o=xr(t.shape,e,r),s=wr(n,e.length),u=kr(o,n,e.length);return fa(t.reshape(i),a).reshape(o).slice(s,u)},e.prototype.spaceToBatchND=function(t,e,n){Zl([t],"spaceToBatchND");var r=e.reduce(function(t,e){return t*e}),i=[[0,0]];i.push.apply(i,n);for(var a=1+e.length;a<t.shape.length;++a)i.push([0,0]);var o=t.pad(i),s=yr(o.shape,e,r,!1),u=br(s.length,e.length,!1),c=xr(o.shape,e,r,!1);return fa(o.reshape(s),u).reshape(c)},e.prototype.maxPool=function(t,e){return Zl(t,"maxPool"),Ql(this.readSync(t.dataId),t.shape,t.dtype,t.strides,e,"max").toTensor()},e.prototype.maxPoolBackprop=function(t,e,n,r){Zl([e,n],"maxPoolBackprop");for(var i=this.readSync(e.dataId),a=ar(r.outShape,e.dtype,tf(i,e.shape,e.dtype,r).values),o=r.strideHeight,s=r.strideWidth,u=r.dilationHeight,c=r.dilationWidth,l=r.effectiveFilterHeight,f=r.effectiveFilterWidth,d=f-1-r.padInfo.left,h=l-1-r.padInfo.top,p=ar(e.shape,"float32"),m=this.bufferSync(t),g=0;g<r.batchSize;++g)for(var v=0;v<r.inChannels;++v)for(var y=0;y<r.inHeight;++y)for(var b=0;b<r.inWidth;++b){for(var x=y-h,w=b-d,k=0,_=0;_<l;_+=u){var E=(x+_)/o;if(!(E<0||E>=r.outHeight||Math.floor(E)!==E))for(var O=0;O<f;O+=c){var S=(w+O)/s;if(!(S<0||S>=r.outWidth||Math.floor(S)!==S)){var C=l*f-1-a.get(g,E,S,v)===_*f+O?1:0;0!==C&&(k+=m.get(g,E,S,v)*C)}}}p.set(k,g,y,b,v)}return p.toTensor()},e.prototype.avgPoolBackprop=function(t,e,n){Zl([t,e],"avgPoolBackprop");for(var r=n.strideHeight,i=n.strideWidth,a=n.filterHeight,o=n.filterWidth,s=n.dilationHeight,u=n.dilationWidth,c=n.effectiveFilterHeight,l=n.effectiveFilterWidth,f=l-1-n.padInfo.left,d=c-1-n.padInfo.top,h=ar(e.shape,"float32"),p=1/(a*o),m=this.bufferSync(t),g=0;g<n.batchSize;++g)for(var v=0;v<n.inChannels;++v)for(var y=0;y<n.inHeight;++y)for(var b=0;b<n.inWidth;++b){for(var x=y-d,w=b-f,k=0,_=0;_<c;_+=s){var E=(x+_)/r;if(!(E<0||E>=n.outHeight||Math.floor(E)!==E))for(var O=0;O<l;O+=u){var S=(w+O)/i;S<0||S>=n.outWidth||Math.floor(S)!==S||(k+=m.get(g,E,S,v))}}h.set(k*p,g,y,b,v)}return h.toTensor()},e.prototype.pool3d=function(t,e,n){Zl(t,"pool3d");for(var r=e.strideDepth,i=e.strideHeight,a=e.strideWidth,o=e.dilationDepth,s=e.dilationHeight,u=e.dilationWidth,c=e.effectiveFilterDepth,l=e.effectiveFilterHeight,f=e.effectiveFilterWidth,d=e.padInfo.front,h=e.padInfo.top,p=e.padInfo.left,m="max"===n?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,g=this.readSync(t.dataId),v=ar(e.outShape,t.dtype),y=v.values,b=e.outShape[1]*e.outShape[2]*e.outShape[3]*e.outShape[4],x=e.outShape[2]*e.outShape[3]*e.outShape[4],w=e.outShape[3]*e.outShape[4],k=e.outShape[4],_=0;_<e.batchSize;++_)for(var E=_*b,O=_*t.strides[0],S=0;S<e.inChannels;++S)for(var C=0;C<e.outDepth;++C){for(var A=C*r-d,N=A;N<0;)N+=o;for(var T=Math.min(e.inDepth,c+A),I=E+C*x,D=0;D<e.outHeight;++D){for(var M=D*i-h,R=M;R<0;)R+=s;for(var F=Math.min(e.inHeight,l+M),j=I+D*w,P=0;P<e.outWidth;++P){for(var L=P*a-p,z=L;z<0;)z+=u;for(var B=Math.min(e.inWidth,f+L),U=j+P*k,W=m,V=0,q=0,H=N;H<T;H+=o){for(var G=O+H*t.strides[1],$=R;$<F;$+=s){for(var K=G+$*t.strides[2],X=z;X<B;X+=u){var Y=g[K+X*t.strides[3]+S];if("max"===n&&Y>W?W=Y:"avg"===n&&(V+=Y,q++),isNaN(W))break}if(isNaN(W))break}if(isNaN(W))break}y[U+S]="avg"===n?V/q:W}}}return v.toTensor()},e.prototype.avgPool3d=function(t,e){return Zl(t,"avgPool3d"),this.pool3d(t,e,"avg").toFloat()},e.prototype.avgPool3dBackprop=function(t,e,n){Zl([t,e],"avgPool3dBackprop");for(var r=n.strideDepth,i=n.strideHeight,a=n.strideWidth,o=n.filterDepth,s=n.filterHeight,u=n.filterWidth,c=n.dilationDepth,l=n.dilationHeight,f=n.dilationWidth,d=n.effectiveFilterDepth,h=n.effectiveFilterHeight,p=n.effectiveFilterWidth,m=d-1-n.padInfo.front,g=p-1-n.padInfo.left,v=h-1-n.padInfo.top,y=ar(e.shape,"float32"),b=1/(o*s*u),x=this.bufferSync(t),w=0;w<n.batchSize;++w)for(var k=0;k<n.inChannels;++k)for(var _=0;_<n.inDepth;++_)for(var E=0;E<n.inHeight;++E)for(var O=0;O<n.inWidth;++O){for(var S=_-m,C=E-v,A=O-g,N=0,T=0;T<d;T+=c){var I=(S+T)/r;if(!(I<0||I>=n.outDepth||Math.floor(I)!==I))for(var D=0;D<h;D+=l){var M=(C+D)/i;if(!(M<0||M>=n.outHeight||Math.floor(M)!==M))for(var R=0;R<p;R+=f){var F=(A+R)/a;F<0||F>=n.outWidth||Math.floor(F)!==F||(N+=x.get(w,I,M,F,k))}}}y.set(N*b,w,_,E,O,k)}return y.toTensor()},e.prototype.maxPool3d=function(t,e){return Zl(t,"maxPool3d"),this.pool3d(t,e,"max").toFloat()},e.prototype.maxPool3dPositions=function(t,e){for(var n=ar(e.outShape,"int32"),r=e.strideDepth,i=e.strideHeight,a=e.strideWidth,o=e.dilationDepth,s=e.dilationHeight,u=e.dilationWidth,c=e.effectiveFilterDepth,l=e.effectiveFilterHeight,f=e.effectiveFilterWidth,d=e.padInfo.front,h=e.padInfo.top,p=e.padInfo.left,m=this.bufferSync(t),g=0;g<e.batchSize;++g)for(var v=0;v<e.inChannels;++v)for(var y=0;y<e.outDepth;++y){for(var b=y*r-d,x=b;x<0;)x+=o;for(var w=Math.min(e.inDepth,c+b),k=0;k<e.outHeight;++k){for(var _=k*i-h,E=_;E<0;)E+=s;for(var O=Math.min(e.inHeight,l+_),S=0;S<e.outWidth;++S){for(var C=S*a-p,A=C;A<0;)A+=u;for(var N=Math.min(e.inWidth,f+C),T=Number.NEGATIVE_INFINITY,I=-1,D=x;D<w;D+=o)for(var M=D-b,R=E;R<O;R+=s)for(var F=R-_,j=A;j<N;j+=u){var P=j-C,L=m.get(g,D,R,j,v);L>=T&&(T=L,I=M*l*f+F*l+P)}n.set(I,g,y,k,S,v)}}}return n.toTensor()},e.prototype.maxPool3dBackprop=function(t,e,n,r){Zl([e,n],"maxPool3dBackprop");for(var i=this.maxPool3dPositions(e,r),a=r.strideDepth,o=r.strideHeight,s=r.strideWidth,u=r.dilationDepth,c=r.dilationHeight,l=r.dilationWidth,f=r.effectiveFilterDepth,d=r.effectiveFilterHeight,h=r.effectiveFilterWidth,p=f-1-r.padInfo.front,m=h-1-r.padInfo.left,g=d-1-r.padInfo.top,v=ar(e.shape,"float32"),y=this.bufferSync(i),b=this.bufferSync(t),x=0;x<r.batchSize;++x)for(var w=0;w<r.inChannels;++w)for(var k=0;k<r.inDepth;++k)for(var _=0;_<r.inHeight;++_)for(var E=0;E<r.inWidth;++E){for(var O=k-p,S=_-g,C=E-m,A=0,N=0;N<f;N+=u){var T=(O+N)/a;if(!(T<0||T>=r.outDepth||Math.floor(T)!==T))for(var I=0;I<d;I+=c){var D=(S+I)/o;if(!(D<0||D>=r.outHeight||Math.floor(D)!==D))for(var M=0;M<h;M+=l){var R=(C+M)/s;if(!(R<0||R>=r.outWidth||Math.floor(R)!==R)){var F=f*d*h-1-y.get(x,T,D,R,w)===N*d*h+I*h+M?1:0;0!==F&&(A+=b.get(x,T,D,R,w)*F)}}}}v.set(A,x,k,_,E,w)}return v.toTensor()},e.prototype.cast=function(t,e){return Ca(t,e,this)},e.prototype.reshape=function(t,e){return Aa(t,e)},e.prototype.avgPool=function(t,e){return Zl(t,"avgPool"),Zl(t,"maxPool"),Ql(this.readSync(t.dataId),t.shape,t.dtype,t.strides,e,"avg").toTensor().toFloat()},e.prototype.resizeBilinear=function(t,e,n,r){Zl(t,"resizeBilinear");for(var i=t.shape,a=i[0],o=i[1],s=i[2],u=i[3],c=this.readSync(t.dataId),l=new Float32Array(I([a,e,n,u])),f=[r&&e>1?o-1:o,r&&n>1?s-1:s],d=[r&&e>1?e-1:e,r&&n>1?n-1:n],h=0,p=f[0]/d[0],m=f[1]/d[1],g=0;g<a;g++)for(var v=0;v<e;v++)for(var y=p*v,b=Math.floor(y),x=y-b,w=Math.min(o-1,Math.ceil(y)),k=g*t.strides[0]+b*t.strides[1],_=g*t.strides[0]+w*t.strides[1],E=0;E<n;E++)for(var O=m*E,S=Math.floor(O),C=O-S,A=Math.min(s-1,Math.ceil(O)),N=k+S*t.strides[2],T=_+S*t.strides[2],D=k+A*t.strides[2],M=_+A*t.strides[2],R=0;R<u;R++){var F=c[N+R],j=c[T+R],P=F+(c[D+R]-F)*C,L=P+(j+(c[M+R]-j)*C-P)*x;l[h++]=L}return jn(l,[a,e,n,u])},e.prototype.resizeBilinearBackprop=function(t,e,n){Zl([t,e],"resizeBilinearBackprop");for(var r=e.shape,i=r[0],a=r[1],o=r[2],s=r[3],u=t.shape,c=u[1],l=u[2],f=new Float32Array(i*a*o*s),d=[n&&c>1?a-1:a,n&&l>1?o-1:o],h=[n&&c>1?c-1:c,n&&l>1?l-1:l],p=d[0]/h[0],m=d[1]/h[1],g=this.readSync(t.dataId),v=0,y=0;y<i;y++)for(var b=y*e.strides[0],x=0;x<c;x++)for(var w=x*p,k=Math.floor(w),_=Math.min(Math.ceil(w),a-1),E=b+k*e.strides[1],O=b+_*e.strides[1],S=w-k,C=1-S,A=0;A<l;A++)for(var N=A*m,T=Math.floor(N),I=Math.min(Math.ceil(N),o-1),D=N-T,M=1-D,R=E+T*e.strides[2],F=E+I*e.strides[2],j=O+T*e.strides[2],P=O+I*e.strides[2],L=C*M,z=C*D,B=S*M,U=S*D,W=0;W<s;W++){var V=g[v++];f[R+W]+=V*L,f[F+W]+=V*z,f[j+W]+=V*B,f[P+W]+=V*U}return Wn(f,[i,o,a,s],e.dtype)},e.prototype.resizeNearestNeighbor=function(t,e,n,r){Zl(t,"resizeNearestNeighbor");for(var i=t.shape,a=i[0],o=i[1],s=i[2],u=i[3],c=this.readSync(t.dataId),l=new Float32Array(a*e*n*u),f=[r&&e>1?o-1:o,r&&n>1?s-1:s],d=[r&&e>1?e-1:e,r&&n>1?n-1:n],h=f[0]/d[0],p=f[1]/d[1],m=0,g=0;g<a;g++)for(var v=g*t.strides[0],y=0;y<e;y++)for(var b=h*y,x=v+Math.min(o-1,r?Math.round(b):Math.floor(b))*t.strides[1],w=0;w<n;w++)for(var k=p*w,_=x+Math.min(s-1,r?Math.round(k):Math.floor(k))*t.strides[2],E=0;E<u;E++){var O=c[_+E];l[m++]=O}return jn(l,[a,e,n,u],t.dtype)},e.prototype.resizeNearestNeighborBackprop=function(t,e,n){Zl([t,e],"resizeNearestNeighborBackprop");for(var r=e.shape,i=r[0],a=r[1],o=r[2],s=r[3],u=t.shape,c=u[1],l=u[2],f=new Float32Array(i*a*o*s),d=this.readSync(t.dataId),h=[n&&c>1?a-1:a,n&&l>1?o-1:o],p=[n&&c>1?c-1:c,n&&l>1?l-1:l],m=h[0]/p[0],g=h[1]/p[1],v=1/m,y=1/g,b=2*Math.ceil(v)+2,x=2*Math.ceil(y)+2,w=0;w<i;w++)for(var k=w*e.strides[0],_=0;_<a;_++)for(var E=k+_*e.strides[1],O=Math.floor(_*v),S=Math.floor(O-b/2),C=0;C<o;C++)for(var A=E+C*e.strides[2],N=Math.floor(C*y),T=Math.floor(N-x/2),I=0;I<s;I++){for(var D=0,M=0;M<b;M++){var R=M+S;if(!(R<0||R>=c)){var F=k+R*t.strides[1],j=R*m;if(_===Math.min(a-1,n?Math.round(j):Math.floor(j)))for(var P=0;P<x;P++){var L=P+T;if(!(L<0||L>=l)){var z=F+L*t.strides[2],B=L*g;C===Math.min(o-1,n?Math.round(B):Math.floor(B))&&(D+=d[z+I])}}}}f[A+I]=D}return Wn(f,e.shape,e.dtype)},e.prototype.batchNormalization=function(t,e,n,r,i,a){Zl([t,e,n,i,a],"batchNorm");for(var o=this.readSync(t.dataId),s=this.readSync(e.dataId),u=this.readSync(n.dataId),c=i?this.readSync(i.dataId):new Float32Array([1]),l=a?this.readSync(a.dataId):new Float32Array([0]),f=new Float32Array(o.length),d=l.length,h=c.length,p=u.length,m=s.length,g=0,v=0,y=0,b=0,x=0;x<o.length;++x)f[x]=l[g++]+(o[x]-s[v++])*c[y++]/Math.sqrt(u[b++]+r),g>=d&&(g=0),v>=m&&(v=0),y>=h&&(y=0),b>=p&&(b=0);return Wn(f,t.shape)},e.prototype.localResponseNormalization4D=function(t,e,n,r,i){Zl(t,"localResponseNormalization4D");var a=t.shape[3],o=a-1,s=this.readSync(t.dataId),u=t.size,c=new Float32Array(u);function l(t){for(var n=t%a,r=t-n+Math.max(0,n-e),i=t-n+Math.min(n+e,o),u=0;r<=i;r++){var c=s[r];u+=c*c}return u}for(var f=0;f<u;f++){var d=l(f),h=s[f]*Math.pow(n+r*d,-i);c[f]=h}return Wn(c,t.shape)},e.prototype.LRNGrad=function(t,e,n,r,i,a,o){Zl(t,"LRNGrad");for(var s=t.shape[3],u=this.readSync(t.dataId),c=this.readSync(e.dataId),l=this.readSync(n.dataId),f=new Float32Array(t.size),d=t.size,h=0;h<d;h++){for(var p=h%s,m=h-p+Math.max(0,p-r),g=h-p+Math.min(s,p+r+1),v=0,y=m;y<g;y++)v+=Math.pow(c[y],2);for(v=a*v+i,y=m;y<g;y++){var b=-2*a*o*c[y]*l[h]/v;h===y&&(b+=Math.pow(v,-o)),b*=u[h],f[y]+=b}}return Wn(f,t.shape)},e.prototype.multinomial=function(t,e,n,r){Zl(t,"multinomial");for(var i=e?t:ca(t),a=i.shape[0],o=i.shape[1],s=$n([a,n],"int32"),u=this.readSync(s.dataId),c=this.readSync(i.dataId),l=0;l<a;++l){var f=l*o,d=new Float32Array(o-1);d[0]=c[f];for(var h=1;h<d.length;++h)d[h]=d[h-1]+c[f+h];for(var p=Ps(r.toString()),m=l*n,g=0;g<n;++g){var v=p();u[m+g]=d.length;for(var y=0;y<d.length;y++)if(v<d[y]){u[m+g]=y;break}}}return s},e.prototype.oneHot=function(t,e,n,r){Zl(t,"oneHot");var i=new Float32Array(t.size*e);i.fill(r);for(var a=this.readSync(t.dataId),o=0;o<t.size;++o)a[o]>=0&&a[o]<e&&(i[o*e+a[o]]=n);return Bn(i,[t.size,e],"int32")},e.prototype.nonMaxSuppression=function(t,e,n,r,i){return Zl(t,"nonMaxSuppression"),Pa(this.readSync(t.dataId),this.readSync(e.dataId),n,r,i)},e.prototype.fft=function(t){return this.fftBatch(t,!1)},e.prototype.ifft=function(t){return this.fftBatch(t,!0)},e.prototype.fftBatch=function(t,e){for(var n=t.shape[0],r=t.shape[1],i=ar(t.shape,"float32"),a=ar(t.shape,"float32"),o=Rn(t).as2D(n,r),s=Fn(t).as2D(n,r),u=0;u<n;u++)for(var c=o.slice([u,0],[1,r]),l=s.slice([u,0],[1,r]),f=Mn(c,l),d=this.readSync(this.fftImpl(f,e).dataId),h=0;h<r;h++){var p=Da(d,h);i.values[u*r+h]=p.real,a.values[u*r+h]=p.imag}return Mn(i.toTensor(),a.toTensor()).as2D(n,r)},e.prototype.fftImpl=function(t,e){var n=t.as1D(),r=n.size;if(this.isExponentOf2(r)){var i=this.fftRadix2(n,r,e).as2D(t.shape[0],t.shape[1]);return e&&(i=Mn(Rn(i).div(Ln(r)),Fn(i).div(Ln(r)))),i}var a=this.readSync(t.dataId),o=function(t){for(var e=new Float32Array(t.length/2),n=new Float32Array(t.length/2),r=0;r<t.length;r+=2)e[r/2]=t[r],n[r/2]=t[r+1];return{real:e,imag:n}}(this.fourierTransformByMatmul(a,r,e));return Mn(o.real,o.imag).as2D(t.shape[0],t.shape[1])},e.prototype.isExponentOf2=function(t){return 0==(t&t-1)},e.prototype.fftRadix2=function(t,e,n){if(1===e)return t;var r=this.readSync(t.dataId),i=e/2,a=function(t){for(var e=Math.ceil(t.length/4),n=new Float32Array(e),r=new Float32Array(e),i=0;i<t.length;i+=4)n[Math.floor(i/4)]=t[i],r[Math.floor(i/4)]=t[i+1];return{real:n,imag:r}}(r),o=Mn(a.real,a.imag).as1D(),s=function(t){for(var e=Math.floor(t.length/4),n=new Float32Array(e),r=new Float32Array(e),i=2;i<t.length;i+=4)n[Math.floor(i/4)]=t[i],r[Math.floor(i/4)]=t[i+1];return{real:n,imag:r}}(r),u=Mn(s.real,s.imag).as1D();o=this.fftRadix2(o,i,n),u=this.fftRadix2(u,i,n);var c=function(t,e){for(var n=new Float32Array(t/2),r=new Float32Array(t/2),i=0;i<Math.ceil(t/2);i++){var a=(e?2:-2)*Math.PI*(i/t);n[i]=Math.cos(a),r[i]=Math.sin(a)}return{real:n,imag:r}}(e,n),l=Mn(c.real,c.imag).mul(u),f=o.add(l),d=o.sub(l),h=Rn(f).concat(Rn(d)),p=Fn(f).concat(Fn(d));return Mn(h,p).as1D()},e.prototype.fourierTransformByMatmul=function(t,e,n){for(var r=new Float32Array(2*e),i=0;i<e;i++){for(var a=0,o=0,s=0;s<e;s++){var u=Ra(i*s,e,n),c=Da(t,s);a+=c.real*u.real-c.imag*u.imag,o+=c.real*u.imag+c.imag*u.real}n&&(a/=e,o/=e),Ma(r,a,o,i)}return r},e.prototype.depthToSpace=function(t,e,n){C("NHWC"===n,function(){return"Only NHWC dataFormat supported on CPU for depthToSpace. Got "+n}),C(e>1,function(){return"blockSize should be > 1 for depthToSpace, but was: "+e});for(var r=t.shape[0],i=t.shape[1],a=t.shape[2],o=t.shape[3],s=i*e,u=a*e,c=o/(e*e),l=this.readSync(t.dataId),f=new Float32Array(r*s*u*c),d=0,h=0;h<r;++h)for(var p=0;p<s;++p)for(var m=Math.floor(p/e),g=p%e,v=0;v<u;++v)for(var y=Math.floor(v/e),b=(g*e+v%e)*c,x=0;x<c;++x){var w=x+b+o*(y+a*(m+i*h));f[d++]=l[w]}return Wn(f,[r,s,u,c])},e.prototype.broadcastedBinaryOp=function(t,e,n,r){var i=Ur(t.shape,e.shape),a=ar(i,n),o=this.readSync(t.dataId),s=this.readSync(e.dataId),u=zr(t.shape,i),c=zr(e.shape,i),l=a.values;if(u.length+c.length===0)for(var f=0;f<l.length;++f)l[f]=r(o[f%o.length],s[f%s.length]);else{var d=this.bufferSync(t),h=this.bufferSync(e),p=function(n){var i=a.indexToLoc(n),f=i.slice(-t.rank);u.forEach(function(t){return f[t]=0});var p=d.locToIndex(f),m=i.slice(-e.rank);c.forEach(function(t){return m[t]=0});var g=h.locToIndex(m);l[n]=r(o[p],s[g])};for(f=0;f<l.length;++f)p(f)}return a.toTensor()},e.prototype.broadcastedBinaryComplexOp=function(t,e,n){var r=Ur(t.shape,e.shape),i=ar(r,"float32"),a=ar(r,"float32"),o=this.readSync(t.dataId),s=this.readSync(e.dataId),u=zr(t.shape,r),c=zr(e.shape,r),l=i.values,f=a.values;if(u.length+c.length===0)for(var d=0;d<l.length;d++){var h=d%o.length,p=d%s.length,m=n(o[2*h],o[2*h+1],s[2*p],s[2*p+1]);l[d]=m.real,f[d]=m.imag}else{var g=this.bufferSync(this.data.get(t.dataId).complexTensors.real),v=this.bufferSync(this.data.get(e.dataId).complexTensors.real),y=function(r){var a=i.indexToLoc(r),d=a.slice(-t.rank);u.forEach(function(t){return d[t]=0});var h=g.locToIndex(d),p=a.slice(-e.rank);c.forEach(function(t){return p[t]=0});var m=v.locToIndex(p),y=n(o[2*h],o[2*h+1],s[2*m],s[2*m+1]);l[r]=y.real,f[r]=y.imag};for(d=0;d<l.length;d++)y(d)}return this.complex(i.toTensor(),a.toTensor())},e.prototype.split=function(t,e,n){return Va(t,e,n)},e.prototype.dispose=function(){},e.prototype.floatPrecision=function(){return 32},e.prototype.epsilon=function(){return 1e-7},e.prototype.cropAndResize=function(t,e,n,r,i,a){for(var o=t.shape,s=o[0],u=o[1],c=o[2],l=o[3],f=e.shape[0],d=r[0],h=r[1],p=ar([f,d,h,l],"float32"),m=this.readSync(e.dataId),g=this.readSync(n.dataId),v=this.readSync(t.dataId),y=t.strides,b=p.strides,x=0;x<f;x++){var w=4*x,k=m[w],_=m[w+1],E=m[w+2],O=m[w+3],S=g[x];if(!(S>=s))for(var C=d>1?(E-k)*(u-1)/(d-1):0,A=h>1?(O-_)*(c-1)/(h-1):0,N=0;N<d;N++){var T=d>1?k*(u-1)+N*C:.5*(k+E)*(u-1);if(T<0||T>u-1)for(var I=0;I<h;I++)for(var D=0;D<l;D++){var M=D+I*b[2]+N*b[1]+x*b[0];p.values[M]=a}else if("bilinear"===i){var R=Math.floor(T),F=Math.ceil(T),j=T-R;for(I=0;I<h;I++)if((H=h>1?_*(c-1)+I*A:.5*(_+O)*(c-1))<0||H>c-1)for(D=0;D<l;D++)M=D+I*b[2]+N*b[1]+x*b[0],p.values[M]=a;else{var P=Math.floor(H),L=Math.ceil(H),z=H-P;for(D=0;D<l;D++){var B=v[M=D+P*y[2]+R*y[1]+S*y[0]],U=v[M=D+L*y[2]+R*y[1]+S*y[0]],W=v[M=D+P*y[2]+F*y[1]+S*y[0]],V=B+(U-B)*z,q=W+(v[M=D+L*y[2]+F*y[1]+S*y[0]]-W)*z;M=D+I*b[2]+N*b[1]+x*b[0],p.values[M]=V+(q-V)*j}}}else for(I=0;I<h;++I){var H;if((H=h>1?_*(c-1)+I*A:.5*(_+O)*(c-1))<0||H>c-1)for(D=0;D<l;D++)M=D+I*b[2]+N*b[1]+x*b[0],p.values[M]=a;else{var G=Math.round(H),$=Math.round(T);for(D=0;D<l;D++){var K=D+G*y[2]+$*y[1]+S*y[0],X=D+I*b[2]+N*b[1]+x*b[0];p.values[X]=v[K]}}}}}return p.toTensor()},e.prototype.sparseToDense=function(t,e,n,r){var i=Gi(0,t,n),a=i.sliceRank,o=i.numUpdates,s=i.sliceSize,u=i.strides,c=i.outputSize;return this.scatter(t,e,n,c,s,o,a,u,r,!1)},e.prototype.gatherND=function(t,e){var n=e.shape,r=n[n.length-1],i=Bi(t,e),a=i[0],o=i[1],s=i[2],u=i[3];if(0===o)return jn([],a,t.dtype);for(var c=new wt([o,s],t.dtype),l=this.readSync(e.dataId),f=this.readSync(t.dataId),d=0;d<o;d++){for(var h=[],p=0,m=0;m<r;m++){var g=l[d*r+m];p+=g*u[m],h.push(g)}if(p<0||p>=t.size/s)throw new Error("Invalid indices: "+h+" does not index into "+t.shape);for(var v=0;v<s;v++)c.values[d*s+v]=f[p*s+v]}return c.toTensor().reshape(a)},e.prototype.scatterND=function(t,e,n){var r=Gi(0,t,n),i=r.sliceRank,a=r.numUpdates,o=r.sliceSize,s=r.strides,u=r.outputSize,c=Ln(0);return this.scatter(t,e,n,u,o,a,i,s,c,!0)},e.prototype.fill=function(t,e,n){var r=W(n=n||Z(e),I(t));return r.fill(e),Wt.makeTensor(r,t,n,this)},e.prototype.onesLike=function(t){if("string"===t.dtype)throw new Error("onesLike is not supported for string tensors");return this.fill(t.shape,1,t.dtype)},e.prototype.zerosLike=function(t){var e=W(t.dtype,I(t.shape));return this.makeOutput(e,t.shape,t.dtype)},e.prototype.linspace=function(t,e,n){return Na(t,e,n)},e.prototype.scatter=function(t,e,n,r,i,a,o,s,u,c){var l=[r/i,i],f=this.readSync(t.dataId),d=this.readSync(e.dataId);if(0===r)return jn([],n,e.dtype);var h=new wt(l,e.dtype);h.values.fill(this.readSync(u.dataId)[0]);for(var p=0;p<a;p++){for(var m=[],g=0,v=0;v<o;v++){var y=f[p*o+v];m.push(y),g+=y*s[v]}if(g<0||g>=r/i)throw new Error("Invalid indices: "+m+" does not index into "+n);for(var b=0;b<i;b++)c?h.values[g*i+b]+=d[p*i+b]:h.values[g*i+b]=0===e.rank?d[0]:d[p*i+b]}return h.toTensor().reshape(n)},e}(ha);function rf(t,e){return{kernelName:t,backendName:"cpu",kernelFunc:function(n){var r=n.inputs,i=n.backend,a=r,o=a.a,s=a.b,u=i;Zl([o,s],t);var c=u.data.get(o.dataId).values,l=u.data.get(s.dataId).values,f=e(o.shape,s.shape,c,l,o.dtype),d=f[0],h=f[1];return{dataId:u.write(d,h,o.dtype),shape:h,dtype:o.dtype}}}}function af(t){return function(e,n,r,i,a){var o=Ur(e,n),s=o.length,u=et(o),c=U(a,I(o)),l=e.length,f=n.length,d=et(e),h=et(n),p=zr(e,o),m=zr(n,o);if(p.length+m.length===0)for(var g=0;g<c.length;++g)c[g]=t(r[g%r.length],i[g%i.length]);else{var v=function(e){var n=ft(e,s,u),a=n.slice(-l);p.forEach(function(t){return a[t]=0});var o=lt(a,l,d),g=n.slice(-f);m.forEach(function(t){return g[t]=0});var v=lt(g,f,h);c[e]=t(r[o],i[v])};for(g=0;g<c.length;++g)v(g)}return[c,o]}}Wt.registerBackend("cpu",function(){return new nf},1);var of=af(function(t,e){return t/e}),sf=rf(Or,of),uf={kernelName:"MaxPoolWithArgmax",backendName:"cpu",kernelFunc:function(t){var e=t.inputs,n=t.attrs,r=t.backend,i=e.x,a=n,o=a.filterSize,s=a.strides,u=a.pad,c=a.includeBatchInIndex,l=r;Zl(i,"MaxPoolWithArgmax");var f=l.data.get(i.dataId).values,d=ma(i.shape,o,s,[1,1],u),h=function(t,e,n,r,i){var a=Ql(t,0,n,et(e),i,"max"),o=tf(t,e,n,i,!0,r);return[a.values,o.values]}(f,i.shape,i.dtype,c,d),p=h[0],m=h[1],g=l.write(p,d.outShape,i.dtype),v=l.write(m,d.outShape,i.dtype);return[{dataId:g,shape:d.outShape,dtype:i.dtype},{dataId:v,shape:d.outShape,dtype:"int32"}]}},cf={kernelName:"NonMaxSuppressionV5",backendName:"cpu",kernelFunc:function(t){var e=t.inputs,n=t.backend,r=t.attrs,i=e,a=i.boxes,o=i.scores,s=r,u=s.maxOutputSize,c=s.iouThreshold,l=s.scoreThreshold,f=s.softNmsSigma,d=n;Zl(a,"NonMaxSuppressionWithScore");var h=La(d.data.get(a.dataId).values,d.data.get(o.dataId).values,u,c,l,f);return[h.selectedIndices,h.selectedScores]}},lf={kernelName:"Square",backendName:"cpu",kernelFunc:function(t){var e=t.inputs,n=t.backend,r=e.x,i=n;Zl(r,"square");for(var a=i.data.get(r.dataId).values,o=new Float32Array(a.length),s=0;s<a.length;++s){var u=a[s];o[s]=u*u}return{dataId:i.write(o,r.shape,r.dtype),shape:r.shape,dtype:r.dtype}}},ff=af(function(t,e){var n=t-e;return n*n});function df(t,e,n,r,i){for(var a=I(e),o=e.length,s=et(e),u=et(i),c=U(n,I(i)),l=0;l<a;++l){for(var f=ft(l,o,s),d=new Array(f.length),h=0;h<d.length;h++)d[h]=f[r[h]];c[lt(d,o,u)]=t[l]}return c}for(var hf=0,pf=[cf,lf,rf(Cr,ff),sf,{kernelName:"Transpose",backendName:"cpu",kernelFunc:function(t){var e=t.inputs,n=t.attrs,r=t.backend,i=e.x,a=n.perm,o=r;Zl(i,"transpose");for(var s=i.shape.length,u=new Array(s),c=0;c<u.length;c++)u[c]=i.shape[a[c]];var l=df(o.data.get(i.dataId).values,i.shape,i.dtype,a,u);return{dataId:o.write(l,u,i.dtype),shape:u,dtype:i.dtype}}},uf];hf<pf.length;hf++)y(pf[hf]);for(var mf,gf=0,vf=[{kernelName:"FromPixels",backendName:"webgl",kernelFunc:function(t){var e=t.inputs,n=t.backend,r=t.attrs,i=e.pixels,a=r.numChannels,o="undefined"!=typeof HTMLVideoElement&&i instanceof HTMLVideoElement,s="undefined"!=typeof HTMLImageElement&&i instanceof HTMLImageElement,u=o?[i.videoWidth,i.videoHeight]:[i.width,i.height],c=u[0],l=u[1],d=[l,c],h=[l,c,a];(s||o)&&(null==mf&&(mf=document.createElement("canvas").getContext("2d")),mf.canvas.width=c,mf.canvas.height=l,mf.drawImage(i,0,0,c,l),i=mf.canvas);var p=n.makeTensorInfo(d,"int32");n.texData.get(p.dataId).usage=Gt.PIXELS,n.gpgpu.uploadPixelDataToTexture(n.getTexture(p.dataId),i);var m=f().getBool("WEBGL_PACK")?new function(t){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0;var e=Xa(),n=t[0],r=t[1];this.outputShape=t,this.userCode="\n void main() {\n ivec3 coords = getOutputCoords();\n int texR = coords[0];\n int texC = coords[1];\n int depth = coords[2];\n\n vec4 result = vec4(0.);\n\n for(int row=0; row<=1; row++) {\n for(int col=0; col<=1; col++) {\n texC = coords[1] + row;\n depth = coords[2] + col;\n\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2("+r+".0, "+n+".0);\n vec4 values = "+e.texture2D+"(A, uv);\n float value;\n if (depth == 0) {\n value = values.r;\n } else if (depth == 1) {\n value = values.g;\n } else if (depth == 2) {\n value = values.b;\n } else if (depth == 3) {\n value = values.a;\n }\n\n result[row * 2 + col] = floor(value * 255.0 + 0.5);\n }\n }\n\n "+e.output+" = result;\n }\n "}(h):new function(t){this.variableNames=["A"];var e=Xa(),n=t[0],r=t[1];this.outputShape=t,this.userCode="\n void main() {\n ivec3 coords = getOutputCoords();\n int texR = coords[0];\n int texC = coords[1];\n int depth = coords[2];\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2("+r+".0, "+n+".0);\n\n vec4 values = "+e.texture2D+"(A, uv);\n float value;\n if (depth == 0) {\n value = values.r;\n } else if (depth == 1) {\n value = values.g;\n } else if (depth == 2) {\n value = values.b;\n } else if (depth == 3) {\n value = values.a;\n }\n\n setOutput(floor(value * 255.0 + 0.5));\n }\n "}(h),g=n.runWebGLProgram(m,[p],"int32");return n.disposeData(p.dataId),g}},{kernelName:Or,backendName:"webgl",kernelFunc:function(t){var e=t.inputs,n=t.backend,r=e;return function(t,e,n){var r=new mo("\nif (a == b) {\n return 1.0;\n};\nreturn a / b;",t.shape,e.shape);return f().getBool("WEBGL_PACK_BINARY_OPERATIONS")&&(r=new vo("\n // vec4 one = vec4(equal(a, b));\n // return one + (vec4(1.0) - one) * a / b;\n vec4 result = a / b;\n if(a.x == b.x) {\n result.x = 1.;\n }\n if(a.y == b.y) {\n result.y = 1.;\n }\n if(a.z == b.z) {\n result.z = 1.;\n }\n if(a.w == b.w) {\n result.w = 1.;\n }\n\n return result;\n",t.shape,e.shape,!0)),n.runWebGLProgram(r,[t,e],"float32")}(r.a,r.b,n)}},{kernelName:"NonMaxSuppressionV5",backendName:"webgl",kernelFunc:function(t){var e=t.inputs,n=t.backend,r=t.attrs;vn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");var i=e,a=i.boxes,o=i.scores,s=r,u=s.maxOutputSize,c=s.iouThreshold,l=s.scoreThreshold,f=s.softNmsSigma,d=n,h=La(d.readSync(a.dataId),d.readSync(o.dataId),u,c,l,f);return[h.selectedIndices,h.selectedScores]}},{kernelName:"Square",backendName:"webgl",kernelFunc:function(t){var e=t.inputs,n=t.backend,r=e.x,i=n,a=new ss(r.shape,"return x * x;");return i.runWebGLProgram(a,[r],r.dtype)}},{kernelName:Cr,backendName:"webgl",kernelFunc:function(t){var e=t.inputs,n=t.backend,r=e,i=r.a,a=r.b,o=n,s=f().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new vo("return (a - b) * (a - b);",i.shape,a.shape):new mo("return (a - b) * (a - b);",i.shape,a.shape);return o.compileAndRun(s,[i,a])}},{kernelName:"Transpose",backendName:"webgl",kernelFunc:function(t){for(var e,n=t.inputs,r=t.attrs,i=t.backend,a=n.x,o=r.perm,s=i,u=a.shape.length,c=new Array(u),l=0;l<c.length;l++)c[l]=a.shape[o[l]];if(s.shouldExecuteOnCPU([a])){var d=df(s.texData.get(a.dataId).values,a.shape,a.dtype,o,c);e=s.makeTensorInfo(c,a.dtype),s.texData.get(e.dataId).values=d}else e=function(t,e,n){var r=f().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new function(t,e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0;for(var n=new Array(t.length),r=0;r<n.length;r++)n[r]=t[e[r]];if(this.outputShape=n,this.rank=n.length,this.rank>6)throw Error("Packed transpose for rank "+this.rank+" is not yet supported.");var i=oo(this.rank),a=$a("rc",this.rank),o=new Array(this.rank);for(r=0;r<e.length;r++)o[e[r]]=a[r];var s="vec2("+o.slice(-2).join()+")",u="++"+a[this.rank-1]+" < "+n[this.rank-1],c="getChannel(getA("+o.join()+"), "+s+")";this.userCode="\n void main() {\n "+i+" rc = getOutputCoords();\n vec4 result = vec4(0.);\n result[0] = "+c+";\n if("+u+") {\n result[1] = "+c+";\n }\n --"+a[this.rank-1]+";\n if(++"+a[this.rank-2]+" < "+n[this.rank-2]+") {\n result[2] = "+c+";\n if("+u+") {\n result[3] = "+c+";\n }\n }\n setOutput(result);\n }\n "}(t.shape,e):new function(t,e){this.variableNames=["A"];for(var n=new Array(t.length),r=0;r<n.length;r++)n[r]=t[e[r]];this.outputShape=n,this.rank=n.length;var i=oo(this.rank),a=function(t){var e=t.length;if(e>6)throw Error("Transpose for rank "+e+" is not yet supported");for(var n=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u","resRC.v"],r=new Array(e),i=0;i<t.length;i++)r[t[i]]=n[i];return r.join()}(e);this.userCode="\n void main() {\n "+i+" resRC = getOutputCoords();\n setOutput(getA("+a+"));\n }\n "}(t.shape,e);return n.runWebGLProgram(r,[t],t.dtype)}(a,o,s);return e}},{kernelName:"MaxPoolWithArgmax",backendName:"webgl",kernelFunc:function(t){var e=t.inputs,n=t.attrs,r=t.backend,i=e.x,a=n,o=a.filterSize,s=a.strides,u=a.pad,c=a.includeBatchInIndex,l=r;C(4===i.shape.length,function(){return"Error in maxPool: input must be rank 4 but got rank "+i.shape.length+"."});var f=[1,1];C(Oa(s,f),function(){return"Error in maxPool: Either strides or dilations must be 1. Got strides "+s+" and dilations '"+f+"'"});var d=ma(i.shape,o,s,f,u),h=function(t,e,n,r){var i=new Yo(n,"max",!1),a=r.runWebGLProgram(i,[t],"float32");return i=new Yo(n,"max",!0,!0,e),[a,r.runWebGLProgram(i,[t],"float32")]}(i,c,d,l);return[h[0],h[1]]}}];gf<vf.length;gf++)y(vf[gf]);for(var yf=0,bf=[{kernelName:_r,inputsToSave:["a","b"],gradFunc:function(t,e){var n=e[0],r=e[1],i=Ur(n.shape,r.shape);return{a:function(){var e=t,r=Br(n.shape,i);return r.length>0&&(e=e.sum(r)),e.reshape(n.shape)},b:function(){var e=t,n=Br(r.shape,i);return n.length>0&&(e=e.sum(n)),e.reshape(r.shape)}}}},{kernelName:"AddN",saveAllInputs:!0,gradFunc:function(t,e){var n={};return e.forEach(function(e,r){n[r]=function(){return t.clone()}}),n}},{kernelName:Ir,gradFunc:function(t,e,n){for(var r=n,i=r.inputShape,a=r.shape,o=Array.from(a),s=i.length-1;s>=0;s--)if(i[s]===a[s])o[s]=1;else if(1!==i[s])throw new Error("broadcastTo(): ["+i+"] cannot be broadcast to ["+a+"].");var u=[];for(s=0;s<o.length;s++)o[s]>1&&u.push(s);return{x:function(){return t.sum(u,!0)}}}},{kernelName:Or,inputsToSave:["a","b"],gradFunc:function(t,e){var n=e[0],r=e[1],i=Ur(n.shape,r.shape);return{a:function(){var e=zi(t,r.toFloat()),a=Br(n.shape,i);return a.length>0?Wc(e,a).reshape(n.shape):e},b:function(){var e=t.mul(n.toFloat()),a=Br(r.shape,i);a.length>0&&(e=Wc(e,a).reshape(r.shape));var o=Iu(r);return oi(zi(e,o.toFloat()))}}}},{kernelName:"FusedBatchNorm",inputsToSave:["x","mean","variance","scale"],gradFunc:function(t,e,n){var r=n.varianceEpsilon,i=e[0],a=e[1],o=e[2],s=e[3],u=Bs(i),c=null==s?Ln(1):s,l=Br(a.shape,u.shape),f=[];if(1===a.rank){for(var d=0;d<u.shape.length-1;++d)f.push(u.shape[d]);f.push(1)}var h=Pi(i,a),p=Di(t,c),m=ci(Lr(o,Ln(r))),g=Di(Di(Di(m,m),m),Ln(-.5));return{x:function(){return 1===a.rank?dr(Di(Di(t,cu(m.as4D(1,1,1,a.shape[0]),f)),c),i.shape):dr(Di(Di(t,m),c),i.shape)},mean:function(){var t=Di(Di(m,Ln(-1)),p);return 1===a.rank&&(t=Wc(t,l)),dr(t,a.shape)},variance:function(){var t=Di(Di(g,h),p);return 1===a.rank&&(t=Wc(t,l)),dr(t,a.shape)},scale:function(){var e=Di(h,m),n=Di(t,e);return 1===a.rank&&(n=Wc(n,l)),dr(n,a.shape)},offset:function(){var e=t;return 1===a.rank&&(e=Wc(e,l)),dr(e,a.shape)}}}},{kernelName:Mr,gradFunc:function(t){return{x:function(){return t.toFloat()}}}},{kernelName:Dr,inputsToSave:["indices"],gradFunc:function(t,e){var n=e[0];return{indices:function(){return $n(n.shape,"float32")}}}},{kernelName:Fr,inputsToSave:["x"],gradFunc:function(t,e,n){var r=e[0],i=n.paddings.map(function(t){return t[0]});return{x:function(){return t.slice(i,r.shape)}}}},{kernelName:"Square",inputsToSave:["x"],gradFunc:function(t,e){var n=e[0];return{x:function(){return t.mul(n.toFloat().mul(2))}}}},{kernelName:Cr,inputsToSave:["a","b"],gradFunc:function(t,e){var n=e[0],r=e[1],i=Ln(2);return{a:function(){return Di(t,Di(i,Pi(n,r)))},b:function(){return Di(t,Di(i,Pi(r,n)))}}}},{kernelName:Rr,inputsToSave:["x"],gradFunc:function(t,e,n){var r=e[0],i=n.reps;return{x:function(){var e=Zn(r);if(1===r.rank)for(var n=0;n<i[0];++n)e=e.add(t.slice([n*r.shape[0]],[r.shape[0]]));else if(2===r.rank)for(n=0;n<i[0];++n)for(var a=0;a<i[1];++a)e=e.add(t.slice([n*r.shape[0],a*r.shape[1]],[r.shape[0],r.shape[1]]));else if(3===r.rank)for(n=0;n<i[0];++n)for(a=0;a<i[1];++a)for(var o=0;o<i[2];++o)e=e.add(t.slice([n*r.shape[0],a*r.shape[1],o*r.shape[2]],[r.shape[0],r.shape[1],r.shape[2]]));else{if(4!==r.rank)throw new Error("Gradient for tile operation is not implemented for rank-"+r.rank+" tensors yet.");for(n=0;n<i[0];++n)for(a=0;a<i[1];++a)for(o=0;o<i[2];++o)for(var s=0;s<i[3];++s)e=e.add(t.slice([n*r.shape[0],a*r.shape[1],o*r.shape[2],s*r.shape[3]],[r.shape[0],r.shape[1],r.shape[2],r.shape[3]]))}return e}}}},{kernelName:"Transpose",gradFunc:function(t,e,n){var r=An(n.perm);return{x:function(){return fa(t,r)}}}}];yf<bf.length;yf++)b(bf[yf]);var xf=function(){function t(){}return t.prototype.fetch=function(t,e){return fetch(t,e)},t.prototype.now=function(){return performance.now()},t.prototype.encode=function(t,e){if("utf-8"!==e&&"utf8"!==e)throw new Error("Browser's encoder only supports utf-8, but got "+e);return null==this.textEncoder&&(this.textEncoder=new TextEncoder),this.textEncoder.encode(t)},t.prototype.decode=function(t,e){return new TextDecoder(e).decode(t)},t}();f().get("IS_BROWSER")&&f().setPlatform("browser",new xf);var wf,kf=function(){function t(){this.util=n(478),this.textEncoder=new this.util.TextEncoder}return t.prototype.fetch=function(t,e){return null!=f().global.fetch?f().global.fetch(t,e):(null==wf&&(wf=n(479)),wf(t,e))},t.prototype.now=function(){var t=r.hrtime();return 1e3*t[0]+t[1]/1e6},t.prototype.encode=function(t,e){if("utf-8"!==e&&"utf8"!==e)throw new Error("Node built-in encoder only supports utf-8, but got "+e);return this.textEncoder.encode(t)},t.prototype.decode=function(t,e){return 0===t.length?"":new this.util.TextDecoder(e).decode(t)},t}();f().get("IS_NODE")&&f().setPlatform("node",new kf);var _f={float32:4,int32:4,uint16:2,uint8:1,bool:1},Ef=4;function Of(t,e){for(var n={},r=0,i=function(e){var i=e.name,a=e.dtype,o=e.shape,s=I(o),u=void 0;if("quantization"in e){var c=e.quantization;if("uint8"!==c.dtype&&"uint16"!==c.dtype)throw new Error("Weight "+e.name+" has unknown quantization dtype "+c.dtype+". Supported quantization dtypes are: 'uint8' and 'uint16'.");var l=_f[c.dtype],f=t.slice(r,r+s*l),d="uint8"===c.dtype?new Uint8Array(f):new Uint16Array(f);if("float32"===a)u=Float32Array.from(d,function(t){return t*c.scale+c.min});else{if("int32"!==a)throw new Error("Unsupported dtype in weight '"+i+"': "+a);u=Int32Array.from(d,function(t){return Math.round(t*c.scale+c.min)})}r+=s*l}else if("string"===a){var h=I(e.shape);u=[];for(var p=0;p<h;p++){var m=new Uint32Array(t.slice(r,r+Ef))[0];r+=Ef;var g=new Uint8Array(t.slice(r,r+m));u.push(g),r+=m}}else{var v=_f[a];if(f=t.slice(r,r+s*v),"float32"===a)u=new Float32Array(f);else if("int32"===a)u=new Int32Array(f);else{if("bool"!==a)throw new Error("Unsupported dtype in weight '"+i+"': "+a);u=new Uint8Array(f)}r+=s*v}n[i]=jn(u,o,a)},a=0,o=e;a<o.length;a++)i(o[a]);return n}var Sf=void 0!==i&&("undefined"==typeof Blob||"undefined"==typeof atob||"undefined"==typeof btoa);function Cf(t){return Sf?i.byteLength(t):new Blob([t]).size}function Af(t){var e=0;t.forEach(function(t){e+=t.byteLength});var n=new Uint8Array(e),r=0;return t.forEach(function(t){n.set(new Uint8Array(t),r),r+=t.byteLength}),n.buffer}function Nf(t){for(t=t.trim();t.endsWith("/");)t=t.slice(0,t.length-1);var e=t.split("/");return e[e.length-1]}function Tf(t){if(t.modelTopology instanceof ArrayBuffer)throw new Error("Expected JSON model topology, received ArrayBuffer.");return{dateSaved:new Date,modelTopologyType:"JSON",modelTopologyBytes:null==t.modelTopology?0:Cf(JSON.stringify(t.modelTopology)),weightSpecsBytes:null==t.weightSpecs?0:Cf(JSON.stringify(t.weightSpecs)),weightDataBytes:null==t.weightData?0:t.weightData.byteLength}}var If=function(){function t(){this.saveRouters=[],this.loadRouters=[]}return t.getInstance=function(){return null==t.instance&&(t.instance=new t),t.instance},t.registerSaveRouter=function(e){t.getInstance().saveRouters.push(e)},t.registerLoadRouter=function(e){t.getInstance().loadRouters.push(e)},t.getSaveHandlers=function(e){return t.getHandlers(e,"save")},t.getLoadHandlers=function(e,n){return t.getHandlers(e,"load",n)},t.getHandlers=function(e,n,r){var i=[];return("load"===n?t.getInstance().loadRouters:t.getInstance().saveRouters).forEach(function(t){var n=t(e,r);null!==n&&i.push(n)}),i},t}(),Df="://",Mf=function(){function t(){this.managers={}}return t.getInstance=function(){return null==t.instance&&(t.instance=new t),t.instance},t.registerManager=function(e,n){C(null!=e,function(){return"scheme must not be undefined or null."}),e.endsWith(Df)&&(e=e.slice(0,e.indexOf(Df))),C(e.length>0,function(){return"scheme must not be an empty string."});var r=t.getInstance();C(null==r.managers[e],function(){return"A model store manager is already registered for scheme '"+e+"'."}),r.managers[e]=n},t.getManager=function(t){var e=this.getInstance().managers[t];if(null==e)throw new Error("Cannot find model manager for scheme '"+t+"'");return e},t.getSchemes=function(){return Object.keys(this.getInstance().managers)},t}();function Rf(t){if(-1===t.indexOf(Df))throw new Error("The url string provided does not contain a scheme. Supported schemes are: "+Mf.getSchemes().join(","));return{scheme:t.split(Df)[0],path:t.split(Df)[1]}}function Ff(t,e,n){return void 0===n&&(n=!1),u(this,void 0,void 0,function(){var r,i,a,o,s,u,l,f,d;return c(this,function(c){switch(c.label){case 0:return C(t!==e,function(){return"Old path and new path are the same: '"+t+"'"}),C((r=If.getLoadHandlers(t)).length>0,function(){return"Copying failed because no load handler is found for source URL "+t+"."}),C(r.length<2,function(){return"Copying failed because more than one ("+r.length+") load handlers for source URL "+t+"."}),i=r[0],C((a=If.getSaveHandlers(e)).length>0,function(){return"Copying failed because no save handler is found for destination URL "+e+"."}),C(a.length<2,function(){return"Copying failed because more than one ("+r.length+") save handlers for destination URL "+e+"."}),o=a[0],s=Rf(t).scheme,u=Rf(t).path,l=s===Rf(t).scheme,[4,i.load()];case 1:return f=c.sent(),n&&l?[4,Mf.getManager(s).removeModel(u)]:[3,3];case 2:c.sent(),c.label=3;case 3:return[4,o.save(f)];case 4:return d=c.sent(),!n||l?[3,6]:[4,Mf.getManager(s).removeModel(u)];case 5:c.sent(),c.label=6;case 6:return[2,d.modelArtifactsInfo]}})})}var jf="models_store",Pf="model_info_store";function Lf(){if(!f().getBool("IS_BROWSER"))throw new Error("Failed to obtain IndexedDB factory because the current environmentis not a web browser.");var t=window||self,e=t.indexedDB||t.mozIndexedDB||t.webkitIndexedDB||t.msIndexedDB||t.shimIndexedDB;if(null==e)throw new Error("The current browser does not appear to support IndexedDB.");return e}function zf(t){var e=t.result;e.createObjectStore(jf,{keyPath:"modelPath"}),e.createObjectStore(Pf,{keyPath:"modelPath"})}var Bf=function(){function t(t){if(this.indexedDB=Lf(),null==t||!t)throw new Error("For IndexedDB, modelPath must not be null, undefined or empty.");this.modelPath=t}return t.prototype.save=function(t){return u(this,void 0,void 0,function(){return c(this,function(e){if(t.modelTopology instanceof ArrayBuffer)throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");return[2,this.databaseAction(this.modelPath,t)]})})},t.prototype.load=function(){return u(this,void 0,void 0,function(){return c(this,function(t){return[2,this.databaseAction(this.modelPath)]})})},t.prototype.databaseAction=function(t,e){var n=this;return new Promise(function(t,r){var i=n.indexedDB.open("tensorflowjs",1);i.onupgradeneeded=function(){return zf(i)},i.onsuccess=function(){var a=i.result;if(null==e){var o=a.transaction(jf,"readonly"),s=o.objectStore(jf).get(n.modelPath);s.onsuccess=function(){if(null==s.result)return a.close(),r(new Error("Cannot find model with path '"+n.modelPath+"' in IndexedDB."));t(s.result.modelArtifacts)},s.onerror=function(t){return a.close(),r(s.error)},o.oncomplete=function(){return a.close()}}else{var u,c=Tf(e),l=a.transaction(Pf,"readwrite"),f=l.objectStore(Pf),d=f.put({modelPath:n.modelPath,modelArtifactsInfo:c});d.onsuccess=function(){var i=(u=a.transaction(jf,"readwrite")).objectStore(jf).put({modelPath:n.modelPath,modelArtifacts:e,modelArtifactsInfo:c});i.onsuccess=function(){return t({modelArtifactsInfo:c})},i.onerror=function(t){var e=(f=l.objectStore(Pf)).delete(n.modelPath);e.onsuccess=function(){return a.close(),r(i.error)},e.onerror=function(t){return a.close(),r(i.error)}}},d.onerror=function(t){return a.close(),r(d.error)},l.oncomplete=function(){null==u?a.close():u.oncomplete=function(){return a.close()}}}},i.onerror=function(t){return r(i.error)}})},t.URL_SCHEME="indexeddb://",t}(),Uf=function(t){return f().getBool("IS_BROWSER")&&!Array.isArray(t)&&t.startsWith(Bf.URL_SCHEME)?(e=t.slice(Bf.URL_SCHEME.length),new Bf(e)):null;var e};If.registerSaveRouter(Uf),If.registerLoadRouter(Uf);var Wf=function(){function t(){this.indexedDB=Lf()}return t.prototype.listModels=function(){return u(this,void 0,void 0,function(){var t=this;return c(this,function(e){return[2,new Promise(function(e,n){var r=t.indexedDB.open("tensorflowjs",1);r.onupgradeneeded=function(){return zf(r)},r.onsuccess=function(){var t=r.result,i=t.transaction(Pf,"readonly"),a=i.objectStore(Pf).getAll();a.onsuccess=function(){for(var t={},n=0,r=a.result;n<r.length;n++){var i=r[n];t[i.modelPath]=i.modelArtifactsInfo}e(t)},a.onerror=function(e){return t.close(),n(a.error)},i.oncomplete=function(){return t.close()}},r.onerror=function(t){return n(r.error)}})]})})},t.prototype.removeModel=function(t){return u(this,void 0,void 0,function(){var e=this;return c(this,function(n){var r;return t=(r=t).startsWith(Bf.URL_SCHEME)?r.slice(Bf.URL_SCHEME.length):r,[2,new Promise(function(n,r){var i=e.indexedDB.open("tensorflowjs",1);i.onupgradeneeded=function(){return zf(i)},i.onsuccess=function(){var e,a=i.result,o=a.transaction(Pf,"readwrite"),s=o.objectStore(Pf),u=s.get(t);u.onsuccess=function(){if(null==u.result)return a.close(),r(new Error("Cannot find model with path '"+t+"' in IndexedDB."));var i=s.delete(t),o=function(){var i=(e=a.transaction(jf,"readwrite")).objectStore(jf).delete(t);i.onsuccess=function(){return n(u.result.modelArtifactsInfo)},i.onerror=function(t){return r(u.error)}};i.onsuccess=o,i.onerror=function(t){return o(),a.close(),r(u.error)}},u.onerror=function(t){return a.close(),r(u.error)},o.oncomplete=function(){null==e?a.close():e.oncomplete=function(){return a.close()}}},i.onerror=function(t){return r(i.error)}})]})})},t}();if(f().getBool("IS_BROWSER"))try{Mf.registerManager(Bf.URL_SCHEME,new Wf)}catch(o){}var Vf="/",qf="tensorflowjs_models",Hf="info",Gf="model_topology",$f="weight_specs",Kf="weight_data",Xf="model_metadata";function Yf(t){return{info:[qf,t,Hf].join(Vf),topology:[qf,t,Gf].join(Vf),weightSpecs:[qf,t,$f].join(Vf),weightData:[qf,t,Kf].join(Vf),modelMetadata:[qf,t,Xf].join(Vf)}}function Jf(t){var e=t.split(Vf);if(e.length<3)throw new Error("Invalid key format: "+t);return e.slice(1,e.length-1).join(Vf)}var Zf=function(){function t(t){if(!f().getBool("IS_BROWSER")||"undefined"==typeof window||void 0===window.localStorage)throw new Error("The current environment does not support local storage.");if(this.LS=window.localStorage,null==t||!t)throw new Error("For local storage, modelPath must not be null, undefined or empty.");this.modelPath=t,this.keys=Yf(this.modelPath)}return t.prototype.save=function(t){return u(this,void 0,void 0,function(){var e,n,r;return c(this,function(a){if(t.modelTopology instanceof ArrayBuffer)throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");e=JSON.stringify(t.modelTopology),n=JSON.stringify(t.weightSpecs),r=Tf(t);try{return this.LS.setItem(this.keys.info,JSON.stringify(r)),this.LS.setItem(this.keys.topology,e),this.LS.setItem(this.keys.weightSpecs,n),this.LS.setItem(this.keys.weightData,function(t){if(Sf)return i.from(t).toString("base64");for(var e=new Uint8Array(t),n="",r=0,a=e.length;r<a;r++)n+=String.fromCharCode(e[r]);return btoa(n)}(t.weightData)),this.LS.setItem(this.keys.modelMetadata,JSON.stringify({format:t.format,generatedBy:t.generatedBy,convertedBy:t.convertedBy,userDefinedMetadata:t.userDefinedMetadata})),[2,{modelArtifactsInfo:r}]}catch(t){throw this.LS.removeItem(this.keys.info),this.LS.removeItem(this.keys.topology),this.LS.removeItem(this.keys.weightSpecs),this.LS.removeItem(this.keys.weightData),this.LS.removeItem(this.keys.modelMetadata),new Error("Failed to save model '"+this.modelPath+"' to local storage: size quota being exceeded is a possible cause of this failure: modelTopologyBytes="+r.modelTopologyBytes+", weightSpecsBytes="+r.weightSpecsBytes+", weightDataBytes="+r.weightDataBytes+".")}return[2]})})},t.prototype.load=function(){return u(this,void 0,void 0,function(){var t,e,n,r,a,o,s;return c(this,function(u){if(null==(t=JSON.parse(this.LS.getItem(this.keys.info))))throw new Error("In local storage, there is no model with name '"+this.modelPath+"'");if("JSON"!==t.modelTopologyType)throw new Error("BrowserLocalStorage does not support loading non-JSON model topology yet.");if(e={},null==(n=JSON.parse(this.LS.getItem(this.keys.topology))))throw new Error("In local storage, the topology of model '"+this.modelPath+"' is missing.");if(e.modelTopology=n,null==(r=JSON.parse(this.LS.getItem(this.keys.weightSpecs))))throw new Error("In local storage, the weight specs of model '"+this.modelPath+"' are missing.");if(e.weightSpecs=r,null!=(a=this.LS.getItem(this.keys.modelMetadata))&&(o=JSON.parse(a),e.format=o.format,e.generatedBy=o.generatedBy,e.convertedBy=o.convertedBy,e.userDefinedMetadata=o.userDefinedMetadata),null==(s=this.LS.getItem(this.keys.weightData)))throw new Error("In local storage, the binary weight values of model '"+this.modelPath+"' are missing.");return e.weightData=function(t){if(Sf){var e=i.from(t,"base64");return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}for(var n=atob(t),r=new Uint8Array(n.length),a=0;a<n.length;++a)r.set([n.charCodeAt(a)],a);return r.buffer}(s),[2,e]})})},t.URL_SCHEME="localstorage://",t}(),Qf=function(t){return f().getBool("IS_BROWSER")&&!Array.isArray(t)&&t.startsWith(Zf.URL_SCHEME)?(e=t.slice(Zf.URL_SCHEME.length),new Zf(e)):null;var e};If.registerSaveRouter(Qf),If.registerLoadRouter(Qf);var td=function(){function t(){C(f().getBool("IS_BROWSER"),function(){return"Current environment is not a web browser"}),C("undefined"==typeof window||void 0!==window.localStorage,function(){return"Current browser does not appear to support localStorage"}),this.LS=window.localStorage}return t.prototype.listModels=function(){return u(this,void 0,void 0,function(){var t,e,n,r,i,a;return c(this,function(o){for(t={},e=qf+Vf,n=Vf+Hf,r=0;r<this.LS.length;++r)(i=this.LS.key(r)).startsWith(e)&&i.endsWith(n)&&(a=Jf(i),t[a]=JSON.parse(this.LS.getItem(i)));return[2,t]})})},t.prototype.removeModel=function(t){return u(this,void 0,void 0,function(){var e,n;return c(this,function(r){var i;if(t=(i=t).startsWith(Zf.URL_SCHEME)?i.slice(Zf.URL_SCHEME.length):i,e=Yf(t),null==this.LS.getItem(e.info))throw new Error("Cannot find model at path '"+t+"'");return n=JSON.parse(this.LS.getItem(e.info)),this.LS.removeItem(e.info),this.LS.removeItem(e.topology),this.LS.removeItem(e.weightSpecs),this.LS.removeItem(e.weightData),[2,n]})})},t}();if(f().getBool("IS_BROWSER"))try{Mf.registerManager(Zf.URL_SCHEME,new td)}catch(o){}var ed="model",nd=".json",rd=".weights.bin";function id(t){return new Promise(function(t){return setTimeout(t)}).then(t)}var ad=function(){function t(e){if(!f().getBool("IS_BROWSER"))throw new Error("browserDownloads() cannot proceed because the current environment is not a browser.");e.startsWith(t.URL_SCHEME)&&(e=e.slice(t.URL_SCHEME.length)),null!=e&&0!==e.length||(e=ed),this.modelTopologyFileName=e+nd,this.weightDataFileName=e+rd}return t.prototype.save=function(t){return u(this,void 0,void 0,function(){var e,n,r,i,a,o;return c(this,function(s){switch(s.label){case 0:if("undefined"==typeof document)throw new Error("Browser downloads are not supported in this environment since `document` is not present");if(e=window.URL.createObjectURL(new Blob([t.weightData],{type:"application/octet-stream"})),!(t.modelTopology instanceof ArrayBuffer))return[3,1];throw new Error("BrowserDownloads.save() does not support saving model topology in binary formats yet.");case 1:return n=[{paths:["./"+this.weightDataFileName],weights:t.weightSpecs}],r={modelTopology:t.modelTopology,format:t.format,generatedBy:t.generatedBy,convertedBy:t.convertedBy,weightsManifest:n},i=window.URL.createObjectURL(new Blob([JSON.stringify(r)],{type:"application/json"})),(a=null==this.jsonAnchor?document.createElement("a"):this.jsonAnchor).download=this.modelTopologyFileName,a.href=i,[4,id(function(){return a.dispatchEvent(new MouseEvent("click"))})];case 2:return s.sent(),null==t.weightData?[3,4]:((o=null==this.weightDataAnchor?document.createElement("a"):this.weightDataAnchor).download=this.weightDataFileName,o.href=e,[4,id(function(){return o.dispatchEvent(new MouseEvent("click"))})]);case 3:s.sent(),s.label=4;case 4:return[2,{modelArtifactsInfo:Tf(t)}]}})})},t.URL_SCHEME="downloads://",t}(),od=function(){function t(t){if(null==t||t.length<1)throw new Error("When calling browserFiles, at least 1 file is required, but received "+t);this.files=t}return t.prototype.load=function(){return u(this,void 0,void 0,function(){var t,e,n=this;return c(this,function(r){return t=this.files[0],e=this.files.slice(1),[2,new Promise(function(r,i){var a=new FileReader;a.onload=function(a){var o=JSON.parse(a.target.result),s=o.modelTopology;if(null!=s){0===e.length&&r({modelTopology:s});var u=o.weightsManifest;if(null!=u){var c;try{c=n.checkManifestAndWeightFiles(u,e)}catch(t){return void i(t)}var l=[],f=[],d=[];u.forEach(function(t){t.paths.forEach(function(t){f.push(t),d.push(null)}),l.push.apply(l,t.weights)}),u.forEach(function(t){t.paths.forEach(function(t){var e=new FileReader;e.onload=function(e){var n=e.target.result,i=f.indexOf(t);d[i]=n,-1===d.indexOf(null)&&r({modelTopology:s,weightSpecs:l,weightData:Af(d),format:o.format,generatedBy:o.generatedBy,convertedBy:o.convertedBy,userDefinedMetadata:o.userDefinedMetadata})},e.onerror=function(e){return i("Failed to weights data from file of path '"+t+"'.")},e.readAsArrayBuffer(c[t])})})}else i(new Error("weightManifest field is missing from file "+t.name))}else i(new Error("modelTopology field is missing from file "+t.name))},a.onerror=function(e){return i("Failed to read model topology and weights manifest JSON from file '"+t.name+"'. BrowserFiles supports loading Keras-style tf.Model artifacts only.")},a.readAsText(t)})]})})},t.prototype.checkManifestAndWeightFiles=function(t,e){for(var n=[],r=e.map(function(t){return Nf(t.name)}),i={},a=0,o=t;a<o.length;a++)o[a].paths.forEach(function(t){var a=Nf(t);if(-1!==n.indexOf(a))throw new Error("Duplicate file basename found in weights manifest: '"+a+"'");if(n.push(a),-1===r.indexOf(a))throw new Error("Weight file with basename '"+a+"' is not provided.");i[t]=e[r.indexOf(a)]});if(n.length!==e.length)throw new Error("Mismatch in the number of files in weights manifest ("+n.length+") and the number of weight files provided ("+e.length+").");return i},t}();function sd(t,e,n,r){!function(t){C(null!=t&&Array.isArray(t)&&t.length>0,function(){return"promises must be a none empty array"})}(t),function(t,e){C(t>=0&&t<=1,function(){return"Progress fraction must be in range [0, 1], but got startFraction "+t}),C(e>=0&&e<=1,function(){return"Progress fraction must be in range [0, 1], but got endFraction "+e}),C(e>=t,function(){return"startFraction must be no more than endFraction, but got startFraction "+t+" and endFraction "+e})}(n=null==n?0:n,r=null==r?1:r);var i=0;return Promise.all(t.map(function(a){return a.then(function(a){var o=n+ ++i/t.length*(r-n);return e(o),a}),a}))}function ud(t,e){return u(this,void 0,void 0,function(){var n,r,i,a,o,s,u,l,d;return c(this,function(c){switch(c.label){case 0:return null==e&&(e={}),n=null==e.fetchFunc?f().platform.fetch:e.fetchFunc,r=t.map(function(t){return n(t,e.requestInit,{isBinary:!0})}),i=0,a=.5,null!=e.onProgress?[3,2]:[4,Promise.all(r)];case 1:return o=c.sent(),[3,4];case 2:return[4,sd(r,e.onProgress,i,a)];case 3:o=c.sent(),c.label=4;case 4:return s=o.map(function(t){return t.arrayBuffer()}),u=.5,l=1,null!=e.onProgress?[3,6]:[4,Promise.all(s)];case 5:return d=c.sent(),[3,8];case 6:return[4,sd(s,e.onProgress,u,l)];case 7:d=c.sent(),c.label=8;case 8:return[2,d]}})})}function cd(t){var e=this;return function(n,r,i){return void 0===r&&(r=""),u(e,void 0,void 0,function(){var e,a,o,s,u,l,f,d,h,p;return c(this,function(c){switch(c.label){case 0:if(e=n.map(function(){return!1}),a={},o=null!=i?i.map(function(){return!1}):[],s=[],n.forEach(function(t,n){var r=0;t.weights.forEach(function(t){var u="quantization"in t?t.quantization.dtype:t.dtype,c=_f[u]*I(t.shape),l=function(){e[n]=!0,null==a[n]&&(a[n]=[]),a[n].push({manifestEntry:t,groupOffset:r,sizeBytes:c})};null!=i?i.forEach(function(e,n){e===t.name&&(l(),o[n]=!0)}):l(),s.push(t.name),r+=c})}),!o.every(function(t){return t}))throw u=i.filter(function(t,e){return!o[e]}),new Error("Could not find weights in manifest with names: "+u.join(", ")+". \nManifest JSON has weights with names: "+s.join(", ")+".");return l=e.reduce(function(t,e,n){return e&&t.push(n),t},[]),f=[],l.forEach(function(t){n[t].paths.forEach(function(t){var e=r+(r.endsWith("/")?"":"/")+t;f.push(e)})}),[4,t(f)];case 1:return d=c.sent(),h={},p=0,l.forEach(function(t){for(var e=n[t].paths.length,r=0,i=0;i<e;i++)r+=d[p+i].byteLength;for(var o=new ArrayBuffer(r),s=new Uint8Array(o),u=0,c=0;c<e;c++){var l=new Uint8Array(d[p+c]);s.set(l,u),u+=l.byteLength}a[t].forEach(function(t){var e=Of(o.slice(t.groupOffset,t.groupOffset+t.sizeBytes),[t.manifestEntry]);for(var n in e)h[n]=e[n]}),p+=e}),[2,h]}})})}}If.registerSaveRouter(function(t){return f().getBool("IS_BROWSER")&&!Array.isArray(t)&&t.startsWith(ad.URL_SCHEME)?function(t){return void 0===t&&(t="model"),new ad(t)}(t.slice(ad.URL_SCHEME.length)):null});var ld=function(){function t(t,e){if(this.DEFAULT_METHOD="POST",null==e&&(e={}),this.weightPathPrefix=e.weightPathPrefix,this.onProgress=e.onProgress,null!=e.fetchFunc?(C("function"==typeof e.fetchFunc,function(){return"Must pass a function that matches the signature of `fetch` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)"}),this.fetch=e.fetchFunc):this.fetch=f().platform.fetch,C(null!=t&&t.length>0,function(){return"URL path for http must not be null, undefined or empty."}),Array.isArray(t)&&C(2===t.length,function(){return"URL paths for http must have a length of 2, (actual length is "+t.length+")."}),this.path=t,null!=e.requestInit&&null!=e.requestInit.body)throw new Error("requestInit is expected to have no pre-existing body, but has one.");this.requestInit=e.requestInit||{}}return t.prototype.save=function(t){return u(this,void 0,void 0,function(){var e,n,r,i;return c(this,function(a){switch(a.label){case 0:if(t.modelTopology instanceof ArrayBuffer)throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");return(e=Object.assign({method:this.DEFAULT_METHOD},this.requestInit)).body=new FormData,n=[{paths:["./model.weights.bin"],weights:t.weightSpecs}],r={modelTopology:t.modelTopology,format:t.format,generatedBy:t.generatedBy,convertedBy:t.convertedBy,userDefinedMetadata:t.userDefinedMetadata,weightsManifest:n},e.body.append("model.json",new Blob([JSON.stringify(r)],{type:"application/json"}),"model.json"),null!=t.weightData&&e.body.append("model.weights.bin",new Blob([t.weightData],{type:"application/octet-stream"}),"model.weights.bin"),[4,this.fetch(this.path,e)];case 1:if((i=a.sent()).ok)return[2,{modelArtifactsInfo:Tf(t),responses:[i]}];throw new Error("BrowserHTTPRequest.save() failed due to HTTP response status "+i.status+".")}})})},t.prototype.load=function(){return u(this,void 0,void 0,function(){var t,e,n,r,i,a,o,s,u,l,f,d;return c(this,function(c){switch(c.label){case 0:return[4,this.fetch(this.path,this.requestInit)];case 1:if(!(t=c.sent()).ok)throw new Error("Request to "+this.path+" failed with status code "+t.status+". Please verify this URL points to the model JSON of the model to load.");c.label=2;case 2:return c.trys.push([2,4,,5]),[4,t.json()];case 3:return e=c.sent(),[3,5];case 4:throw c.sent(),n="Failed to parse model JSON of response from "+this.path+".",this.path.endsWith(".pb")?n+=" Your path contains a .pb file extension. Support for .pb models have been removed in TensorFlow.js 1.0 in favor of .json models. You can re-convert your Python TensorFlow model using the TensorFlow.js 1.0 conversion scripts or you can convert your.pb models with the 'pb2json'NPM script in the tensorflow/tfjs-converter repository.":n+=" Please make sure the server is serving valid JSON for this request.",new Error(n);case 5:if(r=e.modelTopology,i=e.weightsManifest,a=e.generatedBy,o=e.convertedBy,s=e.format,u=e.userDefinedMetadata,null==r&&null==i)throw new Error("The JSON from HTTP path "+this.path+" contains neither model topology or manifest for weights.");return null==i?[3,7]:[4,this.loadWeights(i)];case 6:d=c.sent(),l=d[0],f=d[1],c.label=7;case 7:return[2,{modelTopology:r,weightSpecs:l,weightData:f,userDefinedMetadata:u,generatedBy:a,convertedBy:o,format:s}]}})})},t.prototype.loadWeights=function(t){return u(this,void 0,void 0,function(){var e,n,r,i,a,o,s,u,l,f,d;return c(this,function(c){switch(c.label){case 0:for(e=Array.isArray(this.path)?this.path[1]:this.path,n=function(t){var e=t.lastIndexOf("/"),n=t.lastIndexOf("?");return[t.substring(0,e)+"/",n>e?t.substring(n):""]}(e),r=n[0],i=n[1],a=this.weightPathPrefix||r,o=[],s=0,u=t;s<u.length;s++)l=u[s],o.push.apply(o,l.weights);return f=[],t.forEach(function(t){t.paths.forEach(function(t){f.push(a+t+i)})}),[4,ud(f,{requestInit:this.requestInit,fetchFunc:this.fetch,onProgress:this.onProgress})];case 1:return d=c.sent(),[2,[o,Af(d)]]}})})},t.URL_SCHEME_REGEX=/^https?:\/\//,t}();function fd(t){return null!=t.match(ld.URL_SCHEME_REGEX)}var dd=function(t,e){return"undefined"==typeof fetch?null:(Array.isArray(t)?t.every(function(t){return fd(t)}):fd(t))?hd(t,{onProgress:e}):null};function hd(t,e){return new ld(t,e)}If.registerSaveRouter(dd),If.registerLoadRouter(dd);var pd,md=function(){function t(t){this.modelArtifacts=t}return t.prototype.load=function(){return u(this,void 0,void 0,function(){return c(this,function(t){return[2,this.modelArtifacts]})})},t}(),gd=function(){function t(t){this.saveHandler=t}return t.prototype.save=function(t){return u(this,void 0,void 0,function(){return c(this,function(e){return[2,this.saveHandler(t)]})})},t}(),vd=Object.freeze({browserFiles:function(t){return new od(t)},browserHTTPRequest:function(t,e){return hd(t,e)},concatenateArrayBuffers:Af,decodeWeights:Of,encodeWeights:function(t,e){return u(this,void 0,void 0,function(){var n,r,i,a,o,s=this;return c(this,function(l){switch(l.label){case 0:for(n=[],r=[],i=Array.isArray(t)?t.map(function(t){return t.name}):Object.keys(t),a=function(a){var o=i[a],l=Array.isArray(t)?t[a].tensor:t[o];if("float32"!==l.dtype&&"int32"!==l.dtype&&"bool"!==l.dtype&&"string"!==l.dtype)throw new Error("Unsupported dtype in weight '"+o+"': "+l.dtype);var f={name:o,shape:l.shape,dtype:l.dtype};if("string"===l.dtype){var d=new Promise(function(t){return u(s,void 0,void 0,function(){var e,n,r,i,a,o,s;return c(this,function(u){switch(u.label){case 0:return[4,l.bytes()];case 1:for(e=u.sent(),n=e.reduce(function(t,e){return t+e.length},0)+Ef*e.length,r=new Uint8Array(n),i=0,a=0;a<e.length;a++)o=e[a],s=new Uint8Array(new Uint32Array([o.length]).buffer),r.set(s,i),i+=Ef,r.set(o,i),i+=o.length;return t(r),[2]}})})});r.push(d)}else r.push(l.data());null!=e&&(f.group=e),n.push(f)},o=0;o<i.length;++o)a(o);return[4,Promise.all(r)];case 1:return[2,{data:function(t){if(null===t)throw new Error("Invalid input value: "+JSON.stringify(t));var e=0,n=[];t.forEach(function(t){if(e+=t.byteLength,n.push(t.byteLength===t.buffer.byteLength?t:new t.constructor(t)),!(t instanceof Float32Array||t instanceof Int32Array||t instanceof Uint8Array))throw new Error("Unsupported TypedArray subtype: "+t.constructor.name)});var r=new Uint8Array(e),i=0;return n.forEach(function(t){r.set(new Uint8Array(t.buffer),i),i+=t.byteLength}),r.buffer}(l.sent()),specs:n}]}})})},fromMemory:function(t,e,n,r){return 1===arguments.length?null!=t.modelTopology||null!=t.weightSpecs?new md(t):(console.warn("Please call tf.io.fromMemory() with only one argument. The argument should be of type ModelArtifacts. The multi-argument signature of tf.io.fromMemory() has been deprecated and will be removed in a future release."),new md({modelTopology:t})):(console.warn("Please call tf.io.fromMemory() with only one argument. The argument should be of type ModelArtifacts. The multi-argument signature of tf.io.fromMemory() has been deprecated and will be removed in a future release."),new md({modelTopology:t,weightSpecs:e,weightData:n,trainingConfig:r}))},getLoadHandlers:function(t,e){return If.getLoadHandlers(t,e)},getModelArtifactsInfoForJSON:Tf,getSaveHandlers:function(t){return If.getSaveHandlers(t)},http:hd,isHTTPScheme:fd,loadWeights:function(t,e,n,r){return void 0===e&&(e=""),u(this,void 0,void 0,function(){return c(this,function(i){return[2,cd(function(t){return ud(t,{requestInit:r})})(t,e,n)]})})},registerLoadRouter:function(t){return If.registerLoadRouter(t)},registerSaveRouter:function(t){return If.registerSaveRouter(t)},weightsLoaderFactory:cd,withSaveHandler:function(t){return new gd(t)},copyModel:function(t,e){return u(this,void 0,void 0,function(){return c(this,function(n){return[2,Ff(t,e,!1)]})})},listModels:function(){return u(this,void 0,void 0,function(){var t,e,n,r,i,a,o;return c(this,function(s){switch(s.label){case 0:t=Mf.getSchemes(),e={},n=0,r=t,s.label=1;case 1:return n<r.length?(i=r[n],[4,Mf.getManager(i).listModels()]):[3,4];case 2:for(o in a=s.sent())e[i+Df+o]=a[o];s.label=3;case 3:return n++,[3,1];case 4:return[2,e]}})})},moveModel:function(t,e){return u(this,void 0,void 0,function(){return c(this,function(n){return[2,Ff(t,e,!0)]})})},removeModel:function(t){return u(this,void 0,void 0,function(){var e;return c(this,function(n){return e=Rf(t),[2,Mf.getManager(e.scheme).removeModel(e.path)]})})}}),yd=Dn({confusionMatrix_:function(t,e,n){var r=xn(t,"labels","confusionMatrix"),i=xn(e,"predictions","confusionMatrix");C(null==n||n>0&&Number.isInteger(n),function(){return"If provided, numClasses must be a positive integer, but got "+n}),C(1===r.rank,function(){return"Expected the rank of labels to be 1, but got "+r.rank}),C(1===i.rank,function(){return"Expected the rank of predictions to be 1, but got "+i.rank}),C(r.shape[0]===i.shape[0],function(){return"Mismatch in the number of examples: "+r.shape[0]+" vs. "+i.shape[0]+". Labels and predictions should have the same number of elements."}),C(n>0&&Number.isInteger(n),function(){return"numClasses is required to be a positive integer, but got "+n});var a=du(r.asType("int32"),n),o=du(i.asType("int32"),n);return a.transpose().matMul(o).asType("int32")}}),bd=Object.freeze({confusionMatrix:yd}),xd=Dn({fromPixels_:function(t,e){if(void 0===e&&(e=3),e>4)throw new Error("Cannot construct Tensor with more than 4 channels from pixels.");if(null==t)throw new Error("pixels passed to tf.browser.fromPixels() can not be null");var n=!1,r=!1,i=!1,a=!1,o=!1;if(t.data instanceof Uint8Array)n=!0;else if("undefined"!=typeof ImageData&&t instanceof ImageData)r=!0;else if("undefined"!=typeof HTMLVideoElement&&t instanceof HTMLVideoElement)i=!0;else if("undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement)a=!0;else{if(null==t.getContext)throw new Error("pixels passed to tf.browser.fromPixels() must be either an HTMLVideoElement, HTMLImageElement, HTMLCanvasElement, ImageData in browser, or OffscreenCanvas, ImageData in webworker or {data: Uint32Array, width: number, height: number}, but was "+t.constructor.name);o=!0}if(i&&i&&t.readyState<2)throw new Error("The video element has not loaded data yet. Please wait for `loadeddata` event on the <video> element.");if(null!=m("FromPixels",Wt.backendName))return Wt.runKernel("FromPixels",{pixels:t},{numChannels:e});var s,u,c=i?[t.videoWidth,t.videoHeight]:[t.width,t.height],l=c[0],f=c[1];if(o?s=t.getContext("2d").getImageData(0,0,l,f).data:r||n?s=t.data:(a||i)&&(null==pd&&(pd=document.createElement("canvas").getContext("2d")),pd.canvas.width=l,pd.canvas.height=f,pd.drawImage(t,0,0,l,f),s=pd.getImageData(0,0,l,f).data),4===e)u=new Int32Array(s);else{var d=l*f;u=new Int32Array(d*e);for(var h=0;h<d;h++)for(var p=0;p<e;++p)u[h*e+p]=s[4*h+p]}return Un(u,[f,l,e],"int32")}}),wd=Object.freeze({toPixels:function(t,e){return u(this,void 0,void 0,function(){var n,r,i,a,o,s,u,l,f,d,h,p,m,g,v,y,b,x,w,k,_,E,O;return c(this,function(c){switch(c.label){case 0:if(n=xn(t,"img","toPixels"),t instanceof Ot||(n=n.toInt()),2!==n.rank&&3!==n.rank)throw new Error("toPixels only supports rank 2 or 3 tensors, got rank "+n.rank+".");if(r=n.shape.slice(0,2),i=r[0],a=r[1],(o=2===n.rank?1:n.shape[2])>4||2===o)throw new Error("toPixels only supports depth of size 1, 3 or 4 but got "+o);return[4,n.data()];case 1:return s=c.sent(),u=n.min(),l=n.max(),[4,Promise.all([u.data(),l.data()])];case 2:if(f=c.sent(),d=f[0],h=f[1],p=d[0],m=h[0],u.dispose(),l.dispose(),"float32"===n.dtype){if(p<0||m>1)throw new Error("Tensor values for a float32 Tensor must be in the range [0 - 1] but got range ["+p+" - "+m+"].")}else{if("int32"!==n.dtype)throw new Error("Unsupported type for toPixels: "+n.dtype+". Please use float32 or int32 tensors.");if(p<0||m>255)throw new Error("Tensor values for a int32 Tensor must be in the range [0 - 255] but got range ["+p+" - "+m+"].")}for(g="float32"===n.dtype?255:1,v=new Uint8ClampedArray(a*i*4),y=0;y<i*a;++y)b=void 0,x=void 0,w=void 0,k=void 0,1===o?(b=s[y]*g,x=s[y]*g,w=s[y]*g,k=255):3===o?(b=s[3*y]*g,x=s[3*y+1]*g,w=s[3*y+2]*g,k=255):4===o&&(b=s[4*y]*g,x=s[4*y+1]*g,w=s[4*y+2]*g,k=s[4*y+3]*g),v[0+(_=4*y)]=Math.round(b),v[_+1]=Math.round(x),v[_+2]=Math.round(w),v[_+3]=Math.round(k);return null!=e&&(e.width=a,e.height=i,E=e.getContext("2d"),O=new ImageData(v,a,i),E.putImageData(O,0,0)),n!==t&&n.dispose(),[2,v]}})})},fromPixels:xd}),kd=function(){function t(){}return t.prototype.getClassName=function(){return this.constructor.className},t.fromConfig=function(t,e){return new t(e)},t}(),_d=function(){function t(){this.classNameMap={}}return t.getMap=function(){return null==t.instance&&(t.instance=new t),t.instance},t.register=function(e){t.getMap().classNameMap[e.className]=[e,e.fromConfig]},t}();function Ed(t){C(null!=t.className,function(){return"Class being registered does not have the static className property defined."}),C("string"==typeof t.className,function(){return"className is required to be a string, but got type "+typeof t.className}),C(t.className.length>0,function(){return"Class being registered has an empty-string as its className, which is disallowed."}),_d.register(t)}var Od=Object.freeze({Serializable:kd,SerializationMap:_d,registerClass:Ed}),Sd="1.7.2",Cd=Object.freeze({gpgpu_util:Ho,webgl_util:$e,forceHalfFloat:function(){f().set("WEBGL_FORCE_F16_TEXTURES",!0)},MathBackendWebGL:As,setWebGLContext:Yt,GPGPUContext:Go}),Ad=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return s(e,t),e.prototype.minimize=function(t,e,n){void 0===e&&(e=!1);var r=this.computeGradients(t,n),i=r.value,a=r.grads;if(null!=n){var o=n.map(function(t){return{name:t.name,tensor:a[t.name]}});this.applyGradients(o)}else this.applyGradients(a);return an(a),e?i:(i.dispose(),null)},Object.defineProperty(e.prototype,"iterations",{get:function(){return null==this.iterations_&&(this.iterations_=0),this.iterations_},enumerable:!0,configurable:!0}),e.prototype.incrementIterations=function(){this.iterations_=this.iterations+1},e.prototype.computeGradients=function(t,e){return oa(t,e)},e.prototype.dispose=function(){null!=this.iterations_&&an(this.iterations_)},e.prototype.saveIterations=function(){return u(this,void 0,void 0,function(){return c(this,function(t){return null==this.iterations_&&(this.iterations_=0),[2,{name:"iter",tensor:Ln(this.iterations_,"int32")}]})})},e.prototype.getWeights=function(){return u(this,void 0,void 0,function(){return c(this,function(t){throw new Error("getWeights() is not implemented for this optimizer yet.")})})},e.prototype.setWeights=function(t){return u(this,void 0,void 0,function(){return c(this,function(t){throw new Error("setWeights() is not implemented for this optimizer class "+this.getClassName())})})},e.prototype.extractIterations=function(t){return u(this,void 0,void 0,function(){var e;return c(this,function(n){switch(n.label){case 0:return e=this,[4,t[0].tensor.data()];case 1:return e.iterations_=n.sent()[0],[2,t.slice(1)]}})})},e}(kd);Object.defineProperty(Ad,Symbol.hasInstance,{value:function(t){return null!=t.minimize&&null!=t.computeGradients&&null!=t.applyGradients}});var Nd=function(t){function e(e,n,r){void 0===r&&(r=null);var i=t.call(this)||this;return i.learningRate=e,i.rho=n,i.epsilon=r,i.accumulatedGrads=[],i.accumulatedUpdates=[],null==r&&(i.epsilon=Wt.backend.epsilon()),i}return s(e,t),e.prototype.applyGradients=function(t){var e=this;(Array.isArray(t)?t.map(function(t){return t.name}):Object.keys(t)).forEach(function(n,r){var i=Wt.registeredVariables[n];null==e.accumulatedGrads[r]&&(e.accumulatedGrads[r]={originalName:n+"/accum_grad",variable:rn(function(){return Zn(i).variable(!1)})}),null==e.accumulatedUpdates[r]&&(e.accumulatedUpdates[r]={originalName:n+"/accum_var",variable:rn(function(){return Zn(i).variable(!1)})});var a=Array.isArray(t)?t[r].tensor:t[n];if(null!=a){var o=e.accumulatedGrads[r].variable,s=e.accumulatedUpdates[r].variable;rn(function(){var t=o.mul(e.rho).add(a.square().mul(1-e.rho)),n=s.add(e.epsilon).sqrt().div(o.add(e.epsilon).sqrt()).mul(a),r=s.mul(e.rho).add(n.square().mul(1-e.rho));o.assign(t),s.assign(r);var u=n.mul(-e.learningRate).add(i);i.assign(u)})}}),this.incrementIterations()},e.prototype.dispose=function(){null!=this.accumulatedUpdates&&(an(this.accumulatedGrads.map(function(t){return t.variable})),an(this.accumulatedUpdates.map(function(t){return t.variable})))},e.prototype.getWeights=function(){return u(this,void 0,void 0,function(){var t;return c(this,function(e){switch(e.label){case 0:return t=this.accumulatedGrads.concat(this.accumulatedUpdates),[4,this.saveIterations()];case 1:return[2,[e.sent()].concat(t.map(function(t){return{name:t.originalName,tensor:t.variable}}))]}})})},e.prototype.setWeights=function(t){return u(this,void 0,void 0,function(){var e;return c(this,function(n){switch(n.label){case 0:return[4,this.extractIterations(t)];case 1:return t=n.sent(),e=t.length/2,this.accumulatedGrads=t.slice(0,e).map(function(t){return{originalName:t.name,variable:t.tensor.variable(!1)}}),this.accumulatedUpdates=t.slice(e,2*e).map(function(t){return{originalName:t.name,variable:t.tensor.variable(!1)}}),[2]}})})},e.prototype.getConfig=function(){return{learningRate:this.learningRate,rho:this.rho,epsilon:this.epsilon}},e.fromConfig=function(t,e){return new t(e.learningRate,e.rho,e.epsilon)},e.className="Adadelta",e}(Ad);Ed(Nd);var Td=function(t){function e(e,n){void 0===n&&(n=.1);var r=t.call(this)||this;return r.learningRate=e,r.initialAccumulatorValue=n,r.accumulatedGrads=[],r}return s(e,t),e.prototype.applyGradients=function(t){var e=this;(Array.isArray(t)?t.map(function(t){return t.name}):Object.keys(t)).forEach(function(n,r){var i=Wt.registeredVariables[n];null==e.accumulatedGrads[r]&&(e.accumulatedGrads[r]={originalName:n+"/accumulator",variable:rn(function(){return Kn(i.shape,e.initialAccumulatorValue).variable(!1)})});var a=Array.isArray(t)?t[r].tensor:t[n];if(null!=a){var o=e.accumulatedGrads[r].variable;rn(function(){var t=o.add(a.square());o.assign(t);var n=a.div(t.add(Wt.backend.epsilon()).sqrt()).mul(-e.learningRate).add(i);i.assign(n)})}}),this.incrementIterations()},e.prototype.dispose=function(){null!=this.accumulatedGrads&&an(this.accumulatedGrads.map(function(t){return t.variable}))},e.prototype.getWeights=function(){return u(this,void 0,void 0,function(){return c(this,function(t){switch(t.label){case 0:return[4,this.saveIterations()];case 1:return[2,[t.sent()].concat(this.accumulatedGrads.map(function(t){return{name:t.originalName,tensor:t.variable}}))]}})})},e.prototype.setWeights=function(t){return u(this,void 0,void 0,function(){return c(this,function(e){switch(e.label){case 0:return[4,this.extractIterations(t)];case 1:return t=e.sent(),this.accumulatedGrads=t.map(function(t){return{originalName:t.name,variable:t.tensor.variable(!1)}}),[2]}})})},e.prototype.getConfig=function(){return{learningRate:this.learningRate,initialAccumulatorValue:this.initialAccumulatorValue}},e.fromConfig=function(t,e){return new t(e.learningRate,e.initialAccumulatorValue)},e.className="Adagrad",e}(Ad);Ed(Td);var Id=function(t){function e(e,n,r,i){void 0===i&&(i=null);var a=t.call(this)||this;return a.learningRate=e,a.beta1=n,a.beta2=r,a.epsilon=i,a.accumulatedFirstMoment=[],a.accumulatedSecondMoment=[],rn(function(){a.accBeta1=Ln(n).variable(),a.accBeta2=Ln(r).variable()}),null==i&&(a.epsilon=Wt.backend.epsilon()),a}return s(e,t),e.prototype.applyGradients=function(t){var e=this,n=Array.isArray(t)?t.map(function(t){return t.name}):Object.keys(t);rn(function(){var r=Pi(1,e.accBeta1),i=Pi(1,e.accBeta2);n.forEach(function(n,a){var o=Wt.registeredVariables[n];null==e.accumulatedFirstMoment[a]&&(e.accumulatedFirstMoment[a]={originalName:n+"/m",variable:rn(function(){return Zn(o).variable(!1)})}),null==e.accumulatedSecondMoment[a]&&(e.accumulatedSecondMoment[a]={originalName:n+"/v",variable:rn(function(){return Zn(o).variable(!1)})});var s=Array.isArray(t)?t[a].tensor:t[n];if(null!=s){var u=e.accumulatedFirstMoment[a].variable,c=e.accumulatedSecondMoment[a].variable,l=u.mul(e.beta1).add(s.mul(1-e.beta1)),f=c.mul(e.beta2).add(s.square().mul(1-e.beta2)),d=l.div(r),h=f.div(i);u.assign(l),c.assign(f);var p=d.div(h.sqrt().add(e.epsilon)).mul(-e.learningRate).add(o);o.assign(p)}}),e.accBeta1.assign(e.accBeta1.mul(e.beta1)),e.accBeta2.assign(e.accBeta2.mul(e.beta2))}),this.incrementIterations()},e.prototype.dispose=function(){this.accBeta1.dispose(),this.accBeta2.dispose(),null!=this.accumulatedFirstMoment&&an(this.accumulatedFirstMoment.map(function(t){return t.variable})),null!=this.accumulatedSecondMoment&&an(this.accumulatedSecondMoment.map(function(t){return t.variable}))},e.prototype.getWeights=function(){return u(this,void 0,void 0,function(){var t;return c(this,function(e){switch(e.label){case 0:return t=this.accumulatedFirstMoment.concat(this.accumulatedSecondMoment),[4,this.saveIterations()];case 1:return[2,[e.sent()].concat(t.map(function(t){return{name:t.originalName,tensor:t.variable}}))]}})})},e.prototype.setWeights=function(t){return u(this,void 0,void 0,function(){var e,n=this;return c(this,function(r){switch(r.label){case 0:return[4,this.extractIterations(t)];case 1:return t=r.sent(),rn(function(){n.accBeta1.assign(Ri(n.beta1,n.iterations_+1)),n.accBeta2.assign(Ri(n.beta2,n.iterations_+1))}),e=t.length/2,this.accumulatedFirstMoment=t.slice(0,e).map(function(t){return{originalName:t.name,variable:t.tensor.variable(!1)}}),this.accumulatedSecondMoment=t.slice(e,2*e).map(function(t){return{originalName:t.name,variable:t.tensor.variable(!1)}}),[2]}})})},e.prototype.getConfig=function(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon}},e.fromConfig=function(t,e){return new t(e.learningRate,e.beta1,e.beta2,e.epsilon)},e.className="Adam",e}(Ad);Ed(Id);var Dd=function(t){function e(e,n,r,i,a){void 0===i&&(i=null),void 0===a&&(a=0);var o=t.call(this)||this;return o.learningRate=e,o.beta1=n,o.beta2=r,o.epsilon=i,o.decay=a,o.accumulatedFirstMoment=[],o.accumulatedWeightedInfNorm=[],rn(function(){o.iteration=Ln(0).variable(),o.accBeta1=Ln(n).variable()}),null==i&&(o.epsilon=Wt.backend.epsilon()),o}return s(e,t),e.prototype.applyGradients=function(t){var e=this,n=Array.isArray(t)?t.map(function(t){return t.name}):Object.keys(t);rn(function(){var r=Pi(1,e.accBeta1),i=zi(-e.learningRate,e.iteration.mul(e.decay).add(1));n.forEach(function(n,a){var o=Wt.registeredVariables[n];null==e.accumulatedFirstMoment[a]&&(e.accumulatedFirstMoment[a]={originalName:n+"/m",variable:Zn(o).variable(!1)}),null==e.accumulatedWeightedInfNorm[a]&&(e.accumulatedWeightedInfNorm[a]={originalName:n+"/v",variable:Zn(o).variable(!1)});var s=Array.isArray(t)?t[a].tensor:t[n];if(null!=s){var u=e.accumulatedFirstMoment[a].variable,c=e.accumulatedWeightedInfNorm[a].variable,l=u.mul(e.beta1).add(s.mul(1-e.beta1)),f=c.mul(e.beta2),d=s.abs(),h=f.maximum(d);u.assign(l),c.assign(h);var p=i.div(r).mul(l.div(h.add(e.epsilon))).add(o);o.assign(p)}}),e.iteration.assign(e.iteration.add(1)),e.accBeta1.assign(e.accBeta1.mul(e.beta1))}),this.incrementIterations()},e.prototype.dispose=function(){this.accBeta1.dispose(),this.iteration.dispose(),null!=this.accumulatedFirstMoment&&an(this.accumulatedFirstMoment.map(function(t){return t.variable})),null!=this.accumulatedWeightedInfNorm&&an(this.accumulatedWeightedInfNorm.map(function(t){return t.variable}))},e.prototype.getWeights=function(){return u(this,void 0,void 0,function(){return c(this,function(t){throw new Error("getWeights() is not implemented for Adamax yet.")})})},e.prototype.setWeights=function(t){return u(this,void 0,void 0,function(){return c(this,function(t){throw new Error("setWeights() is not implemented for Adamax yet.")})})},e.prototype.getConfig=function(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon,decay:this.decay}},e.fromConfig=function(t,e){return new t(e.learningRate,e.beta1,e.beta2,e.epsilon,e.decay)},e.className="Adamax",e}(Ad);Ed(Dd);var Md=function(t){function e(e){var n=t.call(this)||this;return n.learningRate=e,n.setLearningRate(e),n}return s(e,t),e.prototype.applyGradients=function(t){var e=this;(Array.isArray(t)?t.map(function(t){return t.name}):Object.keys(t)).forEach(function(n,r){var i=Array.isArray(t)?t[r].tensor:t[n];if(null!=i){var a=Wt.registeredVariables[n];rn(function(){var t=e.c.mul(i).add(a);a.assign(t)})}}),this.incrementIterations()},e.prototype.setLearningRate=function(t){this.learningRate=t,null!=this.c&&this.c.dispose(),this.c=on(Ln(-t))},e.prototype.dispose=function(){this.c.dispose()},e.prototype.getWeights=function(){return u(this,void 0,void 0,function(){return c(this,function(t){switch(t.label){case 0:return[4,this.saveIterations()];case 1:return[2,[t.sent()]]}})})},e.prototype.setWeights=function(t){return u(this,void 0,void 0,function(){return c(this,function(e){switch(e.label){case 0:return[4,this.extractIterations(t)];case 1:if(0!==(t=e.sent()).length)throw new Error("SGD optimizer does not have settable weights.");return[2]}})})},e.prototype.getConfig=function(){return{learningRate:this.learningRate}},e.fromConfig=function(t,e){return new t(e.learningRate)},e.className="SGD",e}(Ad);Ed(Md);var Rd=function(t){function e(e,n,r){void 0===r&&(r=!1);var i=t.call(this,e)||this;return i.learningRate=e,i.momentum=n,i.useNesterov=r,i.accumulations=[],i.m=Ln(i.momentum),i}return s(e,t),e.prototype.applyGradients=function(t){var e=this;(Array.isArray(t)?t.map(function(t){return t.name}):Object.keys(t)).forEach(function(n,r){var i=Wt.registeredVariables[n];null==e.accumulations[r]&&(e.accumulations[r]={originalName:n+"/momentum",variable:rn(function(){return Zn(i).variable(!1)})});var a=e.accumulations[r].variable,o=Array.isArray(t)?t[r].tensor:t[n];null!=o&&rn(function(){var t,n=e.m.mul(a).add(o);t=e.useNesterov?e.c.mul(o.add(n.mul(e.m))).add(i):e.c.mul(n).add(i),a.assign(n),i.assign(t)})}),this.incrementIterations()},e.prototype.dispose=function(){this.m.dispose(),null!=this.accumulations&&an(this.accumulations.map(function(t){return t.variable}))},e.prototype.setMomentum=function(t){this.momentum=t},e.prototype.getWeights=function(){return u(this,void 0,void 0,function(){return c(this,function(t){switch(t.label){case 0:return[4,this.saveIterations()];case 1:return[2,[t.sent()].concat(this.accumulations.map(function(t){return{name:t.originalName,tensor:t.variable}}))]}})})},e.prototype.setWeights=function(t){return u(this,void 0,void 0,function(){return c(this,function(e){switch(e.label){case 0:return[4,this.extractIterations(t)];case 1:return t=e.sent(),this.accumulations=t.map(function(t){return{originalName:t.name,variable:t.tensor.variable(!1)}}),[2]}})})},e.prototype.getConfig=function(){return{learningRate:this.learningRate,momentum:this.momentum,useNesterov:this.useNesterov}},e.fromConfig=function(t,e){return new t(e.learningRate,e.momentum,e.useNesterov)},e.className="Momentum",e}(Md);Ed(Rd);var Fd=function(t){function e(e,n,r,i,a){void 0===n&&(n=.9),void 0===r&&(r=0),void 0===i&&(i=null),void 0===a&&(a=!1);var o=t.call(this)||this;if(o.learningRate=e,o.decay=n,o.momentum=r,o.epsilon=i,o.accumulatedMeanSquares=[],o.accumulatedMoments=[],o.accumulatedMeanGrads=[],o.centered=a,null==i&&(o.epsilon=Wt.backend.epsilon()),null==e)throw new Error("learningRate for RMSPropOptimizer must be defined.");return o}return s(e,t),e.prototype.applyGradients=function(t){var e=this;(Array.isArray(t)?t.map(function(t){return t.name}):Object.keys(t)).forEach(function(n,r){var i=Wt.registeredVariables[n];null==e.accumulatedMeanSquares[r]&&(e.accumulatedMeanSquares[r]={originalName:n+"/rms",variable:rn(function(){return Zn(i).variable(!1)})}),null==e.accumulatedMoments[r]&&(e.accumulatedMoments[r]={originalName:n+"/momentum",variable:rn(function(){return Zn(i).variable(!1)})}),null==e.accumulatedMeanGrads[r]&&e.centered&&(e.accumulatedMeanGrads[r]={originalName:n+"/mg",variable:rn(function(){return Zn(i).variable(!1)})});var a=Array.isArray(t)?t[r].tensor:t[n];if(null!=a){var o=e.accumulatedMeanSquares[r].variable,s=e.accumulatedMoments[r].variable;rn(function(){var t=o.mul(e.decay).add(a.square().mul(1-e.decay));if(e.centered){var n=e.accumulatedMeanGrads[r].variable,u=n.mul(e.decay).add(a.mul(1-e.decay)),c=s.mul(e.momentum).add(a.mul(e.learningRate).div(t.sub(u.square().add(e.epsilon)).sqrt()));o.assign(t),n.assign(u),s.assign(c);var l=i.sub(c);i.assign(l)}else{var f=o.mul(e.decay).add(a.square().mul(1-e.decay));c=s.mul(e.momentum).add(a.mul(e.learningRate).div(f.add(e.epsilon).sqrt())),o.assign(f),s.assign(c),l=i.sub(c),i.assign(l)}})}}),this.incrementIterations()},e.prototype.dispose=function(){null!=this.accumulatedMeanSquares&&an(this.accumulatedMeanSquares.map(function(t){return t.variable})),null!=this.accumulatedMeanGrads&&this.centered&&an(this.accumulatedMeanGrads.map(function(t){return t.variable})),null!=this.accumulatedMoments&&an(this.accumulatedMoments.map(function(t){return t.variable}))},e.prototype.getWeights=function(){return u(this,void 0,void 0,function(){var t;return c(this,function(e){switch(e.label){case 0:return t=this.accumulatedMeanSquares.concat(this.accumulatedMoments),this.centered&&t.push.apply(t,this.accumulatedMeanGrads),[4,this.saveIterations()];case 1:return[2,[e.sent()].concat(t.map(function(t){return{name:t.originalName,tensor:t.variable}}))]}})})},e.prototype.setWeights=function(t){return u(this,void 0,void 0,function(){var e;return c(this,function(n){switch(n.label){case 0:return[4,this.extractIterations(t)];case 1:return t=n.sent(),e=this.centered?t.length/3:t.length/2,this.accumulatedMeanSquares=t.slice(0,e).map(function(t){return{originalName:t.name,variable:t.tensor.variable(!1)}}),this.accumulatedMoments=t.slice(e,2*e).map(function(t){return{originalName:t.name,variable:t.tensor.variable(!1)}}),this.centered&&(this.accumulatedMeanGrads=t.slice(2*e,3*e).map(function(t){return{originalName:t.name,variable:t.tensor.variable(!1)}})),[2]}})})},e.prototype.getConfig=function(){return{learningRate:this.learningRate,decay:this.decay,momentum:this.momentum,epsilon:this.epsilon,centered:this.centered}},e.fromConfig=function(t,e){return new t(e.learningRate,e.decay,e.momentum,e.epsilon,e.centered)},e.className="RMSProp",e}(Ad);Ed(Fd);var jd=function(){function t(){}return t.sgd=function(t){return new Md(t)},t.momentum=function(t,e,n){return void 0===n&&(n=!1),new Rd(t,e,n)},t.rmsprop=function(t,e,n,r,i){return void 0===e&&(e=.9),void 0===n&&(n=0),void 0===r&&(r=null),void 0===i&&(i=!1),new Fd(t,e,n,r,i)},t.adam=function(t,e,n,r){return void 0===t&&(t=.001),void 0===e&&(e=.9),void 0===n&&(n=.999),void 0===r&&(r=null),new Id(t,e,n,r)},t.adadelta=function(t,e,n){return void 0===t&&(t=.001),void 0===e&&(e=.95),void 0===n&&(n=null),new Nd(t,e,n)},t.adamax=function(t,e,n,r,i){return void 0===t&&(t=.002),void 0===e&&(e=.9),void 0===n&&(n=.999),void 0===r&&(r=null),void 0===i&&(i=0),new Dd(t,e,n,r,i)},t.adagrad=function(t,e){return void 0===e&&(e=.1),new Td(t,e)},t}(),Pd={sgd:jd.sgd,momentum:jd.momentum,adadelta:jd.adadelta,adagrad:jd.adagrad,rmsprop:jd.rmsprop,adamax:jd.adamax,adam:jd.adam},Ld="undefined"!=typeof requestAnimationFrame?requestAnimationFrame:void 0!==a?a:function(t){return t()};function zd(){return new Promise(function(t){return Ld(function(){return t()})})}Ot.prototype.add=function(t){return Lr(this,t)},Ot.prototype.broadcastTo=function(t){return tu(this,t)},Ot.prototype.div=function(t){return zi(this,t)},Ot.prototype.divNoNan=function(t){return uu(this,t)},Ot.prototype.squaredDifference=function(t){return Du(this,t)},Ot.prototype.tile=function(t){return cu(this,t)},Ot.prototype.oneHot=function(t,e,n){return void 0===e&&(e=1),void 0===n&&(n=0),du(this,t,e,n)},Ot.prototype.transpose=function(t){return fa(this,t)},Ot.prototype.pad=function(t,e){return hu(this,t,e)},Ot.prototype.batchNorm=function(t,e,n,r,i){return qs(this,t,e,n,r,i)},_t=Jl}.call(this,n(53),n(87),n(86).Buffer,n(244).setImmediate)},function(t,e,n){"use strict";var r=function(t,e,n){return t.fields=e||[],t.fname=n,t};function i(t){return null==t?null:t.fname}function a(t){return null==t?null:t.fields}var o=function(t){throw Error(t)},s=function(t){var e,n,r,i=[],a=null,s=0,u=t.length,c="";function l(){i.push(c+t.substring(e,n)),c="",e=n+1}for(t+="",e=n=0;n<u;++n)if("\\"===(r=t[n]))c+=t.substring(e,n),c+=t.substring(++n,++n),e=n;else if(r===a)l(),a=null,s=-1;else{if(a)continue;e===s&&'"'===r?(e=n+1,a=r):e===s&&"'"===r?(e=n+1,a=r):"."!==r||s?"["===r?(n>e&&l(),s=e=n+1):"]"===r&&(s||o("Access path missing open bracket: "+t),s>0&&l(),s=0,e=n+1):n>e?l():e=n+1}return s&&o("Access path missing closing bracket: "+t),a&&o("Access path missing closing quote: "+t),n>e&&(n++,l()),i},u=Array.isArray,c=function(t){return t===Object(t)},l=function(t){return"string"==typeof t};function f(t){return u(t)?"["+t.map(f)+"]":c(t)||l(t)?JSON.stringify(t).replace("\u2028","\\u2028").replace("\u2029","\\u2029"):t}var d=function(t,e){var n=s(t),i="return _["+n.map(f).join("][")+"];";return r(Function("_",i),[t=1===n.length?n[0]:t],e||t)},h=[],p=d("id"),m=r(function(t){return t},h,"identity"),g=r(function(){return 0},h,"zero"),v=r(function(){return 1},h,"one"),y=r(function(){return!0},h,"true"),b=r(function(){return!1},h,"false");function x(t,e,n){var r=[e].concat([].slice.call(n));console[t].apply(console,r)}var w=function(t,e){var n=t||0;return{level:function(t){return arguments.length?(n=+t,this):n},error:function(){return n>=1&&x(e||"error","ERROR",arguments),this},warn:function(){return n>=2&&x(e||"warn","WARN",arguments),this},info:function(){return n>=3&&x(e||"log","INFO",arguments),this},debug:function(){return n>=4&&x(e||"log","DEBUG",arguments),this}}};const k=t=>"__proto__"!==t;function _(...t){return t.reduce((t,e)=>{for(var n in e)if("signals"===n)t.signals=O(t.signals,e.signals);else{var r="legend"===n?{layout:1}:"style"===n||null;E(t,n,e[n],r)}return t},{})}function E(t,e,n,r){var i,a;if(k(e))if(c(n)&&!u(n))for(i in a=c(t[e])?t[e]:t[e]={},n)r&&(!0===r||r[i])?E(a,i,n[i]):k(i)&&(a[i]=n[i]);else t[e]=n}function O(t,e){if(null==t)return e;const n={},r=[];function i(t){n[t.name]||(n[t.name]=1,r.push(t))}return e.forEach(i),t.forEach(i),r}var S=function(t){return t[t.length-1]},C=function(t){return null==t||""===t?null:+t};function A(t){return function(e){return t*Math.exp(e)}}function N(t){return function(e){return Math.log(t*e)}}function T(t){return function(e){return Math.sign(e)*Math.log1p(Math.abs(e/t))}}function I(t){return function(e){return Math.sign(e)*Math.expm1(Math.abs(e))*t}}function D(t){return function(e){return e<0?-Math.pow(-e,t):Math.pow(e,t)}}function M(t,e,n,r){var i=n(t[0]),a=n(S(t)),o=(a-i)*e;return[r(i-o),r(a-o)]}function R(t,e){return M(t,e,C,m)}function F(t,e){var n=Math.sign(t[0]);return M(t,e,N(n),A(n))}function j(t,e,n){return M(t,e,D(n),D(1/n))}function P(t,e,n){return M(t,e,T(n),I(n))}function L(t,e,n,r,i){var a=r(t[0]),o=r(S(t)),s=null!=e?r(e):(a+o)/2;return[i(s+(a-s)*n),i(s+(o-s)*n)]}function z(t,e,n){return L(t,e,n,C,m)}function B(t,e,n){var r=Math.sign(t[0]);return L(t,e,n,N(r),A(r))}function U(t,e,n,r){return L(t,e,n,D(r),D(1/r))}function W(t,e,n,r){return L(t,e,n,T(r),I(r))}function V(t){return 1+~~(new Date(t).getMonth()/3)}function q(t){return 1+~~(new Date(t).getUTCMonth()/3)}var H=function(t){return null!=t?u(t)?t:[t]:[]},G=function(t,e,n){var r,i=t[0],a=t[1];return a<i&&(r=a,a=i,i=r),(r=a-i)>=n-e?[e,n]:[i=Math.min(Math.max(i,e),n-r),i+r]},$=function(t){return"function"==typeof t},K=function(t,e){var n,i,o,u,c,l,d,h,p,m=[],g=(t=H(t)).map(function(t,e){return null==t?null:(m.push(e),$(t)?t:s(t).map(f).join("]["))}),v=m.length-1,y=H(e),b="var u,v;return ";if(v<0)return null;for(i=0;i<=v;++i)o=g[n=m[i]],$(o)?(u="(u=this."+(l="f"+n)+"(a))",c="(v=this."+l+"(b))",(d=d||{})[l]=o):(u="(u=a["+o+"])",c="(v=b["+o+"])"),l="((v=v instanceof Date?+v:v),(u=u instanceof Date?+u:u))","descending"!==y[n]?(p=1,h=-1):(p=-1,h=1),b+="("+u+"<"+c+"||u==null)&&v!=null?"+h+":(u>v||v==null)&&u!=null?"+p+":"+l+"!==u&&v===v?"+h+":v!==v&&u===u?"+p+(n<v?":":":0");return o=Function("a","b",b+";"),d&&(o=o.bind(d)),t=t.reduce(function(t,e){return $(e)?(a(e)||[]).forEach(function(e){t[e]=1}):null!=e&&(t[e+""]=1),t},{}),r(o,Object.keys(t))},X=function(t){return $(t)?t:function(){return t}},Y=function(t,e){var n,r;function i(){e(r),n=r=null}return function(e){r=e,n&&clearTimeout(n),n=setTimeout(i,t)}},J=function(t){for(var e,n,r=1,i=arguments.length;r<i;++r)for(n in e=arguments[r])t[n]=e[n];return t},Z=function(t,e){var n,r,i,a,o=0;if(t&&(n=t.length))if(null==e){for(r=t[o];o<n&&(null==r||r!=r);r=t[++o]);for(i=a=r;o<n;++o)null!=(r=t[o])&&(r<i&&(i=r),r>a&&(a=r))}else{for(r=e(t[o]);o<n&&(null==r||r!=r);r=e(t[++o]));for(i=a=r;o<n;++o)null!=(r=e(t[o]))&&(r<i&&(i=r),r>a&&(a=r))}return[i,a]},Q=function(t,e){var n,r,i,a,o,s=-1,u=t.length;if(null==e){for(;++s<u;)if(null!=(r=t[s])&&r>=r){n=i=r;break}if(s===u)return[-1,-1];for(a=o=s;++s<u;)null!=(r=t[s])&&(n>r&&(n=r,a=s),i<r&&(i=r,o=s))}else{for(;++s<u;)if(null!=(r=e(t[s],s,t))&&r>=r){n=i=r;break}if(s===u)return[-1,-1];for(a=o=s;++s<u;)null!=(r=e(t[s],s,t))&&(n>r&&(n=r,a=s),i<r&&(i=r,o=s))}return[a,o]};const tt=Object.prototype.hasOwnProperty;var et=function(t,e){return tt.call(t,e)},nt={},rt=function(t){var e,n,r={};function i(t){return et(r,t)&&r[t]!==nt}return e={size:0,empty:0,object:r,has:i,get:function(t){return i(t)?r[t]:void 0},set:function(t,n){return i(t)||(++e.size,r[t]===nt&&--e.empty),r[t]=n,this},delete:function(t){return i(t)&&(--e.size,++e.empty,r[t]=nt),this},clear:function(){e.size=e.empty=0,e.object=r={}},test:function(t){return arguments.length?(n=t,e):n},clean:function(){var t,i,a={},o=0;for(t in r)(i=r[t])===nt||n&&n(i)||(a[t]=i,++o);e.size=o,e.empty=0,e.object=r=a}},t&&Object.keys(t).forEach(function(n){e.set(n,t[n])}),e},it=function(t,e,n,r,i,a){if(!n&&0!==n)return a;var o,s,u=t[0],c=S(t),l=+n;return c<u&&(o=u,u=c,c=o),(o=Math.abs(e-u))<(s=Math.abs(c-e))&&o<=l?r:s<=l?i:a},at=function(t,e){var n=t.prototype=Object.create(e.prototype);return n.constructor=t,n},ot=function(t,e,n,r){var i,a=e[0],o=e[e.length-1];return a>o&&(i=a,a=o,o=i),n=void 0===n||n,r=void 0===r||r,(n?a<=t:a<t)&&(r?t<=o:t<o)},st=function(t){return"boolean"==typeof t},ut=function(t){return"[object Date]"===Object.prototype.toString.call(t)},ct=function(t){return"number"==typeof t},lt=function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},ft=function(t,e){t&&(t=e?H(t).map(function(t){return t.replace(/\\(.)/g,"$1")}):H(t));var n=t&&t.length?Function("_","return ''+"+t.map(function(t){return"_["+(e?f(t):s(t).map(f).join("]["))+"]"}).join("+'|'+")+";"):function(){return""};return r(n,t,"key")},dt=function(t,e){const n=t[0],r=S(t),i=+e;return i?1===i?r:n+i*(r-n):n};var ht=function(t){let e,n,r;t=+t||1e4;const i=()=>{e={},n={},r=0},a=(i,a)=>(++r>t&&(n=e,e={},r=1),e[i]=a);return i(),{clear:i,has:t=>et(e,t)||et(n,t),get:t=>et(e,t)?e[t]:et(n,t)?a(t,n[t]):void 0,set:(t,n)=>et(e,t)?e[t]=n:a(t,n)}},pt=function(t,e,n,r){var i=e.length,a=n.length;if(!a)return e;if(!i)return n;for(var o=r||new e.constructor(i+a),s=0,u=0,c=0;s<i&&u<a;++c)o[c]=t(e[s],n[u])>0?n[u++]:e[s++];for(;s<i;++s,++c)o[c]=e[s];for(;u<a;++u,++c)o[c]=n[u];return o},mt=function(t,e){for(var n="";--e>=0;)n+=t;return n},gt=function(t,e,n,r){var i=n||" ",a=t+"",o=e-a.length;return o<=0?a:"left"===r?mt(i,o)+a:"center"===r?mt(i,~~(o/2))+a+mt(i,Math.ceil(o/2)):a+mt(i,o)},vt=function(t){return t&&S(t)-t[0]||0},yt=function(t){return null==t||""===t?null:!(!t||"false"===t||"0"===t)&&!!t};function bt(t){return ct(t)?t:ut(t)?t:Date.parse(t)}var xt=function(t,e){return e=e||bt,null==t||""===t?null:e(t)},wt=function(t){return null==t||""===t?null:t+""},kt=function(t){for(var e={},n=0,r=t.length;n<r;++n)e[t[n]]=!0;return e},_t=function(t,e,n,r){var i=null!=r?r:"…",a=t+"",o=a.length,s=Math.max(0,e-i.length);return o<=e?a:"left"===n?i+a.slice(o-s):"center"===n?a.slice(0,Math.ceil(s/2))+i+a.slice(o-~~(s/2)):a.slice(0,s)+i},Et=function(t,e,n){if(t){var r,i=0,a=t.length;if(e)for(;i<a;++i)(r=e(t[i]))&&n(r,i,t);else t.forEach(n)}};n.d(e,"f",function(){return r}),n.d(e,"h",function(){return i}),n.d(e,"g",function(){return a}),n.d(e,"w",function(){return p}),n.d(e,"x",function(){return m}),n.d(e,"Ka",function(){return g}),n.d(e,"O",function(){return v}),n.d(e,"Ga",function(){return y}),n.d(e,"r",function(){return b}),n.d(e,"K",function(){return w}),n.d(e,"d",function(){return 0}),n.d(e,"b",function(){return 1}),n.d(e,"e",function(){return 2}),n.d(e,"c",function(){return 3}),n.d(e,"a",function(){return 4}),n.d(e,"N",function(){return _}),n.d(e,"Ja",function(){return E}),n.d(e,"Q",function(){return R}),n.d(e,"R",function(){return F}),n.d(e,"S",function(){return j}),n.d(e,"T",function(){return P}),n.d(e,"La",function(){return z}),n.d(e,"Ma",function(){return B}),n.d(e,"Na",function(){return U}),n.d(e,"Oa",function(){return W}),n.d(e,"V",function(){return V}),n.d(e,"Ha",function(){return q}),n.d(e,"i",function(){return H}),n.d(e,"j",function(){return G}),n.d(e,"k",function(){return K}),n.d(e,"l",function(){return X}),n.d(e,"m",function(){return Y}),n.d(e,"n",function(){return o}),n.d(e,"o",function(){return J}),n.d(e,"p",function(){return Z}),n.d(e,"q",function(){return Q}),n.d(e,"s",function(){return rt}),n.d(e,"t",function(){return d}),n.d(e,"u",function(){return it}),n.d(e,"v",function(){return et}),n.d(e,"y",function(){return at}),n.d(e,"z",function(){return ot}),n.d(e,"A",function(){return u}),n.d(e,"B",function(){return st}),n.d(e,"C",function(){return ut}),n.d(e,"D",function(){return $}),n.d(e,"E",function(){return ct}),n.d(e,"F",function(){return c}),n.d(e,"G",function(){return lt}),n.d(e,"H",function(){return l}),n.d(e,"I",function(){return ft}),n.d(e,"J",function(){return dt}),n.d(e,"L",function(){return ht}),n.d(e,"M",function(){return pt}),n.d(e,"P",function(){return gt}),n.d(e,"U",function(){return S}),n.d(e,"W",function(){return mt}),n.d(e,"X",function(){return vt}),n.d(e,"Y",function(){return s}),n.d(e,"Z",function(){return f}),n.d(e,"Aa",function(){return yt}),n.d(e,"Ba",function(){return xt}),n.d(e,"Ca",function(){return C}),n.d(e,"Ea",function(){return wt}),n.d(e,"Da",function(){return kt}),n.d(e,"Fa",function(){return _t}),n.d(e,"Ia",function(){return Et})},function(t,e,n){"use strict";n.r(e),function(t,r,i,a){n.d(e,"AdadeltaOptimizer",function(){return nd}),n.d(e,"AdagradOptimizer",function(){return rd}),n.d(e,"AdamOptimizer",function(){return id}),n.d(e,"AdamaxOptimizer",function(){return ad}),n.d(e,"DataStorage",function(){return ki}),n.d(e,"ENV",function(){return d}),n.d(e,"Environment",function(){return l}),n.d(e,"KernelBackend",function(){return _i}),n.d(e,"MomentumOptimizer",function(){return sd}),n.d(e,"Optimizer",function(){return ed}),n.d(e,"RMSPropOptimizer",function(){return ud}),n.d(e,"Rank",function(){return St}),n.d(e,"Reduction",function(){return Gc}),n.d(e,"SGDOptimizer",function(){return od}),n.d(e,"Tensor",function(){return Ot}),n.d(e,"TensorBuffer",function(){return wt}),n.d(e,"Variable",function(){return It}),n.d(e,"abs",function(){return Ho}),n.d(e,"acos",function(){return Go}),n.d(e,"acosh",function(){return $o}),n.d(e,"add",function(){return Hs}),n.d(e,"addN",function(){return Gs}),n.d(e,"addStrict",function(){return $s}),n.d(e,"all",function(){return lc}),n.d(e,"any",function(){return fc}),n.d(e,"argMax",function(){return dc}),n.d(e,"argMin",function(){return hc}),n.d(e,"asin",function(){return Ko}),n.d(e,"asinh",function(){return Xo}),n.d(e,"atan",function(){return Yo}),n.d(e,"atan2",function(){return Ks}),n.d(e,"atanh",function(){return Jo}),n.d(e,"avgPool",function(){return tc}),n.d(e,"avgPool3d",function(){return rc}),n.d(e,"backend",function(){return mn}),n.d(e,"backend_util",function(){return Vi}),n.d(e,"basicLSTMCell",function(){return Tc}),n.d(e,"batchNorm",function(){return Fs}),n.d(e,"batchNorm2d",function(){return js}),n.d(e,"batchNorm3d",function(){return Ps}),n.d(e,"batchNorm4d",function(){return Ls}),n.d(e,"batchNormalization",function(){return Rs}),n.d(e,"batchNormalization2d",function(){return Is}),n.d(e,"batchNormalization3d",function(){return Ds}),n.d(e,"batchNormalization4d",function(){return Ms}),n.d(e,"batchToSpaceND",function(){return br}),n.d(e,"booleanMaskAsync",function(){return Au}),n.d(e,"broadcastTo",function(){return xr}),n.d(e,"browser",function(){return Wf}),n.d(e,"buffer",function(){return vr}),n.d(e,"cast",function(){return wr}),n.d(e,"ceil",function(){return Zo}),n.d(e,"clipByValue",function(){return Qo}),n.d(e,"clone",function(){return kr}),n.d(e,"complex",function(){return Mn}),n.d(e,"concat",function(){return Qn}),n.d(e,"concat1d",function(){return tr}),n.d(e,"concat2d",function(){return er}),n.d(e,"concat3d",function(){return nr}),n.d(e,"concat4d",function(){return rr}),n.d(e,"conv1d",function(){return Du}),n.d(e,"conv2d",function(){return Mu}),n.d(e,"conv2dTranspose",function(){return Uu}),n.d(e,"conv3d",function(){return Ru}),n.d(e,"conv3dTranspose",function(){return Wu}),n.d(e,"cos",function(){return ts}),n.d(e,"cosh",function(){return es}),n.d(e,"cumsum",function(){return _r}),n.d(e,"customGrad",function(){return yi}),n.d(e,"deprecationWarn",function(){return Ze}),n.d(e,"depthToSpace",function(){return Er}),n.d(e,"depthwiseConv2d",function(){return Pu}),n.d(e,"diag",function(){return Vc}),n.d(e,"disableDeprecationWarnings",function(){return Je}),n.d(e,"dispose",function(){return an}),n.d(e,"disposeVariables",function(){return Qe}),n.d(e,"div",function(){return Xs}),n.d(e,"divNoNan",function(){return Ys}),n.d(e,"divStrict",function(){return Js}),n.d(e,"dot",function(){return qu}),n.d(e,"dropout",function(){return qc}),n.d(e,"elu",function(){return wc}),n.d(e,"enableDebugMode",function(){return Ye}),n.d(e,"enableProdMode",function(){return Xe}),n.d(e,"engine",function(){return tn}),n.d(e,"env",function(){return f}),n.d(e,"equal",function(){return du}),n.d(e,"equalStrict",function(){return hu}),n.d(e,"erf",function(){return ns}),n.d(e,"exp",function(){return rs}),n.d(e,"expandDims",function(){return Or}),n.d(e,"expm1",function(){return is}),n.d(e,"eye",function(){return Sr}),n.d(e,"fft",function(){return jc}),n.d(e,"fill",function(){return Kn}),n.d(e,"findBackend",function(){return dn}),n.d(e,"findBackendFactory",function(){return hn}),n.d(e,"floor",function(){return as}),n.d(e,"floorDiv",function(){return Zs}),n.d(e,"frame",function(){return Xc}),n.d(e,"fused",function(){return Al}),n.d(e,"gather",function(){return Su}),n.d(e,"gatherND",function(){return Wc}),n.d(e,"gather_util",function(){return Zr}),n.d(e,"getBackend",function(){return ln}),n.d(e,"getGradient",function(){return g}),n.d(e,"getKernel",function(){return m}),n.d(e,"getKernelsForBackend",function(){return v}),n.d(e,"grad",function(){return hi}),n.d(e,"grads",function(){return pi}),n.d(e,"greater",function(){return pu}),n.d(e,"greaterEqual",function(){return mu}),n.d(e,"greaterEqualStrict",function(){return gu}),n.d(e,"greaterStrict",function(){return vu}),n.d(e,"hammingWindow",function(){return Kc}),n.d(e,"hannWindow",function(){return $c}),n.d(e,"ifft",function(){return Pc}),n.d(e,"imag",function(){return Fn}),n.d(e,"image",function(){return xl}),n.d(e,"inTopKAsync",function(){return Zc}),n.d(e,"io",function(){return Lf}),n.d(e,"irfft",function(){return zc}),n.d(e,"isFinite",function(){return vs}),n.d(e,"isInf",function(){return gs}),n.d(e,"isNaN",function(){return ms}),n.d(e,"keep",function(){return on}),n.d(e,"leakyRelu",function(){return kc}),n.d(e,"less",function(){return yu}),n.d(e,"lessEqual",function(){return bu}),n.d(e,"lessEqualStrict",function(){return xu}),n.d(e,"lessStrict",function(){return wu}),n.d(e,"linalg",function(){return hl}),n.d(e,"linspace",function(){return Xn}),n.d(e,"localResponseNormalization",function(){return Ac}),n.d(e,"log",function(){return os}),n.d(e,"log1p",function(){return ss}),n.d(e,"logSigmoid",function(){return us}),n.d(e,"logSoftmax",function(){return wi}),n.d(e,"logSumExp",function(){return pc}),n.d(e,"logicalAnd",function(){return zs}),n.d(e,"logicalNot",function(){return Bs}),n.d(e,"logicalOr",function(){return Us}),n.d(e,"logicalXor",function(){return Ws}),n.d(e,"losses",function(){return ul}),n.d(e,"matMul",function(){return Vu}),n.d(e,"math",function(){return Bf}),n.d(e,"max",function(){return mc}),n.d(e,"maxPool",function(){return Qu}),n.d(e,"maxPool3d",function(){return nc}),n.d(e,"maximum",function(){return Qs}),n.d(e,"maximumStrict",function(){return tu}),n.d(e,"mean",function(){return gc}),n.d(e,"memory",function(){return en}),n.d(e,"min",function(){return vc}),n.d(e,"minimum",function(){return eu}),n.d(e,"minimumStrict",function(){return nu}),n.d(e,"mod",function(){return ru}),n.d(e,"modStrict",function(){return iu}),n.d(e,"moments",function(){return yc}),n.d(e,"movingAverage",function(){return Dc}),n.d(e,"mul",function(){return au}),n.d(e,"mulStrict",function(){return ou}),n.d(e,"multiRNNCell",function(){return Ic}),n.d(e,"multinomial",function(){return Cr}),n.d(e,"neg",function(){return cs}),n.d(e,"nextFrame",function(){return dd}),n.d(e,"norm",function(){return Nc}),n.d(e,"notEqual",function(){return ku}),n.d(e,"notEqualStrict",function(){return _u}),n.d(e,"oneHot",function(){return Ar}),n.d(e,"ones",function(){return Gn}),n.d(e,"onesLike",function(){return Jn}),n.d(e,"op",function(){return Dn}),n.d(e,"outerProduct",function(){return Hu}),n.d(e,"pad",function(){return Nr}),n.d(e,"pad1d",function(){return Tr}),n.d(e,"pad2d",function(){return Ir}),n.d(e,"pad3d",function(){return Dr}),n.d(e,"pad4d",function(){return Mr}),n.d(e,"pool",function(){return ec}),n.d(e,"pow",function(){return su}),n.d(e,"powStrict",function(){return uu}),n.d(e,"prelu",function(){return _c}),n.d(e,"print",function(){return yr}),n.d(e,"prod",function(){return xc}),n.d(e,"profile",function(){return nn}),n.d(e,"rand",function(){return Rr}),n.d(e,"randomGamma",function(){return jr}),n.d(e,"randomNormal",function(){return Fr}),n.d(e,"randomUniform",function(){return Pr}),n.d(e,"range",function(){return Yn}),n.d(e,"ready",function(){return cn}),n.d(e,"real",function(){return Rn}),n.d(e,"reciprocal",function(){return ls}),n.d(e,"registerBackend",function(){return pn}),n.d(e,"registerGradient",function(){return b}),n.d(e,"registerKernel",function(){return y}),n.d(e,"relu",function(){return Ec}),n.d(e,"relu6",function(){return Oc}),n.d(e,"removeBackend",function(){return fn}),n.d(e,"reshape",function(){return Lr}),n.d(e,"reverse",function(){return Gu}),n.d(e,"reverse1d",function(){return $u}),n.d(e,"reverse2d",function(){return Ku}),n.d(e,"reverse3d",function(){return Xu}),n.d(e,"reverse4d",function(){return Yu}),n.d(e,"rfft",function(){return Lc}),n.d(e,"round",function(){return fs}),n.d(e,"rsqrt",function(){return ds}),n.d(e,"scalar",function(){return Ln}),n.d(e,"scatterND",function(){return Fc}),n.d(e,"scatter_util",function(){return ii}),n.d(e,"selu",function(){return Sc}),n.d(e,"separableConv2d",function(){return Bu}),n.d(e,"serialization",function(){return Gf}),n.d(e,"setBackend",function(){return un}),n.d(e,"setPlatform",function(){return gn}),n.d(e,"setdiff1dAsync",function(){return Hr}),n.d(e,"sigmoid",function(){return hs}),n.d(e,"sign",function(){return ps}),n.d(e,"signal",function(){return Jc}),n.d(e,"sin",function(){return ys}),n.d(e,"sinh",function(){return bs}),n.d(e,"slice",function(){return ic}),n.d(e,"slice1d",function(){return ac}),n.d(e,"slice2d",function(){return oc}),n.d(e,"slice3d",function(){return sc}),n.d(e,"slice4d",function(){return uc}),n.d(e,"slice_util",function(){return di}),n.d(e,"softmax",function(){return xi}),n.d(e,"softplus",function(){return xs}),n.d(e,"spaceToBatchND",function(){return zr}),n.d(e,"sparseToDense",function(){return Uc}),n.d(e,"spectral",function(){return Bc}),n.d(e,"split",function(){return ir}),n.d(e,"sqrt",function(){return ws}),n.d(e,"square",function(){return Wo}),n.d(e,"squaredDifference",function(){return qo}),n.d(e,"squaredDifferenceStrict",function(){return cu}),n.d(e,"squeeze",function(){return Br}),n.d(e,"stack",function(){return Ur}),n.d(e,"step",function(){return ks}),n.d(e,"stft",function(){return Yc}),n.d(e,"stridedSlice",function(){return Mc}),n.d(e,"sub",function(){return lu}),n.d(e,"subStrict",function(){return fu}),n.d(e,"sum",function(){return bc}),n.d(e,"sumOutType",function(){return Rt}),n.d(e,"tan",function(){return _s}),n.d(e,"tanh",function(){return Es}),n.d(e,"tensor",function(){return jn}),n.d(e,"tensor1d",function(){return zn}),n.d(e,"tensor2d",function(){return Bn}),n.d(e,"tensor3d",function(){return Un}),n.d(e,"tensor4d",function(){return Wn}),n.d(e,"tensor5d",function(){return Vn}),n.d(e,"tensor6d",function(){return qn}),n.d(e,"tensor_util",function(){return zt}),n.d(e,"test_util",function(){return Zf}),n.d(e,"tidy",function(){return rn}),n.d(e,"tile",function(){return Wr}),n.d(e,"time",function(){return sn}),n.d(e,"topk",function(){return Rc}),n.d(e,"train",function(){return ld}),n.d(e,"transpose",function(){return Cc}),n.d(e,"truncatedNormal",function(){return Vr}),n.d(e,"unregisterGradient",function(){return w}),n.d(e,"unregisterKernel",function(){return x}),n.d(e,"unsortedSegmentSum",function(){return Cu}),n.d(e,"unstack",function(){return qr}),n.d(e,"util",function(){return dt}),n.d(e,"valueAndGrad",function(){return mi}),n.d(e,"valueAndGrads",function(){return gi}),n.d(e,"variable",function(){return Hn}),n.d(e,"variableGrads",function(){return vi}),n.d(e,"version_core",function(){return Qf}),n.d(e,"webgl",function(){return td}),n.d(e,"where",function(){return Vs}),n.d(e,"whereAsync",function(){return qs}),n.d(e,"zeros",function(){return $n}),n.d(e,"zerosLike",function(){return Zn});
  19. /**
  20. * @license
  21. * Copyright 2020 Google LLC. All Rights Reserved.
  22. * Licensed under the Apache License, Version 2.0 (the "License");
  23. * you may not use this file except in compliance with the License.
  24. * You may obtain a copy of the License at
  25. *
  26. * http://www.apache.org/licenses/LICENSE-2.0
  27. *
  28. * Unless required by applicable law or agreed to in writing, software
  29. * distributed under the License is distributed on an "AS IS" BASIS,
  30. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  31. * See the License for the specific language governing permissions and
  32. * limitations under the License.
  33. * =============================================================================
  34. */
  35. var o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function s(t,e){function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function u(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})}function c(t,e){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=(i=o.trys).length>0&&i[i.length-1])&&(6===a[0]||2===a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}var l=function(){function t(t){this.global=t,this.flags={},this.flagRegistry={},this.urlFlags={},this.populateURLFlags()}return t.prototype.setPlatform=function(t,e){null!=this.platform&&console.warn("Platform "+this.platformName+" has already been set. Overwriting the platform with "+e+"."),this.platformName=t,this.platform=e},t.prototype.registerFlag=function(t,e,n){if(this.flagRegistry[t]={evaluationFn:e,setHook:n},null!=this.urlFlags[t]){var r=this.urlFlags[t];console.warn("Setting feature override from URL "+t+": "+r+"."),this.set(t,r)}},t.prototype.get=function(t){return t in this.flags?this.flags[t]:(this.flags[t]=this.evaluateFlag(t),this.flags[t])},t.prototype.getNumber=function(t){return this.get(t)},t.prototype.getBool=function(t){return this.get(t)},t.prototype.getFlags=function(){return this.flags},Object.defineProperty(t.prototype,"features",{get:function(){return this.flags},enumerable:!0,configurable:!0}),t.prototype.set=function(t,e){if(null==this.flagRegistry[t])throw new Error("Cannot set flag "+t+" as it has not been registered.");this.flags[t]=e,null!=this.flagRegistry[t].setHook&&this.flagRegistry[t].setHook(e)},t.prototype.evaluateFlag=function(t){if(null==this.flagRegistry[t])throw new Error("Cannot evaluate flag '"+t+"': no evaluation function found.");return this.flagRegistry[t].evaluationFn()},t.prototype.setFlags=function(t){this.flags=Object.assign({},t)},t.prototype.reset=function(){this.flags={},this.urlFlags={},this.populateURLFlags()},t.prototype.populateURLFlags=function(){var t=this;if(void 0!==this.global&&void 0!==this.global.location&&void 0!==this.global.location.search){var e,n,r=(e=this.global.location.search,n={},e.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g,function(t){for(var e=[],r=1;r<arguments.length;r++)e[r-1]=arguments[r];return function(t,e,n){t[decodeURIComponent(e)]=decodeURIComponent(n||"")}(n,e[0],e[1]),e.join("=")}),n);"tfjsflags"in r&&r.tfjsflags.split(",").forEach(function(e){var n=e.split(":"),r=n[0],i=n[1];t.urlFlags[r]=function(t,e){if("true"===(e=e.toLowerCase())||"false"===e)return"true"===e;if(""+ +e===e)return+e;throw new Error("Could not parse value flag value "+e+" for flag "+t+".")}(r,i)})}},t}();function f(){return d}var d=null,h=new Map,p=new Map;function m(t,e){var n=k(t,e);return h.get(n)}function g(t){return p.get(t)}function v(t){for(var e=h.entries(),n=[];;){var r=e.next(),i=r.done,a=r.value;if(i)break;var o=a[0],s=a[1];o.split("_")[0]===t&&n.push(s)}return n}function y(t){var e=t.kernelName,n=t.backendName,r=k(e,n);if(h.has(r))throw new Error("The kernel '"+e+"' for backend '"+n+"' is already registered");h.set(r,t)}function b(t){var e=t.kernelName;p.has(e)&&console.warn("Overriding the gradient for '"+e+"'"),p.set(e,t)}function x(t,e){var n=k(t,e);if(!h.has(n))throw new Error("The kernel '"+t+"' for backend '"+e+"' is not registered");h.delete(n)}function w(t){if(!p.has(t))throw new Error("The gradient '"+t+"' for backend is not registered");p.delete(t)}function k(t,e){return e+"_"+t}function _(t){for(var e=t.length,n=0,r=0;e>0;)r=Math.random()*e|0,n=t[--e],t[e]=t[r],t[r]=n}function E(t,e,n){return Math.max(t,Math.min(e,n))}function O(t){return t%2==0?t:t+1}function S(t){for(var e=0,n=0;n<t.length;n++)e+=t[n];return e}function C(t,e){if(!t)throw new Error("string"==typeof e?e:e())}function A(t,e,n){void 0===n&&(n=""),C(D(t,e),function(){return n+" Shapes "+t+" and "+e+" must match"})}function N(t){C(null!=t,function(){return"The input to the tensor constructor must be a non-null value."})}function T(t,e,n){if(void 0===e&&(e=[]),void 0===n&&(n=!1),null==e&&(e=[]),Array.isArray(t)||G(t)&&!n)for(var r=0;r<t.length;++r)T(t[r],e,n);else e.push(t);return e}function I(t){if(0===t.length)return 1;for(var e=t[0],n=1;n<t.length;n++)e*=t[n];return e}function D(t,e){if(t===e)return!0;if(null==t||null==e)return!1;if(t.length!==e.length)return!1;for(var n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}function M(t){return t%1==0}function R(t){if(null!=Math.tanh)return Math.tanh(t);if(t===1/0)return 1;if(t===-1/0)return-1;var e=Math.exp(2*t);return(e-1)/(e+1)}function F(t){var e=Math.ceil(Math.sqrt(t));return[e,Math.ceil(t/e)]}function j(t,e){return e<=t.length?t:t+" ".repeat(e-t.length)}function P(t,e,n){return void 0===e&&(e=function(t){return 0}),new Promise(function(r,i){var a=0,o=function(){if(t())r();else{var s=e(++a);null!=n&&a>=n?i():setTimeout(o,s)}};o()})}function L(t,e){for(var n=1,r=-1,i=0;i<t.length;++i)if(t[i]>=0)n*=t[i];else if(-1===t[i]){if(-1!==r)throw Error("Shapes can only have 1 implicit size. Found -1 at dim "+r+" and dim "+i);r=i}else if(t[i]<0)throw Error("Shapes can not be < 0. Found "+t[i]+" at dim "+i);if(-1===r){if(e>0&&e!==n)throw Error("Size("+e+") must match the product of shape "+t);return t}if(0===n)throw Error("Cannot infer the missing size in ["+t+"] when there are 0 elements");if(e%n!=0)throw Error("The implicit shape can't be a fractional number. Got "+e+" / "+n);var a=t.slice();return a[r]=e/n,a}function z(t,e){var n=e.length;return C((t=null==t?e.map(function(t,e){return e}):[].concat(t)).every(function(t){return t>=-n&&t<n}),function(){return"All values in axis param must be in range [-"+n+", "+n+") but got axis "+t}),C(t.every(function(t){return M(t)}),function(){return"All values in axis param must be integers but got axis "+t}),t.map(function(t){return t<0?n+t:t})}function B(t,e){for(var n=[],r=[],i=null!=e&&Array.isArray(e)&&0===e.length,a=null==e||i?null:z(e,t).sort(),o=0,s=0;s<t.length;++s){if(null!=a){if(a[o]===s&&1!==t[s])throw new Error("Can't squeeze axis "+s+" since its dim '"+t[s]+"' is not 1");(null==a[o]||a[o]>s)&&1===t[s]&&(n.push(t[s]),r.push(s)),a[o]<=s&&o++}1!==t[s]&&(n.push(t[s]),r.push(s))}return{newShape:n,keptDims:r}}function U(t,e){var n=null;if(null==t||"float32"===t)n=new Float32Array(e);else if("int32"===t)n=new Int32Array(e);else{if("bool"!==t)throw new Error("Unknown data type "+t);n=new Uint8Array(e)}return n}function W(t,e){var n=null;if(null==t||"float32"===t)n=new Float32Array(e);else if("int32"===t)n=new Int32Array(e);else if("bool"===t)n=new Uint8Array(e);else{if("string"!==t)throw new Error("Unknown data type "+t);n=new Array(e)}return n}function V(t,e){for(var n=0;n<t.length;n++){var r=t[n];if(isNaN(r)||!isFinite(r))throw Error("A tensor of type "+e+" being uploaded contains "+r+".")}}function q(t){return"bool"===t||"complex64"===t||"float32"===t||"int32"===t||"string"===t}function H(t,e){return!("complex64"===e||"float32"===e&&"complex64"!==t||"int32"===e&&"float32"!==t&&"complex64"!==t||"bool"===e&&"bool"===t)}function G(t){return t instanceof Float32Array||t instanceof Int32Array||t instanceof Uint8Array}function $(t){if("float32"===t||"int32"===t)return 4;if("complex64"===t)return 8;if("bool"===t)return 1;throw new Error("Unknown dtype "+t)}function K(t){if(null==t)return 0;var e=0;return t.forEach(function(t){return e+=t.length}),e}function X(t){return"string"==typeof t||t instanceof String}function Y(t){return"boolean"==typeof t}function J(t){return"number"==typeof t}function Z(t){return Array.isArray(t)?Z(t[0]):t instanceof Float32Array?"float32":t instanceof Int32Array||t instanceof Uint8Array?"int32":J(t)?"float32":X(t)?"string":Y(t)?"bool":"float32"}function Q(t){return!!(t&&t.constructor&&t.call&&t.apply)}function tt(t,e){for(var n=e;n<t;++n)if(t%n==0)return n;return t}function et(t){var e=t.length;if(e<2)return[];var n=new Array(e-1);n[e-2]=t[e-1];for(var r=e-3;r>=0;--r)n[r]=n[r+1]*t[r+1];return n}function nt(t,e,n){if("string"===e)throw new Error("Cannot convert a string[] to a TypedArray");if(Array.isArray(t)&&(t=T(t)),n&&V(t,e),function(t,e){return t instanceof Float32Array&&"float32"===e||t instanceof Int32Array&&"int32"===e||t instanceof Uint8Array&&"bool"===e}(t,e))return t;if(null==e||"float32"===e||"complex64"===e)return new Float32Array(t);if("int32"===e)return new Int32Array(t);if("bool"===e){for(var r=new Uint8Array(t.length),i=0;i<r.length;++i)0!==Math.round(t[i])&&(r[i]=1);return r}throw new Error("Unknown data type "+e)}function rt(t,e){if(0===t.length)return e[0];var n=t.reduce(function(t,e){return t*e});if(0===n)return[];if(n!==e.length)throw new Error("["+t+"] does not match the input size.");return function t(e,n,r){var i=new Array;if(1===n.length)for(var a=n[0],o=0;o<a;o++)i[o]=r[e+o];else{a=n[0];var s=n.slice(1),u=s.reduce(function(t,e){return t*e});for(o=0;o<a;o++)i[o]=t(e+o*u,s,r)}return i}(0,t,e)}function it(t,e){for(var n=at(t,e),r=0;r<n.length;r++)n[r]=1;return n}function at(t,e){if(null==e||"float32"===e||"complex64"===e)return new Float32Array(t);if("int32"===e)return new Int32Array(t);if("bool"===e)return new Uint8Array(t);throw new Error("Unknown data type "+e)}function ot(){return f().platform.now()}function st(t){t.forEach(function(e){C(Number.isInteger(e)&&e>=0,function(){return"Tensor must have a shape comprised of positive integers but got shape ["+t+"]."})})}function ut(t,e){return void 0===e&&(e="utf-8"),e=e||"utf-8",f().platform.encode(t,e)}function ct(t,e){return void 0===e&&(e="utf-8"),e=e||"utf-8",f().platform.decode(t,e)}function lt(t,e,n){if(0===e)return 0;if(1===e)return t[0];for(var r=t[t.length-1],i=0;i<t.length-1;++i)r+=n[i]*t[i];return r}function ft(t,e,n){if(0===e)return[];if(1===e)return[t];for(var r=new Array(e),i=0;i<r.length-1;++i)r[i]=Math.floor(t/n[i]),t-=r[i]*n[i];return r[r.length-1]=t,r}var dt=Object.freeze({shuffle:_,clamp:E,nearestLargerEven:O,sum:S,randUniform:function(t,e){var n=Math.random();return e*n+(1-n)*t},distSquared:function(t,e){for(var n=0,r=0;r<t.length;r++){var i=Number(t[r])-Number(e[r]);n+=i*i}return n},assert:C,assertShapesMatch:A,assertNonNull:N,flatten:T,sizeFromShape:I,isScalarShape:function(t){return 0===t.length},arraysEqual:D,isInt:M,tanh:R,sizeToSquarishShape:F,createShuffledIndices:function(t){for(var e=new Uint32Array(t),n=0;n<t;++n)e[n]=n;return _(e),e},rightPad:j,repeatedTry:P,inferFromImplicitShape:L,parseAxisParam:z,squeezeShape:B,getTypedArrayFromDType:U,getArrayFromDType:W,checkConversionForErrors:V,isValidDtype:q,hasEncodingLoss:H,isTypedArray:G,bytesPerElement:$,bytesFromStringArray:K,isString:X,isBoolean:Y,isNumber:J,inferDtype:Z,isFunction:Q,nearestDivisor:tt,computeStrides:et,toTypedArray:nt,toNestedArray:rt,makeOnesTypedArray:it,makeZerosTypedArray:at,now:ot,assertNonNegativeIntegerDimensions:st,fetch:function(t,e){return f().platform.fetch(t,e)},encodeString:ut,decodeString:ct,locToIndex:lt,indexToLoc:ft}),ht=function(){function t(t,e){this.backendTimer=t,this.logger=e,null==e&&(this.logger=new pt)}return t.prototype.profileKernel=function(t,e,n){var r,i=this,a=this.backendTimer.time(function(){r=n()});return r.forEach(function(n){n.data().then(function(r){!function(t,e,n){if("float32"!==e)return!1;for(var r=0;r<t.length;r++){var i=t[r];if(isNaN(i)||!isFinite(i))return console.warn("Found "+i+" in the result of '"+n+"'"),!0}}(r,n.dtype,t),a.then(function(a){var o="";null!=a.getExtraProfileInfo&&(o=a.getExtraProfileInfo()),i.logger.logKernelProfile(t,n,r,a.kernelMs,e,o)})})}),r},t}(),pt=function(){function t(){}return t.prototype.logKernelProfile=function(t,e,n,r,i,a){var o="number"==typeof r?j(r+"ms",9):r.error,s=j(t,25),u=e.rank,c=e.size,l=j(e.shape.toString(),14),f="";for(var d in i){var h=i[d].shape||e.shape,p=h.length;f+=d+": "+p+"D "+(p>0?h:"")+" "}console.log("%c"+s+"\t%c"+o+"\t%c"+u+"D "+l+"\t%c"+c+"\t%c"+f+"\t%c"+a,"font-weight:bold","color:red","color:blue","color: orange","color: green","color: steelblue")},t}(),mt=20,gt=3,vt=7;function yt(t,e,n){return j(Array.isArray(t)?parseFloat(t[0].toFixed(vt))+" + "+parseFloat(t[1].toFixed(vt))+"j":X(t)?"'"+t+"'":"bool"===n?bt(t):parseFloat(t.toFixed(vt)).toString(),e)}function bt(t){return 0===t?"false":"true"}function xt(t){for(var e=[],n=0;n<t.length;n+=2)e.push([t[n],t[n+1]]);return e}var wt=function(){function t(t,e,n){var r=this;if(this.dtype=e,this.shape=t.slice(),this.size=I(t),null!=n){var i=n.length;C(i===this.size,function(){return"Length of values '"+i+"' does not match the size inferred by the shape '"+r.size+"'."})}if("complex64"===e)throw new Error("complex64 dtype TensorBuffers are not supported. Please create a TensorBuffer for the real and imaginary parts separately and call tf.complex(real, imag).");this.values=n||W(e,this.size),this.strides=et(t)}return t.prototype.set=function(t){for(var e=this,n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];0===n.length&&(n=[0]),C(n.length===this.rank,function(){return"The number of provided coordinates ("+n.length+") must match the rank ("+e.rank+")"});var i=this.locToIndex(n);this.values[i]=t},t.prototype.get=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];0===t.length&&(t=[0]);for(var n=0,r=0,i=t;r<i.length;r++){var a=i[r];if(a<0||a>=this.shape[n]){var o="Requested out of range element at "+t+". Buffer shape="+this.shape;throw new Error(o)}n++}for(var s=t[t.length-1],u=0;u<t.length-1;++u)s+=this.strides[u]*t[u];return this.values[s]},t.prototype.locToIndex=function(t){if(0===this.rank)return 0;if(1===this.rank)return t[0];for(var e=t[t.length-1],n=0;n<t.length-1;++n)e+=this.strides[n]*t[n];return e},t.prototype.indexToLoc=function(t){if(0===this.rank)return[];if(1===this.rank)return[t];for(var e=new Array(this.shape.length),n=0;n<e.length-1;++n)e[n]=Math.floor(t/this.strides[n]),t-=e[n]*this.strides[n];return e[e.length-1]=t,e},Object.defineProperty(t.prototype,"rank",{get:function(){return this.shape.length},enumerable:!0,configurable:!0}),t.prototype.toTensor=function(){return kt().makeTensor(this.values,this.shape,this.dtype)},t}(),kt=null,_t=null,Et=null,Ot=function(){function t(t,e,n,r){this.kept=!1,this.isDisposedInternal=!1,this.shape=t.slice(),this.dtype=e||"float32",this.size=I(t),this.strides=et(t),this.dataId=n,this.id=r,this.rankType=this.rank<5?this.rank.toString():"higher"}return t.prototype.flatten=function(){return this.throwIfDisposed(),this.as1D()},t.prototype.asScalar=function(){return this.throwIfDisposed(),C(1===this.size,function(){return"The array must have only 1 element."}),this.reshape([])},t.prototype.as1D=function(){return this.throwIfDisposed(),this.reshape([this.size])},t.prototype.as2D=function(t,e){return this.throwIfDisposed(),this.reshape([t,e])},t.prototype.as3D=function(t,e,n){return this.throwIfDisposed(),this.reshape([t,e,n])},t.prototype.as4D=function(t,e,n,r){return this.throwIfDisposed(),this.reshape([t,e,n,r])},t.prototype.as5D=function(t,e,n,r,i){return this.throwIfDisposed(),this.reshape([t,e,n,r,i])},t.prototype.asType=function(t){return this.throwIfDisposed(),_t.cast(this,t)},Object.defineProperty(t.prototype,"rank",{get:function(){return this.shape.length},enumerable:!0,configurable:!0}),t.prototype.buffer=function(){return u(this,void 0,void 0,function(){var t;return c(this,function(e){switch(e.label){case 0:return[4,this.data()];case 1:return t=e.sent(),[2,_t.buffer(this.shape,this.dtype,t)]}})})},t.prototype.bufferSync=function(){return _t.buffer(this.shape,this.dtype,this.dataSync())},t.prototype.array=function(){return u(this,void 0,void 0,function(){var t;return c(this,function(e){switch(e.label){case 0:return[4,this.data()];case 1:return t=e.sent(),[2,rt(this.shape,t)]}})})},t.prototype.arraySync=function(){return rt(this.shape,this.dataSync())},t.prototype.data=function(){return u(this,void 0,void 0,function(){var t,e;return c(this,function(n){switch(n.label){case 0:return this.throwIfDisposed(),t=kt().read(this.dataId),"string"!==this.dtype?[3,2]:[4,t];case 1:e=n.sent();try{return[2,e.map(function(t){return ct(t)})]}catch(t){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}n.label=2;case 2:return[2,t]}})})},t.prototype.dataSync=function(){this.throwIfDisposed();var t=kt().readSync(this.dataId);if("string"===this.dtype)try{return t.map(function(t){return ct(t)})}catch(t){throw new Error("Failed to decode the string bytes into utf-8. To get the original bytes, call tensor.bytes().")}return t},t.prototype.bytes=function(){return u(this,void 0,void 0,function(){var t;return c(this,function(e){switch(e.label){case 0:return this.throwIfDisposed(),[4,kt().read(this.dataId)];case 1:return t=e.sent(),"string"===this.dtype?[2,t]:[2,new Uint8Array(t.buffer)]}})})},t.prototype.dispose=function(){this.isDisposed||(kt().disposeTensor(this),this.isDisposedInternal=!0)},Object.defineProperty(t.prototype,"isDisposed",{get:function(){return this.isDisposedInternal},enumerable:!0,configurable:!0}),t.prototype.throwIfDisposed=function(){if(this.isDisposed)throw new Error("Tensor is disposed.")},t.prototype.toFloat=function(){return this.asType("float32")},t.prototype.toInt=function(){return this.asType("int32")},t.prototype.toBool=function(){return this.asType("bool")},t.prototype.print=function(t){return void 0===t&&(t=!1),_t.print(this,t)},t.prototype.reshape=function(t){return this.throwIfDisposed(),_t.reshape(this,t)},t.prototype.reshapeAs=function(t){return this.throwIfDisposed(),this.reshape(t.shape)},t.prototype.expandDims=function(t){return void 0===t&&(t=0),_t.expandDims(this,t)},t.prototype.cumsum=function(t,e,n){return void 0===t&&(t=0),void 0===e&&(e=!1),void 0===n&&(n=!1),_t.cumsum(this,t,e,n)},t.prototype.squeeze=function(t){return this.throwIfDisposed(),_t.squeeze(this,t)},t.prototype.clone=function(){return this.throwIfDisposed(),_t.clone(this)},t.prototype.oneHot=function(t,e,n){return this.throwIfDisposed(),_t.oneHot(this,t,e,n)},t.prototype.toString=function(t){return void 0===t&&(t=!1),function(t,e,n,r){var i=et(e),a=function(t,e,n,r){var i=I(e),a=r[r.length-1],o=new Array(a).fill(0),s=e.length,u="complex64"===n?xt(t):t;if(s>1)for(var c=0;c<i/a;c++)for(var l=c*a,f=0;f<a;f++)o[f]=Math.max(o[f],yt(u[l+f],0,n).length);return o}(t,e,n,i),o=e.length,s=function t(e,n,r,i,a,o){void 0===o&&(o=!0);var s="complex64"===r?2:1,u=n[0],c=n.length;if(0===c)return"complex64"===r?[yt(xt(e)[0],0,r)]:"bool"===r?[bt(e[0])]:[e[0].toString()];if(1===c){if(u>mt){var l=gt*s,f=Array.from(e.slice(0,l)),d=Array.from(e.slice((u-gt)*s,u*s));return"complex64"===r&&(f=xt(f),d=xt(d)),["["+f.map(function(t,e){return yt(t,a[e],r)}).join(", ")+", ..., "+d.map(function(t,e){return yt(t,a[u-gt+e],r)}).join(", ")+"]"]}return["["+("complex64"===r?xt(e):Array.from(e)).map(function(t,e){return yt(t,a[e],r)}).join(", ")+"]"]}var h=n.slice(1),p=i.slice(1),m=i[0]*s,g=[];if(u>mt){for(var v=0;v<gt;v++){var y=(b=v*m)+m;g.push.apply(g,t(e.slice(b,y),h,r,p,a,!1))}for(g.push("..."),v=u-gt;v<u;v++)y=(b=v*m)+m,g.push.apply(g,t(e.slice(b,y),h,r,p,a,v===u-1))}else for(v=0;v<u;v++){var b;y=(b=v*m)+m,g.push.apply(g,t(e.slice(b,y),h,r,p,a,v===u-1))}var x=2===c?",":"";for(g[0]="["+g[0]+x,v=1;v<g.length-1;v++)g[v]=" "+g[v]+x;var w=",\n";for(v=2;v<c;v++)w+="\n";return g[g.length-1]=" "+g[g.length-1]+"]"+(o?"":w),g}(t,e,n,i,a),u=["Tensor"];return r&&(u.push(" dtype: "+n),u.push(" rank: "+o),u.push(" shape: ["+e+"]"),u.push(" values:")),u.push(s.map(function(t){return" "+t}).join("\n")),u.join("\n")}(this.dataSync(),this.shape,this.dtype,t)},t.prototype.tile=function(t){return this.throwIfDisposed(),_t.tile(this,t)},t.prototype.gather=function(t,e){return void 0===e&&(e=0),this.throwIfDisposed(),_t.gather(this,t,e)},t.prototype.matMul=function(t,e,n){return void 0===e&&(e=!1),void 0===n&&(n=!1),this.throwIfDisposed(),_t.matMul(this,t,e,n)},t.prototype.dot=function(t){return this.throwIfDisposed(),_t.dot(this,t)},t.prototype.norm=function(t,e,n){return void 0===t&&(t="euclidean"),void 0===e&&(e=null),void 0===n&&(n=!1),this.throwIfDisposed(),_t.norm(this,t,e,n)},t.prototype.slice=function(t,e){return this.throwIfDisposed(),_t.slice(this,t,e)},t.prototype.reverse=function(t){return this.throwIfDisposed(),_t.reverse(this,t)},t.prototype.concat=function(e,n){return void 0===n&&(n=0),this.throwIfDisposed(),e instanceof t&&(e=[e]),_t.concat([this].concat(e),n)},t.prototype.split=function(t,e){return void 0===e&&(e=0),this.throwIfDisposed(),_t.split(this,t,e)},t.prototype.stack=function(t,e){return void 0===e&&(e=0),_t.stack([this,t],e)},t.prototype.unstack=function(t){return void 0===t&&(t=0),_t.unstack(this,t)},t.prototype.pad=function(t,e){return void 0===e&&(e=0),_t.pad(this,t,e)},t.prototype.batchNormalization=function(t,e,n,r,i){return void 0===n&&(n=.001),Et("tf.batchNormalization() is going away. Use tf.batchNorm() instead, and note the positional argument change of scale, offset, and varianceEpsilon"),this.batchNorm(t,e,i,r,n)},t.prototype.batchNorm=function(t,e,n,r,i){return void 0===i&&(i=.001),this.throwIfDisposed(),_t.batchNorm(this,t,e,n,r,i)},t.prototype.all=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),_t.all(this,t,e)},t.prototype.any=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),_t.any(this,t,e)},t.prototype.logSumExp=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),_t.logSumExp(this,t,e)},t.prototype.sum=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),_t.sum(this,t,e)},t.prototype.prod=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),_t.prod(this,t,e)},t.prototype.mean=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),_t.mean(this,t,e)},t.prototype.min=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),_t.min(this,t,e)},t.prototype.max=function(t,e){return void 0===t&&(t=null),void 0===e&&(e=!1),this.throwIfDisposed(),_t.max(this,t,e)},t.prototype.argMin=function(t){return void 0===t&&(t=null),this.throwIfDisposed(),_t.argMin(this,t)},t.prototype.argMax=function(t){return void 0===t&&(t=null),this.throwIfDisposed(),_t.argMax(this,t)},t.prototype.cast=function(t){return this.throwIfDisposed(),_t.cast(this,t)},t.prototype.add=function(t){return this.throwIfDisposed(),_t.add(this,t)},t.prototype.addStrict=function(t){return this.throwIfDisposed(),_t.addStrict(this,t)},t.prototype.atan2=function(t){return this.throwIfDisposed(),_t.atan2(this,t)},t.prototype.sub=function(t){return this.throwIfDisposed(),_t.sub(this,t)},t.prototype.subStrict=function(t){return this.throwIfDisposed(),_t.subStrict(this,t)},t.prototype.pow=function(t){return this.throwIfDisposed(),_t.pow(this,t)},t.prototype.powStrict=function(t){return this.throwIfDisposed(),_t.powStrict(this,t)},t.prototype.mul=function(t){return this.throwIfDisposed(),_t.mul(this,t)},t.prototype.mulStrict=function(t){return this.throwIfDisposed(),_t.mulStrict(this,t)},t.prototype.div=function(t){return this.throwIfDisposed(),_t.div(this,t)},t.prototype.divNoNan=function(t){return this.throwIfDisposed(),_t.divNoNan(this,t)},t.prototype.floorDiv=function(t){return this.throwIfDisposed(),_t.floorDiv(this,t)},t.prototype.divStrict=function(t){return this.throwIfDisposed(),_t.divStrict(this,t)},t.prototype.minimum=function(t){return this.throwIfDisposed(),_t.minimum(this,t)},t.prototype.minimumStrict=function(t){return this.throwIfDisposed(),_t.minimumStrict(this,t)},t.prototype.maximum=function(t){return this.throwIfDisposed(),_t.maximum(this,t)},t.prototype.maximumStrict=function(t){return this.throwIfDisposed(),_t.maximumStrict(this,t)},t.prototype.mod=function(t){return this.throwIfDisposed(),_t.mod(this,t)},t.prototype.modStrict=function(t){return this.throwIfDisposed(),_t.modStrict(this,t)},t.prototype.squaredDifferenceStrict=function(t){return this.throwIfDisposed(),_t.squaredDifferenceStrict(this,t)},t.prototype.transpose=function(t){return this.throwIfDisposed(),_t.transpose(this,t)},t.prototype.notEqual=function(t){return this.throwIfDisposed(),_t.notEqual(this,t)},t.prototype.notEqualStrict=function(t){return this.throwIfDisposed(),_t.notEqualStrict(this,t)},t.prototype.less=function(t){return this.throwIfDisposed(),_t.less(this,t)},t.prototype.lessStrict=function(t){return this.throwIfDisposed(),_t.lessStrict(this,t)},t.prototype.equal=function(t){return this.throwIfDisposed(),_t.equal(this,t)},t.prototype.equalStrict=function(t){return this.throwIfDisposed(),_t.equalStrict(this,t)},t.prototype.lessEqual=function(t){return this.throwIfDisposed(),_t.lessEqual(this,t)},t.prototype.lessEqualStrict=function(t){return this.throwIfDisposed(),_t.lessEqualStrict(this,t)},t.prototype.greater=function(t){return this.throwIfDisposed(),_t.greater(this,t)},t.prototype.greaterStrict=function(t){return this.throwIfDisposed(),_t.greaterStrict(this,t)},t.prototype.greaterEqual=function(t){return this.throwIfDisposed(),_t.greaterEqual(this,t)},t.prototype.greaterEqualStrict=function(t){return this.throwIfDisposed(),_t.greaterEqualStrict(this,t)},t.prototype.logicalAnd=function(t){return this.throwIfDisposed(),_t.logicalAnd(this,t)},t.prototype.logicalOr=function(t){return this.throwIfDisposed(),_t.logicalOr(this,t)},t.prototype.logicalNot=function(){return this.throwIfDisposed(),_t.logicalNot(this)},t.prototype.logicalXor=function(t){return this.throwIfDisposed(),_t.logicalXor(this,t)},t.prototype.where=function(t,e){return this.throwIfDisposed(),_t.where(t,this,e)},t.prototype.neg=function(){return this.throwIfDisposed(),_t.neg(this)},t.prototype.ceil=function(){return this.throwIfDisposed(),_t.ceil(this)},t.prototype.floor=function(){return this.throwIfDisposed(),_t.floor(this)},t.prototype.sign=function(){return this.throwIfDisposed(),_t.sign(this)},t.prototype.isNaN=function(){return this.throwIfDisposed(),_t.isNaN(this)},t.prototype.isInf=function(){return this.throwIfDisposed(),_t.isInf(this)},t.prototype.isFinite=function(){return this.throwIfDisposed(),_t.isFinite(this)},t.prototype.exp=function(){return this.throwIfDisposed(),_t.exp(this)},t.prototype.expm1=function(){return this.throwIfDisposed(),_t.expm1(this)},t.prototype.log=function(){return this.throwIfDisposed(),_t.log(this)},t.prototype.log1p=function(){return this.throwIfDisposed(),_t.log1p(this)},t.prototype.sqrt=function(){return this.throwIfDisposed(),_t.sqrt(this)},t.prototype.rsqrt=function(){return this.throwIfDisposed(),_t.rsqrt(this)},t.prototype.square=function(){return this.throwIfDisposed(),_t.square(this)},t.prototype.reciprocal=function(){return this.throwIfDisposed(),_t.reciprocal(this)},t.prototype.abs=function(){return this.throwIfDisposed(),_t.abs(this)},t.prototype.clipByValue=function(t,e){return this.throwIfDisposed(),_t.clipByValue(this,t,e)},t.prototype.relu=function(){return this.throwIfDisposed(),_t.relu(this)},t.prototype.relu6=function(){return this.throwIfDisposed(),_t.relu6(this)},t.prototype.elu=function(){return this.throwIfDisposed(),_t.elu(this)},t.prototype.selu=function(){return this.throwIfDisposed(),_t.selu(this)},t.prototype.leakyRelu=function(t){return void 0===t&&(t=.2),this.throwIfDisposed(),_t.leakyRelu(this,t)},t.prototype.prelu=function(t){return this.throwIfDisposed(),_t.prelu(this,t)},t.prototype.sigmoid=function(){return this.throwIfDisposed(),_t.sigmoid(this)},t.prototype.logSigmoid=function(){return this.throwIfDisposed(),_t.logSigmoid(this)},t.prototype.softplus=function(){return this.throwIfDisposed(),_t.softplus(this)},t.prototype.zerosLike=function(){return this.throwIfDisposed(),_t.zerosLike(this)},t.prototype.onesLike=function(){return this.throwIfDisposed(),_t.onesLike(this)},t.prototype.sin=function(){return this.throwIfDisposed(),_t.sin(this)},t.prototype.cos=function(){return this.throwIfDisposed(),_t.cos(this)},t.prototype.tan=function(){return this.throwIfDisposed(),_t.tan(this)},t.prototype.asin=function(){return this.throwIfDisposed(),_t.asin(this)},t.prototype.acos=function(){return this.throwIfDisposed(),_t.acos(this)},t.prototype.atan=function(){return this.throwIfDisposed(),_t.atan(this)},t.prototype.sinh=function(){return this.throwIfDisposed(),_t.sinh(this)},t.prototype.cosh=function(){return this.throwIfDisposed(),_t.cosh(this)},t.prototype.tanh=function(){return this.throwIfDisposed(),_t.tanh(this)},t.prototype.asinh=function(){return this.throwIfDisposed(),_t.asinh(this)},t.prototype.acosh=function(){return this.throwIfDisposed(),_t.acosh(this)},t.prototype.atanh=function(){return this.throwIfDisposed(),_t.atanh(this)},t.prototype.erf=function(){return this.throwIfDisposed(),_t.erf(this)},t.prototype.round=function(){return this.throwIfDisposed(),_t.round(this)},t.prototype.step=function(t){return void 0===t&&(t=0),this.throwIfDisposed(),_t.step(this,t)},t.prototype.softmax=function(t){return void 0===t&&(t=-1),this.throwIfDisposed(),_t.softmax(this,t)},t.prototype.logSoftmax=function(t){return void 0===t&&(t=-1),this.throwIfDisposed(),_t.logSoftmax(this,t)},t.prototype.resizeBilinear=function(t,e){return void 0===e&&(e=!1),this.throwIfDisposed(),_t.image.resizeBilinear(this,t,e)},t.prototype.resizeNearestNeighbor=function(t,e){return void 0===e&&(e=!1),this.throwIfDisposed(),_t.image.resizeNearestNeighbor(this,t,e)},t.prototype.conv1d=function(t,e,n,r,i,a){return void 0===r&&(r="NWC"),void 0===i&&(i=1),this.throwIfDisposed(),_t.conv1d(this,t,e,n,r,i,a)},t.prototype.conv2d=function(t,e,n,r,i,a){return void 0===r&&(r="NHWC"),void 0===i&&(i=[1,1]),this.throwIfDisposed(),_t.conv2d(this,t,e,n,r,i,a)},t.prototype.conv2dTranspose=function(t,e,n,r,i){return this.throwIfDisposed(),_t.conv2dTranspose(this,t,e,n,r,i)},t.prototype.depthwiseConv2D=function(t,e,n,r,i,a){return void 0===r&&(r="NHWC"),void 0===i&&(i=[1,1]),this.throwIfDisposed(),_t.depthwiseConv2d(this,t,e,n,r,i,a)},t.prototype.separableConv2d=function(t,e,n,r,i,a){return void 0===i&&(i=[1,1]),void 0===a&&(a="NHWC"),this.throwIfDisposed(),_t.separableConv2d(this,t,e,n,r,i,a)},t.prototype.avgPool=function(t,e,n,r){return this.throwIfDisposed(),_t.avgPool(this,t,e,n,r)},t.prototype.maxPool=function(t,e,n,r){return this.throwIfDisposed(),_t.maxPool(this,t,e,n,r)},t.prototype.localResponseNormalization=function(t,e,n,r){return void 0===t&&(t=5),void 0===e&&(e=1),void 0===n&&(n=1),void 0===r&&(r=.5),_t.localResponseNormalization(this,t,e,n,r)},t.prototype.pool=function(t,e,n,r,i){return this.throwIfDisposed(),_t.pool(this,t,e,n,r,i)},t.prototype.variable=function(t,e,n){return void 0===t&&(t=!0),this.throwIfDisposed(),kt().makeVariable(this,t,e,n)},t.prototype.unsortedSegmentSum=function(t,e){return this.throwIfDisposed(),_t.unsortedSegmentSum(this,t,e)},t.prototype.batchToSpaceND=function(t,e){return this.throwIfDisposed(),_t.batchToSpaceND(this,t,e)},t.prototype.spaceToBatchND=function(t,e){return this.throwIfDisposed(),_t.spaceToBatchND(this,t,e)},t.prototype.topk=function(t,e){return void 0===t&&(t=1),void 0===e&&(e=!0),this.throwIfDisposed(),_t.topk(this,t,e)},t.prototype.stridedSlice=function(t,e,n,r,i,a,o,s){return void 0===r&&(r=0),void 0===i&&(i=0),void 0===a&&(a=0),void 0===o&&(o=0),void 0===s&&(s=0),this.throwIfDisposed(),_t.stridedSlice(this,t,e,n,r,i,a,o,s)},t.prototype.depthToSpace=function(t,e){return this.throwIfDisposed(),_t.depthToSpace(this,t,e)},t.prototype.fft=function(){return this.throwIfDisposed(),_t.spectral.fft(this)},t.prototype.ifft=function(){return this.throwIfDisposed(),_t.spectral.ifft(this)},t.prototype.rfft=function(){return this.throwIfDisposed(),_t.spectral.rfft(this)},t.prototype.irfft=function(){return this.throwIfDisposed(),_t.spectral.irfft(this)},t}();Object.defineProperty(Ot,Symbol.hasInstance,{value:function(t){return!!t&&null!=t.dataId&&null!=t.shape&&null!=t.dtype}});var St,Ct,At,Nt,Tt,It=function(t){function e(e,n,r,i){var a=t.call(this,e.shape,e.dtype,e.dataId,i)||this;return a.trainable=n,a.name=r,a}return s(e,t),e.prototype.assign=function(t){if(t.dtype!==this.dtype)throw new Error("dtype of the new value ("+t.dtype+") and previous value ("+this.dtype+") must match");if(!D(t.shape,this.shape))throw new Error("shape of the new value ("+t.shape+") and previous value ("+this.shape+") must match");kt().disposeTensor(this),this.dataId=t.dataId,kt().incRef(this,null)},e.prototype.dispose=function(){kt().disposeVariable(this),this.isDisposedInternal=!0},e}(Ot);Object.defineProperty(It,Symbol.hasInstance,{value:function(t){return t instanceof Ot&&null!=t.assign&&t.assign instanceof Function}}),function(t){t.R0="R0",t.R1="R1",t.R2="R2",t.R3="R3",t.R4="R4",t.R5="R5",t.R6="R6"}(St||(St={})),function(t){t.float32="float32",t.int32="int32",t.bool="int32",t.complex64="complex64"}(Ct||(Ct={})),function(t){t.float32="float32",t.int32="int32",t.bool="bool",t.complex64="complex64"}(At||(At={})),function(t){t.float32="float32",t.int32="float32",t.bool="float32",t.complex64="complex64"}(Nt||(Nt={})),function(t){t.float32="complex64",t.int32="complex64",t.bool="complex64",t.complex64="complex64"}(Tt||(Tt={}));var Dt={float32:Nt,int32:Ct,bool:At,complex64:Tt};function Mt(t,e){if("string"===t||"string"===e){if("string"===t&&"string"===e)return"string";throw new Error("Can not upcast "+t+" with "+e)}return Dt[t][e]}function Rt(t){return Mt(t,"int32")}function Ft(t,e){if(t.dtype===e.dtype)return[t,e];var n=Mt(t.dtype,e.dtype);return[t.cast(n),e.cast(n)]}function jt(t,e){C(t.dtype===e.dtype,function(){return"The dtypes of the first("+t.dtype+") and second("+e.dtype+") input must match"})}function Pt(t){var e=[];return function t(e,n,r){if(null!=e)if(e instanceof Ot)n.push(e);else if(i=e,Array.isArray(i)||"object"==typeof i){var i,a=e;for(var o in a){var s=a[o];r.has(s)||(r.add(s),t(s,n,r))}}}(t,e,new Set),e}var Lt,zt=Object.freeze({makeTypesMatch:Ft,assertTypesMatch:jt,isTensorInList:function(t,e){return e.some(function(e){return e.id===t.id})},getTensorsInContainer:Pt}),Bt=function(){function t(){this.registeredVariables={},this.nextTapeNodeId=0,this.numBytes=0,this.numTensors=0,this.numStringTensors=0,this.numDataBuffers=0,this.gradientDepth=0,this.kernelDepth=0,this.scopeStack=[],this.numDataMovesStack=[],this.nextScopeId=0,this.tensorInfo=new WeakMap,this.profiling=!1,this.activeProfile={newBytes:0,newTensors:0,peakBytes:0,kernels:[],result:null}}return t.prototype.dispose=function(){for(var t in this.registeredVariables)this.registeredVariables[t].dispose()},t}(),Ut=function(){function t(t){this.ENV=t,this.registry={},this.registryFactory={},this.pendingBackendInitId=0,this.state=new Bt}return t.prototype.ready=function(){return u(this,void 0,void 0,function(){var t,e,n;return c(this,function(r){switch(r.label){case 0:if(null!=this.pendingBackendInit)return[2,this.pendingBackendInit.then(function(){})];if(null!=this.backendInstance)return[2];t=this.getSortedBackends(),e=0,r.label=1;case 1:return e<t.length?(n=t[e],[4,this.initializeBackend(n).success]):[3,5];case 2:return r.sent()?[4,this.setBackend(n)]:[3,4];case 3:return r.sent(),[2];case 4:return e++,[3,1];case 5:throw new Error("Could not initialize any backends, all backend initializations failed.")}})})},Object.defineProperty(t.prototype,"backend",{get:function(){if(null!=this.pendingBackendInit)throw new Error("Backend '"+this.backendName+"' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods");if(null==this.backendInstance){var t=this.initializeBackendsAndReturnBest(),e=t.name;if(t.asyncInit)throw new Error("The highest priority backend '"+e+"' has not yet been initialized. Make sure to await tf.ready() or await tf.setBackend() before calling other methods");this.setBackend(e)}return this.backendInstance},enumerable:!0,configurable:!0}),t.prototype.backendNames=function(){return Object.keys(this.registryFactory)},t.prototype.findBackend=function(t){if(!(t in this.registry)){if(!(t in this.registryFactory))return null;if(this.initializeBackend(t).asyncInit)return null}return this.registry[t]},t.prototype.findBackendFactory=function(t){return t in this.registryFactory?this.registryFactory[t].factory:null},t.prototype.registerBackend=function(t,e,n){return void 0===n&&(n=1),t in this.registryFactory?(console.warn(t+" backend was already registered. Reusing existing backend factory."),!1):(this.registryFactory[t]={factory:e,priority:n},!0)},t.prototype.setBackend=function(t){return u(this,void 0,void 0,function(){var e,n,r;return c(this,function(i){switch(i.label){case 0:if(null==this.registryFactory[t])throw new Error("Backend name '"+t+"' not found in registry");return this.backendName=t,null!=this.registry[t]?[3,4]:(this.backendInstance=null,e=this.initializeBackend(t),n=e.success,e.asyncInit?[4,n]:[3,2]);case 1:return r=i.sent(),[3,3];case 2:r=n,i.label=3;case 3:if(!r)return[2,!1];i.label=4;case 4:return this.backendInstance=this.registry[t],this.setupRegisteredKernels(),this.profiler=new ht(this.backendInstance),[2,!0]}})})},t.prototype.setupRegisteredKernels=function(){var t=this;v(this.backendName).forEach(function(e){null!=e.setupFunc&&e.setupFunc(t.backendInstance)})},t.prototype.disposeRegisteredKernels=function(t){var e=this;v(t).forEach(function(n){null!=n.disposeFunc&&n.disposeFunc(e.registry[t])})},t.prototype.initializeBackend=function(t){var e=this,n=this.registryFactory[t];if(null==n)throw new Error("Cannot initialize backend "+t+", no registration found.");try{var r=n.factory();if(Promise.resolve(r)===r){var i=++this.pendingBackendInitId,a=r.then(function(n){return!(i<e.pendingBackendInitId||(e.registry[t]=n,e.pendingBackendInit=null,0))}).catch(function(n){return!(i<e.pendingBackendInitId||(e.pendingBackendInit=null,console.warn("Initialization of backend "+t+" failed"),console.warn(n.stack||n.message),1))});return this.pendingBackendInit=a,{success:a,asyncInit:!0}}return this.registry[t]=r,{success:!0,asyncInit:!1}}catch(e){return console.warn("Initialization of backend "+t+" failed"),console.warn(e.stack||e.message),{success:!1,asyncInit:!1}}},t.prototype.removeBackend=function(t){if(!(t in this.registryFactory))throw new Error(t+" backend not found in registry");this.backendName===t&&null!=this.pendingBackendInit&&this.pendingBackendInitId++,t in this.registry&&(this.disposeRegisteredKernels(t),this.registry[t].dispose(),delete this.registry[t]),delete this.registryFactory[t],this.backendName===t&&(this.pendingBackendInit=null,this.backendName=null,this.backendInstance=null)},t.prototype.getSortedBackends=function(){var t=this;if(0===Object.keys(this.registryFactory).length)throw new Error("No backend found in registry.");return Object.keys(this.registryFactory).sort(function(e,n){return t.registryFactory[n].priority-t.registryFactory[e].priority})},t.prototype.initializeBackendsAndReturnBest=function(){for(var t=this.getSortedBackends(),e=0;e<t.length;e++){var n=t[e],r=this.initializeBackend(n),i=r.success,a=r.asyncInit;if(a||i)return{name:n,asyncInit:a}}throw new Error("Could not initialize any backends, all backend initializations failed.")},t.prototype.moveData=function(t,e){var n=this.state.tensorInfo.get(e),r=n.backend,i=this.readSync(e);r.disposeData(e),n.backend=t,t.move(e,i,n.shape,n.dtype),this.shouldCheckForMemLeaks()&&this.state.numDataMovesStack[this.state.numDataMovesStack.length-1]++},t.prototype.tidy=function(t,e){var n,r=this,i=null;if(null==e){if("function"!=typeof t)throw new Error("Please provide a function to tidy()");e=t}else{if("string"!=typeof t&&!(t instanceof String))throw new Error("When calling with two arguments, the first argument to tidy() must be a string");if("function"!=typeof e)throw new Error("When calling with two arguments, the 2nd argument to tidy() must be a function");i=t}return this.scopedRun(function(){return r.startScope(i)},function(){return r.endScope(n)},function(){return(n=e())instanceof Promise&&console.error("Cannot return a Promise inside of tidy."),n})},t.prototype.scopedRun=function(t,e,n){t();try{var r=n();return e(),r}catch(t){throw e(),t}},t.prototype.nextTensorId=function(){return t.nextTensorId++},t.prototype.nextVariableId=function(){return t.nextVariableId++},t.prototype.clone=function(t){var e=this.makeTensorFromDataId(t.dataId,t.shape,t.dtype),n={x:t};return this.addTapeNode(this.state.activeScope.name,n,[e],function(t){return{x:function(){return t.toFloat()}}},[]),e},t.prototype.runKernel=function(t,e,n,r,i){return this.runKernelFunc(null,e,null,t,n,r,i)},t.prototype.shouldCheckForMemLeaks=function(){return this.ENV.getBool("IS_TEST")},t.prototype.checkKernelForMemLeak=function(t,e,n){var r=this.backend.numDataIds(),i=0;n.forEach(function(t){i+="complex64"===t.dtype?3:1});var a=this.state.numDataMovesStack[this.state.numDataMovesStack.length-1],o=r-e-i-a;if(o>0)throw new Error("Backend '"+this.backendName+"' has an internal memory leak ("+o+" data ids) after running '"+t+"'")},t.prototype.runKernelFunc=function(t,e,n,r,i,a,o){var s,u=this;void 0===a&&(a=[]),void 0===o&&(o=[]);var c=[],l=this.isTapeOn();null==r&&(r=null!=this.state.activeScope?this.state.activeScope.name:"");var f,d=function(t){l&&(c=t.map(function(t){return u.keep(u.clone(t))}))},h=this.state.numBytes,p=this.state.numTensors;this.shouldCheckForMemLeaks()&&this.state.numDataMovesStack.push(0);var g,v=m(r,this.backendName);return f=null!=v?function(){var t=u.backend.numDataIds();g=v.kernelFunc({inputs:e,attrs:i,backend:u.backend});var n=Array.isArray(g)?g:[g];u.shouldCheckForMemLeaks()&&u.checkKernelForMemLeak(r,t,n);var s=n.map(function(t){var e=t.dataId,n=t.shape,r=t.dtype;return u.makeTensorFromDataId(e,n,r)}),c=s.filter(function(t,e){return o[e]});return d((a||[]).slice().concat(c)),s}:function(){var e=u.backend.numDataIds();g=u.tidy(function(){return t(u.backend,d)});var n=Array.isArray(g)?g:[g];return u.shouldCheckForMemLeaks()&&u.checkKernelForMemLeak(r,e,n),n},this.scopedRun(function(){return u.state.kernelDepth++},function(){return u.state.kernelDepth--},function(){s=u.ENV.getBool("DEBUG")?u.profiler.profileKernel(r,e,function(){return f()}):f()}),l&&this.addTapeNode(r,e,s,n,c),this.state.profiling&&this.state.activeProfile.kernels.push({name:r,bytesAdded:this.state.numBytes-h,totalBytesSnapshot:this.state.numBytes,tensorsAdded:this.state.numTensors-p,totalTensorsSnapshot:this.state.numTensors,inputShapes:Object.keys(e).map(function(t){return e[t].shape}),outputShapes:s.map(function(t){return t.shape})}),Array.isArray(g)?s:s[0]},t.prototype.makeTensor=function(t,e,n,r){if(null==t)throw new Error("Values passed to engine.makeTensor() are null");n=n||"float32",r=r||this.backend;var i=t;"string"===n&&X(t[0])&&(i=t.map(function(t){return ut(t)}));var a=r.write(i,e,n),o=new Ot(e,n,a,this.nextTensorId());if(this.incRef(o,r),"string"===n){var s=this.state.tensorInfo.get(a),u=K(i);this.state.numBytes+=u-s.bytes,s.bytes=u}return o},t.prototype.makeTensorFromDataId=function(t,e,n,r){var i=new Ot(e,n=n||"float32",t,this.nextTensorId());return this.incRef(i,r),i},t.prototype.makeVariable=function(t,e,n,r){void 0===e&&(e=!0),n=n||this.nextVariableId().toString(),null!=r&&r!==t.dtype&&(t=t.asType(r));var i=new It(t,e,n,this.nextTensorId());if(null!=this.state.registeredVariables[i.name])throw new Error("Variable with name "+i.name+" was already registered");return this.state.registeredVariables[i.name]=i,this.incRef(i,this.backend),i},t.prototype.incRef=function(t,e){var n=this.state.tensorInfo.has(t.dataId)?this.state.tensorInfo.get(t.dataId).refCount:0;if(this.state.numTensors++,"string"===t.dtype&&this.state.numStringTensors++,0===n){this.state.numDataBuffers++;var r=0;"complex64"!==t.dtype&&"string"!==t.dtype&&(r=t.size*$(t.dtype)),this.state.tensorInfo.set(t.dataId,{backend:e||this.backend,dtype:t.dtype,shape:t.shape,bytes:r,refCount:0}),this.state.numBytes+=r}this.state.tensorInfo.get(t.dataId).refCount++,t instanceof It||this.track(t)},t.prototype.disposeTensor=function(t){if(this.state.tensorInfo.has(t.dataId)){this.state.numTensors--,"string"===t.dtype&&this.state.numStringTensors--;var e=this.state.tensorInfo.get(t.dataId);e.refCount<=1?("complex64"!==t.dtype&&(this.state.numBytes-=e.bytes),this.state.numDataBuffers--,e.backend.disposeData(t.dataId),this.state.tensorInfo.delete(t.dataId)):this.state.tensorInfo.get(t.dataId).refCount--}},t.prototype.disposeVariables=function(){for(var t in this.state.registeredVariables){var e=this.state.registeredVariables[t];this.disposeVariable(e)}},t.prototype.disposeVariable=function(t){this.disposeTensor(t),null!=this.state.registeredVariables[t.name]&&delete this.state.registeredVariables[t.name]},t.prototype.memory=function(){var t=this.backend.memory();return t.numTensors=this.state.numTensors,t.numDataBuffers=this.state.numDataBuffers,t.numBytes=this.state.numBytes,this.state.numStringTensors>0&&(t.unreliable=!0,null==t.reasons&&(t.reasons=[]),t.reasons.push("Memory usage by string tensors is approximate (2 bytes per character)")),t},t.prototype.profile=function(t){return u(this,void 0,void 0,function(){var e,n;return c(this,function(r){return this.state.profiling=!0,e=this.state.numBytes,n=this.state.numTensors,this.state.activeProfile.kernels=[],this.state.activeProfile.result=t(),this.state.profiling=!1,this.state.activeProfile.peakBytes=Math.max.apply(Math,this.state.activeProfile.kernels.map(function(t){return t.totalBytesSnapshot})),this.state.activeProfile.newBytes=this.state.numBytes-e,this.state.activeProfile.newTensors=this.state.numTensors-n,[2,this.state.activeProfile]})})},t.prototype.isTapeOn=function(){return this.state.gradientDepth>0&&0===this.state.kernelDepth},t.prototype.addTapeNode=function(t,e,n,r,i){var a=this,o={id:this.state.nextTapeNodeId++,kernelName:t,inputs:e,outputs:n,saved:i},s=g(t);null!=s&&(r=s.gradFunc),null!=r&&(o.gradient=function(t){return t=t.map(function(t,e){if(null==t){var r=n[e],i=at(r.size,r.dtype);return a.makeTensor(i,r.shape,r.dtype)}return t}),r(t.length>1?t:t[0],i)}),this.state.activeTape.push(o)},t.prototype.keep=function(t){return t.kept=!0,t},t.prototype.startTape=function(){0===this.state.gradientDepth&&(this.state.activeTape=[]),this.state.gradientDepth++},t.prototype.endTape=function(){this.state.gradientDepth--},t.prototype.startScope=function(t){var e={track:[],name:"unnamed scope",id:this.state.nextScopeId++};t&&(e.name=t),this.state.scopeStack.push(e),this.state.activeScope=e},t.prototype.endScope=function(t){for(var e=this,n=Pt(t),r=new Set(n.map(function(t){return t.id})),i=0;i<this.state.activeScope.track.length;i++){var a=this.state.activeScope.track[i];a.kept||r.has(a.id)||a.dispose()}var o=this.state.scopeStack.pop();this.state.activeScope=0===this.state.scopeStack.length?null:this.state.scopeStack[this.state.scopeStack.length-1],n.forEach(function(t){t.kept||t.scopeId!==o.id||e.track(t)})},t.prototype.gradients=function(t,e,n,r){var i=this;if(void 0===r&&(r=!1),C(e.length>0,function(){return"gradients() received an empty list of xs."}),null!=n&&"float32"!==n.dtype)throw new Error("dy must have 'float32' dtype, but has '"+n.dtype+"'");var a=this.scopedRun(function(){return i.startTape()},function(){return i.endTape()},function(){return i.tidy("forward",t)});C(a instanceof Ot,function(){return"The result y returned by f() must be a tensor."});var o=function(t,e,n){for(var r={},i={},a=0;a<e.length;a++)r[e[a].id]=!0;for(a=0;a<t.length;a++){var o=(p=t[a]).inputs;for(var s in o){for(var u=o[s],c=!1,l=0;l<e.length;l++)if(r[u.id]){p.outputs.forEach(function(t){return r[t.id]=!0}),c=!0,i[p.id]=!0;break}if(c)break}}var f={};f[n.id]=!0;var d={};for(a=t.length-1;a>=0;a--)for(o=(p=t[a]).inputs,l=0;l<p.outputs.length;l++)if(f[p.outputs[l].id]){for(var s in o)f[o[s].id]=!0,d[p.id]=!0;break}var h=[];for(a=0;a<t.length;a++){var p;if(i[(p=t[a]).id]&&d[p.id]){var m={};for(var s in p.inputs){var g=p.inputs[s];r[g.id]&&(m[s]=g)}var v=Object.assign({},p);v.inputs=m,v.outputs=p.outputs,h.push(v)}}return h}(this.state.activeTape,e,a);if(!r&&0===o.length&&e.length>0)throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that the f you passed encloses all operations that lead from x to y.");return this.tidy("backward",function(){var t,r,s={};s[a.id]=null==n?(r=it(I(t=a.shape),"float32"),Wt.makeTensor(r,t,"float32")):n,function(t,e,n){for(var r=function(r){var i=e[r],a=[];if(i.outputs.forEach(function(e){var n=t[e.id];null!=n?a.push(n):a.push(null)}),null==i.gradient)throw new Error("Cannot compute gradient: gradient function not found for "+i.kernelName+".");var o=i.gradient(a),s=function(e){if(!(e in o))throw new Error("Cannot backprop through input "+e+". Available gradients found: "+Object.keys(o)+".");var r=n(function(){return o[e]()});if("float32"!==r.dtype)throw new Error("Error in gradient for op "+i.kernelName+". The gradient of input "+e+" must have 'float32' dtype, but has '"+r.dtype+"'");var a=i.inputs[e];if(!D(r.shape,a.shape))throw new Error("Error in gradient for op "+i.kernelName+". The gradient of input '"+e+"' has shape '"+r.shape+"', which does not match the shape of the input '"+a.shape+"'");if(null==t[a.id])t[a.id]=r;else{var s=t[a.id];t[a.id]=s.add(r),s.dispose()}};for(var u in i.inputs)s(u)},i=e.length-1;i>=0;i--)r(i)}(s,o,function(t){return i.tidy(t)});var u=e.map(function(t){return s[t.id]});return 0===i.state.gradientDepth&&(i.state.activeTape.forEach(function(t){for(var e=0,n=t.saved;e<n.length;e++)n[e].dispose()}),i.state.activeTape=null),{value:a,grads:u}})},t.prototype.customGrad=function(t){var e=this;return C(Q(t),function(){return"The f passed in customGrad(f) must be a function."}),function(){for(var n,r=[],i=0;i<arguments.length;i++)r[i]=arguments[i];C(r.every(function(t){return t instanceof Ot}),function(){return"The args passed in customGrad(f)(x1, x2,...) must all be tensors"});var a={};return r.forEach(function(t,e){a[e]=t}),e.runKernelFunc(function(e,i){return C((n=t.apply(void 0,r.concat([i]))).value instanceof Ot,function(){return"The function f passed in customGrad(f) must return an object where `obj.value` is a tensor"}),C(Q(n.gradFunc),function(){return"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function."}),n.value},a,function(t,e){var i=n.gradFunc(t,e),a=Array.isArray(i)?i:[i];C(a.length===r.length,function(){return"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns the same number of tensors as inputs passed to f(...)."}),C(a.every(function(t){return t instanceof Ot}),function(){return"The function f passed in customGrad(f) must return an object where `obj.gradFunc` is a function that returns a list of only tensors."});var o={};return a.forEach(function(t,e){o[e]=function(){return t}}),o})}},t.prototype.readSync=function(t){return this.state.tensorInfo.get(t).backend.readSync(t)},t.prototype.read=function(t){return this.state.tensorInfo.get(t).backend.read(t)},t.prototype.time=function(t){return u(this,void 0,void 0,function(){var e,n;return c(this,function(r){switch(r.label){case 0:return e=ot(),[4,this.backend.time(t)];case 1:return(n=r.sent()).wallMs=ot()-e,[2,n]}})})},t.prototype.track=function(t){return null!=this.state.activeScope&&(t.scopeId=this.state.activeScope.id,this.state.activeScope.track.push(t)),t},Object.defineProperty(t.prototype,"registeredVariables",{get:function(){return this.state.registeredVariables},enumerable:!0,configurable:!0}),t.prototype.reset=function(){for(var t in this.pendingBackendInitId++,this.state.dispose(),this.ENV.reset(),this.state=new Bt,this.registry)this.disposeRegisteredKernels(t),this.registry[t].dispose(),delete this.registry[t];this.backendName=null,this.backendInstance=null,this.pendingBackendInit=null},t.nextTensorId=0,t.nextVariableId=0,t}(),Wt=function(){var e=function(){if(null==Lt){var e=void 0;if("undefined"!=typeof window)e=window;else if(void 0!==t)e=t;else if(void 0!==r)e=r;else{if("undefined"==typeof self)throw new Error("Could not find a global object");e=self}Lt=e}return Lt}();if(null==e._tfengine){var n=new l(e);e._tfengine=new Ut(n)}return function(t){d=t}(e._tfengine.ENV),kt=function(){return e._tfengine},e._tfengine}();function Vt(){return"undefined"!=typeof window&&null!=window.document||"undefined"!=typeof WorkerGlobalScope}var qt=f();qt.registerFlag("DEBUG",function(){return!1},function(t){t&&console.warn("Debugging mode is ON. The output of every math call will be downloaded to CPU and checked for NaNs. This significantly impacts performance.")}),qt.registerFlag("IS_BROWSER",function(){return Vt()}),qt.registerFlag("IS_NODE",function(){return void 0!==r&&void 0!==r.versions&&void 0!==r.versions.node}),qt.registerFlag("IS_CHROME",function(){return"undefined"!=typeof navigator&&null!=navigator&&null!=navigator.userAgent&&/Chrome/.test(navigator.userAgent)&&/Google Inc/.test(navigator.vendor)}),qt.registerFlag("PROD",function(){return!1}),qt.registerFlag("TENSORLIKE_CHECK_SHAPE_CONSISTENCY",function(){return qt.getBool("DEBUG")}),qt.registerFlag("DEPRECATION_WARNINGS_ENABLED",function(){return!0}),qt.registerFlag("IS_TEST",function(){return!1});var Ht,Gt,$t,Kt={},Xt={alpha:!1,antialias:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!1,depth:!1,stencil:!1,failIfMajorPerformanceCaveat:!0};function Yt(t,e){Kt[t]=e}function Jt(t){t in Kt||(Kt[t]=function(t){if(1!==t&&2!==t)throw new Error("Cannot get WebGL rendering context, WebGL is disabled.");var e=function(t){if("undefined"!=typeof OffscreenCanvas&&2===t)return new OffscreenCanvas(300,150);if("undefined"!=typeof document)return document.createElement("canvas");throw new Error("Cannot create a canvas in this context")}(t);return e.addEventListener("webglcontextlost",function(e){e.preventDefault(),delete Kt[t]},!1),1===t?e.getContext("webgl",Xt)||e.getContext("experimental-webgl",Xt):e.getContext("webgl2",Xt)}(t));var e=Kt[t];return e.isContextLost()?(delete Kt[t],Jt(t)):(e.disable(e.DEPTH_TEST),e.disable(e.STENCIL_TEST),e.disable(e.BLEND),e.disable(e.DITHER),e.disable(e.POLYGON_OFFSET_FILL),e.disable(e.SAMPLE_COVERAGE),e.enable(e.SCISSOR_TEST),e.enable(e.CULL_FACE),e.cullFace(e.BACK),Kt[t])}function Zt(t,e){return[e,t]}function Qt(t){var e=I(t);return F(Math.ceil(e/4))}function te(t,e){return[Math.max(1,Math.ceil(e/2)),Math.max(1,Math.ceil(t/2))]}function ee(t,e){var n,r,i,a,o,s,u,c,l,d=t;return 2===f().getNumber("WEBGL_VERSION")?(n=d.R32F,r=d.R16F,i=d.RGBA16F,a=d.RGBA32F,o=d.RED,s=4,u=1,c=d.HALF_FLOAT,l=d.FLOAT):(n=t.RGBA,r=t.RGBA,i=t.RGBA,a=d.RGBA,o=t.RGBA,s=4,u=4,c=null!=e?e.HALF_FLOAT_OES:null,l=t.FLOAT),{internalFormatFloat:n,internalFormatHalfFloat:r,internalFormatPackedHalfFloat:i,internalFormatPackedFloat:a,textureFormatFloat:o,downloadTextureFormat:t.RGBA,downloadUnpackNumChannels:s,defaultNumChannels:u,textureTypeHalfFloat:c,textureTypeFloat:l}}function ne(t,e,n){var r=n();return e&&function(t){var e=t.getError();if(e!==t.NO_ERROR)throw new Error("WebGL Error: "+oe(t,e))}(t),r}!function(t){t[t.DENSE=0]="DENSE",t[t.SHARED_BATCH=1]="SHARED_BATCH"}(Ht||(Ht={})),function(t){t[t.RENDER=0]="RENDER",t[t.UPLOAD=1]="UPLOAD",t[t.PIXELS=2]="PIXELS",t[t.DOWNLOAD=3]="DOWNLOAD"}(Gt||(Gt={})),function(t){t[t.UNPACKED_FLOAT16=0]="UNPACKED_FLOAT16",t[t.UNPACKED_FLOAT32=1]="UNPACKED_FLOAT32",t[t.PACKED_4X1_UNSIGNED_BYTE=2]="PACKED_4X1_UNSIGNED_BYTE",t[t.PACKED_2X2_FLOAT32=3]="PACKED_2X2_FLOAT32",t[t.PACKED_2X2_FLOAT16=4]="PACKED_2X2_FLOAT16"}($t||($t={}));var re=5.96e-8,ie=65504;function ae(t){return!!(f().getBool("WEBGL_RENDER_FLOAT32_ENABLED")||0===t||re<Math.abs(t)&&Math.abs(t)<ie)}function oe(t,e){switch(e){case t.NO_ERROR:return"NO_ERROR";case t.INVALID_ENUM:return"INVALID_ENUM";case t.INVALID_VALUE:return"INVALID_VALUE";case t.INVALID_OPERATION:return"INVALID_OPERATION";case t.INVALID_FRAMEBUFFER_OPERATION:return"INVALID_FRAMEBUFFER_OPERATION";case t.OUT_OF_MEMORY:return"OUT_OF_MEMORY";case t.CONTEXT_LOST_WEBGL:return"CONTEXT_LOST_WEBGL";default:return"Unknown error code "+e}}function se(t,e,n){return Te(t,e,function(){return t.getExtension(n)},'Extension "'+n+'" not supported on this browser.')}function ue(t,e,n){var r=Te(t,e,function(){return t.createShader(t.VERTEX_SHADER)},"Unable to create vertex WebGLShader.");if(ne(t,e,function(){return t.shaderSource(r,n)}),ne(t,e,function(){return t.compileShader(r)}),!1===t.getShaderParameter(r,t.COMPILE_STATUS))throw console.log(t.getShaderInfoLog(r)),new Error("Failed to compile vertex shader.");return r}function ce(t,e,n){var r=Te(t,e,function(){return t.createShader(t.FRAGMENT_SHADER)},"Unable to create fragment WebGLShader.");if(ne(t,e,function(){return t.shaderSource(r,n)}),ne(t,e,function(){return t.compileShader(r)}),!1===t.getShaderParameter(r,t.COMPILE_STATUS))throw function(t,e){var n=de.exec(e);if(null==n)return console.log("Couldn't parse line number in error: "+e),void console.log(t);for(var r=+n[1],i=t.split("\n"),a=i.length.toString().length+2,o=i.map(function(t,e){return j((e+1).toString(),a)+t}),s=0,u=0;u<o.length;u++)s=Math.max(o[u].length,s);var c=o.slice(0,r-1),l=o.slice(r-1,r),f=o.slice(r);console.log(c.join("\n")),console.log(e.split("\n")[0]),console.log("%c "+j(l[0],s),"border:1px solid red; background-color:#e3d2d2; color:#a61717"),console.log(f.join("\n"))}(n,t.getShaderInfoLog(r)),new Error("Failed to compile fragment shader.");return r}var le,fe,de=/ERROR: [0-9]+:([0-9]+):/g;function he(t,e){return Te(t,e,function(){return t.createProgram()},"Unable to create WebGLProgram.")}function pe(t,e,n){if(ne(t,e,function(){return t.linkProgram(n)}),!1===t.getProgramParameter(n,t.LINK_STATUS))throw console.log(t.getProgramInfoLog(n)),new Error("Failed to link vertex and fragment shaders.")}function me(t,e,n){if(ne(t,e,function(){return t.validateProgram(n)}),!1===t.getProgramParameter(n,t.VALIDATE_STATUS))throw console.log(t.getProgramInfoLog(n)),new Error("Shader program validation failed.")}function ge(t,e,n){var r=Te(t,e,function(){return t.createBuffer()},"Unable to create WebGLBuffer");return ne(t,e,function(){return t.bindBuffer(t.ARRAY_BUFFER,r)}),ne(t,e,function(){return t.bufferData(t.ARRAY_BUFFER,n,t.STATIC_DRAW)}),r}function ve(t,e,n){var r=Te(t,e,function(){return t.createBuffer()},"Unable to create WebGLBuffer");return ne(t,e,function(){return t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,r)}),ne(t,e,function(){return t.bufferData(t.ELEMENT_ARRAY_BUFFER,n,t.STATIC_DRAW)}),r}function ye(t,e){return Te(t,e,function(){return t.createTexture()},"Unable to create WebGLTexture.")}function be(t,e){var n=f().getNumber("WEBGL_MAX_TEXTURE_SIZE");if(t<=0||e<=0){var r="["+t+"x"+e+"]";throw new Error("Requested texture size "+r+" is invalid.")}if(t>n||e>n)throw r="["+t+"x"+e+"]",new Error("Requested texture size "+r+" greater than WebGL maximum on this browser / GPU ["+n+"x"+n+"].")}function xe(t,e){return Te(t,e,function(){return t.createFramebuffer()},"Unable to create WebGLFramebuffer.")}function we(t,e,n,r,i,a,o,s){var u=t.getAttribLocation(n,r);return-1!==u&&(ne(t,e,function(){return t.bindBuffer(t.ARRAY_BUFFER,i)}),ne(t,e,function(){return t.vertexAttribPointer(u,a,t.FLOAT,!1,o,s)}),ne(t,e,function(){return t.enableVertexAttribArray(u)}),!0)}function ke(t,e,n,r){Ie(t,r),ne(t,e,function(){return t.activeTexture(t.TEXTURE0+r)}),ne(t,e,function(){return t.bindTexture(t.TEXTURE_2D,n)})}function _e(t,e,n,r){return Te(t,e,function(){return t.getUniformLocation(n,r)},'uniform "'+r+'" not present in program.')}function Ee(t,e,n){return t.getUniformLocation(e,n)}function Oe(t,e,n,r,i,a){ne(t,e,function(){return ke(t,e,r,a)}),ne(t,e,function(){return t.uniform1i(i,a)})}function Se(t,e,n,r){ne(t,e,function(){return t.bindFramebuffer(t.FRAMEBUFFER,r)}),ne(t,e,function(){return t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,n,0)})}function Ce(t,e,n){ne(t,e,function(){return t.bindFramebuffer(t.FRAMEBUFFER,n)}),ne(t,e,function(){return t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,null,0)})}function Ae(t){var e=t.checkFramebufferStatus(t.FRAMEBUFFER);if(e!==t.FRAMEBUFFER_COMPLETE)throw new Error("Error binding framebuffer: "+Ne(t,e))}function Ne(t,e){switch(e){case t.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_ATTACHMENT";case t.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:return"FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT";case t.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:return"FRAMEBUFFER_INCOMPLETE_DIMENSIONS";case t.FRAMEBUFFER_UNSUPPORTED:return"FRAMEBUFFER_UNSUPPORTED";default:return"unknown error "+e}}function Te(t,e,n,r){var i=ne(t,e,function(){return n()});if(null==i)throw new Error(r);return i}function Ie(t,e){var n=t.MAX_COMBINED_TEXTURE_IMAGE_UNITS-1,r=e+t.TEXTURE0;if(r<t.TEXTURE0||r>n)throw new Error("textureUnit must be in [gl.TEXTURE0, gl.TEXTURE"+n+"].")}function De(t,e){return void 0===e&&(e=2),I(t.slice(0,t.length-e))}function Me(t){if(0===t.length)throw Error("Cannot get rows and columns of an empty shape array.");return[t.length>1?t[t.length-2]:1,t[t.length-1]]}function Re(t){var e=[1,1,1];return 0===t.length||1===t.length&&1===t[0]||(e=[De(t)].concat(Me(t))),e}function Fe(t,e){var n;void 0===e&&(e=!1);var r=f().getNumber("WEBGL_MAX_TEXTURE_SIZE");if(e&&(r*=2,1===(t=t.map(function(e,n){return n>=t.length-2?O(t[n]):t[n]})).length&&(t=[2,t[0]])),2!==t.length){var i=B(t);t=i.newShape}var a=I(t);if(t.length<=1&&a<=r)return[1,a];if(2===t.length&&t[0]<=r&&t[1]<=r)return t;if(3===t.length&&t[0]*t[1]<=r&&t[2]<=r)return[t[0]*t[1],t[2]];if(3===t.length&&t[0]<=r&&t[1]*t[2]<=r)return[t[0],t[1]*t[2]];if(4===t.length&&t[0]*t[1]*t[2]<=r&&t[3]<=r)return[t[0]*t[1]*t[2],t[3]];if(4===t.length&&t[0]<=r&&t[1]*t[2]*t[3]<=r)return[t[0],t[1]*t[2]*t[3]];if(e){var o=De(t),s=2,u=2;return t.length&&(s=(n=Me(t))[0],u=n[1]),F(a=o*(s/2)*(u/2)).map(function(t){return 2*t})}return F(a)}function je(t){return t%2==0}function Pe(t,e){if(D(t=t.slice(-2),e=e.slice(-2)))return!0;if(!t.length||!e.length)return!0;if(0===t[0]||0===t[1]||0===e[0]||0===e[1])return!0;if(t.length!==e.length){var n=t.slice(-1)[0],r=e.slice(-1)[0];if(n===r)return!0;if(je(n)&&je(r)&&(1===t[0]||1===e[0]))return!0}return t[1]===e[1]&&je(t[0])&&je(e[0])}function Le(t){if(null==le){var e=Jt(t);le=e.getParameter(e.MAX_TEXTURE_SIZE)}return le}function ze(t){if(null==fe){var e=Jt(t);fe=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS)}return Math.min(16,fe)}function Be(t){if(0===t)return 0;var e=Jt(t);return Ue(e,"EXT_disjoint_timer_query_webgl2")&&2===t?2:Ue(e,"EXT_disjoint_timer_query")?1:0}function Ue(t,e){return null!=t.getExtension(e)}function We(t){try{if(null!=Jt(t))return!0}catch(t){return!1}return!1}function Ve(t){if(0===t)return!1;var e=Jt(t);if(1===t){if(!Ue(e,"OES_texture_float"))return!1}else if(!Ue(e,"EXT_color_buffer_float"))return!1;return He(e)}function qe(t){if(0===t)return!1;var e=Jt(t);return 1!==t?Ue(e,"EXT_color_buffer_float")?He(e):!!Ue(e,"EXT_color_buffer_half_float")&&function(t,e){var n=ee(t,e),r=t.createTexture();t.bindTexture(t.TEXTURE_2D,r),t.texImage2D(t.TEXTURE_2D,0,n.internalFormatHalfFloat,1,1,0,n.textureFormatFloat,n.textureTypeHalfFloat,null);var i=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,i),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,r,0);var a=t.checkFramebufferStatus(t.FRAMEBUFFER)===t.FRAMEBUFFER_COMPLETE;return t.bindTexture(t.TEXTURE_2D,null),t.bindFramebuffer(t.FRAMEBUFFER,null),t.deleteTexture(r),t.deleteFramebuffer(i),a}(e,e.getExtension("EXT_color_buffer_half_float")):!!Ue(e,"OES_texture_float")&&!!Ue(e,"WEBGL_color_buffer_float")&&He(e)}function He(t){var e=ee(t),n=t.createTexture();t.bindTexture(t.TEXTURE_2D,n),t.texImage2D(t.TEXTURE_2D,0,e.internalFormatFloat,1,1,0,e.textureFormatFloat,e.textureTypeFloat,null);var r=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,r),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,n,0);var i=t.checkFramebufferStatus(t.FRAMEBUFFER)===t.FRAMEBUFFER_COMPLETE;return t.bindTexture(t.TEXTURE_2D,null),t.bindFramebuffer(t.FRAMEBUFFER,null),t.deleteTexture(n),t.deleteFramebuffer(r),i}function Ge(t){return 2===t&&null!=Jt(t).fenceSync}var $e=Object.freeze({callAndCheck:ne,canBeRepresented:ae,getWebGLErrorMessage:oe,getExtensionOrThrow:se,createVertexShader:ue,createFragmentShader:ce,createProgram:he,linkProgram:pe,validateProgram:me,createStaticVertexBuffer:ge,createStaticIndexBuffer:ve,getNumChannels:function(){return 2===f().getNumber("WEBGL_VERSION")?1:4},createTexture:ye,validateTextureSize:be,createFramebuffer:xe,bindVertexBufferToProgramAttribute:we,bindTextureUnit:ke,unbindTextureUnit:function(t,e,n){Ie(t,n),ne(t,e,function(){return t.activeTexture(t.TEXTURE0+n)}),ne(t,e,function(){return t.bindTexture(t.TEXTURE_2D,null)})},getProgramUniformLocationOrThrow:_e,getProgramUniformLocation:Ee,bindTextureToProgramUniformSampler:Oe,bindCanvasToFramebuffer:function(t,e){ne(t,e,function(){return t.bindFramebuffer(t.FRAMEBUFFER,null)}),ne(t,e,function(){return t.viewport(0,0,t.canvas.width,t.canvas.height)}),ne(t,e,function(){return t.scissor(0,0,t.canvas.width,t.canvas.height)})},bindColorTextureToFramebuffer:Se,unbindColorTextureFromFramebuffer:Ce,validateFramebuffer:Ae,getFramebufferErrorMessage:Ne,getBatchDim:De,getRowsCols:Me,getShapeAs3D:Re,getTextureShapeFromLogicalShape:Fe,isReshapeFree:Pe,getWebGLMaxTextureSize:Le,resetMaxTextureSize:function(){le=null},resetMaxTexturesInShader:function(){fe=null},getMaxTexturesInShader:ze,getWebGLDisjointQueryTimerVersion:Be,hasExtension:Ue,isWebGLVersionEnabled:We,isCapableOfRenderingToFloatTexture:Ve,isDownloadFloatTextureEnabled:qe,isWebGLFenceEnabled:Ge}),Ke=f();function Xe(){f().set("PROD",!0)}function Ye(){f().set("DEBUG",!0)}function Je(){f().set("DEPRECATION_WARNINGS_ENABLED",!1),console.warn("TensorFlow.js deprecation warnings have been disabled.")}function Ze(t){f().getBool("DEPRECATION_WARNINGS_ENABLED")&&console.warn(t+" You can disable deprecation warnings with tf.disableDeprecationWarnings().")}function Qe(){Wt.disposeVariables()}function tn(){return Wt}function en(){return Wt.memory()}function nn(t){return Wt.profile(t)}function rn(t,e){return Wt.tidy(t,e)}function an(t){Pt(t).forEach(function(t){return t.dispose()})}function on(t){return Wt.keep(t)}function sn(t){return Wt.time(t)}function un(t){return Wt.setBackend(t)}function cn(){return Wt.ready()}function ln(){return Wt.backendName}function fn(t){Wt.removeBackend(t)}function dn(t){return Wt.findBackend(t)}function hn(t){return Wt.findBackendFactory(t)}function pn(t,e,n){return void 0===n&&(n=1),Wt.registerBackend(t,e,n)}function mn(){return Wt.backend}function gn(t,e){f().setPlatform(t,e)}function vn(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];f().getBool("IS_TEST")||console.warn.apply(console,t)}function yn(t,e){var n=t;if(G(t))return"string"===e?[]:[t.length];if(!Array.isArray(t))return[];for(var r=[];Array.isArray(n)||G(n)&&"string"!==e;)r.push(n.length),n=n[0];return Array.isArray(t)&&f().getBool("TENSORLIKE_CHECK_SHAPE_CONSISTENCY")&&function t(e,n,r){if(r=r||[],Array.isArray(e)||G(e)){C(n.length>0,function(){return"Element arr["+r.join("][")+"] should be a primitive, but is an array of "+e.length+" elements"}),C(e.length===n[0],function(){return"Element arr["+r.join("][")+"] should have "+n[0]+" elements, but has "+e.length+" elements"});for(var i=n.slice(1),a=0;a<e.length;++a)t(e[a],i,r.concat(a))}else C(0===n.length,function(){return"Element arr["+r.join("][")+"] is a primitive, but should be an array/TypedArray of "+n[0]+" elements"})}(t,r,[]),r}function bn(t,e,n,r){if(null!=t&&("numeric"!==t&&t!==e||"numeric"===t&&"string"===e))throw new Error("Argument '"+n+"' passed to '"+r+"' must be "+t+" tensor, but got "+e+" tensor")}function xn(t,e,n,r){if(void 0===r&&(r="numeric"),t instanceof Ot)return bn(r,t.dtype,e,n),t;var i=Z(t);if("string"!==i&&["bool","int32","float32"].indexOf(r)>=0&&(i=r),bn(r,i,e,n),null==t||!G(t)&&!Array.isArray(t)&&"number"!=typeof t&&"boolean"!=typeof t&&"string"!=typeof t){var a=null==t?"null":t.constructor.name;throw new Error("Argument '"+e+"' passed to '"+n+"' must be a Tensor or TensorLike, but got '"+a+"'")}var o=yn(t,i);G(t)||Array.isArray(t)||(t=[t]);var s="string"!==i?nt(t,i,f().getBool("DEBUG")):T(t,[],!0);return Wt.makeTensor(s,o,i)}function wn(t,e,n,r){if(void 0===r&&(r="numeric"),!Array.isArray(t))throw new Error("Argument "+e+" passed to "+n+" must be a `Tensor[]` or `TensorLike[]`");return t.map(function(t,r){return xn(t,e+"["+r+"]",n)},r)}function kn(t,e){for(var n=0;n<t.length;++n)if(t[t.length-n-1]!==e-1-n)return!1;return!0}function _n(t,e,n){for(var r=t.length+e.length,i=[],a=0,o=0,s=0;s<r;s++)-1===n.indexOf(s)?i.push(t[a++]):i.push(e[o++]);return i}function En(t,e){for(var n=[],r=t.length,i=0;i<r;i++)-1===e.indexOf(i)&&n.push(t[i]);return[n,e.map(function(e){return t[e]})]}function On(t,e){return _n(t,e.map(function(t){return 1}),e)}function Sn(t,e,n){C(kn(e,n),function(){return t+" supports only inner-most axes for now. Got axes "+e+" and rank-"+n+" input."})}function Cn(t,e){if(kn(t,e))return null;for(var n=[],r=0;r<e;++r)-1===t.indexOf(r)&&n.push(r);return t.forEach(function(t){return n.push(t)}),n}function An(t){return t.map(function(t,e){return[e,t]}).sort(function(t,e){return t[1]-e[1]}).map(function(t){return t[0]})}function Nn(t,e){for(var n=[],r=e-t;r<e;++r)n.push(r);return n}function Tn(t,e){var n=t[0].length;t.forEach(function(t,e){C(t.length===n,function(){return"Error in concat"+n+"D: rank of tensors["+e+"] must be the same as the rank of the rest ("+n+")"})}),C(e>=0&&e<n,function(){return"Error in concat"+n+"D: axis must be between 0 and "+(n-1)+"."});var r=t[0];t.forEach(function(t,i){for(var a=0;a<n;a++)C(a===e||t[a]===r[a],function(){return"Error in concat"+n+"D: Shape of tensors["+i+"] ("+t+") does not match the shape of the rest ("+r+") along the non-concatenated axis "+i+"."})})}function In(t,e){for(var n=t[0].slice(),r=1;r<t.length;r++)n[e]+=t[r][e];return n}function Dn(t){var e=Object.keys(t);if(1!==e.length)throw new Error("Please provide an object with a single key (operation name) mapping to a function. Got an object with "+e.length+" keys.");var n=e[0],r=t[n];n.endsWith("_")&&(n=n.substring(0,n.length-1));var i=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];Wt.startScope(n);try{var i=r.apply(void 0,t);return i instanceof Promise&&console.error("Cannot return a Promise inside of tidy."),Wt.endScope(i),i}catch(t){throw Wt.endScope(null),t}};return Object.defineProperty(i,"name",{value:n,configurable:!0}),i}Ke.registerFlag("HAS_WEBGL",function(){return Ke.getNumber("WEBGL_VERSION")>0}),Ke.registerFlag("WEBGL_VERSION",function(){return We(2)?2:We(1)?1:0}),Ke.registerFlag("WEBGL_BUFFER_SUPPORTED",function(){return 2===Ke.get("WEBGL_VERSION")}),Ke.registerFlag("WEBGL_CPU_FORWARD",function(){return!0}),Ke.registerFlag("WEBGL_FORCE_F16_TEXTURES",function(){return!1}),Ke.registerFlag("WEBGL_PACK",function(){return Ke.getBool("HAS_WEBGL")}),Ke.registerFlag("WEBGL_PACK_NORMALIZATION",function(){return Ke.getBool("WEBGL_PACK")}),Ke.registerFlag("WEBGL_PACK_CLIP",function(){return Ke.getBool("WEBGL_PACK")}),Ke.registerFlag("WEBGL_PACK_DEPTHWISECONV",function(){return!1}),Ke.registerFlag("WEBGL_PACK_BINARY_OPERATIONS",function(){return Ke.getBool("WEBGL_PACK")}),Ke.registerFlag("WEBGL_PACK_UNARY_OPERATIONS",function(){return Ke.getBool("WEBGL_PACK")}),Ke.registerFlag("WEBGL_PACK_ARRAY_OPERATIONS",function(){return Ke.getBool("WEBGL_PACK")}),Ke.registerFlag("WEBGL_PACK_IMAGE_OPERATIONS",function(){return Ke.getBool("WEBGL_PACK")}),Ke.registerFlag("WEBGL_PACK_REDUCE",function(){return Ke.getBool("WEBGL_PACK")}),Ke.registerFlag("WEBGL_LAZILY_UNPACK",function(){return Ke.getBool("WEBGL_PACK")}),Ke.registerFlag("WEBGL_CONV_IM2COL",function(){return Ke.getBool("WEBGL_PACK")}),Ke.registerFlag("WEBGL_MAX_TEXTURE_SIZE",function(){return Le(Ke.getNumber("WEBGL_VERSION"))}),Ke.registerFlag("WEBGL_MAX_TEXTURES_IN_SHADER",function(){return ze(Ke.getNumber("WEBGL_VERSION"))}),Ke.registerFlag("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION",function(){var t=Ke.getNumber("WEBGL_VERSION");return 0===t?0:Be(t)}),Ke.registerFlag("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE",function(){return Ke.getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")>0&&(t=navigator.userAgent||navigator.vendor||window.opera,!(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(t)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(t.substr(0,4))));var t}),Ke.registerFlag("WEBGL_RENDER_FLOAT32_CAPABLE",function(){return Ve(Ke.getNumber("WEBGL_VERSION"))}),Ke.registerFlag("WEBGL_RENDER_FLOAT32_ENABLED",function(){return!Ke.getBool("WEBGL_FORCE_F16_TEXTURES")&&Ke.getBool("WEBGL_RENDER_FLOAT32_CAPABLE")}),Ke.registerFlag("WEBGL_DOWNLOAD_FLOAT_ENABLED",function(){return qe(Ke.getNumber("WEBGL_VERSION"))}),Ke.registerFlag("WEBGL_FENCE_API_ENABLED",function(){return Ge(Ke.getNumber("WEBGL_VERSION"))}),Ke.registerFlag("WEBGL_SIZE_UPLOAD_UNIFORM",function(){return Ke.getBool("WEBGL_RENDER_FLOAT32_ENABLED")?4:0}),Et=Ze;var Mn=Dn({complex_:function(t,e){var n=xn(t,"real","complex"),r=xn(e,"imag","complex");return A(n.shape,r.shape,"real and imag shapes, "+n.shape+" and "+r.shape+", must match in call to tf.complex()."),Wt.runKernelFunc(function(t){return t.complex(n,r)},{$real:n,$imag:r})}}),Rn=Dn({real_:function(t){var e=xn(t,"input","real");return Wt.runKernelFunc(function(t){return t.real(e)},{$input:e})}}),Fn=Dn({imag_:function(t){var e=xn(t,"input","imag");return Wt.runKernelFunc(function(t){return t.imag(e)},{$input:e})}});function jn(t,e,n){return Pn(t,e,yn(t,n),n)}function Pn(t,e,n,r){if(null==r&&(r=Z(t)),"complex64"===r)throw new Error("Cannot construct a complex64 tensor directly. Please use tf.complex(real, imag).");if(!G(t)&&!Array.isArray(t)&&"number"!=typeof t&&"boolean"!=typeof t&&"string"!=typeof t)throw new Error("values passed to tensor(values) must be a number/boolean/string or an array of numbers/booleans/strings, or a TypedArray");if(null!=e){st(e);var i=I(e),a=I(n);C(i===a,function(){return"Based on the provided shape, ["+e+"], the tensor should have "+i+" values but has "+a});for(var o=0;o<n.length;++o){var s=n[o],u=o!==n.length-1||s!==I(e.slice(o));C(n[o]===e[o]||!u,function(){return"Error creating a new Tensor. Inferred shape ("+n+") does not match the provided shape ("+e+"). "})}}return G(t)||Array.isArray(t)||(t=[t]),e=e||n,t="string"!==r?nt(t,r,f().getBool("DEBUG")):T(t,[],!0),Wt.makeTensor(t,e,r)}function Ln(t,e){if((G(t)&&"string"!==e||Array.isArray(t))&&"complex64"!==e)throw new Error("Error creating a new Scalar: value must be a primitive (number|boolean|string)");if("string"===e&&G(t)&&!(t instanceof Uint8Array))throw new Error("When making a scalar from encoded string, the value must be `Uint8Array`.");return Pn(t,[],[],e)}function zn(t,e){N(t);var n=yn(t,e);if(1!==n.length)throw new Error("tensor1d() requires values to be a flat/TypedArray");return Pn(t,null,n,e)}function Bn(t,e,n){if(N(t),null!=e&&2!==e.length)throw new Error("tensor2d() requires shape to have two numbers");var r=yn(t,n);if(2!==r.length&&1!==r.length)throw new Error("tensor2d() requires values to be number[][] or flat/TypedArray");if(1===r.length&&null==e)throw new Error("tensor2d() requires shape to be provided when `values` are a flat/TypedArray");return Pn(t,e,r,n)}function Un(t,e,n){if(N(t),null!=e&&3!==e.length)throw new Error("tensor3d() requires shape to have three numbers");var r=yn(t,n);if(3!==r.length&&1!==r.length)throw new Error("tensor3d() requires values to be number[][][] or flat/TypedArray");if(1===r.length&&null==e)throw new Error("tensor3d() requires shape to be provided when `values` are a flat array");return Pn(t,e,r,n)}function Wn(t,e,n){if(N(t),null!=e&&4!==e.length)throw new Error("tensor4d() requires shape to have four numbers");var r=yn(t,n);if(4!==r.length&&1!==r.length)throw new Error("tensor4d() requires values to be number[][][][] or flat/TypedArray");if(1===r.length&&null==e)throw new Error("tensor4d() requires shape to be provided when `values` are a flat array");return Pn(t,e,r,n)}function Vn(t,e,n){if(N(t),null!=e&&5!==e.length)throw new Error("tensor5d() requires shape to have five numbers");var r=yn(t,n);if(5!==r.length&&1!==r.length)throw new Error("tensor5d() requires values to be number[][][][][] or flat/TypedArray");if(1===r.length&&null==e)throw new Error("tensor5d() requires shape to be provided when `values` are a flat array");return Pn(t,e,r,n)}function qn(t,e,n){if(N(t),null!=e&&6!==e.length)throw new Error("tensor6d() requires shape to have six numbers");var r=yn(t,n);if(6!==r.length&&1!==r.length)throw new Error("tensor6d() requires values to be number[][][][][][] or flat/TypedArray");if(1===r.length&&null==e)throw new Error("tensor6d() requires shape to be provided when `values` are a flat array");return Pn(t,e=e||r,r,n)}function Hn(t,e,n,r){return void 0===e&&(e=!0),Wt.makeVariable(t,e,n,r)}function Gn(t,e){if(void 0===e&&(e="float32"),"complex64"===e){var n=Gn(t,"float32"),r=$n(t,"float32");return Mn(n,r)}var i=it(I(t),e);return Wt.makeTensor(i,t,e)}function $n(t,e){if(void 0===e&&(e="float32"),"complex64"===e){var n=$n(t,"float32"),r=$n(t,"float32");return Mn(n,r)}var i=at(I(t),e);return Wt.makeTensor(i,t,e)}function Kn(t,e,n){return Wt.runKernelFunc(function(r){return r.fill(t,e,n)},{})}function Xn(t,e,n){if(n<=0)throw new Error("The number of values should be positive.");return Wt.runKernelFunc(function(r){return r.linspace(t,e,n)},{})}function Yn(t,e,n,r){if(void 0===n&&(n=1),void 0===r&&(r="float32"),0===n)throw new Error("Cannot have a step of zero");if(t===e||t<e&&n<0||e<t&&n>1)return $n([0],r);var i=at(Math.abs(Math.ceil((e-t)/n)),r);e<t&&1===n&&(n=-1),i[0]=t;for(var a=1;a<i.length;a++)i[a]=i[a-1]+n;return zn(i,r)}var Jn=Dn({onesLike_:function(t){var e=xn(t,"x","onesLike");if("complex64"===e.dtype){var n=Jn(Rn(e)),r=Zn(Fn(e));return Mn(n,r)}return Wt.runKernelFunc(function(t){return t.onesLike(e)},{$x:e},function(t,e){return{$x:function(){return Zn(t)}}})}}),Zn=Dn({zerosLike_:function(t){var e=xn(t,"x","zerosLike");return Wt.runKernelFunc(function(t){return t.zerosLike(e)},{$x:e},function(t,e){return{$x:function(){return Zn(t)}}})}}),Qn=Dn({concat_:function(t,e){void 0===e&&(e=0),C(t.length>=1,function(){return"Pass at least one tensor to concat"});var n=wn(t,"tensors","concat");"complex64"===n[0].dtype&&n.forEach(function(t){if("complex64"!==t.dtype)throw new Error("Cannot concatenate complex64 tensors with a tensor\n with dtype "+t.dtype+". ")}),e=z(e,n[0].shape)[0];var r=In(n.map(function(t){return t.shape}),e);if(0===I(r))return jn([],r);if(1===(n=n.filter(function(t){return t.size>0})).length)return n[0];var i=n.map(function(t){return t.shape});Tn(i,e);var a=n,o={axis:e};return Wt.runKernelFunc(function(t){return t.concat(n,e)},a,function(t){var n=i.map(function(t){return t[e]});return ir(t,n,e).map(function(t){return function(){return t}})},"Concat",o)}}),tr=Dn({concat1d_:function(t){return Qn(t,0)}}),er=Dn({concat2d_:function(t,e){return Qn(t,e)}}),nr=Dn({concat3d_:function(t,e){return Qn(t,e)}}),rr=Dn({concat4d_:function(t,e){return Qn(t,e)}}),ir=Dn({split_:function(t,e,n){void 0===n&&(n=0);var r,i=xn(t,"x","split");return n=z(n,i.shape)[0],"number"==typeof e?(C(i.shape[n]%e==0,function(){return"Number of splits must evenly divide the axis."}),r=new Array(e).fill(i.shape[n]/e)):(C(i.shape[n]===e.reduce(function(t,e){return t+e}),function(){return"The sum of sizes must match the size of the axis dimension."}),r=e),Wt.runKernelFunc(function(t){return t.split(i,r,n)},{$x:i},function(t){return{$x:function(){return Qn(t,n)}}})}});function ar(t,e){return t(e={exports:{}},e.exports),e.exports}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:void 0!==t||"undefined"!=typeof self&&self;var or=ar(function(t){!function(t,e,n){function r(t,e){return e.c=t.c,e.s0=t.s0,e.s1=t.s1,e.s2=t.s2,e}function i(t,e){var n=new function(t){var e,n=this,r=(e=4022871197,function(t){t=t.toString();for(var n=0;n<t.length;n++){var r=.02519603282416938*(e+=t.charCodeAt(n));r-=e=r>>>0,e=(r*=e)>>>0,e+=4294967296*(r-=e)}return 2.3283064365386963e-10*(e>>>0)});n.next=function(){var t=2091639*n.s0+2.3283064365386963e-10*n.c;return n.s0=n.s1,n.s1=n.s2,n.s2=t-(n.c=0|t)},n.c=1,n.s0=r(" "),n.s1=r(" "),n.s2=r(" "),n.s0-=r(t),n.s0<0&&(n.s0+=1),n.s1-=r(t),n.s1<0&&(n.s1+=1),n.s2-=r(t),n.s2<0&&(n.s2+=1),r=null}(t),i=e&&e.state,a=n.next;return a.int32=function(){return 4294967296*n.next()|0},a.double=function(){return a()+1.1102230246251565e-16*(2097152*a()|0)},a.quick=a,i&&("object"==typeof i&&r(i,n),a.state=function(){return r(n,{})}),a}e&&e.exports?e.exports=i:this.alea=i}(0,t)}),sr=ar(function(t){!function(t,e,n){function r(t,e){return e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w,e}function i(t,e){var n=new function(t){var e=this,n="";e.x=0,e.y=0,e.z=0,e.w=0,e.next=function(){var t=e.x^e.x<<11;return e.x=e.y,e.y=e.z,e.z=e.w,e.w^=e.w>>>19^t^t>>>8},t===(0|t)?e.x=t:n+=t;for(var r=0;r<n.length+64;r++)e.x^=0|n.charCodeAt(r),e.next()}(t),i=e&&e.state,a=function(){return(n.next()>>>0)/4294967296};return a.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},a.int32=n.next,a.quick=a,i&&("object"==typeof i&&r(i,n),a.state=function(){return r(n,{})}),a}e&&e.exports?e.exports=i:this.xor128=i}(0,t)}),ur=ar(function(t){!function(t,e,n){function r(t,e){return e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w,e.v=t.v,e.d=t.d,e}function i(t,e){var n=new function(t){var e=this,n="";e.next=function(){var t=e.x^e.x>>>2;return e.x=e.y,e.y=e.z,e.z=e.w,e.w=e.v,(e.d=e.d+362437|0)+(e.v=e.v^e.v<<4^t^t<<1)|0},e.x=0,e.y=0,e.z=0,e.w=0,e.v=0,t===(0|t)?e.x=t:n+=t;for(var r=0;r<n.length+64;r++)e.x^=0|n.charCodeAt(r),r==n.length&&(e.d=e.x<<10^e.x>>>4),e.next()}(t),i=e&&e.state,a=function(){return(n.next()>>>0)/4294967296};return a.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},a.int32=n.next,a.quick=a,i&&("object"==typeof i&&r(i,n),a.state=function(){return r(n,{})}),a}e&&e.exports?e.exports=i:this.xorwow=i}(0,t)}),cr=ar(function(t){!function(t,e,n){function r(t,e){return e.x=t.x.slice(),e.i=t.i,e}function i(t,e){null==t&&(t=+new Date);var n=new function(t){var e=this;e.next=function(){var t,n,r=e.x,i=e.i;return t=r[i],n=(t^=t>>>7)^t<<24,n^=(t=r[i+1&7])^t>>>10,n^=(t=r[i+3&7])^t>>>3,n^=(t=r[i+4&7])^t<<7,t=r[i+7&7],n^=(t^=t<<13)^t<<9,r[i]=n,e.i=i+1&7,n},function(t,e){var n,r=[];if(e===(0|e))r[0]=e;else for(e=""+e,n=0;n<e.length;++n)r[7&n]=r[7&n]<<15^e.charCodeAt(n)+r[n+1&7]<<13;for(;r.length<8;)r.push(0);for(n=0;n<8&&0===r[n];++n);for(8==n?r[7]=-1:r[n],t.x=r,t.i=0,n=256;n>0;--n)t.next()}(e,t)}(t),i=e&&e.state,a=function(){return(n.next()>>>0)/4294967296};return a.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},a.int32=n.next,a.quick=a,i&&(i.x&&r(i,n),a.state=function(){return r(n,{})}),a}e&&e.exports?e.exports=i:this.xorshift7=i}(0,t)}),lr=ar(function(t){!function(t,e,n){function r(t,e){return e.i=t.i,e.w=t.w,e.X=t.X.slice(),e}function i(t,e){null==t&&(t=+new Date);var n=new function(t){var e=this;e.next=function(){var t,n,r=e.w,i=e.X,a=e.i;return e.w=r=r+1640531527|0,n=i[a+34&127],t=i[a=a+1&127],n^=n<<13,t^=t<<17,n^=n>>>15,t^=t>>>12,n=i[a]=n^t,e.i=a,n+(r^r>>>16)|0},function(t,e){var n,r,i,a,o,s=[],u=128;for(e===(0|e)?(r=e,e=null):(e+="\0",r=0,u=Math.max(u,e.length)),i=0,a=-32;a<u;++a)e&&(r^=e.charCodeAt((a+32)%e.length)),0===a&&(o=r),r^=r<<10,r^=r>>>15,r^=r<<4,r^=r>>>13,a>=0&&(o=o+1640531527|0,i=0==(n=s[127&a]^=r+o)?i+1:0);for(i>=128&&(s[127&(e&&e.length||0)]=-1),i=127,a=512;a>0;--a)r=s[i+34&127],n=s[i=i+1&127],r^=r<<13,n^=n<<17,r^=r>>>15,n^=n>>>12,s[i]=r^n;t.w=o,t.X=s,t.i=i}(e,t)}(t),i=e&&e.state,a=function(){return(n.next()>>>0)/4294967296};return a.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},a.int32=n.next,a.quick=a,i&&(i.X&&r(i,n),a.state=function(){return r(n,{})}),a}e&&e.exports?e.exports=i:this.xor4096=i}(0,t)}),fr=ar(function(t){!function(t,e,n){function r(t,e){return e.a=t.a,e.b=t.b,e.c=t.c,e.d=t.d,e}function i(t,e){var n=new function(t){var e=this,n="";e.next=function(){var t=e.b,n=e.c,r=e.d,i=e.a;return t=t<<25^t>>>7^n,n=n-r|0,r=r<<24^r>>>8^i,i=i-t|0,e.b=t=t<<20^t>>>12^n,e.c=n=n-r|0,e.d=r<<16^n>>>16^i,e.a=i-t|0},e.a=0,e.b=0,e.c=-1640531527,e.d=1367130551,t===Math.floor(t)?(e.a=t/4294967296|0,e.b=0|t):n+=t;for(var r=0;r<n.length+20;r++)e.b^=0|n.charCodeAt(r),e.next()}(t),i=e&&e.state,a=function(){return(n.next()>>>0)/4294967296};return a.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},a.int32=n.next,a.quick=a,i&&("object"==typeof i&&r(i,n),a.state=function(){return r(n,{})}),a}e&&e.exports?e.exports=i:this.tychei=i}(0,t)}),dr=ar(function(t){!function(e,r){var i,a=this,o=256,s=6,u="random",c=r.pow(o,s),l=r.pow(2,52),f=2*l,d=o-1;function h(t,n,d){var h=[],y=g(function t(e,n){var r,i=[],a=typeof e;if(n&&"object"==a)for(r in e)try{i.push(t(e[r],n-1))}catch(t){}return i.length?i:"string"==a?e:e+"\0"}((n=1==n?{entropy:!0}:n||{}).entropy?[t,v(e)]:null==t?function(){try{var t;return i&&(t=i.randomBytes)?t=t(o):(t=new Uint8Array(o),(a.crypto||a.msCrypto).getRandomValues(t)),v(t)}catch(t){var n=a.navigator,r=n&&n.plugins;return[+new Date,a,r,a.screen,v(e)]}}():t,3),h),b=new p(h),x=function(){for(var t=b.g(s),e=c,n=0;t<l;)t=(t+n)*o,e*=o,n=b.g(1);for(;t>=f;)t/=2,e/=2,n>>>=1;return(t+n)/e};return x.int32=function(){return 0|b.g(4)},x.quick=function(){return b.g(4)/4294967296},x.double=x,g(v(b.S),e),(n.pass||d||function(t,e,n,i){return i&&(i.S&&m(i,b),t.state=function(){return m(b,{})}),n?(r[u]=t,e):t})(x,y,"global"in n?n.global:this==r,n.state)}function p(t){var e,n=t.length,r=this,i=0,a=r.i=r.j=0,s=r.S=[];for(n||(t=[n++]);i<o;)s[i]=i++;for(i=0;i<o;i++)s[i]=s[a=d&a+t[i%n]+(e=s[i])],s[a]=e;(r.g=function(t){for(var e,n=0,i=r.i,a=r.j,s=r.S;t--;)e=s[i=d&i+1],n=n*o+s[d&(s[i]=s[a=d&a+e])+(s[a]=e)];return r.i=i,r.j=a,n})(o)}function m(t,e){return e.i=t.i,e.j=t.j,e.S=t.S.slice(),e}function g(t,e){for(var n,r=t+"",i=0;i<r.length;)e[d&i]=d&(n^=19*e[d&i])+r.charCodeAt(i++);return v(e)}function v(t){return String.fromCharCode.apply(0,t)}if(r["seed"+u]=h,g(r.random(),e),t.exports){t.exports=h;try{i=n(303)}catch(t){}}}([],Math)});dr.alea=or,dr.xor128=sr,dr.xorwow=ur,dr.xorshift7=cr,dr.xor4096=lr,dr.tychei=fr;var hr=dr.alea,pr=function(){function t(t,e,n,r,i){this.mean=t,this.stdDev=e,this.dtype=n,this.nextVal=NaN,this.truncated=r,this.truncated&&(this.upper=this.mean+2*this.stdDev,this.lower=this.mean-2*this.stdDev);var a=i||Math.random();this.random=hr(a.toString())}return t.prototype.nextValue=function(){if(!isNaN(this.nextVal)){var t=this.nextVal;return this.nextVal=NaN,t}for(var e,n,r=!1;!r;){var i=void 0,a=void 0,o=void 0;do{o=(i=2*this.random()-1)*i+(a=2*this.random()-1)*a}while(o>=1||0===o);var s=Math.sqrt(-2*Math.log(o)/o);e=this.mean+this.stdDev*i*s,n=this.mean+this.stdDev*a*s,this.truncated&&!this.isValidTruncated(e)||(r=!0)}return this.truncated&&!this.isValidTruncated(n)||(this.nextVal=this.convertValue(n)),this.convertValue(e)},t.prototype.convertValue=function(t){return null==this.dtype||"float32"===this.dtype?t:Math.round(t)},t.prototype.isValidTruncated=function(t){return t<=this.upper&&t>=this.lower},t}(),mr=function(){function t(t,e,n,r){this.alpha=t,this.beta=1/e,this.dtype=n;var i=r||Math.random();this.randu=hr(i.toString()),this.randn=new pr(0,1,n,!1,this.randu()),this.d=t<1?t+2/3:t-1/3,this.c=1/Math.sqrt(9*this.d)}return t.prototype.nextValue=function(){for(var t,e,n,r,i,a;;){do{r=this.randn.nextValue(),a=1+this.c*r}while(a<=0);if(a*=a*a,e=1-.331*(t=r*r)*t,n=.5*t+this.d*(1-a+Math.log(a)),(i=this.randu())<e||Math.log(i)<n)break}return a=1/this.beta*this.d*a,this.alpha<1&&(a*=Math.pow(this.randu(),1/this.alpha)),this.convertValue(a)},t.prototype.convertValue=function(t){return"float32"===this.dtype?t:Math.round(t)},t}(),gr=function(){function t(t,e,n,r){var i=this;if(void 0===t&&(t=0),void 0===e&&(e=1),this.canReturnFloat=function(){return null==i.dtype||"float32"===i.dtype},this.min=t,this.range=e-t,this.dtype=n,null==r&&(r=Math.random()),"number"==typeof r&&(r=r.toString()),!this.canReturnFloat()&&this.range<=1)throw new Error("The difference between "+t+" - "+e+" <= 1 and dtype is not float");this.random=hr(r)}return t.prototype.convertValue=function(t){return this.canReturnFloat()?t:Math.round(t)},t.prototype.nextValue=function(){return this.convertValue(this.min+this.range*this.random())},t}();function vr(t,e,n){return void 0===e&&(e="float32"),e=e||"float32",st(t),new wt(t,e,n)}function yr(t,e){void 0===e&&(e=!1),console.log(t.toString(e))}var br=Dn({batchToSpaceND_:function(t,e,n){var r=xn(t,"x","batchToSpaceND"),i=e.reduce(function(t,e){return t*e});return C(r.rank>=1+e.length,function(){return"input rank is "+r.rank+" but should be > than blockShape.length "+e.length}),C(n.length===e.length,function(){return"crops.length is "+n.length+" but should be equal to blockShape.length "+e.length}),C(r.shape[0]%i==0,function(){return"input tensor batch is "+r.shape[0]+" but is not divisible by the product of the elements of blockShape "+e.join(" * ")+" === "+i}),Wt.runKernelFunc(function(t){return t.batchToSpaceND(r,e,n)},{$x:r},function(t){return{$x:function(){return t.spaceToBatchND(e,n)}}})}}),xr=Dn({broadcastTo_:function(t,e){var n=xn(t,"broadcastTo","x"),r=n.shape;if(e.some(function(t){return!(t>0)||t%1!=0}))throw new Error("broadcastTo(): Invalid broadcast shape ["+e+"].");if(e.length<n.rank)throw new Error("broadcastTo(): shape.length="+e.length+" < input.rank="+n.rank+".");if(e.length>n.rank){for(var i=n.shape.slice();i.length<e.length;)i.unshift(1);n=n.reshape(i)}for(var a=Array.from(e),o=e.length-1;o>=0;o--)if(n.shape[o]===e[o])a[o]=1;else if(1!==n.shape[o])throw new Error("broadcastTo(): ["+r+"] cannot be broadcast to ["+e+"].");var s=a.map(function(t,e){return t>1?e:-1}).filter(function(t){return t>=0});return 0===s.length?n.clone():Wt.runKernelFunc(function(t){return t.tile(n,a)},{input:n},function(t){return{input:function(){return t.sum(s,!0)}}})}}),wr=Dn({cast_:function(t,e){var n=xn(t,"x","cast");if(!q(e))throw new Error("Failed to cast to unknown dtype "+e);if("string"===e&&"string"!==n.dtype||"string"!==e&&"string"===n.dtype)throw new Error("Only strings can be casted to strings");var r={dtype:e};return Wt.runKernelFunc(function(t){return t.cast(n,e)},{x:n},function(t){return{x:function(){return t.clone()}}},"Cast",r)}}),kr=Dn({clone_:function(t){var e=xn(t,"x","clone",null);return Wt.runKernelFunc(function(){return Wt.makeTensorFromDataId(e.dataId,e.shape,e.dtype)},{$x:e},function(t){return{$x:function(){return t.toFloat()}}})}}),_r=Dn({cumsum_:function(t,e,n,r){void 0===e&&(e=0),void 0===n&&(n=!1),void 0===r&&(r=!1);var i=xn(t,"x","cumsum"),a=Cn([e|=0],i.rank),o=i;null!=a&&(o=i.transpose(a));var s=Nn(1,i.rank)[0],u=Wt.runKernelFunc(function(t){return t.cumsum(o,s,n,r)},{permutedX:o},function(t){return{permutedX:function(){return t.cumsum(e,n,!r)}}});return null!=a&&(u=u.transpose(a)),u}}),Er=Dn({depthToSpace_:function(t,e,n){void 0===n&&(n="NHWC");var r=xn(t,"x","depthToSpace"),i="NHWC"===n?r.shape[1]:r.shape[2],a="NHWC"===n?r.shape[2]:r.shape[3],o="NHWC"===n?r.shape[3]:r.shape[1];return C(i*e>=0,function(){return"Negative dimension size caused by overflow when multiplying\n "+i+" and "+e+" for depthToSpace with input shape\n "+r.shape}),C(a*e>=0,function(){return"Negative dimension size caused by overflow when multiplying\n "+a+" and "+e+" for depthToSpace with input shape\n "+r.shape}),C(o%(e*e)==0,function(){return"Dimension size must be evenly divisible by "+e*e+" but is "+o+" for depthToSpace with input shape "+r.shape}),Wt.runKernelFunc(function(t){return t.depthToSpace(r,e,n)},{$x:r})}}),Or=Dn({expandDims_:function(t,e){void 0===e&&(e=0);var n=xn(t,"x","expandDims",null);C(e<=n.rank,function(){return"Axis must be <= rank of the tensor"});var r=n.shape.slice();return e<0&&(C(-(n.rank+1)<=e,function(){return"Axis must be in the interval ["+-(n.rank+1)+", "+n.rank+"]"}),e=n.rank+e+1),r.splice(e,0,1),Lr(n,r)}}),Sr=Dn({eye_:function(t,e,n,r){void 0===r&&(r="float32"),null==e&&(e=t);for(var i=vr([t,e],r),a=t<=e?t:e,o=0;o<a;++o)i.set(1,o,o);var s=i.toTensor().as2D(t,e);if(null==n)return s;if(1===n.length)return Wr(Or(s,0),[n[0],1,1]);if(2===n.length)return Wr(Or(Or(s,0),0),[n[0],n[1],1,1]);if(3===n.length)return Wr(Or(Or(Or(s,0),0),0),[n[0],n[1],n[2],1,1]);throw new Error("eye() currently supports only 1D and 2D batchShapes, but received "+n.length+"D.")}}),Cr=Dn({multinomial_:function(t,e,n,r){void 0===r&&(r=!1);var i=xn(t,"logits","multinomial"),a=i.size,o=i.rank;if(a<2)throw new Error("Error in multinomial: you need at least 2 outcomes, but got "+a+".");if(o>2)throw new Error("Rank of probabilities must be 1 or 2, but is "+o);n=n||Math.random();var s=1===o?i.as2D(1,-1):i,u=Wt.runKernelFunc(function(t){return t.multinomial(s,r,e,n)},{logits2D:s});return 1===o?u.as1D():u}}),Ar=Dn({oneHot_:function(t,e,n,r){if(void 0===n&&(n=1),void 0===r&&(r=0),e<2)throw new Error("Error in oneHot: depth must be >=2, but it is "+e);var i=xn(t,"indices","oneHot","int32"),a=i.shape.concat([e]);return i=i.flatten(),Wt.runKernelFunc(function(t){return t.oneHot(i,e,n,r)},{$indices:i},function(t){return{$indices:function(){return $n(i.shape,"float32")}}}).reshape(a)}}),Nr=Dn({pad_:function(t,e,n){void 0===n&&(n=0);var r=xn(t,"x","pad");if(0===r.rank)throw new Error("pad(scalar) is not defined. Pass non-scalar to pad");var i={paddings:e,constantValue:n};return Wt.runKernelFunc(function(t){return t.pad(r,e,n)},{x:r},function(t){var n=e.map(function(t){return t[0]});return{x:function(){return t.slice(n,r.shape)}}},"PadV2",i)}}),Tr=Dn({pad1d_:function(t,e,n){return void 0===n&&(n=0),C(2===e.length,function(){return"Invalid number of paddings. Must be length of 2."}),Nr(t,[e],n)}}),Ir=Dn({pad2d_:function(t,e,n){return void 0===n&&(n=0),C(2===e.length&&2===e[0].length&&2===e[1].length,function(){return"Invalid number of paddings. Must be length of 2 each."}),Nr(t,e,n)}}),Dr=Dn({pad3d_:function(t,e,n){return void 0===n&&(n=0),C(3===e.length&&2===e[0].length&&2===e[1].length&&2===e[2].length,function(){return"Invalid number of paddings. Must be length of 2 each."}),Nr(t,e,n)}}),Mr=Dn({pad4d_:function(t,e,n){return void 0===n&&(n=0),C(4===e.length&&2===e[0].length&&2===e[1].length&&2===e[2].length&&2===e[3].length,function(){return"Invalid number of paddings. Must be length of 2 each."}),Nr(t,e,n)}}),Rr=Dn({rand_:function(t,e,n){var r=I(t),i=null;if(null==n||"float32"===n)i=new Float32Array(r);else if("int32"===n)i=new Int32Array(r);else{if("bool"!==n)throw new Error("Unknown data type "+n);i=new Uint8Array(r)}for(var a=0;a<r;a++)i[a]=e();return Wt.makeTensor(i,t,n)}}),Fr=Dn({randomNormal_:function(t,e,n,r,i){if(void 0===e&&(e=0),void 0===n&&(n=1),null!=r&&"bool"===r)throw new Error("Unsupported data type "+r);for(var a=new pr(e,n,r,!1,i),o=vr(t,r),s=0;s<o.values.length;s++)o.values[s]=a.nextValue();return o.toTensor()}}),jr=Dn({randomGamma_:function(t,e,n,r,i){if(void 0===n&&(n=1),void 0===r&&(r="float32"),null==n&&(n=1),null==r&&(r="float32"),"float32"!==r&&"int32"!==r)throw new Error("Unsupported data type "+r);for(var a=new mr(e,n,r,i),o=vr(t,r),s=0;s<o.values.length;s++)o.values[s]=a.nextValue();return o.toTensor()}}),Pr=Dn({randomUniform_:function(t,e,n,r,i){void 0===e&&(e=0),void 0===n&&(n=1),void 0===r&&(r="float32");for(var a=vr(t,r),o=new gr(e,n,null,i),s=0;s<a.values.length;s++)a.values[s]=o.nextValue();return a.toTensor()}}),Lr=Dn({reshape_:function(t,e){var n=xn(t,"x","reshape",null);e=L(e,n.size),C(n.size===I(e),function(){return"new shape and old shape must have the same number of elements."});var r={shape:e};return Wt.runKernelFunc(function(t){return t.reshape(n,e)},{x:n},function(t){return{x:function(){return t.reshape(n.shape)}}},"Reshape",r)}}),zr=Dn({spaceToBatchND_:function(t,e,n){var r=xn(t,"x","spaceToBatchND");return C(r.rank>=1+e.length,function(){return"input rank "+r.rank+" should be > than [blockShape] "+e.length}),C(n.length===e.length,function(){return"paddings.shape[0] "+n.length+" must be equal to [blockShape] "+e.length}),C(r.shape.reduce(function(t,r,i){return i>0&&i<=e.length?t&&(r+n[i-1][0]+n[i-1][1])%e[i-1]==0:t},!0),function(){return"input spatial dimensions "+r.shape.slice(1)+" with paddings "+n.toString()+" must be divisible by blockShapes "+e.toString()}),Wt.runKernelFunc(function(t){return t.spaceToBatchND(r,e,n)},{$x:r},function(t){return{$x:function(){return t.batchToSpaceND(e,n)}}})}}),Br=Dn({squeeze_:function(t,e){var n=xn(t,"x","squeeze");return Lr(n,B(n.shape,e).newShape)}}),Ur=Dn({stack_:function(t,e){void 0===e&&(e=0);var n=wn(t,"tensors","stack");if(C(n.length>=1,function(){return"Pass at least one tensor to tf.stack"}),1===n.length)return n[0].expandDims(e);var r=n[0].rank,i=n[0].shape,a=n[0].dtype;C(e<=r,function(){return"Axis must be <= rank of the tensor"}),n.forEach(function(t){A(i,t.shape,"All tensors passed to stack must have matching shapes")}),n.forEach(function(t){C(a===t.dtype,function(){return"All tensors passed to stack must have matching dtypes"})});var o=n.map(function(t){return t.expandDims(e)});return Qn(o,e)}}),Wr=Dn({tile_:function(t,e){var n=xn(t,"x","tile",null);C(n.rank===e.length,function(){return"Error in transpose: rank of input "+n.rank+" must match length of reps "+e+"."});var r=[n],i={reps:e};return Wt.runKernelFunc(function(t,r){var i=t.tile(n,e);return r([n]),i},{x:n},function(t,n){var r=n[0];return{x:function(){var n=Zn(r);if(1===r.rank)for(var i=0;i<e[0];++i)n=n.add(t.slice([i*r.shape[0]],[r.shape[0]]));else if(2===r.rank)for(i=0;i<e[0];++i)for(var a=0;a<e[1];++a)n=n.add(t.slice([i*r.shape[0],a*r.shape[1]],[r.shape[0],r.shape[1]]));else if(3===r.rank)for(i=0;i<e[0];++i)for(a=0;a<e[1];++a)for(var o=0;o<e[2];++o)n=n.add(t.slice([i*r.shape[0],a*r.shape[1],o*r.shape[2]],[r.shape[0],r.shape[1],r.shape[2]]));else{if(4!==r.rank)throw new Error("Gradient for tile operation is not implemented for rank-"+r.rank+" tensors yet.");for(i=0;i<e[0];++i)for(a=0;a<e[1];++a)for(o=0;o<e[2];++o)for(var s=0;s<e[3];++s)n=n.add(t.slice([i*r.shape[0],a*r.shape[1],o*r.shape[2],s*r.shape[3]],[r.shape[0],r.shape[1],r.shape[2],r.shape[3]]))}return n}}},"Tile",i,r)}}),Vr=Dn({truncatedNormal_:function(t,e,n,r,i){if(void 0===e&&(e=0),void 0===n&&(n=1),null!=r&&"bool"===r)throw new Error("Unsupported data type "+r);for(var a=new pr(e,n,r,!0,i),o=vr(t,r),s=0;s<o.values.length;s++)o.values[s]=a.nextValue();return o.toTensor()}}),qr=Dn({unstack_:function(t,e){void 0===e&&(e=0),e=e||0;var n=xn(t,"x","unstack");C(e>=-n.shape.length&&e<n.shape.length,function(){return"Axis = "+e+" is not in [-"+n.shape.length+", "+n.shape.length+")"}),e<0&&(e+=n.shape.length);var r={axis:e};return Wt.runKernelFunc(function(t){return t.unstack(n,e)},{x:n},function(t){return{x:function(){return Ur(t,e)}}},"Unpack",r)}}),Hr=function(t,e){return u(this,void 0,void 0,function(){var n,r,i,a,o,s,u,l,f,d;return c(this,function(c){switch(c.label){case 0:return n=xn(t,"x","setdiff1d"),r=xn(e,"y","setdiff1d"),C(n.dtype===r.dtype,function(){return"x and y should have the same dtype, but got x ("+n.dtype+") and y ("+r.dtype+")."}),C(1===n.rank,function(){return"x should be 1D tensor, but got x ("+n.shape+")."}),C(1===r.rank,function(){return"y should be 1D tensor, but got y ("+r.shape+")."}),[4,n.data()];case 1:return i=c.sent(),[4,r.data()];case 2:for(a=c.sent(),o=new Set(a),s=0,f=0;f<i.length;f++)o.has(i[f])||s++;for(u=new wt([s],n.dtype),l=new wt([s],"int32"),f=0,d=0;f<i.length;f++)o.has(i[f])||(u.values[d]=i[f],l.values[d]=f,d++);return[2,[u.toTensor(),l.toTensor()]]}})})};function Gr(t,e,n,r){void 0===r&&(r=!0);var i=[];if(r)(i=i.concat(e.slice(0))).push(t[0]/n),i=i.concat(t.slice(1));else{i=i.concat(t[0]);for(var a=e.length,o=0;o<a;++o)i=i.concat([t[o+1]/e[o],e[o]]);i=i.concat(t.slice(a+1))}return i}function $r(t,e,n){void 0===n&&(n=!0);var r=[];if(n){r.push(e);for(var i=e+1;i<t;++i)i<=2*e?(r.push(i),r.push(i-(e+1))):r.push(i)}else{var a=[],o=[];for(i=1;i<t;++i)i>=2*e+1||i%2==1?o.push(i):a.push(i);r.push.apply(r,a),r.push(0),r.push.apply(r,o)}return r}function Kr(t,e,n,r){void 0===r&&(r=!0);var i=[];r?i.push(t[0]/n):i.push(t[0]*n);for(var a=1;a<t.length;++a)a<=e.length?r?i.push(e[a-1]*t[a]):i.push(t[a]/e[a-1]):i.push(t[a]);return i}function Xr(t,e){for(var n=[0],r=0;r<e;++r)n.push(t[r][0]);return n}function Yr(t,e,n){for(var r=t.slice(0,1),i=0;i<n;++i)r.push(t[i+1]-e[i][0]-e[i][1]);return r}function Jr(t,e){if(t.rank<1)throw new Error("tf.gatherND() expects the input to be rank 1 or higher, but the rank was "+t.rank+".");if(e.rank<1)throw new Error("tf.gatherND() expects the indices to be rank 1 or higher, but the rank was "+e.rank+".");if("int32"!==e.dtype)throw new Error("tf.gatherND() expects the indices to be int32 type, but the dtype was "+e.dtype+".");if(e.shape[e.rank-1]>t.rank)throw new Error("index innermost dimension length must be <= tensor rank; saw: "+e.shape[e.rank-1]+" vs. "+t.rank);if(0===t.size)throw new Error("Requested more than 0 entries, but input is empty. Input shape: "+t.shape+".");for(var n=e.shape,r=n[n.length-1],i=1,a=0;a<n.length-1;++a)i*=n[a];var o=t.shape,s=n.slice();s.pop();var u=1;for(a=r;a<t.rank;++a)u*=o[a],s.push(o[a]);var c=et(t.shape).map(function(t){return t/u}).concat([1]).slice(0,r);return[s,i,u,c]}var Zr=Object.freeze({prepareAndValidate:Jr}),Qr=30;function ti(t){return t<=Qr?t:tt(t,Math.floor(Math.sqrt(t)))}function ei(t,e,n){var r=e.rank>1?e.shape[e.rank-1]:1,i=e.rank>1?e.rank-1:1,a="Must have updates.shape = indices.shape[:batchDim] + shape[sliceDim:], got updates.shape: "+n.shape+", indices.shape: "+e.shape+", shape: "+t+", sliceDim: "+r+", and batchDim: "+i+".";if(n.rank<i)throw new Error(a+" update.rank < "+i+". ");if(t.length<r+(n.rank-i))throw new Error(a+" Output shape length < "+(r+(n.rank-i)));if(n.rank!==i+t.length-r)throw new Error(a+" update.rank != "+(i+t.length-r));for(var o=0;o<i;++o)if(n.shape[o]!==e.shape[o])throw new Error(a+" updates.shape["+o+"] ("+n.shape[o]+") != indices.shape["+o+"] ("+e.shape[o]+").");for(o=0;o<n.rank-i;++o)if(n.shape[o+i]!==t[o+r])throw new Error(a+" updates.shape["+(o+i)+"] ("+n.shape[o+i]+") != shape["+(o+i)+"] ("+t[o+i]+")")}function ni(t,e,n){if(e.rank<1)throw new Error("tf.scatterND() expects the indices to be rank 1 or higher, but the rank was "+e.rank+".");if(t.rank<1)throw new Error("tf.scatterND() expects the updates to be rank 1 or higher, but the rank was "+t.rank+".");if("int32"!==e.dtype)throw new Error("The dtype of 'indices' should be int32, but got dtype: "+e.dtype);if(n.length<1)throw new Error("Output rank must be greater or equal to 1, but got shape: "+n);if(0===n.length){if(0===e.size)throw new Error("Indices specified for empty output. indices shape: "+e.shape);if(0===t.size)throw new Error("Updates specified for empty output. updates shape: "+t.shape)}ei(n,e,t)}function ri(t,e,n){for(var r=e.shape.length,i=r>1?e.shape[r-1]:1,a=n.length,o=1,s=i;s<a;++s)o*=n[s];var u=i<1?1:i;return{sliceRank:i,numUpdates:I(e.shape)/u,sliceSize:o,strides:et(n.slice(0,i)).concat([1]),outputSize:I(n)}}var ii=Object.freeze({validateUpdateShape:ei,validateInput:ni,calculateShapes:ri});function ai(t,e,n){C(t.rank===e.length,function(){return"Error in slice"+t.rank+"D: Length of begin "+e+" must match the rank of the array ("+t.rank+")."}),C(t.rank===n.length,function(){return"Error in slice"+t.rank+"D: Length of size "+n+" must match the rank of the array ("+t.rank+")."});for(var r=function(r){C(e[r]+n[r]<=t.shape[r],function(){return"Error in slice"+t.rank+"D: begin["+r+"] + size["+r+"] ("+(e[r]+n[r])+") would overflow input.shape["+r+"] ("+t.shape[r]+")"})},i=0;i<t.rank;++i)r(i)}function oi(t){for(var e=[],n=0;t>0;)1&t&&e.push(n),t/=2,n++;return e}function si(t,e,n){for(var r=[],i=0;i<t.length;i++)r[i]=Math.ceil((e[i]-t[i])/n[i]);return r}function ui(t,e,n,r,i){var a=e[i],o=n[i]||1;(t&1<<i||null==a)&&(a=o>0?Number.MIN_SAFE_INTEGER:Number.MAX_SAFE_INTEGER);var s=r[i];return a<0&&(a+=s),E(0,a,s-1)}function ci(t,e,n,r,i){var a=e[i],o=n[i]||1;(t&1<<i||null==a)&&(a=o>0?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER);var s=r[i];return a<0&&(a+=s),o>0?E(0,a,s):E(-1,a,s-1)}function li(t,e,n){for(var r=n.length,i=0;i<n.length;i++)if(n[i]>1){r=i;break}for(i=r+1;i<n.length;i++)if(e[i]>0||n[i]!==t[i])return!1;return!0}function fi(t,e){for(var n=t.length>0?t[t.length-1]:1,r=0;r<t.length-1;r++)n+=t[r]*e[r];return n}var di=Object.freeze({assertParamsValid:ai,maskToAxes:oi,computeOutShape:si,startForAxis:ui,stopForAxis:ci,isSliceContinous:li,computeFlatOffset:fi});function hi(t){return C(Q(t),function(){return"The f passed in grad(f) must be a function"}),function(e,n){var r=xn(e,"x","tf.grad",null),i=null!=n?xn(n,"dy","tf.grad"):null;return Wt.tidy(function(){var e=Wt.gradients(function(){return t(r)},[r],i),n=e.value,a=e.grads;return null!=i&&A(n.shape,i.shape,"The shape of dy passed in grad(f)(x, dy) must match the shape returned by f(x)"),bi(a),a[0]})}}function pi(t){return C(Q(t),function(){return"The f passed in grads(f) must be a function"}),function(e,n){C(Array.isArray(e),function(){return"The args passed in grads(f)(args) must be an array of `Tensor`s or `TensorLike`s"});var r=wn(e,"args","tf.grads",null),i=null!=n?xn(n,"dy","tf.grads"):null;return Wt.tidy(function(){var e=Wt.gradients(function(){return t.apply(void 0,r)},r,i),n=e.value,a=e.grads;return null!=i&&A(n.shape,i.shape,"The shape of dy passed in grads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),bi(a),a})}}function mi(t){return C(Q(t),function(){return"The f passed in valueAndGrad(f) must be a function"}),function(e,n){C(e instanceof Ot,function(){return"The x passed in valueAndGrad(f)(x) must be a tensor"}),C(null==n||n instanceof Ot,function(){return"The dy passed in valueAndGrad(f)(x, dy) must be a tensor"});var r=Wt.gradients(function(){return t(e)},[e],n),i=r.grads,a=r.value;return bi(i),{grad:i[0],value:a}}}function gi(t){return C(Q(t),function(){return"The f passed in valueAndGrads(f) must be a function"}),function(e,n){C(Array.isArray(e)&&e.every(function(t){return t instanceof Ot}),function(){return"The args passed in valueAndGrads(f)(args) must be array of tensors"}),C(null==n||n instanceof Ot,function(){return"The dy passed in valueAndGrads(f)(args, dy) must be a tensor"});var r=Wt.gradients(function(){return t.apply(void 0,e)},e,n);return null!=n&&A(r.value.shape,n.shape,"The shape of dy passed in valueAndGrads(f)([x1,...], dy) must match the shape returned by f([x1,...])"),bi(r.grads),r}}function vi(t,e){C(Q(t),function(){return"The f passed in variableGrads(f) must be a function"}),C(null==e||Array.isArray(e)&&e.every(function(t){return t instanceof It}),function(){return"The varList passed in variableGrads(f, varList) must be an array of variables"});var n=null!=e;if(!n)for(var r in e=[],Wt.registeredVariables)e.push(Wt.registeredVariables[r]);var i=n?e.filter(function(t){return!t.trainable}):null,a=e.length;C((e=e.filter(function(t){return t.trainable})).length>0,function(){return"variableGrads() expects at least one of the input variables to be trainable, but none of the "+a+" variables is trainable."});var o=Wt.gradients(t,e,null,!0),s=o.value,u=o.grads;C(u.some(function(t){return null!=t}),function(){return"Cannot find a connection between any variable and the result of the loss function y=f(x). Please make sure the operations that use variables are inside the function f passed to minimize()."}),C(0===s.rank,function(){return"The f passed in variableGrads(f) must return a scalar, but it returned a rank-"+s.rank+" tensor"});var c={};return e.forEach(function(t,e){null!=u[e]&&(c[t.name]=u[e])}),null!=i&&i.forEach(function(t){return c[t.name]=null}),{value:s,grads:c}}function yi(t){return Wt.customGrad(t)}function bi(t){if(t.filter(function(t){return null==t}).length>0)throw new Error("Cannot compute gradient of y=f(x) with respect to x. Make sure that\n the f you passed encloses all operations that lead from x to y.")}var xi=Dn({softmax_:function(t,e){void 0===e&&(e=-1);var n=xn(t,"logits","softmax","float32");if(-1===e&&(e=n.rank-1),e!==n.rank-1)throw Error("Softmax along a non-last dimension is not yet supported. Logits was rank "+n.rank+" and dim was "+e);return Wt.runKernelFunc(function(t,r){var i=t.softmax(n,e);return r([i]),i},{logits:n},function(t,n){var r=n[0],i=t.mul(r);return{logits:function(){return i.sub(i.sum([e],!0).mul(r))}}},"Softmax",{dim:e},[],[!0])}}),wi=Dn({logSoftmax_:function(t,e){void 0===e&&(e=-1);var n=xn(t,"logits","logSoftmax");if(-1===e&&(e=n.rank-1),e!==n.rank-1)throw Error("Log Softmax along a non-last dimension is not yet supported. Logits was rank "+n.rank+" and axis was "+e);return yi(function(t,n){var r=t.max(e,!0),i=t.sub(r),a=i.toFloat().sub(i.exp().sum(e,!0).log());return n([a]),{value:a,gradFunc:function(t,n){var r=n[0].exp();return t.sub(t.sum(e,!0).mul(r))}}})(n)}}),ki=function(){function t(t,e){this.backend=t,this.dataMover=e,this.data=new WeakMap,this.dataIdsCount=0}return t.prototype.get=function(t){return this.data.has(t)||this.dataMover.moveData(this.backend,t),this.data.get(t)},t.prototype.set=function(t,e){this.dataIdsCount++,this.data.set(t,e)},t.prototype.has=function(t){return this.data.has(t)},t.prototype.delete=function(t){return this.dataIdsCount--,this.data.delete(t)},t.prototype.numDataIds=function(){return this.dataIdsCount},t}(),_i=function(){function t(){}return t.prototype.time=function(t){return Ei("time")},t.prototype.read=function(t){return Ei("read")},t.prototype.readSync=function(t){return Ei("readSync")},t.prototype.numDataIds=function(){return Ei("numDataIds")},t.prototype.disposeData=function(t){return Ei("disposeData")},t.prototype.write=function(t,e,n){return Ei("write")},t.prototype.move=function(t,e,n,r){return Ei("move")},t.prototype.memory=function(){return Ei("memory")},t.prototype.floatPrecision=function(){return Ei("floatPrecision")},t.prototype.epsilon=function(){return 32===this.floatPrecision()?1e-7:1e-4},t.prototype.batchMatMul=function(t,e,n,r){return Ei("batchMatMul")},t.prototype.fusedBatchMatMul=function(t){return t.a,t.b,t.transposeA,t.transposeB,t.bias,t.activation,t.preluActivationWeights,Ei("fusedBatchMatMul")},t.prototype.slice=function(t,e,n){return Ei("slice")},t.prototype.stridedSlice=function(t,e,n,r){return Ei("stridedSlice")},t.prototype.unstack=function(t,e){return Ei("unstack")},t.prototype.reverse=function(t,e){return Ei("reverse")},t.prototype.concat=function(t,e){return Ei("concat")},t.prototype.neg=function(t){return Ei("neg")},t.prototype.add=function(t,e){return Ei("add")},t.prototype.addN=function(t){return Ei("addN")},t.prototype.subtract=function(t,e){return Ei("subtract")},t.prototype.multiply=function(t,e){return Ei("multiply")},t.prototype.realDivide=function(t,e){return Ei("realDivide")},t.prototype.floorDiv=function(t,e){return Ei("floorDiv")},t.prototype.sum=function(t,e){return Ei("sum")},t.prototype.prod=function(t,e){return Ei("prod")},t.prototype.unsortedSegmentSum=function(t,e,n){return Ei("unsortedSegmentSum")},t.prototype.argMin=function(t,e){return Ei("argMin")},t.prototype.argMax=function(t,e){return Ei("argMax")},t.prototype.equal=function(t,e){return Ei("equal")},t.prototype.notEqual=function(t,e){return Ei("notEqual")},t.prototype.less=function(t,e){return Ei("less")},t.prototype.lessEqual=function(t,e){return Ei("lessEqual")},t.prototype.greater=function(t,e){return Ei("greater")},t.prototype.greaterEqual=function(t,e){return Ei("greaterEqual")},t.prototype.logicalNot=function(t){return Ei("logicalNot")},t.prototype.logicalAnd=function(t,e){return Ei("logicalAnd")},t.prototype.logicalOr=function(t,e){return Ei("logicalOr")},t.prototype.where=function(t){return Ei("where")},t.prototype.select=function(t,e,n){return Ei("select")},t.prototype.topk=function(t,e,n){return Ei("topk")},t.prototype.min=function(t,e){return Ei("min")},t.prototype.minimum=function(t,e){return Ei("minimum")},t.prototype.mod=function(t,e){return Ei("mod")},t.prototype.max=function(t,e){return Ei("max")},t.prototype.maximum=function(t,e){return Ei("maximum")},t.prototype.all=function(t,e){return Ei("all")},t.prototype.any=function(t,e){return Ei("any")},t.prototype.squaredDifference=function(t,e){return Ei("squaredDifference")},t.prototype.ceil=function(t){return Ei("ceil")},t.prototype.floor=function(t){return Ei("floor")},t.prototype.round=function(t){return Ei("round")},t.prototype.sign=function(t){return Ei("sign")},t.prototype.isNaN=function(t){return Ei("isNaN")},t.prototype.isInf=function(t){return Ei("isInf")},t.prototype.isFinite=function(t){return Ei("isFinite")},t.prototype.pow=function(t,e){return Ei("pow")},t.prototype.exp=function(t){return Ei("exp")},t.prototype.expm1=function(t){return Ei("expm1")},t.prototype.softmax=function(t,e){return Ei("softmax")},t.prototype.log=function(t){return Ei("log")},t.prototype.log1p=function(t){return Ei("log1p")},t.prototype.sqrt=function(t){return Ei("sqrt")},t.prototype.rsqrt=function(t){return Ei("rsqrt")},t.prototype.square=function(t){return Ei("square")},t.prototype.reciprocal=function(t){return Ei("reciprocal")},t.prototype.relu=function(t){return Ei("relu")},t.prototype.relu6=function(t){return Ei("relu6")},t.prototype.prelu=function(t,e){return Ei("prelu")},t.prototype.elu=function(t){return Ei("elu")},t.prototype.eluDer=function(t,e){return Ei("eluDer")},t.prototype.selu=function(t){return Ei("selu")},t.prototype.int=function(t){return Ei("int")},t.prototype.clip=function(t,e,n){return Ei("clip")},t.prototype.abs=function(t){return Ei("abs")},t.prototype.complexAbs=function(t){return Ei("complexAbs")},t.prototype.sigmoid=function(t){return Ei("sigmoid")},t.prototype.softplus=function(t){return Ei("softplus")},t.prototype.sin=function(t){return Ei("sin")},t.prototype.cos=function(t){return Ei("cos")},t.prototype.tan=function(t){return Ei("tan")},t.prototype.asin=function(t){return Ei("asin")},t.prototype.acos=function(t){return Ei("acos")},t.prototype.atan=function(t){return Ei("atan")},t.prototype.atan2=function(t,e){return Ei("atan2")},t.prototype.sinh=function(t){return Ei("sinh")},t.prototype.cosh=function(t){return Ei("cosh")},t.prototype.tanh=function(t){return Ei("tanh")},t.prototype.asinh=function(t){return Ei("asinh")},t.prototype.acosh=function(t){return Ei("acosh")},t.prototype.atanh=function(t){return Ei("atanh")},t.prototype.erf=function(t){return Ei("erf")},t.prototype.step=function(t,e){return Ei("step")},t.prototype.fusedConv2d=function(t){return t.input,t.filter,t.convInfo,t.bias,t.activation,t.preluActivationWeights,Ei("fusedConv2d")},t.prototype.conv2d=function(t,e,n){return Ei("conv2d")},t.prototype.conv2dDerInput=function(t,e,n){return Ei("conv2dDerInput")},t.prototype.conv2dDerFilter=function(t,e,n){return Ei("conv2dDerFilter")},t.prototype.fusedDepthwiseConv2D=function(t){return t.input,t.filter,t.convInfo,t.bias,t.activation,t.preluActivationWeights,Ei("fusedDepthwiseConv2D")},t.prototype.depthwiseConv2D=function(t,e,n){return Ei("depthwiseConv2D")},t.prototype.depthwiseConv2DDerInput=function(t,e,n){return Ei("depthwiseConv2DDerInput")},t.prototype.depthwiseConv2DDerFilter=function(t,e,n){return Ei("depthwiseConv2DDerFilter")},t.prototype.conv3d=function(t,e,n){return Ei("conv3d")},t.prototype.conv3dDerInput=function(t,e,n){return Ei("conv3dDerInput")},t.prototype.conv3dDerFilter=function(t,e,n){return Ei("conv3dDerFilter")},t.prototype.maxPool=function(t,e){return Ei("maxPool")},t.prototype.maxPoolBackprop=function(t,e,n,r){return Ei("maxPoolBackprop")},t.prototype.avgPool=function(t,e){return Ei("avgPool")},t.prototype.avgPoolBackprop=function(t,e,n){return Ei("avgPoolBackprop")},t.prototype.avgPool3d=function(t,e){return Ei("avgPool3d")},t.prototype.avgPool3dBackprop=function(t,e,n){return Ei("avgPool3dBackprop")},t.prototype.maxPool3d=function(t,e){return Ei("maxPool3d")},t.prototype.maxPool3dBackprop=function(t,e,n,r){return Ei("maxPool3dBackprop")},t.prototype.reshape=function(t,e){return Ei("reshape")},t.prototype.cast=function(t,e){return Ei("cast")},t.prototype.tile=function(t,e){return Ei("tile")},t.prototype.pad=function(t,e,n){return Ei("pad")},t.prototype.transpose=function(t,e){return Ei("transpose")},t.prototype.gather=function(t,e,n){return Ei("gather")},t.prototype.gatherND=function(t,e){return Ei("gatherND")},t.prototype.scatterND=function(t,e,n){return Ei("scatterND")},t.prototype.batchToSpaceND=function(t,e,n){return Ei("batchToSpaceND")},t.prototype.spaceToBatchND=function(t,e,n){return Ei("spaceToBatchND")},t.prototype.resizeBilinear=function(t,e,n,r){return Ei("resizeBilinear")},t.prototype.resizeBilinearBackprop=function(t,e,n){return Ei("resizeBilinearBackprop")},t.prototype.resizeNearestNeighbor=function(t,e,n,r){return Ei("resizeNearestNeighbor")},t.prototype.resizeNearestNeighborBackprop=function(t,e,n){return Ei("resizeNearestNeighborBackprop")},t.prototype.batchNormalization=function(t,e,n,r,i,a){return Ei("batchNormalization")},t.prototype.localResponseNormalization4D=function(t,e,n,r,i){return Ei("localResponseNormalization4D")},t.prototype.LRNGrad=function(t,e,n,r,i,a,o){return Ei("LRNGrad")},t.prototype.multinomial=function(t,e,n,r){return Ei("multinomial")},t.prototype.oneHot=function(t,e,n,r){return Ei("oneHot")},t.prototype.cumsum=function(t,e,n,r){return Ei("cumsum")},t.prototype.nonMaxSuppression=function(t,e,n,r,i){return Ei("nonMaxSuppression")},t.prototype.fft=function(t){return Ei("fft")},t.prototype.ifft=function(t){return Ei("ifft")},t.prototype.complex=function(t,e){return Ei("complex")},t.prototype.real=function(t){return Ei("real")},t.prototype.imag=function(t){return Ei("imag")},t.prototype.cropAndResize=function(t,e,n,r,i,a){return Ei("cropAndResize")},t.prototype.depthToSpace=function(t,e,n){return Ei("depthToSpace")},t.prototype.split=function(t,e,n){return Ei("split")},t.prototype.sparseToDense=function(t,e,n,r){return Ei("sparseToDense")},t.prototype.diag=function(t){return Ei("diag")},t.prototype.fill=function(t,e,n){return Ei("fill")},t.prototype.onesLike=function(t){return Ei("onesLike")},t.prototype.zerosLike=function(t){return Ei("zerosLike")},t.prototype.linspace=function(t,e,n){return Ei("linspace")},t.prototype.dispose=function(){return Ei("dispose")},t}();function Ei(t){throw new Error("'"+t+"' not yet implemented or not found in the registry. Did you forget to import the kernel?")}function Oi(t,e){for(var n=t.length,r=[],i=0;i<n;i++){var a=n-1-i,o=t[a]||1;(e[e.length-1-i]||1)>1&&1===o&&r.unshift(a)}return r}function Si(t,e){for(var n=[],r=0;r<e.length;r++){var i=t[t.length-r-1],a=e.length-r-1,o=e[a];(null==i||1===i&&o>1)&&n.unshift(a)}return n}function Ci(t,e){for(var n=[],r=Math.max(t.length,e.length),i=0;i<r;i++){var a=t[t.length-i-1];null==a&&(a=1);var o=e[e.length-i-1];if(null==o&&(o=1),1===a)n.unshift(o);else if(1===o)n.unshift(a);else{if(a!==o)throw Error("Operands could not be broadcast together with shapes "+t+" and "+e+".");n.unshift(a)}}return n}function Ai(t,e,n,r,i,a,o){void 0===o&&(o="channelsLast");var s,u=Mi(e),c=u[0],l=u[1];if("channelsLast"===o)s=[c,l,t[3],t[3]];else{if("channelsFirst"!==o)throw new Error("Unknown dataFormat "+o);s=[c,l,t[1],t[1]]}return Ti(t,s,n,r,i,a,!1,o)}function Ni(t,e,n,r,i,a,o){void 0===o&&(o="NDHWC");var s,u,c=Ri(e),l=c[0],f=c[1],d=c[2];if("NDHWC"===o)u="channelsLast",s=[l,f,d,t[4],t[4]];else{if("NCDHW"!==o)throw new Error("Unknown dataFormat "+o);u="channelsFirst",s=[l,f,d,t[1],t[1]]}return Ii(t,s,n,r,i,!1,u,a)}function Ti(t,e,n,r,i,a,o,s){void 0===o&&(o=!1),void 0===s&&(s="channelsLast");var u=[-1,-1,-1,-1],c=u[0],l=u[1],f=u[2],d=u[3];if("channelsLast"===s)c=t[0],l=t[1],f=t[2],d=t[3];else{if("channelsFirst"!==s)throw new Error("Unknown dataFormat "+s);c=t[0],d=t[1],l=t[2],f=t[3]}var h,p=e[0],m=e[1],g=e[3],v=Mi(n),y=v[0],b=v[1],x=Mi(r),w=x[0],k=x[1],_=Fi(p,w),E=Fi(m,k),O=function(t,e,n,r,i,a,o,s){var u,c,l;if("number"==typeof t){u={top:t,bottom:t,left:t,right:t,type:0===t?"VALID":"NUMBER"};var f=function(t,e,n,r,i){null==r&&(r=Di(t,e,n));var a=t[1],o=ji((t[0]-e+2*r)/n+1,i);C(M(o),function(){return"The output # of rows ("+o+") must be an integer. Change the stride and/or zero pad parameters"});var s=ji((a-e+2*r)/n+1,i);return C(M(s),function(){return"The output # of columns ("+s+") must be an integer. Change the stride and/or zero pad parameters"}),[o,s]}([e,n],a,r,t,s);c=f[0],l=f[1]}else if("same"===t){c=Math.ceil(e/r),l=Math.ceil(n/i);var d=Math.max(0,(c-1)*r+a-e),h=Math.max(0,(l-1)*i+o-n),p=Math.floor(d/2),m=d-p,g=Math.floor(h/2);u={top:p,bottom:m,left:g,right:h-g,type:"SAME"}}else{if("valid"!==t)throw Error("Unknown padding parameter: "+t);u={top:0,bottom:0,left:0,right:0,type:"VALID"},c=Math.ceil((e-a+1)/r),l=Math.ceil((n-o+1)/i)}return{padInfo:u,outHeight:c,outWidth:l}}(i,l,f,y,b,_,E,a),S=O.padInfo,A=O.outHeight,N=O.outWidth,T=o?g*d:g;return"channelsFirst"===s?h=[c,T,A,N]:"channelsLast"===s&&(h=[c,A,N,T]),{batchSize:c,dataFormat:s,inHeight:l,inWidth:f,inChannels:d,outHeight:A,outWidth:N,outChannels:T,padInfo:S,strideHeight:y,strideWidth:b,filterHeight:p,filterWidth:m,effectiveFilterHeight:_,effectiveFilterWidth:E,dilationHeight:w,dilationWidth:k,inShape:t,outShape:h,filterShape:e}}function Ii(t,e,n,r,i,a,o,s){void 0===a&&(a=!1),void 0===o&&(o="channelsLast");var u=[-1,-1,-1,-1,-1],c=u[0],l=u[1],f=u[2],d=u[3],h=u[4];if("channelsLast"===o)c=t[0],l=t[1],f=t[2],d=t[3],h=t[4];else{if("channelsFirst"!==o)throw new Error("Unknown dataFormat "+o);c=t[0],h=t[1],l=t[2],f=t[3],d=t[4]}var p,m=e[0],g=e[1],v=e[2],y=e[4],b=Ri(n),x=b[0],w=b[1],k=b[2],_=Ri(r),E=_[0],O=_[1],S=_[2],A=Fi(m,E),N=Fi(g,O),T=Fi(v,S),I=function(t,e,n,r,i,a,o,s,u,c,l){var f,d,h,p;if("number"==typeof t){f={top:t,bottom:t,left:t,right:t,front:t,back:t,type:0===t?"VALID":"NUMBER"};var m=function(t,e,n,r,i,a){null==i&&(i=Di(t,e,r));var o=t[1],s=t[2],u=ji((t[0]-e+2*i)/r+1,a);C(M(u),function(){return"The output # of depths ("+u+") must be an integer. Change the stride and/or zero pad parameters"});var c=ji((o-e+2*i)/r+1,a);C(M(c),function(){return"The output # of rows ("+c+") must be an integer. Change the stride and/or zero pad parameters"});var l=ji((s-e+2*i)/r+1,a);return C(M(l),function(){return"The output # of columns ("+l+") must be an integer. Change the stride and/or zero pad parameters"}),[u,c,l,1]}([e,n,r,1],s,0,i,t,l);d=m[0],h=m[1],p=m[2]}else if("same"===t){var g=((d=Math.ceil(e/i))-1)*i+s-e,v=((h=Math.ceil(n/a))-1)*a+u-n,y=((p=Math.ceil(r/o))-1)*o+c-r,b=Math.floor(g/2),x=g-b,w=Math.floor(v/2),k=v-w,_=Math.floor(y/2);f={top:w,bottom:k,left:_,right:y-_,front:b,back:x,type:"SAME"}}else{if("valid"!==t)throw Error("Unknown padding parameter: "+t);f={top:0,bottom:0,left:0,right:0,front:0,back:0,type:"VALID"},d=Math.ceil((e-s+1)/i),h=Math.ceil((n-u+1)/a),p=Math.ceil((r-c+1)/o)}return{padInfo:f,outDepth:d,outHeight:h,outWidth:p}}(i,l,f,d,x,w,k,A,N,T,s),D=I.padInfo,R=I.outDepth,F=I.outHeight,j=I.outWidth,P=a?y*h:y;return"channelsFirst"===o?p=[c,P,R,F,j]:"channelsLast"===o&&(p=[c,R,F,j,P]),{batchSize:c,dataFormat:o,inDepth:l,inHeight:f,inWidth:d,inChannels:h,outDepth:R,outHeight:F,outWidth:j,outChannels:P,padInfo:D,strideDepth:x,strideHeight:w,strideWidth:k,filterDepth:m,filterHeight:g,filterWidth:v,effectiveFilterDepth:A,effectiveFilterHeight:N,effectiveFilterWidth:T,dilationDepth:E,dilationHeight:O,dilationWidth:S,inShape:t,outShape:p,filterShape:e}}function Di(t,e,n,r){void 0===r&&(r=1);var i=Fi(e,r);return Math.floor((t[0]*(n-1)-n+i)/2)}function Mi(t){return"number"==typeof t?[t,t,t]:2===t.length?[t[0],t[1],1]:t}function Ri(t){return"number"==typeof t?[t,t,t]:t}function Fi(t,e){return e<=1?t:t+(t-1)*(e-1)}function ji(t,e){if(!e)return t;switch(e){case"round":return Math.round(t);case"ceil":return Math.ceil(t);case"floor":return Math.floor(t);default:throw new Error("Unknown roundingMode "+e)}}function Pi(t){var e=Mi(t),n=e[0],r=e[1],i=e[2];return 1===n&&1===r&&1===i}function Li(t,e){return Pi(t)||Pi(e)}function zi(t){if("NHWC"===t)return"channelsLast";if("NCHW"===t)return"channelsFirst";throw new Error("Unknown dataFormat "+t)}function Bi(t,e,n){if("complex64"===e){if("complex64"===t.dtype)return t.clone();var r=$n(t.shape),i=t.toFloat(),a=n.complex(i,r);return r.dispose(),i.dispose(),a}if(!H(t.dtype,e))return Wt.makeTensorFromDataId(t.dataId,t.shape,e);if("complex64"===t.dtype){var o=n.real(t);return a=o.cast(e),o.dispose(),a}if("int32"===e)return n.int(t);if("bool"===e){var s=Ln(0,t.dtype);return a=n.notEqual(t,s),s.dispose(),a}throw new Error("Error in Cast: failed to cast "+t.dtype+" to "+e)}function Ui(t,e){return Wt.makeTensorFromDataId(t.dataId,e,t.dtype)}function Wi(t,e,n){var r=(e-t)/(n-1),i=at(n,"float32");i[0]=t;for(var a=1;a<i.length;a++)i[a]=i[a-1]+r;return zn(i,"float32")}var Vi=Object.freeze({castTensor:Bi,reshapeTensor:Ui,linspaceImpl:Wi,upcastType:Mt,axesAreInnerMostDims:kn,combineLocations:_n,computeOutAndReduceShapes:En,expandShapeToKeepDim:On,assertAxesAreInnerMostDims:Sn,getAxesPermutation:Cn,getUndoAxesPermutation:An,getInnerMostAxes:Nn,getBroadcastDims:Oi,getReductionAxes:Si,assertAndGetBroadcastShape:Ci,assertParamsConsistent:Tn,computeOutShape:In,computePool2DInfo:Ai,computePool3DInfo:Ni,computeConv2DInfo:Ti,computeConv3DInfo:Ii,computeDefaultPad:Di,tupleValuesAreOne:Pi,eitherStridesOrDilationsAreOne:Li,convertConv2DDataFormat:zi,PARALLELIZE_THRESHOLD:Qr,computeOptimalWindowSize:ti});function qi(t,e){if(t.length!==e.length)throw new Error("Cannot merge real and imag arrays of different lengths. real:"+t.length+", imag: "+e.length+".");for(var n=new Float32Array(2*t.length),r=0;r<n.length;r+=2)n[r]=t[r/2],n[r+1]=e[r/2];return n}function Hi(t,e){return{real:t[2*e],imag:t[2*e+1]}}function Gi(t,e,n,r){t[2*r]=e,t[2*r+1]=n}function $i(t,e,n){var r=(n?2:-2)*Math.PI*(t/e);return{real:Math.cos(r),imag:Math.sin(r)}}function Ki(t,e,n){var r=function(t,e,n){return function(t,e,n){for(var r=0,i=t.length,a=0,o=!1;r<i;){var s=n(e,t[a=r+(i-r>>>1)]);s>0?r=a+1:(i=a,o=!s)}return o?r:-r-1}(t,e,n||Xi)}(t,e,n),i=r<0?-(r+1):r;t.splice(i,0,e)}function Xi(t,e){return t>e?1:t<e?-1:0}function Yi(t,e,n,r,i){return Zi(t,e,n,r,i,0).selectedIndices}function Ji(t,e,n,r,i,a){var o=Zi(t,e,n,r,i,a,!0);return o.numValidOutputs.dispose(),{selectedIndices:o.selectedIndices,selectedScores:o.selectedScores}}function Zi(t,e,n,r,i,a,o,s){void 0===o&&(o=!1),void 0===s&&(s=!1);for(var u=Array.from(e).map(function(t,e){return{score:t,boxIndex:e,suppressBeginIndex:0}}).filter(function(t){return t.score>i}).sort(ea),c=a>0?-.5/a:0,l=[],f=[];l.length<n&&u.length>0;){var d=u.pop(),h=d.score,p=d.boxIndex,m=d.suppressBeginIndex;if(h<i)break;for(var g=!1,v=l.length-1;v>=m;--v){var y=Qi(t,p,l[v]);if(y>=r){g=!0;break}if(d.score=d.score*ta(r,c,y),d.score<=i)break}d.suppressBeginIndex=l.length,g||(d.score===h?(l.push(p),f.push(d.score)):d.score>i&&Ki(u,d,ea))}var b=l.length;return s&&(l.fill(0,b),f.fill(0,b)),{selectedIndices:zn(l,"int32"),selectedScores:zn(f,"float32"),numValidOutputs:Ln(b,"int32")}}function Qi(t,e,n){var r=t.subarray(4*e,4*e+4),i=t.subarray(4*n,4*n+4),a=Math.min(r[0],r[2]),o=Math.min(r[1],r[3]),s=Math.max(r[0],r[2]),u=Math.max(r[1],r[3]),c=Math.min(i[0],i[2]),l=Math.min(i[1],i[3]),f=Math.max(i[0],i[2]),d=Math.max(i[1],i[3]),h=(s-a)*(u-o),p=(f-c)*(d-l);if(h<=0||p<=0)return 0;var m=Math.max(a,c),g=Math.max(o,l),v=Math.min(s,f),y=Math.min(u,d),b=Math.max(v-m,0)*Math.max(y-g,0);return b/(h+p-b)}function ta(t,e,n){var r=Math.exp(e*n*n);return n<=t?r:0}function ea(t,e){return t.score-e.score||t.score===e.score&&e.boxIndex-t.boxIndex}function na(t,e,n){var r=new Array(t.rank).fill(0),i=t.shape.slice();return e.map(function(e){i[n]=e;var a=t.slice(r,i);return r[n]+=e,a})}function ra(t,e){for(var n=new Array(t.rank),r=0;r<n.length;r++)n[r]=t.shape[r]*e[r];var i=vr(n,t.dtype);for(r=0;r<i.values.length;++r){for(var a=i.indexToLoc(r),o=new Array(t.rank),s=0;s<o.length;s++)o[s]=a[s]%t.shape[s];var u=t.locToIndex(o);i.values[r]=t.values[u]}return i.toTensor()}function ia(t,e,n,r,i){for(var a=e[e.length-1],o=[t.length/a,a],s=o[0],u=o[1],c=U(n,s*r),l=U("int32",s*r),f=0;f<s;f++){for(var d=f*u,h=t.subarray(d,d+u),p=[],m=0;m<h.length;m++)p.push({value:h[m],index:m});p.sort(function(t,e){return e.value-t.value});var g=f*r,v=c.subarray(g,g+r),y=l.subarray(g,g+r);for(m=0;m<r;m++)v[m]=p[m].value,y[m]=p[m].index}var b=e.slice();return b[b.length-1]=r,[jn(c,b,n),jn(l,b,"int32")]}function aa(t,e){for(var n=[],r=0;r<e.length;r++)e[r]&&n.push(r);var i=vr(t,"int32"),a=vr([n.length,t.length],"int32");for(r=0;r<n.length;r++){var o=i.indexToLoc(n[r]),s=r*t.length;a.values.set(o,s)}return a.toTensor()}function oa(t,e){return["x","y","z","w","u","v"].slice(0,e).map(function(e){return t+"."+e})}function sa(t,e){return 1===e?[t]:oa(t,e)}function ua(){var t,e,n,r,i,a,o,s,u,c;return 2===f().getNumber("WEBGL_VERSION")?(t="#version 300 es",e="in",n="out",r="in",i="texture",a="outputColor",o="out vec4 outputColor;",s="\n bool isnan_custom(float val) {\n return (val > 0.0 || val < 0.0) ? false : val != 0.0;\n }\n\n bvec4 isnan_custom(vec4 val) {\n return bvec4(isnan_custom(val.x),\n isnan_custom(val.y), isnan_custom(val.z), isnan_custom(val.w));\n }\n\n #define isnan(value) isnan_custom(value)\n ",u="",c="\n #define round(value) newRound(value)\n int newRound(float value) {\n return int(floor(value + 0.5));\n }\n\n ivec4 newRound(vec4 value) {\n return ivec4(floor(value + vec4(0.5)));\n }\n "):(t="",e="attribute",n="varying",r="varying",i="texture2D",a="gl_FragColor",o="",s="\n #define isnan(value) isnan_custom(value)\n bool isnan_custom(float val) {\n return (val > 0. || val < 1. || val == 0.) ? false : true;\n }\n bvec4 isnan_custom(vec4 val) {\n return bvec4(isnan(val.x), isnan(val.y), isnan(val.z), isnan(val.w));\n }\n ",u="\n uniform float INFINITY;\n\n bool isinf(float val) {\n return abs(val) == INFINITY;\n }\n bvec4 isinf(vec4 val) {\n return equal(abs(val), vec4(INFINITY));\n }\n ",c="\n int round(float value) {\n return int(floor(value + 0.5));\n }\n\n ivec4 round(vec4 value) {\n return ivec4(floor(value + vec4(0.5)));\n }\n "),{version:t,attribute:e,varyingVs:n,varyingFs:r,texture2D:i,output:a,defineOutput:o,defineSpecialNaN:s,defineSpecialInf:u,defineRound:c}}function ca(t,e,n){void 0===n&&(n="index");var r=et(e);return r.map(function(e,i){return"int "+t[i]+" = "+n+" / "+e+"; "+(i===r.length-1?"int "+t[i+1]+" = "+n+" - "+t[i]+" * "+e:"index -= "+t[i]+" * "+e)+";"}).join("")}function la(t){var e=et(t).map(function(t){return t.toString()});return"\n int getFlatIndex(ivec3 coords) {\n return coords.x * "+e[0]+" + coords.y * "+e[1]+" + coords.z;\n }\n"}var fa="\n const float FLOAT_MAX = 1.70141184e38;\n const float FLOAT_MIN = 1.17549435e-38;\n\n lowp vec4 encode_float(highp float v) {\n if (isnan(v)) {\n return vec4(255, 255, 255, 255);\n }\n\n highp float av = abs(v);\n\n if(av < FLOAT_MIN) {\n return vec4(0.0, 0.0, 0.0, 0.0);\n } else if(v > FLOAT_MAX) {\n return vec4(0.0, 0.0, 128.0, 127.0) / 255.0;\n } else if(v < -FLOAT_MAX) {\n return vec4(0.0, 0.0, 128.0, 255.0) / 255.0;\n }\n\n highp vec4 c = vec4(0,0,0,0);\n\n highp float e = floor(log2(av));\n highp float m = exp2(fract(log2(av))) - 1.0;\n\n c[2] = floor(128.0 * m);\n m -= c[2] / 128.0;\n c[1] = floor(32768.0 * m);\n m -= c[1] / 32768.0;\n c[0] = floor(8388608.0 * m);\n\n highp float ebias = e + 127.0;\n c[3] = floor(ebias / 2.0);\n ebias -= c[3] * 2.0;\n c[2] += floor(ebias) * 128.0;\n\n c[3] += 128.0 * step(0.0, -v);\n\n return c / 255.0;\n }\n";function da(t,e,n,r){var i=[];t.forEach(function(t){var e=I(t.shapeInfo.logicalShape);t.shapeInfo.isUniform?i.push("uniform float "+t.name+(e>1?"["+e+"]":"")+";"):(i.push("uniform sampler2D "+t.name+";"),i.push("uniform int offset"+t.name+";"))});var a,o,s=i.join("\n"),u=t.map(function(t){return function(t,e,n){void 0===n&&(n=!1);var r="";r+=n?function t(e){var n,r,i;switch(e.shapeInfo.logicalShape.length){case 0:return n=e.name,r="get"+n.charAt(0).toUpperCase()+n.slice(1),i=ua(),"\n vec4 "+r+"() {\n return "+i.texture2D+"("+n+", halfCR);\n }\n ";case 1:return function(t){var e=t.name,n="get"+e.charAt(0).toUpperCase()+e.slice(1),r=t.shapeInfo.texShape,i=[Math.ceil(r[0]/2),Math.ceil(r[1]/2)],a=ua();return"\n vec4 "+n+"(int index) {\n vec2 uv = packedUVfrom1D(\n "+i[0]+", "+i[1]+", index);\n return "+a.texture2D+"("+e+", uv);\n }\n "}(e);case 2:return function(t){var e=t.shapeInfo.logicalShape,n=t.name,r="get"+n.charAt(0).toUpperCase()+n.slice(1),i=t.shapeInfo.texShape,a=i[0],o=i[1],s=ua();if(null!=i&&D(e,i))return"\n vec4 "+r+"(int row, int col) {\n vec2 uv = (vec2(col, row) + halfCR) / vec2("+o+".0, "+a+".0);\n\n return "+s.texture2D+"("+n+", uv);\n }\n ";var u=[Math.ceil(i[0]/2),Math.ceil(i[1]/2)],c=Math.ceil(e[1]/2);return"\n vec4 "+r+"(int row, int col) {\n vec2 uv = packedUVfrom2D("+c+", "+u[0]+", "+u[1]+", row, col);\n return "+s.texture2D+"("+n+", uv);\n }\n "}(e);case 3:return function(e){var n=e.shapeInfo.logicalShape,r=e.name,i="get"+r.charAt(0).toUpperCase()+r.slice(1),a=e.shapeInfo.texShape,o=[Math.ceil(a[0]/2),Math.ceil(a[1]/2)];if(1===n[0]){var s=n.slice(1),u=xa(e,s);return"\n "+t(u)+"\n vec4 "+i+"(int b, int row, int col) {\n return "+i+"("+wa(["b","row","col"],[1,2])+");\n }\n "}var c=o[0],l=o[1],f=Math.ceil(n[2]/2),d=f*Math.ceil(n[1]/2),h=ua();return"\n vec4 "+i+"(int b, int row, int col) {\n vec2 uv = packedUVfrom3D(\n "+c+", "+l+", "+d+", "+f+", b, row, col);\n return "+h.texture2D+"("+r+", uv);\n }\n "}(e);default:return function(t){for(var e=t.shapeInfo.logicalShape,n=e.length,r=t.name,i="get"+r.charAt(0).toUpperCase()+r.slice(1),a=t.shapeInfo.texShape,o=[Math.ceil(a[0]/2),Math.ceil(a[1]/2)],s=o[0],u=o[1],c=Math.ceil(e[n-1]/2),l=c*Math.ceil(e[n-2]/2),f="int b, int row, int col",d="b * "+l+" + (row / 2) * "+c+" + (col / 2)",h=2;h<n-1;h++)f="int b"+h+", "+f,l*=e[n-h-1],d="b"+h+" * "+l+" + "+d;var p=ua();return"\n vec4 "+i+"("+f+") {\n int index = "+d+";\n int texR = index / "+u+";\n int texC = index - texR * "+u+";\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2("+u+", "+s+");\n return "+p.texture2D+"("+r+", uv);\n }\n "}(e)}}(t):function t(e){var n=e.shapeInfo.logicalShape;switch(n.length){case 0:return function(t){var e=t.name,n="get"+e.charAt(0).toUpperCase()+e.slice(1);if(t.shapeInfo.isUniform)return"float "+n+"() {return "+e+";}";var r=t.shapeInfo.texShape,i=r[0],a=r[1];if(1===i&&1===a)return"\n float "+n+"() {\n return sampleTexture("+e+", halfCR);\n }\n ";var o=t.shapeInfo.texShape,s=o[0],u=o[1],c=va(e);return"\n float "+n+"() {\n vec2 uv = uvFromFlat("+s+", "+u+", "+c+");\n return sampleTexture("+e+", uv);\n }\n "}(e);case 1:return function(t){var e=t.name,n="get"+e.charAt(0).toUpperCase()+e.slice(1);if(t.shapeInfo.isUniform)return"\n float "+n+"(int index) {\n "+ya(t)+"\n }\n ";var r=t.shapeInfo.texShape,i=r[0],a=r[1];if(1===a&&1===i)return"\n float "+n+"(int index) {\n return sampleTexture("+e+", halfCR);\n }\n ";var o=va(e);return 1===a?"\n float "+n+"(int index) {\n vec2 uv = vec2(0.5, (float(index + "+o+") + 0.5) / "+i+".0);\n return sampleTexture("+e+", uv);\n }\n ":1===i?"\n float "+n+"(int index) {\n vec2 uv = vec2((float(index + "+o+") + 0.5) / "+a+".0, 0.5);\n return sampleTexture("+e+", uv);\n }\n ":"\n float "+n+"(int index) {\n vec2 uv = uvFromFlat("+i+", "+a+", index + "+o+");\n return sampleTexture("+e+", uv);\n }\n "}(e);case 2:return function(e){var n=e.shapeInfo.logicalShape,r=e.name,i="get"+r.charAt(0).toUpperCase()+r.slice(1),a=e.shapeInfo.texShape;if(null!=a&&D(n,a)){var o=a[0],s=a[1];return"\n float "+i+"(int row, int col) {\n vec2 uv = (vec2(col, row) + halfCR) / vec2("+s+".0, "+o+".0);\n return sampleTexture("+r+", uv);\n }\n "}var u=B(n),c=u.newShape,l=u.keptDims,f=c;if(f.length<n.length){var d=xa(e,f);return"\n "+t(d)+"\n float "+i+"(int row, int col) {\n return "+i+"("+wa(["row","col"],l)+");\n }\n "}if(e.shapeInfo.isUniform)return"\n float "+i+"(int row, int col) {\n int index = round(dot(vec2(row, col), vec2("+n[1]+", 1)));\n "+ya(e)+"\n }\n ";var h=a[0],p=a[1],m=va(r);return 1===p?"\n float "+i+"(int row, int col) {\n float index = dot(vec3(row, col, "+m+"), vec3("+n[1]+", 1, 1));\n vec2 uv = vec2(0.5, (index + 0.5) / "+h+".0);\n return sampleTexture("+r+", uv);\n }\n ":1===h?"\n float "+i+"(int row, int col) {\n float index = dot(vec3(row, col, "+m+"), vec3("+n[1]+", 1, 1));\n vec2 uv = vec2((index + 0.5) / "+p+".0, 0.5);\n return sampleTexture("+r+", uv);\n }\n ":"\n float "+i+"(int row, int col) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * "+n[1]+" + col + "+m+";\n vec2 uv = uvFromFlat("+h+", "+p+", index);\n return sampleTexture("+r+", uv);\n }\n"}(e);case 3:return function(e){var n=e.shapeInfo.logicalShape,r=e.name,i="get"+r.charAt(0).toUpperCase()+r.slice(1),a=n[1]*n[2],o=n[2],s=B(n),u=s.newShape,c=s.keptDims,l=u;if(l.length<n.length){var f=xa(e,l);return"\n "+t(f)+"\n float "+i+"(int row, int col, int depth) {\n return "+i+"("+wa(["row","col","depth"],c)+");\n }\n "}if(e.shapeInfo.isUniform)return"\n float "+i+"(int row, int col, int depth) {\n int index = round(dot(vec3(row, col, depth),\n vec3("+a+", "+o+", 1)));\n "+ya(e)+"\n }\n ";var d=e.shapeInfo.texShape,h=d[0],p=d[1],m=e.shapeInfo.flatOffset;if(p===a&&null==m)return"\n float "+i+"(int row, int col, int depth) {\n float texR = float(row);\n float texC = dot(vec2(col, depth), vec2("+o+", 1));\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2("+p+".0, "+h+".0);\n return sampleTexture("+r+", uv);\n }\n ";if(p===o&&null==m)return"\n float "+i+"(int row, int col, int depth) {\n float texR = dot(vec2(row, col), vec2("+n[1]+", 1));\n float texC = float(depth);\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2("+p+".0, "+h+".0);\n return sampleTexture("+r+", uv);\n }\n ";var g=va(r);return"\n float "+i+"(int row, int col, int depth) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * "+a+" + col * "+o+" + depth + "+g+";\n vec2 uv = uvFromFlat("+h+", "+p+", index);\n return sampleTexture("+r+", uv);\n }\n "}(e);case 4:return function(e){var n=e.shapeInfo.logicalShape,r=e.name,i="get"+r.charAt(0).toUpperCase()+r.slice(1),a=n[3],o=n[2]*a,s=n[1]*o,u=B(n),c=u.newShape,l=u.keptDims;if(c.length<n.length){var f=xa(e,c);return"\n "+t(f)+"\n float "+i+"(int row, int col, int depth, int depth2) {\n return "+i+"("+wa(["row","col","depth","depth2"],l)+");\n }\n "}if(e.shapeInfo.isUniform)return"\n float "+i+"(int row, int col, int depth, int depth2) {\n int index = round(dot(vec4(row, col, depth, depth2),\n vec4("+s+", "+o+", "+a+", 1)));\n "+ya(e)+"\n }\n ";var d=e.shapeInfo.flatOffset,h=e.shapeInfo.texShape,p=h[0],m=h[1];if(m===s&&null==d)return"\n float "+i+"(int row, int col, int depth, int depth2) {\n float texR = float(row);\n float texC =\n dot(vec3(col, depth, depth2),\n vec3("+o+", "+a+", 1));\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2("+m+".0, "+p+".0);\n return sampleTexture("+r+", uv);\n }\n ";if(m===a&&null==d)return"\n float "+i+"(int row, int col, int depth, int depth2) {\n float texR = dot(vec3(row, col, depth),\n vec3("+n[1]*n[2]+", "+n[2]+", 1));\n float texC = float(depth2);\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2("+m+".0, "+p+".0);\n return sampleTexture("+r+", uv);\n }\n ";var g=va(r);return"\n float "+i+"(int row, int col, int depth, int depth2) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * "+s+" + col * "+o+" +\n depth * "+a+" + depth2;\n vec2 uv = uvFromFlat("+p+", "+m+", index + "+g+");\n return sampleTexture("+r+", uv);\n }\n "}(e);case 5:return function(e){var n=e.shapeInfo.logicalShape,r=e.name,i="get"+r.charAt(0).toUpperCase()+r.slice(1),a=n[4],o=n[3]*a,s=n[2]*o,u=n[1]*s,c=B(n),l=c.newShape,f=c.keptDims;if(l.length<n.length){var d=xa(e,l);return"\n "+t(d)+"\n float "+i+"(int row, int col, int depth, int depth2, int depth3) {\n return "+i+"("+wa(["row","col","depth","depth2","depth3"],f)+");\n }\n "}if(e.shapeInfo.isUniform)return"\n float "+i+"(int row, int col, int depth, int depth2, int depth3) {\n float index = dot(\n vec4(row, col, depth, depth2),\n vec4("+u+", "+s+", "+o+", "+a+")) +\n depth3;\n "+ya(e)+"\n }\n ";var h=e.shapeInfo.flatOffset,p=e.shapeInfo.texShape,m=p[0],g=p[1];if(g===u&&null==h)return"\n float "+i+"(int row, int col, int depth, int depth2, int depth3) {\n int texR = row;\n float texC = dot(vec4(col, depth, depth2, depth3),\n vec4("+s+", "+o+", "+a+", 1));\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2("+g+".0, "+m+".0);\n return sampleTexture("+r+", uv);\n }\n ";if(g===a&&null==h)return"\n float "+i+"(int row, int col, int depth, int depth2, int depth3) {\n float texR = dot(\n vec4(row, col, depth, depth2),\n vec4("+n[1]*n[2]*n[3]+",\n "+n[2]*n[3]+", "+n[3]+", 1));\n int texC = depth3;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2("+g+".0, "+m+".0);\n return sampleTexture("+r+", uv);\n }\n ";var v=va(r);return"\n float "+i+"(int row, int col, int depth, int depth2, int depth3) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * "+u+" + col * "+s+" + depth * "+o+" +\n depth2 * "+a+" + depth3 + "+v+";\n vec2 uv = uvFromFlat("+m+", "+g+", index);\n return sampleTexture("+r+", uv);\n }\n "}(e);case 6:return function(e){var n=e.shapeInfo.logicalShape,r=e.name,i="get"+r.charAt(0).toUpperCase()+r.slice(1),a=B(n),o=a.newShape,s=a.keptDims;if(o.length<n.length){var u=xa(e,o);return"\n "+t(u)+"\n float "+i+"(int row, int col, int depth,\n int depth2, int depth3, int depth4) {\n return "+i+"("+wa(["row","col","depth","depth2","depth3","depth4"],s)+");\n }\n "}var c=n[5],l=n[4]*c,f=n[3]*l,d=n[2]*f,h=n[1]*d;if(e.shapeInfo.isUniform)return"\n float "+i+"(int row, int col, int depth,\n int depth2, int depth3, int depth4) {\n int index = round(dot(\n vec4(row, col, depth, depth2),\n vec4("+h+", "+d+", "+f+", "+l+")) +\n dot(\n vec2(depth3, depth4),\n vec2("+c+", 1)));\n "+ya(e)+"\n }\n ";var p=e.shapeInfo.flatOffset,m=e.shapeInfo.texShape,g=m[0],v=m[1];if(v===h&&null==p)return"\n float "+i+"(int row, int col, int depth,\n int depth2, int depth3, int depth4) {\n int texR = row;\n float texC = dot(vec4(col, depth, depth2, depth3),\n vec4("+d+", "+f+", "+l+", "+c+")) +\n float(depth4);\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2("+v+".0, "+g+".0);\n return sampleTexture("+r+", uv);\n }\n ";if(v===c&&null==p)return"\n float "+i+"(int row, int col, int depth,\n int depth2, int depth3, int depth4) {\n float texR = dot(vec4(row, col, depth, depth2),\n vec4("+n[1]*n[2]*n[3]*n[4]+",\n "+n[2]*n[3]*n[4]+",\n "+n[3]*n[4]+",\n "+n[4]+")) + float(depth3);\n int texC = depth4;\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2("+v+".0, "+g+".0);\n return sampleTexture("+r+", uv);\n }\n ";var y=va(r);return"\n float "+i+"(int row, int col, int depth,\n int depth2, int depth3, int depth4) {\n // Explicitly use integer operations as dot() only works on floats.\n int index = row * "+h+" + col * "+d+" + depth * "+f+" +\n depth2 * "+l+" + depth3 * "+c+" + depth4 + "+y+";\n vec2 uv = uvFromFlat("+g+", "+v+", index);\n return sampleTexture("+r+", uv);\n }\n "}(e);default:throw new Error(n.length+"-D input sampling is not yet supported")}}(t);var i=t.shapeInfo.logicalShape,a=e.logicalShape;return i.length<=a.length&&(r+=n?function(t,e){var n,r=t.name,i=r.charAt(0).toUpperCase()+r.slice(1),a="get"+i+"AtOutCoords",o=t.shapeInfo.logicalShape.length,s=e.logicalShape.length,u=Oi(t.shapeInfo.logicalShape,e.logicalShape),c=ba(s),l=s-o,f=["x","y","z","w","u","v"];n=0===o?"":s<2&&u.length>=1?"coords = 0;":u.map(function(t){return"coords."+f[t+l]+" = 0;"}).join("\n");var d;d=s<2&&o>0?"coords":t.shapeInfo.logicalShape.map(function(t,e){return"coords."+f[e+l]}).join(", ");var h="return outputValue;",p=1===I(t.shapeInfo.logicalShape),m=1===I(e.logicalShape);if(1!==o||p||m){if(p&&!m)h=1===s?"\n return vec4(outputValue.x, outputValue.x, 0., 0.);\n ":"\n return vec4(outputValue.x);\n ";else if(u.length){var g=o-2,v=o-1;u.indexOf(g)>-1&&u.indexOf(v)>-1?h="return vec4(outputValue.x);":u.indexOf(g)>-1?h="return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);":u.indexOf(v)>-1&&(h="return vec4(outputValue.xx, outputValue.zz);")}}else h="\n return vec4(outputValue.xy, outputValue.xy);\n ";return"\n vec4 "+a+"() {\n "+c+" coords = getOutputCoords();\n "+n+"\n vec4 outputValue = get"+i+"("+d+");\n "+h+"\n }\n "}(t,e):function(t,e){var n=t.name,r=n.charAt(0).toUpperCase()+n.slice(1),i="get"+r+"AtOutCoords",a=e.texShape,o=t.shapeInfo.texShape,s=t.shapeInfo.logicalShape.length,u=e.logicalShape.length;if(!t.shapeInfo.isUniform&&s===u&&null==t.shapeInfo.flatOffset&&D(o,a))return"\n float "+i+"() {\n return sampleTexture("+n+", resultUV);\n }\n ";var c=ba(u),l=Oi(t.shapeInfo.logicalShape,e.logicalShape),f=u-s,d=["x","y","z","w","u","v"];return"\n float "+i+"() {\n "+c+" coords = getOutputCoords();\n "+(0===s?"":u<2&&l.length>=1?"coords = 0;":l.map(function(t){return"coords."+d[t+f]+" = 0;"}).join("\n"))+"\n return get"+r+"("+(u<2&&s>0?"coords":t.shapeInfo.logicalShape.map(function(t,e){return"coords."+d[e+f]}).join(", "))+");\n }\n "}(t,e)),r}(t,e,r)}).join("\n"),c=e.texShape,l=ua(),f="\n float sampleTexture(sampler2D textureSampler, vec2 uv) {\n return "+l.texture2D+"(textureSampler, uv).r;\n }\n ",d=function(t){return t.version+"\n precision highp float;\n precision highp int;\n precision highp sampler2D;\n "+t.varyingFs+" vec2 resultUV;\n "+t.defineOutput+"\n const vec2 halfCR = vec2(0.5, 0.5);\n\n struct ivec5\n {\n int x;\n int y;\n int z;\n int w;\n int u;\n };\n\n struct ivec6\n {\n int x;\n int y;\n int z;\n int w;\n int u;\n int v;\n };\n\n uniform float NAN;\n "+t.defineSpecialNaN+"\n "+t.defineSpecialInf+"\n "+t.defineRound+"\n\n int imod(int x, int y) {\n return x - y * (x / y);\n }\n\n int idiv(int a, int b, float sign) {\n int res = a / b;\n int mod = imod(a, b);\n if (sign < 0. && mod != 0) {\n res -= 1;\n }\n return res;\n }\n\n //Based on the work of Dave Hoskins\n //https://www.shadertoy.com/view/4djSRW\n #define HASHSCALE1 443.8975\n float random(float seed){\n vec2 p = resultUV * seed;\n vec3 p3 = fract(vec3(p.xyx) * HASHSCALE1);\n p3 += dot(p3, p3.yzx + 19.19);\n return fract((p3.x + p3.y) * p3.z);\n }\n\n "+ha+"\n "+pa+"\n "+ma+"\n "}(l);return e.isPacked?(a=function(t,e){switch(t.length){case 0:return"\n int getOutputCoords() {\n return 0;\n }\n ";case 1:return function(t,e){var n=[Math.ceil(e[0]/2),Math.ceil(e[1]/2)];return 1===n[0]?"\n int getOutputCoords() {\n return 2 * int(resultUV.x * "+n[1]+".0);\n }\n ":1===n[1]?"\n int getOutputCoords() {\n return 2 * int(resultUV.y * "+n[0]+".0);\n }\n ":"\n int getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+n[0]+", "+n[1]+"));\n return 2 * (resTexRC.x * "+n[1]+" + resTexRC.y);\n }\n "}(0,e);case 2:return function(t,e){var n=[Math.ceil(e[0]/2),Math.ceil(e[1]/2)];if(D(t,e))return"\n ivec2 getOutputCoords() {\n return 2 * ivec2(resultUV.yx * vec2("+n[0]+", "+n[1]+"));\n }\n ";var r=Math.ceil(t[1]/2);return"\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+n[0]+", "+n[1]+"));\n\n int index = resTexRC.x * "+n[1]+" + resTexRC.y;\n int r = 2 * (index / "+r+");\n int c = imod(index, "+r+") * 2;\n\n return ivec2(r, c);\n }\n "}(t,e);case 3:return n=t,r=e,i=[Math.ceil(r[0]/2),Math.ceil(r[1]/2)],o=(a=Math.ceil(n[2]/2))*Math.ceil(n[1]/2),"\n ivec3 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+i[0]+", "+i[1]+"));\n int index = resTexRC.x * "+i[1]+" + resTexRC.y;\n\n int b = index / "+o+";\n index -= b * "+o+";\n\n int r = 2 * (index / "+a+");\n int c = imod(index, "+a+") * 2;\n\n return ivec3(b, r, c);\n }\n ";default:return function(t,e){for(var n=[Math.ceil(e[0]/2),Math.ceil(e[1]/2)],r=Math.ceil(t[t.length-1]/2),i=r*Math.ceil(t[t.length-2]/2),a=i,o="",s="b, r, c",u=2;u<t.length-1;u++)o="\n int b"+u+" = index / "+(a*=t[t.length-u-1])+";\n index -= b"+u+" * "+a+";\n "+o,s="b"+u+", "+s;return"\n ivec"+t.length+" getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+n[0]+", "+n[1]+"));\n int index = resTexRC.x * "+n[1]+" + resTexRC.y;\n\n "+o+"\n\n int b = index / "+i+";\n index -= b * "+i+";\n\n int r = 2 * (index / "+r+");\n int c = imod(index, "+r+") * 2;\n\n return ivec"+t.length+"("+s+");\n }\n "}(t,e)}var n,r,i,a,o}(e.logicalShape,c),o="\n void setOutput(vec4 val) {\n "+l.output+" = val;\n }\n "):(a=function(t,e){switch(t.length){case 0:return"\n int getOutputCoords() {\n return 0;\n }\n ";case 1:return function(t,e){return 1===e[0]?"\n int getOutputCoords() {\n return int(resultUV.x * "+e[1]+".0);\n }\n ":1===e[1]?"\n int getOutputCoords() {\n return int(resultUV.y * "+e[0]+".0);\n }\n ":"\n int getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+e[0]+", "+e[1]+"));\n return resTexRC.x * "+e[1]+" + resTexRC.y;\n }\n "}(0,e);case 2:return function(t,e){return D(t,e)?"\n ivec2 getOutputCoords() {\n return ivec2(resultUV.yx * vec2("+e[0]+", "+e[1]+"));\n }\n ":1===t[1]?"\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+e[0]+", "+e[1]+"));\n int index = resTexRC.x * "+e[1]+" + resTexRC.y;\n return ivec2(index, 0);\n }\n ":1===t[0]?"\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+e[0]+", "+e[1]+"));\n int index = resTexRC.x * "+e[1]+" + resTexRC.y;\n return ivec2(0, index);\n }\n ":"\n ivec2 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+e[0]+", "+e[1]+"));\n int index = resTexRC.x * "+e[1]+" + resTexRC.y;\n int r = index / "+t[1]+";\n int c = index - r * "+t[1]+";\n return ivec2(r, c);\n }\n "}(t,e);case 3:return n=e,r=ca(["r","c","d"],t),"\n ivec3 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+n[0]+", "+n[1]+"));\n int index = resTexRC.x * "+n[1]+" + resTexRC.y;\n "+r+"\n return ivec3(r, c, d);\n }\n ";case 4:return function(t,e){var n=ca(["r","c","d","d2"],t);return"\n ivec4 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+e[0]+", "+e[1]+"));\n int index = resTexRC.x * "+e[1]+" + resTexRC.y;\n "+n+"\n return ivec4(r, c, d, d2);\n }\n "}(t,e);case 5:return function(t,e){var n=ca(["r","c","d","d2","d3"],t);return"\n ivec5 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx * vec2("+e[0]+",\n "+e[1]+"));\n\n int index = resTexRC.x * "+e[1]+" + resTexRC.y;\n\n "+n+"\n\n ivec5 outShape = ivec5(r, c, d, d2, d3);\n return outShape;\n }\n "}(t,e);case 6:return function(t,e){var n=ca(["r","c","d","d2","d3","d4"],t);return"\n ivec6 getOutputCoords() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+e[0]+", "+e[1]+"));\n int index = resTexRC.x * "+e[1]+" + resTexRC.y;\n\n "+n+"\n\n ivec6 result = ivec6(r, c, d, d2, d3, d4);\n return result;\n }\n "}(t,e);default:throw new Error(t.length+"-D output sampling is not yet supported")}var n,r}(e.logicalShape,c),o="\n void setOutput(float val) {\n "+l.output+" = vec4(val, 0, 0, 0);\n }\n "),r&&(d+=ga),[d,f,o,s,a,u,n].join("\n")}var ha="\nvec2 uvFromFlat(int texNumR, int texNumC, int index) {\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\nvec2 packedUVfrom1D(int texNumR, int texNumC, int index) {\n int texelIndex = index / 2;\n int texR = texelIndex / texNumC;\n int texC = texelIndex - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n",pa="\nvec2 packedUVfrom2D(int texelsInLogicalRow, int texNumR,\n int texNumC, int row, int col) {\n int texelIndex = (row / 2) * texelsInLogicalRow + (col / 2);\n int texR = texelIndex / texNumC;\n int texC = texelIndex - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n",ma="\nvec2 packedUVfrom3D(int texNumR, int texNumC,\n int texelsInBatch, int texelsInLogicalRow, int b,\n int row, int col) {\n int index = b * texelsInBatch + (row / 2) * texelsInLogicalRow + (col / 2);\n int texR = index / texNumC;\n int texC = index - texR * texNumC;\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\n}\n",ga="\n float getChannel(vec4 frag, vec2 innerDims) {\n vec2 modCoord = mod(innerDims, 2.);\n return modCoord.x == 0. ?\n (modCoord.y == 0. ? frag.r : frag.g) :\n (modCoord.y == 0. ? frag.b : frag.a);\n }\n float getChannel(vec4 frag, int dim) {\n float modCoord = mod(float(dim), 2.);\n return modCoord == 0. ? frag.r : frag.g;\n }\n";function va(t){return"offset"+t}function ya(t){var e=t.name,n=I(t.shapeInfo.logicalShape);return n<2?"return "+e+";":"\n for (int i = 0; i < "+n+"; i++) {\n if (i == index) {\n return "+e+"[i];\n }\n }\n "}function ba(t){if(t<=1)return"int";if(2===t)return"ivec2";if(3===t)return"ivec3";if(4===t)return"ivec4";if(5===t)return"ivec5";if(6===t)return"ivec6";throw Error("GPU for rank "+t+" is not yet supported")}function xa(t,e){var n=JSON.parse(JSON.stringify(t));return n.shapeInfo.logicalShape=e,n}function wa(t,e){return e.map(function(e){return t[e]}).join(", ")}var ka=function(t,e,n){this.variableNames=["AReal","AImag","BReal","BImag"],this.outputShape=Ci(e,n),this.userCode="\n float binaryOpComplex(\n float areal, float aimag, float breal, float bimag) {\n "+t+"\n }\n\n void main() {\n float areal = getARealAtOutCoords();\n float aimag = getAImagAtOutCoords();\n float breal = getBRealAtOutCoords();\n float bimag = getBImagAtOutCoords();\n setOutput(binaryOpComplex(areal, aimag, breal, bimag));\n }\n "},_a="return a + b;",Ea="return a - b;",Oa="return a * b;",Sa="return (a < 0.) ? b * a : a;",Ca=function(t,e,n){this.variableNames=["A","B"],this.outputShape=Ci(e,n),this.userCode="\n float binaryOperation(float a, float b) {\n "+t+"\n }\n\n void main() {\n float a = getAAtOutCoords();\n float b = getBAtOutCoords();\n setOutput(binaryOperation(a, b));\n }\n "},Aa="\n vec4 aLessThanZero = vec4(lessThan(a, vec4(0.)));\n return (aLessThanZero * (b * a)) + ((vec4(1.0) - aLessThanZero) * a);\n",Na=function(t,e,n,r){void 0===r&&(r=!1),this.variableNames=["A","B"],this.supportsBroadcasting=!0,this.packedInputs=!0,this.packedOutput=!0,this.outputShape=Ci(e,n);var i=this.outputShape.length,a="";if(r)if(0===i||1===I(this.outputShape))a="\n result.y = 0.;\n result.z = 0.;\n result.w = 0.;\n ";else if(a="\n "+ba(i)+" coords = getOutputCoords();\n ",1===i)a+="\n result.y = (coords + 1) >= "+this.outputShape[0]+" ? 0. : result.y;\n result.z = 0.;\n result.w = 0.;\n ";else{var o=sa("coords",i);a+="\n bool nextRowOutOfBounds =\n ("+o[i-2]+" + 1) >= "+this.outputShape[i-2]+";\n bool nextColOutOfBounds =\n ("+o[i-1]+" + 1) >= "+this.outputShape[i-1]+";\n result.y = nextColOutOfBounds ? 0. : result.y;\n result.z = nextRowOutOfBounds ? 0. : result.z;\n result.w = nextColOutOfBounds || nextRowOutOfBounds ? 0. : result.w;\n "}this.userCode="\n vec4 binaryOperation(vec4 a, vec4 b) {\n "+t+"\n }\n\n void main() {\n vec4 a = getAAtOutCoords();\n vec4 b = getBAtOutCoords();\n\n vec4 result = binaryOperation(a, b);\n "+a+"\n\n setOutput(result);\n }\n "},Ta=function(){function t(t){this.variableNames=["A"],this.outputShape=t,this.userCode="\n uniform float minVal;\n uniform float maxVal;\n\n void main() {\n float value = getAAtOutCoords();\n if (isnan(value)) {\n setOutput(value);\n return;\n }\n\n setOutput(clamp(value, minVal, maxVal));\n }\n "}return t.prototype.getCustomSetupFunc=function(t,e){var n=this;return function(r,i){null==n.minLoc&&(n.minLoc=r.getUniformLocationNoThrow(i,"minVal"),n.maxLoc=r.getUniformLocationNoThrow(i,"maxVal")),r.gl.uniform1f(n.minLoc,t),r.gl.uniform1f(n.maxLoc,e)}},t}(),Ia=function(){function t(t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t,this.userCode="\n uniform float minVal;\n uniform float maxVal;\n\n void main() {\n vec4 value = getAAtOutCoords();\n\n if (any(isnan(value))) {\n setOutput(value);\n return;\n }\n\n setOutput(clamp(value, vec4(minVal), vec4(maxVal)));\n }\n "}return t.prototype.getCustomSetupFunc=function(t,e){var n=this;return function(r,i){null==n.minLoc&&(n.minLoc=r.getUniformLocationNoThrow(i,"minVal"),n.maxLoc=r.getUniformLocationNoThrow(i,"maxVal")),r.gl.uniform1f(n.minLoc,t),r.gl.uniform1f(n.maxLoc,e)}},t}();function Da(t,e,n){var r=t.indexOf(e);return t.map(function(t,e){return e===r?t+" - "+n:t}).join()}var Ma=function(t,e,n,r){void 0===e&&(e=!1),void 0===n&&(n=null),void 0===r&&(r=!1),this.variableNames=["x","W"],this.outputShape=t.outShape;var i=t.padInfo.top,a=t.padInfo.left,o=t.strideHeight,s=t.strideWidth,u=t.dilationHeight,c=t.dilationWidth,l=t.filterHeight,f=t.filterWidth,d=4*Math.floor(t.inChannels/4),h=t.inChannels%4,p="channelsLast"===t.dataFormat,m=p?1:2,g=p?2:3,v=p?3:1,y="",b="";n&&(y=r?"float activation(float a) {\n float b = getPreluActivationWeightsAtOutCoords();\n "+n+"\n }":"\n float activation(float x) {\n "+n+"\n }\n ",b="result = activation(result);");var x=e?"result += getBiasAtOutCoords();":"";e&&this.variableNames.push("bias"),r&&this.variableNames.push("preluActivationWeights"),this.userCode="\n "+y+"\n\n const ivec2 strides = ivec2("+o+", "+s+");\n const ivec2 pads = ivec2("+i+", "+a+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d2 = coords["+v+"];\n\n ivec2 xRCCorner =\n ivec2(coords["+m+"], coords["+g+"]) * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // Convolve x(?, ?, d1) with w(:, :, d1, d2) to get y(yR, yC, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < "+l+"; wR++) {\n int xR = xRCorner + wR * "+u+";\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int wC = 0; wC < "+f+"; wC++) {\n int xC = xCCorner + wC * "+c+";\n\n if (xC < 0 || xC >= "+t.inWidth+") {\n continue;\n }\n\n for (int d1 = 0; d1 < "+d+"; d1 += 4) {\n vec4 wValues = vec4(\n getW(wR, wC, d1, d2),\n getW(wR, wC, d1 + 1, d2),\n getW(wR, wC, d1 + 2, d2),\n getW(wR, wC, d1 + 3, d2)\n );\n\n if ("+p+") {\n vec4 xValues = vec4(\n getX(batch, xR, xC, d1),\n getX(batch, xR, xC, d1 + 1),\n getX(batch, xR, xC, d1 + 2),\n getX(batch, xR, xC, d1 + 3)\n );\n dotProd += dot(xValues, wValues);\n } else {\n vec4 xValues = vec4(\n getX(batch, d1, xR, xC),\n getX(batch, d1 + 1, xR, xC),\n getX(batch, d1 + 2, xR, xC),\n getX(batch, d1 + 3, xR, xC)\n );\n dotProd += dot(xValues, wValues);\n }\n }\n\n if ("+(1===h)+") {\n\n if ("+p+") {\n dotProd +=\n getX(batch, xR, xC, "+d+") *\n getW(wR, wC, "+d+", d2);\n } else {\n dotProd +=\n getX(batch, "+d+", xR, xC) *\n getW(wR, wC, "+d+", d2);\n }\n\n } else if ("+(2===h)+") {\n vec2 wValues = vec2(\n getW(wR, wC, "+d+", d2),\n getW(wR, wC, "+d+" + 1, d2)\n );\n\n if ("+p+") {\n vec2 xValues = vec2(\n getX(batch, xR, xC, "+d+"),\n getX(batch, xR, xC, "+d+" + 1)\n );\n dotProd += dot(xValues, wValues);\n } else {\n vec2 xValues = vec2(\n getX(batch, "+d+", xR, xC),\n getX(batch, "+d+" + 1, xR, xC)\n );\n dotProd += dot(xValues, wValues);\n }\n\n } else if ("+(3===h)+") {\n vec3 wValues = vec3(\n getW(wR, wC, "+d+", d2),\n getW(wR, wC, "+d+" + 1, d2),\n getW(wR, wC, "+d+" + 2, d2)\n );\n\n if ("+p+") {\n vec3 xValues = vec3(\n getX(batch, xR, xC, "+d+"),\n getX(batch, xR, xC, "+d+" + 1),\n getX(batch, xR, xC, "+d+" + 2)\n );\n dotProd += dot(xValues, wValues);\n } else {\n vec3 xValues = vec3(\n getX(batch, "+d+", xR, xC),\n getX(batch, "+d+" + 1, xR, xC),\n getX(batch, "+d+" + 2, xR, xC)\n );\n dotProd += dot(xValues, wValues);\n }\n\n }\n }\n }\n\n float result = dotProd;\n "+x+"\n "+b+"\n setOutput(result);\n }\n "},Ra=function(t,e,n,r){void 0===e&&(e=!1),void 0===n&&(n=null),void 0===r&&(r=!1),this.variableNames=["x","W"],this.outputShape=t.outShape;var i=t.inHeight,a=t.inWidth,o=t.padInfo.top,s=t.padInfo.left,u=t.strideHeight,c=t.strideWidth,l=t.dilationHeight,f=t.dilationWidth,d=t.filterHeight,h=t.filterWidth,p=t.outChannels/t.inChannels,m="",g="";n&&(m=r?"float activation(float a) {\n float b = getPreluActivationWeightsAtOutCoords();\n "+n+"\n }":"\n float activation(float x) {\n "+n+"\n }\n ",g="result = activation(result);");var v=e?"result += getBiasAtOutCoords();":"";e&&this.variableNames.push("bias"),r&&this.variableNames.push("preluActivationWeights"),this.userCode="\n "+m+"\n\n const ivec2 strides = ivec2("+u+", "+c+");\n const ivec2 pads = ivec2("+o+", "+s+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords.x;\n ivec2 xRCCorner = coords.yz * strides - pads;\n int d2 = coords.w;\n int d1 = d2 / "+p+";\n int q = d2 - d1 * "+p+";\n\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // Convolve x(?, ?, d1) with w(:, :, d1, q) to get y(yR, yC, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n // TO DO(dsmilkov): Flatten the two for loops and vec4 the operations.\n for (int wR = 0; wR < "+d+"; wR++) {\n int xR = xRCorner + wR * "+l+";\n\n if (xR < 0 || xR >= "+i+") {\n continue;\n }\n\n for (int wC = 0; wC < "+h+"; wC++) {\n int xC = xCCorner + wC * "+f+";\n\n if (xC < 0 || xC >= "+a+") {\n continue;\n }\n\n float xVal = getX(batch, xR, xC, d1);\n float wVal = getW(wR, wC, d1, q);\n dotProd += xVal * wVal;\n }\n }\n\n float result = dotProd;\n "+v+"\n "+g+"\n setOutput(result);\n }\n "},Fa=function(t,e,n,r){void 0===e&&(e=!1),void 0===n&&(n=null),void 0===r&&(r=!1),this.variableNames=["x","W"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t.outShape;for(var i=t.inHeight,a=t.inWidth,o=t.padInfo.top,s=t.padInfo.left,u=t.strideHeight,c=t.strideWidth,l=t.dilationHeight,f=t.dilationWidth,d=t.filterHeight,h=t.filterWidth,p=h,m="int xR; int xC; int xCOffset;",g=0;g<d;g++)for(var v=0;v<h;v++)m+="\n vec4 xTexelR"+g+"C"+2*v+" = vec4(0.);\n vec4 wR"+g+"C"+v+" = vec4(0.);\n vec4 xR"+g+"C"+v+" = vec4(0.);";for(g=0;g<d;g++)for(var y=0;y<p;y++){if(m+="\n xR = xRCorner + "+g*l+";\n xC = xCCorner + "+(v=2*y)*f+";\n ",1===c){if(v<h&&(m+=s%2==1?"\n xCOffset = xC + 1;\n if(xR >= 0 && xR < "+i+" && xCOffset >= 0 && xCOffset < "+a+") {\n xTexelR"+g+"C"+v+" = getX(batch, xR, xCOffset, d1);\n\n // Need to manually clear unused channels in case\n // we're reading from recycled texture.\n if(xCOffset + 1 >= "+a+") {\n xTexelR"+g+"C"+v+".zw = vec2(0.);\n }\n } else {\n xTexelR"+g+"C"+v+" = vec4(0.);\n }\n\n xCOffset = xC + 1 - 2;\n if(xR >= 0 && xR < "+i+" && xCOffset >= 0 && xCOffset < "+a+") {\n vec4 previous = getX(batch, xR, xCOffset, d1);\n\n // Need to manually clear unused channels in case\n // we're reading from recycled texture.\n if(xCOffset + 1 >= "+a+") {\n previous.zw = vec2(0.);\n }\n\n xR"+g+"C"+v+" = vec4(previous.zw, xTexelR"+g+"C"+v+".xy);\n } else {\n xR"+g+"C"+v+" = vec4(0, 0, xTexelR"+g+"C"+v+".xy);\n }\n ":"\n if(xR >= 0 && xR < "+i+" && xC >= 0 && xC < "+a+") {\n xTexelR"+g+"C"+v+" = getX(batch, xR, xC, d1);\n } else {\n xTexelR"+g+"C"+v+" = vec4(0.);\n }\n\n xR"+g+"C"+v+" = xTexelR"+g+"C"+v+";\n ",v+1<h)){var b=s%2==0?O(f):f;f%2==0&&s%2==1||f%2!=0&&s%2!=1?(m+="\n xCOffset = xC + "+s%2+" + "+b+";\n\n if(xR >= 0 && xR < "+i+" &&\n xCOffset >= 0 && xCOffset < "+a+") {\n xTexelR"+g+"C"+(v+2)+" = getX(batch, xR, xCOffset, d1);\n }\n ",f>1&&(m+="\n xCOffset -= 2;\n if(xR >= 0 && xR < "+i+" &&\n xCOffset >= 0 && xCOffset < "+a+") {\n xTexelR"+g+"C"+v+" = getX(batch, xR, xCOffset, d1);\n } else {\n xTexelR"+g+"C"+v+" = vec4(0.);\n }\n "),m+="\n xR"+g+"C"+(v+1)+" = vec4(\n xTexelR"+g+"C"+v+".zw, xTexelR"+g+"C"+(v+2)+".xy);\n "):m+="\n xCOffset = xC + "+b+";\n\n if(xR >= 0 && xR < "+i+" &&\n xCOffset >= 0 && xCOffset < "+a+") {\n xTexelR"+g+"C"+(v+2)+" = getX(batch, xR, xCOffset, d1);\n }\n\n xR"+g+"C"+(v+1)+" = xTexelR"+g+"C"+(v+2)+";\n "}}else v<h&&(m+="\n if(xR >= 0 && xR < "+i+") {\n ",s%2==1?(m+="\n xCOffset = xC + 1 - "+c+";\n if(xCOffset >= 0 && xCOffset < "+a+") {\n xTexelR"+g+"C"+v+" = getX(batch, xR, xCOffset, d1);\n } else {\n xTexelR"+g+"C"+v+" = vec4(0.);\n }\n\n if(xC + 1 >= 0 && xC + 1 < "+a+") {\n xTexelR"+g+"C"+(v+2)+" = getX(batch, xR, xC + 1, d1);\n } else {\n xTexelR"+g+"C"+(v+2)+" = vec4(0.);\n }\n\n xR"+g+"C"+v+" = vec4(\n xTexelR"+g+"C"+v+".zw, xTexelR"+g+"C"+(v+2)+".zw);\n ",v+1<h&&(m+="\n vec4 final = vec4(0.);\n xCOffset = xC + 1 + "+c+";\n if(xCOffset >= 0 && xCOffset < "+a+") {\n final = getX(batch, xR, xCOffset, d1);\n }\n xR"+g+"C"+(v+1)+" = vec4(xTexelR"+g+"C"+(v+2)+".xy, final.xy);\n ")):(m+="\n if(xC >= 0 && xC < "+a+") {\n xTexelR"+g+"C"+v+" = getX(batch, xR, xC, d1);\n } else {\n xTexelR"+g+"C"+v+" = vec4(0.);\n }\n\n xCOffset = xC + "+c+";\n if(xCOffset >= 0 && xCOffset < "+a+") {\n xTexelR"+g+"C"+(v+2)+" = getX(batch, xR, xCOffset, d1);\n } else {\n xTexelR"+g+"C"+(v+2)+" = vec4(0.);\n }\n\n xR"+g+"C"+v+" = vec4(\n xTexelR"+g+"C"+v+".xy, xTexelR"+g+"C"+(v+2)+".xy);\n ",v+1<h&&(m+="\n xR"+g+"C"+(v+1)+" = vec4(\n xTexelR"+g+"C"+v+".zw, xTexelR"+g+"C"+(v+2)+".zw);\n ")),m+="}");v<h&&(m+="\n vec4 wTexelR"+g+"C"+v+" = getW("+g+", "+v+", d1, q);\n wR"+g+"C"+v+" = vec4(wTexelR"+g+"C"+v+".xz, wTexelR"+g+"C"+v+".xz);\n ",v+1<h&&(m+="\n vec4 wTexelR"+g+"C"+(v+1)+" = getW("+g+", "+(v+1)+", d1, q);\n wR"+g+"C"+(v+1)+" =\n vec4(wTexelR"+g+"C"+(v+1)+".xz, wTexelR"+g+"C"+(v+1)+".xz);"))}for(g=0;g<d;g++)for(v=0;v<h;v++)m+="dotProd += xR"+g+"C"+v+" * wR"+g+"C"+v+";";var x="",w="";n&&(x=r?"vec4 activation(vec4 a) {\n vec4 b = getPreluActivationWeightsAtOutCoords();\n "+n+"\n }":"vec4 activation(vec4 x) {\n "+n+"\n }",w="result = activation(result);");var k=e?"result += getBiasAtOutCoords();":"";e&&this.variableNames.push("bias"),r&&this.variableNames.push("preluActivationWeights"),this.userCode="\n "+x+"\n\n const ivec2 strides = ivec2("+u+", "+c+");\n const ivec2 pads = ivec2("+o+", "+s+");\n\n void main() {\n\n ivec4 coords = getOutputCoords();\n int batch = coords.x;\n ivec2 xRCCorner = coords.yz * strides - pads;\n int d2 = coords.w;\n int d1 = d2;\n int q = 0;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n vec4 dotProd = vec4(0.);\n\n "+m+"\n\n vec4 result = dotProd;\n "+k+"\n "+w+"\n setOutput(result);\n }\n "};function ja(t,e){if(1===t)return""+e;if(2===t)return e+".y";if(3===t)return e+".z";if(4===t)return e+".w";throw Error("Cumulative sum for rank "+t+" is not yet supported")}var Pa=function(){function t(t,e,n){this.variableNames=["x"],this.outputShape=[],this.outputShape=t,this.blockSize=e,this.dataFormat=n,this.userCode="\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int h = "+this.getHeightCoordString()+";\n int w = "+this.getWidthCoordString()+";\n int d = "+this.getDepthCoordString()+";\n\n int in_h = h / "+e+";\n int offset_h = imod(h, "+e+");\n int in_w = w / "+e+";\n int offset_w = imod(w, "+e+");\n int offset_d = (offset_h * "+e+" + offset_w) *\n "+this.getOutputDepthSize()+";\n int in_d = d + offset_d;\n\n float result = "+this.getInputSamplingString()+";\n setOutput(result);\n }\n "}return t.prototype.getHeightCoordString=function(){return"NHWC"===this.dataFormat?"coords[1]":"coords[2]"},t.prototype.getWidthCoordString=function(){return"NHWC"===this.dataFormat?"coords[2]":"coords[3]"},t.prototype.getDepthCoordString=function(){return"NHWC"===this.dataFormat?"coords[3]":"coords[1]"},t.prototype.getOutputDepthSize=function(){return"NHWC"===this.dataFormat?this.outputShape[3]:this.outputShape[1]},t.prototype.getInputSamplingString=function(){return"NHWC"===this.dataFormat?"getX(b, in_h, in_w, in_d)":"getX(b, in_d, in_h, in_w)"},t}(),La=function(t,e,n){this.variableNames=["real","imag"];var r=e[1];this.outputShape=e;var i=n?"2.0 * "+Math.PI:"-2.0 * "+Math.PI,a=n?r+".0":"1.0";this.userCode="\n const float exponentMultiplier = "+i+";\n\n float unaryOpComplex(float real, float expR, float imag, float expI) {\n "+t+"\n }\n\n float mulMatDFT(int batch, int index) {\n float indexRatio = float(index) / float("+r+");\n float exponentMultiplierTimesIndexRatio =\n exponentMultiplier * indexRatio;\n\n float result = 0.0;\n\n for (int i = 0; i < "+r+"; i++) {\n // x = (-2|2 * PI / N) * index * i;\n float x = exponentMultiplierTimesIndexRatio * float(i);\n float expR = cos(x);\n float expI = sin(x);\n float real = getReal(batch, i);\n float imag = getImag(batch, i);\n\n result +=\n unaryOpComplex(real, expR, imag, expI) / "+a+";\n }\n\n return result;\n }\n\n void main() {\n ivec2 coords = getOutputCoords();\n setOutput(mulMatDFT(coords[0], coords[1]));\n }\n "},za=function(){function t(t,e){this.outputShape=[],this.variableNames=["x"],this.outputShape=t,this.userCode="\n uniform float value;\n void main() {\n // Input can be obtained from uniform value.\n setOutput(value);\n }\n "}return t.prototype.getCustomSetupFunc=function(t){var e=this;return function(n,r){null==e.valueLoc&&(e.valueLoc=n.getUniformLocationNoThrow(r,"value")),n.gl.uniform1f(e.valueLoc,t)}},t}();function Ba(t,e){var n=ua();return ue(t,e,n.version+"\n precision highp float;\n "+n.attribute+" vec3 clipSpacePos;\n "+n.attribute+" vec2 uv;\n "+n.varyingVs+" vec2 resultUV;\n\n void main() {\n gl_Position = vec4(clipSpacePos, 1);\n resultUV = uv;\n }")}function Ua(t,e){return ge(t,e,new Float32Array([-1,1,0,0,1,-1,-1,0,0,0,1,1,0,1,1,1,-1,0,1,0]))}function Wa(t,e){return ve(t,e,new Uint16Array([0,1,2,2,1,3]))}function Va(t,e,n,r,i,a,o){be(n,r);var s=ye(t,e),u=t.TEXTURE_2D;return ne(t,e,function(){return t.bindTexture(u,s)}),ne(t,e,function(){return t.texParameteri(u,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE)}),ne(t,e,function(){return t.texParameteri(u,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE)}),ne(t,e,function(){return t.texParameteri(u,t.TEXTURE_MIN_FILTER,t.NEAREST)}),ne(t,e,function(){return t.texParameteri(u,t.TEXTURE_MAG_FILTER,t.NEAREST)}),ne(t,e,function(){return t.texImage2D(u,0,i,n,r,0,a,o,null)}),ne(t,e,function(){return t.bindTexture(t.TEXTURE_2D,null)}),s}function qa(t,e,n,r,i){var a=Zt(n,r);return Va(t,e,a[0],a[1],i.internalFormatFloat,i.textureFormatFloat,t.FLOAT)}function Ha(t,e,n,r,i){var a=Zt(n,r);return Va(t,e,a[0],a[1],i.internalFormatHalfFloat,i.textureFormatFloat,i.textureTypeHalfFloat)}function Ga(t,e,n,r,i){var a=Zt(n,r);return Va(t,e,a[0],a[1],t.RGBA,t.RGBA,t.UNSIGNED_BYTE)}function $a(t,e,n,r,i){var a=te(n,r);return Va(t,e,a[0],a[1],i.internalFormatPackedFloat,t.RGBA,t.FLOAT)}function Ka(t,e,n,r,i){var a=te(n,r);return Va(t,e,a[0],a[1],i.internalFormatPackedHalfFloat,t.RGBA,i.textureTypeHalfFloat)}function Xa(t,e,n,r){return ne(t,e,function(){return t.bindBuffer(t.ARRAY_BUFFER,r)}),we(t,e,n,"clipSpacePos",r,3,20,0)&&we(t,e,n,"uv",r,2,20,12)}function Ya(t,e,n,r,i,a,o){var s,u,c;ne(t,e,function(){return t.bindTexture(t.TEXTURE_2D,n)}),a instanceof Uint8Array?(s=new Uint8Array(r*i*4),u=t.UNSIGNED_BYTE,c=t.RGBA):(s=new Float32Array(r*i*4),u=t.FLOAT,c=o.internalFormatPackedFloat),s.set(a),ne(t,e,function(){return t.texImage2D(t.TEXTURE_2D,0,c,r,i,0,t.RGBA,u,s)}),ne(t,e,function(){return t.bindTexture(t.TEXTURE_2D,null)})}function Ja(t,e,n,r){ne(t,e,function(){return t.bindTexture(t.TEXTURE_2D,n)}),r.data instanceof Uint8Array?ne(t,e,function(){return t.texImage2D(t.TEXTURE_2D,0,t.RGBA,r.width,r.height,0,t.RGBA,t.UNSIGNED_BYTE,r.data)}):ne(t,e,function(){return t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,r)}),ne(t,e,function(){return t.bindTexture(t.TEXTURE_2D,null)})}function Za(t,e,n,r,i){var a=t.createBuffer();ne(t,e,function(){return t.bindBuffer(t.PIXEL_PACK_BUFFER,a)});var o=16*n*r;return ne(t,e,function(){return t.bufferData(t.PIXEL_PACK_BUFFER,o,t.STREAM_READ)}),ne(t,e,function(){return t.readPixels(0,0,r,n,t.RGBA,t.FLOAT,0)}),ne(t,e,function(){return t.bindBuffer(t.PIXEL_PACK_BUFFER,null)}),a}function Qa(t,e,n){var r=t,i=new Float32Array(n);return r.bindBuffer(r.PIXEL_PACK_BUFFER,e),r.getBufferSubData(r.PIXEL_PACK_BUFFER,0,i),r.bindBuffer(r.PIXEL_PACK_BUFFER,null),i}function to(t,e,n,r,i){var a=Zt(n,r),o=a[0],s=a[1],u=new Uint8Array(n*r*4);return ne(t,e,function(){return t.readPixels(0,0,o,s,i.downloadTextureFormat,t.UNSIGNED_BYTE,u)}),new Float32Array(u.buffer)}function eo(t,e,n,r,i,a,o,s){var u=t,c=new Float32Array(function(t,e){var n=te(a,o);return n[0]*n[1]*4}());return u.bindBuffer(u.PIXEL_PACK_BUFFER,e),u.getBufferSubData(u.PIXEL_PACK_BUFFER,0,c),u.bindBuffer(u.PIXEL_PACK_BUFFER,null),c}function no(t,e,n,r){var i=new Float32Array(n*r*4);return ne(t,e,function(){return t.readPixels(0,0,r,n,t.RGBA,t.FLOAT,i)}),i}var ro=Object.freeze({createVertexShader:Ba,createVertexBuffer:Ua,createIndexBuffer:Wa,createFloat32MatrixTexture:qa,createFloat16MatrixTexture:Ha,createUnsignedBytesMatrixTexture:Ga,createPackedMatrixTexture:$a,createFloat16PackedMatrixTexture:Ka,bindVertexProgramAttributeStreams:Xa,uploadDenseMatrixToTexture:Ya,uploadPixelDataToTexture:Ja,createBufferFromOutputTexture:Za,downloadFloat32MatrixFromBuffer:Qa,downloadByteEncodedFloatMatrixFromOutputTexture:to,downloadPackedMatrixFromBuffer:eo,downloadMatrixFromPackedOutputTexture:no}),io=function(){function t(t){this.outputTexture=null,this.program=null,this.disposed=!1,this.vertexAttrsAreBound=!1,this.itemsToPoll=[];var e=f().getNumber("WEBGL_VERSION");null!=t?(this.gl=t,Yt(e,t)):this.gl=Jt(e);var n="WEBGL_color_buffer_float";if(1===f().getNumber("WEBGL_VERSION")){if(this.textureFloatExtension=se(this.gl,this.debug,"OES_texture_float"),Ue(this.gl,"OES_texture_half_float"))this.textureHalfFloatExtension=se(this.gl,this.debug,"OES_texture_half_float");else if(f().get("WEBGL_FORCE_F16_TEXTURES"))throw new Error("GL context does not support half float textures, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true.");if(this.colorBufferFloatExtension=this.gl.getExtension(n),Ue(this.gl,"EXT_color_buffer_half_float"))this.colorBufferHalfFloatExtension=se(this.gl,this.debug,"EXT_color_buffer_half_float");else if(f().get("WEBGL_FORCE_F16_TEXTURES"))throw new Error("GL context does not support color renderable half floats, yet the environment flag WEBGL_FORCE_F16_TEXTURES is set to true.")}else if(n="EXT_color_buffer_float",Ue(this.gl,n))this.colorBufferFloatExtension=this.gl.getExtension(n);else{if(!Ue(this.gl,"EXT_color_buffer_half_float"))throw new Error("GL context does not support color renderable floats");this.colorBufferHalfFloatExtension=this.gl.getExtension("EXT_color_buffer_half_float")}this.vertexBuffer=Ua(this.gl,this.debug),this.indexBuffer=Wa(this.gl,this.debug),this.framebuffer=xe(this.gl,this.debug),this.textureConfig=ee(this.gl,this.textureHalfFloatExtension)}return Object.defineProperty(t.prototype,"debug",{get:function(){return f().getBool("DEBUG")},enumerable:!0,configurable:!0}),t.prototype.dispose=function(){var t=this;if(!this.disposed){null!=this.program&&console.warn("Disposing a GPGPUContext that still has a bound WebGLProgram. This is probably a resource leak, delete the program with GPGPUContext.deleteProgram before disposing."),null!=this.outputTexture&&console.warn("Disposing a GPGPUContext that still has a bound output matrix texture. This is probably a resource leak, delete the output matrix texture with GPGPUContext.deleteMatrixTexture before disposing.");var e=this.gl;ne(e,this.debug,function(){return e.finish()}),ne(e,this.debug,function(){return e.bindFramebuffer(e.FRAMEBUFFER,null)}),ne(e,this.debug,function(){return e.deleteFramebuffer(t.framebuffer)}),ne(e,this.debug,function(){return e.bindBuffer(e.ARRAY_BUFFER,null)}),ne(e,this.debug,function(){return e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null)}),ne(e,this.debug,function(){return e.deleteBuffer(t.indexBuffer)}),this.disposed=!0}},t.prototype.createFloat32MatrixTexture=function(t,e){return this.throwIfDisposed(),qa(this.gl,this.debug,t,e,this.textureConfig)},t.prototype.createFloat16MatrixTexture=function(t,e){return this.throwIfDisposed(),Ha(this.gl,this.debug,t,e,this.textureConfig)},t.prototype.createUnsignedBytesMatrixTexture=function(t,e){return this.throwIfDisposed(),Ga(this.gl,this.debug,t,e,this.textureConfig)},t.prototype.uploadPixelDataToTexture=function(t,e){this.throwIfDisposed(),Ja(this.gl,this.debug,t,e)},t.prototype.uploadDenseMatrixToTexture=function(t,e,n,r){this.throwIfDisposed(),Ya(this.gl,this.debug,t,e,n,r,this.textureConfig)},t.prototype.createFloat16PackedMatrixTexture=function(t,e){return this.throwIfDisposed(),Ka(this.gl,this.debug,t,e,this.textureConfig)},t.prototype.createPackedMatrixTexture=function(t,e){return this.throwIfDisposed(),$a(this.gl,this.debug,t,e,this.textureConfig)},t.prototype.deleteMatrixTexture=function(t){var e=this;this.throwIfDisposed(),this.outputTexture===t&&(Ce(this.gl,this.debug,this.framebuffer),this.outputTexture=null),ne(this.gl,this.debug,function(){return e.gl.deleteTexture(t)})},t.prototype.downloadByteEncodedFloatMatrixFromOutputTexture=function(t,e,n){var r=this;return this.downloadMatrixDriver(t,function(){return to(r.gl,r.debug,e,n,r.textureConfig)})},t.prototype.downloadPackedMatrixFromBuffer=function(t,e,n,r,i,a){return eo(this.gl,t,0,0,0,i,a,this.textureConfig)},t.prototype.downloadFloat32MatrixFromBuffer=function(t,e){return Qa(this.gl,t,e)},t.prototype.createBufferFromTexture=function(t,e,n){this.bindTextureToFrameBuffer(t);var r=Za(this.gl,this.debug,e,n,this.textureConfig);return this.unbindTextureToFrameBuffer(),r},t.prototype.createAndWaitForFence=function(){var t=this.createFence(this.gl);return this.pollFence(t)},t.prototype.createFence=function(t){var e,n,r=this;if(f().getBool("WEBGL_FENCE_API_ENABLED")){var i=t,a=i.fenceSync(i.SYNC_GPU_COMMANDS_COMPLETE,0);t.flush(),n=function(){var t=i.clientWaitSync(a,0,0);return t===i.ALREADY_SIGNALED||t===i.CONDITION_SATISFIED},e=a}else f().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")>0?(e=this.beginQuery(),this.endQuery(),n=function(){return r.isQueryAvailable(e,f().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))}):n=function(){return!0};return{query:e,isFencePassed:n}},t.prototype.downloadMatrixFromPackedTexture=function(t,e,n){var r=this;return this.downloadMatrixDriver(t,function(){return no(r.gl,r.debug,e,n)})},t.prototype.createProgram=function(t){this.throwIfDisposed();var e=this.gl,n=ce(e,this.debug,t),r=Ba(e,this.debug),i=he(e,this.debug);return ne(e,this.debug,function(){return e.attachShader(i,r)}),ne(e,this.debug,function(){return e.attachShader(i,n)}),pe(e,this.debug,i),this.debug&&me(e,this.debug,i),this.vertexAttrsAreBound||(this.setProgram(i),this.vertexAttrsAreBound=Xa(e,this.debug,this.program,this.vertexBuffer)),i},t.prototype.deleteProgram=function(t){var e=this;this.throwIfDisposed(),t===this.program&&(this.program=null),null!=t&&ne(this.gl,this.debug,function(){return e.gl.deleteProgram(t)})},t.prototype.setProgram=function(t){var e=this;this.throwIfDisposed(),this.program=t,null!=this.program&&this.debug&&me(this.gl,this.debug,this.program),ne(this.gl,this.debug,function(){return e.gl.useProgram(t)})},t.prototype.getUniformLocation=function(t,e,n){return void 0===n&&(n=!0),this.throwIfDisposed(),n?_e(this.gl,this.debug,t,e):Ee(this.gl,t,e)},t.prototype.getAttributeLocation=function(t,e){var n=this;return this.throwIfDisposed(),ne(this.gl,this.debug,function(){return n.gl.getAttribLocation(t,e)})},t.prototype.getUniformLocationNoThrow=function(t,e){return this.throwIfDisposed(),this.gl.getUniformLocation(t,e)},t.prototype.setInputMatrixTexture=function(t,e,n){this.throwIfDisposed(),this.throwIfNoProgram(),Oe(this.gl,this.debug,this.program,t,e,n)},t.prototype.setOutputMatrixTexture=function(t,e,n){this.setOutputMatrixTextureDriver(t,n,e)},t.prototype.setOutputPackedMatrixTexture=function(t,e,n){this.throwIfDisposed();var r=te(e,n),i=r[0],a=r[1];this.setOutputMatrixTextureDriver(t,i,a)},t.prototype.setOutputMatrixWriteRegion=function(t,e,n,r){this.setOutputMatrixWriteRegionDriver(n,t,r,e)},t.prototype.setOutputPackedMatrixWriteRegion=function(t,e,n,r){throw new Error("setOutputPackedMatrixWriteRegion not implemented.")},t.prototype.debugValidate=function(){null!=this.program&&me(this.gl,this.debug,this.program),Ae(this.gl)},t.prototype.executeProgram=function(){this.throwIfDisposed(),this.throwIfNoProgram();var t=this.gl;this.debug&&this.debugValidate(),ne(t,this.debug,function(){return t.drawElements(t.TRIANGLES,6,t.UNSIGNED_SHORT,0)})},t.prototype.blockUntilAllProgramsCompleted=function(){var t=this;this.throwIfDisposed(),ne(this.gl,this.debug,function(){return t.gl.finish()})},t.prototype.getQueryTimerExtension=function(){return null==this.disjointQueryTimerExtension&&(this.disjointQueryTimerExtension=se(this.gl,this.debug,2===f().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")?"EXT_disjoint_timer_query_webgl2":"EXT_disjoint_timer_query")),this.disjointQueryTimerExtension},t.prototype.getQueryTimerExtensionWebGL2=function(){return this.getQueryTimerExtension()},t.prototype.getQueryTimerExtensionWebGL1=function(){return this.getQueryTimerExtension()},t.prototype.beginQuery=function(){if(2===f().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")){var t=this.gl,e=this.getQueryTimerExtensionWebGL2(),n=t.createQuery();return t.beginQuery(e.TIME_ELAPSED_EXT,n),n}var r=this.getQueryTimerExtensionWebGL1(),i=r.createQueryEXT();return r.beginQueryEXT(r.TIME_ELAPSED_EXT,i),i},t.prototype.endQuery=function(){if(2!==f().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION")){var t=this.getQueryTimerExtensionWebGL1();t.endQueryEXT(t.TIME_ELAPSED_EXT)}else{var e=this.gl,n=this.getQueryTimerExtensionWebGL2();e.endQuery(n.TIME_ELAPSED_EXT)}},t.prototype.waitForQueryAndGetTime=function(t){return u(this,void 0,void 0,function(){var e=this;return c(this,function(n){switch(n.label){case 0:return[4,P(function(){return e.disposed||e.isQueryAvailable(t,f().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))})];case 1:return n.sent(),[2,this.getQueryTime(t,f().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION"))]}})})},t.prototype.getQueryTime=function(t,e){if(0===e)return null;if(2===e){var n=this.gl;return n.getQueryParameter(t,n.QUERY_RESULT)/1e6}var r=this.getQueryTimerExtensionWebGL1();return r.getQueryObjectEXT(t,r.QUERY_RESULT_EXT)/1e6},t.prototype.isQueryAvailable=function(t,e){if(0===e)return!0;if(2===e){var n=this.gl,r=this.getQueryTimerExtensionWebGL2(),i=n.getQueryParameter(t,n.QUERY_RESULT_AVAILABLE);return null==this.disjoint&&(this.disjoint=this.gl.getParameter(r.GPU_DISJOINT_EXT)),i&&!this.disjoint}return i=(r=this.getQueryTimerExtensionWebGL1()).getQueryObjectEXT(t,r.QUERY_RESULT_AVAILABLE_EXT),null==this.disjoint&&(this.disjoint=this.gl.getParameter(r.GPU_DISJOINT_EXT)),i&&!this.disjoint},t.prototype.pollFence=function(t){var e=this;return new Promise(function(n){e.addItemToPoll(function(){return t.isFencePassed()},function(){return n()})})},t.prototype.pollItems=function(){for(var t=function(t){for(var e=0;e<t.length&&t[e]();++e);return e-1}(this.itemsToPoll.map(function(t){return t.isDoneFn})),e=0;e<=t;++e)(0,this.itemsToPoll[e].resolveFn)();this.itemsToPoll=this.itemsToPoll.slice(t+1)},t.prototype.addItemToPoll=function(t,e){var n=this;this.itemsToPoll.push({isDoneFn:t,resolveFn:e}),this.itemsToPoll.length>1||P(function(){return n.pollItems(),0===n.itemsToPoll.length})},t.prototype.bindTextureToFrameBuffer=function(t){this.throwIfDisposed(),Se(this.gl,this.debug,t,this.framebuffer),this.debug&&Ae(this.gl)},t.prototype.unbindTextureToFrameBuffer=function(){null!=this.outputTexture?(Se(this.gl,this.debug,this.outputTexture,this.framebuffer),this.debug&&Ae(this.gl)):Ce(this.gl,this.debug,this.framebuffer)},t.prototype.downloadMatrixDriver=function(t,e){this.bindTextureToFrameBuffer(t);var n=e();return this.unbindTextureToFrameBuffer(),n},t.prototype.setOutputMatrixTextureDriver=function(t,e,n){this.throwIfDisposed();var r=this.gl;Se(r,this.debug,t,this.framebuffer),this.debug&&Ae(r),this.outputTexture=t,ne(r,this.debug,function(){return r.viewport(0,0,e,n)}),ne(r,this.debug,function(){return r.scissor(0,0,e,n)})},t.prototype.setOutputMatrixWriteRegionDriver=function(t,e,n,r){var i=this;this.throwIfDisposed(),ne(this.gl,this.debug,function(){return i.gl.scissor(t,e,n,r)})},t.prototype.throwIfDisposed=function(){if(this.disposed)throw new Error("Attempted to use disposed GPGPUContext.")},t.prototype.throwIfNoProgram=function(){if(null==this.program)throw new Error("No GPU program is currently set.")},t}();function ao(t,e){if(t.length!==e.length)throw Error("Binary was compiled with "+t.length+" inputs, but was executed with "+e.length+" inputs");t.forEach(function(t,n){var r=t.logicalShape,i=e[n],a=i.shape;if(!D(r,a))throw Error("Binary was compiled with different shapes than the current args. Shapes "+r+" and "+a+" must match");if(!t.isUniform||!i.isUniform){var o=t.texShape,s=i.isUniform?null:i.texData.texShape;if(!D(o,s))throw Error("Binary was compiled with different texture shapes than the current args. Shape "+o+" and "+s+" must match")}})}var oo=function(t,e,n,r,i,a,o){void 0===n&&(n=!1),void 0===r&&(r=!1),void 0===i&&(i=!1),void 0===a&&(a=null),void 0===o&&(o=!1),this.variableNames=["matrixA","matrixB"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e;var s=n?t[1]:t[2],u=Math.ceil(s/2),c=n?"i * 2, rc.y":"rc.y, i * 2",l=r?"rc.z, i * 2":"i * 2, rc.z",f=n?["a.xxyy","a.zzww"]:["a.xxzz","a.yyww"],d=r?["b.xzxz","b.ywyw"]:["b.xyxy","b.zwzw"],h="",p="";a&&(h=o?"vec4 activation(vec4 a) {\n vec4 b = getPreluActivationWeightsAtOutCoords();\n "+a+"\n }":"vec4 activation(vec4 x) {\n "+a+"\n }",p="result = activation(result);");var m=i?"result += getBiasAtOutCoords();":"";i&&this.variableNames.push("bias"),o&&this.variableNames.push("preluActivationWeights"),this.userCode="\n "+h+"\n\n const float sharedDimension = "+u+".0;\n\n vec4 dot2x2ARowBCol(ivec3 rc) {\n vec4 result = vec4(0);\n for (int i = 0; i < "+u+"; i++) {\n vec4 a = getMatrixA(rc.x, "+c+");\n vec4 b = getMatrixB(rc.x, "+l+");\n\n // These swizzled products need to be separately added.\n // See: https://github.com/tensorflow/tfjs/issues/1735\n result += ("+f[0]+" * "+d[0]+");\n result += ("+f[1]+" * "+d[1]+");\n }\n return result;\n }\n\n void main() {\n ivec3 rc = getOutputCoords();\n vec4 result = dot2x2ARowBCol(rc);\n\n "+m+"\n\n "+p+"\n\n setOutput(result);\n }\n "},so=function(){function t(t,e,n){this.variableNames=["probs"],this.outputShape=[t,n],this.userCode="\n uniform float seed;\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n\n float r = random(seed);\n float cdf = 0.0;\n\n for (int i = 0; i < "+(e-1)+"; i++) {\n cdf += getProbs(batch, i);\n\n if (r < cdf) {\n setOutput(float(i));\n return;\n }\n }\n\n // If no other event happened, last event happened.\n setOutput(float("+(e-1)+"));\n }\n "}return t.prototype.getCustomSetupFunc=function(t){var e=this;return function(n,r){null==e.seedLoc&&(e.seedLoc=n.getUniformLocation(r,"seed")),n.gl.uniform1f(e.seedLoc,t)}},t}(),uo=function(t,e,n){if(this.variableNames=["x"],"avg"===e&&n)throw new Error("Cannot compute positions for average pool.");var r=t.filterWidth,i=t.strideHeight,a=t.strideWidth,o=t.dilationHeight,s=t.dilationWidth,u=t.effectiveFilterHeight,c=t.effectiveFilterWidth,l=t.padInfo.top,f=t.padInfo.left;this.outputShape=t.outShape;var d="avg"===e,h="0.0";if(d||(h="-1.0 / 1e-20"),n)this.userCode="\n const ivec2 strides = ivec2("+i+", "+a+");\n const ivec2 pads = ivec2("+l+", "+f+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d = coords[3];\n\n ivec2 xRCCorner = coords.yz * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // max/min x(?, ?, d) to get y(yR, yC, d).\n // ? = to be determined\n float minMaxValue = 0.0;\n float minMaxValueFound = 0.0;\n int minMaxPosition = 0;\n float avgValue = 0.0;\n\n for (int wR = 0; wR < "+u+";\n wR += "+o+") {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int wC = 0; wC < "+c+";\n wC += "+s+") {\n int xC = xCCorner + wC;\n\n if (xC < 0 || xC >= "+t.inWidth+") {\n continue;\n }\n\n float value = getX(batch, xR, xC, d);\n\n // If a min / max value has already been found, use it. If not,\n // use the current value.\n float currMinMaxValue = mix(\n value, minMaxValue, minMaxValueFound);\n if (value >= currMinMaxValue) {\n minMaxValue = value;\n minMaxValueFound = 1.0;\n minMaxPosition = wR * "+c+" + wC;\n }\n }\n }\n setOutput(float(minMaxPosition));\n }\n ";else{var p=e+"("+e+"("+e+"(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";"avg"===e&&(p="avgValue / count");var m=4*Math.floor(r/4),g=r%4,v="\n if ("+d+") {\n avgValue += dot(values, ones);\n } else {\n minMaxValue = max(values, minMaxValue);\n }\n ";this.userCode="\n const ivec2 strides = ivec2("+i+", "+a+");\n const ivec2 pads = ivec2("+l+", "+f+");\n const float initializationValue = "+h+";\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n float count = 0.0;\n\n float getValue(int batch, int xR, int xC, int d) {\n if (xC < 0 || xC >= "+t.inWidth+") {\n return initializationValue;\n }\n count += 1.0;\n return getX(batch, xR, xC, d);\n }\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d = coords[3];\n\n ivec2 xRCCorner = coords.yz * strides - pads;\n int xRCorner = xRCCorner.x;\n int xCCorner = xRCCorner.y;\n\n // max/min x(?, ?, d) to get y(yR, yC, d).\n // ? = to be determined\n vec4 minMaxValue = vec4("+h+");\n float avgValue = 0.0;\n count = 0.0;\n\n for (int wR = 0; wR < "+u+";\n wR += "+o+") {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int wC = 0; wC < "+m+"; wC += 4) {\n int xC = xCCorner + wC * "+s+";\n\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + "+s+", d),\n getValue(batch, xR, xC + 2 * "+s+", d),\n getValue(batch, xR, xC + 3 * "+s+", d)\n );\n\n "+v+"\n }\n\n int xC = xCCorner + "+m+";\n if ("+(1===g)+") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n initializationValue,\n initializationValue,\n initializationValue\n );\n\n "+v+"\n } else if ("+(2===g)+") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + "+s+", d),\n initializationValue,\n initializationValue\n );\n\n "+v+"\n } else if ("+(3===g)+") {\n vec4 values = vec4(\n getValue(batch, xR, xC, d),\n getValue(batch, xR, xC + "+s+", d),\n getValue(batch, xR, xC + 2 * "+s+", d),\n initializationValue\n );\n\n "+v+"\n }\n }\n setOutput("+p+");\n }\n "}},co=function(t,e,n){if(this.variableNames=["x"],"avg"===e&&n)throw new Error("Cannot compute positions for average pool.");var r=t.filterWidth,i=t.strideDepth,a=t.strideHeight,o=t.strideWidth,s=t.dilationDepth,u=t.dilationHeight,c=t.dilationWidth,l=t.effectiveFilterDepth,f=t.effectiveFilterHeight,d=t.effectiveFilterWidth,h=t.padInfo.front,p=t.padInfo.top,m=t.padInfo.left;this.outputShape=t.outShape;var g="avg"===e,v="0.0";if(g||(v="-1.0 / 1e-20"),n)this.userCode="\n const ivec3 strides =\n ivec3("+i+", "+a+", "+o+");\n const ivec3 pads = ivec3("+h+", "+p+", "+m+");\n\n void main() {\n ivec5 coords = getOutputCoords();\n int batch = coords.x;\n int ch = coords.u;\n\n ivec3 xCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;\n int xDCorner = xCorner.x;\n int xRCorner = xCorner.y;\n int xCCorner = xCorner.z;\n\n // max/min x(?, ?, ?, ch) to get y(yD, yR, yC, ch).\n // ? = to be determined\n float minMaxValue = 0.0;\n float minMaxValueFound = 0.0;\n int minMaxPosition = 0;\n\n for (int wD = 0; wD < "+l+";\n wD += "+s+") {\n int xD = xDCorner + wD;\n\n if (xD < 0 || xD >= "+t.inDepth+") {\n continue;\n }\n\n for (int wR = 0; wR < "+f+";\n wR += "+u+") {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int wC = 0; wC < "+d+";\n wC += "+c+") {\n int xC = xCCorner + wC;\n\n if (xC < 0 || xC >= "+t.inWidth+") {\n continue;\n }\n\n float value = getX(batch, xD, xR, xC, ch);\n\n // If a min / max value has already been found, use it. If not,\n // use the current value.\n float currMinMaxValue = mix(\n value, minMaxValue, minMaxValueFound);\n if (value >= currMinMaxValue) {\n minMaxValue = value;\n minMaxValueFound = 1.0;\n minMaxPosition =\n wD * "+f+" * "+d+" +\n wR * "+d+" + wC;;\n }\n }\n }\n }\n setOutput(float(minMaxPosition));\n }\n ";else{var y=e+"("+e+"("+e+"(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";"avg"===e&&(y="avgValue / count");var b=4*Math.floor(r/4),x=r%4,w="\n if ("+g+") {\n avgValue += dot(values, ones);\n } else {\n minMaxValue = max(values, minMaxValue);\n }\n ";this.userCode="\n const ivec3 strides =\n ivec3("+i+", "+a+", "+o+");\n const ivec3 pads = ivec3("+h+", "+p+", "+m+");\n const float initializationValue = "+v+";\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n float count = 0.0;\n\n float getValue(int batch, int xD, int xR, int xC, int ch) {\n if (xC < 0 || xC >= "+t.inWidth+") {\n return initializationValue;\n }\n count += 1.0;\n return getX(batch, xD, xR, xC, ch);\n }\n\n void main() {\n ivec5 coords = getOutputCoords();\n int batch = coords.x;\n int ch = coords.u;\n\n ivec3 xCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;\n int xDCorner = xCorner.x;\n int xRCorner = xCorner.y;\n int xCCorner = xCorner.z;\n\n // max/min x(?, ?, ?, d) to get y(yD, yR, yC, ch).\n // ? = to be determined\n vec4 minMaxValue = vec4("+v+");\n float avgValue = 0.0;\n count = 0.0;\n\n for (int wD = 0; wD < "+l+";\n wD += "+s+") {\n int xD = xDCorner + wD;\n\n if (xD < 0 || xD >= "+t.inDepth+") {\n continue;\n }\n\n for (int wR = 0; wR < "+f+";\n wR += "+u+") {\n int xR = xRCorner + wR;\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int wC = 0; wC < "+b+"; wC += 4) {\n int xC = xCCorner + wC * "+c+";\n\n vec4 values = vec4(\n getValue(batch, xD, xR, xC, ch),\n getValue(batch, xD, xR, xC + "+c+", ch),\n getValue(batch, xD, xR, xC + 2 * "+c+", ch),\n getValue(batch, xD, xR, xC + 3 * "+c+", ch)\n );\n\n "+w+"\n }\n\n int xC = xCCorner + "+b+";\n if ("+(1===x)+") {\n vec4 values = vec4(\n getValue(batch, xD, xR, xC, ch),\n initializationValue,\n initializationValue,\n initializationValue\n );\n\n "+w+"\n } else if ("+(2===x)+") {\n vec4 values = vec4(\n getValue(batch, xD, xR, xC, ch),\n getValue(batch, xD, xR, xC + "+c+", ch),\n initializationValue,\n initializationValue\n );\n\n "+w+"\n } else if ("+(3===x)+") {\n vec4 values = vec4(\n getValue(batch, xD, xR, xC, ch),\n getValue(batch, xD, xR, xC + "+c+", ch),\n getValue(batch, xD, xR, xC + 2 * "+c+", ch),\n initializationValue\n );\n\n "+w+"\n }\n }\n setOutput("+y+");\n }\n }\n "}},lo=function(t,e,n,r,i,a,o){void 0===o&&(o=!0),this.variableNames=["updates","indices","defaultValue"],this.outputShape=a;var s=ba(i.length),u=ba(a.length),c="";1===n?c="i":2===n&&(c="i, j");var l="getIndices("+c+")",f="";1===r?f="i":2===r&&(f="i, coords[1]");var d="getUpdates("+f+")",h=e>1?"strides[j]":"strides";this.userCode="\n "+s+" strides = "+s+"("+i+");\n\n void main() {\n "+u+" coords = getOutputCoords();\n float sum = 0.0;\n bool found = false;\n for (int i = 0; i < "+t+"; i++) {\n int flattenedIndex = 0;\n for (int j = 0; j < "+e+"; j++) {\n int index = round("+l+");\n flattenedIndex += index * "+h+";\n }\n if (flattenedIndex == coords[0]) {\n sum += "+d+";\n found = true;\n }\n }\n setOutput(mix(getDefaultValue(), sum, float(found)));\n }\n "},fo=function(){function t(t){this.variableNames=["source"],this.outputShape=t,this.rank=t.length;var e,n=ba(this.rank),r="uniform int start["+this.rank+"];",i=function(t){if(1===t)return"sourceLoc";if(t<=6)return ho.slice(0,t).map(function(t){return"sourceLoc."+t}).join(",");throw Error("Slicing for rank "+t+" is not yet supported")}(this.rank);e="\n "+n+" sourceLoc;\n "+n+" coords = getOutputCoords();\n "+t.map(function(t,e){return"sourceLoc."+ho[e]+" = start["+e+"] + coords."+ho[e]+";"}).join("\n")+"\n ",this.userCode="\n "+r+"\n void main() {\n "+e+"\n setOutput(getSource("+i+"));\n }\n "}return t.prototype.getCustomSetupFunc=function(t){var e=this;if(t.length!==this.rank)throw Error("The rank ("+this.rank+") of the program must match the length of start ("+t.length+")");return function(n,r){null==e.startLoc&&(e.startLoc=n.getUniformLocationNoThrow(r,"start"),null==e.startLoc)||n.gl.uniform1iv(e.startLoc,t)}},t}(),ho=["x","y","z","w","u","v"],po=function(){function t(t){this.variableNames=["source"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t,this.rank=t.length;var e=ba(this.rank),n=sa("coords",this.rank),r=sa("sourceLoc",this.rank),i=1===this.rank?"sourceLoc":"vec2("+r.slice(-2).join()+")",a="getChannel(getSource("+r.join()+"), "+i+")",o="\n result.x = "+a+";\n if (++"+n[this.rank-1]+" < "+t[this.rank-1]+") {\n ++"+r[this.rank-1]+";\n result.y = "+a+";\n --"+r[this.rank-1]+";\n }\n ",s=1===this.rank?"":"\n --"+n[this.rank-1]+";\n if (++"+n[this.rank-2]+" < "+t[this.rank-2]+") {\n ++"+r[this.rank-2]+";\n result.z = "+a+";\n if (++"+n[this.rank-1]+" < "+t[this.rank-1]+") {\n ++"+r[this.rank-1]+";\n result.w = "+a+";\n }\n }\n ",u=this.rank<=4?"sourceLoc = coords +\n "+e+"("+t.map(function(t,e){return"start["+e+"]"}).join()+");":t.map(function(t,e){return r[e]+" = "+n[e]+" + start["+e+"];"}).join("\n");this.userCode="\n uniform int start["+this.rank+"];\n void main() {\n "+e+" coords = getOutputCoords();\n "+e+" sourceLoc;\n "+u+"\n vec4 result = vec4(0.);\n "+o+"\n "+s+"\n setOutput(result);\n }\n "}return t.prototype.getCustomSetupFunc=function(t){var e=this;if(t.length!==this.rank)throw Error("The rank ("+this.rank+") of the program must match the length of start ("+t.length+")");return function(n,r){null==e.startLoc&&(e.startLoc=n.getUniformLocationNoThrow(r,"start"),null==e.startLoc)||n.gl.uniform1iv(e.startLoc,t)}},t}(),mo=function(){function t(t){this.gpgpu=t,this.numUsedTextures=0,this.numFreeTextures=0,this.freeTextures={},this.logEnabled=!1,this.usedTextures={}}return t.prototype.acquireTexture=function(t,e,n){var r,i=go(e,n),a=vo(t,i,n);if(a in this.freeTextures||(this.freeTextures[a]=[]),a in this.usedTextures||(this.usedTextures[a]=[]),this.freeTextures[a].length>0){this.numFreeTextures--,this.numUsedTextures++,this.log();var o=this.freeTextures[a].shift();return this.usedTextures[a].push(o),o}return this.numUsedTextures++,this.log(),i===$t.PACKED_2X2_FLOAT32?r=this.gpgpu.createPackedMatrixTexture(t[0],t[1]):i===$t.PACKED_2X2_FLOAT16?r=this.gpgpu.createFloat16PackedMatrixTexture(t[0],t[1]):i===$t.UNPACKED_FLOAT32?r=this.gpgpu.createFloat32MatrixTexture(t[0],t[1]):i===$t.UNPACKED_FLOAT16?r=this.gpgpu.createFloat16MatrixTexture(t[0],t[1]):i===$t.PACKED_4X1_UNSIGNED_BYTE&&(r=this.gpgpu.createUnsignedBytesMatrixTexture(t[0],t[1])),this.usedTextures[a].push(r),r},t.prototype.releaseTexture=function(t,e,n,r){if(null!=this.freeTextures){var i=vo(e,go(n,r),r);i in this.freeTextures||(this.freeTextures[i]=[]),this.freeTextures[i].push(t),this.numFreeTextures++,this.numUsedTextures--;var a=this.usedTextures[i],o=a.indexOf(t);if(o<0)throw new Error("Cannot release a texture that was never provided by this texture manager");a.splice(o,1),this.log()}},t.prototype.log=function(){if(this.logEnabled){var t=this.numFreeTextures+this.numUsedTextures;console.log("Free/Used",this.numFreeTextures+" / "+this.numUsedTextures,"("+t+")")}},t.prototype.getNumUsedTextures=function(){return this.numUsedTextures},t.prototype.getNumFreeTextures=function(){return this.numFreeTextures},t.prototype.dispose=function(){var t=this;if(null!=this.freeTextures){for(var e in this.freeTextures)this.freeTextures[e].forEach(function(e){t.gpgpu.deleteMatrixTexture(e)});for(var e in this.usedTextures)this.usedTextures[e].forEach(function(e){t.gpgpu.deleteMatrixTexture(e)});this.freeTextures=null,this.usedTextures=null,this.numUsedTextures=0,this.numFreeTextures=0}},t}();function go(t,e){if(t===Gt.UPLOAD)return $t.PACKED_2X2_FLOAT32;if(t===Gt.RENDER||null==t)return function(t){return f().getBool("WEBGL_RENDER_FLOAT32_ENABLED")?t?$t.PACKED_2X2_FLOAT32:$t.UNPACKED_FLOAT32:t?$t.PACKED_2X2_FLOAT16:$t.UNPACKED_FLOAT16}(e);if(t===Gt.DOWNLOAD||t===Gt.PIXELS)return $t.PACKED_4X1_UNSIGNED_BYTE;throw new Error("Unknown logical texture type "+t)}function vo(t,e,n){return t[0]+"_"+t[1]+"_"+e+"_"+n}var yo=1.7580993408473768,bo=1.0507009873554805,xo=function(t,e){this.variableNames=["A"],this.outputShape=t,this.userCode="\n float unaryOperation(float x) {\n "+e+"\n }\n\n void main() {\n float x = getAAtOutCoords();\n float y = unaryOperation(x);\n\n setOutput(y);\n }\n "},wo="if (isnan(x)) return x;",ko="return x;",_o="return abs(x);",Eo=wo+"\n return (x < 0.0) ? 0.0 : x;\n",Oo=wo+"\n return (x < 0.0) ? 0.0 : min(6.0, x);\n",So="return (x >= 0.0) ? x : (exp(x) - 1.0);",Co="return -x;",Ao="return ceil(x);",No="return floor(x);",To="return exp(x);",Io="return exp(x) - 1.0;",Do="return x;",Mo="return x;",Ro="\n vec4 result = x * vec4(greaterThanEqual(x, vec4(0.0)));\n bvec4 isNaN = isnan(x);\n\n result.r = isNaN.r ? x.r : result.r;\n result.g = isNaN.g ? x.g : result.g;\n result.b = isNaN.b ? x.b : result.b;\n result.a = isNaN.a ? x.a : result.a;\n\n return result;\n",Fo="\n vec4 result = min(x, vec4(6.)) * vec4(greaterThanEqual(x, vec4(0.0)));\n bvec4 isNaN = isnan(x);\n\n result.r = isNaN.r ? x.r : result.r;\n result.g = isNaN.g ? x.g : result.g;\n result.b = isNaN.b ? x.b : result.b;\n result.a = isNaN.a ? x.a : result.a;\n\n return result;\n",jo="\n vec4 result;\n\n result.r = (x.r >= 0.0) ? x.r : (exp(x.r) - 1.0);\n result.g = (x.g >= 0.0) ? x.g : (exp(x.g) - 1.0);\n result.b = (x.b >= 0.0) ? x.b : (exp(x.b) - 1.0);\n result.a = (x.a >= 0.0) ? x.a : (exp(x.a) - 1.0);\n\n return result;\n",Po=function(t,e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t,this.userCode="\n vec4 unaryOperation(vec4 x) {\n "+e+"\n }\n\n void main() {\n vec4 x = getAAtOutCoords();\n vec4 y = unaryOperation(x);\n\n setOutput(y);\n }\n "},Lo={};function zo(t,e){if(void 0===e&&(e=!1),"linear"===t)return e?Mo:ko;if("relu"===t)return e?Ro:Eo;if("elu"===t)return e?jo:So;if("relu6"===t)return e?Fo:Oo;if("prelu"===t)return e?Aa:Sa;throw new Error("Activation "+t+" has not been implemented for the WebGL backend.")}var Bo=600,Uo=function(t){function e(e){var n,r=t.call(this)||this;if(r.pendingRead=new WeakMap,r.pendingDisposal=new WeakSet,r.dataRefCount=new WeakMap,r.numBytesInGPU=0,r.uploadWaitMs=0,r.downloadWaitMs=0,r.warnedAboutMemory=!1,r.pendingDeletes=0,r.disposed=!1,!f().getBool("HAS_WEBGL"))throw new Error("WebGL is not supported on this device");if(null==e){var i=Jt(f().getNumber("WEBGL_VERSION"));r.binaryCache=(n=f().getNumber("WEBGL_VERSION"))in Lo?Lo[n]:(Lo[n]={},Lo[n]),r.gpgpu=new io(i),r.canvas=i.canvas,r.gpgpuCreatedLocally=!0}else r.gpgpu=e,r.binaryCache={},r.gpgpuCreatedLocally=!1,r.canvas=e.gl.canvas;return r.textureManager=new mo(r.gpgpu),r.numMBBeforeWarning=null==f().global.screen?1024:f().global.screen.height*f().global.screen.width*window.devicePixelRatio*Bo/1024/1024,r.texData=new ki(r,Wt),r}return s(e,t),e.prototype.numDataIds=function(){return this.texData.numDataIds()+(this.cpuBackend?this.cpuBackend.numDataIds():0)-this.pendingDeletes},e.prototype.write=function(t,e,n){if(f().getBool("DEBUG")&&this.checkNumericalProblems(t),"complex64"===n&&null!=t)throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");var r={};return this.texData.set(r,{shape:e,dtype:n,values:t,usage:Gt.UPLOAD}),r},e.prototype.move=function(t,e,n,r){if(f().getBool("DEBUG")&&this.checkNumericalProblems(e),"complex64"===r)throw new Error("Cannot write to a complex64 dtype. Please use tf.complex(real, imag).");this.texData.set(t,{shape:n,dtype:r,values:e,usage:Gt.UPLOAD})},e.prototype.readSync=function(t){var e=this.texData.get(t),n=e.values,r=e.dtype,i=e.complexTensors,a=e.slice,o=e.shape,s=e.isPacked;if(null!=a){var u;u=s?new Po(o,Do):new xo(o,Do);var c=this.runWebGLProgram(u,[{dataId:t,shape:o,dtype:r}],r),l=this.readSync(c.dataId);return this.disposeData(c.dataId),l}if(null!=n)return this.convertAndCacheOnCPU(t);if("string"===r)return n;var f,d,h=null!=this.activeTimers;return h&&(f=ot()),d="complex64"===r?qi(i.real.dataSync(),i.imag.dataSync()):this.getValuesFromTexture(t),h&&(this.downloadWaitMs+=ot()-f),this.convertAndCacheOnCPU(t,d)},e.prototype.read=function(t){return u(this,void 0,void 0,function(){var e,n,r,i,a,o,s,u,l,d,h,p,m,g,v,y,b,x,w,k,_,E;return c(this,function(c){switch(c.label){case 0:if(this.pendingRead.has(t))return e=this.pendingRead.get(t),[2,new Promise(function(t){return e.push(t)})];if(n=this.texData.get(t),r=n.values,i=n.shape,a=n.slice,o=n.dtype,s=n.complexTensors,u=n.isPacked,null!=a)return l=void 0,l=u?new Po(i,Do):new xo(i,Do),d=this.runWebGLProgram(l,[{dataId:t,shape:i,dtype:o}],o),h=this.read(d.dataId),this.disposeData(d.dataId),[2,h];if(null!=r)return[2,this.convertAndCacheOnCPU(t)];if(!f().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED")&&2===f().getNumber("WEBGL_VERSION"))throw new Error("tensor.data() with WEBGL_DOWNLOAD_FLOAT_ENABLED=false and WEBGL_VERSION=2 not yet supported.");return p=null,"complex64"!==o&&f().get("WEBGL_BUFFER_SUPPORTED")&&(m=this.decode(t),g=this.texData.get(m.dataId),p=(E=this.gpgpu).createBufferFromTexture.apply(E,[g.texture].concat(Qt(i)))),this.pendingRead.set(t,[]),"complex64"===o?[3,2]:[4,this.gpgpu.createAndWaitForFence()];case 1:c.sent(),c.label=2;case 2:return"complex64"!==o?[3,4]:[4,Promise.all([s.real.data(),s.imag.data()])];case 3:return y=c.sent(),b=y[0],x=y[1],v=qi(b,x),[3,5];case 4:null==p?v=this.getValuesFromTexture(t):(w=I(i),v=this.gpgpu.downloadFloat32MatrixFromBuffer(p,w)),c.label=5;case 5:return null!=m&&this.disposeData(m.dataId),k=this.convertAndCacheOnCPU(t,v),_=this.pendingRead.get(t),this.pendingRead.delete(t),_.forEach(function(t){return t(k)}),this.pendingDisposal.has(t)&&(this.pendingDisposal.delete(t),this.disposeData(t),this.pendingDeletes--),[2,k]}})})},e.prototype.checkNumericalProblems=function(t){if(null!=t)for(var e=0;e<t.length;e++){var n=t[e];if(!ae(n)){if(f().getBool("WEBGL_RENDER_FLOAT32_CAPABLE"))throw Error("The value "+n+" cannot be represented with your current settings. Consider enabling float32 rendering: 'tf.env().set('WEBGL_RENDER_FLOAT32_ENABLED', true);'");throw Error("The value "+n+" cannot be represented on this device.")}}},e.prototype.getValuesFromTexture=function(t){var e,n=this.texData.get(t),r=n.shape,i=n.dtype,a=n.isPacked,o=I(r);if(f().getBool("WEBGL_DOWNLOAD_FLOAT_ENABLED")){var s=this.decode(t),u=this.texData.get(s.dataId),c=(e=this.gpgpu).downloadMatrixFromPackedTexture.apply(e,[u.texture].concat(Qt(r))).subarray(0,o);return this.disposeData(s.dataId),c}var l=f().getBool("WEBGL_PACK")&&!0===a,d=l?Re(r):r,h=l?new function(t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outTexUsage=Gt.DOWNLOAD;var e=ua();this.outputShape=t,this.userCode="\n "+fa+"\n\n void main() {\n ivec3 coords = getOutputCoords();\n float x = getChannel(getAAtOutCoords(), vec2(coords.y, coords.z));\n "+e.output+" = encode_float(x);\n }\n "}(d):new function(t){this.variableNames=["A"],this.outTexUsage=Gt.DOWNLOAD;var e=ua();this.outputShape=t,this.userCode="\n "+fa+"\n\n void main() {\n float x = getAAtOutCoords();\n "+e.output+" = encode_float(x);\n }\n "}(d),p=this.runWebGLProgram(h,[{shape:d,dtype:i,dataId:t}],"float32"),m=this.texData.get(p.dataId),g=this.gpgpu.downloadByteEncodedFloatMatrixFromOutputTexture(m.texture,m.texShape[0],m.texShape[1]).subarray(0,o);return this.disposeData(p.dataId),g},e.prototype.time=function(t){return u(this,void 0,void 0,function(){var e,n,r,i,a,o,s;return c(this,function(u){switch(u.label){case 0:return e=this.activeTimers,n=[],r=!1,null==this.programTimersStack?(this.programTimersStack=n,r=!0):this.activeTimers.push(n),this.activeTimers=n,t(),i=T(this.activeTimers.map(function(t){return t.query})).filter(function(t){return null!=t}),a=T(this.activeTimers.map(function(t){return t.name})).filter(function(t){return null!=t}),this.activeTimers=e,r&&(this.programTimersStack=null),o={uploadWaitMs:this.uploadWaitMs,downloadWaitMs:this.downloadWaitMs,kernelMs:null,wallMs:null},f().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?[4,Promise.all(i)]:[3,2];case 1:return s=u.sent(),o.kernelMs=S(s),o.getExtraProfileInfo=function(){return s.map(function(t,e){return{name:a[e],ms:t}}).map(function(t){return t.name+": "+t.ms}).join(", ")},[3,3];case 2:o.kernelMs={error:"WebGL query timers are not supported in this environment."},u.label=3;case 3:return this.uploadWaitMs=0,this.downloadWaitMs=0,[2,o]}})})},e.prototype.memory=function(){return{unreliable:!1,numBytesInGPU:this.numBytesInGPU}},e.prototype.startTimer=function(){return f().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?this.gpgpu.beginQuery():{startMs:ot(),endMs:null}},e.prototype.endTimer=function(t){return f().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?(this.gpgpu.endQuery(),t):(t.endMs=ot(),t)},e.prototype.getQueryTime=function(t){return u(this,void 0,void 0,function(){var e;return c(this,function(n){return f().getNumber("WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE")>0?[2,this.gpgpu.waitForQueryAndGetTime(t)]:[2,(e=t).endMs-e.startMs]})})},e.prototype.disposeData=function(t){if(!this.pendingDisposal.has(t)){if(this.pendingRead.has(t))return this.pendingDisposal.add(t),void this.pendingDeletes++;if(this.texData.has(t)){this.releaseGPUData(t);var e=this.texData.get(t).complexTensors;null!=e&&(e.real.dispose(),e.imag.dispose()),this.texData.delete(t)}}},e.prototype.releaseGPUData=function(t){var e=this.texData.get(t),n=e.texture,r=e.dtype,i=e.texShape,a=e.usage,o=e.isPacked,s=e.slice,u=s&&s.origDataId||t,c=this.dataRefCount.get(u);c>1?this.dataRefCount.set(u,c-1):(this.dataRefCount.delete(u),null!=n&&(this.numBytesInGPU-=this.computeBytes(i,r),this.textureManager.releaseTexture(n,i,a,o)));var l=this.texData.get(t);l.texture=null,l.texShape=null,l.isPacked=!1,l.slice=null},e.prototype.getTexture=function(t){return this.uploadToGPU(t),this.texData.get(t).texture},e.prototype.getDataInfo=function(t){return this.texData.get(t)},e.prototype.getCPUBackend=function(){return f().getBool("WEBGL_CPU_FORWARD")?(null==this.cpuBackend&&(this.cpuBackend=Wt.findBackend("cpu")),this.cpuBackend):null},e.prototype.shouldExecuteOnCPU=function(t,e){var n=this;return void 0===e&&(e=128),null!=this.getCPUBackend()&&t.every(function(t){return null==n.texData.get(t.dataId).texture&&t.size<e})},e.prototype.getGPGPUContext=function(){return this.gpgpu},e.prototype.complex=function(t,e){var n=this.makeOutput(t.shape,"complex64");return this.texData.get(n.dataId).complexTensors={real:Wt.keep(t.clone()),imag:Wt.keep(e.clone())},n},e.prototype.real=function(t){return this.texData.get(t.dataId).complexTensors.real.clone()},e.prototype.imag=function(t){return this.texData.get(t.dataId).complexTensors.imag.clone()},e.prototype.slice=function(t,e,n){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.slice(t,e,n);if(0===I(n))return jn([],n,t.dtype);var r=this.texData.get(t.dataId).isPacked,i=li(t.shape,e,n);if(r||!i){var a=f().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new po(n):new fo(n),o=a.getCustomSetupFunc(e);return this.compileAndRun(a,[t],null,o)}return this.uploadToGPU(t.dataId),this.shallowSlice(t,e,n)},e.prototype.shallowSlice=function(t,e,n){var r=this.texData.get(t.dataId),i=this.makeOutput(n,t.dtype),a=this.texData.get(i.dataId);Object.assign(a,r),a.shape=n,a.dtype=t.dtype;var o=fi(e,t.strides);r.slice&&(o+=r.slice.flatOffset),a.slice={flatOffset:o,origDataId:r.slice&&r.slice.origDataId||t.dataId};var s=this.dataRefCount.get(a.slice.origDataId)||1;return this.dataRefCount.set(a.slice.origDataId,s+1),i},e.prototype.stridedSlice=function(t,e,n,r){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.stridedSlice(t,e,n,r);var i=si(e,n,r);if(i.some(function(t){return 0===t}))return jn([],i);var a=new function(t,e,n){this.variableNames=["x"],this.outputShape=n;var r=n.length,i=ba(n.length),a=ba(n.length),o="";if(1===r)o="coords * strides + begin";else{var s=0;o=n.map(function(t,e){return s++,1===n.length?"coords * strides["+e+"] + begin["+e+"]":"coords["+(s-1)+"] * strides["+e+"] + begin["+e+"]"}).join(",")}this.userCode="\n "+i+" begin = "+i+"("+t+");\n "+i+" strides = "+i+"("+e+");\n\n void main() {\n "+a+" coords = getOutputCoords();\n setOutput(getX("+o+"));\n }\n "}(e,r,i);return this.compileAndRun(a,[t])},e.prototype.reverse=function(t,e){var n=f().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new function(t,e){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0;var n=t.length;if(n>4)throw new Error("WebGL backend: Reverse of rank-"+n+" tensor is not yet supported");this.outputShape=t;var r=sa("rc",n),i=r[n-1]+" + 1 < "+this.outputShape[n-1],a=r[n-2]+" + 1 < "+this.outputShape[n-2],o=ba(n);function s(n){var r=t.map(function(r,i){return function(n,r){return-1!==e.indexOf(n)&&1!==t[n]?t[n]+" - "+r[n]+" - 1":""+r[n]}(i,n)});return"getChannel(getX("+r.join(",")+"), vec2("+r.slice(-2).join(",")+"))"}this.userCode=1===n?"\n void main(){\n int rc = getOutputCoords();\n vec4 result = vec4(0.);\n result.r = getChannel(getX("+t[0]+" - rc - 1),\n "+t[0]+" - rc - 1);\n if("+i+"){\n result.g = getChannel(getX("+t[0]+" - (rc + 1) - 1),\n "+t[0]+" - (rc + 1) - 1);\n }\n setOutput(result);\n }\n ":"\n void main() {\n "+o+" rc = getOutputCoords();\n vec4 result = vec4(0.);\n result.r = "+s(r.slice())+";\n if("+i+"){\n result.g = "+function(t){return t[n-1]="("+t[n-1]+" + 1)",s(t)}(r.slice())+";\n }\n if("+a+") {\n result.b = "+function(t){return t[n-2]="("+t[n-2]+" + 1)",s(t)}(r.slice())+";\n if("+i+") {\n result.a = "+function(t){return t[n-1]="("+t[n-1]+" + 1)",t[n-2]="("+t[n-2]+" + 1)",s(t)}(r.slice())+";\n }\n }\n setOutput(result);\n }\n "}(t.shape,e):new function(t,e){this.variableNames=["x"];var n=t.length;if(n>4)throw new Error("WebGL backend: Reverse of rank-"+n+" tensor is not yet supported");if(this.outputShape=t,1!==n){var r=t.map(function(n,r){return function(n){return-1!==e.indexOf(n)&&1!==t[n]?t[n]+" - coords["+n+"] - 1":"coords["+n+"]"}(r)}).join(","),i=ba(n);this.userCode="\n void main() {\n "+i+" coords = getOutputCoords();\n setOutput(getX("+r+"));\n }\n "}else this.userCode="\n void main() {\n int coord = getOutputCoords();\n setOutput(getX("+t[0]+" - coord - 1));\n }\n "}(t.shape,e);return this.compileAndRun(n,[t])},e.prototype.concat=function(t,e){if("complex64"===t[0].dtype){var n=t.map(function(t){return Rn(t)}),r=t.map(function(t){return Fn(t)});return Mn(this.concat(n,e),this.concat(r,e))}if(this.shouldExecuteOnCPU(t))return this.cpuBackend.concat(t,e);if(1===t.length)return t[0];if(t.length>f().getNumber("WEBGL_MAX_TEXTURES_IN_SHADER")){var i=Math.floor(t.length/2),a=this.concat(t.slice(0,i),e),o=this.concat(t.slice(i),e);return this.concat([a,o],e)}if(f().getBool("WEBGL_PACK_ARRAY_OPERATIONS")&&t[0].rank>1){var s=new function(t,e){this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[],this.outputShape=In(t,e);var n=this.outputShape,r=n.length,i=ba(r),a=sa("coords",r),o=["x","y","z","w","u","v"].slice(0,r);this.variableNames=t.map(function(t,e){return"T"+e});var s=new Array(t.length-1);s[0]=t[0][e];for(var u=1;u<s.length;u++)s[u]=s[u-1]+t[u][e];var c=o[e],l=o.slice(-2),f=o.join(),d="if ("+c+" < "+s[0]+") {\n return getChannel(\n getT0("+f+"), vec2("+l.join()+"));\n }";for(u=1;u<s.length;u++){var h=s[u-1];d+="\n if ("+c+" < "+s[u]+" && "+c+" >= "+s[u-1]+") {\n return getChannel(\n getT"+u+"("+Da(o,c,h)+"),\n vec2("+Da(l,c,h)+"));\n }"}var p=s.length,m=s[s.length-1];d+="\n return getChannel(\n getT"+p+"("+Da(o,c,m)+"),\n vec2("+Da(l,c,m)+"));",this.userCode="\n float getValue("+o.map(function(t){return"int "+t})+") {\n "+d+"\n }\n\n void main() {\n "+i+" coords = getOutputCoords();\n vec4 result = vec4(getValue("+a+"), 0., 0., 0.);\n\n "+a[r-1]+" = "+a[r-1]+" + 1;\n if ("+a[r-1]+" < "+n[r-1]+") {\n result.g = getValue("+a+");\n }\n\n "+a[r-2]+" = "+a[r-2]+" + 1;\n if ("+a[r-2]+" < "+n[r-2]+") {\n result.a = getValue("+a+");\n }\n\n "+a[r-1]+" = "+a[r-1]+" - 1;\n if ("+a[r-2]+" < "+n[r-2]+" &&\n "+a[r-1]+" < "+n[r-1]+") {\n result.b = getValue("+a+");\n }\n setOutput(result);\n }\n "}(t.map(function(t){return t.shape}),e);return this.compileAndRun(s,t)}var u=In(t.map(function(t){return t.shape}),e),c=t.map(function(t){return t.as2D(-1,I(t.shape.slice(e)))}),l=new function(t){this.outputShape=[],this.outputShape=In(t,1),this.variableNames=t.map(function(t,e){return"T"+e});var e=new Array(t.length-1);e[0]=t[0][1];for(var n=1;n<e.length;n++)e[n]=e[n-1]+t[n][1];var r=["if (yC < "+e[0]+") setOutput(getT0(yR, yC));"];for(n=1;n<e.length;n++){var i=e[n-1];r.push("else if (yC < "+e[n]+") setOutput(getT"+n+"(yR, yC-"+i+"));")}var a=e.length,o=e[e.length-1];r.push("else setOutput(getT"+a+"(yR, yC-"+o+"));"),this.userCode="\n void main() {\n ivec2 coords = getOutputCoords();\n int yR = coords.x;\n int yC = coords.y;\n\n "+r.join("\n ")+"\n }\n "}(c.map(function(t){return t.shape}));return this.compileAndRun(l,c).reshape(u)},e.prototype.neg=function(t){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.neg(t);if(f().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(t,Co,t.dtype);var e=new xo(t.shape,Co);return this.compileAndRun(e,[t])},e.prototype.batchMatMul=function(t,e,n,r){var i=n?t.shape[2]:t.shape[1],a=r?e.shape[1]:e.shape[2],o=n?t.shape[1]:t.shape[2],s=t.shape[0];if((1===i||1===a)&&o>1e3){n&&(t=t.transpose([0,2,1])),r&&(e=e.transpose([0,2,1]));var u=1===a?t:t.as3D(s,o,1),c=1===a?2:1,l=1===a?e.as3D(s,1,o):e;return this.multiply(u,l).sum(c,!0)}var f=Mt(t.dtype,e.dtype),d=new oo(t.shape,[s,i,a],n,r);return this.compileAndRun(d,[t,e],f)},e.prototype.fusedBatchMatMul=function(t){var e=t.a,n=t.b,r=t.transposeA,i=t.transposeB,a=t.bias,o=t.activation,s=t.preluActivationWeights,u=r?e.shape[2]:e.shape[1],c=i?n.shape[1]:n.shape[2],l=e.shape[0],f=Mt(e.dtype,n.dtype),d=null!=a,h=null!=s,p=o?zo(o,!0):null,m=new oo(e.shape,[l,u,c],r,i,d,p,h),g=[e,n];return a&&g.push(a),s&&g.push(s),this.compileAndRun(m,g,f)},e.prototype.multiply=function(t,e){if("complex64"===t.dtype){var n=this.texData.get(t.dataId),r=this.texData.get(e.dataId),i=new ka("return areal * breal - aimag * bimag;",t.shape,e.shape),a=new ka("return areal * bimag + aimag * breal;",t.shape,e.shape),o=[this.makeComplexComponentTensorInfo(t,n.complexTensors.real),this.makeComplexComponentTensorInfo(t,n.complexTensors.imag),this.makeComplexComponentTensorInfo(e,r.complexTensors.real),this.makeComplexComponentTensorInfo(e,r.complexTensors.imag)],s=this.compileAndRun(i,o),u=this.compileAndRun(a,o),c=this.complex(s,u);return s.dispose(),u.dispose(),c}if(this.shouldExecuteOnCPU([t,e]))return this.cpuBackend.multiply(t,e);if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,Oa,t.dtype);var l=new Ca(Oa,t.shape,e.shape);return this.compileAndRun(l,[t,e],t.dtype)},e.prototype.batchNormalization=function(t,e,n,r,i,a){var o=[t,e,n],s=null;null!=a&&(s=a.shape,o.push(a));var u=null;if(null!=i&&(u=i.shape,o.push(i)),f().getBool("WEBGL_PACK_NORMALIZATION")){var c=new function(t,e,n,r,i,a){this.packedInputs=!0,this.packedOutput=!0,this.variableNames=["x","mean","variance"],Ci(t,e),Ci(t,n);var o="vec4(0.0)";null!=r&&(Ci(t,r),this.variableNames.push("offset"),o="getOffsetAtOutCoords()");var s="vec4(1.0)";null!=i&&(Ci(t,i),this.variableNames.push("scale"),s="getScaleAtOutCoords()"),this.outputShape=t,this.userCode="\n void main() {\n vec4 offset = "+o+";\n vec4 scale = "+s+";\n\n vec4 x = getXAtOutCoords();\n vec4 mean = getMeanAtOutCoords();\n vec4 variance = getVarianceAtOutCoords();\n\n vec4 inv = scale * inversesqrt(variance + vec4("+a+"));\n\n setOutput((x - mean) * inv + offset);\n }\n "}(t.shape,e.shape,n.shape,s,u,r);return this.compileAndRun(c,o)}var l=new function(t,e,n,r,i,a){this.outputShape=[],this.variableNames=["x","mean","variance"],Ci(t,e),Ci(t,n);var o="0.0";null!=r&&(Ci(t,r),this.variableNames.push("offset"),o="getOffsetAtOutCoords()");var s="1.0";null!=i&&(Ci(t,i),this.variableNames.push("scale"),s="getScaleAtOutCoords()"),this.outputShape=t,this.userCode="\n void main() {\n float x = getXAtOutCoords();\n float mean = getMeanAtOutCoords();\n float variance = getVarianceAtOutCoords();\n float offset = "+o+";\n float scale = "+s+";\n float inv = scale * inversesqrt(variance + float("+a+"));\n setOutput(dot(vec3(x, -mean, offset), vec3(inv, inv, 1)));\n }\n "}(t.shape,e.shape,n.shape,s,u,r);return this.compileAndRun(l,o)},e.prototype.localResponseNormalization4D=function(t,e,n,r,i){var a=f().getBool("WEBGL_PACK_NORMALIZATION")?new function(t,e,n,r,i){this.variableNames=["x"],this.outputShape=[],this.packedInputs=!0,this.packedOutput=!0;var a,o=e,s=t[3]-1;this.outputShape=t;var u="float("+n+") + float("+r+") * sum";a=.5===i?"inversesqrt("+u+")":1===i?"1.0/("+u+")":"exp(log("+u+") * float(-"+i+"));",this.userCode="\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords.x;\n int r = coords.y;\n int c = coords.z;\n int d = coords.w;\n\n bool hasNextCol = d < "+this.outputShape[3]+";\n bool hasNextRow = c < "+this.outputShape[2]+";\n\n vec4 sum = vec4(0.);\n vec4 xFragAtOutputCoords = getX(b, r, c, d);\n\n vec4 xAtOutputCoords = vec4(\n getChannel(xFragAtOutputCoords, vec2(c, d)),\n hasNextCol ?\n getChannel(xFragAtOutputCoords, vec2(c, d + 1)) : 0.0,\n hasNextRow ?\n getChannel(xFragAtOutputCoords , vec2(c + 1, d)) : 0.0,\n (hasNextRow && hasNextCol) ?\n getChannel(xFragAtOutputCoords, vec2(c + 1, d + 1)) : 0.0\n );\n\n int firstChannel = d - "+o+";\n vec2 cache = vec2(0.);\n if(firstChannel >= 0){\n vec4 firstChannelFrag = getX(b, r, c, firstChannel);\n cache.x = getChannel(firstChannelFrag, vec2(c, firstChannel));\n if(hasNextRow){\n cache.y = getChannel(firstChannelFrag, vec2(c + 1, firstChannel));\n }\n }\n\n ivec2 depth = ivec2(d, d + 1);\n for (int j = - "+o+"; j <= "+o+"; j++) {\n ivec2 idx = depth + j;\n bvec2 aboveLowerBound = greaterThanEqual(idx, ivec2(0));\n bvec2 belowUpperBound = lessThanEqual(idx, ivec2("+s+"));\n\n bool depthInRange = aboveLowerBound.x && belowUpperBound.x;\n bool depthPlusOneInRange = aboveLowerBound.y && belowUpperBound.y;\n\n if(depthInRange || depthPlusOneInRange){\n vec4 z = vec4(0.);\n vec4 xFragAtCurrentDepth;\n z.xz = cache.xy;\n if(depthPlusOneInRange && hasNextCol){\n xFragAtCurrentDepth = idx.y != d ?\n getX(b, r, c, idx.y) : xFragAtOutputCoords;\n z.y = getChannel(xFragAtCurrentDepth, vec2(c, idx.y));\n if(hasNextRow){\n z.w = getChannel(xFragAtCurrentDepth, vec2(c + 1, idx.y));\n }\n }\n cache.xy = z.yw;\n sum += z * z;\n }\n }\n vec4 result = xAtOutputCoords * "+a+";\n setOutput(result);\n }\n "}(t.shape,e,n,r,i):new function(t,e,n,r,i){this.variableNames=["x"],this.outputShape=[];var a,o=e,s=t[3]-1;this.outputShape=t;var u="float("+n+") + float("+r+") * sum";a=.5===i?"inversesqrt("+u+")":1===i?"1.0/("+u+")":"exp(log("+u+") * float(-"+i+"));",this.userCode="\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int r = coords[1];\n int c = coords[2];\n int d = coords[3];\n float x = getX(b, r, c, d);\n float sum = 0.0;\n for (int j = -"+o+"; j <= "+o+"; j++) {\n int idx = d + j;\n if (idx >= 0 && idx <= "+s+") {\n float z = getX(b, r, c, idx);\n sum += z * z;\n }\n }\n float val = x * "+a+";\n setOutput(val);\n }\n "}(t.shape,e,n,r,i);return this.compileAndRun(a,[t])},e.prototype.LRNGrad=function(t,e,n,r,i,a,o){var s=new function(t,e,n,r,i){this.variableNames=["inputImage","outputImage","dy"],this.outputShape=[],this.outputShape=t,this.depth=t[3],this.depthRadius=e,this.bias=n,this.alpha=r,this.beta=i,this.userCode="\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int r = coords[1];\n int c = coords[2];\n\n float result = 0.0;\n for (int d = 0; d < "+this.depth+"; ++d) {\n int depthBegin = int(max(0.0, float(d - "+e+")));\n int depthEnd = int(min(float("+this.depth+"),\n float(d + "+e+" + 1)));\n\n const int MIN_DEPTH_BEGIN = 0;\n const int MAX_DEPTH_END = "+this.depth+";\n\n float norm = 0.0;\n for (int k = MIN_DEPTH_BEGIN; k < MAX_DEPTH_END; ++k) {\n if (k < depthBegin){\n continue;\n }\n else if (k >= depthBegin && k < depthEnd) {\n norm += getInputImage(b, r, c, k) * getInputImage(b, r, c, k);\n }\n else {\n break;\n }\n }\n\n norm = float("+r+") * norm + float("+n+");\n\n for(int k = MIN_DEPTH_BEGIN; k < MAX_DEPTH_END; ++k){\n if (k < depthBegin){\n continue;\n }\n else if (k >= depthBegin && k < depthEnd){\n float dyi = -2.0 * float("+r+")\n * float("+i+")\n * getInputImage(b ,r ,c, k) * getOutputImage(b, r, c, d)\n / norm;\n if (k == d) {\n dyi += pow(norm, -1.0 * "+i+");\n }\n if (k == coords[3]) {\n dyi *= getDy(b, r, c, d);\n result += dyi;\n }\n }\n else {\n break;\n }\n }\n }\n setOutput(result);\n }\n "}(e.shape,r,i,a,o);return this.compileAndRun(s,[e,n,t])},e.prototype.tile=function(t,e){if("string"===t.dtype){var n=this.readSync(t.dataId).map(function(t){return ct(t)});return ra(vr(t.shape,t.dtype,n),e)}var r=new function(t,e){this.variableNames=["A"];for(var n=new Array(t.length),r=0;r<n.length;r++)n[r]=t[r]*e[r];this.outputShape=n,this.rank=n.length;var i=ba(this.rank),a=function(t){var e=t.length;if(e>5)throw Error("Tile for rank "+e+" is not yet supported");if(1===e)return"imod(resRC, "+t[0]+")";for(var n=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u"],r=[],i=0;i<t.length;i++)r.push("imod("+n[i]+", "+t[i]+")");return r.join()}(t);this.userCode="\n void main() {\n "+i+" resRC = getOutputCoords();\n setOutput(getA("+a+"));\n }\n "}(t.shape,e);return this.compileAndRun(r,[t])},e.prototype.pad=function(t,e,n){var r=f().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new function(t,e,n){this.variableNames=["x"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=e.map(function(e,n){return e[0]+t[n]+e[1]});for(var r=t.length,i=ba(r),a=e.map(function(t){return t[0]}).join(","),o=e.map(function(e,n){return e[0]+t[n]}).join(","),s=sa("rc",r),u=sa("source",r),c=s[r-1]+" < "+this.outputShape[r-1],l=1===r?"source":"vec2("+u.slice(-2).join()+")",f=[i+" rc = outputLoc;",s[r-1]+" += 1;\n if("+c+") {\n ",1===r?"":"}\n rc = outputLoc;\n "+s[r-2]+" += 1;\n if("+s[r-2]+" < "+this.outputShape[r-2]+") {",1===r?"":" "+s[r-1]+" += 1;\n if("+c+") {"],d=1===r?"rc < start || rc >= end":"any(lessThan(rc, start)) || any(greaterThanEqual(rc, end))",h="",p=0,m=1===r?2:4;p<m;p++)h+="\n "+f[p]+"\n if ("+d+") {\n result["+p+"] = float("+n+");\n } else {\n "+i+" source = rc - start;\n result["+p+"] = getChannel(getX("+u.join()+"), "+l+");\n }\n ";h+=1===r?"} ":"}}",this.userCode="\n const "+i+" start = "+i+"("+a+");\n const "+i+" end = "+i+"("+o+");\n\n void main() {\n "+i+" outputLoc = getOutputCoords();\n vec4 result = vec4(0.);\n "+h+"\n setOutput(result);\n }\n "}(t.shape,e,n):new function(t,e,n){this.variableNames=["x"],this.outputShape=e.map(function(e,n){return e[0]+t[n]+e[1]});var r=t.length,i=ba(r),a=e.map(function(t){return t[0]}).join(","),o=e.map(function(e,n){return e[0]+t[n]}).join(","),s=["coords[0]","coords[1]","coords[2]","coords[3]"].slice(0,r);this.userCode=1!==r?"\n "+i+" start = "+i+"("+a+");\n "+i+" end = "+i+"("+o+");\n\n void main() {\n "+i+" outC = getOutputCoords();\n if (any(lessThan(outC, start)) || any(greaterThanEqual(outC, end))) {\n setOutput(float("+n+"));\n } else {\n "+i+" coords = outC - start;\n setOutput(getX("+s+"));\n }\n }\n ":"\n int start = "+a+";\n int end = "+o+";\n\n void main() {\n int outC = getOutputCoords();\n if (outC < start || outC >= end) {\n setOutput(float("+n+"));\n } else {\n setOutput(getX(outC - start));\n }\n }\n "}(t.shape,e,n);return this.compileAndRun(r,[t])},e.prototype.transpose=function(t,e){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.transpose(t,e);var n=f().getBool("WEBGL_PACK_ARRAY_OPERATIONS")?new function(t,e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0;for(var n=new Array(t.length),r=0;r<n.length;r++)n[r]=t[e[r]];if(this.outputShape=n,this.rank=n.length,this.rank>6)throw Error("Packed transpose for rank "+this.rank+" is not yet supported.");var i=ba(this.rank),a=oa("rc",this.rank),o=new Array(this.rank);for(r=0;r<e.length;r++)o[e[r]]=a[r];var s="vec2("+o.slice(-2).join()+")",u="++"+a[this.rank-1]+" < "+n[this.rank-1],c="getChannel(getA("+o.join()+"), "+s+")";this.userCode="\n void main() {\n "+i+" rc = getOutputCoords();\n vec4 result = vec4(0.);\n result[0] = "+c+";\n if("+u+") {\n result[1] = "+c+";\n }\n --"+a[this.rank-1]+";\n if(++"+a[this.rank-2]+" < "+n[this.rank-2]+") {\n result[2] = "+c+";\n if("+u+") {\n result[3] = "+c+";\n }\n }\n setOutput(result);\n }\n "}(t.shape,e):new function(t,e){this.variableNames=["A"];for(var n=new Array(t.length),r=0;r<n.length;r++)n[r]=t[e[r]];this.outputShape=n,this.rank=n.length;var i=ba(this.rank),a=function(t){var e=t.length;if(e>6)throw Error("Transpose for rank "+e+" is not yet supported");for(var n=["resRC.x","resRC.y","resRC.z","resRC.w","resRC.u","resRC.v"],r=new Array(e),i=0;i<t.length;i++)r[t[i]]=n[i];return r.join()}(e);this.userCode="\n void main() {\n "+i+" resRC = getOutputCoords();\n setOutput(getA("+a+"));\n }\n "}(t.shape,e);return this.compileAndRun(n,[t])},e.prototype.gather=function(t,e,n){if(this.shouldExecuteOnCPU([t,e]))return this.cpuBackend.gather(t,e,n);var r=new function(t,e,n){this.variableNames=["A","indices"];var r=t.slice();r[n]=e,this.outputShape=r,this.rank=r.length;var i=ba(this.rank),a=function(t,e){var n=t.length;if(n>4)throw Error("Gather for rank "+n+" is not yet supported");if(1===n)return"int(getIndices(resRC))";for(var r=["resRC.x","resRC.y","resRC.z","resRC.w"],i=[],a=0;a<t.length;a++)a===e?i.push("int(getIndices("+r[a]+"))"):i.push(""+r[a]);return i.join()}(t,n);this.userCode="\n void main() {\n "+i+" resRC = getOutputCoords();\n setOutput(getA("+a+"));\n }\n "}(t.shape,e.size,n);return this.compileAndRun(r,[t,e])},e.prototype.batchToSpaceND=function(t,e,n){C(t.rank<=4,function(){return"batchToSpaceND for rank > 4 with a WebGL backend not implemented yet"});var r=e.reduce(function(t,e){return t*e}),i=Gr(t.shape,e,r),a=$r(i.length,e.length),o=Kr(t.shape,e,r),s=Xr(n,e.length),u=Yr(o,n,e.length);return t.reshape(i).transpose(a).reshape(o).slice(s,u)},e.prototype.spaceToBatchND=function(t,e,n){C(t.rank<=4,function(){return"spaceToBatchND for rank > 4 with a WebGL backend not implemented yet"});var r=e.reduce(function(t,e){return t*e}),i=[[0,0]];i.push.apply(i,n);for(var a=1+e.length;a<t.shape.length;++a)i.push([0,0]);var o=t.pad(i),s=Gr(o.shape,e,r,!1),u=$r(s.length,e.length,!1),c=Kr(o.shape,e,r,!1);return o.reshape(s).transpose(u).reshape(c)},e.prototype.reduce=function(t,e,n){var r=t.shape[0],i=t.shape[1],a=new function(t,e){this.variableNames=["x"];var n=t.windowSize,r=t.batchSize,i=t.inSize,a=Math.ceil(i/n);this.outputShape=[r,a];var o="0.0",s="";"prod"===e?o="1.0":"min"===e?(o="1.0 / 1e-20",s="min"):"max"===e&&(o="-1.0 / 1e-20",s="max");var u=e+"("+e+"("+e+"(minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])";"sum"===e?u="sumValue":"prod"===e?u="prodValue":"all"===e?u="allValue":"any"===e&&(u="anyValue");var c=4*Math.floor(n/4),l=n%4,f="\n if ("+("sum"===e)+") {\n sumValue += dot(values, ones);\n } else if ("+("prod"===e)+") {\n vec2 tmp = vec2(values[0], values[1]) * vec2(values[2], values[3]);\n prodValue *= tmp[0] * tmp[1];\n } else {\n minMaxValue = "+s+"(values, minMaxValue);\n }\n ",d="vec4";"all"===e?(o="1.0",f="\n bool reducedAllValue = all(values);\n float floatedReducedAllValue = float(reducedAllValue);\n allValue = float(allValue >= 1.0 && floatedReducedAllValue >= 1.0);\n ",d="bvec4"):"any"===e&&(o="0.0",f="\n bool reducedAnyValue = any(values);\n float floatedReducedAnyValue = float(reducedAnyValue);\n anyValue = float(anyValue >= 1.0 || floatedReducedAnyValue >= 1.0);\n ",d="bvec4");var h="";i%n>0&&(h="\n if (inIdx < 0 || inIdx >= "+i+") {\n return initializationValue;\n }\n "),this.userCode="\n const float initializationValue = "+o+";\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\n\n float getValue(int batch, int inIdx) {\n "+h+"\n return getX(batch, inIdx);\n }\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n int outIdx = coords[1];\n int inOffset = outIdx * "+n+";\n\n vec4 minMaxValue = vec4("+o+");\n float prodValue = 1.0;\n float sumValue = 0.0;\n float allValue = 1.0;\n float anyValue = 0.0;\n\n for (int i = 0; i < "+c+"; i += 4) {\n int inIdx = inOffset + i;\n "+d+" values = "+d+"(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n getValue(batch, inIdx + 3)\n );\n\n "+f+"\n }\n\n int inIdx = inOffset + "+c+";\n if ("+(1===l)+") {\n "+d+" values = "+d+"(\n getValue(batch, inIdx),\n initializationValue,\n initializationValue,\n initializationValue\n );\n\n "+f+"\n } else if ("+(2===l)+") {\n "+d+" values = "+d+"(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n initializationValue,\n initializationValue\n );\n\n "+f+"\n } else if ("+(3===l)+") {\n "+d+" values = "+d+"(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n initializationValue\n );\n\n "+f+"\n }\n setOutput("+u+");\n }\n "}({windowSize:ti(i),inSize:i,batchSize:r},e),o=this.compileAndRun(a,[t],n);return 1===o.shape[1]?o:this.reduce(o,e,n)},e.prototype.argReduce=function(t,e,n){void 0===n&&(n=null);var r=t.shape[0],i=t.shape[1];null!=n&&(r=n.shape[0],i=n.shape[1]);var a=new function(t,e,n){this.variableNames=["A"];var r=t.windowSize,i=t.batchSize,a=t.inSize,o=Math.ceil(a/r);n||this.variableNames.push("bestIndicesA"),this.outputShape=[i,o];var s="max"===e?">":"<",u=n?"inOffset + i;":"round(getBestIndicesA(batch, inOffset + i));";this.userCode="\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n int outIdx = coords[1];\n int inOffset = outIdx * "+r+";\n\n int bestIndex = inOffset;\n float bestValue = getA(batch, bestIndex);\n\n for (int i = 0; i < "+r+"; i++) {\n int inIdx = "+u+";\n float candidate = getA(batch, inIdx);\n if (candidate "+s+" bestValue) {\n bestValue = candidate;\n bestIndex = inIdx;\n }\n }\n setOutput(float(bestIndex));\n }\n "}({windowSize:ti(i),inSize:i,batchSize:r},e,null==n),o=[t];null!=n&&o.push(n);var s=this.compileAndRun(a,o,"int32");return 1===s.shape[1]?s:this.argReduce(t,e,s)},e.prototype.argReducePacked=function(t,e,n){void 0===n&&(n=null);var r=null!=n?n.shape:t.shape,i=new function(t,e,n,r){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,C(t.length>2,function(){return"Packed arg"+(n.charAt(0).toUpperCase()+n.slice(1))+" supports only inputs with rank above 2."});var i=t[t.length-1],a=Math.ceil(i/e);this.outputShape=t.slice(0,-1),a>1&&this.outputShape.push(a),r||this.variableNames.push("bestIndicesA");var o,s,u=this.outputShape,c=u.length,l=ba(c),f=sa("coords",c);if(1===a){var d=ba(s=c+1);o="\n "+d+" sourceLocR = "+d+"("+f.join()+", 0);\n ++"+f[c-1]+";\n "+d+" sourceLocG = "+d+"("+f.join()+", 0);\n ++"+f[c-2]+";\n "+d+" sourceLocA = "+d+"("+f.join()+", 0);\n --"+f[c-1]+";\n "+d+" sourceLocB = "+d+"("+f.join()+", 0);\n --"+f[c-2]+";"}else s=c,o="\n "+l+" sourceLocR = coords;\n ++"+f[c-1]+";\n "+l+" sourceLocG = coords;\n ++"+f[c-2]+";\n "+l+" sourceLocA = coords;\n --"+f[c-1]+";\n "+l+" sourceLocB = coords;\n --"+f[c-2]+";";var h=["x","y","z","w","u","v"].slice(0,s),p="."+h[s-1],m=h.map(function(t){return"int "+t}),g=sa("sourceLocR",s-1).concat("inIdx.r"),v=sa("sourceLocG",s-1).concat("inIdx.g"),y=sa("sourceLocB",s-1).concat("inIdx.b"),b=sa("sourceLocA",s-1).concat("inIdx.a"),x="max"===n?"greaterThan":"lessThan",w=r?"":"\n inIdx = round(vec4(getBestIndicesAChannel("+g.join()+"),\n getBestIndicesAChannel("+v.join()+"),\n getBestIndicesAChannel("+y.join()+"),\n getBestIndicesAChannel("+b.join()+")));",k="vec4(\n getAChannel("+g.join()+"),\n hasNextCol ? getAChannel("+v.join()+") : 0.,\n hasNextRow ? getAChannel("+y.join()+") : 0.,\n hasNextRow && hasNextCol ? getAChannel("+b.join()+") : 0.)",_=r?"":"\n float getBestIndicesAChannel("+m.join()+") {\n return getChannel(getBestIndicesA("+h.join()+"),\n vec2("+h.slice(-2).join()+"));\n }";this.userCode="\n float getAChannel("+m.join()+") {\n return getChannel(getA("+h.join()+"),\n vec2("+h.slice(-2).join()+"));\n }\n "+_+"\n void main() {\n "+l+" coords = getOutputCoords();\n bool hasNextCol = "+f[c-1]+" < "+(u[c-1]-1)+";\n bool hasNextRow = "+f[c-2]+" < "+(u[c-2]-1)+";\n "+o+"\n ivec4 srcIdx = ivec4(sourceLocR"+p+", sourceLocG"+p+",\n sourceLocB"+p+", sourceLocA"+p+") * "+e+";\n ivec4 inIdx = srcIdx;\n vec4 bestIndex = vec4(inIdx);\n vec4 bestValue = "+k+";\n\n for (int i = 0; i < "+e+"; i++) {\n inIdx = srcIdx;\n "+w+"\n vec4 candidate = "+k+";\n bvec4 nan = isnan(candidate);\n bvec4 replace = bvec4(\n vec4("+x+"(candidate, bestValue)) * (vec4(1.0) - vec4(nan)));\n\n bestValue = vec4(replace.x ? candidate.x : bestValue.x,\n replace.y ? candidate.y : bestValue.y,\n replace.z ? candidate.z : bestValue.z,\n replace.w ? candidate.w : bestValue.w);\n bestIndex = mix(bestIndex, vec4(inIdx), vec4(replace));\n srcIdx++;\n }\n setOutput(bestIndex);\n }\n "}(r,ti(r[r.length-1]),e,null==n),a=null==n?[t]:[t,n],o=this.compileAndRun(i,a,"int32");return o.rank===t.rank?this.argReducePacked(t,e,o):o},e.prototype.sum=function(t,e){Sn("sum",e,t.rank);var n=En(t.shape,e),r=n[0],i=I(n[1]),a=t.as2D(-1,i),o=Rt(t.dtype);return this.reduce(a,"sum",o).reshape(r)},e.prototype.prod=function(t,e){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.prod(t,e);var n=En(t.shape,e),r=n[0],i=I(n[1]),a=t.as2D(-1,i),o=Rt(t.dtype);return this.reduce(a,"prod",o).reshape(r)},e.prototype.unsortedSegmentSum=function(t,e,n){var r=0,i=Cn([r],t.rank),a=t;null!=i&&(a=t.transpose(i),r=Nn(1,t.rank)[0]);var o=function(t,e,n){for(var r=[],i=t.length,a=0;a<i;a++)a!==e?r.push(t[a]):r.push(n);return r}(a.shape,r,n),s=I([a.shape[r]]),u=a.as2D(-1,s),c=Rt(t.dtype),l=this.segOpCompute(u,"unsortedSegmentSum",e,c,n).reshape(o);return null!=i&&(l=l.transpose(An(i))),l},e.prototype.segOpCompute=function(t,e,n,r,i){var a=t.shape[0],o=t.shape[1],s=function(t,e){var n,r=!1;for(t<=Qr?(n=t,r=!0):n=tt(t,Math.floor(Math.sqrt(t)));!r;)n>e||n===t?r=!0:n=tt(t,n+1);return n}(o,i),u=new function(t,e){this.variableNames=["x","segmentIds"];var n=t.windowSize,r=t.batchSize,i=t.inSize,a=t.numSegments,o=a*Math.ceil(i/n);this.outputShape=[r,o];var s=4*Math.floor(n/4),u=n%4,c="\n sumValue += dot(values, segFilter);\n ",l="";i%n>0&&(l="\n if (inIdx < 0 || inIdx >= "+i+") {\n return initializationValue;\n }\n ");var f="";i%n>0&&(f="\n if (inIdx < 0 || inIdx >= "+i+") {\n return -1.0;\n }\n "),this.userCode="\n const float initializationValue = 0.0;\n\n float getValue(int batch, int inIdx) {\n "+l+"\n return getX(batch, inIdx);\n }\n\n float getSegmentIdAtIndex(int inIdx) {\n "+f+"\n return getSegmentIds(inIdx);\n }\n\n void main() {\n ivec2 coords = getOutputCoords();\n int batch = coords[0];\n int outIdx = coords[1];\n int inOffset = int(floor(float(outIdx) / float(\n "+a+")) * float("+n+"));\n int currentSeg = int(mod(float(outIdx), float("+a+")));\n\n float sumValue = 0.0;\n\n for (int i = 0; i < "+s+"; i += 4) {\n int inIdx = inOffset + i;\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n getValue(batch, inIdx + 3)\n );\n\n vec4 segFilter = vec4(\n int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 2)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 3)) == currentSeg ? 1 : 0\n );\n\n "+c+"\n }\n\n int inIdx = inOffset + "+s+";\n if ("+(1===u)+") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n initializationValue,\n initializationValue,\n initializationValue\n );\n\n int inIdxSeg = int(getSegmentIdAtIndex(inIdx));\n\n vec4 segFilter = vec4(\n int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,\n 0,\n 0,\n 0\n );\n\n "+c+"\n } else if ("+(2===u)+") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n initializationValue,\n initializationValue\n );\n\n vec4 segFilter = vec4(\n int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,\n 0,\n 0\n );\n\n "+c+"\n } else if ("+(3===u)+") {\n vec4 values = vec4(\n getValue(batch, inIdx),\n getValue(batch, inIdx + 1),\n getValue(batch, inIdx + 2),\n initializationValue\n );\n\n vec4 segFilter = vec4(\n int(getSegmentIdAtIndex(inIdx)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 1)) == currentSeg ? 1 : 0,\n int(getSegmentIdAtIndex(inIdx + 2)) == currentSeg ? 1 : 0,\n 0\n );\n\n "+c+"\n }\n setOutput(sumValue);\n }\n "}({windowSize:s,inSize:o,batchSize:a,numSegments:i},e),c=this.compileAndRun(u,[t,n],r);return c.shape[1]===i?c:(n=Yn(0,i).tile([o/s]),this.segOpCompute(c,e,n,r,i))},e.prototype.argMinMaxReduce=function(t,e,n){var r=[e];if(Sn("arg"+n.charAt(0).toUpperCase()+n.slice(1),r,t.rank),!f().getBool("WEBGL_PACK_REDUCE")||t.rank<=2){var i=En(t.shape,r),a=i[0],o=I(i[1]),s=t.as2D(-1,o);return this.argReduce(s,n).reshape(a)}return this.argReducePacked(t,n)},e.prototype.argMin=function(t,e){return this.argMinMaxReduce(t,e,"min")},e.prototype.argMax=function(t,e){return this.argMinMaxReduce(t,e,"max")},e.prototype.cumsum=function(t,e,n,r){if(e!==t.rank-1)throw new Error("WebGL cumsum shader expects an inner-most axis="+(t.rank-1)+" but got axis="+e);var i=new function(t,e,n){this.variableNames=["x"],this.outputShape=t;var r=t.length,i=t[t.length-1],a=n?"<":">";this.userCode="\n int getIndex(int i) {\n "+(n?"return "+i+" -i - 1;":"return i;")+"\n }\n\n void main() {\n "+ba(r)+" coords = getOutputCoords();\n int end = "+ja(r,"coords")+";\n float val = 0.0;\n for (int i = "+i+" - 1; i >= 0; i -= 1) {\n int idx = getIndex(i);\n if (idx "+a+" end) {\n continue;\n }\n if (idx == end && "+e+") {\n continue;\n }\n "+ja(r,"coords")+" = idx;\n val += getX("+function(t,e){if(1===t)return""+e;if(2===t)return e+".x, "+e+".y";if(3===t)return e+".x, "+e+".y, "+e+".z";if(4===t)return e+".x, "+e+".y, "+e+".z, "+e+".w";throw Error("Cumulative sum for rank "+t+" is not yet supported")}(r,"coords")+");\n }\n setOutput(val);\n }\n "}(t.shape,n,r);return this.compileAndRun(i,[t])},e.prototype.equal=function(t,e){if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n return vec4(equal(a, b));\n","bool");var n=new Ca("return float(a == b);",t.shape,e.shape);return this.compileAndRun(n,[t,e],"bool")},e.prototype.notEqual=function(t,e){if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n return vec4(notEqual(a, b));\n","bool");var n=new Ca("return float(a != b);",t.shape,e.shape);return this.compileAndRun(n,[t,e],"bool")},e.prototype.less=function(t,e){if(this.shouldExecuteOnCPU([t,e]))return this.cpuBackend.less(t,e);if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n return vec4(lessThan(a, b));\n","bool");var n=new Ca("return float(a < b);",t.shape,e.shape);return this.compileAndRun(n,[t,e],"bool")},e.prototype.lessEqual=function(t,e){if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n return vec4(lessThanEqual(a, b));\n","bool");var n=new Ca("return float(a <= b);",t.shape,e.shape);return this.compileAndRun(n,[t,e],"bool")},e.prototype.greater=function(t,e){if(this.shouldExecuteOnCPU([t,e]))return this.cpuBackend.greater(t,e);if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n return vec4(greaterThan(a, b));\n","bool");var n=new Ca("return float(a > b);",t.shape,e.shape);return this.compileAndRun(n,[t,e],"bool")},e.prototype.greaterEqual=function(t,e){if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n return vec4(greaterThanEqual(a, b));\n","bool");var n=new Ca("return float(a >= b);",t.shape,e.shape);return this.compileAndRun(n,[t,e],"bool")},e.prototype.logicalNot=function(t){var e=new xo(t.shape,"return float(!(x >= 1.0));");return this.compileAndRun(e,[t])},e.prototype.logicalAnd=function(t,e){if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n return vec4(\n vec4(greaterThanEqual(a, vec4(1.0))) *\n vec4(greaterThanEqual(b, vec4(1.0))));\n","bool");var n=new Ca("return float(a >= 1.0 && b >= 1.0);",t.shape,e.shape);return this.compileAndRun(n,[t,e],"bool")},e.prototype.logicalOr=function(t,e){if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n return min(\n vec4(greaterThanEqual(a, vec4(1.0))) +\n vec4(greaterThanEqual(b, vec4(1.0))),\n vec4(1.0));\n","bool");var n=new Ca("return float(a >= 1.0 || b >= 1.0);",t.shape,e.shape);return this.compileAndRun(n,[t,e],"bool")},e.prototype.select=function(t,e,n){var r=new function(t,e,n){var r,i;if(this.variableNames=["c","a","b"],this.outputShape=e,n>4)throw Error("Where for rank "+n+" is not yet supported");if(1===n)i="resRC",r="resRC";else{for(var a=["resRC.x","resRC.y","resRC.z","resRC.w"],o=[],s=[],u=0;u<e.length;u++)s.push(""+a[u]),u<t&&o.push(""+a[u]);r=o.join(),i=s.join()}var c=ba(n);this.userCode="\n void main() {\n "+c+" resRC = getOutputCoords();\n float cVal = getC("+r+");\n if (cVal >= 1.0) {\n setOutput(getA("+i+"));\n } else {\n setOutput(getB("+i+"));\n }\n }\n "}(t.rank,e.shape,e.rank);return this.compileAndRun(r,[t,e,n],Mt(e.dtype,n.dtype))},e.prototype.where=function(t){vn("tf.where() in webgl locks the UI thread. Call tf.whereAsync() instead");var e=t.dataSync();return aa(t.shape,e)},e.prototype.topk=function(t,e,n){return ia(t.dataSync(),t.shape,t.dtype,e)},e.prototype.min=function(t,e){Sn("min",e,t.rank);var n=En(t.shape,e),r=n[0],i=I(n[1]),a=t.as2D(-1,i);return this.reduce(a,"min",a.dtype).reshape(r)},e.prototype.minimum=function(t,e){if(this.shouldExecuteOnCPU([t,e]))return this.cpuBackend.minimum(t,e);var n=f().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Na("\n vec4 result = vec4(min(a, b));\n vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));\n \n result.r = isNaN.r > 0. ? NAN : result.r;\n result.g = isNaN.g > 0. ? NAN : result.g;\n result.b = isNaN.b > 0. ? NAN : result.b;\n result.a = isNaN.a > 0. ? NAN : result.a;\n\n return result;\n",t.shape,e.shape):new Ca("\n if (isnan(a)) return a;\n if (isnan(b)) return b;\n\n return min(a, b);\n",t.shape,e.shape);return this.compileAndRun(n,[t,e])},e.prototype.mod=function(t,e){var n=f().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Na("\n vec4 result = mod(a, b);\n vec4 isNaN = vec4(equal(b, vec4(0.0)));\n \n result.r = isNaN.r > 0. ? NAN : result.r;\n result.g = isNaN.g > 0. ? NAN : result.g;\n result.b = isNaN.b > 0. ? NAN : result.b;\n result.a = isNaN.a > 0. ? NAN : result.a;\n\n return result;\n",t.shape,e.shape):new Ca("if (b == 0.0) return NAN;\n return mod(a, b);",t.shape,e.shape);return this.compileAndRun(n,[t,e])},e.prototype.max=function(t,e){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.max(t,e);Sn("max",e,t.rank);var n=En(t.shape,e),r=n[0],i=I(n[1]),a=t.as2D(-1,i);return this.reduce(a,"max",a.dtype).reshape(r)},e.prototype.maximum=function(t,e){if(this.shouldExecuteOnCPU([t,e]))return this.cpuBackend.maximum(t,e);var n=f().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Na("\n vec4 result = vec4(max(a, b));\n vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));\n \n result.r = isNaN.r > 0. ? NAN : result.r;\n result.g = isNaN.g > 0. ? NAN : result.g;\n result.b = isNaN.b > 0. ? NAN : result.b;\n result.a = isNaN.a > 0. ? NAN : result.a;\n\n return result;\n",t.shape,e.shape):new Ca("\n if (isnan(a)) return a;\n if (isnan(b)) return b;\n\n return max(a, b);\n",t.shape,e.shape);return this.compileAndRun(n,[t,e])},e.prototype.all=function(t,e){Sn("all",e,t.rank);var n=En(t.shape,e),r=n[0],i=I(n[1]),a=t.as2D(-1,i);return this.reduce(a,"all",a.dtype).reshape(r)},e.prototype.any=function(t,e){Sn("any",e,t.rank);var n=En(t.shape,e),r=n[0],i=I(n[1]),a=t.as2D(-1,i);return this.reduce(a,"any",a.dtype).reshape(r)},e.prototype.realDivide=function(t,e){if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n // vec4 one = vec4(equal(a, b));\n // return one + (vec4(1.0) - one) * a / b;\n vec4 result = a / b;\n if(a.x == b.x) {\n result.x = 1.;\n }\n if(a.y == b.y) {\n result.y = 1.;\n }\n if(a.z == b.z) {\n result.z = 1.;\n }\n if(a.w == b.w) {\n result.w = 1.;\n }\n\n return result;\n","float32",!0);var n=new Ca("\nif (a == b) {\n return 1.0;\n};\nreturn a / b;",t.shape,e.shape);return this.compileAndRun(n,[t,e],"float32")},e.prototype.floorDiv=function(t,e){if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,"\n ivec4 ia = round(a);\n ivec4 ib = round(b);\n bvec4 cond = notEqual(ib, ivec4(0));\n ivec4 result = ivec4(0);\n vec4 s = sign(a) * sign(b);\n\n // Windows (D3D) wants guaranteed non-zero int division at compile-time.\n if (cond[0]) {\n result[0] = idiv(ia[0], ib[0], s[0]);\n }\n if (cond[1]) {\n result[1] = idiv(ia[1], ib[1], s[1]);\n }\n if (cond[2]) {\n result[2] = idiv(ia[2], ib[2], s[2]);\n }\n if (cond[3]) {\n result[3] = idiv(ia[3], ib[3], s[3]);\n }\n return vec4(result);\n","int32");var n=new Ca("\n float s = sign(a) * sign(b);\n int ia = round(a);\n int ib = round(b);\n if (ib != 0) {\n // Windows (D3D) wants guaranteed non-zero int division at compile-time.\n return float(idiv(ia, ib, s));\n } else {\n return NAN;\n }\n",t.shape,e.shape);return this.compileAndRun(n,[t,e],"int32")},e.prototype.add=function(t,e){if("complex64"===t.dtype&&"complex64"===e.dtype)return this.complexSeparableBinaryOp(t,e,_a);if(this.shouldExecuteOnCPU([t,e]))return this.cpuBackend.add(t,e);var n=Mt(t.dtype,e.dtype);if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,_a,n);var r=new Ca(_a,t.shape,e.shape);return this.compileAndRun(r,[t,e],n)},e.prototype.packedUnaryOp=function(t,e,n){var r=new Po(t.shape,e);return this.compileAndRun(r,[t],n)},e.prototype.packedBinaryOp=function(t,e,n,r,i){void 0===i&&(i=!1);var a=new Na(n,t.shape,e.shape,i);return this.compileAndRun(a,[t,e],r)},e.prototype.complexSeparableBinaryOp=function(t,e,n){var r=this,i=this.texData.get(t.dataId),a=this.texData.get(e.dataId),o=[[i.complexTensors.real,a.complexTensors.real],[i.complexTensors.imag,a.complexTensors.imag]].map(function(i){var a=i[0],o=i[1],s=r.makeComplexComponentTensorInfo(t,a),u=r.makeComplexComponentTensorInfo(e,o),c=new Ca(n,t.shape,e.shape);return r.compileAndRun(c,[s,u],Mt(a.dtype,o.dtype))}),s=o[0],u=o[1],c=this.complex(s,u);return s.dispose(),u.dispose(),c},e.prototype.makeComplexComponentTensorInfo=function(t,e){return{dataId:e.dataId,dtype:e.dtype,shape:t.shape}},e.prototype.addN=function(t){if(1===t.length)return t[0];if(t.length>f().get("WEBGL_MAX_TEXTURES_IN_SHADER")){var e=Math.floor(t.length/2),n=this.addN(t.slice(0,e)),r=this.addN(t.slice(e));return this.addN([n,r])}var i=t.map(function(t){return t.dtype}).reduce(function(t,e){return Mt(t,e)}),a=t.map(function(t){return t.shape}),o=f().getBool("WEBGL_PACK")?new function(t,e){this.outputShape=[],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t,this.variableNames=e.map(function(t,e){return"T"+e});var n=[];this.variableNames.forEach(function(t){n.push("vec4 v"+t+" = get"+t+"AtOutCoords();")});var r=this.variableNames.map(function(t){return"v"+t}).join(" + ");this.userCode="\n void main() {\n "+n.join("\n ")+"\n\n vec4 result = "+r+";\n setOutput(result);\n }\n "}(t[0].shape,a):new function(t,e){this.outputShape=[],this.outputShape=t,this.variableNames=e.map(function(t,e){return"T"+e});var n=[];this.variableNames.forEach(function(t){n.push("float v"+t+" = get"+t+"AtOutCoords();")});var r=this.variableNames.map(function(t){return"v"+t}).join(" + ");this.userCode="\n void main() {\n "+n.join("\n ")+"\n\n float result = "+r+";\n setOutput(result);\n }\n "}(t[0].shape,a);return this.compileAndRun(o,t,i)},e.prototype.subtract=function(t,e){if("complex64"===t.dtype&&"complex64"===e.dtype)return this.complexSeparableBinaryOp(t,e,Ea);if(this.shouldExecuteOnCPU([t,e]))return this.cpuBackend.subtract(t,e);var n=Mt(t.dtype,e.dtype);if(f().getBool("WEBGL_PACK_BINARY_OPERATIONS"))return this.packedBinaryOp(t,e,Ea,t.dtype);var r=new Ca(Ea,t.shape,e.shape);return this.compileAndRun(r,[t,e],n)},e.prototype.pow=function(t,e){var n=f().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Na("\n // isModRound1 has 1 for components with round(mod(b, 2.0)) == 1, 0 otherwise.\n vec4 isModRound1 = vec4(equal(round(mod(b, 2.0)), ivec4(1)));\n vec4 multiplier = sign(a) * isModRound1 + (vec4(1.0) - isModRound1);\n vec4 result = multiplier * pow(abs(a), b);\n\n // Ensure that a^0 = 1, including 0^0 = 1 as this correspond to TF and JS\n bvec4 isExpZero = equal(b, vec4(0.0));\n result.r = isExpZero.r ? 1.0 : result.r;\n result.g = isExpZero.g ? 1.0 : result.g;\n result.b = isExpZero.b ? 1.0 : result.b;\n result.a = isExpZero.a ? 1.0 : result.a;\n\n vec4 isNaN = vec4(lessThan(a, vec4(0.0))) * vec4(lessThan(floor(b), b));\n \n result.r = isNaN.r > 0. ? NAN : result.r;\n result.g = isNaN.g > 0. ? NAN : result.g;\n result.b = isNaN.b > 0. ? NAN : result.b;\n result.a = isNaN.a > 0. ? NAN : result.a;\n\n return result;\n",t.shape,e.shape):new Ca("\nif(a < 0.0 && floor(b) < b){\n return NAN;\n}\nif (b == 0.0) {\n return 1.0;\n}\nreturn (round(mod(b, 2.0)) != 1) ?\n pow(abs(a), b) : sign(a) * pow(abs(a), b);\n",t.shape,e.shape),r=Mt(t.dtype,e.dtype);return this.compileAndRun(n,[t,e],r)},e.prototype.ceil=function(t){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.ceil(t);if(f().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(t,Ao,t.dtype);var e=new xo(t.shape,Ao);return this.compileAndRun(e,[t])},e.prototype.floor=function(t){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.floor(t);if(f().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(t,No,t.dtype);var e=new xo(t.shape,No);return this.compileAndRun(e,[t])},e.prototype.sign=function(t){var e=new xo(t.shape,"\n if (isnan(x)) { return 0.0; }\n return sign(x);\n");return this.compileAndRun(e,[t])},e.prototype.isNaN=function(t){var e=new xo(t.shape,"return float(isnan(x));");return this.compileAndRun(e,[t],"bool")},e.prototype.isInf=function(t){var e=new xo(t.shape,"return float(isinf(x));");return this.compileAndRun(e,[t],"bool")},e.prototype.isFinite=function(t){var e=new xo(t.shape,"return float(!isnan(x) && !isinf(x));");return this.compileAndRun(e,[t],"bool")},e.prototype.round=function(t){var e=new xo(t.shape,"\n // OpenGL ES does not support round function.\n // The algorithm is based on banker's rounding.\n float base = floor(x);\n if ((x - base) < 0.5) {\n return floor(x);\n } else if ((x - base) > 0.5) {\n return ceil(x);\n } else {\n if (mod(base, 2.0) == 0.0) {\n return base;\n } else {\n return base + 1.0;\n }\n }\n");return this.compileAndRun(e,[t])},e.prototype.exp=function(t){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.exp(t);if(f().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(t,To,t.dtype);var e=new xo(t.shape,To);return this.compileAndRun(e,[t])},e.prototype.expm1=function(t){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.expm1(t);if(f().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(t,Io,t.dtype);var e=new xo(t.shape,Io);return this.compileAndRun(e,[t])},e.prototype.softmax=function(t,e){var n=z([e],t.shape),r=this.max(t,n),i=On(r.shape,n),a=this.subtract(t,r.reshape(i)),o=this.exp(a),s=this.sum(o,n).reshape(i);return this.realDivide(o,s)},e.prototype.log=function(t){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.log(t);if(f().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(t,"\n vec4 result = log(x);\n vec4 isNaN = vec4(lessThan(x, vec4(0.0)));\n result.r = isNaN.r == 1.0 ? NAN : result.r;\n result.g = isNaN.g == 1.0 ? NAN : result.g;\n result.b = isNaN.b == 1.0 ? NAN : result.b;\n result.a = isNaN.a == 1.0 ? NAN : result.a;\n\n return result;\n",t.dtype);var e=new xo(t.shape,"if (x < 0.0) return NAN;\n return log(x);");return this.compileAndRun(e,[t])},e.prototype.log1p=function(t){var e=new xo(t.shape,"return log(1.0 + x);");return this.compileAndRun(e,[t])},e.prototype.sqrt=function(t){var e=new xo(t.shape,"return sqrt(x);");return this.compileAndRun(e,[t])},e.prototype.rsqrt=function(t){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.rsqrt(t);var e=new xo(t.shape,"return inversesqrt(x);");return this.compileAndRun(e,[t])},e.prototype.reciprocal=function(t){var e=new xo(t.shape,"return 1.0 / x;");return this.compileAndRun(e,[t])},e.prototype.relu=function(t){var e;return e=f().getBool("WEBGL_PACK")?new Po(t.shape,Ro):new xo(t.shape,Eo),this.compileAndRun(e,[t])},e.prototype.relu6=function(t){var e;return e=f().getBool("WEBGL_PACK")?new Po(t.shape,Fo):new xo(t.shape,Oo),this.compileAndRun(e,[t])},e.prototype.prelu=function(t,e){var n=f().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Na(Aa,t.shape,e.shape):new Ca(Sa,t.shape,e.shape);return this.compileAndRun(n,[t,e])},e.prototype.elu=function(t){if(f().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(t,jo,t.dtype);var e=new xo(t.shape,So);return this.compileAndRun(e,[t])},e.prototype.eluDer=function(t,e){var n=f().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Na("\n vec4 bGTEZero = vec4(greaterThanEqual(b, vec4(0.)));\n return (bGTEZero * a) + ((vec4(1.0) - bGTEZero) * (a * (b + vec4(1.0))));\n",t.shape,e.shape):new Ca("return (b >= 1.0) ? a : a * (b + 1.0);",t.shape,e.shape);return this.compileAndRun(n,[t,e])},e.prototype.selu=function(t){var e=new xo(t.shape,"\n // Stable and Attracting Fixed Point (0, 1) for Normalized Weights.\n // see: https://arxiv.org/abs/1706.02515\n float scaleAlpha = 1.7580993408473768;\n float scale = 1.0507009873554805;\n return (x >= 0.0) ? scale * x : scaleAlpha * (exp(x) - 1.0);\n");return this.compileAndRun(e,[t])},e.prototype.int=function(t){var e=new xo(t.shape,"return float(int(x));");return this.compileAndRun(e,[t],"int32")},e.prototype.clip=function(t,e,n){var r,i=(r=f().getBool("WEBGL_PACK_CLIP")?new Ia(t.shape):new Ta(t.shape)).getCustomSetupFunc(e,n);return this.compileAndRun(r,[t],null,i)},e.prototype.abs=function(t){if(this.shouldExecuteOnCPU([t]))return this.cpuBackend.abs(t);if(f().getBool("WEBGL_PACK_UNARY_OPERATIONS"))return this.packedUnaryOp(t,_o,t.dtype);var e=new xo(t.shape,_o);return this.compileAndRun(e,[t])},e.prototype.complexAbs=function(t){var e=this.texData.get(t.dataId),n=new function(t){this.variableNames=["real","imag"],this.outputShape=t,this.userCode="\n void main() {\n float re = abs(getRealAtOutCoords());\n float im = abs(getImagAtOutCoords());\n float mx = max(re, im);\n\n // sadly the length function in glsl is not underflow-safe\n // (at least not on Intel GPUs). So the safe solution is\n // to ensure underflow-safety in all cases.\n setOutput(\n mx == 0.0 ? 0.0 : mx * length(vec2(1, min(re, im)/mx))\n );\n }\n "}(t.shape),r=[this.makeComplexComponentTensorInfo(t,e.complexTensors.real),this.makeComplexComponentTensorInfo(t,e.complexTensors.imag)];return this.compileAndRun(n,r)},e.prototype.sigmoid=function(t){var e=new xo(t.shape,"return 1.0 / (1.0 + exp(-1.0 * x));");return this.compileAndRun(e,[t])},e.prototype.softplus=function(t){var e=new xo(t.shape,"\n float epsilon = 1.1920928955078125e-7;\n float threshold = log(epsilon) + 2.0;\n\n bool too_large = x > -threshold;\n bool too_small = x < threshold;\n\n float result;\n float exp_x = exp(x);\n\n if (too_large){\n result = x;\n }\n else if (too_small){\n result = exp_x;\n }\n else{\n result = log(exp_x + 1.0);\n }\n return result;\n");return this.compileAndRun(e,[t])},e.prototype.sin=function(t){var e=new xo(t.shape,"if (isnan(x)) return x;\n return sin(x);\n");return this.compileAndRun(e,[t])},e.prototype.cos=function(t){var e=new xo(t.shape,"if (isnan(x)) return x;\n return cos(x);\n");return this.compileAndRun(e,[t])},e.prototype.tan=function(t){var e=new xo(t.shape,"return tan(x);");return this.compileAndRun(e,[t])},e.prototype.asin=function(t){var e=new xo(t.shape,"if (isnan(x)) return x;\n if (abs(x) > 1.) {\n return NAN;\n }\n return asin(x);\n");return this.compileAndRun(e,[t])},e.prototype.acos=function(t){var e=new xo(t.shape,"if (isnan(x)) return x;\n if (abs(x) > 1.) {\n return NAN;\n }\n return acos(x);\n");return this.compileAndRun(e,[t])},e.prototype.atan=function(t){var e=new xo(t.shape,"if (isnan(x)) return x;\n return atan(x);\n");return this.compileAndRun(e,[t])},e.prototype.atan2=function(t,e){var n=f().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Na("\n vec4 result = atan(a, b);\n vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0));\n \n result.r = isNaN.r > 0. ? NAN : result.r;\n result.g = isNaN.g > 0. ? NAN : result.g;\n result.b = isNaN.b > 0. ? NAN : result.b;\n result.a = isNaN.a > 0. ? NAN : result.a;\n\n return result;\n",t.shape,e.shape):new Ca("\n if (isnan(a)) return a;\n if (isnan(b)) return b;\n\n return atan(a, b);\n",t.shape,e.shape);return this.compileAndRun(n,[t,e])},e.prototype.sinh=function(t){var e=new xo(t.shape,"\n float e2x = exp(x);\n return (e2x - 1.0 / e2x) / 2.0;\n");return this.compileAndRun(e,[t])},e.prototype.cosh=function(t){var e=new xo(t.shape,"\n float e2x = exp(-x);\n return (e2x + 1.0 / e2x) / 2.0;\n");return this.compileAndRun(e,[t])},e.prototype.tanh=function(t){var e=new xo(t.shape,"\n float e2x = exp(-2.0 * abs(x));\n return sign(x) * (1.0 - e2x) / (1.0 + e2x);\n");return this.compileAndRun(e,[t])},e.prototype.asinh=function(t){var e=new xo(t.shape,"if (isnan(x)) return x;return log(x + sqrt(x * x + 1.0));");return this.compileAndRun(e,[t])},e.prototype.acosh=function(t){var e=new xo(t.shape,"if (isnan(x)) return x;\n if (x < 1.0) return NAN;\n return log(x + sqrt(x * x - 1.0));");return this.compileAndRun(e,[t])},e.prototype.atanh=function(t){var e=new xo(t.shape,"if (isnan(x)) return x;\n if ((x < -1.0) || (x > 1.0)) return NAN;\n return (log(1.0 + x) - log(1.0 - x)) / 2.0;");return this.compileAndRun(e,[t])},e.prototype.erf=function(t){var e=new xo(t.shape,'\n // Error function is calculated approximately with elementary function.\n // See "Handbook of Mathematical Functions with Formulas,\n // Graphs, and Mathematical Tables", Abramowitz and Stegun.\n float p = 0.3275911;\n float a1 = 0.254829592;\n float a2 = -0.284496736;\n float a3 = 1.421413741;\n float a4 = -1.453152027;\n float a5 = 1.061405429;\n\n float sign = sign(x);\n x = abs(x);\n float t = 1.0 / (1.0 + p * x);\n return sign * (1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x));\n');return this.compileAndRun(e,[t])},e.prototype.step=function(t,e){var n=new xo(t.shape,function(t){return void 0===t&&(t=0),wo+"\n return x > 0.0 ? 1.0 : float("+t+");\n "}(e));return this.compileAndRun(n,[t])},e.prototype.conv2dByMatMul=function(t,e,n,r,i,a){var o=t.shape,s=this.texData.get(t.dataId),u=n.inChannels,c=o[0]*o[1]*o[2],l=n.outChannels,d="channelsLast"===n.dataFormat,h=(1===c||1===l)&&u>1e3,p=o[2]%2!=0&&!!s.isPacked;if(h||!f().getBool("WEBGL_LAZILY_UNPACK")||!f().getBool("WEBGL_PACK_BINARY_OPERATIONS")||!p){var m=d?o[0]*o[1]*o[2]:o[0]*o[2]*o[3],g=this.reshape(t,[1,m,n.inChannels]),v=this.reshape(e,[1,n.inChannels,n.outChannels]);return this.reshape(this.fusedBatchMatMul({a:g,b:v,transposeA:!1,transposeB:!1,bias:r,activation:i,preluActivationWeights:a}),n.outShape)}var y=d?o[0]*o[1]*(o[2]+1):o[0]*o[2]*(o[3]+1),b={dataId:t.dataId,shape:[1,y,n.inChannels],dtype:t.dtype},x=s.shape;s.shape=s.shape.slice(),s.shape[s.shape.length-2]++,C(Pe(s.shape,b.shape),function(){return"packed reshape "+s.shape+" to "+b.shape+" isn't free"});var w=this.reshape(e,[1,n.inChannels,n.outChannels]),k=this.fusedBatchMatMul({a:b,b:w,transposeA:!1,transposeB:!1,bias:r,activation:i,preluActivationWeights:a}),_=this.texData.get(k.dataId);return C(_.isPacked,function(){return"batchMatMul result is expected to be packed"}),s.shape=x,_.shape=n.outShape,Wt.makeTensorFromDataId(k.dataId,n.outShape,k.dtype)},e.prototype.conv2dWithIm2Row=function(t,e,n,r,i,a){var o=n.filterWidth,s=n.filterHeight,u=n.inChannels,c=n.outWidth,l=n.outHeight,f="channelsLast"===n.dataFormat,d=o*s*u,h=l*c,p=[d,h],m=t.squeeze([0]),g=e.reshape([1,d,-1]),v=new function(t,e,n){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t;for(var r=n.filterWidth,i=n.inChannels,a=n.strideWidth,o=n.strideHeight,s=n.padInfo,u=n.outWidth,c=n.dilationWidth,l=n.dilationHeight,f=n.dataFormat,d=s.left,h=s.top,p=i*r,m=ua(),g="channelsLast"===f,v=g?0:1,y=g?1:2,b="",x=0;x<=1;x++)for(var w=0;w<=1;w++)b+="\n blockIndex = rc.y + "+w+";\n pos = rc.x + "+x+";\n\n if(blockIndex < "+t[1]+" && pos < "+t[0]+") {\n offsetY = int(blockIndex / ("+u+")) * "+o+" - "+h+";\n d0 = offsetY + "+l+" * (pos / "+p+");\n\n if(d0 < "+e[v]+" && d0 >= 0) {\n\n offsetX = int(mod(float(blockIndex), "+u+".) * "+a+". - "+d+".);\n d1 = offsetX + "+c+" * (int(mod(float(pos), "+p+".) / "+i+".));\n\n if(d1 < "+e[y]+" && d1 >= 0) {\n\n ch = int(mod(float(pos), "+i+".));\n\n if ("+g+") {\n innerDims = vec2(d1, ch);\n result["+(2*x+w)+"] = getChannel(\n getA(d0, int(innerDims.x),\n int(innerDims.y)), innerDims);\n } else {\n innerDims = vec2(d0, d1);\n result["+(2*x+w)+"] = getChannel(\n getA(ch, int(innerDims.x),\n int(innerDims.y)), innerDims);\n }\n }\n }\n }\n ";this.userCode="\n void main() {\n ivec2 rc = getOutputCoords();\n\n vec4 result = vec4(0);\n\n int blockIndex, pos, offsetY, d0, offsetX, d1, ch;\n vec2 innerDims;\n\n "+b+"\n\n "+m.output+" = result;\n }\n "}(p,m.shape,n),y=this.compileAndRun(v,[m]).reshape([1,p[0],p[1]]),b=null!=r,x=null!=a,w=i?zo(i,!0):null,k=new oo(y.shape,[1,h,n.outChannels],!0,!1,b,w,x),_=[y,g];r&&_.push(r),x&&_.push(a);var E=this.compileAndRun(k,_);return f?E.reshape([1,l,c,n.outChannels]):E.reshape([1,n.outChannels,l,c])},e.prototype.fusedConv2d=function(t){var e=t.input,n=t.filter,r=t.convInfo,i=t.bias,a=t.activation,o=t.preluActivationWeights;if(1===r.filterHeight&&1===r.filterWidth&&1===r.dilationHeight&&1===r.dilationWidth&&1===r.strideHeight&&1===r.strideWidth&&("SAME"===r.padInfo.type||"VALID"===r.padInfo.type))return this.conv2dByMatMul(e,n,r,i,a,o);if(f().getBool("WEBGL_CONV_IM2COL")&&1===e.shape[0])return this.conv2dWithIm2Row(e,n,r,i,a,o);var s=null!=i,u=null!=o,c=a?zo(a,!1):null,l=new Ma(r,s,c,u),d=[e,n];return i&&d.push(i),o&&d.push(o),this.compileAndRun(l,d)},e.prototype.conv2d=function(t,e,n){if(1===n.filterHeight&&1===n.filterWidth&&1===n.dilationHeight&&1===n.dilationWidth&&1===n.strideHeight&&1===n.strideWidth&&("SAME"===n.padInfo.type||"VALID"===n.padInfo.type))return this.conv2dByMatMul(t,e,n);if(f().getBool("WEBGL_CONV_IM2COL")&&1===t.shape[0])return this.conv2dWithIm2Row(t,e,n);var r=new Ma(n);return this.compileAndRun(r,[t,e])},e.prototype.conv2dDerInput=function(t,e,n){var r=new function(t){this.variableNames=["dy","W"],this.outputShape=t.inShape;var e=t.filterHeight,n=t.filterWidth,r=t.strideHeight,i=t.strideWidth,a="channelsLast"===t.dataFormat,o=e-1-t.padInfo.top,s=n-1-t.padInfo.left,u=a?1:2,c=a?2:3,l=a?3:1;this.userCode="\n const ivec2 pads = ivec2("+o+", "+s+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d1 = coords["+l+"];\n\n ivec2 dyCorner = ivec2(coords["+u+"], coords["+c+"]) - pads;\n int dyRCorner = dyCorner.x;\n int dyCCorner = dyCorner.y;\n\n // Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < "+e+"; wR++) {\n float dyR = float(dyRCorner + wR) / "+r+".0;\n\n if (dyR < 0.0 || dyR >= "+t.outHeight+".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n int wRPerm = "+e+" - 1 - wR;\n\n for (int wC = 0; wC < "+n+"; wC++) {\n float dyC = float(dyCCorner + wC) / "+i+".0;\n\n if (dyC < 0.0 || dyC >= "+t.outWidth+".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n int wCPerm = "+n+" - 1 - wC;\n\n for (int d2 = 0; d2 < "+t.outChannels+"; d2++) {\n\n if ("+a+") {\n float xValue = getDy(batch, idyR, idyC, d2);\n float wValue = getW(wRPerm, wCPerm, d1, d2);\n dotProd += xValue * wValue;\n } else {\n float xValue = getDy(batch, d2, idyR, idyC);\n float wValue = getW(wRPerm, wCPerm, d1, d2);\n dotProd += xValue * wValue;\n }\n\n }\n }\n }\n setOutput(dotProd);\n }\n "}(n);return this.compileAndRun(r,[t,e])},e.prototype.conv2dDerFilter=function(t,e,n){var r=new function(t){this.variableNames=["x","dy"],this.outputShape=t.filterShape;var e=t.strideHeight,n=t.strideWidth,r=t.padInfo.top,i=t.padInfo.left,a="channelsLast"===t.dataFormat;this.userCode="\n void main() {\n ivec4 coords = getOutputCoords();\n int wR = coords.x;\n int wC = coords.y;\n int d1 = coords.z;\n int d2 = coords.w;\n\n // Convolve x(?, ?, d1) with dy(:, :, d2) to get dw(wR, wC, d1, d2).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n\n for (int b = 0; b < "+t.batchSize+"; b++) {\n for (int yR = 0; yR < "+t.outHeight+"; yR++) {\n int xR = wR + yR * "+e+" - "+r+";\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int yC = 0; yC < "+t.outWidth+"; yC++) {\n int xC = wC + yC * "+n+" - "+i+";\n\n if (xC < 0 || xC >= "+t.inWidth+") {\n continue;\n }\n\n if ("+a+") {\n float dyValue = getDy(b, yR, yC, d2);\n float xValue = getX(b, xR, xC, d1);\n dotProd += (xValue * dyValue);\n } else {\n float dyValue = getDy(b, d2, yR, yC);\n float xValue = getX(b, d1, xR, xC);\n dotProd += (xValue * dyValue);\n }\n\n }\n }\n }\n setOutput(dotProd);\n }\n "}(n);return this.compileAndRun(r,[t,e])},e.prototype.fusedDepthwiseConv2D=function(t){var e,n=t.input,r=t.filter,i=t.convInfo,a=t.bias,o=t.activation,s=t.preluActivationWeights,u=f().getBool("WEBGL_PACK_DEPTHWISECONV")&&i.strideWidth<=2&&i.outChannels/i.inChannels==1,c=o?zo(o,u):null,l=[n,r],d=null!=a,h=null!=s;return d&&l.push(a),h&&l.push(s),u?(e=new Fa(i,d,c,h),this.compileAndRun(e,l)):(e=new Ra(i,d,c,h),this.compileAndRun(e,l))},e.prototype.depthwiseConv2D=function(t,e,n){var r;return f().getBool("WEBGL_PACK_DEPTHWISECONV")&&n.strideWidth<=2&&n.outChannels/n.inChannels==1?(r=new Fa(n),this.compileAndRun(r,[t,e])):(r=new Ra(n),this.compileAndRun(r,[t,e]))},e.prototype.depthwiseConv2DDerInput=function(t,e,n){var r=new function(t){this.variableNames=["dy","W"],this.outputShape=t.inShape;var e=t.filterHeight,n=t.filterWidth,r=t.strideHeight,i=t.strideWidth,a=e-1-t.padInfo.top,o=n-1-t.padInfo.left,s=t.outChannels/t.inChannels;this.userCode="\n const ivec2 pads = ivec2("+a+", "+o+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int batch = coords[0];\n int d1 = coords[3];\n ivec2 dyCorner = coords.yz - pads;\n int dyRCorner = dyCorner.x;\n int dyCCorner = dyCorner.y;\n\n float dotProd = 0.0;\n\n for (int wR = 0; wR < "+e+"; wR++) {\n float dyR = float(dyRCorner + wR) / "+r+".0;\n\n if (dyR < 0.0 || dyR >= "+t.outHeight+".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n int wRPerm = "+e+" - 1 - wR;\n\n for (int wC = 0; wC < "+n+"; wC++) {\n float dyC = float(dyCCorner + wC) / "+i+".0;\n\n if (dyC < 0.0 || dyC >= "+t.outWidth+".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n int wCPerm = "+n+" - 1 - wC;\n\n // TO DO: Vec4 over the channelMul\n for (int dm = 0; dm < "+s+"; dm++) {\n int d2 = d1 * "+s+" + dm;\n float xValue = getDy(batch, idyR, idyC, d2);\n float wValue = getW(wRPerm, wCPerm, d1, dm);\n dotProd += xValue * wValue;\n }\n }\n }\n setOutput(dotProd);\n }\n "}(n);return this.compileAndRun(r,[t,e])},e.prototype.depthwiseConv2DDerFilter=function(t,e,n){var r=new function(t){this.variableNames=["x","dy"],this.outputShape=t.filterShape;var e=t.strideHeight,n=t.strideWidth,r=t.padInfo.top,i=t.padInfo.left,a=t.outChannels/t.inChannels;this.userCode="\n void main() {\n ivec4 coords = getOutputCoords();\n int wR = coords.x;\n int wC = coords.y;\n int d1 = coords.z;\n int dm = coords.w;\n int d2 = d1 * "+a+" + dm;\n\n float dotProd = 0.0;\n\n // TO DO: Vec4 over the batch size\n for (int b = 0; b < "+t.batchSize+"; b++) {\n for (int yR = 0; yR < "+t.outHeight+"; yR++) {\n int xR = wR + yR * "+e+" - "+r+";\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int yC = 0; yC < "+t.outWidth+"; yC++) {\n int xC = wC + yC * "+n+" - "+i+";\n\n if (xC < 0 || xC >= "+t.inWidth+") {\n continue;\n }\n\n float dyValue = getDy(b, yR, yC, d2);\n float xValue = getX(b, xR, xC, d1);\n dotProd += (xValue * dyValue);\n }\n }\n }\n setOutput(dotProd);\n }\n "}(n);return this.compileAndRun(r,[t,e])},e.prototype.conv3d=function(t,e,n){var r=new function(t){this.variableNames=["x","W"],this.outputShape=t.outShape;var e=t.padInfo.front,n=t.padInfo.top,r=t.padInfo.left,i=t.strideDepth,a=t.strideHeight,o=t.strideWidth,s=t.dilationDepth,u=t.dilationHeight,c=t.dilationWidth,l=t.filterDepth,f=t.filterHeight,d=t.filterWidth,h=4*Math.floor(t.inChannels/4),p=t.inChannels%4;this.userCode="\n const ivec3 strides = ivec3("+i+", "+a+", "+o+");\n const ivec3 pads = ivec3("+e+", "+n+", "+r+");\n\n void main() {\n ivec5 coords = getOutputCoords();\n int batch = coords.x;\n int d2 = coords.u;\n\n ivec3 xFRCCorner = ivec3(coords.y, coords.z, coords.w) * strides - pads;\n int xFCorner = xFRCCorner.x;\n int xRCorner = xFRCCorner.y;\n int xCCorner = xFRCCorner.z;\n\n // Convolve x(?, ?, ?, d1) with w(:, :, :, d1, d2) to get\n // y(yF, yR, yC, d2). ? = to be determined. : = across all\n // values in that axis.\n float dotProd = 0.0;\n for (int wF = 0; wF < "+l+"; wF++) {\n int xF = xFCorner + wF * "+s+";\n\n if (xF < 0 || xF >= "+t.inDepth+") {\n continue;\n }\n\n for (int wR = 0; wR < "+f+"; wR++) {\n int xR = xRCorner + wR * "+u+";\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int wC = 0; wC < "+d+"; wC++) {\n int xC = xCCorner + wC * "+c+";\n\n if (xC < 0 || xC >= "+t.inWidth+") {\n continue;\n }\n\n for (int d1 = 0; d1 < "+h+"; d1 += 4) {\n vec4 xValues = vec4(\n getX(batch, xF, xR, xC, d1),\n getX(batch, xF, xR, xC, d1 + 1),\n getX(batch, xF, xR, xC, d1 + 2),\n getX(batch, xF, xR, xC, d1 + 3)\n );\n vec4 wValues = vec4(\n getW(wF, wR, wC, d1, d2),\n getW(wF, wR, wC, d1 + 1, d2),\n getW(wF, wR, wC, d1 + 2, d2),\n getW(wF, wR, wC, d1 + 3, d2)\n );\n\n dotProd += dot(xValues, wValues);\n }\n\n if ("+(1===p)+") {\n dotProd +=\n getX(batch, xF, xR, xC, "+h+") *\n getW(wF, wR, wC, "+h+", d2);\n } else if ("+(2===p)+") {\n vec2 xValues = vec2(\n getX(batch, xF, xR, xC, "+h+"),\n getX(batch, xF, xR, xC, "+h+" + 1)\n );\n vec2 wValues = vec2(\n getW(wF, wR, wC, "+h+", d2),\n getW(wF, wR, wC, "+h+" + 1, d2)\n );\n dotProd += dot(xValues, wValues);\n } else if ("+(3===p)+") {\n vec3 xValues = vec3(\n getX(batch, xF, xR, xC, "+h+"),\n getX(batch, xF, xR, xC, "+h+" + 1),\n getX(batch, xF, xR, xC, "+h+" + 2)\n );\n vec3 wValues = vec3(\n getW(wF, wR, wC, "+h+", d2),\n getW(wF, wR, wC, "+h+" + 1, d2),\n getW(wF, wR, wC, "+h+" + 2, d2)\n );\n dotProd += dot(xValues, wValues);\n }\n }\n }\n }\n setOutput(dotProd);\n }\n "}(n);return this.compileAndRun(r,[t,e])},e.prototype.conv3dDerInput=function(t,e,n){var r=new function(t){this.variableNames=["dy","W"],this.outputShape=t.inShape;var e=t.filterDepth,n=t.filterHeight,r=t.filterWidth,i=t.strideDepth,a=t.strideHeight,o=t.strideWidth,s=e-1-t.padInfo.front,u=n-1-t.padInfo.top,c=r-1-t.padInfo.left;this.userCode="\n const ivec3 pads = ivec3("+s+", "+u+", "+c+");\n\n void main() {\n ivec5 coords = getOutputCoords();\n int batch = coords.x;\n int d1 = coords.u;\n\n\n ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;\n int dyFCorner = dyCorner.x;\n int dyRCorner = dyCorner.y;\n int dyCCorner = dyCorner.z;\n\n float dotProd = 0.0;\n for (int wF = 0; wF < "+e+"; wF++) {\n float dyF = float(dyFCorner + wF) / "+i+".0;\n\n if (dyF < 0.0 || dyF >= "+t.outDepth+".0 || fract(dyF) > 0.0) {\n continue;\n }\n int idyF = int(dyF);\n\n int wFPerm = "+e+" - 1 - wF;\n\n for (int wR = 0; wR < "+n+"; wR++) {\n float dyR = float(dyRCorner + wR) / "+a+".0;\n\n if (dyR < 0.0 || dyR >= "+t.outHeight+".0 ||\n fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n int wRPerm = "+n+" - 1 - wR;\n\n for (int wC = 0; wC < "+r+"; wC++) {\n float dyC = float(dyCCorner + wC) / "+o+".0;\n\n if (dyC < 0.0 || dyC >= "+t.outWidth+".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n int wCPerm = "+r+" - 1 - wC;\n\n for (int d2 = 0; d2 < "+t.outChannels+"; d2++) {\n float xValue = getDy(batch, idyF, idyR, idyC, d2);\n float wValue = getW(wFPerm, wRPerm, wCPerm, d1, d2);\n dotProd += xValue * wValue;\n }\n }\n }\n }\n setOutput(dotProd);\n }\n "}(n);return this.compileAndRun(r,[t,e])},e.prototype.conv3dDerFilter=function(t,e,n){var r=new function(t){this.variableNames=["x","dy"],this.outputShape=t.filterShape;var e=t.strideDepth,n=t.strideHeight,r=t.strideWidth,i=t.padInfo.front,a=t.padInfo.top,o=t.padInfo.left;this.userCode="\n void main() {\n ivec5 coords = getOutputCoords();\n int wF = coords.x;\n int wR = coords.y;\n int wC = coords.z;\n int d1 = coords.w;\n int d2 = coords.u;\n\n float dotProd = 0.0;\n\n for (int b = 0; b < "+t.batchSize+"; b++) {\n for (int yF = 0; yF < "+t.outDepth+"; yF++) {\n int xF = wF + yF * "+e+" - "+i+";\n\n if (xF < 0 || xF >= "+t.inDepth+") {\n continue;\n }\n\n for (int yR = 0; yR < "+t.outHeight+"; yR++) {\n int xR = wR + yR * "+n+" - "+a+";\n\n if (xR < 0 || xR >= "+t.inHeight+") {\n continue;\n }\n\n for (int yC = 0; yC < "+t.outWidth+"; yC++) {\n int xC = wC + yC * "+r+" - "+o+";\n\n if (xC < 0 || xC >= "+t.inWidth+") {\n continue;\n }\n\n float dyValue = getDy(b, yF, yR, yC, d2);\n float xValue = getX(b, xF, xR, xC, d1);\n dotProd += (xValue * dyValue);\n }\n }\n }\n }\n setOutput(dotProd);\n }\n "}(n);return this.compileAndRun(r,[t,e])},e.prototype.maxPool=function(t,e){var n=new uo(e,"max",!1);return this.compileAndRun(n,[t])},e.prototype.avgPool=function(t,e){var n=new uo(e,"avg",!1);return this.compileAndRun(n,[t],"float32")},e.prototype.maxPoolBackprop=function(t,e,n,r){var i=new uo(r,"max",!0),a=this.compileAndRun(i,[e]),o=new function(t){this.variableNames=["dy","maxPos"],this.outputShape=t.inShape;var e=t.strideHeight,n=t.strideWidth,r=t.dilationHeight,i=t.effectiveFilterHeight,a=t.effectiveFilterWidth,o=i-1-t.padInfo.top,s=a-1-t.padInfo.left,u=i*a-1;this.userCode="\n const ivec2 pads = ivec2("+o+", "+s+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n\n ivec2 dyRCCorner = coords.yz - pads;\n int dyRCorner = dyRCCorner.x;\n int dyCCorner = dyRCCorner.y;\n\n // Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < "+i+";\n wR += "+r+") {\n float dyR = float(dyRCorner + wR) / "+e+".0;\n\n if (dyR < 0.0 || dyR >= "+t.outHeight+".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < "+a+"; wC++) {\n float dyC = float(dyCCorner + wC) / "+n+".0;\n\n if (dyC < 0.0 || dyC >= "+t.outWidth+".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(b, idyR, idyC, d);\n int maxPosValue = "+u+" - int(getMaxPos(b, idyR, idyC, d));\n\n // Get the current value, check it against the value from the\n // position matrix.\n int curPosValue = wR * "+a+" + wC;\n float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);\n\n dotProd += dyValue * mask;\n }\n }\n setOutput(dotProd);\n }\n "}(r),s=this.compileAndRun(o,[t,a],e.dtype);return a.dispose(),s},e.prototype.avgPoolBackprop=function(t,e,n){var r=new function(t){this.variableNames=["dy"],this.outputShape=t.inShape;var e=t.filterHeight,n=t.filterWidth,r=t.strideHeight,i=t.strideWidth,a=t.dilationHeight,o=t.dilationWidth,s=t.effectiveFilterHeight,u=t.effectiveFilterWidth,c=s-1-t.padInfo.top,l=u-1-t.padInfo.left,f=1/(e*n);this.userCode="\n const ivec2 pads = ivec2("+c+", "+l+");\n const float avgMultiplier = float("+f+");\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n\n ivec2 dyRCCorner = coords.yz - pads;\n int dyRCorner = dyRCCorner.x;\n int dyCCorner = dyRCCorner.y;\n\n // Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n for (int wR = 0; wR < "+s+";\n wR += "+a+") {\n float dyR = float(dyRCorner + wR) / "+r+".0;\n\n if (dyR < 0.0 || dyR >= "+t.outHeight+".0 || fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < "+u+";\n wC+= "+o+") {\n float dyC = float(dyCCorner + wC) / "+i+".0;\n\n if (dyC < 0.0 || dyC >= "+t.outWidth+".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(b, idyR, idyC, d);\n\n dotProd += dyValue * avgMultiplier;\n }\n }\n setOutput(dotProd);\n }\n "}(n);return this.compileAndRun(r,[t],e.dtype)},e.prototype.cast=function(t,e){return Bi(t,e,this)},e.prototype.unstack=function(t,e){for(var n=t.shape[e],r=new Array(t.rank-1),i=0,a=0;a<t.rank;a++)a!==e&&(r[i++]=t.shape[a]);var o=new Array(t.rank).fill(0),s=t.shape.slice();s[e]=1;var u=new Array(n);for(a=0;a<u.length;a++)o[e]=a,u[a]=this.slice(t,o,s).reshape(r);return u},e.prototype.avgPool3d=function(t,e){var n=new co(e,"avg",!1);return this.compileAndRun(n,[t],"float32")},e.prototype.avgPool3dBackprop=function(t,e,n){var r=new function(t){this.variableNames=["dy"],this.outputShape=t.inShape;var e=t.filterDepth,n=t.filterHeight,r=t.filterWidth,i=t.strideDepth,a=t.strideHeight,o=t.strideWidth,s=t.dilationDepth,u=t.dilationHeight,c=t.dilationWidth,l=t.effectiveFilterDepth,f=t.effectiveFilterHeight,d=t.effectiveFilterWidth,h=l-1-t.padInfo.front,p=f-1-t.padInfo.top,m=d-1-t.padInfo.left,g=1/(e*n*r);this.userCode="\n const ivec3 pads = ivec3("+h+", "+p+", "+m+");\n const float avgMultiplier = float("+g+");\n\n void main() {\n ivec5 coords = getOutputCoords();\n int batch = coords.x;\n int ch = coords.u;\n\n ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;\n int dyDCorner = dyCorner.x;\n int dyRCorner = dyCorner.y;\n int dyCCorner = dyCorner.z;\n\n // Convolve dy(?, ?, ?, d) with pos mask(:, :, :, ch) to get\n // dx(xD, xR, xC, ch).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n\n for (int wD = 0; wD < "+l+";\n wD += "+s+") {\n float dyD = float(dyDCorner + wD) / "+i+".0;\n\n if (dyD < 0.0 || dyD >= "+t.outDepth+".0 || fract(dyD) > 0.0) {\n continue;\n }\n int idyD = int(dyD);\n\n for (int wR = 0; wR < "+f+";\n wR += "+u+") {\n float dyR = float(dyRCorner + wR) / "+a+".0;\n\n if (dyR < 0.0 || dyR >= "+t.outHeight+".0 ||\n fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < "+d+";\n wC += "+c+") {\n float dyC = float(dyCCorner + wC) / "+o+".0;\n\n if (dyC < 0.0 || dyC >= "+t.outWidth+".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(batch, idyD, idyR, idyC, ch);\n\n dotProd += dyValue * avgMultiplier;\n }\n }\n }\n setOutput(dotProd);\n }\n "}(n);return this.compileAndRun(r,[t],e.dtype)},e.prototype.maxPool3d=function(t,e){var n=new co(e,"max",!1);return this.compileAndRun(n,[t],"float32")},e.prototype.maxPool3dBackprop=function(t,e,n,r){var i=new co(r,"max",!0),a=this.compileAndRun(i,[e]),o=new function(t){this.variableNames=["dy","maxPos"],this.outputShape=t.inShape;var e=t.strideDepth,n=t.strideHeight,r=t.strideWidth,i=t.dilationDepth,a=t.dilationHeight,o=t.dilationWidth,s=t.effectiveFilterDepth,u=t.effectiveFilterHeight,c=t.effectiveFilterWidth,l=s-1-t.padInfo.front,f=u-1-t.padInfo.top,d=c-1-t.padInfo.left,h=s*u*c-1;this.userCode="\n const ivec3 pads = ivec3("+l+", "+f+", "+d+");\n\n void main() {\n ivec5 coords = getOutputCoords();\n int batch = coords.x;\n int ch = coords.u;\n\n ivec3 dyCorner = ivec3(coords.y, coords.z, coords.w) - pads;\n int dyDCorner = dyCorner.x;\n int dyRCorner = dyCorner.y;\n int dyCCorner = dyCorner.z;\n\n // Convolve dy(?, ?, ?, ch) with pos mask(:, :, :, d) to get\n // dx(xD, xR, xC, ch).\n // ? = to be determined. : = across all values in that axis.\n float dotProd = 0.0;\n\n for (int wD = 0; wD < "+s+";\n wD += "+i+") {\n float dyD = float(dyDCorner + wD) / "+e+".0;\n\n if (dyD < 0.0 || dyD >= "+t.outDepth+".0 || fract(dyD) > 0.0) {\n continue;\n }\n int idyD = int(dyD);\n\n for (int wR = 0; wR < "+u+";\n wR += "+a+") {\n float dyR = float(dyRCorner + wR) / "+n+".0;\n\n if (dyR < 0.0 || dyR >= "+t.outHeight+".0 ||\n fract(dyR) > 0.0) {\n continue;\n }\n int idyR = int(dyR);\n\n for (int wC = 0; wC < "+c+";\n wC += "+o+") {\n float dyC = float(dyCCorner + wC) / "+r+".0;\n\n if (dyC < 0.0 || dyC >= "+t.outWidth+".0 ||\n fract(dyC) > 0.0) {\n continue;\n }\n int idyC = int(dyC);\n\n float dyValue = getDy(batch, idyD, idyR, idyC, ch);\n int maxPosValue = "+h+" -\n int(getMaxPos(batch, idyD, idyR, idyC, ch));\n\n // Get the current value, check it against the value from the\n // position matrix.\n int curPosValue =\n wD * "+u+" * "+c+" +\n wR * "+c+" + wC;\n float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);\n\n dotProd += dyValue * mask;\n }\n }\n }\n setOutput(dotProd);\n }\n "}(r),s=this.compileAndRun(o,[t,a],e.dtype);return a.dispose(),s},e.prototype.reshape=function(t,e){var n=this.texData.get(t.dataId);if(n.isPacked&&!Pe(t.shape,e)&&(null===n.texture||!Pe(n.shape,e))){var r=this.packedReshape(t,e);return Wt.makeTensorFromDataId(r.dataId,r.shape,r.dtype)}return Ui(t,e)},e.prototype.resizeBilinear=function(t,e,n,r){var i=f().getBool("WEBGL_PACK_IMAGE_OPERATIONS")?new function(t,e,n,r){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=[];var i=t[0],a=t[1],o=t[2],s=t[3];this.outputShape=[i,e,n,s];var u=[r&&e>1?a-1:a,r&&n>1?o-1:o],c=[r&&e>1?e-1:e,r&&n>1?n-1:n];this.userCode="\n const vec3 effectiveInputOverOutputRatioRC = vec3(\n "+u[0]/c[0]+",\n "+u[1]/c[1]+",\n "+u[1]/c[1]+");\n const vec3 inputShapeRC = vec3("+a+".0, "+o+".0,\n "+o+".0);\n\n float getAValue(int b, int r, int c, int d) {\n return getChannel(getA(b, r, c, d), vec2(c, d));\n }\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n // Calculate values for next column in yRC.z.\n ivec3 yRC = coords.yzz + ivec3(0, 0, 1);\n\n // Fractional source index.\n vec3 sourceFracIndexRC = vec3(yRC) * effectiveInputOverOutputRatioRC;\n\n // Compute the four integer indices.\n ivec3 sourceFloorRC = ivec3(sourceFracIndexRC);\n ivec3 sourceCeilRC = ivec3(\n min(inputShapeRC - 1.0, ceil(sourceFracIndexRC)));\n\n // Should we calculate next column and row elements in 2x2 packed cell.\n bool hasNextCol = d < "+(s-1)+";\n bool hasNextRow = coords.z < "+(n-1)+";\n\n // In parallel, construct four corners for all four components in\n // packed 2x2 cell.\n vec4 topLeft = vec4(\n getAValue(b, sourceFloorRC.x, sourceFloorRC.y, d),\n hasNextCol ? getAValue(b, sourceFloorRC.x, sourceFloorRC.y, d + 1)\n : 0.0,\n hasNextRow ? getAValue(b, sourceFloorRC.x, sourceFloorRC.z, d)\n : 0.0,\n (hasNextRow && hasNextCol) ?\n getAValue(b, sourceFloorRC.x, sourceFloorRC.z, d + 1) : 0.0);\n\n vec4 bottomLeft = vec4(\n getAValue(b, sourceCeilRC.x, sourceFloorRC.y, d),\n hasNextCol ? getAValue(b, sourceCeilRC.x, sourceFloorRC.y, d + 1)\n : 0.0,\n hasNextRow ? getAValue(b, sourceCeilRC.x, sourceFloorRC.z, d)\n : 0.0,\n (hasNextRow && hasNextCol) ?\n getAValue(b, sourceCeilRC.x, sourceFloorRC.z, d + 1) : 0.0);\n\n vec4 topRight = vec4(\n getAValue(b, sourceFloorRC.x, sourceCeilRC.y, d),\n hasNextCol ? getAValue(b, sourceFloorRC.x, sourceCeilRC.y, d + 1)\n : 0.0,\n hasNextRow ? getAValue(b, sourceFloorRC.x, sourceCeilRC.z, d)\n : 0.0,\n (hasNextRow && hasNextCol) ?\n getAValue(b, sourceFloorRC.x, sourceCeilRC.z, d + 1) : 0.0);\n\n vec4 bottomRight = vec4(\n getAValue(b, sourceCeilRC.x, sourceCeilRC.y, d),\n hasNextCol ? getAValue(b, sourceCeilRC.x, sourceCeilRC.y, d + 1)\n : 0.0,\n hasNextRow ? getAValue(b, sourceCeilRC.x, sourceCeilRC.z, d)\n : 0.0,\n (hasNextRow && hasNextCol) ?\n getAValue(b, sourceCeilRC.x, sourceCeilRC.z, d + 1) : 0.0);\n\n vec3 fracRC = sourceFracIndexRC - vec3(sourceFloorRC);\n\n vec4 top = mix(topLeft, topRight, fracRC.yyzz);\n vec4 bottom = mix(bottomLeft, bottomRight, fracRC.yyzz);\n vec4 newValue = mix(top, bottom, fracRC.x);\n\n setOutput(newValue);\n }\n "}(t.shape,e,n,r):new function(t,e,n,r){this.variableNames=["A"],this.outputShape=[];var i=t[0],a=t[1],o=t[2],s=t[3];this.outputShape=[i,e,n,s];var u=[r&&e>1?a-1:a,r&&n>1?o-1:o],c=[r&&e>1?e-1:e,r&&n>1?n-1:n];this.userCode="\n const vec2 effectiveInputOverOutputRatioRC = vec2(\n "+u[0]/c[0]+",\n "+u[1]/c[1]+");\n const vec2 inputShapeRC = vec2("+a+".0, "+o+".0);\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n ivec2 yRC = coords.yz;\n\n // Fractional source index.\n vec2 sourceFracIndexRC = vec2(yRC) * effectiveInputOverOutputRatioRC;\n\n // Compute the four integer indices.\n ivec2 sourceFloorRC = ivec2(sourceFracIndexRC);\n ivec2 sourceCeilRC = ivec2(\n min(inputShapeRC - 1.0, ceil(sourceFracIndexRC)));\n\n float topLeft = getA(b, sourceFloorRC.x, sourceFloorRC.y, d);\n float bottomLeft = getA(b, sourceCeilRC.x, sourceFloorRC.y, d);\n float topRight = getA(b, sourceFloorRC.x, sourceCeilRC.y, d);\n float bottomRight = getA(b, sourceCeilRC.x, sourceCeilRC.y, d);\n\n vec2 fracRC = sourceFracIndexRC - vec2(sourceFloorRC);\n\n float top = topLeft + (topRight - topLeft) * fracRC.y;\n float bottom = bottomLeft + (bottomRight - bottomLeft) * fracRC.y;\n float newValue = top + (bottom - top) * fracRC.x;\n\n setOutput(newValue);\n }\n "}(t.shape,e,n,r);return this.compileAndRun(i,[t],"float32")},e.prototype.resizeBilinearBackprop=function(t,e,n){var r=new function(t,e,n){this.variableNames=["dy"],this.outputShape=[],this.outputShape=e.shape;var r=e.shape,i=r[1],a=r[2],o=t.shape,s=o[1],u=o[2],c=[n&&s>1?i-1:i,n&&u>1?a-1:a],l=[n&&s>1?s-1:s,n&&u>1?u-1:u],f=c[0]/l[0],d=c[1]/l[1],h=1/f,p=1/d,m=2*Math.ceil(h)+2,g=2*Math.ceil(p)+2;this.userCode="\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n int r = coords[1];\n int c = coords[2];\n\n float accumulator = 0.0;\n\n const float heightScale = float("+f+");\n const float widthScale = float("+d+");\n\n const float invHeightScale = float("+h+");\n const float invWidthScale = float("+p+");\n\n const int winHeight = int("+m+");\n const int winWidth = int("+g+");\n\n // Compute bounds for where in dy we will look\n float startRLerp = floor(float(r) * invHeightScale);\n int startDyR = int(startRLerp - float(winHeight / 2));\n\n float startCLerp = floor(float(c) * invWidthScale);\n int startDyC = int(startCLerp - float(winWidth / 2));\n\n // Loop over dy\n for (int dyROffset = 0; dyROffset < winHeight; dyROffset++) {\n int dyR = dyROffset + startDyR;\n\n // Guard against the window exceeding the bounds of dy\n if (dyR < 0 || dyR >= "+s+") {\n continue;\n }\n\n for (int dyCOffset = 0; dyCOffset < winWidth; dyCOffset++) {\n int dyC = dyCOffset + startDyC;\n\n // Guard against the window exceeding the bounds of dy\n if (dyC < 0 || dyC >= "+u+") {\n continue;\n }\n\n float dxR = float(dyR) * heightScale;\n int topDxRIndex = int(floor(dxR));\n int bottomDxRIndex = int(min(ceil(dxR), "+(i-1)+".0));\n float dxRLerp = dxR - float(topDxRIndex);\n float inverseDxRLerp = 1.0 - dxRLerp;\n\n float dxC = float(dyC) * widthScale;\n int leftDxCIndex = int(floor(dxC));\n int rightDxCIndex = int(min(ceil(dxC), "+(a-1)+".0));\n float dxCLerp = dxC - float(leftDxCIndex);\n float inverseDxCLerp = 1.0 - dxCLerp;\n\n if (r == topDxRIndex && c == leftDxCIndex) {\n // topLeft\n accumulator +=\n getDy(b, dyR, dyC, d) * inverseDxRLerp * inverseDxCLerp;\n }\n\n if (r == topDxRIndex && c == rightDxCIndex) {\n // topRight\n accumulator += getDy(b, dyR, dyC, d) * inverseDxRLerp * dxCLerp;\n }\n\n if (r == bottomDxRIndex && c == leftDxCIndex) {\n // bottomLeft\n accumulator += getDy(b, dyR, dyC, d) * dxRLerp * inverseDxCLerp;\n }\n\n if (r == bottomDxRIndex && c == rightDxCIndex) {\n // bottomRight\n accumulator += getDy(b, dyR, dyC, d) * dxRLerp * dxCLerp;\n }\n }\n }\n // End loop over dy\n\n setOutput(accumulator);\n }\n "}(t,e,n);return this.compileAndRun(r,[t])},e.prototype.resizeNearestNeighbor=function(t,e,n,r){var i=new function(t,e,n,r){this.variableNames=["A"],this.outputShape=[];var i=t[0],a=t[1],o=t[2],s=t[3];this.outputShape=[i,e,n,s];var u=[r&&e>1?a-1:a,r&&n>1?o-1:o],c=[r&&e>1?e-1:e,r&&n>1?n-1:n],l=r?"0.5":"0.0";this.userCode="\n const vec2 effectiveInputOverOutputRatioRC = vec2(\n "+u[0]/c[0]+",\n "+u[1]/c[1]+");\n const vec2 inputShapeRC = vec2("+a+".0, "+o+".0);\n\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n ivec2 yRC = coords.yz;\n\n // Fractional source index.\n vec2 sourceFracIndexRC = vec2(yRC) * effectiveInputOverOutputRatioRC;\n\n // Compute the coordinators of nearest neighbor point.\n ivec2 sourceNearestRC = ivec2(\n min(inputShapeRC - 1.0, floor(sourceFracIndexRC + "+l+")));\n\n float newValue = getA(b, sourceNearestRC.x, sourceNearestRC.y, d);\n\n setOutput(newValue);\n }\n "}(t.shape,e,n,r);return this.compileAndRun(i,[t])},e.prototype.resizeNearestNeighborBackprop=function(t,e,n){var r=new function(t,e,n){this.variableNames=["dy"],this.outputShape=[],this.outputShape=e.shape;var r=e.shape,i=r[1],a=r[2],o=t.shape,s=o[1],u=o[2],c=[n&&s>1?i-1:i,n&&u>1?a-1:a],l=[n&&s>1?s-1:s,n&&u>1?u-1:u],f=c[0]/l[0],d=c[1]/l[1],h=1/f,p=1/d,m=2*Math.ceil(h)+2,g=2*Math.ceil(p)+2;this.userCode="\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int d = coords[3];\n int r = coords[1];\n int c = coords[2];\n\n float accumulator = 0.0;\n\n const float heightScale = float("+f+");\n const float widthScale = float("+d+");\n\n const float invHeightScale = float("+h+");\n const float invWidthScale = float("+p+");\n\n const int winHeight = int("+m+");\n const int winWidth = int("+g+");\n\n // Compute bounds for where in dy we will look\n float startRLerp = floor(float(r) * invHeightScale);\n int startDyR = int(floor(startRLerp - float(winHeight / 2)));\n\n float startCLerp = floor(float(c) * invWidthScale);\n int startDyC = int(floor(startCLerp - float(winWidth / 2)));\n\n // Loop over dy\n for (int dyROffset = 0; dyROffset < winHeight; dyROffset++) {\n int dyR = dyROffset + startDyR;\n\n // Guard against the window exceeding the bounds of dy\n if (dyR < 0 || dyR >= "+s+") {\n continue;\n }\n\n for (int dyCOffset = 0; dyCOffset < winWidth; dyCOffset++) {\n int dyC = dyCOffset + startDyC;\n\n // Guard against the window exceeding the bounds of dy\n if (dyC < 0 || dyC >= "+u+") {\n continue;\n }\n\n float sourceFracRow =\n float("+c[0]+") *\n (float(dyR) / float("+l[0]+"));\n\n float sourceFracCol =\n float("+c[1]+") *\n (float(dyC) / float("+l[1]+"));\n\n int sourceNearestRow = int(min(\n float(int("+i+") - 1),\n "+n+" ? float(round(sourceFracRow)) :\n float(floor(sourceFracRow))));\n\n int sourceNearestCol = int(min(\n float(int("+a+") - 1),\n "+n+" ? float(round(sourceFracCol)) :\n float(floor(sourceFracCol))));\n\n if (r == sourceNearestRow && c == sourceNearestCol) {\n accumulator += getDy(b, dyR, dyC, d);\n }\n }\n }\n // End loop over dy\n\n setOutput(accumulator);\n }\n "}(t,e,n);return this.compileAndRun(r,[t])},e.prototype.multinomial=function(t,e,n,r){var i=e?t:xi(t),a=i.shape[0],o=i.shape[1],s=new so(a,o,n),u=s.getCustomSetupFunc(r);return this.compileAndRun(s,[i],"int32",u)},e.prototype.oneHot=function(t,e,n,r){var i=new function(t,e,n,r){this.variableNames=["indices"],this.outputShape=[t,e],this.userCode="\n void main() {\n ivec2 coords = getOutputCoords();\n int index = round(getIndices(coords.x));\n setOutput(mix(float("+r+"), float("+n+"),\n float(index == coords.y)));\n }\n "}(t.size,e,n,r);return this.compileAndRun(i,[t])},e.prototype.diag=function(t){var e=new function(t){this.variableNames=["X"],this.outputShape=[t,t],this.userCode="\n void main() {\n ivec2 coords = getOutputCoords();\n float val = coords[0] == coords[1] ? getX(coords[0]) : 0.0;\n setOutput(val);\n }\n "}(t.size);return this.compileAndRun(e,[t])},e.prototype.nonMaxSuppression=function(t,e,n,r,i){return vn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead"),Yi(t.dataSync(),e.dataSync(),n,r,i)},e.prototype.cropAndResize=function(t,e,n,r,i,a){var o=new function(t,e,n,r,i){this.variableNames=["Image","Boxes","BoxInd"],this.outputShape=[];var a=t[0],o=t[1],s=t[2],u=t[3],c=e[0],l=n[0],f=n[1];this.outputShape=[c,l,f,u];var d="bilinear"===r?1:0,h=[o-1+".0",s-1+".0"],p=h[0],m=h[1],g=l>1?[""+(o-1)/(l-1),"(y2-y1) * height_ratio","y1*"+p+" + float(y)*(height_scale)"]:["0.0","0.0","0.5 * (y1+y2) * "+p],v=g[0],y=g[1],b=g[2],x=f>1?[""+(s-1)/(f-1),"(x2-x1) * width_ratio","x1*"+m+" + float(x)*(width_scale)"]:["0.0","0.0","0.5 * (x1+x2) * "+m],w=x[0],k=x[1],_=x[2];this.userCode="\n const float height_ratio = float("+v+");\n const float width_ratio = float("+w+");\n void main() {\n ivec4 coords = getOutputCoords();\n int b = coords[0];\n int y = coords[1];\n int x = coords[2];\n int d = coords[3];\n\n // get box vals\n float y1 = getBoxes(b,0);\n float x1 = getBoxes(b,1);\n float y2 = getBoxes(b,2);\n float x2 = getBoxes(b,3);\n\n // get image in batch index\n int bInd = round(getBoxInd(b));\n if(bInd < 0 || bInd >= "+a+") {\n return;\n }\n\n float height_scale = "+y+";\n float width_scale = "+k+";\n\n float in_y = "+b+";\n if( in_y < 0.0 || in_y > "+p+" ) {\n setOutput(float("+i+"));\n return;\n }\n float in_x = "+_+";\n if( in_x < 0.0 || in_x > "+m+" ) {\n setOutput(float("+i+"));\n return;\n }\n\n vec2 sourceFracIndexCR = vec2(in_x,in_y);\n if("+d+" == 1) {\n // Compute the four integer indices.\n ivec2 sourceFloorCR = ivec2(sourceFracIndexCR);\n ivec2 sourceCeilCR = ivec2(ceil(sourceFracIndexCR));\n\n float topLeft = getImage(b, sourceFloorCR.y, sourceFloorCR.x, d);\n float bottomLeft = getImage(b, sourceCeilCR.y, sourceFloorCR.x, d);\n float topRight = getImage(b, sourceFloorCR.y, sourceCeilCR.x, d);\n float bottomRight = getImage(b, sourceCeilCR.y, sourceCeilCR.x, d);\n\n vec2 fracCR = sourceFracIndexCR - vec2(sourceFloorCR);\n\n float top = topLeft + (topRight - topLeft) * fracCR.x;\n float bottom = bottomLeft + (bottomRight - bottomLeft) * fracCR.x;\n float newValue = top + (bottom - top) * fracCR.y;\n setOutput(newValue);\n } else {\n // Compute the coordinators of nearest neighbor point.\n ivec2 sourceNearestCR = ivec2(floor(\n sourceFracIndexCR + vec2(0.5,0.5)));\n float newValue = getImage(b, sourceNearestCR.y, sourceNearestCR.x, d);\n setOutput(newValue);\n }\n }\n "}(t.shape,e.shape,r,i,a);return this.compileAndRun(o,[t,e,n],"float32")},e.prototype.depthToSpace=function(t,e,n){C(e>1,function(){return"blockSize should be > 1 for depthToSpace, but was: "+e});var r=t.shape[0],i="NHWC"===n?t.shape[1]:t.shape[2],a="NHWC"===n?t.shape[2]:t.shape[3],o="NHWC"===n?t.shape[3]:t.shape[1],s=i*e,u=a*e,c=o/(e*e),l=new Pa("NHWC"===n?[r,s,u,c]:[r,c,s,u],e,n);return this.compileAndRun(l,[t])},e.prototype.split=function(t,e,n){return na(t,e,n)},e.prototype.scatterND=function(t,e,n){var r=ri(0,t,n),i=r.sliceRank,a=r.numUpdates,o=r.sliceSize,s=r.strides,u=r.outputSize,c=[u/o,o],l=t.reshape([a,i]),f=e.reshape([a,o]);if(0===u)return Ui(jn([]),n);var d=Ln(0),h=new lo(a,i,l.rank,f.rank,s,c);return this.compileAndRun(h,[f,l,d]).reshape(n)},e.prototype.sparseToDense=function(t,e,n,r){var i=ri(0,t,n),a=i.sliceRank,o=i.numUpdates,s=i.strides,u=i.outputSize,c=new lo(o,a,t.rank,e.rank,s,[u,1],!1);return this.compileAndRun(c,[e,t,r]).reshape(n)},e.prototype.fft=function(t){return this.fftImpl(t,!1)},e.prototype.ifft=function(t){return this.fftImpl(t,!0)},e.prototype.fftImpl=function(t,e){var n=this.texData.get(t.dataId),r=new La("return real * expR - imag * expI;",t.shape,e),i=new La("return real * expI + imag * expR;",t.shape,e),a=[this.makeComplexComponentTensorInfo(t,n.complexTensors.real),this.makeComplexComponentTensorInfo(t,n.complexTensors.imag)],o=this.compileAndRun(r,a),s=this.compileAndRun(i,a),u=this.complex(o,s).as2D(t.shape[0],t.shape[1]);return o.dispose(),s.dispose(),u},e.prototype.gatherND=function(t,e){var n=e.shape,r=n[n.length-1],i=Jr(t,e),a=i[0],o=i[1],s=i[2],u=i[3],c=e.reshape([o,r]),l=t.reshape([t.size/s,s]),f=new function(t,e,n){this.sliceDim=t,this.strides=e,this.variableNames=["x","indices"],this.outputShape=n;var r=ba(e.length),i=ba(n.length),a=this.sliceDim>1?"strides[j]":"strides";this.userCode="\n "+r+" strides = "+r+"("+this.strides+");\n void main() {\n "+i+" coords = getOutputCoords();\n int flattenIndex = 0;\n for (int j = 0; j < "+this.sliceDim+"; j++) {\n int index = round(getIndices(coords[0], j));\n flattenIndex += index * "+a+";\n }\n setOutput(getX(flattenIndex, coords[1]));\n }\n "}(r,u,[o,s]);return this.compileAndRun(f,[l,c]).reshape(a)},e.prototype.fill=function(t,e,n){if("string"===(n=n||Z(e))){var r=W(n,I(t));return r.fill(e),Wt.makeTensor(r,t,n,this)}var i=new za(t,e),a=i.getCustomSetupFunc(e);return this.compileAndRun(i,[],n,a)},e.prototype.onesLike=function(t){if("string"===t.dtype)throw new Error("onesLike is not supported under string dtype");return this.fill(t.shape,1,t.dtype)},e.prototype.zerosLike=function(t){return this.fill(t.shape,"string"===t.dtype?"":0,t.dtype)},e.prototype.linspace=function(t,e,n){return Wi(t,e,n)},e.prototype.makeTensorInfo=function(t,e){var n=this.write(null,t,e);return this.texData.get(n).usage=null,{dataId:n,shape:t,dtype:e}},e.prototype.makeOutput=function(t,e){var n=this.makeTensorInfo(t,e).dataId;return Wt.makeTensorFromDataId(n,t,e,this)},e.prototype.unpackTensor=function(t){var e=new function(t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!1,this.outputShape=t;var e=t.length,n=sa("rc",e),r=ba(e),i=function(t,e){if(1===t)return"rc";for(var n="",r=0;r<t;r++)n+=e[r],r<t-1&&(n+=",");return n}(e,n),a=n.slice(-2),o=e<=1?"rc":"vec2("+a.join(",")+")";this.userCode="\n void main() {\n "+r+" rc = getOutputCoords();\n vec4 packedInput = getA("+i+");\n\n setOutput(getChannel(packedInput, "+o+"));\n }\n "}(t.shape);return this.runWebGLProgram(e,[t],t.dtype)},e.prototype.packTensor=function(t){var e=new function(t){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0,this.outputShape=t;var e=t.length;if(0===e)this.userCode="\n void main() {\n setOutput(vec4(getA(), 0., 0., 0.));\n }\n ";else{var n=sa("rc",e),r=ba(e),i=function(t,e,n){if(1===t)return"rc > "+e[0];for(var r="",i=t-2;i<t;i++)r+=n[i]+" >= "+e[i],i<t-1&&(r+="||");return r}(e,t,n),a=function(t,e,n,r){if(1===t)return"";var i=r.slice(-2);return"\n int r = "+i[0]+";\n int c = "+i[1]+";\n int rp1 = r + 1;\n int cp1 = c + 1;\n\n bool cEdge = cp1 >= "+e+";\n bool rEdge = rp1 >= "+n+";\n "}(e,t[t.length-1],t[t.length-2],n),o=function(t,e){var n=t.length,r=function(t,e){for(var n=[],r=0;r<=1;r++)for(var i=0;i<=1;i++){for(var a=(0===r?"r":"rp1")+", "+(0===i?"c":"cp1"),o=2;o<t;o++)a=e[e.length-1-o]+","+a;n.push(a)}return n}(n,e);return 1===n?"getA(rc),\n rc + 1 >= "+t[0]+" ? 0. : getA(rc + 1),\n 0, 0":"getA("+r[0]+"),\n cEdge ? 0. : getA("+r[1]+"),\n rEdge ? 0. : getA("+r[2]+"),\n rEdge || cEdge ? 0. : getA("+r[3]+")"}(t,n);this.userCode="\n void main() {\n "+r+" rc = getOutputCoords();\n\n if("+i+") {\n setOutput(vec4(0));\n } else {\n "+a+"\n\n setOutput(vec4("+o+"));\n }\n }\n "}}(t.shape);return this.runWebGLProgram(e,[t],t.dtype,null,!0)},e.prototype.packedReshape=function(t,e){var n=[De(t.shape)].concat(Me(t.shape)),r={dtype:t.dtype,shape:n,dataId:t.dataId},i=new function(t,e){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outputShape=t;for(var n="",r=0;r<4;r++){var i="thisRC = rc;";r%2==1&&(i+="thisRC.z += 1;"),r>1&&(i+="thisRC.y += 1;"),n+="\n "+i+"\n "+(r>0?"if(thisRC.y < rows && thisRC.z < cols){":"")+"\n int flatIndex = getFlatIndex(thisRC);\n\n ivec3 inputRC = inputCoordsFromReshapedOutCoords(flatIndex);\n vec2 inputRCInnerDims = vec2(float(inputRC.y),float(inputRC.z));\n\n result["+r+"] =\n getChannel(getA(inputRC.x, inputRC.y, inputRC.z), inputRCInnerDims);\n "+(r>0?"}":"")+"\n "}this.userCode="\n \n ivec3 inputCoordsFromReshapedOutCoords(int index) {\n "+ca(["r","c","d"],e)+"\n return ivec3(r, c, d);\n }\n \n "+la(t)+"\n\n void main() {\n ivec3 rc = getOutputCoords();\n\n vec4 result = vec4(0.);\n\n ivec3 thisRC;\n int rows = "+t[1]+";\n int cols = "+t[2]+";\n\n "+n+"\n\n setOutput(result);\n }\n "}([De(e)].concat(Me(e)),n),a=this.runWebGLProgram(i,[r],t.dtype,null,!0);return{dataId:a.dataId,shape:e,dtype:a.dtype}},e.prototype.decode=function(t){var e,n=this.texData.get(t),r=n.isPacked,i=n.shape,a=n.dtype,o=Re(i);return e=r?new function(t){this.variableNames=["A"],this.packedInputs=!0,this.packedOutput=!0,this.outPackingScheme=Ht.DENSE;var e=Qt(t),n=ua();this.outputShape=t,this.userCode="\n ivec3 outCoordsFromFlatIndex(int index) {\n "+ca(["r","c","d"],t)+"\n return ivec3(r, c, d);\n }\n\n void main() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+e[0]+", "+e[1]+"));\n int index = 4 * (resTexRC.x * "+e[1]+" + resTexRC.y);\n\n vec4 result = vec4(0.);\n\n for (int i=0; i<4; i++) {\n int flatIndex = index + i;\n ivec3 rc = outCoordsFromFlatIndex(flatIndex);\n result[i] = getChannel(getA(rc.x, rc.y, rc.z), vec2(rc.y, rc.z));\n }\n\n "+n.output+" = result;\n }\n "}(o):new function(t){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0,this.outPackingScheme=Ht.DENSE;var e=Qt(t),n=ua();this.outputShape=t,this.userCode="\n ivec3 outCoordsFromFlatIndex(int index) {\n "+ca(["r","c","d"],t)+"\n return ivec3(r, c, d);\n }\n\n void main() {\n ivec2 resTexRC = ivec2(resultUV.yx *\n vec2("+e[0]+", "+e[1]+"));\n int index = 4 * (resTexRC.x * "+e[1]+" + resTexRC.y);\n\n vec4 result = vec4(0.);\n\n for (int i=0; i<4; i++) {\n int flatIndex = index + i;\n ivec3 rc = outCoordsFromFlatIndex(flatIndex);\n result[i] = getA(rc.x, rc.y, rc.z);\n }\n\n "+n.output+" = result;\n }\n "}(o),{dtype:a,shape:i,dataId:this.runWebGLProgram(e,[{shape:o,dtype:a,dataId:t}],a,null,!0).dataId}},e.prototype.runWebGLProgram=function(t,e,n,r,i){var a=this;void 0===i&&(i=!1);var o=this.makeTensorInfo(t.outputShape,n),s=this.texData.get(o.dataId);if(t.packedOutput&&(s.isPacked=!0),t.outPackingScheme===Ht.DENSE){var u=Qt(t.outputShape);s.texShape=u.map(function(t){return 2*t})}if(null!=t.outTexUsage&&(s.usage=t.outTexUsage),0===I(o.shape))return s.values=U(o.dtype,0),o;var c=[],l=e.map(function(e){if("complex64"===e.dtype)throw new Error("GPGPUProgram does not support complex64 input. For complex64 dtypes, please separate the program into real and imaginary parts.");var n=a.texData.get(e.dataId);if(null==n.texture){if(!t.packedInputs&&I(e.shape)<=f().getNumber("WEBGL_SIZE_UPLOAD_UNIFORM"))return{shape:e.shape,texData:null,isUniform:!0,uniformValues:n.values};t.packedInputs&&(n.isPacked=!0,n.shape=e.shape)}else if(!!n.isPacked!=!!t.packedInputs)e=n.isPacked?a.unpackTensor(e):a.packTensor(e),c.push(e),n=a.texData.get(e.dataId);else if(n.isPacked&&!Pe(n.shape,e.shape)){var r=e,i=e.shape;e.shape=n.shape,e=a.packedReshape(e,i),c.push(e),n=a.texData.get(e.dataId),r.shape=i}return a.uploadToGPU(e.dataId),{shape:e.shape,texData:n,isUniform:!1}});this.uploadToGPU(o.dataId);var d,h={shape:o.shape,texData:s,isUniform:!1},p=function(t,e,n){var r="";l.concat(n).forEach(function(t){var e=null!=t.texData&&null!=t.texData.slice&&t.texData.slice.flatOffset>0,n=t.isUniform?"uniform":t.texData.texShape;r+=t.shape+"_"+n+"_"+e});var i=t.userCode;return t.constructor.name+"_"+r+"_"+i}(t,0,h),m=this.getAndSaveBinary(p,function(){return function(t,e,n,r){var i=e.userCode,a=n.map(function(t,n){var r={logicalShape:t.shape,texShape:t.isUniform?null:t.texData.texShape,isUniform:t.isUniform,isPacked:!t.isUniform&&t.texData.isPacked,flatOffset:null};return null!=t.texData&&null!=t.texData.slice&&t.texData.slice.flatOffset>0&&(r.flatOffset=t.texData.slice.flatOffset),{name:e.variableNames[n],shapeInfo:r}}),o=a.map(function(t){return t.shapeInfo}),s={logicalShape:r.shape,texShape:r.texData.texShape,isUniform:!1,isPacked:r.texData.isPacked,flatOffset:null},u=da(a,s,i,e.packedInputs),c=t.createProgram(u),l=null,d=t.getUniformLocation(c,"NAN",!1);1===f().getNumber("WEBGL_VERSION")&&(l=t.getUniformLocation(c,"INFINITY",!1));for(var h={},p=0;p<e.variableNames.length;p++){var m=e.variableNames[p];h[m]=t.getUniformLocation(c,m,!1),h["offset"+m]=t.getUniformLocation(c,"offset"+m,!1)}return{program:e,source:u,webGLProgram:c,uniformLocations:h,inShapeInfos:o,outShapeInfo:s,infLoc:l,nanLoc:d}}(a.gpgpu,t,l,h)}),g=null!=this.activeTimers;if(g&&(d=this.startTimer()),function(t,e,n,r,i){ao(e.inShapeInfos,n),ao([e.outShapeInfo],[r]);var a=r.texData.texture,o=r.texData.texShape;r.texData.isPacked?t.setOutputPackedMatrixTexture(a,o[0],o[1]):t.setOutputMatrixTexture(a,o[0],o[1]),t.setProgram(e.webGLProgram),1===f().getNumber("WEBGL_VERSION")&&null!==e.infLoc&&t.gl.uniform1f(e.infLoc,1/0),null!==e.nanLoc&&t.gl.uniform1f(e.nanLoc,NaN),n.forEach(function(n,r){var i=e.program.variableNames[r],a=e.uniformLocations[i],o=e.uniformLocations["offset"+i];if(null!=a)if(n.isUniform)if(I(n.shape)<2)t.gl.uniform1f(a,n.uniformValues[0]);else{var s=n.uniformValues;s instanceof Float32Array||(s=new Float32Array(s)),t.gl.uniform1fv(a,s)}else null!=n.texData.slice&&null!=o&&t.gl.uniform1i(o,n.texData.slice.flatOffset),t.setInputMatrixTexture(n.texData.texture,a,r)}),null!=i&&i(t,e.webGLProgram),t.executeProgram()}(this.gpgpu,m,l,h,r),c.forEach(function(t){return a.disposeData(t.dataId)}),g&&(d=this.endTimer(d),this.activeTimers.push({name:t.constructor.name,query:this.getQueryTime(d)})),!f().getBool("WEBGL_LAZILY_UNPACK")&&s.isPacked&&!1===i){var v=this.unpackTensor(o);return this.disposeData(o.dataId),v}return o},e.prototype.compileAndRun=function(t,e,n,r,i){void 0===i&&(i=!1),n=n||e[0].dtype;var a=this.runWebGLProgram(t,e,n,r,i);return Wt.makeTensorFromDataId(a.dataId,a.shape,a.dtype)},e.prototype.getAndSaveBinary=function(t,e){return t in this.binaryCache||(this.binaryCache[t]=e()),this.binaryCache[t]},e.prototype.getTextureManager=function(){return this.textureManager},e.prototype.dispose=function(){var t=this;this.disposed||(f().getBool("IS_TEST")||Object.keys(this.binaryCache).forEach(function(e){t.gpgpu.deleteProgram(t.binaryCache[e].webGLProgram),delete t.binaryCache[e]}),this.textureManager.dispose(),null!=this.canvas&&"undefined"!=typeof HTMLCanvasElement&&this.canvas instanceof HTMLCanvasElement?this.canvas.remove():this.canvas=null,this.gpgpuCreatedLocally&&(this.gpgpu.program=null,this.gpgpu.dispose()),this.disposed=!0)},e.prototype.floatPrecision=function(){var t=this;return null==this.floatPrecisionValue&&(this.floatPrecisionValue=rn(function(){if(!f().get("WEBGL_RENDER_FLOAT32_ENABLED")){var e=f().getBool("DEBUG");f().set("DEBUG",!1);var n=t.abs(Ln(1e-8)).dataSync()[0];if(f().set("DEBUG",e),n>0)return 32}return 16})),this.floatPrecisionValue},e.prototype.epsilon=function(){return 32===this.floatPrecision()?1e-7:1e-4},e.prototype.uploadToGPU=function(t){var e,n=this.texData.get(t),r=n.shape,i=n.dtype,a=n.values,o=n.texture,s=n.usage,u=n.isPacked;if(null==o){var c,l=null!=this.activeTimers;l&&(c=ot());var f=n.texShape;if(null==f&&(f=Fe(r,u),n.texShape=f),null!=a){var d=Re(r),h=void 0,p=f[1],m=f[0],g=a instanceof Uint8Array;u?(p=(e=te(f[0],f[1]))[0],h=new function(t,e,n){void 0===n&&(n=!1),this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0;var r=ua(),i=e[0],a=e[1];this.outputShape=t;var o="",s="result";n&&(s="floor(result * 255. + 0.5)");for(var u=0;u<=1;u++)for(var c=0;c<=1;c++){var l=2*u+c;o+="\n localCoords = coords;\n if(localCoords[2] + "+c+" < "+t[2]+") {\n localCoords[2] += "+c+";\n if(localCoords[1] + "+u+" < "+t[1]+") {\n localCoords[1] += "+u+";\n\n flatIndex = getFlatIndex(localCoords);\n offset = imod(flatIndex, 4);\n\n flatIndex = idiv(flatIndex, 4, 1.);\n\n r = flatIndex / "+a+";\n c = imod(flatIndex, "+a+");\n uv = (vec2(c, r) + halfCR) / vec2("+a+".0, "+i+".0);\n values = "+r.texture2D+"(A, uv);\n\n if(offset == 0) {\n result["+l+"] = values[0];\n } else if(offset == 1) {\n result["+l+"] = values[1];\n } else if(offset == 2) {\n result["+l+"] = values[2];\n } else {\n result["+l+"] = values[3];\n }\n }\n }\n "}this.userCode="\n "+la(t)+"\n\n void main() {\n ivec3 coords = getOutputCoords();\n\n vec4 result = vec4(0.);\n int flatIndex, r, c, offset;\n ivec3 localCoords;\n vec2 uv;\n vec4 values;\n\n "+o+"\n\n "+r.output+" = "+s+";\n }\n "}(d,[m=e[1],p],g)):h=new function(t,e,n){void 0===n&&(n=!1),this.variableNames=["A"];var r=ua(),i=e[0],a=e[1];this.outputShape=t;var o="result";n&&(o="floor(result * 255. + 0.5)"),this.userCode="\n "+la(t)+"\n\n void main() {\n ivec3 coords = getOutputCoords();\n\n int flatIndex = getFlatIndex(coords);\n int offset = imod(flatIndex, 4);\n\n flatIndex = idiv(flatIndex, 4, 1.);\n \n int r = flatIndex / "+a+";\n int c = imod(flatIndex, "+a+");\n vec2 uv = (vec2(c, r) + halfCR) / vec2("+a+".0, "+i+".0);\n vec4 values = "+r.texture2D+"(A, uv);\n\n float result;\n\n if(offset == 0) {\n result = values[0];\n } else if(offset == 1) {\n result = values[1];\n } else if(offset == 2) {\n result = values[2];\n } else {\n result = values[3];\n }\n\n "+r.output+" = vec4("+o+", 0., 0., 0.);\n }\n "}(d,[m,p],g);var v=this.makeTensorInfo([m,p],i);this.texData.get(v.dataId).usage=g?Gt.PIXELS:Gt.UPLOAD,this.gpgpu.uploadDenseMatrixToTexture(this.getTexture(v.dataId),p,m,a);var y=this.runWebGLProgram(h,[v],i,null,!0),b=this.texData.get(y.dataId);n.texture=b.texture,n.texShape=b.texShape,n.isPacked=b.isPacked,n.usage=b.usage,this.disposeData(v.dataId),this.texData.delete(y.dataId),n.values=null,l&&(this.uploadWaitMs+=ot()-c)}else{var x=this.acquireTexture(f,s,i,u);n.texture=x}}},e.prototype.convertAndCacheOnCPU=function(t,e){var n=this.texData.get(t),r=n.dtype;return this.releaseGPUData(t),null!=e&&(n.values=function(t,e){if("float32"===e||"complex64"===e)return t;if("int32"===e||"bool"===e){for(var n="int32"===e?new Int32Array(t.length):new Uint8Array(t.length),r=0;r<n.length;++r)n[r]=Math.round(t[r]);return n}throw new Error("Unknown dtype "+e)}(e,r)),n.values},e.prototype.acquireTexture=function(t,e,n,r){if(this.numBytesInGPU+=this.computeBytes(t,n),!this.warnedAboutMemory&&this.numBytesInGPU>1024*this.numMBBeforeWarning*1024){var i=(this.numBytesInGPU/1024/1024).toFixed(2);this.warnedAboutMemory=!0,console.warn("High memory usage in GPU: "+i+" MB, most likely due to a memory leak")}return this.textureManager.acquireTexture(t,e,r)},e.prototype.computeBytes=function(t,e){return t[0]*t[1]*$(e)},e}(_i);Vt()&&Wt.registerBackend("webgl",function(){return new Uo},2);var Wo=Dn({square_:function(t){var e=xn(t,"x","square"),n=[e];return Wt.runKernelFunc(function(t,n){return n([e]),t.square(e)},{x:e},null,"Square",{},n,[])}}),Vo="SquaredDifference",qo=Dn({squaredDifference_:function(t,e){var n,r=xn(t,"a","squaredDifference"),i=xn(e,"b","squaredDifference");n=Ft(r,i),r=n[0],i=n[1],Ci(r.shape,i.shape);var a={a:r,b:i},o=[r,i];return Wt.runKernelFunc(function(t,e){var n=t.squaredDifference(r,i);return e([r,i]),n},a,function(t,e){var n=e[0],r=e[1],i=Ln(2);return{a:function(){return t.mul(n.sub(r).mul(i))},b:function(){return t.mul(r.sub(n).mul(i))}}},Vo,{},o,[])}}),Ho=Dn({abs_:function(t){var e=xn(t,"x","abs");return"complex64"===e.dtype?Wt.runKernelFunc(function(t){return t.complexAbs(e)},{$x:e}):Wt.runKernelFunc(function(t,n){var r=t.abs(e);return n([e]),r},{x:e},function(t,e){var n=e[0];return{x:function(){return t.mul(n.toFloat().step(-1))}}},"Abs")}}),Go=Dn({acos_:function(t){var e=xn(t,"x","acos");return Wt.runKernelFunc(function(t,n){var r=t.acos(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.divStrict(Ln(1).sub(n.toFloat().square()).sqrt()).neg()}}})}}),$o=Dn({acosh_:function(t){var e=xn(t,"x","acosh");return Wt.runKernelFunc(function(t,n){var r=t.acosh(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.divStrict(n.toFloat().square().sub(1).sqrt())}}})}}),Ko=Dn({asin_:function(t){var e=xn(t,"x","asin");return Wt.runKernelFunc(function(t,n){var r=t.asin(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.divStrict(Ln(1).sub(n.toFloat().square()).sqrt())}}})}}),Xo=Dn({asinh_:function(t){var e=xn(t,"x","asinh");return Wt.runKernelFunc(function(t,n){var r=t.asinh(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.divStrict(Ln(1).add(n.toFloat().square()).sqrt())}}})}}),Yo=Dn({atan_:function(t){var e=xn(t,"x","atan");return Wt.runKernelFunc(function(t,n){var r=t.atan(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.div(n.toFloat().square().add(1))}}})}}),Jo=Dn({atanh_:function(t){var e=xn(t,"x","atanh");return Wt.runKernelFunc(function(t,n){var r=t.atanh(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.div(Ln(1).sub(n.toFloat().square()))}}})}}),Zo=Dn({ceil_:function(t){var e=xn(t,"x","ceil");return Wt.runKernelFunc(function(t){return t.ceil(e)},{$x:e},function(t){return{$x:function(){return Zn(t)}}})}}),Qo=Dn({clipByValue_:function(t,e,n){var r=xn(t,"x","clipByValue");C(e<=n,function(){return"Error in clip: min ("+e+") must be less than or equal to max ("+n+")."});var i=[r],a={min:e,max:n};return Wt.runKernelFunc(function(t,i){var a=t.clip(r,e,n);return i([r]),a},{x:r},function(t,r){var i=r[0];return{x:function(){return t.where(i.greaterEqual(e).logicalAnd(i.lessEqual(n)),Zn(t))}}},"ClipByValue",a,i)}}),ts=Dn({cos_:function(t){var e=xn(t,"x","cos"),n=[e];return Wt.runKernelFunc(function(t,n){var r=t.cos(e);return n([e]),r},{x:e},function(t,e){var n=e[0];return{x:function(){return n.toFloat().sin().neg().mul(t)}}},"Cos",{},n)}}),es=Dn({cosh_:function(t){var e=xn(t,"x","cosh");return Wt.runKernelFunc(function(t,n){var r=t.cosh(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return n.toFloat().sinh().mulStrict(t)}}})}}),ns=Dn({erf_:function(t){var e=xn(t,"x","erf");return C("int32"===e.dtype||"float32"===e.dtype,function(){return"Input dtype must be `int32` or `float32`."}),"int32"===e.dtype&&(e=e.toFloat()),Wt.runKernelFunc(function(t,n){var r=t.erf(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.mul(n.square().neg().exp().mul(2/Math.sqrt(Math.PI)))}}})}}),rs=Dn({exp_:function(t){var e=xn(t,"x","exp");return Wt.runKernelFunc(function(t,n){var r=t.exp(e);return n([r]),r},{x:e},function(t,e){return{x:function(){return t.mulStrict(e[0])}}},"Exp",{},[],[!0])}}),is=Dn({expm1_:function(t){var e=xn(t,"x","expm1");return Wt.runKernelFunc(function(t,n){var r=t.expm1(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.mul(n.exp())}}})}}),as=Dn({floor_:function(t){var e=xn(t,"x","floor");return Wt.runKernelFunc(function(t){return t.floor(e)},{$x:e},function(t){return{$x:function(){return Zn(t)}}})}}),os=Dn({log_:function(t){var e=xn(t,"x","log"),n=[e];return Wt.runKernelFunc(function(t,n){var r=t.log(e);return n([e]),r},{x:e},function(t,e){var n=e[0];return{x:function(){return t.div(n.toFloat())}}},"Log",{},n)}}),ss=Dn({log1p_:function(t){var e=xn(t,"x","log1p");return Wt.runKernelFunc(function(t,n){var r=t.log1p(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.div(n.add(1))}}})}}),us=Dn({logSigmoid_:function(t){var e=xn(t,"x","logSigmoid");return Wt.runKernelFunc(function(t,n){var r=t.softplus(e.neg()).neg();return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.mul(n.neg().sigmoid())}}})}}),cs=Dn({neg_:function(t){var e=xn(t,"x","neg"),n=[e];return Wt.runKernelFunc(function(t){return t.neg(e)},{x:e},function(t){return{x:function(){return t.neg()}}},"Neg",{},n)}}),ls=Dn({reciprocal_:function(t){var e=xn(t,"x","reciprocal");return Wt.runKernelFunc(function(t,n){var r=t.reciprocal(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.div(n.square().neg())}}})}}),fs=Dn({round_:function(t){var e=xn(t,"x","round");return Wt.runKernelFunc(function(t){return t.round(e)},{$x:e},function(t){return{$x:function(){return Zn(t)}}})}}),ds=Dn({rsqrt_:function(t){var e=xn(t,"x","rsqrt"),n=[e];return Wt.runKernelFunc(function(t,n){var r=t.rsqrt(e);return n([e]),r},{x:e},function(t,e){var n=e[0];return{x:function(){return t.div(n.pow(1.5).mul(2)).neg()}}},"Rsqrt",{},n)}}),hs=Dn({sigmoid_:function(t){var e=xn(t,"x","sigmoid");return Wt.runKernelFunc(function(t,n){var r=t.sigmoid(e);return n([r]),r},{x:e},function(t,e){var n=e[0];return{x:function(){return t.mul(n.mul(Ln(1).sub(n)))}}},"Sigmoid")}}),ps=Dn({sign_:function(t){var e=xn(t,"x","sign");return Wt.runKernelFunc(function(t){return t.sign(e)},{$x:e},function(t){return{$x:function(){return Zn(t)}}})}}),ms=Dn({isNaN_:function(t){var e=xn(t,"x","isNaN");return Wt.runKernelFunc(function(t){return t.isNaN(e)},{$x:e},function(t){return{$x:function(){return Zn(t)}}})}}),gs=Dn({isInf_:function(t){var e=xn(t,"x","isInf");return Wt.runKernelFunc(function(t){return t.isInf(e)},{$x:e},function(t){return{$x:function(){return Zn(t)}}})}}),vs=Dn({isFinite_:function(t){var e=xn(t,"x","isFinite");return Wt.runKernelFunc(function(t){return t.isFinite(e)},{$x:e},function(t){return{$x:function(){return Zn(t)}}})}}),ys=Dn({sin_:function(t){var e=xn(t,"x","sin"),n=[e];return Wt.runKernelFunc(function(t,n){var r=t.sin(e);return n([e]),r},{x:e},function(t,e){var n=e[0];return{x:function(){return n.toFloat().cos().mul(t)}}},"Sin",{},n)}}),bs=Dn({sinh_:function(t){var e=xn(t,"x","sinh");return Wt.runKernelFunc(function(t,n){var r=t.sinh(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return n.toFloat().cosh().mulStrict(t)}}})}}),xs=Dn({softplus_:function(t){var e=xn(t,"x","softplus");return Wt.runKernelFunc(function(t,n){var r=t.softplus(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.mul(n.sigmoid())}}})}}),ws=Dn({sqrt_:function(t){var e=xn(t,"x","sqrt");return Wt.runKernelFunc(function(t,n){var r=t.sqrt(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.div(n.toFloat().sqrt().mul(2))}}})}}),ks=Dn({step_:function(t,e){void 0===e&&(e=0);var n=xn(t,"x","step");return Wt.runKernelFunc(function(t){return t.step(n,e)},{$x:n},function(t){return{$x:function(){return Zn(t)}}})}}),_s=Dn({tan_:function(t){var e=xn(t,"x","tan");return Wt.runKernelFunc(function(t,n){var r=t.tan(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return t.div(n.cos().square())}}})}}),Es=Dn({tanh_:function(t){var e=xn(t,"x","tanh");return Wt.runKernelFunc(function(t,n){var r=t.tanh(e);return n([r]),r},{x:e},function(t,e){var n=e[0];return{x:function(){return Ln(1).sub(n.square()).mulStrict(t)}}},"Tanh",{},null,[!0])}});function Os(t,e,n,r,i,a){var o,s,u=xn(t,"x","batchNorm"),c=xn(e,"mean","batchNorm"),l=xn(n,"variance","batchNorm");return null!=i&&(o=xn(i,"scale","batchNorm")),null!=r&&(s=xn(r,"offset","batchNorm")),C(2===u.rank,function(){return"Error in batchNorm3D: x must be rank 3 but got rank "+u.rank+"."}),C(2===c.rank||1===c.rank,function(){return"Error in batchNorm2D: mean must be rank 2 or rank 1 but got rank "+c.rank+"."}),C(2===l.rank||1===l.rank,function(){return"Error in batchNorm2D: variance must be rank 2 or rank 1 but got rank "+l.rank+"."}),null!=o&&C(2===o.rank||1===o.rank,function(){return"Error in batchNorm2D: scale must be rank 2 or rank 1 but got rank "+o.rank+"."}),null!=s&&C(2===s.rank||1===s.rank,function(){return"Error in batchNorm2D: offset must be rank 2 or rank 1 but got rank "+s.rank+"."}),As(u,c,l,s,o,a)}function Ss(t,e,n,r,i,a){var o,s,u=xn(t,"x","batchNorm"),c=xn(e,"mean","batchNorm"),l=xn(n,"variance","batchNorm");return null!=i&&(o=xn(i,"scale","batchNorm")),null!=r&&(s=xn(r,"offset","batchNorm")),C(3===u.rank,function(){return"Error in batchNorm3D: x must be rank 3 but got rank "+u.rank+"."}),C(3===c.rank||1===c.rank,function(){return"Error in batchNorm3D: mean must be rank 3 or rank 1 but got rank "+c.rank+"."}),C(3===l.rank||1===l.rank,function(){return"Error in batchNorm3D: variance must be rank 3 or rank 1 but got rank "+l.rank+"."}),null!=o&&C(3===o.rank||1===o.rank,function(){return"Error in batchNorm3D: scale must be rank 3 or rank 1 but got rank "+o.rank+"."}),null!=s&&C(3===s.rank||1===s.rank,function(){return"Error in batchNorm3D: offset must be rank 3 or rank 1 but got rank "+s.rank+"."}),As(u,c,l,s,o,a)}function Cs(t,e,n,r,i,a){var o,s,u=xn(t,"x","batchNorm"),c=xn(e,"mean","batchNorm"),l=xn(n,"variance","batchNorm");return null!=i&&(o=xn(i,"scale","batchNorm")),null!=r&&(s=xn(r,"offset","batchNorm")),C(4===u.rank,function(){return"Error in batchNorm4D: x must be rank 4 but got rank "+u.rank+"."}),C(4===c.rank||1===c.rank,function(){return"Error in batchNorm4D: mean must be rank 4 or rank 1 but got rank "+c.rank+"."}),C(4===l.rank||1===l.rank,function(){return"Error in batchNorm4D: variance must be rank 4 or rank 1 but got rank "+l.rank+"."}),null!=o&&C(4===o.rank||1===o.rank,function(){return"Error in batchNorm4D: scale must be rank 4 or rank 1 but got rank "+o.rank+"."}),null!=s&&C(4===s.rank||1===s.rank,function(){return"Error in batchNorm4D: offset must be rank 4 or rank 1 but got rank "+s.rank+"."}),As(u,c,l,s,o,a)}function As(t,e,n,r,i,a){null==a&&(a=.001);var o,s,u,c=xn(t,"x","batchNorm"),l=xn(e,"mean","batchNorm"),f=xn(n,"variance","batchNorm");null!=i&&(o=xn(i,"scale","batchNorm")),null!=r&&(s=xn(r,"offset","batchNorm")),C(l.rank===f.rank,function(){return"Batch normalization gradient requires mean and variance to have equal ranks."}),C(null==s||l.rank===s.rank,function(){return"Batch normalization gradient requires mean and offset to have equal ranks."}),C(null==o||l.rank===o.rank,function(){return"Batch normalization gradient requires mean and scale to have equal ranks."}),u=0===c.rank||1===c.rank?c.as4D(1,1,1,c.size):2===c.rank?c.as4D(1,1,c.shape[0],c.shape[1]):3===c.rank?c.as4D(1,c.shape[0],c.shape[1],c.shape[2]):c;var d=[c,l,f,o];return Wt.runKernelFunc(function(t,e){var n=t.batchNormalization(u,Ns(l),Ns(f),a,Ns(o),Ns(s));return e([c,l,f,o]),n},{x:c,mean:l,variance:f,scale:o,offset:s},function(t,e){var n=e,r=n[0],i=n[1],o=n[2],s=n[3],c=null==s?Ln(1):s,l=Si(i.shape,u.shape),f=[];if(1===i.rank){for(var d=0;d<u.shape.length-1;++d)f.push(u.shape[d]);f.push(1)}var h=r.sub(i),p=t.mul(c),m=ds(o.add(Ln(a))),g=m.mul(m).mul(m).mul(Ln(-.5));return{x:function(){return 1===i.rank?t.mul(Wr(m.as4D(1,1,1,i.shape[0]),f)).mul(c).reshape(r.shape):t.mul(m).mul(c).reshape(r.shape)},mean:function(){var t=m.mul(Ln(-1)).mul(p);return 1===i.rank&&(t=t.sum(l)),t.reshape(i.shape)},variance:function(){var t=g.mul(h).mul(p);return 1===i.rank&&(t=t.sum(l)),t.reshape(i.shape)},scale:function(){var e=h.mul(m),n=t.mul(e);return 1===i.rank&&(n=n.sum(l)),n.reshape(i.shape)},offset:function(){var e=t;return 1===i.rank&&(e=e.sum(l)),e.reshape(i.shape)}}},"BatchNormalization",{varianceEpsilon:a},d).reshape(c.shape)}function Ns(t){return null==t?null:0===t.rank?t.as1D():1===t.rank?t:2===t.rank?t.as4D(1,1,t.shape[0],t.shape[1]):3===t.rank?t.as4D(1,t.shape[0],t.shape[1],t.shape[2]):t}function Ts(){Ze("tf.batchNormalization() is going away. Use tf.batchNorm() instead, and note the positional argument change of scale, offset, and varianceEpsilon")}var Is=Dn({batchNormalization2d_:function(t,e,n,r,i,a){return void 0===r&&(r=.001),Ts(),Os(t,e,n,a,i,r)}}),Ds=Dn({batchNormalization3d_:function(t,e,n,r,i,a){return void 0===r&&(r=.001),Ts(),Ss(t,e,n,a,i,r)}}),Ms=Dn({batchNormalization4d_:function(t,e,n,r,i,a){return void 0===r&&(r=.001),Ts(),Cs(t,e,n,a,i,r)}}),Rs=Dn({batchNormalization_:function(t,e,n,r,i,a){return void 0===r&&(r=.001),Ts(),As(t,e,n,a,i,r)}}),Fs=Dn({batchNorm_:As}),js=Dn({batchNorm2d_:Os}),Ps=Dn({batchNorm3d_:Ss}),Ls=Dn({batchNorm4d_:Cs}),zs=Dn({logicalAnd_:function(t,e){var n=xn(t,"a","logicalAnd","bool"),r=xn(e,"b","logicalAnd","bool");return Ci(n.shape,r.shape),Wt.runKernelFunc(function(t){return t.logicalAnd(n,r)},{a:n,b:r},null,"LogicalAnd")}}),Bs=Dn({logicalNot_:function(t){var e=xn(t,"x","logicalNot","bool");return Wt.runKernelFunc(function(t){return t.logicalNot(e)},{$x:e})}}),Us=Dn({logicalOr_:function(t,e){var n=xn(t,"a","logicalOr","bool"),r=xn(e,"b","logicalOr","bool");return Ci(n.shape,r.shape),Wt.runKernelFunc(function(t){return t.logicalOr(n,r)},{$a:n,$b:r})}}),Ws=Dn({logicalXor_:function(t,e){var n=xn(t,"a","logicalXor","bool"),r=xn(e,"b","logicalXor","bool");return Ci(n.shape,r.shape),Us(t,e).logicalAnd(zs(t,e).logicalNot())}}),Vs=Dn({where_:function(t,e,n){var r=xn(e,"a","where"),i=xn(n,"b","where"),a=xn(t,"condition","where","bool");return A(r.shape,i.shape,"Error in where: "),1===a.rank?C(a.shape[0]===r.shape[0],function(){return"The first dimension of `a` must match the size of `condition`."}):A(a.shape,i.shape,"Error in where: "),Wt.runKernelFunc(function(t,e){var n=t.select(a,r,i);return e([a]),n},{$condition:a,$a:r,$b:i},function(t,e){var n=e[0];return{$condition:function(){return Zn(n).toFloat()},$a:function(){return t.mul(n.cast(t.dtype))},$b:function(){return t.mul(n.logicalNot().cast(t.dtype))}}})}}),qs=function(t){return u(this,void 0,void 0,function(){var e,n,r;return c(this,function(i){switch(i.label){case 0:return[4,(e=xn(t,"condition","whereAsync","bool")).data()];case 1:return n=i.sent(),r=aa(e.shape,n),t!==e&&e.dispose(),[2,r]}})})},Hs=Dn({add_:function(t,e){var n,r=xn(t,"a","add"),i=xn(e,"b","add");n=Ft(r,i),r=n[0],i=n[1];var a=Ci(r.shape,i.shape);return Wt.runKernelFunc(function(t){return t.add(r,i)},{a:r,b:i},function(t){return{a:function(){var e=t,n=Si(r.shape,a);return n.length>0&&(e=e.sum(n)),e.reshape(r.shape)},b:function(){var e=t,n=Si(i.shape,a);return n.length>0&&(e=e.sum(n)),e.reshape(i.shape)}}},"Add")}}),Gs=Dn({addN_:function(t){C(Array.isArray(t),function(){return"The argument passed to tf.addN() must be a list of tensors"}),C(t.length>=1,function(){return"Must pass at least one tensor to tf.addN(), but got "+t.length});var e=t.map(function(t,e){return xn(t,"tensors"+e,"addN")}),n=e[0];e.forEach(function(t){if(t.dtype!==n.dtype)throw new Error("All tensors passed to tf.addN() must have the same dtype")}),e.forEach(function(t){if(!D(t.shape,n.shape))throw new Error("All tensors passed to tf.addN() must have the same shape")});var r=e;return Wt.runKernelFunc(function(t){return t.addN(e)},r,function(t){var n={};return e.forEach(function(e,r){n[r]=function(){return t.clone()}}),n},"AddN")}}),$s=Dn({addStrict_:function(t,e){var n=xn(t,"a","addStrict"),r=xn(e,"b","addStrict");return A(n.shape,r.shape,"Error in addStrict: "),n.add(r)}}),Ks=Dn({atan2_:function(t,e){var n,r=xn(t,"a","atan2"),i=xn(e,"b","atan2");n=Ft(r,i),r=n[0],i=n[1];var a=Ci(r.shape,i.shape);return Wt.runKernelFunc(function(t,e){var n=t.atan2(r,i);return e([r,i]),n},{$a:r,$b:i},function(t,e){var n=e[0],r=e[1];return{$a:function(){var e=Hs(n.square(),r.square()),i=t.mul(r.div(e)),o=Si(n.shape,a);return o.length>0&&(i=i.sum(o)),i.reshape(n.shape)},$b:function(){var e=Hs(n.square(),r.square()),i=cs(t.mul(n.div(e))),o=Si(r.shape,a);return o.length>0&&(i=i.sum(o)),i.reshape(r.shape)}}})}}),Xs=Dn({div_:function(t,e){var n,r=xn(t,"a","div"),i=xn(e,"b","div");if(n=Ft(r,i),r=n[0],i=n[1],"int32"===r.dtype&&"int32"===i.dtype)return Zs(r,i);var a=Ci(r.shape,i.shape);return Wt.runKernelFunc(function(t,e){var n=t.realDivide(r,i);return e([r,i]),n},{a:r,b:i},function(t,e){var n=e[0],r=e[1];return{a:function(){var e=t.div(r.toFloat()),i=Si(n.shape,a);return i.length>0?e.sum(i).reshape(n.shape):e},b:function(){var e=t.mul(n.toFloat()),i=Si(r.shape,a);i.length>0&&(e=e.sum(i).reshape(r.shape));var o=r.square();return e.div(o.toFloat()).neg()}}},"Div")}}),Ys=Dn({divNoNan_:function(t,e){var n,r=xn(t,"a","div"),i=xn(e,"b","div");r=(n=Ft(r,i))[0],i=n[1];var a=Xs(r,i),o=Zn(a),s=i.equal(o);return Vs(s,o,a)}}),Js=Dn({divStrict_:function(t,e){var n=xn(t,"a","div"),r=xn(e,"b","div");return A(n.shape,r.shape,"Error in divideStrict: "),n.div(r)}}),Zs=Dn({floorDiv_:function(t,e){var n,r=xn(t,"a","floorDiv"),i=xn(e,"b","floorDiv");n=Ft(r,i),r=n[0],i=n[1];var a=Ci(r.shape,i.shape);return Wt.runKernelFunc(function(t,e){var n=t.floorDiv(r,i);return e([r,i]),n},{a:r,b:i},function(t,e){var n=e[0],r=e[1];return{a:function(){var e=t.div(r.toFloat()),i=Si(n.shape,a);return i.length>0?e.sum(i).reshape(n.shape):e},b:function(){var e=t.mul(n.toFloat()),i=Si(r.shape,a);i.length>0&&(e=e.sum(i).reshape(r.shape));var o=r.square();return e.div(o.toFloat()).neg()}}},"FloorDiv")}}),Qs=Dn({maximum_:function(t,e){var n,r=xn(t,"a","maximum"),i=xn(e,"b","maximum");return n=Ft(r,i),r=n[0],i=n[1],"bool"===r.dtype&&(r=r.toInt(),i=i.toInt()),Ci(r.shape,i.shape),Wt.runKernelFunc(function(t,e){var n=t.maximum(r,i);return e([r,i]),n},{a:r,b:i},function(t,e){var n=e[0],r=e[1];return{a:function(){return t.mul(n.greaterEqual(r).toFloat())},b:function(){return t.mul(n.less(r).toFloat())}}},"Maximum")}}),tu=Dn({maximumStrict_:function(t,e){var n=xn(t,"a","maximumStrict"),r=xn(e,"b","maximumStrict");return A(n.shape,r.shape,"Error in maximumStrict: "),n.maximum(r)}}),eu=Dn({minimum_:function(t,e){var n,r=xn(t,"a","minimum"),i=xn(e,"b","minimum");return n=Ft(r,i),r=n[0],i=n[1],"bool"===r.dtype&&(r=r.toInt(),i=i.toInt()),Ci(r.shape,i.shape),Wt.runKernelFunc(function(t,e){var n=t.minimum(r,i);return e([r,i]),n},{a:r,b:i},function(t,e){var n=e[0],r=e[1];return{a:function(){return t.mul(n.lessEqual(r).toFloat())},b:function(){return t.mul(n.greater(r).toFloat())}}},"Minimum")}}),nu=Dn({minimumStrict_:function(t,e){var n=xn(t,"a","minimumStrict"),r=xn(e,"b","minimumStrict");return A(n.shape,r.shape,"Error in minimumStrict: "),n.minimum(r)}}),ru=Dn({mod_:function(t,e){var n,r=xn(t,"a","mod"),i=xn(e,"b","mod");n=Ft(r,i),r=n[0],i=n[1];var a=Ci(r.shape,i.shape);return Wt.runKernelFunc(function(t,e){var n=t.mod(r,i);return e([r,i]),n},{$a:r,$b:i},function(t,e){var n=e[0],r=e[1];return{$a:function(){var e=Si(n.shape,a);return e.length>0?t.sum(e).reshape(n.shape):t},$b:function(){var e=t.mul(n.div(r).floor().neg()),i=Si(r.shape,a);return i.length>0?e.sum(i).reshape(r.shape):e}}})}}),iu=Dn({modStrict_:function(t,e){var n=xn(t,"a","modStrict"),r=xn(e,"b","modStrict");return A(n.shape,r.shape,"Error in modStrict: "),n.mod(r)}}),au=Dn({mul_:function(t,e){var n,r=xn(t,"a","mul"),i=xn(e,"b","mul");n=Ft(r,i),r=n[0],i=n[1];var a=Ci(r.shape,i.shape);return Wt.runKernelFunc(function(t,e){var n=t.multiply(r,i);return e([r,i]),n},{a:r,b:i},function(t,e){var n=e[0],r=e[1];return{a:function(){var e=t.mul(r.toFloat()),i=Si(n.shape,a);return i.length>0?e.sum(i).reshape(n.shape):e},b:function(){var e=t.mul(n.toFloat()),i=Si(r.shape,a);return i.length>0?e.sum(i).reshape(r.shape):e}}},"Mul")}}),ou=Dn({mulStrict_:function(t,e){var n=xn(t,"a","mul"),r=xn(e,"b","mul");return A(n.shape,r.shape,"Error in multiplyStrict: "),n.mul(r)}}),su=Dn({pow_:function(t,e){var n,r=xn(t,"base","pow"),i=xn(e,"exp","pow");n=Ft(r,i),r=n[0],i=n[1];var a=Ci(r.shape,i.shape),o=[r,i];return Wt.runKernelFunc(function(t,e){var n=t.pow(r,i);return e([r,i,n]),n},{a:r,b:i},function(t,e){var n=e[0],r=e[1],i=e[2];return{a:function(){var e=r.toFloat(),i=t.mul(e.mul(n.pow(e.sub(Ln(1))))),o=Si(n.shape,a);return o.length>0&&(i=i.sum(o)),i.reshape(n.shape)},b:function(){var e=n.greater(0),o=n.log().where(e,Zn(n)),s=t.mul(i.mul(o)),u=Si(r.shape,a);return u.length>0&&(s=s.sum(u)),s.reshape(r.shape)}}},"Pow",{},o,[!0])}}),uu=Dn({powStrict_:function(t,e){return A(t.shape,e.shape,"Error in powStrict: "),t.pow(e)}}),cu=Dn({squaredDifferenceStrict_:function(t,e){var n=xn(t,"a","squaredDifferenceStrict"),r=xn(e,"b","squaredDifferenceStrict");return A(n.shape,r.shape,"Error in squaredDifferenceStrict: "),n.squaredDifference(r)}}),lu=Dn({sub_:function(t,e){var n,r=xn(t,"a","sub"),i=xn(e,"b","sub");n=Ft(r,i),r=n[0],i=n[1];var a=Ci(r.shape,i.shape);return Wt.runKernelFunc(function(t){return t.subtract(r,i)},{a:r,b:i},function(t){return{a:function(){var e=t,n=Si(r.shape,a);return n.length>0&&(e=e.sum(n)),e.reshape(r.shape)},b:function(){var e=t,n=Si(i.shape,a);return n.length>0&&(e=e.sum(n)),e.neg().reshape(i.shape)}}},"Sub")}}),fu=Dn({subStrict_:function(t,e){var n=xn(t,"a","subStrict"),r=xn(e,"b","subStrict");return A(n.shape,r.shape,"Error in subStrict: "),n.sub(r)}}),du=Dn({equal_:function(t,e){var n,r=xn(t,"a","equal"),i=xn(e,"b","equal");return n=Ft(r,i),r=n[0],i=n[1],Ci(r.shape,i.shape),Wt.runKernelFunc(function(t){return t.equal(r,i)},{$a:r,$b:i})}}),hu=Dn({equalStrict_:function(t,e){var n=xn(t,"a","equalStrict"),r=xn(e,"b","equalStrict");return A(n.shape,r.shape,"Error in equalStrict: "),n.equal(r)}}),pu=Dn({greater_:function(t,e){var n,r=xn(t,"a","greater"),i=xn(e,"b","greater");return n=Ft(r,i),r=n[0],i=n[1],Ci(r.shape,i.shape),Wt.runKernelFunc(function(t){return t.greater(r,i)},{a:r,b:i},null,"Greater")}}),mu=Dn({greaterEqual_:function(t,e){var n,r=xn(t,"a","greaterEqual"),i=xn(e,"b","greaterEqual");return n=Ft(r,i),r=n[0],i=n[1],Ci(r.shape,i.shape),Wt.runKernelFunc(function(t,e){var n=t.greaterEqual(r,i);return e([r,i]),n},{a:r,b:i},function(t,e){var n=e[0],r=e[1];return{a:function(){return Zn(n)},b:function(){return Zn(r)}}},"GreaterEqual")}}),gu=Dn({greaterEqualStrict_:function(t,e){var n=xn(t,"a","greaterEqualStrict"),r=xn(e,"b","greaterEqualStrict");return A(n.shape,r.shape,"Error in greaterEqualStrict: "),n.greaterEqual(r)}}),vu=Dn({greaterStrict_:function(t,e){var n=xn(t,"a","greaterStrict"),r=xn(e,"b","greaterStrict");return A(n.shape,r.shape,"Error in greaterStrict: "),n.greater(r)}}),yu=Dn({less_:function(t,e){var n,r=xn(t,"a","less"),i=xn(e,"b","less");return n=Ft(r,i),r=n[0],i=n[1],Ci(r.shape,i.shape),Wt.runKernelFunc(function(t){return t.less(r,i)},{a:r,b:i},null,"Less")}}),bu=Dn({lessEqual_:function(t,e){var n,r=xn(t,"a","lessEqual"),i=xn(e,"b","lessEqual");return n=Ft(r,i),r=n[0],i=n[1],Ci(r.shape,i.shape),Wt.runKernelFunc(function(t,e){var n=t.lessEqual(r,i);return e([r,i]),n},{a:r,b:i},null,"LessEqual")}}),xu=Dn({lessEqualStrict_:function(t,e){var n=xn(t,"a","lessEqualStrict"),r=xn(e,"b","lessEqualStrict");return A(n.shape,r.shape,"Error in lessEqualStrict: "),n.lessEqual(r)}}),wu=Dn({lessStrict_:function(t,e){var n=xn(t,"a","lessStrict"),r=xn(e,"b","lessStrict");return A(n.shape,r.shape,"Error in lessStrict: "),n.less(r)}}),ku=Dn({notEqual_:function(t,e){var n,r=xn(t,"a","notEqual"),i=xn(e,"b","notEqual");return n=Ft(r,i),r=n[0],i=n[1],Ci(r.shape,i.shape),Wt.runKernelFunc(function(t){return t.notEqual(r,i)},{a:r,b:i},null,"NotEqual")}}),_u=Dn({notEqualStrict_:function(t,e){var n=xn(t,"a","notEqualStrict"),r=xn(e,"b","notEqualStrict");return A(n.shape,r.shape,"Error in notEqualStrict: "),n.notEqual(r)}});function Eu(t,e){for(var n=[],r=t;r<e;++r)n.push(r);return n}function Ou(t){for(var e=[],n=0;n<t.length;++n)for(var r=0;r<t[n].length;++r)e.push(t[n][r]);return e}var Su=Dn({gather_:function(t,e,n){void 0===n&&(n=0);var r=xn(t,"x","gather"),i=xn(e,"indices","gather","int32");n=z(n,r.shape)[0];var a=function(t,e,n){for(var r=t.shape[n],i=[],a=1,o=1,s=0;s<n;s++)i.push(t.shape[s]),a*=t.shape[s];for(s=0;s<e.rank;s++)i.push(e.shape[s]);for(s=n+1;s<t.rank;s++)i.push(t.shape[s]),o*=t.shape[s];return{batchSize:a,sliceSize:o,dimSize:r,outputShape:i}}(r,i,n);return Wt.runKernelFunc(function(t,e){var a=t.gather(r,i.flatten(),n);return e([i]),a},{x:r,indices:i},function(t,e){var i=e[0];return{x:function(){var e=r.shape,a=i.size,o=e.slice(0,n),s=o.length,u=e.slice(n,e.length).slice(1),c=u.length,l=Eu(0,s),f=Eu(s+1,s+1+c),d=Ou([o,[a],u]),h=t.reshape(d),p=i.reshape([a]),m=Ou([[s],l,f]),g=h.transpose(m),v=Cu(g,p,r.shape[n]),y=An(m);return v.transpose(y)},indices:function(){return i}}},"Gather",{axis:n}).reshape(a.outputShape)}}),Cu=Dn({unsortedSegmentSum_:function(t,e,n){var r=xn(t,"x","unsortedSegmentSum"),i=xn(e,"segmentIds","unsortedSegmentSum","int32");return C(M(n),function(){return"numSegments must be of dtype int"}),Wt.runKernelFunc(function(t,e){var a=t.unsortedSegmentSum(r,i,n);return e([i]),a},{$x:r},function(t,e){var n=e[0];return{$x:function(){return function(t,e){for(var n=Qs(e,Zn(e)),r=Su(t,n),i=mu(e,Ln(0,"int32")),a=r.rank-i.rank,o=0;o<a;++o)i=Or(i,o+1);i=zs(i,Gn(r.shape,"bool"));var s=Zn(r);return Vs(i,r,s)}(t,n)}}})}}),Au=function(t,e,n){return u(this,void 0,void 0,function(){var r,i,a,o,s,u,l,f,d,h,p,m,g;return c(this,function(c){switch(c.label){case 0:for(r=xn(t,"tensor","boolMask"),i=xn(e,"mask","boolMask","bool"),a=null==n?0:n,o=i.rank,s=r.shape,C(o>0,function(){return"mask cannot be scalar"}),A(s.slice(a,a+o),i.shape,"mask's shape must match the first K dimensions of tensor's shape,"),u=1,l=a;l<a+o;l++)u*=s[l];return f=s.slice(0,a).concat([u],s.slice(a+o)),d=r.reshape(f),h=i.reshape([-1]),[4,qs(h)];case 1:return p=c.sent(),m=p.squeeze([1]),g=Su(d,m,a),t!==r&&r.dispose(),e!==i&&i.dispose(),m.dispose(),d.dispose(),h.dispose(),p.dispose(),[2,g]}})})};function Nu(t,e,n,r,i,a,o){void 0===a&&(a="NHWC"),C(t.length===e.rank,function(){return"Length of inShape ("+t.length+") and rank of dy ("+e.rank+") must match"});var s=t,u=e,c=!1;3===e.rank&&(c=!0,u=e.as4D(1,e.shape[0],e.shape[1],e.shape[2]),s=[1,t[0],t[1],t[2]]),C(4===s.length,function(){return"Error in conv2dDerInput: inShape must be length 4, but got length "+s.length+"."}),C(4===u.rank,function(){return"Error in conv2dDerInput: dy must be rank 4, but got rank "+u.rank}),C(4===n.rank,function(){return"Error in conv2dDerInput: filter must be rank 4, but got rank "+n.rank});var l="NHWC"===a?s[3]:s[1],f="NHWC"===a?u.shape[3]:u.shape[1];C(l===n.shape[2],function(){return"Error in conv2dDerInput: depth of input ("+l+") must match input depth for filter "+n.shape[2]+"."}),C(f===n.shape[3],function(){return"Error in conv2dDerInput: depth of output ("+f+") must match output depth for filter "+n.shape[3]+"."}),null!=o&&C(M(i),function(){return"Error in conv2dDerInput: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+i+"."});var d=zi(a),h=Ti(s,n.shape,r,1,i,o,!1,d),p=Wt.runKernelFunc(function(t,e){var r=t.conv2dDerInput(u,n,h);return e([n,u]),r},{dy4D:u,filter:n},function(t,e){var n=e[0],s=e[1];return{dy4D:function(){return Mu(t,n,r,i,a,1,o)},filter:function(){return Fu(t,s,n.shape,r,i,a,o)}}});return c?p.as3D(p.shape[1],p.shape[2],p.shape[3]):p}function Tu(t){var e=function(t){return"number"==typeof t?[t,t,t]:2===t.length?[t[0],t[1],1]:t}(t),n=e[0],r=e[1],i=e[2];return 1===n&&1===r&&1===i}function Iu(t,e,n,r,i){C(t.length===e.rank,function(){return"Length of inShape ("+t.length+") and rank of dy ("+e.rank+") must match"});var a=t,o=e,s=!1;4===e.rank&&(s=!0,o=e.as5D(1,e.shape[0],e.shape[1],e.shape[2],e.shape[3]),a=[1,t[0],t[1],t[2],t[3]]);var u=a[4],c=o.shape[4];C(5===a.length,function(){return"Error in conv3dDerInput: inShape must be length 5, but got length "+a.length+"."}),C(5===o.rank,function(){return"Error in conv3dDerInput: dy must be rank 5, but got rank "+o.rank}),C(5===n.rank,function(){return"Error in conv3dDerInput: filter must be rank 5, but got rank "+n.rank}),C(u===n.shape[3],function(){return"Error in conv3dDerInput: depth of input ("+u+") must match input depth for filter "+n.shape[3]+"."}),C(c===n.shape[4],function(){return"Error in conv3dDerInput: depth of output ("+c+") must match output depth for filter "+n.shape[4]+"."});var l=Ii(a,n.shape,r,1,i),f=Wt.runKernelFunc(function(t){return t.conv3dDerInput(o,n,l)},{dy5D:o});return s?f.as4D(f.shape[1],f.shape[2],f.shape[3],f.shape[4]):f}var Du=Dn({conv1d_:function(t,e,n,r,i,a,o){void 0===i&&(i="NWC"),void 0===a&&(a=1);var s=xn(t,"x","conv1d"),u=xn(e,"filter","conv1d"),c=s,l=!1;2===s.rank&&(l=!0,c=s.as3D(1,s.shape[0],s.shape[1])),C(3===c.rank,function(){return"Error in conv1d: input must be rank 3, but got rank "+c.rank+"."}),C(3===u.rank,function(){return"Error in conv1d: filter must be rank 3, but got rank "+u.rank+"."}),null!=o&&C(M(r),function(){return"Error in conv1d: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+r+"."}),C(c.shape[2]===u.shape[1],function(){return"Error in conv1d: depth of input ("+c.shape[2]+") must match input depth for filter "+u.shape[1]+"."}),C(Li(n,a),function(){return"Error in conv1D: Either stride or dilation must be 1. Got stride "+n+" and dilation '"+a+"'"}),C("NWC"===i,function(){return"Error in conv1d: got dataFormat of "+i+" but only NWC is currently supported."});var f=u.as4D(1,u.shape[0],u.shape[1],u.shape[2]),d=c.as4D(c.shape[0],1,c.shape[1],c.shape[2]),h=Mu(d,f,[1,n],r,"NHWC",[1,a],o);return l?h.as2D(h.shape[2],h.shape[3]):h.as3D(h.shape[0],h.shape[2],h.shape[3])}}),Mu=Dn({conv2d_:function(t,e,n,r,i,a,o){void 0===i&&(i="NHWC"),void 0===a&&(a=[1,1]);var s=xn(t,"x","conv2d"),u=xn(e,"filter","conv2d"),c=s,l=!1;3===s.rank&&(l=!0,c=s.as4D(1,s.shape[0],s.shape[1],s.shape[2])),C(4===c.rank,function(){return"Error in conv2d: input must be rank 4, but got rank "+c.rank+"."}),C(4===u.rank,function(){return"Error in conv2d: filter must be rank 4, but got rank "+u.rank+"."}),null!=o&&C(M(r),function(){return"Error in conv2d: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+r+"."});var f="NHWC"===i?c.shape[3]:c.shape[1];C(f===u.shape[2],function(){return"Error in conv2d: depth of input ("+f+") must match input depth for filter "+u.shape[2]+"."}),C(Li(n,a),function(){return"Error in conv2D: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+a+"'"});var d=zi(i),h=Ti(c.shape,u.shape,n,a,r,o,!1,d),p=[u,c],m=Wt.runKernelFunc(function(t,e){var n=t.conv2d(c,u,h);return e([u,c]),n},{x:c,filter:u},function(t,e){var o=e,s=o[0],u=o[1];return C(Pi(a),function(){return"Error in gradient of conv2D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '"+a+"'"}),{x:function(){return ju(u.shape,t,s,n,r,i)},filter:function(){return Fu(u,t,s.shape,n,r,i)}}},"Conv2D",h,p);return l?m.as3D(m.shape[1],m.shape[2],m.shape[3]):m}}),Ru=Dn({conv3d_:function(t,e,n,r,i,a){void 0===i&&(i="NDHWC"),void 0===a&&(a=[1,1,1]);var o=xn(t,"x","conv3d"),s=xn(e,"filter","conv3d"),u=o,c=!1;4===o.rank&&(c=!0,u=o.as5D(1,o.shape[0],o.shape[1],o.shape[2],o.shape[3])),C(5===u.rank,function(){return"Error in conv3d: input must be rank 5, but got rank "+u.rank+"."}),C(5===s.rank,function(){return"Error in conv3d: filter must be rank 5, but got rank "+s.rank+"."}),C(u.shape[4]===s.shape[3],function(){return"Error in conv3d: depth of input ("+u.shape[4]+") must match input depth for filter "+s.shape[3]+"."}),C(function(t,e){return Tu(n)||Tu(e)}(0,a),function(){return"Error in conv3D: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+a+"'"}),C("NDHWC"===i,function(){return"Error in conv3d: got dataFormat of "+i+" but only NDHWC is currently supported."});var l=Ii(u.shape,s.shape,n,a,r),f=Wt.runKernelFunc(function(t,e){var n=t.conv3d(u,s,l);return e([u,s]),n},{x:u,$filter:s},function(t,e){C(Tu(a),function(){return"Error in gradient of conv3D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '"+a+"'"});var i=e[0],o=e[1];return{x:function(){return Iu(i.shape,t,o,n,r)},$filter:function(){return function(t,e,n,r,i){var a=t;4===t.rank&&(a=t.as5D(1,t.shape[0],t.shape[1],t.shape[2],t.shape[3]));var o=e;4===o.rank&&(o=e.as5D(1,e.shape[0],e.shape[1],e.shape[2],e.shape[3])),C(5===a.rank,function(){return"Error in conv3dDerFilter: input must be rank 5, but got shape "+a.shape+"."}),C(5===o.rank,function(){return"Error in conv3dDerFilter: dy must be rank 5, but got shape "+o.shape+"."}),C(5===n.length,function(){return"Error in conv3dDerFilter: filterShape must be length 5, but got "+n+"."}),C(a.shape[4]===n[3],function(){return"Error in conv3dDerFilter: depth of input "+a.shape[4]+") must match input depth in filter ("+n[3]+"."}),C(o.shape[4]===n[4],function(){return"Error in conv3dDerFilter: depth of dy ("+o.shape[4]+") must match output depth for filter ("+n[4]+")."});var s=Ii(a.shape,n,r,1,i);return Wt.runKernelFunc(function(t){return t.conv3dDerFilter(a,o,s)},{x5D:a,dy5D:o})}(i,t,o.shape,n,r)}}});return c?f.as4D(f.shape[1],f.shape[2],f.shape[3],f.shape[4]):f}}),Fu=Dn({conv2dDerFilter_:function(t,e,n,r,i,a,o){void 0===a&&(a="NHWC");var s=t;3===t.rank&&(s=t.as4D(1,t.shape[0],t.shape[1],t.shape[2]));var u=e;3===u.rank&&(u=e.as4D(1,e.shape[0],e.shape[1],e.shape[2])),C(4===s.rank,function(){return"Error in conv2dDerFilter: input must be rank 4, but got shape "+s.shape+"."}),C(4===u.rank,function(){return"Error in conv2dDerFilter: dy must be rank 4, but got shape "+u.shape+"."}),C(4===n.length,function(){return"Error in conv2dDerFilter: filterShape must be length 4, but got "+n+"."});var c="NHWC"===a?s.shape[3]:s.shape[1],l="NHWC"===a?u.shape[3]:u.shape[1];C(c===n[2],function(){return"Error in conv2dDerFilter: depth of input "+c+") must match input depth in filter ("+n[2]+"."}),C(l===n[3],function(){return"Error in conv2dDerFilter: depth of dy ("+l+") must match output depth for filter ("+n[3]+")."}),null!=o&&C(M(i),function(){return"Error in conv2dDerFilter: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+i+"."});var f=zi(a),d=Ti(s.shape,n,r,1,i,o,!1,f);return Wt.runKernelFunc(function(t){return t.conv2dDerFilter(s,u,d)},{x4D:s,dy4D:u})}}),ju=Dn({conv2dDerInput_:Nu}),Pu=Dn({depthwiseConv2d_:function(t,e,n,r,i,a,o){void 0===i&&(i="NHWC"),void 0===a&&(a=[1,1]);var s=xn(t,"x","depthwiseConv2d"),u=xn(e,"filter","depthwiseConv2d"),c=s,l=!1;3===s.rank&&(l=!0,c=s.as4D(1,s.shape[0],s.shape[1],s.shape[2])),C(4===c.rank,function(){return"Error in depthwiseConv2d: input must be rank 4, but got rank "+c.rank+"."}),C(4===u.rank,function(){return"Error in depthwiseConv2d: filter must be rank 4, but got rank "+u.rank+"."}),C(c.shape[3]===u.shape[2],function(){return"Error in depthwiseConv2d: number of input channels ("+c.shape[3]+") must match the inChannels dimension in filter "+u.shape[2]+"."}),null==a&&(a=[1,1]),C(Li(n,a),function(){return"Error in depthwiseConv2d: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+a+"'"}),null!=o&&C(M(r),function(){return"Error in depthwiseConv2d: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+r+"."});var f=Ti(c.shape,u.shape,n,a,r,o,!0),d=[c,u],h=Wt.runKernelFunc(function(t,e){var n=t.depthwiseConv2D(c,u,f);return e([c,u]),n},{x:c,filter:u},function(t,e){C(Pi(a),function(){return"Error in gradient of depthwiseConv2d: dilation rates greater than 1 are not yet supported. Got dilations '"+a+"'"});var n=e[0],r=e[1];return{x:function(){return Lu(n.shape,t,r,f)},filter:function(){return zu(n,t,r.shape,f)}}},"DepthwiseConv2dNative",f,d);return l?h.as3D(h.shape[1],h.shape[2],h.shape[3]):h}}),Lu=Dn({depthwiseConv2dDerInput_:function(t,e,n,r){var i=e,a=!1;3===e.rank&&(a=!0,i=e.as4D(1,e.shape[0],e.shape[1],e.shape[2]));var o=Wt.runKernelFunc(function(t){return t.depthwiseConv2DDerInput(i,n,r)},{dy4D:i});return a?o.as3D(o.shape[1],o.shape[2],o.shape[3]):o}}),zu=Dn({depthwiseConv2dDerFilter_:function(t,e,n,r){var i=t;3===t.rank&&(i=t.as4D(1,t.shape[0],t.shape[1],t.shape[2]));var a=e;return 3===a.rank&&(a=e.as4D(1,e.shape[0],e.shape[1],e.shape[2])),Wt.runKernelFunc(function(t){return t.depthwiseConv2DDerFilter(i,a,r)},{x4D:i,dy4D:a})}}),Bu=Dn({separableConv2d_:function(t,e,n,r,i,a,o){void 0===a&&(a=[1,1]),void 0===o&&(o="NHWC");var s=xn(t,"x","separableConv2d"),u=xn(e,"depthwiseFilter","separableConv2d"),c=xn(n,"pointwiseFilter","separableConv2d"),l=s,f=!1;if(3===s.rank&&(f=!0,l=s.as4D(1,s.shape[0],s.shape[1],s.shape[2])),"NCHW"===o)throw new Error("separableConv2d currently does not support dataFormat NCHW; only NHWC is supported");C(4===l.rank,function(){return"Error in separableConv2d: input must be rank 4, but got rank "+l.rank+"."}),C(4===u.rank,function(){return"Error in separableConv2d: depthwise filter must be rank 4, but got rank "+u.rank+"."}),C(4===c.rank,function(){return"Error in separableConv2d: pointwise filter must be rank 4, but got rank "+u.rank+"."}),C(1===c.shape[0],function(){return"Error in separableConv2d: the first dimension of pointwise filter must be 1, but got "+c.shape[0]+"."}),C(1===c.shape[1],function(){return"Error in separableConv2d: the second dimension of pointwise filter must be 1, but got "+c.shape[1]+"."});var d=u.shape[2],h=u.shape[3];C(c.shape[2]===d*h,function(){return"Error in separableConv2d: the third dimension of pointwise filter must be "+d*h+", but got "+c.shape[2]+"."});var p=Pu(l,u,r,i,o,a),m=Mu(p,c,1,"valid",o);return f?m.as3D(m.shape[1],m.shape[2],m.shape[3]):m}}),Uu=Dn({conv2dTranspose_:function(t,e,n,r,i,a){return Nu(n,xn(t,"x","conv2dTranspose"),xn(e,"filter","conv2dTranspose"),r,i,"NHWC",a)}}),Wu=Dn({conv3dTranspose_:function(t,e,n,r,i){return Iu(n,xn(t,"x","conv3dTranspose"),xn(e,"filter","conv3dTranspose"),r,i)}}),Vu=Dn({matMul_:function(t,e,n,r){var i;void 0===n&&(n=!1),void 0===r&&(r=!1);var a=xn(t,"a","matMul"),o=xn(e,"b","matMul");i=Ft(a,o),a=i[0],o=i[1];var s=n?a.shape[a.rank-2]:a.shape[a.rank-1],u=r?o.shape[o.rank-1]:o.shape[o.rank-2],c=n?a.shape[a.rank-1]:a.shape[a.rank-2],l=r?o.shape[o.rank-2]:o.shape[o.rank-1],f=a.shape.slice(0,-2),d=o.shape.slice(0,-2),h=I(f),p=I(d);C(a.rank>=2&&o.rank>=2&&a.rank===o.rank,function(){return"Error in matMul: inputs must have the same rank of at least 2, got ranks "+a.rank+" and "+o.rank+"."}),C(D(f,d),function(){return"Error in matMul: outer dimensions ("+f+") and ("+d+") of Tensors with shapes "+a.shape+" and "+o.shape+" must match."}),C(s===u,function(){return"Error in matMul: inner shapes ("+s+") and ("+u+") of Tensors with shapes "+a.shape+" and "+o.shape+" and transposeA="+n+" and transposeB="+r+" must match."});var m=a.shape.slice(0,-2).concat([c,l]),g=n?a.as3D(h,s,c):a.as3D(h,c,s),v=r?o.as3D(p,l,u):o.as3D(p,u,l),y={transposeA:n,transposeB:r};return Wt.runKernelFunc(function(t,e){var i=t.batchMatMul(g,v,n,r);return e([g,v]),i},{a:g,b:v},function(t,e){var i=e,a=i[0],o=i[1];return n||r?!n&&r?{a:function(){return t.matMul(o,!1,!1)},b:function(){return t.matMul(a,!0,!1)}}:n&&!r?{a:function(){return o.matMul(t,!1,!0)},b:function(){return a.matMul(t,!1,!1)}}:{a:function(){return o.matMul(t,!0,!0)},b:function(){return t.matMul(a,!0,!0)}}:{a:function(){return t.matMul(o,!1,!0)},b:function(){return a.matMul(t,!0,!1)}}},"BatchMatMul",y).reshape(m)}}),qu=Dn({dot_:function(t,e){var n=xn(t,"t1","dot"),r=xn(e,"t2","dot");C(!(1!==n.rank&&2!==n.rank||1!==r.rank&&2!==r.rank),function(){return"Error in dot: inputs must all be rank 1 or 2, but got ranks "+n.rank+" and "+r.rank+"."});var i=1===n.rank?n.size:n.shape[1],a=1===r.rank?r.size:r.shape[0];return C(i===a,function(){return"Error in dot: inner dimensions of inputs must match, but got "+i+" and "+a+"."}),1===n.rank&&1===r.rank?n.as2D(1,-1).matMul(r.as2D(-1,1)).asScalar():1===n.rank&&2===r.rank?n.as2D(1,-1).matMul(r.as2D(r.shape[0],r.shape[1])).as1D():2===n.rank&&1===r.rank?n.matMul(r.as2D(-1,1)).as1D():n.matMul(r.as2D(r.shape[0],r.shape[1]))}}),Hu=Dn({outerProduct_:function(t,e){var n=xn(t,"v1","outerProduct"),r=xn(e,"v2","outerProduct");return C(1===n.rank&&1===r.rank,function(){return"Error in outerProduct: inputs must be rank 1, but got ranks "+n.rank+" and "+r.rank+"."}),n.as2D(-1,1).matMul(r.as2D(1,-1))}}),Gu=Dn({reverse_:function(t,e){var n=xn(t,"x","reverse");if(0===n.rank)return n.clone();var r=z(e,n.shape);return Wt.runKernelFunc(function(t){return t.reverse(n,r)},{$x:n},function(t){return{$x:function(){return t.reverse(r)}}}).reshapeAs(n)}}),$u=Dn({reverse1d_:function(t){var e=xn(t,"x","reverse");return C(1===e.rank,function(){return"Error in reverse1D: x must be rank 1 but got rank "+e.rank+"."}),Gu(e,0)}}),Ku=Dn({reverse2d_:function(t,e){var n=xn(t,"x","reverse");return C(2===n.rank,function(){return"Error in reverse2D: x must be rank 2 but got rank "+n.rank+"."}),Gu(n,e)}}),Xu=Dn({reverse3d_:function(t,e){var n=xn(t,"x","reverse");return C(3===n.rank,function(){return"Error in reverse3D: x must be rank 3 but got rank "+n.rank+"."}),Gu(n,e)}}),Yu=Dn({reverse4d_:function(t,e){var n=xn(t,"x","reverse");return C(4===n.rank,function(){return"Error in reverse4D: x must be rank 4 but got rank "+n.rank+"."}),Gu(n,e)}});function Ju(t,e,n,r,i,a){var o=xn(t,"x","maxPool"),s=o,u=!1;3===o.rank&&(u=!0,s=o.as4D(1,o.shape[0],o.shape[1],o.shape[2])),null==r&&(r=[1,1]),C(4===s.rank,function(){return"Error in maxPool: input must be rank 4 but got rank "+s.rank+"."}),C(Li(n,r),function(){return"Error in maxPool: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+r+"'"}),null!=a&&C(M(i),function(){return"Error in maxPool: pad must be an integer when using, dimRoundingMode "+a+" but got pad "+i+"."});var c=Ai(s.shape,e,n,r,i,a);if(1===c.filterWidth&&1===c.filterHeight&&D(c.inShape,c.outShape))return o.clone();var l=[s],f=Wt.runKernelFunc(function(t,e){var n=t.maxPool(s,c);return e([s,n]),n},{x:s},function(t,a){var o=a[0],s=a[1];return{x:function(){return function(t,e,n,r,i,a,o,s){var u=xn(t,"dy","maxPoolBackprop"),c=xn(e,"input","maxPoolBackprop"),l=xn(n,"output","maxPoolBackprop");C(c.rank===u.rank,function(){return"Rank of input ("+c.rank+") does not match rank of dy ("+u.rank+")"}),null==a&&(a=[1,1]),C(Li(i,a),function(){return"Error in maxPoolBackProp: Either strides or dilations must be 1. Got strides "+i+" and dilations '"+a+"'"}),C(4===u.rank,function(){return"Error in maxPoolBackprop: dy must be rank 4 but got rank "+u.rank+"."}),C(4===c.rank,function(){return"Error in maxPoolBackprop: input must be rank 4 but got rank "+c.rank+"."});var f=Ai(c.shape,r,i,a,o,s);return Wt.runKernelFunc(function(t){return t.maxPoolBackprop(u,c,l,f)},{$dy:u,$input:c})}(t,o,s,e,n,r,i)}}},"MaxPool",c,l);return u?f.as3D(f.shape[1],f.shape[2],f.shape[3]):f}function Zu(t,e,n,r,i,a){var o=xn(t,"x","avgPool","float32");null==r&&(r=[1,1]),C(Li(n,r),function(){return"Error in avgPool: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+r+"'"});var s=o,u=!1;3===o.rank&&(u=!0,s=o.as4D(1,o.shape[0],o.shape[1],o.shape[2])),C(4===s.rank,function(){return"Error in avgPool: x must be rank 4 but got rank "+s.rank+"."}),null!=a&&C(M(i),function(){return"Error in avgPool: pad must be an integer when using, dimRoundingMode "+a+" but got pad "+i+"."});var c=Ai(s.shape,e,n,r,i,a);if(1===c.filterWidth&&1===c.filterHeight&&D(c.inShape,c.outShape))return o.clone();var l=Wt.runKernelFunc(function(t){return t.avgPool(s,c)},{x:s},function(t){return{x:function(){return function(t,e,n,r,i,a){var o=xn(t,"dy","avgPoolBackprop"),s=xn(e,"input","avgPoolBackprop");C(s.rank===o.rank,function(){return"Rank of input ("+s.rank+") does not match rank of dy ("+o.rank+")"}),null==i&&(i=[1,1]),C(Li(r,i),function(){return"Error in avgPoolBackprop: Either strides or dilations must be 1. Got strides "+r+" and dilations '"+i+"'"});var u=s,c=o,l=!1;3===s.rank&&(l=!0,u=s.as4D(1,s.shape[0],s.shape[1],s.shape[2]),c=o.as4D(1,o.shape[0],o.shape[1],o.shape[2])),C(4===c.rank,function(){return"Error in avgPoolBackprop: dy must be rank 4 but got rank "+c.rank+"."}),C(4===u.rank,function(){return"Error in avgPoolBackprop: input must be rank 4 but got rank "+u.rank+"."});var f=Ai(u.shape,n,r,i,a),d=Wt.runKernelFunc(function(t){return t.avgPoolBackprop(c,u,f)},{dy4D:c,input4D:u});return l?d.as3D(d.shape[1],d.shape[2],d.shape[3]):d}(t,s,e,n,r,i)}}},"AvgPool",c);return l=l.cast(o.dtype),u?l.as3D(l.shape[1],l.shape[2],l.shape[3]):l}var Qu=Dn({maxPool_:function(t,e,n,r,i){return Ju(t,e,n,1,r,i)}}),tc=Dn({avgPool_:function(t,e,n,r,i){return Zu(t,e,n,1,r,i)}}),ec=Dn({pool_:function(t,e,n,r,i,a){null==i&&(i=[1,1]),null==a&&(a=1),0===r&&(r="valid");var o=xn(t,"x","maxPool"),s=o,u=!1;3===o.rank&&(u=!0,s=o.as4D(1,o.shape[0],o.shape[1],o.shape[2])),C(Li(a,i),function(){return"Error in pool: Either strides or dilations must be 1. Got strides "+a+" and dilations '"+i+"'"});var c,l=Ai(s.shape,e,a,i,r),f=[l.dilationHeight,l.dilationWidth];c="same"===r?function(t,e){var n=t.map(function(t,n){return t+(t-1)*(e[n]-1)}).map(function(t){return t-1}),r=n.map(function(t){return Math.floor(t/2)}),i=n.map(function(t,e){return t-r[e]});return n.map(function(t,e){return[r[e],i[e]]})}([l.filterHeight,l.filterWidth],f):[[0,0],[0,0]];var d=1===f[0]&&1===f[1],h=function(t,e,n){var r=n.map(function(t){return t[0]}),i=n.map(function(t){return t[1]}),a=t.concat(r,i),o=e.map(function(t,e){return(t-a[e]%t)%t}),s=i.map(function(t,e){return t+o[e]});return[e.map(function(t,e){return[r[e],s[e]]}),e.map(function(t,e){return[0,o[e]]})]}([l.inHeight,l.inWidth],f,c),p=h[0],m=h[1],g=d?r:"valid",v=d?s:zr(s,f,p),y=("avg"===n?function(){return Zu(v,e,a,1,g)}:function(){return Ju(v,e,a,1,g)})(),b=d?y:br(y,f,m);return u?b.as3D(b.shape[1],b.shape[2],b.shape[3]):b}}),nc=Dn({maxPool3d_:function(t,e,n,r,i,a,o){void 0===a&&(a="NDHWC");var s=xn(t,"x","maxPool3d"),u=s,c=!1;4===s.rank&&(c=!0,u=s.as5D(1,s.shape[0],s.shape[1],s.shape[2],s.shape[3])),null==o&&(o=[1,1,1]),C(5===u.rank,function(){return"Error in maxPool3d: x must be rank 5 but got rank "+u.rank+"."}),C("NDHWC"===a,function(){return"Error in maxPool3d: Only NDHWC is currently supported, but got dataFormat of "+a}),C(Li(n,o),function(){return"Error in maxPool3d: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+o+"'"}),null!=i&&C(M(r),function(){return"Error in maxPool3d: pad must be an integer when using, dimRoundingMode "+i+" but got pad "+r+"."});var l=Ni(u.shape,e,n,o,r,i,a),f=Wt.runKernelFunc(function(t,e){var n=t.maxPool3d(u,l);return e([u,n]),n},{x:u},function(t,a){var s=a[0],u=a[1];return{x:function(){return function(t,e,n,r,i,a,o,s){var u=xn(t,"dy","maxPool3dBackprop"),c=xn(e,"input","maxPool3dBackprop"),l=xn(n,"output","maxPool3dBackprop"),f=u,d=c,h=l,p=!1;4===c.rank&&(p=!0,f=u.as5D(1,u.shape[0],u.shape[1],u.shape[2],u.shape[3]),d=c.as5D(1,c.shape[0],c.shape[1],c.shape[2],c.shape[3]),h=l.as5D(1,l.shape[0],l.shape[1],l.shape[2],l.shape[3])),C(5===f.rank,function(){return"Error in maxPool3dBackprop: dy must be rank 5 but got rank "+f.rank+"."}),C(5===d.rank,function(){return"Error in maxPool3dBackprop: input must be rank 5 but got rank "+d.rank+"."}),C(5===h.rank,function(){return"Error in maxPool3dBackprop: output must be rank 5 but got rank "+h.rank+"."}),null==a&&(a=[1,1,1]),C(Li(i,a),function(){return"Error in maxPool3dBackprop: Either strides or dilations must be 1. Got strides "+i+" and dilations '"+a+"'"}),null!=s&&C(M(o),function(){return"Error in maxPool3dBackprop: pad must be an integer when using, dimRoundingMode "+s+" but got pad "+o+"."});var m=Ni(d.shape,r,i,a,o,s),g=Wt.runKernelFunc(function(t){return t.maxPool3dBackprop(f,d,h,m)},{dy5D:f,input5D:d});return p?g.as4D(g.shape[1],g.shape[2],g.shape[3],g.shape[4]):g}(t,s,u,e,n,o,r,i)}}});return c?f.as4D(f.shape[1],f.shape[2],f.shape[3],f.shape[4]):f}}),rc=Dn({avgPool3d_:function(t,e,n,r,i,a,o){void 0===a&&(a="NDHWC");var s=xn(t,"x","avgPool3d","float32"),u=s,c=!1;4===s.rank&&(c=!0,u=s.as5D(1,s.shape[0],s.shape[1],s.shape[2],s.shape[3])),null==o&&(o=[1,1,1]),C(5===u.rank,function(){return"Error in avgPool3d: x must be rank 5 but got rank "+u.rank+"."}),C("NDHWC"===a,function(){return"Error in avgPool3d: Only NDHWC is currently supported, but got dataFormat of "+a}),C(Li(n,o),function(){return"Error in avgPool3d: Either strides or dilations must be 1. Got strides "+n+" and dilations '"+o+"'"}),null!=i&&C(M(r),function(){return"Error in avgPool3d: pad must be an integer when using, dimRoundingMode "+i+" but got pad "+r+"."});var l=Ni(u.shape,e,n,o,r,i,a),f=Wt.runKernelFunc(function(t){return t.avgPool3d(u,l)},{x:u},function(t){return{x:function(){return function(t,e,n,r,i,a,o){var s=xn(t,"dy","avgPool3dBackprop"),u=xn(e,"input","avgPool3dBackprop"),c=s,l=u,f=!1;4===u.rank&&(f=!0,c=s.as5D(1,s.shape[0],s.shape[1],s.shape[2],s.shape[3]),l=u.as5D(1,u.shape[0],u.shape[1],u.shape[2],u.shape[3])),C(5===c.rank,function(){return"Error in avgPool3dBackprop: dy must be rank 5 but got rank "+c.rank+"."}),C(5===l.rank,function(){return"Error in avgPool3dBackprop: input must be rank 5 but got rank "+l.rank+"."}),null==i&&(i=[1,1,1]),C(Li(r,i),function(){return"Error in avgPool3dBackprop: Either strides or dilations must be 1. Got strides "+r+" and dilations '"+i+"'"}),null!=o&&C(M(a),function(){return"Error in maxPool3dBackprop: pad must be an integer when using, dimRoundingMode "+o+" but got pad "+a+"."});var d=Ni(l.shape,n,r,i,a,o),h=Wt.runKernelFunc(function(t){return t.avgPool3dBackprop(c,l,d)},{dy5D:c,input5D:l});return f?h.as4D(h.shape[1],h.shape[2],h.shape[3],h.shape[4]):h}(t,u,e,n,o,r,i)}}});return f=f.cast(u.dtype),c?f.as4D(f.shape[1],f.shape[2],f.shape[3],f.shape[4]):f}}),ic=Dn({slice_:function(t,e,n){var r,i,a=xn(t,"x","slice");if(0===a.rank)throw new Error("Slicing scalar is not possible");(r="number"==typeof e?[e].concat(new Array(a.rank-1).fill(0)):e.length<a.rank?e.concat(new Array(a.rank-e.length).fill(0)):e.slice()).forEach(function(t){C(-1!==t,function(){return"slice() does not support negative begin indexing."})}),i=(i=null==n?new Array(a.rank).fill(-1):"number"==typeof n?[n].concat(new Array(a.rank-1).fill(-1)):n.length<a.rank?n.concat(new Array(a.rank-n.length).fill(-1)):n).map(function(t,e){return t>=0?t:(C(-1===t,function(){return"Negative size values should be exactly -1 but got "+t+" for the slice() size at index "+e+"."}),a.shape[e]-r[e])}),ai(a,r,i);var o=a.shape,s={begin:r,size:i};return Wt.runKernelFunc(function(t){return t.slice(a,r,i)},{x:a},function(t){for(var e=[],n=0;n<t.rank;n++)e.push([r[n],o[n]-r[n]-i[n]]);return{x:function(){return t.pad(e)}}},"Slice",s)}}),ac=Dn({slice1d_:function(t,e,n){var r=xn(t,"x","slice1d");return C(1===r.rank,function(){return"slice1d expects a rank-1 tensor, but got a rank-"+r.rank+" tensor"}),ic(r,[e],[n])}}),oc=Dn({slice2d_:function(t,e,n){var r=xn(t,"x","slice2d");return C(2===r.rank,function(){return"slice2d expects a rank-2 tensor, but got a rank-"+r.rank+" tensor"}),ic(r,e,n)}}),sc=Dn({slice3d_:function(t,e,n){var r=xn(t,"x","slice3d");return C(3===r.rank,function(){return"slice3d expects a rank-3 tensor, but got a rank-"+r.rank+" tensor"}),ic(r,e,n)}}),uc=Dn({slice4d_:function(t,e,n){var r=xn(t,"x","slice4d");return C(4===r.rank,function(){return"slice4d expects a rank-4 tensor, but got a rank-"+r.rank+" tensor"}),ic(r,e,n)}});function cc(t,e,n,r,i){return e.rank<n.rank&&(e=e.reshape(On(e.shape,r))),t.rank<n.rank&&(t=t.reshape(On(t.shape,r))),{x:function(){var r=t.mul(n.equal(e).cast(t.dtype));return null==i?r:r.transpose(i)}}}var lc=Dn({all_:function(t,e,n){void 0===e&&(e=null),void 0===n&&(n=!1);var r=xn(t,"x","all","bool"),i=z(e,r.shape),a=i,o=Cn(a,r.rank);null!=o&&(r=r.transpose(o),a=Nn(a.length,r.rank));var s=Wt.runKernelFunc(function(t){return t.all(r,a)},{$x:r});if(n){var u=On(s.shape,i);return s.reshape(u)}return s}}),fc=Dn({any_:function(t,e,n){void 0===e&&(e=null),void 0===n&&(n=!1);var r=xn(t,"x","any","bool"),i=z(e,r.shape),a=i,o=Cn(a,r.rank);null!=o&&(r=r.transpose(o),a=Nn(a.length,r.rank));var s=Wt.runKernelFunc(function(t){return t.any(r,a)},{$x:r});if(n){var u=On(s.shape,i);return s.reshape(u)}return s}}),dc=Dn({argMax_:function(t,e){void 0===e&&(e=0);var n=xn(t,"x","argMax");null==e&&(e=0);var r=z(e,n.shape),i=Cn(r,n.rank);null!=i&&(n=n.transpose(i),r=Nn(r.length,n.rank));var a={axis:r[0]},o=[n];return Wt.runKernelFunc(function(t,e){var i=t.argMax(n,r[0]);return e([n]),i},{x:n},function(t,e){var n=e[0];return{x:function(){return Zn(n)}}},"ArgMax",a,o)}}),hc=Dn({argMin_:function(t,e){void 0===e&&(e=0);var n=xn(t,"x","argMin");null==e&&(e=0);var r=z(e,n.shape),i=Cn(r,n.rank);return null!=i&&(n=n.transpose(i),r=Nn(r.length,n.rank)),Wt.runKernelFunc(function(t,e){var i=t.argMin(n,r[0]);return e([n]),i},{$x:n},function(t,e){var n=e[0];return{$x:function(){return Zn(n)}}})}}),pc=Dn({logSumExp_:function(t,e,n){void 0===e&&(e=null),void 0===n&&(n=!1);var r=xn(t,"x","logSumExp"),i=z(e,r.shape),a=r.max(i,!0),o=r.sub(a).exp().sum(i).log(),s=a.reshape(o.shape).add(o);if(n){var u=On(s.shape,i);return s.reshape(u)}return s}}),mc=Dn({max_:function(t,e,n){void 0===e&&(e=null),void 0===n&&(n=!1);var r=xn(t,"x","max"),i=r,a=z(e,r.shape),o=a,s=Cn(o,r.rank);null!=s&&(r=r.transpose(s),o=Nn(o.length,r.rank));var u=[r],c=Wt.runKernelFunc(function(t,e){var n=t.max(r,o);return e([i,n]),n},{x:r},function(t,e){return cc(t,e[1],e[0],a,s)},"Max",{axes:o},u,[!0]);if(n){var l=On(c.shape,a);c=c.reshape(l)}return c}}),gc=Dn({mean_:function(t,e,n){void 0===e&&(e=null),void 0===n&&(n=!1);var r=xn(t,"x","mean"),i=z(e,r.shape),a=I(En(r.shape,i)[1]);return yi(function(t){var r=Ln(a);return{value:(r.dtype===t.dtype?t:t.cast(r.dtype)).div(r).sum(e,n),gradFunc:function(e){var n=t.shape.slice();return i.forEach(function(t){n[t]=1}),e.reshape(n).mul(Gn(t.shape,"float32")).div(a)}}})(r)}}),vc=Dn({min_:function(t,e,n){void 0===e&&(e=null),void 0===n&&(n=!1);var r=xn(t,"x","min"),i=r,a=z(e,r.shape),o=a,s=Cn(o,r.rank);null!=s&&(r=r.transpose(s),o=Nn(o.length,r.rank));var u=[r],c=Wt.runKernelFunc(function(t,e){var n=t.min(r,o);return e([i,n]),n},{x:r},function(t,e){return cc(t,e[1],e[0],a,s)},"Min",{axes:o},u,[!0]);if(n){var l=On(c.shape,a);c=c.reshape(l)}return c}}),yc=Dn({moments_:function(t,e,n){void 0===e&&(e=null),void 0===n&&(n=!1);var r=z(e,(t=xn(t,"x","moments")).shape),i=t.mean(r,n),a=i.shape;return n||(a=On(i.shape,r)),{mean:i,variance:t.toFloat().sub(i.reshape(a)).square().mean(r,n)}}}),bc=Dn({sum_:function(t,e,n){void 0===e&&(e=null),void 0===n&&(n=!1);var r=xn(t,"x","sum");"bool"===r.dtype&&(r=r.toInt());var i=z(e,r.shape);return yi(function(t){var e=Cn(i,t.rank),r=i,a=t;null!=e&&(a=t.transpose(e),r=Nn(r.length,t.rank));var o=function(e){var n=t.shape.slice();return i.forEach(function(t){n[t]=1}),e.reshape(n).mul(Gn(t.shape,"float32"))},s={axes:r},u=Wt.runKernelFunc(function(t){return t.sum(a,r)},{x:a},function(t){return{x:function(){return o(t)}}},"Sum",s);if(n){var c=On(u.shape,i);u=u.reshape(c)}return{value:u,gradFunc:o}})(r)}}),xc=Dn({prod_:function(t,e,n){void 0===e&&(e=null),void 0===n&&(n=!1);var r=xn(t,"x","prod");"bool"===r.dtype&&(r=r.toInt());var i=z(e,r.shape),a=Cn(i,r.rank),o=i,s=r;null!=a&&(s=r.transpose(a),o=Nn(o.length,r.rank));var u=Wt.runKernelFunc(function(t){return t.prod(s,o)},{permutedX:s});if(n){var c=On(u.shape,i);u=u.reshape(c)}return u}}),wc=Dn({elu_:function(t){var e=xn(t,"x","elu");return Wt.runKernelFunc(function(t,n){var r=t.elu(e);return n([r]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){return Wt.runKernelFunc(function(e){return e.eluDer(t,n)},{dy:t,y:n})}}})}}),kc=Dn({leakyRelu_:function(t,e){void 0===e&&(e=.2);var n=xn(t,"x","leakyRelu");return Qs(Ln(e).mul(n),n)}}),_c=Dn({prelu_:function(t,e){var n=xn(t,"x","prelu"),r=xn(e,"alpha","prelu");return Wt.runKernelFunc(function(t,e){var i=t.prelu(n,r);return e([n,r]),i},{x:n,alpha:r},function(t,e){var n=e[0],r=e[1],i=n.greater(0);return{x:function(){return Vs(i,t,t.mul(r))},alpha:function(){var e=Vs(i,Zn(t),t.mul(n)),a=Si(r.shape,t.shape);return a.length>0&&(e=e.sum(a)),e.reshape(r.shape)}}},"Prelu")}}),Ec=Dn({relu_:function(t){var e=xn(t,"x","relu");return"bool"===e.dtype?e.toInt():Wt.runKernelFunc(function(t,n){var r=t.relu(e);return n([e]),r},{x:e},function(t,e){var n=e[0];return{x:function(){return t.mulStrict(n.step().toFloat())}}},"Relu")}}),Oc=Dn({relu6_:function(t){var e=xn(t,"x","relu6");return"bool"===e.dtype?e.toInt():Wt.runKernelFunc(function(t,n){var r=t.relu6(e);return n([e]),r},{x:e},function(t,e){var n=e[0],r=n.lessEqual(6).mul(n.step());return{x:function(){return t.mulStrict(r.toFloat())}}},"Relu6")}}),Sc=Dn({selu_:function(t){var e=xn(t,"x","selu");return Wt.runKernelFunc(function(t,n){var r=t.selu(e);return n([e]),r},{$x:e},function(t,e){var n=e[0];return{$x:function(){var e=n.greater(Ln(0)),r=Ln(yo),i=Ln(bo),a=t.mul(i),o=t.mul(r).mul(n.toFloat().exp());return Vs(e,a,o)}}})}}),Cc=Dn({transpose_:function(t,e){var n=xn(t,"x","transpose");if(null==e&&(e=n.shape.map(function(t,e){return e}).reverse()),C(n.rank===e.length,function(){return"Error in transpose: rank of input "+n.rank+" must match length of perm "+e+"."}),e.forEach(function(t){C(t>=0&&t<n.rank,function(){return"All entries in 'perm' must be between 0 and "+(n.rank-1)+" but got "+e})}),n.rank<=1)return n.clone();var r={perm:e};return Wt.runKernelFunc(function(t){return t.transpose(n,e)},{x:n},function(t){var n=An(e);return{x:function(){return t.transpose(n)}}},"Transpose",r)}}),Ac=Dn({localResponseNormalization_:function(t,e,n,r,i){void 0===e&&(e=5),void 0===n&&(n=1),void 0===r&&(r=1),void 0===i&&(i=.5);var a=xn(t,"x","localResponseNormalization");C(4===a.rank||3===a.rank,function(){return"Error in localResponseNormalization: x must be rank 3 or 4 but got\n rank "+a.rank+"."}),C(M(e),function(){return"Error in localResponseNormalization: depthRadius must be an integer but got depthRadius "+e+"."});var o=a,s=!1;3===a.rank&&(s=!0,o=a.as4D(1,a.shape[0],a.shape[1],a.shape[2]));var u=Wt.runKernelFunc(function(t,a){var s=t.localResponseNormalization4D(o,e,n,r,i);return a([o,s]),s},{x4D:o},function(t,a){var o=a[0],s=a[1];return{x4D:function(){return Wt.runKernelFunc(function(a){return a.LRNGrad(t,o,s,e,n,r,i)},{})}}});return s?u.as3D(u.shape[1],u.shape[2],u.shape[3]):u}}),Nc=Dn({norm_:function(t,e,n,r){void 0===e&&(e="euclidean"),void 0===n&&(n=null),void 0===r&&(r=!1);var i=function t(e,n,r){if(void 0===r&&(r=null),0===e.rank)return e.abs();if(1!==e.rank&&null===r)return t(e.reshape([-1]),n,r);if(1===e.rank||"number"==typeof r||Array.isArray(r)&&1===r.length){if(1===n)return e.abs().sum(r);if(n===1/0)return e.abs().max(r);if(n===-1/0)return e.abs().min(r);if("euclidean"===n||2===n)return e.abs().pow(Ln(2,"int32")).sum(r).sqrt();throw new Error("Error in norm: invalid ord value: "+n)}if(Array.isArray(r)&&2===r.length){if(1===n)return e.abs().sum(r[0]).max(r[1]-1);if(n===1/0)return e.abs().sum(r[1]).max(r[0]);if(n===-1/0)return e.abs().sum(r[1]).min(r[0]);if("fro"===n||"euclidean"===n)return e.square().sum(r).sqrt();throw new Error("Error in norm: invalid ord value: "+n)}throw new Error("Error in norm: invalid axis: "+r)}(t=xn(t,"x","norm"),e,n),a=i.shape;if(r){var o=z(n,t.shape);a=On(i.shape,o)}return i.reshape(a)}}),Tc=Dn({basicLSTMCell_:function(t,e,n,r,i,a){var o=xn(t,"forgetBias","basicLSTMCell"),s=xn(e,"lstmKernel","basicLSTMCell"),u=xn(n,"lstmBias","basicLSTMCell"),c=xn(r,"data","basicLSTMCell"),l=xn(i,"c","basicLSTMCell"),f=xn(a,"h","basicLSTMCell"),d=c.concat(f,1).matMul(s).add(u),h=d.shape[0],p=d.shape[1]/4,m=[h,p],g=d.slice([0,0],m),v=d.slice([0,p],m),y=d.slice([0,2*p],m),b=d.slice([0,3*p],m),x=g.sigmoid().mulStrict(v.tanh()).addStrict(l.mulStrict(o.add(y).sigmoid()));return[x,x.tanh().mulStrict(b.sigmoid())]}}),Ic=Dn({multiRNNCell_:function(t,e,n,r){for(var i=xn(e,"data","multiRNNCell"),a=wn(n,"c","multiRNNCell"),o=wn(r,"h","multiRNNCell"),s=i,u=[],c=0;c<t.length;c++){var l=t[c](s,a[c],o[c]);u.push(l[0]),u.push(l[1]),s=l[1]}var f=[],d=[];for(c=0;c<u.length;c+=2)f.push(u[c]),d.push(u[c+1]);return[f,d]}}),Dc=Dn({movingAverage_:function(t,e,n,r,i){void 0===i&&(i=!0);var a=xn(t,"v","movingAverage"),o=xn(e,"x","movingAverage"),s=xn(n,"decay","movingAverage");jt(a,o),C(D(a.shape,o.shape),function(){return"Shape mismatch in v and x"});var u=Ln(1),c=u.sub(s),l=o.sub(a).mul(c);if(i){C(null!=r,function(){return"When using zeroDebias: true, step is required."});var f=xn(r,"step","movingAverage");l=l.div(u.sub(su(s,f)))}return a.add(l)}}),Mc=Dn({stridedSlice_:function(t,e,n,r,i,a,o,s,u){if(void 0===i&&(i=0),void 0===a&&(a=0),void 0===o&&(o=0),void 0===s&&(s=0),void 0===u&&(u=0),null==r&&(r=new Array(e.length)),0!==o)throw new Error("ellipsis mask is not yet supported");var c=xn(t,"x","stridedSlice"),l=oi(s),f=c.shape.slice();l.forEach(function(t){e[t]=0,n[t]=1,f.splice(t,0,1)}),c=c.reshape(f);for(var d=0;d<c.rank;d++)e[d]=ui(i,e,r,c.shape,d),n[d]=ci(a,n,r,c.shape,d),r[d]=r[d]||1;var h=oi(u);h.forEach(function(t){n[t]=e[t]+1,r[t]=1});var p=si(e,n,r),m=p.filter(function(t,e){return-1===h.indexOf(e)});return r.every(function(t){return 1===t})?ic(c,e,p).reshape(m):Wt.runKernelFunc(function(t){return t.stridedSlice(c,e,n,r)},{$x:c}).reshape(m)}}),Rc=Dn({topk_:function(t,e,n){void 0===e&&(e=1),void 0===n&&(n=!0);var r=xn(t,"x","topk");if(0===r.rank)throw new Error("topk() expects the input to be of rank 1 or higher");var i=r.shape[r.shape.length-1];if(e>i)throw new Error("'k' passed to topk() must be <= the last dimension ("+i+") but got "+e);var a=Wt.runKernelFunc(function(t){return t.topk(r,e,n)},{$x:r});return{values:a[0],indices:a[1]}}}),Fc=Dn({scatterND_:function(t,e,n){var r=xn(t,"indices","scatterND","int32"),i=xn(e,"updates","scatterND");return ni(i,r,n),Wt.runKernelFunc(function(t){return t.scatterND(r,i,n)},{indices:r,updates:i},null,"ScatterNd",{shape:n})}}),jc=Dn({fft_:function(t){C("complex64"===t.dtype,function(){return"The dtype for tf.spectral.fft() must be complex64 but got "+t.dtype+"."});var e=t.shape[t.shape.length-1],n=t.size/e,r=t.as2D(n,e);return Wt.runKernelFunc(function(t){return t.fft(r)},{input:t}).reshape(t.shape)}}),Pc=Dn({ifft_:function(t){C("complex64"===t.dtype,function(){return"The dtype for tf.spectral.ifft() must be complex64 but got "+t.dtype+"."});var e=t.shape[t.shape.length-1],n=t.size/e,r=t.as2D(n,e);return Wt.runKernelFunc(function(t){return t.ifft(r)},{input:t}).reshape(t.shape)}}),Lc=Dn({rfft_:function(t,e){C("float32"===t.dtype,function(){return"The dtype for rfft() must be real value but got "+t.dtype});var n,r=t.shape[t.shape.length-1],i=t.size/r;if(null!=e&&e<r){var a=t.shape.map(function(t){return 0}),o=t.shape.map(function(t){return t});o[t.shape.length-1]=e,n=t.slice(a,o),r=e}else if(null!=e&&e>r){var s=t.shape.map(function(t){return t});s[t.shape.length-1]=e-r,n=t.concat($n(s),t.shape.length-1),r=e}else n=t;var u=n.zerosLike(),c=Mn(n,u).as2D(i,r),l=jc(c),f=Math.floor(r/2)+1,d=Rn(l),h=Fn(l),p=d.split([f,r-f],d.shape.length-1),m=h.split([f,r-f],h.shape.length-1),g=n.shape.slice();return g[n.shape.length-1]=f,Mn(p[0],m[0]).reshape(g)}}),zc=Dn({irfft_:function(t){var e=t.shape[t.shape.length-1],n=t.size/e;if(e<=2){var r=t.as2D(n,e),i=Pc(r);return Rn(i)}var a=[n,2*(e-1)],o=Rn(t).as2D(n,e),s=Fn(t).as2D(n,e),u=o.slice([0,1],[n,e-2]).reverse(1),c=s.slice([0,1],[n,e-2]).reverse(1).mul(Ln(-1)),l=o.concat(u,1),f=s.concat(c,1);return r=Mn(l,f).as2D(a[0],a[1]),i=Pc(r),Rn(i)}}),Bc=Object.freeze({fft:jc,ifft:Pc,rfft:Lc,irfft:zc}),Uc=Dn({sparseToDense_:function(t,e,n,r){void 0===r&&(r=0);var i=xn(t,"sparseIndices","sparseToDense","int32"),a=xn(e,"sparseValues","sparseToDense"),o=xn(r,"defaultValue","sparseToDense",a.dtype);return function(t,e,n,r){if("int32"!==t.dtype)throw new Error("tf.sparseToDense() expects the indices to be int32 type, but the dtype was "+t.dtype+".");if(t.rank>2)throw new Error("sparseIndices should be a scalar, vector, or matrix, but got shape "+t.shape+".");var i=t.rank>0?t.shape[0]:1,a=t.rank>1?t.shape[1]:1;if(n.length!==a)throw new Error("outputShape has incorrect number of elements:, "+n.length+", should be: "+a+".");var o=e.size;if(0!==e.rank&&(1!==e.rank||o!==i))throw new Error("sparseValues has incorrect shape "+e.shape+", should be [] or ["+i+"]");if(e.dtype!==r.dtype)throw new Error("sparseValues.dtype must match defaultValues.dtype")}(i,a,n,o),Wt.runKernelFunc(function(t){return t.sparseToDense(i,a,n,o)},{$sparseIndices:i,$sparseValues:a,$defaultValue:o})}}),Wc=Dn({gatherND_:function(t,e){var n=xn(e,"indices","gatherND","int32"),r=xn(t,"x","gatherND");return Wt.runKernelFunc(function(t){return t.gatherND(r,n)},{x:r,indices:n},null,"GatherNd")}}),Vc=Dn({diag_:function(t){var e=xn(t,"x","diag").flatten(),n=t.shape.concat(t.shape);return Wt.runKernelFunc(function(t){return t.diag(e)},{$x:e}).reshape(n)}}),qc=Dn({dropout_:function(t,e,n,r){var i=xn(t,"x","dropout");if(C("float32"===i.dtype,function(){return"x has to be a floating point tensor since it's going to be scaled, but got a "+i.dtype+" tensor instead."}),C(e>=0&&e<1,function(){return"rate must be a float in the range [0, 1), but got "+e+"."}),0===e)return t instanceof Ot?i.clone():i;var a=function(t,e){if(null==e)return t.shape.slice();if(D(t.shape,e))return e;if(t.shape.length===e.length){for(var n=[],r=0;r<t.shape.length;r++)null==e[r]&&null!=t.shape[r]?n.push(t.shape[r]):n.push(e[r]);return n}return e}(i,n),o=1-e,s=Pr(a,0,1,"float32",r).add(o).floor().div(o);return i.mul(s)}});function Hc(t,e,n){for(var r=1-t%2,i=new Float32Array(t),a=0;a<t;++a){var o=2*Math.PI*a/(t+r-1);i[a]=e-n*Math.cos(o)}return zn(i,"float32")}var Gc,$c=Dn({hannWindow_:function(t){return Hc(t,.5,.5)}}),Kc=Dn({hammingWindow_:function(t){return Hc(t,.54,.46)}}),Xc=Dn({frame_:function(t,e,n,r,i){void 0===r&&(r=!1),void 0===i&&(i=0);for(var a=0,o=[];a+e<=t.size;)o.push(ic(t,a,e)),a+=n;if(r)for(;a<t.size;){var s=a+e-t.size,u=Qn([ic(t,a,e-s),Kn([s],i)]);o.push(u),a+=n}return 0===o.length?Bn([],[0,e]):Qn(o).as2D(o.length,e)}}),Yc=Dn({stft_:function(t,e,n,r,i){var a;void 0===i&&(i=$c),null==r&&(a=e,r=Math.floor(Math.pow(2,Math.ceil(Math.log(a)/Math.log(2)))));for(var o=Xc(t,e,n),s=au(o,i(e)),u=[],c=0;c<o.shape[0];c++)u.push(Lc(s.slice([c,0],[1,e]),r));return Qn(u)}}),Jc=Object.freeze({hannWindow:$c,hammingWindow:Kc,frame:Xc,stft:Yc}),Zc=function(t,e,n){return void 0===n&&(n=1),u(this,void 0,void 0,function(){var r,i,a,o,s,u,l,f,d,h,p,m,g,v;return c(this,function(c){switch(c.label){case 0:return r=xn(t,"predictions","inTopK"),i=xn(e,"targets","inTopK"),C(r.rank>1,function(){return"inTopK() expects the predictions to be of rank 2 or higher, but got "+r.rank}),C(r.rank-1===i.rank,function(){return"predictions rank should be 1 larger than targets rank, but got predictions rank "+r.rank+" and targets rank "+i.rank}),A(r.shape.slice(0,r.shape.length-1),i.shape,"predictions's shape should be align with the targets' shape, except the last dimension."),a=r.shape[r.shape.length-1],C(n>0&&n<=a,function(){return"'k' passed to inTopK() must be > 0 && <= the predictions last dimension ("+a+"), but got "+n}),[4,r.data()];case 1:return o=c.sent(),[4,i.data()];case 2:for(s=c.sent(),u=[o.length/a,a],f=u[1],d=U("bool",l=u[0]),h=0;h<l;h++){for(p=h*f,m=o.subarray(p,p+f),g=[],v=0;v<m.length;v++)g.push({value:m[v],index:v});for(g.sort(function(t,e){return e.value-t.value}),d[h]=0,v=0;v<n;v++)if(g[v].index===s[h]){d[h]=1;break}}return t!==r&&r.dispose(),e!==i&&i.dispose(),[2,jn(d,i.shape,"bool")]}})})};!function(t){t[t.NONE=0]="NONE",t[t.MEAN=1]="MEAN",t[t.SUM=2]="SUM",t[t.SUM_BY_NONZERO_WEIGHTS=3]="SUM_BY_NONZERO_WEIGHTS"}(Gc||(Gc={}));var Qc=Dn({absoluteDifference_:function(t,e,n,r){void 0===r&&(r=Gc.SUM_BY_NONZERO_WEIGHTS);var i=xn(t,"labels","absoluteDifference"),a=xn(e,"predictions","absoluteDifference"),o=null;null!=n&&(o=xn(n,"weights","absoluteDifference")),A(i.shape,a.shape,"Error in absoluteDifference: ");var s=i.sub(a).abs();return tl(s,o,r)}}),tl=Dn({computeWeightedLoss_:function(t,e,n){void 0===n&&(n=Gc.SUM_BY_NONZERO_WEIGHTS);var r=xn(t,"losses","computeWeightedLoss"),i=null;null!=e&&(i=xn(e,"weights","computeWeightedLoss"));var a=null==i?r:r.mul(i);if(n===Gc.NONE)return a;if(n===Gc.SUM)return a.sum();if(n===Gc.MEAN){if(null==i)return a.mean();var o=r.size/i.size,s=a.sum().div(i.sum());return o>1?s.div(Ln(o)):s}if(n===Gc.SUM_BY_NONZERO_WEIGHTS){if(null==i)return a.sum().div(Ln(r.size));var u=i.mul(Gn(r.shape)).notEqual(Ln(0)).sum().toFloat();return a.sum().div(u)}throw Error("Unknown reduction: "+n)}}),el=Dn({cosineDistance_:function(t,e,n,r,i){void 0===i&&(i=Gc.SUM_BY_NONZERO_WEIGHTS);var a=xn(t,"labels","cosineDistance"),o=xn(e,"predictions","cosineDistance"),s=null;null!=r&&(s=xn(r,"weights","cosineDistance")),A(a.shape,o.shape,"Error in cosineDistance: ");var u=Ln(1).sub(a.mul(o).sum(n,!0));return tl(u,s,i)}}),nl=Dn({hingeLoss_:function(t,e,n,r){void 0===r&&(r=Gc.SUM_BY_NONZERO_WEIGHTS);var i=xn(t,"labels","hingeLoss"),a=xn(e,"predictions","hingeLoss"),o=null;null!=n&&(o=xn(n,"weights","hingeLoss")),A(i.shape,a.shape,"Error in hingeLoss: ");var s=Ln(1);i=Ln(2).mul(i).sub(s);var u=s.sub(i.mul(a)).relu();return tl(u,o,r)}}),rl=Dn({huberLoss_:function(t,e,n,r,i){void 0===r&&(r=1),void 0===i&&(i=Gc.SUM_BY_NONZERO_WEIGHTS);var a=xn(t,"labels","huberLoss"),o=xn(e,"predictions","huberLoss"),s=null;null!=n&&(s=xn(n,"weights","huberLoss")),A(a.shape,o.shape,"Error in huberLoss: ");var u=Ln(r),c=o.sub(a).abs(),l=eu(c,u),f=c.sub(l),d=Ln(.5).mul(l.square()).add(u.mul(f));return tl(d,s,i)}}),il=Dn({logLoss_:function(t,e,n,r,i){void 0===r&&(r=1e-7),void 0===i&&(i=Gc.SUM_BY_NONZERO_WEIGHTS);var a=xn(t,"labels","logLoss"),o=xn(e,"predictions","logLoss"),s=null;null!=n&&(s=xn(n,"weights","logLoss")),A(a.shape,o.shape,"Error in logLoss: ");var u=Ln(1),c=Ln(r),l=a.mul(o.add(c).log()).neg().sub(u.sub(a).mul(u.sub(o).add(c).log()));return tl(l,s,i)}}),al=Dn({meanSquaredError_:function(t,e,n,r){void 0===r&&(r=Gc.SUM_BY_NONZERO_WEIGHTS);var i=xn(t,"labels","meanSquaredError"),a=xn(e,"predictions","meanSquaredError"),o=null;null!=n&&(o=xn(n,"weights","meanSquaredError")),A(i.shape,a.shape,"Error in meanSquaredError: ");var s=i.squaredDifference(a);return tl(s,o,r)}}),ol=Dn({sigmoidCrossEntropy_:function(t,e,n,r,i){void 0===r&&(r=0),void 0===i&&(i=Gc.SUM_BY_NONZERO_WEIGHTS);var a=xn(t,"multiClassLabels","sigmoidCrossEntropy"),o=xn(e,"logits","sigmoidCrossEntropy"),s=null;if(null!=n&&(s=xn(n,"weights","sigmoidCrossEntropy")),A(a.shape,o.shape,"Error in sigmoidCrossEntropy: "),r>0){var u=Ln(r),c=Ln(1),l=Ln(.5);a=a.mul(c.sub(u)).add(l.mul(u))}var f=function(t,e){var n=xn(t,"labels","sigmoidCrossEntropyWithLogits"),r=xn(e,"logits","sigmoidCrossEntropyWithLogits");A(n.shape,r.shape,"Error in sigmoidCrossEntropyWithLogits: ");var i=r.relu(),a=r.mul(n),o=r.abs().neg().exp().log1p();return i.sub(a).add(o)}(a,o);return tl(f,s,i)}}),sl=Dn({softmaxCrossEntropy_:function(t,e,n,r,i){void 0===r&&(r=0),void 0===i&&(i=Gc.SUM_BY_NONZERO_WEIGHTS);var a=xn(t,"onehotLabels","softmaxCrossEntropy"),o=xn(e,"logits","softmaxCrossEntropy"),s=null;if(null!=n&&(s=xn(n,"weights","softmaxCrossEntropy")),A(a.shape,o.shape,"Error in softmaxCrossEntropy: "),r>0){var u=Ln(r),c=Ln(1),l=Ln(a.shape[1]);a=a.mul(c.sub(u)).add(u.div(l))}var f=function(t,e,n){if(void 0===n&&(n=-1),-1===n&&(n=e.rank-1),n!==e.rank-1)throw Error("Softmax cross entropy along a non-last dimension is not yet supported. Labels / logits was rank "+e.rank+" and dim was "+n);return yi(function(t,e,r){var i=e.logSumExp([n],!0),a=e.toFloat().sub(i);return r([t,a]),{value:a.mul(t).neg().sum([n]),gradFunc:function(t,e){var r=e[0],i=e[1],a=On(t.shape,[n]);return[t.reshape(a).mul(r.toFloat().sub(i.exp())),t.reshape(a).mul(i.exp().sub(r.toFloat()))]}}})(t,e)}(a,o);return tl(f,s,i)}}),ul=Object.freeze({get Reduction(){return Gc},absoluteDifference:Qc,computeWeightedLoss:tl,cosineDistance:el,hingeLoss:nl,huberLoss:rl,logLoss:il,meanSquaredError:al,sigmoidCrossEntropy:ol,softmaxCrossEntropy:sl});function cl(t,e){return void 0===e&&(e=!1),Wt.tidy(function(){if(2!==t.shape.length)throw new Error("qr2d() requires a 2D Tensor, but got a "+t.shape.length+"D Tensor.");for(var n=t.shape[0],r=t.shape[1],i=Sr(n),a=t.clone(),o=Bn([[1]],[1,1]),s=o.clone(),u=n>=r?r:n,c=function(t){var e,u=a,c=s,l=i;e=Wt.tidy(function(){var e=a.slice([t,t],[n-t,1]),u=e.norm(),c=a.slice([t,t],[1,1]),l=Bn([[-1]]).where(c.greater(0),Bn([[1]])),f=c.sub(l.mul(u)),d=e.div(f);s=1===d.shape[0]?o.clone():o.concat(d.slice([1,0],[d.shape[0]-1,d.shape[1]]),0);var h=l.matMul(f).div(u).neg(),p=a.slice([t,0],[n-t,r]),m=h.mul(s);if(0===t)a=p.sub(m.matMul(s.transpose().matMul(p)));else{var g=p.sub(m.matMul(s.transpose().matMul(p)));a=a.slice([0,0],[t,r]).concat(g,0)}var v=i.slice([0,t],[n,i.shape[1]-t]);if(0===t)i=v.sub(v.matMul(s).matMul(m.transpose()));else{var y=v.sub(v.matMul(s).matMul(m.transpose()));i=i.slice([0,0],[n,t]).concat(y,1)}return[s,a,i]}),s=e[0],a=e[1],i=e[2],an([u,c,l])},l=0;l<u;++l)c(l);return!e&&n>r&&(i=i.slice([0,0],[n,r]),a=a.slice([0,0],[r,r])),[i,a]})}var ll=Dn({bandPart_:function(t,e,n){if(e%1!=0)throw new Error("bandPart(): numLower must be an integer, got "+e+".");if(n%1!=0)throw new Error("bandPart(): numUpper must be an integer, got "+n+".");var r=xn(t,"a","bandPart");if(r.rank<2)throw new Error("bandPart(): Rank must be at least 2, got "+r.rank+".");var i=r.shape,a=r.shape.slice(-2),o=a[0],s=a[1];if(!(e<=o))throw new Error("bandPart(): numLower ("+e+") must not be greater than the number of rows ("+o+").");if(!(n<=s))throw new Error("bandPart(): numUpper ("+n+") must not be greater than the number of columns ("+s+").");e<0&&(e=o),n<0&&(n=s);var u=Yn(0,o,1,"int32").reshape([-1,1]),c=Yn(0,s,1,"int32"),l=lu(u,c),f=zs(l.lessEqual(Ln(+e,"int32")),l.greaterEqual(Ln(-n,"int32"))),d=$n([o,s],r.dtype);return Ur(qr(r.reshape([-1,o,s])).map(function(t){return Vs(f,t,d)})).reshape(i)}}),fl=Dn({gramSchmidt_:function(t){var e;if(Array.isArray(t)){e=!1,C(null!=t&&t.length>0,function(){return"Gram-Schmidt process: input must not be null, undefined, or empty"});for(var n=t[0].shape[0],r=function(e){C(t[e].shape[0]===n,function(){return"Gram-Schmidt: Non-unique lengths found in the input vectors: ("+t[e].shape[0]+" vs. "+n+")"})},i=1;i<t.length;++i)r(i)}else e=!0,t=ir(t,t.shape[0],0).map(function(t){return Br(t,[0])});C(t.length<=t[0].shape[0],function(){return"Gram-Schmidt: Number of vectors ("+t.length+") exceeds number of dimensions ("+t[0].shape[0]+")."});var a=[],o=t,s=function(t){a.push(Wt.tidy(function(){var e=o[t];if(t>0)for(var n=0;n<t;++n){var r=bc(a[n].mulStrict(e)).mul(a[n]);e=e.sub(r)}return e.div(Nc(e,"euclidean"))}))};for(i=0;i<t.length;++i)s(i);return e?Ur(a,0):a}}),dl=Dn({qr_:function(t,e){if(void 0===e&&(e=!1),t.rank<2)throw new Error("qr() requires input tensor to have a rank >= 2, but got rank "+t.rank);if(2===t.rank)return cl(t,e);var n=t.shape.slice(0,t.shape.length-2).reduce(function(t,e){return t*e}),r=[],i=[];return qr(t.reshape([n,t.shape[t.shape.length-2],t.shape[t.shape.length-1]]),0).forEach(function(t){var n=cl(t,e),a=n[0],o=n[1];r.push(a),i.push(o)}),[Ur(r,0).reshape(t.shape),Ur(i,0).reshape(t.shape)]}}),hl=Object.freeze({bandPart:ll,gramSchmidt:fl,qr:dl});function pl(t,e,n,r,i,a){null==r&&(r=.5),null==i&&(i=Number.NEGATIVE_INFINITY),null==a&&(a=0);var o=t.shape[0];return n=Math.min(n,o),C(0<=r&&r<=1,function(){return"iouThreshold must be in [0, 1], but was '"+r+"'"}),C(2===t.rank,function(){return"boxes must be a 2D tensor, but was of rank '"+t.rank+"'"}),C(4===t.shape[1],function(){return"boxes must have 4 columns, but 2nd dimension was "+t.shape[1]}),C(1===e.rank,function(){return"scores must be a 1D tensor"}),C(e.shape[0]===o,function(){return"scores has incompatible shape with boxes. Expected "+o+", but was "+e.shape[0]}),C(0<=a&&a<=1,function(){return"softNmsSigma must be in [0, 1], but was '"+a+"'"}),{maxOutputSize:n,iouThreshold:r,scoreThreshold:i,softNmsSigma:a}}var ml=Dn({resizeBilinear_:function(t,e,n){void 0===n&&(n=!1);var r=xn(t,"images","resizeBilinear");C(3===r.rank||4===r.rank,function(){return"Error in resizeBilinear: x must be rank 3 or 4, but got rank "+r.rank+"."}),C(2===e.length,function(){return"Error in resizeBilinear: new shape must 2D, but got shape "+e+"."});var i=r,a=!1;3===r.rank&&(a=!0,i=r.as4D(1,r.shape[0],r.shape[1],r.shape[2]));var o=e[0],s=e[1],u=Wt.runKernelFunc(function(t,e){return e([i]),t.resizeBilinear(i,o,s,n)},{x:i},function(t,e){return{x:function(){return Wt.runKernelFunc(function(r){return r.resizeBilinearBackprop(t,e[0],n)},{})}}},"ResizeBilinear",{alignCorners:n,newHeight:o,newWidth:s});return a?u.as3D(u.shape[1],u.shape[2],u.shape[3]):u}}),gl=Dn({resizeNearestNeighbor_:function(t,e,n){void 0===n&&(n=!1);var r=xn(t,"images","resizeNearestNeighbor");C(3===r.rank||4===r.rank,function(){return"Error in resizeNearestNeighbor: x must be rank 3 or 4, but got rank "+r.rank+"."}),C(2===e.length,function(){return"Error in resizeNearestNeighbor: new shape must 2D, but got shape "+e+"."}),C("float32"===r.dtype||"int32"===r.dtype,function(){return"`images` must have `int32` or `float32` as dtype"});var i=r,a=!1;3===r.rank&&(a=!0,i=r.as4D(1,r.shape[0],r.shape[1],r.shape[2]));var o=e[0],s=e[1],u=Wt.runKernelFunc(function(t,e){return e([i]),t.resizeNearestNeighbor(i,o,s,n)},{batchImages:i},function(t,e){return{batchImages:function(){return Wt.runKernelFunc(function(r){return r.resizeNearestNeighborBackprop(t,e[0],n)},{})}}});return a?u.as3D(u.shape[1],u.shape[2],u.shape[3]):u}}),vl=Dn({nonMaxSuppression_:function(t,e,n,r,i){void 0===r&&(r=.5),void 0===i&&(i=Number.NEGATIVE_INFINITY);var a=xn(t,"boxes","nonMaxSuppression"),o=xn(e,"scores","nonMaxSuppression"),s=pl(a,o,n,r,i);n=s.maxOutputSize,r=s.iouThreshold,i=s.scoreThreshold;var u={maxOutputSize:n,iouThreshold:r,scoreThreshold:i};return Wt.runKernelFunc(function(t){return t.nonMaxSuppression(a,o,n,r,i)},{boxes:a,scores:o},null,"NonMaxSuppressionV3",u)}}),yl=Dn({nonMaxSuppressionWithScore_:function(t,e,n,r,i,a){void 0===r&&(r=.5),void 0===i&&(i=Number.NEGATIVE_INFINITY),void 0===a&&(a=0);var o=xn(t,"boxes","nonMaxSuppression"),s=xn(e,"scores","nonMaxSuppression"),u=pl(o,s,n,r,i,a),c={maxOutputSize:n=u.maxOutputSize,iouThreshold:r=u.iouThreshold,scoreThreshold:i=u.scoreThreshold,softNmsSigma:a=u.softNmsSigma},l=Wt.runKernel("NonMaxSuppressionV5",{boxes:o,scores:s},c);return{selectedIndices:l[0],selectedScores:l[1]}}}),bl=Dn({cropAndResize_:function(t,e,n,r,i,a){var o=xn(t,"image","cropAndResize"),s=xn(e,"boxes","cropAndResize","float32"),u=xn(n,"boxInd","cropAndResize","int32");i=i||"bilinear",a=a||0;var c=s.shape[0];return C(4===o.rank,function(){return"Error in cropAndResize: image must be rank 4,but got rank "+o.rank+"."}),C(2===s.rank&&4===s.shape[1],function(){return"Error in cropAndResize: boxes must be have size ["+c+",4] but had shape "+s.shape+"."}),C(1===u.rank&&u.shape[0]===c,function(){return"Error in cropAndResize: boxInd must be have size ["+c+"] but had shape "+s.shape+"."}),C(2===r.length,function(){return"Error in cropAndResize: cropSize must be of length 2, but got length "+r.length+"."}),C(r[0]>=1&&r[1]>=1,function(){return"cropSize must be atleast [1,1], but was "+r}),C("bilinear"===i||"nearest"===i,function(){return"method must be bilinear or nearest, but was "+i}),Wt.runKernelFunc(function(t,e){return t.cropAndResize(o,s,u,r,i,a)},{images:o,boxes:s,boxInd:u},null,"CropAndResize",{method:i,extrapolationValue:a,cropSize:r})}}),xl=Object.freeze({resizeBilinear:ml,resizeNearestNeighbor:gl,nonMaxSuppression:vl,nonMaxSuppressionAsync:function(t,e,n,r,i){return void 0===r&&(r=.5),void 0===i&&(i=Number.NEGATIVE_INFINITY),u(this,void 0,void 0,function(){var a,o,s,u,l,f,d;return c(this,function(c){switch(c.label){case 0:return a=xn(t,"boxes","nonMaxSuppressionAsync"),o=xn(e,"scores","nonMaxSuppressionAsync"),s=pl(a,o,n,r,i),n=s.maxOutputSize,r=s.iouThreshold,i=s.scoreThreshold,[4,Promise.all([a.data(),o.data()])];case 1:return u=c.sent(),l=u[0],f=u[1],d=Yi(l,f,n,r,i),a!==t&&a.dispose(),o!==e&&o.dispose(),[2,d]}})})},nonMaxSuppressionWithScore:yl,nonMaxSuppressionWithScoreAsync:function(t,e,n,r,i,a){return void 0===r&&(r=.5),void 0===i&&(i=Number.NEGATIVE_INFINITY),void 0===a&&(a=0),u(this,void 0,void 0,function(){var o,s,u,l,f,d,h;return c(this,function(c){switch(c.label){case 0:return o=xn(t,"boxes","nonMaxSuppressionAsync"),s=xn(e,"scores","nonMaxSuppressionAsync"),u=pl(o,s,n,r,i,a),n=u.maxOutputSize,r=u.iouThreshold,i=u.scoreThreshold,a=u.softNmsSigma,[4,Promise.all([o.data(),s.data()])];case 1:return l=c.sent(),f=l[0],d=l[1],h=Ji(f,d,n,r,i,a),o!==t&&o.dispose(),s!==e&&s.dispose(),[2,h]}})})},cropAndResize:bl}),wl=function(t,e){return!(t>0)||"linear"===e},kl=function(t,e,n){if(null==n||"linear"===n)return t;if("relu"===n)return t.mul(e.step());throw new Error("Gradient for activation "+n+" has not been implemented yet.")},_l=function(t,e){var n=e,r=Si(t.shape,e.shape);return r.length>0&&(n=n.sum(r)),n.reshape(t.shape)},El=function(t,e,n){if("linear"===e)return t;if("relu"===e)return Ec(t);if("elu"===e)return wc(t);if("relu6"===e)return Oc(t);if("prelu"===e)return _c(t,n);throw new Error("Unknown fused activation "+e+".")},Ol=Dn({fusedMatMul_:function(t){var e,n=t.a,r=t.b,i=t.transposeA,a=void 0!==i&&i,o=t.transposeB,s=void 0!==o&&o,u=t.bias,c=t.activation,l=void 0===c?"linear":c,f=t.preluActivationWeights;if(!1===wl(Wt.state.gradientDepth,l)){var d=Vu(n,r,a,s);return null!=u&&(d=Hs(d,u)),El(d,l,f)}var h=xn(n,"a","fused matMul"),p=xn(r,"b","fused matMul");e=Ft(h,p),h=e[0],p=e[1];var m=a?h.shape[h.rank-2]:h.shape[h.rank-1],g=s?p.shape[p.rank-1]:p.shape[p.rank-2],v=a?h.shape[h.rank-1]:h.shape[h.rank-2],y=s?p.shape[p.rank-2]:p.shape[p.rank-1],b=h.shape.slice(0,-2),x=p.shape.slice(0,-2),w=I(b),k=I(x);C(h.rank>=2&&p.rank>=2&&h.rank===p.rank,function(){return"Error in fused matMul: inputs must have the same rank of at least 2, got ranks "+h.rank+" and "+p.rank+"."}),C(D(b,x),function(){return"Error in fused matMul: outer dimensions ("+b+") and ("+x+") of Tensors with shapes "+h.shape+" and "+p.shape+" must match."}),C(m===g,function(){return"Error in fused matMul: inner shapes ("+m+") and ("+g+") of Tensors with shapes "+h.shape+" and "+p.shape+" and transposeA="+a+" and transposeB="+s+" must match."});var _,E,O=h.shape.slice(0,-2).concat([v,y]),S=a?h.as3D(w,m,v):h.as3D(w,v,m),A=s?p.as3D(k,y,g):p.as3D(k,g,y);null!=u&&Ci(O,(_=Ft(_=xn(u,"bias","fused matMul"),h)[0]).shape),null!=f&&(E=xn(f,"prelu weights","fused matMul"));var N={a:S,b:A};null!=u&&(N.bias=_),null!=f&&(N.preluActivationWeights=E);var T=[S,A];return Wt.runKernelFunc(function(t,e){var n=t.fusedBatchMatMul({a:S,b:A,transposeA:a,transposeB:s,bias:_,activation:l,preluActivationWeights:E});return e([S,A,n]),n},N,function(t,e){var n=e[0],r=e[1],i=e[2],o=kl(t,i,l),c={};return null!=u&&(c={bias:function(){return _l(_,o)}}),a||s?!a&&s?Object.assign({a:function(){return o.matMul(r,!1,!1)},b:function(){return o.matMul(n,!0,!1)}},c):a&&!s?Object.assign({a:function(){return r.matMul(o,!1,!0)},b:function(){return n.matMul(o,!1,!1)}},c):Object.assign({a:function(){return r.matMul(o,!0,!0)},b:function(){return o.matMul(n,!0,!0)}},c):Object.assign({a:function(){return o.matMul(r,!1,!0)},b:function(){return n.matMul(o,!0,!1)}},c)},"_FusedMatMul",{transposeA:a,transposeB:s,activation:l},T,[!0]).reshape(O)}}),Sl=Dn({fusedConv2d_:function(t){var e=t.x,n=t.filter,r=t.strides,i=t.pad,a=t.dataFormat,o=void 0===a?"NHWC":a,s=t.dilations,u=void 0===s?[1,1]:s,c=t.dimRoundingMode,l=t.bias,f=t.activation,d=void 0===f?"linear":f,h=t.preluActivationWeights;if(d=d||"linear",!1===wl(Wt.state.gradientDepth,d)){var p=Mu(e,n,r,i,o,u,c);return null!=l&&(p=Hs(p,l)),El(p,d,h)}var m=xn(e,"x","conv2d"),g=xn(n,"filter","conv2d"),v=m,y=!1;3===m.rank&&(y=!0,v=m.as4D(1,m.shape[0],m.shape[1],m.shape[2])),C(4===v.rank,function(){return"Error in fused conv2d: input must be rank 4, but got rank "+v.rank+"."}),C(4===g.rank,function(){return"Error in fused conv2d: filter must be rank 4, but got rank "+g.rank+"."}),null!=c&&C(M(i),function(){return"Error in fused conv2d: pad must be an integer when using, dimRoundingMode "+c+" but got pad "+i+"."}),C(v.shape[3]===g.shape[2],function(){return"Error in conv2d: depth of input ("+v.shape[3]+") must match input depth for filter "+g.shape[2]+"."}),C(Li(r,u),function(){return"Error in conv2D: Either strides or dilations must be 1. Got strides "+r+" and dilations '"+u+"'"}),C("NHWC"===o,function(){return"Error in conv2d: got dataFormat of "+o+" but only NHWC is currently supported."});var b,x,w=Ti(v.shape,g.shape,r,u,i,c);null!=l&&(b=Ft(b=xn(l,"bias","fused conv2d"),m)[0],Ci(w.outShape,b.shape)),null!=h&&(x=xn(h,"prelu weights","fused conv2d"));var k={x:v,filter:g};null!=l&&(k.bias=b),null!=h&&(k.preluActivationWeights=x);var _=[g,v],E=Wt.runKernelFunc(function(t,e){var n=t.fusedConv2d({input:v,filter:g,convInfo:w,bias:b,activation:d,preluActivationWeights:x});return e([g,v,n]),n},k,function(t,e){var n=e,a=n[0],o=n[1],s=n[2],c=kl(t,s,d);C(Pi(u),function(){return"Error in gradient of fused conv2D: dilation rates greater than 1 are not yet supported in gradients. Got dilations '"+u+"'"});var f={};return null!=l&&(f={bias:function(){return _l(b,c)}}),Object.assign({x:function(){return ju(o.shape,c,a,r,i)},filter:function(){return Fu(o,c,a.shape,r,i)}},f)},"FusedConv2D",{convInfo:w,activation:d},_,[!0]);return y?E.as3D(E.shape[1],E.shape[2],E.shape[3]):E}}),Cl=Dn({fusedDepthwiseConv2d_:function(t){var e=t.x,n=t.filter,r=t.strides,i=t.pad,a=t.dataFormat,o=void 0===a?"NHWC":a,s=t.dilations,u=void 0===s?[1,1]:s,c=t.dimRoundingMode,l=t.bias,f=t.activation,d=void 0===f?"linear":f,h=t.preluActivationWeights;if(!1===wl(Wt.state.gradientDepth,d)){var p=Pu(e,n,r,i,o,u,c);return null!=l&&(p=Hs(p,l)),El(p,d,h)}var m=xn(e,"x","depthwiseConv2d"),g=xn(n,"filter","depthwiseConv2d"),v=m,y=!1;3===m.rank&&(y=!0,v=m.as4D(1,m.shape[0],m.shape[1],m.shape[2])),C(4===v.rank,function(){return"Error in fused depthwiseConv2d: input must be rank 4, but got rank "+v.rank+"."}),C(4===g.rank,function(){return"Error in fused depthwiseConv2d: filter must be rank 4, but got rank "+g.rank+"."}),C(v.shape[3]===g.shape[2],function(){return"Error in fused depthwiseConv2d: number of input channels ("+v.shape[3]+") must match the inChannels dimension in filter "+g.shape[2]+"."}),null==u&&(u=[1,1]),C(Li(r,u),function(){return"Error in fused depthwiseConv2d: Either strides or dilations must be 1. Got strides "+r+" and dilations '"+u+"'"}),null!=c&&C(M(i),function(){return"Error in fused depthwiseConv2d: pad must be an integer when using dimRoundingMode "+c+" but got pad "+i+"."});var b,x,w=Ti(v.shape,g.shape,r,u,i,c,!0);null!=l&&(b=Ft(b=xn(l,"bias","fused conv2d"),m)[0],Ci(w.outShape,b.shape)),null!=h&&(x=xn(h,"prelu weights","fused depthwiseConv2d"));var k={x:v,filter:g};null!=l&&(k.bias=b),null!=h&&(k.preluActivationWeights=x);var _=[g,v],E=Wt.runKernelFunc(function(t,e){var n=t.fusedDepthwiseConv2D({input:v,filter:g,convInfo:w,bias:b,activation:d,preluActivationWeights:x});return e([g,v,n]),n},k,function(t,e){C(Pi(u),function(){return"Error in gradient of fused depthwiseConv2d: dilation rates greater than 1 are not yet supported. Got dilations '"+u+"'"});var n=e[0],r=e[1],i=e[2],a=kl(t,i,d),o={};return null!=l&&(o={bias:function(){return _l(b,a)}}),Object.assign({x:function(){return Lu(r.shape,a,n,w)},filter:function(){return zu(r,a,n.shape,w)}},o)},"FusedDepthwiseConv2D",{convInfo:w,activation:d},_,[!0]);return y?E.as3D(E.shape[1],E.shape[2],E.shape[3]):E}}),Al=Object.freeze({matMul:Ol,conv2d:Sl,depthwiseConv2d:Cl}),Nl=Object.freeze({image:xl,linalg:hl,losses:ul,spectral:Bc,fused:Al,signal:Jc,square:Wo,squaredDifference:qo,conv1d:Du,conv2d:Mu,conv3d:Ru,depthwiseConv2d:Pu,separableConv2d:Bu,conv2dTranspose:Uu,conv3dTranspose:Wu,op:Dn,batchNormalization2d:Is,batchNormalization3d:Ds,batchNormalization4d:Ms,batchNormalization:Rs,batchNorm:Fs,batchNorm2d:js,batchNorm3d:Ps,batchNorm4d:Ls,booleanMaskAsync:Au,complex:Mn,real:Rn,imag:Fn,concat:Qn,concat1d:tr,concat2d:er,concat3d:nr,concat4d:rr,split:ir,matMul:Vu,dot:qu,outerProduct:Hu,reverse:Gu,reverse1d:$u,reverse2d:Ku,reverse3d:Xu,reverse4d:Yu,maxPool:Qu,avgPool:tc,pool:ec,maxPool3d:nc,avgPool3d:rc,slice:ic,slice1d:ac,slice2d:oc,slice3d:sc,slice4d:uc,abs:Ho,acos:Go,acosh:$o,asin:Ko,asinh:Xo,atan:Yo,atanh:Jo,ceil:Zo,clipByValue:Qo,cos:ts,cosh:es,erf:ns,exp:rs,expm1:is,floor:as,log:os,log1p:ss,logSigmoid:us,neg:cs,reciprocal:ls,round:fs,rsqrt:ds,sigmoid:hs,sign:ps,isNaN:ms,isInf:gs,isFinite:vs,sin:ys,sinh:bs,softplus:xs,sqrt:ws,step:ks,tan:_s,tanh:Es,all:lc,any:fc,argMax:dc,argMin:hc,logSumExp:pc,max:mc,mean:gc,min:vc,moments:yc,sum:bc,prod:xc,equal:du,equalStrict:hu,greater:pu,greaterEqual:mu,greaterEqualStrict:gu,greaterStrict:vu,less:yu,lessEqual:bu,lessEqualStrict:xu,lessStrict:wu,notEqual:ku,notEqualStrict:_u,add:Hs,addN:Gs,addStrict:$s,atan2:Ks,div:Xs,divNoNan:Ys,divStrict:Js,floorDiv:Zs,maximum:Qs,maximumStrict:tu,minimum:eu,minimumStrict:nu,mod:ru,modStrict:iu,mul:au,mulStrict:ou,pow:su,powStrict:uu,squaredDifferenceStrict:cu,sub:lu,subStrict:fu,elu:wc,leakyRelu:kc,prelu:_c,relu:Ec,relu6:Oc,selu:Sc,logicalAnd:zs,logicalNot:Bs,logicalOr:Us,logicalXor:Ws,where:Vs,whereAsync:qs,buffer:vr,print:yr,batchToSpaceND:br,broadcastTo:xr,cast:wr,clone:kr,cumsum:_r,depthToSpace:Er,expandDims:Or,eye:Sr,multinomial:Cr,oneHot:Ar,pad:Nr,pad1d:Tr,pad2d:Ir,pad3d:Dr,pad4d:Mr,rand:Rr,randomNormal:Fr,randomGamma:jr,randomUniform:Pr,reshape:Lr,spaceToBatchND:zr,squeeze:Br,stack:Ur,tile:Wr,truncatedNormal:Vr,unstack:qr,setdiff1dAsync:Hr,fill:Kn,linspace:Xn,ones:Gn,range:Yn,scalar:Ln,tensor:jn,tensor1d:zn,tensor2d:Bn,tensor3d:Un,tensor4d:Wn,tensor5d:Vn,tensor6d:qn,variable:Hn,zeros:$n,onesLike:Jn,zerosLike:Zn,transpose:Cc,softmax:xi,logSoftmax:wi,localResponseNormalization:Ac,norm:Nc,gather:Su,unsortedSegmentSum:Cu,basicLSTMCell:Tc,multiRNNCell:Ic,movingAverage:Dc,stridedSlice:Mc,topk:Rc,scatterND:Fc,fft:jc,ifft:Pc,rfft:Lc,irfft:zc,sparseToDense:Uc,gatherND:Wc,diag:Vc,dropout:qc,hannWindow:$c,hammingWindow:Kc,frame:Xc,stft:Yc,inTopKAsync:Zc});function Tl(t,e){Array.isArray(t)||(t=[t]),t.forEach(function(t){null!=t&&C("complex64"!==t.dtype,function(){return e+" does not support complex64 tensors."})})}function Il(t,e,n,r){if("linear"===n)return t.linear(e);if("relu"===n)return t.relu(e);if("elu"===n)return t.elu(e);if("relu6"===n)return t.relu6(e);if("prelu"===n)return t.prelu(e,r);throw new Error("Activation "+n+" has not been implemented for the CPU backend.")}var Dl=function(t){function e(){var e=t.call(this)||this;return e.blockSize=48,e.firstUse=!0,e.data=new ki(e,Wt),e}return s(e,t),e.prototype.write=function(t,e,n){this.firstUse&&(this.firstUse=!1,f().get("IS_NODE")&&vn("\n============================\nHi there 👋. Looks like you are running TensorFlow.js in Node.js. To speed things up dramatically, install our node backend, which binds to TensorFlow C++, by running npm i @tensorflow/tfjs-node, or npm i @tensorflow/tfjs-node-gpu if you have CUDA. Then call require('@tensorflow/tfjs-node'); (-gpu suffix for CUDA) at the start of your program. Visit https://github.com/tensorflow/tfjs-node for more details.\n============================"));var r={};return this.data.set(r,{values:t,dtype:n}),r},e.prototype.move=function(t,e,n,r){this.data.set(t,{values:e,dtype:r})},e.prototype.numDataIds=function(){return this.data.numDataIds()},e.prototype.read=function(t){return u(this,void 0,void 0,function(){return c(this,function(e){return[2,this.readSync(t)]})})},e.prototype.readSync=function(t){var e=this.data.get(t),n=e.dtype,r=e.complexTensors;return"complex64"===n?qi(this.readSync(r.real.dataId),this.readSync(r.imag.dataId)):this.data.get(t).values},e.prototype.bufferSync=function(t){var e=this.readSync(t.dataId),n=e;if("string"===t.dtype)try{n=e.map(function(t){return ct(t)})}catch(t){throw new Error("Failed to decode encoded string bytes into utf-8")}return vr(t.shape,t.dtype,n)},e.prototype.makeOutput=function(t,e,n){var r=this.write(t,e,n);return Wt.makeTensorFromDataId(r,e,n,this)},e.prototype.disposeData=function(t){if(this.data.has(t)){var e=this.data.get(t).complexTensors;null!=e&&(e.real.dispose(),e.imag.dispose()),this.data.delete(t)}},e.prototype.time=function(t){return u(this,void 0,void 0,function(){var e;return c(this,function(n){return e=ot(),t(),[2,{kernelMs:ot()-e}]})})},e.prototype.memory=function(){return{unreliable:!0,reasons:["The reported memory is an upper bound. Due to automatic garbage collection, the true allocated memory may be less."]}},e.prototype.complex=function(t,e){var n=this.makeOutput(null,t.shape,"complex64");return this.data.get(n.dataId).complexTensors={real:Wt.keep(t.clone()),imag:Wt.keep(e.clone())},n},e.prototype.real=function(t){return this.data.get(t.dataId).complexTensors.real.clone()},e.prototype.imag=function(t){return this.data.get(t.dataId).complexTensors.imag.clone()},e.prototype.slice=function(t,e,n){if(Tl(t,"slice"),li(t.shape,e,n)){var r=fi(e,t.strides),i=I(n);return jn(this.readSync(t.dataId).subarray(r,r+i),n,t.dtype)}for(var a=vr(n,t.dtype),o=this.bufferSync(t),s=0;s<a.size;++s){var u=a.indexToLoc(s).map(function(t,n){return t+e[n]});a.values[s]=o.get.apply(o,u)}return a.toTensor()},e.prototype.stridedSlice=function(t,e,n,r){Tl(t,"stridedSlice");var i=si(e,n,r);if(i.some(function(t){return 0===t}))return jn([],i);for(var a=vr(i,t.dtype),o=this.bufferSync(t),s=0;s<a.size;s++){for(var u=a.indexToLoc(s),c=new Array(u.length),l=0;l<c.length;l++)c[l]=u[l]*r[l]+e[l];a.set.apply(a,[o.get.apply(o,c)].concat(u))}return a.toTensor()},e.prototype.diag=function(t){for(var e=this.readSync(t.dataId),n=vr([t.size,t.size],t.dtype),r=n.values,i=0;i<e.length;i++)r[i*t.size+i]=e[i];return n.toTensor()},e.prototype.unstack=function(t,e){for(var n=t.shape[e],r=new Array(t.rank-1),i=0,a=0;a<t.rank;a++)a!==e&&(r[i++]=t.shape[a]);var o=new Array(t.rank).fill(0),s=t.shape.slice();s[e]=1;var u=new Array(n);for(a=0;a<u.length;a++)o[e]=a,u[a]=this.slice(t,o,s).reshape(r);return u},e.prototype.reverse=function(t,e){Tl(t,"reverse");for(var n=vr(t.shape,t.dtype),r=this.bufferSync(t),i=function(i){var a=n.indexToLoc(i),o=a.slice();e.forEach(function(e){return o[e]=t.shape[e]-1-o[e]}),n.set.apply(n,[r.get.apply(r,o)].concat(a))},a=0;a<n.size;a++)i(a);return n.toTensor()},e.prototype.concat=function(t,e){var n=this;if("complex64"===t[0].dtype){var r=t.map(function(t){return Rn(t)}),i=t.map(function(t){return Fn(t)});return Mn(this.concat(r,e),this.concat(i,e))}var a=t.map(function(t){var n=I(t.shape.slice(e));return t.as2D(-1,n)}),o=In(a.map(function(t){return t.shape}),1),s=vr(o,t[0].dtype).values;if(1===a[0].shape[0]){var u=0;a.forEach(function(t){s.set(n.readSync(t.dataId),u),u+=t.size})}else{var c=0;a.forEach(function(t){for(var e=n.readSync(t.dataId),r=0,i=0;i<t.shape[0];++i)for(var a=i*o[1]+c,u=0;u<t.shape[1];++u)s[a+u]=e[r++];c+=t.shape[1]})}var l=In(t.map(function(t){return t.shape}),e);return jn(s,l,t[0].dtype)},e.prototype.neg=function(t){return Tl(t,"neg"),this.multiply(Ln(-1),t)},e.prototype.add=function(t,e){return"complex64"===t.dtype||"complex64"===e.dtype?this.broadcastedBinaryComplexOp(t.cast("complex64"),e.cast("complex64"),function(t,e,n,r){return{real:t+n,imag:e+r}}):this.broadcastedBinaryOp(t,e,Mt(t.dtype,e.dtype),function(t,e){return t+e})},e.prototype.addN=function(t){var e=this;Tl(t,"addN");for(var n=t.map(function(t){return e.readSync(t.dataId)}),r=vr(t[0].shape,t[0].dtype),i=r.values,a=0;a<t.length;a++)for(var o=n[a],s=0;s<i.length;s++)i[s]+=o[s];return r.toTensor()},e.prototype.softmax=function(t,e){var n=z([e],t.shape),r=this.max(t,n),i=On(r.shape,n),a=this.subtract(t,r.reshape(i)),o=this.exp(a),s=this.sum(o,n).reshape(i);return this.realDivide(o,s)},e.prototype.subtract=function(t,e){return"complex64"===t.dtype||"complex64"===e.dtype?this.broadcastedBinaryComplexOp(t.cast("complex64"),e.cast("complex64"),function(t,e,n,r){return{real:t-n,imag:e-r}}):this.broadcastedBinaryOp(t,e,Mt(t.dtype,e.dtype),function(t,e){return t-e})},e.prototype.pow=function(t,e){return Tl([t,e],"pow"),this.broadcastedBinaryOp(t,e,t.dtype,function(t,e){return Math.pow(t,e)})},e.prototype.batchMatMul=function(t,e,n,r){Tl([t,e],"matMul");for(var i=n?t.shape[1]:t.shape[2],a=n?t.shape[2]:t.shape[1],o=r?e.shape[1]:e.shape[2],s=t.shape[0],u=this.readSync(t.dataId),c=this.readSync(e.dataId),l=n?[t.strides[0],1,t.strides[1]]:[t.strides[0],t.strides[1],1],f=l[0],d=l[1],h=l[2],p=r?[1,e.strides[1],e.strides[0]]:[e.strides[1],1,e.strides[0]],m=p[0],g=p[1],v=p[2],y=a*o,b=vr([s,a,o],t.dtype),x=b.values,w=this.blockSize,k=0;k<s;k++)for(var _=0;_<a;_+=w)for(var E=0;E<o;E+=w)for(var O=0;O<i;O+=w)for(var S=Math.min(_+w,a),C=Math.min(E+w,o),A=Math.min(O+w,i),N=_;N<S;N++)for(var T=E;T<C;T++){for(var I=0,D=O;D<A;D++)I+=u[k*f+N*d+D*h]*c[D*m+T*g+k*v];x[k*y+(N*o+T)]+=I}return b.toTensor()},e.prototype.fusedBatchMatMul=function(t){var e=t.a,n=t.b,r=t.transposeA,i=t.transposeB,a=t.bias,o=t.activation,s=t.preluActivationWeights,u=this.batchMatMul(e,n,r,i);return a&&(u=this.add(u,a)),o&&(u=Il(this,u,o,s)),u},e.prototype.multiply=function(t,e){return"complex64"===t.dtype||"complex64"===e.dtype?this.broadcastedBinaryComplexOp(t.cast("complex64"),e.cast("complex64"),function(t,e,n,r){return{real:t*n-e*r,imag:t*r+e*n}}):this.broadcastedBinaryOp(t,e,Mt(t.dtype,e.dtype),function(t,e){return t*e})},e.prototype.realDivide=function(t,e){return Tl([t,e],"realDivide"),this.broadcastedBinaryOp(t,e,"float32",function(t,e){return t/e})},e.prototype.floorDiv=function(t,e){return Tl([t,e],"floorDiv"),this.broadcastedBinaryOp(t,e,"int32",function(t,e){return Math.floor(t/e)})},e.prototype.sum=function(t,e){Tl(t,"sum"),Sn("sum",e,t.rank);for(var n=En(t.shape,e),r=n[0],i=n[1],a=$n(r,Mt(t.dtype,"int32")),o=I(i),s=this.readSync(a.dataId),u=this.readSync(t.dataId),c=0;c<s.length;++c){for(var l=c*o,f=0,d=0;d<o;++d)f+=u[l+d];s[c]=f}return a},e.prototype.prod=function(t,e){Tl(t,"sum");for(var n=En(t.shape,e),r=n[0],i=n[1],a=$n(r,Mt(t.dtype,"int32")),o=I(i),s=this.readSync(a.dataId),u=this.readSync(t.dataId),c=0;c<s.length;++c){for(var l=c*o,f=1,d=0;d<o;++d)f*=u[l+d];s[c]=f}return a},e.prototype.unsortedSegmentSum=function(t,e,n){Tl(t,"unsortedSegmentSum");for(var r=[],i=t.rank-e.rank,a=0;a<i;++a)e=e.expandDims(a+1);for(a=0;a<n;++a){var o=Ln(a,"int32"),s=du(o,e).asType("float32").mul(t).sum(0);r.push(s)}return Ur(r)},e.prototype.argMin=function(t,e){Tl(t,"argMin");var n=[e];Sn("argMin",n,t.rank);for(var r=En(t.shape,n),i=r[0],a=r[1],o=$n(i,"int32"),s=I(a),u=this.readSync(o.dataId),c=this.readSync(t.dataId),l=0;l<u.length;++l){for(var f=l*s,d=c[f],h=0,p=0;p<s;++p){var m=c[f+p];m<d&&(d=m,h=p)}u[l]=h}return o},e.prototype.argMax=function(t,e){Tl(t,"argMax");var n=[e];Sn("argMax",n,t.rank);for(var r=En(t.shape,n),i=r[0],a=r[1],o=$n(i,"int32"),s=I(a),u=this.readSync(o.dataId),c=this.readSync(t.dataId),l=0;l<u.length;++l){for(var f=l*s,d=c[f],h=0,p=0;p<s;++p){var m=c[f+p];m>d&&(d=m,h=p)}u[l]=h}return o},e.prototype.cumsum=function(t,e,n,r){if(Tl(t,"cumsum"),e!==t.rank-1)throw new Error("backend.cumsum in CPU expects an inner-most axis="+(t.rank-1)+" but got axis="+e);for(var i=Mt(t.dtype,"int32"),a=$n(t.shape,i),o=this.readSync(a.dataId),s=this.readSync(t.dataId),u=t.shape[t.rank-1],c=r?function(t,e){return t+u-e-1}:function(t,e){return t+e},l=0;l<s.length;l+=u)for(var f=0;f<u;f++){var d=c(l,f);if(0===f)o[d]=n?0:s[d];else{var h=c(l,f-1);o[d]=n?s[h]+o[h]:s[d]+o[h]}}return a},e.prototype.equal=function(t,e){return Tl([t,e],"equal"),this.broadcastedBinaryOp(t,e,"bool",function(t,e){return t===e?1:0})},e.prototype.notEqual=function(t,e){return Tl([t,e],"notEqual"),this.broadcastedBinaryOp(t,e,"bool",function(t,e){return t!==e?1:0})},e.prototype.less=function(t,e){return Tl([t,e],"less"),this.broadcastedBinaryOp(t,e,"bool",function(t,e){return t<e?1:0})},e.prototype.lessEqual=function(t,e){return Tl([t,e],"lessEqual"),this.broadcastedBinaryOp(t,e,"bool",function(t,e){return t<=e?1:0})},e.prototype.greater=function(t,e){return Tl([t,e],"greater"),this.broadcastedBinaryOp(t,e,"bool",function(t,e){return t>e?1:0})},e.prototype.greaterEqual=function(t,e){return Tl([t,e],"greaterEqual"),this.broadcastedBinaryOp(t,e,"bool",function(t,e){return t>=e?1:0})},e.prototype.logicalNot=function(t){Tl(t,"logicalNot");for(var e=this.readSync(t.dataId),n=new Uint8Array(e.length),r=0;r<e.length;++r)n[r]=e[r]?0:1;return this.makeOutput(n,t.shape,"bool")},e.prototype.logicalAnd=function(t,e){return Tl([t,e],"logicalAnd"),this.broadcastedBinaryOp(t,e,"bool",function(t,e){return t&&e})},e.prototype.logicalOr=function(t,e){return Tl([t,e],"logicalOr"),this.broadcastedBinaryOp(t,e,"bool",function(t,e){return t||e})},e.prototype.select=function(t,e,n){Tl([t,e,n],"select");for(var r=this.readSync(t.dataId),i=this.readSync(e.dataId),a=this.readSync(n.dataId),o=$n(e.shape,Mt(e.dtype,n.dtype)),s=this.readSync(o.dataId),u=0,c=0===t.rank||t.rank>1||1===e.rank?1:I(e.shape.slice(1)),l=0;l<r.length;l++)for(var f=0;f<c;f++)1===r[l]?s[u++]=i[l]:s[u++]=a[l];return o},e.prototype.where=function(t){Tl([t],"where");var e=this.readSync(t.dataId);return aa(t.shape,e)},e.prototype.topk=function(t,e,n){return Tl(t,"topk"),ia(this.readSync(t.dataId),t.shape,t.dtype,e)},e.prototype.min=function(t,e){Tl(t,"min"),Sn("min",e,t.rank);for(var n=En(t.shape,e),r=n[0],i=n[1],a=$n(r,t.dtype),o=I(i),s=this.readSync(a.dataId),u=this.readSync(t.dataId),c=0;c<s.length;++c){for(var l=c*o,f=u[l],d=0;d<o;++d){var h=u[l+d];h<f&&(f=h)}s[c]=f}return a},e.prototype.minimum=function(t,e){return Tl([t,e],"minimum"),this.broadcastedBinaryOp(t,e,t.dtype,function(t,e){return Math.min(t,e)})},e.prototype.mod=function(t,e){return Tl([t,e],"mod"),this.broadcastedBinaryOp(t,e,t.dtype,function(t,e){var n=t%e;return t<0&&e<0||t>=0&&e>=0?n:(n+e)%e})},e.prototype.max=function(t,e){Tl(t,"max"),Sn("max",e,t.rank);for(var n=En(t.shape,e),r=n[0],i=n[1],a=$n(r,t.dtype),o=I(i),s=this.readSync(a.dataId),u=this.readSync(t.dataId),c=0;c<s.length;++c){for(var l=c*o,f=u[l],d=0;d<o;++d){var h=u[l+d];h>f&&(f=h)}s[c]=f}return a},e.prototype.maximum=function(t,e){return Tl([t,e],"maximum"),this.broadcastedBinaryOp(t,e,t.dtype,function(t,e){return Math.max(t,e)})},e.prototype.all=function(t,e){Tl(t,"all"),Sn("all",e,t.rank);for(var n=En(t.shape,e),r=n[0],i=n[1],a=$n(r,t.dtype),o=I(i),s=this.readSync(a.dataId),u=this.readSync(t.dataId),c=0;c<s.length;++c){for(var l=c*o,f=u[l],d=0;d<o;++d){var h=u[l+d];f=f&&h}s[c]=f}return a},e.prototype.any=function(t,e){Tl(t,"any"),Sn("any",e,t.rank);for(var n=En(t.shape,e),r=n[0],i=n[1],a=$n(r,t.dtype),o=I(i),s=this.readSync(a.dataId),u=this.readSync(t.dataId),c=0;c<s.length;++c){for(var l=c*o,f=u[l],d=0;d<o;++d){var h=u[l+d];f=f||h}s[c]=f}return a},e.prototype.squaredDifference=function(t,e){return Tl([t,e],"squaredDifference"),this.broadcastedBinaryOp(t,e,t.dtype,function(t,e){var n=t-e;return n*n})},e.prototype.ceil=function(t){Tl(t,"ceil");for(var e=this.readSync(t.dataId),n=new Float32Array(e.length),r=0;r<e.length;++r)n[r]=Math.ceil(e[r]);return this.makeOutput(n,t.shape,"float32")},e.prototype.floor=function(t){Tl(t,"floor");for(var e=this.readSync(t.dataId),n=new Float32Array(e.length),r=0;r<e.length;++r)n[r]=Math.floor(e[r]);return this.makeOutput(n,t.shape,"float32")},e.prototype.sign=function(t){Tl(t,"x");for(var e=this.readSync(t.dataId),n=new Float32Array(e.length),r=0;r<e.length;++r)e[r]<0?n[r]=-1:e[r]>0?n[r]=1:n[r]=0;return this.makeOutput(n,t.shape,"float32")},e.prototype.isNaN=function(t){Tl(t,"x");for(var e=this.readSync(t.dataId),n=new Uint8Array(e.length),r=0;r<e.length;++r)Number.isNaN(e[r])&&(n[r]=1);return this.makeOutput(n,t.shape,"bool")},e.prototype.isInf=function(t){Tl(t,"x");for(var e=this.readSync(t.dataId),n=new Uint8Array(e.length),r=0;r<e.length;++r)Math.abs(e[r])===1/0&&(n[r]=1);return this.makeOutput(n,t.shape,"bool")},e.prototype.isFinite=function(t){Tl(t,"x");for(var e=this.readSync(t.dataId),n=new Uint8Array(e.length),r=0;r<e.length;++r)Number.isFinite(e[r])&&(n[r]=1);return this.makeOutput(n,t.shape,"bool")},e.prototype.round=function(t){Tl(t,"round");for(var e=this.readSync(t.dataId),n=new Float32Array(e.length),r=0;r<e.length;++r){var i=Math.floor(e[r]);e[r]-i<.5?n[r]=Math.floor(e[r]):e[r]-i>.5?n[r]=Math.ceil(e[r]):n[r]=i%2==0?i:i+1}return this.makeOutput(n,t.shape,"float32")},e.prototype.exp=function(t){Tl(t,"exp");for(var e=this.readSync(t.dataId),n=new Float32Array(e.length),r=0;r<e.length;++r)n[r]=Math.exp(e[r]);return this.makeOutput(n,t.shape,"float32")},e.prototype.expm1=function(t){Tl(t,"expm1");for(var e=this.readSync(t.dataId),n=new Float32Array(e.length),r=0;r<e.length;++r)n[r]=Math.expm1(e[r]);return this.makeOutput(n,t.shape,"float32")},e.prototype.log=function(t){Tl(t,"log");for(var e=this.readSync(t.dataId),n=new Float32Array(e.length),r=0;r<e.length;++r){var i=e[r];n[r]=Math.log(i)}return this.makeOutput(n,t.shape,"float32")},e.prototype.log1p=function(t){Tl(t,"log1p");for(var e=this.readSync(t.dataId),n=new Float32Array(e.length),r=0;r<e.length;++r){var i=e[r];n[r]=Math.log1p(i)}return this.makeOutput(n,t.shape,"float32")},e.prototype.sqrt=function(t){Tl(t,"sqrt");for(var e=this.readSync(t.dataId),n=new Float32Array(e.length),r=0;r<e.length;++r){var i=e[r];n[r]=Math.sqrt(i)}return this.makeOutput(n,t.shape,"float32")},e.prototype.rsqrt=function(t){Tl(t,"rsqrt");for(var e=this.readSync(t.dataId),n=new Float32Array(e.length),r=0;r<e.length;++r){var i=e[r];n[r]=1/Math.sqrt(i)}return this.makeOutput(n,t.shape,"float32")},e.prototype.reciprocal=function(t){Tl(t,"reciprocal");for(var e=this.readSync(t.dataId),n=new Float32Array(e.length),r=0;r<e.length;++r)n[r]=1/e[r];return this.makeOutput(n,t.shape,"float32")},e.prototype.linear=function(t){return t},e.prototype.relu=function(t){Tl(t,"relu");for(var e=$n(t.shape,t.dtype),n=this.readSync(e.dataId),r=this.readSync(t.dataId),i=0;i<r.length;++i)n[i]=Math.max(0,r[i]);return e},e.prototype.relu6=function(t){Tl(t,"relu");for(var e=$n(t.shape,t.dtype),n=this.readSync(e.dataId),r=this.readSync(t.dataId),i=0;i<r.length;++i)n[i]=Math.min(Math.max(0,r[i]),6);return e},e.prototype.prelu=function(t,e){return Tl([t,e],"prelu"),this.broadcastedBinaryOp(t,e,t.dtype,function(t,e){return t<0?e*t:t})},e.prototype.elu=function(t){Tl(t,"elu");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r){var i=n[r];e[r]=i>=0?i:Math.exp(i)-1}return this.makeOutput(e,t.shape,"float32")},e.prototype.eluDer=function(t,e){Tl([t,e],"eluDer");for(var n=new Float32Array(e.size),r=this.readSync(e.dataId),i=this.readSync(t.dataId),a=0;a<r.length;++a){var o=r[a];n[a]=o>=1?i[a]:i[a]*(o+1)}return this.makeOutput(n,e.shape,"float32")},e.prototype.selu=function(t){Tl(t,"selu");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r){var i=n[r];e[r]=i>=0?1.0507009873554805*i:1.7580993408473768*(Math.exp(i)-1)}return this.makeOutput(e,t.shape,"float32")},e.prototype.clip=function(t,e,n){Tl(t,"clip");for(var r=new Float32Array(t.size),i=this.readSync(t.dataId),a=0;a<i.length;++a){var o=i[a];r[a]=o>n?n:o<e?e:o}return this.makeOutput(r,t.shape,"float32")},e.prototype.abs=function(t){for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.abs(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.complexAbs=function(t){for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<t.size;++r){var i=n[2*r],a=n[2*r+1];e[r]=Math.hypot(i,a)}return this.makeOutput(e,t.shape,"float32")},e.prototype.int=function(t){Tl(t,"int");for(var e=new Int32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=n[r];return this.makeOutput(e,t.shape,"int32")},e.prototype.sigmoid=function(t){Tl(t,"sigmoid");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=1/(1+Math.exp(-n[r]));return this.makeOutput(e,t.shape,"float32")},e.prototype.softplus=function(t){Tl(t,"softplus");for(var e=Math.log(1.1920928955078125e-7)+2,n=new Float32Array(t.size),r=this.readSync(t.dataId),i=0;i<r.length;++i){var a,o=r[i]>-e,s=r[i]<e,u=Math.exp(r[i]);a=s?u:o?r[i]:Math.log(1+u),n[i]=a}return this.makeOutput(n,t.shape,"float32")},e.prototype.sin=function(t){Tl(t,"sin");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.sin(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.cos=function(t){Tl(t,"cos");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.cos(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.tan=function(t){Tl(t,"tan");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.tan(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.asin=function(t){Tl(t,"asin");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.asin(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.acos=function(t){Tl(t,"acos");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.acos(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.atan=function(t){Tl(t,"atan");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.atan(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.atan2=function(t,e){return Tl([t,e],"atan2"),this.broadcastedBinaryOp(t,e,t.dtype,function(t,e){return Math.atan2(t,e)})},e.prototype.sinh=function(t){Tl(t,"sinh");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.sinh(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.cosh=function(t){Tl(t,"cosh");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.cosh(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.tanh=function(t){Tl(t,"tanh");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=R(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.asinh=function(t){Tl(t,"asinh");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.asinh(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.acosh=function(t){Tl(t,"acosh");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.acosh(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.atanh=function(t){Tl(t,"atanh");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r)e[r]=Math.atanh(n[r]);return this.makeOutput(e,t.shape,"float32")},e.prototype.erf=function(t){Tl(t,"erf");for(var e=new Float32Array(t.size),n=this.readSync(t.dataId),r=0;r<n.length;++r){var i=Math.sign(n[r]),a=Math.abs(n[r]),o=1/(1+.3275911*a);e[r]=i*(1-((((1.061405429*o-1.453152027)*o+1.421413741)*o-.284496736)*o+.254829592)*o*Math.exp(-a*a))}return this.makeOutput(e,t.shape,"float32")},e.prototype.step=function(t,e){void 0===e&&(e=0),Tl(t,"step");for(var n=new Float32Array(t.size),r=this.readSync(t.dataId),i=0;i<r.length;++i){var a=r[i];isNaN(a)?n[i]=NaN:n[i]=a>0?1:e}return this.makeOutput(n,t.shape,"float32")},e.prototype.fusedConv2d=function(t){var e=t.input,n=t.filter,r=t.convInfo,i=t.bias,a=t.activation,o=t.preluActivationWeights,s=this.conv2d(e,n,r);return i&&(s=this.add(s,i)),a&&(s=Il(this,s,a,o)),s},e.prototype.conv2d=function(t,e,n){Tl([t,e],"conv2d");for(var r=n.filterHeight,i=n.filterWidth,a=n.dilationHeight,o=n.dilationWidth,s=n.padInfo.left,u=n.padInfo.top,c="channelsLast"===n.dataFormat,l=vr(n.outShape,t.dtype),f=t.strides[0],d=c?t.strides[1]:t.strides[2],h=c?t.strides[2]:1,p=c?1:t.strides[1],m=l.strides[0],g=c?l.strides[1]:l.strides[2],v=c?l.strides[2]:1,y=c?1:l.strides[1],b=this.readSync(t.dataId),x=this.readSync(e.dataId),w=l.values,k=0;k<n.batchSize;++k)for(var _=k*f,E=k*m,O=0;O<n.outHeight;++O)for(var S=E+O*g,C=O*n.strideHeight-u,A=0;A<r;A++){var N=C+A*a;if(!(N<0||N>=n.inHeight))for(var T=A*e.strides[0],I=_+N*d,D=0;D<n.outWidth;++D)for(var M=S+D*v,R=D*n.strideWidth-s,F=0;F<i;F++){var j=R+F*o;if(!(j<0||j>=n.inWidth))for(var P=I+j*h,L=T+F*e.strides[1],z=0;z<n.inChannels;++z){for(var B=b[P+z*p],U=0;U<n.outChannels;++U)w[M+U*y]+=B*x[L+U];L+=n.outChannels}}}return l.toTensor()},e.prototype.conv3d=function(t,e,n){for(var r=n.filterDepth,i=n.filterHeight,a=n.filterWidth,o=n.dilationDepth,s=n.dilationHeight,u=n.dilationWidth,c=n.padInfo.front,l=n.padInfo.left,f=n.padInfo.top,d=vr(n.outShape,t.dtype),h=this.readSync(t.dataId),p=this.readSync(e.dataId),m=d.values,g=0;g<n.batchSize;++g)for(var v=g*t.strides[0],y=g*d.strides[0],b=0;b<n.outDepth;++b)for(var x=y+b*d.strides[1],w=b*n.strideDepth-c,k=0;k<r;k++){var _=w+k*o;if(!(_<0||_>=n.inDepth))for(var E=k*e.strides[0],O=v+_*t.strides[1],S=0;S<n.outHeight;++S)for(var C=x+S*d.strides[2],A=S*n.strideHeight-f,N=0;N<i;N++){var T=A+N*s;if(!(T<0||T>=n.inHeight))for(var I=E+N*e.strides[1],D=O+T*t.strides[2],M=0;M<n.outWidth;++M)for(var R=C+M*n.outChannels,F=M*n.strideWidth-l,j=0;j<a;j++){var P=F+j*u;if(!(P<0||P>=n.inWidth))for(var L=I+j*e.strides[2],z=D+P*n.inChannels,B=L,U=0;U<n.inChannels;++U){for(var W=h[z+U],V=0;V<n.outChannels;++V)m[R+V]+=W*p[B+V];B+=n.outChannels}}}}return d.toTensor()},e.prototype.conv2dDerInput=function(t,e,n){Tl([t,e],"conv2dDerInput");for(var r=vr(n.inShape,"float32"),i=r.values,a=this.readSync(t.dataId),o=this.readSync(e.dataId),s=e.strides,u=s[0],c=s[1],l=s[2],f=n.batchSize,d=n.filterHeight,h=n.filterWidth,p=n.inChannels,m=n.inHeight,g=n.inWidth,v=n.outChannels,y=n.outHeight,b=n.outWidth,x=n.strideHeight,w=n.strideWidth,k=n.dataFormat,_=d-1-n.padInfo.top,E=h-1-n.padInfo.left,O="channelsLast"===k,S=r.strides[0],C=O?r.strides[1]:r.strides[2],A=O?r.strides[2]:1,N=O?1:r.strides[1],T=t.strides[0],I=O?t.strides[1]:t.strides[2],D=O?t.strides[2]:1,M=O?1:t.strides[1],R=0;R<f;++R)for(var F=0;F<p;++F)for(var j=0;j<m;++j)for(var P=j-_,L=Math.max(0,Math.ceil(P/x)),z=Math.min(y,(d+P)/x),B=0;B<g;++B){for(var U=B-E,W=Math.max(0,Math.ceil(U/w)),V=Math.min(b,(h+U)/w),q=0,H=L;H<z;++H)for(var G=H*x-P,$=W;$<V;++$)for(var K=T*R+I*H+D*$,X=u*(d-1-G)+c*(h-1-($*w-U))+l*F,Y=0;Y<v;++Y)q+=a[K+M*Y]*o[X+Y];i[S*R+C*j+A*B+N*F]=q}return r.toTensor()},e.prototype.conv3dDerInput=function(t,e,n){for(var r=vr(n.inShape,"float32"),i=r.values,a=r.strides,o=a[0],s=a[1],u=a[2],c=a[3],l=this.readSync(t.dataId),f=t.strides,d=f[0],h=f[1],p=f[2],m=f[3],g=this.readSync(e.dataId),v=e.strides,y=v[0],b=v[1],x=v[2],w=v[3],k=n.batchSize,_=n.filterDepth,E=n.filterHeight,O=n.filterWidth,S=n.inChannels,C=n.inDepth,A=n.inHeight,N=n.inWidth,T=n.outChannels,I=n.outDepth,D=n.outHeight,M=n.outWidth,R=n.strideDepth,F=n.strideHeight,j=n.strideWidth,P=_-1-n.padInfo.front,L=E-1-n.padInfo.top,z=O-1-n.padInfo.left,B=0;B<k;++B)for(var U=0;U<S;++U)for(var W=0;W<C;++W)for(var V=W-P,q=Math.max(0,Math.ceil(V/R)),H=Math.min(I,(_+V)/R),G=0;G<A;++G)for(var $=G-L,K=Math.max(0,Math.ceil($/F)),X=Math.min(D,(E+$)/F),Y=0;Y<N;++Y){for(var J=Y-z,Z=Math.max(0,Math.ceil(J/j)),Q=Math.min(M,(O+J)/j),tt=0,et=q;et<H;++et)for(var nt=et*R-V,rt=K;rt<X;++rt)for(var it=rt*F-$,at=Z;at<Q;++at)for(var ot=d*B+h*et+p*rt+m*at,st=y*(_-1-nt)+b*(E-1-it)+x*(O-1-(at*j-J))+w*U,ut=0;ut<T;++ut)tt+=l[ot+ut]*g[st+ut];i[o*B+s*W+u*G+c*Y+U]=tt}return r.toTensor()},e.prototype.conv2dDerFilter=function(t,e,n){Tl([t,e],"conv2dDerFilter");for(var r=n.strideHeight,i=n.strideWidth,a=n.filterHeight,o=n.filterWidth,s="channelsLast"===n.dataFormat,u=vr(n.filterShape,"float32"),c=n.padInfo.left,l=n.padInfo.top,f=this.bufferSync(t),d=this.bufferSync(e),h=0;h<a;++h)for(var p=Math.max(0,Math.ceil((l-h)/r)),m=Math.min(n.outHeight,(n.inHeight+l-h)/r),g=0;g<o;++g)for(var v=Math.max(0,Math.ceil((c-g)/i)),y=Math.min(n.outWidth,(n.inWidth+c-g)/i),b=0;b<n.inChannels;++b)for(var x=0;x<n.outChannels;++x){for(var w=0,k=0;k<n.batchSize;++k)for(var _=p;_<m;++_)for(var E=h+_*r-l,O=v;O<y;++O){var S=g+O*i-c;w+=s?f.get(k,E,S,b)*d.get(k,_,O,x):f.get(k,b,E,S)*d.get(k,x,_,O)}u.set(w,h,g,b,x)}return u.toTensor()},e.prototype.conv3dDerFilter=function(t,e,n){for(var r=n.strideDepth,i=n.strideHeight,a=n.strideWidth,o=n.filterDepth,s=n.filterHeight,u=n.filterWidth,c=vr(n.filterShape,"float32"),l=c.values,f=c.strides,d=f[0],h=f[1],p=f[2],m=f[3],g=this.readSync(e.dataId),v=e.strides,y=v[0],b=v[1],x=v[2],w=v[3],k=this.readSync(t.dataId),_=t.strides,E=_[0],O=_[1],S=_[2],C=_[3],A=n.padInfo.front,N=n.padInfo.left,T=n.padInfo.top,I=0;I<o;++I)for(var D=Math.max(0,Math.ceil((A-I)/r)),M=Math.min(n.outDepth,(n.inDepth+A-I)/r),R=I*d,F=0;F<s;++F)for(var j=Math.max(0,Math.ceil((T-F)/i)),P=Math.min(n.outHeight,(n.inHeight+T-F)/i),L=F*h+R,z=0;z<u;++z)for(var B=Math.max(0,Math.ceil((N-z)/a)),U=Math.min(n.outWidth,(n.inWidth+N-z)/a),W=z*p+L,V=0;V<n.inChannels;++V)for(var q=V*m+W,H=0;H<n.outChannels;++H){for(var G=0,$=0;$<n.batchSize;++$)for(var K=$*E,X=$*y,Y=D;Y<M;++Y)for(var J=(I+Y*r-A)*O+K,Z=Y*b+X,Q=j;Q<P;++Q)for(var tt=(F+Q*i-T)*S+J,et=Q*x+Z,nt=B;nt<U;++nt){var rt=nt*w+et;G+=k[(z+nt*a-N)*C+tt+V]*g[rt+H]}l[q+H]=G}return c.toTensor()},e.prototype.fusedDepthwiseConv2D=function(t){var e=t.input,n=t.filter,r=t.convInfo,i=t.bias,a=t.activation,o=t.preluActivationWeights,s=this.depthwiseConv2D(e,n,r);return i&&(s=this.add(s,i)),a&&(s=Il(this,s,a,o)),s},e.prototype.depthwiseConv2D=function(t,e,n){Tl([t,e],"depthwiseConv2D");for(var r=n.filterHeight,i=n.filterWidth,a=n.dilationHeight,o=n.dilationWidth,s=n.padInfo.left,u=n.padInfo.top,c=n.outChannels/n.inChannels,l=vr(n.outShape,t.dtype),f=this.readSync(t.dataId),d=this.readSync(e.dataId),h=l.values,p=0;p<n.batchSize;++p)for(var m=p*t.strides[0],g=p*l.strides[0],v=0;v<n.outHeight;++v)for(var y=g+v*l.strides[1],b=v*n.strideHeight-s,x=0;x<r;++x){var w=b+x*a;if(!(w<0||w>=n.inHeight))for(var k=x*e.strides[0],_=m+w*t.strides[1],E=0;E<n.outWidth;++E)for(var O=y+E*l.strides[2],S=E*n.strideWidth-u,C=0;C<i;++C){var A=S+C*o;if(!(A<0||A>=n.inWidth))for(var N=k+C*e.strides[1],T=_+A*n.inChannels,I=O,D=N,M=0;M<n.inChannels;++M){for(var R=f[T+M],F=0;F<c;++F)h[I+F]+=R*d[D+F];I+=c,D+=c}}}return l.toTensor()},e.prototype.depthwiseConv2DDerInput=function(t,e,n){Tl([t,e],"depthwiseConv2DDerInput");for(var r=vr(n.inShape,"float32"),i=r.values,a=r.strides,o=a[0],s=a[1],u=a[2],c=this.readSync(t.dataId),l=t.strides,f=l[0],d=l[1],h=l[2],p=this.readSync(e.dataId),m=e.strides,g=m[0],v=m[1],y=m[2],b=n.batchSize,x=n.filterHeight,w=n.filterWidth,k=n.inChannels,_=n.inHeight,E=n.inWidth,O=n.outChannels,S=n.outHeight,C=n.outWidth,A=n.strideHeight,N=n.strideWidth,T=x-1-n.padInfo.top,I=w-1-n.padInfo.left,D=O/k,M=0;M<b;++M)for(var R=0;R<k;++R)for(var F=0;F<_;++F)for(var j=F-T,P=Math.max(0,Math.ceil(j/A)),L=Math.min(S,(x+j)/A),z=0;z<E;++z){for(var B=z-I,U=Math.max(0,Math.ceil(B/N)),W=Math.min(C,(w+B)/N),V=0,q=P;q<L;++q)for(var H=q*A-j,G=U;G<W;++G)for(var $=f*M+d*q+h*G,K=g*(x-1-H)+v*(w-1-(G*N-B))+y*R,X=0;X<D;++X)V+=c[$+(R*D+X)]*p[K+X];i[o*M+s*F+u*z+R]=V}return r.toTensor()},e.prototype.depthwiseConv2DDerFilter=function(t,e,n){Tl([t,e],"depthwiseConv2DDerFilter");for(var r=n.strideHeight,i=n.strideWidth,a=n.filterHeight,o=n.filterWidth,s=vr(n.filterShape,"float32"),u=n.padInfo.left,c=n.padInfo.top,l=n.outChannels/n.inChannels,f=this.bufferSync(t),d=this.bufferSync(e),h=0;h<a;++h)for(var p=Math.max(0,Math.ceil((c-h)/r)),m=Math.min(n.outHeight,(n.inHeight+c-h)/r),g=0;g<o;++g)for(var v=Math.max(0,Math.ceil((u-g)/i)),y=Math.min(n.outWidth,(n.inWidth+u-g)/i),b=0;b<n.outChannels;++b){for(var x=Math.trunc(b/l),w=b%l,k=0,_=0;_<n.batchSize;++_)for(var E=p;E<m;++E)for(var O=h+E*r-c,S=v;S<y;++S){var C=g+S*i-u;k+=f.get(_,O,C,x)*d.get(_,E,S,b)}s.set(k,h,g,x,w)}return s.toTensor()},e.prototype.tile=function(t,e){return Tl(t,"tile"),ra(this.bufferSync(t),e)},e.prototype.pad=function(t,e,n){Tl(t,"pad");var r=e.map(function(e,n){return e[0]+t.shape[n]+e[1]}),i=e.map(function(t){return t[0]}),a=this.bufferSync(t),o=vr(r,t.dtype);0!==n&&o.values.fill(n);for(var s=0;s<t.size;s++){var u=a.indexToLoc(s),c=u.map(function(t,e){return t+i[e]});o.set.apply(o,[a.get.apply(a,u)].concat(c))}return o.toTensor()},e.prototype.transpose=function(t,e){Tl(t,"transpose");for(var n=new Array(t.rank),r=0;r<n.length;r++)n[r]=t.shape[e[r]];var i=this.readSync(t.dataId),a=vr(n,t.dtype),o=this.bufferSync(t);for(r=0;r<t.size;++r){for(var s=o.indexToLoc(r),u=new Array(s.length),c=0;c<u.length;c++)u[c]=s[e[c]];var l=a.locToIndex(u);a.values[l]=i[r]}return a.toTensor()},e.prototype.gather=function(t,e,n){Tl([t,e],"gather");var r=t.shape.slice(),i=this.readSync(e.dataId);r[n]=i.length;for(var a=vr(r,t.dtype),o=this.bufferSync(t),s=0;s<a.size;++s){var u=a.indexToLoc(s),c=u.slice();c[n]=i[u[n]];var l=o.locToIndex(c);a.values[s]=o.values[l]}return a.toTensor()},e.prototype.batchToSpaceND=function(t,e,n){Tl([t],"batchToSpaceND");var r=e.reduce(function(t,e){return t*e}),i=Gr(t.shape,e,r),a=$r(i.length,e.length),o=Kr(t.shape,e,r),s=Xr(n,e.length),u=Yr(o,n,e.length);return t.reshape(i).transpose(a).reshape(o).slice(s,u)},e.prototype.spaceToBatchND=function(t,e,n){Tl([t],"spaceToBatchND");var r=e.reduce(function(t,e){return t*e}),i=[[0,0]];i.push.apply(i,n);for(var a=1+e.length;a<t.shape.length;++a)i.push([0,0]);var o=t.pad(i),s=Gr(o.shape,e,r,!1),u=$r(s.length,e.length,!1),c=Kr(o.shape,e,r,!1);return o.reshape(s).transpose(u).reshape(c)},e.prototype.pool=function(t,e,n){Tl(t,"pool");for(var r=e.strideHeight,i=e.strideWidth,a=e.dilationHeight,o=e.dilationWidth,s=e.effectiveFilterHeight,u=e.effectiveFilterWidth,c=e.padInfo.top,l=e.padInfo.left,f="max"===n?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,d=this.readSync(t.dataId),h=vr(e.outShape,t.dtype),p=h.values,m=e.outShape[1]*e.outShape[2]*e.outShape[3],g=e.outShape[2]*e.outShape[3],v=e.outShape[3],y=0;y<e.batchSize;++y)for(var b=y*m,x=y*t.strides[0],w=0;w<e.inChannels;++w)for(var k=0;k<e.outHeight;++k)for(var _=k*r-c,E=Math.max(0,_),O=Math.min(e.inHeight,s+_),S=b+k*g,C=0;C<e.outWidth;++C){for(var A=C*i-l,N=Math.max(0,A),T=Math.min(e.inWidth,u+A),I=f,D=0,M=0,R=E;R<O;R+=a){for(var F=x+R*t.strides[1],j=N;j<T;j+=o){var P=d[F+j*t.strides[2]+w];"max"===n&&P>I?I=P:"avg"===n&&(D+=P,M++)}if(isNaN(I))break}p[S+C*v+w]="avg"===n?D/M:I}return h.toTensor()},e.prototype.maxPool=function(t,e){return this.pool(t,e,"max")},e.prototype.maxPoolPositions=function(t,e){for(var n=vr(e.outShape,"int32"),r=e.strideHeight,i=e.strideWidth,a=e.dilationHeight,o=e.dilationWidth,s=e.effectiveFilterHeight,u=e.effectiveFilterWidth,c=e.padInfo.top,l=e.padInfo.left,f=this.bufferSync(t),d=0;d<e.batchSize;++d)for(var h=0;h<e.inChannels;++h)for(var p=0;p<e.outHeight;++p){for(var m=p*r-c,g=m;g<0;)g+=a;for(var v=Math.min(e.inHeight,s+m),y=0;y<e.outWidth;++y){for(var b=y*i-l,x=b;x<0;)x+=o;for(var w=Math.min(e.inWidth,u+b),k=Number.NEGATIVE_INFINITY,_=-1,E=g;E<v;E+=a)for(var O=E-m,S=x;S<w;S+=o){var C=S-b,A=f.get(d,E,S,h);A>k&&(k=A,_=O*u+C)}n.set(_,d,p,y,h)}}return n.toTensor()},e.prototype.maxPoolBackprop=function(t,e,n,r){Tl([e,n],"maxPoolBackprop");for(var i=this.maxPoolPositions(e,r),a=r.strideHeight,o=r.strideWidth,s=r.dilationHeight,u=r.dilationWidth,c=r.effectiveFilterHeight,l=r.effectiveFilterWidth,f=l-1-r.padInfo.left,d=c-1-r.padInfo.top,h=vr(e.shape,"float32"),p=this.bufferSync(i),m=this.bufferSync(t),g=0;g<r.batchSize;++g)for(var v=0;v<r.inChannels;++v)for(var y=0;y<r.inHeight;++y)for(var b=0;b<r.inWidth;++b){for(var x=y-d,w=b-f,k=0,_=0;_<c;_+=s){var E=(x+_)/a;if(!(E<0||E>=r.outHeight||Math.floor(E)!==E))for(var O=0;O<l;O+=u){var S=(w+O)/o;if(!(S<0||S>=r.outWidth||Math.floor(S)!==S)){var C=c*l-1-p.get(g,E,S,v)===_*l+O?1:0;0!==C&&(k+=m.get(g,E,S,v)*C)}}}h.set(k,g,y,b,v)}return h.toTensor()},e.prototype.avgPoolBackprop=function(t,e,n){Tl([t,e],"avgPoolBackprop");for(var r=n.strideHeight,i=n.strideWidth,a=n.filterHeight,o=n.filterWidth,s=n.dilationHeight,u=n.dilationWidth,c=n.effectiveFilterHeight,l=n.effectiveFilterWidth,f=l-1-n.padInfo.left,d=c-1-n.padInfo.top,h=vr(e.shape,"float32"),p=1/(a*o),m=this.bufferSync(t),g=0;g<n.batchSize;++g)for(var v=0;v<n.inChannels;++v)for(var y=0;y<n.inHeight;++y)for(var b=0;b<n.inWidth;++b){for(var x=y-d,w=b-f,k=0,_=0;_<c;_+=s){var E=(x+_)/r;if(!(E<0||E>=n.outHeight||Math.floor(E)!==E))for(var O=0;O<l;O+=u){var S=(w+O)/i;S<0||S>=n.outWidth||Math.floor(S)!==S||(k+=m.get(g,E,S,v))}}h.set(k*p,g,y,b,v)}return h.toTensor()},e.prototype.pool3d=function(t,e,n){Tl(t,"pool3d");for(var r=e.strideDepth,i=e.strideHeight,a=e.strideWidth,o=e.dilationDepth,s=e.dilationHeight,u=e.dilationWidth,c=e.effectiveFilterDepth,l=e.effectiveFilterHeight,f=e.effectiveFilterWidth,d=e.padInfo.front,h=e.padInfo.top,p=e.padInfo.left,m="max"===n?Number.NEGATIVE_INFINITY:Number.POSITIVE_INFINITY,g=this.readSync(t.dataId),v=vr(e.outShape,t.dtype),y=v.values,b=e.outShape[1]*e.outShape[2]*e.outShape[3]*e.outShape[4],x=e.outShape[2]*e.outShape[3]*e.outShape[4],w=e.outShape[3]*e.outShape[4],k=e.outShape[4],_=0;_<e.batchSize;++_)for(var E=_*b,O=_*t.strides[0],S=0;S<e.inChannels;++S)for(var C=0;C<e.outDepth;++C){for(var A=C*r-d,N=A;N<0;)N+=o;for(var T=Math.min(e.inDepth,c+A),I=E+C*x,D=0;D<e.outHeight;++D){for(var M=D*i-h,R=M;R<0;)R+=s;for(var F=Math.min(e.inHeight,l+M),j=I+D*w,P=0;P<e.outWidth;++P){for(var L=P*a-p,z=L;z<0;)z+=u;for(var B=Math.min(e.inWidth,f+L),U=j+P*k,W=m,V=0,q=0,H=N;H<T;H+=o){for(var G=O+H*t.strides[1],$=R;$<F;$+=s){for(var K=G+$*t.strides[2],X=z;X<B;X+=u){var Y=g[K+X*t.strides[3]+S];if("max"===n&&Y>W?W=Y:"avg"===n&&(V+=Y,q++),isNaN(W))break}if(isNaN(W))break}if(isNaN(W))break}y[U+S]="avg"===n?V/q:W}}}return v.toTensor()},e.prototype.avgPool3d=function(t,e){return Tl(t,"avgPool3d"),this.pool3d(t,e,"avg").toFloat()},e.prototype.avgPool3dBackprop=function(t,e,n){Tl([t,e],"avgPool3dBackprop");for(var r=n.strideDepth,i=n.strideHeight,a=n.strideWidth,o=n.filterDepth,s=n.filterHeight,u=n.filterWidth,c=n.dilationDepth,l=n.dilationHeight,f=n.dilationWidth,d=n.effectiveFilterDepth,h=n.effectiveFilterHeight,p=n.effectiveFilterWidth,m=d-1-n.padInfo.front,g=p-1-n.padInfo.left,v=h-1-n.padInfo.top,y=vr(e.shape,"float32"),b=1/(o*s*u),x=this.bufferSync(t),w=0;w<n.batchSize;++w)for(var k=0;k<n.inChannels;++k)for(var _=0;_<n.inDepth;++_)for(var E=0;E<n.inHeight;++E)for(var O=0;O<n.inWidth;++O){for(var S=_-m,C=E-v,A=O-g,N=0,T=0;T<d;T+=c){var I=(S+T)/r;if(!(I<0||I>=n.outDepth||Math.floor(I)!==I))for(var D=0;D<h;D+=l){var M=(C+D)/i;if(!(M<0||M>=n.outHeight||Math.floor(M)!==M))for(var R=0;R<p;R+=f){var F=(A+R)/a;F<0||F>=n.outWidth||Math.floor(F)!==F||(N+=x.get(w,I,M,F,k))}}}y.set(N*b,w,_,E,O,k)}return y.toTensor()},e.prototype.maxPool3d=function(t,e){return Tl(t,"maxPool3d"),this.pool3d(t,e,"max").toFloat()},e.prototype.maxPool3dPositions=function(t,e){for(var n=vr(e.outShape,"int32"),r=e.strideDepth,i=e.strideHeight,a=e.strideWidth,o=e.dilationDepth,s=e.dilationHeight,u=e.dilationWidth,c=e.effectiveFilterDepth,l=e.effectiveFilterHeight,f=e.effectiveFilterWidth,d=e.padInfo.front,h=e.padInfo.top,p=e.padInfo.left,m=this.bufferSync(t),g=0;g<e.batchSize;++g)for(var v=0;v<e.inChannels;++v)for(var y=0;y<e.outDepth;++y){for(var b=y*r-d,x=b;x<0;)x+=o;for(var w=Math.min(e.inDepth,c+b),k=0;k<e.outHeight;++k){for(var _=k*i-h,E=_;E<0;)E+=s;for(var O=Math.min(e.inHeight,l+_),S=0;S<e.outWidth;++S){for(var C=S*a-p,A=C;A<0;)A+=u;for(var N=Math.min(e.inWidth,f+C),T=Number.NEGATIVE_INFINITY,I=-1,D=x;D<w;D+=o)for(var M=D-b,R=E;R<O;R+=s)for(var F=R-_,j=A;j<N;j+=u){var P=j-C,L=m.get(g,D,R,j,v);L>=T&&(T=L,I=M*l*f+F*l+P)}n.set(I,g,y,k,S,v)}}}return n.toTensor()},e.prototype.maxPool3dBackprop=function(t,e,n,r){Tl([e,n],"maxPool3dBackprop");for(var i=this.maxPool3dPositions(e,r),a=r.strideDepth,o=r.strideHeight,s=r.strideWidth,u=r.dilationDepth,c=r.dilationHeight,l=r.dilationWidth,f=r.effectiveFilterDepth,d=r.effectiveFilterHeight,h=r.effectiveFilterWidth,p=f-1-r.padInfo.front,m=h-1-r.padInfo.left,g=d-1-r.padInfo.top,v=vr(e.shape,"float32"),y=this.bufferSync(i),b=this.bufferSync(t),x=0;x<r.batchSize;++x)for(var w=0;w<r.inChannels;++w)for(var k=0;k<r.inDepth;++k)for(var _=0;_<r.inHeight;++_)for(var E=0;E<r.inWidth;++E){for(var O=k-p,S=_-g,C=E-m,A=0,N=0;N<f;N+=u){var T=(O+N)/a;if(!(T<0||T>=r.outDepth||Math.floor(T)!==T))for(var I=0;I<d;I+=c){var D=(S+I)/o;if(!(D<0||D>=r.outHeight||Math.floor(D)!==D))for(var M=0;M<h;M+=l){var R=(C+M)/s;if(!(R<0||R>=r.outWidth||Math.floor(R)!==R)){var F=f*d*h-1-y.get(x,T,D,R,w)===N*d*h+I*h+M?1:0;0!==F&&(A+=b.get(x,T,D,R,w)*F)}}}}v.set(A,x,k,_,E,w)}return v.toTensor()},e.prototype.cast=function(t,e){return Bi(t,e,this)},e.prototype.reshape=function(t,e){return Ui(t,e)},e.prototype.avgPool=function(t,e){return Tl(t,"avgPool"),this.pool(t,e,"avg").toFloat()},e.prototype.resizeBilinear=function(t,e,n,r){Tl(t,"resizeBilinear");for(var i=t.shape,a=i[0],o=i[1],s=i[2],u=i[3],c=this.readSync(t.dataId),l=new Float32Array(I([a,e,n,u])),f=[r&&e>1?o-1:o,r&&n>1?s-1:s],d=[r&&e>1?e-1:e,r&&n>1?n-1:n],h=0,p=f[0]/d[0],m=f[1]/d[1],g=0;g<a;g++)for(var v=0;v<e;v++)for(var y=p*v,b=Math.floor(y),x=y-b,w=Math.min(o-1,Math.ceil(y)),k=g*t.strides[0]+b*t.strides[1],_=g*t.strides[0]+w*t.strides[1],E=0;E<n;E++)for(var O=m*E,S=Math.floor(O),C=O-S,A=Math.min(s-1,Math.ceil(O)),N=k+S*t.strides[2],T=_+S*t.strides[2],D=k+A*t.strides[2],M=_+A*t.strides[2],R=0;R<u;R++){var F=c[N+R],j=c[T+R],P=F+(c[D+R]-F)*C,L=P+(j+(c[M+R]-j)*C-P)*x;l[h++]=L}return jn(l,[a,e,n,u])},e.prototype.resizeBilinearBackprop=function(t,e,n){Tl([t,e],"resizeBilinearBackprop");for(var r=e.shape,i=r[0],a=r[1],o=r[2],s=r[3],u=t.shape,c=u[1],l=u[2],f=new Float32Array(i*a*o*s),d=[n&&c>1?a-1:a,n&&l>1?o-1:o],h=[n&&c>1?c-1:c,n&&l>1?l-1:l],p=d[0]/h[0],m=d[1]/h[1],g=this.readSync(t.dataId),v=0,y=0;y<i;y++)for(var b=y*e.strides[0],x=0;x<c;x++)for(var w=x*p,k=Math.floor(w),_=Math.min(Math.ceil(w),a-1),E=b+k*e.strides[1],O=b+_*e.strides[1],S=w-k,C=1-S,A=0;A<l;A++)for(var N=A*m,T=Math.floor(N),I=Math.min(Math.ceil(N),o-1),D=N-T,M=1-D,R=E+T*e.strides[2],F=E+I*e.strides[2],j=O+T*e.strides[2],P=O+I*e.strides[2],L=C*M,z=C*D,B=S*M,U=S*D,W=0;W<s;W++){var V=g[v++];f[R+W]+=V*L,f[F+W]+=V*z,f[j+W]+=V*B,f[P+W]+=V*U}return Wn(f,[i,o,a,s],e.dtype)},e.prototype.resizeNearestNeighbor=function(t,e,n,r){Tl(t,"resizeNearestNeighbor");for(var i=t.shape,a=i[0],o=i[1],s=i[2],u=i[3],c=this.readSync(t.dataId),l=new Float32Array(a*e*n*u),f=[r&&e>1?o-1:o,r&&n>1?s-1:s],d=[r&&e>1?e-1:e,r&&n>1?n-1:n],h=f[0]/d[0],p=f[1]/d[1],m=0,g=0;g<a;g++)for(var v=g*t.strides[0],y=0;y<e;y++)for(var b=h*y,x=v+Math.min(o-1,r?Math.round(b):Math.floor(b))*t.strides[1],w=0;w<n;w++)for(var k=p*w,_=x+Math.min(s-1,r?Math.round(k):Math.floor(k))*t.strides[2],E=0;E<u;E++){var O=c[_+E];l[m++]=O}return jn(l,[a,e,n,u],t.dtype)},e.prototype.resizeNearestNeighborBackprop=function(t,e,n){Tl([t,e],"resizeNearestNeighborBackprop");for(var r=e.shape,i=r[0],a=r[1],o=r[2],s=r[3],u=t.shape,c=u[1],l=u[2],f=new Float32Array(i*a*o*s),d=this.readSync(t.dataId),h=[n&&c>1?a-1:a,n&&l>1?o-1:o],p=[n&&c>1?c-1:c,n&&l>1?l-1:l],m=h[0]/p[0],g=h[1]/p[1],v=1/m,y=1/g,b=2*Math.ceil(v)+2,x=2*Math.ceil(y)+2,w=0;w<i;w++)for(var k=w*e.strides[0],_=0;_<a;_++)for(var E=k+_*e.strides[1],O=Math.floor(_*v),S=Math.floor(O-b/2),C=0;C<o;C++)for(var A=E+C*e.strides[2],N=Math.floor(C*y),T=Math.floor(N-x/2),I=0;I<s;I++){for(var D=0,M=0;M<b;M++){var R=M+S;if(!(R<0||R>=c)){var F=k+R*t.strides[1],j=R*m;if(_===Math.min(a-1,n?Math.round(j):Math.floor(j)))for(var P=0;P<x;P++){var L=P+T;if(!(L<0||L>=l)){var z=F+L*t.strides[2],B=L*g;C===Math.min(o-1,n?Math.round(B):Math.floor(B))&&(D+=d[z+I])}}}}f[A+I]=D}return Wn(f,e.shape,e.dtype)},e.prototype.batchNormalization=function(t,e,n,r,i,a){Tl([t,e,n,i,a],"batchNorm");for(var o=this.readSync(t.dataId),s=this.readSync(e.dataId),u=this.readSync(n.dataId),c=i?this.readSync(i.dataId):new Float32Array([1]),l=a?this.readSync(a.dataId):new Float32Array([0]),f=new Float32Array(o.length),d=l.length,h=c.length,p=u.length,m=s.length,g=0,v=0,y=0,b=0,x=0;x<o.length;++x)f[x]=l[g++]+(o[x]-s[v++])*c[y++]/Math.sqrt(u[b++]+r),g>=d&&(g=0),v>=m&&(v=0),y>=h&&(y=0),b>=p&&(b=0);return Wn(f,t.shape)},e.prototype.localResponseNormalization4D=function(t,e,n,r,i){Tl(t,"localResponseNormalization4D");var a=t.shape[3],o=a-1,s=this.readSync(t.dataId),u=t.size,c=new Float32Array(u);function l(t){for(var n=t%a,r=t-n+Math.max(0,n-e),i=t-n+Math.min(n+e,o),u=0;r<=i;r++){var c=s[r];u+=c*c}return u}for(var f=0;f<u;f++){var d=l(f),h=s[f]*Math.pow(n+r*d,-i);c[f]=h}return Wn(c,t.shape)},e.prototype.LRNGrad=function(t,e,n,r,i,a,o){Tl(t,"LRNGrad");for(var s=t.shape[3],u=this.readSync(t.dataId),c=this.readSync(e.dataId),l=this.readSync(n.dataId),f=new Float32Array(t.size),d=t.size,h=0;h<d;h++){for(var p=h%s,m=h-p+Math.max(0,p-r),g=h-p+Math.min(s,p+r+1),v=0,y=m;y<g;y++)v+=Math.pow(c[y],2);for(v=a*v+i,y=m;y<g;y++){var b=-2*a*o*c[y]*l[h]/v;h===y&&(b+=Math.pow(v,-o)),b*=u[h],f[y]+=b}}return Wn(f,t.shape)},e.prototype.multinomial=function(t,e,n,r){Tl(t,"multinomial");for(var i=e?t:xi(t),a=i.shape[0],o=i.shape[1],s=$n([a,n],"int32"),u=this.readSync(s.dataId),c=this.readSync(i.dataId),l=0;l<a;++l){var f=l*o,d=new Float32Array(o-1);d[0]=c[f];for(var h=1;h<d.length;++h)d[h]=d[h-1]+c[f+h];for(var p=hr(r.toString()),m=l*n,g=0;g<n;++g){var v=p();u[m+g]=d.length;for(var y=0;y<d.length;y++)if(v<d[y]){u[m+g]=y;break}}}return s},e.prototype.oneHot=function(t,e,n,r){Tl(t,"oneHot");var i=new Float32Array(t.size*e);i.fill(r);for(var a=this.readSync(t.dataId),o=0;o<t.size;++o)a[o]>=0&&a[o]<e&&(i[o*e+a[o]]=n);return Bn(i,[t.size,e],"int32")},e.prototype.nonMaxSuppression=function(t,e,n,r,i){return Tl(t,"nonMaxSuppression"),Yi(this.readSync(t.dataId),this.readSync(e.dataId),n,r,i)},e.prototype.fft=function(t){return this.fftBatch(t,!1)},e.prototype.ifft=function(t){return this.fftBatch(t,!0)},e.prototype.fftBatch=function(t,e){for(var n=t.shape[0],r=t.shape[1],i=vr(t.shape,"float32"),a=vr(t.shape,"float32"),o=Rn(t).as2D(n,r),s=Fn(t).as2D(n,r),u=0;u<n;u++)for(var c=o.slice([u,0],[1,r]),l=s.slice([u,0],[1,r]),f=Mn(c,l),d=this.readSync(this.fftImpl(f,e).dataId),h=0;h<r;h++){var p=Hi(d,h);i.values[u*r+h]=p.real,a.values[u*r+h]=p.imag}return Mn(i.toTensor(),a.toTensor()).as2D(n,r)},e.prototype.fftImpl=function(t,e){var n=t.as1D(),r=n.size;if(this.isExponentOf2(r)){var i=this.fftRadix2(n,r,e).as2D(t.shape[0],t.shape[1]);return e&&(i=Mn(Rn(i).div(Ln(r)),Fn(i).div(Ln(r)))),i}var a=this.readSync(t.dataId),o=function(t){for(var e=new Float32Array(t.length/2),n=new Float32Array(t.length/2),r=0;r<t.length;r+=2)e[r/2]=t[r],n[r/2]=t[r+1];return{real:e,imag:n}}(this.fourierTransformByMatmul(a,r,e));return Mn(o.real,o.imag).as2D(t.shape[0],t.shape[1])},e.prototype.isExponentOf2=function(t){return 0==(t&t-1)},e.prototype.fftRadix2=function(t,e,n){if(1===e)return t;var r=this.readSync(t.dataId),i=e/2,a=function(t){for(var e=Math.ceil(t.length/4),n=new Float32Array(e),r=new Float32Array(e),i=0;i<t.length;i+=4)n[Math.floor(i/4)]=t[i],r[Math.floor(i/4)]=t[i+1];return{real:n,imag:r}}(r),o=Mn(a.real,a.imag).as1D(),s=function(t){for(var e=Math.floor(t.length/4),n=new Float32Array(e),r=new Float32Array(e),i=2;i<t.length;i+=4)n[Math.floor(i/4)]=t[i],r[Math.floor(i/4)]=t[i+1];return{real:n,imag:r}}(r),u=Mn(s.real,s.imag).as1D();o=this.fftRadix2(o,i,n),u=this.fftRadix2(u,i,n);var c=function(t,e){for(var n=new Float32Array(t/2),r=new Float32Array(t/2),i=0;i<Math.ceil(t/2);i++){var a=(e?2:-2)*Math.PI*(i/t);n[i]=Math.cos(a),r[i]=Math.sin(a)}return{real:n,imag:r}}(e,n),l=Mn(c.real,c.imag).mul(u),f=o.add(l),d=o.sub(l),h=Rn(f).concat(Rn(d)),p=Fn(f).concat(Fn(d));return Mn(h,p).as1D()},e.prototype.fourierTransformByMatmul=function(t,e,n){for(var r=new Float32Array(2*e),i=0;i<e;i++){for(var a=0,o=0,s=0;s<e;s++){var u=$i(i*s,e,n),c=Hi(t,s);a+=c.real*u.real-c.imag*u.imag,o+=c.real*u.imag+c.imag*u.real}n&&(a/=e,o/=e),Gi(r,a,o,i)}return r},e.prototype.depthToSpace=function(t,e,n){C("NHWC"===n,function(){return"Only NHWC dataFormat supported on CPU for depthToSpace. Got "+n}),C(e>1,function(){return"blockSize should be > 1 for depthToSpace, but was: "+e});for(var r=t.shape[0],i=t.shape[1],a=t.shape[2],o=t.shape[3],s=i*e,u=a*e,c=o/(e*e),l=this.readSync(t.dataId),f=new Float32Array(r*s*u*c),d=0,h=0;h<r;++h)for(var p=0;p<s;++p)for(var m=Math.floor(p/e),g=p%e,v=0;v<u;++v)for(var y=Math.floor(v/e),b=(g*e+v%e)*c,x=0;x<c;++x){var w=x+b+o*(y+a*(m+i*h));f[d++]=l[w]}return Wn(f,[r,s,u,c])},e.prototype.broadcastedBinaryOp=function(t,e,n,r){var i=Ci(t.shape,e.shape),a=vr(i,n),o=this.readSync(t.dataId),s=this.readSync(e.dataId),u=Oi(t.shape,i),c=Oi(e.shape,i),l=a.values;if(u.length+c.length===0)for(var f=0;f<l.length;++f)l[f]=r(o[f%o.length],s[f%s.length]);else{var d=this.bufferSync(t),h=this.bufferSync(e),p=function(n){var i=a.indexToLoc(n),f=i.slice(-t.rank);u.forEach(function(t){return f[t]=0});var p=d.locToIndex(f),m=i.slice(-e.rank);c.forEach(function(t){return m[t]=0});var g=h.locToIndex(m);l[n]=r(o[p],s[g])};for(f=0;f<l.length;++f)p(f)}return a.toTensor()},e.prototype.broadcastedBinaryComplexOp=function(t,e,n){var r=Ci(t.shape,e.shape),i=vr(r,"float32"),a=vr(r,"float32"),o=this.readSync(t.dataId),s=this.readSync(e.dataId),u=Oi(t.shape,r),c=Oi(e.shape,r),l=i.values,f=a.values;if(u.length+c.length===0)for(var d=0;d<l.length;d++){var h=d%o.length,p=d%s.length,m=n(o[2*h],o[2*h+1],s[2*p],s[2*p+1]);l[d]=m.real,f[d]=m.imag}else{var g=this.bufferSync(this.data.get(t.dataId).complexTensors.real),v=this.bufferSync(this.data.get(e.dataId).complexTensors.real),y=function(r){var a=i.indexToLoc(r),d=a.slice(-t.rank);u.forEach(function(t){return d[t]=0});var h=g.locToIndex(d),p=a.slice(-e.rank);c.forEach(function(t){return p[t]=0});var m=v.locToIndex(p),y=n(o[2*h],o[2*h+1],s[2*m],s[2*m+1]);l[r]=y.real,f[r]=y.imag};for(d=0;d<l.length;d++)y(d)}return this.complex(i.toTensor(),a.toTensor())},e.prototype.split=function(t,e,n){return na(t,e,n)},e.prototype.dispose=function(){},e.prototype.floatPrecision=function(){return 32},e.prototype.epsilon=function(){return 1e-7},e.prototype.cropAndResize=function(t,e,n,r,i,a){for(var o=t.shape,s=o[0],u=o[1],c=o[2],l=o[3],f=e.shape[0],d=r[0],h=r[1],p=vr([f,d,h,l],"float32"),m=this.readSync(e.dataId),g=this.readSync(n.dataId),v=this.readSync(t.dataId),y=t.strides,b=p.strides,x=0;x<f;x++){var w=4*x,k=m[w],_=m[w+1],E=m[w+2],O=m[w+3],S=g[x];if(!(S>=s))for(var C=d>1?(E-k)*(u-1)/(d-1):0,A=h>1?(O-_)*(c-1)/(h-1):0,N=0;N<d;N++){var T=d>1?k*(u-1)+N*C:.5*(k+E)*(u-1);if(T<0||T>u-1)for(var I=0;I<h;I++)for(var D=0;D<l;D++){var M=D+I*b[2]+N*b[1]+x*b[0];p.values[M]=a}else if("bilinear"===i){var R=Math.floor(T),F=Math.ceil(T),j=T-R;for(I=0;I<h;I++)if((H=h>1?_*(c-1)+I*A:.5*(_+O)*(c-1))<0||H>c-1)for(D=0;D<l;D++)M=D+I*b[2]+N*b[1]+x*b[0],p.values[M]=a;else{var P=Math.floor(H),L=Math.ceil(H),z=H-P;for(D=0;D<l;D++){var B=v[M=D+P*y[2]+R*y[1]+S*y[0]],U=v[M=D+L*y[2]+R*y[1]+S*y[0]],W=v[M=D+P*y[2]+F*y[1]+S*y[0]],V=B+(U-B)*z,q=W+(v[M=D+L*y[2]+F*y[1]+S*y[0]]-W)*z;M=D+I*b[2]+N*b[1]+x*b[0],p.values[M]=V+(q-V)*j}}}else for(I=0;I<h;++I){var H;if((H=h>1?_*(c-1)+I*A:.5*(_+O)*(c-1))<0||H>c-1)for(D=0;D<l;D++)M=D+I*b[2]+N*b[1]+x*b[0],p.values[M]=a;else{var G=Math.round(H),$=Math.round(T);for(D=0;D<l;D++){var K=D+G*y[2]+$*y[1]+S*y[0],X=D+I*b[2]+N*b[1]+x*b[0];p.values[X]=v[K]}}}}}return p.toTensor()},e.prototype.sparseToDense=function(t,e,n,r){var i=ri(0,t,n),a=i.sliceRank,o=i.numUpdates,s=i.sliceSize,u=i.strides,c=i.outputSize;return this.scatter(t,e,n,c,s,o,a,u,r,!1)},e.prototype.gatherND=function(t,e){var n=e.shape,r=n[n.length-1],i=Jr(t,e),a=i[0],o=i[1],s=i[2],u=i[3];if(0===o)return jn([],a,t.dtype);for(var c=new wt([o,s],t.dtype),l=this.readSync(e.dataId),f=this.readSync(t.dataId),d=0;d<o;d++){for(var h=[],p=0,m=0;m<r;m++){var g=l[d*r+m];p+=g*u[m],h.push(g)}if(p<0||p>=t.size/s)throw new Error("Invalid indices: "+h+" does not index into "+t.shape);for(var v=0;v<s;v++)c.values[d*s+v]=f[p*s+v]}return c.toTensor().reshape(a)},e.prototype.scatterND=function(t,e,n){var r=ri(0,t,n),i=r.sliceRank,a=r.numUpdates,o=r.sliceSize,s=r.strides,u=r.outputSize,c=Ln(0);return this.scatter(t,e,n,u,o,a,i,s,c,!0)},e.prototype.fill=function(t,e,n){var r=W(n=n||Z(e),I(t));return r.fill(e),Wt.makeTensor(r,t,n,this)},e.prototype.onesLike=function(t){if("string"===t.dtype)throw new Error("onesLike is not supported for string tensors");return this.fill(t.shape,1,t.dtype)},e.prototype.zerosLike=function(t){var e=W(t.dtype,I(t.shape));return this.makeOutput(e,t.shape,t.dtype)},e.prototype.linspace=function(t,e,n){return Wi(t,e,n)},e.prototype.scatter=function(t,e,n,r,i,a,o,s,u,c){var l=[r/i,i],f=this.readSync(t.dataId),d=this.readSync(e.dataId);if(0===r)return jn([],n,e.dtype);var h=new wt(l,e.dtype);h.values.fill(this.readSync(u.dataId)[0]);for(var p=0;p<a;p++){for(var m=[],g=0,v=0;v<o;v++){var y=f[p*o+v];m.push(y),g+=y*s[v]}if(g<0||g>=r/i)throw new Error("Invalid indices: "+m+" does not index into "+n);for(var b=0;b<i;b++)c?h.values[g*i+b]+=d[p*i+b]:h.values[g*i+b]=0===e.rank?d[0]:d[p*i+b]}return h.toTensor().reshape(n)},e}(_i);Wt.registerBackend("cpu",function(){return new Dl},1);for(var Ml=0,Rl=[{kernelName:"NonMaxSuppressionV5",backendName:"cpu",kernelFunc:function(t){var e=t.inputs,n=t.backend,r=t.attrs,i=e,a=i.boxes,o=i.scores,s=r,u=s.maxOutputSize,c=s.iouThreshold,l=s.scoreThreshold,f=s.softNmsSigma,d=n;Tl(a,"NonMaxSuppressionWithScore");var h=Ji(d.data.get(a.dataId).values,d.data.get(o.dataId).values,u,c,l,f);return[h.selectedIndices,h.selectedScores]}},{kernelName:"Square",backendName:"cpu",kernelFunc:function(t){var e=t.inputs,n=t.backend,r=e.x,i=n;Tl(r,"square");for(var a=i.data.get(r.dataId).values,o=new Float32Array(a.length),s=0;s<a.length;++s){var u=a[s];o[s]=u*u}return{dataId:i.write(o,r.shape,r.dtype),shape:r.shape,dtype:r.dtype}}},{kernelName:Vo,backendName:"cpu",kernelFunc:function(t){var e=t.inputs,n=t.backend,r=e,i=r.a,a=r.b,o=n;Tl([i,a],Vo);var s=o.data.get(i.dataId).values,u=o.data.get(a.dataId).values,c=function(t,e,n,r,i,a){var o=Ci(t,e),s=o.length,u=et(o),c=U(i,I(o)),l=t.length,f=e.length,d=et(t),h=et(e),p=Oi(t,o),m=Oi(e,o);if(p.length+m.length===0)for(var g=0;g<c.length;++g)c[g]=a(n[g%n.length],r[g%r.length]);else{var v=function(t){var e=ft(t,s,u),i=e.slice(-l);p.forEach(function(t){return i[t]=0});var o=lt(i,l,d),g=e.slice(-f);m.forEach(function(t){return g[t]=0});var v=lt(g,f,h);c[t]=a(n[o],r[v])};for(g=0;g<c.length;++g)v(g)}return[c,o]}(i.shape,a.shape,s,u,i.dtype,function(t,e){var n=t-e;return n*n}),l=c[0],f=c[1];return{dataId:o.write(l,f,i.dtype),shape:f,dtype:i.dtype}}}];Ml<Rl.length;Ml++)y(Rl[Ml]);for(var Fl,jl=0,Pl=[{kernelName:"FromPixels",backendName:"webgl",kernelFunc:function(t){var e=t.inputs,n=t.backend,r=t.attrs,i=e.pixels,a=r.numChannels,o="undefined"!=typeof HTMLVideoElement&&i instanceof HTMLVideoElement,s="undefined"!=typeof HTMLImageElement&&i instanceof HTMLImageElement,u=o?[i.videoWidth,i.videoHeight]:[i.width,i.height],c=u[0],l=u[1],d=[l,c],h=[l,c,a];(s||o)&&(null==Fl&&(Fl=document.createElement("canvas").getContext("2d")),Fl.canvas.width=c,Fl.canvas.height=l,Fl.drawImage(i,0,0,c,l),i=Fl.canvas);var p=n.makeTensorInfo(d,"int32");n.texData.get(p.dataId).usage=Gt.PIXELS,n.gpgpu.uploadPixelDataToTexture(n.getTexture(p.dataId),i);var m=f().getBool("WEBGL_PACK")?new function(t){this.variableNames=["A"],this.packedInputs=!1,this.packedOutput=!0;var e=ua(),n=t[0],r=t[1];this.outputShape=t,this.userCode="\n void main() {\n ivec3 coords = getOutputCoords();\n int texR = coords[0];\n int texC = coords[1];\n int depth = coords[2];\n\n vec4 result = vec4(0.);\n\n for(int row=0; row<=1; row++) {\n for(int col=0; col<=1; col++) {\n texC = coords[1] + row;\n depth = coords[2] + col;\n\n vec2 uv = (vec2(texC, texR) + halfCR) /\n vec2("+r+".0, "+n+".0);\n vec4 values = "+e.texture2D+"(A, uv);\n float value;\n if (depth == 0) {\n value = values.r;\n } else if (depth == 1) {\n value = values.g;\n } else if (depth == 2) {\n value = values.b;\n } else if (depth == 3) {\n value = values.a;\n }\n\n result[row * 2 + col] = floor(value * 255.0 + 0.5);\n }\n }\n\n "+e.output+" = result;\n }\n "}(h):new function(t){this.variableNames=["A"];var e=ua(),n=t[0],r=t[1];this.outputShape=t,this.userCode="\n void main() {\n ivec3 coords = getOutputCoords();\n int texR = coords[0];\n int texC = coords[1];\n int depth = coords[2];\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2("+r+".0, "+n+".0);\n\n vec4 values = "+e.texture2D+"(A, uv);\n float value;\n if (depth == 0) {\n value = values.r;\n } else if (depth == 1) {\n value = values.g;\n } else if (depth == 2) {\n value = values.b;\n } else if (depth == 3) {\n value = values.a;\n }\n\n setOutput(floor(value * 255.0 + 0.5));\n }\n "}(h),g=n.runWebGLProgram(m,[p],"int32");return n.disposeData(p.dataId),g}},{kernelName:"NonMaxSuppressionV5",backendName:"webgl",kernelFunc:function(t){var e=t.inputs,n=t.backend,r=t.attrs;vn("tf.nonMaxSuppression() in webgl locks the UI thread. Call tf.nonMaxSuppressionAsync() instead");var i=e,a=i.boxes,o=i.scores,s=r,u=s.maxOutputSize,c=s.iouThreshold,l=s.scoreThreshold,f=s.softNmsSigma,d=n,h=Ji(d.readSync(a.dataId),d.readSync(o.dataId),u,c,l,f);return[h.selectedIndices,h.selectedScores]}},{kernelName:"Square",backendName:"webgl",kernelFunc:function(t){var e=t.inputs,n=t.backend,r=e.x,i=n,a=new xo(r.shape,"return x * x;");return i.runWebGLProgram(a,[r],r.dtype)}},{kernelName:Vo,backendName:"webgl",kernelFunc:function(t){var e=t.inputs,n=t.backend,r=e,i=r.a,a=r.b,o=n,s=f().getBool("WEBGL_PACK_BINARY_OPERATIONS")?new Na("return (a - b) * (a - b);",i.shape,a.shape):new Ca("return (a - b) * (a - b);",i.shape,a.shape);return o.compileAndRun(s,[i,a])}}];jl<Pl.length;jl++)y(Pl[jl]);for(var Ll=0,zl=[{kernelName:"Square",gradFunc:function(t,e){var n=e[0];return{x:function(){return t.mul(n.toFloat().mul(2))}}}},{kernelName:Vo,gradFunc:function(t,e){var n=e[0],r=e[1],i=Ln(2);return{a:function(){return au(t,au(i,lu(n,r)))},b:function(){return au(t,au(i,lu(r,n)))}}}}];Ll<zl.length;Ll++)b(zl[Ll]);var Bl=function(){function t(){}return t.prototype.fetch=function(t,e){return fetch(t,e)},t.prototype.now=function(){return performance.now()},t.prototype.encode=function(t,e){if("utf-8"!==e&&"utf8"!==e)throw new Error("Browser's encoder only supports utf-8, but got "+e);return null==this.textEncoder&&(this.textEncoder=new TextEncoder),this.textEncoder.encode(t)},t.prototype.decode=function(t,e){return new TextDecoder(e).decode(t)},t}();f().get("IS_BROWSER")&&f().setPlatform("browser",new Bl);var Ul,Wl=function(){function t(){this.util=n(301),this.textEncoder=new this.util.TextEncoder}return t.prototype.fetch=function(t,e){return null!=f().global.fetch?f().global.fetch(t,e):(null==Ul&&(Ul=n(302)),Ul(t,e))},t.prototype.now=function(){var t=r.hrtime();return 1e3*t[0]+t[1]/1e6},t.prototype.encode=function(t,e){if("utf-8"!==e&&"utf8"!==e)throw new Error("Node built-in encoder only supports utf-8, but got "+e);return this.textEncoder.encode(t)},t.prototype.decode=function(t,e){return 0===t.length?"":new this.util.TextDecoder(e).decode(t)},t}();f().get("IS_NODE")&&f().setPlatform("node",new Wl);var Vl={float32:4,int32:4,uint16:2,uint8:1,bool:1},ql=4;function Hl(t,e){for(var n={},r=0,i=function(e){var i=e.name,a=e.dtype,o=e.shape,s=I(o),u=void 0;if("quantization"in e){var c=e.quantization;if("uint8"!==c.dtype&&"uint16"!==c.dtype)throw new Error("Weight "+e.name+" has unknown quantization dtype "+c.dtype+". Supported quantization dtypes are: 'uint8' and 'uint16'.");var l=Vl[c.dtype],f=t.slice(r,r+s*l),d="uint8"===c.dtype?new Uint8Array(f):new Uint16Array(f);if("float32"===a)u=Float32Array.from(d,function(t){return t*c.scale+c.min});else{if("int32"!==a)throw new Error("Unsupported dtype in weight '"+i+"': "+a);u=Int32Array.from(d,function(t){return Math.round(t*c.scale+c.min)})}r+=s*l}else if("string"===a){var h=I(e.shape);u=[];for(var p=0;p<h;p++){var m=new Uint32Array(t.slice(r,r+ql))[0];r+=ql;var g=new Uint8Array(t.slice(r,r+m));u.push(g),r+=m}}else{var v=Vl[a];if(f=t.slice(r,r+s*v),"float32"===a)u=new Float32Array(f);else if("int32"===a)u=new Int32Array(f);else{if("bool"!==a)throw new Error("Unsupported dtype in weight '"+i+"': "+a);u=new Uint8Array(f)}r+=s*v}n[i]=jn(u,o,a)},a=0,o=e;a<o.length;a++)i(o[a]);return n}var Gl=void 0!==i&&("undefined"==typeof Blob||"undefined"==typeof atob||"undefined"==typeof btoa);function $l(t){return Gl?i.byteLength(t):new Blob([t]).size}function Kl(t){var e=0;t.forEach(function(t){e+=t.byteLength});var n=new Uint8Array(e),r=0;return t.forEach(function(t){n.set(new Uint8Array(t),r),r+=t.byteLength}),n.buffer}function Xl(t){for(t=t.trim();t.endsWith("/");)t=t.slice(0,t.length-1);var e=t.split("/");return e[e.length-1]}function Yl(t){if(t.modelTopology instanceof ArrayBuffer)throw new Error("Expected JSON model topology, received ArrayBuffer.");return{dateSaved:new Date,modelTopologyType:"JSON",modelTopologyBytes:null==t.modelTopology?0:$l(JSON.stringify(t.modelTopology)),weightSpecsBytes:null==t.weightSpecs?0:$l(JSON.stringify(t.weightSpecs)),weightDataBytes:null==t.weightData?0:t.weightData.byteLength}}var Jl=function(){function t(){this.saveRouters=[],this.loadRouters=[]}return t.getInstance=function(){return null==t.instance&&(t.instance=new t),t.instance},t.registerSaveRouter=function(e){t.getInstance().saveRouters.push(e)},t.registerLoadRouter=function(e){t.getInstance().loadRouters.push(e)},t.getSaveHandlers=function(e){return t.getHandlers(e,"save")},t.getLoadHandlers=function(e,n){return t.getHandlers(e,"load",n)},t.getHandlers=function(e,n,r){var i=[];return("load"===n?t.getInstance().loadRouters:t.getInstance().saveRouters).forEach(function(t){var n=t(e,r);null!==n&&i.push(n)}),i},t}(),Zl="://",Ql=function(){function t(){this.managers={}}return t.getInstance=function(){return null==t.instance&&(t.instance=new t),t.instance},t.registerManager=function(e,n){C(null!=e,function(){return"scheme must not be undefined or null."}),e.endsWith(Zl)&&(e=e.slice(0,e.indexOf(Zl))),C(e.length>0,function(){return"scheme must not be an empty string."});var r=t.getInstance();C(null==r.managers[e],function(){return"A model store manager is already registered for scheme '"+e+"'."}),r.managers[e]=n},t.getManager=function(t){var e=this.getInstance().managers[t];if(null==e)throw new Error("Cannot find model manager for scheme '"+t+"'");return e},t.getSchemes=function(){return Object.keys(this.getInstance().managers)},t}();function tf(t){if(-1===t.indexOf(Zl))throw new Error("The url string provided does not contain a scheme. Supported schemes are: "+Ql.getSchemes().join(","));return{scheme:t.split(Zl)[0],path:t.split(Zl)[1]}}function ef(t,e,n){return void 0===n&&(n=!1),u(this,void 0,void 0,function(){var r,i,a,o,s,u,l,f,d;return c(this,function(c){switch(c.label){case 0:return C(t!==e,function(){return"Old path and new path are the same: '"+t+"'"}),C((r=Jl.getLoadHandlers(t)).length>0,function(){return"Copying failed because no load handler is found for source URL "+t+"."}),C(r.length<2,function(){return"Copying failed because more than one ("+r.length+") load handlers for source URL "+t+"."}),i=r[0],C((a=Jl.getSaveHandlers(e)).length>0,function(){return"Copying failed because no save handler is found for destination URL "+e+"."}),C(a.length<2,function(){return"Copying failed because more than one ("+r.length+") save handlers for destination URL "+e+"."}),o=a[0],s=tf(t).scheme,u=tf(t).path,l=s===tf(t).scheme,[4,i.load()];case 1:return f=c.sent(),n&&l?[4,Ql.getManager(s).removeModel(u)]:[3,3];case 2:c.sent(),c.label=3;case 3:return[4,o.save(f)];case 4:return d=c.sent(),!n||l?[3,6]:[4,Ql.getManager(s).removeModel(u)];case 5:c.sent(),c.label=6;case 6:return[2,d.modelArtifactsInfo]}})})}var nf="models_store",rf="model_info_store";function af(){if(!f().getBool("IS_BROWSER"))throw new Error("Failed to obtain IndexedDB factory because the current environmentis not a web browser.");var t=window||self,e=t.indexedDB||t.mozIndexedDB||t.webkitIndexedDB||t.msIndexedDB||t.shimIndexedDB;if(null==e)throw new Error("The current browser does not appear to support IndexedDB.");return e}function of(t){var e=t.result;e.createObjectStore(nf,{keyPath:"modelPath"}),e.createObjectStore(rf,{keyPath:"modelPath"})}var sf=function(){function t(t){if(this.indexedDB=af(),null==t||!t)throw new Error("For IndexedDB, modelPath must not be null, undefined or empty.");this.modelPath=t}return t.prototype.save=function(t){return u(this,void 0,void 0,function(){return c(this,function(e){if(t.modelTopology instanceof ArrayBuffer)throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");return[2,this.databaseAction(this.modelPath,t)]})})},t.prototype.load=function(){return u(this,void 0,void 0,function(){return c(this,function(t){return[2,this.databaseAction(this.modelPath)]})})},t.prototype.databaseAction=function(t,e){var n=this;return new Promise(function(t,r){var i=n.indexedDB.open("tensorflowjs",1);i.onupgradeneeded=function(){return of(i)},i.onsuccess=function(){var a=i.result;if(null==e){var o=a.transaction(nf,"readonly"),s=o.objectStore(nf).get(n.modelPath);s.onsuccess=function(){if(null==s.result)return a.close(),r(new Error("Cannot find model with path '"+n.modelPath+"' in IndexedDB."));t(s.result.modelArtifacts)},s.onerror=function(t){return a.close(),r(s.error)},o.oncomplete=function(){return a.close()}}else{var u,c=Yl(e),l=a.transaction(rf,"readwrite"),f=l.objectStore(rf),d=f.put({modelPath:n.modelPath,modelArtifactsInfo:c});d.onsuccess=function(){var i=(u=a.transaction(nf,"readwrite")).objectStore(nf).put({modelPath:n.modelPath,modelArtifacts:e,modelArtifactsInfo:c});i.onsuccess=function(){return t({modelArtifactsInfo:c})},i.onerror=function(t){var e=(f=l.objectStore(rf)).delete(n.modelPath);e.onsuccess=function(){return a.close(),r(i.error)},e.onerror=function(t){return a.close(),r(i.error)}}},d.onerror=function(t){return a.close(),r(d.error)},l.oncomplete=function(){null==u?a.close():u.oncomplete=function(){return a.close()}}}},i.onerror=function(t){return r(i.error)}})},t.URL_SCHEME="indexeddb://",t}(),uf=function(t){return f().getBool("IS_BROWSER")&&!Array.isArray(t)&&t.startsWith(sf.URL_SCHEME)?(e=t.slice(sf.URL_SCHEME.length),new sf(e)):null;var e};Jl.registerSaveRouter(uf),Jl.registerLoadRouter(uf);var cf=function(){function t(){this.indexedDB=af()}return t.prototype.listModels=function(){return u(this,void 0,void 0,function(){var t=this;return c(this,function(e){return[2,new Promise(function(e,n){var r=t.indexedDB.open("tensorflowjs",1);r.onupgradeneeded=function(){return of(r)},r.onsuccess=function(){var t=r.result,i=t.transaction(rf,"readonly"),a=i.objectStore(rf).getAll();a.onsuccess=function(){for(var t={},n=0,r=a.result;n<r.length;n++){var i=r[n];t[i.modelPath]=i.modelArtifactsInfo}e(t)},a.onerror=function(e){return t.close(),n(a.error)},i.oncomplete=function(){return t.close()}},r.onerror=function(t){return n(r.error)}})]})})},t.prototype.removeModel=function(t){return u(this,void 0,void 0,function(){var e=this;return c(this,function(n){var r;return t=(r=t).startsWith(sf.URL_SCHEME)?r.slice(sf.URL_SCHEME.length):r,[2,new Promise(function(n,r){var i=e.indexedDB.open("tensorflowjs",1);i.onupgradeneeded=function(){return of(i)},i.onsuccess=function(){var e,a=i.result,o=a.transaction(rf,"readwrite"),s=o.objectStore(rf),u=s.get(t);u.onsuccess=function(){if(null==u.result)return a.close(),r(new Error("Cannot find model with path '"+t+"' in IndexedDB."));var i=s.delete(t),o=function(){var i=(e=a.transaction(nf,"readwrite")).objectStore(nf).delete(t);i.onsuccess=function(){return n(u.result.modelArtifactsInfo)},i.onerror=function(t){return r(u.error)}};i.onsuccess=o,i.onerror=function(t){return o(),a.close(),r(u.error)}},u.onerror=function(t){return a.close(),r(u.error)},o.oncomplete=function(){null==e?a.close():e.oncomplete=function(){return a.close()}}},i.onerror=function(t){return r(i.error)}})]})})},t}();if(f().getBool("IS_BROWSER"))try{Ql.registerManager(sf.URL_SCHEME,new cf)}catch(o){}var lf="/",ff="tensorflowjs_models",df="info",hf="model_topology",pf="weight_specs",mf="weight_data",gf="model_metadata";function vf(t){return{info:[ff,t,df].join(lf),topology:[ff,t,hf].join(lf),weightSpecs:[ff,t,pf].join(lf),weightData:[ff,t,mf].join(lf),modelMetadata:[ff,t,gf].join(lf)}}function yf(t){var e=t.split(lf);if(e.length<3)throw new Error("Invalid key format: "+t);return e.slice(1,e.length-1).join(lf)}var bf=function(){function t(t){if(!f().getBool("IS_BROWSER")||"undefined"==typeof window||void 0===window.localStorage)throw new Error("The current environment does not support local storage.");if(this.LS=window.localStorage,null==t||!t)throw new Error("For local storage, modelPath must not be null, undefined or empty.");this.modelPath=t,this.keys=vf(this.modelPath)}return t.prototype.save=function(t){return u(this,void 0,void 0,function(){var e,n,r;return c(this,function(a){if(t.modelTopology instanceof ArrayBuffer)throw new Error("BrowserLocalStorage.save() does not support saving model topology in binary formats yet.");e=JSON.stringify(t.modelTopology),n=JSON.stringify(t.weightSpecs),r=Yl(t);try{return this.LS.setItem(this.keys.info,JSON.stringify(r)),this.LS.setItem(this.keys.topology,e),this.LS.setItem(this.keys.weightSpecs,n),this.LS.setItem(this.keys.weightData,function(t){if(Gl)return i.from(t).toString("base64");for(var e=new Uint8Array(t),n="",r=0,a=e.length;r<a;r++)n+=String.fromCharCode(e[r]);return btoa(n)}(t.weightData)),this.LS.setItem(this.keys.modelMetadata,JSON.stringify({format:t.format,generatedBy:t.generatedBy,convertedBy:t.convertedBy,userDefinedMetadata:t.userDefinedMetadata})),[2,{modelArtifactsInfo:r}]}catch(t){throw this.LS.removeItem(this.keys.info),this.LS.removeItem(this.keys.topology),this.LS.removeItem(this.keys.weightSpecs),this.LS.removeItem(this.keys.weightData),this.LS.removeItem(this.keys.modelMetadata),new Error("Failed to save model '"+this.modelPath+"' to local storage: size quota being exceeded is a possible cause of this failure: modelTopologyBytes="+r.modelTopologyBytes+", weightSpecsBytes="+r.weightSpecsBytes+", weightDataBytes="+r.weightDataBytes+".")}return[2]})})},t.prototype.load=function(){return u(this,void 0,void 0,function(){var t,e,n,r,a,o,s;return c(this,function(u){if(null==(t=JSON.parse(this.LS.getItem(this.keys.info))))throw new Error("In local storage, there is no model with name '"+this.modelPath+"'");if("JSON"!==t.modelTopologyType)throw new Error("BrowserLocalStorage does not support loading non-JSON model topology yet.");if(e={},null==(n=JSON.parse(this.LS.getItem(this.keys.topology))))throw new Error("In local storage, the topology of model '"+this.modelPath+"' is missing.");if(e.modelTopology=n,null==(r=JSON.parse(this.LS.getItem(this.keys.weightSpecs))))throw new Error("In local storage, the weight specs of model '"+this.modelPath+"' are missing.");if(e.weightSpecs=r,null!=(a=this.LS.getItem(this.keys.modelMetadata))&&(o=JSON.parse(a),e.format=o.format,e.generatedBy=o.generatedBy,e.convertedBy=o.convertedBy,e.userDefinedMetadata=o.userDefinedMetadata),null==(s=this.LS.getItem(this.keys.weightData)))throw new Error("In local storage, the binary weight values of model '"+this.modelPath+"' are missing.");return e.weightData=function(t){if(Gl){var e=i.from(t,"base64");return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}for(var n=atob(t),r=new Uint8Array(n.length),a=0;a<n.length;++a)r.set([n.charCodeAt(a)],a);return r.buffer}(s),[2,e]})})},t.URL_SCHEME="localstorage://",t}(),xf=function(t){return f().getBool("IS_BROWSER")&&!Array.isArray(t)&&t.startsWith(bf.URL_SCHEME)?(e=t.slice(bf.URL_SCHEME.length),new bf(e)):null;var e};Jl.registerSaveRouter(xf),Jl.registerLoadRouter(xf);var wf=function(){function t(){C(f().getBool("IS_BROWSER"),function(){return"Current environment is not a web browser"}),C("undefined"==typeof window||void 0!==window.localStorage,function(){return"Current browser does not appear to support localStorage"}),this.LS=window.localStorage}return t.prototype.listModels=function(){return u(this,void 0,void 0,function(){var t,e,n,r,i,a;return c(this,function(o){for(t={},e=ff+lf,n=lf+df,r=0;r<this.LS.length;++r)(i=this.LS.key(r)).startsWith(e)&&i.endsWith(n)&&(a=yf(i),t[a]=JSON.parse(this.LS.getItem(i)));return[2,t]})})},t.prototype.removeModel=function(t){return u(this,void 0,void 0,function(){var e,n;return c(this,function(r){var i;if(t=(i=t).startsWith(bf.URL_SCHEME)?i.slice(bf.URL_SCHEME.length):i,e=vf(t),null==this.LS.getItem(e.info))throw new Error("Cannot find model at path '"+t+"'");return n=JSON.parse(this.LS.getItem(e.info)),this.LS.removeItem(e.info),this.LS.removeItem(e.topology),this.LS.removeItem(e.weightSpecs),this.LS.removeItem(e.weightData),[2,n]})})},t}();if(f().getBool("IS_BROWSER"))try{Ql.registerManager(bf.URL_SCHEME,new wf)}catch(o){}var kf="model",_f=".json",Ef=".weights.bin";function Of(t){return new Promise(function(t){return setTimeout(t)}).then(t)}var Sf=function(){function t(e){if(!f().getBool("IS_BROWSER"))throw new Error("browserDownloads() cannot proceed because the current environment is not a browser.");e.startsWith(t.URL_SCHEME)&&(e=e.slice(t.URL_SCHEME.length)),null!=e&&0!==e.length||(e=kf),this.modelTopologyFileName=e+_f,this.weightDataFileName=e+Ef}return t.prototype.save=function(t){return u(this,void 0,void 0,function(){var e,n,r,i,a,o;return c(this,function(s){switch(s.label){case 0:if("undefined"==typeof document)throw new Error("Browser downloads are not supported in this environment since `document` is not present");if(e=window.URL.createObjectURL(new Blob([t.weightData],{type:"application/octet-stream"})),!(t.modelTopology instanceof ArrayBuffer))return[3,1];throw new Error("BrowserDownloads.save() does not support saving model topology in binary formats yet.");case 1:return n=[{paths:["./"+this.weightDataFileName],weights:t.weightSpecs}],r={modelTopology:t.modelTopology,format:t.format,generatedBy:t.generatedBy,convertedBy:t.convertedBy,weightsManifest:n},i=window.URL.createObjectURL(new Blob([JSON.stringify(r)],{type:"application/json"})),(a=null==this.jsonAnchor?document.createElement("a"):this.jsonAnchor).download=this.modelTopologyFileName,a.href=i,[4,Of(function(){return a.dispatchEvent(new MouseEvent("click"))})];case 2:return s.sent(),null==t.weightData?[3,4]:((o=null==this.weightDataAnchor?document.createElement("a"):this.weightDataAnchor).download=this.weightDataFileName,o.href=e,[4,Of(function(){return o.dispatchEvent(new MouseEvent("click"))})]);case 3:s.sent(),s.label=4;case 4:return[2,{modelArtifactsInfo:Yl(t)}]}})})},t.URL_SCHEME="downloads://",t}(),Cf=function(){function t(t){if(null==t||t.length<1)throw new Error("When calling browserFiles, at least 1 file is required, but received "+t);this.files=t}return t.prototype.load=function(){return u(this,void 0,void 0,function(){var t,e,n=this;return c(this,function(r){return t=this.files[0],e=this.files.slice(1),[2,new Promise(function(r,i){var a=new FileReader;a.onload=function(a){var o=JSON.parse(a.target.result),s=o.modelTopology;if(null!=s){0===e.length&&r({modelTopology:s});var u=o.weightsManifest;if(null!=u){var c;try{c=n.checkManifestAndWeightFiles(u,e)}catch(t){return void i(t)}var l=[],f=[],d=[];u.forEach(function(t){t.paths.forEach(function(t){f.push(t),d.push(null)}),l.push.apply(l,t.weights)}),u.forEach(function(t){t.paths.forEach(function(t){var e=new FileReader;e.onload=function(e){var n=e.target.result,i=f.indexOf(t);d[i]=n,-1===d.indexOf(null)&&r({modelTopology:s,weightSpecs:l,weightData:Kl(d),format:o.format,generatedBy:o.generatedBy,convertedBy:o.convertedBy,userDefinedMetadata:o.userDefinedMetadata})},e.onerror=function(e){return i("Failed to weights data from file of path '"+t+"'.")},e.readAsArrayBuffer(c[t])})})}else i(new Error("weightManifest field is missing from file "+t.name))}else i(new Error("modelTopology field is missing from file "+t.name))},a.onerror=function(e){return i("Failed to read model topology and weights manifest JSON from file '"+t.name+"'. BrowserFiles supports loading Keras-style tf.Model artifacts only.")},a.readAsText(t)})]})})},t.prototype.checkManifestAndWeightFiles=function(t,e){for(var n=[],r=e.map(function(t){return Xl(t.name)}),i={},a=0,o=t;a<o.length;a++)o[a].paths.forEach(function(t){var a=Xl(t);if(-1!==n.indexOf(a))throw new Error("Duplicate file basename found in weights manifest: '"+a+"'");if(n.push(a),-1===r.indexOf(a))throw new Error("Weight file with basename '"+a+"' is not provided.");i[t]=e[r.indexOf(a)]});if(n.length!==e.length)throw new Error("Mismatch in the number of files in weights manifest ("+n.length+") and the number of weight files provided ("+e.length+").");return i},t}();function Af(t,e,n,r){!function(t){C(null!=t&&Array.isArray(t)&&t.length>0,function(){return"promises must be a none empty array"})}(t),function(t,e){C(t>=0&&t<=1,function(){return"Progress fraction must be in range [0, 1], but got startFraction "+t}),C(e>=0&&e<=1,function(){return"Progress fraction must be in range [0, 1], but got endFraction "+e}),C(e>=t,function(){return"startFraction must be no more than endFraction, but got startFraction "+t+" and endFraction "+e})}(n=null==n?0:n,r=null==r?1:r);var i=0;return Promise.all(t.map(function(a){return a.then(function(a){var o=n+ ++i/t.length*(r-n);return e(o),a}),a}))}function Nf(t,e){return u(this,void 0,void 0,function(){var n,r,i,a,o,s,u,l,d;return c(this,function(c){switch(c.label){case 0:return null==e&&(e={}),n=null==e.fetchFunc?f().platform.fetch:e.fetchFunc,r=t.map(function(t){return n(t,e.requestInit,{isBinary:!0})}),i=0,a=.5,null!=e.onProgress?[3,2]:[4,Promise.all(r)];case 1:return o=c.sent(),[3,4];case 2:return[4,Af(r,e.onProgress,i,a)];case 3:o=c.sent(),c.label=4;case 4:return s=o.map(function(t){return t.arrayBuffer()}),u=.5,l=1,null!=e.onProgress?[3,6]:[4,Promise.all(s)];case 5:return d=c.sent(),[3,8];case 6:return[4,Af(s,e.onProgress,u,l)];case 7:d=c.sent(),c.label=8;case 8:return[2,d]}})})}function Tf(t){var e=this;return function(n,r,i){return void 0===r&&(r=""),u(e,void 0,void 0,function(){var e,a,o,s,u,l,f,d,h,p;return c(this,function(c){switch(c.label){case 0:if(e=n.map(function(){return!1}),a={},o=null!=i?i.map(function(){return!1}):[],s=[],n.forEach(function(t,n){var r=0;t.weights.forEach(function(t){var u="quantization"in t?t.quantization.dtype:t.dtype,c=Vl[u]*I(t.shape),l=function(){e[n]=!0,null==a[n]&&(a[n]=[]),a[n].push({manifestEntry:t,groupOffset:r,sizeBytes:c})};null!=i?i.forEach(function(e,n){e===t.name&&(l(),o[n]=!0)}):l(),s.push(t.name),r+=c})}),!o.every(function(t){return t}))throw u=i.filter(function(t,e){return!o[e]}),new Error("Could not find weights in manifest with names: "+u.join(", ")+". \nManifest JSON has weights with names: "+s.join(", ")+".");return l=e.reduce(function(t,e,n){return e&&t.push(n),t},[]),f=[],l.forEach(function(t){n[t].paths.forEach(function(t){var e=r+(r.endsWith("/")?"":"/")+t;f.push(e)})}),[4,t(f)];case 1:return d=c.sent(),h={},p=0,l.forEach(function(t){for(var e=n[t].paths.length,r=0,i=0;i<e;i++)r+=d[p+i].byteLength;for(var o=new ArrayBuffer(r),s=new Uint8Array(o),u=0,c=0;c<e;c++){var l=new Uint8Array(d[p+c]);s.set(l,u),u+=l.byteLength}a[t].forEach(function(t){var e=Hl(o.slice(t.groupOffset,t.groupOffset+t.sizeBytes),[t.manifestEntry]);for(var n in e)h[n]=e[n]}),p+=e}),[2,h]}})})}}Jl.registerSaveRouter(function(t){return f().getBool("IS_BROWSER")&&!Array.isArray(t)&&t.startsWith(Sf.URL_SCHEME)?function(t){return void 0===t&&(t="model"),new Sf(t)}(t.slice(Sf.URL_SCHEME.length)):null});var If=function(){function t(t,e){if(this.DEFAULT_METHOD="POST",null==e&&(e={}),this.weightPathPrefix=e.weightPathPrefix,this.onProgress=e.onProgress,null!=e.fetchFunc?(C("function"==typeof e.fetchFunc,function(){return"Must pass a function that matches the signature of `fetch` (see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)"}),this.fetch=e.fetchFunc):this.fetch=f().platform.fetch,C(null!=t&&t.length>0,function(){return"URL path for http must not be null, undefined or empty."}),Array.isArray(t)&&C(2===t.length,function(){return"URL paths for http must have a length of 2, (actual length is "+t.length+")."}),this.path=t,null!=e.requestInit&&null!=e.requestInit.body)throw new Error("requestInit is expected to have no pre-existing body, but has one.");this.requestInit=e.requestInit||{}}return t.prototype.save=function(t){return u(this,void 0,void 0,function(){var e,n,r,i;return c(this,function(a){switch(a.label){case 0:if(t.modelTopology instanceof ArrayBuffer)throw new Error("BrowserHTTPRequest.save() does not support saving model topology in binary formats yet.");return(e=Object.assign({method:this.DEFAULT_METHOD},this.requestInit)).body=new FormData,n=[{paths:["./model.weights.bin"],weights:t.weightSpecs}],r={modelTopology:t.modelTopology,format:t.format,generatedBy:t.generatedBy,convertedBy:t.convertedBy,userDefinedMetadata:t.userDefinedMetadata,weightsManifest:n},e.body.append("model.json",new Blob([JSON.stringify(r)],{type:"application/json"}),"model.json"),null!=t.weightData&&e.body.append("model.weights.bin",new Blob([t.weightData],{type:"application/octet-stream"}),"model.weights.bin"),[4,this.fetch(this.path,e)];case 1:if((i=a.sent()).ok)return[2,{modelArtifactsInfo:Yl(t),responses:[i]}];throw new Error("BrowserHTTPRequest.save() failed due to HTTP response status "+i.status+".")}})})},t.prototype.load=function(){return u(this,void 0,void 0,function(){var t,e,n,r,i,a,o,s,u,l,f,d;return c(this,function(c){switch(c.label){case 0:return[4,this.fetch(this.path,this.requestInit)];case 1:if(!(t=c.sent()).ok)throw new Error("Request to "+this.path+" failed with status code "+t.status+". Please verify this URL points to the model JSON of the model to load.");c.label=2;case 2:return c.trys.push([2,4,,5]),[4,t.json()];case 3:return e=c.sent(),[3,5];case 4:throw c.sent(),n="Failed to parse model JSON of response from "+this.path+".",this.path.endsWith(".pb")?n+=" Your path contains a .pb file extension. Support for .pb models have been removed in TensorFlow.js 1.0 in favor of .json models. You can re-convert your Python TensorFlow model using the TensorFlow.js 1.0 conversion scripts or you can convert your.pb models with the 'pb2json'NPM script in the tensorflow/tfjs-converter repository.":n+=" Please make sure the server is serving valid JSON for this request.",new Error(n);case 5:if(r=e.modelTopology,i=e.weightsManifest,a=e.generatedBy,o=e.convertedBy,s=e.format,u=e.userDefinedMetadata,null==r&&null==i)throw new Error("The JSON from HTTP path "+this.path+" contains neither model topology or manifest for weights.");return null==i?[3,7]:[4,this.loadWeights(i)];case 6:d=c.sent(),l=d[0],f=d[1],c.label=7;case 7:return[2,{modelTopology:r,weightSpecs:l,weightData:f,userDefinedMetadata:u,generatedBy:a,convertedBy:o,format:s}]}})})},t.prototype.loadWeights=function(t){return u(this,void 0,void 0,function(){var e,n,r,i,a,o,s,u,l,f,d;return c(this,function(c){switch(c.label){case 0:for(e=Array.isArray(this.path)?this.path[1]:this.path,n=function(t){var e=t.lastIndexOf("/"),n=t.lastIndexOf("?");return[t.substring(0,e)+"/",n>e?t.substring(n):""]}(e),r=n[0],i=n[1],a=this.weightPathPrefix||r,o=[],s=0,u=t;s<u.length;s++)l=u[s],o.push.apply(o,l.weights);return f=[],t.forEach(function(t){t.paths.forEach(function(t){f.push(a+t+i)})}),[4,Nf(f,{requestInit:this.requestInit,fetchFunc:this.fetch,onProgress:this.onProgress})];case 1:return d=c.sent(),[2,[o,Kl(d)]]}})})},t.URL_SCHEME_REGEX=/^https?:\/\//,t}();function Df(t){return null!=t.match(If.URL_SCHEME_REGEX)}var Mf=function(t,e){return"undefined"==typeof fetch?null:(Array.isArray(t)?t.every(function(t){return Df(t)}):Df(t))?Rf(t,{onProgress:e}):null};function Rf(t,e){return new If(t,e)}Jl.registerSaveRouter(Mf),Jl.registerLoadRouter(Mf);var Ff,jf=function(){function t(t){this.modelArtifacts=t}return t.prototype.load=function(){return u(this,void 0,void 0,function(){return c(this,function(t){return[2,this.modelArtifacts]})})},t}(),Pf=function(){function t(t){this.saveHandler=t}return t.prototype.save=function(t){return u(this,void 0,void 0,function(){return c(this,function(e){return[2,this.saveHandler(t)]})})},t}(),Lf=Object.freeze({browserFiles:function(t){return new Cf(t)},browserHTTPRequest:function(t,e){return Rf(t,e)},concatenateArrayBuffers:Kl,decodeWeights:Hl,encodeWeights:function(t,e){return u(this,void 0,void 0,function(){var n,r,i,a,o,s=this;return c(this,function(l){switch(l.label){case 0:for(n=[],r=[],i=Array.isArray(t)?t.map(function(t){return t.name}):Object.keys(t),a=function(a){var o=i[a],l=Array.isArray(t)?t[a].tensor:t[o];if("float32"!==l.dtype&&"int32"!==l.dtype&&"bool"!==l.dtype&&"string"!==l.dtype)throw new Error("Unsupported dtype in weight '"+o+"': "+l.dtype);var f={name:o,shape:l.shape,dtype:l.dtype};if("string"===l.dtype){var d=new Promise(function(t){return u(s,void 0,void 0,function(){var e,n,r,i,a,o,s;return c(this,function(u){switch(u.label){case 0:return[4,l.bytes()];case 1:for(e=u.sent(),n=e.reduce(function(t,e){return t+e.length},0)+ql*e.length,r=new Uint8Array(n),i=0,a=0;a<e.length;a++)o=e[a],s=new Uint8Array(new Uint32Array([o.length]).buffer),r.set(s,i),i+=ql,r.set(o,i),i+=o.length;return t(r),[2]}})})});r.push(d)}else r.push(l.data());null!=e&&(f.group=e),n.push(f)},o=0;o<i.length;++o)a(o);return[4,Promise.all(r)];case 1:return[2,{data:function(t){if(null===t)throw new Error("Invalid input value: "+JSON.stringify(t));var e=0,n=[];t.forEach(function(t){if(e+=t.byteLength,n.push(t.byteLength===t.buffer.byteLength?t:new t.constructor(t)),!(t instanceof Float32Array||t instanceof Int32Array||t instanceof Uint8Array))throw new Error("Unsupported TypedArray subtype: "+t.constructor.name)});var r=new Uint8Array(e),i=0;return n.forEach(function(t){r.set(new Uint8Array(t.buffer),i),i+=t.byteLength}),r.buffer}(l.sent()),specs:n}]}})})},fromMemory:function(t,e,n,r){return 1===arguments.length?null!=t.modelTopology||null!=t.weightSpecs?new jf(t):(console.warn("Please call tf.io.fromMemory() with only one argument. The argument should be of type ModelArtifacts. The multi-argument signature of tf.io.fromMemory() has been deprecated and will be removed in a future release."),new jf({modelTopology:t})):(console.warn("Please call tf.io.fromMemory() with only one argument. The argument should be of type ModelArtifacts. The multi-argument signature of tf.io.fromMemory() has been deprecated and will be removed in a future release."),new jf({modelTopology:t,weightSpecs:e,weightData:n,trainingConfig:r}))},getLoadHandlers:function(t,e){return Jl.getLoadHandlers(t,e)},getModelArtifactsInfoForJSON:Yl,getSaveHandlers:function(t){return Jl.getSaveHandlers(t)},http:Rf,isHTTPScheme:Df,loadWeights:function(t,e,n,r){return void 0===e&&(e=""),u(this,void 0,void 0,function(){return c(this,function(i){return[2,Tf(function(t){return Nf(t,{requestInit:r})})(t,e,n)]})})},registerLoadRouter:function(t){return Jl.registerLoadRouter(t)},registerSaveRouter:function(t){return Jl.registerSaveRouter(t)},weightsLoaderFactory:Tf,withSaveHandler:function(t){return new Pf(t)},copyModel:function(t,e){return u(this,void 0,void 0,function(){return c(this,function(n){return[2,ef(t,e,!1)]})})},listModels:function(){return u(this,void 0,void 0,function(){var t,e,n,r,i,a,o;return c(this,function(s){switch(s.label){case 0:t=Ql.getSchemes(),e={},n=0,r=t,s.label=1;case 1:return n<r.length?(i=r[n],[4,Ql.getManager(i).listModels()]):[3,4];case 2:for(o in a=s.sent())e[i+Zl+o]=a[o];s.label=3;case 3:return n++,[3,1];case 4:return[2,e]}})})},moveModel:function(t,e){return u(this,void 0,void 0,function(){return c(this,function(n){return[2,ef(t,e,!0)]})})},removeModel:function(t){return u(this,void 0,void 0,function(){var e;return c(this,function(n){return e=tf(t),[2,Ql.getManager(e.scheme).removeModel(e.path)]})})}}),zf=Dn({confusionMatrix_:function(t,e,n){var r=xn(t,"labels","confusionMatrix"),i=xn(e,"predictions","confusionMatrix");C(null==n||n>0&&Number.isInteger(n),function(){return"If provided, numClasses must be a positive integer, but got "+n}),C(1===r.rank,function(){return"Expected the rank of labels to be 1, but got "+r.rank}),C(1===i.rank,function(){return"Expected the rank of predictions to be 1, but got "+i.rank}),C(r.shape[0]===i.shape[0],function(){return"Mismatch in the number of examples: "+r.shape[0]+" vs. "+i.shape[0]+". Labels and predictions should have the same number of elements."}),C(n>0&&Number.isInteger(n),function(){return"numClasses is required to be a positive integer, but got "+n});var a=Ar(r.asType("int32"),n),o=Ar(i.asType("int32"),n);return a.transpose().matMul(o).asType("int32")}}),Bf=Object.freeze({confusionMatrix:zf}),Uf=Dn({fromPixels_:function(t,e){if(void 0===e&&(e=3),e>4)throw new Error("Cannot construct Tensor with more than 4 channels from pixels.");if(null==t)throw new Error("pixels passed to tf.browser.fromPixels() can not be null");var n=!1,r=!1,i=!1,a=!1,o=!1;if(t.data instanceof Uint8Array)n=!0;else if("undefined"!=typeof ImageData&&t instanceof ImageData)r=!0;else if("undefined"!=typeof HTMLVideoElement&&t instanceof HTMLVideoElement)i=!0;else if("undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement)a=!0;else{if(null==t.getContext)throw new Error("pixels passed to tf.browser.fromPixels() must be either an HTMLVideoElement, HTMLImageElement, HTMLCanvasElement, ImageData in browser, or OffscreenCanvas, ImageData in webworker or {data: Uint32Array, width: number, height: number}, but was "+t.constructor.name);o=!0}if(i&&i&&t.readyState<2)throw new Error("The video element has not loaded data yet. Please wait for `loadeddata` event on the <video> element.");if(null!=m("FromPixels",Wt.backendName))return Wt.runKernel("FromPixels",{pixels:t},{numChannels:e});var s,u,c=i?[t.videoWidth,t.videoHeight]:[t.width,t.height],l=c[0],f=c[1];if(o?s=t.getContext("2d").getImageData(0,0,l,f).data:r||n?s=t.data:(a||i)&&(null==Ff&&(Ff=document.createElement("canvas").getContext("2d")),Ff.canvas.width=l,Ff.canvas.height=f,Ff.drawImage(t,0,0,l,f),s=Ff.getImageData(0,0,l,f).data),4===e)u=new Int32Array(s);else{var d=l*f;u=new Int32Array(d*e);for(var h=0;h<d;h++)for(var p=0;p<e;++p)u[h*e+p]=s[4*h+p]}return Un(u,[f,l,e],"int32")}}),Wf=Object.freeze({toPixels:function(t,e){return u(this,void 0,void 0,function(){var n,r,i,a,o,s,u,l,f,d,h,p,m,g,v,y,b,x,w,k,_,E,O;return c(this,function(c){switch(c.label){case 0:if(n=xn(t,"img","toPixels"),t instanceof Ot||(n=n.toInt()),2!==n.rank&&3!==n.rank)throw new Error("toPixels only supports rank 2 or 3 tensors, got rank "+n.rank+".");if(r=n.shape.slice(0,2),i=r[0],a=r[1],(o=2===n.rank?1:n.shape[2])>4||2===o)throw new Error("toPixels only supports depth of size 1, 3 or 4 but got "+o);return[4,n.data()];case 1:return s=c.sent(),u=n.min(),l=n.max(),[4,Promise.all([u.data(),l.data()])];case 2:if(f=c.sent(),d=f[0],h=f[1],p=d[0],m=h[0],u.dispose(),l.dispose(),"float32"===n.dtype){if(p<0||m>1)throw new Error("Tensor values for a float32 Tensor must be in the range [0 - 1] but got range ["+p+" - "+m+"].")}else{if("int32"!==n.dtype)throw new Error("Unsupported type for toPixels: "+n.dtype+". Please use float32 or int32 tensors.");if(p<0||m>255)throw new Error("Tensor values for a int32 Tensor must be in the range [0 - 255] but got range ["+p+" - "+m+"].")}for(g="float32"===n.dtype?255:1,v=new Uint8ClampedArray(a*i*4),y=0;y<i*a;++y)b=void 0,x=void 0,w=void 0,k=void 0,1===o?(b=s[y]*g,x=s[y]*g,w=s[y]*g,k=255):3===o?(b=s[3*y]*g,x=s[3*y+1]*g,w=s[3*y+2]*g,k=255):4===o&&(b=s[4*y]*g,x=s[4*y+1]*g,w=s[4*y+2]*g,k=s[4*y+3]*g),v[0+(_=4*y)]=Math.round(b),v[_+1]=Math.round(x),v[_+2]=Math.round(w),v[_+3]=Math.round(k);return null!=e&&(e.width=a,e.height=i,E=e.getContext("2d"),O=new ImageData(v,a,i),E.putImageData(O,0,0)),n!==t&&n.dispose(),[2,v]}})})},fromPixels:Uf}),Vf=function(){function t(){}return t.prototype.getClassName=function(){return this.constructor.className},t.fromConfig=function(t,e){return new t(e)},t}(),qf=function(){function t(){this.classNameMap={}}return t.getMap=function(){return null==t.instance&&(t.instance=new t),t.instance},t.register=function(e){t.getMap().classNameMap[e.className]=[e,e.fromConfig]},t}();function Hf(t){C(null!=t.className,function(){return"Class being registered does not have the static className property defined."}),C("string"==typeof t.className,function(){return"className is required to be a string, but got type "+typeof t.className}),C(t.className.length>0,function(){return"Class being registered has an empty-string as its className, which is disallowed."}),qf.register(t)}var Gf=Object.freeze({Serializable:Vf,SerializationMap:qf,registerClass:Hf}),$f=.001,Kf=.1;function Xf(){return 32===Wt.backend.floatPrecision()?$f:Kf}function Yf(t,e,n){var r=!0;if((G(t)||G(e))&&(r=!1),G(t)&&G(e)&&(r=!0),r){var i=t.constructor.name,a=e.constructor.name;if(i!==a)throw new Error("Arrays are of different type. Actual: "+i+". Expected: "+a)}if(Array.isArray(t)&&Array.isArray(e)){var o=yn(t),s=yn(e);if(!D(o,s))throw new Error("Arrays have different shapes. Actual: ["+o+"]. Expected: ["+s+"]")}var u=G(t)?t:T(t),c=G(e)?e:T(e);if(u.length!==c.length)throw new Error("Arrays have different lengths actual: "+u.length+" vs expected: "+c.length+".\nActual: "+u+".\nExpected: "+c+".");for(var l=0;l<c.length;++l){var f=u[l],d=c[l];if(!n(f,d))throw new Error("Arrays differ: actual["+l+"] = "+f+", expected["+l+"] = "+d+".\nActual: "+u+".\nExpected: "+c+".")}}function Jf(t,e,n){return!isFinite(t)&&!isFinite(e)||!(isNaN(t)||isNaN(e)||Math.abs(t-e)>n)}var Zf=Object.freeze({TEST_EPSILON_FLOAT16:Kf,expectArraysClose:function(t,e,n){return null==n&&(n=Xf()),Yf(t,e,function(t,e){return Jf(t,e,n)})},testEpsilon:Xf,expectPromiseToFail:function(t,e){t().then(function(){return e.fail()},function(){return e()})},expectArraysEqual:function(t,e){var n="string"==typeof e||"number"==typeof e||"boolean"==typeof e?[e]:e;return X(t)||X(t[0])||X(e)||X(e[0])?Yf(t,n,function(t,e){return t==e}):Yf(t,e,function(t,e){return Jf(t,e,0)})},expectNumbersClose:function(t,e,n){if(null==n&&(n=Xf()),!Jf(t,e,n))throw new Error("Numbers differ: actual === "+t+", expected === "+e)},expectValuesInRange:function(t,e,n){for(var r=0;r<t.length;r++)if(t[r]<e||t[r]>n)throw new Error("Value out of range:"+t[r]+" low: "+e+", high: "+n)},expectArrayBuffersEqual:function(t,e){expect(new Float32Array(t)).toEqual(new Float32Array(e))}}),Qf="1.7.0",td=Object.freeze({gpgpu_util:ro,webgl_util:$e,forceHalfFloat:function(){f().set("WEBGL_FORCE_F16_TEXTURES",!0)},MathBackendWebGL:Uo,setWebGLContext:Yt,GPGPUContext:io}),ed=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return s(e,t),e.prototype.minimize=function(t,e,n){void 0===e&&(e=!1);var r=this.computeGradients(t,n),i=r.value,a=r.grads;if(null!=n){var o=n.map(function(t){return{name:t.name,tensor:a[t.name]}});this.applyGradients(o)}else this.applyGradients(a);return an(a),e?i:(i.dispose(),null)},Object.defineProperty(e.prototype,"iterations",{get:function(){return null==this.iterations_&&(this.iterations_=0),this.iterations_},enumerable:!0,configurable:!0}),e.prototype.incrementIterations=function(){this.iterations_=this.iterations+1},e.prototype.computeGradients=function(t,e){return vi(t,e)},e.prototype.dispose=function(){null!=this.iterations_&&an(this.iterations_)},e.prototype.saveIterations=function(){return u(this,void 0,void 0,function(){return c(this,function(t){return null==this.iterations_&&(this.iterations_=0),[2,{name:"iter",tensor:Ln(this.iterations_,"int32")}]})})},e.prototype.getWeights=function(){return u(this,void 0,void 0,function(){return c(this,function(t){throw new Error("getWeights() is not implemented for this optimizer yet.")})})},e.prototype.setWeights=function(t){return u(this,void 0,void 0,function(){return c(this,function(t){throw new Error("setWeights() is not implemented for this optimizer class "+this.getClassName())})})},e.prototype.extractIterations=function(t){return u(this,void 0,void 0,function(){var e;return c(this,function(n){switch(n.label){case 0:return e=this,[4,t[0].tensor.data()];case 1:return e.iterations_=n.sent()[0],[2,t.slice(1)]}})})},e}(Vf);Object.defineProperty(ed,Symbol.hasInstance,{value:function(t){return null!=t.minimize&&null!=t.computeGradients&&null!=t.applyGradients}});var nd=function(t){function e(e,n,r){void 0===r&&(r=null);var i=t.call(this)||this;return i.learningRate=e,i.rho=n,i.epsilon=r,i.accumulatedGrads=[],i.accumulatedUpdates=[],null==r&&(i.epsilon=Wt.backend.epsilon()),i}return s(e,t),e.prototype.applyGradients=function(t){var e=this;(Array.isArray(t)?t.map(function(t){return t.name}):Object.keys(t)).forEach(function(n,r){var i=Wt.registeredVariables[n];null==e.accumulatedGrads[r]&&(e.accumulatedGrads[r]={originalName:n+"/accum_grad",variable:rn(function(){return Zn(i).variable(!1)})}),null==e.accumulatedUpdates[r]&&(e.accumulatedUpdates[r]={originalName:n+"/accum_var",variable:rn(function(){return Zn(i).variable(!1)})});var a=Array.isArray(t)?t[r].tensor:t[n];if(null!=a){var o=e.accumulatedGrads[r].variable,s=e.accumulatedUpdates[r].variable;rn(function(){var t=o.mul(e.rho).add(a.square().mul(1-e.rho)),n=s.add(e.epsilon).sqrt().div(o.add(e.epsilon).sqrt()).mul(a),r=s.mul(e.rho).add(n.square().mul(1-e.rho));o.assign(t),s.assign(r);var u=n.mul(-e.learningRate).add(i);i.assign(u)})}}),this.incrementIterations()},e.prototype.dispose=function(){null!=this.accumulatedUpdates&&(an(this.accumulatedGrads.map(function(t){return t.variable})),an(this.accumulatedUpdates.map(function(t){return t.variable})))},e.prototype.getWeights=function(){return u(this,void 0,void 0,function(){var t;return c(this,function(e){switch(e.label){case 0:return t=this.accumulatedGrads.concat(this.accumulatedUpdates),[4,this.saveIterations()];case 1:return[2,[e.sent()].concat(t.map(function(t){return{name:t.originalName,tensor:t.variable}}))]}})})},e.prototype.setWeights=function(t){return u(this,void 0,void 0,function(){var e;return c(this,function(n){switch(n.label){case 0:return[4,this.extractIterations(t)];case 1:return t=n.sent(),e=t.length/2,this.accumulatedGrads=t.slice(0,e).map(function(t){return{originalName:t.name,variable:t.tensor.variable(!1)}}),this.accumulatedUpdates=t.slice(e,2*e).map(function(t){return{originalName:t.name,variable:t.tensor.variable(!1)}}),[2]}})})},e.prototype.getConfig=function(){return{learningRate:this.learningRate,rho:this.rho,epsilon:this.epsilon}},e.fromConfig=function(t,e){return new t(e.learningRate,e.rho,e.epsilon)},e.className="Adadelta",e}(ed);Hf(nd);var rd=function(t){function e(e,n){void 0===n&&(n=.1);var r=t.call(this)||this;return r.learningRate=e,r.initialAccumulatorValue=n,r.accumulatedGrads=[],r}return s(e,t),e.prototype.applyGradients=function(t){var e=this;(Array.isArray(t)?t.map(function(t){return t.name}):Object.keys(t)).forEach(function(n,r){var i=Wt.registeredVariables[n];null==e.accumulatedGrads[r]&&(e.accumulatedGrads[r]={originalName:n+"/accumulator",variable:rn(function(){return Kn(i.shape,e.initialAccumulatorValue).variable(!1)})});var a=Array.isArray(t)?t[r].tensor:t[n];if(null!=a){var o=e.accumulatedGrads[r].variable;rn(function(){var t=o.add(a.square());o.assign(t);var n=a.div(t.add(Wt.backend.epsilon()).sqrt()).mul(-e.learningRate).add(i);i.assign(n)})}}),this.incrementIterations()},e.prototype.dispose=function(){null!=this.accumulatedGrads&&an(this.accumulatedGrads.map(function(t){return t.variable}))},e.prototype.getWeights=function(){return u(this,void 0,void 0,function(){return c(this,function(t){switch(t.label){case 0:return[4,this.saveIterations()];case 1:return[2,[t.sent()].concat(this.accumulatedGrads.map(function(t){return{name:t.originalName,tensor:t.variable}}))]}})})},e.prototype.setWeights=function(t){return u(this,void 0,void 0,function(){return c(this,function(e){switch(e.label){case 0:return[4,this.extractIterations(t)];case 1:return t=e.sent(),this.accumulatedGrads=t.map(function(t){return{originalName:t.name,variable:t.tensor.variable(!1)}}),[2]}})})},e.prototype.getConfig=function(){return{learningRate:this.learningRate,initialAccumulatorValue:this.initialAccumulatorValue}},e.fromConfig=function(t,e){return new t(e.learningRate,e.initialAccumulatorValue)},e.className="Adagrad",e}(ed);Hf(rd);var id=function(t){function e(e,n,r,i){void 0===i&&(i=null);var a=t.call(this)||this;return a.learningRate=e,a.beta1=n,a.beta2=r,a.epsilon=i,a.accumulatedFirstMoment=[],a.accumulatedSecondMoment=[],rn(function(){a.accBeta1=Ln(n).variable(),a.accBeta2=Ln(r).variable()}),null==i&&(a.epsilon=Wt.backend.epsilon()),a}return s(e,t),e.prototype.applyGradients=function(t){var e=this,n=Array.isArray(t)?t.map(function(t){return t.name}):Object.keys(t);rn(function(){var r=lu(1,e.accBeta1),i=lu(1,e.accBeta2);n.forEach(function(n,a){var o=Wt.registeredVariables[n];null==e.accumulatedFirstMoment[a]&&(e.accumulatedFirstMoment[a]={originalName:n+"/m",variable:rn(function(){return Zn(o).variable(!1)})}),null==e.accumulatedSecondMoment[a]&&(e.accumulatedSecondMoment[a]={originalName:n+"/v",variable:rn(function(){return Zn(o).variable(!1)})});var s=Array.isArray(t)?t[a].tensor:t[n];if(null!=s){var u=e.accumulatedFirstMoment[a].variable,c=e.accumulatedSecondMoment[a].variable,l=u.mul(e.beta1).add(s.mul(1-e.beta1)),f=c.mul(e.beta2).add(s.square().mul(1-e.beta2)),d=l.div(r),h=f.div(i);u.assign(l),c.assign(f);var p=d.div(h.sqrt().add(e.epsilon)).mul(-e.learningRate).add(o);o.assign(p)}}),e.accBeta1.assign(e.accBeta1.mul(e.beta1)),e.accBeta2.assign(e.accBeta2.mul(e.beta2))}),this.incrementIterations()},e.prototype.dispose=function(){this.accBeta1.dispose(),this.accBeta2.dispose(),null!=this.accumulatedFirstMoment&&an(this.accumulatedFirstMoment.map(function(t){return t.variable})),null!=this.accumulatedSecondMoment&&an(this.accumulatedSecondMoment.map(function(t){return t.variable}))},e.prototype.getWeights=function(){return u(this,void 0,void 0,function(){var t;return c(this,function(e){switch(e.label){case 0:return t=this.accumulatedFirstMoment.concat(this.accumulatedSecondMoment),[4,this.saveIterations()];case 1:return[2,[e.sent()].concat(t.map(function(t){return{name:t.originalName,tensor:t.variable}}))]}})})},e.prototype.setWeights=function(t){return u(this,void 0,void 0,function(){var e,n=this;return c(this,function(r){switch(r.label){case 0:return[4,this.extractIterations(t)];case 1:return t=r.sent(),rn(function(){n.accBeta1.assign(su(n.beta1,n.iterations_+1)),n.accBeta2.assign(su(n.beta2,n.iterations_+1))}),e=t.length/2,this.accumulatedFirstMoment=t.slice(0,e).map(function(t){return{originalName:t.name,variable:t.tensor.variable(!1)}}),this.accumulatedSecondMoment=t.slice(e,2*e).map(function(t){return{originalName:t.name,variable:t.tensor.variable(!1)}}),[2]}})})},e.prototype.getConfig=function(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon}},e.fromConfig=function(t,e){return new t(e.learningRate,e.beta1,e.beta2,e.epsilon)},e.className="Adam",e}(ed);Hf(id);var ad=function(t){function e(e,n,r,i,a){void 0===i&&(i=null),void 0===a&&(a=0);var o=t.call(this)||this;return o.learningRate=e,o.beta1=n,o.beta2=r,o.epsilon=i,o.decay=a,o.accumulatedFirstMoment=[],o.accumulatedWeightedInfNorm=[],rn(function(){o.iteration=Ln(0).variable(),o.accBeta1=Ln(n).variable()}),null==i&&(o.epsilon=Wt.backend.epsilon()),o}return s(e,t),e.prototype.applyGradients=function(t){var e=this,n=Array.isArray(t)?t.map(function(t){return t.name}):Object.keys(t);rn(function(){var r=lu(1,e.accBeta1),i=Xs(-e.learningRate,e.iteration.mul(e.decay).add(1));n.forEach(function(n,a){var o=Wt.registeredVariables[n];null==e.accumulatedFirstMoment[a]&&(e.accumulatedFirstMoment[a]={originalName:n+"/m",variable:Zn(o).variable(!1)}),null==e.accumulatedWeightedInfNorm[a]&&(e.accumulatedWeightedInfNorm[a]={originalName:n+"/v",variable:Zn(o).variable(!1)});var s=Array.isArray(t)?t[a].tensor:t[n];if(null!=s){var u=e.accumulatedFirstMoment[a].variable,c=e.accumulatedWeightedInfNorm[a].variable,l=u.mul(e.beta1).add(s.mul(1-e.beta1)),f=c.mul(e.beta2),d=s.abs(),h=f.maximum(d);u.assign(l),c.assign(h);var p=i.div(r).mul(l.div(h.add(e.epsilon))).add(o);o.assign(p)}}),e.iteration.assign(e.iteration.add(1)),e.accBeta1.assign(e.accBeta1.mul(e.beta1))}),this.incrementIterations()},e.prototype.dispose=function(){this.accBeta1.dispose(),this.iteration.dispose(),null!=this.accumulatedFirstMoment&&an(this.accumulatedFirstMoment.map(function(t){return t.variable})),null!=this.accumulatedWeightedInfNorm&&an(this.accumulatedWeightedInfNorm.map(function(t){return t.variable}))},e.prototype.getWeights=function(){return u(this,void 0,void 0,function(){return c(this,function(t){throw new Error("getWeights() is not implemented for Adamax yet.")})})},e.prototype.setWeights=function(t){return u(this,void 0,void 0,function(){return c(this,function(t){throw new Error("setWeights() is not implemented for Adamax yet.")})})},e.prototype.getConfig=function(){return{learningRate:this.learningRate,beta1:this.beta1,beta2:this.beta2,epsilon:this.epsilon,decay:this.decay}},e.fromConfig=function(t,e){return new t(e.learningRate,e.beta1,e.beta2,e.epsilon,e.decay)},e.className="Adamax",e}(ed);Hf(ad);var od=function(t){function e(e){var n=t.call(this)||this;return n.learningRate=e,n.setLearningRate(e),n}return s(e,t),e.prototype.applyGradients=function(t){var e=this;(Array.isArray(t)?t.map(function(t){return t.name}):Object.keys(t)).forEach(function(n,r){var i=Array.isArray(t)?t[r].tensor:t[n];if(null!=i){var a=Wt.registeredVariables[n];rn(function(){var t=e.c.mul(i).add(a);a.assign(t)})}}),this.incrementIterations()},e.prototype.setLearningRate=function(t){this.learningRate=t,null!=this.c&&this.c.dispose(),this.c=on(Ln(-t))},e.prototype.dispose=function(){this.c.dispose()},e.prototype.getWeights=function(){return u(this,void 0,void 0,function(){return c(this,function(t){switch(t.label){case 0:return[4,this.saveIterations()];case 1:return[2,[t.sent()]]}})})},e.prototype.setWeights=function(t){return u(this,void 0,void 0,function(){return c(this,function(e){switch(e.label){case 0:return[4,this.extractIterations(t)];case 1:if(0!==(t=e.sent()).length)throw new Error("SGD optimizer does not have settable weights.");return[2]}})})},e.prototype.getConfig=function(){return{learningRate:this.learningRate}},e.fromConfig=function(t,e){return new t(e.learningRate)},e.className="SGD",e}(ed);Hf(od);var sd=function(t){function e(e,n,r){void 0===r&&(r=!1);var i=t.call(this,e)||this;return i.learningRate=e,i.momentum=n,i.useNesterov=r,i.accumulations=[],i.m=Ln(i.momentum),i}return s(e,t),e.prototype.applyGradients=function(t){var e=this;(Array.isArray(t)?t.map(function(t){return t.name}):Object.keys(t)).forEach(function(n,r){var i=Wt.registeredVariables[n];null==e.accumulations[r]&&(e.accumulations[r]={originalName:n+"/momentum",variable:rn(function(){return Zn(i).variable(!1)})});var a=e.accumulations[r].variable,o=Array.isArray(t)?t[r].tensor:t[n];null!=o&&rn(function(){var t,n=e.m.mul(a).add(o);t=e.useNesterov?e.c.mul(o.add(n.mul(e.m))).add(i):e.c.mul(n).add(i),a.assign(n),i.assign(t)})}),this.incrementIterations()},e.prototype.dispose=function(){this.m.dispose(),null!=this.accumulations&&an(this.accumulations.map(function(t){return t.variable}))},e.prototype.setMomentum=function(t){this.momentum=t},e.prototype.getWeights=function(){return u(this,void 0,void 0,function(){return c(this,function(t){switch(t.label){case 0:return[4,this.saveIterations()];case 1:return[2,[t.sent()].concat(this.accumulations.map(function(t){return{name:t.originalName,tensor:t.variable}}))]}})})},e.prototype.setWeights=function(t){return u(this,void 0,void 0,function(){return c(this,function(e){switch(e.label){case 0:return[4,this.extractIterations(t)];case 1:return t=e.sent(),this.accumulations=t.map(function(t){return{originalName:t.name,variable:t.tensor.variable(!1)}}),[2]}})})},e.prototype.getConfig=function(){return{learningRate:this.learningRate,momentum:this.momentum,useNesterov:this.useNesterov}},e.fromConfig=function(t,e){return new t(e.learningRate,e.momentum,e.useNesterov)},e.className="Momentum",e}(od);Hf(sd);var ud=function(t){function e(e,n,r,i,a){void 0===n&&(n=.9),void 0===r&&(r=0),void 0===i&&(i=null),void 0===a&&(a=!1);var o=t.call(this)||this;if(o.learningRate=e,o.decay=n,o.momentum=r,o.epsilon=i,o.accumulatedMeanSquares=[],o.accumulatedMoments=[],o.accumulatedMeanGrads=[],o.centered=a,null==i&&(o.epsilon=Wt.backend.epsilon()),null==e)throw new Error("learningRate for RMSPropOptimizer must be defined.");return o}return s(e,t),e.prototype.applyGradients=function(t){var e=this;(Array.isArray(t)?t.map(function(t){return t.name}):Object.keys(t)).forEach(function(n,r){var i=Wt.registeredVariables[n];null==e.accumulatedMeanSquares[r]&&(e.accumulatedMeanSquares[r]={originalName:n+"/rms",variable:rn(function(){return Zn(i).variable(!1)})}),null==e.accumulatedMoments[r]&&(e.accumulatedMoments[r]={originalName:n+"/momentum",variable:rn(function(){return Zn(i).variable(!1)})}),null==e.accumulatedMeanGrads[r]&&e.centered&&(e.accumulatedMeanGrads[r]={originalName:n+"/mg",variable:rn(function(){return Zn(i).variable(!1)})});var a=Array.isArray(t)?t[r].tensor:t[n];if(null!=a){var o=e.accumulatedMeanSquares[r].variable,s=e.accumulatedMoments[r].variable;rn(function(){var t=o.mul(e.decay).add(a.square().mul(1-e.decay));if(e.centered){var n=e.accumulatedMeanGrads[r].variable,u=n.mul(e.decay).add(a.mul(1-e.decay)),c=s.mul(e.momentum).add(a.mul(e.learningRate).div(t.sub(u.square().add(e.epsilon)).sqrt()));o.assign(t),n.assign(u),s.assign(c);var l=i.sub(c);i.assign(l)}else{var f=o.mul(e.decay).add(a.square().mul(1-e.decay));c=s.mul(e.momentum).add(a.mul(e.learningRate).div(f.add(e.epsilon).sqrt())),o.assign(f),s.assign(c),l=i.sub(c),i.assign(l)}})}}),this.incrementIterations()},e.prototype.dispose=function(){null!=this.accumulatedMeanSquares&&an(this.accumulatedMeanSquares.map(function(t){return t.variable})),null!=this.accumulatedMeanGrads&&this.centered&&an(this.accumulatedMeanGrads.map(function(t){return t.variable})),null!=this.accumulatedMoments&&an(this.accumulatedMoments.map(function(t){return t.variable}))},e.prototype.getWeights=function(){return u(this,void 0,void 0,function(){var t;return c(this,function(e){switch(e.label){case 0:return t=this.accumulatedMeanSquares.concat(this.accumulatedMoments),this.centered&&t.push.apply(t,this.accumulatedMeanGrads),[4,this.saveIterations()];case 1:return[2,[e.sent()].concat(t.map(function(t){return{name:t.originalName,tensor:t.variable}}))]}})})},e.prototype.setWeights=function(t){return u(this,void 0,void 0,function(){var e;return c(this,function(n){switch(n.label){case 0:return[4,this.extractIterations(t)];case 1:return t=n.sent(),e=this.centered?t.length/3:t.length/2,this.accumulatedMeanSquares=t.slice(0,e).map(function(t){return{originalName:t.name,variable:t.tensor.variable(!1)}}),this.accumulatedMoments=t.slice(e,2*e).map(function(t){return{originalName:t.name,variable:t.tensor.variable(!1)}}),this.centered&&(this.accumulatedMeanGrads=t.slice(2*e,3*e).map(function(t){return{originalName:t.name,variable:t.tensor.variable(!1)}})),[2]}})})},e.prototype.getConfig=function(){return{learningRate:this.learningRate,decay:this.decay,momentum:this.momentum,epsilon:this.epsilon,centered:this.centered}},e.fromConfig=function(t,e){return new t(e.learningRate,e.decay,e.momentum,e.epsilon,e.centered)},e.className="RMSProp",e}(ed);Hf(ud);var cd=function(){function t(){}return t.sgd=function(t){return new od(t)},t.momentum=function(t,e,n){return void 0===n&&(n=!1),new sd(t,e,n)},t.rmsprop=function(t,e,n,r,i){return void 0===e&&(e=.9),void 0===n&&(n=0),void 0===r&&(r=null),void 0===i&&(i=!1),new ud(t,e,n,r,i)},t.adam=function(t,e,n,r){return void 0===t&&(t=.001),void 0===e&&(e=.9),void 0===n&&(n=.999),void 0===r&&(r=null),new id(t,e,n,r)},t.adadelta=function(t,e,n){return void 0===t&&(t=.001),void 0===e&&(e=.95),void 0===n&&(n=null),new nd(t,e,n)},t.adamax=function(t,e,n,r,i){return void 0===t&&(t=.002),void 0===e&&(e=.9),void 0===n&&(n=.999),void 0===r&&(r=null),void 0===i&&(i=0),new ad(t,e,n,r,i)},t.adagrad=function(t,e){return void 0===e&&(e=.1),new rd(t,e)},t}(),ld={sgd:cd.sgd,momentum:cd.momentum,adadelta:cd.adadelta,adagrad:cd.adagrad,rmsprop:cd.rmsprop,adamax:cd.adamax,adam:cd.adam},fd="undefined"!=typeof requestAnimationFrame?requestAnimationFrame:void 0!==a?a:function(t){return t()};function dd(){return new Promise(function(t){return fd(function(){return t()})})}Ot.prototype.squaredDifference=function(t){return qo(this,t)},_t=Nl}.call(this,n(53),n(87),n(86).Buffer,n(244).setImmediate)},function(t,e,n){"use strict";n.d(e,"c",function(){return i}),n.d(e,"a",function(){return a}),n.d(e,"b",function(){return o}),n.d(e,"d",function(){return s}),n.d(e,"e",function(){return u});
  36. /*! *****************************************************************************
  37. Copyright (c) Microsoft Corporation. All rights reserved.
  38. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  39. this file except in compliance with the License. You may obtain a copy of the
  40. License at http://www.apache.org/licenses/LICENSE-2.0
  41. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  43. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  44. MERCHANTABLITY OR NON-INFRINGEMENT.
  45. See the Apache Version 2.0 License for specific language governing permissions
  46. and limitations under the License.
  47. ***************************************************************************** */
  48. var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function i(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var a=function(){return(a=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function o(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):function(t){return t instanceof n?t:new n(function(e){e(t)})}(t.value).then(o,s)}u((r=r.apply(t,e||[])).next())})}function s(t,e){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=(i=o.trys).length>0&&i[i.length-1])&&(6===a[0]||2===a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}function u(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var r=Array(t),i=0;for(e=0;e<n;e++)for(var a=arguments[e],o=0,s=a.length;o<s;o++,i++)r[i]=a[o];return r}},function(t,e,n){"use strict";n.r(e);var r=n(0),i=function(t,e){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};
  49. /**
  50. * @license
  51. * Copyright 2020 Google LLC. All Rights Reserved.
  52. * Licensed under the Apache License, Version 2.0 (the "License");
  53. * you may not use this file except in compliance with the License.
  54. * You may obtain a copy of the License at
  55. *
  56. * http://www.apache.org/licenses/LICENSE-2.0
  57. *
  58. * Unless required by applicable law or agreed to in writing, software
  59. * distributed under the License is distributed on an "AS IS" BASIS,
  60. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  61. * See the License for the specific language governing permissions and
  62. * limitations under the License.
  63. * =============================================================================
  64. */function a(t,e){function n(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var o,s=function(){return(s=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function u(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})}function c(t,e){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=(i=o.trys).length>0&&i[i.length-1])&&(6===a[0]||2===a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}function l(){return null==o&&(o=Object(r.backend)().epsilon()),o}var f=function(t){function e(n){var r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}return a(e,t),e}(Error),d=function(t){function e(n){var r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}return a(e,t),e}(Error),h=function(t){function e(n){var r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}return a(e,t),e}(Error),p=function(t){function e(n){var r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}return a(e,t),e}(Error),m=function(t){function e(n){var r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}return a(e,t),e}(Error);!function(t){function e(n){var r=t.call(this,n)||this;return Object.setPrototypeOf(r,e.prototype),r}a(e,t)}(Error);function g(t,e){if(Array.isArray(t)){for(var n=[],r=0;r<e;r++)n=n.concat(t);return n}return(n=new Array(e)).fill(t),n}function v(t,e){if(!t)throw new m(e)}function y(t,e){for(var n=0,r=0,i=t;r<i.length;r++)i[r]===e&&n++;return n}function b(t){return 1===t.length?t[0]:t}function x(t){return Array.isArray(t)?t:[t]}function w(t){var e=t.replace(/(.)([A-Z][a-z0-9]+)/g,"$1_$2").replace(/([a-z])([A-Z])/g,"$1_$2").toLowerCase();return"_"!==e[0]?e:"private"+e}function k(t){return t.length<=1?t:-1===t.indexOf("_")?t:t.replace(/[_]+(\w|$)/g,function(t,e){return e.toUpperCase()})}var _={};function E(t){if(null===t||void 0===t)return null;var e={};return e.className=t.getClassName(),e.config=t.getConfig(),e}function O(t,e,n,r,i){var a,o,u;if(void 0===e&&(e={}),void 0===n&&(n={}),void 0===r&&(r="object"),void 0===i&&(i=!1),"string"==typeof t){var c=t,l=void 0;if(c in n)l=n[c];else if(c in _)l=_[c];else if(null==(l=e[c]))throw new h("Unknown "+r+": "+t+". This may be due to one of the following reasons:\n1. The "+r+" is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.\n2. The custom "+r+" is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().");return l}var f=t;if(null==f.className||null==f.config)throw new h(r+": Improper config format: "+JSON.stringify(f)+".\n'className' and 'config' must set.");var d=f.className,p=void 0,m=void 0;if(d in n?(p=(a=n[d])[0],m=a[1]):d in _?(p=(o=_.className)[0],m=o[1]):d in e&&(p=(u=e[d])[0],m=u[1]),null==p)throw new h("Unknown "+r+": "+d+". This may be due to one of the following reasons:\n1. The "+r+" is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.\n2. The custom "+r+" is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().");if(null!=m){for(var g={},v=0,y=Object.keys(_);v<y.length;v++)g[O=y[v]]=_[O];for(var b=0,x=Object.keys(n);b<x.length;b++)g[O=x[b]]=n[O];f.config.customObjects=g;for(var w=s({},_),k=0,E=Object.keys(n);k<E.length;k++){var O=E[k];_[O]=n[O]}!function t(e){if(null!=e&&"object"==typeof e)if(Array.isArray(e))e.forEach(function(e){return t(e)});else for(var n=0,r=Object.keys(e);n<r.length;n++){var i=r[n],a=e[i];null!=a&&"object"==typeof a&&(Array.isArray(a)||"ndarray"!==a.type||"number"!=typeof a.value?t(a):e[i]=a.value)}}(f.config);var S=m(p,f.config,n,i);return _=s({},w),S}w=s({},_);for(var C=0,A=Object.keys(n);C<A.length;C++)O=A[C],_[O]=n[O];return S=new p(f.config),_=s({},w),S}function S(t,e){return-1*function(t,e){return t<e?-1:t>e?1:0}(t,e)}function C(t){if(null==t)return t;for(var e=[],n=0,r=t;n<r.length;n++){var i=r[n];-1===e.indexOf(i)&&e.push(i)}return e}function A(t){if(null==t)throw new h("Invalid value in obj: "+JSON.stringify(t));for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}function N(t,e,n){if(null!=n&&t.indexOf(n)<0)throw new h(n+" is not a valid "+e+". Valid values are "+t+" or null/undefined.")}function T(t,e,n,r){return void 0===n&&(n=0),void 0===r&&(r=1/0),v(n>=0),v(r>=n),Array.isArray(t)&&t.length>=n&&t.length<=r&&t.every(function(t){return typeof t===e})}function I(t,e){Array.isArray(t)?(r.util.assert(t.length>0,function(){return e+" is unexpectedly an empty array."}),t.forEach(function(t,n){return I(t,"element "+(n+1)+" of "+e)})):r.util.assert(Number.isInteger(t)&&t>0,function(){return"Expected "+e+" to be a positive integer, but got "+function t(e){return null===e?"null":Array.isArray(e)?"["+e.map(function(e){return t(e)}).join(",")+"]":"string"==typeof e?'"'+e+'"':""+e}(t)+"."})}function D(t){return"relu"===t?"relu":"linear"===t?"linear":"elu"===t?"elu":null}function M(t,e){return Object(r.tidy)(function(){return Object(r.sqrt)(Object(r.sum)(Object(r.mulStrict)(t,t),e,!0))})}var R=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.getConfig=function(){return{}},e}(r.serialization.Serializable),F=function(t){function e(e){var n=t.call(this)||this;return n.defaultMaxValue=2,n.defaultAxis=0,n.maxValue=null!=e.maxValue?e.maxValue:n.defaultMaxValue,n.axis=null!=e.axis?e.axis:n.defaultAxis,n}return a(e,t),e.prototype.apply=function(t){var e=this;return Object(r.tidy)(function(){var n=M(t,e.axis),i=Object(r.clipByValue)(n,0,e.maxValue);return Object(r.mul)(t,Object(r.div)(i,Object(r.add)(l(),n)))})},e.prototype.getConfig=function(){return{maxValue:this.maxValue,axis:this.axis}},e.className="MaxNorm",e}(R);r.serialization.registerClass(F);var j=function(t){function e(e){var n=t.call(this)||this;return n.defaultAxis=0,n.axis=null!=e.axis?e.axis:n.defaultAxis,n}return a(e,t),e.prototype.apply=function(t){var e=this;return Object(r.tidy)(function(){return Object(r.div)(t,Object(r.add)(l(),M(t,e.axis)))})},e.prototype.getConfig=function(){return{axis:this.axis}},e.className="UnitNorm",e}(R);r.serialization.registerClass(j);var P=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.apply=function(t){return Object(r.relu)(t)},e.className="NonNeg",e}(R);r.serialization.registerClass(P);var L=function(t){function e(e){var n=t.call(this)||this;return n.defaultMinValue=0,n.defaultMaxValue=1,n.defaultRate=1,n.defaultAxis=0,n.minValue=null!=e.minValue?e.minValue:n.defaultMinValue,n.maxValue=null!=e.maxValue?e.maxValue:n.defaultMaxValue,n.rate=null!=e.rate?e.rate:n.defaultRate,n.axis=null!=e.axis?e.axis:n.defaultAxis,n}return a(e,t),e.prototype.apply=function(t){var e=this;return Object(r.tidy)(function(){var n=M(t,e.axis),i=Object(r.add)(Object(r.mul)(e.rate,Object(r.clipByValue)(n,e.minValue,e.maxValue)),Object(r.mul)(1-e.rate,n));return Object(r.mul)(t,Object(r.div)(i,Object(r.add)(l(),n)))})},e.prototype.getConfig=function(){return{minValue:this.minValue,maxValue:this.maxValue,rate:this.rate,axis:this.axis}},e.className="MinMaxNorm",e}(R);r.serialization.registerClass(L);var z={maxNorm:"MaxNorm",minMaxNorm:"MinMaxNorm",nonNeg:"NonNeg",unitNorm:"UnitNorm"};function B(t){return E(t)}function U(t,e){return void 0===e&&(e={}),O(t,r.serialization.SerializationMap.getMap().classNameMap,e,"constraint")}function W(t){return null==t?null:"string"==typeof t?U({className:t in z?z[t]:t,config:{}}):t instanceof R?t:U(t)}var V=Object.freeze({maxNorm:function(t){return new F(t)},unitNorm:function(t){return new j(t)},nonNeg:function(){return new P},minMaxNorm:function(t){return new L(t)}}),q=["channelsFirst","channelsLast"],H=["valid","same","causal"],G=["max","avg"],$=["sum","mul","concat","ave"],K=new Map;function X(t){N(q,"DataFormat",t)}function Y(t){N(H,"PaddingMode",t)}function J(t){N(G,"PoolMode",t)}var Z=[],Q="/";function tt(t,e){Z.push(t);try{var n=e();return Z.pop(),n}catch(t){throw Z.pop(),t}}function et(t){if(!it(t))throw new Error("Not a valid tensor name: '"+t+"'");return(0===Z.length?"":Z.join(Q)+Q)+t}function nt(t){if(!it(t))throw new Error("Not a valid tensor name: '"+t+"'");K.has(t)||K.set(t,0);var e=K.get(t);if(K.set(t,K.get(t)+1),e>0){var n=t+"_"+e;return K.set(n,1),n}return t}var rt=new RegExp(/^[A-Za-z0-9][-A-Za-z0-9\._\/]*$/);function it(t){return!!t.match(rt)}function at(t){return t===parseInt(t.toString(),10)}function ot(t,e,n){null==e&&(e=0),null==n&&(n=t.length);for(var r=1,i=e;i<n;++i)r*=t[i];return r}function st(t){return t=Array.isArray(t)?new Float32Array(t):t,Object(r.tensor1d)(t)}function ut(t){return Object(r.min)(st(t)).dataSync()[0]}function ct(t){return Object(r.max)(st(t)).dataSync()[0]}function lt(t,e){if(e<t)throw new h("end ("+e+") < begin ("+t+") is forbidden.");for(var n=[],r=t;r<e;++r)n.push(r);return n}function ft(t,e){return t.asType(e)}function dt(t,e){void 0===e&&(e=-1);var n=t.shape.slice();return e<0&&(e=n.length+e+1),n.splice(e,0,1),t.reshape(n)}function ht(t,e,n){return Object(r.tidy)(function(){switch(t.rank){case 1:return Object(r.slice1d)(t,e,n);case 2:return Object(r.slice2d)(t,[e,0],[n,t.shape[1]]);case 3:return Object(r.slice3d)(t,[e,0,0],[n,t.shape[1],t.shape[2]]);case 4:return Object(r.slice4d)(t,[e,0,0,0],[n,t.shape[1],t.shape[2],t.shape[3]]);case 5:return Object(r.slice)(t,[e,0,0,0,0],[n,t.shape[1],t.shape[2],t.shape[3],t.shape[4]]);case 6:return Object(r.slice)(t,[e,0,0,0,0,0],[n,t.shape[1],t.shape[2],t.shape[3],t.shape[4],t.shape[5]]);default:throw new h("sliceAlongFirstAxis() received an unsupported tensor rank: "+t.rank)}})}function pt(t,e,n){return Object(r.tidy)(function(){switch(t.rank){case 1:return Object(r.slice1d)(t,e,n);case 2:return Object(r.slice2d)(t,[0,e],[t.shape[0],n]);case 3:return Object(r.slice3d)(t,[0,0,e],[t.shape[0],t.shape[1],n]);case 4:return Object(r.slice4d)(t,[0,0,0,e],[t.shape[0],t.shape[1],t.shape[2],n]);default:throw new h("sliceAlongLastAxis() received an unsupported tensor rank: "+t.rank)}})}function mt(t,e,n,i){return Object(r.tidy)(function(){switch(t.rank){case 1:return Object(r.slice1d)(t,e,n);case 2:switch(i){case 1:return ht(t,e,n);case 2:return pt(t,e,n);default:throw new h("The axis is not within the rank of the tensor "+i)}case 3:switch(i){case 1:return ht(t,e,n);case 2:return Object(r.slice3d)(t,[0,e,0],[t.shape[0],n,t.shape[2]]);case 3:return pt(t,e,n);default:throw new h("The axis is not within the rank of the tensor "+i)}case 4:switch(i){case 1:return ht(t,e,n);case 2:return Object(r.slice4d)(t,[0,e,0,0],[t.shape[0],n,t.shape[2],t.shape[3]]);case 3:return Object(r.slice4d)(t,[0,0,e,0],[t.shape[0],t.shape[1],n,t.shape[3]]);case 4:return pt(t,e,n);default:throw new h("The axis is not within the rank of the tensor "+i)}default:throw new h("sliceAlongLastAxis() received an unsupported tensor rank: "+t.rank)}})}function gt(t,e){var n;return void 0===e&&(e=-1),e<0&&(e=0!==(n=t[0].rank)?n:0),e===t[0].rank&&(e=-1),Object(r.concat)(t,e)}function vt(t,e){switch(t.rank){case 1:return Object(r.concat1d)([t,e]);case 2:return Object(r.concat2d)([t,e],0);case 3:return Object(r.concat3d)([t,e],0);case 4:return Object(r.concat4d)([t,e],0);default:throw new h("concatAlongFirstAxis() received an unsupported tensor rank: "+t.rank)}}function yt(t,e){if(Array.isArray(e)||(e=[e]),t.rank!==e.length)throw new h("The length of input n ("+e.length+") does not match the number of dimensions in input x ("+t.rank+")");return Object(r.tile)(t,e)}function bt(t,e,n,i,a){return void 0===e&&(e=0),void 0===n&&(n=1),Object(r.randomNormal)(t,e,n,i,a)}function xt(t,e,n,i){if(t.rank<2||e.rank<2)throw new p("dot requires both inputs to be rank >= 2 but got x shape = "+t.shape+" and y shape = "+e.shape);if(e.rank>=3&&t.shape.slice(-1)[0]!==(f=e.shape.slice(-2)[0]))throw new p("If rank y >= 3, then the second last dim of y must equal the last dim of x but got x shape = "+t.shape+" and y shape = "+e.shape);if(2===t.rank&&2===e.rank){var a=!1,o=!1;return r.fused.matMul({a:t,b:e,transposeA:a,transposeB:o,bias:i?_t(t.rank,i,"channelsLast"):null,activation:n})}var s=t.shape.slice(),u=s.pop();t=t.reshape([-1,u]);var c=e.shape.slice(),l=c.pop(),f=c.pop(),d=c.concat([l]),h=Array.from({length:e.rank},function(t,n){return 0===n?e.rank-2:n<=e.rank-2?n-1:n});e=e.transpose(h).reshape([f,-1]);var m=s.concat(d);return a=!1,o=!1,r.fused.matMul({a:t,b:e,transposeA:a,transposeB:o,bias:i?_t(t.rank,i,"channelsLast"):null,activation:n}).reshape(m)}function wt(t,e,n){return Object(r.tidy)(function(){return e=Array.isArray(e)?Object(r.tensor1d)(e,"int32"):e.toInt(),Object(r.gather)(t,e,n)})}function kt(t){return Object(r.mulStrict)(t,t)}function _t(t,e,n){var r=e.shape;if(1!==e.rank&&e.rank!==t)throw new h("Unexpected bias dimensions: "+e.rank+"; expected it to be 1 or "+t);if(5===t){if("channelsFirst"===n)return 1===r.length?e.reshape([1,r[0],1,1,1]):e.reshape([1,r[3],r[0],r[1],r[2]]);if("channelsLast"===n)return 1===r.length?e.reshape([1,1,1,1,r[0]]):e.reshape([1].concat(r))}else if(4===t){if("channelsFirst"===n)return 1===r.length?e.reshape([1,r[0],1,1]):e.reshape([1,r[2],r[0],r[1]]);if("channelsLast"===n)return 1===r.length?e.reshape([1,1,1,r[0]]):e.reshape([1].concat(r))}else if(3===t){if("channelsFirst"===n)return 1===r.length?e.reshape([1,r[0],1]):e.reshape([1,r[1],r[0]]);if("channelsLast"===n)return 1===r.length?e.reshape([1,1,r[0]]):e.reshape([1].concat(r))}else if(t<3)return e;throw new h("Unsupported input rank by biasAdd: "+e.rank)}function Et(t,e,n){return Object(r.tidy)(function(){return null==n&&(n="channelsLast"),X(n),t.add(_t(t.rank,e,n))})}function Ot(t,e,n,i){return Object(r.tidy)(function(){return Object(r.dropout)(t,e,n,i)})}function St(t,e,n){return void 0===n&&(n=!1),n?t():e()}var Ct=["fanIn","fanOut","fanAvg"],At=["normal","uniform","truncatedNormal"];var Nt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.fromConfigUsesCustomObjects=function(){return!1},e.prototype.getConfig=function(){return{}},e}(r.serialization.Serializable),Tt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.apply=function(t,e){return Object(r.zeros)(t,e)},e.className="Zeros",e}(Nt);r.serialization.registerClass(Tt);var It=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.apply=function(t,e){return Object(r.ones)(t,e)},e.className="Ones",e}(Nt);r.serialization.registerClass(It);var Dt=function(t){function e(e){var n=t.call(this)||this;if("object"!=typeof e)throw new h("Expected argument of type ConstantConfig but got "+e);if(void 0===e.value)throw new h("config must have value set but got "+e);return n.value=e.value,n}return a(e,t),e.prototype.apply=function(t,e){var n=this;return Object(r.tidy)(function(){return Object(r.mul)(Object(r.scalar)(n.value),Object(r.ones)(t,e))})},e.prototype.getConfig=function(){return{value:this.value}},e.className="Constant",e}(Nt);r.serialization.registerClass(Dt);var Mt=function(t){function e(e){var n=t.call(this)||this;return n.DEFAULT_MINVAL=-.05,n.DEFAULT_MAXVAL=.05,n.minval=e.minval||n.DEFAULT_MINVAL,n.maxval=e.maxval||n.DEFAULT_MAXVAL,n.seed=e.seed,n}return a(e,t),e.prototype.apply=function(t,e){return Object(r.randomUniform)(t,this.minval,this.maxval,e)},e.prototype.getConfig=function(){return{minval:this.minval,maxval:this.maxval,seed:this.seed}},e.className="RandomUniform",e}(Nt);r.serialization.registerClass(Mt);var Rt=function(t){function e(e){var n=t.call(this)||this;return n.DEFAULT_MEAN=0,n.DEFAULT_STDDEV=.05,n.mean=e.mean||n.DEFAULT_MEAN,n.stddev=e.stddev||n.DEFAULT_STDDEV,n.seed=e.seed,n}return a(e,t),e.prototype.apply=function(t,e){if("float32"!==(e=e||"float32")&&"int32"!==e)throw new p("randomNormal does not support dType "+e+".");return bt(t,this.mean,this.stddev,e,this.seed)},e.prototype.getConfig=function(){return{mean:this.mean,stddev:this.stddev,seed:this.seed}},e.className="RandomNormal",e}(Nt);r.serialization.registerClass(Rt);var Ft=function(t){function e(e){var n=t.call(this)||this;return n.DEFAULT_MEAN=0,n.DEFAULT_STDDEV=.05,n.mean=e.mean||n.DEFAULT_MEAN,n.stddev=e.stddev||n.DEFAULT_STDDEV,n.seed=e.seed,n}return a(e,t),e.prototype.apply=function(t,e){if("float32"!==(e=e||"float32")&&"int32"!==e)throw new p("truncatedNormal does not support dType "+e+".");return Object(r.truncatedNormal)(t,this.mean,this.stddev,e,this.seed)},e.prototype.getConfig=function(){return{mean:this.mean,stddev:this.stddev,seed:this.seed}},e.className="TruncatedNormal",e}(Nt);r.serialization.registerClass(Ft);var jt=function(t){function e(e){var n=t.call(this)||this;return n.gain=null!=e.gain?e.gain:1,n}return a(e,t),e.prototype.apply=function(t,e){var n=this;return Object(r.tidy)(function(){if(2!==t.length||t[0]!==t[1])throw new h("Identity matrix initializer can only be used for 2D square matrices.");return Object(r.mul)(n.gain,Object(r.eye)(t[0]))})},e.prototype.getConfig=function(){return{gain:this.gain}},e.className="Identity",e}(Nt);r.serialization.registerClass(jt);var Pt=function(t){function e(e){var n=t.call(this)||this;if(e.scale<0)throw new h("scale must be a positive float. Got: "+e.scale);return n.scale=null==e.scale?1:e.scale,n.mode=null==e.mode?"fanIn":e.mode,function(t){N(Ct,"FanMode",t)}(n.mode),n.distribution=null==e.distribution?"normal":e.distribution,function(t){N(At,"Distribution",t)}(n.distribution),n.seed=e.seed,n}return a(e,t),e.prototype.apply=function(t,e){var n=function(t,e){var n,r;if(void 0===e&&(e="channelsLast"),X(e),2===t.length)n=t[0],r=t[1];else if(-1!==[3,4,5].indexOf(t.length))if("channelsFirst"===e){var i=ot(t,2);n=t[1]*i,r=t[0]*i}else"channelsLast"===e&&(i=ot(t,0,t.length-2),n=t[t.length-2]*i,r=t[t.length-1]*i);else{var a=ot(t);n=Math.sqrt(a),r=Math.sqrt(a)}return[n,r]}(t),i=n[0],a=n[1],o=this.scale;if("fanIn"===this.mode?o/=Math.max(1,i):"fanOut"===this.mode?o/=Math.max(1,a):o/=Math.max(1,(i+a)/2),"normal"===this.distribution){var s=Math.sqrt(o);if("float32"!==(e=e||"float32")&&"int32"!==e)throw new p(this.getClassName()+" does not support dType "+e+".");return Object(r.truncatedNormal)(t,0,s,e,this.seed)}var u=Math.sqrt(3*o);return Object(r.randomUniform)(t,-u,u,e)},e.prototype.getConfig=function(){return{scale:this.scale,mode:this.mode,distribution:this.distribution,seed:this.seed}},e.className="VarianceScaling",e}(Nt);r.serialization.registerClass(Pt);var Lt=function(t){function e(e){return t.call(this,{scale:1,mode:"fanAvg",distribution:"uniform",seed:null==e?null:e.seed})||this}return a(e,t),e.prototype.getClassName=function(){return Pt.className},e.className="GlorotUniform",e}(Pt);r.serialization.registerClass(Lt);var zt=function(t){function e(e){return t.call(this,{scale:1,mode:"fanAvg",distribution:"normal",seed:null==e?null:e.seed})||this}return a(e,t),e.prototype.getClassName=function(){return Pt.className},e.className="GlorotNormal",e}(Pt);r.serialization.registerClass(zt);var Bt=function(t){function e(e){return t.call(this,{scale:2,mode:"fanIn",distribution:"normal",seed:null==e?null:e.seed})||this}return a(e,t),e.prototype.getClassName=function(){return Pt.className},e.className="HeNormal",e}(Pt);r.serialization.registerClass(Bt);var Ut=function(t){function e(e){return t.call(this,{scale:2,mode:"fanIn",distribution:"uniform",seed:null==e?null:e.seed})||this}return a(e,t),e.prototype.getClassName=function(){return Pt.className},e.className="HeUniform",e}(Pt);r.serialization.registerClass(Ut);var Wt=function(t){function e(e){return t.call(this,{scale:1,mode:"fanIn",distribution:"normal",seed:null==e?null:e.seed})||this}return a(e,t),e.prototype.getClassName=function(){return Pt.className},e.className="LeCunNormal",e}(Pt);r.serialization.registerClass(Wt);var Vt=function(t){function e(e){return t.call(this,{scale:1,mode:"fanIn",distribution:"uniform",seed:null==e?null:e.seed})||this}return a(e,t),e.prototype.getClassName=function(){return Pt.className},e.className="LeCunNormal",e}(Pt);r.serialization.registerClass(Vt);var qt=function(t){function e(e){var n=t.call(this)||this;if(n.DEFAULT_GAIN=1,n.gain=null==e.gain?n.DEFAULT_GAIN:e.gain,n.seed=e.seed,null!=n.seed)throw new p("Random seed is not implemented for Orthogonal Initializer yet.");return n}return a(e,t),e.prototype.apply=function(t,e){var n=this;return Object(r.tidy)(function(){if(2!==t.length)throw new p("The Orthogonal Initializer does not support non-2D shapes yet.");t[0]*t[1]>2e3&&console.warn("Orthogonal initializer is being called on a matrix with more than 2000 ("+t[0]*t[1]+") elements: Slowness may result.");var e=bt(t[0]>t[1]?[t[1],t[0]]:t,0,1,"float32"),i=r.linalg.gramSchmidt(e);return t[0]>t[1]&&(i=i.transpose()),Object(r.mul)(n.gain,i)})},e.prototype.getConfig=function(){return{gain:this.gain,seed:this.seed}},e.className="Orthogonal",e}(Nt);r.serialization.registerClass(qt);var Ht={constant:"Constant",glorotNormal:"GlorotNormal",glorotUniform:"GlorotUniform",heNormal:"HeNormal",heUniform:"HeUniform",identity:"Identity",leCunNormal:"LeCunNormal",leCunUniform:"LeCunUniform",ones:"Ones",orthogonal:"Orthogonal",randomNormal:"RandomNormal",randomUniform:"RandomUniform",truncatedNormal:"TruncatedNormal",varianceScaling:"VarianceScaling",zeros:"Zeros"};function Gt(t,e){return void 0===e&&(e={}),O(t,r.serialization.SerializationMap.getMap().classNameMap,e,"initializer")}function $t(t){return E(t)}function Kt(t){if("string"==typeof t){var e=t in Ht?Ht[t]:t;if("GlorotNormal"===e)return new zt;if("GlorotUniform"===e)return new Lt;if("HeNormal"===e)return new Bt;if("HeUniform"===e)return new Ut;if("LeCunNormal"===e)return new Wt;if("LeCunUniform"===e)return new Vt;var n={};return n.className=e,n.config={},Gt(n)}return t instanceof Nt?t:Gt(t)}var Xt=Object.freeze({zeros:function(){return new Tt},ones:function(){return new It},constant:function(t){return new Dt(t)},randomUniform:function(t){return new Mt(t)},randomNormal:function(t){return new Rt(t)},truncatedNormal:function(t){return new Ft(t)},identity:function(t){return new jt(t)},varianceScaling:function(t){return new Pt(t)},glorotUniform:function(t){return new Lt(t)},glorotNormal:function(t){return new zt(t)},heNormal:function(t){return new Bt(t)},heUniform:function(t){return new Ut(t)},leCunNormal:function(t){return new Wt(t)},leCunUniform:function(t){return new Vt(t)},orthogonal:function(t){return new qt(t)}}),Yt=0;function Jt(){return Yt++}var Zt={};function Qt(t){return void 0===t&&(t=""),t in Zt||(Zt[t]=0),Zt[t]+=1,t+Zt[t].toString()}function te(t){return Array.isArray(t)&&Array.isArray(t[0])}function ee(t){return 0===t.length?[]:Array.isArray(t[0])?t:[t]}function ne(t){var e;if(Array.isArray(t)){if(1!==t.length)throw new h("Expected Tensor length to be 1; got "+t.length);e=t[0]}else e=t;return e}function re(t){if(Array.isArray(t)&&Array.isArray(t[0])){if(1===t.length)return(t=t)[0];throw new h("Expected exactly 1 Shape; got "+t.length)}return t}function ie(t){for(var e=0,n=0,r=t;n<r.length;n++){var i=r[n];0===i.shape.length?e+=1:e+=i.shape.reduce(function(t,e){return t*e})}return e}var ae="Variable",oe=function(){function t(t,e,n,i,a){void 0===e&&(e="float32"),void 0===n&&(n=ae),void 0===i&&(i=!0),void 0===a&&(a=null),this.dtype=null==e?"float32":e,this.shape=t.shape,this.id=Jt(),n=null==n?ae:n,this.originalName=et(n),this.name=nt(this.originalName),this.trainable_=i,this.constraint=a,this.val=Object(r.variable)(t,this.trainable_,this.name,this.dtype)}return t.prototype.read=function(){return this.assertNotDisposed(),this.val},t.prototype.write=function(t){return this.assertNotDisposed(),function(t,e){if(t.shape.toString()!==e.shape.toString())throw new Error("Shape mismatch: "+JSON.stringify(t.shape)+" vs. "+JSON.stringify(e.shape))}(this.val,t),this.val.id!==t.id&&(this.val.assign(t),null!=this.constraint&&this.val.assign(this.constraint.apply(this.val))),this},t.prototype.dispose=function(){this.assertNotDisposed(),this.val.dispose()},t.prototype.assertNotDisposed=function(){if(this.val.isDisposed)throw new Error("LayersVariable "+this.name+" is already disposed.")},Object.defineProperty(t.prototype,"trainable",{get:function(){return this.trainable_},set:function(t){this.trainable_=t,this.val.trainable=t},enumerable:!0,configurable:!0}),t}();function se(t){return t.map(function(t){return t.read()})}function ue(t){t.forEach(function(t){t[0].write(t[1])})}var ce=function(t){this.dtype=t.dtype,this.shape=t.shape,null!=t.shape?this.ndim=t.shape.length:this.ndim=t.ndim,this.maxNDim=t.maxNDim,this.minNDim=t.minNDim,this.axes=t.axes||{}},le=function(t,e,n,r,i,a,o){this.dtype=t,this.shape=e,this.sourceLayer=n,this.inputs=r,this.callArgs=i,this.outputTensorIndex=o,this.id=Jt(),null!=a&&(this.originalName=et(a),this.name=nt(this.originalName)),this.rank=e.length},fe=0,de=function(){function t(t,e){this.callArgs=e,this.id=fe++,this.outboundLayer=t.outboundLayer,this.inboundLayers=t.inboundLayers,this.nodeIndices=t.nodeIndices,this.tensorIndices=t.tensorIndices,this.inputTensors=t.inputTensors,this.outputTensors=t.outputTensors,this.inputMasks=t.inputMasks,this.outputMasks=t.outputMasks,this.inputShapes=t.inputShapes,this.outputShapes=t.outputShapes;for(var n=0,r=t.inboundLayers;n<r.length;n++){var i=r[n];null!=i&&i.outboundNodes.push(this)}t.outboundLayer.inboundNodes.push(this)}return t.prototype.getConfig=function(){for(var t=[],e=0,n=this.inboundLayers;e<n.length;e++){var r=n[e];null!=r?t.push(r.name):t.push(null)}return{outboundLayer:this.outboundLayer?this.outboundLayer.name:null,inboundLayers:t,nodeIndices:this.nodeIndices,tensorIndices:this.tensorIndices}},t}(),he=0,pe=function(t){function e(e){var n=t.call(this)||this;n._callHook=null,n._addedWeightNames=[],n._stateful=!1,n.id=he++,n.activityRegularizer=null,n.inputSpec=null,n.supportsMasking=!1,n._trainableWeights=[],n._nonTrainableWeights=[],n._losses=[],n._updates=[],n._built=!1,n.inboundNodes=[],n.outboundNodes=[];var r=e.name;if(!r){var i=n.getClassName();r=w(i)+"_"+Qt(i)}if(n.name=r,n.trainable_=null==e.trainable||e.trainable,null!=e.inputShape||null!=e.batchInputShape){var a=void 0;if(null!=e.batchInputShape)a=e.batchInputShape;else if(null!=e.inputShape){var o=null;null!=e.batchSize&&(o=e.batchSize),a=[o].concat(e.inputShape)}n.batchInputShape=a;var s=e.dtype;null==s&&(s=e.inputDType),null==s&&(s="float32"),n.dtype=s}return null!=e.weights?n.initialWeights=e.weights:n.initialWeights=null,n._refCount=null,n.fastWeightInitDuringBuild=!1,n}return a(e,t),e.nodeKey=function(t,e){return t.name+"_ib-"+e.toString()},e.prototype.getNodeAtIndex=function(t,e){if(0===this.inboundNodes.length)throw new d("The layer has never been called and thus has no defined "+e+".");if(this.inboundNodes.length<=t)throw new h("Asked to get "+e+" at node "+t+", but the layer has only "+this.inboundNodes.length+" inbound nodes.");return this.inboundNodes[t]},e.prototype.getInputAt=function(t){return b(this.getNodeAtIndex(t,"input").inputTensors)},e.prototype.getOutputAt=function(t){return b(this.getNodeAtIndex(t,"output").outputTensors)},Object.defineProperty(e.prototype,"input",{get:function(){if(this.inboundNodes.length>1)throw new f("Layer "+this.name+' has multiple inbound nodes, hence the notion of "layer input" is ill-defined. Use `getInputAt(nodeIndex)` instead.');if(0===this.inboundNodes.length)throw new f("Layer "+this.name+" is not connected, no input to return.");return b(this.getNodeAtIndex(0,"input").inputTensors)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"output",{get:function(){if(0===this.inboundNodes.length)throw new f("Layer "+this.name+" has no inbound nodes.");if(this.inboundNodes.length>1)throw new f("Layer "+this.name+' has multiple inbound nodes, hence the notion of "layer output" is ill-defined. Use `getOutputAt(nodeIndex)` instead.');return b(this.getNodeAtIndex(0,"output").outputTensors)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"losses",{get:function(){return this._losses},enumerable:!0,configurable:!0}),e.prototype.calculateLosses=function(){return this.losses.map(function(t){return t()})},Object.defineProperty(e.prototype,"updates",{get:function(){return this._updates},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"built",{get:function(){return this._built},set:function(t){this._built=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"trainable",{get:function(){return this.trainable_},set:function(t){this._trainableWeights.forEach(function(e){return e.trainable=t}),this.trainable_=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"trainableWeights",{get:function(){return this.trainable_?this._trainableWeights.filter(function(t){return t.trainable}):[]},set:function(t){this._trainableWeights=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"nonTrainableWeights",{get:function(){return this.trainable?this._trainableWeights.filter(function(t){return!t.trainable}).concat(this._nonTrainableWeights):this._trainableWeights.concat(this._nonTrainableWeights)},set:function(t){this._nonTrainableWeights=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"weights",{get:function(){return this.trainableWeights.concat(this.nonTrainableWeights)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"stateful",{get:function(){return this._stateful},enumerable:!0,configurable:!0}),e.prototype.resetStates=function(){if(!this.stateful)throw new Error("Cannot call the resetStates() method of a non-stateful Layer object.")},e.prototype.assertInputCompatibility=function(t){if(t=x(t),null!=this.inputSpec&&0!==this.inputSpec.length){var e=x(this.inputSpec);if(t.length!==e.length)throw new h("Layer "+this.name+" expects "+e.length+" inputs, but it received "+t.length+" input tensors. Input received: "+t);for(var n=0;n<t.length;n++){var r=t[n],i=e[n];if(null!=i){var a=r.rank;if(null!=i.ndim&&a!==i.ndim)throw new h("Input "+n+" is incompatible with layer "+this.name+": expected ndim="+i.ndim+", found ndim="+a);if(null!=i.maxNDim&&a>i.maxNDim)throw new h("Input "+n+" is incompatible with layer "+this.name+": expected max_ndim="+i.maxNDim+", found ndim="+a);if(null!=i.minNDim&&a<i.minNDim)throw new h("Input "+n+" is incompatible with layer "+this.name+": expected min_ndim="+i.minNDim+", found ndim="+a+".");if(null!=i.dtype&&r.dtype!==i.dtype)throw new h("Input "+n+" is incompatible with layer "+this.name+" : expected dtype="+i.dtype+", found dtype="+r.dtype+".");if(i.axes){var o=r.shape;for(var s in i.axes){var u=Number(s),c=i.axes[s],l=u>=0?o[u]:o[o.length+u];if(null!=c&&-1===[c,null].indexOf(l))throw new h("Input "+n+" is incompatible with layer "+this.name+": expected axis "+u+" of input shape to have value "+c+" but got shape "+o+".")}}if(null!=i.shape)for(var f=0;f<i.shape.length;++f){var d=i.shape[f],p=r.shape[f];if(null!=d&&null!=p&&d!==p)throw new h("Input "+n+" is incompatible with layer "+this.name+": expected shape="+i.shape+", found shape="+r.shape+".")}}}}},e.prototype.call=function(t,e){return t},e.prototype.invokeCallHook=function(t,e){null!=this._callHook&&this._callHook(t,e)},e.prototype.setCallHook=function(t){this._callHook=t},e.prototype.clearCallHook=function(){this._callHook=null},e.prototype.apply=function(t,e){var n=this;e=e||{},this.assertNotDisposed();for(var r=x(t),i=!0,a=0,o=r;a<o.length;a++)if(!(o[a]instanceof le)){i=!1;break}for(var s=!0,u=0,c=r;u<c.length;u++)if(c[u]instanceof le){s=!1;break}if(i===s)throw new h("Arguments to apply() must be all SymbolicTensors or all Tensors");return tt(this.name,function(){if(!n.built){n.assertInputCompatibility(t);for(var i=[],a=0,o=x(t);a<o.length;a++){var u=o[a];i.push(u.shape)}n.build(b(i)),n.built=!0,n.initialWeights&&n.setWeights(n.initialWeights),null===n._refCount&&s&&(n._refCount=1)}if(n.assertInputCompatibility(t),s){for(var c=[],l=0,f=x(g=n.call(t,e));l<f.length;l++){var d=f[l];-1!==r.indexOf(d)&&(d=d.clone()),c.push(d)}if(g=b(c),null!=n.activityRegularizer)throw new p("Layer invocation in the presence of activity regularizer(s) is not supported yet.");return g}var h=function(t){for(var e=[],n=0,r=t=x(t);n<r.length;n++){var i=r[n];e.push(i.shape)}return b(e)}(t),m=n.computeOutputShape(h),g=void 0,v="float32";if(n.warnOnIncompatibleInputShape(Array.isArray(t)?h[0]:h),g=null!=m&&m.length>0&&Array.isArray(m[0])?m.map(function(r,i){return new le(v,r,n,x(t),e,n.name,i)}):new le(v,m,n,x(t),e,n.name),n.addInboundNode(t,g,null,null,h,m,e),n._refCount++,null!=n.activityRegularizer)throw new p("Layer invocation in the presence of activity regularizer(s) is not supported yet.");return g})},e.prototype.warnOnIncompatibleInputShape=function(t){if(null!=this.batchInputShape)if(t.length!==this.batchInputShape.length)console.warn("The rank of the input tensor provided (shape: "+JSON.stringify(t)+") does not match that of the batchInputShape ("+JSON.stringify(this.batchInputShape)+") of the layer "+this.name);else{var e=!1;this.batchInputShape.forEach(function(n,r){null!=n&&null!=t[r]&&t[r]!==n&&(e=!0)}),e&&console.warn("The shape of the input tensor ("+JSON.stringify(t)+") does not match the expectation of layer "+this.name+": "+JSON.stringify(this.batchInputShape))}},Object.defineProperty(e.prototype,"outputShape",{get:function(){if(null==this.inboundNodes||0===this.inboundNodes.length)throw new f("The layer "+this.name+" has never been called and thus has no defined output shape.");for(var t=[],e=0,n=this.inboundNodes;e<n.length;e++){var r=n[e],i=JSON.stringify(r.outputShapes);-1===t.indexOf(i)&&t.push(i)}if(1===t.length){var a=this.inboundNodes[0].outputShapes;return Array.isArray(a)&&Array.isArray(a[0])&&1===a.length?a[0]:a}throw new f("The layer "+this.name+' has multiple inbound nodes with different output shapes. Hence the notion of "outut shape" is ill-defined for the layer.')},enumerable:!0,configurable:!0}),e.prototype.countParams=function(){if(!this.built)throw new d("You tried to call countParams() on "+this.name+", but the layer is not built yet. Build it first by calling build(batchInputShape).");return ie(this.weights)},e.prototype.build=function(t){this.built=!0},e.prototype.getWeights=function(t){return void 0===t&&(t=!1),se(t?this.trainableWeights:this.weights)},e.prototype.setWeights=function(t){var e=this;Object(r.tidy)(function(){var n=e.weights;if(n.length!==t.length)throw new h('You called setWeights(weights) on layer "'+e.name+'" with a weight list of length '+t.length+", but the layer was expecting "+n.length+" weights. Provided weights: "+t+"...");if(0!==n.length){for(var i=[],a=se(n),o=0;o<a.length;++o){var s=a[o],u=n[o],c=t[o];if(!r.util.arraysEqual(s.shape,c.shape))throw new h("Layer weight shape "+s.shape+" not compatible with provided weight shape "+c.shape);i.push([u,c])}ue(i)}})},e.prototype.addWeight=function(t,e,n,r,i,a,o){if(-1!==this._addedWeightNames.indexOf(t))throw new h("Duplicate weight name "+t+" for layer "+this.name);this._addedWeightNames.push(t),null==n&&(n="float32"),this.fastWeightInitDuringBuild&&(r=Kt("zeros"));var s=r.apply(e,n),u=new oe(s,n,t,a,o);return s.dispose(),null!=i&&this.addLoss(function(){return i.apply(u.read())}),null==a&&(a=!0),a?this._trainableWeights.push(u):this._nonTrainableWeights.push(u),u},e.prototype.setFastWeightInitDuringBuild=function(t){this.fastWeightInitDuringBuild=t},e.prototype.addLoss=function(t){var e;null==t||Array.isArray(t)&&0===t.length||(t=x(t),void 0!==this._losses&&null!==this._losses&&(e=this.losses).push.apply(e,t))},e.prototype.computeOutputShape=function(t){return t},e.prototype.computeMask=function(t,e){var n=this;if(!this.supportsMasking){if(null!=e){if(!Array.isArray(e))throw new TypeError("Layer "+this.name+" does not support masking, but was passed an inputMask.");e.forEach(function(t){if(null!=t)throw new TypeError("Layer "+n.name+" does not support masking, but was passed an inputMask.")})}return null}return e},e.prototype.addInboundNode=function(t,e,n,r,i,a,o){void 0===o&&(o=null);var s=x(t);e=x(e),n=x(n),r=x(r),i=ee(i),a=ee(a);for(var u=[],c=[],l=[],f=0,d=s;f<d.length;f++){var h=d[f];u.push(h.sourceLayer),c.push(h.nodeIndex),l.push(h.tensorIndex)}new de({outboundLayer:this,inboundLayers:u,nodeIndices:c,tensorIndices:l,inputTensors:s,outputTensors:e,inputMasks:n,outputMasks:r,inputShapes:i,outputShapes:a},o);for(var p=0;p<e.length;p++)e[p].sourceLayer=this,e[p].nodeIndex=this.inboundNodes.length-1,e[p].tensorIndex=p},e.prototype.getConfig=function(){var t={name:this.name,trainable:this.trainable};return null!=this.batchInputShape&&(t.batchInputShape=this.batchInputShape),null!=this.dtype&&(t.dtype=this.dtype),t},e.prototype.disposeWeights=function(){return this.weights.forEach(function(t){return t.dispose()}),this.weights.length},e.prototype.assertNotDisposed=function(){if(0===this._refCount)throw new Error("Layer '"+this.name+"' is already disposed.")},e.prototype.dispose=function(){if(!this.built)throw new Error("Cannot dispose Layer "+this.name+" because it has not been built yet.");if(null===this._refCount)throw new Error("Cannot dispose Layer "+this.name+" because it has not been used yet.");this.assertNotDisposed();var t=0;return 0==--this._refCount&&(t=this.disposeWeights()),{refCountAfterDispose:this._refCount,numDisposedVariables:t}},e}(r.serialization.Serializable);var me,ge=function(t){function e(e){var n=t.call(this,{dtype:e.dtype,name:null!=e.name?e.name:Qt("input").toString()})||this;if(null==e.batchSize&&(e.batchSize=null),null==e.sparse&&(e.sparse=!1),n.trainable=!1,n.built=!0,n.sparse=e.sparse,null!=e.inputShape&&null!=e.batchInputShape)throw new h("Only provide the inputShape OR batchInputShape argument to inputLayer, not both at the same time.");var r=e.batchInputShape;if(null==r){if(null==e.inputShape)throw new h("An InputLayer should be passed either a `batchInputShape` or an `inputShape`.");r=[e.batchSize].concat(e.inputShape)}else if(null!=e.batchSize)throw new h("Cannot specify batchSize if batchInputShape is specified when creating an InputLayer.");var i=e.dtype||"float32";n.batchInputShape=r,n.dtype=i,n.inputSpec=[{shape:r}];var a=new le(n.dtype,n.batchInputShape,n,[],{},n.name);return a.nodeIndex=0,a.tensorIndex=0,new de({outboundLayer:n,inboundLayers:[],nodeIndices:[],tensorIndices:[],inputTensors:[a],outputTensors:[a],inputMasks:[null],outputMasks:[null],inputShapes:[r],outputShapes:[r]}),n}return a(e,t),e.prototype.apply=function(t,e){throw new h("Cannot pass any input to an InputLayer's apply() method. InputLayer name: "+this.name)},e.prototype.dispose=function(){return{refCountAfterDispose:this._refCount,numDisposedVariables:0}},e.prototype.getConfig=function(){return{batchInputShape:this.batchInputShape,dtype:this.dtype,sparse:this.sparse,name:this.name}},e.className="InputLayer",e}(pe);function ve(t){if(null==t.batchShape&&null==t.shape)throw new Error("Please provide to Input either a `shape` or a `batchShape` argument. Note that `shape` does not include the batch dimension.");if(null!=t.batchShape&&null!=t.shape)throw new h("Please provide either a `shape` or `batchShape` argument to Input, but not both.");var e=t.batchShape;null!=t.shape&&null==e&&(e=[null].concat(t.shape));var n=t.dtype;return null==n&&(n="float32"),new ge({batchInputShape:e,name:t.name,dtype:n,sparse:t.sparse}).inboundNodes[0].outputTensors[0]}function ye(t){return u(this,void 0,void 0,function(){var e,n,i,a,o,s,u,l;return c(this,function(c){switch(c.label){case 0:if(null==t)return[2];for(a in e=[],n=[],i=[],t)"number"!=typeof(o=t[a])&&(s=o,e.push(s.data()),n.push(a),i.push(s));return e.length>0?[4,Promise.all(e)]:[3,2];case 1:for(u=c.sent(),l=0;l<u.length;++l)t[n[l]]=u[l][0];Object(r.dispose)(i),c.label=2;case 2:return[2]}})})}function be(t){if(null!=t)for(var e in t){var n=t[e];"number"!=typeof n&&n.dispose()}}r.serialization.registerClass(ge),function(t){t[t.SILENT=0]="SILENT",t[t.VERBOSE=1]="VERBOSE"}(me||(me={}));var xe=125,we=function(){function t(){this.validationData=null}return t.prototype.setParams=function(t){this.params=t},t.prototype.onEpochBegin=function(t,e){return u(this,void 0,void 0,function(){return c(this,function(t){return[2]})})},t.prototype.onEpochEnd=function(t,e){return u(this,void 0,void 0,function(){return c(this,function(t){return[2]})})},t.prototype.onBatchBegin=function(t,e){return u(this,void 0,void 0,function(){return c(this,function(t){return[2]})})},t.prototype.onBatchEnd=function(t,e){return u(this,void 0,void 0,function(){return c(this,function(t){return[2]})})},t.prototype.onTrainBegin=function(t){return u(this,void 0,void 0,function(){return c(this,function(t){return[2]})})},t.prototype.onTrainEnd=function(t){return u(this,void 0,void 0,function(){return c(this,function(t){return[2]})})},t.prototype.setModel=function(t){},t}(),ke=function(){function t(t,e){void 0===e&&(e=10),null==t&&(t=[]),this.callbacks=t,this.queueLength=e}return t.prototype.append=function(t){this.callbacks.push(t)},t.prototype.setParams=function(t){for(var e=0,n=this.callbacks;e<n.length;e++)n[e].setParams(t)},t.prototype.setModel=function(t){for(var e=0,n=this.callbacks;e<n.length;e++)n[e].setModel(t)},t.prototype.onEpochBegin=function(t,e){return u(this,void 0,void 0,function(){var n,r;return c(this,function(i){switch(i.label){case 0:null==e&&(e={}),n=0,r=this.callbacks,i.label=1;case 1:return n<r.length?[4,r[n].onEpochBegin(t,e)]:[3,4];case 2:i.sent(),i.label=3;case 3:return n++,[3,1];case 4:return[2]}})})},t.prototype.onEpochEnd=function(t,e){return u(this,void 0,void 0,function(){var n,r;return c(this,function(i){switch(i.label){case 0:null==e&&(e={}),n=0,r=this.callbacks,i.label=1;case 1:return n<r.length?[4,r[n].onEpochEnd(t,e)]:[3,4];case 2:i.sent(),i.label=3;case 3:return n++,[3,1];case 4:return[2]}})})},t.prototype.onBatchBegin=function(t,e){return u(this,void 0,void 0,function(){var n,r;return c(this,function(i){switch(i.label){case 0:null==e&&(e={}),n=0,r=this.callbacks,i.label=1;case 1:return n<r.length?[4,r[n].onBatchBegin(t,e)]:[3,4];case 2:i.sent(),i.label=3;case 3:return n++,[3,1];case 4:return[2]}})})},t.prototype.onBatchEnd=function(t,e){return u(this,void 0,void 0,function(){var n,r;return c(this,function(i){switch(i.label){case 0:null==e&&(e={}),n=0,r=this.callbacks,i.label=1;case 1:return n<r.length?[4,r[n].onBatchEnd(t,e)]:[3,4];case 2:i.sent(),i.label=3;case 3:return n++,[3,1];case 4:return[2]}})})},t.prototype.onTrainBegin=function(t){return u(this,void 0,void 0,function(){var e,n;return c(this,function(r){switch(r.label){case 0:null==t&&(t={}),e=0,n=this.callbacks,r.label=1;case 1:return e<n.length?[4,n[e].onTrainBegin(t)]:[3,4];case 2:r.sent(),r.label=3;case 3:return e++,[3,1];case 4:return[2]}})})},t.prototype.onTrainEnd=function(t){return u(this,void 0,void 0,function(){var e,n;return c(this,function(r){switch(r.label){case 0:null==t&&(t={}),e=0,n=this.callbacks,r.label=1;case 1:return e<n.length?[4,n[e].onTrainEnd(t)]:[3,4];case 2:r.sent(),r.label=3;case 3:return e++,[3,1];case 4:return[2]}})})},t}(),_e=function(t){function e(){return t.call(this)||this}return a(e,t),e.prototype.onEpochBegin=function(t){return u(this,void 0,void 0,function(){return c(this,function(t){return this.seen=0,this.totals={},[2]})})},e.prototype.onBatchEnd=function(t,e){return u(this,void 0,void 0,function(){var t,n,i,a,o=this;return c(this,function(s){for(a in null==e&&(e={}),t=null==e.size?0:e.size,this.seen+=t,n=function(n){var a=e[n];if("number"==typeof a)i.totals.hasOwnProperty(n)||(i.totals[n]=0),i.totals[n]=i.totals[n]+a*t;else{var s=void 0;n in i.totals?s=i.totals[n]:i.totals[n]=0;var u=Object(r.tidy)(function(){return Object(r.add)(o.totals[n],Object(r.mul)(a,t))});i.totals[n]=u,null!=s&&s.dispose()}},i=this,e)n(a);return[2]})})},e.prototype.onEpochEnd=function(t,e){return u(this,void 0,void 0,function(){var t,n,i,a,o,s=this;return c(this,function(u){if(null!=e)for(t=function(t){if(null==n.totals[t])return"continue";"number"==typeof n.totals[t]?e[t]=n.totals[t]/n.seen:Object(r.tidy)(function(){var n=Object(r.mul)(Object(r.div)(1,s.seen),s.totals[t]);e[t]=n,s.totals[t].dispose(),Object(r.keep)(e[t])})},n=this,i=0,a=this.params.metrics;i<a.length;i++)o=a[i],t(o);return[2]})})},e}(we),Ee=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.onTrainBegin=function(t){return u(this,void 0,void 0,function(){return c(this,function(t){return this.epoch=[],this.history={},[2]})})},e.prototype.onEpochEnd=function(t,e){return u(this,void 0,void 0,function(){var n;return c(this,function(r){for(n in null==e&&(e={}),this.epoch.push(t),e)null==this.history[n]&&(this.history[n]=[]),this.history[n].push(e[n]);return[2]})})},e.prototype.syncData=function(){return u(this,void 0,void 0,function(){var t,e,n,r,i,a,o,s,u;return c(this,function(c){switch(c.label){case 0:for(r in t=[],e=[],n=[],this.history)for(i=this.history[r],a=0;a<i.length;++a)"number"!=typeof i[a]&&(o=i[a],t.push(o.data()),e.push(r),n.push(a));return[4,Promise.all(t)];case 1:for(s=c.sent(),u=0;u<s.length;++u)this.history[e[u]][n[u]].dispose(),this.history[e[u]][n[u]]=s[u][0];return[2]}})})},e}(we),Oe=function(t){function e(e,n){var i=t.call(this)||this;if(i.currentEpoch=0,i.yieldEvery=n||"auto","auto"===i.yieldEvery&&(i.yieldEvery=xe),"never"===i.yieldEvery&&null!=e.onYield)throw new Error("yieldEvery is `never` but you provided an `onYield` callback. Either change `yieldEvery` or remove the callback");return r.util.isNumber(i.yieldEvery)&&(i.maybeWait=function(t,e){var n,i=r.util.now();return function(){for(var a=[],o=0;o<arguments.length;o++)a[o]=arguments[o];var s=r.util.now();return s-i<e?n:(i=s,n=t.apply(void 0,a))}}(i.maybeWait.bind(i),i.yieldEvery)),i.trainBegin=e.onTrainBegin,i.trainEnd=e.onTrainEnd,i.epochBegin=e.onEpochBegin,i.epochEnd=e.onEpochEnd,i.batchBegin=e.onBatchBegin,i.batchEnd=e.onBatchEnd,i.yield=e.onYield,i}return a(e,t),e.prototype.maybeWait=function(t,e,n){return u(this,void 0,void 0,function(){var i;return c(this,function(a){switch(a.label){case 0:return i=[],null==this.yield?[3,2]:[4,ye(n)];case 1:a.sent(),i.push(this.yield(t,e,n)),a.label=2;case 2:return i.push(Object(r.nextFrame)()),[4,Promise.all(i)];case 3:return a.sent(),[2]}})})},e.prototype.onEpochBegin=function(t,e){return u(this,void 0,void 0,function(){return c(this,function(n){switch(n.label){case 0:return this.currentEpoch=t,null==this.epochBegin?[3,3]:[4,ye(e)];case 1:return n.sent(),[4,this.epochBegin(t,e)];case 2:n.sent(),n.label=3;case 3:return[2]}})})},e.prototype.onEpochEnd=function(t,e){return u(this,void 0,void 0,function(){var n;return c(this,function(i){switch(i.label){case 0:return n=[],null==this.epochEnd?[3,2]:[4,ye(e)];case 1:i.sent(),n.push(this.epochEnd(t,e)),i.label=2;case 2:return"epoch"===this.yieldEvery&&n.push(Object(r.nextFrame)()),[4,Promise.all(n)];case 3:return i.sent(),[2]}})})},e.prototype.onBatchBegin=function(t,e){return u(this,void 0,void 0,function(){return c(this,function(n){switch(n.label){case 0:return null==this.batchBegin?[3,3]:[4,ye(e)];case 1:return n.sent(),[4,this.batchBegin(t,e)];case 2:n.sent(),n.label=3;case 3:return[2]}})})},e.prototype.onBatchEnd=function(t,e){return u(this,void 0,void 0,function(){var n;return c(this,function(i){switch(i.label){case 0:return n=[],null==this.batchEnd?[3,2]:[4,ye(e)];case 1:i.sent(),n.push(this.batchEnd(t,e)),i.label=2;case 2:return"batch"===this.yieldEvery?n.push(Object(r.nextFrame)()):r.util.isNumber(this.yieldEvery)&&n.push(this.maybeWait(this.currentEpoch,t,e)),[4,Promise.all(n)];case 3:return i.sent(),[2]}})})},e.prototype.onTrainBegin=function(t){return u(this,void 0,void 0,function(){return c(this,function(e){switch(e.label){case 0:return null==this.trainBegin?[3,3]:[4,ye(t)];case 1:return e.sent(),[4,this.trainBegin(t)];case 2:e.sent(),e.label=3;case 3:return[2]}})})},e.prototype.onTrainEnd=function(t){return u(this,void 0,void 0,function(){return c(this,function(e){switch(e.label){case 0:return null==this.trainEnd?[3,3]:[4,ye(t)];case 1:return e.sent(),[4,this.trainEnd(t)];case 2:e.sent(),e.label=3;case 3:return[2]}})})},e}(we);function Se(t,e){return null==t&&(t={}),t instanceof we?[t]:Array.isArray(t)&&t[0]instanceof we?t:x(t).map(function(t){return new Oe(t,e)})}var Ce=function(){function t(){}return t.registerCallbackConstructor=function(e,n){r.util.assert(e>=0&&Number.isInteger(e),function(){return"Verbosity level is expected to be an integer >= 0, but got "+e}),t.checkForDuplicate(n),null==t.constructors[e]&&(t.constructors[e]=[]),t.constructors[e].push(n)},t.checkForDuplicate=function(e){for(var n in t.constructors)t.constructors[+n].forEach(function(t){if(t===e)throw new h("Duplicate callback constructor.")})},t.clear=function(){t.constructors={}},t.createCallbacks=function(e){var n=[];for(var r in t.constructors){var i=+r;e>=i&&n.push.apply(n,t.constructors[i])}return n.map(function(t){return new t})},t.constructors={},t}();function Ae(t,e,n,r,i,a,o,s,u){var c=new Ee,l=[new _e].concat(Ce.createCallbacks(e));null!=t&&l.push.apply(l,t),l.push(c);var f=new ke(l);return f.setParams({epochs:n,initialEpoch:r,samples:i,steps:a,batchSize:o,verbose:e,doValidation:s,metrics:u}),{callbackList:f,history:c}}function Ne(t,e,n){return void 0===e&&(e={}),void 0===n&&(n=!1),O(t,r.serialization.SerializationMap.getMap().classNameMap,e,"layer",n)}function Te(t,e){return Object(r.tidy)(function(){"float32"!==t.dtype&&(t=t.asType("float32"));var n=Object(r.sum)(kt(t),e,!0),i=Object(r.fill)(n.shape,l()),a=Object(r.sqrt)(Object(r.maximum)(n,i));return Object(r.div)(t,a)})}function Ie(t,e){return Object(r.tidy)(function(){return Object(r.mean)(kt(Object(r.sub)(e,t)),-1)})}function De(t,e){return Object(r.tidy)(function(){return Object(r.mean)(Object(r.abs)(Object(r.sub)(e,t)),-1)})}function Me(t,e){return Object(r.tidy)(function(){var n=Object(r.sub)(t,e),i=Object(r.clipByValue)(Object(r.abs)(t),l(),Number.MAX_VALUE),a=Object(r.abs)(Object(r.div)(n,i));return Object(r.mul)(100,Object(r.mean)(a,-1))})}function Re(t,e,n){return void 0===n&&(n=!1),Object(r.tidy)(function(){if(n)e=Object(r.softmax)(e);else{var i=Object(r.sum)(e,e.shape.length-1,!0);e=Object(r.div)(e,i)}return e=Object(r.clipByValue)(e,l(),1-l()),Object(r.neg)(Object(r.sum)(Object(r.mul)(t.toFloat(),Object(r.log)(e)),e.shape.length-1))})}function Fe(t,e){return Object(r.tidy)(function(){var n=Object(r.floor)(function(t){var e=[ot(t.shape)];return t.reshape(e)}(t)).toInt(),i=(e=Object(r.clipByValue)(e,l(),1-l())).shape;return Re(Object(r.oneHot)(n,i[i.length-1]).reshape(i),e,!1)})}function je(t,e){return Object(r.tidy)(function(){var n;return n=Object(r.clipByValue)(e,l(),1-l()),n=Object(r.log)(Object(r.div)(n,Object(r.sub)(1,n))),Object(r.mean)(function(t,e){if(!r.util.arraysEqual(t.shape,e.shape))throw new h("logits and labels must have the same shape, but got shapes "+JSON.stringify(t.shape)+" and "+JSON.stringify(e.shape));return Object(r.tidy)(function(){var n=e.relu(),r=e.abs().neg();return n.sub(e.mul(t)).add(r.exp().log1p())})}(t,n),-1)})}function Pe(t,e){return Object(r.tidy)(function(){var n=Te(t,-1),i=Te(e,-1),a=Object(r.mul)(n,i);return Object(r.neg)(Object(r.sum)(a,-1))})}var Le={meanSquaredError:Ie,meanAbsoluteError:De,meanAbsolutePercentageError:Me,meanSquaredLogarithmicError:function(t,e){return Object(r.tidy)(function(){var n=Object(r.clipByValue)(e,l(),Number.MAX_VALUE),i=Object(r.log)(Object(r.add)(1,n)),a=Object(r.clipByValue)(t,l(),Number.MAX_VALUE),o=Object(r.log)(Object(r.add)(1,a));return Object(r.mean)(kt(Object(r.sub)(i,o)),-1)})},squaredHinge:function(t,e){return Object(r.tidy)(function(){var n=Object(r.maximum)(0,Object(r.sub)(1,Object(r.mul)(t,e)));return Object(r.mean)(kt(n),-1)})},hinge:function(t,e){return Object(r.tidy)(function(){var n=Object(r.maximum)(0,Object(r.sub)(1,Object(r.mul)(t,e)));return Object(r.mean)(n,-1)})},categoricalHinge:function(t,e){return Object(r.tidy)(function(){var n=Object(r.sum)(Object(r.mul)(t,e),-1),i=Object(r.max)(Object(r.mul)(Object(r.sub)(1,t),e),-1);return Object(r.maximum)(0,Object(r.add)(1,Object(r.sub)(i,n)))})},logcosh:function(t,e){return Object(r.tidy)(function(){var n=Math.log(2),i=Object(r.sub)(e,t),a=Object(r.sub)(Object(r.add)(i,Object(r.softplus)(Object(r.mul)(-2,i))),n);return Object(r.mean)(a,-1)})},categoricalCrossentropy:Re,sparseCategoricalCrossentropy:Fe,binaryCrossentropy:je,kullbackLeiblerDivergence:function(t,e){return Object(r.tidy)(function(){var n=Object(r.clipByValue)(t,l(),1),i=Object(r.clipByValue)(e,l(),1);return Object(r.sum)(Object(r.mul)(t,Object(r.log)(Object(r.div)(n,i))),-1)})},poisson:function(t,e){return Object(r.tidy)(function(){var n=Object(r.log)(Object(r.add)(l(),e));return Object(r.mean)(Object(r.sub)(e,Object(r.mul)(t,n)),-1)})},cosineProximity:Pe};function ze(t){if("string"==typeof t){if(t in Le)return Le[t];var e="Unknown loss "+t;throw t.toLowerCase().includes("softmaxcrossentropy")&&(e="Unknown loss "+t+'. Use "categoricalCrossentropy" as the string name for tf.losses.softmaxCrossEntropy'),new h(e)}return t}function Be(t,e){return Object(r.tidy)(function(){var n=Object(r.mul)(.5,Object(r.onesLike)(e)),i=ft(Object(r.greater)(e,n),t.dtype);return Object(r.mean)(Object(r.equal)(t,i),-1)})}function Ue(t,e){return Object(r.tidy)(function(){return ft(Object(r.equal)(Object(r.argMax)(t,-1),Object(r.argMax)(e,-1)),"float32")})}function We(t,e){return Object(r.tidy)(function(){return Object(r.logicalAnd)(t.equal(1),e.equal(1)).sum().cast("float32")})}function Ve(t,e){return Object(r.tidy)(function(){var n=We(t,e),i=function(t,e){return Object(r.tidy)(function(){return Object(r.logicalAnd)(t.equal(0),e.equal(1)).sum().cast("float32")})}(t,e),a=n.add(i);return Object(r.where)(Object(r.greater)(a,0),n.div(a),0).cast("float32")})}function qe(t,e){return Object(r.tidy)(function(){var n=We(t,e),i=function(t,e){return Object(r.tidy)(function(){return Object(r.logicalAnd)(t.equal(1),e.equal(0)).sum().cast("float32")})}(t,e),a=n.add(i);return Object(r.where)(Object(r.greater)(a,0),n.div(a),0).cast("float32")})}function He(t,e){return je(t,e)}function Ge(t,e){return t.rank===e.rank&&(t=t.squeeze([t.rank-1])),(e=e.argMax(-1)).dtype!==t.dtype&&(e=e.asType(t.dtype)),Object(r.equal)(t,e).asType("float32")}var $e=Re,Ke=Fe,Xe={binaryAccuracy:Be,categoricalAccuracy:Ue,precision:Ve,categoricalCrossentropy:$e,sparseCategoricalCrossentropy:Ke,mse:Ie,MSE:Ie,mae:De,MAE:De,mape:Me,MAPE:Me,cosine:Pe};function Ye(t){if(v(null!==t,"Unknown LossOrMetricFn "+t),"string"==typeof t)return t;for(var e=void 0,n=0,r=Object.keys(Le);n<r.length;n++){var i=r[n];if(Le[i]===t){e=i;break}}if(void 0!==e)return e;for(var a=0,o=Object.keys(Xe);a<o.length;a++)if(i=o[a],Xe[i]===t){e=i;break}return void 0!==e?e:t.name}var Je=1048576;function Ze(t,e,n){if(void 0===n&&(n=!1),null==t||"object"!=typeof t||Object.getPrototypeOf(t)!==Object.prototype||!function t(e){if(null===e)return!0;if("object"==typeof e){if(Object.getPrototypeOf(e)===Object.prototype){for(var n=0,r=Object.keys(e);n<r.length;n++){var i=r[n];if("string"!=typeof i)return!1;if(!t(e[i]))return!1}return!0}if(Array.isArray(e)){for(var a=0,o=e;a<o.length;a++)if(!t(o[a]))return!1;return!0}return!1}var s=typeof e;return"string"===s||"number"===s||"boolean"===s}(t))throw new Error("User-defined metadata is expected to be a JSON object, but is not.");if(n){var r=JSON.stringify(t);r.length>Je&&console.warn('User-defined metadata of model "'+e+'" is too large in size (length='+r.length+" when serialized). It is not recommended to store such large objects in user-defined metadata. Please make sure its serialized length is <= "+Je+".")}}function Qe(t,e,n,r){void 0===r&&(r=console.log);var i,a=function(t){var e=!0,n=[],r=[];for(var i in t.nodesByDepth)n.push(t.nodesByDepth[i]);for(var a=0,o=n;a<o.length;a++){var s=o[a];if(s.length>1||1===s.length&&s[0].inboundLayers.length>1){e=!1;break}r.push.apply(r,s)}if(e)for(var u=0,c=t.layers;u<c.length;u++){for(var l=!1,f=0,d=c[u].inboundNodes;f<d.length;f++){var h=d[f];if(-1!==r.indexOf(h)){if(l){e=!1;break}l=!0}}if(!e)break}return e}(t),o=["Layer (type)","Output shape","Param #"];if(a?(e=e||65,n=n||[.45,.85,1]):(e=e||98,n=n||[.33,.55,.67,1]),n[n.length-1]<=1&&(n=n.map(function(t){return Math.floor(e*t)})),!a)for(var s in o.push("Receives inputs"),i=[],t.nodesByDepth)i.push.apply(i,t.nodesByDepth[s]);r("_".repeat(e)),tn(o,n,r),r("=".repeat(e));for(var u=t.layers,c=0;c<u.length;++c)a?en(u[c],n,r):nn(u[c],n,i,r),r((c===u.length-1?"=":"_").repeat(e));t.checkTrainableWeightsConsistency();var l=function(t){return null!=t.collectedTrainableWeights?ie(t.collectedTrainableWeights):ie(t.trainableWeights)}(t),f=ie(t.nonTrainableWeights);r("Total params: "+(l+f)),r("Trainable params: "+l),r("Non-trainable params: "+f),r("_".repeat(e))}function tn(t,e,n){void 0===n&&(n=console.log);for(var r="",i=0;i<t.length;++i)i>0&&(r=r.slice(0,r.length-1)+" "),r=(r+=t[i]).slice(0,e[i]),r+=" ".repeat(e[i]-r.length);n(r)}function en(t,e,n){var r;try{r=JSON.stringify(t.outputShape)}catch(t){r="multiple"}tn([t.name+" ("+t.getClassName()+")",r,t.countParams().toString()],e,n)}function nn(t,e,n,r){var i;try{i=JSON.stringify(t.outputShape)}catch(t){i="multiple"}for(var a=[],o=0,s=t.inboundNodes;o<s.length;o++){var u=s[o];if(!(null!=n&&n.length>0&&-1===n.indexOf(u)))for(var c=0;c<u.inboundLayers.length;++c){var l=u.inboundLayers[c].name,f=u.nodeIndices[c],d=u.tensorIndices[c];a.push(l+"["+f+"]["+d+"]")}}var h=t.name,p=t.getClassName(),m=0===a.length?"":a[0];for(tn([h+" ("+p+")",i,t.countParams().toString(),m],e,r),c=1;c<a.length;++c)tn(["","","",a[c]],e,r)}function rn(t,e,n){return("inboundNodes"===t||"outputLayers"===t||"inputLayers"===t)&&0===e&&"string"==typeof n}function an(t,e){if(null===t)return null;if("string"==typeof t)return k(t);if("number"==typeof t||"boolean"==typeof t)return t;if(t instanceof Array){for(var n=[],r=t.length,i=0;i<r;++i){var a=t[i];rn(e,i,a)?n.push(a):n.push(an(a,e))}return n}for(var o={},s=0,u=Object.keys(t);s<u.length;s++){var c=u[s],l=t[c];if("name"===c&&"string"==typeof l)o[c]=l;else{var f=k(c);o[f]=an(l,f)}}return o}var on=function(){function t(e){if(this.id2Value={},this.id2Mask={},this.name2Id={},e instanceof t)for(var n in e.id2Value)this.id2Value[n]=e.id2Value[n],n in e.id2Mask&&(this.id2Mask[n]=e.id2Mask[n]);else{if(null==e)return;for(var r=0,i=e;r<i.length;r++){var a=i[r];this.add(a.key,a.value)}}}return t.prototype.add=function(t,e,n){if(null!=this.id2Value[t.id])throw new h("Duplicate key: name="+t.name+", id="+t.id);return this.id2Value[t.id]=function(t,e){if(null==t.dtype||t.dtype===e.dtype)return e;try{return Object(r.cast)(e,t.dtype)}catch(n){throw new h("The dtype of the feed ("+e.dtype+") can not be cast to the dtype of the key '"+t.name+"' ("+t.dtype+").")}}(t,e),this.name2Id[t.name]=t.id,null!=n&&(this.id2Mask[t.id]=n),this},t.prototype.addFeed=function(t){this.add(t.key,t.value)},t.prototype.hasKey=function(t){return null!=this.id2Value[t.id]},t.prototype.names=function(){return Object.keys(this.name2Id)},t.prototype.getValue=function(t){if(t instanceof le){if(null==this.id2Value[t.id])throw new h("Nonexistent key: "+t.name);return this.id2Value[t.id]}var e=this.name2Id[t];if(null==e)throw new h("Feed dict has no SymbolicTensor name: "+t);return this.id2Value[e]},t.prototype.getMask=function(t){if(t instanceof le){if(null==this.id2Value[t.id])throw new h("Nonexistent key: "+t.name);return this.id2Mask[t.id]}var e=this.name2Id[t];if(null==e)throw new h("Feed dict has no SymbolicTensor name: "+t);return this.id2Mask[e]},t.prototype.disposeMasks=function(){null!=this.id2Mask&&Object(r.dispose)(this.id2Mask)},t}(),sn={},un={};function cn(t,e,n,i){for(var a=null!=n&&n.training,o=Array.isArray(t),s=o?t:[t],u=s.map(function(t){return t.name}),c=[],l=e.names(),f=0,d=u;f<d.length;f++){var h=d[f];-1!==l.indexOf(h)?c.push(e.getValue(h)):c.push(null)}null!=i&&(i.maxNumTensors=-1/0,i.minNumTensors=1/0);var p,m,g=u.join(",")+"|"+e.names().join(",");if(null==sn[g]){var v=function(t,e){r.util.assert(null!=t&&t.length>0,function(){return"Expected at least one fetch, got none"});var n=[],i={};if(1===t.length){var a=ln(t[0],e);n=a.sorted,i=a.recipientMap}else for(var o=new Set,s=0,u=t;s<u.length;s++){for(var c=ln(u[s],e),l=c.sorted,f=c.recipientMap,d=0,h=l;d<h.length;d++){var p=h[d];o.has(p.name)||(n.push(p),o.add(p.name))}var m=function(t){null==i[t]&&(i[t]=new Set),f[t].forEach(function(e){return i[t].add(e)})};for(var g in f)m(g)}return{sorted:n,recipientCounts:function(t){var e={};for(var n in t)e[n]=t[n].size;return e}(i)}}(s,e);p=v.sorted,m=v.recipientCounts,sn[g]=p,un[g]=m}p=sn[g],m={},a||Object.assign(m,un[g]);for(var y=new on(e),b=0;b<p.length;++b){if(null!=i){var w=Object(r.memory)().numTensors;w>i.maxNumTensors&&(i.maxNumTensors=w),w<i.minNumTensors&&(i.minNumTensors=w)}var k=p[b],_=k.sourceLayer;if(!(_ instanceof ge)){for(var E=[],O=[],S=[],C=!1,A=0,N=k.inputs;A<N.length;A++){var T=N[A],I=y.getValue(T),D=y.getMask(T);E.push(I),O.push(D),null!=D&&(C=!0),a||(m[T.name]--,0!==m[T.name]||e.hasKey(T)||-1!==u.indexOf(T.name)||I.isDisposed||!0===T.sourceLayer.stateful||S.push(I))}C&&((n=n||{}).mask=O[0]);var M=x(_.apply(E,n)),R=null;_.supportsMasking&&(R=_.computeMask(E,O));for(var F=fn(k),j=Array.isArray(F)?F:[F],P=0;P<j.length;++P){y.hasKey(j[P])||y.add(j[P],M[P],Array.isArray(R)?R[0]:R);var L=u.indexOf(j[P].name);-1!==L&&(c[L]=M[P])}a||Object(r.dispose)(S)}}return y.disposeMasks(),o?c:c[0]}function ln(t,e){for(var n=new Set,r=[],i={},a=0,o=e.names();a<o.length;a++){var s=o[a];n.add(s)}var u=[],c=[];for(u.push(t);u.length>0;){var l=u[u.length-1];if(n.has(l.name))u.pop();else{var f=c[c.length-1]===u.length-1;if(0===l.inputs.length||f)u.pop(),r.push(l),n.add(l.name),f&&c.pop();else{c.push(u.length-1);for(var d=0,h=l.inputs;d<h.length;d++){var p=h[d];null==i[p.name]&&(i[p.name]=new Set),i[p.name].add(l.name),n.has(p.name)||u.push(p)}}}}return{sorted:r,recipientMap:i}}function fn(t){var e;if(1===t.sourceLayer.inboundNodes.length)e=t.sourceLayer.output;else{for(var n=null,r=0;r<t.sourceLayer.inboundNodes.length;++r)for(var i=0,a=t.sourceLayer.inboundNodes[r].outputTensors;i<a.length;i++)if(a[i].id===t.id){n=r;break}e=t.sourceLayer.getOutputAt(n)}return e}function dn(t,e){return function(t,e,n){var r=e.length;if(null==t||Array.isArray(t)&&0===t.length)return e.map(function(t){return null});if(1===r)return Array.isArray(t)&&1===t.length?t:"object"==typeof t&&e[0]in t?[t[e[0]]]:[t];if(Array.isArray(t)){if(t.length!==r)throw new Error("Provided "+n+" is an array of "+t.length+" element(s), but the model has "+r+" outputs. Make sure a set of weights is provided for each model output.");return t}if("object"==typeof t&&Object.keys(t).length>0&&"object"==typeof t[Object.keys(t)[0]]){var i=[];return e.forEach(function(e){e in t?i.push(t[e]):i.push(null)}),i}throw new Error("The model has multiple ("+r+") outputs, so "+n+" must be either an array with "+r+" elements or an object with "+e+" keys. Provided "+n+" not understood: "+JSON.stringify(t))}(t,e,"classWeight")}function hn(t,e,n,i){return u(this,void 0,void 0,function(){var a,o,s,u,l;return c(this,function(c){switch(c.label){case 0:if(null!=e||null!=i)throw new Error("Support sampleWeight is not implemented yet");return null==n?[3,2]:(a=Object(r.tidy)(function(){if(1===t.shape.length)return t.clone();if(2===t.shape.length){if(t.shape[1]>1)return t.argMax(1);if(1===t.shape[1])return t.reshape([t.shape[0]]);throw new Error("Encountered unexpected last-dimension size ("+t.shape[1]+") during handling of class weights. The size is expected to be >= 1.")}throw new Error("Unexpected rank of target (y) tensor ("+t.rank+") during handling of class weights. The rank is expected to be 1 or 2.")}),u=(s=Array).from,[4,a.data()]);case 1:return o=u.apply(s,[c.sent()]),Object(r.dispose)(a),l=[],o.forEach(function(t){if(null==n[t])throw new Error("classWeight must contain all classes in the training data. The class "+t+" exists in the data but not in classWeight");l.push(n[t])}),[2,Object(r.tensor1d)(l,"float32")];case 2:return[2,null]}})})}function pn(t,e){return Object(r.mul)(t,e)}var mn=32;function gn(t,e){var n,i,a=e;n=a.xs,i=a.ys,r.util.assert(null!=n&&null!=i,function(){return"A Dataset iterator for fitDataset() is expected to generate objects of the form `{xs: xVal, ys: yVal}`, where the two values may be `tf.Tensor`, an array of Tensors, or a map of string to Tensor. The provided Dataset instead generates "+e});var o=vn("input",t.inputNames,n),s=vn("output",t.outputNames,i),u=o[0].shape[0];r.util.assert(o.length===t.inputs.length,function(){return"LayersModel has "+t.inputs.length+" inputs, but the dataset provides "+o.length+" inputs. (Expected input keys: "+JSON.stringify(t.inputNames)+")"}),r.util.assert(s.length===t.outputs.length,function(){return"LayersModel has "+t.outputs.length+" outputs, but the dataset provides "+s.length+" outputs. (Expected output keys: "+JSON.stringify(t.outputNames)+")"});for(var c=function(e){r.util.assert(o[e].shape[0]===u,function(){return"Batch size mismatch: input "+t.inputNames[e]+" has "+o[e].shape[0]+"; expected "+u+" based on input "+t.inputNames[0]+"."})},l=0;l<o.length;l++)c(l);for(var f=function(e){r.util.assert(s[e].shape[0]===u,function(){return"Batch size mismatch: output "+t.outputNames[e]+" has "+s[e].shape[0]+"; expected "+u+" based on input "+t.inputNames[0]+"."})},d=0;d<s.length;d++)f(d);return{xs:o,ys:s}}function vn(t,e,n){if(n instanceof r.Tensor)return[n];if(Array.isArray(n))return r.util.assert(n.length===e.length,function(){return"Received an array of "+n.length+" Tensors, but expected "+e.length+" to match the "+t+" keys "+e+"."}),n;for(var i=[],a=0,o=e;a<o.length;a++){var s=o[a];if(null==n[s])throw new h("The feature data generated by the dataset lacks the required "+t+" key '"+s+"'.");i.push(n[s])}return i}function yn(t,e,n){return u(this,void 0,void 0,function(){var i,a,o,s,u,l,f,d,h,m,g,v,y,b,w,k,_,E,O,S,C,A,N,T,I,D,M,R,F,j,P,L,z,B;return c(this,function(c){switch(c.label){case 0:if(i=null!=n.batchesPerEpoch,r.util.assert(null!=t.optimizer,function(){return"You must compile a model before training/testing. Use LayersModel.compile(modelCompileConfig)."}),r.util.assert(null!=n,function(){return"For fitDataset(), the 2nd argument (config) is required, but it is not provided in this call."}),r.util.assert(null!=n.epochs&&n.epochs>0&&Number.isInteger(n.epochs),function(){return"For fitDataset(), config.epochs is expected to be a positive integer, but got "+n.epochs}),r.util.assert(!i||n.batchesPerEpoch>0&&Number.isInteger(n.batchesPerEpoch),function(){return"For fitDataset(), config.batchesPerEpoch is expected to be a positive integer if specified, but got "+n.batchesPerEpoch}),r.util.assert(null==n.validationSplit,function(){return"`validationSplit` is not supported by `fitDataset()`. Use validationData instead."}),t.isTraining)throw new Error("Cannot start training because another fit() call is ongoing.");t.isTraining=!0,c.label=1;case 1:return c.trys.push([1,,26,27]),a=null!=n.validationData,o=void 0,s=void 0,a&&(bn(n.validationData)?r.util.assert(null==n.validationBatches||n.validationBatches>0&&Number.isInteger(n.validationBatches),function(){return"For fitDataset() with dataset-based validation, config.validationBatches is expected not to be provided, or to be a positive integer, but got "+n.validationBatches}):(u=function(t){if(3===t.length)throw new p("Validation with sample weights is not implemented yet.");return{xs:t[0],ys:t[1]}}(n.validationData),o=u.xs,s=u.ys)),l=t.makeTrainFunction(),f=t.getDedupedMetricsNames(),d=void 0,d=a?f.slice().concat(f.map(function(t){return"val_"+t})):f.slice(),h=Se(n.callbacks,n.yieldEvery),m=null==n.verbose?1:n.verbose,g=Ae(h,m,n.epochs,null,null,function(t,e){var n=null;return null!=e.batchesPerEpoch?n=e.batchesPerEpoch:Number.isFinite(t.size)&&(n=t.size),n}(e,n),null,a,d),v=g.callbackList,y=g.history,v.setModel(t),t.history=y,[4,v.onTrainBegin()];case 2:return c.sent(),t.stopTraining_=!1,b=null==n.initialEpoch?0:n.initialEpoch,[4,e.iterator()];case 3:w=c.sent(),c.label=4;case 4:return b<n.epochs?(k={},[4,v.onEpochBegin(b)]):[3,23];case 5:return c.sent(),_=0,E=0,i?[3,7]:[4,e.iterator()];case 6:w=c.sent(),c.label=7;case 7:return!i||_<n.batchesPerEpoch?[4,w.next()]:[3,21];case 8:return O=c.sent(),i&&O.done?(console.warn("You provided `batchesPerEpoch` as "+n.batchesPerEpoch+", but your dataset iterator ran out of data after "+_+" batches; interrupting training. Make sure that your dataset can generate at least `batchesPerEpoch * epochs` batches (in this case, "+n.batchesPerEpoch*n.epochs+" batches). You may need to use the repeat() function when building your dataset."),[3,21]):null==O.value?[3,15]:(S=gn(t,O.value),C=S.xs,A=S.ys,(N={}).batch=E,N.size=C[0].shape[0],[4,v.onBatchBegin(E,N)]);case 9:if(c.sent(),T=[],null==n.classWeight)return[3,13];I=dn(n.classWeight,t.outputNames),B=0,c.label=10;case 10:return B<I.length?(M=(D=T).push,[4,hn(A[B],null,I[B])]):[3,13];case 11:M.apply(D,[c.sent()]),c.label=12;case 12:return++B,[3,10];case 13:for(R=C.concat(A).concat(T),F=l(R),Object(r.dispose)(R),B=0;B<f.length;++B)j=f[B],P=F[B],N[j]=P,Object(r.keep)(P);return[4,v.onBatchEnd(E,N)];case 14:c.sent(),be(N),E++,_++,c.label=15;case 15:return(i?_>=n.batchesPerEpoch:O.done)?a?(L=void 0,bn(n.validationData)?(z=x,[4,t.evaluateDataset(n.validationData,{batches:n.validationBatches})]):[3,17]):[3,19]:[3,20];case 16:return L=z.apply(void 0,[c.sent()]),[3,18];case 17:L=x(t.evaluate(o,s,{batchSize:null==n.validationBatchSize?mn:n.validationBatchSize,verbose:0})),c.label=18;case 18:for(B=0;B<t.metricsNames.length;++B)k["val_"+t.metricsNames[B]]=L[B];c.label=19;case 19:return[3,21];case 20:return t.stopTraining_?[3,21]:[3,7];case 21:return[4,v.onEpochEnd(b,k)];case 22:return c.sent(),b++,t.stopTraining_?[3,23]:[3,4];case 23:return[4,v.onTrainEnd()];case 24:return c.sent(),[4,t.history.syncData()];case 25:return c.sent(),[2,t.history];case 26:return t.isTraining=!1,[7];case 27:return[2]}})})}function bn(t){return"function"==typeof t.iterator}function xn(t){r.util.assert(t>0&&Number.isInteger(t),function(){return"batchSize is required to be a positive integer, but got "+t})}function wn(t,e,n){return null==t?[null]:Array.isArray(t)?t.map(function(t){return ht(t,e,n-e)}):ht(t,e,n-e)}function kn(t,e){return Object(r.tidy)(function(){return null==t?null:Array.isArray(t)?t.map(function(t){return kn(t,e)}):wt(t,"int32"===e.dtype?e:e.toInt())})}function _n(t,e){for(var n=[],r=0,i=null;r<t;)(i=r+e)>=t&&(i=t),n.push([r,i]),r=i;return n}function En(t,e,n,i){return void 0===i&&(i={}),u(this,void 0,void 0,function(){var a,o,s,l,f,d,m,g,v,y,b,x,w,k,_,E,O,S,C,A,N,T;return c(this,function(I){switch(I.label){case 0:if(t.isTraining)throw new Error("Cannot start training because another fit() call is ongoing.");t.isTraining=!0,I.label=1;case 1:return I.trys.push([1,,7,8]),xn(g=null==i.batchSize?32:i.batchSize),v=!1,[4,t.standardizeUserData(e,n,i.sampleWeight,i.classWeight,v,g)];case 2:if(y=I.sent(),a=y[0],o=y[1],m=y[2],b=!1,x=void 0,!(null!=i.validationData&&i.validationData.length>0))return[3,4];if(b=!0,2!==i.validationData.length)throw 3===i.validationData.length?new p("validationData including sample weights is not supported yet."):new h("When passing validation data, it must contain 2 (valX, valY) or 3 (valX, valY, valSampleWeight) items; "+i.validationData+" is invalid.");return s=i.validationData[0],l=i.validationData[1],w=!0,[4,t.standardizeUserData(s,l,null,null,w,g)];case 3:return k=I.sent(),f=k[0],d=k[1],x=f.concat(d),[3,5];case 4:null!=i.validationSplit&&i.validationSplit>0&&i.validationSplit<1?(b=!0,_=Math.floor(a[0].shape[0]*(1-i.validationSplit)),E=a[0].shape[0],f=wn(a,_,E),a=wn(a,0,_),d=wn(o,_,E),o=wn(o,0,_),x=f.concat(d)):null!=i.validationSteps&&(b=!0),I.label=5;case 5:return O=a.concat(o).concat(m),t.checkTrainableWeightsConsistency(),S=t.makeTrainFunction(),C=t.getDedupedMetricsNames(),A=void 0,N=void 0,b?(t.makeTestFunction(),A=t.testFunction,N=C.slice().concat(C.map(function(t){return"val_"+t}))):(A=null,x=[],N=C.slice()),T=Se(i.callbacks,i.yieldEvery),[4,function(t,e,n,i,a,o,s,l,f,d,m,g,v,y,b){return u(this,void 0,void 0,function(){var u,x,w,k,_,E,O,S;return c(this,function(C){switch(C.label){case 0:if(null==a&&(a=32),null==o&&(o=1),null==m&&(m=!0),null==v&&(v=0),u=!1,null!=f&&null!=d&&(u=!0),null!=b&&(u=!0,null==y))throw new h("Can only use `validationSteps` when doing step-wise training, i.e., `stepsPerEpoch` must be set.");return null!=(x=t.checkNumSamples(n,a,y,"steps_per_epoch"))&&(w=lt(0,x)),null==s&&(s=1),k=Ae(l,s,o,v,x,y,a,u,g),_=k.callbackList,E=k.history,_.setModel(t),t.history=E,[4,_.onTrainBegin()];case 1:C.sent(),t.stopTraining_=!1,O=function(o){var s,l,h,g,v;return c(this,function(b){switch(b.label){case 0:return[4,_.onEpochBegin(o)];case 1:if(b.sent(),s={},null==y)return[3,2];throw new p("stepsPerEpoch mode is not implemented yet.");case 2:if("batch"===m)throw new p("batch shuffling is not implemneted yet");m&&r.util.shuffle(w),l=Object(r.tensor1d)(w),h=_n(x,a),g=function(o){var p;return c(this,function(c){switch(c.label){case 0:return p={},[4,_.onBatchBegin(o,p)];case 1:return c.sent(),Object(r.tidy)(function(){var c=h[o][0],m=h[o][1],g=ht(l,c,m-c);p.batch=o,p.size=m-c;for(var v=kn(n,g),y=e(v),b=0;b<i.length;++b){var x=i[b],w=y[b];p[x]=w,Object(r.keep)(w)}if(o===h.length-1&&u){var k=t.testLoop(f,d,a);for(b=0;b<i.length;++b)x=i[b],w=k[b],Object(r.keep)(w),s["val_"+x]=w}}),[4,_.onBatchEnd(o,p)];case 2:return c.sent(),be(p),t.stopTraining_?[2,"break"]:[2]}})},v=0,b.label=3;case 3:return v<h.length?[5,g(v)]:[3,6];case 4:if("break"===b.sent())return[3,6];b.label=5;case 5:return++v,[3,3];case 6:l.dispose(),b.label=7;case 7:return[4,_.onEpochEnd(o,s)];case 8:return b.sent(),t.stopTraining_?[2,"break"]:[2]}})},S=v,C.label=2;case 2:return S<o?[5,O(S)]:[3,5];case 3:if("break"===C.sent())return[3,5];C.label=4;case 4:return++S,[3,2];case 5:return[4,_.onTrainEnd()];case 6:return C.sent(),[4,t.history.syncData()];case 7:return C.sent(),[2,t.history]}})})}(t,S,O,C,g,i.epochs,i.verbose,T,A,x,i.shuffle,N,i.initialEpoch,null,null)];case 6:return[2,I.sent()];case 7:return t.isTraining=!1,Sn(a,e),Sn(o,n),Sn(f,s),Sn(d,l),null!=m&&Object(r.dispose)(m),[7];case 8:return[2]}})})}function On(t){var e=[];t instanceof r.Tensor&&(t=[t]);for(var n=0;n<t.length;++n){var i=t[n];if(1===i.rank)e.push(dt(i,1));else{if(0===i.rank)throw new Error("Expected tensor to be at least 1D, but received a 0D tensor (scalar).");e.push(i)}}return e}function Sn(t,e){if(null!=t){var n=[];if(e instanceof r.Tensor)n.push(e.id);else if(Array.isArray(e))e.forEach(function(t){return n.push(t.id)});else if(null!=e)for(var i in e){var a=e[i];n.push(a.id)}var o=[];if(t instanceof r.Tensor)-1===n.indexOf(t.id)&&o.push(t);else if(Array.isArray(t))t.forEach(function(t){-1===n.indexOf(t.id)&&o.push(t)});else if(null!=t)for(var s in t){var u=t[s];-1===n.indexOf(u.id)&&o.push(u)}o.forEach(function(t){t.isDisposed||t.dispose()})}}function Cn(t){return Array.isArray(t)}function An(t){return!function(t){return t instanceof r.Tensor}(t)&&!Cn(t)}function Nn(t,e,n,r,i){if(void 0===r&&(r=!0),void 0===i&&(i=""),null==e||0===e.length){if(null!=t){var a=!1;if(Cn(t)&&t.length>0)a=!0;else if(An(t)){for(var o in t)if(t.hasOwnProperty(o)){a=!0;break}}else a=!0;if(a)throw new h("Error when checking model "+i+" expected no data, but got "+t)}return[]}if(null==t)return e.map(function(t){return null});var s;if(An(t)){t=t,s=[];for(var u=0,c=e;u<c.length;u++){var l=c[u];if(null==t[l])throw new h('No data provided for "'+l+'". Need data for each key in: '+e);s.push(t[l])}}else if(Cn(t)){if((t=t).length!==e.length)throw new h("Error when checking model "+i+": the Array of Tensors that you are passing to your model is not the size the model expected. Expected to see "+e.length+" Tensor(s), but instead got the following list of Tensor(s): "+t);s=t}else{if(t=t,e.length>1)throw new h("The model "+i+" expects "+e.length+" Tensor(s), but only received one Tensor. Found: Tensor with shape "+t.shape);s=[t]}if(s=On(s),null!=n)for(var f=0;f<e.length;++f)if(null!=n[f]){var d=s[f];if(d.shape.length!==n[f].length)throw new h("Error when checking "+i+": expected "+e[f]+" to have "+n[f].length+" dimension(s). but got array with shape "+d.shape);for(var p=0;p<n[f].length;++p)if(0!==p||r){var m=d.shape[p],g=n[f][p];if(null!=g&&g>=0&&m!==g)throw new h("Error when checking "+i+": expected "+e[f]+" to have shape ["+n[f]+"], but got array with shape ["+d.shape+"].")}}return s}function Tn(t,e,n,r,i){var a;if(void 0===r&&(r=!0),void 0===i&&(i=""),Array.isArray(t)){if(t.length!==e.length)throw new h("Error when checking model "+i+": the Array of Tensors that you are passing to your model is not the size the the model expected. Expected to see "+e.length+" Tensor(s), but instead got "+t.length+" Tensors(s).");a=t}else{if(e.length>1)throw new h("The model expects "+e.length+" "+i+" Tensors, but only received one Tensor. Found: array with shape "+JSON.stringify(t.shape)+".");a=[t]}if(null!=n)for(var o=0;o<e.length;++o)if(null!=n[o]){var s=a[o];if(s.shape.length!==n[o].length)throw new h("Error when checking "+i+": expected "+e[o]+" to have "+n[o].length+" dimension(s), but got array with shape "+JSON.stringify(s.shape));for(var u=0;u<n[o].length;++u)if(0!==u||r){var c=s.shape[u],l=n[o][u];if(null!=l&&l!==c)throw new h("Error when checking "+i+": expected "+e[o]+" to have shape "+JSON.stringify(n[o])+" but got array with shape "+JSON.stringify(s.shape)+".")}}}var In=function(t){function e(e){var n=t.call(this,e)||this;return n.isTraining=!1,n}return a(e,t),e.prototype.summary=function(t,e,n){if(void 0===n&&(n=console.log),!this.built)throw new h("This model has never been called, thus its weights have not been created yet. So no summary can be displayed. Build the model first (e.g., by calling it on some test data).");Qe(this,t,e,n)},e.prototype.compile=function(t){var e=this;if(null==t.loss&&(t.loss=[]),this.loss=t.loss,"string"==typeof t.optimizer)this.optimizer_=function(t){var e={Adagrad:function(){return r.train.adagrad(.01)},Adadelta:function(){return r.train.adadelta(1,.95,l())},Adam:function(){return r.train.adam(.001,.9,.999,l())},Adamax:function(){return r.train.adamax(.002,.9,.999,l(),0)},RMSProp:function(){return r.train.rmsprop(.001,.9,0,l())},SGD:function(){return r.train.sgd(.01)}};if(e.adagrad=e.Adagrad,e.adadelta=e.Adadelta,e.adam=e.Adam,e.adamax=e.Adamax,e.rmsprop=e.RMSProp,e.sgd=e.SGD,t in e)return e[t]();throw new h("Unknown Optimizer "+t)}(t.optimizer),this.isOptimizerOwned=!0;else{if(!(t.optimizer instanceof r.Optimizer))throw new h("User-defined optimizer must be an instance of tf.Optimizer.");this.optimizer_=t.optimizer,this.isOptimizerOwned=!1}var n=[];if(Array.isArray(t.loss)||"string"==typeof t.loss||"function"==typeof t.loss)if(Array.isArray(t.loss)){if(t.loss.length!==this.outputs.length)throw new h("When passing an Array as loss, it should have one entry per model output. The model has "+this.outputs.length+" output(s), but you passed loss="+t.loss+".");var i=t.loss;n=i.map(function(t){return ze(t)})}else{var a=ze(t.loss);this.outputs.forEach(function(t){n.push(a)})}else{for(var o in t.loss=t.loss,t.loss)if(-1===this.outputNames.indexOf(o))throw new h('Unknown entry in loss dictionary: "'+o+'". Only expected the following keys: '+this.outputNames);for(var s=0,u=this.outputNames;s<u.length;s++){var c=u[s];null==t.loss[c]&&console.warn('Output "'+c+'" is missing from loss dictionary. We assume this was done on purpose, and we will not be expecting data to be passed to '+c+" during training"),n.push(ze(t.loss[c]))}}this.lossFunctions=n,this.feedOutputNames=[],this.feedOutputShapes=[],this.feedLossFns=[];for(var f=0;f<this.outputs.length;++f){var d=this.internalOutputShapes[f],p=this.outputNames[f];this.feedOutputNames.push(p),this.feedOutputShapes.push(d),this.feedLossFns.push(this.lossFunctions[f])}var m=[];this.metrics=t.metrics,this.metricsNames=["loss"],this.metricsTensors=[],tt("loss",function(){for(var t=0;t<e.outputs.length;++t)if(-1===m.indexOf(t)){var n=e.lossFunctions[t];e.outputs.length>1&&(e.metricsTensors.push([n,t]),e.metricsNames.push(e.outputNames[t]+"_loss"))}});var g=function(t,e){if(null==t||Array.isArray(t)&&0===t.length)return e.map(function(t){return[]});var n;if("string"==typeof t||"function"==typeof t)n=[t];else{if(!Array.isArray(t)&&"object"!=typeof t)throw new TypeError("Type of metrics argument not understood. Expected an string,function, Array, or Object, found: "+t);n=t}if(Array.isArray(n))return e.map(function(t){return n});for(var r=[],i=0,a=e;i<a.length;i++){var o=a[i],s=n.hasOwnProperty(o)?n[o]:[];Array.isArray(s)||(s=[s]),r.push(s)}return r}(t.metrics,this.outputNames);tt("metric",function(){for(var t=function(t){if(-1!==m.indexOf(t))return"continue";!function(n){for(var r,i,a,o=function(n){if("string"==typeof n&&-1!==["accuracy","acc","crossentropy","ce"].indexOf(n)){var o=e.internalOutputShapes[t];1===o[o.length-1]||e.lossFunctions[t]===je?-1!==["accuracy","acc"].indexOf(n)?i=Be:-1!==["crossentropy","ce"].indexOf(n)&&(i=He):e.lossFunctions[t]===Fe?-1!==["accuracy","acc"].indexOf(n)?i=Ge:-1!==["crossentropy","ce"].indexOf(n)&&(i=Ke):-1!==["accuracy","acc"].indexOf(n)?i=Ue:-1!==["crossentropy","ce"].indexOf(n)&&(i=$e);var s=void 0;-1!==["accuracy","acc"].indexOf(n)?s="acc":-1!==["crossentropy","ce"].indexOf(n)&&(s="ce"),a=i,r=""+s}else{var u=function(t){if("string"==typeof t&&t in Xe)return Xe[t];if("string"!=typeof t&&null!=t)return t;throw new h("Unknown metric "+t)}(n);a=u,r=""+Ye(n)}var c;tt(r,function(){c=a}),function(t,n,r){e.outputNames.length>1&&(n=e.outputNames[t]+"_"+n),e.metricsNames.push(n),e.metricsTensors.push([r,t])}(t,r,c)},s=0,u=g[t];s<u.length;s++)o(u[s])}()},n=0;n<e.outputs.length;++n)t(n)}),this.collectedTrainableWeights=this.trainableWeights},e.prototype.checkTrainableWeightsConsistency=function(){null!=this.collectedTrainableWeights&&this.trainableWeights.length!==this.collectedTrainableWeights.length&&console.warn("Discrepancy between trainableweights and collected trainable weights. Did you set `model.trainable` without calling `model.compile()` afterwards?")},e.prototype.evaluate=function(t,e,n){void 0===n&&(n={});var r=null==n.batchSize?32:n.batchSize;xn(r);var i=this.standardizeUserDataXY(t,e,!0,r);try{var a=i[0].concat(i[1]);this.makeTestFunction();var o=this.testFunction;return b(this.testLoop(o,a,r,n.verbose,n.steps))}finally{Sn(i[0],t),Sn(i[1],e)}},e.prototype.evaluateDataset=function(t,e){return u(this,void 0,void 0,function(){return c(this,function(n){return this.makeTestFunction(),[2,function(t,e,n){return u(this,void 0,void 0,function(){var i,a,o,s,u,l,f,d,h,m;return c(this,function(g){switch(g.label){case 0:if(i=null!=(n=n||{}).batches,a=t.testFunction,o=[],n.verbose>0)throw new p("Verbose mode is not implemented yet.");return r.util.assert(!i||n.batches>0&&Number.isInteger(n.batches),function(){return"Test loop expects `batches` to be a positive integer, but received "+JSON.stringify(n.batches)}),function(t){return"function"==typeof t.next}(e)?(u=e,[3,3]):[3,1];case 1:return[4,e.iterator()];case 2:u=g.sent(),g.label=3;case 3:s=u,l=0,f=0,d=function(){var e;return c(this,function(u){switch(u.label){case 0:return[4,s.next()];case 1:return e=u.sent(),o=Object(r.tidy)(function(){if(e.value){var n=gn(t,e.value),i=n.xs,s=n.ys,u=i.concat(s),c=Object(r.tidy)(function(){return a(u)});if(Object(r.dispose)(u),0===f)for(var d=0;d<c.length;++d)o.push(Object(r.scalar)(0));var h=u[0].shape[0],p=function(t){var e=c[t],n=o[t];o[t]=Object(r.tidy)(function(){return Object(r.add)(o[t],Object(r.mul)(h,e))}),f>0&&Object(r.dispose)(n)};for(d=0;d<c.length;++d)p(d);Object(r.dispose)(c),l+=h,++f}return o}),e.done?(i&&console.warn("Your dataset iterator ran out of data during evaluateDataset(). Interrupting evalution. Make sure that your dataset can generate at least `batches` batches (in this case, "+n.batches+" batches). You may need to use the repeat() function when building your dataset."),[2,"break"]):[2]}})},g.label=4;case 4:return!i||f<n.batches?[5,d()]:[3,6];case 5:return"break"===g.sent()?[3,6]:[3,4];case 6:for(h=0;h<o.length;++h)m=o[h],o[h]=Object(r.div)(o[h],l),Object(r.dispose)(m);return[2,b(o)]}})})}(this,t,e)]})})},e.prototype.checkNumSamples=function(t,e,n,r){var i;if(void 0===r&&(r="steps"),null!=n){if(i=null,null!=e)throw new h("If "+r+" is set, batchSize must be null or undefined.Got batchSize = "+e)}else{if(null==t)throw new h("Either the input data should have a defined shape, or "+r+" shoud be specified.");i=Array.isArray(t)?t[0].shape[0]:t.shape[0]}return i},e.prototype.execute=function(t,e){if(Array.isArray(e)&&0===e.length)throw new h("`outputs` is an empty Array, which is not allowed.");var n=Array.isArray(e),i=n?e:[e],a=this.retrieveSymbolicTensors(i),o=new on;if(t instanceof r.Tensor&&(t=[t]),Array.isArray(t)){if(t.length!==this.inputs.length)throw new h("The number of inputs provided ("+t.length+") does not match the number of inputs of this model ("+this.inputs.length+").");for(var s=0;s<this.inputs.length;++s)o.add(this.inputs[s],t[s])}else for(var u=0,c=this.inputs;u<c.length;u++){var l=c[u],f=t[l.name];if(null==f)throw new h("No value is provided for the model's input "+l.name);o.add(l,f)}var d=cn(a,o);return n?d:d[0]},e.prototype.retrieveSymbolicTensors=function(t){for(var e=g(null,t.length),n=t.length,r=0,i=this.layers;r<i.length;r++){for(var a=i[r],o=Array.isArray(a.output)?a.output:[a.output],s=o.map(function(t){return t.name}),u=0;u<t.length;++u){var c=s.indexOf(t[u]);if(-1!==c&&(e[u]=o[c],n--),0===n)break}if(0===n)break}if(n>0){var l=[];throw e.forEach(function(e,n){null==e&&l.push(t[n])}),new h("Cannot find SymbolicTensors for output name(s): "+JSON.stringify(l))}return e},e.prototype.predictLoop=function(t,e,n){var i=this;return void 0===e&&(e=32),void 0===n&&(n=!1),Object(r.tidy)(function(){var a=i.checkNumSamples(t);if(n)throw new p("Verbose predictLoop() is not implemented yet.");for(var o=_n(a,e),s=i.outputs.map(function(t){return[]}),u=function(e){Object(r.tidy)(function(){var n=o[e][0],r=o[e][1],a=wn(t,n,r),s=[];if(Array.isArray(a))for(var u=0;u<a.length;++u)s.push({key:i.inputs[u],value:a[u]});else s.push({key:i.inputs[0],value:a});var c=new on(s);return cn(i.outputs,c)}).forEach(function(t,e){return s[e].push(t)})},c=0;c<o.length;++c)u(c);return b(s.map(function(t){return Object(r.concat)(t,0)}))})},e.prototype.predict=function(t,e){void 0===e&&(e={});var n=On(t);Tn(n,this.inputNames,this.feedInputShapes,!1);try{var r=null==e.batchSize?32:e.batchSize;return xn(r),this.predictLoop(n,r)}finally{Sn(n,t)}},e.prototype.predictOnBatch=function(t){Tn(t,this.inputNames,this.feedInputShapes,!0);var e=(Array.isArray(t)?t[0]:t).shape[0];return this.predictLoop(t,e)},e.prototype.standardizeUserDataXY=function(t,e,n,i){if(void 0===n&&(n=!0),null==this.optimizer_)throw new d("You must compile a model before training/testing. Use LayersModel.compile(modelCompileArgs).");for(var a=[],o=0;o<this.feedOutputShapes.length;++o){var s=this.feedOutputShapes[o];this.feedLossFns[o]===Fe?a.push(s.slice(0,s.length-1).concat([1])):a.push(s)}if(function(t,e,n){var i=C(t.map(function(t){return t.shape[0]}));i.sort();var a=C(e.map(function(t){return t.shape[0]}));if(a.sort(),i.length>1)throw new h("All input Tensors (x) should have the same number of samples. Got array shapes: "+JSON.stringify(t.map(function(t){return t.shape})));if(a.length>1)throw new h("All target Tensors (y) should have the same number of samples. Got array shapes: "+JSON.stringify(e.map(function(t){return t.shape})));if(i.length>0&&a.length>0&&!r.util.arraysEqual(i,a))throw new h("Input Tensors should have the same number of samples as target Tensors. Found "+i[0]+" input sample(s) and "+a[0]+" target sample(s).")}(t=Nn(t,this.feedInputNames,this.feedInputShapes,!1,"input"),e=Nn(e,this.feedOutputNames,a,!1,"target")),function(t,e,n){for(var r=[Ie,je,Re],i=0;i<t.length;++i){var a=t[i],o=e[i],s=n[i];if(null!=o){if(o===Re&&1===a.shape[a.shape.length-1])throw new h("You are passing a target array of shape "+a.shape+" while using a loss 'categorical_crossentropy'. 'categorical_crossentropy'expects targets to be binary matrices (1s and 0s) of shape [samples, classes].");if(-1!==r.indexOf(o))for(var u=a.shape.slice(1),c=s.slice(1),l=0;l<u.length;++l){var f=u[l],d=c[l];if(null!=d&&f!==d)throw new h("A target Tensor with shape "+a.shape+" was passed for an output of shape "+s+", while using a loss function that expects targets to have the same shape as the output.")}}}}(e,this.feedLossFns,this.feedOutputShapes),this.stateful&&null!=i&&i>0&&t[0].shape[0]%i!=0)throw new h("In a stateful network, you should only pass inputs with a number of samples that is divisible by the batch size "+i+". Found: "+t[0].shape[0]+" sample(s).");return[t,e]},e.prototype.standardizeUserData=function(t,e,n,r,i,a){return void 0===i&&(i=!0),u(this,void 0,void 0,function(){var o,s,u,l,f,d,h,p;return c(this,function(c){switch(c.label){case 0:if(o=this.standardizeUserDataXY(t,e,i,a),s=o[0],u=o[1],null!=n)throw new Error("sample weight is not supported yet.");if(l=null,null==r)return[3,4];f=dn(r,this.outputNames),l=[],d=0,c.label=1;case 1:return d<f.length?(p=(h=l).push,[4,hn(u[d],null,f[d])]):[3,4];case 2:p.apply(h,[c.sent()]),c.label=3;case 3:return++d,[3,1];case 4:return[2,[s,u,l]]}})})},e.prototype.testLoop=function(t,e,n,i,a){var o=this;return void 0===i&&(i=0),Object(r.tidy)(function(){var s=o.checkNumSamples(e,n,a,"steps"),u=[];if(i>0)throw new p("Verbose mode is not implemented yet.");if(null!=a)throw new p("steps mode in testLoop() is not implemented yet");for(var c=_n(s,n),l=Object(r.tensor1d)(lt(0,s)),f=0;f<c.length;++f){var d=c[f][0],h=c[f][1],m=ht(l,d,h-d),g=kn(e,m),v=t(g);if(0===f)for(var y=0;y<v.length;++y)u.push(Object(r.scalar)(0));for(y=0;y<v.length;++y){var b=v[y];u[y]=Object(r.add)(u[y],Object(r.mul)(h-d,b))}}for(y=0;y<u.length;++y)u[y]=Object(r.div)(u[y],s);return u})},e.prototype.getDedupedMetricsNames=function(){for(var t=this.metricsNames,e=[],n=0;n<t.length;++n){var r=t[n],i=r;y(t,r)>1&&(i+="_"+y(t.slice(0,n),r)),e.push(i)}return e},e.prototype.makeTrainFunction=function(){var t=this;return function(e){var n=[],i=e.slice(0,t.inputs.length),a=e.slice(t.inputs.length,t.inputs.length+t.outputs.length),o=e.slice(t.inputs.length+t.outputs.length,t.inputs.length+2*t.outputs.length),s=[],u=t.collectedTrainableWeights.map(function(t){return t.read()});return[t.optimizer_.minimize(function(){for(var e=[],u=0;u<t.inputs.length;++u)e.push({key:t.inputs[u],value:i[u]});var c,l=new on(e),f=cn(t.outputs,l,{training:!0});for(u=0;u<t.lossFunctions.length;++u){var d=(0,t.lossFunctions[u])(a[u],f[u]);null!=o[u]&&(d=pn(d,o[u]));var h=Object(r.mean)(d);n.push(h),c=0===u?d:Object(r.add)(c,d)}for(u=0;u<t.metricsTensors.length;++u){var p=void 0;if(t.outputs.length>1&&u<t.outputs.length)p=n[u];else{var m=t.metricsTensors[u][0],g=t.metricsTensors[u][1];p=Object(r.mean)(m(a[g],f[g]))}Object(r.keep)(p),s.push(p)}return c=Object(r.mean)(c),t.calculateLosses().forEach(function(t){c=Object(r.add)(c,t)}),c},!0,u)].concat(s)}},e.prototype.makeTestFunction=function(){var t=this;this.testFunction=function(e){return Object(r.tidy)(function(){for(var n,i=[],a=e.slice(0,t.inputs.length),o=e.slice(t.inputs.length,t.inputs.length+t.outputs.length),s=[],u=0;u<t.inputs.length;++u)s.push({key:t.inputs[u],value:a[u]});var c=new on(s),l=cn(t.outputs,c);for(u=0;u<t.lossFunctions.length;++u){var f=t.lossFunctions[u],d=Object(r.mean)(f(o[u],l[u]));n=0===u?d:Object(r.add)(n,d),i.push(n)}for(u=0;u<t.metricsTensors.length;++u){var h=t.metricsTensors[u][0],p=t.metricsTensors[u][1],m=Object(r.mean)(h(o[p],l[p]));i.push(m)}return i})}},e.prototype.fit=function(t,e,n){return void 0===n&&(n={}),u(this,void 0,void 0,function(){return c(this,function(r){return[2,En(this,t,e,n)]})})},e.prototype.fitDataset=function(t,e){return u(this,void 0,void 0,function(){return c(this,function(n){return[2,yn(this,t,e)]})})},e.prototype.trainOnBatch=function(t,e){return u(this,void 0,void 0,function(){var n,i,a,o,s,u,l,f,d;return c(this,function(c){switch(c.label){case 0:return[4,this.standardizeUserData(t,e)];case 1:n=c.sent(),i=n[0],a=n[1],o=this.makeTrainFunction(),s=o(i.concat(a)),u=[],l=0,f=s,c.label=2;case 2:return l<f.length?[4,f[l].data()]:[3,5];case 3:d=c.sent(),u.push(d[0]),c.label=4;case 4:return l++,[3,2];case 5:return Object(r.dispose)(s),[2,b(u)]}})})},e.prototype.getNamedWeights=function(t){for(var e=[],n=null!=t&&t.trainableOnly,r=n?this.trainableWeights:this.weights,i=this.getWeights(n),a=0;a<r.length;++a)n&&!r[a].trainable||e.push({name:r[a].originalName,tensor:i[a]});return e},Object.defineProperty(e.prototype,"stopTraining",{get:function(){return this.stopTraining_},set:function(t){this.stopTraining_=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"optimizer",{get:function(){return this.optimizer_},set:function(t){this.optimizer_!==t&&(this.optimizer_=t,this.isOptimizerOwned=!1)},enumerable:!0,configurable:!0}),e.prototype.dispose=function(){var e=t.prototype.dispose.call(this);if(0===e.refCountAfterDispose&&null!=this.optimizer&&this.isOptimizerOwned){var n=Object(r.memory)().numTensors;this.optimizer_.dispose(),e.numDisposedVariables+=n-Object(r.memory)().numTensors}return e},e.prototype.getLossIdentifiers=function(){var t;if("string"==typeof this.loss)t=w(this.loss);else if(Array.isArray(this.loss)){for(var e=0,n=this.loss;e<n.length;e++)if("string"!=typeof n[e])throw new Error("Serialization of non-string loss is not supported.");t=this.loss.map(function(t){return w(t)})}else{var r=Object.keys(this.loss);t={};for(var i=this.loss,a=0,o=r;a<o.length;a++){var s=o[a];if("string"!=typeof i[s])throw new Error("Serialization of non-string loss is not supported.");t[s]=w(i[s])}}return t},e.prototype.getMetricIdentifiers=function(){if("string"==typeof this.metrics||"function"==typeof this.metrics)return[w(Ye(this.metrics))];if(Array.isArray(this.metrics))return this.metrics.map(function(t){return w(Ye(t))});var t={};for(var e in this.metrics)t[e]=w(Ye(this.metrics[e]));return t},e.prototype.getTrainingConfig=function(){return{loss:this.getLossIdentifiers(),metrics:this.getMetricIdentifiers(),optimizer_config:{class_name:this.optimizer.getClassName(),config:this.optimizer.getConfig()}}},e.prototype.loadTrainingConfig=function(t){if(null!=t.weighted_metrics)throw new Error("Loading weight_metrics is not supported yet.");if(null!=t.loss_weights)throw new Error("Loading loss_weights is not supported yet.");if(null!=t.sample_weight_mode)throw new Error("Loading sample_weight_mode is not supported yet.");var e,n,r=Ne(an(t.optimizer_config));if("string"==typeof t.loss)e=k(t.loss);else if(Array.isArray(t.loss))e=t.loss.map(function(t){return k(t)});else if(null!=t.loss)for(var i in e={},t.loss)e[i]=k(t.loss[i]);if(Array.isArray(t.metrics))n=t.metrics.map(function(t){return k(t)});else if(null!=t.metrics)for(var i in n={},t.metrics)n[i]=k(t.metrics[i]);this.compile({loss:e,metrics:n,optimizer:r})},e.prototype.save=function(t,e){return u(this,void 0,void 0,function(){var n,i,a,o,s,u,l,f,d,p,m,g,v,y;return c(this,function(c){switch(c.label){case 0:if("string"==typeof t){if(0===(n=r.io.getSaveHandlers(t)).length)throw new h("Cannot find any save handlers for URL '"+t+"'");if(n.length>1)throw new h("Found more than one ("+n.length+") save handlers for URL '"+t+"'");t=n[0]}if(null==t.save)throw new h("LayersModel.save() cannot proceed because the IOHandler provided does not have the `save` attribute defined.");return[4,r.io.encodeWeights(this.getNamedWeights(e))];case 1:return i=c.sent(),a=!1,o=null,s=this.toJSON(o,a),u={modelTopology:s,format:"layers-model",generatedBy:"TensorFlow.js tfjs-layers v1.7.2",convertedBy:null},null!=e&&e.includeOptimizer&&null!=this.optimizer?(u.trainingConfig=this.getTrainingConfig(),l="optimizer",g=(m=r.io).encodeWeights,[4,this.optimizer.getWeights()]):[3,4];case 2:return[4,g.apply(m,[c.sent(),l])];case 3:f=c.sent(),d=f.data,p=f.specs,(y=i.specs).push.apply(y,p),i.data=r.io.concatenateArrayBuffers([i.data,d]),c.label=4;case 4:return null!=this.userDefinedMetadata&&(v=!0,Ze(this.userDefinedMetadata,this.name,v),u.userDefinedMetadata=this.userDefinedMetadata),u.weightData=i.data,u.weightSpecs=i.specs,[2,t.save(u)]}})})},e.prototype.setUserDefinedMetadata=function(t){Ze(t,this.name),this.userDefinedMetadata=t},e.prototype.getUserDefinedMetadata=function(){return this.userDefinedMetadata},e.className="Model",e}(function(t){function e(n){var r=t.call(this,{})||this;if(r.containerNodes=new Set,r.name=n.name,null==r.name){var i=r.getClassName().toLowerCase();r.name=Qt(i)}if(r.supportsMasking=!1,r.trainable_=!0,Array.isArray(n.inputs)?r.inputs=n.inputs.slice():r.inputs=[n.inputs],Array.isArray(n.outputs)?r.outputs=n.outputs.slice():r.outputs=[n.outputs],C(r.inputs).length!==r.inputs.length)throw new h("The list of inputs passed to the model is redundant. All inputs should only appear once. Found: "+r.inputs.map(function(t){return t.name}));C(r.outputs).length!==r.outputs.length&&console.warn("The list of outputs passed to the model is redundant. All outputs should only appear once. Found: "+r.outputs.map(function(t){return t.name})),r.inputLayers=[],r.inputLayersNodeIndices=[],r.inputLayersTensorIndices=[],r.outputLayers=[],r.outputLayersNodeIndices=[],r.outputLayersTensorIndices=[],r.layers=[],r.internalContainerRefs=[];for(var a=0,o=r.outputs;a<o.length;a++){var s=(I=o[a]).sourceLayer,u=I.nodeIndex,c=I.tensorIndex;r.outputLayers.push(s),r.outputLayersNodeIndices.push(u),r.outputLayersTensorIndices.push(c)}for(var l=0,f=r.inputs;l<f.length;l++)s=(I=f[l]).sourceLayer,u=I.nodeIndex,c=I.tensorIndex,v(0===u,"input layer has >1 nodes"),v(0===c,"input layer has >1 tensors"),r.inputLayers.push(s),r.inputLayersNodeIndices.push(u),r.inputLayersTensorIndices.push(c);r.inputNames=[],r.outputNames=[],r.feedInputShapes=[],r.feedInputNames=[],r.feedOutputNames=[];for(var p=0;p<r.inputLayers.length;p++){if(!((s=r.inputLayers[p])instanceof ge))throw new TypeError("Input layers to a LayersModel must be InputLayer objects. Received inputs: "+n.inputs+". Input "+p+" (0-based) originates from layer type "+s.getClassName()+".");r.inputNames.push(s.name),r.feedInputShapes.push(s.batchInputShape),r.feedInputNames.push(s.name)}for(var m=0,g=r.outputLayers;m<g.length;m++)s=g[m],r.outputNames.push(s.name);r.internalInputShapes=r.inputs.map(function(t){return t.shape}),r.internalOutputShapes=r.outputs.map(function(t){return t.shape});for(var y={},b={},x={},w={},k={},_=[],E=function(t,n,i,a,o,s){null!=a&&null!=o&&null!=s||(a=t.sourceLayer,o=t.nodeIndex,s=t.tensorIndex);var u=a.inboundNodes[o];if(-1!==i.indexOf(u))throw new d("The tensor "+t.name+' at layer "'+a.name+'" is part of a cycle.');if(-1===n.indexOf(u)){r.containerNodes.add(e.nodeKey(a,o)),a.id in k||(k[a.id]=Object.keys(k).length),-1===i.indexOf(u)&&i.push(u);for(var c=u.inboundLayers.length,l=0;l<c;l++){var f=u.inputTensors[l],h=u.inboundLayers[l],p=u.nodeIndices[l],m=u.tensorIndices[l];E(f,n,i,h,p,m)}for(n.push(u);i.indexOf(u)>=0;)i.splice(i.indexOf(u),1);_.push(u)}},O=[],A=[],N=0,T=r.outputs;N<T.length;N++){var I=T[N];E(I,O,A)}for(var D=0,M=_.slice().reverse();D<M.length;D++){b[(et=M[D]).id]=et,et.id in y||(y[et.id]=0);var R=y[et.id],F=null==x[et.outboundLayer.id]?0:x[et.outboundLayer.id];for(R=Math.max(R,F),x[et.outboundLayer.id]=R,w[et.outboundLayer.id]=et.outboundLayer,y[et.id]=R,p=0;p<et.inboundLayers.length;p++){var j=et.inboundLayers[p],P=(u=et.nodeIndices[p],j.inboundNodes[u]),L=null==y[P.id]?0:y[P.id];y[P.id]=Math.max(R+1,L),b[P.id]=P}}var z={};for(var B in y)(R=y[B])in z||(z[R]=[]),z[R].push(b[B]);var U={};for(var W in x)(R=x[W])in U||(U[R]=[]),U[R].push(w[W]);var V=Object.keys(U).map(function(t){return parseInt(t,10)}).sort(S);r.layers=[];for(var q=0,H=V;q<H.length;q++){var G=U[R=H[q]];G.sort(function(t,e){var n=k[t.id],r=k[e.id];return n<r?-1:n>r?1:0});for(var $=0,K=G;$<K.length;$++)(s=K[$])instanceof e&&r.internalContainerRefs.push(s),r.layers.push(s)}r.layersByDepth=U,V=Object.keys(z).map(function(t){return parseInt(t,10)}).sort(S);for(var X=r.inputs.slice(),Y=[],J=0,Z=V;J<Z.length;J++)for(var Q=0,tt=z[R=Z[J]];Q<tt.length;Q++){var et;if(null!=(s=(et=tt[Q]).outboundLayer)){for(var nt=0,rt=et.inputTensors;nt<rt.length;nt++)if(I=rt[nt],-1===X.indexOf(I))throw new d("Graph disconnected: cannot obtain value for tensor "+I+' at layer "'+s.name+'". The following previous layers were accessed without issue: '+Y);for(var it=0,at=et.outputTensors;it<at.length;it++)I=at[it],X.push(I);Y.push(s.name)}}r.nodesByDepth=z;for(var ot=r.layers.map(function(t){return t.name}),st=function(t){var e=ot.filter(function(e){return e===t}).length;if(1!==e)throw new d('The name "'+t+'" is used '+e+" times in the model. All layer names should be unique. Layer names: "+JSON.stringify(ot))},ut=0,ct=ot;ut<ct.length;ut++)st(ct[ut]);return r.outboundNodes=[],r.inboundNodes=[],new de({outboundLayer:r,inboundLayers:[],nodeIndices:[],tensorIndices:[],inputTensors:r.inputs,outputTensors:r.outputs,inputMasks:r.inputs.map(function(t){return null}),outputMasks:r.outputs.map(function(t){return null}),inputShapes:r.inputs.map(function(t){return t.shape}),outputShapes:r.outputs.map(function(t){return t.shape})}),r.built=!0,r._refCount=1,r}return a(e,t),e.prototype.assertNotDisposed=function(){if(0===this._refCount)throw new Error("Container '"+this.name+"' is already disposed.")},e.prototype.dispose=function(){this.assertNotDisposed();var t={refCountAfterDispose:null,numDisposedVariables:0};if(0==--this._refCount){for(var e=0,n=this.layers;e<n.length;e++){var r=n[e];t.numDisposedVariables+=r.dispose().numDisposedVariables}for(var i=0,a=this.internalContainerRefs;i<a.length;i++){var o=a[i];t.numDisposedVariables+=o.dispose().numDisposedVariables}}return t.refCountAfterDispose=this._refCount,t},Object.defineProperty(e.prototype,"trainable",{get:function(){return this.trainable_},set:function(t){this.layers.forEach(function(e){e._trainableWeights.forEach(function(e){return e.trainable=t})}),this.trainable_=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"trainableWeights",{get:function(){if(this._trainableWeights.length>0)throw new h("Container instance unexpectedly contains _trainableWeights.The trainable weights of a Container are a union of the trainable weights of its consituent Layers. Its own _trainableWeights must remain an empty Array.");if(!this.trainable)return[];for(var t=[],e=0,n=this.layers;e<n.length;e++){var r=n[e];t=t.concat(r.trainableWeights)}return t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"nonTrainableWeights",{get:function(){for(var t=[],e=0,n=this.layers;e<n.length;e++){var r=n[e];t.push.apply(t,r.nonTrainableWeights)}if(!this.trainable){for(var i=[],a=0,o=this.layers;a<o.length;a++)r=o[a],i.push.apply(i,r.trainableWeights);return i.concat(t)}return t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"weights",{get:function(){return this.trainableWeights.concat(this.nonTrainableWeights)},enumerable:!0,configurable:!0}),e.prototype.loadWeights=function(t,e){void 0===e&&(e=!0);for(var n={},r=0,i=0,a=this.layers;i<a.length;i++)for(var o=0,s=a[i].weights;o<s.length;o++){var u=s[o];if(null!=n[u.originalName])throw new h("Duplicate weight name: "+u.originalName);n[u.originalName]=u,r++}var c=[];for(var l in t){if(null!=n[l])c.push([n[l],t[l]]);else if(e)throw new h("Provided weight data has no target variable: "+l);delete n[l]}if(e){var f=[];for(var d in n)f.push(d);if(f.length>0)throw new h(f.length+" of "+r+" weights are not set: "+f)}ue(c)},e.prototype.updatedConfig=function(){var t=this.getConfig(),e={};return e.className=this.getClassName(),e.config=t,e.kerasVersion="tfjs-layers 1.7.2",e.backend="TensorFlow.js",e},e.prototype.toJSON=function(t,e){void 0===e&&(e=!0);var n=function t(e,n){if(null===e||void 0===e)return null;if("string"==typeof e)return w(e);if("number"==typeof e||"boolean"==typeof e)return e;if(e instanceof Array){for(var r=[],i=e.length,a=0;a<i;++a){var o=e[a];rn(n,a,o)?r.push(o):r.push(t(o,n))}return r}for(var s={},u=0,c=Object.keys(e);u<c.length;u++){var l=c[u],f=e[l];s[w(l)]="name"!==l&&"className"!==l||"string"!=typeof f?t(f,l):f}return s}(this.updatedConfig());return e?JSON.stringify(n):n},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){t=x(t);for(var r=new on,i=0;i<n.inputs.length;++i)r.add(n.inputs[i],t[i]);return cn(n.outputs,r,e)})},e.prototype.computeMask=function(t,e){var n=this;return Object(r.tidy)(function(){var r;return t=x(t),r=null==e?g(null,t.length):x(e),n.runInternalGraph(t,r)[1]})},e.prototype.computeOutputShape=function(t){var e=ee(t);if(e.length!==this.inputLayers.length)throw new h("Invalid inputShape argument "+t+": model has "+this.inputLayers.length+" tensor inputs.");for(var n={},r=0;r<e.length;r++){var i=this.inputLayers[r],a=e[r];n[C=i.name+"_0_0"]=a}var o=Object.keys(this.nodesByDepth).map(function(t){return parseInt(t,10)}).sort(S);if(o.length>1)for(var s=0,u=o;s<u.length;s++)for(var c=u[s],l=0,f=this.nodesByDepth[c];l<f.length;l++){var d=f[l];if(i=d.outboundLayer,-1===this.inputLayers.map(function(t){return t.id}).indexOf(i.id)){for(var p=[],m=0;m<d.inboundLayers.length;m++){var g=d.inboundLayers[m],y=d.nodeIndices[m],x=d.tensorIndices[m],w=n[C=g.name+"_"+y+"_"+x];p.push(w)}var k=ee(i.computeOutputShape(b(p))),_=i.inboundNodes.indexOf(d);for(m=0;m<k.length;m++)n[C=i.name+"_"+_+"_"+m]=k[m]}}var E=[],O=[];for(r=0;r<this.outputLayers.length;r++){i=this.outputLayers[r],_=this.outputLayersNodeIndices[r],x=this.outputLayersTensorIndices[r];var C=i.name+"_"+_+"_"+x;O.push(C)}for(r=0;r<O.length;r++){var A=O[r];v(A in n),E.push(n[A])}return b(E)},e.prototype.runInternalGraph=function(t,e){null==e&&(e=g(null,t.length));for(var n={},r=0;r<this.inputs.length;++r){var i=this.inputs[r],a=t[r],o=e[r];n[i.id]=[a,o]}for(var s=0,u=Object.keys(this.nodesByDepth).map(function(t){return parseInt(t,10)}).sort(S);s<u.length;s++)for(var c=u[s],l=0,f=this.nodesByDepth[c];l<f.length;l++){for(var d=f[l],h=d.outboundLayer,m=d.inputTensors,y=d.outputTensors,b=new Array,w=0,k=m;w<k.length;w++)(i=k[w]).id in n&&b.push(n[i.id]);if(b.length===m.length){var _={},E=void 0,O=void 0,C=void 0,A=void 0;if(null!=d.callArgs&&(_=d.callArgs),1===b.length){var N=b[0],T=N[0],I=N[1];null==_.mask&&(_.mask=I),C=x(h.call(T,_)),A=x(h.computeMask(T,I)),E=[T],O=[I]}else E=b.map(function(t){return t[0]}),O=b.map(function(t){return t[1]}),null==_.mask&&(_.mask=O),C=x(h.call(E,_)),A=x(h.computeMask(E,O));if(h.activityRegularizer)throw new p("LayersModel invocation with concrete Tensor value(s) in the presence of activity regularizer(s) is not supported yet.");for(r=0;r<y.length;++r)i=y[r],a=C[r],o=A[r],n[i.id]=[a,o]}}for(var D=[],M=[],R=[],F=0,j=this.outputs;F<j.length;F++){v((i=j[F]).id in n,"Could not compute output "+i.name+" : "+i.id);var P=n[i.id],L=P[0];o=P[1],R.push(L.shape),D.push(L),M.push(o)}return[D,M,R]},e.prototype.buildNodeConversionMap=function(t){for(var n,r={},i=0,a=this.layers;i<a.length;i++){var o=a[i];n=o instanceof e?1:0;for(var s=0;s<o.inboundNodes.length;s++){var u=e.nodeKey(o,s);this.containerNodes.has(u)&&(r[u]=n,n+=1)}}return r},e.prototype.getLayer=function(t,e){if(null!=e){if(this.layers.length<=e)throw new h("Was asked to retrieve layer at index "+e+", but model only has "+this.layers.length+" layer(s).");return this.layers[e]}if(null==t)throw new h("Provide either a layer name or layer index");for(var n=0,r=this.layers;n<r.length;n++){var i=r[n];if(i.name===t)return i}throw new h("No such layer: "+t)},e.prototype.calculateLosses=function(){var t=this;return Object(r.tidy)(function(){for(var n=[],r=0,i=t.layers;r<i.length;r++)for(var a=i[r],o=0;o<a.inboundNodes.length;++o){var s=e.nodeKey(a,o);t.containerNodes.has(s)&&n.push.apply(n,a.calculateLosses())}return n})},e.prototype.getConfig=function(){for(var t={name:this.name},n=this.buildNodeConversionMap(this.layers),r=[],i=0,a=this.layers;i<a.length;i++){for(var o=(x=a[i]).getClassName(),s=x.getConfig(),u=[],c=0;c<x.inboundNodes.length;c++){var l=x.inboundNodes[c],f=e.nodeKey(x,c),d={};if(this.containerNodes.has(f)){if(l.callArgs)try{JSON.stringify(l.callArgs),d=l.callArgs}catch(t){console.warn("Layer "+x.name+" was passed non-serializable keyword arguments: "+l.callArgs+". They will not be included in the serialized model (and thus will be missing at deserialization time)."),d={}}if(l.inboundLayers.length>0){for(var h=[],p=0;p<l.inboundLayers.length;p++){var m=l.inboundLayers[p],g=l.nodeIndices[p],v=l.tensorIndices[p];null==(k=n[e.nodeKey(m,g)])&&(k=0),h.push([m.name,k,v,d])}u.push(h)}}}var y={};y.name=x.name,y.className=o,y.config=s,y.inboundNodes=u,r.push(y)}t.layers=r;var b=[];for(p=0;p<this.inputLayers.length;p++){var x=this.inputLayers[p];g=this.inputLayersNodeIndices[p],f=e.nodeKey(x,g),this.containerNodes.has(f)&&(null!==(k=n[f])&&void 0!==k||(k=0),v=this.inputLayersTensorIndices[p],b.push([x.name,k,v]))}t.inputLayers=b;var w=[];for(p=0;p<this.outputLayers.length;p++){var k;if(x=this.outputLayers[p],g=this.outputLayersNodeIndices[p],f=e.nodeKey(x,g),this.containerNodes.has(f))null!==(k=n[f])&&void 0!==k||(k=0),v=this.outputLayersTensorIndices[p],w.push([x.name,k,v])}return t.outputLayers=w,t},e.fromConfig=function(t,e,n,r){void 0===n&&(n={}),void 0===r&&(r=!1);var i={},a={};function o(t,e){t.name in a?a[t.name].push(e):a[t.name]=[e]}function s(t,e){for(var n,r=[],a=0,s=e;a<s.length;a++){var u=s[a],c=u[0],l=u[1],f=u[2];if(n=null==u[3]?{}:u[3],!(c in i))return void o(t,e);var d=i[c];if(d.inboundNodes.length<=l)return void o(t,e);var h=d.inboundNodes[l];r.push(h.outputTensors[f])}r.length>0&&t.apply(b(r),n)}function u(t){var n=t.name,a=Ne(t,null!=e.customObjects?e.customObjects:{});a.setFastWeightInitDuringBuild(r),i[n]=a,t.inboundNodes.forEach(function(t){if(!(t instanceof Array))throw new h("Corrupted configuration, expected array for nodeData: "+t);o(a,t)})}for(var c=e.name,l=e.layers,f=0,d=l;f<d.length;f++)u(g=d[f]);for(;!A(a);)for(var p=0,m=l;p<m.length;p++){var g=m[p];if((M=i[g.name]).name in a){var y=a[M.name];delete a[M.name];for(var x=0,w=y;x<w.length;x++)s(M,w[x])}}for(var k=[],_=[],E=0,O=e.inputLayers;E<O.length;E++){var S=(g=O[E])[0],C=g[1],N=g[2];v(S in i);var T=(M=i[S]).inboundNodes[C].outputTensors;k.push(T[N])}for(var I=0,D=e.outputLayers;I<D.length;I++){var M;S=(g=D[I])[0],C=g[1],N=g[2],v(S in i),T=(M=i[S]).inboundNodes[C].outputTensors,_.push(T[N])}return new t({inputs:k,outputs:_,name:c})},Object.defineProperty(e.prototype,"stateful",{get:function(){if(this._stateful)throw new h("Container instance unexpectedly has _stateful = true. The statefulness of a Container is determined by the Layers it contains. Its _stateful property must remain the default false.");for(var t=0,e=this.layers;t<e.length;t++)if(e[t].stateful)return!0;return!1},enumerable:!0,configurable:!0}),e.prototype.resetStates=function(){var t=this;Object(r.tidy)(function(){t.layers.forEach(function(t){t.stateful&&t.resetStates()})})},e}(pe));function Dn(t,e){return u(this,void 0,void 0,function(){var n;return c(this,function(i){if(null==e&&(e={}),"string"==typeof t){if(0===(n=r.io.getLoadHandlers(t,e.onProgress)).length)n.push(r.io.browserHTTPRequest(t,e));else if(n.length>1)throw new h("Found more than one ("+n.length+") load handlers for URL '"+t+"'");t=n[0]}return[2,function(t,e,n){return u(this,void 0,void 0,function(){var i,a,o,s,u,l,f,d,p;return c(this,function(c){switch(c.label){case 0:if(null==n&&(n={}),null==t.load)throw new h("Cannot proceed with model loading because the IOHandler provided does not have the `load` method implemented.");return[4,t.load()];case 1:if(i=c.sent(),null!=(a=i.modelTopology).model_config&&(a=a.model_config),o=null==n.strict||n.strict,s=null!=i.weightData&&null!=i.weightSpecs&&o,u=Ne(an(a),e,s),null!=(l=i.trainingConfig)&&u.loadTrainingConfig(l),null!=i.userDefinedMetadata&&u.setUserDefinedMetadata(i.userDefinedMetadata),null==i.weightData)return[3,4];if(null==i.weightSpecs)throw new h("LayersModel artifacts contains weight data, but not weight specs. Therefore loading of weights cannot proceed.");return f=function(t,e){var n=r.io.decodeWeights(t,e),i={},a=[];return e.forEach(function(t){"optimizer"===t.group?a.push({name:t.name,tensor:n[t.name]}):i[t.name]=n[t.name]}),{modelWeights:i,optimizerWeights:a}}(i.weightData,i.weightSpecs),d=f.modelWeights,p=f.optimizerWeights,u.loadWeights(d,o),null!=u.optimizer&&p.length>0?[4,u.optimizer.setWeights(p)]:[3,3];case 2:c.sent(),c.label=3;case 3:Object(r.dispose)(d),Object(r.dispose)(p.map(function(t){return t.tensor})),c.label=4;case 4:return[2,u]}})})}(t,void 0,e)]})})}r.serialization.registerClass(In);var Mn=function(t){function e(e){var n=t.call(this,{inputs:[],outputs:[]})||this;if(e=e||{},n.trainable=!0,n.built=!1,n.name=null!=e.name?e.name:Qt("sequential_"),null!=e.layers)for(var r=0,i=e.layers;r<i.length;r++){var a=i[r];n.add(a)}return n}return a(e,t),e.prototype.checkShape=function(t){if(t.inboundNodes[0].outputTensors[0].shape.some(function(t){return t<0}))throw new h("Negative dimension size caused by adding layer "+t.name+" with input shape ["+t.inboundNodes[0].inputTensors[0].shape+"]")},e.prototype.add=function(t){var n,r=t instanceof e||t instanceof In;if(r){if(1!==(n=t).outputs.length)throw new h("All layers in a Sequential model should have a single output tensor. For multi-output layers, use the functional API.");if(1!==n.inputs.length)throw new h("All layers in a Sequential model should have a single input tensor. For multi-input layers, use the functional API.")}if(0===this.outputs.length){if(0===t.inboundNodes.length){if(null==t.batchInputShape)throw new h("The first layer in a Sequential model must get an `inputShape` or `batchInputShape` argument.");var i=ve({batchShape:t.batchInputShape,dtype:t.dtype,name:t.name+"_input"});t.apply(i)}if(r)this.outputs=n.outputs,this.inputs=n.inputs;else{if(1!==t.inboundNodes.length)throw new h("A layer added to a Sequential model must not already be connected somewhere else. LayersModel received layer "+t.name+" which has "+t.inboundNodes.length+" pre-existing inbound connections.");if(1!==t.inboundNodes[0].outputTensors.length)throw new h("All layers in a Sequential model should have a single output tensor. For multi-output layers, use the functional API.");this.checkShape(t),this.outputs=[t.inboundNodes[0].outputTensors[0]],this.inputs=function t(e,n,r){if((null==n||null!=r&&r>0)&&(n=e.sourceLayer,r=e.nodeIndex),0===n.inboundNodes.length)return[e];var i=n.inboundNodes[r];if(0===i.inboundLayers.length)return i.inputTensors;for(var a=[],o=0;o<i.inboundLayers.length;o++)for(var s=0,u=t(i.inputTensors[o],i.inboundLayers[o],i.nodeIndices[o]);s<u.length;s++){var c=u[s];-1===a.indexOf(c)&&a.push(c)}return a}(this.outputs[0])}this.inboundNodes=[],new de({outboundLayer:this,inboundLayers:[],nodeIndices:[],tensorIndices:[],inputTensors:this.inputs,outputTensors:this.outputs,inputMasks:g(null,this.inputs.length),outputMasks:[null],inputShapes:this.inputs.map(function(t){return t.shape}),outputShapes:this.outputs[0].shape})}else{var a=t.apply(this.outputs[0]);if(Array.isArray(a))throw new TypeError("All layers in a Sequential model should have a single output tensor. For multi-output layers, use the functional API.");this.checkShape(t),this.outputs=[a],this.inboundNodes[0].outputTensors=this.outputs,this.inboundNodes[0].outputShapes=[this.outputs[0].shape]}this.layers.push(t),this.built=!1},e.prototype.pop=function(){if(0===this.layers.length)throw new TypeError("There are no layers in the model.");if(this.layers.pop(),0===this.layers.length)this.outputs=[],this.inboundNodes=[],this.outboundNodes=[];else{var t=this.layers.length-1;this.layers[t].outboundNodes=[],this.outputs=[this.layers[t].output],this.inboundNodes[0].outputTensors=this.outputs,this.inboundNodes[0].outputShapes=[this.outputs[0].shape]}},e.prototype.call=function(t,e){return null==this.model&&this.build(),this.model.call(t,e)},e.prototype.build=function(t){if(re(t),0===this.inputs.length||0===this.outputs.length)throw new TypeError("Sequential model cannot be built: model is empty. Add some layers first.");this.model=new In({inputs:this.inputs,outputs:this.outputs[0],name:this.name+"_model"}),this.model.trainable=this.trainable,this.supportsMasking=this.model.supportsMasking,this.inputLayers=this.model.inputLayers,this.inputLayersNodeIndices=this.model.inputLayersNodeIndices,this.inputLayersTensorIndices=this.model.inputLayersTensorIndices,this.outputLayers=this.model.outputLayers,this.outputLayersNodeIndices=this.model.outputLayersNodeIndices,this.outputLayersTensorIndices=this.model.outputLayersTensorIndices,this.nodesByDepth=this.model.nodesByDepth,this.containerNodes=this.model.containerNodes,this.outputNames=this.model.outputNames,this.inputNames=this.model.inputNames,this.built=!0},e.prototype.countParams=function(){return this.built||this.build(),t.prototype.countParams.call(this)},e.prototype.summary=function(e,n,r){void 0===r&&(r=console.log),this.built||this.build(),t.prototype.summary.call(this,e,n,r)},e.prototype.setWeights=function(t){null==this.model&&this.build(),this.model.setWeights(t)},e.prototype.evaluate=function(t,e,n){if(void 0===n&&(n={}),!this.built)throw new d("The model needs to be compiled before being used.");return this.model.evaluate(t,e,n)},e.prototype.evaluateDataset=function(t,e){return u(this,void 0,void 0,function(){return c(this,function(n){if(!this.built)throw new d("The model needs to be compiled before being used.");return[2,this.model.evaluateDataset(t,e)]})})},e.prototype.predict=function(t,e){return void 0===e&&(e={}),null==this.model&&this.build(),this.model.predict(t,e)},e.prototype.predictOnBatch=function(t){return null==this.model&&this.build(),this.model.predictOnBatch(t)},e.prototype.compile=function(t){this.build(),this.model.compile(t),this.optimizer_=this.model.optimizer,this.isOptimizerOwned=this.model.isOptimizerOwned,this.loss=this.model.loss,this.metrics=this.model.metrics,this.metricsTensors=this.model.metricsTensors,this.metricsNames=this.model.metricsNames},Object.defineProperty(e.prototype,"optimizer",{get:function(){return null==this.model?void 0:this.model.optimizer},set:function(t){this.model.optimizer=t},enumerable:!0,configurable:!0}),e.prototype.fit=function(t,e,n){return void 0===n&&(n={}),u(this,void 0,void 0,function(){return c(this,function(r){if(!this.built)throw new d("The model needs to be compiled before being used.");return[2,this.model.fit(t,e,n)]})})},e.prototype.fitDataset=function(t,e){return u(this,void 0,void 0,function(){return c(this,function(n){if(!this.built)throw new d("The model needs to be compiled before being used.");return[2,this.model.fitDataset(t,e)]})})},e.prototype.trainOnBatch=function(t,e){return u(this,void 0,void 0,function(){return c(this,function(n){return[2,this.model.trainOnBatch(t,e)]})})},e.fromConfig=function(t,n,i,a){var o;void 0===i&&(i={}),void 0===a&&(a=!1);var s={};if(n instanceof Array){if(null==n[0].className||"Merge"===n[0].className)throw new h("Legacy serialization format not supported yet.");o=n}else r.util.assert(null!=n.layers,function(){return"When the config data for a Sequential model is not an Array, it must be an Object that contains the 'layers' field."}),o=n.layers,delete n.layers,s=n;var u=new t(s);if(!(u instanceof e))throw new p("Sequential.fromConfig called on non-Sequential input: "+u);for(var c=0,l=o;c<l.length;c++){var f=Ne(l[c],void 0,a);a&&f.setFastWeightInitDuringBuild(!0),u.add(f)}return u},Object.defineProperty(e.prototype,"stopTraining",{get:function(){if(null==this.model)throw new h("Cannot get the stopTraining property of a sequential model before it is compiled.");return this.model.stopTraining},set:function(t){if(null==this.model)throw new h("Cannot set the stopTraining property of a sequential model before it is compiled.");this.model.stopTraining=t},enumerable:!0,configurable:!0}),e.prototype.getConfig=function(){for(var t=[],e=0,n=this.layers;e<n.length;e++){var r=n[e],i={};i.className=r.getClassName(),i.config=r.getConfig(),t.push(i)}return{name:this.name,layers:t}},e.className="Sequential",e}(In);function Rn(t){return new In(t)}function Fn(t){return new Mn(t)}function jn(t,e){return null==e&&(e={}),Dn(t,e)}function Pn(t){return ve(t)}function Ln(t,e){Ce.registerCallbackConstructor(t,e)}r.serialization.registerClass(Mn);var zn=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.getConfig=function(){return{}},e}(r.serialization.Serializable),Bn=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.apply=function(t,e){return void 0===e&&(e=1),function(t,e){if(void 0===e&&(e=1),1!==e)throw new p("Support for alpha values other than 1 ("+e+") is not implemented yet.");return Object(r.elu)(t)}(t,e)},e.className="elu",e}(zn);r.serialization.registerClass(Bn);var Un=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.apply=function(t){return Object(r.selu)(t)},e.className="selu",e}(zn);r.serialization.registerClass(Un);var Wn=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.apply=function(t){return Object(r.relu)(t)},e.className="relu",e}(zn);r.serialization.registerClass(Wn);var Vn=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.apply=function(t){return Object(r.tidy)(function(){return Object(r.minimum)(6,Object(r.relu)(t))})},e.className="relu6",e}(zn);r.serialization.registerClass(Vn);var qn=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.apply=function(t){return t},e.className="linear",e}(zn);r.serialization.registerClass(qn);var Hn=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.apply=function(t){return Object(r.sigmoid)(t)},e.className="sigmoid",e}(zn);r.serialization.registerClass(Hn);var Gn=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.apply=function(t){return function(t){return Object(r.tidy)(function(){var e=Object(r.add)(.5,Object(r.mul)(.2,t));return Object(r.clipByValue)(e,0,1)})}(t)},e.className="hardSigmoid",e}(zn);r.serialization.registerClass(Gn);var $n=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.apply=function(t){return Object(r.softplus)(t)},e.className="softplus",e}(zn);r.serialization.registerClass($n);var Kn=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.apply=function(t){return function(t){return Object(r.tidy)(function(){return Object(r.div)(t,Object(r.abs)(t).add(1))})}(t)},e.className="softsign",e}(zn);r.serialization.registerClass(Kn);var Xn=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.apply=function(t){return Object(r.tanh)(t)},e.className="tanh",e}(zn);r.serialization.registerClass(Xn);var Yn=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.apply=function(t,e){return void 0===e&&(e=-1),Object(r.softmax)(t,e)},e.className="softmax",e}(zn);r.serialization.registerClass(Yn);var Jn=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.apply=function(t,e){return void 0===e&&(e=-1),Object(r.logSoftmax)(t,e)},e.className="logSoftmax",e}(zn);function Zn(t){return t.getClassName()}function Qn(t,e){return void 0===e&&(e={}),O(t,r.serialization.SerializationMap.getMap().classNameMap,e,"activation")}function tr(t){var e;return null==t?Qn(e={className:"linear",config:{}}):"string"==typeof t?((e={}).className=t,e.config={},Qn(e)):t instanceof zn?t:Qn(t)}function er(t){if(null!=t&&"object"!=typeof t)throw new Error("Argument to L1L2 regularizer's constructor is expected to be an object, but received: "+t)}r.serialization.registerClass(Jn);var nr=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e}(r.serialization.Serializable),rr=function(t){function e(e){var n=t.call(this)||this;return er(e),n.l1=null==e||null==e.l1?.01:e.l1,n.l2=null==e||null==e.l2?.01:e.l2,n.hasL1=0!==n.l1,n.hasL2=0!==n.l2,n}return a(e,t),e.prototype.apply=function(t){var e=this;return Object(r.tidy)(function(){var n=Object(r.zeros)([1]);return e.hasL1&&(n=Object(r.add)(n,Object(r.sum)(Object(r.mul)(e.l1,Object(r.abs)(t))))),e.hasL2&&(n=Object(r.add)(n,Object(r.sum)(Object(r.mul)(e.l2,kt(t))))),n.asScalar()})},e.prototype.getConfig=function(){return{l1:this.l1,l2:this.l2}},e.fromConfig=function(t,e){return new t({l1:e.l1,l2:e.l2})},e.className="L1L2",e}(nr);r.serialization.registerClass(rr);var ir={l1l2:"L1L2"};function ar(t){return E(t)}function or(t,e){return void 0===e&&(e={}),O(t,r.serialization.SerializationMap.getMap().classNameMap,e,"regularizer")}function sr(t){return null==t?null:"string"==typeof t?or({className:t in ir?ir[t]:t,config:{}}):t instanceof nr?t:or(t)}var ur=function(t){function e(e){var n=t.call(this,null==e?{}:e)||this;return n.supportsMasking=!0,null!=e&&(n.maxValue=e.maxValue),n}return a(e,t),e.prototype.call=function(t,e){t=ne(t);var n=Object(r.relu)(t);return null!=this.maxValue&&(n=Object(r.clipByValue)(n,0,this.maxValue)),n},e.prototype.computeOutputShape=function(t){return t},e.prototype.getConfig=function(){var e={maxValue:this.maxValue},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="ReLU",e}(pe);r.serialization.registerClass(ur);var cr=function(t){function e(e){var n=t.call(this,null==e?{}:e)||this;return n.DEFAULT_ALPHA=.3,null==e&&(e={}),n.alpha=null==e.alpha?n.DEFAULT_ALPHA:e.alpha,n}return a(e,t),e.prototype.call=function(t,e){var n=ne(t);return Object(r.leakyRelu)(n,this.alpha)},e.prototype.computeOutputShape=function(t){return t},e.prototype.getConfig=function(){var e={alpha:this.alpha},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="LeakyReLU",e}(pe);r.serialization.registerClass(cr);var lr=function(t){function e(e){var n=t.call(this,null==e?{}:e)||this;if(n.DEFAULT_ALPHA_INITIALIZER="zeros",null==e&&(e={}),n.supportsMasking=!0,n.alphaInitializer=Kt(e.alphaInitializer||n.DEFAULT_ALPHA_INITIALIZER),n.alphaRegularizer=sr(e.alphaRegularizer),n.alphaConstraint=W(e.alphaConstraint),null==e.sharedAxes)n.sharedAxes=null;else if(Array.isArray(e.sharedAxes))n.sharedAxes=e.sharedAxes;else{if("number"!=typeof e.sharedAxes)throw new h("Expected sharedAxes to be a number or an array of numbers, but got "+e.sharedAxes);n.sharedAxes=[e.sharedAxes]}return n}return a(e,t),e.prototype.build=function(t){var e=(t=re(t)).slice(1);if(null!=this.sharedAxes)for(var n=0,r=this.sharedAxes;n<r.length;n++)e[(a=r[n])-1]=1;this.alpha=this.addWeight("alpha",e,"float32",this.alphaInitializer,this.alphaRegularizer,!0,this.alphaConstraint);var i={};if(null!=this.sharedAxes)for(var a=1;a<t.length;++a)i[a]=t[a];this.inputSpec=[new ce({ndim:t.length,axes:i})],this.built=!0},e.prototype.call=function(t,e){return t=ne(t),Object(r.prelu)(t,this.alpha.read())},e.prototype.getConfig=function(){var e={alphaInitializer:$t(this.alphaInitializer),alphaRegularizer:ar(this.alphaRegularizer),alphaConstraint:B(this.alphaConstraint),sharedAxes:this.sharedAxes},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="PReLU",e}(pe);r.serialization.registerClass(lr);var fr=function(t){function e(e){var n=t.call(this,null==e?{}:e)||this;if(n.DEFAULT_ALPHA=1,null==e&&(e={}),null!=e.alpha&&e.alpha!==n.DEFAULT_ALPHA)throw new p("Non-default alpha value ("+e.alpha+") is not supported by the ELU layer yet.");return n.alpha=null==e.alpha?n.DEFAULT_ALPHA:e.alpha,n}return a(e,t),e.prototype.call=function(t,e){var n=ne(t);return Object(r.elu)(n)},e.prototype.computeOutputShape=function(t){return t},e.prototype.getConfig=function(){var e={alpha:this.alpha},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="ELU",e}(pe);r.serialization.registerClass(fr);var dr=function(t){function e(e){var n=t.call(this,null==e?{}:e)||this;return n.DEFAULT_THETA=1,null==e&&(e={}),n.theta=null==e.theta?n.DEFAULT_THETA:e.theta,n}return a(e,t),e.prototype.call=function(t,e){var n=ne(t);return n.mul(ft(n.greater(this.theta),"float32"))},e.prototype.computeOutputShape=function(t){return t},e.prototype.getConfig=function(){var e={theta:this.theta},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="ThresholdedReLU",e}(pe);r.serialization.registerClass(dr);var hr=function(t){function e(e){var n=t.call(this,null==e?{}:e)||this;return n.DEFAULT_AXIS=1,null==e&&(e={}),n.softmax=(new Yn).apply,n.axis=null==e.axis?n.DEFAULT_AXIS:e.axis,n}return a(e,t),e.prototype.call=function(t,e){var n=ne(t);return this.softmax(n,this.axis)},e.prototype.computeOutputShape=function(t){return t},e.prototype.getConfig=function(){var e={axis:this.axis},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="Softmax",e}(pe);function pr(t,e,n){if("number"==typeof t)return g(t,e);if(t.length!==e)throw new h("The "+n+" argument must be an integer or tuple of "+e+" integers. Received: "+t.length+" elements.");for(var r=0;r<e;++r){var i=t[r];if(!at(i))throw new h("The "+n+" argument must be an integer or tuple of "+e+" integers. Received: "+JSON.stringify(t)+" including a non-integer number "+i)}return t}function mr(t,e,n,r,i){return void 0===i&&(i=1),null==t?t:(a="same"===n?t:t-(e+(e-1)*(i-1))+1,Math.floor((a+r-1)/r));var a}function gr(t,e,n,r){if(null==t)return null;if("valid"===r)t=t*e+ct([n-e,0]);else{if("same"!==r)throw new h("Unsupport padding mode: "+r+".");t*=e}return t}function vr(t,e){return Object(r.tidy)(function(){return X(e),"channelsFirst"===e?Object(r.transpose)(t,[0,2,3,1]):t})}function yr(t,e){return Object(r.tidy)(function(){return X(e),"channelsFirst"===e?Object(r.transpose)(t,[0,2,3,4,1]):t})}function br(t,e,n,i,a,o,s,u){return void 0===i&&(i=[1,1]),void 0===a&&(a="valid"),void 0===u&&(u=null),Object(r.tidy)(function(){if(null==o&&(o="channelsLast"),X(o),3!==t.rank&&4!==t.rank)throw new h("conv2dWithBiasActivation expects input to be of rank 3 or 4, but received "+t.rank+".");if(3!==e.rank&&4!==e.rank)throw new h("conv2dWithBiasActivation expects kernel to be of rank 3 or 4, but received "+t.rank+".");var c=vr(t,o);if("causal"===a)throw new p("The support for CAUSAL padding mode in conv1dWithBias is not implemented yet.");return c=r.fused.conv2d({x:c,filter:e,strides:i,pad:"same"===a?"same":"valid",dilations:s,dataFormat:"NHWC",bias:n,activation:u}),"channelsFirst"===o&&(c=Object(r.transpose)(c,[0,3,1,2])),c})}r.serialization.registerClass(hr);var xr=function(t){function e(n,r){var i=t.call(this,r)||this;if(i.bias=null,i.DEFAULT_KERNEL_INITIALIZER="glorotNormal",i.DEFAULT_BIAS_INITIALIZER="zeros",e.verifyArgs(r),i.rank=n,I(i.rank,"rank"),1!==i.rank&&2!==i.rank&&3!==i.rank)throw new p("Convolution layer for rank other than 1, 2, or 3 ("+i.rank+") is not implemented yet.");if(i.kernelSize=pr(r.kernelSize,n,"kernelSize"),i.strides=pr(null==r.strides?1:r.strides,n,"strides"),i.padding=null==r.padding?"valid":r.padding,Y(i.padding),i.dataFormat=null==r.dataFormat?"channelsLast":r.dataFormat,X(i.dataFormat),i.activation=tr(r.activation),i.useBias=null==r.useBias||r.useBias,i.biasInitializer=Kt(r.biasInitializer||i.DEFAULT_BIAS_INITIALIZER),i.biasConstraint=W(r.biasConstraint),i.biasRegularizer=sr(r.biasRegularizer),i.activityRegularizer=sr(r.activityRegularizer),i.dilationRate=pr(null==r.dilationRate?1:r.dilationRate,n,"dilationRate"),1===i.rank&&Array.isArray(i.dilationRate)&&1!==i.dilationRate.length)throw new h("dilationRate must be a number or an array of a single number for 1D convolution, but received "+JSON.stringify(i.dilationRate));if(2===i.rank){if("number"==typeof i.dilationRate)i.dilationRate=[i.dilationRate,i.dilationRate];else if(2!==i.dilationRate.length)throw new h("dilationRate must be a number or array of two numbers for 2D convolution, but received "+JSON.stringify(i.dilationRate))}else if(3===i.rank)if("number"==typeof i.dilationRate)i.dilationRate=[i.dilationRate,i.dilationRate,i.dilationRate];else if(3!==i.dilationRate.length)throw new h("dilationRate must be a number or array of three numbers for 3D convolution, but received "+JSON.stringify(i.dilationRate));return i}return a(e,t),e.verifyArgs=function(t){if(v("kernelSize"in t,"required key 'kernelSize' not in config"),"number"!=typeof t.kernelSize&&!T(t.kernelSize,"number",1,3))throw new h("BaseConv expects config.kernelSize to be number or number[] with length 1, 2, or 3, but received "+JSON.stringify(t.kernelSize)+".")},e.prototype.getConfig=function(){var e={kernelSize:this.kernelSize,strides:this.strides,padding:this.padding,dataFormat:this.dataFormat,dilationRate:this.dilationRate,activation:Zn(this.activation),useBias:this.useBias,biasInitializer:$t(this.biasInitializer),biasRegularizer:ar(this.biasRegularizer),activityRegularizer:ar(this.activityRegularizer),biasConstraint:B(this.biasConstraint)},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e}(pe),wr=function(t){function e(n,r){var i=t.call(this,n,r)||this;return i.kernel=null,e.verifyArgs(r),i.filters=r.filters,I(i.filters,"filters"),i.kernelInitializer=Kt(r.kernelInitializer||i.DEFAULT_KERNEL_INITIALIZER),i.kernelConstraint=W(r.kernelConstraint),i.kernelRegularizer=sr(r.kernelRegularizer),i}return a(e,t),e.prototype.build=function(t){var e;t=re(t);var n="channelsFirst"===this.dataFormat?1:t.length-1;if(null==t[n])throw new h("The channel dimension of the input should be defined. Found "+t[n]);var r=t[n],i=this.kernelSize.concat([r,this.filters]);this.kernel=this.addWeight("kernel",i,null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.useBias&&(this.bias=this.addWeight("bias",[this.filters],null,this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint)),this.inputSpec=[{ndim:this.rank+2,axes:(e={},e[n]=r,e)}],this.built=!0},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){var e;t=ne(t);var i=null==n.bias?null:n.bias.read(),a=D(n.activation.getClassName());if(null!=a&&2===n.rank)e=br(t,n.kernel.read(),i,n.strides,n.padding,n.dataFormat,n.dilationRate,a);else{if(1===n.rank)e=function(t,e,n,i,a,o,s){return void 0===i&&(i=1),void 0===a&&(a="valid"),void 0===s&&(s=1),Object(r.tidy)(function(){if(null==o&&(o="channelsLast"),X(o),3!==t.shape.length)throw new h("The input of a conv1dWithBias operation should be 3, but is "+t.shape.length+" instead.");if(3!==e.shape.length)throw new h("The kernel for a conv1dWithBias operation should be 3, but is "+e.shape.length+" instead");if(null!=n&&1!==n.shape.length)throw new h("The bias for a conv1dWithBias operation should be 1, but is "+e.shape.length+" instead");if("channelsFirst"===o&&(t=Object(r.transpose)(t,[0,2,1])),"causal"===a)throw new p("The support for CAUSAL padding mode in conv1dWithBias is not implemented yet.");var u=Object(r.conv1d)(t,e,i,"same"===a?"same":"valid","NWC",s);return null!=n&&(u=Et(u,n)),u})}(t,n.kernel.read(),i,n.strides[0],n.padding,n.dataFormat,n.dilationRate[0]);else if(2===n.rank)e=br(t,n.kernel.read(),i,n.strides,n.padding,n.dataFormat,n.dilationRate);else{if(3!==n.rank)throw new p("convolutions greater than 3D are not implemented yet.");e=function(t,e,n,i,a,o,s){return void 0===i&&(i=[1,1,1]),void 0===a&&(a="valid"),Object(r.tidy)(function(){if(null==o&&(o="channelsLast"),X(o),4!==t.rank&&5!==t.rank)throw new h("conv3dWithBias expects input to be of rank 4 or 5, but received "+t.rank+".");if(4!==e.rank&&5!==e.rank)throw new h("conv3dWithBias expects kernel to be of rank 4 or 5, but received "+t.rank+".");var u=yr(t,o);if("causal"===a)throw new p("The support for CAUSAL padding mode in conv3dWithBias is not implemented yet.");return u=Object(r.conv3d)(u,e,i,"same"===a?"same":"valid","NDHWC",s),null!=n&&(u=Et(u,n)),"channelsFirst"===o&&(u=Object(r.transpose)(u,[0,4,1,2,3])),u})}(t,n.kernel.read(),i,n.strides,n.padding,n.dataFormat,n.dilationRate)}null!=n.activation&&(e=n.activation.apply(e))}return e})},e.prototype.computeOutputShape=function(t){t=re(t);for(var e=[],n="channelsLast"===this.dataFormat?t.slice(1,t.length-1):t.slice(2),r=0;r<n.length;++r){var i=mr(n[r],this.kernelSize[r],this.padding,this.strides[r],"number"==typeof this.dilationRate?this.dilationRate:this.dilationRate[r]);e.push(i)}var a=[t[0]];return"channelsLast"===this.dataFormat?(a=a.concat(e)).push(this.filters):(a.push(this.filters),a=a.concat(e)),a},e.prototype.getConfig=function(){var e={filters:this.filters,kernelInitializer:$t(this.kernelInitializer),kernelRegularizer:ar(this.kernelRegularizer),kernelConstraint:B(this.kernelConstraint)},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.verifyArgs=function(t){if(!("filters"in t)||"number"!=typeof t.filters||t.filters<1)throw new h("Convolution layer expected config.filters to be a 'number' > 0 but got "+JSON.stringify(t.filters))},e}(xr),kr=function(t){function e(n){var r=t.call(this,2,n)||this;return e.verifyArgs(n),r}return a(e,t),e.prototype.getConfig=function(){var e=t.prototype.getConfig.call(this);return delete e.rank,e},e.verifyArgs=function(t){if("number"!=typeof t.kernelSize&&!T(t.kernelSize,"number",1,2))throw new h("Conv2D expects config.kernelSize to be number or number[] with length 1 or 2, but received "+JSON.stringify(t.kernelSize)+".")},e.className="Conv2D",e}(wr);r.serialization.registerClass(kr);var _r=function(t){function e(n){var r=t.call(this,3,n)||this;return e.verifyArgs(n),r}return a(e,t),e.prototype.getConfig=function(){var e=t.prototype.getConfig.call(this);return delete e.rank,e},e.verifyArgs=function(t){if("number"!=typeof t.kernelSize&&(!Array.isArray(t.kernelSize)||1!==t.kernelSize.length&&3!==t.kernelSize.length))throw new h("Conv3D expects config.kernelSize to be number or [number, number, number], but received "+JSON.stringify(t.kernelSize)+".")},e.className="Conv3D",e}(wr);r.serialization.registerClass(_r);var Er=function(t){function e(e){var n=t.call(this,e)||this;if(n.inputSpec=[new ce({ndim:4})],"same"!==n.padding&&"valid"!==n.padding)throw new h("Conv2DTranspose currently supports only padding modes 'same' and 'valid', but received padding mode "+n.padding);return n}return a(e,t),e.prototype.build=function(t){var e;if(4!==(t=re(t)).length)throw new h("Input should have rank 4; Received input shape: "+JSON.stringify(t));var n="channelsFirst"===this.dataFormat?1:t.length-1;if(null==t[n])throw new h("The channel dimension of the inputs should be defined. Found `None`.");var r=t[n],i=this.kernelSize.concat([this.filters,r]);this.kernel=this.addWeight("kernel",i,"float32",this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.useBias&&(this.bias=this.addWeight("bias",[this.filters],"float32",this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint)),this.inputSpec=[new ce({ndim:4,axes:(e={},e[n]=r,e)})],this.built=!0},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){var e=ne(t);if(4!==e.shape.length)throw new h("Conv2DTranspose.call() expects input tensor to be rank-4, but received a tensor of rank-"+e.shape.length);var i,a,o=e.shape,s=o[0];"channelsFirst"===n.dataFormat?(i=2,a=3):(i=1,a=2);var u=o[i],c=o[a],l=n.kernelSize[0],f=n.kernelSize[1],d=n.strides[0],p=n.strides[1],m=[s,gr(u,d,l,n.padding),gr(c,p,f,n.padding),n.filters];"channelsLast"!==n.dataFormat&&(e=Object(r.transpose)(e,[0,2,3,1]));var g=Object(r.conv2dTranspose)(e,n.kernel.read(),m,n.strides,n.padding);return"channelsLast"!==n.dataFormat&&(g=Object(r.transpose)(g,[0,3,1,2])),null!=n.bias&&(g=Et(g,n.bias.read(),n.dataFormat)),null!=n.activation&&(g=n.activation.apply(g)),g})},e.prototype.computeOutputShape=function(t){var e,n,r,i=(t=re(t)).slice();"channelsFirst"===this.dataFormat?(e=1,n=2,r=3):(e=3,n=1,r=2);var a=this.kernelSize[0],o=this.kernelSize[1],s=this.strides[0],u=this.strides[1];return i[e]=this.filters,i[n]=gr(i[n],s,a,this.padding),i[r]=gr(i[r],u,o,this.padding),i},e.prototype.getConfig=function(){var e=t.prototype.getConfig.call(this);return delete e.dilationRate,e},e.className="Conv2DTranspose",e}(kr);r.serialization.registerClass(Er);var Or=function(t){function e(e){return t.call(this,2,e)||this}return a(e,t),e.className="SeparableConv2D",e}(function(t){function e(e,n){var r=t.call(this,e,n)||this;if(r.DEFAULT_DEPTHWISE_INITIALIZER="glorotUniform",r.DEFAULT_POINTWISE_INITIALIZER="glorotUniform",r.depthwiseKernel=null,r.pointwiseKernel=null,null==n.filters)throw new h("The `filters` configuration field is required by SeparableConv, but is unspecified.");if(null!=n.kernelInitializer||null!=n.kernelRegularizer||null!=n.kernelConstraint)throw new h("Fields kernelInitializer, kernelRegularizer and kernelConstraint are invalid for SeparableConv2D. Use depthwiseInitializer, depthwiseRegularizer, depthwiseConstraint, pointwiseInitializer, pointwiseRegularizer and pointwiseConstraint instead.");if(null!=n.padding&&"same"!==n.padding&&"valid"!==n.padding)throw new h("SeparableConv"+r.rank+"D supports only padding modes: 'same' and 'valid', but received "+JSON.stringify(n.padding));return r.depthMultiplier=null==n.depthMultiplier?1:n.depthMultiplier,r.depthwiseInitializer=Kt(n.depthwiseInitializer||r.DEFAULT_DEPTHWISE_INITIALIZER),r.depthwiseRegularizer=sr(n.depthwiseRegularizer),r.depthwiseConstraint=W(n.depthwiseConstraint),r.pointwiseInitializer=Kt(n.depthwiseInitializer||r.DEFAULT_POINTWISE_INITIALIZER),r.pointwiseRegularizer=sr(n.pointwiseRegularizer),r.pointwiseConstraint=W(n.pointwiseConstraint),r}return a(e,t),e.prototype.build=function(t){var e;if((t=re(t)).length<this.rank+2)throw new h("Inputs to SeparableConv"+this.rank+"D should have rank "+(this.rank+2)+", but received input shape: "+JSON.stringify(t));var n="channelsFirst"===this.dataFormat?1:t.length-1;if(null==t[n]||t[n]<0)throw new h("The channel dimension of the inputs should be defined, but found "+JSON.stringify(t[n]));for(var r=t[n],i=this.kernelSize.concat([r,this.depthMultiplier]),a=[],o=0;o<this.rank;++o)a.push(1);a.push(r*this.depthMultiplier,this.filters),this.depthwiseKernel=this.addWeight("depthwise_kernel",i,"float32",this.depthwiseInitializer,this.depthwiseRegularizer,!0,this.depthwiseConstraint),this.pointwiseKernel=this.addWeight("pointwise_kernel",a,"float32",this.pointwiseInitializer,this.pointwiseRegularizer,!0,this.pointwiseConstraint),this.useBias?this.bias=this.addWeight("bias",[this.filters],"float32",this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint):this.bias=null,this.inputSpec=[new ce({ndim:this.rank+2,axes:(e={},e[n]=r,e)})],this.built=!0},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){var e;if(t=ne(t),1===n.rank)throw new p("1D separable convolution is not implemented yet.");return 2===n.rank&&("channelsFirst"===n.dataFormat&&(t=Object(r.transpose)(t,[0,2,3,1])),e=Object(r.separableConv2d)(t,n.depthwiseKernel.read(),n.pointwiseKernel.read(),n.strides,n.padding,n.dilationRate,"NHWC")),n.useBias&&(e=Et(e,n.bias.read(),n.dataFormat)),null!=n.activation&&(e=n.activation.apply(e)),"channelsFirst"===n.dataFormat&&(e=Object(r.transpose)(e,[0,3,1,2])),e})},e.prototype.getConfig=function(){var e=t.prototype.getConfig.call(this);return delete e.rank,delete e.kernelInitializer,delete e.kernelRegularizer,delete e.kernelConstraint,e.depthwiseInitializer=$t(this.depthwiseInitializer),e.pointwiseInitializer=$t(this.pointwiseInitializer),e.depthwiseRegularizer=ar(this.depthwiseRegularizer),e.pointwiseRegularizer=ar(this.pointwiseRegularizer),e.depthwiseConstraint=B(this.depthwiseConstraint),e.pointwiseConstraint=B(this.pointwiseConstraint),e},e.className="SeparableConv",e}(wr));r.serialization.registerClass(Or);var Sr=function(t){function e(n){var r=t.call(this,1,n)||this;return e.verifyArgs(n),r.inputSpec=[{ndim:3}],r}return a(e,t),e.prototype.getConfig=function(){var e=t.prototype.getConfig.call(this);return delete e.rank,delete e.dataFormat,e},e.verifyArgs=function(t){if("number"!=typeof t.kernelSize&&!T(t.kernelSize,"number",1,1))throw new h("Conv1D expects config.kernelSize to be number or number[] with length 1, but received "+JSON.stringify(t.kernelSize)+".")},e.className="Conv1D",e}(wr);r.serialization.registerClass(Sr);var Cr=function(t){function e(e){var n=t.call(this,e)||this;return"number"==typeof e.cropping?n.cropping=[[e.cropping,e.cropping],[e.cropping,e.cropping]]:"number"==typeof e.cropping[0]?n.cropping=[[e.cropping[0],e.cropping[0]],[e.cropping[1],e.cropping[1]]]:n.cropping=e.cropping,n.dataFormat=void 0===e.dataFormat?"channelsLast":e.dataFormat,n.inputSpec=[{ndim:4}],n}return a(e,t),e.prototype.computeOutputShape=function(t){return"channelsFirst"===this.dataFormat?[t[0],t[1],t[2]-this.cropping[0][0]-this.cropping[0][1],t[3]-this.cropping[1][0]-this.cropping[1][1]]:[t[0],t[1]-this.cropping[0][0]-this.cropping[0][1],t[2]-this.cropping[1][0]-this.cropping[1][1],t[3]]},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){return t=ne(t),"channelsLast"===n.dataFormat?mt(mt(t,n.cropping[0][0],t.shape[1]-n.cropping[0][0]-n.cropping[0][1],2),n.cropping[1][0],t.shape[2]-n.cropping[1][1]-n.cropping[1][0],3):mt(mt(t,n.cropping[0][0],t.shape[2]-n.cropping[0][0]-n.cropping[0][1],3),n.cropping[1][0],t.shape[3]-n.cropping[1][1]-n.cropping[1][0],4)})},e.prototype.getConfig=function(){var e={cropping:this.cropping,dataFormat:this.dataFormat},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="Cropping2D",e}(pe);r.serialization.registerClass(Cr);var Ar=function(t){function e(e){var n=t.call(this,e)||this;return n.DEFAULT_SIZE=[2,2],n.inputSpec=[{ndim:4}],n.size=null==e.size?n.DEFAULT_SIZE:e.size,n.dataFormat=null==e.dataFormat?"channelsLast":e.dataFormat,n}return a(e,t),e.prototype.computeOutputShape=function(t){if("channelsFirst"===this.dataFormat){var e=null==t[2]?null:this.size[0]*t[2],n=null==t[3]?null:this.size[1]*t[3];return[t[0],t[1],e,n]}return e=null==t[1]?null:this.size[0]*t[1],n=null==t[2]?null:this.size[1]*t[2],[t[0],e,n,t[3]]},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){var e=ne(t),i=e.shape;if("channelsFirst"===n.dataFormat){e=Object(r.transpose)(e,[0,2,3,1]);var a=n.size[0]*i[2],o=n.size[1]*i[3],s=e.resizeNearestNeighbor([a,o]);return Object(r.transpose)(s,[0,3,1,2])}return a=n.size[0]*i[1],o=n.size[1]*i[2],e.resizeNearestNeighbor([a,o])})},e.prototype.getConfig=function(){var e={size:this.size,dataFormat:this.dataFormat},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="UpSampling2D",e}(pe);r.serialization.registerClass(Ar);var Nr=function(t){function e(e){var n=t.call(this,2,e)||this;return n.depthwiseKernel=null,n.depthMultiplier=null==e.depthMultiplier?1:e.depthMultiplier,n.depthwiseInitializer=Kt(e.depthwiseInitializer||n.DEFAULT_KERNEL_INITIALIZER),n.depthwiseConstraint=W(e.depthwiseConstraint),n.depthwiseRegularizer=sr(e.depthwiseRegularizer),n}return a(e,t),e.prototype.build=function(t){if((t=re(t)).length<4)throw new h("Inputs to DepthwiseConv2D should have rank 4. Received input shape: "+JSON.stringify(t)+".");var e="channelsFirst"===this.dataFormat?1:3;if(null==t[e]||t[e]<0)throw new h("The channel dimension of the inputs to DepthwiseConv2D should be defined, but is not ("+t[e]+").");var n=t[e],r=[this.kernelSize[0],this.kernelSize[1],n,this.depthMultiplier];this.depthwiseKernel=this.addWeight("depthwise_kernel",r,null,this.depthwiseInitializer,this.depthwiseRegularizer,!0,this.depthwiseConstraint),this.useBias?this.bias=this.addWeight("bias",[n*this.depthMultiplier],null,this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint):this.bias=null,this.built=!0},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){var e=function(t,e,n,i,a,o){return void 0===n&&(n=[1,1]),void 0===i&&(i="valid"),Object(r.tidy)(function(){null==a&&(a="channelsLast"),X(a);var s=vr(t,a);if(4!==t.rank)throw new h("Input for depthwiseConv2d is required to be 4-D, but is instead "+t.rank+"-D");if(4!==e.rank)throw new h("depthwiseKernel is required to be 4-D, but is instead "+e.rank+"-D");return s=Object(r.depthwiseConv2d)(s,e,n,"same"===i?"same":"valid","NHWC",o),"channelsFirst"===a&&(s=Object(r.transpose)(s,[0,3,1,2])),s})}(t=ne(t),n.depthwiseKernel.read(),n.strides,n.padding,n.dataFormat,null);return n.useBias&&(e=Et(e,n.bias.read(),n.dataFormat)),null!=n.activation&&(e=n.activation.apply(e)),e})},e.prototype.computeOutputShape=function(t){t=re(t);var e="channelsFirst"===this.dataFormat?t[2]:t[1],n="channelsFirst"===this.dataFormat?t[3]:t[2],r="channelsFirst"===this.dataFormat?t[1]*this.depthMultiplier:t[3]*this.depthMultiplier,i=mr(e,this.kernelSize[0],this.padding,this.strides[0]),a=mr(n,this.kernelSize[1],this.padding,this.strides[1]);return"channelsFirst"===this.dataFormat?[t[0],r,i,a]:[t[0],i,a,r]},e.prototype.getConfig=function(){var e=t.prototype.getConfig.call(this);return e.depthMultiplier=this.depthMultiplier,e.depthwiseInitializer=$t(this.depthwiseInitializer),e.depthwiseRegularizer=ar(this.depthwiseRegularizer),e.depthwiseConstraint=B(this.depthwiseRegularizer),e},e.className="DepthwiseConv2D",e}(xr);r.serialization.registerClass(Nr);var Tr=function(t){function e(e){var n=t.call(this,e)||this;return n.rate=Math.max(Math.min(e.rate,1),0),n.noiseShape=e.noiseShape,n.seed=e.seed,n.supportsMasking=!0,n}return a(e,t),e.prototype.getNoiseShape=function(t){if(null==this.noiseShape)return this.noiseShape;for(var e=t.shape,n=[],r=0;r<this.noiseShape.length;++r)n.push(null==this.noiseShape[r]?e[r]:this.noiseShape[r]);return n},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){n.invokeCallHook(t,e);var r=ne(t);if(0<n.rate&&n.rate<1){var i=null!=e.training&&e.training,a=n.getNoiseShape(r);return St(function(){return Ot(r,n.rate,a,n.seed)},function(){return r},i)}return t})},e.prototype.getConfig=function(){var e={rate:this.rate,noiseShape:this.noiseShape,seed:this.seed},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.prototype.dispose=function(){return t.prototype.dispose.call(this)},e.className="Dropout",e}(pe);r.serialization.registerClass(Tr);var Ir=function(t){function e(e){var n=t.call(this,e)||this;return n.inputSpec=[{ndim:3}],n}return a(e,t),e.prototype.getNoiseShape=function(t){var e=t.shape;return[e[0],1,e[2]]},e.className="SpatialDropout1D",e}(Tr);r.serialization.registerClass(Ir);var Dr=function(t){function e(e){var n=t.call(this,e)||this;if(n.activation=null,n.useBias=!0,n.kernel=null,n.bias=null,n.DEFAULT_KERNEL_INITIALIZER="glorotNormal",n.DEFAULT_BIAS_INITIALIZER="zeros",null==e.batchInputShape&&null==e.inputShape&&null!=e.inputDim){var r=null;null!=e.batchSize&&(r=e.batchSize),n.batchInputShape=[r,e.inputDim]}return n.units=e.units,I(n.units,"units"),n.activation=tr(e.activation),null!=e.useBias&&(n.useBias=e.useBias),n.kernelInitializer=Kt(e.kernelInitializer||n.DEFAULT_KERNEL_INITIALIZER),n.biasInitializer=Kt(e.biasInitializer||n.DEFAULT_BIAS_INITIALIZER),n.kernelConstraint=W(e.kernelConstraint),n.biasConstraint=W(e.biasConstraint),n.kernelRegularizer=sr(e.kernelRegularizer),n.biasRegularizer=sr(e.biasRegularizer),n.activityRegularizer=sr(e.activityRegularizer),n.supportsMasking=!0,n.inputSpec=[{minNDim:2}],n}return a(e,t),e.prototype.build=function(t){var e,n=(t=re(t))[t.length-1];null==this.kernel&&(this.kernel=this.addWeight("kernel",[n,this.units],null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.useBias&&(this.bias=this.addWeight("bias",[this.units],null,this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint))),this.inputSpec=[{minNDim:2,axes:(e={},e[-1]=n,e)}],this.built=!0},e.prototype.computeOutputShape=function(t){var e=(t=re(t)).slice();return e[e.length-1]=this.units,e},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){n.invokeCallHook(t,e);var r,i=ne(t),a=D(n.activation.getClassName());return null!=a?r=xt(i,n.kernel.read(),a,n.bias?n.bias.read():null):(r=xt(i,n.kernel.read()),null!=n.bias&&(r=Et(r,n.bias.read())),null!=n.activation&&(r=n.activation.apply(r))),r})},e.prototype.getConfig=function(){var e={units:this.units,activation:Zn(this.activation),useBias:this.useBias,kernelInitializer:$t(this.kernelInitializer),biasInitializer:$t(this.biasInitializer),kernelRegularizer:ar(this.kernelRegularizer),biasRegularizer:ar(this.biasRegularizer),activityRegularizer:ar(this.activityRegularizer),kernelConstraint:B(this.kernelConstraint),biasConstraint:B(this.biasConstraint)},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="Dense",e}(pe);r.serialization.registerClass(Dr);var Mr=function(t){function e(e){var n=this;return e=e||{},(n=t.call(this,e)||this).inputSpec=[{minNDim:3}],n.dataFormat=e.dataFormat,n}return a(e,t),e.prototype.computeOutputShape=function(t){for(var e=0,n=(t=re(t)).slice(1);e<n.length;e++)if(null==n[e])throw new h('The shape of the input to "Flatten" is not fully defined (got '+t.slice(1)+'). Make sure to pass a complete "input_shape" or "batch_input_shape" argument to the first layer in your model.');return[t[0],ot(t,1)]},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){n.invokeCallHook(t,e);var r=ne(t);if("channelsFirst"===n.dataFormat&&r.rank>1){for(var i=[0],a=2;a<r.rank;++a)i.push(a);i.push(1),r=r.transpose(i)}return function(t){if(t.rank<=1)throw new h("batchFlatten requires a minimum rank of 2. Got rank: "+t.rank+".");var e=[t.shape[0],ot(t.shape,1)];return t.reshape(e)}(r)})},e.prototype.getConfig=function(){var e={};null!=this.dataFormat&&(e.dataFormat=this.dataFormat);var n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="Flatten",e}(pe);r.serialization.registerClass(Mr);var Rr=function(t){function e(e){var n=t.call(this,e)||this;return n.supportsMasking=!0,n.activation=tr(e.activation),n}return a(e,t),e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){n.invokeCallHook(t,e);var r=ne(t);return n.activation.apply(r)})},e.prototype.getConfig=function(){var e={activation:Zn(this.activation)},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="Activation",e}(pe);r.serialization.registerClass(Rr);var Fr=function(t){function e(e){var n=t.call(this,e)||this;return n.n=e.n,n.inputSpec=[{ndim:2}],n}return a(e,t),e.prototype.computeOutputShape=function(t){return[t[0],this.n,t[1]]},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){return function(t,e){return Object(r.tidy)(function(){if(2!==t.shape.length)throw new h("repeat() expects a rank-2 tensor, but received a rank-"+t.shape.length+" tensor.");return yt(dt(t,1),[1,e,1])})}(t=ne(t),n.n)})},e.prototype.getConfig=function(){var e={n:this.n},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="RepeatVector",e}(pe);r.serialization.registerClass(Fr);var jr=function(t){function e(e){var n=t.call(this,e)||this;n.targetShape=e.targetShape;for(var r=0;r<n.targetShape.length;++r)n.isUnknown(n.targetShape[r])&&(n.targetShape[r]=null);return n}return a(e,t),e.prototype.isUnknown=function(t){return t<0||null==t},e.prototype.fixUnknownDimension=function(t,e){for(var n="Total size of new array must be unchanged.",r=e.slice(),i=1,a=null,o=0;o<r.length;++o){var s=r[o];if(this.isUnknown(s)){if(null!==a)throw new h("Can only specifiy one unknown dimension.");a=o}else i*=s}var u=ot(t);if(null!==a){if(0===i||u%i!=0)throw new h(n);r[a]=u/i}else if(u!==i)throw new h(n);return r},e.prototype.computeOutputShape=function(t){for(var e=!1,n=0;n<t.length;++n)if(this.isUnknown(t[n])){e=!0;break}return e?t.slice(0,1).concat(this.targetShape):t.slice(0,1).concat(this.fixUnknownDimension(t.slice(1),this.targetShape))},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){n.invokeCallHook(t,e);var r=ne(t),i=r.shape,a=i.slice(0,1).concat(n.fixUnknownDimension(i.slice(1),n.targetShape));return r.reshape(a)})},e.prototype.getConfig=function(){var e={targetShape:this.targetShape},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="Reshape",e}(pe);r.serialization.registerClass(jr);var Pr=function(t){function e(e){var n=t.call(this,e)||this;if(null==e.dims)throw new Error("Required configuration field `dims` is missing during Permute constructor call.");if(!Array.isArray(e.dims))throw new Error("Permute constructor requires `dims` to be an Array, but received "+e.dims+" instead.");var i=lt(1,e.dims.length+1);if(!r.util.arraysEqual(e.dims.slice().sort(),i))throw new Error("Invalid permutation `dims`: "+JSON.stringify(e.dims)+" `dims` must contain consecutive integers starting from 1.");return n.dims=e.dims,n.dimsIncludingBatch=[0].concat(n.dims),n.inputSpec=[new ce({ndim:n.dims.length+1})],n}return a(e,t),e.prototype.computeOutputShape=function(t){var e=(t=re(t)).slice();return this.dims.forEach(function(n,r){e[r+1]=t[n]}),e},e.prototype.call=function(t,e){return Object(r.transpose)(ne(t),this.dimsIncludingBatch)},e.prototype.getConfig=function(){var e={dims:this.dims},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="Permute",e}(pe);r.serialization.registerClass(Pr);var Lr=function(t){function e(e){var n=t.call(this,null==e?{}:e)||this;return n.supportsMasking=!0,n.maskValue=null!=e?null==e.maskValue?0:e.maskValue:0,n}return a(e,t),e.prototype.computeOutputShape=function(t){return t},e.prototype.getConfig=function(){var e=t.prototype.getConfig.call(this),n={maskValue:this.maskValue};return Object.assign(n,e),n},e.prototype.computeMask=function(t,e){var n=ne(t);return Object(r.any)(Object(r.notEqual)(n,this.maskValue),-1)},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){n.invokeCallHook(t,e);var i=ne(t),a=Object(r.any)(Object(r.notEqual)(i,n.maskValue),-1,!0);return i.mul(a.asType(i.dtype))})},e.className="Masking",e}(pe);r.serialization.registerClass(Lr);var zr=function(t){function e(e){var n=t.call(this,e)||this;if(n.embeddings=null,n.DEFAULT_EMBEDDINGS_INITIALIZER="randomUniform",null==e.batchInputShape&&null==e.inputShape){var r=null;null!=e.batchSize&&(r=e.batchSize),null==e.inputLength?n.batchInputShape=[r,null]:n.batchInputShape=[r].concat(x(e.inputLength))}return n.inputDim=e.inputDim,I(n.inputDim,"inputDim"),n.outputDim=e.outputDim,I(n.outputDim,"outputDim"),n.embeddingsInitializer=Kt(e.embeddingsInitializer||n.DEFAULT_EMBEDDINGS_INITIALIZER),n.embeddingsRegularizer=sr(e.embeddingsRegularizer),n.activityRegularizer=sr(e.activityRegularizer),n.embeddingsConstraint=W(e.embeddingsConstraint),n.maskZero=e.maskZero,n.supportsMasking=e.maskZero,n.inputLength=e.inputLength,n}return a(e,t),e.prototype.build=function(t){this.embeddings=this.addWeight("embeddings",[this.inputDim,this.outputDim],this.dtype,this.embeddingsInitializer,this.embeddingsRegularizer,!0,this.embeddingsConstraint),this.built=!0},e.prototype.warnOnIncompatibleInputShape=function(t){},e.prototype.computeMask=function(t,e){var n=this;return Object(r.tidy)(function(){return n.maskZero?(t=ne(t),Object(r.notEqual)(t,Object(r.zerosLike)(t))):null})},e.prototype.computeOutputShape=function(t){if(t=re(t),null==this.inputLength)return t.concat([this.outputDim]);var e=x(this.inputLength);if(e.length!==t.length-1)throw new h('"inputLength" is '+this.inputLength+", but received input shape has shape "+t);for(var n=0,r=0;r<e.length;++r){var i=e[r],a=t[r+1];if(null!=i&&null!=a&&i!==a)throw new h('"inputLength" is '+this.inputLength+", but received input shape has shape "+t);null==i&&(e[n]=a),n++}return[t[0]].concat(e,[this.outputDim])},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){n.invokeCallHook(t,e);var r=ne(t);return"int32"!==r.dtype&&(r=ft(r,"int32")),wt(n.embeddings.read(),r.as1D()).reshape(re(n.computeOutputShape(r.shape)))})},e.prototype.getConfig=function(){var e={inputDim:this.inputDim,outputDim:this.outputDim,embeddingsInitializer:$t(this.embeddingsInitializer),embeddingsRegularizer:ar(this.embeddingsRegularizer),activityRegularizer:ar(this.activityRegularizer),embeddingsConstraint:B(this.embeddingsConstraint),maskZero:this.maskZero,inputLength:this.inputLength},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="Embedding",e}(pe);r.serialization.registerClass(zr);var Br=function(t){function e(e){var n=t.call(this,e||{})||this;return n.supportsMasking=!0,n}return a(e,t),e.prototype.mergeFunction=function(t){throw new p},e.prototype.computeElementwiseOpOutputShape=function(t,e){if(null==t||null==e)return null;if(t.length<e.length)return this.computeElementwiseOpOutputShape(e,t);if(0===e.length)return t;for(var n=t.slice(0,t.length-e.length),r=0;r<e.length;++r){var i=t[t.length-e.length+r],a=e[r];if(null==i||null==a||i<0||a<0)n.push(null);else if(1===i)n.push(a);else if(1===a)n.push(i);else{if(i!==a)throw new h("Operands could not be broadcast together with shapes "+JSON.stringify(t)+" "+JSON.stringify(e));n.push(i)}}return n},e.prototype.build=function(t){if(Array.isArray(t)&&!Array.isArray(t[0])&&(t=[re(t)]),(t=t).length<2)throw new h("A merge layer should be called on an Array of at least 2 inputs. Got "+t.length+" input(s).");for(var e=[],n=0,r=t;n<r.length;n++)null!=(o=r[n])&&null!==o[0]&&e.push(o[0]);if((e=C(e)).length>1)throw new h("Can not merge tensors with different batch sizes. Got tensors with shapes: "+JSON.stringify(t)+".");for(var i=null==t[0]?null:t[0].slice(1),a=1;a<t.length;++a){var o=null==t[a]?null:t[a].slice(1);i=this.computeElementwiseOpOutputShape(i,o)}var s=t.map(function(t){return t.length});-1===t.indexOf(null)&&1===C(s).length?this.reshapeRequired=!1:this.reshapeRequired=!0},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){if(t=t,n.reshapeRequired){var e=[],i=t.map(function(t){return t.rank});if(-1===i.indexOf(null)){for(var a=ct(i),o=0,s=t;o<s.length;o++){for(var u=(h=s[o]).rank,c=0;c<a-u;++c)h=dt(h,1);e.push(h)}return n.mergeFunction(e)}for(var l=!1,f=0,d=t;f<d.length;f++){var h;if(null==(u=(h=d[f]).rank)){var p=h.shape,m=p[0],g=p.slice(1).concat([m]),v=h.reshape([m].concat(ot(p.slice(1))));v=(v=Object(r.transpose)(v,[1,0])).reshape(g),e.push(v),l=!0}else if(u>1){var y=lt(1,u).concat([0]);e.push(Object(r.transpose)(h,y)),l=!0}else e.push(h)}var b=n.mergeFunction(e),x=b.rank;if(l)if(null==x){var w=b.shape;g=[m=w[w.length-1]].concat(w.slice(0,w.length-1)),b=Object(r.transpose)(b.reshape([-1,m]),[1,0]).reshape(g)}else x>1&&(y=[x-1].concat(lt(0,x-1)),b=Object(r.transpose)(b,y));return b}return n.mergeFunction(t)})},e.prototype.computeOutputShape=function(t){var e;e=null==(t=t)[0]?null:t[0].slice(1);for(var n=1;n<t.length;++n){var r=null==t[n]?null:t[n].slice(1);e=this.computeElementwiseOpOutputShape(e,r)}for(var i=[],a=0,o=t;a<o.length;a++)null!=(r=o[a])&&null!==r[0]&&i.push(r[0]);return 1===(i=C(i)).length?i.concat(e):[null].concat(e)},e.prototype.computeMask=function(t,e){return Object(r.tidy)(function(){if(null==e)return null;if(!Array.isArray(e))throw new h("`mask` should be an Array");if(!Array.isArray(t))throw new h("`inputs` should be an Array");if(e.length!==t.length)throw new h("The Array 'inputs' and 'mask' are expected to have the same length, but have different lengths ("+t.length+" vs "+e.length+")");if(e.every(function(t){return null==t}))return null;for(var n=(e=e.map(function(t){return null==t?t:Object(r.expandDims)(t,0)}))[0],i=1;i<e.length-1;++i)n=Object(r.logicalAnd)(n,e[i]);return n})},e}(pe),Ur=function(t){function e(e){return t.call(this,e)||this}return a(e,t),e.prototype.mergeFunction=function(t){return Object(r.tidy)(function(){for(var e=t[0].clone(),n=1;n<t.length;++n)e=Object(r.add)(e,t[n]);return e})},e.className="Add",e}(Br);r.serialization.registerClass(Ur);var Wr=function(t){function e(e){return t.call(this,e)||this}return a(e,t),e.prototype.mergeFunction=function(t){return Object(r.tidy)(function(){for(var e=t[0].clone(),n=1;n<t.length;++n)e=Object(r.mul)(e,t[n]);return e})},e.className="Multiply",e}(Br);r.serialization.registerClass(Wr);var Vr=function(t){function e(e){return t.call(this,e)||this}return a(e,t),e.prototype.mergeFunction=function(t){return Object(r.tidy)(function(){for(var e=t[0].clone(),n=1;n<t.length;++n)e=Object(r.add)(e,t[n]);return Object(r.mul)(1/t.length,e)})},e.className="Average",e}(Br);r.serialization.registerClass(Vr);var qr=function(t){function e(e){return t.call(this,e)||this}return a(e,t),e.prototype.mergeFunction=function(t){return Object(r.tidy)(function(){for(var e=t[0],n=1;n<t.length;++n)e=Object(r.maximum)(e,t[n]);return e})},e.className="Maximum",e}(Br);r.serialization.registerClass(qr);var Hr=function(t){function e(e){return t.call(this,e)||this}return a(e,t),e.prototype.mergeFunction=function(t){return Object(r.tidy)(function(){for(var e=t[0],n=1;n<t.length;++n)e=Object(r.minimum)(e,t[n]);return e})},e.className="Minimum",e}(Br);r.serialization.registerClass(Hr);var Gr=function(t){function e(e){var n=t.call(this,e)||this;return n.DEFAULT_AXIS=-1,null==e&&(e={}),n.axis=null==e.axis?n.DEFAULT_AXIS:e.axis,n.supportsMasking=!0,n.reshapeRequired=!1,n}return a(e,t),e.prototype.build=function(t){if(!Array.isArray(t)||!Array.isArray(t[0])||1===t.length)throw new h("A `Concatenate` layer should be called on a list of at least 2 inputs");for(var e=!0,n=0,i=t=t;n<i.length;n++)if(null!=(f=i[n])){e=!1;break}if(!e){for(var a=[],o=0;o<t.length;++o){var s=t[o].slice();s.splice(this.axis,1);for(var u=!1,c=0,l=a;c<l.length;c++){var f=l[c];if(r.util.arraysEqual(f,s)){u=!0;break}}u||a.push(s)}if(a.length>1)throw new h("A `Concatenate` layer requires inputs with matching shapes except for the concat axis. Got input shapes: "+JSON.stringify(t))}},e.prototype.mergeFunction=function(t){var e=this;return Object(r.tidy)(function(){return gt(t,e.axis)})},e.prototype.computeOutputShape=function(t){if(!Array.isArray(t)||!Array.isArray(t[0]))throw new h("A `Concatenate` layer should be called on a list of inputs.");for(var e=t,n=e[0].slice(),r=this.axis<0?n.length+this.axis:this.axis,i=0,a=e.slice(1);i<a.length;i++){var o=a[i];if(null==n[r]||null==o[r]){n[r]=null;break}n[r]+=o[r]}return n},e.prototype.computeMask=function(t,e){var n=this;if(null==e)return null;if(!Array.isArray(e))throw new h("`mask` should be an array for Concatenate");if(!Array.isArray(t))throw new h("`inputs` should be an array for Concatenate");if(e.length!==t.length)throw new h("Mismatch in the length of mask ("+e.length+") and the legnth of inputs ("+t.length+")");return Object(r.tidy)(function(){var i=!0;if(e.forEach(function(t){null==t||(i=!1)}),i)return null;for(var a=[],o=0;o<t.length;++o)null==e[o]?a.push(Object(r.onesLike)(t[o]).asType("bool")):e[o].rank<t[o].rank?a.push(Object(r.expandDims)(e[o],-1)):a.push(e[o]);var s=Object(r.concat)(a,n.axis);return Object(r.all)(s,-1,!1)})},e.prototype.getConfig=function(){var e={axis:this.axis},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="Concatenate",e}(Br);function $r(t,e){for(;t<0;)t+=e;return t}r.serialization.registerClass(Gr);var Kr=function(t){function e(e){var n=t.call(this,e)||this;return n.axes=e.axes,n.normalize=null!=e.normalize&&e.normalize,n.supportsMasking=!0,n.reshapeRequired=!1,n}return a(e,t),e.prototype.build=function(t){r.util.assert(Array.isArray(t)&&2===t.length&&Array.isArray(t[0])&&Array.isArray(t[1]),function(){return"A `Dot` layer should be called on a list of exactly 2 inputs."});var e=t[0],n=t[1];if(e.length>3||n.length>3)throw new p("Dot layer does not support tensors of 4D or higher rank yet.");var i=this.interpretAxes(e,n);if(e[i[0]]!==n[i[1]])throw new h("Dimension incompatibility: "+e[i[0]]+" !== "+n[i[1]])},e.prototype.mergeFunction=function(t){if(2!==t.length)throw new h("A `Dot` layer must be called on exactly 2 inputs, but received "+t.length+" input(s).");var e,n=t[0],i=t[1];return e=Array.isArray(this.axes)?this.axes.map(function(e,n){return $r(e,t[n].shape.length)}):[$r(this.axes,n.shape.length),$r(this.axes,i.shape.length)],this.normalize&&(n=Te(n,e[0]),i=Te(i,e[1])),function(t,e,n){if(t.shape.length>3||e.shape.length>3)throw new p("batchDot is not implemented for tensors of 4D or higher rank yet");if(r.util.assert(t.shape.length>=2,function(){return"batchDot requires the rank of x to be >= 2, but got "+t.shape.length}),r.util.assert(t.shape.length>=2,function(){return"batchDot requires the rank of y to be >= 2, but got "+e.shape.length}),"number"==typeof n&&(n=[n,n]),"complex64"===t.dtype||"complex64"===e.dtype)throw new p("batchDot is not implemented for complex64-type Tensors yet.");var i=t.shape.length,a=e.shape.length;null==n&&(n=[i-1,a-2]);var o=n;return Object(r.tidy)(function(){var n,r;if(i>a){n=i-a;for(var s=[],u=0;u<n;++u)s.push(1);e=e.reshape(e.shape.concat(s))}else if(a>i){for(n=a-i,s=[],u=0;u<n;++u)s.push(1);t=t.reshape(t.shape.concat(s))}else n=0;if(2===t.shape.length&&2===e.shape.length)r=o[0]===o[1]?t.mulStrict(e).sum(o[0]):t.transpose([1,0]).mulStrict(e).sum(o[1]);else{var c=o[0]!==t.shape.length-1,l=o[1]===e.shape.length-1;r=t.matMul(e,c,l)}if(n>0){var f,d=[];for(u=f=i>a?i+a-3:i-1;u<f+n;++u)d.push(u);r=r.squeeze(d)}return 1===r.shape.length&&(r=r.expandDims(1)),r})}(n,i,e)},e.prototype.interpretAxes=function(t,e){return Array.isArray(this.axes)?this.axes:[$r(this.axes,t.length),$r(this.axes,e.length)]},e.prototype.computeOutputShape=function(t){r.util.assert(Array.isArray(t)&&2===t.length&&Array.isArray(t[0])&&Array.isArray(t[1]),function(){return"A `Dot` layer should be called on a list of exactly 2 inputs."});var e=t[0].slice(),n=t[1].slice();if(e.length>3||n.length>3)throw new p("Dot layer does not support tensors of 4D or higher rank yet.");var i=this.interpretAxes(e,n);e.splice(i[0],1),n.splice(i[1],1),n.splice(0,1);var a=e.concat(n);return 1===a.length&&a.push(1),a},e.prototype.computeMask=function(t,e){return null},e.prototype.getConfig=function(){var e={axes:this.axes,normalize:this.normalize},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="Dot",e}(Br);r.serialization.registerClass(Kr);var Xr=function(t){function e(e){var n=t.call(this,e)||this;return n.supportsMasking=!0,n.stddev=e.stddev,n}return a(e,t),e.prototype.computeOutputShape=function(t){return t},e.prototype.getConfig=function(){var e=t.prototype.getConfig.call(this),n={stddev:this.stddev};return Object.assign(n,e),n},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){n.invokeCallHook(t,e);var r=ne(t);return St(function(){return bt(r.shape,0,n.stddev).add(r)},function(){return r},e.training||!1)})},e.className="GaussianNoise",e}(pe);r.serialization.registerClass(Xr);var Yr=function(t){function e(e){var n=t.call(this,e)||this;return n.supportsMasking=!0,n.rate=e.rate,n}return a(e,t),e.prototype.computeOutputShape=function(t){return t},e.prototype.getConfig=function(){var e=t.prototype.getConfig.call(this),n={rate:this.rate};return Object.assign(n,e),n},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){n.invokeCallHook(t,e);var r=ne(t);return n.rate>0&&n.rate<1?St(function(){var t=Math.sqrt(n.rate/(1-n.rate));return r.mul(bt(r.shape,1,t))},function(){return r},e.training||!1):r})},e.className="GaussianDropout",e}(pe);r.serialization.registerClass(Yr);var Jr=function(t){function e(e){var n=t.call(this,e)||this;return n.supportsMasking=!0,n.rate=e.rate,n.noiseShape=e.noiseShape,n}return a(e,t),e.prototype._getNoiseShape=function(t){return this.noiseShape||ne(t).shape},e.prototype.computeOutputShape=function(t){return t},e.prototype.getConfig=function(){var e=t.prototype.getConfig.call(this),n={rate:this.rate};return Object.assign(n,e),n},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){if(n.rate<1&&n.rate>0){var i=n._getNoiseShape(t);return St(function(){var e=ne(t),a=-1.7580993408473766,o=Object(r.greaterEqual)(Object(r.randomUniform)(i),n.rate);o=ft(o,"float32");var s=Math.pow((1-n.rate)*(1+n.rate*Math.pow(a,2)),-.5),u=-s*a*n.rate;return e.mul(o).add(o.add(-1).mul(a)).mul(s).add(u)},function(){return ne(t)},e.training||!1)}return t})},e.className="AlphaDropout",e}(pe);function Zr(t,e,n,i,a,o){var s;if(void 0===o&&(o=.001),2===t.rank)s=Object(r.batchNorm2d)(t,e,n,i,a,o);else if(3===t.rank)s=Object(r.batchNorm3d)(t,e,n,i,a,o);else{if(4!==t.rank)throw new p("batchNormalization is not implemented for array of rank "+t.rank+" yet");s=Object(r.batchNorm4d)(t,e,n,i,a,o)}return s}function Qr(t,e,n,i,a){return void 0===a&&(a=.001),r.util.arraysEqual(i.slice().sort(),lt(0,t.rank-1))?function(t,e,n,i,a){return void 0===a&&(a=.001),Object(r.tidy)(function(){var o=Object(r.moments)(t,i),s=o.mean,u=o.variance;return[Zr(t,s,u,n,e,a),s,u]})}(t,e,n,i,a):function(t,e,n,i,a){return void 0===a&&(a=.001),Object(r.tidy)(function(){for(var o=Object(r.moments)(t,i),s=o.mean,u=o.variance,c=[],l=0,f=lt(0,t.rank);l<f.length;l++){var d=f[l];-1!==i.indexOf(d)?c.push(1):c.push(t.shape[d])}var h=s.reshape(c),p=u.reshape(c),m=null==e?null:e.reshape(c),g=null==n?null:n.reshape(c);return[Zr(t,h,p,g,m,a),s,u]})}(t,e,n,i,a)}r.serialization.registerClass(Jr);var ti=function(t){function e(e){var n=this;return null==e&&(e={}),(n=t.call(this,e)||this).supportsMasking=!0,n.axis=null==e.axis?-1:e.axis,n.momentum=null==e.momentum?.99:e.momentum,n.epsilon=null==e.epsilon?.001:e.epsilon,n.center=null==e.center||e.center,n.scale=null==e.scale||e.scale,n.betaInitializer=Kt(e.betaInitializer||"zeros"),n.gammaInitializer=Kt(e.gammaInitializer||"ones"),n.movingMeanInitializer=Kt(e.movingMeanInitializer||"zeros"),n.movingVarianceInitializer=Kt(e.movingVarianceInitializer||"ones"),n.betaConstraint=W(e.betaConstraint),n.gammaConstraint=W(e.gammaConstraint),n.betaRegularizer=sr(e.betaRegularizer),n.gammaRegularizer=sr(e.gammaRegularizer),n}return a(e,t),e.prototype.build=function(t){var e;t=re(t);var n=this.axis>=0?this.axis:this.axis+t.length,r=t[n];if(null==r)throw new h("Axis "+n+" of input tensor should have a defined dimension but the layer received an input with shape "+JSON.stringify(t)+".");this.inputSpec=[new ce({ndim:t.length,axes:(e={},e[n]=r,e)})];var i=[r];this.scale&&(this.gamma=this.addWeight("gamma",i,null,this.gammaInitializer,this.gammaRegularizer,!0,this.gammaConstraint)),this.center&&(this.beta=this.addWeight("beta",i,null,this.betaInitializer,this.betaRegularizer,!0,this.betaConstraint)),this.movingMean=this.addWeight("moving_mean",i,null,this.movingMeanInitializer,null,!1),this.movingVariance=this.addWeight("moving_variance",i,null,this.movingVarianceInitializer,null,!1),this.built=!0},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){var i=null!=e.training&&e.training,a=ne(t),o=a.shape,s=o.length,u=lt(0,s),c=n.axis>=0?n.axis:n.axis+s;u.splice(c,1);var l=g(1,s);l[c]=o[c];var f=u.slice();f.sort();var d=!r.util.arraysEqual(f,lt(0,s).slice(0,s-1));if(!i)return function(){if(d){var t=n.movingMean.read().reshape(l),e=n.movingVariance.read().reshape(l),r=n.center?n.beta.read().reshape(l):null,i=n.scale?n.gamma.read().reshape(l):null;return Zr(a,t,e,r,i,n.epsilon)}return Zr(a,n.movingMean.read(),n.movingVariance.read(),null==n.beta?null:n.beta.read(),null==n.gamma?null:n.gamma.read(),n.epsilon)}();var h=Qr(a,n.gamma.read(),n.beta.read(),u,n.epsilon),p=h[0],m=h[1],v=h[2],y=function(t,e,n){Object(r.tidy)(function(){var r=1-n,i=t.read(),a=i.sub(e).mul(r);t.write(i.sub(a))})};return y(n.movingMean,m,n.momentum),y(n.movingVariance,v,n.momentum),p})},e.prototype.getConfig=function(){var e={axis:this.axis,momentum:this.momentum,epsilon:this.epsilon,center:this.center,scale:this.scale,betaInitializer:$t(this.betaInitializer),gammaInitializer:$t(this.gammaInitializer),movingMeanInitializer:$t(this.movingMeanInitializer),movingVarianceInitializer:$t(this.movingVarianceInitializer),betaRegularizer:ar(this.betaRegularizer),gammaRegularizer:ar(this.gammaRegularizer),betaConstraint:B(this.betaConstraint),gammaConstraint:B(this.gammaConstraint)},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="BatchNormalization",e}(pe);r.serialization.registerClass(ti);var ei=function(t){function e(e){var n=this;if(null==e&&(e={}),(n=t.call(this,e)||this).axis=null==e.axis?-1:e.axis,"number"==typeof n.axis){if(!Number.isInteger(n.axis))throw new Error("Expected axis to be an integer, but received "+n.axis)}else{if(!Array.isArray(n.axis))throw new Error("Expected axis to be an integer or an array of integers, but received "+JSON.stringify(n.axis));for(var r=0,i=n.axis;r<i.length;r++){var a=i[r];if(!Number.isInteger(a))throw new Error("Expected axis to be an array of integers, but received "+JSON.stringify(n.axis))}}return n.epsilon=null==e.epsilon?.001:e.epsilon,n.center=null==e.center||e.center,n.scale=null==e.scale||e.scale,n.betaInitializer=Kt(e.betaInitializer||"zeros"),n.gammaInitializer=Kt(e.gammaInitializer||"ones"),n.betaRegularizer=sr(e.betaRegularizer),n.gammaRegularizer=sr(e.gammaRegularizer),n.supportsMasking=!0,n}return a(e,t),e.prototype.build=function(t){var e=(t=re(t)).length;"number"==typeof this.axis&&(this.axis=[this.axis]);for(var n=0;n<this.axis.length;++n)this.axis[n]<0&&(this.axis[n]+=e);for(var r=0,i=this.axis;r<i.length;r++){var a=i[r];if(a<0||a>=e)throw new Error("Invalid axis: "+a)}if(this.axis.length!==C(this.axis).length)throw new Error("Found duplicate axes in: "+this.axis);var o=this.axis.map(function(e){return t[e]});this.scale?this.gamma=this.addWeight("gamma",o,"float32",this.gammaInitializer,this.gammaRegularizer,!0):this.gamma=null,this.center?this.beta=this.addWeight("beta",o,"float32",this.betaInitializer,this.betaRegularizer,!0):this.beta=null,this.built=!0},e.prototype.call=function(t,e){var n=this,i=ne(t),a=i.shape,o=a.length;return Object(r.tidy)(function(){for(var t=Object(r.moments)(i,n.axis,!0),e=t.mean,s=t.variance,u=g(1,o),c=0,l=n.axis;c<l.length;c++){var f=l[c];u[f]=a[f]}for(var d=function(t){return null!=t&&t.shape.length!==o&&n.axis!==[o-1]?t.reshape(u):t},h=d(n.gamma.read()),p=d(n.beta.read()),m=[],v=[],y=0;y<o;++y)-1!==n.axis.indexOf(y)?(m.push(a[y]),v.push(1)):(m.push(1),v.push(a[y]));return e=e.tile(m),s=s.tile(m),h=h.tile(v),p=p.tile(v),Zr(i,e,s,p,h,n.epsilon)})},e.prototype.getConfig=function(){var e={axis:this.axis,epsilon:this.epsilon,center:this.center,scale:this.scale,betaInitializer:$t(this.betaInitializer),gammaInitializer:$t(this.gammaInitializer),betaRegularizer:ar(this.betaRegularizer),gammaRegularizer:ar(this.gammaRegularizer)},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="LayerNormalization",e}(pe);r.serialization.registerClass(ei);var ni=function(t){function e(e){var n=this;if(null==e&&(e={}),(n=t.call(this,e)||this).dataFormat=null==e.dataFormat?"channelsLast":e.dataFormat,null==e.padding)n.padding=[[1,1],[1,1]];else if("number"==typeof e.padding)n.padding=[[e.padding,e.padding],[e.padding,e.padding]];else{if(e.padding=e.padding,2!==e.padding.length)throw new h("ZeroPadding2D expects padding to be a length-2 array, but received a length-"+e.padding.length+" array.");var r=void 0,i=void 0;if("number"==typeof e.padding[0])r=[e.padding[0],e.padding[0]],i=[e.padding[1],e.padding[1]];else{if(e.padding=e.padding,2!==e.padding[0].length)throw new h("ZeroPadding2D expects height padding to be a length-2 array, but received a length-"+e.padding[0].length+" array.");if(r=e.padding[0],2!==e.padding[1].length)throw new h("ZeroPadding2D expects width padding to be a length-2 array, but received a length-"+e.padding[1].length+" array.");i=e.padding[1]}n.padding=[r,i]}return n.inputSpec=[new ce({ndim:4})],n}return a(e,t),e.prototype.computeOutputShape=function(t){var e,n;return t=re(t),"channelsFirst"===this.dataFormat?(e=null!=t[2]&&t[2]>=0?t[2]+this.padding[0][0]+this.padding[0][1]:null,n=null!=t[3]&&t[3]>=0?t[3]+this.padding[1][0]+this.padding[1][1]:null,[t[0],t[1],e,n]):(e=null!=t[1]&&t[1]>=0?t[1]+this.padding[0][0]+this.padding[0][1]:null,n=null!=t[2]&&t[2]>=0?t[2]+this.padding[1][0]+this.padding[1][1]:null,[t[0],e,n,t[3]])},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){return function(t,e,n){return Object(r.tidy)(function(){if(4!==t.rank)throw new h("temporalPadding expects input tensor to be 4-D, but received a "+t.rank+"-D tensor.");if(null==e&&(e=[[1,1],[1,1]]),2!==e.length||2!==e[0].length||2!==e[1].length)throw new h("spatial2dPadding expects `padding` to be an Array of two Arrays, each of which is an Array of two integers.");if(null==n&&(n="channelsLast"),"channelsLast"!==n&&"channelsFirst"!==n)throw new h("Unknown data format: "+n+". Supported data formats are 'channelsLast' and 'channelsFirst.");var i;return i="channelsFirst"===n?[[0,0],[0,0],e[0],e[1]]:[[0,0],e[0],e[1],[0,0]],Object(r.pad)(t,i)})}(ne(t),n.padding,n.dataFormat)})},e.prototype.getConfig=function(){var e={padding:this.padding,dataFormat:this.dataFormat},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="ZeroPadding2D",e}(pe);function ri(t,e,n,i,a,o){return Object(r.tidy)(function(){var s;X(a),J(o),Y(i),null==n&&(n=[1,1]),null==i&&(i="valid"),null==a&&(a="channelsLast"),null==o&&(o="max"),t=vr(t,a);var u="same"===i?"same":"valid";return s="max"===o?Object(r.maxPool)(t,e,n,u):Object(r.avgPool)(t,e,n,u),"channelsFirst"===a&&(s=Object(r.transpose)(s,[0,3,1,2])),s})}function ii(t,e,n,i,a,o){return Object(r.tidy)(function(){var s;X(a),J(o),Y(i),null==n&&(n=[1,1,1]),null==i&&(i="valid"),null==a&&(a="channelsLast"),null==o&&(o="max"),t=yr(t,a);var u="same"===i?"same":"valid";return s="max"===o?Object(r.maxPool3d)(t,e,n,u):Object(r.avgPool3d)(t,e,n,u),"channelsFirst"===a&&(s=Object(r.transpose)(s,[0,4,1,2,3])),s})}r.serialization.registerClass(ni);var ai=function(t){function e(e){var n=this;if(null==e.poolSize&&(e.poolSize=2),n=t.call(this,e)||this,"number"==typeof e.poolSize)n.poolSize=[e.poolSize];else{if(!Array.isArray(e.poolSize)||1!==e.poolSize.length||"number"!=typeof e.poolSize[0])throw new h("poolSize for 1D convolutional layer must be a number or an Array of a single number, but received "+JSON.stringify(e.poolSize));n.poolSize=e.poolSize}if(I(n.poolSize,"poolSize"),null==e.strides)n.strides=n.poolSize;else if("number"==typeof e.strides)n.strides=[e.strides];else{if(!Array.isArray(e.strides)||1!==e.strides.length||"number"!=typeof e.strides[0])throw new h("strides for 1D convolutional layer must be a number or an Array of a single number, but received "+JSON.stringify(e.strides));n.strides=e.strides}return I(n.strides,"strides"),n.padding=null==e.padding?"valid":e.padding,Y(n.padding),n.inputSpec=[new ce({ndim:3})],n}return a(e,t),e.prototype.computeOutputShape=function(t){var e=mr((t=re(t))[1],this.poolSize[0],this.padding,this.strides[0]);return[t[0],e,t[2]]},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){n.invokeCallHook(t,e),t=dt(ne(t),2);var i=n.poolingFunction(ne(t),[n.poolSize[0],1],[n.strides[0],1],n.padding,"channelsLast");return Object(r.squeeze)(i,[2])})},e.prototype.getConfig=function(){var e={poolSize:this.poolSize,padding:this.padding,strides:this.strides},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e}(pe),oi=function(t){function e(e){return t.call(this,e)||this}return a(e,t),e.prototype.poolingFunction=function(t,e,n,r,i){return X(i),Y(r),ri(t,e,n,r,i,"max")},e.className="MaxPooling1D",e}(ai);r.serialization.registerClass(oi);var si=function(t){function e(e){return t.call(this,e)||this}return a(e,t),e.prototype.poolingFunction=function(t,e,n,r,i){return X(i),Y(r),ri(t,e,n,r,i,"avg")},e.className="AveragePooling1D",e}(ai);r.serialization.registerClass(si);var ui=function(t){function e(e){var n=this;if(null==e.poolSize&&(e.poolSize=[2,2]),(n=t.call(this,e)||this).poolSize=Array.isArray(e.poolSize)?e.poolSize:[e.poolSize,e.poolSize],null==e.strides)n.strides=n.poolSize;else if(Array.isArray(e.strides)){if(2!==e.strides.length)throw new h("If the strides property of a 2D pooling layer is an Array, it is expected to have a length of 2, but received length "+e.strides.length+".");n.strides=e.strides}else n.strides=[e.strides,e.strides];return I(n.poolSize,"poolSize"),I(n.strides,"strides"),n.padding=null==e.padding?"valid":e.padding,n.dataFormat=null==e.dataFormat?"channelsLast":e.dataFormat,X(n.dataFormat),Y(n.padding),n.inputSpec=[new ce({ndim:4})],n}return a(e,t),e.prototype.computeOutputShape=function(t){t=re(t);var e="channelsFirst"===this.dataFormat?t[2]:t[1],n="channelsFirst"===this.dataFormat?t[3]:t[2];return e=mr(e,this.poolSize[0],this.padding,this.strides[0]),n=mr(n,this.poolSize[1],this.padding,this.strides[1]),"channelsFirst"===this.dataFormat?[t[0],t[1],e,n]:[t[0],e,n,t[3]]},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){return n.invokeCallHook(t,e),n.poolingFunction(ne(t),n.poolSize,n.strides,n.padding,n.dataFormat)})},e.prototype.getConfig=function(){var e={poolSize:this.poolSize,padding:this.padding,strides:this.strides,dataFormat:this.dataFormat},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e}(pe),ci=function(t){function e(e){return t.call(this,e)||this}return a(e,t),e.prototype.poolingFunction=function(t,e,n,r,i){return X(i),Y(r),ri(t,e,n,r,i,"max")},e.className="MaxPooling2D",e}(ui);r.serialization.registerClass(ci);var li=function(t){function e(e){return t.call(this,e)||this}return a(e,t),e.prototype.poolingFunction=function(t,e,n,r,i){return X(i),Y(r),ri(t,e,n,r,i,"avg")},e.className="AveragePooling2D",e}(ui);r.serialization.registerClass(li);var fi=function(t){function e(e){var n=this;if(null==e.poolSize&&(e.poolSize=[2,2,2]),(n=t.call(this,e)||this).poolSize=Array.isArray(e.poolSize)?e.poolSize:[e.poolSize,e.poolSize,e.poolSize],null==e.strides)n.strides=n.poolSize;else if(Array.isArray(e.strides)){if(3!==e.strides.length)throw new h("If the strides property of a 3D pooling layer is an Array, it is expected to have a length of 3, but received length "+e.strides.length+".");n.strides=e.strides}else n.strides=[e.strides,e.strides,e.strides];return I(n.poolSize,"poolSize"),I(n.strides,"strides"),n.padding=null==e.padding?"valid":e.padding,n.dataFormat=null==e.dataFormat?"channelsLast":e.dataFormat,X(n.dataFormat),Y(n.padding),n.inputSpec=[new ce({ndim:5})],n}return a(e,t),e.prototype.computeOutputShape=function(t){t=re(t);var e="channelsFirst"===this.dataFormat?t[2]:t[1],n="channelsFirst"===this.dataFormat?t[3]:t[2],r="channelsFirst"===this.dataFormat?t[4]:t[3];return e=mr(e,this.poolSize[0],this.padding,this.strides[0]),n=mr(n,this.poolSize[1],this.padding,this.strides[1]),r=mr(r,this.poolSize[2],this.padding,this.strides[2]),"channelsFirst"===this.dataFormat?[t[0],t[1],e,n,r]:[t[0],e,n,r,t[4]]},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){return n.invokeCallHook(t,e),n.poolingFunction(ne(t),n.poolSize,n.strides,n.padding,n.dataFormat)})},e.prototype.getConfig=function(){var e={poolSize:this.poolSize,padding:this.padding,strides:this.strides,dataFormat:this.dataFormat},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e}(pe),di=function(t){function e(e){return t.call(this,e)||this}return a(e,t),e.prototype.poolingFunction=function(t,e,n,r,i){return X(i),Y(r),ii(t,e,n,r,i,"max")},e.className="MaxPooling3D",e}(fi);r.serialization.registerClass(di);var hi=function(t){function e(e){return t.call(this,e)||this}return a(e,t),e.prototype.poolingFunction=function(t,e,n,r,i){return X(i),Y(r),ii(t,e,n,r,i,"avg")},e.className="AveragePooling3D",e}(fi);r.serialization.registerClass(hi);var pi=function(t){function e(e){var n=t.call(this,e)||this;return n.inputSpec=[new ce({ndim:3})],n}return a(e,t),e.prototype.computeOutputShape=function(t){return[t[0],t[2]]},e.prototype.call=function(t,e){throw new p},e}(pe),mi=function(t){function e(e){return t.call(this,e||{})||this}return a(e,t),e.prototype.call=function(t,e){return Object(r.tidy)(function(){var e=ne(t);return Object(r.mean)(e,1)})},e.className="GlobalAveragePooling1D",e}(pi);r.serialization.registerClass(mi);var gi=function(t){function e(e){return t.call(this,e||{})||this}return a(e,t),e.prototype.call=function(t,e){return Object(r.tidy)(function(){var e=ne(t);return Object(r.max)(e,1)})},e.className="GlobalMaxPooling1D",e}(pi);r.serialization.registerClass(gi);var vi=function(t){function e(e){var n=t.call(this,e)||this;return n.dataFormat=null==e.dataFormat?"channelsLast":e.dataFormat,X(n.dataFormat),n.inputSpec=[new ce({ndim:4})],n}return a(e,t),e.prototype.computeOutputShape=function(t){return t=t,"channelsLast"===this.dataFormat?[t[0],t[3]]:[t[0],t[1]]},e.prototype.call=function(t,e){throw new p},e.prototype.getConfig=function(){var e={dataFormat:this.dataFormat},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e}(pe),yi=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){var e=ne(t);return"channelsLast"===n.dataFormat?Object(r.mean)(e,[1,2]):Object(r.mean)(e,[2,3])})},e.className="GlobalAveragePooling2D",e}(vi);r.serialization.registerClass(yi);var bi=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){var e=ne(t);return"channelsLast"===n.dataFormat?Object(r.max)(e,[1,2]):Object(r.max)(e,[2,3])})},e.className="GlobalMaxPooling2D",e}(vi);function xi(t,e,n,r){if(Array.isArray(t)){if(null!=e||null!=n)throw new h("When inputs is an array, neither initialState or constants should be provided");null!=r&&(n=t.slice(t.length-r,t.length),t=t.slice(0,t.length-r)),t.length>1&&(e=t.slice(1,t.length)),t=t[0]}function i(t){return null==t||Array.isArray(t)?t:[t]}return{inputs:t,initialState:e=i(e),constants:n=i(n)}}function wi(t,e,n,i,a,o,s,u){return void 0===i&&(i=!1),void 0===s&&(s=!1),void 0===u&&(u=!1),Object(r.tidy)(function(){var c=e.shape.length;if(c<3)throw new h("Input should be at least 3D, but is "+c+"D.");var l=[1,0].concat(lt(2,c));if(e=Object(r.transpose)(e,l),null!=o)throw new p("The rnn() functoin of the deeplearn.js backend does not support constants yet.");s&&console.warn("Backend rnn(): the unroll = true option is not applicable to the imperative deeplearn.js backend."),null!=a&&((a=a.asType("bool").asType("float32")).rank===c-1&&(a=Object(r.expandDims)(a,-1)),a=Object(r.transpose)(a,l)),i&&(e=Object(r.reverse)(e,0),null!=a&&(a=Object(r.reverse)(a,0)));var f,d,m=[],g=n,v=e.shape[0],y=Object(r.unstack)(e);null!=a&&(d=Object(r.unstack)(a));for(var b,x=function(e){var n=y[e],i=Object(r.tidy)(function(){return t(n,g)});if(null==a)f=i[0],g=i[1];else{var o=Object(r.tidy)(function(){var t=d[e],n=Object(r.onesLike)(t).sub(t);return{output:i[0].mul(t).addStrict(g[0].mul(n)),newStates:g.map(function(e,r){return i[1][r].mul(t).addStrict(e.mul(n))})}});f=o.output,g=o.newStates}u&&m.push(f)},w=0;w<v;++w)x(w);return u&&(b=Object(r.stack)(m,1)),[f,b,g]})}r.serialization.registerClass(bi);var ki=function(t){function e(e){var n,r=t.call(this,e)||this;if(null==e.cell)throw new h("cell property is missing for the constructor of RNN.");if(null==(n=Array.isArray(e.cell)?new Ti({cells:e.cell}):e.cell).stateSize)throw new h("The RNN cell should have an attribute `stateSize` (tuple of integers, one integer per RNN state).");return r.cell=n,r.returnSequences=null!=e.returnSequences&&e.returnSequences,r.returnState=null!=e.returnState&&e.returnState,r.goBackwards=null!=e.goBackwards&&e.goBackwards,r._stateful=null!=e.stateful&&e.stateful,r.unroll=null!=e.unroll&&e.unroll,r.supportsMasking=!0,r.inputSpec=[new ce({ndim:3})],r.stateSpec=null,r.states_=null,r.numConstants=null,r.keptStates=[],r}return a(e,t),e.prototype.getStates=function(){return null==this.states_?lt(0,Array.isArray(this.cell.stateSize)?this.cell.stateSize.length:1).map(function(t){return null}):this.states_},e.prototype.setStates=function(t){this.states_=t},e.prototype.computeOutputShape=function(t){te(t)&&(t=t[0]),t=t;var e=this.cell.stateSize;Array.isArray(e)||(e=[e]);var n,r=e[0];if(n=this.returnSequences?[t[0],t[1],r]:[t[0],r],this.returnState){for(var i=[],a=0,o=e;a<o.length;a++){var s=o[a];i.push([t[0],s])}return[n].concat(i)}return n},e.prototype.computeMask=function(t,e){var n=this;return Object(r.tidy)(function(){Array.isArray(e)&&(e=e[0]);var t=n.returnSequences?e:null;if(n.returnState){var r=n.states.map(function(t){return null});return[t].concat(r)}return t})},Object.defineProperty(e.prototype,"states",{get:function(){if(null==this.states_){for(var t=Array.isArray(this.cell.stateSize)?this.cell.stateSize.length:1,e=[],n=0;n<t;++n)e.push(null);return e}return this.states_},set:function(t){this.states_=t},enumerable:!0,configurable:!0}),e.prototype.build=function(t){if(null!=this.numConstants)throw new p("Constants support is not implemented in RNN yet.");te(t)&&(t=t[0]),t=t;var e=this.stateful?t[0]:null,n=t[t.length-1];this.inputSpec[0]=new ce({shape:[e,null,n]});var i,a=[t[0]].concat(t.slice(2));if(this.cell.build(a),i=Array.isArray(this.cell.stateSize)?this.cell.stateSize:[this.cell.stateSize],null!=this.stateSpec){if(!r.util.arraysEqual(this.stateSpec.map(function(t){return t.shape[t.shape.length-1]}),i))throw new h("An initialState was passed that is not compatible with cell.stateSize. Received stateSpec="+this.stateSpec+"; However cell.stateSize is "+this.cell.stateSize)}else this.stateSpec=i.map(function(t){return new ce({shape:[null,t]})});this.stateful&&this.resetStates()},e.prototype.resetStates=function(t,e){var n=this;void 0===e&&(e=!1),Object(r.tidy)(function(){if(!n.stateful)throw new f("Cannot call resetStates() on an RNN Layer that is not stateful.");var i=n.inputSpec[0].shape[0];if(null==i)throw new h("If an RNN is stateful, it needs to know its batch size. Specify the batch size of your input tensors: \n- If using a Sequential model, specify the batch size by passing a `batchInputShape` option to your first layer.\n- If using the functional API, specify the batch size by passing a `batchShape` option to your Input layer.");if(null==n.states_)Array.isArray(n.cell.stateSize)?n.states_=n.cell.stateSize.map(function(t){return Object(r.zeros)([i,t])}):n.states_=[Object(r.zeros)([i,n.cell.stateSize])];else if(null==t)Object(r.dispose)(n.states_),null!=n.keptStates&&(Object(r.dispose)(n.keptStates),n.keptStates=[]),Array.isArray(n.cell.stateSize)?n.states_=n.cell.stateSize.map(function(t){return Object(r.zeros)([i,t])}):n.states_[0]=Object(r.zeros)([i,n.cell.stateSize]);else{if(Array.isArray(t)||(t=[t]),t.length!==n.states_.length)throw new h("Layer "+n.name+" expects "+n.states_.length+" state(s), but it received "+t.length+" state value(s). Input received: "+t);!0===e?n.keptStates.push(n.states_.slice()):Object(r.dispose)(n.states_);for(var a=0;a<n.states_.length;++a){var o=t[a],s=Array.isArray(n.cell.stateSize)?n.cell.stateSize[a]:n.cell.stateSize,u=[i,s];if(!r.util.arraysEqual(o.shape,u))throw new h("State "+a+" is incompatible with layer "+n.name+": expected shape="+u+", received shape="+o.shape);n.states_[a]=o}}n.states_=n.states_.map(function(t){return Object(r.keep)(t.clone())})})},e.prototype.apply=function(e,n){var r=null==n?null:n.initialState,i=null==n?null:n.constants;null==n&&(n={});var a=xi(e,r,i,this.numConstants);e=a.inputs,r=a.initialState,i=a.constants;var o=[],s=[];if(null!=r){n.initialState=r,o=o.concat(r),this.stateSpec=[];for(var u=0,c=r;u<c.length;u++){var l=c[u];this.stateSpec.push(new ce({shape:l.shape}))}s=s.concat(this.stateSpec)}if(null!=i&&(n.constants=i,o=o.concat(i),this.numConstants=i.length),o[0]instanceof le){var f=[e].concat(o),d=this.inputSpec.concat(s),h=this.inputSpec;this.inputSpec=d;var p=t.prototype.apply.call(this,f,n);return this.inputSpec=h,p}return t.prototype.apply.call(this,e,n)},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){var r=null==e?null:e.mask,i=null==e?null:e.training,a=null==e?null:e.initialState;t=ne(t),null==a&&(a=n.stateful?n.states_:n.getInitialState(t));var o=Array.isArray(n.cell.stateSize)?n.cell.stateSize.length:1;if(a.length!==o)throw new h("RNN Layer has "+o+" state(s) but was passed "+a.length+" initial state(s).");n.unroll&&console.warn("Ignoring unroll = true for RNN layer, due to imperative backend.");var s={training:i},u=wi(function(t,e){var r=n.cell.call([t].concat(e),s);return[r[0],r.slice(1)]},t,a,n.goBackwards,r,null,n.unroll,n.returnSequences),c=u[0],l=u[1],f=u[2];n.stateful&&n.resetStates(f,i);var d=n.returnSequences?l:c;return n.returnState?[d].concat(f):d})},e.prototype.getInitialState=function(t){var e=this;return Object(r.tidy)(function(){var n=Object(r.zeros)(t.shape);return n=dt(n=Object(r.sum)(n,[1,2])),Array.isArray(e.cell.stateSize)?e.cell.stateSize.map(function(t){return t>1?yt(n,[1,t]):n}):e.cell.stateSize>1?[yt(n,[1,e.cell.stateSize])]:[n]})},Object.defineProperty(e.prototype,"trainableWeights",{get:function(){return this.trainable?this.cell.trainableWeights:[]},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"nonTrainableWeights",{get:function(){return this.trainable?this.cell.nonTrainableWeights:this.cell.weights},enumerable:!0,configurable:!0}),e.prototype.setFastWeightInitDuringBuild=function(e){t.prototype.setFastWeightInitDuringBuild.call(this,e),null!=this.cell&&this.cell.setFastWeightInitDuringBuild(e)},e.prototype.getConfig=function(){var e={returnSequences:this.returnSequences,returnState:this.returnState,goBackwards:this.goBackwards,stateful:this.stateful,unroll:this.unroll};null!=this.numConstants&&(e.numConstants=this.numConstants);var n=this.cell.getConfig();e.cell={className:this.cell.getClassName(),config:n};var r=t.prototype.getConfig.call(this);return Object.assign(e,r),e},e.fromConfig=function(t,e,n){void 0===n&&(n={});var r=Ne(e.cell,n);return new t(Object.assign(e,{cell:r}))},e.className="RNN",e}(pe);r.serialization.registerClass(ki);var _i=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e}(pe),Ei=function(t){function e(e){var n=t.call(this,e)||this;return n.DEFAULT_ACTIVATION="tanh",n.DEFAULT_KERNEL_INITIALIZER="glorotNormal",n.DEFAULT_RECURRENT_INITIALIZER="orthogonal",n.DEFAULT_BIAS_INITIALIZER="zeros",n.units=e.units,I(n.units,"units"),n.activation=tr(null==e.activation?n.DEFAULT_ACTIVATION:e.activation),n.useBias=null==e.useBias||e.useBias,n.kernelInitializer=Kt(e.kernelInitializer||n.DEFAULT_KERNEL_INITIALIZER),n.recurrentInitializer=Kt(e.recurrentInitializer||n.DEFAULT_RECURRENT_INITIALIZER),n.biasInitializer=Kt(e.biasInitializer||n.DEFAULT_BIAS_INITIALIZER),n.kernelRegularizer=sr(e.kernelRegularizer),n.recurrentRegularizer=sr(e.recurrentRegularizer),n.biasRegularizer=sr(e.biasRegularizer),n.kernelConstraint=W(e.kernelConstraint),n.recurrentConstraint=W(e.recurrentConstraint),n.biasConstraint=W(e.biasConstraint),n.dropout=ut([1,ct([0,null==e.dropout?0:e.dropout])]),n.recurrentDropout=ut([1,ct([0,null==e.recurrentDropout?0:e.recurrentDropout])]),n.stateSize=n.units,n.dropoutMask=null,n.recurrentDropoutMask=null,n}return a(e,t),e.prototype.build=function(t){t=re(t),this.kernel=this.addWeight("kernel",[t[t.length-1],this.units],null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.recurrentKernel=this.addWeight("recurrent_kernel",[this.units,this.units],null,this.recurrentInitializer,this.recurrentRegularizer,!0,this.recurrentConstraint),this.useBias?this.bias=this.addWeight("bias",[this.units],null,this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint):this.bias=null,this.built=!0},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){if(2!==(t=t).length)throw new h("SimpleRNNCell expects 2 input Tensors, got "+t.length+".");var i=t[1];t=t[0];var a,o=null!=e.training&&e.training;0<n.dropout&&n.dropout<1&&null==n.dropoutMask&&(n.dropoutMask=Ii(function(){return Object(r.onesLike)(t)},n.dropout,o)),0<n.recurrentDropout&&n.recurrentDropout<1&&null==n.recurrentDropoutMask&&(n.recurrentDropoutMask=Ii(function(){return Object(r.onesLike)(i)},n.recurrentDropout,o));var s=n.dropoutMask,u=n.recurrentDropoutMask;a=xt(null!=s?Object(r.mul)(t,s):t,n.kernel.read()),null!=n.bias&&(a=Et(a,n.bias.read())),null!=u&&(i=Object(r.mul)(i,u));var c=Object(r.add)(a,xt(i,n.recurrentKernel.read()));return null!=n.activation&&(c=n.activation.apply(c)),[c,c]})},e.prototype.getConfig=function(){var e={units:this.units,activation:Zn(this.activation),useBias:this.useBias,kernelInitializer:$t(this.kernelInitializer),recurrentInitializer:$t(this.recurrentInitializer),biasInitializer:$t(this.biasInitializer),kernelRegularizer:ar(this.kernelRegularizer),recurrentRegularizer:ar(this.recurrentRegularizer),biasRegularizer:ar(this.biasRegularizer),activityRegularizer:ar(this.activityRegularizer),kernelConstraint:B(this.kernelConstraint),recurrentConstraint:B(this.recurrentConstraint),biasConstraint:B(this.biasConstraint),dropout:this.dropout,recurrentDropout:this.recurrentDropout},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="SimpleRNNCell",e}(_i);r.serialization.registerClass(Ei);var Oi=function(t){function e(e){return e.cell=new Ei(e),t.call(this,e)||this}return a(e,t),e.prototype.call=function(e,n){var i=this;return Object(r.tidy)(function(){null!=i.cell.dropoutMask&&(Object(r.dispose)(i.cell.dropoutMask),i.cell.dropoutMask=null),null!=i.cell.recurrentDropoutMask&&(Object(r.dispose)(i.cell.recurrentDropoutMask),i.cell.recurrentDropoutMask=null);var a=null==n?null:n.mask,o=null==n?null:n.training,s=null==n?null:n.initialState;return t.prototype.call.call(i,e,{mask:a,training:o,initialState:s})})},Object.defineProperty(e.prototype,"units",{get:function(){return this.cell.units},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"activation",{get:function(){return this.cell.activation},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"useBias",{get:function(){return this.cell.useBias},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"kernelInitializer",{get:function(){return this.cell.kernelInitializer},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"recurrentInitializer",{get:function(){return this.cell.recurrentInitializer},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"biasInitializer",{get:function(){return this.cell.biasInitializer},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"kernelRegularizer",{get:function(){return this.cell.kernelRegularizer},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"recurrentRegularizer",{get:function(){return this.cell.recurrentRegularizer},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"biasRegularizer",{get:function(){return this.cell.biasRegularizer},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"kernelConstraint",{get:function(){return this.cell.kernelConstraint},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"recurrentConstraint",{get:function(){return this.cell.recurrentConstraint},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"biasConstraint",{get:function(){return this.cell.biasConstraint},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"dropout",{get:function(){return this.cell.dropout},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"recurrentDropout",{get:function(){return this.cell.recurrentDropout},enumerable:!0,configurable:!0}),e.prototype.getConfig=function(){var e={units:this.units,activation:Zn(this.activation),useBias:this.useBias,kernelInitializer:$t(this.kernelInitializer),recurrentInitializer:$t(this.recurrentInitializer),biasInitializer:$t(this.biasInitializer),kernelRegularizer:ar(this.kernelRegularizer),recurrentRegularizer:ar(this.recurrentRegularizer),biasRegularizer:ar(this.biasRegularizer),activityRegularizer:ar(this.activityRegularizer),kernelConstraint:B(this.kernelConstraint),recurrentConstraint:B(this.recurrentConstraint),biasConstraint:B(this.biasConstraint),dropout:this.dropout,recurrentDropout:this.recurrentDropout},n=t.prototype.getConfig.call(this);return delete n.cell,Object.assign(e,n),e},e.fromConfig=function(t,e){return new t(e)},e.className="SimpleRNN",e}(ki);r.serialization.registerClass(Oi);var Si=function(t){function e(e){var n=t.call(this,e)||this;return n.DEFAULT_ACTIVATION="tanh",n.DEFAULT_RECURRENT_ACTIVATION="hardSigmoid",n.DEFAULT_KERNEL_INITIALIZER="glorotNormal",n.DEFAULT_RECURRENT_INITIALIZER="orthogonal",n.DEFAULT_BIAS_INITIALIZER="zeros",n.units=e.units,I(n.units,"units"),n.activation=tr(void 0===e.activation?n.DEFAULT_ACTIVATION:e.activation),n.recurrentActivation=tr(void 0===e.recurrentActivation?n.DEFAULT_RECURRENT_ACTIVATION:e.recurrentActivation),n.useBias=null==e.useBias||e.useBias,n.kernelInitializer=Kt(e.kernelInitializer||n.DEFAULT_KERNEL_INITIALIZER),n.recurrentInitializer=Kt(e.recurrentInitializer||n.DEFAULT_RECURRENT_INITIALIZER),n.biasInitializer=Kt(e.biasInitializer||n.DEFAULT_BIAS_INITIALIZER),n.kernelRegularizer=sr(e.kernelRegularizer),n.recurrentRegularizer=sr(e.recurrentRegularizer),n.biasRegularizer=sr(e.biasRegularizer),n.kernelConstraint=W(e.kernelConstraint),n.recurrentConstraint=W(e.recurrentConstraint),n.biasConstraint=W(e.biasConstraint),n.dropout=ut([1,ct([0,null==e.dropout?0:e.dropout])]),n.recurrentDropout=ut([1,ct([0,null==e.recurrentDropout?0:e.recurrentDropout])]),n.implementation=e.implementation,n.stateSize=n.units,n.dropoutMask=null,n.recurrentDropoutMask=null,n}return a(e,t),e.prototype.build=function(t){var e=(t=re(t))[t.length-1];this.kernel=this.addWeight("kernel",[e,3*this.units],null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.recurrentKernel=this.addWeight("recurrent_kernel",[this.units,3*this.units],null,this.recurrentInitializer,this.recurrentRegularizer,!0,this.recurrentConstraint),this.useBias?this.bias=this.addWeight("bias",[3*this.units],null,this.biasInitializer,this.biasRegularizer,!0,this.biasConstraint):this.bias=null,this.built=!0},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){if(2!==(t=t).length)throw new h("GRUCell expects 2 input Tensors (inputs, h, c), got "+t.length+".");var i=null!=e.training&&e.training,a=t[1];t=t[0],0<n.dropout&&n.dropout<1&&null==n.dropoutMask&&(n.dropoutMask=Ii(function(){return Object(r.onesLike)(t)},n.dropout,i,3)),0<n.recurrentDropout&&n.recurrentDropout<1&&null==n.recurrentDropoutMask&&(n.recurrentDropoutMask=Ii(function(){return Object(r.onesLike)(a)},n.recurrentDropout,i,3));var o,s,u,c=n.dropoutMask,l=n.recurrentDropoutMask;0<n.dropout&&n.dropout<1&&(t=Object(r.mul)(t,c[0]));var f=xt(t,n.kernel.read());n.useBias&&(f=Et(f,n.bias.read())),0<n.recurrentDropout&&n.recurrentDropout<1&&(a=Object(r.mul)(a,l[0]));var d=n.recurrentKernel.read(),p=Object(r.split)(d,[2*n.units,n.units],d.rank-1),m=p[0],g=p[1],v=xt(a,m),y=Object(r.split)(f,3,f.rank-1),b=y[0],x=y[1],w=y[2],k=Object(r.split)(v,2,v.rank-1),_=k[0],E=k[1];o=n.recurrentActivation.apply(Object(r.add)(b,_)),s=n.recurrentActivation.apply(Object(r.add)(x,E));var O=xt(Object(r.mul)(s,a),g);u=n.activation.apply(Object(r.add)(w,O));var S=Object(r.add)(Object(r.mul)(o,a),Object(r.mul)(Object(r.add)(1,Object(r.neg)(o)),u));return[S,S]})},e.prototype.getConfig=function(){var e={units:this.units,activation:Zn(this.activation),recurrentActivation:Zn(this.recurrentActivation),useBias:this.useBias,kernelInitializer:$t(this.kernelInitializer),recurrentInitializer:$t(this.recurrentInitializer),biasInitializer:$t(this.biasInitializer),kernelRegularizer:ar(this.kernelRegularizer),recurrentRegularizer:ar(this.recurrentRegularizer),biasRegularizer:ar(this.biasRegularizer),activityRegularizer:ar(this.activityRegularizer),kernelConstraint:B(this.kernelConstraint),recurrentConstraint:B(this.recurrentConstraint),biasConstraint:B(this.biasConstraint),dropout:this.dropout,recurrentDropout:this.recurrentDropout,implementation:this.implementation},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="GRUCell",e}(_i);r.serialization.registerClass(Si);var Ci=function(t){function e(e){return 0===e.implementation&&console.warn("`implementation=0` has been deprecated, and now defaults to `implementation=1`. Please update your layer call."),e.cell=new Si(e),t.call(this,e)||this}return a(e,t),e.prototype.call=function(e,n){var i=this;return Object(r.tidy)(function(){null!=i.cell.dropoutMask&&(Object(r.dispose)(i.cell.dropoutMask),i.cell.dropoutMask=null),null!=i.cell.recurrentDropoutMask&&(Object(r.dispose)(i.cell.recurrentDropoutMask),i.cell.recurrentDropoutMask=null);var a=null==n?null:n.mask,o=null==n?null:n.training,s=null==n?null:n.initialState;return t.prototype.call.call(i,e,{mask:a,training:o,initialState:s})})},Object.defineProperty(e.prototype,"units",{get:function(){return this.cell.units},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"activation",{get:function(){return this.cell.activation},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"recurrentActivation",{get:function(){return this.cell.recurrentActivation},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"useBias",{get:function(){return this.cell.useBias},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"kernelInitializer",{get:function(){return this.cell.kernelInitializer},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"recurrentInitializer",{get:function(){return this.cell.recurrentInitializer},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"biasInitializer",{get:function(){return this.cell.biasInitializer},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"kernelRegularizer",{get:function(){return this.cell.kernelRegularizer},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"recurrentRegularizer",{get:function(){return this.cell.recurrentRegularizer},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"biasRegularizer",{get:function(){return this.cell.biasRegularizer},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"kernelConstraint",{get:function(){return this.cell.kernelConstraint},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"recurrentConstraint",{get:function(){return this.cell.recurrentConstraint},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"biasConstraint",{get:function(){return this.cell.biasConstraint},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"dropout",{get:function(){return this.cell.dropout},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"recurrentDropout",{get:function(){return this.cell.recurrentDropout},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"implementation",{get:function(){return this.cell.implementation},enumerable:!0,configurable:!0}),e.prototype.getConfig=function(){var e={units:this.units,activation:Zn(this.activation),recurrentActivation:Zn(this.recurrentActivation),useBias:this.useBias,kernelInitializer:$t(this.kernelInitializer),recurrentInitializer:$t(this.recurrentInitializer),biasInitializer:$t(this.biasInitializer),kernelRegularizer:ar(this.kernelRegularizer),recurrentRegularizer:ar(this.recurrentRegularizer),biasRegularizer:ar(this.biasRegularizer),activityRegularizer:ar(this.activityRegularizer),kernelConstraint:B(this.kernelConstraint),recurrentConstraint:B(this.recurrentConstraint),biasConstraint:B(this.biasConstraint),dropout:this.dropout,recurrentDropout:this.recurrentDropout,implementation:this.implementation},n=t.prototype.getConfig.call(this);return delete n.cell,Object.assign(e,n),e},e.fromConfig=function(t,e){return 0===e.implmentation&&(e.implementation=1),new t(e)},e.className="GRU",e}(ki);r.serialization.registerClass(Ci);var Ai=function(t){function e(e){var n=t.call(this,e)||this;return n.DEFAULT_ACTIVATION="tanh",n.DEFAULT_RECURRENT_ACTIVATION="hardSigmoid",n.DEFAULT_KERNEL_INITIALIZER="glorotNormal",n.DEFAULT_RECURRENT_INITIALIZER="orthogonal",n.DEFAULT_BIAS_INITIALIZER="zeros",n.units=e.units,I(n.units,"units"),n.activation=tr(void 0===e.activation?n.DEFAULT_ACTIVATION:e.activation),n.recurrentActivation=tr(void 0===e.recurrentActivation?n.DEFAULT_RECURRENT_ACTIVATION:e.recurrentActivation),n.useBias=null==e.useBias||e.useBias,n.kernelInitializer=Kt(e.kernelInitializer||n.DEFAULT_KERNEL_INITIALIZER),n.recurrentInitializer=Kt(e.recurrentInitializer||n.DEFAULT_RECURRENT_INITIALIZER),n.biasInitializer=Kt(e.biasInitializer||n.DEFAULT_BIAS_INITIALIZER),n.unitForgetBias=e.unitForgetBias,n.kernelRegularizer=sr(e.kernelRegularizer),n.recurrentRegularizer=sr(e.recurrentRegularizer),n.biasRegularizer=sr(e.biasRegularizer),n.kernelConstraint=W(e.kernelConstraint),n.recurrentConstraint=W(e.recurrentConstraint),n.biasConstraint=W(e.biasConstraint),n.dropout=ut([1,ct([0,null==e.dropout?0:e.dropout])]),n.recurrentDropout=ut([1,ct([0,null==e.recurrentDropout?0:e.recurrentDropout])]),n.implementation=e.implementation,n.stateSize=[n.units,n.units],n.dropoutMask=null,n.recurrentDropoutMask=null,n}return a(e,t),e.prototype.build=function(t){var e,n,r=(t=re(t))[t.length-1];if(this.kernel=this.addWeight("kernel",[r,4*this.units],null,this.kernelInitializer,this.kernelRegularizer,!0,this.kernelConstraint),this.recurrentKernel=this.addWeight("recurrent_kernel",[this.units,4*this.units],null,this.recurrentInitializer,this.recurrentRegularizer,!0,this.recurrentConstraint),this.useBias){if(this.unitForgetBias){var i=this.biasInitializer,o=this.units;n=new((e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return a(e,t),e.prototype.apply=function(t,e){var n=i.apply([o]),r=(new It).apply([o]),a=i.apply([2*o]);return vt(vt(n,r),a)},e}(Nt)).className="CustomInit",e)}else n=this.biasInitializer;this.bias=this.addWeight("bias",[4*this.units],null,n,this.biasRegularizer,!0,this.biasConstraint)}else this.bias=null;this.built=!0},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){var i=null!=e.training&&e.training;if(3!==(t=t).length)throw new h("LSTMCell expects 3 input Tensors (inputs, h, c), got "+t.length+".");var a=t[1],o=t[2];t=t[0],0<n.dropout&&n.dropout<1&&null==n.dropoutMask&&(n.dropoutMask=Ii(function(){return Object(r.onesLike)(t)},n.dropout,i,4)),0<n.recurrentDropout&&n.recurrentDropout<1&&null==n.recurrentDropoutMask&&(n.recurrentDropoutMask=Ii(function(){return Object(r.onesLike)(a)},n.recurrentDropout,i,4));var s,u,c,l,f=n.dropoutMask,d=n.recurrentDropoutMask;0<n.dropout&&n.dropout<1&&(t=Object(r.mul)(t,f[0]));var p=xt(t,n.kernel.read());0<n.recurrentDropout&&n.recurrentDropout<1&&(a=Object(r.mul)(a,d[0])),p=Object(r.add)(p,xt(a,n.recurrentKernel.read())),n.useBias&&(p=Et(p,n.bias.read()));var m=Object(r.split)(p,4,p.rank-1),g=m[0],v=m[1],y=m[2],b=m[3];s=n.recurrentActivation.apply(g),u=n.recurrentActivation.apply(v),c=Object(r.add)(Object(r.mul)(u,o),Object(r.mul)(s,n.activation.apply(y))),l=n.recurrentActivation.apply(b);var x=Object(r.mul)(l,n.activation.apply(c));return[x,x,c]})},e.prototype.getConfig=function(){var e={units:this.units,activation:Zn(this.activation),recurrentActivation:Zn(this.recurrentActivation),useBias:this.useBias,kernelInitializer:$t(this.kernelInitializer),recurrentInitializer:$t(this.recurrentInitializer),biasInitializer:$t(this.biasInitializer),unitForgetBias:this.unitForgetBias,kernelRegularizer:ar(this.kernelRegularizer),recurrentRegularizer:ar(this.recurrentRegularizer),biasRegularizer:ar(this.biasRegularizer),activityRegularizer:ar(this.activityRegularizer),kernelConstraint:B(this.kernelConstraint),recurrentConstraint:B(this.recurrentConstraint),biasConstraint:B(this.biasConstraint),dropout:this.dropout,recurrentDropout:this.recurrentDropout,implementation:this.implementation},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.className="LSTMCell",e}(_i);r.serialization.registerClass(Ai);var Ni=function(t){function e(e){return 0===e.implementation&&console.warn("`implementation=0` has been deprecated, and now defaults to `implementation=1`. Please update your layer call."),e.cell=new Ai(e),t.call(this,e)||this}return a(e,t),e.prototype.call=function(e,n){var i=this;return Object(r.tidy)(function(){null!=i.cell.dropoutMask&&(Object(r.dispose)(i.cell.dropoutMask),i.cell.dropoutMask=null),null!=i.cell.recurrentDropoutMask&&(Object(r.dispose)(i.cell.recurrentDropoutMask),i.cell.recurrentDropoutMask=null);var a=null==n?null:n.mask,o=null==n?null:n.training,s=null==n?null:n.initialState;return t.prototype.call.call(i,e,{mask:a,training:o,initialState:s})})},Object.defineProperty(e.prototype,"units",{get:function(){return this.cell.units},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"activation",{get:function(){return this.cell.activation},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"recurrentActivation",{get:function(){return this.cell.recurrentActivation},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"useBias",{get:function(){return this.cell.useBias},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"kernelInitializer",{get:function(){return this.cell.kernelInitializer},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"recurrentInitializer",{get:function(){return this.cell.recurrentInitializer},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"biasInitializer",{get:function(){return this.cell.biasInitializer},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"unitForgetBias",{get:function(){return this.cell.unitForgetBias},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"kernelRegularizer",{get:function(){return this.cell.kernelRegularizer},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"recurrentRegularizer",{get:function(){return this.cell.recurrentRegularizer},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"biasRegularizer",{get:function(){return this.cell.biasRegularizer},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"kernelConstraint",{get:function(){return this.cell.kernelConstraint},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"recurrentConstraint",{get:function(){return this.cell.recurrentConstraint},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"biasConstraint",{get:function(){return this.cell.biasConstraint},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"dropout",{get:function(){return this.cell.dropout},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"recurrentDropout",{get:function(){return this.cell.recurrentDropout},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"implementation",{get:function(){return this.cell.implementation},enumerable:!0,configurable:!0}),e.prototype.getConfig=function(){var e={units:this.units,activation:Zn(this.activation),recurrentActivation:Zn(this.recurrentActivation),useBias:this.useBias,kernelInitializer:$t(this.kernelInitializer),recurrentInitializer:$t(this.recurrentInitializer),biasInitializer:$t(this.biasInitializer),unitForgetBias:this.unitForgetBias,kernelRegularizer:ar(this.kernelRegularizer),recurrentRegularizer:ar(this.recurrentRegularizer),biasRegularizer:ar(this.biasRegularizer),activityRegularizer:ar(this.activityRegularizer),kernelConstraint:B(this.kernelConstraint),recurrentConstraint:B(this.recurrentConstraint),biasConstraint:B(this.biasConstraint),dropout:this.dropout,recurrentDropout:this.recurrentDropout,implementation:this.implementation},n=t.prototype.getConfig.call(this);return delete n.cell,Object.assign(e,n),e},e.fromConfig=function(t,e){return 0===e.implmentation&&(e.implementation=1),new t(e)},e.className="LSTM",e}(ki);r.serialization.registerClass(Ni);var Ti=function(t){function e(e){var n=t.call(this,e)||this;return n.cells=e.cells,n}return a(e,t),Object.defineProperty(e.prototype,"stateSize",{get:function(){for(var t=[],e=0,n=this.cells.slice().reverse();e<n.length;e++){var r=n[e];Array.isArray(r.stateSize)?t.push.apply(t,r.stateSize):t.push(r.stateSize)}return t},enumerable:!0,configurable:!0}),e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){for(var r=(t=t).slice(1),i=[],a=0,o=n.cells.slice().reverse();a<o.length;a++){var s=o[a];Array.isArray(s.stateSize)?i.push(r.splice(0,s.stateSize.length)):i.push(r.splice(0,1))}i.reverse();for(var u,c=[],l=0;l<n.cells.length;++l)s=n.cells[l],r=i[l],u=0===l?[t[0]].concat(r):[u[0]].concat(r),u=s.call(u,e),c.push(u.slice(1));r=[];for(var f=0,d=c.slice().reverse();f<d.length;f++){var h=d[f];r.push.apply(r,h)}return[u[0]].concat(r)})},e.prototype.build=function(t){var e;te(t)&&(t=t[0]),t=t,this.cells.forEach(function(n,r){tt("RNNCell_"+r,function(){n.build(t),e=Array.isArray(n.stateSize)?n.stateSize[0]:n.stateSize,t=[t[0],e]})}),this.built=!0},e.prototype.getConfig=function(){for(var e=[],n=0,r=this.cells;n<r.length;n++){var i=r[n];e.push({className:i.getClassName(),config:i.getConfig()})}var a={cells:e},o=t.prototype.getConfig.call(this);return Object.assign(a,o),a},e.fromConfig=function(t,e,n){void 0===n&&(n={});for(var r=[],i=0,a=e.cells;i<a.length;i++){var o=a[i];r.push(Ne(o,n))}return new t({cells:r})},Object.defineProperty(e.prototype,"trainableWeights",{get:function(){if(!this.trainable)return[];for(var t=[],e=0,n=this.cells;e<n.length;e++){var r=n[e];t.push.apply(t,r.trainableWeights)}return t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"nonTrainableWeights",{get:function(){for(var t=[],e=0,n=this.cells;e<n.length;e++){var r=n[e];t.push.apply(t,r.nonTrainableWeights)}if(!this.trainable){for(var i=[],a=0,o=this.cells;a<o.length;a++)r=o[a],i.push.apply(i,r.trainableWeights);return i.concat(t)}return t},enumerable:!0,configurable:!0}),e.prototype.getWeights=function(){for(var t=[],e=0,n=this.cells;e<n.length;e++){var r=n[e];t.push.apply(t,r.weights)}return se(t)},e.prototype.setWeights=function(t){for(var e=[],n=0,r=this.cells;n<r.length;n++)for(var i=r[n],a=i.weights.length,o=t.splice(a),s=0;s<i.weights.length;++s)e.push([i.weights[s],o[s]]);ue(e)},e.className="StackedRNNCells",e}(_i);function Ii(t,e,n,i){function a(){return Ot(t(),e)}if(void 0===n&&(n=null),void 0===i&&(i=1),i>1){for(var o=[],s=0;s<i;s++)o.push(St(a,t,n));return o.map(function(t){return Object(r.keep)(t.clone())})}return Object(r.keep)(St(a,t,n).clone())}r.serialization.registerClass(Ti);var Di=function(t){function e(e){var n=t.call(this,e)||this;return n.layer=e.layer,n}return a(e,t),e.prototype.build=function(t){this.built=!0},Object.defineProperty(e.prototype,"trainable",{get:function(){return null!=this.layer&&this.layer.trainable},set:function(t){null!=this.layer&&(this.layer.trainable=t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"trainableWeights",{get:function(){return this.layer.trainableWeights},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"nonTrainableWeights",{get:function(){return this.layer.nonTrainableWeights},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updates",{get:function(){return this.layer._updates},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"losses",{get:function(){return this.layer.losses},enumerable:!0,configurable:!0}),e.prototype.getWeights=function(){return this.layer.getWeights()},e.prototype.setWeights=function(t){this.layer.setWeights(t)},e.prototype.getConfig=function(){var e={layer:{className:this.layer.getClassName(),config:this.layer.getConfig()}},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.prototype.setFastWeightInitDuringBuild=function(e){t.prototype.setFastWeightInitDuringBuild.call(this,e),null!=this.layer&&this.layer.setFastWeightInitDuringBuild(e)},e.fromConfig=function(t,e,n){void 0===n&&(n={});var r=Ne(e.layer,n);delete e.layer;var i={layer:r};return Object.assign(i,e),new t(i)},e}(pe),Mi=function(t){function e(e){var n=t.call(this,e)||this;return n.supportsMasking=!0,n}return a(e,t),e.prototype.build=function(e){if((e=re(e)).length<3)throw new h("TimeDistributed layer expects an input shape >= 3D, but received input shape "+JSON.stringify(e));this.inputSpec=[{shape:e}];var n=[e[0]].concat(e.slice(2));this.layer.built||(this.layer.build(n),this.layer.built=!0),t.prototype.build.call(this,e)},e.prototype.computeOutputShape=function(t){var e=[(t=re(t))[0]].concat(t.slice(2)),n=this.layer.computeOutputShape(e),r=t[1];return[n[0],r].concat(n.slice(1))},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){return wi(function(t,r){return[ne(n.layer.call(t,e)),[]]},t=ne(t),[],!1,null,null,!1,!0)[1]})},e.className="TimeDistributed",e}(Di);r.serialization.registerClass(Mi);var Ri="concat",Fi=function(t){function e(e){var n=t.call(this,e)||this,r=e.layer.getConfig(),i={};i.className=e.layer.getClassName(),i.config=r,n.forwardLayer=Ne(i),r.goBackwards=!0!==r.goBackwards;var a={};if(a.className=e.layer.getClassName(),a.config=r,n.backwardLayer=Ne(a),n.forwardLayer.name="forward_"+n.forwardLayer.name,n.backwardLayer.name="backward_"+n.backwardLayer.name,n.mergeMode=void 0===e.mergeMode?Ri:e.mergeMode,function(t){N($,"BidirectionalMergeMode",t)}(n.mergeMode),e.weights)throw new p("weights support is not implemented for Bidirectional layer yet.");return n._stateful=e.layer.stateful,n.returnSequences=e.layer.returnSequences,n.returnState=e.layer.returnState,n.supportsMasking=!0,n._trainable=!0,n.inputSpec=e.layer.inputSpec,n.numConstants=null,n}return a(e,t),Object.defineProperty(e.prototype,"trainable",{get:function(){return this._trainable},set:function(t){this._trainable=t,null!=this.forwardLayer&&(this.forwardLayer.trainable=t),null!=this.backwardLayer&&(this.backwardLayer.trainable=t)},enumerable:!0,configurable:!0}),e.prototype.getWeights=function(){return this.forwardLayer.getWeights().concat(this.backwardLayer.getWeights())},e.prototype.setWeights=function(t){var e=t.length,n=Math.floor(e/2);this.forwardLayer.setWeights(t.slice(0,n)),this.backwardLayer.setWeights(t.slice(n))},e.prototype.computeOutputShape=function(t){var e,n,r,i=this.forwardLayer.computeOutputShape(t);return Array.isArray(i)&&Array.isArray(i[0])||(i=[i]),i=i,this.returnState?(r=i.slice(1),e=i[0]):e=i[0],e=e,"concat"===this.mergeMode?(e[e.length-1]*=2,n=[e]):n=null==this.mergeMode?[e,e.slice()]:[e],this.returnState?null==this.mergeMode?n.concat(r).concat(r.slice()):[e].concat(r).concat(r.slice()):b(n)},e.prototype.apply=function(e,n){var r=null==n?null:n.initialState,i=null==n?null:n.constants;null==n&&(n={});var a=xi(e,r,i,this.numConstants);if(e=a.inputs,r=a.initialState,i=a.constants,Array.isArray(e)&&(r=e.slice(1),e=e[0]),(null==r||0===r.length)&&null==i)return t.prototype.apply.call(this,e,n);var o=[],s=[];if(null!=r){var u=r.length;if(u%2>0)throw new h("When passing `initialState` to a Bidrectional RNN, the state should be an Array containing the states of the underlying RNNs.");n.initialState=r,o.push.apply(o,r);var c=r.map(function(t){return new ce({shape:t.shape})});this.forwardLayer.stateSpec=c.slice(0,u/2),this.backwardLayer.stateSpec=c.slice(u/2),s.push.apply(s,c)}if(null!=i)throw new p("Support for constants in Bidirectional layers is not implemented yet.");for(var l=o[0]instanceof le,f=0,d=o;f<d.length;f++)if(d[f]instanceof le!==l)throw new h("The initial state of a Bidirectional layer cannot be specified as a mix of symbolic and non-symbolic tensors");if(l){var m=[e].concat(o),g=this.inputSpec.concat(s),v=this.inputSpec;this.inputSpec=g;var y=t.prototype.apply.call(this,m,n);return this.inputSpec=v,y}return t.prototype.apply.call(this,e,n)},e.prototype.call=function(t,e){var n=this;return Object(r.tidy)(function(){var i,a,o,s,u=e.initialState;if(null==u)i=n.forwardLayer.call(t,e),a=n.backwardLayer.call(t,e);else{var c=u.slice(0,u.length/2),l=u.slice(u.length/2);i=n.forwardLayer.call(t,Object.assign(e,{initialState:c})),a=n.backwardLayer.call(t,Object.assign(e,{initialState:l}))}return n.returnState&&(Array.isArray(i)&&(o=i.slice(1).concat(a.slice(1))),i=i[0],a=a[0]),n.returnSequences&&(a=Object(r.reverse)(a,1)),"concat"===n.mergeMode?s=gt([i,a]):"sum"===n.mergeMode?s=Object(r.add)(i,a):"ave"===n.mergeMode?s=Object(r.mul)(.5,Object(r.add)(i,a)):"mul"===n.mergeMode?s=Object(r.mul)(i,a):null==n.mergeMode&&(s=[i,a]),n.returnState?null==n.mergeMode?s.concat(o):[s].concat(o):s})},e.prototype.resetStates=function(t){this.forwardLayer.resetStates(),this.backwardLayer.resetStates()},e.prototype.build=function(t){var e=this;tt(this.forwardLayer.name,function(){e.forwardLayer.build(t)}),tt(this.backwardLayer.name,function(){e.backwardLayer.build(t)}),this.built=!0},e.prototype.computeMask=function(t,e){var n;if(Array.isArray(e)&&(e=e[0]),n=this.returnSequences?null==this.mergeMode?[e,e]:e:null==this.mergeMode?[null,null]:null,this.returnState){var r=this.forwardLayer.states.map(function(t){return null});return Array.isArray(n)?n.concat(r).concat(r):[n].concat(r).concat(r)}return n},Object.defineProperty(e.prototype,"trainableWeights",{get:function(){return this.forwardLayer.trainableWeights.concat(this.backwardLayer.trainableWeights)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"nonTrainableWeights",{get:function(){return this.forwardLayer.nonTrainableWeights.concat(this.backwardLayer.nonTrainableWeights)},enumerable:!0,configurable:!0}),e.prototype.setFastWeightInitDuringBuild=function(e){t.prototype.setFastWeightInitDuringBuild.call(this,e),null!=this.forwardLayer&&this.forwardLayer.setFastWeightInitDuringBuild(e),null!=this.backwardLayer&&this.backwardLayer.setFastWeightInitDuringBuild(e)},e.prototype.getConfig=function(){var e={mergeMode:this.mergeMode},n=t.prototype.getConfig.call(this);return Object.assign(e,n),e},e.fromConfig=function(t,e){var n=Ne(e.layer);if(delete e.layer,null!=e.numConstants)throw new p("Deserialization of a Bidirectional layer with numConstants present is not supported yet.");var r=e;return r.layer=n,new t(r)},e.className="Bidirectional",e}(Di);function ji(t){return new si(t)}function Pi(t){return new li(t)}function Li(t){return new hi(t)}function zi(t){return new gi(t)}function Bi(t){return new bi(t)}function Ui(t){return new oi(t)}function Wi(t){return new ci(t)}r.serialization.registerClass(Fi);var Vi=zi,qi=Bi,Hi=Ui,Gi=Wi;var $i=Object.freeze({inputLayer:function(t){return new ge(t)},elu:function(t){return new fr(t)},reLU:function(t){return new ur(t)},leakyReLU:function(t){return new cr(t)},prelu:function(t){return new lr(t)},softmax:function(t){return new hr(t)},thresholdedReLU:function(t){return new dr(t)},conv1d:function(t){return new Sr(t)},conv2d:function(t){return new kr(t)},conv2dTranspose:function(t){return new Er(t)},conv3d:function(t){return new _r(t)},separableConv2d:function(t){return new Or(t)},cropping2D:function(t){return new Cr(t)},upSampling2d:function(t){return new Ar(t)},depthwiseConv2d:function(t){return new Nr(t)},activation:function(t){return new Rr(t)},dense:function(t){return new Dr(t)},dropout:function(t){return new Tr(t)},spatialDropout1d:function(t){return new Ir(t)},flatten:function(t){return new Mr(t)},repeatVector:function(t){return new Fr(t)},reshape:function(t){return new jr(t)},permute:function(t){return new Pr(t)},embedding:function(t){return new zr(t)},add:function(t){return new Ur(t)},average:function(t){return new Vr(t)},concatenate:function(t){return new Gr(t)},maximum:function(t){return new qr(t)},minimum:function(t){return new Hr(t)},multiply:function(t){return new Wr(t)},dot:function(t){return new Kr(t)},batchNormalization:function(t){return new ti(t)},layerNormalization:function(t){return new ei(t)},zeroPadding2d:function(t){return new ni(t)},averagePooling1d:ji,avgPool1d:function(t){return ji(t)},avgPooling1d:function(t){return ji(t)},averagePooling2d:Pi,avgPool2d:function(t){return Pi(t)},avgPooling2d:function(t){return Pi(t)},averagePooling3d:Li,avgPool3d:function(t){return Li(t)},avgPooling3d:function(t){return Li(t)},globalAveragePooling1d:function(t){return new mi(t)},globalAveragePooling2d:function(t){return new yi(t)},globalMaxPooling1d:zi,globalMaxPooling2d:Bi,maxPooling1d:Ui,maxPooling2d:Wi,maxPooling3d:function(t){return new di(t)},gru:function(t){return new Ci(t)},gruCell:function(t){return new Si(t)},lstm:function(t){return new Ni(t)},lstmCell:function(t){return new Ai(t)},simpleRNN:function(t){return new Oi(t)},simpleRNNCell:function(t){return new Ei(t)},rnn:function(t){return new ki(t)},stackedRNNCells:function(t){return new Ti(t)},bidirectional:function(t){return new Fi(t)},timeDistributed:function(t){return new Mi(t)},globalMaxPool1d:Vi,globalMaxPool2d:qi,maxPool1d:Hi,maxPool2d:Gi,Layer:pe,RNN:ki,RNNCell:_i,input:Pn,gaussianNoise:function(t){return new Xr(t)},gaussianDropout:function(t){return new Yr(t)},alphaDropout:function(t){return new Jr(t)},masking:function(t){return new Lr(t)}});var Ki=Object.freeze({binaryAccuracy:function(t,e){return Be(t,e)},binaryCrossentropy:function(t,e){return He(t,e)},sparseCategoricalAccuracy:function(t,e){return Ge(t,e)},categoricalAccuracy:function(t,e){return Ue(t,e)},categoricalCrossentropy:function(t,e){return $e(t,e)},precision:function(t,e){return Ve(t,e)},recall:function(t,e){return qe(t,e)},cosineProximity:function(t,e){return Pe(t,e)},meanAbsoluteError:function(t,e){return De(t,e)},meanAbsolutePercentageError:function(t,e){return Me(t,e)},MAPE:function(t,e){return Me(t,e)},mape:function(t,e){return Me(t,e)},meanSquaredError:function(t,e){return Ie(t,e)},MSE:function(t,e){return Ie(t,e)},mse:function(t,e){return Ie(t,e)}}),Xi=Object.freeze({modelFromJSON:function(t,e){return u(this,void 0,void 0,function(){var n,i,a,o,s,u,l,f;return c(this,function(c){switch(c.label){case 0:return"modelTopology"in t||(t={modelTopology:t}),null!=(n=(t=t).modelTopology).model_config&&(n=n.model_config),i=an(n),a=Ne(i,e),null==t.weightsManifest?[3,2]:[4,r.io.loadWeights(t.weightsManifest,t.pathPrefix,a.weights.map(function(t){return t.originalName}))];case 1:for(o=c.sent(),s={},u=0,l=a.weights;u<l.length;u++)f=l[u],s[f.originalName]=o[f.originalName];a.loadWeights(s),Object(r.dispose)(o),c.label=2;case 2:return[2,a]}})})}});var Yi=Object.freeze({l1l2:function(t){return new rr(t)},l1:function(t){return function(t){return er(t),new rr({l1:null!=t?t.l1:null,l2:0})}(t)},l2:function(t){return function(t){return er(t),new rr({l2:null!=t?t.l2:null,l1:0})}(t)}}),Ji=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.model=null,e}return a(e,t),e.prototype.setModel=function(t){if(!(t instanceof In))throw new Error("model must be a LayersModel, not some other Container");this.model=t},e}(we);function Zi(t,e){return t<e}function Qi(t,e){return t>e}var ta=function(t){function e(e){var n=t.call(this)||this;if(null==e&&(e={}),e.restoreBestWeights)throw new p("restoreBestWeights = True is not implemented in EarlyStopping yet.");return n.monitor=e.monitor||"val_loss",n.minDelta=Math.abs(e.minDelta||0),n.patience=e.patience||0,n.verbose=e.verbose||0,n.mode=e.mode||"auto",n.baseline=e.baseline,-1===["auto","min","max"].indexOf(n.mode)&&(console.warn("EarlyStopping mode '"+n.mode+"' is invalid. Falling back to mode 'auto'."),n.mode="auto"),"min"===n.mode?n.monitorFunc=Zi:"max"===n.mode?n.monitorFunc=Qi:-1!==n.monitor.indexOf("acc")?n.monitorFunc=Qi:n.monitorFunc=Zi,n.monitorFunc===Zi&&(n.minDelta*=-1),n}return a(e,t),e.prototype.onTrainBegin=function(t){return u(this,void 0,void 0,function(){return c(this,function(t){return this.wait=0,this.stoppedEpoch=0,null!=this.baseline?this.best=this.baseline:this.best=this.monitorFunc===Zi?1/0:-1/0,[2]})})},e.prototype.onEpochEnd=function(t,e){return u(this,void 0,void 0,function(){var n;return c(this,function(r){switch(r.label){case 0:return[4,ye(e)];case 1:return r.sent(),null==(n=this.getMonitorValue(e))?[2]:(this.monitorFunc(n-this.minDelta,this.best)?(this.best=n,this.wait=0):(this.wait++,this.wait>=this.patience&&(this.stoppedEpoch=t,this.model.stopTraining=!0)),[2])}})})},e.prototype.onTrainEnd=function(t){return u(this,void 0,void 0,function(){return c(this,function(t){return this.stoppedEpoch>0&&this.verbose&&console.log("Epoch "+this.stoppedEpoch+": early stopping."),[2]})})},e.prototype.getMonitorValue=function(t){null==t&&(t={});var e=t[this.monitor];return null==e&&console.warn("Metric for EarlyStopping "+this.monitor+" is not available. Available metrics are: "+Object.keys(t)),e},e}(Ji);var ea={earlyStopping:function(t){return new ta(t)}},na=n(20),ra=n(137);n.d(e,"version",function(){return ia}),n.d(e,"AdadeltaOptimizer",function(){return r.AdadeltaOptimizer}),n.d(e,"AdagradOptimizer",function(){return r.AdagradOptimizer}),n.d(e,"AdamOptimizer",function(){return r.AdamOptimizer}),n.d(e,"AdamaxOptimizer",function(){return r.AdamaxOptimizer}),n.d(e,"Add",function(){return r.Add}),n.d(e,"AddN",function(){return r.AddN}),n.d(e,"BroadcastTo",function(){return r.BroadcastTo}),n.d(e,"DataStorage",function(){return r.DataStorage}),n.d(e,"Div",function(){return r.Div}),n.d(e,"ENV",function(){return r.ENV}),n.d(e,"Environment",function(){return r.Environment}),n.d(e,"FromPixels",function(){return r.FromPixels}),n.d(e,"FusedBatchNorm",function(){return r.FusedBatchNorm}),n.d(e,"Identity",function(){return r.Identity}),n.d(e,"KernelBackend",function(){return r.KernelBackend}),n.d(e,"MaxPoolWithArgmax",function(){return r.MaxPoolWithArgmax}),n.d(e,"MomentumOptimizer",function(){return r.MomentumOptimizer}),n.d(e,"NonMaxSuppressionV5",function(){return r.NonMaxSuppressionV5}),n.d(e,"OneHot",function(){return r.OneHot}),n.d(e,"Optimizer",function(){return r.Optimizer}),n.d(e,"PadV2",function(){return r.PadV2}),n.d(e,"RMSPropOptimizer",function(){return r.RMSPropOptimizer}),n.d(e,"Rank",function(){return r.Rank}),n.d(e,"Reduction",function(){return r.Reduction}),n.d(e,"SGDOptimizer",function(){return r.SGDOptimizer}),n.d(e,"Square",function(){return r.Square}),n.d(e,"SquaredDifference",function(){return r.SquaredDifference}),n.d(e,"Tensor",function(){return r.Tensor}),n.d(e,"TensorBuffer",function(){return r.TensorBuffer}),n.d(e,"Tile",function(){return r.Tile}),n.d(e,"Transpose",function(){return r.Transpose}),n.d(e,"Variable",function(){return r.Variable}),n.d(e,"abs",function(){return r.abs}),n.d(e,"acos",function(){return r.acos}),n.d(e,"acosh",function(){return r.acosh}),n.d(e,"add",function(){return r.add}),n.d(e,"addN",function(){return r.addN}),n.d(e,"addStrict",function(){return r.addStrict}),n.d(e,"all",function(){return r.all}),n.d(e,"any",function(){return r.any}),n.d(e,"argMax",function(){return r.argMax}),n.d(e,"argMin",function(){return r.argMin}),n.d(e,"asin",function(){return r.asin}),n.d(e,"asinh",function(){return r.asinh}),n.d(e,"atan",function(){return r.atan}),n.d(e,"atan2",function(){return r.atan2}),n.d(e,"atanh",function(){return r.atanh}),n.d(e,"avgPool",function(){return r.avgPool}),n.d(e,"avgPool3d",function(){return r.avgPool3d}),n.d(e,"backend",function(){return r.backend}),n.d(e,"backend_util",function(){return r.backend_util}),n.d(e,"basicLSTMCell",function(){return r.basicLSTMCell}),n.d(e,"batchNorm",function(){return r.batchNorm}),n.d(e,"batchNorm2d",function(){return r.batchNorm2d}),n.d(e,"batchNorm3d",function(){return r.batchNorm3d}),n.d(e,"batchNorm4d",function(){return r.batchNorm4d}),n.d(e,"batchNormalization",function(){return r.batchNormalization}),n.d(e,"batchNormalization2d",function(){return r.batchNormalization2d}),n.d(e,"batchNormalization3d",function(){return r.batchNormalization3d}),n.d(e,"batchNormalization4d",function(){return r.batchNormalization4d}),n.d(e,"batchToSpaceND",function(){return r.batchToSpaceND}),n.d(e,"booleanMaskAsync",function(){return r.booleanMaskAsync}),n.d(e,"broadcastTo",function(){return r.broadcastTo}),n.d(e,"browser",function(){return r.browser}),n.d(e,"buffer",function(){return r.buffer}),n.d(e,"cast",function(){return r.cast}),n.d(e,"ceil",function(){return r.ceil}),n.d(e,"clipByValue",function(){return r.clipByValue}),n.d(e,"clone",function(){return r.clone}),n.d(e,"complex",function(){return r.complex}),n.d(e,"concat",function(){return r.concat}),n.d(e,"concat1d",function(){return r.concat1d}),n.d(e,"concat2d",function(){return r.concat2d}),n.d(e,"concat3d",function(){return r.concat3d}),n.d(e,"concat4d",function(){return r.concat4d}),n.d(e,"conv1d",function(){return r.conv1d}),n.d(e,"conv2d",function(){return r.conv2d}),n.d(e,"conv2dTranspose",function(){return r.conv2dTranspose}),n.d(e,"conv3d",function(){return r.conv3d}),n.d(e,"conv3dTranspose",function(){return r.conv3dTranspose}),n.d(e,"cos",function(){return r.cos}),n.d(e,"cosh",function(){return r.cosh}),n.d(e,"cumsum",function(){return r.cumsum}),n.d(e,"customGrad",function(){return r.customGrad}),n.d(e,"deprecationWarn",function(){return r.deprecationWarn}),n.d(e,"depthToSpace",function(){return r.depthToSpace}),n.d(e,"depthwiseConv2d",function(){return r.depthwiseConv2d}),n.d(e,"diag",function(){return r.diag}),n.d(e,"disableDeprecationWarnings",function(){return r.disableDeprecationWarnings}),n.d(e,"dispose",function(){return r.dispose}),n.d(e,"disposeVariables",function(){return r.disposeVariables}),n.d(e,"div",function(){return r.div}),n.d(e,"divNoNan",function(){return r.divNoNan}),n.d(e,"divStrict",function(){return r.divStrict}),n.d(e,"dot",function(){return r.dot}),n.d(e,"dropout",function(){return r.dropout}),n.d(e,"elu",function(){return r.elu}),n.d(e,"enableDebugMode",function(){return r.enableDebugMode}),n.d(e,"enableProdMode",function(){return r.enableProdMode}),n.d(e,"engine",function(){return r.engine}),n.d(e,"env",function(){return r.env}),n.d(e,"equal",function(){return r.equal}),n.d(e,"equalStrict",function(){return r.equalStrict}),n.d(e,"erf",function(){return r.erf}),n.d(e,"exp",function(){return r.exp}),n.d(e,"expandDims",function(){return r.expandDims}),n.d(e,"expm1",function(){return r.expm1}),n.d(e,"eye",function(){return r.eye}),n.d(e,"fft",function(){return r.fft}),n.d(e,"fill",function(){return r.fill}),n.d(e,"findBackend",function(){return r.findBackend}),n.d(e,"findBackendFactory",function(){return r.findBackendFactory}),n.d(e,"floor",function(){return r.floor}),n.d(e,"floorDiv",function(){return r.floorDiv}),n.d(e,"frame",function(){return r.frame}),n.d(e,"fused",function(){return r.fused}),n.d(e,"gather",function(){return r.gather}),n.d(e,"gatherND",function(){return r.gatherND}),n.d(e,"gather_util",function(){return r.gather_util}),n.d(e,"getBackend",function(){return r.getBackend}),n.d(e,"getGradient",function(){return r.getGradient}),n.d(e,"getKernel",function(){return r.getKernel}),n.d(e,"getKernelsForBackend",function(){return r.getKernelsForBackend}),n.d(e,"grad",function(){return r.grad}),n.d(e,"grads",function(){return r.grads}),n.d(e,"greater",function(){return r.greater}),n.d(e,"greaterEqual",function(){return r.greaterEqual}),n.d(e,"greaterEqualStrict",function(){return r.greaterEqualStrict}),n.d(e,"greaterStrict",function(){return r.greaterStrict}),n.d(e,"hammingWindow",function(){return r.hammingWindow}),n.d(e,"hannWindow",function(){return r.hannWindow}),n.d(e,"ifft",function(){return r.ifft}),n.d(e,"imag",function(){return r.imag}),n.d(e,"image",function(){return r.image}),n.d(e,"inTopKAsync",function(){return r.inTopKAsync}),n.d(e,"io",function(){return r.io}),n.d(e,"irfft",function(){return r.irfft}),n.d(e,"isFinite",function(){return r.isFinite}),n.d(e,"isInf",function(){return r.isInf}),n.d(e,"isNaN",function(){return r.isNaN}),n.d(e,"keep",function(){return r.keep}),n.d(e,"leakyRelu",function(){return r.leakyRelu}),n.d(e,"less",function(){return r.less}),n.d(e,"lessEqual",function(){return r.lessEqual}),n.d(e,"lessEqualStrict",function(){return r.lessEqualStrict}),n.d(e,"lessStrict",function(){return r.lessStrict}),n.d(e,"linalg",function(){return r.linalg}),n.d(e,"linspace",function(){return r.linspace}),n.d(e,"localResponseNormalization",function(){return r.localResponseNormalization}),n.d(e,"log",function(){return r.log}),n.d(e,"log1p",function(){return r.log1p}),n.d(e,"logSigmoid",function(){return r.logSigmoid}),n.d(e,"logSoftmax",function(){return r.logSoftmax}),n.d(e,"logSumExp",function(){return r.logSumExp}),n.d(e,"logicalAnd",function(){return r.logicalAnd}),n.d(e,"logicalNot",function(){return r.logicalNot}),n.d(e,"logicalOr",function(){return r.logicalOr}),n.d(e,"logicalXor",function(){return r.logicalXor}),n.d(e,"losses",function(){return r.losses}),n.d(e,"matMul",function(){return r.matMul}),n.d(e,"math",function(){return r.math}),n.d(e,"max",function(){return r.max}),n.d(e,"maxPool",function(){return r.maxPool}),n.d(e,"maxPool3d",function(){return r.maxPool3d}),n.d(e,"maxPoolWithArgmax",function(){return r.maxPoolWithArgmax}),n.d(e,"maximum",function(){return r.maximum}),n.d(e,"maximumStrict",function(){return r.maximumStrict}),n.d(e,"mean",function(){return r.mean}),n.d(e,"memory",function(){return r.memory}),n.d(e,"min",function(){return r.min}),n.d(e,"minimum",function(){return r.minimum}),n.d(e,"minimumStrict",function(){return r.minimumStrict}),n.d(e,"mod",function(){return r.mod}),n.d(e,"modStrict",function(){return r.modStrict}),n.d(e,"moments",function(){return r.moments}),n.d(e,"movingAverage",function(){return r.movingAverage}),n.d(e,"mul",function(){return r.mul}),n.d(e,"mulStrict",function(){return r.mulStrict}),n.d(e,"multiRNNCell",function(){return r.multiRNNCell}),n.d(e,"multinomial",function(){return r.multinomial}),n.d(e,"neg",function(){return r.neg}),n.d(e,"nextFrame",function(){return r.nextFrame}),n.d(e,"norm",function(){return r.norm}),n.d(e,"notEqual",function(){return r.notEqual}),n.d(e,"notEqualStrict",function(){return r.notEqualStrict}),n.d(e,"oneHot",function(){return r.oneHot}),n.d(e,"ones",function(){return r.ones}),n.d(e,"onesLike",function(){return r.onesLike}),n.d(e,"op",function(){return r.op}),n.d(e,"outerProduct",function(){return r.outerProduct}),n.d(e,"pad",function(){return r.pad}),n.d(e,"pad1d",function(){return r.pad1d}),n.d(e,"pad2d",function(){return r.pad2d}),n.d(e,"pad3d",function(){return r.pad3d}),n.d(e,"pad4d",function(){return r.pad4d}),n.d(e,"pool",function(){return r.pool}),n.d(e,"pow",function(){return r.pow}),n.d(e,"powStrict",function(){return r.powStrict}),n.d(e,"prelu",function(){return r.prelu}),n.d(e,"print",function(){return r.print}),n.d(e,"prod",function(){return r.prod}),n.d(e,"profile",function(){return r.profile}),n.d(e,"rand",function(){return r.rand}),n.d(e,"randomGamma",function(){return r.randomGamma}),n.d(e,"randomNormal",function(){return r.randomNormal}),n.d(e,"randomUniform",function(){return r.randomUniform}),n.d(e,"range",function(){return r.range}),n.d(e,"ready",function(){return r.ready}),n.d(e,"real",function(){return r.real}),n.d(e,"reciprocal",function(){return r.reciprocal}),n.d(e,"registerBackend",function(){return r.registerBackend}),n.d(e,"registerGradient",function(){return r.registerGradient}),n.d(e,"registerKernel",function(){return r.registerKernel}),n.d(e,"relu",function(){return r.relu}),n.d(e,"relu6",function(){return r.relu6}),n.d(e,"removeBackend",function(){return r.removeBackend}),n.d(e,"reshape",function(){return r.reshape}),n.d(e,"reverse",function(){return r.reverse}),n.d(e,"reverse1d",function(){return r.reverse1d}),n.d(e,"reverse2d",function(){return r.reverse2d}),n.d(e,"reverse3d",function(){return r.reverse3d}),n.d(e,"reverse4d",function(){return r.reverse4d}),n.d(e,"rfft",function(){return r.rfft}),n.d(e,"round",function(){return r.round}),n.d(e,"rsqrt",function(){return r.rsqrt}),n.d(e,"scalar",function(){return r.scalar}),n.d(e,"scatterND",function(){return r.scatterND}),n.d(e,"scatter_util",function(){return r.scatter_util}),n.d(e,"selu",function(){return r.selu}),n.d(e,"separableConv2d",function(){return r.separableConv2d}),n.d(e,"serialization",function(){return r.serialization}),n.d(e,"setBackend",function(){return r.setBackend}),n.d(e,"setPlatform",function(){return r.setPlatform}),n.d(e,"setdiff1dAsync",function(){return r.setdiff1dAsync}),n.d(e,"sigmoid",function(){return r.sigmoid}),n.d(e,"sign",function(){return r.sign}),n.d(e,"signal",function(){return r.signal}),n.d(e,"sin",function(){return r.sin}),n.d(e,"sinh",function(){return r.sinh}),n.d(e,"slice",function(){return r.slice}),n.d(e,"slice1d",function(){return r.slice1d}),n.d(e,"slice2d",function(){return r.slice2d}),n.d(e,"slice3d",function(){return r.slice3d}),n.d(e,"slice4d",function(){return r.slice4d}),n.d(e,"slice_util",function(){return r.slice_util}),n.d(e,"softmax",function(){return r.softmax}),n.d(e,"softplus",function(){return r.softplus}),n.d(e,"spaceToBatchND",function(){return r.spaceToBatchND}),n.d(e,"sparseToDense",function(){return r.sparseToDense}),n.d(e,"spectral",function(){return r.spectral}),n.d(e,"split",function(){return r.split}),n.d(e,"sqrt",function(){return r.sqrt}),n.d(e,"square",function(){return r.square}),n.d(e,"squaredDifference",function(){return r.squaredDifference}),n.d(e,"squaredDifferenceStrict",function(){return r.squaredDifferenceStrict}),n.d(e,"squeeze",function(){return r.squeeze}),n.d(e,"stack",function(){return r.stack}),n.d(e,"step",function(){return r.step}),n.d(e,"stft",function(){return r.stft}),n.d(e,"stridedSlice",function(){return r.stridedSlice}),n.d(e,"sub",function(){return r.sub}),n.d(e,"subStrict",function(){return r.subStrict}),n.d(e,"sum",function(){return r.sum}),n.d(e,"sumOutType",function(){return r.sumOutType}),n.d(e,"tan",function(){return r.tan}),n.d(e,"tanh",function(){return r.tanh}),n.d(e,"tensor",function(){return r.tensor}),n.d(e,"tensor1d",function(){return r.tensor1d}),n.d(e,"tensor2d",function(){return r.tensor2d}),n.d(e,"tensor3d",function(){return r.tensor3d}),n.d(e,"tensor4d",function(){return r.tensor4d}),n.d(e,"tensor5d",function(){return r.tensor5d}),n.d(e,"tensor6d",function(){return r.tensor6d}),n.d(e,"tensor_util",function(){return r.tensor_util}),n.d(e,"test_util",function(){return r.test_util}),n.d(e,"tidy",function(){return r.tidy}),n.d(e,"tile",function(){return r.tile}),n.d(e,"time",function(){return r.time}),n.d(e,"topk",function(){return r.topk}),n.d(e,"train",function(){return r.train}),n.d(e,"transpose",function(){return r.transpose}),n.d(e,"truncatedNormal",function(){return r.truncatedNormal}),n.d(e,"unregisterGradient",function(){return r.unregisterGradient}),n.d(e,"unregisterKernel",function(){return r.unregisterKernel}),n.d(e,"unsortedSegmentSum",function(){return r.unsortedSegmentSum}),n.d(e,"unstack",function(){return r.unstack}),n.d(e,"util",function(){return r.util}),n.d(e,"valueAndGrad",function(){return r.valueAndGrad}),n.d(e,"valueAndGrads",function(){return r.valueAndGrads}),n.d(e,"variable",function(){return r.variable}),n.d(e,"variableGrads",function(){return r.variableGrads}),n.d(e,"version_core",function(){return r.version_core}),n.d(e,"webgl",function(){return r.webgl}),n.d(e,"where",function(){return r.where}),n.d(e,"whereAsync",function(){return r.whereAsync}),n.d(e,"zeros",function(){return r.zeros}),n.d(e,"zerosLike",function(){return r.zerosLike}),n.d(e,"constraints",function(){return V}),n.d(e,"initializers",function(){return Xt}),n.d(e,"layers",function(){return $i}),n.d(e,"metrics",function(){return Ki}),n.d(e,"models",function(){return Xi}),n.d(e,"regularizers",function(){return Yi}),n.d(e,"CallbackList",function(){return ke}),n.d(e,"CustomCallback",function(){return Oe}),n.d(e,"History",function(){return Ee}),n.d(e,"Callback",function(){return Ji}),n.d(e,"callbacks",function(){return ea}),n.d(e,"EarlyStopping",function(){return ta}),n.d(e,"InputSpec",function(){return ce}),n.d(e,"SymbolicTensor",function(){return le}),n.d(e,"LayersModel",function(){return In}),n.d(e,"input",function(){return Pn}),n.d(e,"loadLayersModel",function(){return jn}),n.d(e,"model",function(){return Rn}),n.d(e,"registerCallbackConstructor",function(){return Ln}),n.d(e,"sequential",function(){return Fn}),n.d(e,"RNN",function(){return ki}),n.d(e,"Sequential",function(){return Mn}),n.d(e,"LayerVariable",function(){return oe}),n.d(e,"version_layers",function(){return"1.7.2"}),n.d(e,"GraphModel",function(){return na.a}),n.d(e,"loadGraphModel",function(){return na.c}),n.d(e,"deregisterOp",function(){return na.b}),n.d(e,"registerOp",function(){return na.d}),n.d(e,"version_converter",function(){return na.e}),n.d(e,"data",function(){return ra});var ia={"tfjs-core":r.version_core,"tfjs-data":ra.version_data,"tfjs-layers":"1.7.2","tfjs-converter":na.e,tfjs:"1.7.2"}},function(t,e,n){var r=n(11),i=n(44),a=n(31),o=n(30),s=n(43),u=function(t,e,n){var c,l,f,d,h=t&u.F,p=t&u.G,m=t&u.S,g=t&u.P,v=t&u.B,y=p?r:m?r[e]||(r[e]={}):(r[e]||{}).prototype,b=p?i:i[e]||(i[e]={}),x=b.prototype||(b.prototype={});for(c in p&&(n=e),n)f=((l=!h&&y&&void 0!==y[c])?y:n)[c],d=v&&l?s(f,r):g&&"function"==typeof f?s(Function.call,f):f,y&&o(y,c,f,t&u.U),b[c]!=f&&a(b,c,d),g&&x[c]!=f&&(x[c]=f)};r.core=i,u.F=1,u.G=2,u.S=4,u.P=8,u.B=16,u.W=32,u.U=64,u.R=128,t.exports=u},function(t,e,n){var r=n(13);t.exports=function(t){if(!r(t))throw TypeError(t+" is not an object!");return t}},function(t,e,n){"use strict";e.__esModule=!0,e.default=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}},function(t,e,n){"use strict";e.__esModule=!0;var r=function(t){return t&&t.__esModule?t:{default:t}}(n(24));e.default=function(t){return function(){var e=t.apply(this,arguments);return new r.default(function(t,n){return function i(a,o){try{var s=e[a](o),u=s.value}catch(t){return void n(t)}if(!s.done)return r.default.resolve(u).then(function(t){i("next",t)},function(t){i("throw",t)});t(u)}("next")})}}},function(t,e,n){t.exports=n(427)},function(t,e,n){"use strict";e.__esModule=!0;var r=function(t){return t&&t.__esModule?t:{default:t}}(n(222));e.default=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),(0,r.default)(t,i.key,i)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}()},function(t,e){var n=t.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=n)},function(t,e){t.exports=function(t){try{return!!t()}catch(t){return!0}}},function(t,e){t.exports=function(t){return"object"==typeof t?null!==t:"function"==typeof t}},function(t,e,n){"use strict";e.__esModule=!0;var r=o(n(410)),i=o(n(408)),a="function"==typeof i.default&&"symbol"==typeof r.default?function(t){return typeof t}:function(t){return t&&"function"==typeof i.default&&t.constructor===i.default&&t!==i.default.prototype?"symbol":typeof t};function o(t){return t&&t.__esModule?t:{default:t}}e.default="function"==typeof i.default&&"symbol"===a(r.default)?function(t){return void 0===t?"undefined":a(t)}:function(t){return t&&"function"==typeof i.default&&t.constructor===i.default&&t!==i.default.prototype?"symbol":void 0===t?"undefined":a(t)}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){e&&t.then(function(t){return e(void 0,t),t}).catch(function(t){return e(t),t});return t}},function(t,e,n){var r=n(114)("wks"),i=n(79),a=n(11).Symbol,o="function"==typeof a;(t.exports=function(t){return r[t]||(r[t]=o&&a[t]||(o?a:i)("Symbol."+t))}).store=r},function(t,e,n){var r=n(41),i=Math.min;t.exports=function(t){return t>0?i(r(t),9007199254740991):0}},function(t,e){var n=t.exports={version:"2.6.11"};"number"==typeof __e&&(__e=n)},function(t,e,n){t.exports=!n(12)(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},function(t,e,n){"use strict";(function(t){n.d(e,"a",function(){return _t}),n.d(e,"c",function(){return Et}),n.d(e,"b",function(){return d}),n.d(e,"d",function(){return l}),n.d(e,"e",function(){return Ot});var r,i,a=n(0),o=function(){return(o=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};
  65. /**
  66. * @license
  67. * Copyright 2020 Google LLC. All Rights Reserved.
  68. * Licensed under the Apache License, Version 2.0 (the "License");
  69. * you may not use this file except in compliance with the License.
  70. * You may obtain a copy of the License at
  71. *
  72. * http://www.apache.org/licenses/LICENSE-2.0
  73. *
  74. * Unless required by applicable law or agreed to in writing, software
  75. * distributed under the License is distributed on an "AS IS" BASIS,
  76. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  77. * See the License for the specific language governing permissions and
  78. * limitations under the License.
  79. * =============================================================================
  80. */function s(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})}function u(t,e){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=(i=o.trys).length>0&&i[i.length-1])&&(6===a[0]||2===a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}!function(t){t[t.DT_INVALID=0]="DT_INVALID",t[t.DT_FLOAT=1]="DT_FLOAT",t[t.DT_DOUBLE=2]="DT_DOUBLE",t[t.DT_INT32=3]="DT_INT32",t[t.DT_UINT8=4]="DT_UINT8",t[t.DT_INT16=5]="DT_INT16",t[t.DT_INT8=6]="DT_INT8",t[t.DT_STRING=7]="DT_STRING",t[t.DT_COMPLEX64=8]="DT_COMPLEX64",t[t.DT_INT64=9]="DT_INT64",t[t.DT_BOOL=10]="DT_BOOL",t[t.DT_QINT8=11]="DT_QINT8",t[t.DT_QUINT8=12]="DT_QUINT8",t[t.DT_QINT32=13]="DT_QINT32",t[t.DT_BFLOAT16=14]="DT_BFLOAT16",t[t.DT_FLOAT_REF=101]="DT_FLOAT_REF",t[t.DT_DOUBLE_REF=102]="DT_DOUBLE_REF",t[t.DT_INT32_REF=103]="DT_INT32_REF",t[t.DT_UINT8_REF=104]="DT_UINT8_REF",t[t.DT_INT16_REF=105]="DT_INT16_REF",t[t.DT_INT8_REF=106]="DT_INT8_REF",t[t.DT_STRING_REF=107]="DT_STRING_REF",t[t.DT_COMPLEX64_REF=108]="DT_COMPLEX64_REF",t[t.DT_INT64_REF=109]="DT_INT64_REF",t[t.DT_BOOL_REF=110]="DT_BOOL_REF",t[t.DT_QINT8_REF=111]="DT_QINT8_REF",t[t.DT_QUINT8_REF=112]="DT_QUINT8_REF",t[t.DT_QINT32_REF=113]="DT_QINT32_REF",t[t.DT_BFLOAT16_REF=114]="DT_BFLOAT16_REF"}(r||(r={})),function(t){!function(t){t[t.LEGACY=0]="LEGACY",t[t.V1=1]="V1",t[t.V2=2]="V2"}(t.CheckpointFormatVersion||(t.CheckpointFormatVersion={}))}(i||(i={}));var c={};function l(t,e){var n={tfOpName:t,category:"custom",inputs:[],attrs:[],customExecutor:e};c[t]=n}function f(t){return c[t]}function d(t){delete c[t]}function h(t,e,n,r){var i=e.inputParams[t];if(i&&void 0!==i.inputIndexStart){var a=i.inputIndexStart,o=0===i.inputIndexEnd?void 0:void 0===i.inputIndexEnd?a+1:i.inputIndexEnd;if("tensor"===i.type)return p(e.inputNames[i.inputIndexStart],n,r);if("tensors"===i.type)return e.inputNames.slice(a,o).map(function(t){return p(t,n,r)});var s=Array.prototype.slice.call(p(e.inputNames.slice(a)[0],n,r).dataSync());return"number"===i.type?s[0]:s}var u=e.attrParams[t];return u&&u.value}function p(t,e,n){var r=v(t),i=r[0],a=r[1],o=n.currentContextIds.find(function(t){return!!e[g(i,t)]});return void 0!==o?e[g(i,o)][a]:void 0}function m(t,e){var n=v(t),r=n[0],i=n[1];return[g(r,e&&e.currentContextId),i]}function g(t,e){return e?t+"-"+e:t}function v(t){var e=t.lastIndexOf(":");return-1===e?[t,0]:[t.substring(0,e),Number(t.substring(e+1))]}function y(t,e){for(var n=[],r=0;r<t.length;r+=e)n.push(t.slice(r,r+e));return n}var b=Object.freeze({json:[{tfOpName:"Add",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"AddV2",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"AddN",category:"arithmetic",inputs:[{start:0,end:0,name:"tensors",type:"tensors"}]},{tfOpName:"BiasAdd",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Sub",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"RealDiv",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Div",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"DivNoNan",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"FloorDiv",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Mul",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Maximum",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}]},{tfOpName:"Minimum",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}]},{tfOpName:"Pow",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"SquaredDifference",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Mod",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"FloorMod",category:"arithmetic",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]}]}),x=Object.freeze({json:[{tfOpName:"Abs",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Acos",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Asin",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Atan",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Atan2",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"y",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Ceil",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"ClipByValue",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"clip_value_min",name:"clipValueMin",type:"number"},{tfName:"clip_value_max",name:"clipValueMax",type:"number"}]},{tfOpName:"Complex",category:"basic_math",inputs:[{start:0,name:"real",type:"tensor"},{start:1,name:"imag",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"ComplexAbs",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Cos",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Cosh",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Elu",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Exp",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Floor",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Log",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Imag",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"Tout",name:"outputType",type:"dtype",notSupported:!0}]},{tfOpName:"Neg",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Real",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"Tout",name:"outputType",type:"dtype",notSupported:!0}]},{tfOpName:"Prelu",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"alpha",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Relu",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Relu6",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"clipValueMin",name:"clipValueMin",type:"number",defaultValue:0},{tfName:"clipValueMax",name:"clipValueMax",type:"number",defaultValue:6}]},{tfOpName:"Selu",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Sigmoid",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Sin",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Sinh",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Sqrt",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Rsqrt",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Square",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Tan",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Tanh",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Sign",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Round",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Expm1",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Log1p",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Reciprocal",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Softplus",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Asinh",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Acosh",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Atanh",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Erf",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Prod",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axes",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool",notSupported:!0},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"LeakyRelu",category:"basic_math",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"alpha",name:"alpha",type:"number",defaultValue:.2},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]}]}),w=Object.freeze({json:[{tfOpName:"LoopCond",category:"control",inputs:[{start:0,name:"pred",type:"tensor"}]},{tfOpName:"Switch",category:"control",inputs:[{start:0,name:"data",type:"tensor"},{start:1,name:"pred",type:"tensor"}]},{tfOpName:"Merge",category:"control",inputs:[{start:0,end:0,name:"tensors",type:"tensors"}]},{tfOpName:"Enter",category:"control",inputs:[{start:0,name:"tensor",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"frame_name",name:"frameName",type:"string"},{tfName:"is_constant",name:"isConstant",type:"bool"}]},{tfOpName:"Exit",category:"control",inputs:[{start:0,name:"tensor",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"NextIteration",category:"control",inputs:[{start:0,name:"tensor",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"TensorArrayV3",category:"control",inputs:[{start:0,name:"size",type:"number"}],attrs:[{tfName:"dtype",name:"dtype",type:"dtype"},{tfName:"element_shape",name:"elementShape",type:"shape"},{tfName:"dynamic_size",name:"dynamicSize",type:"bool"},{tfName:"clear_after_read",name:"clearAfterRead",type:"bool"},{tfName:"identical_element_shapes",name:"identicalElementShapes",type:"bool"},{tfName:"tensor_array_name",name:"name",type:"string"}]},{tfOpName:"TensorArrayWriteV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"number"},{start:1,name:"index",type:"number"},{start:2,name:"tensor",type:"tensor"},{start:3,name:"flowIn",type:"number"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"TensorArrayReadV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"number"},{start:1,name:"index",type:"number"},{start:2,name:"flowIn",type:"number"}],attrs:[{tfName:"dtype",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"TensorArrayGatherV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"number"},{start:1,name:"indices",type:"number[]"},{start:2,name:"flowIn",type:"number"}],attrs:[{tfName:"dtype",name:"dtype",type:"dtype"},{tfName:"element_shape",name:"elementShape",type:"shape"}]},{tfOpName:"TensorArrayScatterV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"number"},{start:1,name:"indices",type:"number[]"},{start:2,name:"tensor",type:"tensor"},{start:3,name:"flowIn",type:"number"}],attrs:[{tfName:"T",name:"dtype",type:"dtype"}]},{tfOpName:"TensorArrayConcatV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"number"},{start:1,name:"flowIn",type:"number"}],attrs:[{tfName:"dtype",name:"dtype",type:"dtype"},{tfName:"element_shape_except0",name:"elementShapeExcept0",type:"shape",notSupported:!0}]},{tfOpName:"TensorArraySplitV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"number"},{start:1,name:"tensor",type:"tensor"},{start:2,name:"lengths",type:"number[]"},{start:3,name:"flowIn",type:"number"}],attrs:[{tfName:"T",name:"dtype",type:"dtype"}]},{tfOpName:"TensorArraySizeV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"number"},{start:1,name:"flowIn",type:"number"}]},{tfOpName:"TensorArrayCloseV3",category:"control",inputs:[{start:0,name:"tensorArrayId",type:"number"}]}]}),k=Object.freeze({json:[{tfOpName:"AvgPool",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0},{tfName:"ksize",name:"kernelSize",type:"number[]"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"MaxPool",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0},{tfName:"ksize",name:"kernelSize",type:"number[]"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"MaxPoolWithArgmax",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"ksize",name:"kernelSize",type:"number[]"},{tfName:"include_batch_in_index",name:"includeBatchInIndex",type:"bool"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"AvgPool3D",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0},{tfName:"ksize",name:"kernelSize",type:"number[]"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"MaxPool3D",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0},{tfName:"ksize",name:"kernelSize",type:"number[]"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Conv1D",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"filter",type:"tensor"}],attrs:[{tfName:"stride",name:"stride",type:"number"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",defaultValue:"NWC"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"dilation",name:"dilation",type:"number",defaultValue:1}]},{tfOpName:"Conv2D",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"filter",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"useCudnnOnGpu",name:"useCudnnOnGpu",type:"bool"},{tfName:"data_format",name:"dataFormat",type:"string",defaultValue:"NHWC"},{tfName:"dilations",name:"dilations",type:"number[]"}]},{tfOpName:"_FusedConv2D",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"filter",type:"tensor"},{start:2,end:0,name:"args",type:"tensors"}],attrs:[{tfName:"num_args",name:"numArgs",type:"number"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"explicit_paddings",name:"explicitPaddings",type:"number[]",defaultValue:[]},{tfName:"use_cudnn_on_gpu",name:"useCudnnOnGpu",type:"bool",defaultValue:!0},{tfName:"data_format",name:"dataFormat",type:"string",defaultValue:"NHWC"},{tfName:"dilations",name:"dilations",type:"number[]",defaultValue:[1,1,1,1]},{tfName:"fused_ops",name:"fusedOps",type:"string[]",defaultValue:[]},{tfName:"epsilon",name:"epsilon",type:"number",defaultValue:1e-4}]},{tfOpName:"Conv2DBackpropInput",category:"convolution",inputs:[{start:2,name:"x",type:"tensor"},{start:1,name:"filter",type:"tensor"},{start:0,name:"outputShape",type:"number[]"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0}]},{tfOpName:"DepthwiseConv2d",category:"convolution",inputs:[{start:0,name:"input",type:"tensor"},{start:1,name:"filter",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",defaultValue:"NHWC"},{tfName:"dilations",name:"dilations",type:"number[]"}]},{tfOpName:"DepthwiseConv2dNative",category:"convolution",inputs:[{start:0,name:"input",type:"tensor"},{start:1,name:"filter",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",defaultValue:"NHWC"},{tfName:"dilations",name:"dilations",type:"number[]"}]},{tfOpName:"FusedDepthwiseConv2dNative",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"filter",type:"tensor"},{start:2,end:0,name:"args",type:"tensors"}],attrs:[{tfName:"num_args",name:"numArgs",type:"number"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0},{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",defaultValue:"NHWC"},{tfName:"dilations",name:"dilations",type:"number[]",defaultValue:[1,1,1,1]},{tfName:"fused_ops",name:"fusedOps",type:"string[]",defaultValue:[]}]},{tfOpName:"Conv3D",category:"convolution",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"filter",type:"tensor"}],attrs:[{tfName:"strides",name:"strides",type:"number[]"},{tfName:"padding",name:"pad",type:"string"},{tfName:"data_format",name:"dataFormat",type:"string",defaultValue:"NHWC"},{tfName:"dilations",name:"dilations",type:"number[]"}]}]}),_=Object.freeze({json:[{tfOpName:"Fill",category:"creation",inputs:[{start:0,name:"shape",type:"number[]"},{start:1,name:"value",type:"number"}],attrs:[{tfName:"T",name:"dtype",type:"dtype"}]},{tfOpName:"LinSpace",category:"creation",inputs:[{start:0,name:"start",type:"number"},{start:1,name:"stop",type:"number"},{start:2,name:"num",type:"number"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"OneHot",category:"creation",inputs:[{start:0,name:"indices",type:"tensor"},{start:1,name:"depth",type:"number"},{start:2,name:"onValue",type:"number",defaultValue:1},{start:3,name:"offValue",type:"number",defaultValue:0}],attrs:[{tfName:"axis",name:"axis",type:"number",notSupported:!0},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Ones",category:"creation",inputs:[{start:0,name:"shape",type:"number[]"}],attrs:[{tfName:"T",name:"dtype",type:"dtype"}]},{tfOpName:"OnesLike",category:"creation",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"dtype",name:"dtype",type:"dtype"}]},{tfOpName:"RandomUniform",category:"creation",inputs:[{start:0,name:"shape",type:"number[]"}],attrs:[{tfName:"minval",name:"minval",type:"number",defaultValue:0},{tfName:"maxval",name:"maxval",type:"number",defaultValue:1},{tfName:"dtype",name:"dtype",type:"dtype"},{tfName:"seed",name:"seed",type:"number",defaultValue:0},{tfName:"seed2",name:"seed2",type:"number",defaultValue:0,notSupported:!0},{tfName:"T",name:"T",type:"number",notSupported:!0}]},{tfOpName:"Range",category:"creation",inputs:[{start:0,name:"start",type:"number"},{start:1,name:"stop",type:"number"},{start:2,name:"step",type:"number",defaultValue:0}],attrs:[{tfName:"Tidx",name:"dtype",type:"dtype"}]},{tfOpName:"TruncatedNormal",category:"creation",inputs:[{start:0,name:"shape",type:"number[]"}],attrs:[{tfName:"means",name:"mean",type:"number",defaultValue:0},{tfName:"stddev",name:"stdDev",type:"number",defaultValue:1},{tfName:"seed",name:"seed",type:"number"},{tfName:"seed2",name:"seed2",type:"number",defaultValue:0,notSupported:!0},{tfName:"dtype",name:"dtype",type:"dtype"},{tfName:"T",name:"T",type:"number",notSupported:!0}]},{tfOpName:"Zeros",category:"creation",inputs:[{start:0,name:"shape",type:"number[]"}],attrs:[{tfName:"T",name:"dtype",type:"dtype"}]},{tfOpName:"ZerosLike",category:"creation",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype"}]},{tfOpName:"Multinomial",category:"creation",inputs:[{start:0,name:"logits",type:"tensor"},{start:1,name:"numSamples",type:"number"}],attrs:[{tfName:"seed",name:"seed",type:"number"},{tfName:"seed2",name:"seed2",type:"number"},{tfName:"T",name:"dtype",type:"dtype"},{tfName:"output_dtype",name:"output_dtype",type:"dtype"}]}]}),E=Object.freeze({json:[{tfOpName:"NonMaxSuppressionV2",category:"dynamic",inputs:[{start:0,name:"boxes",type:"tensor"},{start:1,name:"scores",type:"tensor"},{start:2,name:"maxOutputSize",type:"number"},{start:3,name:"iouThreshold",type:"number"}]},{tfOpName:"NonMaxSuppressionV3",category:"dynamic",inputs:[{start:0,name:"boxes",type:"tensor"},{start:1,name:"scores",type:"tensor"},{start:2,name:"maxOutputSize",type:"number"},{start:3,name:"iouThreshold",type:"number"},{start:4,name:"scoreThreshold",type:"number"}]},{tfOpName:"NonMaxSuppressionV5",category:"dynamic",inputs:[{start:0,name:"boxes",type:"tensor"},{start:1,name:"scores",type:"tensor"},{start:2,name:"maxOutputSize",type:"number"},{start:3,name:"iouThreshold",type:"number"},{start:4,name:"scoreThreshold",type:"number"},{start:5,name:"softNmsSigma",type:"number"}]},{tfOpName:"Where",category:"dynamic",inputs:[{start:0,name:"condition",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"ListDiff",category:"dynamic",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"y",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]}]}),O=Object.freeze({json:[{tfOpName:"TopKV2",category:"evaluation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"k",type:"number"}],attrs:[{tfName:"sorted",name:"sorted",type:"bool"}]}]}),S=Object.freeze({json:[{tfOpName:"PlaceholderWithDefault",category:"graph",inputs:[{start:0,name:"default",type:"tensor"}],attrs:[{tfName:"shape",name:"shape",type:"shape"},{tfName:"dtype",name:"dtype",type:"dtype"}]},{tfOpName:"Placeholder",category:"graph",attrs:[{tfName:"shape",name:"shape",type:"shape"},{tfName:"dtype",name:"dtype",type:"dtype"}]},{tfOpName:"Const",category:"graph"},{tfOpName:"Identity",category:"graph",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"IdentityN",category:"graph",inputs:[{start:0,end:0,name:"x",type:"tensors"}]},{tfOpName:"Snapshot",category:"graph",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"Rank",category:"graph",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"Size",category:"graph",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"Shape",category:"graph",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"ShapeN",category:"graph",inputs:[{start:0,end:0,name:"x",type:"tensors"}]},{tfOpName:"Print",category:"graph",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"data",type:"tensors"}],attrs:[{tfName:"message",name:"message",type:"string"},{tfName:"first_n",name:"firstN",type:"number",notSupported:!0},{tfName:"summarize",name:"summarize",type:"number",defaultValue:3}]},{tfOpName:"NoOp",category:"graph",inputs:[]},{tfOpName:"StopGradient",category:"graph",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"FakeQuantWithMinMaxVars",category:"graph",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"min",name:"min",type:"number"},{tfName:"max",name:"max",type:"number"}]}]}),C=Object.freeze({json:[{tfOpName:"ResizeBilinear",category:"image",inputs:[{start:0,name:"images",type:"tensor"},{start:1,name:"size",type:"number[]"}],attrs:[{tfName:"align_corners",name:"alignCorners",type:"bool"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"ResizeNearestNeighbor",category:"image",inputs:[{start:0,name:"images",type:"tensor"},{start:1,name:"size",type:"number[]"}],attrs:[{tfName:"align_corners",name:"alignCorners",type:"bool"},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"CropAndResize",category:"image",inputs:[{start:0,name:"image",type:"tensor"},{start:1,name:"boxes",type:"tensor"},{start:2,name:"boxInd",type:"tensor"},{start:3,name:"cropSize",type:"number[]"}],attrs:[{tfName:"method",name:"method",type:"string"},{tfName:"extrapolation_value",name:"extrapolationValue",type:"number"}]}]}),A=Object.freeze({json:[{tfOpName:"Equal",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"NotEqual",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Greater",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"GreaterEqual",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Less",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"LessEqual",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"LogicalAnd",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"LogicalNot",category:"logical",inputs:[{start:0,name:"a",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"LogicalOr",category:"logical",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Select",category:"logical",inputs:[{start:0,name:"condition",type:"tensor"},{start:1,name:"a",type:"tensor"},{start:2,name:"b",type:"tensor"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]}]}),N=Object.freeze({json:[{tfOpName:"_FusedMatMul",category:"matrices",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"},{start:2,end:0,name:"args",type:"tensors"}],attrs:[{tfName:"num_args",name:"numArgs",type:"number"},{tfName:"fused_ops",name:"fusedOps",type:"string[]",defaultValue:[]},{tfName:"epsilon",name:"epsilon",type:"number",defaultValue:1e-4},{tfName:"transpose_a",name:"transposeA",type:"bool",defaultValue:!1},{tfName:"transpose_b",name:"transposeB",type:"bool",defaultValue:!1},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"MatMul",category:"matrices",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"transpose_a",name:"transposeA",type:"bool",defaultValue:!1},{tfName:"transpose_b",name:"transposeB",type:"bool",defaultValue:!1},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"BatchMatMul",category:"matrices",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"adj_x",name:"transposeA",type:"bool",defaultValue:!1},{tfName:"adj_y",name:"transposeB",type:"bool",defaultValue:!1},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"BatchMatMulV2",category:"matrices",inputs:[{start:0,name:"a",type:"tensor"},{start:1,name:"b",type:"tensor"}],attrs:[{tfName:"adj_x",name:"transposeA",type:"bool",defaultValue:!1},{tfName:"adj_y",name:"transposeB",type:"bool",defaultValue:!1},{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]},{tfOpName:"Transpose",category:"matrices",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"perm",type:"number[]"}],attrs:[{tfName:"T",name:"dtype",type:"dtype",notSupported:!0}]}]}),T=Object.freeze({json:[{tfOpName:"FusedBatchNorm",category:"normalization",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"scale",type:"tensor"},{start:2,name:"offset",type:"tensor"},{start:3,name:"mean",type:"tensor"},{start:4,name:"variance",type:"tensor"}],attrs:[{tfName:"epsilon",name:"epsilon",type:"number",defaultValue:.001},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0}]},{tfOpName:"FusedBatchNormV2",category:"normalization",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"scale",type:"tensor"},{start:2,name:"offset",type:"tensor"},{start:3,name:"mean",type:"tensor"},{start:4,name:"variance",type:"tensor"}],attrs:[{tfName:"epsilon",name:"epsilon",type:"number",defaultValue:.001},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0}]},{tfOpName:"FusedBatchNormV3",category:"normalization",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"scale",type:"tensor"},{start:2,name:"offset",type:"tensor"},{start:3,name:"mean",type:"tensor"},{start:4,name:"variance",type:"tensor"}],attrs:[{tfName:"epsilon",name:"epsilon",type:"number",defaultValue:.001},{tfName:"data_format",name:"dataFormat",type:"string",notSupported:!0}]},{tfOpName:"LRN",category:"normalization",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"depth_radius",name:"radius",type:"number",defaultValue:5},{tfName:"bias",name:"bias",type:"number",defaultValue:1},{tfName:"alpha",name:"alpha",type:"number",defaultValue:1},{tfName:"beta",name:"beta",type:"number",defaultValue:.5}]},{tfOpName:"Softmax",category:"normalization",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"LogSoftmax",category:"normalization",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"SparseToDense",category:"normalization",inputs:[{start:0,name:"sparseIndices",type:"tensor"},{start:1,name:"outputShape",type:"number[]"},{start:2,name:"sparseValues",type:"tensor"},{start:3,name:"defaultValue",type:"tensor"}],attrs:[{tfName:"validate_indices",name:"validateIndices",type:"bool",defaultValue:!0,notSupported:!0}]}]}),I=Object.freeze({json:[{tfOpName:"Max",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool"}]},{tfOpName:"Mean",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool"}]},{tfOpName:"Min",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool"}]},{tfOpName:"Sum",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool"}]},{tfOpName:"All",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool"}]},{tfOpName:"Any",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool"}]},{tfOpName:"ArgMax",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number"}]},{tfOpName:"ArgMin",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number"}]},{tfOpName:"Prod",category:"reduction",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}],attrs:[{tfName:"keep_dims",name:"keepDims",type:"bool"}]}]}),D=Object.freeze({json:[{tfOpName:"ConcatV2",category:"slice_join",inputs:[{start:0,end:-1,name:"tensors",type:"tensors"},{start:-1,name:"axis",type:"number"}],attrs:[{tfName:"N",name:"n",type:"number",defaultValue:2}]},{tfOpName:"Concat",category:"slice_join",inputs:[{start:1,end:0,name:"tensors",type:"tensors"},{start:0,name:"axis",type:"number"}],attrs:[{tfName:"N",name:"n",type:"number",defaultValue:2}]},{tfOpName:"GatherV2",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"indices",type:"tensor"},{start:2,name:"axis",type:"number",defaultValue:0}]},{tfOpName:"Gather",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"indices",type:"tensor"}],attrs:[{tfName:"axis",name:"axis",type:"number",defaultValue:0},{tfName:"validate_indices",name:"validateIndices",type:"bool",notSupported:!0}]},{tfOpName:"Reverse",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"dims",type:"bool",notSupported:!0}]},{tfOpName:"ReverseV2",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number[]"}]},{tfOpName:"Slice",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"begin",type:"number[]"},{start:2,name:"size",type:"number[]"}]},{tfOpName:"StridedSlice",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"begin",type:"number[]"},{start:2,name:"end",type:"number[]"},{start:3,name:"strides",type:"number[]"}],attrs:[{tfName:"begin_mask",name:"beginMask",type:"number",defaultValue:0},{tfName:"end_mask",name:"endMask",type:"number",defaultValue:0},{tfName:"new_axis_mask",name:"newAxisMask",type:"number",defaultValue:0},{tfName:"ellipsis_mask",name:"ellipsisMask",type:"number",defaultValue:0},{tfName:"shrink_axis_mask",name:"shrinkAxisMask",type:"number",defaultValue:0}]},{tfOpName:"Pack",category:"slice_join",inputs:[{start:0,end:0,name:"tensors",type:"tensors"}],attrs:[{tfName:"axis",name:"axis",type:"number",defaultValue:0}]},{tfOpName:"Unpack",category:"slice_join",inputs:[{start:0,name:"tensor",type:"tensor"}],attrs:[{tfName:"axis",name:"axis",type:"number",defaultValue:0},{tfName:"num",name:"num",type:"number",defaultValue:0,notSupported:!0}]},{tfOpName:"Tile",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"reps",type:"number[]"}]},{tfOpName:"Split",category:"slice_join",inputs:[{start:0,name:"axis",type:"number",defaultValue:0},{start:1,name:"x",type:"tensor"}],attrs:[{tfName:"num_split",name:"numOrSizeSplits",type:"number",defaultValue:1}]},{tfOpName:"SplitV",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"numOrSizeSplits",type:"number[]"},{start:2,name:"axis",type:"number",defaultValue:0}]},{tfOpName:"ScatterNd",category:"slice_join",inputs:[{start:0,name:"indices",type:"tensor"},{start:1,name:"values",type:"tensor"},{start:2,name:"shape",type:"number[]"}]},{tfOpName:"GatherNd",category:"slice_join",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"indices",type:"tensor"}]},{tfOpName:"SparseToDense",category:"slice_join",inputs:[{start:0,name:"sparseIndices",type:"tensor"},{start:1,name:"outputShape",type:"number[]"},{start:2,name:"sparseValues",type:"tensor"},{start:3,name:"defaultValue",type:"tensor"}],attrs:[{tfName:"validate_indices",name:"validateIndices",type:"bool",defaultValue:!1,notSupported:!0}]}]}),M=Object.freeze({json:[{tfOpName:"FFT",category:"spectral",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"IFFT",category:"spectral",inputs:[{start:0,name:"x",type:"tensor"}]},{tfOpName:"RFFT",category:"spectral",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"fft_length",type:"number",notSupported:!0}]},{tfOpName:"IRFFT",category:"spectral",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"fft_length",type:"number",notSupported:!0}]}]}),R=Object.freeze({json:[{tfOpName:"Cast",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"SrcT",name:"sdtype",type:"dtype",notSupported:!0},{tfName:"DstT",name:"dtype",type:"dtype"}]},{tfOpName:"ExpandDims",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"axis",type:"number"}]},{tfOpName:"Pad",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"padding",type:"number[]"}],attrs:[{tfName:"constant_value",name:"constantValue",type:"number",defaultValue:0}]},{tfOpName:"PadV2",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"padding",type:"number[]"},{start:2,name:"constantValue",type:"number",defaultValue:0}]},{tfOpName:"Reshape",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"shape",type:"number[]"}]},{tfOpName:"Squeeze",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"axis",tfDeprecatedName:"squeeze_dims",name:"axis",type:"number[]"}]},{tfOpName:"SpaceToBatchND",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"blockShape",type:"number[]"},{start:2,name:"paddings",type:"number[]"}]},{tfOpName:"BatchToSpaceND",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"},{start:1,name:"blockShape",type:"number[]"},{start:2,name:"crops",type:"number[]"}]},{tfOpName:"DepthToSpace",category:"transformation",inputs:[{start:0,name:"x",type:"tensor"}],attrs:[{tfName:"block_size",name:"blockSize",type:"number"},{tfName:"data_format",name:"dataFormat",type:"string"}]}]}),F=function(){function t(){var t=[b,x,w,k,_,E,O,A,C,S,N,T,I,D,M,R],e=[].concat.apply([],t.map(function(t){return t.json}));this.opMappers=e.reduce(function(t,e){return t[e.tfOpName]=e,t},{})}return Object.defineProperty(t,"Instance",{get:function(){return this._instance||(this._instance=new this)},enumerable:!0,configurable:!0}),t.prototype.transformGraph=function(t,e){var n=this;void 0===e&&(e={});var r=[],i=[],a=t.node.reduce(function(t,e){return t[e.name]=n.mapNode(e),e.op.startsWith("Placeholder")&&r.push(t[e.name]),"Const"===e.op&&i.push(t[e.name]),t},{}),o=[],s=[],u={},c={};null!=e&&(u=this.mapSignatureEntries(e.inputs),c=this.mapSignatureEntries(e.outputs));var l=Object.keys(a);return l.forEach(function(t){var e=a[t];e.inputNames.forEach(function(t){var n=m(t)[0];e.inputs.push(a[n]),a[n].children.push(e)})}),0===Object.keys(c).length?l.forEach(function(t){var e=a[t];0===e.children.length&&s.push(e)}):Object.keys(c).forEach(function(t){var e=m(t)[0],n=a[e];null!=n&&(n.signatureKey=c[t],s.push(n))}),Object.keys(u).length>0?Object.keys(u).forEach(function(t){var e=m(t)[0],n=a[e];n&&(n.signatureKey=u[t],o.push(n))}):o=r,{nodes:a,inputs:o,outputs:s,weights:i,placeholders:r,signature:e}},t.prototype.mapSignatureEntries=function(t){return Object.keys(t||{}).reduce(function(e,n){return e[t[n].name]=n,e},{})},t.prototype.mapNode=function(t){var e=f(t.op)||this.opMappers[t.op]||{};null==t.attr&&(t.attr={});var n={name:t.name,op:t.op,category:e.category,inputNames:(t.input||[]).map(function(t){return t.startsWith("^")?t.substr(1):t}),inputs:[],children:[],inputParams:{},attrParams:{},rawAttrs:t.attr};return null!=e.inputs&&(n.inputParams=e.inputs.reduce(function(t,e){return t[e.name]={type:e.type,inputIndexStart:e.start,inputIndexEnd:e.end},t},{})),null!=e.attrs&&(n.attrParams=e.attrs.reduce(function(e,n){var r=n.type,i=void 0;switch(n.type){case"string":void 0===(i=P(t.attr,n.tfName,n.defaultValue))&&n.tfDeprecatedName&&(i=P(t.attr,n.tfDeprecatedName,n.defaultValue));break;case"string[]":void 0===(i=G(t.attr,n.tfName,n.defaultValue))&&n.tfDeprecatedName&&(i=G(t.attr,n.tfDeprecatedName,n.defaultValue));break;case"number":void 0===(i=z(t.attr,n.tfName,n.defaultValue||0))&&n.tfDeprecatedName&&(i=z(t.attr,n.tfDeprecatedName,n.defaultValue));break;case"number[]":void 0===(i=H(t.attr,n.tfName,n.defaultValue))&&n.tfDeprecatedName&&(i=H(t.attr,n.tfDeprecatedName,n.defaultValue));break;case"bool":void 0===(i=L(t.attr,n.tfName,n.defaultValue))&&n.tfDeprecatedName&&(i=L(t.attr,n.tfDeprecatedName,n.defaultValue));break;case"bool[]":void 0===(i=K(t.attr,n.tfName,n.defaultValue))&&n.tfDeprecatedName&&(i=K(t.attr,n.tfDeprecatedName,n.defaultValue));break;case"shape":void 0===(i=q(t.attr,n.tfName,n.defaultValue))&&n.tfDeprecatedName&&(i=q(t.attr,n.tfDeprecatedName,n.defaultValue));break;case"shape[]":void 0===(i=$(t.attr,n.tfName,n.defaultValue))&&n.tfDeprecatedName&&(i=$(t.attr,n.tfDeprecatedName,n.defaultValue));break;case"dtype":void 0===(i=U(t.attr,n.tfName,n.defaultValue))&&n.tfDeprecatedName&&(i=U(t.attr,n.tfDeprecatedName,n.defaultValue));break;case"dtype[]":void 0===(i=W(t.attr,n.tfName,n.defaultValue))&&n.tfDeprecatedName&&(i=W(t.attr,n.tfDeprecatedName,n.defaultValue));break;case"tensor":case"tensors":break;default:throw new Error("Unsupported param type: "+n.type+" for op: "+t.op)}return e[n.name]={value:i,type:r},e},{})),n},t}();function j(e,n){var r=Array.isArray(e)?String.fromCharCode.apply(null,e):function(e){var n=Object(a.env)().global;if(void 0!==n.atob)return n.atob(e);if(void 0!==t)return new t(e,"base64").toString();throw new Error("Unable to decode base64 in this environment. Missing built-in atob() or Buffer()")}(e);return n?r:r.toLowerCase()}function P(t,e,n,r){void 0===r&&(r=!1);var i=t[e];return null!=i?j(i.s,r):n}function L(t,e,n){var r=t[e];return r?r.b:n}function z(t,e,n){var r=t[e]||{},i=null!=r.i?r.i:null!=r.f?r.f:n;return"number"==typeof i?i:parseInt(i,10)}function B(t){switch("string"==typeof t&&(t=r[t]),t){case r.DT_FLOAT:return"float32";case r.DT_INT32:case r.DT_INT64:case r.DT_INT8:case r.DT_UINT8:return"int32";case r.DT_BOOL:return"bool";case r.DT_DOUBLE:return"float32";case r.DT_STRING:return"string";default:return null}}function U(t,e,n){var r=t[e];return r&&r.type?B(r.type):n}function W(t,e,n){var r=t[e];return r&&r.list&&r.list.type?r.list.type.map(function(t){return B(t)}):n}function V(t){if(!t.unknownRank)return null!=t.dim?t.dim.map(function(t){return"number"==typeof t.size?t.size:parseInt(t.size,10)}):[]}function q(t,e,n){var r=t[e];return r&&r.shape?V(r.shape):n}function H(t,e,n){var r=t[e];return r?((r.list.f&&r.list.f.length?r.list.f:r.list.i)||[]).map(function(t){return"number"==typeof t?t:parseInt(t,10)}):n}function G(t,e,n,r){void 0===r&&(r=!1);var i=t[e];return i&&i.list&&i.list.s?i.list.s.map(function(t){return j(t,r)}):n}function $(t,e,n){var r=t[e];return r&&r.list&&r.list.shape?r.list.shape.map(function(t){return V(t)}):n}function K(t,e,n){var r=t[e];return r&&r.list&&r.list.b?r.list.b:n}var X=function(){function t(t,e,n){var r=this;this.node=t,this.tensorMap=e,this.context=n,this.inputs=[],this.attrs={},this.inputs=t.inputNames.map(function(t){return r.getInput(t)}),null!=t.rawAttrs&&(this.attrs=Object.keys(t.rawAttrs).reduce(function(t,e){return t[e]=r.getAttr(e),t},{}))}return t.prototype.getInput=function(t){return p(t,this.tensorMap,this.context)},t.prototype.getAttr=function(t,e){var n=this.node.rawAttrs[t];if(null!=n.tensor)return p(t,this.tensorMap,this.context);if(null!=n.i||null!=n.f)return z(this.node.rawAttrs,t,e);if(null!=n.s)return P(this.node.rawAttrs,t,e);if(null!=n.b)return L(this.node.rawAttrs,t,e);if(null!=n.shape)return q(this.node.rawAttrs,t,e);if(null!=n.type)return U(this.node.rawAttrs,t,e);if(null!=n.list){if(null!=n.list.i||null!=n.list.f)return H(this.node.rawAttrs,t,e);if(null!=n.list.s)return G(this.node.rawAttrs,t,e);if(null!=n.list.shape)return $(this.node.rawAttrs,t,e);if(null!=n.list.b)return K(this.node.rawAttrs,t,e);if(null!=n.list.type)return W(this.node.rawAttrs,t,e)}return e},t}(),Y=function(t,e,n){switch(t.op){case"BiasAdd":case"AddV2":case"Add":return[Object(a.add)(h("a",t,e,n),h("b",t,e,n))];case"AddN":return[Object(a.addN)(h("tensors",t,e,n))];case"FloorMod":case"Mod":return[Object(a.mod)(h("a",t,e,n),h("b",t,e,n))];case"Mul":return[Object(a.mul)(h("a",t,e,n),h("b",t,e,n))];case"RealDiv":case"Div":return[Object(a.div)(h("a",t,e,n),h("b",t,e,n))];case"DivNoNan":return[Object(a.divNoNan)(h("a",t,e,n),h("b",t,e,n))];case"FloorDiv":return[Object(a.floorDiv)(h("a",t,e,n),h("b",t,e,n))];case"Sub":return[Object(a.sub)(h("a",t,e,n),h("b",t,e,n))];case"Minimum":return[Object(a.minimum)(h("a",t,e,n),h("b",t,e,n))];case"Maximum":return[Object(a.maximum)(h("a",t,e,n),h("b",t,e,n))];case"Pow":return[Object(a.pow)(h("a",t,e,n),h("b",t,e,n))];case"SquaredDifference":return[Object(a.squaredDifference)(h("a",t,e,n),h("b",t,e,n))];default:throw TypeError("Node type "+t.op+" is not implemented")}},J=function(t,e,n){switch(t.op){case"Abs":case"ComplexAbs":return[Object(a.abs)(h("x",t,e,n))];case"Acos":return[Object(a.acos)(h("x",t,e,n))];case"Acosh":return[Object(a.acosh)(h("x",t,e,n))];case"Asin":return[Object(a.asin)(h("x",t,e,n))];case"Asinh":return[Object(a.asinh)(h("x",t,e,n))];case"Atan":return[Object(a.atan)(h("x",t,e,n))];case"Atan2":return[Object(a.atan2)(h("x",t,e,n),h("y",t,e,n))];case"Atanh":return[Object(a.atanh)(h("x",t,e,n))];case"Ceil":return[Object(a.ceil)(h("x",t,e,n))];case"Complex":return[Object(a.complex)(h("real",t,e,n),h("imag",t,e,n))];case"Cos":return[Object(a.cos)(h("x",t,e,n))];case"Cosh":return[Object(a.cosh)(h("x",t,e,n))];case"Elu":return[Object(a.elu)(h("x",t,e,n))];case"Erf":return[Object(a.erf)(h("x",t,e,n))];case"Exp":return[Object(a.exp)(h("x",t,e,n))];case"Expm1":return[Object(a.expm1)(h("x",t,e,n))];case"Floor":return[Object(a.floor)(h("x",t,e,n))];case"Log":return[Object(a.log)(h("x",t,e,n))];case"Log1p":return[Object(a.log1p)(h("x",t,e,n))];case"Imag":return[Object(a.imag)(h("x",t,e,n))];case"Neg":return[Object(a.neg)(h("x",t,e,n))];case"Reciprocal":return[Object(a.reciprocal)(h("x",t,e,n))];case"Real":return[Object(a.real)(h("x",t,e,n))];case"Relu":return[Object(a.relu)(h("x",t,e,n))];case"Round":return[Object(a.round)(h("x",t,e,n))];case"Selu":return[Object(a.selu)(h("x",t,e,n))];case"Sigmoid":return[Object(a.sigmoid)(h("x",t,e,n))];case"Sin":return[Object(a.sin)(h("x",t,e,n))];case"Sign":return[Object(a.sign)(h("x",t,e,n))];case"Sinh":return[Object(a.sinh)(h("x",t,e,n))];case"Softplus":return[Object(a.softplus)(h("x",t,e,n))];case"Sqrt":return[Object(a.sqrt)(h("x",t,e,n))];case"Square":return[Object(a.square)(h("x",t,e,n))];case"Tanh":return[Object(a.tanh)(h("x",t,e,n))];case"Tan":return[Object(a.tan)(h("x",t,e,n))];case"Relu6":case"ClipByValue":return[Object(a.clipByValue)(h("x",t,e,n),h("clipValueMin",t,e,n),h("clipValueMax",t,e,n))];case"Rsqrt":return[Object(a.rsqrt)(p(t.inputNames[0],e,n))];case"Prod":return[Object(a.prod)(h("x",t,e,n),h("axes",t,e,n))];case"LeakyRelu":return[Object(a.leakyRelu)(h("x",t,e,n),h("alpha",t,e,n))];case"Prelu":return[Object(a.prelu)(h("x",t,e,n),h("alpha",t,e,n))];default:throw TypeError("Node type "+t.op+" is not implemented")}},Z=function(){function t(e,n,r,i,a,o,s){this.name=e,this.dtype=n,this.maxSize=r,this.elementShape=i,this.identicalElementShapes=a,this.dynamicSize=o,this.clearAfterRead=s,this.tensors=[],this.closed_=!1,this.id=t.nextId++}return Object.defineProperty(t.prototype,"closed",{get:function(){return this.closed_},enumerable:!0,configurable:!0}),t.prototype.clearAndClose=function(){this.tensors.forEach(function(t){return t.tensor.dispose()}),this.tensors=[],this.closed_=!0},t.prototype.size=function(){return this.tensors.length},t.prototype.read=function(t){if(this.closed_)throw new Error("TensorArray "+this.name+" has already been closed.");if(t<0||t>=this.tensors.length)throw new Error("Tried to read from index "+t+", but array size is: "+this.tensors.length);var e=this.tensors[t];if(e.cleared)throw new Error("TensorArray "+this.name+": Could not read index "+t+" twice because it was cleared after a previous read (perhaps try setting clear_after_read = false?).");return this.clearAfterRead&&(e.cleared=!0),e.read=!0,e.tensor},t.prototype.readMany=function(t){var e=this;return t.map(function(t){return e.read(t)})},t.prototype.write=function(t,e){if(this.closed_)throw new Error("TensorArray "+this.name+" has already been closed.");if(t<0||!this.dynamicSize&&t>=this.maxSize)throw new Error("Tried to write to index "+t+", but array is not resizeable and size is: "+this.maxSize);var n=this.tensors[t]||{};if(e.dtype!==this.dtype)throw new Error("TensorArray "+this.name+": Could not write to TensorArray index "+t+",\n because the value dtype is "+e.dtype+", but TensorArray dtype is "+this.dtype+".");if(0!==this.size()||null!=this.elementShape&&0!==this.elementShape.length||(this.elementShape=e.shape),this.assertShapesMatchAllowUndefinedSize(this.elementShape,e.shape,"TensorArray "+this.name+": Could not write to TensorArray index "+t+"."),n&&n.read)throw new Error("TensorArray "+this.name+": Could not write to TensorArray index "+t+", because it has already been read.");if(n&&n.written)throw new Error("TensorArray "+this.name+": Could not write to TensorArray index "+t+", because it has already been written.");n.tensor=e,n.written=!0,this.tensors[t]=n},t.prototype.writeMany=function(t,e){var n=this;if(t.length!==e.length)throw new Error("TensorArray "+this.name+": could not write multiple tensors,because the index size: "+t.length+" is not the same as tensors size: "+e.length+".");t.forEach(function(t,r){return n.write(t,e[r])})},t.prototype.gather=function(t,e){if(e&&e!==this.dtype)throw new Error("TensorArray dtype is "+this.dtype+" but gather requested dtype "+e);if(!t){t=[];for(var n=0;n<this.size();n++)t.push(n)}if(0===t.length)return Object(a.tensor)([],[0].concat(this.elementShape));var r=this.readMany(t);return this.assertShapesMatchAllowUndefinedSize(this.elementShape,r[0].shape,"TensorArray shape mismatch: "),Object(a.stack)(r,0)},t.prototype.concat=function(t){if(t&&t!==this.dtype)throw new Error("TensorArray dtype is "+this.dtype+" but concat requested dtype "+t);if(0===this.size())return Object(a.tensor)([],[0].concat(this.elementShape));for(var e=[],n=0;n<this.size();n++)e.push(n);var r=this.readMany(e);return this.assertShapesMatchAllowUndefinedSize(this.elementShape,r[0].shape,"TensorArray shape mismatch: tensor array shape ("+this.elementShape+") vs first tensor shape ("+r[0].shape+")"),Object(a.concat)(r,0)},t.prototype.scatter=function(t,e){if(e.dtype!==this.dtype)throw new Error("TensorArray dtype is "+this.dtype+" but tensor has dtype "+e.dtype);if(t.length!==e.shape[0])throw new Error("Expected len(indices) == tensor.shape[0], but saw: "+t.length+" vs. "+e.shape[0]);var n=Math.max.apply(Math,t);if(!this.dynamicSize&&n>=this.maxSize)throw new Error("Max index must be < array size ("+n+" vs. "+this.maxSize+")");this.writeMany(t,Object(a.unstack)(e,0))},t.prototype.split=function(t,e){var n=this;if(e.dtype!==this.dtype)throw new Error("TensorArray dtype is "+this.dtype+" but tensor has dtype "+e.dtype);var r=0,i=t.map(function(t){return r+=t});if(r!==e.shape[0])throw new Error("Expected sum of lengths to be equal to\n tensor.shape[0], but sum of lengths is\n "+r+", and tensor's shape is: "+e.shape);if(!this.dynamicSize&&t.length!==this.maxSize)throw new Error("TensorArray's size is not equal to the size of lengths ("+this.maxSize+" vs. "+t.length+"), and the TensorArray is not marked as dynamically resizeable");var o=0===r?0:e.size/r,s=[];Object(a.tidy)(function(){e=e.reshape([1,r,o]);for(var u=0;u<t.length;++u){var c=[0,0===u?0:i[u-1],0],l=[1,t[u],o];s[u]=Object(a.slice)(e,c,l).reshape(n.elementShape)}return s});for(var u=[],c=0;c<t.length;c++)u[c]=c;this.writeMany(u,s)},t.prototype.assertShapesMatchAllowUndefinedSize=function(t,e,n){void 0===n&&(n=""),a.util.assert(this.shapesEqualAllowUndefinedSize(t,e),function(){return n+" Shapes "+t+" and "+e+" must match"})},t.prototype.shapesEqualAllowUndefinedSize=function(t,e){if(t.length!==e.length)return!1;for(var n=0;n<t.length;n++)if(-1!==t[n]&&-1!==e[n]&&t[n]!==e[n])return!1;return!0},t.nextId=0,t}(),Q=function(t,e,n){return s(void 0,void 0,void 0,function(){var r,i,o,s,c,l,f,d,m,g,v,y,b,x,w,k,_,E,O,S,C,A,N,T,I,D,M,R,F,j,P,L,z,B,U;return u(this,function(u){switch(u.label){case 0:switch(t.op){case"LoopCond":return[3,1];case"Switch":return[3,2];case"Merge":return[3,4];case"Enter":return[3,5];case"Exit":return[3,6];case"NextIteration":return[3,7];case"TensorArrayV3":return[3,8];case"TensorArrayWriteV3":return[3,9];case"TensorArrayReadV3":return[3,10];case"TensorArrayGatherV3":return[3,11];case"TensorArrayScatterV3":return[3,12];case"TensorArrayConcatV3":return[3,13];case"TensorArraySplitV3":return[3,14];case"TensorArraySizeV3":return[3,15];case"TensorArrayCloseV3":return[3,16]}return[3,17];case 1:return[2,[h("pred",t,e,n).clone()]];case 2:return r=h("pred",t,e,n),i=h("data",t,e,n),[4,r.data()];case 3:return[2,u.sent()[0]?[void 0,i.clone()]:[i.clone(),void 0]];case 4:return[2,(o=t.inputNames.find(function(t){return void 0!==p(t,e,n)}))?[p(o,e,n).clone()]:void 0];case 5:return s=h("frameName",t,e,n),c=h("tensor",t,e,n),n.enterFrame(s),[2,[c.clone()]];case 6:return l=h("tensor",t,e,n),n.exitFrame(),[2,[l.clone()]];case 7:return f=h("tensor",t,e,n),n.nextIteration(),[2,[f.clone()]];case 8:return d=h("size",t,e,n),m=h("dtype",t,e,n),g=h("elementShape",t,e,n),v=h("dynamicSize",t,e,n),y=h("clearAfterRead",t,e,n),b=h("identicalElementShapes",t,e,n),x=h("name",t,e,n),w=new Z(x,m,d,g,b,v,y),n.addTensorArray(w),[2,[Object(a.scalar)(w.id),Object(a.scalar)(1)]];case 9:return k=h("tensorArrayId",t,e,n),_=h("index",t,e,n),E=h("tensor",t,e,n),n.getTensorArray(k).write(_,E),[2,[Object(a.scalar)(1)]];case 10:return O=h("tensorArrayId",t,e,n),S=h("index",t,e,n),[2,[n.getTensorArray(O).read(S)]];case 11:return C=h("tensorArrayId",t,e,n),A=h("indices",t,e,n),N=h("dtype",t,e,n),[2,[n.getTensorArray(C).gather(A,N)]];case 12:return T=h("tensorArrayId",t,e,n),I=h("indices",t,e,n),D=h("tensor",t,e,n),n.getTensorArray(T).scatter(I,D),[2,[Object(a.scalar)(1)]];case 13:return M=h("tensorArrayId",t,e,n),R=n.getTensorArray(M),F=h("dtype",t,e,n),[2,[R.concat(F)]];case 14:return j=h("tensorArrayId",t,e,n),P=h("tensor",t,e,n),L=h("lengths",t,e,n),n.getTensorArray(j).split(L,P),[2,[Object(a.scalar)(1)]];case 15:return z=h("tensorArrayId",t,e,n),B=n.getTensorArray(z),[2,[Object(a.scalar)(B.size(),"int32")]];case 16:return U=h("tensorArrayId",t,e,n),n.getTensorArray(U).clearAndClose(),[2,[Object(a.scalar)(0)]];case 17:throw TypeError("Node type "+t.op+" is not implemented")}})})},tt=function(t,e,n){switch(t.op){case"Conv1D":var r=h("stride",t,e,n),i=h("pad",t,e,n),o=h("dataFormat",t,e,n).toUpperCase(),s=h("dilation",t,e,n);return[Object(a.conv1d)(h("x",t,e,n),h("filter",t,e,n),r,i,o,s)];case"Conv2D":r=h("strides",t,e,n),i=h("pad",t,e,n),o=h("dataFormat",t,e,n).toUpperCase();var u=h("dilations",t,e,n);return[Object(a.conv2d)(h("x",t,e,n),h("filter",t,e,n),[r[1],r[2]],i,o,[u[1],u[2]])];case"_FusedConv2D":case"FusedDepthwiseConv2dNative":var c=h("fusedOps",t,e,n),l=c[0],f=c[1],d="biasadd"===l,p="prelu"===f,m="fusedbatchnorm"===l,g=h("numArgs",t,e,n);if(d){if(p&&2!==g)throw new Error("FusedConv2d and DepthwiseConv2d with BiasAdd and Prelu must have two extra arguments: bias and alpha.");if(!p&&1!==g)throw new Error("FusedConv2d and DepthwiseConv2d with BiasAdd must have one extra argument: bias.")}if(m)throw new Error("FusedConv2d and DepthwiseConv2d with FusedBatchNorm is not supported.");r=h("strides",t,e,n),i=h("pad",t,e,n),o=h("dataFormat",t,e,n).toUpperCase(),u=h("dilations",t,e,n);var v=h("args",t,e,n),y=v[0],b=v[1];return[("_FusedConv2D"===t.op?a.fused.conv2d:a.fused.depthwiseConv2d)({x:h("x",t,e,n),filter:h("filter",t,e,n),strides:[r[1],r[2]],pad:i,dataFormat:o,dilations:[u[1],u[2]],bias:y,activation:f,preluActivationWeights:b})];case"Conv2DBackpropInput":case"Conv2dTranspose":var x=h("outputShape",t,e,n);return r=h("strides",t,e,n),i=h("pad",t,e,n),[Object(a.conv2dTranspose)(h("x",t,e,n),h("filter",t,e,n),x,[r[1],r[2]],i)];case"DepthwiseConv2dNative":case"DepthwiseConv2d":return r=h("strides",t,e,n),i=h("pad",t,e,n),u=h("dilations",t,e,n),o=h("dataFormat",t,e,n).toUpperCase(),[Object(a.depthwiseConv2d)(h("input",t,e,n),h("filter",t,e,n),[r[1],r[2]],i,o,[u[1],u[2]])];case"Conv3D":return r=h("strides",t,e,n),i=h("pad",t,e,n),o=h("dataFormat",t,e,n).toUpperCase(),u=h("dilations",t,e,n),[Object(a.conv3d)(h("x",t,e,n),h("filter",t,e,n),[r[1],r[2],r[3]],i,o,[u[1],u[2],u[3]])];case"AvgPool":r=h("strides",t,e,n),i=h("pad",t,e,n);var w=h("kernelSize",t,e,n);return[Object(a.avgPool)(h("x",t,e,n),[w[1],w[2]],[r[1],r[2]],i)];case"MaxPool":return r=h("strides",t,e,n),i=h("pad",t,e,n),w=h("kernelSize",t,e,n),[Object(a.maxPool)(h("x",t,e,n),[w[1],w[2]],[r[1],r[2]],i)];case"MaxPoolWithArgmax":r=h("strides",t,e,n),i=h("pad",t,e,n),w=h("kernelSize",t,e,n);var k=h("includeBatchInIndex",t,e,n),_=Object(a.maxPoolWithArgmax)(h("x",t,e,n),[w[1],w[2]],[r[1],r[2]],i,k);return[_.result,_.indexes];case"AvgPool3D":return r=h("strides",t,e,n),i=h("pad",t,e,n),w=h("kernelSize",t,e,n),[Object(a.avgPool3d)(h("x",t,e,n),[w[1],w[2],w[3]],[r[1],r[2],r[3]],i)];case"MaxPool3D":return r=h("strides",t,e,n),i=h("pad",t,e,n),w=h("kernelSize",t,e,n),[Object(a.maxPool3d)(h("x",t,e,n),[w[1],w[2],w[3]],[r[1],r[2],r[3]],i)];default:throw TypeError("Node type "+t.op+" is not implemented")}},et=function(t,e,n){switch(t.op){case"Fill":var r=h("shape",t,e,n),i=h("dtype",t,e,n),o=h("value",t,e,n);return[Object(a.fill)(r,o,i)];case"LinSpace":var s=h("start",t,e,n),u=h("stop",t,e,n),c=h("num",t,e,n);return[Object(a.linspace)(s,u,c)];case"Multinomial":var l=h("logits",t,e,n),f=h("numSamples",t,e,n),d=h("seed",t,e,n);return[Object(a.multinomial)(l,f,d)];case"OneHot":var p=h("indices",t,e,n),m=h("depth",t,e,n),g=h("onValue",t,e,n),v=h("offValue",t,e,n);return[Object(a.oneHot)(p,m,g,v)];case"Ones":return[Object(a.ones)(h("shape",t,e,n),h("dtype",t,e,n))];case"OnesLike":return[Object(a.onesLike)(h("x",t,e,n))];case"RandomUniform":return[Object(a.randomUniform)(h("shape",t,e,n),h("minval",t,e,n),h("maxval",t,e,n),h("dtype",t,e,n))];case"Range":s=h("start",t,e,n);var y=h("stop",t,e,n),b=h("step",t,e,n);return[Object(a.range)(s,y,b,h("dtype",t,e,n))];case"TruncatedNormal":r=h("shape",t,e,n);var x=h("mean",t,e,n),w=h("stdDev",t,e,n);return d=h("seed",t,e,n),[Object(a.truncatedNormal)(r,x,w,h("dtype",t,e,n),d)];case"Zeros":return[Object(a.zeros)(h("shape",t,e,n),h("dtype",t,e,n))];case"ZerosLike":return[Object(a.zerosLike)(h("x",t,e,n))];default:throw TypeError("Node type "+t.op+" is not implemented")}},nt=function(t,e,n){return s(void 0,void 0,void 0,function(){var r,i,o,s,c,l,f,d;return u(this,function(u){switch(u.label){case 0:switch(t.op){case"NonMaxSuppressionV5":case"NonMaxSuppressionV3":case"NonMaxSuppressionV2":return[3,1];case"Where":return[3,5];case"ListDiff":return[3,7]}return[3,8];case 1:return r=h("boxes",t,e,n),i=h("scores",t,e,n),o=h("maxOutputSize",t,e,n),s=h("iouThreshold",t,e,n),c=h("scoreThreshold",t,e,n),"NonMaxSuppressionV5"!==t.op?[3,3]:(l=h("softNmsSigma",t,e,n),[4,a.image.nonMaxSuppressionWithScoreAsync(r,i,o,s,c,l)]);case 2:return[2,[(d=u.sent()).selectedIndices,d.selectedScores]];case 3:return[4,a.image.nonMaxSuppressionAsync(r,i,o,s,c)];case 4:return[2,[u.sent()]];case 5:return f=h("condition",t,e,n).asType("bool"),[4,Object(a.whereAsync)(f)];case 6:return d=[u.sent()],f.dispose(),[2,d];case 7:return[2,Object(a.setdiff1dAsync)(h("x",t,e,n),h("y",t,e,n))];case 8:throw TypeError("Node type "+t.op+" is not implemented")}})})},rt=function(t,e,n){switch(t.op){case"TopKV2":var r=h("x",t,e,n),i=h("k",t,e,n),o=h("sorted",t,e,n),s=Object(a.topk)(r,i,o);return[s.values,s.indices];default:throw TypeError("Node type "+t.op+" is not implemented")}},it=function(t,e,n){switch(t.op){case"Const":return e[t.name];case"PlaceholderWithDefault":var r=h("default",t,e,n);return[p(t.name,e,n)||r];case"Placeholder":return[p(t.name,e,n)];case"Identity":case"StopGradient":case"FakeQuantWithMinMaxVars":return[h("x",t,e,n).clone()];case"IdentityN":return h("x",t,e,n).map(function(t){return t.clone()});case"Snapshot":return[h("x",t,e,n).clone()];case"Shape":return[Object(a.tensor1d)(h("x",t,e,n).shape,"int32")];case"ShapeN":return h("x",t,e,n).map(function(t){return Object(a.tensor1d)(t.shape)});case"Size":return[Object(a.scalar)(h("x",t,e,n).size,"int32")];case"Rank":return[Object(a.scalar)(h("x",t,e,n).rank,"int32")];case"NoOp":return[Object(a.scalar)(1)];case"Print":var i=h("x",t,e,n),o=h("data",t,e,n),s=h("message",t,e,n),u=h("summarize",t,e,n);console.warn("The graph has a tf.print() operation,usually used for debugging, which slows down performance."),console.log(s);for(var c=0;c<o.length;c++)console.log(Array.prototype.slice.call(o[c].dataSync()).slice(0,u));return[i];default:throw TypeError("Node type "+t.op+" is not implemented")}},at=function(t,e,n){switch(t.op){case"ResizeBilinear":var r=h("images",t,e,n),i=h("size",t,e,n),o=h("alignCorners",t,e,n);return[a.image.resizeBilinear(r,[i[0],i[1]],o)];case"ResizeNearestNeighbor":return r=h("images",t,e,n),i=h("size",t,e,n),o=h("alignCorners",t,e,n),[a.image.resizeNearestNeighbor(r,[i[0],i[1]],o)];case"CropAndResize":var s=h("image",t,e,n),u=h("boxes",t,e,n),c=h("boxInd",t,e,n),l=h("cropSize",t,e,n),f=h("method",t,e,n),d=h("extrapolationValue",t,e,n);return[a.image.cropAndResize(s,u,c,l,f,d)];default:throw TypeError("Node type "+t.op+" is not implemented")}},ot=function(t,e,n){switch(t.op){case"Equal":return[Object(a.equal)(h("a",t,e,n),h("b",t,e,n))];case"NotEqual":return[Object(a.notEqual)(h("a",t,e,n),h("b",t,e,n))];case"Greater":return[Object(a.greater)(h("a",t,e,n),h("b",t,e,n))];case"GreaterEqual":return[Object(a.greaterEqual)(h("a",t,e,n),h("b",t,e,n))];case"Less":return[Object(a.less)(h("a",t,e,n),h("b",t,e,n))];case"LessEqual":return[Object(a.lessEqual)(h("a",t,e,n),h("b",t,e,n))];case"LogicalAnd":return[Object(a.logicalAnd)(h("a",t,e,n),h("b",t,e,n))];case"LogicalNot":return[Object(a.logicalNot)(h("a",t,e,n))];case"LogicalOr":return[Object(a.logicalOr)(h("a",t,e,n),h("b",t,e,n))];case"Select":return[Object(a.where)(h("condition",t,e,n),h("a",t,e,n),h("b",t,e,n))];default:throw TypeError("Node type "+t.op+" is not implemented")}},st=function(t,e,n){switch(t.op){case"BatchMatMul":case"BatchMatMulV2":case"MatMul":return[Object(a.matMul)(h("a",t,e,n),h("b",t,e,n),h("transposeA",t,e,n),h("transposeB",t,e,n))];case"Transpose":return[Object(a.transpose)(h("x",t,e,n),h("perm",t,e,n))];case"_FusedMatMul":var r=h("fusedOps",t,e,n),i=r[0],o=r[1],s="biasadd"===i,u="prelu"===o,c=h("numArgs",t,e,n);if(s){if(u&&2!==c)throw new Error("Fused MatMul with BiasAdd and Prelu must have two extra arguments: bias and alpha.");if(!u&&1!==c)throw new Error("Fused MatMul with BiasAdd must have one extra argument: bias.")}var l=h("args",t,e,n),f=l[0],d=l[1];return[a.fused.matMul({a:h("a",t,e,n),b:h("b",t,e,n),transposeA:h("transposeA",t,e,n),transposeB:h("transposeB",t,e,n),bias:f,activation:o,preluActivationWeights:d})];default:throw TypeError("Node type "+t.op+" is not implemented")}},ut=function(t,e,n){switch(t.op){case"FusedBatchNorm":case"FusedBatchNormV2":case"FusedBatchNormV3":return[Object(a.batchNorm)(h("x",t,e,n),h("mean",t,e,n),h("variance",t,e,n),h("offset",t,e,n),h("scale",t,e,n),h("epsilon",t,e,n))];case"LRN":return[Object(a.localResponseNormalization)(h("x",t,e,n),h("radius",t,e,n),h("bias",t,e,n),h("alpha",t,e,n),h("beta",t,e,n))];case"Softmax":return[Object(a.softmax)(h("x",t,e,n))];case"LogSoftmax":return[Object(a.logSoftmax)(h("x",t,e,n))];case"SparseToDense":return[Object(a.sparseToDense)(h("sparseIndices",t,e,n),h("outputShape",t,e,n),h("sparseValues",t,e,n),h("defaultValue",t,e,n))];default:throw TypeError("Node type "+t.op+" is not implemented")}},ct=function(t,e,n){switch(t.op){case"Max":var r=h("axis",t,e,n),i=h("keepDims",t,e,n);return[Object(a.max)(h("x",t,e,n),r,i)];case"Mean":return r=h("axis",t,e,n),i=h("keepDims",t,e,n),[Object(a.mean)(h("x",t,e,n),r,i)];case"Min":return r=h("axis",t,e,n),i=h("keepDims",t,e,n),[Object(a.min)(h("x",t,e,n),r,i)];case"Sum":return r=h("axis",t,e,n),i=h("keepDims",t,e,n),[Object(a.sum)(h("x",t,e,n),r,i)];case"All":return r=h("axis",t,e,n),i=h("keepDims",t,e,n),[Object(a.all)(h("x",t,e,n),r,i)];case"Any":return r=h("axis",t,e,n),i=h("keepDims",t,e,n),[Object(a.any)(h("x",t,e,n),r,i)];case"ArgMax":return r=h("axis",t,e,n),[Object(a.argMax)(h("x",t,e,n),r)];case"ArgMin":return r=h("axis",t,e,n),[Object(a.argMin)(h("x",t,e,n),r)];case"Prod":return r=h("axis",t,e,n),i=h("keepDims",t,e,n),[Object(a.prod)(h("x",t,e,n),r,i)];default:throw TypeError("Node type "+t.op+" is not implemented")}},lt=function(t,e,n){switch(t.op){case"ConcatV2":case"Concat":var r=h("n",t,e,n),i=h("axis",t,e,n),o=h("tensors",t,e,n);return o=o.slice(0,r),[Object(a.concat)(o,i)];case"GatherV2":case"Gather":i=h("axis",t,e,n);var s=h("x",t,e,n),u=h("indices",t,e,n);return[Object(a.gather)(s,u.asType("int32"),i)];case"ReverseV2":case"Reverse":return i=h("axis",t,e,n),s=h("x",t,e,n),[Object(a.reverse)(s,i)];case"Slice":var c=h("begin",t,e,n),l=h("size",t,e,n);return[Object(a.slice)(h("x",t,e,n),c,l)];case"StridedSlice":c=h("begin",t,e,n);var f=h("end",t,e,n),d=h("strides",t,e,n),p=h("beginMask",t,e,n),m=h("endMask",t,e,n),g=h("ellipsisMask",t,e,n),v=h("newAxisMask",t,e,n),y=h("shrinkAxisMask",t,e,n),b=h("x",t,e,n);if(1===c.length&&b.shape.length>1)for(var x=1;x<b.shape.length;x++)c.push(0),f.push(b.shape[x]),d.push(d[0]);return[Object(a.stridedSlice)(b,c,f,d,p,m,g,v,y)];case"Pack":return Object(a.tidy)(function(){var r=h("axis",t,e,n),i=h("tensors",t,e,n),o=i[0].shape,s=i[0].squeeze().shape,u=i.map(function(t){var e=a.util.arraysEqual(t.shape,o);if(!e&&!a.util.arraysEqual(t.squeeze().shape,s))throw new Error("the input tensors shape does not match");return e?t:t.reshape(o)});return[Object(a.stack)(u,r)]});case"Unpack":return Object(a.tidy)(function(){var r=h("axis",t,e,n),i=h("tensor",t,e,n);return Object(a.unstack)(i,r)});case"Tile":var w=h("reps",t,e,n);return[Object(a.tile)(h("x",t,e,n),w)];case"Split":case"SplitV":i=h("axis",t,e,n);var k=h("numOrSizeSplits",t,e,n);return Object(a.split)(h("x",t,e,n),k,i);case"ScatterNd":u=h("indices",t,e,n);var _=h("values",t,e,n),E=h("shape",t,e,n);return[Object(a.scatterND)(u,_,E)];case"GatherNd":var O=h("x",t,e,n);return u=h("indices",t,e,n),[Object(a.gatherND)(O,u)];case"SparseToDense":u=h("sparseIndices",t,e,n),E=h("outputShape",t,e,n);var S=h("sparseValues",t,e,n),C=h("defaultValue",t,e,n);return[Object(a.sparseToDense)(u,S,E,S.dtype===C.dtype?C:C.asType(S.dtype))];default:throw TypeError("Node type "+t.op+" is not implemented")}},ft=function(t,e,n){switch(t.op){case"FFT":return[Object(a.fft)(h("x",t,e,n))];case"IFFT":return[Object(a.ifft)(h("x",t,e,n))];case"RFFT":return[Object(a.rfft)(h("x",t,e,n))];case"IRFFT":return[Object(a.irfft)(h("x",t,e,n))];default:throw TypeError("Node type "+t.op+" is not implemented")}},dt=function(t,e,n){switch(t.op){case"Cast":return[Object(a.cast)(h("x",t,e,n),h("dtype",t,e,n))];case"ExpandDims":var r=h("axis",t,e,n);return[Object(a.expandDims)(h("x",t,e,n),r)];case"Squeeze":return r=h("axis",t,e,n),[Object(a.squeeze)(h("x",t,e,n),r)];case"Reshape":return[Object(a.reshape)(h("x",t,e,n),h("shape",t,e,n))];case"PadV2":case"Pad":return[Object(a.pad)(h("x",t,e,n),y(h("padding",t,e,n),2),h("constantValue",t,e,n))];case"SpaceToBatchND":var i=h("blockShape",t,e,n),o=y(h("paddings",t,e,n),2);return[Object(a.spaceToBatchND)(h("x",t,e,n),i,o)];case"BatchToSpaceND":i=h("blockShape",t,e,n);var s=y(h("crops",t,e,n),2);return[Object(a.batchToSpaceND)(h("x",t,e,n),i,s)];case"DepthToSpace":var u=h("blockSize",t,e,n),c=h("dataFormat",t,e,n).toUpperCase();return[Object(a.depthToSpace)(h("x",t,e,n),u,c)];default:throw TypeError("Node type "+t.op+" is not implemented")}};function ht(t,e,n){var r=function(t,e,n){switch(t.category){case"arithmetic":return Object(a.tidy)(function(){return Y(t,e,n)});case"basic_math":return Object(a.tidy)(function(){return J(t,e,n)});case"control":return Q(t,e,n);case"convolution":return Object(a.tidy)(function(){return tt(t,e,n)});case"creation":return Object(a.tidy)(function(){return et(t,e,n)});case"dynamic":return nt(t,e,n);case"evaluation":return Object(a.tidy)(function(){return rt(t,e,n)});case"image":return Object(a.tidy)(function(){return at(t,e,n)});case"graph":return Object(a.tidy)(function(){return it(t,e,n)});case"logical":return Object(a.tidy)(function(){return ot(t,e,n)});case"matrices":return Object(a.tidy)(function(){return st(t,e,n)});case"normalization":return Object(a.tidy)(function(){return ut(t,e,n)});case"reduction":return Object(a.tidy)(function(){return ct(t,e,n)});case"slice_join":return Object(a.tidy)(function(){return lt(t,e,n)});case"spectral":return Object(a.tidy)(function(){return ft(t,e,n)});case"transformation":return Object(a.tidy)(function(){return dt(t,e,n)});case"custom":var r=f(t.op);if(r&&r.customExecutor)return r.customExecutor(new X(t,e,n));throw TypeError("Custom op "+t.op+" is not registered.");default:throw TypeError("Unknown op '"+t.op+"'. File an issue at https://github.com/tensorflow/tfjs/issues so we can add it, or register a custom execution with tf.registerOp()")}}(t,e,n);return r instanceof Promise?r.then(function(t){return[].concat(t)}):[].concat(r)}var pt=function(){function t(t,e){this.weightMap=t,this.tensorArrayMap=e,this.rootContext={id:0,frameName:"",iterationId:0},this.contexts=[this.rootContext],this.lastId=0,this.generateCurrentContextIds()}return t.prototype.newFrame=function(t,e){return{id:t,frameName:e,iterationId:0}},Object.defineProperty(t.prototype,"currentContext",{get:function(){return this.contexts},set:function(t){this.contexts!==t&&(this.contexts=t,this.generateCurrentContextIds())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"currentContextId",{get:function(){return this._currentContextIds[0]},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"currentContextIds",{get:function(){return this._currentContextIds},enumerable:!0,configurable:!0}),t.prototype.generateCurrentContextIds=function(){for(var t=[],e=0;e<this.contexts.length-1;e++){var n=this.contexts.slice(0,this.contexts.length-e);t.push(this.contextIdforContexts(n))}t.push(""),this._currentContextIds=t},t.prototype.contextIdforContexts=function(t){return t?t.map(function(t){return 0===t.id&&0===t.iterationId?"":t.frameName+"-"+t.iterationId}).join("/"):""},t.prototype.enterFrame=function(t){this.contexts&&(this.lastId++,this.contexts=this.contexts.slice(),this.contexts.push(this.newFrame(this.lastId,t)),this._currentContextIds.unshift(this.contextIdforContexts(this.contexts)))},t.prototype.exitFrame=function(){if(!(this.contexts&&this.contexts.length>1))throw new Error("Cannot exit frame, the context is empty");this.contexts=this.contexts.slice(),this.contexts.splice(-1),this.currentContextIds.shift()},t.prototype.nextIteration=function(){if(!(this.contexts&&this.contexts.length>0))throw new Error("Cannot increase frame iteration, the context is empty");this.contexts=this.contexts.slice(),this.lastId++;var t=Object.assign({},this.contexts[this.contexts.length-1]);t.iterationId+=1,t.id=this.lastId,this.contexts.splice(-1,1,t),this._currentContextIds.splice(0,1,this.contextIdforContexts(this.contexts))},t.prototype.getWeight=function(t){return this.weightMap[t]},t.prototype.addTensorArray=function(t){this.tensorArrayMap[t.id]=t},t.prototype.getTensorArray=function(t){return this.tensorArrayMap[t]},t}();function mt(t,e,n){for(var r=new Set,i=[],a=null,o=null,s=new Set,u=Object.keys(t).map(function(t){return v(t)[0]}),c=e.slice();c.length>0;){var l=c.pop();(yt(l)||bt(l))&&null==a&&(o=(a=l).children.map(function(t){return t.name}).filter(function(t){return r.has(t)})),r.add(l.name),null==n[l.name]&&-1===u.indexOf(l.name)&&(0!==l.inputs.length?l.inputs.forEach(function(t){s.has(t.name)||(s.add(t.name),c.push(t))}):i.push(l.name))}return{inputs:t,outputs:e,usedNodes:r,missingInputs:i,dynamicNode:a,syncInputs:o}}var gt=["Switch","Merge","Enter","Exit","NextIteration"],vt=["NonMaxSuppressionV2","NonMaxSuppressionV3","NonMaxSuppressionV5","Where"];function yt(t){return gt.indexOf(t.op)>=0}function bt(t){return vt.indexOf(t.op)>=0}var xt=function(){function t(t){this.graph=t,this.compiledMap=new Map,this._weightMap={},this.SEPERATOR=",",this._outputs=t.outputs,this._inputs=t.inputs,this._signature=t.signature}return Object.defineProperty(t.prototype,"weightMap",{get:function(){return this._weightMap},set:function(t){var e=Object.keys(t).map(function(e){return t[e].map(function(t){return t.id})});this.weightIds=[].concat.apply([],e),this._weightMap=t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"inputs",{get:function(){return this._inputs.map(function(t){return{name:t.name,shape:t.attrParams.shape?t.attrParams.shape.value:void 0,dtype:t.attrParams.dtype?t.attrParams.dtype.value:void 0}})},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"outputs",{get:function(){return this._outputs.map(function(t){return{name:t.name,shape:t.attrParams.shape?t.attrParams.shape.value:void 0,dtype:t.attrParams.dtype?t.attrParams.dtype.value:void 0}})},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"inputNodes",{get:function(){return this._inputs.map(function(t){return t.signatureKey||t.name})},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"outputNodes",{get:function(){return this._outputs.map(function(t){return t.signatureKey||t.name})},enumerable:!0,configurable:!0}),t.prototype.getCompilationKey=function(t,e){var n=t.map(function(t){return t.name}).sort(),r=e.map(function(t){return t.name}).sort();return n.join(this.SEPERATOR)+"--"+r.join(this.SEPERATOR)},t.prototype.compile=function(t,e){var n=mt(t,e,this.weightMap),r=n.missingInputs,i=n.dynamicNode,a=n.syncInputs;if(null!=i)throw new Error("This execution contains the node '"+i.name+"', which has the dynamic op '"+i.op+"'. Please use model.executeAsync() instead. Alternatively, to avoid the dynamic ops, specify the inputs ["+a+"]");if(r.length>0){var o=e.map(function(t){return t.name}),s=Object.keys(t);throw new Error("Cannot compute the outputs ["+o+"] from the provided inputs ["+s+"]. Missing the following inputs: ["+r+"]")}return function(t,e,n){var r=n.usedNodes,i=n.inputs,a=[];Object.keys(i).map(function(t){return v(t)[0]}).map(function(e){return t.nodes[e]}).forEach(function(t){r.has(t.name)&&a.push(t)}),t.weights.forEach(function(t){r.has(t.name)&&a.push(t)});for(var o=new Set,s=[];a.length>0;){var u=a.pop();o.add(u.name),e[u.name]||s.push(u),u.children.forEach(function(t){!o.has(t.name)&&r.has(t.name)&&t.inputs.every(function(t){return o.has(t.name)})&&a.push(t)})}return s}(this.graph,this.weightMap,n)},t.prototype.execute=function(t,e){var n=this;t=this.mapInputs(t);var r=Object.keys(t).sort();this.checkInputs(t),this.checkInputShapeAndType(t),e=this.mapOutputs(e),this.checkOutputs(e);var i=r.map(function(t){return n.graph.nodes[v(t)[0]]}),s=e.map(function(t){return n.graph.nodes[v(t)[0]]}),u=this.getCompilationKey(i,s),c=this.compiledMap.get(u);null==c&&(c=this.compile(t,s),this.compiledMap.set(u,c));var l={};return Object(a.tidy)(function(){var r=new pt(n._weightMap,l),i=o({},n.weightMap);Object.keys(t).forEach(function(e){var n=v(e),r=n[0],a=[];a[n[1]]=t[e],i[r]=a});for(var a=n.getFrozenTensorIds(i),s={},u=0;u<c.length;u++){var f=c[u];if(!i[f.name]){var d=ht(f,i,r);if(d instanceof Promise)throw new Error("The execution of the op '"+f.op+"' returned a promise. Please use model.executeAsync() instead.");i[f.name]=d,n.checkTensorForDisposal(f.name,f,i,r,a,e,s)}}return e.map(function(t){return p(t,i,r)})})},t.prototype.getFrozenTensorIds=function(t){var e=[].concat.apply([],Object.keys(t).map(function(e){return t[e]}).map(function(t){return t.map(function(t){return t.id})}));return new Set(e)},t.prototype.checkTensorForDisposal=function(t,e,n,r,i,a,o){"control"!==e.category&&-1===a.indexOf(t)&&(n[t].forEach(function(t){null!=t&&(o[t.id]=(o[t.id]||0)+e.children.length)}),e.inputs.forEach(function(t){if("control"!==t.category){var e=function(t,e,n){return e[g(t,n.currentContextId)]}(t.name,n,r);null!=e&&e.forEach(function(t){if(t&&!i.has(t.id)){var e=o[t.id];1===e?(t.dispose(),delete o[t.id]):null!=e&&o[t.id]--}})}}))},t.prototype.executeAsync=function(t,e){return s(this,void 0,void 0,function(){var n,r,i,a,o,s,c=this;return u(this,function(u){switch(u.label){case 0:return t=this.mapInputs(t),this.checkInputs(t),this.checkInputShapeAndType(t),e=this.mapOutputs(e),this.checkOutputs(e),n={},r=new pt(this._weightMap,n),[4,this.executeWithControlFlow(t,r,e)];case 1:return i=u.sent(),a=e.map(function(t){return p(t,i,r)}),o=new Set(a.map(function(t){return t.id})),s=new Set(Object.keys(t).map(function(e){return t[e].id})),Object.keys(i).forEach(function(t){i[t].forEach(function(t){!t||t.isDisposed||o.has(t.id)||s.has(t.id)||-1!==c.weightIds.indexOf(t.id)||t.dispose()})}),[2,a]}})})},t.prototype.executeWithControlFlow=function(t,e,n){return s(this,void 0,void 0,function(){var r,i,a,s,c,l,f,d,h,m,g,y,b,x,w,k,_=this;return u(this,function(u){switch(u.label){case 0:r=Object.keys(t),i=r.map(function(t){return _.graph.nodes[v(t)[0]]}),a=n.map(function(t){return _.graph.nodes[v(t)[0]]}),s=mt(t,a,this.weightMap),c=s.usedNodes,l=s.missingInputs,f=s.dynamicNode,d=s.syncInputs,h=i.concat(this.graph.weights).map(function(t){return{node:t,contexts:e.currentContext}}),m=o({},this.weightMap),Object.keys(t).forEach(function(e){var n=v(e),r=n[0],i=[];i[n[1]]=t[e],m[r]=i}),g={},y=this.getFrozenTensorIds(m),b={},u.label=1;case 1:return h.length>0?(x=this.processStack(i,h,e,m,b,y,n,g,c),[4,Promise.all(x)]):[3,3];case 2:return u.sent(),[3,1];case 3:if(null==f&&console.warn("This model execution did not contain any nodes with control flow or dynamic output shapes. You can use model.execute() instead."),(w=a.filter(function(t){return!yt(t)&&!p(t.name,m,e)}).map(function(t){return t.name})).length>0)throw k="",null!=f&&(k="Alternatively, to avoid the dynamic ops, use model.execute() and specify the inputs ["+d+"]"),new Error("Cannot compute the outputs ["+w+"] from the provided inputs ["+r+"]. Consider providing the following inputs: ["+l+"]. "+k);return[2,m]}})})},t.prototype.processStack=function(t,e,n,r,i,a,o,s,u){for(var c=this,l=[],f=function(){var f=e.pop();n.currentContext=f.contexts;var p="";if("Enter"===f.node.op&&h("isConstant",f.node,r,n)&&(p=m(f.node.name,n)[0]),-1===t.indexOf(f.node)){var g=ht(f.node,r,n);p||(p=m(f.node.name,n)[0]);var v=n.currentContext;g instanceof Promise?l.push(g.then(function(t){return r[p]=t,n.currentContext=v,c.checkTensorForDisposal(p,f.node,r,n,a,o,s),c.processChildNodes(f.node,e,n,r,i,u),t})):(r[p]=g,d.checkTensorForDisposal(p,f.node,r,n,a,o,s),d.processChildNodes(f.node,e,n,r,i,u))}else d.processChildNodes(f.node,e,n,r,i,u)},d=this;e.length>0;)f();return l},t.prototype.processChildNodes=function(t,e,n,r,i,a){t.children.forEach(function(t){var o=m(t.name,n)[0];!i[o]&&a.has(t.name)&&("Merge"===t.op?t.inputNames.some(function(t){return!!p(t,r,n)})&&(i[o]=!0,e.push({contexts:n.currentContext,node:t})):t.inputNames.every(function(t){return!!p(t,r,n)})&&(i[o]=!0,e.push({contexts:n.currentContext,node:t})))})},t.prototype.dispose=function(){var t=this;Object.keys(this.weightMap).forEach(function(e){return t.weightMap[e].forEach(function(t){return t.dispose()})})},t.prototype.checkInputShapeAndType=function(t){var e=this;Object.keys(t).forEach(function(n){var r=t[n],i=v(n)[0],o=e.graph.nodes[i];if(o.attrParams.shape&&o.attrParams.shape.value){var s=o.attrParams.shape.value,u=s.length===r.shape.length&&r.shape.every(function(t,e){return-1===s[e]||s[e]===t});a.util.assert(u,function(){return"The shape of dict['"+o.name+"'] provided in model.execute(dict) must be ["+s+"], but was ["+r.shape+"]"})}o.attrParams.dtype&&o.attrParams.dtype.value&&a.util.assert(r.dtype===o.attrParams.dtype.value,function(){return"The dtype of dict['"+o.name+"'] provided in model.execute(dict) must be "+o.attrParams.dtype.value+", but was "+r.dtype})})},t.prototype.mapInputs=function(t){var e={};for(var n in t)null!=this._signature&&null!=this._signature.inputs&&null!=this._signature.inputs[n]?e[this._signature.inputs[n].name]=t[n]:e[n]=t[n];return e},t.prototype.checkInputs=function(t){var e=this,n=Object.keys(t).filter(function(t){var n=v(t)[0];return null==e.graph.nodes[n]});if(n.length>0)throw new Error("The dict provided in model.execute(dict) has keys: ["+n+"] that are not part of graph")},t.prototype.mapOutputs=function(t){var e=this;return t.map(function(t){return null!=e._signature&&null!=e._signature.outputs&&null!=e._signature.outputs[t]?e._signature.outputs[t].name:t},{})},t.prototype.checkOutputs=function(t){var e=this;t.forEach(function(t){var n=v(t)[0];if(!e.graph.nodes[n])throw new Error("The output '"+t+"' is not found in the graph")})},t}(),wt="?tfjs-format=file",kt="model.json",_t=function(){function t(t,e){void 0===e&&(e={}),this.modelUrl=t,this.loadOptions=e,this.version="n/a",null==e&&(this.loadOptions={})}return Object.defineProperty(t.prototype,"modelVersion",{get:function(){return this.version},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"inputNodes",{get:function(){return this.executor.inputNodes},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"outputNodes",{get:function(){return this.executor.outputNodes},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"inputs",{get:function(){return this.executor.inputs},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"outputs",{get:function(){return this.executor.outputs},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"weights",{get:function(){return this.executor.weightMap},enumerable:!0,configurable:!0}),t.prototype.findIOHandler=function(){var t=this.modelUrl;if(null!=t.load)this.handler=t;else if(null!=this.loadOptions.requestInit)this.handler=a.io.browserHTTPRequest(t,this.loadOptions);else{var e=a.io.getLoadHandlers(t,this.loadOptions.onProgress);if(0===e.length)e.push(a.io.browserHTTPRequest(t,this.loadOptions));else if(e.length>1)throw new Error("Found more than one ("+e.length+") load handlers for URL '"+[t]+"'");this.handler=e[0]}},t.prototype.load=function(){return s(this,void 0,void 0,function(){var t,e,n,r;return u(this,function(i){switch(i.label){case 0:if(this.findIOHandler(),null==this.handler.load)throw new Error("Cannot proceed with model loading because the IOHandler provided does not have the `load` method implemented.");return t=this,[4,this.handler.load()];case 1:return t.artifacts=i.sent(),e=this.artifacts.modelTopology,n={},null!=this.artifacts.userDefinedMetadata&&(n=this.artifacts.userDefinedMetadata.signature),this.version=e.versions.producer+"."+e.versions.minConsumer,r=a.io.decodeWeights(this.artifacts.weightData,this.artifacts.weightSpecs),this.executor=new xt(F.Instance.transformGraph(e,n)),this.executor.weightMap=this.convertTensorMapToTensorsMap(r),[2,!0]}})})},t.prototype.save=function(t,e){return s(this,void 0,void 0,function(){var e;return u(this,function(n){if("string"==typeof t){if(0===(e=a.io.getSaveHandlers(t)).length)throw new Error("Cannot find any save handlers for URL '"+t+"'");if(e.length>1)throw new Error("Found more than one ("+e.length+") save handlers for URL '"+t+"'");t=e[0]}if(null==t.save)throw new Error("GraphModel.save() cannot proceed because the IOHandler provided does not have the `save` attribute defined.");return[2,t.save(this.artifacts)]})})},t.prototype.predict=function(t,e){return this.execute(t,this.outputNodes)},t.prototype.normalizeInputs=function(t){if(!(t instanceof a.Tensor||Array.isArray(t)))return t;if((t=Array.isArray(t)?t:[t]).length!==this.inputNodes.length)throw new Error("Input tensor count mismatch,the graph model has "+this.inputNodes.length+" placeholders, while there are "+t.length+" input tensors.");return this.inputNodes.reduce(function(e,n,r){return e[n]=t[r],e},{})},t.prototype.normalizeOutputs=function(t){return t=t||this.outputNodes,Array.isArray(t)?t:[t]},t.prototype.execute=function(t,e){t=this.normalizeInputs(t),e=this.normalizeOutputs(e);var n=this.executor.execute(t,e);return n.length>1?n:n[0]},t.prototype.executeAsync=function(t,e){return s(this,void 0,void 0,function(){var n;return u(this,function(r){switch(r.label){case 0:return t=this.normalizeInputs(t),e=this.normalizeOutputs(e),[4,this.executor.executeAsync(t,e)];case 1:return[2,(n=r.sent()).length>1?n:n[0]]}})})},t.prototype.convertTensorMapToTensorsMap=function(t){return Object.keys(t).reduce(function(e,n){return e[n]=[t[n]],e},{})},t.prototype.dispose=function(){this.executor.dispose()},t}();function Et(t,e){return void 0===e&&(e={}),s(this,void 0,void 0,function(){var n;return u(this,function(r){switch(r.label){case 0:if(null==t)throw new Error("modelUrl in loadGraphModel() cannot be null. Please provide a url or an IOHandler that loads the model");return null==e&&(e={}),e.fromTFHub&&null==t.load&&(t.endsWith("/")||(t+="/"),t=""+t+kt+wt),[4,(n=new _t(t,e)).load()];case 1:return r.sent(),[2,n]}})})}var Ot="1.7.2"}).call(this,n(86).Buffer)},function(t,e,n){var r=n(6),i=n(282),a=n(52),o=Object.defineProperty;e.f=n(19)?Object.defineProperty:function(t,e,n){if(r(t),e=a(e,!0),r(n),i)try{return o(t,e,n)}catch(t){}if("get"in n||"set"in n)throw TypeError("Accessors not supported!");return"value"in n&&(t[e]=n.value),t}},function(t,e,n){var r=n(51);t.exports=function(t){return Object(r(t))}},function(t,e,n){var r=n(26),i=n(18),a=n(56),o=n(60),s=n(68),u=function(t,e,n){var c,l,f,d=t&u.F,h=t&u.G,p=t&u.S,m=t&u.P,g=t&u.B,v=t&u.W,y=h?i:i[e]||(i[e]={}),b=y.prototype,x=h?r:p?r[e]:(r[e]||{}).prototype;for(c in h&&(n=e),n)(l=!d&&x&&void 0!==x[c])&&s(y,c)||(f=l?x[c]:n[c],y[c]=h&&"function"!=typeof x[c]?n[c]:g&&l?a(f,r):v&&x[c]==f?function(t){var e=function(e,n,r){if(this instanceof t){switch(arguments.length){case 0:return new t;case 1:return new t(e);case 2:return new t(e,n)}return new t(e,n,r)}return t.apply(this,arguments)};return e.prototype=t.prototype,e}(f):m&&"function"==typeof f?a(Function.call,f):f,m&&((y.virtual||(y.virtual={}))[c]=f,t&u.R&&b&&!b[c]&&o(b,c,f)))};u.F=1,u.G=2,u.S=4,u.P=8,u.B=16,u.W=32,u.U=64,u.R=128,t.exports=u},function(t,e,n){t.exports={default:n(425),__esModule:!0}},function(t,e,n){var r=n(159)("wks"),i=n(121),a=n(26).Symbol,o="function"==typeof a;(t.exports=function(t){return r[t]||(r[t]=o&&a[t]||(o?a:i)("Symbol."+t))}).store=r},function(t,e){var n=t.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=n)},function(t,e){t.exports=function(t){if("function"!=typeof t)throw TypeError(t+" is not a function!");return t}},function(t,e,n){"use strict";var r=n(218),i=Object.prototype.toString;function a(t){return"[object Array]"===i.call(t)}function o(t){return void 0===t}function s(t){return null!==t&&"object"==typeof t}function u(t){return"[object Function]"===i.call(t)}function c(t,e){if(null!==t&&void 0!==t)if("object"!=typeof t&&(t=[t]),a(t))for(var n=0,r=t.length;n<r;n++)e.call(null,t[n],n,t);else for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.call(null,t[i],i,t)}t.exports={isArray:a,isArrayBuffer:function(t){return"[object ArrayBuffer]"===i.call(t)},isBuffer:function(t){return null!==t&&!o(t)&&null!==t.constructor&&!o(t.constructor)&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)},isFormData:function(t){return"undefined"!=typeof FormData&&t instanceof FormData},isArrayBufferView:function(t){return"undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(t):t&&t.buffer&&t.buffer instanceof ArrayBuffer},isString:function(t){return"string"==typeof t},isNumber:function(t){return"number"==typeof t},isObject:s,isUndefined:o,isDate:function(t){return"[object Date]"===i.call(t)},isFile:function(t){return"[object File]"===i.call(t)},isBlob:function(t){return"[object Blob]"===i.call(t)},isFunction:u,isStream:function(t){return s(t)&&u(t.pipe)},isURLSearchParams:function(t){return"undefined"!=typeof URLSearchParams&&t instanceof URLSearchParams},isStandardBrowserEnv:function(){return("undefined"==typeof navigator||"ReactNative"!==navigator.product&&"NativeScript"!==navigator.product&&"NS"!==navigator.product)&&"undefined"!=typeof window&&"undefined"!=typeof document},forEach:c,merge:function t(){var e={};function n(n,r){"object"==typeof e[r]&&"object"==typeof n?e[r]=t(e[r],n):e[r]=n}for(var r=0,i=arguments.length;r<i;r++)c(arguments[r],n);return e},deepMerge:function t(){var e={};function n(n,r){"object"==typeof e[r]&&"object"==typeof n?e[r]=t(e[r],n):e[r]="object"==typeof n?t({},n):n}for(var r=0,i=arguments.length;r<i;r++)c(arguments[r],n);return e},extend:function(t,e,n){return c(e,function(e,i){t[i]=n&&"function"==typeof e?r(e,n):e}),t},trim:function(t){return t.replace(/^\s*/,"").replace(/\s*$/,"")}}},function(t,e,n){var r=n(5),i=n(12),a=n(51),o=/"/g,s=function(t,e,n,r){var i=String(a(t)),s="<"+e;return""!==n&&(s+=" "+n+'="'+String(r).replace(o,"&quot;")+'"'),s+">"+i+"</"+e+">"};t.exports=function(t,e){var n={};n[t]=e(s),r(r.P+r.F*i(function(){var e=""[t]('"');return e!==e.toLowerCase()||e.split('"').length>3}),"String",n)}},function(t,e,n){var r=n(11),i=n(31),a=n(36),o=n(79)("src"),s=n(689),u=(""+s).split("toString");n(44).inspectSource=function(t){return s.call(t)},(t.exports=function(t,e,n,s){var c="function"==typeof n;c&&(a(n,"name")||i(n,"name",e)),t[e]!==n&&(c&&(a(n,o)||i(n,o,t[e]?""+t[e]:u.join(String(e)))),t===r?t[e]=n:s?t[e]?t[e]=n:i(t,e,n):(delete t[e],i(t,e,n)))})(Function.prototype,"toString",function(){return"function"==typeof this&&this[o]||s.call(this)})},function(t,e,n){var r=n(21),i=n(80);t.exports=n(19)?function(t,e,n){return r.f(t,e,i(1,n))}:function(t,e,n){return t[e]=n,t}},function(t,e,n){t.exports=!n(69)(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},function(t,e,n){var r=n(36),i=n(22),a=n(190)("IE_PROTO"),o=Object.prototype;t.exports=Object.getPrototypeOf||function(t){return t=i(t),r(t,a)?t[a]:"function"==typeof t.constructor&&t instanceof t.constructor?t.constructor.prototype:t instanceof Object?o:null}},function(t,e,n){var r=n(112),i=n(80),a=n(35),o=n(52),s=n(36),u=n(282),c=Object.getOwnPropertyDescriptor;e.f=n(19)?c:function(t,e){if(t=a(t),e=o(e,!0),u)try{return c(t,e)}catch(t){}if(s(t,e))return i(!r.f.call(t,e),t[e])}},function(t,e,n){var r=n(113),i=n(51);t.exports=function(t){return r(i(t))}},function(t,e){var n={}.hasOwnProperty;t.exports=function(t,e){return n.call(t,e)}},function(t,e,n){"use strict";
  81. /**
  82. * @license
  83. * Copyright 2018 Google LLC. All Rights Reserved.
  84. * Licensed under the Apache License, Version 2.0 (the "License");
  85. * you may not use this file except in compliance with the License.
  86. * You may obtain a copy of the License at
  87. *
  88. * http://www.apache.org/licenses/LICENSE-2.0
  89. *
  90. * Unless required by applicable law or agreed to in writing, software
  91. * distributed under the License is distributed on an "AS IS" BASIS,
  92. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  93. * See the License for the specific language governing permissions and
  94. * limitations under the License.
  95. * =============================================================================
  96. */var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})};Object.defineProperty(e,"__esModule",{value:!0});const i=n(237),a=n(236);e.getDrawArea=function(t){if(t instanceof HTMLElement)return t;if(i.isSurface(t))return t.drawArea;if(i.isSurfaceInfo(t))return a.visor().surface({name:t.name,tab:t.tab,styles:t.styles}).drawArea;throw new Error("Not a drawable")},e.shallowEquals=function(t,e){const n=Object.getOwnPropertyNames(t),r=Object.getOwnPropertyNames(e);if(n.length!==r.length)return!1;for(let r=0;r<n.length;r++){const i=n[r];if(t[i]!==e[i])return!1}return!0},e.nextFrame=function(){return r(this,void 0,void 0,function*(){yield new Promise(t=>requestAnimationFrame(t))})}},function(t,e){t.exports=function(t){return"object"==typeof t?null!==t:"function"==typeof t}},function(t,e,n){var r=n(48),i=n(246),a=n(164),o=Object.defineProperty;e.f=n(32)?Object.defineProperty:function(t,e,n){if(r(t),e=a(e,!0),r(n),i)try{return o(t,e,n)}catch(t){}if("get"in n||"set"in n)throw TypeError("Accessors not supported!");return"value"in n&&(t[e]=n.value),t}},function(t,e,n){"use strict";var r=n(12);t.exports=function(t,e){return!!t&&r(function(){e?t.call(null,function(){},1):t.call(null)})}},function(t,e){var n=Math.ceil,r=Math.floor;t.exports=function(t){return isNaN(t=+t)?0:(t>0?r:n)(t)}},function(t,e){var n={}.toString;t.exports=function(t){return n.call(t).slice(8,-1)}},function(t,e,n){var r=n(27);t.exports=function(t,e,n){if(r(t),void 0===e)return t;switch(n){case 1:return function(n){return t.call(e,n)};case 2:return function(n,r){return t.call(e,n,r)};case 3:return function(n,r,i){return t.call(e,n,r,i)}}return function(){return t.apply(e,arguments)}}},function(t,e){var n=t.exports={version:"2.6.11"};"number"==typeof __e&&(__e=n)},function(t,e,n){"use strict";n.r(e);var r=function(t,e){if((n=(t=e?t.toExponential(e-1):t.toExponential()).indexOf("e"))<0)return null;var n,r=t.slice(0,n);return[r.length>1?r[0]+r.slice(2):r,+t.slice(n+1)]},i=function(t){return(t=r(Math.abs(t)))?t[1]:NaN},a=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function o(t){return new s(t)}function s(t){if(!(e=a.exec(t)))throw new Error("invalid format: "+t);var e;this.fill=e[1]||" ",this.align=e[2]||">",this.sign=e[3]||"-",this.symbol=e[4]||"",this.zero=!!e[5],this.width=e[6]&&+e[6],this.comma=!!e[7],this.precision=e[8]&&+e[8].slice(1),this.trim=!!e[9],this.type=e[10]||""}o.prototype=s.prototype,s.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(null==this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(null==this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};var u,c,l,f,d=function(t){t:for(var e,n=t.length,r=1,i=-1;r<n;++r)switch(t[r]){case".":i=e=r;break;case"0":0===i&&(i=r),e=r;break;default:if(i>0){if(!+t[r])break t;i=0}}return i>0?t.slice(0,i)+t.slice(e+1):t},h=function(t,e){var n=r(t,e);if(!n)return t+"";var i=n[0],a=n[1];return a<0?"0."+new Array(-a).join("0")+i:i.length>a+1?i.slice(0,a+1)+"."+i.slice(a+1):i+new Array(a-i.length+2).join("0")},p={"%":function(t,e){return(100*t).toFixed(e)},b:function(t){return Math.round(t).toString(2)},c:function(t){return t+""},d:function(t){return Math.round(t).toString(10)},e:function(t,e){return t.toExponential(e)},f:function(t,e){return t.toFixed(e)},g:function(t,e){return t.toPrecision(e)},o:function(t){return Math.round(t).toString(8)},p:function(t,e){return h(100*t,e)},r:h,s:function(t,e){var n=r(t,e);if(!n)return t+"";var i=n[0],a=n[1],o=a-(u=3*Math.max(-8,Math.min(8,Math.floor(a/3))))+1,s=i.length;return o===s?i:o>s?i+new Array(o-s+1).join("0"):o>0?i.slice(0,o)+"."+i.slice(o):"0."+new Array(1-o).join("0")+r(t,Math.max(0,e+o-1))[0]},X:function(t){return Math.round(t).toString(16).toUpperCase()},x:function(t){return Math.round(t).toString(16)}},m=function(t){return t},g=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"],v=function(t){var e=t.grouping&&t.thousands?function(t,e){return function(n,r){for(var i=n.length,a=[],o=0,s=t[0],u=0;i>0&&s>0&&(u+s+1>r&&(s=Math.max(1,r-u)),a.push(n.substring(i-=s,i+s)),!((u+=s+1)>r));)s=t[o=(o+1)%t.length];return a.reverse().join(e)}}(t.grouping,t.thousands):m,n=t.currency,r=t.decimal,a=t.numerals?function(t){return function(e){return e.replace(/[0-9]/g,function(e){return t[+e]})}}(t.numerals):m,s=t.percent||"%";function c(t){var i=(t=o(t)).fill,c=t.align,l=t.sign,f=t.symbol,h=t.zero,m=t.width,v=t.comma,y=t.precision,b=t.trim,x=t.type;"n"===x?(v=!0,x="g"):p[x]||(null==y&&(y=12),b=!0,x="g"),(h||"0"===i&&"="===c)&&(h=!0,i="0",c="=");var w="$"===f?n[0]:"#"===f&&/[boxX]/.test(x)?"0"+x.toLowerCase():"",k="$"===f?n[1]:/[%p]/.test(x)?s:"",_=p[x],E=/[defgprs%]/.test(x);function O(t){var n,o,s,f=w,p=k;if("c"===x)p=_(t)+p,t="";else{var O=(t=+t)<0;if(t=_(Math.abs(t),y),b&&(t=d(t)),O&&0==+t&&(O=!1),f=(O?"("===l?l:"-":"-"===l||"("===l?"":l)+f,p=("s"===x?g[8+u/3]:"")+p+(O&&"("===l?")":""),E)for(n=-1,o=t.length;++n<o;)if(48>(s=t.charCodeAt(n))||s>57){p=(46===s?r+t.slice(n+1):t.slice(n))+p,t=t.slice(0,n);break}}v&&!h&&(t=e(t,1/0));var S=f.length+t.length+p.length,C=S<m?new Array(m-S+1).join(i):"";switch(v&&h&&(t=e(C+t,C.length?m-p.length:1/0),C=""),c){case"<":t=f+t+p+C;break;case"=":t=f+C+t+p;break;case"^":t=C.slice(0,S=C.length>>1)+f+t+p+C.slice(S);break;default:t=C+f+t+p}return a(t)}return y=null==y?6:/[gprs]/.test(x)?Math.max(1,Math.min(21,y)):Math.max(0,Math.min(20,y)),O.toString=function(){return t+""},O}return{format:c,formatPrefix:function(t,e){var n=c(((t=o(t)).type="f",t)),r=3*Math.max(-8,Math.min(8,Math.floor(i(e)/3))),a=Math.pow(10,-r),s=g[8+r/3];return function(t){return n(a*t)+s}}}};function y(t){return c=v(t),l=c.format,f=c.formatPrefix,c}y({decimal:".",thousands:",",grouping:[3],currency:["$",""]});var b=function(t){return Math.max(0,-i(Math.abs(t)))},x=function(t,e){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(i(e)/3)))-i(Math.abs(t)))},w=function(t,e){return t=Math.abs(t),e=Math.abs(e)-t,Math.max(0,i(e)-i(t))+1};n.d(e,"formatDefaultLocale",function(){return y}),n.d(e,"format",function(){return l}),n.d(e,"formatPrefix",function(){return f}),n.d(e,"formatLocale",function(){return v}),n.d(e,"formatSpecifier",function(){return o}),n.d(e,"precisionFixed",function(){return b}),n.d(e,"precisionPrefix",function(){return x}),n.d(e,"precisionRound",function(){return w})},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.imgToPixelArray=e.flipImage=e.isInstanceOfSupportedElement=e.imgToTensor=e.cropImage=e.processVideo=e.array3DToImage=void 0;var r=u(n(47)),i=u(n(14)),a=u(n(65)),o=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(4)),s=u(n(64));function u(t){return t&&t.__esModule?t:{default:t}}var c=function(t){var e=Math.min(t.shape[0],t.shape[1]),n=t.shape[0]/2-e/2,r=t.shape[1]/2-e/2;return t.slice([n,r,0],[e,e,3])};e.array3DToImage=function(t){var e=(0,a.default)(t.shape,2),n=e[0],r=e[1],i=t.dataSync(),o=document.createElement("canvas");o.width=r,o.height=n;for(var s=o.getContext("2d"),u=s.getImageData(0,0,o.width,o.height),c=0;c<r*n;c+=1){var l=4*c,f=3*c;u.data[l+0]=Math.floor(256*i[f+0]),u.data[l+1]=Math.floor(256*i[f+1]),u.data[l+2]=Math.floor(256*i[f+2]),u.data[l+3]=255}s.putImageData(u,0,0);var d=o.toDataURL(),h=document.createElement("img");return h.src=d,h.style.width=r,h.style.height=n,t.dispose(),h},e.processVideo=function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){},r=t,i=document.createElement("video");return r.onplay=function(){var t=r.captureStream();i.srcObject=t,i.width=e,i.height=e,i.autoplay=!0,i.playsinline=!0,i.muted=!0,n()},i},e.cropImage=c,e.imgToTensor=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return o.tidy(function(){var n=o.browser.fromPixels(t);return e&&(n=o.image.resizeBilinear(n,e)),c(n).expandDims(0).toFloat().div(o.scalar(127)).sub(o.scalar(1))})},e.isInstanceOfSupportedElement=function(t){return t instanceof HTMLVideoElement||t instanceof HTMLImageElement||t instanceof HTMLCanvasElement||t instanceof ImageData},e.flipImage=function(t){var e=void 0,n=void 0,r=void 0;if(r=t instanceof HTMLImageElement||t instanceof HTMLCanvasElement||t instanceof HTMLVideoElement||t instanceof ImageData?t:"object"===(void 0===t?"undefined":(0,i.default)(t))&&(t.elt instanceof HTMLImageElement||t.elt instanceof HTMLCanvasElement||t.elt instanceof HTMLVideoElement||t.elt instanceof ImageData)?t.elt:"object"===(void 0===t?"undefined":(0,i.default)(t))&&t.canvas instanceof HTMLCanvasElement?t.canvas:t,HTMLVideoElement,e=r.width,n=r.height,s.default.checkP5()){var a=s.default.p5Instance.createGraphics(e,n);return a.push(),a.translate(e,0),a.scale(-1,1),a.image(t,0,0,e,n),a.pop(),a}var o=document.createElement("canvas");o.width=e,o.height=n;var u=o.getContext("2d");return u.drawImage(r,0,0,e,n),u.translate(e,0),u.scale(-1,1),u.drawImage(o,-1*e,0,e,n),o},e.imgToPixelArray=function(t){var e=void 0,n=void 0,a=void 0;a=t instanceof HTMLImageElement||t instanceof HTMLCanvasElement||t instanceof HTMLVideoElement||t instanceof ImageData?t:"object"===(void 0===t?"undefined":(0,i.default)(t))&&(t.elt instanceof HTMLImageElement||t.elt instanceof HTMLCanvasElement||t.elt instanceof HTMLVideoElement||t.elt instanceof ImageData)?t.elt:"object"===(void 0===t?"undefined":(0,i.default)(t))&&t.canvas instanceof HTMLCanvasElement?t.canvas:t,HTMLVideoElement,e=a.width,n=a.height;var o=document.createElement("canvas");o.width=e,o.height=n;var s=o.getContext("2d");s.drawImage(a,0,0,e,n);var u=s.getImageData(0,0,e,n);return(0,r.default)(u.data)}},function(t,e,n){t.exports={default:n(401),__esModule:!0}},function(t,e,n){var r=n(38);t.exports=function(t){if(!r(t))throw TypeError(t+" is not an object!");return t}},function(t,e,n){var r=n(43),i=n(113),a=n(22),o=n(17),s=n(174);t.exports=function(t,e){var n=1==t,u=2==t,c=3==t,l=4==t,f=6==t,d=5==t||f,h=e||s;return function(e,s,p){for(var m,g,v=a(e),y=i(v),b=r(s,p,3),x=o(y.length),w=0,k=n?h(e,x):u?h(e,0):void 0;x>w;w++)if((d||w in y)&&(g=b(m=y[w],w,v),t))if(n)k[w]=g;else if(g)switch(t){case 3:return!0;case 5:return m;case 6:return w;case 2:k.push(m)}else if(l)return!1;return f?-1:c||l?l:k}}},function(t,e,n){var r=n(5),i=n(44),a=n(12);t.exports=function(t,e){var n=(i.Object||{})[t]||Object[t],o={};o[t]=e(n),r(r.S+r.F*a(function(){n(1)}),"Object",o)}},function(t,e){t.exports=function(t){if(void 0==t)throw TypeError("Can't call method on "+t);return t}},function(t,e,n){var r=n(13);t.exports=function(t,e){if(!r(t))return t;var n,i;if(e&&"function"==typeof(n=t.toString)&&!r(i=n.call(t)))return i;if("function"==typeof(n=t.valueOf)&&!r(i=n.call(t)))return i;if(!e&&"function"==typeof(n=t.toString)&&!r(i=n.call(t)))return i;throw TypeError("Can't convert object to primitive value")}},function(t,e){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){t.exports={default:n(366),__esModule:!0}},function(t,e,n){t.exports=n(398)},function(t,e,n){var r=n(109);t.exports=function(t,e,n){if(r(t),void 0===e)return t;switch(n){case 1:return function(n){return t.call(e,n)};case 2:return function(n,r){return t.call(e,n,r)};case 3:return function(n,r,i){return t.call(e,n,r,i)}}return function(){return t.apply(e,arguments)}}},function(t,e,n){var r=n(259),i=n(5),a=n(114)("metadata"),o=a.store||(a.store=new(n(256))),s=function(t,e,n){var i=o.get(t);if(!i){if(!n)return;o.set(t,i=new r)}var a=i.get(e);if(!a){if(!n)return;i.set(e,a=new r)}return a};t.exports={store:o,map:s,has:function(t,e,n){var r=s(e,n,!1);return void 0!==r&&r.has(t)},get:function(t,e,n){var r=s(e,n,!1);return void 0===r?void 0:r.get(t)},set:function(t,e,n,r){s(n,r,!0).set(t,e)},keys:function(t,e){var n=s(t,e,!1),r=[];return n&&n.forEach(function(t,e){r.push(e)}),r},key:function(t){return void 0===t||"symbol"==typeof t?t:String(t)},exp:function(t){i(i.S,"Reflect",t)}}},function(t,e,n){"use strict";if(n(19)){var r=n(63),i=n(11),a=n(12),o=n(5),s=n(126),u=n(166),c=n(43),l=n(73),f=n(80),d=n(31),h=n(71),p=n(41),m=n(17),g=n(254),v=n(77),y=n(52),b=n(36),x=n(93),w=n(13),k=n(22),_=n(177),E=n(76),O=n(33),S=n(75).f,C=n(175),A=n(79),N=n(16),T=n(49),I=n(136),D=n(110),M=n(172),R=n(91),F=n(131),j=n(74),P=n(173),L=n(265),z=n(21),B=n(34),U=z.f,W=B.f,V=i.RangeError,q=i.TypeError,H=i.Uint8Array,G=Array.prototype,$=u.ArrayBuffer,K=u.DataView,X=T(0),Y=T(2),J=T(3),Z=T(4),Q=T(5),tt=T(6),et=I(!0),nt=I(!1),rt=M.values,it=M.keys,at=M.entries,ot=G.lastIndexOf,st=G.reduce,ut=G.reduceRight,ct=G.join,lt=G.sort,ft=G.slice,dt=G.toString,ht=G.toLocaleString,pt=N("iterator"),mt=N("toStringTag"),gt=A("typed_constructor"),vt=A("def_constructor"),yt=s.CONSTR,bt=s.TYPED,xt=s.VIEW,wt=T(1,function(t,e){return St(D(t,t[vt]),e)}),kt=a(function(){return 1===new H(new Uint16Array([1]).buffer)[0]}),_t=!!H&&!!H.prototype.set&&a(function(){new H(1).set({})}),Et=function(t,e){var n=p(t);if(n<0||n%e)throw V("Wrong offset!");return n},Ot=function(t){if(w(t)&&bt in t)return t;throw q(t+" is not a typed array!")},St=function(t,e){if(!(w(t)&&gt in t))throw q("It is not a typed array constructor!");return new t(e)},Ct=function(t,e){return At(D(t,t[vt]),e)},At=function(t,e){for(var n=0,r=e.length,i=St(t,r);r>n;)i[n]=e[n++];return i},Nt=function(t,e,n){U(t,e,{get:function(){return this._d[n]}})},Tt=function(t){var e,n,r,i,a,o,s=k(t),u=arguments.length,l=u>1?arguments[1]:void 0,f=void 0!==l,d=C(s);if(void 0!=d&&!_(d)){for(o=d.call(s),r=[],e=0;!(a=o.next()).done;e++)r.push(a.value);s=r}for(f&&u>2&&(l=c(l,arguments[2],2)),e=0,n=m(s.length),i=St(this,n);n>e;e++)i[e]=f?l(s[e],e):s[e];return i},It=function(){for(var t=0,e=arguments.length,n=St(this,e);e>t;)n[t]=arguments[t++];return n},Dt=!!H&&a(function(){ht.call(new H(1))}),Mt=function(){return ht.apply(Dt?ft.call(Ot(this)):Ot(this),arguments)},Rt={copyWithin:function(t,e){return L.call(Ot(this),t,e,arguments.length>2?arguments[2]:void 0)},every:function(t){return Z(Ot(this),t,arguments.length>1?arguments[1]:void 0)},fill:function(t){return P.apply(Ot(this),arguments)},filter:function(t){return Ct(this,Y(Ot(this),t,arguments.length>1?arguments[1]:void 0))},find:function(t){return Q(Ot(this),t,arguments.length>1?arguments[1]:void 0)},findIndex:function(t){return tt(Ot(this),t,arguments.length>1?arguments[1]:void 0)},forEach:function(t){X(Ot(this),t,arguments.length>1?arguments[1]:void 0)},indexOf:function(t){return nt(Ot(this),t,arguments.length>1?arguments[1]:void 0)},includes:function(t){return et(Ot(this),t,arguments.length>1?arguments[1]:void 0)},join:function(t){return ct.apply(Ot(this),arguments)},lastIndexOf:function(t){return ot.apply(Ot(this),arguments)},map:function(t){return wt(Ot(this),t,arguments.length>1?arguments[1]:void 0)},reduce:function(t){return st.apply(Ot(this),arguments)},reduceRight:function(t){return ut.apply(Ot(this),arguments)},reverse:function(){for(var t,e=Ot(this).length,n=Math.floor(e/2),r=0;r<n;)t=this[r],this[r++]=this[--e],this[e]=t;return this},some:function(t){return J(Ot(this),t,arguments.length>1?arguments[1]:void 0)},sort:function(t){return lt.call(Ot(this),t)},subarray:function(t,e){var n=Ot(this),r=n.length,i=v(t,r);return new(D(n,n[vt]))(n.buffer,n.byteOffset+i*n.BYTES_PER_ELEMENT,m((void 0===e?r:v(e,r))-i))}},Ft=function(t,e){return Ct(this,ft.call(Ot(this),t,e))},jt=function(t){Ot(this);var e=Et(arguments[1],1),n=this.length,r=k(t),i=m(r.length),a=0;if(i+e>n)throw V("Wrong length!");for(;a<i;)this[e+a]=r[a++]},Pt={entries:function(){return at.call(Ot(this))},keys:function(){return it.call(Ot(this))},values:function(){return rt.call(Ot(this))}},Lt=function(t,e){return w(t)&&t[bt]&&"symbol"!=typeof e&&e in t&&String(+e)==String(e)},zt=function(t,e){return Lt(t,e=y(e,!0))?f(2,t[e]):W(t,e)},Bt=function(t,e,n){return!(Lt(t,e=y(e,!0))&&w(n)&&b(n,"value"))||b(n,"get")||b(n,"set")||n.configurable||b(n,"writable")&&!n.writable||b(n,"enumerable")&&!n.enumerable?U(t,e,n):(t[e]=n.value,t)};yt||(B.f=zt,z.f=Bt),o(o.S+o.F*!yt,"Object",{getOwnPropertyDescriptor:zt,defineProperty:Bt}),a(function(){dt.call({})})&&(dt=ht=function(){return ct.call(this)});var Ut=h({},Rt);h(Ut,Pt),d(Ut,pt,Pt.values),h(Ut,{slice:Ft,set:jt,constructor:function(){},toString:dt,toLocaleString:Mt}),Nt(Ut,"buffer","b"),Nt(Ut,"byteOffset","o"),Nt(Ut,"byteLength","l"),Nt(Ut,"length","e"),U(Ut,mt,{get:function(){return this[bt]}}),t.exports=function(t,e,n,u){var c=t+((u=!!u)?"Clamped":"")+"Array",f="get"+t,h="set"+t,p=i[c],v=p||{},y=p&&O(p),b=!p||!s.ABV,k={},_=p&&p.prototype,C=function(t,n){U(t,n,{get:function(){return function(t,n){var r=t._d;return r.v[f](n*e+r.o,kt)}(this,n)},set:function(t){return function(t,n,r){var i=t._d;u&&(r=(r=Math.round(r))<0?0:r>255?255:255&r),i.v[h](n*e+i.o,r,kt)}(this,n,t)},enumerable:!0})};b?(p=n(function(t,n,r,i){l(t,p,c,"_d");var a,o,s,u,f=0,h=0;if(w(n)){if(!(n instanceof $||"ArrayBuffer"==(u=x(n))||"SharedArrayBuffer"==u))return bt in n?At(p,n):Tt.call(p,n);a=n,h=Et(r,e);var v=n.byteLength;if(void 0===i){if(v%e)throw V("Wrong length!");if((o=v-h)<0)throw V("Wrong length!")}else if((o=m(i)*e)+h>v)throw V("Wrong length!");s=o/e}else s=g(n),a=new $(o=s*e);for(d(t,"_d",{b:a,o:h,l:o,e:s,v:new K(a)});f<s;)C(t,f++)}),_=p.prototype=E(Ut),d(_,"constructor",p)):a(function(){p(1)})&&a(function(){new p(-1)})&&F(function(t){new p,new p(null),new p(1.5),new p(t)},!0)||(p=n(function(t,n,r,i){var a;return l(t,p,c),w(n)?n instanceof $||"ArrayBuffer"==(a=x(n))||"SharedArrayBuffer"==a?void 0!==i?new v(n,Et(r,e),i):void 0!==r?new v(n,Et(r,e)):new v(n):bt in n?At(p,n):Tt.call(p,n):new v(g(n))}),X(y!==Function.prototype?S(v).concat(S(y)):S(v),function(t){t in p||d(p,t,v[t])}),p.prototype=_,r||(_.constructor=p));var A=_[pt],N=!!A&&("values"==A.name||void 0==A.name),T=Pt.values;d(p,gt,!0),d(_,bt,c),d(_,xt,!0),d(_,vt,p),(u?new p(1)[mt]==c:mt in _)||U(_,mt,{get:function(){return c}}),k[c]=p,o(o.G+o.W+o.F*(p!=v),k),o(o.S,c,{BYTES_PER_ELEMENT:e}),o(o.S+o.F*a(function(){v.of.call(p,1)}),c,{from:Tt,of:It}),"BYTES_PER_ELEMENT"in _||d(_,"BYTES_PER_ELEMENT",e),o(o.P,c,Rt),j(c),o(o.P+o.F*_t,c,{set:jt}),o(o.P+o.F*!N,c,Pt),r||_.toString==dt||(_.toString=dt),o(o.P+o.F*a(function(){new p(1).slice()}),c,{slice:Ft}),o(o.P+o.F*(a(function(){return[1,2].toLocaleString()!=new p([1,2]).toLocaleString()})||!a(function(){_.toLocaleString.call([1,2])})),c,{toLocaleString:Mt}),R[c]=N?A:T,r||N||d(_,pt,T)}}else t.exports=function(){}},function(t,e,n){"use strict";
  97. /**
  98. * @license
  99. * Copyright 2018 Google LLC. All Rights Reserved.
  100. * Licensed under the Apache License, Version 2.0 (the "License");
  101. * you may not use this file except in compliance with the License.
  102. * You may obtain a copy of the License at
  103. *
  104. * http://www.apache.org/licenses/LICENSE-2.0
  105. *
  106. * Unless required by applicable law or agreed to in writing, software
  107. * distributed under the License is distributed on an "AS IS" BASIS,
  108. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  109. * See the License for the specific language governing permissions and
  110. * limitations under the License.
  111. * =============================================================================
  112. */Object.defineProperty(e,"__esModule",{value:!0});const r=n(104),i=n(37),a={prepend:!1};e.subSurface=function(t,e,n={}){const o=i.getDrawArea(t),s=r.css({"& canvas":{display:"block"},marginTop:".5rem",marginBottom:".5rem"}),u=r.css({backgroundColor:"white",display:"inline-block",boxSizing:"border-box",borderBottom:"1px solid #357EDD",lineHeight:"2em",padding:"0 10px 0 10px",marginBottom:"20px",fontWeight:"600",textAlign:"left"}),c=Object.assign({},a,n);let l=o.querySelector(`div[data-name=${e}]`);if(!l){if((l=document.createElement("div")).setAttribute("class",`${s}`),l.dataset.name=e,c.title){const t=document.createElement("div");t.setAttribute("class",`subsurface-title ${u}`),t.innerText=c.title,l.appendChild(t)}c.prepend?o.insertBefore(l,o.firstChild):o.appendChild(l)}return l},e.getDefaultWidth=function(t){let e=0,n=t;for(;n&&0===n.clientWidth;)n=n.parentElement,e=50;return n.clientWidth-e},e.getDefaultHeight=function(t){return 0===t.clientHeight?200:t.clientHeight}},function(t,e,n){var r=n(39),i=n(108);t.exports=n(32)?function(t,e,n){return r.f(t,e,i(1,n))}:function(t,e,n){return t[e]=n,t}},function(t,e,n){var r=n(16)("unscopables"),i=Array.prototype;void 0==i[r]&&n(31)(i,r,{}),t.exports=function(t){i[r][t]=!0}},function(t,e,n){var r=n(79)("meta"),i=n(13),a=n(36),o=n(21).f,s=0,u=Object.isExtensible||function(){return!0},c=!n(12)(function(){return u(Object.preventExtensions({}))}),l=function(t){o(t,r,{value:{i:"O"+ ++s,w:{}}})},f=t.exports={KEY:r,NEED:!1,fastKey:function(t,e){if(!i(t))return"symbol"==typeof t?t:("string"==typeof t?"S":"P")+t;if(!a(t,r)){if(!u(t))return"F";if(!e)return"E";l(t)}return t[r].i},getWeak:function(t,e){if(!a(t,r)){if(!u(t))return!0;if(!e)return!1;l(t)}return t[r].w},onFreeze:function(t){return c&&f.NEED&&u(t)&&!a(t,r)&&l(t),t}}},function(t,e){t.exports=!1},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=c(n(9)),i=c(n(47)),a=c(n(8)),o=c(n(24)),s=c(n(7)),u=c(n(10));function c(t){return t&&t.__esModule?t:{default:t}}var l=new(function(){function t(){(0,s.default)(this,t),this.m_p5Instance=window}return(0,u.default)(t,[{key:"setP5Instance",value:function(t){this.m_p5Instance=t}},{key:"checkP5",value:function(){return!!this.p5Instance}},{key:"getBlob",value:function(t){return new o.default(function(e){t.toBlob(function(t){e(t)})})}},{key:"loadAsync",value:function(t){var e=this;return new o.default(function(n){e.p5Instance.loadImage(t,function(t){n(t)})})}},{key:"rawToBlob",value:function(){var t=(0,a.default)(r.default.mark(function t(e,n,a){var o,s,u,c,l,f,d;return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:for(o=(0,i.default)(e),s=document.createElement("canvas"),u=s.getContext("2d"),s.width=n,s.height=a,c=u.createImageData(n,a),l=c.data,f=0;f<n*a*4;f+=1)l[f]=o[f];return u.putImageData(c,0,0),t.next=11,this.getBlob(s);case 11:return d=t.sent,t.abrupt("return",d);case 13:case"end":return t.stop()}},t,this)}));return function(e,n,r){return t.apply(this,arguments)}}()},{key:"blobToP5Image",value:function(){var t=(0,a.default)(r.default.mark(function t(e){var n;return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.checkP5()){t.next=5;break}return t.next=3,this.loadAsync(URL.createObjectURL(e));case 3:return n=t.sent,t.abrupt("return",n);case 5:return t.abrupt("return",null);case 6:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"p5Instance",get:function(){return void 0!==this.m_p5Instance&&"function"==typeof this.m_p5Instance.loadImage?this.m_p5Instance:void 0!==this.m_p5Instance.p5&&void 0!==this.m_p5Instance.p5.Image&&"function"==typeof this.m_p5Instance.p5.Image?this.m_p5Instance.p5:void 0}}]),t}());e.default=l},function(t,e,n){"use strict";e.__esModule=!0;var r=a(n(378)),i=a(n(375));function a(t){return t&&t.__esModule?t:{default:t}}e.default=function(){return function(t,e){if(Array.isArray(t))return t;if((0,r.default)(Object(t)))return function(t,e){var n=[],r=!0,a=!1,o=void 0;try{for(var s,u=(0,i.default)(t);!(r=(s=u.next()).done)&&(n.push(s.value),!e||n.length!==e);r=!0);}catch(t){a=!0,o=t}finally{try{!r&&u.return&&u.return()}finally{if(a)throw o}}return n}(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}()},function(t,e,n){var r=n(162);t.exports=function(t){return Object(r(t))}},function(t,e,n){var r=n(163),i=n(162);t.exports=function(t){return r(i(t))}},function(t,e){var n={}.hasOwnProperty;t.exports=function(t,e){return n.call(t,e)}},function(t,e){t.exports=function(t){try{return!!t()}catch(t){return!0}}},function(t,e,n){var r=n(13);t.exports=function(t,e){if(!r(t)||t._t!==e)throw TypeError("Incompatible receiver, "+e+" required!");return t}},function(t,e,n){var r=n(30);t.exports=function(t,e,n){for(var i in e)r(t,i,e[i],n);return t}},function(t,e,n){var r=n(43),i=n(267),a=n(177),o=n(6),s=n(17),u=n(175),c={},l={};(e=t.exports=function(t,e,n,f,d){var h,p,m,g,v=d?function(){return t}:u(t),y=r(n,f,e?2:1),b=0;if("function"!=typeof v)throw TypeError(t+" is not iterable!");if(a(v)){for(h=s(t.length);h>b;b++)if((g=e?y(o(p=t[b])[0],p[1]):y(t[b]))===c||g===l)return g}else for(m=v.call(t);!(p=m.next()).done;)if((g=i(m,y,p.value,e))===c||g===l)return g}).BREAK=c,e.RETURN=l},function(t,e){t.exports=function(t,e,n,r){if(!(t instanceof e)||void 0!==r&&r in t)throw TypeError(n+": incorrect invocation!");return t}},function(t,e,n){"use strict";var r=n(11),i=n(21),a=n(19),o=n(16)("species");t.exports=function(t){var e=r[t];a&&e&&!e[o]&&i.f(e,o,{configurable:!0,get:function(){return this}})}},function(t,e,n){var r=n(280),i=n(189).concat("length","prototype");e.f=Object.getOwnPropertyNames||function(t){return r(t,i)}},function(t,e,n){var r=n(6),i=n(279),a=n(189),o=n(190)("IE_PROTO"),s=function(){},u=function(){var t,e=n(192)("iframe"),r=a.length;for(e.style.display="none",n(188).appendChild(e),e.src="javascript:",(t=e.contentWindow.document).open(),t.write("<script>document.F=Object<\/script>"),t.close(),u=t.F;r--;)delete u.prototype[a[r]];return u()};t.exports=Object.create||function(t,e){var n;return null!==t?(s.prototype=r(t),n=new s,s.prototype=null,n[o]=t):n=u(),void 0===e?n:i(n,e)}},function(t,e,n){var r=n(41),i=Math.max,a=Math.min;t.exports=function(t,e){return(t=r(t))<0?i(t+e,0):a(t,e)}},function(t,e,n){var r=n(280),i=n(189);t.exports=Object.keys||function(t){return r(t,i)}},function(t,e){var n=0,r=Math.random();t.exports=function(t){return"Symbol(".concat(void 0===t?"":t,")_",(++n+r).toString(36))}},function(t,e){t.exports=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}}},function(t,e,n){"use strict";t.exports=function(t,e){e||(e={}),"function"==typeof e&&(e={cmp:e});var n="boolean"==typeof e.cycles&&e.cycles,r=e.cmp&&function(t){return function(e){return function(n,r){var i={key:n,value:e[n]},a={key:r,value:e[r]};return t(i,a)}}}(e.cmp),i=[];return function t(e){if(e&&e.toJSON&&"function"==typeof e.toJSON&&(e=e.toJSON()),void 0!==e){if("number"==typeof e)return isFinite(e)?""+e:"null";if("object"!=typeof e)return JSON.stringify(e);var a,o;if(Array.isArray(e)){for(o="[",a=0;a<e.length;a++)a&&(o+=","),o+=t(e[a])||"null";return o+"]"}if(null===e)return"null";if(-1!==i.indexOf(e)){if(n)return JSON.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}var s=i.push(e)-1,u=Object.keys(e).sort(r&&r(e));for(o="",a=0;a<u.length;a++){var c=u[a],l=t(e[c]);l&&(o&&(o+=","),o+=JSON.stringify(c)+":"+l)}return i.splice(s,1),"{"+o+"}"}}(t)}},function(t,e,n){"use strict";n.r(e);var r={};n.d(r,"aggregate",function(){return ea}),n.d(r,"bin",function(){return ra}),n.d(r,"collect",function(){return oa}),n.d(r,"compare",function(){return sa}),n.d(r,"countpattern",function(){return ca}),n.d(r,"cross",function(){return fa}),n.d(r,"density",function(){return ga}),n.d(r,"dotbin",function(){return wa}),n.d(r,"expression",function(){return ka}),n.d(r,"extent",function(){return Ea}),n.d(r,"facet",function(){return Ca}),n.d(r,"field",function(){return Na}),n.d(r,"filter",function(){return Ia}),n.d(r,"flatten",function(){return Da}),n.d(r,"fold",function(){return Ma}),n.d(r,"formula",function(){return Ra}),n.d(r,"generate",function(){return Fa}),n.d(r,"impute",function(){return La}),n.d(r,"joinaggregate",function(){return za}),n.d(r,"kde",function(){return Ua}),n.d(r,"key",function(){return Wa}),n.d(r,"load",function(){return qa}),n.d(r,"lookup",function(){return Ga}),n.d(r,"multiextent",function(){return $a}),n.d(r,"multivalues",function(){return Xa}),n.d(r,"params",function(){return Ja}),n.d(r,"pivot",function(){return Za}),n.d(r,"prefacet",function(){return to}),n.d(r,"project",function(){return eo}),n.d(r,"proxy",function(){return no}),n.d(r,"quantile",function(){return io}),n.d(r,"relay",function(){return ao}),n.d(r,"sample",function(){return oo}),n.d(r,"sequence",function(){return so}),n.d(r,"sieve",function(){return uo}),n.d(r,"subflow",function(){return Oa}),n.d(r,"timeunit",function(){return ws}),n.d(r,"tupleindex",function(){return Es}),n.d(r,"values",function(){return Os}),n.d(r,"window",function(){return Ts});var i={};n.d(i,"bound",function(){return Rh}),n.d(i,"identifier",function(){return Ph}),n.d(i,"mark",function(){return Lh}),n.d(i,"overlap",function(){return zh}),n.d(i,"render",function(){return Gh}),n.d(i,"viewlayout",function(){return pp});var a={};n.d(a,"interpolate",function(){return Jm}),n.d(a,"interpolateArray",function(){return Vm}),n.d(a,"interpolateBasis",function(){return Tm}),n.d(a,"interpolateBasisClosed",function(){return Im}),n.d(a,"interpolateDate",function(){return Hm}),n.d(a,"interpolateDiscrete",function(){return mv}),n.d(a,"interpolateHue",function(){return gv}),n.d(a,"interpolateNumber",function(){return Gm}),n.d(a,"interpolateNumberArray",function(){return Um}),n.d(a,"interpolateObject",function(){return $m}),n.d(a,"interpolateRound",function(){return Zm}),n.d(a,"interpolateString",function(){return Ym}),n.d(a,"interpolateTransformCss",function(){return wv}),n.d(a,"interpolateTransformSvg",function(){return kv}),n.d(a,"interpolateZoom",function(){return Ov}),n.d(a,"interpolateRgb",function(){return Pm}),n.d(a,"interpolateRgbBasis",function(){return zm}),n.d(a,"interpolateRgbBasisClosed",function(){return Bm}),n.d(a,"interpolateHsl",function(){return Cv}),n.d(a,"interpolateHslLong",function(){return Av}),n.d(a,"interpolateLab",function(){return Xv}),n.d(a,"interpolateHcl",function(){return Jv}),n.d(a,"interpolateHclLong",function(){return Zv}),n.d(a,"interpolateCubehelix",function(){return uy}),n.d(a,"interpolateCubehelixLong",function(){return cy}),n.d(a,"piecewise",function(){return Qm}),n.d(a,"quantize",function(){return ly});var o={};n.d(o,"axisticks",function(){return Ly}),n.d(o,"datajoin",function(){return zy}),n.d(o,"encode",function(){return Wy}),n.d(o,"legendentries",function(){return Jy}),n.d(o,"linkpath",function(){return rb}),n.d(o,"pie",function(){return ub}),n.d(o,"scale",function(){return db}),n.d(o,"sortitems",function(){return gb}),n.d(o,"stack",function(){return yb}),n.d(o,"validTicks",function(){return Fy});var s={};n.d(s,"contour",function(){return zb}),n.d(s,"geojson",function(){return Wb}),n.d(s,"geopath",function(){return u_}),n.d(s,"geopoint",function(){return c_}),n.d(s,"geoshape",function(){return l_}),n.d(s,"graticule",function(){return p_}),n.d(s,"heatmap",function(){return m_}),n.d(s,"isocontour",function(){return Nb}),n.d(s,"kde2d",function(){return jb}),n.d(s,"projection",function(){return v_});var u={};n.d(u,"force",function(){return hE});var c={};n.d(c,"nest",function(){return SE}),n.d(c,"pack",function(){return ZE}),n.d(c,"partition",function(){return rO}),n.d(c,"stratify",function(){return fO}),n.d(c,"tree",function(){return _O}),n.d(c,"treelinks",function(){return OO}),n.d(c,"treemap",function(){return MO});var l={};n.d(l,"loess",function(){return jO}),n.d(l,"regression",function(){return LO});var f={};n.d(f,"voronoi",function(){return nS});var d={};n.d(d,"wordcloud",function(){return LS});var h={};n.d(h,"crossfilter",function(){return qS}),n.d(h,"resolvefilter",function(){return GS});var p={};n.d(p,"version",function(){return $S.a}),n.d(p,"Dataflow",function(){return Pr}),n.d(p,"EventStream",function(){return Mt}),n.d(p,"Parameters",function(){return Ot}),n.d(p,"Pulse",function(){return Sr}),n.d(p,"MultiPulse",function(){return Ir}),n.d(p,"Operator",function(){return Nt}),n.d(p,"Transform",function(){return Br}),n.d(p,"changeset",function(){return _t}),n.d(p,"ingest",function(){return vt}),n.d(p,"isTuple",function(){return pt}),n.d(p,"definition",function(){return Vr}),n.d(p,"transform",function(){return qr}),n.d(p,"transforms",function(){return Wr}),n.d(p,"tupleid",function(){return mt}),n.d(p,"scale",function(){return xC}),n.d(p,"scheme",function(){return TC}),n.d(p,"interpolate",function(){return SC}),n.d(p,"interpolateColors",function(){return EC}),n.d(p,"interpolateRange",function(){return _C}),n.d(p,"timeInterval",function(){return pC}),n.d(p,"quantizeInterpolator",function(){return OC}),n.d(p,"projection",function(){return i_}),n.d(p,"View",function(){return gM}),n.d(p,"expressionFunction",function(){return UD}),n.d(p,"formatLocale",function(){return PT}),n.d(p,"timeFormatLocale",function(){return yr}),n.d(p,"parse",function(){return aP}),n.d(p,"runtime",function(){return QD}),n.d(p,"runtimeContext",function(){return eM}),n.d(p,"bandwidthNRD",function(){return ui}),n.d(p,"bin",function(){return ci}),n.d(p,"bootstrapCI",function(){return di}),n.d(p,"dotbin",function(){return hi}),n.d(p,"quantiles",function(){return oi}),n.d(p,"quartiles",function(){return si}),n.d(p,"random",function(){return li}),n.d(p,"setRandom",function(){return fi}),n.d(p,"randomLCG",function(){return pi}),n.d(p,"randomInteger",function(){return mi}),n.d(p,"randomKDE",function(){return Ei}),n.d(p,"randomLogNormal",function(){return Ni}),n.d(p,"sampleLogNormal",function(){return Oi}),n.d(p,"densityLogNormal",function(){return Si}),n.d(p,"cumulativeLogNormal",function(){return Ci}),n.d(p,"quantileLogNormal",function(){return Ai}),n.d(p,"randomMixture",function(){return Ti}),n.d(p,"randomNormal",function(){return _i}),n.d(p,"sampleNormal",function(){return bi}),n.d(p,"densityNormal",function(){return xi}),n.d(p,"cumulativeNormal",function(){return wi}),n.d(p,"quantileNormal",function(){return ki}),n.d(p,"randomUniform",function(){return Fi}),n.d(p,"sampleUniform",function(){return Ii}),n.d(p,"densityUniform",function(){return Di}),n.d(p,"cumulativeUniform",function(){return Mi}),n.d(p,"quantileUniform",function(){return Ri}),n.d(p,"regressionLinear",function(){return Bi}),n.d(p,"regressionLog",function(){return Ui}),n.d(p,"regressionExp",function(){return Wi}),n.d(p,"regressionPow",function(){return Vi}),n.d(p,"regressionQuad",function(){return qi}),n.d(p,"regressionPoly",function(){return Hi}),n.d(p,"regressionLoess",function(){return $i}),n.d(p,"sampleCurve",function(){return Ji}),n.d(p,"accessor",function(){return ct.f}),n.d(p,"accessorName",function(){return ct.h}),n.d(p,"accessorFields",function(){return ct.g}),n.d(p,"id",function(){return ct.w}),n.d(p,"identity",function(){return ct.x}),n.d(p,"zero",function(){return ct.Ka}),n.d(p,"one",function(){return ct.O}),n.d(p,"truthy",function(){return ct.Ga}),n.d(p,"falsy",function(){return ct.r}),n.d(p,"logger",function(){return ct.K}),n.d(p,"None",function(){return ct.d}),n.d(p,"Error",function(){return ct.b}),n.d(p,"Warn",function(){return ct.e}),n.d(p,"Info",function(){return ct.c}),n.d(p,"Debug",function(){return ct.a}),n.d(p,"mergeConfig",function(){return ct.N}),n.d(p,"writeConfig",function(){return ct.Ja}),n.d(p,"panLinear",function(){return ct.Q}),n.d(p,"panLog",function(){return ct.R}),n.d(p,"panPow",function(){return ct.S}),n.d(p,"panSymlog",function(){return ct.T}),n.d(p,"zoomLinear",function(){return ct.La}),n.d(p,"zoomLog",function(){return ct.Ma}),n.d(p,"zoomPow",function(){return ct.Na}),n.d(p,"zoomSymlog",function(){return ct.Oa}),n.d(p,"quarter",function(){return ct.V}),n.d(p,"utcquarter",function(){return ct.Ha}),n.d(p,"array",function(){return ct.i}),n.d(p,"clampRange",function(){return ct.j}),n.d(p,"compare",function(){return ct.k}),n.d(p,"constant",function(){return ct.l}),n.d(p,"debounce",function(){return ct.m}),n.d(p,"error",function(){return ct.n}),n.d(p,"extend",function(){return ct.o}),n.d(p,"extent",function(){return ct.p}),n.d(p,"extentIndex",function(){return ct.q}),n.d(p,"fastmap",function(){return ct.s}),n.d(p,"field",function(){return ct.t}),n.d(p,"flush",function(){return ct.u}),n.d(p,"hasOwnProperty",function(){return ct.v}),n.d(p,"inherits",function(){return ct.y}),n.d(p,"inrange",function(){return ct.z}),n.d(p,"isArray",function(){return ct.A}),n.d(p,"isBoolean",function(){return ct.B}),n.d(p,"isDate",function(){return ct.C}),n.d(p,"isFunction",function(){return ct.D}),n.d(p,"isNumber",function(){return ct.E}),n.d(p,"isObject",function(){return ct.F}),n.d(p,"isRegExp",function(){return ct.G}),n.d(p,"isString",function(){return ct.H}),n.d(p,"key",function(){return ct.I}),n.d(p,"lerp",function(){return ct.J}),n.d(p,"lruCache",function(){return ct.L}),n.d(p,"merge",function(){return ct.M}),n.d(p,"pad",function(){return ct.P}),n.d(p,"peek",function(){return ct.U}),n.d(p,"repeat",function(){return ct.W}),n.d(p,"span",function(){return ct.X}),n.d(p,"splitAccessPath",function(){return ct.Y}),n.d(p,"stringValue",function(){return ct.Z}),n.d(p,"toBoolean",function(){return ct.Aa}),n.d(p,"toDate",function(){return ct.Ba}),n.d(p,"toNumber",function(){return ct.Ca}),n.d(p,"toString",function(){return ct.Ea}),n.d(p,"toSet",function(){return ct.Da}),n.d(p,"truncate",function(){return ct.Fa}),n.d(p,"visitArray",function(){return ct.Ia}),n.d(p,"loader",function(){return xr}),n.d(p,"read",function(){return br}),n.d(p,"inferType",function(){return $t}),n.d(p,"inferTypes",function(){return Kt}),n.d(p,"typeParsers",function(){return qt}),n.d(p,"format",function(){return xe}),n.d(p,"formats",function(){return we}),n.d(p,"responseType",function(){return ke}),n.d(p,"Bounds",function(){return yu}),n.d(p,"Gradient",function(){return Ou}),n.d(p,"GroupItem",function(){return Cu}),n.d(p,"ResourceLoader",function(){return Tu}),n.d(p,"Item",function(){return Su}),n.d(p,"Scenegraph",function(){return kd}),n.d(p,"Handler",function(){return Id}),n.d(p,"Renderer",function(){return Rd}),n.d(p,"CanvasHandler",function(){return Pd}),n.d(p,"CanvasRenderer",function(){return Wd}),n.d(p,"SVGHandler",function(){return $d}),n.d(p,"SVGRenderer",function(){return nh}),n.d(p,"SVGStringRenderer",function(){return mh}),n.d(p,"RenderType",function(){return kh}),n.d(p,"renderModule",function(){return Eh}),n.d(p,"intersect",function(){return Oh}),n.d(p,"Marks",function(){return md}),n.d(p,"boundClip",function(){return Th}),n.d(p,"boundContext",function(){return Ll}),n.d(p,"boundStroke",function(){return Ml}),n.d(p,"boundItem",function(){return gd}),n.d(p,"boundMark",function(){return yd}),n.d(p,"pathCurves",function(){return Sc}),n.d(p,"pathSymbols",function(){return qc}),n.d(p,"pathRectangle",function(){return al}),n.d(p,"pathTrail",function(){return ol}),n.d(p,"pathParse",function(){return Nc}),n.d(p,"pathRender",function(){return Uc}),n.d(p,"point",function(){return Td}),n.d(p,"domCreate",function(){return Od}),n.d(p,"domFind",function(){return Sd}),n.d(p,"domChild",function(){return Cd}),n.d(p,"domClear",function(){return Ad}),n.d(p,"openTag",function(){return Yd}),n.d(p,"closeTag",function(){return Jd}),n.d(p,"font",function(){return cd}),n.d(p,"fontFamily",function(){return ud}),n.d(p,"fontSize",function(){return rd}),n.d(p,"lineHeight",function(){return id}),n.d(p,"multiLineOffset",function(){return od}),n.d(p,"textMetrics",function(){return Jf}),n.d(p,"resetSVGClipId",function(){return Cf}),n.d(p,"sceneEqual",function(){return Dh}),n.d(p,"pathEqual",function(){return Mh}),n.d(p,"sceneToJSON",function(){return xd}),n.d(p,"sceneFromJSON",function(){return wd}),n.d(p,"intersectPath",function(){return Xl}),n.d(p,"intersectPoint",function(){return Yl}),n.d(p,"intersectRule",function(){return Zl}),n.d(p,"intersectBoxLine",function(){return Ql}),n.d(p,"sceneZOrder",function(){return cf}),n.d(p,"sceneVisit",function(){return lf}),n.d(p,"scenePickVisit",function(){return ff});var m={};n.d(m,"invalidSpec",function(){return yB}),n.d(m,"FIT_NON_SINGLE",function(){return bB}),n.d(m,"containerSizeNonSingle",function(){return xB}),n.d(m,"containerSizeNotCompatibleWithAutosize",function(){return wB}),n.d(m,"droppingFit",function(){return kB}),n.d(m,"cannotProjectOnChannelWithoutField",function(){return _B}),n.d(m,"cannotProjectAggregate",function(){return EB}),n.d(m,"nearestNotSupportForContinuous",function(){return OB}),n.d(m,"selectionNotSupported",function(){return SB}),n.d(m,"selectionNotFound",function(){return CB}),n.d(m,"SCALE_BINDINGS_CONTINUOUS",function(){return AB}),n.d(m,"LEGEND_BINDINGS_PROJECT_LENGTH",function(){return NB}),n.d(m,"noSameUnitLookup",function(){return TB}),n.d(m,"noSuchRepeatedValue",function(){return IB}),n.d(m,"columnsNotSupportByRowCol",function(){return DB}),n.d(m,"CONCAT_CANNOT_SHARE_AXIS",function(){return MB}),n.d(m,"REPEAT_CANNOT_SHARE_AXIS",function(){return RB}),n.d(m,"unrecognizedParse",function(){return FB}),n.d(m,"differentParse",function(){return jB}),n.d(m,"invalidTransformIgnored",function(){return PB}),n.d(m,"NO_FIELDS_NEEDS_AS",function(){return LB}),n.d(m,"encodingOverridden",function(){return zB}),n.d(m,"projectionOverridden",function(){return BB}),n.d(m,"primitiveChannelDef",function(){return UB}),n.d(m,"invalidFieldType",function(){return WB}),n.d(m,"nonZeroScaleUsedWithLengthMark",function(){return VB}),n.d(m,"invalidFieldTypeForCountAggregate",function(){return qB}),n.d(m,"invalidAggregate",function(){return HB}),n.d(m,"missingFieldType",function(){return GB}),n.d(m,"droppingColor",function(){return $B}),n.d(m,"emptyFieldDef",function(){return KB}),n.d(m,"latLongDeprecated",function(){return XB}),n.d(m,"LINE_WITH_VARYING_SIZE",function(){return YB}),n.d(m,"incompatibleChannel",function(){return JB}),n.d(m,"invalidEncodingChannel",function(){return ZB}),n.d(m,"facetChannelShouldBeDiscrete",function(){return QB}),n.d(m,"facetChannelDropped",function(){return tU}),n.d(m,"discreteChannelCannotEncode",function(){return eU}),n.d(m,"lineWithRange",function(){return nU}),n.d(m,"orientOverridden",function(){return rU}),n.d(m,"CANNOT_UNION_CUSTOM_DOMAIN_WITH_FIELD_DOMAIN",function(){return iU}),n.d(m,"RANGE_STEP_DEPRECATED",function(){return aU}),n.d(m,"cannotUseScalePropertyWithNonColor",function(){return oU}),n.d(m,"unaggregateDomainHasNoEffectForRawField",function(){return sU}),n.d(m,"unaggregateDomainWithNonSharedDomainOp",function(){return uU}),n.d(m,"unaggregatedDomainWithLogScale",function(){return cU}),n.d(m,"cannotApplySizeToNonOrientedMark",function(){return lU}),n.d(m,"scaleTypeNotWorkWithChannel",function(){return fU}),n.d(m,"scaleTypeNotWorkWithFieldDef",function(){return dU}),n.d(m,"scalePropertyNotWorkWithScaleType",function(){return hU}),n.d(m,"scaleTypeNotWorkWithMark",function(){return pU}),n.d(m,"stepDropped",function(){return mU}),n.d(m,"mergeConflictingProperty",function(){return gU}),n.d(m,"mergeConflictingDomainProperty",function(){return vU}),n.d(m,"independentScaleMeansIndependentGuide",function(){return yU}),n.d(m,"domainSortDropped",function(){return bU}),n.d(m,"UNABLE_TO_MERGE_DOMAINS",function(){return xU}),n.d(m,"MORE_THAN_ONE_SORT",function(){return wU}),n.d(m,"INVALID_CHANNEL_FOR_AXIS",function(){return kU}),n.d(m,"cannotStackRangedMark",function(){return _U}),n.d(m,"cannotStackNonLinearScale",function(){return EU}),n.d(m,"stackNonSummativeAggregate",function(){return OU}),n.d(m,"invalidTimeUnit",function(){return SU}),n.d(m,"dayReplacedWithDate",function(){return CU}),n.d(m,"droppedDay",function(){return AU}),n.d(m,"errorBarCenterAndExtentAreNotNeeded",function(){return NU}),n.d(m,"errorBarCenterIsUsedWithWrongExtent",function(){return TU}),n.d(m,"errorBarContinuousAxisHasCustomizedAggregate",function(){return IU}),n.d(m,"errorBarCenterIsNotNeeded",function(){return DU}),n.d(m,"errorBand1DNotSupport",function(){return MU}),n.d(m,"channelRequiredForBinned",function(){return RU}),n.d(m,"domainRequiredForThresholdScale",function(){return FU});var g={};n.d(g,"symbols",function(){return SK}),n.d(g,"gradient",function(){return CK}),n.d(g,"labels",function(){return AK}),n.d(g,"entries",function(){return NK}),n.d(g,"getFirstConditionValue",function(){return IK});var v={};n.d(v,"compile",function(){return lJ}),n.d(v,"extractTransforms",function(){return dJ}),n.d(v,"normalize",function(){return EH}),n.d(v,"version",function(){return hJ});var y={};n.d(y,"dark",function(){return vJ}),n.d(y,"excel",function(){return yJ}),n.d(y,"fivethirtyeight",function(){return bJ}),n.d(y,"ggplot2",function(){return xJ}),n.d(y,"latimes",function(){return _J}),n.d(y,"quartz",function(){return EJ}),n.d(y,"vox",function(){return OJ}),n.d(y,"urbaninstitute",function(){return CJ}),n.d(y,"googlecharts",function(){return AJ}),n.d(y,"version",function(){return NJ});function b(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}var x={},w=null;"undefined"!=typeof document&&("onmouseenter"in document.documentElement||(x={mouseenter:"mouseover",mouseleave:"mouseout"}));function k(t,e,n){return t=_(t,e,n),function(e){var n=e.relatedTarget;n&&(n===this||8&n.compareDocumentPosition(this))||t.call(this,e)}}function _(t,e,n){return function(r){var i=w;w=r;try{t.call(this,this.__data__,e,n)}finally{w=i}}}function E(t){return function(){var e=this.__on;if(e){for(var n,r=0,i=-1,a=e.length;r<a;++r)n=e[r],t.type&&n.type!==t.type||n.name!==t.name?e[++i]=n:this.removeEventListener(n.type,n.listener,n.capture);++i?e.length=i:delete this.__on}}}function O(t,e,n){var r=x.hasOwnProperty(t.type)?k:_;return function(i,a,o){var s,u=this.__on,c=r(e,a,o);if(u)for(var l=0,f=u.length;l<f;++l)if((s=u[l]).type===t.type&&s.name===t.name)return this.removeEventListener(s.type,s.listener,s.capture),this.addEventListener(s.type,s.listener=c,s.capture=n),void(s.value=e);this.addEventListener(t.type,c,n),s={type:t.type,name:t.name,value:e,listener:c,capture:n},u?u.push(s):this.__on=[s]}}function S(){}var C=function(t){return null==t?S:function(){return this.querySelector(t)}};function A(){return[]}var N=function(t){return new Array(t.length)};function T(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}T.prototype={constructor:T,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var I="$";function D(t,e,n,r,i,a){for(var o,s=0,u=e.length,c=a.length;s<c;++s)(o=e[s])?(o.__data__=a[s],r[s]=o):n[s]=new T(t,a[s]);for(;s<u;++s)(o=e[s])&&(i[s]=o)}function M(t,e,n,r,i,a,o){var s,u,c,l={},f=e.length,d=a.length,h=new Array(f);for(s=0;s<f;++s)(u=e[s])&&(h[s]=c=I+o.call(u,u.__data__,s,e),c in l?i[s]=u:l[c]=u);for(s=0;s<d;++s)(u=l[c=I+o.call(t,a[s],s,a)])?(r[s]=u,u.__data__=a[s],l[c]=null):n[s]=new T(t,a[s]);for(s=0;s<f;++s)(u=e[s])&&l[h[s]]===u&&(i[s]=u)}function R(t,e){return t<e?-1:t>e?1:t>=e?0:NaN}var F="http://www.w3.org/1999/xhtml",j={svg:"http://www.w3.org/2000/svg",xhtml:F,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},P=function(t){var e=t+="",n=e.indexOf(":");return n>=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),j.hasOwnProperty(e)?{space:j[e],local:t}:t};var L=function(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView};function z(t){return t.trim().split(/^|\s+/)}function B(t){return t.classList||new U(t)}function U(t){this._node=t,this._names=z(t.getAttribute("class")||"")}function W(t,e){for(var n=B(t),r=-1,i=e.length;++r<i;)n.add(e[r])}function V(t,e){for(var n=B(t),r=-1,i=e.length;++r<i;)n.remove(e[r])}U.prototype={add:function(t){this._names.indexOf(t)<0&&(this._names.push(t),this._node.setAttribute("class",this._names.join(" ")))},remove:function(t){var e=this._names.indexOf(t);e>=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};function q(){this.textContent=""}function H(){this.innerHTML=""}function G(){this.nextSibling&&this.parentNode.appendChild(this)}function $(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}var K=function(t){var e=P(t);return(e.local?function(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}:function(t){return function(){var e=this.ownerDocument,n=this.namespaceURI;return n===F&&e.documentElement.namespaceURI===F?e.createElement(t):e.createElementNS(n,t)}})(e)};function X(){return null}function Y(){var t=this.parentNode;t&&t.removeChild(this)}function J(){var t=this.cloneNode(!1),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function Z(){var t=this.cloneNode(!0),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function Q(t,e,n){var r=L(t),i=r.CustomEvent;"function"==typeof i?i=new i(e,n):(i=r.document.createEvent("Event"),n?(i.initEvent(e,n.bubbles,n.cancelable),i.detail=n.detail):i.initEvent(e,!1,!1)),t.dispatchEvent(i)}var tt=[null];function et(t,e){this._groups=t,this._parents=e}function nt(){return new et([[document.documentElement]],tt)}et.prototype=nt.prototype={constructor:et,select:function(t){"function"!=typeof t&&(t=C(t));for(var e=this._groups,n=e.length,r=new Array(n),i=0;i<n;++i)for(var a,o,s=e[i],u=s.length,c=r[i]=new Array(u),l=0;l<u;++l)(a=s[l])&&(o=t.call(a,a.__data__,l,s))&&("__data__"in a&&(o.__data__=a.__data__),c[l]=o);return new et(r,this._parents)},selectAll:function(t){"function"!=typeof t&&(t=function(t){return null==t?A:function(){return this.querySelectorAll(t)}}(t));for(var e=this._groups,n=e.length,r=[],i=[],a=0;a<n;++a)for(var o,s=e[a],u=s.length,c=0;c<u;++c)(o=s[c])&&(r.push(t.call(o,o.__data__,c,s)),i.push(o));return new et(r,i)},filter:function(t){"function"!=typeof t&&(t=function(t){return function(){return this.matches(t)}}(t));for(var e=this._groups,n=e.length,r=new Array(n),i=0;i<n;++i)for(var a,o=e[i],s=o.length,u=r[i]=[],c=0;c<s;++c)(a=o[c])&&t.call(a,a.__data__,c,o)&&u.push(a);return new et(r,this._parents)},data:function(t,e){if(!t)return h=new Array(this.size()),c=-1,this.each(function(t){h[++c]=t}),h;var n=e?M:D,r=this._parents,i=this._groups;"function"!=typeof t&&(t=function(t){return function(){return t}}(t));for(var a=i.length,o=new Array(a),s=new Array(a),u=new Array(a),c=0;c<a;++c){var l=r[c],f=i[c],d=f.length,h=t.call(l,l&&l.__data__,c,r),p=h.length,m=s[c]=new Array(p),g=o[c]=new Array(p);n(l,f,m,g,u[c]=new Array(d),h,e);for(var v,y,b=0,x=0;b<p;++b)if(v=m[b]){for(b>=x&&(x=b+1);!(y=g[x])&&++x<p;);v._next=y||null}}return(o=new et(o,r))._enter=s,o._exit=u,o},enter:function(){return new et(this._enter||this._groups.map(N),this._parents)},exit:function(){return new et(this._exit||this._groups.map(N),this._parents)},join:function(t,e,n){var r=this.enter(),i=this,a=this.exit();return r="function"==typeof t?t(r):r.append(t+""),null!=e&&(i=e(i)),null==n?a.remove():n(a),r&&i?r.merge(i).order():i},merge:function(t){for(var e=this._groups,n=t._groups,r=e.length,i=n.length,a=Math.min(r,i),o=new Array(r),s=0;s<a;++s)for(var u,c=e[s],l=n[s],f=c.length,d=o[s]=new Array(f),h=0;h<f;++h)(u=c[h]||l[h])&&(d[h]=u);for(;s<r;++s)o[s]=e[s];return new et(o,this._parents)},order:function(){for(var t=this._groups,e=-1,n=t.length;++e<n;)for(var r,i=t[e],a=i.length-1,o=i[a];--a>=0;)(r=i[a])&&(o&&4^r.compareDocumentPosition(o)&&o.parentNode.insertBefore(r,o),o=r);return this},sort:function(t){function e(e,n){return e&&n?t(e.__data__,n.__data__):!e-!n}t||(t=R);for(var n=this._groups,r=n.length,i=new Array(r),a=0;a<r;++a){for(var o,s=n[a],u=s.length,c=i[a]=new Array(u),l=0;l<u;++l)(o=s[l])&&(c[l]=o);c.sort(e)}return new et(i,this._parents).order()},call:function(){var t=arguments[0];return arguments[0]=this,t.apply(null,arguments),this},nodes:function(){var t=new Array(this.size()),e=-1;return this.each(function(){t[++e]=this}),t},node:function(){for(var t=this._groups,e=0,n=t.length;e<n;++e)for(var r=t[e],i=0,a=r.length;i<a;++i){var o=r[i];if(o)return o}return null},size:function(){var t=0;return this.each(function(){++t}),t},empty:function(){return!this.node()},each:function(t){for(var e=this._groups,n=0,r=e.length;n<r;++n)for(var i,a=e[n],o=0,s=a.length;o<s;++o)(i=a[o])&&t.call(i,i.__data__,o,a);return this},attr:function(t,e){var n=P(t);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((null==e?n.local?function(t){return function(){this.removeAttributeNS(t.space,t.local)}}:function(t){return function(){this.removeAttribute(t)}}:"function"==typeof e?n.local?function(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,n)}}:function(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}:n.local?function(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}:function(t,e){return function(){this.setAttribute(t,e)}})(n,e))},style:function(t,e,n){return arguments.length>1?this.each((null==e?function(t){return function(){this.style.removeProperty(t)}}:"function"==typeof e?function(t,e,n){return function(){var r=e.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,n)}}:function(t,e,n){return function(){this.style.setProperty(t,e,n)}})(t,e,null==n?"":n)):function(t,e){return t.style.getPropertyValue(e)||L(t).getComputedStyle(t,null).getPropertyValue(e)}(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?function(t){return function(){delete this[t]}}:"function"==typeof e?function(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}:function(t,e){return function(){this[t]=e}})(t,e)):this.node()[t]},classed:function(t,e){var n=z(t+"");if(arguments.length<2){for(var r=B(this.node()),i=-1,a=n.length;++i<a;)if(!r.contains(n[i]))return!1;return!0}return this.each(("function"==typeof e?function(t,e){return function(){(e.apply(this,arguments)?W:V)(this,t)}}:e?function(t){return function(){W(this,t)}}:function(t){return function(){V(this,t)}})(n,e))},text:function(t){return arguments.length?this.each(null==t?q:("function"==typeof t?function(t){return function(){var e=t.apply(this,arguments);this.textContent=null==e?"":e}}:function(t){return function(){this.textContent=t}})(t)):this.node().textContent},html:function(t){return arguments.length?this.each(null==t?H:("function"==typeof t?function(t){return function(){var e=t.apply(this,arguments);this.innerHTML=null==e?"":e}}:function(t){return function(){this.innerHTML=t}})(t)):this.node().innerHTML},raise:function(){return this.each(G)},lower:function(){return this.each($)},append:function(t){var e="function"==typeof t?t:K(t);return this.select(function(){return this.appendChild(e.apply(this,arguments))})},insert:function(t,e){var n="function"==typeof t?t:K(t),r=null==e?X:"function"==typeof e?e:C(e);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})},remove:function(){return this.each(Y)},clone:function(t){return this.select(t?Z:J)},datum:function(t){return arguments.length?this.property("__data__",t):this.node().__data__},on:function(t,e,n){var r,i,a=function(t){return t.trim().split(/^|\s+/).map(function(t){var e="",n=t.indexOf(".");return n>=0&&(e=t.slice(n+1),t=t.slice(0,n)),{type:t,name:e}})}(t+""),o=a.length;if(!(arguments.length<2)){for(s=e?O:E,null==n&&(n=!1),r=0;r<o;++r)this.each(s(a[r],e,n));return this}var s=this.node().__on;if(s)for(var u,c=0,l=s.length;c<l;++c)for(r=0,u=s[c];r<o;++r)if((i=a[r]).type===u.type&&i.name===u.name)return u.value},dispatch:function(t,e){return this.each(("function"==typeof e?function(t,e){return function(){return Q(this,t,e.apply(this,arguments))}}:function(t,e){return function(){return Q(this,t,e)}})(t,e))}};var rt=function(t){return"string"==typeof t?new et([[document.querySelector(t)]],[document.documentElement]):new et([[t]],tt)},it=n(95),at=n.n(it),ot=n(140),st=n.n(ot),ut=n(196),ct=n(1);function lt(t){var e=t||ct.x,n=[],r={};return n.add=function(t){var i=e(t);return r[i]||(r[i]=1,n.push(t)),n},n.remove=function(t){var i,a=e(t);return r[a]&&(r[a]=0,(i=n.indexOf(t))>=0&&n.splice(i,1)),n},n}var ft=async function(t,e){try{await e(t)}catch(e){t.error(e)}},dt=Symbol("vega_id"),ht=1;function pt(t){return!(!t||!mt(t))}function mt(t){return t[dt]}function gt(t,e){return t[dt]=e,t}function vt(t){var e=t===Object(t)?t:{data:t};return mt(e)?e:gt(e,ht++)}function yt(t){return bt(t,vt({}))}function bt(t,e){for(var n in t)e[n]=t[n];return e}function xt(t,e){return gt(e,mt(t))}function wt(t,e){return t?e?(n,r)=>t(n,r)||mt(e(n))-mt(e(r)):(e,n)=>t(e,n)||mt(e)-mt(n):null}function kt(t){return t&&t.constructor===_t}function _t(){var t=[],e=[],n=[],r=[],i=[],a=!1;return{constructor:_t,insert:function(e){for(var n=Object(ct.i)(e),r=0,i=n.length;r<i;++r)t.push(n[r]);return this},remove:function(t){for(var n=Object(ct.D)(t)?r:e,i=Object(ct.i)(t),a=0,o=i.length;a<o;++a)n.push(i[a]);return this},modify:function(t,e,r){var a={field:e,value:Object(ct.l)(r)};return Object(ct.D)(t)?(a.filter=t,i.push(a)):(a.tuple=t,n.push(a)),this},encode:function(t,e){return Object(ct.D)(t)?i.push({filter:t,field:e}):n.push({tuple:t,field:e}),this},reflow:function(){return a=!0,this},pulse:function(o,s){var u,c,l,f,d,h,p={},m={};for(u=0,c=s.length;u<c;++u)p[mt(s[u])]=1;for(u=0,c=e.length;u<c;++u)p[mt(d=e[u])]=-1;for(u=0,c=r.length;u<c;++u)f=r[u],s.forEach(function(t){f(t)&&(p[mt(t)]=-1)});for(u=0,c=t.length;u<c;++u)h=mt(d=t[u]),p[h]?p[h]=1:o.add.push(vt(t[u]));for(u=0,c=s.length;u<c;++u)d=s[u],p[mt(d)]<0&&o.rem.push(d);function g(t,e,n){n?t[e]=n(t):o.encode=e,a||(m[mt(t)]=t)}for(u=0,c=n.length;u<c;++u)d=(l=n[u]).tuple,f=l.field,(h=p[mt(d)])>0&&(g(d,f,l.value),o.modifies(f));for(u=0,c=i.length;u<c;++u)l=i[u],f=l.filter,s.forEach(function(t){f(t)&&p[mt(t)]>0&&g(t,l.field,l.value)}),o.modifies(l.field);if(a)o.mod=e.length||r.length?s.filter(function(t){return p[mt(t)]>0}):s.slice();else for(h in m)o.mod.push(m[h]);return o}}}var Et="_:mod:_";function Ot(){Object.defineProperty(this,Et,{writable:!0,value:{}})}var St=Ot.prototype;St.set=function(t,e,n,r){var i=this,a=i[t],o=i[Et];return null!=e&&e>=0?(a[e]!==n||r)&&(a[e]=n,o[e+":"+t]=-1,o[t]=-1):(a!==n||r)&&(i[t]=n,o[t]=Object(ct.A)(n)?1+n.length:-1),i},St.modified=function(t,e){var n,r=this[Et];if(!arguments.length){for(n in r)if(r[n])return!0;return!1}if(Object(ct.A)(t)){for(n=0;n<t.length;++n)if(r[t[n]])return!0;return!1}return null!=e&&e>=0?e+1<r[t]||!!r[e+":"+t]:!!r[t]},St.clear=function(){return this[Et]={},this};var Ct=0,At=new Ot;function Nt(t,e,n,r){this.id=++Ct,this.value=t,this.stamp=-1,this.rank=-1,this.qrank=-1,this.flags=0,e&&(this._update=e),n&&this.parameters(n,r)}var Tt=Nt.prototype;function It(t){return function(e){var n=this.flags;return 0===arguments.length?!!(n&t):(this.flags=e?n|t:n&~t,this)}}Tt.targets=function(){return this._targets||(this._targets=lt(ct.w))},Tt.set=function(t){return this.value!==t?(this.value=t,1):0},Tt.skip=It(1),Tt.modified=It(2),Tt.parameters=function(t,e,n){e=!1!==e;var r,i,a,o,s=this,u=s._argval=s._argval||new Ot,c=s._argops=s._argops||[],l=[];function f(t,n,r){r instanceof Nt?(r!==s&&(e&&r.targets().add(s),l.push(r)),c.push({op:r,name:t,index:n})):u.set(t,n,r)}for(r in t)if(i=t[r],"pulse"===r)Object(ct.i)(i).forEach(function(t){t instanceof Nt?t!==s&&(t.targets().add(s),l.push(t)):Object(ct.n)("Pulse parameters must be operator instances.")}),s.source=i;else if(Object(ct.A)(i))for(u.set(r,-1,Array(a=i.length)),o=0;o<a;++o)f(r,o,i[o]);else f(r,-1,i);return this.marshall().clear(),n&&(c.initonly=!0),l},Tt.marshall=function(t){var e,n,r,i,a,o=this._argval||At,s=this._argops;if(s){for(n=0,r=s.length;n<r;++n)a=(i=(e=s[n]).op).modified()&&i.stamp===t,o.set(e.name,e.index,i.value,a);if(s.initonly){for(n=0;n<r;++n)(e=s[n]).op.targets().remove(this);this._argops=null,this._update=null}}return o},Tt.evaluate=function(t){var e=this._update;if(e){var n=this.marshall(t.stamp),r=e.call(this,n,t);if(n.clear(),r!==this.value)this.value=r;else if(!this.modified())return t.StopPropagation}},Tt.run=function(t){return t.stamp<this.stamp?t.StopPropagation:(this.skip()?(this.skip(!1),e=0):e=this.evaluate(t),this.pulse=e||t);var e};var Dt=0;function Mt(t,e,n){this.id=++Dt,this.value=null,n&&(this.receive=n),t&&(this._filter=t),e&&(this._apply=e)}function Rt(t,e,n){return new Mt(t,e,n)}var Ft=Mt.prototype;Ft._filter=ct.Ga,Ft._apply=ct.x,Ft.targets=function(){return this._targets||(this._targets=lt(ct.w))},Ft.consume=function(t){return arguments.length?(this._consume=!!t,this):!!this._consume},Ft.receive=function(t){if(this._filter(t)){for(var e=this.value=this._apply(t),n=this._targets,r=n?n.length:0,i=0;i<r;++i)n[i].receive(e);this._consume&&(t.preventDefault(),t.stopPropagation())}},Ft.filter=function(t){var e=Rt(t);return this.targets().add(e),e},Ft.apply=function(t){var e=Rt(null,t);return this.targets().add(e),e},Ft.merge=function(){var t=Rt();this.targets().add(t);for(var e=0,n=arguments.length;e<n;++e)arguments[e].targets().add(t);return t},Ft.throttle=function(t){var e=-1;return this.filter(function(){var n=Date.now();return n-e>t?(e=n,1):0})},Ft.debounce=function(t){var e=Rt();return this.targets().add(Rt(null,null,Object(ct.m)(t,function(t){var n=t.dataflow;e.receive(t),n&&n.run&&n.run()}))),e},Ft.between=function(t,e){var n=!1;return t.targets().add(Rt(null,null,function(){n=!0})),e.targets().add(Rt(null,null,function(){n=!1})),this.filter(function(){return n})};const jt=/^([A-Za-z]+:)?\/\//,Pt=/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp|file|data):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i,Lt=/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205f\u3000]/g,zt="file://";async function Bt(t,e){const n=await this.sanitize(t,e),r=n.href;return n.localFile?this.file(r):this.http(r,e)}async function Ut(t,e){e=Object(ct.o)({},this.options,e);const n=this.fileAccess,r={href:null};let i,a,o;const s=Pt.test(t.replace(Lt,""));null!=t&&"string"==typeof t&&s||Object(ct.n)("Sanitize failure, invalid URI: "+Object(ct.Z)(t));const u=jt.test(t);return(o=e.baseURL)&&!u&&(t.startsWith("/")||"/"===o[o.length-1]||(t="/"+t),t=o+t),a=(i=t.startsWith(zt))||"file"===e.mode||"http"!==e.mode&&!u&&n,i?t=t.slice(zt.length):t.startsWith("//")&&("file"===e.defaultProtocol?(t=t.slice(2),a=!0):t=(e.defaultProtocol||"http")+":"+t),Object.defineProperty(r,"localFile",{value:!!a}),r.href=t,e.target&&(r.target=e.target+""),e.rel&&(r.rel=e.rel+""),"image"===e.context&&e.crossOrigin&&(r.crossOrigin=e.crossOrigin+""),r}async function Wt(){Object(ct.n)("No file system access.")}async function Vt(){Object(ct.n)("No HTTP fetch method available.")}var qt={boolean:ct.Aa,integer:ct.Ca,number:ct.Ca,date:ct.Ba,string:ct.Ea,unknown:ct.x},Ht=[function(t){return"true"===t||"false"===t||!0===t||!1===t},function(t){return Yt(t)&&Number.isInteger(+t)},Yt,function(t){return!Number.isNaN(Date.parse(t))}],Gt=["boolean","integer","number","date"];function $t(t,e){if(!t||!t.length)return"unknown";var n,r,i,a=0,o=t.length,s=Ht.length,u=Ht.map(function(t,e){return e+1});for(r=0,o=t.length;r<o;++r)for(n=e?t[r][e]:t[r],i=0;i<s;++i)if(u[i]&&Xt(n)&&!Ht[i](n)&&(u[i]=0,++a===Ht.length))return"string";return a=u.reduce(function(t,e){return 0===t?e:t},0)-1,Gt[a]}function Kt(t,e){return e.reduce(function(e,n){return e[n]=$t(t,n),e},{})}function Xt(t){return null!=t&&t==t}function Yt(t){return!(Number.isNaN(+t)||t instanceof Date)}var Jt={},Zt={},Qt=34,te=10,ee=13;function ne(t){return new Function("d","return {"+t.map(function(t,e){return JSON.stringify(t)+": d["+e+'] || ""'}).join(",")+"}")}function re(t){var e=Object.create(null),n=[];return t.forEach(function(t){for(var r in t)r in e||n.push(e[r]=r)}),n}function ie(t,e){var n=t+"",r=n.length;return r<e?new Array(e-r+1).join(0)+n:n}function ae(t){var e=t.getUTCHours(),n=t.getUTCMinutes(),r=t.getUTCSeconds(),i=t.getUTCMilliseconds();return isNaN(t)?"Invalid Date":function(t){return t<0?"-"+ie(-t,6):t>9999?"+"+ie(t,6):ie(t,4)}(t.getUTCFullYear())+"-"+ie(t.getUTCMonth()+1,2)+"-"+ie(t.getUTCDate(),2)+(i?"T"+ie(e,2)+":"+ie(n,2)+":"+ie(r,2)+"."+ie(i,3)+"Z":r?"T"+ie(e,2)+":"+ie(n,2)+":"+ie(r,2)+"Z":n||e?"T"+ie(e,2)+":"+ie(n,2)+"Z":"")}var oe=function(t){var e=new RegExp('["'+t+"\n\r]"),n=t.charCodeAt(0);function r(t,e){var r,i=[],a=t.length,o=0,s=0,u=a<=0,c=!1;function l(){if(u)return Zt;if(c)return c=!1,Jt;var e,r,i=o;if(t.charCodeAt(i)===Qt){for(;o++<a&&t.charCodeAt(o)!==Qt||t.charCodeAt(++o)===Qt;);return(e=o)>=a?u=!0:(r=t.charCodeAt(o++))===te?c=!0:r===ee&&(c=!0,t.charCodeAt(o)===te&&++o),t.slice(i+1,e-1).replace(/""/g,'"')}for(;o<a;){if((r=t.charCodeAt(e=o++))===te)c=!0;else if(r===ee)c=!0,t.charCodeAt(o)===te&&++o;else if(r!==n)continue;return t.slice(i,e)}return u=!0,t.slice(i,a)}for(t.charCodeAt(a-1)===te&&--a,t.charCodeAt(a-1)===ee&&--a;(r=l())!==Zt;){for(var f=[];r!==Jt&&r!==Zt;)f.push(r),r=l();e&&null==(f=e(f,s++))||i.push(f)}return i}function i(e,n){return e.map(function(e){return n.map(function(t){return o(e[t])}).join(t)})}function a(e){return e.map(o).join(t)}function o(t){return null==t?"":t instanceof Date?ae(t):e.test(t+="")?'"'+t.replace(/"/g,'""')+'"':t}return{parse:function(t,e){var n,i,a=r(t,function(t,r){if(n)return n(t,r-1);i=t,n=e?function(t,e){var n=ne(t);return function(r,i){return e(n(r),i,t)}}(t,e):ne(t)});return a.columns=i||[],a},parseRows:r,format:function(e,n){return null==n&&(n=re(e)),[n.map(o).join(t)].concat(i(e,n)).join("\n")},formatBody:function(t,e){return null==e&&(e=re(t)),i(t,e).join("\n")},formatRows:function(t){return t.map(a).join("\n")},formatRow:a,formatValue:o}};function se(t){const e=function(e,n){const r={delimiter:t};return ue(e,n?Object(ct.o)(n,r):r)};return e.responseType="text",e}function ue(t,e){return e.header&&(t=e.header.map(ct.Z).join(e.delimiter)+"\n"+t),oe(e.delimiter).parse(t+"")}ue.responseType="text";var ce=n(139),le=function(t){return t},fe=function(t){if(null==t)return le;var e,n,r=t.scale[0],i=t.scale[1],a=t.translate[0],o=t.translate[1];return function(t,s){s||(e=n=0);var u=2,c=t.length,l=new Array(c);for(l[0]=(e+=t[0])*r+a,l[1]=(n+=t[1])*i+o;u<c;)l[u]=t[u],++u;return l}},de=function(t,e){for(var n,r=t.length,i=r-e;i<--r;)n=t[i],t[i++]=t[r],t[r]=n},he=function(t,e){return"string"==typeof e&&(e=t.objects[e]),"GeometryCollection"===e.type?{type:"FeatureCollection",features:e.geometries.map(function(e){return pe(t,e)})}:pe(t,e)};function pe(t,e){var n=e.id,r=e.bbox,i=null==e.properties?{}:e.properties,a=me(t,e);return null==n&&null==r?{type:"Feature",properties:i,geometry:a}:null==r?{type:"Feature",id:n,properties:i,geometry:a}:{type:"Feature",id:n,bbox:r,properties:i,geometry:a}}function me(t,e){var n=fe(t.transform),r=t.arcs;function i(t,e){e.length&&e.pop();for(var i=r[t<0?~t:t],a=0,o=i.length;a<o;++a)e.push(n(i[a],a));t<0&&de(e,o)}function a(t){return n(t)}function o(t){for(var e=[],n=0,r=t.length;n<r;++n)i(t[n],e);return e.length<2&&e.push(e[0]),e}function s(t){for(var e=o(t);e.length<4;)e.push(e[0]);return e}function u(t){return t.map(s)}return function t(e){var n,r=e.type;switch(r){case"GeometryCollection":return{type:r,geometries:e.geometries.map(t)};case"Point":n=a(e.coordinates);break;case"MultiPoint":n=e.coordinates.map(a);break;case"LineString":n=o(e.arcs);break;case"MultiLineString":n=e.arcs.map(o);break;case"Polygon":n=u(e.arcs);break;case"MultiPolygon":n=e.arcs.map(u);break;default:return null}return{type:r,coordinates:n}}(e)}var ge=function(t,e){var n={},r={},i={},a=[],o=-1;function s(t,e){for(var r in t){var i=t[r];delete e[i.start],delete i.start,delete i.end,i.forEach(function(t){n[t<0?~t:t]=1}),a.push(i)}}return e.forEach(function(n,r){var i,a=t.arcs[n<0?~n:n];a.length<3&&!a[1][0]&&!a[1][1]&&(i=e[++o],e[o]=n,e[r]=i)}),e.forEach(function(e){var n,a,o=function(e){var n,r=t.arcs[e<0?~e:e],i=r[0];t.transform?(n=[0,0],r.forEach(function(t){n[0]+=t[0],n[1]+=t[1]})):n=r[r.length-1];return e<0?[n,i]:[i,n]}(e),s=o[0],u=o[1];if(n=i[s])if(delete i[n.end],n.push(e),n.end=u,a=r[u]){delete r[a.start];var c=a===n?n:n.concat(a);r[c.start=n.start]=i[c.end=a.end]=c}else r[n.start]=i[n.end]=n;else if(n=r[u])if(delete r[n.start],n.unshift(e),n.start=s,a=i[s]){delete i[a.end];var l=a===n?n:a.concat(n);r[l.start=a.start]=i[l.end=n.end]=l}else r[n.start]=i[n.end]=n;else r[(n=[e]).start=s]=i[n.end=u]=n}),s(i,r),s(r,i),e.forEach(function(t){n[t<0?~t:t]||a.push([t])}),a},ve=function(t){return me(t,function(t,e,n){var r,i,a;if(arguments.length>1)r=function(t,e,n){var r,i=[],a=[];function o(t){var e=t<0?~t:t;(a[e]||(a[e]=[])).push({i:t,g:r})}function s(t){t.forEach(o)}function u(t){t.forEach(s)}return function t(e){switch(r=e,e.type){case"GeometryCollection":e.geometries.forEach(t);break;case"LineString":s(e.arcs);break;case"MultiLineString":case"Polygon":u(e.arcs);break;case"MultiPolygon":!function(t){t.forEach(u)}(e.arcs)}}(e),a.forEach(null==n?function(t){i.push(t[0].i)}:function(t){n(t[0].g,t[t.length-1].g)&&i.push(t[0].i)}),i}(0,e,n);else for(i=0,r=new Array(a=t.arcs.length);i<a;++i)r[i]=i;return{type:"MultiLineString",arcs:ge(t,r)}}.apply(this,arguments))};const ye={interior:(t,e)=>t!==e,exterior:(t,e)=>t===e};function be(t,e){let n,r,i,a;return t=Object(ce.a)(t,e),e&&e.feature?(n=he,i=e.feature):e&&e.mesh?(n=ve,i=e.mesh,a=ye[e.filter]):Object(ct.n)("Missing TopoJSON feature or mesh parameter."),(r=(r=t.objects[i])?n(t,r,a):Object(ct.n)("Invalid TopoJSON object: "+i))&&r.features||[r]}be.responseType="json";const xe={dsv:ue,csv:se(","),tsv:se("\t"),json:ce.a,topojson:be};function we(t,e){return arguments.length>1?(xe[t]=e,this):Object(ct.v)(xe,t)?xe[t]:null}function ke(t){const e=we(t);return e&&e.responseType||"text"}var _e=new Date,Ee=new Date;function Oe(t,e,n,r){function i(e){return t(e=0===arguments.length?new Date:new Date(+e)),e}return i.floor=function(e){return t(e=new Date(+e)),e},i.ceil=function(n){return t(n=new Date(n-1)),e(n,1),t(n),n},i.round=function(t){var e=i(t),n=i.ceil(t);return t-e<n-t?e:n},i.offset=function(t,n){return e(t=new Date(+t),null==n?1:Math.floor(n)),t},i.range=function(n,r,a){var o,s=[];if(n=i.ceil(n),a=null==a?1:Math.floor(a),!(n<r&&a>0))return s;do{s.push(o=new Date(+n)),e(n,a),t(n)}while(o<n&&n<r);return s},i.filter=function(n){return Oe(function(e){if(e>=e)for(;t(e),!n(e);)e.setTime(e-1)},function(t,r){if(t>=t)if(r<0)for(;++r<=0;)for(;e(t,-1),!n(t););else for(;--r>=0;)for(;e(t,1),!n(t););})},n&&(i.count=function(e,r){return _e.setTime(+e),Ee.setTime(+r),t(_e),t(Ee),Math.floor(n(_e,Ee))},i.every=function(t){return t=Math.floor(t),isFinite(t)&&t>0?t>1?i.filter(r?function(e){return r(e)%t==0}:function(e){return i.count(0,e)%t==0}):i:null}),i}var Se=Oe(function(t){t.setMonth(0,1),t.setHours(0,0,0,0)},function(t,e){t.setFullYear(t.getFullYear()+e)},function(t,e){return e.getFullYear()-t.getFullYear()},function(t){return t.getFullYear()});Se.every=function(t){return isFinite(t=Math.floor(t))&&t>0?Oe(function(e){e.setFullYear(Math.floor(e.getFullYear()/t)*t),e.setMonth(0,1),e.setHours(0,0,0,0)},function(e,n){e.setFullYear(e.getFullYear()+n*t)}):null};var Ce=Se,Ae=(Se.range,6e4),Ne=6048e5;function Te(t){return Oe(function(e){e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-t)%7),e.setUTCHours(0,0,0,0)},function(t,e){t.setUTCDate(t.getUTCDate()+7*e)},function(t,e){return(e-t)/Ne})}var Ie=Te(0),De=Te(1),Me=Te(2),Re=Te(3),Fe=Te(4),je=Te(5),Pe=Te(6),Le=(Ie.range,De.range,Me.range,Re.range,Fe.range,je.range,Pe.range,Oe(function(t){t.setUTCHours(0,0,0,0)},function(t,e){t.setUTCDate(t.getUTCDate()+e)},function(t,e){return(e-t)/864e5},function(t){return t.getUTCDate()-1})),ze=Le;Le.range;function Be(t){return Oe(function(e){e.setDate(e.getDate()-(e.getDay()+7-t)%7),e.setHours(0,0,0,0)},function(t,e){t.setDate(t.getDate()+7*e)},function(t,e){return(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*Ae)/Ne})}var Ue=Be(0),We=Be(1),Ve=Be(2),qe=Be(3),He=Be(4),Ge=Be(5),$e=Be(6),Ke=(Ue.range,We.range,Ve.range,qe.range,He.range,Ge.range,$e.range,Oe(function(t){t.setHours(0,0,0,0)},function(t,e){t.setDate(t.getDate()+e)},function(t,e){return(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*Ae)/864e5},function(t){return t.getDate()-1})),Xe=Ke,Ye=(Ke.range,Oe(function(t){t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)},function(t,e){t.setUTCFullYear(t.getUTCFullYear()+e)},function(t,e){return e.getUTCFullYear()-t.getUTCFullYear()},function(t){return t.getUTCFullYear()}));Ye.every=function(t){return isFinite(t=Math.floor(t))&&t>0?Oe(function(e){e.setUTCFullYear(Math.floor(e.getUTCFullYear()/t)*t),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},function(e,n){e.setUTCFullYear(e.getUTCFullYear()+n*t)}):null};var Je=Ye;Ye.range;function Ze(t){if(0<=t.y&&t.y<100){var e=new Date(-1,t.m,t.d,t.H,t.M,t.S,t.L);return e.setFullYear(t.y),e}return new Date(t.y,t.m,t.d,t.H,t.M,t.S,t.L)}function Qe(t){if(0<=t.y&&t.y<100){var e=new Date(Date.UTC(-1,t.m,t.d,t.H,t.M,t.S,t.L));return e.setUTCFullYear(t.y),e}return new Date(Date.UTC(t.y,t.m,t.d,t.H,t.M,t.S,t.L))}function tn(t,e,n){return{y:t,m:e,d:n,H:0,M:0,S:0,L:0}}var en,nn,rn,an,on,sn={"-":"",_:" ",0:"0"},un=/^\s*\d+/,cn=/^%/,ln=/[\\^$*+?|[\]().{}]/g;function fn(t,e,n){var r=t<0?"-":"",i=(r?-t:t)+"",a=i.length;return r+(a<n?new Array(n-a+1).join(e)+i:i)}function dn(t){return t.replace(ln,"\\$&")}function hn(t){return new RegExp("^(?:"+t.map(dn).join("|")+")","i")}function pn(t){for(var e={},n=-1,r=t.length;++n<r;)e[t[n].toLowerCase()]=n;return e}function mn(t,e,n){var r=un.exec(e.slice(n,n+1));return r?(t.w=+r[0],n+r[0].length):-1}function gn(t,e,n){var r=un.exec(e.slice(n,n+1));return r?(t.u=+r[0],n+r[0].length):-1}function vn(t,e,n){var r=un.exec(e.slice(n,n+2));return r?(t.U=+r[0],n+r[0].length):-1}function yn(t,e,n){var r=un.exec(e.slice(n,n+2));return r?(t.V=+r[0],n+r[0].length):-1}function bn(t,e,n){var r=un.exec(e.slice(n,n+2));return r?(t.W=+r[0],n+r[0].length):-1}function xn(t,e,n){var r=un.exec(e.slice(n,n+4));return r?(t.y=+r[0],n+r[0].length):-1}function wn(t,e,n){var r=un.exec(e.slice(n,n+2));return r?(t.y=+r[0]+(+r[0]>68?1900:2e3),n+r[0].length):-1}function kn(t,e,n){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(n,n+6));return r?(t.Z=r[1]?0:-(r[2]+(r[3]||"00")),n+r[0].length):-1}function _n(t,e,n){var r=un.exec(e.slice(n,n+1));return r?(t.q=3*r[0]-3,n+r[0].length):-1}function En(t,e,n){var r=un.exec(e.slice(n,n+2));return r?(t.m=r[0]-1,n+r[0].length):-1}function On(t,e,n){var r=un.exec(e.slice(n,n+2));return r?(t.d=+r[0],n+r[0].length):-1}function Sn(t,e,n){var r=un.exec(e.slice(n,n+3));return r?(t.m=0,t.d=+r[0],n+r[0].length):-1}function Cn(t,e,n){var r=un.exec(e.slice(n,n+2));return r?(t.H=+r[0],n+r[0].length):-1}function An(t,e,n){var r=un.exec(e.slice(n,n+2));return r?(t.M=+r[0],n+r[0].length):-1}function Nn(t,e,n){var r=un.exec(e.slice(n,n+2));return r?(t.S=+r[0],n+r[0].length):-1}function Tn(t,e,n){var r=un.exec(e.slice(n,n+3));return r?(t.L=+r[0],n+r[0].length):-1}function In(t,e,n){var r=un.exec(e.slice(n,n+6));return r?(t.L=Math.floor(r[0]/1e3),n+r[0].length):-1}function Dn(t,e,n){var r=cn.exec(e.slice(n,n+1));return r?n+r[0].length:-1}function Mn(t,e,n){var r=un.exec(e.slice(n));return r?(t.Q=+r[0],n+r[0].length):-1}function Rn(t,e,n){var r=un.exec(e.slice(n));return r?(t.s=+r[0],n+r[0].length):-1}function Fn(t,e){return fn(t.getDate(),e,2)}function jn(t,e){return fn(t.getHours(),e,2)}function Pn(t,e){return fn(t.getHours()%12||12,e,2)}function Ln(t,e){return fn(1+Xe.count(Ce(t),t),e,3)}function zn(t,e){return fn(t.getMilliseconds(),e,3)}function Bn(t,e){return zn(t,e)+"000"}function Un(t,e){return fn(t.getMonth()+1,e,2)}function Wn(t,e){return fn(t.getMinutes(),e,2)}function Vn(t,e){return fn(t.getSeconds(),e,2)}function qn(t){var e=t.getDay();return 0===e?7:e}function Hn(t,e){return fn(Ue.count(Ce(t)-1,t),e,2)}function Gn(t,e){var n=t.getDay();return t=n>=4||0===n?He(t):He.ceil(t),fn(He.count(Ce(t),t)+(4===Ce(t).getDay()),e,2)}function $n(t){return t.getDay()}function Kn(t,e){return fn(We.count(Ce(t)-1,t),e,2)}function Xn(t,e){return fn(t.getFullYear()%100,e,2)}function Yn(t,e){return fn(t.getFullYear()%1e4,e,4)}function Jn(t){var e=t.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+fn(e/60|0,"0",2)+fn(e%60,"0",2)}function Zn(t,e){return fn(t.getUTCDate(),e,2)}function Qn(t,e){return fn(t.getUTCHours(),e,2)}function tr(t,e){return fn(t.getUTCHours()%12||12,e,2)}function er(t,e){return fn(1+ze.count(Je(t),t),e,3)}function nr(t,e){return fn(t.getUTCMilliseconds(),e,3)}function rr(t,e){return nr(t,e)+"000"}function ir(t,e){return fn(t.getUTCMonth()+1,e,2)}function ar(t,e){return fn(t.getUTCMinutes(),e,2)}function or(t,e){return fn(t.getUTCSeconds(),e,2)}function sr(t){var e=t.getUTCDay();return 0===e?7:e}function ur(t,e){return fn(Ie.count(Je(t)-1,t),e,2)}function cr(t,e){var n=t.getUTCDay();return t=n>=4||0===n?Fe(t):Fe.ceil(t),fn(Fe.count(Je(t),t)+(4===Je(t).getUTCDay()),e,2)}function lr(t){return t.getUTCDay()}function fr(t,e){return fn(De.count(Je(t)-1,t),e,2)}function dr(t,e){return fn(t.getUTCFullYear()%100,e,2)}function hr(t,e){return fn(t.getUTCFullYear()%1e4,e,4)}function pr(){return"+0000"}function mr(){return"%"}function gr(t){return+t}function vr(t){return Math.floor(+t/1e3)}function yr(t){return en=function(t){var e=t.dateTime,n=t.date,r=t.time,i=t.periods,a=t.days,o=t.shortDays,s=t.months,u=t.shortMonths,c=hn(i),l=pn(i),f=hn(a),d=pn(a),h=hn(o),p=pn(o),m=hn(s),g=pn(s),v=hn(u),y=pn(u),b={a:function(t){return o[t.getDay()]},A:function(t){return a[t.getDay()]},b:function(t){return u[t.getMonth()]},B:function(t){return s[t.getMonth()]},c:null,d:Fn,e:Fn,f:Bn,H:jn,I:Pn,j:Ln,L:zn,m:Un,M:Wn,p:function(t){return i[+(t.getHours()>=12)]},q:function(t){return 1+~~(t.getMonth()/3)},Q:gr,s:vr,S:Vn,u:qn,U:Hn,V:Gn,w:$n,W:Kn,x:null,X:null,y:Xn,Y:Yn,Z:Jn,"%":mr},x={a:function(t){return o[t.getUTCDay()]},A:function(t){return a[t.getUTCDay()]},b:function(t){return u[t.getUTCMonth()]},B:function(t){return s[t.getUTCMonth()]},c:null,d:Zn,e:Zn,f:rr,H:Qn,I:tr,j:er,L:nr,m:ir,M:ar,p:function(t){return i[+(t.getUTCHours()>=12)]},q:function(t){return 1+~~(t.getUTCMonth()/3)},Q:gr,s:vr,S:or,u:sr,U:ur,V:cr,w:lr,W:fr,x:null,X:null,y:dr,Y:hr,Z:pr,"%":mr},w={a:function(t,e,n){var r=h.exec(e.slice(n));return r?(t.w=p[r[0].toLowerCase()],n+r[0].length):-1},A:function(t,e,n){var r=f.exec(e.slice(n));return r?(t.w=d[r[0].toLowerCase()],n+r[0].length):-1},b:function(t,e,n){var r=v.exec(e.slice(n));return r?(t.m=y[r[0].toLowerCase()],n+r[0].length):-1},B:function(t,e,n){var r=m.exec(e.slice(n));return r?(t.m=g[r[0].toLowerCase()],n+r[0].length):-1},c:function(t,n,r){return E(t,e,n,r)},d:On,e:On,f:In,H:Cn,I:Cn,j:Sn,L:Tn,m:En,M:An,p:function(t,e,n){var r=c.exec(e.slice(n));return r?(t.p=l[r[0].toLowerCase()],n+r[0].length):-1},q:_n,Q:Mn,s:Rn,S:Nn,u:gn,U:vn,V:yn,w:mn,W:bn,x:function(t,e,r){return E(t,n,e,r)},X:function(t,e,n){return E(t,r,e,n)},y:wn,Y:xn,Z:kn,"%":Dn};function k(t,e){return function(n){var r,i,a,o=[],s=-1,u=0,c=t.length;for(n instanceof Date||(n=new Date(+n));++s<c;)37===t.charCodeAt(s)&&(o.push(t.slice(u,s)),null!=(i=sn[r=t.charAt(++s)])?r=t.charAt(++s):i="e"===r?" ":"0",(a=e[r])&&(r=a(n,i)),o.push(r),u=s+1);return o.push(t.slice(u,s)),o.join("")}}function _(t,e){return function(n){var r,i,a=tn(1900,void 0,1);if(E(a,t,n+="",0)!=n.length)return null;if("Q"in a)return new Date(a.Q);if("s"in a)return new Date(1e3*a.s+("L"in a?a.L:0));if(!e||"Z"in a||(a.Z=0),"p"in a&&(a.H=a.H%12+12*a.p),void 0===a.m&&(a.m="q"in a?a.q:0),"V"in a){if(a.V<1||a.V>53)return null;"w"in a||(a.w=1),"Z"in a?(r=(i=(r=Qe(tn(a.y,0,1))).getUTCDay())>4||0===i?De.ceil(r):De(r),r=ze.offset(r,7*(a.V-1)),a.y=r.getUTCFullYear(),a.m=r.getUTCMonth(),a.d=r.getUTCDate()+(a.w+6)%7):(r=(i=(r=Ze(tn(a.y,0,1))).getDay())>4||0===i?We.ceil(r):We(r),r=Xe.offset(r,7*(a.V-1)),a.y=r.getFullYear(),a.m=r.getMonth(),a.d=r.getDate()+(a.w+6)%7)}else("W"in a||"U"in a)&&("w"in a||(a.w="u"in a?a.u%7:"W"in a?1:0),i="Z"in a?Qe(tn(a.y,0,1)).getUTCDay():Ze(tn(a.y,0,1)).getDay(),a.m=0,a.d="W"in a?(a.w+6)%7+7*a.W-(i+5)%7:a.w+7*a.U-(i+6)%7);return"Z"in a?(a.H+=a.Z/100|0,a.M+=a.Z%100,Qe(a)):Ze(a)}}function E(t,e,n,r){for(var i,a,o=0,s=e.length,u=n.length;o<s;){if(r>=u)return-1;if(37===(i=e.charCodeAt(o++))){if(i=e.charAt(o++),!(a=w[i in sn?e.charAt(o++):i])||(r=a(t,n,r))<0)return-1}else if(i!=n.charCodeAt(r++))return-1}return r}return b.x=k(n,b),b.X=k(r,b),b.c=k(e,b),x.x=k(n,x),x.X=k(r,x),x.c=k(e,x),{format:function(t){var e=k(t+="",b);return e.toString=function(){return t},e},parse:function(t){var e=_(t+="",!1);return e.toString=function(){return t},e},utcFormat:function(t){var e=k(t+="",x);return e.toString=function(){return t},e},utcParse:function(t){var e=_(t+="",!0);return e.toString=function(){return t},e}}}(t),nn=en.format,rn=en.parse,an=en.utcFormat,on=en.utcParse,en}yr({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]});var br=function(t,e,n){const r=we((e=e||{}).type||"json");return r||Object(ct.n)("Unknown data format type: "+e.type),t=r(t,e),e.parse&&function(t,e,n){if(!t.length)return;n=n||rn;var r,i,a,o,s,u,c,l=t.columns||Object.keys(t[0]);"auto"===e&&(e=Kt(t,l));for(l=Object.keys(e),r=l.map(function(t){var r,i,a=e[t];if(a&&(a.startsWith("date:")||a.startsWith("utc:")))return("'"===(i=(r=a.split(/:(.+)?/,2))[1])[0]&&"'"===i[i.length-1]||'"'===i[0]&&'"'===i[i.length-1])&&(i=i.slice(1,-1)),"utc"===r[0]?on(i):n(i);if(!qt[a])throw Error("Illegal format pattern: "+t+":"+a);return qt[a]}),o=0,u=t.length,c=l.length;o<u;++o)for(i=t[o],s=0;s<c;++s)a=l[s],i[a]=r[s](i[a])}(t,e.parse,n),Object(ct.v)(t,"columns")&&delete t.columns,t};var xr=function(t,e){return function(n){return{options:n||{},sanitize:Ut,load:Bt,fileAccess:!!e,file:function(t){return t?function(e){return new Promise(function(n,r){t.readFile(e,function(t,e){t?r(t):n(e)})})}:Wt}(e),http:function(t){return t?async function(e,n){const r=Object(ct.o)({},this.options.http,n),i=n&&n.response,a=await t(e,r);return a.ok?Object(ct.D)(a[i])?a[i]():a.text():Object(ct.n)(a.status+""+a.statusText)}:Vt}(t)}}}("undefined"!=typeof fetch&&fetch,null);const wr=br;var kr={skip:!0};function _r(t,e,n,r,i,a){var o,s,u=Object(ct.o)({},a,kr);Object(ct.D)(n)||(n=Object(ct.l)(n)),void 0===r?o=(e=>t.touch(n(e))):Object(ct.D)(r)?(s=new Nt(null,r,i,!1),o=(e=>{s.evaluate(e);const r=n(e),i=s.value;kt(i)?t.pulse(r,i,a):t.update(r,i,u)})):o=(e=>t.update(n(e),r,u)),e.apply(o)}function Er(t,e,n,r,i,a){if(void 0===r)e.targets().add(n);else{const o=a||{},s=new Nt(null,function(t,e){return e=Object(ct.D)(e)?e:Object(ct.l)(e),t?function(n,r){const i=e(n,r);return t.skip()||(t.skip(i!==this.value).value=i),i}:e}(n,r),i,!1);s.modified(o.force),s.rank=e.rank,e.targets().add(s),n&&(s.skip(!0),s.value=n.value,s.targets().add(n),t.connect(n,[s]))}}var Or={};function Sr(t,e,n){this.dataflow=t,this.stamp=null==e?-1:e,this.add=[],this.rem=[],this.mod=[],this.fields=null,this.encode=n||null}var Cr=Sr.prototype;function Ar(t,e){return t?function(n,r){return t(n,r)&&e(n,r)}:e}function Nr(t,e){var n=[];return Object(ct.Ia)(t,e,function(t){n.push(t)}),n}function Tr(t,e){var n={};return t.visit(e,function(t){n[mt(t)]=1}),function(t){return n[mt(t)]?null:t}}function Ir(t,e,n,r){var i,a,o,s,u,c=this,l=0;for(this.dataflow=t,this.stamp=e,this.fields=null,this.encode=r||null,this.pulses=n,o=0,s=n.length;o<s;++o)if((i=n[o]).stamp===e){if(i.fields)for(u in a=c.fields||(c.fields={}),i.fields)a[u]=1;i.changed(c.ADD)&&(l|=c.ADD),i.changed(c.REM)&&(l|=c.REM),i.changed(c.MOD)&&(l|=c.MOD)}this.changes=l}Cr.StopPropagation=Or,Cr.ADD=1,Cr.REM=2,Cr.MOD=4,Cr.ADD_REM=3,Cr.ADD_MOD=5,Cr.ALL=7,Cr.REFLOW=8,Cr.SOURCE=16,Cr.NO_SOURCE=32,Cr.NO_FIELDS=64,Cr.fork=function(t){return new Sr(this.dataflow).init(this,t)},Cr.clone=function(){var t=this.fork(7);return t.add=t.add.slice(),t.rem=t.rem.slice(),t.mod=t.mod.slice(),t.source&&(t.source=t.source.slice()),t.materialize(23)},Cr.addAll=function(){var t=this;return this.source&&this.source.length!==this.add.length?((t=new Sr(this.dataflow).init(this)).add=t.source,t):t},Cr.init=function(t,e){var n=this;return n.stamp=t.stamp,n.encode=t.encode,!t.fields||64&e||(n.fields=t.fields),1&e?(n.addF=t.addF,n.add=t.add):(n.addF=null,n.add=[]),2&e?(n.remF=t.remF,n.rem=t.rem):(n.remF=null,n.rem=[]),4&e?(n.modF=t.modF,n.mod=t.mod):(n.modF=null,n.mod=[]),32&e?(n.srcF=null,n.source=null):(n.srcF=t.srcF,n.source=t.source),n},Cr.runAfter=function(t){this.dataflow.runAfter(t)},Cr.changed=function(t){var e=t||7;return 1&e&&this.add.length||2&e&&this.rem.length||4&e&&this.mod.length},Cr.reflow=function(t){if(t)return this.fork(7).reflow();var e=this.add.length,n=this.source&&this.source.length;return n&&n!==e&&(this.mod=this.source,e&&this.filter(4,Tr(this,1))),this},Cr.modifies=function(t){var e=this.fields||(this.fields={});return Object(ct.A)(t)?t.forEach(t=>e[t]=!0):e[t]=!0,this},Cr.modified=function(t,e){var n=this.fields;return!(!e&&!this.mod.length||!n)&&(arguments.length?Object(ct.A)(t)?t.some(function(t){return n[t]}):n[t]:!!n)},Cr.filter=function(t,e){var n=this;return 1&t&&(n.addF=Ar(n.addF,e)),2&t&&(n.remF=Ar(n.remF,e)),4&t&&(n.modF=Ar(n.modF,e)),16&t&&(n.srcF=Ar(n.srcF,e)),n},Cr.materialize=function(t){var e=this;return 1&(t=t||7)&&e.addF&&(e.add=Nr(e.add,e.addF),e.addF=null),2&t&&e.remF&&(e.rem=Nr(e.rem,e.remF),e.remF=null),4&t&&e.modF&&(e.mod=Nr(e.mod,e.modF),e.modF=null),16&t&&e.srcF&&(e.source=e.source.filter(e.srcF),e.srcF=null),e},Cr.visit=function(t,e){var n,r,i=this,a=e;return 16&t?(Object(ct.Ia)(i.source,i.srcF,a),i):(1&t&&Object(ct.Ia)(i.add,i.addF,a),2&t&&Object(ct.Ia)(i.rem,i.remF,a),4&t&&Object(ct.Ia)(i.mod,i.modF,a),8&t&&(n=i.source)&&((r=i.add.length+i.mod.length)===n.length||(r?Object(ct.Ia)(n,Tr(i,5),a):Object(ct.Ia)(n,i.srcF,a))),i)};var Dr=Object(ct.y)(Ir,Sr);function Mr(t){return t.error("Dataflow already running. Use runAsync() to chain invocations."),t}Dr.fork=function(t){var e=new Sr(this.dataflow).init(this,t&this.NO_FIELDS);return void 0!==t&&(t&e.ADD&&this.visit(e.ADD,function(t){return e.add.push(t)}),t&e.REM&&this.visit(e.REM,function(t){return e.rem.push(t)}),t&e.MOD&&this.visit(e.MOD,function(t){return e.mod.push(t)})),e},Dr.changed=function(t){return this.changes&t},Dr.modified=function(t){var e=this,n=e.fields;return n&&e.changes&e.MOD?Object(ct.A)(t)?t.some(function(t){return n[t]}):n[t]:0},Dr.filter=function(){Object(ct.n)("MultiPulse does not support filtering.")},Dr.materialize=function(){Object(ct.n)("MultiPulse does not support materialization.")},Dr.visit=function(t,e){var n=this,r=n.pulses,i=r.length,a=0;if(t&n.SOURCE)for(;a<i;++a)r[a].visit(t,e);else for(;a<i;++a)r[a].stamp===n.stamp&&r[a].visit(t,e);return n};var Rr={skip:!1,force:!1};function Fr(t){var e=[];return{clear:()=>e=[],size:()=>e.length,peek:()=>e[0],push:n=>(e.push(n),jr(e,0,e.length-1,t)),pop:()=>{var n,r=e.pop();return e.length?(n=e[0],e[0]=r,function(t,e,n){var r,i=e,a=t.length,o=t[e],s=1+(e<<1);for(;s<a;)(r=s+1)<a&&n(t[s],t[r])>=0&&(s=r),t[e]=t[s],s=1+((e=s)<<1);t[e]=o,jr(t,i,e,n)}(e,0,t)):n=r,n}}}function jr(t,e,n,r){var i,a,o;for(i=t[n];n>e&&r(i,a=t[o=n-1>>1])<0;)t[n]=a,n=o;return t[n]=i}function Pr(){this.logger(Object(ct.K)()),this.logLevel(ct.b),this._clock=0,this._rank=0;try{this._loader=xr()}catch(t){}this._touched=lt(ct.w),this._input={},this._pulse=null,this._heap=Fr((t,e)=>t.qrank-e.qrank),this._postrun=[]}var Lr=Pr.prototype;function zr(t){return function(){return this._log[t].apply(this,arguments)}}function Br(t,e){Nt.call(this,t,null,e)}Lr.stamp=function(){return this._clock},Lr.loader=function(t){return arguments.length?(this._loader=t,this):this._loader},Lr.cleanThreshold=1e4,Lr.add=function(t,e,n,r){var i,a=1;return t instanceof Nt?i=t:t&&t.prototype instanceof Nt?i=new t:Object(ct.D)(t)?i=new Nt(null,t):(a=0,i=new Nt(t,e)),this.rank(i),a&&(r=n,n=e),n&&this.connect(i,i.parameters(n,r)),this.touch(i),i},Lr.connect=function(t,e){var n,r,i=t.rank;for(n=0,r=e.length;n<r;++n)if(i<e[n].rank)return void this.rerank(t)},Lr.rank=function(t){t.rank=++this._rank},Lr.rerank=function(t){for(var e,n,r,i=[t];i.length;)if(this.rank(e=i.pop()),n=e._targets)for(r=n.length;--r>=0;)i.push(e=n[r]),e===t&&Object(ct.n)("Cycle detected in dataflow graph.")},Lr.pulse=function(t,e,n){this.touch(t,n||Rr);var r=new Sr(this,this._clock+(this._pulse?0:1)),i=t.pulse&&t.pulse.source||[];return r.target=t,this._input[t.id]=e.pulse(r,i),this},Lr.touch=function(t,e){var n=e||Rr;return this._pulse?this._enqueue(t):this._touched.add(t),n.skip&&t.skip(!0),this},Lr.update=function(t,e,n){var r=n||Rr;return(t.set(e)||r.force)&&this.touch(t,r),this},Lr.changeset=_t,Lr.ingest=function(t,e,n){return this.pulse(t,this.changeset().insert(wr(e,n)))},Lr.parse=wr,Lr.preload=async function(t,e,n){const r=this,i=r._pending||function(t){var e,n=new Promise(function(t){e=t});return n.requests=0,n.done=function(){0==--n.requests&&(t._pending=null,e(t))},t._pending=n}(r);i.requests+=1;const a=await r.request(e,n);return r.pulse(t,r.changeset().remove(ct.Ga).insert(a.data||[])),i.done(),a},Lr.request=async function(t,e){const n=this;let r,i=0;try{r=await n.loader().load(t,{context:"dataflow",response:ke(e&&e.type)});try{r=wr(r,e)}catch(e){i=-2,n.warn("Data ingestion failed",t,e)}}catch(e){i=-1,n.warn("Loading failed",t,e)}return{data:r,status:i}},Lr.events=function(t,e,n,r){for(var i,a=this,o=Rt(n,r),s=function(t){t.dataflow=a;try{o.receive(t)}catch(t){a.error(t)}finally{a.run()}},u=0,c=(i="string"==typeof t&&"undefined"!=typeof document?document.querySelectorAll(t):Object(ct.i)(t)).length;u<c;++u)i[u].addEventListener(e,s);return o},Lr.on=function(t,e,n,r,i){return(t instanceof Nt?Er:_r)(this,t,e,n,r,i),this},Lr.evaluate=async function(t,e,n){const r=this,i=r.logLevel(),a=[];if(r._pulse)return Mr(r);if(r._pending&&await r._pending,e&&await ft(r,e),!r._touched.length)return r.info("Dataflow invoked, but nothing to do."),r;let o,s,u,c,l=++r._clock,f=0;r._pulse=new Sr(r,l,t),i>=ct.c&&(u=Date.now(),r.debug("-- START PROPAGATION ("+l+") -----")),r._touched.forEach(t=>r._enqueue(t,!0)),r._touched=lt(ct.w);try{for(;r._heap.size()>0;)(o=r._heap.pop()).rank===o.qrank?((s=o.run(r._getPulse(o,t))).then?s=await s:s.async&&(a.push(s.async),s=Or),i>=ct.a&&r.debug(o.id,s===Or?"STOP":s,o),s!==Or&&o._targets&&o._targets.forEach(t=>r._enqueue(t)),++f):r._enqueue(o,!0)}catch(t){r._heap.clear(),c=t}if(r._input={},r._pulse=null,i>=ct.c&&(u=Date.now()-u,r.info("> Pulse "+l+": "+f+" operators; "+u+"ms")),c&&(r._postrun=[],r.error(c)),r._postrun.length){const t=r._postrun.sort((t,e)=>e.priority-t.priority);r._postrun=[];for(let e=0;e<t.length;++e)await ft(r,t[e].callback)}return n&&await ft(r,n),a.length&&Promise.all(a).then(t=>r.runAsync(null,()=>{t.forEach(t=>{try{t(r)}catch(t){r.error(t)}})})),r},Lr.run=function(t,e,n){return this._pulse?Mr(this):(this.evaluate(t,e,n),this)},Lr.runAsync=async function(t,e,n){for(;this._running;)await this._running;const r=()=>this._running=null;return(this._running=this.evaluate(t,e,n)).then(r,r),this._running},Lr.runAfter=function(t,e,n){if(this._pulse||e)this._postrun.push({priority:n||0,callback:t});else try{t(this)}catch(t){this.error(t)}},Lr._enqueue=function(t,e){var n=t.stamp<this._clock;n&&(t.stamp=this._clock),(n||e)&&(t.qrank=t.rank,this._heap.push(t))},Lr._getPulse=function(t,e){var n=t.source,r=this._clock;return n&&Object(ct.A)(n)?new Ir(this,r,n.map(t=>t.pulse),e):this._input[t.id]||function(t,e){return e&&e.stamp===t.stamp?e:(t=t.fork(),e&&e!==Or&&(t.source=e.source),t)}(this._pulse,n&&n.pulse)},Lr.logger=function(t){return arguments.length?(this._log=t,this):this._log},Lr.error=zr("error"),Lr.warn=zr("warn"),Lr.info=zr("info"),Lr.debug=zr("debug"),Lr.logLevel=zr("level");var Ur=Object(ct.y)(Br,Nt);Ur.run=function(t){return t.stamp<this.stamp?t.StopPropagation:(this.skip()?this.skip(!1):e=this.evaluate(t),(e=e||t).then?e=e.then(t=>this.pulse=t):e!==t.StopPropagation&&(this.pulse=e),e);var e},Ur.evaluate=function(t){var e=this.marshall(t.stamp),n=this.transform(e,t);return e.clear(),n},Ur.transform=function(){};var Wr={};function Vr(t){var e=qr(t);return e&&e.Definition||null}function qr(t){return t=t&&t.toLowerCase(),Object(ct.v)(Wr,t)?Wr[t]:null}function Hr(t){return t&&t.length?1===t.length?t[0]:function(t){return function(e){for(var n=t.length,r=1,i=String(t[0](e));r<n;++r)i+="|"+t[r](e);return i}}(t):function(){return""}}function Gr(t,e,n){return n||t+(e?"_"+e:"")}var $r={values:Yr({name:"values",init:"cell.store = true;",set:"cell.data.values()",idx:-1}),count:Yr({name:"count",set:"cell.num"}),__count__:Yr({name:"count",set:"this.missing + this.valid"}),missing:Yr({name:"missing",set:"this.missing"}),valid:Yr({name:"valid",set:"this.valid"}),sum:Yr({name:"sum",init:"this.sum = 0;",add:"this.sum += +v;",rem:"this.sum -= v;",set:"this.sum"}),product:Yr({name:"product",init:"this.product = 1;",add:"this.product *= v;",rem:"this.product /= v;",set:"this.valid ? this.product : undefined"}),mean:Yr({name:"mean",init:"this.mean = 0;",add:"var d = v - this.mean; this.mean += d / this.valid;",rem:"var d = v - this.mean; this.mean -= this.valid ? d / this.valid : this.mean;",set:"this.valid ? this.mean : undefined"}),average:Yr({name:"average",set:"this.valid ? this.mean : undefined",req:["mean"],idx:1}),variance:Yr({name:"variance",init:"this.dev = 0;",add:"this.dev += d * (v - this.mean);",rem:"this.dev -= d * (v - this.mean);",set:"this.valid > 1 ? this.dev / (this.valid-1) : undefined",req:["mean"],idx:1}),variancep:Yr({name:"variancep",set:"this.valid > 1 ? this.dev / this.valid : undefined",req:["variance"],idx:2}),stdev:Yr({name:"stdev",set:"this.valid > 1 ? Math.sqrt(this.dev / (this.valid-1)) : undefined",req:["variance"],idx:2}),stdevp:Yr({name:"stdevp",set:"this.valid > 1 ? Math.sqrt(this.dev / this.valid) : undefined",req:["variance"],idx:2}),stderr:Yr({name:"stderr",set:"this.valid > 1 ? Math.sqrt(this.dev / (this.valid * (this.valid-1))) : undefined",req:["variance"],idx:2}),distinct:Yr({name:"distinct",set:"cell.data.distinct(this.get)",req:["values"],idx:3}),ci0:Yr({name:"ci0",set:"cell.data.ci0(this.get)",req:["values"],idx:3}),ci1:Yr({name:"ci1",set:"cell.data.ci1(this.get)",req:["values"],idx:3}),median:Yr({name:"median",set:"cell.data.q2(this.get)",req:["values"],idx:3}),q1:Yr({name:"q1",set:"cell.data.q1(this.get)",req:["values"],idx:3}),q3:Yr({name:"q3",set:"cell.data.q3(this.get)",req:["values"],idx:3}),argmin:Yr({name:"argmin",init:"this.argmin = undefined;",add:"if (v < this.min) this.argmin = t;",rem:"if (v <= this.min) this.argmin = undefined;",set:"this.argmin || cell.data.argmin(this.get)",req:["min"],str:["values"],idx:3}),argmax:Yr({name:"argmax",init:"this.argmax = undefined;",add:"if (v > this.max) this.argmax = t;",rem:"if (v >= this.max) this.argmax = undefined;",set:"this.argmax || cell.data.argmax(this.get)",req:["max"],str:["values"],idx:3}),min:Yr({name:"min",init:"this.min = undefined;",add:"if (v < this.min || this.min === undefined) this.min = v;",rem:"if (v <= this.min) this.min = NaN;",set:"this.min = (Number.isNaN(this.min) ? cell.data.min(this.get) : this.min)",str:["values"],idx:4}),max:Yr({name:"max",init:"this.max = undefined;",add:"if (v > this.max || this.max === undefined) this.max = v;",rem:"if (v >= this.max) this.max = NaN;",set:"this.max = (Number.isNaN(this.max) ? cell.data.max(this.get) : this.max)",str:["values"],idx:4})},Kr=Object.keys($r);function Xr(t,e){return $r[t](e)}function Yr(t){return function(e){var n=Object(ct.o)({init:"",add:"",rem:"",idx:0},t);return n.out=e||t.name,n}}function Jr(t,e){return t.idx-e.idx}function Zr(t,e){var n=e||ct.x,r="var cell = this.cell; this.valid = 0; this.missing = 0;",i="this.cell = cell; this.init();",a="if(v==null){++this.missing; return;} if(v!==v) return; ++this.valid;",o="if(v==null){--this.missing; return;} if(v!==v) return; --this.valid;",s="var cell = this.cell;";return function(t,e){var n,r=t.reduce(function t(n,r){function i(e){n[e]||t(n,n[e]=$r[e]())}return r.req&&r.req.forEach(i),e&&r.str&&r.str.forEach(i),n},t.reduce(function(t,e){return t[e.name]=e,t},{})),i=[];for(n in r)i.push(r[n]);return i.sort(Jr)}(t,!0).forEach(function(t){r+=t.init,a+=t.add,o+=t.rem}),t.slice().sort(Jr).forEach(function(t){s+="t["+Object(ct.Z)(t.out)+"]="+t.set+";"}),s+="return t;",(i=Function("cell",i)).prototype.init=Function(r),i.prototype.add=Function("v","t",a),i.prototype.rem=Function("v","t",o),i.prototype.set=Function("t",s),i.prototype.get=n,i.fields=t.map(function(t){return t.out}),i}var Qr=function*(t,e){if(void 0===e)for(let e of t)null!=e&&(e=+e)>=e&&(yield e);else{let n=-1;for(let r of t)null!=(r=e(r,++n,t))&&(r=+r)>=r&&(yield r)}},ti=function(t,e){return t<e?-1:t>e?1:t>=e?0:NaN};function ei(t,e){let n;if(void 0===e)for(const e of t)null!=e&&(n<e||void 0===n&&e>=e)&&(n=e);else{let r=-1;for(let i of t)null!=(i=e(i,++r,t))&&(n<i||void 0===n&&i>=i)&&(n=i)}return n}function ni(t,e){let n;if(void 0===e)for(const e of t)null!=e&&(n>e||void 0===n&&e>=e)&&(n=e);else{let r=-1;for(let i of t)null!=(i=e(i,++r,t))&&(n>i||void 0===n&&i>=i)&&(n=i)}return n}function ri(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}var ii=function(t){return null===t?NaN:+t};function ai(t,e,n){if(r=(t=Float64Array.from(function*(t,e){if(void 0===e)for(let e of t)null!=e&&(e=+e)>=e&&(yield e);else{let n=-1;for(let r of t)null!=(r=e(r,++n,t))&&(r=+r)>=r&&(yield r)}}(t,n))).length){if((e=+e)<=0||r<2)return ni(t);if(e>=1)return ei(t);var r,i=(r-1)*e,a=Math.floor(i),o=ei(function t(e,n,r=0,i=e.length-1,a=ti){for(;i>r;){if(i-r>600){const o=i-r+1,s=n-r+1,u=Math.log(o),c=.5*Math.exp(2*u/3),l=.5*Math.sqrt(u*c*(o-c)/o)*(s-o/2<0?-1:1);t(e,n,Math.max(r,Math.floor(n-s*c/o+l)),Math.min(i,Math.floor(n+(o-s)*c/o+l)),a)}const o=e[n];let s=r,u=i;for(ri(e,r,n),a(e[i],o)>0&&ri(e,r,i);s<u;){for(ri(e,s,u),++s,--u;a(e[s],o)<0;)++s;for(;a(e[u],o)>0;)--u}0===a(e[r],o)?ri(e,r,u):ri(e,++u,i),u<=n&&(r=u+1),n<=u&&(i=u-1)}return e}(t,a).subarray(0,a+1));return o+(ni(t.subarray(a+1))-o)*(i-a)}}var oi=function(t,e,n){var r=Float64Array.from(Qr(t,n));return r.sort(ti),e.map(t=>(function(t,e,n=ii){if(r=t.length){if((e=+e)<=0||r<2)return+n(t[0],0,t);if(e>=1)return+n(t[r-1],r-1,t);var r,i=(r-1)*e,a=Math.floor(i),o=+n(t[a],a,t);return o+(+n(t[a+1],a+1,t)-o)*(i-a)}})(r,t))},si=function(t,e){return oi(t,[.25,.5,.75],e)};var ui=function(t,e){var n=t.length,r=function(t,e){const n=function(t,e){let n,r=0,i=0,a=0;if(void 0===e)for(let e of t)null!=e&&(e=+e)>=e&&(a+=(n=e-i)*(e-(i+=n/++r)));else{let o=-1;for(let s of t)null!=(s=e(s,++o,t))&&(s=+s)>=s&&(a+=(n=s-i)*(s-(i+=n/++r)))}if(r>1)return a/(r-1)}(t,e);return n?Math.sqrt(n):n}(t,e),i=si(t,e),a=(i[2]-i[0])/1.34;return 1.06*(r=Math.min(r,a)||r||Math.abs(i[0])||1)*Math.pow(n,-.2)},ci=function(t){var e,n,r,i,a,o,s,u,c=t.maxbins||20,l=t.base||10,f=Math.log(l),d=t.divide||[5,2],h=t.extent[0],p=t.extent[1],m=t.span||p-h||Math.abs(h)||1;if(t.step)e=t.step;else if(t.steps){for(a=m/c,o=0,s=t.steps.length;o<s&&t.steps[o]<a;++o);e=t.steps[Math.max(0,o-1)]}else{for(n=Math.ceil(Math.log(c)/f),r=t.minstep||0,e=Math.max(r,Math.pow(l,Math.round(Math.log(m)/f)-n));Math.ceil(m/e)>c;)e*=l;for(o=0,s=d.length;o<s;++o)(a=e/d[o])>=r&&m/a<=c&&(e=a)}return i=(a=Math.log(e))>=0?0:1+~~(-a/f),u=Math.pow(l,-i-1),(t.nice||void 0===t.nice)&&(h=h<(a=Math.floor(h/e+u)*e)?a-e:a,p=Math.ceil(p/e)*e),{start:h,stop:p===h?h+e:p,step:e}},li=Math.random;function fi(t){li=t}var di=function(t,e,n,r){if(!t.length)return[void 0,void 0];var i,a,o,s,u=Float64Array.from(Qr(t,r)),c=u.length,l=e;for(o=0,s=Array(l);o<l;++o){for(i=0,a=0;a<c;++a)i+=u[~~(li()*c)];s[o]=i/c}return s.sort(ti),[ai(s,n/2),ai(s,1-n/2)]},hi=function(t,e,n,r){r=r||(t=>t);let i,a=0,o=1,s=t.length,u=new Float64Array(s),c=r(t[0]),l=c,f=c+e;for(;o<s;++o){if((i=r(t[o]))>=f){for(l=(c+l)/2;a<o;++a)u[a]=l;f=i+e,c=i}l=i}for(l=(c+l)/2;a<o;++a)u[a]=l;return n?function(t,e){let n,r,i=t.length,a=0,o=1;for(;t[a]===t[o];)++o;for(;o<i;){for(n=o+1;t[o]===t[n];)++n;if(t[o]-t[o-1]<e){for(r=o+(a+n-o-o>>1);r<o;)t[r++]=t[o];for(;r>o;)t[r--]=t[a]}a=o,o=n}return t}(u,e+e/4):u};var pi=function(t){return function(){return(t=(1103515245*t+12345)%2147483647)/2147483647}},mi=function(t,e){null==e&&(e=t,t=0);var n,r,i,a={};return a.min=function(t){return arguments.length?(i=r-(n=t||0),a):n},a.max=function(t){return arguments.length?(i=(r=t||0)-n,a):r},a.sample=function(){return n+Math.floor(i*li())},a.pdf=function(t){return t===Math.floor(t)&&t>=n&&t<r?1/i:0},a.cdf=function(t){var e=Math.floor(t);return e<n?0:e>=r?1:(e-n+1)/i},a.icdf=function(t){return t>=0&&t<=1?n-1+Math.floor(t*i):NaN},a.min(t).max(e)};const gi=Math.sqrt(2*Math.PI),vi=Math.SQRT2;let yi=NaN;function bi(t,e){t=t||0,e=null==e?1:e;let n,r,i=0,a=0;if(yi==yi)i=yi,yi=NaN;else{do{n=(i=2*li()-1)*i+(a=2*li()-1)*a}while(0===n||n>1);i*=r=Math.sqrt(-2*Math.log(n)/n),yi=a*r}return t+i*e}function xi(t,e,n){n=null==n?1:n;const r=(t-(e||0))/n;return Math.exp(-.5*r*r)/(n*gi)}function wi(t,e,n){let r,i=(t-(e=e||0))/(n=null==n?1:n),a=Math.abs(i);if(a>37)r=0;else{let t,e=Math.exp(-a*a/2);a<7.07106781186547?(r=e*(t=(t=(t=(t=(t=(t=.0352624965998911*a+.700383064443688)*a+6.37396220353165)*a+33.912866078383)*a+112.079291497871)*a+221.213596169931)*a+220.206867912376),r/=t=(t=(t=(t=(t=(t=(t=.0883883476483184*a+1.75566716318264)*a+16.064177579207)*a+86.7807322029461)*a+296.564248779674)*a+637.333633378831)*a+793.826512519948)*a+440.413735824752):r=e/(t=a+1/(t=a+2/(t=a+3/(t=a+4/(t=a+.65)))))/2.506628274631}return i>0?1-r:r}function ki(t,e,n){return t<0||t>1?NaN:(e||0)+(null==n?1:n)*vi*function(t){let e,n=-Math.log((1-t)*(1+t));n<6.25?e=1.6536545626831027+(e=.24015818242558962+(e=(e=(e=.00018673420803405714+(e=(e=(e=4.2347877827932404e-7+(e=(e=(e=1.0512122733215323e-9+(e=(e=(e=2.6335093153082323e-12+(e=(e=(e=6.637638134358324e-15+(e=2.0972767875968562e-17+(e=(e=1.1157877678025181e-17+(e=1.28584807152564e-18+(e=(e=-3.64441206401782e-21)*(n-=3.125)-1.6850591381820166e-19)*n)*n)*n-1.333171662854621e-16)*n)*n)*n-4.054566272975207e-14)*n-8.151934197605472e-14)*n)*n-1.2975133253453532e-11)*n-5.415412054294628e-11)*n)*n-4.112633980346984e-9)*n-2.9070369957882005e-8)*n)*n-13654692000834679e-22)*n-13882523362786469e-21)*n)*n-.000740702534166267)*n-.006033670871430149)*n)*n:n<16?(n=Math.sqrt(n)-3.25,e=3.0838856104922208+(e=1.0052589676941592+(e=.005370914553590064+(e=(e=.002491442096107851+(e=(e=.0009532893797373805+(e=(e=24031110387097894e-21+(e=6828485145957318e-20+(e=(e=12475304481671779e-21+(e=29234449089955446e-22+(e=(e=15027403968909828e-22+(e=1.8239629214389228e-8+(e=(e=9.075656193888539e-8+(e=2.2137376921775787e-9)*n)*n-2.7517406297064545e-7)*n)*n)*n-4013867526981546e-21)*n)*n)*n-47318229009055734e-21)*n)*n)*n-.0003550375203628475)*n)*n-.0016882755560235047)*n)*n-.003751208507569241)*n)*n)*n):Number.isFinite(n)?(n=Math.sqrt(n)-5,e=4.849906401408584+(e=1.0103004648645344+(e=(e=(e=7599527703001776e-20+(e=(e=4526062597223154e-21+(e=(e=2.2900482228026655e-7+(e=(e=2.914795345090108e-8+(e=(e=7.61570120807834e-9+(e=(e=1.5076572693500548e-9+(e=(e=-2.7109920616438573e-11)*n-2.555641816996525e-10)*n)*n-3.789465440126737e-9)*n)*n-1.496002662714924e-8)*n)*n-6.771199775845234e-8)*n)*n-9.9298272942317e-7)*n)*n-1968177810553167e-20)*n)*n-.00021503011930044477)*n-.00013871931833623122)*n)*n):e=1/0;return e*t}(2*t-1)}var _i=function(t,e){var n,r,i={mean:function(t){return arguments.length?(n=t||0,i):n},stdev:function(t){return arguments.length?(r=null==t?1:t,i):r},sample:()=>bi(n,r),pdf:t=>xi(t,n,r),cdf:t=>wi(t,n,r),icdf:t=>ki(t,n,r)};return i.mean(t).stdev(e)},Ei=function(t,e){var n=_i(),r={},i=0;return r.data=function(n){return arguments.length?(t=n,i=n?n.length:0,r.bandwidth(e)):t},r.bandwidth=function(n){return arguments.length?(!(e=n)&&t&&(e=ui(t)),r):e},r.sample=function(){return t[~~(li()*i)]+e*n.sample()},r.pdf=function(r){for(var a=0,o=0;o<i;++o)a+=n.pdf((r-t[o])/e);return a/e/i},r.cdf=function(r){for(var a=0,o=0;o<i;++o)a+=n.cdf((r-t[o])/e);return a/i},r.icdf=function(){throw Error("KDE icdf not supported.")},r.data(t)};function Oi(t,e){return t=t||0,e=null==e?1:e,Math.exp(t+bi()*e)}function Si(t,e,n){if(t<=0)return 0;e=e||0,n=null==n?1:n;const r=(Math.log(t)-e)/n;return Math.exp(-.5*r*r)/(n*gi*t)}function Ci(t,e,n){return wi(Math.log(t),e,n)}function Ai(t,e,n){return Math.exp(ki(t,e,n))}var Ni=function(t,e){var n,r,i={mean:function(t){return arguments.length?(n=t||0,i):n},stdev:function(t){return arguments.length?(r=null==t?1:t,i):r},sample:()=>Oi(n,r),pdf:t=>Si(t,n,r),cdf:t=>Ci(t,n,r),icdf:t=>Ai(t,n,r)};return i.mean(t).stdev(e)},Ti=function(t,e){var n,r={},i=0;return r.weights=function(t){return arguments.length?(n=function(t){var e,n=[],r=0;for(e=0;e<i;++e)r+=n[e]=null==t[e]?1:+t[e];for(e=0;e<i;++e)n[e]/=r;return n}(e=t||[]),r):e},r.distributions=function(n){return arguments.length?(n?(i=n.length,t=n):(i=0,t=[]),r.weights(e)):t},r.sample=function(){for(var e=li(),r=t[i-1],a=n[0],o=0;o<i-1;a+=n[++o])if(e<a){r=t[o];break}return r.sample()},r.pdf=function(e){for(var r=0,a=0;a<i;++a)r+=n[a]*t[a].pdf(e);return r},r.cdf=function(e){for(var r=0,a=0;a<i;++a)r+=n[a]*t[a].cdf(e);return r},r.icdf=function(){throw Error("Mixture icdf not supported.")},r.distributions(t).weights(e)};function Ii(t,e){return null==e&&(e=null==t?1:t,t=0),t+(e-t)*li()}function Di(t,e,n){return null==n&&(n=null==e?1:e,e=0),t>=e&&t<=n?1/(n-e):0}function Mi(t,e,n){return null==n&&(n=null==e?1:e,e=0),t<e?0:t>n?1:(t-e)/(n-e)}function Ri(t,e,n){return null==n&&(n=null==e?1:e,e=0),t>=0&&t<=1?e+t*(n-e):NaN}var Fi=function(t,e){var n,r,i={min:function(t){return arguments.length?(n=t||0,i):n},max:function(t){return arguments.length?(r=null==t?1:t,i):r},sample:()=>Ii(n,r),pdf:t=>Di(t,n,r),cdf:t=>Mi(t,n,r),icdf:t=>Ri(t,n,r)};return null==e&&(e=null==t?1:t,t=0),i.min(t).max(e)},ji=function(t,e,n,r){const i=r-t*t,a=Math.abs(i)<1e-24?0:(n-t*e)/i;return[e-a*t,a]};function Pi(t,e,n,r){t=t.filter(t=>{let r=e(t),i=n(t);return null!=r&&(r=+r)>=r&&null!=i&&(i=+i)>=i}),r&&t.sort((t,n)=>e(t)-e(n));const i=t.length,a=new Float64Array(i),o=new Float64Array(i);let s,u,c,l=0,f=0,d=0;for(c of t)a[l]=s=+e(c),o[l]=u=+n(c),f+=(s-f)/++l,d+=(u-d)/l;for(l=0;l<i;++l)a[l]-=f,o[l]-=d;return[a,o,f,d]}function Li(t,e,n,r){let i,a,o=-1;for(let s of t)i=e(s),a=n(s),null!=i&&(i=+i)>=i&&null!=a&&(a=+a)>=a&&r(i,a,++o)}var zi=function(t,e,n,r,i){let a=0,o=0;return Li(t,e,n,(t,e)=>{const n=e-i(t),s=e-r;a+=n*n,o+=s*s}),1-a/o},Bi=function(t,e,n){let r=0,i=0,a=0,o=0,s=0;Li(t,e,n,(t,e)=>{r+=(t-r)/++s,i+=(e-i)/s,a+=(t*e-a)/s,o+=(t*t-o)/s});const u=ji(r,i,a,o),c=t=>u[0]+u[1]*t;return{coef:u,predict:c,rSquared:zi(t,e,n,i,c)}},Ui=function(t,e,n){let r=0,i=0,a=0,o=0,s=0;Li(t,e,n,(t,e)=>{++s,t=Math.log(t),r+=(t-r)/s,i+=(e-i)/s,a+=(t*e-a)/s,o+=(t*t-o)/s});const u=ji(r,i,a,o),c=t=>u[0]+u[1]*Math.log(t);return{coef:u,predict:c,rSquared:zi(t,e,n,i,c)}},Wi=function(t,e,n){const[r,i,a,o]=Pi(t,e,n);let s,u,c,l=0,f=0,d=0,h=0,p=0;Li(t,e,n,(t,e)=>{s=r[p++],u=Math.log(e),l+=(e*u-l)/p,f+=((c=s*e)-f)/p,d+=(c*u-d)/p,h+=(s*c-h)/p});const[m,g]=ji(f/o,l/o,d/o,h/o),v=t=>Math.exp(m+g*(t-a));return{coef:[Math.exp(m-g*a),g],predict:v,rSquared:zi(t,e,n,o,v)}},Vi=function(t,e,n){let r=0,i=0,a=0,o=0,s=0,u=0;Li(t,e,n,(t,e)=>{const n=Math.log(t),c=Math.log(e);r+=(n-r)/++u,i+=(c-i)/u,a+=(n*c-a)/u,o+=(n*n-o)/u,s+=(e-s)/u});const c=ji(r,i,a,o),l=t=>c[0]*Math.pow(t,c[1]);return c[0]=Math.exp(c[0]),{coef:c,predict:l,rSquared:zi(t,e,n,s,l)}},qi=function(t,e,n){const[r,i,a,o]=Pi(t,e,n),s=r.length;let u,c,l,f,d=0,h=0,p=0,m=0,g=0;for(u=0;u<s;)c=r[u],l=i[u++],d+=((f=c*c)-d)/u,h+=(f*c-h)/u,p+=(f*f-p)/u,m+=(c*l-m)/u,g+=(f*l-g)/u;const v=p-d*d,y=d*v-h*h,b=(g*d-m*h)/y,x=(m*v-g*h)/y,w=-b*d,k=t=>b*(t-=a)*t+x*t+w+o;return{coef:[w-x*a+b*a*a+o,x-2*b*a,b],predict:k,rSquared:zi(t,e,n,o,k)}},Hi=function(t,e,n,r){if(1===r)return Bi(t,e,n);if(2===r)return qi(t,e,n);const[i,a,o,s]=Pi(t,e,n),u=i.length,c=[],l=[],f=r+1;let d,h,p,m,g;for(d=0;d<f;++d){for(p=0,m=0;p<u;++p)m+=Math.pow(i[p],d)*a[p];for(c.push(m),g=new Float64Array(f),h=0;h<f;++h){for(p=0,m=0;p<u;++p)m+=Math.pow(i[p],d+h);g[h]=m}l.push(g)}l.push(c);const v=function(t){const e=t.length-1,n=[];let r,i,a,o,s;for(r=0;r<e;++r){for(o=r,i=r+1;i<e;++i)Math.abs(t[r][i])>Math.abs(t[r][o])&&(o=i);for(a=r;a<e+1;++a)s=t[a][r],t[a][r]=t[a][o],t[a][o]=s;for(i=r+1;i<e;++i)for(a=e;a>=r;a--)t[a][i]-=t[a][r]*t[r][i]/t[r][r]}for(i=e-1;i>=0;--i){for(s=0,a=i+1;a<e;++a)s+=t[a][i]*n[a];n[i]=(t[e][i]-s)/t[i][i]}return n}(l),y=t=>{t-=o;let e=s+v[0]+v[1]*t+v[2]*t*t;for(d=3;d<f;++d)e+=v[d]*Math.pow(t,d);return e};return{coef:function(t,e,n,r){const i=Array(t);let a,o,s,u;for(a=0;a<t;++a)i[a]=0;for(a=t-1;a>=0;--a)for(s=e[a],u=1,i[a]+=s,o=1;o<=a;++o)u*=(a+1-o)/o,i[a-o]+=s*Math.pow(n,o)*u;return i[0]+=r,i}(f,v,-o,s),predict:y,rSquared:zi(t,e,n,s,y)}};var Gi=function(t,e){return ai(t,.5,e)};var $i=function(t,e,n,r){const[i,a,o,s]=Pi(t,e,n,!0),u=i.length,c=Math.max(2,~~(r*u)),l=new Float64Array(u),f=new Float64Array(u),d=new Float64Array(u).fill(1);for(let t=-1;++t<=2;){const e=[0,c-1];for(let t=0;t<u;++t){const n=i[t],r=e[0],o=e[1],s=n-i[r]>i[o]-n?r:o;let u=0,c=0,h=0,p=0,m=0,g=1/Math.abs(i[s]-n||1);for(let t=r;t<=o;++t){const e=i[t],r=a[t],o=Ki(Math.abs(n-e)*g)*d[t],s=e*o;u+=o,c+=s,h+=r*o,p+=r*s,m+=e*s}const[v,y]=ji(c/u,h/u,p/u,m/u);l[t]=v+y*n,f[t]=Math.abs(a[t]-l[t]),Xi(i,t+1,e)}if(2===t)break;const n=Gi(f);if(Math.abs(n)<1e-12)break;for(let t,e,r=0;r<u;++r)t=f[r]/(6*n),d[r]=t>=1?1e-12:(e=1-t*t)*e}return function(t,e,n,r){const i=t.length,a=[];let o,s=0,u=0,c=[];for(;s<i;++s)o=t[s]+n,c[0]===o?c[1]+=(e[s]-c[1])/++u:(u=0,c[1]+=r,c=[o,e[s]],a.push(c));return c[1]+=r,a}(i,l,o,s)};function Ki(t){return(t=1-t*t*t)*t*t}function Xi(t,e,n){let r=t[e],i=n[0],a=n[1]+1;if(!(a>=t.length))for(;e>i&&t[a]-r<=r-t[i];)n[0]=++i,n[1]=a,++a}const Yi=.1*Math.PI/180;var Ji=function(t,e,n,r){n=n||25,r=Math.max(n,r||200);const i=e=>[e,t(e)],a=e[0],o=e[1],s=o-a,u=s/r,c=[i(a)],l=[];if(n===r){for(let t=1;t<r;++t)c.push(i(a+t/n*s));return c.push(i(o)),c}l.push(i(o));for(let t=n;--t>0;)l.push(i(a+t/n*s));let f=c[0],d=l[l.length-1];for(;d;){const t=i((f[0]+d[0])/2);t[0]-f[0]>=u&&Zi(f,t,d)>Yi?l.push(t):(f=d,c.push(d),l.pop()),d=l[l.length-1]}return c};function Zi(t,e,n){const r=Math.atan2(n[1]-t[1],n[0]-t[0]),i=Math.atan2(e[1]-t[1],e[0]-t[0]);return Math.abs(r-i)}function Qi(t){this._key=t?Object(ct.t)(t):mt,this.reset()}var ta=Qi.prototype;function ea(t){Br.call(this,null,t),this._adds=[],this._mods=[],this._alen=0,this._mlen=0,this._drop=!0,this._cross=!1,this._dims=[],this._dnames=[],this._measures=[],this._countOnly=!1,this._counts=null,this._prev=null,this._inputs=null,this._outputs=null}ta.reset=function(){this._add=[],this._rem=[],this._ext=null,this._get=null,this._q=null},ta.add=function(t){this._add.push(t)},ta.rem=function(t){this._rem.push(t)},ta.values=function(){if(this._get=null,0===this._rem.length)return this._add;var t,e,n,r=this._add,i=this._rem,a=this._key,o=r.length,s=i.length,u=Array(o-s),c={};for(t=0;t<s;++t)c[a(i[t])]=1;for(t=0,e=0;t<o;++t)c[a(n=r[t])]?c[a(n)]=0:u[e++]=n;return this._rem=[],this._add=u},ta.distinct=function(t){for(var e,n=this.values(),r=n.length,i={},a=0;--r>=0;)e=t(n[r])+"",Object(ct.v)(i,e)||(i[e]=1,++a);return a},ta.extent=function(t){if(this._get!==t||!this._ext){var e=this.values(),n=Object(ct.q)(e,t);this._ext=[e[n[0]],e[n[1]]],this._get=t}return this._ext},ta.argmin=function(t){return this.extent(t)[0]||{}},ta.argmax=function(t){return this.extent(t)[1]||{}},ta.min=function(t){var e=this.extent(t)[0];return null!=e?t(e):void 0},ta.max=function(t){var e=this.extent(t)[1];return null!=e?t(e):void 0},ta.quartile=function(t){return this._get===t&&this._q||(this._q=si(this.values(),t),this._get=t),this._q},ta.q1=function(t){return this.quartile(t)[0]},ta.q2=function(t){return this.quartile(t)[1]},ta.q3=function(t){return this.quartile(t)[2]},ta.ci=function(t){return this._get===t&&this._ci||(this._ci=di(this.values(),1e3,.05,t),this._get=t),this._ci},ta.ci0=function(t){return this.ci(t)[0]},ta.ci1=function(t){return this.ci(t)[1]},ea.Definition={type:"Aggregate",metadata:{generates:!0,changes:!0},params:[{name:"groupby",type:"field",array:!0},{name:"ops",type:"enum",array:!0,values:Kr},{name:"fields",type:"field",null:!0,array:!0},{name:"as",type:"string",null:!0,array:!0},{name:"drop",type:"boolean",default:!0},{name:"cross",type:"boolean",default:!1},{name:"key",type:"field"}]};var na=Object(ct.y)(ea,Br);na.transform=function(t,e){var n=this,r=e.fork(e.NO_SOURCE|e.NO_FIELDS),i=t.modified();return n.stamp=r.stamp,n.value&&(i||e.modified(n._inputs,!0))?(n._prev=n.value,n.value=i?n.init(t):{},e.visit(e.SOURCE,t=>n.add(t))):(n.value=n.value||n.init(t),e.visit(e.REM,t=>n.rem(t)),e.visit(e.ADD,t=>n.add(t))),r.modifies(n._outputs),n._drop=!1!==t.drop,t.cross&&n._dims.length>1&&(n._drop=!1,n.cross()),n.changes(r)},na.cross=function(){var t=this,e=t.value,n=t._dnames,r=n.map(function(){return{}}),i=n.length;function a(t){var e,a,o,s;for(e in t)for(o=t[e].tuple,a=0;a<i;++a)r[a][s=o[n[a]]]=s}a(t._prev),a(e),function a(o,s,u){var c,l,f=n[u],d=r[u++];for(c in d)s[f]=d[c],l=o?o+"|"+c:c,u<i?a(l,s,u):e[l]||t.cell(l,s)}("",{},0)},na.init=function(t){var e=this._inputs=[],n=this._outputs=[],r={};function i(t){for(var n,i=Object(ct.i)(Object(ct.g)(t)),a=0,o=i.length;a<o;++a)r[n=i[a]]||(r[n]=1,e.push(n))}this._dims=Object(ct.i)(t.groupby),this._dnames=this._dims.map(function(t){var e=Object(ct.h)(t);return i(t),n.push(e),e}),this.cellkey=t.key?t.key:Hr(this._dims),this._countOnly=!0,this._counts=[],this._measures=[];var a,o,s,u,c,l,f=t.fields||[null],d=t.ops||["count"],h=t.as||[],p=f.length,m={};for(p!==d.length&&Object(ct.n)("Unmatched number of fields and aggregate ops."),l=0;l<p;++l)a=f[l],o=d[l],null==a&&"count"!==o&&Object(ct.n)("Null aggregate field specified."),c=Gr(o,u=Object(ct.h)(a),h[l]),n.push(c),"count"!==o?((s=m[u])||(i(a),(s=m[u]=[]).field=a,this._measures.push(s)),"count"!==o&&(this._countOnly=!1),s.push(Xr(o,c))):this._counts.push(c);return this._measures=this._measures.map(function(t){return Zr(t,t.field)}),{}},na.cellkey=Hr(),na.cell=function(t,e){var n=this.value[t];return n?0===n.num&&this._drop&&n.stamp<this.stamp?(n.stamp=this.stamp,this._adds[this._alen++]=n):n.stamp<this.stamp&&(n.stamp=this.stamp,this._mods[this._mlen++]=n):(n=this.value[t]=this.newcell(t,e),this._adds[this._alen++]=n),n},na.newcell=function(t,e){var n={key:t,num:0,agg:null,tuple:this.newtuple(e,this._prev&&this._prev[t]),stamp:this.stamp,store:!1};if(!this._countOnly){var r,i=this._measures,a=i.length;for(n.agg=Array(a),r=0;r<a;++r)n.agg[r]=new i[r](n)}return n.store&&(n.data=new Qi),n},na.newtuple=function(t,e){var n,r,i=this._dnames,a=this._dims,o={};for(n=0,r=a.length;n<r;++n)o[i[n]]=a[n](t);return e?xt(e.tuple,o):vt(o)},na.add=function(t){var e,n,r,i=this.cellkey(t),a=this.cell(i,t);if(a.num+=1,!this._countOnly)for(a.store&&a.data.add(t),n=0,r=(e=a.agg).length;n<r;++n)e[n].add(e[n].get(t),t)},na.rem=function(t){var e,n,r,i=this.cellkey(t),a=this.cell(i,t);if(a.num-=1,!this._countOnly)for(a.store&&a.data.rem(t),n=0,r=(e=a.agg).length;n<r;++n)e[n].rem(e[n].get(t),t)},na.celltuple=function(t){var e,n,r,i=t.tuple,a=this._counts;for(t.store&&t.data.values(),n=0,r=a.length;n<r;++n)i[a[n]]=t.num;if(!this._countOnly)for(n=0,r=(e=t.agg).length;n<r;++n)e[n].set(i);return i},na.changes=function(t){var e,n,r,i,a=this._adds,o=this._mods,s=this._prev,u=this._drop,c=t.add,l=t.rem,f=t.mod;if(s)for(n in s)e=s[n],u&&!e.num||l.push(e.tuple);for(r=0,i=this._alen;r<i;++r)c.push(this.celltuple(a[r])),a[r]=null;for(r=0,i=this._mlen;r<i;++r)(0===(e=o[r]).num&&u?l:f).push(this.celltuple(e)),o[r]=null;return this._alen=this._mlen=0,this._prev=null,t};function ra(t){Br.call(this,null,t)}ra.Definition={type:"Bin",metadata:{modifies:!0},params:[{name:"field",type:"field",required:!0},{name:"interval",type:"boolean",default:!0},{name:"anchor",type:"number"},{name:"maxbins",type:"number",default:20},{name:"base",type:"number",default:10},{name:"divide",type:"number",array:!0,default:[5,2]},{name:"extent",type:"number",array:!0,length:2,required:!0},{name:"span",type:"number"},{name:"step",type:"number"},{name:"steps",type:"number",array:!0},{name:"minstep",type:"number",default:0},{name:"nice",type:"boolean",default:!0},{name:"name",type:"string"},{name:"as",type:"string",array:!0,length:2,default:["bin0","bin1"]}]};var ia=Object(ct.y)(ra,Br);ia.transform=function(t,e){var n,r=!1!==t.interval,i=this._bins(t),a=i.start,o=i.step,s=t.as||["bin0","bin1"],u=s[0],c=s[1];return n=t.modified()?(e=e.reflow(!0)).SOURCE:e.modified(Object(ct.g)(t.field))?e.ADD_MOD:e.ADD,e.visit(n,r?function(t){var e=i(t);t[u]=e,t[c]=null==e?null:a+o*(1+(e-a)/o)}:function(t){t[u]=i(t)}),e.modifies(r?s:u)},ia._bins=function(t){if(this.value&&!t.modified())return this.value;var e,n,r=t.field,i=ci(t),a=i.step,o=i.start,s=o+Math.ceil((i.stop-o)/a)*a;null!=(e=t.anchor)&&(n=e-(o+a*Math.floor((e-o)/a)),o+=n,s+=n);var u=function(t){var e=r(t);return null==e?null:e<o?-1/0:e>s?1/0:(e=Math.max(o,Math.min(+e,s-a)),o+a*Math.floor(1e-14+(e-o)/a))};return u.start=o,u.stop=i.stop,u.step=a,this.value=Object(ct.f)(u,Object(ct.g)(r),t.name||"bin_"+Object(ct.h)(r))};var aa=function(t,e,n){var r=t,i=e||[],a=n||[],o={},s=0;return{add:function(t){a.push(t)},remove:function(t){o[r(t)]=++s},size:function(){return i.length},data:function(t,e){return s&&(i=i.filter(function(t){return!o[r(t)]}),o={},s=0),e&&t&&i.sort(t),a.length&&(i=t?Object(ct.M)(t,i,a.sort(t)):i.concat(a),a=[]),i}}};function oa(t){Br.call(this,[],t)}function sa(t){Nt.call(this,null,ua,t)}function ua(t){return this.value&&!t.modified()?this.value:Object(ct.k)(t.fields,t.orders)}function ca(t){Br.call(this,null,t)}oa.Definition={type:"Collect",metadata:{source:!0},params:[{name:"sort",type:"compare"}]},Object(ct.y)(oa,Br).transform=function(t,e){var n=e.fork(e.ALL),r=aa(mt,this.value,n.materialize(n.ADD).add),i=t.sort,a=e.changed()||i&&(t.modified("sort")||e.modified(i.fields));return n.visit(n.REM,r.remove),this.modified(a),this.value=n.source=r.data(wt(i),a),e.source&&e.source.root&&(this.value.root=e.source.root),n},Object(ct.y)(sa,Nt),ca.Definition={type:"CountPattern",metadata:{generates:!0,changes:!0},params:[{name:"field",type:"field",required:!0},{name:"case",type:"enum",values:["upper","lower","mixed"],default:"mixed"},{name:"pattern",type:"string",default:'[\\w"]+'},{name:"stopwords",type:"string",default:""},{name:"as",type:"string",array:!0,length:2,default:["text","count"]}]};var la=Object(ct.y)(ca,Br);function fa(t){Br.call(this,null,t)}la.transform=function(t,e){function n(e){return function(n){for(var r,i=function(t,e,n){switch(e){case"upper":t=t.toUpperCase();break;case"lower":t=t.toLowerCase()}return t.match(n)}(s(n),t.case,a)||[],u=0,c=i.length;u<c;++u)o.test(r=i[u])||e(r)}}var r=this._parameterCheck(t,e),i=this._counts,a=this._match,o=this._stop,s=t.field,u=t.as||["text","count"],c=n(function(t){i[t]=1+(i[t]||0)}),l=n(function(t){i[t]-=1});return r?e.visit(e.SOURCE,c):(e.visit(e.ADD,c),e.visit(e.REM,l)),this._finish(e,u)},la._parameterCheck=function(t,e){var n=!1;return!t.modified("stopwords")&&this._stop||(this._stop=new RegExp("^"+(t.stopwords||"")+"$","i"),n=!0),!t.modified("pattern")&&this._match||(this._match=new RegExp(t.pattern||"[\\w']+","g"),n=!0),(t.modified("field")||e.modified(t.field.fields))&&(n=!0),n&&(this._counts={}),n},la._finish=function(t,e){var n,r,i,a=this._counts,o=this._tuples||(this._tuples={}),s=e[0],u=e[1],c=t.fork(t.NO_SOURCE|t.NO_FIELDS);for(n in a)r=o[n],i=a[n]||0,!r&&i?(o[n]=r=vt({}),r[s]=n,r[u]=i,c.add.push(r)):0===i?(r&&c.rem.push(r),a[n]=null,o[n]=null):r[u]!==i&&(r[u]=i,c.mod.push(r));return c.modifies(e)},fa.Definition={type:"Cross",metadata:{generates:!0},params:[{name:"filter",type:"expr"},{name:"as",type:"string",array:!0,length:2,default:["a","b"]}]},Object(ct.y)(fa,Br).transform=function(t,e){var n=e.fork(e.NO_SOURCE),r=this.value,i=t.as||["a","b"],a=i[0],o=i[1];return!r||e.changed(e.ADD_REM)||t.modified("as")||t.modified("filter")?(r&&(n.rem=r),r=e.materialize(e.SOURCE).source,n.add=this.value=function(t,e,n,r){for(var i,a,o=[],s={},u=t.length,c=0;c<u;++c)for(s[e]=a=t[c],i=0;i<u;++i)s[n]=t[i],r(s)&&(o.push(vt(s)),(s={})[e]=a);return o}(r,a,o,t.filter||ct.Ga)):n.mod=r,n.source=this.value,n.modifies(i)};var da={kde:Ei,mixture:Ti,normal:_i,lognormal:Ni,uniform:Fi},ha="distributions",pa="function",ma="field";function ga(t){Br.call(this,null,t)}var va=[{key:{function:"normal"},params:[{name:"mean",type:"number",default:0},{name:"stdev",type:"number",default:1}]},{key:{function:"lognormal"},params:[{name:"mean",type:"number",default:0},{name:"stdev",type:"number",default:1}]},{key:{function:"uniform"},params:[{name:"min",type:"number",default:0},{name:"max",type:"number",default:1}]},{key:{function:"kde"},params:[{name:"field",type:"field",required:!0},{name:"from",type:"data"},{name:"bandwidth",type:"number",default:0}]}],ya={key:{function:"mixture"},params:[{name:"distributions",type:"param",array:!0,params:va},{name:"weights",type:"number",array:!0}]};function ba(t,e){return t?t.map(function(t,n){return e[n]||Object(ct.h)(t)}):null}function xa(t,e,n){var r,i,a,o,s,u,c=[],l=function(t){return t(o)};if(null==e)c.push(t.map(n));else for(r={},i=0,a=t.length;i<a;++i)o=t[i],(u=r[s=e.map(l)])||(r[s]=u=[],u.dims=s,c.push(u)),u.push(n(o));return c}ga.Definition={type:"Density",metadata:{generates:!0},params:[{name:"extent",type:"number",array:!0,length:2},{name:"steps",type:"number"},{name:"minsteps",type:"number",default:25},{name:"maxsteps",type:"number",default:200},{name:"method",type:"string",default:"pdf",values:["pdf","cdf"]},{name:"distribution",type:"param",params:va.concat(ya)},{name:"as",type:"string",array:!0,default:["value","density"]}]},Object(ct.y)(ga,Br).transform=function(t,e){var n=e.fork(e.NO_SOURCE|e.NO_FIELDS);if(!this.value||e.changed()||t.modified()){var r=function t(e,n){var r=e[pa];Object(ct.v)(da,r)||Object(ct.n)("Unknown distribution function: "+r);var i=da[r]();for(var a in e)a===ma?i.data((e.from||n()).map(e[a])):a===ha?i[a](e[a].map(function(e){return t(e,n)})):typeof i[a]===pa&&i[a](e[a]);return i}(t.distribution,function(t){return function(){return t.materialize(t.SOURCE).source}}(e)),i=t.steps||t.minsteps||25,a=t.steps||t.maxsteps||200,o=t.method||"pdf";"pdf"!==o&&"cdf"!==o&&Object(ct.n)("Invalid density method: "+o),t.extent||r.data||Object(ct.n)("Missing density extent parameter."),o=r[o];var s=t.as||["value","density"],u=t.extent||Object(ct.p)(r.data()),c=Ji(o,u,i,a).map(t=>{var e={};return e[s[0]]=t[0],e[s[1]]=t[1],vt(e)});this.value&&(n.rem=this.value),this.value=n.add=n.source=c}return n};function wa(t){Br.call(this,null,t)}function ka(t){Nt.call(this,null,_a,t),this.modified(!0)}function _a(t){var e=t.expr;return this.value&&!t.modified("expr")?this.value:Object(ct.f)(n=>e(n,t),Object(ct.g)(e),Object(ct.h)(e))}function Ea(t){Br.call(this,[void 0,void 0],t)}function Oa(t,e){Nt.call(this,t),this.parent=e}wa.Definition={type:"DotBin",metadata:{modifies:!0},params:[{name:"field",type:"field",required:!0},{name:"groupby",type:"field",array:!0},{name:"step",type:"number"},{name:"smooth",type:"boolean",default:!1},{name:"as",type:"string",default:"bin"}]},Object(ct.y)(wa,Br).transform=function(t,e){if(this.value&&!t.modified()&&!e.changed())return e;const n=e.materialize(e.SOURCE).source,r=xa(e.source,t.groupby,ct.x),i=t.smooth||!1,a=t.field,o=t.step||function(t,e){return Object(ct.X)(Object(ct.p)(t,e))/30}(n,a),s=wt((t,e)=>a(t)-a(e)),u=t.as||"bin",c=r.length;let l,f=1/0,d=-1/0,h=0;for(;h<c;++h){const t=r[h].sort(s);l=-1;for(const e of hi(t,o,i,a))e<f&&(f=e),e>d&&(d=e),t[++l][u]=e}return this.value={start:f,stop:d,step:o},e.reflow(!0).modifies(u)},Object(ct.y)(ka,Nt),Ea.Definition={type:"Extent",metadata:{},params:[{name:"field",type:"field",required:!0}]},Object(ct.y)(Ea,Br).transform=function(t,e){var n,r=this.value,i=t.field,a=r[0],o=r[1];if(((n=e.changed()||e.modified(i.fields)||t.modified("field"))||null==a)&&(a=1/0,o=-1/0),e.visit(n?e.SOURCE:e.ADD,function(t){var e=i(t);null!=e&&((e=+e)<a&&(a=e),e>o&&(o=e))}),!Number.isFinite(a)||!Number.isFinite(o)){let t=Object(ct.h)(i);t&&(t=` for field "${t}"`),e.dataflow.warn(`Infinite extent${t}: [${a}, ${o}]`),a=o=void 0}this.value=[a,o]};var Sa=Object(ct.y)(Oa,Nt);function Ca(t){Br.call(this,{},t),this._keys=Object(ct.s)();var e=this._targets=[];e.active=0,e.forEach=function(t){for(var n=0,r=e.active;n<r;++n)t(e[n],n,e)}}Sa.connect=function(t){return this.targets().add(t),t.source=this},Sa.add=function(t){this.value.add.push(t)},Sa.rem=function(t){this.value.rem.push(t)},Sa.mod=function(t){this.value.mod.push(t)},Sa.init=function(t){this.value.init(t,t.NO_SOURCE)},Sa.evaluate=function(){return this.value};var Aa=Object(ct.y)(Ca,Br);function Na(t){Nt.call(this,null,Ta,t)}function Ta(t){return this.value&&!t.modified()?this.value:Object(ct.A)(t.name)?Object(ct.i)(t.name).map(function(t){return Object(ct.t)(t)}):Object(ct.t)(t.name,t.as)}function Ia(t){Br.call(this,Object(ct.s)(),t)}function Da(t){Br.call(this,[],t)}function Ma(t){Br.call(this,[],t)}function Ra(t){Br.call(this,null,t)}function Fa(t){Br.call(this,[],t)}Aa.activate=function(t){this._targets[this._targets.active++]=t},Aa.subflow=function(t,e,n,r){var i,a,o=this.value,s=Object(ct.v)(o,t)&&o[t];return s?s.value.stamp<n.stamp&&(s.init(n),this.activate(s)):(a=r||(a=this._group[t])&&a.tuple,s=(i=n.dataflow).add(new Oa(n.fork(n.NO_SOURCE),this)).connect(e(i,t,a)),o[t]=s,this.activate(s)),s},Aa.transform=function(t,e){var n=e.dataflow,r=this,i=t.key,a=t.subflow,o=this._keys,s=t.modified("key");function u(t){return r.subflow(t,a,e)}return this._group=t.group||{},this._targets.active=0,e.visit(e.REM,function(t){var e=mt(t),n=o.get(e);void 0!==n&&(o.delete(e),u(n).rem(t))}),e.visit(e.ADD,function(t){var e=i(t);o.set(mt(t),e),u(e).add(t)}),s||e.modified(i.fields)?e.visit(e.MOD,function(t){var e=mt(t),n=o.get(e),r=i(t);n===r?u(r).mod(t):(o.set(e,r),u(n).rem(t),u(r).add(t))}):e.changed(e.MOD)&&e.visit(e.MOD,function(t){u(o.get(mt(t))).mod(t)}),s&&e.visit(e.REFLOW,function(t){var e=mt(t),n=o.get(e),r=i(t);n!==r&&(o.set(e,r),u(n).rem(t),u(r).add(t))}),o.empty>n.cleanThreshold&&n.runAfter(o.clean),e},Object(ct.y)(Na,Nt),Ia.Definition={type:"Filter",metadata:{changes:!0},params:[{name:"expr",type:"expr",required:!0}]},Object(ct.y)(Ia,Br).transform=function(t,e){var n=e.dataflow,r=this.value,i=e.fork(),a=i.add,o=i.rem,s=i.mod,u=t.expr,c=!0;function l(e){var n=mt(e),i=u(e,t),l=r.get(n);i&&l?(r.delete(n),a.push(e)):i||l?c&&i&&!l&&s.push(e):(r.set(n,1),o.push(e))}return e.visit(e.REM,function(t){var e=mt(t);r.has(e)?r.delete(e):o.push(t)}),e.visit(e.ADD,function(e){u(e,t)?a.push(e):r.set(mt(e),1)}),e.visit(e.MOD,l),t.modified()&&(c=!1,e.visit(e.REFLOW,l)),r.empty>n.cleanThreshold&&n.runAfter(r.clean),i},Da.Definition={type:"Flatten",metadata:{generates:!0},params:[{name:"fields",type:"field",array:!0,required:!0},{name:"index",type:"string"},{name:"as",type:"string",array:!0}]},Object(ct.y)(Da,Br).transform=function(t,e){var n=e.fork(e.NO_SOURCE),r=t.fields,i=ba(r,t.as||[]),a=t.index||null,o=i.length;return n.rem=this.value,e.visit(e.SOURCE,function(t){for(var e,s,u,c=r.map(e=>e(t)),l=c.reduce((t,e)=>Math.max(t,e.length),0),f=0;f<l;++f){for(s=yt(t),e=0;e<o;++e)s[i[e]]=null==(u=c[e][f])?null:u;a&&(s[a]=f),n.add.push(s)}}),this.value=n.source=n.add,a&&n.modifies(a),n.modifies(i)},Ma.Definition={type:"Fold",metadata:{generates:!0},params:[{name:"fields",type:"field",array:!0,required:!0},{name:"as",type:"string",array:!0,length:2,default:["key","value"]}]},Object(ct.y)(Ma,Br).transform=function(t,e){var n=e.fork(e.NO_SOURCE),r=t.fields,i=r.map(ct.h),a=t.as||["key","value"],o=a[0],s=a[1],u=r.length;return n.rem=this.value,e.visit(e.SOURCE,function(t){for(var e,a=0;a<u;++a)(e=yt(t))[o]=i[a],e[s]=r[a](t),n.add.push(e)}),this.value=n.source=n.add,n.modifies(a)},Ra.Definition={type:"Formula",metadata:{modifies:!0},params:[{name:"expr",type:"expr",required:!0},{name:"as",type:"string",required:!0},{name:"initonly",type:"boolean"}]},Object(ct.y)(Ra,Br).transform=function(t,e){var n=t.expr,r=t.as,i=t.modified(),a=t.initonly?e.ADD:i?e.SOURCE:e.modified(n.fields)||e.modified(r)?e.ADD_MOD:e.ADD;return i&&(e=e.materialize().reflow(!0)),t.initonly||e.modifies(r),e.visit(a,e=>e[r]=n(e,t))},Object(ct.y)(Fa,Br).transform=function(t,e){var n,r,i,a=this.value,o=e.fork(e.ALL),s=t.size-a.length,u=t.generator;if(s>0){for(n=[];--s>=0;)n.push(i=vt(u(t))),a.push(i);o.add=o.add.length?o.materialize(o.ADD).add.concat(n):n}else r=a.slice(0,-s),o.rem=o.rem.length?o.materialize(o.REM).rem.concat(r):r,a=a.slice(-s);return o.source=this.value=a,o};var ja={value:"value",median:Gi,mean:function(t,e){let n=0,r=0;if(void 0===e)for(let e of t)null!=e&&(e=+e)>=e&&(++n,r+=e);else{let i=-1;for(let a of t)null!=(a=e(a,++i,t))&&(a=+a)>=a&&(++n,r+=a)}if(n)return r/n},min:ni,max:ei},Pa=[];function La(t){Br.call(this,[],t)}function za(t){ea.call(this,t)}La.Definition={type:"Impute",metadata:{changes:!0},params:[{name:"field",type:"field",required:!0},{name:"key",type:"field",required:!0},{name:"keyvals",array:!0},{name:"groupby",type:"field",array:!0},{name:"method",type:"enum",default:"value",values:["value","mean","median","max","min"]},{name:"value",default:0}]},Object(ct.y)(La,Br).transform=function(t,e){var n,r,i,a,o,s,u,c,l,f,d=e.fork(e.ALL),h=function(t){var e,n=t.method||ja.value;if(null!=ja[n])return n===ja.value?(e=void 0!==t.value?t.value:0,function(){return e}):ja[n];Object(ct.n)("Unrecognized imputation method: "+n)}(t),p=function(t){var e=t.field;return function(t){return t?e(t):NaN}}(t),m=Object(ct.h)(t.field),g=Object(ct.h)(t.key),v=(t.groupby||[]).map(ct.h),y=function(t,e,n,r){var i,a,o,s,u,c,l,f,d=function(t){return t(f)},h=[],p=r?r.slice():[],m={},g={};for(p.forEach(function(t,e){m[t]=e+1}),s=0,l=t.length;s<l;++s)f=t[s],c=n(f),u=m[c]||(m[c]=p.push(c)),a=(i=e?e.map(d):Pa)+"",(o=g[a])||(o=g[a]=[],h.push(o),o.values=i),o[u-1]=f;return h.domain=p,h}(e.source,t.groupby,t.key,t.keyvals),b=[],x=this.value,w=y.domain.length;for(o=0,c=y.length;o<c;++o)for(i=(n=y[o]).values,r=NaN,u=0;u<w;++u)if(null==n[u]){for(a=y.domain[u],f={_impute:!0},s=0,l=i.length;s<l;++s)f[v[s]]=i[s];f[g]=a,f[m]=Number.isNaN(r)?r=h(n,p):r,b.push(vt(f))}return b.length&&(d.add=d.materialize(d.ADD).add.concat(b)),x.length&&(d.rem=d.materialize(d.REM).rem.concat(x)),this.value=b,d},za.Definition={type:"JoinAggregate",metadata:{modifies:!0},params:[{name:"groupby",type:"field",array:!0},{name:"fields",type:"field",null:!0,array:!0},{name:"ops",type:"enum",array:!0,values:Kr},{name:"as",type:"string",null:!0,array:!0},{name:"key",type:"field"}]};var Ba=Object(ct.y)(za,ea);function Ua(t){Br.call(this,null,t)}function Wa(t){Nt.call(this,null,Va,t)}function Va(t){return this.value&&!t.modified()?this.value:Object(ct.I)(t.fields,t.flat)}function qa(t){Br.call(this,[],t),this._pending=null}function Ha(t,e,n){n.forEach(vt);const r=e.fork(e.NO_FIELDS&e.NO_SOURCE);return r.rem=t.value,t.value=r.source=r.add=n,t._pending=null,r}function Ga(t){Br.call(this,{},t)}function $a(t){Nt.call(this,null,Ka,t)}function Ka(t){if(this.value&&!t.modified())return this.value;var e,n,r,i=1/0,a=-1/0,o=t.extents;for(e=0,n=o.length;e<n;++e)(r=o[e])[0]<i&&(i=r[0]),r[1]>a&&(a=r[1]);return[i,a]}function Xa(t){Nt.call(this,null,Ya,t)}function Ya(t){return this.value&&!t.modified()?this.value:t.values.reduce(function(t,e){return t.concat(e)},[])}function Ja(t){Br.call(this,null,t)}function Za(t){ea.call(this,t)}Ba.transform=function(t,e){var n,r=this,i=t.modified();return r.value&&(i||e.modified(r._inputs,!0))?(n=r.value=i?r.init(t):{},e.visit(e.SOURCE,function(t){r.add(t)})):(n=r.value=r.value||this.init(t),e.visit(e.REM,function(t){r.rem(t)}),e.visit(e.ADD,function(t){r.add(t)})),r.changes(),e.visit(e.SOURCE,function(t){Object(ct.o)(t,n[r.cellkey(t)].tuple)}),e.reflow(i).modifies(this._outputs)},Ba.changes=function(){var t,e,n=this._adds,r=this._mods;for(t=0,e=this._alen;t<e;++t)this.celltuple(n[t]),n[t]=null;for(t=0,e=this._mlen;t<e;++t)this.celltuple(r[t]),r[t]=null;this._alen=this._mlen=0},Ua.Definition={type:"KDE",metadata:{generates:!0},params:[{name:"groupby",type:"field",array:!0},{name:"field",type:"field",required:!0},{name:"cumulative",type:"boolean",default:!1},{name:"counts",type:"boolean",default:!1},{name:"bandwidth",type:"number",default:0},{name:"extent",type:"number",array:!0,length:2},{name:"resolve",type:"enum",values:["shared","independent"],default:"independent"},{name:"steps",type:"number"},{name:"minsteps",type:"number",default:25},{name:"maxsteps",type:"number",default:200},{name:"as",type:"string",array:!0,default:["value","density"]}]},Object(ct.y)(Ua,Br).transform=function(t,e){var n=e.fork(e.NO_SOURCE|e.NO_FIELDS);if(!this.value||e.changed()||t.modified()){const r=e.materialize(e.SOURCE).source,i=xa(r,t.groupby,t.field),a=(t.groupby||[]).map(ct.h),o=t.bandwidth,s=t.cumulative?"cdf":"pdf",u=t.as||["value","density"],c=[];let l=t.extent,f=t.steps||t.minsteps||25,d=t.steps||t.maxsteps||200;"pdf"!==s&&"cdf"!==s&&Object(ct.n)("Invalid density method: "+s),"shared"===t.resolve&&(l||(l=Object(ct.p)(r,t.field)),f=d=t.steps||d),i.forEach(e=>{const n=Ei(e,o)[s],r=t.counts?e.length:1,i=l||Object(ct.p)(e);Ji(n,i,f,d).forEach(t=>{const n={};for(let t=0;t<a.length;++t)n[a[t]]=e.dims[t];n[u[0]]=t[0],n[u[1]]=t[1]*r,c.push(vt(n))})}),this.value&&(n.rem=this.value),this.value=n.add=n.source=c}return n},Object(ct.y)(Wa,Nt),Object(ct.y)(qa,Br).transform=function(t,e){const n=e.dataflow;if(this._pending)return Ha(this,e,this._pending);if(function(t){return t.modified("async")&&!(t.modified("values")||t.modified("url")||t.modified("format"))}(t))return e.StopPropagation;if(t.values)return Ha(this,e,n.parse(t.values,t.format));if(t.async){return{async:n.request(t.url,t.format).then(t=>(this._pending=Object(ct.i)(t.data),t=>t.touch(this)))}}return n.request(t.url,t.format).then(t=>Ha(this,e,Object(ct.i)(t.data)))},Ga.Definition={type:"Lookup",metadata:{modifies:!0},params:[{name:"index",type:"index",params:[{name:"from",type:"data",required:!0},{name:"key",type:"field",required:!0}]},{name:"values",type:"field",array:!0},{name:"fields",type:"field",array:!0,required:!0},{name:"as",type:"string",array:!0},{name:"default",default:null}]},Object(ct.y)(Ga,Br).transform=function(t,e){var n,r,i=e,a=t.as,o=t.fields,s=t.index,u=t.values,c=null==t.default?null:t.default,l=t.modified(),f=l?e.SOURCE:e.ADD,d=o.length;return u?(r=u.length,d>1&&!a&&Object(ct.n)('Multi-field lookup requires explicit "as" parameter.'),a&&a.length!==d*r&&Object(ct.n)('The "as" parameter has too few output field names.'),a=a||u.map(ct.h),n=function(t){for(var e,n,i=0,l=0;i<d;++i)if(null==(n=s.get(o[i](t))))for(e=0;e<r;++e,++l)t[a[l]]=c;else for(e=0;e<r;++e,++l)t[a[l]]=u[e](n)}):(a||Object(ct.n)("Missing output field names."),n=function(t){for(var e,n=0;n<d;++n)e=s.get(o[n](t)),t[a[n]]=null==e?c:e}),l?i=e.reflow(!0):f|=o.some(function(t){return e.modified(t.fields)})?e.MOD:0,e.visit(f,n),i.modifies(a)},Object(ct.y)($a,Nt),Object(ct.y)(Xa,Nt),Object(ct.y)(Ja,Br),Ja.prototype.transform=function(t,e){return this.modified(t.modified()),this.value=t,e.fork(e.NO_SOURCE|e.NO_FIELDS)},Za.Definition={type:"Pivot",metadata:{generates:!0,changes:!0},params:[{name:"groupby",type:"field",array:!0},{name:"field",type:"field",required:!0},{name:"value",type:"field",required:!0},{name:"op",type:"enum",values:Kr,default:"sum"},{name:"limit",type:"number",default:0},{name:"key",type:"field"}]};var Qa=Object(ct.y)(Za,ea);function to(t){Ca.call(this,t)}function eo(t){Br.call(this,null,t)}function no(t){Br.call(this,null,t)}Qa._transform=Qa.transform,Qa.transform=function(t,e){return this._transform(function(t,e){var n=t.field,r=t.value,i=("count"===t.op?"__count__":t.op)||"sum",a=Object(ct.g)(n).concat(Object(ct.g)(r)),o=function(t,e,n){var r={},i=[];return n.visit(n.SOURCE,function(e){var n=t(e);r[n]||(r[n]=1,i.push(n))}),i.sort(function(t,e){return(t<e||null==t)&&null!=e?-1:(t>e||null==e)&&null!=t?1:(e=e instanceof Date?+e:e,(t=t instanceof Date?+t:t)!==t&&e==e?-1:e!=e&&t==t?1:0)}),e?i.slice(0,e):i}(n,t.limit||0,e);e.changed()&&t.set("__pivot__",null,null,!0);return{key:t.key,groupby:t.groupby,ops:o.map(function(){return i}),fields:o.map(function(t){return function(t,e,n,r){return Object(ct.f)(function(r){return e(r)===t?n(r):NaN},r,t+"")}(t,n,r,a)}),as:o.map(function(t){return t+""}),modified:t.modified.bind(t)}}(t,e),e)},Object(ct.y)(to,Ca).transform=function(t,e){var n=this,r=t.subflow,i=t.field;return(t.modified("field")||i&&e.modified(Object(ct.g)(i)))&&Object(ct.n)("PreFacet does not support field modification."),this._targets.active=0,e.visit(e.MOD,function(t){var a=n.subflow(mt(t),r,e,t);i?i(t).forEach(function(t){a.mod(t)}):a.mod(t)}),e.visit(e.ADD,function(t){var a=n.subflow(mt(t),r,e,t);i?i(t).forEach(function(t){a.add(vt(t))}):a.add(t)}),e.visit(e.REM,function(t){var a=n.subflow(mt(t),r,e,t);i?i(t).forEach(function(t){a.rem(t)}):a.rem(t)}),e},eo.Definition={type:"Project",metadata:{generates:!0,changes:!0},params:[{name:"fields",type:"field",array:!0},{name:"as",type:"string",null:!0,array:!0}]},Object(ct.y)(eo,Br).transform=function(t,e){var n,r,i=t.fields,a=ba(t.fields,t.as||[]),o=i?function(t,e){return function(t,e,n,r){for(var i=0,a=n.length;i<a;++i)e[r[i]]=n[i](t);return e}(t,e,i,a)}:bt;return this.value?r=this.value:(e=e.addAll(),r=this.value={}),n=e.fork(e.NO_SOURCE),e.visit(e.REM,function(t){var e=mt(t);n.rem.push(r[e]),r[e]=null}),e.visit(e.ADD,function(t){var e=o(t,vt({}));r[mt(t)]=e,n.add.push(e)}),e.visit(e.MOD,function(t){n.mod.push(o(t,r[mt(t)]))}),n},Object(ct.y)(no,Br).transform=function(t,e){return this.value=t.value,t.modified("value")?e.fork(e.NO_SOURCE|e.NO_FIELDS):e.StopPropagation};var ro=function(t,e,n){t=+t,e=+e,n=(i=arguments.length)<2?(e=t,t=0,1):i<3?1:+n;for(var r=-1,i=0|Math.max(0,Math.ceil((e-t)/n)),a=new Array(i);++r<i;)a[r]=t+r*n;return a};function io(t){Br.call(this,null,t)}io.Definition={type:"Quantile",metadata:{generates:!0,changes:!0},params:[{name:"groupby",type:"field",array:!0},{name:"field",type:"field",required:!0},{name:"probs",type:"number",array:!0},{name:"step",type:"number",default:.01},{name:"as",type:"string",array:!0,default:["prob","value"]}]};function ao(t){Br.call(this,null,t)}function oo(t){Br.call(this,[],t),this.count=0}function so(t){Br.call(this,null,t)}function uo(t){Br.call(this,null,t),this.modified(!0)}Object(ct.y)(io,Br).transform=function(t,e){var n=e.fork(e.NO_SOURCE|e.NO_FIELDS),r=t.as||["prob","value"];if(this.value&&!t.modified()&&!e.changed())return n.source=this.value,n;const i=xa(e.materialize(e.SOURCE).source,t.groupby,t.field),a=(t.groupby||[]).map(ct.h),o=[],s=t.step||.01,u=t.probs||ro(s/2,1-1e-14,s),c=u.length;return i.forEach(t=>{const e=oi(t,u);for(let n=0;n<c;++n){const i={};for(let e=0;e<a.length;++e)i[a[e]]=t.dims[e];i[r[0]]=u[n],i[r[1]]=e[n],o.push(vt(i))}}),this.value&&(n.rem=this.value),this.value=n.add=n.source=o,n},Object(ct.y)(ao,Br).transform=function(t,e){var n,r;return this.value?r=this.value:(n=e=e.addAll(),r=this.value={}),t.derive&&(n=e.fork(e.NO_SOURCE),e.visit(e.REM,t=>{var e=mt(t);n.rem.push(r[e]),r[e]=null}),e.visit(e.ADD,t=>{var e=yt(t);r[mt(t)]=e,n.add.push(e)}),e.visit(e.MOD,t=>{var e,i=r[mt(t)];for(e in t)i[e]=t[e],n.modifies(e);n.mod.push(i)})),n},oo.Definition={type:"Sample",metadata:{},params:[{name:"size",type:"number",default:1e3}]},Object(ct.y)(oo,Br).transform=function(t,e){var n=e.fork(e.NO_SOURCE),r=t.modified("size"),i=t.size,a=this.value,o=this.count,s=0,u=a.reduce(function(t,e){return t[mt(e)]=1,t},{});function c(t){var e,r;a.length<i?a.push(t):(r=~~((o+1)*li()))<a.length&&r>=s&&(e=a[r],u[mt(e)]&&n.rem.push(e),a[r]=t),++o}if(e.rem.length&&(e.visit(e.REM,function(t){var e=mt(t);u[e]&&(u[e]=-1,n.rem.push(t)),--o}),a=a.filter(function(t){return-1!==u[mt(t)]})),(e.rem.length||r)&&a.length<i&&e.source&&(s=o=a.length,e.visit(e.SOURCE,function(t){u[mt(t)]||c(t)}),s=-1),r&&a.length>i){for(var l=0,f=a.length-i;l<f;++l)u[mt(a[l])]=-1,n.rem.push(a[l]);a=a.slice(f)}return e.mod.length&&e.visit(e.MOD,function(t){u[mt(t)]&&n.mod.push(t)}),e.add.length&&e.visit(e.ADD,c),(e.add.length||s<0)&&(n.add=a.filter(function(t){return!u[mt(t)]})),this.count=o,this.value=n.source=a,n},so.Definition={type:"Sequence",metadata:{generates:!0,changes:!0},params:[{name:"start",type:"number",required:!0},{name:"stop",type:"number",required:!0},{name:"step",type:"number",default:1},{name:"as",type:"string",default:"data"}]},Object(ct.y)(so,Br).transform=function(t,e){if(!this.value||t.modified()){var n=e.materialize().fork(e.MOD),r=t.as||"data";return n.rem=this.value?e.rem.concat(this.value):e.rem,this.value=ro(t.start,t.stop,t.step||1).map(function(t){var e={};return e[r]=t,vt(e)}),n.add=e.add.concat(this.value),n}},Object(ct.y)(uo,Br).transform=function(t,e){return this.value=e.source,e.changed()?e.fork(e.NO_SOURCE|e.NO_FIELDS):e.StopPropagation};const co="year",lo="quarter",fo="month",ho="week",po="date",mo="day",go="hours",vo="minutes",yo="seconds",bo="milliseconds",xo=[co,lo,fo,ho,po,mo,go,vo,yo,bo].reduce((t,e,n)=>(t[e]=1+n,t),{});function wo(t){const e=Object(ct.i)(t).slice(),n={};return e.length||Object(ct.n)("Missing time unit."),e.forEach(t=>{Object(ct.v)(xo,t)?n[t]=1:Object(ct.n)(`Invalid time unit: ${t}.`)}),(n[ho]||n[mo])&&(n[lo]||n[fo]||n[po])&&Object(ct.n)(`Incompatible time units: ${t}`),e.sort((t,e)=>xo[t]-xo[e]),e}const ko=new Date;function _o(t,e,n,r){const i=e||1,a=Object(ct.U)(t),o=(t,e,r)=>(function(t,e,n){return e<=1?t:n?(r,i)=>n+e*Math.floor((t(r,i)-n)/e):(n,r)=>e*Math.floor(t(n,r)/e)})(n[r||t],t===a&&i,e),s=new Date,u=Object(ct.Da)(t),c=u[co]?o(co):Object(ct.l)(2012),l=u[fo]?o(fo):u[lo]?o(lo):ct.Ka,f=u[ho]&&u[mo]?o(mo,1,ho+mo):u[ho]?o(ho,1):u[mo]?o(mo,1):u[po]?o(po,1):ct.O,d=u[go]?o(go):ct.Ka,h=u[vo]?o(vo):ct.Ka,p=u[yo]?o(yo):ct.Ka,m=u[bo]?o(bo):ct.Ka;return function(t){s.setTime(+t);const e=c(s);return r(e,l(s),f(s,e),d(s),h(s),p(s),m(s))}}function Eo(t,e,n){return e+7*t-(n+6)%7}const Oo={[co]:t=>t.getFullYear(),[lo]:t=>3*~~(t.getMonth()/3),[fo]:t=>t.getMonth(),[po]:t=>t.getDate(),[go]:t=>t.getHours(),[vo]:t=>t.getMinutes(),[yo]:t=>t.getSeconds(),[bo]:t=>t.getMilliseconds(),[mo]:(t,e)=>Eo(1,t.getDay(),Ao(e)),[ho]:(t,e)=>Eo(Co(t),0,Ao(e)),[ho+mo]:(t,e)=>Eo(Co(t),t.getDay(),Ao(e))};function So(t){return ko.setFullYear(t),ko.setMonth(0),ko.setDate(1),ko.setHours(0,0,0,0),ko}function Co(t){return Ue.count(So(t.getFullYear())-1,t)}function Ao(t){return So(t).getDay()}function No(t,e,n,r,i,a,o){if(0<=t&&t<100){var s=new Date(-1,e,n,r,i,a,o);return s.setFullYear(t),s}return new Date(t,e,n,r,i,a,o)}const To={[co]:t=>t.getUTCFullYear(),[lo]:t=>3*~~(t.getUTCMonth()/3),[fo]:t=>t.getUTCMonth(),[po]:t=>t.getUTCDate(),[go]:t=>t.getUTCHours(),[vo]:t=>t.getUTCMinutes(),[yo]:t=>t.getUTCSeconds(),[bo]:t=>t.getUTCMilliseconds(),[mo]:(t,e)=>Eo(1,t.getUTCDay(),Do(e)),[ho]:(t,e)=>Eo(Io(t),0,Do(e)),[ho+mo]:(t,e)=>Eo(Io(t),t.getUTCDay(),Do(e))};function Io(t){const e=Date.UTC(t.getUTCFullYear(),0,1);return Ie.count(e-1,t)}function Do(t){return ko.setTime(Date.UTC(t,0,1)),ko.getUTCDay()}function Mo(t,e,n,r,i,a,o){if(0<=t&&t<100){var s=new Date(Date.UTC(-1,e,n,r,i,a,o));return s.setUTCFullYear(n.y),s}return new Date(Date.UTC(t,e,n,r,i,a,o))}var Ro=Oe(function(t){t.setUTCDate(1),t.setUTCHours(0,0,0,0)},function(t,e){t.setUTCMonth(t.getUTCMonth()+e)},function(t,e){return e.getUTCMonth()-t.getUTCMonth()+12*(e.getUTCFullYear()-t.getUTCFullYear())},function(t){return t.getUTCMonth()}),Fo=Ro,jo=(Ro.range,Oe(function(t){t.setDate(1),t.setHours(0,0,0,0)},function(t,e){t.setMonth(t.getMonth()+e)},function(t,e){return e.getMonth()-t.getMonth()+12*(e.getFullYear()-t.getFullYear())},function(t){return t.getMonth()})),Po=jo,Lo=(jo.range,Oe(function(t){t.setTime(t-t.getMilliseconds()-1e3*t.getSeconds()-t.getMinutes()*Ae)},function(t,e){t.setTime(+t+36e5*e)},function(t,e){return(e-t)/36e5},function(t){return t.getHours()})),zo=Lo,Bo=(Lo.range,Oe(function(){},function(t,e){t.setTime(+t+e)},function(t,e){return e-t}));Bo.every=function(t){return t=Math.floor(t),isFinite(t)&&t>0?t>1?Oe(function(e){e.setTime(Math.floor(e/t)*t)},function(e,n){e.setTime(+e+n*t)},function(e,n){return(n-e)/t}):Bo:null};var Uo=Bo,Wo=(Bo.range,Oe(function(t){t.setTime(t-t.getMilliseconds()-1e3*t.getSeconds())},function(t,e){t.setTime(+t+e*Ae)},function(t,e){return(e-t)/Ae},function(t){return t.getMinutes()})),Vo=Wo,qo=(Wo.range,Oe(function(t){t.setUTCMinutes(0,0,0)},function(t,e){t.setTime(+t+36e5*e)},function(t,e){return(e-t)/36e5},function(t){return t.getUTCHours()})),Ho=qo,Go=(qo.range,Oe(function(t){t.setTime(t-t.getMilliseconds())},function(t,e){t.setTime(+t+1e3*e)},function(t,e){return(e-t)/1e3},function(t){return t.getUTCSeconds()})),$o=Go,Ko=(Go.range,Oe(function(t){t.setUTCSeconds(0,0)},function(t,e){t.setTime(+t+e*Ae)},function(t,e){return(e-t)/Ae},function(t){return t.getUTCMinutes()})),Xo=Ko;Ko.range;const Yo={[co]:Ce,[lo]:Po.every(3),[fo]:Po,[ho]:Ue,[po]:Xe,[mo]:Xe,[go]:zo,[vo]:Vo,[yo]:$o,[bo]:Uo},Jo={[co]:Je,[lo]:Fo.every(3),[fo]:Fo,[ho]:Ie,[po]:ze,[mo]:ze,[go]:Ho,[vo]:Xo,[yo]:$o,[bo]:Uo};function Zo(t){return Yo[t]}function Qo(t){return Jo[t]}function ts(t,e,n){return t?t.offset(e,n):void 0}function es(t,e,n,r){return t?t.range(e,n,r):void 0}const ns={[co]:"%Y ",[lo]:"Q%q ",[fo]:"%b ",[po]:"%d ",[ho]:"W%U ",[mo]:"%a ",[go]:"%H:00",[vo]:"00:%M",[yo]:":%S",[bo]:".%L",[`${co}-${fo}`]:"%Y-%m ",[`${co}-${fo}-${po}`]:"%Y-%m-%d ",[`${go}-${vo}`]:"%H:%M"};function rs(t){return as(nn,Zo,t)}function is(t){return as(an,Qo,t)}function as(t,e,n){return Object(ct.H)(n)?t(n):function(t,e,n){n=n||{},Object(ct.F)(n)||Object(ct.n)(`Invalid time multi-format specifier: ${n}`);const r=e(yo),i=e(vo),a=e(go),o=e(po),s=e(ho),u=e(fo),c=e(lo),l=e(co),f=t(n[bo]||".%L"),d=t(n[yo]||":%S"),h=t(n[vo]||"%I:%M"),p=t(n[go]||"%I %p"),m=t(n[po]||n[mo]||"%a %d"),g=t(n[ho]||"%b %d"),v=t(n[fo]||"%B"),y=t(n[lo]||"%B"),b=t(n[co]||"%Y");return function(t){return(r(t)<t?f:i(t)<t?d:a(t)<t?h:o(t)<t?p:u(t)<t?s(t)<t?m:g:l(t)<t?c(t)<t?v:y:b)(t)}}(t,e,n)}var os=function(t){return 1===t.length&&(t=function(t){return function(e,n){return ti(t(e),n)}}(t)),{left:function(e,n,r,i){for(null==r&&(r=0),null==i&&(i=e.length);r<i;){var a=r+i>>>1;t(e[a],n)<0?r=a+1:i=a}return r},right:function(e,n,r,i){for(null==r&&(r=0),null==i&&(i=e.length);r<i;){var a=r+i>>>1;t(e[a],n)>0?i=a:r=a+1}return r}}};var ss=Math.sqrt(50),us=Math.sqrt(10),cs=Math.sqrt(2),ls=function(t,e,n){var r,i,a,o,s=-1;if(n=+n,(t=+t)===(e=+e)&&n>0)return[t];if((r=e<t)&&(i=t,t=e,e=i),0===(o=fs(t,e,n))||!isFinite(o))return[];if(o>0)for(t=Math.ceil(t/o),e=Math.floor(e/o),a=new Array(i=Math.ceil(e-t+1));++s<i;)a[s]=(t+s)*o;else for(t=Math.floor(t*o),e=Math.ceil(e*o),a=new Array(i=Math.ceil(t-e+1));++s<i;)a[s]=(t-s)/o;return r&&a.reverse(),a};function fs(t,e,n){var r=(e-t)/Math.max(0,n),i=Math.floor(Math.log(r)/Math.LN10),a=r/Math.pow(10,i);return i>=0?(a>=ss?10:a>=us?5:a>=cs?2:1)*Math.pow(10,i):-Math.pow(10,-i)/(a>=ss?10:a>=us?5:a>=cs?2:1)}function ds(t,e,n){var r=Math.abs(e-t)/Math.max(0,n),i=Math.pow(10,Math.floor(Math.log(r)/Math.LN10)),a=r/i;return a>=ss?i*=10:a>=us?i*=5:a>=cs&&(i*=2),e<t?-i:i}const hs=[co,fo,po,go,vo,yo,bo],ps=hs.slice(0,-1),ms=ps.slice(0,-1),gs=ms.slice(0,-1),vs=gs.slice(0,-1),ys=[co,fo],bs=[co],xs=[[ps,1,1e3],[ps,5,5e3],[ps,15,15e3],[ps,30,3e4],[ms,1,6e4],[ms,5,3e5],[ms,15,9e5],[ms,30,18e5],[gs,1,36e5],[gs,3,108e5],[gs,6,216e5],[gs,12,432e5],[vs,1,864e5],[[co,ho],1,6048e5],[ys,1,2592e6],[ys,3,7776e6],[bs,1,31536e6]];function ws(t){Br.call(this,null,t)}const ks=["unit0","unit1"];ws.Definition={type:"TimeUnit",metadata:{modifies:!0},params:[{name:"field",type:"field",required:!0},{name:"interval",type:"boolean",default:!0},{name:"units",type:"string",array:!0},{name:"step",type:"number",default:1},{name:"maxbins",type:"number",default:40},{name:"extent",type:"date",array:!0},{name:"timezone",type:"enum",default:"local",values:["local","utc"]},{name:"as",type:"string",array:!0,length:2,default:ks}]};var _s=Object(ct.y)(ws,Br);function Es(t){Br.call(this,Object(ct.s)(),t)}function Os(t){Br.call(this,null,t)}_s.transform=function(t,e){var n=t.field,r=!1!==t.interval,i="utc"===t.timezone,a=this._floor(t,e),o=(i?Qo:Zo)(a.unit).offset,s=t.as||ks,u=s[0],c=s[1],l=a.start||1/0,f=a.stop||-1/0,d=a.step,h=e.ADD;return(t.modified()||e.modified(Object(ct.g)(n)))&&(h=(e=e.reflow(!0)).SOURCE,l=1/0,f=-1/0),e.visit(h,function(t){var e,i,s=n(t);null==s?(t[u]=null,r&&(t[c]=null)):(t[u]=e=i=a(s),r&&(t[c]=i=o(e,d)),e<l&&(l=e),i>f&&(f=i))}),a.start=l,a.stop=f,e.modifies(r?s:u)},_s._floor=function(t,e){const n="utc"===t.timezone;let{units:r,step:i}=t.units?{units:t.units,step:t.step||1}:function(t){const e=t.extent,n=t.maxbins||40,r=Math.abs(Object(ct.X)(e))/n;let i,a,o=os(t=>t[2]).right(xs,r);return o===xs.length?(i=bs,a=ds(e[0]/31536e6,e[1]/31536e6,n)):o?(i=(o=xs[r/xs[o-1][2]<xs[o][2]/r?o-1:o])[0],a=o[1]):(i=hs,a=Math.max(ds(e[0],e[1],n),1)),{units:i,step:a}}({extent:t.extent||Object(ct.p)(e.materialize(e.SOURCE).source,t.field),maxbins:t.maxbins});r=wo(r);const a=this.value||{},o=(n?function(t,e){return _o(t,e||1,To,Mo)}:function(t,e){return _o(t,e||1,Oo,No)})(r,i);return o.unit=Object(ct.U)(r),o.units=r,o.step=i,o.start=a.start,o.stop=a.stop,this.value=o},Object(ct.y)(Es,Br).transform=function(t,e){var n=e.dataflow,r=t.field,i=this.value,a=!0;function o(t){i.set(r(t),t)}return t.modified("field")||e.modified(r.fields)?(i.clear(),e.visit(e.SOURCE,o)):e.changed()?(e.visit(e.REM,function(t){i.delete(r(t))}),e.visit(e.ADD,o)):a=!1,this.modified(a),i.empty>n.cleanThreshold&&n.runAfter(i.clean),e.fork()},Object(ct.y)(Os,Br).transform=function(t,e){(!this.value||t.modified("field")||t.modified("sort")||e.changed()||t.sort&&e.modified(t.sort.fields))&&(this.value=(t.sort?e.source.slice().sort(wt(t.sort)):e.source).map(t.field))};const Ss={row_number:function(){return{next:t=>t.index+1}},rank:function(){let t;return{init:()=>t=1,next:e=>{let n=e.index,r=e.data;return n&&e.compare(r[n-1],r[n])?t=n+1:t}}},dense_rank:function(){let t;return{init:()=>t=1,next:e=>{let n=e.index,r=e.data;return n&&e.compare(r[n-1],r[n])?++t:t}}},percent_rank:function(){let t=Ss.rank(),e=t.next;return{init:t.init,next:t=>(e(t)-1)/(t.data.length-1)}},cume_dist:function(){let t;return{init:()=>t=0,next:e=>{let n=e.index,r=e.data,i=e.compare;if(t<n){for(;n+1<r.length&&!i(r[n],r[n+1]);)++n;t=n}return(1+t)/r.length}}},ntile:function(t,e){(e=+e)>0||Object(ct.n)("ntile num must be greater than zero.");let n=Ss.cume_dist(),r=n.next;return{init:n.init,next:t=>Math.ceil(e*r(t))}},lag:function(t,e){return e=+e||1,{next:n=>{let r=n.index-e;return r>=0?t(n.data[r]):null}}},lead:function(t,e){return e=+e||1,{next:n=>{let r=n.index+e,i=n.data;return r<i.length?t(i[r]):null}}},first_value:function(t){return{next:e=>t(e.data[e.i0])}},last_value:function(t){return{next:e=>t(e.data[e.i1-1])}},nth_value:function(t,e){return(e=+e)>0||Object(ct.n)("nth_value nth must be greater than zero."),{next:n=>{let r=n.i0+(e-1);return r<n.i1?t(n.data[r]):null}}},prev_value:function(t){let e;return{init:()=>e=null,next:n=>{let r=t(n.data[n.index]);return null!=r?e=r:e}}},next_value:function(t){let e,n;return{init:()=>(e=null,n=-1),next:r=>{let i=r.data;return r.index<=n?e:(n=function(t,e,n){for(let r=e.length;n<r;++n){let r=t(e[n]);if(null!=r)return n}return-1}(t,i,r.index))<0?(n=i.length,e=null):e=t(i[n])}}}};var Cs=Object.keys(Ss);function As(t){let e=this,n=Object(ct.i)(t.ops),r=Object(ct.i)(t.fields),i=Object(ct.i)(t.params),a=Object(ct.i)(t.as),o=e.outputs=[],s=e.windows=[],u={},c={},l=!0,f=[],d=[];function h(t){Object(ct.i)(Object(ct.g)(t)).forEach(t=>u[t]=1)}h(t.sort),n.forEach(function(t,e){let n=r[e],u=Object(ct.h)(n),p=Gr(t,u,a[e]);if(h(n),o.push(p),Object(ct.v)(Ss,t))s.push(function(t,e,n,r){let i=Ss[t](e,n);return{init:i.init||ct.Ka,update:function(t,e){e[r]=i.next(t)}}}(t,r[e],i[e],p));else{if(null==n&&"count"!==t&&Object(ct.n)("Null aggregate field specified."),"count"===t)return void f.push(p);l=!1;let e=c[u];e||((e=c[u]=[]).field=n,d.push(e)),e.push(Xr(t,p))}}),(f.length||d.length)&&(e.cell=function(t,e,n){t=t.map(t=>Zr(t,t.field));let r={num:0,agg:null,store:!1,count:e};if(!n)for(var i=t.length,a=r.agg=Array(i),o=0;o<i;++o)a[o]=new t[o](r);if(r.store)var s=r.data=new Qi;return r.add=function(t){if(r.num+=1,!n){s&&s.add(t);for(let e=0;e<i;++e)a[e].add(a[e].get(t),t)}},r.rem=function(t){if(r.num-=1,!n){s&&s.rem(t);for(let e=0;e<i;++e)a[e].rem(a[e].get(t),t)}},r.set=function(t){let i,o;for(s&&s.values(),i=0,o=e.length;i<o;++i)t[e[i]]=r.num;if(!n)for(i=0,o=a.length;i<o;++i)a[i].set(t)},r.init=function(){r.num=0,s&&s.reset();for(let t=0;t<i;++t)a[t].init()},r}(d,f,l)),e.inputs=Object.keys(u)}const Ns=As.prototype;function Ts(t){Br.call(this,{},t),this._mlen=0,this._mods=[]}Ns.init=function(){this.windows.forEach(t=>t.init()),this.cell&&this.cell.init()},Ns.update=function(t,e){let n,r=this.cell,i=this.windows,a=t.data,o=i&&i.length;if(r){for(n=t.p0;n<t.i0;++n)r.rem(a[n]);for(n=t.p1;n<t.i1;++n)r.add(a[n]);r.set(e)}for(n=0;n<o;++n)i[n].update(t,e)},Ts.Definition={type:"Window",metadata:{modifies:!0},params:[{name:"sort",type:"compare"},{name:"groupby",type:"field",array:!0},{name:"ops",type:"enum",array:!0,values:Cs.concat(Kr)},{name:"params",type:"number",null:!0,array:!0},{name:"fields",type:"field",null:!0,array:!0},{name:"as",type:"string",null:!0,array:!0},{name:"frame",type:"number",null:!0,array:!0,length:2,default:[null,0]},{name:"ignorePeers",type:"boolean",default:!1}]};var Is=Object(ct.y)(Ts,Br);function Ds(t,e,n,r){var i=r.sort,a=i&&!r.ignorePeers,o=r.frame||[null,0],s=t.data(n),u=s.length,c=0,l=a?os(i):null,f={i0:0,i1:0,p0:0,p1:0,index:0,data:s,compare:i||Object(ct.l)(-1)};for(e.init();c<u;++c)Ms(f,o,c,u),a&&Rs(f,l),e.update(f,s[c])}function Ms(t,e,n,r){t.p0=t.i0,t.p1=t.i1,t.i0=null==e[0]?0:Math.max(0,n-Math.abs(e[0])),t.i1=null==e[1]?r:Math.min(r,n+Math.abs(e[1])+1),t.index=n}function Rs(t,e){var n=t.i0,r=t.i1-1,i=t.compare,a=t.data,o=a.length-1;n>0&&!i(a[n],a[n-1])&&(t.i0=e.left(a,a[n])),r<o&&!i(a[r],a[r+1])&&(t.i1=e.right(a,a[r]))}Is.transform=function(t,e){var n,r,i=this,a=i.state,o=t.modified(),s=wt(t.sort);this.stamp=e.stamp,a&&!o||(a=i.state=new As(t));var u=Hr(t.groupby);function c(t){return i.group(u(t))}for(o||e.modified(a.inputs)?(i.value={},e.visit(e.SOURCE,function(t){c(t).add(t)})):(e.visit(e.REM,function(t){c(t).remove(t)}),e.visit(e.ADD,function(t){c(t).add(t)})),n=0,r=i._mlen;n<r;++n)Ds(i._mods[n],a,s,t);return i._mlen=0,i._mods=[],e.reflow(o).modifies(a.outputs)},Is.group=function(t){var e=this.value[t];return e||((e=this.value[t]=aa(mt)).stamp=-1),e.stamp<this.stamp&&(e.stamp=this.stamp,this._mods[this._mlen++]=e),e};const Fs="top",js="left",Ps="right",Ls="bottom",zs="top-left",Bs="top-right",Us="bottom-left",Ws="bottom-right",Vs="start",qs="middle",Hs="end",Gs="x",$s="y",Ks="group",Xs="axis",Ys="title",Js="frame",Zs="scope",Qs="legend",tu="row-header",eu="row-footer",nu="row-title",ru="column-header",iu="column-footer",au="column-title",ou="padding",su="symbol",uu="fit",cu="fit-x",lu="fit-y",fu="pad",du="none",hu="all",pu="each",mu="flush",gu="column",vu="row";function yu(t){this.clear(),t&&this.union(t)}var bu=yu.prototype;bu.clone=function(){return new yu(this)},bu.clear=function(){return this.x1=+Number.MAX_VALUE,this.y1=+Number.MAX_VALUE,this.x2=-Number.MAX_VALUE,this.y2=-Number.MAX_VALUE,this},bu.empty=function(){return this.x1===+Number.MAX_VALUE&&this.y1===+Number.MAX_VALUE&&this.x2===-Number.MAX_VALUE&&this.y2===-Number.MAX_VALUE},bu.equals=function(t){return this.x1===t.x1&&this.y1===t.y1&&this.x2===t.x2&&this.y2===t.y2},bu.set=function(t,e,n,r){return n<t?(this.x2=t,this.x1=n):(this.x1=t,this.x2=n),r<e?(this.y2=e,this.y1=r):(this.y1=e,this.y2=r),this},bu.add=function(t,e){return t<this.x1&&(this.x1=t),e<this.y1&&(this.y1=e),t>this.x2&&(this.x2=t),e>this.y2&&(this.y2=e),this},bu.expand=function(t){return this.x1-=t,this.y1-=t,this.x2+=t,this.y2+=t,this},bu.round=function(){return this.x1=Math.floor(this.x1),this.y1=Math.floor(this.y1),this.x2=Math.ceil(this.x2),this.y2=Math.ceil(this.y2),this},bu.scale=function(t){return this.x1*=t,this.y1*=t,this.x2*=t,this.y2*=t,this},bu.translate=function(t,e){return this.x1+=t,this.x2+=t,this.y1+=e,this.y2+=e,this},bu.rotate=function(t,e,n){const r=this.rotatedPoints(t,e,n);return this.clear().add(r[0],r[1]).add(r[2],r[3]).add(r[4],r[5]).add(r[6],r[7])},bu.rotatedPoints=function(t,e,n){var{x1:r,y1:i,x2:a,y2:o}=this,s=Math.cos(t),u=Math.sin(t),c=e-e*s+n*u,l=n-e*u-n*s;return[s*r-u*i+c,u*r+s*i+l,s*r-u*o+c,u*r+s*o+l,s*a-u*i+c,u*a+s*i+l,s*a-u*o+c,u*a+s*o+l]},bu.union=function(t){return t.x1<this.x1&&(this.x1=t.x1),t.y1<this.y1&&(this.y1=t.y1),t.x2>this.x2&&(this.x2=t.x2),t.y2>this.y2&&(this.y2=t.y2),this},bu.intersect=function(t){return t.x1>this.x1&&(this.x1=t.x1),t.y1>this.y1&&(this.y1=t.y1),t.x2<this.x2&&(this.x2=t.x2),t.y2<this.y2&&(this.y2=t.y2),this},bu.encloses=function(t){return t&&this.x1<=t.x1&&this.x2>=t.x2&&this.y1<=t.y1&&this.y2>=t.y2},bu.alignsWith=function(t){return t&&(this.x1==t.x1||this.x2==t.x2||this.y1==t.y1||this.y2==t.y2)},bu.intersects=function(t){return t&&!(this.x2<t.x1||this.x1>t.x2||this.y2<t.y1||this.y1>t.y2)},bu.contains=function(t,e){return!(t<this.x1||t>this.x2||e<this.y1||e>this.y2)},bu.width=function(){return this.x2-this.x1},bu.height=function(){return this.y2-this.y1};var xu=0;const wu="p_";function ku(t){return t&&t.gradient}function _u(t,e,n){let r=t.id,i=t.gradient,a="radial"===i?wu:"";return r||(r=t.id="gradient_"+xu++,"radial"===i?(t.x1=Eu(t.x1,.5),t.y1=Eu(t.y1,.5),t.r1=Eu(t.r1,0),t.x2=Eu(t.x2,.5),t.y2=Eu(t.y2,.5),t.r2=Eu(t.r2,.5),a=wu):(t.x1=Eu(t.x1,0),t.y1=Eu(t.y1,0),t.x2=Eu(t.x2,1),t.y2=Eu(t.y2,0))),e[r]=t,"url("+(n||"")+"#"+a+r+")"}function Eu(t,e){return null!=t?t:e}var Ou=function(t,e){var n,r=[];return n={gradient:"linear",x1:t?t[0]:0,y1:t?t[1]:0,x2:e?e[0]:1,y2:e?e[1]:0,stops:r,stop:function(t,e){return r.push({offset:t,color:e}),n}}};function Su(t){this.mark=t,this.bounds=this.bounds||new yu}function Cu(t){Su.call(this,t),this.items=this.items||[]}function Au(t,e){if("undefined"!=typeof document&&document.createElement){var n=document.createElement("canvas");if(n&&n.getContext)return n.width=t,n.height=e,n}return null}function Nu(){return"undefined"!=typeof Image?Image:null}function Tu(t){this._pending=0,this._loader=t||xr()}Object(ct.y)(Cu,Su);var Iu=Tu.prototype;function Du(t){t._pending+=1}function Mu(t){t._pending-=1}function Ru(t){this._context=t}Iu.pending=function(){return this._pending},Iu.sanitizeURL=function(t){var e=this;return Du(e),e._loader.sanitize(t,{context:"href"}).then(function(t){return Mu(e),t}).catch(function(){return Mu(e),null})},Iu.loadImage=function(t){const e=this,n=Nu();return Du(e),e._loader.sanitize(t,{context:"image"}).then(function(t){const r=t.href;if(!r||!n)throw{url:r};const i=new n,a=Object(ct.v)(t,"crossOrigin")?t.crossOrigin:"anonymous";return null!=a&&(i.crossOrigin=a),i.onload=(()=>Mu(e)),i.onerror=(()=>Mu(e)),i.src=r,i}).catch(function(t){return Mu(e),{complete:!1,width:0,height:0,src:t&&t.url||""}})},Iu.ready=function(){var t=this;return new Promise(function(e){!function n(r){t.pending()?setTimeout(function(){n(!0)},10):e(r)}(!1)})},Ru.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:this._context.lineTo(t,e)}}};var Fu=function(t){return new Ru(t)},ju=function(){};function Pu(t,e,n){t._context.bezierCurveTo((2*t._x0+t._x1)/3,(2*t._y0+t._y1)/3,(t._x0+2*t._x1)/3,(t._y0+2*t._y1)/3,(t._x0+4*t._x1+e)/6,(t._y0+4*t._y1+n)/6)}function Lu(t){this._context=t}Lu.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:Pu(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:Pu(this,t,e)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}};function zu(t){this._context=t}zu.prototype={areaStart:ju,areaEnd:ju,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._y0=this._y1=this._y2=this._y3=this._y4=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x2,this._y2),this._context.closePath();break;case 2:this._context.moveTo((this._x2+2*this._x3)/3,(this._y2+2*this._y3)/3),this._context.lineTo((this._x3+2*this._x2)/3,(this._y3+2*this._y2)/3),this._context.closePath();break;case 3:this.point(this._x2,this._y2),this.point(this._x3,this._y3),this.point(this._x4,this._y4)}},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._x2=t,this._y2=e;break;case 1:this._point=2,this._x3=t,this._y3=e;break;case 2:this._point=3,this._x4=t,this._y4=e,this._context.moveTo((this._x0+4*this._x1+t)/6,(this._y0+4*this._y1+e)/6);break;default:Pu(this,t,e)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}};function Bu(t,e){this._basis=new Lu(t),this._beta=e}Bu.prototype={lineStart:function(){this._x=[],this._y=[],this._basis.lineStart()},lineEnd:function(){var t=this._x,e=this._y,n=t.length-1;if(n>0)for(var r,i=t[0],a=e[0],o=t[n]-i,s=e[n]-a,u=-1;++u<=n;)r=u/n,this._basis.point(this._beta*t[u]+(1-this._beta)*(i+r*o),this._beta*e[u]+(1-this._beta)*(a+r*s));this._x=this._y=null,this._basis.lineEnd()},point:function(t,e){this._x.push(+t),this._y.push(+e)}};var Uu=function t(e){function n(t){return 1===e?new Lu(t):new Bu(t,e)}return n.beta=function(e){return t(+e)},n}(.85);function Wu(t,e,n){t._context.bezierCurveTo(t._x1+t._k*(t._x2-t._x0),t._y1+t._k*(t._y2-t._y0),t._x2+t._k*(t._x1-e),t._y2+t._k*(t._y1-n),t._x2,t._y2)}function Vu(t,e){this._context=t,this._k=(1-e)/6}Vu.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:Wu(this,this._x1,this._y1)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2,this._x1=t,this._y1=e;break;case 2:this._point=3;default:Wu(this,t,e)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};var qu=function t(e){function n(t){return new Vu(t,e)}return n.tension=function(e){return t(+e)},n}(0);function Hu(t,e){this._context=t,this._k=(1-e)/6}Hu.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3,this._line?this._context.lineTo(this._x2,this._y2):this._context.moveTo(this._x2,this._y2);break;case 3:this._point=4;default:Wu(this,t,e)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};var Gu=function t(e){function n(t){return new Hu(t,e)}return n.tension=function(e){return t(+e)},n}(0);function $u(t,e){this._context=t,this._k=(1-e)/6}$u.prototype={areaStart:ju,areaEnd:ju,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._x5=this._y0=this._y1=this._y2=this._y3=this._y4=this._y5=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x3,this._y3),this._context.closePath();break;case 2:this._context.lineTo(this._x3,this._y3),this._context.closePath();break;case 3:this.point(this._x3,this._y3),this.point(this._x4,this._y4),this.point(this._x5,this._y5)}},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._x3=t,this._y3=e;break;case 1:this._point=2,this._context.moveTo(this._x4=t,this._y4=e);break;case 2:this._point=3,this._x5=t,this._y5=e;break;default:Wu(this,t,e)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};var Ku=function t(e){function n(t){return new $u(t,e)}return n.tension=function(e){return t(+e)},n}(0),Xu=Math.abs,Yu=Math.atan2,Ju=Math.cos,Zu=Math.max,Qu=Math.min,tc=Math.sin,ec=Math.sqrt,nc=1e-12,rc=Math.PI,ic=rc/2,ac=2*rc;function oc(t){return t>=1?ic:t<=-1?-ic:Math.asin(t)}function sc(t,e,n){var r=t._x1,i=t._y1,a=t._x2,o=t._y2;if(t._l01_a>nc){var s=2*t._l01_2a+3*t._l01_a*t._l12_a+t._l12_2a,u=3*t._l01_a*(t._l01_a+t._l12_a);r=(r*s-t._x0*t._l12_2a+t._x2*t._l01_2a)/u,i=(i*s-t._y0*t._l12_2a+t._y2*t._l01_2a)/u}if(t._l23_a>nc){var c=2*t._l23_2a+3*t._l23_a*t._l12_a+t._l12_2a,l=3*t._l23_a*(t._l23_a+t._l12_a);a=(a*c+t._x1*t._l23_2a-e*t._l12_2a)/l,o=(o*c+t._y1*t._l23_2a-n*t._l12_2a)/l}t._context.bezierCurveTo(r,i,a,o,t._x2,t._y2)}function uc(t,e){this._context=t,this._alpha=e}uc.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:this.point(this._x2,this._y2)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){if(t=+t,e=+e,this._point){var n=this._x2-t,r=this._y2-e;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(n*n+r*r,this._alpha))}switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3;default:sc(this,t,e)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};var cc=function t(e){function n(t){return e?new uc(t,e):new Vu(t,0)}return n.alpha=function(e){return t(+e)},n}(.5);function lc(t,e){this._context=t,this._alpha=e}lc.prototype={areaStart:ju,areaEnd:ju,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._x5=this._y0=this._y1=this._y2=this._y3=this._y4=this._y5=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){switch(this._point){case 1:this._context.moveTo(this._x3,this._y3),this._context.closePath();break;case 2:this._context.lineTo(this._x3,this._y3),this._context.closePath();break;case 3:this.point(this._x3,this._y3),this.point(this._x4,this._y4),this.point(this._x5,this._y5)}},point:function(t,e){if(t=+t,e=+e,this._point){var n=this._x2-t,r=this._y2-e;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(n*n+r*r,this._alpha))}switch(this._point){case 0:this._point=1,this._x3=t,this._y3=e;break;case 1:this._point=2,this._context.moveTo(this._x4=t,this._y4=e);break;case 2:this._point=3,this._x5=t,this._y5=e;break;default:sc(this,t,e)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};var fc=function t(e){function n(t){return e?new lc(t,e):new $u(t,0)}return n.alpha=function(e){return t(+e)},n}(.5);function dc(t){this._context=t}dc.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3;var n=(this._x0+4*this._x1+t)/6,r=(this._y0+4*this._y1+e)/6;this._line?this._context.lineTo(n,r):this._context.moveTo(n,r);break;case 3:this._point=4;default:Pu(this,t,e)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}};function hc(t){this._context=t}hc.prototype={areaStart:ju,areaEnd:ju,lineStart:function(){this._point=0},lineEnd:function(){this._point&&this._context.closePath()},point:function(t,e){t=+t,e=+e,this._point?this._context.lineTo(t,e):(this._point=1,this._context.moveTo(t,e))}};function pc(t){return t<0?-1:1}function mc(t,e,n){var r=t._x1-t._x0,i=e-t._x1,a=(t._y1-t._y0)/(r||i<0&&-0),o=(n-t._y1)/(i||r<0&&-0),s=(a*i+o*r)/(r+i);return(pc(a)+pc(o))*Math.min(Math.abs(a),Math.abs(o),.5*Math.abs(s))||0}function gc(t,e){var n=t._x1-t._x0;return n?(3*(t._y1-t._y0)/n-e)/2:e}function vc(t,e,n){var r=t._x0,i=t._y0,a=t._x1,o=t._y1,s=(a-r)/3;t._context.bezierCurveTo(r+s,i+s*e,a-s,o-s*n,a,o)}function yc(t){this._context=t}function bc(t){this._context=new xc(t)}function xc(t){this._context=t}function wc(t){this._context=t}function kc(t){var e,n,r=t.length-1,i=new Array(r),a=new Array(r),o=new Array(r);for(i[0]=0,a[0]=2,o[0]=t[0]+2*t[1],e=1;e<r-1;++e)i[e]=1,a[e]=4,o[e]=4*t[e]+2*t[e+1];for(i[r-1]=2,a[r-1]=7,o[r-1]=8*t[r-1]+t[r],e=1;e<r;++e)n=i[e]/a[e-1],a[e]-=n,o[e]-=n*o[e-1];for(i[r-1]=o[r-1]/a[r-1],e=r-2;e>=0;--e)i[e]=(o[e]-i[e+1])/a[e];for(a[r-1]=(t[r]+i[r-1])/2,e=0;e<r-1;++e)a[e]=2*t[e+1]-i[e+1];return[i,a]}yc.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=this._t0=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x1,this._y1);break;case 3:vc(this,this._t0,gc(this,this._t0))}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){var n=NaN;if(e=+e,(t=+t)!==this._x1||e!==this._y1){switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3,vc(this,gc(this,n=mc(this,t,e)),n);break;default:vc(this,this._t0,n=mc(this,t,e))}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e,this._t0=n}}},(bc.prototype=Object.create(yc.prototype)).point=function(t,e){yc.prototype.point.call(this,e,t)},xc.prototype={moveTo:function(t,e){this._context.moveTo(e,t)},closePath:function(){this._context.closePath()},lineTo:function(t,e){this._context.lineTo(e,t)},bezierCurveTo:function(t,e,n,r,i,a){this._context.bezierCurveTo(e,t,r,n,a,i)}},wc.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=[],this._y=[]},lineEnd:function(){var t=this._x,e=this._y,n=t.length;if(n)if(this._line?this._context.lineTo(t[0],e[0]):this._context.moveTo(t[0],e[0]),2===n)this._context.lineTo(t[1],e[1]);else for(var r=kc(t),i=kc(e),a=0,o=1;o<n;++a,++o)this._context.bezierCurveTo(r[0][a],i[0][a],r[1][a],i[1][a],t[o],e[o]);(this._line||0!==this._line&&1===n)&&this._context.closePath(),this._line=1-this._line,this._x=this._y=null},point:function(t,e){this._x.push(+t),this._y.push(+e)}};function _c(t,e){this._context=t,this._t=e}_c.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=this._y=NaN,this._point=0},lineEnd:function(){0<this._t&&this._t<1&&2===this._point&&this._context.lineTo(this._x,this._y),(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line>=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:if(this._t<=0)this._context.lineTo(this._x,e),this._context.lineTo(t,e);else{var n=this._x*(1-this._t)+t*this._t;this._context.lineTo(n,this._y),this._context.lineTo(n,e)}}this._x=t,this._y=e}};function Ec(t,e){this._context=t,this._alpha=e}Ec.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){(this._line||0!==this._line&&3===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){if(t=+t,e=+e,this._point){var n=this._x2-t,r=this._y2-e;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(n*n+r*r,this._alpha))}switch(this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3,this._line?this._context.lineTo(this._x2,this._y2):this._context.moveTo(this._x2,this._y2);break;case 3:this._point=4;default:sc(this,t,e)}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};var Oc={basis:{curve:function(t){return new Lu(t)}},"basis-closed":{curve:function(t){return new zu(t)}},"basis-open":{curve:function(t){return new dc(t)}},bundle:{curve:Uu,tension:"beta",value:.85},cardinal:{curve:qu,tension:"tension",value:0},"cardinal-open":{curve:Gu,tension:"tension",value:0},"cardinal-closed":{curve:Ku,tension:"tension",value:0},"catmull-rom":{curve:cc,tension:"alpha",value:.5},"catmull-rom-closed":{curve:fc,tension:"alpha",value:.5},"catmull-rom-open":{curve:function t(e){function n(t){return e?new Ec(t,e):new Hu(t,0)}return n.alpha=function(e){return t(+e)},n}(.5),tension:"alpha",value:.5},linear:{curve:Fu},"linear-closed":{curve:function(t){return new hc(t)}},monotone:{horizontal:function(t){return new bc(t)},vertical:function(t){return new yc(t)}},natural:{curve:function(t){return new wc(t)}},step:{curve:function(t){return new _c(t,.5)}},"step-after":{curve:function(t){return new _c(t,1)}},"step-before":{curve:function(t){return new _c(t,0)}}};function Sc(t,e,n){var r=Object(ct.v)(Oc,t)&&Oc[t],i=null;return r&&(i=r.curve||r[e||"vertical"],r.tension&&null!=n&&(i=i[r.tension](n))),i}var Cc={m:2,l:2,h:1,v:1,c:6,s:4,q:4,t:2,a:7},Ac=[/([MLHVCSQTAZmlhvcsqtaz])/g,/###/,/(\d)([-+])/g,/\s|,|###/],Nc=function(t){var e,n,r,i,a,o,s,u,c,l,f,d=[];for(u=0,l=(e=t.slice().replace(Ac[0],"###$1").split(Ac[1]).slice(1)).length;u<l;++u){for(r=(n=e[u]).slice(1).trim().replace(Ac[2],"$1###$2").split(Ac[3]),i=[o=n.charAt(0)],c=0,f=r.length;c<f;++c)(a=+r[c])===a&&i.push(a);if(s=Cc[o.toLowerCase()],i.length-1>s)for(c=1,f=i.length;c<f;c+=s)d.push([o].concat(i.slice(c,c+s)));else d.push(i)}return d};const Tc=Math.PI/180,Ic=1e-14,Dc=Math.PI/2,Mc=2*Math.PI,Rc=Math.sqrt(3)/2;var Fc={},jc={},Pc=[].join;function Lc(t){var e=Pc.call(t);if(jc[e])return jc[e];var n=t[0],r=t[1],i=t[2],a=t[3],o=t[4],s=t[5],u=t[6],c=t[7],l=c*o,f=-u*s,d=u*o,h=c*s,p=Math.cos(i),m=Math.sin(i),g=Math.cos(a),v=Math.sin(a),y=.5*(a-i),b=Math.sin(.5*y),x=8/3*b*b/Math.sin(y),w=n+p-x*m,k=r+m+x*p,_=n+g,E=r+v,O=_+x*v,S=E-x*g;return jc[e]=[l*w+f*k,d*w+h*k,l*O+f*S,d*O+h*S,l*_+f*E,d*_+h*E]}var zc=["l",0,0,0,0,0,0,0];function Bc(t,e,n){var r=zc[0]=t[0];if("a"===r||"A"===r)zc[1]=e*t[1],zc[2]=n*t[2],zc[3]=t[3],zc[4]=t[4],zc[5]=t[5],zc[6]=e*t[6],zc[7]=n*t[7];else if("h"===r||"H"===r)zc[1]=e*t[1];else if("v"===r||"V"===r)zc[1]=n*t[1];else for(var i=1,a=t.length;i<a;++i)zc[i]=(i%2==1?e:n)*t[i];return zc}var Uc=function(t,e,n,r,i,a){var o,s,u,c,l,f=null,d=0,h=0,p=0,m=0;null==n&&(n=0),null==r&&(r=0),null==i&&(i=1),null==a&&(a=i),t.beginPath&&t.beginPath();for(var g=0,v=e.length;g<v;++g){switch(o=e[g],1===i&&1===a||(o=Bc(o,i,a)),o[0]){case"l":d+=o[1],h+=o[2],t.lineTo(d+n,h+r);break;case"L":d=o[1],h=o[2],t.lineTo(d+n,h+r);break;case"h":d+=o[1],t.lineTo(d+n,h+r);break;case"H":d=o[1],t.lineTo(d+n,h+r);break;case"v":h+=o[1],t.lineTo(d+n,h+r);break;case"V":h=o[1],t.lineTo(d+n,h+r);break;case"m":d+=o[1],h+=o[2],t.moveTo(d+n,h+r);break;case"M":d=o[1],h=o[2],t.moveTo(d+n,h+r);break;case"c":s=d+o[5],u=h+o[6],p=d+o[3],m=h+o[4],t.bezierCurveTo(d+o[1]+n,h+o[2]+r,p+n,m+r,s+n,u+r),d=s,h=u;break;case"C":d=o[5],h=o[6],p=o[3],m=o[4],t.bezierCurveTo(o[1]+n,o[2]+r,p+n,m+r,d+n,h+r);break;case"s":s=d+o[3],u=h+o[4],p=2*d-p,m=2*h-m,t.bezierCurveTo(p+n,m+r,d+o[1]+n,h+o[2]+r,s+n,u+r),p=d+o[1],m=h+o[2],d=s,h=u;break;case"S":s=o[3],u=o[4],p=2*d-p,m=2*h-m,t.bezierCurveTo(p+n,m+r,o[1]+n,o[2]+r,s+n,u+r),d=s,h=u,p=o[1],m=o[2];break;case"q":s=d+o[3],u=h+o[4],p=d+o[1],m=h+o[2],t.quadraticCurveTo(p+n,m+r,s+n,u+r),d=s,h=u;break;case"Q":s=o[3],u=o[4],t.quadraticCurveTo(o[1]+n,o[2]+r,s+n,u+r),d=s,h=u,p=o[1],m=o[2];break;case"t":s=d+o[1],u=h+o[2],null===f[0].match(/[QqTt]/)?(p=d,m=h):"t"===f[0]?(p=2*d-c,m=2*h-l):"q"===f[0]&&(p=2*d-p,m=2*h-m),c=p,l=m,t.quadraticCurveTo(p+n,m+r,s+n,u+r),h=u,p=(d=s)+o[1],m=h+o[2];break;case"T":s=o[1],u=o[2],p=2*d-p,m=2*h-m,t.quadraticCurveTo(p+n,m+r,s+n,u+r),d=s,h=u;break;case"a":Wc(t,d+n,h+r,[o[1],o[2],o[3],o[4],o[5],o[6]+d+n,o[7]+h+r]),d+=o[6],h+=o[7];break;case"A":Wc(t,d+n,h+r,[o[1],o[2],o[3],o[4],o[5],o[6]+n,o[7]+r]),d=o[6],h=o[7];break;case"z":case"Z":t.closePath()}f=o}};function Wc(t,e,n,r){for(var i=function(t,e,n,r,i,a,o,s,u){var c=Pc.call(arguments);if(Fc[c])return Fc[c];var l=o*Tc,f=Math.sin(l),d=Math.cos(l),h=d*(s-t)*.5+f*(u-e)*.5,p=d*(u-e)*.5-f*(s-t)*.5,m=h*h/((n=Math.abs(n))*n)+p*p/((r=Math.abs(r))*r);m>1&&(n*=m=Math.sqrt(m),r*=m);var g=d/n,v=f/n,y=-f/r,b=d/r,x=g*s+v*u,w=y*s+b*u,k=g*t+v*e,_=y*t+b*e,E=1/((k-x)*(k-x)+(_-w)*(_-w))-.25;E<0&&(E=0);var O=Math.sqrt(E);a==i&&(O=-O);var S=.5*(x+k)-O*(_-w),C=.5*(w+_)+O*(k-x),A=Math.atan2(w-C,x-S),N=Math.atan2(_-C,k-S)-A;N<0&&1===a?N+=Mc:N>0&&0===a&&(N-=Mc);for(var T=Math.ceil(Math.abs(N/(Dc+.001))),I=[],D=0;D<T;++D){var M=A+D*N/T,R=A+(D+1)*N/T;I[D]=[S,C,M,R,n,r,f,d]}return Fc[c]=I}(r[5],r[6],r[0],r[1],r[3],r[4],r[2],e,n),a=0;a<i.length;++a){var o=Lc(i[a]);t.bezierCurveTo(o[0],o[1],o[2],o[3],o[4],o[5])}}var Vc={circle:{draw:function(t,e){var n=Math.sqrt(e)/2;t.moveTo(n,0),t.arc(0,0,n,0,Mc)}},cross:{draw:function(t,e){var n=Math.sqrt(e)/2,r=n/2.5;t.moveTo(-n,-r),t.lineTo(-n,r),t.lineTo(-r,r),t.lineTo(-r,n),t.lineTo(r,n),t.lineTo(r,r),t.lineTo(n,r),t.lineTo(n,-r),t.lineTo(r,-r),t.lineTo(r,-n),t.lineTo(-r,-n),t.lineTo(-r,-r),t.closePath()}},diamond:{draw:function(t,e){var n=Math.sqrt(e)/2;t.moveTo(-n,0),t.lineTo(0,-n),t.lineTo(n,0),t.lineTo(0,n),t.closePath()}},square:{draw:function(t,e){var n=Math.sqrt(e),r=-n/2;t.rect(r,r,n,n)}},arrow:{draw:function(t,e){var n=Math.sqrt(e)/2,r=n/7,i=n/2.5,a=n/8;t.moveTo(-r,n),t.lineTo(r,n),t.lineTo(r,-a),t.lineTo(i,-a),t.lineTo(0,-n),t.lineTo(-i,-a),t.lineTo(-r,-a),t.closePath()}},wedge:{draw:function(t,e){var n=Math.sqrt(e)/2,r=Rc*n,i=r-.5773502691896257*n,a=n/4;t.moveTo(0,-r-i),t.lineTo(-a,r-i),t.lineTo(a,r-i),t.closePath()}},triangle:{draw:function(t,e){var n=Math.sqrt(e)/2,r=Rc*n,i=r-.5773502691896257*n;t.moveTo(0,-r-i),t.lineTo(-n,r-i),t.lineTo(n,r-i),t.closePath()}},"triangle-up":{draw:function(t,e){var n=Math.sqrt(e)/2,r=Rc*n;t.moveTo(0,-r),t.lineTo(-n,r),t.lineTo(n,r),t.closePath()}},"triangle-down":{draw:function(t,e){var n=Math.sqrt(e)/2,r=Rc*n;t.moveTo(0,r),t.lineTo(-n,-r),t.lineTo(n,-r),t.closePath()}},"triangle-right":{draw:function(t,e){var n=Math.sqrt(e)/2,r=Rc*n;t.moveTo(r,0),t.lineTo(-r,-n),t.lineTo(-r,n),t.closePath()}},"triangle-left":{draw:function(t,e){var n=Math.sqrt(e)/2,r=Rc*n;t.moveTo(-r,0),t.lineTo(r,-n),t.lineTo(r,n),t.closePath()}},stroke:{draw:function(t,e){var n=Math.sqrt(e)/2;t.moveTo(-n,0),t.lineTo(n,0)}}};function qc(t){return Object(ct.v)(Vc,t)?Vc[t]:function(t){if(!Object(ct.v)(Hc,t)){var e=Nc(t);Hc[t]={draw:function(t,n){Uc(t,e,0,0,Math.sqrt(n)/2)}}}return Hc[t]}(t)}var Hc={};var Gc=Math.PI,$c=2*Gc,Kc=$c-1e-6;function Xc(){this._x0=this._y0=this._x1=this._y1=null,this._=""}function Yc(){return new Xc}Xc.prototype=Yc.prototype={constructor:Xc,moveTo:function(t,e){this._+="M"+(this._x0=this._x1=+t)+","+(this._y0=this._y1=+e)},closePath:function(){null!==this._x1&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")},lineTo:function(t,e){this._+="L"+(this._x1=+t)+","+(this._y1=+e)},quadraticCurveTo:function(t,e,n,r){this._+="Q"+ +t+","+ +e+","+(this._x1=+n)+","+(this._y1=+r)},bezierCurveTo:function(t,e,n,r,i,a){this._+="C"+ +t+","+ +e+","+ +n+","+ +r+","+(this._x1=+i)+","+(this._y1=+a)},arcTo:function(t,e,n,r,i){t=+t,e=+e,n=+n,r=+r,i=+i;var a=this._x1,o=this._y1,s=n-t,u=r-e,c=a-t,l=o-e,f=c*c+l*l;if(i<0)throw new Error("negative radius: "+i);if(null===this._x1)this._+="M"+(this._x1=t)+","+(this._y1=e);else if(f>1e-6)if(Math.abs(l*s-u*c)>1e-6&&i){var d=n-a,h=r-o,p=s*s+u*u,m=d*d+h*h,g=Math.sqrt(p),v=Math.sqrt(f),y=i*Math.tan((Gc-Math.acos((p+f-m)/(2*g*v)))/2),b=y/v,x=y/g;Math.abs(b-1)>1e-6&&(this._+="L"+(t+b*c)+","+(e+b*l)),this._+="A"+i+","+i+",0,0,"+ +(l*d>c*h)+","+(this._x1=t+x*s)+","+(this._y1=e+x*u)}else this._+="L"+(this._x1=t)+","+(this._y1=e);else;},arc:function(t,e,n,r,i,a){t=+t,e=+e,a=!!a;var o=(n=+n)*Math.cos(r),s=n*Math.sin(r),u=t+o,c=e+s,l=1^a,f=a?r-i:i-r;if(n<0)throw new Error("negative radius: "+n);null===this._x1?this._+="M"+u+","+c:(Math.abs(this._x1-u)>1e-6||Math.abs(this._y1-c)>1e-6)&&(this._+="L"+u+","+c),n&&(f<0&&(f=f%$c+$c),f>Kc?this._+="A"+n+","+n+",0,1,"+l+","+(t-o)+","+(e-s)+"A"+n+","+n+",0,1,"+l+","+(this._x1=u)+","+(this._y1=c):f>1e-6&&(this._+="A"+n+","+n+",0,"+ +(f>=Gc)+","+l+","+(this._x1=t+n*Math.cos(i))+","+(this._y1=e+n*Math.sin(i))))},rect:function(t,e,n,r){this._+="M"+(this._x0=this._x1=+t)+","+(this._y0=this._y1=+e)+"h"+ +n+"v"+ +r+"h"+-n+"Z"},toString:function(){return this._}};var Jc=Yc;const Zc=.448084975506;function Qc(t){return t.x}function tl(t){return t.y}function el(t){return t.width}function nl(t){return t.height}function rl(t){return"function"==typeof t?t:()=>+t}function il(t,e,n){return Math.max(e,Math.min(t,n))}var al=function(){var t=Qc,e=tl,n=el,r=nl,i=rl(0),a=i,o=i,s=i,u=null;function c(c,l,f){var d,h=null!=l?l:+t.call(this,c),p=null!=f?f:+e.call(this,c),m=+n.call(this,c),g=+r.call(this,c),v=Math.min(m,g)/2,y=il(+i.call(this,c),0,v),b=il(+a.call(this,c),0,v),x=il(+o.call(this,c),0,v),w=il(+s.call(this,c),0,v);if(u||(u=d=Jc()),y<=0&&b<=0&&x<=0&&w<=0)u.rect(h,p,m,g);else{var k=h+m,_=p+g;u.moveTo(h+y,p),u.lineTo(k-b,p),u.bezierCurveTo(k-Zc*b,p,k,p+Zc*b,k,p+b),u.lineTo(k,_-w),u.bezierCurveTo(k,_-Zc*w,k-Zc*w,_,k-w,_),u.lineTo(h+x,_),u.bezierCurveTo(h+Zc*x,_,h,_-Zc*x,h,_-x),u.lineTo(h,p+y),u.bezierCurveTo(h,p+Zc*y,h+Zc*y,p,h+y,p),u.closePath()}if(d)return u=null,d+""||null}return c.x=function(e){return arguments.length?(t=rl(e),c):t},c.y=function(t){return arguments.length?(e=rl(t),c):e},c.width=function(t){return arguments.length?(n=rl(t),c):n},c.height=function(t){return arguments.length?(r=rl(t),c):r},c.cornerRadius=function(t,e,n,r){return arguments.length?(i=rl(t),a=null!=e?rl(e):i,s=null!=n?rl(n):i,o=null!=r?rl(r):a,c):i},c.context=function(t){return arguments.length?(u=null==t?null:t,c):u},c},ol=function(){var t,e,n,r,i,a,o,s,u=null;function c(t,e,n){var r=n/2;if(i){var c=o-e,l=t-a;if(c||l){var f=Math.sqrt(c*c+l*l),d=(c/=f)*s,h=(l/=f)*s,p=Math.atan2(l,c);u.moveTo(a-d,o-h),u.lineTo(t-c*r,e-l*r),u.arc(t,e,r,p-Math.PI,p),u.lineTo(a+d,o+h),u.arc(a,o,s,p,p+Math.PI)}else u.arc(t,e,r,0,Mc);u.closePath()}else i=1;a=t,o=e,s=r}function l(a){var o,s,l,f=a.length,d=!1;for(null==u&&(u=l=Jc()),o=0;o<=f;++o)!(o<f&&r(s=a[o],o,a))===d&&(d=!d)&&(i=0),d&&c(+t(s,o,a),+e(s,o,a),+n(s,o,a));if(l)return u=null,l+""||null}return l.x=function(e){return arguments.length?(t=e,l):t},l.y=function(t){return arguments.length?(e=t,l):e},l.size=function(t){return arguments.length?(n=t,l):n},l.defined=function(t){return arguments.length?(r=t,l):r},l.context=function(t){return arguments.length?(u=null==t?null:t,l):u},l},sl=function(t){return function(){return t}};function ul(t){return t[0]}function cl(t){return t[1]}var ll=function(){var t=ul,e=cl,n=sl(!0),r=null,i=Fu,a=null;function o(o){var s,u,c,l=o.length,f=!1;for(null==r&&(a=i(c=Jc())),s=0;s<=l;++s)!(s<l&&n(u=o[s],s,o))===f&&((f=!f)?a.lineStart():a.lineEnd()),f&&a.point(+t(u,s,o),+e(u,s,o));if(c)return a=null,c+""||null}return o.x=function(e){return arguments.length?(t="function"==typeof e?e:sl(+e),o):t},o.y=function(t){return arguments.length?(e="function"==typeof t?t:sl(+t),o):e},o.defined=function(t){return arguments.length?(n="function"==typeof t?t:sl(!!t),o):n},o.curve=function(t){return arguments.length?(i=t,null!=r&&(a=i(r)),o):i},o.context=function(t){return arguments.length?(null==t?r=a=null:a=i(r=t),o):r},o},fl=function(){var t=ul,e=null,n=sl(0),r=cl,i=sl(!0),a=null,o=Fu,s=null;function u(u){var c,l,f,d,h,p=u.length,m=!1,g=new Array(p),v=new Array(p);for(null==a&&(s=o(h=Jc())),c=0;c<=p;++c){if(!(c<p&&i(d=u[c],c,u))===m)if(m=!m)l=c,s.areaStart(),s.lineStart();else{for(s.lineEnd(),s.lineStart(),f=c-1;f>=l;--f)s.point(g[f],v[f]);s.lineEnd(),s.areaEnd()}m&&(g[c]=+t(d,c,u),v[c]=+n(d,c,u),s.point(e?+e(d,c,u):g[c],r?+r(d,c,u):v[c]))}if(h)return s=null,h+""||null}function c(){return ll().defined(i).curve(o).context(a)}return u.x=function(n){return arguments.length?(t="function"==typeof n?n:sl(+n),e=null,u):t},u.x0=function(e){return arguments.length?(t="function"==typeof e?e:sl(+e),u):t},u.x1=function(t){return arguments.length?(e=null==t?null:"function"==typeof t?t:sl(+t),u):e},u.y=function(t){return arguments.length?(n="function"==typeof t?t:sl(+t),r=null,u):n},u.y0=function(t){return arguments.length?(n="function"==typeof t?t:sl(+t),u):n},u.y1=function(t){return arguments.length?(r=null==t?null:"function"==typeof t?t:sl(+t),u):r},u.lineX0=u.lineY0=function(){return c().x(t).y(n)},u.lineY1=function(){return c().x(t).y(r)},u.lineX1=function(){return c().x(e).y(n)},u.defined=function(t){return arguments.length?(i="function"==typeof t?t:sl(!!t),u):i},u.curve=function(t){return arguments.length?(o=t,null!=a&&(s=o(a)),u):o},u.context=function(t){return arguments.length?(null==t?a=s=null:s=o(a=t),u):a},u},dl={draw:function(t,e){var n=Math.sqrt(e/rc);t.moveTo(n,0),t.arc(0,0,n,0,ac)}},hl=(Math.sqrt(1/3),Math.sin(rc/10)/Math.sin(7*rc/10));Math.sin(ac/10),Math.cos(ac/10),Math.sqrt(3),Math.sqrt(3),Math.sqrt(12);function pl(t){return t.innerRadius}function ml(t){return t.outerRadius}function gl(t){return t.startAngle}function vl(t){return t.endAngle}function yl(t){return t&&t.padAngle}function bl(t,e,n,r,i,a,o){var s=t-n,u=e-r,c=(o?a:-a)/ec(s*s+u*u),l=c*u,f=-c*s,d=t+l,h=e+f,p=n+l,m=r+f,g=(d+p)/2,v=(h+m)/2,y=p-d,b=m-h,x=y*y+b*b,w=i-a,k=d*m-p*h,_=(b<0?-1:1)*ec(Zu(0,w*w*x-k*k)),E=(k*b-y*_)/x,O=(-k*y-b*_)/x,S=(k*b+y*_)/x,C=(-k*y+b*_)/x,A=E-g,N=O-v,T=S-g,I=C-v;return A*A+N*N>T*T+I*I&&(E=S,O=C),{cx:E,cy:O,x01:-l,y01:-f,x11:E*(i/w-1),y11:O*(i/w-1)}}function xl(t,e){return null!=t?t:e}const wl=t=>t.x||0,kl=t=>t.y||0,_l=t=>!(!1===t.defined),El=function(){var t=pl,e=ml,n=sl(0),r=null,i=gl,a=vl,o=yl,s=null;function u(){var u,c,l=+t.apply(this,arguments),f=+e.apply(this,arguments),d=i.apply(this,arguments)-ic,h=a.apply(this,arguments)-ic,p=Xu(h-d),m=h>d;if(s||(s=u=Jc()),f<l&&(c=f,f=l,l=c),f>nc)if(p>ac-nc)s.moveTo(f*Ju(d),f*tc(d)),s.arc(0,0,f,d,h,!m),l>nc&&(s.moveTo(l*Ju(h),l*tc(h)),s.arc(0,0,l,h,d,m));else{var g,v,y=d,b=h,x=d,w=h,k=p,_=p,E=o.apply(this,arguments)/2,O=E>nc&&(r?+r.apply(this,arguments):ec(l*l+f*f)),S=Qu(Xu(f-l)/2,+n.apply(this,arguments)),C=S,A=S;if(O>nc){var N=oc(O/l*tc(E)),T=oc(O/f*tc(E));(k-=2*N)>nc?(x+=N*=m?1:-1,w-=N):(k=0,x=w=(d+h)/2),(_-=2*T)>nc?(y+=T*=m?1:-1,b-=T):(_=0,y=b=(d+h)/2)}var I=f*Ju(y),D=f*tc(y),M=l*Ju(w),R=l*tc(w);if(S>nc){var F,j=f*Ju(b),P=f*tc(b),L=l*Ju(x),z=l*tc(x);if(p<rc&&(F=function(t,e,n,r,i,a,o,s){var u=n-t,c=r-e,l=o-i,f=s-a,d=f*u-l*c;if(!(d*d<nc))return[t+(d=(l*(e-a)-f*(t-i))/d)*u,e+d*c]}(I,D,L,z,j,P,M,R))){var B=I-F[0],U=D-F[1],W=j-F[0],V=P-F[1],q=1/tc(function(t){return t>1?0:t<-1?rc:Math.acos(t)}((B*W+U*V)/(ec(B*B+U*U)*ec(W*W+V*V)))/2),H=ec(F[0]*F[0]+F[1]*F[1]);C=Qu(S,(l-H)/(q-1)),A=Qu(S,(f-H)/(q+1))}}_>nc?A>nc?(g=bl(L,z,I,D,f,A,m),v=bl(j,P,M,R,f,A,m),s.moveTo(g.cx+g.x01,g.cy+g.y01),A<S?s.arc(g.cx,g.cy,A,Yu(g.y01,g.x01),Yu(v.y01,v.x01),!m):(s.arc(g.cx,g.cy,A,Yu(g.y01,g.x01),Yu(g.y11,g.x11),!m),s.arc(0,0,f,Yu(g.cy+g.y11,g.cx+g.x11),Yu(v.cy+v.y11,v.cx+v.x11),!m),s.arc(v.cx,v.cy,A,Yu(v.y11,v.x11),Yu(v.y01,v.x01),!m))):(s.moveTo(I,D),s.arc(0,0,f,y,b,!m)):s.moveTo(I,D),l>nc&&k>nc?C>nc?(g=bl(M,R,j,P,l,-C,m),v=bl(I,D,L,z,l,-C,m),s.lineTo(g.cx+g.x01,g.cy+g.y01),C<S?s.arc(g.cx,g.cy,C,Yu(g.y01,g.x01),Yu(v.y01,v.x01),!m):(s.arc(g.cx,g.cy,C,Yu(g.y01,g.x01),Yu(g.y11,g.x11),!m),s.arc(0,0,l,Yu(g.cy+g.y11,g.cx+g.x11),Yu(v.cy+v.y11,v.cx+v.x11),m),s.arc(v.cx,v.cy,C,Yu(v.y11,v.x11),Yu(v.y01,v.x01),!m))):s.arc(0,0,l,w,x,m):s.lineTo(M,R)}else s.moveTo(0,0);if(s.closePath(),u)return s=null,u+""||null}return u.centroid=function(){var n=(+t.apply(this,arguments)+ +e.apply(this,arguments))/2,r=(+i.apply(this,arguments)+ +a.apply(this,arguments))/2-rc/2;return[Ju(r)*n,tc(r)*n]},u.innerRadius=function(e){return arguments.length?(t="function"==typeof e?e:sl(+e),u):t},u.outerRadius=function(t){return arguments.length?(e="function"==typeof t?t:sl(+t),u):e},u.cornerRadius=function(t){return arguments.length?(n="function"==typeof t?t:sl(+t),u):n},u.padRadius=function(t){return arguments.length?(r=null==t?null:"function"==typeof t?t:sl(+t),u):r},u.startAngle=function(t){return arguments.length?(i="function"==typeof t?t:sl(+t),u):i},u.endAngle=function(t){return arguments.length?(a="function"==typeof t?t:sl(+t),u):a},u.padAngle=function(t){return arguments.length?(o="function"==typeof t?t:sl(+t),u):o},u.context=function(t){return arguments.length?(s=null==t?null:t,u):s},u}().startAngle(t=>t.startAngle||0).endAngle(t=>t.endAngle||0).padAngle(t=>t.padAngle||0).innerRadius(t=>t.innerRadius||0).outerRadius(t=>t.outerRadius||0).cornerRadius(t=>t.cornerRadius||0),Ol=fl().x(wl).y1(kl).y0(t=>(t.y||0)+(t.height||0)).defined(_l),Sl=fl().y(kl).x1(wl).x0(t=>(t.x||0)+(t.width||0)).defined(_l),Cl=ll().x(wl).y(kl).defined(_l),Al=al().x(wl).y(kl).width(t=>t.width||0).height(t=>t.height||0).cornerRadius(t=>xl(t.cornerRadiusTopLeft,t.cornerRadius)||0,t=>xl(t.cornerRadiusTopRight,t.cornerRadius)||0,t=>xl(t.cornerRadiusBottomRight,t.cornerRadius)||0,t=>xl(t.cornerRadiusBottomLeft,t.cornerRadius)||0),Nl=function(){var t=sl(dl),e=sl(64),n=null;function r(){var r;if(n||(n=r=Jc()),t.apply(this,arguments).draw(n,+e.apply(this,arguments)),r)return n=null,r+""||null}return r.type=function(e){return arguments.length?(t="function"==typeof e?e:sl(e),r):t},r.size=function(t){return arguments.length?(e="function"==typeof t?t:sl(+t),r):e},r.context=function(t){return arguments.length?(n=null==t?null:t,r):n},r}().type(t=>qc(t.shape||"circle")).size(t=>xl(t.size,64)),Tl=ol().x(wl).y(kl).defined(_l).size(t=>t.size||1);function Il(t){return t.cornerRadius||t.cornerRadiusTopLeft||t.cornerRadiusTopRight||t.cornerRadiusBottomRight||t.cornerRadiusBottomLeft}function Dl(t,e,n,r){return Al.context(t)(e,n,r)}var Ml=function(t,e,n){if(e.stroke&&0!==e.opacity&&0!==e.strokeOpacity){const r=null!=e.strokeWidth?+e.strokeWidth:1;t.expand(r+(n?function(t,e){return t.strokeJoin&&"miter"!==t.strokeJoin?0:e}(e,r):0))}return t};var Rl,Fl,jl,Pl=Mc-1e-8;function Ll(t){return Rl=t,Ll}function zl(){}function Bl(t,e){Rl.add(t,e)}function Ul(t,e){Bl(Fl=t,jl=e)}function Wl(t){Bl(t,Rl.y1)}function Vl(t){Bl(Rl.x1,t)}function ql(t,e,n,r){const i=(t-e)/(t+n-2*e);0<i&&i<1&&r(t+(e-t)*i)}function Hl(t,e,n,r,i){const a=r-t+3*e-3*n,o=t+n-2*e,s=t-e;let u,c=0,l=0;Math.abs(a)>Ic?(u=o*o+s*a)>=0&&(c=(-o+(u=Math.sqrt(u)))/a,l=(-o-u)/a):c=.5*s/o,0<c&&c<1&&i(Gl(c,t,e,n,r)),0<l&&l<1&&i(Gl(l,t,e,n,r))}function Gl(t,e,n,r,i){const a=1-t,o=a*a,s=t*t;return o*a*e+3*o*t*n+3*a*s*r+s*t*i}Ll.beginPath=zl,Ll.closePath=zl,Ll.moveTo=Ul,Ll.lineTo=Ul,Ll.rect=function(t,e,n,r){Bl(t+n,e+r),Ul(t,e)},Ll.quadraticCurveTo=function(t,e,n,r){ql(Fl,t,n,Wl),ql(jl,e,r,Vl),Ul(n,r)},Ll.bezierCurveTo=function(t,e,n,r,i,a){Hl(Fl,t,n,i,Wl),Hl(jl,e,r,a,Vl),Ul(i,a)},Ll.arc=function(t,e,n,r,i,a){if(Fl=n*Math.cos(i)+t,jl=n*Math.sin(i)+e,Math.abs(i-r)>Pl)Bl(t-n,e-n),Bl(t+n,e+n);else{const o=r=>Bl(n*Math.cos(r)+t,n*Math.sin(r)+e);let s,u;if(o(r),o(i),i!==r)if((r%=Mc)<0&&(r+=Mc),(i%=Mc)<0&&(i+=Mc),i<r&&(a=!a,s=r,r=i,i=s),a)for(i-=Mc,s=r-r%Dc,u=0;u<4&&s>i;++u,s-=Dc)o(s);else for(s=r-r%Dc+Dc,u=0;u<4&&s<i;++u,s+=Dc)o(s)}};var $l=($l=Au(1,1))?$l.getContext("2d"):null;const Kl=new yu;function Xl(t){return function(e,n){if(!$l)return!0;t($l,e),Kl.clear().union(e.bounds).intersect(n).round();const{x1:r,y1:i,x2:a,y2:o}=Kl;for(let t=i;t<=o;++t)for(let e=r;e<=a;++e)if($l.isPointInPath(e,t))return!0;return!1}}function Yl(t,e){return e.contains(t.x||0,t.y||0)}function Jl(t,e){const n=t.x||0,r=t.y||0,i=t.width||0,a=t.height||0;return e.intersects(Kl.set(n,r,n+i,r+a))}function Zl(t,e){const n=t.x||0,r=t.y||0;return Ql(e,n,r,null!=t.x2?t.x2:n,null!=t.y2?t.y2:r)}function Ql(t,e,n,r,i){const{x1:a,y1:o,x2:s,y2:u}=t,c=r-e,l=i-n;let f,d,h,p,m=0,g=1;for(p=0;p<4;++p){if(0===p&&(f=-c,d=-(a-e)),1===p&&(f=c,d=s-e),2===p&&(f=-l,d=-(o-n)),3===p&&(f=l,d=u-n),Math.abs(f)<1e-10&&d<0)return!1;if(h=d/f,f<0){if(h>g)return!1;h>m&&(m=h)}else if(f>0){if(h<m)return!1;h<g&&(g=h)}}return!0}var tf=function(t,e){t.globalCompositeOperation=e.blend||"source-over"};function ef(t,e){return null==t?e:t}function nf(t,e){const n=e.length;for(let r=0;r<n;++r)t.addColorStop(e[r].offset,e[r].color);return t}var rf=function(t,e,n){return ku(n)?function(t,e,n){const r=n.width(),i=n.height();let a;if("radial"===e.gradient)a=t.createRadialGradient(n.x1+ef(e.x1,.5)*r,n.y1+ef(e.y1,.5)*i,Math.max(r,i)*ef(e.r1,0),n.x1+ef(e.x2,.5)*r,n.y1+ef(e.y2,.5)*i,Math.max(r,i)*ef(e.r2,.5));else{const o=ef(e.x1,0),s=ef(e.y1,0),u=ef(e.x2,1),c=ef(e.y2,0);if(o!==u&&s!==c&&r!==i){const n=Au(Math.ceil(r),Math.ceil(i)),a=n.getContext("2d");return a.scale(r,i),a.fillStyle=nf(a.createLinearGradient(o,s,u,c),e.stops),a.fillRect(0,0,r,i),t.createPattern(n,"no-repeat")}a=t.createLinearGradient(n.x1+o*r,n.y1+s*i,n.x1+u*r,n.y1+c*i)}return nf(a,e.stops)}(t,n,e.bounds):n},af=function(t,e,n){return(n*=null==e.fillOpacity?1:e.fillOpacity)>0&&(t.globalAlpha=n,t.fillStyle=rf(t,e,e.fill),!0)},of=[],sf=function(t,e,n){var r=null!=(r=e.strokeWidth)?r:1;return!(r<=0)&&((n*=null==e.strokeOpacity?1:e.strokeOpacity)>0&&(t.globalAlpha=n,t.strokeStyle=rf(t,e,e.stroke),t.lineWidth=r,t.lineCap=e.strokeCap||"butt",t.lineJoin=e.strokeJoin||"miter",t.miterLimit=e.strokeMiterLimit||10,t.setLineDash&&(t.setLineDash(e.strokeDash||of),t.lineDashOffset=e.strokeDashOffset||0),!0))};function uf(t,e){return t.zindex-e.zindex||t.index-e.index}function cf(t){if(!t.zdirty)return t.zitems;var e,n,r,i=t.items,a=[];for(n=0,r=i.length;n<r;++n)(e=i[n]).index=n,e.zindex&&a.push(e);return t.zdirty=!1,t.zitems=a.sort(uf)}function lf(t,e){var n,r,i=t.items;if(i&&i.length){var a=cf(t);if(a&&a.length){for(n=0,r=i.length;n<r;++n)i[n].zindex||e(i[n]);i=a}for(n=0,r=i.length;n<r;++n)e(i[n])}}function ff(t,e){var n,r,i=t.items;if(!i||!i.length)return null;var a=cf(t);for(a&&a.length&&(i=a),r=i.length;--r>=0;)if(n=e(i[r]))return n;if(i===a)for(r=(i=t.items).length;--r>=0;)if(!i[r].zindex&&(n=e(i[r])))return n;return null}function df(t){return function(e,n,r){lf(n,function(n){r&&!r.intersects(n.bounds)||hf(t,e,n,n)})}}function hf(t,e,n,r){var i=null==n.opacity?1:n.opacity;0!==i&&(t(e,r)||(tf(e,n),n.fill&&af(e,n,i)&&e.fill(),n.stroke&&sf(e,n,i)&&e.stroke()))}function pf(t){return t=t||ct.Ga,function(e,n,r,i,a,o){return r*=e.pixelRatio,i*=e.pixelRatio,ff(n,function(n){var s=n.bounds;if((!s||s.contains(a,o))&&s)return t(e,n,r,i,a,o)?n:void 0})}}function mf(t,e){return function(n,r,i,a){var o,s,u=Array.isArray(r)?r[0]:r,c=null==e?u.fill:e,l=u.stroke&&n.isPointInStroke;return l&&(o=u.strokeWidth,s=u.strokeCap,n.lineWidth=null!=o?o:1,n.lineCap=null!=s?s:"butt"),!t(n,r)&&(c&&n.isPointInPath(i,a)||l&&n.isPointInStroke(i,a))}}function gf(t){return pf(mf(t))}function vf(t,e){return"translate("+t+","+e+")"}function yf(t){return"rotate("+t+")"}function bf(t){return vf(t.x||0,t.y||0)}function xf(t){return vf(t.x||0,t.y||0)+(t.angle?" "+yf(t.angle):"")+(t.scaleX||t.scaleY?" "+function(t,e){return"scale("+t+","+e+")"}(t.scaleX||1,t.scaleY||1):"")}var wf=function(t,e,n){function r(t,n){var r=n.x||0,i=n.y||0,a=n.angle||0;t.translate(r,i),a&&t.rotate(a*=Tc),t.beginPath(),e(t,n),a&&t.rotate(-a),t.translate(-r,-i)}return{type:t,tag:"path",nested:!1,attr:function(t,n){t("transform",xf(n)),t("d",e(null,n))},bound:function(t,n){var r=n.x||0,i=n.y||0;return e(Ll(t),n),Ml(t,n).translate(r,i),n.angle&&t.rotate(n.angle*Tc,r,i),t},draw:df(r),pick:gf(r),isect:n||Xl(r)}},kf=wf("arc",function(t,e){return El.context(t)(e)});var _f=function(t,e,n){function r(t,n){t.beginPath(),e(t,n)}var i=mf(r);return{type:t,tag:"path",nested:!0,attr:function(t,n){var r=n.mark.items;r.length&&t("d",e(null,r))},bound:function(t,n){var r=n.items;return 0===r.length?t:(e(Ll(t),r),Ml(t,r[0]))},draw:function(t){return function(e,n,r){!n.items.length||r&&!r.intersects(n.bounds)||hf(t,e,n.items[0],n.items)}}(r),pick:function(t,e,n,r,a,o){var s=e.items,u=e.bounds;return!s||!s.length||u&&!u.contains(a,o)?null:(n*=t.pixelRatio,r*=t.pixelRatio,i(t,s,n,r)?s[0]:null)},isect:Yl,tip:n}},Ef=_f("area",function(t,e){var n=e[0],r=n.interpolate||"linear";return("horizontal"===n.orient?Sl:Ol).curve(Sc(r,n.orient,n.tension)).context(t)(e)},function(t,e){for(var n,r,i="horizontal"===t[0].orient?e[1]:e[0],a="horizontal"===t[0].orient?"y":"x",o=t.length,s=1/0;--o>=0;)!1!==t[o].defined&&(r=Math.abs(t[o][a]-i))<s&&(s=r,n=t[o]);return n});function Of(t,e){t.beginPath(),Il(e)?Dl(t,e,0,0):t.rect(0,0,e.width||0,e.height||0),t.clip()}var Sf=1;function Cf(){Sf=1}var Af=function(t,e,n){var r=e.clip,i=t._defs,a=e.clip_id||(e.clip_id="clip"+Sf++),o=i.clipping[a]||(i.clipping[a]={id:a});return Object(ct.D)(r)?o.path=r(null):Il(n)?o.path=Dl(null,n,0,0):(o.width=n.width||0,o.height=n.height||0),"url(#"+a+")"};function Nf(t){var e=null!=(e=t.strokeWidth)?e:1;return null!=t.strokeOffset?t.strokeOffset:t.stroke&&e>.5&&e<1.5?.5-Math.abs(e-1):0}function Tf(t,e){var n=Nf(e);t("d",Dl(null,e,n,n))}function If(t,e,n,r){var i=Nf(e);t.beginPath(),Dl(t,e,(n||0)+i,(r||0)+i)}var Df=mf(If),Mf=mf(If,!1);var Rf={type:"group",tag:"g",nested:!1,attr:function(t,e){t("transform",bf(e))},bound:function(t,e){if(!e.clip&&e.items)for(var n=e.items,r=0,i=n.length;r<i;++r)t.union(n[r].bounds);return(e.clip||e.width||e.height)&&!e.noBound&&t.add(0,0).add(e.width||0,e.height||0),Ml(t,e),t.translate(e.x||0,e.y||0)},draw:function(t,e,n){var r=this;lf(e,function(e){var i=e.x||0,a=e.y||0,o=e.strokeForeground,s=null==e.opacity?1:e.opacity;(e.stroke||e.fill)&&s&&(If(t,e,i,a),tf(t,e),e.fill&&af(t,e,s)&&t.fill(),e.stroke&&!o&&sf(t,e,s)&&t.stroke()),t.save(),t.translate(i,a),e.clip&&Of(t,e),n&&n.translate(-i,-a),lf(e,function(e){r.draw(t,e,n)}),n&&n.translate(i,a),t.restore(),o&&e.stroke&&s&&(If(t,e,i,a),tf(t,e),sf(t,e,s)&&t.stroke())})},pick:function(t,e,n,r,i,a){if(e.bounds&&!e.bounds.contains(i,a)||!e.items)return null;var o=this,s=n*t.pixelRatio,u=r*t.pixelRatio;return ff(e,function(c){var l,f,d,h,p,m,g,v,y;if((!(v=c.bounds)||v.contains(i,a))&&(h=c.x||0,p=c.y||0,m=h+(c.width||0),g=p+(c.height||0),!(y=c.clip)||!(i<h||i>m||a<h||a>g)))return t.save(),t.translate(h,p),h=i-h,p=a-p,y&&Il(c)&&!Df(t,c,s,u)?(t.restore(),null):(f=c.strokeForeground,(d=!1!==e.interactive)&&f&&c.stroke&&Mf(t,c,s,u)?(t.restore(),c):(!(l=ff(c,function(t){return function(t,e,n){return(!1!==t.interactive||"group"===t.marktype)&&t.bounds&&t.bounds.contains(e,n)}(t,h,p)?o.pick(t,n,r,h,p):null}))&&d&&(c.fill||!f&&c.stroke)&&Df(t,c,s,u)&&(l=c),t.restore(),l||null))})},isect:Jl,content:function(t,e,n){t("clip-path",e.clip?Af(n,e,e):null)},background:function(t,e){t("class","background"),Tf(t,e)},foreground:function(t,e){t("class","foreground"),e.strokeForeground?Tf(t,e):t("d","")}};function Ff(t,e){var n=t.image;return(!n||t.url&&t.url!==n.url)&&(n={complete:!1,width:0,height:0},e.loadImage(t.url).then(e=>{t.image=e,t.image.url=t.url})),n}function jf(t,e){return null!=t.width?t.width:e&&e.width?!1!==t.aspect&&t.height?t.height*e.width/e.height:e.width:0}function Pf(t,e){return null!=t.height?t.height:e&&e.height?!1!==t.aspect&&t.width?t.width*e.height/e.width:e.height:0}function Lf(t,e){return"center"===t?e/2:"right"===t?e:0}function zf(t,e){return"middle"===t?e/2:"bottom"===t?e:0}var Bf={type:"image",tag:"image",nested:!1,attr:function(t,e,n){var r=Ff(e,n),i=e.x||0,a=e.y||0,o=jf(e,r),s=Pf(e,r),u=!1===e.aspect?"none":"xMidYMid";i-=Lf(e.align,o),a-=zf(e.baseline,s),!r.src&&r.toDataURL?t("href",r.toDataURL(),"http://www.w3.org/1999/xlink","xlink:href"):t("href",r.src||"","http://www.w3.org/1999/xlink","xlink:href"),t("transform",vf(i,a)),t("width",o),t("height",s),t("preserveAspectRatio",u)},bound:function(t,e){var n=e.image,r=e.x||0,i=e.y||0,a=jf(e,n),o=Pf(e,n);return r-=Lf(e.align,a),i-=zf(e.baseline,o),t.set(r,i,r+a,i+o)},draw:function(t,e,n){var r=this;lf(e,function(e){if(!n||n.intersects(e.bounds)){var i,a,o,s,u=Ff(e,r),c=e.x||0,l=e.y||0,f=jf(e,u),d=Pf(e,u);c-=Lf(e.align,f),l-=zf(e.baseline,d),!1!==e.aspect&&(a=u.width/u.height,o=e.width/e.height,a==a&&o==o&&a!==o&&(o<a?(l+=(d-(s=f/a))/2,d=s):(c+=(f-(s=d*a))/2,f=s))),(u.complete||u.toDataURL)&&(tf(t,e),t.globalAlpha=null!=(i=e.opacity)?i:1,t.imageSmoothingEnabled=!1!==e.smooth,t.drawImage(u,c,l,f,d))}})},pick:pf(),isect:ct.Ga,get:Ff,xOffset:Lf,yOffset:zf},Uf=_f("line",function(t,e){var n=e[0],r=n.interpolate||"linear";return Cl.curve(Sc(r,n.orient,n.tension)).context(t)(e)},function(t,e){for(var n,r,i=Math.pow(t[0].strokeWidth||1,2),a=t.length;--a>=0;)if(!1!==t[a].defined&&(n=t[a].x-e[0])*n+(r=t[a].y-e[1])*r<i)return t[a];return null});function Wf(t,e){var n=e.path;if(null==n)return!0;var r=e.x||0,i=e.y||0,a=e.scaleX||1,o=e.scaleY||1,s=(e.angle||0)*Tc,u=e.pathCache;u&&u.path===n||((e.pathCache=u=Nc(n)).path=n),s&&t.rotate&&t.translate?(t.translate(r,i),t.rotate(s),Uc(t,u,0,0,a,o),t.rotate(-s),t.translate(-r,-i)):Uc(t,u,r,i,a,o)}var Vf={type:"path",tag:"path",nested:!1,attr:function(t,e){var n=e.scaleX||1,r=e.scaleY||1;1===n&&1===r||t("vector-effect","non-scaling-stroke"),t("transform",xf(e)),t("d",e.path)},bound:function(t,e){return Wf(Ll(t),e)?t.set(0,0,0,0):Ml(t,e,!0),e.angle&&t.rotate(e.angle*Tc,e.x||0,e.y||0),t},draw:df(Wf),pick:gf(Wf),isect:Xl(Wf)};function qf(t,e){t.beginPath(),Dl(t,e)}var Hf={type:"rect",tag:"path",nested:!1,attr:function(t,e){t("d",Dl(null,e))},bound:function(t,e){var n,r;return Ml(t.set(n=e.x||0,r=e.y||0,n+e.width||0,r+e.height||0),e)},draw:df(qf),pick:gf(qf),isect:Jl};function Gf(t,e,n){var r,i,a,o;return!(!e.stroke||!sf(t,e,n))&&(r=e.x||0,i=e.y||0,a=null!=e.x2?e.x2:r,o=null!=e.y2?e.y2:i,t.beginPath(),t.moveTo(r,i),t.lineTo(a,o),!0)}var $f={type:"rule",tag:"line",nested:!1,attr:function(t,e){t("transform",bf(e)),t("x2",null!=e.x2?e.x2-(e.x||0):0),t("y2",null!=e.y2?e.y2-(e.y||0):0)},bound:function(t,e){var n,r;return Ml(t.set(n=e.x||0,r=e.y||0,null!=e.x2?e.x2:n,null!=e.y2?e.y2:r),e)},draw:function(t,e,n){lf(e,function(e){if(!n||n.intersects(e.bounds)){var r=null==e.opacity?1:e.opacity;r&&Gf(t,e,r)&&(tf(t,e),t.stroke())}})},pick:pf(function(t,e,n,r){return!!t.isPointInStroke&&Gf(t,e,1)&&t.isPointInStroke(n,r)}),isect:Zl},Kf=wf("shape",function(t,e){return(e.mark.shape||e.shape).context(t)(e)}),Xf=wf("symbol",function(t,e){return Nl.context(t)(e)},Yl);const Yf=Object(ct.L)();var Jf={height:rd,measureWidth:ed,estimateWidth:Qf,width:Qf,canvas:Zf};function Zf(t){Jf.width=t&&$l?ed:Qf}function Qf(t,e){return td(sd(t,e),rd(t))}function td(t,e){return~~(.8*t.length*e)}function ed(t,e){return rd(t)<=0||!(e=sd(t,e))?0:nd(e,cd(t))}function nd(t,e){const n=`(${e}) ${t}`;let r=Yf.get(n);return void 0===r&&($l.font=e,r=$l.measureText(t).width,Yf.set(n,r)),r}function rd(t){return null!=t.fontSize?+t.fontSize||0:11}function id(t){return null!=t.lineHeight?t.lineHeight:rd(t)+2}function ad(t){return function(t){return Object(ct.A)(t)?t.length>1?t:t[0]:t}(t.lineBreak&&t.text&&!Object(ct.A)(t.text)?t.text.split(t.lineBreak):t.text)}function od(t){const e=ad(t);return(Object(ct.A)(e)?e.length-1:0)*id(t)}function sd(t,e){const n=null==e?"":(e+"").trim();return t.limit>0&&n.length?function(t,e){var n=+t.limit,r=function(t){if(Jf.width===ed){const e=cd(t);return t=>nd(t,e)}{const e=rd(t);return t=>td(t,e)}}(t);if(r(e)<n)return e;var i,a=t.ellipsis||"…",o="rtl"===t.dir,s=0,u=e.length;if(n-=r(a),o){for(;s<u;)i=s+u>>>1,r(e.slice(i))>n?s=i+1:u=i;return a+e.slice(s)}for(;s<u;)i=1+(s+u>>>1),r(e.slice(0,i))<n?s=i:u=i-1;return e.slice(0,s)+a}(t,n):n}function ud(t,e){var n=t.font;return(e&&n?String(n).replace(/"/g,"'"):n)||"sans-serif"}function cd(t,e){return(t.fontStyle?t.fontStyle+" ":"")+(t.fontVariant?t.fontVariant+" ":"")+(t.fontWeight?t.fontWeight+" ":"")+rd(t)+"px "+ud(t,e)}function ld(t){var e=t.baseline,n=rd(t);return Math.round("top"===e?.79*n:"middle"===e?.3*n:"bottom"===e?-.21*n:"line-top"===e?.29*n+.5*id(t):"line-bottom"===e?.29*n-.5*id(t):0)}Zf(!0);var fd={left:"start",center:"middle",right:"end"},dd=new yu;function hd(t){var e,n=t.x||0,r=t.y||0,i=t.radius||0;return i&&(e=(t.theta||0)-Dc,n+=i*Math.cos(e),r+=i*Math.sin(e)),dd.x1=n,dd.y1=r,dd}function pd(t,e,n){var r,i=Jf.height(e),a=e.align,o=hd(e),s=o.x1,u=o.y1,c=e.dx||0,l=(e.dy||0)+ld(e)-Math.round(.8*i),f=ad(e);if(Object(ct.A)(f)?(i+=id(e)*(f.length-1),r=f.reduce((t,n)=>Math.max(t,Jf.width(e,n)),0)):r=Jf.width(e,f),"center"===a?c-=r/2:"right"===a&&(c-=r),t.set(c+=s,l+=u,c+r,l+i),e.angle&&!n)t.rotate(e.angle*Tc,s,u);else if(2===n)return t.rotatedPoints(e.angle*Tc,s,u);return t}var md={arc:kf,area:Ef,group:Rf,image:Bf,line:Uf,path:Vf,rect:Hf,rule:$f,shape:Kf,symbol:Xf,text:{type:"text",tag:"text",nested:!1,attr:function(t,e){var n,r=e.dx||0,i=(e.dy||0)+ld(e),a=hd(e),o=a.x1,s=a.y1,u=e.angle||0;t("text-anchor",fd[e.align]||"start"),u?(n=vf(o,s)+" "+yf(u),(r||i)&&(n+=" "+vf(r,i))):n=vf(o+r,s+i),t("transform",n)},bound:pd,draw:function(t,e,n){lf(e,function(e){var r,i,a,o,s,u,c,l=null==e.opacity?1:e.opacity;if(!(n&&!n.intersects(e.bounds)||0===l||e.fontSize<=0||null==e.text||0===e.text.length)){if(t.font=cd(e),t.textAlign=e.align||"left",i=(r=hd(e)).x1,a=r.y1,e.angle&&(t.save(),t.translate(i,a),t.rotate(e.angle*Tc),i=a=0),i+=e.dx||0,a+=(e.dy||0)+ld(e),u=ad(e),tf(t,e),Object(ct.A)(u))for(s=id(e),o=0;o<u.length;++o)c=sd(e,u[o]),e.fill&&af(t,e,l)&&t.fillText(c,i,a),e.stroke&&sf(t,e,l)&&t.strokeText(c,i,a),a+=s;else c=sd(e,u),e.fill&&af(t,e,l)&&t.fillText(c,i,a),e.stroke&&sf(t,e,l)&&t.strokeText(c,i,a);e.angle&&t.restore()}})},pick:pf(function(t,e,n,r,i,a){if(e.fontSize<=0)return!1;if(!e.angle)return!0;var o=hd(e),s=o.x1,u=o.y1,c=pd(dd,e,1),l=-e.angle*Tc,f=Math.cos(l),d=Math.sin(l),h=f*i-d*a+(s-f*s+d*u),p=d*i+f*a+(u-d*s-f*u);return c.contains(h,p)}),isect:function(t,e){var n=pd(dd,t,2);return Ql(e,n[0],n[1],n[2],n[3])||Ql(e,n[0],n[1],n[4],n[5])||Ql(e,n[4],n[5],n[6],n[7])||Ql(e,n[2],n[3],n[6],n[7])}},trail:_f("trail",function(t,e){return Tl.context(t)(e)},function(t,e){for(var n,r,i=t.length;--i>=0;)if(!1!==t[i].defined&&(n=t[i].x-e[0])*n+(r=t[i].y-e[1])*r<(n=t[i].size||1)*n)return t[i];return null})},gd=function(t,e,n){var r=md[t.mark.marktype],i=e||r.bound;return r.nested&&(t=t.mark),i(t.bounds||(t.bounds=new yu),t,n)},vd={mark:null},yd=function(t,e,n){var r,i,a,o,s=md[t.marktype],u=s.bound,c=t.items,l=c&&c.length;if(s.nested)return l?a=c[0]:(vd.mark=t,a=vd),o=gd(a,u,n),e=e&&e.union(o)||o;if(e=e||t.bounds&&t.bounds.clear()||new yu,l)for(r=0,i=c.length;r<i;++r)e.union(gd(c[r],u,n));return t.bounds=e},bd=["marktype","name","role","interactive","clip","items","zindex","x","y","width","height","align","baseline","fill","fillOpacity","opacity","blend","stroke","strokeOpacity","strokeWidth","strokeCap","strokeDash","strokeDashOffset","strokeForeground","strokeOffset","startAngle","endAngle","innerRadius","outerRadius","cornerRadius","padAngle","cornerRadiusTopLeft","cornerRadiusTopRight","cornerRadiusBottomLeft","cornerRadiusBottomRight","interpolate","tension","orient","defined","url","aspect","smooth","path","scaleX","scaleY","x2","y2","size","shape","text","angle","theta","radius","dir","dx","dy","ellipsis","limit","lineBreak","lineHeight","font","fontSize","fontWeight","fontStyle","fontVariant"];function xd(t,e){return JSON.stringify(t,bd,e)}function wd(t){return function t(e){var n,r,i,a=e.marktype,o=e.items;if(o)for(r=0,i=o.length;r<i;++r)n=a?"mark":"group",o[r][n]=e,o[r].zindex&&(o[r][n].zdirty=!0),"group"===(a||n)&&t(o[r]);a&&yd(e);return e}("string"==typeof t?JSON.parse(t):t)}function kd(t){arguments.length?this.root=wd(t):(this.root=Ed({marktype:"group",name:"root",role:"frame"}),this.root.items=[new Cu(this.root)])}var _d=kd.prototype;function Ed(t,e){return{bounds:new yu,clip:!!t.clip,group:e,interactive:!1!==t.interactive,items:[],marktype:t.marktype,name:t.name||void 0,role:t.role||void 0,zindex:t.zindex||0}}function Od(t,e,n){return!t&&"undefined"!=typeof document&&document.createElement&&(t=document),t?n?t.createElementNS(n,e):t.createElement(e):null}function Sd(t,e){e=e.toLowerCase();for(var n=t.childNodes,r=0,i=n.length;r<i;++r)if(n[r].tagName.toLowerCase()===e)return n[r]}function Cd(t,e,n,r){var i,a=t.childNodes[e];return a&&a.tagName.toLowerCase()===n.toLowerCase()||(i=a||null,a=Od(t.ownerDocument,n,r),t.insertBefore(a,i)),a}function Ad(t,e){for(var n=t.childNodes,r=n.length;r>e;)t.removeChild(n[--r]);return t}function Nd(t){return"mark-"+t.marktype+(t.role?" role-"+t.role:"")+(t.name?" "+t.name:"")}_d.toJSON=function(t){return xd(this.root,t||0)},_d.mark=function(t,e,n){var r=Ed(t,e=e||this.root.items[0]);return e.items[n]=r,r.zindex&&(r.group.zdirty=!0),r};var Td=function(t,e){var n=e.getBoundingClientRect();return[t.clientX-n.left-(e.clientLeft||0),t.clientY-n.top-(e.clientTop||0)]};function Id(t,e){this._active=null,this._handlers={},this._loader=t||xr(),this._tooltip=e||Dd}function Dd(t,e,n,r){t.element().setAttribute("title",r||"")}var Md=Id.prototype;function Rd(t){this._el=null,this._bgcolor=null,this._loader=new Tu(t)}Md.initialize=function(t,e,n){return this._el=t,this._obj=n||null,this.origin(e)},Md.element=function(){return this._el},Md.canvas=function(){return this._el&&this._el.firstChild},Md.origin=function(t){return arguments.length?(this._origin=t||[0,0],this):this._origin.slice()},Md.scene=function(t){return arguments.length?(this._scene=t,this):this._scene},Md.on=function(){},Md.off=function(){},Md._handlerIndex=function(t,e,n){for(var r=t?t.length:0;--r>=0;)if(t[r].type===e&&(!n||t[r].handler===n))return r;return-1},Md.handlers=function(t){var e,n=this._handlers,r=[];if(t)r.push.apply(r,n[this.eventName(t)]);else for(e in n)r.push.apply(r,n[e]);return r},Md.eventName=function(t){var e=t.indexOf(".");return e<0?t:t.slice(0,e)},Md.handleHref=function(t,e,n){this._loader.sanitize(n,{context:"href"}).then(function(e){var n=new MouseEvent(t.type,t),r=Od(null,"a");for(var i in e)r.setAttribute(i,e[i]);r.dispatchEvent(n)}).catch(function(){})},Md.handleTooltip=function(t,e,n){if(e&&null!=e.tooltip){e=function(t,e,n,r){var i,a,o=t&&t.mark;if(o&&(i=md[o.marktype]).tip){for((a=Td(e,n))[0]-=r[0],a[1]-=r[1];t=t.mark.group;)a[0]-=t.x||0,a[1]-=t.y||0;t=i.tip(o.items,a)}return t}(e,t,this.canvas(),this._origin);var r=n&&e&&e.tooltip||null;this._tooltip.call(this._obj,this,t,e,r)}},Md.getItemBoundingClientRect=function(t){if(e=this.canvas()){for(var e,n=e.getBoundingClientRect(),r=this._origin,i=t.bounds,a=i.x1+r[0]+n.left,o=i.y1+r[1]+n.top,s=i.width(),u=i.height();t.mark&&(t=t.mark.group);)a+=t.x||0,o+=t.y||0;return{x:a,y:o,width:s,height:u,left:a,top:o,right:a+s,bottom:o+u}}};var Fd=Rd.prototype;Fd.initialize=function(t,e,n,r,i){return this._el=t,this.resize(e,n,r,i)},Fd.element=function(){return this._el},Fd.canvas=function(){return this._el&&this._el.firstChild},Fd.background=function(t){return 0===arguments.length?this._bgcolor:(this._bgcolor=t,this)},Fd.resize=function(t,e,n,r){return this._width=t,this._height=e,this._origin=n||[0,0],this._scale=r||1,this},Fd.dirty=function(){},Fd.render=function(t){var e=this;return e._call=function(){e._render(t)},e._call(),e._call=null,e},Fd._render=function(){},Fd.renderAsync=function(t){var e=this.render(t);return this._ready?this._ready.then(function(){return e}):Promise.resolve(e)},Fd._load=function(t,e){var n=this,r=n._loader[t](e);if(!n._ready){var i=n._call;n._ready=n._loader.ready().then(function(t){t&&i(),n._ready=null})}return r},Fd.sanitizeURL=function(t){return this._load("sanitizeURL",t)},Fd.loadImage=function(t){return this._load("loadImage",t)};var jd="mouseout";function Pd(t,e){Id.call(this,t,e),this._down=null,this._touch=null,this._first=!0}var Ld=Object(ct.y)(Pd,Id);function zd(t,e,n){return function(r){var i=this._active,a=this.pickEvent(r);a===i?this.fire(t,r):(i&&i.exit||this.fire(n,r),this._active=a,this.fire(e,r),this.fire(t,r))}}function Bd(t){return function(e){this.fire(t,e),this._active=null}}Ld.initialize=function(t,e,n){var r=this._canvas=t&&Sd(t,"canvas");if(r){var i=this;this.events.forEach(function(t){r.addEventListener(t,function(e){Ld[t]?Ld[t].call(i,e):i.fire(t,e)})})}return Id.prototype.initialize.call(this,t,e,n)},Ld.canvas=function(){return this._canvas},Ld.context=function(){return this._canvas.getContext("2d")},Ld.events=["keydown","keypress","keyup","dragenter","dragleave","dragover","mousedown","mouseup","mousemove","mouseout","mouseover","click","dblclick","wheel","mousewheel","touchstart","touchmove","touchend"],Ld.DOMMouseScroll=function(t){this.fire("mousewheel",t)},Ld.mousemove=zd("mousemove","mouseover","mouseout"),Ld.dragover=zd("dragover","dragenter","dragleave"),Ld.mouseout=Bd("mouseout"),Ld.dragleave=Bd("dragleave"),Ld.mousedown=function(t){this._down=this._active,this.fire("mousedown",t)},Ld.click=function(t){this._down===this._active&&(this.fire("click",t),this._down=null)},Ld.touchstart=function(t){this._touch=this.pickEvent(t.changedTouches[0]),this._first&&(this._active=this._touch,this._first=!1),this.fire("touchstart",t,!0)},Ld.touchmove=function(t){this.fire("touchmove",t,!0)},Ld.touchend=function(t){this.fire("touchend",t,!0),this._touch=null},Ld.fire=function(t,e,n){var r,i,a=n?this._touch:this._active,o=this._handlers[t];if(e.vegaType=t,"click"===t&&a&&a.href?this.handleHref(e,a,a.href):"mousemove"!==t&&t!==jd||this.handleTooltip(e,a,t!==jd),o)for(r=0,i=o.length;r<i;++r)o[r].handler.call(this._obj,e,a)},Ld.on=function(t,e){var n=this.eventName(t),r=this._handlers;return this._handlerIndex(r[n],t,e)<0&&(r[n]||(r[n]=[])).push({type:t,handler:e}),this},Ld.off=function(t,e){var n=this.eventName(t),r=this._handlers[n],i=this._handlerIndex(r,t,e);return i>=0&&r.splice(i,1),this},Ld.pickEvent=function(t){var e=Td(t,this._canvas),n=this._origin;return this.pick(this._scene,e[0],e[1],e[0]-n[0],e[1]-n[1])},Ld.pick=function(t,e,n,r,i){var a=this.context();return md[t.marktype].pick.call(this,a,t,e,n,r,i)};var Ud="undefined"!=typeof window&&window.devicePixelRatio||1;function Wd(t){Rd.call(this,t),this._redraw=!1,this._dirty=new yu}var Vd=Object(ct.y)(Wd,Rd),qd=Rd.prototype,Hd=new yu;function Gd(t,e,n){return Hd.set(0,0,e,n).translate(-t[0],-t[1])}function $d(t,e){Id.call(this,t,e);var n=this;n._hrefHandler=Xd(n,function(t,e){e&&e.href&&n.handleHref(t,e,e.href)}),n._tooltipHandler=Xd(n,function(t,e){n.handleTooltip(t,e,t.type!==jd)})}Vd.initialize=function(t,e,n,r,i,a){return this._options=a,this._canvas=Au(1,1,a&&a.type),t&&(Ad(t,0).appendChild(this._canvas),this._canvas.setAttribute("class","marks")),qd.initialize.call(this,t,e,n,r,i)},Vd.resize=function(t,e,n,r){return qd.resize.call(this,t,e,n,r),function(t,e,n,r,i,a){const o="undefined"!=typeof HTMLElement&&t instanceof HTMLElement&&null!=t.parentNode,s=t.getContext("2d"),u=o?Ud:i;t.width=e*u,t.height=n*u;for(const t in a)s[t]=a[t];o&&1!==u&&(t.style.width=e+"px",t.style.height=n+"px"),s.pixelRatio=u,s.setTransform(u,0,0,u,u*r[0],u*r[1])}(this._canvas,this._width,this._height,this._origin,this._scale,this._options&&this._options.context),this._redraw=!0,this},Vd.canvas=function(){return this._canvas},Vd.context=function(){return this._canvas?this._canvas.getContext("2d"):null},Vd.dirty=function(t){var e=function(t,e){if(null==e)return t;for(var n=Hd.clear().union(t);null!=e;e=e.mark.group)n.translate(e.x||0,e.y||0);return n}(t.bounds,t.mark.group);this._dirty.union(e)},Vd._render=function(t){var e=this.context(),n=this._origin,r=this._width,i=this._height,a=this._dirty;return e.save(),this._redraw||a.empty()?(this._redraw=!1,a=Gd(n,r,i).expand(1)):a=function(t,e,n){return e.expand(1).round(),t.pixelRatio%1&&e.scale(t.pixelRatio).round().scale(1/t.pixelRatio),e.translate(-n[0]%1,-n[1]%1),t.beginPath(),t.rect(e.x1,e.y1,e.width(),e.height()),t.clip(),e}(e,a.intersect(Gd(n,r,i)),n),this.clear(-n[0],-n[1],r,i),this.draw(e,t,a),e.restore(),this._dirty.clear(),this},Vd.draw=function(t,e,n){var r=md[e.marktype];e.clip&&function(t,e){var n=e.clip;t.save(),Object(ct.D)(n)?(t.beginPath(),n(t),t.clip()):Of(t,e.group)}(t,e),r.draw.call(this,t,e,n),e.clip&&t.restore()},Vd.clear=function(t,e,n,r){var i=this.context();i.clearRect(t,e,n,r),null!=this._bgcolor&&(i.fillStyle=this._bgcolor,i.fillRect(t,e,n,r))};var Kd=Object(ct.y)($d,Id);function Xd(t,e){return function(n){var r=n.target.__data__;n.vegaType=n.type,r=Array.isArray(r)?r[0]:r,e.call(t._obj,n,r)}}function Yd(t,e,n){var r,i,a="<"+t;if(e)for(r in e)null!=(i=e[r])&&(a+=" "+r+'="'+i+'"');return n&&(a+=" "+n),a+">"}function Jd(t){return"</"+t+">"}Kd.initialize=function(t,e,n){var r=this._svg;return r&&(r.removeEventListener("click",this._hrefHandler),r.removeEventListener("mousemove",this._tooltipHandler),r.removeEventListener(jd,this._tooltipHandler)),this._svg=r=t&&Sd(t,"svg"),r&&(r.addEventListener("click",this._hrefHandler),r.addEventListener("mousemove",this._tooltipHandler),r.addEventListener(jd,this._tooltipHandler)),Id.prototype.initialize.call(this,t,e,n)},Kd.canvas=function(){return this._svg},Kd.on=function(t,e){var n=this.eventName(t),r=this._handlers;if(this._handlerIndex(r[n],t,e)<0){var i={type:t,handler:e,listener:Xd(this,e)};(r[n]||(r[n]=[])).push(i),this._svg&&this._svg.addEventListener(n,i.listener)}return this},Kd.off=function(t,e){var n=this.eventName(t),r=this._handlers[n],i=this._handlerIndex(r,t,e);return i>=0&&(this._svg&&this._svg.removeEventListener(n,r[i].listener),r.splice(i,1)),this};var Zd={version:"1.1",xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink"},Qd={fill:"fill",fillOpacity:"fill-opacity",stroke:"stroke",strokeOpacity:"stroke-opacity",strokeWidth:"stroke-width",strokeCap:"stroke-linecap",strokeJoin:"stroke-linejoin",strokeDash:"stroke-dasharray",strokeDashOffset:"stroke-dashoffset",strokeMiterLimit:"stroke-miterlimit",opacity:"opacity",blend:"mix-blend-mode"},th=Object.keys(Qd),eh=Zd.xmlns;function nh(t){Rd.call(this,t),this._dirtyID=0,this._dirty=[],this._svg=null,this._root=null,this._defs=null}var rh=Object(ct.y)(nh,Rd),ih=Rd.prototype;function ah(t,e,n){var r,i,a;if("radial"===e.gradient){var o=Cd(t,n++,"pattern",eh);o.setAttribute("id",wu+e.id),o.setAttribute("viewBox","0,0,1,1"),o.setAttribute("width","100%"),o.setAttribute("height","100%"),o.setAttribute("preserveAspectRatio","xMidYMid slice"),(o=Cd(o,0,"rect",eh)).setAttribute("width","1"),o.setAttribute("height","1"),o.setAttribute("fill","url("+ph()+"#"+e.id+")"),(t=Cd(t,n++,"radialGradient",eh)).setAttribute("id",e.id),t.setAttribute("fx",e.x1),t.setAttribute("fy",e.y1),t.setAttribute("fr",e.r1),t.setAttribute("cx",e.x2),t.setAttribute("cy",e.y2),t.setAttribute("r",e.r2)}else(t=Cd(t,n++,"linearGradient",eh)).setAttribute("id",e.id),t.setAttribute("x1",e.x1),t.setAttribute("x2",e.x2),t.setAttribute("y1",e.y1),t.setAttribute("y2",e.y2);for(r=0,i=e.stops.length;r<i;++r)(a=Cd(t,r,"stop",eh)).setAttribute("offset",e.stops[r].offset),a.setAttribute("stop-color",e.stops[r].color);return Ad(t,r),n}function oh(t,e,n){var r;return(t=Cd(t,n,"clipPath",eh)).setAttribute("id",e.id),e.path?(r=Cd(t,0,"path",eh)).setAttribute("d",e.path):((r=Cd(t,0,"rect",eh)).setAttribute("x",0),r.setAttribute("y",0),r.setAttribute("width",e.width),r.setAttribute("height",e.height)),Ad(t,1),n+1}function sh(t,e){for(;t&&t.dirty!==e;t=t.mark.group){if(t.dirty=e,!t.mark||t.mark.dirty===e)return;t.mark.dirty=e}}function uh(t,e,n,r,i){var a,o=t._svg;if(!o&&(o=Od(a=e.ownerDocument,r,eh),t._svg=o,t.mark&&(o.__data__=t,o.__values__={fill:"default"},"g"===r))){var s=Od(a,"path",eh);o.appendChild(s),s.__data__=t;var u=Od(a,"g",eh);o.appendChild(u),u.__data__=t;var c=Od(a,"path",eh);o.appendChild(c),c.__data__=t,c.__values__={fill:"default"}}return(o.ownerSVGElement!==i||function(t,e){return t.parentNode&&t.parentNode.childNodes.length>1&&t.previousSibling!=e}(o,n))&&e.insertBefore(o,n?n.nextSibling:e.firstChild),o}rh.initialize=function(t,e,n,r){return t&&(this._svg=Cd(t,0,"svg",eh),this._svg.setAttribute("class","marks"),Ad(t,1),this._root=Cd(this._svg,0,"g",eh),Ad(this._svg,1)),this._defs={gradient:{},clipping:{}},this.background(this._bgcolor),ih.initialize.call(this,t,e,n,r)},rh.background=function(t){return arguments.length&&this._svg&&this._svg.style.setProperty("background-color",t),ih.background.apply(this,arguments)},rh.resize=function(t,e,n,r){return ih.resize.call(this,t,e,n,r),this._svg&&(this._svg.setAttribute("width",this._width*this._scale),this._svg.setAttribute("height",this._height*this._scale),this._svg.setAttribute("viewBox","0 0 "+this._width+" "+this._height),this._root.setAttribute("transform","translate("+this._origin+")")),this._dirty=[],this},rh.canvas=function(){return this._svg},rh.svg=function(){if(!this._svg)return null;var t={class:"marks",width:this._width*this._scale,height:this._height*this._scale,viewBox:"0 0 "+this._width+" "+this._height};for(var e in Zd)t[e]=Zd[e];var n=this._bgcolor?Yd("rect",{width:this._width,height:this._height,style:"fill: "+this._bgcolor+";"})+Jd("rect"):"";return Yd("svg",t)+n+this._svg.innerHTML+Jd("svg")},rh._render=function(t){return this._dirtyCheck()&&(this._dirtyAll&&this._resetDefs(),this.draw(this._root,t),Ad(this._root,1)),this.updateDefs(),this._dirty=[],++this._dirtyID,this},rh.updateDefs=function(){var t,e=this._svg,n=this._defs,r=n.el,i=0;for(t in n.gradient)r||(n.el=r=Cd(e,0,"defs",eh)),i=ah(r,n.gradient[t],i);for(t in n.clipping)r||(n.el=r=Cd(e,0,"defs",eh)),i=oh(r,n.clipping[t],i);r&&(0===i?(e.removeChild(r),n.el=null):Ad(r,i))},rh._resetDefs=function(){var t=this._defs;t.gradient={},t.clipping={}},rh.dirty=function(t){t.dirty!==this._dirtyID&&(t.dirty=this._dirtyID,this._dirty.push(t))},rh.isDirty=function(t){return this._dirtyAll||!t._svg||t.dirty===this._dirtyID},rh._dirtyCheck=function(){this._dirtyAll=!0;var t=this._dirty;if(!t.length||!this._dirtyID)return!0;var e,n,r,i,a,o,s,u=++this._dirtyID;for(a=0,o=t.length;a<o;++a)(n=(e=t[a]).mark).marktype!==r&&(r=n.marktype,i=md[r]),n.zdirty&&n.dirty!==u&&(this._dirtyAll=!1,sh(e,u),n.items.forEach(function(t){t.dirty=u})),n.zdirty||(e.exit?(i.nested&&n.items.length?(s=n.items[0])._svg&&this._update(i,s._svg,s):e._svg&&(s=e._svg.parentNode)&&s.removeChild(e._svg),e._svg=null):(e=i.nested?n.items[0]:e)._update!==u&&(e._svg&&e._svg.ownerSVGElement?this._update(i,e._svg,e):(this._dirtyAll=!1,sh(e,u)),e._update=u));return!this._dirtyAll},rh.draw=function(t,e,n){if(!this.isDirty(e))return e._svg;var r,i=this,a=this._svg,o=md[e.marktype],s=!1===e.interactive?"none":null,u="g"===o.tag,c=null,l=0;function f(t){var e=i.isDirty(t),n=uh(t,r,c,o.tag,a);e&&(i._update(o,n,t),u&&function(t,e,n){e=e.lastChild.previousSibling;var r,i=0;lf(n,function(n){r=t.draw(e,n,r),++i}),Ad(e,1+i)}(i,n,t)),c=n,++l}return(r=uh(e,t,n,"g",a)).setAttribute("class",Nd(e)),u||r.style.setProperty("pointer-events",s),e.clip?r.setAttribute("clip-path",Af(i,e,e.group)):r.removeAttribute("clip-path"),o.nested?e.items.length&&f(e.items[0]):lf(e,f),Ad(r,l),r};var ch=null,lh=null,fh={group:function(t,e,n){var r,i;ch=r=e.childNodes[2],lh=r.__values__,t.foreground(hh,n,this),lh=e.__values__,ch=e.childNodes[1],t.content(hh,n,this),ch=i=e.childNodes[0],t.background(hh,n,this);var a=!1===n.mark.interactive?"none":null;if(a!==lh.events&&(r.style.setProperty("pointer-events",a),i.style.setProperty("pointer-events",a),lh.events=a),n.strokeForeground&&n.stroke){const t=n.fill;r.style.removeProperty("display"),this.style(i,n),i.style.removeProperty("stroke"),t&&(n.fill=null),lh=r.__values__,this.style(r,n),t&&(n.fill=t),ch=null}else r.style.setProperty("display","none"),r.style.setProperty("fill","none")},image:function(t,e,n){!1===n.smooth?(dh(e,"image-rendering","optimizeSpeed"),dh(e,"image-rendering","pixelated")):dh(e,"image-rendering",null)},text:function(t,e,n){var r,i,a,o,s=ad(n);Object(ct.A)(s)?(r=(i=s.map(t=>sd(n,t))).join("\n"))!==lh.text&&(Ad(e,0),a=e.ownerDocument,o=id(n),i.forEach((t,r)=>{const i=Od(a,"tspan",eh);i.__data__=n,i.textContent=t,r&&(i.setAttribute("x",0),i.setAttribute("dy",o)),e.appendChild(i)}),lh.text=r):(i=sd(n,s))!==lh.text&&(e.textContent=i,lh.text=i),dh(e,"font-family",ud(n)),dh(e,"font-size",rd(n)+"px"),dh(e,"font-style",n.fontStyle),dh(e,"font-variant",n.fontVariant),dh(e,"font-weight",n.fontWeight)}};function dh(t,e,n){n!==lh[e]&&(null==n?t.style.removeProperty(e):t.style.setProperty(e,n+""),lh[e]=n)}function hh(t,e,n){e!==lh[t]&&(null!=e?n?ch.setAttributeNS(n,t,e):ch.setAttribute(t,e):n?ch.removeAttributeNS(n,t):ch.removeAttribute(t),lh[t]=e)}function ph(){var t;return"undefined"==typeof window?"":(t=window.location).hash?t.href.slice(0,-t.hash.length):t.href}function mh(t){Rd.call(this,t),this._text={head:"",bg:"",root:"",foot:"",defs:"",body:""},this._defs={gradient:{},clipping:{}}}rh._update=function(t,e,n){ch=e,lh=e.__values__,t.attr(hh,n,this);var r=fh[t.type];r&&r.call(this,t,e,n),ch&&this.style(ch,n)},rh.style=function(t,e){var n,r,i,a,o;if(null!=e)for(n=0,r=th.length;n<r;++n)o=e[i=th[n]],"font"===i&&(o=ud(e)),o!==lh[i]&&(a=Qd[i],null==o?"fill"===a?t.style.setProperty(a,"none"):t.style.removeProperty(a):(ku(o)&&(o=_u(o,this._defs.gradient,ph())),t.style.setProperty(a,o+"")),lh[i]=o)};var gh,vh=Object(ct.y)(mh,Rd),yh=Rd.prototype;function bh(t,e,n,r){gh[r||t]=e}function xh(t,e,n,r){if(null==t)return"";var i,a,o,s,u,c="";for("bgrect"===n&&!1===e.interactive&&(c+="pointer-events: none; "),"bgfore"===n&&(!1===e.interactive&&(c+="pointer-events: none; "),c+="display: none; "),"image"===n&&!1===t.smooth&&(c+="image-rendering: optimizeSpeed; image-rendering: pixelated; "),"text"===n&&(c+="font-family: "+ud(t)+"; ",c+="font-size: "+rd(t)+"px; ",t.fontStyle&&(c+="font-style: "+t.fontStyle+"; "),t.fontVariant&&(c+="font-variant: "+t.fontVariant+"; "),t.fontWeight&&(c+="font-weight: "+t.fontWeight+"; ")),i=0,a=th.length;i<a;++i)o=th[i],s=Qd[o],null==(u=t[o])?"fill"===s&&(c+="fill: none; "):"transparent"!==u||"fill"!==s&&"stroke"!==s?(ku(u)&&(u=_u(u,r.gradient,"")),c+=s+": "+u+"; "):c+=s+": none; ";return c?'style="'+c.trim()+'"':null}function wh(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}vh.resize=function(t,e,n,r){yh.resize.call(this,t,e,n,r);var i=this._origin,a=this._text,o={class:"marks",width:this._width*this._scale,height:this._height*this._scale,viewBox:"0 0 "+this._width+" "+this._height};for(var s in Zd)o[s]=Zd[s];a.head=Yd("svg",o);var u=this._bgcolor;return"transparent"!==u&&"none"!==u||(u=null),a.bg=u?Yd("rect",{width:this._width,height:this._height,style:"fill: "+u+";"})+Jd("rect"):"",a.root=Yd("g",{transform:"translate("+i+")"}),a.foot=Jd("g")+Jd("svg"),this},vh.background=function(){var t=yh.background.apply(this,arguments);return arguments.length&&this._text.head&&this.resize(this._width,this._height,this._origin,this._scale),t},vh.svg=function(){var t=this._text;return t.head+t.bg+t.defs+t.root+t.body+t.foot},vh._render=function(t){return this._text.body=this.mark(t),this._text.defs=this.buildDefs(),this},vh.buildDefs=function(){var t,e,n,r,i,a=this._defs,o="";for(e in a.gradient){for(i=(n=a.gradient[e]).stops,"radial"===n.gradient?(o+=Yd(r="pattern",{id:wu+e,viewBox:"0,0,1,1",width:"100%",height:"100%",preserveAspectRatio:"xMidYMid slice"}),o+=Yd("rect",{width:"1",height:"1",fill:"url(#"+e+")"})+Jd("rect"),o+=Jd(r),o+=Yd(r="radialGradient",{id:e,fx:n.x1,fy:n.y1,fr:n.r1,cx:n.x2,cy:n.y2,r:n.r2})):o+=Yd(r="linearGradient",{id:e,x1:n.x1,x2:n.x2,y1:n.y1,y2:n.y2}),t=0;t<i.length;++t)o+=Yd("stop",{offset:i[t].offset,"stop-color":i[t].color})+Jd("stop");o+=Jd(r)}for(e in a.clipping)n=a.clipping[e],o+=Yd("clipPath",{id:e}),n.path?o+=Yd("path",{d:n.path})+Jd("path"):o+=Yd("rect",{x:0,y:0,width:n.width,height:n.height})+Jd("rect"),o+=Jd("clipPath");return o.length>0?Yd("defs")+o+Jd("defs"):""},vh.attributes=function(t,e){return gh={},t(bh,e,this),gh},vh.href=function(t){var e,n=this,r=t.href;if(r){if(e=n._hrefs&&n._hrefs[r])return e;n.sanitizeURL(r).then(function(t){t["xlink:href"]=t.href,t.href=null,(n._hrefs||(n._hrefs={}))[r]=t})}return null},vh.mark=function(t){var e,n=this,r=md[t.marktype],i=r.tag,a=this._defs,o="";function s(s){var u=n.href(s);if(u&&(o+=Yd("a",u)),e="g"!==i?xh(s,t,i,a):null,o+=Yd(i,n.attributes(r.attr,s),e),"text"===i){const t=ad(s);if(Object(ct.A)(t)){const e={x:0,dy:id(s)};for(let n=0;n<t.length;++n)o+=Yd("tspan",n?e:null)+wh(sd(s,t[n]))+Jd("tspan")}else o+=wh(sd(s,t))}else if("g"===i){const e=s.strokeForeground,i=s.fill,u=s.stroke;e&&u&&(s.stroke=null),o+=Yd("path",n.attributes(r.background,s),xh(s,t,"bgrect",a))+Jd("path"),o+=Yd("g",n.attributes(r.content,s))+n.markGroup(s)+Jd("g"),e&&u?(i&&(s.fill=null),s.stroke=u,o+=Yd("path",n.attributes(r.foreground,s),xh(s,t,"bgrect",a))+Jd("path"),i&&(s.fill=i)):o+=Yd("path",n.attributes(r.foreground,s),xh({},t,"bgfore",a))+Jd("path")}o+=Jd(i),u&&(o+=Jd("a"))}return"g"!==i&&!1===t.interactive&&(e='style="pointer-events: none;"'),o+=Yd("g",{class:Nd(t),"clip-path":t.clip?Af(n,t,t.group):null},e),r.nested?t.items&&t.items.length&&s(t.items[0]):lf(t,s),o+Jd("g")},vh.markGroup=function(t){var e=this,n="";return lf(t,function(t){n+=e.mark(t)}),n};var kh={Canvas:"canvas",PNG:"png",SVG:"svg",None:"none"},_h={};function Eh(t,e){return t=String(t||"").toLowerCase(),arguments.length>1?(_h[t]=e,this):_h[t]}function Oh(t,e,n){const r=[],i=(new yu).union(e),a=t.marktype;return a?Sh(t,i,n,r):"group"===a?Ch(t,i,n,r):Object(ct.n)("Intersect scene must be mark node or group item.")}function Sh(t,e,n,r){if(function(t,e,n){return t.bounds&&e.intersects(t.bounds)&&("group"===t.marktype||!1!==t.interactive&&(!n||n(t)))}(t,e,n)){const i=t.items,a=t.marktype,o=i.length;let s=0;if("group"===a)for(;s<o;++s)Ch(i[s],e,n,r);else for(const t=md[a].isect;s<o;++s){let n=i[s];Ah(n,e,t)&&r.push(n)}}return r}function Ch(t,e,n,r){n&&n(t.mark)&&Ah(t,e,md.group.isect)&&r.push(t);const i=t.items,a=i&&i.length;if(a){const o=t.x||0,s=t.y||0;e.translate(-o,-s);for(let t=0;t<a;++t)Sh(i[t],e,n,r);e.translate(o,s)}return r}function Ah(t,e,n){const r=t.bounds;return e.encloses(r)||e.intersects(r)&&n(t,e)}_h.canvas=_h.png={renderer:Wd,headless:Wd,handler:Pd},_h.svg={renderer:nh,headless:mh,handler:$d},_h.none={};var Nh=new yu,Th=function(t){var e=t.clip;if(Object(ct.D)(e))e(Ll(Nh.clear()));else{if(!e)return;Nh.set(0,0,t.group.width,t.group.height)}t.bounds.intersect(Nh)},Ih=1e-9;function Dh(t,e,n){return t===e||("path"===n?Mh(t,e):t instanceof Date&&e instanceof Date?+t==+e:Object(ct.E)(t)&&Object(ct.E)(e)?Math.abs(t-e)<=Ih:t&&e&&(Object(ct.F)(t)||Object(ct.F)(e))?null!=t&&null!=e&&function(t,e){var n,r,i=Object.keys(t),a=Object.keys(e);if(i.length!==a.length)return!1;for(i.sort(),a.sort(),r=i.length-1;r>=0;r--)if(i[r]!=a[r])return!1;for(r=i.length-1;r>=0;r--)if(n=i[r],!Dh(t[n],e[n],n))return!1;return typeof t==typeof e}(t,e):t==e)}function Mh(t,e){return Dh(Nc(t),Nc(e))}function Rh(t){Br.call(this,null,t)}function Fh(t,e,n){return e(t.bounds.clear(),t,n)}Object(ct.y)(Rh,Br).transform=function(t,e){var n,r=e.dataflow,i=t.mark,a=i.marktype,o=md[a],s=o.bound,u=i.bounds;if(o.nested)i.items.length&&r.dirty(i.items[0]),u=Fh(i,s),i.items.forEach(function(t){t.bounds.clear().union(u)});else if(a===Ks||t.modified())switch(e.visit(e.MOD,function(t){r.dirty(t)}),u.clear(),i.items.forEach(function(t){u.union(Fh(t,s))}),i.role){case Xs:case Qs:case Ys:e.reflow()}else n=e.changed(e.REM),e.visit(e.ADD,function(t){u.union(Fh(t,s))}),e.visit(e.MOD,function(t){n=n||u.alignsWith(t.bounds),r.dirty(t),u.union(Fh(t,s))}),n&&(u.clear(),i.items.forEach(function(t){u.union(t.bounds)}));return Th(i),e.modifies("bounds")};var jh=":vega_identifier:";function Ph(t){Br.call(this,0,t)}function Lh(t){Br.call(this,null,t)}function zh(t){Br.call(this,null,t)}Ph.Definition={type:"Identifier",metadata:{modifies:!0},params:[{name:"as",type:"string",required:!0}]},Object(ct.y)(Ph,Br).transform=function(t,e){var n=function(t){var e=t._signals[jh];e||(t._signals[jh]=e=t.add(0));return e}(e.dataflow),r=n.value,i=t.as;return e.visit(e.ADD,function(t){t[i]||(t[i]=++r)}),n.set(this.value=r),e},Object(ct.y)(Lh,Br).transform=function(t,e){var n=this.value;n||((n=e.dataflow.scenegraph().mark(t.markdef,function(t){var e=t.groups,n=t.parent;return e&&1===e.size?e.get(Object.keys(e.object)[0]):e&&n?e.lookup(n):null}(t),t.index)).group.context=t.context,t.context.group||(t.context.group=n.group),n.source=this.source,n.clip=t.clip,n.interactive=t.interactive,this.value=n);var r=n.marktype===Ks?Cu:Su;return e.visit(e.ADD,function(t){r.call(t,n)}),(t.modified("clip")||t.modified("interactive"))&&(n.clip=t.clip,n.interactive=!!t.interactive,n.zdirty=!0,e.reflow()),n.items=e.source,e};var Bh={parity:function(t){return t.filter((t,e)=>e%2?t.opacity=0:1)},greedy:function(t,e){var n;return t.filter((t,r)=>r&&Uh(n.bounds,t.bounds,e)?t.opacity=0:(n=t,1))}};function Uh(t,e,n){return n>Math.max(e.x1-t.x2,t.x1-e.x2,e.y1-t.y2,t.y1-e.y2)}function Wh(t,e){for(var n,r=1,i=t.length,a=t[0].bounds;r<i;a=n,++r)if(Uh(a,n=t[r].bounds,e))return!0}function Vh(t){var e=t.bounds;return e.width()>1&&e.height()>1}function qh(t){return t.forEach(t=>t.opacity=1),t}function Hh(t,e){return t.reflow(e.modified()).modifies("opacity")}function Gh(t){Br.call(this,null,t)}Object(ct.y)(zh,Br).transform=function(t,e){var n,r,i,a=Bh[t.method]||Bh.parity,o=e.materialize(e.SOURCE).source,s=t.separation||0;if(o&&o.length){if(!t.method)return t.modified("method")&&(qh(o),e=Hh(e,t)),e;if((o=o.filter(Vh)).length){if(t.sort&&(o=o.slice().sort(t.sort)),n=qh(o),e=Hh(e,t),n.length>=3&&Wh(n,s)){do{n=a(n,s)}while(n.length>=3&&Wh(n,s));n.length<3&&!Object(ct.U)(o).opacity&&(n.length>1&&(Object(ct.U)(n).opacity=0),Object(ct.U)(o).opacity=1)}return t.boundScale&&t.boundTolerance>=0&&(r=function(t,e,n){var r=t.range(),i=new yu;return e===Fs||e===Ls?i.set(r[0],-1/0,r[1],1/0):i.set(-1/0,r[0],1/0,r[1]),i.expand(n||1),t=>i.encloses(t.bounds)}(t.boundScale,t.boundOrient,+t.boundTolerance),o.forEach(t=>{r(t)||(t.opacity=0)})),i=n[0].mark.bounds.clear(),o.forEach(t=>{t.opacity&&i.union(t.bounds)}),e}}},Object(ct.y)(Gh,Br).transform=function(t,e){var n=e.dataflow;if(e.visit(e.ALL,function(t){n.dirty(t)}),e.fields&&e.fields.zindex){var r=e.source&&e.source[0];r&&(r.mark.zdirty=!0)}};const $h=new yu;function Kh(t,e,n){return t[e]===n?0:(t[e]=n,1)}function Xh(t){var e=t.items[0].datum.orient;return e===js||e===Ps}function Yh(t,e,n,r){var i,a,o=e.items[0],s=o.datum,u=s.orient,c=null!=s.translate?s.translate:.5,l=function(t){var e=+t.grid;return[t.ticks?e++:-1,t.labels?e++:-1,e+ +t.domain]}(s),f=o.range,d=o.offset,h=o.position,p=o.minExtent,m=o.maxExtent,g=s.title&&o.items[l[2]].items[0],v=o.titlePadding,y=o.bounds,b=g&&od(g),x=0,w=0;switch($h.clear().union(y),y.clear(),(i=l[0])>-1&&y.union(o.items[i].bounds),(i=l[1])>-1&&y.union(o.items[i].bounds),u){case Fs:x=h||0,w=-d,a=Math.max(p,Math.min(m,-y.y1)),y.add(0,-a).add(f,0),g&&Jh(t,g,a,v,b,0,-1,y);break;case js:x=-d,w=h||0,a=Math.max(p,Math.min(m,-y.x1)),y.add(-a,0).add(0,f),g&&Jh(t,g,a,v,b,1,-1,y);break;case Ps:x=n+d,w=h||0,a=Math.max(p,Math.min(m,y.x2)),y.add(0,0).add(a,f),g&&Jh(t,g,a,v,b,1,1,y);break;case Ls:x=h||0,w=r+d,a=Math.max(p,Math.min(m,y.y2)),y.add(0,0).add(f,a),g&&Jh(t,g,a,v,0,0,1,y);break;default:x=o.x,w=o.y}return Ml(y.translate(x,w),o),Kh(o,"x",x+c)|Kh(o,"y",w+c)&&(o.bounds=$h,t.dirty(o),o.bounds=y,t.dirty(o)),o.mark.bounds.clear().union(y)}function Jh(t,e,n,r,i,a,o,s){const u=e.bounds;if(e.auto){const s=o*(n+i+r);let c=0,l=0;t.dirty(e),a?c=(e.x||0)-(e.x=s):l=(e.y||0)-(e.y=s),e.mark.bounds.clear().union(u.translate(-c,-l)),t.dirty(e)}s.union(u)}function Zh(t){return(new yu).set(0,0,t.width||0,t.height||0)}function Qh(t){var e=t.bounds.clone();return e.empty()?e.set(0,0,0,0):e.translate(-(t.x||0),-(t.y||0))}function tp(t,e,n){var r=Object(ct.F)(t)?t[e]:t;return null!=r?r:void 0!==n?n:0}function ep(t){return t<0?Math.ceil(-t):0}function np(t,e,n){var r,i,a,o,s,u,c,l,f,d,h,p=!n.nodirty,m=n.bounds===mu?Zh:Qh,g=$h.set(0,0,0,0),v=tp(n.align,gu),y=tp(n.align,vu),b=tp(n.padding,gu),x=tp(n.padding,vu),w=n.columns||e.length,k=w<0?1:Math.ceil(e.length/w),_=e.length,E=Array(_),O=Array(w),S=0,C=Array(_),A=Array(k),N=0,T=Array(_),I=Array(_),D=Array(_);for(i=0;i<w;++i)O[i]=0;for(i=0;i<k;++i)A[i]=0;for(i=0;i<_;++i)u=e[i],s=D[i]=m(u),u.x=u.x||0,T[i]=0,u.y=u.y||0,I[i]=0,a=i%w,o=~~(i/w),S=Math.max(S,c=Math.ceil(s.x2)),N=Math.max(N,l=Math.ceil(s.y2)),O[a]=Math.max(O[a],c),A[o]=Math.max(A[o],l),E[i]=b+ep(s.x1),C[i]=x+ep(s.y1),p&&t.dirty(e[i]);for(i=0;i<_;++i)i%w==0&&(E[i]=0),i<w&&(C[i]=0);if(v===pu)for(a=1;a<w;++a){for(h=0,i=a;i<_;i+=w)h<E[i]&&(h=E[i]);for(i=a;i<_;i+=w)E[i]=h+O[a-1]}else if(v===hu){for(h=0,i=0;i<_;++i)i%w&&h<E[i]&&(h=E[i]);for(i=0;i<_;++i)i%w&&(E[i]=h+S)}else for(v=!1,a=1;a<w;++a)for(i=a;i<_;i+=w)E[i]+=O[a-1];if(y===pu)for(o=1;o<k;++o){for(h=0,r=(i=o*w)+w;i<r;++i)h<C[i]&&(h=C[i]);for(i=o*w;i<r;++i)C[i]=h+A[o-1]}else if(y===hu){for(h=0,i=w;i<_;++i)h<C[i]&&(h=C[i]);for(i=w;i<_;++i)C[i]=h+N}else for(y=!1,o=1;o<k;++o)for(r=(i=o*w)+w;i<r;++i)C[i]+=A[o-1];for(f=0,i=0;i<_;++i)f=E[i]+(i%w?f:0),T[i]+=f-e[i].x;for(a=0;a<w;++a)for(d=0,i=a;i<_;i+=w)d+=C[i],I[i]+=d-e[i].y;if(v&&tp(n.center,gu)&&k>1)for(i=0;i<_;++i)(f=(s=v===hu?S:O[i%w])-D[i].x2-e[i].x-T[i])>0&&(T[i]+=f/2);if(y&&tp(n.center,vu)&&1!==w)for(i=0;i<_;++i)(d=(s=y===hu?N:A[~~(i/w)])-D[i].y2-e[i].y-I[i])>0&&(I[i]+=d/2);for(i=0;i<_;++i)g.union(D[i].translate(T[i],I[i]));switch(f=tp(n.anchor,Gs),d=tp(n.anchor,$s),tp(n.anchor,gu)){case Hs:f-=g.width();break;case qs:f-=g.width()/2}switch(tp(n.anchor,vu)){case Hs:d-=g.height();break;case qs:d-=g.height()/2}for(f=Math.round(f),d=Math.round(d),g.clear(),i=0;i<_;++i)e[i].mark.bounds.clear();for(i=0;i<_;++i)(u=e[i]).x+=T[i]+=f,u.y+=I[i]+=d,g.union(u.mark.bounds.union(u.bounds.translate(T[i],I[i]))),p&&t.dirty(u);return g}function rp(t,e,n){var r,i,a,o,s,u,c,l=function(t){for(var e,n,r=t.items,i=r.length,a=0,o={marks:[],rowheaders:[],rowfooters:[],colheaders:[],colfooters:[],rowtitle:null,coltitle:null};a<i;++a)if(n=(e=r[a]).items,e.marktype===Ks)switch(e.role){case Xs:case Qs:case Ys:break;case tu:o.rowheaders.push(...n);break;case eu:o.rowfooters.push(...n);break;case ru:o.colheaders.push(...n);break;case iu:o.colfooters.push(...n);break;case nu:o.rowtitle=n[0];break;case au:o.coltitle=n[0];break;default:o.marks.push(...n)}return o}(e),f=l.marks,d=n.bounds===mu?ip:ap,h=n.offset,p=n.columns||f.length,m=p<0?1:Math.ceil(f.length/p),g=m*p;const v=np(t,f,n);l.rowheaders&&(u=tp(n.headerBand,vu,null),r=up(t,l.rowheaders,f,p,m,-tp(h,"rowHeader"),op,0,d,"x1",0,p,1,u)),l.colheaders&&(u=tp(n.headerBand,gu,null),i=up(t,l.colheaders,f,p,p,-tp(h,"columnHeader"),op,1,d,"y1",0,1,p,u)),l.rowfooters&&(u=tp(n.footerBand,vu,null),a=up(t,l.rowfooters,f,p,m,tp(h,"rowFooter"),sp,0,d,"x2",p-1,p,1,u)),l.colfooters&&(u=tp(n.footerBand,gu,null),o=up(t,l.colfooters,f,p,p,tp(h,"columnFooter"),sp,1,d,"y2",g-p,1,p,u)),l.rowtitle&&(s=tp(n.titleAnchor,vu),c=tp(h,"rowTitle"),c=s===Hs?a+c:r-c,u=tp(n.titleBand,vu,.5),cp(t,l.rowtitle,c,0,v,u)),l.coltitle&&(s=tp(n.titleAnchor,gu),c=tp(h,"columnTitle"),c=s===Hs?o+c:i-c,u=tp(n.titleBand,gu,.5),cp(t,l.coltitle,c,1,v,u))}function ip(t,e){return"x1"===e?t.x||0:"y1"===e?t.y||0:"x2"===e?(t.x||0)+(t.width||0):"y2"===e?(t.y||0)+(t.height||0):void 0}function ap(t,e){return t.bounds[e]}function op(t,e){return Math.floor(Math.min(t,e))}function sp(t,e){return Math.ceil(Math.max(t,e))}function up(t,e,n,r,i,a,o,s,u,c,l,f,d,h){var p,m,g,v,y,b,x,w,k,_=n.length,E=0,O=0;if(!_)return E;for(p=l;p<_;p+=f)n[p]&&(E=o(E,u(n[p],c)));if(!e.length)return E;for(e.length>i&&(t.warn("Grid headers exceed limit: "+i),e=e.slice(0,i)),E+=a,m=0,v=e.length;m<v;++m)t.dirty(e[m]),e[m].mark.bounds.clear();for(p=l,m=0,v=e.length;m<v;++m,p+=f){for(y=(b=e[m]).mark.bounds,g=p;g>=0&&null==(x=n[g]);g-=d);s?(w=null==h?x.x:Math.round(x.bounds.x1+h*x.bounds.width()),k=E):(w=E,k=null==h?x.y:Math.round(x.bounds.y1+h*x.bounds.height())),y.union(b.bounds.translate(w-(b.x||0),k-(b.y||0))),b.x=w,b.y=k,t.dirty(b),O=o(O,y[c])}return O}function cp(t,e,n,r,i,a){if(e){t.dirty(e);var o=n,s=n;r?o=Math.round(i.x1+a*i.width()):s=Math.round(i.y1+a*i.height()),e.bounds.translate(o-(e.x||0),s-(e.y||0)),e.mark.bounds.clear().union(e.bounds),e.x=o,e.y=s,t.dirty(e)}}function lp(t,e,n,r,i,a,o){const s=function(t,e){const n=t[e]||{};return(e,r)=>null!=n[e]?n[e]:null!=t[e]?t[e]:r}(n,e),u=function(t,e){var n=-1/0;return t.forEach(t=>{null!=t.offset&&(n=Math.max(n,t.offset))}),n>-1/0?n:e}(t,s("offset",0)),c=s("anchor",Vs),l=c===Hs?1:c===qs?.5:0,f={align:pu,bounds:s("bounds",mu),columns:"vertical"===s("direction")?1:t.length,padding:s("margin",8),center:s("center"),nodirty:!0};switch(e){case js:f.anchor={x:Math.floor(r.x1)-u,column:Hs,y:l*(o||r.height()+2*r.y1),row:c};break;case Ps:f.anchor={x:Math.ceil(r.x2)+u,y:l*(o||r.height()+2*r.y1),row:c};break;case Fs:f.anchor={y:Math.floor(i.y1)-u,row:Hs,x:l*(a||i.width()+2*i.x1),column:c};break;case Ls:f.anchor={y:Math.ceil(i.y2)+u,x:l*(a||i.width()+2*i.x1),column:c};break;case zs:f.anchor={x:u,y:u};break;case Bs:f.anchor={x:a-u,y:u,column:Hs};break;case Us:f.anchor={x:u,y:o-u,row:Hs};break;case Ws:f.anchor={x:a-u,y:o-u,column:Hs,row:Hs}}return f}function fp(t,e){var n,r,i=e.items[0],a=i.datum,o=i.orient,s=i.bounds,u=i.x,c=i.y;return i._bounds?i._bounds.clear().union(s):i._bounds=s.clone(),s.clear(),function(t,e,n){var r=e.padding,i=r-n.x,a=r-n.y;if(e.datum.title){var o=e.items[1].items[0],s=o.anchor,u=e.titlePadding||0,c=r-o.x,l=r-o.y;switch(o.orient){case js:i+=Math.ceil(o.bounds.width())+u;break;case Ps:case Ls:break;default:a+=o.bounds.height()+u}switch((i||a)&&hp(t,n,i,a),o.orient){case js:l+=dp(e,n,o,s,1,1);break;case Ps:c+=dp(e,n,o,Hs,0,0)+u,l+=dp(e,n,o,s,1,1);break;case Ls:c+=dp(e,n,o,s,0,0),l+=dp(e,n,o,Hs,-1,0,1)+u;break;default:c+=dp(e,n,o,s,0,0)}(c||l)&&hp(t,o,c,l),(c=Math.round(o.bounds.x1-r))<0&&(hp(t,n,-c,0),hp(t,o,-c,0))}else(i||a)&&hp(t,n,i,a)}(t,i,i.items[0].items[0]),s=function(t,e){return t.items.forEach(t=>e.union(t.bounds)),e.x1=t.padding,e.y1=t.padding,e}(i,s),n=2*i.padding,r=2*i.padding,s.empty()||(n=Math.ceil(s.width()+n),r=Math.ceil(s.height()+r)),a.type===su&&function(t){var e=t.reduce(function(t,e){return t[e.column]=Math.max(e.bounds.x2-e.x,t[e.column]||0),t},{});t.forEach(function(t){t.width=e[t.column],t.height=t.bounds.y2-t.y})}(i.items[0].items[0].items[0].items),o!==du&&(i.x=u=0,i.y=c=0),i.width=n,i.height=r,Ml(s.set(u,c,u+n,c+r),i),i.mark.bounds.clear().union(s),i}function dp(t,e,n,r,i,a,o){const s="symbol"!==t.datum.type,u=n.datum.vgrad,c=(!s||!a&&u||o?e:e.items[0]).bounds[i?"y2":"x2"]-t.padding,l=u&&a?c:0,f=u&&a?0:c,d=i<=0?0:od(n);return Math.round(r===Vs?l:r===Hs?f-d:.5*(c-d))}function hp(t,e,n,r){e.x+=n,e.y+=r,e.bounds.translate(n,r),e.mark.bounds.translate(n,r),t.dirty(e)}function pp(t){Br.call(this,null,t)}Object(ct.y)(pp,Br).transform=function(t,e){var n=e.dataflow;return t.mark.items.forEach(function(e){t.layout&&rp(n,e,t.layout),function(t,e,n){var r,i,a,o,s,u=e.items,c=Math.max(0,e.width||0),l=Math.max(0,e.height||0),f=(new yu).set(0,0,c,l),d=f.clone(),h=f.clone(),p=[];for(o=0,s=u.length;o<s;++o)switch((i=u[o]).role){case Xs:(Xh(i)?d:h).union(Yh(t,i,c,l));break;case Ys:r=i;break;case Qs:p.push(fp(t,i));break;case Js:case Zs:case tu:case eu:case nu:case ru:case iu:case au:d.union(i.bounds),h.union(i.bounds);break;default:f.union(i.bounds)}if(p.length){const e={};p.forEach(t=>{(a=t.orient||Ps)!==du&&(e[a]||(e[a]=[])).push(t)});for(let r in e){const i=e[r];np(t,i,lp(i,r,n.legends,d,h,c,l))}p.forEach(e=>{const r=e.bounds;if(r.equals(e._bounds)||(e.bounds=e._bounds,t.dirty(e),e.bounds=r,t.dirty(e)),n.autosize&&n.autosize.type===uu)switch(e.orient){case js:case Ps:f.add(r.x1,0).add(r.x2,0);break;case Fs:case Ls:f.add(0,r.y1).add(0,r.y2)}else f.union(r)})}f.union(d).union(h),r&&f.union(function(t,e,n,r,i){var a,o=e.items[0],s=o.frame,u=o.orient,c=o.anchor,l=o.offset,f=o.padding,d=o.items[0].items[0],h=o.items[1]&&o.items[1].items[0],p=u===js||u===Ps?r:n,m=0,g=0,v=0,y=0,b=0;if(s!==Ks?u===js?(m=i.y2,p=i.y1):u===Ps?(m=i.y1,p=i.y2):(m=i.x1,p=i.x2):u===js&&(m=r,p=0),a=c===Vs?m:c===Hs?p:(m+p)/2,h&&h.text){switch(u){case Fs:case Ls:b=d.bounds.height()+f;break;case js:y=d.bounds.width()+f;break;case Ps:y=-d.bounds.width()-f}$h.clear().union(h.bounds),$h.translate(y-(h.x||0),b-(h.y||0)),Kh(h,"x",y)|Kh(h,"y",b)&&(t.dirty(h),h.bounds.clear().union($h),h.mark.bounds.clear().union($h),t.dirty(h)),$h.clear().union(h.bounds)}else $h.clear();switch($h.union(d.bounds),u){case Fs:g=a,v=i.y1-$h.height()-l;break;case js:g=i.x1-$h.width()-l,v=a;break;case Ps:g=i.x2+$h.width()+l,v=a;break;case Ls:g=a,v=i.y2+l;break;default:g=o.x,v=o.y}return Kh(o,"x",g)|Kh(o,"y",v)&&($h.translate(g,v),t.dirty(o),o.bounds.clear().union($h),e.bounds.clear().union($h),t.dirty(o)),o.bounds}(t,r,c,l,f));e.clip&&f.set(0,0,e.width||0,e.height||0);!function(t,e,n,r){const i=r.autosize||{},a=i.type;if(t._autosize<1||!a)return;let o=t._width,s=t._height,u=Math.max(0,e.width||0),c=Math.max(0,Math.ceil(-n.x1)),l=Math.max(0,Math.ceil(n.x2-u)),f=Math.max(0,e.height||0),d=Math.max(0,Math.ceil(-n.y1)),h=Math.max(0,Math.ceil(n.y2-f));if(i.contains===ou){const e=t.padding();o-=e.left+e.right,s-=e.top+e.bottom}a===du?(c=0,d=0,u=o,f=s):a===uu?(u=Math.max(0,o-c-l),f=Math.max(0,s-d-h)):a===cu?(u=Math.max(0,o-c-l),s=f+d+h):a===lu?(o=u+c+l,f=Math.max(0,s-d-h)):a===fu&&(o=u+c+l,s=f+d+h);t._resizeView(o,s,u,f,[c,d],i.resize)}(t,e,f,n)}(n,e,t)}),t.modified()&&e.reflow(),e};var mp=function(t,e,n){var r=t-e+2*n;return t?r>0?r:1:0};const gp="linear",vp="log",yp="pow",bp="sqrt",xp="symlog",wp="time",kp="utc",_p="sequential",Ep="diverging",Op="quantile",Sp="quantize",Cp="threshold",Ap="ordinal",Np="point",Tp="band",Ip="bin-ordinal",Dp="continuous",Mp="discrete",Rp="discretizing",Fp="interpolating",jp="temporal";var Pp=function(t){return function(e){var n,r=e[0],i=e[1];return i<r&&(n=r,r=i,i=n),[t.invert(r),t.invert(i)]}},Lp=function(t){return function(e){var n,r,i,a,o=t.range(),s=e[0],u=e[1],c=-1;for(u<s&&(r=s,s=u,u=r),i=0,a=o.length;i<a;++i)o[i]>=s&&o[i]<=u&&(c<0&&(c=i),n=i);if(!(c<0))return s=t.invertExtent(o[c]),u=t.invertExtent(o[n]),[void 0===s[0]?s[1]:s[0],void 0===u[1]?u[0]:u[1]]}},zp=os(ti),Bp=zp.right,Up=zp.left,Wp=Bp;function Vp(t,e){switch(arguments.length){case 0:break;case 1:this.range(t);break;default:this.range(e).domain(t)}return this}function qp(t,e){switch(arguments.length){case 0:break;case 1:"function"==typeof t?this.interpolator(t):this.range(t);break;default:this.domain(t),"function"==typeof e?this.interpolator(e):this.range(e)}return this}const Hp=Symbol("implicit");function Gp(){var t=new Map,e=[],n=[],r=Hp;function i(i){var a=i+"",o=t.get(a);if(!o){if(r!==Hp)return r;t.set(a,o=e.push(i))}return n[(o-1)%n.length]}return i.domain=function(n){if(!arguments.length)return e.slice();e=[],t=new Map;for(const r of n){const n=r+"";t.has(n)||t.set(n,e.push(r))}return i},i.range=function(t){return arguments.length?(n=Array.from(t),i):n.slice()},i.unknown=function(t){return arguments.length?(r=t,i):r},i.copy=function(){return Gp(e,n).unknown(r)},Vp.apply(i,arguments),i}function $p(){var t,e,n=Gp().unknown(void 0),r=n.domain,i=n.range,a=[0,1],o=!1,s=0,u=0,c=.5;function l(){var n=r().length,l=a[1]<a[0],f=a[l-0],d=a[1-l],h=mp(n,s,u);t=(d-f)/(h||1),o&&(t=Math.floor(t)),f+=(d-f-t*(n-s))*c,e=t*(1-s),o&&(f=Math.round(f),e=Math.round(e));var p=ro(n).map(function(e){return f+t*e});return i(l?p.reverse():p)}return delete n.unknown,n.domain=function(t){return arguments.length?(r(t),l()):r()},n.range=function(t){return arguments.length?(a=[+t[0],+t[1]],l()):a.slice()},n.rangeRound=function(t){return a=[+t[0],+t[1]],o=!0,l()},n.bandwidth=function(){return e},n.step=function(){return t},n.round=function(t){return arguments.length?(o=!!t,l()):o},n.padding=function(t){return arguments.length?(u=Math.max(0,Math.min(1,t)),s=u,l()):s},n.paddingInner=function(t){return arguments.length?(s=Math.max(0,Math.min(1,t)),l()):s},n.paddingOuter=function(t){return arguments.length?(u=Math.max(0,Math.min(1,t)),l()):u},n.align=function(t){return arguments.length?(c=Math.max(0,Math.min(1,t)),l()):c},n.invertRange=function(t){if(null!=t[0]&&null!=t[1]){var n,o,s,u=+t[0],c=+t[1],l=a[1]<a[0],f=l?i().reverse():i(),d=f.length-1;if(u==u&&c==c&&(c<u&&(s=u,u=c,c=s),!(c<f[0]||u>a[1-l])))return n=Math.max(0,Bp(f,u)-1),o=u===c?n:Bp(f,c)-1,u-f[n]>e+1e-10&&++n,l&&(s=n,n=d-o,o=d-s),n>o?void 0:r().slice(n,o+1)}},n.invert=function(t){var e=n.invertRange([t,t]);return e?e[0]:e},n.copy=function(){return $p().domain(r()).range(a).round(o).paddingInner(s).paddingOuter(u).align(c)},l()}var Kp=n(45),Xp=function(t,e,n,r){var i,a=ds(t,e,n);switch((r=Object(Kp.formatSpecifier)(null==r?",f":r)).type){case"s":var o=Math.max(Math.abs(t),Math.abs(e));return null!=r.precision||isNaN(i=Object(Kp.precisionPrefix)(a,o))||(r.precision=i),Object(Kp.formatPrefix)(r,o);case"":case"e":case"g":case"p":case"r":null!=r.precision||isNaN(i=Object(Kp.precisionRound)(a,Math.max(Math.abs(t),Math.abs(e))))||(r.precision=i-("e"===r.type));break;case"f":case"%":null!=r.precision||isNaN(i=Object(Kp.precisionFixed)(a))||(r.precision=i-2*("%"===r.type))}return Object(Kp.format)(r)},Yp=Array.prototype.map;var Jp=Array.prototype.slice;function Zp(){var t,e=[.5],n=[0,1],r=1;function i(i){return i<=i?n[Wp(e,i,0,r)]:t}return i.domain=function(t){return arguments.length?(e=Array.from(t),r=Math.min(e.length,n.length-1),i):e.slice()},i.range=function(t){return arguments.length?(n=Array.from(t),r=Math.min(e.length,n.length-1),i):n.slice()},i.invertExtent=function(t){var r=n.indexOf(t);return[e[r-1],e[r]]},i.unknown=function(e){return arguments.length?(t=e,i):t},i.copy=function(){return Zp().domain(e).range(n).unknown(t)},Vp.apply(i,arguments)}var Qp=function(t,e,n){t.prototype=e.prototype=n,n.constructor=t};function tm(t,e){var n=Object.create(t.prototype);for(var r in e)n[r]=e[r];return n}function em(){}var nm="\\s*([+-]?\\d+)\\s*",rm="\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",im="\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",am=/^#([0-9a-f]{3,8})$/,om=new RegExp("^rgb\\("+[nm,nm,nm]+"\\)$"),sm=new RegExp("^rgb\\("+[im,im,im]+"\\)$"),um=new RegExp("^rgba\\("+[nm,nm,nm,rm]+"\\)$"),cm=new RegExp("^rgba\\("+[im,im,im,rm]+"\\)$"),lm=new RegExp("^hsl\\("+[rm,im,im]+"\\)$"),fm=new RegExp("^hsla\\("+[rm,im,im,rm]+"\\)$"),dm={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};function hm(){return this.rgb().formatHex()}function pm(){return this.rgb().formatRgb()}function mm(t){var e,n;return t=(t+"").trim().toLowerCase(),(e=am.exec(t))?(n=e[1].length,e=parseInt(e[1],16),6===n?gm(e):3===n?new xm(e>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?new xm(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?new xm(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=om.exec(t))?new xm(e[1],e[2],e[3],1):(e=sm.exec(t))?new xm(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=um.exec(t))?vm(e[1],e[2],e[3],e[4]):(e=cm.exec(t))?vm(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=lm.exec(t))?Em(e[1],e[2]/100,e[3]/100,1):(e=fm.exec(t))?Em(e[1],e[2]/100,e[3]/100,e[4]):dm.hasOwnProperty(t)?gm(dm[t]):"transparent"===t?new xm(NaN,NaN,NaN,0):null}function gm(t){return new xm(t>>16&255,t>>8&255,255&t,1)}function vm(t,e,n,r){return r<=0&&(t=e=n=NaN),new xm(t,e,n,r)}function ym(t){return t instanceof em||(t=mm(t)),t?new xm((t=t.rgb()).r,t.g,t.b,t.opacity):new xm}function bm(t,e,n,r){return 1===arguments.length?ym(t):new xm(t,e,n,null==r?1:r)}function xm(t,e,n,r){this.r=+t,this.g=+e,this.b=+n,this.opacity=+r}function wm(){return"#"+_m(this.r)+_m(this.g)+_m(this.b)}function km(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"rgb(":"rgba(")+Math.max(0,Math.min(255,Math.round(this.r)||0))+", "+Math.max(0,Math.min(255,Math.round(this.g)||0))+", "+Math.max(0,Math.min(255,Math.round(this.b)||0))+(1===t?")":", "+t+")")}function _m(t){return((t=Math.max(0,Math.min(255,Math.round(t)||0)))<16?"0":"")+t.toString(16)}function Em(t,e,n,r){return r<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new Cm(t,e,n,r)}function Om(t){if(t instanceof Cm)return new Cm(t.h,t.s,t.l,t.opacity);if(t instanceof em||(t=mm(t)),!t)return new Cm;if(t instanceof Cm)return t;var e=(t=t.rgb()).r/255,n=t.g/255,r=t.b/255,i=Math.min(e,n,r),a=Math.max(e,n,r),o=NaN,s=a-i,u=(a+i)/2;return s?(o=e===a?(n-r)/s+6*(n<r):n===a?(r-e)/s+2:(e-n)/s+4,s/=u<.5?a+i:2-a-i,o*=60):s=u>0&&u<1?0:o,new Cm(o,s,u,t.opacity)}function Sm(t,e,n,r){return 1===arguments.length?Om(t):new Cm(t,e,n,null==r?1:r)}function Cm(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}function Am(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}function Nm(t,e,n,r,i){var a=t*t,o=a*t;return((1-3*t+3*a-o)*e+(4-6*a+3*o)*n+(1+3*t+3*a-3*o)*r+o*i)/6}Qp(em,mm,{copy:function(t){return Object.assign(new this.constructor,this,t)},displayable:function(){return this.rgb().displayable()},hex:hm,formatHex:hm,formatHsl:function(){return Om(this).formatHsl()},formatRgb:pm,toString:pm}),Qp(xm,bm,tm(em,{brighter:function(t){return t=null==t?1/.7:Math.pow(1/.7,t),new xm(this.r*t,this.g*t,this.b*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new xm(this.r*t,this.g*t,this.b*t,this.opacity)},rgb:function(){return this},displayable:function(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:wm,formatHex:wm,formatRgb:km,toString:km})),Qp(Cm,Sm,tm(em,{brighter:function(t){return t=null==t?1/.7:Math.pow(1/.7,t),new Cm(this.h,this.s,this.l*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new Cm(this.h,this.s,this.l*t,this.opacity)},rgb:function(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*e,i=2*n-r;return new xm(Am(t>=240?t-240:t+120,i,r),Am(t,i,r),Am(t<120?t+240:t-120,i,r),this.opacity)},displayable:function(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl:function(){var t=this.opacity;return(1===(t=isNaN(t)?1:Math.max(0,Math.min(1,t)))?"hsl(":"hsla(")+(this.h||0)+", "+100*(this.s||0)+"%, "+100*(this.l||0)+"%"+(1===t?")":", "+t+")")}}));var Tm=function(t){var e=t.length-1;return function(n){var r=n<=0?n=0:n>=1?(n=1,e-1):Math.floor(n*e),i=t[r],a=t[r+1],o=r>0?t[r-1]:2*i-a,s=r<e-1?t[r+2]:2*a-i;return Nm((n-r/e)*e,o,i,a,s)}},Im=function(t){var e=t.length;return function(n){var r=Math.floor(((n%=1)<0?++n:n)*e),i=t[(r+e-1)%e],a=t[r%e],o=t[(r+1)%e],s=t[(r+2)%e];return Nm((n-r/e)*e,i,a,o,s)}},Dm=function(t){return function(){return t}};function Mm(t,e){return function(n){return t+n*e}}function Rm(t,e){var n=e-t;return n?Mm(t,n>180||n<-180?n-360*Math.round(n/360):n):Dm(isNaN(t)?e:t)}function Fm(t){return 1==(t=+t)?jm:function(e,n){return n-e?function(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(r){return Math.pow(t+r*e,n)}}(e,n,t):Dm(isNaN(e)?n:e)}}function jm(t,e){var n=e-t;return n?Mm(t,n):Dm(isNaN(t)?e:t)}var Pm=function t(e){var n=Fm(e);function r(t,e){var r=n((t=bm(t)).r,(e=bm(e)).r),i=n(t.g,e.g),a=n(t.b,e.b),o=jm(t.opacity,e.opacity);return function(e){return t.r=r(e),t.g=i(e),t.b=a(e),t.opacity=o(e),t+""}}return r.gamma=t,r}(1);function Lm(t){return function(e){var n,r,i=e.length,a=new Array(i),o=new Array(i),s=new Array(i);for(n=0;n<i;++n)r=bm(e[n]),a[n]=r.r||0,o[n]=r.g||0,s[n]=r.b||0;return a=t(a),o=t(o),s=t(s),r.opacity=1,function(t){return r.r=a(t),r.g=o(t),r.b=s(t),r+""}}}var zm=Lm(Tm),Bm=Lm(Im),Um=function(t,e){e||(e=[]);var n,r=t?Math.min(e.length,t.length):0,i=e.slice();return function(a){for(n=0;n<r;++n)i[n]=t[n]*(1-a)+e[n]*a;return i}};function Wm(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}var Vm=function(t,e){return(Wm(e)?Um:qm)(t,e)};function qm(t,e){var n,r=e?e.length:0,i=t?Math.min(r,t.length):0,a=new Array(i),o=new Array(r);for(n=0;n<i;++n)a[n]=Jm(t[n],e[n]);for(;n<r;++n)o[n]=e[n];return function(t){for(n=0;n<i;++n)o[n]=a[n](t);return o}}var Hm=function(t,e){var n=new Date;return t=+t,e=+e,function(r){return n.setTime(t*(1-r)+e*r),n}},Gm=function(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}},$m=function(t,e){var n,r={},i={};for(n in null!==t&&"object"==typeof t||(t={}),null!==e&&"object"==typeof e||(e={}),e)n in t?r[n]=Jm(t[n],e[n]):i[n]=e[n];return function(t){for(n in r)i[n]=r[n](t);return i}},Km=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Xm=new RegExp(Km.source,"g");var Ym=function(t,e){var n,r,i,a=Km.lastIndex=Xm.lastIndex=0,o=-1,s=[],u=[];for(t+="",e+="";(n=Km.exec(t))&&(r=Xm.exec(e));)(i=r.index)>a&&(i=e.slice(a,i),s[o]?s[o]+=i:s[++o]=i),(n=n[0])===(r=r[0])?s[o]?s[o]+=r:s[++o]=r:(s[++o]=null,u.push({i:o,x:Gm(n,r)})),a=Xm.lastIndex;return a<e.length&&(i=e.slice(a),s[o]?s[o]+=i:s[++o]=i),s.length<2?u[0]?function(t){return function(e){return t(e)+""}}(u[0].x):function(t){return function(){return t}}(e):(e=u.length,function(t){for(var n,r=0;r<e;++r)s[(n=u[r]).i]=n.x(t);return s.join("")})},Jm=function(t,e){var n,r=typeof e;return null==e||"boolean"===r?Dm(e):("number"===r?Gm:"string"===r?(n=mm(e))?(e=n,Pm):Ym:e instanceof mm?Pm:e instanceof Date?Hm:Wm(e)?Um:Array.isArray(e)?qm:"function"!=typeof e.valueOf&&"function"!=typeof e.toString||isNaN(e)?$m:Gm)(t,e)},Zm=function(t,e){return t=+t,e=+e,function(n){return Math.round(t*(1-n)+e*n)}};function Qm(t,e){for(var n=0,r=e.length-1,i=e[0],a=new Array(r<0?0:r);n<r;)a[n]=t(i,i=e[++n]);return function(t){var e=Math.max(0,Math.min(r-1,Math.floor(t*=r)));return a[e](t-e)}}var tg=function(t){return function(){return t}},eg=function(t){return+t},ng=[0,1];function rg(t){return t}function ig(t,e){return(e-=t=+t)?function(n){return(n-t)/e}:tg(isNaN(e)?NaN:.5)}function ag(t,e,n){var r=t[0],i=t[1],a=e[0],o=e[1];return i<r?(r=ig(i,r),a=n(o,a)):(r=ig(r,i),a=n(a,o)),function(t){return a(r(t))}}function og(t,e,n){var r=Math.min(t.length,e.length)-1,i=new Array(r),a=new Array(r),o=-1;for(t[r]<t[0]&&(t=t.slice().reverse(),e=e.slice().reverse());++o<r;)i[o]=ig(t[o],t[o+1]),a[o]=n(e[o],e[o+1]);return function(e){var n=Wp(t,e,1,r)-1;return a[n](i[n](e))}}function sg(t,e){return e.domain(t.domain()).range(t.range()).interpolate(t.interpolate()).clamp(t.clamp()).unknown(t.unknown())}function ug(){var t,e,n,r,i,a,o=ng,s=ng,u=Jm,c=rg;function l(){var t=Math.min(o.length,s.length);return c!==rg&&(c=function(t,e){var n;return t>e&&(n=t,t=e,e=n),function(n){return Math.max(t,Math.min(e,n))}}(o[0],o[t-1])),r=t>2?og:ag,i=a=null,f}function f(e){return isNaN(e=+e)?n:(i||(i=r(o.map(t),s,u)))(t(c(e)))}return f.invert=function(n){return c(e((a||(a=r(s,o.map(t),Gm)))(n)))},f.domain=function(t){return arguments.length?(o=Array.from(t,eg),l()):o.slice()},f.range=function(t){return arguments.length?(s=Array.from(t),l()):s.slice()},f.rangeRound=function(t){return s=Array.from(t),u=Zm,l()},f.clamp=function(t){return arguments.length?(c=!!t||rg,l()):c!==rg},f.interpolate=function(t){return arguments.length?(u=t,l()):u},f.unknown=function(t){return arguments.length?(n=t,f):n},function(n,r){return t=n,e=r,l()}}function cg(){return ug()(rg,rg)}function lg(t){var e=t.domain;return t.ticks=function(t){var n=e();return ls(n[0],n[n.length-1],null==t?10:t)},t.tickFormat=function(t,n){var r=e();return Xp(r[0],r[r.length-1],null==t?10:t,n)},t.nice=function(n){null==n&&(n=10);var r,i=e(),a=0,o=i.length-1,s=i[a],u=i[o];return u<s&&(r=s,s=u,u=r,r=a,a=o,o=r),(r=fs(s,u,n))>0?r=fs(s=Math.floor(s/r)*r,u=Math.ceil(u/r)*r,n):r<0&&(r=fs(s=Math.ceil(s*r)/r,u=Math.floor(u*r)/r,n)),r>0?(i[a]=Math.floor(s/r)*r,i[o]=Math.ceil(u/r)*r,e(i)):r<0&&(i[a]=Math.ceil(s*r)/r,i[o]=Math.floor(u*r)/r,e(i)),t},t}function fg(){var t=cg();return t.copy=function(){return sg(t,fg())},Vp.apply(t,arguments),lg(t)}var dg=function(t,e){var n,r=0,i=(t=t.slice()).length-1,a=t[r],o=t[i];return o<a&&(n=r,r=i,i=n,n=a,a=o,o=n),t[r]=e.floor(a),t[i]=e.ceil(o),t};function hg(t){return Math.log(t)}function pg(t){return Math.exp(t)}function mg(t){return-Math.log(-t)}function gg(t){return-Math.exp(-t)}function vg(t){return isFinite(t)?+("1e"+t):t<0?0:t}function yg(t){return function(e){return-t(-e)}}function bg(t){var e,n,r=t(hg,pg),i=r.domain,a=10;function o(){return e=function(t){return t===Math.E?Math.log:10===t&&Math.log10||2===t&&Math.log2||(t=Math.log(t),function(e){return Math.log(e)/t})}(a),n=function(t){return 10===t?vg:t===Math.E?Math.exp:function(e){return Math.pow(t,e)}}(a),i()[0]<0?(e=yg(e),n=yg(n),t(mg,gg)):t(hg,pg),r}return r.base=function(t){return arguments.length?(a=+t,o()):a},r.domain=function(t){return arguments.length?(i(t),o()):i()},r.ticks=function(t){var r,o=i(),s=o[0],u=o[o.length-1];(r=u<s)&&(d=s,s=u,u=d);var c,l,f,d=e(s),h=e(u),p=null==t?10:+t,m=[];if(!(a%1)&&h-d<p){if(d=Math.floor(d),h=Math.ceil(h),s>0){for(;d<=h;++d)for(l=1,c=n(d);l<a;++l)if(!((f=c*l)<s)){if(f>u)break;m.push(f)}}else for(;d<=h;++d)for(l=a-1,c=n(d);l>=1;--l)if(!((f=c*l)<s)){if(f>u)break;m.push(f)}2*m.length<p&&(m=ls(s,u,p))}else m=ls(d,h,Math.min(h-d,p)).map(n);return r?m.reverse():m},r.tickFormat=function(t,i){if(null==i&&(i=10===a?".0e":","),"function"!=typeof i&&(i=Object(Kp.format)(i)),t===1/0)return i;null==t&&(t=10);var o=Math.max(1,a*t/r.ticks().length);return function(t){var r=t/n(Math.round(e(t)));return r*a<a-.5&&(r*=a),r<=o?i(t):""}},r.nice=function(){return i(dg(i(),{floor:function(t){return n(Math.floor(e(t)))},ceil:function(t){return n(Math.ceil(e(t)))}}))},r}function xg(){var t=bg(ug()).domain([1,10]);return t.copy=function(){return sg(t,xg()).base(t.base())},Vp.apply(t,arguments),t}function wg(t){return function(e){return Math.sign(e)*Math.log1p(Math.abs(e/t))}}function kg(t){return function(e){return Math.sign(e)*Math.expm1(Math.abs(e))*t}}function _g(t){var e=1,n=t(wg(e),kg(e));return n.constant=function(n){return arguments.length?t(wg(e=+n),kg(e)):e},lg(n)}function Eg(){var t=_g(ug());return t.copy=function(){return sg(t,Eg()).constant(t.constant())},Vp.apply(t,arguments)}function Og(t){return function(e){return e<0?-Math.pow(-e,t):Math.pow(e,t)}}function Sg(t){return t<0?-Math.sqrt(-t):Math.sqrt(t)}function Cg(t){return t<0?-t*t:t*t}function Ag(t){var e=t(rg,rg),n=1;return e.exponent=function(e){return arguments.length?1===(n=+e)?t(rg,rg):.5===n?t(Sg,Cg):t(Og(n),Og(1/n)):n},lg(e)}function Ng(){var t=Ag(ug());return t.copy=function(){return sg(t,Ng()).exponent(t.exponent())},Vp.apply(t,arguments),t}function Tg(){return Ng.apply(null,arguments).exponent(.5)}function Ig(){var t,e,n,r,i,a=0,o=1,s=rg,u=!1;function c(e){return isNaN(e=+e)?i:s(0===n?.5:(e=(r(e)-t)*n,u?Math.max(0,Math.min(1,e)):e))}function l(t){return function(e){var n,r;return arguments.length?([n,r]=e,s=t(n,r),c):[s(0),s(1)]}}return c.domain=function(i){return arguments.length?([a,o]=i,t=r(a=+a),e=r(o=+o),n=t===e?0:1/(e-t),c):[a,o]},c.clamp=function(t){return arguments.length?(u=!!t,c):u},c.interpolator=function(t){return arguments.length?(s=t,c):s},c.range=l(Jm),c.rangeRound=l(Zm),c.unknown=function(t){return arguments.length?(i=t,c):i},function(i){return r=i,t=i(a),e=i(o),n=t===e?0:1/(e-t),c}}function Dg(t,e){return e.domain(t.domain()).interpolator(t.interpolator()).clamp(t.clamp()).unknown(t.unknown())}function Mg(){var t=lg(Ig()(rg));return t.copy=function(){return Dg(t,Mg())},qp.apply(t,arguments)}function Rg(){var t=bg(Ig()).domain([1,10]);return t.copy=function(){return Dg(t,Rg()).base(t.base())},qp.apply(t,arguments)}function Fg(){var t=_g(Ig());return t.copy=function(){return Dg(t,Fg()).constant(t.constant())},qp.apply(t,arguments)}function jg(){var t=Ag(Ig());return t.copy=function(){return Dg(t,jg()).exponent(t.exponent())},qp.apply(t,arguments)}function Pg(){return jg.apply(null,arguments).exponent(.5)}function Lg(){var t,e,n,r,i,a,o,s=0,u=.5,c=1,l=1,f=rg,d=!1;function h(t){return isNaN(t=+t)?o:(t=.5+((t=+a(t))-e)*(l*t<l*e?r:i),f(d?Math.max(0,Math.min(1,t)):t))}function p(t){return function(e){var n,r,i;return arguments.length?([n,r,i]=e,f=Qm(t,[n,r,i]),h):[f(0),f(.5),f(1)]}}return h.domain=function(o){return arguments.length?([s,u,c]=o,t=a(s=+s),e=a(u=+u),n=a(c=+c),r=t===e?0:.5/(e-t),i=e===n?0:.5/(n-e),l=e<t?-1:1,h):[s,u,c]},h.clamp=function(t){return arguments.length?(d=!!t,h):d},h.interpolator=function(t){return arguments.length?(f=t,h):f},h.range=p(Jm),h.rangeRound=p(Zm),h.unknown=function(t){return arguments.length?(o=t,h):o},function(o){return a=o,t=o(s),e=o(u),n=o(c),r=t===e?0:.5/(e-t),i=e===n?0:.5/(n-e),l=e<t?-1:1,h}}function zg(){var t=lg(Lg()(rg));return t.copy=function(){return Dg(t,zg())},qp.apply(t,arguments)}function Bg(){var t=bg(Lg()).domain([.1,1,10]);return t.copy=function(){return Dg(t,Bg()).base(t.base())},qp.apply(t,arguments)}function Ug(){var t=_g(Lg());return t.copy=function(){return Dg(t,Ug()).constant(t.constant())},qp.apply(t,arguments)}function Wg(){var t=Ag(Lg());return t.copy=function(){return Dg(t,Wg()).exponent(t.exponent())},qp.apply(t,arguments)}function Vg(){return Wg.apply(null,arguments).exponent(.5)}function qg(){var t,e=[],n=[],r=[];function i(){var t=0,i=Math.max(1,n.length);for(r=new Array(i-1);++t<i;)r[t-1]=ai(e,t/i);return a}function a(e){return isNaN(e=+e)?t:n[Wp(r,e)]}return a.invertExtent=function(t){var i=n.indexOf(t);return i<0?[NaN,NaN]:[i>0?r[i-1]:e[0],i<r.length?r[i]:e[e.length-1]]},a.domain=function(t){if(!arguments.length)return e.slice();e=[];for(let n of t)null==n||isNaN(n=+n)||e.push(n);return e.sort(ti),i()},a.range=function(t){return arguments.length?(n=Array.from(t),i()):n.slice()},a.unknown=function(e){return arguments.length?(t=e,a):t},a.quantiles=function(){return r.slice()},a.copy=function(){return qg().domain(e).range(n).unknown(t)},Vp.apply(a,arguments)}var Hg=1e3,Gg=60*Hg,$g=60*Gg,Kg=24*$g,Xg=7*Kg,Yg=30*Kg,Jg=365*Kg;function Zg(t){return new Date(t)}function Qg(t){return t instanceof Date?+t:+new Date(+t)}function tv(t,e,n,r,i,a,o,s,u){var c=cg(),l=c.invert,f=c.domain,d=u(".%L"),h=u(":%S"),p=u("%I:%M"),m=u("%I %p"),g=u("%a %d"),v=u("%b %d"),y=u("%B"),b=u("%Y"),x=[[o,1,Hg],[o,5,5*Hg],[o,15,15*Hg],[o,30,30*Hg],[a,1,Gg],[a,5,5*Gg],[a,15,15*Gg],[a,30,30*Gg],[i,1,$g],[i,3,3*$g],[i,6,6*$g],[i,12,12*$g],[r,1,Kg],[r,2,2*Kg],[n,1,Xg],[e,1,Yg],[e,3,3*Yg],[t,1,Jg]];function w(s){return(o(s)<s?d:a(s)<s?h:i(s)<s?p:r(s)<s?m:e(s)<s?n(s)<s?g:v:t(s)<s?y:b)(s)}function k(e,n,r){if(null==e&&(e=10),"number"==typeof e){var i,a=Math.abs(r-n)/e,o=os(function(t){return t[2]}).right(x,a);return o===x.length?(i=ds(n/Jg,r/Jg,e),e=t):o?(i=(o=x[a/x[o-1][2]<x[o][2]/a?o-1:o])[1],e=o[0]):(i=Math.max(ds(n,r,e),1),e=s),e.every(i)}return e}return c.invert=function(t){return new Date(l(t))},c.domain=function(t){return arguments.length?f(Array.from(t,Qg)):f().map(Zg)},c.ticks=function(t){var e,n=f(),r=n[0],i=n[n.length-1],a=i<r;return a&&(e=r,r=i,i=e),e=(e=k(t,r,i))?e.range(r,i+1):[],a?e.reverse():e},c.tickFormat=function(t,e){return null==e?w:u(e)},c.nice=function(t){var e=f();return(t=k(t,e[0],e[e.length-1]))?f(dg(e,t)):c},c.copy=function(){return sg(c,tv(t,e,n,r,i,a,o,s,u))},c}var ev=function(){return Vp.apply(tv(Ce,Po,Ue,Xe,zo,Vo,$o,Uo,nn).domain([new Date(2e3,0,1),new Date(2e3,0,2)]),arguments)},nv=function(){return Vp.apply(tv(Je,Fo,Ie,ze,Ho,Xo,$o,Uo,an).domain([Date.UTC(2e3,0,1),Date.UTC(2e3,0,2)]),arguments)};function rv(){var t,e=0,n=1,r=1,i=[.5],a=[0,1];function o(e){return e<=e?a[Wp(i,e,0,r)]:t}function s(){var t=-1;for(i=new Array(r);++t<r;)i[t]=((t+1)*n-(t-r)*e)/(r+1);return o}return o.domain=function(t){return arguments.length?([e,n]=t,e=+e,n=+n,s()):[e,n]},o.range=function(t){return arguments.length?(r=(a=Array.from(t)).length-1,s()):a.slice()},o.invertExtent=function(t){var o=a.indexOf(t);return o<0?[NaN,NaN]:o<1?[e,i[0]]:o>=r?[i[r-1],n]:[i[o-1],i[o]]},o.unknown=function(e){return arguments.length?(t=e,o):o},o.thresholds=function(){return i.slice()},o.copy=function(){return rv().domain([e,n]).range(a).unknown(t)},Vp.apply(lg(o),arguments)}function iv(t){var e;function n(t){return isNaN(t=+t)?e:t}return n.invert=n,n.domain=n.range=function(e){return arguments.length?(t=Array.from(e,eg),n):t.slice()},n.unknown=function(t){return arguments.length?(e=t,n):e},n.copy=function(){return iv(t).unknown(e)},t=arguments.length?Array.from(t,eg):[0,1],lg(n)}const av={};function ov(t,e,n){return arguments.length>1?(av[t]=function(t,e,n){const r=function(){var n=e();return n.invertRange||(n.invertRange=n.invert?Pp(n):n.invertExtent?Lp(n):void 0),n.type=t,n};return r.metadata=Object(ct.Da)(Object(ct.i)(n)),r}(t,e,n),this):function(t){return Object(ct.v)(av,t)}(t)?av[t]:void 0}function sv(t,e){const n=av[t];return n&&n.metadata[e]}function uv(t){return sv(t,Dp)}function cv(t){return sv(t,vp)}function lv(t){return sv(t,Fp)}ov("identity",iv),ov(gp,fg,Dp),ov(vp,xg,[Dp,vp]),ov(yp,Ng,Dp),ov(bp,Tg,Dp),ov(xp,Eg,Dp),ov(wp,ev,[Dp,jp]),ov(kp,nv,[Dp,jp]),ov(_p,Mg,[Dp,Fp]),ov(`${_p}-${gp}`,Mg,[Dp,Fp]),ov(`${_p}-${vp}`,Rg,[Dp,Fp,vp]),ov(`${_p}-${yp}`,jg,[Dp,Fp]),ov(`${_p}-${bp}`,Pg,[Dp,Fp]),ov(`${_p}-${xp}`,Fg,[Dp,Fp]),ov(`${Ep}-${gp}`,zg,[Dp,Fp]),ov(`${Ep}-${vp}`,Bg,[Dp,Fp,vp]),ov(`${Ep}-${yp}`,Wg,[Dp,Fp]),ov(`${Ep}-${bp}`,Vg,[Dp,Fp]),ov(`${Ep}-${xp}`,Ug,[Dp,Fp]),ov(Op,qg,[Rp,Op]),ov(Sp,rv,Rp),ov(Cp,Zp,Rp),ov(Ip,function t(){var e=[],n=[];function r(t){return null==t||t!=t?void 0:n[(Wp(e,t)-1)%n.length]}return r.domain=function(t){return arguments.length?(e=function(t){return Yp.call(t,function(t){return+t})}(t),r):e.slice()},r.range=function(t){return arguments.length?(n=Jp.call(t),r):n.slice()},r.tickFormat=function(t,n){return Xp(e[0],Object(ct.U)(e),null==t?10:t,n)},r.copy=function(){return t().domain(r.domain()).range(r.range())},r},[Mp,Rp]),ov(Ap,Gp,Mp),ov(Tp,$p,Mp),ov(Np,function(){return function t(e){var n=e.copy;return e.padding=e.paddingOuter,delete e.paddingInner,e.copy=function(){return t(n())},e}($p().paddingInner(1))},Mp);var fv,dv,hv,pv,mv=function(t){var e=t.length;return function(n){return t[Math.max(0,Math.min(e-1,Math.floor(n*e)))]}},gv=function(t,e){var n=Rm(+t,+e);return function(t){var e=n(t);return e-360*Math.floor(e/360)}},vv=180/Math.PI,yv={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1},bv=function(t,e,n,r,i,a){var o,s,u;return(o=Math.sqrt(t*t+e*e))&&(t/=o,e/=o),(u=t*n+e*r)&&(n-=t*u,r-=e*u),(s=Math.sqrt(n*n+r*r))&&(n/=s,r/=s,u/=s),t*r<e*n&&(t=-t,e=-e,u=-u,o=-o),{translateX:i,translateY:a,rotate:Math.atan2(e,t)*vv,skewX:Math.atan(u)*vv,scaleX:o,scaleY:s}};function xv(t,e,n,r){function i(t){return t.length?t.pop()+" ":""}return function(a,o){var s=[],u=[];return a=t(a),o=t(o),function(t,r,i,a,o,s){if(t!==i||r!==a){var u=o.push("translate(",null,e,null,n);s.push({i:u-4,x:Gm(t,i)},{i:u-2,x:Gm(r,a)})}else(i||a)&&o.push("translate("+i+e+a+n)}(a.translateX,a.translateY,o.translateX,o.translateY,s,u),function(t,e,n,a){t!==e?(t-e>180?e+=360:e-t>180&&(t+=360),a.push({i:n.push(i(n)+"rotate(",null,r)-2,x:Gm(t,e)})):e&&n.push(i(n)+"rotate("+e+r)}(a.rotate,o.rotate,s,u),function(t,e,n,a){t!==e?a.push({i:n.push(i(n)+"skewX(",null,r)-2,x:Gm(t,e)}):e&&n.push(i(n)+"skewX("+e+r)}(a.skewX,o.skewX,s,u),function(t,e,n,r,a,o){if(t!==n||e!==r){var s=a.push(i(a)+"scale(",null,",",null,")");o.push({i:s-4,x:Gm(t,n)},{i:s-2,x:Gm(e,r)})}else 1===n&&1===r||a.push(i(a)+"scale("+n+","+r+")")}(a.scaleX,a.scaleY,o.scaleX,o.scaleY,s,u),a=o=null,function(t){for(var e,n=-1,r=u.length;++n<r;)s[(e=u[n]).i]=e.x(t);return s.join("")}}}var wv=xv(function(t){return"none"===t?yv:(fv||(fv=document.createElement("DIV"),dv=document.documentElement,hv=document.defaultView),fv.style.transform=t,t=hv.getComputedStyle(dv.appendChild(fv),null).getPropertyValue("transform"),dv.removeChild(fv),t=t.slice(7,-1).split(","),bv(+t[0],+t[1],+t[2],+t[3],+t[4],+t[5]))},"px, ","px)","deg)"),kv=xv(function(t){return null==t?yv:(pv||(pv=document.createElementNS("http://www.w3.org/2000/svg","g")),pv.setAttribute("transform",t),(t=pv.transform.baseVal.consolidate())?(t=t.matrix,bv(t.a,t.b,t.c,t.d,t.e,t.f)):yv)},", ",")",")"),_v=Math.SQRT2;function Ev(t){return((t=Math.exp(t))+1/t)/2}var Ov=function(t,e){var n,r,i=t[0],a=t[1],o=t[2],s=e[0],u=e[1],c=e[2],l=s-i,f=u-a,d=l*l+f*f;if(d<1e-12)r=Math.log(c/o)/_v,n=function(t){return[i+t*l,a+t*f,o*Math.exp(_v*t*r)]};else{var h=Math.sqrt(d),p=(c*c-o*o+4*d)/(2*o*2*h),m=(c*c-o*o-4*d)/(2*c*2*h),g=Math.log(Math.sqrt(p*p+1)-p),v=Math.log(Math.sqrt(m*m+1)-m);r=(v-g)/_v,n=function(t){var e=t*r,n=Ev(g),s=o/(2*h)*(n*function(t){return((t=Math.exp(2*t))-1)/(t+1)}(_v*e+g)-function(t){return((t=Math.exp(t))-1/t)/2}(g));return[i+s*l,a+s*f,o*n/Ev(_v*e+g)]}}return n.duration=1e3*r,n};function Sv(t){return function(e,n){var r=t((e=Sm(e)).h,(n=Sm(n)).h),i=jm(e.s,n.s),a=jm(e.l,n.l),o=jm(e.opacity,n.opacity);return function(t){return e.h=r(t),e.s=i(t),e.l=a(t),e.opacity=o(t),e+""}}}var Cv=Sv(Rm),Av=Sv(jm),Nv=Math.PI/180,Tv=180/Math.PI,Iv=.96422,Dv=1,Mv=.82521,Rv=4/29,Fv=6/29,jv=3*Fv*Fv,Pv=Fv*Fv*Fv;function Lv(t){if(t instanceof Bv)return new Bv(t.l,t.a,t.b,t.opacity);if(t instanceof $v)return Kv(t);t instanceof xm||(t=ym(t));var e,n,r=qv(t.r),i=qv(t.g),a=qv(t.b),o=Uv((.2225045*r+.7168786*i+.0606169*a)/Dv);return r===i&&i===a?e=n=o:(e=Uv((.4360747*r+.3850649*i+.1430804*a)/Iv),n=Uv((.0139322*r+.0971045*i+.7141733*a)/Mv)),new Bv(116*o-16,500*(e-o),200*(o-n),t.opacity)}function zv(t,e,n,r){return 1===arguments.length?Lv(t):new Bv(t,e,n,null==r?1:r)}function Bv(t,e,n,r){this.l=+t,this.a=+e,this.b=+n,this.opacity=+r}function Uv(t){return t>Pv?Math.pow(t,1/3):t/jv+Rv}function Wv(t){return t>Fv?t*t*t:jv*(t-Rv)}function Vv(t){return 255*(t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055)}function qv(t){return(t/=255)<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4)}function Hv(t){if(t instanceof $v)return new $v(t.h,t.c,t.l,t.opacity);if(t instanceof Bv||(t=Lv(t)),0===t.a&&0===t.b)return new $v(NaN,0<t.l&&t.l<100?0:NaN,t.l,t.opacity);var e=Math.atan2(t.b,t.a)*Tv;return new $v(e<0?e+360:e,Math.sqrt(t.a*t.a+t.b*t.b),t.l,t.opacity)}function Gv(t,e,n,r){return 1===arguments.length?Hv(t):new $v(t,e,n,null==r?1:r)}function $v(t,e,n,r){this.h=+t,this.c=+e,this.l=+n,this.opacity=+r}function Kv(t){if(isNaN(t.h))return new Bv(t.l,0,0,t.opacity);var e=t.h*Nv;return new Bv(t.l,Math.cos(e)*t.c,Math.sin(e)*t.c,t.opacity)}function Xv(t,e){var n=jm((t=zv(t)).l,(e=zv(e)).l),r=jm(t.a,e.a),i=jm(t.b,e.b),a=jm(t.opacity,e.opacity);return function(e){return t.l=n(e),t.a=r(e),t.b=i(e),t.opacity=a(e),t+""}}function Yv(t){return function(e,n){var r=t((e=Gv(e)).h,(n=Gv(n)).h),i=jm(e.c,n.c),a=jm(e.l,n.l),o=jm(e.opacity,n.opacity);return function(t){return e.h=r(t),e.c=i(t),e.l=a(t),e.opacity=o(t),e+""}}}Qp(Bv,zv,tm(em,{brighter:function(t){return new Bv(this.l+18*(null==t?1:t),this.a,this.b,this.opacity)},darker:function(t){return new Bv(this.l-18*(null==t?1:t),this.a,this.b,this.opacity)},rgb:function(){var t=(this.l+16)/116,e=isNaN(this.a)?t:t+this.a/500,n=isNaN(this.b)?t:t-this.b/200;return new xm(Vv(3.1338561*(e=Iv*Wv(e))-1.6168667*(t=Dv*Wv(t))-.4906146*(n=Mv*Wv(n))),Vv(-.9787684*e+1.9161415*t+.033454*n),Vv(.0719453*e-.2289914*t+1.4052427*n),this.opacity)}})),Qp($v,Gv,tm(em,{brighter:function(t){return new $v(this.h,this.c,this.l+18*(null==t?1:t),this.opacity)},darker:function(t){return new $v(this.h,this.c,this.l-18*(null==t?1:t),this.opacity)},rgb:function(){return Kv(this).rgb()}}));var Jv=Yv(Rm),Zv=Yv(jm),Qv=-.29227,ty=-.90649,ey=1.97294,ny=ey*ty,ry=1.78277*ey,iy=1.78277*Qv- -.14861*ty;function ay(t,e,n,r){return 1===arguments.length?function(t){if(t instanceof oy)return new oy(t.h,t.s,t.l,t.opacity);t instanceof xm||(t=ym(t));var e=t.r/255,n=t.g/255,r=t.b/255,i=(iy*r+ny*e-ry*n)/(iy+ny-ry),a=r-i,o=(ey*(n-i)-Qv*a)/ty,s=Math.sqrt(o*o+a*a)/(ey*i*(1-i)),u=s?Math.atan2(o,a)*Tv-120:NaN;return new oy(u<0?u+360:u,s,i,t.opacity)}(t):new oy(t,e,n,null==r?1:r)}function oy(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}function sy(t){return function e(n){function r(e,r){var i=t((e=ay(e)).h,(r=ay(r)).h),a=jm(e.s,r.s),o=jm(e.l,r.l),s=jm(e.opacity,r.opacity);return function(t){return e.h=i(t),e.s=a(t),e.l=o(Math.pow(t,n)),e.opacity=s(t),e+""}}return n=+n,r.gamma=e,r}(1)}Qp(oy,ay,tm(em,{brighter:function(t){return t=null==t?1/.7:Math.pow(1/.7,t),new oy(this.h,this.s,this.l*t,this.opacity)},darker:function(t){return t=null==t?.7:Math.pow(.7,t),new oy(this.h,this.s,this.l*t,this.opacity)},rgb:function(){var t=isNaN(this.h)?0:(this.h+120)*Nv,e=+this.l,n=isNaN(this.s)?0:this.s*e*(1-e),r=Math.cos(t),i=Math.sin(t);return new xm(255*(e+n*(-.14861*r+1.78277*i)),255*(e+n*(Qv*r+ty*i)),255*(e+n*(ey*r)),this.opacity)}}));var uy=sy(Rm),cy=sy(jm),ly=function(t,e){for(var n=new Array(e),r=0;r<e;++r)n[r]=t(r/(e-1));return n};const fy=["clamp","base","constant","exponent"];function dy(t,e,n){return Qm(hy(e||"rgb",n),t)}function hy(t,e){var n=a[function(t){return"interpolate"+t.toLowerCase().split("-").map(function(t){return t[0].toUpperCase()+t.slice(1)}).join("")}(t)];return null!=e&&n&&n.gamma?n.gamma(e):n}function py(t){for(var e=t.length/6|0,n=new Array(e),r=0;r<e;)n[r]="#"+t.slice(6*r,6*++r);return n}function my(t,e){for(let n in t)vy(n,e(t[n]))}const gy={};function vy(t,e){return t=t&&t.toLowerCase(),arguments.length>1?(gy[t]=e,this):gy[t]}my({category10:"1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf",category20:"1f77b4aec7e8ff7f0effbb782ca02c98df8ad62728ff98969467bdc5b0d58c564bc49c94e377c2f7b6d27f7f7fc7c7c7bcbd22dbdb8d17becf9edae5",category20b:"393b795254a36b6ecf9c9ede6379398ca252b5cf6bcedb9c8c6d31bd9e39e7ba52e7cb94843c39ad494ad6616be7969c7b4173a55194ce6dbdde9ed6",category20c:"3182bd6baed69ecae1c6dbefe6550dfd8d3cfdae6bfdd0a231a35474c476a1d99bc7e9c0756bb19e9ac8bcbddcdadaeb636363969696bdbdbdd9d9d9",tableau10:"4c78a8f58518e4575672b7b254a24beeca3bb279a2ff9da69d755dbab0ac",tableau20:"4c78a89ecae9f58518ffbf7954a24b88d27ab79a20f2cf5b43989483bcb6e45756ff9d9879706ebab0acd67195fcbfd2b279a2d6a5c99e765fd8b5a5",accent:"7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666",dark2:"1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666",paired:"a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928",pastel1:"fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2",pastel2:"b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc",set1:"e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999",set2:"66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3",set3:"8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f"},py),my({blues:"cfe1f2bed8eca8cee58fc1de74b2d75ba3cf4592c63181bd206fb2125ca40a4a90",greens:"d3eecdc0e6baabdda594d3917bc77d60ba6c46ab5e329a512089430e7735036429",greys:"e2e2e2d4d4d4c4c4c4b1b1b19d9d9d8888887575756262624d4d4d3535351e1e1e",oranges:"fdd8b3fdc998fdb87bfda55efc9244f87f2cf06b18e4580bd14904b93d029f3303",purples:"e2e1efd4d4e8c4c5e0b4b3d6a3a0cc928ec3827cb97566ae684ea25c3696501f8c",reds:"fdc9b4fcb49afc9e80fc8767fa7051f6573fec3f2fdc2a25c81b1db21218970b13",blueGreen:"d5efedc1e8e0a7ddd18bd2be70c6a958ba9144ad77319c5d2089460e7736036429",bluePurple:"ccddecbad0e4a8c2dd9ab0d4919cc98d85be8b6db28a55a6873c99822287730f71",greenBlue:"d3eecec5e8c3b1e1bb9bd8bb82cec269c2ca51b2cd3c9fc7288abd1675b10b60a1",orangeRed:"fddcaffdcf9bfdc18afdad77fb9562f67d53ee6545e24932d32d1ebf130da70403",purpleBlue:"dbdaebc8cee4b1c3de97b7d87bacd15b9fc93a90c01e7fb70b70ab056199045281",purpleBlueGreen:"dbd8eac8cee4b0c3de93b7d872acd1549fc83892bb1c88a3097f8702736b016353",purpleRed:"dcc9e2d3b3d7ce9eccd186c0da6bb2e14da0e23189d91e6fc61159ab07498f023a",redPurple:"fccfccfcbec0faa9b8f98faff571a5ec539ddb3695c41b8aa908808d0179700174",yellowGreen:"e4f4acd1eca0b9e2949ed68880c97c62bb6e47aa5e3297502083440e723b036034",yellowOrangeBrown:"feeaa1fedd84fecc63feb746fca031f68921eb7215db5e0bc54c05ab3d038f3204",yellowOrangeRed:"fee087fed16ffebd59fea849fd903efc7335f9522bee3423de1b20ca0b22af0225",blueOrange:"134b852f78b35da2cb9dcae1d2e5eff2f0ebfce0bafbbf74e8932fc5690d994a07",brownBlueGreen:"704108a0651ac79548e3c78af3e6c6eef1eac9e9e48ed1c74da79e187a72025147",purpleGreen:"5b1667834792a67fb6c9aed3e6d6e8eff0efd9efd5aedda971bb75368e490e5e29",purpleOrange:"4114696647968f83b7b9b4d6dadbebf3eeeafce0bafbbf74e8932fc5690d994a07",redBlue:"8c0d25bf363adf745ef4ae91fbdbc9f2efeed2e5ef9dcae15da2cb2f78b3134b85",redGrey:"8c0d25bf363adf745ef4ae91fcdccbfaf4f1e2e2e2c0c0c0969696646464343434",yellowGreenBlue:"eff9bddbf1b4bde5b594d5b969c5be45b4c22c9ec02182b82163aa23479c1c3185",redYellowBlue:"a50026d4322cf16e43fcac64fedd90faf8c1dcf1ecabd6e875abd04a74b4313695",redYellowGreen:"a50026d4322cf16e43fcac63fedd8df9f7aed7ee8ea4d86e64bc6122964f006837",pinkYellowGreen:"8e0152c0267edd72adf0b3d6faddedf5f3efe1f2cab6de8780bb474f9125276419",spectral:"9e0142d13c4bf0704afcac63fedd8dfbf8b0e0f3a1a9dda269bda94288b55e4fa2",viridis:"440154470e61481a6c482575472f7d443a834144873d4e8a39568c35608d31688e2d708e2a788e27818e23888e21918d1f988b1fa08822a8842ab07f35b77943bf7154c56866cc5d7ad1518fd744a5db36bcdf27d2e21be9e51afde725",magma:"0000040404130b0924150e3720114b2c11603b0f704a107957157e651a80721f817f24828c29819a2e80a8327db6377ac43c75d1426fde4968e95462f1605df76f5cfa7f5efc8f65fe9f6dfeaf78febf84fece91fddea0fcedaffcfdbf",inferno:"0000040403130c0826170c3b240c4f330a5f420a68500d6c5d126e6b176e781c6d86216b932667a12b62ae305cbb3755c73e4cd24644dd513ae65c30ed6925f3771af8850ffb9506fca50afcb519fac62df6d645f2e661f3f484fcffa4",plasma:"0d088723069033059742039d5002a25d01a66a00a87801a88405a7900da49c179ea72198b12a90ba3488c33d80cb4779d35171da5a69e16462e76e5bed7953f2834cf68f44fa9a3dfca636fdb32ffec029fcce25f9dc24f5ea27f0f921",rainbow:"6e40aa883eb1a43db3bf3cafd83fa4ee4395fe4b83ff576eff6659ff7847ff8c38f3a130e2b72fcfcc36bee044aff05b8ff4576ff65b52f6673af27828ea8d1ddfa319d0b81cbecb23abd82f96e03d82e14c6edb5a5dd0664dbf6e40aa",sinebow:"ff4040fc582af47218e78d0bd5a703bfbf00a7d5038de70b72f41858fc2a40ff402afc5818f4720be78d03d5a700bfbf03a7d50b8de71872f42a58fc4040ff582afc7218f48d0be7a703d5bf00bfd503a7e70b8df41872fc2a58ff4040",browns:"eedbbdecca96e9b97ae4a865dc9856d18954c7784cc0673fb85536ad44339f3632",tealBlues:"bce4d89dd3d181c3cb65b3c245a2b9368fae347da0306a932c5985",teals:"bbdfdfa2d4d58ac9c975bcbb61b0af4da5a43799982b8b8c1e7f7f127273006667",warmGreys:"dcd4d0cec5c1c0b8b4b3aaa7a59c9998908c8b827f7e7673726866665c5a59504e",goldGreen:"f4d166d5ca60b6c35c98bb597cb25760a6564b9c533f8f4f33834a257740146c36",goldOrange:"f4d166f8be5cf8aa4cf5983bf3852aef701be2621fd65322c54923b142239e3a26",goldRed:"f4d166f6be59f9aa51fc964ef6834bee734ae56249db5247cf4244c43141b71d3e",lightGreyRed:"efe9e6e1dad7d5cbc8c8bdb9bbaea9cd967ddc7b43e15f19df4011dc000b",lightGreyTeal:"e4eaead6dcddc8ced2b7c2c7a6b4bc64b0bf22a6c32295c11f85be1876bc",lightMulti:"e0f1f2c4e9d0b0de9fd0e181f6e072f6c053f3993ef77440ef4a3c",lightOrange:"f2e7daf7d5baf9c499fab184fa9c73f68967ef7860e8645bde515bd43d5b",lightTealBlue:"e3e9e0c0dccf9aceca7abfc859afc0389fb9328dad2f7ca0276b95255988",darkBlue:"3232322d46681a5c930074af008cbf05a7ce25c0dd38daed50f3faffffff",darkGold:"3c3c3c584b37725e348c7631ae8b2bcfa424ecc31ef9de30fff184ffffff",darkGreen:"3a3a3a215748006f4d048942489e4276b340a6c63dd2d836ffeb2cffffaa",darkMulti:"3737371f5287197d8c29a86995ce3fffe800ffffff",darkRed:"3434347036339e3c38cc4037e75d1eec8620eeab29f0ce32ffeb2c"},t=>dy(py(t)));var yy=function(t,e){if((n=(t=e?t.toExponential(e-1):t.toExponential()).indexOf("e"))<0)return null;var n,r=t.slice(0,n);return[r.length>1?r[0]+r.slice(2):r,+t.slice(n+1)]},by=function(t){return(t=yy(Math.abs(t)))?t[1]:NaN},xy=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function wy(t){if(!(e=xy.exec(t)))throw new Error("invalid format: "+t);var e;return new ky({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}function ky(t){this.fill=void 0===t.fill?" ":t.fill+"",this.align=void 0===t.align?">":t.align+"",this.sign=void 0===t.sign?"-":t.sign+"",this.symbol=void 0===t.symbol?"":t.symbol+"",this.zero=!!t.zero,this.width=void 0===t.width?void 0:+t.width,this.comma=!!t.comma,this.precision=void 0===t.precision?void 0:+t.precision,this.trim=!!t.trim,this.type=void 0===t.type?"":t.type+""}wy.prototype=ky.prototype,ky.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};var _y,Ey,Oy,Sy=function(t){t:for(var e,n=t.length,r=1,i=-1;r<n;++r)switch(t[r]){case".":i=e=r;break;case"0":0===i&&(i=r),e=r;break;default:if(!+t[r])break t;i>0&&(i=0)}return i>0?t.slice(0,i)+t.slice(e+1):t},Cy=function(t,e){var n=yy(t,e);if(!n)return t+"";var r=n[0],i=n[1];return i<0?"0."+new Array(-i).join("0")+r:r.length>i+1?r.slice(0,i+1)+"."+r.slice(i+1):r+new Array(i-r.length+2).join("0")},Ay={"%":function(t,e){return(100*t).toFixed(e)},b:function(t){return Math.round(t).toString(2)},c:function(t){return t+""},d:function(t){return Math.round(t).toString(10)},e:function(t,e){return t.toExponential(e)},f:function(t,e){return t.toFixed(e)},g:function(t,e){return t.toPrecision(e)},o:function(t){return Math.round(t).toString(8)},p:function(t,e){return Cy(100*t,e)},r:Cy,s:function(t,e){var n=yy(t,e);if(!n)return t+"";var r=n[0],i=n[1],a=i-(_y=3*Math.max(-8,Math.min(8,Math.floor(i/3))))+1,o=r.length;return a===o?r:a>o?r+new Array(a-o+1).join("0"):a>0?r.slice(0,a)+"."+r.slice(a):"0."+new Array(1-a).join("0")+yy(t,Math.max(0,e+a-1))[0]},X:function(t){return Math.round(t).toString(16).toUpperCase()},x:function(t){return Math.round(t).toString(16)}},Ny=function(t){return t},Ty=Array.prototype.map,Iy=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"],Dy=function(t){var e=void 0===t.grouping||void 0===t.thousands?Ny:function(t,e){return function(n,r){for(var i=n.length,a=[],o=0,s=t[0],u=0;i>0&&s>0&&(u+s+1>r&&(s=Math.max(1,r-u)),a.push(n.substring(i-=s,i+s)),!((u+=s+1)>r));)s=t[o=(o+1)%t.length];return a.reverse().join(e)}}(Ty.call(t.grouping,Number),t.thousands+""),n=void 0===t.currency?"":t.currency[0]+"",r=void 0===t.currency?"":t.currency[1]+"",i=void 0===t.decimal?".":t.decimal+"",a=void 0===t.numerals?Ny:function(t){return function(e){return e.replace(/[0-9]/g,function(e){return t[+e]})}}(Ty.call(t.numerals,String)),o=void 0===t.percent?"%":t.percent+"",s=void 0===t.minus?"-":t.minus+"",u=void 0===t.nan?"NaN":t.nan+"";function c(t){var c=(t=wy(t)).fill,l=t.align,f=t.sign,d=t.symbol,h=t.zero,p=t.width,m=t.comma,g=t.precision,v=t.trim,y=t.type;"n"===y?(m=!0,y="g"):Ay[y]||(void 0===g&&(g=12),v=!0,y="g"),(h||"0"===c&&"="===l)&&(h=!0,c="0",l="=");var b="$"===d?n:"#"===d&&/[boxX]/.test(y)?"0"+y.toLowerCase():"",x="$"===d?r:/[%p]/.test(y)?o:"",w=Ay[y],k=/[defgprs%]/.test(y);function _(t){var n,r,o,d=b,_=x;if("c"===y)_=w(t)+_,t="";else{var E=(t=+t)<0||1/t<0;if(t=isNaN(t)?u:w(Math.abs(t),g),v&&(t=Sy(t)),E&&0==+t&&"+"!==f&&(E=!1),d=(E?"("===f?f:s:"-"===f||"("===f?"":f)+d,_=("s"===y?Iy[8+_y/3]:"")+_+(E&&"("===f?")":""),k)for(n=-1,r=t.length;++n<r;)if(48>(o=t.charCodeAt(n))||o>57){_=(46===o?i+t.slice(n+1):t.slice(n))+_,t=t.slice(0,n);break}}m&&!h&&(t=e(t,1/0));var O=d.length+t.length+_.length,S=O<p?new Array(p-O+1).join(c):"";switch(m&&h&&(t=e(S+t,S.length?p-_.length:1/0),S=""),l){case"<":t=d+t+_+S;break;case"=":t=d+S+t+_;break;case"^":t=S.slice(0,O=S.length>>1)+d+t+_+S.slice(O);break;default:t=S+d+t+_}return a(t)}return g=void 0===g?6:/[gprs]/.test(y)?Math.max(1,Math.min(21,g)):Math.max(0,Math.min(20,g)),_.toString=function(){return t+""},_}return{format:c,formatPrefix:function(t,e){var n=c(((t=wy(t)).type="f",t)),r=3*Math.max(-8,Math.min(8,Math.floor(by(e)/3))),i=Math.pow(10,-r),a=Iy[8+r/3];return function(t){return n(i*t)+a}}}};!function(t){Ey=Dy(t),Oy=Ey.format,Ey.formatPrefix}({decimal:".",thousands:",",grouping:[3],currency:["$",""],minus:"-"});const My=t=>Object(ct.A)(t)?t.map(t=>String(t)):String(t);function Ry(t,e,n){var r;return Object(ct.E)(e)&&(t.bins&&(e=Math.max(e,t.bins.length)),null!=n&&(e=Math.min(e,~~(Object(ct.X)(t.domain())/n)||1))),Object(ct.F)(e)&&(r=e.step,e=e.interval),Object(ct.H)(e)&&(e=t.type===wp?Zo(e):t.type==kp?Qo(e):Object(ct.n)("Only time and utc scales accept interval strings."),r&&(e=e.every(r))),e}function Fy(t,e,n){var r=t.range(),i=Math.floor(r[0]),a=Math.ceil(Object(ct.U)(r));if(i>a&&(r=a,a=i,i=r),e=e.filter(function(e){return e=t(e),i<=e&&e<=a}),n>0&&e.length>1){for(var o=[e[0],Object(ct.U)(e)];e.length>n&&e.length>=3;)e=e.filter(function(t,e){return!(e%2)});e.length<3&&(e=o)}return e}function jy(t,e){return t.bins?Fy(t,t.bins):t.ticks?t.ticks(e):t.domain()}function Py(t,e,n,r,i){var a=t.type,o=a===wp||r===wp?rs(n):a===kp||r===kp?is(n):t.tickFormat?t.tickFormat(e,n):n?Oy(n):My;if(cv(a)){var s=function(t){var e=wy(t||",");if(null==e.precision){switch(e.precision=12,e.type){case"%":e.precision-=2;break;case"e":e.precision-=1}return function(t,e){return function(n){var r,i,a=t(n),o=a.indexOf(e);if(o<0)return a;for(r=function(t,e){var n,r=t.lastIndexOf("e");if(r>0)return r;for(r=t.length;--r>e;)if((n=t.charCodeAt(r))>=48&&n<=57)return r+1}(a,o),i=r<a.length?a.slice(r):"";--r>o;)if("0"!==a[r]){++r;break}return a.slice(0,r)+i}}(Oy(e),Oy(".1f")(1)[1])}return Oy(e)}(n);o=i||t.bins?s:function(t,e){return n=>t(n)?e(n):""}(o,s)}return o}function Ly(t){Br.call(this,null,t)}function zy(t){Br.call(this,null,t)}function By(){return vt({})}function Uy(t){return t.exit}function Wy(t){Br.call(this,null,t)}Object(ct.y)(Ly,Br).transform=function(t,e){if(this.value&&!t.modified())return e.StopPropagation;var n=e.fork(e.NO_SOURCE|e.NO_FIELDS),r=this.value,i=t.scale,a=Ry(i,null==t.count?t.values?t.values.length:10:t.count,t.minstep),o=t.format||Py(i,a,t.formatSpecifier,t.formatType,!!t.values),s=t.values?Fy(i,t.values,a):jy(i,a);return r&&(n.rem=r),r=s.map(function(t,e){return vt({index:e/(s.length-1||1),value:t,label:o(t)})}),t.extra&&r.length&&r.push(vt({index:-1,extra:{value:r[0].value},label:""})),n.source=r,n.add=r,this.value=r,n},Object(ct.y)(zy,Br).transform=function(t,e){var n=e.dataflow,r=e.fork(e.NO_SOURCE|e.NO_FIELDS),i=t.item||By,a=t.key||mt,o=this.value;return Object(ct.A)(r.encode)&&(r.encode=null),o&&(t.modified("key")||e.modified(a))&&Object(ct.n)("DataJoin does not support modified key function or fields."),o||(e=e.addAll(),this.value=o=Object(ct.s)().test(Uy),o.lookup=function(t){return o.get(a(t))}),e.visit(e.ADD,function(t){var e=a(t),n=o.get(e);n?n.exit?(o.empty--,r.add.push(n)):r.mod.push(n):(o.set(e,n=i(t)),r.add.push(n)),n.datum=t,n.exit=!1}),e.visit(e.MOD,function(t){var e=a(t),n=o.get(e);n&&(n.datum=t,r.mod.push(n))}),e.visit(e.REM,function(t){var e=a(t),n=o.get(e);t!==n.datum||n.exit||(r.rem.push(n),n.exit=!0,++o.empty)}),e.changed(e.ADD_MOD)&&r.modifies("datum"),t.clean&&o.empty>n.cleanThreshold&&n.runAfter(o.clean),r},Object(ct.y)(Wy,Br).transform=function(t,e){var n=e.fork(e.ADD_REM),r=t.mod||!1,i=t.encoders,a=e.encode;if(Object(ct.A)(a)){if(!n.changed()&&!a.every(function(t){return i[t]}))return e.StopPropagation;a=a[0],n.encode=null}var o="enter"===a,s=i.update||ct.r,u=i.enter||ct.r,c=i.exit||ct.r,l=(a&&!o?i[a]:s)||ct.r;if(e.changed(e.ADD)&&(e.visit(e.ADD,function(e){u(e,t),s(e,t)}),n.modifies(u.output),n.modifies(s.output),l!==ct.r&&l!==s&&(e.visit(e.ADD,function(e){l(e,t)}),n.modifies(l.output))),e.changed(e.REM)&&c!==ct.r&&(e.visit(e.REM,function(e){c(e,t)}),n.modifies(c.output)),o||l!==ct.r){var f=e.MOD|(t.modified()?e.REFLOW:0);o?(e.visit(f,function(e){var i=u(e,t)||r;(l(e,t)||i)&&n.mod.push(e)}),n.mod.length&&n.modifies(u.output)):e.visit(f,function(e){(l(e,t)||r)&&n.mod.push(e)}),n.mod.length&&n.modifies(l.output)}return n.changed()?n:e.StopPropagation};var Vy="symbol",qy="discrete";const Hy={[Op]:"quantiles",[Sp]:"thresholds",[Cp]:"domain"},Gy={[Op]:"quantiles",[Sp]:"domain"};function $y(t,e){return t.bins?function(t){const e=t.slice(0,-1);return e.max=Object(ct.U)(t),e}(t.bins):t.type===vp?function(t,e){var n=jy(t,e),r=t.base(),i=Math.log(r),a=Math.max(1,r*e/n.length);return n.filter(t=>{var e=t/Math.pow(r,Math.round(Math.log(t)/i));return e*r<r-.5&&(e*=r),e<=a})}(t,e):Hy[t.type]?function(t){const e=[-1/0].concat(t);return e.max=1/0,e}(t[Hy[t.type]]()):jy(t,e)}function Ky(t,e,n,r,i,a){const o=Gy[t.type]&&i!==wp&&i!==kp?function(t,e){var n,r=t[Gy[t.type]](),i=r.length,a=i>1?r[1]-r[0]:r[0];for(n=1;n<i;++n)a=Math.min(a,r[n]-r[n-1]);return Xp(0,a,30,e)}(t,r):Py(t,e,r,i,a);return n===Vy&&function(t){return Hy[t.type]||t.bins}(t)?function(t){return function(e,n,r){var i=Xy(r[n+1],Xy(r.max,1/0)),a=Yy(e,t),o=Yy(i,t);return a&&o?a+" – "+o:o?"< "+o:"≥ "+a}}(o):n===qy?function(t){return function(e,n){return n?t(e):null}}(o):function(t){return function(e){return t(e)}}(o)}function Xy(t,e){return null!=t?t:e}function Yy(t,e){return Number.isFinite(t)?e(t):null}function Jy(t){Br.call(this,[],t)}Object(ct.y)(Jy,Br).transform=function(t,e){if(null!=this.value&&!t.modified())return e.StopPropagation;var n,r,i,a,o,s=e.fork(e.NO_SOURCE|e.NO_FIELDS),u=this.value,c=t.type||Vy,l=t.scale,f=+t.limit,d=Ry(l,null==t.count?5:t.count,t.minstep),h=!!t.values||c===Vy,p=t.format||Ky(l,d,c,t.formatSpecifier,t.formatType,h),m=t.values||$y(l,d);return u&&(s.rem=u),c===Vy?(f&&m.length>f?(e.dataflow.warn("Symbol legend count exceeds limit, filtering items."),u=m.slice(0,f-1),o=!0):u=m,Object(ct.D)(i=t.size)?(t.values||0!==l(u[0])||(u=u.slice(1)),a=u.reduce(function(e,n){return Math.max(e,i(n,t))},0)):i=Object(ct.l)(a=i||8),u=u.map(function(e,n){return vt({index:n,label:p(e,n,u),value:e,offset:a,size:i(e,t)})}),o&&(o=m[u.length],u.push(vt({index:u.length,label:`…${m.length-u.length} entries`,value:o,offset:a,size:i(o,t)})))):"gradient"===c?(n=l.domain(),r=function(t,e,n){var r,i,a,o=n-e;return o&&Number.isFinite(o)?(r=(i=t.type).indexOf("-"),i=r<0?i:i.slice(r+1),a=ov(i)().domain([e,n]).range([0,1]),fy.forEach(e=>t[e]?a[e](t[e]()):0),a):Object(ct.l)(.5)}(l,n[0],Object(ct.U)(n)),m.length<3&&!t.values&&n[0]!==Object(ct.U)(n)&&(m=[n[0],Object(ct.U)(n)]),u=m.map(function(t,e){return vt({index:e,label:p(t,e,m),value:t,perc:r(t)})})):(i=m.length-1,r=function(t){var e=t.domain(),n=e.length-1,r=+e[0],i=+Object(ct.U)(e),a=i-r;if(t.type===Cp){var o=n?a/n:.1;a=(i+=o)-(r-=o)}return function(t){return(t-r)/a}}(l),u=m.map(function(t,e){return vt({index:e,label:p(t,e,m),value:t,perc:e?r(t):0,perc2:e===i?1:r(m[e+1])})})),s.source=u,s.add=u,this.value=u,s};var Zy=Object(ct.s)({line:ib,"line-radial":function(t,e,n,r){return ib(e*Math.cos(t),e*Math.sin(t),r*Math.cos(n),r*Math.sin(n))},arc:ab,"arc-radial":function(t,e,n,r){return ab(e*Math.cos(t),e*Math.sin(t),r*Math.cos(n),r*Math.sin(n))},curve:ob,"curve-radial":function(t,e,n,r){return ob(e*Math.cos(t),e*Math.sin(t),r*Math.cos(n),r*Math.sin(n))},"orthogonal-horizontal":function(t,e,n,r){return"M"+t+","+e+"V"+r+"H"+n},"orthogonal-vertical":function(t,e,n,r){return"M"+t+","+e+"H"+n+"V"+r},"orthogonal-radial":function(t,e,n,r){var i=Math.cos(t),a=Math.sin(t),o=Math.cos(n),s=Math.sin(n),u=Math.abs(n-t)>Math.PI?n<=t:n>t;return"M"+e*i+","+e*a+"A"+e+","+e+" 0 0,"+(u?1:0)+" "+e*o+","+e*s+"L"+r*o+","+r*s},"diagonal-horizontal":function(t,e,n,r){var i=(t+n)/2;return"M"+t+","+e+"C"+i+","+e+" "+i+","+r+" "+n+","+r},"diagonal-vertical":function(t,e,n,r){var i=(e+r)/2;return"M"+t+","+e+"C"+t+","+i+" "+n+","+i+" "+n+","+r},"diagonal-radial":function(t,e,n,r){var i=Math.cos(t),a=Math.sin(t),o=Math.cos(n),s=Math.sin(n),u=(e+r)/2;return"M"+e*i+","+e*a+"C"+u*i+","+u*a+" "+u*o+","+u*s+" "+r*o+","+r*s}});function Qy(t){return t.source.x}function tb(t){return t.source.y}function eb(t){return t.target.x}function nb(t){return t.target.y}function rb(t){Br.call(this,{},t)}function ib(t,e,n,r){return"M"+t+","+e+"L"+n+","+r}function ab(t,e,n,r){var i=n-t,a=r-e,o=Math.sqrt(i*i+a*a)/2;return"M"+t+","+e+"A"+o+","+o+" "+180*Math.atan2(a,i)/Math.PI+" 0 1 "+n+","+r}function ob(t,e,n,r){var i=n-t,a=r-e,o=.2*(i+a),s=.2*(a-i);return"M"+t+","+e+"C"+(t+o)+","+(e+s)+" "+(n+s)+","+(r-o)+" "+n+","+r}function sb(t,e){let n=0;if(void 0===e)for(let e of t)(e=+e)&&(n+=e);else{let r=-1;for(let i of t)(i=+e(i,++r,t))&&(n+=i)}return n}function ub(t){Br.call(this,null,t)}rb.Definition={type:"LinkPath",metadata:{modifies:!0},params:[{name:"sourceX",type:"field",default:"source.x"},{name:"sourceY",type:"field",default:"source.y"},{name:"targetX",type:"field",default:"target.x"},{name:"targetY",type:"field",default:"target.y"},{name:"orient",type:"enum",default:"vertical",values:["horizontal","vertical","radial"]},{name:"shape",type:"enum",default:"line",values:["line","arc","curve","diagonal","orthogonal"]},{name:"require",type:"signal"},{name:"as",type:"string",default:"path"}]},Object(ct.y)(rb,Br).transform=function(t,e){var n=t.sourceX||Qy,r=t.sourceY||tb,i=t.targetX||eb,a=t.targetY||nb,o=t.as||"path",s=t.orient||"vertical",u=t.shape||"line",c=Zy.get(u+"-"+s)||Zy.get(u);return c||Object(ct.n)("LinkPath unsupported type: "+t.shape+(t.orient?"-"+t.orient:"")),e.visit(e.SOURCE,function(t){t[o]=c(n(t),r(t),i(t),a(t))}),e.reflow(t.modified()).modifies(o)},ub.Definition={type:"Pie",metadata:{modifies:!0},params:[{name:"field",type:"field"},{name:"startAngle",type:"number",default:0},{name:"endAngle",type:"number",default:6.283185307179586},{name:"sort",type:"boolean",default:!1},{name:"as",type:"string",array:!0,length:2,default:["startAngle","endAngle"]}]},Object(ct.y)(ub,Br).transform=function(t,e){var n,r,i,a=t.as||["startAngle","endAngle"],o=a[0],s=a[1],u=t.field||ct.O,c=t.startAngle||0,l=null!=t.endAngle?t.endAngle:2*Math.PI,f=e.source,d=f.map(u),h=d.length,p=c,m=(l-c)/sb(d),g=ro(h);for(t.sort&&g.sort(function(t,e){return d[t]-d[e]}),n=0;n<h;++n)i=d[g[n]],(r=f[g[n]])[o]=p,r[s]=p+=i*m;return this.value=d,e.reflow(t.modified()).modifies(a)};var cb=5;function lb(t){return uv(t)&&t!==_p}var fb=Object(ct.Da)(["set","modified","clear","type","scheme","schemeExtent","schemeCount","domain","domainMin","domainMid","domainMax","domainRaw","domainImplicit","nice","zero","bins","range","rangeStep","round","reverse","interpolate","interpolateGamma"]);function db(t){Br.call(this,null,t),this.modified(!0)}function hb(t,e,n){cv(t)&&(Math.abs(e.reduce(function(t,e){return t+(e<0?-1:e>0?1:0)},0))!==e.length&&n.warn("Log scale domain includes zero: "+Object(ct.Z)(e)));return e}function pb(t,e,n){return Object(ct.D)(t)&&(e||n)?function(t,e){var n=e[0],r=Object(ct.U)(e)-n;return function(e){return t(n+e*r)}}(t,mb(e||[0,1],n)):t}function mb(t,e){return e?t.slice().reverse():t}function gb(t){Br.call(this,null,t)}Object(ct.y)(db,Br).transform=function(t,e){var n=e.dataflow,r=this.value,i=function(t){var e,n=t.type,r="";if(n===_p)return _p+"-"+gp;(function(t){const e=t.type;return uv(e)&&e!==wp&&e!==kp&&(t.scheme||t.range&&t.range.length&&t.range.every(ct.H))})(t)&&(e=t.rawDomain?t.rawDomain.length:t.domain?t.domain.length+ +(null!=t.domainMid):0,r=2===e?_p+"-":3===e?Ep+"-":"");return(r+n||gp).toLowerCase()}(t);for(i in r&&i===r.type||(this.value=r=ov(i)()),t)if(!fb[i]){if("padding"===i&&lb(r.type))continue;Object(ct.D)(r[i])?r[i](t[i]):n.warn("Unsupported scale property: "+i)}return function(t,e,n){var r=t.type,i=e.round||!1,a=e.range;if(null!=e.rangeStep)a=function(t,e,n){t!==Tp&&t!==Np&&Object(ct.n)("Only band and point scales support rangeStep.");var r=(null!=e.paddingOuter?e.paddingOuter:e.padding)||0,i=t===Np?1:(null!=e.paddingInner?e.paddingInner:e.padding)||0;return[0,e.rangeStep*mp(n,i,r)]}(r,e,n);else if(e.scheme&&(a=function(t,e,n){var r,i,a=e.schemeExtent;Object(ct.A)(e.scheme)?i=dy(e.scheme,e.interpolate,e.interpolateGamma):(r=e.scheme.toLowerCase(),(i=vy(r))||Object(ct.n)(`Unrecognized scheme name: ${e.scheme}`));return n=t===Cp?n+1:t===Ip?n-1:t===Op||t===Sp?+e.schemeCount||cb:n,lv(t)?pb(i,a,e.reverse):Object(ct.D)(i)?function(t,e){for(var n=new Array(e),r=e+1,i=0;i<e;)n[i]=t(++i/r);return n}(pb(i,a),n):t===Ap?i:i.slice(0,n)}(r,e,n),Object(ct.D)(a))){if(t.interpolator)return t.interpolator(a);Object(ct.n)(`Scale type ${r} does not support interpolating color schemes.`)}if(a&&lv(r))return t.interpolator(dy(mb(a,e.reverse),e.interpolate,e.interpolateGamma));a&&e.interpolate&&t.interpolate?t.interpolate(hy(e.interpolate,e.interpolateGamma)):Object(ct.D)(t.round)?t.round(i):Object(ct.D)(t.rangeRound)&&t.interpolate(i?Zm:Jm);a&&t.range(mb(a,e.reverse))}(r,t,function(t,e,n){let r=e.bins;if(r&&!Object(ct.A)(r)){let e=t.domain(),n=e[0],i=Object(ct.U)(e),a=null==r.start?n:r.start,o=null==r.stop?i:r.stop,s=r.step;s||Object(ct.n)("Scale bins parameter missing step property."),a<n&&(a=s*Math.ceil(n/s)),o>i&&(o=s*Math.floor(i/s)),r=ro(a,o+s/2,s)}r?t.bins=r:t.bins&&delete t.bins;t.type===Ip&&(r?e.domain||e.domainRaw||(t.domain(r),n=r.length):t.bins=t.domain());return n}(r,t,function(t,e,n){var r=function(t,e,n){return e?(t.domain(hb(t.type,e,n)),e.length):-1}(t,e.domainRaw,n);if(r>-1)return r;var i,a,o=e.domain,s=t.type,u=e.zero||void 0===e.zero&&function(t){const e=t.type;return!t.bins&&(e===gp||e===yp||e===bp)}(t);if(!o)return 0;lb(s)&&e.padding&&o[0]!==Object(ct.U)(o)&&(o=function(t,e,n,r,i,a){var o=Math.abs(Object(ct.U)(n)-n[0]),s=o/(o-2*r),u=t===vp?Object(ct.Ma)(e,null,s):t===bp?Object(ct.Na)(e,null,s,.5):t===yp?Object(ct.Na)(e,null,s,i||1):t===xp?Object(ct.Oa)(e,null,s,a||1):Object(ct.La)(e,null,s);return(e=e.slice())[0]=u[0],e[e.length-1]=u[1],e}(s,o,e.range,e.padding,e.exponent,e.constant));(u||null!=e.domainMin||null!=e.domainMax||null!=e.domainMid)&&(i=(o=o.slice()).length-1||1,u&&(o[0]>0&&(o[0]=0),o[i]<0&&(o[i]=0)),null!=e.domainMin&&(o[0]=e.domainMin),null!=e.domainMax&&(o[i]=e.domainMax),null!=e.domainMid&&(((a=e.domainMid)<o[0]||a>o[i])&&n.warn("Scale domainMid exceeds domain min or max.",a),o.splice(i,0,a)));t.domain(hb(s,o,n)),s===Ap&&t.unknown(e.domainImplicit?Hp:void 0);e.nice&&t.nice&&t.nice(!0!==e.nice&&Ry(t,e.nice)||null);return o.length}(r,t,n))),e.fork(e.NO_SOURCE|e.NO_FIELDS)},Object(ct.y)(gb,Br).transform=function(t,e){var n=t.modified("sort")||e.changed(e.ADD)||e.modified(t.sort.fields)||e.modified("datum");return n&&e.source.sort(wt(t.sort)),this.modified(n),e};var vb=["y0","y1"];function yb(t){Br.call(this,null,t)}function bb(t,e,n,r,i){for(var a,o=(e-t.sum)/2,s=t.length,u=0;u<s;++u)(a=t[u])[r]=o,a[i]=o+=Math.abs(n(a))}function xb(t,e,n,r,i){for(var a,o=1/t.sum,s=0,u=t.length,c=0,l=0;c<u;++c)(a=t[c])[r]=s,a[i]=s=o*(l+=Math.abs(n(a)))}function wb(t,e,n,r,i){for(var a,o,s=0,u=0,c=t.length,l=0;l<c;++l)(a=+n(o=t[l]))<0?(o[r]=u,o[i]=u+=a):(o[r]=s,o[i]=s+=a)}function kb(){}yb.Definition={type:"Stack",metadata:{modifies:!0},params:[{name:"field",type:"field"},{name:"groupby",type:"field",array:!0},{name:"sort",type:"compare"},{name:"offset",type:"enum",default:"zero",values:["zero","center","normalize"]},{name:"as",type:"string",array:!0,length:2,default:vb}]},Object(ct.y)(yb,Br).transform=function(t,e){var n,r,i,a,o=t.as||vb,s=o[0],u=o[1],c=wt(t.sort),l=t.field||ct.O,f="center"===t.offset?bb:"normalize"===t.offset?xb:wb;for(n=function(t,e,n,r){var i,a,o,s,u,c,l,f,d,h=[],p=function(t){return t(u)};if(null==e)h.push(t.slice());else for(i={},a=0,o=t.length;a<o;++a)u=t[a],c=e.map(p),(l=i[c])||(i[c]=l=[],h.push(l)),l.push(u);for(c=0,d=0,s=h.length;c<s;++c){for(l=h[c],a=0,f=0,o=l.length;a<o;++a)f+=Math.abs(r(l[a]));l.sum=f,f>d&&(d=f),n&&l.sort(n)}return h.max=d,h}(e.source,t.groupby,c,l),r=0,i=n.length,a=n.max;r<i;++r)f(n[r],a,l,s,u);return e.reflow(t.modified()).modifies(o)};const _b=[[],[[[1,1.5],[.5,1]]],[[[1.5,1],[1,1.5]]],[[[1.5,1],[.5,1]]],[[[1,.5],[1.5,1]]],[[[1,1.5],[.5,1]],[[1,.5],[1.5,1]]],[[[1,.5],[1,1.5]]],[[[1,.5],[.5,1]]],[[[.5,1],[1,.5]]],[[[1,1.5],[1,.5]]],[[[.5,1],[1,.5]],[[1.5,1],[1,1.5]]],[[[1.5,1],[1,.5]]],[[[.5,1],[1.5,1]]],[[[1,1.5],[1.5,1]]],[[[.5,1],[1,1.5]]],[]];var Eb=function(){var t=1,e=1,n=o;function r(t,e){return e.map(e=>i(t,e))}function i(r,i){var o=[],s=[];return function(n,r,i){var o,s,u,c,l,f,d=new Array,h=new Array;o=s=-1,c=n[0]>=r,_b[c<<1].forEach(p);for(;++o<t-1;)u=c,c=n[o+1]>=r,_b[u|c<<1].forEach(p);_b[c<<0].forEach(p);for(;++s<e-1;){for(o=-1,c=n[s*t+t]>=r,l=n[s*t]>=r,_b[c<<1|l<<2].forEach(p);++o<t-1;)u=c,c=n[s*t+t+o+1]>=r,f=l,l=n[s*t+o+1]>=r,_b[u|c<<1|l<<2|f<<3].forEach(p);_b[c|l<<3].forEach(p)}o=-1,l=n[s*t]>=r,_b[l<<2].forEach(p);for(;++o<t-1;)f=l,l=n[s*t+o+1]>=r,_b[l<<2|f<<3].forEach(p);function p(t){var e,n,r=[t[0][0]+o,t[0][1]+s],u=[t[1][0]+o,t[1][1]+s],c=a(r),l=a(u);(e=h[c])?(n=d[l])?(delete h[e.end],delete d[n.start],e===n?(e.ring.push(u),i(e.ring)):d[e.start]=h[n.end]={start:e.start,end:n.end,ring:e.ring.concat(n.ring)}):(delete h[e.end],e.ring.push(u),h[e.end=l]=e):(e=d[l])?(n=h[c])?(delete d[e.start],delete h[n.end],e===n?(e.ring.push(u),i(e.ring)):d[n.start]=h[e.end]={start:n.start,end:e.end,ring:n.ring.concat(e.ring)}):(delete d[e.start],e.ring.unshift(r),d[e.start=c]=e):d[c]=h[l]={start:c,end:l,ring:[r,u]}}_b[l<<3].forEach(p)}(r,i,function(t){n(t,r,i),function(t){var e=0,n=t.length,r=t[n-1][1]*t[0][0]-t[n-1][0]*t[0][1];for(;++e<n;)r+=t[e-1][1]*t[e][0]-t[e-1][0]*t[e][1];return r}(t)>0?o.push([t]):s.push(t)}),s.forEach(function(t){for(var e,n=0,r=o.length;n<r;++n)if(-1!==Ob((e=o[n])[0],t))return void e.push(t)}),{type:"MultiPolygon",value:i,coordinates:o}}function a(e){return 2*e[0]+e[1]*(t+1)*4}function o(n,r,i){n.forEach(function(n){var a,o=n[0],s=n[1],u=0|o,c=0|s,l=r[c*t+u];o>0&&o<t&&u===o&&(a=r[c*t+u-1],n[0]=o+(i-a)/(l-a)-.5),s>0&&s<e&&c===s&&(a=r[(c-1)*t+u],n[1]=s+(i-a)/(l-a)-.5)})}return r.contour=i,r.size=function(n){if(!arguments.length)return[t,e];var i=Math.ceil(n[0]),a=Math.ceil(n[1]);return i>0&&a>0||Object(ct.n)("invalid size"),t=i,e=a,r},r.smooth=function(t){return arguments.length?(n=t?o:kb,r):n===o},r};function Ob(t,e){for(var n,r=-1,i=e.length;++r<i;)if(n=Sb(t,e[r]))return n;return 0}function Sb(t,e){for(var n=e[0],r=e[1],i=-1,a=0,o=t.length,s=o-1;a<o;s=a++){var u=t[a],c=u[0],l=u[1],f=t[s],d=f[0],h=f[1];if(Cb(u,f,e))return 0;l>r!=h>r&&n<(d-c)*(r-l)/(h-l)+c&&(i=-i)}return i}function Cb(t,e,n){var r;return function(t,e,n){return(e[0]-t[0])*(n[1]-t[1])==(n[0]-t[0])*(e[1]-t[1])}(t,e,n)&&function(t,e,n){return t<=e&&e<=n||n<=e&&e<=t}(t[r=+(t[0]===e[0])],n[r],e[r])}var Ab=function(t,e,n){return function(r){var i=Object(ct.p)(r),a=n?Math.min(i[0],0):i[0],o=i[1],s=o-a,u=e?ds(a,o,t):s/(t+1);return ro(u,o,u)}};function Nb(t){Br.call(this,null,t)}function Tb(t,e,n,r,i){const a=t.x1||0,o=t.y1||0,s=e*n<0;function u(t){t.forEach(c)}function c(t){s&&t.reverse(),t.forEach(l)}function l(t){t[0]=(t[0]-a)*e+r,t[1]=(t[1]-o)*n+i}return function(t){return t.coordinates.forEach(u),t}}function Ib(t,e,n){const r=t>=0?t:ui(e,n);return Math.round((Math.sqrt(4*r*r+1)-1)/2)}function Db(t){return Object(ct.D)(t)?t:Object(ct.l)(+t)}Nb.Definition={type:"Isocontour",metadata:{generates:!0},params:[{name:"field",type:"field"},{name:"thresholds",type:"number",array:!0},{name:"levels",type:"number"},{name:"nice",type:"boolean",default:!1},{name:"resolve",type:"enum",values:["shared","independent"],default:"independent"},{name:"zero",type:"boolean",default:!0},{name:"smooth",type:"boolean",default:!0},{name:"scale",type:"number",expr:!0},{name:"translate",type:"number",array:!0,expr:!0},{name:"as",type:"string",null:!0,default:"contour"}]},Object(ct.y)(Nb,Br).transform=function(t,e){if(this.value&&!e.changed()&&!t.modified())return e.StopPropagation;var n=e.fork(e.NO_SOURCE|e.NO_FIELDS),r=e.materialize(e.SOURCE).source,i=t.field||ct.x,a=Eb().smooth(!1!==t.smooth),o=t.thresholds||function(t,e,n){const r=Ab(n.levels||10,n.nice,!1!==n.zero);return"shared"!==n.resolve?r:r(t.map(t=>ei(e(t).values)))}(r,i,t),s=null===t.as?null:t.as||"contour",u=[];return r.forEach(e=>{const n=i(e),r=a.size([n.width,n.height])(n.values,Object(ct.A)(o)?o:o(n.values));!function(t,e,n,r){let i=r.scale||e.scale,a=r.translate||e.translate;Object(ct.D)(i)&&(i=i(n,r));Object(ct.D)(a)&&(a=a(n,r));if((1===i||null==i)&&!a)return;const o=(Object(ct.E)(i)?i:i[0])||1,s=(Object(ct.E)(i)?i:i[1])||1,u=a&&a[0]||0,c=a&&a[1]||0;t.forEach(Tb(e,o,s,u,c))}(r,n,e,t),r.forEach(t=>{u.push(bt(e,vt(null!=s?{[s]:t}:t)))})}),this.value&&(n.rem=this.value),this.value=n.source=n.add=u,n};var Mb=function(){var t=t=>t[0],e=t=>t[1],n=ct.O,r=[-1,-1],i=960,a=500,o=2;function s(s,u){const c=Ib(r[0],s,t)>>o,l=Ib(r[1],s,e)>>o,f=c?c+2:0,d=l?l+2:0,h=2*f+(i>>o),p=2*d+(a>>o),m=new Float32Array(h*p),g=new Float32Array(h*p);let v=m;s.forEach(r=>{const i=f+(+t(r)>>o),a=d+(+e(r)>>o);i>=0&&i<h&&a>=0&&a<p&&(m[i+a*h]+=+n(r))}),c>0&&l>0?(Rb(h,p,m,g,c),Fb(h,p,g,m,l),Rb(h,p,m,g,c),Fb(h,p,g,m,l),Rb(h,p,m,g,c),Fb(h,p,g,m,l)):c>0?(Rb(h,p,m,g,c),Rb(h,p,g,m,c),Rb(h,p,m,g,c),v=g):l>0&&(Fb(h,p,m,g,l),Fb(h,p,g,m,l),Fb(h,p,m,g,l),v=g);let y=u?Math.pow(2,-2*o):1/sb(v);for(let t=0,e=h*p;t<e;++t)v[t]*=y;return{values:v,scale:1<<o,width:h,height:p,x1:f,y1:d,x2:f+(i>>o),y2:d+(a>>o)}}return s.x=function(e){return arguments.length?(t=Db(e),s):t},s.y=function(t){return arguments.length?(e=Db(t),s):e},s.weight=function(t){return arguments.length?(n=Db(t),s):n},s.size=function(t){if(!arguments.length)return[i,a];var e=Math.ceil(t[0]),n=Math.ceil(t[1]);return e>=0||e>=0||Object(ct.n)("invalid size"),i=e,a=n,s},s.cellSize=function(t){return arguments.length?((t=+t)>=1||Object(ct.n)("invalid cell size"),o=Math.floor(Math.log(t)/Math.LN2),s):1<<o},s.bandwidth=function(t){return arguments.length?(1===(t=Object(ct.i)(t)).length&&(t=[+t[0],+t[0]]),2!==t.length&&Object(ct.n)("invalid bandwidth"),r=t,s):r},s};function Rb(t,e,n,r,i){const a=1+(i<<1);for(let o=0;o<e;++o)for(let e=0,s=0;e<t+i;++e)e<t&&(s+=n[e+o*t]),e>=i&&(e>=a&&(s-=n[e-a+o*t]),r[e-i+o*t]=s/Math.min(e+1,t-1+a-e,a))}function Fb(t,e,n,r,i){const a=1+(i<<1);for(let o=0;o<t;++o)for(let s=0,u=0;s<e+i;++s)s<e&&(u+=n[o+s*t]),s>=i&&(s>=a&&(u-=n[o+(s-a)*t]),r[o+(s-i)*t]=u/Math.min(s+1,e-1+a-s,a))}function jb(t){Br.call(this,null,t)}jb.Definition={type:"KDE2D",metadata:{generates:!0},params:[{name:"size",type:"number",array:!0,length:2,required:!0},{name:"x",type:"field",required:!0},{name:"y",type:"field",required:!0},{name:"weight",type:"field"},{name:"groupby",type:"field",array:!0},{name:"cellSize",type:"number"},{name:"bandwidth",type:"number",array:!0,length:2},{name:"counts",type:"boolean",default:!1},{name:"as",type:"string",default:"grid"}]};const Pb=["x","y","weight","size","cellSize","bandwidth"];function Lb(t,e){return Pb.forEach(n=>null!=e[n]?t[n](e[n]):0),t}function zb(t){Br.call(this,null,t)}Object(ct.y)(jb,Br).transform=function(t,e){if(this.value&&!e.changed()&&!t.modified())return e.StopPropagation;var n,r=e.fork(e.NO_SOURCE|e.NO_FIELDS),i=function(t,e){var n,r,i,a,o,s,u=[],c=t=>t(a);if(null==e)u.push(t);else for(n={},r=0,i=t.length;r<i;++r)a=t[r],o=e.map(c),(s=n[o])||(n[o]=s=[],s.dims=o,u.push(s)),s.push(a);return u}(e.materialize(e.SOURCE).source,t.groupby),a=(t.groupby||[]).map(ct.h),o=Lb(Mb(),t),s=t.as||"grid";return n=i.map(e=>vt(function(t,e){for(let n=0;n<a.length;++n)t[a[n]]=e[n];return t}({[s]:o(e,t.counts)},e.dims))),this.value&&(r.rem=this.value),this.value=r.source=r.add=n,r},zb.Definition={type:"Contour",metadata:{generates:!0},params:[{name:"size",type:"number",array:!0,length:2,required:!0},{name:"values",type:"number",array:!0},{name:"x",type:"field"},{name:"y",type:"field"},{name:"weight",type:"field"},{name:"cellSize",type:"number"},{name:"bandwidth",type:"number"},{name:"count",type:"number"},{name:"nice",type:"boolean",default:!1},{name:"thresholds",type:"number",array:!0},{name:"smooth",type:"boolean",default:!0}]},Object(ct.y)(zb,Br).transform=function(t,e){if(this.value&&!e.changed()&&!t.modified())return e.StopPropagation;var n,r,i=e.fork(e.NO_SOURCE|e.NO_FIELDS),a=Eb().smooth(!1!==t.smooth),o=t.values,s=t.thresholds||Ab(t.count||10,t.nice,!!o),u=t.size;return o||(o=e.materialize(e.SOURCE).source,r=Tb(n=Lb(Mb(),t)(o,!0),n.scale||1,n.scale||1,0,0),u=[n.width,n.height],o=n.values),s=Object(ct.A)(s)?s:s(o),o=a.size(u)(o,s),r&&o.forEach(r),this.value&&(i.rem=this.value),this.value=i.source=i.add=(o||[]).map(vt),i};var Bb="Feature",Ub="FeatureCollection";function Wb(t){Br.call(this,null,t)}function Vb(){}Wb.Definition={type:"GeoJSON",metadata:{},params:[{name:"fields",type:"field",array:!0,length:2},{name:"geojson",type:"field"}]},Object(ct.y)(Wb,Br).transform=function(t,e){var n,r=this._features,i=this._points,a=t.fields,o=a&&a[0],s=a&&a[1],u=t.geojson||!a&&ct.x,c=e.ADD;n=t.modified()||e.changed(e.REM)||e.modified(Object(ct.g)(u))||o&&e.modified(Object(ct.g)(o))||s&&e.modified(Object(ct.g)(s)),this.value&&!n||(c=e.SOURCE,this._features=r=[],this._points=i=[]),u&&e.visit(c,function(t){r.push(u(t))}),o&&s&&(e.visit(c,function(t){var e=o(t),n=s(t);null!=e&&null!=n&&(e=+e)===e&&(n=+n)===n&&i.push([e,n])}),r=r.concat({type:Bb,geometry:{type:"MultiPoint",coordinates:i}})),this.value={type:Ub,features:r}};var qb=function(){var t,e=[];return{point:function(e,n){t.push([e,n])},lineStart:function(){e.push(t=[])},lineEnd:Vb,rejoin:function(){e.length>1&&e.push(e.pop().concat(e.shift()))},result:function(){var n=e;return e=[],t=null,n}}},Hb=1e-6,Gb=Math.PI,$b=Gb/2,Kb=Gb/4,Xb=2*Gb,Yb=180/Gb,Jb=Gb/180,Zb=Math.abs,Qb=Math.atan,tx=Math.atan2,ex=Math.cos,nx=Math.ceil,rx=Math.exp,ix=(Math.floor,Math.log),ax=Math.pow,ox=Math.sin,sx=Math.sign||function(t){return t>0?1:t<0?-1:0},ux=Math.sqrt,cx=Math.tan;function lx(t){return t>1?0:t<-1?Gb:Math.acos(t)}function fx(t){return t>1?$b:t<-1?-$b:Math.asin(t)}var dx=function(t,e){return Zb(t[0]-e[0])<Hb&&Zb(t[1]-e[1])<Hb};function hx(t,e,n,r){this.x=t,this.z=e,this.o=n,this.e=r,this.v=!1,this.n=this.p=null}var px=function(t,e,n,r,i){var a,o,s=[],u=[];if(t.forEach(function(t){if(!((e=t.length-1)<=0)){var e,n,r=t[0],o=t[e];if(dx(r,o)){for(i.lineStart(),a=0;a<e;++a)i.point((r=t[a])[0],r[1]);i.lineEnd()}else s.push(n=new hx(r,t,null,!0)),u.push(n.o=new hx(r,null,n,!1)),s.push(n=new hx(o,t,null,!1)),u.push(n.o=new hx(o,null,n,!0))}}),s.length){for(u.sort(e),mx(s),mx(u),a=0,o=u.length;a<o;++a)u[a].e=n=!n;for(var c,l,f=s[0];;){for(var d=f,h=!0;d.v;)if((d=d.n)===f)return;c=d.z,i.lineStart();do{if(d.v=d.o.v=!0,d.e){if(h)for(a=0,o=c.length;a<o;++a)i.point((l=c[a])[0],l[1]);else r(d.x,d.n.x,1,i);d=d.n}else{if(h)for(c=d.p.z,a=c.length-1;a>=0;--a)i.point((l=c[a])[0],l[1]);else r(d.x,d.p.x,-1,i);d=d.p}c=(d=d.o).z,h=!h}while(!d.v);i.lineEnd()}}};function mx(t){if(e=t.length){for(var e,n,r=0,i=t[0];++r<e;)i.n=n=t[r],n.p=i,i=n;i.n=n=t[0],n.p=i}}var gx=function(){return new vx};function vx(){this.reset()}vx.prototype={constructor:vx,reset:function(){this.s=this.t=0},add:function(t){bx(yx,t,this.t),bx(this,yx.s,this.s),this.s?this.t+=yx.t:this.s=yx.t},valueOf:function(){return this.s}};var yx=new vx;function bx(t,e,n){var r=t.s=e+n,i=r-e,a=r-i;t.t=e-a+(n-i)}function xx(t){return[tx(t[1],t[0]),fx(t[2])]}function wx(t){var e=t[0],n=t[1],r=ex(n);return[r*ex(e),r*ox(e),ox(n)]}function kx(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function _x(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function Ex(t,e){t[0]+=e[0],t[1]+=e[1],t[2]+=e[2]}function Ox(t,e){return[t[0]*e,t[1]*e,t[2]*e]}function Sx(t){var e=ux(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]);t[0]/=e,t[1]/=e,t[2]/=e}var Cx=gx();function Ax(t){return Zb(t[0])<=Gb?t[0]:sx(t[0])*((Zb(t[0])+Gb)%Xb-Gb)}var Nx=function(t,e){return t<e?-1:t>e?1:t>=e?0:NaN};var Tx=function(t){return 1===t.length&&(t=function(t){return function(e,n){return Nx(t(e),n)}}(t)),{left:function(e,n,r,i){for(null==r&&(r=0),null==i&&(i=e.length);r<i;){var a=r+i>>>1;t(e[a],n)<0?r=a+1:i=a}return r},right:function(e,n,r,i){for(null==r&&(r=0),null==i&&(i=e.length);r<i;){var a=r+i>>>1;t(e[a],n)>0?i=a:r=a+1}return r}}}(Nx);Tx.right,Tx.left;var Ix=Array.prototype,Dx=(Ix.slice,Ix.map,function(t,e,n){t=+t,e=+e,n=(i=arguments.length)<2?(e=t,t=0,1):i<3?1:+n;for(var r=-1,i=0|Math.max(0,Math.ceil((e-t)/n)),a=new Array(i);++r<i;)a[r]=t+r*n;return a});Math.sqrt(50),Math.sqrt(10),Math.sqrt(2);var Mx=function(t){for(var e,n,r,i=t.length,a=-1,o=0;++a<i;)o+=t[a].length;for(n=new Array(o);--i>=0;)for(e=(r=t[i]).length;--e>=0;)n[--o]=r[e];return n};var Rx=function(t,e,n,r){return function(i){var a,o,s,u=e(i),c=qb(),l=e(c),f=!1,d={point:h,lineStart:m,lineEnd:g,polygonStart:function(){d.point=v,d.lineStart=y,d.lineEnd=b,o=[],a=[]},polygonEnd:function(){d.point=h,d.lineStart=m,d.lineEnd=g,o=Mx(o);var t=function(t,e){var n=Ax(e),r=e[1],i=ox(r),a=[ox(n),-ex(n),0],o=0,s=0;Cx.reset(),1===i?r=$b+Hb:-1===i&&(r=-$b-Hb);for(var u=0,c=t.length;u<c;++u)if(f=(l=t[u]).length)for(var l,f,d=l[f-1],h=Ax(d),p=d[1]/2+Kb,m=ox(p),g=ex(p),v=0;v<f;++v,h=b,m=w,g=k,d=y){var y=l[v],b=Ax(y),x=y[1]/2+Kb,w=ox(x),k=ex(x),_=b-h,E=_>=0?1:-1,O=E*_,S=O>Gb,C=m*w;if(Cx.add(tx(C*E*ox(O),g*k+C*ex(O))),o+=S?_+E*Xb:_,S^h>=n^b>=n){var A=_x(wx(d),wx(y));Sx(A);var N=_x(a,A);Sx(N);var T=(S^_>=0?-1:1)*fx(N[2]);(r>T||r===T&&(A[0]||A[1]))&&(s+=S^_>=0?1:-1)}}return(o<-Hb||o<Hb&&Cx<-Hb)^1&s}(a,r);o.length?(f||(i.polygonStart(),f=!0),px(o,jx,t,n,i)):t&&(f||(i.polygonStart(),f=!0),i.lineStart(),n(null,null,1,i),i.lineEnd()),f&&(i.polygonEnd(),f=!1),o=a=null},sphere:function(){i.polygonStart(),i.lineStart(),n(null,null,1,i),i.lineEnd(),i.polygonEnd()}};function h(e,n){t(e,n)&&i.point(e,n)}function p(t,e){u.point(t,e)}function m(){d.point=p,u.lineStart()}function g(){d.point=h,u.lineEnd()}function v(t,e){s.push([t,e]),l.point(t,e)}function y(){l.lineStart(),s=[]}function b(){v(s[0][0],s[0][1]),l.lineEnd();var t,e,n,r,u=l.clean(),d=c.result(),h=d.length;if(s.pop(),a.push(s),s=null,h)if(1&u){if((e=(n=d[0]).length-1)>0){for(f||(i.polygonStart(),f=!0),i.lineStart(),t=0;t<e;++t)i.point((r=n[t])[0],r[1]);i.lineEnd()}}else h>1&&2&u&&d.push(d.pop().concat(d.shift())),o.push(d.filter(Fx))}return d}};function Fx(t){return t.length>1}function jx(t,e){return((t=t.x)[0]<0?t[1]-$b-Hb:$b-t[1])-((e=e.x)[0]<0?e[1]-$b-Hb:$b-e[1])}var Px=Rx(function(){return!0},function(t){var e,n=NaN,r=NaN,i=NaN;return{lineStart:function(){t.lineStart(),e=1},point:function(a,o){var s=a>0?Gb:-Gb,u=Zb(a-n);Zb(u-Gb)<Hb?(t.point(n,r=(r+o)/2>0?$b:-$b),t.point(i,r),t.lineEnd(),t.lineStart(),t.point(s,r),t.point(a,r),e=0):i!==s&&u>=Gb&&(Zb(n-i)<Hb&&(n-=i*Hb),Zb(a-s)<Hb&&(a-=s*Hb),r=function(t,e,n,r){var i,a,o=ox(t-n);return Zb(o)>Hb?Qb((ox(e)*(a=ex(r))*ox(n)-ox(r)*(i=ex(e))*ox(t))/(i*a*o)):(e+r)/2}(n,r,a,o),t.point(i,r),t.lineEnd(),t.lineStart(),t.point(s,r),e=0),t.point(n=a,r=o),i=s},lineEnd:function(){t.lineEnd(),n=r=NaN},clean:function(){return 2-e}}},function(t,e,n,r){var i;if(null==t)i=n*$b,r.point(-Gb,i),r.point(0,i),r.point(Gb,i),r.point(Gb,0),r.point(Gb,-i),r.point(0,-i),r.point(-Gb,-i),r.point(-Gb,0),r.point(-Gb,i);else if(Zb(t[0]-e[0])>Hb){var a=t[0]<e[0]?Gb:-Gb;i=n*a/2,r.point(-a,i),r.point(0,i),r.point(a,i)}else r.point(e[0],e[1])},[-Gb,-$b]);var Lx=function(t,e){function n(n,r){return n=t(n,r),e(n[0],n[1])}return t.invert&&e.invert&&(n.invert=function(n,r){return(n=e.invert(n,r))&&t.invert(n[0],n[1])}),n};function zx(t,e){return[Zb(t)>Gb?t+Math.round(-t/Xb)*Xb:t,e]}function Bx(t,e,n){return(t%=Xb)?e||n?Lx(Wx(t),Vx(e,n)):Wx(t):e||n?Vx(e,n):zx}function Ux(t){return function(e,n){return[(e+=t)>Gb?e-Xb:e<-Gb?e+Xb:e,n]}}function Wx(t){var e=Ux(t);return e.invert=Ux(-t),e}function Vx(t,e){var n=ex(t),r=ox(t),i=ex(e),a=ox(e);function o(t,e){var o=ex(e),s=ex(t)*o,u=ox(t)*o,c=ox(e),l=c*n+s*r;return[tx(u*i-l*a,s*n-c*r),fx(l*i+u*a)]}return o.invert=function(t,e){var o=ex(e),s=ex(t)*o,u=ox(t)*o,c=ox(e),l=c*i-u*a;return[tx(u*i+c*a,s*n+l*r),fx(l*n-s*r)]},o}zx.invert=zx;var qx=function(t){function e(e){return(e=t(e[0]*Jb,e[1]*Jb))[0]*=Yb,e[1]*=Yb,e}return t=Bx(t[0]*Jb,t[1]*Jb,t.length>2?t[2]*Jb:0),e.invert=function(e){return(e=t.invert(e[0]*Jb,e[1]*Jb))[0]*=Yb,e[1]*=Yb,e},e};function Hx(t,e,n,r,i,a){if(n){var o=ex(e),s=ox(e),u=r*n;null==i?(i=e+r*Xb,a=e-u/2):(i=Gx(o,i),a=Gx(o,a),(r>0?i<a:i>a)&&(i+=r*Xb));for(var c,l=i;r>0?l>a:l<a;l-=u)c=xx([o,-s*ex(l),-s*ox(l)]),t.point(c[0],c[1])}}function Gx(t,e){(e=wx(e))[0]-=t,Sx(e);var n=lx(-e[1]);return((-e[2]<0?-n:n)+Xb-Hb)%Xb}var $x=function(t){var e=ex(t),n=6*Jb,r=e>0,i=Zb(e)>Hb;function a(t,n){return ex(t)*ex(n)>e}function o(t,n,r){var i=[1,0,0],a=_x(wx(t),wx(n)),o=kx(a,a),s=a[0],u=o-s*s;if(!u)return!r&&t;var c=e*o/u,l=-e*s/u,f=_x(i,a),d=Ox(i,c);Ex(d,Ox(a,l));var h=f,p=kx(d,h),m=kx(h,h),g=p*p-m*(kx(d,d)-1);if(!(g<0)){var v=ux(g),y=Ox(h,(-p-v)/m);if(Ex(y,d),y=xx(y),!r)return y;var b,x=t[0],w=n[0],k=t[1],_=n[1];w<x&&(b=x,x=w,w=b);var E=w-x,O=Zb(E-Gb)<Hb;if(!O&&_<k&&(b=k,k=_,_=b),O||E<Hb?O?k+_>0^y[1]<(Zb(y[0]-x)<Hb?k:_):k<=y[1]&&y[1]<=_:E>Gb^(x<=y[0]&&y[0]<=w)){var S=Ox(h,(-p+v)/m);return Ex(S,d),[y,xx(S)]}}}function s(e,n){var i=r?t:Gb-t,a=0;return e<-i?a|=1:e>i&&(a|=2),n<-i?a|=4:n>i&&(a|=8),a}return Rx(a,function(t){var e,n,u,c,l;return{lineStart:function(){c=u=!1,l=1},point:function(f,d){var h,p=[f,d],m=a(f,d),g=r?m?0:s(f,d):m?s(f+(f<0?Gb:-Gb),d):0;if(!e&&(c=u=m)&&t.lineStart(),m!==u&&(!(h=o(e,p))||dx(e,h)||dx(p,h))&&(p[0]+=Hb,p[1]+=Hb,m=a(p[0],p[1])),m!==u)l=0,m?(t.lineStart(),h=o(p,e),t.point(h[0],h[1])):(h=o(e,p),t.point(h[0],h[1]),t.lineEnd()),e=h;else if(i&&e&&r^m){var v;g&n||!(v=o(p,e,!0))||(l=0,r?(t.lineStart(),t.point(v[0][0],v[0][1]),t.point(v[1][0],v[1][1]),t.lineEnd()):(t.point(v[1][0],v[1][1]),t.lineEnd(),t.lineStart(),t.point(v[0][0],v[0][1])))}!m||e&&dx(e,p)||t.point(p[0],p[1]),e=p,u=m,n=g},lineEnd:function(){u&&t.lineEnd(),e=null},clean:function(){return l|(c&&u)<<1}}},function(e,r,i,a){Hx(a,t,n,i,e,r)},r?[0,-t]:[-Gb,t-Gb])},Kx=function(t,e,n,r,i,a){var o,s=t[0],u=t[1],c=0,l=1,f=e[0]-s,d=e[1]-u;if(o=n-s,f||!(o>0)){if(o/=f,f<0){if(o<c)return;o<l&&(l=o)}else if(f>0){if(o>l)return;o>c&&(c=o)}if(o=i-s,f||!(o<0)){if(o/=f,f<0){if(o>l)return;o>c&&(c=o)}else if(f>0){if(o<c)return;o<l&&(l=o)}if(o=r-u,d||!(o>0)){if(o/=d,d<0){if(o<c)return;o<l&&(l=o)}else if(d>0){if(o>l)return;o>c&&(c=o)}if(o=a-u,d||!(o<0)){if(o/=d,d<0){if(o>l)return;o>c&&(c=o)}else if(d>0){if(o<c)return;o<l&&(l=o)}return c>0&&(t[0]=s+c*f,t[1]=u+c*d),l<1&&(e[0]=s+l*f,e[1]=u+l*d),!0}}}}},Xx=1e9,Yx=-Xx;function Jx(t,e,n,r){function i(i,a){return t<=i&&i<=n&&e<=a&&a<=r}function a(i,a,s,c){var l=0,f=0;if(null==i||(l=o(i,s))!==(f=o(a,s))||u(i,a)<0^s>0)do{c.point(0===l||3===l?t:n,l>1?r:e)}while((l=(l+s+4)%4)!==f);else c.point(a[0],a[1])}function o(r,i){return Zb(r[0]-t)<Hb?i>0?0:3:Zb(r[0]-n)<Hb?i>0?2:1:Zb(r[1]-e)<Hb?i>0?1:0:i>0?3:2}function s(t,e){return u(t.x,e.x)}function u(t,e){var n=o(t,1),r=o(e,1);return n!==r?n-r:0===n?e[1]-t[1]:1===n?t[0]-e[0]:2===n?t[1]-e[1]:e[0]-t[0]}return function(o){var u,c,l,f,d,h,p,m,g,v,y,b=o,x=qb(),w={point:k,lineStart:function(){w.point=_,c&&c.push(l=[]);v=!0,g=!1,p=m=NaN},lineEnd:function(){u&&(_(f,d),h&&g&&x.rejoin(),u.push(x.result()));w.point=k,g&&b.lineEnd()},polygonStart:function(){b=x,u=[],c=[],y=!0},polygonEnd:function(){var e=function(){for(var e=0,n=0,i=c.length;n<i;++n)for(var a,o,s=c[n],u=1,l=s.length,f=s[0],d=f[0],h=f[1];u<l;++u)a=d,o=h,f=s[u],d=f[0],h=f[1],o<=r?h>r&&(d-a)*(r-o)>(h-o)*(t-a)&&++e:h<=r&&(d-a)*(r-o)<(h-o)*(t-a)&&--e;return e}(),n=y&&e,i=(u=Mx(u)).length;(n||i)&&(o.polygonStart(),n&&(o.lineStart(),a(null,null,1,o),o.lineEnd()),i&&px(u,s,e,a,o),o.polygonEnd());b=o,u=c=l=null}};function k(t,e){i(t,e)&&b.point(t,e)}function _(a,o){var s=i(a,o);if(c&&l.push([a,o]),v)f=a,d=o,h=s,v=!1,s&&(b.lineStart(),b.point(a,o));else if(s&&g)b.point(a,o);else{var u=[p=Math.max(Yx,Math.min(Xx,p)),m=Math.max(Yx,Math.min(Xx,m))],x=[a=Math.max(Yx,Math.min(Xx,a)),o=Math.max(Yx,Math.min(Xx,o))];Kx(u,x,t,e,n,r)?(g||(b.lineStart(),b.point(u[0],u[1])),b.point(x[0],x[1]),s||b.lineEnd(),y=!1):s&&(b.lineStart(),b.point(a,o),y=!1)}p=a,m=o,g=s}return w}}var Zx=function(t){return t};function Qx(t){return function(e){var n=new tw;for(var r in t)n[r]=t[r];return n.stream=e,n}}function tw(){}function ew(t,e){t&&rw.hasOwnProperty(t.type)&&rw[t.type](t,e)}tw.prototype={constructor:tw,point:function(t,e){this.stream.point(t,e)},sphere:function(){this.stream.sphere()},lineStart:function(){this.stream.lineStart()},lineEnd:function(){this.stream.lineEnd()},polygonStart:function(){this.stream.polygonStart()},polygonEnd:function(){this.stream.polygonEnd()}};var nw={Feature:function(t,e){ew(t.geometry,e)},FeatureCollection:function(t,e){for(var n=t.features,r=-1,i=n.length;++r<i;)ew(n[r].geometry,e)}},rw={Sphere:function(t,e){e.sphere()},Point:function(t,e){t=t.coordinates,e.point(t[0],t[1],t[2])},MultiPoint:function(t,e){for(var n=t.coordinates,r=-1,i=n.length;++r<i;)t=n[r],e.point(t[0],t[1],t[2])},LineString:function(t,e){iw(t.coordinates,e,0)},MultiLineString:function(t,e){for(var n=t.coordinates,r=-1,i=n.length;++r<i;)iw(n[r],e,0)},Polygon:function(t,e){aw(t.coordinates,e)},MultiPolygon:function(t,e){for(var n=t.coordinates,r=-1,i=n.length;++r<i;)aw(n[r],e)},GeometryCollection:function(t,e){for(var n=t.geometries,r=-1,i=n.length;++r<i;)ew(n[r],e)}};function iw(t,e,n){var r,i=-1,a=t.length-n;for(e.lineStart();++i<a;)r=t[i],e.point(r[0],r[1],r[2]);e.lineEnd()}function aw(t,e){var n=-1,r=t.length;for(e.polygonStart();++n<r;)iw(t[n],e,1);e.polygonEnd()}var ow=function(t,e){t&&nw.hasOwnProperty(t.type)?nw[t.type](t,e):ew(t,e)},sw=1/0,uw=sw,cw=-sw,lw=cw;var fw={point:function(t,e){t<sw&&(sw=t);t>cw&&(cw=t);e<uw&&(uw=e);e>lw&&(lw=e)},lineStart:Vb,lineEnd:Vb,polygonStart:Vb,polygonEnd:Vb,result:function(){var t=[[sw,uw],[cw,lw]];return cw=lw=-(uw=sw=1/0),t}};function dw(t,e,n){var r=t.clipExtent&&t.clipExtent();return t.scale(150).translate([0,0]),null!=r&&t.clipExtent(null),ow(n,t.stream(fw)),e(fw.result()),null!=r&&t.clipExtent(r),t}function hw(t,e,n){return dw(t,function(n){var r=e[1][0]-e[0][0],i=e[1][1]-e[0][1],a=Math.min(r/(n[1][0]-n[0][0]),i/(n[1][1]-n[0][1])),o=+e[0][0]+(r-a*(n[1][0]+n[0][0]))/2,s=+e[0][1]+(i-a*(n[1][1]+n[0][1]))/2;t.scale(150*a).translate([o,s])},n)}function pw(t,e,n){return hw(t,[[0,0],e],n)}function mw(t,e,n){return dw(t,function(n){var r=+e,i=r/(n[1][0]-n[0][0]),a=(r-i*(n[1][0]+n[0][0]))/2,o=-i*n[0][1];t.scale(150*i).translate([a,o])},n)}function gw(t,e,n){return dw(t,function(n){var r=+e,i=r/(n[1][1]-n[0][1]),a=-i*n[0][0],o=(r-i*(n[1][1]+n[0][1]))/2;t.scale(150*i).translate([a,o])},n)}var vw=16,yw=ex(30*Jb),bw=function(t,e){return+e?function(t,e){function n(r,i,a,o,s,u,c,l,f,d,h,p,m,g){var v=c-r,y=l-i,b=v*v+y*y;if(b>4*e&&m--){var x=o+d,w=s+h,k=u+p,_=ux(x*x+w*w+k*k),E=fx(k/=_),O=Zb(Zb(k)-1)<Hb||Zb(a-f)<Hb?(a+f)/2:tx(w,x),S=t(O,E),C=S[0],A=S[1],N=C-r,T=A-i,I=y*N-v*T;(I*I/b>e||Zb((v*N+y*T)/b-.5)>.3||o*d+s*h+u*p<yw)&&(n(r,i,a,o,s,u,C,A,O,x/=_,w/=_,k,m,g),g.point(C,A),n(C,A,O,x,w,k,c,l,f,d,h,p,m,g))}}return function(e){var r,i,a,o,s,u,c,l,f,d,h,p,m={point:g,lineStart:v,lineEnd:b,polygonStart:function(){e.polygonStart(),m.lineStart=x},polygonEnd:function(){e.polygonEnd(),m.lineStart=v}};function g(n,r){n=t(n,r),e.point(n[0],n[1])}function v(){l=NaN,m.point=y,e.lineStart()}function y(r,i){var a=wx([r,i]),o=t(r,i);n(l,f,c,d,h,p,l=o[0],f=o[1],c=r,d=a[0],h=a[1],p=a[2],vw,e),e.point(l,f)}function b(){m.point=g,e.lineEnd()}function x(){v(),m.point=w,m.lineEnd=k}function w(t,e){y(r=t,e),i=l,a=f,o=d,s=h,u=p,m.point=y}function k(){n(l,f,c,d,h,p,i,a,r,o,s,u,vw,e),m.lineEnd=b,b()}return m}}(t,e):function(t){return Qx({point:function(e,n){e=t(e,n),this.stream.point(e[0],e[1])}})}(t)};var xw=Qx({point:function(t,e){this.stream.point(t*Jb,e*Jb)}});function ww(t,e,n,r){var i=ex(r),a=ox(r),o=i*t,s=a*t,u=i/t,c=a/t,l=(a*n-i*e)/t,f=(a*e+i*n)/t;function d(t,r){return[o*t-s*r+e,n-s*t-o*r]}return d.invert=function(t,e){return[u*t-c*e+l,f-c*t-u*e]},d}function kw(t){return _w(function(){return t})()}function _w(t){var e,n,r,i,a,o,s,u,c,l,f=150,d=480,h=250,p=0,m=0,g=0,v=0,y=0,b=0,x=null,w=Px,k=null,_=Zx,E=.5;function O(t){return u(t[0]*Jb,t[1]*Jb)}function S(t){return(t=u.invert(t[0],t[1]))&&[t[0]*Yb,t[1]*Yb]}function C(){var t=ww(f,0,0,b).apply(null,e(p,m)),r=(b?ww:function(t,e,n){function r(r,i){return[e+t*r,n-t*i]}return r.invert=function(r,i){return[(r-e)/t,(n-i)/t]},r})(f,d-t[0],h-t[1],b);return n=Bx(g,v,y),s=Lx(e,r),u=Lx(n,s),o=bw(s,E),A()}function A(){return c=l=null,O}return O.stream=function(t){return c&&l===t?c:c=xw(function(t){return Qx({point:function(e,n){var r=t(e,n);return this.stream.point(r[0],r[1])}})}(n)(w(o(_(l=t)))))},O.preclip=function(t){return arguments.length?(w=t,x=void 0,A()):w},O.postclip=function(t){return arguments.length?(_=t,k=r=i=a=null,A()):_},O.clipAngle=function(t){return arguments.length?(w=+t?$x(x=t*Jb):(x=null,Px),A()):x*Yb},O.clipExtent=function(t){return arguments.length?(_=null==t?(k=r=i=a=null,Zx):Jx(k=+t[0][0],r=+t[0][1],i=+t[1][0],a=+t[1][1]),A()):null==k?null:[[k,r],[i,a]]},O.scale=function(t){return arguments.length?(f=+t,C()):f},O.translate=function(t){return arguments.length?(d=+t[0],h=+t[1],C()):[d,h]},O.center=function(t){return arguments.length?(p=t[0]%360*Jb,m=t[1]%360*Jb,C()):[p*Yb,m*Yb]},O.rotate=function(t){return arguments.length?(g=t[0]%360*Jb,v=t[1]%360*Jb,y=t.length>2?t[2]%360*Jb:0,C()):[g*Yb,v*Yb,y*Yb]},O.angle=function(t){return arguments.length?(b=t%360*Jb,C()):b*Yb},O.precision=function(t){return arguments.length?(o=bw(s,E=t*t),A()):ux(E)},O.fitExtent=function(t,e){return hw(O,t,e)},O.fitSize=function(t,e){return pw(O,t,e)},O.fitWidth=function(t,e){return mw(O,t,e)},O.fitHeight=function(t,e){return gw(O,t,e)},function(){return e=t.apply(this,arguments),O.invert=e.invert&&S,C()}}var Ew=1.340264,Ow=-.081106,Sw=893e-6,Cw=.003796,Aw=ux(3)/2;function Nw(t,e){var n=fx(Aw*ox(e)),r=n*n,i=r*r*r;return[t*ex(n)/(Aw*(Ew+3*Ow*r+i*(7*Sw+9*Cw*r))),n*(Ew+Ow*r+i*(Sw+Cw*r))]}Nw.invert=function(t,e){for(var n,r=e,i=r*r,a=i*i*i,o=0;o<12&&(a=(i=(r-=n=(r*(Ew+Ow*i+a*(Sw+Cw*i))-e)/(Ew+3*Ow*i+a*(7*Sw+9*Cw*i)))*r)*i*i,!(Zb(n)<1e-12));++o);return[Aw*t*(Ew+3*Ow*i+a*(7*Sw+9*Cw*i))/ex(r),fx(ox(r)/Aw)]};var Tw,Iw,Dw,Mw,Rw=gx(),Fw=gx(),jw={point:Vb,lineStart:Vb,lineEnd:Vb,polygonStart:function(){jw.lineStart=Pw,jw.lineEnd=Bw},polygonEnd:function(){jw.lineStart=jw.lineEnd=jw.point=Vb,Rw.add(Zb(Fw)),Fw.reset()},result:function(){var t=Rw/2;return Rw.reset(),t}};function Pw(){jw.point=Lw}function Lw(t,e){jw.point=zw,Tw=Dw=t,Iw=Mw=e}function zw(t,e){Fw.add(Mw*t-Dw*e),Dw=t,Mw=e}function Bw(){zw(Tw,Iw)}var Uw,Ww,Vw,qw,Hw=jw,Gw=0,$w=0,Kw=0,Xw=0,Yw=0,Jw=0,Zw=0,Qw=0,tk=0,ek={point:nk,lineStart:rk,lineEnd:ok,polygonStart:function(){ek.lineStart=sk,ek.lineEnd=uk},polygonEnd:function(){ek.point=nk,ek.lineStart=rk,ek.lineEnd=ok},result:function(){var t=tk?[Zw/tk,Qw/tk]:Jw?[Xw/Jw,Yw/Jw]:Kw?[Gw/Kw,$w/Kw]:[NaN,NaN];return Gw=$w=Kw=Xw=Yw=Jw=Zw=Qw=tk=0,t}};function nk(t,e){Gw+=t,$w+=e,++Kw}function rk(){ek.point=ik}function ik(t,e){ek.point=ak,nk(Vw=t,qw=e)}function ak(t,e){var n=t-Vw,r=e-qw,i=ux(n*n+r*r);Xw+=i*(Vw+t)/2,Yw+=i*(qw+e)/2,Jw+=i,nk(Vw=t,qw=e)}function ok(){ek.point=nk}function sk(){ek.point=ck}function uk(){lk(Uw,Ww)}function ck(t,e){ek.point=lk,nk(Uw=Vw=t,Ww=qw=e)}function lk(t,e){var n=t-Vw,r=e-qw,i=ux(n*n+r*r);Xw+=i*(Vw+t)/2,Yw+=i*(qw+e)/2,Jw+=i,Zw+=(i=qw*t-Vw*e)*(Vw+t),Qw+=i*(qw+e),tk+=3*i,nk(Vw=t,qw=e)}var fk=ek;function dk(t){this._context=t}dk.prototype={_radius:4.5,pointRadius:function(t){return this._radius=t,this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){0===this._line&&this._context.closePath(),this._point=NaN},point:function(t,e){switch(this._point){case 0:this._context.moveTo(t,e),this._point=1;break;case 1:this._context.lineTo(t,e);break;default:this._context.moveTo(t+this._radius,e),this._context.arc(t,e,this._radius,0,Xb)}},result:Vb};var hk,pk,mk,gk,vk,yk=gx(),bk={point:Vb,lineStart:function(){bk.point=xk},lineEnd:function(){hk&&wk(pk,mk),bk.point=Vb},polygonStart:function(){hk=!0},polygonEnd:function(){hk=null},result:function(){var t=+yk;return yk.reset(),t}};function xk(t,e){bk.point=wk,pk=gk=t,mk=vk=e}function wk(t,e){gk-=t,vk-=e,yk.add(ux(gk*gk+vk*vk)),gk=t,vk=e}var kk=bk;function _k(){this._string=[]}function Ek(t){return"m0,"+t+"a"+t+","+t+" 0 1,1 0,"+-2*t+"a"+t+","+t+" 0 1,1 0,"+2*t+"z"}_k.prototype={_radius:4.5,_circle:Ek(4.5),pointRadius:function(t){return(t=+t)!==this._radius&&(this._radius=t,this._circle=null),this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){0===this._line&&this._string.push("Z"),this._point=NaN},point:function(t,e){switch(this._point){case 0:this._string.push("M",t,",",e),this._point=1;break;case 1:this._string.push("L",t,",",e);break;default:null==this._circle&&(this._circle=Ek(this._radius)),this._string.push("M",t,",",e,this._circle)}},result:function(){if(this._string.length){var t=this._string.join("");return this._string=[],t}return null}};var Ok=function(t,e){var n,r,i=4.5;function a(t){return t&&("function"==typeof i&&r.pointRadius(+i.apply(this,arguments)),ow(t,n(r))),r.result()}return a.area=function(t){return ow(t,n(Hw)),Hw.result()},a.measure=function(t){return ow(t,n(kk)),kk.result()},a.bounds=function(t){return ow(t,n(fw)),fw.result()},a.centroid=function(t){return ow(t,n(fk)),fk.result()},a.projection=function(e){return arguments.length?(n=null==e?(t=null,Zx):(t=e).stream,a):t},a.context=function(t){return arguments.length?(r=null==t?(e=null,new _k):new dk(e=t),"function"!=typeof i&&r.pointRadius(i),a):e},a.pointRadius=function(t){return arguments.length?(i="function"==typeof t?t:(r.pointRadius(+t),+t),a):i},a.projection(t).context(e)};function Sk(t){var e=0,n=Gb/3,r=_w(t),i=r(e,n);return i.parallels=function(t){return arguments.length?r(e=t[0]*Jb,n=t[1]*Jb):[e*Yb,n*Yb]},i}function Ck(t,e){var n=ox(t),r=(n+ox(e))/2;if(Zb(r)<Hb)return function(t){var e=ex(t);function n(t,n){return[t*e,ox(n)/e]}return n.invert=function(t,n){return[t/e,fx(n*e)]},n}(t);var i=1+n*(2*r-n),a=ux(i)/r;function o(t,e){var n=ux(i-2*r*ox(e))/r;return[n*ox(t*=r),a-n*ex(t)]}return o.invert=function(t,e){var n=a-e;return[tx(t,Zb(n))/r*sx(n),fx((i-(t*t+n*n)*r*r)/(2*r))]},o}var Ak=function(){return Sk(Ck).scale(155.424).center([0,33.6442])},Nk=function(){return Ak().parallels([29.5,45.5]).scale(1070).translate([480,250]).rotate([96,0]).center([-.6,38.7])};function Tk(t){return function(e,n){var r=ex(e),i=ex(n),a=t(r*i);return[a*i*ox(e),a*ox(n)]}}function Ik(t){return function(e,n){var r=ux(e*e+n*n),i=t(r),a=ox(i),o=ex(i);return[tx(e*a,r*o),fx(r&&n*a/r)]}}var Dk=Tk(function(t){return ux(2/(1+t))});Dk.invert=Ik(function(t){return 2*fx(t/2)});var Mk=Tk(function(t){return(t=lx(t))&&t/ox(t)});Mk.invert=Ik(function(t){return t});function Rk(t,e){return[t,ix(cx(($b+e)/2))]}Rk.invert=function(t,e){return[t,2*Qb(rx(e))-$b]};function Fk(t){var e,n,r,i=kw(t),a=i.center,o=i.scale,s=i.translate,u=i.clipExtent,c=null;function l(){var a=Gb*o(),s=i(qx(i.rotate()).invert([0,0]));return u(null==c?[[s[0]-a,s[1]-a],[s[0]+a,s[1]+a]]:t===Rk?[[Math.max(s[0]-a,c),e],[Math.min(s[0]+a,n),r]]:[[c,Math.max(s[1]-a,e)],[n,Math.min(s[1]+a,r)]])}return i.scale=function(t){return arguments.length?(o(t),l()):o()},i.translate=function(t){return arguments.length?(s(t),l()):s()},i.center=function(t){return arguments.length?(a(t),l()):a()},i.clipExtent=function(t){return arguments.length?(null==t?c=e=n=r=null:(c=+t[0][0],e=+t[0][1],n=+t[1][0],r=+t[1][1]),l()):null==c?null:[[c,e],[n,r]]},l()}function jk(t){return cx(($b+t)/2)}function Pk(t,e){var n=ex(t),r=t===e?ox(t):ix(n/ex(e))/ix(jk(e)/jk(t)),i=n*ax(jk(t),r)/r;if(!r)return Rk;function a(t,e){i>0?e<-$b+Hb&&(e=-$b+Hb):e>$b-Hb&&(e=$b-Hb);var n=i/ax(jk(e),r);return[n*ox(r*t),i-n*ex(r*t)]}return a.invert=function(t,e){var n=i-e,a=sx(r)*ux(t*t+n*n);return[tx(t,Zb(n))/r*sx(n),2*Qb(ax(i/a,1/r))-$b]},a}function Lk(t,e){return[t,e]}Lk.invert=Lk;function zk(t,e){var n=ex(t),r=t===e?ox(t):(n-ex(e))/(e-t),i=n/r+t;if(Zb(r)<Hb)return Lk;function a(t,e){var n=i-e,a=r*t;return[n*ox(a),i-n*ex(a)]}return a.invert=function(t,e){var n=i-e;return[tx(t,Zb(n))/r*sx(n),i-sx(r)*ux(t*t+n*n)]},a}function Bk(t,e){var n=ex(e),r=ex(t)*n;return[n*ox(t)/r,ox(e)/r]}Bk.invert=Ik(Qb);function Uk(t,e,n,r){return 1===t&&1===e&&0===n&&0===r?Zx:Qx({point:function(i,a){this.stream.point(i*t+n,a*e+r)}})}function Wk(t,e){var n=ex(e),r=1+ex(t)*n;return[n*ox(t)/r,ox(e)/r]}Wk.invert=Ik(function(t){return 2*Qb(t)});function Vk(t,e){var n=e*e,r=n*n;return[t*(.8707-.131979*n+r*(r*(.003971*n-.001529*r)-.013791)),e*(1.007226+n*(.015085+r*(.028874*n-.044475-.005916*r)))]}Vk.invert=function(t,e){var n,r=e,i=25;do{var a=r*r,o=a*a;r-=n=(r*(1.007226+a*(.015085+o*(.028874*a-.044475-.005916*o)))-e)/(1.007226+a*(.045255+o*(.259866*a-.311325-.005916*11*o)))}while(Zb(n)>Hb&&--i>0);return[t/(.8707+(a=r*r)*(a*(a*a*a*(.003971-.001529*a)-.013791)-.131979)),r]};function qk(t,e){return[ex(e)*ox(t),ox(e)]}qk.invert=Ik(fx);function Hk(t,e){return[ix(cx(($b+e)/2)),-t]}Hk.invert=function(t,e){return[-e,2*Qb(rx(t))-$b]};var Gk=Math.abs,$k=(Math.atan,Math.atan2,Math.ceil,Math.cos),Kk=(Math.exp,Math.floor,Math.log,Math.max,Math.min,Math.pow,Math.round,Math.sign,Math.sin),Xk=(Math.tan,1e-6),Yk=Math.PI,Jk=Yk/2,Zk=(Math.SQRT1_2,t_(2));t_(Yk);function Qk(t){return t>1?Jk:t<-1?-Jk:Math.asin(t)}function t_(t){return t>0?Math.sqrt(t):0}var e_=function(t,e,n){function r(r,i){return[t*r*$k(i=function(t,e){var n,r=t*Kk(e),i=30;do{e-=n=(e+Kk(e)-r)/(1+$k(e))}while(Gk(n)>Xk&&--i>0);return e/2}(n,i)),e*Kk(i)]}return r.invert=function(r,i){return i=Qk(i/e),[r/(t*$k(i)),Qk((2*i+Kk(2*i))/n)]},r}(Zk/Jk,Zk,Yk),n_=Ok(),r_=["clipAngle","clipExtent","scale","translate","center","rotate","parallels","precision","reflectX","reflectY","coefficient","distance","fraction","lobes","parallel","radius","ratio","spacing","tilt"];function i_(t,e){if(!t||"string"!=typeof t)throw new Error("Projection type must be a name string.");return t=t.toLowerCase(),arguments.length>1?(o_[t]=function(t,e){return function n(){var r=e();return r.type=t,r.path=Ok().projection(r),r.copy=r.copy||function(){var t=n();return r_.forEach(function(e){r[e]&&t[e](r[e]())}),t.path.pointRadius(r.path.pointRadius()),t},r}}(t,e),this):o_[t]||null}function a_(t){return t&&t.path||n_}var o_={albers:Nk,albersusa:function(){var t,e,n,r,i,a,o=Nk(),s=Ak().rotate([154,0]).center([-2,58.5]).parallels([55,65]),u=Ak().rotate([157,0]).center([-3,19.9]).parallels([8,18]),c={point:function(t,e){a=[t,e]}};function l(t){var e=t[0],o=t[1];return a=null,n.point(e,o),a||(r.point(e,o),a)||(i.point(e,o),a)}function f(){return t=e=null,l}return l.invert=function(t){var e=o.scale(),n=o.translate(),r=(t[0]-n[0])/e,i=(t[1]-n[1])/e;return(i>=.12&&i<.234&&r>=-.425&&r<-.214?s:i>=.166&&i<.234&&r>=-.214&&r<-.115?u:o).invert(t)},l.stream=function(n){return t&&e===n?t:t=function(t){var e=t.length;return{point:function(n,r){for(var i=-1;++i<e;)t[i].point(n,r)},sphere:function(){for(var n=-1;++n<e;)t[n].sphere()},lineStart:function(){for(var n=-1;++n<e;)t[n].lineStart()},lineEnd:function(){for(var n=-1;++n<e;)t[n].lineEnd()},polygonStart:function(){for(var n=-1;++n<e;)t[n].polygonStart()},polygonEnd:function(){for(var n=-1;++n<e;)t[n].polygonEnd()}}}([o.stream(e=n),s.stream(n),u.stream(n)])},l.precision=function(t){return arguments.length?(o.precision(t),s.precision(t),u.precision(t),f()):o.precision()},l.scale=function(t){return arguments.length?(o.scale(t),s.scale(.35*t),u.scale(t),l.translate(o.translate())):o.scale()},l.translate=function(t){if(!arguments.length)return o.translate();var e=o.scale(),a=+t[0],l=+t[1];return n=o.translate(t).clipExtent([[a-.455*e,l-.238*e],[a+.455*e,l+.238*e]]).stream(c),r=s.translate([a-.307*e,l+.201*e]).clipExtent([[a-.425*e+Hb,l+.12*e+Hb],[a-.214*e-Hb,l+.234*e-Hb]]).stream(c),i=u.translate([a-.205*e,l+.212*e]).clipExtent([[a-.214*e+Hb,l+.166*e+Hb],[a-.115*e-Hb,l+.234*e-Hb]]).stream(c),f()},l.fitExtent=function(t,e){return hw(l,t,e)},l.fitSize=function(t,e){return pw(l,t,e)},l.fitWidth=function(t,e){return mw(l,t,e)},l.fitHeight=function(t,e){return gw(l,t,e)},l.scale(1070)},azimuthalequalarea:function(){return kw(Dk).scale(124.75).clipAngle(179.999)},azimuthalequidistant:function(){return kw(Mk).scale(79.4188).clipAngle(179.999)},conicconformal:function(){return Sk(Pk).scale(109.5).parallels([30,30])},conicequalarea:Ak,conicequidistant:function(){return Sk(zk).scale(131.154).center([0,13.9389])},equalEarth:function(){return kw(Nw).scale(177.158)},equirectangular:function(){return kw(Lk).scale(152.63)},gnomonic:function(){return kw(Bk).scale(144.049).clipAngle(60)},identity:function(){var t,e,n,r,i,a,o=1,s=0,u=0,c=1,l=1,f=Zx,d=null,h=Zx;function p(){return r=i=null,a}return a={stream:function(t){return r&&i===t?r:r=f(h(i=t))},postclip:function(r){return arguments.length?(h=r,d=t=e=n=null,p()):h},clipExtent:function(r){return arguments.length?(h=null==r?(d=t=e=n=null,Zx):Jx(d=+r[0][0],t=+r[0][1],e=+r[1][0],n=+r[1][1]),p()):null==d?null:[[d,t],[e,n]]},scale:function(t){return arguments.length?(f=Uk((o=+t)*c,o*l,s,u),p()):o},translate:function(t){return arguments.length?(f=Uk(o*c,o*l,s=+t[0],u=+t[1]),p()):[s,u]},reflectX:function(t){return arguments.length?(f=Uk(o*(c=t?-1:1),o*l,s,u),p()):c<0},reflectY:function(t){return arguments.length?(f=Uk(o*c,o*(l=t?-1:1),s,u),p()):l<0},fitExtent:function(t,e){return hw(a,t,e)},fitSize:function(t,e){return pw(a,t,e)},fitWidth:function(t,e){return mw(a,t,e)},fitHeight:function(t,e){return gw(a,t,e)}}},mercator:function(){return Fk(Rk).scale(961/Xb)},mollweide:function(){return kw(e_).scale(169.529)},naturalEarth1:function(){return kw(Vk).scale(175.295)},orthographic:function(){return kw(qk).scale(249.5).clipAngle(90+Hb)},stereographic:function(){return kw(Wk).scale(250).clipAngle(142)},transversemercator:function(){var t=Fk(Hk),e=t.center,n=t.rotate;return t.center=function(t){return arguments.length?e([-t[1],t[0]]):[(t=e())[1],-t[0]]},t.rotate=function(t){return arguments.length?n([t[0],t[1],t.length>2?t[2]+90:90]):[(t=n())[0],t[1],t[2]-90]},n([0,0,90]).scale(159.155)}};for(var s_ in o_)i_(s_,o_[s_]);function u_(t){Br.call(this,null,t)}function c_(t){Br.call(this,null,t)}function l_(t){Br.call(this,null,t)}function f_(t,e,n){var r=Dx(t,e-Hb,n).concat(e);return function(t){return r.map(function(e){return[t,e]})}}function d_(t,e,n){var r=Dx(t,e-Hb,n).concat(e);return function(t){return r.map(function(e){return[e,t]})}}function h_(){var t,e,n,r,i,a,o,s,u,c,l,f,d=10,h=d,p=90,m=360,g=2.5;function v(){return{type:"MultiLineString",coordinates:y()}}function y(){return Dx(nx(r/p)*p,n,p).map(l).concat(Dx(nx(s/m)*m,o,m).map(f)).concat(Dx(nx(e/d)*d,t,d).filter(function(t){return Zb(t%p)>Hb}).map(u)).concat(Dx(nx(a/h)*h,i,h).filter(function(t){return Zb(t%m)>Hb}).map(c))}return v.lines=function(){return y().map(function(t){return{type:"LineString",coordinates:t}})},v.outline=function(){return{type:"Polygon",coordinates:[l(r).concat(f(o).slice(1),l(n).reverse().slice(1),f(s).reverse().slice(1))]}},v.extent=function(t){return arguments.length?v.extentMajor(t).extentMinor(t):v.extentMinor()},v.extentMajor=function(t){return arguments.length?(r=+t[0][0],n=+t[1][0],s=+t[0][1],o=+t[1][1],r>n&&(t=r,r=n,n=t),s>o&&(t=s,s=o,o=t),v.precision(g)):[[r,s],[n,o]]},v.extentMinor=function(n){return arguments.length?(e=+n[0][0],t=+n[1][0],a=+n[0][1],i=+n[1][1],e>t&&(n=e,e=t,t=n),a>i&&(n=a,a=i,i=n),v.precision(g)):[[e,a],[t,i]]},v.step=function(t){return arguments.length?v.stepMajor(t).stepMinor(t):v.stepMinor()},v.stepMajor=function(t){return arguments.length?(p=+t[0],m=+t[1],v):[p,m]},v.stepMinor=function(t){return arguments.length?(d=+t[0],h=+t[1],v):[d,h]},v.precision=function(d){return arguments.length?(g=+d,u=f_(a,i,90),c=d_(e,t,g),l=f_(s,o,90),f=d_(r,n,g),v):g},v.extentMajor([[-180,-90+Hb],[180,90-Hb]]).extentMinor([[-180,-80-Hb],[180,80+Hb]])}function p_(t){Br.call(this,[],t),this.generator=h_()}function m_(t){Br.call(this,null,t)}function g_(t){if(!Object(ct.D)(t))return!1;const e=Object(ct.Da)(Object(ct.g)(t));return e.$x||e.$y||e.$value||e.$max}function v_(t){Br.call(this,null,t),this.modified(!0)}function y_(t,e,n){Object(ct.D)(t[e])&&t[e](n)}u_.Definition={type:"GeoPath",metadata:{modifies:!0},params:[{name:"projection",type:"projection"},{name:"field",type:"field"},{name:"pointRadius",type:"number",expr:!0},{name:"as",type:"string",default:"path"}]},Object(ct.y)(u_,Br).transform=function(t,e){var n=e.fork(e.ALL),r=this.value,i=t.field||ct.x,a=t.as||"path",o=n.SOURCE;!r||t.modified()?(this.value=r=a_(t.projection),n.materialize().reflow()):o=i===ct.x||e.modified(i.fields)?n.ADD_MOD:n.ADD;var s=function(t,e){var n=t.pointRadius();t.context(null),null!=e&&t.pointRadius(e);return n}(r,t.pointRadius);return n.visit(o,function(t){t[a]=r(i(t))}),r.pointRadius(s),n.modifies(a)},c_.Definition={type:"GeoPoint",metadata:{modifies:!0},params:[{name:"projection",type:"projection",required:!0},{name:"fields",type:"field",array:!0,required:!0,length:2},{name:"as",type:"string",array:!0,length:2,default:["x","y"]}]},Object(ct.y)(c_,Br).transform=function(t,e){var n,r=t.projection,i=t.fields[0],a=t.fields[1],o=t.as||["x","y"],s=o[0],u=o[1];function c(t){var e=r([i(t),a(t)]);e?(t[s]=e[0],t[u]=e[1]):(t[s]=void 0,t[u]=void 0)}return t.modified()?e=e.materialize().reflow(!0).visit(e.SOURCE,c):(n=e.modified(i.fields)||e.modified(a.fields),e.visit(n?e.ADD_MOD:e.ADD,c)),e.modifies(o)},l_.Definition={type:"GeoShape",metadata:{modifies:!0,nomod:!0},params:[{name:"projection",type:"projection"},{name:"field",type:"field",default:"datum"},{name:"pointRadius",type:"number",expr:!0},{name:"as",type:"string",default:"shape"}]},Object(ct.y)(l_,Br).transform=function(t,e){var n=e.fork(e.ALL),r=this.value,i=t.as||"shape",a=n.ADD;return r&&!t.modified()||(this.value=r=function(t,e,n){var r=null==n?function(n){return t(e(n))}:function(r){var i=t.pointRadius(),a=t.pointRadius(n)(e(r));return t.pointRadius(i),a};return r.context=function(e){return t.context(e),r},r}(a_(t.projection),t.field||Object(ct.t)("datum"),t.pointRadius),n.materialize().reflow(),a=n.SOURCE),n.visit(a,function(t){t[i]=r}),n.modifies(i)},p_.Definition={type:"Graticule",metadata:{changes:!0,generates:!0},params:[{name:"extent",type:"array",array:!0,length:2,content:{type:"number",array:!0,length:2}},{name:"extentMajor",type:"array",array:!0,length:2,content:{type:"number",array:!0,length:2}},{name:"extentMinor",type:"array",array:!0,length:2,content:{type:"number",array:!0,length:2}},{name:"step",type:"number",array:!0,length:2},{name:"stepMajor",type:"number",array:!0,length:2,default:[90,360]},{name:"stepMinor",type:"number",array:!0,length:2,default:[10,10]},{name:"precision",type:"number",default:2.5}]},Object(ct.y)(p_,Br).transform=function(t,e){var n,r=this.value,i=this.generator;if(!r.length||t.modified())for(var a in t)Object(ct.D)(i[a])&&i[a](t[a]);return n=i(),r.length?e.mod.push(xt(r[0],n)):e.add.push(vt(n)),r[0]=n,e},m_.Definition={type:"heatmap",metadata:{modifies:!0},params:[{name:"field",type:"field"},{name:"color",type:"string",expr:!0},{name:"opacity",type:"number",expr:!0},{name:"resolve",type:"enum",values:["shared","independent"],default:"independent"},{name:"as",type:"string",default:"image"}]},Object(ct.y)(m_,Br).transform=function(t,e){if(!e.changed()&&!t.modified())return e.StopPropagation;var n=e.materialize(e.SOURCE).source,r="shared"===t.resolve,i=t.field||ct.x,a=function(t,e){let n;Object(ct.D)(t)?(n=(n=>t(n,e))).dep=g_(t):t?n=Object(ct.l)(t):(n=(t=>t.$value/t.$max||0)).dep=!0;return n}(t.opacity,t),o=function(t,e){let n;Object(ct.D)(t)?(n=(n=>bm(t(n,e)))).dep=g_(t):n=Object(ct.l)(bm(t||"#888"));return n}(t.color,t),s=t.as||"image",u={$x:0,$y:0,$value:0,$max:r?ei(n.map(t=>ei(i(t).values))):0};return n.forEach(t=>{const e=i(t),n=Object(ct.o)({},t,u);r||(n.$max=ei(e.values||[])),t[s]=function(t,e,n,r){const i=t.width,a=t.height,o=t.x1||0,s=t.y1||0,u=t.x2||i,c=t.y2||a,l=t.values,f=l?t=>l[t]:ct.Ka,d=Au(u-o,c-s),h=d.getContext("2d"),p=h.getImageData(0,0,u-o,c-s),m=p.data;for(let t=s,a=0;t<c;++t){e.$y=t-s;for(let s=o,c=t*i;s<u;++s,a+=4){e.$x=s-o,e.$value=f(s+c);const t=n(e);m[a+0]=t.r,m[a+1]=t.g,m[a+2]=t.b,m[a+3]=~~(255*r(e))}}return h.putImageData(p,0,0),d}(e,n,o.dep?o:Object(ct.l)(o(n)),a.dep?a:Object(ct.l)(a(n)))}),e.reflow(!0).modifies(s)},Object(ct.y)(v_,Br).transform=function(t,e){var n=this.value;return!n||t.modified("type")?(this.value=n=function(t){var e=i_((t||"mercator").toLowerCase());e||Object(ct.n)("Unrecognized projection type: "+t);return e()}(t.type),r_.forEach(function(e){null!=t[e]&&y_(n,e,t[e])})):r_.forEach(function(e){t.modified(e)&&y_(n,e,t[e])}),null!=t.pointRadius&&n.path.pointRadius(t.pointRadius),t.fit&&function(t,e){var n=function(t){return 1===(t=Object(ct.i)(t)).length?t[0]:{type:Ub,features:t.reduce((t,e)=>t.concat(function(t){return t.type===Ub?t.features:Object(ct.i)(t).filter(t=>null!=t).map(t=>t.type===Bb?t:{type:Bb,geometry:t})}(e)),[])}}(e.fit);e.extent?t.fitExtent(e.extent,n):e.size&&t.fitSize(e.size,n)}(n,t),e.fork(e.NO_SOURCE|e.NO_FIELDS)};function b_(t,e,n,r){if(isNaN(e)||isNaN(n))return t;var i,a,o,s,u,c,l,f,d,h=t._root,p={data:r},m=t._x0,g=t._y0,v=t._x1,y=t._y1;if(!h)return t._root=p,t;for(;h.length;)if((c=e>=(a=(m+v)/2))?m=a:v=a,(l=n>=(o=(g+y)/2))?g=o:y=o,i=h,!(h=h[f=l<<1|c]))return i[f]=p,t;if(s=+t._x.call(null,h.data),u=+t._y.call(null,h.data),e===s&&n===u)return p.next=h,i?i[f]=p:t._root=p,t;do{i=i?i[f]=new Array(4):t._root=new Array(4),(c=e>=(a=(m+v)/2))?m=a:v=a,(l=n>=(o=(g+y)/2))?g=o:y=o}while((f=l<<1|c)==(d=(u>=o)<<1|s>=a));return i[d]=h,i[f]=p,t}var x_=function(t,e,n,r,i){this.node=t,this.x0=e,this.y0=n,this.x1=r,this.y1=i};function w_(t){return t[0]}function k_(t){return t[1]}function __(t,e,n){var r=new E_(null==e?w_:e,null==n?k_:n,NaN,NaN,NaN,NaN);return null==t?r:r.addAll(t)}function E_(t,e,n,r,i,a){this._x=t,this._y=e,this._x0=n,this._y0=r,this._x1=i,this._y1=a,this._root=void 0}function O_(t){for(var e={data:t.data},n=e;t=t.next;)n=n.next={data:t.data};return e}var S_=__.prototype=E_.prototype;S_.copy=function(){var t,e,n=new E_(this._x,this._y,this._x0,this._y0,this._x1,this._y1),r=this._root;if(!r)return n;if(!r.length)return n._root=O_(r),n;for(t=[{source:r,target:n._root=new Array(4)}];r=t.pop();)for(var i=0;i<4;++i)(e=r.source[i])&&(e.length?t.push({source:e,target:r.target[i]=new Array(4)}):r.target[i]=O_(e));return n},S_.add=function(t){var e=+this._x.call(null,t),n=+this._y.call(null,t);return b_(this.cover(e,n),e,n,t)},S_.addAll=function(t){var e,n,r,i,a=t.length,o=new Array(a),s=new Array(a),u=1/0,c=1/0,l=-1/0,f=-1/0;for(n=0;n<a;++n)isNaN(r=+this._x.call(null,e=t[n]))||isNaN(i=+this._y.call(null,e))||(o[n]=r,s[n]=i,r<u&&(u=r),r>l&&(l=r),i<c&&(c=i),i>f&&(f=i));if(u>l||c>f)return this;for(this.cover(u,c).cover(l,f),n=0;n<a;++n)b_(this,o[n],s[n],t[n]);return this},S_.cover=function(t,e){if(isNaN(t=+t)||isNaN(e=+e))return this;var n=this._x0,r=this._y0,i=this._x1,a=this._y1;if(isNaN(n))i=(n=Math.floor(t))+1,a=(r=Math.floor(e))+1;else{for(var o,s,u=i-n,c=this._root;n>t||t>=i||r>e||e>=a;)switch(s=(e<r)<<1|t<n,(o=new Array(4))[s]=c,c=o,u*=2,s){case 0:i=n+u,a=r+u;break;case 1:n=i-u,a=r+u;break;case 2:i=n+u,r=a-u;break;case 3:n=i-u,r=a-u}this._root&&this._root.length&&(this._root=c)}return this._x0=n,this._y0=r,this._x1=i,this._y1=a,this},S_.data=function(){var t=[];return this.visit(function(e){if(!e.length)do{t.push(e.data)}while(e=e.next)}),t},S_.extent=function(t){return arguments.length?this.cover(+t[0][0],+t[0][1]).cover(+t[1][0],+t[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]},S_.find=function(t,e,n){var r,i,a,o,s,u,c,l=this._x0,f=this._y0,d=this._x1,h=this._y1,p=[],m=this._root;for(m&&p.push(new x_(m,l,f,d,h)),null==n?n=1/0:(l=t-n,f=e-n,d=t+n,h=e+n,n*=n);u=p.pop();)if(!(!(m=u.node)||(i=u.x0)>d||(a=u.y0)>h||(o=u.x1)<l||(s=u.y1)<f))if(m.length){var g=(i+o)/2,v=(a+s)/2;p.push(new x_(m[3],g,v,o,s),new x_(m[2],i,v,g,s),new x_(m[1],g,a,o,v),new x_(m[0],i,a,g,v)),(c=(e>=v)<<1|t>=g)&&(u=p[p.length-1],p[p.length-1]=p[p.length-1-c],p[p.length-1-c]=u)}else{var y=t-+this._x.call(null,m.data),b=e-+this._y.call(null,m.data),x=y*y+b*b;if(x<n){var w=Math.sqrt(n=x);l=t-w,f=e-w,d=t+w,h=e+w,r=m.data}}return r},S_.remove=function(t){if(isNaN(a=+this._x.call(null,t))||isNaN(o=+this._y.call(null,t)))return this;var e,n,r,i,a,o,s,u,c,l,f,d,h=this._root,p=this._x0,m=this._y0,g=this._x1,v=this._y1;if(!h)return this;if(h.length)for(;;){if((c=a>=(s=(p+g)/2))?p=s:g=s,(l=o>=(u=(m+v)/2))?m=u:v=u,e=h,!(h=h[f=l<<1|c]))return this;if(!h.length)break;(e[f+1&3]||e[f+2&3]||e[f+3&3])&&(n=e,d=f)}for(;h.data!==t;)if(r=h,!(h=h.next))return this;return(i=h.next)&&delete h.next,r?(i?r.next=i:delete r.next,this):e?(i?e[f]=i:delete e[f],(h=e[0]||e[1]||e[2]||e[3])&&h===(e[3]||e[2]||e[1]||e[0])&&!h.length&&(n?n[d]=h:this._root=h),this):(this._root=i,this)},S_.removeAll=function(t){for(var e=0,n=t.length;e<n;++e)this.remove(t[e]);return this},S_.root=function(){return this._root},S_.size=function(){var t=0;return this.visit(function(e){if(!e.length)do{++t}while(e=e.next)}),t},S_.visit=function(t){var e,n,r,i,a,o,s=[],u=this._root;for(u&&s.push(new x_(u,this._x0,this._y0,this._x1,this._y1));e=s.pop();)if(!t(u=e.node,r=e.x0,i=e.y0,a=e.x1,o=e.y1)&&u.length){var c=(r+a)/2,l=(i+o)/2;(n=u[3])&&s.push(new x_(n,c,l,a,o)),(n=u[2])&&s.push(new x_(n,r,l,c,o)),(n=u[1])&&s.push(new x_(n,c,i,a,l)),(n=u[0])&&s.push(new x_(n,r,i,c,l))}return this},S_.visitAfter=function(t){var e,n=[],r=[];for(this._root&&n.push(new x_(this._root,this._x0,this._y0,this._x1,this._y1));e=n.pop();){var i=e.node;if(i.length){var a,o=e.x0,s=e.y0,u=e.x1,c=e.y1,l=(o+u)/2,f=(s+c)/2;(a=i[0])&&n.push(new x_(a,o,s,l,f)),(a=i[1])&&n.push(new x_(a,l,s,u,f)),(a=i[2])&&n.push(new x_(a,o,f,l,c)),(a=i[3])&&n.push(new x_(a,l,f,u,c))}r.push(e)}for(;e=r.pop();)t(e.node,e.x0,e.y0,e.x1,e.y1);return this},S_.x=function(t){return arguments.length?(this._x=t,this):this._x},S_.y=function(t){return arguments.length?(this._y=t,this):this._y};var C_=function(t){return function(){return t}},A_=function(){return 1e-6*(Math.random()-.5)};function N_(t){return t.x+t.vx}function T_(t){return t.y+t.vy}function I_(t){return t.index}function D_(t,e){var n=t.get(e);if(!n)throw new Error("missing: "+e);return n}var M_={value:function(){}};function R_(){for(var t,e=0,n=arguments.length,r={};e<n;++e){if(!(t=arguments[e]+"")||t in r||/[\s.]/.test(t))throw new Error("illegal type: "+t);r[t]=[]}return new F_(r)}function F_(t){this._=t}function j_(t,e){for(var n,r=0,i=t.length;r<i;++r)if((n=t[r]).name===e)return n.value}function P_(t,e,n){for(var r=0,i=t.length;r<i;++r)if(t[r].name===e){t[r]=M_,t=t.slice(0,r).concat(t.slice(r+1));break}return null!=n&&t.push({name:e,value:n}),t}F_.prototype=R_.prototype={constructor:F_,on:function(t,e){var n,r=this._,i=function(t,e){return t.trim().split(/^|\s+/).map(function(t){var n="",r=t.indexOf(".");if(r>=0&&(n=t.slice(r+1),t=t.slice(0,r)),t&&!e.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:n}})}(t+"",r),a=-1,o=i.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++a<o;)if(n=(t=i[a]).type)r[n]=P_(r[n],t.name,e);else if(null==e)for(n in r)r[n]=P_(r[n],t.name,null);return this}for(;++a<o;)if((n=(t=i[a]).type)&&(n=j_(r[n],t.name)))return n},copy:function(){var t={},e=this._;for(var n in e)t[n]=e[n].slice();return new F_(t)},call:function(t,e){if((n=arguments.length-2)>0)for(var n,r,i=new Array(n),a=0;a<n;++a)i[a]=arguments[a+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(a=0,n=(r=this._[t]).length;a<n;++a)r[a].value.apply(e,i)},apply:function(t,e,n){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var r=this._[t],i=0,a=r.length;i<a;++i)r[i].value.apply(e,n)}};var L_,z_,B_=R_,U_=0,W_=0,V_=0,q_=1e3,H_=0,G_=0,$_=0,K_="object"==typeof performance&&performance.now?performance:Date,X_="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function Y_(){return G_||(X_(J_),G_=K_.now()+$_)}function J_(){G_=0}function Z_(){this._call=this._time=this._next=null}function Q_(t,e,n){var r=new Z_;return r.restart(t,e,n),r}function tE(){G_=(H_=K_.now())+$_,U_=W_=0;try{!function(){Y_(),++U_;for(var t,e=L_;e;)(t=G_-e._time)>=0&&e._call.call(null,t),e=e._next;--U_}()}finally{U_=0,function(){var t,e,n=L_,r=1/0;for(;n;)n._call?(r>n._time&&(r=n._time),t=n,n=n._next):(e=n._next,n._next=null,n=t?t._next=e:L_=e);z_=t,nE(r)}(),G_=0}}function eE(){var t=K_.now(),e=t-H_;e>q_&&($_-=e,H_=t)}function nE(t){U_||(W_&&(W_=clearTimeout(W_)),t-G_>24?(t<1/0&&(W_=setTimeout(tE,t-K_.now()-$_)),V_&&(V_=clearInterval(V_))):(V_||(H_=K_.now(),V_=setInterval(eE,q_)),U_=1,X_(tE)))}function rE(t){return t.x}function iE(t){return t.y}Z_.prototype=Q_.prototype={constructor:Z_,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?Y_():+n)+(null==e?0:+e),this._next||z_===this||(z_?z_._next=this:L_=this,z_=this),this._call=t,this._time=n,nE()},stop:function(){this._call&&(this._call=null,this._time=1/0,nE())}};var aE=10,oE=Math.PI*(3-Math.sqrt(5)),sE=function(t){var e,n=1,r=.001,i=1-Math.pow(r,1/300),a=0,o=.6,s=new Map,u=Q_(l),c=B_("tick","end");function l(){f(),c.call("tick",e),n<r&&(u.stop(),c.call("end",e))}function f(r){var u,c,l=t.length;void 0===r&&(r=1);for(var f=0;f<r;++f)for(n+=(a-n)*i,s.forEach(function(t){t(n)}),u=0;u<l;++u)null==(c=t[u]).fx?c.x+=c.vx*=o:(c.x=c.fx,c.vx=0),null==c.fy?c.y+=c.vy*=o:(c.y=c.fy,c.vy=0);return e}function d(){for(var e,n=0,r=t.length;n<r;++n){if((e=t[n]).index=n,null!=e.fx&&(e.x=e.fx),null!=e.fy&&(e.y=e.fy),isNaN(e.x)||isNaN(e.y)){var i=aE*Math.sqrt(n),a=n*oE;e.x=i*Math.cos(a),e.y=i*Math.sin(a)}(isNaN(e.vx)||isNaN(e.vy))&&(e.vx=e.vy=0)}}function h(e){return e.initialize&&e.initialize(t),e}return null==t&&(t=[]),d(),e={tick:f,restart:function(){return u.restart(l),e},stop:function(){return u.stop(),e},nodes:function(n){return arguments.length?(t=n,d(),s.forEach(h),e):t},alpha:function(t){return arguments.length?(n=+t,e):n},alphaMin:function(t){return arguments.length?(r=+t,e):r},alphaDecay:function(t){return arguments.length?(i=+t,e):+i},alphaTarget:function(t){return arguments.length?(a=+t,e):a},velocityDecay:function(t){return arguments.length?(o=1-t,e):1-o},force:function(t,n){return arguments.length>1?(null==n?s.delete(t):s.set(t,h(n)),e):s.get(t)},find:function(e,n,r){var i,a,o,s,u,c=0,l=t.length;for(null==r?r=1/0:r*=r,c=0;c<l;++c)(o=(i=e-(s=t[c]).x)*i+(a=n-s.y)*a)<r&&(u=s,r=o);return u},on:function(t,n){return arguments.length>1?(c.on(t,n),e):c.on(t)}}},uE={center:function(t,e){var n;function r(){var r,i,a=n.length,o=0,s=0;for(r=0;r<a;++r)o+=(i=n[r]).x,s+=i.y;for(o=o/a-t,s=s/a-e,r=0;r<a;++r)(i=n[r]).x-=o,i.y-=s}return null==t&&(t=0),null==e&&(e=0),r.initialize=function(t){n=t},r.x=function(e){return arguments.length?(t=+e,r):t},r.y=function(t){return arguments.length?(e=+t,r):e},r},collide:function(t){var e,n,r=1,i=1;function a(){for(var t,a,s,u,c,l,f,d=e.length,h=0;h<i;++h)for(a=__(e,N_,T_).visitAfter(o),t=0;t<d;++t)s=e[t],l=n[s.index],f=l*l,u=s.x+s.vx,c=s.y+s.vy,a.visit(p);function p(t,e,n,i,a){var o=t.data,d=t.r,h=l+d;if(!o)return e>u+h||i<u-h||n>c+h||a<c-h;if(o.index>s.index){var p=u-o.x-o.vx,m=c-o.y-o.vy,g=p*p+m*m;g<h*h&&(0===p&&(g+=(p=A_())*p),0===m&&(g+=(m=A_())*m),g=(h-(g=Math.sqrt(g)))/g*r,s.vx+=(p*=g)*(h=(d*=d)/(f+d)),s.vy+=(m*=g)*h,o.vx-=p*(h=1-h),o.vy-=m*h)}}}function o(t){if(t.data)return t.r=n[t.data.index];for(var e=t.r=0;e<4;++e)t[e]&&t[e].r>t.r&&(t.r=t[e].r)}function s(){if(e){var r,i,a=e.length;for(n=new Array(a),r=0;r<a;++r)i=e[r],n[i.index]=+t(i,r,e)}}return"function"!=typeof t&&(t=C_(null==t?1:+t)),a.initialize=function(t){e=t,s()},a.iterations=function(t){return arguments.length?(i=+t,a):i},a.strength=function(t){return arguments.length?(r=+t,a):r},a.radius=function(e){return arguments.length?(t="function"==typeof e?e:C_(+e),s(),a):t},a},nbody:function(){var t,e,n,r,i=C_(-30),a=1,o=1/0,s=.81;function u(r){var i,a=t.length,o=__(t,rE,iE).visitAfter(l);for(n=r,i=0;i<a;++i)e=t[i],o.visit(f)}function c(){if(t){var e,n,a=t.length;for(r=new Array(a),e=0;e<a;++e)n=t[e],r[n.index]=+i(n,e,t)}}function l(t){var e,n,i,a,o,s=0,u=0;if(t.length){for(i=a=o=0;o<4;++o)(e=t[o])&&(n=Math.abs(e.value))&&(s+=e.value,u+=n,i+=n*e.x,a+=n*e.y);t.x=i/u,t.y=a/u}else{(e=t).x=e.data.x,e.y=e.data.y;do{s+=r[e.data.index]}while(e=e.next)}t.value=s}function f(t,i,u,c){if(!t.value)return!0;var l=t.x-e.x,f=t.y-e.y,d=c-i,h=l*l+f*f;if(d*d/s<h)return h<o&&(0===l&&(h+=(l=A_())*l),0===f&&(h+=(f=A_())*f),h<a&&(h=Math.sqrt(a*h)),e.vx+=l*t.value*n/h,e.vy+=f*t.value*n/h),!0;if(!(t.length||h>=o)){(t.data!==e||t.next)&&(0===l&&(h+=(l=A_())*l),0===f&&(h+=(f=A_())*f),h<a&&(h=Math.sqrt(a*h)));do{t.data!==e&&(d=r[t.data.index]*n/h,e.vx+=l*d,e.vy+=f*d)}while(t=t.next)}}return u.initialize=function(e){t=e,c()},u.strength=function(t){return arguments.length?(i="function"==typeof t?t:C_(+t),c(),u):i},u.distanceMin=function(t){return arguments.length?(a=t*t,u):Math.sqrt(a)},u.distanceMax=function(t){return arguments.length?(o=t*t,u):Math.sqrt(o)},u.theta=function(t){return arguments.length?(s=t*t,u):Math.sqrt(s)},u},link:function(t){var e,n,r,i,a,o=I_,s=function(t){return 1/Math.min(i[t.source.index],i[t.target.index])},u=C_(30),c=1;function l(r){for(var i=0,o=t.length;i<c;++i)for(var s,u,l,f,d,h,p,m=0;m<o;++m)u=(s=t[m]).source,f=(l=s.target).x+l.vx-u.x-u.vx||A_(),d=l.y+l.vy-u.y-u.vy||A_(),f*=h=((h=Math.sqrt(f*f+d*d))-n[m])/h*r*e[m],d*=h,l.vx-=f*(p=a[m]),l.vy-=d*p,u.vx+=f*(p=1-p),u.vy+=d*p}function f(){if(r){var s,u,c=r.length,l=t.length,f=new Map(r.map((t,e)=>[o(t,e,r),t]));for(s=0,i=new Array(c);s<l;++s)(u=t[s]).index=s,"object"!=typeof u.source&&(u.source=D_(f,u.source)),"object"!=typeof u.target&&(u.target=D_(f,u.target)),i[u.source.index]=(i[u.source.index]||0)+1,i[u.target.index]=(i[u.target.index]||0)+1;for(s=0,a=new Array(l);s<l;++s)u=t[s],a[s]=i[u.source.index]/(i[u.source.index]+i[u.target.index]);e=new Array(l),d(),n=new Array(l),h()}}function d(){if(r)for(var n=0,i=t.length;n<i;++n)e[n]=+s(t[n],n,t)}function h(){if(r)for(var e=0,i=t.length;e<i;++e)n[e]=+u(t[e],e,t)}return null==t&&(t=[]),l.initialize=function(t){r=t,f()},l.links=function(e){return arguments.length?(t=e,f(),l):t},l.id=function(t){return arguments.length?(o=t,l):o},l.iterations=function(t){return arguments.length?(c=+t,l):c},l.strength=function(t){return arguments.length?(s="function"==typeof t?t:C_(+t),d(),l):s},l.distance=function(t){return arguments.length?(u="function"==typeof t?t:C_(+t),h(),l):u},l},x:function(t){var e,n,r,i=C_(.1);function a(t){for(var i,a=0,o=e.length;a<o;++a)(i=e[a]).vx+=(r[a]-i.x)*n[a]*t}function o(){if(e){var a,o=e.length;for(n=new Array(o),r=new Array(o),a=0;a<o;++a)n[a]=isNaN(r[a]=+t(e[a],a,e))?0:+i(e[a],a,e)}}return"function"!=typeof t&&(t=C_(null==t?0:+t)),a.initialize=function(t){e=t,o()},a.strength=function(t){return arguments.length?(i="function"==typeof t?t:C_(+t),o(),a):i},a.x=function(e){return arguments.length?(t="function"==typeof e?e:C_(+e),o(),a):t},a},y:function(t){var e,n,r,i=C_(.1);function a(t){for(var i,a=0,o=e.length;a<o;++a)(i=e[a]).vy+=(r[a]-i.y)*n[a]*t}function o(){if(e){var a,o=e.length;for(n=new Array(o),r=new Array(o),a=0;a<o;++a)n[a]=isNaN(r[a]=+t(e[a],a,e))?0:+i(e[a],a,e)}}return"function"!=typeof t&&(t=C_(null==t?0:+t)),a.initialize=function(t){e=t,o()},a.strength=function(t){return arguments.length?(i="function"==typeof t?t:C_(+t),o(),a):i},a.y=function(e){return arguments.length?(t="function"==typeof e?e:C_(+e),o(),a):t},a}},cE="forces",lE=["alpha","alphaMin","alphaTarget","velocityDecay","forces"],fE=["static","iterations"],dE=["x","y","vx","vy"];function hE(t){Br.call(this,null,t)}hE.Definition={type:"Force",metadata:{modifies:!0},params:[{name:"static",type:"boolean",default:!1},{name:"restart",type:"boolean",default:!1},{name:"iterations",type:"number",default:300},{name:"alpha",type:"number",default:1},{name:"alphaMin",type:"number",default:.001},{name:"alphaTarget",type:"number",default:0},{name:"velocityDecay",type:"number",default:.4},{name:"forces",type:"param",array:!0,params:[{key:{force:"center"},params:[{name:"x",type:"number",default:0},{name:"y",type:"number",default:0}]},{key:{force:"collide"},params:[{name:"radius",type:"number",expr:!0},{name:"strength",type:"number",default:.7},{name:"iterations",type:"number",default:1}]},{key:{force:"nbody"},params:[{name:"strength",type:"number",default:-30},{name:"theta",type:"number",default:.9},{name:"distanceMin",type:"number",default:1},{name:"distanceMax",type:"number"}]},{key:{force:"link"},params:[{name:"links",type:"data"},{name:"id",type:"field"},{name:"distance",type:"number",default:30,expr:!0},{name:"strength",type:"number",expr:!0},{name:"iterations",type:"number",default:1}]},{key:{force:"x"},params:[{name:"strength",type:"number",default:.1},{name:"x",type:"field"}]},{key:{force:"y"},params:[{name:"strength",type:"number",default:.1},{name:"y",type:"field"}]}]},{name:"as",type:"string",array:!0,modify:!1,default:dE}]};var pE=Object(ct.y)(hE,Br);function mE(t,e,n,r){var i,a,o,s,u=Object(ct.i)(e.forces);for(i=0,a=lE.length;i<a;++i)(o=lE[i])!==cE&&e.modified(o)&&t[o](e[o]);for(i=0,a=u.length;i<a;++i)s=cE+i,(o=n||e.modified(cE,i)?vE(u[i]):r&&gE(u[i],r)?t.force(s):null)&&t.force(s,o);for(a=t.numForces||0;i<a;++i)t.force(cE+i,null);return t.numForces=u.length,t}function gE(t,e){var n,r;for(n in t)if(Object(ct.D)(r=t[n])&&e.modified(Object(ct.g)(r)))return 1;return 0}function vE(t){var e,n;for(n in Object(ct.v)(uE,t.force)||Object(ct.n)("Unrecognized force: "+t.force),e=uE[t.force](),t)Object(ct.D)(e[n])&&yE(e[n],t[n],t);return e}function yE(t,e,n){t(Object(ct.D)(e)?function(t){return e(t,n)}:e)}pE.transform=function(t,e){var n=this.value,r=e.changed(e.ADD_REM),i=t.modified(lE),a=t.iterations||300;if(n?(r&&(e.modifies("index"),n.nodes(e.source)),(i||e.changed(e.MOD))&&mE(n,t,0,e)):(this.value=n=function(t,e){var n=sE(t),r=!1,i=n.stop,a=n.restart;return n.stopped=function(){return r},n.restart=function(){return r=!1,a()},n.stop=function(){return r=!0,i()},mE(n,e,!0).on("end",function(){r=!0})}(e.source,t),n.on("tick",function(t,e){return function(){t.touch(e).run()}}(e.dataflow,this)),t.static||(r=!0,n.tick()),e.modifies("index")),i||r||t.modified(fE)||e.changed()&&t.restart)if(n.alpha(Math.max(n.alpha(),t.alpha||1)).alphaDecay(1-Math.pow(n.alphaMin(),1/a)),t.static)for(n.stop();--a>=0;)n.tick();else if(n.stopped()&&n.restart(),!r)return e.StopPropagation;return this.finish(t,e)},pE.finish=function(t,e){for(var n,r=e.dataflow,i=this._argops,a=0,o=i.length;a<o;++a)if((n=i[a]).name===cE&&"link"===n.op._argval.force)for(var s,u=n.op._argops,c=0,l=u.length;c<l;++c)if("links"===u[c].name&&(s=u[c].op.source)){r.pulse(s,r.changeset().reflow());break}return e.reflow(t.modified()).modifies(dE)};var bE=function(t,e,n){var r={};return t.each(function(t){var i=t.data;n(i)&&(r[e(i)]=t)}),t.lookup=r,t};function xE(t){var e=0,n=t.children,r=n&&n.length;if(r)for(;--r>=0;)e+=n[r].value;else e=1;t.value=e}function wE(t,e){var n,r,i,a,o,s=new OE(t),u=+t.value&&(s.value=t.value),c=[s];for(null==e&&(e=kE);n=c.pop();)if(u&&(n.value=+n.data.value),(i=e(n.data))&&(o=i.length))for(n.children=new Array(o),a=o-1;a>=0;--a)c.push(r=n.children[a]=new OE(i[a])),r.parent=n,r.depth=n.depth+1;return s.eachBefore(EE)}function kE(t){return t.children}function _E(t){t.data=t.data.data}function EE(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function OE(t){this.data=t,this.depth=this.height=0,this.parent=null}function SE(t){Br.call(this,null,t)}function CE(t){return t.values}function AE(t){Br.call(this,null,t)}function NE(t,e){return t.parent===e.parent?1:2}OE.prototype=wE.prototype={constructor:OE,count:function(){return this.eachAfter(xE)},each:function(t){var e,n,r,i,a=this,o=[a];do{for(e=o.reverse(),o=[];a=e.pop();)if(t(a),n=a.children)for(r=0,i=n.length;r<i;++r)o.push(n[r])}while(o.length);return this},eachAfter:function(t){for(var e,n,r,i=this,a=[i],o=[];i=a.pop();)if(o.push(i),e=i.children)for(n=0,r=e.length;n<r;++n)a.push(e[n]);for(;i=o.pop();)t(i);return this},eachBefore:function(t){for(var e,n,r=this,i=[r];r=i.pop();)if(t(r),e=r.children)for(n=e.length-1;n>=0;--n)i.push(e[n]);return this},sum:function(t){return this.eachAfter(function(e){for(var n=+t(e.data)||0,r=e.children,i=r&&r.length;--i>=0;)n+=r[i].value;e.value=n})},sort:function(t){return this.eachBefore(function(e){e.children&&e.children.sort(t)})},path:function(t){for(var e=this,n=function(t,e){if(t===e)return t;var n=t.ancestors(),r=e.ancestors(),i=null;for(t=n.pop(),e=r.pop();t===e;)i=t,t=n.pop(),e=r.pop();return i}(e,t),r=[e];e!==n;)e=e.parent,r.push(e);for(var i=r.length;t!==n;)r.splice(i,0,t),t=t.parent;return r},ancestors:function(){for(var t=this,e=[t];t=t.parent;)e.push(t);return e},descendants:function(){var t=[];return this.each(function(e){t.push(e)}),t},leaves:function(){var t=[];return this.eachBefore(function(e){e.children||t.push(e)}),t},links:function(){var t=this,e=[];return t.each(function(n){n!==t&&e.push({source:n.parent,target:n})}),e},copy:function(){return wE(this).eachBefore(_E)}},SE.Definition={type:"Nest",metadata:{treesource:!0,changes:!0},params:[{name:"keys",type:"field",array:!0},{name:"generate",type:"boolean"}]},Object(ct.y)(SE,Br).transform=function(t,e){e.source||Object(ct.n)("Nest transform requires an upstream data source.");var n=t.generate,r=t.modified(),i=e.clone(),a=this.value;return(!a||r||e.changed())&&(a&&a.each(t=>{t.children&&pt(t.data)&&i.rem.push(t.data)}),this.value=a=wE({values:Object(ct.i)(t.keys).reduce((t,e)=>(t.key(e),t),function(){var t,e=[];return t={entries:t=>(function t(n,r){if(++r>e.length)return n;var i,a=[];for(i in n)a.push({key:i,values:t(n[i],r)});return a})(function t(n,r){if(r>=e.length)return n;var i,a,o,s=-1,u=n.length,c=e[r++],l={},f={};for(;++s<u;)i=c(a=n[s])+"",(o=l[i])?o.push(a):l[i]=[a];for(i in l)f[i]=t(l[i],r);return f}(t,0),0),key:n=>(e.push(n),t)}}()).entries(i.source)},CE),n&&a.each(t=>{t.children&&(t=vt(t.data),i.add.push(t),i.source.push(t))}),bE(a,mt,mt)),i.source.root=a,i},Object(ct.y)(AE,Br).transform=function(t,e){e.source&&e.source.root||Object(ct.n)(this.constructor.name+" transform requires a backing tree data source.");var n=this.layout(t.method),r=this.fields,i=e.source.root,a=t.as||r;t.field?i.sum(t.field):i.count(),t.sort&&i.sort(wt(t.sort,t=>t.data)),function(t,e,n){for(var r,i=0,a=e.length;i<a;++i)(r=e[i])in n&&t[r](n[r])}(n,this.params,t),n.separation&&n.separation(!1!==t.separation?NE:ct.O);try{this.value=n(i)}catch(t){Object(ct.n)(t)}return i.each(function(t){!function(t,e,n){for(var r=t.data,i=0,a=e.length-1;i<a;++i)r[n[i]]=t[e[i]];r[n[a]]=t.children?t.children.length:0}(t,r,a)}),e.reflow(t.modified()).modifies(a).modifies("leaf")};var TE=Array.prototype.slice;var IE=function(t){for(var e,n,r=0,i=(t=function(t){for(var e,n,r=t.length;r;)n=Math.random()*r--|0,e=t[r],t[r]=t[n],t[n]=e;return t}(TE.call(t))).length,a=[];r<i;)e=t[r],n&&RE(n,e)?++r:(n=jE(a=DE(a,e)),r=0);return n};function DE(t,e){var n,r;if(FE(e,t))return[e];for(n=0;n<t.length;++n)if(ME(e,t[n])&&FE(PE(t[n],e),t))return[t[n],e];for(n=0;n<t.length-1;++n)for(r=n+1;r<t.length;++r)if(ME(PE(t[n],t[r]),e)&&ME(PE(t[n],e),t[r])&&ME(PE(t[r],e),t[n])&&FE(LE(t[n],t[r],e),t))return[t[n],t[r],e];throw new Error}function ME(t,e){var n=t.r-e.r,r=e.x-t.x,i=e.y-t.y;return n<0||n*n<r*r+i*i}function RE(t,e){var n=t.r-e.r+1e-6,r=e.x-t.x,i=e.y-t.y;return n>0&&n*n>r*r+i*i}function FE(t,e){for(var n=0;n<e.length;++n)if(!RE(t,e[n]))return!1;return!0}function jE(t){switch(t.length){case 1:return function(t){return{x:t.x,y:t.y,r:t.r}}(t[0]);case 2:return PE(t[0],t[1]);case 3:return LE(t[0],t[1],t[2])}}function PE(t,e){var n=t.x,r=t.y,i=t.r,a=e.x,o=e.y,s=e.r,u=a-n,c=o-r,l=s-i,f=Math.sqrt(u*u+c*c);return{x:(n+a+u/f*l)/2,y:(r+o+c/f*l)/2,r:(f+i+s)/2}}function LE(t,e,n){var r=t.x,i=t.y,a=t.r,o=e.x,s=e.y,u=e.r,c=n.x,l=n.y,f=n.r,d=r-o,h=r-c,p=i-s,m=i-l,g=u-a,v=f-a,y=r*r+i*i-a*a,b=y-o*o-s*s+u*u,x=y-c*c-l*l+f*f,w=h*p-d*m,k=(p*x-m*b)/(2*w)-r,_=(m*g-p*v)/w,E=(h*b-d*x)/(2*w)-i,O=(d*v-h*g)/w,S=_*_+O*O-1,C=2*(a+k*_+E*O),A=k*k+E*E-a*a,N=-(S?(C+Math.sqrt(C*C-4*S*A))/(2*S):A/C);return{x:r+k+_*N,y:i+E+O*N,r:N}}function zE(t,e,n){var r,i,a,o,s=t.x-e.x,u=t.y-e.y,c=s*s+u*u;c?(i=e.r+n.r,i*=i,o=t.r+n.r,i>(o*=o)?(r=(c+o-i)/(2*c),a=Math.sqrt(Math.max(0,o/c-r*r)),n.x=t.x-r*s-a*u,n.y=t.y-r*u+a*s):(r=(c+i-o)/(2*c),a=Math.sqrt(Math.max(0,i/c-r*r)),n.x=e.x+r*s-a*u,n.y=e.y+r*u+a*s)):(n.x=e.x+n.r,n.y=e.y)}function BE(t,e){var n=t.r+e.r-1e-6,r=e.x-t.x,i=e.y-t.y;return n>0&&n*n>r*r+i*i}function UE(t){var e=t._,n=t.next._,r=e.r+n.r,i=(e.x*n.r+n.x*e.r)/r,a=(e.y*n.r+n.y*e.r)/r;return i*i+a*a}function WE(t){this._=t,this.next=null,this.previous=null}function VE(t){if(!(i=t.length))return 0;var e,n,r,i,a,o,s,u,c,l,f;if((e=t[0]).x=0,e.y=0,!(i>1))return e.r;if(n=t[1],e.x=-n.r,n.x=e.r,n.y=0,!(i>2))return e.r+n.r;zE(n,e,r=t[2]),e=new WE(e),n=new WE(n),r=new WE(r),e.next=r.previous=n,n.next=e.previous=r,r.next=n.previous=e;t:for(s=3;s<i;++s){zE(e._,n._,r=t[s]),r=new WE(r),u=n.next,c=e.previous,l=n._.r,f=e._.r;do{if(l<=f){if(BE(u._,r._)){n=u,e.next=n,n.previous=e,--s;continue t}l+=u._.r,u=u.next}else{if(BE(c._,r._)){(e=c).next=n,n.previous=e,--s;continue t}f+=c._.r,c=c.previous}}while(u!==c.next);for(r.previous=e,r.next=n,e.next=n.previous=n=r,a=UE(e);(r=r.next)!==n;)(o=UE(r))<a&&(e=r,a=o);n=e.next}for(e=[n._],r=n;(r=r.next)!==n;)e.push(r._);for(r=IE(e),s=0;s<i;++s)(e=t[s]).x-=r.x,e.y-=r.y;return r.r}function qE(t){if("function"!=typeof t)throw new Error;return t}function HE(){return 0}var GE=function(t){return function(){return t}};function $E(t){return Math.sqrt(t.value)}function KE(t){return function(e){e.children||(e.r=Math.max(0,+t(e)||0))}}function XE(t,e){return function(n){if(r=n.children){var r,i,a,o=r.length,s=t(n)*e||0;if(s)for(i=0;i<o;++i)r[i].r+=s;if(a=VE(r),s)for(i=0;i<o;++i)r[i].r-=s;n.r=a+s}}}function YE(t){return function(e){var n=e.parent;e.r*=t,n&&(e.x=n.x+t*e.x,e.y=n.y+t*e.y)}}var JE=["x","y","r","depth","children"];function ZE(t){AE.call(this,t)}ZE.Definition={type:"Pack",metadata:{tree:!0,modifies:!0},params:[{name:"field",type:"field"},{name:"sort",type:"compare"},{name:"padding",type:"number",default:0},{name:"radius",type:"field",default:null},{name:"size",type:"number",array:!0,length:2},{name:"as",type:"string",array:!0,length:JE.length,default:JE}]};var QE=Object(ct.y)(ZE,AE);QE.layout=function(){var t=null,e=1,n=1,r=HE;function i(i){return i.x=e/2,i.y=n/2,t?i.eachBefore(KE(t)).eachAfter(XE(r,.5)).eachBefore(YE(1)):i.eachBefore(KE($E)).eachAfter(XE(HE,1)).eachAfter(XE(r,i.r/Math.min(e,n))).eachBefore(YE(Math.min(e,n)/(2*i.r))),i}return i.radius=function(e){return arguments.length?(t=function(t){return null==t?null:qE(t)}(e),i):t},i.size=function(t){return arguments.length?(e=+t[0],n=+t[1],i):[e,n]},i.padding=function(t){return arguments.length?(r="function"==typeof t?t:GE(+t),i):r},i},QE.params=["radius","size","padding"],QE.fields=JE;var tO=function(t){t.x0=Math.round(t.x0),t.y0=Math.round(t.y0),t.x1=Math.round(t.x1),t.y1=Math.round(t.y1)},eO=function(t,e,n,r,i){for(var a,o=t.children,s=-1,u=o.length,c=t.value&&(r-e)/t.value;++s<u;)(a=o[s]).y0=n,a.y1=i,a.x0=e,a.x1=e+=a.value*c},nO=["x0","y0","x1","y1","depth","children"];function rO(t){AE.call(this,t)}rO.Definition={type:"Partition",metadata:{tree:!0,modifies:!0},params:[{name:"field",type:"field"},{name:"sort",type:"compare"},{name:"padding",type:"number",default:0},{name:"round",type:"boolean",default:!1},{name:"size",type:"number",array:!0,length:2},{name:"as",type:"string",array:!0,length:nO.length,default:nO}]};var iO=Object(ct.y)(rO,AE);iO.layout=function(){var t=1,e=1,n=0,r=!1;function i(i){var a=i.height+1;return i.x0=i.y0=n,i.x1=t,i.y1=e/a,i.eachBefore(function(t,e){return function(r){r.children&&eO(r,r.x0,t*(r.depth+1)/e,r.x1,t*(r.depth+2)/e);var i=r.x0,a=r.y0,o=r.x1-n,s=r.y1-n;o<i&&(i=o=(i+o)/2),s<a&&(a=s=(a+s)/2),r.x0=i,r.y0=a,r.x1=o,r.y1=s}}(e,a)),r&&i.eachBefore(tO),i}return i.round=function(t){return arguments.length?(r=!!t,i):r},i.size=function(n){return arguments.length?(t=+n[0],e=+n[1],i):[t,e]},i.padding=function(t){return arguments.length?(n=+t,i):n},i},iO.params=["size","round","padding"],iO.fields=nO;var aO="$",oO={depth:-1},sO={};function uO(t){return t.id}function cO(t){return t.parentId}var lO=function(){var t=uO,e=cO;function n(n){var r,i,a,o,s,u,c,l=n.length,f=new Array(l),d={};for(i=0;i<l;++i)r=n[i],s=f[i]=new OE(r),null!=(u=t(r,i,n))&&(u+="")&&(d[c=aO+(s.id=u)]=c in d?sO:s);for(i=0;i<l;++i)if(s=f[i],null!=(u=e(n[i],i,n))&&(u+="")){if(!(o=d[aO+u]))throw new Error("missing: "+u);if(o===sO)throw new Error("ambiguous: "+u);o.children?o.children.push(s):o.children=[s],s.parent=o}else{if(a)throw new Error("multiple roots");a=s}if(!a)throw new Error("no root");if(a.parent=oO,a.eachBefore(function(t){t.depth=t.parent.depth+1,--l}).eachBefore(EE),a.parent=null,l>0)throw new Error("cycle");return a}return n.id=function(e){return arguments.length?(t=qE(e),n):t},n.parentId=function(t){return arguments.length?(e=qE(t),n):e},n};function fO(t){Br.call(this,null,t)}function dO(t,e){return t.parent===e.parent?1:2}function hO(t){var e=t.children;return e?e[0]:t.t}function pO(t){var e=t.children;return e?e[e.length-1]:t.t}function mO(t,e,n){var r=n/(e.i-t.i);e.c-=r,e.s+=n,t.c+=r,e.z+=n,e.m+=n}function gO(t,e,n){return t.a.parent===e.parent?t.a:n}function vO(t,e){this._=t,this.parent=null,this.children=null,this.A=null,this.a=this,this.z=0,this.m=0,this.c=0,this.s=0,this.t=null,this.i=e}fO.Definition={type:"Stratify",metadata:{treesource:!0},params:[{name:"key",type:"field",required:!0},{name:"parentKey",type:"field",required:!0}]},Object(ct.y)(fO,Br).transform=function(t,e){e.source||Object(ct.n)("Stratify transform requires an upstream data source.");var n=this.value,r=t.modified(),i=e.fork(e.ALL).materialize(e.SOURCE),a=!this.value||r||e.changed(e.ADD_REM)||e.modified(t.key.fields)||e.modified(t.parentKey.fields);return i.source=i.source.slice(),a&&(n=i.source.length?bE(lO().id(t.key).parentId(t.parentKey)(i.source),t.key,ct.Ga):bE(lO()([{}]),t.key,t.key)),i.source.root=this.value=n,i},vO.prototype=Object.create(OE.prototype);function yO(t,e){return t.parent===e.parent?1:2}function bO(t,e){return t+e.x}function xO(t,e){return Math.max(t,e.y)}var wO={tidy:function(){var t=dO,e=1,n=1,r=null;function i(i){var u=function(t){for(var e,n,r,i,a,o=new vO(t,0),s=[o];e=s.pop();)if(r=e._.children)for(e.children=new Array(a=r.length),i=a-1;i>=0;--i)s.push(n=e.children[i]=new vO(r[i],i)),n.parent=e;return(o.parent=new vO(null,0)).children=[o],o}(i);if(u.eachAfter(a),u.parent.m=-u.z,u.eachBefore(o),r)i.eachBefore(s);else{var c=i,l=i,f=i;i.eachBefore(function(t){t.x<c.x&&(c=t),t.x>l.x&&(l=t),t.depth>f.depth&&(f=t)});var d=c===l?1:t(c,l)/2,h=d-c.x,p=e/(l.x+d+h),m=n/(f.depth||1);i.eachBefore(function(t){t.x=(t.x+h)*p,t.y=t.depth*m})}return i}function a(e){var n=e.children,r=e.parent.children,i=e.i?r[e.i-1]:null;if(n){!function(t){for(var e,n=0,r=0,i=t.children,a=i.length;--a>=0;)(e=i[a]).z+=n,e.m+=n,n+=e.s+(r+=e.c)}(e);var a=(n[0].z+n[n.length-1].z)/2;i?(e.z=i.z+t(e._,i._),e.m=e.z-a):e.z=a}else i&&(e.z=i.z+t(e._,i._));e.parent.A=function(e,n,r){if(n){for(var i,a=e,o=e,s=n,u=a.parent.children[0],c=a.m,l=o.m,f=s.m,d=u.m;s=pO(s),a=hO(a),s&&a;)u=hO(u),(o=pO(o)).a=e,(i=s.z+f-a.z-c+t(s._,a._))>0&&(mO(gO(s,e,r),e,i),c+=i,l+=i),f+=s.m,c+=a.m,d+=u.m,l+=o.m;s&&!pO(o)&&(o.t=s,o.m+=f-l),a&&!hO(u)&&(u.t=a,u.m+=c-d,r=e)}return r}(e,i,e.parent.A||r[0])}function o(t){t._.x=t.z+t.parent.m,t.m+=t.parent.m}function s(t){t.x*=e,t.y=t.depth*n}return i.separation=function(e){return arguments.length?(t=e,i):t},i.size=function(t){return arguments.length?(r=!1,e=+t[0],n=+t[1],i):r?null:[e,n]},i.nodeSize=function(t){return arguments.length?(r=!0,e=+t[0],n=+t[1],i):r?[e,n]:null},i},cluster:function(){var t=yO,e=1,n=1,r=!1;function i(i){var a,o=0;i.eachAfter(function(e){var n=e.children;n?(e.x=function(t){return t.reduce(bO,0)/t.length}(n),e.y=function(t){return 1+t.reduce(xO,0)}(n)):(e.x=a?o+=t(e,a):0,e.y=0,a=e)});var s=function(t){for(var e;e=t.children;)t=e[0];return t}(i),u=function(t){for(var e;e=t.children;)t=e[e.length-1];return t}(i),c=s.x-t(s,u)/2,l=u.x+t(u,s)/2;return i.eachAfter(r?function(t){t.x=(t.x-i.x)*e,t.y=(i.y-t.y)*n}:function(t){t.x=(t.x-c)/(l-c)*e,t.y=(1-(i.y?t.y/i.y:1))*n})}return i.separation=function(e){return arguments.length?(t=e,i):t},i.size=function(t){return arguments.length?(r=!1,e=+t[0],n=+t[1],i):r?null:[e,n]},i.nodeSize=function(t){return arguments.length?(r=!0,e=+t[0],n=+t[1],i):r?[e,n]:null},i}},kO=["x","y","depth","children"];function _O(t){AE.call(this,t)}_O.Definition={type:"Tree",metadata:{tree:!0,modifies:!0},params:[{name:"field",type:"field"},{name:"sort",type:"compare"},{name:"method",type:"enum",default:"tidy",values:["tidy","cluster"]},{name:"size",type:"number",array:!0,length:2},{name:"nodeSize",type:"number",array:!0,length:2},{name:"separation",type:"boolean",default:!0},{name:"as",type:"string",array:!0,length:kO.length,default:kO}]};var EO=Object(ct.y)(_O,AE);function OO(t){Br.call(this,[],t)}EO.layout=function(t){var e=t||"tidy";if(Object(ct.v)(wO,e))return wO[e]();Object(ct.n)("Unrecognized Tree layout method: "+e)},EO.params=["size","nodeSize"],EO.fields=kO,OO.Definition={type:"TreeLinks",metadata:{tree:!0,generates:!0,changes:!0},params:[]},Object(ct.y)(OO,Br).transform=function(t,e){var n=this.value,r=e.source&&e.source.root,i=e.fork(e.NO_SOURCE),a={};return r||Object(ct.n)("TreeLinks transform requires a tree data source."),e.changed(e.ADD_REM)?(i.rem=n,e.visit(e.SOURCE,function(t){a[mt(t)]=1}),r.each(function(t){var e=t.data,n=t.parent&&t.parent.data;n&&a[mt(e)]&&a[mt(n)]&&i.add.push(vt({source:n,target:e}))}),this.value=i.add):e.changed(e.MOD)&&(e.visit(e.MOD,function(t){a[mt(t)]=1}),n.forEach(function(t){(a[mt(t.source)]||a[mt(t.target)])&&i.mod.push(t)})),i};var SO=function(t,e,n,r,i){for(var a,o=t.children,s=-1,u=o.length,c=t.value&&(i-n)/t.value;++s<u;)(a=o[s]).x0=e,a.x1=r,a.y0=n,a.y1=n+=a.value*c},CO=(1+Math.sqrt(5))/2;function AO(t,e,n,r,i,a){for(var o,s,u,c,l,f,d,h,p,m,g,v=[],y=e.children,b=0,x=0,w=y.length,k=e.value;b<w;){u=i-n,c=a-r;do{l=y[x++].value}while(!l&&x<w);for(f=d=l,g=l*l*(m=Math.max(c/u,u/c)/(k*t)),p=Math.max(d/g,g/f);x<w;++x){if(l+=s=y[x].value,s<f&&(f=s),s>d&&(d=s),g=l*l*m,(h=Math.max(d/g,g/f))>p){l-=s;break}p=h}v.push(o={value:l,dice:u<c,children:y.slice(b,x)}),o.dice?eO(o,n,r,i,k?r+=c*l/k:a):SO(o,n,r,k?n+=u*l/k:i,a),k-=l,b=x}return v}var NO=function t(e){function n(t,n,r,i,a){AO(e,t,n,r,i,a)}return n.ratio=function(e){return t((e=+e)>1?e:1)},n}(CO),TO=function t(e){function n(t,n,r,i,a){if((o=t._squarify)&&o.ratio===e)for(var o,s,u,c,l,f=-1,d=o.length,h=t.value;++f<d;){for(u=(s=o[f]).children,c=s.value=0,l=u.length;c<l;++c)s.value+=u[c].value;s.dice?eO(s,n,r,i,r+=(a-r)*s.value/h):SO(s,n,r,n+=(i-n)*s.value/h,a),h-=s.value}else t._squarify=o=AO(e,t,n,r,i,a),o.ratio=e}return n.ratio=function(e){return t((e=+e)>1?e:1)},n}(CO),IO={binary:function(t,e,n,r,i){var a,o,s=t.children,u=s.length,c=new Array(u+1);for(c[0]=o=a=0;a<u;++a)c[a+1]=o+=s[a].value;!function t(e,n,r,i,a,o,u){if(e>=n-1){var l=s[e];return l.x0=i,l.y0=a,l.x1=o,void(l.y1=u)}for(var f=c[e],d=r/2+f,h=e+1,p=n-1;h<p;){var m=h+p>>>1;c[m]<d?h=m+1:p=m}d-c[h-1]<c[h]-d&&e+1<h&&--h;var g=c[h]-f,v=r-g;if(o-i>u-a){var y=(i*v+o*g)/r;t(e,h,g,i,a,y,u),t(h,n,v,y,a,o,u)}else{var b=(a*v+u*g)/r;t(e,h,g,i,a,o,b),t(h,n,v,i,b,o,u)}}(0,u,t.value,e,n,r,i)},dice:eO,slice:SO,slicedice:function(t,e,n,r,i){(1&t.depth?SO:eO)(t,e,n,r,i)},squarify:NO,resquarify:TO},DO=["x0","y0","x1","y1","depth","children"];function MO(t){AE.call(this,t)}MO.Definition={type:"Treemap",metadata:{tree:!0,modifies:!0},params:[{name:"field",type:"field"},{name:"sort",type:"compare"},{name:"method",type:"enum",default:"squarify",values:["squarify","resquarify","binary","dice","slice","slicedice"]},{name:"padding",type:"number",default:0},{name:"paddingInner",type:"number",default:0},{name:"paddingOuter",type:"number",default:0},{name:"paddingTop",type:"number",default:0},{name:"paddingRight",type:"number",default:0},{name:"paddingBottom",type:"number",default:0},{name:"paddingLeft",type:"number",default:0},{name:"ratio",type:"number",default:1.618033988749895},{name:"round",type:"boolean",default:!1},{name:"size",type:"number",array:!0,length:2},{name:"as",type:"string",array:!0,length:DO.length,default:DO}]};var RO=Object(ct.y)(MO,AE);RO.layout=function(){var t=function(){var t=NO,e=!1,n=1,r=1,i=[0],a=HE,o=HE,s=HE,u=HE,c=HE;function l(t){return t.x0=t.y0=0,t.x1=n,t.y1=r,t.eachBefore(f),i=[0],e&&t.eachBefore(tO),t}function f(e){var n=i[e.depth],r=e.x0+n,l=e.y0+n,f=e.x1-n,d=e.y1-n;f<r&&(r=f=(r+f)/2),d<l&&(l=d=(l+d)/2),e.x0=r,e.y0=l,e.x1=f,e.y1=d,e.children&&(n=i[e.depth+1]=a(e)/2,r+=c(e)-n,l+=o(e)-n,f-=s(e)-n,d-=u(e)-n,f<r&&(r=f=(r+f)/2),d<l&&(l=d=(l+d)/2),t(e,r,l,f,d))}return l.round=function(t){return arguments.length?(e=!!t,l):e},l.size=function(t){return arguments.length?(n=+t[0],r=+t[1],l):[n,r]},l.tile=function(e){return arguments.length?(t=qE(e),l):t},l.padding=function(t){return arguments.length?l.paddingInner(t).paddingOuter(t):l.paddingInner()},l.paddingInner=function(t){return arguments.length?(a="function"==typeof t?t:GE(+t),l):a},l.paddingOuter=function(t){return arguments.length?l.paddingTop(t).paddingRight(t).paddingBottom(t).paddingLeft(t):l.paddingTop()},l.paddingTop=function(t){return arguments.length?(o="function"==typeof t?t:GE(+t),l):o},l.paddingRight=function(t){return arguments.length?(s="function"==typeof t?t:GE(+t),l):s},l.paddingBottom=function(t){return arguments.length?(u="function"==typeof t?t:GE(+t),l):u},l.paddingLeft=function(t){return arguments.length?(c="function"==typeof t?t:GE(+t),l):c},l}();return t.ratio=function(e){var n=t.tile();n.ratio&&t.tile(n.ratio(e))},t.method=function(e){Object(ct.v)(IO,e)?t.tile(IO[e]):Object(ct.n)("Unrecognized Treemap layout method: "+e)},t},RO.params=["method","ratio","size","round","padding","paddingInner","paddingOuter","paddingTop","paddingRight","paddingBottom","paddingLeft"],RO.fields=DO;var FO=function(t,e){var n,r,i,a,o,s,u=[],c=function(t){return t(a)};if(null==e)u.push(t);else for(n={},r=0,i=t.length;r<i;++r)a=t[r],(s=n[o=e.map(c)])||(n[o]=s=[],s.dims=o,u.push(s)),s.push(a);return u};function jO(t){Br.call(this,null,t)}jO.Definition={type:"Loess",metadata:{generates:!0},params:[{name:"x",type:"field",required:!0},{name:"y",type:"field",required:!0},{name:"groupby",type:"field",array:!0},{name:"bandwidth",type:"number",default:.3},{name:"as",type:"string",array:!0}]},Object(ct.y)(jO,Br).transform=function(t,e){var n=e.fork(e.NO_SOURCE|e.NO_FIELDS);if(!this.value||e.changed()||t.modified()){const r=e.materialize(e.SOURCE).source,i=FO(r,t.groupby),a=(t.groupby||[]).map(ct.h),o=a.length,s=t.as||[Object(ct.h)(t.x),Object(ct.h)(t.y)],u=[];i.forEach(e=>{$i(e,t.x,t.y,t.bandwidth||.3).forEach(t=>{const n={};for(let t=0;t<o;++t)n[a[t]]=e.dims[t];n[s[0]]=t[0],n[s[1]]=t[1],u.push(vt(n))})}),this.value&&(n.rem=this.value),this.value=n.add=n.source=u}return n};const PO={linear:Bi,log:Ui,exp:Wi,pow:Vi,quad:qi,poly:Hi};function LO(t){Br.call(this,null,t)}LO.Definition={type:"Regression",metadata:{generates:!0},params:[{name:"x",type:"field",required:!0},{name:"y",type:"field",required:!0},{name:"groupby",type:"field",array:!0},{name:"method",type:"string",default:"linear",values:Object.keys(PO)},{name:"order",type:"number",default:3},{name:"extent",type:"number",array:!0,length:2},{name:"params",type:"boolean",default:!1},{name:"as",type:"string",array:!0}]},Object(ct.y)(LO,Br).transform=function(t,e){var n=e.fork(e.NO_SOURCE|e.NO_FIELDS);if(!this.value||e.changed()||t.modified()){const r=e.materialize(e.SOURCE).source,i=FO(r,t.groupby),a=(t.groupby||[]).map(ct.h),o=t.method||"linear",s=t.order||3,u=function(t,e){return"poly"===t?e:"quad"===t?2:1}(o,s),c=t.as||[Object(ct.h)(t.x),Object(ct.h)(t.y)],l=PO[o],f=[];let d=t.extent;Object(ct.v)(PO,o)||Object(ct.n)("Invalid regression method: "+o),null!=d&&"log"===o&&d[0]<=0&&(e.dataflow.warn("Ignoring extent with values <= 0 for log regression."),d=null),i.forEach(n=>{if(n.length<=u)return void e.dataflow.warn("Skipping regression with more parameters than data points.");const r=l(n,t.x,t.y,s);if(t.params)return void f.push(vt({keys:n.dims,coef:r.coef,rSquared:r.rSquared}));const i=d||Object(ct.p)(n,t.x),h=t=>{const e={};for(let t=0;t<a.length;++t)e[a[t]]=n.dims[t];e[c[0]]=t[0],e[c[1]]=t[1],f.push(vt(e))};"linear"===o?i.forEach(t=>h([t,r.predict(t)])):Ji(r.predict,i,25,200).forEach(h)}),this.value&&(n.rem=this.value),this.value=n.add=n.source=f}return n};const zO=Math.pow(2,-52),BO=new Uint32Array(512);class UO{static from(t,e=function(t){return t[0]},n=function(t){return t[1]}){const r=t.length,i=new Float64Array(2*r);for(let a=0;a<r;a++){const r=t[a];i[2*a]=e(r),i[2*a+1]=n(r)}return new UO(i)}constructor(t){const e=t.length>>1;if(e>0&&"number"!=typeof t[0])throw new Error("Expected coords to contain numbers.");this.coords=t;const n=Math.max(2*e-5,0);this._triangles=new Uint32Array(3*n),this._halfedges=new Int32Array(3*n),this._hashSize=Math.ceil(Math.sqrt(e)),this._hullPrev=new Uint32Array(e),this._hullNext=new Uint32Array(e),this._hullTri=new Uint32Array(e),this._hullHash=new Int32Array(this._hashSize).fill(-1),this._ids=new Uint32Array(e),this._dists=new Float64Array(e),this.update()}update(){const{coords:t,_hullPrev:e,_hullNext:n,_hullTri:r,_hullHash:i}=this,a=t.length>>1;let o=1/0,s=1/0,u=-1/0,c=-1/0;for(let e=0;e<a;e++){const n=t[2*e],r=t[2*e+1];n<o&&(o=n),r<s&&(s=r),n>u&&(u=n),r>c&&(c=r),this._ids[e]=e}const l=(o+u)/2,f=(s+c)/2;let d,h,p,m=1/0;for(let e=0;e<a;e++){const n=WO(l,f,t[2*e],t[2*e+1]);n<m&&(d=e,m=n)}const g=t[2*d],v=t[2*d+1];m=1/0;for(let e=0;e<a;e++){if(e===d)continue;const n=WO(g,v,t[2*e],t[2*e+1]);n<m&&n>0&&(h=e,m=n)}let y=t[2*h],b=t[2*h+1],x=1/0;for(let e=0;e<a;e++){if(e===d||e===h)continue;const n=GO(g,v,y,b,t[2*e],t[2*e+1]);n<x&&(p=e,x=n)}let w=t[2*p],k=t[2*p+1];if(x===1/0){for(let e=0;e<a;e++)this._dists[e]=t[2*e]-t[0]||t[2*e+1]-t[1];$O(this._ids,this._dists,0,a-1);const e=new Uint32Array(a);let n=0;for(let t=0,r=-1/0;t<a;t++){const i=this._ids[t];this._dists[i]>r&&(e[n++]=i,r=this._dists[i])}return this.hull=e.subarray(0,n),this.triangles=new Uint32Array(0),void(this.halfedges=new Uint32Array(0))}if(qO(g,v,y,b,w,k)){const t=h,e=y,n=b;h=p,y=w,b=k,p=t,w=e,k=n}const _=function(t,e,n,r,i,a){const o=n-t,s=r-e,u=i-t,c=a-e,l=o*o+s*s,f=u*u+c*c,d=.5/(o*c-s*u);return{x:t+(c*l-s*f)*d,y:e+(o*f-u*l)*d}}(g,v,y,b,w,k);this._cx=_.x,this._cy=_.y;for(let e=0;e<a;e++)this._dists[e]=WO(t[2*e],t[2*e+1],_.x,_.y);$O(this._ids,this._dists,0,a-1),this._hullStart=d;let E=3;n[d]=e[p]=h,n[h]=e[d]=p,n[p]=e[h]=d,r[d]=0,r[h]=1,r[p]=2,i.fill(-1),i[this._hashKey(g,v)]=d,i[this._hashKey(y,b)]=h,i[this._hashKey(w,k)]=p,this.trianglesLen=0,this._addTriangle(d,h,p,-1,-1,-1);for(let a,o,s=0;s<this._ids.length;s++){const u=this._ids[s],c=t[2*u],l=t[2*u+1];if(s>0&&Math.abs(c-a)<=zO&&Math.abs(l-o)<=zO)continue;if(a=c,o=l,u===d||u===h||u===p)continue;let f=0;for(let t=0,e=this._hashKey(c,l);t<this._hashSize&&(-1===(f=i[(e+t)%this._hashSize])||f===n[f]);t++);let m,g=f=e[f];for(;m=n[g],!qO(c,l,t[2*g],t[2*g+1],t[2*m],t[2*m+1]);)if((g=m)===f){g=-1;break}if(-1===g)continue;let v=this._addTriangle(g,u,n[g],-1,-1,r[g]);r[u]=this._legalize(v+2),r[g]=v,E++;let y=n[g];for(;m=n[y],qO(c,l,t[2*y],t[2*y+1],t[2*m],t[2*m+1]);)v=this._addTriangle(y,u,m,r[u],-1,r[y]),r[u]=this._legalize(v+2),n[y]=y,E--,y=m;if(g===f)for(;qO(c,l,t[2*(m=e[g])],t[2*m+1],t[2*g],t[2*g+1]);)v=this._addTriangle(m,u,g,-1,r[g],r[m]),this._legalize(v+2),r[m]=v,n[g]=g,E--,g=m;this._hullStart=e[u]=g,n[g]=e[y]=u,n[u]=y,i[this._hashKey(c,l)]=u,i[this._hashKey(t[2*g],t[2*g+1])]=g}this.hull=new Uint32Array(E);for(let t=0,e=this._hullStart;t<E;t++)this.hull[t]=e,e=n[e];this.triangles=this._triangles.subarray(0,this.trianglesLen),this.halfedges=this._halfedges.subarray(0,this.trianglesLen)}_hashKey(t,e){return Math.floor(function(t,e){const n=t/(Math.abs(t)+Math.abs(e));return(e>0?3-n:1+n)/4}(t-this._cx,e-this._cy)*this._hashSize)%this._hashSize}_legalize(t){const{_triangles:e,_halfedges:n,coords:r}=this;let i=0,a=0;for(;;){const o=n[t],s=t-t%3;if(a=s+(t+2)%3,-1===o){if(0===i)break;t=BO[--i];continue}const u=o-o%3,c=s+(t+1)%3,l=u+(o+2)%3,f=e[a],d=e[t],h=e[c],p=e[l];if(HO(r[2*f],r[2*f+1],r[2*d],r[2*d+1],r[2*h],r[2*h+1],r[2*p],r[2*p+1])){e[t]=p,e[o]=f;const r=n[l];if(-1===r){let e=this._hullStart;do{if(this._hullTri[e]===l){this._hullTri[e]=t;break}e=this._hullPrev[e]}while(e!==this._hullStart)}this._link(t,r),this._link(o,n[a]),this._link(a,l);const s=u+(o+1)%3;i<BO.length&&(BO[i++]=s)}else{if(0===i)break;t=BO[--i]}}return a}_link(t,e){this._halfedges[t]=e,-1!==e&&(this._halfedges[e]=t)}_addTriangle(t,e,n,r,i,a){const o=this.trianglesLen;return this._triangles[o]=t,this._triangles[o+1]=e,this._triangles[o+2]=n,this._link(o,r),this._link(o+1,i),this._link(o+2,a),this.trianglesLen+=3,o}}function WO(t,e,n,r){const i=t-n,a=e-r;return i*i+a*a}function VO(t,e,n,r,i,a){const o=(r-e)*(i-t),s=(n-t)*(a-e);return Math.abs(o-s)>=3.3306690738754716e-16*Math.abs(o+s)?o-s:0}function qO(t,e,n,r,i,a){return(VO(i,a,t,e,n,r)||VO(t,e,n,r,i,a)||VO(n,r,i,a,t,e))<0}function HO(t,e,n,r,i,a,o,s){const u=t-o,c=e-s,l=n-o,f=r-s,d=i-o,h=a-s,p=l*l+f*f,m=d*d+h*h;return u*(f*m-p*h)-c*(l*m-p*d)+(u*u+c*c)*(l*h-f*d)<0}function GO(t,e,n,r,i,a){const o=n-t,s=r-e,u=i-t,c=a-e,l=o*o+s*s,f=u*u+c*c,d=.5/(o*c-s*u),h=(c*l-s*f)*d,p=(o*f-u*l)*d;return h*h+p*p}function $O(t,e,n,r){if(r-n<=20)for(let i=n+1;i<=r;i++){const r=t[i],a=e[r];let o=i-1;for(;o>=n&&e[t[o]]>a;)t[o+1]=t[o--];t[o+1]=r}else{let i=n+1,a=r;KO(t,n+r>>1,i),e[t[n]]>e[t[r]]&&KO(t,n,r),e[t[i]]>e[t[r]]&&KO(t,i,r),e[t[n]]>e[t[i]]&&KO(t,n,i);const o=t[i],s=e[o];for(;;){do{i++}while(e[t[i]]<s);do{a--}while(e[t[a]]>s);if(a<i)break;KO(t,i,a)}t[n+1]=t[a],t[a]=o,r-i+1>=a-n?($O(t,e,i,r),$O(t,e,n,a-1)):($O(t,e,n,a-1),$O(t,e,i,r))}}function KO(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}const XO=1e-6;class YO{constructor(){this._x0=this._y0=this._x1=this._y1=null,this._=""}moveTo(t,e){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}`}closePath(){null!==this._x1&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")}lineTo(t,e){this._+=`L${this._x1=+t},${this._y1=+e}`}arc(t,e,n){const r=(t=+t)+(n=+n),i=e=+e;if(n<0)throw new Error("negative radius");null===this._x1?this._+=`M${r},${i}`:(Math.abs(this._x1-r)>XO||Math.abs(this._y1-i)>XO)&&(this._+="L"+r+","+i),n&&(this._+=`A${n},${n},0,1,1,${t-n},${e}A${n},${n},0,1,1,${this._x1=r},${this._y1=i}`)}rect(t,e,n,r){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}h${+n}v${+r}h${-n}Z`}value(){return this._||null}}class JO{constructor(){this._=[]}moveTo(t,e){this._.push([t,e])}closePath(){this._.push(this._[0].slice())}lineTo(t,e){this._.push([t,e])}value(){return this._.length?this._:null}}class ZO{constructor(t,[e,n,r,i]=[0,0,960,500]){if(!((r=+r)>=(e=+e)&&(i=+i)>=(n=+n)))throw new Error("invalid bounds");this.delaunay=t,this._circumcenters=new Float64Array(2*t.points.length),this.vectors=new Float64Array(2*t.points.length),this.xmax=r,this.xmin=e,this.ymax=i,this.ymin=n,this._init()}update(){return this.delaunay.update(),this._init(),this}_init(){const{delaunay:{points:t,hull:e,triangles:n},vectors:r}=this,i=this.circumcenters=this._circumcenters.subarray(0,n.length/3*2);for(let e,r,a=0,o=0,s=n.length;a<s;a+=3,o+=2){const s=2*n[a],u=2*n[a+1],c=2*n[a+2],l=t[s],f=t[s+1],d=t[u],h=t[u+1],p=t[c],m=t[c+1],g=d-l,v=h-f,y=p-l,b=m-f,x=g*g+v*v,w=y*y+b*b,k=2*(g*b-v*y);if(k)if(Math.abs(k)<1e-8)e=(l+p)/2,r=(f+m)/2;else{const t=1/k;e=l+(b*x-v*w)*t,r=f+(g*w-y*x)*t}else e=(l+p)/2-1e8*b,r=(f+m)/2+1e8*y;i[o]=e,i[o+1]=r}let a,o,s,u=e[e.length-1],c=4*u,l=t[2*u],f=t[2*u+1];r.fill(0);for(let n=0;n<e.length;++n)a=c,o=l,s=f,c=4*(u=e[n]),l=t[2*u],f=t[2*u+1],r[a+2]=r[c]=s-f,r[a+3]=r[c+1]=l-o}render(t){const e=null==t?t=new YO:void 0,{delaunay:{halfedges:n,inedges:r,hull:i},circumcenters:a,vectors:o}=this;if(i.length<=1)return null;for(let e=0,r=n.length;e<r;++e){const r=n[e];if(r<e)continue;const i=2*Math.floor(e/3),o=2*Math.floor(r/3),s=a[i],u=a[i+1],c=a[o],l=a[o+1];this._renderSegment(s,u,c,l,t)}let s,u=i[i.length-1];for(let e=0;e<i.length;++e){s=u,u=i[e];const n=2*Math.floor(r[u]/3),c=a[n],l=a[n+1],f=4*s,d=this._project(c,l,o[f+2],o[f+3]);d&&this._renderSegment(c,l,d[0],d[1],t)}return e&&e.value()}renderBounds(t){const e=null==t?t=new YO:void 0;return t.rect(this.xmin,this.ymin,this.xmax-this.xmin,this.ymax-this.ymin),e&&e.value()}renderCell(t,e){const n=null==e?e=new YO:void 0,r=this._clip(t);if(null===r)return;e.moveTo(r[0],r[1]);let i=r.length;for(;r[0]===r[i-2]&&r[1]===r[i-1]&&i>1;)i-=2;for(let t=2;t<i;t+=2)r[t]===r[t-2]&&r[t+1]===r[t-1]||e.lineTo(r[t],r[t+1]);return e.closePath(),n&&n.value()}*cellPolygons(){const{delaunay:{points:t}}=this;for(let e=0,n=t.length/2;e<n;++e){const t=this.cellPolygon(e);t&&(yield t)}}cellPolygon(t){const e=new JO;return this.renderCell(t,e),e.value()}_renderSegment(t,e,n,r,i){let a;const o=this._regioncode(t,e),s=this._regioncode(n,r);0===o&&0===s?(i.moveTo(t,e),i.lineTo(n,r)):(a=this._clipSegment(t,e,n,r,o,s))&&(i.moveTo(a[0],a[1]),i.lineTo(a[2],a[3]))}contains(t,e,n){return(e=+e)==e&&(n=+n)==n&&this.delaunay._step(t,e,n)===t}*neighbors(t){const e=this._clip(t);if(e)for(const n of this.delaunay.neighbors(t)){const t=this._clip(n);if(t)t:for(let r=0,i=e.length;r<i;r+=2)for(let a=0,o=t.length;a<o;a+=2)if(e[r]==t[a]&&e[r+1]==t[a+1]&&e[(r+2)%i]==t[(a+o-2)%o]&&e[(r+3)%i]==t[(a+o-1)%o]){yield n;break t}}}_cell(t){const{circumcenters:e,delaunay:{inedges:n,halfedges:r,triangles:i}}=this,a=n[t];if(-1===a)return null;const o=[];let s=a;do{const n=Math.floor(s/3);if(o.push(e[2*n],e[2*n+1]),i[s=s%3==2?s-2:s+1]!==t)break;s=r[s]}while(s!==a&&-1!==s);return o}_clip(t){if(0===t&&1===this.delaunay.hull.length)return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];const e=this._cell(t);if(null===e)return null;const{vectors:n}=this,r=4*t;return n[r]||n[r+1]?this._clipInfinite(t,e,n[r],n[r+1],n[r+2],n[r+3]):this._clipFinite(t,e)}_clipFinite(t,e){const n=e.length;let r,i,a,o,s,u=null,c=e[n-2],l=e[n-1],f=this._regioncode(c,l);for(let d=0;d<n;d+=2)if(r=c,i=l,c=e[d],l=e[d+1],a=f,f=this._regioncode(c,l),0===a&&0===f)o=s,s=0,u?u.push(c,l):u=[c,l];else{let e,n,d,h,p;if(0===a){if(null===(e=this._clipSegment(r,i,c,l,a,f)))continue;[n,d,h,p]=e}else{if(null===(e=this._clipSegment(c,l,r,i,f,a)))continue;[h,p,n,d]=e,o=s,s=this._edgecode(n,d),o&&s&&this._edge(t,o,s,u,u.length),u?u.push(n,d):u=[n,d]}o=s,s=this._edgecode(h,p),o&&s&&this._edge(t,o,s,u,u.length),u?u.push(h,p):u=[h,p]}if(u)o=s,s=this._edgecode(u[0],u[1]),o&&s&&this._edge(t,o,s,u,u.length);else if(this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2))return[this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax,this.xmin,this.ymin];return u}_clipSegment(t,e,n,r,i,a){for(;;){if(0===i&&0===a)return[t,e,n,r];if(i&a)return null;let o,s,u=i||a;8&u?(o=t+(n-t)*(this.ymax-e)/(r-e),s=this.ymax):4&u?(o=t+(n-t)*(this.ymin-e)/(r-e),s=this.ymin):2&u?(s=e+(r-e)*(this.xmax-t)/(n-t),o=this.xmax):(s=e+(r-e)*(this.xmin-t)/(n-t),o=this.xmin),i?(t=o,e=s,i=this._regioncode(t,e)):(n=o,r=s,a=this._regioncode(n,r))}}_clipInfinite(t,e,n,r,i,a){let o,s=Array.from(e);if((o=this._project(s[0],s[1],n,r))&&s.unshift(o[0],o[1]),(o=this._project(s[s.length-2],s[s.length-1],i,a))&&s.push(o[0],o[1]),s=this._clipFinite(t,s))for(let e,n=0,r=s.length,i=this._edgecode(s[r-2],s[r-1]);n<r;n+=2)e=i,i=this._edgecode(s[n],s[n+1]),e&&i&&(n=this._edge(t,e,i,s,n),r=s.length);else this.contains(t,(this.xmin+this.xmax)/2,(this.ymin+this.ymax)/2)&&(s=[this.xmin,this.ymin,this.xmax,this.ymin,this.xmax,this.ymax,this.xmin,this.ymax]);return s}_edge(t,e,n,r,i){for(;e!==n;){let n,a;switch(e){case 5:e=4;continue;case 4:e=6,n=this.xmax,a=this.ymin;break;case 6:e=2;continue;case 2:e=10,n=this.xmax,a=this.ymax;break;case 10:e=8;continue;case 8:e=9,n=this.xmin,a=this.ymax;break;case 9:e=1;continue;case 1:e=5,n=this.xmin,a=this.ymin}r[i]===n&&r[i+1]===a||!this.contains(t,n,a)||(r.splice(i,0,n,a),i+=2)}if(r.length>4)for(let t=0;t<r.length;t+=2){const e=(t+2)%r.length,n=(t+4)%r.length;(r[t]===r[e]&&r[e]===r[n]||r[t+1]===r[e+1]&&r[e+1]===r[n+1])&&(r.splice(e,2),t-=2)}return i}_project(t,e,n,r){let i,a,o,s=1/0;if(r<0){if(e<=this.ymin)return null;(i=(this.ymin-e)/r)<s&&(o=this.ymin,a=t+(s=i)*n)}else if(r>0){if(e>=this.ymax)return null;(i=(this.ymax-e)/r)<s&&(o=this.ymax,a=t+(s=i)*n)}if(n>0){if(t>=this.xmax)return null;(i=(this.xmax-t)/n)<s&&(a=this.xmax,o=e+(s=i)*r)}else if(n<0){if(t<=this.xmin)return null;(i=(this.xmin-t)/n)<s&&(a=this.xmin,o=e+(s=i)*r)}return[a,o]}_edgecode(t,e){return(t===this.xmin?1:t===this.xmax?2:0)|(e===this.ymin?4:e===this.ymax?8:0)}_regioncode(t,e){return(t<this.xmin?1:t>this.xmax?2:0)|(e<this.ymin?4:e>this.ymax?8:0)}}const QO=2*Math.PI;function tS(t,e,n){return[t+Math.sin(t+e)*n,e+Math.cos(t-e)*n]}class eS{static from(t,e=function(t){return t[0]},n=function(t){return t[1]},r){return new eS("length"in t?function(t,e,n,r){const i=t.length,a=new Float64Array(2*i);for(let o=0;o<i;++o){const i=t[o];a[2*o]=e.call(r,i,o,t),a[2*o+1]=n.call(r,i,o,t)}return a}(t,e,n,r):Float64Array.from(function*(t,e,n,r){let i=0;for(const a of t)yield e.call(r,a,i,t),yield n.call(r,a,i,t),++i}(t,e,n,r)))}constructor(t){this._delaunator=new UO(t),this.inedges=new Int32Array(t.length/2),this._hullIndex=new Int32Array(t.length/2),this.points=this._delaunator.coords,this._init()}update(){return this._delaunator.update(),this._init(),this}_init(){const t=this._delaunator,e=this.points;if(t.hull&&t.hull.length>2&&function(t){const{triangles:e,coords:n}=t;for(let t=0;t<e.length;t+=3){const r=2*e[t],i=2*e[t+1],a=2*e[t+2];if((n[a]-n[r])*(n[i+1]-n[r+1])-(n[i]-n[r])*(n[a+1]-n[r+1])>1e-10)return!1}return!0}(t)){this.collinear=Int32Array.from({length:e.length/2},(t,e)=>e).sort((t,n)=>e[2*t]-e[2*n]||e[2*t+1]-e[2*n+1]);const t=this.collinear[0],n=this.collinear[this.collinear.length-1],r=[e[2*t],e[2*t+1],e[2*n],e[2*n+1]],i=1e-8*Math.sqrt((r[3]-r[1])**2+(r[2]-r[0])**2);for(let t=0,n=e.length/2;t<n;++t){const n=tS(e[2*t],e[2*t+1],i);e[2*t]=n[0],e[2*t+1]=n[1]}this._delaunator=new UO(e)}else delete this.collinear;const n=this.halfedges=this._delaunator.halfedges,r=this.hull=this._delaunator.hull,i=this.triangles=this._delaunator.triangles,a=this.inedges.fill(-1),o=this._hullIndex.fill(-1);for(let t=0,e=n.length;t<e;++t){const e=i[t%3==2?t-2:t+1];-1!==n[t]&&-1!==a[e]||(a[e]=t)}for(let t=0,e=r.length;t<e;++t)o[r[t]]=t;r.length<=2&&r.length>0&&(this.triangles=new Int32Array(3).fill(-1),this.halfedges=new Int32Array(3).fill(-1),this.triangles[0]=r[0],this.triangles[1]=r[1],this.triangles[2]=r[1],a[r[0]]=1,2===r.length&&(a[r[1]]=0))}voronoi(t){return new ZO(this,t)}*neighbors(t){const{inedges:e,hull:n,_hullIndex:r,halfedges:i,triangles:a,collinear:o}=this;if(o){const e=o.indexOf(t);return e>0&&(yield o[e-1]),void(e<o.length-1&&(yield o[e+1]))}const s=e[t];if(-1===s)return;let u=s,c=-1;do{if(yield c=a[u],a[u=u%3==2?u-2:u+1]!==t)return;if(-1===(u=i[u])){const e=n[(r[t]+1)%n.length];return void(e!==c&&(yield e))}}while(u!==s)}find(t,e,n=0){if((t=+t)!=t||(e=+e)!=e)return-1;const r=n;let i;for(;(i=this._step(n,t,e))>=0&&i!==n&&i!==r;)n=i;return i}_step(t,e,n){const{inedges:r,hull:i,_hullIndex:a,halfedges:o,triangles:s,points:u}=this;if(-1===r[t]||!u.length)return(t+1)%(u.length>>1);let c=t,l=(e-u[2*t])**2+(n-u[2*t+1])**2;const f=r[t];let d=f;do{let r=s[d];const f=(e-u[2*r])**2+(n-u[2*r+1])**2;if(f<l&&(l=f,c=r),s[d=d%3==2?d-2:d+1]!==t)break;if(-1===(d=o[d])){if((d=i[(a[t]+1)%i.length])!==r&&(e-u[2*d])**2+(n-u[2*d+1])**2<l)return d;break}}while(d!==f);return c}render(t){const e=null==t?t=new YO:void 0,{points:n,halfedges:r,triangles:i}=this;for(let e=0,a=r.length;e<a;++e){const a=r[e];if(a<e)continue;const o=2*i[e],s=2*i[a];t.moveTo(n[o],n[o+1]),t.lineTo(n[s],n[s+1])}return this.renderHull(t),e&&e.value()}renderPoints(t,e=2){const n=null==t?t=new YO:void 0,{points:r}=this;for(let n=0,i=r.length;n<i;n+=2){const i=r[n],a=r[n+1];t.moveTo(i+e,a),t.arc(i,a,e,0,QO)}return n&&n.value()}renderHull(t){const e=null==t?t=new YO:void 0,{hull:n,points:r}=this,i=2*n[0],a=n.length;t.moveTo(r[i],r[i+1]);for(let e=1;e<a;++e){const i=2*n[e];t.lineTo(r[i],r[i+1])}return t.closePath(),e&&e.value()}hullPolygon(){const t=new JO;return this.renderHull(t),t.value()}renderTriangle(t,e){const n=null==e?e=new YO:void 0,{points:r,triangles:i}=this,a=2*i[t*=3],o=2*i[t+1],s=2*i[t+2];return e.moveTo(r[a],r[a+1]),e.lineTo(r[o],r[o+1]),e.lineTo(r[s],r[s+1]),e.closePath(),n&&n.value()}*trianglePolygons(){const{triangles:t}=this;for(let e=0,n=t.length/3;e<n;++e)yield this.trianglePolygon(e)}trianglePolygon(t){const e=new JO;return this.renderTriangle(t,e),e.value()}}function nS(t){Br.call(this,null,t)}nS.Definition={type:"Voronoi",metadata:{modifies:!0},params:[{name:"x",type:"field",required:!0},{name:"y",type:"field",required:!0},{name:"size",type:"number",array:!0,length:2},{name:"extent",type:"array",array:!0,length:2,default:[[-1e5,-1e5],[1e5,1e5]],content:{type:"number",array:!0,length:2}},{name:"as",type:"string",default:"path"}]};const rS=[-1e5,-1e5,1e5,1e5];function iS(t){const e=t[0][0],n=t[0][1];let r=t.length-1;for(;t[r][0]===e&&t[r][1]===n;--r);return"M"+t.slice(0,r+1).join("L")+"Z"}Object(ct.y)(nS,Br).transform=function(t,e){const n=t.as||"path",r=e.source;if(!r||!r.length)return e;let i=t.size;i=i?[0,0,i[0],i[1]]:(i=t.extent)?[i[0][0],i[0][1],i[1][0],i[1][1]]:rS;const a=this.value=eS.from(r,t.x,t.y).voronoi(i);for(let t=0,e=r.length;t<e;++t){const e=a.cellPolygon(t);r[t][n]=e?iS(e):null}return e.reflow(t.modified()).modifies(n)};var aS=Math.PI/180,oS=64,sS=2048,uS=function(){var t,e,n,r,i,a,o,s=[256,256],u=hS,c=[],l=Math.random,f={};function d(t,e,n){for(var r,i,a,o=e.x,c=e.y,f=Math.sqrt(s[0]*s[0]+s[1]*s[1]),d=u(s),h=l()<.5?1:-1,p=-h;(r=d(p+=h))&&(i=~~r[0],a=~~r[1],!(Math.min(Math.abs(i),Math.abs(a))>=f));)if(e.x=o+i,e.y=c+a,!(e.x+e.x0<0||e.y+e.y0<0||e.x+e.x1>s[0]||e.y+e.y1>s[1])&&(!n||!lS(e,t,s[0]))&&(!n||dS(e,n))){for(var m,g=e.sprite,v=e.width>>5,y=s[0]>>5,b=e.x-(v<<4),x=127&b,w=32-x,k=e.y1-e.y0,_=(e.y+e.y0)*y+(b>>5),E=0;E<k;E++){m=0;for(var O=0;O<=v;O++)t[_+O]|=m<<w|(O<v?(m=g[E*v+O])>>>x:0);_+=y}return e.sprite=null,!0}return!1}return f.layout=function(){for(var u=function(t){t.width=t.height=1;var e=Math.sqrt(t.getContext("2d").getImageData(0,0,1,1).data.length>>2);t.width=(oS<<5)/e,t.height=sS/e;var n=t.getContext("2d");return n.fillStyle=n.strokeStyle="red",n.textAlign="center",{context:n,ratio:e}}(Au()),f=function(t){var e=[],n=-1;for(;++n<t;)e[n]=0;return e}((s[0]>>5)*s[1]),h=null,p=c.length,m=-1,g=[],v=c.map(function(s){return{text:t(s),font:e(s),style:r(s),weight:i(s),rotate:a(s),size:~~(n(s)+1e-14),padding:o(s),xoff:0,yoff:0,x1:0,y1:0,x0:0,y0:0,hasText:!1,sprite:null,datum:s}}).sort(function(t,e){return e.size-t.size});++m<p;){var y=v[m];y.x=s[0]*(l()+.5)>>1,y.y=s[1]*(l()+.5)>>1,cS(u,y,v,m),y.hasText&&d(f,y,h)&&(g.push(y),h?fS(h,y):h=[{x:y.x+y.x0,y:y.y+y.y0},{x:y.x+y.x1,y:y.y+y.y1}],y.x-=s[0]>>1,y.y-=s[1]>>1)}return g},f.words=function(t){return arguments.length?(c=t,f):c},f.size=function(t){return arguments.length?(s=[+t[0],+t[1]],f):s},f.font=function(t){return arguments.length?(e=pS(t),f):e},f.fontStyle=function(t){return arguments.length?(r=pS(t),f):r},f.fontWeight=function(t){return arguments.length?(i=pS(t),f):i},f.rotate=function(t){return arguments.length?(a=pS(t),f):a},f.text=function(e){return arguments.length?(t=pS(e),f):t},f.spiral=function(t){return arguments.length?(u=mS[t]||t,f):u},f.fontSize=function(t){return arguments.length?(n=pS(t),f):n},f.padding=function(t){return arguments.length?(o=pS(t),f):o},f.random=function(t){return arguments.length?(l=t,f):l},f};function cS(t,e,n,r){if(!e.sprite){var i=t.context,a=t.ratio;i.clearRect(0,0,(oS<<5)/a,sS/a);var o,s,u,c,l,f=0,d=0,h=0,p=n.length;for(--r;++r<p;){if(e=n[r],i.save(),i.font=e.style+" "+e.weight+" "+~~((e.size+1)/a)+"px "+e.font,o=i.measureText(e.text+"m").width*a,u=e.size<<1,e.rotate){var m=Math.sin(e.rotate*aS),g=Math.cos(e.rotate*aS),v=o*g,y=o*m,b=u*g,x=u*m;o=Math.max(Math.abs(v+x),Math.abs(v-x))+31>>5<<5,u=~~Math.max(Math.abs(y+b),Math.abs(y-b))}else o=o+31>>5<<5;if(u>h&&(h=u),f+o>=oS<<5&&(f=0,d+=h,h=0),d+u>=sS)break;i.translate((f+(o>>1))/a,(d+(u>>1))/a),e.rotate&&i.rotate(e.rotate*aS),i.fillText(e.text,0,0),e.padding&&(i.lineWidth=2*e.padding,i.strokeText(e.text,0,0)),i.restore(),e.width=o,e.height=u,e.xoff=f,e.yoff=d,e.x1=o>>1,e.y1=u>>1,e.x0=-e.x1,e.y0=-e.y1,e.hasText=!0,f+=o}for(var w=i.getImageData(0,0,(oS<<5)/a,sS/a).data,k=[];--r>=0;)if((e=n[r]).hasText){for(s=(o=e.width)>>5,u=e.y1-e.y0,c=0;c<u*s;c++)k[c]=0;if(null==(f=e.xoff))return;d=e.yoff;var _=0,E=-1;for(l=0;l<u;l++){for(c=0;c<o;c++){var O=s*l+(c>>5),S=w[(d+l)*(oS<<5)+(f+c)<<2]?1<<31-c%32:0;k[O]|=S,_|=S}_?E=l:(e.y0++,u--,l--,d++)}e.y1=e.y0+E,e.sprite=k.slice(0,(e.y1-e.y0)*s)}}}function lS(t,e,n){n>>=5;for(var r,i=t.sprite,a=t.width>>5,o=t.x-(a<<4),s=127&o,u=32-s,c=t.y1-t.y0,l=(t.y+t.y0)*n+(o>>5),f=0;f<c;f++){r=0;for(var d=0;d<=a;d++)if((r<<u|(d<a?(r=i[f*a+d])>>>s:0))&e[l+d])return!0;l+=n}return!1}function fS(t,e){var n=t[0],r=t[1];e.x+e.x0<n.x&&(n.x=e.x+e.x0),e.y+e.y0<n.y&&(n.y=e.y+e.y0),e.x+e.x1>r.x&&(r.x=e.x+e.x1),e.y+e.y1>r.y&&(r.y=e.y+e.y1)}function dS(t,e){return t.x+t.x1>e[0].x&&t.x+t.x0<e[1].x&&t.y+t.y1>e[0].y&&t.y+t.y0<e[1].y}function hS(t){var e=t[0]/t[1];return function(t){return[e*(t*=.1)*Math.cos(t),t*Math.sin(t)]}}function pS(t){return"function"==typeof t?t:function(){return t}}var mS={archimedean:hS,rectangular:function(t){var e=4*t[0]/t[1],n=0,r=0;return function(t){var i=t<0?-1:1;switch(Math.sqrt(1+4*i*t)-i&3){case 0:n+=e;break;case 1:r+=4;break;case 2:n-=e;break;default:r-=4}return[n,r]}}},gS=function(t,e,n){var r=t-e+2*n;return t?r>0?r:1:0};const vS="log",yS="quantile",bS="continuous",xS="discrete",wS="discretizing",kS="interpolating",_S="temporal";var ES=function(t){return function(e){var n,r=e[0],i=e[1];return i<r&&(n=r,r=i,i=n),[t.invert(r),t.invert(i)]}},OS=function(t){return function(e){var n,r,i,a,o=t.range(),s=e[0],u=e[1],c=-1;for(u<s&&(r=s,s=u,u=r),i=0,a=o.length;i<a;++i)o[i]>=s&&o[i]<=u&&(c<0&&(c=i),n=i);if(!(c<0))return s=t.invertExtent(o[c]),u=t.invertExtent(o[n]),[void 0===s[0]?s[1]:s[0],void 0===u[1]?u[0]:u[1]]}};function SS(){var t,e,n=Gp().unknown(void 0),r=n.domain,i=n.range,a=[0,1],o=!1,s=0,u=0,c=.5;function l(){var n=r().length,l=a[1]<a[0],f=a[l-0],d=a[1-l],h=gS(n,s,u);t=(d-f)/(h||1),o&&(t=Math.floor(t)),f+=(d-f-t*(n-s))*c,e=t*(1-s),o&&(f=Math.round(f),e=Math.round(e));var p=ro(n).map(function(e){return f+t*e});return i(l?p.reverse():p)}return delete n.unknown,n.domain=function(t){return arguments.length?(r(t),l()):r()},n.range=function(t){return arguments.length?(a=[+t[0],+t[1]],l()):a.slice()},n.rangeRound=function(t){return a=[+t[0],+t[1]],o=!0,l()},n.bandwidth=function(){return e},n.step=function(){return t},n.round=function(t){return arguments.length?(o=!!t,l()):o},n.padding=function(t){return arguments.length?(u=Math.max(0,Math.min(1,t)),s=u,l()):s},n.paddingInner=function(t){return arguments.length?(s=Math.max(0,Math.min(1,t)),l()):s},n.paddingOuter=function(t){return arguments.length?(u=Math.max(0,Math.min(1,t)),l()):u},n.align=function(t){return arguments.length?(c=Math.max(0,Math.min(1,t)),l()):c},n.invertRange=function(t){if(null!=t[0]&&null!=t[1]){var n,o,s,u=+t[0],c=+t[1],l=a[1]<a[0],f=l?i().reverse():i(),d=f.length-1;if(u==u&&c==c&&(c<u&&(s=u,u=c,c=s),!(c<f[0]||u>a[1-l])))return n=Math.max(0,Bp(f,u)-1),o=u===c?n:Bp(f,c)-1,u-f[n]>e+1e-10&&++n,l&&(s=n,n=d-o,o=d-s),n>o?void 0:r().slice(n,o+1)}},n.invert=function(t){var e=n.invertRange([t,t]);return e?e[0]:e},n.copy=function(){return SS().domain(r()).range(a).round(o).paddingInner(s).paddingOuter(u).align(c)},l()}var CS=Array.prototype.map;var AS=Array.prototype.slice;const NS={};function TS(t,e,n){return arguments.length>1?(NS[t]=function(t,e,n){const r=function(){var n=e();return n.invertRange||(n.invertRange=n.invert?ES(n):n.invertExtent?OS(n):void 0),n.type=t,n};return r.metadata=Object(ct.Da)(Object(ct.i)(n)),r}(t,e,n),this):function(t){return Object(ct.v)(NS,t)}(t)?NS[t]:void 0}TS("identity",iv),TS("linear",fg,bS),TS(vS,xg,[bS,vS]),TS("pow",Ng,bS),TS("sqrt",Tg,bS),TS("symlog",Eg,bS),TS("time",ev,[bS,_S]),TS("utc",nv,[bS,_S]),TS("sequential",Mg,[bS,kS]),TS("sequential-linear",Mg,[bS,kS]),TS(`sequential-${vS}`,Rg,[bS,kS,vS]),TS("sequential-pow",jg,[bS,kS]),TS("sequential-sqrt",Pg,[bS,kS]),TS("sequential-symlog",Fg,[bS,kS]),TS("diverging-linear",zg,[bS,kS]),TS(`diverging-${vS}`,Bg,[bS,kS,vS]),TS("diverging-pow",Wg,[bS,kS]),TS("diverging-sqrt",Vg,[bS,kS]),TS("diverging-symlog",Ug,[bS,kS]),TS(yS,qg,[wS,yS]),TS("quantize",rv,wS),TS("threshold",Zp,wS),TS("bin-ordinal",function t(){var e=[],n=[];function r(t){return null==t||t!=t?void 0:n[(Wp(e,t)-1)%n.length]}return r.domain=function(t){return arguments.length?(e=function(t){return CS.call(t,function(t){return+t})}(t),r):e.slice()},r.range=function(t){return arguments.length?(n=AS.call(t),r):n.slice()},r.tickFormat=function(t,n){return Xp(e[0],Object(ct.U)(e),null==t?10:t,n)},r.copy=function(){return t().domain(r.domain()).range(r.range())},r},[xS,wS]),TS("ordinal",Gp,xS),TS("band",SS,xS),TS("point",function(){return function t(e){var n=e.copy;return e.padding=e.paddingOuter,delete e.paddingInner,e.copy=function(){return t(n())},e}(SS().paddingInner(1))},xS);function IS(t,e,n){return Qm(function(t,e){var n=a[function(t){return"interpolate"+t.toLowerCase().split("-").map(function(t){return t[0].toUpperCase()+t.slice(1)}).join("")}(t)];return null!=e&&n&&n.gamma?n.gamma(e):n}(e||"rgb",n),t)}function DS(t){for(var e=t.length/6|0,n=new Array(e),r=0;r<e;)n[r]="#"+t.slice(6*r,6*++r);return n}function MS(t,e){for(let n in t)FS(n,e(t[n]))}const RS={};function FS(t,e){return t=t&&t.toLowerCase(),arguments.length>1?(RS[t]=e,this):RS[t]}MS({category10:"1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf",category20:"1f77b4aec7e8ff7f0effbb782ca02c98df8ad62728ff98969467bdc5b0d58c564bc49c94e377c2f7b6d27f7f7fc7c7c7bcbd22dbdb8d17becf9edae5",category20b:"393b795254a36b6ecf9c9ede6379398ca252b5cf6bcedb9c8c6d31bd9e39e7ba52e7cb94843c39ad494ad6616be7969c7b4173a55194ce6dbdde9ed6",category20c:"3182bd6baed69ecae1c6dbefe6550dfd8d3cfdae6bfdd0a231a35474c476a1d99bc7e9c0756bb19e9ac8bcbddcdadaeb636363969696bdbdbdd9d9d9",tableau10:"4c78a8f58518e4575672b7b254a24beeca3bb279a2ff9da69d755dbab0ac",tableau20:"4c78a89ecae9f58518ffbf7954a24b88d27ab79a20f2cf5b43989483bcb6e45756ff9d9879706ebab0acd67195fcbfd2b279a2d6a5c99e765fd8b5a5",accent:"7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666",dark2:"1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666",paired:"a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928",pastel1:"fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2",pastel2:"b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc",set1:"e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999",set2:"66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3",set3:"8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f"},DS),MS({blues:"cfe1f2bed8eca8cee58fc1de74b2d75ba3cf4592c63181bd206fb2125ca40a4a90",greens:"d3eecdc0e6baabdda594d3917bc77d60ba6c46ab5e329a512089430e7735036429",greys:"e2e2e2d4d4d4c4c4c4b1b1b19d9d9d8888887575756262624d4d4d3535351e1e1e",oranges:"fdd8b3fdc998fdb87bfda55efc9244f87f2cf06b18e4580bd14904b93d029f3303",purples:"e2e1efd4d4e8c4c5e0b4b3d6a3a0cc928ec3827cb97566ae684ea25c3696501f8c",reds:"fdc9b4fcb49afc9e80fc8767fa7051f6573fec3f2fdc2a25c81b1db21218970b13",blueGreen:"d5efedc1e8e0a7ddd18bd2be70c6a958ba9144ad77319c5d2089460e7736036429",bluePurple:"ccddecbad0e4a8c2dd9ab0d4919cc98d85be8b6db28a55a6873c99822287730f71",greenBlue:"d3eecec5e8c3b1e1bb9bd8bb82cec269c2ca51b2cd3c9fc7288abd1675b10b60a1",orangeRed:"fddcaffdcf9bfdc18afdad77fb9562f67d53ee6545e24932d32d1ebf130da70403",purpleBlue:"dbdaebc8cee4b1c3de97b7d87bacd15b9fc93a90c01e7fb70b70ab056199045281",purpleBlueGreen:"dbd8eac8cee4b0c3de93b7d872acd1549fc83892bb1c88a3097f8702736b016353",purpleRed:"dcc9e2d3b3d7ce9eccd186c0da6bb2e14da0e23189d91e6fc61159ab07498f023a",redPurple:"fccfccfcbec0faa9b8f98faff571a5ec539ddb3695c41b8aa908808d0179700174",yellowGreen:"e4f4acd1eca0b9e2949ed68880c97c62bb6e47aa5e3297502083440e723b036034",yellowOrangeBrown:"feeaa1fedd84fecc63feb746fca031f68921eb7215db5e0bc54c05ab3d038f3204",yellowOrangeRed:"fee087fed16ffebd59fea849fd903efc7335f9522bee3423de1b20ca0b22af0225",blueOrange:"134b852f78b35da2cb9dcae1d2e5eff2f0ebfce0bafbbf74e8932fc5690d994a07",brownBlueGreen:"704108a0651ac79548e3c78af3e6c6eef1eac9e9e48ed1c74da79e187a72025147",purpleGreen:"5b1667834792a67fb6c9aed3e6d6e8eff0efd9efd5aedda971bb75368e490e5e29",purpleOrange:"4114696647968f83b7b9b4d6dadbebf3eeeafce0bafbbf74e8932fc5690d994a07",redBlue:"8c0d25bf363adf745ef4ae91fbdbc9f2efeed2e5ef9dcae15da2cb2f78b3134b85",redGrey:"8c0d25bf363adf745ef4ae91fcdccbfaf4f1e2e2e2c0c0c0969696646464343434",yellowGreenBlue:"eff9bddbf1b4bde5b594d5b969c5be45b4c22c9ec02182b82163aa23479c1c3185",redYellowBlue:"a50026d4322cf16e43fcac64fedd90faf8c1dcf1ecabd6e875abd04a74b4313695",redYellowGreen:"a50026d4322cf16e43fcac63fedd8df9f7aed7ee8ea4d86e64bc6122964f006837",pinkYellowGreen:"8e0152c0267edd72adf0b3d6faddedf5f3efe1f2cab6de8780bb474f9125276419",spectral:"9e0142d13c4bf0704afcac63fedd8dfbf8b0e0f3a1a9dda269bda94288b55e4fa2",viridis:"440154470e61481a6c482575472f7d443a834144873d4e8a39568c35608d31688e2d708e2a788e27818e23888e21918d1f988b1fa08822a8842ab07f35b77943bf7154c56866cc5d7ad1518fd744a5db36bcdf27d2e21be9e51afde725",magma:"0000040404130b0924150e3720114b2c11603b0f704a107957157e651a80721f817f24828c29819a2e80a8327db6377ac43c75d1426fde4968e95462f1605df76f5cfa7f5efc8f65fe9f6dfeaf78febf84fece91fddea0fcedaffcfdbf",inferno:"0000040403130c0826170c3b240c4f330a5f420a68500d6c5d126e6b176e781c6d86216b932667a12b62ae305cbb3755c73e4cd24644dd513ae65c30ed6925f3771af8850ffb9506fca50afcb519fac62df6d645f2e661f3f484fcffa4",plasma:"0d088723069033059742039d5002a25d01a66a00a87801a88405a7900da49c179ea72198b12a90ba3488c33d80cb4779d35171da5a69e16462e76e5bed7953f2834cf68f44fa9a3dfca636fdb32ffec029fcce25f9dc24f5ea27f0f921",rainbow:"6e40aa883eb1a43db3bf3cafd83fa4ee4395fe4b83ff576eff6659ff7847ff8c38f3a130e2b72fcfcc36bee044aff05b8ff4576ff65b52f6673af27828ea8d1ddfa319d0b81cbecb23abd82f96e03d82e14c6edb5a5dd0664dbf6e40aa",sinebow:"ff4040fc582af47218e78d0bd5a703bfbf00a7d5038de70b72f41858fc2a40ff402afc5818f4720be78d03d5a700bfbf03a7d50b8de71872f42a58fc4040ff582afc7218f48d0be7a703d5bf00bfd503a7e70b8df41872fc2a58ff4040",browns:"eedbbdecca96e9b97ae4a865dc9856d18954c7784cc0673fb85536ad44339f3632",tealBlues:"bce4d89dd3d181c3cb65b3c245a2b9368fae347da0306a932c5985",teals:"bbdfdfa2d4d58ac9c975bcbb61b0af4da5a43799982b8b8c1e7f7f127273006667",warmGreys:"dcd4d0cec5c1c0b8b4b3aaa7a59c9998908c8b827f7e7673726866665c5a59504e",goldGreen:"f4d166d5ca60b6c35c98bb597cb25760a6564b9c533f8f4f33834a257740146c36",goldOrange:"f4d166f8be5cf8aa4cf5983bf3852aef701be2621fd65322c54923b142239e3a26",goldRed:"f4d166f6be59f9aa51fc964ef6834bee734ae56249db5247cf4244c43141b71d3e",lightGreyRed:"efe9e6e1dad7d5cbc8c8bdb9bbaea9cd967ddc7b43e15f19df4011dc000b",lightGreyTeal:"e4eaead6dcddc8ced2b7c2c7a6b4bc64b0bf22a6c32295c11f85be1876bc",lightMulti:"e0f1f2c4e9d0b0de9fd0e181f6e072f6c053f3993ef77440ef4a3c",lightOrange:"f2e7daf7d5baf9c499fab184fa9c73f68967ef7860e8645bde515bd43d5b",lightTealBlue:"e3e9e0c0dccf9aceca7abfc859afc0389fb9328dad2f7ca0276b95255988",darkBlue:"3232322d46681a5c930074af008cbf05a7ce25c0dd38daed50f3faffffff",darkGold:"3c3c3c584b37725e348c7631ae8b2bcfa424ecc31ef9de30fff184ffffff",darkGreen:"3a3a3a215748006f4d048942489e4276b340a6c63dd2d836ffeb2cffffaa",darkMulti:"3737371f5287197d8c29a86995ce3fffe800ffffff",darkRed:"3434347036339e3c38cc4037e75d1eec8620eeab29f0ce32ffeb2c"},t=>IS(DS(t)));var jS=["x","y","font","fontSize","fontStyle","fontWeight","angle"],PS=["text","font","rotate","fontSize","fontStyle","fontWeight"];function LS(t){Br.call(this,uS(),t)}function zS(t){return new Uint32Array(t)}function BS(t,e,n){var r=(e<257?function(t){return new Uint8Array(t)}:e<65537?function(t){return new Uint16Array(t)}:zS)(t);return n&&r.set(n),r}LS.Definition={type:"Wordcloud",metadata:{modifies:!0},params:[{name:"size",type:"number",array:!0,length:2},{name:"font",type:"string",expr:!0,default:"sans-serif"},{name:"fontStyle",type:"string",expr:!0,default:"normal"},{name:"fontWeight",type:"string",expr:!0,default:"normal"},{name:"fontSize",type:"number",expr:!0,default:14},{name:"fontSizeRange",type:"number",array:"nullable",default:[10,50]},{name:"rotate",type:"number",expr:!0,default:0},{name:"text",type:"field"},{name:"spiral",type:"string",values:["archimedean","rectangular"]},{name:"padding",type:"number",expr:!0},{name:"as",type:"string",array:!0,length:7,default:jS}]},Object(ct.y)(LS,Br).transform=function(t,e){!t.size||t.size[0]&&t.size[1]||Object(ct.n)("Wordcloud size dimensions must be non-zero.");var n=t.modified();if(n||e.changed(e.ADD_REM)||PS.some(function(n){var r=t[n];return Object(ct.D)(r)&&e.modified(r.fields)})){var r,i=e.materialize(e.SOURCE).source,a=this.value,o=t.as||jS,s=t.fontSize||14;if(Object(ct.D)(s)?r=t.fontSizeRange:s=Object(ct.l)(s),r){var u=s,c=TS("sqrt")().domain(Object(ct.p)(i,u)).range(r);s=function(t){return c(u(t))}}i.forEach(function(t){t[o[0]]=NaN,t[o[1]]=NaN,t[o[3]]=0});for(var l,f,d=a.words(i).text(t.text).size(t.size||[500,500]).padding(t.padding||1).spiral(t.spiral||"archimedean").rotate(t.rotate||0).font(t.font||"sans-serif").fontStyle(t.fontStyle||"normal").fontWeight(t.fontWeight||"normal").fontSize(s).random(li).layout(),h=a.size(),p=h[0]>>1,m=h[1]>>1,g=0,v=d.length;g<v;++g)(f=(l=d[g]).datum)[o[0]]=l.x+p,f[o[1]]=l.y+m,f[o[2]]=l.font,f[o[3]]=l.size,f[o[4]]=l.style,f[o[5]]=l.weight,f[o[6]]=l.rotate;return e.reflow(n).modifies(o)}};var US=function(t,e,n){var r=1<<e;return{one:r,zero:~r,range:n.slice(),bisect:t.bisect,index:t.index,size:t.size,onAdd:function(t,e){var n,i=this.bisect(this.range,t.value),a=t.index,o=i[0],s=i[1],u=a.length;for(n=0;n<o;++n)e[a[n]]|=r;for(n=s;n<u;++n)e[a[n]]|=r;return this}}},WS=function(t,e){return Array.from(e,e=>t[e])};function VS(){var t=zS(0),e=[],n=0;return{insert:function(r,i,a){if(!i.length)return[];var o,s,u,c=n,l=i.length,f=Array(l),d=zS(l);for(u=0;u<l;++u)f[u]=r(i[u]),d[u]=u;if(f=function(t,e){return t.sort.call(e,function(e,n){var r=t[e],i=t[n];return r<i?-1:r>i?1:0}),WS(t,e)}(f,d),c)o=e,s=t,e=Array(c+l),t=zS(c+l),function(t,e,n,r,i,a,o,s,u){var c,l=0,f=0;for(c=0;l<r&&f<o;++c)e[l]<i[f]?(s[c]=e[l],u[c]=n[l++]):(s[c]=i[f],u[c]=a[f++]+t);for(;l<r;++l,++c)s[c]=e[l],u[c]=n[l];for(;f<o;++f,++c)s[c]=i[f],u[c]=a[f]+t}(a,o,s,c,f,d,l,e,t);else{if(a>0)for(u=0;u<l;++u)d[u]+=a;e=f,t=d}return n=c+l,{index:d,value:f}},remove:function(r,i){var a,o,s,u=n;for(o=0;!i[t[o]]&&o<u;++o);for(s=o;o<u;++o)i[a=t[o]]||(t[s]=a,e[s]=e[o],++s);n=u-r},bisect:function(t,r){var i;return r?i=r.length:(r=e,i=n),[Up(r,t[0],0,i),Bp(r,t[1],0,i)]},reindex:function(e){for(var r=0,i=n;r<i;++r)t[r]=e[t[r]]},index:function(){return t},size:function(){return n}}}function qS(t){Br.call(this,function(){var t=8,e=[],n=zS(0),r=BS(0,t),i=BS(0,t);return{data:function(){return e},seen:function(){return n=function(t,e,n){return t.length>=e?t:((n=n||new t.constructor(e)).set(t),n)}(n,e.length)},add:function(t){for(var n,r=0,i=e.length,a=t.length;r<a;++r)(n=t[r])._index=i++,e.push(n)},remove:function(t,n){var a,o,s,u=e.length,c=Array(u-t),l=e;for(o=0;!n[o]&&o<u;++o)c[o]=e[o],l[o]=o;for(s=o;o<u;++o)a=e[o],n[o]?l[o]=-1:(l[o]=s,r[s]=r[o],i[s]=i[o],c[s]=a,a._index=s++),r[o]=0;return e=c,l},size:function(){return e.length},curr:function(){return r},prev:function(){return i},reset:function(t){i[t]=r[t]},all:function(){return t<257?255:t<65537?65535:4294967295},set:function(t,e){r[t]|=e},clear:function(t,e){r[t]&=~e},resize:function(e,n){(e>r.length||n>t)&&(t=Math.max(n,t),r=BS(e,t,r),i=BS(e,t))}}}(),t),this._indices=null,this._dims=null}qS.Definition={type:"CrossFilter",metadata:{},params:[{name:"fields",type:"field",array:!0,required:!0},{name:"query",type:"array",array:!0,required:!0,content:{type:"number",array:!0,length:2}}]};var HS=Object(ct.y)(qS,Br);function GS(t){Br.call(this,null,t)}HS.transform=function(t,e){return this._dims?t.modified("fields")||t.fields.some(function(t){return e.modified(t.fields)})?this.reinit(t,e):this.eval(t,e):this.init(t,e)},HS.init=function(t,e){for(var n,r,i=t.fields,a=t.query,o=this._indices={},s=this._dims=[],u=a.length,c=0;c<u;++c)r=o[n=i[c].fname]||(o[n]=VS()),s.push(US(r,c,a[c]));return this.eval(t,e)},HS.reinit=function(t,e){var n,r,i,a,o,s,u,c,l,f=e.materialize().fork(),d=t.fields,h=t.query,p=this._indices,m=this._dims,g=this.value,v=g.curr(),y=g.prev(),b=g.all(),x=f.rem=f.add,w=f.mod,k=h.length,_={};if(y.set(v),e.rem.length&&(o=this.remove(t,e,f)),e.add.length&&g.add(e.add),e.mod.length)for(s={},u=0,c=(a=e.mod).length;u<c;++u)s[a[u]._index]=1;for(u=0;u<k;++u)l=d[u],(!m[u]||t.modified("fields",u)||e.modified(l.fields))&&((n=_[i=l.fname])||(p[i]=r=VS(),_[i]=n=r.insert(l,e.source,0)),m[u]=US(r,u,h[u]).onAdd(n,v));for(u=0,c=g.data().length;u<c;++u)o[u]||(y[u]!==v[u]?x.push(u):s[u]&&v[u]!==b&&w.push(u));return g.mask=(1<<k)-1,f},HS.eval=function(t,e){var n=e.materialize().fork(),r=this._dims.length,i=0;return e.rem.length&&(this.remove(t,e,n),i|=(1<<r)-1),t.modified("query")&&!t.modified("fields")&&(i|=this.update(t,e,n)),e.add.length&&(this.insert(t,e,n),i|=(1<<r)-1),e.mod.length&&(this.modify(e,n),i|=(1<<r)-1),this.value.mask=i,n},HS.insert=function(t,e,n){var r,i,a,o=e.add,s=this.value,u=this._dims,c=this._indices,l=t.fields,f={},d=n.add,h=s.size(),p=h+o.length,m=u.length;s.resize(p,m),s.add(o);var g=s.curr(),v=s.prev(),y=s.all();for(r=0;r<m;++r)a=f[i=l[r].fname]||(f[i]=c[i].insert(l[r],o,h)),u[r].onAdd(a,g);for(;h<p;++h)v[h]=y,g[h]!==y&&d.push(h)},HS.modify=function(t,e){var n,r,i,a=e.mod,o=this.value,s=o.curr(),u=o.all(),c=t.mod;for(n=0,r=c.length;n<r;++n)s[i=c[n]._index]!==u&&a.push(i)},HS.remove=function(t,e,n){var r,i,a,o,s=this._indices,u=this.value,c=u.curr(),l=u.prev(),f=u.all(),d={},h=n.rem,p=e.rem;for(r=0,i=p.length;r<i;++r)d[a=p[r]._index]=1,l[a]=o=c[a],c[a]=f,o!==f&&h.push(a);for(a in s)s[a].remove(i,d);return this.reindex(e,i,d),d},HS.reindex=function(t,e,n){var r=this._indices,i=this.value;t.runAfter(function(){var t=i.remove(e,n);for(var a in r)r[a].reindex(t)})},HS.update=function(t,e,n){var r,i,a=this._dims,o=t.query,s=e.stamp,u=a.length,c=0;for(n.filters=0,i=0;i<u;++i)t.modified("query",i)&&(r=i,++c);if(1===c)c=a[r].one,this.incrementOne(a[r],o[r],n.add,n.rem);else for(i=0,c=0;i<u;++i)t.modified("query",i)&&(c|=a[i].one,this.incrementAll(a[i],o[i],s,n.add),n.rem=n.add);return c},HS.incrementAll=function(t,e,n,r){var i,a,o,s=this.value,u=s.seen(),c=s.curr(),l=s.prev(),f=t.index(),d=t.bisect(t.range),h=t.bisect(e),p=h[0],m=h[1],g=d[0],v=d[1],y=t.one;if(p<g)for(i=p,a=Math.min(g,m);i<a;++i)u[o=f[i]]!==n&&(l[o]=c[o],u[o]=n,r.push(o)),c[o]^=y;else if(p>g)for(i=g,a=Math.min(p,v);i<a;++i)u[o=f[i]]!==n&&(l[o]=c[o],u[o]=n,r.push(o)),c[o]^=y;if(m>v)for(i=Math.max(p,v),a=m;i<a;++i)u[o=f[i]]!==n&&(l[o]=c[o],u[o]=n,r.push(o)),c[o]^=y;else if(m<v)for(i=Math.max(g,m),a=v;i<a;++i)u[o=f[i]]!==n&&(l[o]=c[o],u[o]=n,r.push(o)),c[o]^=y;t.range=e.slice()},HS.incrementOne=function(t,e,n,r){var i,a,o,s=this.value.curr(),u=t.index(),c=t.bisect(t.range),l=t.bisect(e),f=l[0],d=l[1],h=c[0],p=c[1],m=t.one;if(f<h)for(i=f,a=Math.min(h,d);i<a;++i)s[o=u[i]]^=m,n.push(o);else if(f>h)for(i=h,a=Math.min(f,p);i<a;++i)s[o=u[i]]^=m,r.push(o);if(d>p)for(i=Math.max(f,p),a=d;i<a;++i)s[o=u[i]]^=m,n.push(o);else if(d<p)for(i=Math.max(h,d),a=p;i<a;++i)s[o=u[i]]^=m,r.push(o);t.range=e.slice()},GS.Definition={type:"ResolveFilter",metadata:{},params:[{name:"ignore",type:"number",required:!0,description:"A bit mask indicating which filters to ignore."},{name:"filter",type:"object",required:!0,description:"Per-tuple filter bitmaps from a CrossFilter transform."}]},Object(ct.y)(GS,Br).transform=function(t,e){var n=~(t.ignore||0),r=t.filter,i=r.mask;if(0==(i&n))return e.StopPropagation;var a=e.fork(e.ALL),o=r.data(),s=r.curr(),u=r.prev(),c=function(t){return s[t]&n?null:o[t]};return a.filter(a.MOD,c),i&i-1?(a.filter(a.ADD,function(t){var e=s[t]&n;return!e&&e^u[t]&n?o[t]:null}),a.filter(a.REM,function(t){var e=s[t]&n;return e&&!(e^e^u[t]&n)?o[t]:null})):(a.filter(a.ADD,c),a.filter(a.REM,function(t){return(s[t]&n)===i?o[t]:null})),a.filter(a.SOURCE,function(t){return c(t._index)})};var $S=n(241),KS=function(t,e,n){var r=t-e+2*n;return t?r>0?r:1:0};const XS="identity",YS="linear",JS="log",ZS="pow",QS="sqrt",tC="symlog",eC="time",nC="utc",rC="sequential",iC="diverging",aC="quantile",oC="quantize",sC="threshold",uC="ordinal",cC="point",lC="band",fC="bin-ordinal";var dC={millisecond:Uo,second:$o,minute:Vo,hour:zo,day:Xe,week:Ue,month:Po,year:Ce},hC={millisecond:Uo,second:$o,minute:Xo,hour:Ho,day:ze,week:Ie,month:Fo,year:Je};function pC(t,e){const n=e===nC?hC:dC;return Object(ct.v)(n,t)&&n[t]}var mC=function(t){return function(e){var n,r=e[0],i=e[1];return i<r&&(n=r,r=i,i=n),[t.invert(r),t.invert(i)]}},gC=function(t){return function(e){var n,r,i,a,o=t.range(),s=e[0],u=e[1],c=-1;for(u<s&&(r=s,s=u,u=r),i=0,a=o.length;i<a;++i)o[i]>=s&&o[i]<=u&&(c<0&&(c=i),n=i);if(!(c<0))return s=t.invertExtent(o[c]),u=t.invertExtent(o[n]),[void 0===s[0]?s[1]:s[0],void 0===u[1]?u[0]:u[1]]}};function vC(){var t,e,n=Gp().unknown(void 0),r=n.domain,i=n.range,a=[0,1],o=!1,s=0,u=0,c=.5;function l(){var n=r().length,l=a[1]<a[0],f=a[l-0],d=a[1-l],h=KS(n,s,u);t=(d-f)/(h||1),o&&(t=Math.floor(t)),f+=(d-f-t*(n-s))*c,e=t*(1-s),o&&(f=Math.round(f),e=Math.round(e));var p=ro(n).map(function(e){return f+t*e});return i(l?p.reverse():p)}return delete n.unknown,n.domain=function(t){return arguments.length?(r(t),l()):r()},n.range=function(t){return arguments.length?(a=[+t[0],+t[1]],l()):a.slice()},n.rangeRound=function(t){return a=[+t[0],+t[1]],o=!0,l()},n.bandwidth=function(){return e},n.step=function(){return t},n.round=function(t){return arguments.length?(o=!!t,l()):o},n.padding=function(t){return arguments.length?(u=Math.max(0,Math.min(1,t)),s=u,l()):s},n.paddingInner=function(t){return arguments.length?(s=Math.max(0,Math.min(1,t)),l()):s},n.paddingOuter=function(t){return arguments.length?(u=Math.max(0,Math.min(1,t)),l()):u},n.align=function(t){return arguments.length?(c=Math.max(0,Math.min(1,t)),l()):c},n.invertRange=function(t){if(null!=t[0]&&null!=t[1]){var n,o,s,u=+t[0],c=+t[1],l=a[1]<a[0],f=l?i().reverse():i(),d=f.length-1;if(u==u&&c==c&&(c<u&&(s=u,u=c,c=s),!(c<f[0]||u>a[1-l])))return n=Math.max(0,Bp(f,u)-1),o=u===c?n:Bp(f,c)-1,u-f[n]>e+1e-10&&++n,l&&(s=n,n=d-o,o=d-s),n>o?void 0:r().slice(n,o+1)}},n.invert=function(t){var e=n.invertRange([t,t]);return e?e[0]:e},n.copy=function(){return vC().domain(r()).range(a).round(o).paddingInner(s).paddingOuter(u).align(c)},l()}var yC=Array.prototype.map;var bC=Array.prototype.slice;function xC(t,e){return arguments.length>1?(wC[t]=function(t,e){return function(){var n=e();return n.invertRange||(n.invertRange=n.invert?mC(n):n.invertExtent?gC(n):void 0),n.type=t,n}}(t,e),this):Object(ct.v)(wC,t)?wC[t]:void 0}var wC={[XS]:iv,[YS]:fg,[JS]:xg,[ZS]:Ng,[QS]:Tg,[tC]:Eg,[eC]:ev,[nC]:nv,[rC]:Mg,[rC+"-"+YS]:Mg,[rC+"-"+JS]:Rg,[rC+"-"+ZS]:jg,[rC+"-"+QS]:Pg,[rC+"-"+tC]:Fg,[iC+"-"+YS]:zg,[iC+"-"+JS]:Bg,[iC+"-"+ZS]:Wg,[iC+"-"+QS]:Vg,[iC+"-"+tC]:Ug,[aC]:qg,[oC]:rv,[sC]:Zp,[fC]:function t(){var e=[],n=[];function r(t){return null==t||t!=t?void 0:n[(Wp(e,t)-1)%n.length]}return r.domain=function(t){return arguments.length?(e=function(t){return yC.call(t,function(t){return+t})}(t),r):e.slice()},r.range=function(t){return arguments.length?(n=bC.call(t),r):n.slice()},r.tickFormat=function(t,n){return Xp(e[0],Object(ct.U)(e),null==t?10:t,n)},r.copy=function(){return t().domain(r.domain()).range(r.range())},r},[uC]:Gp,[lC]:vC,[cC]:function(){return function t(e){var n=e.copy;return e.padding=e.paddingOuter,delete e.paddingInner,e.copy=function(){return t(n())},e}(vC().paddingInner(1))}};for(var kC in wC)xC(kC,wC[kC]);function _C(t,e){var n=e[0],r=Object(ct.U)(e)-n;return function(e){return t(n+e*r)}}function EC(t,e,n){return Qm(SC(e||"rgb",n),t)}function OC(t,e){for(var n=new Array(e),r=e+1,i=0;i<e;)n[i]=t(++i/r);return n}function SC(t,e){var n=a[function(t){return"interpolate"+t.toLowerCase().split("-").map(function(t){return t[0].toUpperCase()+t.slice(1)}).join("")}(t)];return null!=e&&n&&n.gamma?n.gamma(e):n}function CC(t){for(var e=t.length/6|0,n=new Array(e),r=0;r<e;)n[r]="#"+t.slice(6*r,6*++r);return n}function AC(t,e){for(let n in t)TC(n,e(t[n]))}const NC={};function TC(t,e){return t=t&&t.toLowerCase(),arguments.length>1?(NC[t]=e,this):NC[t]}function IC(t,e){t&&(null==e?t.removeAttribute("aria-label"):t.setAttribute("aria-label",e))}AC({category10:"1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf",category20:"1f77b4aec7e8ff7f0effbb782ca02c98df8ad62728ff98969467bdc5b0d58c564bc49c94e377c2f7b6d27f7f7fc7c7c7bcbd22dbdb8d17becf9edae5",category20b:"393b795254a36b6ecf9c9ede6379398ca252b5cf6bcedb9c8c6d31bd9e39e7ba52e7cb94843c39ad494ad6616be7969c7b4173a55194ce6dbdde9ed6",category20c:"3182bd6baed69ecae1c6dbefe6550dfd8d3cfdae6bfdd0a231a35474c476a1d99bc7e9c0756bb19e9ac8bcbddcdadaeb636363969696bdbdbdd9d9d9",tableau10:"4c78a8f58518e4575672b7b254a24beeca3bb279a2ff9da69d755dbab0ac",tableau20:"4c78a89ecae9f58518ffbf7954a24b88d27ab79a20f2cf5b43989483bcb6e45756ff9d9879706ebab0acd67195fcbfd2b279a2d6a5c99e765fd8b5a5",accent:"7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666",dark2:"1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666",paired:"a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928",pastel1:"fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2",pastel2:"b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc",set1:"e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999",set2:"66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3",set3:"8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f"},CC),AC({blues:"cfe1f2bed8eca8cee58fc1de74b2d75ba3cf4592c63181bd206fb2125ca40a4a90",greens:"d3eecdc0e6baabdda594d3917bc77d60ba6c46ab5e329a512089430e7735036429",greys:"e2e2e2d4d4d4c4c4c4b1b1b19d9d9d8888887575756262624d4d4d3535351e1e1e",oranges:"fdd8b3fdc998fdb87bfda55efc9244f87f2cf06b18e4580bd14904b93d029f3303",purples:"e2e1efd4d4e8c4c5e0b4b3d6a3a0cc928ec3827cb97566ae684ea25c3696501f8c",reds:"fdc9b4fcb49afc9e80fc8767fa7051f6573fec3f2fdc2a25c81b1db21218970b13",blueGreen:"d5efedc1e8e0a7ddd18bd2be70c6a958ba9144ad77319c5d2089460e7736036429",bluePurple:"ccddecbad0e4a8c2dd9ab0d4919cc98d85be8b6db28a55a6873c99822287730f71",greenBlue:"d3eecec5e8c3b1e1bb9bd8bb82cec269c2ca51b2cd3c9fc7288abd1675b10b60a1",orangeRed:"fddcaffdcf9bfdc18afdad77fb9562f67d53ee6545e24932d32d1ebf130da70403",purpleBlue:"dbdaebc8cee4b1c3de97b7d87bacd15b9fc93a90c01e7fb70b70ab056199045281",purpleBlueGreen:"dbd8eac8cee4b0c3de93b7d872acd1549fc83892bb1c88a3097f8702736b016353",purpleRed:"dcc9e2d3b3d7ce9eccd186c0da6bb2e14da0e23189d91e6fc61159ab07498f023a",redPurple:"fccfccfcbec0faa9b8f98faff571a5ec539ddb3695c41b8aa908808d0179700174",yellowGreen:"e4f4acd1eca0b9e2949ed68880c97c62bb6e47aa5e3297502083440e723b036034",yellowOrangeBrown:"feeaa1fedd84fecc63feb746fca031f68921eb7215db5e0bc54c05ab3d038f3204",yellowOrangeRed:"fee087fed16ffebd59fea849fd903efc7335f9522bee3423de1b20ca0b22af0225",blueOrange:"134b852f78b35da2cb9dcae1d2e5eff2f0ebfce0bafbbf74e8932fc5690d994a07",brownBlueGreen:"704108a0651ac79548e3c78af3e6c6eef1eac9e9e48ed1c74da79e187a72025147",purpleGreen:"5b1667834792a67fb6c9aed3e6d6e8eff0efd9efd5aedda971bb75368e490e5e29",purpleOrange:"4114696647968f83b7b9b4d6dadbebf3eeeafce0bafbbf74e8932fc5690d994a07",redBlue:"8c0d25bf363adf745ef4ae91fbdbc9f2efeed2e5ef9dcae15da2cb2f78b3134b85",redGrey:"8c0d25bf363adf745ef4ae91fcdccbfaf4f1e2e2e2c0c0c0969696646464343434",yellowGreenBlue:"eff9bddbf1b4bde5b594d5b969c5be45b4c22c9ec02182b82163aa23479c1c3185",redYellowBlue:"a50026d4322cf16e43fcac64fedd90faf8c1dcf1ecabd6e875abd04a74b4313695",redYellowGreen:"a50026d4322cf16e43fcac63fedd8df9f7aed7ee8ea4d86e64bc6122964f006837",pinkYellowGreen:"8e0152c0267edd72adf0b3d6faddedf5f3efe1f2cab6de8780bb474f9125276419",spectral:"9e0142d13c4bf0704afcac63fedd8dfbf8b0e0f3a1a9dda269bda94288b55e4fa2",viridis:"440154470e61481a6c482575472f7d443a834144873d4e8a39568c35608d31688e2d708e2a788e27818e23888e21918d1f988b1fa08822a8842ab07f35b77943bf7154c56866cc5d7ad1518fd744a5db36bcdf27d2e21be9e51afde725",magma:"0000040404130b0924150e3720114b2c11603b0f704a107957157e651a80721f817f24828c29819a2e80a8327db6377ac43c75d1426fde4968e95462f1605df76f5cfa7f5efc8f65fe9f6dfeaf78febf84fece91fddea0fcedaffcfdbf",inferno:"0000040403130c0826170c3b240c4f330a5f420a68500d6c5d126e6b176e781c6d86216b932667a12b62ae305cbb3755c73e4cd24644dd513ae65c30ed6925f3771af8850ffb9506fca50afcb519fac62df6d645f2e661f3f484fcffa4",plasma:"0d088723069033059742039d5002a25d01a66a00a87801a88405a7900da49c179ea72198b12a90ba3488c33d80cb4779d35171da5a69e16462e76e5bed7953f2834cf68f44fa9a3dfca636fdb32ffec029fcce25f9dc24f5ea27f0f921",rainbow:"6e40aa883eb1a43db3bf3cafd83fa4ee4395fe4b83ff576eff6659ff7847ff8c38f3a130e2b72fcfcc36bee044aff05b8ff4576ff65b52f6673af27828ea8d1ddfa319d0b81cbecb23abd82f96e03d82e14c6edb5a5dd0664dbf6e40aa",sinebow:"ff4040fc582af47218e78d0bd5a703bfbf00a7d5038de70b72f41858fc2a40ff402afc5818f4720be78d03d5a700bfbf03a7d50b8de71872f42a58fc4040ff582afc7218f48d0be7a703d5bf00bfd503a7e70b8df41872fc2a58ff4040",browns:"eedbbdecca96e9b97ae4a865dc9856d18954c7784cc0673fb85536ad44339f3632",tealBlues:"bce4d89dd3d181c3cb65b3c245a2b9368fae347da0306a932c5985",teals:"bbdfdfa2d4d58ac9c975bcbb61b0af4da5a43799982b8b8c1e7f7f127273006667",warmGreys:"dcd4d0cec5c1c0b8b4b3aaa7a59c9998908c8b827f7e7673726866665c5a59504e",goldGreen:"f4d166d5ca60b6c35c98bb597cb25760a6564b9c533f8f4f33834a257740146c36",goldOrange:"f4d166f8be5cf8aa4cf5983bf3852aef701be2621fd65322c54923b142239e3a26",goldRed:"f4d166f6be59f9aa51fc964ef6834bee734ae56249db5247cf4244c43141b71d3e",lightGreyRed:"efe9e6e1dad7d5cbc8c8bdb9bbaea9cd967ddc7b43e15f19df4011dc000b",lightGreyTeal:"e4eaead6dcddc8ced2b7c2c7a6b4bc64b0bf22a6c32295c11f85be1876bc",lightMulti:"e0f1f2c4e9d0b0de9fd0e181f6e072f6c053f3993ef77440ef4a3c",lightOrange:"f2e7daf7d5baf9c499fab184fa9c73f68967ef7860e8645bde515bd43d5b",lightTealBlue:"e3e9e0c0dccf9aceca7abfc859afc0389fb9328dad2f7ca0276b95255988",darkBlue:"3232322d46681a5c930074af008cbf05a7ce25c0dd38daed50f3faffffff",darkGold:"3c3c3c584b37725e348c7631ae8b2bcfa424ecc31ef9de30fff184ffffff",darkGreen:"3a3a3a215748006f4d048942489e4276b340a6c63dd2d836ffeb2cffffaa",darkMulti:"3737371f5287197d8c29a86995ce3fffe800ffffff",darkRed:"3434347036339e3c38cc4037e75d1eec8620eeab29f0ce32ffeb2c"},t=>EC(CC(t)));var DC=function(t){t.add(null,e=>(t._background=e.bg,t._resize=1,e.bg),{bg:t._signals.background})},MC=function(t){var e=t._signals.cursor;e||(t._signals.cursor=e=t.add({user:"default",item:null})),t.on(t.events("view","mousemove"),e,function(t,n){var r=e.value,i=r?Object(ct.H)(r)?r:r.user:"default",a=n.item&&n.item.cursor||null;return r&&i===r.user&&a==r.item?r:{user:i,item:a}}),t.add(null,function(t){var e=t.cursor,n=this.value;return Object(ct.H)(e)||(n=e.item,e=e.user),function(t){"undefined"!=typeof document&&document.body&&(document.body.style.cursor=t)}(e&&"default"!==e?e:n||e),n},{cursor:e})};function RC(t,e){var n=t._runtime.data;return Object(ct.v)(n,e)||Object(ct.n)("Unrecognized data set: "+e),n[e]}function FC(t,e){kt(e)||Object(ct.n)("Second argument to changes must be a changeset.");var n=RC(this,t);return n.modified=!0,this.pulse(n.input,e)}function jC(t){var e=t.padding();return Math.max(0,t._viewWidth+e.left+e.right)}function PC(t){var e=t.padding();return Math.max(0,t._viewHeight+e.top+e.bottom)}function LC(t){var e=t.padding(),n=t._origin;return[e.left+n[0],e.top+n[1]]}var zC=function(t,e,n){var r,i,a,o=t._renderer,s=o&&o.canvas();return s&&(a=LC(t),i=e.changedTouches?e.changedTouches[0]:e,(r=Td(i,s))[0]-=a[0],r[1]-=a[1]),e.dataflow=t,e.item=n,e.vega=function(t,e,n){var r=e?"group"===e.mark.marktype?e:e.mark.group:null;function i(t){var n,i=r;if(t)for(n=e;n;n=n.mark.group)if(n.mark.name===t){i=n;break}return i&&i.mark&&i.mark.interactive?i:{}}function a(t){if(!t)return n;Object(ct.H)(t)&&(t=i(t));for(var e=n.slice();t;)e[0]-=t.x||0,e[1]-=t.y||0,t=t.mark&&t.mark.group;return e}return{view:Object(ct.l)(t),item:Object(ct.l)(e||{}),group:i,xy:a,x:function(t){return a(t)[0]},y:function(t){return a(t)[1]}}}(t,n,r),e};const BC="view",UC="timer",WC="window",VC={trap:!1};function qC(t,e,n){const r=t._eventConfig&&t._eventConfig[e];return!(!1===r||Object(ct.F)(r)&&!r[n])||(t.warn(`Blocked ${e} ${n} event listener.`),!1)}function HC(t){return t.item}function GC(t){return t.item.mark.source}function $C(t){return function(e,n){return n.vega.view().changeset().encode(n.item,t)}}var KC=function(t,e,n){var r=document.createElement(t);for(var i in e)r.setAttribute(i,e[i]);return null!=n&&(r.textContent=n),r},XC="vega-bind",YC="vega-bind-name",JC="vega-bind-radio",ZC="vega-option-",QC=function(t,e,n){if(e){var r=n.param,i=n.state;return i||(i=n.state={elements:null,active:!1,set:null,update:function(e){e!==t.signal(r.signal)&&t.runAsync(null,function(){i.source=!0,t.signal(r.signal,e)})}},r.debounce&&(i.update=Object(ct.m)(r.debounce,i.update))),function(t,e,n,r){var i=KC("div",{class:XC});i.appendChild(KC("span",{class:YC},n.name||n.signal)),e.appendChild(i);var a=tA;switch(n.input){case"checkbox":a=eA;break;case"select":a=nA;break;case"radio":a=rA;break;case"range":a=iA}a(t,i,n,r)}(i,e,r,t.signal(r.signal)),i.active||(t.on(t._signals[r.signal],null,function(){i.source?i.source=!1:i.set(t.signal(r.signal))}),i.active=!0),i}};function tA(t,e,n,r){var i=KC("input");for(var a in n)"signal"!==a&&"element"!==a&&i.setAttribute("input"===a?"type":a,n[a]);i.setAttribute("name",n.signal),i.value=r,e.appendChild(i),i.addEventListener("input",function(){t.update(i.value)}),t.elements=[i],t.set=function(t){i.value=t}}function eA(t,e,n,r){var i={type:"checkbox",name:n.signal};r&&(i.checked=!0);var a=KC("input",i);e.appendChild(a),a.addEventListener("change",function(){t.update(a.checked)}),t.elements=[a],t.set=function(t){a.checked=!!t||null}}function nA(t,e,n,r){var i=KC("select",{name:n.signal}),a=n.labels||[];n.options.forEach(function(t,e){var n={value:t};aA(t,r)&&(n.selected=!0),i.appendChild(KC("option",n,(a[e]||t)+""))}),e.appendChild(i),i.addEventListener("change",function(){t.update(n.options[i.selectedIndex])}),t.elements=[i],t.set=function(t){for(var e=0,r=n.options.length;e<r;++e)if(aA(n.options[e],t))return void(i.selectedIndex=e)}}function rA(t,e,n,r){var i=KC("span",{class:JC}),a=n.labels||[];e.appendChild(i),t.elements=n.options.map(function(e,o){var s=ZC+n.signal+"-"+e,u={id:s,type:"radio",name:n.signal,value:e};aA(e,r)&&(u.checked=!0);var c=KC("input",u);return c.addEventListener("change",function(){t.update(e)}),i.appendChild(c),i.appendChild(KC("label",{for:s},(a[o]||e)+"")),c}),t.set=function(e){for(var n=t.elements,r=0,i=n.length;r<i;++r)aA(n[r].value,e)&&(n[r].checked=!0)}}function iA(t,e,n,r){r=void 0!==r?r:(+n.max+ +n.min)/2;var i=null!=n.max?n.max:Math.max(100,+r)||100,a=n.min||Math.min(0,i,+r)||0,o=n.step||ds(a,i,100),s=KC("input",{type:"range",name:n.signal,min:a,max:i,step:o});s.value=r;var u=KC("label",{},+r);function c(){u.textContent=s.value,t.update(+s.value)}e.appendChild(s),e.appendChild(u),s.addEventListener("input",c),s.addEventListener("change",c),t.elements=[s],t.set=function(t){s.value=t,u.textContent=t}}function aA(t,e){return t===e||t+""==e+""}var oA=function(t,e,n,r,i,a){return(e=e||new r(t.loader())).initialize(n,jC(t),PC(t),LC(t),i,a).background(t.background())},sA=function(t,e){return e?function(){try{e.apply(this,arguments)}catch(e){t.error(e)}}:null};function uA(t,e){if("string"==typeof e){if("undefined"==typeof document)return t.error("DOM document instance not found."),null;if(!(e=document.querySelector(e)))return t.error("Signal bind element not found: "+e),null}if(e)try{e.innerHTML=""}catch(n){e=null,t.error(n)}return e}const cA=t=>+t||0;var lA=function(t){return Object(ct.F)(t)?{top:cA(t.top),bottom:cA(t.bottom),left:cA(t.left),right:cA(t.right)}:(t=>({top:t,bottom:t,left:t,right:t}))(cA(t))},fA=async function(t,e,n,r){const i=Eh(e),a=i&&i.headless;return a||Object(ct.n)("Unrecognized renderer type: "+e),await t.runAsync(),oA(t,null,null,a,n,r).renderAsync(t._scenegraph.root)};var dA,hA,pA,mA,gA,vA="RawCode",yA="Literal",bA="Property",xA="Identifier",wA="ArrayExpression",kA="BinaryExpression",_A="CallExpression",EA="ConditionalExpression",OA="LogicalExpression",SA="MemberExpression",CA="ObjectExpression",AA="UnaryExpression";function NA(t){this.type=t}NA.prototype.visit=function(t){var e,n,r;if(t(this))return 1;for(n=0,r=(e=function(t){switch(t.type){case wA:return t.elements;case kA:case OA:return[t.left,t.right];case _A:var e=t.arguments.slice();return e.unshift(t.callee),e;case EA:return[t.test,t.consequent,t.alternate];case SA:return[t.object,t.property];case CA:return t.properties;case bA:return[t.key,t.value];case AA:return[t.argument];case xA:case yA:case vA:default:return[]}}(this)).length;n<r;++n)if(e[n].visit(t))return 1};var TA=1,IA=2,DA=3,MA=4,RA=5,FA=6,jA=7,PA=8;(dA={})[TA]="Boolean",dA[IA]="<end>",dA[DA]="Identifier",dA[MA]="Keyword",dA[RA]="Null",dA[FA]="Numeric",dA[jA]="Punctuator",dA[PA]="String",dA[9]="RegularExpression";var LA="ArrayExpression",zA="BinaryExpression",BA="CallExpression",UA="ConditionalExpression",WA="Identifier",VA="Literal",qA="LogicalExpression",HA="MemberExpression",GA="ObjectExpression",$A="Property",KA="UnaryExpression",XA="Unexpected token %0",YA="Unexpected number",JA="Unexpected string",ZA="Unexpected identifier",QA="Unexpected reserved word",tN="Unexpected end of input",eN="Invalid regular expression",nN="Invalid regular expression: missing /",rN="Octal literals are not allowed in strict mode.",iN="Duplicate data property in object literal not allowed in strict mode",aN="ILLEGAL",oN="Disabled.",sN=new RegExp("[\\xAA\\xB5\\xBA\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0370-\\u0374\\u0376\\u0377\\u037A-\\u037D\\u037F\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u048A-\\u052F\\u0531-\\u0556\\u0559\\u0561-\\u0587\\u05D0-\\u05EA\\u05F0-\\u05F2\\u0620-\\u064A\\u066E\\u066F\\u0671-\\u06D3\\u06D5\\u06E5\\u06E6\\u06EE\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u07F4\\u07F5\\u07FA\\u0800-\\u0815\\u081A\\u0824\\u0828\\u0840-\\u0858\\u08A0-\\u08B2\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0971-\\u0980\\u0985-\\u098C\\u098F\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BD\\u09CE\\u09DC\\u09DD\\u09DF-\\u09E1\\u09F0\\u09F1\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32\\u0A33\\u0A35\\u0A36\\u0A38\\u0A39\\u0A59-\\u0A5C\\u0A5E\\u0A72-\\u0A74\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABD\\u0AD0\\u0AE0\\u0AE1\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3D\\u0B5C\\u0B5D\\u0B5F-\\u0B61\\u0B71\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BD0\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C39\\u0C3D\\u0C58\\u0C59\\u0C60\\u0C61\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDE\\u0CE0\\u0CE1\\u0CF1\\u0CF2\\u0D05-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D3A\\u0D3D\\u0D4E\\u0D60\\u0D61\\u0D7A-\\u0D7F\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0E01-\\u0E30\\u0E32\\u0E33\\u0E40-\\u0E46\\u0E81\\u0E82\\u0E84\\u0E87\\u0E88\\u0E8A\\u0E8D\\u0E94-\\u0E97\\u0E99-\\u0E9F\\u0EA1-\\u0EA3\\u0EA5\\u0EA7\\u0EAA\\u0EAB\\u0EAD-\\u0EB0\\u0EB2\\u0EB3\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EDC-\\u0EDF\\u0F00\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8C\\u1000-\\u102A\\u103F\\u1050-\\u1055\\u105A-\\u105D\\u1061\\u1065\\u1066\\u106E-\\u1070\\u1075-\\u1081\\u108E\\u10A0-\\u10C5\\u10C7\\u10CD\\u10D0-\\u10FA\\u10FC-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u1380-\\u138F\\u13A0-\\u13F4\\u1401-\\u166C\\u166F-\\u167F\\u1681-\\u169A\\u16A0-\\u16EA\\u16EE-\\u16F8\\u1700-\\u170C\\u170E-\\u1711\\u1720-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u1780-\\u17B3\\u17D7\\u17DC\\u1820-\\u1877\\u1880-\\u18A8\\u18AA\\u18B0-\\u18F5\\u1900-\\u191E\\u1950-\\u196D\\u1970-\\u1974\\u1980-\\u19AB\\u19C1-\\u19C7\\u1A00-\\u1A16\\u1A20-\\u1A54\\u1AA7\\u1B05-\\u1B33\\u1B45-\\u1B4B\\u1B83-\\u1BA0\\u1BAE\\u1BAF\\u1BBA-\\u1BE5\\u1C00-\\u1C23\\u1C4D-\\u1C4F\\u1C5A-\\u1C7D\\u1CE9-\\u1CEC\\u1CEE-\\u1CF1\\u1CF5\\u1CF6\\u1D00-\\u1DBF\\u1E00-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FBC\\u1FBE\\u1FC2-\\u1FC4\\u1FC6-\\u1FCC\\u1FD0-\\u1FD3\\u1FD6-\\u1FDB\\u1FE0-\\u1FEC\\u1FF2-\\u1FF4\\u1FF6-\\u1FFC\\u2071\\u207F\\u2090-\\u209C\\u2102\\u2107\\u210A-\\u2113\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u212F-\\u2139\\u213C-\\u213F\\u2145-\\u2149\\u214E\\u2160-\\u2188\\u2C00-\\u2C2E\\u2C30-\\u2C5E\\u2C60-\\u2CE4\\u2CEB-\\u2CEE\\u2CF2\\u2CF3\\u2D00-\\u2D25\\u2D27\\u2D2D\\u2D30-\\u2D67\\u2D6F\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u2E2F\\u3005-\\u3007\\u3021-\\u3029\\u3031-\\u3035\\u3038-\\u303C\\u3041-\\u3096\\u309D-\\u309F\\u30A1-\\u30FA\\u30FC-\\u30FF\\u3105-\\u312D\\u3131-\\u318E\\u31A0-\\u31BA\\u31F0-\\u31FF\\u3400-\\u4DB5\\u4E00-\\u9FCC\\uA000-\\uA48C\\uA4D0-\\uA4FD\\uA500-\\uA60C\\uA610-\\uA61F\\uA62A\\uA62B\\uA640-\\uA66E\\uA67F-\\uA69D\\uA6A0-\\uA6EF\\uA717-\\uA71F\\uA722-\\uA788\\uA78B-\\uA78E\\uA790-\\uA7AD\\uA7B0\\uA7B1\\uA7F7-\\uA801\\uA803-\\uA805\\uA807-\\uA80A\\uA80C-\\uA822\\uA840-\\uA873\\uA882-\\uA8B3\\uA8F2-\\uA8F7\\uA8FB\\uA90A-\\uA925\\uA930-\\uA946\\uA960-\\uA97C\\uA984-\\uA9B2\\uA9CF\\uA9E0-\\uA9E4\\uA9E6-\\uA9EF\\uA9FA-\\uA9FE\\uAA00-\\uAA28\\uAA40-\\uAA42\\uAA44-\\uAA4B\\uAA60-\\uAA76\\uAA7A\\uAA7E-\\uAAAF\\uAAB1\\uAAB5\\uAAB6\\uAAB9-\\uAABD\\uAAC0\\uAAC2\\uAADB-\\uAADD\\uAAE0-\\uAAEA\\uAAF2-\\uAAF4\\uAB01-\\uAB06\\uAB09-\\uAB0E\\uAB11-\\uAB16\\uAB20-\\uAB26\\uAB28-\\uAB2E\\uAB30-\\uAB5A\\uAB5C-\\uAB5F\\uAB64\\uAB65\\uABC0-\\uABE2\\uAC00-\\uD7A3\\uD7B0-\\uD7C6\\uD7CB-\\uD7FB\\uF900-\\uFA6D\\uFA70-\\uFAD9\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFB1D\\uFB1F-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40\\uFB41\\uFB43\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF21-\\uFF3A\\uFF41-\\uFF5A\\uFF66-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC]"),uN=new RegExp("[\\xAA\\xB5\\xBA\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0300-\\u0374\\u0376\\u0377\\u037A-\\u037D\\u037F\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u0483-\\u0487\\u048A-\\u052F\\u0531-\\u0556\\u0559\\u0561-\\u0587\\u0591-\\u05BD\\u05BF\\u05C1\\u05C2\\u05C4\\u05C5\\u05C7\\u05D0-\\u05EA\\u05F0-\\u05F2\\u0610-\\u061A\\u0620-\\u0669\\u066E-\\u06D3\\u06D5-\\u06DC\\u06DF-\\u06E8\\u06EA-\\u06FC\\u06FF\\u0710-\\u074A\\u074D-\\u07B1\\u07C0-\\u07F5\\u07FA\\u0800-\\u082D\\u0840-\\u085B\\u08A0-\\u08B2\\u08E4-\\u0963\\u0966-\\u096F\\u0971-\\u0983\\u0985-\\u098C\\u098F\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BC-\\u09C4\\u09C7\\u09C8\\u09CB-\\u09CE\\u09D7\\u09DC\\u09DD\\u09DF-\\u09E3\\u09E6-\\u09F1\\u0A01-\\u0A03\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32\\u0A33\\u0A35\\u0A36\\u0A38\\u0A39\\u0A3C\\u0A3E-\\u0A42\\u0A47\\u0A48\\u0A4B-\\u0A4D\\u0A51\\u0A59-\\u0A5C\\u0A5E\\u0A66-\\u0A75\\u0A81-\\u0A83\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABC-\\u0AC5\\u0AC7-\\u0AC9\\u0ACB-\\u0ACD\\u0AD0\\u0AE0-\\u0AE3\\u0AE6-\\u0AEF\\u0B01-\\u0B03\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3C-\\u0B44\\u0B47\\u0B48\\u0B4B-\\u0B4D\\u0B56\\u0B57\\u0B5C\\u0B5D\\u0B5F-\\u0B63\\u0B66-\\u0B6F\\u0B71\\u0B82\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BBE-\\u0BC2\\u0BC6-\\u0BC8\\u0BCA-\\u0BCD\\u0BD0\\u0BD7\\u0BE6-\\u0BEF\\u0C00-\\u0C03\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C39\\u0C3D-\\u0C44\\u0C46-\\u0C48\\u0C4A-\\u0C4D\\u0C55\\u0C56\\u0C58\\u0C59\\u0C60-\\u0C63\\u0C66-\\u0C6F\\u0C81-\\u0C83\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBC-\\u0CC4\\u0CC6-\\u0CC8\\u0CCA-\\u0CCD\\u0CD5\\u0CD6\\u0CDE\\u0CE0-\\u0CE3\\u0CE6-\\u0CEF\\u0CF1\\u0CF2\\u0D01-\\u0D03\\u0D05-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D3A\\u0D3D-\\u0D44\\u0D46-\\u0D48\\u0D4A-\\u0D4E\\u0D57\\u0D60-\\u0D63\\u0D66-\\u0D6F\\u0D7A-\\u0D7F\\u0D82\\u0D83\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0DCA\\u0DCF-\\u0DD4\\u0DD6\\u0DD8-\\u0DDF\\u0DE6-\\u0DEF\\u0DF2\\u0DF3\\u0E01-\\u0E3A\\u0E40-\\u0E4E\\u0E50-\\u0E59\\u0E81\\u0E82\\u0E84\\u0E87\\u0E88\\u0E8A\\u0E8D\\u0E94-\\u0E97\\u0E99-\\u0E9F\\u0EA1-\\u0EA3\\u0EA5\\u0EA7\\u0EAA\\u0EAB\\u0EAD-\\u0EB9\\u0EBB-\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EC8-\\u0ECD\\u0ED0-\\u0ED9\\u0EDC-\\u0EDF\\u0F00\\u0F18\\u0F19\\u0F20-\\u0F29\\u0F35\\u0F37\\u0F39\\u0F3E-\\u0F47\\u0F49-\\u0F6C\\u0F71-\\u0F84\\u0F86-\\u0F97\\u0F99-\\u0FBC\\u0FC6\\u1000-\\u1049\\u1050-\\u109D\\u10A0-\\u10C5\\u10C7\\u10CD\\u10D0-\\u10FA\\u10FC-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u135D-\\u135F\\u1380-\\u138F\\u13A0-\\u13F4\\u1401-\\u166C\\u166F-\\u167F\\u1681-\\u169A\\u16A0-\\u16EA\\u16EE-\\u16F8\\u1700-\\u170C\\u170E-\\u1714\\u1720-\\u1734\\u1740-\\u1753\\u1760-\\u176C\\u176E-\\u1770\\u1772\\u1773\\u1780-\\u17D3\\u17D7\\u17DC\\u17DD\\u17E0-\\u17E9\\u180B-\\u180D\\u1810-\\u1819\\u1820-\\u1877\\u1880-\\u18AA\\u18B0-\\u18F5\\u1900-\\u191E\\u1920-\\u192B\\u1930-\\u193B\\u1946-\\u196D\\u1970-\\u1974\\u1980-\\u19AB\\u19B0-\\u19C9\\u19D0-\\u19D9\\u1A00-\\u1A1B\\u1A20-\\u1A5E\\u1A60-\\u1A7C\\u1A7F-\\u1A89\\u1A90-\\u1A99\\u1AA7\\u1AB0-\\u1ABD\\u1B00-\\u1B4B\\u1B50-\\u1B59\\u1B6B-\\u1B73\\u1B80-\\u1BF3\\u1C00-\\u1C37\\u1C40-\\u1C49\\u1C4D-\\u1C7D\\u1CD0-\\u1CD2\\u1CD4-\\u1CF6\\u1CF8\\u1CF9\\u1D00-\\u1DF5\\u1DFC-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FBC\\u1FBE\\u1FC2-\\u1FC4\\u1FC6-\\u1FCC\\u1FD0-\\u1FD3\\u1FD6-\\u1FDB\\u1FE0-\\u1FEC\\u1FF2-\\u1FF4\\u1FF6-\\u1FFC\\u200C\\u200D\\u203F\\u2040\\u2054\\u2071\\u207F\\u2090-\\u209C\\u20D0-\\u20DC\\u20E1\\u20E5-\\u20F0\\u2102\\u2107\\u210A-\\u2113\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u212F-\\u2139\\u213C-\\u213F\\u2145-\\u2149\\u214E\\u2160-\\u2188\\u2C00-\\u2C2E\\u2C30-\\u2C5E\\u2C60-\\u2CE4\\u2CEB-\\u2CF3\\u2D00-\\u2D25\\u2D27\\u2D2D\\u2D30-\\u2D67\\u2D6F\\u2D7F-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u2DE0-\\u2DFF\\u2E2F\\u3005-\\u3007\\u3021-\\u302F\\u3031-\\u3035\\u3038-\\u303C\\u3041-\\u3096\\u3099\\u309A\\u309D-\\u309F\\u30A1-\\u30FA\\u30FC-\\u30FF\\u3105-\\u312D\\u3131-\\u318E\\u31A0-\\u31BA\\u31F0-\\u31FF\\u3400-\\u4DB5\\u4E00-\\u9FCC\\uA000-\\uA48C\\uA4D0-\\uA4FD\\uA500-\\uA60C\\uA610-\\uA62B\\uA640-\\uA66F\\uA674-\\uA67D\\uA67F-\\uA69D\\uA69F-\\uA6F1\\uA717-\\uA71F\\uA722-\\uA788\\uA78B-\\uA78E\\uA790-\\uA7AD\\uA7B0\\uA7B1\\uA7F7-\\uA827\\uA840-\\uA873\\uA880-\\uA8C4\\uA8D0-\\uA8D9\\uA8E0-\\uA8F7\\uA8FB\\uA900-\\uA92D\\uA930-\\uA953\\uA960-\\uA97C\\uA980-\\uA9C0\\uA9CF-\\uA9D9\\uA9E0-\\uA9FE\\uAA00-\\uAA36\\uAA40-\\uAA4D\\uAA50-\\uAA59\\uAA60-\\uAA76\\uAA7A-\\uAAC2\\uAADB-\\uAADD\\uAAE0-\\uAAEF\\uAAF2-\\uAAF6\\uAB01-\\uAB06\\uAB09-\\uAB0E\\uAB11-\\uAB16\\uAB20-\\uAB26\\uAB28-\\uAB2E\\uAB30-\\uAB5A\\uAB5C-\\uAB5F\\uAB64\\uAB65\\uABC0-\\uABEA\\uABEC\\uABED\\uABF0-\\uABF9\\uAC00-\\uD7A3\\uD7B0-\\uD7C6\\uD7CB-\\uD7FB\\uF900-\\uFA6D\\uFA70-\\uFAD9\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFB1D-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40\\uFB41\\uFB43\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE00-\\uFE0F\\uFE20-\\uFE2D\\uFE33\\uFE34\\uFE4D-\\uFE4F\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF10-\\uFF19\\uFF21-\\uFF3A\\uFF3F\\uFF41-\\uFF5A\\uFF66-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC]");function cN(t,e){if(!t)throw new Error("ASSERT: "+e)}function lN(t){return t>=48&&t<=57}function fN(t){return"0123456789abcdefABCDEF".indexOf(t)>=0}function dN(t){return"01234567".indexOf(t)>=0}function hN(t){return 32===t||9===t||11===t||12===t||160===t||t>=5760&&[5760,6158,8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8239,8287,12288,65279].indexOf(t)>=0}function pN(t){return 10===t||13===t||8232===t||8233===t}function mN(t){return 36===t||95===t||t>=65&&t<=90||t>=97&&t<=122||92===t||t>=128&&sN.test(String.fromCharCode(t))}function gN(t){return 36===t||95===t||t>=65&&t<=90||t>=97&&t<=122||t>=48&&t<=57||92===t||t>=128&&uN.test(String.fromCharCode(t))}var vN={if:1,in:1,do:1,var:1,for:1,new:1,try:1,let:1,this:1,else:1,case:1,void:1,with:1,enum:1,while:1,break:1,catch:1,throw:1,const:1,yield:1,class:1,super:1,return:1,typeof:1,delete:1,switch:1,export:1,import:1,public:1,static:1,default:1,finally:1,extends:1,package:1,private:1,function:1,continue:1,debugger:1,interface:1,protected:1,instanceof:1,implements:1};function yN(){for(var t;pA<mA&&(hN(t=hA.charCodeAt(pA))||pN(t));)++pA}function bN(t){var e,n,r,i=0;for(n="u"===t?4:2,e=0;e<n;++e)pA<mA&&fN(hA[pA])?(r=hA[pA++],i=16*i+"0123456789abcdef".indexOf(r.toLowerCase())):FN({},XA,aN);return String.fromCharCode(i)}function xN(){var t,e,n,r;for(e=0,"}"===(t=hA[pA])&&FN({},XA,aN);pA<mA&&fN(t=hA[pA++]);)e=16*e+"0123456789abcdef".indexOf(t.toLowerCase());return(e>1114111||"}"!==t)&&FN({},XA,aN),e<=65535?String.fromCharCode(e):(n=55296+(e-65536>>10),r=56320+(e-65536&1023),String.fromCharCode(n,r))}function wN(){var t,e;for(t=hA.charCodeAt(pA++),e=String.fromCharCode(t),92===t&&(117!==hA.charCodeAt(pA)&&FN({},XA,aN),++pA,(t=bN("u"))&&"\\"!==t&&mN(t.charCodeAt(0))||FN({},XA,aN),e=t);pA<mA&&gN(t=hA.charCodeAt(pA));)++pA,e+=String.fromCharCode(t),92===t&&(e=e.substr(0,e.length-1),117!==hA.charCodeAt(pA)&&FN({},XA,aN),++pA,(t=bN("u"))&&"\\"!==t&&gN(t.charCodeAt(0))||FN({},XA,aN),e+=t);return e}function kN(){var t,e;return t=pA,{type:1===(e=92===hA.charCodeAt(pA)?wN():function(){var t,e;for(t=pA++;pA<mA;){if(92===(e=hA.charCodeAt(pA)))return pA=t,wN();if(!gN(e))break;++pA}return hA.slice(t,pA)}()).length?DA:vN.hasOwnProperty(e)?MA:"null"===e?RA:"true"===e||"false"===e?TA:DA,value:e,start:t,end:pA}}function _N(){var t,e,n,r,i=pA,a=hA.charCodeAt(pA),o=hA[pA];switch(a){case 46:case 40:case 41:case 59:case 44:case 123:case 125:case 91:case 93:case 58:case 63:case 126:return++pA,{type:jA,value:String.fromCharCode(a),start:i,end:pA};default:if(61===(t=hA.charCodeAt(pA+1)))switch(a){case 43:case 45:case 47:case 60:case 62:case 94:case 124:case 37:case 38:case 42:return pA+=2,{type:jA,value:String.fromCharCode(a)+String.fromCharCode(t),start:i,end:pA};case 33:case 61:return pA+=2,61===hA.charCodeAt(pA)&&++pA,{type:jA,value:hA.slice(i,pA),start:i,end:pA}}}return">>>="===(r=hA.substr(pA,4))?{type:jA,value:r,start:i,end:pA+=4}:">>>"===(n=r.substr(0,3))||"<<="===n||">>="===n?{type:jA,value:n,start:i,end:pA+=3}:o===(e=n.substr(0,2))[1]&&"+-<>&|".indexOf(o)>=0||"=>"===e?{type:jA,value:e,start:i,end:pA+=2}:"<>=!+-*%&|^/".indexOf(o)>=0?{type:jA,value:o,start:i,end:++pA}:void FN({},XA,aN)}function EN(){var t,e,n;if(cN(lN((n=hA[pA]).charCodeAt(0))||"."===n,"Numeric literal must start with a decimal digit or a decimal point"),e=pA,t="","."!==n){if(t=hA[pA++],n=hA[pA],"0"===t){if("x"===n||"X"===n)return++pA,function(t){for(var e="";pA<mA&&fN(hA[pA]);)e+=hA[pA++];return 0===e.length&&FN({},XA,aN),mN(hA.charCodeAt(pA))&&FN({},XA,aN),{type:FA,value:parseInt("0x"+e,16),start:t,end:pA}}(e);if(dN(n))return function(t){for(var e="0"+hA[pA++];pA<mA&&dN(hA[pA]);)e+=hA[pA++];return(mN(hA.charCodeAt(pA))||lN(hA.charCodeAt(pA)))&&FN({},XA,aN),{type:FA,value:parseInt(e,8),octal:!0,start:t,end:pA}}(e);n&&lN(n.charCodeAt(0))&&FN({},XA,aN)}for(;lN(hA.charCodeAt(pA));)t+=hA[pA++];n=hA[pA]}if("."===n){for(t+=hA[pA++];lN(hA.charCodeAt(pA));)t+=hA[pA++];n=hA[pA]}if("e"===n||"E"===n)if(t+=hA[pA++],"+"!==(n=hA[pA])&&"-"!==n||(t+=hA[pA++]),lN(hA.charCodeAt(pA)))for(;lN(hA.charCodeAt(pA));)t+=hA[pA++];else FN({},XA,aN);return mN(hA.charCodeAt(pA))&&FN({},XA,aN),{type:FA,value:parseFloat(t),start:e,end:pA}}function ON(){var t,e,n,r;return gA=null,yN(),t=pA,e=function(){var t,e,n,r;for(cN("/"===(t=hA[pA]),"Regular expression literal must start with a slash"),e=hA[pA++],n=!1,r=!1;pA<mA;)if(e+=t=hA[pA++],"\\"===t)pN((t=hA[pA++]).charCodeAt(0))&&FN({},nN),e+=t;else if(pN(t.charCodeAt(0)))FN({},nN);else if(n)"]"===t&&(n=!1);else{if("/"===t){r=!0;break}"["===t&&(n=!0)}return r||FN({},nN),{value:e.substr(1,e.length-2),literal:e}}(),n=function(){var t,e,n;for(e="",n="";pA<mA&&gN((t=hA[pA]).charCodeAt(0));)++pA,"\\"===t&&pA<mA?FN({},XA,aN):(n+=t,e+=t);return n.search(/[^gimuy]/g)>=0&&FN({},eN,n),{value:n,literal:e}}(),r=function(t,e){var n=t;e.indexOf("u")>=0&&(n=n.replace(/\\u\{([0-9a-fA-F]+)\}/g,function(t,e){if(parseInt(e,16)<=1114111)return"x";FN({},eN)}).replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,"x"));try{new RegExp(n)}catch(t){FN({},eN)}try{return new RegExp(t,e)}catch(t){return null}}(e.value,n.value),{literal:e.literal+n.literal,value:r,regex:{pattern:e.value,flags:n.value},start:t,end:pA}}function SN(){var t;return yN(),pA>=mA?{type:IA,start:pA,end:pA}:mN(t=hA.charCodeAt(pA))?kN():40===t||41===t||59===t?_N():39===t||34===t?function(){var t,e,n,r,i="",a=!1;for(cN("'"===(t=hA[pA])||'"'===t,"String literal must starts with a quote"),e=pA,++pA;pA<mA;){if((n=hA[pA++])===t){t="";break}if("\\"===n)if((n=hA[pA++])&&pN(n.charCodeAt(0)))"\r"===n&&"\n"===hA[pA]&&++pA;else switch(n){case"u":case"x":"{"===hA[pA]?(++pA,i+=xN()):i+=bN(n);break;case"n":i+="\n";break;case"r":i+="\r";break;case"t":i+="\t";break;case"b":i+="\b";break;case"f":i+="\f";break;case"v":i+="\v";break;default:dN(n)?(0!==(r="01234567".indexOf(n))&&(a=!0),pA<mA&&dN(hA[pA])&&(a=!0,r=8*r+"01234567".indexOf(hA[pA++]),"0123".indexOf(n)>=0&&pA<mA&&dN(hA[pA])&&(r=8*r+"01234567".indexOf(hA[pA++]))),i+=String.fromCharCode(r)):i+=n}else{if(pN(n.charCodeAt(0)))break;i+=n}}return""!==t&&FN({},XA,aN),{type:PA,value:i,octal:a,start:e,end:pA}}():46===t?lN(hA.charCodeAt(pA+1))?EN():_N():lN(t)?EN():_N()}function CN(){var t;return pA=(t=gA).end,gA=SN(),pA=t.end,t}function AN(){var t;t=pA,gA=SN(),pA=t}function NN(t,e,n){var r=new NA("||"===t||"&&"===t?qA:zA);return r.operator=t,r.left=e,r.right=n,r}function TN(t,e){var n=new NA(BA);return n.callee=t,n.arguments=e,n}function IN(t){var e=new NA(WA);return e.name=t,e}function DN(t){var e=new NA(VA);return e.value=t.value,e.raw=hA.slice(t.start,t.end),t.regex&&("//"===e.raw&&(e.raw="/(?:)/"),e.regex=t.regex),e}function MN(t,e,n){var r=new NA(HA);return r.computed="["===t,r.object=e,r.property=n,r.computed||(n.member=!0),r}function RN(t,e,n){var r=new NA($A);return r.key=e,r.value=n,r.kind=t,r}function FN(t,e){var n,r=Array.prototype.slice.call(arguments,2),i=e.replace(/%(\d)/g,function(t,e){return cN(e<r.length,"Message reference must be in range"),r[e]});throw(n=new Error(i)).index=pA,n.description=i,n}function jN(t){t.type===IA&&FN(t,tN),t.type===FA&&FN(t,YA),t.type===PA&&FN(t,JA),t.type===DA&&FN(t,ZA),t.type===MA&&FN(t,QA),FN(t,XA,t.value)}function PN(t){var e=CN();e.type===jA&&e.value===t||jN(e)}function LN(t){return gA.type===jA&&gA.value===t}function zN(t){return gA.type===MA&&gA.value===t}function BN(){var t=[];for(pA=gA.start,PN("[");!LN("]");)LN(",")?(CN(),t.push(null)):(t.push(ZN()),LN("]")||PN(","));return CN(),function(t){var e=new NA(LA);return e.elements=t,e}(t)}function UN(){var t;return pA=gA.start,(t=CN()).type===PA||t.type===FA?(t.octal&&FN(t,rN),DN(t)):IN(t.value)}function WN(){var t,e,n;return pA=gA.start,(t=gA).type===DA?(n=UN(),PN(":"),RN("init",n,ZN())):t.type!==IA&&t.type!==jA?(e=UN(),PN(":"),RN("init",e,ZN())):void jN(t)}function VN(){var t,e,n=[],r={},i=String;for(pA=gA.start,PN("{");!LN("}");)e="$"+((t=WN()).key.type===WA?t.key.name:i(t.key.value)),Object.prototype.hasOwnProperty.call(r,e)?FN({},iN):r[e]=!0,n.push(t),LN("}")||PN(",");return PN("}"),function(t){var e=new NA(GA);return e.properties=t,e}(n)}var qN={if:1,this:1};function HN(){var t,e,n;if(LN("("))return function(){var t;return PN("("),t=QN(),PN(")"),t}();if(LN("["))return BN();if(LN("{"))return VN();if(t=gA.type,pA=gA.start,t===DA||qN[gA.value])n=IN(CN().value);else if(t===PA||t===FA)gA.octal&&FN(gA,rN),n=DN(CN());else{if(t===MA)throw new Error(oN);t===TA?((e=CN()).value="true"===e.value,n=DN(e)):t===RA?((e=CN()).value=null,n=DN(e)):LN("/")||LN("/=")?(n=DN(ON()),AN()):jN(CN())}return n}function GN(){var t=[];if(PN("("),!LN(")"))for(;pA<mA&&(t.push(ZN()),!LN(")"));)PN(",");return PN(")"),t}function $N(){var t;return pA=gA.start,function(t){return t.type===DA||t.type===MA||t.type===TA||t.type===RA}(t=CN())||jN(t),IN(t.value)}function KN(){var t;return PN("["),t=QN(),PN("]"),t}function XN(){var t=function(){var t;for(t=HN();;)if(LN("."))PN("."),t=MN(".",t,$N());else if(LN("("))t=TN(t,GN());else{if(!LN("["))break;t=MN("[",t,KN())}return t}();if(gA.type===jA&&(LN("++")||LN("--")))throw new Error(oN);return t}function YN(){var t,e;if(gA.type!==jA&&gA.type!==MA)e=XN();else{if(LN("++")||LN("--"))throw new Error(oN);if(LN("+")||LN("-")||LN("~")||LN("!"))t=CN(),e=YN(),e=function(t,e){var n=new NA(KA);return n.operator=t,n.argument=e,n.prefix=!0,n}(t.value,e);else{if(zN("delete")||zN("void")||zN("typeof"))throw new Error(oN);e=XN()}}return e}function JN(t){var e=0;if(t.type!==jA&&t.type!==MA)return 0;switch(t.value){case"||":e=1;break;case"&&":e=2;break;case"|":e=3;break;case"^":e=4;break;case"&":e=5;break;case"==":case"!=":case"===":case"!==":e=6;break;case"<":case">":case"<=":case">=":case"instanceof":case"in":e=7;break;case"<<":case">>":case">>>":e=8;break;case"+":case"-":e=9;break;case"*":case"/":case"%":e=11}return e}function ZN(){var t,e;return t=function(){var t,e,n,r,i,a,o,s,u,c;if(t=gA,u=YN(),0===(i=JN(r=gA)))return u;for(r.prec=i,CN(),e=[t,gA],a=[u,r,o=YN()];(i=JN(gA))>0;){for(;a.length>2&&i<=a[a.length-2].prec;)o=a.pop(),s=a.pop().value,u=a.pop(),e.pop(),n=NN(s,u,o),a.push(n);(r=CN()).prec=i,a.push(r),e.push(gA),n=YN(),a.push(n)}for(n=a[c=a.length-1],e.pop();c>1;)e.pop(),n=NN(a[c-1].value,a[c-2],n),c-=2;return n}(),LN("?")&&(CN(),e=ZN(),PN(":"),t=function(t,e,n){var r=new NA(UA);return r.test=t,r.consequent=e,r.alternate=n,r}(t,e,ZN())),t}function QN(){var t=ZN();if(LN(","))throw new Error(oN);return t}var tT=function(t){pA=0,mA=(hA=t).length,gA=null,AN();var e=QN();if(gA.type!==IA)throw new Error("Unexpect token after expression.");return e},eT={NaN:"NaN",E:"Math.E",LN2:"Math.LN2",LN10:"Math.LN10",LOG2E:"Math.LOG2E",LOG10E:"Math.LOG10E",PI:"Math.PI",SQRT1_2:"Math.SQRT1_2",SQRT2:"Math.SQRT2",MIN_VALUE:"Number.MIN_VALUE",MAX_VALUE:"Number.MAX_VALUE"},nT=function(t){function e(e,n,r){return function(i){return function(e,n,r,i){var a=t(n[0]);return r&&(a=r+"("+a+")",0===r.lastIndexOf("new ",0)&&(a="("+a+")")),a+"."+e+(i<0?"":0===i?"()":"("+n.slice(1).map(t).join(",")+")")}(e,i,n,r)}}var n="new Date";return{isNaN:"Number.isNaN",isFinite:"Number.isFinite",abs:"Math.abs",acos:"Math.acos",asin:"Math.asin",atan:"Math.atan",atan2:"Math.atan2",ceil:"Math.ceil",cos:"Math.cos",exp:"Math.exp",floor:"Math.floor",log:"Math.log",max:"Math.max",min:"Math.min",pow:"Math.pow",random:"Math.random",round:"Math.round",sin:"Math.sin",sqrt:"Math.sqrt",tan:"Math.tan",clamp:function(e){e.length<3&&Object(ct.n)("Missing arguments to clamp function."),e.length>3&&Object(ct.n)("Too many arguments to clamp function.");var n=e.map(t);return"Math.max("+n[1]+", Math.min("+n[2]+","+n[0]+"))"},now:"Date.now",utc:"Date.UTC",datetime:n,date:e("getDate",n,0),day:e("getDay",n,0),year:e("getFullYear",n,0),month:e("getMonth",n,0),hours:e("getHours",n,0),minutes:e("getMinutes",n,0),seconds:e("getSeconds",n,0),milliseconds:e("getMilliseconds",n,0),time:e("getTime",n,0),timezoneoffset:e("getTimezoneOffset",n,0),utcdate:e("getUTCDate",n,0),utcday:e("getUTCDay",n,0),utcyear:e("getUTCFullYear",n,0),utcmonth:e("getUTCMonth",n,0),utchours:e("getUTCHours",n,0),utcminutes:e("getUTCMinutes",n,0),utcseconds:e("getUTCSeconds",n,0),utcmilliseconds:e("getUTCMilliseconds",n,0),length:e("length",null,-1),join:e("join",null),indexof:e("indexOf",null),lastindexof:e("lastIndexOf",null),slice:e("slice",null),reverse:function(e){return"("+t(e[0])+").slice().reverse()"},parseFloat:"parseFloat",parseInt:"parseInt",upper:e("toUpperCase","String",0),lower:e("toLowerCase","String",0),substring:e("substring","String"),split:e("split","String"),replace:e("replace","String"),trim:e("trim","String",0),regexp:"RegExp",test:e("test","RegExp"),if:function(e){e.length<3&&Object(ct.n)("Missing arguments to if function."),e.length>3&&Object(ct.n)("Too many arguments to if function.");var n=e.map(t);return"("+n[0]+"?"+n[1]+":"+n[2]+")"}}};const rT="intersect",iT="union",aT="vlMulti",oT="or",sT="and";var uT="E",cT="R",lT="R-E",fT="R-LE",dT="R-RE",hT="index:unit";function pT(t,e){for(var n,r,i=e.fields,a=e.values,o=i.length,s=0;s<o;++s)if((r=i[s]).getter=ct.t.getter||Object(ct.t)(r.field),n=r.getter(t),Object(ct.C)(n)&&(n=Object(ct.Ca)(n)),Object(ct.C)(a[s])&&(a[s]=Object(ct.Ca)(a[s])),Object(ct.C)(a[s][0])&&(a[s]=a[s].map(ct.Ca)),r.type===uT){if(Object(ct.A)(a[s])?a[s].indexOf(n)<0:n!==a[s])return!1}else if(r.type===cT){if(!Object(ct.z)(n,a[s]))return!1}else if(r.type===dT){if(!Object(ct.z)(n,a[s],!0,!1))return!1}else if(r.type===lT){if(!Object(ct.z)(n,a[s],!1,!1))return!1}else if(r.type===fT&&!Object(ct.z)(n,a[s],!1,!0))return!1;return!0}var mT={E_union:function(t,e){if(!t.length)return e;for(var n=0,r=e.length;n<r;++n)t.indexOf(e[n])<0&&t.push(e[n]);return t},E_intersect:function(t,e){return t.length?t.filter(function(t){return e.indexOf(t)>=0}):e},R_union:function(t,e){var n=Object(ct.Ca)(e[0]),r=Object(ct.Ca)(e[1]);return n>r&&(n=e[1],r=e[0]),t.length?(t[0]>n&&(t[0]=n),t[1]<r&&(t[1]=r),t):[n,r]},R_intersect:function(t,e){var n=Object(ct.Ca)(e[0]),r=Object(ct.Ca)(e[1]);return n>r&&(n=e[1],r=e[0]),t.length?r<t[0]||t[1]<n?[]:(t[0]<n&&(t[0]=n),t[1]>r&&(t[1]=r),t):[n,r]}};const gT=":",vT="@";function yT(t,e,n,r){e[0].type!==yA&&Object(ct.n)("First argument to selection functions must be a string literal.");const i=e[0].value,a=e.length>=2&&Object(ct.U)(e).value,o=vT+"unit",s=gT+i;a!==rT||Object(ct.v)(r,o)||(r[o]=n.getData(i).indataRef(n,"unit")),Object(ct.v)(r,s)||(r[s]=n.getData(i).tuplesRef())}function bT(t){const e=t/255;return e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4)}function xT(t){const e=bm(t);return.2126*bT(e.r)+.7152*bT(e.g)+.0722*bT(e.b)}function wT(t){const e=this.context.data[t];return e?e.values.value:[]}var kT=function(t,e){if((n=(t=e?t.toExponential(e-1):t.toExponential()).indexOf("e"))<0)return null;var n,r=t.slice(0,n);return[r.length>1?r[0]+r.slice(2):r,+t.slice(n+1)]},_T=function(t){return(t=kT(Math.abs(t)))?t[1]:NaN},ET=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function OT(t){if(!(e=ET.exec(t)))throw new Error("invalid format: "+t);var e;return new ST({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}function ST(t){this.fill=void 0===t.fill?" ":t.fill+"",this.align=void 0===t.align?">":t.align+"",this.sign=void 0===t.sign?"-":t.sign+"",this.symbol=void 0===t.symbol?"":t.symbol+"",this.zero=!!t.zero,this.width=void 0===t.width?void 0:+t.width,this.comma=!!t.comma,this.precision=void 0===t.precision?void 0:+t.precision,this.trim=!!t.trim,this.type=void 0===t.type?"":t.type+""}OT.prototype=ST.prototype,ST.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};var CT,AT,NT,TT=function(t){t:for(var e,n=t.length,r=1,i=-1;r<n;++r)switch(t[r]){case".":i=e=r;break;case"0":0===i&&(i=r),e=r;break;default:if(!+t[r])break t;i>0&&(i=0)}return i>0?t.slice(0,i)+t.slice(e+1):t},IT=function(t,e){var n=kT(t,e);if(!n)return t+"";var r=n[0],i=n[1];return i<0?"0."+new Array(-i).join("0")+r:r.length>i+1?r.slice(0,i+1)+"."+r.slice(i+1):r+new Array(i-r.length+2).join("0")},DT={"%":function(t,e){return(100*t).toFixed(e)},b:function(t){return Math.round(t).toString(2)},c:function(t){return t+""},d:function(t){return Math.round(t).toString(10)},e:function(t,e){return t.toExponential(e)},f:function(t,e){return t.toFixed(e)},g:function(t,e){return t.toPrecision(e)},o:function(t){return Math.round(t).toString(8)},p:function(t,e){return IT(100*t,e)},r:IT,s:function(t,e){var n=kT(t,e);if(!n)return t+"";var r=n[0],i=n[1],a=i-(CT=3*Math.max(-8,Math.min(8,Math.floor(i/3))))+1,o=r.length;return a===o?r:a>o?r+new Array(a-o+1).join("0"):a>0?r.slice(0,a)+"."+r.slice(a):"0."+new Array(1-a).join("0")+kT(t,Math.max(0,e+a-1))[0]},X:function(t){return Math.round(t).toString(16).toUpperCase()},x:function(t){return Math.round(t).toString(16)}},MT=function(t){return t},RT=Array.prototype.map,FT=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"],jT=function(t){var e=void 0===t.grouping||void 0===t.thousands?MT:function(t,e){return function(n,r){for(var i=n.length,a=[],o=0,s=t[0],u=0;i>0&&s>0&&(u+s+1>r&&(s=Math.max(1,r-u)),a.push(n.substring(i-=s,i+s)),!((u+=s+1)>r));)s=t[o=(o+1)%t.length];return a.reverse().join(e)}}(RT.call(t.grouping,Number),t.thousands+""),n=void 0===t.currency?"":t.currency[0]+"",r=void 0===t.currency?"":t.currency[1]+"",i=void 0===t.decimal?".":t.decimal+"",a=void 0===t.numerals?MT:function(t){return function(e){return e.replace(/[0-9]/g,function(e){return t[+e]})}}(RT.call(t.numerals,String)),o=void 0===t.percent?"%":t.percent+"",s=void 0===t.minus?"-":t.minus+"",u=void 0===t.nan?"NaN":t.nan+"";function c(t){var c=(t=OT(t)).fill,l=t.align,f=t.sign,d=t.symbol,h=t.zero,p=t.width,m=t.comma,g=t.precision,v=t.trim,y=t.type;"n"===y?(m=!0,y="g"):DT[y]||(void 0===g&&(g=12),v=!0,y="g"),(h||"0"===c&&"="===l)&&(h=!0,c="0",l="=");var b="$"===d?n:"#"===d&&/[boxX]/.test(y)?"0"+y.toLowerCase():"",x="$"===d?r:/[%p]/.test(y)?o:"",w=DT[y],k=/[defgprs%]/.test(y);function _(t){var n,r,o,d=b,_=x;if("c"===y)_=w(t)+_,t="";else{var E=(t=+t)<0||1/t<0;if(t=isNaN(t)?u:w(Math.abs(t),g),v&&(t=TT(t)),E&&0==+t&&"+"!==f&&(E=!1),d=(E?"("===f?f:s:"-"===f||"("===f?"":f)+d,_=("s"===y?FT[8+CT/3]:"")+_+(E&&"("===f?")":""),k)for(n=-1,r=t.length;++n<r;)if(48>(o=t.charCodeAt(n))||o>57){_=(46===o?i+t.slice(n+1):t.slice(n))+_,t=t.slice(0,n);break}}m&&!h&&(t=e(t,1/0));var O=d.length+t.length+_.length,S=O<p?new Array(p-O+1).join(c):"";switch(m&&h&&(t=e(S+t,S.length?p-_.length:1/0),S=""),l){case"<":t=d+t+_+S;break;case"=":t=d+S+t+_;break;case"^":t=S.slice(0,O=S.length>>1)+d+t+_+S.slice(O);break;default:t=S+d+t+_}return a(t)}return g=void 0===g?6:/[gprs]/.test(y)?Math.max(1,Math.min(21,g)):Math.max(0,Math.min(20,g)),_.toString=function(){return t+""},_}return{format:c,formatPrefix:function(t,e){var n=c(((t=OT(t)).type="f",t)),r=3*Math.max(-8,Math.min(8,Math.floor(_T(e)/3))),i=Math.pow(10,-r),a=FT[8+r/3];return function(t){return n(i*t)+a}}}};function PT(t){return AT=jT(t),NT=AT.format,AT.formatPrefix,AT}PT({decimal:".",thousands:",",grouping:[3],currency:["$",""],minus:"-"});const LT={};function zT(t,e,n){let r=t+":"+n,i=LT[r];return i&&i[0]===e||(LT[r]=i=[e,e(n)]),i[1]}function BT(t,e){return zT("timeFormat",rs,e)(t)}var UT=new Date(2e3,0,1);function WT(t,e,n){return Number.isInteger(t)&&Number.isInteger(e)?(UT.setYear(2e3),UT.setMonth(t),UT.setDate(e),BT(UT,n)):""}var VT=function(t,e,n){var r=t-e+2*n;return t?r>0?r:1:0};const qT="log",HT="quantile",GT="continuous",$T="discrete",KT="discretizing",XT="interpolating",YT="temporal";var JT=function(t){return function(e){var n,r=e[0],i=e[1];return i<r&&(n=r,r=i,i=n),[t.invert(r),t.invert(i)]}},ZT=function(t){return function(e){var n,r,i,a,o=t.range(),s=e[0],u=e[1],c=-1;for(u<s&&(r=s,s=u,u=r),i=0,a=o.length;i<a;++i)o[i]>=s&&o[i]<=u&&(c<0&&(c=i),n=i);if(!(c<0))return s=t.invertExtent(o[c]),u=t.invertExtent(o[n]),[void 0===s[0]?s[1]:s[0],void 0===u[1]?u[0]:u[1]]}};function QT(){var t,e,n=Gp().unknown(void 0),r=n.domain,i=n.range,a=[0,1],o=!1,s=0,u=0,c=.5;function l(){var n=r().length,l=a[1]<a[0],f=a[l-0],d=a[1-l],h=VT(n,s,u);t=(d-f)/(h||1),o&&(t=Math.floor(t)),f+=(d-f-t*(n-s))*c,e=t*(1-s),o&&(f=Math.round(f),e=Math.round(e));var p=ro(n).map(function(e){return f+t*e});return i(l?p.reverse():p)}return delete n.unknown,n.domain=function(t){return arguments.length?(r(t),l()):r()},n.range=function(t){return arguments.length?(a=[+t[0],+t[1]],l()):a.slice()},n.rangeRound=function(t){return a=[+t[0],+t[1]],o=!0,l()},n.bandwidth=function(){return e},n.step=function(){return t},n.round=function(t){return arguments.length?(o=!!t,l()):o},n.padding=function(t){return arguments.length?(u=Math.max(0,Math.min(1,t)),s=u,l()):s},n.paddingInner=function(t){return arguments.length?(s=Math.max(0,Math.min(1,t)),l()):s},n.paddingOuter=function(t){return arguments.length?(u=Math.max(0,Math.min(1,t)),l()):u},n.align=function(t){return arguments.length?(c=Math.max(0,Math.min(1,t)),l()):c},n.invertRange=function(t){if(null!=t[0]&&null!=t[1]){var n,o,s,u=+t[0],c=+t[1],l=a[1]<a[0],f=l?i().reverse():i(),d=f.length-1;if(u==u&&c==c&&(c<u&&(s=u,u=c,c=s),!(c<f[0]||u>a[1-l])))return n=Math.max(0,Bp(f,u)-1),o=u===c?n:Bp(f,c)-1,u-f[n]>e+1e-10&&++n,l&&(s=n,n=d-o,o=d-s),n>o?void 0:r().slice(n,o+1)}},n.invert=function(t){var e=n.invertRange([t,t]);return e?e[0]:e},n.copy=function(){return QT().domain(r()).range(a).round(o).paddingInner(s).paddingOuter(u).align(c)},l()}var tI=Array.prototype.map;var eI=Array.prototype.slice;const nI={};function rI(t,e,n){return arguments.length>1?(nI[t]=function(t,e,n){const r=function(){var n=e();return n.invertRange||(n.invertRange=n.invert?JT(n):n.invertExtent?ZT(n):void 0),n.type=t,n};return r.metadata=Object(ct.Da)(Object(ct.i)(n)),r}(t,e,n),this):function(t){return Object(ct.v)(nI,t)}(t)?nI[t]:void 0}rI("identity",iv),rI("linear",fg,GT),rI(qT,xg,[GT,qT]),rI("pow",Ng,GT),rI("sqrt",Tg,GT),rI("symlog",Eg,GT),rI("time",ev,[GT,YT]),rI("utc",nv,[GT,YT]),rI("sequential",Mg,[GT,XT]),rI("sequential-linear",Mg,[GT,XT]),rI(`sequential-${qT}`,Rg,[GT,XT,qT]),rI("sequential-pow",jg,[GT,XT]),rI("sequential-sqrt",Pg,[GT,XT]),rI("sequential-symlog",Fg,[GT,XT]),rI("diverging-linear",zg,[GT,XT]),rI(`diverging-${qT}`,Bg,[GT,XT,qT]),rI("diverging-pow",Wg,[GT,XT]),rI("diverging-sqrt",Vg,[GT,XT]),rI("diverging-symlog",Ug,[GT,XT]),rI(HT,qg,[KT,HT]),rI("quantize",rv,KT),rI("threshold",Zp,KT),rI("bin-ordinal",function t(){var e=[],n=[];function r(t){return null==t||t!=t?void 0:n[(Wp(e,t)-1)%n.length]}return r.domain=function(t){return arguments.length?(e=function(t){return tI.call(t,function(t){return+t})}(t),r):e.slice()},r.range=function(t){return arguments.length?(n=eI.call(t),r):n.slice()},r.tickFormat=function(t,n){return Xp(e[0],Object(ct.U)(e),null==t?10:t,n)},r.copy=function(){return t().domain(r.domain()).range(r.range())},r},[$T,KT]),rI("ordinal",Gp,$T),rI("band",QT,$T),rI("point",function(){return function t(e){var n=e.copy;return e.padding=e.paddingOuter,delete e.paddingInner,e.copy=function(){return t(n())},e}(QT().paddingInner(1))},$T);const iI=["clamp","base","constant","exponent"];function aI(t,e,n){return Qm(function(t,e){var n=a[function(t){return"interpolate"+t.toLowerCase().split("-").map(function(t){return t[0].toUpperCase()+t.slice(1)}).join("")}(t)];return null!=e&&n&&n.gamma?n.gamma(e):n}(e||"rgb",n),t)}function oI(t){for(var e=t.length/6|0,n=new Array(e),r=0;r<e;)n[r]="#"+t.slice(6*r,6*++r);return n}function sI(t,e){for(let n in t)cI(n,e(t[n]))}const uI={};function cI(t,e){return t=t&&t.toLowerCase(),arguments.length>1?(uI[t]=e,this):uI[t]}function lI(t,e){let n;return Object(ct.D)(t)?t:Object(ct.H)(t)?(n=e.scales[t])&&n.value:void 0}sI({category10:"1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf",category20:"1f77b4aec7e8ff7f0effbb782ca02c98df8ad62728ff98969467bdc5b0d58c564bc49c94e377c2f7b6d27f7f7fc7c7c7bcbd22dbdb8d17becf9edae5",category20b:"393b795254a36b6ecf9c9ede6379398ca252b5cf6bcedb9c8c6d31bd9e39e7ba52e7cb94843c39ad494ad6616be7969c7b4173a55194ce6dbdde9ed6",category20c:"3182bd6baed69ecae1c6dbefe6550dfd8d3cfdae6bfdd0a231a35474c476a1d99bc7e9c0756bb19e9ac8bcbddcdadaeb636363969696bdbdbdd9d9d9",tableau10:"4c78a8f58518e4575672b7b254a24beeca3bb279a2ff9da69d755dbab0ac",tableau20:"4c78a89ecae9f58518ffbf7954a24b88d27ab79a20f2cf5b43989483bcb6e45756ff9d9879706ebab0acd67195fcbfd2b279a2d6a5c99e765fd8b5a5",accent:"7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666",dark2:"1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666",paired:"a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928",pastel1:"fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2",pastel2:"b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc",set1:"e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999",set2:"66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3",set3:"8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f"},oI),sI({blues:"cfe1f2bed8eca8cee58fc1de74b2d75ba3cf4592c63181bd206fb2125ca40a4a90",greens:"d3eecdc0e6baabdda594d3917bc77d60ba6c46ab5e329a512089430e7735036429",greys:"e2e2e2d4d4d4c4c4c4b1b1b19d9d9d8888887575756262624d4d4d3535351e1e1e",oranges:"fdd8b3fdc998fdb87bfda55efc9244f87f2cf06b18e4580bd14904b93d029f3303",purples:"e2e1efd4d4e8c4c5e0b4b3d6a3a0cc928ec3827cb97566ae684ea25c3696501f8c",reds:"fdc9b4fcb49afc9e80fc8767fa7051f6573fec3f2fdc2a25c81b1db21218970b13",blueGreen:"d5efedc1e8e0a7ddd18bd2be70c6a958ba9144ad77319c5d2089460e7736036429",bluePurple:"ccddecbad0e4a8c2dd9ab0d4919cc98d85be8b6db28a55a6873c99822287730f71",greenBlue:"d3eecec5e8c3b1e1bb9bd8bb82cec269c2ca51b2cd3c9fc7288abd1675b10b60a1",orangeRed:"fddcaffdcf9bfdc18afdad77fb9562f67d53ee6545e24932d32d1ebf130da70403",purpleBlue:"dbdaebc8cee4b1c3de97b7d87bacd15b9fc93a90c01e7fb70b70ab056199045281",purpleBlueGreen:"dbd8eac8cee4b0c3de93b7d872acd1549fc83892bb1c88a3097f8702736b016353",purpleRed:"dcc9e2d3b3d7ce9eccd186c0da6bb2e14da0e23189d91e6fc61159ab07498f023a",redPurple:"fccfccfcbec0faa9b8f98faff571a5ec539ddb3695c41b8aa908808d0179700174",yellowGreen:"e4f4acd1eca0b9e2949ed68880c97c62bb6e47aa5e3297502083440e723b036034",yellowOrangeBrown:"feeaa1fedd84fecc63feb746fca031f68921eb7215db5e0bc54c05ab3d038f3204",yellowOrangeRed:"fee087fed16ffebd59fea849fd903efc7335f9522bee3423de1b20ca0b22af0225",blueOrange:"134b852f78b35da2cb9dcae1d2e5eff2f0ebfce0bafbbf74e8932fc5690d994a07",brownBlueGreen:"704108a0651ac79548e3c78af3e6c6eef1eac9e9e48ed1c74da79e187a72025147",purpleGreen:"5b1667834792a67fb6c9aed3e6d6e8eff0efd9efd5aedda971bb75368e490e5e29",purpleOrange:"4114696647968f83b7b9b4d6dadbebf3eeeafce0bafbbf74e8932fc5690d994a07",redBlue:"8c0d25bf363adf745ef4ae91fbdbc9f2efeed2e5ef9dcae15da2cb2f78b3134b85",redGrey:"8c0d25bf363adf745ef4ae91fcdccbfaf4f1e2e2e2c0c0c0969696646464343434",yellowGreenBlue:"eff9bddbf1b4bde5b594d5b969c5be45b4c22c9ec02182b82163aa23479c1c3185",redYellowBlue:"a50026d4322cf16e43fcac64fedd90faf8c1dcf1ecabd6e875abd04a74b4313695",redYellowGreen:"a50026d4322cf16e43fcac63fedd8df9f7aed7ee8ea4d86e64bc6122964f006837",pinkYellowGreen:"8e0152c0267edd72adf0b3d6faddedf5f3efe1f2cab6de8780bb474f9125276419",spectral:"9e0142d13c4bf0704afcac63fedd8dfbf8b0e0f3a1a9dda269bda94288b55e4fa2",viridis:"440154470e61481a6c482575472f7d443a834144873d4e8a39568c35608d31688e2d708e2a788e27818e23888e21918d1f988b1fa08822a8842ab07f35b77943bf7154c56866cc5d7ad1518fd744a5db36bcdf27d2e21be9e51afde725",magma:"0000040404130b0924150e3720114b2c11603b0f704a107957157e651a80721f817f24828c29819a2e80a8327db6377ac43c75d1426fde4968e95462f1605df76f5cfa7f5efc8f65fe9f6dfeaf78febf84fece91fddea0fcedaffcfdbf",inferno:"0000040403130c0826170c3b240c4f330a5f420a68500d6c5d126e6b176e781c6d86216b932667a12b62ae305cbb3755c73e4cd24644dd513ae65c30ed6925f3771af8850ffb9506fca50afcb519fac62df6d645f2e661f3f484fcffa4",plasma:"0d088723069033059742039d5002a25d01a66a00a87801a88405a7900da49c179ea72198b12a90ba3488c33d80cb4779d35171da5a69e16462e76e5bed7953f2834cf68f44fa9a3dfca636fdb32ffec029fcce25f9dc24f5ea27f0f921",rainbow:"6e40aa883eb1a43db3bf3cafd83fa4ee4395fe4b83ff576eff6659ff7847ff8c38f3a130e2b72fcfcc36bee044aff05b8ff4576ff65b52f6673af27828ea8d1ddfa319d0b81cbecb23abd82f96e03d82e14c6edb5a5dd0664dbf6e40aa",sinebow:"ff4040fc582af47218e78d0bd5a703bfbf00a7d5038de70b72f41858fc2a40ff402afc5818f4720be78d03d5a700bfbf03a7d50b8de71872f42a58fc4040ff582afc7218f48d0be7a703d5bf00bfd503a7e70b8df41872fc2a58ff4040",browns:"eedbbdecca96e9b97ae4a865dc9856d18954c7784cc0673fb85536ad44339f3632",tealBlues:"bce4d89dd3d181c3cb65b3c245a2b9368fae347da0306a932c5985",teals:"bbdfdfa2d4d58ac9c975bcbb61b0af4da5a43799982b8b8c1e7f7f127273006667",warmGreys:"dcd4d0cec5c1c0b8b4b3aaa7a59c9998908c8b827f7e7673726866665c5a59504e",goldGreen:"f4d166d5ca60b6c35c98bb597cb25760a6564b9c533f8f4f33834a257740146c36",goldOrange:"f4d166f8be5cf8aa4cf5983bf3852aef701be2621fd65322c54923b142239e3a26",goldRed:"f4d166f6be59f9aa51fc964ef6834bee734ae56249db5247cf4244c43141b71d3e",lightGreyRed:"efe9e6e1dad7d5cbc8c8bdb9bbaea9cd967ddc7b43e15f19df4011dc000b",lightGreyTeal:"e4eaead6dcddc8ced2b7c2c7a6b4bc64b0bf22a6c32295c11f85be1876bc",lightMulti:"e0f1f2c4e9d0b0de9fd0e181f6e072f6c053f3993ef77440ef4a3c",lightOrange:"f2e7daf7d5baf9c499fab184fa9c73f68967ef7860e8645bde515bd43d5b",lightTealBlue:"e3e9e0c0dccf9aceca7abfc859afc0389fb9328dad2f7ca0276b95255988",darkBlue:"3232322d46681a5c930074af008cbf05a7ce25c0dd38daed50f3faffffff",darkGold:"3c3c3c584b37725e348c7631ae8b2bcfa424ecc31ef9de30fff184ffffff",darkGreen:"3a3a3a215748006f4d048942489e4276b340a6c63dd2d836ffeb2cffffaa",darkMulti:"3737371f5287197d8c29a86995ce3fffe800ffffff",darkRed:"3434347036339e3c38cc4037e75d1eec8620eeab29f0ce32ffeb2c"},t=>aI(oI(t)));var fI,dI,hI,pI,mI,gI=gx(),vI=gx(),yI={point:Vb,lineStart:Vb,lineEnd:Vb,polygonStart:function(){gI.reset(),yI.lineStart=bI,yI.lineEnd=xI},polygonEnd:function(){var t=+gI;vI.add(t<0?Xb+t:t),this.lineStart=this.lineEnd=this.point=Vb},sphere:function(){vI.add(Xb)}};function bI(){yI.point=wI}function xI(){kI(fI,dI)}function wI(t,e){yI.point=kI,fI=t,dI=e,hI=t*=Jb,pI=ex(e=(e*=Jb)/2+Kb),mI=ox(e)}function kI(t,e){e=(e*=Jb)/2+Kb;var n=(t*=Jb)-hI,r=n>=0?1:-1,i=r*n,a=ex(e),o=ox(e),s=mI*o,u=pI*a+s*ex(i),c=s*r*ox(i);gI.add(tx(c,u)),hI=t,pI=a,mI=o}var _I,EI,OI,SI,CI,AI,NI,TI,II,DI,MI=gx(),RI={point:FI,lineStart:PI,lineEnd:LI,polygonStart:function(){RI.point=zI,RI.lineStart=BI,RI.lineEnd=UI,MI.reset(),yI.polygonStart()},polygonEnd:function(){yI.polygonEnd(),RI.point=FI,RI.lineStart=PI,RI.lineEnd=LI,gI<0?(_I=-(OI=180),EI=-(SI=90)):MI>Hb?SI=90:MI<-Hb&&(EI=-90),DI[0]=_I,DI[1]=OI},sphere:function(){_I=-(OI=180),EI=-(SI=90)}};function FI(t,e){II.push(DI=[_I=t,OI=t]),e<EI&&(EI=e),e>SI&&(SI=e)}function jI(t,e){var n=wx([t*Jb,e*Jb]);if(TI){var r=_x(TI,n),i=_x([r[1],-r[0],0],r);Sx(i),i=xx(i);var a,o=t-CI,s=o>0?1:-1,u=i[0]*Yb*s,c=Zb(o)>180;c^(s*CI<u&&u<s*t)?(a=i[1]*Yb)>SI&&(SI=a):c^(s*CI<(u=(u+360)%360-180)&&u<s*t)?(a=-i[1]*Yb)<EI&&(EI=a):(e<EI&&(EI=e),e>SI&&(SI=e)),c?t<CI?WI(_I,t)>WI(_I,OI)&&(OI=t):WI(t,OI)>WI(_I,OI)&&(_I=t):OI>=_I?(t<_I&&(_I=t),t>OI&&(OI=t)):t>CI?WI(_I,t)>WI(_I,OI)&&(OI=t):WI(t,OI)>WI(_I,OI)&&(_I=t)}else II.push(DI=[_I=t,OI=t]);e<EI&&(EI=e),e>SI&&(SI=e),TI=n,CI=t}function PI(){RI.point=jI}function LI(){DI[0]=_I,DI[1]=OI,RI.point=FI,TI=null}function zI(t,e){if(TI){var n=t-CI;MI.add(Zb(n)>180?n+(n>0?360:-360):n)}else AI=t,NI=e;yI.point(t,e),jI(t,e)}function BI(){yI.lineStart()}function UI(){zI(AI,NI),yI.lineEnd(),Zb(MI)>Hb&&(_I=-(OI=180)),DI[0]=_I,DI[1]=OI,TI=null}function WI(t,e){return(e-=t)<0?e+360:e}function VI(t,e){return t[0]-e[0]}function qI(t,e){return t[0]<=t[1]?t[0]<=e&&e<=t[1]:e<t[0]||t[1]<e}var HI,GI,$I,KI,XI,YI,JI,ZI,QI,tD,eD,nD,rD,iD,aD,oD,sD={sphere:Vb,point:uD,lineStart:lD,lineEnd:hD,polygonStart:function(){sD.lineStart=pD,sD.lineEnd=mD},polygonEnd:function(){sD.lineStart=lD,sD.lineEnd=hD}};function uD(t,e){t*=Jb;var n=ex(e*=Jb);cD(n*ex(t),n*ox(t),ox(e))}function cD(t,e,n){$I+=(t-$I)/++HI,KI+=(e-KI)/HI,XI+=(n-XI)/HI}function lD(){sD.point=fD}function fD(t,e){t*=Jb;var n=ex(e*=Jb);iD=n*ex(t),aD=n*ox(t),oD=ox(e),sD.point=dD,cD(iD,aD,oD)}function dD(t,e){t*=Jb;var n=ex(e*=Jb),r=n*ex(t),i=n*ox(t),a=ox(e),o=tx(ux((o=aD*a-oD*i)*o+(o=oD*r-iD*a)*o+(o=iD*i-aD*r)*o),iD*r+aD*i+oD*a);GI+=o,YI+=o*(iD+(iD=r)),JI+=o*(aD+(aD=i)),ZI+=o*(oD+(oD=a)),cD(iD,aD,oD)}function hD(){sD.point=uD}function pD(){sD.point=gD}function mD(){vD(nD,rD),sD.point=uD}function gD(t,e){nD=t,rD=e,t*=Jb,e*=Jb,sD.point=vD;var n=ex(e);iD=n*ex(t),aD=n*ox(t),oD=ox(e),cD(iD,aD,oD)}function vD(t,e){t*=Jb;var n=ex(e*=Jb),r=n*ex(t),i=n*ox(t),a=ox(e),o=aD*a-oD*i,s=oD*r-iD*a,u=iD*i-aD*r,c=ux(o*o+s*s+u*u),l=fx(c),f=c&&-l/c;QI+=f*o,tD+=f*s,eD+=f*u,GI+=l,YI+=l*(iD+(iD=r)),JI+=l*(aD+(aD=i)),ZI+=l*(oD+(oD=a)),cD(iD,aD,oD)}function yD(t,e){return function(n,r,i){if(n){const e=lI(n,(i||this).context);return e&&e.path[t](r)}return e(r)}}const bD=yD("area",function(t){return vI.reset(),ow(t,yI),2*vI}),xD=yD("bounds",function(t){var e,n,r,i,a,o,s;if(SI=OI=-(_I=EI=1/0),II=[],ow(t,RI),n=II.length){for(II.sort(VI),e=1,a=[r=II[0]];e<n;++e)qI(r,(i=II[e])[0])||qI(r,i[1])?(WI(r[0],i[1])>WI(r[0],r[1])&&(r[1]=i[1]),WI(i[0],r[1])>WI(r[0],r[1])&&(r[0]=i[0])):a.push(r=i);for(o=-1/0,e=0,r=a[n=a.length-1];e<=n;r=i,++e)i=a[e],(s=WI(r[1],i[0]))>o&&(o=s,_I=i[0],OI=r[1])}return II=DI=null,_I===1/0||EI===1/0?[[NaN,NaN],[NaN,NaN]]:[[_I,EI],[OI,SI]]}),wD=yD("centroid",function(t){HI=GI=$I=KI=XI=YI=JI=ZI=QI=tD=eD=0,ow(t,sD);var e=QI,n=tD,r=eD,i=e*e+n*n+r*r;return i<1e-12&&(e=YI,n=JI,r=ZI,GI<Hb&&(e=$I,n=KI,r=XI),(i=e*e+n*n+r*r)<1e-12)?[NaN,NaN]:[tx(n,e)*Yb,fx(r/ux(i))*Yb]});function kD(t,e,n){try{t[e].apply(t,["EXPRESSION"].concat([].slice.call(n)))}catch(e){t.warn(e)}return n[n.length-1]}function _D(t,e){return t===e||t!=t&&e!=e||(Object(ct.A)(t)?!(!Object(ct.A)(e)||t.length!==e.length)&&function(t,e){for(let n=0,r=t.length;n<r;++n)if(!_D(t[n],e[n]))return!1;return!0}(t,e):!(!Object(ct.F)(t)||!Object(ct.F)(e))&&ED(t,e))}function ED(t,e){for(let n in t)if(!_D(t[n],e[n]))return!1;return!0}function OD(t){return e=>ED(t,e)}const SD={};function CD(t){return t.data}function AD(t,e){const n=wT.call(e,t);return n.root&&n.root.lookup||SD}const ND="undefined"!=typeof window&&window||null;const TD=":",ID="@",DD="%";function MD(t,e,n,r){e[0].type!==yA&&Object(ct.n)("First argument to data functions must be a string literal.");const i=e[0].value,a=TD+i;if(!Object(ct.v)(a,r))try{r[a]=n.getData(i).tuplesRef()}catch(t){}}function RD(t,e,n,r){if(e[0].type===yA)FD(n,r,e[0].value);else if(e[0].type===xA)for(t in n.scales)FD(n,r,t)}function FD(t,e,n){const r=DD+n;if(!Object(ct.v)(e,r))try{e[r]=t.scaleRef(n)}catch(t){}}const jD={random:function(){return li()},cumulativeNormal:wi,cumulativeLogNormal:Ci,cumulativeUniform:Mi,densityNormal:xi,densityLogNormal:Si,densityUniform:Di,quantileNormal:ki,quantileLogNormal:Ai,quantileUniform:Ri,sampleNormal:bi,sampleLogNormal:Oi,sampleUniform:Ii,isArray:ct.A,isBoolean:ct.B,isDate:ct.C,isDefined:function(t){return void 0!==t},isNumber:ct.E,isObject:ct.F,isRegExp:ct.G,isString:ct.H,isTuple:pt,isValid:function(t){return null!=t&&t==t},toBoolean:ct.Aa,toDate:ct.Ba,toNumber:ct.Ca,toString:ct.Ea,flush:ct.u,lerp:ct.J,merge:function(){var t=[].slice.call(arguments);return t.unshift({}),ct.o.apply(null,t)},pad:ct.P,peek:ct.U,span:ct.X,inrange:ct.z,truncate:ct.Fa,rgb:bm,lab:zv,hcl:Gv,hsl:Sm,luminance:xT,contrast:function(t,e){const n=xT(t),r=xT(e);return(Math.max(n,r)+.05)/(Math.min(n,r)+.05)},sequence:ro,format:function(t,e){return zT("format",NT,e)(t)},utcFormat:function(t,e){return zT("utcFormat",is,e)(t)},utcParse:function(t,e){return zT("utcParse",on,e)(t)},utcOffset:function(t,e,n){return ts(Qo(t),e,n)},utcSequence:function(t,e,n,r){return es(Qo(t),e,n,r)},timeFormat:BT,timeParse:function(t,e){return zT("timeParse",rn,e)(t)},timeOffset:function(t,e,n){return ts(Zo(t),e,n)},timeSequence:function(t,e,n,r){return es(Zo(t),e,n,r)},timeUnitSpecifier:function(t,e){const n=Object(ct.o)({},ns,e),r=wo(t),i=r.length;let a,o,s="",u=0;for(u=0;u<i;)for(a=r.length;a>u;--a)if(null!=n[o=r.slice(u,a).join("-")]){s+=n[o],u=a;break}return s.trim()},monthFormat:function(t){return WT(t,1,"%B")},monthAbbrevFormat:function(t){return WT(t,1,"%b")},dayFormat:function(t){return WT(0,2+t,"%A")},dayAbbrevFormat:function(t){return WT(0,2+t,"%a")},quarter:ct.V,utcquarter:ct.Ha,warn:function(){return kD(this.context.dataflow,"warn",arguments)},info:function(){return kD(this.context.dataflow,"info",arguments)},debug:function(){return kD(this.context.dataflow,"debug",arguments)},extent:ct.p,inScope:function(t){let e=this.context.group,n=!1;if(e)for(;t;){if(t===e){n=!0;break}t=t.mark.group}return n},intersect:function(t,e,n){if(!t)return[];const[r,i]=t,a=(new yu).set(r[0],r[1],i[0],i[1]);return Oh(n||this.context.dataflow.scenegraph().root,a,function(t){let e=null;if(t){const n=Object(ct.i)(t.marktype),r=Object(ct.i)(t.markname);e=(t=>(!n.length||n.some(e=>t.marktype===e))&&(!r.length||r.some(e=>t.name===e)))}return e}(e))},clampRange:ct.j,pinchDistance:function(t){const e=t.touches,n=e[0].clientX-e[1].clientX,r=e[0].clientY-e[1].clientY;return Math.sqrt(n*n+r*r)},pinchAngle:function(t){const e=t.touches;return Math.atan2(e[0].clientY-e[1].clientY,e[0].clientX-e[1].clientX)},screen:function(){return ND?ND.screen:{}},containerSize:function(){const t=this.context.dataflow,e=t.container&&t.container();return e?[e.clientWidth,e.clientHeight]:[void 0,void 0]},windowSize:function(){return ND?[ND.innerWidth,ND.innerHeight]:[void 0,void 0]},bandspace:function(t,e,n){return VT(t||0,e||0,n||0)},setdata:function(t,e){const n=this.context.dataflow,r=this.context.data[t].input;return n.pulse(r,n.changeset().remove(ct.Ga).insert(e)),1},pathShape:function(t){let e=null;return function(n){return n?Uc(n,e=e||Nc(t)):t}},panLinear:ct.Q,panLog:ct.R,panPow:ct.S,panSymlog:ct.T,zoomLinear:ct.La,zoomLog:ct.Ma,zoomPow:ct.Na,zoomSymlog:ct.Oa,encode:function(t,e,n){if(t){const n=this.context.dataflow,r=t.mark.source;n.pulse(r,n.changeset().encode(t,e))}return void 0!==n?n:t},modify:function(t,e,n,r,i,a){let o,s,u=this.context.dataflow,c=this.context.data[t],l=c.input,f=c.changes,d=u.stamp();if(!1===u._trigger||!(l.value.length||e||r))return 0;if((!f||f.stamp<d)&&(c.changes=f=u.changeset(),f.stamp=d,u.runAfter(function(){c.modified=!0,u.pulse(l,f).run()},!0,1)),n&&(o=!0===n?ct.Ga:Object(ct.A)(n)||pt(n)?n:OD(n),f.remove(o)),e&&f.insert(e),r&&(o=OD(r),l.value.some(o)?f.remove(o):f.insert(r)),i)for(s in a)f.modify(i,s,a[s]);return 1}},PD=["view","item","group","xy","x","y"],LD="event.vega.",zD="this.",BD={};function UD(t,e,n){return 1===arguments.length?jD[t]:(jD[t]=e,n&&(BD[t]=n),VD&&(VD.functions[t]=zD+t),this)}UD("bandwidth",function(t,e){const n=lI(t,(e||this).context);return n&&n.bandwidth?n.bandwidth():0},RD),UD("copy",function(t,e){const n=lI(t,(e||this).context);return n?n.copy():void 0},RD),UD("domain",function(t,e){const n=lI(t,(e||this).context);return n?n.domain():[]},RD),UD("range",function(t,e){const n=lI(t,(e||this).context);return n&&n.range?n.range():[]},RD),UD("invert",function(t,e,n){const r=lI(t,(n||this).context);return r?Object(ct.A)(e)?(r.invertRange||r.invert)(e):(r.invert||r.invertExtent)(e):void 0},RD),UD("scale",function(t,e,n){const r=lI(t,(n||this).context);return r&&void 0!==e?r(e):void 0},RD),UD("gradient",function(t,e,n,r,i){t=lI(t,(i||this).context);const a=Ou(e,n);let o=t.domain(),s=o[0],u=Object(ct.U)(o),c=ct.x;return u-s?c=function(t,e,n){var r,i,a,o=n-e;return o&&Number.isFinite(o)?(r=(i=t.type).indexOf("-"),i=r<0?i:i.slice(r+1),a=rI(i)().domain([e,n]).range([0,1]),iI.forEach(e=>t[e]?a[e](t[e]()):0),a):Object(ct.l)(.5)}(t,s,u):t=(t.interpolator?rI("sequential")().interpolator(t.interpolator()):rI("linear")().interpolate(t.interpolate()).range(t.range())).domain([s=0,u=1]),t.ticks&&(s!==(o=t.ticks(+r||15))[0]&&o.unshift(s),u!==Object(ct.U)(o)&&o.push(u)),o.forEach(e=>a.stop(c(e),t(e))),a},RD),UD("geoArea",bD,RD),UD("geoBounds",xD,RD),UD("geoCentroid",wD,RD),UD("geoShape",function(t,e,n){const r=lI(t,(n||this).context);return function(t){return r?r.path.context(t)(e):""}},RD),UD("indata",function(t,e,n){const r=this.context.data[t]["index:"+e],i=r?r.value.get(n):void 0;return i?i.count:i},function(t,e,n,r){e[0].type!==yA&&Object(ct.n)("First argument to indata must be a string literal."),e[1].type!==yA&&Object(ct.n)("Second argument to indata must be a string literal.");const i=e[0].value,a=e[1].value,o=ID+a;Object(ct.v)(o,r)||(r[o]=n.getData(i).indataRef(n,a))}),UD("data",wT,MD),UD("treePath",function(t,e,n){const r=AD(t,this),i=r[e],a=r[n];return i&&a?i.path(a).map(CD):void 0},MD),UD("treeAncestors",function(t,e){const n=AD(t,this)[e];return n?n.ancestors().map(CD):void 0},MD),UD("vlSelectionTest",function(t,e,n){for(var r,i,a,o,s,u=this.context.data[t],c=u?u.values.value:[],l=u?u[hT]&&u[hT].value:void 0,f=n===rT,d=c.length,h=0;h<d;++h)if(r=c[h],l&&f){if(-1===(a=(i=i||{})[o=r.unit]||0))continue;if(s=pT(e,r),i[o]=s?-1:++a,s&&1===l.size)return!0;if(!s&&a===l.get(o).count)return!1}else if(f^(s=pT(e,r)))return s;return d&&f},yT),UD("vlSelectionResolve",function(t,e,n){for(var r,i,a,o,s,u,c,l,f,d,h,p=this.context.data[t],m=p?p.values.value:[],g={},v={},y={},b=m.length,x=0;x<b;++x){for(o=(r=m[x]).unit,i=r.fields,a=r.values,d=0,h=i.length;d<h;++d)s=i[d],c=(u=g[s.field]||(g[s.field]={}))[o]||(u[o]=[]),y[s.field]=l=s.type.charAt(0),f=mT[l+"_union"],u[o]=f(c,Object(ct.i)(a[d]));n&&(c=v[o]||(v[o]=[])).push(Object(ct.i)(a).reduce((t,e,n)=>(t[i[n].field]=e,t),{}))}return e=e||iT,Object.keys(g).forEach(function(t){g[t]=Object.keys(g[t]).map(e=>g[t][e]).reduce((n,r)=>void 0===n?r:mT[y[t]+"_"+e](n,r))}),m=Object.keys(v),n&&m.length&&(g[aT]=e===iT?{[oT]:m.reduce((t,e)=>(t.push.apply(t,v[e]),t),[])}:{[sT]:m.map(t=>({[oT]:v[t]}))}),g},yT);const WD={blacklist:["_"],whitelist:["datum","event","item"],fieldvar:"datum",globalvar:function(t){return"_["+Object(ct.Z)("$"+t)+"]"},functions:function(t){const e=nT(t);PD.forEach(t=>e[t]=LD+t);for(let t in jD)e[t]=zD+t;return e},constants:eT,visitors:BD};var VD=function(t){var e=(t=t||{}).whitelist?Object(ct.Da)(t.whitelist):{},n=t.blacklist?Object(ct.Da)(t.blacklist):{},r=t.constants||eT,i=(t.functions||nT)(f),a=t.globalvar,o=t.fieldvar,s={},u={},c=0,l=Object(ct.D)(a)?a:function(t){return a+'["'+t+'"]'};function f(t){if(Object(ct.H)(t))return t;var e=d[t.type];return null==e&&Object(ct.n)("Unsupported type: "+t.type),e(t)}var d={Literal:function(t){return t.raw},Identifier:function(t){var i=t.name;return c>0?i:Object(ct.v)(n,i)?Object(ct.n)("Illegal identifier: "+i):Object(ct.v)(r,i)?r[i]:Object(ct.v)(e,i)?i:(s[i]=1,l(i))},MemberExpression:function(t){var e=!t.computed,n=f(t.object);e&&(c+=1);var r=f(t.property);return n===o&&(u[function(t){var e=t&&t.length-1;return e&&('"'===t[0]&&'"'===t[e]||"'"===t[0]&&"'"===t[e])?t.slice(1,-1):t}(r)]=1),e&&(c-=1),n+(e?"."+r:"["+r+"]")},CallExpression:function(t){"Identifier"!==t.callee.type&&Object(ct.n)("Illegal callee type: "+t.callee.type);var e=t.callee.name,n=t.arguments,r=Object(ct.v)(i,e)&&i[e];return r||Object(ct.n)("Unrecognized function: "+e),Object(ct.D)(r)?r(n):r+"("+n.map(f).join(",")+")"},ArrayExpression:function(t){return"["+t.elements.map(f).join(",")+"]"},BinaryExpression:function(t){return"("+f(t.left)+t.operator+f(t.right)+")"},UnaryExpression:function(t){return"("+t.operator+f(t.argument)+")"},ConditionalExpression:function(t){return"("+f(t.test)+"?"+f(t.consequent)+":"+f(t.alternate)+")"},LogicalExpression:function(t){return"("+f(t.left)+t.operator+f(t.right)+")"},ObjectExpression:function(t){return"{"+t.properties.map(f).join(",")+"}"},Property:function(t){c+=1;var e=f(t.key);return c-=1,e+":"+f(t.value)}};function h(t){var e={code:f(t),globals:Object.keys(s),fields:Object.keys(u)};return s={},u={},e}return h.functions=i,h.constants=r,h}(WD);function qD(t,e,n){";"!==e[e.length-1]&&(e="return("+e+");");var r=Function.apply(null,t.concat(e));return n&&n.functions?r.bind(n.functions):r}function HD(t,e){return qD(["event"],t,e)}function GD(t,e){return qD(["item","_"],t,e)}function $D(t,e,n){var r,i;for(r in n=n||{},t)i=t[r],n[r]=Object(ct.A)(i)?i.map(function(t){return KD(t,e,n)}):KD(i,e,n);return n}function KD(t,e,n){if(!t||!Object(ct.F)(t))return t;for(var r,i=0,a=XD.length;i<a;++i)if(r=XD[i],Object(ct.v)(t,r.key))return r.parse(t,e,n);return t}var XD=[{key:"$ref",parse:function(t,e){return e.get(t.$ref)||Object(ct.n)("Operator not defined: "+t.$ref)}},{key:"$key",parse:function(t,e){var n="k:"+t.$key+"_"+!!t.$flat;return e.fn[n]||(e.fn[n]=Object(ct.I)(t.$key,t.$flat))}},{key:"$expr",parse:function(t,e,n){t.$params&&$D(t.$params,e,n);var r="e:"+t.$expr+"_"+t.$name;return e.fn[r]||(e.fn[r]=Object(ct.f)(function(t,e){return qD(["datum","_"],t,e)}(t.$expr,e),t.$fields,t.$name))}},{key:"$field",parse:function(t,e){if(!t.$field)return null;var n="f:"+t.$field+"_"+t.$name;return e.fn[n]||(e.fn[n]=Object(ct.t)(t.$field,t.$name))}},{key:"$encode",parse:function(t,e){var n,r,i=t.$encode,a={};for(n in i)r=i[n],a[n]=Object(ct.f)(GD(r.$expr,e),r.$fields),a[n].output=r.$output;return a}},{key:"$compare",parse:function(t,e){var n="c:"+t.$compare+"_"+t.$order,r=Object(ct.i)(t.$compare).map(function(t){return t&&t.$tupleid?mt:t});return e.fn[n]||(e.fn[n]=Object(ct.k)(r,t.$order))}},{key:"$context",parse:function(t,e){return e}},{key:"$subflow",parse:function(t,e){var n=t.$subflow;return function(t,r,i){var a=QD(n,e.fork()),o=a.get(n.operators[0].id),s=a.signals.parent;return s&&s.set(i),o}}},{key:"$tupleid",parse:function(){return mt}}];function YD(t){return(t+"").toLowerCase()}var JD=function(t,e){!function(t){return"operator"===YD(t)}(t.type)&&t.type?e.transform(t,t.type):e.operator(t,t.update?function(t,e){return qD(["_"],t,e)}(t.update,e):null)};var ZD=function(t,e){var n=Object(ct.F)(n=t.source)?n.$ref:n,r=e.get(n),i=null,a=t.update,o=void 0;r||Object(ct.n)("Source not defined: "+t.source),i=t.target&&t.target.$expr?HD(t.target.$expr,e):e.get(t.target),a&&a.$expr&&(a.$params&&(o=$D(a.$params,e)),a=function(t,e){return qD(["_","event"],t,e)}(a.$expr,e)),e.update(t,r,i,a,o)},QD=function(t,e){var n=t.operators||[];return t.background&&(e.background=t.background),t.eventConfig&&(e.eventConfig=t.eventConfig),n.forEach(function(t){JD(t,e)}),n.forEach(function(t){!function(t,e){if(t.params){var n=e.get(t.id);n||Object(ct.n)("Invalid operator id: "+t.id),e.dataflow.connect(n,n.parameters($D(t.params,e),t.react,t.initonly))}}(t,e)}),(t.streams||[]).forEach(function(t){!function(t,e){var n,r=null!=t.filter?HD(t.filter,e):void 0,i=null!=t.stream?e.get(t.stream):void 0;t.source?i=e.events(t.source,t.type,r):t.merge&&(i=(n=t.merge.map(e.get.bind(e)))[0].merge.apply(n[0],n.slice(1))),t.between&&(n=t.between.map(e.get.bind(e)),i=i.between(n[0],n[1])),t.filter&&(i=i.filter(r)),null!=t.throttle&&(i=i.throttle(+t.throttle)),null!=t.debounce&&(i=i.debounce(+t.debounce)),null==i&&Object(ct.n)("Invalid stream definition: "+JSON.stringify(t)),t.consume&&i.consume(!0),e.stream(t,i)}(t,e)}),(t.updates||[]).forEach(function(t){ZD(t,e)}),e.resolve()},tM={skip:!0};var eM=function(t,e,n){return new nM(t,e,n)};function nM(t,e,n){this.dataflow=t,this.transforms=e,this.events=t.events.bind(t),this.signals={},this.scales={},this.nodes={},this.data={},this.fn={},n&&(this.functions=Object.create(n),this.functions.context=this)}function rM(t){this.dataflow=t.dataflow,this.transforms=t.transforms,this.functions=t.functions,this.events=t.events,this.signals=Object.create(t.signals),this.scales=Object.create(t.scales),this.nodes=Object.create(t.nodes),this.data=Object.create(t.data),this.fn=Object.create(t.fn),t.functions&&(this.functions=Object.create(t.functions),this.functions.context=this)}nM.prototype=rM.prototype={fork:function(){var t=new rM(this);return(this.subcontext||(this.subcontext=[])).push(t),t},get:function(t){return this.nodes[t]},set:function(t,e){return this.nodes[t]=e},add:function(t,e){var n,r=this,i=r.dataflow;if(r.set(t.id,e),function(t){return"collect"===YD(t)}(t.type)&&(n=t.value)&&(n.$ingest?i.ingest(e,n.$ingest,n.$format):n.$request?i.preload(e,n.$request,n.$format):i.pulse(e,i.changeset().insert(n))),t.root&&(r.root=e),t.parent){var a=r.get(t.parent.$ref);a?(i.connect(a,[e]),e.targets().add(a)):(r.unresolved=r.unresolved||[]).push(function(){a=r.get(t.parent.$ref),i.connect(a,[e]),e.targets().add(a)})}if(t.signal&&(r.signals[t.signal]=e),t.scale&&(r.scales[t.scale]=e),t.data)for(var o in t.data)n=r.data[o]||(r.data[o]={}),t.data[o].forEach(function(t){n[t]=e})},resolve:function(){return(this.unresolved||[]).forEach(function(t){t()}),delete this.unresolved,this},operator:function(t,e){this.add(t,this.dataflow.add(t.value,e))},transform:function(t,e){this.add(t,this.dataflow.add(this.transforms[YD(e)]))},stream:function(t,e){this.set(t.id,e)},update:function(t,e,n,r,i){this.dataflow.on(e,n,r,i,t.options)},getState:function(t){var e=this,n={};if(t.signals){var r=n.signals={};Object.keys(e.signals).forEach(function(n){var i=e.signals[n];t.signals(n,i)&&(r[n]=i.value)})}if(t.data){var i=n.data={};Object.keys(e.data).forEach(function(n){var r=e.data[n];t.data(n,r)&&(i[n]=r.input.value)})}return e.subcontext&&!1!==t.recurse&&(n.subcontext=e.subcontext.map(function(e){return e.getState(t)})),n},setState:function(t){var e=this,n=e.dataflow,r=t.data,i=t.signals;Object.keys(i||{}).forEach(function(t){n.update(e.signals[t],i[t],tM)}),Object.keys(r||{}).forEach(function(t){n.pulse(e.data[t].input,n.changeset().remove(ct.Ga).insert(r[t]))}),(t.subcontext||[]).forEach(function(t,n){var r=e.subcontext[n];r&&r.setState(t)})}};var iM=function(t,e,n){return QD(e,eM(t,Wr,n||jD))};var aM="width",oM="height",sM="padding",uM={skip:!0};function cM(t,e){var n=t.autosize(),r=t.padding();return e-(n&&n.contains===sM?r.left+r.right:0)}function lM(t,e){var n=t.autosize(),r=t.padding();return e-(n&&n.contains===sM?r.top+r.bottom:0)}function fM(t,e){return e.modified&&Object(ct.A)(e.input.value)&&t.indexOf("_:vega:_")}function dM(t,e){return!("parent"===t||e instanceof Wr.proxy)}var hM=function(t,e,n,r){var i=t.element();i&&i.setAttribute("title",function(t){return null==t?"":Object(ct.A)(t)?pM(t):Object(ct.F)(t)&&!Object(ct.C)(t)?function(t){return Object.keys(t).map(function(e){var n=t[e];return e+": "+(Object(ct.A)(n)?pM(n):mM(n))}).join("\n")}(t):t+""}(r))};function pM(t){return"["+t.map(mM).join(", ")+"]"}function mM(t){return Object(ct.A)(t)?"[…]":Object(ct.F)(t)&&!Object(ct.C)(t)?"{…}":t}function gM(t,e){e=e||{},Pr.call(this),e.loader&&this.loader(e.loader),e.logger&&this.logger(e.logger),null!=e.logLevel&&this.logLevel(e.logLevel),this._el=null,this._elBind=null,this._renderType=e.renderer||kh.Canvas,this._scenegraph=new kd;var n=this._scenegraph.root;this._renderer=null,this._tooltip=e.tooltip||hM,this._redraw=!0,this._handler=(new Pd).scene(n),this._preventDefault=!1,this._timers=[],this._eventListeners=[],this._resizeListeners=[],this._eventConfig=function(t){const e=Object(ct.o)({defaults:{}},t),n=(t,e)=>{e.forEach(e=>{Object(ct.A)(t[e])&&(t[e]=Object(ct.Da)(t[e]))})};return n(e.defaults,["prevent","allow"]),n(e,["view","window","selector"]),e}(t.eventConfig);var r=iM(this,t,e.functions);this._runtime=r,this._signals=r.signals,this._bind=(t.bindings||[]).map(function(t){return{state:null,param:Object(ct.o)({},t)}}),r.root&&r.root.set(n),n.source=r.data.root.input,this.pulse(r.data.root.input,this.changeset().insert(n.items)),this._width=this.width(),this._height=this.height(),this._viewWidth=cM(this,this._width),this._viewHeight=lM(this,this._height),this._origin=[0,0],this._resize=0,this._autosize=1,function(t){var e=t._signals,n=e[aM],r=e[oM],i=e[sM];function a(){t._autosize=t._resize=1}t._resizeWidth=t.add(null,function(e){t._width=e.size,t._viewWidth=cM(t,e.size),a()},{size:n}),t._resizeHeight=t.add(null,function(e){t._height=e.size,t._viewHeight=lM(t,e.size),a()},{size:r});var o=t.add(null,a,{pad:i});t._resizeWidth.rank=n.rank+1,t._resizeHeight.rank=r.rank+1,o.rank=i.rank+1}(this),DC(this),MC(this),this.description(t.description),e.hover&&this.hover(),e.container&&this.initialize(e.container,e.bind)}var vM=Object(ct.y)(gM,Pr);function yM(t,e){return Object(ct.v)(t._signals,e)?t._signals[e]:Object(ct.n)("Unrecognized signal name: "+Object(ct.Z)(e))}function bM(t,e){var n=(t._targets||[]).filter(function(t){var n=t._update;return n&&n.handler===e});return n.length?n[0]:null}function xM(t,e,n,r){var i=bM(n,r);return i||((i=sA(this,function(){r(e,n.value)})).handler=r,t.on(n,null,i)),t}function wM(t,e,n){var r=bM(e,n);return r&&e._targets.remove(r),t}vM.evaluate=async function(t,e,n){if(await Pr.prototype.evaluate.call(this,t,e),this._redraw||this._resize)try{this._renderer&&(this._resize&&(this._resize=0,function(t){var e=LC(t),n=jC(t),r=PC(t);t._renderer.background(t.background()),t._renderer.resize(n,r,e),t._handler.origin(e),t._resizeListeners.forEach(function(e){try{e(n,r)}catch(e){t.error(e)}})}(this)),await this._renderer.renderAsync(this._scenegraph.root)),this._redraw=!1}catch(t){this.error(t)}return n&&ft(this,n),this},vM.dirty=function(t){this._redraw=!0,this._renderer&&this._renderer.dirty(t)},vM.description=function(t){if(arguments.length){const e=null!=t?t+"":null;return e!==this._desc&&IC(this._el,this._desc=e),this}return this._desc},vM.container=function(){return this._el},vM.scenegraph=function(){return this._scenegraph},vM.origin=function(){return this._origin.slice()},vM.signal=function(t,e,n){var r=yM(this,t);return 1===arguments.length?r.value:this.update(r,e,n)},vM.width=function(t){return arguments.length?this.signal("width",t):this.signal("width")},vM.height=function(t){return arguments.length?this.signal("height",t):this.signal("height")},vM.padding=function(t){return arguments.length?this.signal("padding",lA(t)):lA(this.signal("padding"))},vM.autosize=function(t){return arguments.length?this.signal("autosize",t):this.signal("autosize")},vM.background=function(t){return arguments.length?this.signal("background",t):this.signal("background")},vM.renderer=function(t){return arguments.length?(Eh(t)||Object(ct.n)("Unrecognized renderer type: "+t),t!==this._renderType&&(this._renderType=t,this._resetRenderer()),this):this._renderType},vM.tooltip=function(t){return arguments.length?(t!==this._tooltip&&(this._tooltip=t,this._resetRenderer()),this):this._tooltip},vM.loader=function(t){return arguments.length?(t!==this._loader&&(Pr.prototype.loader.call(this,t),this._resetRenderer()),this):this._loader},vM.resize=function(){return this._autosize=1,this.touch(yM(this,"autosize"))},vM._resetRenderer=function(){this._renderer&&(this._renderer=null,this.initialize(this._el,this._elBind))},vM._resizeView=function(t,e,n,r,i,a){this.runAfter(function(o){var s=0;o._autosize=0,o.width()!==n&&(s=1,o.signal(aM,n,uM),o._resizeWidth.skip(!0)),o.height()!==r&&(s=1,o.signal(oM,r,uM),o._resizeHeight.skip(!0)),o._viewWidth!==t&&(o._resize=1,o._viewWidth=t),o._viewHeight!==e&&(o._resize=1,o._viewHeight=e),o._origin[0]===i[0]&&o._origin[1]===i[1]||(o._resize=1,o._origin=i),s&&o.run("enter"),a&&o.runAfter(t=>t.resize())},!1,1)},vM.addEventListener=function(t,e,n){var r=e;return n&&!1===n.trap||((r=sA(this,e)).raw=e),this._handler.on(t,r),this},vM.removeEventListener=function(t,e){for(var n,r,i=this._handler.handlers(t),a=i.length;--a>=0;)if(r=i[a].type,n=i[a].handler,t===r&&(e===n||e===n.raw)){this._handler.off(r,n);break}return this},vM.addResizeListener=function(t){var e=this._resizeListeners;return e.indexOf(t)<0&&e.push(t),this},vM.removeResizeListener=function(t){var e=this._resizeListeners,n=e.indexOf(t);return n>=0&&e.splice(n,1),this},vM.addSignalListener=function(t,e){return xM(this,t,yM(this,t),e)},vM.removeSignalListener=function(t,e){return wM(this,yM(this,t),e)},vM.addDataListener=function(t,e){return xM(this,t,RC(this,t).values,e)},vM.removeDataListener=function(t,e){return wM(this,RC(this,t).values,e)},vM.preventDefault=function(t){return arguments.length?(this._preventDefault=t,this):this._preventDefault},vM.timer=function(t,e){this._timers.push(function(t,e,n){var r=new Z_,i=e;return null==e?(r.restart(t,e,n),r):(e=+e,n=null==n?Y_():+n,r.restart(function a(o){o+=i,r.restart(a,i+=e,n),t(o)},e,n),r)}(function(e){t({timestamp:Date.now(),elapsed:e})},e))},vM.events=function(t,e,n){var r,i=this,a=new Mt(n),o=function(n,r){i.runAsync(null,()=>{t===BC&&function(t,e){var n=t._eventConfig.defaults,r=n.prevent,i=n.allow;return!1!==r&&!0!==i&&(!0===r||!1===i||(r?r[e]:i?!i[e]:t.preventDefault()))}(i,e)&&n.preventDefault(),a.receive(zC(i,n,r))})};if(t===UC)qC(i,"timer",e)&&i.timer(o,e);else if(t===BC)qC(i,"view",e)&&i.addEventListener(e,o,VC);else if(t===WC?qC(i,"window",e)&&"undefined"!=typeof window&&(r=[window]):"undefined"!=typeof document&&qC(i,"selector",e)&&(r=document.querySelectorAll(t)),r){for(var s=0,u=r.length;s<u;++s)r[s].addEventListener(e,o);i._eventListeners.push({type:e,sources:r,handler:o})}else i.warn("Can not resolve event source: "+t);return a},vM.finalize=function(){var t,e,n,r=this._tooltip,i=this._timers,a=this._eventListeners;for(t=i.length;--t>=0;)i[t].stop();for(t=a.length;--t>=0;)for(e=(n=a[t]).sources.length;--e>=0;)n.sources[e].removeEventListener(n.type,n.handler);return r&&r.call(this,this._handler,null,null,null),this},vM.hover=function(t,e){return t=[t||"hover"],e=[e||"update",t[0]],this.on(this.events("view","mouseover",HC),GC,$C(t)),this.on(this.events("view","mouseout",HC),GC,$C(e)),this},vM.data=function(t,e){return arguments.length<2?RC(this,t).values.value:FC.call(this,t,_t().remove(ct.Ga).insert(e))},vM.change=FC,vM.insert=function(t,e){return FC.call(this,t,_t().insert(e))},vM.remove=function(t,e){return FC.call(this,t,_t().remove(e))},vM.scale=function(t){var e=this._runtime.scales;return Object(ct.v)(e,t)||Object(ct.n)("Unrecognized scale or projection: "+t),e[t].value},vM.initialize=function(t,e){const n=this,r=n._renderType,i=n._eventConfig.bind,a=Eh(r);t=n._el=t?uA(n,t):null,function(t){const e=t.container();e&&(e.setAttribute("role","figure"),IC(e,t.description()))}(n),a||n.error("Unrecognized renderer type: "+r);const o=a.handler||Pd,s=t?a.renderer:a.headless;return n._renderer=s?oA(n,n._renderer,t,s):null,n._handler=function(t,e,n,r){var i=new r(t.loader(),sA(t,t.tooltip())).scene(t.scenegraph().root).initialize(n,LC(t),t);return e&&e.handlers().forEach(function(t){i.on(t.type,t.handler)}),i}(n,n._handler,t,o),n._redraw=!0,t&&"none"!==i&&(e=e?n._elBind=uA(n,e):t.appendChild(KC("div",{class:"vega-bindings"})),n._bind.forEach(function(t){t.param.element&&"container"!==i&&(t.element=uA(n,t.param.element))}),n._bind.forEach(function(t){QC(n,t.element||e,t)})),n},vM.toImageURL=async function(t,e){t!==kh.Canvas&&t!==kh.SVG&&t!==kh.PNG&&Object(ct.n)("Unrecognized image type: "+t);const n=await fA(this,t,e);return t===kh.SVG?function(t,e){var n=new Blob([t],{type:e});return window.URL.createObjectURL(n)}(n.svg(),"image/svg+xml"):n.canvas().toDataURL("image/png")},vM.toCanvas=async function(t,e){return(await fA(this,kh.Canvas,t,e)).canvas()},vM.toSVG=async function(t){return(await fA(this,kh.SVG,t)).svg()},vM.getState=function(t){return this._runtime.getState(t||{data:fM,signals:dM,recurse:!0})},vM.setState=function(t){return this.runAsync(null,e=>{e._trigger=!1,e._runtime.setState(t)},t=>{t._trigger=!0}),this};var kM=function(t){return Object(ct.F)(t)?t:{type:t||"pad"}};const _M=t=>+t||0;var EM=function(t){return Object(ct.F)(t)?t.signal?t:{top:_M(t.top),bottom:_M(t.bottom),left:_M(t.left),right:_M(t.right)}:(t=>({top:t,bottom:t,left:t,right:t}))(_M(t))},OM=["value","update","init","react","bind"];function SM(t,e){Object(ct.n)(t+' for "outer" push: '+Object(ct.Z)(e))}var CM=function(t,e){var n=t.name;if("outer"===t.push)e.signals[n]||SM("No prior signal definition",n),OM.forEach(function(e){void 0!==t[e]&&SM("Invalid property ",e)});else{var r=e.addSignal(n,t.value);!1===t.react&&(r.react=!1),t.bind&&e.addBinding(n,t.bind)}},AM=function(t,e,n){var r,i,a={};try{t=Object(ct.H)(t)?t:Object(ct.Z)(t)+"",r=tT(t)}catch(e){Object(ct.n)("Expression parse error: "+t)}return r.visit(function(t){if(t.type===_A){var n=t.callee.name,r=WD.visitors[n];r&&r(n,t.arguments,e,a)}}),(i=VD(r)).globals.forEach(function(t){var n="$"+t;!Object(ct.v)(a,n)&&e.getSignal(t)&&(a[n]=e.signalRef(t))}),{$expr:n?n+"return("+i.code+");":i.code,$fields:i.fields,$params:a}};function NM(t,e,n,r){this.id=-1,this.type=t,this.value=e,this.params=n,r&&(this.parent=r)}function TM(t,e,n,r){return new NM(t,e,n,r)}function IM(t,e){return TM("operator",t,e)}function DM(t){var e={$ref:t.id};return t.id<0&&(t.refs=t.refs||[]).push(e),e}function MM(t,e){return e?{$field:t,$name:e}:{$field:t}}var RM=MM("key");function FM(t,e){return{$compare:t,$order:e}}var jM="descending";function PM(t,e){return(t&&t.signal?"$"+t.signal:t||"")+(t&&e?"_":"")+(e&&e.signal?"$"+e.signal:e||"")}var LM="scope",zM="view";function BM(t){return t&&t.signal}function UM(t){if(BM(t))return!0;if(Object(ct.F)(t))for(var e in t)if(UM(t[e]))return!0;return!1}function WM(t,e){return null!=t?t:e}function VM(t){return t&&t.signal||t}var qM="timer";function HM(t,e){return(t.merge?GM:t.stream?$M:t.type?KM:Object(ct.n)("Invalid stream specification: "+Object(ct.Z)(t)))(t,e)}function GM(t,e){var n=XM({merge:t.merge.map(t=>HM(t,e))},t,e);return e.addStream(n).id}function $M(t,e){var n=XM({stream:HM(t.stream,e)},t,e);return e.addStream(n).id}function KM(t,e){var n,r;return t.type===qM?(n=e.event(qM,t.throttle),t={between:t.between,filter:t.filter}):n=e.event(function(t){return t===LM?zM:t||zM}(t.source),t.type),r=XM({stream:n},t,e),1===Object.keys(r).length?n:e.addStream(r).id}function XM(t,e,n){var r=e.between;return r&&(2!==r.length&&Object(ct.n)('Stream "between" parameter must have 2 entries: '+Object(ct.Z)(e)),t.between=[HM(r[0],n),HM(r[1],n)]),r=e.filter?[].concat(e.filter):[],(e.marktype||e.markname||e.markrole)&&r.push(function(t,e,n){var r="event.item";return r+(t&&"*"!==t?"&&"+r+".mark.marktype==='"+t+"'":"")+(n?"&&"+r+".mark.role==='"+n+"'":"")+(e?"&&"+r+".mark.name==='"+e+"'":"")}(e.marktype,e.markname,e.markrole)),e.source===LM&&r.push("inScope(event.item)"),r.length&&(t.filter=AM("("+r.join(")&&(")+")").$expr),null!=(r=e.throttle)&&(t.throttle=+r),null!=(r=e.debounce)&&(t.debounce=+r),e.consume&&(t.consume=!0),t}var YM,JM,ZM=function(t,e,n){return YM=e||QM,JM=n||cR,fR(t.trim()).map(dR)},QM="view",tR="[",eR="]",nR="{",rR="}",iR=":",aR=",",oR="@",sR=">",uR=/[[\]{}]/,cR={"*":1,arc:1,area:1,group:1,image:1,line:1,path:1,rect:1,rule:1,shape:1,symbol:1,text:1,trail:1};function lR(t,e,n,r,i){for(var a,o=0,s=t.length;e<s;++e){if(a=t[e],!o&&a===n)return e;i&&i.indexOf(a)>=0?--o:r&&r.indexOf(a)>=0&&++o}return e}function fR(t){for(var e=[],n=0,r=t.length,i=0;i<r;)i=lR(t,i,aR,tR+nR,eR+rR),e.push(t.substring(n,i).trim()),n=++i;if(0===e.length)throw"Empty event selector: "+t;return e}function dR(t){return"["===t[0]?function(t){var e,n,r=t.length,i=1;if((i=lR(t,i,eR,tR,eR))===r)throw"Empty between selector: "+t;if(2!==(e=fR(t.substring(1,i))).length)throw"Between selector must have two elements: "+t;if((t=t.slice(i+1).trim())[0]!==sR)throw"Expected '>' after between selector: "+t;if(e=e.map(dR),(n=dR(t.slice(1).trim())).between)return{between:e,stream:n};n.between=e;return n}(t):function(t){var e,n,r={source:YM},i=[],a=[0,0],o=0,s=0,u=t.length,c=0;if(t[u-1]===rR){if(!((c=t.lastIndexOf(nR))>=0))throw"Unmatched right brace: "+t;try{a=function(t){var e=t.split(aR);if(!t.length||e.length>2)throw t;return e.map(function(e){var n=+e;if(n!=n)throw t;return n})}(t.substring(c+1,u-1))}catch(e){throw"Invalid throttle specification: "+t}t=t.slice(0,c).trim(),u=t.length,c=0}if(!u)throw t;t[0]===oR&&(o=++c);(e=lR(t,c,iR))<u&&(i.push(t.substring(s,e).trim()),s=c=++e);if((c=lR(t,c,tR))===u)i.push(t.substring(s,u).trim());else if(i.push(t.substring(s,c).trim()),n=[],(s=++c)===u)throw"Unmatched left bracket: "+t;for(;c<u;){if((c=lR(t,c,eR))===u)throw"Unmatched left bracket: "+t;if(n.push(t.substring(s,c).trim()),c<u-1&&t[++c]!==tR)throw"Expected left bracket: "+t;s=++c}if(!(u=i.length)||uR.test(i[u-1]))throw"Invalid event selector: "+t;u>1?(r.type=i[1],o?r.markname=i[0].slice(1):!function(t){return JM[t]}(i[0])?r.source=i[0]:r.marktype=i[0]):r.type=i[0];"!"===r.type.slice(-1)&&(r.consume=!0,r.type=r.type.slice(0,-1));null!=n&&(r.filter=n);a[0]&&(r.throttle=a[0]);a[1]&&(r.debounce=a[1]);return r}(t)}var hR=function(t,e,n){var r=t.events,i=t.update,a=t.encode,o=[],s={target:n};r||Object(ct.n)("Signal update missing events specification."),Object(ct.H)(r)&&(r=ZM(r,e.isSubscope()?LM:zM)),r=Object(ct.i)(r).filter(t=>t.signal||t.scale?(o.push(t),0):1),o.length>1&&(o=[function(t){return{signal:"["+t.map(t=>t.scale?'scale("'+t.scale+'")':t.signal)+"]"}}(o)]),r.length&&o.push(r.length>1?{merge:r}:r[0]),null!=a&&(i&&Object(ct.n)("Signal encode and update are mutually exclusive."),i="encode(item(),"+Object(ct.Z)(a)+")"),s.update=Object(ct.H)(i)?AM(i,e,"var datum=event.item&&event.item.datum;"):null!=i.expr?AM(i.expr,e,"var datum=event.item&&event.item.datum;"):null!=i.value?i.value:null!=i.signal?{$expr:"_.value",$params:{value:e.signalRef(i.signal)}}:Object(ct.n)("Invalid signal update specification."),t.force&&(s.options={force:!0}),o.forEach(function(t){e.addUpdate(Object(ct.o)(function(t,e){return{source:t.signal?e.signalRef(t.signal):t.scale?e.scaleRef(t.scale):HM(t,e)}}(t,e),s))})};function pR(t){return function(e,n,r){return TM(t,n,e||void 0,r)}}var mR=pR("aggregate"),gR=pR("axisticks"),vR=pR("bound"),yR=pR("collect"),bR=pR("compare"),xR=pR("datajoin"),wR=pR("encode"),kR=pR("expression"),_R=(pR("extent"),pR("facet")),ER=pR("field"),OR=pR("key"),SR=pR("legendentries"),CR=pR("load"),AR=pR("mark"),NR=pR("multiextent"),TR=pR("multivalues"),IR=pR("overlap"),DR=pR("params"),MR=pR("prefacet"),RR=pR("projection"),FR=pR("proxy"),jR=pR("relay"),PR=pR("render"),LR=pR("scale"),zR=pR("sieve"),BR=pR("sortitems"),UR=pR("viewlayout"),WR=pR("values"),VR=function(t,e,n){var r=t-e+2*n;return t?r>0?r:1:0};const qR="log",HR="quantile",GR="continuous",$R="discrete",KR="discretizing",XR="interpolating",YR="temporal";var JR=function(t){return function(e){var n,r=e[0],i=e[1];return i<r&&(n=r,r=i,i=n),[t.invert(r),t.invert(i)]}},ZR=function(t){return function(e){var n,r,i,a,o=t.range(),s=e[0],u=e[1],c=-1;for(u<s&&(r=s,s=u,u=r),i=0,a=o.length;i<a;++i)o[i]>=s&&o[i]<=u&&(c<0&&(c=i),n=i);if(!(c<0))return s=t.invertExtent(o[c]),u=t.invertExtent(o[n]),[void 0===s[0]?s[1]:s[0],void 0===u[1]?u[0]:u[1]]}};function QR(){var t,e,n=Gp().unknown(void 0),r=n.domain,i=n.range,a=[0,1],o=!1,s=0,u=0,c=.5;function l(){var n=r().length,l=a[1]<a[0],f=a[l-0],d=a[1-l],h=VR(n,s,u);t=(d-f)/(h||1),o&&(t=Math.floor(t)),f+=(d-f-t*(n-s))*c,e=t*(1-s),o&&(f=Math.round(f),e=Math.round(e));var p=ro(n).map(function(e){return f+t*e});return i(l?p.reverse():p)}return delete n.unknown,n.domain=function(t){return arguments.length?(r(t),l()):r()},n.range=function(t){return arguments.length?(a=[+t[0],+t[1]],l()):a.slice()},n.rangeRound=function(t){return a=[+t[0],+t[1]],o=!0,l()},n.bandwidth=function(){return e},n.step=function(){return t},n.round=function(t){return arguments.length?(o=!!t,l()):o},n.padding=function(t){return arguments.length?(u=Math.max(0,Math.min(1,t)),s=u,l()):s},n.paddingInner=function(t){return arguments.length?(s=Math.max(0,Math.min(1,t)),l()):s},n.paddingOuter=function(t){return arguments.length?(u=Math.max(0,Math.min(1,t)),l()):u},n.align=function(t){return arguments.length?(c=Math.max(0,Math.min(1,t)),l()):c},n.invertRange=function(t){if(null!=t[0]&&null!=t[1]){var n,o,s,u=+t[0],c=+t[1],l=a[1]<a[0],f=l?i().reverse():i(),d=f.length-1;if(u==u&&c==c&&(c<u&&(s=u,u=c,c=s),!(c<f[0]||u>a[1-l])))return n=Math.max(0,Bp(f,u)-1),o=u===c?n:Bp(f,c)-1,u-f[n]>e+1e-10&&++n,l&&(s=n,n=d-o,o=d-s),n>o?void 0:r().slice(n,o+1)}},n.invert=function(t){var e=n.invertRange([t,t]);return e?e[0]:e},n.copy=function(){return QR().domain(r()).range(a).round(o).paddingInner(s).paddingOuter(u).align(c)},l()}var tF=Array.prototype.map;var eF=Array.prototype.slice;const nF={};function rF(t,e,n){return arguments.length>1?(nF[t]=function(t,e,n){const r=function(){var n=e();return n.invertRange||(n.invertRange=n.invert?JR(n):n.invertExtent?ZR(n):void 0),n.type=t,n};return r.metadata=Object(ct.Da)(Object(ct.i)(n)),r}(t,e,n),this):iF(t)?nF[t]:void 0}function iF(t){return Object(ct.v)(nF,t)}function aF(t,e){const n=nF[t];return n&&n.metadata[e]}function oF(t){return aF(t,$R)}function sF(t){return aF(t,KR)}function uF(t){return aF(t,HR)}rF("identity",iv),rF("linear",fg,GR),rF(qR,xg,[GR,qR]),rF("pow",Ng,GR),rF("sqrt",Tg,GR),rF("symlog",Eg,GR),rF("time",ev,[GR,YR]),rF("utc",nv,[GR,YR]),rF("sequential",Mg,[GR,XR]),rF("sequential-linear",Mg,[GR,XR]),rF(`sequential-${qR}`,Rg,[GR,XR,qR]),rF("sequential-pow",jg,[GR,XR]),rF("sequential-sqrt",Pg,[GR,XR]),rF("sequential-symlog",Fg,[GR,XR]),rF("diverging-linear",zg,[GR,XR]),rF(`diverging-${qR}`,Bg,[GR,XR,qR]),rF("diverging-pow",Wg,[GR,XR]),rF("diverging-sqrt",Vg,[GR,XR]),rF("diverging-symlog",Ug,[GR,XR]),rF(HR,qg,[KR,HR]),rF("quantize",rv,KR),rF("threshold",Zp,KR),rF("bin-ordinal",function t(){var e=[],n=[];function r(t){return null==t||t!=t?void 0:n[(Wp(e,t)-1)%n.length]}return r.domain=function(t){return arguments.length?(e=function(t){return tF.call(t,function(t){return+t})}(t),r):e.slice()},r.range=function(t){return arguments.length?(n=eF.call(t),r):n.slice()},r.tickFormat=function(t,n){return Xp(e[0],Object(ct.U)(e),null==t?10:t,n)},r.copy=function(){return t().domain(r.domain()).range(r.range())},r},[$R,KR]),rF("ordinal",Gp,$R),rF("band",QR,$R),rF("point",function(){return function t(e){var n=e.copy;return e.padding=e.paddingOuter,delete e.paddingInner,e.copy=function(){return t(n())},e}(QR().paddingInner(1))},$R);function cF(t,e,n){return Qm(function(t,e){var n=a[function(t){return"interpolate"+t.toLowerCase().split("-").map(function(t){return t[0].toUpperCase()+t.slice(1)}).join("")}(t)];return null!=e&&n&&n.gamma?n.gamma(e):n}(e||"rgb",n),t)}function lF(t){for(var e=t.length/6|0,n=new Array(e),r=0;r<e;)n[r]="#"+t.slice(6*r,6*++r);return n}function fF(t,e){for(let n in t)hF(n,e(t[n]))}const dF={};function hF(t,e){return t=t&&t.toLowerCase(),arguments.length>1?(dF[t]=e,this):dF[t]}fF({category10:"1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf",category20:"1f77b4aec7e8ff7f0effbb782ca02c98df8ad62728ff98969467bdc5b0d58c564bc49c94e377c2f7b6d27f7f7fc7c7c7bcbd22dbdb8d17becf9edae5",category20b:"393b795254a36b6ecf9c9ede6379398ca252b5cf6bcedb9c8c6d31bd9e39e7ba52e7cb94843c39ad494ad6616be7969c7b4173a55194ce6dbdde9ed6",category20c:"3182bd6baed69ecae1c6dbefe6550dfd8d3cfdae6bfdd0a231a35474c476a1d99bc7e9c0756bb19e9ac8bcbddcdadaeb636363969696bdbdbdd9d9d9",tableau10:"4c78a8f58518e4575672b7b254a24beeca3bb279a2ff9da69d755dbab0ac",tableau20:"4c78a89ecae9f58518ffbf7954a24b88d27ab79a20f2cf5b43989483bcb6e45756ff9d9879706ebab0acd67195fcbfd2b279a2d6a5c99e765fd8b5a5",accent:"7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666",dark2:"1b9e77d95f027570b3e7298a66a61ee6ab02a6761d666666",paired:"a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928",pastel1:"fbb4aeb3cde3ccebc5decbe4fed9a6ffffcce5d8bdfddaecf2f2f2",pastel2:"b3e2cdfdcdaccbd5e8f4cae4e6f5c9fff2aef1e2cccccccc",set1:"e41a1c377eb84daf4a984ea3ff7f00ffff33a65628f781bf999999",set2:"66c2a5fc8d628da0cbe78ac3a6d854ffd92fe5c494b3b3b3",set3:"8dd3c7ffffb3bebadafb807280b1d3fdb462b3de69fccde5d9d9d9bc80bdccebc5ffed6f"},lF),fF({blues:"cfe1f2bed8eca8cee58fc1de74b2d75ba3cf4592c63181bd206fb2125ca40a4a90",greens:"d3eecdc0e6baabdda594d3917bc77d60ba6c46ab5e329a512089430e7735036429",greys:"e2e2e2d4d4d4c4c4c4b1b1b19d9d9d8888887575756262624d4d4d3535351e1e1e",oranges:"fdd8b3fdc998fdb87bfda55efc9244f87f2cf06b18e4580bd14904b93d029f3303",purples:"e2e1efd4d4e8c4c5e0b4b3d6a3a0cc928ec3827cb97566ae684ea25c3696501f8c",reds:"fdc9b4fcb49afc9e80fc8767fa7051f6573fec3f2fdc2a25c81b1db21218970b13",blueGreen:"d5efedc1e8e0a7ddd18bd2be70c6a958ba9144ad77319c5d2089460e7736036429",bluePurple:"ccddecbad0e4a8c2dd9ab0d4919cc98d85be8b6db28a55a6873c99822287730f71",greenBlue:"d3eecec5e8c3b1e1bb9bd8bb82cec269c2ca51b2cd3c9fc7288abd1675b10b60a1",orangeRed:"fddcaffdcf9bfdc18afdad77fb9562f67d53ee6545e24932d32d1ebf130da70403",purpleBlue:"dbdaebc8cee4b1c3de97b7d87bacd15b9fc93a90c01e7fb70b70ab056199045281",purpleBlueGreen:"dbd8eac8cee4b0c3de93b7d872acd1549fc83892bb1c88a3097f8702736b016353",purpleRed:"dcc9e2d3b3d7ce9eccd186c0da6bb2e14da0e23189d91e6fc61159ab07498f023a",redPurple:"fccfccfcbec0faa9b8f98faff571a5ec539ddb3695c41b8aa908808d0179700174",yellowGreen:"e4f4acd1eca0b9e2949ed68880c97c62bb6e47aa5e3297502083440e723b036034",yellowOrangeBrown:"feeaa1fedd84fecc63feb746fca031f68921eb7215db5e0bc54c05ab3d038f3204",yellowOrangeRed:"fee087fed16ffebd59fea849fd903efc7335f9522bee3423de1b20ca0b22af0225",blueOrange:"134b852f78b35da2cb9dcae1d2e5eff2f0ebfce0bafbbf74e8932fc5690d994a07",brownBlueGreen:"704108a0651ac79548e3c78af3e6c6eef1eac9e9e48ed1c74da79e187a72025147",purpleGreen:"5b1667834792a67fb6c9aed3e6d6e8eff0efd9efd5aedda971bb75368e490e5e29",purpleOrange:"4114696647968f83b7b9b4d6dadbebf3eeeafce0bafbbf74e8932fc5690d994a07",redBlue:"8c0d25bf363adf745ef4ae91fbdbc9f2efeed2e5ef9dcae15da2cb2f78b3134b85",redGrey:"8c0d25bf363adf745ef4ae91fcdccbfaf4f1e2e2e2c0c0c0969696646464343434",yellowGreenBlue:"eff9bddbf1b4bde5b594d5b969c5be45b4c22c9ec02182b82163aa23479c1c3185",redYellowBlue:"a50026d4322cf16e43fcac64fedd90faf8c1dcf1ecabd6e875abd04a74b4313695",redYellowGreen:"a50026d4322cf16e43fcac63fedd8df9f7aed7ee8ea4d86e64bc6122964f006837",pinkYellowGreen:"8e0152c0267edd72adf0b3d6faddedf5f3efe1f2cab6de8780bb474f9125276419",spectral:"9e0142d13c4bf0704afcac63fedd8dfbf8b0e0f3a1a9dda269bda94288b55e4fa2",viridis:"440154470e61481a6c482575472f7d443a834144873d4e8a39568c35608d31688e2d708e2a788e27818e23888e21918d1f988b1fa08822a8842ab07f35b77943bf7154c56866cc5d7ad1518fd744a5db36bcdf27d2e21be9e51afde725",magma:"0000040404130b0924150e3720114b2c11603b0f704a107957157e651a80721f817f24828c29819a2e80a8327db6377ac43c75d1426fde4968e95462f1605df76f5cfa7f5efc8f65fe9f6dfeaf78febf84fece91fddea0fcedaffcfdbf",inferno:"0000040403130c0826170c3b240c4f330a5f420a68500d6c5d126e6b176e781c6d86216b932667a12b62ae305cbb3755c73e4cd24644dd513ae65c30ed6925f3771af8850ffb9506fca50afcb519fac62df6d645f2e661f3f484fcffa4",plasma:"0d088723069033059742039d5002a25d01a66a00a87801a88405a7900da49c179ea72198b12a90ba3488c33d80cb4779d35171da5a69e16462e76e5bed7953f2834cf68f44fa9a3dfca636fdb32ffec029fcce25f9dc24f5ea27f0f921",rainbow:"6e40aa883eb1a43db3bf3cafd83fa4ee4395fe4b83ff576eff6659ff7847ff8c38f3a130e2b72fcfcc36bee044aff05b8ff4576ff65b52f6673af27828ea8d1ddfa319d0b81cbecb23abd82f96e03d82e14c6edb5a5dd0664dbf6e40aa",sinebow:"ff4040fc582af47218e78d0bd5a703bfbf00a7d5038de70b72f41858fc2a40ff402afc5818f4720be78d03d5a700bfbf03a7d50b8de71872f42a58fc4040ff582afc7218f48d0be7a703d5bf00bfd503a7e70b8df41872fc2a58ff4040",browns:"eedbbdecca96e9b97ae4a865dc9856d18954c7784cc0673fb85536ad44339f3632",tealBlues:"bce4d89dd3d181c3cb65b3c245a2b9368fae347da0306a932c5985",teals:"bbdfdfa2d4d58ac9c975bcbb61b0af4da5a43799982b8b8c1e7f7f127273006667",warmGreys:"dcd4d0cec5c1c0b8b4b3aaa7a59c9998908c8b827f7e7673726866665c5a59504e",goldGreen:"f4d166d5ca60b6c35c98bb597cb25760a6564b9c533f8f4f33834a257740146c36",goldOrange:"f4d166f8be5cf8aa4cf5983bf3852aef701be2621fd65322c54923b142239e3a26",goldRed:"f4d166f6be59f9aa51fc964ef6834bee734ae56249db5247cf4244c43141b71d3e",lightGreyRed:"efe9e6e1dad7d5cbc8c8bdb9bbaea9cd967ddc7b43e15f19df4011dc000b",lightGreyTeal:"e4eaead6dcddc8ced2b7c2c7a6b4bc64b0bf22a6c32295c11f85be1876bc",lightMulti:"e0f1f2c4e9d0b0de9fd0e181f6e072f6c053f3993ef77440ef4a3c",lightOrange:"f2e7daf7d5baf9c499fab184fa9c73f68967ef7860e8645bde515bd43d5b",lightTealBlue:"e3e9e0c0dccf9aceca7abfc859afc0389fb9328dad2f7ca0276b95255988",darkBlue:"3232322d46681a5c930074af008cbf05a7ce25c0dd38daed50f3faffffff",darkGold:"3c3c3c584b37725e348c7631ae8b2bcfa424ecc31ef9de30fff184ffffff",darkGreen:"3a3a3a215748006f4d048942489e4276b340a6c63dd2d836ffeb2cffffaa",darkMulti:"3737371f5287197d8c29a86995ce3fffe800ffffff",darkRed:"3434347036339e3c38cc4037e75d1eec8620eeab29f0ce32ffeb2c"},t=>cF(lF(t)));var pF=0,mF={min:"min",max:"max",count:"sum"};function gF(t,e){var n,r=e.getScale(t.name).params;for(n in r.domain=xF(t.domain,t,e),null!=t.range&&(r.range=function t(e,n,r){var i=e.range,a=n.config.range;if(i.signal)return n.signalRef(i.signal);if(Object(ct.H)(i)){if(a&&Object(ct.v)(a,i))return e=Object(ct.o)({},e,{range:a[i]}),t(e,n,r);"width"===i?i=[0,{signal:"width"}]:"height"===i?i=oF(e.type)?[0,{signal:"height"}]:[{signal:"height"},0]:Object(ct.n)("Unrecognized scale range value: "+Object(ct.Z)(i))}else{if(i.scheme)return r.scheme=Object(ct.A)(i.scheme)?yF(i.scheme,n):vF(i.scheme,n),i.extent&&(r.schemeExtent=yF(i.extent,n)),void(i.count&&(r.schemeCount=vF(i.count,n)));if(i.step)return void(r.rangeStep=vF(i.step,n));if(oF(e.type)&&!Object(ct.A)(i))return xF(i,e,n);Object(ct.A)(i)||Object(ct.n)("Unsupported range type: "+Object(ct.Z)(i))}return i.map(t=>(Object(ct.A)(t)?yF:vF)(t,n))}(t,e,r)),null!=t.interpolate&&function(t,e){e.interpolate=vF(t.type||t),null!=t.gamma&&(e.interpolateGamma=vF(t.gamma))}(t.interpolate,r),null!=t.nice&&(r.nice=function(t){return Object(ct.F)(t)?{interval:vF(t.interval),step:vF(t.step)}:vF(t)}(t.nice)),null!=t.bins&&(r.bins=function(t,e){return t.signal||Object(ct.A)(t)?yF(t,e):e.objectProperty(t)}(t.bins,e)),t)Object(ct.v)(r,n)||"name"===n||(r[n]=vF(t[n],e))}function vF(t,e){return Object(ct.F)(t)?t.signal?e.signalRef(t.signal):Object(ct.n)("Unsupported object: "+Object(ct.Z)(t)):t}function yF(t,e){return t.signal?e.signalRef(t.signal):t.map(t=>vF(t,e))}function bF(t){Object(ct.n)("Can not find data set: "+Object(ct.Z)(t))}function xF(t,e,n){if(t)return t.signal?n.signalRef(t.signal):(Object(ct.A)(t)?function(t,e,n){return t.map(function(t){return vF(t,n)})}:t.fields?function(t,e,n){var r=t.data,i=t.fields.reduce(function(t,e){return e=Object(ct.H)(e)?{data:r,field:e}:Object(ct.A)(e)||e.signal?function(t,e){var n="_:vega:_"+pF++,r=yR({});if(Object(ct.A)(t))r.value={$ingest:t};else if(t.signal){var i="setdata("+Object(ct.Z)(n)+","+t.signal+")";r.params.input=e.signalRef(i)}return e.addDataPipeline(n,[r,zR({})]),{data:n,field:"data"}}(e,n):e,t.push(e),t},[]);return(oF(e.type)?function(t,e,n){var r,i,a,o,s,u=wF(t.sort,!0);r=n.map(function(t){var n=e.getData(t.data);return n||bF(t.data),n.countsRef(e,t.field,u)}),i={groupby:RM,pulse:r},u&&(a=u.op||"count",s=u.field?PM(a,u.field):"count",i.ops=[mF[a]],i.fields=[e.fieldRef(s)],i.as=[s]);return a=e.add(mR(i)),o=e.add(yR({pulse:DM(a)})),DM(s=e.add(WR({field:RM,sort:e.sortRef(u),pulse:DM(o)})))}:uF(e.type)?function(t,e,n){var r=n.map(function(t){var n=e.getData(t.data);return n||bF(t.data),n.domainRef(e,t.field)});return DM(e.add(TR({values:r})))}:function(t,e,n){var r=n.map(function(t){var n=e.getData(t.data);return n||bF(t.data),n.extentRef(e,t.field)});return DM(e.add(NR({extents:r})))})(t,n,i)}:function(t,e,n){var r=n.getData(t.data);r||bF(t.data);return oF(e.type)?r.valuesRef(n,t.field,wF(t.sort,!1)):uF(e.type)?r.domainRef(n,t.field):r.extentRef(n,t.field)})(t,e,n);null==e.domainMin&&null==e.domainMax||Object(ct.n)("No scale domain defined for domainMin/domainMax to override.")}function wF(t,e){return t&&(t.field||t.op?t.field||"count"===t.op?e&&t.field&&t.op&&!mF[t.op]&&Object(ct.n)("Multiple domain scales can not be sorted using "+t.op):Object(ct.n)("No field provided for sort aggregate op: "+t.op):Object(ct.F)(t)?t.field="key":t={field:"key"}),t}function kF(t,e,n){return Object(ct.A)(t)?t.map(function(t){return kF(t,e,n)}):Object(ct.F)(t)?t.signal?n.signalRef(t.signal):"fit"===e?t:Object(ct.n)("Unsupported parameter object: "+Object(ct.Z)(t)):t}const _F="vertical",EF="start",OF="end",SF="value",CF="guide-label",AF="group-title",NF="group-subtitle",TF="symbol",IF="gradient",DF="discrete",MF=["size","shape","fill","stroke","strokeWidth","strokeDash","opacity"],RF={name:1,style:1,interactive:1},FF={value:0},jF={value:1};var PF=Object(ct.Da)(["rule"]),LF=Object(ct.Da)(["group","image","rect"]),zF=function(t,e){var n="";return PF[e]?n:(t.x2&&(t.x?(LF[e]&&(n+="if(o.x>o.x2)$=o.x,o.x=o.x2,o.x2=$;"),n+="o.width=o.x2-o.x;"):n+="o.x=o.x2-(o.width||0);"),t.xc&&(n+="o.x=o.xc-(o.width||0)/2;"),t.y2&&(t.y?(LF[e]&&(n+="if(o.y>o.y2)$=o.y,o.y=o.y2,o.y2=$;"),n+="o.height=o.y2-o.y;"):n+="o.y=o.y2-(o.height||0);"),t.yc&&(n+="o.y=o.yc-(o.height||0)/2;"),n)},BF=function(t,e,n,r){var i=AM(t,e);return i.$fields.forEach(function(t){r[t]=1}),Object(ct.o)(n,i.$params),i.$expr},UF=function(t,e,n,r){return function t(e,n,r,i){var a,o,s;if(e.signal)a="datum",s=BF(e.signal,n,r,i);else if(e.group||e.parent){for(o=Math.max(1,e.level||1),a="item";o-- >0;)a+=".mark.group";e.parent?(s=e.parent,a+=".datum"):s=e.group}else e.datum?(a="datum",s=e.datum):Object(ct.n)("Invalid field reference: "+Object(ct.Z)(e));e.signal||(Object(ct.H)(s)?(i[s]=1,s=Object(ct.Y)(s).map(ct.Z).join("][")):s=t(s,n,r,i));return a+"["+s+"]"}(Object(ct.F)(t)?t:{datum:t},e,n,r)};var WF=function(t,e,n,r){return Object(ct.F)(t)?"("+HF(null,t,e,n,r)+")":t},VF=function(t,e,n,r,i){var a,o,s,u=qF(t.scale,n,r,i);return null!=t.range?(o=u+".range()",e=0===(a=+t.range)?o+"[0]":"($="+o+","+(1===a?"$[$.length-1]":"$[0]+"+a+"*($[$.length-1]-$[0])")+")"):(void 0!==e&&(e=u+"("+e+")"),t.band&&(s=function(t,e){if(!Object(ct.H)(t))return-1;var n=e.scaleType(t);return"band"===n||"point"===n?1:0}(t.scale,n))&&(o=u+".bandwidth",a=t.band.signal?o+"()*"+WF(t.band,n,r,i):o+"()"+(1===(a=+t.band)?"":"*"+a),s<0&&(a="("+o+"?"+a+":0)"),e=(e?e+"+":"")+a,t.extra&&(e="(datum.extra?"+u+"(datum.extra.value):"+e+")")),null==e&&(e="0")),e};function qF(t,e,n,r){var i;if(Object(ct.H)(t))i=DD+t,Object(ct.v)(n,i)||(n[i]=e.scaleRef(t)),i=Object(ct.Z)(i);else{for(i in e.scales)n[DD+i]=e.scaleRef(i);i=Object(ct.Z)(DD)+"+"+(t.signal?"("+BF(t.signal,e,n,r)+")":UF(t,e,n,r))}return"_["+i+"]"}var HF=function(t,e,n,r,i){if(null!=e.gradient)return function(t,e,n,r){return"this.gradient("+qF(t.gradient,e,n,r)+","+Object(ct.Z)(t.start)+","+Object(ct.Z)(t.stop)+","+Object(ct.Z)(t.count)+")"}(e,n,r,i);var a=e.signal?BF(e.signal,n,r,i):e.color?function(t,e,n,r){function i(t,i,a,o){return"this."+t+"("+[HF(null,i,e,n,r),HF(null,a,e,n,r),HF(null,o,e,n,r)].join(",")+").toString()"}return t.c?i("hcl",t.h,t.c,t.l):t.h||t.s?i("hsl",t.h,t.s,t.l):t.l||t.a?i("lab",t.l,t.a,t.b):t.r||t.g||t.b?i("rgb",t.r,t.g,t.b):null}(e.color,n,r,i):null!=e.field?UF(e.field,n,r,i):void 0!==e.value?Object(ct.Z)(e.value):void 0;return null!=e.scale&&(a=VF(e,a,n,r,i)),void 0===a&&(a=null),null!=e.exponent&&(a="Math.pow("+a+","+WF(e.exponent,n,r,i)+")"),null!=e.mult&&(a+="*"+WF(e.mult,n,r,i)),null!=e.offset&&(a+="+"+WF(e.offset,n,r,i)),e.round&&(a="Math.round("+a+")"),a},GF=function(t,e,n){const r=t+"["+Object(ct.Z)(e)+"]";return`$=${n};if(${r}!==$)${r}=$,m=1;`},$F=function(t,e,n,r,i){var a="";return e.forEach(function(e){var o=HF(t,e,n,r,i);a+=e.test?BF(e.test,n,r,i)+"?"+o+":":o}),":"===Object(ct.U)(a)&&(a+="null"),GF("o",t,a)};function KF(t,e,n,r){var i,a,o,s={},u="var o=item,datum=o.datum,m=0,$;";for(i in t)a=t[i],Object(ct.A)(a)?u+=$F(i,a,r,n,s):(o=HF(i,a,r,n,s),u+=GF("o",i,o));return u+=zF(t,e),{$expr:u+="return m;",$fields:Object.keys(s),$output:Object.keys(t)}}var XF="mark",YF="frame",JF="title-text",ZF="title-subtitle";function QF(t){return Object(ct.F)(t)&&!Object(ct.A)(t)?Object(ct.o)({},t):{value:t}}function tj(t,e,n,r){return null!=n?(Object(ct.F)(n)&&!Object(ct.A)(n)?t.update[e]=n:t[r||"enter"][e]={value:n},1):0}function ej(t,e,n){for(let n in e)tj(t,n,e[n]);for(let e in n)tj(t,e,n[e],"update")}function nj(t,e,n){for(var r in e)n&&Object(ct.v)(n,r)||(t[r]=Object(ct.o)(t[r]||{},e[r]));return t}function rj(t,e,n,r,i,a){var o,s;for(s in(a=a||{}).encoders={$encode:o={}},t=function(t,e,n,r,i){var a,o,s,u={},c={};o="lineBreak","text"!==e||null==i[o]||aj(o,t)||ij(u,o,i[o]);("legend"==n||String(n).startsWith("axis"))&&(n=null);for(o in s=n===YF?i.group:n===XF?Object(ct.o)({},i.mark,i[e]):null)aj(o,t)||("fill"===o||"stroke"===o)&&(aj("fill",t)||aj("stroke",t))||ij(u,o,s[o]);for(o in Object(ct.i)(r).forEach(function(e){var n=i.style&&i.style[e];for(var r in n)aj(r,t)||ij(u,r,n[r])}),t=Object(ct.o)({},t),u)(s=u[o]).signal?(a=a||{})[o]=s:c[o]=s;t.enter=Object(ct.o)(c,t.enter),a&&(t.update=Object(ct.o)(a,t.update));return t}(t,e,n,r,i.config))o[s]=KF(t[s],e,a,i);return a}function ij(t,e,n){t[e]=n&&n.signal?{signal:n.signal}:{value:n}}function aj(t,e){return e&&(e.enter&&e.enter[t]||e.update&&e.update[t])}var oj=function(t,e,n,r,i,a,o){return{type:t,name:o?o.name:void 0,role:e,style:o&&o.style||n,key:r,from:i,interactive:!(!o||!o.interactive),encode:nj(a,o,RF)}};function sj(t,e){const n=(n,r)=>WM(t[n],WM(e[n],r));return n.isVertical=(n=>_F===WM(t.direction,e.direction||(n?e.symbolDirection:e.gradientDirection))),n.gradientLength=(()=>WM(t.gradientLength,e.gradientLength||e.gradientWidth)),n.gradientThickness=(()=>WM(t.gradientThickness,e.gradientThickness||e.gradientHeight)),n.entryColumns=(()=>WM(t.columns,WM(e.columns,+n.isVertical(!0)))),n}function uj(t,e){var n=e&&(e.update&&e.update[t]||e.enter&&e.enter[t]);return n&&n.signal?n:n?n.value:null}function cj(t,e,n){return`item.anchor === "${EF}" ? ${t} : item.anchor === "${OF}" ? ${e} : ${n}`}const lj=cj(Object(ct.Z)("left"),Object(ct.Z)("right"),Object(ct.Z)("center"));var fj="group",dj="text";var hj=function(t,e,n,r){var i,a,o,s,u,c=sj(t,e),l=c.isVertical(),f=QF(c.gradientThickness()),d=c.gradientLength(),h=c("labelOverlap"),p=c("labelSeparation"),m="";return ej(i={enter:a={opacity:FF},update:o={opacity:jF,text:{field:"label"}},exit:{opacity:FF}},{fill:c("labelColor"),fillOpacity:c("labelOpacity"),font:c("labelFont"),fontSize:c("labelFontSize"),fontStyle:c("labelFontStyle"),fontWeight:c("labelFontWeight"),limit:WM(t.labelLimit,e.gradientLabelLimit)}),l?(a.align={value:"left"},a.baseline=o.baseline={signal:'datum.perc<=0?"bottom":datum.perc>=1?"top":"middle"'},s="y",u="x",m="1-"):(a.align=o.align={signal:'datum.perc<=0?"left":datum.perc>=1?"right":"center"'},a.baseline={value:"top"},s="x",u="y"),a[s]=o[s]={signal:m+"datum.perc",mult:d},a[u]=o[u]=f,f.offset=WM(t.labelOffset,e.gradientLabelOffset)||0,t=oj(dj,"legend-label",CF,SF,r,i,n),h&&(t.overlap={separation:p,method:h,order:"datum.index"}),t},pj=function(t,e,n,r,i,a,o,s){return{type:fj,name:n,role:t,style:e,from:r,interactive:i||!1,encode:a,marks:o,layout:s}};const mj='(item.orient === "left" || item.orient === "right")',gj=`datum.vgrad && ${mj}`,vj=cj('"top"','"bottom"','"middle"'),yj=`datum.vgrad && item.orient === "right" ? (${cj('"right"','"left"','"center"')}) : (${mj} && !(datum.vgrad && item.orient === "left")) ? "left" : ${lj}`,bj=`item._anchor || (${mj} ? "middle" : "start")`,xj=`${gj} ? (item.orient === "left" ? -90 : 90) : 0`,wj=`${mj} ? (datum.vgrad ? (item.orient === "right" ? "bottom" : "top") : ${vj}) : "top"`;function kj(t){return Object(ct.F)(t)&&t.signal?t.signal:Object(ct.Z)(t)}var _j=function(t){var e=t.role||"";return e.indexOf("axis")&&e.indexOf("legend")&&e.indexOf("title")?t.type===fj?"scope":e||XF:e},Ej=function(t,e){var n=Vr(t.type);n||Object(ct.n)("Unrecognized transform type: "+Object(ct.Z)(t.type));var r=TM(n.type.toLowerCase(),null,Oj(n,t,e));return t.signal&&e.addSignal(t.signal,e.proxy(r)),r.metadata=n.metadata||{},r};function Oj(t,e,n){var r,i,a,o={};for(i=0,a=t.params.length;i<a;++i)o[(r=t.params[i]).name]=Sj(r,e,n);return o}function Sj(t,e,n){var r=t.type,i=e[t.name];return"index"===r?function(t,e,n){Object(ct.H)(e.from)||Object(ct.n)('Lookup "from" parameter must be a string literal.');return n.getData(e.from).lookupRef(n,e.key)}(0,e,n):void 0!==i?"param"===r?function(t,e,n){var r=e[t.name];return t.array?(Object(ct.A)(r)||Object(ct.n)("Expected an array of sub-parameters. Instead: "+Object(ct.Z)(r)),r.map(function(e){return Aj(t,e,n)})):Aj(t,r,n)}(t,e,n):"projection"===r?n.projectionRef(e[t.name]):t.array&&!BM(i)?i.map(function(e){return Cj(t,e,n)}):Cj(t,i,n):void(t.required&&Object(ct.n)("Missing required "+Object(ct.Z)(e.type)+" parameter: "+Object(ct.Z)(t.name)))}function Cj(t,e,n){var r=t.type;if(BM(e))return Nj(r)?Object(ct.n)("Expression references can not be signals."):Tj(r)?n.fieldRef(e):Ij(r)?n.compareRef(e):n.signalRef(e.signal);var i=t.expr||Tj(r);return i&&function(t){return t&&t.expr}(e)?n.exprRef(e.expr,e.as):i&&function(t){return t&&t.field}(e)?MM(e.field,e.as):Nj(r)?AM(e,n):function(t){return"data"===t}(r)?DM(n.getData(e).values):Tj(r)?MM(e):Ij(r)?n.compareRef(e):e}function Aj(t,e,n){var r,i,a,o,s;for(o=0,s=t.params.length;o<s;++o){for(a in(i=t.params[o]).key)if(i.key[a]!==e[a]){i=null;break}if(i)break}return i||Object(ct.n)("Unsupported parameter: "+Object(ct.Z)(e)),r=Object(ct.o)(Oj(i,e,n),i.key),DM(n.add(DR(r)))}function Nj(t){return"expr"===t}function Tj(t){return"field"===t}function Ij(t){return"compare"===t}function Dj(t,e){return t.$ref?t:t.data&&t.data.$ref?t.data:DM(e.getData(t.data).output)}function Mj(t,e,n,r,i){this.scope=t,this.input=e,this.output=n,this.values=r,this.aggregate=i,this.index={}}Mj.fromEntries=function(t,e){var n=e.length,r=1,i=e[0],a=e[n-1],o=e[n-2],s=null;for(i&&"load"===i.type&&(i=e[1]),t.add(e[0]);r<n;++r)e[r].params.pulse=DM(e[r-1]),t.add(e[r]),"aggregate"===e[r].type&&(s=e[r]);return new Mj(t,i,o,a,s)};var Rj=Mj.prototype;function Fj(t){return Object(ct.H)(t)?t:null}function jj(t,e,n){var r,i=PM(n.op,n.field);if(e.ops){for(var a=0,o=e.as.length;a<o;++a)if(e.as[a]===i)return}else e.ops=["count"],e.fields=[null],e.as=["count"];n.op&&(e.ops.push((r=n.op.signal)?t.signalRef(r):n.op),e.fields.push(t.fieldRef(n.field)),e.as.push(i))}function Pj(t,e,n,r,i,a,o){var s,u,c=e[n]||(e[n]={}),l=function(t){return Object(ct.F)(t)?(t.order===jM?"-":"+")+PM(t.op,t.field):""}(a),f=Fj(i);if(null!=f&&(t=e.scope,s=c[f+=l?"|"+l:""]),!s){var d=a?{field:RM,pulse:e.countsRef(t,i,a)}:{field:t.fieldRef(i),pulse:DM(e.output)};l&&(d.sort=t.sortRef(a)),u=t.add(TM(r,void 0,d)),o&&(e.index[i]=u),s=DM(u),null!=f&&(c[f]=s)}return s}Rj.countsRef=function(t,e,n){var r,i,a,o=this.counts||(this.counts={}),s=Fj(e);return null!=s&&(t=this.scope,r=o[s]),r?n&&n.field&&jj(t,r.agg.params,n):(a={groupby:t.fieldRef(e,"key"),pulse:DM(this.output)},n&&n.field&&jj(t,a,n),r={agg:i=t.add(mR(a)),ref:DM(r=t.add(yR({pulse:DM(i)})))},null!=s&&(o[s]=r)),r.ref},Rj.tuplesRef=function(){return DM(this.values)},Rj.extentRef=function(t,e){return Pj(t,this,"extent","extent",e,!1)},Rj.domainRef=function(t,e){return Pj(t,this,"domain","values",e,!1)},Rj.valuesRef=function(t,e,n){return Pj(t,this,"vals","values",e,n||!0)},Rj.lookupRef=function(t,e){return Pj(t,this,"lookup","tupleindex",e,!1)},Rj.indataRef=function(t,e){return Pj(t,this,"indata","tupleindex",e,!0,!0)};var Lj=function(t,e,n){var r,i,a=t.remove,o=t.insert,s=t.toggle,u=t.modify,c=t.values,l=e.add(IM());r="if("+t.trigger+',modify("'+n+'",'+[o,a,s,u,c].map(function(t){return null==t?"null":t}).join(",")+"),0)",i=AM(r,e),l.update=i.$expr,l.params=i.$params},zj=function(t,e){var n,r,i,a,o,s,u,c,l,f,d,h,p,m,g=_j(t),v=t.type===fj,y=t.from&&t.from.facet,b=t.layout||"scope"===g||g===YF,x=g===XF||b||y,w=t.overlap;i=function(t,e,n){var r,i,a,o,s;return t?(r=t.facet)&&(e||Object(ct.n)("Only group marks can be faceted."),null!=r.field?o=s=Dj(r,n):(t.data?s=DM(n.getData(t.data).aggregate):((a=Ej(Object(ct.o)({type:"aggregate",groupby:Object(ct.i)(r.groupby)},r.aggregate),n)).params.key=n.keyRef(r.groupby),a.params.pulse=Dj(r,n),o=s=DM(n.add(a))),i=n.keyRef(r.groupby,!0))):o=DM(n.add(yR(null,[{}]))),o||(o=Dj(t,n)),{key:i,pulse:o,parent:s}}(t.from,v,e),f=DM(r=e.add(xR({key:i.key||(t.key?MM(t.key):void 0),pulse:i.pulse,clean:!v}))),r=a=e.add(yR({pulse:f})),d=DM(r=e.add(AR({markdef:function(t){return{marktype:t.type,name:t.name||void 0,role:t.role||_j(t),zindex:+t.zindex||void 0}}(t),interactive:function(t,e){return t&&t.signal?e.signalRef(t.signal):!1!==t}(t.interactive,e),clip:function(t,e){var n;return Object(ct.F)(t)&&(t.signal?n=t.signal:t.path?n="pathShape("+kj(t.path)+")":t.sphere&&(n="geoShape("+kj(t.sphere)+', {type: "Sphere"})')),n?e.signalRef(n):!!t}(t.clip,e),context:{$context:!0},groups:e.lookup(),parent:e.signals.parent?e.signalRef("parent"):null,index:e.markpath(),pulse:DM(r)}))),(r=o=e.add(wR(rj(t.encode,t.type,g,t.style,e,{mod:!1,pulse:d})))).params.parent=e.encode(),t.transform&&t.transform.forEach(function(t){const n=Ej(t,e),i=n.metadata;(i.generates||i.changes)&&Object(ct.n)("Mark transforms should not generate new data."),i.nomod||(o.params.mod=!0),n.params.pulse=DM(r),e.add(r=n)}),t.sort&&(r=e.add(BR({sort:e.compareRef(t.sort),pulse:DM(r)}))),h=DM(r),(y||b)&&(p=DM(b=e.add(UR({layout:e.objectProperty(t.layout),legends:e.legends,mark:d,pulse:h})))),m=DM(s=e.add(vR({mark:d,pulse:p||h}))),v&&(x&&((n=e.operators).pop(),b&&n.pop()),e.pushState(h,p||m,f),y?function(t,e,n){var r,i,a,o,s=t.from.facet,u=s.name,c=Dj(s,e);s.name||Object(ct.n)("Facet must have a name: "+Object(ct.Z)(s)),s.data||Object(ct.n)("Facet must reference a data set: "+Object(ct.Z)(s)),s.field?o=e.add(MR({field:e.fieldRef(s.field),pulse:c})):s.groupby?o=e.add(_R({key:e.keyRef(s.groupby),group:DM(e.proxy(n.parent)),pulse:c})):Object(ct.n)("Facet must specify groupby or field: "+Object(ct.Z)(s)),i=(r=e.fork()).add(yR()),a=r.add(zR({pulse:DM(i)})),r.addData(u,new Mj(r,i,i,a)),r.addSignal("parent",null),o.params.subflow={$subflow:Zj(t,r).toRuntime()}}(t,e,i):x?function(t,e,n){var r=e.add(MR({pulse:n.pulse})),i=e.fork();i.add(zR()),i.addSignal("parent",null),r.params.subflow={$subflow:Zj(t,i).toRuntime()}}(t,e,i):Zj(t,e),e.popState(),x&&(b&&n.push(b),n.push(s))),w&&(m=function(t,e,n){var r,i=t.method,a=t.bound,o=t.separation,s={separation:BM(o)?n.signalRef(o.signal):o,method:BM(i)?n.signalRef(i.signal):i,pulse:e};t.order&&(s.sort=n.compareRef({field:t.order}));a&&(r=a.tolerance,s.boundTolerance=BM(r)?n.signalRef(r.signal):+r,s.boundScale=n.scaleRef(a.scale),s.boundOrient=a.orient);return DM(n.add(IR(s)))}(w,m,e)),u=e.add(PR({pulse:m})),c=e.add(zR({pulse:DM(u)},void 0,e.parent())),null!=t.name&&(l=t.name,e.addData(l,new Mj(e,a,u,c)),t.on&&t.on.forEach(function(t){(t.insert||t.remove||t.toggle)&&Object(ct.n)("Marks only support modify triggers."),Lj(t,e,l)}))};var Bj=function(t,e){var n,r,i,a,o,s,u,c,l,f=e.config.legend,d=t.encode||{},h=d.legend||{},p=h.name||void 0,m=h.interactive,g=h.style,v=sj(t,f),y=MF.reduce(function(e,n){return e||t[n]},0);return y||Object(ct.n)("Missing valid scale for legend."),o=function(t,e){var n=t.type||TF;t.type||1!==function(t){return MF.reduce(function(e,n){return e+(t[n]?1:0)},0)}(t)||!t.fill&&!t.stroke||(n=function(t){return aF(t,GR)}(e)?IF:sF(e)?DF:TF);return n!==IF?n:sF(e)?DF:IF}(t,e.scaleType(y)),s={title:null!=t.title,type:o,vgrad:"symbol"!==o&&v.isVertical()},u=DM(e.add(yR(null,[s]))),h=nj(function(t,e){var n={enter:{},update:{}};return ej(n,{orient:t("orient"),offset:t("offset"),padding:t("padding"),titlePadding:t("titlePadding"),cornerRadius:t("cornerRadius"),fill:t("fillColor"),stroke:t("strokeColor"),strokeWidth:e.strokeWidth,strokeDash:e.strokeDash,x:t("legendX"),y:t("legendY")}),n}(v,f),h,RF),n={enter:{x:{value:0},y:{value:0}}},c=DM(e.add(SR(i={type:o,scale:e.scaleRef(y),count:e.objectProperty(v("tickCount")),limit:e.property(v("symbolLimit")),values:e.objectProperty(t.values),minstep:e.property(t.tickMinStep),formatType:e.property(t.formatType),formatSpecifier:e.property(t.format)}))),o===IF?(a=[function(t,e,n,r){var i,a,o,s,u,c,l=sj(t,n),f=l.isVertical(),d=l.gradientThickness(),h=l.gradientLength();return f?(o=[0,1],s=[0,0],u=d,c=h):(o=[0,0],s=[1,0],u=h,c=d),ej(i={enter:a={opacity:FF,x:FF,y:FF,width:QF(u),height:QF(c)},update:Object(ct.o)({},a,{opacity:jF,fill:{gradient:e,start:o,stop:s}}),exit:{opacity:FF}},{stroke:l("gradientStrokeColor"),strokeWidth:l("gradientStrokeWidth")},{opacity:l("gradientOpacity")}),oj("rect","legend-gradient",null,void 0,void 0,i,r)}(t,y,f,d.gradient),hj(t,f,d.labels,c)],i.count=i.count||e.signalRef(`max(2,2*floor((${VM(v.gradientLength())})/100))`)):o===DF?a=[function(t,e,n,r,i){var a,o,s,u,c,l,f=sj(t,n),d=f.isVertical(),h=f.gradientThickness(),p=f.gradientLength(),m="";return d?(s="y",c="y2",u="x",l="width",m="1-"):(s="x",c="x2",u="y",l="height"),(o={opacity:FF,fill:{scale:e,field:SF}})[s]={signal:m+"datum.perc",mult:p},o[u]=FF,o[c]={signal:m+"datum.perc2",mult:p},o[l]=QF(h),ej(a={enter:o,update:Object(ct.o)({},o,{opacity:jF}),exit:{opacity:FF}},{stroke:f("gradientStrokeColor"),strokeWidth:f("gradientStrokeWidth")},{opacity:f("gradientOpacity")}),oj("rect","legend-band",null,SF,i,a,r)}(t,y,f,d.gradient,c),hj(t,f,d.labels,c)]:(r=function(t,e){const n=sj(t,e);return{align:n("gridAlign"),columns:n.entryColumns(),center:{row:!0,column:!1},padding:{row:n("rowPadding"),column:n("columnPadding")}}}(t,f),a=[function(t,e,n,r,i){var a,o,s,u,c,l,f,d=sj(t,e),h=n.entries,p=!(!h||!h.interactive),m=h?h.name:void 0,g=d("clipHeight"),v=d("symbolOffset"),y={data:"value"},b={},x=`(${i}) ? datum.offset : datum.size`,w=g?QF(g):{field:"size"},k="datum.index",_=`max(1, ${i})`;w.mult=.5,b={enter:a={opacity:FF,x:{signal:x,mult:.5,offset:v},y:w},update:o={opacity:jF,x:a.x,y:a.y},exit:{opacity:FF}};var E=null,O=null;return t.fill||(E=e.symbolBaseFillColor,O=e.symbolBaseStrokeColor),ej(b,{fill:d("symbolFillColor",E),shape:d("symbolType"),size:d("symbolSize"),stroke:d("symbolStrokeColor",O),strokeDash:d("symbolDash"),strokeDashOffset:d("symbolDashOffset"),strokeWidth:d("symbolStrokeWidth")},{opacity:d("symbolOpacity")}),MF.forEach(function(e){t[e]&&(o[e]=a[e]={scale:t[e],field:SF})}),u=oj("symbol","legend-symbol",null,SF,y,b,n.symbols),g&&(u.clip=!0),(s=QF(v)).offset=d("labelOffset"),ej(b={enter:a={opacity:FF,x:{signal:x,offset:s},y:w},update:o={opacity:jF,text:{field:"label"},x:a.x,y:a.y},exit:{opacity:FF}},{align:d("labelAlign"),baseline:d("labelBaseline"),fill:d("labelColor"),fillOpacity:d("labelOpacity"),font:d("labelFont"),fontSize:d("labelFontSize"),fontStyle:d("labelFontStyle"),fontWeight:d("labelFontWeight"),limit:d("labelLimit")}),c=oj(dj,"legend-label",CF,SF,y,b,n.labels),b={enter:{noBound:{value:!g},width:FF,height:g?QF(g):FF,opacity:FF},exit:{opacity:FF},update:o={opacity:jF,row:{signal:null},column:{signal:null}}},d.isVertical(!0)?(l=`ceil(item.mark.items.length / ${_})`,o.row.signal=`${k}%${l}`,o.column.signal=`floor(${k} / ${l})`,f={field:["row",k]}):(o.row.signal=`floor(${k} / ${_})`,o.column.signal=`${k} % ${_}`,f={field:k}),o.column.signal=`(${i})?${o.column.signal}:${k}`,(t=pj("scope",null,m,r={facet:{data:r,name:"value",groupby:"index"}},p,nj(b,h,RF),[u,c])).sort=f,t}(t,f,d,c,VM(r.columns))],i.size=function(t,e,n){var r=VM(Uj("size",t,n)),i=VM(Uj("strokeWidth",t,n)),a=VM(function(t,e,n){return uj("fontSize",t)||function(t,e,n){var r=e.config.style[n];return r&&r[t]}("fontSize",e,n)}(n[1].encode,e,CF));return AM(`max(ceil(sqrt(${r})+${i}),${a})`,e)}(t,e,a[0].marks)),a=[pj("legend-entry",null,null,u,m,n,a,r)],s.title&&a.push(function(t,e,n,r){var i,a=sj(t,e);return ej(i={enter:{opacity:FF},update:{opacity:jF,x:{field:{group:"padding"}},y:{field:{group:"padding"}}},exit:{opacity:FF}},{orient:a("titleOrient"),_anchor:a("titleAnchor"),anchor:{signal:bj},angle:{signal:xj},align:{signal:yj},baseline:{signal:wj},text:t.title,fill:a("titleColor"),fillOpacity:a("titleOpacity"),font:a("titleFont"),fontSize:a("titleFontSize"),fontStyle:a("titleFontStyle"),fontWeight:a("titleFontWeight"),limit:a("titleLimit"),lineHeight:a("titleLineHeight")},{align:a("titleAlign"),baseline:a("titleBaseline")}),oj(dj,"legend-title","guide-title",null,r,i,n)}(t,f,d.title,u)),l=pj("legend",g,p,u,m,h,a),t.zindex&&(l.zindex=t.zindex),zj(l,e)};function Uj(t,e,n){return e[t]?`scale("${e[t]}",datum)`:uj(t,n[0].encode)}const Wj='item.orient==="left"?-90:item.orient==="right"?90:0';var Vj=function(t,e){var n,r,i=sj(t=Object(ct.H)(t)?{text:t}:t,e.config.title),a=t.encode||{},o=a.group||{},s=o.name||void 0,u=o.interactive,c=o.style,l=[];return n=DM(e.add(yR(null,[{}]))),l.push(function(t,e,n,r){var i={value:0},a=t.text,o={enter:{opacity:i},update:{opacity:{value:1}},exit:{opacity:i}};return ej(o,{text:a,align:{signal:"item.mark.group.align"},angle:{signal:"item.mark.group.angle"},limit:{signal:"item.mark.group.limit"},baseline:"top",dx:e("dx"),dy:e("dy"),fill:e("color"),font:e("font"),fontSize:e("fontSize"),fontStyle:e("fontStyle"),fontWeight:e("fontWeight"),lineHeight:e("lineHeight")},{align:e("align"),angle:e("angle"),baseline:e("baseline")}),oj(dj,JF,AF,null,r,o,n)}(t,i,function(t){const e=t.encode;return e&&e.title||Object(ct.o)({name:t.name,interactive:t.interactive,style:t.style},e)}(t),n)),t.subtitle&&l.push(function(t,e,n,r){var i={value:0},a=t.subtitle,o={enter:{opacity:i},update:{opacity:{value:1}},exit:{opacity:i}};return ej(o,{text:a,align:{signal:"item.mark.group.align"},angle:{signal:"item.mark.group.angle"},limit:{signal:"item.mark.group.limit"},baseline:"top",dx:e("dx"),dy:e("dy"),fill:e("subtitleColor"),font:e("subtitleFont"),fontSize:e("subtitleFontSize"),fontStyle:e("subtitleFontStyle"),fontWeight:e("subtitleFontWeight"),lineHeight:e("subtitleLineHeight")},{align:e("align"),angle:e("angle"),baseline:e("baseline")}),oj(dj,ZF,NF,null,r,o,n)}(t,i,a.subtitle,n)),r=pj("title",c,s,n,u,function(t,e){var n={enter:{},update:{}};return ej(n,{orient:t("orient"),anchor:t("anchor"),align:{signal:lj},angle:{signal:Wj},limit:t("limit"),frame:t("frame"),offset:t("offset")||0,padding:t("subtitlePadding")}),nj(n,e,RF)}(i,o),l),t.zindex&&(r.zindex=t.zindex),zj(r,e)};function qj(t,e){var n=[];t.transform&&t.transform.forEach(function(t){n.push(Ej(t,e))}),t.on&&t.on.forEach(function(n){Lj(n,e,t.name)}),e.addDataPipeline(t.name,function(t,e,n){var r,i,a,o,s,u=[],c=null,l=!1,f=!1;t.values?UM(t.values)||UM(t.format)?(u.push(Gj(e,t)),u.push(c=Hj())):u.push(c=Hj({$ingest:t.values,$format:t.format})):t.url?UM(t.url)||UM(t.format)?(u.push(Gj(e,t)),u.push(c=Hj())):u.push(c=Hj({$request:t.url,$format:t.format})):t.source&&(c=r=Object(ct.i)(t.source).map(function(t){return DM(e.getData(t).output)}),u.push(null));for(i=0,a=n.length;i<a;++i)o=n[i],s=o.metadata,c||s.source||u.push(c=Hj()),u.push(o),s.generates&&(f=!0),s.modifies&&!f&&(l=!0),s.source?c=o:s.changes&&(c=null);r&&(a=r.length-1,u[0]=jR({derive:l,pulse:a?r:r[0]}),(l||a)&&u.splice(1,0,Hj()));c||u.push(Hj());return u.push(zR({})),u}(t,e,n))}function Hj(t){var e=yR({},t);return e.metadata={source:!0},e}function Gj(t,e){return CR({url:e.url?t.property(e.url):void 0,async:e.async?t.property(e.async):void 0,values:e.values?t.property(e.values):void 0,format:t.objectProperty(e.format)})}function $j(t,e){return{scale:t.scale,range:e}}var Kj=function(t,e,n,r,i){var a,o,s,u,c,l,f,d,h,p=sj(t,e),m=t.orient,g=t.gridScale,v="left"===m||"top"===m?1:-1,y=function(t,e){if(1===e);else if(Object(ct.F)(t)){for(var n=t=Object(ct.o)({},t);null!=n.mult;){if(!Object(ct.F)(n.mult))return n.mult*=e,t;n=n.mult=Object(ct.o)({},n.mult)}n.mult=e}else t=e*(t||0);return t}(t.offset,v);return ej(a={enter:o={opacity:FF},update:u={opacity:jF},exit:s={opacity:FF}},{stroke:p("gridColor"),strokeDash:p("gridDash"),strokeDashOffset:p("gridDashOffset"),strokeOpacity:p("gridOpacity"),strokeWidth:p("gridWidth")}),c={scale:t.scale,field:SF,band:i.band,extra:i.extra,offset:i.offset,round:p("tickRound")},"top"===m||"bottom"===m?(l="x",f="y",h="height"):(l="y",f="x",h="width"),d=f+"2",u[l]=o[l]=s[l]=c,g?(u[f]=o[f]={scale:g,range:0,mult:v,offset:y},u[d]=o[d]={scale:g,range:1,mult:v,offset:y}):(u[f]=o[f]={value:0,offset:y},u[d]=o[d]={signal:h,mult:v,offset:y}),oj("rule","axis-grid",null,SF,r,a,n)};function Xj(t,e,n,r,i){return{signal:'flush(range("'+t+'"), scale("'+t+'", datum.value), '+e+","+n+","+r+","+i+")"}}var Yj=function(t,e,n,r,i,a){var o,s,u,c,l,f,d,h,p,m,g=sj(t,e),v=t.orient,y="left"===v||"top"===v?-1:1,b="top"===v||"bottom"===v,x=t.scale,w=VM(g("labelFlush")),k=VM(g("labelFlushOffset")),_=0===w||!!w,E=g("labelAlign"),O=g("labelBaseline");return(u=QF(i)).mult=y,u.offset=QF(g("labelPadding")||0),u.offset.mult=y,c={scale:x,field:SF,band:.5,offset:function t(e,n){return n?e?Object(ct.F)(e)?{...e,offset:t(e.offset,n)}:{value:e,offset:n}:n:e}(a.offset,g("labelOffset"))},b?(l=E||(_?Xj(x,w,'"left"','"right"','"center"'):"center"),f=O||("top"===v?"bottom":"top"),d=!E):(l=E||("right"===v?"left":"right"),f=O||(_?Xj(x,w,'"top"','"bottom"','"middle"'):"middle"),d=!O),d=d&&_&&k?Xj(x,w,"-("+k+")",k,0):null,ej(o={enter:s={opacity:FF,x:b?c:u,y:b?u:c},update:{opacity:jF,text:{field:"label"},x:s.x,y:s.y},exit:{opacity:FF,x:s.x,y:s.y}},{[b?"dx":"dy"]:d,align:l,baseline:f,angle:g("labelAngle"),fill:g("labelColor"),fillOpacity:g("labelOpacity"),font:g("labelFont"),fontSize:g("labelFontSize"),fontWeight:g("labelFontWeight"),fontStyle:g("labelFontStyle"),limit:g("labelLimit"),lineHeight:g("labelLineHeight")}),h=g("labelBound"),p=g("labelOverlap"),m=g("labelSeparation"),t=oj(dj,"axis-label",CF,SF,r,o,n),(p||h)&&(t.overlap={separation:m,method:p,order:"datum.index",bound:h?{scale:x,orient:v,tolerance:h}:null}),t},Jj=function(t,e){var n,r,i,a,o,s,u=function(t,e){var n=e.config,r=t.orient,i="top"===r||"bottom"===r?n.axisX:n.axisY,a=n["axis"+r[0].toUpperCase()+r.slice(1)],o="band"===e.scaleType(t.scale)&&n.axisBand;return i||a||o?Object(ct.o)({},n.axis,i,a,o):n.axis}(t,e),c=t.encode||{},l=c.axis||{},f=l.name||void 0,d=l.interactive,h=l.style,p=sj(t,u),m=function(t){let e,n,r=t("tickBand"),i=t("tickOffset");return r?r.signal?(e={signal:`(${r.signal})==='extent'?1:0.5`},n={signal:`(${r.signal})==='extent'?true:false`},Object(ct.F)(i)||(i={signal:`(${r.signal})==='extent'?0:${i}`})):"extent"===r?(e=1,n=!0,i=0):(e=.5,n=!1):(e=t("bandPosition"),n=t("tickExtra")),{extra:n,band:e,offset:i}}(p);return n={orient:t.orient,ticks:!!p("ticks"),labels:!!p("labels"),grid:!!p("grid"),domain:!!p("domain"),title:null!=t.title,translate:p("translate")},r=DM(e.add(yR({},[n]))),l=nj({update:{offset:QF(p("offset")||0),position:QF(WM(t.position,0)),titlePadding:QF(p("titlePadding")),minExtent:QF(p("minExtent")),maxExtent:QF(p("maxExtent")),range:{signal:`abs(span(range("${t.scale}")))`}}},c.axis,RF),i=DM(e.add(gR({scale:e.scaleRef(t.scale),extra:e.property(m.extra),count:e.objectProperty(t.tickCount),values:e.objectProperty(t.values),minstep:e.property(t.tickMinStep),formatType:e.property(t.formatType),formatSpecifier:e.property(t.format)}))),s=[],n.grid&&s.push(Kj(t,u,c.grid,i,m)),n.ticks&&(a=p("tickSize"),s.push(function(t,e,n,r,i,a){var o,s,u,c,l,f,d=sj(t,e),h=t.orient,p="left"===h||"top"===h?-1:1;return ej(o={enter:s={opacity:FF},update:c={opacity:jF},exit:u={opacity:FF}},{stroke:d("tickColor"),strokeDash:d("tickDash"),strokeDashOffset:d("tickDashOffset"),strokeOpacity:d("tickOpacity"),strokeWidth:d("tickWidth")}),(l=QF(i)).mult=p,f={scale:t.scale,field:SF,band:a.band,extra:a.extra,offset:a.offset,round:d("tickRound")},"top"===h||"bottom"===h?(c.y=s.y=FF,c.y2=s.y2=l,c.x=s.x=u.x=f):(c.x=s.x=FF,c.x2=s.x2=l,c.y=s.y=u.y=f),oj("rule","axis-tick",null,SF,r,o,n)}(t,u,c.ticks,i,a,m))),n.labels&&(a=n.ticks?a:0,s.push(Yj(t,u,c.labels,i,a,m))),n.domain&&s.push(function(t,e,n,r){var i,a,o,s,u,c,l=sj(t,e),f=t.orient;return ej(i={enter:a={opacity:FF},update:o={opacity:jF},exit:{opacity:FF}},{stroke:l("domainColor"),strokeDash:l("domainDash"),strokeDashOffset:l("domainDashOffset"),strokeWidth:l("domainWidth"),strokeOpacity:l("domainOpacity")}),"top"===f||"bottom"===f?(s="x",c="y"):(s="y",c="x"),u=s+"2",a[c]=FF,o[s]=a[s]=$j(t,0),o[u]=a[u]=$j(t,1),oj("rule","axis-domain",null,null,r,i,n)}(t,u,c.domain,r)),n.title&&s.push(function(t,e,n,r){var i,a,o,s,u=sj(t,e),c=t.orient,l="left"===c||"top"===c?-1:1,f="top"===c||"bottom"===c;return i={enter:a={opacity:FF,anchor:QF(u("titleAnchor")),align:{signal:lj}},update:o=Object(ct.o)({},a,{opacity:jF,text:QF(t.title)}),exit:{opacity:FF}},s={signal:`lerp(range("${t.scale}"), ${cj(0,1,.5)})`},f?(o.x=s,a.angle={value:0},a.baseline={value:"top"===c?"bottom":"top"}):(o.y=s,a.angle={value:90*l},a.baseline={value:"bottom"}),ej(i,{angle:u("titleAngle"),baseline:u("titleBaseline"),fill:u("titleColor"),fillOpacity:u("titleOpacity"),font:u("titleFont"),fontSize:u("titleFontSize"),fontStyle:u("titleFontStyle"),fontWeight:u("titleFontWeight"),limit:u("titleLimit"),lineHeight:u("titleLineHeight")},{align:u("titleAlign")}),!tj(i,"x",u("titleX"),"update")&&!f&&!aj("x",n)&&(i.enter.auto={value:!0}),!tj(i,"y",u("titleY"),"update")&&f&&!aj("y",n)&&(i.enter.auto={value:!0}),oj(dj,"axis-title","guide-title",null,r,i,n)}(t,u,c.title,r)),o=pj("axis",h,f,r,d,l,s),t.zindex&&(o.zindex=t.zindex),zj(o,e)},Zj=function(t,e,n){var r=Object(ct.i)(t.signals),i=Object(ct.i)(t.scales);return n||r.forEach(t=>CM(t,e)),Object(ct.i)(t.projections).forEach(t=>(function(t,e){var n=e.config.projection||{},r={};for(var i in t)"name"!==i&&(r[i]=kF(t[i],i,e));for(i in n)null==r[i]&&(r[i]=kF(n[i],i,e));e.addProjection(t.name,r)})(t,e)),i.forEach(t=>(function(t,e){var n=t.type||"linear";iF(n)||Object(ct.n)("Unrecognized scale type: "+Object(ct.Z)(n)),e.addScale(t.name,{type:n,domain:void 0})})(t,e)),Object(ct.i)(t.data).forEach(t=>qj(t,e)),i.forEach(t=>gF(t,e)),(n||r).forEach(t=>(function(t,e){var n=e.getSignal(t.name),r=t.update;t.init&&(r?Object(ct.n)("Signals can not include both init and update expressions."):(r=t.init,n.initonly=!0)),r&&(r=AM(r,e),n.update=r.$expr,n.params=r.$params),t.on&&t.on.forEach(function(t){hR(t,e,n.id)})})(t,e)),Object(ct.i)(t.axes).forEach(t=>Jj(t,e)),Object(ct.i)(t.marks).forEach(t=>zj(t,e)),Object(ct.i)(t.legends).forEach(t=>Bj(t,e)),t.title&&Vj(t.title,e),e.parseLambdas(),e};function Qj(t,e){var n,r,i,a,o,s,u=e.config;return o=DM(e.root=e.add(IM())),(s=function(t,e){const n=n=>WM(t[n],e[n]),r=[tP("background",n("background")),tP("autosize",kM(n("autosize"))),tP("padding",EM(n("padding"))),tP("width",n("width")||0),tP("height",n("height")||0)],i=r.reduce((t,e)=>(t[e.name]=e,t),{}),a={};return Object(ct.i)(t.signals).forEach(t=>{Object(ct.v)(i,t.name)?t=Object(ct.o)(i[t.name],t):r.push(t),a[t.name]=t}),Object(ct.i)(e.signals).forEach(t=>{Object(ct.v)(a,t.name)||Object(ct.v)(i,t.name)||r.push(t)}),r}(t,u)).forEach(t=>CM(t,e)),e.description=t.description||u.description,e.eventConfig=u.events,e.legends=e.objectProperty(u.legend&&u.legend.layout),r=e.add(yR()),i=nj({enter:{x:{value:0},y:{value:0}},update:{width:{signal:"width"},height:{signal:"height"}}},t.encode),i=e.add(wR(rj(i,fj,YF,t.style,e,{pulse:DM(r)}))),a=e.add(UR({layout:e.objectProperty(t.layout),legends:e.legends,autosize:e.signalRef("autosize"),mark:o,pulse:DM(i)})),e.operators.pop(),e.pushState(DM(i),DM(a),null),Zj(t,e,s),e.operators.push(a),n=e.add(vR({mark:o,pulse:DM(a)})),n=e.add(PR({pulse:DM(n)})),n=e.add(zR({pulse:DM(n)})),e.addData("root",new Mj(e,r,r,n)),e}function tP(t,e){return e&&e.signal?{name:t,update:e.signal}:{name:t,value:e}}function eP(t){this.config=t,this.bindings=[],this.field={},this.signals={},this.lambdas={},this.scales={},this.events={},this.data={},this.streams=[],this.updates=[],this.operators=[],this.eventConfig=null,this._id=0,this._subid=0,this._nextsub=[0],this._parent=[],this._encode=[],this._lookup=[],this._markpath=[]}function nP(t){this.config=t.config,this.legends=t.legends,this.field=Object.create(t.field),this.signals=Object.create(t.signals),this.lambdas=Object.create(t.lambdas),this.scales=Object.create(t.scales),this.events=Object.create(t.events),this.data=Object.create(t.data),this.streams=[],this.updates=[],this.operators=[],this._id=0,this._subid=++t._nextsub[0],this._nextsub=t._nextsub,this._parent=t._parent.slice(),this._encode=t._encode.slice(),this._lookup=t._lookup.slice(),this._markpath=t._markpath}var rP=eP.prototype=nP.prototype;function iP(t){return(Object(ct.A)(t)?function(t){for(var e,n="[",r=0,i=t.length;r<i;++r)e=t[r],n+=(r>0?",":"")+(Object(ct.F)(e)?e.signal||iP(e):Object(ct.Z)(e));return n+"]"}:function(t){var e,n,r="{",i=0;for(e in t)n=t[e],r+=(++i>1?",":"")+Object(ct.Z)(e)+":"+(Object(ct.F)(n)?n.signal||iP(n):Object(ct.Z)(n));return r+"}"})(t)}rP.fork=function(){return new nP(this)},rP.isSubscope=function(){return this._subid>0},rP.toRuntime=function(){return this.finish(),{description:this.description,operators:this.operators,streams:this.streams,updates:this.updates,bindings:this.bindings,eventConfig:this.eventConfig}},rP.id=function(){return(this._subid?this._subid+":":0)+this._id++},rP.add=function(t){return this.operators.push(t),t.id=this.id(),t.refs&&(t.refs.forEach(function(e){e.$ref=t.id}),t.refs=null),t},rP.proxy=function(t){var e=t instanceof NM?DM(t):t;return this.add(FR({value:e}))},rP.addStream=function(t){return this.streams.push(t),t.id=this.id(),t},rP.addUpdate=function(t){return this.updates.push(t),t},rP.finish=function(){var t,e;for(t in this.root&&(this.root.root=!0),this.signals)this.signals[t].signal=t;for(t in this.scales)this.scales[t].scale=t;function n(t,e,n){var r;t&&((r=t.data||(t.data={}))[e]||(r[e]=[])).push(n)}for(t in this.data)for(var r in n((e=this.data[t]).input,t,"input"),n(e.output,t,"output"),n(e.values,t,"values"),e.index)n(e.index[r],t,"index:"+r);return this},rP.pushState=function(t,e,n){this._encode.push(DM(this.add(zR({pulse:t})))),this._parent.push(e),this._lookup.push(n?DM(this.proxy(n)):null),this._markpath.push(-1)},rP.popState=function(){this._encode.pop(),this._parent.pop(),this._lookup.pop(),this._markpath.pop()},rP.parent=function(){return Object(ct.U)(this._parent)},rP.encode=function(){return Object(ct.U)(this._encode)},rP.lookup=function(){return Object(ct.U)(this._lookup)},rP.markpath=function(){var t=this._markpath;return++t[t.length-1]},rP.fieldRef=function(t,e){if(Object(ct.H)(t))return MM(t,e);t.signal||Object(ct.n)("Unsupported field reference: "+Object(ct.Z)(t));var n,r=t.signal,i=this.field[r];return i||(n={name:this.signalRef(r)},e&&(n.as=e),this.field[r]=i=DM(this.add(ER(n)))),i},rP.compareRef=function(t){function e(t){return BM(t)?(r=!0,n.signalRef(t.signal)):function(t){return t&&t.expr}(t)?(r=!0,n.exprRef(t.expr)):t}var n=this,r=!1,i=Object(ct.i)(t.field).map(e),a=Object(ct.i)(t.order).map(e);return r?DM(this.add(bR({fields:i,orders:a}))):FM(i,a)},rP.keyRef=function(t,e){var n=this.signals,r=!1;return t=Object(ct.i)(t).map(function(t){return BM(t)?(r=!0,DM(n[t.signal])):t}),r?DM(this.add(OR({fields:t,flat:e}))):function(t,e){var n={$key:t};return e&&(n.$flat=!0),n}(t,e)},rP.sortRef=function(t){if(!t)return t;var e=PM(t.op,t.field),n=t.order||"ascending";return n.signal?DM(this.add(bR({fields:e,orders:this.signalRef(n.signal)}))):FM(e,n)},rP.event=function(t,e){var n=t+":"+e;if(!this.events[n]){var r=this.id();this.streams.push({id:r,source:t,type:e}),this.events[n]=r}return this.events[n]},rP.hasOwnSignal=function(t){return Object(ct.v)(this.signals,t)},rP.addSignal=function(t,e){this.hasOwnSignal(t)&&Object(ct.n)("Duplicate signal name: "+Object(ct.Z)(t));var n=e instanceof NM?e:this.add(IM(e));return this.signals[t]=n},rP.getSignal=function(t){return this.signals[t]||Object(ct.n)("Unrecognized signal name: "+Object(ct.Z)(t)),this.signals[t]},rP.signalRef=function(t){return this.signals[t]?DM(this.signals[t]):(Object(ct.v)(this.lambdas,t)||(this.lambdas[t]=this.add(IM(null))),DM(this.lambdas[t]))},rP.parseLambdas=function(){for(var t=Object.keys(this.lambdas),e=0,n=t.length;e<n;++e){var r=t[e],i=AM(r,this),a=this.lambdas[r];a.params=i.$params,a.update=i.$expr}},rP.property=function(t){return t&&t.signal?this.signalRef(t.signal):t},rP.objectProperty=function(t){return t&&Object(ct.F)(t)?this.signalRef(t.signal||iP(t)):t},rP.exprRef=function(t,e){var n={expr:AM(t,this)};return e&&(n.expr.$name=e),DM(this.add(kR(n)))},rP.addBinding=function(t,e){this.bindings||Object(ct.n)("Nested signals do not support binding: "+Object(ct.Z)(t)),this.bindings.push(Object(ct.o)({signal:t},e))},rP.addScaleProj=function(t,e){Object(ct.v)(this.scales,t)&&Object(ct.n)("Duplicate scale or projection name: "+Object(ct.Z)(t)),this.scales[t]=this.add(e)},rP.addScale=function(t,e){this.addScaleProj(t,LR(e))},rP.addProjection=function(t,e){this.addScaleProj(t,RR(e))},rP.getScale=function(t){return this.scales[t]||Object(ct.n)("Unrecognized scale name: "+Object(ct.Z)(t)),this.scales[t]},rP.projectionRef=rP.scaleRef=function(t){return DM(this.getScale(t))},rP.projectionType=rP.scaleType=function(t){return this.getScale(t).params.type},rP.addData=function(t,e){return Object(ct.v)(this.data,t)&&Object(ct.n)("Duplicate data set name: "+Object(ct.Z)(t)),this.data[t]=e},rP.getData=function(t){return this.data[t]||Object(ct.n)("Undefined data set name: "+Object(ct.Z)(t)),this.data[t]},rP.addDataPipeline=function(t,e){return Object(ct.v)(this.data,t)&&Object(ct.n)("Duplicate data set name: "+Object(ct.Z)(t)),this.addData(t,Mj.fromEntries(this,e))};var aP=function(t,e){return Object(ct.F)(t)||Object(ct.n)("Input Vega specification must be an object."),Qj(t,new eP(e=Object(ct.N)({description:"Vega visualization",padding:0,autosize:"pad",background:null,events:{defaults:{allow:["wheel"]}},group:null,mark:null,arc:{fill:"#4c78a8"},area:{fill:"#4c78a8"},image:null,line:{stroke:"#4c78a8",strokeWidth:2},path:{stroke:"#4c78a8"},rect:{fill:"#4c78a8"},rule:{stroke:"#000"},shape:{stroke:"#4c78a8"},symbol:{fill:"#4c78a8",size:64},text:{fill:"#000",font:"sans-serif",fontSize:11},trail:{fill:"#4c78a8",size:2},style:{"guide-label":{fill:"#000",font:"sans-serif",fontSize:10},"guide-title":{fill:"#000",font:"sans-serif",fontSize:11,fontWeight:"bold"},"group-title":{fill:"#000",font:"sans-serif",fontSize:13,fontWeight:"bold"},"group-subtitle":{fill:"#000",font:"sans-serif",fontSize:12},point:{size:30,strokeWidth:2,shape:"circle"},circle:{size:30,strokeWidth:2},square:{size:30,strokeWidth:2,shape:"square"},cell:{fill:"transparent",stroke:"#ddd"}},title:{orient:"top",anchor:"middle",offset:4,subtitlePadding:3},axis:{minExtent:0,maxExtent:200,bandPosition:.5,domain:!0,domainWidth:1,domainColor:"#888",grid:!1,gridWidth:1,gridColor:"#ddd",labels:!0,labelAngle:0,labelLimit:180,labelOffset:0,labelPadding:2,ticks:!0,tickColor:"#888",tickOffset:0,tickRound:!0,tickSize:5,tickWidth:1,titlePadding:4},axisBand:{tickOffset:-.5},projection:{type:"mercator"},legend:{orient:"right",padding:0,gridAlign:"each",columnPadding:10,rowPadding:2,symbolDirection:"vertical",gradientDirection:"vertical",gradientLength:200,gradientThickness:16,gradientStrokeColor:"#ddd",gradientStrokeWidth:0,gradientLabelOffset:2,labelAlign:"left",labelBaseline:"middle",labelLimit:160,labelOffset:4,labelOverlap:!0,symbolLimit:30,symbolType:"circle",symbolSize:100,symbolOffset:0,symbolStrokeWidth:1.5,symbolBaseFillColor:"transparent",symbolBaseStrokeColor:"#888",titleLimit:180,titleOrient:"top",titlePadding:5,layout:{offset:18,direction:"horizontal",left:{direction:"vertical"},right:{direction:"vertical"}}},range:{category:{scheme:"tableau10"},ordinal:{scheme:"blues"},heatmap:{scheme:"yellowgreenblue"},ramp:{scheme:"blues"},diverging:{scheme:"blueorange",extent:[1,0]},symbol:["circle","square","triangle-up","cross","diamond","triangle-right","triangle-down","triangle-left"]}},e,t.config))).toRuntime()};Object(ct.o)(Wr,r,i,o,s,u,c,l,f,d,h);var oP=n(287),sP=function(t,e,n){return t.fields=e||[],t.fname=n,t};var uP=function(t){throw Error(t)},cP=function(t){var e,n,r,i=[],a=null,o=0,s=t.length,u="";function c(){i.push(u+t.substring(e,n)),u="",e=n+1}for(t+="",e=n=0;n<s;++n)if("\\"===(r=t[n]))u+=t.substring(e,n),u+=t.substring(++n,++n),e=n;else if(r===a)c(),a=null,o=-1;else{if(a)continue;e===o&&'"'===r?(e=n+1,a=r):e===o&&"'"===r?(e=n+1,a=r):"."!==r||o?"["===r?(n>e&&c(),o=e=n+1):"]"===r&&(o||uP("Access path missing open bracket: "+t),o>0&&c(),o=0,e=n+1):n>e?c():e=n+1}return o&&uP("Access path missing closing bracket: "+t),a&&uP("Access path missing closing quote: "+t),n>e&&(n++,c()),i},lP=Array.isArray,fP=function(t){return t===Object(t)},dP=function(t){return"string"==typeof t};function hP(t){return lP(t)?"["+t.map(hP)+"]":fP(t)||dP(t)?JSON.stringify(t).replace("\u2028","\\u2028").replace("\u2029","\\u2029"):t}var pP=[],mP=(function(t,e){var n=cP(t),r="return _["+n.map(hP).join("][")+"];";sP(Function("_",r),[t=1===n.length?n[0]:t],e||t)}("id"),sP(function(t){return t},pP,"identity"));sP(function(){return 0},pP,"zero"),sP(function(){return 1},pP,"one"),sP(function(){return!0},pP,"true"),sP(function(){return!1},pP,"false");function gP(t,e,n){var r=[e].concat([].slice.call(n));console[t].apply(console,r)}function vP(...t){return t.reduce((t,e)=>{for(var n in e)if("signals"===n)t.signals=bP(t.signals,e.signals);else{var r="legend"===n?{layout:1}:"style"===n||null;yP(t,n,e[n],r)}return t},{})}function yP(t,e,n,r){var i,a;if(fP(n)&&!lP(n))for(i in a=fP(t[e])?t[e]:t[e]={},n)r&&(!0===r||r[i])?yP(a,i,n[i]):a[i]=n[i];else t[e]=n}function bP(t,e){if(null==t)return e;const n={},r=[];function i(t){n[t.name]||(n[t.name]=1,r.push(t))}return e.forEach(i),t.forEach(i),r}var xP=function(t){return null!=t?lP(t)?t:[t]:[]},wP=function(t){return"function"==typeof t};const kP=Object.prototype.hasOwnProperty;var _P=function(t,e){return kP.call(t,e)},EP=function(t){return"boolean"==typeof t},OP=function(t){return"number"==typeof t};var SP=function(t){for(var e={},n=0,r=t.length;n<r;++n)e[t[n]]=!0;return e};Array.prototype.flat||Object.defineProperty(Array.prototype,"flat",{configurable:!0,value:function t(){var e=isNaN(arguments[0])?1:Number(arguments[0]);return e?Array.prototype.reduce.call(this,function(n,r){return Array.isArray(r)?n.push.apply(n,t.call(r,e-1)):n.push(r),n},[]):Array.prototype.slice.call(this)},writable:!0}),Array.prototype.flatMap||Object.defineProperty(Array.prototype,"flatMap",{configurable:!0,value:function(t){return Array.prototype.map.apply(this,arguments).flat()},writable:!0});var CP=n(286),AP=n.n(CP),NP=n(285),TP=n.n(NP),IP=n(81),DP=n.n(IP);function MP(t){return!!t.or}function RP(t){return!!t.and}function FP(t){return!!t.not}const jP=TP.a,PP=AP.a;function LP(t,e){const n={};for(const r of e)_P(t,r)&&(n[r]=t[r]);return n}function zP(t,e){const n=Object.assign({},t);for(const t of e)delete n[t];return n}Set.prototype.toJSON=function(){return`Set(${[...this].map(t=>DP()(t)).join(",")})`};const BP=DP.a;function UP(t){if(OP(t))return t;const e=dP(t)?t:DP()(t);if(e.length<250)return e;let n=0;for(let t=0;t<e.length;t++){n=(n<<5)-n+e.charCodeAt(t),n&=n}return n}function WP(t){return!1===t||null===t}function VP(t,e){return t.indexOf(e)>-1}function qP(t,e){let n=0;for(const[r,i]of t.entries())if(e(i,r,n++))return!0;return!1}function HP(t,e){let n=0;for(const[r,i]of t.entries())if(!e(i,r,n++))return!1;return!0}function GP(t,e){for(const n of Object.keys(e))yP(t,n,e[n],!0)}function $P(t,e){const n=[],r={};let i;for(const a of t)(i=e(a))in r||(r[i]=1,n.push(a));return n}function KP(t,e){for(const n of t)if(e.has(n))return!0;return!1}function XP(t){const e=new Set;for(const n of t){const t=cP(n).map((t,e)=>0===e?t:`[${t}]`);t.map((e,n)=>t.slice(0,n+1).join("")).forEach(t=>e.add(t))}return e}function YP(t,e){return void 0===t||void 0===e||KP(XP(t),XP(e))}const JP=Object.keys;function ZP(t){const e=[];for(const n in t)_P(t,n)&&e.push(t[n]);return e}function QP(t){return!0===t||!1===t}function tL(t){const e=t.replace(/\W/g,"_");return(t.match(/^\d+/)?"_":"")+e}function eL(t,e){return FP(t)?"!("+eL(t.not,e)+")":RP(t)?"("+t.and.map(t=>eL(t,e)).join(") && (")+")":MP(t)?"("+t.or.map(t=>eL(t,e)).join(") || (")+")":e(t)}function nL(t,e){if(0===e.length)return!0;const n=e.shift();return nL(t[n],e)&&delete t[n],0===JP(t).length}function rL(t){return t.charAt(0).toUpperCase()+t.substr(1)}function iL(t,e="datum"){const n=cP(t),r=[];for(let t=1;t<=n.length;t++){const i=`[${n.slice(0,t).map(hP).join("][")}]`;r.push(`${e}${i}`)}return r.join(" && ")}function aL(t){return`${cP(t).map(t=>oL(t,".","\\.")).join("\\.")}`}function oL(t,e,n){return t.replace(new RegExp(e.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),n)}function sL(t){return t?cP(t).length:0}function uL(...t){for(const e of t)if(void 0!==e)return e}let cL=42;function lL(t){const e=++cL;return t?String(t)+e:e}function fL(t){return(t%360+360)%360}const dL="area",hL="bar",pL="image",mL="line",gL="point",vL="rect",yL="rule",bL="text",xL="tick",wL="trail",kL="circle",_L="square",EL="geoshape",OL={area:1,bar:1,image:1,line:1,point:1,text:1,tick:1,trail:1,rect:1,geoshape:1,rule:1,circle:1,square:1};function SL(t){return VP(["line","area","trail"],t)}function CL(t){return VP(["rect","bar","image"],t)}const AL=JP(OL);function NL(t){return t.type}SP(AL);const TL=[...["stroke","strokeWidth","strokeDash","strokeDashOffset","strokeOpacity","strokeJoin","strokeMiterLimit"],...["fill","fillOpacity"]],IL=["filled","color","tooltip","invalid","timeUnitBandPosition","timeUnitBand"],DL={binSpacing:1,continuousBandSize:5,timeUnitBandPosition:.5},ML={binSpacing:0,continuousBandSize:5,timeUnitBandPosition:.5};function RL(t){return!!t.mark}class FL{constructor(t,e){this.name=t,this.run=e}hasMatchingType(t){return!!RL(t)&&function(t){return NL(t)?t.type:t}(t.mark)===this.name}}const jL={argmax:1,argmin:1,average:1,count:1,distinct:1,max:1,mean:1,median:1,min:1,missing:1,q1:1,q3:1,ci0:1,ci1:1,stderr:1,stdev:1,stdevp:1,sum:1,valid:1,values:1,variance:1,variancep:1},PL={count:1,min:1,max:1};function LL(t){return!!t&&!!t.argmin}function zL(t){return!!t&&!!t.argmax}JP(jL);function BL(t){return dP(t)&&!!jL[t]}const UL=["count","valid","missing","distinct"];function WL(t){return dP(t)&&VP(UL,t)}const VL=["count","sum","distinct","valid","missing"],qL=SP(["mean","average","median","q1","q3","min","max"]),HL="row",GL="column",$L="facet",KL="x",XL="y",YL="x2",JL="y2",ZL="latitude",QL="longitude",tz="latitude2",ez="longitude2",nz="color",rz="fill",iz="stroke",az="shape",oz="size",sz="opacity",uz="fillOpacity",cz="strokeOpacity",lz="strokeWidth",fz="text",dz="order",hz="detail",pz="key",mz="tooltip",gz="href",vz="url",yz={x:1,y:1,x2:1,y2:1};const bz={longitude:1,longitude2:1,latitude:1,latitude2:1};const xz=JP(bz),wz=Object.assign(Object.assign(Object.assign({},yz),bz),{color:1,fill:1,stroke:1,opacity:1,fillOpacity:1,strokeOpacity:1,strokeWidth:1,size:1,shape:1,order:1,text:1,detail:1,key:1,tooltip:1,href:1,url:1});function kz(t){return"color"===t||"fill"===t||"stroke"===t}const _z={row:1,column:1,facet:1},Ez=JP(_z),Oz=Object.assign(Object.assign({},wz),_z),Sz=JP(Oz),{order:Cz,detail:Az,tooltip:Nz}=Oz,Tz=b(Oz,["order","detail","tooltip"]),{row:Iz,column:Dz,facet:Mz}=Tz,Rz=b(Tz,["row","column","facet"]);JP(Tz),JP(Rz);function Fz(t){return!!Rz[t]}function jz(t){return!!Oz[t]}const Pz=["x2","y2","latitude2","longitude2"];function Lz(t){return zz(t)!==t}function zz(t){switch(t){case"x2":return"x";case"y2":return"y";case"latitude2":return"latitude";case"longitude2":return"longitude"}return t}function Bz(t){switch(t){case"x":return"x2";case"y":return"y2";case"latitude":return"latitude2";case"longitude":return"longitude2"}}const{x:Uz,y:Wz,x2:Vz,y2:qz,latitude:Hz,longitude:Gz,latitude2:$z,longitude2:Kz}=wz,Xz=(JP(wz),b(wz,["x","y","x2","y2","latitude","longitude","latitude2","longitude2"])),Yz=JP(Xz),Jz={x:1,y:1},Zz=JP(Jz);function Qz(t){return"x"===t?"width":"height"}function tB(t){return"width"===t?"x":"y"}const{text:eB,tooltip:nB,href:rB,url:iB,detail:aB,key:oB,order:sB}=Xz,uB=b(Xz,["text","tooltip","href","url","detail","key","order"]),cB=JP(uB);const lB=Object.assign(Object.assign({},Jz),uB),fB=JP(lB);function dB(t){return!!lB[t]}function hB(t,e){return function(t){switch(t){case nz:case rz:case iz:case hz:case pz:case mz:case gz:case dz:case sz:case uz:case cz:case lz:case $L:case HL:case GL:return pB;case KL:case XL:case ZL:case QL:return gB;case YL:case JL:case tz:case ez:return{area:"always",bar:"always",image:"always",rect:"always",rule:"always",circle:"binned",point:"binned",square:"binned",tick:"binned",line:"binned",trail:"binned"};case oz:return{point:"always",tick:"always",rule:"always",circle:"always",square:"always",bar:"always",text:"always",line:"always",trail:"always"};case az:return{point:"always",geoshape:"always"};case fz:return{text:"always"};case vz:return{image:"always"}}}(t)[e]}const pB={area:"always",bar:"always",circle:"always",geoshape:"always",image:"always",line:"always",rule:"always",point:"always",rect:"always",square:"always",trail:"always",text:"always",tick:"always"},{geoshape:mB}=pB,gB=b(pB,["geoshape"]);function vB(t){switch(t){case KL:case XL:case oz:case lz:case sz:case uz:case cz:case YL:case JL:return;case $L:case HL:case GL:case az:case fz:case mz:case gz:case vz:return"discrete";case nz:case rz:case iz:return"flexible";case ZL:case QL:case tz:case ez:case hz:case pz:case dz:return}}function yB(t){return`Invalid specification ${JSON.stringify(t)}. Make sure the specification includes at least one of the following properties: "mark", "layer", "facet", "hconcat", "vconcat", "concat", or "repeat".`}const bB='Autosize "fit" only works for single views and layered views.';function xB(t){return`${"width"==t?"Width":"Height"} "container" only works for single views and layered views.`}function wB(t){return`${"width"==t?"Width":"Height"} "container" only works well with autosize "fit" or "fit-x".`}function kB(t){return t?`Dropping "fit-${t}" because spec has discrete ${Qz(t)}.`:'Dropping "fit" because spec has discrete size.'}function _B(t){return`Cannot project a selection on encoding channel "${t}", which has no field.`}function EB(t,e){return`Cannot project a selection on encoding channel "${t}" as it uses an aggregate function ("${e}").`}function OB(t){return`The "nearest" transform is not supported for ${t} marks.`}function SB(t){return`Selection not supported for ${t} yet.`}function CB(t){return`Cannot find a selection named "${t}".`}const AB="Scale bindings are currently only supported for scales with unbinned, continuous domains.",NB="Legend bindings are only supported for selections over an individual field or encoding channel.";function TB(t){return`Cannot define and lookup the "${t}" selection in the same view. `+"Try moving the lookup into a second, layered view?"}function IB(t){return`Unknown repeated value "${t}".`}function DB(t){return`The "columns" property cannot be used when "${t}" has nested row/column.`}const MB="Axes cannot be shared in concatenated views yet (https://github.com/vega/vega-lite/issues/2415).",RB="Axes cannot be shared in repeated views yet (https://github.com/vega/vega-lite/issues/2415).";function FB(t){return`Unrecognized parse "${t}".`}function jB(t,e,n){return`An ancestor parsed field "${t}" as ${n} but a child wants to parse the field as ${e}.`}function PB(t){return`Ignoring an invalid transform: ${BP(t)}.`}const LB='If "from.fields" is not specified, "as" has to be a string that specifies the key to be used for the data from the secondary source.';function zB(t){return`Layer's shared ${t.join(",")} channel ${1===t.length?"is":"are"} overriden.`}function BB(t){const{parentProjection:e,projection:n}=t;return`Layer's shared projection ${BP(e)} is overridden by a child projection ${BP(n)}.`}function UB(t,e,n){return`Channel ${t} is a ${e}. Converted to {value: ${BP(n)}}.`}function WB(t){return`Invalid field type "${t}".`}function VB(t,e,n){return`A ${n.scaleType?`${n.scaleType} scale`:n.zeroFalse?"scale with zero=false":"scale with custom domain that excludes zero"} is used to encode ${t}'s ${e}. This can be misleading as the ${"x"===e?"width":"height"} of the ${t} can be arbitrary based on the scale domain. You may want to use point mark instead.`}function qB(t,e){return`Invalid field type "${t}" for aggregate: "${e}", using "quantitative" instead.`}function HB(t){return`Invalid aggregation operator "${t}".`}function GB(t,e){return`Missing type for channel "${t}", using "${e}" instead.`}function $B(t,e){const{fill:n,stroke:r}=e;return`Dropping color ${t} as the plot also has ${n&&r?"fill and stroke":n?"fill":"stroke"}.`}function KB(t,e){return`Dropping ${BP(t)} from channel "${e}" since it does not contain data field or value.`}function XB(t,e,n){return`${t}-encoding with type ${e} is deprecated. Replacing with ${n}-encoding.`}const YB="Line marks cannot encode size with a non-groupby field. You may want to use trail marks instead.";function JB(t,e,n){return`${t} dropped as it is incompatible with "${e}"${n?` when ${n}`:""}.`}function ZB(t){return`${t}-encoding is dropped as ${t} is not a valid encoding channel.`}function QB(t){return`${t} encoding should be discrete (ordinal / nominal / binned).`}function tU(t){return`Facet encoding dropped as ${t.join(" and ")} ${t.length>1?"are":"is"} also specified.`}function eU(t,e){return`Using discrete channel "${t}" to encode "${e}" field can be misleading as it does not encode ${"ordinal"===e?"order":"magnitude"}.`}function nU(t,e){return`Line mark is for continuous lines and thus cannot be used with ${t&&e?"x2 and y2":t?"x2":"y2"}. We will use the rule mark (line segments) instead.`}function rU(t,e){return`Specified orient "${t}" overridden with "${e}".`}const iU="Custom domain scale cannot be unioned with default field-based domain.",aU='Scale\'s "rangeStep" is deprecated and will be removed in Vega-Lite 5.0. Please use "width"/"height": {"step": ...} instead. See https://vega.github.io/vega-lite/docs/size.html.';function oU(t){return`Cannot use the scale property "${t}" with non-color channel.`}function sU(t){return`Using unaggregated domain with raw field has no effect (${BP(t)}).`}function uU(t){return`Unaggregated domain not applicable for "${t}" since it produces values outside the origin domain of the source data.`}function cU(t){return`Unaggregated domain is currently unsupported for log scale (${BP(t)}).`}function lU(t){return`Cannot apply size to non-oriented mark "${t}".`}function fU(t,e,n){return`Channel "${t}" does not work with "${e}" scale. We are using "${n}" scale instead.`}function dU(t,e){return`FieldDef does not work with "${t}" scale. We are using "${e}" scale instead.`}function hU(t,e,n){return`${n}-scale's "${e}" is dropped as it does not work with ${t} scale.`}function pU(t,e){return`Scale type "${e}" does not work with mark "${t}".`}function mU(t){return`The step for "${t}" is dropped because the ${"width"===t?"x":"y"} is continuous.`}function gU(t,e,n,r){return`Conflicting ${e.toString()} property "${t.toString()}" (${BP(n)} and ${BP(r)}). Using ${BP(n)}.`}function vU(t,e,n,r){return`Conflicting ${e.toString()} property "${t.toString()}" (${BP(n)} and ${BP(r)}). Using the union of the two domains.`}function yU(t){return`Setting the scale to be independent for "${t}" means we also have to set the guide (axis or legend) to be independent.`}function bU(t){return`Dropping sort property ${BP(t)} as unioned domains only support boolean or op "count", "min", and "max".`}const xU="Unable to merge domains.",wU="Domains that should be unioned has conflicting sort properties. Sort will be set to true.",kU="Invalid channel for axis.";function _U(t){return`Cannot stack "${t}" if there is already "${t}2".`}function EU(t){return`Cannot stack non-linear scale (${t}).`}function OU(t){return`Stacking is applied even though the aggregate function is non-summative ("${t}").`}function SU(t,e){return`Invalid ${t}: ${BP(e)}.`}function CU(t){return`Time unit "${t}" is not supported. We are replacing it with ${oL(t,"day","date")}.`}function AU(t){return`Dropping day from datetime ${BP(t)} as day cannot be combined with other units.`}function NU(t,e){return`${e?"extent ":""}${e&&t?"and ":""}${t?"center ":""}${e&&t?"are ":"is "}not needed when data are aggregated.`}function TU(t,e,n){return`${t} is not usually used with ${e} for ${n}.`}function IU(t,e){return`Continuous axis should not have customized aggregation function ${t}; ${e} already agregates the axis.`}function DU(t,e){return`Center is not needed to be specified in ${e} when extent is ${t}.`}function MU(t){return`1D error band does not support ${t}.`}function RU(t){return`Channel ${t} is required for "binned" bin.`}function FU(t){return`Domain for ${t} is required for threshold scale.`}const jU=m,PU=function(t,e){var n=t||0;return{level:function(t){return arguments.length?(n=+t,this):n},error:function(){return n>=1&&gP(e||"error","ERROR",arguments),this},warn:function(){return n>=2&&gP(e||"warn","WARN",arguments),this},info:function(){return n>=3&&gP(e||"log","INFO",arguments),this},debug:function(){return n>=4&&gP(e||"log","DEBUG",arguments),this}}}(2);let LU=PU;function zU(){return LU=PU}function BU(...t){LU.warn(...t)}const UU=2006;function WU(t){return!!(t&&(t.year||t.quarter||t.month||t.date||t.day||t.hours||t.minutes||t.seconds||t.milliseconds))}const VU=["january","february","march","april","may","june","july","august","september","october","november","december"],qU=VU.map(t=>t.substr(0,3)),HU=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"],GU=HU.map(t=>t.substr(0,3));function $U(t,e=!1,n=!1){const r=[];if(e&&void 0!==t.day&&JP(t).length>1&&(BU(jU.droppedDay(t)),delete(t=PP(t)).day),void 0!==t.year?r.push(t.year):void 0!==t.day?r.push(UU):r.push(0),void 0!==t.month){const n=e?function(t){if(OP(t))return(t-1).toString();{const e=t.toLowerCase(),n=VU.indexOf(e);if(-1!==n)return n+"";const r=e.substr(0,3),i=qU.indexOf(r);if(-1!==i)return i+"";throw new Error(jU.invalidTimeUnit("month",t))}}(t.month):t.month;r.push(n)}else if(void 0!==t.quarter){const n=e?function(t){if(OP(t))return t>4&&BU(jU.invalidTimeUnit("quarter",t)),(t-1).toString();throw new Error(jU.invalidTimeUnit("quarter",t))}(t.quarter):t.quarter;r.push(n+"*3")}else r.push(0);if(void 0!==t.date)r.push(t.date);else if(void 0!==t.day){const n=e?function(t){if(OP(t))return t%7+"";{const e=t.toLowerCase(),n=HU.indexOf(e);if(-1!==n)return n+"";const r=e.substr(0,3),i=GU.indexOf(r);if(-1!==i)return i+"";throw new Error(jU.invalidTimeUnit("day",t))}}(t.day):t.day;r.push(n+"+1")}else r.push(1);for(const e of["hours","minutes","seconds","milliseconds"]){const n=t[e];r.push(void 0===n?0:n)}const i=r.join(", ");return n?t.utc?new Function(`return +new Date(Date.UTC(${i}))`)():new Function(`return +new Date(${i})`)():t.utc?`utc(${i})`:`datetime(${i})`}var KU;!function(t){t.YEAR="year",t.MONTH="month",t.DAY="day",t.DATE="date",t.HOURS="hours",t.MINUTES="minutes",t.SECONDS="seconds",t.MILLISECONDS="milliseconds",t.YEARMONTH="yearmonth",t.YEARMONTHDATE="yearmonthdate",t.YEARMONTHDATEHOURS="yearmonthdatehours",t.YEARMONTHDATEHOURSMINUTES="yearmonthdatehoursminutes",t.YEARMONTHDATEHOURSMINUTESSECONDS="yearmonthdatehoursminutesseconds",t.MONTHDATE="monthdate",t.MONTHDATEHOURS="monthdatehours",t.HOURSMINUTES="hoursminutes",t.HOURSMINUTESSECONDS="hoursminutesseconds",t.MINUTESSECONDS="minutesseconds",t.SECONDSMILLISECONDS="secondsmilliseconds",t.QUARTER="quarter",t.YEARQUARTER="yearquarter",t.QUARTERMONTH="quartermonth",t.YEARQUARTERMONTH="yearquartermonth",t.UTCYEAR="utcyear",t.UTCMONTH="utcmonth",t.UTCDAY="utcday",t.UTCDATE="utcdate",t.UTCHOURS="utchours",t.UTCMINUTES="utcminutes",t.UTCSECONDS="utcseconds",t.UTCMILLISECONDS="utcmilliseconds",t.UTCYEARMONTH="utcyearmonth",t.UTCYEARMONTHDATE="utcyearmonthdate",t.UTCYEARMONTHDATEHOURS="utcyearmonthdatehours",t.UTCYEARMONTHDATEHOURSMINUTES="utcyearmonthdatehoursminutes",t.UTCYEARMONTHDATEHOURSMINUTESSECONDS="utcyearmonthdatehoursminutesseconds",t.UTCMONTHDATE="utcmonthdate",t.UTCMONTHDATEHOURS="utcmonthdatehours",t.UTCHOURSMINUTES="utchoursminutes",t.UTCHOURSMINUTESSECONDS="utchoursminutesseconds",t.UTCMINUTESSECONDS="utcminutesseconds",t.UTCSECONDSMILLISECONDS="utcsecondsmilliseconds",t.UTCQUARTER="utcquarter",t.UTCYEARQUARTER="utcyearquarter",t.UTCQUARTERMONTH="utcquartermonth",t.UTCYEARQUARTERMONTH="utcyearquartermonth"}(KU||(KU={}));const XU={year:1,quarter:1,month:1,day:1,date:1,hours:1,minutes:1,seconds:1,milliseconds:1},YU=JP(XU);const JU={utcyear:1,utcquarter:1,utcmonth:1,utcday:1,utcdate:1,utchours:1,utcminutes:1,utcseconds:1,utcmilliseconds:1};const ZU={utcyearquarter:1,utcyearquartermonth:1,utcyearmonth:1,utcyearmonthdate:1,utcyearmonthdatehours:1,utcyearmonthdatehoursminutes:1,utcyearmonthdatehoursminutesseconds:1,utcquartermonth:1,utcmonthdate:1,utcmonthdatehours:1,utchoursminutes:1,utchoursminutesseconds:1,utcminutesseconds:1,utcsecondsmilliseconds:1},QU=Object.assign(Object.assign({},JU),ZU);const tW=Object.assign(Object.assign(Object.assign(Object.assign({},XU),JU),{yearquarter:1,yearquartermonth:1,yearmonth:1,yearmonthdate:1,yearmonthdatehours:1,yearmonthdatehoursminutes:1,yearmonthdatehoursminutesseconds:1,quartermonth:1,monthdate:1,monthdatehours:1,hoursminutes:1,hoursminutesseconds:1,minutesseconds:1,secondsmilliseconds:1}),ZU),eW=(JP(tW),{"year-month":"%b %Y ","year-month-date":"%b %d, %Y "});function nW(t){return YU.reduce((e,n)=>rW(t,n)?[...e,n]:e,[])}function rW(t,e){const n=t.indexOf(e);return n>-1&&(e!==KU.SECONDS||0===n||"i"!==t.charAt(n-1))}function iW(t,e,{end:n}={end:!1}){const r=iL(e),i=function(t){return!!QU[t]}(t)?"utc":"";let a;const o=YU.reduce((e,n)=>(rW(t,n)&&(e[n]=function(t){return t===KU.QUARTER?`(${i}quarter(${r})-1)`:`${i}${t}(${r})`}(n),a=n),e),{});return n&&(o[a]+="+1"),$U(o)}function aW(t,e,n){if(!t)return;const r=function(t){if(!t)return;const e=nW(t);return`timeUnitSpecifier(${DP()(e)}, ${DP()(eW)})`}(t);return n?`utcFormat(${e}, ${r})`:`timeFormat(${e}, ${r})`}function oW(t){return"day"!==t&&t.indexOf("day")>=0?(BU(jU.dayReplacedWithDate(t)),oL(t,"day","date")):t}function sW(t){return t&&!!t.field&&void 0!==t.equal}function uW(t){return t&&!!t.field&&void 0!==t.lt}function cW(t){return t&&!!t.field&&void 0!==t.lte}function lW(t){return t&&!!t.field&&void 0!==t.gt}function fW(t){return t&&!!t.field&&void 0!==t.gte}function dW(t){return!!(t&&t.field&&lP(t.range)&&2===t.range.length)}function hW(t){return t&&!!t.field&&(lP(t.oneOf)||lP(t.in))}function pW(t){return hW(t)||sW(t)||dW(t)||uW(t)||lW(t)||cW(t)||fW(t)}function mW(t,e){return tq(t,{timeUnit:e,time:!0})}function gW(t,e=!0){const{field:n,timeUnit:r}=t,i=r?"time("+iW(r,n)+")":PV(t,{expr:"datum"});if(sW(t))return i+"==="+mW(t.equal,r);if(uW(t)){return`${i}<${mW(t.lt,r)}`}if(lW(t)){return`${i}>${mW(t.gt,r)}`}if(cW(t)){return`${i}<=${mW(t.lte,r)}`}if(fW(t)){return`${i}>=${mW(t.gte,r)}`}if(hW(t))return`indexof([${function(t,e){return t.map(t=>mW(t,e))}(t.oneOf,r).join(",")}], ${i}) !== -1`;if(function(t){return t&&!!t.field&&void 0!==t.valid}(t))return vW(i,t.valid);if(dW(t)){const n=t.range[0],a=t.range[1];if(null!==n&&null!==a&&e)return"inrange("+i+", ["+mW(n,r)+", "+mW(a,r)+"])";const o=[];return null!==n&&o.push(`${i} >= ${mW(n,r)}`),null!==a&&o.push(`${i} <= ${mW(a,r)}`),o.length>0?o.join(" && "):"true"}throw new Error(`Invalid field predicate: ${JSON.stringify(t)}`)}function vW(t,e=!0){return e?`isValid(${t}) && isFinite(+${t})`:`!isValid(${t}) || !isFinite(+${t})`}function yW(t){return pW(t)&&t.timeUnit?Object.assign(Object.assign({},t),{timeUnit:oW(t.timeUnit)}):t}const bW={quantitative:1,ordinal:1,temporal:1,nominal:1,geojson:1};const xW="quantitative",wW="ordinal",kW="temporal",_W="nominal",EW="geojson";var OW;!function(t){t.LINEAR="linear",t.LOG="log",t.POW="pow",t.SQRT="sqrt",t.SYMLOG="symlog",t.TIME="time",t.UTC="utc",t.QUANTILE="quantile",t.QUANTIZE="quantize",t.THRESHOLD="threshold",t.BIN_ORDINAL="bin-ordinal",t.ORDINAL="ordinal",t.POINT="point",t.BAND="band"}(OW||(OW={}));const SW={linear:"numeric",log:"numeric",pow:"numeric",sqrt:"numeric",symlog:"numeric",time:"time",utc:"time",ordinal:"ordinal","bin-ordinal":"bin-ordinal",point:"ordinal-position",band:"ordinal-position",quantile:"discretizing",quantize:"discretizing",threshold:"discretizing"},CW=JP(SW);function AW(t,e){const n=SW[t],r=SW[e];return n===r||"ordinal-position"===n&&"time"===r||"ordinal-position"===r&&"time"===n}const NW={linear:0,log:1,pow:1,sqrt:1,symlog:1,time:0,utc:0,point:10,band:11,ordinal:0,"bin-ordinal":0,quantile:0,quantize:0,threshold:0};function TW(t){return NW[t]}const IW=["linear","log","pow","sqrt","symlog","time","utc"],DW=SP(IW),MW=SP(["quantile","quantize","threshold"]),RW=SP(IW.concat(["quantile","quantize","threshold"])),FW=SP(["ordinal","bin-ordinal","point","band"]);function jW(t){return t in FW}function PW(t){return t in RW}function LW(t){return t in DW}function zW(t){return t in MW}function BW(t){var e;return null===(e=t)||void 0===e?void 0:e.selection}const UW={type:1,domain:1,align:1,range:1,scheme:1,bins:1,reverse:1,round:1,clamp:1,nice:1,base:1,exponent:1,constant:1,interpolate:1,zero:1,padding:1,paddingInner:1,paddingOuter:1},{type:WW,domain:VW,range:qW,scheme:HW}=UW,GW=(JP(UW),b(UW,["type","domain","range","scheme"])),$W=JP(GW);!function(){var t;const e={};for(const n of Sz)for(const r of JP(bW))for(const i of CW){const a=ZW(n,r);JW(n,i)&&YW(i,r)&&(e[a]=null!==(t=e[a])&&void 0!==t?t:[],e[a].push(i))}}();function KW(t,e){switch(e){case"type":case"domain":case"reverse":case"range":return!0;case"scheme":case"interpolate":return!VP(["point","band","identity"],t);case"bins":return!VP(["point","band","identity","ordinal"],t);case"round":return LW(t)||"band"===t||"point"===t;case"padding":return LW(t)||VP(["point","band"],t);case"paddingOuter":case"align":return VP(["point","band"],t);case"paddingInner":return"band"===t;case"clamp":return LW(t);case"nice":return LW(t)||"quantize"===t||"threshold"===t;case"exponent":return"pow"===t;case"base":return"log"===t;case"constant":return"symlog"===t;case"zero":return PW(t)&&!VP(["log","time","utc","threshold","quantile"],t)}}function XW(t,e){switch(e){case"interpolate":case"scheme":return kz(t)?void 0:jU.cannotUseScalePropertyWithNonColor(t);case"align":case"type":case"bins":case"domain":case"range":case"base":case"exponent":case"constant":case"nice":case"padding":case"paddingInner":case"paddingOuter":case"reverse":case"round":case"clamp":case"zero":return}}function YW(t,e){return VP([wW,_W],e)?void 0===t||jW(t):e===kW?VP([OW.TIME,OW.UTC,void 0],t):e!==xW||VP([OW.LOG,OW.POW,OW.SQRT,OW.SYMLOG,OW.QUANTILE,OW.QUANTIZE,OW.THRESHOLD,OW.LINEAR,void 0],t)}function JW(t,e){switch(t){case KL:case XL:return LW(e)||VP(["band","point"],e);case oz:case lz:case sz:case uz:case cz:return LW(e)||zW(e)||VP(["band","point"],e);case nz:case rz:case iz:return"band"!==e;case az:return"ordinal"===e}return!1}function ZW(t,e){return t+"_"+e}function QW(t){const{anchor:e,frame:n,offset:r,orient:i,color:a}=t,o=b(t,["anchor","frame","offset","orient","color"]);return{mark:Object.assign(Object.assign({},o),a?{fill:a}:{}),nonMark:Object.assign(Object.assign(Object.assign(Object.assign({},e?{anchor:e}:{}),n?{frame:n}:{}),r?{offset:r}:{}),i?{orient:i}:{})}}function tV(t){return dP(t)||lP(t)&&dP(t[0])}const eV=" – ";function nV(t){var e;return[].concat(t.type,null!==(e=t.style)&&void 0!==e?e:[])}function rV(t,e,n){return uL(e[t],iV(t,e,n))}function iV(t,e,n,{vgChannel:r}={}){return uL(r?aV(t,e,n.style):void 0,aV(t,e,n.style),r?n[e.type][r]:void 0,n[e.type][t],r?n.mark[r]:n.mark[t])}function aV(t,e,n){const r=nV(e);let i;for(const e of r){const r=n[e],a=t;r&&void 0!==r[a]&&(i=r[a])}return i}function oV(t,e,n,r){if(QV(t)){const i=RV(t)&&t.scale&&t.scale.type===OW.UTC;return{signal:fV(PV(t,{expr:n}),t.timeUnit,e,r.timeFormat,i,!0)}}{const i=sV(t,e,r);if(iq(t.bin)){return{signal:lV(PV(t,{expr:n}),PV(t,{expr:n,binSuffix:"end"}),i,r)}}return"quantitative"===t.type||i?{signal:`${uV(PV(t,{expr:n,binSuffix:"range"}),i)}`}:{signal:`''+${PV(t,{expr:n})}`}}}function sV(t,e,n){return e||(t.type===xW?n.numberFormat:void 0)}function uV(t,e){return`format(${t}, "${e||""}")`}function cV(t,e,n){return uV(t,null!==e&&void 0!==e?e:n.numberFormat)}function lV(t,e,n,r){return`${vW(t,!1)} ? "null" : ${cV(t,n,r)} + "${eV}" + ${cV(e,n,r)}`}function fV(t,e,n,r,i,a=!1){return!e||n?(n=null!==n&&void 0!==n?n:r)||a?`${i?"utc":"time"}Format(${t}, '${n}')`:void 0:aW(e,t,i)}function dV(t,e){return xP(t).reduce((t,n)=>{var r;return t.field.push(PV(n,e)),t.order.push(null!==(r=n.sort)&&void 0!==r?r:"ascending"),t},{field:[],order:[]})}function hV(t,e){const n=[...t];return e.forEach(t=>{for(const e of n)if(jP(e,t))return;n.push(t)}),n}function pV(t,e){return jP(t,e)||!e?t:t?[...xP(t),...xP(e)].join(", "):e}function mV(t,e){const n=t.value,r=e.value;if(null==n||null===r)return{explicit:t.explicit,value:null};if(tV(n)&&tV(r))return{explicit:t.explicit,value:pV(n,r)};if(!tV(n)&&!tV(r))return{explicit:t.explicit,value:hV(n,r)};throw new Error("It should never reach here")}const gV="mean",vV={x:1,y:1,color:1,fill:1,stroke:1,strokeWidth:1,size:1,shape:1,fillOpacity:1,strokeOpacity:1,opacity:1,text:1};function yV(t){return!!vV[t]}function bV(t){return!!t&&!!t.encoding}function xV(t){return!(!t||"count"!==t.op&&!t.field)}function wV(t){return!!t&&lP(t)}function kV(t){return!!t.row||!!t.column}function _V(t){return void 0!==t.facet}function EV(t){const{field:e,timeUnit:n,bin:r,aggregate:i}=t;return Object.assign(Object.assign(Object.assign(Object.assign({},n?{timeUnit:n}:{}),r?{bin:r}:{}),i?{aggregate:i}:{}),{field:e})}function OV(t){return IV(t)&&!!t.sort}function SV(t,e,n,r,i,{isMidPoint:a}={}){const{timeUnit:o,bin:s}=e;if(VP(["x","y"],t)){if(FV(e)&&void 0!==e.band)return e.band;if(o&&!n)return a?iV("timeUnitBandPosition",r,i):CL(r.type)?iV("timeUnitBand",r,i):0;if(iq(s))return CL(r.type)&&!a?1:.5}}function CV(t,e,n,r,i){return!!(iq(e.bin)||e.timeUnit&&IV(e)&&"temporal"===e.type)&&!!SV(t,e,n,r,i)}function AV(t){return!!t&&!!t.condition}function NV(t){return!!t&&!!t.condition&&!lP(t.condition)&&TV(t.condition)}function TV(t){return!(!t||!t.field&&"count"!==t.aggregate)}function IV(t){return!!t&&(!!t.field&&!!t.type||"count"===t.aggregate)}function DV(t){return TV(t)&&dP(t.field)}function MV(t){return t&&"value"in t&&void 0!==t.value}function RV(t){return!(!t||!t.scale&&!t.sort)}function FV(t){return!(!t||!t.axis&&!t.stack&&!t.impute&&void 0===t.band)}function jV(t){return!!t&&!!t.format}function PV(t,e={}){var n,r,i;let a=t.field;const o=e.prefix;let s=e.suffix,u="";if(function(t){return"count"===t.aggregate}(t))a=function(t){return function(t){return 0===t.indexOf("__")}(t)?t:`__${t}`}("count");else{let o;if(!e.nofn)if(function(t){return!!t.op}(t))o=t.op;else{const{bin:c,aggregate:l,timeUnit:f}=t;iq(c)?(o=rq(c),s=(null!==(n=e.binSuffix)&&void 0!==n?n:"")+(null!==(r=e.suffix)&&void 0!==r?r:"")):l?zL(l)?(u=`.${a}`,a=`argmax_${l.argmax}`):LL(l)?(u=`.${a}`,a=`argmin_${l.argmin}`):o=String(l):f&&(o=String(f),s=(!VP(["range","mid"],e.binSuffix)&&e.binSuffix||"")+(null!==(i=e.suffix)&&void 0!==i?i:""))}o&&(a=a?`${o}_${a}`:o)}return s&&(a=`${a}_${s}`),o&&(a=`${o}_${a}`),e.forAs?a:e.expr?function(t,e="datum"){return`${e}[${hP(cP(t).join("."))}]`}(a,e.expr)+u:aL(a)+u}function LV(t){switch(t.type){case"nominal":case"ordinal":case"geojson":return!0;case"quantitative":return!!t.bin;case"temporal":return!1}throw new Error(jU.invalidFieldType(t.type))}function zV(t){return!LV(t)}const BV=(t,e)=>{switch(e.fieldTitle){case"plain":return t.field;case"functional":return function(t){const{aggregate:e,bin:n,timeUnit:r,field:i}=t;if(zL(e))return`${i} for argmax(${e.argmax})`;if(LL(e))return`${i} for argmin(${e.argmin})`;const a=e||r||iq(n)&&"bin";return a?a.toUpperCase()+"("+i+")":i}(t);default:return function(t,e){const{field:n,bin:r,timeUnit:i,aggregate:a}=t;if("count"===a)return e.countTitle;if(iq(r))return`${n} (binned)`;if(i)return`${n} (${nW(i).join("-")})`;return a?zL(a)?`${n} for max ${a.argmax}`:LL(a)?`${n} for min ${a.argmin}`:`${rL(a)} of ${n}`:n}(t,e)}};let UV=BV;function WV(t){UV=t}function VV(t,e,{allowDisabling:n,includeDefault:r=!0}){var i,a;const o=(null!==(i=qV(t))&&void 0!==i?i:{}).title,s=r?HV(t,e):void 0;return n?uL(o,t.title,s):null!==(a=null!==o&&void 0!==o?o:t.title)&&void 0!==a?a:s}function qV(t){return FV(t)&&t.axis?t.axis:function(t){return!!t&&!!t.legend}(t)&&t.legend?t.legend:function(t){return!!t&&!!t.header}(t)&&t.header?t.header:void 0}function HV(t,e){return UV(t,e)}function GV(t){var e;if(jV(t)&&t.format)return t.format;return(null!==(e=qV(t))&&void 0!==e?e:{}).format}function $V(t){return TV(t)?t:NV(t)?t.condition:void 0}function KV(t){return TV(t)?t:NV(t)?t.condition:void 0}function XV(t,e){if(dP(t)||OP(t)||EP(t)){const n=dP(t)?"string":OP(t)?"number":"boolean";return BU(jU.primitiveChannelDef(e,n,t)),{value:t}}return TV(t)?YV(t,e):NV(t)?Object.assign(Object.assign({},t),{condition:YV(t.condition,e)}):t}function YV(t,e){const{aggregate:n,timeUnit:r,bin:i,field:a}=t,o=Object.assign({},t);if(!n||BL(n)||zL(n)||LL(n)||(BU(jU.invalidAggregate(n)),delete o.aggregate),r&&(o.timeUnit=oW(r)),a&&(o.field=`${a}`),iq(i)&&(o.bin=JV(i,e)),aq(i)&&!VP(Zz,e)&&BU(`Channel ${e} should not be used with "binned" bin`),IV(o)){const{type:t}=o,e=function(t){if(t)switch(t=t.toLowerCase()){case"q":case xW:return"quantitative";case"t":case kW:return"temporal";case"o":case wW:return"ordinal";case"n":case _W:return"nominal";case EW:return"geojson"}}(t);t!==e&&(o.type=e),"quantitative"!==t&&WL(n)&&(BU(jU.invalidFieldTypeForCountAggregate(t,n)),o.type="quantitative")}else if(!Lz(e)){const t=function(t,e){if(t.timeUnit)return"temporal";if(iq(t.bin))return"quantitative";switch(vB(e)){case"continuous":return"quantitative";case"discrete":case"flexible":return"nominal";default:return"quantitative"}}(o,e);BU(jU.missingFieldType(e,t)),o.type=t}if(IV(o)){const{compatible:t,warning:n}=function(t,e){const n=t.type;if("geojson"===n&&"shape"!==e)return{compatible:!1,warning:`Channel ${e} should not be used with a geojson data.`};switch(e){case"row":case"column":case"facet":return zV(t)?{compatible:!1,warning:jU.facetChannelShouldBeDiscrete(e)}:ZV;case"x":case"y":case"color":case"fill":case"stroke":case"text":case"detail":case"key":case"tooltip":case"href":case"url":return ZV;case"longitude":case"longitude2":case"latitude":case"latitude2":return n!==xW?{compatible:!1,warning:`Channel ${e} should be used with a quantitative field only, not ${t.type} field.`}:ZV;case"opacity":case"fillOpacity":case"strokeOpacity":case"strokeWidth":case"size":case"x2":case"y2":return"nominal"!==n||t.sort?ZV:{compatible:!1,warning:`Channel ${e} should not be used with an unsorted discrete field.`};case"shape":return VP(["ordinal","nominal","geojson"],t.type)?ZV:{compatible:!1,warning:"Shape channel should be used with only either discrete or geojson data."};case"order":return"nominal"!==t.type||"sort"in t?ZV:{compatible:!1,warning:"Channel order is inappropriate for nominal field, which has no inherent order."}}throw new Error("channelCompatability not implemented for channel "+e)}(o,e);t||BU(n)}if(OV(o)&&dP(o.sort)){const{sort:t}=o;if(yV(t))return Object.assign(Object.assign({},o),{sort:{encoding:t}});const e=t.substr(1);if("-"===t.charAt(0)&&yV(e))return Object.assign(Object.assign({},o),{sort:{encoding:e,order:"descending"}})}return o}function JV(t,e){return EP(t)?{maxbins:uq(e)}:"binned"===t?{binned:!0}:t.maxbins||t.step?t:Object.assign(Object.assign({},t),{maxbins:uq(e)})}const ZV={compatible:!0};function QV(t){const e=qV(t),n=e&&e.formatType||jV(t)&&t.formatType;return"time"===n||!n&&function(t){return"temporal"===t.type||!!t.timeUnit}(t)}function tq(t,{timeUnit:e,type:n,time:r,undefinedIfExprNotRequired:i}){let a;return WU(t)?a=$U(t,!0):(dP(t)||OP(t))&&(e||"temporal"===n)&&(a=function(t){return!!XU[t]}(e)?$U({[e]:t},!0):function(t){return!!JU[t]}(e)?tq(t,{timeUnit:function(t){return t.substr(3)}(e)}):`datetime(${JSON.stringify(t)})`),a?r?`time(${a})`:a:i?void 0:JSON.stringify(t)}function eq(t,e){const{timeUnit:n,type:r}=t;return e.map(t=>{const e=tq(t,{timeUnit:n,type:r,undefinedIfExprNotRequired:!0});return void 0!==e?{signal:e}:t})}function nq(t,e){return iq(t.bin)?dB(e)&&VP(["ordinal","nominal"],t.type):(console.warn("Only use this method with binned field defs"),!1)}function rq(t){return EP(t)&&(t=JV(t,void 0)),"bin"+JP(t).map(e=>sq(t[e])?tL(`_${e}_${Object.entries(t[e])}`):tL(`_${e}_${t[e]}`)).join("")}function iq(t){return!0===t||oq(t)&&!t.binned}function aq(t){return"binned"===t||oq(t)&&!0===t.binned}function oq(t){return fP(t)}function sq(t){var e;return null===(e=t)||void 0===e?void 0:e.selection}function uq(t){switch(t){case HL:case GL:case oz:case nz:case rz:case iz:case lz:case sz:case uz:case cz:case az:return 6;default:return 10}}function cq(t,e){const n=t&&t[e];return!!n&&(lP(n)?qP(n,t=>!!t.field):TV(n)||NV(n))}function lq(t){return qP(Sz,e=>{if(cq(t,e)){const n=t[e];if(lP(n))return qP(n,t=>!!t.aggregate);{const t=$V(n);return t&&!!t.aggregate}}return!1})}function fq(t,e){const n=[],r=[],i=[],a=[],o={};return hq(t,(s,u)=>{if(TV(s)){const{field:c,aggregate:l,timeUnit:f,bin:d}=s,h=b(s,["field","aggregate","timeUnit","bin"]);if(l||f||d){const t=qV(s),p=t&&t.title;let m=PV(s,{forAs:!0});const g=Object.assign(Object.assign(Object.assign({},p?[]:{title:VV(s,e,{allowDisabling:!0})}),h),{field:m}),v="x"===u||"y"===u;if(l){let t;if(zL(l)?(t="argmax",m=PV({op:"argmax",field:l.argmax},{forAs:!0}),g.field=`${m}.${c}`):LL(l)?(t="argmin",m=PV({op:"argmin",field:l.argmin},{forAs:!0}),g.field=`${m}.${c}`):"boxplot"!==l&&"errorbar"!==l&&"errorband"!==l&&(t=l),t){const e={op:t,as:m};c&&(e.field=c),a.push(e)}}else if(n.push(m),IV(s)&&iq(d)){if(r.push({bin:d,field:c,as:m}),n.push(PV(s,{binSuffix:"end"})),nq(s,u)&&n.push(PV(s,{binSuffix:"range"})),v){const t={field:m+"_end"};o[u+"2"]=t}g.bin="binned",Lz(u)||(g.type="quantitative")}else if(f){i.push({timeUnit:f,field:c,as:m});const t=IV(s)&&s.type!==kW&&"time";t&&("text"===u||"tooltip"===u?g.formatType=t:!function(t){return!!Xz[t]}(u)?v&&(g.axis=Object.assign({formatType:t},g.axis)):g.legend=Object.assign({formatType:t},g.legend))}o[u]=g}else n.push(c),o[u]=t[u]}else o[u]=t[u]}),{bins:r,timeUnits:i,aggregate:a,groupby:n,encoding:o}}function dq(t,e){const n=e.type;return JP(t).reduce((r,i)=>{var a;if(!jz(i))return BU(jU.invalidEncodingChannel(i)),r;if(!function(t,e,n){const r=hB(e,n);if(!r)return!1;if("binned"===r){const n=t["x2"===e?"x":"y"];return!!(TV(n)&&TV(t[e])&&aq(n.bin))}return!0}(t,i,n))return BU(jU.incompatibleChannel(i,n)),r;if("size"===i&&"line"===n){if(null===(a=KV(t[i]))||void 0===a?void 0:a.aggregate)return BU(jU.LINE_WITH_VARYING_SIZE),r}if("color"===i&&(e.filled?"fill"in t:"stroke"in t))return BU(jU.droppingColor("encoding",{fill:"fill"in t,stroke:"stroke"in t})),r;const o=t[i];if("detail"===i||"order"===i&&!lP(o)&&!MV(o)||"tooltip"===i&&lP(o))o&&(r[i]=(lP(o)?o:[o]).reduce((t,e)=>(TV(e)?t.push(YV(e,i)):BU(jU.emptyFieldDef(e,i)),t),[]));else{if("tooltip"===i&&null===o)r[i]=null;else if(!TV(o)&&!MV(o)&&!AV(o))return BU(jU.emptyFieldDef(o,i)),r;r[i]=XV(o,i)}return r},{})}function hq(t,e,n){if(t)for(const r of JP(t)){const i=t[r];lP(i)?i.forEach(t=>{e.call(n,t,r)}):e.call(n,i,r)}}function pq(t,e,n,r){return t?JP(t).reduce((n,i)=>{const a=t[i];return lP(a)?a.reduce((t,n)=>e.call(r,t,n,i),n):e.call(r,n,a,i)},n):n}function mq(t,e){return JP(e).reduce((n,r)=>{switch(r){case"x":case"y":case"href":case"url":case"x2":case"y2":case"latitude":case"longitude":case"latitude2":case"longitude2":case"text":case"shape":case"tooltip":return n;case"order":if("line"===t||"trail"===t)return n;case"detail":case"key":{const t=e[r];return(lP(t)||TV(t))&&(lP(t)?t:[t]).forEach(t=>{t.aggregate||n.push(PV(t,{}))}),n}case"size":if("trail"===t)return n;case"color":case"fill":case"stroke":case"opacity":case"fillOpacity":case"strokeOpacity":case"strokeWidth":{const t=KV(e[r]);return t&&!t.aggregate&&n.push(PV(t,{})),n}}},[])}function gq(t,e,n,r=!0){if("tooltip"in n)return{tooltip:n.tooltip};return{tooltip:[...t.map(({fieldPrefix:t,titlePrefix:n})=>({field:t+e.field,type:e.type,title:n+(r?" of "+e.field:"")})),...function(t){const e=[];for(const n of JP(t))if(cq(t,n)){const r=t[n],i=lP(r)?r:[r];for(const t of i)TV(t)?e.push(t):NV(t)&&e.push(t.condition)}return e}(n)]}}function vq(t){const{axis:e,title:n,field:r}=t;return e&&void 0!==e.title?void 0:uL(n,r)}function yq(t,e,n,r,i){const{scale:a,axis:o}=n;return({partName:s,mark:u,positionPrefix:c,endPositionPrefix:l,extraEncoding:f={}})=>{const d=vq(n);return bq(t,s,i,{mark:u,encoding:Object.assign(Object.assign(Object.assign({[e]:Object.assign(Object.assign(Object.assign({field:c+"_"+n.field,type:n.type},void 0!==d?{title:d}:{}),void 0!==a?{scale:a}:{}),void 0!==o?{axis:o}:{})},dP(l)?{[e+"2"]:{field:l+"_"+n.field,type:n.type}}:{}),r),f)})}}function bq(t,e,n,r){const{clip:i,color:a,opacity:o}=t,s=t.type;return t[e]||void 0===t[e]&&n[e]?[Object.assign(Object.assign({},r),{mark:Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},n[e]),i?{clip:i}:{}),a?{color:a}:{}),o?{opacity:o}:{}),NL(r.mark)?r.mark:{type:r.mark}),{style:`${s}-${e}`}),EP(t[e])?{}:t[e])})]:[]}function xq(t,e,n){const{encoding:r}=t,i="vertical"===e?"y":"x",a=r[i],o=r[i+"2"],s=r[i+"Error"],u=r[i+"Error2"];return{continuousAxisChannelDef:wq(a,n),continuousAxisChannelDef2:wq(o,n),continuousAxisChannelDefError:wq(s,n),continuousAxisChannelDefError2:wq(u,n),continuousAxis:i}}function wq(t,e){if(t&&t.aggregate){const{aggregate:n}=t,r=b(t,["aggregate"]);return n!==e&&BU(jU.errorBarContinuousAxisHasCustomizedAggregate(n,e)),r}return t}function kq(t,e){const{mark:n,encoding:r}=t;if(TV(r.x)&&zV(r.x)){if(TV(r.y)&&zV(r.y)){if(void 0===r.x.aggregate&&r.y.aggregate===e)return"vertical";if(void 0===r.y.aggregate&&r.x.aggregate===e)return"horizontal";if(r.x.aggregate===e&&r.y.aggregate===e)throw new Error("Both x and y cannot have aggregate");return NL(n)&&n.orient?n.orient:"vertical"}return"horizontal"}if(TV(r.y)&&zV(r.y))return"vertical";throw new Error("Need a valid continuous axis for "+e+"s")}const _q="boxplot",Eq=JP({box:1,median:1,outliers:1,rule:1,ticks:1}),Oq=new FL(_q,Cq);function Sq(t){return OP(t)?"tukey":t}function Cq(t,{config:e}){var n,r;const{mark:i,encoding:a,selection:o,projection:s}=t,u=b(t,["mark","encoding","selection","projection"]),c=NL(i)?i:{type:i};o&&BU(jU.selectionNotSupported("boxplot"));const l=null!==(n=c.extent)&&void 0!==n?n:e.boxplot.extent,f=uL(c.size,e.boxplot.size),d=Sq(l),{transform:h,continuousAxisChannelDef:p,continuousAxis:m,groupby:g,aggregate:v,encodingWithoutContinuousAxis:y,ticksOrient:x,boxOrient:w,customTooltipWithoutAggregatedField:k}=function(t,e,n){const r=kq(t,_q),{continuousAxisChannelDef:i,continuousAxis:a}=xq(t,r,_q),o=i.field,s=Sq(e),u=[...Aq(o),{op:"median",field:o,as:"mid_box_"+o},{op:"min",field:o,as:("min-max"===s?"lower_whisker_":"min_")+o},{op:"max",field:o,as:("min-max"===s?"upper_whisker_":"max_")+o}],c="min-max"===s||"tukey"===s?[]:[{calculate:`datum["upper_box_${o}"] - datum["lower_box_${o}"]`,as:"iqr_"+o},{calculate:`min(datum["upper_box_${o}"] + datum["iqr_${o}"] * ${e}, datum["max_${o}"])`,as:"upper_whisker_"+o},{calculate:`max(datum["lower_box_${o}"] - datum["iqr_${o}"] * ${e}, datum["min_${o}"])`,as:"lower_whisker_"+o}],l=t.encoding,f=a,d=(l[f],b(l,["symbol"==typeof f?f:f+""])),{customTooltipWithoutAggregatedField:h,filteredEncoding:p}=function(t){const{tooltip:e}=t,n=b(t,["tooltip"]);if(!e)return{filteredEncoding:t};let r,i;return lP(e)?(e.forEach(t=>{t.aggregate?(r||(r=[]),r.push(t)):(i||(i=[]),i.push(t))}),r&&(n.tooltip=r)):e.aggregate?n.tooltip=e:i=e,lP(i)&&1===i.length&&(i=i[0]),{customTooltipWithoutAggregatedField:i,filteredEncoding:n}}(d),{bins:m,timeUnits:g,aggregate:v,groupby:y,encoding:x}=fq(p,n);return{transform:[...m,...g,{aggregate:[...v,...u],groupby:y},...c],groupby:y,aggregate:v,continuousAxisChannelDef:i,continuousAxis:a,encodingWithoutContinuousAxis:x,ticksOrient:"vertical"===r?"horizontal":"vertical",boxOrient:r,customTooltipWithoutAggregatedField:h}}(t,l,e),{color:_,size:E}=y,O=b(y,["color","size"]),S=t=>yq(c,m,p,t,e.boxplot),C=S(O),A=S(y),N=S(Object.assign(Object.assign({},O),E?{size:E}:{})),T=gq([{fieldPrefix:"min-max"===d?"upper_whisker_":"max_",titlePrefix:"Max"},{fieldPrefix:"upper_box_",titlePrefix:"Q3"},{fieldPrefix:"mid_box_",titlePrefix:"Median"},{fieldPrefix:"lower_box_",titlePrefix:"Q1"},{fieldPrefix:"min-max"===d?"lower_whisker_":"min_",titlePrefix:"Min"}],p,y),I={type:"tick",color:"black",opacity:1,orient:x,invalid:null},D="min-max"===d?T:gq([{fieldPrefix:"upper_whisker_",titlePrefix:"Upper Whisker"},{fieldPrefix:"lower_whisker_",titlePrefix:"Lower Whisker"}],p,y),M=[...C({partName:"rule",mark:{type:"rule",invalid:null},positionPrefix:"lower_whisker",endPositionPrefix:"lower_box",extraEncoding:D}),...C({partName:"rule",mark:{type:"rule",invalid:null},positionPrefix:"upper_box",endPositionPrefix:"upper_whisker",extraEncoding:D}),...C({partName:"ticks",mark:I,positionPrefix:"lower_whisker",extraEncoding:D}),...C({partName:"ticks",mark:I,positionPrefix:"upper_whisker",extraEncoding:D})],R=[..."tukey"!==d?M:[],...A({partName:"box",mark:Object.assign(Object.assign({type:"bar"},f?{size:f}:{}),{orient:w,invalid:null}),positionPrefix:"lower_box",endPositionPrefix:"upper_box",extraEncoding:T}),...N({partName:"median",mark:Object.assign(Object.assign(Object.assign({type:"tick",invalid:null},fP(e.boxplot.median)&&e.boxplot.median.color?{color:e.boxplot.median.color}:{}),f?{size:f}:{}),{orient:x}),positionPrefix:"mid_box",extraEncoding:T})];let F;if("min-max"!==d){const t=`datum["lower_box_${p.field}"]`,n=`datum["upper_box_${p.field}"]`,r=`(${n} - ${t})`,i=`${t} - ${l} * ${r}`,a=`${n} + ${l} * ${r}`,o=`datum["${p.field}"]`,s={joinaggregate:Aq(p.field),groupby:g};let u=void 0;"tukey"===d&&(u={transform:[{filter:`(${i} <= ${o}) && (${o} <= ${a})`},{aggregate:[{op:"min",field:p.field,as:"lower_whisker_"+p.field},{op:"max",field:p.field,as:"upper_whisker_"+p.field},{op:"min",field:"lower_box_"+p.field,as:"lower_box_"+p.field},{op:"max",field:"upper_box_"+p.field,as:"upper_box_"+p.field},...v],groupby:g}],layer:M});const{tooltip:f}=O,h=b(O,["tooltip"]),{scale:y,axis:x}=p,w=vq(p),_=bq(c,"outliers",e.boxplot,{transform:[{filter:`(${o} < ${i}) || (${o} > ${a})`}],mark:"point",encoding:Object.assign(Object.assign({[m]:Object.assign(Object.assign(Object.assign({field:p.field,type:p.type},void 0!==w?{title:w}:{}),void 0!==y?{scale:y}:{}),void 0!==x?{axis:x}:{})},h),k?{tooltip:k}:{})})[0];_&&u?F={transform:[s],layer:[_,u]}:_?(F=_).transform.unshift(s):u&&(F=u).transform.unshift(s)}return F?Object.assign(Object.assign({},u),{layer:[F,{transform:h,layer:R}]}):Object.assign(Object.assign({},u),{transform:(r=u.transform,null!==r&&void 0!==r?r:[]).concat(h),layer:R})}function Aq(t){return[{op:"q1",field:t,as:"lower_box_"+t},{op:"q3",field:t,as:"upper_box_"+t}]}const Nq="errorbar",Tq=JP({ticks:1,rule:1}),Iq=new FL(Nq,Dq);function Dq(t,{config:e}){const{transform:n,continuousAxisChannelDef:r,continuousAxis:i,encodingWithoutContinuousAxis:a,ticksOrient:o,markDef:s,outerSpec:u,tooltipEncoding:c}=Rq(t,Nq,e),l=yq(s,i,r,a,e.errorbar),f={type:"tick",orient:o};return Object.assign(Object.assign({},u),{transform:n,layer:[...l({partName:"ticks",mark:f,positionPrefix:"lower",extraEncoding:c}),...l({partName:"ticks",mark:f,positionPrefix:"upper",extraEncoding:c}),...l({partName:"rule",mark:"rule",positionPrefix:"lower",endPositionPrefix:"upper",extraEncoding:c})]})}function Mq(t,e){const{encoding:n}=t;if(function(t){return(TV(t.x)||TV(t.y))&&!TV(t.x2)&&!TV(t.y2)&&!TV(t.xError)&&!TV(t.xError2)&&!TV(t.yError)&&!TV(t.yError2)}(n))return{orient:kq(t,e),inputType:"raw"};const r=function(t){return TV(t.x2)||TV(t.y2)}(n),i=function(t){return TV(t.xError)||TV(t.xError2)||TV(t.yError)||TV(t.yError2)}(n),a=n.x,o=n.y;if(r){if(i)throw new Error(e+" cannot be both type aggregated-upper-lower and aggregated-error");const t=n.x2,r=n.y2;if(TV(t)&&TV(r))throw new Error(e+" cannot have both x2 and y2");if(TV(t)){if(TV(a)&&zV(a))return{orient:"horizontal",inputType:"aggregated-upper-lower"};throw new Error("Both x and x2 have to be quantitative in "+e)}if(TV(r)){if(TV(o)&&zV(o))return{orient:"vertical",inputType:"aggregated-upper-lower"};throw new Error("Both y and y2 have to be quantitative in "+e)}throw new Error("No ranged axis")}{const t=n.xError,r=n.xError2,i=n.yError,s=n.yError2;if(TV(r)&&!TV(t))throw new Error(e+" cannot have xError2 without xError");if(TV(s)&&!TV(i))throw new Error(e+" cannot have yError2 without yError");if(TV(t)&&TV(i))throw new Error(e+" cannot have both xError and yError with both are quantiative");if(TV(t)){if(TV(a)&&zV(a))return{orient:"horizontal",inputType:"aggregated-error"};throw new Error("All x, xError, and xError2 (if exist) have to be quantitative")}if(TV(i)){if(TV(o)&&zV(o))return{orient:"vertical",inputType:"aggregated-error"};throw new Error("All y, yError, and yError2 (if exist) have to be quantitative")}throw new Error("No ranged axis")}}function Rq(t,e,n){var r;const{mark:i,encoding:a,selection:o,projection:s}=t,u=b(t,["mark","encoding","selection","projection"]),c=NL(i)?i:{type:i};o&&BU(jU.selectionNotSupported(e));const{orient:l,inputType:f}=Mq(t,e),{continuousAxisChannelDef:d,continuousAxisChannelDef2:h,continuousAxisChannelDefError:p,continuousAxisChannelDefError2:m,continuousAxis:g}=xq(t,l,e),{errorBarSpecificAggregate:v,postAggregateCalculates:y,tooltipSummary:x,tooltipTitleWithFieldName:w}=function(t,e,n,r,i,a,o,s){let u=[],c=[];const l=e.field;let f,d=!1;if("raw"===a){const e=t.center?t.center:t.extent?"iqr"===t.extent?"median":"mean":s.errorbar.center,n=t.extent?t.extent:"mean"===e?"stderr":"iqr";if("median"===e!=("iqr"===n)&&BU(jU.errorBarCenterIsUsedWithWrongExtent(e,n,o)),"stderr"===n||"stdev"===n)u=[{op:n,field:l,as:"extent_"+l},{op:e,field:l,as:"center_"+l}],c=[{calculate:`datum["center_${l}"] + datum["extent_${l}"]`,as:"upper_"+l},{calculate:`datum["center_${l}"] - datum["extent_${l}"]`,as:"lower_"+l}],f=[{fieldPrefix:"center_",titlePrefix:rL(e)},{fieldPrefix:"upper_",titlePrefix:Fq(e,n,"+")},{fieldPrefix:"lower_",titlePrefix:Fq(e,n,"-")}],d=!0;else{let e,r,i;t.center&&t.extent&&BU(jU.errorBarCenterIsNotNeeded(t.extent,o)),"ci"===n?(e="mean",r="ci0",i="ci1"):(e="median",r="q1",i="q3"),u=[{op:r,field:l,as:"lower_"+l},{op:i,field:l,as:"upper_"+l},{op:e,field:l,as:"center_"+l}],f=[{fieldPrefix:"upper_",titlePrefix:VV({field:l,aggregate:i,type:"quantitative"},s,{allowDisabling:!1})},{fieldPrefix:"lower_",titlePrefix:VV({field:l,aggregate:r,type:"quantitative"},s,{allowDisabling:!1})},{fieldPrefix:"center_",titlePrefix:VV({field:l,aggregate:e,type:"quantitative"},s,{allowDisabling:!1})}]}}else{(t.center||t.extent)&&BU(jU.errorBarCenterAndExtentAreNotNeeded(t.center,t.extent)),"aggregated-upper-lower"===a?(f=[],c=[{calculate:`datum["${n.field}"]`,as:"upper_"+l},{calculate:`datum["${l}"]`,as:"lower_"+l}]):"aggregated-error"===a&&(f=[{fieldPrefix:"",titlePrefix:l}],c=[{calculate:`datum["${l}"] + datum["${r.field}"]`,as:"upper_"+l}],i?c.push({calculate:`datum["${l}"] + datum["${i.field}"]`,as:"lower_"+l}):c.push({calculate:`datum["${l}"] - datum["${r.field}"]`,as:"lower_"+l}));for(const t of c)f.push({fieldPrefix:t.as.substring(0,6),titlePrefix:oL(oL(t.calculate,'datum["',""),'"]',"")})}return{postAggregateCalculates:c,errorBarSpecificAggregate:u,tooltipSummary:f,tooltipTitleWithFieldName:d}}(c,d,h,p,m,f,e,n),k=g,_=(a[k],"x"===g?"x2":"y2"),E=(a[_],"x"===g?"xError":"yError"),O=(a[E],"x"===g?"xError2":"yError2"),S=(a[O],b(a,["symbol"==typeof k?k:k+"","symbol"==typeof _?_:_+"","symbol"==typeof E?E:E+"","symbol"==typeof O?O:O+""])),{bins:C,timeUnits:A,aggregate:N,groupby:T,encoding:I}=fq(S,n),D=[...N,...v],M="raw"!==f?[]:T,R=gq(x,d,I,w);return{transform:[...(r=u.transform,null!==r&&void 0!==r?r:[]),...C,...A,...0===D.length?[]:[{aggregate:D,groupby:M}],...y],groupby:M,continuousAxisChannelDef:d,continuousAxis:g,encodingWithoutContinuousAxis:I,ticksOrient:"vertical"===l?"horizontal":"vertical",markDef:c,outerSpec:u,tooltipEncoding:R}}function Fq(t,e,n){return rL(t)+" "+n+" "+e}const jq="errorband",Pq=JP({band:1,borders:1}),Lq=new FL(jq,zq);function zq(t,{config:e}){const{transform:n,continuousAxisChannelDef:r,continuousAxis:i,encodingWithoutContinuousAxis:a,markDef:o,outerSpec:s,tooltipEncoding:u}=Rq(t,jq,e),c=o,l=yq(c,i,r,a,e.errorband),f=void 0!==t.encoding.x&&void 0!==t.encoding.y;let d={type:f?"area":"rect"},h={type:f?"line":"rule"};const p=Object.assign(Object.assign({},c.interpolate?{interpolate:c.interpolate}:{}),c.tension&&c.interpolate?{interpolate:c.tension}:{});return f?(d=Object.assign(Object.assign({},d),p),h=Object.assign(Object.assign({},h),p)):c.interpolate?BU(jU.errorBand1DNotSupport("interpolate")):c.tension&&BU(jU.errorBand1DNotSupport("tension")),Object.assign(Object.assign({},s),{transform:n,layer:[...l({partName:"band",mark:d,positionPrefix:"lower",endPositionPrefix:"upper",extraEncoding:u}),...l({partName:"borders",mark:h,positionPrefix:"lower",extraEncoding:u}),...l({partName:"borders",mark:h,positionPrefix:"upper",extraEncoding:u})]})}const Bq={};function Uq(t,e,n){const r=new FL(t,e);Bq[t]={normalizer:r,parts:n}}Uq(_q,Cq,Eq),Uq(Nq,Dq,Tq),Uq(jq,zq,Pq);const Wq=["gradientHorizontalMaxLength","gradientHorizontalMinLength","gradientVerticalMaxLength","gradientVerticalMinLength","unselectedOpacity"],Vq={clipHeight:1,columnPadding:1,columns:1,cornerRadius:1,direction:1,fillColor:1,format:1,formatType:1,gradientLength:1,gradientOpacity:1,gradientStrokeColor:1,gradientStrokeWidth:1,gradientThickness:1,gridAlign:1,labelAlign:1,labelBaseline:1,labelColor:1,labelFont:1,labelFontSize:1,labelFontStyle:1,labelFontWeight:1,labelLimit:1,labelOffset:1,labelOpacity:1,labelOverlap:1,labelPadding:1,labelSeparation:1,legendX:1,legendY:1,offset:1,orient:1,padding:1,rowPadding:1,strokeColor:1,symbolDash:1,symbolDashOffset:1,symbolFillColor:1,symbolLimit:1,symbolOffset:1,symbolOpacity:1,symbolSize:1,symbolStrokeColor:1,symbolStrokeWidth:1,symbolType:1,tickCount:1,tickMinStep:1,title:1,titleAlign:1,titleAnchor:1,titleBaseline:1,titleColor:1,titleFont:1,titleFontSize:1,titleFontStyle:1,titleFontWeight:1,titleLimit:1,titleLineHeight:1,titleOpacity:1,titleOrient:1,titlePadding:1,type:1,values:1,zindex:1},qq=(JP(Vq),"_vgsid_"),Hq={single:{on:"click",fields:[qq],resolve:"global",empty:"all",clear:"dblclick"},multi:{on:"click",fields:[qq],toggle:"event.shiftKey",resolve:"global",empty:"all",clear:"dblclick"},interval:{on:"[mousedown, window:mouseup] > window:mousemove!",encodings:["x","y"],translate:"[mousedown, window:mouseup] > window:mousemove!",zoom:"wheel!",mark:{fill:"#333",fillOpacity:.125,stroke:"white"},resolve:"global",clear:"dblclick"}};function Gq(t){return!(!t||"legend"!==t&&!t.legend)}function $q(t){return Gq(t)&&fP(t)}function Kq(t){return void 0!==t.concat}function Xq(t){return void 0!==t.vconcat}function Yq(t){return void 0!==t.hconcat}function Jq(t){return void 0!==t.repeat}function Zq(t){return fP(t)&&void 0!==t.step}const Qq=JP({align:1,bounds:1,center:1,columns:1,spacing:1});function tH(t,e){var n;return null!==(n=t[e])&&void 0!==n?n:t["width"===e?"continuousWidth":"continuousHeight"]}function eH(t,e){const n=nH(t,e);return Zq(n)?n.step:rH}function nH(t,e){var n;return uL(null!==(n=t[e])&&void 0!==n?n:t["width"===e?"discreteWidth":"discreteHeight"],{step:t.step})}const rH=20;const iH={background:"white",padding:5,timeFormat:"%b %d, %Y",countTitle:"Count of Records",view:{continuousWidth:200,continuousHeight:200,step:rH},mark:{color:"#4c78a8",invalid:"filter",timeUnitBand:1},area:{},bar:DL,circle:{},geoshape:{},image:{},line:{},point:{},rect:ML,rule:{color:"black"},square:{},text:{color:"black"},tick:{thickness:1},trail:{},boxplot:{size:14,extent:1.5,box:{},median:{color:"white"},outliers:{},rule:{},ticks:null},errorbar:{center:"mean",rule:!0,ticks:!1},errorband:{band:{opacity:.3},borders:!1},scale:{pointPadding:.5,barBandPaddingInner:.1,rectBandPaddingInner:0,minBandSize:2,minFontSize:8,maxFontSize:40,minOpacity:.3,maxOpacity:.8,minSize:9,minStrokeWidth:1,maxStrokeWidth:4,quantileCount:4,quantizeCount:4},projection:{},axis:{},axisX:{},axisY:{},axisLeft:{},axisRight:{},axisTop:{},axisBottom:{},axisBand:{},legend:{gradientHorizontalMaxLength:200,gradientHorizontalMinLength:100,gradientVerticalMaxLength:200,gradientVerticalMinLength:64,unselectedOpacity:.35},header:{titlePadding:10,labelPadding:10},headerColumn:{},headerRow:{},headerFacet:{},selection:Hq,style:{},title:{},facet:{spacing:20},repeat:{spacing:20},concat:{spacing:20}};function aH(t){return vP({},iH,t)}const oH=["view",...AL],sH=["background","padding","facet","concat","repeat","numberFormat","timeFormat","countTitle","header","scale","selection","overlay"],uH=Object.assign({view:["continuousWidth","continuousHeight","discreteWidth","discreteHeight","step"]},{area:["line","point"],bar:["binSpacing","continuousBandSize","discreteBandSize"],rect:["binSpacing","continuousBandSize","discreteBandSize"],line:["point"],tick:["bandSize","thickness"]});function cH(t){t=PP(t);for(const e of sH)delete t[e];if(t.legend)for(const e of Wq)delete t.legend[e];if(t.mark)for(const e of IL)delete t.mark[e];for(const e of oH){for(const n of IL)delete t[e][n];const n=uH[e];if(n)for(const r of n)delete t[e][r];lH(t,e)}for(const e of JP(Bq))delete t[e];lH(t,"title","group-title");for(const e in t)fP(t[e])&&0===JP(t[e]).length&&delete t[e];return JP(t).length>0?t:void 0}function lH(t,e,n,r){const i="title"===e?QW(t.title).mark:r?t[e][r]:t[e];"view"===e&&(n="cell");const a=Object.assign(Object.assign({},i),t.style[e]);JP(a).length>0&&(t.style[null!==n&&void 0!==n?n:e]=a),r||delete t[e]}function fH(t){return void 0!==t.layer}class dH{map(t,e){return _V(t)?this.mapFacet(t,e):Jq(t)?this.mapRepeat(t,e):Yq(t)?this.mapHConcat(t,e):Xq(t)?this.mapVConcat(t,e):Kq(t)?this.mapConcat(t,e):this.mapLayerOrUnit(t,e)}mapLayerOrUnit(t,e){if(fH(t))return this.mapLayer(t,e);if(RL(t))return this.mapUnit(t,e);throw new Error(jU.invalidSpec(t))}mapLayer(t,e){return Object.assign(Object.assign({},t),{layer:t.layer.map(t=>this.mapLayerOrUnit(t,e))})}mapHConcat(t,e){return Object.assign(Object.assign({},t),{hconcat:t.hconcat.map(t=>this.map(t,e))})}mapVConcat(t,e){return Object.assign(Object.assign({},t),{vconcat:t.vconcat.map(t=>this.map(t,e))})}mapConcat(t,e){const{concat:n}=t,r=b(t,["concat"]);return Object.assign(Object.assign({},r),{concat:n.map(t=>this.map(t,e))})}mapFacet(t,e){return Object.assign(Object.assign({},t),{spec:this.map(t.spec,e)})}mapRepeat(t,e){return Object.assign(Object.assign({},t),{spec:this.map(t.spec,e)})}}const hH={zero:1,center:1,normalize:1};const pH=[hL,dL,yL,gL,kL,_L,mL,bL,xL],mH=[hL,dL];function gH(t,e,n={}){const r=NL(t)?t.type:t;if(!VP(pH,r))return null;const i=function(t){const e=t.x,n=t.y;if(TV(e)&&TV(n))if("quantitative"===e.type&&"quantitative"===n.type){if(e.stack)return"x";if(n.stack)return"y";if(!!e.aggregate!=!!n.aggregate)return e.aggregate?"x":"y"}else{if("quantitative"===e.type)return"x";if("quantitative"===n.type)return"y"}else{if(TV(e)&&"quantitative"===e.type)return"x";if(TV(n)&&"quantitative"===n.type)return"y"}}(e);if(!i)return null;const a=e[i],o=DV(a)?PV(a,{}):void 0,s="x"===i?"y":"x",u=e[s],c=DV(u)?PV(u,{}):void 0,l=Yz.reduce((t,n)=>{if("tooltip"!==n&&cq(e,n)){const r=e[n];(lP(r)?r:[r]).forEach(e=>{const r=KV(e);if(r.aggregate)return;const i=DV(r)?PV(r,{}):void 0;(!i||i!==c&&i!==o)&&t.push({channel:n,fieldDef:r})})}return t},[]);let f;if(void 0!==a.stack?f=EP(a.stack)?a.stack?"zero":null:a.stack:l.length>0&&VP(mH,r)&&(f="zero"),!f||!function(t){return!!hH[t]}(f))return null;if(lq(e)&&0===l.length)return null;if(a.scale&&a.scale.type&&a.scale.type!==OW.LINEAR){if(n.disallowNonLinearStack)return null;BU(jU.cannotStackNonLinearScale(a.scale.type))}return cq(e,i===KL?YL:JL)?(void 0!==a.stack&&BU(jU.cannotStackRangedMark(i)),null):(a.aggregate&&!VP(VL,a.aggregate)&&BU(jU.stackNonSummativeAggregate(a.aggregate)),{groupbyChannel:u?s:void 0,fieldChannel:i,impute:null!==a.impute&&SL(r),stackBy:l,offset:f})}function vH(t,e={},n){return"transparent"===t.point?{opacity:0}:t.point?fP(t.point)?t.point:{}:void 0!==t.point?null:e.point||n.shape?fP(e.point)?e.point:{}:void 0}function yH(t,e={}){return t.line?!0===t.line?{}:t.line:void 0!==t.line?null:e.line?!0===e.line?{}:e.line:void 0}class bH{constructor(){this.name="path-overlay"}hasMatchingType(t,e){if(RL(t)){const{mark:n,encoding:r}=t,i=NL(n)?n:{type:n};switch(i.type){case"line":case"rule":case"trail":return!!vH(i,e[i.type],r);case"area":return!!vH(i,e[i.type],r)||!!yH(i,e[i.type])}}return!1}run(t,e,n){const{config:r}=e,{selection:i,projection:a,encoding:o,mark:s}=t,u=b(t,["selection","projection","encoding","mark"]),c=NL(s)?s:{type:s},l=vH(c,r[c.type],o),f="area"===c.type&&yH(c,r[c.type]),d=[Object.assign(Object.assign({},i?{selection:i}:{}),{mark:function(t){const{point:e,line:n}=t,r=b(t,["point","line"]);return JP(r).length>1?r:r.type}(Object.assign(Object.assign({},c),"area"===c.type?{opacity:.7}:{})),encoding:zP(o,["shape"])})],h=gH(c,o);let p=o;if(h){const{fieldChannel:t,offset:e}=h;p=Object.assign(Object.assign({},o),{[t]:Object.assign(Object.assign({},o[t]),e?{stack:e}:{})})}return f&&d.push(Object.assign(Object.assign({},a?{projection:a}:{}),{mark:Object.assign(Object.assign({type:"line"},LP(c,["clip","interpolate","tension","tooltip"])),f),encoding:p})),l&&d.push(Object.assign(Object.assign({},a?{projection:a}:{}),{mark:Object.assign(Object.assign({type:"point",opacity:1,filled:!0},LP(c,["clip","tooltip"])),l),encoding:p})),n(Object.assign(Object.assign({},u),{layer:d}),Object.assign(Object.assign({},e),{config:function(t){for(const e of["line","area","rule","trail"])t[e]&&(t=Object.assign(Object.assign({},t),{[e]:zP(t[e],["point","line"])}));return t}(r)}))}}class xH{constructor(){this.name="RangeStep"}hasMatchingType(t){var e,n;if(RL(t)&&t.encoding)for(const r of Zz){const i=t.encoding[r];if(i&&TV(i)&&(null===(n=null===(e=i)||void 0===e?void 0:e.scale)||void 0===n?void 0:n.rangeStep))return!0}return!1}run(t){var e,n;const r={};let i=Object.assign({},t.encoding);for(const t of Zz){const a=Qz(t),o=i[t];if(o&&TV(o)&&(null===(n=null===(e=o)||void 0===e?void 0:e.scale)||void 0===n?void 0:n.rangeStep)){const{scale:e}=o,n=b(o,["scale"]),s=e,{rangeStep:u}=s,c=b(s,["rangeStep"]);r[a]={step:e.rangeStep},BU(jU.RANGE_STEP_DEPRECATED),i=Object.assign(Object.assign({},i),{[t]:Object.assign(Object.assign({},n),JP(c).length>0?{scale:c}:{})})}}return Object.assign(Object.assign(Object.assign({},r),t),{encoding:i})}}class wH{constructor(){this.name="RuleForRangedLine"}hasMatchingType(t){if(RL(t)){const{encoding:e,mark:n}=t;if("line"===n)for(const t of Pz){const n=e[zz(t)];if(e[t]&&TV(n)&&!aq(n.bin))return!0}}return!1}run(t,e,n){const{encoding:r}=t;return BU(jU.lineWithRange(!!r.x2,!!r.y2)),n(Object.assign(Object.assign({},t),{mark:"rule"}),e)}}function kH(t){const{parentEncoding:e,encoding:n}=t;if(e&&n){const t=JP(e).reduce((t,e)=>(n[e]&&t.push(e),t),[]);t.length>0&&BU(jU.encodingOverridden(t))}const r=Object.assign(Object.assign({},null!==e&&void 0!==e?e:{}),null!==n&&void 0!==n?n:{});return JP(r).length>0?r:void 0}function _H(t){const{parentProjection:e,projection:n}=t;return e&&n&&BU(jU.projectionOverridden({parentProjection:e,projection:n})),null!==n&&void 0!==n?n:e}function EH(t,e){void 0===e&&(e=aH(t.config));const n=function(t,e={}){return OH.map(t,{config:e})}(t,e),{width:r,height:i}=t,a=function(t,e,n){let{width:r,height:i}=e;const a=RL(t)||fH(t),o={};a?"container"==r&&"container"==i?(o.type="fit",o.contains="padding"):"container"==r?(o.type="fit-x",o.contains="padding"):"container"==i&&(o.type="fit-y",o.contains="padding"):("container"==r&&(BU(jU.containerSizeNonSingle("width")),r=void 0),"container"==i&&(BU(jU.containerSizeNonSingle("height")),i=void 0));const s=Object.assign(Object.assign(Object.assign({type:"pad"},o),n?SH(n.autosize):{}),SH(t.autosize));"fit"!==s.type||a||(BU(jU.FIT_NON_SINGLE),s.type="pad");"container"==r&&"fit"!=s.type&&"fit-x"!=s.type&&BU(jU.containerSizeNotCompatibleWithAutosize("width"));"container"==i&&"fit"!=s.type&&"fit-y"!=s.type&&BU(jU.containerSizeNotCompatibleWithAutosize("height"));if(jP(s,{type:"pad"}))return;return s}(n,{width:r,height:i,autosize:t.autosize},e);return Object.assign(Object.assign({},n),a?{autosize:a}:{})}const OH=new class extends dH{constructor(){super(...arguments),this.nonFacetUnitNormalizers=[Oq,Iq,Lq,new bH,new wH,new xH]}map(t,e){if(RL(t)){const n=cq(t.encoding,HL),r=cq(t.encoding,GL),i=cq(t.encoding,$L);if(n||r||i)return this.mapFacetedUnit(t,e)}return super.map(t,e)}mapUnit(t,e){const{parentEncoding:n,parentProjection:r}=e;if(n||r)return this.mapUnitWithParentEncodingOrProjection(t,e);const i=this.mapLayerOrUnit.bind(this);for(const n of this.nonFacetUnitNormalizers)if(n.hasMatchingType(t,e.config))return n.run(t,e,i);return t}mapRepeat(t,e){const{repeat:n}=t;return!lP(n)&&t.columns&&(t=zP(t,["columns"]),BU(jU.columnsNotSupportByRowCol("repeat"))),Object.assign(Object.assign({},t),{spec:this.map(t.spec,e)})}mapFacet(t,e){const{facet:n}=t;return kV(n)&&t.columns&&(t=zP(t,["columns"]),BU(jU.columnsNotSupportByRowCol("facet"))),super.mapFacet(t,e)}mapUnitWithParentEncodingOrProjection(t,e){const{encoding:n,projection:r}=t,{parentEncoding:i,parentProjection:a,config:o}=e,s=_H({parentProjection:a,projection:r}),u=kH({parentEncoding:i,encoding:n});return this.mapUnit(Object.assign(Object.assign(Object.assign({},t),s?{projection:s}:{}),u?{encoding:u}:{}),{config:o})}mapFacetedUnit(t,e){const n=t.encoding,{row:r,column:i,facet:a}=n,o=b(n,["row","column","facet"]),{mark:s,width:u,projection:c,height:l,selection:f,encoding:d}=t,h=b(t,["mark","width","projection","height","selection","encoding"]),{facetMapping:p,layout:m}=this.getFacetMappingAndLayout({row:r,column:i,facet:a});return this.mapFacet(Object.assign(Object.assign(Object.assign({},h),m),{facet:p,spec:Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},c?{projection:c}:{}),{mark:s}),u?{width:u}:{}),l?{height:l}:{}),{encoding:o}),f?{selection:f}:{})}),e)}getFacetMappingAndLayout(t){var e;const{row:n,column:r,facet:i}=t;if(n||r){i&&BU(jU.facetChannelDropped([...n?[HL]:[],...r?[GL]:[]]));const a={},o={};for(const n of[HL,GL]){const r=t[n];if(r){const{align:t,center:i,spacing:s,columns:u}=r,c=b(r,["align","center","spacing","columns"]);a[n]=c;for(const t of["align","center","spacing"])void 0!==r[t]&&(o[t]=null!==(e=o[t])&&void 0!==e?e:{},o[t][n]=r[t])}}return{facetMapping:a,layout:o}}{const{align:t,center:e,spacing:n,columns:r}=i;return{facetMapping:b(i,["align","center","spacing","columns"]),layout:Object.assign(Object.assign(Object.assign(Object.assign({},t?{align:t}:{}),e?{center:e}:{}),n?{spacing:n}:{}),r?{columns:r}:{})}}}mapLayer(t,e){var{parentEncoding:n,parentProjection:r}=e,i=b(e,["parentEncoding","parentProjection"]);const{encoding:a,projection:o}=t,s=b(t,["encoding","projection"]),u=Object.assign(Object.assign({},i),{parentEncoding:kH({parentEncoding:n,encoding:a}),parentProjection:_H({parentProjection:r,projection:o})});return super.mapLayer(s,u)}};function SH(t){return dP(t)?{type:t}:null!==t&&void 0!==t?t:{}}const CH=["background","padding"];function AH(t){return CH.reduce((e,n)=>(t&&void 0!==t[n]&&(e[n]=t[n]),e),{})}function NH(t){return!!t.url}function TH(t){return!!t.values}function IH(t){return!(!t.name||NH(t)||TH(t)||DH(t))}function DH(t){return t&&(MH(t)||RH(t)||FH(t))}function MH(t){return!!t.sequence}function RH(t){return!!t.sphere}function FH(t){return!!t.graticule}const jH="main",PH="raw";function LH(t){return void 0!==t.filter}function zH(t){return void 0!==t.lookup}function BH(t){return void 0!==t.pivot}function UH(t){return void 0!==t.density}function WH(t){return void 0!==t.quantile}function VH(t){return void 0!==t.regression}function qH(t){return void 0!==t.loess}function HH(t){return void 0!==t.sample}function GH(t){return void 0!==t.window}function $H(t){return void 0!==t.joinaggregate}function KH(t){return void 0!==t.flatten}function XH(t){return void 0!==t.calculate}function YH(t){return!!t.bin}function JH(t){return void 0!==t.impute}function ZH(t){return void 0!==t.timeUnit}function QH(t){return void 0!==t.aggregate}function tG(t){return void 0!==t.stack}function eG(t){return void 0!==t.fold}function nG(t){return t.map(t=>LH(t)?{filter:function t(e,n){return FP(e)?{not:t(e.not,n)}:RP(e)?{and:e.and.map(e=>t(e,n))}:MP(e)?{or:e.or.map(e=>t(e,n))}:n(e)}(t.filter,yW)}:t)}function rG(t){return!!t.signal}function iG(t){return!!t.step}function aG(t){return!lP(t)&&("field"in t&&"data"in t)}const oG=JP({opacity:1,fill:1,fillOpacity:1,stroke:1,strokeCap:1,strokeWidth:1,strokeOpacity:1,strokeDash:1,strokeDashOffset:1,strokeJoin:1,strokeMiterLimit:1,size:1,shape:1,interpolate:1,tension:1,orient:1,align:1,baseline:1,text:1,dir:1,dx:1,dy:1,ellipsis:1,limit:1,radius:1,theta:1,angle:1,font:1,fontSize:1,fontWeight:1,fontStyle:1,lineBreak:1,lineHeight:1,cursor:1,href:1,tooltip:1,cornerRadius:1,cornerRadiusTopLeft:1,cornerRadiusTopRight:1,cornerRadiusBottomLeft:1,cornerRadiusBottomRight:1,x:1,y:1,x2:1,y2:1,width:1,height:1,aspect:1}),sG=["cornerRadius","cornerRadiusTopLeft","cornerRadiusTopRight","cornerRadiusBottomLeft","cornerRadiusBottomRight"],uG={labelAlign:{part:"labels",vgProp:"align"},labelBaseline:{part:"labels",vgProp:"baseline"},labelColor:{part:"labels",vgProp:"fill"},labelFont:{part:"labels",vgProp:"font"},labelFontSize:{part:"labels",vgProp:"fontSize"},labelFontStyle:{part:"labels",vgProp:"fontStyle"},labelFontWeight:{part:"labels",vgProp:"fontWeight"},labelOpacity:{part:"labels",vgProp:"opacity"},gridColor:{part:"grid",vgProp:"stroke"},gridDash:{part:"grid",vgProp:"strokeDash"},gridDashOffset:{part:"grid",vgProp:"strokeDash"},gridOpacity:{part:"grid",vgProp:"opacity"},gridWidth:{part:"grid",vgProp:"strokeWidth"},tickColor:{part:"ticks",vgProp:"stroke"},tickDash:{part:"ticks",vgProp:"strokeDash"},tickDashOffset:{part:"ticks",vgProp:"strokeDash"},tickOpacity:{part:"ticks",vgProp:"opacity"},tickWidth:{part:"ticks",vgProp:"strokeWidth"}};const cG=["domain","grid","labels","ticks","title"],lG={grid:"grid",gridColor:"grid",gridDash:"grid",gridOpacity:"grid",gridScale:"grid",gridWidth:"grid",orient:"main",bandPosition:"both",domain:"main",domainColor:"main",domainOpacity:"main",domainWidth:"main",format:"main",formatType:"main",labelAlign:"main",labelAngle:"main",labelBaseline:"main",labelBound:"main",labelColor:"main",labelFlush:"main",labelFlushOffset:"main",labelFont:"main",labelFontSize:"main",labelFontWeight:"main",labelLimit:"main",labelOpacity:"main",labelOverlap:"main",labelPadding:"main",labels:"main",maxExtent:"main",minExtent:"main",offset:"main",position:"main",tickColor:"main",tickExtra:"main",tickOffset:"both",tickOpacity:"main",tickRound:"main",ticks:"main",tickSize:"main",title:"main",titleAlign:"main",titleAngle:"main",titleBaseline:"main",titleColor:"main",titleFont:"main",titleFontSize:"main",titleFontWeight:"main",titleLimit:"main",titleLineHeight:"main",titleOpacity:"main",titlePadding:"main",titleX:"main",titleY:"main",tickWidth:"both",tickCount:"both",values:"both",scale:"both",zindex:"both"},fG={orient:1,bandPosition:1,domain:1,domainColor:1,domainDash:1,domainDashOffset:1,domainOpacity:1,domainWidth:1,format:1,formatType:1,grid:1,gridColor:1,gridDash:1,gridDashOffset:1,gridOpacity:1,gridWidth:1,labelAlign:1,labelAngle:1,labelBaseline:1,labelBound:1,labelColor:1,labelFlush:1,labelFlushOffset:1,labelFont:1,labelFontSize:1,labelFontStyle:1,labelFontWeight:1,labelLimit:1,labelOpacity:1,labelOverlap:1,labelPadding:1,labels:1,labelSeparation:1,maxExtent:1,minExtent:1,offset:1,position:1,tickBand:1,tickColor:1,tickCount:1,tickDash:1,tickDashOffset:1,tickExtra:1,tickMinStep:1,tickOffset:1,tickOpacity:1,tickRound:1,ticks:1,tickSize:1,tickWidth:1,title:1,titleAlign:1,titleAnchor:1,titleAngle:1,titleBaseline:1,titleColor:1,titleFont:1,titleFontSize:1,titleFontStyle:1,titleFontWeight:1,titleLimit:1,titleLineHeight:1,titleOpacity:1,titlePadding:1,titleX:1,titleY:1,values:1,translate:1,zindex:1},dG=Object.assign(Object.assign({},fG),{labelExpr:1,encoding:1});JP(dG);function hG(t,e,n,r){const i=e&&e.condition,a=r(e);if(i){return{[n]:[...xP(i).map(e=>{const n=r(e),i=function(t){return t.selection}(e)?N$(t,e.selection):I$(t,e.test);return Object.assign({test:i},n)}),...void 0!==a?[a]:[]]}}return void 0!==a?{[n]:a}:{}}function pG(t){const{channel:e,channelDef:n,markDef:r,scale:i}=t,a=bG(t);return TV(n)&&!WL(n.aggregate)&&i&&LW(i.get("type"))&&!1===i.get("zero")?mG({fieldDef:n,channel:e,markDef:r,ref:a}):a}function mG({fieldDef:t,channel:e,markDef:n,ref:r}){return SL(n.type)?r:[function(t,e){const n=gG(t,!0),r="x"===zz(e)?{value:0}:{field:{group:"height"}};return Object.assign({test:n},r)}(t,e),r]}function gG(t,e=!0){return vW(dP(t)?t:PV(t,{expr:"datum"}),!e)}function vG(t,e,n,r){const i=Object.assign(Object.assign({},e?{scale:e}:{}),{field:PV(t,n)});if(r){const{offset:t,band:e}=r;return Object.assign(Object.assign(Object.assign({},i),t?{offset:t}:{}),e?{band:e}:{})}return i}function yG({scaleName:t,fieldDef:e,fieldDef2:n,offset:r,startSuffix:i,band:a=.5}){const o=0<a&&a<1?"datum":void 0,s=PV(e,{expr:o,suffix:i}),u=void 0!==n?PV(n,{expr:o}):PV(e,{suffix:"end",expr:o});if(0===a)return Object.assign({scale:t,field:s},r?{offset:r}:{});if(1===a)return Object.assign({scale:t,field:u},r?{offset:r}:{});{const e=`${a} * ${s} + ${1-a} * ${u}`;return Object.assign({signal:`scale("${t}", ${e})`},r?{offset:r}:{})}}function bG({channel:t,channelDef:e,channel2Def:n,markDef:r,config:i,scaleName:a,scale:o,stack:s,offset:u,defaultRef:c}){if(e){if(TV(e)){if(IV(e)){const o=SV(t,e,n,r,i,{isMidPoint:!0});if(iq(e.bin)||o&&e.timeUnit)return VP([KL,XL],t)&&VP([xW,kW],e.type)?s&&s.impute?vG(e,a,{binSuffix:"mid"},{offset:u}):yG({scaleName:a,fieldDef:e,band:o,offset:u}):vG(e,a,nq(e,t)?{binSuffix:"range"}:{},{offset:u});if(aq(e.bin)){if(TV(n))return yG({scaleName:a,fieldDef:e,fieldDef2:n,band:o,offset:u});{const e=t===KL?YL:JL;BU(jU.channelRequiredForBinned(e))}}}if(o){const t=o.get("type");if(jW(t)){if("band"===t){return vG(e,a,{binSuffix:"range"},{band:uL(FV(e)?e.band:void 0,.5),offset:u})}return vG(e,a,{binSuffix:"range"},{offset:u})}}return vG(e,a,{},{offset:u})}if(MV(e)){const n=e.value,r=u?{offset:u}:{};return Object.assign(Object.assign({},xG(t,n)),r)}}const l=wP(c)?Object.assign(Object.assign({},c()),u?{offset:u}:{}):c;return l?Object.assign(Object.assign({},l),u?{offset:u}:{}):l}function xG(t,e){return VP(["x","x2"],t)&&"width"===e?{field:{group:"width"}}:VP(["y","y2"],t)&&"height"===e?{field:{group:"height"}}:{value:e}}function wG(t,e,n={}){const{markDef:r,encoding:i,config:a}=e,{vgChannel:o=t}=n;let{defaultRef:s,defaultValue:u}=n;void 0===s&&(u=null!==u&&void 0!==u?u:o===t?r[t]:uL(r[t],r[o],iV(t,r,a,{vgChannel:o})),s=u?{value:u}:void 0);const c=i[t];return hG(e,c,o,n=>bG({channel:t,channelDef:n,markDef:r,config:a,scaleName:e.scaleName(t),scale:e.getScaleComponent(t),stack:null,defaultRef:s}))}function kG(t){const{markDef:e,encoding:n,config:r}=t,{filled:i,type:a}=e,o={fill:iV("fill",e,r),stroke:iV("stroke",e,r),color:iV("color",e,r)},s=VP(["bar","point","circle","square","geoshape"],a)?"transparent":void 0,u=uL(e.fill,!0===i?e.color:void 0,o.fill,!0===i?o.color:void 0,s),c=uL(e.stroke,!1===i?e.color:void 0,o.stroke,!1===i?o.color:void 0),l=i?"fill":"stroke",f=Object.assign(Object.assign({},u?{fill:{value:u}}:{}),c?{stroke:{value:c}}:{});return e.color&&(i?e.fill:e.stroke)&&BU(jU.droppingColor("property",{fill:"fill"in e,stroke:"stroke"in e})),Object.assign(Object.assign(Object.assign(Object.assign({},f),wG("color",t,{vgChannel:l,defaultValue:i?u:c})),wG("fill",t,{defaultValue:n.fill?u:void 0})),wG("stroke",t,{defaultValue:n.stroke?c:void 0}))}function _G(t,e="text"){const n=t.encoding[e];return hG(t,n,e,e=>EG(e,t.config))}function EG(t,e,n="datum"){if(t){if(MV(t))return{value:t.value};if(IV(t))return oV(t,GV(t),n,e)}}function OG(t,e={}){const{encoding:n,markDef:r,config:i}=t,a=n.tooltip;return lP(a)?{tooltip:SG({tooltip:a},i,e)}:hG(t,a,"tooltip",a=>{const o=EG(a,t.config,e.reactiveGeom?"datum.datum":"datum");if(o)return o;if(null===a)return;let s=uL(r.tooltip,iV("tooltip",r,i));return!0===s&&(s={content:"encoding"}),dP(s)?{value:s}:fP(s)?"encoding"===s.content?SG(n,i,e):{signal:"datum"}:void 0})}function SG(t,e,{reactiveGeom:n}={}){const r=[],i={},a={},o=n?"datum.datum":"datum",s=[];function u(n,r){const i=zz(r),u=IV(n)?n:Object.assign(Object.assign({},n),{type:t[i].type}),c=xP(VV(u,e,{allowDisabling:!1})).join(", ");let l=EG(u,e,o).signal;if("x"===r||"y"===r){const n="x"===r?"x2":"y2",i=$V(t[n]);if(aq(u.bin)&&i){l=lV(PV(u,{expr:o}),PV(i,{expr:o}),GV(u),e),a[n]=!0}}s.push({channel:r,key:c,value:l})}hq(t,(t,e)=>{TV(t)?u(t,e):NV(t)&&u(t.condition,e)});for(const{channel:t,key:e,value:n}of s)a[t]||i[e]||(r.push(`${hP(e)}: ${n}`),i[e]=!0);return r.length>0?{signal:`{${r.join(", ")}}`}:void 0}function CG(t,e){const n=e[t+"Offset"];if(n)return n}function AG(t,e,{defaultPos:n,vgChannel:r}){const{encoding:i,mark:a,markDef:o,config:s,stack:u}=e,c=i[t],l=i[t===KL?YL:JL],f=e.scaleName(t),d=e.getScaleComponent(t),h=CG(t,e.markDef),p=NG({model:e,markDef:o,config:s,defaultPos:n,channel:t,scaleName:f,scale:d,mark:a,checkBarAreaWithoutZero:!l}),m=c||!i.latitude&&!i.longitude?function(t){const{channel:e,channelDef:n,scaleName:r,stack:i,offset:a}=t;if(TV(n)&&i&&e===i.fieldChannel)return FV(n)&&void 0!==n.band?yG({scaleName:r,fieldDef:n,startSuffix:"start",band:n.band,offset:0}):vG(n,r,{suffix:"end"},{offset:a});return pG(t)}({channel:t,channelDef:c,channel2Def:l,markDef:o,config:s,scaleName:f,scale:d,stack:u,offset:h,defaultRef:p}):{field:e.getName(t)};return{[null!==r&&void 0!==r?r:t]:m}}function NG({model:t,markDef:e,config:n,defaultPos:r,channel:i,scaleName:a,scale:o,mark:s,checkBarAreaWithoutZero:u}){return()=>{const c=zz(i),l=uL(e[i],iV(i,e,n));if(void 0!==l)return xG(i,l);if("zeroOrMin"===r||"zeroOrMax"===r){if(a){const t=o.get("type");if(VP([OW.LOG,OW.TIME,OW.UTC],t))!u||"bar"!==s&&"area"!==s||BU(jU.nonZeroScaleUsedWithLengthMark(s,c,{scaleType:t}));else{if(o.domainDefinitelyIncludesZero())return{scale:a,value:0};!u||"bar"!==s&&"area"!==s||BU(jU.nonZeroScaleUsedWithLengthMark(s,c,{zeroFalse:!1===o.explicit.zero}))}}return"zeroOrMin"===r?"x"===c?{value:0}:{field:{group:"height"}}:"x"===c?{field:{group:"width"}}:{value:0}}{const e=t["x"===c?"width":"height"];return Object.assign(Object.assign({},e),{mult:.5})}}}const TG={left:"x",center:"xc",right:"x2"},IG={top:"y",middle:"yc",bottom:"y2"};function DG(t,e,n){const r="x"===t?"align":"baseline",i=uL(e[r],iV(r,e,n));return"x"===t?TG[null!==i&&void 0!==i?i:"center"]:IG[null!==i&&void 0!==i?i:"middle"]}function MG(t,e,{defaultPos:n,defaultPos2:r,range:i}){return i?RG(t,e,{defaultPos:n,defaultPos2:r}):AG(t,e,{defaultPos:n})}function RG(t,e,{defaultPos:n,defaultPos2:r}){const{markDef:i,config:a}=e,o="x"===t?"width":"height",s=function(t,e,n){const{encoding:r,mark:i,markDef:a,stack:o,config:s}=t,u="x2"===n?"x":"y",c="x2"===n?"width":"height",l=r[u],f=t.scaleName(u),d=t.getScaleComponent(u),h=CG(n,t.markDef);if(!l&&(r.latitude||r.longitude))return{[n]:{field:t.getName(n)}};const p=function({channel:t,channelDef:e,channel2Def:n,markDef:r,config:i,scaleName:a,scale:o,stack:s,offset:u,defaultRef:c}){if(TV(e)&&s&&t.charAt(0)===s.fieldChannel.charAt(0))return vG(e,a,{suffix:"start"},{offset:u});return pG({channel:t,channelDef:n,scaleName:a,scale:o,stack:s,markDef:r,config:i,offset:u,defaultRef:c})}({channel:n,channelDef:l,channel2Def:r[n],markDef:a,config:s,scaleName:f,scale:d,stack:o,offset:h,defaultRef:void 0});if(void 0!==p)return{[n]:p};const m=NG({model:t,markDef:a,config:s,defaultPos:e,channel:n,scaleName:f,scale:d,mark:i,checkBarAreaWithoutZero:!r[n]})();return uL(FG(n,a),FG(n,{[n]:aV(n,a,s.style),[c]:aV(c,a,s.style)}),FG(n,s[i]),FG(n,s.mark),{[n]:m})}(e,r,"x"===t?"x2":"y2"),u=s[o]?DG(t,i,a):t;return Object.assign(Object.assign({},AG(t,e,{defaultPos:n,vgChannel:u})),s)}function FG(t,e){const n="x2"===t?"width":"height";return e[t]?{[t]:xG(t,e[t])}:e[n]?{[n]:{value:e[n]}}:void 0}function jG(t,e,n){var r,i,a,o;const{config:s,encoding:u,markDef:c}=t,l="x"===e?"x2":"y2",f="x"===e?"width":"height",d=u[e],h=u[l],p=t.getScaleComponent(e),m=p?p.get("type"):void 0,g=t.scaleName(e),v=c.orient,y=null!==(o=null!==(a=null!==(i=null!==(r=u[f])&&void 0!==r?r:u.size)&&void 0!==i?i:c[f])&&void 0!==a?a:c.size)&&void 0!==o?o:iV("size",c,s,{vgChannel:f}),b="x"===e?"vertical"===v:"horizontal"===v;if(TV(d)&&(iq(d.bin)||aq(d.bin)||d.timeUnit&&!h)&&!y&&!jW(m)){return function({fieldDef:t,fieldDef2:e,channel:n,band:r,scaleName:i,markDef:a,spacing:o=0,reverse:s}){const u={x:s?o:0,x2:s?0:o,y:s?0:o,y2:s?o:0},c=n===KL?YL:JL;return iq(t.bin)||t.timeUnit?{[c]:zG({channel:n,fieldDef:t,scaleName:i,markDef:a,band:(1-r)/2,offset:u[`${n}2`]}),[n]:zG({channel:n,fieldDef:t,scaleName:i,markDef:a,band:1-(1-r)/2,offset:u[n]})}:aq(t.bin)&&TV(e)?{[c]:vG(t,i,{},{offset:u[`${n}2`]}),[n]:vG(e,i,{},{offset:u[n]})}:void BU(jU.channelRequiredForBinned(c))}({fieldDef:d,fieldDef2:h,channel:e,markDef:c,scaleName:g,band:SV(e,d,void 0,c,s),spacing:uL(c.binSpacing,s[n].binSpacing),reverse:p.get("reverse")})}if((TV(d)&&jW(m)||b)&&!h){if(TV(d)&&m===OW.BAND){return function(t,e,n,r){var i;const a=n.scaleName(e),o="x"===e?"width":"height",{markDef:s,encoding:u,config:c}=n,l={[DG(e,s,c)]:vG(t,a,{},{band:.5})};if(u.size||null!==s.size&&void 0!==s.size){const t=s.orient;if(t){if(KV(u.size)||MV(u.size))return Object.assign(Object.assign({},l),wG("size",n,{vgChannel:o}));if(void 0!==s.size)return Object.assign(Object.assign({},l),{[o]:{value:s.size}})}else BU(jU.cannotApplySizeToNonOrientedMark(s.type))}if(void 0!==(null===(i=r)||void 0===i?void 0:i.value))return Object.assign(Object.assign({},l),{[o]:r});const{band:f=1}=t;return{[e]:vG(t,a,{binSuffix:"range"},{band:(1-f)/2}),[o]:null!==r&&void 0!==r?r:LG(a,f)}}(d,e,t,PG(n,c,f,g,p,s,FV(d)?d.band:void 0))}return function(t,e,n){const r="x"===t?"xc":"yc",i="x"===t?"width":"height";return Object.assign(Object.assign({},AG(t,e,{defaultPos:"mid",vgChannel:r})),wG("size",e,{defaultRef:n,vgChannel:i}))}(e,t,PG(n,c,f,g,p,s))}return RG(e,t,{defaultPos:"zeroOrMax",defaultPos2:"zeroOrMin"})}function PG(t,e,n,r,i,a,o){const s=uL(e[n],e.size,iV("size",e,a,{vgChannel:n}));if(void 0!==s)return{value:s};if(i){const e=i.get("type");if("point"===e||"band"===e){if(void 0!==a[t].discreteBandSize)return{value:a[t].discreteBandSize};if(e===OW.POINT){const t=i.get("range");return iG(t)&&OP(t.step)?{value:t.step-2}:{value:rH-2}}return LG(r,o)}return{value:a[t].continuousBandSize}}const u=eH(a.view,n);return{value:uL(a[t].discreteBandSize,u-2)}}function LG(t,e=!0){return{scale:t,band:e}}function zG({channel:t,fieldDef:e,scaleName:n,markDef:r,band:i,offset:a}){return mG({fieldDef:e,channel:t,markDef:r,ref:yG({scaleName:n,fieldDef:e,band:i,offset:a})})}function BG(t,e){const{fill:n,stroke:r}="include"===e.color?kG(t):{};return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},function(t,e){return oG.reduce((n,r)=>(void 0!==t[r]&&"ignore"!==e[r]&&(n[r]={value:t[r]}),n),{})}(t.markDef,e)),UG(t,"fill",n)),UG(t,"stroke",r)),wG("opacity",t)),wG("fillOpacity",t)),wG("strokeOpacity",t)),wG("strokeWidth",t)),OG(t)),_G(t,"href"))}function UG(t,e,n){const{config:r,mark:i,markDef:a}=t;if("hide"===rV("invalid",a,r)&&n&&!SL(i)){const r=function(t,{invalid:e=!1,channels:n}){const r=n.reduce((e,n)=>{const r=t.getScaleComponent(n);if(r){const i=r.get("type"),a=t.vgField(n,{expr:"datum"});a&&PW(i)&&(e[a]=!0)}return e},{}),i=JP(r);if(i.length>0){const t=e?"||":"&&";return i.map(t=>gG(t,e)).join(` ${t} `)}return}(t,{invalid:!0,channels:fB});if(r)return{[e]:[{test:r,value:null},...xP(n)]}}return n?{[e]:n}:{}}function WG(t){const{config:e,markDef:n}=t;if(rV("invalid",n,e)){const e=function(t,{invalid:e=!1,channels:n}){const r=n.reduce((e,n)=>{const r=t.getScaleComponent(n);if(r){const i=r.get("type"),a=t.vgField(n,{expr:"datum"});a&&PW(i)&&(e[a]=!0)}return e},{}),i=JP(r);if(i.length>0){const t=e?"||":"&&";return i.map(t=>gG(t,e)).join(` ${t} `)}return}(t,{channels:["x","y"]});if(e)return{defined:{signal:e}}}return{}}function VG(t,e){if(void 0!==e)return{[t]:{value:e}}}var qG={has:t=>"interval"!==t.type&&t.nearest,parse:(t,e)=>{if(e.events)for(const n of e.events)n.markname=t.getName("voronoi")},marks:(t,e,n)=>{const{x:r,y:i}=e.project.hasChannel,a=t.mark;if(SL(a))return BU(jU.nearestNotSupportForContinuous(a)),n;const o={name:t.getName("voronoi"),type:"path",interactive:!0,from:{data:t.getName("marks")},encode:{update:Object.assign({fill:{value:"transparent"},strokeWidth:{value:.35},stroke:{value:"transparent"},isVoronoi:{value:!0}},OG(t,{reactiveGeom:!0}))},transform:[{type:"voronoi",x:{expr:r||!i?"datum.datum.x || 0":"0"},y:{expr:i||!r?"datum.datum.y || 0":"0"},size:[t.getSizeSignalRef("width"),t.getSizeSignalRef("height")]}]};let s=0,u=!1;return n.forEach((e,n)=>{var r;const i=null!==(r=e.name)&&void 0!==r?r:"";i===t.component.mark[0].name?s=n:i.indexOf("voronoi")>=0&&(u=!0)}),u||n.splice(s+1,0,o),n}};class HG{constructor(t,e){this.debugName=e,this._children=[],this._parent=null,t&&(this.parent=t)}clone(){throw new Error("Cannot clone node")}get parent(){return this._parent}set parent(t){this._parent=t,t&&t.addChild(this)}get children(){return this._children}numChildren(){return this._children.length}addChild(t,e){this._children.indexOf(t)>-1?console.warn("Attempt to add the same child twice."):void 0!==e?this._children.splice(e,0,t):this._children.push(t)}removeChild(t){const e=this._children.indexOf(t);return this._children.splice(e,1),e}remove(){let t=this._parent.removeChild(this);for(const e of this._children)e._parent=this._parent,this._parent.addChild(e,t++)}insertAsParentOf(t){const e=t.parent;e.removeChild(this),this.parent=e,t.parent=this}swapWithParent(){const t=this._parent,e=t.parent;for(const e of this._children)e.parent=t;this._children=[],t.removeChild(this),t.parent.removeChild(t),this.parent=e,t.parent=this}}class GG extends HG{constructor(t,e,n,r){super(t,e),this.type=n,this.refCounts=r,this._source=this._name=e,!this.refCounts||this._name in this.refCounts||(this.refCounts[this._name]=0)}clone(){const t=new this.constructor;return t.debugName="clone_"+this.debugName,t._source=this._source,t._name="clone_"+this._name,t.type=this.type,t.refCounts=this.refCounts,t.refCounts[t._name]=0,t}dependentFields(){return new Set}producedFields(){return new Set}hash(){return void 0===this._hash&&(this._hash=`Output ${lL()}`),this._hash}getSource(){return this.refCounts[this._name]++,this._source}isRequired(){return!!this.refCounts[this._name]}setSource(t){this._source=t}}class $G extends HG{constructor(t,e){super(t),this.formula=e}clone(){return new $G(null,PP(this.formula))}static makeFromEncoding(t,e){const n=e.reduceFieldDef((t,n,r)=>{const{timeUnit:i,field:a}=n,o=nY(e)?e.encoding[Bz(r)]:void 0,s=nY(e)&&CV(r,n,o,e.markDef,e.config);if(i){const e=PV(n,{forAs:!0});t[UP({as:e,timeUnit:i,field:a})]=Object.assign({as:e,timeUnit:i,field:a},s?{band:!0}:{})}return t},{});return 0===JP(n).length?null:new $G(t,n)}static makeFromTransform(t,e){const n=Object.assign({},e);return new $G(t,{[UP(n)]:n})}merge(t){this.formula=Object.assign({},this.formula);for(const e in t.formula)this.formula[e]&&!t.formula[e].band||(this.formula[e]=t.formula[e]);for(const e of t.children)t.removeChild(e),e.parent=this;t.remove()}producedFields(){return new Set(ZP(this.formula).map(t=>t.as))}dependentFields(){return new Set(ZP(this.formula).map(t=>t.field))}hash(){return`TimeUnit ${UP(this.formula)}`}assemble(){const t=[];for(const e of ZP(this.formula)){const{timeUnit:n,field:r,as:i}=e;t.push({field:r,type:"timeunit",units:nW(n),as:[i,`${i}_end`]})}return t}}const KG="_tuple_fields";var XG={has:t=>"single"===t.type&&"global"===t.resolve&&t.bind&&"scales"!==t.bind&&!Gq(t.bind),parse:(t,e,n,r)=>{r.on||delete e.events,r.clear||delete e.clear},topLevelSignals:(t,e,n)=>{const r=e.name,i=e.project,a=e.bind,o=e.init&&e.init[0],s=qG.has(e)?"(item().isVoronoi ? datum.datum : datum)":"datum";return i.items.forEach((t,i)=>{var u,c;const l=tL(`${r}_${t.field}`);n.filter(t=>t.name===l).length||n.unshift(Object.assign(Object.assign({name:l},o?{init:c$(o[i])}:{value:null}),{on:e.events?[{events:e.events,update:`datum && item().mark.marktype !== 'group' ? ${s}[${hP(t.field)}] : null`}]:[],bind:(u=a[t.field],c=null!==u&&void 0!==u?u:a[t.channel],null!==c&&void 0!==c?c:a)}))}),n},signals:(t,e,n)=>{const r=e.name,i=e.project,a=n.filter(t=>t.name===r+x$)[0],o=r+KG,s=i.items.map(t=>tL(`${r}_${t.field}`)),u=s.map(t=>`${t} !== null`).join(" && ");return s.length&&(a.update=`${u} ? {fields: ${o}, values: [${s.join(", ")}]} : null`),delete a.value,delete a.on,n}};var YG={has:t=>"multi"===t.type&&!!t.toggle,signals:(t,e,n)=>n.concat({name:e.name+"_toggle",value:!1,on:[{events:e.events,update:e.toggle}]}),modifyExpr:(t,e)=>{const n=e.name+x$,r=e.name+"_toggle";return`${r} ? null : ${n}, `+("global"===e.resolve?`${r} ? null : true, `:`${r} ? null : {unit: ${O$(t)}}, `)+`${r} ? ${n} : null`}};var JG={has:t=>"interval"===t.type&&"global"===t.resolve&&t.bind&&"scales"===t.bind,parse:(t,e)=>{const n=e.scales=[];for(const r of e.project.items){const i=r.channel;if(!dB(i))continue;const a=t.getScaleComponent(i),o=a?a.get("type"):void 0;if(!a||!PW(o)){BU(jU.SCALE_BINDINGS_CONTINUOUS);continue}const s={selection:e.name,field:r.field};if(a.set("selectionExtent",s,!0),n.push(r),t.repeater&&t.repeater.row===t.repeater.column){t.getScaleComponent(i===KL?XL:KL).set("selectionExtent",s,!0)}}},topLevelSignals:(t,e,n)=>{const r=e.scales.filter(t=>0===n.filter(e=>e.name===t.signals.data).length);if(!t.parent||QG(t)||0===r.length)return n;const i=n.filter(t=>t.name===e.name)[0];let a=i.update;if(a.indexOf(k$)>=0)i.update=`{${r.map(t=>`${hP(t.field)}: ${t.signals.data}`).join(", ")}}`;else{for(const t of r){const e=`${hP(t.field)}: ${t.signals.data}`;a.indexOf(e)<0&&(a=`${a.substring(0,a.length-1)}, ${e}}`)}i.update=a}return n.concat(r.map(t=>({name:t.signals.data})))},signals:(t,e,n)=>{if(t.parent&&!QG(t))for(const t of e.scales){const e=n.filter(e=>e.name===t.signals.data)[0];e.push="outer",delete e.value,delete e.update}return n}};function ZG(t,e){return`domain(${hP(t.scaleName(e))})`}function QG(t){var e;return t.parent&&oY(t.parent)&&(null!==(e=!t.parent.parent)&&void 0!==e?e:QG(t.parent.parent))}const t$={has:t=>{const e="global"===t.resolve&&t.bind&&Gq(t.bind),n=1===t.project.items.length&&t.project.items[0].field!==qq;return e&&!n&&BU(jU.LEGEND_BINDINGS_PROJECT_LENGTH),e&&n},parse:(t,e,n,r)=>{var i;if(r.on||delete e.events,r.clear||delete e.clear,r.on||r.clear){const t='event.item && indexof(event.item.mark.role, "legend") < 0';for(const n of e.events)n.filter=xP(null!==(i=n.filter)&&void 0!==i?i:[]),n.filter.indexOf(t)<0&&n.filter.push(t)}const a=$q(e.bind)?e.bind.legend:"click",o=dP(a)?ZM(a,"view"):xP(a);e.bind={legend:{merge:o}}},topLevelSignals:(t,e,n)=>{const r=e.name,i=$q(e.bind)&&e.bind.legend,a=t=>e=>{const n=PP(e);return n.markname=t,n};for(const t of e.project.items){if(!t.hasLegend)continue;const o=`${t.field}_legend`,s=`${r}_${o}`;if(0===n.filter(t=>t.name===s).length){const t=i.merge.map(a(`${o}_symbols`)).concat(i.merge.map(a(`${o}_labels`))).concat(i.merge.map(a(`${o}_entries`)));n.unshift(Object.assign(Object.assign({name:s},e.init?{}:{value:null}),{on:[{events:t,update:"datum.value || item().items[0].items[0].datum.value",force:!0},{events:i.merge,update:`!event.item || !datum ? null : ${s}`,force:!0}]}))}}return n},signals:(t,e,n)=>{const r=e.name,i=e.project,a=n.find(t=>t.name===r+x$),o=r+KG,s=i.items.filter(t=>t.hasLegend).map(t=>tL(`${r}_${t.field}_legend`)),u=`${s.map(t=>`${t} !== null`).join(" && ")} ? {fields: ${o}, values: [${s.join(", ")}]} : null`;e.events&&s.length>0?a.on.push({events:s.map(t=>({signal:t})),update:u}):s.length>0&&(a.update=u,delete a.value,delete a.on);const c=n.find(t=>t.name===r+"_toggle"),l=$q(e.bind)&&e.bind.legend;return c&&(e.events?c.on.push(Object.assign(Object.assign({},c.on[0]),{events:l})):c.on[0].events=l),n}};const e$="_translate_anchor",n$="_translate_delta";function r$(t,e,n,r,i){var a;const o=e.name,s=o+e$,u=o+n$,c=n.channel,l=JG.has(e),f=i.filter(t=>t.name===n.signals[l?"data":"visual"])[0],d=t.getSizeSignalRef(r).signal,h=t.getScaleComponent(c),p=h.get("type"),m=`${s}.extent_${c}`,g=`${l?"log"===p?"panLog":"pow"===p?"panPow":"panLinear":"panLinear"}(${m}, ${`${l&&c===KL?"-":""}${u}.${c} / `+(l?`${d}`:`span(${m})`)}`+(l&&"pow"===p?`, ${a=h.get("exponent"),null!==a&&void 0!==a?a:1}`:"")+")";f.on.push({events:{signal:u},update:l?g:`clampRange(${g}, 0, ${d})`})}const i$="_zoom_anchor",a$="_zoom_delta";function o$(t,e,n,r,i){var a;const o=e.name,s=n.channel,u=JG.has(e),c=i.filter(t=>t.name===n.signals[u?"data":"visual"])[0],l=t.getSizeSignalRef(r).signal,f=t.getScaleComponent(s),d=f.get("type"),h=u?ZG(t,s):c.name,p=o+a$,m=`${u?"log"===d?"zoomLog":"pow"===d?"zoomPow":"zoomLinear":"zoomLinear"}(${h}, ${`${o}${i$}.${s}`}, ${p}`+(u&&"pow"===d?`, ${a=f.get("exponent"),null!==a&&void 0!==a?a:1}`:"")+")";c.on.push({events:{signal:p},update:u?m:`clampRange(${m}, 0, ${l})`})}const s$=[{has:()=>!0,parse:(t,e,n)=>{var r,i,a;const o=e.name,s=null!==(r=e.project)&&void 0!==r?r:e.project=new class{constructor(...t){this.items=t,this.hasChannel={},this.hasField={}}},u={},c={},l=new Set,f=(t,e)=>{const n="visual"===e?t.channel:t.field;let r=tL(`${o}_${n}`);for(let t=1;l.has(r);t++)r=tL(`${o}_${n}_${t}`);return l.add(r),{[e]:r}};if(!n.fields&&!n.encodings){const e=t.config.selection[n.type];if(n.init)for(const t of xP(n.init))for(const r of JP(t))Fz(r)?(n.encodings||(n.encodings=[])).push(r):"interval"===n.type?(BU('Interval selections should be initialized using "x" and/or "y" keys.'),n.encodings=e.encodings):(n.fields||(n.fields=[])).push(r);else n.encodings=e.encodings,n.fields=e.fields}for(const t of null!==(i=n.fields)&&void 0!==i?i:[]){const e={type:"E",field:t};e.signals=Object.assign({},f(e,"data")),s.items.push(e),s.hasField[t]=e}for(const r of null!==(a=n.encodings)&&void 0!==a?a:[]){const n=t.fieldDef(r);if(n){let i=n.field;if(n.aggregate){BU(jU.cannotProjectAggregate(r,n.aggregate));continue}if(!i){BU(jU.cannotProjectOnChannelWithoutField(r));continue}if(n.timeUnit){const e={as:i=t.vgField(r),field:n.field,timeUnit:n.timeUnit};c[UP(e)]=e}if(!u[i]){let a="E";if("interval"===e.type){PW(t.getScaleComponent(r).get("type"))&&(a="R")}else n.bin&&(a="R-RE");const o={field:i,channel:r,type:a};o.signals=Object.assign(Object.assign({},f(o,"data")),f(o,"visual")),s.items.push(u[i]=o),s.hasField[i]=s.hasChannel[r]=u[i]}}else BU(jU.cannotProjectOnChannelWithoutField(r))}if(n.init){const t=t=>s.items.map(e=>void 0!==t[e.channel]?t[e.channel]:t[e.field]);if("interval"===n.type)e.init=t(n.init);else{const r=lP(n.init)?n.init:[n.init];e.init=r.map(t)}}JP(c).length>0&&(s.timeUnit=new $G(null,c))},signals:(t,e,n)=>{const r=e.name+KG;return n.filter(t=>t.name===r).length>0?n:n.concat({name:r,value:e.project.items.map(t=>{const{signals:e,hasLegend:n}=t,r=b(t,["signals","hasLegend"]),i=PP(r);return i.field=aL(i.field),i})})}},YG,JG,t$,{has:t=>"interval"===t.type&&t.translate,signals:(t,e,n)=>{const r=e.name,i=JG.has(e),a=r+e$,{x:o,y:s}=e.project.hasChannel;let u=ZM(e.translate,"scope");return i||(u=u.map(t=>(t.between[0].markname=r+d$,t))),n.push({name:a,value:{},on:[{events:u.map(t=>t.between[0]),update:"{x: x(unit), y: y(unit)"+(void 0!==o?", extent_x: "+(i?ZG(t,KL):`slice(${o.signals.visual})`):"")+(void 0!==s?", extent_y: "+(i?ZG(t,XL):`slice(${s.signals.visual})`):"")+"}"}]},{name:r+n$,value:{},on:[{events:u,update:`{x: ${a}.x - x(unit), y: ${a}.y - y(unit)}`}]}),void 0!==o&&r$(t,e,o,"width",n),void 0!==s&&r$(t,e,s,"height",n),n}},{has:t=>"interval"===t.type&&t.zoom,signals:(t,e,n)=>{const r=e.name,i=JG.has(e),a=r+a$,{x:o,y:s}=e.project.hasChannel,u=hP(t.scaleName(KL)),c=hP(t.scaleName(XL));let l=ZM(e.zoom,"scope");return i||(l=l.map(t=>(t.markname=r+d$,t))),n.push({name:r+i$,on:[{events:l,update:i?"{"+[u?`x: invert(${u}, x(unit))`:"",c?`y: invert(${c}, y(unit))`:""].filter(t=>!!t).join(", ")+"}":"{x: x(unit), y: y(unit)}"}]},{name:a,on:[{events:l,force:!0,update:"pow(1.001, event.deltaY * pow(16, event.deltaMode))"}]}),void 0!==o&&o$(t,e,o,"width",n),void 0!==s&&o$(t,e,s,"height",n),n}},XG,qG,{has:t=>void 0!==t.clear&&!1!==t.clear,parse:(t,e,n)=>{n.clear&&(e.clear=dP(n.clear)?ZM(n.clear,"scope"):n.clear)},topLevelSignals:(t,e,n)=>(XG.has(e)&&e.project.items.forEach(t=>{const r=n.findIndex(n=>n.name===tL(`${e.name}_${t.field}`));-1!==r&&n[r].on.push({events:e.clear,update:"null"})}),n),signals:(t,e,n)=>{function r(t,r){-1!==t&&n[t].on&&n[t].on.push({events:e.clear,update:r})}if("interval"===e.type)e.project.items.forEach(t=>{const e=n.findIndex(e=>e.name===t.signals.visual);if(r(e,"[0, 0]"),-1===e){r(n.findIndex(e=>e.name===t.signals.data),"null")}});else{let t=n.findIndex(t=>t.name===e.name+x$);r(t,"null"),YG.has(e)&&r(t=n.findIndex(t=>t.name===e.name+"_toggle"),"false")}return n}}];function u$(t,e){for(const n of s$)n.has(t)&&e(n)}function c$(t,e=!0,n=mP){if(lP(t)){const r=t.map(t=>c$(t,e,n));return e?`[${r.join(", ")}]`:r}return WU(t)?n($U(t,!1,!e)):e?n(JSON.stringify(t)):t}function l$(t,e){return E$(t,(n,r)=>{e=r.marks?r.marks(t,n,e):e,u$(n,r=>{r.marks&&(e=r.marks(t,n,e))})}),e}function f$(t){return t.map(t=>(t.on&&!t.on.length&&delete t.on,t))}const d$="_brush",h$="_scale_trigger",p$={signals:(t,e)=>{const n=e.name,r=n+KG,i=JG.has(e),a=[],o=[],s=[];if(e.translate&&!i){const t=`!event.item || event.item.mark.name !== ${hP(n+d$)}`;m$(e,(e,n)=>{var r;const i=xP(null!==(r=n.between[0].filter)&&void 0!==r?r:n.between[0].filter=[]);return i.indexOf(t)<0&&i.push(t),e})}e.project.items.forEach((n,r)=>{const i=n.channel;if(i!==KL&&i!==XL)return void BU("Interval selections only support x and y encoding channels.");const u=e.init?e.init[r]:null,c=function(t,e,n,r){const i=n.channel,a=n.signals.visual,o=n.signals.data,s=JG.has(e),u=hP(t.scaleName(i)),c=t.getScaleComponent(i),l=c?c.get("type"):void 0,f=t=>`scale(${u}, ${t})`,d=t.getSizeSignalRef(i===KL?"width":"height").signal,h=`${i}(unit)`,p=m$(e,(t,e)=>[...t,{events:e.between[0],update:`[${h}, ${h}]`},{events:e,update:`[${a}[0], clamp(${h}, 0, ${d})]`}]);return p.push({events:{signal:e.name+h$},update:PW(l)?`[${f(`${o}[0]`)}, ${f(`${o}[1]`)}]`:"[0, 0]"}),s?[{name:o,on:[]}]:[Object.assign(Object.assign({name:a},r?{init:c$(r,!0,f)}:{value:[]}),{on:p}),Object.assign(Object.assign({name:o},r?{init:c$(r)}:{}),{on:[{events:{signal:a},update:`${a}[0] === ${a}[1] ? null : invert(${u}, ${a})`}]})]}(t,e,n,u),l=n.signals.data,f=n.signals.visual,d=hP(t.scaleName(i)),h=PW(t.getScaleComponent(i).get("type"))?"+":"";a.push(...c),o.push(l),s.push({scaleName:t.scaleName(i),expr:`(!isArray(${l}) || `+`(${h}invert(${d}, ${f})[0] === ${h}${l}[0] && `+`${h}invert(${d}, ${f})[1] === ${h}${l}[1]))`})}),i||a.push({name:n+h$,value:{},on:[{events:s.map(t=>({scale:t.scaleName})),update:s.map(t=>t.expr).join(" && ")+` ? ${n+h$} : {}`}]});const u=e.init,c=`unit: ${O$(t)}, fields: ${r}, values`;return a.concat(Object.assign(Object.assign({name:n+x$},u?{init:`{${c}: ${c$(u)}}`}:{}),{on:[{events:[{signal:o.join(" || ")}],update:o.join(" && ")+` ? {${c}: [${o}]} : null`}]}))},modifyExpr:(t,e)=>{return e.name+x$+", "+("global"===e.resolve?"true":`{unit: ${O$(t)}}`)},marks:(t,e,n)=>{const r=e.name,{x:i,y:a}=e.project.hasChannel,o=i&&i.signals.visual,s=a&&a.signals.visual,u=`data(${hP(e.name+b$)})`;if(JG.has(e))return n;const c={x:void 0!==i?{signal:`${o}[0]`}:{value:0},y:void 0!==a?{signal:`${s}[0]`}:{value:0},x2:void 0!==i?{signal:`${o}[1]`}:{field:{group:"width"}},y2:void 0!==a?{signal:`${s}[1]`}:{field:{group:"height"}}};if("global"===e.resolve)for(const e of JP(c))c[e]=[Object.assign({test:`${u}.length && ${u}[0].unit === ${O$(t)}`},c[e]),{value:0}];const l=e.mark,{fill:f,fillOpacity:d}=l,h=b(l,["fill","fillOpacity"]),p=JP(h).reduce((t,e)=>(t[e]=[{test:[void 0!==i&&`${o}[0] !== ${o}[1]`,void 0!==a&&`${s}[0] !== ${s}[1]`].filter(t=>t).join(" && "),value:h[e]},{value:null}],t),{});return[{name:r+d$+"_bg",type:"rect",clip:!0,encode:{enter:{fill:{value:f},fillOpacity:{value:d}},update:c}},...n,{name:r+d$,type:"rect",clip:!0,encode:{enter:{fill:{value:"transparent"}},update:Object.assign(Object.assign({},c),p)}}]}};function m$(t,e){return t.events.reduce((t,n)=>n.between?e(t,n):(BU(`${n} is not an ordered event stream for interval selections.`),t),[])}function g$(t,e){const n=e.name,r=n+KG,i="(item().isVoronoi ? datum.datum : datum)",a=e.project.items.map(e=>{const n=t.fieldDef(e.channel);return n&&n.bin?`[${i}[${hP(t.vgField(e.channel,{}))}], `+`${i}[${hP(t.vgField(e.channel,{binSuffix:"end"}))}]]`:`${i}[${hP(e.field)}]`}).join(", "),o=`unit: ${O$(t)}, fields: ${r}, values`,s=e.events;return[{name:n+x$,on:s?[{events:s,update:`datum && item().mark.marktype !== 'group' ? {${o}: [${a}]} : null`,force:!0}]:[]}]}const v$={signals:g$,modifyExpr:(t,e)=>{return e.name+x$+", "+("global"===e.resolve?"null":`{unit: ${O$(t)}}`)}};const y$={signals:g$,modifyExpr:(t,e)=>{return e.name+x$+", "+("global"===e.resolve?"true":`{unit: ${O$(t)}}`)}};const b$="_store",x$="_tuple",w$="_modify",k$="vlSelectionResolve",_$={single:y$,multi:v$,interval:p$};function E$(t,e){const n=t.component.selection;if(n)for(const t in n)if(_P(n,t)){const r=n[t];if(!0===e(r,_$[r.type]))break}}function O$(t,{escape:e}={escape:!0}){let n=e?hP(t.name):t.name;const r=function(t){let e=t.parent;for(;e&&!rY(e);)e=e.parent;return e}(t);if(r){const{facet:t}=r;for(const e of Ez)t[e]&&(n+=` + '__facet_${e}_' + (facet[${hP(r.vgField(e))}])`)}return n}function S$(t){let e=!1;return E$(t,t=>{e=e||t.project.items.some(t=>t.field===qq)}),e}function C$(t){const e=tT(t),n=new Set;return e.visit(t=>{"MemberExpression"===t.type&&function t(e){return"MemberExpression"===e.object.type?t(e.object):"datum"===e.object.name}(t)&&n.add(function t(e){const n=[];return"Identifier"===e.type?[e.name]:"Literal"===e.type?[e.value]:("MemberExpression"===e.type&&(n.push(...t(e.object)),n.push(...t(e.property))),n)}(t).slice(1).join("."))}),n}class A$ extends HG{constructor(t,e,n){super(t),this.model=e,this.filter=n,this.expr=I$(this.model,this.filter,this),this._dependentFields=C$(this.expr)}clone(){return new A$(null,this.model,PP(this.filter))}dependentFields(){return this._dependentFields}producedFields(){return new Set}assemble(){return{type:"filter",expr:this.expr}}hash(){return`Filter ${this.expr}`}}function N$(t,e,n,r="datum"){const i=[];const a=eL(e,function(e){const a=tL(e),o=t.getSelectionComponent(a,e),s=hP(a+b$);if(o.project.timeUnit){const e=null!==n&&void 0!==n?n:t.component.data.raw,r=o.project.timeUnit.clone();e.parent?r.insertAsParentOf(e):e.parent=r}return"none"!==o.empty&&i.push(s),`vlSelectionTest(${s}, ${r}`+("global"===o.resolve?")":`, ${hP(o.resolve)})`)});return(i.length?"!("+i.map(t=>`length(data(${t}))`).join(" || ")+") || ":"")+`(${a})`}function T$(t,e){const n=e.encoding;let r=e.field;if(n||r){if(n&&!r){const i=t.project.items.filter(t=>t.channel===n);!i.length||i.length>1?(r=t.project.items[0].field,BU((i.length?"Multiple ":"No ")+`matching ${hP(n)} encoding found for selection ${hP(e.selection)}. `+`Using "field": ${hP(r)}.`)):r=i[0].field}}else r=t.project.items[0].field,t.project.items.length>1&&BU('A "field" or "encoding" must be specified when using a selection as a scale domain. '+`Using "field": ${hP(r)}.`);return`${t.name}[${hP(r)}]`}function I$(t,e,n){return eL(e,e=>dP(e)?e:function(t){var e;return null===(e=t)||void 0===e?void 0:e.selection}(e)?N$(t,e.selection,n):gW(e))}function D$(t,e,n,r){var i,a,o;t.encode=null!==(i=t.encode)&&void 0!==i?i:{},t.encode[e]=null!==(a=t.encode[e])&&void 0!==a?a:{},t.encode[e].update=null!==(o=t.encode[e].update)&&void 0!==o?o:{},t.encode[e].update[n]=r}function M$(t,e,n,r={header:!1}){var i,a;const o=t.combine(),{orient:s,scale:u,labelExpr:c,title:l,zindex:f}=o,d=b(o,["orient","scale","labelExpr","title","zindex"]);if(JP(d).forEach(t=>{const n=lG[t],r=d[t];if(n&&n!==e&&"both"!==n)delete d[t];else if(function(t){return t.condition}(r)){const{vgProp:e,part:n}=uG[t],{condition:i,value:a}=r,o=[...(lP(i)?i:[i]).map(t=>{const{value:e,test:n}=t;return{test:I$(null,n),value:e}}),{value:a}];D$(d,n,e,o),delete d[t]}}),"grid"===e){if(!d.grid)return;if(d.encode){const{grid:t}=d.encode;d.encode=Object.assign({},t?{grid:t}:{}),0===JP(d.encode).length&&delete d.encode}return Object.assign(Object.assign({scale:u,orient:s},d),{domain:!1,labels:!1,maxExtent:0,minExtent:0,ticks:!1,zindex:uL(f,0)})}{if(!r.header&&t.mainExtracted)return;if(void 0!==c){let t=c;(null===(a=null===(i=d.encode)||void 0===i?void 0:i.labels)||void 0===a?void 0:a.update)&&rG(d.encode.labels.update.text)&&(t=oL(c,"datum.label",d.encode.labels.update.text.signal)),D$(d,"labels","text",{signal:t})}if(d.encode){for(const e of cG)t.hasAxisPart(e)||delete d.encode[e];0===JP(d.encode).length&&delete d.encode}const e=function(t,e){if(t)return tV(t)?t:t.map(t=>HV(t,e)).join(", ")}(l,n);return Object.assign(Object.assign(Object.assign({scale:u,orient:s,grid:!1},e?{title:e}:{}),d),{zindex:uL(f,0)})}}function R$(t){const{axes:e}=t.component;for(const n of Zz)if(e[n])for(const r of e[n])if(!r.get("gridScale")){const e="x"===n?"height":"width";return[{name:e,update:t.getSizeSignalRef(e).signal}]}return[]}const F$={titleAlign:"align",titleAnchor:"anchor",titleAngle:"angle",titleBaseline:"baseline",titleColor:"color",titleFont:"font",titleFontSize:"fontSize",titleFontStyle:"fontStyle",titleFontWeight:"fontWeight",titleLimit:"limit",titleLineHeight:"lineHeight",titleOrient:"orient",titlePadding:"offset"},j$={labelAlign:"align",labelAnchor:"anchor",labelAngle:"angle",labelColor:"color",labelFont:"font",labelFontSize:"fontSize",labelFontStyle:"fontStyle",labelLimit:"limit",labelOrient:"orient",labelPadding:"offset"},P$=JP(F$),L$=JP(j$);function z$(t,e,n,r,i){var a;const o=[..."band"===i?["axisBand"]:[],"x"===n?"axisX":"axisY",...r?["axis"+r.substr(0,1).toUpperCase()+r.substr(1)]:[],"axis"];for(const n of o)if(void 0!==(null===(a=e[n])||void 0===a?void 0:a[t]))return e[n][t]}function B$(t,e){if(void 0!==t)return t=fL(t),"top"===e||"bottom"===e?t<=45||315<=t?"top"===e?"bottom":"top":135<=t&&t<=225?"top"===e?"top":"bottom":"middle":t<=45||315<=t||135<=t&&t<=225?"middle":45<=t&&t<=135?"left"===e?"top":"bottom":"left"===e?"bottom":"top"}function U$(t,e){if(void 0!==t)return t=fL(t),"top"===e||"bottom"===e?t%180==0?"center":0<t&&t<180?"top"===e?"right":"left":"top"===e?"left":"right":(t+90)%180==0?"center":90<=t&&t<270?"left"===e?"left":"right":"left"===e?"right":"left"}function W$(t){switch(t){case KL:return"bottom";case XL:return"left"}throw new Error(jU.INVALID_CHANNEL_FOR_AXIS)}class V$ extends HG{constructor(t,e){super(t),this.transform=e,this._dependentFields=C$(this.transform.calculate)}clone(){return new V$(null,PP(this.transform))}static parseAllForSortIndex(t,e){return e.forEachFieldDef((e,n)=>{if(RV(e)&&wV(e.sort)){const{field:r,timeUnit:i}=e,a=e.sort,o=a.map((t,e)=>`${gW({field:r,timeUnit:i,equal:t})} ? ${e} : `).join("")+a.length;t=new V$(t,{calculate:o,as:q$(e,n,{forAs:!0})})}}),t}producedFields(){return new Set([this.transform.as])}dependentFields(){return this._dependentFields}assemble(){return{type:"formula",expr:this.transform.calculate,as:this.transform.as}}hash(){return`Calculate ${UP(this.transform)}`}}function q$(t,e,n){return PV(t,Object.assign({prefix:e,suffix:"sort_index"},null!==n&&void 0!==n?n:{}))}function H$(t,e){return VP(["top","bottom"],e)?"column":VP(["left","right"],e)?"row":"row"===t?"row":"column"}function G$(t,e,n,r){const i="row"===r?n.headerRow:"column"===r?n.headerColumn:n.headerFacet;return uL(e&&e.header?e.header[t]:void 0,i[t],n.header[t])}function $$(t,e,n,r){const i={};for(const a of t){const t=G$(a,e,n,r);void 0!==t&&(i[a]=t)}return i}const K$=["row","column"],X$=["header","footer"];function Y$(t,e){const n=t.component.layoutHeaders[e].title,r=t.config?t.config:void 0,i=t.component.layoutHeaders[e].facetFieldDef?t.component.layoutHeaders[e].facetFieldDef:void 0,{titleAnchor:a,titleAngle:o,titleOrient:s}=$$(["titleAnchor","titleAngle","titleOrient"],i,r,e),u=H$(e,s);return{name:`${e}-title`,type:"group",role:`${u}-title`,title:Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({text:n},"row"===e?{orient:"left"}:{}),{style:"guide-title"}),Z$(o,u)),J$(u,o,a)),iK(r,i,e,P$,F$))}}function J$(t,e,n="middle"){switch(n){case"start":return{align:"left"};case"end":return{align:"right"}}const r=U$(e,"row"===t?"left":"top");return r?{align:r}:{}}function Z$(t,e){const n=B$(t,"row"===e?"left":"top");return n?{baseline:n}:{}}function Q$(t,e){const n=t.component.layoutHeaders[e],r=[];for(const i of X$)if(n[i])for(const a of n[i])r.push(eK(t,e,i,n,a));return r}function tK(t,e,n){const{format:r,labelAngle:i,labelAnchor:a,labelOrient:o,labelExpr:s}=$$(["format","labelAngle","labelAnchor","labelOrient","labelExpr"],t,n,e),u=oV(t,r,"parent",n).signal,c=H$(e,o);return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({text:{signal:s?oL(oL(s,"datum.label",u),"datum.value",PV(t,{expr:"parent"})):u}},"row"===e?{orient:"left"}:{}),{style:"guide-label",frame:"group"}),Z$(i,c)),J$(c,i,a)),iK(n,t,e,L$,j$))}function eK(t,e,n,r,i){var a;if(i){let o=null;const{facetFieldDef:s}=r,u=t.config?t.config:void 0;if(s&&i.labels){const{labelOrient:t}=$$(["labelOrient"],s,u,e);("row"===e&&!VP(["top","bottom"],t)||"column"===e&&!VP(["left","right"],t))&&(o=tK(s,e,u))}const c=rY(t)&&!kV(t.facet),l=i.axes,f=(null===(a=l)||void 0===a?void 0:a.length)>0;if(o||f){const a="row"===e?"height":"width";return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({name:t.getName(`${e}_${n}`),type:"group",role:`${e}-${n}`},r.facetFieldDef?{from:{data:t.getName(e+"_domain")},sort:function(t,e){var n;const{sort:r}=t;return xV(r)?{field:PV(r,{expr:"datum"}),order:(n=r.order,null!==n&&void 0!==n?n:"ascending")}:lP(r)?{field:q$(t,e,{expr:"datum"}),order:"ascending"}:{field:PV(t,{expr:"datum"}),order:null!==r&&void 0!==r?r:"ascending"}}(s,e)}:{}),f&&c?{from:{data:t.getName(`facet_domain_${e}`)}}:{}),o?{title:o}:{}),i.sizeSignal?{encode:{update:{[a]:i.sizeSignal}}}:{}),f?{axes:l}:{})}}return null}const nK={column:{start:0,end:1},row:{start:1,end:0}};function rK(t,e){return nK[e][t]}function iK(t,e,n,r,i){const a={};for(const o of r){if(!i[o])continue;const r=G$(o,e,t,n);void 0!==r&&(a[i[o]]=r)}return a}function aK(t){return[...oK(t,"width"),...oK(t,"height")]}function oK(t,e){const n="width"===e?"x":"y",r=t.component.layoutSize.get(e);if(!r||"merged"===r)return[];const i=t.getSizeSignalRef(e).signal;if("step"===r){const e=t.getScaleComponent(n);if(e){const r=e.get("type"),a=e.get("range");if(jW(r)&&iG(a)){const r=t.scaleName(n);if(rY(t.parent)){if("independent"===t.parent.component.resolve.scale[n])return[sK(r,a)]}return[sK(r,a),{name:i,update:uK(r,e,`domain('${r}').length`)}]}}throw new Error("layout size is step although width/height is not step.")}if("container"==r){const e=i.endsWith("width"),n=e?"containerSize()[0]":"containerSize()[1]",r=`isFinite(${n}) ? ${n} : ${tH(t.config.view,e?"width":"height")}`;return[{name:i,init:r,on:[{update:r,events:"window:resize"}]}]}return[{name:i,value:r}]}function sK(t,e){return{name:t+"_step",value:e.step}}function uK(t,e,n){const r=e.get("type"),i=e.get("padding"),a=uL(e.get("paddingOuter"),i);let o=e.get("paddingInner");return`bandspace(${n}, ${o="band"===r?void 0!==o?o:i:1}, ${a}) * ${t}_step`}function cK(t,e){return JP(t).reduce((n,r)=>{const i=t[r];return Object.assign(Object.assign({},n),hG(e,i,r,t=>({value:t.value})))},{})}function lK(t,e){if(oY(e)||rY(e))return"shared";if(aY(e)||iY(e))return VP(Zz,t)?"independent":"shared";throw new Error("invalid model type for resolve")}function fK(t,e){const n=t.scale[e],r=VP(Zz,e)?"axis":"legend";return"independent"===n?("shared"===t[r][e]&&BU(jU.independentScaleMeansIndependentGuide(e)),"independent"):t[r][e]||"shared"}class dK{constructor(t={},e={}){this.explicit=t,this.implicit=e}clone(){return new dK(PP(this.explicit),PP(this.implicit))}combine(){return Object.assign(Object.assign({},this.explicit),this.implicit)}get(t){return uL(this.explicit[t],this.implicit[t])}getWithExplicit(t){return void 0!==this.explicit[t]?{explicit:!0,value:this.explicit[t]}:void 0!==this.implicit[t]?{explicit:!1,value:this.implicit[t]}:{explicit:!1,value:void 0}}setWithExplicit(t,e){void 0!==e.value&&this.set(t,e.value,e.explicit)}set(t,e,n){return delete this[n?"implicit":"explicit"][t],this[n?"explicit":"implicit"][t]=e,this}copyKeyFromSplit(t,e){void 0!==e.explicit[t]?this.set(t,e.explicit[t],!0):void 0!==e.implicit[t]&&this.set(t,e.implicit[t],!1)}copyKeyFromObject(t,e){void 0!==e[t]&&this.set(t,e[t],!0)}copyAll(t){for(const e of JP(t.combine())){const n=t.getWithExplicit(e);this.setWithExplicit(e,n)}}}function hK(t){return{explicit:!0,value:t}}function pK(t){return{explicit:!1,value:t}}function mK(t){return(e,n,r,i)=>{const a=t(e.value,n.value);return a>0?e:a<0?n:gK(e,n,r,i)}}function gK(t,e,n,r){return t.explicit&&e.explicit&&BU(jU.mergeConflictingProperty(n,r,t.value,e.value)),t}function vK(t,e,n,r,i=gK){return void 0===t||void 0===t.value?e:t.explicit&&!e.explicit?t:e.explicit&&!t.explicit?e:jP(t.value,e.value)?t:i(t,e,n,r)}const yK=Object.assign(Object.assign({},Vq),{labelExpr:1,selections:1,opacity:1,shape:1,stroke:1,fill:1,size:1,strokeWidth:1,strokeDash:1,encode:1}),bK=JP(yK);class xK extends dK{}function wK(t){const{legend:e}=t;return uL(e.type,kK(t))}function kK({channel:t,timeUnit:e,scaleType:n,alwaysReturn:r}){if(kz(t)){if(VP(["quarter","month","day"],e))return"symbol";if(LW(n))return r?"gradient":void 0}return r?"symbol":void 0}function _K({legend:t,legendConfig:e,timeUnit:n,channel:r,scaleType:i}){const a=uL(t.orient,e.orient,"right"),o=wK({legend:t,channel:r,timeUnit:n,scaleType:i,alwaysReturn:!0});return uL(t.direction,e[o?"gradientDirection":"symbolDirection"],function(t,e){switch(t){case"top":case"bottom":return"horizontal";case"left":case"right":case"none":case void 0:return;default:return"gradient"===e?"horizontal":void 0}}(a,o))}function EK(t,e,n,r){return{signal:`clamp(${t.getSizeSignalRef(e).signal}, ${n}, ${r})`}}function OK(t,e,n){const r=e.getScaleComponent(n).get("type");return uL(t.get("type"),kK({channel:n,scaleType:r,alwaysReturn:!0}))}function SK(t,e,n,r,i){var a,o,s,u,c;if("symbol"!==OK(i,n,r))return;let l=Object.assign(Object.assign({},function(t,e,n){for(const r of n){const n=iV(r,e.markDef,e.config);void 0!==n&&(t[r]={value:n})}return t}({},n,TL)),kG(n));const{markDef:f,encoding:d,config:h}=n,p=f.filled,m=null!==(a=TK(d.opacity))&&void 0!==a?a:f.opacity,g=MK(n,i,t);if(l.fill)if("fill"===r||p&&r===nz)delete l.fill;else if(l.fill.field)i.get("symbolFillColor")?delete l.fill:(l.fill={value:(o=h.legend.symbolBaseFillColor,null!==o&&void 0!==o?o:"black")},l.fillOpacity={value:null!==m&&void 0!==m?m:1});else if(lP(l.fill)){const t=null!==(c=null!==(u=IK(null!==(s=d.fill)&&void 0!==s?s:d.color))&&void 0!==u?u:f.fill)&&void 0!==c?c:p&&f.color;t&&(l.fill={value:t})}if(l.stroke)if("stroke"===r||!p&&r===nz)delete l.stroke;else if(l.stroke.field)delete l.stroke;else if(lP(l.stroke)){const t=uL(IK(d.stroke||d.color),f.stroke,p?f.color:void 0);t&&(l.stroke={value:t})}return r!==sz&&(g?l.opacity=[{test:g,value:null!==m&&void 0!==m?m:1},{value:h.legend.unselectedOpacity}]:m&&(l.opacity={value:m})),l=Object.assign(Object.assign({},l),e),JP(l).length>0?l:void 0}function CK(t,e,n,r,i){if("gradient"!==OK(i,n,r))return;let a={};const o=TK(n.encoding.opacity)||n.markDef.opacity;return o&&(a.opacity={value:o}),a=Object.assign(Object.assign({},a),e),JP(a).length>0?a:void 0}function AK(t,e,n,r,i){const a=n.legend(r),o=n.config,s=MK(n,i,t);let u={};if(QV(t)){const i=n.getScaleComponent(r).get("type")===OW.UTC,s=fV("datum.value",t.timeUnit,a.format,o.timeFormat,i);e=Object.assign(Object.assign({},s?{text:{signal:s}}:{}),e)}return s&&(e.opacity=[{test:s,value:1},{value:o.legend.unselectedOpacity}]),u=Object.assign(Object.assign({},u),e),JP(u).length>0?u:void 0}function NK(t,e,n,r,i){var a;return(null===(a=i.get("selections"))||void 0===a?void 0:a.length)?{fill:{value:"transparent"}}:void 0}function TK(t){return DK(t,(t,e)=>Math.max(t,e.value))}function IK(t){return DK(t,(t,e)=>uL(t,e.value))}function DK(t,e){return function(t){return!!t&&!!t.condition&&(lP(t.condition)||MV(t.condition))}(t)?(lP(t.condition)?t.condition:[t.condition]).reduce(e,t.value):MV(t)?t.value:void 0}function MK(t,e,n){var r;const i=e.get("selections");if(!(null===(r=i)||void 0===r?void 0:r.length))return;const a=hP(n.field);return i.map(t=>{return`(!length(data(${hP(tL(t)+b$)})) || (${t}[${a}] && indexof(${t}[${a}], datum.value) >= 0))`}).join(" || ")}function RK(t){nY(t)?t.component.legends=function(t){const{encoding:e}=t;return[nz,rz,iz,lz,oz,az,sz,uz,cz].reduce((n,r)=>{const i=e[r];return!t.legend(r)||!t.getScaleComponent(r)||TV(i)&&r===az&&i.type===EW||(n[r]=function(t,e){var n;const r=t.fieldDef(e),i=t.legend(e),a=new xK({},function(t,e){const n=t.scaleName(nz);if("color"===e)return t.markDef.filled?{fill:n}:{stroke:n};return{[e]:t.scaleName(e)}}(t,e));!function(t,e,n){const r=t.fieldDef(e).field;E$(t,t=>{var i,a;const o=null!==(i=t.project.hasField[r])&&void 0!==i?i:t.project.hasChannel[e];if(o&&t$.has(t)){const e=null!==(a=n.get("selections"))&&void 0!==a?a:[];e.push(t.name),n.set("selections",e,!1),o.hasLegend=!0}})}(t,e,a);for(const n of bK){const o=jK(n,i,e,t);if(void 0!==o){const e=FK(o,n,i,r);(e||void 0===t.config.legend[n])&&a.set(n,o,e)}}const o=null!==(n=i.encoding)&&void 0!==n?n:{},s=a.get("selections"),u=["labels","legend","title","symbols","gradient","entries"].reduce((n,i)=>{var u,c,l;const f=cK(null!==(u=o[i])&&void 0!==u?u:{},t),d=g[i]?g[i](r,f,t,e,a):f;return void 0!==d&&JP(d).length>0&&(n[i]=Object.assign(Object.assign(Object.assign({},(null===(c=s)||void 0===c?void 0:c.length)?{name:`${r.field}_legend_${i}`}:{}),(null===(l=s)||void 0===l?void 0:l.length)?{interactive:!!s}:{}),{update:d})),n},{});JP(u).length>0&&a.set("encode",u,!!i.encoding);return a}(t,r)),n},{})}(t):t.component.legends=function(t){const{legends:e,resolve:n}=t.component;for(const r of t.children)RK(r),JP(r.component.legends).forEach(i=>{n.legend[i]=fK(t.component.resolve,i),"shared"===n.legend[i]&&(e[i]=PK(e[i],r.component.legends[i]),e[i]||(n.legend[i]="independent",delete e[i]))});return JP(e).forEach(e=>{for(const r of t.children)r.component.legends[e]&&"shared"===n.legend[e]&&delete r.component.legends[e]}),e}(t)}function FK(t,e,n,r){switch(e){case"values":return!!n.values;case"title":if("title"===e&&t===r.title)return!0}return t===n[e]}function jK(t,e,n,r){const{encoding:i,mark:a}=r,o=KV(i[n]),s=r.config.legend,{timeUnit:u}=o,c=r.getScaleComponent(n).get("type");switch(t){case"direction":return _K({legend:e,legendConfig:s,timeUnit:u,channel:n,scaleType:c});case"format":if(QV(o))return;return sV(o,e.format,r.config);case"formatType":if(QV(o))return;return e.formatType;case"gradientLength":return uL(e.gradientLength,s.gradientLength,function({legend:t,legendConfig:e,model:n,channel:r,scaleType:i}){const{gradientHorizontalMaxLength:a,gradientHorizontalMinLength:o,gradientVerticalMaxLength:s,gradientVerticalMinLength:u}=e;if("horizontal"===_K({legend:t,legendConfig:e,channel:r,scaleType:i})){const r=uL(t.orient,e.orient);return"top"===r||"bottom"===r?EK(n,"width",o,a):o}return EK(n,"height",u,s)}({model:r,legend:e,legendConfig:s,channel:n,scaleType:c}));case"labelOverlap":return uL(e.labelOverlap,function(t){if(VP(["quantile","threshold","log"],t))return"greedy"}(c));case"symbolType":return uL(e.symbolType,function(t,e,n,r){var i;if("shape"!==e){const t=null!==(i=IK(n))&&void 0!==i?i:r;if(t)return t}switch(t){case"bar":case"rect":case"image":case"square":return"square";case"line":case"trail":case"rule":return"stroke";case"point":case"circle":case"tick":case"geoshape":case"area":case"text":return"circle"}}(a,n,i.shape,r.markDef.shape));case"title":return VV(o,r.config,{allowDisabling:!0})||void 0;case"type":return wK({legend:e,channel:n,timeUnit:u,scaleType:c,alwaysReturn:!1});case"values":return function(t,e){const n=t.values;if(n)return eq(e,n)}(e,o)}return e[t]}function PK(t,e){var n,r,i,a,o,s;if(!t)return e.clone();const u=t.getWithExplicit("orient"),c=e.getWithExplicit("orient");if(u.explicit&&c.explicit&&u.value!==c.value)return;let l=!1;for(const n of bK){const r=vK(t.getWithExplicit(n),e.getWithExplicit(n),n,"legend",(t,e)=>{switch(n){case"symbolType":return LK(t,e);case"title":return mV(t,e);case"type":return l=!0,pK("symbol")}return gK(t,e,n,"legend")});t.setWithExplicit(n,r)}return l&&((null===(i=null===(r=null===(n=t.implicit)||void 0===n?void 0:n.encode)||void 0===r?void 0:r.gradient)||void 0===i||i)&&nL(t.implicit,["encode","gradient"]),(null===(s=null===(o=null===(a=t.explicit)||void 0===a?void 0:a.encode)||void 0===o?void 0:o.gradient)||void 0===s||s)&&nL(t.explicit,["encode","gradient"])),t}function LK(t,e){return"circle"===e.value?e:t}function zK(t){const e=t.component.legends,n={};for(const r of JP(e)){const i=t.getScaleComponent(r),a=BP(i.get("domains"));if(n[a])for(const t of n[a]){PK(t,e[r])||n[a].push(e[r])}else n[a]=[e[r].clone()]}return ZP(n).flat().map(t=>{var e,n,r,i;const a=t.combine(),{labelExpr:o,selections:s}=a,u=b(a,["labelExpr","selections"]);if(null===(e=u.encode)||void 0===e?void 0:e.symbols){const t=u.encode.symbols.update;!t.fill||"transparent"===t.fill.value||t.stroke||u.stroke||(t.stroke={value:"transparent"}),u.fill&&delete t.fill}if(void 0!==o){let t=o;(null===(i=null===(r=null===(n=u.encode)||void 0===n?void 0:n.labels)||void 0===r?void 0:r.update)||void 0===i?void 0:i.text)&&rG(u.encode.labels.update.text)&&(t=oL(o,"datum.label",u.encode.labels.update.text.signal)),function(t,e,n,r){var i,a,o;t.encode=null!==(i=t.encode)&&void 0!==i?i:{},t.encode[e]=null!==(a=t.encode[e])&&void 0!==a?a:{},t.encode[e].update=null!==(o=t.encode[e].update)&&void 0!==o?o:{},t.encode[e].update[n]=r}(u,"labels","text",{signal:t})}return u})}function BK(t){return oY(t)||aY(t)||iY(t)?function(t){return t.children.reduce((t,e)=>t.concat(e.assembleProjections()),UK(t))}(t):UK(t)}function UK(t){const e=t.component.projection;if(!e||e.merged)return[];const n=e.combine(),{name:r}=n,i=b(n,["name"]);if(e.data){const n={signal:`[${e.size.map(t=>t.signal).join(", ")}]`},a=e.data.reduce((e,n)=>{const r=rG(n)?n.signal:`data('${t.lookupDataSource(n)}')`;return VP(e,r)||e.push(r),e},[]);if(a.length<=0)throw new Error("Projection's fit didn't find any data sources");return[Object.assign({name:r,size:n,fit:{signal:a.length>1?`[${a.join(", ")}]`:a[0]}},i)]}return[Object.assign(Object.assign({name:r},{translate:{signal:"[width / 2, height / 2]"}}),i)]}const WK=["type","clipAngle","clipExtent","center","rotate","precision","reflectX","reflectY","coefficient","distance","fraction","lobes","parallel","radius","ratio","spacing","tilt"];class VK extends dK{constructor(t,e,n,r){super(Object.assign({},e),{name:t}),this.specifiedProjection=e,this.size=n,this.data=r,this.merged=!1}get isFit(){return!!this.data}}function qK(t){t.component.projection=nY(t)?function(t){var e;if(t.hasProjection){const n=t.specifiedProjection,r=!(n&&(null!=n.scale||null!=n.translate)),i=r?[t.getSizeSignalRef("width"),t.getSizeSignalRef("height")]:void 0,a=r?function(t){const e=[];for(const n of[[QL,ZL],[ez,tz]])(t.channelHasField(n[0])||t.channelHasField(n[1]))&&e.push({signal:t.getName(`geojson_${e.length}`)});t.channelHasField(az)&&t.fieldDef(az).type===EW&&e.push({signal:t.getName(`geojson_${e.length}`)});0===e.length&&e.push(t.requestDataName(jH));return e}(t):void 0;return new VK(t.projectionName(!0),Object.assign(Object.assign({},null!==(e=t.config.projection)&&void 0!==e?e:{}),null!==n&&void 0!==n?n:{}),i,a)}return}(t):function(t){if(0===t.children.length)return;let e;t.children.forEach(t=>qK(t));const n=HP(t.children,t=>{const n=t.component.projection;if(n){if(e){const t=function(t,e){const n=HP(WK,n=>!_P(t.explicit,n)&&!_P(e.explicit,n)||!(!_P(t.explicit,n)||!_P(e.explicit,n)||BP(t.get(n))!==BP(e.get(n))));if(BP(t.size)===BP(e.size)){if(n)return t;if(BP(t.explicit)===BP({}))return e;if(BP(e.explicit)===BP({}))return t}return null}(e,n);return t&&(e=t),!!t}return e=n,!0}return!0});if(e&&n){const n=t.projectionName(!0),r=new VK(n,e.specifiedProjection,e.size,PP(e.data));return t.children.forEach(t=>{const e=t.component.projection;e&&(e.isFit&&r.data.push(...t.component.projection.data),t.renameProjection(e.get("name"),n),e.merged=!0)}),r}return}(t)}function HK(t,e){return`${rq(t)}_${e}`}function GK(t,e,n){var r;const i=HK(null!==(r=JV(n,void 0))&&void 0!==r?r:{},e);return t.getName(`${i}_bins`)}function $K(t,e,n){let r,i;r=function(t){return"as"in t}(t)?dP(t.as)?[t.as,`${t.as}_end`]:[t.as[0],t.as[1]]:[PV(t,{forAs:!0}),PV(t,{binSuffix:"end",forAs:!0})];const a=Object.assign({},JV(e,void 0)),o=HK(a,t.field),{signal:s,extentSignal:u}=function(t,e){return{signal:t.getName(`${e}_bins`),extentSignal:t.getName(`${e}_extent`)}}(n,o);if(sq(a.extent)){const t=a.extent,e=t.selection;i=T$(n.getSelectionComponent(tL(e),e),t),delete a.extent}return{key:o,binComponent:Object.assign(Object.assign(Object.assign({bin:a,field:t.field,as:[r]},s?{signal:s}:{}),u?{extentSignal:u}:{}),i?{span:i}:{})}}class KK extends HG{constructor(t,e){super(t),this.bins=e}clone(){return new KK(null,PP(this.bins))}static makeFromEncoding(t,e){const n=e.reduceFieldDef((t,n,r)=>{if(IV(n)&&iq(n.bin)){const{key:i,binComponent:a}=$K(n,n.bin,e);t[i]=Object.assign(Object.assign(Object.assign({},a),t[i]),function(t,e,n,r){var i,a;if(nq(e,n)){const o=nY(t)&&null!==(a=null!==(i=t.axis(n))&&void 0!==i?i:t.legend(n))&&void 0!==a?a:{},s=PV(e,{expr:"datum"}),u=PV(e,{expr:"datum",binSuffix:"end"});return{formulaAs:PV(e,{binSuffix:"range",forAs:!0}),formula:lV(s,u,o.format,r)}}return{}}(e,n,r,e.config))}return t},{});return 0===JP(n).length?null:new KK(t,n)}static makeFromTransform(t,e,n){const{key:r,binComponent:i}=$K(e,e.bin,n);return new KK(t,{[r]:i})}merge(t,e){for(const n of JP(t.bins))n in this.bins?(e(t.bins[n].signal,this.bins[n].signal),this.bins[n].as=$P([...this.bins[n].as,...t.bins[n].as],UP)):this.bins[n]=t.bins[n];for(const e of t.children)t.removeChild(e),e.parent=this;t.remove()}producedFields(){return new Set(ZP(this.bins).map(t=>t.as).flat(2))}dependentFields(){return new Set(ZP(this.bins).map(t=>t.field))}hash(){return`Bin ${UP(this.bins)}`}assemble(){return ZP(this.bins).flatMap(t=>{const e=[],[n,...r]=t.as,i=t.bin,{extent:a}=i,o=b(i,["extent"]),s=Object.assign(Object.assign(Object.assign({type:"bin",field:aL(t.field),as:n,signal:t.signal},sq(a)?{extent:null}:{extent:a}),t.span?{span:{signal:`span(${t.span})`}}:{}),o);!a&&t.extentSignal&&(e.push({type:"extent",field:aL(t.field),signal:t.extentSignal}),s.extent={signal:t.extentSignal}),e.push(s);for(const t of r)for(let r=0;r<2;r++)e.push({type:"formula",expr:PV({field:n[r]},{expr:"datum"}),as:t[r]});return t.formula&&e.push({type:"formula",expr:t.formula,as:t.formulaAs}),e})}}class XK extends HG{constructor(t){let e;if(super(null),DH(t=null!==t&&void 0!==t?t:{name:"source"})||(e=t.format?Object.assign({},zP(t.format,["parse"])):{}),TH(t))this._data={values:t.values};else if(NH(t)){if(this._data={url:t.url},!e.type){let n=/(?:\.([^.]+))?$/.exec(t.url)[1];VP(["json","csv","tsv","dsv","topojson"],n)||(n="json"),e.type=n}}else RH(t)?this._data={values:[{type:"Sphere"}]}:(IH(t)||DH(t))&&(this._data={});this._generator=DH(t),t.name&&(this._name=t.name),e&&JP(e).length>0&&(this._data.format=e)}dependentFields(){return new Set}producedFields(){}get data(){return this._data}hasName(){return!!this._name}get isGenerator(){return this._generator}get dataName(){return this._name}set dataName(t){this._name=t}set parent(t){throw new Error("Source nodes have to be roots.")}remove(){throw new Error("Source nodes are roots and cannot be removed.")}hash(){throw new Error("Cannot hash sources")}assemble(){return Object.assign(Object.assign({name:this._name},this._data),{transform:[]})}}function YK(t){for(const e of t){for(const t of e.children)if(t.parent!==e)return console.error("Dataflow graph is inconsistent.",e,t),!1;if(!YK(e.children))return!1}return!0}class JK extends HG{constructor(t,e){super(t),this.params=e}clone(){return new JK(null,this.params)}dependentFields(){return new Set}producedFields(){}hash(){return`Graticule ${UP(this.params)}`}assemble(){return Object.assign({type:"graticule"},!0===this.params?{}:this.params)}}class ZK extends HG{constructor(t,e){super(t),this.params=e}clone(){return new ZK(null,this.params)}dependentFields(){return new Set}producedFields(){var t;return new Set([(t=this.params.as,null!==t&&void 0!==t?t:"data")])}hash(){return`Hash ${UP(this.params)}`}assemble(){return Object.assign({type:"sequence"},this.params)}}function QK(t){return t instanceof XK||t instanceof JK||t instanceof ZK}class tX{constructor(){this._mutated=!1}setMutated(){this._mutated=!0}get mutatedFlag(){return this._mutated}}class eX extends tX{constructor(){super(),this._continue=!1}setContinue(){this._continue=!0}get continueFlag(){return this._continue}get flags(){return{continueFlag:this.continueFlag,mutatedFlag:this.mutatedFlag}}set flags({continueFlag:t,mutatedFlag:e}){t&&this.setContinue(),e&&this.setMutated()}reset(){}optimizeNextFromLeaves(t){if(QK(t))return!1;const e=t.parent,{continueFlag:n}=this.run(t);return n&&this.optimizeNextFromLeaves(e),this.mutatedFlag}}class nX extends tX{}function rX(t,e,n,r){const i=nY(r)?r.encoding[Bz(e)]:void 0;if(IV(n)&&nY(r)&&CV(e,n,i,r.markDef,r.config))t.add(PV(n,{})),t.add(PV(n,{suffix:"end"})),nq(n,e)&&t.add(PV(n,{binSuffix:"range"}));else if(function(t){return t in bz}(e)){const n=function(t){switch(t){case ZL:return"y";case tz:return"y2";case QL:return"x";case ez:return"x2"}}(e);t.add(r.getName(n))}else t.add(PV(n));return t}class iX extends HG{constructor(t,e,n){super(t),this.dimensions=e,this.measures=n}clone(){return new iX(null,new Set(this.dimensions),PP(this.measures))}get groupBy(){return this.dimensions}static makeFromEncoding(t,e){let n=!1;e.forEachFieldDef(t=>{t.aggregate&&(n=!0)});const r={},i=new Set;return n?(e.forEachFieldDef((t,n)=>{var a,o,s,u;const{aggregate:c,field:l}=t;if(c)if("count"===c)r["*"]=null!==(a=r["*"])&&void 0!==a?a:{},r["*"].count=new Set([PV(t,{forAs:!0})]);else{if(LL(c)||zL(c)){const t=LL(c)?"argmin":"argmax",e=c[t];r[e]=null!==(o=r[e])&&void 0!==o?o:{},r[e][t]=new Set([PV({op:t,field:e},{forAs:!0})])}else r[l]=null!==(s=r[l])&&void 0!==s?s:{},r[l][c]=new Set([PV(t,{forAs:!0})]);dB(n)&&"unaggregated"===e.scaleDomain(n)&&(r[l]=null!==(u=r[l])&&void 0!==u?u:{},r[l].min=new Set([PV({field:l,aggregate:"min"},{forAs:!0})]),r[l].max=new Set([PV({field:l,aggregate:"max"},{forAs:!0})]))}else rX(i,n,t,e)}),i.size+JP(r).length===0?null:new iX(t,i,r)):null}static makeFromTransform(t,e){var n,r,i;const a=new Set,o={};for(const t of e.aggregate){const{op:e,field:i,as:a}=t;e&&("count"===e?(o["*"]=null!==(n=o["*"])&&void 0!==n?n:{},o["*"].count=new Set([a||PV(t,{forAs:!0})])):(o[i]=null!==(r=o[i])&&void 0!==r?r:{},o[i][e]=new Set([a||PV(t,{forAs:!0})])))}for(const t of null!==(i=e.groupby)&&void 0!==i?i:[])a.add(t);return a.size+JP(o).length===0?null:new iX(t,a,o)}merge(t){return function(t,e){if(t.size!==e.size)return!1;for(const n of t)if(!e.has(n))return!1;return!0}(this.dimensions,t.dimensions)?(function(t,e){var n;for(const r of JP(e)){const i=e[r];for(const e of JP(i))r in t?t[r][e]=new Set([...(n=t[r][e],null!==n&&void 0!==n?n:[]),...i[e]]):t[r]={[e]:i[e]}}}(this.measures,t.measures),!0):(function(...t){LU.debug(...t)}("different dimensions, cannot merge"),!1)}addDimensions(t){t.forEach(this.dimensions.add,this.dimensions)}dependentFields(){return new Set([...this.dimensions,...JP(this.measures)])}producedFields(){const t=new Set;for(const e of JP(this.measures))for(const n of JP(this.measures[e])){const r=this.measures[e][n];0===r.size?t.add(`${n}_${e}`):r.forEach(t.add,t)}return t}hash(){return`Aggregate ${UP({dimensions:this.dimensions,measures:this.measures})}`}assemble(){const t=[],e=[],n=[];for(const r of JP(this.measures))for(const i of JP(this.measures[r]))for(const a of this.measures[r][i])n.push(a),t.push(i),e.push("*"===r?null:aL(r));return{type:"aggregate",groupby:[...this.dimensions],ops:t,fields:e,as:n}}}class aX extends HG{constructor(t,e,n,r){super(t),this.model=e,this.name=n,this.data=r;for(const t of Ez){const n=e.facet[t];if(n){const{bin:r,sort:i}=n;this[t]=Object.assign({name:e.getName(`${t}_domain`),fields:[PV(n),...iq(r)?[PV(n,{binSuffix:"end"})]:[]]},xV(i)?{sortField:i}:lP(i)?{sortIndexField:q$(n,t)}:{})}}this.childModel=e.child}hash(){let t="Facet";for(const e of Ez)this[e]&&(t+=` ${e.charAt(0)}:${UP(this[e])}`);return t}get fields(){var t;const e=[];for(const n of Ez)(null===(t=this[n])||void 0===t?void 0:t.fields)&&e.push(...this[n].fields);return e}dependentFields(){const t=new Set(this.fields);for(const e of Ez)this[e]&&(this[e].sortField&&t.add(this[e].sortField.field),this[e].sortIndexField&&t.add(this[e].sortIndexField));return t}producedFields(){return new Set}getSource(){return this.name}getChildIndependentFieldsWithStep(){const t={};for(const e of["x","y"]){const n=this.childModel.component.scales[e];if(n&&!n.merged){const r=n.get("type"),i=n.get("range");if(jW(r)&&iG(i)){const n=LX(zX(this.childModel,e));n?t[e]=n:BU(`Unknown field for ${e}. Cannot calculate view size.`)}}}return t}assembleRowColumnHeaderData(t,e,n){const r={row:"y",column:"x"}[t],i=[],a=[],o=[];n&&n[r]&&(e?(i.push(`distinct_${n[r]}`),a.push("max")):(i.push(n[r]),a.push("distinct")),o.push(`distinct_${n[r]}`));const{sortField:s,sortIndexField:u}=this[t];if(s){const{op:t=gV,field:e}=s;i.push(e),a.push(t),o.push(PV(s,{forAs:!0}))}else u&&(i.push(u),a.push("max"),o.push(u));return{name:this[t].name,source:null!==e&&void 0!==e?e:this.data,transform:[Object.assign({type:"aggregate",groupby:this[t].fields},i.length?{fields:i,ops:a,as:o}:{})]}}assembleFacetHeaderData(t){var e,n;const{columns:r}=this.model.layout,{layoutHeaders:i}=this.model.component,a=[],o={};for(const t of K$){for(const r of X$){const a=null!==(e=i[t]&&i[t][r])&&void 0!==e?e:[];for(const e of a)if((null===(n=e.axes)||void 0===n?void 0:n.length)>0){o[t]=!0;break}}if(o[t]){const e=`length(data("${this.facet.name}"))`,n="row"===t?r?{signal:`ceil(${e} / ${r})`}:1:r?{signal:`min(${e}, ${r})`}:{signal:e};a.push({name:`${this.facet.name}_${t}`,transform:[{type:"sequence",start:0,stop:n}]})}}const{row:s,column:u}=o;return(s||u)&&a.unshift(this.assembleRowColumnHeaderData("facet",null,t)),a}assemble(){var t,e;const n=[];let r=null;const i=this.getChildIndependentFieldsWithStep(),{column:a,row:o,facet:s}=this;if(a&&o&&(i.x||i.y)){r=`cross_${this.column.name}_${this.row.name}`;const a=[].concat(null!==(t=i.x)&&void 0!==t?t:[],null!==(e=i.y)&&void 0!==e?e:[]),o=a.map(()=>"distinct");n.push({name:r,source:this.data,transform:[{type:"aggregate",groupby:this.fields,fields:a,ops:o}]})}for(const t of[GL,HL])this[t]&&n.push(this.assembleRowColumnHeaderData(t,r,i));if(s){const t=this.assembleFacetHeaderData(i);t&&n.push(...t)}return n}}function oX(t){return"'"===t[0]&&"'"===t[t.length-1]||'"'===t[0]&&'"'===t[t.length-1]?t.slice(1,-1):t}function sX(t){const e={};return function t(e,n){if(FP(e))t(e.not,n);else if(RP(e))for(const r of e.and)t(r,n);else if(MP(e))for(const r of e.or)t(r,n);else n(e)}(t.filter,t=>{var n;if(pW(t)){let r=null;sW(t)?r=t.equal:dW(t)?r=t.range[0]:hW(t)&&(r=(n=t.oneOf,null!==n&&void 0!==n?n:t.in)[0]),r&&(WU(r)?e[t.field]="date":OP(r)?e[t.field]="number":dP(r)&&(e[t.field]="string")),t.timeUnit&&(e[t.field]="date")}}),e}function uX(t){const e={};function n(t){QV(t)?e[t.field]="date":"quantitative"===t.type&&function(t){return dP(t)&&VP(["min","max"],t)}(t.aggregate)?e[t.field]="number":sL(t.field)>1?t.field in e||(e[t.field]="flatten"):RV(t)&&xV(t.sort)&&sL(t.sort.field)>1&&(t.sort.field in e||(e[t.sort.field]="flatten"))}if((nY(t)||rY(t))&&t.forEachFieldDef((e,r)=>{if(IV(e))n(e);else{const i=zz(r),a=t.fieldDef(i);n(Object.assign(Object.assign({},e),{type:a.type}))}}),nY(t)){const{mark:n,markDef:r,encoding:i}=t;if(SL(n)&&!t.encoding.order){const t=i["horizontal"===r.orient?"y":"x"];!TV(t)||"quantitative"!==t.type||t.field in e||(e[t.field]="number")}}return e}class cX extends HG{constructor(t,e){super(t),this._parse=e}clone(){return new cX(null,PP(this._parse))}hash(){return`Parse ${UP(this._parse)}`}static makeExplicit(t,e,n){let r={};const i=e.data;return!DH(i)&&i&&i.format&&i.format.parse&&(r=i.format.parse),this.makeWithAncestors(t,r,{},n)}static makeWithAncestors(t,e,n,r){for(const t of JP(n)){const e=r.getWithExplicit(t);void 0!==e.value&&(e.explicit||e.value===n[t]||"derived"===e.value||"flatten"===n[t]?delete n[t]:BU(jU.differentParse(t,n[t],e.value)))}for(const t of JP(e)){const n=r.get(t);void 0!==n&&(n===e[t]?delete e[t]:BU(jU.differentParse(t,e[t],n)))}const i=new dK(e,n);r.copyAll(i);const a={};for(const t of JP(i.combine())){const e=i.get(t);null!==e&&(a[t]=e)}return 0===JP(a).length||r.parseNothing?null:new cX(t,a)}get parse(){return this._parse}merge(t){this._parse=Object.assign(Object.assign({},this._parse),t.parse),t.remove()}assembleFormatParse(){const t={};for(const e of JP(this._parse)){const n=this._parse[e];1===sL(e)&&(t[e]=n)}return t}producedFields(){return new Set(JP(this._parse))}dependentFields(){return new Set(JP(this._parse))}assembleTransforms(t=!1){return JP(this._parse).filter(e=>!t||sL(e)>1).map(t=>{const e=function(t,e){const n=iL(t);if("number"===e)return`toNumber(${n})`;if("boolean"===e)return`toBoolean(${n})`;if("string"===e)return`toString(${n})`;if("date"===e)return`toDate(${n})`;if("flatten"===e)return n;if(0===e.indexOf("date:"))return`timeParse(${n},'${oX(e.slice(5,e.length))}')`;if(0===e.indexOf("utc:"))return`utcParse(${n},'${oX(e.slice(4,e.length))}')`;return BU(jU.unrecognizedParse(e)),null}(t,this._parse[t]);return e?{type:"formula",expr:e,as:function(t){return`${cP(t).join(".")}`}(t)}:null}).filter(t=>null!==t)}}class lX extends HG{constructor(t,e){super(t),this.transform=e}clone(){return new lX(null,PP(this.transform))}addDimensions(t){this.transform.groupby=$P(this.transform.groupby.concat(t),t=>t)}dependentFields(){const t=new Set;return this.transform.groupby&&this.transform.groupby.forEach(e=>t.add(e)),this.transform.joinaggregate.map(t=>t.field).filter(t=>void 0!==t).forEach(e=>t.add(e)),t}producedFields(){return new Set(this.transform.joinaggregate.map(this.getDefaultName))}getDefaultName(t){var e;return null!==(e=t.as)&&void 0!==e?e:PV(t)}hash(){return`JoinAggregateTransform ${UP(this.transform)}`}assemble(){const t=[],e=[],n=[];for(const r of this.transform.joinaggregate)e.push(r.op),n.push(this.getDefaultName(r)),t.push(void 0===r.field?null:r.field);const r=this.transform.groupby;return Object.assign({type:"joinaggregate",as:n,ops:e,fields:t},void 0!==r?{groupby:r}:{})}}class fX extends HG{constructor(t,e){super(t),this._stack=e}clone(){return new fX(null,PP(this._stack))}static makeFromTransform(t,e){const{stack:n,groupby:r,as:i,offset:a="zero"}=e,o=[],s=[];if(void 0!==e.sort)for(const t of e.sort)o.push(t.field),s.push(uL(t.order,"ascending"));const u={field:o,order:s};let c;return c=function(t){return lP(t)&&t.every(t=>dP(t))&&t.length>1}(i)?i:dP(i)?[i,i+"_end"]:[e.stack+"_start",e.stack+"_end"],new fX(t,{stackField:n,groupby:r,offset:a,sort:u,facetby:[],as:c})}static makeFromEncoding(t,e){const n=e.stack,{encoding:r}=e;if(!n)return null;let i;if(n.groupbyChannel){i=KV(r[n.groupbyChannel])}const a=function(t){return t.stack.stackBy.reduce((t,e)=>{const n=PV(e.fieldDef);return n&&t.push(n),t},[])}(e),o=e.encoding.order;let s;return s=lP(o)||TV(o)?dV(o):a.reduce((t,e)=>(t.field.push(e),t.order.push("descending"),t),{field:[],order:[]}),new fX(t,{dimensionFieldDef:i,stackField:e.vgField(n.fieldChannel),facetby:[],stackby:a,sort:s,offset:n.offset,impute:n.impute,as:[e.vgField(n.fieldChannel,{suffix:"start",forAs:!0}),e.vgField(n.fieldChannel,{suffix:"end",forAs:!0})]})}get stack(){return this._stack}addDimensions(t){this._stack.facetby.push(...t)}dependentFields(){const t=new Set;return t.add(this._stack.stackField),this.getGroupbyFields().forEach(e=>t.add(e)),this._stack.facetby.forEach(e=>t.add(e)),this._stack.sort.field.forEach(e=>t.add(e)),t}producedFields(){return new Set(this._stack.as)}hash(){return`Stack ${UP(this._stack)}`}getGroupbyFields(){const{dimensionFieldDef:t,impute:e,groupby:n}=this._stack;return t?t.bin?e?[PV(t,{binSuffix:"mid"})]:[PV(t,{}),PV(t,{binSuffix:"end"})]:[PV(t)]:null!==n&&void 0!==n?n:[]}assemble(){const t=[],{facetby:e,dimensionFieldDef:n,stackField:r,stackby:i,sort:a,offset:o,impute:s,as:u}=this._stack;if(s&&n){const{band:a=.5,bin:o}=n;o&&t.push({type:"formula",expr:`${a}*`+PV(n,{expr:"datum"})+`+${1-a}*`+PV(n,{expr:"datum",binSuffix:"end"}),as:PV(n,{binSuffix:"mid",forAs:!0})}),t.push({type:"impute",field:r,groupby:[...i,...e],key:PV(n,{binSuffix:"mid"}),method:"value",value:0})}return t.push({type:"stack",groupby:[...this.getGroupbyFields(),...e],field:r,sort:a,as:u,offset:o}),t}}class dX extends HG{constructor(t,e){super(t),this.transform=e}clone(){return new dX(null,PP(this.transform))}addDimensions(t){this.transform.groupby=$P(this.transform.groupby.concat(t),t=>t)}dependentFields(){var t,e;const n=new Set;return(t=this.transform.groupby,null!==t&&void 0!==t?t:[]).forEach(t=>n.add(t)),(e=this.transform.sort,null!==e&&void 0!==e?e:[]).forEach(t=>n.add(t.field)),this.transform.window.map(t=>t.field).filter(t=>void 0!==t).forEach(t=>n.add(t)),n}producedFields(){return new Set(this.transform.window.map(this.getDefaultName))}getDefaultName(t){var e;return null!==(e=t.as)&&void 0!==e?e:PV(t)}hash(){return`WindowTransform ${UP(this.transform)}`}assemble(){var t;const e=[],n=[],r=[],i=[];for(const t of this.transform.window)n.push(t.op),r.push(this.getDefaultName(t)),i.push(void 0===t.param?null:t.param),e.push(void 0===t.field?null:t.field);const a=this.transform.frame,o=this.transform.groupby;if(a&&null===a[0]&&null===a[1]&&n.every(t=>BL(t)))return Object.assign({type:"joinaggregate",as:r,ops:n,fields:e},void 0!==o?{groupby:o}:{});const s=[],u=[];if(void 0!==this.transform.sort)for(const e of this.transform.sort)s.push(e.field),u.push(null!==(t=e.order)&&void 0!==t?t:"ascending");const c={field:s,order:u},l=this.transform.ignorePeers;return Object.assign(Object.assign(Object.assign({type:"window",params:i,as:r,ops:n,fields:e,sort:c},void 0!==l?{ignorePeers:l}:{}),void 0!==o?{groupby:o}:{}),void 0!==a?{frame:a}:{})}}class hX extends HG{clone(){return new hX(null)}constructor(t){super(t)}dependentFields(){return new Set}producedFields(){return new Set([qq])}hash(){return"Identifier"}assemble(){return{type:"identifier",as:qq}}}class pX extends eX{run(t){const e=t.parent;if(t instanceof cX){if(QK(e))return this.flags;if(e.numChildren()>1)return this.setContinue(),this.flags;if(e instanceof cX)this.setMutated(),e.merge(t);else{if(YP(e.producedFields(),t.dependentFields()))return this.setContinue(),this.flags;this.setMutated(),t.swapWithParent()}}return this.setContinue(),this.flags}}class mX extends nX{mergeNodes(t,e){const n=e.shift();for(const r of e)t.removeChild(r),r.parent=n,r.remove()}run(t){const e=t.children.map(t=>t.hash()),n={};for(let r=0;r<e.length;r++)void 0===n[e[r]]?n[e[r]]=[t.children[r]]:n[e[r]].push(t.children[r]);for(const e of JP(n))n[e].length>1&&(this.setMutated(),this.mergeNodes(t,n[e]));for(const e of t.children)this.run(e);return this.mutatedFlag}}class gX extends eX{run(t){return t instanceof GG||t.numChildren()>0||t instanceof aX?this.flags:(this.setMutated(),t.remove(),this.flags)}}class vX extends eX{constructor(){super(...arguments),this.fields=new Set,this.prev=null}run(t){if(this.setContinue(),t instanceof $G){const e=t.producedFields();KP(e,this.fields)?(this.setMutated(),this.prev.remove()):this.fields=new Set([...this.fields,...e]),this.prev=t}return this.flags}reset(){this.fields.clear()}}class yX extends eX{run(t){this.setContinue();const e=t.parent.children.filter(t=>t instanceof $G),n=e.pop();for(const t of e)this.setMutated(),n.merge(t);return this.flags}}function bX(t){if(t instanceof aX)if(1!==t.numChildren()||t.children[0]instanceof GG){const e=t.model.component.data.main;!function t(e){if(e instanceof GG&&e.type===jH&&1===e.numChildren()){const n=e.children[0];n instanceof aX||(n.swapWithParent(),t(e))}}(e);const n=function(t){return function e(n){if(!(n instanceof aX)){const r=n.clone();if(r instanceof GG){const e=SX+r.getSource();r.setSource(e),t.model.component.data.outputNodes[e]=r}else(r instanceof iX||r instanceof fX||r instanceof dX||r instanceof lX)&&r.addDimensions(t.fields);return n.children.flatMap(e).forEach(t=>t.parent=r),[r]}return n.children.flatMap(e)}}(t),r=t.children.map(n).flat();for(const t of r)t.parent=e}else{const e=t.children[0];(e instanceof iX||e instanceof fX||e instanceof dX||e instanceof lX)&&e.addDimensions(t.fields),e.swapWithParent(),bX(t)}else t.children.map(bX)}class xX extends nX{constructor(){super()}run(t){t instanceof GG&&!t.isRequired()&&(this.setMutated(),t.remove());for(const e of t.children)this.run(e);return this.mutatedFlag}}class wX extends nX{constructor(t){super(),this.requiresSelectionId=t&&S$(t)}run(t){t instanceof hX&&(this.requiresSelectionId&&(QK(t.parent)||t.parent instanceof iX||t.parent instanceof cX)||(this.setMutated(),t.remove()));for(const e of t.children)this.run(e);return this.mutatedFlag}}class kX extends eX{run(t){const e=t.parent,n=[...e.children],r=e.children.filter(t=>t instanceof cX);if(e.numChildren()>1&&r.length>=1){const t={},i=new Set;for(const e of r){const n=e.parse;for(const e of JP(n))e in t?t[e]!==n[e]&&i.add(e):t[e]=n[e]}for(const e of i)delete t[e];if(0!==JP(t).length){this.setMutated();const r=new cX(e,t);for(const i of n){if(i instanceof cX)for(const e of JP(t))delete i.parse[e];e.removeChild(i),i.parent=r,i instanceof cX&&0===JP(i.parse).length&&i.remove()}}}return this.setContinue(),this.flags}}class _X extends eX{run(t){const e=t.parent,n=e.children.filter(t=>t instanceof iX),r={};for(const t of n){const e=UP(t.groupBy);e in r||(r[e]=[]),r[e].push(t)}for(const t of JP(r)){const n=r[t];if(n.length>1){const t=n.pop();for(const r of n)t.merge(r)&&(e.removeChild(r),r.parent=t,r.remove(),this.setMutated())}}return this.setContinue(),this.flags}}class EX extends eX{constructor(t){super(),this.model=t}run(t){const e=t.parent,n=!(QK(e)||e instanceof A$||e instanceof cX||e instanceof hX),r=[],i=[];for(const t of e.children)t instanceof KK&&(n&&!YP(e.producedFields(),t.dependentFields())?r.push(t):i.push(t));if(r.length>0){const t=r.pop();for(const e of r)t.merge(e,this.model.renameSignal.bind(this.model));this.setMutated(),e instanceof KK?e.merge(t,this.model.renameSignal.bind(this.model)):t.swapWithParent()}if(i.length>1){const t=i.pop();for(const e of i)t.merge(e,this.model.renameSignal.bind(this.model));this.setMutated()}return this.setContinue(),this.flags}}class OX extends eX{run(t){const e=t.parent,n=[...e.children];if(!qP(n,t=>t instanceof GG)||e.numChildren()<=1)return this.setContinue(),this.flags;const r=[];let i;for(const t of n)if(t instanceof GG){let n=t;for(;1===n.numChildren();){const t=n.children[0];if(!(t instanceof GG))break;n=t}r.push(...n.children),i?(e.removeChild(t),t.parent=i.parent,i.parent.removeChild(i),i.parent=n,this.setMutated()):i=n}else r.push(t);if(r.length){this.setMutated();for(const t of r)t.parent.removeChild(t),t.parent=i}return this.setContinue(),this.flags}}const SX="scale_",CX=5;function AX(t){const e=[];return t.forEach(function t(n){0===n.numChildren()?e.push(n):n.children.forEach(t)}),e}function NX(t){return t}function TX(t,e){return e.map(e=>{if(t instanceof eX){const n=t.optimizeNextFromLeaves(e);return t.reset(),n}return t.run(e)}).some(NX)}function IX(t,e){let n=t.sources;const r=new Set;return r.add(TX(new xX,n)),r.add(TX(new wX(e),n)),n=n.filter(t=>t.numChildren()>0),r.add(TX(new gX,AX(n))),n=n.filter(t=>t.numChildren()>0),r.add(TX(new pX,AX(n))),r.add(TX(new EX(e),AX(n))),r.add(TX(new vX,AX(n))),r.add(TX(new kX,AX(n))),r.add(TX(new _X,AX(n))),r.add(TX(new yX,AX(n))),r.add(TX(new mX,n)),r.add(TX(new OX,AX(n))),t.sources=n,r.has(!0)}class DX{constructor(t){Object.defineProperty(this,"signal",{enumerable:!0,get:t})}static fromName(t,e){return new DX(()=>t(e))}}function MX(t){nY(t)?function(t){const e=t.component.scales;JP(e).forEach(n=>{const r=function(t,e){const n=t.getScaleComponent(e).get("type"),r=function(t,e,n,r){if("unaggregated"===t){const{valid:t,reason:r}=jX(e,n);if(!t)return void BU(r)}else if(void 0===t&&r.useUnaggregatedDomain){const{valid:t}=jX(e,n);if(t)return"unaggregated"}return t}(t.scaleDomain(e),t.fieldDef(e),n,t.config.scale);r!==t.scaleDomain(e)&&(t.specifiedScales[e]=Object.assign(Object.assign({},t.specifiedScales[e]),{domain:r}));if("x"===e&&t.channelHasField("x2"))return t.channelHasField("x")?vK(RX(n,r,t,"x"),RX(n,r,t,"x2"),"domain","scale",PX):RX(n,r,t,"x2");if("y"===e&&t.channelHasField("y2"))return t.channelHasField("y")?vK(RX(n,r,t,"y"),RX(n,r,t,"y2"),"domain","scale",PX):RX(n,r,t,"y2");return RX(n,r,t,e)}(t,n),i=e[n];if(i.setWithExplicit("domains",r),function(t,e){const n=t.component.scales[e],r=t.specifiedScales[e].domain,i=t.fieldDef(e).bin,a=BW(r)&&r,o=oq(i)&&sq(i.extent)&&i.extent;(a||o)&&n.set("selectionExtent",null!==a&&void 0!==a?a:o,!0)}(t,n),t.component.data.isFaceted){let e=t;for(;!rY(e)&&e.parent;)e=e.parent;const i=e.component.resolve.scale[n];if("shared"===i)for(const t of r.value)aG(t)&&(t.data=SX+t.data.replace(SX,""))}})}(t):function(t){for(const e of t.children)MX(e);const e=t.component.scales;JP(e).forEach(n=>{let r,i=null;for(const e of t.children){const t=e.component.scales[n];if(t){r=void 0===r?t.getWithExplicit("domains"):vK(r,t.getWithExplicit("domains"),"domains","scale",PX);const e=t.get("selectionExtent");i&&e&&i.selection!==e.selection&&BU("The same selection must be used to override scale domains in a layered view."),i=e}}e[n].setWithExplicit("domains",r),i&&e[n].set("selectionExtent",i,!0)})}(t)}function RX(t,e,n,r){const i=n.fieldDef(r);if(e&&"unaggregated"!==e&&!BW(e)){const{type:t,timeUnit:n}=i;return hK("temporal"===t||n?function(t,e,n){return t.map(t=>({signal:`{data: ${tq(t,{timeUnit:n,type:e})}}`}))}(e,t,n):[e])}const a=n.stack;if(a&&r===a.fieldChannel){if("normalize"===a.offset)return pK([[0,1]]);const t=n.requestDataName(jH);return pK([{data:t,field:n.vgField(r,{suffix:"start"})},{data:t,field:n.vgField(r,{suffix:"end"})}])}const o=dB(r)?function(t,e,n){if(!jW(n))return;const r=t.fieldDef(e),i=r.sort;if(wV(i))return{op:"min",field:q$(r,e),order:"ascending"};const a=null!==t.stack;if(xV(i))return FX(i,a);if(bV(i)){const{encoding:e,order:n}=i,r=t.fieldDef(e),{aggregate:o,field:s}=r;if(LL(o)||zL(o))return FX({field:PV(r),order:n},a);if(BL(o)||!o)return FX({op:o,field:s,order:n},a)}else{if("descending"===i)return{op:"min",field:t.vgField(e),order:"descending"};if(VP(["ascending",void 0],i))return!0}return}(n,r,t):void 0;if("unaggregated"===e){const t=n.requestDataName(jH),{field:e}=i;return pK([{data:t,field:PV({field:e,aggregate:"min"})},{data:t,field:PV({field:e,aggregate:"max"})}])}if(iq(i.bin)){if(jW(t))return pK("bin-ordinal"===t?[]:[{data:QP(o)?n.requestDataName(jH):n.requestDataName(PH),field:n.vgField(r,nq(i,r)?{binSuffix:"range"}:{}),sort:!0!==o&&fP(o)?o:{field:n.vgField(r,{}),op:"min"}}]);{const{bin:t}=i;if(iq(t)){const e=GK(n,i.field,t);return pK([new DX(()=>{const t=n.getSignalName(e);return`[${t}.start, ${t}.stop]`})])}return pK([{data:n.requestDataName(jH),field:n.vgField(r,{})}])}}if(i.timeUnit&&VP(["time","utc"],t)&&CV(r,i,nY(n)?n.encoding[Bz(r)]:void 0,n.markDef,n.config)){const t=n.requestDataName(jH);return pK([{data:t,field:n.vgField(r)},{data:t,field:n.vgField(r,{suffix:"end"})}])}return pK(o?[{data:QP(o)?n.requestDataName(jH):n.requestDataName(PH),field:n.vgField(r),sort:o}]:[{data:n.requestDataName(jH),field:n.vgField(r)}])}function FX(t,e){const{op:n,field:r,order:i}=t;return Object.assign(Object.assign({op:null!==n&&void 0!==n?n:e?"sum":gV},r?{field:aL(r)}:{}),i?{order:i}:{})}function jX(t,e){const{aggregate:n,type:r}=t;return n?dP(n)&&!qL[n]?{valid:!1,reason:jU.unaggregateDomainWithNonSharedDomainOp(n)}:"quantitative"===r&&"log"===e?{valid:!1,reason:jU.unaggregatedDomainWithLogScale(t)}:{valid:!0}:{valid:!1,reason:jU.unaggregateDomainHasNoEffectForRawField(t)}}function PX(t,e,n,r){return t.explicit&&e.explicit&&BU(jU.mergeConflictingDomainProperty(n,r,t.value,e.value)),{explicit:t.explicit,value:[...t.value,...e.value]}}function LX(t){if(aG(t)&&dP(t.field))return t.field;if(function(t){return!lP(t)&&"fields"in t&&!("data"in t)}(t)){let e;for(const n of t.fields)if(aG(n)&&dP(n.field))if(e){if(e!==n.field)return BU("Detected faceted independent scales that union domain of multiple fields from different data sources. We will use the first field. The result view size may be incorrect."),e}else e=n.field;return BU("Detected faceted independent scales that union domain of identical fields from different source detected. We will assume that this is the same field from a different fork of the same data source. However, if this is not case, the result view size maybe incorrect."),e}if(function(t){return!lP(t)&&"fields"in t&&"data"in t}(t)){BU("Detected faceted independent scales that union domain of multiple fields from the same data source. We will use the first field. The result view size may be incorrect.");const e=t.fields[0];return dP(e)?e:void 0}}function zX(t,e){return function(t){const e=$P(t.map(t=>{if(aG(t)){const{sort:e}=t;return b(t,["sort"])}return t}),UP),n=$P(t.map(t=>{if(aG(t)){const e=t.sort;return void 0===e||QP(e)||("op"in e&&"count"===e.op&&delete e.field,"ascending"===e.order&&delete e.order),e}}).filter(t=>void 0!==t),UP);if(0===e.length)return;if(1===e.length){const e=t[0];if(aG(e)&&n.length>0){let t=n[0];return n.length>1&&(BU(jU.MORE_THAN_ONE_SORT),t=!0),Object.assign(Object.assign({},e),{sort:t})}return e}const r=$P(n.map(t=>QP(t)||!("op"in t)||t.op in PL?t:(BU(jU.domainSortDropped(t)),!0)),UP);let i;1===r.length?i=r[0]:r.length>1&&(BU(jU.MORE_THAN_ONE_SORT),i=!0);const a=$P(t.map(t=>aG(t)?t.data:null),t=>t);if(1===a.length&&null!==a[0])return Object.assign({data:a[0],fields:e.map(t=>t.field)},i?{sort:i}:{});return Object.assign({fields:e},i?{sort:i}:{})}(t.component.scales[e].get("domains").map(e=>(aG(e)&&(e.data=t.lookupDataSource(e.data)),e)))}function BX(t){return JP(t.component.scales).reduce((e,n)=>{const r=t.component.scales[n];if(r.merged)return e;const i=r.combine(),{name:a,type:o,selectionExtent:s,domains:u,range:c}=i,l=b(i,["name","type","selectionExtent","domains","range"]),f=function(t,e,n){if(("x"===n||"y"===n)&&iG(t))return{step:{signal:e+"_step"}};return t}(i.range,a,n);let d;s&&(d=function(t,e){const n=e.selection;return{signal:T$(t.getSelectionComponent(n,tL(n)),e)}}(t,s));const h=zX(t,n);return e.push(Object.assign(Object.assign(Object.assign(Object.assign({name:a,type:o},h?{domain:h}:{}),d?{domainRaw:d}:{}),{range:f}),l)),e},[])}class UX extends dK{constructor(t,e){super({},{name:t}),this.merged=!1,this.setWithExplicit("type",e)}domainDefinitelyIncludesZero(){return!1!==this.get("zero")||qP(this.get("domains"),t=>lP(t)&&2===t.length&&t[0]<=0&&t[1]>=0)}}const WX=["range","scheme"];function VX(t){return"x"===t?"width":"y"===t?"height":void 0}function qX(t){const e=t.component.scales;fB.forEach(n=>{const r=e[n];if(!r)return;const i=function(t,e){const n=e.specifiedScales[t],{size:r}=e,i=e.getScaleComponent(t).get("type");for(const e of WX)if(void 0!==n[e]){const r=KW(i,e),a=XW(t,e);if(r)if(a)BU(a);else switch(e){case"range":return hK(n[e]);case"scheme":return hK(GX(n[e]))}else BU(jU.scalePropertyNotWorkWithScaleType(i,e,t))}if(t===KL||t===XL){const e=t===KL?"width":"height",n=r[e];if(Zq(n)){if(jW(i))return hK({step:n.step});BU(jU.stepDropped(e))}}return pK(function(t,e){const{size:n,config:r,mark:i}=e,a=e.getSignalName.bind(e),{type:o}=e.fieldDef(t),s=e.getScaleComponent(t).get("type"),{domain:u}=e.specifiedScales[t];switch(t){case KL:case XL:{if(VP(["point","band"],s))if(t!==KL||n.width){if(t===XL&&!n.height){const t=nH(r.view,"height");if(Zq(t))return t}}else{const t=nH(r.view,"width");if(Zq(t))return t}const i=VX(t),o=e.getName(i);return t===XL&&PW(s)?[DX.fromName(a,o),0]:[0,DX.fromName(a,o)]}case oz:{const a=e.component.scales[t].get("zero"),o=function(t,e,n){if(e)return 0;switch(t){case"bar":case"tick":return n.scale.minBandSize;case"line":case"trail":case"rule":return n.scale.minStrokeWidth;case"text":return n.scale.minFontSize;case"point":case"square":case"circle":return n.scale.minSize}throw new Error(jU.incompatibleChannel("size",t))}(i,a,r),c=function(t,e,n,r){const i={x:HX(n,"x"),y:HX(n,"y")};switch(t){case"bar":case"tick":{if(void 0!==r.scale.maxBandSize)return r.scale.maxBandSize;const t=KX(e,i,r.view);return OP(t)?t-1:new DX(()=>`${t.signal} - 1`)}case"line":case"trail":case"rule":return r.scale.maxStrokeWidth;case"text":return r.scale.maxFontSize;case"point":case"square":case"circle":{if(r.scale.maxSize)return r.scale.maxSize;const t=KX(e,i,r.view);return OP(t)?Math.pow($X*t,2):new DX(()=>`pow(${$X} * ${t.signal}, 2)`)}}throw new Error(jU.incompatibleChannel("size",t))}(i,n,e,r);return zW(s)?function(t,e,n){const r=()=>{const r=rG(e)?e.signal:e,i=`(${r} - ${t}) / (${n} - 1)`;return`sequence(${t}, ${e} + ${i}, ${i})`};return rG(e)?new DX(r):{signal:r()}}(o,c,function(t,e,n,r){switch(t){case"quantile":return e.scale.quantileCount;case"quantize":return e.scale.quantizeCount;case"threshold":return void 0!==n&&lP(n)?n.length+1:(BU(jU.domainRequiredForThresholdScale(r)),3)}}(s,r,u,t)):[o,c]}case lz:return[r.scale.minStrokeWidth,r.scale.maxStrokeWidth];case az:return"symbol";case nz:case rz:case iz:return"ordinal"===s?"nominal"===o?"category":"ordinal":"rect"===i||"geoshape"===i?"heatmap":"ramp";case sz:case uz:case cz:return[r.scale.minOpacity,r.scale.maxOpacity]}throw new Error(`Scale range undefined for channel ${t}`)}(t,e))}(n,t);r.setWithExplicit("range",i)})}function HX(t,e){const n=t.fieldDef(e);if(n&&n.bin&&iq(n.bin)){const r=GK(t,n.field,n.bin),i=VX(e),a=t.getName(i);return new DX(()=>{const e=t.getSignalName(r),n=`(${e}.stop - ${e}.start) / ${e}.step`;return`${t.getSignalName(a)} / (${n})`})}}function GX(t){return function(t){return!dP(t)&&!!t.name}(t)?Object.assign({scheme:t.name},zP(t,["name"])):{scheme:t}}const $X=.95;function KX(t,e,n){const r=Zq(t.width)?t.width.step:eH(n,"width"),i=Zq(t.height)?t.height.step:eH(n,"height");return e.x||e.y?new DX(()=>{return`min(${[e.x?e.x.signal:r,e.y?e.y.signal:i].join(", ")})`}):Math.min(r,i)}function XX(t,e){nY(t)?function(t,e){const n=t.component.scales;JP(n).forEach(r=>{const i=t.specifiedScales[r],a=n[r],o=t.getScaleComponent(r),s=t.fieldDef(r),u=t.config,c=i[e],l=o.get("type"),f=KW(l,e),d=XW(r,e);if(void 0!==c&&(f?d&&BU(d):BU(jU.scalePropertyNotWorkWithScaleType(l,e,r))),f&&void 0===d)if(void 0!==c)a.copyKeyFromObject(e,i);else{const n=function(t,e,n,r,i,a,o,s,u,c){const l=c.scale,{type:f,sort:d}=r;switch(t){case"bins":return function(t,e){const n=e.bin;if(iq(n)){const r=GK(t,e.field,n);return new DX(()=>t.getSignalName(r))}if(aq(n)&&oq(n)&&void 0!==n.step)return{step:n.step};return}(e,r);case"interpolate":return function(t,e){if(VP([nz,rz,iz],t)&&"nominal"!==e)return"hcl";return}(n,f);case"nice":return function(t,e,n){if(n.bin||VP([OW.TIME,OW.UTC],t))return;return!!VP([KL,XL],e)||void 0}(i,n,r);case"padding":return function(t,e,n,r,i,a){if(VP([KL,XL],t)){if(LW(e)){if(void 0!==n.continuousPadding)return n.continuousPadding;const{type:e,orient:o}=i;if("bar"===e&&!r.bin&&!r.timeUnit&&("vertical"===o&&"x"===t||"horizontal"===o&&"y"===t))return a.continuousBandSize}if(e===OW.POINT)return n.pointPadding}return}(n,i,l,r,u,c.bar);case"paddingInner":return function(t,e,n,r){if(void 0!==t)return;if(VP([KL,XL],e)){const{bandPaddingInner:t,barBandPaddingInner:e,rectBandPaddingInner:i}=r;return uL(t,"bar"===n?e:i)}return}(a,n,u.type,l);case"paddingOuter":return function(t,e,n,r,i,a){if(void 0!==t)return;if(VP([KL,XL],e)&&n===OW.BAND){const{bandPaddingOuter:t}=a;return uL(t,i/2)}return}(a,n,i,u.type,o,l);case"reverse":return function(t,e){if(PW(t)&&"descending"===e)return!0;return}(i,d);case"zero":return function(t,e,n,r,i){if(n&&"unaggregated"!==n&&PW(i)){if(lP(n)){const t=n[0],e=n[n.length-1];if(t<=0&&e>=0)return!0}return!1}if("size"===t&&"quantitative"===e.type&&!zW(i))return!0;if(!e.bin&&VP([KL,XL],t)){const{orient:e,type:n}=r;return!VP(["bar","area","line","trail"],n)||!("horizontal"===e&&"y"===t||"vertical"===e&&"x"===t)}return!1}(n,r,s,u,i)}return l[t]}(e,t,r,s,o.get("type"),o.get("padding"),o.get("paddingInner"),i.domain,t.markDef,u);void 0!==n&&a.set(e,n,!1)}})}(t,e):JX(t,e)}function YX(t){nY(t)?qX(t):JX(t,"range")}function JX(t,e){const n=t.component.scales;for(const n of t.children)"range"===e?YX(n):XX(n,e);JP(n).forEach(r=>{let i;for(const n of t.children){const t=n.component.scales[r];if(t){i=vK(i,t.getWithExplicit(e),e,"scale",mK((t,n)=>{switch(e){case"range":return t.step&&n.step?t.step-n.step:0}return 0}))}}n[r].setWithExplicit(e,i)})}function ZX(t,e,n,r){const i=function(t,e,n){switch(e.type){case"nominal":case"ordinal":return kz(t)||"discrete"===vB(t)?("shape"===t&&"ordinal"===e.type&&BU(jU.discreteChannelCannotEncode(t,"ordinal")),"ordinal"):VP(["x","y"],t)&&VP(["rect","bar","image","rule"],n)?"band":"point";case"temporal":return kz(t)?"time":"discrete"===vB(t)?(BU(jU.discreteChannelCannotEncode(t,"temporal")),"ordinal"):"time";case"quantitative":return kz(t)?iq(e.bin)?"bin-ordinal":"linear":"discrete"===vB(t)?(BU(jU.discreteChannelCannotEncode(t,"quantitative")),"ordinal"):"linear";case"geojson":return}throw new Error(jU.invalidFieldType(e.type))}(e,n,r),{type:a}=t;return dB(e)?void 0!==a?JW(e,a)?YW(a,n.type)?a:(BU(jU.scaleTypeNotWorkWithFieldDef(a,i)),i):(BU(jU.scaleTypeNotWorkWithChannel(e,a,i)),i):i:null}function QX(t){nY(t)?t.component.scales=function(t){const{encoding:e,mark:n}=t;return fB.reduce((r,i)=>{let a,o;const s=e[i];if(TV(s)&&n===EL&&i===az&&s.type===EW)return r;if(TV(s)?(a=s,o=s.scale):NV(s)&&(a=s.condition,o=s.condition.scale),a&&null!==o&&!1!==o){const e=ZX(o=null!==o&&void 0!==o?o:{},i,a,n);r[i]=new UX(t.scaleName(i+"",!0),{value:e,explicit:o.type===e})}return r},{})}(t):t.component.scales=function(t){const e=t.component.scales={},n={},r=t.component.resolve;for(const e of t.children)QX(e),JP(e.component.scales).forEach(i=>{var a;if(r.scale[i]=null!==(a=r.scale[i])&&void 0!==a?a:lK(i,t),"shared"===r.scale[i]){const t=n[i],a=e.component.scales[i].getWithExplicit("type");t?AW(t.value,a.value)?n[i]=vK(t,a,"type","scale",tY):(r.scale[i]="independent",delete n[i]):n[i]=a}});for(const r of JP(n)){const i=t.scaleName(r,!0),a=n[r];e[r]=new UX(i,a);for(const e of t.children){const t=e.component.scales[r];t&&(e.renameScale(t.get("name"),i),t.merged=!0)}}return e}(t)}const tY=mK((t,e)=>TW(t)-TW(e));class eY{constructor(){this.nameMap={}}rename(t,e){this.nameMap[t]=e}has(t){return void 0!==this.nameMap[t]}get(t){for(;this.nameMap[t]&&t!==this.nameMap[t];)t=this.nameMap[t];return t}}function nY(t){var e;return"unit"===(null===(e=t)||void 0===e?void 0:e.type)}function rY(t){var e;return"facet"===(null===(e=t)||void 0===e?void 0:e.type)}function iY(t){var e;return"repeat"===(null===(e=t)||void 0===e?void 0:e.type)}function aY(t){var e;return"concat"===(null===(e=t)||void 0===e?void 0:e.type)}function oY(t){var e;return"layer"===(null===(e=t)||void 0===e?void 0:e.type)}class sY{constructor(t,e,n,r,i,a,o,s){var u,c;this.type=e,this.parent=n,this.config=i,this.repeater=a,this.view=s,this.children=[],this.correctDataNames=(t=>(t.from&&t.from.data&&(t.from.data=this.lookupDataSource(t.from.data)),t.from&&t.from.facet&&t.from.facet.data&&(t.from.facet.data=this.lookupDataSource(t.from.facet.data)),t)),this.parent=n,this.config=i,this.repeater=a,this.name=null!==(u=t.name)&&void 0!==u?u:r,this.title=tV(t.title)?{text:t.title}:t.title,this.scaleNameMap=n?n.scaleNameMap:new eY,this.projectionNameMap=n?n.projectionNameMap:new eY,this.signalNameMap=n?n.signalNameMap:new eY,this.data=t.data,this.description=t.description,this.transforms=nG(null!==(c=t.transform)&&void 0!==c?c:[]),this.layout=RL(t)||fH(t)?{}:function(t,e,n){var r,i;const a=n[e],o={},{spacing:s,columns:u}=a;void 0!==s&&(o.spacing=s),void 0!==u&&(_V(t)&&!kV(t.facet)||Jq(t)&&lP(t.repeat)||Kq(t))&&(o.columns=u);for(const e of Qq)if(void 0!==t[e])if("spacing"===e){const n=t[e];o[e]=OP(n)?n:{row:(r=n.row,null!==r&&void 0!==r?r:s),column:(i=n.column,null!==i&&void 0!==i?i:s)}}else o[e]=t[e];return o}(t,e,i),this.component={data:{sources:n?n.component.data.sources:[],outputNodes:n?n.component.data.outputNodes:{},outputNodeRefCounts:n?n.component.data.outputNodeRefCounts:{},isFaceted:_V(t)||n&&n.component.data.isFaceted&&void 0===t.data},layoutSize:new dK,layoutHeaders:{row:{},column:{},facet:{}},mark:null,resolve:Object.assign({scale:{},axis:{},legend:{}},o?PP(o):{}),selection:null,scales:null,projection:null,axes:{},legends:{}}}get width(){return this.getSizeSignalRef("width")}get height(){return this.getSizeSignalRef("height")}parse(){this.parseScale(),this.parseLayoutSize(),this.renameTopLevelLayoutSizeSignal(),this.parseSelections(),this.parseProjection(),this.parseData(),this.parseAxesAndHeaders(),this.parseLegends(),this.parseMarkGroup()}parseScale(){!function(t,{ignoreRange:e}={}){QX(t),MX(t);for(const e of $W)XX(t,e);e||YX(t)}(this)}parseProjection(){qK(this)}renameTopLevelLayoutSizeSignal(){"width"!==this.getName("width")&&this.renameSignal(this.getName("width"),"width"),"height"!==this.getName("height")&&this.renameSignal(this.getName("height"),"height")}parseLegends(){RK(this)}assembleGroupStyle(){var t,e;if("unit"===this.type||"layer"===this.type)return null!==(e=null===(t=this.view)||void 0===t?void 0:t.style)&&void 0!==e?e:"cell"}assembleEncodeFromView(t){const{style:e}=t,n=b(t,["style"]),r={};for(const t in n)if(_P(n,t)){const e=n[t];void 0!==e&&(r[t]={value:e})}return r}assembleGroupEncodeEntry(t){let e=void 0;return this.view&&(e=this.assembleEncodeFromView(this.view)),t||"unit"!==this.type&&"layer"!==this.type?e:Object.assign({width:this.getSizeSignalRef("width"),height:this.getSizeSignalRef("height")},null!==e&&void 0!==e?e:{})}assembleLayout(){if(!this.layout)return;const t=this.layout,{spacing:e}=t,n=b(t,["spacing"]),{component:r,config:i}=this,a=function(t,e){var n;const r={};for(const i of Ez){const a=t[i];if(null===(n=a)||void 0===n?void 0:n.facetFieldDef){const{titleAnchor:t,titleOrient:n}=$$(["titleAnchor","titleOrient"],a.facetFieldDef,e,i),o=H$(i,n),s=rK(t,o);void 0!==s&&(r[o]=s)}}return JP(r).length>0?r:void 0}(r.layoutHeaders,i);return Object.assign(Object.assign(Object.assign({padding:e},this.assembleDefaultLayout()),n),a?{titleBand:a}:{})}assembleDefaultLayout(){return{}}assembleHeaderMarks(){const{layoutHeaders:t}=this.component;let e=[];for(const n of Ez)t[n].title&&e.push(Y$(this,n));for(const t of K$)e=e.concat(Q$(this,t));return e}assembleAxes(){return function(t,e){const{x:n=[],y:r=[]}=t;return[...n.map(t=>M$(t,"grid",e)),...r.map(t=>M$(t,"grid",e)),...n.map(t=>M$(t,"main",e)),...r.map(t=>M$(t,"main",e))].filter(t=>t)}(this.component.axes,this.config)}assembleLegends(){return zK(this)}assembleProjections(){return BK(this)}assembleTitle(){var t,e,n;const r=null!==(t=this.title)&&void 0!==t?t:{},{encoding:i}=r,a=b(r,["encoding"]),o=Object.assign(Object.assign(Object.assign({},QW(this.config.title).nonMark),a),i?{encode:{update:i}}:{});if(o.text)return VP(["unit","layer"],this.type)?VP(["middle",void 0],o.anchor)&&(o.frame=null!==(e=o.frame)&&void 0!==e?e:"group"):o.anchor=null!==(n=o.anchor)&&void 0!==n?n:"start",JP(o).length>0?o:void 0}assembleGroup(t=[]){const e={};(t=t.concat(this.assembleSignals())).length>0&&(e.signals=t);const n=this.assembleLayout();n&&(e.layout=n),e.marks=[].concat(this.assembleHeaderMarks(),this.assembleMarks());const r=!this.parent||rY(this.parent)?function t(e){return oY(e)||aY(e)||iY(e)?e.children.reduce((e,n)=>e.concat(t(n)),BX(e)):BX(e)}(this):[];r.length>0&&(e.scales=r);const i=this.assembleAxes();i.length>0&&(e.axes=i);const a=this.assembleLegends();return a.length>0&&(e.legends=a),e}hasDescendantWithFieldOnChannel(t){for(const e of this.children)if(nY(e)){if(e.channelHasField(t))return!0}else if(e.hasDescendantWithFieldOnChannel(t))return!0;return!1}getName(t){return tL((this.name?this.name+"_":"")+t)}requestDataName(t){var e;const n=this.getName(t),r=this.component.data.outputNodeRefCounts;return r[n]=(null!==(e=r[n])&&void 0!==e?e:0)+1,n}getSizeSignalRef(t){if(rY(this.parent)){const e=tB(t),n=this.component.scales[e];if(n&&!n.merged){const t=n.get("type"),r=n.get("range");if(jW(t)&&iG(r)){const t=n.get("name"),r=LX(zX(this,e));if(r){return{signal:uK(t,n,PV({aggregate:"distinct",field:r},{expr:"datum"}))}}return BU(`Unknown field for ${e}. Cannot calculate view size.`),null}}}return{signal:this.signalNameMap.get(this.getName(t))}}lookupDataSource(t){const e=this.component.data.outputNodes[t];return e?e.getSource():t}getSignalName(t){return this.signalNameMap.get(t)}renameSignal(t,e){this.signalNameMap.rename(t,e)}renameScale(t,e){this.scaleNameMap.rename(t,e)}renameProjection(t,e){this.projectionNameMap.rename(t,e)}scaleName(t,e){return e?this.getName(t):jz(t)&&dB(t)&&this.component.scales[t]||this.scaleNameMap.has(this.getName(t))?this.scaleNameMap.get(this.getName(t)):void 0}projectionName(t){return t?this.getName("projection"):this.component.projection&&!this.component.projection.merged||this.projectionNameMap.has(this.getName("projection"))?this.projectionNameMap.get(this.getName("projection")):void 0}getScaleComponent(t){if(!this.component.scales)throw new Error("getScaleComponent cannot be called before parseScale(). Make sure you have called parseScale or use parseUnitModelWithScale().");const e=this.component.scales[t];return e&&!e.merged?e:this.parent?this.parent.getScaleComponent(t):void 0}getSelectionComponent(t,e){let n=this.component.selection[t];if(!n&&this.parent&&(n=this.parent.getSelectionComponent(t,e)),!n)throw new Error(jU.selectionNotFound(e));return n}}class uY extends sY{vgField(t,e={}){const n=this.fieldDef(t);if(n)return PV(n,e)}reduceFieldDef(t,e){return pq(this.getMapping(),(e,n,r)=>{const i=$V(n);return i?t(e,i,r):e},e)}forEachFieldDef(t,e){hq(this.getMapping(),(e,n)=>{const r=$V(e);r&&t(r,n)},e)}}class cY extends HG{constructor(t,e){var n,r,i;super(t),this.transform=e,this.transform=PP(e);const a=null!==(n=this.transform.as)&&void 0!==n?n:[void 0,void 0];this.transform.as=[(r=a[0],null!==r&&void 0!==r?r:"value"),(i=a[1],null!==i&&void 0!==i?i:"density")]}clone(){return new cY(null,PP(this.transform))}dependentFields(){var t;return new Set([this.transform.density,...(t=this.transform.groupby,null!==t&&void 0!==t?t:[])])}producedFields(){return new Set(this.transform.as)}hash(){return`DensityTransform ${UP(this.transform)}`}assemble(){const t=this.transform,{density:e}=t,n=b(t,["density"]);return Object.assign({type:"kde",field:e},n)}}class lY extends HG{constructor(t,e){super(t),this.filter=e}clone(){return new lY(null,Object.assign({},this.filter))}static make(t,e){const{config:n,mark:r,markDef:i}=e;if("filter"!==rV("invalid",i,n))return null;const a=e.reduceFieldDef((t,n,i)=>{const a=dB(i)&&e.getScaleComponent(i);if(a){!PW(a.get("type"))||n.aggregate||SL(r)||(t[n.field]=n)}return t},{});return JP(a).length?new lY(t,a):null}dependentFields(){return new Set(JP(this.filter))}producedFields(){return new Set}hash(){return`FilterInvalid ${UP(this.filter)}`}assemble(){const t=JP(this.filter).reduce((t,e)=>{const n=this.filter[e],r=PV(n,{expr:"datum"});return null!==n&&("temporal"===n.type?t.push(`(isDate(${r}) || (isValid(${r}) && isFinite(+${r})))`):"quantitative"===n.type&&(t.push(`isValid(${r})`),t.push(`isFinite(+${r})`))),t},[]);return t.length>0?{type:"filter",expr:t.join(" && ")}:null}}class fY extends HG{constructor(t,e){super(t),this.transform=e,this.transform=PP(e);const{flatten:n,as:r=[]}=this.transform;this.transform.as=n.map((t,e)=>{var n;return null!==(n=r[e])&&void 0!==n?n:t})}clone(){return new fY(this.parent,PP(this.transform))}dependentFields(){return new Set(this.transform.flatten)}producedFields(){return new Set(this.transform.as)}hash(){return`FlattenTransform ${UP(this.transform)}`}assemble(){const{flatten:t,as:e}=this.transform;return{type:"flatten",fields:t,as:e}}}class dY extends HG{constructor(t,e){var n,r,i;super(t),this.transform=e,this.transform=PP(e);const a=null!==(n=this.transform.as)&&void 0!==n?n:[void 0,void 0];this.transform.as=[(r=a[0],null!==r&&void 0!==r?r:"key"),(i=a[1],null!==i&&void 0!==i?i:"value")]}clone(){return new dY(null,PP(this.transform))}dependentFields(){return new Set(this.transform.fold)}producedFields(){return new Set(this.transform.as)}hash(){return`FoldTransform ${UP(this.transform)}`}assemble(){const{fold:t,as:e}=this.transform;return{type:"fold",fields:t,as:e}}}class hY extends HG{constructor(t,e,n,r){super(t),this.fields=e,this.geojson=n,this.signal=r}clone(){return new hY(null,PP(this.fields),this.geojson,this.signal)}static parseAll(t,e){if(e.component.projection&&!e.component.projection.isFit)return t;let n=0;for(const r of[[QL,ZL],[ez,tz]]){const i=r.map(t=>e.channelHasField(t)?e.fieldDef(t).field:MV(e.encoding[t])?{expr:e.encoding[t].value+""}:void 0);(i[0]||i[1])&&(t=new hY(t,i,null,e.getName(`geojson_${n++}`)))}if(e.channelHasField(az)){const r=e.fieldDef(az);r.type===EW&&(t=new hY(t,null,r.field,e.getName(`geojson_${n++}`)))}return t}dependentFields(){var t;const e=(t=this.fields,null!==t&&void 0!==t?t:[]).filter(dP);return new Set([...this.geojson?[this.geojson]:[],...e])}producedFields(){return new Set}hash(){return`GeoJSON ${this.geojson} ${this.signal} ${UP(this.fields)}`}assemble(){return Object.assign(Object.assign(Object.assign({type:"geojson"},this.fields?{fields:this.fields}:{}),this.geojson?{geojson:this.geojson}:{}),{signal:this.signal})}}class pY extends HG{constructor(t,e,n,r){super(t),this.projection=e,this.fields=n,this.as=r}clone(){return new pY(null,this.projection,PP(this.fields),PP(this.as))}static parseAll(t,e){if(!e.projectionName())return t;for(const n of[[QL,ZL],[ez,tz]]){const r=n.map(t=>e.channelHasField(t)?e.fieldDef(t).field:MV(e.encoding[t])?{expr:e.encoding[t].value+""}:void 0),i=n[0]===ez?"2":"";(r[0]||r[1])&&(t=new pY(t,e.projectionName(),r,[e.getName("x"+i),e.getName("y"+i)]))}return t}dependentFields(){return new Set(this.fields.filter(dP))}producedFields(){return new Set(this.as)}hash(){return`Geopoint ${this.projection} ${UP(this.fields)} ${UP(this.as)}`}assemble(){return{type:"geopoint",projection:this.projection,fields:this.fields,as:this.as}}}class mY extends HG{constructor(t,e){super(t),this.transform=e}clone(){return new mY(null,PP(this.transform))}dependentFields(){var t;return new Set([this.transform.impute,this.transform.key,...(t=this.transform.groupby,null!==t&&void 0!==t?t:[])])}producedFields(){return new Set([this.transform.impute])}processSequence(t){const{start:e=0,stop:n,step:r}=t;return{signal:`sequence(${[e,n,...r?[r]:[]].join(",")})`}}static makeFromTransform(t,e){return new mY(t,e)}static makeFromEncoding(t,e){const n=e.encoding,r=n.x,i=n.y;if(TV(r)&&TV(i)){const a=r.impute?r:i.impute?i:void 0;if(void 0===a)return;const o=r.impute?i:i.impute?r:void 0,{method:s,value:u,frame:c,keyvals:l}=a.impute,f=mq(e.mark,n);return new mY(t,Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({impute:a.field,key:o.field},s?{method:s}:{}),void 0!==u?{value:u}:{}),c?{frame:c}:{}),void 0!==l?{keyvals:l}:{}),f.length?{groupby:f}:{}))}return null}hash(){return`Impute ${UP(this.transform)}`}assemble(){const{impute:t,key:e,keyvals:n,method:r,groupby:i,value:a,frame:o=[null,null]}=this.transform,s=Object.assign(Object.assign(Object.assign(Object.assign({type:"impute",field:t,key:e},n?{keyvals:function(t){var e;return void 0!==(null===(e=t)||void 0===e?void 0:e.stop)}(n)?this.processSequence(n):n}:{}),{method:"value"}),i?{groupby:i}:{}),{value:null});let u;if(r&&"value"!==r){u=[Object.assign({type:"window",as:[`imputed_${t}_value`],ops:[r],fields:[t],frame:o,ignorePeers:!1},i?{groupby:i}:{}),{type:"formula",expr:`datum.${t} === null ? datum.imputed_${t}_value : datum.${t}`,as:t}]}else{u=[{type:"formula",expr:`datum.${t} === null ? ${a} : datum.${t}`,as:t}]}return[s,...u]}}class gY extends dK{constructor(t={},e={},n=!1){super(t,e),this.explicit=t,this.implicit=e,this.parseNothing=n}clone(){const t=super.clone();return t.parseNothing=this.parseNothing,t}}class vY extends HG{constructor(t,e){var n,r,i;super(t),this.transform=e,this.transform=PP(e);const a=null!==(n=this.transform.as)&&void 0!==n?n:[void 0,void 0];this.transform.as=[(r=a[0],null!==r&&void 0!==r?r:e.on),(i=a[1],null!==i&&void 0!==i?i:e.loess)]}clone(){return new vY(null,PP(this.transform))}dependentFields(){var t;return new Set([this.transform.loess,this.transform.on,...(t=this.transform.groupby,null!==t&&void 0!==t?t:[])])}producedFields(){return new Set(this.transform.as)}hash(){return`LoessTransform ${UP(this.transform)}`}assemble(){const t=this.transform,{loess:e,on:n}=t,r=b(t,["loess","on"]);return Object.assign({type:"loess",x:n,y:e},r)}}class yY extends HG{constructor(t,e,n){super(t),this.transform=e,this.secondary=n}clone(){return new yY(null,PP(this.transform),this.secondary)}static make(t,e,n,r){var i;const a=e.component.data.sources,{from:o}=n;let s=null;if(function(t){return void 0!==t.data}(o)){let t=BY(o.data,a);t||(t=new XK(o.data),a.push(t));const n=e.getName(`lookup_${r}`);s=new GG(t,n,"lookup",e.component.data.outputNodeRefCounts),e.component.data.outputNodes[n]=s}else if(function(t){return void 0!==t.selection}(o)){const t=o.selection;if(n.as=null!==(i=n.as)&&void 0!==i?i:t,!(s=e.getSelectionComponent(tL(t),t).materialized))throw new Error(jU.noSameUnitLookup(t))}return new yY(t,n,s.getSource())}dependentFields(){return new Set([this.transform.lookup])}producedFields(){return new Set(this.transform.as?xP(this.transform.as):this.transform.from.fields)}hash(){return`Lookup ${UP({transform:this.transform,secondary:this.secondary})}`}assemble(){let t;if(this.transform.from.fields)t=Object.assign({values:this.transform.from.fields},this.transform.as?{as:xP(this.transform.as)}:{});else{let e=this.transform.as;dP(e)||(BU(jU.NO_FIELDS_NEEDS_AS),e="_lookup"),t={as:[e]}}return Object.assign(Object.assign({type:"lookup",from:this.secondary,key:this.transform.from.key,fields:[this.transform.lookup]},t),this.transform.default?{default:this.transform.default}:{})}}class bY extends HG{constructor(t,e){var n,r,i;super(t),this.transform=e,this.transform=PP(e);const a=null!==(n=this.transform.as)&&void 0!==n?n:[void 0,void 0];this.transform.as=[(r=a[0],null!==r&&void 0!==r?r:"prob"),(i=a[1],null!==i&&void 0!==i?i:"value")]}clone(){return new bY(null,PP(this.transform))}dependentFields(){var t;return new Set([this.transform.quantile,...(t=this.transform.groupby,null!==t&&void 0!==t?t:[])])}producedFields(){return new Set(this.transform.as)}hash(){return`QuantileTransform ${UP(this.transform)}`}assemble(){const t=this.transform,{quantile:e}=t,n=b(t,["quantile"]);return Object.assign({type:"quantile",field:e},n)}}class xY extends HG{constructor(t,e){var n,r,i;super(t),this.transform=e,this.transform=PP(e);const a=null!==(n=this.transform.as)&&void 0!==n?n:[void 0,void 0];this.transform.as=[(r=a[0],null!==r&&void 0!==r?r:e.on),(i=a[1],null!==i&&void 0!==i?i:e.regression)]}clone(){return new xY(null,PP(this.transform))}dependentFields(){var t;return new Set([this.transform.regression,this.transform.on,...(t=this.transform.groupby,null!==t&&void 0!==t?t:[])])}producedFields(){return new Set(this.transform.as)}hash(){return`RegressionTransform ${UP(this.transform)}`}assemble(){const t=this.transform,{regression:e,on:n}=t,r=b(t,["regression","on"]);return Object.assign({type:"regression",x:n,y:e},r)}}class wY extends HG{constructor(t,e){super(t),this.transform=e}clone(){return new wY(null,PP(this.transform))}addDimensions(t){var e;this.transform.groupby=$P((e=this.transform.groupby,null!==e&&void 0!==e?e:[]).concat(t),t=>t)}producedFields(){}dependentFields(){var t;return new Set([this.transform.pivot,this.transform.value,...(t=this.transform.groupby,null!==t&&void 0!==t?t:[])])}hash(){return`PivotTransform ${UP(this.transform)}`}assemble(){const{pivot:t,value:e,groupby:n,limit:r,op:i}=this.transform;return Object.assign(Object.assign(Object.assign({type:"pivot",field:t,value:e},void 0!==r?{limit:r}:{}),void 0!==i?{op:i}:{}),void 0!==n?{groupby:n}:{})}}class kY extends HG{constructor(t,e){super(t),this.transform=e}clone(){return new kY(null,PP(this.transform))}dependentFields(){return new Set}producedFields(){return new Set}hash(){return`SampleTransform ${UP(this.transform)}`}assemble(){return{type:"sample",size:this.transform.sample}}}function _Y(t){let e=0;return function n(r,i){var a;r instanceof XK&&!r.isGenerator&&!NH(r.data)&&(t.push(i),i={name:null,source:i.name,transform:[]});if(r instanceof cX&&(r.parent instanceof XK&&!i.source?(i.format=Object.assign(Object.assign({},null!==(a=i.format)&&void 0!==a?a:{}),{parse:r.assembleFormatParse()}),i.transform.push(...r.assembleTransforms(!0))):i.transform.push(...r.assembleTransforms())),r instanceof aX)return i.name||(i.name=`data_${e++}`),!i.source||i.transform.length>0?(t.push(i),r.data=i.name):r.data=i.source,void r.assemble().forEach(e=>t.push(e));(r instanceof JK||r instanceof ZK||r instanceof lY||r instanceof A$||r instanceof V$||r instanceof pY||r instanceof hY||r instanceof iX||r instanceof yY||r instanceof dX||r instanceof lX||r instanceof dY||r instanceof fY||r instanceof cY||r instanceof vY||r instanceof bY||r instanceof xY||r instanceof hX||r instanceof kY||r instanceof wY)&&i.transform.push(r.assemble()),(r instanceof KK||r instanceof $G||r instanceof mY||r instanceof fX)&&i.transform.push(...r.assemble()),r instanceof GG&&(i.source&&0===i.transform.length?r.setSource(i.source):r.parent instanceof GG?r.setSource(i.name):(i.name||(i.name=`data_${e++}`),r.setSource(i.name),1===r.numChildren()&&(t.push(i),i={name:null,source:i.name,transform:[]})));switch(r.numChildren()){case 0:r instanceof GG&&(!i.source||i.transform.length>0)&&t.push(i);break;case 1:n(r.children[0],i);break;default:{i.name||(i.name=`data_${e++}`);let a=i.name;!i.source||i.transform.length>0?t.push(i):a=i.source,r.children.forEach(t=>{n(t,{name:null,source:a,transform:[]})});break}}}}function EY(t){return"top"===t||"left"===t?"header":"footer"}function OY(t,e){var n;if(t.channelHasField(e)){const r=t.facet[e],i=G$("title",null,t.config,e);let a=VV(r,t.config,{allowDisabling:!0,includeDefault:void 0===i||!!i});t.child.component.layoutHeaders[e].title&&(a=lP(a)?a.join(", "):a,a+=" / "+t.child.component.layoutHeaders[e].title,t.child.component.layoutHeaders[e].title=null);const o=G$("labelOrient",r,t.config,e),s=uL((null!==(n=r.header)&&void 0!==n?n:{}).labels,!0),u=VP(["bottom","right"],o)?"footer":"header";t.component.layoutHeaders[e]={title:a,facetFieldDef:r,[u]:"facet"===e?[]:[SY(t,e,s)]}}}function SY(t,e,n){const r="row"===e?"height":"width";return{labels:n,sizeSignal:t.child.component.layoutSize.get(r)?t.child.getSizeSignalRef(r):void 0,axes:[]}}function CY(t,e){var n;const{child:r}=t;if(r.component.axes[e]){const{layoutHeaders:i,resolve:a}=t.component;if(a.axis[e]=fK(a,e),"shared"===a.axis[e]){const a="x"===e?"column":"row",o=i[a];for(const i of r.component.axes[e]){const e=EY(i.get("orient"));o[e]=null!==(n=o[e])&&void 0!==n?n:[SY(t,a,!1)];const r=M$(i,"main",t.config,{header:!0});o[e][0].axes.push(r),i.mainExtracted=!0}}}}function AY(t){IY(t);const e=t.component.layoutSize;e.setWithExplicit("width",DY(t,"width")),e.setWithExplicit("height",DY(t,"height"))}const NY=AY,TY={vconcat:"width",hconcat:"height"};function IY(t){for(const e of t.children)e.parseLayoutSize()}function DY(t,e){const n="width"===e?"x":"y",r=t.component.resolve;let i;for(const a of t.children){const t=a.component.layoutSize.getWithExplicit(e),o=r.scale[n];if("independent"===o&&"step"===t.value){i=void 0;break}if(i){if("independent"===o&&i.value!==t.value){i=void 0;break}i=vK(i,t,e,"")}else i=t}if(i){for(const n of t.children)t.renameSignal(n.getName(e),t.getName(e)),n.component.layoutSize.set(e,"merged",!1);return i}return{explicit:!1,value:void 0}}function MY(t,e){const n="width"===e?"x":"y",r=t.config,i=t.getScaleComponent(n);if(i){const t=i.get("type"),n=i.get("range");if(jW(t)){const t=nH(r.view,e);return iG(n)||Zq(t)?"step":t}return tH(r.view,e)}if(t.hasProjection)return tH(r.view,e);{const t=nH(r.view,e);return Zq(t)?t.step:t}}function RY(t,e){return function(t){return t&&!dP(t)&&"repeat"in t}(t.field)?t.field.repeat in e?Object.assign(Object.assign({},t),{field:e[t.field.repeat]}):void BU(jU.noSuchRepeatedValue(t.field.repeat)):t}function FY(t,e){if(void 0!==(t=RY(t,e))){if(null===t)return null;if(OV(t)&&xV(t.sort)){const n=RY(t.sort,e);t=Object.assign(Object.assign({},t),n?{sort:n}:{})}return t}}function jY(t,e){if(!TV(t)){if(NV(t)){const n=FY(t.condition,e);if(n)return Object.assign(Object.assign({},t),{condition:n});{const{condition:e}=t;return b(t,["condition"])}}return t}{const n=FY(t,e);if(n)return n;if(AV(t))return{condition:t.condition}}}function PY(t,e){const n={};for(const r in t)if(_P(t,r)){const i=t[r];if(lP(i))n[r]=i.map(t=>jY(t,e)).filter(t=>t);else{const t=jY(i,e);void 0!==t&&(n[r]=t)}}return n}function LY(t,e,n){return PV(e,Object.assign({suffix:`by_${PV(t)}`},null!==n&&void 0!==n?n:{}))}class zY extends uY{constructor(t,e,n,r,i){super(t,"facet",e,n,i,r,t.resolve),this.child=cJ(t.spec,this,this.getName("child"),void 0,r,i),this.children=[this.child];const a=function(t,e){return kV(t)?PY(t,e):FY(t,e)}(t.facet,r);this.facet=this.initFacet(a)}initFacet(t){return kV(t)?pq(t,(t,e,n)=>VP([HL,GL],n)?void 0===e.field?(BU(jU.emptyFieldDef(e,n)),t):(t[n]=XV(e,n),t):(BU(jU.incompatibleChannel(n,"facet")),t),{}):{facet:XV(t,"facet")}}channelHasField(t){return!!this.facet[t]}fieldDef(t){return this.facet[t]}parseData(){this.component.data=WY(this),this.child.parseData()}parseLayoutSize(){IY(this)}parseSelections(){this.child.parseSelections(),this.component.selection=this.child.component.selection}parseMarkGroup(){this.child.parseMarkGroup()}parseAxesAndHeaders(){this.child.parseAxesAndHeaders(),function(t){for(const e of Ez)OY(t,e);CY(t,"x"),CY(t,"y")}(this)}assembleSelectionTopLevelSignals(t){return this.child.assembleSelectionTopLevelSignals(t)}assembleSignals(){return this.child.assembleSignals(),[]}assembleSelectionData(t){return this.child.assembleSelectionData(t)}getHeaderLayoutMixins(){var t,e,n,r;const i={};for(const a of Ez)for(const o of X$){const s=this.component.layoutHeaders[a],u=s[o],{facetFieldDef:c}=s;if(c){const e=G$("titleOrient",c,this.config,a);if(VP(["right","bottom"],e)){const n=H$(a,e);i.titleAnchor=null!==(t=i.titleAnchor)&&void 0!==t?t:{},i.titleAnchor[n]="end"}}if(null===(e=u)||void 0===e?void 0:e[0]){const t="row"===a?"height":"width",e="header"===o?"headerBand":"footerBand";"facet"===a||this.child.component.layoutSize.get(t)||(i[e]=null!==(n=i[e])&&void 0!==n?n:{},i[e][a]=.5),s.title&&(i.offset=null!==(r=i.offset)&&void 0!==r?r:{},i.offset["row"===a?"rowTitle":"columnTitle"]=10)}}return i}assembleDefaultLayout(){const{column:t,row:e}=this.facet,n=t?this.columnDistinctSignal():e?1:void 0;let r="all";return(e||"independent"!==this.component.resolve.scale.x)&&(t||"independent"!==this.component.resolve.scale.y)||(r="none"),Object.assign(Object.assign(Object.assign({},this.getHeaderLayoutMixins()),n?{columns:n}:{}),{bounds:"full",align:r})}assembleLayoutSignals(){return this.child.assembleLayoutSignals()}columnDistinctSignal(){if(!(this.parent&&this.parent instanceof zY)){return{signal:`length(data('${this.getName("column_domain")}'))`}}}assembleGroup(t){return this.parent&&this.parent instanceof zY?Object.assign(Object.assign({},this.channelHasField("column")?{encode:{update:{columns:{field:PV(this.facet.column,{prefix:"distinct"})}}}}:{}),super.assembleGroup(t)):super.assembleGroup(t)}getCardinalityAggregateForChild(){const t=[],e=[],n=[];if(this.child instanceof zY){if(this.child.channelHasField("column")){const r=PV(this.child.facet.column);t.push(r),e.push("distinct"),n.push(`distinct_${r}`)}}else for(const r of["x","y"]){const i=this.child.component.scales[r];if(i&&!i.merged){const a=i.get("type"),o=i.get("range");if(jW(a)&&iG(o)){const i=LX(zX(this.child,r));i?(t.push(i),e.push("distinct"),n.push(`distinct_${i}`)):BU(`Unknown field for ${r}. Cannot calculate view size.`)}}}return{fields:t,ops:e,as:n}}assembleFacet(){const{name:t,data:e}=this.component.data.facetRoot,{row:n,column:r}=this.facet,{fields:i,ops:a,as:o}=this.getCardinalityAggregateForChild(),s=[];for(const t of Ez){const e=this.facet[t];if(e){s.push(PV(e));const{bin:u,sort:c}=e;if(iq(u)&&s.push(PV(e,{binSuffix:"end"})),xV(c)){const{field:t,op:s=gV}=c,u=LY(e,c);n&&r?(i.push(u),a.push("max"),o.push(u)):(i.push(t),a.push(s),o.push(u))}else if(lP(c)){const n=q$(e,t);i.push(n),a.push("max"),o.push(n)}}}const u=!!n&&!!r;return Object.assign({name:t,data:e,groupby:s},u||i.length>0?{aggregate:Object.assign(Object.assign({},u?{cross:u}:{}),i.length?{fields:i,ops:a,as:o}:{})}:{})}facetSortFields(t){const{facet:e}=this,n=e[t];return n?xV(n.sort)?[LY(n,n.sort,{expr:"datum"})]:lP(n.sort)?[q$(n,t,{expr:"datum"})]:[PV(n,{expr:"datum"})]:[]}facetSortOrder(t){const{facet:e}=this,n=e[t];if(n){const{sort:t}=n;return[(xV(t)?t.order:!lP(t)&&t)||"ascending"]}return[]}assembleLabelTitle(){const{facet:t,config:e}=this;if(t.facet)return tK(t.facet,"facet",e);const n={row:["top","bottom"],column:["left","right"]};for(const r of K$)if(t[r]){const i=G$("labelOrient",t[r],e,r);if(VP(n[r],i))return tK(t[r],r,e)}}assembleMarks(){const{child:t}=this,e=function(t){const e=[],n=_Y(e);return t.children.forEach(e=>n(e,{source:t.name,name:null,transform:[]})),e}(this.component.data.facetRoot),n=t.assembleGroupEncodeEntry(!1),r=this.assembleLabelTitle()||t.assembleTitle(),i=t.assembleGroupStyle();return[Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({name:this.getName("cell"),type:"group"},r?{title:r}:{}),i?{style:i}:{}),{from:{facet:this.assembleFacet()},sort:{field:Ez.map(t=>this.facetSortFields(t)).flat(),order:Ez.map(t=>this.facetSortOrder(t)).flat()}}),e.length>0?{data:e}:{}),n?{encode:{update:n}}:{}),t.assembleGroup(function(t,e){if(t.component.selection&&JP(t.component.selection).length){const n=hP(t.getName("cell"));e.unshift({name:"facet",value:{},on:[{events:ZM("mousemove","scope"),update:`isTuple(facet) ? facet : group(${n}).datum`}]})}return f$(e)}(this,[])))]}getMapping(){return this.facet}}function BY(t,e){var n,r,i,a,o,s,u,c,l,f;for(const d of e){const e=d.data;if((!t.name||!d.hasName()||t.name===d.dataName)&&!((null===(n=t.format)||void 0===n?void 0:n.mesh)&&(null===(r=e.format)||void 0===r?void 0:r.feature)||((null===(i=t.format)||void 0===i?void 0:i.feature)||(null===(a=e.format)||void 0===a?void 0:a.feature))&&(null===(o=t.format)||void 0===o?void 0:o.feature)!==(null===(s=e.format)||void 0===s?void 0:s.feature)||((null===(u=t.format)||void 0===u?void 0:u.mesh)||(null===(c=e.format)||void 0===c?void 0:c.mesh))&&(null===(l=t.format)||void 0===l?void 0:l.mesh)!==(null===(f=e.format)||void 0===f?void 0:f.mesh)))if(TH(t)&&TH(e)){if(jP(t.values,e.values))return d}else if(NH(t)&&NH(e)){if(t.url===e.url)return d}else if(IH(t)&&t.name===d.dataName)return d}return null}function UY(t,e){if(t.data||!t.parent){if(null===t.data){const t=new XK([]);return e.push(t),t}const n=BY(t.data,e);if(n)return DH(t.data)||(n.data.format=function(t,...e){for(const n of e)GP(t,null!==n&&void 0!==n?n:{});return t}({},t.data.format,n.data.format)),!n.hasName()&&t.data.name&&(n.dataName=t.data.name),n;{const n=new XK(t.data);return e.push(n),n}}return t.parent.component.data.facetRoot?t.parent.component.data.facetRoot:t.parent.component.data.main}function WY(t){var e,n,r,i,a,o,s,u,c,l,f;let d=UY(t,t.component.data.sources);const{outputNodes:h,outputNodeRefCounts:p}=t.component.data,m=t.parent?t.parent.component.data.ancestorParse.clone():new gY,g=t.data;DH(g)?(MH(g)?d=new ZK(d,g.sequence):FH(g)&&(d=new JK(d,g.graticule)),m.parseNothing=!0):null===(null===(n=null===(e=g)||void 0===e?void 0:e.format)||void 0===n?void 0:n.parse)&&(m.parseNothing=!0),r=cX.makeExplicit(d,t,m),d=new hX(d=null!==r&&void 0!==r?r:d);const v=t.parent&&oY(t.parent);(nY(t)||rY(t))&&v&&(d=null!==(i=KK.makeFromEncoding(d,t))&&void 0!==i?i:d),t.transforms.length>0&&(d=function(t,e,n){var r,i;let a=0;for(const o of e.transforms){let s,u=void 0;if(XH(o))s=t=new V$(t,o),u="derived";else if(LH(o)){const i=sX(o);s=t=null!==(r=cX.makeWithAncestors(t,{},i,n))&&void 0!==r?r:t,t=new A$(t,e,o.filter)}else if(YH(o))s=t=KK.makeFromTransform(t,o,e),u="number";else if(ZH(o))u="date",void 0===n.getWithExplicit(o.field).value&&(t=new cX(t,{[o.field]:u}),n.set(o.field,u,!1)),s=t=$G.makeFromTransform(t,o);else if(QH(o))s=t=iX.makeFromTransform(t,o),u="number",S$(e)&&(t=new hX(t));else if(zH(o))s=t=yY.make(t,e,o,a++),u="derived";else if(GH(o))s=t=new dX(t,o),u="number";else if($H(o))s=t=new lX(t,o),u="number";else if(tG(o))s=t=fX.makeFromTransform(t,o),u="derived";else if(eG(o))s=t=new dY(t,o),u="derived";else if(KH(o))s=t=new fY(t,o),u="derived";else if(BH(o))s=t=new wY(t,o),u="derived";else if(HH(o))t=new kY(t,o);else if(JH(o))s=t=mY.makeFromTransform(t,o),u="derived";else if(UH(o))s=t=new cY(t,o),u="derived";else if(WH(o))s=t=new bY(t,o),u="derived";else if(VH(o))s=t=new xY(t,o),u="derived";else{if(!qH(o)){BU(jU.invalidTransformIgnored(o));continue}s=t=new vY(t,o),u="derived"}if(s&&void 0!==u)for(const t of null!==(i=s.producedFields())&&void 0!==i?i:[])n.set(t,u,!1)}return t}(d,t,m));const y=function(t){const e={};if(nY(t)&&t.component.selection)for(const n of JP(t.component.selection)){const r=t.component.selection[n];for(const t of r.project.items)!t.channel&&sL(t.field)>1&&(e[t.field]="flatten")}return e}(t),b=uX(t);d=null!==(a=cX.makeWithAncestors(d,{},Object.assign(Object.assign({},y),b),m))&&void 0!==a?a:d,nY(t)&&(d=hY.parseAll(d,t),d=pY.parseAll(d,t)),(nY(t)||rY(t))&&(v||(d=null!==(o=KK.makeFromEncoding(d,t))&&void 0!==o?o:d),d=null!==(s=$G.makeFromEncoding(d,t))&&void 0!==s?s:d,d=V$.parseAllForSortIndex(d,t));const x=t.getName(PH),w=new GG(d,x,PH,p);if(h[x]=w,d=w,nY(t)){const e=iX.makeFromEncoding(d,t);e&&(d=e,S$(t)&&(d=new hX(d))),d=null!==(u=mY.makeFromEncoding(d,t))&&void 0!==u?u:d,d=null!==(c=fX.makeFromEncoding(d,t))&&void 0!==c?c:d}nY(t)&&(d=null!==(l=lY.make(d,t))&&void 0!==l?l:d);const k=t.getName(jH),_=new GG(d,k,jH,p);h[k]=_,d=_,nY(t)&&function(t,e){E$(t,n=>{const r=n.name,i=t.getName(`lookup_${r}`);t.component.data.outputNodes[i]=n.materialized=new GG(new A$(e,t,{selection:r}),i,"lookup",t.component.data.outputNodeRefCounts)})}(t,_);let E=null;if(rY(t)){const e=t.getName("facet");f=function(t,e){const{row:n,column:r}=e;if(n&&r){let e=null;for(const i of[n,r])if(xV(i.sort)){const{field:n,op:r=gV}=i.sort;t=e=new lX(t,{joinaggregate:[{op:r,field:n,as:LY(i,i.sort,{forAs:!0})}],groupby:[PV(i)]})}return e}return null}(d=V$.parseAllForSortIndex(d,t),t.facet),E=new aX(d=null!==f&&void 0!==f?f:d,t,e,_.getSource()),h[e]=E,d=E}return Object.assign(Object.assign({},t.component.data),{outputNodes:h,outputNodeRefCounts:p,raw:w,main:_,facetRoot:E,ancestorParse:m})}class VY extends sY{constructor(t,e,n,r,i,a,o){super(t,e,n,r,i,a,o)}parseData(){this.component.data=WY(this),this.children.forEach(t=>{t.parseData()})}parseSelections(){this.component.selection={};for(const t of this.children)t.parseSelections(),JP(t.component.selection).forEach(e=>{this.component.selection[e]=t.component.selection[e]})}parseMarkGroup(){for(const t of this.children)t.parseMarkGroup()}parseAxesAndHeaders(){for(const t of this.children)t.parseAxesAndHeaders()}assembleSelectionTopLevelSignals(t){return this.children.reduce((t,e)=>e.assembleSelectionTopLevelSignals(t),t)}assembleSignals(){return this.children.forEach(t=>t.assembleSignals()),[]}assembleLayoutSignals(){return this.children.reduce((t,e)=>[...t,...e.assembleLayoutSignals()],aK(this))}assembleSelectionData(t){return this.children.reduce((t,e)=>e.assembleSelectionData(t),t)}assembleMarks(){return this.children.map(t=>{const e=t.assembleTitle(),n=t.assembleGroupStyle(),r=t.assembleGroupEncodeEntry(!1);return Object.assign(Object.assign(Object.assign(Object.assign({type:"group",name:t.getName("group")},e?{title:e}:{}),n?{style:n}:{}),r?{encode:{update:r}}:{}),t.assembleGroup())})}}class qY extends VY{constructor(t,e,n,r,i){var a,o,s,u;super(t,"concat",e,n,i,r,t.resolve),"shared"!==(null===(o=null===(a=t.resolve)||void 0===a?void 0:a.axis)||void 0===o?void 0:o.x)&&"shared"!==(null===(u=null===(s=t.resolve)||void 0===s?void 0:s.axis)||void 0===u?void 0:u.y)||BU(jU.CONCAT_CANNOT_SHARE_AXIS),this.concatType=Xq(t)?"vconcat":Yq(t)?"hconcat":"concat",this.children=this.getChildren(t).map((t,e)=>cJ(t,this,this.getName("concat_"+e),void 0,r,i))}getChildren(t){return Xq(t)?t.vconcat:Yq(t)?t.hconcat:t.concat}parseLayoutSize(){!function(t){IY(t);const e=t.component.layoutSize,n=TY[t.concatType];n&&e.setWithExplicit(n,DY(t,n))}(this)}parseAxisGroup(){return null}assembleDefaultLayout(){return Object.assign(Object.assign({},"vconcat"===this.concatType?{columns:1}:{}),{bounds:"full",align:"each"})}}const HY=Object.assign(Object.assign({gridScale:1,scale:1},fG),{labelExpr:1,encode:1}),GY=JP(HY);class $Y extends dK{constructor(t={},e={},n=!1){super(),this.explicit=t,this.implicit=e,this.mainExtracted=n}clone(){return new $Y(PP(this.explicit),PP(this.implicit),this.mainExtracted)}hasAxisPart(t){return"axis"===t||("grid"===t||"title"===t?!!this.get(t):!function(t){return!1===t||null===t}(this.get(t)))}}function KY(t){return Zz.reduce((e,n)=>(t.component.scales[n]&&t.axis(n)&&(e[n]=[function(t,e){var n;const r=e.axis(t),i=new $Y;GY.forEach(n=>{const a=function(t,e,n,r){const i=r.fieldDef(n),a=function(t,e,n,r){if(void 0!==e.labelAngle)return fL(e.labelAngle);{const e=z$("labelAngle",t.config,n,W$(n),t.getScaleComponent(n).get("type"));return void 0!==e?fL(e):n===KL&&VP([_W,wW],r.type)?270:void 0}}(r,e,n,i),o=uL(e.orient,W$(n)),{mark:s,config:u}=r;switch(t){case"scale":return r.scaleName(n);case"gridScale":return function(t,e){const n="x"===e?"y":"x";if(t.getScaleComponent(n))return t.scaleName(n)}(r,n);case"format":if(QV(i))return;return sV(i,e.format,u);case"formatType":if(QV(i))return;return e.formatType;case"grid":if(aq(r.fieldDef(n).bin))return!1;{const t=r.getScaleComponent(n).get("type");return uL(e.grid,function(t,e){return!jW(t)&&!iq(e.bin)}(t,i))}case"labelAlign":return uL(e.labelAlign,U$(a,o));case"labelAngle":return a;case"labelBaseline":return uL(e.labelBaseline,B$(a,o));case"labelFlush":return uL(e.labelFlush,function(t,e){if("x"===e&&VP(["quantitative","temporal"],t.type))return!0}(i,n));case"labelOverlap":{const t=r.getScaleComponent(n).get("type");return uL(e.labelOverlap,function(t,e){if("nominal"!==t.type)return"log"!==e||"greedy"}(i,t))}case"orient":return o;case"tickCount":{const t=r.getScaleComponent(n).get("type"),a="x"===n?"width":"y"===n?"height":void 0,o=a?r.getSizeSignalRef(a):void 0;return uL(e.tickCount,function({fieldDef:t,scaleType:e,size:n}){if(!jW(e)&&"log"!==e&&!VP(["month","hours","day","quarter"],t.timeUnit))return iq(t.bin)?{signal:`ceil(${n.signal}/10)`}:{signal:`ceil(${n.signal}/40)`}}({fieldDef:i,scaleType:t,size:o}))}case"title":{const t="x"===n?"x2":"y2",a=r.fieldDef(t);return uL(e.title,ZY(r,n),hV([EV(i)],a?[EV(a)]:[]))}case"values":return function(t,e,n){const r=t.values;if(r)return eq(n,r)}(e,0,i);case"zindex":return uL(e.zindex,function(t,e){return"rect"===t&&LV(e)?1:0}(s,i))}return function(t){return!!dG[t]}(t)?e[t]:void 0}(n,r,t,e);if(void 0!==a){const o=function(t,e,n,r,i){switch(e){case"titleAngle":case"labelAngle":return t===fL(n[e]);case"values":return!!n.values;case"encode":return!!n.encoding||!!n.labelAngle;case"title":if(t===ZY(r,i))return!0}return t===n[e]}(a,n,r,e,t),s=z$(n,e.config,t,i.get("orient"),e.getScaleComponent(t).get("type"));o||void 0===s?i.set(n,a,o):VP(["grid","orient"],n)&&s&&i.set(n,s,!1)}});const a=null!==(n=r.encoding)&&void 0!==n?n:{},o=cG.reduce((n,r)=>{var o;if(!i.hasAxisPart(r))return n;const s=cK(null!==(o=a[r])&&void 0!==o?o:{},e),u="labels"===r?function(t,e,n){var r;const i=null!==(r=t.fieldDef(e))&&void 0!==r?r:"x"===e?t.fieldDef("x2"):"y"===e?t.fieldDef("y2"):void 0,a=t.axis(e);let o={};if(QV(i)){const n=t.getScaleComponent(e).get("type")===OW.UTC,r=fV("datum.value",i.timeUnit,a.format,null,n);r&&(o.text={signal:r})}return o=Object.assign(Object.assign({},o),n),0===JP(o).length?void 0:o}(e,t,s):s;return void 0!==u&&JP(u).length>0&&(n[r]={update:u}),n},{});JP(o).length>0&&i.set("encode",o,!!r.encoding||void 0!==r.labelAngle);return i}(n,t)]),e),{})}const XY={bottom:"top",top:"bottom",left:"right",right:"left"};function YY(t,e){if(!t)return e.map(t=>t.clone());{if(t.length!==e.length)return;const n=t.length;for(let r=0;r<n;r++){const n=t[r],i=e[r];if(!!n!=!!i)return;if(n&&i){const e=n.getWithExplicit("orient"),a=i.getWithExplicit("orient");if(e.explicit&&a.explicit&&e.value!==a.value)return;t[r]=JY(n,i)}}}return t}function JY(t,e){for(const n of GY){const r=vK(t.getWithExplicit(n),e.getWithExplicit(n),n,"axis",(t,e)=>{switch(n){case"title":return mV(t,e);case"gridScale":return{explicit:t.explicit,value:uL(t.value,e.value)}}return gK(t,e,n,"axis")});t.setWithExplicit(n,r)}return t}function ZY(t,e){const n="x"===e?"x2":"y2",r=t.fieldDef(e),i=t.fieldDef(n),a=r?r.title:void 0,o=i?i.title:void 0;return a&&o?pV(a,o):a||(o||(void 0!==a?a:void 0!==o?o:void 0))}function QY(t,e,n,{graticule:r}){var i,a;const o=NL(t)?Object.assign({},t):{type:t},s=null!==(i=o.orient)&&void 0!==i?i:iV("orient",o,n);return o.orient=function(t,e,n){switch(t){case gL:case kL:case _L:case bL:case vL:case pL:return}const{x:r,y:i,x2:a,y2:o}=e;switch(t){case hL:if(TV(r)&&(aq(r.bin)||TV(i)&&i.aggregate&&!r.aggregate))return"vertical";if(TV(i)&&(aq(i.bin)||TV(r)&&r.aggregate&&!i.aggregate))return"horizontal";if(o||a){if(n)return n;if(!a&&TV(r)&&r.type===xW&&!iq(r.bin))return"horizontal";if(!o&&TV(i)&&i.type===xW&&!iq(i.bin))return"vertical"}case yL:if(a&&o)return;case dL:if(o)return TV(i)&&aq(i.bin)?"horizontal":"vertical";if(a)return TV(r)&&aq(r.bin)?"vertical":"horizontal";if(t===yL){if(r&&!i)return"vertical";if(i&&!r)return"horizontal"}case mL:case xL:{const e=TV(r)&&zV(r),a=TV(i)&&zV(i);if(e&&!a)return"tick"!==t?"horizontal":"vertical";if(!e&&a)return"tick"!==t?"vertical":"horizontal";if(e&&a){const e=r,a=i,o=e.type===kW,s=a.type===kW;return o&&!s?"tick"!==t?"vertical":"horizontal":!o&&s?"tick"!==t?"horizontal":"vertical":!e.aggregate&&a.aggregate?"tick"!==t?"vertical":"horizontal":e.aggregate&&!a.aggregate?"tick"!==t?"horizontal":"vertical":n||"vertical"}return n||void 0}}return"vertical"}(o.type,e,s),void 0!==s&&s!==o.orient&&BU(jU.orientOverridden(o.orient,s)),void 0===uL(o.opacity,iV("opacity",o,n))&&(o.opacity=function(t,e){if(VP([gL,xL,kL,_L],t)&&!lq(e))return.7;return}(o.type,e)),void 0===o.filled&&(o.filled=!r&&function(t,e){const n=iV("filled",t,e),r=t.type;return uL(n,r!==gL&&r!==mL&&r!==yL)}(o,n)),void 0===(null!==(a=o.cursor)&&void 0!==a?a:iV("cursor",o,n))&&(o.cursor=function(t,e,n){if(e.href||t.href||iV("href",t,n))return"pointer";return t.cursor}(o,e,n)),o}function tJ(t,e){const{config:n}=t;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},BG(t,{align:"ignore",baseline:"ignore",color:"include",size:"include",orient:"ignore"})),AG("x",t,{defaultPos:"mid"})),AG("y",t,{defaultPos:"mid"})),wG("size",t)),function(t,e,n){if(n)return{shape:{value:n}};return wG("shape",t)}(t,0,e))}const eJ={area:{vgMark:"area",encodeEntry:t=>Object.assign(Object.assign(Object.assign(Object.assign({},BG(t,{align:"ignore",baseline:"ignore",color:"include",orient:"include",size:"ignore"})),MG("x",t,{defaultPos:"zeroOrMin",defaultPos2:"zeroOrMin",range:"horizontal"===t.markDef.orient})),MG("y",t,{defaultPos:"zeroOrMin",defaultPos2:"zeroOrMin",range:"vertical"===t.markDef.orient})),WG(t))},bar:{vgMark:"rect",encodeEntry:t=>Object.assign(Object.assign(Object.assign({},BG(t,{align:"ignore",baseline:"ignore",color:"include",orient:"ignore",size:"ignore"})),jG(t,"x","bar")),jG(t,"y","bar"))},circle:{vgMark:"symbol",encodeEntry:t=>tJ(t,"circle")},geoshape:{vgMark:"shape",encodeEntry:t=>Object.assign({},BG(t,{align:"ignore",baseline:"ignore",color:"include",size:"ignore",orient:"ignore"})),postEncodingTransform:t=>{const{encoding:e}=t,n=e.shape;return[Object.assign({type:"geoshape",projection:t.projectionName()},n&&TV(n)&&n.type===EW?{field:PV(n,{expr:"datum"})}:{})]}},image:{vgMark:"image",encodeEntry:t=>Object.assign(Object.assign(Object.assign(Object.assign({},BG(t,{align:"ignore",baseline:"ignore",color:"ignore",orient:"ignore",size:"ignore"})),jG(t,"x","image")),jG(t,"y","image")),_G(t,"url"))},line:{vgMark:"line",encodeEntry:t=>Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},BG(t,{align:"ignore",baseline:"ignore",color:"include",size:"ignore",orient:"ignore"})),AG("x",t,{defaultPos:"mid"})),AG("y",t,{defaultPos:"mid"})),wG("size",t,{vgChannel:"strokeWidth"})),WG(t))},point:{vgMark:"symbol",encodeEntry:t=>tJ(t)},rect:{vgMark:"rect",encodeEntry:t=>Object.assign(Object.assign(Object.assign({},BG(t,{align:"ignore",baseline:"ignore",color:"include",orient:"ignore",size:"ignore"})),jG(t,"x","rect")),jG(t,"y","rect"))},rule:{vgMark:"rule",encodeEntry:t=>{const{markDef:e}=t,n=e.orient;return t.encoding.x||t.encoding.y||t.encoding.latitude||t.encoding.longitude?Object.assign(Object.assign(Object.assign(Object.assign({},BG(t,{align:"ignore",baseline:"ignore",color:"include",orient:"ignore",size:"ignore"})),MG("x",t,{defaultPos:"horizontal"===n?"zeroOrMin":"mid",defaultPos2:"zeroOrMax",range:"vertical"!==n})),MG("y",t,{defaultPos:"vertical"===n?"zeroOrMin":"mid",defaultPos2:"zeroOrMax",range:"horizontal"!==n})),wG("size",t,{vgChannel:"strokeWidth"})):{}}},square:{vgMark:"symbol",encodeEntry:t=>tJ(t,"square")},text:{vgMark:"text",encodeEntry:t=>{const{config:e,encoding:n}=t;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},BG(t,{align:"include",baseline:"include",color:"include",size:"ignore",orient:"ignore"})),AG("x",t,{defaultPos:"mid"})),AG("y",t,{defaultPos:"mid"})),_G(t)),wG("size",t,{vgChannel:"fontSize"})),VG("align",function(t,e,n){var r;if(void 0===(null!==(r=t.align)&&void 0!==r?r:iV("align",t,n)))return"center";return}(t.markDef,0,e))),VG("baseline",function(t,e,n){var r;if(void 0===(null!==(r=t.baseline)&&void 0!==r?r:iV("baseline",t,n)))return"middle";return}(t.markDef,0,e)))}},tick:{vgMark:"rect",encodeEntry:t=>{const{config:e,markDef:n}=t,r=n.orient,i="horizontal"===r?"width":"height",a="horizontal"===r?"height":"width";return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},BG(t,{align:"ignore",baseline:"ignore",color:"include",orient:"ignore",size:"ignore"})),AG("x",t,{defaultPos:"mid",vgChannel:"xc"})),AG("y",t,{defaultPos:"mid",vgChannel:"yc"})),wG("size",t,{defaultValue:function(t){const{config:e,markDef:n}=t,{orient:r}=n,i="horizontal"===r?"width":"height",a=t.getScaleComponent("horizontal"===r?"x":"y"),o=uL(n[i],n.size,iV("size",n,e,{vgChannel:i}),e.tick.bandSize);if(void 0!==o)return o;{const t=a?a.get("range"):void 0;if(t&&iG(t)&&OP(t.step))return 3*t.step/4;const n=eH(e.view,i);return 3*n/4}}(t),vgChannel:i})),{[a]:{value:uL(n.thickness,e.tick.thickness)}})}},trail:{vgMark:"trail",encodeEntry:t=>Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},BG(t,{align:"ignore",baseline:"ignore",color:"include",size:"include",orient:"ignore"})),AG("x",t,{defaultPos:"mid"})),AG("y",t,{defaultPos:"mid"})),wG("size",t)),WG(t))}};function nJ(t){return VP([mL,dL,wL],t.mark)?function(t){const e=mq(t.mark,t.encoding),n=aJ(t,{fromPrefix:e.length>0?rJ:""});return e.length>0?[{name:t.getName("pathgroup"),type:"group",from:{facet:{name:rJ+t.requestDataName(jH),data:t.requestDataName(jH),groupby:e}},encode:{update:{width:{field:{group:"width"}},height:{field:{group:"height"}}}},marks:n}]:n}(t):VP([hL],t.mark)?function(t){var e;const n=sG.some(e=>t.markDef[e]||iV(e,t.markDef,t.config));if(t.stack&&!t.fieldDef("size")&&n){const[n]=aJ(t,{fromPrefix:iJ}),r=t.scaleName(t.stack.fieldChannel),i=(e={})=>t.vgField(t.stack.fieldChannel,e),a=(t,e)=>{const n=[i({prefix:"min",suffix:"start",expr:e}),i({prefix:"max",suffix:"start",expr:e}),i({prefix:"min",suffix:"end",expr:e}),i({prefix:"max",suffix:"end",expr:e})];return`${t}(${n.map(t=>`scale('${r}',${t})`).join(",")})`};let o,s;"x"===t.stack.fieldChannel?(o=Object.assign(Object.assign({},LP(n.encode.update,["y","yc","y2","height",...sG])),{x:{signal:a("min","datum")},x2:{signal:a("max","datum")},clip:{value:!0}}),s={x:{field:{group:"x"},mult:-1},height:{field:{group:"height"}}},n.encode.update=Object.assign(Object.assign({},zP(n.encode.update,["y","yc","y2"])),{height:{field:{group:"height"}}})):(o=Object.assign(Object.assign({},LP(n.encode.update,["x","xc","x2","width"])),{y:{signal:a("min","datum")},y2:{signal:a("max","datum")},clip:{value:!0}}),s={y:{field:{group:"y"},mult:-1},width:{field:{group:"width"}}},n.encode.update=Object.assign(Object.assign({},zP(n.encode.update,["x","xc","x2"])),{width:{field:{group:"width"}}}));for(const e of sG){const r=iV(e,t.markDef,t.config);n.encode.update[e]?(o[e]=n.encode.update[e],delete n.encode.update[e]):r&&(o[e]={value:r}),r&&(n.encode.update[e]={value:0})}const u=t.vgField(t.stack.groupbyChannel)?[t.vgField(t.stack.groupbyChannel)]:[];(null===(e=t.fieldDef(t.stack.groupbyChannel))||void 0===e?void 0:e.bin)&&u.push(t.vgField(t.stack.groupbyChannel,{binSuffix:"end"}));const c=["stroke","strokeWidth","strokeJoin","strokeCap","strokeDash","strokeDashOffset","strokeMiterLimit","strokeOpacity"];return(o=c.reduce((e,r)=>{if(n.encode.update[r])return Object.assign(Object.assign({},e),{[r]:n.encode.update[r]});{const n=iV(r,t.markDef,t.config);return void 0!==n?Object.assign(Object.assign({},e),{[r]:{value:n}}):e}},o)).stroke&&(o.strokeForeground={value:!0},o.strokeOffset={value:0}),[{type:"group",from:{facet:{data:t.requestDataName(jH),name:iJ+t.requestDataName(jH),groupby:u,aggregate:{fields:[i({suffix:"start"}),i({suffix:"start"}),i({suffix:"end"}),i({suffix:"end"})],ops:["min","max","min","max"]}}},encode:{update:o},marks:[{type:"group",encode:{update:s},marks:[n]}]}]}return aJ(t)}(t):aJ(t)}const rJ="faceted_path_";const iJ="stack_group_";function aJ(t,e={fromPrefix:""}){const n=t.mark,r=uL(t.markDef.clip,function(t){const e=t.getScaleComponent("x"),n=t.getScaleComponent("y");return!!(e&&e.get("selectionExtent")||n&&n.get("selectionExtent"))||void 0}(t),function(t){const e=t.component.projection;return!(!e||e.isFit)||void 0}(t)),i=nV(t.markDef),a=t.encoding.key,o=function(t){const{encoding:e,stack:n,mark:r,markDef:i,config:a}=t,o=e.order;if(!(!lP(o)&&MV(o)&&WP(o.value)||!o&&WP(i.order)||WP(iV("order",i,a)))){if((lP(o)||TV(o))&&!n)return dV(o,{expr:"datum"});if(SL(r)){const n="horizontal"===i.orient?"y":"x",r=e[n];if(TV(r)){const e=r.sort;return lP(e)?{field:PV(r,{prefix:n,suffix:"sort_index",expr:"datum"})}:xV(e)?{field:PV({aggregate:lq(t.encoding)?e.op:void 0,field:e.field},{expr:"datum"})}:bV(e)?{field:PV(t.fieldDef(e.encoding),{expr:"datum"}),order:e.order}:{field:PV(r,{binSuffix:t.stack&&t.stack.impute?"mid":void 0,expr:"datum"})}}}}}(t),s=function(t){if(!t.component.selection)return null;const e=JP(t.component.selection).length;let n=e,r=t.parent;for(;r&&0===n;)n=JP(r.component.selection).length,r=r.parent;return n?{interactive:e>0}:null}(t),u=eJ[n].postEncodingTransform?eJ[n].postEncodingTransform(t):null;return[Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({name:t.getName("marks"),type:eJ[n].vgMark},r?{clip:!0}:{}),i?{style:i}:{}),a?{key:a.field}:{}),o?{sort:o}:{}),s||{}),{from:{data:e.fromPrefix+t.requestDataName(jH)},encode:{update:eJ[n].encodeEntry(t)}}),u?{transform:u}:{})]}class oJ extends uY{constructor(t,e,n,r={},i,a){var o;super(t,"unit",e,n,a,i,void 0,t.view),this.specifiedScales={},this.specifiedAxes={},this.specifiedLegends={},this.specifiedProjection={},this.selection={},this.children=[];const s=NL(t.mark)?t.mark.type:t.mark,u=function(t,e){return PY(t,e)}(null!==(o=t.encoding)&&void 0!==o?o:{},i);this.markDef=QY(t.mark,u,a,{graticule:t.data&&FH(t.data)});const c=this.encoding=dq(u,this.markDef);this.size=function({encoding:t,size:e}){for(const n of Zz){const r=Qz(n),i=$V(t[n]);Zq(e[r])&&i&&zV(i)&&(delete e[r],BU(jU.stepDropped(r)))}return e}({encoding:c,size:Object.assign(Object.assign(Object.assign({},r),t.width?{width:t.width}:{}),t.height?{height:t.height}:{})}),this.stack=gH(s,c),this.specifiedScales=this.initScales(s,c),this.specifiedAxes=this.initAxes(c),this.specifiedLegends=this.initLegend(c),this.specifiedProjection=t.projection,this.selection=t.selection}get hasProjection(){const{encoding:t}=this,e=this.mark===EL,n=t&&xz.some(e=>TV(t[e]));return e||n}scaleDomain(t){const e=this.specifiedScales[t];return e?e.domain:void 0}axis(t){return this.specifiedAxes[t]}legend(t){return this.specifiedLegends[t]}initScales(t,e){return fB.reduce((t,n)=>{let r,i;const a=e[n];return TV(a)?(r=a,i=a.scale):NV(a)&&(r=a.condition,i=a.condition.scale),r&&(t[n]=null!==i&&void 0!==i?i:{}),t},{})}initAxes(t){return[KL,XL].reduce((e,n)=>{const r=t[n];if(TV(r)||n===KL&&TV(t.x2)||n===XL&&TV(t.y2)){const t=TV(r)?r.axis:null;null!==t&&(e[n]=Object.assign({},t))}return e},{})}initLegend(t){return cB.reduce((e,n)=>{const r=t[n];if(r){const t=TV(r)?r.legend:NV(r)?r.condition.legend:null;null!==t&&!1!==t&&function(t){switch(t){case nz:case rz:case iz:case oz:case az:case sz:case lz:return!0;case uz:case cz:return!1}}(n)&&(e[n]=Object.assign({},t))}return e},{})}parseData(){this.component.data=WY(this)}parseLayoutSize(){!function(t){const{size:e,component:n}=t;for(const r of Zz){const i=Qz(r);if(e[i]){const t=e[i];n.layoutSize.set(i,Zq(t)?"step":t,!0)}else{const e=MY(t,i);n.layoutSize.set(i,e,!1)}}}(this)}parseSelections(){this.component.selection=function(t,e){var n;const r={},i=t.config.selection;for(const a in e){if(!_P(e,a))continue;const o=PP(e[a]),s=i[o.type],{fields:u,encodings:c}=s,l=b(s,["fields","encodings"]);for(const t in l)"encodings"===t&&o.fields||"fields"===t&&o.encodings||("mark"===t&&(o[t]=Object.assign(Object.assign({},l[t]),o[t])),void 0!==o[t]&&!0!==o[t]||(o[t]=null!==(n=l[t])&&void 0!==n?n:o[t]));const f=tL(a),d=r[f]=Object.assign(Object.assign({},o),{name:f,events:dP(o.on)?ZM(o.on,"scope"):PP(o.on)});u$(d,n=>{n.has(d)&&n.parse&&n.parse(t,d,o,e[a])})}return r}(this,this.selection)}parseMarkGroup(){this.component.mark=nJ(this)}parseAxesAndHeaders(){this.component.axes=KY(this)}assembleSelectionTopLevelSignals(t){return function(t,e){let n=!1;E$(t,(r,i)=>{const a=r.name,o=hP(a+b$);if(0===e.filter(t=>t.name===a).length){const t="global"===r.resolve?"union":r.resolve,n="multi"===r.type?", true)":")";e.push({name:r.name,update:`${k$}(${o}, ${hP(t)}${n}`})}n=!0,i.topLevelSignals&&(e=i.topLevelSignals(t,r,e)),u$(r,n=>{n.topLevelSignals&&(e=n.topLevelSignals(t,r,e))})}),n&&0===e.filter(t=>"unit"===t.name).length&&e.unshift({name:"unit",value:{},on:[{events:"mousemove",update:"isTuple(group()) ? group() : unit"}]});return f$(e)}(this,t)}assembleSignals(){return[...R$(this),...function(t,e){return E$(t,(n,r)=>{const i=n.name;let a=r.modifyExpr(t,n);e.push(...r.signals(t,n)),u$(n,r=>{r.signals&&(e=r.signals(t,n,e)),r.modifyExpr&&(a=r.modifyExpr(t,n,a))}),e.push({name:i+w$,on:[{events:{signal:n.name+x$},update:`modify(${hP(n.name+b$)}, ${a})`}]})}),f$(e)}(this,[])]}assembleSelectionData(t){return function(t,e){const n=[...e];return E$(t,e=>{const r={name:e.name+b$};if(e.init){const n=e.project.items.map(t=>{const{signals:e}=t;return b(t,["signals"])}),i=e.init.map(t=>c$(t,!1));r.values="interval"===e.type?[{unit:O$(t,{escape:!1}),fields:n,values:i}]:i.map(e=>({unit:O$(t,{escape:!1}),fields:n,values:e}))}n.filter(t=>t.name===e.name+b$).length||n.push(r)}),n}(this,t)}assembleLayout(){return null}assembleLayoutSignals(){return aK(this)}assembleMarks(){var t;let e=null!==(t=this.component.mark)&&void 0!==t?t:[];return this.parent&&oY(this.parent)||(e=l$(this,e)),e.map(this.correctDataNames)}getMapping(){return this.encoding}get mark(){return this.markDef.type}channelHasField(t){return cq(this.encoding,t)}fieldDef(t){return KV(this.encoding[t])}}class sJ extends sY{constructor(t,e,n,r,i,a){super(t,"layer",e,n,a,i,t.resolve,t.view);const o=Object.assign(Object.assign(Object.assign({},r),t.width?{width:t.width}:{}),t.height?{height:t.height}:{});this.children=t.layer.map((t,e)=>{if(fH(t))return new sJ(t,this,this.getName("layer_"+e),o,i,a);if(RL(t))return new oJ(t,this,this.getName("layer_"+e),o,i,a);throw new Error(jU.invalidSpec(t))})}parseData(){this.component.data=WY(this);for(const t of this.children)t.parseData()}parseLayoutSize(){AY(this)}parseSelections(){this.component.selection={};for(const t of this.children)t.parseSelections(),JP(t.component.selection).forEach(e=>{this.component.selection[e]=t.component.selection[e]})}parseMarkGroup(){for(const t of this.children)t.parseMarkGroup()}parseAxesAndHeaders(){!function(t){var e;const{axes:n,resolve:r}=t.component,i={top:0,bottom:0,right:0,left:0};for(const e of t.children){e.parseAxesAndHeaders();for(const i of JP(e.component.axes))r.axis[i]=fK(t.component.resolve,i),"shared"===r.axis[i]&&(n[i]=YY(n[i],e.component.axes[i]),n[i]||(r.axis[i]="independent",delete n[i]))}for(const a of[KL,XL]){for(const o of t.children)if(o.component.axes[a]){if("independent"===r.axis[a]){n[a]=(e=n[a],null!==e&&void 0!==e?e:[]).concat(o.component.axes[a]);for(const t of o.component.axes[a]){const{value:e,explicit:n}=t.getWithExplicit("orient");if(i[e]>0&&!n){const n=XY[e];i[e]>i[n]&&t.set("orient",n,!1)}i[e]++}}delete o.component.axes[a]}if("independent"===r.axis[a]&&n[a]&&n[a].length>1)for(const t of n[a])t.get("grid")&&!t.explicit.grid&&(t.implicit.grid=!1)}}(this)}assembleSelectionTopLevelSignals(t){return this.children.reduce((t,e)=>e.assembleSelectionTopLevelSignals(t),t)}assembleSignals(){return this.children.reduce((t,e)=>t.concat(e.assembleSignals()),R$(this))}assembleLayoutSignals(){return this.children.reduce((t,e)=>t.concat(e.assembleLayoutSignals()),aK(this))}assembleSelectionData(t){return this.children.reduce((t,e)=>e.assembleSelectionData(t),t)}assembleTitle(){let t=super.assembleTitle();if(t)return t;for(const e of this.children)if(t=e.assembleTitle())return t}assembleLayout(){return null}assembleMarks(){return function(t,e){for(const n of t.children)nY(n)&&(e=l$(n,e));return e}(this,this.children.flatMap(t=>t.assembleMarks()))}assembleLegends(){return this.children.reduce((t,e)=>t.concat(e.assembleLegends()),zK(this))}}class uJ extends VY{constructor(t,e,n,r,i){super(t,"repeat",e,n,i,r,t.resolve),t.resolve&&t.resolve.axis&&("shared"===t.resolve.axis.x||"shared"===t.resolve.axis.y)&&BU(jU.REPEAT_CANNOT_SHARE_AXIS),this.repeat=t.repeat,this.children=this._initChildren(t,this.repeat,r,i)}_initChildren(t,e,n,r){const i=[],a=!lP(e)&&e.row||[n?n.row:null],o=!lP(e)&&e.column||[n?n.column:null],s=lP(e)&&e||[n?n.repeat:null];for(const e of s)for(const n of a)for(const a of o){const o=(e?`__repeat_repeat_${e}`:"")+(n?`__repeat_row_${n}`:"")+(a?`__repeat_column_${a}`:""),s={repeat:e,row:n,column:a};i.push(cJ(t.spec,this,this.getName("child"+o),void 0,s,r))}return i}parseLayoutSize(){NY(this)}assembleDefaultLayout(){const{repeat:t}=this,e=lP(t)?void 0:t.column?t.column.length:1;return Object.assign(Object.assign({},e?{columns:e}:{}),{bounds:"full",align:"all"})}}function cJ(t,e,n,r,i,a){if(_V(t))return new zY(t,e,n,i,a);if(fH(t))return new sJ(t,e,n,r,i,a);if(RL(t))return new oJ(t,e,n,r,i,a);if(Jq(t))return new uJ(t,e,n,i,a);if(function(t){return Xq(t)||Yq(t)||Kq(t)}(t))return new qY(t,e,n,i,a);throw new Error(jU.invalidSpec(t))}function lJ(t,e={}){e.logger&&function(t){LU=t}(e.logger),e.fieldTitle&&WV(e.fieldTitle);try{const n=aH(vP({},e.config,t.config)),r=EH(t,n),i=cJ(r,null,"",void 0,void 0,n);return i.parse(),function(t,e){YK(t.sources);let n=0,r=0;for(let r=0;r<CX&&IX(t,e);r++)n++;t.sources.map(bX);for(let n=0;n<CX&&IX(t,e);n++)r++;YK(t.sources),Math.max(n,r)===CX&&BU(`Maximum optimization runs(${CX}) reached.`)}(i.component.data,i),{spec:function(t,e,n={},r){const i=t.config?cH(t.config):void 0,a=[].concat(t.assembleSelectionData([]),function(t,e){var n,r;const i=[],a=_Y(i);let o=0;t.sources.forEach(t=>{t.hasName()||(t.dataName=`source_${o++}`);const e=t.assemble();a(t,e)}),i.forEach(t=>{0===t.transform.length&&delete t.transform});let s=0;for(const[t,e]of i.entries())0!==(n=e.transform,null!==n&&void 0!==n?n:[]).length||e.source||i.splice(s++,0,i.splice(t,1)[0]);for(const e of i)for(const n of null!==(r=e.transform)&&void 0!==r?r:[])"lookup"===n.type&&(n.from=t.outputNodes[n.from].getSource());for(const t of i)t.name in e&&(t.values=e[t.name]);return i}(t.component.data,n)),o=t.assembleProjections(),s=t.assembleTitle(),u=t.assembleGroupStyle(),c=t.assembleGroupEncodeEntry(!0);let l=t.assembleLayoutSignals();return l=l.filter(t=>"width"!==t.name&&"height"!==t.name||void 0===t.value||(e[t.name]=+t.value,!1)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({$schema:"https://vega.github.io/schema/vega/v5.json"},t.description?{description:t.description}:{}),e),s?{title:s}:{}),u?{style:u}:{}),c?{encode:{update:c}}:{}),{data:a}),o.length>0?{projections:o}:{}),t.assembleGroup([...l,...t.assembleSelectionTopLevelSignals([])])),i?{config:i}:{}),r?{usermeta:r}:{})}(i,function(t,e,n,r){const i=r.component.layoutSize.get("width"),a=r.component.layoutSize.get("height");void 0===e?e={type:"pad"}:dP(e)&&(e={type:e});if(i&&a&&function(t){return"fit"===t||"fit-x"===t||"fit-y"===t}(e.type))if("step"===i&&"step"===a)BU(jU.droppingFit()),e.type="pad";else if("step"===i||"step"===a){const t="step"===i?"width":"height";BU(jU.droppingFit(tB(t)));const n="width"===t?"height":"width";e.type=function(t){return t?`fit-${tB(t)}`:"fit"}(n)}return Object.assign(Object.assign(Object.assign({},1===JP(e).length&&e.type?"pad"===e.type?{}:{autosize:e.type}:{autosize:e}),AH(n)),AH(t))}(t,r.autosize,n,i),t.datasets,t.usermeta),normalized:r}}finally{e.logger&&zU(),e.fieldTitle&&WV(BV)}}const fJ=new class extends dH{mapUnit(t,{config:e}){if(t.encoding){const{encoding:n,transform:r}=t,{bins:i,timeUnits:a,aggregate:o,groupby:s,encoding:u}=fq(n,e),c=[...r||[],...i,...a,...0===o.length?[]:[{aggregate:o,groupby:s}]];return Object.assign(Object.assign(Object.assign({},t),c.length>0?{transform:c}:{}),{encoding:u})}return t}};function dJ(t,e){return fJ.map(t,{config:e})}const hJ=oP.version;var pJ=n(195),mJ=n.n(pJ),gJ=n(284);var vJ={background:"#333",title:{color:"#fff"},style:{"guide-label":{fill:"#fff"},"guide-title":{fill:"#fff"}},axis:{domainColor:"#fff",gridColor:"#888",tickColor:"#fff"}};var yJ={background:"#fff",arc:{fill:"#4572a7"},area:{fill:"#4572a7"},line:{stroke:"#4572a7",strokeWidth:2},path:{stroke:"#4572a7"},rect:{fill:"#4572a7"},shape:{stroke:"#4572a7"},symbol:{fill:"#4572a7",strokeWidth:1.5,size:50},axis:{bandPosition:.5,grid:!0,gridColor:"#000000",gridOpacity:1,gridWidth:.5,labelPadding:10,tickSize:5,tickWidth:.5},axisBand:{grid:!1,tickExtra:!0},legend:{labelBaseline:"middle",labelFontSize:11,symbolSize:50,symbolType:"square"},range:{category:["#4572a7","#aa4643","#8aa453","#71598e","#4598ae","#d98445","#94aace","#d09393","#b9cc98","#a99cbc"]}};var bJ={arc:{fill:"#30a2da"},area:{fill:"#30a2da"},axis:{domainColor:"#cbcbcb",grid:!0,gridColor:"#cbcbcb",gridWidth:1,labelColor:"#999",labelFontSize:10,titleColor:"#333",tickColor:"#cbcbcb",tickSize:10,titleFontSize:14,titlePadding:10,labelPadding:4},axisBand:{grid:!1},background:"#f0f0f0",group:{fill:"#f0f0f0"},legend:{labelColor:"#333",labelFontSize:11,padding:1,symbolSize:30,symbolType:"square",titleColor:"#333",titleFontSize:14,titlePadding:10},line:{stroke:"#30a2da",strokeWidth:2},path:{stroke:"#30a2da",strokeWidth:.5},rect:{fill:"#30a2da"},range:{category:["#30a2da","#fc4f30","#e5ae38","#6d904f","#8b8b8b","#b96db8","#ff9e27","#56cc60","#52d2ca","#52689e","#545454","#9fe4f8"],diverging:["#cc0020","#e77866","#f6e7e1","#d6e8ed","#91bfd9","#1d78b5"],heatmap:["#d6e8ed","#cee0e5","#91bfd9","#549cc6","#1d78b5"]},point:{filled:!0,shape:"circle"},shape:{stroke:"#30a2da"},bar:{binSpacing:2,fill:"#30a2da",stroke:null},title:{anchor:"start",fontSize:24,fontWeight:600,offset:20}};var xJ={group:{fill:"#e5e5e5"},arc:{fill:"#000"},area:{fill:"#000"},line:{stroke:"#000"},path:{stroke:"#000"},rect:{fill:"#000"},shape:{stroke:"#000"},symbol:{fill:"#000",size:40},axis:{domain:!1,grid:!0,gridColor:"#FFFFFF",gridOpacity:1,labelColor:"#7F7F7F",labelPadding:4,tickColor:"#7F7F7F",tickSize:5.67,titleFontSize:16,titleFontWeight:"normal"},legend:{labelBaseline:"middle",labelFontSize:11,symbolSize:40},range:{category:["#000000","#7F7F7F","#1A1A1A","#999999","#333333","#B0B0B0","#4D4D4D","#C9C9C9","#666666","#DCDCDC"]}};const wJ="Benton Gothic Bold, sans-serif",kJ={"category-6":["#ec8431","#829eb1","#c89d29","#3580b1","#adc839","#ab7fb4"],"fire-7":["#fbf2c7","#f9e39c","#f8d36e","#f4bb6a","#e68a4f","#d15a40","#ab4232"],"fireandice-6":["#e68a4f","#f4bb6a","#f9e39c","#dadfe2","#a6b7c6","#849eae"],"ice-7":["#edefee","#dadfe2","#c4ccd2","#a6b7c6","#849eae","#607785","#47525d"]};var _J={background:"#ffffff",title:{anchor:"start",color:"#000000",font:wJ,fontSize:22,fontWeight:"normal"},arc:{fill:"#82c6df"},area:{fill:"#82c6df"},line:{stroke:"#82c6df",strokeWidth:2},path:{stroke:"#82c6df"},rect:{fill:"#82c6df"},shape:{stroke:"#82c6df"},symbol:{fill:"#82c6df",size:30},axis:{labelFont:"Benton Gothic, sans-serif",labelFontSize:11.5,labelFontWeight:"normal",titleFont:wJ,titleFontSize:13,titleFontWeight:"normal"},axisX:{labelAngle:0,labelPadding:4,tickSize:3},axisY:{labelBaseline:"middle",maxExtent:45,minExtent:45,tickSize:2,titleAlign:"left",titleAngle:0,titleX:-45,titleY:-11},legend:{labelFont:"Benton Gothic, sans-serif",labelFontSize:11.5,symbolType:"square",titleFont:wJ,titleFontSize:13,titleFontWeight:"normal"},range:{category:kJ["category-6"],diverging:kJ["fireandice-6"],heatmap:kJ["fire-7"],ordinal:kJ["fire-7"],ramp:kJ["fire-7"]}};var EJ={background:"#f9f9f9",arc:{fill:"#ab5787"},area:{fill:"#ab5787"},line:{stroke:"#ab5787"},path:{stroke:"#ab5787"},rect:{fill:"#ab5787"},shape:{stroke:"#ab5787"},symbol:{fill:"#ab5787",size:30},axis:{domainColor:"#979797",domainWidth:.5,gridWidth:.2,labelColor:"#979797",tickColor:"#979797",tickWidth:.2,titleColor:"#979797"},axisBand:{grid:!1},axisX:{grid:!0,tickSize:10},axisY:{domain:!1,grid:!0,tickSize:0},legend:{labelFontSize:11,padding:1,symbolSize:30,symbolType:"square"},range:{category:["#ab5787","#51b2e5","#703c5c","#168dd9","#d190b6","#00609f","#d365ba","#154866","#666666","#c4c4c4"]}};var OJ={background:"#fff",arc:{fill:"#3e5c69"},area:{fill:"#3e5c69"},line:{stroke:"#3e5c69"},path:{stroke:"#3e5c69"},rect:{fill:"#3e5c69"},shape:{stroke:"#3e5c69"},symbol:{fill:"#3e5c69"},axis:{domainWidth:.5,grid:!0,labelPadding:2,tickSize:5,tickWidth:.5,titleFontWeight:"normal"},axisBand:{grid:!1},axisX:{gridWidth:.2},axisY:{gridDash:[3],gridWidth:.4},legend:{labelFontSize:11,padding:1,symbolType:"square"},range:{category:["#3e5c69","#6793a6","#182429","#0570b0","#3690c0","#74a9cf","#a6bddb","#e2ddf2"]}};const SJ={"main-colors":["#1696d2","#d2d2d2","#000000","#fdbf11","#ec008b","#55b748","#5c5859","#db2b27"],"shades-blue":["#CFE8F3","#A2D4EC","#73BFE2","#46ABDB","#1696D2","#12719E","#0A4C6A","#062635"],"shades-gray":["#F5F5F5","#ECECEC","#E3E3E3","#DCDBDB","#D2D2D2","#9D9D9D","#696969","#353535"],"shades-yellow":["#FFF2CF","#FCE39E","#FDD870","#FCCB41","#FDBF11","#E88E2D","#CA5800","#843215"],"shades-magenta":["#F5CBDF","#EB99C2","#E46AA7","#E54096","#EC008B","#AF1F6B","#761548","#351123"],"shades-green":["#DCEDD9","#BCDEB4","#98CF90","#78C26D","#55B748","#408941","#2C5C2D","#1A2E19"],"shades-black":["#D5D5D4","#ADABAC","#848081","#5C5859","#332D2F","#262223","#1A1717","#0E0C0D"],"shades-red":["#F8D5D4","#F1AAA9","#E9807D","#E25552","#DB2B27","#A4201D","#6E1614","#370B0A"],"one-group":["#1696d2","#000000"],"two-groups-cat-1":["#1696d2","#000000"],"two-groups-cat-2":["#1696d2","#fdbf11"],"two-groups-cat-3":["#1696d2","#db2b27"],"two-groups-seq":["#a2d4ec","#1696d2"],"three-groups-cat":["#1696d2","#fdbf11","#000000"],"three-groups-seq":["#a2d4ec","#1696d2","#0a4c6a"],"four-groups-cat-1":["#000000","#d2d2d2","#fdbf11","#1696d2"],"four-groups-cat-2":["#1696d2","#ec0008b","#fdbf11","#5c5859"],"four-groups-seq":["#cfe8f3","#73bf42","#1696d2","#0a4c6a"],"five-groups-cat-1":["#1696d2","#fdbf11","#d2d2d2","#ec008b","#000000"],"five-groups-cat-2":["#1696d2","#0a4c6a","#d2d2d2","#fdbf11","#332d2f"],"five-groups-seq":["#cfe8f3","#73bf42","#1696d2","#0a4c6a","#000000"],"six-groups-cat-1":["#1696d2","#ec008b","#fdbf11","#000000","#d2d2d2","#55b748"],"six-groups-cat-2":["#1696d2","#d2d2d2","#ec008b","#fdbf11","#332d2f","#0a4c6a"],"six-groups-seq":["#cfe8f3","#a2d4ec","#73bfe2","#46abdb","#1696d2","#12719e"],"diverging-colors":["#ca5800","#fdbf11","#fdd870","#fff2cf","#cfe8f3","#73bfe2","#1696d2","#0a4c6a"]};var CJ={background:"#FFFFFF",title:{anchor:"start",fontSize:18,font:"Lato"},axisX:{domain:!0,domainColor:"#000000",domainWidth:1,grid:!1,labelFontSize:12,labelFont:"Lato",labelAngle:0,tickColor:"#000000",tickSize:5,titleFontSize:12,titlePadding:10,titleFont:"Lato"},axisY:{domain:!1,domainWidth:1,grid:!0,gridColor:"#DEDDDD",gridWidth:1,labelFontSize:12,labelFont:"Lato",labelPadding:8,ticks:!1,titleFontSize:12,titlePadding:10,titleFont:"Lato",titleAngle:0,titleY:-10,titleX:18},legend:{labelFontSize:12,labelFont:"Lato",symbolSize:100,titleFontSize:12,titlePadding:10,titleFont:"Lato",orient:"right",offset:10},view:{stroke:"transparent"},range:{category:SJ["six-groups-cat-1"],diverging:SJ["diverging-colors"],heatmap:SJ["diverging-colors"],ordinal:SJ["six-groups-seq"],ramp:SJ["shades-blue"]},area:{fill:"#1696d2"},rect:{fill:"#1696d2"},line:{color:"#1696d2",stroke:"#1696d2",strokeWidth:5},trail:{color:"#1696d2",stroke:"#1696d2",strokeWidth:0,size:1},path:{stroke:"#1696d2",strokeWidth:.5},point:{filled:!0},text:{font:"Lato",color:"#1696d2",fontSize:11,align:"center",fontWeight:400,size:11},style:{bar:{fill:"#1696d2",stroke:null}},arc:{fill:"#1696d2"},shape:{stroke:"#1696d2"},symbol:{fill:"#1696d2",size:30}};var AJ={arc:{fill:"#3366CC"},area:{fill:"#3366CC"},path:{stroke:"#3366CC"},rect:{fill:"#3366CC"},shape:{stroke:"#3366CC"},symbol:{stroke:"#3366CC"},circle:{fill:"#3366CC"},background:"#fff",padding:{top:10,right:10,bottom:10,left:10},style:{"guide-label":{font:"Arial, sans-serif",fontSize:12},"guide-title":{font:"Arial, sans-serif",fontSize:12},"group-title":{font:"Arial, sans-serif",fontSize:12}},title:{font:"Arial, sans-serif",fontSize:14,fontWeight:"bold",dy:-3,anchor:"start"},axis:{gridColor:"#ccc",tickColor:"#ccc",domain:!1,grid:!0},range:{category:["#4285F4","#DB4437","#F4B400","#0F9D58","#AB47BC","#00ACC1","#FF7043","#9E9D24","#5C6BC0","#F06292","#00796B","#C2185B"],heatmap:["#c6dafc","#5e97f6","#2a56c6"]}};const NJ=gJ.version;var TJ=n(283),IJ="#vg-tooltip-element {\n visibility: hidden;\n padding: 8px;\n position: fixed;\n z-index: 1000;\n font-family: sans-serif;\n font-size: 11px;\n border-radius: 3px;\n box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);\n /* The default theme is the light theme. */\n background-color: rgba(255, 255, 255, 0.95);\n border: 1px solid #d9d9d9;\n color: black; }\n #vg-tooltip-element.visible {\n visibility: visible; }\n #vg-tooltip-element h2 {\n margin-top: 0;\n margin-bottom: 10px;\n font-size: 13px; }\n #vg-tooltip-element table {\n border-spacing: 0; }\n #vg-tooltip-element table tr {\n border: none; }\n #vg-tooltip-element table tr td {\n overflow: hidden;\n text-overflow: ellipsis;\n padding-top: 2px;\n padding-bottom: 2px; }\n #vg-tooltip-element table tr td.key {\n color: #808080;\n max-width: 150px;\n text-align: right;\n padding-right: 4px; }\n #vg-tooltip-element table tr td.value {\n display: block;\n max-width: 300px;\n max-height: 7em;\n text-align: left; }\n #vg-tooltip-element.dark-theme {\n background-color: rgba(32, 32, 32, 0.9);\n border: 1px solid #f5f5f5;\n color: white; }\n #vg-tooltip-element.dark-theme td.key {\n color: #bfbfbf; }\n";const DJ="vg-tooltip-element",MJ={offsetX:10,offsetY:10,id:DJ,styleId:"vega-tooltip-style",theme:"light",disableDefaultStyle:!1,sanitize:function(t){return String(t).replace(/&/g,"&amp;").replace(/</g,"&lt;")},maxDepth:2};var RJ=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n};function FJ(t,e){return JSON.stringify(t,function(t){const e=[];return function(n,r){if("object"!=typeof r||null===r)return r;const i=e.indexOf(this)+1;return e.length=i,e.length>t?"[Object]":e.indexOf(r)>=0?"[Circular]":(e.push(r),r)}}(e))}class jJ{constructor(t){this.options=Object.assign(Object.assign({},MJ),t);const e=this.options.id;if(this.call=this.tooltipHandler.bind(this),!this.options.disableDefaultStyle&&!document.getElementById(this.options.styleId)){const t=document.createElement("style");t.setAttribute("id",this.options.styleId),t.innerHTML=function(t){if(!/^[A-Za-z]+[-:.\w]*$/.test(t))throw new Error("Invalid HTML ID");return IJ.toString().replace(DJ,t)}(e);const n=document.head;n.childNodes.length>0?n.insertBefore(t,n.childNodes[0]):n.appendChild(t)}this.el=document.getElementById(e),this.el||(this.el=document.createElement("div"),this.el.setAttribute("id",e),this.el.classList.add("vg-tooltip"),document.body.appendChild(this.el))}tooltipHandler(t,e,n,r){if(null==r||""===r)return void this.el.classList.remove("visible",`${this.options.theme}-theme`);this.el.innerHTML=function(t,e,n){if(Object(ct.A)(t))return`[${t.map(t=>e(Object(ct.H)(t)?t:FJ(t,n))).join(", ")}]`;if(Object(ct.F)(t)){let r="";const i=t,{title:a}=i,o=RJ(i,["title"]);a&&(r+=`<h2>${e(a)}</h2>`);const s=Object.keys(o);if(s.length>0){r+="<table>";for(const t of s){let i=o[t];void 0!==i&&(Object(ct.F)(i)&&(i=FJ(i,n)),r+=`<tr><td class="key">${e(t)}:</td><td class="value">${e(i)}</td></tr>`)}r+="</table>"}return r||"{}"}return e(t)}(r,this.options.sanitize,this.options.maxDepth),this.el.classList.add("visible",`${this.options.theme}-theme`);const{x:i,y:a}=function(t,e,n,r){let i=t.clientX+n;i+e.width>window.innerWidth&&(i=+t.clientX-n-e.width);let a=t.clientY+r;return a+e.height>window.innerHeight&&(a=+t.clientY-r-e.height),{x:i,y:a}}(e,this.el.getBoundingClientRect(),this.options.offsetX,this.options.offsetY);this.el.setAttribute("style",`top: ${a}px; left: ${i}px`)}}TJ.version;var PJ=function(t,e,n){const r=t.open(e),i=250;let a=~~(1e4/i);t.addEventListener("message",function e(n){n.source===r&&(a=0,t.removeEventListener("message",e,!1))},!1),setTimeout(function t(){a<=0||(r.postMessage(n,"*"),setTimeout(t,i),a-=1)},i)},LJ='.vega-embed {\n position: relative;\n display: inline-block;\n padding-right: 38px; }\n .vega-embed details:not([open]) > :not(summary) {\n display: none !important; }\n .vega-embed summary {\n list-style: none;\n position: absolute;\n top: 0;\n right: 0;\n padding: 6px;\n z-index: 1000;\n background: white;\n box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1);\n color: #1b1e23;\n border: 1px solid #aaa;\n border-radius: 999px;\n opacity: 0.2;\n transition: opacity 0.4s ease-in;\n outline: none;\n cursor: pointer;\n line-height: 0px; }\n .vega-embed summary::-webkit-details-marker {\n display: none; }\n .vega-embed summary:active {\n box-shadow: #aaa 0px 0px 0px 1px inset; }\n .vega-embed summary svg {\n width: 14px;\n height: 14px; }\n .vega-embed details[open] summary {\n opacity: 0.7; }\n .vega-embed:hover summary,\n .vega-embed:focus summary {\n opacity: 1 !important;\n transition: opacity 0.2s ease; }\n .vega-embed .vega-actions {\n position: absolute;\n top: 35px;\n right: -9px;\n display: flex;\n flex-direction: column;\n padding-bottom: 8px;\n padding-top: 8px;\n border-radius: 4px;\n box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.2);\n border: 1px solid #d9d9d9;\n background: white;\n animation-duration: 0.15s;\n animation-name: scale-in;\n animation-timing-function: cubic-bezier(0.2, 0, 0.13, 1.5); }\n .vega-embed .vega-actions a {\n padding: 8px 16px;\n font-family: sans-serif;\n font-size: 14px;\n font-weight: 600;\n white-space: nowrap;\n color: #434a56;\n text-decoration: none; }\n .vega-embed .vega-actions a:hover {\n background-color: #f7f7f9;\n color: black; }\n .vega-embed .vega-actions::before, .vega-embed .vega-actions::after {\n content: "";\n display: inline-block;\n position: absolute; }\n .vega-embed .vega-actions::before {\n left: auto;\n right: 14px;\n top: -16px;\n border: 8px solid #0000;\n border-bottom-color: #d9d9d9; }\n .vega-embed .vega-actions::after {\n left: auto;\n right: 15px;\n top: -14px;\n border: 7px solid #0000;\n border-bottom-color: #fff; }\n\n.vega-embed-wrapper {\n max-width: 100%;\n overflow: scroll;\n padding-right: 14px; }\n\n@keyframes scale-in {\n from {\n opacity: 0;\n transform: scale(0.6); }\n to {\n opacity: 1;\n transform: scale(1); } }\n';n.d(e,"vega",function(){return zJ}),n.d(e,"vegaLite",function(){return BJ}),n.d(e,"guessMode",function(){return KJ}),n.d(e,"default",function(){return XJ});const zJ=p;let BJ=v;const UJ=window;void 0===BJ&&UJ.vl&&UJ.vl.compile&&(BJ=UJ.vl);const WJ={CLICK_TO_VIEW_ACTIONS:"Click to view actions",COMPILED_ACTION:"View Compiled Vega",EDITOR_ACTION:"Open in Vega Editor",PNG_ACTION:"Save as PNG",SOURCE_ACTION:"View Source",SVG_ACTION:"Save as SVG"},VJ={vega:"Vega","vega-lite":"Vega-Lite"},qJ={vega:zJ.version,"vega-lite":BJ?BJ.version:"not available"},HJ={vega:t=>t,"vega-lite":(t,e)=>BJ.compile(t,{config:e}).spec},GJ='\n<svg viewBox="0 0 16 16" fill="currentColor" stroke="none" stroke-width="1" stroke-linecap="round" stroke-linejoin="round">\n <circle r="2" cy="8" cx="2"></circle>\n <circle r="2" cy="8" cx="8"></circle>\n <circle r="2" cy="8" cx="14"></circle>\n</svg>';function $J(t,e,n,r){const i=`<html><head>${e}</head><body><pre><code class="json">`,a=`</code></pre>${n}</body></html>`,o=window.open("");o.document.write(i+t+a),o.document.title=`${VJ[r]} JSON Source`}function KJ(t,e){if(t.$schema){const n=mJ()(t.$schema);e&&e!==n.library&&console.warn(`The given visualization spec is written in ${VJ[n.library]}, but mode argument sets ${VJ[e]||e}.`);const r=n.library;return Object(ut.satisfies)(qJ[r],`^${n.version.slice(1)}`)||console.warn(`The input spec uses ${VJ[r]} ${n.version}, but the current version of ${VJ[r]} is v${qJ[r]}.`),r}return"mark"in t||"encoding"in t||"layer"in t||"hconcat"in t||"vconcat"in t||"facet"in t||"repeat"in t?"vega-lite":"marks"in t||"signals"in t||"scales"in t||"axes"in t?"vega":e||"vega"}function XJ(t,e,n={}){return function(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})}(this,void 0,void 0,function*(){const r=function(t){return!!(t&&"load"in t)}(n.loader)?n.loader:zJ.loader(n.loader);if(zJ.isString(e)){const i=yield r.load(e);return XJ(t,JSON.parse(i),n)}let i=(n=at()(n,e.usermeta&&e.usermeta.embedOptions||{})).config||{};if(zJ.isString(i)){const a=yield r.load(i);return XJ(t,e,Object.assign(Object.assign({},n),{config:JSON.parse(a)}))}const a=Object(ct.B)(n.actions)?n.actions:at()({export:{svg:!0,png:!0},source:!0,compiled:!0,editor:!0},n.actions||{}),o=Object.assign(Object.assign({},WJ),n.i18n),s=n.renderer||"canvas",u=n.logLevel||zJ.Warn,c=n.downloadFileName||"visualization";if(!1!==n.defaultStyle){const t="vega-embed-style";if(!document.getElementById(t)){const e=document.createElement("style");e.id=t,e.innerText=void 0===n.defaultStyle||!0===n.defaultStyle?(LJ||"").toString():n.defaultStyle,document.head.appendChild(e)}}n.theme&&(i=at()(y[n.theme],i));const l=KJ(e,n.mode);let f=HJ[l](e,i);if("vega-lite"===l&&f.$schema){const t=mJ()(f.$schema);Object(ut.satisfies)(qJ.vega,`^${t.version.slice(1)}`)||console.warn(`The compiled spec uses Vega ${t.version}, but current version is v${qJ.vega}.`)}const d=rt(t).classed("vega-embed",!0).html(""),h=n.patch;if(h)if(h instanceof Function)f=h(f);else if(zJ.isString(h)){const t=yield r.load(h);f=at()(f,JSON.parse(t))}else f=at()(f,h);const p=zJ.parse(f,"vega-lite"===l?{}:i),m=new zJ.View(p,{loader:r,logLevel:u,renderer:s});if(!1!==n.tooltip){let t;t=function(t){return"function"==typeof t}(n.tooltip)?n.tooltip:new jJ(!0===n.tooltip?{}:n.tooltip).call,m.tooltip(t)}let{hover:g}=n;if(void 0===g&&(g="vega"===l),g){const{hoverSet:t,updateSet:e}="boolean"==typeof g?{}:g;m.hover(t,e)}if(n&&(n.width&&m.width(n.width),n.height&&m.height(n.height),n.padding&&m.padding(n.padding)),yield m.initialize(t).runAsync(),!1!==a){let t=d;if(!1!==n.defaultStyle){const e=d.append("details").attr("title",o.CLICK_TO_VIEW_ACTIONS);t=e,e.insert("summary").html(GJ);const n=e.node();document.addEventListener("click",t=>{n.contains(t.target)||n.removeAttribute("open")})}const r=t.insert("div").attr("class","vega-actions");if(!0===a||!1!==a.export)for(const t of["svg","png"])if(!0===a||!0===a.export||a.export[t]){const e=o[`${t.toUpperCase()}_ACTION`];r.append("a").text(e).attr("href","#").attr("target","_blank").attr("download",`${c}.${t}`).on("mousedown",function(){m.toImageURL(t,n.scaleFactor).then(t=>{this.href=t}).catch(t=>{throw t}),w.preventDefault()})}if(!0!==a&&!1===a.source||r.append("a").text(o.SOURCE_ACTION).attr("href","#").on("mousedown",()=>{$J(st()(e),n.sourceHeader||"",n.sourceFooter||"",l),w.preventDefault()}),"vega-lite"!==l||!0!==a&&!1===a.compiled||r.append("a").text(o.COMPILED_ACTION).attr("href","#").on("mousedown",()=>{$J(st()(f),n.sourceHeader||"",n.sourceFooter||"","vega"),w.preventDefault()}),!0===a||!1!==a.editor){const t=n.editorUrl||"https://vega.github.io/editor/";r.append("a").text(o.EDITOR_ACTION).attr("href","#").on("mousedown",()=>{PJ(window,t,{config:i,mode:l,renderer:s,spec:st()(e)}),w.preventDefault()})}}return{view:m,spec:e,vgSpec:f}})}},function(t,e,n){"use strict";e.__esModule=!0;var r=function(t){return t&&t.__esModule?t:{default:t}}(n(47));e.default=function(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return(0,r.default)(t)}},function(t,e){t.exports={}},function(t,e,n){"use strict";var r=n(424)(!0);n(152)(String,"String",function(t){this._t=String(t),this._i=0},function(){var t,e=this._t,n=this._i;return n>=e.length?{value:void 0,done:!0}:(t=r(e,n),this._i+=t.length,{value:t,done:!1})})},function(t,e,n){"use strict";(function(t){
  113. /*!
  114. * The buffer module from node.js, for the browser.
  115. *
  116. * @author Feross Aboukhadijeh <http://feross.org>
  117. * @license MIT
  118. */
  119. var r=n(484),i=n(483),a=n(482);function o(){return u.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function s(t,e){if(o()<e)throw new RangeError("Invalid typed array length");return u.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=u.prototype:(null===t&&(t=new u(e)),t.length=e),t}function u(t,e,n){if(!(u.TYPED_ARRAY_SUPPORT||this instanceof u))return new u(t,e,n);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return f(this,t)}return c(this,t,e,n)}function c(t,e,n,r){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,n,r){if(e.byteLength,n<0||e.byteLength<n)throw new RangeError("'offset' is out of bounds");if(e.byteLength<n+(r||0))throw new RangeError("'length' is out of bounds");e=void 0===n&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,n):new Uint8Array(e,n,r);u.TYPED_ARRAY_SUPPORT?(t=e).__proto__=u.prototype:t=d(t,e);return t}(t,e,n,r):"string"==typeof e?function(t,e,n){"string"==typeof n&&""!==n||(n="utf8");if(!u.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var r=0|p(e,n),i=(t=s(t,r)).write(e,n);i!==r&&(t=t.slice(0,i));return t}(t,e,n):function(t,e){if(u.isBuffer(e)){var n=0|h(e.length);return 0===(t=s(t,n)).length?t:(e.copy(t,0,0,n),t)}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||function(t){return t!=t}(e.length)?s(t,0):d(t,e);if("Buffer"===e.type&&a(e.data))return d(t,e.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function l(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function f(t,e){if(l(e),t=s(t,e<0?0:0|h(e)),!u.TYPED_ARRAY_SUPPORT)for(var n=0;n<e;++n)t[n]=0;return t}function d(t,e){var n=e.length<0?0:0|h(e.length);t=s(t,n);for(var r=0;r<n;r+=1)t[r]=255&e[r];return t}function h(t){if(t>=o())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o().toString(16)+" bytes");return 0|t}function p(t,e){if(u.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var n=t.length;if(0===n)return 0;for(var r=!1;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return B(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return U(t).length;default:if(r)return B(t).length;e=(""+e).toLowerCase(),r=!0}}function m(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function g(t,e,n,r,i){if(0===t.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=i?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(i)return-1;n=t.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof e&&(e=u.from(e,r)),u.isBuffer(e))return 0===e.length?-1:v(t,e,n,r,i);if("number"==typeof e)return e&=255,u.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):v(t,[e],n,r,i);throw new TypeError("val must be string, number or Buffer")}function v(t,e,n,r,i){var a,o=1,s=t.length,u=e.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(t.length<2||e.length<2)return-1;o=2,s/=2,u/=2,n/=2}function c(t,e){return 1===o?t[e]:t.readUInt16BE(e*o)}if(i){var l=-1;for(a=n;a<s;a++)if(c(t,a)===c(e,-1===l?0:a-l)){if(-1===l&&(l=a),a-l+1===u)return l*o}else-1!==l&&(a-=a-l),l=-1}else for(n+u>s&&(n=s-u),a=n;a>=0;a--){for(var f=!0,d=0;d<u;d++)if(c(t,a+d)!==c(e,d)){f=!1;break}if(f)return a}return-1}function y(t,e,n,r){n=Number(n)||0;var i=t.length-n;r?(r=Number(r))>i&&(r=i):r=i;var a=e.length;if(a%2!=0)throw new TypeError("Invalid hex string");r>a/2&&(r=a/2);for(var o=0;o<r;++o){var s=parseInt(e.substr(2*o,2),16);if(isNaN(s))return o;t[n+o]=s}return o}function b(t,e,n,r){return W(B(e,t.length-n),t,n,r)}function x(t,e,n,r){return W(function(t){for(var e=[],n=0;n<t.length;++n)e.push(255&t.charCodeAt(n));return e}(e),t,n,r)}function w(t,e,n,r){return x(t,e,n,r)}function k(t,e,n,r){return W(U(e),t,n,r)}function _(t,e,n,r){return W(function(t,e){for(var n,r,i,a=[],o=0;o<t.length&&!((e-=2)<0);++o)n=t.charCodeAt(o),r=n>>8,i=n%256,a.push(i),a.push(r);return a}(e,t.length-n),t,n,r)}function E(t,e,n){return 0===e&&n===t.length?r.fromByteArray(t):r.fromByteArray(t.slice(e,n))}function O(t,e,n){n=Math.min(t.length,n);for(var r=[],i=e;i<n;){var a,o,s,u,c=t[i],l=null,f=c>239?4:c>223?3:c>191?2:1;if(i+f<=n)switch(f){case 1:c<128&&(l=c);break;case 2:128==(192&(a=t[i+1]))&&(u=(31&c)<<6|63&a)>127&&(l=u);break;case 3:a=t[i+1],o=t[i+2],128==(192&a)&&128==(192&o)&&(u=(15&c)<<12|(63&a)<<6|63&o)>2047&&(u<55296||u>57343)&&(l=u);break;case 4:a=t[i+1],o=t[i+2],s=t[i+3],128==(192&a)&&128==(192&o)&&128==(192&s)&&(u=(15&c)<<18|(63&a)<<12|(63&o)<<6|63&s)>65535&&u<1114112&&(l=u)}null===l?(l=65533,f=1):l>65535&&(l-=65536,r.push(l>>>10&1023|55296),l=56320|1023&l),r.push(l),i+=f}return function(t){var e=t.length;if(e<=S)return String.fromCharCode.apply(String,t);var n="",r=0;for(;r<e;)n+=String.fromCharCode.apply(String,t.slice(r,r+=S));return n}(r)}e.Buffer=u,e.SlowBuffer=function(t){+t!=t&&(t=0);return u.alloc(+t)},e.INSPECT_MAX_BYTES=50,u.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(t){return!1}}(),e.kMaxLength=o(),u.poolSize=8192,u._augment=function(t){return t.__proto__=u.prototype,t},u.from=function(t,e,n){return c(null,t,e,n)},u.TYPED_ARRAY_SUPPORT&&(u.prototype.__proto__=Uint8Array.prototype,u.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&u[Symbol.species]===u&&Object.defineProperty(u,Symbol.species,{value:null,configurable:!0})),u.alloc=function(t,e,n){return function(t,e,n,r){return l(e),e<=0?s(t,e):void 0!==n?"string"==typeof r?s(t,e).fill(n,r):s(t,e).fill(n):s(t,e)}(null,t,e,n)},u.allocUnsafe=function(t){return f(null,t)},u.allocUnsafeSlow=function(t){return f(null,t)},u.isBuffer=function(t){return!(null==t||!t._isBuffer)},u.compare=function(t,e){if(!u.isBuffer(t)||!u.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var n=t.length,r=e.length,i=0,a=Math.min(n,r);i<a;++i)if(t[i]!==e[i]){n=t[i],r=e[i];break}return n<r?-1:r<n?1:0},u.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},u.concat=function(t,e){if(!a(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return u.alloc(0);var n;if(void 0===e)for(e=0,n=0;n<t.length;++n)e+=t[n].length;var r=u.allocUnsafe(e),i=0;for(n=0;n<t.length;++n){var o=t[n];if(!u.isBuffer(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(r,i),i+=o.length}return r},u.byteLength=p,u.prototype._isBuffer=!0,u.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)m(this,e,e+1);return this},u.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)m(this,e,e+3),m(this,e+1,e+2);return this},u.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)m(this,e,e+7),m(this,e+1,e+6),m(this,e+2,e+5),m(this,e+3,e+4);return this},u.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?O(this,0,t):function(t,e,n){var r=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return N(this,e,n);case"utf8":case"utf-8":return O(this,e,n);case"ascii":return C(this,e,n);case"latin1":case"binary":return A(this,e,n);case"base64":return E(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,e,n);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=!0}}.apply(this,arguments)},u.prototype.equals=function(t){if(!u.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===u.compare(this,t)},u.prototype.inspect=function(){var t="",n=e.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,n).match(/.{2}/g).join(" "),this.length>n&&(t+=" ... ")),"<Buffer "+t+">"},u.prototype.compare=function(t,e,n,r,i){if(!u.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===r&&(r=0),void 0===i&&(i=this.length),e<0||n>t.length||r<0||i>this.length)throw new RangeError("out of range index");if(r>=i&&e>=n)return 0;if(r>=i)return-1;if(e>=n)return 1;if(e>>>=0,n>>>=0,r>>>=0,i>>>=0,this===t)return 0;for(var a=i-r,o=n-e,s=Math.min(a,o),c=this.slice(r,i),l=t.slice(e,n),f=0;f<s;++f)if(c[f]!==l[f]){a=c[f],o=l[f];break}return a<o?-1:o<a?1:0},u.prototype.includes=function(t,e,n){return-1!==this.indexOf(t,e,n)},u.prototype.indexOf=function(t,e,n){return g(this,t,e,n,!0)},u.prototype.lastIndexOf=function(t,e,n){return g(this,t,e,n,!1)},u.prototype.write=function(t,e,n,r){if(void 0===e)r="utf8",n=this.length,e=0;else if(void 0===n&&"string"==typeof e)r=e,n=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(n)?(n|=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}var i=this.length-e;if((void 0===n||n>i)&&(n=i),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var a=!1;;)switch(r){case"hex":return y(this,t,e,n);case"utf8":case"utf-8":return b(this,t,e,n);case"ascii":return x(this,t,e,n);case"latin1":case"binary":return w(this,t,e,n);case"base64":return k(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return _(this,t,e,n);default:if(a)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),a=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var S=4096;function C(t,e,n){var r="";n=Math.min(t.length,n);for(var i=e;i<n;++i)r+=String.fromCharCode(127&t[i]);return r}function A(t,e,n){var r="";n=Math.min(t.length,n);for(var i=e;i<n;++i)r+=String.fromCharCode(t[i]);return r}function N(t,e,n){var r=t.length;(!e||e<0)&&(e=0),(!n||n<0||n>r)&&(n=r);for(var i="",a=e;a<n;++a)i+=z(t[a]);return i}function T(t,e,n){for(var r=t.slice(e,n),i="",a=0;a<r.length;a+=2)i+=String.fromCharCode(r[a]+256*r[a+1]);return i}function I(t,e,n){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>n)throw new RangeError("Trying to access beyond buffer length")}function D(t,e,n,r,i,a){if(!u.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<a)throw new RangeError('"value" argument is out of bounds');if(n+r>t.length)throw new RangeError("Index out of range")}function M(t,e,n,r){e<0&&(e=65535+e+1);for(var i=0,a=Math.min(t.length-n,2);i<a;++i)t[n+i]=(e&255<<8*(r?i:1-i))>>>8*(r?i:1-i)}function R(t,e,n,r){e<0&&(e=4294967295+e+1);for(var i=0,a=Math.min(t.length-n,4);i<a;++i)t[n+i]=e>>>8*(r?i:3-i)&255}function F(t,e,n,r,i,a){if(n+r>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function j(t,e,n,r,a){return a||F(t,0,n,4),i.write(t,e,n,r,23,4),n+4}function P(t,e,n,r,a){return a||F(t,0,n,8),i.write(t,e,n,r,52,8),n+8}u.prototype.slice=function(t,e){var n,r=this.length;if(t=~~t,e=void 0===e?r:~~e,t<0?(t+=r)<0&&(t=0):t>r&&(t=r),e<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t),u.TYPED_ARRAY_SUPPORT)(n=this.subarray(t,e)).__proto__=u.prototype;else{var i=e-t;n=new u(i,void 0);for(var a=0;a<i;++a)n[a]=this[a+t]}return n},u.prototype.readUIntLE=function(t,e,n){t|=0,e|=0,n||I(t,e,this.length);for(var r=this[t],i=1,a=0;++a<e&&(i*=256);)r+=this[t+a]*i;return r},u.prototype.readUIntBE=function(t,e,n){t|=0,e|=0,n||I(t,e,this.length);for(var r=this[t+--e],i=1;e>0&&(i*=256);)r+=this[t+--e]*i;return r},u.prototype.readUInt8=function(t,e){return e||I(t,1,this.length),this[t]},u.prototype.readUInt16LE=function(t,e){return e||I(t,2,this.length),this[t]|this[t+1]<<8},u.prototype.readUInt16BE=function(t,e){return e||I(t,2,this.length),this[t]<<8|this[t+1]},u.prototype.readUInt32LE=function(t,e){return e||I(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},u.prototype.readUInt32BE=function(t,e){return e||I(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},u.prototype.readIntLE=function(t,e,n){t|=0,e|=0,n||I(t,e,this.length);for(var r=this[t],i=1,a=0;++a<e&&(i*=256);)r+=this[t+a]*i;return r>=(i*=128)&&(r-=Math.pow(2,8*e)),r},u.prototype.readIntBE=function(t,e,n){t|=0,e|=0,n||I(t,e,this.length);for(var r=e,i=1,a=this[t+--r];r>0&&(i*=256);)a+=this[t+--r]*i;return a>=(i*=128)&&(a-=Math.pow(2,8*e)),a},u.prototype.readInt8=function(t,e){return e||I(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},u.prototype.readInt16LE=function(t,e){e||I(t,2,this.length);var n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},u.prototype.readInt16BE=function(t,e){e||I(t,2,this.length);var n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},u.prototype.readInt32LE=function(t,e){return e||I(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},u.prototype.readInt32BE=function(t,e){return e||I(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},u.prototype.readFloatLE=function(t,e){return e||I(t,4,this.length),i.read(this,t,!0,23,4)},u.prototype.readFloatBE=function(t,e){return e||I(t,4,this.length),i.read(this,t,!1,23,4)},u.prototype.readDoubleLE=function(t,e){return e||I(t,8,this.length),i.read(this,t,!0,52,8)},u.prototype.readDoubleBE=function(t,e){return e||I(t,8,this.length),i.read(this,t,!1,52,8)},u.prototype.writeUIntLE=function(t,e,n,r){(t=+t,e|=0,n|=0,r)||D(this,t,e,n,Math.pow(2,8*n)-1,0);var i=1,a=0;for(this[e]=255&t;++a<n&&(i*=256);)this[e+a]=t/i&255;return e+n},u.prototype.writeUIntBE=function(t,e,n,r){(t=+t,e|=0,n|=0,r)||D(this,t,e,n,Math.pow(2,8*n)-1,0);var i=n-1,a=1;for(this[e+i]=255&t;--i>=0&&(a*=256);)this[e+i]=t/a&255;return e+n},u.prototype.writeUInt8=function(t,e,n){return t=+t,e|=0,n||D(this,t,e,1,255,0),u.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},u.prototype.writeUInt16LE=function(t,e,n){return t=+t,e|=0,n||D(this,t,e,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):M(this,t,e,!0),e+2},u.prototype.writeUInt16BE=function(t,e,n){return t=+t,e|=0,n||D(this,t,e,2,65535,0),u.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):M(this,t,e,!1),e+2},u.prototype.writeUInt32LE=function(t,e,n){return t=+t,e|=0,n||D(this,t,e,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):R(this,t,e,!0),e+4},u.prototype.writeUInt32BE=function(t,e,n){return t=+t,e|=0,n||D(this,t,e,4,4294967295,0),u.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):R(this,t,e,!1),e+4},u.prototype.writeIntLE=function(t,e,n,r){if(t=+t,e|=0,!r){var i=Math.pow(2,8*n-1);D(this,t,e,n,i-1,-i)}var a=0,o=1,s=0;for(this[e]=255&t;++a<n&&(o*=256);)t<0&&0===s&&0!==this[e+a-1]&&(s=1),this[e+a]=(t/o>>0)-s&255;return e+n},u.prototype.writeIntBE=function(t,e,n,r){if(t=+t,e|=0,!r){var i=Math.pow(2,8*n-1);D(this,t,e,n,i-1,-i)}var a=n-1,o=1,s=0;for(this[e+a]=255&t;--a>=0&&(o*=256);)t<0&&0===s&&0!==this[e+a+1]&&(s=1),this[e+a]=(t/o>>0)-s&255;return e+n},u.prototype.writeInt8=function(t,e,n){return t=+t,e|=0,n||D(this,t,e,1,127,-128),u.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},u.prototype.writeInt16LE=function(t,e,n){return t=+t,e|=0,n||D(this,t,e,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):M(this,t,e,!0),e+2},u.prototype.writeInt16BE=function(t,e,n){return t=+t,e|=0,n||D(this,t,e,2,32767,-32768),u.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):M(this,t,e,!1),e+2},u.prototype.writeInt32LE=function(t,e,n){return t=+t,e|=0,n||D(this,t,e,4,2147483647,-2147483648),u.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):R(this,t,e,!0),e+4},u.prototype.writeInt32BE=function(t,e,n){return t=+t,e|=0,n||D(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),u.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):R(this,t,e,!1),e+4},u.prototype.writeFloatLE=function(t,e,n){return j(this,t,e,!0,n)},u.prototype.writeFloatBE=function(t,e,n){return j(this,t,e,!1,n)},u.prototype.writeDoubleLE=function(t,e,n){return P(this,t,e,!0,n)},u.prototype.writeDoubleBE=function(t,e,n){return P(this,t,e,!1,n)},u.prototype.copy=function(t,e,n,r){if(n||(n=0),r||0===r||(r=this.length),e>=t.length&&(e=t.length),e||(e=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-e<r-n&&(r=t.length-e+n);var i,a=r-n;if(this===t&&n<e&&e<r)for(i=a-1;i>=0;--i)t[i+e]=this[i+n];else if(a<1e3||!u.TYPED_ARRAY_SUPPORT)for(i=0;i<a;++i)t[i+e]=this[i+n];else Uint8Array.prototype.set.call(t,this.subarray(n,n+a),e);return a},u.prototype.fill=function(t,e,n,r){if("string"==typeof t){if("string"==typeof e?(r=e,e=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),1===t.length){var i=t.charCodeAt(0);i<256&&(t=i)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!u.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<n)throw new RangeError("Out of range index");if(n<=e)return this;var a;if(e>>>=0,n=void 0===n?this.length:n>>>0,t||(t=0),"number"==typeof t)for(a=e;a<n;++a)this[a]=t;else{var o=u.isBuffer(t)?t:B(new u(t,r).toString()),s=o.length;for(a=0;a<n-e;++a)this[a+e]=o[a%s]}return this};var L=/[^+\/0-9A-Za-z-_]/g;function z(t){return t<16?"0"+t.toString(16):t.toString(16)}function B(t,e){var n;e=e||1/0;for(var r=t.length,i=null,a=[],o=0;o<r;++o){if((n=t.charCodeAt(o))>55295&&n<57344){if(!i){if(n>56319){(e-=3)>-1&&a.push(239,191,189);continue}if(o+1===r){(e-=3)>-1&&a.push(239,191,189);continue}i=n;continue}if(n<56320){(e-=3)>-1&&a.push(239,191,189),i=n;continue}n=65536+(i-55296<<10|n-56320)}else i&&(e-=3)>-1&&a.push(239,191,189);if(i=null,n<128){if((e-=1)<0)break;a.push(n)}else if(n<2048){if((e-=2)<0)break;a.push(n>>6|192,63&n|128)}else if(n<65536){if((e-=3)<0)break;a.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;a.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return a}function U(t){return r.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(L,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function W(t,e,n,r){for(var i=0;i<r&&!(i+n>=e.length||i>=t.length);++i)e[i+n]=t[i];return i}}).call(this,n(53))},function(t,e){var n,r,i=t.exports={};function a(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function s(t){if(n===setTimeout)return setTimeout(t,0);if((n===a||!n)&&setTimeout)return n=setTimeout,setTimeout(t,0);try{return n(t,0)}catch(e){try{return n.call(null,t,0)}catch(e){return n.call(this,t,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:a}catch(t){n=a}try{r="function"==typeof clearTimeout?clearTimeout:o}catch(t){r=o}}();var u,c=[],l=!1,f=-1;function d(){l&&u&&(l=!1,u.length?c=u.concat(c):f=-1,c.length&&h())}function h(){if(!l){var t=s(d);l=!0;for(var e=c.length;e;){for(u=c,c=[];++f<e;)u&&u[f].run();f=-1,e=c.length}u=null,l=!1,function(t){if(r===clearTimeout)return clearTimeout(t);if((r===o||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(t);try{r(t)}catch(e){try{return r.call(null,t)}catch(e){return r.call(this,t)}}}(t)}}function p(t,e){this.fun=t,this.array=e}function m(){}i.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)e[n-1]=arguments[n];c.push(new p(t,e)),1!==c.length||l||s(h)},p.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=m,i.addListener=m,i.once=m,i.off=m,i.removeListener=m,i.removeAllListeners=m,i.emit=m,i.prependListener=m,i.prependOnceListener=m,i.listeners=function(t){return[]},i.binding=function(t){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(t){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},function(t,e,n){var r=n(245),i=n(158);t.exports=Object.keys||function(t){return r(t,i)}},function(t,e,n){t.exports={default:n(489),__esModule:!0}},function(t,e,n){"use strict";e.__esModule=!0;var r=function(t){return t&&t.__esModule?t:{default:t}}(n(89));e.default=r.default||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}},function(t,e){t.exports={}},function(t,e,n){var r=n(5),i=n(51),a=n(12),o=n(186),s="["+o+"]",u=RegExp("^"+s+s+"*"),c=RegExp(s+s+"*$"),l=function(t,e,n){var i={},s=a(function(){return!!o[t]()||"​…"!="​…"[t]()}),u=i[t]=s?e(f):o[t];n&&(i[n]=u),r(r.P+r.F*s,"String",i)},f=l.trim=function(t,e){return t=String(i(t)),1&e&&(t=t.replace(u,"")),2&e&&(t=t.replace(c,"")),t};t.exports=l},function(t,e,n){var r=n(42),i=n(16)("toStringTag"),a="Arguments"==r(function(){return arguments}());t.exports=function(t){var e,n,o;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(n=function(t,e){try{return t[e]}catch(t){}}(e=Object(t),i))?n:a?r(e):"Object"==(o=r(e))&&"function"==typeof e.callee?"Arguments":o}},function(t,e,n){var r=n(21).f,i=n(36),a=n(16)("toStringTag");t.exports=function(t,e,n){t&&!i(t=n?t:t.prototype,a)&&r(t,a,{configurable:!0,value:e})}},function(t,e,n){"use strict";var r=function(t){return function(t){return!!t&&"object"==typeof t}(t)&&!function(t){var e=Object.prototype.toString.call(t);return"[object RegExp]"===e||"[object Date]"===e||function(t){return t.$$typeof===i}(t)}(t)};var i="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;function a(t,e){return!1!==e.clone&&e.isMergeableObject(t)?l(function(t){return Array.isArray(t)?[]:{}}(t),t,e):t}function o(t,e,n){return t.concat(e).map(function(t){return a(t,n)})}function s(t){return Object.keys(t).concat(function(t){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(t).filter(function(e){return t.propertyIsEnumerable(e)}):[]}(t))}function u(t,e){try{return e in t}catch(t){return!1}}function c(t,e,n){var r={};return n.isMergeableObject(t)&&s(t).forEach(function(e){r[e]=a(t[e],n)}),s(e).forEach(function(i){(function(t,e){return u(t,e)&&!(Object.hasOwnProperty.call(t,e)&&Object.propertyIsEnumerable.call(t,e))})(t,i)||(u(t,i)&&n.isMergeableObject(e[i])?r[i]=function(t,e){if(!e.customMerge)return l;var n=e.customMerge(t);return"function"==typeof n?n:l}(i,n)(t[i],e[i],n):r[i]=a(e[i],n))}),r}function l(t,e,n){(n=n||{}).arrayMerge=n.arrayMerge||o,n.isMergeableObject=n.isMergeableObject||r,n.cloneUnlessOtherwiseSpecified=a;var i=Array.isArray(e);return i===Array.isArray(t)?i?n.arrayMerge(t,e,n):c(t,e,n):a(e,n)}l.all=function(t,e){if(!Array.isArray(t))throw new Error("first argument should be an array");return t.reduce(function(t,n){return l(t,n,e)},{})};var f=l;t.exports=f},function(t,e,n){"use strict";e.__esModule=!0;var r=o(n(356)),i=o(n(352)),a=o(n(14));function o(t){return t&&t.__esModule?t:{default:t}}e.default=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+(void 0===e?"undefined":(0,a.default)(e)));t.prototype=(0,i.default)(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(r.default?(0,r.default)(t,e):t.__proto__=e)}},function(t,e,n){"use strict";e.__esModule=!0;var r=function(t){return t&&t.__esModule?t:{default:t}}(n(14));e.default=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!==(void 0===e?"undefined":(0,r.default)(e))&&"function"!=typeof e?t:e}},function(t,e,n){t.exports={default:n(358),__esModule:!0}},function(t,e,n){t.exports={default:n(367),__esModule:!0}},function(t,e,n){var r=n(56),i=n(230),a=n(229),o=n(48),s=n(122),u=n(150),c={},l={};(e=t.exports=function(t,e,n,f,d){var h,p,m,g,v=d?function(){return t}:u(t),y=r(n,f,e?2:1),b=0;if("function"!=typeof v)throw TypeError(t+" is not iterable!");if(a(v)){for(h=s(t.length);h>b;b++)if((g=e?y(o(p=t[b])[0],p[1]):y(t[b]))===c||g===l)return g}else for(m=v.call(t);!(p=m.next()).done;)if((g=i(m,y,p.value,e))===c||g===l)return g}).BREAK=c,e.RETURN=l},function(t,e,n){n(421);for(var r=n(26),i=n(60),a=n(84),o=n(25)("toStringTag"),s="CSSRuleList,CSSStyleDeclaration,CSSValueList,ClientRectList,DOMRectList,DOMStringList,DOMTokenList,DataTransferItemList,FileList,HTMLAllCollection,HTMLCollection,HTMLFormElement,HTMLSelectElement,MediaList,MimeTypeArray,NamedNodeMap,NodeList,PaintRequestList,Plugin,PluginArray,SVGLengthList,SVGNumberList,SVGPathSegList,SVGPointList,SVGStringList,SVGTransformList,SourceBufferList,StyleSheetList,TextTrackCueList,TextTrackList,TouchList".split(","),u=0;u<s.length;u++){var c=s[u],l=r[c],f=l&&l.prototype;f&&!f[o]&&i(f,o,c),a[c]=a.Array}},function(t,e,n){var r=n(39).f,i=n(68),a=n(25)("toStringTag");t.exports=function(t,e,n){t&&!i(t=n?t:t.prototype,a)&&r(t,a,{configurable:!0,value:e})}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){return"string"==typeof t&&r.test(t)};var r=/-webkit-|-moz-|-ms-/;t.exports=e.default},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.compose=e.merge=e.$=e.style=e.presets=e.keyframes=e.fontFace=e.insertGlobal=e.insertRule=e.plugins=e.styleSheet=void 0,e.speedy=function(t){return f.speedy(t)},e.simulations=function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];g=!!t},e.simulate=function(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];if(!(e=(0,o.default)(e)))return{};if(!g)return v||(console.warn("can't simulate without once calling simulations(true)"),v=!0),h||p||y||(console.warn("don't use simulation outside dev"),y=!0),{};return e.reduce(function(t,e){return t["data-simulate-"+x(e)]="",t},{})},e.cssLabels=function(t){b=!!t},e.isLikeRule=k,e.idFor=_,e.css=V,e.rehydrate=function(t){(0,r.default)(T,t.reduce(function(t,e){return t[e]=!0,t},{}))},e.flush=function(){T=f.inserted={},I=f.registered={},M={},f.flush(),f.inject()},e.select=H,e.parent=function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];return V(l({},t+" &",n))},e.media=function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];return V(l({},"@media "+t,n))},e.pseudo=G,e.active=function(t){return G(":active",t)},e.any=function(t){return G(":any",t)},e.checked=function(t){return G(":checked",t)},e.disabled=function(t){return G(":disabled",t)},e.empty=function(t){return G(":empty",t)},e.enabled=function(t){return G(":enabled",t)},e._default=function(t){return G(":default",t)},e.first=function(t){return G(":first",t)},e.firstChild=function(t){return G(":first-child",t)},e.firstOfType=function(t){return G(":first-of-type",t)},e.fullscreen=function(t){return G(":fullscreen",t)},e.focus=function(t){return G(":focus",t)},e.hover=function(t){return G(":hover",t)},e.indeterminate=function(t){return G(":indeterminate",t)},e.inRange=function(t){return G(":in-range",t)},e.invalid=function(t){return G(":invalid",t)},e.lastChild=function(t){return G(":last-child",t)},e.lastOfType=function(t){return G(":last-of-type",t)},e.left=function(t){return G(":left",t)},e.link=function(t){return G(":link",t)},e.onlyChild=function(t){return G(":only-child",t)},e.onlyOfType=function(t){return G(":only-of-type",t)},e.optional=function(t){return G(":optional",t)},e.outOfRange=function(t){return G(":out-of-range",t)},e.readOnly=function(t){return G(":read-only",t)},e.readWrite=function(t){return G(":read-write",t)},e.required=function(t){return G(":required",t)},e.right=function(t){return G(":right",t)},e.root=function(t){return G(":root",t)},e.scope=function(t){return G(":scope",t)},e.target=function(t){return G(":target",t)},e.valid=function(t){return G(":valid",t)},e.visited=function(t){return G(":visited",t)},e.dir=function(t,e){return G(":dir("+t+")",e)},e.lang=function(t,e){return G(":lang("+t+")",e)},e.not=function(t,e){var n=t.split(",").map(function(t){return t.trim()}).map(function(t){return":not("+t+")"});if(1===n.length)return G(":not("+t+")",e);return H(n.join(""),e)},e.nthChild=function(t,e){return G(":nth-child("+t+")",e)},e.nthLastChild=function(t,e){return G(":nth-last-child("+t+")",e)},e.nthLastOfType=function(t,e){return G(":nth-last-of-type("+t+")",e)},e.nthOfType=function(t,e){return G(":nth-of-type("+t+")",e)},e.after=function(t){return G("::after",t)},e.before=function(t){return G("::before",t)},e.firstLetter=function(t){return G("::first-letter",t)},e.firstLine=function(t){return G("::first-line",t)},e.selection=function(t){return G("::selection",t)},e.backdrop=function(t){return G("::backdrop",t)},e.placeholder=function(t){return V({"::placeholder":t})},e.cssFor=function(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];return(e=(0,o.default)(e))?e.map(function(t){var e={label:[]};return P(e,{src:t}),N(w(e),A(e)).join("")}).join(""):""},e.attribsFor=function(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];return(e=(0,o.default)(e))?e.map(function(t){_(t);var e=Object.keys(t)[0],n=t[e];return e+'="'+(n||"")+'"'}).join(" "):""};var r=c(n(156)),i=n(467),a=n(240),o=c(n(458)),s=n(457),u=c(n(440));function c(t){return t&&t.__esModule?t:{default:t}}function l(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var f=e.styleSheet=new i.StyleSheet;f.inject();var d=e.plugins=f.plugins=new s.PluginSet([s.prefixes,s.contentWrap,s.fallbacks]);d.media=new s.PluginSet,d.fontFace=new s.PluginSet,d.keyframes=new s.PluginSet([s.prefixes,s.fallbacks]);var h=!1,p=!1,m="undefined"!=typeof window,g=h,v=!1,y=!1;var b=h;function x(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return t.toLowerCase().replace(/[^a-z0-9]/g,e)}function w(t){var e=JSON.stringify(t),n=(0,u.default)(e).toString(36);return t.label&&t.label.length>0&&h?x(t.label.join("."),"-")+"-"+n:n}function k(t){var e=Object.keys(t).filter(function(t){return"toString"!==t});return 1===e.length&&!!/data\-css\-([a-zA-Z0-9\-_]+)/.exec(e[0])}function _(t){var e=Object.keys(t).filter(function(t){return"toString"!==t});if(1!==e.length)throw new Error("not a rule");var n=/data\-css\-([a-zA-Z0-9\-_]+)/.exec(e[0]);if(!n)throw new Error("not a rule");return n[1]}var E=/[(),]|"(?:\\.|[^"\n])*"|'(?:\\.|[^'\n])*'|\/\*[\s\S]*?\*\//g;function O(t){if(-1===t.indexOf(","))return[t];for(var e,n=[],r=[],i=0;e=E.exec(t);)switch(e[0]){case"(":i++;break;case")":i--;break;case",":if(i)break;n.push(e.index)}for(e=n.length;e--;)r.unshift(t.slice(n[e]+1)),t=t.slice(0,n[e]);return r.unshift(t),r}function S(t,e){if(!t)return e.replace(/\&/g,"");if(!e)return".css-"+t+",[data-css-"+t+"]";var n=O(e).map(function(e){return e.indexOf("&")>=0?[e.replace(/\&/gm,".css-"+t),e.replace(/\&/gm,"[data-css-"+t+"]")].join(","):".css-"+t+e+",[data-css-"+t+"]"+e}).join(",");return g&&/^\&\:/.exec(e)&&!/\s/.exec(e)&&(n+=",.css-"+t+"[data-simulate-"+x(e)+"],[data-css-"+t+"][data-simulate-"+x(e)+"]"),n}function C(t){var e=t.selector,n=t.style,r=d.transform({selector:e,style:n});return r.selector+"{"+(0,a.createMarkupForStyles)(r.style)+"}"}function A(t){var e=void 0,n=void 0,r=void 0,i=void 0;return Object.keys(t).forEach(function(a){a.indexOf("&")>=0?(n=n||{})[a]=t[a]:0===a.indexOf("@media")?(r=r||{})[a]=A(t[a]):0===a.indexOf("@supports")?(i=i||{})[a]=A(t[a]):"label"===a?t.label.length>0&&((e=e||{}).label=b?t.label.join("."):""):(e=e||{})[a]=t[a]}),{plain:e,selects:n,medias:r,supports:i}}function N(t,e){var n=[],r=e.plain,i=e.selects,a=e.medias,o=e.supports;return r&&n.push(C({style:r,selector:S(t)})),i&&Object.keys(i).forEach(function(e){return n.push(C({style:i[e],selector:S(t,e)}))}),a&&Object.keys(a).forEach(function(e){return n.push(e+"{"+N(t,a[e]).join("")+"}")}),o&&Object.keys(o).forEach(function(e){return n.push(e+"{"+N(t,o[e]).join("")+"}")}),n}var T=f.inserted={};var I=f.registered={};function D(t){I[t.id]||(I[t.id]=t)}var M={};function R(t){if(D(t),function(t){if(!T[t.id]){T[t.id]=!0;var e=A(t.style),n=N(t.id,e);T[t.id]=!!m||n,n.forEach(function(t){return f.insert(t)})}}(t),M[t.id])return M[t.id];var e=l({},"data-css-"+t.id,b&&t.label||"");return Object.defineProperty(e,"toString",{enumerable:!1,value:function(){return"css-"+t.id}}),M[t.id]=e,e}function F(t,e){var n=O(t).map(function(t){return t.indexOf("&")>=0?t:"&"+t});return O(e).map(function(t){return t.indexOf("&")>=0?t:"&"+t}).reduce(function(t,e){return t.concat(n.map(function(t){return e.replace(/\&/g,t)}))},[]).join(",")}var j={"::placeholder":["::-webkit-input-placeholder","::-moz-placeholder","::-ms-input-placeholder"],":fullscreen":[":-webkit-full-screen",":-moz-full-screen",":-ms-fullscreen"]};function P(t,e){var n=e.selector,r=void 0===n?"":n,i=e.mq,a=void 0===i?"":i,s=e.supp,u=void 0===s?"":s,c=e.src,l=void 0===c?{}:c;Array.isArray(l)||(l=[l]),(l=function t(e){for(var n=[],r=0;r<e.length;r++)n=Array.isArray(e[r])?n.concat(t(e[r])):n.concat(e[r]);return n}(l)).forEach(function(e){if(k(e)){var n=function(t){if(k(t)){var e=I[_(t)];if(null==e)throw new Error("[glamor] an unexpected rule cache miss occurred. This is probably a sign of multiple glamor instances in your app. See https://github.com/threepointone/glamor/issues/79");return e}return t}(e);if("css"!==n.type)throw new Error("cannot merge this rule");e=n.style}(e=(0,o.default)(e))&&e.composes&&P(t,{selector:r,mq:a,supp:u,src:e.composes}),Object.keys(e||{}).forEach(function(n){if(function(t){for(var e=[":",".","[",">"," "],n=!1,r=t.charAt(0),i=0;i<e.length;i++)if(r===e[i]){n=!0;break}return n||t.indexOf("&")>=0}(n))j[n]&&j[n].forEach(function(i){return P(t,{selector:F(r,i),mq:a,supp:u,src:e[n]})}),P(t,{selector:F(r,n),mq:a,supp:u,src:e[n]});else if(function(t){return 0===t.indexOf("@media")}(n))P(t,{selector:r,mq:function(t,e){return t?"@media "+t.substring(6)+" and "+e.substring(6):e}(a,n),supp:u,src:e[n]});else if(function(t){return 0===t.indexOf("@supports")}(n))P(t,{selector:r,mq:a,supp:function(t,e){return t?"@supports "+t.substring(9)+" and "+e.substring(9):e}(u,n),src:e[n]});else if("composes"===n);else{var i=t;u&&(i[u]=i[u]||{},i=i[u]),a&&(i[a]=i[a]||{},i=i[a]),r&&(i[r]=i[r]||{},i=i[r]),"label"===n?b&&(t.label=t.label.concat(e.label)):i[n]=e[n]}})})}function L(t){var e={label:[]};return P(e,{src:t}),R({id:w(e),style:e,label:b?e.label.join("."):"",type:"css"})}var z={};Object.defineProperty(z,"toString",{enumerable:!1,value:function(){return"css-nil"}});var B="undefined"!=typeof WeakMap?[z,new WeakMap,new WeakMap,new WeakMap]:[z],U=!1;var W="undefined"!=typeof WeakMap?function(t){return function(e){if(B[e.length]){for(var n=B[e.length],r=0;r<e.length-1;)n.has(e[r])||n.set(e[r],new WeakMap),n=n.get(e[r]),r++;if(n.has(e[e.length-1])){var i=n.get(e[r]);if(I[i.toString().substring(4)])return i}}var a=t(e);if(B[e.length]){for(var o=0,s=B[e.length];o<e.length-1;)s=s.get(e[o]),o++;try{s.set(e[o],a)}catch(t){var u;h&&!U&&(U=!0,(u=console).warn.apply(u,["failed setting the WeakMap cache for args:"].concat(function(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}(e))),console.warn("this should NOT happen, please file a bug on the github repo."))}}return a}}(L):L;function V(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];if(e[0]&&e[0].length&&e[0].raw)throw new Error("you forgot to include glamor/babel in your babel plugins.");return(e=(0,o.default)(e))?W(e):z}V.insert=function(t){var e={id:w(t),css:t,type:"raw"};D(e),T[e.id]||(f.insert(e.css),T[e.id]=!!m||[e.css])};e.insertRule=V.insert;V.global=function(t,e){if(e=(0,o.default)(e))return V.insert(C({selector:t,style:e}))};e.insertGlobal=V.global;V.keyframes=function(t,e){e||(e=t,t="animation");var n={id:w({name:t,kfs:e=(0,o.default)(e)||{}}),type:"keyframes",name:t,keyframes:e};return D(n),function(t){if(!T[t.id]){var e=Object.keys(t.keyframes).map(function(e){var n=d.keyframes.transform({id:t.id,name:e,style:t.keyframes[e]});return n.name+"{"+(0,a.createMarkupForStyles)(n.style)+"}"}).join(""),n=["-webkit-","-moz-","-o-",""].map(function(n){return"@"+n+"keyframes "+t.name+"_"+t.id+"{"+e+"}"});n.forEach(function(t){return f.insert(t)}),T[t.id]=!!m||n}}(n),t+"_"+n.id},V.fontFace=function(t){var e={id:w(t=(0,o.default)(t)),type:"font-face",font:t};return D(e),function(t){if(!T[t.id]){var e="@font-face{"+(0,a.createMarkupForStyles)(t.font)+"}";f.insert(e),T[t.id]=!!m||[e]}}(e),t.fontFamily};e.fontFace=V.fontFace,e.keyframes=V.keyframes;e.presets={mobile:"(min-width: 400px)",Mobile:"@media (min-width: 400px)",phablet:"(min-width: 550px)",Phablet:"@media (min-width: 550px)",tablet:"(min-width: 750px)",Tablet:"@media (min-width: 750px)",desktop:"(min-width: 1000px)",Desktop:"@media (min-width: 1000px)",hd:"(min-width: 1200px)",Hd:"@media (min-width: 1200px)"};var q=e.style=V;function H(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];return t?V(l({},t,n)):q(n)}e.$=H;e.merge=V,e.compose=V;function G(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];return V(l({},t,n))}},function(t,e){e.f={}.propertyIsEnumerable},function(t,e){t.exports=!0},function(t,e){var n={}.toString;t.exports=function(t){return n.call(t).slice(8,-1)}},function(t,e){t.exports=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}}},function(t,e){t.exports=function(t){if("function"!=typeof t)throw TypeError(t+" is not a function!");return t}},function(t,e,n){var r=n(6),i=n(27),a=n(16)("species");t.exports=function(t,e){var n,o=r(t).constructor;return void 0===o||void 0==(n=r(o)[a])?e:i(n)}},function(t,e,n){"use strict";var r=n(6);t.exports=function(){var t=r(this),e="";return t.global&&(e+="g"),t.ignoreCase&&(e+="i"),t.multiline&&(e+="m"),t.unicode&&(e+="u"),t.sticky&&(e+="y"),e}},function(t,e){e.f={}.propertyIsEnumerable},function(t,e,n){var r=n(42);t.exports=Object("z").propertyIsEnumerable(0)?Object:function(t){return"String"==r(t)?t.split(""):Object(t)}},function(t,e,n){var r=n(44),i=n(11),a=i["__core-js_shared__"]||(i["__core-js_shared__"]={});(t.exports=function(t,e){return a[t]||(a[t]=void 0!==e?e:{})})("versions",[]).push({version:r.version,mode:n(63)?"pure":"global",copyright:"© 2019 Denis Pushkarev (zloirock.ru)"})},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.loadFile=e.saveBlob=void 0;var r=o(n(9)),i=o(n(8)),a=o(n(55));function o(t){return t&&t.__esModule?t:{default:t}}var s=function(){var t=(0,i.default)(r.default.mark(function t(e,n,i){var a,o;return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:(a=document.createElement("a")).style.display="none",document.body.appendChild(a),o=new Blob([e],{type:i}),a.href=URL.createObjectURL(o),a.download=n,a.click();case 7:case"end":return t.stop()}},t,void 0)}));return function(e,n,r){return t.apply(this,arguments)}}(),u=function(){var t=(0,i.default)(r.default.mark(function t(e,n){return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",a.default.get(e).then(function(t){return t.data}).then(function(t){return n&&n(null,t),t}).catch(function(t){throw n&&n(t),console.error("There has been a problem loading the file: "+t.message),t}));case 1:case"end":return t.stop()}},t,void 0)}));return function(e,n){return t.apply(this,arguments)}}();e.saveBlob=s,e.loadFile=u},function(t,e,n){var r=n(107),i=n(25)("toStringTag"),a="Arguments"==r(function(){return arguments}());t.exports=function(t){var e,n,o;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(n=function(t,e){try{return t[e]}catch(t){}}(e=Object(t),i))?n:a?r(e):"Object"==(o=r(e))&&"function"==typeof e.callee?"Arguments":o}},function(t,e,n){var r=n(48),i=n(422),a=n(158),o=n(160)("IE_PROTO"),s=function(){},u=function(){var t,e=n(165)("iframe"),r=a.length;for(e.style.display="none",n(233).appendChild(e),e.src="javascript:",(t=e.contentWindow.document).open(),t.write("<script>document.F=Object<\/script>"),t.close(),u=t.F;r--;)delete u.prototype[a[r]];return u()};t.exports=Object.create||function(t,e){var n;return null!==t?(s.prototype=r(t),n=new s,s.prototype=null,n[o]=t):n=u(),void 0===e?n:i(n,e)}},function(t,e,n){"use strict";
  120. /**
  121. * @license
  122. * Copyright 2018 Google LLC. All Rights Reserved.
  123. * Licensed under the Apache License, Version 2.0 (the "License");
  124. * you may not use this file except in compliance with the License.
  125. * You may obtain a copy of the License at
  126. *
  127. * http://www.apache.org/licenses/LICENSE-2.0
  128. *
  129. * Unless required by applicable law or agreed to in writing, software
  130. * distributed under the License is distributed on an "AS IS" BASIS,
  131. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  132. * See the License for the specific language governing permissions and
  133. * limitations under the License.
  134. * =============================================================================
  135. */Object.defineProperty(e,"__esModule",{value:!0});const r=n(45),i=n(289),a=n(104),o=n(37);e.table=function(t,e,n={}){if(e&&null==e.headers)throw new Error('Data to render must have a "headers" property');if(e&&null==e.values)throw new Error('Data to render must have a "values" property');const u=o.getDrawArea(t),c=Object.assign({},s,n);let l=i.select(u).select("table.tf-table");const f=a.css({fontSize:c.fontSize||".875rem",width:"100%",maxWidth:"64rem",marginRight:"auto",marginLeft:"auto"});if(0===l.size()&&((l=i.select(u).append("table")).attr("class",` ${f} tf-table`),l.append("thead").append("tr"),l.append("tbody")),1!==l.size())throw new Error("Error inserting table");const d=a.css({fontWeight:"600",borderBottomStyle:"solid",borderBottomWidth:"1px",borderColor:"rgba( 0, 0, 0, .2 )",textAlign:"left",paddingBottom:"1rem",paddingRight:"1rem",backgroundColor:"#fff"}),h=l.select("thead").select("tr").selectAll("th").data(e.headers),p=h.enter().append("th").attr("class",`${d}`);h.merge(p).html(t=>t),h.exit().remove();const m=r.format(",.4~f"),g=l.select("tbody").selectAll("tr").data(e.values),v=g.enter().append("tr"),y=a.css({padding:"0.25rem",borderBottomStyle:"solid",borderBottomWidth:"1px",borderColor:"rgba( 0, 0, 0, .2 )"}),b=g.merge(v).selectAll("td").data(t=>t),x=b.enter().append("td").attr("class",`${y}`);b.merge(x).html(t=>"number"==typeof t?m(t):t),b.exit().remove(),g.exit().remove()};const s={fontSize:14}},function(t,e,n){"use strict";
  136. /**
  137. * @license
  138. * Copyright 2018 Google LLC. All Rights Reserved.
  139. * Licensed under the Apache License, Version 2.0 (the "License");
  140. * you may not use this file except in compliance with the License.
  141. * You may obtain a copy of the License at
  142. *
  143. * http://www.apache.org/licenses/LICENSE-2.0
  144. *
  145. * Unless required by applicable law or agreed to in writing, software
  146. * distributed under the License is distributed on an "AS IS" BASIS,
  147. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  148. * See the License for the specific language governing permissions and
  149. * limitations under the License.
  150. * =============================================================================
  151. */var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})};Object.defineProperty(e,"__esModule",{value:!0});const i=n(4),a=n(120);e.arrayStats=function(t){if(!Array.isArray(t))throw new Error("input must be an array");if(0===t.length)return{numVals:0,numNans:0,numZeros:0,max:void 0,min:void 0};const e=t.length;let n=-1/0,r=1/0,i=0,a=0,o=0;for(let s=0;s<e;s++){const e=t[s];e>n&&(n=e),e<r&&(r=e),0===e&&(i+=1),isNaN(e)?a+=1:isFinite(e)||(o+=1)}const s={numVals:e,numZeros:i,numNans:a,max:n,min:r,numInfs:o};return s.max===-1/0&&(s.max=NaN),s.min===1/0&&(s.min=NaN),s},e.tensorStats=function(t){return r(this,void 0,void 0,function*(){const[e,n,r]=i.tidy(()=>{const e=i.scalar(0,t.dtype);return[t.min(),t.max(),t.equal(e).sum()]});return Promise.all([t.data(),e.data(),n.data(),r.data()]).then(([t,e,n,r])=>{const i=t.length;let a=0,o=0;for(let e=0;e<i;e++){const n=t[e];isNaN(n)?a+=1:isFinite(n)||(o+=1)}let s=e[0],u=n[0];return a===i&&(s=NaN,u=NaN),{numVals:i,numZeros:r[0],numNans:a,min:s,max:u,numInfs:o}})})},e.confusionMatrix=function(t,e,n,o){return r(this,void 0,void 0,function*(){a.assert(1===t.rank,"labels must be a 1D tensor"),a.assert(1===e.rank,"predictions must be a 1D tensor"),a.assert(t.size===e.size,"labels and predictions must be the same length"),null!=o&&a.assert(o.size===e.size,"labels and predictions must be the same length");const r=t.cast("int32"),s=e.cast("int32");null==n&&(n=i.tidy(()=>i.maximum(r.max(),s.max()).cast("int32").dataSync()[0]+1));let u=Promise.resolve(null);return null!=o&&(u=o.data()),Promise.all([r.data(),s.data(),u]).then(([t,e,r])=>{const i=Array(n).fill(0);for(let t=0;t<n;t++)i[t]=Array(n).fill(0);for(let n=0;n<t.length;n++){const a=t[n],o=e[n];i[a][o]+=null!=r?r[n]:1}return i})})},e.accuracy=function(t,e){return r(this,void 0,void 0,function*(){a.assertShapesMatch(t.shape,e.shape,"Error computing accuracy.");const n=t.equal(e),r=n.mean(),o=(yield r.data())[0];return i.dispose([n,r]),o})},e.perClassAccuracy=function(t,e,n){return r(this,void 0,void 0,function*(){return a.assert(1===t.rank,"labels must be a 1D tensor"),a.assert(1===e.rank,"predictions must be a 1D tensor"),a.assert(t.size===e.size,"labels and predictions must be the same length"),null==n&&(n=i.tidy(()=>i.maximum(t.max(),e.max()).dataSync()[0]+1)),Promise.all([t.data(),e.data()]).then(([t,e])=>{const r=Array(n).fill(0),i=Array(n).fill(0);for(let n=0;n<t.length;n++){const a=t[n],o=e[n];r[a]+=1,a===o&&(i[a]+=1)}const a=[];for(let t=0;t<r.length;t++)a.push({count:r[t],accuracy:0===r[t]?0:i[t]/r[t]});return a})})}},function(t,e,n){"use strict";
  152. /*
  153. * @license
  154. * Copyright 2018 Google LLC. All Rights Reserved.
  155. * Licensed under the Apache License, Version 2.0 (the "License");
  156. * you may not use this file except in compliance with the License.
  157. * You may obtain a copy of the License at
  158. *
  159. * http://www.apache.org/licenses/LICENSE-2.0
  160. *
  161. * Unless required by applicable law or agreed to in writing, software
  162. * distributed under the License is distributed on an "AS IS" BASIS,
  163. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  164. * See the License for the specific language governing permissions and
  165. * limitations under the License.
  166. * =============================================================================
  167. */
  168. function r(t,e){if(!t)throw new Error("string"==typeof e?e:e())}function i(t,e){if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0}Object.defineProperty(e,"__esModule",{value:!0}),e.assert=r,e.assertShapesMatch=function(t,e,n=""){r(i(t,e),n+` Shapes ${t} and ${e} must match`)},e.arraysEqual=i,e.DECIMAL_PLACES_TO_CHECK=4},function(t,e){var n=0,r=Math.random();t.exports=function(t){return"Symbol(".concat(void 0===t?"":t,")_",(++n+r).toString(36))}},function(t,e,n){var r=n(161),i=Math.min;t.exports=function(t){return t>0?i(r(t),9007199254740991):0}},function(t,e,n){"use strict";var r=n(5),i=n(27),a=n(43),o=n(72);t.exports=function(t){r(r.S,t,{from:function(t){var e,n,r,s,u=arguments[1];return i(this),(e=void 0!==u)&&i(u),void 0==t?new this:(n=[],e?(r=0,s=a(u,arguments[2],2),o(t,!1,function(t){n.push(s(t,r++))})):o(t,!1,n.push,n),new this(n))}})}},function(t,e,n){"use strict";var r=n(5);t.exports=function(t){r(r.S,t,{of:function(){for(var t=arguments.length,e=new Array(t);t--;)e[t]=arguments[t];return new this(e)}})}},function(t,e,n){"use strict";t.exports=n(63)||!n(12)(function(){var t=Math.random();__defineSetter__.call(null,t,function(){}),delete n(11)[t]})},function(t,e,n){for(var r,i=n(11),a=n(31),o=n(79),s=o("typed_array"),u=o("view"),c=!(!i.ArrayBuffer||!i.DataView),l=c,f=0,d="Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array".split(",");f<9;)(r=i[d[f++]])?(a(r.prototype,s,!0),a(r.prototype,u,!0)):l=!1;t.exports={ABV:c,CONSTR:l,TYPED:s,VIEW:u}},function(t,e,n){"use strict";var r=n(11),i=n(5),a=n(30),o=n(71),s=n(62),u=n(72),c=n(73),l=n(13),f=n(12),d=n(131),h=n(94),p=n(185);t.exports=function(t,e,n,m,g,v){var y=r[t],b=y,x=g?"set":"add",w=b&&b.prototype,k={},_=function(t){var e=w[t];a(w,t,"delete"==t?function(t){return!(v&&!l(t))&&e.call(this,0===t?0:t)}:"has"==t?function(t){return!(v&&!l(t))&&e.call(this,0===t?0:t)}:"get"==t?function(t){return v&&!l(t)?void 0:e.call(this,0===t?0:t)}:"add"==t?function(t){return e.call(this,0===t?0:t),this}:function(t,n){return e.call(this,0===t?0:t,n),this})};if("function"==typeof b&&(v||w.forEach&&!f(function(){(new b).entries().next()}))){var E=new b,O=E[x](v?{}:-0,1)!=E,S=f(function(){E.has(1)}),C=d(function(t){new b(t)}),A=!v&&f(function(){for(var t=new b,e=5;e--;)t[x](e,e);return!t.has(-0)});C||((b=e(function(e,n){c(e,b,t);var r=p(new y,e,b);return void 0!=n&&u(n,g,r[x],r),r})).prototype=w,w.constructor=b),(S||A)&&(_("delete"),_("has"),g&&_("get")),(A||O)&&_(x),v&&w.clear&&delete w.clear}else b=m.getConstructor(e,t,g,x),o(b.prototype,n),s.NEED=!0;return h(b,t),k[t]=b,i(i.G+i.W+i.F*(b!=y),k),v||m.setStrong(b,t,g),b}},function(t,e,n){var r=n(11).navigator;t.exports=r&&r.userAgent||""},function(t,e,n){"use strict";n(263);var r=n(30),i=n(31),a=n(12),o=n(51),s=n(16),u=n(171),c=s("species"),l=!a(function(){var t=/./;return t.exec=function(){var t=[];return t.groups={a:"7"},t},"7"!=="".replace(t,"$<a>")}),f=function(){var t=/(?:)/,e=t.exec;t.exec=function(){return e.apply(this,arguments)};var n="ab".split(t);return 2===n.length&&"a"===n[0]&&"b"===n[1]}();t.exports=function(t,e,n){var d=s(t),h=!a(function(){var e={};return e[d]=function(){return 7},7!=""[t](e)}),p=h?!a(function(){var e=!1,n=/a/;return n.exec=function(){return e=!0,null},"split"===t&&(n.constructor={},n.constructor[c]=function(){return n}),n[d](""),!e}):void 0;if(!h||!p||"replace"===t&&!l||"split"===t&&!f){var m=/./[d],g=n(o,d,""[t],function(t,e,n,r,i){return e.exec===u?h&&!i?{done:!0,value:m.call(e,n,r)}:{done:!0,value:t.call(n,e,r)}:{done:!1}}),v=g[0],y=g[1];r(String.prototype,t,v),i(RegExp.prototype,d,2==e?function(t,e){return y.call(t,this,e)}:function(t){return y.call(t,this)})}}},function(t,e,n){"use strict";var r=n(93),i=RegExp.prototype.exec;t.exports=function(t,e){var n=t.exec;if("function"==typeof n){var a=n.call(t,e);if("object"!=typeof a)throw new TypeError("RegExp exec method returned something other than an Object or null");return a}if("RegExp"!==r(t))throw new TypeError("RegExp#exec called on incompatible receiver");return i.call(t,e)}},function(t,e,n){var r=n(16)("iterator"),i=!1;try{var a=[7][r]();a.return=function(){i=!0},Array.from(a,function(){throw 2})}catch(t){}t.exports=function(t,e){if(!e&&!i)return!1;var n=!1;try{var a=[7],o=a[r]();o.next=function(){return{done:n=!0}},a[r]=function(){return o},t(a)}catch(t){}return n}},function(t,e,n){var r=n(13),i=n(42),a=n(16)("match");t.exports=function(t){var e;return r(t)&&(void 0!==(e=t[a])?!!e:"RegExp"==i(t))}},function(t,e,n){var r=n(41),i=n(51);t.exports=function(t){return function(e,n){var a,o,s=String(i(e)),u=r(n),c=s.length;return u<0||u>=c?t?"":void 0:(a=s.charCodeAt(u))<55296||a>56319||u+1===c||(o=s.charCodeAt(u+1))<56320||o>57343?t?s.charAt(u):a:t?s.slice(u,u+2):o-56320+(a-55296<<10)+65536}}},function(t,e,n){var r=n(42);t.exports=Array.isArray||function(t){return"Array"==r(t)}},function(t,e){e.f=Object.getOwnPropertySymbols},function(t,e,n){var r=n(35),i=n(17),a=n(77);t.exports=function(t){return function(e,n,o){var s,u=r(e),c=i(u.length),l=a(o,c);if(t&&n!=n){for(;c>l;)if((s=u[l++])!=s)return!0}else for(;c>l;l++)if((t||l in u)&&u[l]===n)return t||l||0;return!t&&-1}}},function(t,e,n){"use strict";n.r(e),function(t,r){n.d(e,"array",function(){return X}),n.d(e,"Dataset",function(){return $}),n.d(e,"zip",function(){return Y}),n.d(e,"CSVDataset",function(){return it}),n.d(e,"TextLineDataset",function(){return Z}),n.d(e,"csv",function(){return bt}),n.d(e,"func",function(){return xt}),n.d(e,"generator",function(){return wt}),n.d(e,"microphone",function(){return _t}),n.d(e,"webcam",function(){return kt}),n.d(e,"FileDataSource",function(){return vt}),n.d(e,"URLDataSource",function(){return yt}),n.d(e,"version_data",function(){return Et});var i=n(0),a=function(t,e){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};
  169. /**
  170. * @license
  171. * Copyright 2020 Google LLC. All Rights Reserved.
  172. * Licensed under the Apache License, Version 2.0 (the "License");
  173. * you may not use this file except in compliance with the License.
  174. * You may obtain a copy of the License at
  175. *
  176. * http://www.apache.org/licenses/LICENSE-2.0
  177. *
  178. * Unless required by applicable law or agreed to in writing, software
  179. * distributed under the License is distributed on an "AS IS" BASIS,
  180. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  181. * See the License for the specific language governing permissions and
  182. * limitations under the License.
  183. * =============================================================================
  184. */function o(t,e){function n(){this.constructor=t}a(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function s(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})}function u(t,e){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=(i=o.trys).length>0&&i[i.length-1])&&(6===a[0]||2===a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}"undefined"!=typeof window?window:void 0!==t||"undefined"!=typeof self&&self;function c(t,e){return t(e={exports:{}},e.exports),e.exports}var l=c(function(t){!function(t,e,n){function r(t,e){return e.c=t.c,e.s0=t.s0,e.s1=t.s1,e.s2=t.s2,e}function i(t,e){var n=new function(t){var e,n=this,r=(e=4022871197,function(t){t=t.toString();for(var n=0;n<t.length;n++){var r=.02519603282416938*(e+=t.charCodeAt(n));r-=e=r>>>0,e=(r*=e)>>>0,e+=4294967296*(r-=e)}return 2.3283064365386963e-10*(e>>>0)});n.next=function(){var t=2091639*n.s0+2.3283064365386963e-10*n.c;return n.s0=n.s1,n.s1=n.s2,n.s2=t-(n.c=0|t)},n.c=1,n.s0=r(" "),n.s1=r(" "),n.s2=r(" "),n.s0-=r(t),n.s0<0&&(n.s0+=1),n.s1-=r(t),n.s1<0&&(n.s1+=1),n.s2-=r(t),n.s2<0&&(n.s2+=1),r=null}(t),i=e&&e.state,a=n.next;return a.int32=function(){return 4294967296*n.next()|0},a.double=function(){return a()+1.1102230246251565e-16*(2097152*a()|0)},a.quick=a,i&&("object"==typeof i&&r(i,n),a.state=function(){return r(n,{})}),a}e&&e.exports?e.exports=i:this.alea=i}(0,t)}),f=c(function(t){!function(t,e,n){function r(t,e){return e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w,e}function i(t,e){var n=new function(t){var e=this,n="";e.x=0,e.y=0,e.z=0,e.w=0,e.next=function(){var t=e.x^e.x<<11;return e.x=e.y,e.y=e.z,e.z=e.w,e.w^=e.w>>>19^t^t>>>8},t===(0|t)?e.x=t:n+=t;for(var r=0;r<n.length+64;r++)e.x^=0|n.charCodeAt(r),e.next()}(t),i=e&&e.state,a=function(){return(n.next()>>>0)/4294967296};return a.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},a.int32=n.next,a.quick=a,i&&("object"==typeof i&&r(i,n),a.state=function(){return r(n,{})}),a}e&&e.exports?e.exports=i:this.xor128=i}(0,t)}),d=c(function(t){!function(t,e,n){function r(t,e){return e.x=t.x,e.y=t.y,e.z=t.z,e.w=t.w,e.v=t.v,e.d=t.d,e}function i(t,e){var n=new function(t){var e=this,n="";e.next=function(){var t=e.x^e.x>>>2;return e.x=e.y,e.y=e.z,e.z=e.w,e.w=e.v,(e.d=e.d+362437|0)+(e.v=e.v^e.v<<4^t^t<<1)|0},e.x=0,e.y=0,e.z=0,e.w=0,e.v=0,t===(0|t)?e.x=t:n+=t;for(var r=0;r<n.length+64;r++)e.x^=0|n.charCodeAt(r),r==n.length&&(e.d=e.x<<10^e.x>>>4),e.next()}(t),i=e&&e.state,a=function(){return(n.next()>>>0)/4294967296};return a.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},a.int32=n.next,a.quick=a,i&&("object"==typeof i&&r(i,n),a.state=function(){return r(n,{})}),a}e&&e.exports?e.exports=i:this.xorwow=i}(0,t)}),h=c(function(t){!function(t,e,n){function r(t,e){return e.x=t.x.slice(),e.i=t.i,e}function i(t,e){null==t&&(t=+new Date);var n=new function(t){var e=this;e.next=function(){var t,n,r=e.x,i=e.i;return t=r[i],n=(t^=t>>>7)^t<<24,n^=(t=r[i+1&7])^t>>>10,n^=(t=r[i+3&7])^t>>>3,n^=(t=r[i+4&7])^t<<7,t=r[i+7&7],n^=(t^=t<<13)^t<<9,r[i]=n,e.i=i+1&7,n},function(t,e){var n,r=[];if(e===(0|e))r[0]=e;else for(e=""+e,n=0;n<e.length;++n)r[7&n]=r[7&n]<<15^e.charCodeAt(n)+r[n+1&7]<<13;for(;r.length<8;)r.push(0);for(n=0;n<8&&0===r[n];++n);for(8==n?r[7]=-1:r[n],t.x=r,t.i=0,n=256;n>0;--n)t.next()}(e,t)}(t),i=e&&e.state,a=function(){return(n.next()>>>0)/4294967296};return a.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},a.int32=n.next,a.quick=a,i&&(i.x&&r(i,n),a.state=function(){return r(n,{})}),a}e&&e.exports?e.exports=i:this.xorshift7=i}(0,t)}),p=c(function(t){!function(t,e,n){function r(t,e){return e.i=t.i,e.w=t.w,e.X=t.X.slice(),e}function i(t,e){null==t&&(t=+new Date);var n=new function(t){var e=this;e.next=function(){var t,n,r=e.w,i=e.X,a=e.i;return e.w=r=r+1640531527|0,n=i[a+34&127],t=i[a=a+1&127],n^=n<<13,t^=t<<17,n^=n>>>15,t^=t>>>12,n=i[a]=n^t,e.i=a,n+(r^r>>>16)|0},function(t,e){var n,r,i,a,o,s=[],u=128;for(e===(0|e)?(r=e,e=null):(e+="\0",r=0,u=Math.max(u,e.length)),i=0,a=-32;a<u;++a)e&&(r^=e.charCodeAt((a+32)%e.length)),0===a&&(o=r),r^=r<<10,r^=r>>>15,r^=r<<4,r^=r>>>13,a>=0&&(o=o+1640531527|0,i=0==(n=s[127&a]^=r+o)?i+1:0);for(i>=128&&(s[127&(e&&e.length||0)]=-1),i=127,a=512;a>0;--a)r=s[i+34&127],n=s[i=i+1&127],r^=r<<13,n^=n<<17,r^=r>>>15,n^=n>>>12,s[i]=r^n;t.w=o,t.X=s,t.i=i}(e,t)}(t),i=e&&e.state,a=function(){return(n.next()>>>0)/4294967296};return a.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},a.int32=n.next,a.quick=a,i&&(i.X&&r(i,n),a.state=function(){return r(n,{})}),a}e&&e.exports?e.exports=i:this.xor4096=i}(0,t)}),m=c(function(t){!function(t,e,n){function r(t,e){return e.a=t.a,e.b=t.b,e.c=t.c,e.d=t.d,e}function i(t,e){var n=new function(t){var e=this,n="";e.next=function(){var t=e.b,n=e.c,r=e.d,i=e.a;return t=t<<25^t>>>7^n,n=n-r|0,r=r<<24^r>>>8^i,i=i-t|0,e.b=t=t<<20^t>>>12^n,e.c=n=n-r|0,e.d=r<<16^n>>>16^i,e.a=i-t|0},e.a=0,e.b=0,e.c=-1640531527,e.d=1367130551,t===Math.floor(t)?(e.a=t/4294967296|0,e.b=0|t):n+=t;for(var r=0;r<n.length+20;r++)e.b^=0|n.charCodeAt(r),e.next()}(t),i=e&&e.state,a=function(){return(n.next()>>>0)/4294967296};return a.double=function(){do{var t=((n.next()>>>11)+(n.next()>>>0)/4294967296)/(1<<21)}while(0===t);return t},a.int32=n.next,a.quick=a,i&&("object"==typeof i&&r(i,n),a.state=function(){return r(n,{})}),a}e&&e.exports?e.exports=i:this.tychei=i}(0,t)}),g=c(function(t){!function(e,r){var i,a=this,o=256,s=6,u="random",c=r.pow(o,s),l=r.pow(2,52),f=2*l,d=o-1;function h(t,n,h){var v=[],y=m(function t(e,n){var r,i=[],a=typeof e;if(n&&"object"==a)for(r in e)try{i.push(t(e[r],n-1))}catch(t){}return i.length?i:"string"==a?e:e+"\0"}((n=1==n?{entropy:!0}:n||{}).entropy?[t,g(e)]:null==t?function(){try{var t;return i&&(t=i.randomBytes)?t=t(o):(t=new Uint8Array(o),(a.crypto||a.msCrypto).getRandomValues(t)),g(t)}catch(t){var n=a.navigator,r=n&&n.plugins;return[+new Date,a,r,a.screen,g(e)]}}():t,3),v),b=new function(t){var e,n=t.length,r=this,i=0,a=r.i=r.j=0,s=r.S=[];for(n||(t=[n++]);i<o;)s[i]=i++;for(i=0;i<o;i++)s[i]=s[a=d&a+t[i%n]+(e=s[i])],s[a]=e;(r.g=function(t){for(var e,n=0,i=r.i,a=r.j,s=r.S;t--;)e=s[i=d&i+1],n=n*o+s[d&(s[i]=s[a=d&a+e])+(s[a]=e)];return r.i=i,r.j=a,n})(o)}(v),x=function(){for(var t=b.g(s),e=c,n=0;t<l;)t=(t+n)*o,e*=o,n=b.g(1);for(;t>=f;)t/=2,e/=2,n>>>=1;return(t+n)/e};return x.int32=function(){return 0|b.g(4)},x.quick=function(){return b.g(4)/4294967296},x.double=x,m(g(b.S),e),(n.pass||h||function(t,e,n,i){return i&&(i.S&&p(i,b),t.state=function(){return p(b,{})}),n?(r[u]=t,e):t})(x,y,"global"in n?n.global:this==r,n.state)}function p(t,e){return e.i=t.i,e.j=t.j,e.S=t.S.slice(),e}function m(t,e){for(var n,r=t+"",i=0;i<r.length;)e[d&i]=d&(n^=19*e[d&i])+r.charCodeAt(i++);return g(e)}function g(t){return String.fromCharCode.apply(0,t)}if(r["seed"+u]=h,m(r.random(),e),t.exports){t.exports=h;try{i=n(477)}catch(t){}}}([],Math)});g.alea=l,g.xor128=f,g.xorwow=d,g.xorshift7=h,g.xor4096=p,g.tychei=m;var v=g.alea;function y(t,e,n,r){if(void 0===n&&(n=new Map),void 0===r&&(r=new Set),null==t)return null;if(r.has(t))throw new Error("Circular references are not supported.");if(n.has(t))return n.get(t);var i=e(t);if(i.recurse&&null!==i.value)throw new Error("A deep map function may not return both a value and recurse=true.");if(i.recurse){if(k(t)){var a=Array.isArray(t)?[]:{};for(var o in r.add(t),t){var s=y(t[o],e,n,r);a[o]=s}return r.delete(t),a}throw new Error("Can't recurse into non-iterable type: "+t)}return n.set(t,i.value),i.value}function b(t,e){return void 0===e&&(e=x),function t(e,n,r){void 0===r&&(r=new Set);var i=e[0];if(r.has(i))throw new Error("Circular references are not supported.");var a=n(e);if(a.recurse&&null!==a.value)throw new Error("A deep zip function may not return both a value and recurse=true.");if(a.recurse){if(k(i)){var o=Array.isArray(i)?[]:{};r.add(i);var s=function(i){var a=t(e.map(function(t){return t[i]}),n,r);o[i]=a};for(var u in i)s(u);return r.delete(i),o}throw new Error("Can't recurse into non-iterable type: "+i)}return a.value}(t,e)}function x(t){return null===t?null:k(t[0])?{value:null,recurse:!0}:{value:t,recurse:!1}}function w(t,e){return s(this,void 0,void 0,function(){var n,r,i,a,o,s;return u(this,function(u){switch(u.label){case 0:n=new Map,y(t,e,n),r=0,i=Array.from(n.keys()),u.label=1;case 1:return r<i.length?(a=i[r],(o=n.get(a))instanceof Promise?[4,o]:[3,3]):[3,4];case 2:s=u.sent(),n.set(a,s),u.label=3;case 3:return r++,[3,1];case 4:return[2,y(t,e,n)]}})})}function k(t){return null!=t&&!ArrayBuffer.isView(t)&&(Array.isArray(t)||"object"==typeof t&&!(t instanceof i.Tensor))}function _(t){return function(t,e){return y(t,e)}(t,E)}function E(t){return t instanceof i.Tensor?{value:t.clone(),recurse:!1}:k(t)?{value:null,recurse:!0}:{value:t,recurse:!1}}var O=function(){function t(t){if(this.capacity=t,this.begin=0,this.end=0,null==t)throw new RangeError("Can't create a ring buffer of unknown capacity.");if(t<1)throw new RangeError("Can't create ring buffer of capacity < 1.");this.data=new Array(t),this.doubledCapacity=2*t}return t.prototype.wrap=function(t){for(;t<0;)t+=this.doubledCapacity;return t%this.doubledCapacity},t.prototype.get=function(t){if(t<0)throw new RangeError("Can't get item at a negative index.");return this.data[t%this.capacity]},t.prototype.set=function(t,e){if(t<0)throw new RangeError("Can't set item at a negative index.");this.data[t%this.capacity]=e},t.prototype.length=function(){var t=this.end-this.begin;return t<0&&(t=this.doubledCapacity+t),t},t.prototype.isFull=function(){return this.length()===this.capacity},t.prototype.isEmpty=function(){return 0===this.length()},t.prototype.push=function(t){if(this.isFull())throw new RangeError("Ring buffer is full.");this.set(this.end,t),this.end=this.wrap(this.end+1)},t.prototype.pushAll=function(t){for(var e=0,n=t;e<n.length;e++){var r=n[e];this.push(r)}},t.prototype.pop=function(){if(this.isEmpty())throw new RangeError("Ring buffer is empty.");this.end=this.wrap(this.end-1);var t=this.get(this.end);return this.set(this.end,void 0),t},t.prototype.unshift=function(t){if(this.isFull())throw new RangeError("Ring buffer is full.");this.begin=this.wrap(this.begin-1),this.set(this.begin,t)},t.prototype.shift=function(){if(this.isEmpty())throw new RangeError("Ring buffer is empty.");var t=this.get(this.begin);return this.set(this.begin,void 0),this.begin=this.wrap(this.begin+1),t},t.prototype.shuffleExcise=function(t){if(this.isEmpty())throw new RangeError("Ring buffer is empty.");var e=this.wrap(this.begin+t),n=this.get(e);return this.set(e,this.pop()),n},t}(),S=function(t){function e(){return t.call(this,e.INITIAL_CAPACITY)||this}return o(e,t),e.prototype.isFull=function(){return!1},e.prototype.push=function(e){t.prototype.isFull.call(this)&&this.expand(),t.prototype.push.call(this,e)},e.prototype.unshift=function(e){t.prototype.isFull.call(this)&&this.expand(),t.prototype.unshift.call(this,e)},e.prototype.expand=function(){for(var t=2*this.capacity,e=new Array(t),n=this.length(),r=0;r<n;r++)e[r]=this.get(this.wrap(this.begin+r));this.data=e,this.capacity=t,this.doubledCapacity=2*this.capacity,this.begin=0,this.end=n},e.INITIAL_CAPACITY=32,e}(O);function C(t){return new I(t)}function A(t){return new D(t)}var N,T=function(){function t(){}return t.prototype.toArray=function(){return s(this,void 0,void 0,function(){var t,e;return u(this,function(n){switch(n.label){case 0:return t=[],[4,this.next()];case 1:e=n.sent(),n.label=2;case 2:return e.done?[3,4]:(t.push(e.value),[4,this.next()]);case 3:return e=n.sent(),[3,2];case 4:return[2,t]}})})},t.prototype.toArrayForTest=function(){return s(this,void 0,void 0,function(){var t,e,n;return u(this,function(r){switch(r.label){case 0:return t=this.prefetch(100),e=[],[4,t.next()];case 1:n=r.sent(),r.label=2;case 2:return n.done?[3,4]:(e.push(n.value),[4,t.next()]);case 3:return n=r.sent(),[3,2];case 4:return[2,e]}})})},t.prototype.resolveFully=function(){return s(this,void 0,void 0,function(){var t;return u(this,function(e){switch(e.label){case 0:return[4,this.next()];case 1:t=e.sent(),e.label=2;case 2:return t.done?[3,4]:[4,this.next()];case 3:return t=e.sent(),[3,2];case 4:return[2]}})})},t.prototype.resolveWhile=function(t){return s(this,void 0,void 0,function(){var e,n;return u(this,function(r){switch(r.label){case 0:return[4,this.next()];case 1:e=r.sent(),n=t(e.value),r.label=2;case 2:return e.done||!n?[3,4]:[4,this.next()];case 3:return e=r.sent(),n=t(e.value),[3,2];case 4:return[2]}})})},t.prototype.handleErrors=function(t){return new z(this,t)},t.prototype.filter=function(t){return new P(this,t)},t.prototype.map=function(t){return new L(this,t)},t.prototype.mapAsync=function(t){return new B(this,t)},t.prototype.serialMapAsync=function(t){return new B(this,t).serial()},t.prototype.flatmap=function(t){return new W(this,t)},t.prototype.forEachAsync=function(t){return s(this,void 0,void 0,function(){return u(this,function(e){return[2,this.map(t).resolveFully()]})})},t.prototype.serialForEach=function(t){return s(this,void 0,void 0,function(){return u(this,function(e){return[2,this.serialMapAsync(t).resolveWhile(function(t){return!0===t})]})})},t.prototype.rowMajorBatch=function(t,e){return void 0===e&&(e=!0),new j(this,t,e)},t.prototype.columnMajorBatch=function(t,e,n){return void 0===e&&(e=!0),void 0===n&&(n=x),this.rowMajorBatch(t,e).map(function(t){return b(t,n)})},t.prototype.concatenate=function(t,e){return new V(C([this,t]),e)},t.prototype.take=function(t){return t<0||null==t?this:new F(this,t)},t.prototype.skip=function(t){return t<0||null==t?this:new R(this,t)},t.prototype.prefetch=function(t){return new H(this,t)},t.prototype.shuffle=function(t,e){return new G(this,t,e)},t.prototype.serial=function(){return new M(this)},t}(),I=function(t){function e(e){var n=t.call(this)||this;return n.items=e,n.trav=0,n}return o(e,t),e.prototype.summary=function(){return"Array of "+this.items.length+" items"},e.prototype.next=function(){return s(this,void 0,void 0,function(){var t;return u(this,function(e){return this.trav>=this.items.length?[2,{value:null,done:!0}]:(t=this.items[this.trav],this.trav++,[2,{value:_(t),done:!1}])})})},e}(T),D=function(t){function e(e){var n=t.call(this)||this;return n.nextFn=e,n}return o(e,t),e.prototype.summary=function(){return"Function call"},e.prototype.next=function(){return s(this,void 0,void 0,function(){return u(this,function(t){try{return[2,this.nextFn()]}catch(t){throw t.message="Error thrown while iterating through a dataset: "+t.message,t}return[2]})})},e}(T),M=function(t){function e(e){var n=t.call(this)||this;return n.upstream=e,n.lastRead=Promise.resolve({value:null,done:!1}),n}return o(e,t),e.prototype.summary=function(){return this.upstream.summary()+" -> Serial"},e.prototype.next=function(){return s(this,void 0,void 0,function(){var t=this;return u(this,function(e){return this.lastRead=this.lastRead.then(function(){return t.serialNext()}),[2,this.lastRead]})})},e.prototype.serialNext=function(){return s(this,void 0,void 0,function(){return u(this,function(t){return[2,this.upstream.next()]})})},e}(T),R=function(t){function e(e,n){var r=t.call(this)||this;return r.upstream=e,r.maxCount=n,r.count=0,r.lastRead=Promise.resolve({value:null,done:!1}),r}return o(e,t),e.prototype.summary=function(){return this.upstream.summary()+" -> Skip"},e.prototype.next=function(){return s(this,void 0,void 0,function(){var t=this;return u(this,function(e){return this.lastRead=this.lastRead.then(function(){return t.serialNext()}),[2,this.lastRead]})})},e.prototype.serialNext=function(){return s(this,void 0,void 0,function(){var t;return u(this,function(e){switch(e.label){case 0:return this.count++<this.maxCount?[4,this.upstream.next()]:[3,2];case 1:return(t=e.sent()).done?[2,t]:(Object(i.dispose)(t.value),[3,0]);case 2:return[2,this.upstream.next()]}})})},e}(T),F=function(t){function e(e,n){var r=t.call(this)||this;return r.upstream=e,r.maxCount=n,r.count=0,r}return o(e,t),e.prototype.summary=function(){return this.upstream.summary()+" -> Take"},e.prototype.next=function(){return s(this,void 0,void 0,function(){return u(this,function(t){return this.count++>=this.maxCount?[2,{value:null,done:!0}]:[2,this.upstream.next()]})})},e}(T),j=function(t){function e(e,n,r){void 0===r&&(r=!0);var i=t.call(this)||this;return i.upstream=e,i.batchSize=n,i.enableSmallLastBatch=r,i.lastRead=Promise.resolve({value:null,done:!1}),i}return o(e,t),e.prototype.summary=function(){return this.upstream.summary()+" -> RowMajorBatch"},e.prototype.next=function(){return s(this,void 0,void 0,function(){var t=this;return u(this,function(e){return this.lastRead=this.lastRead.then(function(){return t.serialNext()}),[2,this.lastRead]})})},e.prototype.serialNext=function(){return s(this,void 0,void 0,function(){var t,e;return u(this,function(n){switch(n.label){case 0:t=[],n.label=1;case 1:return t.length<this.batchSize?[4,this.upstream.next()]:[3,3];case 2:return(e=n.sent()).done?this.enableSmallLastBatch&&t.length>0?[2,{value:t,done:!1}]:[2,{value:null,done:!0}]:(t.push(e.value),[3,1]);case 3:return[2,{value:t,done:!1}]}})})},e}(T),P=function(t){function e(e,n){var r=t.call(this)||this;return r.upstream=e,r.predicate=n,r.lastRead=Promise.resolve({value:null,done:!1}),r}return o(e,t),e.prototype.summary=function(){return this.upstream.summary()+" -> Filter"},e.prototype.next=function(){return s(this,void 0,void 0,function(){var t=this;return u(this,function(e){return this.lastRead=this.lastRead.then(function(){return t.serialNext()}),[2,this.lastRead]})})},e.prototype.serialNext=function(){return s(this,void 0,void 0,function(){var t;return u(this,function(e){switch(e.label){case 0:return[4,this.upstream.next()];case 1:return(t=e.sent()).done||this.predicate(t.value)?[2,t]:(Object(i.dispose)(t.value),[3,0]);case 2:return[2]}})})},e}(T),L=function(t){function e(e,n){var r=t.call(this)||this;return r.upstream=e,r.transform=n,r}return o(e,t),e.prototype.summary=function(){return this.upstream.summary()+" -> Map"},e.prototype.next=function(){return s(this,void 0,void 0,function(){var t,e,n,r,a,o,s;return u(this,function(u){switch(u.label){case 0:return[4,this.upstream.next()];case 1:if((t=u.sent()).done)return[2,{value:null,done:!0}];for(e=i.tensor_util.getTensorsInContainer(t.value),n=this.transform(t.value),r=i.tensor_util.getTensorsInContainer(n),a=0,o=e;a<o.length;a++)s=o[a],i.tensor_util.isTensorInList(s,r)||s.dispose();return[2,{value:n,done:!1}]}})})},e}(T),z=function(t){function e(e,n){var r=t.call(this)||this;return r.upstream=e,r.handler=n,r.count=0,r.lastRead=Promise.resolve({value:null,done:!1}),r}return o(e,t),e.prototype.summary=function(){return this.upstream.summary()+" -> handleErrors"},e.prototype.next=function(){return s(this,void 0,void 0,function(){var t=this;return u(this,function(e){return this.lastRead=this.lastRead.then(function(){return t.serialNext()}),[2,this.lastRead]})})},e.prototype.serialNext=function(){return s(this,void 0,void 0,function(){var t;return u(this,function(e){switch(e.label){case 0:e.label=1;case 1:return e.trys.push([1,3,,4]),[4,this.upstream.next()];case 2:return[2,e.sent()];case 3:return t=e.sent(),this.handler(t)?[3,4]:[2,{value:null,done:!0}];case 4:return[3,0];case 5:return[2]}})})},e}(T),B=function(t){function e(e,n){var r=t.call(this)||this;return r.upstream=e,r.transform=n,r}return o(e,t),e.prototype.summary=function(){return this.upstream.summary()+" -> AsyncMap"},e.prototype.next=function(){return s(this,void 0,void 0,function(){var t,e,n,r,a,o,s;return u(this,function(u){switch(u.label){case 0:return[4,this.upstream.next()];case 1:return(t=u.sent()).done?[2,{value:null,done:!0}]:(e=i.tensor_util.getTensorsInContainer(t.value),[4,this.transform(t.value)]);case 2:for(n=u.sent(),r=i.tensor_util.getTensorsInContainer(n),a=0,o=e;a<o.length;a++)s=o[a],i.tensor_util.isTensorInList(s,r)||s.dispose();return[2,{value:n,done:!1}]}})})},e}(T),U=function(t){function e(){var e=t.call(this)||this;return e.outputQueue=new S,e.lastRead=Promise.resolve({value:null,done:!1}),e}return o(e,t),e.prototype.next=function(){return s(this,void 0,void 0,function(){var t=this;return u(this,function(e){return this.lastRead=this.lastRead.then(function(){return t.serialNext()}),[2,this.lastRead]})})},e.prototype.serialNext=function(){return s(this,void 0,void 0,function(){return u(this,function(t){switch(t.label){case 0:return 0!==this.outputQueue.length()?[3,2]:[4,this.pump()];case 1:return t.sent()?[3,0]:[2,{value:null,done:!0}];case 2:return[2,{value:this.outputQueue.shift(),done:!1}]}})})},e}(T),W=function(t){function e(e,n){var r=t.call(this)||this;return r.upstream=e,r.transform=n,r}return o(e,t),e.prototype.summary=function(){return this.upstream.summary()+" -> Flatmap"},e.prototype.pump=function(){return s(this,void 0,void 0,function(){var t,e,n,r,a,o,s;return u(this,function(u){switch(u.label){case 0:return[4,this.upstream.next()];case 1:if((t=u.sent()).done)return[2,!1];for(e=i.tensor_util.getTensorsInContainer(t.value),n=this.transform(t.value),r=i.tensor_util.getTensorsInContainer(n),this.outputQueue.pushAll(n),a=0,o=e;a<o.length;a++)s=o[a],i.tensor_util.isTensorInList(s,r)||s.dispose();return[2,!0]}})})},e}(U),V=function(t){function e(e,n){var r=t.call(this)||this;return r.baseErrorHandler=n,r.lastRead=null,r.iterator=null,r.moreIterators=e,r}return o(e,t),e.prototype.summary=function(){return"TODO: fill in upstream of chained summaries -> Chained"},e.prototype.next=function(){return s(this,void 0,void 0,function(){return u(this,function(t){return this.lastRead=this.readFromChain(this.lastRead),[2,this.lastRead]})})},e.prototype.readFromChain=function(t){return s(this,void 0,void 0,function(){var e,n;return u(this,function(r){switch(r.label){case 0:return[4,t];case 1:return r.sent(),null!=this.iterator?[3,3]:[4,this.moreIterators.next()];case 2:if((e=r.sent()).done)return[2,{value:null,done:!0}];this.iterator=e.value,null!=this.baseErrorHandler&&(this.iterator=this.iterator.handleErrors(this.baseErrorHandler)),r.label=3;case 3:return[4,this.iterator.next()];case 4:return(n=r.sent()).done?(this.iterator=null,[2,this.readFromChain(t)]):[2,n]}})})},e}(T);!function(t){t[t.FAIL=0]="FAIL",t[t.SHORTEST=1]="SHORTEST",t[t.LONGEST=2]="LONGEST"}(N||(N={}));var q=function(t){function e(e,n){void 0===n&&(n=N.FAIL);var r=t.call(this)||this;return r.iterators=e,r.mismatchMode=n,r.count=0,r.currentPromise=null,r}return o(e,t),e.prototype.summary=function(){return"{TODO: fill in upstream of zip summaries} -> Zip"},e.prototype.nextState=function(t){return s(this,void 0,void 0,function(){function e(t){return t instanceof T?{value:t.next().then(function(t){return n++,t.done&&r++,t.value}),recurse:!1}:{value:null,recurse:!0}}var n,r,i;return u(this,function(a){switch(a.label){case 0:return[4,t];case 1:return a.sent(),n=0,r=0,[4,w(this.iterators,e)];case 2:if(i=a.sent(),n===r)return[2,{value:null,done:!0}];if(r>0)switch(this.mismatchMode){case N.FAIL:throw new Error("Zipped streams should have the same length. Mismatched at element "+this.count+".");case N.SHORTEST:return[2,{value:null,done:!0}];case N.LONGEST:}return this.count++,[2,{value:i,done:!1}]}})})},e.prototype.next=function(){return s(this,void 0,void 0,function(){return u(this,function(t){return this.currentPromise=this.nextState(this.currentPromise),[2,this.currentPromise]})})},e}(T),H=function(t){function e(e,n){var r=t.call(this)||this;return r.upstream=e,r.bufferSize=n,r.buffer=new O(n),r}return o(e,t),e.prototype.summary=function(){return this.upstream.summary()+" -> Prefetch"},e.prototype.refill=function(){for(;!this.buffer.isFull();){var t=this.upstream.next();this.buffer.push(t)}},e.prototype.next=function(){return this.refill(),this.buffer.shift()},e}(T),G=function(t){function e(e,n,r){var a=t.call(this,e,n)||this;return a.upstream=e,a.windowSize=n,a.upstreamExhausted=!1,a.random=v(r||i.util.now().toString()),a.lastRead=Promise.resolve({value:null,done:!1}),a}return o(e,t),e.prototype.next=function(){return s(this,void 0,void 0,function(){var t=this;return u(this,function(e){return this.lastRead=this.lastRead.then(function(){return t.serialNext()}),[2,this.lastRead]})})},e.prototype.randomInt=function(t){return Math.floor(this.random()*t)},e.prototype.chooseIndex=function(){return this.randomInt(this.buffer.length())},e.prototype.serialNext=function(){return s(this,void 0,void 0,function(){var t,e;return u(this,function(n){switch(n.label){case 0:this.upstreamExhausted||this.refill(),n.label=1;case 1:return this.buffer.isEmpty()?[3,3]:(t=this.chooseIndex(),[4,this.buffer.shuffleExcise(t)]);case 2:return(e=n.sent()).done?(this.upstreamExhausted=!0,[3,1]):(this.refill(),[2,e]);case 3:return[2,{value:null,done:!0}]}})})},e}(H),$=function(){function t(){this.size=null}return t.prototype.batch=function(t,e){var n=this;void 0===e&&(e=!0);var r=this;return i.util.assert(t>0,function(){return"batchSize needs to be positive, but it is\n "+t}),K(function(){return s(n,void 0,void 0,function(){return u(this,function(n){switch(n.label){case 0:return[4,r.iterator()];case 1:return[2,n.sent().columnMajorBatch(t,e,J)]}})})},this.size===1/0||null==this.size?this.size:e?Math.ceil(this.size/t):Math.floor(this.size/t))},t.prototype.concatenate=function(t){var e=this,n=this;return K(function(){return s(e,void 0,void 0,function(){var e,r;return u(this,function(i){switch(i.label){case 0:return[4,n.iterator()];case 1:return r=(e=i.sent()).concatenate,[4,t.iterator()];case 2:return[2,r.apply(e,[i.sent()])]}})})},this.size===1/0||t.size===1/0?1/0:null!=this.size&&null!=t.size?this.size+t.size:null)},t.prototype.filter=function(t){var e=this,n=this;return K(function(){return s(e,void 0,void 0,function(){return u(this,function(e){switch(e.label){case 0:return[4,n.iterator()];case 1:return[2,e.sent().filter(function(e){return Object(i.tidy)(function(){return t(e)})})]}})})},this.size===1/0?1/0:null)},t.prototype.forEachAsync=function(t){return s(this,void 0,void 0,function(){return u(this,function(e){switch(e.label){case 0:return[4,this.iterator()];case 1:return[2,e.sent().forEachAsync(t)]}})})},t.prototype.forEach=function(t){return s(this,void 0,void 0,function(){return u(this,function(e){return Object(i.deprecationWarn)("dataset.forEach() is deprecated and will be removed. Please use dataset.forEachAsync() instead"),[2,this.forEachAsync(t)]})})},t.prototype.map=function(t){var e=this,n=this;return K(function(){return s(e,void 0,void 0,function(){return u(this,function(e){switch(e.label){case 0:return[4,n.iterator()];case 1:return[2,e.sent().map(function(e){return Object(i.tidy)(function(){return t(e)})})]}})})},this.size)},t.prototype.mapAsync=function(t){var e=this,n=this;return K(function(){return s(e,void 0,void 0,function(){return u(this,function(e){switch(e.label){case 0:return[4,n.iterator()];case 1:return[2,e.sent().mapAsync(t)]}})})},this.size)},t.prototype.prefetch=function(t){var e=this;if(null==t)throw new RangeError("`Dataset.prefetch()` requires bufferSize to be specified.");var n=this;return K(function(){return s(e,void 0,void 0,function(){return u(this,function(e){switch(e.label){case 0:return[4,n.iterator()];case 1:return[2,e.sent().prefetch(t)]}})})},this.size)},t.prototype.repeat=function(t){var e=this,n=this;return K(function(){return s(e,void 0,void 0,function(){var e=this;return u(this,function(r){return[2,function(t,e){return new V(t,e)}(A(function(){return s(e,void 0,void 0,function(){var t;return u(this,function(e){switch(e.label){case 0:return t={},[4,n.iterator()];case 1:return[2,(t.value=e.sent(),t.done=!1,t)]}})})}).take(t))]})})},null!=this.size&&t>0?this.size*t:0===t?0:null!=this.size&&(void 0===t||t<0)?1/0:null)},t.prototype.skip=function(t){var e=this,n=this;return K(function(){return s(e,void 0,void 0,function(){return u(this,function(e){switch(e.label){case 0:return[4,n.iterator()];case 1:return[2,e.sent().skip(t)]}})})},null!=this.size&&t>=0&&this.size>=t?this.size-t:null!=this.size&&(this.size<t||void 0===t||t<0)?0:null)},t.prototype.shuffle=function(t,e,n){var r=this;if(void 0===n&&(n=!0),null==t||t<0)throw null==this.size?new RangeError("`Dataset.shuffle()` requires bufferSize to be specified."):new RangeError("`Dataset.shuffle()` requires bufferSize to be specified. If your data fits in main memory (for regular JS objects), and/or GPU memory (for `tf.Tensor`s), consider setting bufferSize to the dataset size ("+this.size+" elements)");var a=this,o=v(e||i.util.now().toString());return K(function(){return s(r,void 0,void 0,function(){var e;return u(this,function(r){switch(r.label){case 0:return e=o.int32(),n&&(e+=o.int32()),[4,a.iterator()];case 1:return[2,r.sent().shuffle(t,e.toString())]}})})},this.size)},t.prototype.take=function(t){var e=this,n=this;return K(function(){return s(e,void 0,void 0,function(){return u(this,function(e){switch(e.label){case 0:return[4,n.iterator()];case 1:return[2,e.sent().take(t)]}})})},null!=this.size&&this.size>t?t:null!=this.size&&this.size<=t?this.size:null)},t.prototype.toArray=function(){return s(this,void 0,void 0,function(){return u(this,function(t){switch(t.label){case 0:if(this.size===1/0)throw new Error("Can not convert infinite data stream to array.");return[4,this.iterator()];case 1:return[2,t.sent().toArray()]}})})},t.prototype.toArrayForTest=function(){return s(this,void 0,void 0,function(){return u(this,function(t){switch(t.label){case 0:if(this.size===1/0)throw new Error("Can not convert infinite data stream to array.");return[4,this.iterator()];case 1:return[2,t.sent().toArrayForTest()]}})})},t.MAX_BUFFER_SIZE=1e4,t}();function K(t,e){return void 0===e&&(e=null),new(function(n){function r(){var t=null!==n&&n.apply(this,arguments)||this;return t.size=e,t}return o(r,n),r.prototype.iterator=function(){return s(this,void 0,void 0,function(){return u(this,function(e){return[2,t()]})})},r}($))}function X(t){var e=this;return K(function(){return s(e,void 0,void 0,function(){return u(this,function(e){return[2,C(t)]})})},t.length)}function Y(t){var e,n=this;if(!k(t))throw new Error("The argument to zip() must be an object or array.");if(Array.isArray(t))for(var r=0;r<t.length;r++)e=null==e?t[r].size:Math.min(e,t[r].size);else if(t instanceof Object)for(var i in t)e=null==e?t[i].size:Math.min(e,t[i].size);return K(function(){return s(n,void 0,void 0,function(){return u(this,function(e){switch(e.label){case 0:return[4,w(t,function(t){if(t instanceof $)return{value:t.iterator(),recurse:!1};if(k(t))return{value:null,recurse:!0};throw new Error("Leaves of the structure passed to zip() must be Datasets, not primitives.")})];case 1:return[2,function(t,e){return void 0===e&&(e=N.FAIL),new q(t,e)}(e.sent(),N.SHORTEST)]}})})},e)}function J(t){return null===t?null:function(t){return null==t||function(t){return null===t||"object"!=typeof t&&"function"!=typeof t}(t)||Array.isArray(t)||"object"==typeof t&&t instanceof i.Tensor||i.util.isTypedArray(t)}(t[0])?{value:function(t){if(0===t.length)throw new Error("Can't make a batch of zero elements.");return t[0]instanceof i.Tensor?Object(i.stack)(t):Object(i.tensor)(t)}(t),recurse:!1}:{value:null,recurse:!0}}var Z=function(t){function e(e){var n=t.call(this)||this;return n.input=e,n}return o(e,t),e.prototype.iterator=function(){return s(this,void 0,void 0,function(){var t;return u(this,function(e){switch(e.label){case 0:return[4,this.input.iterator()];case 1:return t=e.sent(),[2,t.decodeUTF8().split("\n").map(function(t){return t.endsWith("\r")&&(t=t.slice(0,-1)),t})]}})})},e}($),Q=Symbol("out"),tt=Symbol("field"),et=Symbol("quote"),nt=Symbol("quoteafterquote"),rt=Symbol("quoteinquote"),it=function(t){function e(e,n){var r=t.call(this)||this;return r.input=e,r.hasHeader=!0,r.fullColumnNames=null,r.columnNamesValidated=!1,r.columnConfigs=null,r.configuredColumnsOnly=!1,r.delimiter=",",r.delimWhitespace=!1,r.base=new Z(e),n||(n={}),r.hasHeader=!1!==n.hasHeader,r.fullColumnNames=n.columnNames,r.columnConfigs=n.columnConfigs,r.configuredColumnsOnly=n.configuredColumnsOnly,n.delimWhitespace?(i.util.assert(null==n.delimiter,function(){return"Delimiter should not be provided when delimWhitespace is true."}),r.delimWhitespace=!0,r.delimiter=" "):r.delimiter=n.delimiter?n.delimiter:",",r}return o(e,t),e.prototype.columnNames=function(){return s(this,void 0,void 0,function(){return u(this,function(t){switch(t.label){case 0:return this.columnNamesValidated?[3,2]:[4,this.setColumnNames()];case 1:t.sent(),t.label=2;case 2:return[2,this.configuredColumnsOnly?Object.keys(this.columnConfigs):this.fullColumnNames]}})})},e.prototype.setColumnNames=function(){return s(this,void 0,void 0,function(){var t,e,n,r,a,o,s=this;return u(this,function(u){switch(u.label){case 0:return[4,this.maybeReadHeaderLine()];case 1:if(t=u.sent(),!this.fullColumnNames&&!t)throw new Error("Column names must be provided if there is no header line.");if(this.fullColumnNames&&t&&i.util.assert(t.length===this.fullColumnNames.length,function(){return"The length of provided columnNames ("+s.fullColumnNames.length.toString()+") does not match the length of the header line read from file ("+t.length.toString()+")."}),this.fullColumnNames||(this.fullColumnNames=t),e=this.fullColumnNames.reduce(function(t,e){return t[e]=t[e]+1||1,t},{}),n=Object.keys(e).filter(function(t){return e[t]>1}),i.util.assert(0===n.length,function(){return"Duplicate column names found: "+n.toString()}),this.columnConfigs)for(r=0,a=Object.keys(this.columnConfigs);r<a.length;r++)if(o=a[r],-1===this.fullColumnNames.indexOf(o))throw new Error('The key "'+o+'" provided in columnConfigs does not match any of the column names ('+this.fullColumnNames.toString()+").");return this.columnNamesValidated=!0,[2]}})})},e.prototype.maybeReadHeaderLine=function(){return s(this,void 0,void 0,function(){var t,e;return u(this,function(n){switch(n.label){case 0:return this.hasHeader?[4,this.base.iterator()]:[3,3];case 1:return[4,n.sent().next()];case 2:if((t=n.sent()).done)throw new Error("No data was found for CSV parsing.");return e=t.value,[2,this.parseRow(e,!1)];case 3:return[2,null]}})})},e.prototype.iterator=function(){return s(this,void 0,void 0,function(){var t,e=this;return u(this,function(n){switch(n.label){case 0:return this.columnNamesValidated?[3,2]:[4,this.setColumnNames()];case 1:n.sent(),n.label=2;case 2:return[4,this.base.iterator()];case 3:return t=n.sent(),this.hasHeader&&(t=t.skip(1)),[2,t.map(function(t){return e.makeDataElement(t)})]}})})},e.prototype.makeDataElement=function(t){for(var e=this.parseRow(t),n={},r={},i=0;i<this.fullColumnNames.length;i++){var a=this.fullColumnNames[i],o=this.columnConfigs?this.columnConfigs[a]:null;if(!this.configuredColumnsOnly||o){var s=e[i],u=null;if(""===s)if(o&&void 0!==o.default)u=o.default;else{if(o&&(o.required||o.isLabel))throw new Error("Required column "+a+" is empty in this line: "+t);u=void 0}else{var c=Number(s);if(isNaN(c))u=o&&"bool"===o.dtype?this.getBoolean(s):s;else if(o&&o.dtype)switch(o.dtype){case"float32":u=c;break;case"int32":u=Math.floor(c);break;case"bool":u=this.getBoolean(s);break;default:u=c}else u=c}o&&o.isLabel?r[a]=u:n[a]=u}}return 0===Object.keys(r).length?n:{xs:n,ys:r}},e.prototype.getBoolean=function(t){return"1"===t||"true"===t.toLowerCase()?1:0},e.prototype.parseRow=function(t,e){void 0===e&&(e=!0);for(var n=[],r=0,i=t.length,a=Q,o=0;o<i;o++)switch(a){case Q:switch(t.charAt(o)){case'"':r=o+1,a=et;break;case this.delimiter:if(r=o+1," "===this.delimiter&&this.delimWhitespace)break;n.push(""),a=Q;break;default:a=tt,r=o}break;case tt:switch(t.charAt(o)){case this.delimiter:n.push(t.substring(r,o)),a=Q,r=o+1}break;case et:switch(t.charAt(o)){case'"':a=nt}break;case nt:switch(t.charAt(o)){case this.delimiter:n.push(t.substring(r,o-1)),a=Q,r=o+1;break;case'"':a=et;break;default:a=rt}break;case rt:switch(t.charAt(o)){case'"':a=et}}if(a===nt?n.push(t.substring(r,i-1)):n.push(t.substring(r)),e&&n.length!==this.fullColumnNames.length)throw new Error("Invalid row in csv file. Should have "+this.fullColumnNames.length+" elements in a row, but got "+n);return n},e}($),at=function(t){function e(e){var n=t.call(this)||this;n.microphoneConfig=e,n.isClosed=!1,n.fftSize=e.fftSize||1024;var r=Math.log2(n.fftSize);if(n.fftSize<0||r<4||r>14||!Number.isInteger(r))throw new Error("Invalid fftSize: it must be a power of 2 between 2 to 4 and 2 to 14, but got "+n.fftSize);if(n.numFrames=e.numFramesPerSpectrogram||43,n.sampleRateHz=e.sampleRateHz,n.columnTruncateLength=e.columnTruncateLength||n.fftSize,n.audioTrackConstraints=e.audioTrackConstraints,n.smoothingTimeConstant=e.smoothingTimeConstant||0,n.includeSpectrogram=!1!==e.includeSpectrogram,n.includeWaveform=!0===e.includeWaveform,!n.includeSpectrogram&&!n.includeWaveform)throw new Error("Both includeSpectrogram and includeWaveform are false. At least one type of data should be returned.");return n}return o(e,t),e.prototype.summary=function(){return"microphone"},e.create=function(t){return void 0===t&&(t={}),s(this,void 0,void 0,function(){var n;return u(this,function(r){switch(r.label){case 0:if(Object(i.env)().get("IS_NODE"))throw new Error("microphone API is only supported in browser environment.");return[4,(n=new e(t)).start()];case 1:return r.sent(),[2,n]}})})},e.prototype.start=function(){return s(this,void 0,void 0,function(){var t,e,n,r;return u(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),t=this,[4,navigator.mediaDevices.getUserMedia({audio:null==this.audioTrackConstraints||this.audioTrackConstraints,video:!1})];case 1:return t.stream=i.sent(),[3,3];case 2:throw e=i.sent(),new Error("Error thrown while initializing video stream: "+e.message);case 3:if(!this.stream)throw new Error("Could not obtain audio from microphone.");if(n=window.AudioContext||window.webkitAudioContext,this.audioContext=new n,this.sampleRateHz){if(this.audioContext.sampleRate!==this.sampleRateHz)throw new Error("Mismatch in sampling rate: Expected: "+this.sampleRateHz+"; Actual: "+this.audioContext.sampleRate)}else this.sampleRateHz=this.audioContext.sampleRate;return r=this.audioContext.createMediaStreamSource(this.stream),this.analyser=this.audioContext.createAnalyser(),this.analyser.fftSize=2*this.fftSize,this.analyser.smoothingTimeConstant=this.smoothingTimeConstant,r.connect(this.analyser),this.freqData=new Float32Array(this.fftSize),this.timeData=new Float32Array(this.fftSize),[2]}})})},e.prototype.next=function(){return s(this,void 0,void 0,function(){var t,e,n,r,i;return u(this,function(a){switch(a.label){case 0:return this.isClosed?[2,{value:null,done:!0}]:[4,this.getAudioData()];case 1:return n=a.sent(),this.includeSpectrogram&&(r=this.flattenQueue(n.freqDataQueue),t=this.getTensorFromAudioDataArray(r,[this.numFrames,this.columnTruncateLength,1])),this.includeWaveform&&(i=this.flattenQueue(n.timeDataQueue),e=this.getTensorFromAudioDataArray(i,[this.numFrames*this.fftSize,1])),[2,{value:{spectrogram:t,waveform:e},done:!1}]}})})},e.prototype.capture=function(){return s(this,void 0,void 0,function(){return u(this,function(t){switch(t.label){case 0:return[4,this.next()];case 1:return[2,t.sent().value]}})})},e.prototype.getAudioData=function(){return s(this,void 0,void 0,function(){var t,e,n,r=this;return u(this,function(i){return t=[],e=[],n=0,[2,new Promise(function(i){var a=setInterval(function(){r.includeSpectrogram&&(r.analyser.getFloatFrequencyData(r.freqData),r.freqData[0]===-1/0&&i({freqDataQueue:t,timeDataQueue:e}),t.push(r.freqData.slice(0,r.columnTruncateLength))),r.includeWaveform&&(r.analyser.getFloatTimeDomainData(r.timeData),e.push(r.timeData.slice())),++n===r.numFrames&&(clearInterval(a),i({freqDataQueue:t,timeDataQueue:e}))},r.fftSize/r.sampleRateHz*1e3)})]})})},e.prototype.stop=function(){this.isClosed||(this.isClosed=!0,this.analyser.disconnect(),this.audioContext.close(),null!=this.stream&&this.stream.getTracks().length>0&&this.stream.getTracks()[0].stop())},e.prototype.toArray=function(){throw new Error("Can not convert infinite audio stream to array.")},e.prototype.getSampleRate=function(){return this.sampleRateHz},e.prototype.flattenQueue=function(t){var e=t[0].length,n=new Float32Array(t.length*e);return t.forEach(function(t,r){return n.set(t,r*e)}),n},e.prototype.getTensorFromAudioDataArray=function(t,e){var n=new Float32Array(i.util.sizeFromShape(e));return n.set(t,n.length-t.length),Object(i.tensor)(n,e)},e}(T),ot=function(t){function e(e,n){var r=t.call(this)||this;if(r.webcamVideoElement=e,r.webcamConfig=n,r.isClosed=!0,r.resize=!1,r.needToResize())if(r.resize=!0,r.cropSize=[r.webcamConfig.resizeHeight,r.webcamConfig.resizeWidth],r.cropBoxInd=Object(i.tensor1d)([0],"int32"),r.webcamConfig.centerCrop){var a=1*r.webcamConfig.resizeWidth/r.webcamVideoElement.width,o=1*r.webcamConfig.resizeHeight/r.webcamVideoElement.height,s=(1-a)/2,u=(1-o)/2,c=s+a,l=o+u;r.cropBox=Object(i.tensor2d)([u,s,l,c],[1,4])}else r.cropBox=Object(i.tensor2d)([0,0,1,1],[1,4]);return r}return o(e,t),e.prototype.summary=function(){return"webcam"},e.create=function(t,n){return void 0===n&&(n={}),s(this,void 0,void 0,function(){var r;return u(this,function(a){switch(a.label){case 0:if(Object(i.env)().get("IS_NODE"))throw new Error("tf.data.webcam is only supported in browser environment.");if(!t){if(t=document.createElement("video"),!n.resizeWidth||!n.resizeHeight)throw new Error("Please provide webcam video element, or resizeWidth and resizeHeight to create a hidden video element.");t.width=n.resizeWidth,t.height=n.resizeHeight}return[4,(r=new e(t,n)).start()];case 1:return a.sent(),[2,r]}})})},e.prototype.start=function(){return s(this,void 0,void 0,function(){var t,e,n=this;return u(this,function(r){switch(r.label){case 0:this.webcamConfig.facingMode&&i.util.assert("user"===this.webcamConfig.facingMode||"environment"===this.webcamConfig.facingMode,function(){return"Invalid webcam facing mode: "+n.webcamConfig.facingMode+". Please provide 'user' or 'environment'"}),r.label=1;case 1:return r.trys.push([1,3,,4]),t=this,[4,navigator.mediaDevices.getUserMedia({video:{deviceId:this.webcamConfig.deviceId,facingMode:this.webcamConfig.facingMode?this.webcamConfig.facingMode:"user",width:this.webcamVideoElement.width,height:this.webcamVideoElement.height}})];case 2:return t.stream=r.sent(),[3,4];case 3:throw(e=r.sent()).message="Error thrown while initializing video stream: "+e.message,e;case 4:if(!this.stream)throw new Error("Could not obtain video from webcam.");try{this.webcamVideoElement.srcObject=this.stream}catch(t){console.log(t),this.webcamVideoElement.src=window.URL.createObjectURL(this.stream)}return this.webcamVideoElement.play(),this.isClosed=!1,[2,new Promise(function(t){n.webcamVideoElement.onloadedmetadata=function(){t()}})]}})})},e.prototype.next=function(){return s(this,void 0,void 0,function(){var t;return u(this,function(e){if(this.isClosed)return[2,{value:null,done:!0}];try{t=i.browser.fromPixels(this.webcamVideoElement)}catch(t){throw new Error("Error thrown converting video to pixels: "+JSON.stringify(t))}if(!this.resize)return[2,{value:t,done:!1}];try{return[2,{value:this.cropAndResizeFrame(t),done:!1}]}catch(t){throw new Error("Error thrown cropping the video: "+t.message)}finally{t.dispose()}return[2]})})},e.prototype.needToResize=function(){return!(!this.webcamConfig.resizeWidth||!this.webcamConfig.resizeHeight||this.webcamVideoElement.width===this.webcamConfig.resizeWidth&&this.webcamVideoElement.height===this.webcamConfig.resizeHeight)},e.prototype.cropAndResizeFrame=function(t){var e=this;return Object(i.tidy)(function(){var n,r=t.toFloat().expandDims(0),a=(n=i.image.cropAndResize(r,e.cropBox,e.cropBoxInd,e.cropSize,"bilinear")).shape;return n.reshape(a.slice(1))})},e.prototype.capture=function(){return s(this,void 0,void 0,function(){return u(this,function(t){switch(t.label){case 0:return[4,this.next()];case 1:return[2,t.sent().value]}})})},e.prototype.stop=function(){this.stream.getTracks().forEach(function(t){return t.stop()});try{this.webcamVideoElement.srcObject=null}catch(t){console.log(t),this.webcamVideoElement.src=null}this.isClosed=!0},e.prototype.toArray=function(){throw new Error("Can not convert infinite video stream to array.")},e}(T),st=function(){},ut=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),e.prototype.split=function(t){return new ct(this,t)},e}(T),ct=function(t){function e(e,n){var r=t.call(this)||this;return r.upstream=e,r.impl=new lt(e,n),r}return o(e,t),e.prototype.summary=function(){return this.impl.summary()},e.prototype.next=function(){return s(this,void 0,void 0,function(){return u(this,function(t){return[2,this.impl.next()]})})},e}(ut),lt=function(t){function e(e,n){var r=t.call(this)||this;return r.upstream=e,r.separator=n,r.carryover="",r}return o(e,t),e.prototype.summary=function(){return this.upstream.summary()+" -> Split('"+this.separator+"')"},e.prototype.pump=function(){return s(this,void 0,void 0,function(){var t,e,n,r,i;return u(this,function(a){switch(a.label){case 0:return[4,this.upstream.next()];case 1:if((t=a.sent()).done)return""===this.carryover?[2,!1]:(this.outputQueue.push(this.carryover),this.carryover="",[2,!0]);for((e=t.value.split(this.separator))[0]=this.carryover+e[0],n=0,r=e.slice(0,-1);n<r.length;n++)i=r[n],this.outputQueue.push(i);return this.carryover=e[e.length-1],[2,!0]}})})},e}(U),ft=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),e.prototype.decodeUTF8=function(){return new dt(this)},e}(T),dt=function(t){function e(e){var n=t.call(this)||this;return n.upstream=e,n.impl=new ht(e),n}return o(e,t),e.prototype.summary=function(){return this.impl.summary()},e.prototype.next=function(){return s(this,void 0,void 0,function(){return u(this,function(t){return[2,this.impl.next()]})})},e}(ut),ht=function(t){function e(e){var r=t.call(this)||this;if(r.upstream=e,Object(i.env)().get("IS_BROWSER"))r.decoder=new TextDecoder("utf-8");else{var a=n(476).StringDecoder;r.decoder=new a("utf8")}return r}return o(e,t),e.prototype.summary=function(){return this.upstream.summary()+" -> Utf8"},e.prototype.pump=function(){return s(this,void 0,void 0,function(){var t,e,n;return u(this,function(a){switch(a.label){case 0:return[4,this.upstream.next()];case 1:return(t=a.sent()).done?[2,!1]:(e=t.value,n=Object(i.env)().get("IS_BROWSER")?this.decoder.decode(e,{stream:!0}):this.decoder.write(r.from(e.buffer)),this.outputQueue.push(n),[2,!0])}})})},e}(U),pt=function(t){function e(e,n){void 0===n&&(n={});var r=t.call(this)||this;return r.file=e,r.options=n,i.util.assert(e instanceof Uint8Array||!!Object(i.env)().get("IS_BROWSER")&&(e instanceof File||e instanceof Blob),function(){return"FileChunkIterator only supports File, Blob and Uint8Array right now."}),r.offset=n.offset||0,r.chunkSize=n.chunkSize||1048576,r}return o(e,t),e.prototype.summary=function(){return"FileChunks "+this.file},e.prototype.next=function(){return s(this,void 0,void 0,function(){var t,e,n=this;return u(this,function(r){switch(r.label){case 0:return this.offset>=(this.file instanceof Uint8Array?this.file.byteLength:this.file.size)?[2,{value:null,done:!0}]:(t=new Promise(function(t,e){var r=n.offset+n.chunkSize;if(n.file instanceof Uint8Array)t(new Uint8Array(n.file.slice(n.offset,r)));else{var i=new FileReader;i.onload=function(n){var r=i.result;if(r instanceof ArrayBuffer&&(r=new Uint8Array(r)),!(r instanceof Uint8Array))return e(new TypeError("FileReader returned unknown type."));t(r)},i.onabort=function(t){return e(new Error("Aborted"))},i.onerror=function(t){return e(new Error(t.type))};var a=n.file.slice(n.offset,r);i.readAsArrayBuffer(a)}n.offset=r}),e={},[4,t]);case 1:return[2,(e.value=r.sent(),e.done=!1,e)]}})})},e}(ft);var mt=function(t){return{method:t.method,headers:t.headers,body:t.body,mode:t.mode,credentials:t.credentials,cache:t.cache,redirect:t.redirect,referrer:t.referrer,integrity:t.integrity}};function gt(t){return"string"==typeof t&&"file://"===t.substr(0,7)}var vt=function(t){function e(e,n){void 0===n&&(n={});var r=t.call(this)||this;return r.input=e,r.options=n,r}return o(e,t),e.prototype.iterator=function(){return s(this,void 0,void 0,function(){var t;return u(this,function(e){return gt(this.input)&&Object(i.env)().get("IS_NODE")&&(t=n(475),this.input=t.readFileSync(this.input.substr(7))),[2,new pt(this.input,this.options)]})})},e}(st),yt=function(t){function e(e,n){void 0===n&&(n={});var r=t.call(this)||this;return r.url=e,r.fileOptions=n,r}return o(e,t),e.prototype.iterator=function(){return s(this,void 0,void 0,function(){return u(this,function(t){return gt(this.url)?[2,new vt(this.url,this.fileOptions).iterator()]:[2,function(t,e){return void 0===e&&(e={}),s(this,void 0,void 0,function(){var n,r,a,o,s;return u(this,function(u){switch(u.label){case 0:return"string"==typeof t?n=t:(n=t.url,r=mt(t)),[4,i.util.fetch(n,r)];case 1:return(a=u.sent()).ok?(s=Uint8Array.bind,[4,a.arrayBuffer()]):[3,3];case 2:return o=new(s.apply(Uint8Array,[void 0,u.sent()])),[2,new pt(o,e)];case 3:throw new Error(a.statusText)}})})}(this.url,this.fileOptions)]})})},e}(st);function bt(t,e){return void 0===e&&(e={}),new it(new yt(t),e)}function xt(t){var e=this,n=A(t);return K(function(){return s(e,void 0,void 0,function(){return u(this,function(t){return[2,n]})})})}function wt(t){var e=this;return K(function(){return s(e,void 0,void 0,function(){var e;return u(this,function(n){switch(n.label){case 0:return[4,t()];case 1:return e=n.sent(),[2,A(function(){return e.next()})]}})})})}function kt(t,e){return s(this,void 0,void 0,function(){return u(this,function(n){return[2,ot.create(t,e)]})})}function _t(t){return s(this,void 0,void 0,function(){return u(this,function(e){return[2,at.create(t)]})})}var Et="1.7.2"}.call(this,n(53),n(86).Buffer)},function(t,e,n){"use strict";function r(t){var e="";if(!t)try{t=n(210)}catch(t){e=t.toString()}return{readFile:t?function(e){return new Promise(function(n,r){t.readFile(e,function(t,e){return t?r(t):n(e)})})}:function(){throw new Error("readFile - failed to require fs in nodejs environment with error: "+e)}}}n.d(e,"a",function(){return r})},function(t,e,n){"use strict";(function(t){n.d(e,"a",function(){return i});var r=n(1);function i(e,n){const i=n&&n.property?Object(r.t)(n.property):r.x;return Object(r.F)(e)&&!function(e){return!("function"!=typeof t||!Object(r.D)(t.isBuffer))&&t.isBuffer(e)}(e)?function(t,e){return e&&e.copy?JSON.parse(JSON.stringify(t)):t}(i(e)):i(JSON.parse(e))}i.responseType="json"}).call(this,n(86).Buffer)},function(t,e,n){"use strict";var r=/("(?:[^\\"]|\\.)*")|[:,]/g;t.exports=function(t,e){var n,i,a;return e=e||{},n=JSON.stringify([1],void 0,void 0===e.indent?2:e.indent).slice(2,-3),i=""===n?1/0:void 0===e.maxLength?80:e.maxLength,a=e.replacer,function t(e,o,s){var u,c,l,f,d,h,p,m,g,v,y,b;if(e&&"function"==typeof e.toJSON&&(e=e.toJSON()),void 0===(y=JSON.stringify(e,a)))return y;if(p=i-o.length-s,y.length<=p&&(g=y.replace(r,function(t,e){return e||t+" "})).length<=p)return g;if(null!=a&&(e=JSON.parse(y),a=void 0),"object"==typeof e&&null!==e){if(m=o+n,l=[],c=0,Array.isArray(e))for(v="[",u="]",p=e.length;c<p;c++)l.push(t(e[c],m,c===p-1?0:1)||"null");else for(v="{",u="}",p=(h=Object.keys(e)).length;c<p;c++)f=h[c],d=JSON.stringify(f)+": ",void 0!==(b=t(e[f],m,d.length+(c===p-1?0:1)))&&l.push(d+b);if(l.length>0)return[v,n+l.join(",\n"+m),u].join("\n"+o)}return y}(t,"",0)}},function(t,e,n){"use strict";var r,i="object"==typeof Reflect?Reflect:null,a=i&&"function"==typeof i.apply?i.apply:function(t,e,n){return Function.prototype.apply.call(t,e,n)};r=i&&"function"==typeof i.ownKeys?i.ownKeys:Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:function(t){return Object.getOwnPropertyNames(t)};var o=Number.isNaN||function(t){return t!=t};function s(){s.init.call(this)}t.exports=s,s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var u=10;function c(t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}function l(t){return void 0===t._maxListeners?s.defaultMaxListeners:t._maxListeners}function f(t,e,n,r){var i,a,o;if(c(n),void 0===(a=t._events)?(a=t._events=Object.create(null),t._eventsCount=0):(void 0!==a.newListener&&(t.emit("newListener",e,n.listener?n.listener:n),a=t._events),o=a[e]),void 0===o)o=a[e]=n,++t._eventsCount;else if("function"==typeof o?o=a[e]=r?[n,o]:[o,n]:r?o.unshift(n):o.push(n),(i=l(t))>0&&o.length>i&&!o.warned){o.warned=!0;var s=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");s.name="MaxListenersExceededWarning",s.emitter=t,s.type=e,s.count=o.length,function(t){console&&console.warn&&console.warn(t)}(s)}return t}function d(t,e,n){var r={fired:!1,wrapFn:void 0,target:t,type:e,listener:n},i=function(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}.bind(r);return i.listener=n,r.wrapFn=i,i}function h(t,e,n){var r=t._events;if(void 0===r)return[];var i=r[e];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]:n?function(t){for(var e=new Array(t.length),n=0;n<e.length;++n)e[n]=t[n].listener||t[n];return e}(i):m(i,i.length)}function p(t){var e=this._events;if(void 0!==e){var n=e[t];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function m(t,e){for(var n=new Array(e),r=0;r<e;++r)n[r]=t[r];return n}Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return u},set:function(t){if("number"!=typeof t||t<0||o(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");u=t}}),s.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},s.prototype.setMaxListeners=function(t){if("number"!=typeof t||t<0||o(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this},s.prototype.getMaxListeners=function(){return l(this)},s.prototype.emit=function(t){for(var e=[],n=1;n<arguments.length;n++)e.push(arguments[n]);var r="error"===t,i=this._events;if(void 0!==i)r=r&&void 0===i.error;else if(!r)return!1;if(r){var o;if(e.length>0&&(o=e[0]),o instanceof Error)throw o;var s=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw s.context=o,s}var u=i[t];if(void 0===u)return!1;if("function"==typeof u)a(u,this,e);else{var c=u.length,l=m(u,c);for(n=0;n<c;++n)a(l[n],this,e)}return!0},s.prototype.addListener=function(t,e){return f(this,t,e,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(t,e){return f(this,t,e,!0)},s.prototype.once=function(t,e){return c(e),this.on(t,d(this,t,e)),this},s.prototype.prependOnceListener=function(t,e){return c(e),this.prependListener(t,d(this,t,e)),this},s.prototype.removeListener=function(t,e){var n,r,i,a,o;if(c(e),void 0===(r=this._events))return this;if(void 0===(n=r[t]))return this;if(n===e||n.listener===e)0==--this._eventsCount?this._events=Object.create(null):(delete r[t],r.removeListener&&this.emit("removeListener",t,n.listener||e));else if("function"!=typeof n){for(i=-1,a=n.length-1;a>=0;a--)if(n[a]===e||n[a].listener===e){o=n[a].listener,i=a;break}if(i<0)return this;0===i?n.shift():function(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}(n,i),1===n.length&&(r[t]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",t,o||e)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(t){var e,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[t]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[t]),this;if(0===arguments.length){var i,a=Object.keys(n);for(r=0;r<a.length;++r)"removeListener"!==(i=a[r])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(e=n[t]))this.removeListener(t,e);else if(void 0!==e)for(r=e.length-1;r>=0;r--)this.removeListener(t,e[r]);return this},s.prototype.listeners=function(t){return h(this,t,!0)},s.prototype.rawListeners=function(t){return h(this,t,!1)},s.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):p.call(t,e)},s.prototype.listenerCount=p,s.prototype.eventNames=function(){return this._eventsCount>0?r(this._events):[]}},function(t,e,n){"use strict";function r(t){return!!new RegExp("^(?:[a-z]+:)?//","i").test(t)}Object.defineProperty(e,"__esModule",{value:!0}),e.default={isAbsoluteURL:r,getModelPath:function(t){return r(t)?t:window.location.pathname+t}}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=c(n(9)),i=c(n(24)),a=c(n(8)),o=c(n(14)),s=c(n(7)),u=c(n(10));function c(t){return t&&t.__esModule?t:{default:t}}var l=function(){function t(e,n){(0,s.default)(this,t),this.videoElt=null,this.size=n,this.videoReady=!1,e instanceof HTMLVideoElement?this.videoElt=e:null!==e&&"object"===(void 0===e?"undefined":(0,o.default)(e))&&e.elt instanceof HTMLVideoElement&&(this.videoElt=e.elt)}return(0,u.default)(t,[{key:"loadVideo",value:function(){var t=(0,a.default)(r.default.mark(function t(){var e,n=this;return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=void 0,t.abrupt("return",new i.default(function(t){n.video=document.createElement("video");var r=navigator.userAgent;e=r.indexOf("Firefox")>-1?n.videoElt.mozCaptureStream():n.videoElt.captureStream(),n.video.srcObject=e,n.video.width=n.size,n.video.height=n.size,n.video.autoplay=!0,n.video.playsinline=!0,n.video.muted=!0;var i=n.video.play();void 0!==i&&i.then(function(){t(n.video)})}));case 2:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()}]),t}();e.default=l},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.getTopKClassesFromTensor=void 0;var r=o(n(9)),i=o(n(8)),a=e.getTopKClassesFromTensor=function(){var t=(0,i.default)(r.default.mark(function t(e,n,i){var a;return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.data();case 2:return a=t.sent,t.abrupt("return",s(a,n,i));case 4:case"end":return t.stop()}},t,this)}));return function(e,n,r){return t.apply(this,arguments)}}();function o(t){return t&&t.__esModule?t:{default:t}}function s(t,e,n){for(var r=[],i=0;i<t.length;i+=1)r.push({value:t[i],index:i});r.sort(function(t,e){return e.value-t.value});for(var a=new Float32Array(e),o=new Int32Array(e),s=0;s<e;s+=1)a[s]=r[s].value,o[s]=r[s].index;for(var u=[],c=0;c<o.length;c+=1)u.push({className:n[o[c]],probability:a[c]});return u}e.getTopKClassesFromArray=s,e.default={getTopKClassesFromArray:s,getTopKClassesFromTensor:a}},function(t,e,n){var r=n(26),i=n(18),a=n(106),o=n(147),s=n(39).f;t.exports=function(t){var e=i.Symbol||(i.Symbol=a?{}:r.Symbol||{});"_"==t.charAt(0)||t in e||s(e,t,{value:o.f(t)})}},function(t,e,n){var r=n(121)("meta"),i=n(38),a=n(68),o=n(39).f,s=0,u=Object.isExtensible||function(){return!0},c=!n(69)(function(){return u(Object.preventExtensions({}))}),l=function(t){o(t,r,{value:{i:"O"+ ++s,w:{}}})},f=t.exports={KEY:r,NEED:!1,fastKey:function(t,e){if(!i(t))return"symbol"==typeof t?t:("string"==typeof t?"S":"P")+t;if(!a(t,r)){if(!u(t))return"F";if(!e)return"E";l(t)}return t[r].i},getWeak:function(t,e){if(!a(t,r)){if(!u(t))return!0;if(!e)return!1;l(t)}return t[r].w},onFreeze:function(t){return c&&f.NEED&&u(t)&&!a(t,r)&&l(t),t}}},function(t,e,n){e.f=n(25)},function(t,e,n){var r=n(60);t.exports=function(t,e,n){for(var i in e)n&&t[i]?t[i]=e[i]:r(t,i,e[i]);return t}},function(t,e,n){"use strict";var r=n(109);t.exports.f=function(t){return new function(t){var e,n;this.promise=new t(function(t,r){if(void 0!==e||void 0!==n)throw TypeError("Bad Promise constructor");e=t,n=r}),this.resolve=r(e),this.reject=r(n)}(t)}},function(t,e,n){var r=n(116),i=n(25)("iterator"),a=n(84);t.exports=n(18).getIteratorMethod=function(t){if(void 0!=t)return t[i]||t["@@iterator"]||a[r(t)]}},function(t,e){t.exports=function(t,e,n,r){if(!(t instanceof e)||void 0!==r&&r in t)throw TypeError(n+": incorrect invocation!");return t}},function(t,e,n){"use strict";var r=n(106),i=n(23),a=n(234),o=n(60),s=n(84),u=n(423),c=n(102),l=n(232),f=n(25)("iterator"),d=!([].keys&&"next"in[].keys()),h=function(){return this};t.exports=function(t,e,n,p,m,g,v){u(n,e,p);var y,b,x,w=function(t){if(!d&&t in O)return O[t];switch(t){case"keys":case"values":return function(){return new n(this,t)}}return function(){return new n(this,t)}},k=e+" Iterator",_="values"==m,E=!1,O=t.prototype,S=O[f]||O["@@iterator"]||m&&O[m],C=S||w(m),A=m?_?w("entries"):C:void 0,N="Array"==e&&O.entries||S;if(N&&(x=l(N.call(new t)))!==Object.prototype&&x.next&&(c(x,k,!0),r||"function"==typeof x[f]||o(x,f,h)),_&&S&&"values"!==S.name&&(E=!0,C=function(){return S.call(this)}),r&&!v||!d&&!E&&O[f]||o(O,f,C),s[e]=C,s[k]=h,m)if(y={values:_?C:w("values"),keys:g?C:w("keys"),entries:A},v)for(b in y)b in O||a(O,b,y[b]);else i(i.P+i.F*(d||E),e,y);return y}},function(t,e){},function(t,e,n){"use strict";
  185. /**
  186. * @license
  187. * Copyright 2018 Google LLC. All Rights Reserved.
  188. * Licensed under the Apache License, Version 2.0 (the "License");
  189. * you may not use this file except in compliance with the License.
  190. * You may obtain a copy of the License at
  191. *
  192. * http://www.apache.org/licenses/LICENSE-2.0
  193. *
  194. * Unless required by applicable law or agreed to in writing, software
  195. * distributed under the License is distributed on an "AS IS" BASIS,
  196. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  197. * See the License for the specific language governing permissions and
  198. * limitations under the License.
  199. * =============================================================================
  200. */var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})},i=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const a=n(45),o=i(n(82)),s=n(59),u=n(119),c=n(118),l={maxBins:12,fontSize:11};e.histogram=function(t,e,n={}){return r(this,void 0,void 0,function*(){const r=function(t){if(null==t.length)throw new Error("input data must be an array");if(0===t.length)return[];if("object"==typeof t[0]){if(null==t[0].value)throw new Error("input data must have a value field");return t}{const e=Array(t.length);for(let n=0;n<t.length;n++)e[n]={value:t[n]};return e}}(e),i=Object.assign({},l,n),f=s.subSurface(t,"histogram");if(!1!==n.stats){const e=s.subSurface(t,"stats",{prepend:!0});let o;!function(t,e,n){const r=a.format(",.4~f"),i=a.format(".4~p"),o=[],s=[];if(null!=t.numVals&&(o.push("Num Vals"),s.push(r(t.numVals))),null!=t.min&&(o.push("Min"),s.push(r(t.min))),null!=t.max&&(o.push("Max"),s.push(r(t.max))),null!=t.numZeros){o.push("# Zeros");let e="";t.numVals&&(e=t.numZeros>0?`(${i(t.numZeros/t.numVals)})`:""),s.push(`${r(t.numZeros)} ${e}`)}if(null!=t.numNans){o.push("# NaNs");let e="";t.numVals&&(e=t.numNans>0?`(${i(t.numNans/t.numVals)})`:""),s.push(`${r(t.numNans)} ${e}`)}if(null!=t.numInfs){o.push("# Infinity");let e="";t.numVals&&(e=t.numInfs>0?`(${i(t.numInfs/t.numVals)})`:""),s.push(`${r(t.numInfs)} ${e}`)}c.table(e,{headers:o,values:[s]},n)}(o=n.stats?n.stats:u.arrayStats(r.map(t=>t.value)),e,{fontSize:i.fontSize})}const d=[];for(let t=0;t<r.length;t++){const e=r[t].value;null!=e&&isFinite(e)&&d.push(r[t])}const h={width:i.width||s.getDefaultWidth(f),height:i.height||s.getDefaultHeight(f),padding:0,autosize:{type:"fit",contains:"padding",resize:!0},data:{values:d},mark:{type:"bar",tooltip:!0},config:{axis:{labelFontSize:i.fontSize,titleFontSize:i.fontSize},text:{fontSize:i.fontSize},legend:{labelFontSize:i.fontSize,titleFontSize:i.fontSize}},encoding:{x:{bin:{maxbins:i.maxBins},field:"value",type:"quantitative"},y:{aggregate:"count",type:"quantitative"},color:{value:i.color||"#001B44"}}};return o.default(f,h,{actions:!1,mode:"vega-lite",defaultStyle:!1})})}},function(t,e,n){"use strict";n.r(e),n.d(e,"h",function(){return o}),n.d(e,"createElement",function(){return o}),n.d(e,"cloneElement",function(){return c}),n.d(e,"Component",function(){return F}),n.d(e,"render",function(){return j}),n.d(e,"rerender",function(){return h}),n.d(e,"options",function(){return r});var r={},i=[],a=[];function o(t,e){var n,o,s,u,c=a;for(u=arguments.length;u-- >2;)i.push(arguments[u]);for(e&&null!=e.children&&(i.length||i.push(e.children),delete e.children);i.length;)if((o=i.pop())&&void 0!==o.pop)for(u=o.length;u--;)i.push(o[u]);else"boolean"==typeof o&&(o=null),(s="function"!=typeof t)&&(null==o?o="":"number"==typeof o?o=String(o):"string"!=typeof o&&(s=!1)),s&&n?c[c.length-1]+=o:c===a?c=[o]:c.push(o),n=s;var l=new function(){};return l.nodeName=t,l.children=c,l.attributes=null==e?void 0:e,l.key=null==e?void 0:e.key,void 0!==r.vnode&&r.vnode(l),l}function s(t,e){for(var n in e)t[n]=e[n];return t}var u="function"==typeof Promise?Promise.resolve().then.bind(Promise.resolve()):setTimeout;function c(t,e){return o(t.nodeName,s(s({},t.attributes),e),arguments.length>2?[].slice.call(arguments,2):t.children)}var l=/acit|ex(?:s|g|n|p|$)|rph|ows|mnc|ntw|ine[ch]|zoo|^ord/i,f=[];function d(t){!t._dirty&&(t._dirty=!0)&&1==f.push(t)&&(r.debounceRendering||u)(h)}function h(){var t,e=f;for(f=[];t=e.pop();)t._dirty&&M(t)}function p(t,e,n){return"string"==typeof e||"number"==typeof e?void 0!==t.splitText:"string"==typeof e.nodeName?!t._componentConstructor&&m(t,e.nodeName):n||t._componentConstructor===e.nodeName}function m(t,e){return t.normalizedNodeName===e||t.nodeName.toLowerCase()===e.toLowerCase()}function g(t){var e=s({},t.attributes);e.children=t.children;var n=t.nodeName.defaultProps;if(void 0!==n)for(var r in n)void 0===e[r]&&(e[r]=n[r]);return e}function v(t){var e=t.parentNode;e&&e.removeChild(t)}function y(t,e,n,r,i){if("className"===e&&(e="class"),"key"===e);else if("ref"===e)n&&n(null),r&&r(t);else if("class"!==e||i)if("style"===e){if(r&&"string"!=typeof r&&"string"!=typeof n||(t.style.cssText=r||""),r&&"object"==typeof r){if("string"!=typeof n)for(var a in n)a in r||(t.style[a]="");for(var a in r)t.style[a]="number"==typeof r[a]&&!1===l.test(a)?r[a]+"px":r[a]}}else if("dangerouslySetInnerHTML"===e)r&&(t.innerHTML=r.__html||"");else if("o"==e[0]&&"n"==e[1]){var o=e!==(e=e.replace(/Capture$/,""));e=e.toLowerCase().substring(2),r?n||t.addEventListener(e,b,o):t.removeEventListener(e,b,o),(t._listeners||(t._listeners={}))[e]=r}else if("list"!==e&&"type"!==e&&!i&&e in t)!function(t,e,n){try{t[e]=n}catch(t){}}(t,e,null==r?"":r),null!=r&&!1!==r||t.removeAttribute(e);else{var s=i&&e!==(e=e.replace(/^xlink:?/,""));null==r||!1===r?s?t.removeAttributeNS("http://www.w3.org/1999/xlink",e.toLowerCase()):t.removeAttribute(e):"function"!=typeof r&&(s?t.setAttributeNS("http://www.w3.org/1999/xlink",e.toLowerCase(),r):t.setAttribute(e,r))}else t.className=r||""}function b(t){return this._listeners[t.type](r.event&&r.event(t)||t)}var x=[],w=0,k=!1,_=!1;function E(){for(var t;t=x.pop();)r.afterMount&&r.afterMount(t),t.componentDidMount&&t.componentDidMount()}function O(t,e,n,r,i,a){w++||(k=null!=i&&void 0!==i.ownerSVGElement,_=null!=t&&!("__preactattr_"in t));var o=S(t,e,n,r,a);return i&&o.parentNode!==i&&i.appendChild(o),--w||(_=!1,a||E()),o}function S(t,e,n,r,i){var a=t,o=k;if(null!=e&&"boolean"!=typeof e||(e=""),"string"==typeof e||"number"==typeof e)return t&&void 0!==t.splitText&&t.parentNode&&(!t._component||i)?t.nodeValue!=e&&(t.nodeValue=e):(a=document.createTextNode(e),t&&(t.parentNode&&t.parentNode.replaceChild(a,t),C(t,!0))),a.__preactattr_=!0,a;var s=e.nodeName;if("function"==typeof s)return function(t,e,n,r){var i=t&&t._component,a=i,o=t,s=i&&t._componentConstructor===e.nodeName,u=s,c=g(e);for(;i&&!u&&(i=i._parentComponent);)u=i.constructor===e.nodeName;i&&u&&(!r||i._component)?(D(i,c,3,n,r),t=i.base):(a&&!s&&(R(a),t=o=null),i=T(e.nodeName,c,n),t&&!i.nextBase&&(i.nextBase=t,o=null),D(i,c,1,n,r),t=i.base,o&&t!==o&&(o._component=null,C(o,!1)));return t}(t,e,n,r);if(k="svg"===s||"foreignObject"!==s&&k,s=String(s),(!t||!m(t,s))&&(a=function(t,e){var n=e?document.createElementNS("http://www.w3.org/2000/svg",t):document.createElement(t);return n.normalizedNodeName=t,n}(s,k),t)){for(;t.firstChild;)a.appendChild(t.firstChild);t.parentNode&&t.parentNode.replaceChild(a,t),C(t,!0)}var u=a.firstChild,c=a.__preactattr_,l=e.children;if(null==c){c=a.__preactattr_={};for(var f=a.attributes,d=f.length;d--;)c[f[d].name]=f[d].value}return!_&&l&&1===l.length&&"string"==typeof l[0]&&null!=u&&void 0!==u.splitText&&null==u.nextSibling?u.nodeValue!=l[0]&&(u.nodeValue=l[0]):(l&&l.length||null!=u)&&function(t,e,n,r,i){var a,o,s,u,c,l=t.childNodes,f=[],d={},h=0,m=0,g=l.length,y=0,b=e?e.length:0;if(0!==g)for(var x=0;x<g;x++){var w=l[x],k=w.__preactattr_,_=b&&k?w._component?w._component.__key:k.key:null;null!=_?(h++,d[_]=w):(k||(void 0!==w.splitText?!i||w.nodeValue.trim():i))&&(f[y++]=w)}if(0!==b)for(var x=0;x<b;x++){u=e[x],c=null;var _=u.key;if(null!=_)h&&void 0!==d[_]&&(c=d[_],d[_]=void 0,h--);else if(!c&&m<y)for(a=m;a<y;a++)if(void 0!==f[a]&&p(o=f[a],u,i)){c=o,f[a]=void 0,a===y-1&&y--,a===m&&m++;break}c=S(c,u,n,r),s=l[x],c&&c!==t&&c!==s&&(null==s?t.appendChild(c):c===s.nextSibling?v(s):t.insertBefore(c,s))}if(h)for(var x in d)void 0!==d[x]&&C(d[x],!1);for(;m<=y;)void 0!==(c=f[y--])&&C(c,!1)}(a,l,n,r,_||null!=c.dangerouslySetInnerHTML),function(t,e,n){var r;for(r in n)e&&null!=e[r]||null==n[r]||y(t,r,n[r],n[r]=void 0,k);for(r in e)"children"===r||"innerHTML"===r||r in n&&e[r]===("value"===r||"checked"===r?t[r]:n[r])||y(t,r,n[r],n[r]=e[r],k)}(a,e.attributes,c),k=o,a}function C(t,e){var n=t._component;n?R(n):(null!=t.__preactattr_&&t.__preactattr_.ref&&t.__preactattr_.ref(null),!1!==e&&null!=t.__preactattr_||v(t),A(t))}function A(t){for(t=t.lastChild;t;){var e=t.previousSibling;C(t,!0),t=e}}var N={};function T(t,e,n){var r,i=N[t.name];if(t.prototype&&t.prototype.render?(r=new t(e,n),F.call(r,e,n)):((r=new F(e,n)).constructor=t,r.render=I),i)for(var a=i.length;a--;)if(i[a].constructor===t){r.nextBase=i[a].nextBase,i.splice(a,1);break}return r}function I(t,e,n){return this.constructor(t,n)}function D(t,e,n,i,a){t._disable||(t._disable=!0,(t.__ref=e.ref)&&delete e.ref,(t.__key=e.key)&&delete e.key,!t.base||a?t.componentWillMount&&t.componentWillMount():t.componentWillReceiveProps&&t.componentWillReceiveProps(e,i),i&&i!==t.context&&(t.prevContext||(t.prevContext=t.context),t.context=i),t.prevProps||(t.prevProps=t.props),t.props=e,t._disable=!1,0!==n&&(1!==n&&!1===r.syncComponentUpdates&&t.base?d(t):M(t,1,a)),t.__ref&&t.__ref(t))}function M(t,e,n,i){if(!t._disable){var a,o,u,c=t.props,l=t.state,f=t.context,d=t.prevProps||c,h=t.prevState||l,p=t.prevContext||f,m=t.base,v=t.nextBase,y=m||v,b=t._component,k=!1;if(m&&(t.props=d,t.state=h,t.context=p,2!==e&&t.shouldComponentUpdate&&!1===t.shouldComponentUpdate(c,l,f)?k=!0:t.componentWillUpdate&&t.componentWillUpdate(c,l,f),t.props=c,t.state=l,t.context=f),t.prevProps=t.prevState=t.prevContext=t.nextBase=null,t._dirty=!1,!k){a=t.render(c,l,f),t.getChildContext&&(f=s(s({},f),t.getChildContext()));var _,S,A=a&&a.nodeName;if("function"==typeof A){var N=g(a);(o=b)&&o.constructor===A&&N.key==o.__key?D(o,N,1,f,!1):(_=o,t._component=o=T(A,N,f),o.nextBase=o.nextBase||v,o._parentComponent=t,D(o,N,0,f,!1),M(o,1,n,!0)),S=o.base}else u=y,(_=b)&&(u=t._component=null),(y||1===e)&&(u&&(u._component=null),S=O(u,a,f,n||!m,y&&y.parentNode,!0));if(y&&S!==y&&o!==b){var I=y.parentNode;I&&S!==I&&(I.replaceChild(S,y),_||(y._component=null,C(y,!1)))}if(_&&R(_),t.base=S,S&&!i){for(var F=t,j=t;j=j._parentComponent;)(F=j).base=S;S._component=F,S._componentConstructor=F.constructor}}if(!m||n?x.unshift(t):k||(t.componentDidUpdate&&t.componentDidUpdate(d,h,p),r.afterUpdate&&r.afterUpdate(t)),null!=t._renderCallbacks)for(;t._renderCallbacks.length;)t._renderCallbacks.pop().call(t);w||i||E()}}function R(t){r.beforeUnmount&&r.beforeUnmount(t);var e=t.base;t._disable=!0,t.componentWillUnmount&&t.componentWillUnmount(),t.base=null;var n=t._component;n?R(n):e&&(e.__preactattr_&&e.__preactattr_.ref&&e.__preactattr_.ref(null),t.nextBase=e,v(e),function(t){var e=t.constructor.name;(N[e]||(N[e]=[])).push(t)}(t),A(e)),t.__ref&&t.__ref(null)}function F(t,e){this._dirty=!0,this.context=e,this.props=t,this.state=this.state||{}}function j(t,e,n){return O(n,t,{},!1,e,!1)}s(F.prototype,{setState:function(t,e){var n=this.state;this.prevState||(this.prevState=s({},n)),s(n,"function"==typeof t?t(n,this.props):t),e&&(this._renderCallbacks=this._renderCallbacks||[]).push(e),d(this)},forceUpdate:function(t){t&&(this._renderCallbacks=this._renderCallbacks||[]).push(t),M(this,2)},render:function(){}});var P={h:o,createElement:o,cloneElement:c,Component:F,render:j,rerender:h,options:r};e.default=P},function(t,e,n){"use strict";
  201. /*
  202. object-assign
  203. (c) Sindre Sorhus
  204. @license MIT
  205. */var r=Object.getOwnPropertySymbols,i=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable;t.exports=function(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},n=0;n<10;n++)e["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(e).map(function(t){return e[t]}).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach(function(t){r[t]=t}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(t){return!1}}()?Object.assign:function(t,e){for(var n,o,s=function(t){if(null===t||void 0===t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}(t),u=1;u<arguments.length;u++){for(var c in n=Object(arguments[u]))i.call(n,c)&&(s[c]=n[c]);if(r){o=r(n);for(var l=0;l<o.length;l++)a.call(n,o[l])&&(s[o[l]]=n[o[l]])}}return s}},function(t,e){e.f=Object.getOwnPropertySymbols},function(t,e){t.exports="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")},function(t,e,n){var r=n(18),i=n(26),a=i["__core-js_shared__"]||(i["__core-js_shared__"]={});(t.exports=function(t,e){return a[t]||(a[t]=void 0!==e?e:{})})("versions",[]).push({version:r.version,mode:n(106)?"pure":"global",copyright:"© 2019 Denis Pushkarev (zloirock.ru)"})},function(t,e,n){var r=n(159)("keys"),i=n(121);t.exports=function(t){return r[t]||(r[t]=i(t))}},function(t,e){var n=Math.ceil,r=Math.floor;t.exports=function(t){return isNaN(t=+t)?0:(t>0?r:n)(t)}},function(t,e){t.exports=function(t){if(void 0==t)throw TypeError("Can't call method on "+t);return t}},function(t,e,n){var r=n(107);t.exports=Object("z").propertyIsEnumerable(0)?Object:function(t){return"String"==r(t)?t.split(""):Object(t)}},function(t,e,n){var r=n(38);t.exports=function(t,e){if(!r(t))return t;var n,i;if(e&&"function"==typeof(n=t.toString)&&!r(i=n.call(t)))return i;if("function"==typeof(n=t.valueOf)&&!r(i=n.call(t)))return i;if(!e&&"function"==typeof(n=t.toString)&&!r(i=n.call(t)))return i;throw TypeError("Can't convert object to primitive value")}},function(t,e,n){var r=n(38),i=n(26).document,a=r(i)&&r(i.createElement);t.exports=function(t){return a?i.createElement(t):{}}},function(t,e,n){"use strict";var r=n(11),i=n(19),a=n(63),o=n(126),s=n(31),u=n(71),c=n(12),l=n(73),f=n(41),d=n(17),h=n(254),p=n(75).f,m=n(21).f,g=n(173),v=n(94),y="prototype",b="Wrong index!",x=r.ArrayBuffer,w=r.DataView,k=r.Math,_=r.RangeError,E=r.Infinity,O=x,S=k.abs,C=k.pow,A=k.floor,N=k.log,T=k.LN2,I=i?"_b":"buffer",D=i?"_l":"byteLength",M=i?"_o":"byteOffset";function R(t,e,n){var r,i,a,o=new Array(n),s=8*n-e-1,u=(1<<s)-1,c=u>>1,l=23===e?C(2,-24)-C(2,-77):0,f=0,d=t<0||0===t&&1/t<0?1:0;for((t=S(t))!=t||t===E?(i=t!=t?1:0,r=u):(r=A(N(t)/T),t*(a=C(2,-r))<1&&(r--,a*=2),(t+=r+c>=1?l/a:l*C(2,1-c))*a>=2&&(r++,a/=2),r+c>=u?(i=0,r=u):r+c>=1?(i=(t*a-1)*C(2,e),r+=c):(i=t*C(2,c-1)*C(2,e),r=0));e>=8;o[f++]=255&i,i/=256,e-=8);for(r=r<<e|i,s+=e;s>0;o[f++]=255&r,r/=256,s-=8);return o[--f]|=128*d,o}function F(t,e,n){var r,i=8*n-e-1,a=(1<<i)-1,o=a>>1,s=i-7,u=n-1,c=t[u--],l=127&c;for(c>>=7;s>0;l=256*l+t[u],u--,s-=8);for(r=l&(1<<-s)-1,l>>=-s,s+=e;s>0;r=256*r+t[u],u--,s-=8);if(0===l)l=1-o;else{if(l===a)return r?NaN:c?-E:E;r+=C(2,e),l-=o}return(c?-1:1)*r*C(2,l-e)}function j(t){return t[3]<<24|t[2]<<16|t[1]<<8|t[0]}function P(t){return[255&t]}function L(t){return[255&t,t>>8&255]}function z(t){return[255&t,t>>8&255,t>>16&255,t>>24&255]}function B(t){return R(t,52,8)}function U(t){return R(t,23,4)}function W(t,e,n){m(t[y],e,{get:function(){return this[n]}})}function V(t,e,n,r){var i=h(+n);if(i+e>t[D])throw _(b);var a=t[I]._b,o=i+t[M],s=a.slice(o,o+e);return r?s:s.reverse()}function q(t,e,n,r,i,a){var o=h(+n);if(o+e>t[D])throw _(b);for(var s=t[I]._b,u=o+t[M],c=r(+i),l=0;l<e;l++)s[u+l]=c[a?l:e-l-1]}if(o.ABV){if(!c(function(){x(1)})||!c(function(){new x(-1)})||c(function(){return new x,new x(1.5),new x(NaN),"ArrayBuffer"!=x.name})){for(var H,G=(x=function(t){return l(this,x),new O(h(t))})[y]=O[y],$=p(O),K=0;$.length>K;)(H=$[K++])in x||s(x,H,O[H]);a||(G.constructor=x)}var X=new w(new x(2)),Y=w[y].setInt8;X.setInt8(0,2147483648),X.setInt8(1,2147483649),!X.getInt8(0)&&X.getInt8(1)||u(w[y],{setInt8:function(t,e){Y.call(this,t,e<<24>>24)},setUint8:function(t,e){Y.call(this,t,e<<24>>24)}},!0)}else x=function(t){l(this,x,"ArrayBuffer");var e=h(t);this._b=g.call(new Array(e),0),this[D]=e},w=function(t,e,n){l(this,w,"DataView"),l(t,x,"DataView");var r=t[D],i=f(e);if(i<0||i>r)throw _("Wrong offset!");if(i+(n=void 0===n?r-i:d(n))>r)throw _("Wrong length!");this[I]=t,this[M]=i,this[D]=n},i&&(W(x,"byteLength","_l"),W(w,"buffer","_b"),W(w,"byteLength","_l"),W(w,"byteOffset","_o")),u(w[y],{getInt8:function(t){return V(this,1,t)[0]<<24>>24},getUint8:function(t){return V(this,1,t)[0]},getInt16:function(t){var e=V(this,2,t,arguments[1]);return(e[1]<<8|e[0])<<16>>16},getUint16:function(t){var e=V(this,2,t,arguments[1]);return e[1]<<8|e[0]},getInt32:function(t){return j(V(this,4,t,arguments[1]))},getUint32:function(t){return j(V(this,4,t,arguments[1]))>>>0},getFloat32:function(t){return F(V(this,4,t,arguments[1]),23,4)},getFloat64:function(t){return F(V(this,8,t,arguments[1]),52,8)},setInt8:function(t,e){q(this,1,t,P,e)},setUint8:function(t,e){q(this,1,t,P,e)},setInt16:function(t,e){q(this,2,t,L,e,arguments[2])},setUint16:function(t,e){q(this,2,t,L,e,arguments[2])},setInt32:function(t,e){q(this,4,t,z,e,arguments[2])},setUint32:function(t,e){q(this,4,t,z,e,arguments[2])},setFloat32:function(t,e){q(this,4,t,U,e,arguments[2])},setFloat64:function(t,e){q(this,8,t,B,e,arguments[2])}});v(x,"ArrayBuffer"),v(w,"DataView"),s(w[y],o.VIEW,!0),e.ArrayBuffer=x,e.DataView=w},function(t,e,n){"use strict";var r=n(27);t.exports.f=function(t){return new function(t){var e,n;this.promise=new t(function(t,r){if(void 0!==e||void 0!==n)throw TypeError("Bad Promise constructor");e=t,n=r}),this.resolve=r(e),this.reject=r(n)}(t)}},function(t,e,n){var r=n(11),i=n(169).set,a=r.MutationObserver||r.WebKitMutationObserver,o=r.process,s=r.Promise,u="process"==n(42)(o);t.exports=function(){var t,e,n,c=function(){var r,i;for(u&&(r=o.domain)&&r.exit();t;){i=t.fn,t=t.next;try{i()}catch(r){throw t?n():e=void 0,r}}e=void 0,r&&r.enter()};if(u)n=function(){o.nextTick(c)};else if(!a||r.navigator&&r.navigator.standalone)if(s&&s.resolve){var l=s.resolve(void 0);n=function(){l.then(c)}}else n=function(){i.call(r,c)};else{var f=!0,d=document.createTextNode("");new a(c).observe(d,{characterData:!0}),n=function(){d.data=f=!f}}return function(r){var i={fn:r,next:void 0};e&&(e.next=i),t||(t=i,n()),e=i}}},function(t,e,n){var r,i,a,o=n(43),s=n(274),u=n(188),c=n(192),l=n(11),f=l.process,d=l.setImmediate,h=l.clearImmediate,p=l.MessageChannel,m=l.Dispatch,g=0,v={},y=function(){var t=+this;if(v.hasOwnProperty(t)){var e=v[t];delete v[t],e()}},b=function(t){y.call(t.data)};d&&h||(d=function(t){for(var e=[],n=1;arguments.length>n;)e.push(arguments[n++]);return v[++g]=function(){s("function"==typeof t?t:Function(t),e)},r(g),g},h=function(t){delete v[t]},"process"==n(42)(f)?r=function(t){f.nextTick(o(y,t,1))}:m&&m.now?r=function(t){m.now(o(y,t,1))}:p?(a=(i=new p).port2,i.port1.onmessage=b,r=o(a.postMessage,a,1)):l.addEventListener&&"function"==typeof postMessage&&!l.importScripts?(r=function(t){l.postMessage(t+"","*")},l.addEventListener("message",b,!1)):r="onreadystatechange"in c("script")?function(t){u.appendChild(c("script")).onreadystatechange=function(){u.removeChild(this),y.call(t)}}:function(t){setTimeout(o(y,t,1),0)}),t.exports={set:d,clear:h}},function(t,e,n){"use strict";var r=n(133)(!0);t.exports=function(t,e,n){return e+(n?r(t,e).length:1)}},function(t,e,n){"use strict";var r=n(111),i=RegExp.prototype.exec,a=String.prototype.replace,o=i,s=function(){var t=/a/,e=/b*/g;return i.call(t,"a"),i.call(e,"a"),0!==t.lastIndex||0!==e.lastIndex}(),u=void 0!==/()??/.exec("")[1];(s||u)&&(o=function(t){var e,n,o,c,l=this;return u&&(n=new RegExp("^"+l.source+"$(?!\\s)",r.call(l))),s&&(e=l.lastIndex),o=i.call(l,t),s&&o&&(l.lastIndex=l.global?o.index+o[0].length:e),u&&o&&o.length>1&&a.call(o[0],n,function(){for(c=1;c<arguments.length-2;c++)void 0===arguments[c]&&(o[c]=void 0)}),o}),t.exports=o},function(t,e,n){"use strict";var r=n(61),i=n(264),a=n(91),o=n(35);t.exports=n(181)(Array,"Array",function(t,e){this._t=o(t),this._i=0,this._k=e},function(){var t=this._t,e=this._k,n=this._i++;return!t||n>=t.length?(this._t=void 0,i(1)):i(0,"keys"==e?n:"values"==e?t[n]:[n,t[n]])},"values"),a.Arguments=a.Array,r("keys"),r("values"),r("entries")},function(t,e,n){"use strict";var r=n(22),i=n(77),a=n(17);t.exports=function(t){for(var e=r(this),n=a(e.length),o=arguments.length,s=i(o>1?arguments[1]:void 0,n),u=o>2?arguments[2]:void 0,c=void 0===u?n:i(u,n);c>s;)e[s++]=t;return e}},function(t,e,n){var r=n(600);t.exports=function(t,e){return new(r(t))(e)}},function(t,e,n){var r=n(93),i=n(16)("iterator"),a=n(91);t.exports=n(44).getIteratorMethod=function(t){if(void 0!=t)return t[i]||t["@@iterator"]||a[r(t)]}},function(t,e,n){"use strict";var r=n(21),i=n(80);t.exports=function(t,e,n){e in t?r.f(t,e,i(0,n)):t[e]=n}},function(t,e,n){var r=n(91),i=n(16)("iterator"),a=Array.prototype;t.exports=function(t){return void 0!==t&&(r.Array===t||a[i]===t)}},function(t,e,n){var r=n(16)("match");t.exports=function(t){var e=/./;try{"/./"[t](e)}catch(n){try{return e[r]=!1,!"/./"[t](e)}catch(t){}}return!0}},function(t,e,n){var r=n(132),i=n(51);t.exports=function(t,e,n){if(r(e))throw TypeError("String#"+n+" doesn't accept regex!");return String(i(t))}},function(t,e,n){"use strict";var r=n(76),i=n(80),a=n(94),o={};n(31)(o,n(16)("iterator"),function(){return this}),t.exports=function(t,e,n){t.prototype=r(o,{next:i(1,n)}),a(t,e+" Iterator")}},function(t,e,n){"use strict";var r=n(63),i=n(5),a=n(30),o=n(31),s=n(91),u=n(180),c=n(94),l=n(33),f=n(16)("iterator"),d=!([].keys&&"next"in[].keys()),h=function(){return this};t.exports=function(t,e,n,p,m,g,v){u(n,e,p);var y,b,x,w=function(t){if(!d&&t in O)return O[t];switch(t){case"keys":case"values":return function(){return new n(this,t)}}return function(){return new n(this,t)}},k=e+" Iterator",_="values"==m,E=!1,O=t.prototype,S=O[f]||O["@@iterator"]||m&&O[m],C=S||w(m),A=m?_?w("entries"):C:void 0,N="Array"==e&&O.entries||S;if(N&&(x=l(N.call(new t)))!==Object.prototype&&x.next&&(c(x,k,!0),r||"function"==typeof x[f]||o(x,f,h)),_&&S&&"values"!==S.name&&(E=!0,C=function(){return S.call(this)}),r&&!v||!d&&!E&&O[f]||o(O,f,C),s[e]=C,s[k]=h,m)if(y={values:_?C:w("values"),keys:g?C:w("keys"),entries:A},v)for(b in y)b in O||a(O,b,y[b]);else i(i.P+i.F*(d||E),e,y);return y}},function(t,e){var n=Math.expm1;t.exports=!n||n(10)>22025.465794806718||n(10)<22025.465794806718||-2e-17!=n(-2e-17)?function(t){return 0==(t=+t)?t:t>-1e-6&&t<1e-6?t+t*t/2:Math.exp(t)-1}:n},function(t,e){t.exports=Math.sign||function(t){return 0==(t=+t)||t!=t?t:t<0?-1:1}},function(t,e,n){"use strict";var r=n(41),i=n(51);t.exports=function(t){var e=String(i(this)),n="",a=r(t);if(a<0||a==1/0)throw RangeError("Count can't be negative");for(;a>0;(a>>>=1)&&(e+=e))1&a&&(n+=e);return n}},function(t,e,n){var r=n(13),i=n(187).set;t.exports=function(t,e,n){var a,o=e.constructor;return o!==n&&"function"==typeof o&&(a=o.prototype)!==n.prototype&&r(a)&&i&&i(t,a),t}},function(t,e){t.exports="\t\n\v\f\r  ᠎              \u2028\u2029\ufeff"},function(t,e,n){var r=n(13),i=n(6),a=function(t,e){if(i(t),!r(e)&&null!==e)throw TypeError(e+": can't set as prototype!")};t.exports={set:Object.setPrototypeOf||("__proto__"in{}?function(t,e,r){try{(r=n(43)(Function.call,n(34).f(Object.prototype,"__proto__").set,2))(t,[]),e=!(t instanceof Array)}catch(t){e=!0}return function(t,n){return a(t,n),e?t.__proto__=n:r(t,n),t}}({},!1):void 0),check:a}},function(t,e,n){var r=n(11).document;t.exports=r&&r.documentElement},function(t,e){t.exports="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")},function(t,e,n){var r=n(114)("keys"),i=n(79);t.exports=function(t){return r[t]||(r[t]=i(t))}},function(t,e,n){var r=n(11),i=n(44),a=n(63),o=n(281),s=n(21).f;t.exports=function(t){var e=i.Symbol||(i.Symbol=a?{}:r.Symbol||{});"_"==t.charAt(0)||t in e||s(e,t,{value:o.f(t)})}},function(t,e,n){var r=n(13),i=n(11).document,a=r(i)&&r(i.createElement);t.exports=function(t){return a?i.createElement(t):{}}},function(t,e,n){"use strict";(function(r,i){function a(){return"object"==typeof r&&void 0!==t&&void 0!==i&&!!i.version}n.d(e,"a",function(){return a})}).call(this,n(53),n(87))},function(t,e,n){"use strict";(function(t){n.d(e,"a",function(){return a});var r=n(3),i=n(138);function a(){var e=t.Canvas||t.HTMLCanvasElement,n=t.Image||t.HTMLImageElement,a=t.fetch||function(){throw new Error("fetch - missing fetch implementation for nodejs environment")},o=Object(i.a)();return Object(r.a)({Canvas:e||function(){return function(){}}(),CanvasRenderingContext2D:t.CanvasRenderingContext2D||function(){return function(){}}(),Image:n||function(){return function(){}}(),ImageData:t.ImageData||function(){return function(){}}(),Video:t.HTMLVideoElement||function(){return function(){}}(),createCanvasElement:function(){if(e)return new e;throw new Error("createCanvasElement - missing Canvas implementation for nodejs environment")},createImageElement:function(){if(n)return new n;throw new Error("createImageElement - missing Image implementation for nodejs environment")},fetch:a},o)}}).call(this,n(53))},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e=/\/schema\/([\w-]+)\/([\w\.\-]+)\.json$/g.exec(t).slice(1,3);return{library:e[0],version:e[1]}}},function(t,e,n){(function(n){var r;e=t.exports=h,r="object"==typeof n&&n.env&&n.env.NODE_DEBUG&&/\bsemver\b/i.test(n.env.NODE_DEBUG)?function(){var t=Array.prototype.slice.call(arguments,0);t.unshift("SEMVER"),console.log.apply(console,t)}:function(){},e.SEMVER_SPEC_VERSION="2.0.0";var i=256,a=Number.MAX_SAFE_INTEGER||9007199254740991,o=e.re=[],s=e.src=[],u=e.tokens={},c=0;function l(t){u[t]=c++}l("NUMERICIDENTIFIER"),s[u.NUMERICIDENTIFIER]="0|[1-9]\\d*",l("NUMERICIDENTIFIERLOOSE"),s[u.NUMERICIDENTIFIERLOOSE]="[0-9]+",l("NONNUMERICIDENTIFIER"),s[u.NONNUMERICIDENTIFIER]="\\d*[a-zA-Z-][a-zA-Z0-9-]*",l("MAINVERSION"),s[u.MAINVERSION]="("+s[u.NUMERICIDENTIFIER]+")\\.("+s[u.NUMERICIDENTIFIER]+")\\.("+s[u.NUMERICIDENTIFIER]+")",l("MAINVERSIONLOOSE"),s[u.MAINVERSIONLOOSE]="("+s[u.NUMERICIDENTIFIERLOOSE]+")\\.("+s[u.NUMERICIDENTIFIERLOOSE]+")\\.("+s[u.NUMERICIDENTIFIERLOOSE]+")",l("PRERELEASEIDENTIFIER"),s[u.PRERELEASEIDENTIFIER]="(?:"+s[u.NUMERICIDENTIFIER]+"|"+s[u.NONNUMERICIDENTIFIER]+")",l("PRERELEASEIDENTIFIERLOOSE"),s[u.PRERELEASEIDENTIFIERLOOSE]="(?:"+s[u.NUMERICIDENTIFIERLOOSE]+"|"+s[u.NONNUMERICIDENTIFIER]+")",l("PRERELEASE"),s[u.PRERELEASE]="(?:-("+s[u.PRERELEASEIDENTIFIER]+"(?:\\."+s[u.PRERELEASEIDENTIFIER]+")*))",l("PRERELEASELOOSE"),s[u.PRERELEASELOOSE]="(?:-?("+s[u.PRERELEASEIDENTIFIERLOOSE]+"(?:\\."+s[u.PRERELEASEIDENTIFIERLOOSE]+")*))",l("BUILDIDENTIFIER"),s[u.BUILDIDENTIFIER]="[0-9A-Za-z-]+",l("BUILD"),s[u.BUILD]="(?:\\+("+s[u.BUILDIDENTIFIER]+"(?:\\."+s[u.BUILDIDENTIFIER]+")*))",l("FULL"),l("FULLPLAIN"),s[u.FULLPLAIN]="v?"+s[u.MAINVERSION]+s[u.PRERELEASE]+"?"+s[u.BUILD]+"?",s[u.FULL]="^"+s[u.FULLPLAIN]+"$",l("LOOSEPLAIN"),s[u.LOOSEPLAIN]="[v=\\s]*"+s[u.MAINVERSIONLOOSE]+s[u.PRERELEASELOOSE]+"?"+s[u.BUILD]+"?",l("LOOSE"),s[u.LOOSE]="^"+s[u.LOOSEPLAIN]+"$",l("GTLT"),s[u.GTLT]="((?:<|>)?=?)",l("XRANGEIDENTIFIERLOOSE"),s[u.XRANGEIDENTIFIERLOOSE]=s[u.NUMERICIDENTIFIERLOOSE]+"|x|X|\\*",l("XRANGEIDENTIFIER"),s[u.XRANGEIDENTIFIER]=s[u.NUMERICIDENTIFIER]+"|x|X|\\*",l("XRANGEPLAIN"),s[u.XRANGEPLAIN]="[v=\\s]*("+s[u.XRANGEIDENTIFIER]+")(?:\\.("+s[u.XRANGEIDENTIFIER]+")(?:\\.("+s[u.XRANGEIDENTIFIER]+")(?:"+s[u.PRERELEASE]+")?"+s[u.BUILD]+"?)?)?",l("XRANGEPLAINLOOSE"),s[u.XRANGEPLAINLOOSE]="[v=\\s]*("+s[u.XRANGEIDENTIFIERLOOSE]+")(?:\\.("+s[u.XRANGEIDENTIFIERLOOSE]+")(?:\\.("+s[u.XRANGEIDENTIFIERLOOSE]+")(?:"+s[u.PRERELEASELOOSE]+")?"+s[u.BUILD]+"?)?)?",l("XRANGE"),s[u.XRANGE]="^"+s[u.GTLT]+"\\s*"+s[u.XRANGEPLAIN]+"$",l("XRANGELOOSE"),s[u.XRANGELOOSE]="^"+s[u.GTLT]+"\\s*"+s[u.XRANGEPLAINLOOSE]+"$",l("COERCE"),s[u.COERCE]="(^|[^\\d])(\\d{1,16})(?:\\.(\\d{1,16}))?(?:\\.(\\d{1,16}))?(?:$|[^\\d])",l("COERCERTL"),o[u.COERCERTL]=new RegExp(s[u.COERCE],"g"),l("LONETILDE"),s[u.LONETILDE]="(?:~>?)",l("TILDETRIM"),s[u.TILDETRIM]="(\\s*)"+s[u.LONETILDE]+"\\s+",o[u.TILDETRIM]=new RegExp(s[u.TILDETRIM],"g");l("TILDE"),s[u.TILDE]="^"+s[u.LONETILDE]+s[u.XRANGEPLAIN]+"$",l("TILDELOOSE"),s[u.TILDELOOSE]="^"+s[u.LONETILDE]+s[u.XRANGEPLAINLOOSE]+"$",l("LONECARET"),s[u.LONECARET]="(?:\\^)",l("CARETTRIM"),s[u.CARETTRIM]="(\\s*)"+s[u.LONECARET]+"\\s+",o[u.CARETTRIM]=new RegExp(s[u.CARETTRIM],"g");l("CARET"),s[u.CARET]="^"+s[u.LONECARET]+s[u.XRANGEPLAIN]+"$",l("CARETLOOSE"),s[u.CARETLOOSE]="^"+s[u.LONECARET]+s[u.XRANGEPLAINLOOSE]+"$",l("COMPARATORLOOSE"),s[u.COMPARATORLOOSE]="^"+s[u.GTLT]+"\\s*("+s[u.LOOSEPLAIN]+")$|^$",l("COMPARATOR"),s[u.COMPARATOR]="^"+s[u.GTLT]+"\\s*("+s[u.FULLPLAIN]+")$|^$",l("COMPARATORTRIM"),s[u.COMPARATORTRIM]="(\\s*)"+s[u.GTLT]+"\\s*("+s[u.LOOSEPLAIN]+"|"+s[u.XRANGEPLAIN]+")",o[u.COMPARATORTRIM]=new RegExp(s[u.COMPARATORTRIM],"g");l("HYPHENRANGE"),s[u.HYPHENRANGE]="^\\s*("+s[u.XRANGEPLAIN]+")\\s+-\\s+("+s[u.XRANGEPLAIN]+")\\s*$",l("HYPHENRANGELOOSE"),s[u.HYPHENRANGELOOSE]="^\\s*("+s[u.XRANGEPLAINLOOSE]+")\\s+-\\s+("+s[u.XRANGEPLAINLOOSE]+")\\s*$",l("STAR"),s[u.STAR]="(<|>)?=?\\s*\\*";for(var f=0;f<c;f++)r(f,s[f]),o[f]||(o[f]=new RegExp(s[f]));function d(t,e){if(e&&"object"==typeof e||(e={loose:!!e,includePrerelease:!1}),t instanceof h)return t;if("string"!=typeof t)return null;if(t.length>i)return null;if(!(e.loose?o[u.LOOSE]:o[u.FULL]).test(t))return null;try{return new h(t,e)}catch(t){return null}}function h(t,e){if(e&&"object"==typeof e||(e={loose:!!e,includePrerelease:!1}),t instanceof h){if(t.loose===e.loose)return t;t=t.version}else if("string"!=typeof t)throw new TypeError("Invalid Version: "+t);if(t.length>i)throw new TypeError("version is longer than "+i+" characters");if(!(this instanceof h))return new h(t,e);r("SemVer",t,e),this.options=e,this.loose=!!e.loose;var n=t.trim().match(e.loose?o[u.LOOSE]:o[u.FULL]);if(!n)throw new TypeError("Invalid Version: "+t);if(this.raw=t,this.major=+n[1],this.minor=+n[2],this.patch=+n[3],this.major>a||this.major<0)throw new TypeError("Invalid major version");if(this.minor>a||this.minor<0)throw new TypeError("Invalid minor version");if(this.patch>a||this.patch<0)throw new TypeError("Invalid patch version");n[4]?this.prerelease=n[4].split(".").map(function(t){if(/^[0-9]+$/.test(t)){var e=+t;if(e>=0&&e<a)return e}return t}):this.prerelease=[],this.build=n[5]?n[5].split("."):[],this.format()}e.parse=d,e.valid=function(t,e){var n=d(t,e);return n?n.version:null},e.clean=function(t,e){var n=d(t.trim().replace(/^[=v]+/,""),e);return n?n.version:null},e.SemVer=h,h.prototype.format=function(){return this.version=this.major+"."+this.minor+"."+this.patch,this.prerelease.length&&(this.version+="-"+this.prerelease.join(".")),this.version},h.prototype.toString=function(){return this.version},h.prototype.compare=function(t){return r("SemVer.compare",this.version,this.options,t),t instanceof h||(t=new h(t,this.options)),this.compareMain(t)||this.comparePre(t)},h.prototype.compareMain=function(t){return t instanceof h||(t=new h(t,this.options)),m(this.major,t.major)||m(this.minor,t.minor)||m(this.patch,t.patch)},h.prototype.comparePre=function(t){if(t instanceof h||(t=new h(t,this.options)),this.prerelease.length&&!t.prerelease.length)return-1;if(!this.prerelease.length&&t.prerelease.length)return 1;if(!this.prerelease.length&&!t.prerelease.length)return 0;var e=0;do{var n=this.prerelease[e],i=t.prerelease[e];if(r("prerelease compare",e,n,i),void 0===n&&void 0===i)return 0;if(void 0===i)return 1;if(void 0===n)return-1;if(n!==i)return m(n,i)}while(++e)},h.prototype.compareBuild=function(t){t instanceof h||(t=new h(t,this.options));var e=0;do{var n=this.build[e],i=t.build[e];if(r("prerelease compare",e,n,i),void 0===n&&void 0===i)return 0;if(void 0===i)return 1;if(void 0===n)return-1;if(n!==i)return m(n,i)}while(++e)},h.prototype.inc=function(t,e){switch(t){case"premajor":this.prerelease.length=0,this.patch=0,this.minor=0,this.major++,this.inc("pre",e);break;case"preminor":this.prerelease.length=0,this.patch=0,this.minor++,this.inc("pre",e);break;case"prepatch":this.prerelease.length=0,this.inc("patch",e),this.inc("pre",e);break;case"prerelease":0===this.prerelease.length&&this.inc("patch",e),this.inc("pre",e);break;case"major":0===this.minor&&0===this.patch&&0!==this.prerelease.length||this.major++,this.minor=0,this.patch=0,this.prerelease=[];break;case"minor":0===this.patch&&0!==this.prerelease.length||this.minor++,this.patch=0,this.prerelease=[];break;case"patch":0===this.prerelease.length&&this.patch++,this.prerelease=[];break;case"pre":if(0===this.prerelease.length)this.prerelease=[0];else{for(var n=this.prerelease.length;--n>=0;)"number"==typeof this.prerelease[n]&&(this.prerelease[n]++,n=-2);-1===n&&this.prerelease.push(0)}e&&(this.prerelease[0]===e?isNaN(this.prerelease[1])&&(this.prerelease=[e,0]):this.prerelease=[e,0]);break;default:throw new Error("invalid increment argument: "+t)}return this.format(),this.raw=this.version,this},e.inc=function(t,e,n,r){"string"==typeof n&&(r=n,n=void 0);try{return new h(t,n).inc(e,r).version}catch(t){return null}},e.diff=function(t,e){if(b(t,e))return null;var n=d(t),r=d(e),i="";if(n.prerelease.length||r.prerelease.length){i="pre";var a="prerelease"}for(var o in n)if(("major"===o||"minor"===o||"patch"===o)&&n[o]!==r[o])return i+o;return a},e.compareIdentifiers=m;var p=/^[0-9]+$/;function m(t,e){var n=p.test(t),r=p.test(e);return n&&r&&(t=+t,e=+e),t===e?0:n&&!r?-1:r&&!n?1:t<e?-1:1}function g(t,e,n){return new h(t,n).compare(new h(e,n))}function v(t,e,n){return g(t,e,n)>0}function y(t,e,n){return g(t,e,n)<0}function b(t,e,n){return 0===g(t,e,n)}function x(t,e,n){return 0!==g(t,e,n)}function w(t,e,n){return g(t,e,n)>=0}function k(t,e,n){return g(t,e,n)<=0}function _(t,e,n,r){switch(e){case"===":return"object"==typeof t&&(t=t.version),"object"==typeof n&&(n=n.version),t===n;case"!==":return"object"==typeof t&&(t=t.version),"object"==typeof n&&(n=n.version),t!==n;case"":case"=":case"==":return b(t,n,r);case"!=":return x(t,n,r);case">":return v(t,n,r);case">=":return w(t,n,r);case"<":return y(t,n,r);case"<=":return k(t,n,r);default:throw new TypeError("Invalid operator: "+e)}}function E(t,e){if(e&&"object"==typeof e||(e={loose:!!e,includePrerelease:!1}),t instanceof E){if(t.loose===!!e.loose)return t;t=t.value}if(!(this instanceof E))return new E(t,e);r("comparator",t,e),this.options=e,this.loose=!!e.loose,this.parse(t),this.semver===O?this.value="":this.value=this.operator+this.semver.version,r("comp",this)}e.rcompareIdentifiers=function(t,e){return m(e,t)},e.major=function(t,e){return new h(t,e).major},e.minor=function(t,e){return new h(t,e).minor},e.patch=function(t,e){return new h(t,e).patch},e.compare=g,e.compareLoose=function(t,e){return g(t,e,!0)},e.compareBuild=function(t,e,n){var r=new h(t,n),i=new h(e,n);return r.compare(i)||r.compareBuild(i)},e.rcompare=function(t,e,n){return g(e,t,n)},e.sort=function(t,n){return t.sort(function(t,r){return e.compareBuild(t,r,n)})},e.rsort=function(t,n){return t.sort(function(t,r){return e.compareBuild(r,t,n)})},e.gt=v,e.lt=y,e.eq=b,e.neq=x,e.gte=w,e.lte=k,e.cmp=_,e.Comparator=E;var O={};function S(t,e){if(e&&"object"==typeof e||(e={loose:!!e,includePrerelease:!1}),t instanceof S)return t.loose===!!e.loose&&t.includePrerelease===!!e.includePrerelease?t:new S(t.raw,e);if(t instanceof E)return new S(t.value,e);if(!(this instanceof S))return new S(t,e);if(this.options=e,this.loose=!!e.loose,this.includePrerelease=!!e.includePrerelease,this.raw=t,this.set=t.split(/\s*\|\|\s*/).map(function(t){return this.parseRange(t.trim())},this).filter(function(t){return t.length}),!this.set.length)throw new TypeError("Invalid SemVer Range: "+t);this.format()}function C(t,e){for(var n=!0,r=t.slice(),i=r.pop();n&&r.length;)n=r.every(function(t){return i.intersects(t,e)}),i=r.pop();return n}function A(t){return!t||"x"===t.toLowerCase()||"*"===t}function N(t,e,n,r,i,a,o,s,u,c,l,f,d){return((e=A(n)?"":A(r)?">="+n+".0.0":A(i)?">="+n+"."+r+".0":">="+e)+" "+(s=A(u)?"":A(c)?"<"+(+u+1)+".0.0":A(l)?"<"+u+"."+(+c+1)+".0":f?"<="+u+"."+c+"."+l+"-"+f:"<="+s)).trim()}function T(t,e,n){for(var i=0;i<t.length;i++)if(!t[i].test(e))return!1;if(e.prerelease.length&&!n.includePrerelease){for(i=0;i<t.length;i++)if(r(t[i].semver),t[i].semver!==O&&t[i].semver.prerelease.length>0){var a=t[i].semver;if(a.major===e.major&&a.minor===e.minor&&a.patch===e.patch)return!0}return!1}return!0}function I(t,e,n){try{e=new S(e,n)}catch(t){return!1}return e.test(t)}function D(t,e,n,r){var i,a,o,s,u;switch(t=new h(t,r),e=new S(e,r),n){case">":i=v,a=k,o=y,s=">",u=">=";break;case"<":i=y,a=w,o=v,s="<",u="<=";break;default:throw new TypeError('Must provide a hilo val of "<" or ">"')}if(I(t,e,r))return!1;for(var c=0;c<e.set.length;++c){var l=null,f=null;if(e.set[c].forEach(function(t){t.semver===O&&(t=new E(">=0.0.0")),l=l||t,f=f||t,i(t.semver,l.semver,r)?l=t:o(t.semver,f.semver,r)&&(f=t)}),l.operator===s||l.operator===u)return!1;if((!f.operator||f.operator===s)&&a(t,f.semver))return!1;if(f.operator===u&&o(t,f.semver))return!1}return!0}E.prototype.parse=function(t){var e=this.options.loose?o[u.COMPARATORLOOSE]:o[u.COMPARATOR],n=t.match(e);if(!n)throw new TypeError("Invalid comparator: "+t);this.operator=void 0!==n[1]?n[1]:"","="===this.operator&&(this.operator=""),n[2]?this.semver=new h(n[2],this.options.loose):this.semver=O},E.prototype.toString=function(){return this.value},E.prototype.test=function(t){if(r("Comparator.test",t,this.options.loose),this.semver===O||t===O)return!0;if("string"==typeof t)try{t=new h(t,this.options)}catch(t){return!1}return _(t,this.operator,this.semver,this.options)},E.prototype.intersects=function(t,e){if(!(t instanceof E))throw new TypeError("a Comparator is required");var n;if(e&&"object"==typeof e||(e={loose:!!e,includePrerelease:!1}),""===this.operator)return""===this.value||(n=new S(t.value,e),I(this.value,n,e));if(""===t.operator)return""===t.value||(n=new S(this.value,e),I(t.semver,n,e));var r=!(">="!==this.operator&&">"!==this.operator||">="!==t.operator&&">"!==t.operator),i=!("<="!==this.operator&&"<"!==this.operator||"<="!==t.operator&&"<"!==t.operator),a=this.semver.version===t.semver.version,o=!(">="!==this.operator&&"<="!==this.operator||">="!==t.operator&&"<="!==t.operator),s=_(this.semver,"<",t.semver,e)&&(">="===this.operator||">"===this.operator)&&("<="===t.operator||"<"===t.operator),u=_(this.semver,">",t.semver,e)&&("<="===this.operator||"<"===this.operator)&&(">="===t.operator||">"===t.operator);return r||i||a&&o||s||u},e.Range=S,S.prototype.format=function(){return this.range=this.set.map(function(t){return t.join(" ").trim()}).join("||").trim(),this.range},S.prototype.toString=function(){return this.range},S.prototype.parseRange=function(t){var e=this.options.loose;t=t.trim();var n=e?o[u.HYPHENRANGELOOSE]:o[u.HYPHENRANGE];t=t.replace(n,N),r("hyphen replace",t),t=t.replace(o[u.COMPARATORTRIM],"$1$2$3"),r("comparator trim",t,o[u.COMPARATORTRIM]),t=(t=(t=t.replace(o[u.TILDETRIM],"$1~")).replace(o[u.CARETTRIM],"$1^")).split(/\s+/).join(" ");var i=e?o[u.COMPARATORLOOSE]:o[u.COMPARATOR],a=t.split(" ").map(function(t){return function(t,e){return r("comp",t,e),t=function(t,e){return t.trim().split(/\s+/).map(function(t){return function(t,e){r("caret",t,e);var n=e.loose?o[u.CARETLOOSE]:o[u.CARET];return t.replace(n,function(e,n,i,a,o){var s;return r("caret",t,e,n,i,a,o),A(n)?s="":A(i)?s=">="+n+".0.0 <"+(+n+1)+".0.0":A(a)?s="0"===n?">="+n+"."+i+".0 <"+n+"."+(+i+1)+".0":">="+n+"."+i+".0 <"+(+n+1)+".0.0":o?(r("replaceCaret pr",o),s="0"===n?"0"===i?">="+n+"."+i+"."+a+"-"+o+" <"+n+"."+i+"."+(+a+1):">="+n+"."+i+"."+a+"-"+o+" <"+n+"."+(+i+1)+".0":">="+n+"."+i+"."+a+"-"+o+" <"+(+n+1)+".0.0"):(r("no pr"),s="0"===n?"0"===i?">="+n+"."+i+"."+a+" <"+n+"."+i+"."+(+a+1):">="+n+"."+i+"."+a+" <"+n+"."+(+i+1)+".0":">="+n+"."+i+"."+a+" <"+(+n+1)+".0.0"),r("caret return",s),s})}(t,e)}).join(" ")}(t,e),r("caret",t),t=function(t,e){return t.trim().split(/\s+/).map(function(t){return function(t,e){var n=e.loose?o[u.TILDELOOSE]:o[u.TILDE];return t.replace(n,function(e,n,i,a,o){var s;return r("tilde",t,e,n,i,a,o),A(n)?s="":A(i)?s=">="+n+".0.0 <"+(+n+1)+".0.0":A(a)?s=">="+n+"."+i+".0 <"+n+"."+(+i+1)+".0":o?(r("replaceTilde pr",o),s=">="+n+"."+i+"."+a+"-"+o+" <"+n+"."+(+i+1)+".0"):s=">="+n+"."+i+"."+a+" <"+n+"."+(+i+1)+".0",r("tilde return",s),s})}(t,e)}).join(" ")}(t,e),r("tildes",t),t=function(t,e){return r("replaceXRanges",t,e),t.split(/\s+/).map(function(t){return function(t,e){t=t.trim();var n=e.loose?o[u.XRANGELOOSE]:o[u.XRANGE];return t.replace(n,function(n,i,a,o,s,u){r("xRange",t,n,i,a,o,s,u);var c=A(a),l=c||A(o),f=l||A(s),d=f;return"="===i&&d&&(i=""),u=e.includePrerelease?"-0":"",c?n=">"===i||"<"===i?"<0.0.0-0":"*":i&&d?(l&&(o=0),s=0,">"===i?(i=">=",l?(a=+a+1,o=0,s=0):(o=+o+1,s=0)):"<="===i&&(i="<",l?a=+a+1:o=+o+1),n=i+a+"."+o+"."+s+u):l?n=">="+a+".0.0"+u+" <"+(+a+1)+".0.0"+u:f&&(n=">="+a+"."+o+".0"+u+" <"+a+"."+(+o+1)+".0"+u),r("xRange return",n),n})}(t,e)}).join(" ")}(t,e),r("xrange",t),t=function(t,e){return r("replaceStars",t,e),t.trim().replace(o[u.STAR],"")}(t,e),r("stars",t),t}(t,this.options)},this).join(" ").split(/\s+/);return this.options.loose&&(a=a.filter(function(t){return!!t.match(i)})),a=a.map(function(t){return new E(t,this.options)},this)},S.prototype.intersects=function(t,e){if(!(t instanceof S))throw new TypeError("a Range is required");return this.set.some(function(n){return C(n,e)&&t.set.some(function(t){return C(t,e)&&n.every(function(n){return t.every(function(t){return n.intersects(t,e)})})})})},e.toComparators=function(t,e){return new S(t,e).set.map(function(t){return t.map(function(t){return t.value}).join(" ").trim().split(" ")})},S.prototype.test=function(t){if(!t)return!1;if("string"==typeof t)try{t=new h(t,this.options)}catch(t){return!1}for(var e=0;e<this.set.length;e++)if(T(this.set[e],t,this.options))return!0;return!1},e.satisfies=I,e.maxSatisfying=function(t,e,n){var r=null,i=null;try{var a=new S(e,n)}catch(t){return null}return t.forEach(function(t){a.test(t)&&(r&&-1!==i.compare(t)||(i=new h(r=t,n)))}),r},e.minSatisfying=function(t,e,n){var r=null,i=null;try{var a=new S(e,n)}catch(t){return null}return t.forEach(function(t){a.test(t)&&(r&&1!==i.compare(t)||(i=new h(r=t,n)))}),r},e.minVersion=function(t,e){t=new S(t,e);var n=new h("0.0.0");if(t.test(n))return n;if(n=new h("0.0.0-0"),t.test(n))return n;n=null;for(var r=0;r<t.set.length;++r){var i=t.set[r];i.forEach(function(t){var e=new h(t.semver.version);switch(t.operator){case">":0===e.prerelease.length?e.patch++:e.prerelease.push(0),e.raw=e.format();case"":case">=":n&&!v(n,e)||(n=e);break;case"<":case"<=":break;default:throw new Error("Unexpected operation: "+t.operator)}})}if(n&&t.test(n))return n;return null},e.validRange=function(t,e){try{return new S(t,e).range||"*"}catch(t){return null}},e.ltr=function(t,e,n){return D(t,e,"<",n)},e.gtr=function(t,e,n){return D(t,e,">",n)},e.outside=D,e.prerelease=function(t,e){var n=d(t,e);return n&&n.prerelease.length?n.prerelease:null},e.intersects=function(t,e,n){return t=new S(t,n),e=new S(e,n),t.intersects(e)},e.coerce=function(t,e){if(t instanceof h)return t;"number"==typeof t&&(t=String(t));if("string"!=typeof t)return null;var n=null;if((e=e||{}).rtl){for(var r;(r=o[u.COERCERTL].exec(t))&&(!n||n.index+n[0].length!==t.length);)n&&r.index+r[0].length===n.index+n[0].length||(n=r),o[u.COERCERTL].lastIndex=r.index+r[1].length+r[2].length;o[u.COERCERTL].lastIndex=-1}else n=t.match(o[u.COERCE]);if(null===n)return null;return d(n[2]+"."+(n[3]||"0")+"."+(n[4]||"0"),e)}}).call(this,n(87))},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=u(n(14)),i=u(n(90)),a=u(n(83)),o=u(n(7)),s=u(n(10));function u(t){return t&&t.__esModule?t:{default:t}}var c=function(){function t(e){(0,o.default)(this,t),this.options=e||{}}return(0,s.default)(t,[{key:"normalizeValue",value:function(t,e,n){return(t-e)/(n-e)}},{key:"unnormalizeValue",value:function(t,e,n){return t*(n-e)+e}},{key:"getMin",value:function(t){return t.reduce(function(t,e){return Math.min(t,e)})}},{key:"getMax",value:function(t){return t.reduce(function(t,e){return Math.max(t,e)})}},{key:"isJsonOrString",value:function(t){try{JSON.parse(t)}catch(t){return!1}return!0}},{key:"zipArrays",value:function(t,e){return t.length!==e.length?(console.error("arrays do not have the same length"),[]):[].concat((0,a.default)(new Array(t.length).fill(null))).map(function(n,r){return(0,i.default)({},t[r],e[r])})}},{key:"createLabelsFromArrayValues",value:function(t,e){var n=void 0;return Array.isArray(t)&&(n=t.map(function(t,n){return e+"_"+n})),n}},{key:"formatDataAsObject",value:function(t,e){var n={};if(Array.isArray(t))return t.forEach(function(t,r){var i=e[r];n[i]=t}),n;if("object"===(void 0===t?"undefined":(0,r.default)(t)))return n=t;throw new Error("input provided is not supported or does not match your output label specifications")}},{key:"getDataType",value:function(t){var e=void 0===t?"undefined":(0,r.default)(t);return"object"===e&&Array.isArray(t)&&(e="array"),e}}]),t}();e.default=new c},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.randomSample=e.randomGaussian=e.randomInt=e.randomFloat=void 0;var r=function(t){return t&&t.__esModule?t:{default:t}}(n(47));var i=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return Math.random()*(e-t)+t};e.randomFloat=i,e.randomInt=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return Math.floor(Math.random()*(e-t+1))+t},e.randomGaussian=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=void 0,r=void 0,a=void 0,o=void 0,s=void 0,u=void 0;if(u)n=r,u=!1;else{do{s=(a=i(0,2)-1)*a+(o=i(0,2)-1)*o}while(s>=1);n=a*(s=Math.sqrt(-2*Math.log(s)/s)),r=o*s,u=!0}return n*e+t},e.randomSample=function(t,e){var n=void 0;if(!0===(arguments.length>2&&void 0!==arguments[2]&&arguments[2]))n=(0,r.default)({length:e},function(){return t[Math.floor(Math.random()*t.length)]});else{if(e>t.length)throw new RangeError("Sample size must be less than or equal to array length when sampling without replacement.");n=t.map(function(t){return[t,Math.random()]}).sort(function(t,e){return t[1]<e[1]?-1:1}).slice(0,e).map(function(t){return t[0]})}return n}},function(t,e,n){"use strict";e.__esModule=!0;var r=function(t){return t&&t.__esModule?t:{default:t}}(n(222));e.default=function(t,e,n){return e in t?(0,r.default)(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}},function(t,e,n){t.exports={default:n(309),__esModule:!0}},function(t){t.exports={name:"ml5",version:"0.6.0",description:"A friendly machine learning library for the web.",main:"dist/ml5.min.js",directories:{examples:"examples",dist:"dist"},scripts:{commit:"git-cz",prebuild:"rimraf dist",develop:"npm-run-all --parallel start examples:serve examples:watch",start:"webpack-dev-server --config webpack.dev.babel.js",lint:"eslint . --ext .js; exit 0","lint:nibble":"npx eslint-nibble --ext .js .","manual-test":"webpack-dev-server --open --config webpack.test.babel.js",build:"webpack --config webpack.prod.babel.js --config-name ml5",test:"./node_modules/karma/bin/karma start karma.conf.js","test:single":"./node_modules/karma/bin/karma start karma.conf.js --single-run","test-travis":"./scripts/test-travis.sh","serve:docs":"docsify serve docs","update:readme":"node ./scripts/updateReadme.js","update:docs":"node ./scripts/updateDocVersions.js $oldversion","publish:npm":"npm run build && npm publish","contributors:add":"all-contributors add","contributors:generate":"all-contributors generate","examples:serve":"live-server ./examples --port=8081 --mount=/:./examples --wait=250","examples:update-json":"node scripts/update-examples-json.js","examples:watch":"onchange -f 'addDir unlinkDir' './examples' -- npm run examples:update-json","preexamples:build":"rimraf dist_examples","examples:build":"npm run examples:update-json && webpack --config webpack.prod.babel.js --config-name examples"},repository:{type:"git",url:"git+https://github.com/ml5js/ml5-library.git"},keywords:["machine learning"],author:"NYU ITP <cvalenzuela@nyu.edu> (https://github.com/ml5js)",license:"MIT",bugs:{url:"https://github.com/ml5js/ml5-library/issues"},homepage:"https://github.com/ml5js/ml5-library#readme",devDependencies:{"all-contributors-cli":"^6.10.0","babel-cli":"6.26.0","babel-core":"6.26.0","babel-loader":"7.1.4","babel-plugin-transform-object-rest-spread":"^6.26.0","babel-plugin-transform-runtime":"^6.23.0","babel-polyfill":"6.26.0","babel-preset-env":"1.6.1","babel-register":"6.26.0",commitizen:"4.0.3","copy-webpack-plugin":"^5.1.1","cz-conventional-changelog":"2.1.0","docsify-cli":"^4.3.0",dotenv:"^8.2.0",eslint:"4.18.2","eslint-config-airbnb-base":"12.1.0","eslint-config-prettier":"^4.1.0","eslint-loader":"2.0.0","eslint-nibble":"^5.1.0","eslint-plugin-import":"2.9.0","extract-text-webpack-plugin":"4.0.0-beta.0",ghooks:"2.0.2","html-webpack-plugin":"^3.0.7","jasmine-core":"3.1.0",karma:"2.0.0","karma-browserstack-launcher":"^1.5.1","karma-chrome-launcher":"2.2.0","karma-jasmine":"1.1.1","karma-mocha-reporter":"^2.2.5","karma-safari-launcher":"1.0.0","karma-webpack":"3.0.0","live-server":"^1.2.1","npm-run-all":"^4.1.5",q:"^1.5.1","recursive-readdir":"^2.2.2","regenerator-runtime":"0.11.1","request-promise":"^4.2.5",rimraf:"2.6.2","semantic-release":"^15.13.26","uglifyjs-webpack-plugin":"^1.2.5",webpack:"4.1.1","webpack-cli":"2.0.10","webpack-dev-server":"3.10.3","webpack-merge":"^4.1.2"},config:{commitizen:{path:"node_modules/cz-conventional-changelog"}},files:["dist","README.md"],babel:{presets:[["env"]],plugins:["transform-runtime","transform-object-rest-spread"]},peerDependencies:{"@tensorflow/tfjs-core":"^1.2.9","@tensorflow/tfjs-converter":"^1.2.9"},dependencies:{"@magenta/sketch":"0.2.0","@tensorflow-models/body-pix":"1.1.2","@tensorflow-models/coco-ssd":"^2.0.0","@tensorflow-models/facemesh":"0.0.3","@tensorflow-models/handpose":"0.0.3","@tensorflow-models/knn-classifier":"1.2.1","@tensorflow-models/mobilenet":"2.0.3","@tensorflow-models/posenet":"^2.2.1","@tensorflow-models/speech-commands":"0.3.9","@tensorflow-models/universal-sentence-encoder":"^1.2.2","@tensorflow/tfjs":"^1.7.0","@tensorflow/tfjs-vis":"^1.1.0",axios:"^0.19.2",events:"^3.0.0","face-api.js":"~0.22.2",onchange:"^6.1.0"}}},function(t,e,n){var r=n(38);t.exports=function(t,e){if(!r(t)||t._t!==e)throw TypeError("Incompatible receiver, "+e+" required!");return t}},function(t,e,n){t.exports={default:n(332),__esModule:!0}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=l(n(54)),i=l(n(9)),a=l(n(24)),o=l(n(8)),s=l(n(7)),u=l(n(10)),c=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(4));function l(t){return t&&t.__esModule?t:{default:t}}var f=function(){function t(e){(0,s.default)(this,t),this.urlPath=e,"/"!==this.urlPath.charAt(this.urlPath.length-1)&&(this.urlPath+="/")}return(0,u.default)(t,[{key:"loadManifest",value:function(){var t=(0,o.default)(i.default.mark(function t(){var e=this;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new a.default(function(t,n){var r=new XMLHttpRequest;r.open("GET",e.urlPath+"manifest.json"),r.onload=function(){e.checkpointManifest=JSON.parse(r.responseText),t()},r.onerror=function(t){throw n(),new Error("manifest.json not found at "+e.urlPath+". "+t)},r.send()}));case 1:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"getCheckpointManifest",value:function(){var t=(0,o.default)(i.default.mark(function t(){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(null!=this.checkpointManifest){t.next=3;break}return t.next=3,this.loadManifest();case 3:return t.abrupt("return",this.checkpointManifest);case 4:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"getAllVariables",value:function(){var t=(0,o.default)(i.default.mark(function t(){var e,n,o=this;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(null==this.variables){t.next=2;break}return t.abrupt("return",a.default.resolve(this.variables));case 2:return t.next=4,this.getCheckpointManifest();case 4:return e=(0,r.default)(this.checkpointManifest),n=e.map(function(t){return o.getVariable(t)}),t.abrupt("return",a.default.all(n).then(function(t){o.variables={};for(var n=0;n<t.length;n+=1)o.variables[e[n]]=t[n];return o.variables}));case 7:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"getVariable",value:function(t){var e=this;if(!(t in this.checkpointManifest))throw new Error("Cannot load non-existent variable "+t);var n=function(n){var r=new XMLHttpRequest;r.responseType="arraybuffer";var i=e.checkpointManifest[t].filename;r.open("GET",e.urlPath+i),r.onload=function(){if(404===r.status)throw new Error("Not found variable "+t);var i=new Float32Array(r.response),a=c.tensor(i,e.checkpointManifest[t].shape);n(a)},r.onerror=function(e){throw new Error("Could not fetch variable "+t+": "+e)},r.send()};return null==this.checkpointManifest?new a.default(function(t){e.loadManifest().then(function(){new a.default(n).then(t)})}):new a.default(n)}}]),t}();e.default=f},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.CocoSsd=e.CocoSsdBase=void 0;var r=h(n(14)),i=h(n(9)),a=h(n(8)),o=h(n(7)),s=h(n(10)),u=d(n(4)),c=d(n(347)),l=h(n(15)),f=n(46);function d(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}function h(t){return t&&t.__esModule?t:{default:t}}var p={base:"lite_mobilenet_v2",modelUrl:void 0},m=e.CocoSsdBase=function(){function t(e,n,r){(0,o.default)(this,t),this.video=e||null,this.modelReady=!1,this.isPredicting=!1,this.config={base:n.base||p.base,modelUrl:n.modelUrl||p.modelUrl},this.callback=r,this.ready=(0,l.default)(this.loadModel(),this.callback)}return(0,s.default)(t,[{key:"loadModel",value:function(){var t=(0,a.default)(i.default.mark(function t(){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,c.load(this.config);case 2:return this.model=t.sent,this.modelReady=!0,t.abrupt("return",this);case 5:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"detectInternal",value:function(){var t=(0,a.default)(i.default.mark(function t(e){var n,r;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.isPredicting=!0,t.next=3,this.model.detect(e);case 3:return n=t.sent,r=n.map(function(t){return{label:t.class,confidence:t.score,x:t.bbox[0],y:t.bbox[1],width:t.bbox[2],height:t.bbox[3],normalized:{x:t.bbox[0]/e.width,y:t.bbox[1]/e.height,width:t.bbox[2]/e.width,height:t.bbox[3]/e.height}}}),this.isPredicting=!1,t.abrupt("return",r);case 7:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"detect",value:function(){var t=(0,a.default)(i.default.mark(function t(e,n){var a,o;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.ready;case 2:return t.next=4,u.nextFrame();case 4:if(a=void 0,o=n,!(0,f.isInstanceOfSupportedElement)(e)){t.next=10;break}a=e,t.next=24;break;case 10:if("object"!==(void 0===e?"undefined":(0,r.default)(e))||!(0,f.isInstanceOfSupportedElement)(e.elt)){t.next=14;break}a=e.elt,t.next=24;break;case 14:if("object"!==(void 0===e?"undefined":(0,r.default)(e))||!(0,f.isInstanceOfSupportedElement)(e.canvas)){t.next=18;break}a=e.canvas,t.next=24;break;case 18:if("function"!=typeof e){t.next=23;break}a=this.video,o=e,t.next=24;break;case 23:throw new Error("Detection subject not supported");case 24:return t.abrupt("return",(0,l.default)(this.detectInternal(a),o));case 25:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()}]),t}();e.CocoSsd=function(t,e,n){var i=null,a={},o=n;return t instanceof HTMLVideoElement?i=t:"object"===(void 0===t?"undefined":(0,r.default)(t))&&t.elt instanceof HTMLVideoElement?i=t.elt:"function"==typeof t?o=t:"object"===(void 0===t?"undefined":(0,r.default)(t))&&(a=t),"object"===(void 0===e?"undefined":(0,r.default)(e))?a=e:"function"==typeof e&&(o=e),new m(i,a,o)}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.YOLO=e.YOLOBase=void 0;var r=b(n(65)),i=b(n(14)),a=b(n(9)),o=b(n(8)),s=b(n(98)),u=b(n(7)),c=b(n(10)),l=b(n(97)),f=b(n(96)),d=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(4)),h=b(n(143)),p=n(46),m=b(n(15)),g=b(n(349)),v=b(n(142)),y=n(348);function b(t){return t&&t.__esModule?t:{default:t}}var x={modelUrl:"https://raw.githubusercontent.com/ml5js/ml5-data-and-training/master/models/YOLO/model.json",filterBoxesThreshold:.01,IOUThreshold:.4,classProbThreshold:.4},w=416,k=e.YOLOBase=function(t){function e(t,n,r){(0,u.default)(this,e);var i=(0,l.default)(this,(e.__proto__||(0,s.default)(e)).call(this,t,w));return i.modelUrl=n.modelUrl||x.modelUrl,i.filterBoxesThreshold=n.filterBoxesThreshold||x.filterBoxesThreshold,i.IOUThreshold=n.IOUThreshold||x.IOUThreshold,i.classProbThreshold=n.classProbThreshold||x.classProbThreshold,i.modelReady=!1,i.isPredicting=!1,i.callback=r,i.ready=(0,m.default)(i.loadModel(),i.callback),n.disableDeprecationNotice||console.warn("WARNING! Function YOLO has been deprecated, please use the new ObjectDetector function instead"),i}return(0,f.default)(e,t),(0,c.default)(e,[{key:"loadModel",value:function(){var t=(0,o.default)(a.default.mark(function t(){var e;return a.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.videoElt||this.video){t.next=4;break}return t.next=3,this.loadVideo();case 3:this.video=t.sent;case 4:if(!0!==v.default.isAbsoluteURL(this.modelUrl)){t.next=10;break}return t.next=7,d.loadLayersModel(this.modelUrl);case 7:this.model=t.sent,t.next=15;break;case 10:return e=v.default.getModelPath(this.modelUrl),this.modelUrl=e+"/model.json",t.next=14,d.loadLayersModel(this.modelUrl);case 14:this.model=t.sent;case 15:return this.modelReady=!0,t.abrupt("return",this);case 17:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"detect",value:function(){var t=(0,o.default)(a.default.mark(function t(e,n){var r,o;return a.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.ready;case 2:if(r=void 0,o=n,!(0,p.isInstanceOfSupportedElement)(e)){t.next=8;break}r=e,t.next=22;break;case 8:if("object"!==(void 0===e?"undefined":(0,i.default)(e))||!(0,p.isInstanceOfSupportedElement)(e.elt)){t.next=12;break}r=e.elt,t.next=22;break;case 12:if("object"!==(void 0===e?"undefined":(0,i.default)(e))||!(0,p.isInstanceOfSupportedElement)(e.canvas)){t.next=16;break}r=e.canvas,t.next=22;break;case 16:if("function"!=typeof e){t.next=21;break}r=this.video,o=e,t.next=22;break;case 21:throw new Error("Detection subject not supported");case 22:return t.abrupt("return",(0,m.default)(this.detectInternal(r),o));case 23:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"detectInternal",value:function(){var t=(0,o.default)(a.default.mark(function t(e){var n,i,o,s,u,c,l,f,h,m,v,b=this;return a.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.ready;case 2:return t.next=4,d.nextFrame();case 4:return n=d.tensor2d([[.57273,.677385],[1.87446,2.06253],[3.33843,5.47434],[7.88282,3.52778],[9.77052,9.16828]]),this.isPredicting=!0,i=d.tidy(function(){var t=(0,p.imgToTensor)(e,[w,w]),i=b.model.predict(t),a=(0,y.head)(i,n,80),o=(0,r.default)(a,4),s=o[0],u=o[1],c=o[2],l=o[3];return[(0,y.boxesToCorners)(s,u),c,l]}),o=(0,r.default)(i,3),s=o[0],u=o[1],c=o[2],t.next=9,(0,y.filterBoxes)(s,u,c,this.filterBoxesThreshold);case 9:if(l=t.sent,f=(0,r.default)(l,3),h=f[0],m=f[1],v=f[2],s.dispose(),u.dispose(),c.dispose(),null!=h){t.next=19;break}return t.abrupt("return",[]);case 19:return t.abrupt("return",d.tidy(function(){var t=d.scalar(w),e=d.scalar(w),i=d.stack([e,t,e,t]).reshape([1,4]),a=d.mul(h,i),o=a.dataSync(),s=m.dataSync(),u=(0,y.nonMaxSuppression)(o,s,b.IOUThreshold),c=(0,r.default)(u,3),l=c[0],f=c[1],p=c[2],x=[];return v.gather(d.tensor1d(l,"int32")).dataSync().forEach(function(t,e){var n=p[e];if(!(n<b.classProbThreshold)){var i=g.default[t],a=(0,r.default)(f[e],4),o=a[0],s=a[1],u=a[2],c=a[3];o=Math.max(0,o),s=Math.max(0,s),u=Math.min(w,u)-o;var l={label:i,confidence:n,x:s,y:o,width:c=Math.min(w,c)-s,height:u,normalized:{x:s/w,y:o/w,width:c/w,height:u/w}};x.push(l)}}),b.isPredicting=!1,t.dispose(),e.dispose(),i.dispose(),a.dispose(),h.dispose(),m.dispose(),v.dispose(),n.dispose(),x}));case 20:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()}]),e}(h.default);e.YOLO=function(t,e,n){var r=null,a={},o=n;return t instanceof HTMLVideoElement?r=t:"object"===(void 0===t?"undefined":(0,i.default)(t))&&t.elt instanceof HTMLVideoElement?r=t.elt:"function"==typeof t?o=t:"object"===(void 0===t?"undefined":(0,i.default)(t))&&(a=t),"object"===(void 0===e?"undefined":(0,i.default)(e))?a=e:"function"==typeof e&&(o=e),new k(r,a,o)}},function(t,e,n){var r=n(32),i=n(88),a=n(67),o=n(105).f;t.exports=function(t){return function(e){for(var n,s=a(e),u=i(s),c=u.length,l=0,f=[];c>l;)n=u[l++],r&&!o.call(s,n)||f.push(t?[n,s[n]]:s[n]);return f}}},function(t,e,n){t.exports={default:n(360),__esModule:!0}},function(t,e,n){var r=n(23),i=n(18),a=n(69);t.exports=function(t,e){var n=(i.Object||{})[t]||Object[t],o={};o[t]=e(n),r(r.S+r.F*a(function(){n(1)}),"Object",o)}},function(t,e){},function(t,e,n){"use strict";function r(t){this.message=t}r.prototype.toString=function(){return"Cancel"+(this.message?": "+this.message:"")},r.prototype.__CANCEL__=!0,t.exports=r},function(t,e,n){"use strict";var r=n(28);t.exports=function(t,e){e=e||{};var n={},i=["url","method","params","data"],a=["headers","auth","proxy"],o=["baseURL","url","transformRequest","transformResponse","paramsSerializer","timeout","withCredentials","adapter","responseType","xsrfCookieName","xsrfHeaderName","onUploadProgress","onDownloadProgress","maxContentLength","validateStatus","maxRedirects","httpAgent","httpsAgent","cancelToken","socketPath"];r.forEach(i,function(t){void 0!==e[t]&&(n[t]=e[t])}),r.forEach(a,function(i){r.isObject(e[i])?n[i]=r.deepMerge(t[i],e[i]):void 0!==e[i]?n[i]=e[i]:r.isObject(t[i])?n[i]=r.deepMerge(t[i]):void 0!==t[i]&&(n[i]=t[i])}),r.forEach(o,function(r){void 0!==e[r]?n[r]=e[r]:void 0!==t[r]&&(n[r]=t[r])});var s=i.concat(a).concat(o),u=Object.keys(e).filter(function(t){return-1===s.indexOf(t)});return r.forEach(u,function(r){void 0!==e[r]?n[r]=e[r]:void 0!==t[r]&&(n[r]=t[r])}),n}},function(t,e,n){"use strict";var r=n(391);t.exports=function(t,e,n,i,a){var o=new Error(t);return r(o,e,n,i,a)}},function(t,e,n){"use strict";var r=n(28),i=n(392),a=n(217),o=n(390),s=n(387),u=n(386),c=n(213);t.exports=function(t){return new Promise(function(e,l){var f=t.data,d=t.headers;r.isFormData(f)&&delete d["Content-Type"];var h=new XMLHttpRequest;if(t.auth){var p=t.auth.username||"",m=t.auth.password||"";d.Authorization="Basic "+btoa(p+":"+m)}var g=o(t.baseURL,t.url);if(h.open(t.method.toUpperCase(),a(g,t.params,t.paramsSerializer),!0),h.timeout=t.timeout,h.onreadystatechange=function(){if(h&&4===h.readyState&&(0!==h.status||h.responseURL&&0===h.responseURL.indexOf("file:"))){var n="getAllResponseHeaders"in h?s(h.getAllResponseHeaders()):null,r={data:t.responseType&&"text"!==t.responseType?h.response:h.responseText,status:h.status,statusText:h.statusText,headers:n,config:t,request:h};i(e,l,r),h=null}},h.onabort=function(){h&&(l(c("Request aborted",t,"ECONNABORTED",h)),h=null)},h.onerror=function(){l(c("Network Error",t,null,h)),h=null},h.ontimeout=function(){var e="timeout of "+t.timeout+"ms exceeded";t.timeoutErrorMessage&&(e=t.timeoutErrorMessage),l(c(e,t,"ECONNABORTED",h)),h=null},r.isStandardBrowserEnv()){var v=n(385),y=(t.withCredentials||u(g))&&t.xsrfCookieName?v.read(t.xsrfCookieName):void 0;y&&(d[t.xsrfHeaderName]=y)}if("setRequestHeader"in h&&r.forEach(d,function(t,e){void 0===f&&"content-type"===e.toLowerCase()?delete d[e]:h.setRequestHeader(e,t)}),r.isUndefined(t.withCredentials)||(h.withCredentials=!!t.withCredentials),t.responseType)try{h.responseType=t.responseType}catch(e){if("json"!==t.responseType)throw e}"function"==typeof t.onDownloadProgress&&h.addEventListener("progress",t.onDownloadProgress),"function"==typeof t.onUploadProgress&&h.upload&&h.upload.addEventListener("progress",t.onUploadProgress),t.cancelToken&&t.cancelToken.promise.then(function(t){h&&(h.abort(),l(t),h=null)}),void 0===f&&(f=null),h.send(f)})}},function(t,e,n){"use strict";(function(e){var r=n(28),i=n(393),a={"Content-Type":"application/x-www-form-urlencoded"};function o(t,e){!r.isUndefined(t)&&r.isUndefined(t["Content-Type"])&&(t["Content-Type"]=e)}var s={adapter:function(){var t;return"undefined"!=typeof XMLHttpRequest?t=n(214):void 0!==e&&"[object process]"===Object.prototype.toString.call(e)&&(t=n(214)),t}(),transformRequest:[function(t,e){return i(e,"Accept"),i(e,"Content-Type"),r.isFormData(t)||r.isArrayBuffer(t)||r.isBuffer(t)||r.isStream(t)||r.isFile(t)||r.isBlob(t)?t:r.isArrayBufferView(t)?t.buffer:r.isURLSearchParams(t)?(o(e,"application/x-www-form-urlencoded;charset=utf-8"),t.toString()):r.isObject(t)?(o(e,"application/json;charset=utf-8"),JSON.stringify(t)):t}],transformResponse:[function(t){if("string"==typeof t)try{t=JSON.parse(t)}catch(t){}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*"}}};r.forEach(["delete","get","head"],function(t){s.headers[t]={}}),r.forEach(["post","put","patch"],function(t){s.headers[t]=r.merge(a)}),t.exports=s}).call(this,n(87))},function(t,e,n){"use strict";t.exports=function(t){return!(!t||!t.__CANCEL__)}},function(t,e,n){"use strict";var r=n(28);function i(t){return encodeURIComponent(t).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}t.exports=function(t,e,n){if(!e)return t;var a;if(n)a=n(e);else if(r.isURLSearchParams(e))a=e.toString();else{var o=[];r.forEach(e,function(t,e){null!==t&&void 0!==t&&(r.isArray(t)?e+="[]":t=[t],r.forEach(t,function(t){r.isDate(t)?t=t.toISOString():r.isObject(t)&&(t=JSON.stringify(t)),o.push(i(e)+"="+i(t))}))}),a=o.join("&")}if(a){var s=t.indexOf("#");-1!==s&&(t=t.slice(0,s)),t+=(-1===t.indexOf("?")?"?":"&")+a}return t}},function(t,e,n){"use strict";t.exports=function(t,e){return function(){for(var n=new Array(arguments.length),r=0;r<n.length;r++)n[r]=arguments[r];return t.apply(e,n)}}},function(t,e,n){var r=n(105),i=n(108),a=n(67),o=n(164),s=n(68),u=n(246),c=Object.getOwnPropertyDescriptor;e.f=n(32)?c:function(t,e){if(t=a(t),e=o(e,!0),u)try{return c(t,e)}catch(t){}if(s(t,e))return i(!r.f.call(t,e),t[e])}},function(t,e,n){var r=n(245),i=n(158).concat("length","prototype");e.f=Object.getOwnPropertyNames||function(t){return r(t,i)}},function(t,e,n){var r=n(107);t.exports=Array.isArray||function(t){return"Array"==r(t)}},function(t,e,n){t.exports={default:n(413),__esModule:!0}},function(t,e,n){var r=n(25)("iterator"),i=!1;try{var a=[7][r]();a.return=function(){i=!0},Array.from(a,function(){throw 2})}catch(t){}t.exports=function(t,e){if(!e&&!i)return!1;var n=!1;try{var a=[7],o=a[r]();o.next=function(){return{done:n=!0}},a[r]=function(){return o},t(a)}catch(t){}return n}},function(t,e,n){"use strict";var r=n(26),i=n(18),a=n(39),o=n(32),s=n(25)("species");t.exports=function(t){var e="function"==typeof i[t]?i[t]:r[t];o&&e&&!e[s]&&a.f(e,s,{configurable:!0,get:function(){return this}})}},function(t,e,n){var r=n(48),i=n(38),a=n(149);t.exports=function(t,e){if(r(t),i(e)&&e.constructor===t)return e;var n=a.f(t);return(0,n.resolve)(e),n.promise}},function(t,e){t.exports=function(t){try{return{e:!1,v:t()}}catch(t){return{e:!0,v:t}}}},function(t,e,n){var r,i,a,o=n(56),s=n(418),u=n(233),c=n(165),l=n(26),f=l.process,d=l.setImmediate,h=l.clearImmediate,p=l.MessageChannel,m=l.Dispatch,g=0,v={},y=function(){var t=+this;if(v.hasOwnProperty(t)){var e=v[t];delete v[t],e()}},b=function(t){y.call(t.data)};d&&h||(d=function(t){for(var e=[],n=1;arguments.length>n;)e.push(arguments[n++]);return v[++g]=function(){s("function"==typeof t?t:Function(t),e)},r(g),g},h=function(t){delete v[t]},"process"==n(107)(f)?r=function(t){f.nextTick(o(y,t,1))}:m&&m.now?r=function(t){m.now(o(y,t,1))}:p?(a=(i=new p).port2,i.port1.onmessage=b,r=o(a.postMessage,a,1)):l.addEventListener&&"function"==typeof postMessage&&!l.importScripts?(r=function(t){l.postMessage(t+"","*")},l.addEventListener("message",b,!1)):r="onreadystatechange"in c("script")?function(t){u.appendChild(c("script")).onreadystatechange=function(){u.removeChild(this),y.call(t)}}:function(t){setTimeout(o(y,t,1),0)}),t.exports={set:d,clear:h}},function(t,e,n){var r=n(48),i=n(109),a=n(25)("species");t.exports=function(t,e){var n,o=r(t).constructor;return void 0===o||void 0==(n=r(o)[a])?e:i(n)}},function(t,e,n){var r=n(84),i=n(25)("iterator"),a=Array.prototype;t.exports=function(t){return void 0!==t&&(r.Array===t||a[i]===t)}},function(t,e,n){var r=n(48);t.exports=function(t,e,n,i){try{return i?e(r(n)[0],n[1]):e(n)}catch(e){var a=t.return;throw void 0!==a&&r(a.call(t)),e}}},function(t,e){t.exports=function(t,e){return{value:e,done:!!t}}},function(t,e,n){var r=n(68),i=n(66),a=n(160)("IE_PROTO"),o=Object.prototype;t.exports=Object.getPrototypeOf||function(t){return t=i(t),r(t,a)?t[a]:"function"==typeof t.constructor&&t instanceof t.constructor?t.constructor.prototype:t instanceof Object?o:null}},function(t,e,n){var r=n(26).document;t.exports=r&&r.documentElement},function(t,e,n){t.exports=n(60)},function(t,e,n){"use strict";
  206. /**
  207. * @license
  208. * Copyright 2018 Google LLC. All Rights Reserved.
  209. * Licensed under the Apache License, Version 2.0 (the "License");
  210. * you may not use this file except in compliance with the License.
  211. * You may obtain a copy of the License at
  212. *
  213. * http://www.apache.org/licenses/LICENSE-2.0
  214. *
  215. * Unless required by applicable law or agreed to in writing, software
  216. * distributed under the License is distributed on an "AS IS" BASIS,
  217. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  218. * See the License for the specific language governing permissions and
  219. * limitations under the License.
  220. * =============================================================================
  221. */var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})},i=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const a=i(n(82)),o=n(59),s=n(120),u=n(37);e.linechart=function(t,e,n={}){return r(this,void 0,void 0,function*(){const r=Array.isArray(e.values[0])?e.values:[e.values],i=r[0].length,l=e.series?e.series:r.map((t,e)=>`Series ${e+1}`);s.assert(l.length===r.length,"Must have an equal number of series labels as there are data series"),null!=n.seriesColors&&s.assert(n.seriesColors.length===r.length,"Must have an equal number of series colors as there are data series");const f=[];for(let t=0;t<i;t++){const e={x:t};l.forEach((n,i)=>{const a=r[i][t].y;e[n]=a,e[`${n}-name`]=n}),f.push(e)}const d=Object.assign({},c,n),h={x:{field:"x",type:d.xType,title:d.xLabel},tooltip:[{field:"x",type:"quantitative"},...l.map(t=>({field:t,type:"quantitative"}))]},p=l.map(t=>({data:void 0,mark:{type:"line",clip:!0},encoding:{y:{field:t,type:d.yType,title:d.yLabel,scale:d.zoomToFit?{zero:!1}:null!=d.yAxisDomain?{domain:d.yAxisDomain}:void 0},color:{field:`${t}-name`,type:"nominal",legend:{values:l,title:null},scale:{range:d.seriesColors}}}})),m=u.getDrawArea(t),g={width:d.width||o.getDefaultWidth(m),height:d.height||o.getDefaultHeight(m),padding:0,autosize:{type:"fit",contains:"padding",resize:!0},config:{axis:{labelFontSize:d.fontSize,titleFontSize:d.fontSize},text:{fontSize:d.fontSize},legend:{labelFontSize:d.fontSize,titleFontSize:d.fontSize}},data:{values:f},encoding:h,layer:[...p,{mark:"rule",selection:{hover:{type:"single",on:"mouseover",nearest:!0,clear:"mouseout"}},encoding:{color:{value:"grey",condition:{selection:{not:"hover"},value:"transparent"}}}}]};return yield a.default(m,g,{actions:!1,mode:"vega-lite",defaultStyle:!1}),Promise.resolve()})};const c={xLabel:"x",yLabel:"y",xType:"quantitative",yType:"quantitative",zoomToFit:!1,fontSize:11}},function(t,e,n){"use strict";
  222. /**
  223. * @license
  224. * Copyright 2018 Google LLC. All Rights Reserved.
  225. * Licensed under the Apache License, Version 2.0 (the "License");
  226. * you may not use this file except in compliance with the License.
  227. * You may obtain a copy of the License at
  228. *
  229. * http://www.apache.org/licenses/LICENSE-2.0
  230. *
  231. * Unless required by applicable law or agreed to in writing, software
  232. * distributed under the License is distributed on an "AS IS" BASIS,
  233. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  234. * See the License for the specific language governing permissions and
  235. * limitations under the License.
  236. * =============================================================================
  237. */Object.defineProperty(e,"__esModule",{value:!0});const r=n(439);let i;const a="Visor",o="tfjs-visor-container";e.visor=function(){if("undefined"==typeof document)throw new Error("No document defined. This library needs a browser/dom to work");if(document.getElementById(o)&&null!=i)return i;let t,e=document.getElementById(o);function n(e,n){let i=null;return t=r.VisorComponent.render(e,t,{ref:t=>i=t,surfaceList:Array.from(n.values())}),i}null==e&&((e=document.createElement("div")).id=o,document.body.appendChild(e));const a=new Map,u=n(e,a);return i=new s(u,e,a,n)};class s{constructor(t,e,n,r){this.visorComponent=t,this.el=e,this.surfaceList=n,this.renderVisor=r}surface(t){const{name:e}=t,n=null==t.tab?a:t.tab;if(null==e||!("string"==typeof e||e instanceof String))throw new Error("You must pass a config object with a 'name' property to create or retrieve a surface");const r=Object.assign({},t,{tab:n}),i=`${e}-${n}`;return this.surfaceList.has(i)||this.surfaceList.set(i,r),this.renderVisor(this.el,this.surfaceList),this.visorComponent.getSurface(e,n)}isFullscreen(){return this.visorComponent.isFullscreen()}isOpen(){return this.visorComponent.isOpen()}close(){return this.visorComponent.close()}open(){return this.visorComponent.open()}toggle(){return this.visorComponent.toggle()}toggleFullScreen(){return this.visorComponent.toggleFullScreen()}bindKeys(){return this.visorComponent.bindKeys()}unbindKeys(){return this.visorComponent.unbindKeys()}setActiveTab(t){if(!this.visorComponent.state.tabs.has(t))throw new Error(`Tab '${t}' does not exist`);this.visorComponent.setState({activeTab:t})}}e.Visor=s},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.isSurfaceInfo=function(t){return null!=t.name},e.isSurface=function(t){return t.drawArea instanceof HTMLElement}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){return t.charAt(0).toUpperCase()+t.slice(1)},t.exports=e.default},function(t,e,n){"use strict";var r=n(462);t.exports=r},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.processStyleName=void 0,e.createMarkupForStyles=function(t,e){var n="";for(var i in t){var a=0===i.indexOf("--");if(t.hasOwnProperty(i)&&"label"!==i){var o=t[i];0,null!=o&&(a?n+=i+":"+o+";":(n+=s(i)+":",n+=(0,r.default)(i,o,e)+";"))}}return n||null};o(n(466));var r=o(n(464)),i=o(n(461)),a=o(n(459));o(n(239));function o(t){return t&&t.__esModule?t:{default:t}}var s=e.processStyleName=(0,a.default)(i.default)},function(t){t.exports={a:"5.4.0"}},function(t,e,n){"use strict";n.r(e),n.d(e,"default",function(){return o}),n.d(e,"point",function(){return s});var r=n(null),i=n(null),a=n(null);function o(){var t,e,n=Object(a.a)().unknown(void 0),s=n.domain,u=n.range,c=0,l=1,f=!1,d=0,h=0,p=.5;function m(){var n=s().length,i=l<c,a=i?l:c,o=i?c:l;t=(o-a)/Math.max(1,n-d+2*h),f&&(t=Math.floor(t)),a+=(o-a-t*(n-d))*p,e=t*(1-d),f&&(a=Math.round(a),e=Math.round(e));var m=Object(r.a)(n).map(function(e){return a+t*e});return u(i?m.reverse():m)}return delete n.unknown,n.domain=function(t){return arguments.length?(s(t),m()):s()},n.range=function(t){return arguments.length?([c,l]=t,c=+c,l=+l,m()):[c,l]},n.rangeRound=function(t){return[c,l]=t,c=+c,l=+l,f=!0,m()},n.bandwidth=function(){return e},n.step=function(){return t},n.round=function(t){return arguments.length?(f=!!t,m()):f},n.padding=function(t){return arguments.length?(d=Math.min(1,h=+t),m()):d},n.paddingInner=function(t){return arguments.length?(d=Math.min(1,t),m()):d},n.paddingOuter=function(t){return arguments.length?(h=+t,m()):h},n.align=function(t){return arguments.length?(p=Math.max(0,Math.min(1,t)),m()):p},n.copy=function(){return o(s(),[c,l]).round(f).paddingInner(d).paddingOuter(h).align(p)},i.a.apply(m(),arguments)}function s(){return function t(e){var n=e.copy;return e.padding=e.paddingOuter,delete e.paddingInner,delete e.paddingOuter,e.copy=function(){return t(n())},e}(o.apply(null,arguments).paddingInner(1))}},function(t,e,n){"use strict";
  238. /**
  239. * @license
  240. * Copyright 2018 Google LLC. All Rights Reserved.
  241. * Licensed under the Apache License, Version 2.0 (the "License");
  242. * you may not use this file except in compliance with the License.
  243. * You may obtain a copy of the License at
  244. *
  245. * http://www.apache.org/licenses/LICENSE-2.0
  246. *
  247. * Unless required by applicable law or agreed to in writing, software
  248. * distributed under the License is distributed on an "AS IS" BASIS,
  249. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  250. * See the License for the specific language governing permissions and
  251. * limitations under the License.
  252. * =============================================================================
  253. */Object.defineProperty(e,"__esModule",{value:!0});const r=n(474),i=n(436),a=n(435),o=n(154),s=n(235),u=n(434),c=n(118),l=n(433),f=n(432),d=n(431),h=n(430),p=n(119),m=n(429);e.version_vis=m.version;const g={barchart:r.barchart,table:c.table,histogram:o.histogram,linechart:s.linechart,scatterplot:u.scatterplot,confusionMatrix:i.confusionMatrix,heatmap:a.heatmap};e.render=g;const v={accuracy:p.accuracy,perClassAccuracy:p.perClassAccuracy,confusionMatrix:p.confusionMatrix};e.metrics=v;const y={history:l.history,fitCallbacks:l.fitCallbacks,perClassAccuracy:d.showPerClassAccuracy,valuesDistribution:h.valuesDistribution,layer:f.layer,modelSummary:f.modelSummary};e.show=y;var b=n(236);e.visor=b.visor,function(t){for(var n in t)e.hasOwnProperty(n)||(e[n]=t[n])}(n(237))},function(t,e,n){(function(t){var r=void 0!==t&&t||"undefined"!=typeof self&&self||window,i=Function.prototype.apply;function a(t,e){this._id=t,this._clearFn=e}e.setTimeout=function(){return new a(i.call(setTimeout,r,arguments),clearTimeout)},e.setInterval=function(){return new a(i.call(setInterval,r,arguments),clearInterval)},e.clearTimeout=e.clearInterval=function(t){t&&t.close()},a.prototype.unref=a.prototype.ref=function(){},a.prototype.close=function(){this._clearFn.call(r,this._id)},e.enroll=function(t,e){clearTimeout(t._idleTimeoutId),t._idleTimeout=e},e.unenroll=function(t){clearTimeout(t._idleTimeoutId),t._idleTimeout=-1},e._unrefActive=e.active=function(t){clearTimeout(t._idleTimeoutId);var e=t._idleTimeout;e>=0&&(t._idleTimeoutId=setTimeout(function(){t._onTimeout&&t._onTimeout()},e))},n(481),e.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==t&&t.setImmediate||this&&this.setImmediate,e.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==t&&t.clearImmediate||this&&this.clearImmediate}).call(this,n(53))},function(t,e,n){var r=n(68),i=n(67),a=n(486)(!1),o=n(160)("IE_PROTO");t.exports=function(t,e){var n,s=i(t),u=0,c=[];for(n in s)n!=o&&r(s,n)&&c.push(n);for(;e.length>u;)r(s,n=e[u++])&&(~a(c,n)||c.push(n));return c}},function(t,e,n){t.exports=!n(32)&&!n(69)(function(){return 7!=Object.defineProperty(n(165)("div"),"a",{get:function(){return 7}}).a})},function(t,e){t.exports=Math.scale||function(t,e,n,r,i){return 0===arguments.length||t!=t||e!=e||n!=n||r!=r||i!=i?NaN:t===1/0||t===-1/0?t:(t-e)*(i-r)/(n-e)+r}},function(t,e,n){var r=n(72);t.exports=function(t,e){var n=[];return r(t,!1,n.push,n,e),n}},function(t,e,n){var r=n(93),i=n(248);t.exports=function(t){return function(){if(r(this)!=t)throw TypeError(t+"#toJSON isn't generic");return i(this)}}},function(t,e,n){var r=n(19),i=n(78),a=n(35),o=n(112).f;t.exports=function(t){return function(e){for(var n,s=a(e),u=i(s),c=u.length,l=0,f=[];c>l;)n=u[l++],r&&!o.call(s,n)||f.push(t?[n,s[n]]:s[n]);return f}}},function(t,e,n){var r=n(17),i=n(184),a=n(51);t.exports=function(t,e,n,o){var s=String(a(t)),u=s.length,c=void 0===n?" ":String(n),l=r(e);if(l<=u||""==c)return s;var f=l-u,d=i.call(c,Math.ceil(f/c.length));return d.length>f&&(d=d.slice(0,f)),o?d+s:s+d}},function(t,e,n){"use strict";var r=n(134),i=n(13),a=n(17),o=n(43),s=n(16)("isConcatSpreadable");t.exports=function t(e,n,u,c,l,f,d,h){for(var p,m,g=l,v=0,y=!!d&&o(d,h,3);v<c;){if(v in u){if(p=y?y(u[v],v,n):u[v],m=!1,i(p)&&(m=void 0!==(m=p[s])?!!m:r(p)),m&&f>0)g=t(e,n,p,a(p.length),g,f-1)-1;else{if(g>=9007199254740991)throw TypeError();e[g]=p}g++}v++}return g}},function(t,e,n){var r=n(75),i=n(135),a=n(6),o=n(11).Reflect;t.exports=o&&o.ownKeys||function(t){var e=r.f(a(t)),n=i.f;return n?e.concat(n(t)):e}},function(t,e,n){var r=n(41),i=n(17);t.exports=function(t){if(void 0===t)return 0;var e=r(t),n=i(e);if(e!==n)throw RangeError("Wrong length!");return n}},function(t,e,n){"use strict";var r=n(71),i=n(62).getWeak,a=n(6),o=n(13),s=n(73),u=n(72),c=n(49),l=n(36),f=n(70),d=c(5),h=c(6),p=0,m=function(t){return t._l||(t._l=new g)},g=function(){this.a=[]},v=function(t,e){return d(t.a,function(t){return t[0]===e})};g.prototype={get:function(t){var e=v(this,t);if(e)return e[1]},has:function(t){return!!v(this,t)},set:function(t,e){var n=v(this,t);n?n[1]=e:this.a.push([t,e])},delete:function(t){var e=h(this.a,function(e){return e[0]===t});return~e&&this.a.splice(e,1),!!~e}},t.exports={getConstructor:function(t,e,n,a){var c=t(function(t,r){s(t,c,e,"_i"),t._t=e,t._i=p++,t._l=void 0,void 0!=r&&u(r,n,t[a],t)});return r(c.prototype,{delete:function(t){if(!o(t))return!1;var n=i(t);return!0===n?m(f(this,e)).delete(t):n&&l(n,this._i)&&delete n[this._i]},has:function(t){if(!o(t))return!1;var n=i(t);return!0===n?m(f(this,e)).has(t):n&&l(n,this._i)}}),c},def:function(t,e,n){var r=i(a(e),!0);return!0===r?m(t).set(e,n):r[t._i]=n,t},ufstore:m}},function(t,e,n){"use strict";var r,i=n(11),a=n(49)(0),o=n(30),s=n(62),u=n(277),c=n(255),l=n(13),f=n(70),d=n(70),h=!i.ActiveXObject&&"ActiveXObject"in i,p=s.getWeak,m=Object.isExtensible,g=c.ufstore,v=function(t){return function(){return t(this,arguments.length>0?arguments[0]:void 0)}},y={get:function(t){if(l(t)){var e=p(t);return!0===e?g(f(this,"WeakMap")).get(t):e?e[this._i]:void 0}},set:function(t,e){return c.def(f(this,"WeakMap"),t,e)}},b=t.exports=n(127)("WeakMap",v,y,c,!0,!0);d&&h&&(u((r=c.getConstructor(v,"WeakMap")).prototype,y),s.NEED=!0,a(["delete","has","get","set"],function(t){var e=b.prototype,n=e[t];o(e,t,function(e,i){if(l(e)&&!m(e)){this._f||(this._f=new r);var a=this._f[t](e,i);return"set"==t?this:a}return n.call(this,e,i)})}))},function(t,e,n){"use strict";var r=n(258),i=n(70);t.exports=n(127)("Set",function(t){return function(){return t(this,arguments.length>0?arguments[0]:void 0)}},{add:function(t){return r.def(i(this,"Set"),t=0===t?0:t,t)}},r)},function(t,e,n){"use strict";var r=n(21).f,i=n(76),a=n(71),o=n(43),s=n(73),u=n(72),c=n(181),l=n(264),f=n(74),d=n(19),h=n(62).fastKey,p=n(70),m=d?"_s":"size",g=function(t,e){var n,r=h(e);if("F"!==r)return t._i[r];for(n=t._f;n;n=n.n)if(n.k==e)return n};t.exports={getConstructor:function(t,e,n,c){var l=t(function(t,r){s(t,l,e,"_i"),t._t=e,t._i=i(null),t._f=void 0,t._l=void 0,t[m]=0,void 0!=r&&u(r,n,t[c],t)});return a(l.prototype,{clear:function(){for(var t=p(this,e),n=t._i,r=t._f;r;r=r.n)r.r=!0,r.p&&(r.p=r.p.n=void 0),delete n[r.i];t._f=t._l=void 0,t[m]=0},delete:function(t){var n=p(this,e),r=g(n,t);if(r){var i=r.n,a=r.p;delete n._i[r.i],r.r=!0,a&&(a.n=i),i&&(i.p=a),n._f==r&&(n._f=i),n._l==r&&(n._l=a),n[m]--}return!!r},forEach:function(t){p(this,e);for(var n,r=o(t,arguments.length>1?arguments[1]:void 0,3);n=n?n.n:this._f;)for(r(n.v,n.k,this);n&&n.r;)n=n.p},has:function(t){return!!g(p(this,e),t)}}),d&&r(l.prototype,"size",{get:function(){return p(this,e)[m]}}),l},def:function(t,e,n){var r,i,a=g(t,e);return a?a.v=n:(t._l=a={i:i=h(e,!0),k:e,v:n,p:r=t._l,n:void 0,r:!1},t._f||(t._f=a),r&&(r.n=a),t[m]++,"F"!==i&&(t._i[i]=a)),t},getEntry:g,setStrong:function(t,e,n){c(t,e,function(t,n){this._t=p(t,e),this._k=n,this._l=void 0},function(){for(var t=this._k,e=this._l;e&&e.r;)e=e.p;return this._t&&(this._l=e=e?e.n:this._t._f)?l(0,"keys"==t?e.k:"values"==t?e.v:[e.k,e.v]):(this._t=void 0,l(1))},n?"entries":"values",!n,!0),f(e)}}},function(t,e,n){"use strict";var r=n(258),i=n(70);t.exports=n(127)("Map",function(t){return function(){return t(this,arguments.length>0?arguments[0]:void 0)}},{get:function(t){var e=r.getEntry(i(this,"Map"),t);return e&&e.v},set:function(t,e){return r.def(i(this,"Map"),0===t?0:t,e)}},r,!0)},function(t,e,n){var r=n(6),i=n(13),a=n(167);t.exports=function(t,e){if(r(t),i(e)&&e.constructor===t)return e;var n=a.f(t);return(0,n.resolve)(e),n.promise}},function(t,e){t.exports=function(t){try{return{e:!1,v:t()}}catch(t){return{e:!0,v:t}}}},function(t,e,n){n(19)&&"g"!=/./g.flags&&n(21).f(RegExp.prototype,"flags",{configurable:!0,get:n(111)})},function(t,e,n){"use strict";var r=n(171);n(5)({target:"RegExp",proto:!0,forced:r!==/./.exec},{exec:r})},function(t,e){t.exports=function(t,e){return{value:e,done:!!t}}},function(t,e,n){"use strict";var r=n(22),i=n(77),a=n(17);t.exports=[].copyWithin||function(t,e){var n=r(this),o=a(n.length),s=i(t,o),u=i(e,o),c=arguments.length>2?arguments[2]:void 0,l=Math.min((void 0===c?o:i(c,o))-u,o-s),f=1;for(u<s&&s<u+l&&(f=-1,u+=l-1,s+=l-1);l-- >0;)u in n?n[s]=n[u]:delete n[s],s+=f,u+=f;return n}},function(t,e,n){var r=n(27),i=n(22),a=n(113),o=n(17);t.exports=function(t,e,n,s,u){r(e);var c=i(t),l=a(c),f=o(c.length),d=u?f-1:0,h=u?-1:1;if(n<2)for(;;){if(d in l){s=l[d],d+=h;break}if(d+=h,u?d<0:f<=d)throw TypeError("Reduce of empty array with no initial value")}for(;u?d>=0:f>d;d+=h)d in l&&(s=e(s,l[d],d,c));return s}},function(t,e,n){var r=n(6);t.exports=function(t,e,n,i){try{return i?e(r(n)[0],n[1]):e(n)}catch(e){var a=t.return;throw void 0!==a&&r(a.call(t)),e}}},function(t,e,n){var r=n(183),i=Math.pow,a=i(2,-52),o=i(2,-23),s=i(2,127)*(2-o),u=i(2,-126);t.exports=Math.fround||function(t){var e,n,i=Math.abs(t),c=r(t);return i<u?c*function(t){return t+1/a-1/a}(i/u/o)*u*o:(n=(e=(1+o/a)*i)-(e-i))>s||n!=n?c*(1/0):c*n}},function(t,e){t.exports=Math.log1p||function(t){return(t=+t)>-1e-8&&t<1e-8?t-t*t/2:Math.log(1+t)}},function(t,e,n){var r=n(13),i=Math.floor;t.exports=function(t){return!r(t)&&isFinite(t)&&i(t)===t}},function(t,e,n){var r=n(42);t.exports=function(t,e){if("number"!=typeof t&&"Number"!=r(t))throw TypeError(e);return+t}},function(t,e,n){var r=n(11).parseFloat,i=n(92).trim;t.exports=1/r(n(186)+"-0")!=-1/0?function(t){var e=i(String(t),3),n=r(e);return 0===n&&"-"==e.charAt(0)?-0:n}:r},function(t,e,n){var r=n(11).parseInt,i=n(92).trim,a=n(186),o=/^[-+]?0[xX]/;t.exports=8!==r(a+"08")||22!==r(a+"0x16")?function(t,e){var n=i(String(t),3);return r(n,e>>>0||(o.test(n)?16:10))}:r},function(t,e){t.exports=function(t,e,n){var r=void 0===n;switch(e.length){case 0:return r?t():t.call(n);case 1:return r?t(e[0]):t.call(n,e[0]);case 2:return r?t(e[0],e[1]):t.call(n,e[0],e[1]);case 3:return r?t(e[0],e[1],e[2]):t.call(n,e[0],e[1],e[2]);case 4:return r?t(e[0],e[1],e[2],e[3]):t.call(n,e[0],e[1],e[2],e[3])}return t.apply(n,e)}},function(t,e,n){"use strict";var r=n(27),i=n(13),a=n(274),o=[].slice,s={};t.exports=Function.bind||function(t){var e=r(this),n=o.call(arguments,1),u=function(){var r=n.concat(o.call(arguments));return this instanceof u?function(t,e,n){if(!(e in s)){for(var r=[],i=0;i<e;i++)r[i]="a["+i+"]";s[e]=Function("F,a","return new F("+r.join(",")+")")}return s[e](t,n)}(e,r.length,r):a(e,r,t)};return i(e.prototype)&&(u.prototype=e.prototype),u}},function(t,e){t.exports=Object.is||function(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e}},function(t,e,n){"use strict";var r=n(19),i=n(78),a=n(135),o=n(112),s=n(22),u=n(113),c=Object.assign;t.exports=!c||n(12)(function(){var t={},e={},n=Symbol(),r="abcdefghijklmnopqrst";return t[n]=7,r.split("").forEach(function(t){e[t]=t}),7!=c({},t)[n]||Object.keys(c({},e)).join("")!=r})?function(t,e){for(var n=s(t),c=arguments.length,l=1,f=a.f,d=o.f;c>l;)for(var h,p=u(arguments[l++]),m=f?i(p).concat(f(p)):i(p),g=m.length,v=0;g>v;)h=m[v++],r&&!d.call(p,h)||(n[h]=p[h]);return n}:c},function(t,e,n){var r=n(35),i=n(75).f,a={}.toString,o="object"==typeof window&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];t.exports.f=function(t){return o&&"[object Window]"==a.call(t)?function(t){try{return i(t)}catch(t){return o.slice()}}(t):i(r(t))}},function(t,e,n){var r=n(21),i=n(6),a=n(78);t.exports=n(19)?Object.defineProperties:function(t,e){i(t);for(var n,o=a(e),s=o.length,u=0;s>u;)r.f(t,n=o[u++],e[n]);return t}},function(t,e,n){var r=n(36),i=n(35),a=n(136)(!1),o=n(190)("IE_PROTO");t.exports=function(t,e){var n,s=i(t),u=0,c=[];for(n in s)n!=o&&r(s,n)&&c.push(n);for(;e.length>u;)r(s,n=e[u++])&&(~a(c,n)||c.push(n));return c}},function(t,e,n){e.f=n(16)},function(t,e,n){t.exports=!n(19)&&!n(12)(function(){return 7!=Object.defineProperty(n(192)("div"),"a",{get:function(){return 7}}).a})},function(t){t.exports={name:"vega-tooltip",version:"0.19.1",description:"A tooltip plugin for Vega-Lite and Vega visualizations.",main:"build/vega-tooltip.js",module:"build/src/index.js",unpkg:"build/vega-tooltip.min.js",jsdelivr:"build/vega-tooltip.min.js",typings:"build/src/index.d.ts",repository:{type:"git",url:"https://github.com/vega/vega-tooltip.git"},keywords:["vega-lite","vega","tooltip"],author:{name:"UW Interactive Data Lab",url:"https://idl.cs.washington.edu"},collaborators:["Dominik Moritz","Sira Horradarn","Zening Qu","Kanit Wongsuphasawat","Yuri Astrakhan","Jeffrey Heer"],license:"BSD-3-Clause",bugs:{url:"https://github.com/vega/vega-tooltip/issues"},homepage:"https://github.com/vega/vega-tooltip#readme",scripts:{prepare:"beemo create-config --silent","tsc:src":"tsc -b tsconfig.src.json",build:"yarn tsc:src && rollup -c",clean:"rm -rf build examples/data && rm -f src/style.ts","copy:data":"rsync -r node_modules/vega-datasets/data/* examples/data","copy:build":"rsync -r build/* examples/build","deploy:gh":"yarn build && yarn copy:build && gh-pages -d examples && yarn clean",prettierbase:"beemo prettier 'examples/*.{html,scss,css}'",eslintbase:"beemo eslint '{src,test,types}/**/*.ts'",format:"yarn eslintbase --fix && yarn prettierbase --write",lint:"yarn eslintbase && yarn prettierbase --check",postbuild:"terser build/vega-tooltip.js -c -m -o build/vega-tooltip.min.js",prebuild:"mkdir -p build && yarn copy:data && ./build-style.sh",prepublishOnly:"yarn clean && yarn build",preversion:"yarn lint",start:"yarn build && concurrently --kill-others -n Server,Typescript,Rollup 'browser-sync start -s -f build examples --serveStatic examples' 'yarn tsc:src -w' 'rollup -c -w'",pretest:"./build-style.sh",test:"jest"},devDependencies:{"@types/jest":"^24.0.18","browser-sync":"^2.26.7",concurrently:"^4.1.2","gh-pages":"^2.1.1",jest:"^24.9.0","node-sass":"^4.12.0",path:"^0.12.7",rollup:"^1.20.3","rollup-plugin-commonjs":"^10.1.0","rollup-plugin-json":"^4.0.0","rollup-plugin-node-resolve":"^5.2.0",terser:"^4.2.1","ts-jest":"^24.0.2",typescript:"^3.6.2","vega-datasets":"^1.25.0","vega-lite-dev-config":"^0.2.5","vega-typings":"^0.8.1"},dependencies:{"vega-util":"^1.11.1"},beemo:{module:"vega-lite-dev-config",drivers:["prettier","eslint"]},jest:{testURL:"http://localhost/",transform:{"^.+\\.tsx?$":"ts-jest"},testRegex:"(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",moduleFileExtensions:["ts","tsx","js","jsx","json","node"],testPathIgnorePatterns:["node_modules","<rootDir>/build","src"]}}},function(t){t.exports={name:"vega-themes",version:"2.8.3",description:"Themes for stylized Vega and Vega-Lite visualizations.",keywords:["vega","vega-lite","themes","style"],license:"BSD-3-Clause",author:{name:"UW Interactive Data Lab",url:"https://idl.cs.washington.edu"},contributors:[{name:"Emily Gu",url:"https://github.com/emilygu"},{name:"Arvind Satyanarayan",url:"http://arvindsatya.com"},{name:"Jeffrey Heer",url:"https://idl.cs.washington.edu"},{name:"Dominik Moritz",url:"https://www.domoritz.de"}],main:"build/vega-themes.js",module:"build/src/index.js",unpkg:"build/vega-themes.min.js",jsdelivr:"build/vega-themes.min.js",typings:"build/src/index.d.ts",repository:{type:"git",url:"https://github.com/vega/vega-themes.git"},scripts:{prepare:"beemo create-config --silent",clean:"rm -rf build examples/build",prettierbase:"beemo prettier 'examples/*.{html,scss,css}'",eslintbase:"beemo eslint 'src/**/*.ts'",format:"yarn eslintbase --fix && yarn prettierbase --write",lint:"yarn eslintbase && yarn prettierbase --check",prebuild:"mkdir -p build",build:"tsc && rollup -c",postbuild:"terser build/vega-themes.js -cm > build/vega-themes.min.js","deploy:gh":"yarn build && mkdir -p examples/build && rsync -r build/* examples/build && gh-pages -d examples",prepublishOnly:"yarn clean && yarn build",preversion:"yarn lint",serve:"browser-sync start -s -f build examples --serveStatic examples",start:"yarn build && concurrently --kill-others -n Server,Typescript,Rollup 'yarn serve' 'tsc -w' 'rollup -c -w'"},devDependencies:{"@rollup/plugin-json":"^4.0.2","browser-sync":"^2.26.7",concurrently:"^5.1.0","gh-pages":"^2.2.0",rollup:"^2.1.0",terser:"^4.6.7",typescript:"^3.8.3",vega:"^5.10.0","vega-lite":"^4.8.1","vega-lite-dev-config":"^0.5.0"},peerDependencies:{vega:"*","vega-lite":"*"},beemo:{module:"vega-lite-dev-config",drivers:["prettier","eslint"]}}},function(t,e,n){"use strict";t.exports=function t(e,n){if(e===n)return!0;if(e&&n&&"object"==typeof e&&"object"==typeof n){if(e.constructor!==n.constructor)return!1;var r,i,a;if(Array.isArray(e)){if((r=e.length)!=n.length)return!1;for(i=r;0!=i--;)if(!t(e[i],n[i]))return!1;return!0}if(e.constructor===RegExp)return e.source===n.source&&e.flags===n.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===n.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===n.toString();if((r=(a=Object.keys(e)).length)!==Object.keys(n).length)return!1;for(i=r;0!=i--;)if(!Object.prototype.hasOwnProperty.call(n,a[i]))return!1;for(i=r;0!=i--;){var o=a[i];if(!t(e[o],n[o]))return!1}return!0}return e!=e&&n!=n}},function(t,e,n){(function(e){var n=function(){"use strict";function t(t,e){return null!=e&&t instanceof e}var n,r,i;try{n=Map}catch(t){n=function(){}}try{r=Set}catch(t){r=function(){}}try{i=Promise}catch(t){i=function(){}}function a(o,u,c,l,f){"object"==typeof u&&(c=u.depth,l=u.prototype,f=u.includeNonEnumerable,u=u.circular);var d=[],h=[],p=void 0!==e;return void 0===u&&(u=!0),void 0===c&&(c=1/0),function o(c,m){if(null===c)return null;if(0===m)return c;var g,v;if("object"!=typeof c)return c;if(t(c,n))g=new n;else if(t(c,r))g=new r;else if(t(c,i))g=new i(function(t,e){c.then(function(e){t(o(e,m-1))},function(t){e(o(t,m-1))})});else if(a.__isArray(c))g=[];else if(a.__isRegExp(c))g=new RegExp(c.source,s(c)),c.lastIndex&&(g.lastIndex=c.lastIndex);else if(a.__isDate(c))g=new Date(c.getTime());else{if(p&&e.isBuffer(c))return g=e.allocUnsafe?e.allocUnsafe(c.length):new e(c.length),c.copy(g),g;t(c,Error)?g=Object.create(c):void 0===l?(v=Object.getPrototypeOf(c),g=Object.create(v)):(g=Object.create(l),v=l)}if(u){var y=d.indexOf(c);if(-1!=y)return h[y];d.push(c),h.push(g)}for(var b in t(c,n)&&c.forEach(function(t,e){var n=o(e,m-1),r=o(t,m-1);g.set(n,r)}),t(c,r)&&c.forEach(function(t){var e=o(t,m-1);g.add(e)}),c){var x;v&&(x=Object.getOwnPropertyDescriptor(v,b)),x&&null==x.set||(g[b]=o(c[b],m-1))}if(Object.getOwnPropertySymbols){var w=Object.getOwnPropertySymbols(c);for(b=0;b<w.length;b++){var k=w[b];(!(E=Object.getOwnPropertyDescriptor(c,k))||E.enumerable||f)&&(g[k]=o(c[k],m-1),E.enumerable||Object.defineProperty(g,k,{enumerable:!1}))}}if(f){var _=Object.getOwnPropertyNames(c);for(b=0;b<_.length;b++){var E,O=_[b];(E=Object.getOwnPropertyDescriptor(c,O))&&E.enumerable||(g[O]=o(c[O],m-1),Object.defineProperty(g,O,{enumerable:!1}))}}return g}(o,c)}function o(t){return Object.prototype.toString.call(t)}function s(t){var e="";return t.global&&(e+="g"),t.ignoreCase&&(e+="i"),t.multiline&&(e+="m"),e}return a.clonePrototype=function(t){if(null===t)return null;var e=function(){};return e.prototype=t,new e},a.__objToStr=o,a.__isDate=function(t){return"object"==typeof t&&"[object Date]"===o(t)},a.__isArray=function(t){return"object"==typeof t&&"[object Array]"===o(t)},a.__isRegExp=function(t){return"object"==typeof t&&"[object RegExp]"===o(t)},a.__getRegExpFlags=s,a}();"object"==typeof t&&t.exports&&(t.exports=n)}).call(this,n(86).Buffer)},function(t){t.exports={name:"vega-lite",author:'Dominik Moritz, Kanit "Ham" Wongsuphasawat, Arvind Satyanarayan, Jeffrey Heer',version:"4.0.2",collaborators:["Kanit Wongsuphasawat (http://kanitw.yellowpigz.com)","Dominik Moritz (https://www.domoritz.de)","Arvind Satyanarayan (https://arvindsatya.com)","Jeffrey Heer (https://jheer.org)"],homepage:"https://vega.github.io/vega-lite/",description:"Vega-Lite is a concise high-level language for interactive visualization.",main:"build/vega-lite.js",unpkg:"build/vega-lite.min.js",jsdelivr:"build/vega-lite.min.js",module:"build/src/index",types:"build/src/index.d.ts",bin:{vl2png:"./bin/vl2png",vl2svg:"./bin/vl2svg",vl2vg:"./bin/vl2vg"},directories:{test:"test"},scripts:{build:"yarn build:only","build:only":"yarn tsc:src && rollup -c",postbuild:"terser build/vega-lite.js -cm --source-map content=build/vega-lite.js.map,filename=build/vega-lite.min.js.map -o build/vega-lite.min.js && yarn schema","prebuild:examples":"yarn build:only","build:examples":"yarn data && TZ=America/Los_Angeles scripts/build-examples.sh","prebuild:examples-full":"yarn build:only","build:examples-full":"TZ=America/Los_Angeles scripts/build-examples.sh 1","build:example":"TZ=America/Los_Angeles scripts/build-example.sh","build:toc":"yarn build:jekyll && scripts/generate-toc","build:site":"yarn tsc:site && rollup -c site/rollup.config.js","build:jekyll":"pushd site && bundle exec jekyll build -q && popd","build:versions":"scripts/update-version.sh",clean:"find build ! -name 'vega-lite-schema.json' -type f -delete && rm -rf site/data/* && rm -f examples/compiled/*.png && find site/examples ! -name 'index.md' ! -name 'data' -type f -delete","predeploy:site":"yarn presite","deploy:site":"gh-pages -d site",data:"rsync -r node_modules/vega-datasets/data/* site/data",schema:"mkdir -p build && ts-json-schema-generator -c -f tsconfig.json -p src/index.ts -t TopLevelSpec -k deprecated > build/vega-lite-schema.json && yarn renameschema && cp build/vega-lite-schema.json site/_data/",renameschema:"scripts/rename-schema.sh",presite:"yarn data && yarn schema && yarn build:site && yarn build:versions && scripts/create-example-pages.sh",site:"pushd site && bundle exec jekyll serve -I -l && popd","tsc:src":"tsc -b src/tsconfig.src.json","tsc:site":"tsc -b site/tsconfig.site.json",prettierbase:"prettier '**/*.{md,css,yml}'",eslintbase:"eslint --ext .ts .",format:"yarn eslintbase --fix && yarn prettierbase --write",lint:"yarn eslintbase && yarn prettierbase --check",test:"jest test/ && yarn lint && yarn schema && jest examples/ && yarn test:runtime","test:inspect":"node --inspect-brk ./node_modules/.bin/jest --runInBand test","test:runtime":"TZ=America/Los_Angeles jest test-runtime/","test:runtime:generate":"yarn build:only && rm -Rf test-runtime/resources && VL_GENERATE_TESTS=true yarn test:runtime","watch:build":"yarn build:only && concurrently --kill-others -n Typescript,Rollup 'yarn tsc:src -w' 'rollup -c -w'","watch:site":"concurrently --kill-others -n Typescript,Rollup 'yarn tsc:site -w' 'rollup -c site/rollup.config.js -w'","watch:test":"jest --watch"},repository:{type:"git",url:"https://github.com/vega/vega-lite.git"},license:"BSD-3-Clause",bugs:{url:"https://github.com/vega/vega-lite/issues"},devDependencies:{"@commitlint/cli":"^8.2.0","@commitlint/config-conventional":"^8.2.0","@types/chai":"^4.2.6","@types/d3":"^5.7.2","@types/highlight.js":"^9.12.3","@types/jest":"^24.0.23","@types/jest-environment-puppeteer":"^4.3.1","@types/mkdirp":"^0.5.2","@types/puppeteer":"^2.0.0","@typescript-eslint/eslint-plugin":"^2.10.0","@typescript-eslint/parser":"^2.10.0",ajv:"^6.10.2",chai:"^4.2.0",cheerio:"^1.0.0-rc.2",codecov:"^3.6.1",concurrently:"^5.0.0",d3:"^5.14.2",eslint:"^6.7.2","eslint-config-prettier":"^6.7.0","eslint-plugin-prettier":"^3.1.1","gh-pages":"^2.1.1","highlight.js":"^9.16.2","http-server":"^0.12.0",husky:"^3.1.0",jest:"^24.9.0","jest-puppeteer":"^4.3.0","lint-staged":"^9.5.0",mkdirp:"^0.5.1",prettier:"^1.19.1",puppeteer:"^2.0.0",rollup:"^1.27.8","rollup-plugin-commonjs":"^10.1.0","rollup-plugin-json":"^4.0.0","rollup-plugin-node-resolve":"^5.2.0","rollup-plugin-sourcemaps":"^0.4.2","rollup-plugin-terser":"^5.1.2","svg2png-many":"^0.0.7",terser:"^4.4.2","ts-jest":"^24.2.0","ts-json-schema-generator":"^0.57.0",typescript:"~3.7.3","vega-cli":"^5.9.0","vega-datasets":"^1.28.0","vega-embed":"^6.2.0","vega-tooltip":"^0.19.1","yaml-front-matter":"^4.0.0"},dependencies:{"@types/clone":"~0.1.30","@types/fast-json-stable-stringify":"^2.0.0","array-flat-polyfill":"^1.0.1",clone:"~2.1.2","fast-deep-equal":"~3.1.1","fast-json-stable-stringify":"~2.0.0","json-stringify-pretty-compact":"~2.0.0",tslib:"~1.10.0","vega-event-selector":"~2.0.2","vega-expression":"~2.6.3","vega-typings":"~0.12.0","vega-util":"~1.12.1",yargs:"~15.0.2"},peerDependencies:{vega:"^5.9.0"},husky:{hooks:{"pre-commit":"lint-staged","commit-msg":"commitlint -E HUSKY_GIT_PARAMS"}},"lint-staged":{"*.ts":["eslint --fix","git add"],"*.{md,css,yml}":["prettier --write","git add"]},jest:{preset:"jest-puppeteer",transform:{"^.+\\.tsx?$":"ts-jest"},testRegex:"(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",moduleFileExtensions:["ts","tsx","js","jsx","json","node"],testPathIgnorePatterns:["<rootDir>/node_modules","<rootDir>/build","<rootDir>/_site","<rootDir>/src"],coverageDirectory:"./coverage/",collectCoverage:!1}}},function(t,e,n){"use strict";n.r(e),n.d(e,"isoSpecifier",function(){return i});var r=n(null),i="%Y-%m-%dT%H:%M:%S.%LZ";var a=Date.prototype.toISOString?function(t){return t.toISOString()}:Object(r.b)(i);e.default=a},function(t,e,n){"use strict";n.r(e);var r="http://www.w3.org/1999/xhtml",i={svg:"http://www.w3.org/2000/svg",xhtml:r,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"},a=function(t){var e=t+="",n=e.indexOf(":");return n>=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),i.hasOwnProperty(e)?{space:i[e],local:t}:t};var o=function(t){var e=a(t);return(e.local?function(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}:function(t){return function(){var e=this.ownerDocument,n=this.namespaceURI;return n===r&&e.documentElement.namespaceURI===r?e.createElement(t):e.createElementNS(n,t)}})(e)};function s(){}var u=function(t){return null==t?s:function(){return this.querySelector(t)}};function c(){return[]}var l=function(t){return null==t?c:function(){return this.querySelectorAll(t)}},f=function(t){return function(){return this.matches(t)}};if("undefined"!=typeof document){var d=document.documentElement;if(!d.matches){var h=d.webkitMatchesSelector||d.msMatchesSelector||d.mozMatchesSelector||d.oMatchesSelector;f=function(t){return function(){return h.call(this,t)}}}}var p=f,m=function(t){return new Array(t.length)};function g(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}g.prototype={constructor:g,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var v="$";function y(t,e,n,r,i,a){for(var o,s=0,u=e.length,c=a.length;s<c;++s)(o=e[s])?(o.__data__=a[s],r[s]=o):n[s]=new g(t,a[s]);for(;s<u;++s)(o=e[s])&&(i[s]=o)}function b(t,e,n,r,i,a,o){var s,u,c,l={},f=e.length,d=a.length,h=new Array(f);for(s=0;s<f;++s)(u=e[s])&&(h[s]=c=v+o.call(u,u.__data__,s,e),c in l?i[s]=u:l[c]=u);for(s=0;s<d;++s)(u=l[c=v+o.call(t,a[s],s,a)])?(r[s]=u,u.__data__=a[s],l[c]=null):n[s]=new g(t,a[s]);for(s=0;s<f;++s)(u=e[s])&&l[h[s]]===u&&(i[s]=u)}function x(t,e){return t<e?-1:t>e?1:t>=e?0:NaN}var w=function(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView};function k(t,e){return t.style.getPropertyValue(e)||w(t).getComputedStyle(t,null).getPropertyValue(e)}function _(t){return t.trim().split(/^|\s+/)}function E(t){return t.classList||new O(t)}function O(t){this._node=t,this._names=_(t.getAttribute("class")||"")}function S(t,e){for(var n=E(t),r=-1,i=e.length;++r<i;)n.add(e[r])}function C(t,e){for(var n=E(t),r=-1,i=e.length;++r<i;)n.remove(e[r])}O.prototype={add:function(t){this._names.indexOf(t)<0&&(this._names.push(t),this._node.setAttribute("class",this._names.join(" ")))},remove:function(t){var e=this._names.indexOf(t);e>=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};function A(){this.textContent=""}function N(){this.innerHTML=""}function T(){this.nextSibling&&this.parentNode.appendChild(this)}function I(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function D(){return null}function M(){var t=this.parentNode;t&&t.removeChild(this)}function R(){return this.parentNode.insertBefore(this.cloneNode(!1),this.nextSibling)}function F(){return this.parentNode.insertBefore(this.cloneNode(!0),this.nextSibling)}var j={},P=null;"undefined"!=typeof document&&("onmouseenter"in document.documentElement||(j={mouseenter:"mouseover",mouseleave:"mouseout"}));function L(t,e,n){return t=z(t,e,n),function(e){var n=e.relatedTarget;n&&(n===this||8&n.compareDocumentPosition(this))||t.call(this,e)}}function z(t,e,n){return function(r){var i=P;P=r;try{t.call(this,this.__data__,e,n)}finally{P=i}}}function B(t){return function(){var e=this.__on;if(e){for(var n,r=0,i=-1,a=e.length;r<a;++r)n=e[r],t.type&&n.type!==t.type||n.name!==t.name?e[++i]=n:this.removeEventListener(n.type,n.listener,n.capture);++i?e.length=i:delete this.__on}}}function U(t,e,n){var r=j.hasOwnProperty(t.type)?L:z;return function(i,a,o){var s,u=this.__on,c=r(e,a,o);if(u)for(var l=0,f=u.length;l<f;++l)if((s=u[l]).type===t.type&&s.name===t.name)return this.removeEventListener(s.type,s.listener,s.capture),this.addEventListener(s.type,s.listener=c,s.capture=n),void(s.value=e);this.addEventListener(t.type,c,n),s={type:t.type,name:t.name,value:e,listener:c,capture:n},u?u.push(s):this.__on=[s]}}function W(t,e,n,r){var i=P;t.sourceEvent=P,P=t;try{return e.apply(n,r)}finally{P=i}}function V(t,e,n){var r=w(t),i=r.CustomEvent;"function"==typeof i?i=new i(e,n):(i=r.document.createEvent("Event"),n?(i.initEvent(e,n.bubbles,n.cancelable),i.detail=n.detail):i.initEvent(e,!1,!1)),t.dispatchEvent(i)}var q=[null];function H(t,e){this._groups=t,this._parents=e}function G(){return new H([[document.documentElement]],q)}H.prototype=G.prototype={constructor:H,select:function(t){"function"!=typeof t&&(t=u(t));for(var e=this._groups,n=e.length,r=new Array(n),i=0;i<n;++i)for(var a,o,s=e[i],c=s.length,l=r[i]=new Array(c),f=0;f<c;++f)(a=s[f])&&(o=t.call(a,a.__data__,f,s))&&("__data__"in a&&(o.__data__=a.__data__),l[f]=o);return new H(r,this._parents)},selectAll:function(t){"function"!=typeof t&&(t=l(t));for(var e=this._groups,n=e.length,r=[],i=[],a=0;a<n;++a)for(var o,s=e[a],u=s.length,c=0;c<u;++c)(o=s[c])&&(r.push(t.call(o,o.__data__,c,s)),i.push(o));return new H(r,i)},filter:function(t){"function"!=typeof t&&(t=p(t));for(var e=this._groups,n=e.length,r=new Array(n),i=0;i<n;++i)for(var a,o=e[i],s=o.length,u=r[i]=[],c=0;c<s;++c)(a=o[c])&&t.call(a,a.__data__,c,o)&&u.push(a);return new H(r,this._parents)},data:function(t,e){if(!t)return h=new Array(this.size()),c=-1,this.each(function(t){h[++c]=t}),h;var n=e?b:y,r=this._parents,i=this._groups;"function"!=typeof t&&(t=function(t){return function(){return t}}(t));for(var a=i.length,o=new Array(a),s=new Array(a),u=new Array(a),c=0;c<a;++c){var l=r[c],f=i[c],d=f.length,h=t.call(l,l&&l.__data__,c,r),p=h.length,m=s[c]=new Array(p),g=o[c]=new Array(p);n(l,f,m,g,u[c]=new Array(d),h,e);for(var v,x,w=0,k=0;w<p;++w)if(v=m[w]){for(w>=k&&(k=w+1);!(x=g[k])&&++k<p;);v._next=x||null}}return(o=new H(o,r))._enter=s,o._exit=u,o},enter:function(){return new H(this._enter||this._groups.map(m),this._parents)},exit:function(){return new H(this._exit||this._groups.map(m),this._parents)},merge:function(t){for(var e=this._groups,n=t._groups,r=e.length,i=n.length,a=Math.min(r,i),o=new Array(r),s=0;s<a;++s)for(var u,c=e[s],l=n[s],f=c.length,d=o[s]=new Array(f),h=0;h<f;++h)(u=c[h]||l[h])&&(d[h]=u);for(;s<r;++s)o[s]=e[s];return new H(o,this._parents)},order:function(){for(var t=this._groups,e=-1,n=t.length;++e<n;)for(var r,i=t[e],a=i.length-1,o=i[a];--a>=0;)(r=i[a])&&(o&&o!==r.nextSibling&&o.parentNode.insertBefore(r,o),o=r);return this},sort:function(t){function e(e,n){return e&&n?t(e.__data__,n.__data__):!e-!n}t||(t=x);for(var n=this._groups,r=n.length,i=new Array(r),a=0;a<r;++a){for(var o,s=n[a],u=s.length,c=i[a]=new Array(u),l=0;l<u;++l)(o=s[l])&&(c[l]=o);c.sort(e)}return new H(i,this._parents).order()},call:function(){var t=arguments[0];return arguments[0]=this,t.apply(null,arguments),this},nodes:function(){var t=new Array(this.size()),e=-1;return this.each(function(){t[++e]=this}),t},node:function(){for(var t=this._groups,e=0,n=t.length;e<n;++e)for(var r=t[e],i=0,a=r.length;i<a;++i){var o=r[i];if(o)return o}return null},size:function(){var t=0;return this.each(function(){++t}),t},empty:function(){return!this.node()},each:function(t){for(var e=this._groups,n=0,r=e.length;n<r;++n)for(var i,a=e[n],o=0,s=a.length;o<s;++o)(i=a[o])&&t.call(i,i.__data__,o,a);return this},attr:function(t,e){var n=a(t);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((null==e?n.local?function(t){return function(){this.removeAttributeNS(t.space,t.local)}}:function(t){return function(){this.removeAttribute(t)}}:"function"==typeof e?n.local?function(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,n)}}:function(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}:n.local?function(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}:function(t,e){return function(){this.setAttribute(t,e)}})(n,e))},style:function(t,e,n){return arguments.length>1?this.each((null==e?function(t){return function(){this.style.removeProperty(t)}}:"function"==typeof e?function(t,e,n){return function(){var r=e.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,n)}}:function(t,e,n){return function(){this.style.setProperty(t,e,n)}})(t,e,null==n?"":n)):k(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?function(t){return function(){delete this[t]}}:"function"==typeof e?function(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}:function(t,e){return function(){this[t]=e}})(t,e)):this.node()[t]},classed:function(t,e){var n=_(t+"");if(arguments.length<2){for(var r=E(this.node()),i=-1,a=n.length;++i<a;)if(!r.contains(n[i]))return!1;return!0}return this.each(("function"==typeof e?function(t,e){return function(){(e.apply(this,arguments)?S:C)(this,t)}}:e?function(t){return function(){S(this,t)}}:function(t){return function(){C(this,t)}})(n,e))},text:function(t){return arguments.length?this.each(null==t?A:("function"==typeof t?function(t){return function(){var e=t.apply(this,arguments);this.textContent=null==e?"":e}}:function(t){return function(){this.textContent=t}})(t)):this.node().textContent},html:function(t){return arguments.length?this.each(null==t?N:("function"==typeof t?function(t){return function(){var e=t.apply(this,arguments);this.innerHTML=null==e?"":e}}:function(t){return function(){this.innerHTML=t}})(t)):this.node().innerHTML},raise:function(){return this.each(T)},lower:function(){return this.each(I)},append:function(t){var e="function"==typeof t?t:o(t);return this.select(function(){return this.appendChild(e.apply(this,arguments))})},insert:function(t,e){var n="function"==typeof t?t:o(t),r=null==e?D:"function"==typeof e?e:u(e);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})},remove:function(){return this.each(M)},clone:function(t){return this.select(t?F:R)},datum:function(t){return arguments.length?this.property("__data__",t):this.node().__data__},on:function(t,e,n){var r,i,a=function(t){return t.trim().split(/^|\s+/).map(function(t){var e="",n=t.indexOf(".");return n>=0&&(e=t.slice(n+1),t=t.slice(0,n)),{type:t,name:e}})}(t+""),o=a.length;if(!(arguments.length<2)){for(s=e?U:B,null==n&&(n=!1),r=0;r<o;++r)this.each(s(a[r],e,n));return this}var s=this.node().__on;if(s)for(var u,c=0,l=s.length;c<l;++c)for(r=0,u=s[c];r<o;++r)if((i=a[r]).type===u.type&&i.name===u.name)return u.value},dispatch:function(t,e){return this.each(("function"==typeof e?function(t,e){return function(){return V(this,t,e.apply(this,arguments))}}:function(t,e){return function(){return V(this,t,e)}})(t,e))}};var $=G,K=function(t){return"string"==typeof t?new H([[document.querySelector(t)]],[document.documentElement]):new H([[t]],q)},X=function(t){return K(o(t).call(document.documentElement))},Y=0;function J(){return new Z}function Z(){this._="@"+(++Y).toString(36)}Z.prototype=J.prototype={constructor:Z,get:function(t){for(var e=this._;!(e in t);)if(!(t=t.parentNode))return;return t[e]},set:function(t,e){return t[this._]=e},remove:function(t){return this._ in t&&delete t[this._]},toString:function(){return this._}};var Q=function(){for(var t,e=P;t=e.sourceEvent;)e=t;return e},tt=function(t,e){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,[(r=r.matrixTransform(t.getScreenCTM().inverse())).x,r.y]}var i=t.getBoundingClientRect();return[e.clientX-i.left-t.clientLeft,e.clientY-i.top-t.clientTop]},et=function(t){var e=Q();return e.changedTouches&&(e=e.changedTouches[0]),tt(t,e)},nt=function(t){return"string"==typeof t?new H([document.querySelectorAll(t)],[document.documentElement]):new H([null==t?[]:t],q)},rt=function(t,e,n){arguments.length<3&&(n=e,e=Q().changedTouches);for(var r,i=0,a=e?e.length:0;i<a;++i)if((r=e[i]).identifier===n)return tt(t,r);return null},it=function(t,e){null==e&&(e=Q().touches);for(var n=0,r=e?e.length:0,i=new Array(r);n<r;++n)i[n]=tt(t,e[n]);return i};n.d(e,"create",function(){return X}),n.d(e,"creator",function(){return o}),n.d(e,"local",function(){return J}),n.d(e,"matcher",function(){return p}),n.d(e,"mouse",function(){return et}),n.d(e,"namespace",function(){return a}),n.d(e,"namespaces",function(){return i}),n.d(e,"clientPoint",function(){return tt}),n.d(e,"select",function(){return K}),n.d(e,"selectAll",function(){return nt}),n.d(e,"selection",function(){return $}),n.d(e,"selector",function(){return u}),n.d(e,"selectorAll",function(){return l}),n.d(e,"style",function(){return k}),n.d(e,"touch",function(){return rt}),n.d(e,"touches",function(){return it}),n.d(e,"window",function(){return w}),n.d(e,"event",function(){return P}),n.d(e,"customEvent",function(){return W})},function(t,e,n){"use strict";n.r(e);var r={};n.d(r,"isTensor",function(){return c}),n.d(r,"isTensor1D",function(){return l}),n.d(r,"isTensor2D",function(){return f}),n.d(r,"isTensor3D",function(){return d}),n.d(r,"isTensor4D",function(){return h}),n.d(r,"isFloat",function(){return p}),n.d(r,"isEven",function(){return m}),n.d(r,"round",function(){return g}),n.d(r,"isDimensions",function(){return v}),n.d(r,"computeReshapedDimensions",function(){return y}),n.d(r,"getCenterPoint",function(){return b}),n.d(r,"range",function(){return x}),n.d(r,"isValidNumber",function(){return w}),n.d(r,"isValidProbablitiy",function(){return k});var i={};n.d(i,"drawContour",function(){return o}),n.d(i,"drawDetections",function(){return ut}),n.d(i,"drawFaceExpressions",function(){return te}),n.d(i,"DrawBoxOptions",function(){return ot}),n.d(i,"DrawBox",function(){return st}),n.d(i,"DrawFaceLandmarksOptions",function(){return re}),n.d(i,"DrawFaceLandmarks",function(){return ie}),n.d(i,"drawFaceLandmarks",function(){return ae}),n.d(i,"AnchorPosition",function(){return tt}),n.d(i,"DrawTextFieldOptions",function(){return it}),n.d(i,"DrawTextField",function(){return at});var a=n(2);function o(t,e,n){if(void 0===n&&(n=!1),t.beginPath(),e.slice(1).forEach(function(n,r){var i=n.x,a=n.y,o=e[r];t.moveTo(o.x,o.y),t.lineTo(i,a)}),n){var r=e[e.length-1],i=e[0];if(!r||!i)return;t.moveTo(r.x,r.y),t.lineTo(i.x,i.y)}t.stroke()}var s=n(3),u=function(){function t(t,e){if(!w(t)||!w(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(t.prototype,"width",{get:function(){return this._width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},enumerable:!0,configurable:!0}),t.prototype.reverse=function(){return new t(1/this.width,1/this.height)},t}();function c(t,e){return t instanceof a.Tensor&&t.shape.length===e}function l(t){return c(t,1)}function f(t){return c(t,2)}function d(t){return c(t,3)}function h(t){return c(t,4)}function p(t){return t%1!=0}function m(t){return t%2==0}function g(t,e){void 0===e&&(e=2);var n=Math.pow(10,e);return Math.floor(t*n)/n}function v(t){return t&&t.width&&t.height}function y(t,e){var n=t.width,r=t.height,i=e/Math.max(r,n);return new u(Math.round(n*i),Math.round(r*i))}function b(t){return t.reduce(function(t,e){return t.add(e)},new _(0,0)).div(new _(t.length,t.length))}function x(t,e,n){return Array(t).fill(0).map(function(t,r){return e+r*n})}function w(t){return!!t&&t!==1/0&&t!==-1/0&&!isNaN(t)||0===t}function k(t){return w(t)&&0<=t&&t<=1}var _=function(){function t(t,e){this._x=t,this._y=e}return Object.defineProperty(t.prototype,"x",{get:function(){return this._x},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},enumerable:!0,configurable:!0}),t.prototype.add=function(e){return new t(this.x+e.x,this.y+e.y)},t.prototype.sub=function(e){return new t(this.x-e.x,this.y-e.y)},t.prototype.mul=function(e){return new t(this.x*e.x,this.y*e.y)},t.prototype.div=function(e){return new t(this.x/e.x,this.y/e.y)},t.prototype.abs=function(){return new t(Math.abs(this.x),Math.abs(this.y))},t.prototype.magnitude=function(){return Math.sqrt(Math.pow(this.x,2)+Math.pow(this.y,2))},t.prototype.floor=function(){return new t(Math.floor(this.x),Math.floor(this.y))},t}(),E=function(){function t(e,n){void 0===n&&(n=!0);var r=e||{},i=[r.left,r.top,r.right,r.bottom].every(w),a=[r.x,r.y,r.width,r.height].every(w);if(!a&&!i)throw new Error("Box.constructor - expected box to be IBoundingBox | IRect, instead have "+JSON.stringify(r));var o=a?[r.x,r.y,r.width,r.height]:[r.left,r.top,r.right-r.left,r.bottom-r.top],s=o[0],u=o[1],c=o[2],l=o[3];t.assertIsValidBox({x:s,y:u,width:c,height:l},"Box.constructor",n),this._x=s,this._y=u,this._width=c,this._height=l}return t.isRect=function(t){return!!t&&[t.x,t.y,t.width,t.height].every(w)},t.assertIsValidBox=function(e,n,r){if(void 0===r&&(r=!1),!t.isRect(e))throw new Error(n+" - invalid box: "+JSON.stringify(e)+", expected object with properties x, y, width, height");if(!r&&(e.width<0||e.height<0))throw new Error(n+" - width ("+e.width+") and height ("+e.height+") must be positive numbers")},Object.defineProperty(t.prototype,"x",{get:function(){return this._x},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"width",{get:function(){return this._width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"area",{get:function(){return this.width*this.height},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"topLeft",{get:function(){return new _(this.left,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"topRight",{get:function(){return new _(this.right,this.top)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bottomLeft",{get:function(){return new _(this.left,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bottomRight",{get:function(){return new _(this.right,this.bottom)},enumerable:!0,configurable:!0}),t.prototype.round=function(){var e=[this.x,this.y,this.width,this.height].map(function(t){return Math.round(t)});return new t({x:e[0],y:e[1],width:e[2],height:e[3]})},t.prototype.floor=function(){var e=[this.x,this.y,this.width,this.height].map(function(t){return Math.floor(t)});return new t({x:e[0],y:e[1],width:e[2],height:e[3]})},t.prototype.toSquare=function(){var e=this.x,n=this.y,r=this.width,i=this.height,a=Math.abs(r-i);return r<i&&(e-=a/2,r+=a),i<r&&(n-=a/2,i+=a),new t({x:e,y:n,width:r,height:i})},t.prototype.rescale=function(e){var n=v(e)?e.width:e,r=v(e)?e.height:e;return new t({x:this.x*n,y:this.y*r,width:this.width*n,height:this.height*r})},t.prototype.pad=function(e,n){var r=[this.x-e/2,this.y-n/2,this.width+e,this.height+n];return new t({x:r[0],y:r[1],width:r[2],height:r[3]})},t.prototype.clipAtImageBorders=function(e,n){var r=this.x,i=this.y,a=this.right,o=this.bottom,s=Math.max(r,0),u=Math.max(i,0),c=a-s,l=o-u;return new t({x:s,y:u,width:Math.min(c,e-s),height:Math.min(l,n-u)}).floor()},t.prototype.shift=function(e,n){var r=this.width,i=this.height;return new t({x:this.x+e,y:this.y+n,width:r,height:i})},t.prototype.padAtBorders=function(t,e){var n=this.width+1,r=this.height+1,i=n,a=r,o=this.left,s=this.top,u=this.right,c=this.bottom;return u>e&&(i=-u+e+n,u=e),c>t&&(a=-c+t+r,c=t),o<1&&(a=2-o,o=1),s<1&&(a=2-s,s=1),{dy:1,edy:a,dx:1,edx:i,y:s,ey:c,x:o,ex:u,w:n,h:r}},t.prototype.calibrate=function(e){return new t({left:this.left+e.left*this.width,top:this.top+e.top*this.height,right:this.right+e.right*this.width,bottom:this.bottom+e.bottom*this.height}).toSquare().round()},t}(),O=function(t){function e(e,n,r,i,a){return void 0===a&&(a=!1),t.call(this,{left:e,top:n,right:r,bottom:i},a)||this}return Object(s.c)(e,t),e}(E),S=function(){function t(t,e,n,r,i){this._imageDims=new u(i.width,i.height),this._score=t,this._classScore=e,this._className=n,this._box=new E(r).rescale(this._imageDims)}return 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}),Object.defineProperty(t.prototype,"className",{get:function(){return this._className},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"box",{get:function(){return this._box},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"imageDims",{get:function(){return this._imageDims},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"imageWidth",{get:function(){return this.imageDims.width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"imageHeight",{get:function(){return this.imageDims.height},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"relativeBox",{get:function(){return new E(this._box).rescale(this.imageDims.reverse())},enumerable:!0,configurable:!0}),t.prototype.forSize=function(e,n){return new t(this.score,this.classScore,this.className,this.relativeBox,{width:e,height:n})},t}(),C=function(t){function e(e,n,r){return t.call(this,e,e,"",n,r)||this}return Object(s.c)(e,t),e.prototype.forSize=function(n,r){var i=t.prototype.forSize.call(this,n,r);return new e(i.score,i.relativeBox,i.imageDims)},e}(S);function A(t,e,n){void 0===n&&(n=!0);var r=Math.max(0,Math.min(t.right,e.right)-Math.max(t.left,e.left))*Math.max(0,Math.min(t.bottom,e.bottom)-Math.max(t.top,e.top));return n?r/(t.area+e.area-r):r/Math.min(t.area,e.area)}function N(t){var e=t.map(function(t){return t.x}),n=t.map(function(t){return t.y}),r=e.reduce(function(t,e){return e<t?e:t},1/0),i=n.reduce(function(t,e){return e<t?e:t},1/0),a=e.reduce(function(t,e){return t<e?e:t},0),o=n.reduce(function(t,e){return t<e?e:t},0);return new O(r,i,a,o)}function T(t,e,n,r){void 0===r&&(r=!0);for(var i=e.map(function(t,e){return{score:t,boxIndex:e}}).sort(function(t,e){return t.score-e.score}).map(function(t){return t.boxIndex}),a=[],o=function(){var e=i.pop();a.push(e);for(var o=i,s=[],u=0;u<o.length;u++){var c=o[u],l=t[e],f=t[c];s.push(A(l,f,r))}i=i.filter(function(t,e){return s[e]<=n})};i.length>0;)o();return a}function I(t,e){return a.tidy(function(){var n=e[0],r=e[1],i=e[2],o=a.fill(Object(s.e)(t.shape.slice(0,3),[1]),n),u=a.fill(Object(s.e)(t.shape.slice(0,3),[1]),r),c=a.fill(Object(s.e)(t.shape.slice(0,3),[1]),i),l=a.concat([o,u,c],3);return a.sub(t,l)})}function D(t,e){return void 0===e&&(e=!1),a.tidy(function(){var n=t.shape.slice(1),r=n[0],i=n[1];if(r===i)return t;var o=Math.abs(r-i),s=Math.round(o*(e?.5:1)),u=r>i?2:1,c=function(e){var n=t.shape.slice();return n[u]=e,a.fill(n,0)},l=c(s),f=o-l.shape[u],d=[e&&f?c(f):null,t,l].filter(function(t){return!!t}).map(function(t){return t.toFloat()});return a.concat(d,u)})}function M(t){for(var e=t.slice(),n=e.length-1;n>0;n--){var r=Math.floor(Math.random()*(n+1)),i=e[n];e[n]=e[r],e[r]=i}return e}function R(t){return 1/(1+Math.exp(-t))}function F(t){return Math.log(t/(1-t))}var j=function(t){function e(e,n,r,i,a){return void 0===a&&(a=!1),t.call(this,{x:e,y:n,width:r,height:i},a)||this}return Object(s.c)(e,t),e}(E),P=function(){function t(t,e,n){void 0===n&&(n=new _(0,0));var r=e.width,i=e.height;this._imgDims=new u(r,i),this._shift=n,this._positions=t.map(function(t){return t.mul(new _(r,i)).add(n)})}return Object.defineProperty(t.prototype,"shift",{get:function(){return new _(this._shift.x,this._shift.y)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"imageWidth",{get:function(){return this._imgDims.width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"imageHeight",{get:function(){return this._imgDims.height},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"positions",{get:function(){return this._positions},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"relativePositions",{get:function(){var t=this;return this._positions.map(function(e){return e.sub(t._shift).div(new _(t.imageWidth,t.imageHeight))})},enumerable:!0,configurable:!0}),t.prototype.forSize=function(t,e){return new this.constructor(this.relativePositions,{width:t,height:e})},t.prototype.shiftBy=function(t,e){return new this.constructor(this.relativePositions,this._imgDims,new _(t,e))},t.prototype.shiftByPoint=function(t){return this.shiftBy(t.x,t.y)},t.prototype.align=function(t,e){if(void 0===e&&(e={}),t){var n=t instanceof C?t.box.floor():new E(t);return this.shiftBy(n.x,n.y).align(null,e)}var r=Object.assign({},{useDlibAlignment:!1,minBoxPadding:.2},e),i=r.useDlibAlignment,a=r.minBoxPadding;return i?this.alignDlib():this.alignMinBbox(a)},t.prototype.alignDlib=function(){var t=this.getRefPointsForAlignment(),e=t[0],n=t[1],r=t[2],i=function(t){return r.sub(t).magnitude()},a=(i(e)+i(n))/2,o=Math.floor(a/.45),s=b(t),u=Math.floor(Math.max(0,s.x-.5*o)),c=Math.floor(Math.max(0,s.y-.43*o));return new j(u,c,Math.min(o,this.imageWidth+u),Math.min(o,this.imageHeight+c))},t.prototype.alignMinBbox=function(t){var e=N(this.positions);return e.pad(e.width*t,e.height*t)},t.prototype.getRefPointsForAlignment=function(){throw new Error("getRefPointsForAlignment not implemented by base class")},t}(),L=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Object(s.c)(e,t),e.prototype.getRefPointsForAlignment=function(){var t=this.positions;return[t[0],t[1],b([t[3],t[4]])]},e}(P),z=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Object(s.c)(e,t),e.prototype.getJawOutline=function(){return this.positions.slice(0,17)},e.prototype.getLeftEyeBrow=function(){return this.positions.slice(17,22)},e.prototype.getRightEyeBrow=function(){return this.positions.slice(22,27)},e.prototype.getNose=function(){return this.positions.slice(27,36)},e.prototype.getLeftEye=function(){return this.positions.slice(36,42)},e.prototype.getRightEye=function(){return this.positions.slice(42,48)},e.prototype.getMouth=function(){return this.positions.slice(48,68)},e.prototype.getRefPointsForAlignment=function(){return[this.getLeftEye(),this.getRightEye(),this.getMouth()].map(b)},e}(P),B=function(){function t(t,e){this._label=t,this._distance=e}return Object.defineProperty(t.prototype,"label",{get:function(){return this._label},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"distance",{get:function(){return this._distance},enumerable:!0,configurable:!0}),t.prototype.toString=function(t){return void 0===t&&(t=!0),this.label+(t?" ("+g(this.distance)+")":"")},t}(),U=function(t){function e(e,n){var r=t.call(this,e)||this;return r._label=n,r}return Object(s.c)(e,t),e.assertIsValidLabeledBox=function(t,e){if(E.assertIsValidBox(t,e),!w(t.label))throw new Error(e+" - expected property label ("+t.label+") to be a number")},Object.defineProperty(e.prototype,"label",{get:function(){return this._label},enumerable:!0,configurable:!0}),e}(E),W=function(){function t(t,e){if("string"!=typeof t)throw new Error("LabeledFaceDescriptors - constructor expected label to be a string");if(!Array.isArray(e)||e.some(function(t){return!(t instanceof Float32Array)}))throw new Error("LabeledFaceDescriptors - constructor expected descriptors to be an array of Float32Array");this._label=t,this._descriptors=e}return Object.defineProperty(t.prototype,"label",{get:function(){return this._label},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"descriptors",{get:function(){return this._descriptors},enumerable:!0,configurable:!0}),t.prototype.toJSON=function(){return{label:this.label,descriptors:this.descriptors.map(function(t){return Array.from(t)})}},t.fromJSON=function(e){var n=e.descriptors.map(function(t){return new Float32Array(t)});return new t(e.label,n)},t}(),V=function(t){function e(e,n,r,i){var a=t.call(this,e,n)||this;return a._score=r,a._classScore=i,a}return Object(s.c)(e,t),e.assertIsValidPredictedBox=function(t,e){if(U.assertIsValidLabeledBox(t,e),!k(t.score)||!k(t.classScore))throw new Error(e+" - expected properties score ("+t.score+") and ("+t.classScore+") to be a number between [0, 1]")},Object.defineProperty(e.prototype,"score",{get:function(){return this._score},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"classScore",{get:function(){return this._classScore},enumerable:!0,configurable:!0}),e}(U);function q(t){return t.detection instanceof C}function H(t,e){var n={detection:e};return Object.assign({},t,n)}function G(){var t=window.fetch||function(){throw new Error("fetch - missing fetch implementation for browser environment")};return{Canvas:HTMLCanvasElement,CanvasRenderingContext2D:CanvasRenderingContext2D,Image:HTMLImageElement,ImageData:ImageData,Video:HTMLVideoElement,createCanvasElement:function(){return document.createElement("canvas")},createImageElement:function(){return document.createElement("img")},fetch:t,readFile:function(){throw new Error("readFile - filesystem not available for browser environment")}}}var $=n(138),K=n(194);function X(){return"object"==typeof window&&"undefined"!=typeof document&&"undefined"!=typeof HTMLImageElement&&"undefined"!=typeof HTMLCanvasElement&&"undefined"!=typeof HTMLVideoElement&&"undefined"!=typeof ImageData&&"undefined"!=typeof CanvasRenderingContext2D}var Y,J=n(193);function Z(t){Y=t}function Q(){X()&&Z(G()),Object(J.a)()&&Z(Object(K.a)())}var tt,et={getEnv:function(){if(!Y)throw new Error("getEnv - environment is not defined, check isNodejs() and isBrowser()");return Y},setEnv:Z,initialize:Q,createBrowserEnv:G,createFileSystem:$.a,createNodejsEnv:K.a,monkeyPatch:function(t){if(Y||Q(),!Y)throw new Error("monkeyPatch - environment is not defined, check isNodejs() and isBrowser()");var e=t.Canvas,n=void 0===e?Y.Canvas:e,r=t.Image,i=void 0===r?Y.Image:r;Y.Canvas=n,Y.Image=i,Y.createCanvasElement=t.createCanvasElement||function(){return new n},Y.createImageElement=t.createImageElement||function(){return new i},Y.ImageData=t.ImageData||Y.ImageData,Y.Video=t.Video||Y.Video,Y.fetch=t.fetch||Y.fetch,Y.readFile=t.readFile||Y.readFile},isBrowser:X,isNodejs:J.a};function nt(t){return et.isNodejs()||"string"!=typeof t?t:document.getElementById(t)}function rt(t){var e=et.getEnv(),n=e.Canvas;if(t instanceof e.CanvasRenderingContext2D)return t;var r=nt(t);if(!(r instanceof n))throw new Error("resolveContext2d - expected canvas to be of instance of Canvas");var i=r.getContext("2d");if(!i)throw new Error("resolveContext2d - canvas 2d context is null");return i}Q(),function(t){t.TOP_LEFT="TOP_LEFT",t.TOP_RIGHT="TOP_RIGHT",t.BOTTOM_LEFT="BOTTOM_LEFT",t.BOTTOM_RIGHT="BOTTOM_RIGHT"}(tt||(tt={}));var it=function(){return function(t){void 0===t&&(t={});var e=t.anchorPosition,n=t.backgroundColor,r=t.fontColor,i=t.fontSize,a=t.fontStyle,o=t.padding;this.anchorPosition=e||tt.TOP_LEFT,this.backgroundColor=n||"rgba(0, 0, 0, 0.5)",this.fontColor=r||"rgba(255, 255, 255, 1)",this.fontSize=i||14,this.fontStyle=a||"Georgia",this.padding=o||4}}(),at=function(){function t(e,n,r){void 0===r&&(r={}),this.text="string"==typeof e?[e]:e instanceof t?e.text:e,this.anchor=n,this.options=new it(r)}return t.prototype.measureWidth=function(t){var e=this.options.padding;return this.text.map(function(e){return t.measureText(e).width}).reduce(function(t,e){return t<e?e:t},0)+2*e},t.prototype.measureHeight=function(){var t=this.options,e=t.fontSize,n=t.padding;return this.text.length*e+2*n},t.prototype.getUpperLeft=function(t,e){var n=this.options.anchorPosition,r=n===tt.BOTTOM_RIGHT||n===tt.TOP_RIGHT,i=n===tt.BOTTOM_LEFT||n===tt.BOTTOM_RIGHT,a=this.measureWidth(t),o=this.measureHeight(),s=r?this.anchor.x-a:this.anchor.x,u=i?this.anchor.y-o:this.anchor.y;if(e){var c=e.width,l=e.height;return{x:Math.max(Math.min(s,c-a),0),y:Math.max(Math.min(u,l-o),0)}}return{x:s,y:u}},t.prototype.draw=function(t){var e=nt(t),n=rt(e),r=this.options,i=r.backgroundColor,a=r.fontColor,o=r.fontSize,s=r.fontStyle,u=r.padding;n.font=o+"px "+s;var c=this.measureWidth(n),l=this.measureHeight();n.fillStyle=i;var f=this.getUpperLeft(n,e);n.fillRect(f.x,f.y,c,l),n.fillStyle=a,this.text.forEach(function(t,e){var r=u+f.x,i=u+f.y+(e+1)*o;n.fillText(t,r,i)})},t}(),ot=function(){return function(t){void 0===t&&(t={});var e=t.boxColor,n=t.lineWidth,r=t.label,i=t.drawLabelOptions;this.boxColor=e||"rgba(0, 0, 255, 1)",this.lineWidth=n||2,this.label=r;var a={anchorPosition:tt.BOTTOM_LEFT,backgroundColor:this.boxColor};this.drawLabelOptions=new it(Object.assign({},a,i))}}(),st=function(){function t(t,e){void 0===e&&(e={}),this.box=new E(t),this.options=new ot(e)}return t.prototype.draw=function(t){var e=rt(t),n=this.options,r=n.boxColor,i=n.lineWidth,a=this.box,o=a.x,s=a.y,u=a.width,c=a.height;e.strokeStyle=r,e.lineWidth=i,e.strokeRect(o,s,u,c);var l=this.options.label;l&&new at([l],{x:o-i/2,y:s},this.options.drawLabelOptions).draw(t)},t}();function ut(t,e){(Array.isArray(e)?e:[e]).forEach(function(e){var n=e instanceof C?e.score:q(e)?e.detection.score:void 0,r=e instanceof C?e.box:q(e)?e.detection.box:new E(e),i=n?""+g(n):void 0;new st(r,{label:i}).draw(t)})}function ct(t){var e=et.getEnv(),n=e.Image,r=e.Video;return t instanceof n&&t.complete||t instanceof r&&t.readyState>=3}function lt(t){return new Promise(function(e,n){if(t instanceof et.getEnv().Canvas||ct(t))return e();function r(t){t.currentTarget&&(t.currentTarget.removeEventListener("load",r),t.currentTarget.removeEventListener("error",i),e(t))}function i(t){t.currentTarget&&(t.currentTarget.removeEventListener("load",r),t.currentTarget.removeEventListener("error",i),n(t))}t.addEventListener("load",r),t.addEventListener("error",i)})}function ft(t){return new Promise(function(e,n){if(!(t instanceof Blob))return n("bufferToImage - expected buf to be of type: Blob");var r=new FileReader;r.onload=function(){if("string"!=typeof r.result)return n("bufferToImage - expected reader.result to be a string, in onload");var t=et.getEnv().createImageElement();t.onload=function(){return e(t)},t.onerror=n,t.src=r.result},r.onerror=n,r.readAsDataURL(t)})}function dt(t){var e=et.getEnv(),n=e.Image,r=e.Video;return t instanceof n?new u(t.naturalWidth,t.naturalHeight):t instanceof r?new u(t.videoWidth,t.videoHeight):new u(t.width,t.height)}function ht(t){var e=t.width,n=t.height,r=(0,et.getEnv().createCanvasElement)();return r.width=e,r.height=n,r}function pt(t,e){var n=et.getEnv().ImageData;if(!(t instanceof n||ct(t)))throw new Error("createCanvasFromMedia - media has not finished loading yet");var r=e||dt(t),i=r.width,a=r.height,o=ht({width:i,height:a});return t instanceof n?rt(o).putImageData(t,0,0):rt(o).drawImage(t,0,0,i,a),o}function mt(t,e){return Object(s.b)(this,void 0,void 0,function(){var n,r,i,o,u,c;return Object(s.d)(this,function(s){switch(s.label){case 0:return n=e||et.getEnv().createCanvasElement(),r=t.shape.slice(h(t)?1:0),i=r[0],o=r[1],u=r[2],c=a.tidy(function(){return t.as3D(i,o,u).toInt()}),[4,a.browser.toPixels(c,n)];case 1:return s.sent(),c.dispose(),[2,n]}})})}function gt(t){var e=et.getEnv(),n=e.Image,r=e.Canvas,i=e.Video;return t instanceof n||t instanceof r||t instanceof i}function vt(t,e,n){void 0===n&&(n=!1);var r=et.getEnv(),i=r.Image,a=r.Canvas;if(!(t instanceof i||t instanceof a))throw new Error("imageToSquare - expected arg0 to be HTMLImageElement | HTMLCanvasElement");var o=dt(t),s=e/Math.max(o.height,o.width),u=s*o.width,c=s*o.height,l=ht({width:e,height:e}),f=t instanceof a?t:pt(t),d=Math.abs(u-c)/2,h=n&&u<c?d:0,p=n&&c<u?d:0;return rt(l).drawImage(f,h,p,u,c),l}var yt=function(){function t(t,e){var n=this;if(void 0===e&&(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(t,e){if(d(t))return n._imageTensors[e]=t,void(n._inputDimensions[e]=t.shape);if(h(t)){var r=t.shape[0];if(1!==r)throw new Error("NetInput - tf.Tensor4D with batchSize "+r+" passed, but not supported in input array");return n._imageTensors[e]=t,void(n._inputDimensions[e]=t.shape.slice(1))}var i=t instanceof et.getEnv().Canvas?t:pt(t);n._canvases[e]=i,n._inputDimensions[e]=[i.height,i.width,3]})}return Object.defineProperty(t.prototype,"imageTensors",{get:function(){return this._imageTensors},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"canvases",{get:function(){return this._canvases},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isBatchInput",{get:function(){return this.batchSize>1||this._treatAsBatchInput},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"batchSize",{get:function(){return this._batchSize},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"inputDimensions",{get:function(){return this._inputDimensions},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"inputSize",{get:function(){return this._inputSize},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"reshapedInputDimensions",{get:function(){var t=this;return x(this.batchSize,0,1).map(function(e,n){return t.getReshapedInputDimensions(n)})},enumerable:!0,configurable:!0}),t.prototype.getInput=function(t){return this.canvases[t]||this.imageTensors[t]},t.prototype.getInputDimensions=function(t){return this._inputDimensions[t]},t.prototype.getInputHeight=function(t){return this._inputDimensions[t][0]},t.prototype.getInputWidth=function(t){return this._inputDimensions[t][1]},t.prototype.getReshapedInputDimensions=function(t){if("number"!=typeof this.inputSize)throw new Error("getReshapedInputDimensions - inputSize not set, toBatchTensor has not been called yet");return y({width:this.getInputWidth(t),height:this.getInputHeight(t)},this.inputSize)},t.prototype.toBatchTensor=function(t,e){var n=this;return void 0===e&&(e=!0),this._inputSize=t,a.tidy(function(){var r=x(n.batchSize,0,1).map(function(r){var i=n.getInput(r);if(i instanceof a.Tensor){var o=h(i)?i:i.expandDims();return(o=D(o,e)).shape[1]===t&&o.shape[2]===t||(o=a.image.resizeBilinear(o,[t,t])),o.as3D(t,t,3)}if(i instanceof et.getEnv().Canvas)return a.browser.fromPixels(vt(i,t,e));throw new Error("toBatchTensor - at batchIdx "+r+", expected input to be instanceof tf.Tensor or instanceof HTMLCanvasElement, instead have "+i)});return a.stack(r.map(function(t){return t.toFloat()})).as4D(n.batchSize,t,t,3)})},t}();function bt(t){return Object(s.b)(this,void 0,void 0,function(){var e,n,r;return Object(s.d)(this,function(i){switch(i.label){case 0:if(t instanceof yt)return[2,t];if(!(e=Array.isArray(t)?t:[t]).length)throw new Error("toNetInput - empty array passed as input");return n=function(e){return Array.isArray(t)?" at input index "+e+":":""},(r=e.map(nt)).forEach(function(t,r){if(!gt(t)&&!d(t)&&!h(t)){if("string"==typeof e[r])throw new Error("toNetInput -"+n(r)+" string passed, but could not resolve HTMLElement for element id "+e[r]);throw new Error("toNetInput -"+n(r)+" expected media to be of type HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | tf.Tensor3D, or to be an element id")}if(h(t)){var i=t.shape[0];if(1!==i)throw new Error("toNetInput -"+n(r)+" tf.Tensor4D with batchSize "+i+" passed, but not supported in input array")}}),[4,Promise.all(r.map(function(t){return gt(t)&&lt(t)}))];case 1:return i.sent(),[2,new yt(r,Array.isArray(t))]}})})}function xt(t,e){return Object(s.b)(this,void 0,void 0,function(){var n,r,i,a,o,u;return Object(s.d)(this,function(s){switch(s.label){case 0:return n=et.getEnv().Canvas,r=t,t instanceof n?[3,5]:[4,bt(t)];case 1:if((i=s.sent()).batchSize>1)throw new Error("extractFaces - batchSize > 1 not supported");return(a=i.getInput(0))instanceof n?(o=a,[3,4]):[3,2];case 2:return[4,mt(a)];case 3:o=s.sent(),s.label=4;case 4:r=o,s.label=5;case 5:return u=rt(r),[2,e.map(function(t){return t instanceof C?t.forSize(r.width,r.height).box.floor():t}).map(function(t){return t.clipAtImageBorders(r.width,r.height)}).map(function(t){var e=t.x,n=t.y,r=t.width,i=t.height,a=ht({width:r,height:i});return rt(a).putImageData(u.getImageData(e,n,r,i),0,0),a})]}})})}function wt(t,e){return Object(s.b)(this,void 0,void 0,function(){return Object(s.d)(this,function(n){if(!d(t)&&!h(t))throw new Error("extractFaceTensors - expected image tensor to be 3D or 4D");if(h(t)&&t.shape[0]>1)throw new Error("extractFaceTensors - batchSize > 1 not supported");return[2,a.tidy(function(){var n=t.shape.slice(h(t)?1:0),r=n[0],i=n[1],o=n[2];return e.map(function(t){return t instanceof C?t.forSize(i,r).box:t}).map(function(t){return t.clipAtImageBorders(i,r)}).map(function(e){var n=e.x,s=e.y,u=e.width,c=e.height;return a.slice3d(t.as3D(r,i,o),[s,n,0],[c,u,o])})})]})})}function kt(t,e){return Object(s.b)(this,void 0,void 0,function(){var n;return Object(s.d)(this,function(r){switch(r.label){case 0:return[4,(0,et.getEnv().fetch)(t,e)];case 1:if(!((n=r.sent()).status<400))throw new Error("failed to fetch: ("+n.status+") "+n.statusText+", from url: "+n.url);return[2,n]}})})}function _t(t){return Object(s.b)(this,void 0,void 0,function(){var e,n;return Object(s.d)(this,function(r){switch(r.label){case 0:return[4,kt(t)];case 1:return[4,(e=r.sent()).blob()];case 2:if(!(n=r.sent()).type.startsWith("image/"))throw new Error("fetchImage - expected blob type to be of type image/*, instead have: "+n.type+", for url: "+e.url);return[2,ft(n)]}})})}function Et(t){return Object(s.b)(this,void 0,void 0,function(){return Object(s.d)(this,function(e){switch(e.label){case 0:return[4,kt(t)];case 1:return[2,e.sent().json()]}})})}function Ot(t){return Object(s.b)(this,void 0,void 0,function(){var e;return Object(s.d)(this,function(n){switch(n.label){case 0:return e=Float32Array.bind,[4,kt(t)];case 1:return[4,n.sent().arrayBuffer()];case 2:return[2,new(e.apply(Float32Array,[void 0,n.sent()]))]}})})}function St(t,e){var n=e+"-weights_manifest.json";if(!t)return{modelBaseUri:"",manifestUri:n};if("/"===t)return{modelBaseUri:"/",manifestUri:"/"+n};var r=t.startsWith("http://")?"http://":t.startsWith("https://")?"https://":"",i=(t=t.replace(r,"")).split("/").filter(function(t){return t}),a=t.endsWith(".json")?i[i.length-1]:n,o=r+(t.endsWith(".json")?i.slice(0,i.length-1):i).join("/");return{modelBaseUri:o=t.startsWith("/")?"/"+o:o,manifestUri:"/"===o?"/"+a:o+"/"+a}}function Ct(t,e){return Object(s.b)(this,void 0,void 0,function(){var n,r,i,o;return Object(s.d)(this,function(s){switch(s.label){case 0:return n=St(t,e),r=n.manifestUri,i=n.modelBaseUri,[4,Et(r)];case 1:return o=s.sent(),[2,a.io.loadWeights(o,i)]}})})}function At(t,e,n){void 0===n&&(n=!1);var r=n?dt(e):e,i=r.width,a=r.height;return t.width=i,t.height=a,{width:i,height:a}}var Nt=function(){function t(t){this._name=t,this._params=void 0,this._paramMappings=[]}return Object.defineProperty(t.prototype,"params",{get:function(){return this._params},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"paramMappings",{get:function(){return this._paramMappings},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isLoaded",{get:function(){return!!this.params},enumerable:!0,configurable:!0}),t.prototype.getParamFromPath=function(t){var e=this.traversePropertyPath(t);return e.obj[e.objProp]},t.prototype.reassignParamFromPath=function(t,e){var n=this.traversePropertyPath(t),r=n.obj,i=n.objProp;r[i].dispose(),r[i]=e},t.prototype.getParamList=function(){var t=this;return this._paramMappings.map(function(e){var n=e.paramPath;return{path:n,tensor:t.getParamFromPath(n)}})},t.prototype.getTrainableParams=function(){return this.getParamList().filter(function(t){return t.tensor instanceof a.Variable})},t.prototype.getFrozenParams=function(){return this.getParamList().filter(function(t){return!(t.tensor instanceof a.Variable)})},t.prototype.variable=function(){var t=this;this.getFrozenParams().forEach(function(e){var n=e.path,r=e.tensor;t.reassignParamFromPath(n,r.variable())})},t.prototype.freeze=function(){var t=this;this.getTrainableParams().forEach(function(e){var n=e.path,r=e.tensor,i=a.tensor(r.dataSync());r.dispose(),t.reassignParamFromPath(n,i)})},t.prototype.dispose=function(t){void 0===t&&(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},t.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)}))},t.prototype.load=function(t){return Object(s.b)(this,void 0,void 0,function(){return Object(s.d)(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]}})})},t.prototype.loadFromUri=function(t){return Object(s.b)(this,void 0,void 0,function(){var e;return Object(s.d)(this,function(n){switch(n.label){case 0:if(t&&"string"!=typeof t)throw new Error(this._name+".loadFromUri - expected model uri");return[4,Ct(t,this.getDefaultModelName())];case 1:return e=n.sent(),this.loadFromWeightMap(e),[2]}})})},t.prototype.loadFromDisk=function(t){return Object(s.b)(this,void 0,void 0,function(){var e,n,r,i,o,u,c,l,f,d;return Object(s.d)(this,function(s){switch(s.label){case 0:if(t&&"string"!=typeof t)throw new Error(this._name+".loadFromDisk - expected model file path");return e=et.getEnv().readFile,n=St(t,this.getDefaultModelName()),r=n.manifestUri,i=n.modelBaseUri,o=function(t){return Promise.all(t.map(function(t){return e(t).then(function(t){return t.buffer})}))},u=a.io.weightsLoaderFactory(o),f=(l=JSON).parse,[4,e(r)];case 1:return c=f.apply(l,[s.sent().toString()]),[4,u(c,i)];case 2:return d=s.sent(),this.loadFromWeightMap(d),[2]}})})},t.prototype.loadFromWeightMap=function(t){var e=this.extractParamsFromWeigthMap(t),n=e.paramMappings,r=e.params;this._paramMappings=n,this._params=r},t.prototype.extractWeights=function(t){var e=this.extractParams(t),n=e.paramMappings,r=e.params;this._paramMappings=n,this._params=r},t.prototype.traversePropertyPath=function(t){if(!this.params)throw new Error("traversePropertyPath - model has no loaded params");var e=t.split("/").reduce(function(e,n){if(!e.nextObj.hasOwnProperty(n))throw new Error("traversePropertyPath - object does not have property "+n+", for path "+t);return{obj:e.nextObj,objProp:n,nextObj:e.nextObj[n]}},{nextObj:this.params}),n=e.obj,r=e.objProp;if(!(n&&r&&n[r]instanceof a.Tensor))throw new Error("traversePropertyPath - parameter is not a tensor, for path "+t);return{obj:n,objProp:r}},t}();function Tt(t,e,n){return a.tidy(function(){var r=a.separableConv2d(t,e.depthwise_filter,e.pointwise_filter,n,"same");return r=a.add(r,e.bias)})}function It(t,e,n){return void 0===n&&(n=!1),a.tidy(function(){var r=a.relu(n?a.add(a.conv2d(t,e.conv0.filters,[2,2],"same"),e.conv0.bias):Tt(t,e.conv0,[2,2])),i=Tt(r,e.conv1,[1,1]),o=Tt(a.relu(a.add(r,i)),e.conv2,[1,1]);return a.relu(a.add(r,a.add(i,o)))})}function Dt(t,e,n,r){return void 0===n&&(n=!1),void 0===r&&(r=!0),a.tidy(function(){var i=a.relu(n?a.add(a.conv2d(t,e.conv0.filters,r?[2,2]:[1,1],"same"),e.conv0.bias):Tt(t,e.conv0,r?[2,2]:[1,1])),o=Tt(i,e.conv1,[1,1]),s=Tt(a.relu(a.add(i,o)),e.conv2,[1,1]),u=Tt(a.relu(a.add(i,a.add(o,s))),e.conv3,[1,1]);return a.relu(a.add(i,a.add(o,a.add(s,u))))})}function Mt(t,e,n,r){return void 0===n&&(n="same"),void 0===r&&(r=!1),a.tidy(function(){var i=a.add(a.conv2d(t,e.filters,[1,1],n),e.bias);return r?a.relu(i):i})}function Rt(t,e){Object.keys(t).forEach(function(n){e.some(function(t){return t.originalPath===n})||t[n].dispose()})}function Ft(t,e){return function(n,r,i,o){var s=a.tensor4d(t(n*r*i*i),[i,i,n,r]),u=a.tensor1d(t(r));return e.push({paramPath:o+"/filters"},{paramPath:o+"/bias"}),{filters:s,bias:u}}}function jt(t,e){return function(n,r,i){var o=a.tensor2d(t(n*r),[n,r]),s=a.tensor1d(t(r));return e.push({paramPath:i+"/weights"},{paramPath:i+"/bias"}),{weights:o,bias:s}}}var Pt=function(){return function(t,e,n){this.depthwise_filter=t,this.pointwise_filter=e,this.bias=n}}();function Lt(t,e){return function(n,r,i){var o=a.tensor4d(t(9*n),[3,3,n,1]),s=a.tensor4d(t(n*r),[1,1,n,r]),u=a.tensor1d(t(r));return e.push({paramPath:i+"/depthwise_filter"},{paramPath:i+"/pointwise_filter"},{paramPath:i+"/bias"}),new Pt(o,s,u)}}function zt(t){return function(e){var n=t(e+"/depthwise_filter",4),r=t(e+"/pointwise_filter",4),i=t(e+"/bias",1);return new Pt(n,r,i)}}function Bt(t,e){return function(n,r,i){var a=t[n];if(!c(a,r))throw new Error("expected weightMap["+n+"] to be a Tensor"+r+"D, instead have "+a);return e.push({originalPath:n,paramPath:i||n}),a}}function Ut(t){var e=t;return{extractWeights:function(t){var n=e.slice(0,t);return e=e.slice(t),n},getRemainingWeights:function(){return e}}}function Wt(t,e){var n=Ft(t,e),r=Lt(t,e);function i(t,e,i,a){return void 0===a&&(a=!1),{conv0:a?n(t,e,3,i+"/conv0"):r(t,e,i+"/conv0"),conv1:r(e,e,i+"/conv1"),conv2:r(e,e,i+"/conv2")}}return{extractDenseBlock3Params:i,extractDenseBlock4Params:function(t,e,n,a){void 0===a&&(a=!1);var o=i(t,e,n,a);return{conv0:o.conv0,conv1:o.conv1,conv2:o.conv2,conv3:r(e,e,n+"/conv3")}}}}function Vt(t){return function(e){return{filters:t(e+"/filters",4),bias:t(e+"/bias",1)}}}function qt(t,e){var n=Bt(t,e),r=Vt(n),i=zt(n);return{extractDenseBlock3Params:function(t,e){return void 0===e&&(e=!1),{conv0:e?r(t+"/conv0"):i(t+"/conv0"),conv1:i(t+"/conv1"),conv2:i(t+"/conv2")}},extractDenseBlock4Params:function(t,e){return void 0===e&&(e=!1),{conv0:e?r(t+"/conv0"):i(t+"/conv0"),conv1:i(t+"/conv1"),conv2:i(t+"/conv2"),conv3:i(t+"/conv3")}}}}var Ht=function(t){function e(){return t.call(this,"FaceFeatureExtractor")||this}return Object(s.c)(e,t),e.prototype.forwardInput=function(t){var e=this.params;if(!e)throw new Error("FaceFeatureExtractor - load model before inference");return a.tidy(function(){var n=Dt(I(t.toBatchTensor(112,!0),[122.782,117.001,104.298]).div(a.scalar(255)),e.dense0,!0);return n=Dt(n=Dt(n=Dt(n,e.dense1),e.dense2),e.dense3),n=a.avgPool(n,[7,7],[2,2],"valid")})},e.prototype.forward=function(t){return Object(s.b)(this,void 0,void 0,function(){var e;return Object(s.d)(this,function(n){switch(n.label){case 0:return e=this.forwardInput,[4,bt(t)];case 1:return[2,e.apply(this,[n.sent()])]}})})},e.prototype.getDefaultModelName=function(){return"face_feature_extractor_model"},e.prototype.extractParamsFromWeigthMap=function(t){return function(t){var e=[],n=qt(t,e).extractDenseBlock4Params,r={dense0:n("dense0",!0),dense1:n("dense1"),dense2:n("dense2"),dense3:n("dense3")};return Rt(t,e),{params:r,paramMappings:e}}(t)},e.prototype.extractParams=function(t){return function(t){var e=[],n=Ut(t),r=n.extractWeights,i=n.getRemainingWeights,a=Wt(r,e).extractDenseBlock4Params,o=a(3,32,"dense0",!0),s=a(32,64,"dense1"),u=a(64,128,"dense2"),c=a(128,256,"dense3");if(0!==i().length)throw new Error("weights remaing after extract: "+i().length);return{paramMappings:e,params:{dense0:o,dense1:s,dense2:u,dense3:c}}}(t)},e}(Nt);function Gt(t,e){return a.tidy(function(){return a.add(a.matMul(t,e.weights),e.bias)})}function $t(t){var e={},n={};return Object.keys(t).forEach(function(r){(r.startsWith("fc")?n:e)[r]=t[r]}),{featureExtractorMap:e,classifierMap:n}}var Kt=function(t){function e(e,n){var r=t.call(this,e)||this;return r._faceFeatureExtractor=n,r}return Object(s.c)(e,t),Object.defineProperty(e.prototype,"faceFeatureExtractor",{get:function(){return this._faceFeatureExtractor},enumerable:!0,configurable:!0}),e.prototype.runNet=function(t){var e=this,n=this.params;if(!n)throw new Error(this._name+" - load model before inference");return a.tidy(function(){var r=t instanceof yt?e.faceFeatureExtractor.forwardInput(t):t;return Gt(r.as2D(r.shape[0],-1),n.fc)})},e.prototype.dispose=function(e){void 0===e&&(e=!0),this.faceFeatureExtractor.dispose(e),t.prototype.dispose.call(this,e)},e.prototype.loadClassifierParams=function(t){var e=this.extractClassifierParams(t),n=e.params,r=e.paramMappings;this._params=n,this._paramMappings=r},e.prototype.extractClassifierParams=function(t){return function(t,e,n){var r=[],i=Ut(t),a=i.extractWeights,o=i.getRemainingWeights,s=jt(a,r)(e,n,"fc");if(0!==o().length)throw new Error("weights remaing after extract: "+o().length);return{paramMappings:r,params:{fc:s}}}(t,this.getClassifierChannelsIn(),this.getClassifierChannelsOut())},e.prototype.extractParamsFromWeigthMap=function(t){var e=$t(t),n=e.featureExtractorMap,r=e.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(n),function(t){var e=[],n=Bt(t,e),r={fc:function(t){return{weights:n(t+"/weights",2),bias:n(t+"/bias",1)}}("fc")};return Rt(t,e),{params:r,paramMappings:e}}(r)},e.prototype.extractParams=function(t){var e=this.getClassifierChannelsIn(),n=this.getClassifierChannelsOut(),r=n*e+n,i=t.slice(0,t.length-r),a=t.slice(t.length-r);return this.faceFeatureExtractor.extractWeights(i),this.extractClassifierParams(a)},e}(Nt),Xt=["neutral","happy","sad","angry","fearful","disgusted","surprised"],Yt=function(){function t(t){var e=this;if(7!==t.length)throw new Error("FaceExpressions.constructor - expected probabilities.length to be 7, have: "+t.length);Xt.forEach(function(n,r){e[n]=t[r]})}return t.prototype.asSortedArray=function(){var t=this;return Xt.map(function(e){return{expression:e,probability:t[e]}}).sort(function(t,e){return e.probability-t.probability})},t}(),Jt=function(t){function e(e){return void 0===e&&(e=new Ht),t.call(this,"FaceExpressionNet",e)||this}return Object(s.c)(e,t),e.prototype.forwardInput=function(t){var e=this;return a.tidy(function(){return a.softmax(e.runNet(t))})},e.prototype.forward=function(t){return Object(s.b)(this,void 0,void 0,function(){var e;return Object(s.d)(this,function(n){switch(n.label){case 0:return e=this.forwardInput,[4,bt(t)];case 1:return[2,e.apply(this,[n.sent()])]}})})},e.prototype.predictExpressions=function(t){return Object(s.b)(this,void 0,void 0,function(){var e,n,r,i,o=this;return Object(s.d)(this,function(u){switch(u.label){case 0:return[4,bt(t)];case 1:return e=u.sent(),[4,this.forwardInput(e)];case 2:return n=u.sent(),[4,Promise.all(a.unstack(n).map(function(t){return Object(s.b)(o,void 0,void 0,function(){var e;return Object(s.d)(this,function(n){switch(n.label){case 0:return[4,t.data()];case 1:return e=n.sent(),t.dispose(),[2,e]}})})}))];case 3:return r=u.sent(),n.dispose(),i=r.map(function(t){return new Yt(t)}),[2,e.isBatchInput?i:i[0]]}})})},e.prototype.getDefaultModelName=function(){return"face_expression_model"},e.prototype.getClassifierChannelsIn=function(){return 256},e.prototype.getClassifierChannelsOut=function(){return 7},e}(Kt);function Zt(t){return t.expressions instanceof Yt}function Qt(t,e){var n={expressions:e};return Object.assign({},t,n)}function te(t,e,n,r){void 0===n&&(n=.1),(Array.isArray(e)?e:[e]).forEach(function(e){var i=e instanceof Yt?e:Zt(e)?e.expressions:void 0;if(!i)throw new Error("drawFaceExpressions - expected faceExpressions to be FaceExpressions | WithFaceExpressions<{}> or array thereof");var a=i.asSortedArray().filter(function(t){return t.probability>n}),o=q(e)?e.detection.box.bottomLeft:r||new _(0,0);new at(a.map(function(t){return t.expression+" ("+g(t.probability)+")"}),o).draw(t)})}function ee(t){return q(t)&&t.landmarks instanceof P&&t.unshiftedLandmarks instanceof P&&t.alignedRect instanceof C}function ne(t,e){var n=t.detection.box,r=e.shiftBy(n.x,n.y),i=r.align(),a=t.detection.imageDims,o={landmarks:r,unshiftedLandmarks:e,alignedRect:new C(t.detection.score,i.rescale(a.reverse()),a)};return Object.assign({},t,o)}var re=function(){return function(t){void 0===t&&(t={});var e=t.drawLines,n=void 0===e||e,r=t.drawPoints,i=void 0===r||r,a=t.lineWidth,o=t.lineColor,s=t.pointSize,u=t.pointColor;this.drawLines=n,this.drawPoints=i,this.lineWidth=a||1,this.pointSize=s||2,this.lineColor=o||"rgba(0, 255, 255, 1)",this.pointColor=u||"rgba(255, 0, 255, 1)"}}(),ie=function(){function t(t,e){void 0===e&&(e={}),this.faceLandmarks=t,this.options=new re(e)}return t.prototype.draw=function(t){var e=rt(t),n=this.options,r=n.drawLines,i=n.drawPoints,a=n.lineWidth,s=n.lineColor,u=n.pointSize,c=n.pointColor;if(r&&this.faceLandmarks instanceof z&&(e.strokeStyle=s,e.lineWidth=a,o(e,this.faceLandmarks.getJawOutline()),o(e,this.faceLandmarks.getLeftEyeBrow()),o(e,this.faceLandmarks.getRightEyeBrow()),o(e,this.faceLandmarks.getNose()),o(e,this.faceLandmarks.getLeftEye(),!0),o(e,this.faceLandmarks.getRightEye(),!0),o(e,this.faceLandmarks.getMouth(),!0)),i){e.strokeStyle=c,e.fillStyle=c;this.faceLandmarks.positions.forEach(function(t){e.beginPath(),e.arc(t.x,t.y,u,0,2*Math.PI),e.fill()})}},t}();function ae(t,e){(Array.isArray(e)?e:[e]).forEach(function(e){var n=e instanceof P?e:ee(e)?e.landmarks:void 0;if(!n)throw new Error("drawFaceLandmarks - expected faceExpressions to be FaceLandmarks | WithFaceLandmarks<WithFaceDetection<{}>> or array thereof");new ie(n).draw(t)})}function oe(t,e){var n=[],r=Ut(t),i=r.extractWeights,a=r.getRemainingWeights,o=function(t,e){var n=Ft(t,e),r=Lt(t,e);return{extractConvParams:n,extractSeparableConvParams:r,extractReductionBlockParams:function(t,e,i){return{separable_conv0:r(t,e,i+"/separable_conv0"),separable_conv1:r(e,e,i+"/separable_conv1"),expansion_conv:n(t,e,1,i+"/expansion_conv")}},extractMainBlockParams:function(t,e){return{separable_conv0:r(t,t,e+"/separable_conv0"),separable_conv1:r(t,t,e+"/separable_conv1"),separable_conv2:r(t,t,e+"/separable_conv2")}}}}(i,n),s=o.extractConvParams,u=o.extractSeparableConvParams,c=o.extractReductionBlockParams,l=o.extractMainBlockParams,f={conv_in:s(3,32,3,"entry_flow/conv_in"),reduction_block_0:c(32,64,"entry_flow/reduction_block_0"),reduction_block_1:c(64,128,"entry_flow/reduction_block_1")},d={};x(e,0,1).forEach(function(t){d["main_block_"+t]=l(128,"middle_flow/main_block_"+t)});var h={reduction_block:c(128,256,"exit_flow/reduction_block"),separable_conv:u(256,512,"exit_flow/separable_conv")};if(0!==a().length)throw new Error("weights remaing after extract: "+a().length);return{paramMappings:n,params:{entry_flow:f,middle_flow:d,exit_flow:h}}}function se(t,e){var n=[],r=function(t,e){var n=Bt(t,e),r=Vt(n),i=zt(n);return{extractConvParams:r,extractSeparableConvParams:i,extractReductionBlockParams:function(t){return{separable_conv0:i(t+"/separable_conv0"),separable_conv1:i(t+"/separable_conv1"),expansion_conv:r(t+"/expansion_conv")}},extractMainBlockParams:function(t){return{separable_conv0:i(t+"/separable_conv0"),separable_conv1:i(t+"/separable_conv1"),separable_conv2:i(t+"/separable_conv2")}}}}(t,n),i=r.extractConvParams,a=r.extractSeparableConvParams,o=r.extractReductionBlockParams,s=r.extractMainBlockParams,u={conv_in:i("entry_flow/conv_in"),reduction_block_0:o("entry_flow/reduction_block_0"),reduction_block_1:o("entry_flow/reduction_block_1")},c={};x(e,0,1).forEach(function(t){c["main_block_"+t]=s("middle_flow/main_block_"+t)});var l={reduction_block:o("exit_flow/reduction_block"),separable_conv:a("exit_flow/separable_conv")};return Rt(t,n),{params:{entry_flow:u,middle_flow:c,exit_flow:l},paramMappings:n}}function ue(t,e,n){return a.add(a.conv2d(t,e.filters,n,"same"),e.bias)}function ce(t,e,n){void 0===n&&(n=!0);var r=n?a.relu(t):t;return r=Tt(r,e.separable_conv0,[1,1]),r=Tt(a.relu(r),e.separable_conv1,[1,1]),r=a.maxPool(r,[3,3],[2,2],"same"),r=a.add(r,ue(t,e.expansion_conv,[2,2]))}var le,fe=function(t){function e(e){var n=t.call(this,"TinyXception")||this;return n._numMainBlocks=e,n}return Object(s.c)(e,t),e.prototype.forwardInput=function(t){var e=this,n=this.params;if(!n)throw new Error("TinyXception - load model before inference");return a.tidy(function(){var r=I(t.toBatchTensor(112,!0),[122.782,117.001,104.298]).div(a.scalar(256)),i=a.relu(ue(r,n.entry_flow.conv_in,[2,2]));return i=ce(i=ce(i,n.entry_flow.reduction_block_0,!1),n.entry_flow.reduction_block_1),x(e._numMainBlocks,0,1).forEach(function(t){i=function(t,e){var n=Tt(a.relu(t),e.separable_conv0,[1,1]);return n=Tt(a.relu(n),e.separable_conv1,[1,1]),n=Tt(a.relu(n),e.separable_conv2,[1,1]),n=a.add(n,t)}(i,n.middle_flow["main_block_"+t])}),i=ce(i,n.exit_flow.reduction_block),i=a.relu(Tt(i,n.exit_flow.separable_conv,[1,1]))})},e.prototype.forward=function(t){return Object(s.b)(this,void 0,void 0,function(){var e;return Object(s.d)(this,function(n){switch(n.label){case 0:return e=this.forwardInput,[4,bt(t)];case 1:return[2,e.apply(this,[n.sent()])]}})})},e.prototype.getDefaultModelName=function(){return"tiny_xception_model"},e.prototype.extractParamsFromWeigthMap=function(t){return se(t,this._numMainBlocks)},e.prototype.extractParams=function(t){return oe(t,this._numMainBlocks)},e}(Nt);!function(t){t.FEMALE="female",t.MALE="male"}(le||(le={}));var de=function(t){function e(e){void 0===e&&(e=new fe(2));var n=t.call(this,"AgeGenderNet")||this;return n._faceFeatureExtractor=e,n}return Object(s.c)(e,t),Object.defineProperty(e.prototype,"faceFeatureExtractor",{get:function(){return this._faceFeatureExtractor},enumerable:!0,configurable:!0}),e.prototype.runNet=function(t){var e=this,n=this.params;if(!n)throw new Error(this._name+" - load model before inference");return a.tidy(function(){var r=t instanceof yt?e.faceFeatureExtractor.forwardInput(t):t,i=a.avgPool(r,[7,7],[2,2],"valid").as2D(r.shape[0],-1);return{age:Gt(i,n.fc.age).as1D(),gender:Gt(i,n.fc.gender)}})},e.prototype.forwardInput=function(t){var e=this;return a.tidy(function(){var n=e.runNet(t),r=n.age,i=n.gender;return{age:r,gender:a.softmax(i)}})},e.prototype.forward=function(t){return Object(s.b)(this,void 0,void 0,function(){var e;return Object(s.d)(this,function(n){switch(n.label){case 0:return e=this.forwardInput,[4,bt(t)];case 1:return[2,e.apply(this,[n.sent()])]}})})},e.prototype.predictAgeAndGender=function(t){return Object(s.b)(this,void 0,void 0,function(){var e,n,r,i,o,u,c=this;return Object(s.d)(this,function(l){switch(l.label){case 0:return[4,bt(t)];case 1:return e=l.sent(),[4,this.forwardInput(e)];case 2:return n=l.sent(),r=a.unstack(n.age),i=a.unstack(n.gender),o=r.map(function(t,e){return{ageTensor:t,genderTensor:i[e]}}),[4,Promise.all(o.map(function(t){var e=t.ageTensor,n=t.genderTensor;return Object(s.b)(c,void 0,void 0,function(){var t,r,i,a,o;return Object(s.d)(this,function(s){switch(s.label){case 0:return[4,e.data()];case 1:return t=s.sent()[0],[4,n.data()];case 2:return r=s.sent()[0],a=(i=r>.5)?le.MALE:le.FEMALE,o=i?r:1-r,e.dispose(),n.dispose(),[2,{age:t,gender:a,genderProbability:o}]}})})}))];case 3:return u=l.sent(),n.age.dispose(),n.gender.dispose(),[2,e.isBatchInput?u:u[0]]}})})},e.prototype.getDefaultModelName=function(){return"age_gender_model"},e.prototype.dispose=function(e){void 0===e&&(e=!0),this.faceFeatureExtractor.dispose(e),t.prototype.dispose.call(this,e)},e.prototype.loadClassifierParams=function(t){var e=this.extractClassifierParams(t),n=e.params,r=e.paramMappings;this._params=n,this._paramMappings=r},e.prototype.extractClassifierParams=function(t){return function(t){var e=[],n=Ut(t),r=n.extractWeights,i=n.getRemainingWeights,a=jt(r,e),o=a(512,1,"fc/age"),s=a(512,2,"fc/gender");if(0!==i().length)throw new Error("weights remaing after extract: "+i().length);return{paramMappings:e,params:{fc:{age:o,gender:s}}}}(t)},e.prototype.extractParamsFromWeigthMap=function(t){var e=$t(t),n=e.featureExtractorMap,r=e.classifierMap;return this.faceFeatureExtractor.loadFromWeightMap(n),function(t){var e=[],n=Bt(t,e);function r(t){return{weights:n(t+"/weights",2),bias:n(t+"/bias",1)}}var i={fc:{age:r("fc/age"),gender:r("fc/gender")}};return Rt(t,e),{params:i,paramMappings:e}}(r)},e.prototype.extractParams=function(t){var e=t.slice(0,t.length-1539),n=t.slice(t.length-1539);return this.faceFeatureExtractor.extractWeights(e),this.extractClassifierParams(n)},e}(Nt),he=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Object(s.c)(e,t),e.prototype.postProcess=function(t,e,n){var r=n.map(function(t){var n=t.width,r=t.height,i=e/Math.max(r,n);return{width:n*i,height:r*i}}),i=r.length;return a.tidy(function(){var n=function(t,e){return a.stack([a.fill([68],t),a.fill([68],e)],1).as2D(1,136).as1D()},o=function(t,e){var n=r[t],i=n.width,a=n.height;return e(i,a)?Math.abs(i-a)/2:0};return t.mul(a.fill([i,136],e)).sub(a.stack(Array.from(Array(i),function(t,e){return n(function(t){return o(t,function(t,e){return t<e})}(e),function(t){return o(t,function(t,e){return e<t})}(e))}))).div(a.stack(Array.from(Array(i),function(t,e){return n(r[e].width,r[e].height)})))})},e.prototype.forwardInput=function(t){var e=this;return a.tidy(function(){var n=e.runNet(t);return e.postProcess(n,t.inputSize,t.inputDimensions.map(function(t){return{height:t[0],width:t[1]}}))})},e.prototype.forward=function(t){return Object(s.b)(this,void 0,void 0,function(){var e;return Object(s.d)(this,function(n){switch(n.label){case 0:return e=this.forwardInput,[4,bt(t)];case 1:return[2,e.apply(this,[n.sent()])]}})})},e.prototype.detectLandmarks=function(t){return Object(s.b)(this,void 0,void 0,function(){var e,n,r,i=this;return Object(s.d)(this,function(o){switch(o.label){case 0:return[4,bt(t)];case 1:return e=o.sent(),n=a.tidy(function(){return a.unstack(i.forwardInput(e))}),[4,Promise.all(n.map(function(t,n){return Object(s.b)(i,void 0,void 0,function(){var r,i,a,o,u;return Object(s.d)(this,function(s){switch(s.label){case 0:return a=(i=Array).from,[4,t.data()];case 1:return r=a.apply(i,[s.sent()]),o=r.filter(function(t,e){return m(e)}),u=r.filter(function(t,e){return!m(e)}),[2,new z(Array(68).fill(0).map(function(t,e){return new _(o[e],u[e])}),{height:e.getInputHeight(n),width:e.getInputWidth(n)})]}})})}))];case 2:return r=o.sent(),n.forEach(function(t){return t.dispose()}),[2,e.isBatchInput?r:r[0]]}})})},e.prototype.getClassifierChannelsOut=function(){return 136},e}(Kt),pe=function(t){function e(e){return void 0===e&&(e=new Ht),t.call(this,"FaceLandmark68Net",e)||this}return Object(s.c)(e,t),e.prototype.getDefaultModelName=function(){return"face_landmark_68_model"},e.prototype.getClassifierChannelsIn=function(){return 256},e}(he);var me=function(t){function e(){return t.call(this,"TinyFaceFeatureExtractor")||this}return Object(s.c)(e,t),e.prototype.forwardInput=function(t){var e=this.params;if(!e)throw new Error("TinyFaceFeatureExtractor - load model before inference");return a.tidy(function(){var n=It(I(t.toBatchTensor(112,!0),[122.782,117.001,104.298]).div(a.scalar(255)),e.dense0,!0);return n=It(n=It(n,e.dense1),e.dense2),n=a.avgPool(n,[14,14],[2,2],"valid")})},e.prototype.forward=function(t){return Object(s.b)(this,void 0,void 0,function(){var e;return Object(s.d)(this,function(n){switch(n.label){case 0:return e=this.forwardInput,[4,bt(t)];case 1:return[2,e.apply(this,[n.sent()])]}})})},e.prototype.getDefaultModelName=function(){return"face_feature_extractor_tiny_model"},e.prototype.extractParamsFromWeigthMap=function(t){return function(t){var e=[],n=qt(t,e).extractDenseBlock3Params,r={dense0:n("dense0",!0),dense1:n("dense1"),dense2:n("dense2")};return Rt(t,e),{params:r,paramMappings:e}}(t)},e.prototype.extractParams=function(t){return function(t){var e=[],n=Ut(t),r=n.extractWeights,i=n.getRemainingWeights,a=Wt(r,e).extractDenseBlock3Params,o=a(3,32,"dense0",!0),s=a(32,64,"dense1"),u=a(64,128,"dense2");if(0!==i().length)throw new Error("weights remaing after extract: "+i().length);return{paramMappings:e,params:{dense0:o,dense1:s,dense2:u}}}(t)},e}(Nt),ge=function(t){function e(e){return void 0===e&&(e=new me),t.call(this,"FaceLandmark68TinyNet",e)||this}return Object(s.c)(e,t),e.prototype.getDefaultModelName=function(){return"face_landmark_68_tiny_model"},e.prototype.getClassifierChannelsIn=function(){return 128},e}(he),ve=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Object(s.c)(e,t),e}(pe);function ye(t,e,n,r,i){void 0===i&&(i="same");var o=e.conv,s=o.filters,u=o.bias,c=a.conv2d(t,s,n,i);return c=function(t,e){return a.add(a.mul(t,e.weights),e.biases)}(c=a.add(c,u),e.scale),r?a.relu(c):c}function be(t,e){return ye(t,e,[1,1],!1)}function xe(t,e){return ye(t,e,[2,2],!0,"valid")}function we(t,e){function n(n,r,i,o){var s=function(e,n,r){var i=t(e),o=i.length/(n*r*r);if(p(o))throw new Error("depth has to be an integer: "+o+", weights.length: "+i.length+", numFilters: "+n+", filterSize: "+r);return a.tidy(function(){return a.transpose(a.tensor4d(i,[n,o,r,r]),[2,3,1,0])})}(n,r,i),u=a.tensor1d(t(r));return e.push({paramPath:o+"/filters"},{paramPath:o+"/bias"}),{filters:s,bias:u}}function r(r,i,o,s){return{conv:n(r,i,o,s+"/conv"),scale:function(n,r){var i=a.tensor1d(t(n)),o=a.tensor1d(t(n));return e.push({paramPath:r+"/weights"},{paramPath:r+"/biases"}),{weights:i,biases:o}}(i,s+"/scale")}}return{extractConvLayerParams:r,extractResidualLayerParams:function(t,e,n,i,a){return void 0===a&&(a=!1),{conv1:r((a?.5:1)*t,e,n,i+"/conv1"),conv2:r(t,e,n,i+"/conv2")}}}}function ke(t,e){var n=Bt(t,e);function r(t){return{conv:{filters:n(t+"/conv/filters",4),bias:n(t+"/conv/bias",1)},scale:function(t){return{weights:n(t+"/scale/weights",1),biases:n(t+"/scale/biases",1)}}(t)}}return{extractConvLayerParams:r,extractResidualLayerParams:function(t){return{conv1:r(t+"/conv1"),conv2:r(t+"/conv2")}}}}function _e(t,e){var n=function(t,e){return ye(t,e,[1,1],!0)}(t,e.conv1);return n=be(n,e.conv2),n=a.add(n,t),n=a.relu(n)}function Ee(t,e){var n=xe(t,e.conv1);n=be(n,e.conv2);var r=a.avgPool(t,2,2,"valid"),i=a.zeros(r.shape),o=r.shape[3]!==n.shape[3];if(r.shape[1]!==n.shape[1]||r.shape[2]!==n.shape[2]){var u=Object(s.e)(n.shape);u[1]=1;var c=a.zeros(u);n=a.concat([n,c],1);var l=Object(s.e)(n.shape);l[2]=1;var f=a.zeros(l);n=a.concat([n,f],2)}return r=o?a.concat([r,i],3):r,n=a.add(r,n),n=a.relu(n)}var Oe=function(t){function e(){return t.call(this,"FaceRecognitionNet")||this}return Object(s.c)(e,t),e.prototype.forwardInput=function(t){var e=this.params;if(!e)throw new Error("FaceRecognitionNet - load model before inference");return a.tidy(function(){var n=xe(I(t.toBatchTensor(150,!0).toFloat(),[122.782,117.001,104.298]).div(a.scalar(256)),e.conv32_down),r=(n=Ee(n=_e(n=_e(n=Ee(n=_e(n=_e(n=Ee(n=_e(n=_e(n=_e(n=Ee(n=_e(n=_e(n=_e(n=a.maxPool(n,3,2,"valid"),e.conv32_1),e.conv32_2),e.conv32_3),e.conv64_down),e.conv64_1),e.conv64_2),e.conv64_3),e.conv128_down),e.conv128_1),e.conv128_2),e.conv256_down),e.conv256_1),e.conv256_2),e.conv256_down_out)).mean([1,2]);return a.matMul(r,e.fc)})},e.prototype.forward=function(t){return Object(s.b)(this,void 0,void 0,function(){var e;return Object(s.d)(this,function(n){switch(n.label){case 0:return e=this.forwardInput,[4,bt(t)];case 1:return[2,e.apply(this,[n.sent()])]}})})},e.prototype.computeFaceDescriptor=function(t){return Object(s.b)(this,void 0,void 0,function(){var e,n,r,i=this;return Object(s.d)(this,function(o){switch(o.label){case 0:return[4,bt(t)];case 1:return e=o.sent(),n=a.tidy(function(){return a.unstack(i.forwardInput(e))}),[4,Promise.all(n.map(function(t){return t.data()}))];case 2:return r=o.sent(),n.forEach(function(t){return t.dispose()}),[2,e.isBatchInput?r:r[0]]}})})},e.prototype.getDefaultModelName=function(){return"face_recognition_model"},e.prototype.extractParamsFromWeigthMap=function(t){return function(t){var e=[],n=ke(t,e),r=n.extractConvLayerParams,i=n.extractResidualLayerParams,a=r("conv32_down"),o=i("conv32_1"),s=i("conv32_2"),u=i("conv32_3"),c=i("conv64_down"),l=i("conv64_1"),d=i("conv64_2"),h=i("conv64_3"),p=i("conv128_down"),m=i("conv128_1"),g=i("conv128_2"),v=i("conv256_down"),y=i("conv256_1"),b=i("conv256_2"),x=i("conv256_down_out"),w=t.fc;if(e.push({originalPath:"fc",paramPath:"fc"}),!f(w))throw new Error("expected weightMap[fc] to be a Tensor2D, instead have "+w);var k={conv32_down:a,conv32_1:o,conv32_2:s,conv32_3:u,conv64_down:c,conv64_1:l,conv64_2:d,conv64_3:h,conv128_down:p,conv128_1:m,conv128_2:g,conv256_down:v,conv256_1:y,conv256_2:b,conv256_down_out:x,fc:w};return Rt(t,e),{params:k,paramMappings:e}}(t)},e.prototype.extractParams=function(t){return function(t){var e=Ut(t),n=e.extractWeights,r=e.getRemainingWeights,i=[],o=we(n,i),s=o.extractConvLayerParams,u=o.extractResidualLayerParams,c=s(4704,32,7,"conv32_down"),l=u(9216,32,3,"conv32_1"),f=u(9216,32,3,"conv32_2"),d=u(9216,32,3,"conv32_3"),h=u(36864,64,3,"conv64_down",!0),p=u(36864,64,3,"conv64_1"),m=u(36864,64,3,"conv64_2"),g=u(36864,64,3,"conv64_3"),v=u(147456,128,3,"conv128_down",!0),y=u(147456,128,3,"conv128_1"),b=u(147456,128,3,"conv128_2"),x=u(589824,256,3,"conv256_down",!0),w=u(589824,256,3,"conv256_1"),k=u(589824,256,3,"conv256_2"),_=u(589824,256,3,"conv256_down_out"),E=a.tidy(function(){return a.transpose(a.tensor2d(n(32768),[128,256]),[1,0])});if(i.push({paramPath:"fc"}),0!==r().length)throw new Error("weights remaing after extract: "+r().length);return{params:{conv32_down:c,conv32_1:l,conv32_2:f,conv32_3:d,conv64_down:h,conv64_1:p,conv64_2:m,conv64_3:g,conv128_down:v,conv128_1:y,conv128_2:b,conv256_down:x,conv256_1:w,conv256_2:k,conv256_down_out:_,fc:E},paramMappings:i}}(t)},e}(Nt);function Se(t){var e=new Oe;return e.extractWeights(t),e}function Ce(t,e){var n={descriptor:e};return Object.assign({},t,n)}function Ae(t){return"number"==typeof t.age}function Ne(t,e){var n={age:e};return Object.assign({},t,n)}function Te(t){return(t.gender===le.MALE||t.gender===le.FEMALE)&&k(t.genderProbability)}function Ie(t,e,n){var r={gender:e,genderProbability:n};return Object.assign({},t,r)}var De=function(){function t(t){var e=void 0===t?{}:t,n=e.minFaceSize,r=e.scaleFactor,i=e.maxNumScales,a=e.scoreThresholds,o=e.scaleSteps;if(this._name="MtcnnOptions",this._minFaceSize=n||20,this._scaleFactor=r||.709,this._maxNumScales=i||10,this._scoreThresholds=a||[.6,.7,.7],this._scaleSteps=o,"number"!=typeof this._minFaceSize||this._minFaceSize<0)throw new Error(this._name+" - expected minFaceSize to be a number > 0");if("number"!=typeof this._scaleFactor||this._scaleFactor<=0||this._scaleFactor>=1)throw new Error(this._name+" - expected scaleFactor to be a number between 0 and 1");if("number"!=typeof this._maxNumScales||this._maxNumScales<0)throw new Error(this._name+" - expected maxNumScales to be a number > 0");if(!Array.isArray(this._scoreThresholds)||3!==this._scoreThresholds.length||this._scoreThresholds.some(function(t){return"number"!=typeof t}))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(t){return"number"!=typeof t})))throw new Error(this._name+" - expected scaleSteps to be an array of numbers")}return Object.defineProperty(t.prototype,"minFaceSize",{get:function(){return this._minFaceSize},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scaleFactor",{get:function(){return this._scaleFactor},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"maxNumScales",{get:function(){return this._maxNumScales},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scoreThresholds",{get:function(){return this._scoreThresholds},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scaleSteps",{get:function(){return this._scaleSteps},enumerable:!0,configurable:!0}),t}();function Me(t,e){function n(n,r,i,o,s){var u=a.tensor4d(t(n*r*i*i),[i,i,n,r]),c=a.tensor1d(t(r));return e.push({paramPath:o+"/filters"},{paramPath:o+"/"+(s?"batch_norm_offset":"bias")}),{filters:u,bias:c}}function r(t,e,r,i){var a=n(t,e,r,i,!0);return{filters:a.filters,batch_norm_offset:a.bias}}function i(n,i,o){return{depthwise_conv:function(n,r){var i=a.tensor4d(t(9*n),[3,3,n,1]),o=a.tensor1d(t(n)),s=a.tensor1d(t(n)),u=a.tensor1d(t(n)),c=a.tensor1d(t(n));return e.push({paramPath:r+"/filters"},{paramPath:r+"/batch_norm_scale"},{paramPath:r+"/batch_norm_offset"},{paramPath:r+"/batch_norm_mean"},{paramPath:r+"/batch_norm_variance"}),{filters:i,batch_norm_scale:o,batch_norm_offset:s,batch_norm_mean:u,batch_norm_variance:c}}(n,o+"/depthwise_conv"),pointwise_conv:r(n,i,1,o+"/pointwise_conv")}}return{extractMobilenetV1Params:function(){return{conv_0:r(3,32,3,"mobilenetv1/conv_0"),conv_1:i(32,64,"mobilenetv1/conv_1"),conv_2:i(64,128,"mobilenetv1/conv_2"),conv_3:i(128,128,"mobilenetv1/conv_3"),conv_4:i(128,256,"mobilenetv1/conv_4"),conv_5:i(256,256,"mobilenetv1/conv_5"),conv_6:i(256,512,"mobilenetv1/conv_6"),conv_7:i(512,512,"mobilenetv1/conv_7"),conv_8:i(512,512,"mobilenetv1/conv_8"),conv_9:i(512,512,"mobilenetv1/conv_9"),conv_10:i(512,512,"mobilenetv1/conv_10"),conv_11:i(512,512,"mobilenetv1/conv_11"),conv_12:i(512,1024,"mobilenetv1/conv_12"),conv_13:i(1024,1024,"mobilenetv1/conv_13")}},extractPredictionLayerParams:function(){return{conv_0:r(1024,256,1,"prediction_layer/conv_0"),conv_1:r(256,512,3,"prediction_layer/conv_1"),conv_2:r(512,128,1,"prediction_layer/conv_2"),conv_3:r(128,256,3,"prediction_layer/conv_3"),conv_4:r(256,128,1,"prediction_layer/conv_4"),conv_5:r(128,256,3,"prediction_layer/conv_5"),conv_6:r(256,64,1,"prediction_layer/conv_6"),conv_7:r(64,128,3,"prediction_layer/conv_7"),box_predictor_0:{box_encoding_predictor:n(512,12,1,"prediction_layer/box_predictor_0/box_encoding_predictor"),class_predictor:n(512,9,1,"prediction_layer/box_predictor_0/class_predictor")},box_predictor_1:{box_encoding_predictor:n(1024,24,1,"prediction_layer/box_predictor_1/box_encoding_predictor"),class_predictor:n(1024,18,1,"prediction_layer/box_predictor_1/class_predictor")},box_predictor_2:{box_encoding_predictor:n(512,24,1,"prediction_layer/box_predictor_2/box_encoding_predictor"),class_predictor:n(512,18,1,"prediction_layer/box_predictor_2/class_predictor")},box_predictor_3:{box_encoding_predictor:n(256,24,1,"prediction_layer/box_predictor_3/box_encoding_predictor"),class_predictor:n(256,18,1,"prediction_layer/box_predictor_3/class_predictor")},box_predictor_4:{box_encoding_predictor:n(256,24,1,"prediction_layer/box_predictor_4/box_encoding_predictor"),class_predictor:n(256,18,1,"prediction_layer/box_predictor_4/class_predictor")},box_predictor_5:{box_encoding_predictor:n(128,24,1,"prediction_layer/box_predictor_5/box_encoding_predictor"),class_predictor:n(128,18,1,"prediction_layer/box_predictor_5/class_predictor")}}}}}function Re(t){var e=[],n=function(t,e){var n=Bt(t,e);function r(t,e,r){return{filters:n(t+"/Conv2d_"+e+"_pointwise/weights",4,r+"/filters"),batch_norm_offset:n(t+"/Conv2d_"+e+"_pointwise/convolution_bn_offset",1,r+"/batch_norm_offset")}}function i(t){var e="mobilenetv1/conv_"+t,i="MobilenetV1/Conv2d_"+t+"_depthwise",a=e+"/depthwise_conv",o=e+"/pointwise_conv";return{depthwise_conv:{filters:n(i+"/depthwise_weights",4,a+"/filters"),batch_norm_scale:n(i+"/BatchNorm/gamma",1,a+"/batch_norm_scale"),batch_norm_offset:n(i+"/BatchNorm/beta",1,a+"/batch_norm_offset"),batch_norm_mean:n(i+"/BatchNorm/moving_mean",1,a+"/batch_norm_mean"),batch_norm_variance:n(i+"/BatchNorm/moving_variance",1,a+"/batch_norm_variance")},pointwise_conv:r("MobilenetV1",t,o)}}function a(t,e){return{filters:n(t+"/weights",4,e+"/filters"),bias:n(t+"/biases",1,e+"/bias")}}function o(t){return{box_encoding_predictor:a("Prediction/BoxPredictor_"+t+"/BoxEncodingPredictor","prediction_layer/box_predictor_"+t+"/box_encoding_predictor"),class_predictor:a("Prediction/BoxPredictor_"+t+"/ClassPredictor","prediction_layer/box_predictor_"+t+"/class_predictor")}}return{extractMobilenetV1Params:function(){return{conv_0:r("MobilenetV1",0,"mobilenetv1/conv_0"),conv_1:i(1),conv_2:i(2),conv_3:i(3),conv_4:i(4),conv_5:i(5),conv_6:i(6),conv_7:i(7),conv_8:i(8),conv_9:i(9),conv_10:i(10),conv_11:i(11),conv_12:i(12),conv_13:i(13)}},extractPredictionLayerParams:function(){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:o(0),box_predictor_1:o(1),box_predictor_2:o(2),box_predictor_3:o(3),box_predictor_4:o(4),box_predictor_5:o(5)}}}}(t,e),r=n.extractMobilenetV1Params,i=n.extractPredictionLayerParams,a=t["Output/extra_dim"];if(e.push({originalPath:"Output/extra_dim",paramPath:"output_layer/extra_dim"}),!d(a))throw new Error("expected weightMap['Output/extra_dim'] to be a Tensor3D, instead have "+a);var o={mobilenetv1:r(),prediction_layer:i(),output_layer:{extra_dim:a}};return Rt(t,e),{params:o,paramMappings:e}}function Fe(t,e,n){return a.tidy(function(){var r=a.conv2d(t,e.filters,n,"same");return r=a.add(r,e.batch_norm_offset),a.clipByValue(r,0,6)})}var je=.0010000000474974513;function Pe(t,e){return a.tidy(function(){var n=null,r=Fe(t,e.conv_0,[2,2]);if([e.conv_1,e.conv_2,e.conv_3,e.conv_4,e.conv_5,e.conv_6,e.conv_7,e.conv_8,e.conv_9,e.conv_10,e.conv_11,e.conv_12,e.conv_13].forEach(function(t,e){var i=e+1,o=function(t){return[2,4,6,12].some(function(e){return e===t})?[2,2]:[1,1]}(i);r=Fe(r=function(t,e,n){return a.tidy(function(){var r=a.depthwiseConv2d(t,e.filters,n,"same");return r=a.batchNorm(r,e.batch_norm_mean,e.batch_norm_variance,e.batch_norm_offset,e.batch_norm_scale,je),a.clipByValue(r,0,6)})}(r,t.depthwise_conv,o),t.pointwise_conv,[1,1]),11===i&&(n=r)}),null===n)throw new Error("mobileNetV1 - output of conv layer 11 is null");return{out:r,conv11:n}})}function Le(t,e,n){var r=t.arraySync(),i=Math.min(r[e][0],r[e][2]),a=Math.min(r[e][1],r[e][3]),o=Math.max(r[e][0],r[e][2]),s=Math.max(r[e][1],r[e][3]),u=Math.min(r[n][0],r[n][2]),c=Math.min(r[n][1],r[n][3]),l=Math.max(r[n][0],r[n][2]),f=Math.max(r[n][1],r[n][3]),d=(o-i)*(s-a),h=(l-u)*(f-c);if(d<=0||h<=0)return 0;var p=Math.max(i,u),m=Math.max(a,c),g=Math.min(o,l),v=Math.min(s,f),y=Math.max(g-p,0)*Math.max(v-m,0);return y/(d+h-y)}function ze(t,e){var n=function(t){var e=a.unstack(a.transpose(t,[1,0])),n=[a.sub(e[2],e[0]),a.sub(e[3],e[1])];return{sizes:n,centers:[a.add(e[0],a.div(n[0],a.scalar(2))),a.add(e[1],a.div(n[1],a.scalar(2)))]}}(t),r=n.sizes,i=n.centers,o=a.unstack(a.transpose(e,[1,0])),s=a.div(a.mul(a.exp(a.div(o[2],a.scalar(5))),r[0]),a.scalar(2)),u=a.add(a.mul(a.div(o[0],a.scalar(10)),r[0]),i[0]),c=a.div(a.mul(a.exp(a.div(o[3],a.scalar(5))),r[1]),a.scalar(2)),l=a.add(a.mul(a.div(o[1],a.scalar(10)),r[1]),i[1]);return a.transpose(a.stack([a.sub(u,s),a.sub(l,c),a.add(u,s),a.add(l,c)]),[1,0])}function Be(t,e){return a.tidy(function(){var n=t.shape[0];return{boxPredictionEncoding:a.reshape(Mt(t,e.box_encoding_predictor),[n,-1,1,4]),classPrediction:a.reshape(Mt(t,e.class_predictor),[n,-1,3])}})}var Ue=function(){function t(t){var e=void 0===t?{}:t,n=e.minConfidence,r=e.maxResults;if(this._name="SsdMobilenetv1Options",this._minConfidence=n||.5,this._maxResults=r||100,"number"!=typeof this._minConfidence||this._minConfidence<=0||this._minConfidence>=1)throw new Error(this._name+" - expected minConfidence to be a number between 0 and 1");if("number"!=typeof this._maxResults)throw new Error(this._name+" - expected maxResults to be a number")}return Object.defineProperty(t.prototype,"minConfidence",{get:function(){return this._minConfidence},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"maxResults",{get:function(){return this._maxResults},enumerable:!0,configurable:!0}),t}(),We=function(t){function e(){return t.call(this,"SsdMobilenetv1")||this}return Object(s.c)(e,t),e.prototype.forwardInput=function(t){var e=this.params;if(!e)throw new Error("SsdMobilenetv1 - load model before inference");return a.tidy(function(){var n=t.toBatchTensor(512,!1).toFloat(),r=Pe(a.sub(a.mul(n,a.scalar(.007843137718737125)),a.scalar(1)),e.mobilenetv1),i=function(t,e,n){return a.tidy(function(){var r=Fe(Fe(t,n.conv_0,[1,1]),n.conv_1,[2,2]),i=Fe(Fe(r,n.conv_2,[1,1]),n.conv_3,[2,2]),o=Fe(Fe(i,n.conv_4,[1,1]),n.conv_5,[2,2]),s=Fe(Fe(o,n.conv_6,[1,1]),n.conv_7,[2,2]),u=Be(e,n.box_predictor_0),c=Be(t,n.box_predictor_1),l=Be(r,n.box_predictor_2),f=Be(i,n.box_predictor_3),d=Be(o,n.box_predictor_4),h=Be(s,n.box_predictor_5);return{boxPredictions:a.concat([u.boxPredictionEncoding,c.boxPredictionEncoding,l.boxPredictionEncoding,f.boxPredictionEncoding,d.boxPredictionEncoding,h.boxPredictionEncoding],1),classPredictions:a.concat([u.classPrediction,c.classPrediction,l.classPrediction,f.classPrediction,d.classPrediction,h.classPrediction],1)}})}(r.out,r.conv11,e.prediction_layer);return function(t,e,n){return a.tidy(function(){var r=t.shape[0],i=ze(a.reshape(a.tile(n.extra_dim,[r,1,1]),[-1,4]),a.reshape(t,[-1,4]));i=a.reshape(i,[r,i.shape[0]/r,4]);var o=a.sigmoid(a.slice(e,[0,0,1],[-1,-1,-1])),s=a.slice(o,[0,0,0],[-1,-1,1]);return s=a.reshape(s,[r,s.shape[1]]),{boxes:a.unstack(i),scores:a.unstack(s)}})}(i.boxPredictions,i.classPredictions,e.output_layer)})},e.prototype.forward=function(t){return Object(s.b)(this,void 0,void 0,function(){var e;return Object(s.d)(this,function(n){switch(n.label){case 0:return e=this.forwardInput,[4,bt(t)];case 1:return[2,e.apply(this,[n.sent()])]}})})},e.prototype.locateFaces=function(t,e){return void 0===e&&(e={}),Object(s.b)(this,void 0,void 0,function(){var n,r,i,a,o,u,c,l,f,d,h,p,m,g,v,y,b,x,w,k;return Object(s.d)(this,function(s){switch(s.label){case 0:return n=new Ue(e),r=n.maxResults,i=n.minConfidence,[4,bt(t)];case 1:for(a=s.sent(),o=this.forwardInput(a),u=o.boxes,c=o.scores,l=u[0],f=c[0],d=1;d<u.length;d++)u[d].dispose(),c[d].dispose();return m=(p=Array).from,[4,f.data()];case 2:return h=m.apply(p,[s.sent()]),g=function(t,e,n,r,i){var a=t.shape[0],o=Math.min(n,a),s=function(t){return t<=r?1:0},u=[];return e.map(function(t,e){return{score:t,boxIndex:e}}).filter(function(t){return t.score>i}).sort(function(t,e){return e.score-t.score}).forEach(function(e){if(!(u.length>=o)){for(var n=e.score,r=u.length-1;r>=0;--r){var a=Le(t,e.boxIndex,u[r]);if(0!==a&&(e.score*=s(a),e.score<=i))break}n===e.score&&u.push(e.boxIndex)}}),u}(l,h,r,.5,i),v=a.getReshapedInputDimensions(0),y=a.inputSize,b=y/v.width,x=y/v.height,w=l.arraySync(),k=g.map(function(t){var e=[Math.max(0,w[t][0]),Math.min(1,w[t][2])].map(function(t){return t*x}),n=e[0],r=e[1],i=[Math.max(0,w[t][1]),Math.min(1,w[t][3])].map(function(t){return t*b}),o=i[0],s=i[1];return new C(h[t],new j(o,n,s-o,r-n),{height:a.getInputHeight(0),width:a.getInputWidth(0)})}),l.dispose(),f.dispose(),[2,k]}})})},e.prototype.getDefaultModelName=function(){return"ssd_mobilenetv1_model"},e.prototype.extractParamsFromWeigthMap=function(t){return Re(t)},e.prototype.extractParams=function(t){return function(t){var e=[],n=Ut(t),r=n.extractWeights,i=n.getRemainingWeights,o=Me(r,e),s=o.extractMobilenetV1Params,u=o.extractPredictionLayerParams,c=s(),l=u(),f={extra_dim:a.tensor3d(r(20472),[1,5118,4])};if(e.push({paramPath:"output_layer/extra_dim"}),0!==i().length)throw new Error("weights remaing after extract: "+i().length);return{params:{mobilenetv1:c,prediction_layer:l,output_layer:f},paramMappings:e}}(t)},e}(Nt);function Ve(t){var e=new We;return e.extractWeights(t),e}function qe(t){return Ve(t)}var He,Ge=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Object(s.c)(e,t),e}(We),$e=.4,Ke=[new _(.738768,.874946),new _(2.42204,2.65704),new _(4.30971,7.04493),new _(10.246,4.59428),new _(12.6868,11.8741)],Xe=[new _(1.603231,2.094468),new _(6.041143,7.080126),new _(2.882459,3.518061),new _(4.266906,5.178857),new _(9.041765,10.66308)],Ye=[117.001,114.697,97.404],Je=function(t){return"number"==typeof t};function Ze(t){if(!t)throw new Error("invalid config: "+t);if("boolean"!=typeof t.withSeparableConvs)throw new Error("config.withSeparableConvs has to be a boolean, have: "+t.withSeparableConvs);if(!Je(t.iouThreshold)||t.iouThreshold<0||t.iouThreshold>1)throw new Error("config.iouThreshold has to be a number between [0, 1], have: "+t.iouThreshold);if(!Array.isArray(t.classes)||!t.classes.length||!t.classes.every(function(t){return"string"==typeof t}))throw new Error("config.classes has to be an array class names: string[], have: "+JSON.stringify(t.classes));if(!Array.isArray(t.anchors)||!t.anchors.length||!t.anchors.map(function(t){return t||{}}).every(function(t){return Je(t.x)&&Je(t.y)}))throw new Error("config.anchors has to be an array of { x: number, y: number }, have: "+JSON.stringify(t.anchors));if(t.meanRgb&&(!Array.isArray(t.meanRgb)||3!==t.meanRgb.length||!t.meanRgb.every(Je)))throw new Error("config.meanRgb has to be an array of shape [number, number, number], have: "+JSON.stringify(t.meanRgb))}function Qe(t){return a.tidy(function(){var e=a.mul(t,a.scalar(.10000000149011612));return a.add(a.relu(a.sub(t,e)),e)})}function tn(t,e){return a.tidy(function(){var n=a.pad(t,[[0,0],[1,1],[1,1],[0,0]]);return n=a.conv2d(n,e.conv.filters,[1,1],"valid"),n=a.sub(n,e.bn.sub),n=a.mul(n,e.bn.truediv),Qe(n=a.add(n,e.conv.bias))})}function en(t,e){return a.tidy(function(){var n=a.pad(t,[[0,0],[1,1],[1,1],[0,0]]);return n=a.separableConv2d(n,e.depthwise_filter,e.pointwise_filter,[1,1],"valid"),Qe(n=a.add(n,e.bias))})}function nn(t,e){var n=Ft(t,e);var r=Lt(t,e);return{extractConvParams:n,extractConvWithBatchNormParams:function(r,i,o){return{conv:n(r,i,3,o+"/conv"),bn:function(n,r){var i=a.tensor1d(t(n)),o=a.tensor1d(t(n));return e.push({paramPath:r+"/sub"},{paramPath:r+"/truediv"}),{sub:i,truediv:o}}(i,o+"/bn")}},extractSeparableConvParams:r}}function rn(t,e){var n=Bt(t,e);function r(t){return{filters:n(t+"/filters",4),bias:n(t+"/bias",1)}}return{extractConvParams:r,extractConvWithBatchNormParams:function(t){return{conv:r(t+"/conv"),bn:function(t){return{sub:n(t+"/sub",1),truediv:n(t+"/truediv",1)}}(t+"/bn")}},extractSeparableConvParams:zt(n)}}!function(t){t[t.XS=224]="XS",t[t.SM=320]="SM",t[t.MD=416]="MD",t[t.LG=608]="LG"}(He||(He={}));var an=function(){function t(t){var e=void 0===t?{}:t,n=e.inputSize,r=e.scoreThreshold;if(this._name="TinyYolov2Options",this._inputSize=n||416,this._scoreThreshold=r||.5,"number"!=typeof this._inputSize||this._inputSize%32!=0)throw new Error(this._name+" - expected inputSize to be a number divisible by 32");if("number"!=typeof this._scoreThreshold||this._scoreThreshold<=0||this._scoreThreshold>=1)throw new Error(this._name+" - expected scoreThreshold to be a number between 0 and 1")}return Object.defineProperty(t.prototype,"inputSize",{get:function(){return this._inputSize},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scoreThreshold",{get:function(){return this._scoreThreshold},enumerable:!0,configurable:!0}),t}(),on=function(t){function e(e){var n=t.call(this,"TinyYolov2")||this;return Ze(e),n._config=e,n}return Object(s.c)(e,t),Object.defineProperty(e.prototype,"config",{get:function(){return this._config},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"withClassScores",{get:function(){return this.config.withClassScores||this.config.classes.length>1},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"boxEncodingSize",{get:function(){return 5+(this.withClassScores?this.config.classes.length:0)},enumerable:!0,configurable:!0}),e.prototype.runTinyYolov2=function(t,e){var n=tn(t,e.conv0);return n=tn(n=a.maxPool(n,[2,2],[2,2],"same"),e.conv1),n=tn(n=a.maxPool(n,[2,2],[2,2],"same"),e.conv2),n=tn(n=a.maxPool(n,[2,2],[2,2],"same"),e.conv3),n=tn(n=a.maxPool(n,[2,2],[2,2],"same"),e.conv4),n=tn(n=a.maxPool(n,[2,2],[2,2],"same"),e.conv5),Mt(n=tn(n=tn(n=a.maxPool(n,[2,2],[1,1],"same"),e.conv6),e.conv7),e.conv8,"valid",!1)},e.prototype.runMobilenet=function(t,e){var n=this.config.isFirstLayerConv2d?Qe(Mt(t,e.conv0,"valid",!1)):en(t,e.conv0);return n=en(n=a.maxPool(n,[2,2],[2,2],"same"),e.conv1),n=en(n=a.maxPool(n,[2,2],[2,2],"same"),e.conv2),n=en(n=a.maxPool(n,[2,2],[2,2],"same"),e.conv3),n=en(n=a.maxPool(n,[2,2],[2,2],"same"),e.conv4),n=en(n=a.maxPool(n,[2,2],[2,2],"same"),e.conv5),n=a.maxPool(n,[2,2],[1,1],"same"),n=e.conv6?en(n,e.conv6):n,Mt(n=e.conv7?en(n,e.conv7):n,e.conv8,"valid",!1)},e.prototype.forwardInput=function(t,e){var n=this,r=this.params;if(!r)throw new Error("TinyYolov2 - load model before inference");return a.tidy(function(){var i=t.toBatchTensor(e,!1).toFloat();return i=(i=n.config.meanRgb?I(i,n.config.meanRgb):i).div(a.scalar(256)),n.config.withSeparableConvs?n.runMobilenet(i,r):n.runTinyYolov2(i,r)})},e.prototype.forward=function(t,e){return Object(s.b)(this,void 0,void 0,function(){var n;return Object(s.d)(this,function(r){switch(r.label){case 0:return n=this.forwardInput,[4,bt(t)];case 1:return[4,n.apply(this,[r.sent(),e])];case 2:return[2,r.sent()]}})})},e.prototype.detect=function(t,e){return void 0===e&&(e={}),Object(s.b)(this,void 0,void 0,function(){var n,r,i,o,u,c,l,f,d,h,p,m,g,v=this;return Object(s.d)(this,function(s){switch(s.label){case 0:return n=new an(e),r=n.inputSize,i=n.scoreThreshold,[4,bt(t)];case 1:return o=s.sent(),[4,this.forwardInput(o,r)];case 2:return u=s.sent(),c=a.tidy(function(){return a.unstack(u)[0].expandDims()}),l={width:o.getInputWidth(0),height:o.getInputHeight(0)},[4,this.extractBoxes(c,o.getReshapedInputDimensions(0),i)];case 3:return f=s.sent(),u.dispose(),c.dispose(),d=f.map(function(t){return t.box}),h=f.map(function(t){return t.score}),p=f.map(function(t){return t.classScore}),m=f.map(function(t){return v.config.classes[t.label]}),g=T(d.map(function(t){return t.rescale(r)}),h,this.config.iouThreshold,!0),[2,g.map(function(t){return new S(h[t],p[t],m[t],d[t],l)})]}})})},e.prototype.getDefaultModelName=function(){return""},e.prototype.extractParamsFromWeigthMap=function(t){return function(t,e){var n,r=[],i=rn(t,r),a=i.extractConvParams,o=i.extractConvWithBatchNormParams,s=i.extractSeparableConvParams;if(e.withSeparableConvs){var u=e.filterSizes&&e.filterSizes.length||9;n={conv0:e.isFirstLayerConv2d?a("conv0"):s("conv0"),conv1:s("conv1"),conv2:s("conv2"),conv3:s("conv3"),conv4:s("conv4"),conv5:s("conv5"),conv6:u>7?s("conv6"):void 0,conv7:u>8?s("conv7"):void 0,conv8:a("conv8")}}else n={conv0:o("conv0"),conv1:o("conv1"),conv2:o("conv2"),conv3:o("conv3"),conv4:o("conv4"),conv5:o("conv5"),conv6:o("conv6"),conv7:o("conv7"),conv8:a("conv8")};return Rt(t,r),{params:n,paramMappings:r}}(t,this.config)},e.prototype.extractParams=function(t){var n=this.config.filterSizes||e.DEFAULT_FILTER_SIZES,r=n?n.length:void 0;if(7!==r&&8!==r&&9!==r)throw new Error("TinyYolov2 - expected 7 | 8 | 9 convolutional filters, but found "+r+" filterSizes in config");return function(t,e,n,r){var i,a=Ut(t),o=a.extractWeights,s=a.getRemainingWeights,u=[],c=nn(o,u),l=c.extractConvParams,f=c.extractConvWithBatchNormParams,d=c.extractSeparableConvParams;if(e.withSeparableConvs){var h=r[0],p=r[1],m=r[2],g=r[3],v=r[4],y=r[5],b=r[6],x=r[7],w=r[8];i={conv0:e.isFirstLayerConv2d?l(h,p,3,"conv0"):d(h,p,"conv0"),conv1:d(p,m,"conv1"),conv2:d(m,g,"conv2"),conv3:d(g,v,"conv3"),conv4:d(v,y,"conv4"),conv5:d(y,b,"conv5"),conv6:x?d(b,x,"conv6"):void 0,conv7:w?d(x,w,"conv7"):void 0,conv8:l(w||x||b,5*n,1,"conv8")}}else h=r[0],p=r[1],m=r[2],g=r[3],v=r[4],y=r[5],b=r[6],x=r[7],w=r[8],i={conv0:f(h,p,"conv0"),conv1:f(p,m,"conv1"),conv2:f(m,g,"conv2"),conv3:f(g,v,"conv3"),conv4:f(v,y,"conv4"),conv5:f(y,b,"conv5"),conv6:f(b,x,"conv6"),conv7:f(x,w,"conv7"),conv8:l(w,5*n,1,"conv8")};if(0!==s().length)throw new Error("weights remaing after extract: "+s().length);return{params:i,paramMappings:u}}(t,this.config,this.boxEncodingSize,n)},e.prototype.extractBoxes=function(t,e,n){return Object(s.b)(this,void 0,void 0,function(){var r,i,o,u,c,l,f,d,h,p,m,g,v,y,b,x,w,k,_,E,S,C,A,N,T,I,D,M,F,j=this;return Object(s.d)(this,function(P){switch(P.label){case 0:return r=e.width,i=e.height,o=Math.max(r,i),u=o/r,c=o/i,l=t.shape[1],f=this.config.anchors.length,d=a.tidy(function(){var e=t.reshape([l,l,f,j.boxEncodingSize]);return[e.slice([0,0,0,0],[l,l,f,4]),e.slice([0,0,0,4],[l,l,f,1]),j.withClassScores?a.softmax(e.slice([0,0,0,5],[l,l,f,j.config.classes.length]),3):a.scalar(0)]}),h=d[0],p=d[1],m=d[2],g=[],[4,p.array()];case 1:return v=P.sent(),[4,h.array()];case 2:y=P.sent(),b=0,P.label=3;case 3:if(!(b<l))return[3,12];x=0,P.label=4;case 4:if(!(x<l))return[3,11];w=0,P.label=5;case 5:return w<f?(k=R(v[b][x][w][0]),!n||k>n?(_=(x+R(y[b][x][w][0]))/l*u,E=(b+R(y[b][x][w][1]))/l*c,S=Math.exp(y[b][x][w][2])*this.config.anchors[w].x/l*u,C=Math.exp(y[b][x][w][3])*this.config.anchors[w].y/l*c,A=_-S/2,N=E-C/2,T={row:b,col:x,anchor:w},this.withClassScores?[4,this.extractPredictedClass(m,T)]:[3,7]):[3,9]):[3,10];case 6:return F=P.sent(),[3,8];case 7:F={classScore:1,label:0},P.label=8;case 8:D=(I=F).classScore,M=I.label,g.push(Object(s.a)({box:new O(A,N,A+S,N+C),score:k,classScore:k*D,label:M},T)),P.label=9;case 9:return w++,[3,5];case 10:return x++,[3,4];case 11:return b++,[3,3];case 12:return h.dispose(),p.dispose(),m.dispose(),[2,g]}})})},e.prototype.extractPredictedClass=function(t,e){return Object(s.b)(this,void 0,void 0,function(){var n,r,i,a;return Object(s.d)(this,function(o){switch(o.label){case 0:return n=e.row,r=e.col,i=e.anchor,[4,t.array()];case 1:return a=o.sent(),[2,Array(this.config.classes.length).fill(0).map(function(t,e){return a[n][r][i][e]}).map(function(t,e){return{classScore:t,label:e}}).reduce(function(t,e){return t.classScore>e.classScore?t:e})]}})})},e.DEFAULT_FILTER_SIZES=[3,16,32,64,128,256,512,1024,1024],e}(Nt),sn=function(t){function e(e){void 0===e&&(e=!0);var n=Object.assign({},{withSeparableConvs:e,iouThreshold:$e,classes:["face"]},e?{anchors:Xe,meanRgb:Ye}:{anchors:Ke,withClassScores:!0});return t.call(this,n)||this}return Object(s.c)(e,t),Object.defineProperty(e.prototype,"withSeparableConvs",{get:function(){return this.config.withSeparableConvs},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"anchors",{get:function(){return this.config.anchors},enumerable:!0,configurable:!0}),e.prototype.locateFaces=function(t,e){return Object(s.b)(this,void 0,void 0,function(){return Object(s.d)(this,function(n){switch(n.label){case 0:return[4,this.detect(t,e)];case 1:return[2,n.sent().map(function(t){return new C(t.score,t.relativeBox,{width:t.imageWidth,height:t.imageHeight})})]}})})},e.prototype.getDefaultModelName=function(){return this.withSeparableConvs?"tiny_yolov2_separable_conv_model":"tiny_yolov2_model"},e.prototype.extractParamsFromWeigthMap=function(e){return t.prototype.extractParamsFromWeigthMap.call(this,e)},e}(on);function un(t,e){void 0===e&&(e=!0);var n=new sn(e);return n.extractWeights(t),n}var cn=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._name="TinyFaceDetectorOptions",e}return Object(s.c)(e,t),e}(an),ln=function(){function t(){}return t.prototype.then=function(t){return Object(s.b)(this,void 0,void 0,function(){var e;return Object(s.d)(this,function(n){switch(n.label){case 0:return e=t,[4,this.run()];case 1:return[2,e.apply(void 0,[n.sent()])]}})})},t.prototype.run=function(){return Object(s.b)(this,void 0,void 0,function(){return Object(s.d)(this,function(t){throw new Error("ComposableTask - run is not implemented")})})},t}();function fn(t,e,n,r,i){return void 0===i&&(i=function(t){return t.alignedRect}),Object(s.b)(this,void 0,void 0,function(){var o,u,c,l,f;return Object(s.d)(this,function(s){switch(s.label){case 0:return o=t.map(function(t){return ee(t)?i(t):t.detection}),(c=r)?[3,5]:e instanceof a.Tensor?[4,wt(e,o)]:[3,2];case 1:return l=s.sent(),[3,4];case 2:return[4,xt(e,o)];case 3:l=s.sent(),s.label=4;case 4:c=l,s.label=5;case 5:return[4,n(u=c)];case 6:return f=s.sent(),u.forEach(function(t){return t instanceof a.Tensor&&t.dispose()}),[2,f]}})})}function dn(t,e,n,r,i){return Object(s.b)(this,void 0,void 0,function(){var a=this;return Object(s.d)(this,function(o){return[2,fn([t],e,function(t){return Object(s.b)(a,void 0,void 0,function(){return Object(s.d)(this,function(e){return[2,n(t[0])]})})},r,i)]})})}var hn=2,pn=12;function mn(t){var e=Ut(t),n=e.extractWeights,r=e.getRemainingWeights,i=[],o=function(t,e){var n=Ft(t,e),r=jt(t,e);function i(n,r){var i=a.tensor1d(t(n));return e.push({paramPath:r}),i}function o(t,e,r){return void 0===r&&(r=!1),{conv1:n(t[0],t[1],3,e+"/conv1"),prelu1_alpha:i(t[1],e+"/prelu1_alpha"),conv2:n(t[1],t[2],3,e+"/conv2"),prelu2_alpha:i(t[2],e+"/prelu2_alpha"),conv3:n(t[2],t[3],r?2:3,e+"/conv3"),prelu3_alpha:i(t[3],e+"/prelu3_alpha")}}return{extractPNetParams:function(){var t=o([3,10,16,32],"pnet"),e=n(32,2,1,"pnet/conv4_1"),r=n(32,4,1,"pnet/conv4_2");return Object(s.a)(Object(s.a)({},t),{conv4_1:e,conv4_2:r})},extractRNetParams:function(){var t=o([3,28,48,64],"rnet",!0),e=r(576,128,"rnet/fc1"),n=i(128,"rnet/prelu4_alpha"),a=r(128,2,"rnet/fc2_1"),u=r(128,4,"rnet/fc2_2");return Object(s.a)(Object(s.a)({},t),{fc1:e,prelu4_alpha:n,fc2_1:a,fc2_2:u})},extractONetParams:function(){var t=o([3,32,64,64],"onet"),e=n(64,128,2,"onet/conv4"),a=i(128,"onet/prelu4_alpha"),u=r(1152,256,"onet/fc1"),c=i(256,"onet/prelu5_alpha"),l=r(256,2,"onet/fc2_1"),f=r(256,4,"onet/fc2_2"),d=r(256,10,"onet/fc2_3");return Object(s.a)(Object(s.a)({},t),{conv4:e,prelu4_alpha:a,fc1:u,prelu5_alpha:c,fc2_1:l,fc2_2:f,fc2_3:d})}}}(n,i),u=o.extractPNetParams,c=o.extractRNetParams,l=o.extractONetParams,f=u(),d=c(),h=l();if(0!==r().length)throw new Error("weights remaing after extract: "+r().length);return{params:{pnet:f,rnet:d,onet:h},paramMappings:i}}function gn(t){var e=[],n=function(t,e){var n=Bt(t,e);function r(t){return{filters:n(t+"/weights",4,t+"/filters"),bias:n(t+"/bias",1)}}function i(t){return{weights:n(t+"/weights",2),bias:n(t+"/bias",1)}}function a(t){return n(t,1)}function o(t){return{conv1:r(t+"/conv1"),prelu1_alpha:a(t+"/prelu1_alpha"),conv2:r(t+"/conv2"),prelu2_alpha:a(t+"/prelu2_alpha"),conv3:r(t+"/conv3"),prelu3_alpha:a(t+"/prelu3_alpha")}}return{extractPNetParams:function(){var t=o("pnet"),e=r("pnet/conv4_1"),n=r("pnet/conv4_2");return Object(s.a)(Object(s.a)({},t),{conv4_1:e,conv4_2:n})},extractRNetParams:function(){var t=o("rnet"),e=i("rnet/fc1"),n=a("rnet/prelu4_alpha"),r=i("rnet/fc2_1"),u=i("rnet/fc2_2");return Object(s.a)(Object(s.a)({},t),{fc1:e,prelu4_alpha:n,fc2_1:r,fc2_2:u})},extractONetParams:function(){var t=o("onet"),e=r("onet/conv4"),n=a("onet/prelu4_alpha"),u=i("onet/fc1"),c=a("onet/prelu5_alpha"),l=i("onet/fc2_1"),f=i("onet/fc2_2"),d=i("onet/fc2_3");return Object(s.a)(Object(s.a)({},t),{conv4:e,prelu4_alpha:n,fc1:u,prelu5_alpha:c,fc2_1:l,fc2_2:f,fc2_3:d})}}}(t,e),r=n.extractPNetParams,i=n.extractRNetParams,a=n.extractONetParams,o=r(),u=i(),c=a();return Rt(t,e),{params:{pnet:o,rnet:u,onet:c},paramMappings:e}}function vn(t,e){var n=e[0],r=e[1];return{height:Math.floor(n*t),width:Math.floor(r*t)}}var yn=function(t){function e(e,n,r,i){return t.call(this,{left:e,top:n,right:r,bottom:i},!0)||this}return Object(s.c)(e,t),e}(E);function bn(t){return a.tidy(function(){return a.mul(a.sub(t,a.scalar(127.5)),a.scalar(.0078125))})}function xn(t,e){return a.tidy(function(){return a.add(a.relu(t),a.mul(e,a.neg(a.relu(a.neg(t)))))})}function wn(t,e,n){return void 0===n&&(n=!1),a.tidy(function(){var r=Mt(t,e.conv1,"valid");return r=xn(r,e.prelu1_alpha),r=xn(r=Mt(r=a.maxPool(r,n?[2,2]:[3,3],[2,2],"same"),e.conv2,"valid"),e.prelu2_alpha),r=xn(r=Mt(r=n?r:a.maxPool(r,[3,3],[2,2],"valid"),e.conv3,"valid"),e.prelu3_alpha)})}function kn(t,e,n,r,i){i.stage1=[];var o=e.map(function(e){return a.tidy(function(){var n={scale:e},i=function(t,e){return a.tidy(function(){var n=vn(e,t.shape.slice(1)),r=n.height,i=n.width,o=bn(a.image.resizeBilinear(t,[r,i]));return a.transpose(o,[0,2,1,3])})}(t,e),o=Date.now(),s=function(t,e){return a.tidy(function(){var n=wn(t,e,!0),r=Mt(n,e.conv4_1,"valid"),i=a.expandDims(a.max(r,3),3);return{prob:a.softmax(a.sub(r,i),3),regions:Mt(n,e.conv4_2,"valid")}})}(i,r),u=s.prob,c=s.regions;return n.pnet=Date.now()-o,{scoresTensor:a.unstack(a.unstack(u,3)[1])[0],regionsTensor:a.unstack(c)[0],scale:e,statsForScale:n}})}).map(function(t){var e=t.scoresTensor,r=t.regionsTensor,a=t.scale,o=t.statsForScale,s=function(t,e,n,r){for(var i=[],a=t.arraySync(),o=0;o<t.shape[0];o++)for(var s=0;s<t.shape[1];s++)a[o][s]>=r&&i.push(new _(s,o));return i.map(function(t){var r=new O(Math.round((t.y*hn+1)/n),Math.round((t.x*hn+1)/n),Math.round((t.y*hn+pn)/n),Math.round((t.x*hn+pn)/n)),i=a[t.y][t.x],o=e.arraySync();return{cell:r,score:i,region:new yn(o[t.y][t.x][0],o[t.y][t.x][1],o[t.y][t.x][2],o[t.y][t.x][3])}})}(e,r,a,n);if(e.dispose(),r.dispose(),!s.length)return i.stage1.push(o),[];var u=Date.now(),c=T(s.map(function(t){return t.cell}),s.map(function(t){return t.score}),.5);return o.nms=Date.now()-u,o.numBoxes=c.length,i.stage1.push(o),c.map(function(t){return s[t]})}).reduce(function(t,e){return t.concat(e)},[]),s=[],u=[];if(o.length>0){var c=Date.now(),l=T(o.map(function(t){return t.cell}),o.map(function(t){return t.score}),.7);i.stage1_nms=Date.now()-c,u=l.map(function(t){return o[t].score}),s=l.map(function(t){return o[t]}).map(function(t){var e=t.cell,n=t.region;return new O(e.left+n.left*e.width,e.top+n.top*e.height,e.right+n.right*e.width,e.bottom+n.bottom*e.height).toSquare().round()})}return{boxes:s,scores:u}}function _n(t,e,n){var r=n.width,i=n.height;return Object(s.b)(this,void 0,void 0,function(){var n,o,u,c=this;return Object(s.d)(this,function(l){switch(l.label){case 0:return n=rt(t),[4,Promise.all(e.map(function(e){return Object(s.b)(c,void 0,void 0,function(){var r,i,a,o,u,c,l,f;return Object(s.d)(this,function(s){return r=e.padAtBorders(t.height,t.width),i=r.y,a=r.ey,o=r.x,u=r.ex,c=o-1,l=i-1,f=n.getImageData(c,l,u-c,a-l),[2,et.isNodejs()?pt(f):createImageBitmap(f)]})})}))];case 1:return o=l.sent(),u=[],o.forEach(function(t){var e=rt(ht({width:r,height:i}));e.drawImage(t,0,0,r,i);for(var n=e.getImageData(0,0,r,i).data,a=[],o=0;o<n.length;o+=4)a.push(n[o+2]),a.push(n[o+1]),a.push(n[o]);u.push(a)}),[2,u.map(function(t){return a.tidy(function(){return bn(a.transpose(a.tensor4d(t,[1,r,i,3]),[0,2,1,3]).toFloat())})})]}})})}function En(t,e,n,r,i){return Object(s.b)(this,void 0,void 0,function(){var o,u,c,l,f,d,h,p,m,g,v,y,b,x;return Object(s.d)(this,function(s){switch(s.label){case 0:return o=Date.now(),[4,_n(t,e,{width:24,height:24})];case 1:return u=s.sent(),i.stage2_extractImagePatches=Date.now()-o,o=Date.now(),c=u.map(function(t){var e=function(t,e){return a.tidy(function(){var n=wn(t,e),r=xn(Gt(a.reshape(n,[n.shape[0],e.fc1.weights.shape[0]]),e.fc1),e.prelu4_alpha),i=Gt(r,e.fc2_1),o=a.expandDims(a.max(i,1),1),s=a.softmax(a.sub(i,o),1),u=Gt(r,e.fc2_2);return{scores:a.unstack(s,1)[1],regions:u}})}(t,r);return t.dispose(),e}),i.stage2_rnet=Date.now()-o,l=c.length>1?a.concat(c.map(function(t){return t.scores})):c[0].scores,h=(d=Array).from,[4,l.data()];case 2:return f=h.apply(d,[s.sent()]),l.dispose(),p=f.map(function(t,e){return{score:t,idx:e}}).filter(function(t){return t.score>n}).map(function(t){return t.idx}),m=p.map(function(t){return e[t]}),g=p.map(function(t){return f[t]}),v=[],y=[],m.length>0&&(o=Date.now(),b=T(m,g,.7),i.stage2_nms=Date.now()-o,x=b.map(function(t){var e=c[p[t]].regions.arraySync();return new yn(e[0][0],e[0][1],e[0][2],e[0][3])}),y=b.map(function(t){return g[t]}),v=b.map(function(t,e){return m[t].calibrate(x[e])})),c.forEach(function(t){t.regions.dispose(),t.scores.dispose()}),[2,{boxes:v,scores:y}]}})})}function On(t,e,n,r,i){return Object(s.b)(this,void 0,void 0,function(){var o,u,c,l,f,d,h,p,m,g,v,y,b,x,w;return Object(s.d)(this,function(s){switch(s.label){case 0:return o=Date.now(),[4,_n(t,e,{width:48,height:48})];case 1:return u=s.sent(),i.stage3_extractImagePatches=Date.now()-o,o=Date.now(),c=u.map(function(t){var e=function(t,e){return a.tidy(function(){var n=wn(t,e);n=xn(n=Mt(n=a.maxPool(n,[2,2],[2,2],"same"),e.conv4,"valid"),e.prelu4_alpha);var r=xn(Gt(a.reshape(n,[n.shape[0],e.fc1.weights.shape[0]]),e.fc1),e.prelu5_alpha),i=Gt(r,e.fc2_1),o=a.expandDims(a.max(i,1),1),s=a.softmax(a.sub(i,o),1),u=Gt(r,e.fc2_2),c=Gt(r,e.fc2_3);return{scores:a.unstack(s,1)[1],regions:u,points:c}})}(t,r);return t.dispose(),e}),i.stage3_onet=Date.now()-o,l=c.length>1?a.concat(c.map(function(t){return t.scores})):c[0].scores,h=(d=Array).from,[4,l.data()];case 2:return f=h.apply(d,[s.sent()]),l.dispose(),p=f.map(function(t,e){return{score:t,idx:e}}).filter(function(t){return t.score>n}).map(function(t){return t.idx}),m=p.map(function(t){var e=c[t].regions.arraySync();return new yn(e[0][0],e[0][1],e[0][2],e[0][3])}),g=p.map(function(t,n){return e[t].calibrate(m[n])}),v=p.map(function(t){return f[t]}),y=[],b=[],x=[],g.length>0&&(o=Date.now(),w=T(g,v,.7,!1),i.stage3_nms=Date.now()-o,y=w.map(function(t){return g[t]}),b=w.map(function(t){return v[t]}),x=w.map(function(t,e){return Array(5).fill(0).map(function(n,r){var i=c[t].points.arraySync();return new _(i[0][r]*(y[e].width+1)+y[e].left,i[0][r+5]*(y[e].height+1)+y[e].top)})})),c.forEach(function(t){t.regions.dispose(),t.scores.dispose(),t.points.dispose()}),[2,{boxes:y,scores:b,points:x}]}})})}var Sn=function(t){function e(){return t.call(this,"Mtcnn")||this}return Object(s.c)(e,t),e.prototype.load=function(e){return Object(s.b)(this,void 0,void 0,function(){return Object(s.d)(this,function(n){return console.warn("mtcnn is deprecated and will be removed soon"),[2,t.prototype.load.call(this,e)]})})},e.prototype.loadFromDisk=function(e){return Object(s.b)(this,void 0,void 0,function(){return Object(s.d)(this,function(n){return console.warn("mtcnn is deprecated and will be removed soon"),[2,t.prototype.loadFromDisk.call(this,e)]})})},e.prototype.forwardInput=function(t,e){return void 0===e&&(e={}),Object(s.b)(this,void 0,void 0,function(){var n,r,i,o,u,c,l,f,d,h,p,m,g,v,y,b,x,w,k,E,O;return Object(s.d)(this,function(s){switch(s.label){case 0:if(!(n=this.params))throw new Error("Mtcnn - load model before inference");if(!(r=t.canvases[0]))throw new Error("Mtcnn - inputCanvas is not defined, note that passing tensors into Mtcnn.forwardInput is not supported yet.");return i={},o=Date.now(),u=a.tidy(function(){return function(t){return a.tidy(function(){return a.stack(a.unstack(t,3).reverse(),3)})}(a.expandDims(a.browser.fromPixels(r)).toFloat())}),c=function(t){return u.dispose(),i.total=Date.now()-o,t},l=u.shape.slice(1),f=l[0],d=l[1],h=new De(e),p=h.minFaceSize,m=h.scaleFactor,g=h.maxNumScales,v=h.scoreThresholds,y=h.scaleSteps,b=(y||function(t,e,n){for(var r=n[0],i=n[1],a=pn/t,o=[],s=Math.min(r,i)*a,u=0;s>=12;)o.push(a*Math.pow(e,u)),s*=e,u+=1;return o}(p,m,[f,d])).filter(function(t){var e=vn(t,[f,d]);return Math.min(e.width,e.height)>pn}).slice(0,g),i.scales=b,i.pyramid=b.map(function(t){return vn(t,[f,d])}),x=Date.now(),[4,kn(u,b,v[0],n.pnet,i)];case 1:return w=s.sent(),i.total_stage1=Date.now()-x,w.boxes.length?(i.stage2_numInputBoxes=w.boxes.length,x=Date.now(),[4,En(r,w.boxes,v[1],n.rnet,i)]):[2,c({results:[],stats:i})];case 2:return k=s.sent(),i.total_stage2=Date.now()-x,k.boxes.length?(i.stage3_numInputBoxes=k.boxes.length,x=Date.now(),[4,On(r,k.boxes,v[2],n.onet,i)]):[2,c({results:[],stats:i})];case 3:return E=s.sent(),i.total_stage3=Date.now()-x,O=E.boxes.map(function(t,e){return ne(H({},new C(E.scores[e],new j(t.left/d,t.top/f,t.width/d,t.height/f),{height:f,width:d})),new L(E.points[e].map(function(e){return e.sub(new _(t.left,t.top)).div(new _(t.width,t.height))}),{width:t.width,height:t.height}))}),[2,c({results:O,stats:i})]}})})},e.prototype.forward=function(t,e){return void 0===e&&(e={}),Object(s.b)(this,void 0,void 0,function(){var n;return Object(s.d)(this,function(r){switch(r.label){case 0:return n=this.forwardInput,[4,bt(t)];case 1:return[4,n.apply(this,[r.sent(),e])];case 2:return[2,r.sent().results]}})})},e.prototype.forwardWithStats=function(t,e){return void 0===e&&(e={}),Object(s.b)(this,void 0,void 0,function(){var n;return Object(s.d)(this,function(r){switch(r.label){case 0:return n=this.forwardInput,[4,bt(t)];case 1:return[2,n.apply(this,[r.sent(),e])]}})})},e.prototype.getDefaultModelName=function(){return"mtcnn_model"},e.prototype.extractParamsFromWeigthMap=function(t){return gn(t)},e.prototype.extractParams=function(t){return mn(t)},e}(Nt),Cn=.4,An=[new _(1.603231,2.094468),new _(6.041143,7.080126),new _(2.882459,3.518061),new _(4.266906,5.178857),new _(9.041765,10.66308)],Nn=[117.001,114.697,97.404],Tn=function(t){function e(){var e={withSeparableConvs:!0,iouThreshold:Cn,classes:["face"],anchors:An,meanRgb:Nn,isFirstLayerConv2d:!0,filterSizes:[3,16,32,64,128,256,512]};return t.call(this,e)||this}return Object(s.c)(e,t),Object.defineProperty(e.prototype,"anchors",{get:function(){return this.config.anchors},enumerable:!0,configurable:!0}),e.prototype.locateFaces=function(t,e){return Object(s.b)(this,void 0,void 0,function(){return Object(s.d)(this,function(n){switch(n.label){case 0:return[4,this.detect(t,e)];case 1:return[2,n.sent().map(function(t){return new C(t.score,t.relativeBox,{width:t.imageWidth,height:t.imageHeight})})]}})})},e.prototype.getDefaultModelName=function(){return"tiny_face_detector_model"},e.prototype.extractParamsFromWeigthMap=function(e){return t.prototype.extractParamsFromWeigthMap.call(this,e)},e}(on),In={ssdMobilenetv1:new We,tinyFaceDetector:new Tn,tinyYolov2:new sn,mtcnn:new Sn,faceLandmark68Net:new pe,faceLandmark68TinyNet:new ge,faceRecognitionNet:new Oe,faceExpressionNet:new Jt,ageGenderNet:new de},Dn=function(t,e){return In.ssdMobilenetv1.locateFaces(t,e)},Mn=function(t,e){return In.tinyFaceDetector.locateFaces(t,e)},Rn=function(t,e){return In.tinyYolov2.locateFaces(t,e)},Fn=function(t,e){return In.mtcnn.forward(t,e)},jn=function(t){return In.faceLandmark68Net.detectLandmarks(t)},Pn=function(t){return In.faceLandmark68TinyNet.detectLandmarks(t)},Ln=function(t){return In.faceRecognitionNet.computeFaceDescriptor(t)},zn=function(t){return In.faceExpressionNet.predictExpressions(t)},Bn=function(t){return In.ageGenderNet.predictAgeAndGender(t)},Un=function(t){return In.ssdMobilenetv1.load(t)},Wn=function(t){return In.tinyFaceDetector.load(t)},Vn=function(t){return In.mtcnn.load(t)},qn=function(t){return In.tinyYolov2.load(t)},Hn=function(t){return In.faceLandmark68Net.load(t)},Gn=function(t){return In.faceLandmark68TinyNet.load(t)},$n=function(t){return In.faceRecognitionNet.load(t)},Kn=function(t){return In.faceExpressionNet.load(t)},Xn=function(t){return In.ageGenderNet.load(t)},Yn=Un,Jn=Dn,Zn=jn,Qn=function(t){function e(e,n,r){var i=t.call(this)||this;return i.parentTask=e,i.input=n,i.extractedFaces=r,i}return Object(s.c)(e,t),e}(ln),tr=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Object(s.c)(e,t),e.prototype.run=function(){return Object(s.b)(this,void 0,void 0,function(){var t,e,n=this;return Object(s.d)(this,function(r){switch(r.label){case 0:return[4,this.parentTask];case 1:return[4,fn(t=r.sent(),this.input,function(t){return Object(s.b)(n,void 0,void 0,function(){return Object(s.d)(this,function(e){switch(e.label){case 0:return[4,Promise.all(t.map(function(t){return In.faceExpressionNet.predictExpressions(t)}))];case 1:return[2,e.sent()]}})})},this.extractedFaces)];case 2:return e=r.sent(),[2,t.map(function(t,n){return Qt(t,e[n])})]}})})},e.prototype.withAgeAndGender=function(){return new ar(this,this.input)},e}(Qn),er=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Object(s.c)(e,t),e.prototype.run=function(){return Object(s.b)(this,void 0,void 0,function(){var t,e;return Object(s.d)(this,function(n){switch(n.label){case 0:return[4,this.parentTask];case 1:return(t=n.sent())?[4,dn(t,this.input,function(t){return In.faceExpressionNet.predictExpressions(t)},this.extractedFaces)]:[2];case 2:return e=n.sent(),[2,Qt(t,e)]}})})},e.prototype.withAgeAndGender=function(){return new or(this,this.input)},e}(Qn),nr=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Object(s.c)(e,t),e.prototype.withAgeAndGender=function(){return new sr(this,this.input)},e.prototype.withFaceDescriptors=function(){return new lr(this,this.input)},e}(tr),rr=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Object(s.c)(e,t),e.prototype.withAgeAndGender=function(){return new ur(this,this.input)},e.prototype.withFaceDescriptor=function(){return new fr(this,this.input)},e}(er),ir=function(t){function e(e,n,r){var i=t.call(this)||this;return i.parentTask=e,i.input=n,i.extractedFaces=r,i}return Object(s.c)(e,t),e}(ln),ar=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Object(s.c)(e,t),e.prototype.run=function(){return Object(s.b)(this,void 0,void 0,function(){var t,e,n=this;return Object(s.d)(this,function(r){switch(r.label){case 0:return[4,this.parentTask];case 1:return[4,fn(t=r.sent(),this.input,function(t){return Object(s.b)(n,void 0,void 0,function(){return Object(s.d)(this,function(e){switch(e.label){case 0:return[4,Promise.all(t.map(function(t){return In.ageGenderNet.predictAgeAndGender(t)}))];case 1:return[2,e.sent()]}})})},this.extractedFaces)];case 2:return e=r.sent(),[2,t.map(function(t,n){var r=e[n],i=r.age;return Ne(Ie(t,r.gender,r.genderProbability),i)})]}})})},e.prototype.withFaceExpressions=function(){return new tr(this,this.input)},e}(ir),or=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Object(s.c)(e,t),e.prototype.run=function(){return Object(s.b)(this,void 0,void 0,function(){var t,e,n,r,i;return Object(s.d)(this,function(a){switch(a.label){case 0:return[4,this.parentTask];case 1:return(t=a.sent())?[4,dn(t,this.input,function(t){return In.ageGenderNet.predictAgeAndGender(t)},this.extractedFaces)]:[2];case 2:return e=a.sent(),n=e.age,r=e.gender,i=e.genderProbability,[2,Ne(Ie(t,r,i),n)]}})})},e.prototype.withFaceExpressions=function(){return new er(this,this.input)},e}(ir),sr=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Object(s.c)(e,t),e.prototype.withFaceExpressions=function(){return new nr(this,this.input)},e.prototype.withFaceDescriptors=function(){return new lr(this,this.input)},e}(ar),ur=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Object(s.c)(e,t),e.prototype.withFaceExpressions=function(){return new rr(this,this.input)},e.prototype.withFaceDescriptor=function(){return new fr(this,this.input)},e}(or),cr=function(t){function e(e,n){var r=t.call(this)||this;return r.parentTask=e,r.input=n,r}return Object(s.c)(e,t),e}(ln),lr=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Object(s.c)(e,t),e.prototype.run=function(){return Object(s.b)(this,void 0,void 0,function(){var t;return Object(s.d)(this,function(e){switch(e.label){case 0:return[4,this.parentTask];case 1:return[4,fn(t=e.sent(),this.input,function(t){return Promise.all(t.map(function(t){return In.faceRecognitionNet.computeFaceDescriptor(t)}))},null,function(t){return t.landmarks.align(null,{useDlibAlignment:!0})})];case 2:return[2,e.sent().map(function(e,n){return Ce(t[n],e)})]}})})},e.prototype.withFaceExpressions=function(){return new nr(this,this.input)},e.prototype.withAgeAndGender=function(){return new sr(this,this.input)},e}(cr),fr=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Object(s.c)(e,t),e.prototype.run=function(){return Object(s.b)(this,void 0,void 0,function(){var t,e;return Object(s.d)(this,function(n){switch(n.label){case 0:return[4,this.parentTask];case 1:return(t=n.sent())?[4,dn(t,this.input,function(t){return In.faceRecognitionNet.computeFaceDescriptor(t)},null,function(t){return t.landmarks.align(null,{useDlibAlignment:!0})})]:[2];case 2:return e=n.sent(),[2,Ce(t,e)]}})})},e.prototype.withFaceExpressions=function(){return new rr(this,this.input)},e.prototype.withAgeAndGender=function(){return new ur(this,this.input)},e}(cr),dr=function(t){function e(e,n,r){var i=t.call(this)||this;return i.parentTask=e,i.input=n,i.useTinyLandmarkNet=r,i}return Object(s.c)(e,t),Object.defineProperty(e.prototype,"landmarkNet",{get:function(){return this.useTinyLandmarkNet?In.faceLandmark68TinyNet:In.faceLandmark68Net},enumerable:!0,configurable:!0}),e}(ln),hr=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Object(s.c)(e,t),e.prototype.run=function(){return Object(s.b)(this,void 0,void 0,function(){var t,e,n,r,i,o=this;return Object(s.d)(this,function(s){switch(s.label){case 0:return[4,this.parentTask];case 1:return t=s.sent(),e=t.map(function(t){return t.detection}),this.input instanceof a.Tensor?[4,wt(this.input,e)]:[3,3];case 2:return r=s.sent(),[3,5];case 3:return[4,xt(this.input,e)];case 4:r=s.sent(),s.label=5;case 5:return n=r,[4,Promise.all(n.map(function(t){return o.landmarkNet.detectLandmarks(t)}))];case 6:return i=s.sent(),n.forEach(function(t){return t instanceof a.Tensor&&t.dispose()}),[2,t.map(function(t,e){return ne(t,i[e])})]}})})},e.prototype.withFaceExpressions=function(){return new nr(this,this.input)},e.prototype.withAgeAndGender=function(){return new sr(this,this.input)},e.prototype.withFaceDescriptors=function(){return new lr(this,this.input)},e}(dr),pr=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Object(s.c)(e,t),e.prototype.run=function(){return Object(s.b)(this,void 0,void 0,function(){var t,e,n,r,i;return Object(s.d)(this,function(o){switch(o.label){case 0:return[4,this.parentTask];case 1:return(t=o.sent())?(e=t.detection,this.input instanceof a.Tensor?[4,wt(this.input,[e])]:[3,3]):[2];case 2:return r=o.sent(),[3,5];case 3:return[4,xt(this.input,[e])];case 4:r=o.sent(),o.label=5;case 5:return n=r,[4,this.landmarkNet.detectLandmarks(n[0])];case 6:return i=o.sent(),n.forEach(function(t){return t instanceof a.Tensor&&t.dispose()}),[2,ne(t,i)]}})})},e.prototype.withFaceExpressions=function(){return new rr(this,this.input)},e.prototype.withAgeAndGender=function(){return new ur(this,this.input)},e.prototype.withFaceDescriptor=function(){return new fr(this,this.input)},e}(dr),mr=function(t){function e(e,n){void 0===n&&(n=new Ue);var r=t.call(this)||this;return r.input=e,r.options=n,r}return Object(s.c)(e,t),e}(ln),gr=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Object(s.c)(e,t),e.prototype.run=function(){return Object(s.b)(this,void 0,void 0,function(){var t,e,n,r;return Object(s.d)(this,function(i){switch(i.label){case 0:return e=(t=this).input,(n=t.options)instanceof De?[4,In.mtcnn.forward(e,n)]:[3,2];case 1:return[2,i.sent().map(function(t){return t.detection})];case 2:if(!(r=n instanceof cn?function(t){return In.tinyFaceDetector.locateFaces(t,n)}:n instanceof Ue?function(t){return In.ssdMobilenetv1.locateFaces(t,n)}:n instanceof an?function(t){return In.tinyYolov2.locateFaces(t,n)}:null))throw new Error("detectFaces - expected options to be instance of TinyFaceDetectorOptions | SsdMobilenetv1Options | MtcnnOptions | TinyYolov2Options");return[2,r(e)]}})})},e.prototype.runAndExtendWithFaceDetections=function(){var t=this;return new Promise(function(e){return Object(s.b)(t,void 0,void 0,function(){var t;return Object(s.d)(this,function(n){switch(n.label){case 0:return[4,this.run()];case 1:return t=n.sent(),[2,e(t.map(function(t){return H({},t)}))]}})})})},e.prototype.withFaceLandmarks=function(t){return void 0===t&&(t=!1),new hr(this.runAndExtendWithFaceDetections(),this.input,t)},e.prototype.withFaceExpressions=function(){return new tr(this.runAndExtendWithFaceDetections(),this.input)},e.prototype.withAgeAndGender=function(){return new ar(this.runAndExtendWithFaceDetections(),this.input)},e}(mr),vr=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return Object(s.c)(e,t),e.prototype.run=function(){return Object(s.b)(this,void 0,void 0,function(){var t,e;return Object(s.d)(this,function(n){switch(n.label){case 0:return[4,new gr(this.input,this.options)];case 1:return t=n.sent(),e=t[0],t.forEach(function(t){t.score>e.score&&(e=t)}),[2,e]}})})},e.prototype.runAndExtendWithFaceDetection=function(){var t=this;return new Promise(function(e){return Object(s.b)(t,void 0,void 0,function(){var t;return Object(s.d)(this,function(n){switch(n.label){case 0:return[4,this.run()];case 1:return t=n.sent(),[2,e(t?H({},t):void 0)]}})})})},e.prototype.withFaceLandmarks=function(t){return void 0===t&&(t=!1),new pr(this.runAndExtendWithFaceDetection(),this.input,t)},e.prototype.withFaceExpressions=function(){return new er(this.runAndExtendWithFaceDetection(),this.input)},e.prototype.withAgeAndGender=function(){return new or(this.runAndExtendWithFaceDetection(),this.input)},e}(mr);function yr(t,e){return void 0===e&&(e=new Ue),new vr(t,e)}function br(t,e){return void 0===e&&(e=new Ue),new gr(t,e)}function xr(t,e){return Object(s.b)(this,void 0,void 0,function(){return Object(s.d)(this,function(n){switch(n.label){case 0:return console.warn("allFacesSsdMobilenetv1 is deprecated and will be removed soon, use the high level api instead"),[4,br(t,new Ue(e?{minConfidence:e}:{})).withFaceLandmarks().withFaceDescriptors()];case 1:return[2,n.sent()]}})})}function wr(t,e){return void 0===e&&(e={}),Object(s.b)(this,void 0,void 0,function(){return Object(s.d)(this,function(n){switch(n.label){case 0:return console.warn("allFacesTinyYolov2 is deprecated and will be removed soon, use the high level api instead"),[4,br(t,new an(e)).withFaceLandmarks().withFaceDescriptors()];case 1:return[2,n.sent()]}})})}function kr(t,e){return void 0===e&&(e={}),Object(s.b)(this,void 0,void 0,function(){return Object(s.d)(this,function(n){switch(n.label){case 0:return console.warn("allFacesMtcnn is deprecated and will be removed soon, use the high level api instead"),[4,br(t,new De(e)).withFaceLandmarks().withFaceDescriptors()];case 1:return[2,n.sent()]}})})}var _r=xr;function Er(t,e){if(t.length!==e.length)throw new Error("euclideanDistance: arr1.length !== arr2.length");var n=Array.from(t),r=Array.from(e);return Math.sqrt(n.map(function(t,e){return t-r[e]}).reduce(function(t,e){return t+Math.pow(e,2)},0))}var Or=function(){function t(t,e){void 0===e&&(e=.6),this._distanceThreshold=e;var n=Array.isArray(t)?t:[t];if(!n.length)throw new Error("FaceRecognizer.constructor - expected atleast one input");var r=1,i=function(){return"person "+r++};this._labeledDescriptors=n.map(function(t){if(t instanceof W)return t;if(t instanceof Float32Array)return new W(i(),[t]);if(t.descriptor&&t.descriptor instanceof Float32Array)return new W(i(),[t.descriptor]);throw new Error("FaceRecognizer.constructor - expected inputs to be of type LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array | Array<LabeledFaceDescriptors | WithFaceDescriptor<any> | Float32Array>")})}return Object.defineProperty(t.prototype,"labeledDescriptors",{get:function(){return this._labeledDescriptors},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"distanceThreshold",{get:function(){return this._distanceThreshold},enumerable:!0,configurable:!0}),t.prototype.computeMeanDistance=function(t,e){return e.map(function(e){return Er(e,t)}).reduce(function(t,e){return t+e},0)/(e.length||1)},t.prototype.matchDescriptor=function(t){var e=this;return this.labeledDescriptors.map(function(n){var r=n.descriptors,i=n.label;return new B(i,e.computeMeanDistance(t,r))}).reduce(function(t,e){return t.distance<e.distance?t:e})},t.prototype.findBestMatch=function(t){var e=this.matchDescriptor(t);return e.distance<this.distanceThreshold?e:new B("unknown",e.distance)},t.prototype.toJSON=function(){return{distanceThreshold:this.distanceThreshold,labeledDescriptors:this.labeledDescriptors.map(function(t){return t.toJSON()})}},t.fromJSON=function(e){return new t(e.labeledDescriptors.map(function(t){return W.fromJSON(t)}),e.distanceThreshold)},t}();function Sr(t){var e=new Sn;return e.extractWeights(t),e}function Cr(t){var e=new Tn;return e.extractWeights(t),e}function Ar(t,e){var n=new u(e.width,e.height),r=n.width,i=n.height;if(r<=0||i<=0)throw new Error("resizeResults - invalid dimensions: "+JSON.stringify({width:r,height:i}));if(Array.isArray(t))return t.map(function(t){return Ar(t,{width:r,height:i})});if(ee(t)){var a=t.detection.forSize(r,i),o=t.unshiftedLandmarks.forSize(a.box.width,a.box.height);return ne(H(t,a),o)}return q(t)?H(t,t.detection.forSize(r,i)):t instanceof P||t instanceof C?t.forSize(r,i):t}n.d(e,"draw",function(){return i}),n.d(e,"utils",function(){return r}),n.d(e,"tf",function(){return a}),n.d(e,"AgeGenderNet",function(){return de}),n.d(e,"Gender",function(){return le}),n.d(e,"FaceDetection",function(){return C}),n.d(e,"FaceLandmarks",function(){return P}),n.d(e,"BoundingBox",function(){return O}),n.d(e,"Box",function(){return E}),n.d(e,"Dimensions",function(){return u}),n.d(e,"FaceLandmarks5",function(){return L}),n.d(e,"FaceLandmarks68",function(){return z}),n.d(e,"FaceMatch",function(){return B}),n.d(e,"LabeledBox",function(){return U}),n.d(e,"LabeledFaceDescriptors",function(){return W}),n.d(e,"ObjectDetection",function(){return S}),n.d(e,"Point",function(){return _}),n.d(e,"PredictedBox",function(){return V}),n.d(e,"Rect",function(){return j}),n.d(e,"awaitMediaLoaded",function(){return lt}),n.d(e,"bufferToImage",function(){return ft}),n.d(e,"createCanvas",function(){return ht}),n.d(e,"createCanvasFromMedia",function(){return pt}),n.d(e,"extractFaces",function(){return xt}),n.d(e,"extractFaceTensors",function(){return wt}),n.d(e,"fetchImage",function(){return _t}),n.d(e,"fetchJson",function(){return Et}),n.d(e,"fetchNetWeights",function(){return Ot}),n.d(e,"fetchOrThrow",function(){return kt}),n.d(e,"getContext2dOrThrow",function(){return rt}),n.d(e,"getMediaDimensions",function(){return dt}),n.d(e,"imageTensorToCanvas",function(){return mt}),n.d(e,"imageToSquare",function(){return vt}),n.d(e,"isMediaElement",function(){return gt}),n.d(e,"isMediaLoaded",function(){return ct}),n.d(e,"loadWeightMap",function(){return Ct}),n.d(e,"matchDimensions",function(){return At}),n.d(e,"NetInput",function(){return yt}),n.d(e,"resolveInput",function(){return nt}),n.d(e,"toNetInput",function(){return bt}),n.d(e,"env",function(){return et}),n.d(e,"FaceExpressionNet",function(){return Jt}),n.d(e,"FACE_EXPRESSION_LABELS",function(){return Xt}),n.d(e,"FaceExpressions",function(){return Yt}),n.d(e,"FaceLandmarkNet",function(){return ve}),n.d(e,"FaceLandmark68Net",function(){return pe}),n.d(e,"FaceLandmark68TinyNet",function(){return ge}),n.d(e,"createFaceRecognitionNet",function(){return Se}),n.d(e,"FaceRecognitionNet",function(){return Oe}),n.d(e,"isWithFaceDetection",function(){return q}),n.d(e,"extendWithFaceDetection",function(){return H}),n.d(e,"isWithFaceLandmarks",function(){return ee}),n.d(e,"extendWithFaceLandmarks",function(){return ne}),n.d(e,"extendWithFaceDescriptor",function(){return Ce}),n.d(e,"isWithFaceExpressions",function(){return Zt}),n.d(e,"extendWithFaceExpressions",function(){return Qt}),n.d(e,"isWithAge",function(){return Ae}),n.d(e,"extendWithAge",function(){return Ne}),n.d(e,"isWithGender",function(){return Te}),n.d(e,"extendWithGender",function(){return Ie}),n.d(e,"allFacesSsdMobilenetv1",function(){return xr}),n.d(e,"allFacesTinyYolov2",function(){return wr}),n.d(e,"allFacesMtcnn",function(){return kr}),n.d(e,"allFaces",function(){return _r}),n.d(e,"ComposableTask",function(){return ln}),n.d(e,"ComputeFaceDescriptorsTaskBase",function(){return cr}),n.d(e,"ComputeAllFaceDescriptorsTask",function(){return lr}),n.d(e,"ComputeSingleFaceDescriptorTask",function(){return fr}),n.d(e,"detectSingleFace",function(){return yr}),n.d(e,"detectAllFaces",function(){return br}),n.d(e,"DetectFacesTaskBase",function(){return mr}),n.d(e,"DetectAllFacesTask",function(){return gr}),n.d(e,"DetectSingleFaceTask",function(){return vr}),n.d(e,"DetectFaceLandmarksTaskBase",function(){return dr}),n.d(e,"DetectAllFaceLandmarksTask",function(){return hr}),n.d(e,"DetectSingleFaceLandmarksTask",function(){return pr}),n.d(e,"FaceMatcher",function(){return Or}),n.d(e,"nets",function(){return In}),n.d(e,"ssdMobilenetv1",function(){return Dn}),n.d(e,"tinyFaceDetector",function(){return Mn}),n.d(e,"tinyYolov2",function(){return Rn}),n.d(e,"mtcnn",function(){return Fn}),n.d(e,"detectFaceLandmarks",function(){return jn}),n.d(e,"detectFaceLandmarksTiny",function(){return Pn}),n.d(e,"computeFaceDescriptor",function(){return Ln}),n.d(e,"recognizeFaceExpressions",function(){return zn}),n.d(e,"predictAgeAndGender",function(){return Bn}),n.d(e,"loadSsdMobilenetv1Model",function(){return Un}),n.d(e,"loadTinyFaceDetectorModel",function(){return Wn}),n.d(e,"loadMtcnnModel",function(){return Vn}),n.d(e,"loadTinyYolov2Model",function(){return qn}),n.d(e,"loadFaceLandmarkModel",function(){return Hn}),n.d(e,"loadFaceLandmarkTinyModel",function(){return Gn}),n.d(e,"loadFaceRecognitionModel",function(){return $n}),n.d(e,"loadFaceExpressionModel",function(){return Kn}),n.d(e,"loadAgeGenderModel",function(){return Xn}),n.d(e,"loadFaceDetectionModel",function(){return Yn}),n.d(e,"locateFaces",function(){return Jn}),n.d(e,"detectLandmarks",function(){return Zn}),n.d(e,"createMtcnn",function(){return Sr}),n.d(e,"Mtcnn",function(){return Sn}),n.d(e,"MtcnnOptions",function(){return De}),n.d(e,"sigmoid",function(){return R}),n.d(e,"inverseSigmoid",function(){return F}),n.d(e,"iou",function(){return A}),n.d(e,"minBbox",function(){return N}),n.d(e,"nonMaxSuppression",function(){return T}),n.d(e,"normalize",function(){return I}),n.d(e,"padToSquare",function(){return D}),n.d(e,"shuffleArray",function(){return M}),n.d(e,"createSsdMobilenetv1",function(){return Ve}),n.d(e,"createFaceDetectionNet",function(){return qe}),n.d(e,"FaceDetectionNet",function(){return Ge}),n.d(e,"SsdMobilenetv1",function(){return We}),n.d(e,"SsdMobilenetv1Options",function(){return Ue}),n.d(e,"createTinyFaceDetector",function(){return Cr}),n.d(e,"TinyFaceDetector",function(){return Tn}),n.d(e,"TinyFaceDetectorOptions",function(){return cn}),n.d(e,"TinyYolov2",function(){return sn}),n.d(e,"createTinyYolov2",function(){return un}),n.d(e,"TinyYolov2SizeType",function(){return He}),n.d(e,"TinyYolov2Options",function(){return an}),n.d(e,"validateConfig",function(){return Ze}),n.d(e,"euclideanDistance",function(){return Er}),n.d(e,"NeuralNetwork",function(){return Nt}),n.d(e,"resizeResults",function(){return Ar})},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.getImageData=e.getRobin=void 0;var r=o(n(9)),i=o(n(24)),a=o(n(8));function o(t){return t&&t.__esModule?t:{default:t}}e.getRobin=function(){var t=(0,a.default)(r.default.mark(function t(){var e;return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return(e=new Image).crossOrigin="",e.src="https://cdn.jsdelivr.net/gh/ml5js/ml5-library@main/assets/bird.jpg",t.next=5,new i.default(function(t){e.onload=t});case 5:return t.abrupt("return",e);case 6:case"end":return t.stop()}},t,void 0)}));return function(){return t.apply(this,arguments)}}(),e.getImageData=function(){var t=(0,a.default)(r.default.mark(function t(){var e,n,i;return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:for(e=new Uint8ClampedArray(2e4),n=0;n<e.length;n+=4)e[n+0]=0,e[n+1]=190,e[n+2]=0,e[n+3]=255;return i=new ImageData(e,200),t.abrupt("return",i);case 4:case"end":return t.stop()}},t,void 0)}));return function(){return t.apply(this,arguments)}}()},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(201);e.default=function(){console.log("\n🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈\n🌟 Thank you for using ml5.js v"+r.version+" 🌟\n\nPlease read our community statement to ensure \nthat the use of this software reflects the values \nof the ml5.js community:\n↳ https://ml5js.org/about\n\nReporting: \n↳ https://github.com/ml5js/ml5-library/issues\n↳ Email: info@ml5js.org \n🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈🌈")}},function(t,e,n){"use strict";n.r(e),n.d(e,"load",function(){return T}),n.d(e,"HandPose",function(){return I});var r=n(0),i=n(20);
  254. /**
  255. * @license
  256. * Copyright 2020 Google LLC. All Rights Reserved.
  257. * Licensed under the Apache License, Version 2.0 (the "License");
  258. * you may not use this file except in compliance with the License.
  259. * You may obtain a copy of the License at
  260. *
  261. * http://www.apache.org/licenses/LICENSE-2.0
  262. *
  263. * Unless required by applicable law or agreed to in writing, software
  264. * distributed under the License is distributed on an "AS IS" BASIS,
  265. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  266. * See the License for the specific language governing permissions and
  267. * limitations under the License.
  268. * =============================================================================
  269. */
  270. function a(t){return[Math.abs(t.endPoint[0]-t.startPoint[0]),Math.abs(t.endPoint[1]-t.startPoint[1])]}function o(t){return[t.startPoint[0]+(t.endPoint[0]-t.startPoint[0])/2,t.startPoint[1]+(t.endPoint[1]-t.startPoint[1])/2]}function s(t,e=1.5){const n=o(t),r=a(t),i=[e*r[0]/2,e*r[1]/2];return{startPoint:[n[0]-i[0],n[1]-i[1]],endPoint:[n[0]+i[0],n[1]+i[1]],palmLandmarks:t.palmLandmarks}}function u(t){const e=o(t),n=a(t),r=Math.max(...n)/2;return{startPoint:[e[0]-r,e[1]-r],endPoint:[e[0]+r,e[1]+r],palmLandmarks:t.palmLandmarks}}function c(t,e){const n=[t.endPoint[0]-t.startPoint[0],t.endPoint[1]-t.startPoint[1]],r=[n[0]*e[0],n[1]*e[1]];return{startPoint:[t.startPoint[0]+r[0],t.startPoint[1]+r[1]],endPoint:[t.endPoint[0]+r[0],t.endPoint[1]+r[1]],palmLandmarks:t.palmLandmarks}}class l{constructor(t,e,n,i,a,o){this.model=t,this.width=e,this.height=n,this.iouThreshold=a,this.scoreThreshold=o,this.anchors=i.map(t=>[t.x_center,t.y_center]),this.anchorsTensor=Object(r.tensor2d)(this.anchors),this.inputSizeTensor=Object(r.tensor1d)([e,n]),this.doubleInputSizeTensor=Object(r.tensor1d)([2*e,2*n])}normalizeBoxes(t){return Object(r.tidy)(()=>{const e=Object(r.slice)(t,[0,0],[-1,2]),n=Object(r.slice)(t,[0,2],[-1,2]),i=Object(r.add)(Object(r.div)(e,this.inputSizeTensor),this.anchorsTensor),a=Object(r.div)(n,this.doubleInputSizeTensor),o=Object(r.mul)(Object(r.sub)(i,a),this.inputSizeTensor),s=Object(r.mul)(Object(r.add)(i,a),this.inputSizeTensor);return Object(r.concat2d)([o,s],1)})}normalizeLandmarks(t,e){return Object(r.tidy)(()=>{const n=Object(r.add)(Object(r.div)(t.reshape([-1,7,2]),this.inputSizeTensor),this.anchors[e]);return Object(r.mul)(n,this.inputSizeTensor)})}getBoundingBoxes(t){return Object(r.tidy)(()=>{const e=Object(r.mul)(Object(r.sub)(t,.5),2),n=Object(r.env)().get("WEBGL_PACK_DEPTHWISECONV");Object(r.env)().set("WEBGL_PACK_DEPTHWISECONV",!0);const i=this.model.predict(e).squeeze();Object(r.env)().set("WEBGL_PACK_DEPTHWISECONV",n);const a=Object(r.sigmoid)(Object(r.slice)(i,[0,0],[-1,1])).squeeze(),o=Object(r.slice)(i,[0,1],[-1,4]),s=this.normalizeBoxes(o),u=console.warn;console.warn=(()=>{});const c=r.image.nonMaxSuppression(s,a,1,this.iouThreshold,this.scoreThreshold).arraySync();if(console.warn=u,0===c.length)return null;const l=c[0],f=Object(r.slice)(s,[l,0],[1,-1]),d=Object(r.slice)(i,[l,5],[1,14]);return{boxes:f,palmLandmarks:this.normalizeLandmarks(d,l).reshape([-1,2])}})}estimateHandBounds(t){const e=t.shape[1],n=t.shape[2],i=Object(r.tidy)(()=>t.resizeBilinear([this.width,this.height]).div(255)),a=this.getBoundingBoxes(i);if(null===a)return i.dispose(),null;const o=a.boxes.arraySync(),s=o[0].slice(0,2),u=o[0].slice(2,4),c=a.palmLandmarks.arraySync();return i.dispose(),a.boxes.dispose(),a.palmLandmarks.dispose(),function(t,e){return{startPoint:[t.startPoint[0]*e[0],t.startPoint[1]*e[1]],endPoint:[t.endPoint[0]*e[0],t.endPoint[1]*e[1]],palmLandmarks:t.palmLandmarks.map(t=>[t[0]*e[0],t[1]*e[1]])}}({startPoint:s,endPoint:u,palmLandmarks:c},[n/this.width,e/this.height])}}const f={thumb:[1,2,3,4],indexFinger:[5,6,7,8],middleFinger:[9,10,11,12],ringFinger:[13,14,15,16],pinky:[17,18,19,20],palmBase:[0]};function d(t,e){return function(t){return t-2*Math.PI*Math.floor((t+Math.PI)/(2*Math.PI))}(Math.PI/2-Math.atan2(-(e[1]-t[1]),e[0]-t[0]))}const h=(t,e)=>[[1,0,t],[0,1,e],[0,0,1]];function p(t,e){let n=0;for(let r=0;r<t.length;r++)n+=t[r]*e[r];return n}function m(t,e){const n=[];for(let r=0;r<t.length;r++)n.push(t[r][e]);return n}function g(t,e){const n=[],r=t.length;for(let i=0;i<r;i++){n.push([]);for(let a=0;a<r;a++)n[i].push(p(t[i],m(e,a)))}return n}function v(t,e){const n=Math.cos(t),r=Math.sin(t),i=[[n,-r,0],[r,n,0],[0,0,1]];return g(g(h(e[0],e[1]),i),h(-e[0],-e[1]))}function y(t,e){return[p(t,e[0]),p(t,e[1])]}const b=.8,x=[0,-.4],w=3,k=[0,-.1],_=1.65,E=[0,5,9,13,17,1,2],O=0,S=2;class C{constructor(t,e,n,r,i,a){this.regionsOfInterest=[],this.runsWithoutHandDetector=0,this.boundingBoxDetector=t,this.meshDetector=e,this.maxContinuousChecks=i,this.detectionConfidence=a,this.meshWidth=n,this.meshHeight=r,this.maxHandsNumber=1}getBoxForPalmLandmarks(t,e){const n=t.map(t=>y([...t,1],e));return s(u(c(this.calculateLandmarksBoundingBox(n),x)),w)}getBoxForHandLandmarks(t){const e=s(u(c(this.calculateLandmarksBoundingBox(t),k)),_),n=[];for(let e=0;e<E.length;e++)n.push(t[E[e]].slice(0,2));return e.palmLandmarks=n,e}transformRawCoords(t,e,n,r){const i=a(e),s=[i[0]/this.meshWidth,i[1]/this.meshHeight],u=t.map(t=>[s[0]*(t[0]-this.meshWidth/2),s[1]*(t[1]-this.meshHeight/2),t[2]]),c=v(n,[0,0]),l=u.map(t=>[...y(t,c),t[2]]),f=function(t){const e=[[t[0][0],t[1][0]],[t[0][1],t[1][1]]],n=[t[0][2],t[1][2]],r=[-p(e[0],n),-p(e[1],n)];return[e[0].concat(r[0]),e[1].concat(r[1]),[0,0,1]]}(r),d=[...o(e),1],h=[p(d,f[0]),p(d,f[1])];return l.map(t=>[t[0]+h[0],t[1]+h[1],t[2]])}async estimateHand(t){const e=this.shouldUpdateRegionsOfInterest();if(!0===e){const e=this.boundingBoxDetector.estimateHandBounds(t);if(null===e)return t.dispose(),this.regionsOfInterest=[],null;this.updateRegionsOfInterest(e,!0),this.runsWithoutHandDetector=0}else this.runsWithoutHandDetector++;const n=this.regionsOfInterest[0],i=d(n.palmLandmarks[O],n.palmLandmarks[S]),a=o(n),s=[a[0]/t.shape[2],a[1]/t.shape[1]];let u;const c=Object(r.getBackend)();if("webgl"===c)u=function(t,e,n,i){const a=t.shape,o=a[1],s=a[2],u=Math.sin(e),c=Math.cos(e),l=Math.floor(s*("number"==typeof i?i:i[0])),f=Math.floor(o*("number"==typeof i?i:i[1]));let d="";const h={variableNames:["Image"],outputShape:a,userCode:`\n void main() {\n ivec4 coords = getOutputCoords();\n int x = coords[2];\n int y = coords[1];\n int coordX = int(float(x - ${l}) * ${c} -\n float(y - ${f}) * ${u});\n int coordY = int(float(x - ${l}) * ${u} +\n float(y - ${f}) * ${c});\n coordX = int(coordX + ${l});\n coordY = int(coordY + ${f});\n\n ${d="number"==typeof n?`float outputValue = ${n.toFixed(2)};`:`\n vec3 fill = vec3(${n.join(",")});\n float outputValue = fill[coords[3]];`}\n\n if(coordX > 0 && coordX < ${s} && coordY > 0 && coordY < ${o}) {\n outputValue = getImage(coords[0], coordY, coordX, coords[3]);\n }\n\n setOutput(outputValue);\n }`};return Object(r.backend)().compileAndRun(h,[t])}(t,i,0,s);else{if("cpu"!==c)throw new Error(`Handpose is not yet supported by the ${c} `+"backend - rotation kernel is not defined.");u=function(t,e,n,i){const a=Object(r.backend)(),o=Object(r.buffer)(t.shape,t.dtype),[s,u,c,l]=t.shape,f=c*("number"==typeof i?i:i[0]),d=u*("number"==typeof i?i:i[1]),h=Math.sin(-e),p=Math.cos(-e),m=a.readSync(t.dataId);for(let t=0;t<s;t++)for(let e=0;e<u;e++)for(let r=0;r<c;r++)for(let i=0;i<l;i++){const a=[s,e,r,i],g=a[2],v=a[1];let y=(g-f)*p-(v-d)*h,b=(g-f)*h+(v-d)*p;y=Math.round(y+f),b=Math.round(b+d);let x=n;"number"!=typeof n&&(x=3===i?255:n[i]),y>=0&&y<c&&b>=0&&b<u&&(x=m[t*c*u*l+b*(c*l)+y*l+i]);const w=t*c*u*l+e*(c*l)+r*l+i;o.values[w]=x}return o.toTensor()}(t,i,0,s)}const l=v(-i,a);let f;const h=function(t,e,n){const i=e.shape[1],a=e.shape[2],o=[[t.startPoint[1]/i,t.startPoint[0]/a,t.endPoint[1]/i,t.endPoint[0]/a]];return r.image.cropAndResize(e,o,[0],n)}(f=!0===e?this.getBoxForPalmLandmarks(n.palmLandmarks,l):n,u,[this.meshWidth,this.meshHeight]),p=h.div(255);h.dispose(),u.dispose();const m=Object(r.env)().get("WEBGL_PACK_DEPTHWISECONV");Object(r.env)().set("WEBGL_PACK_DEPTHWISECONV",!0);const[g,y]=this.meshDetector.predict(p);Object(r.env)().set("WEBGL_PACK_DEPTHWISECONV",m),p.dispose();const b=g.dataSync()[0];if(g.dispose(),b<this.detectionConfidence)return y.dispose(),this.regionsOfInterest=[],null;const x=Object(r.reshape)(y,[-1,3]),w=x.arraySync();y.dispose(),x.dispose();const k=this.transformRawCoords(w,f,i,l),_=this.getBoxForHandLandmarks(k);return this.updateRegionsOfInterest(_,!1),{landmarks:k,handInViewConfidence:b,boundingBox:{topLeft:_.startPoint,bottomRight:_.endPoint}}}calculateLandmarksBoundingBox(t){const e=t.map(t=>t[0]),n=t.map(t=>t[1]);return{startPoint:[Math.min(...e),Math.min(...n)],endPoint:[Math.max(...e),Math.max(...n)]}}updateRegionsOfInterest(t,e){if(e)this.regionsOfInterest=[t];else{const e=this.regionsOfInterest[0];let n=0;if(null!=e&&null!=e.startPoint){const[r,i]=t.startPoint,[a,o]=t.endPoint,[s,u]=e.startPoint,[c,l]=e.endPoint,f=Math.max(r,s),d=Math.max(i,u),h=(Math.min(a,c)-f)*(Math.min(o,l)-d);n=h/((a-r)*(o-i)+(c-s)*(l-i)-h)}this.regionsOfInterest[0]=n>b?e:t}}shouldUpdateRegionsOfInterest(){return this.regionsOfInterest.length!==this.maxHandsNumber||this.runsWithoutHandDetector>=this.maxContinuousChecks}}const A=256,N=256;async function T({maxContinuousChecks:t=1/0,detectionConfidence:e=.8,iouThreshold:n=.3,scoreThreshold:a=.5}={}){const[o,s,u]=await Promise.all([async function(){return r.util.fetch("https://tfhub.dev/mediapipe/tfjs-model/handskeleton/1/default/1/anchors.json?tfjs-format=file").then(t=>t.json())}(),async function(){return Object(i.c)("https://tfhub.dev/mediapipe/tfjs-model/handdetector/1/default/1",{fromTFHub:!0})}(),async function(){return Object(i.c)("https://tfhub.dev/mediapipe/tfjs-model/handskeleton/1/default/1",{fromTFHub:!0})}()]),c=new l(s,A,N,o,n,a),f=new C(c,u,A,N,t,e);return new I(f)}class I{constructor(t){this.pipeline=t}static getAnnotations(){return f}async estimateHands(t,e=!1){const[,n]=function(t){return t instanceof r.Tensor?[t.shape[0],t.shape[1]]:[t.height,t.width]}(t),i=Object(r.tidy)(()=>(t instanceof r.Tensor||(t=r.browser.fromPixels(t)),t.toFloat().expandDims(0))),a=await this.pipeline.estimateHand(i);if(i.dispose(),null===a)return[];let o=a;!0===e&&(o=function(t,e){const{handInViewConfidence:n,landmarks:r,boundingBox:i}=t;return{handInViewConfidence:n,landmarks:r.map(t=>[e-1-t[0],t[1],t[2]]),boundingBox:{topLeft:[e-1-i.topLeft[0],i.topLeft[1]],bottomRight:[e-1-i.bottomRight[0],i.bottomRight[1]]}}}(a,n));const s={};for(const t of Object.keys(f))s[t]=f[t].map(t=>o.landmarks[t]);return[{handInViewConfidence:o.handInViewConfidence,boundingBox:o.boundingBox,landmarks:o.landmarks,annotations:s}]}}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=v(n(14)),i=v(n(9)),a=v(n(24)),o=v(n(8)),s=v(n(98)),u=v(n(7)),c=v(n(10)),l=v(n(97)),f=v(n(96)),d=g(n(4)),h=g(n(293)),p=n(141),m=v(n(15));function g(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}function v(t){return t&&t.__esModule?t:{default:t}}var y=function(t){function e(t,n,r){(0,u.default)(this,e);var i=(0,l.default)(this,(e.__proto__||(0,s.default)(e)).call(this));return i.video=t,i.model=null,i.modelReady=!1,i.config=n,i.ready=(0,m.default)(i.loadModel(),r),i}return(0,f.default)(e,t),(0,c.default)(e,[{key:"loadModel",value:function(){var t=(0,o.default)(i.default.mark(function t(){var e=this;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,h.load(this.config);case 2:if(this.model=t.sent,this.modelReady=!0,!this.video||0!==this.video.readyState){t.next=7;break}return t.next=7,new a.default(function(t){e.video.onloadeddata=function(){t()}});case 7:return this.predict(),t.abrupt("return",this);case 9:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"predict",value:function(){var t=(0,o.default)(i.default.mark(function t(e,n){var r,a,o,s,u=this;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r=this.getInput(e)){t.next=3;break}return t.abrupt("return",[]);case 3:return a=this.config.flipHorizontal,t.next=6,this.model.estimateHands(r,a);case 6:if(o=t.sent,s=o,this.emit("predict",s),!this.video){t.next=11;break}return t.abrupt("return",d.nextFrame().then(function(){return u.predict()}));case 11:return"function"==typeof n&&n(s),t.abrupt("return",s);case 13:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"getInput",value:function(t){return t instanceof HTMLImageElement||t instanceof HTMLVideoElement||t instanceof HTMLCanvasElement||t instanceof ImageData?t:"object"===(void 0===t?"undefined":(0,r.default)(t))&&(t.elt instanceof HTMLImageElement||t.elt instanceof HTMLVideoElement||t.elt instanceof ImageData)?t.elt:"object"===(void 0===t?"undefined":(0,r.default)(t))&&t.canvas instanceof HTMLCanvasElement?t.canvas:this.video}}]),e}(p.EventEmitter);e.default=function(t,e,n){var i=void 0,a={},o=n;t instanceof HTMLVideoElement?i=t:"object"===(void 0===t?"undefined":(0,r.default)(t))&&t.elt instanceof HTMLVideoElement?i=t.elt:"object"===(void 0===t?"undefined":(0,r.default)(t))?a=t:"function"==typeof t&&(o=t),"object"===(void 0===e?"undefined":(0,r.default)(e))?a=e:"function"==typeof e&&(o=e);var s=new y(i,a,o);return o?s:s.ready}},function(t,e,n){"use strict";n.r(e),n.d(e,"load",function(){return S}),n.d(e,"FaceMesh",function(){return A});var r=n(0),i=n(20);
  271. /**
  272. * @license
  273. * Copyright 2020 Google LLC. All Rights Reserved.
  274. * Licensed under the Apache License, Version 2.0 (the "License");
  275. * you may not use this file except in compliance with the License.
  276. * You may obtain a copy of the License at
  277. *
  278. * http://www.apache.org/licenses/LICENSE-2.0
  279. *
  280. * Unless required by applicable law or agreed to in writing, software
  281. * distributed under the License is distributed on an "AS IS" BASIS,
  282. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  283. * See the License for the specific language governing permissions and
  284. * limitations under the License.
  285. * =============================================================================
  286. */
  287. const a=t=>{t.startEndTensor.dispose(),t.startPoint.dispose(),t.endPoint.dispose()},o=t=>({startEndTensor:t,startPoint:Object(r.slice)(t,[0,0],[-1,2]),endPoint:Object(r.slice)(t,[0,2],[-1,2])}),s=(t,e)=>{const n=Object(r.mul)(t.startPoint,e),i=Object(r.mul)(t.endPoint,e),a=Object(r.concat2d)([n,i],1);return o(a)},u={strides:[8,16],anchors:[2,6]},c=6;function l(t,e){let n,i,a;if(t.topLeft instanceof r.Tensor&&t.bottomRight instanceof r.Tensor){const[o,s]=Object(r.tidy)(()=>[Object(r.concat)([Object(r.sub)(e-1,t.topLeft.slice(0,1)),t.topLeft.slice(1,1)]),Object(r.concat)([Object(r.sub)(e-1,t.bottomRight.slice(0,1)),t.bottomRight.slice(1,1)])]);n=o,i=s,null!=t.landmarks&&(a=Object(r.tidy)(()=>{const n=Object(r.sub)(Object(r.tensor1d)([e-1,0]),t.landmarks),i=Object(r.tensor1d)([1,-1]);return Object(r.mul)(n,i)}))}else{const[r,o]=t.topLeft,[s,u]=t.bottomRight;n=[e-1-r,o],i=[e-1-s,u],null!=t.landmarks&&(a=t.landmarks.map(t=>[e-1-t[0],t[1]]))}const o={topLeft:n,bottomRight:i};return null!=a&&(o.landmarks=a),null!=t.probability&&(o.probability=t.probability instanceof r.Tensor?t.probability.clone():t.probability),o}function f(t,e){return Object(r.tidy)(()=>{let n;return n=t.hasOwnProperty("box")?t.box:t,s(n,e).startEndTensor.squeeze()})}class d{constructor(t,e,n,i,a,o){this.blazeFaceModel=t,this.width=e,this.height=n,this.maxFaces=i,this.anchorsData=function(t,e,n){const r=[];for(let i=0;i<n.strides.length;i++){const a=n.strides[i],o=Math.floor((e+a-1)/a),s=Math.floor((t+a-1)/a),u=n.anchors[i];for(let t=0;t<o;t++){const e=a*(t+.5);for(let t=0;t<s;t++){const n=a*(t+.5);for(let t=0;t<u;t++)r.push([n,e])}}}return r}(e,n,u),this.anchors=Object(r.tensor2d)(this.anchorsData),this.inputSizeData=[e,n],this.inputSize=Object(r.tensor1d)([e,n]),this.iouThreshold=a,this.scoreThreshold=o}async getBoundingBoxes(t,e,n=!0){const[i,a,s]=Object(r.tidy)(()=>{const e=t.resizeBilinear([this.width,this.height]),n=Object(r.mul)(Object(r.sub)(e.div(255),.5),2),i=this.blazeFaceModel.predict(n).squeeze(),a=function(t,e,n){const i=Object(r.slice)(t,[0,1],[-1,2]),a=Object(r.add)(i,e),o=Object(r.slice)(t,[0,3],[-1,2]),s=Object(r.div)(o,n),u=Object(r.div)(a,n),c=Object(r.div)(s,2),l=Object(r.sub)(u,c),f=Object(r.add)(u,c),d=Object(r.mul)(l,n),h=Object(r.mul)(f,n);return Object(r.concat2d)([d,h],1)}(i,this.anchors,this.inputSize),o=Object(r.slice)(i,[0,0],[-1,1]);return[i,a,Object(r.sigmoid)(o).squeeze()]}),u=console.warn;console.warn=(()=>{});const l=r.image.nonMaxSuppression(a,s,this.maxFaces,this.iouThreshold,this.scoreThreshold);console.warn=u;const f=await l.array();l.dispose();let d=f.map(t=>Object(r.slice)(a,[t,0],[1,-1]));e||(d=await Promise.all(d.map(async t=>{const e=await t.array();return t.dispose(),e})));const h=t.shape[1],p=t.shape[2];let m;m=e?Object(r.div)([p,h],this.inputSize):[p/this.inputSizeData[0],h/this.inputSizeData[1]];const g=[];for(let t=0;t<d.length;t++){const a=d[t],u=Object(r.tidy)(()=>{const u=o(a instanceof r.Tensor?a:Object(r.tensor2d)(a));if(!n)return u;const l=f[t];let d;return d=e?this.anchors.slice([l,0],[1,2]):this.anchorsData[l],{box:u,landmarks:Object(r.slice)(i,[l,c-1],[1,-1]).squeeze().reshape([c,-1]),probability:Object(r.slice)(s,[l],[1]),anchor:d}});g.push(u)}return a.dispose(),s.dispose(),i.dispose(),{boxes:g,scaleFactor:m}}async estimateFaces(t,e=!1,n=!1,i=!0){const[,o]=function(t){return t instanceof r.Tensor?[t.shape[0],t.shape[1]]:[t.height,t.width]}(t),s=Object(r.tidy)(()=>(t instanceof r.Tensor||(t=r.browser.fromPixels(t)),t.toFloat().expandDims(0))),{boxes:u,scaleFactor:c}=await this.getBoundingBoxes(s,e,i);return s.dispose(),e?u.map(t=>{const e=f(t,c);let r={topLeft:e.slice([0],[2]),bottomRight:e.slice([2],[2])};if(i){const{landmarks:e,probability:n,anchor:i}=t,a=e.add(i).mul(c);r.landmarks=a,r.probability=n}return n&&(r=l(r,o)),r}):Promise.all(u.map(async t=>{const e=f(t,c);let r;if(i){const[n,i,o]=await Promise.all([t.landmarks,e,t.probability].map(async t=>t.array())),s=t.anchor,[u,l]=c,f=n.map(t=>[(t[0]+s[0])*u,(t[1]+s[1])*l]);r={topLeft:i.slice(0,2),bottomRight:i.slice(2),landmarks:f,probability:o},a(t.box),t.landmarks.dispose(),t.probability.dispose()}else{const t=await e.array();r={topLeft:t.slice(0,2),bottomRight:t.slice(2)}}return e.dispose(),n&&(r=l(r,o)),r}))}}const h="https://tfhub.dev/tensorflow/tfjs-model/blazeface/1/default/1";const p={silhouette:[10,338,297,332,284,251,389,356,454,323,361,288,397,365,379,378,400,377,152,148,176,149,150,136,172,58,132,93,234,127,162,21,54,103,67,109],lipsUpperOuter:[61,185,40,39,37,0,267,269,270,409,291],lipsLowerOuter:[146,91,181,84,17,314,405,321,375,291],lipsUpperInner:[78,191,80,81,82,13,312,311,310,415,308],lipsLowerInner:[78,95,88,178,87,14,317,402,318,324,308],rightEyeUpper0:[246,161,160,159,158,157,173],rightEyeLower0:[33,7,163,144,145,153,154,155,133],rightEyeUpper1:[247,30,29,27,28,56,190],rightEyeLower1:[130,25,110,24,23,22,26,112,243],rightEyeUpper2:[113,225,224,223,222,221,189],rightEyeLower2:[226,31,228,229,230,231,232,233,244],rightEyeLower3:[143,111,117,118,119,120,121,128,245],rightEyebrowUpper:[156,70,63,105,66,107,55,193],rightEyebrowLower:[35,124,46,53,52,65],leftEyeUpper0:[466,388,387,386,385,384,398],leftEyeLower0:[263,249,390,373,374,380,381,382,362],leftEyeUpper1:[467,260,259,257,258,286,414],leftEyeLower1:[359,255,339,254,253,252,256,341,463],leftEyeUpper2:[342,445,444,443,442,441,413],leftEyeLower2:[446,261,448,449,450,451,452,453,464],leftEyeLower3:[372,340,346,347,348,349,350,357,465],leftEyebrowUpper:[383,300,293,334,296,336,285,417],leftEyebrowLower:[265,353,276,283,282,295],midwayBetweenEyes:[168],noseTip:[1],noseBottom:[2],noseRightCorner:[98],noseLeftCorner:[327],rightCheek:[205],leftCheek:[425]};function m(t){null!=t&&null!=t.startPoint&&(t.startEndTensor.dispose(),t.startPoint.dispose(),t.endPoint.dispose())}function g(t,e,n){return{startEndTensor:t,startPoint:null!=e?e:Object(r.slice)(t,[0,0],[-1,2]),endPoint:null!=n?n:Object(r.slice)(t,[0,2],[-1,2])}}function v(t){return Object(r.tidy)(()=>{const e=Object(r.sub)(t.endPoint,t.startPoint);return Object(r.abs)(e)})}function y(t,e=1.5){return Object(r.tidy)(()=>{const n=function(t){return Object(r.tidy)(()=>{const e=Object(r.div)(Object(r.sub)(t.endPoint,t.startPoint),2);return Object(r.add)(t.startPoint,e)})}(t),i=v(t),a=Object(r.mul)(Object(r.div)(i,2),e),o=Object(r.sub)(n,a),s=Object(r.add)(n,a);return g(Object(r.concat2d)([o,s],1),o,s)})}const b=468,x=.25;class w{constructor(t,e,n,r,i,a){this.regionsOfInterest=[],this.runsWithoutFaceDetector=0,this.boundingBoxDetector=t,this.meshDetector=e,this.meshWidth=n,this.meshHeight=r,this.maxContinuousChecks=i,this.maxFaces=a}async predict(t){if(this.shouldUpdateRegionsOfInterest()){const e=!0,n=!1,{boxes:i,scaleFactor:a}=await this.boundingBoxDetector.getBoundingBoxes(t,e,n);if(0===i.length)return a.dispose(),this.clearAllRegionsOfInterest(),null;const o=i.map(t=>y(function(t,e){const n=Object(r.mul)(t.startPoint,e),i=Object(r.mul)(t.endPoint,e);return g(Object(r.concat2d)([n,i],1))}(t,a)));i.forEach(m),this.updateRegionsOfInterest(o),this.runsWithoutFaceDetector=0}else this.runsWithoutFaceDetector++;return Object(r.tidy)(()=>this.regionsOfInterest.map((e,n)=>{const i=function(t,e,n){const i=e.shape[1],a=e.shape[2],o=t.startEndTensor;return Object(r.tidy)(()=>{const t=Object(r.concat2d)([o.slice([0,1],[-1,1]),o.slice([0,0],[-1,1]),o.slice([0,3],[-1,1]),o.slice([0,2],[-1,1])],0),s=Object(r.div)(t.transpose(),[i,a,i,a]);return r.image.cropAndResize(e,s,[0],n)})}(e,t,[this.meshHeight,this.meshWidth]).div(255),[,a,o]=this.meshDetector.predict(i),s=Object(r.reshape)(o,[-1,3]),u=Object(r.div)(v(e),[this.meshWidth,this.meshHeight]),c=Object(r.mul)(s,u.concat(Object(r.tensor2d)([1],[1,1]),1)).add(e.startPoint.concat(Object(r.tensor2d)([0],[1,1]),1)),l=this.calculateLandmarksBoundingBox(c);return m(this.regionsOfInterest[n]),this.regionsOfInterest[n]=l,{coords:s,scaledCoords:c,box:l,flag:a.squeeze()}}))}updateRegionsOfInterest(t){for(let e=0;e<t.length;e++){const n=t[e],r=this.regionsOfInterest[e];let i=0;if(r&&r.startPoint){const[t,e,a,o]=n.startEndTensor.arraySync()[0],[s,u,c,l]=r.startEndTensor.arraySync()[0],f=Math.max(t,s),d=Math.max(e,u),h=(Math.min(a,c)-f)*(Math.min(o,l)-d);i=h/((a-t)*(o-e)+(c-s)*(l-e)-h)}i>x?m(n):(this.regionsOfInterest[e]=n,m(r))}for(let e=t.length;e<this.regionsOfInterest.length;e++)m(this.regionsOfInterest[e]);this.regionsOfInterest=this.regionsOfInterest.slice(0,t.length)}clearRegionOfInterest(t){null!=this.regionsOfInterest[t]&&(m(this.regionsOfInterest[t]),this.regionsOfInterest=[...this.regionsOfInterest.slice(0,t),...this.regionsOfInterest.slice(t+1)])}clearAllRegionsOfInterest(){for(let t=0;t<this.regionsOfInterest.length;t++)m(this.regionsOfInterest[t]);this.regionsOfInterest=[]}shouldUpdateRegionsOfInterest(){const t=this.regionsOfInterest.length,e=0===t;return 1===this.maxFaces||e?e:t!==this.maxFaces&&this.runsWithoutFaceDetector>=this.maxContinuousChecks}calculateLandmarksBoundingBox(t){const e=t.slice([0,0],[b,1]),n=t.slice([0,1],[b,1]);return y(g(Object(r.stack)([e.min(),n.min(),e.max(),n.max()]).expandDims(0)))}}const k=[[.499976992607117,.652534008026123],[.500025987625122,.547487020492554],[.499974012374878,.602371990680695],[.482113003730774,.471979022026062],[.500150978565216,.527155995368958],[.499909996986389,.498252987861633],[.499523013830185,.40106201171875],[.289712011814117,.380764007568359],[.499954998493195,.312398016452789],[.499987006187439,.269918978214264],[.500023007392883,.107050001621246],[.500023007392883,.666234016418457],[.5000159740448,.679224014282227],[.500023007392883,.692348003387451],[.499976992607117,.695277988910675],[.499976992607117,.70593398809433],[.499976992607117,.719385027885437],[.499976992607117,.737019002437592],[.499967992305756,.781370997428894],[.499816000461578,.562981009483337],[.473773002624512,.573909997940063],[.104906998574734,.254140973091125],[.365929991006851,.409575998783112],[.338757991790771,.41302502155304],[.311120003461838,.409460008144379],[.274657994508743,.389131009578705],[.393361985683441,.403706014156342],[.345234006643295,.344011008739471],[.370094001293182,.346076011657715],[.319321990013123,.347265005111694],[.297903001308441,.353591024875641],[.24779200553894,.410809993743896],[.396889001131058,.842755019664764],[.280097991228104,.375599980354309],[.106310002505779,.399955987930298],[.2099249958992,.391353011131287],[.355807989835739,.534406006336212],[.471751004457474,.65040397644043],[.474155008792877,.680191993713379],[.439785003662109,.657229006290436],[.414617002010345,.66654098033905],[.450374007225037,.680860996246338],[.428770989179611,.682690978050232],[.374971002340317,.727805018424988],[.486716985702515,.547628998756409],[.485300987958908,.527395009994507],[.257764995098114,.314490020275116],[.401223003864288,.455172002315521],[.429818987846375,.548614978790283],[.421351999044418,.533740997314453],[.276895999908447,.532056987285614],[.483370006084442,.499586999416351],[.33721199631691,.282882988452911],[.296391993761063,.293242990970612],[.169294998049736,.193813979625702],[.447580009698868,.302609980106354],[.392390012741089,.353887975215912],[.354490011930466,.696784019470215],[.067304998636246,.730105042457581],[.442739009857178,.572826027870178],[.457098007202148,.584792017936707],[.381974011659622,.694710969924927],[.392388999462128,.694203019142151],[.277076005935669,.271932005882263],[.422551989555359,.563233017921448],[.385919004678726,.281364023685455],[.383103013038635,.255840003490448],[.331431001424789,.119714021682739],[.229923993349075,.232002973556519],[.364500999450684,.189113974571228],[.229622006416321,.299540996551514],[.173287004232407,.278747975826263],[.472878992557526,.666198015213013],[.446828007698059,.668527007102966],[.422762006521225,.673889994621277],[.445307999849319,.580065965652466],[.388103008270264,.693961024284363],[.403039008378983,.706539988517761],[.403629004955292,.693953037261963],[.460041999816895,.557139039039612],[.431158006191254,.692366003990173],[.452181994915009,.692366003990173],[.475387006998062,.692366003990173],[.465828001499176,.779190003871918],[.472328990697861,.736225962638855],[.473087012767792,.717857003211975],[.473122000694275,.704625964164734],[.473033010959625,.695277988910675],[.427942007780075,.695277988910675],[.426479011774063,.703539967536926],[.423162013292313,.711845993995667],[.4183090031147,.720062971115112],[.390094995498657,.639572978019714],[.013953999616206,.560034036636353],[.499913990497589,.58014702796936],[.413199990987778,.69539999961853],[.409626007080078,.701822996139526],[.468080013990402,.601534962654114],[.422728985548019,.585985004901886],[.463079988956451,.593783974647522],[.37211999297142,.47341400384903],[.334562003612518,.496073007583618],[.411671012639999,.546965003013611],[.242175996303558,.14767599105835],[.290776997804642,.201445996761322],[.327338010072708,.256527006626129],[.399509996175766,.748921036720276],[.441727995872498,.261676013469696],[.429764986038208,.187834024429321],[.412198007106781,.108901023864746],[.288955003023148,.398952007293701],[.218936994671822,.435410976409912],[.41278201341629,.398970007896423],[.257135003805161,.355440020561218],[.427684992551804,.437960982322693],[.448339998722076,.536936044692993],[.178560003638268,.45755398273468],[.247308000922203,.457193970680237],[.286267012357712,.467674970626831],[.332827985286713,.460712015628815],[.368755996227264,.447206974029541],[.398963987827301,.432654976844788],[.476410001516342,.405806005001068],[.189241006970406,.523923993110657],[.228962004184723,.348950982093811],[.490725994110107,.562400996685028],[.404670000076294,.485132992267609],[.019469000399113,.401564002037048],[.426243007183075,.420431017875671],[.396993011236191,.548797011375427],[.266469985246658,.376977026462555],[.439121007919312,.51895797252655],[.032313998788595,.644356966018677],[.419054001569748,.387154996395111],[.462783008813858,.505746960639954],[.238978996872902,.779744982719421],[.198220998048782,.831938028335571],[.107550002634525,.540755033493042],[.183610007166862,.740257024765015],[.134409993886948,.333683013916016],[.385764002799988,.883153975009918],[.490967005491257,.579378008842468],[.382384985685349,.508572995662689],[.174399003386497,.397670984268188],[.318785011768341,.39623498916626],[.343364000320435,.400596976280212],[.396100014448166,.710216999053955],[.187885001301765,.588537991046906],[.430987000465393,.944064974784851],[.318993002176285,.898285031318665],[.266247987747192,.869701027870178],[.500023007392883,.190576016902924],[.499976992607117,.954452991485596],[.366169989109039,.398822009563446],[.393207013607025,.39553701877594],[.410373002290726,.391080021858215],[.194993004202843,.342101991176605],[.388664990663528,.362284004688263],[.365961998701096,.355970978736877],[.343364000320435,.355356991291046],[.318785011768341,.35834002494812],[.301414996385574,.363156020641327],[.058132998645306,.319076001644135],[.301414996385574,.387449026107788],[.499987989664078,.618434011936188],[.415838003158569,.624195992946625],[.445681989192963,.566076993942261],[.465844005346298,.620640993118286],[.49992299079895,.351523995399475],[.288718998432159,.819945991039276],[.335278987884521,.852819979190826],[.440512001514435,.902418971061707],[.128294005990028,.791940987110138],[.408771991729736,.373893976211548],[.455606997013092,.451801002025604],[.499877005815506,.908990025520325],[.375436991453171,.924192011356354],[.11421000212431,.615022003650665],[.448662012815475,.695277988910675],[.4480200111866,.704632043838501],[.447111994028091,.715808033943176],[.444831997156143,.730794012546539],[.430011987686157,.766808986663818],[.406787008047104,.685672998428345],[.400738000869751,.681069016456604],[.392399996519089,.677703022956848],[.367855995893478,.663918972015381],[.247923001646996,.601333022117615],[.452769994735718,.420849978923798],[.43639200925827,.359887003898621],[.416164010763168,.368713974952698],[.413385987281799,.692366003990173],[.228018000721931,.683571994304657],[.468268007040024,.352671027183533],[.411361992359161,.804327011108398],[.499989002943039,.469825029373169],[.479153990745544,.442654013633728],[.499974012374878,.439637005329132],[.432112008333206,.493588984012604],[.499886006116867,.866917014122009],[.49991300702095,.821729004383087],[.456548988819122,.819200992584229],[.344549000263214,.745438992977142],[.37890899181366,.574010014533997],[.374292999505997,.780184984207153],[.319687992334366,.570737957954407],[.357154995203018,.604269981384277],[.295284003019333,.621580958366394],[.447750002145767,.862477004528046],[.410986006259918,.508723020553589],[.31395098567009,.775308012962341],[.354128003120422,.812552988529205],[.324548006057739,.703992962837219],[.189096003770828,.646299958229065],[.279776990413666,.71465802192688],[.1338230073452,.682700991630554],[.336768001317978,.644733011722565],[.429883986711502,.466521978378296],[.455527991056442,.548622965812683],[.437114000320435,.558896005153656],[.467287987470627,.529924988746643],[.414712011814117,.335219979286194],[.37704598903656,.322777986526489],[.344107985496521,.320150971412659],[.312875986099243,.32233202457428],[.283526003360748,.333190023899078],[.241245999932289,.382785975933075],[.102986000478268,.468762993812561],[.267612010240555,.424560010433197],[.297879010438919,.433175981044769],[.333433985710144,.433878004550934],[.366427004337311,.426115989685059],[.396012008190155,.416696012020111],[.420121014118195,.41022801399231],[.007561000064015,.480777025222778],[.432949006557465,.569517970085144],[.458638995885849,.479089021682739],[.473466008901596,.545744001865387],[.476087987422943,.563830018043518],[.468472003936768,.555056989192963],[.433990985155106,.582361996173859],[.483518004417419,.562983989715576],[.482482999563217,.57784903049469],[.42645001411438,.389798998832703],[.438998997211456,.39649498462677],[.450067013502121,.400434017181396],[.289712011814117,.368252992630005],[.276670008897781,.363372981548309],[.517862021923065,.471948027610779],[.710287988185883,.380764007568359],[.526226997375488,.573909997940063],[.895093023777008,.254140973091125],[.634069979190826,.409575998783112],[.661242008209229,.41302502155304],[.688880026340485,.409460008144379],[.725341975688934,.389131009578705],[.606630027294159,.40370500087738],[.654766023159027,.344011008739471],[.629905998706818,.346076011657715],[.680678009986877,.347265005111694],[.702096998691559,.353591024875641],[.75221198797226,.410804986953735],[.602918028831482,.842862963676453],[.719901978969574,.375599980354309],[.893692970275879,.399959981441498],[.790081977844238,.391354024410248],[.643998026847839,.534487962722778],[.528249025344849,.65040397644043],[.525849997997284,.680191040039062],[.560214996337891,.657229006290436],[.585384011268616,.66654098033905],[.549625992774963,.680860996246338],[.57122802734375,.682691991329193],[.624852001667023,.72809898853302],[.513050019741058,.547281980514526],[.51509702205658,.527251958847046],[.742246985435486,.314507007598877],[.598631024360657,.454979002475739],[.570338010787964,.548575043678284],[.578631997108459,.533622980117798],[.723087012767792,.532054007053375],[.516445994377136,.499638974666595],[.662801027297974,.282917976379395],[.70362401008606,.293271005153656],[.830704987049103,.193813979625702],[.552385985851288,.302568018436432],[.607609987258911,.353887975215912],[.645429015159607,.696707010269165],[.932694971561432,.730105042457581],[.557260990142822,.572826027870178],[.542901992797852,.584792017936707],[.6180260181427,.694710969924927],[.607590973377228,.694203019142151],[.722943007946014,.271963000297546],[.577413976192474,.563166975975037],[.614082992076874,.281386971473694],[.616907000541687,.255886018276215],[.668509006500244,.119913995265961],[.770092010498047,.232020974159241],[.635536015033722,.189248979091644],[.77039098739624,.299556016921997],[.826722025871277,.278755009174347],[.527121007442474,.666198015213013],[.553171992301941,.668527007102966],[.577238023281097,.673889994621277],[.554691970348358,.580065965652466],[.611896991729736,.693961024284363],[.59696102142334,.706539988517761],[.596370995044708,.693953037261963],[.539958000183105,.557139039039612],[.568841993808746,.692366003990173],[.547818005084991,.692366003990173],[.52461302280426,.692366003990173],[.534089982509613,.779141008853912],[.527670979499817,.736225962638855],[.526912987232208,.717857003211975],[.526877999305725,.704625964164734],[.526966989040375,.695277988910675],[.572058022022247,.695277988910675],[.573521018028259,.703539967536926],[.57683801651001,.711845993995667],[.581691026687622,.720062971115112],[.609944999217987,.639909982681274],[.986046016216278,.560034036636353],[.5867999792099,.69539999961853],[.590372025966644,.701822996139526],[.531915009021759,.601536989212036],[.577268004417419,.585934996604919],[.536915004253387,.593786001205444],[.627542972564697,.473352015018463],[.665585994720459,.495950996875763],[.588353991508484,.546862006187439],[.757824003696442,.14767599105835],[.709249973297119,.201507985591888],[.672684013843536,.256581008434296],[.600408971309662,.74900496006012],[.55826598405838,.261672019958496],[.570303976535797,.187870979309082],[.588165998458862,.109044015407562],[.711045026779175,.398952007293701],[.781069993972778,.435405015945435],[.587247014045715,.398931980133057],[.742869973182678,.355445981025696],[.572156012058258,.437651991844177],[.55186802148819,.536570012569427],[.821442008018494,.457556009292603],[.752701997756958,.457181990146637],[.71375697851181,.467626988887787],[.66711300611496,.460672974586487],[.631101012229919,.447153985500336],[.6008620262146,.432473003864288],[.523481011390686,.405627012252808],[.810747981071472,.523926019668579],[.771045982837677,.348959028720856],[.509127020835876,.562718033790588],[.595292985439301,.485023975372314],[.980530977249146,.401564002037048],[.573499977588654,.420000016689301],[.602994978427887,.548687994480133],[.733529984951019,.376977026462555],[.560611009597778,.519016981124878],[.967685997486115,.644356966018677],[.580985009670258,.387160003185272],[.537728011608124,.505385041236877],[.760966002941132,.779752969741821],[.801778972148895,.831938028335571],[.892440974712372,.54076099395752],[.816350996494293,.740260004997253],[.865594983100891,.333687007427216],[.614073991775513,.883246004581451],[.508952975273132,.579437971115112],[.617941975593567,.508316040039062],[.825608015060425,.397674977779388],[.681214988231659,.39623498916626],[.656635999679565,.400596976280212],[.603900015354156,.710216999053955],[.81208598613739,.588539004325867],[.56801301240921,.944564998149872],[.681007981300354,.898285031318665],[.733752012252808,.869701027870178],[.633830010890961,.398822009563446],[.606792986392975,.39553701877594],[.589659988880157,.391062021255493],[.805015981197357,.342108011245728],[.611334979534149,.362284004688263],[.634037971496582,.355970978736877],[.656635999679565,.355356991291046],[.681214988231659,.35834002494812],[.698584973812103,.363156020641327],[.941866993904114,.319076001644135],[.698584973812103,.387449026107788],[.584177017211914,.624107003211975],[.554318010807037,.566076993942261],[.534153997898102,.62064003944397],[.711217999458313,.819975018501282],[.664629995822906,.852871000766754],[.559099972248077,.902631998062134],[.871706008911133,.791940987110138],[.591234028339386,.373893976211548],[.544341027736664,.451583981513977],[.624562978744507,.924192011356354],[.88577002286911,.615028977394104],[.551338016986847,.695277988910675],[.551980018615723,.704632043838501],[.552887976169586,.715808033943176],[.555167973041534,.730794012546539],[.569944024085999,.767035007476807],[.593203008174896,.685675978660583],[.599261999130249,.681069016456604],[.607599973678589,.677703022956848],[.631937980651855,.663500010967255],[.752032995223999,.601315021514893],[.547226011753082,.420395016670227],[.563543975353241,.359827995300293],[.583841025829315,.368713974952698],[.586614012718201,.692366003990173],[.771915018558502,.683578014373779],[.531597018241882,.352482974529266],[.588370978832245,.804440975189209],[.52079701423645,.442565023899078],[.567984998226166,.493479013442993],[.543282985687256,.819254994392395],[.655317008495331,.745514988899231],[.621008992195129,.574018001556396],[.625559985637665,.78031200170517],[.680198013782501,.570719003677368],[.64276397228241,.604337990283966],[.704662978649139,.621529996395111],[.552012026309967,.862591981887817],[.589071989059448,.508637011051178],[.685944974422455,.775357007980347],[.645735025405884,.812640011310577],[.675342977046967,.703978002071381],[.810858011245728,.646304965019226],[.72012197971344,.714666962623596],[.866151988506317,.682704985141754],[.663187026977539,.644596993923187],[.570082008838654,.466325998306274],[.544561982154846,.548375964164734],[.562758982181549,.558784961700439],[.531987011432648,.530140042304993],[.585271000862122,.335177004337311],[.622952997684479,.32277899980545],[.655896008014679,.320163011550903],[.687132000923157,.322345972061157],[.716481983661652,.333200991153717],[.758756995201111,.382786989212036],[.897013008594513,.468769013881683],[.732392013072968,.424547016620636],[.70211398601532,.433162987232208],[.66652500629425,.433866024017334],[.633504986763,.426087975502014],[.603875994682312,.416586995124817],[.579657971858978,.409945011138916],[.992439985275269,.480777025222778],[.567192018032074,.569419980049133],[.54136598110199,.478899002075195],[.526564002037048,.546118021011353],[.523913025856018,.563830018043518],[.531529009342194,.555056989192963],[.566035985946655,.582329034805298],[.51631098985672,.563053965568542],[.5174720287323,.577877044677734],[.573594987392426,.389806985855103],[.560697972774506,.395331978797913],[.549755990505219,.399751007556915],[.710287988185883,.368252992630005],[.723330020904541,.363372981548309]],_="https://tfhub.dev/mediapipe/tfjs-model/facemesh/1/default/1",E=192,O=192;async function S({maxContinuousChecks:t=5,detectionConfidence:e=.9,maxFaces:n=10,iouThreshold:r=.3,scoreThreshold:a=.75}={}){const[o,s]=await Promise.all([async function(t,e,n){return async function({maxFaces:t=10,inputWidth:e=128,inputHeight:n=128,iouThreshold:r=.3,scoreThreshold:a=.75}={}){const o=await Object(i.c)(h,{fromTFHub:!0});return new d(o,e,n,t,r,a)}({maxFaces:t,iouThreshold:e,scoreThreshold:n})}(n,r,a),async function(){return Object(i.c)(_,{fromTFHub:!0})}()]);return new A(o,s,t,e,n)}function C(t,e){if(t.mesh instanceof r.Tensor){const[n,i,a,o]=Object(r.tidy)(()=>{const n=Object(r.tensor1d)([e-1,0,0]),i=Object(r.tensor1d)([1,-1,1]);return Object(r.tidy)(()=>[Object(r.concat)([Object(r.sub)(e-1,t.boundingBox.topLeft.slice(0,1)),t.boundingBox.topLeft.slice(1,1)]),Object(r.concat)([Object(r.sub)(e-1,t.boundingBox.bottomRight.slice(0,1)),t.boundingBox.bottomRight.slice(1,1)]),Object(r.sub)(n,t.mesh).mul(i),Object(r.sub)(n,t.scaledMesh).mul(i)])});return Object.assign({},t,{boundingBox:{topLeft:n,bottomRight:i},mesh:a,scaledMesh:o})}return Object.assign({},t,{boundingBox:{topLeft:[e-1-t.boundingBox.topLeft[0],t.boundingBox.topLeft[1]],bottomRight:[e-1-t.boundingBox.bottomRight[0],t.boundingBox.bottomRight[1]]},mesh:t.mesh.map(t=>{const n=t.slice(0);return n[0]=e-1-t[0],n}),scaledMesh:t.scaledMesh.map(t=>{const n=t.slice(0);return n[0]=e-1-t[0],n})})}class A{constructor(t,e,n,r,i){this.pipeline=new w(t,e,E,O,n,i),this.detectionConfidence=r}static getAnnotations(){return p}static getUVCoords(){return k}async estimateFaces(t,e=!1,n=!1){const[,i]=function(t){return t instanceof r.Tensor?[t.shape[0],t.shape[1]]:[t.height,t.width]}(t),a=Object(r.tidy)(()=>(t instanceof r.Tensor||(t=r.browser.fromPixels(t)),t.toFloat().expandDims(0))),o=Object(r.env)().get("WEBGL_PACK_DEPTHWISECONV");Object(r.env)().set("WEBGL_PACK_DEPTHWISECONV",!0);const s=await this.pipeline.predict(a);return Object(r.env)().set("WEBGL_PACK_DEPTHWISECONV",o),a.dispose(),null!=s&&s.length>0?Promise.all(s.map(async(t,r)=>{const{coords:a,scaledCoords:o,box:s,flag:u}=t;let c=[u];e||(c=c.concat([a,o,s.startPoint,s.endPoint]));const l=await Promise.all(c.map(async t=>t.array())),f=l[0];if(u.dispose(),f<this.detectionConfidence&&this.pipeline.clearRegionOfInterest(r),e){const t={faceInViewConfidence:f,mesh:a,scaledMesh:o,boundingBox:{topLeft:s.startPoint.squeeze(),bottomRight:s.endPoint.squeeze()}};return n?C(t,i):t}const[d,h,m,g]=l.slice(1);o.dispose(),a.dispose();let v={faceInViewConfidence:f,boundingBox:{topLeft:m,bottomRight:g},mesh:d,scaledMesh:h};n&&(v=C(v,i));const y={};for(const t in p)y[t]=p[t].map(t=>v.scaledMesh[t]);return v.annotations=y,v})):[]}}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=v(n(14)),i=v(n(9)),a=v(n(24)),o=v(n(8)),s=v(n(98)),u=v(n(7)),c=v(n(10)),l=v(n(97)),f=v(n(96)),d=g(n(4)),h=g(n(295)),p=n(141),m=v(n(15));function g(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}function v(t){return t&&t.__esModule?t:{default:t}}var y=function(t){function e(t,n,r){(0,u.default)(this,e);var i=(0,l.default)(this,(e.__proto__||(0,s.default)(e)).call(this));return i.video=t,i.model=null,i.modelReady=!1,i.config=n,i.ready=(0,m.default)(i.loadModel(),r),i}return(0,f.default)(e,t),(0,c.default)(e,[{key:"loadModel",value:function(){var t=(0,o.default)(i.default.mark(function t(){var e=this;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,h.load(this.config);case 2:if(this.model=t.sent,this.modelReady=!0,!this.video||0!==this.video.readyState){t.next=7;break}return t.next=7,new a.default(function(t){e.video.onloadeddata=function(){t()}});case 7:return this.predict(),t.abrupt("return",this);case 9:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"predict",value:function(){var t=(0,o.default)(i.default.mark(function t(e,n){var r,a,o,s,u=this;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=this.getInput(e),a=this.config.flipHorizontal,t.next=4,this.model.estimateFaces(r,a);case 4:if(o=t.sent,s=o,this.emit("predict",s),!this.video){t.next=9;break}return t.abrupt("return",d.nextFrame().then(function(){return u.predict()}));case 9:return"function"==typeof n&&n(s),t.abrupt("return",s);case 11:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"getInput",value:function(t){return t instanceof HTMLImageElement||t instanceof HTMLVideoElement||t instanceof HTMLCanvasElement||t instanceof ImageData?t:"object"===(void 0===t?"undefined":(0,r.default)(t))&&(t.elt instanceof HTMLImageElement||t.elt instanceof HTMLVideoElement||t.elt instanceof ImageData)?t.elt:"object"===(void 0===t?"undefined":(0,r.default)(t))&&t.canvas instanceof HTMLCanvasElement?t.canvas:this.video}}]),e}(p.EventEmitter);e.default=function(t,e,n){var i=void 0,a={},o=n;t instanceof HTMLVideoElement?i=t:"object"===(void 0===t?"undefined":(0,r.default)(t))&&t.elt instanceof HTMLVideoElement?i=t.elt:"object"===(void 0===t?"undefined":(0,r.default)(t))?a=t:"function"==typeof t&&(o=t),"object"===(void 0===e?"undefined":(0,r.default)(e))?a=e:"function"==typeof e&&(o=e);var s=new y(i,a,o);return o?s:s.ready}},function(t,e,n){"use strict";n.r(e),n.d(e,"load",function(){return m}),n.d(e,"loadTokenizer",function(){return g}),n.d(e,"UniversalSentenceEncoder",function(){return y}),n.d(e,"Tokenizer",function(){return d}),n.d(e,"version",function(){return h});var r=n(20),i=n(0);
  288. /**
  289. * @license
  290. * Copyright 2019 Google LLC. All Rights Reserved.
  291. * Licensed under the Apache License, Version 2.0 (the "License");
  292. * you may not use this file except in compliance with the License.
  293. * You may obtain a copy of the License at
  294. *
  295. * http://www.apache.org/licenses/LICENSE-2.0
  296. *
  297. * Unless required by applicable law or agreed to in writing, software
  298. * distributed under the License is distributed on an "AS IS" BASIS,
  299. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  300. * See the License for the specific language governing permissions and
  301. * limitations under the License.
  302. * =============================================================================
  303. */
  304. function a(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})}function o(t,e){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=(i=o.trys).length>0&&i[i.length-1])&&(6===a[0]||2===a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}var s=function(t){for(var e=[],n=0,r=t;n<r.length;n++){var i=r[n];e.push(i)}return e},u=function(){this.parent=null,this.children={},this.end=!1,this.word=[[],0,0]},c=function(){function t(){this.root=new u}return t.prototype.insert=function(t,e,n){for(var r=this.root,i=s(t),a=0;a<i.length;a++)r.children[i[a]]||(r.children[i[a]]=new u,r.children[i[a]].parent=r,r.children[i[a]].word[0]=r.word[0].concat(i[a])),r=r.children[i[a]],a===i.length-1&&(r.end=!0,r.word[1]=e,r.word[2]=n)},t.prototype.commonPrefixSearch=function(t){for(var e=[],n=this.root.children[t[0]],r=0;r<t.length&&n;r++)n.end&&e.push(n.word),n=n.children[t[r+1]];return e.length||e.push([[t[0]],0,0]),e},t}(),l="▁";var f=6,d=function(){function t(t){this.vocabulary=t,this.trie=new c;for(var e=f;e<this.vocabulary.length;e++)this.trie.insert(this.vocabulary[e][0],this.vocabulary[e][1],e)}return t.prototype.encode=function(t){var e=[],n=[],r=[];t=function(t){var e=t.normalize("NFKC");return l+e.replace(/ /g,l)}(t);for(var i=s(t),a=0;a<=i.length;a++)e.push({}),n.push(0),r.push(0);for(a=0;a<i.length;a++)for(var o=this.trie.commonPrefixSearch(i.slice(a)),u=0;u<o.length;u++){var c=o[u],f={key:c[0],score:c[1],index:c[2]};null==e[a+(d=c[0].length)][a]&&(e[a+d][a]=[]),e[a+d][a].push(f)}for(var d=0;d<=i.length;d++)for(var h in e[d]){var p=e[d][h];for(u=0;u<p.length;u++){var m=p[u],g=m.score+r[d-m.key.length];(0===r[d]||g>=r[d])&&(r[d]=g,n[d]=p[u].index)}}for(var v=[],y=n.length-1;y>0;)v.push(n[y]),y-=this.vocabulary[n[y]][0].length;var b=[],x=!1;for(a=0;a<v.length;a++){var w=v[a];x&&0===w||b.push(w),x=0===w}return b.reverse()},t}(),h="1.2.2",p="https://storage.googleapis.com/tfjs-models/savedmodel/universal_sentence_encoder/";function m(){return a(this,void 0,void 0,function(){var t;return o(this,function(e){switch(e.label){case 0:return[4,(t=new y).load()];case 1:return e.sent(),[2,t]}})})}function g(t){return a(this,void 0,void 0,function(){var e;return o(this,function(n){switch(n.label){case 0:return[4,v(t)];case 1:return e=n.sent(),[2,new d(e)]}})})}function v(t){return void 0===t&&(t=p+"vocab.json"),a(this,void 0,void 0,function(){return o(this,function(e){switch(e.label){case 0:return[4,i.util.fetch(t)];case 1:return[2,e.sent().json()]}})})}var y=function(){function t(){}return t.prototype.loadModel=function(){return a(this,void 0,void 0,function(){return o(this,function(t){return[2,Object(r.c)("https://tfhub.dev/tensorflow/tfjs-model/universal-sentence-encoder-lite/1/default/1",{fromTFHub:!0})]})})},t.prototype.load=function(){return a(this,void 0,void 0,function(){var t,e,n;return o(this,function(r){switch(r.label){case 0:return[4,Promise.all([this.loadModel(),v()])];case 1:return t=r.sent(),e=t[0],n=t[1],this.model=e,this.tokenizer=new d(n),[2]}})})},t.prototype.embed=function(t){return a(this,void 0,void 0,function(){var e,n,r,a,s,u,c,l=this;return o(this,function(o){switch(o.label){case 0:for("string"==typeof t&&(t=[t]),e=t.map(function(t){return l.tokenizer.encode(t)}),n=e.map(function(t,e){return t.map(function(t,n){return[e,n]})}),r=[],a=0;a<n.length;a++)r=r.concat(n[a]);return s=Object(i.tensor2d)(r,[r.length,2],"int32"),u=Object(i.tensor1d)(i.util.flatten(e),"int32"),[4,this.model.executeAsync({indices:s,values:u})];case 1:return c=o.sent(),s.dispose(),u.dispose(),[2,c]}})})},t}()},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=l(n(14)),i=l(n(9)),a=l(n(8)),o=l(n(7)),s=l(n(10)),u=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(297)),c=l(n(15));function l(t){return t&&t.__esModule?t:{default:t}}var f={withTokenizer:!1},d=function(){function t(e,n){(0,o.default)(this,t),this.model=null,this.tokenizer=null,this.config={withTokenizer:e.withTokenizer||f.withTokenizer},(0,c.default)(this.loadModel(),n)}return(0,s.default)(t,[{key:"loadModel",value:function(){var t=(0,a.default)(i.default.mark(function t(){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!0!==this.config.withTokenizer){t.next=4;break}return t.next=3,u.loadTokenizer();case 3:this.tokenizer=t.sent;case 4:return t.next=6,u.load();case 6:return this.model=t.sent,t.abrupt("return",this);case 8:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"predict",value:function(t,e){return(0,c.default)(this.predictInternal(t),e)}},{key:"predictInternal",value:function(){var t=(0,a.default)(i.default.mark(function t(e){var n,r;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.model.embed(e);case 3:return n=t.sent,t.next=6,n.array();case 6:return r=t.sent,n.dispose(),t.abrupt("return",r);case 11:return t.prev=11,t.t0=t.catch(0),console.error(t.t0),t.abrupt("return",t.t0);case 15:case"end":return t.stop()}},t,this,[[0,11]])}));return function(e){return t.apply(this,arguments)}}()},{key:"encode",value:function(t,e){return(0,c.default)(this.encodeInternal(t),e)}},{key:"encodeInternal",value:function(){var t=(0,a.default)(i.default.mark(function t(e){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!0!==this.config.withTokenizer){t.next=2;break}return t.abrupt("return",this.tokenizer.encode(e));case 2:return console.error('withTokenizer must be set to true - please pass "withTokenizer:true" as an option in the constructor'),t.abrupt("return",!1);case 4:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()}]),t}();e.default=function(t,e){var n="object"===(void 0===t?"undefined":(0,r.default)(t))?t:{};return new d(n,"function"==typeof t?t:e)}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=d(n(14)),i=d(n(9)),a=d(n(8)),o=d(n(7)),s=d(n(10)),u=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(4)),c=d(n(15)),l=d(n(64)),f=n(46);function d(t){return t&&t.__esModule?t:{default:t}}var h={hosoda:"https://raw.githubusercontent.com/leemengtaiwan/tfjs-models/master/cartoongan/tfjs_json_models/hosoda/model.json",miyazaki:"https://raw.githubusercontent.com/Derek-Wds/training_CartoonGAN/master/tfModels/Miyazaki/model.json"},p=function(){function t(e,n){(0,o.default)(this,t),this.config={modelUrl:e.modelUrl?e.modelUrl:h.miyazaki,returnTensors:!!e.returnTensors&&e.returnTensors},this.model={},this.ready=!1,this.ready=(0,c.default)(this.loadModel(this.config.modelUrl),n)}return(0,s.default)(t,[{key:"loadModel",value:function(){var t=(0,a.default)(i.default.mark(function t(e){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,u.loadGraphModel(e);case 2:return this.model=t.sent,t.abrupt("return",this);case 4:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"generate",value:function(){var t=(0,a.default)(i.default.mark(function t(e,n){var a,o;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(a=void 0,o=n,!(0,f.isInstanceOfSupportedElement)(e)){t.next=6;break}a=e,t.next=20;break;case 6:if("object"!==(void 0===e?"undefined":(0,r.default)(e))||!(0,f.isInstanceOfSupportedElement)(e.elt)){t.next=10;break}a=e.elt,t.next=20;break;case 10:if("object"!==(void 0===e?"undefined":(0,r.default)(e))||!(0,f.isInstanceOfSupportedElement)(e.canvas)){t.next=14;break}a=e.canvas,t.next=20;break;case 14:if("function"!=typeof e){t.next=19;break}a=this.video,o=e,t.next=20;break;case 19:throw new Error("Detection subject not supported");case 20:return t.abrupt("return",(0,c.default)(this.generateInternal(a),o));case 21:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"generateInternal",value:function(){var t=(0,a.default)(i.default.mark(function t(e){var n,r,a,o;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.ready;case 2:return t.next=4,u.nextFrame();case 4:if(256===(n=u.browser.fromPixels(e).resizeBilinear([256,256])).shape[0]&&256===n.shape[1]){t.next=9;break}throw new Error("Input size should be 256*256 but "+n.shape+" is found");case 9:if(3===n.shape[2]){t.next=11;break}throw new Error("Input color channel number should be 3 but "+n.shape[2]+" is found");case 11:if(n=n.sub(127.5).div(127.5).reshape([1,256,256,3]),r=u.ones([256,256,1]).tile([1,1,1]).mul(255),a=(a=(a=this.model.predict(n)).add(1).mul(127.5).reshape([256,256,3]).floor()).concat(r,2),o=this.resultFinalize(a),!this.config.returnTensors){t.next=19;break}return t.abrupt("return",o);case 19:return n.dispose(),a.dispose(),t.abrupt("return",o);case 22:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"resultFinalize",value:function(){var t=(0,a.default)(i.default.mark(function t(e){var n,r,a,o;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=e,t.next=3,e.data();case 3:return r=t.sent,t.next=6,l.default.rawToBlob(r,e.shape[0],e.shape[1]);case 6:return a=t.sent,t.next=9,l.default.blobToP5Image(a);case 9:if(o=t.sent,!this.config.returnTensors){t.next=12;break}return t.abrupt("return",{tensor:n,raw:r,blob:a,image:o});case 12:return t.abrupt("return",{raw:r,blob:a,image:o});case 13:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()}]),t}();e.default=function(t,e){var n="object"===(void 0===t?"undefined":(0,r.default)(t))?t:{},i="function"==typeof t?t:e;return"string"==typeof t&&(n.modelUrl=t),new p(n,i)}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=h(n(7)),i=h(n(10)),a=h(n(208)),o=h(n(9)),s=h(n(8)),u=function(){var t=(0,s.default)(o.default.mark(function t(e){var n,r;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=l.data.csv(e),t.next=3,n.toArray();case 3:return r=t.sent,t.abrupt("return",r);case 5:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}(),c=function(){var t=(0,s.default)(o.default.mark(function t(e){var n,r;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(n=void 0,"string"!=typeof e){t.next=7;break}return t.next=4,u(e);case 4:n=t.sent,t.next=8;break;case 7:n=e;case 8:return r=n.map(function(t){return(0,a.default)(t)}),t.abrupt("return",r);case 10:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}(),l=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(4)),f=h(n(15)),d=n(198);function h(t){return t&&t.__esModule?t:{default:t}}var p={k:3,maxIter:5,threshold:.5},m=function(){function t(e,n,i){(0,r.default)(this,t),this.config={k:n.k||p.k,maxIter:n.maxIter||p.maxIter,threshold:n.threshold||p.threshold},this.ready=(0,f.default)(this.load(e),i)}return(0,i.default)(t,[{key:"load",value:function(){var t=(0,s.default)(o.default.mark(function t(e){var n=this;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,c(e);case 2:return this.dataset=t.sent,l.tidy(function(){n.dataTensor=l.tensor2d(n.dataset),n.dataset.forEach(function(t){var e=l.tensor1d((0,a.default)(t));t.tensor=e}),n.centroids=l.tensor2d((0,d.randomSample)(n.dataset,n.config.k,!1)),n.fit()}),t.abrupt("return",this);case 5:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"fit",value:function(){this.getClosestCentroids(),this.recenterCentroids();for(var e=t.getEuclidianDistance(this.centroids,this.centroidsOld),n=0;e>this.config.threshold&&n<this.config.maxIter;)this.getClosestCentroids(),this.recenterCentroids(),e=t.getEuclidianDistance(this.centroids,this.centroidsOld),n+=1}},{key:"getClosestCentroids",value:function(){var t=this;this.dataset.forEach(function(e){var n=t.closestCentroid(e.tensor);e.centroid=n})}},{key:"closestCentroid",value:function(t){var e=this;return l.tidy(function(){return e.centroids.squaredDifference(t).sum(1).sqrt().argMin().arraySync()})}},{key:"classify",value:function(t){var e=this;return l.tidy(function(){var n=l.tensor1d((0,a.default)(t));return e.closestCentroid(n)})}},{key:"recenterCentroids",value:function(){var t=this,e=l.tidy(function(){return t.centroidsOld=t.centroids,l.stack(t.centroids.unstack().map(function(e,n){var r=t.dataset.filter(function(t){return t.centroid===n}).map(function(t){return t.tensor});return 0===r.length?e:1===r.length?r[0]:l.tidy(function(){return l.stack(r).mean(0)})}))});this.centroids=e}}],[{key:"getEuclidianDistance",value:function(t,e){return l.tidy(function(){return l.squaredDifference(t,e).sum().sqrt().dataSync()})[0]}}]),t}();e.default=function(t,e,n){return new m(t,e,n)}},function(t,e){},function(t,e){},function(t,e){},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=m(n(89)),i=m(n(24)),a=m(n(14)),o=m(n(9)),s=m(n(54)),u=m(n(8)),c=m(n(7)),l=m(n(10)),f=p(n(4)),d=p(n(290)),h=m(n(15));function p(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}function m(t){return t&&t.__esModule?t:{default:t}}var g={withLandmarks:!0,withDescriptors:!0,minConfidence:.5,withTinyNet:!0,MODEL_URLS:{Mobilenetv1Model:"https://raw.githubusercontent.com/ml5js/ml5-data-and-models/main/models/faceapi/ssd_mobilenetv1_model-weights_manifest.json",TinyFaceDetectorModel:"https://raw.githubusercontent.com/ml5js/ml5-data-and-models/main/models/faceapi/tiny_face_detector_model-weights_manifest.json",FaceLandmarkModel:"https://raw.githubusercontent.com/ml5js/ml5-data-and-models/main/models/faceapi/face_landmark_68_model-weights_manifest.json",FaceLandmark68TinyNet:"https://raw.githubusercontent.com/ml5js/ml5-data-and-models/main/models/faceapi/face_landmark_68_tiny_model-weights_manifest.json",FaceRecognitionModel:"https://raw.githubusercontent.com/ml5js/ml5-data-and-models/main/models/faceapi/face_recognition_model-weights_manifest.json"}},v=function(){function t(e,n,r){(0,c.default)(this,t),this.video=e,this.model=null,this.modelReady=!1,this.detectorOptions=null,this.config={minConfidence:this.checkUndefined(n.minConfidence,g.minConfidence),withLandmarks:this.checkUndefined(n.withLandmarks,g.withLandmarks),withDescriptors:this.checkUndefined(n.withDescriptors,g.withDescriptors),withTinyNet:this.checkUndefined(n.withTinyNet,g.withTinyNet),MODEL_URLS:{Mobilenetv1Model:this.checkUndefined(n.Mobilenetv1Model,g.MODEL_URLS.Mobilenetv1Model),TinyFaceDetectorModel:this.checkUndefined(n.TinyFaceDetectorModel,g.MODEL_URLS.TinyFaceDetectorModel),FaceLandmarkModel:this.checkUndefined(n.FaceLandmarkModel,g.MODEL_URLS.FaceLandmarkModel),FaceLandmark68TinyNet:this.checkUndefined(n.FaceLandmark68TinyNet,g.MODEL_URLS.FaceLandmark68TinyNet),FaceRecognitionModel:this.checkUndefined(n.FaceRecognitionModel,g.MODEL_URLS.FaceRecognitionModel)}},this.ready=(0,h.default)(this.loadModel(),r)}return(0,l.default)(t,[{key:"loadModel",value:function(){var t=(0,u.default)(o.default.mark(function t(){var e,n,r,i,a,u,c,l=this;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e=["Mobilenetv1Model","TinyFaceDetectorModel","FaceLandmarkModel","FaceLandmark68TinyNet","FaceRecognitionModel"],(0,s.default)(this.config.MODEL_URLS).forEach(function(t){e.includes(t)&&(l.config.MODEL_URLS[t]=l.getModelPath(l.config.MODEL_URLS[t]))}),n=this.config.MODEL_URLS,r=n.Mobilenetv1Model,i=n.TinyFaceDetectorModel,a=n.FaceLandmarkModel,u=n.FaceRecognitionModel,c=n.FaceLandmark68TinyNet,this.model=d,!0===this.config.withTinyNet?this.detectorOptions=new d.TinyFaceDetectorOptions({minConfidence:this.minConfidence,inputSize:512}):this.detectorOptions=new d.SsdMobilenetv1Options({minConfidence:this.minConfidence}),!0!==this.config.withTinyNet){t.next=12;break}return t.next=8,this.model.loadFaceLandmarkTinyModel(c);case 8:return t.next=10,this.model.loadTinyFaceDetectorModel(i);case 10:t.next=16;break;case 12:return t.next=14,this.model.loadFaceLandmarkModel(a);case 14:return t.next=16,this.model.loadSsdMobilenetv1Model(r);case 16:return t.next=18,this.model.loadFaceRecognitionModel(u);case 18:return this.modelReady=!0,t.abrupt("return",this);case 20:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"detect",value:function(){var t=(0,u.default)(o.default.mark(function t(e,n,r){var i,s,u;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(i=this.video,s=void 0,u=this.config,"function"!=typeof e){t.next=8;break}i=this.video,s=e,t.next=22;break;case 8:if(!(e instanceof HTMLImageElement||e instanceof HTMLCanvasElement||e instanceof HTMLVideoElement||e instanceof ImageData)){t.next=12;break}i=e,t.next=22;break;case 12:if("object"!==(void 0===e?"undefined":(0,a.default)(e))||!(e.elt instanceof HTMLImageElement||e.elt instanceof HTMLCanvasElement||e.elt instanceof HTMLVideoElement||e.elt instanceof ImageData)){t.next=16;break}i=e.elt,t.next=22;break;case 16:if(!("object"===(void 0===e?"undefined":(0,a.default)(e))&&e.canvas instanceof HTMLCanvasElement)){t.next=20;break}i=e.canvas,t.next=22;break;case 20:if(this.video instanceof HTMLVideoElement){t.next=22;break}throw new Error("No input image provided. If you want to classify a video, pass the video element in the constructor. ");case 22:return"object"===(void 0===n?"undefined":(0,a.default)(n))?u=n:"function"==typeof n&&(s=n),"function"==typeof r&&(s=r),t.abrupt("return",(0,h.default)(this.detectInternal(i,u),s));case 25:case"end":return t.stop()}},t,this)}));return function(e,n,r){return t.apply(this,arguments)}}()},{key:"detectInternal",value:function(){var t=(0,u.default)(o.default.mark(function t(e,n){var r,a,s,u,c=this;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.ready;case 2:return t.next=4,f.nextFrame();case 4:if(!this.video||0!==this.video.readyState){t.next=7;break}return t.next=7,new i.default(function(t){c.video.onloadeddata=function(){return t()}});case 7:if(this.config=this.setReturnOptions(n),r=this.config,a=r.withLandmarks,s=r.withDescriptors,u=void 0,!a){t.next=22;break}if(!s){t.next=17;break}return t.next=14,this.model.detectAllFaces(e,this.detectorOptions).withFaceLandmarks(this.config.withTinyNet).withFaceDescriptors();case 14:u=t.sent,t.next=20;break;case 17:return t.next=19,this.model.detectAllFaces(e,this.detectorOptions).withFaceLandmarks(this.config.withTinyNet);case 19:u=t.sent;case 20:t.next=31;break;case 22:if(a){t.next=28;break}return t.next=25,this.model.detectAllFaces(e);case 25:u=t.sent,t.next=31;break;case 28:return t.next=30,this.model.detectAllFaces(e,this.detectorOptions).withFaceLandmarks(this.config.withTinyNet).withFaceDescriptors();case 30:u=t.sent;case 31:return u=this.resizeResults(u,e.width,e.height),u=this.landmarkParts(u),t.abrupt("return",u);case 34:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"detectSingle",value:function(){var t=(0,u.default)(o.default.mark(function t(e,n,r){var i,s,u;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(i=this.video,s=void 0,u=this.config,"function"!=typeof e){t.next=8;break}i=this.video,s=e,t.next=22;break;case 8:if(!(e instanceof HTMLImageElement||e instanceof HTMLCanvasElement||e instanceof HTMLVideoElement||e instanceof ImageData)){t.next=12;break}i=e,t.next=22;break;case 12:if("object"!==(void 0===e?"undefined":(0,a.default)(e))||!(e.elt instanceof HTMLImageElement||e.elt instanceof HTMLCanvasElement||e.elt instanceof HTMLVideoElement||e.elt instanceof ImageData)){t.next=16;break}i=e.elt,t.next=22;break;case 16:if(!("object"===(void 0===e?"undefined":(0,a.default)(e))&&e.canvas instanceof HTMLCanvasElement)){t.next=20;break}i=e.canvas,t.next=22;break;case 20:if(this.video instanceof HTMLVideoElement){t.next=22;break}throw new Error("No input image provided. If you want to classify a video, pass the video element in the constructor. ");case 22:return"object"===(void 0===n?"undefined":(0,a.default)(n))?u=n:"function"==typeof n&&(s=n),"function"==typeof r&&(s=r),t.abrupt("return",(0,h.default)(this.detectSingleInternal(i,u),s));case 25:case"end":return t.stop()}},t,this)}));return function(e,n,r){return t.apply(this,arguments)}}()},{key:"detectSingleInternal",value:function(){var t=(0,u.default)(o.default.mark(function t(e,n){var r,a,s,u,c=this;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.ready;case 2:return t.next=4,f.nextFrame();case 4:if(!this.video||0!==this.video.readyState){t.next=7;break}return t.next=7,new i.default(function(t){c.video.onloadeddata=function(){return t()}});case 7:if(this.config=this.setReturnOptions(n),r=this.config,a=r.withLandmarks,s=r.withDescriptors,u=void 0,!a){t.next=22;break}if(!s){t.next=17;break}return t.next=14,this.model.detectSingleFace(e,this.detectorOptions).withFaceLandmarks(this.config.withTinyNet).withFaceDescriptor();case 14:u=t.sent,t.next=20;break;case 17:return t.next=19,this.model.detectSingleFace(e,this.detectorOptions).withFaceLandmarks(this.config.withTinyNet);case 19:u=t.sent;case 20:t.next=31;break;case 22:if(a){t.next=28;break}return t.next=25,this.model.detectSingleFace(e);case 25:u=t.sent,t.next=31;break;case 28:return t.next=30,this.model.detectSingleFace(e,this.detectorOptions).withFaceLandmarks(this.config.withTinyNet).withFaceDescriptor();case 30:u=t.sent;case 31:return u=this.resizeResults(u,e.width,e.height),u=this.landmarkParts(u),t.abrupt("return",u);case 34:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"checkUndefined",value:function(t,e){return void 0!==t?t:e}},{key:"getModelPath",value:function(t){return this.isAbsoluteURL(t)?t:window.location.pathname+t}},{key:"setReturnOptions",value:function(t){var e=this,n=(0,r.default)({},this.config);return["withLandmarks","withDescriptors"].forEach(function(r){void 0!==t[r]?e.config[r]=t[r]:n[r]=e.config[r]}),n}},{key:"resizeResults",value:function(t,e,n){if(void 0===e||void 0===n)throw new Error("width and height must be defined");return this.model.resizeResults(t,{width:e,height:n})}},{key:"isAbsoluteURL",value:function(t){return!!new RegExp("^(?:[a-z]+:)?//","i").test(t)}},{key:"landmarkParts",value:function(t){var e=void 0;if(!0===Array.isArray(t))e=t.map(function(t){var e=(0,r.default)({},t);if(e.landmarks){var n=e.landmarks;e.parts={mouth:n.getMouth(),nose:n.getNose(),leftEye:n.getLeftEye(),leftEyeBrow:n.getLeftEyeBrow(),rightEye:n.getRightEye(),rightEyeBrow:n.getRightEyeBrow(),jawOutline:n.getJawOutline()}}else e.parts={mouth:[],nose:[],leftEye:[],leftEyeBrow:[],rightEye:[],rightEyeBrow:[],jawOutline:[]};return e});else if((e=(0,r.default)({},t)).landmarks){var n=t.landmarks;e.parts={mouth:n.getMouth(),nose:n.getNose(),leftEye:n.getLeftEye(),leftEyeBrow:n.getLeftEyeBrow(),rightEye:n.getRightEye(),rightEyeBrow:n.getRightEyeBrow()}}else e.parts={mouth:[],nose:[],leftEye:[],leftEyeBrow:[],rightEye:[],rightEyeBrow:[]};return e}}]),t}();e.default=function(t,e,n){var r=void 0,i={},o=n;t instanceof HTMLVideoElement?r=t:"object"===(void 0===t?"undefined":(0,a.default)(t))&&t.elt instanceof HTMLVideoElement?r=t.elt:"object"===(void 0===t?"undefined":(0,a.default)(t))?i=t:"function"==typeof t&&(o=t),"object"===(void 0===e?"undefined":(0,a.default)(e))?(i=e,console.log(i)):"function"==typeof e&&(o=e);var s=new v(r,i,o);return o?s:s.ready}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=u(n(83)),i=u(n(90)),a=u(n(7)),o=u(n(10)),s=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(243));function u(t){return t&&t.__esModule?t:{default:t}}var c=function(){function t(){(0,a.default)(this,t),this.config={height:300}}return(0,o.default)(t,[{key:"modelSummary",value:function(t,e){var n=(0,i.default)({},t);s.show.modelSummary(n,e)}},{key:"scatterplot",value:function(t,e,n){var r=n.map(function(n){return{x:n.xs[t],y:n.ys[e]}}),i={xLabel:"X",yLabel:"Y",height:this.config.height};s.render.scatterplot({name:"debug mode"},r,i)}},{key:"scatterplotAll",value:function(t,e,n){var i=[];t.forEach(function(t){e.forEach(function(e){var a=n.map(function(n){return{x:n.xs[t],y:n.ys[e]}});i=[].concat((0,r.default)(i),(0,r.default)(a))})});var a={xLabel:"X",yLabel:"Y",height:this.config.height};s.render.scatterplot({name:"debug mode"},i,a)}},{key:"barchart",value:function(t,e,n){var r=n.map(function(n){return{value:n.xs[t],index:n.ys[e]}}),i={xLabel:"label",yLabel:"value",height:this.config.height};console.log(i);s.render.barchart({name:"Bar chart"},r)}},{key:"trainingVis",value:function(){return s.show.fitCallbacks({name:"Training Performance"},["loss","accuracy"],{height:this.config.height,callbacks:["onEpochEnd"]})}}]),t}();e.default=c},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=k(n(14)),i=k(n(47)),a=k(n(24)),o=k(n(99)),s=k(n(9)),u=k(n(8)),c=k(n(203)),l=k(n(199)),f=k(n(83)),d=k(n(200)),h=k(n(54)),p=k(n(89)),m=k(n(90)),g=k(n(7)),v=k(n(10)),y=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(4)),b=k(n(55)),x=n(115),w=k(n(197));function k(t){return t&&t.__esModule?t:{default:t}}var _=function(){function t(){(0,g.default)(this,t),this.meta={inputUnits:null,outputUnits:null,inputs:{},outputs:{},isNormalized:!1},this.isMetadataReady=!1,this.isWarmedUp=!1,this.data={raw:[]},this.createMetadata=this.createMetadata.bind(this),this.getDataStats=this.getDataStats.bind(this),this.getInputMetaStats=this.getInputMetaStats.bind(this),this.getDataUnits=this.getDataUnits.bind(this),this.getInputMetaUnits=this.getInputMetaUnits.bind(this),this.getDTypesFromData=this.getDTypesFromData.bind(this),this.addData=this.addData.bind(this),this.convertRawToTensors=this.convertRawToTensors.bind(this),this.normalizeDataRaw=this.normalizeDataRaw.bind(this),this.normalizeInputData=this.normalizeInputData.bind(this),this.normalizeArray=this.normalizeArray.bind(this),this.unnormalizeArray=this.unnormalizeArray.bind(this),this.applyOneHotEncodingsToDataRaw=this.applyOneHotEncodingsToDataRaw.bind(this),this.getDataOneHot=this.getDataOneHot.bind(this),this.getInputMetaOneHot=this.getInputMetaOneHot.bind(this),this.createOneHotEncodings=this.createOneHotEncodings.bind(this),this.loadDataFromUrl=this.loadDataFromUrl.bind(this),this.loadJSON=this.loadJSON.bind(this),this.loadCSV=this.loadCSV.bind(this),this.loadBlob=this.loadBlob.bind(this),this.loadData=this.loadData.bind(this),this.saveData=this.saveData.bind(this),this.saveMeta=this.saveMeta.bind(this),this.loadMeta=this.loadMeta.bind(this),this.findEntries=this.findEntries.bind(this),this.formatRawData=this.formatRawData.bind(this),this.csvToJSON=this.csvToJSON.bind(this)}return(0,v.default)(t,[{key:"createMetadata",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return this.getDTypesFromData(t),this.getDataStats(t),this.getDataOneHot(t),this.getDataUnits(t,e),this.isMetadataReady=!0,(0,m.default)({},this.meta)}},{key:"getDataStats",value:function(t){var e=(0,p.default)({},this.meta),n=this.getInputMetaStats(t,e.inputs,"xs"),r=this.getInputMetaStats(t,e.outputs,"ys");return e.inputs=n,e.outputs=r,this.meta=(0,m.default)({},this.meta,e),e}},{key:"getInputMetaStats",value:function(t,e,n){var r=(0,p.default)({},e);return(0,h.default)(r).forEach(function(e){if("string"===r[e].dtype)r[e].min=0,r[e].max=1;else if("number"===r[e].dtype){var i=t.map(function(t){return t[n][e]});r[e].min=w.default.getMin(i),r[e].max=w.default.getMax(i)}else if("array"===r[e].dtype){var a=t.map(function(t){return t[n][e]}).flat();r[e].min=w.default.getMin(a),r[e].max=w.default.getMax(a)}}),r}},{key:"getDataUnits",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=null!==e?e:void 0,r=(0,p.default)({},this.meta),i=void 0;i=n||[this.getInputMetaUnits(t,r.inputs)].flat();var a=this.getInputMetaUnits(t,r.outputs);return r.inputUnits=i,r.outputUnits=a,this.meta=(0,m.default)({},this.meta,r),r}},{key:"getInputMetaUnits",value:function(t,e){var n=0,r=(0,p.default)({},e);return(0,d.default)(r).forEach(function(t){var e=t[1].dtype;if("number"===e)n+=1;else if("string"===e){var r=t[1].uniqueValues.length;n+=r}else"array"===e&&(n=[])}),n}},{key:"getDTypesFromData",value:function(t){var e=(0,m.default)({},this.meta,{inputs:{},outputs:{}}),n=t[0],r=(0,h.default)(n.xs),i=(0,h.default)(n.ys);return r.forEach(function(t){e.inputs[t]={dtype:w.default.getDataType(n.xs[t])}}),i.forEach(function(t){e.outputs[t]={dtype:w.default.getDataType(n.ys[t])}}),this.meta=e,e}},{key:"addData",value:function(t,e){this.data.raw.push({xs:t,ys:e})}},{key:"convertRawToTensors",value:function(t){var e=(0,p.default)({},this.meta),n=t.length;return y.tidy(function(){var r=[],i=[];return t.forEach(function(t){var n=(0,h.default)(e.inputs).map(function(e){return t.xs[e]}).flat();r.push(n);var a=(0,h.default)(e.outputs).map(function(e){return t.ys[e]}).flat();i.push(a)}),{inputs:y.tensor(r.flat(),[n].concat((0,f.default)(e.inputUnits))),outputs:y.tensor(i.flat(),[n,e.outputUnits])}})}},{key:"normalizeDataRaw",value:function(t){var e=(0,p.default)({},this.meta),n=this.normalizeInputData(t,e.inputs,"xs"),r=this.normalizeInputData(t,e.outputs,"ys");return w.default.zipArrays(n,r)}},{key:"normalizeInputData",value:function(t,e,n){var r=this,i=t.length,a=(0,p.default)({},e),o={};return(0,h.default)(a).forEach(function(e){var i={min:a[e].min,max:a[e].max},s=t.map(function(t){return t[n][e]});"string"===a[e].dtype?(i.legend=a[e].legend,o[e]=r.normalizeArray(s,i)):"number"===a[e].dtype?o[e]=r.normalizeArray(s,i):"array"===a[e].dtype&&(o[e]=s.map(function(t){return r.normalizeArray(t,i)}))}),[].concat((0,f.default)(new Array(i).fill(null))).map(function(t,e){var r=(0,l.default)({},n,{});return(0,h.default)(a).forEach(function(t){r[n][t]=o[t][e]}),r})}},{key:"normalizeArray",value:function(t,e){var n=e.min,r=e.max;if(e.legend)return t.map(function(t){return e.legend[t]?e.legend[t]:t});if(t.every(function(t){return"number"==typeof t}))return t.map(function(t){return w.default.normalizeValue(t,n,r)});throw new Error("error in inputArray of normalizeArray() function")}},{key:"unnormalizeArray",value:function(t,e){var n=e.min,r=e.max;if(e.legend)return t.map(function(t){var n=void 0;return(0,d.default)(e.legend).forEach(function(e){var r=e[0],i=e[1];t.map(function(t,e){return t===i[e]}).every(function(t){return!0===t})&&(n=r)}),n});if(t.every(function(t){return"number"==typeof t}))return t.map(function(t){return w.default.unnormalizeValue(t,n,r)});throw new Error("error in inputArray of normalizeArray() function")}},{key:"applyOneHotEncodingsToDataRaw",value:function(t){var e=(0,p.default)({},this.meta);return t.map(function(t){var n=(0,m.default)({},t.xs),r=(0,m.default)({},t.ys);return(0,h.default)(e.inputs).forEach(function(r){e.inputs[r].legend&&(n[r]=e.inputs[r].legend[t.xs[r]])}),(0,h.default)(e.outputs).forEach(function(n){e.outputs[n].legend&&(r[n]=e.outputs[n].legend[t.ys[n]])}),{xs:n,ys:r}})}},{key:"getDataOneHot",value:function(t){var e=(0,p.default)({},this.meta),n=this.getInputMetaOneHot(t,e.inputs,"xs"),r=this.getInputMetaOneHot(t,e.outputs,"ys");return e.inputs=n,e.outputs=r,this.meta=(0,m.default)({},this.meta,e),e}},{key:"getInputMetaOneHot",value:function(t,e,n){var r=this,i=(0,p.default)({},e);return(0,d.default)(i).forEach(function(e){var a=e[0];if("string"===e[1].dtype){var o=[].concat((0,f.default)(new c.default(t.map(function(t){return t[n][a]})))),s=r.createOneHotEncodings(o);i[a]=(0,m.default)({},i[a],s)}}),i}},{key:"createOneHotEncodings",value:function(t){return y.tidy(function(){var e={uniqueValues:t,legend:{}},n=t,r=n.map(function(t,e){return e}),i=y.oneHot(y.tensor1d(r,"int32"),n.length).arraySync();return n.forEach(function(t,n){e.legend[t]=i[n]}),e})}},{key:"loadDataFromUrl",value:function(){var t=(0,u.default)(s.default.mark(function t(e,n,r){var i;return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(t.prev=0,i=void 0,!e.endsWith(".csv")){t.next=8;break}return t.next=5,this.loadCSV(e,n,r);case 5:i=t.sent,t.next=21;break;case 8:if(!e.endsWith(".json")){t.next=14;break}return t.next=11,this.loadJSON(e,n,r);case 11:i=t.sent,t.next=21;break;case 14:if(!e.includes("blob")){t.next=20;break}return t.next=17,this.loadBlob(e,n,r);case 17:i=t.sent,t.next=21;break;case 20:throw new Error("Not a valid data format. Must be csv or json");case 21:return t.abrupt("return",i);case 24:throw t.prev=24,t.t0=t.catch(0),console.error(t.t0),new Error(t.t0);case 28:case"end":return t.stop()}},t,this,[[0,24]])}));return function(e,n,r){return t.apply(this,arguments)}}()},{key:"loadJSON",value:function(){var t=(0,u.default)(s.default.mark(function t(e,n,r){var i,a,o,u;return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(t.prev=0,i=void 0,!(e instanceof Object)){t.next=6;break}i=(0,p.default)({},e),t.next=11;break;case 6:return t.next=8,b.default.get(e);case 8:a=t.sent,o=a.data,i=o;case 11:return u=this.formatRawData(i,n,r),t.abrupt("return",u);case 15:throw t.prev=15,t.t0=t.catch(0),console.error("error loading json"),new Error(t.t0);case 19:case"end":return t.stop()}},t,this,[[0,15]])}));return function(e,n,r){return t.apply(this,arguments)}}()},{key:"loadCSV",value:function(){var t=(0,u.default)(s.default.mark(function t(e,n,r){var i,a,o,u;return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,i=y.data.csv(e),t.next=4,i.toArray();case 4:return a=t.sent,o={entries:a},u=this.formatRawData(o,n,r),t.abrupt("return",u);case 10:throw t.prev=10,t.t0=t.catch(0),console.error("error loading csv",t.t0),new Error(t.t0);case 14:case"end":return t.stop()}},t,this,[[0,10]])}));return function(e,n,r){return t.apply(this,arguments)}}()},{key:"loadBlob",value:function(){var t=(0,u.default)(s.default.mark(function t(e,n,r){var i,a,o,u,c,l;return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,b.default.get(e);case 3:if(i=t.sent,a=i.data,o=a,u=void 0,!w.default.isJsonOrString(o)){t.next=14;break}return c=JSON.parse(o),t.next=11,this.loadJSON(c,n,r);case 11:u=t.sent,t.next=18;break;case 14:return l=this.csvToJSON(o),t.next=17,this.loadJSON(l,n,r);case 17:u=t.sent;case 18:return t.abrupt("return",u);case 21:throw t.prev=21,t.t0=t.catch(0),console.log("mmm might be passing in a string or something!",t.t0),new Error(t.t0);case 25:case"end":return t.stop()}},t,this,[[0,21]])}));return function(e,n,r){return t.apply(this,arguments)}}()},{key:"loadData",value:function(){var t=(0,u.default)(s.default.mark(function t(){var e,n,r,i,a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,u=arguments[1];return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(t.prev=0,e=void 0,"string"==typeof a){t.next=16;break}if(n=a[0],(new FileReader).readAsText(n),!n.name.includes(".json")){t.next=13;break}return t.next=9,n.text();case 9:r=t.sent,e=JSON.parse(r),t.next=14;break;case 13:console.log('data must be a json object containing an array called "data" or "entries');case 14:t.next=21;break;case 16:return t.next=18,b.default.get(a,{responseType:"text"});case 18:e=t.sent,i=(0,o.default)(e.data),w.default.isJsonOrString(i)?e=JSON.parse(i):console.log("Whoops! something went wrong. Either this kind of data is not supported yet or there is an issue with .loadData");case 21:this.data.raw=this.findEntries(e),!this.data.raw.length>0&&console.log('data must be a json object containing an array called "data" '),u&&u(),t.next=29;break;case 26:throw t.prev=26,t.t0=t.catch(0),new Error(t.t0);case 29:case"end":return t.stop()}},t,this,[[0,26]])}));return function(){return t.apply(this,arguments)}}()},{key:"saveData",value:function(){var t=(0,u.default)(s.default.mark(function t(e){var n,r,i,a,u;return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=new Date,r=String(n.getFullYear())+"-"+String(n.getMonth()+1)+"-"+String(n.getDate()),i=String(n.getHours())+"-"+String(n.getMinutes())+"-"+String(n.getSeconds()),a=r+"_"+i,e&&(a=e),u={data:this.data.raw},t.next=9,(0,x.saveBlob)((0,o.default)(u),a+".json","text/plain");case 9:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"saveMeta",value:function(){var t=(0,u.default)(s.default.mark(function t(e,n){var r,i;return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=void 0,i=void 0,"function"==typeof e?(r="model",i=e):"string"==typeof e?(r=e,"function"==typeof n&&(i=n)):r="model",t.next=5,(0,x.saveBlob)((0,o.default)(this.meta),r+"_meta.json","text/plain");case 5:i&&i();case 6:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"loadMeta",value:function(){var t=(0,u.default)(s.default.mark(function t(){var e,n,r,c,l,f=this,d=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,h=arguments[1];return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!(d instanceof FileList)){t.next=8;break}return t.next=3,a.default.all((0,i.default)(d).map(function(){var t=(0,u.default)(s.default.mark(function t(e){var n;return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!e.name.includes(".json")||e.name.includes("_meta")){t.next=4;break}return t.abrupt("return",{name:"model",file:e});case 4:if(!e.name.includes(".json")||!e.name.includes("_meta.json")){t.next=11;break}return t.next=7,e.text();case 7:return n=t.sent,t.abrupt("return",{name:"metadata",file:n});case 11:if(!e.name.includes(".bin")){t.next=13;break}return t.abrupt("return",{name:"weights",file:e});case 13:return t.abrupt("return",{name:null,file:null});case 14:case"end":return t.stop()}},t,f)}));return function(e){return t.apply(this,arguments)}}()));case 3:e=t.sent,n=JSON.parse(e.find(function(t){return"metadata"===t.name}).file),this.meta=n,t.next=23;break;case 8:if(!(d instanceof Object)){t.next=17;break}return t.next=11,b.default.get(d.metadata,{responseType:"text"});case 11:r=t.sent,r=(0,o.default)(r.data),r=JSON.parse(r),this.meta=r,t.next=23;break;case 17:return c=d.substring(0,d.lastIndexOf("/"))+"/model_meta.json",t.next=20,b.default.get(c);case 20:l=(l=t.sent).data,this.meta=l;case 23:return this.isMetadataReady=!0,this.isWarmedUp=!0,h&&h(),t.abrupt("return",this.meta);case 27:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"formatRawData",value:function(t,e,n){var r=this.findEntries(t);!r.length>0&&console.log("your data must be contained in an array in \n\n a property called 'entries' or 'data' of your json object");var i=r.map(function(t,r){var i={xs:{},ys:{}};return e.forEach(function(e){void 0!==t[e]?i.xs[e]=t[e]:console.error("the input label "+e+" does not exist at row "+r)}),n.forEach(function(e){void 0!==t[e]?i.ys[e]=t[e]:console.error("the output label "+e+" does not exist at row "+r)}),i});return this.data.raw=i,i}},{key:"csvToJSON",value:function(t){for(var e=t.split("\n"),n=[],r=e[0].split(","),i=function(t){var i={},a=e[t].split(",");r.forEach(function(t,e){i[t]=a[e]}),n.push(i)},a=1;a<e.length;a+=1)i(a);return{entries:n}}},{key:"findEntries",value:function(t){var e=this,n=(0,p.default)({},t);return n.entries&&n.entries instanceof Array?n.entries:n.data&&n.data instanceof Array?n.data:((0,h.default)(n).forEach(function(t){if("object"===(0,r.default)(n[t]))return e.findEntries(n[t])}),n)}}]),t}();e.default=_},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=m(n(47)),i=m(n(24)),a=m(n(99)),o=m(n(9)),s=m(n(8)),u=m(n(7)),c=m(n(10)),l=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(4)),f=m(n(55)),d=m(n(15)),h=n(115),p=n(198);function m(t){return t&&t.__esModule?t:{default:t}}var g=function(){function t(){(0,u.default)(this,t),this.isTrained=!1,this.isCompiled=!1,this.isLayered=!1,this.model=null,this.init=this.init.bind(this),this.createModel=this.createModel.bind(this),this.addLayer=this.addLayer.bind(this),this.compile=this.compile.bind(this),this.setOptimizerFunction=this.setOptimizerFunction.bind(this),this.train=this.train.bind(this),this.trainInternal=this.trainInternal.bind(this),this.predict=this.predict.bind(this),this.classify=this.classify.bind(this),this.save=this.save.bind(this),this.load=this.load.bind(this),this.init()}return(0,c.default)(t,[{key:"init",value:function(){this.createModel()}},{key:"createModel",value:function(){switch((arguments.length>0&&void 0!==arguments[0]?arguments[0]:"sequential").toLowerCase()){case"sequential":default:return this.model=l.sequential(),this.model}}},{key:"addLayer",value:function(t){var e=t||{};this.model.add(e),this.model.layers.length>=2&&(this.isLayered=!0)}},{key:"compile",value:function(t){this.model.compile(t),this.isCompiled=!0}},{key:"setOptimizerFunction",value:function(t,e){return e.call(this,t)}},{key:"train",value:function(t,e){return(0,d.default)(this.trainInternal(t),e)}},{key:"trainInternal",value:function(){var t=(0,s.default)(o.default.mark(function t(e){var n,r,i,a,s,u,c,l;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=(n=e).inputs,i=n.outputs,a=n.batchSize,s=n.epochs,u=n.shuffle,c=n.validationSplit,l=n.whileTraining,t.next=6,this.model.fit(r,i,{batchSize:a,epochs:s,shuffle:u,validationSplit:c,callbacks:l});case 6:r.dispose(),i.dispose(),this.isTrained=!0;case 9:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"predictSync",value:function(t){var e=this,n=l.tidy(function(){return e.model.predict(t)}),r=n.arraySync();return n.dispose(),t.dispose(),r}},{key:"predict",value:function(){var t=(0,s.default)(o.default.mark(function t(e){var n,r,i=this;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=l.tidy(function(){return i.model.predict(e)}),t.next=3,n.array();case 3:return r=t.sent,n.dispose(),e.dispose(),t.abrupt("return",r);case 7:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"classify",value:function(){var t=(0,s.default)(o.default.mark(function t(e){return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.predict(e));case 1:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"classifySync",value:function(t){return this.predictSync(t)}},{key:"save",value:function(){var t=(0,s.default)(o.default.mark(function t(e,n){var r,i,u=this;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:r=void 0,i=void 0,"function"==typeof e?(r="model",i=e):"string"==typeof e?(r=e,"function"==typeof n&&(i=n)):r="model",this.model.save(l.io.withSaveHandler(function(){var t=(0,s.default)(o.default.mark(function t(e){return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return u.weightsManifest={modelTopology:e.modelTopology,weightsManifest:[{paths:["./"+r+".weights.bin"],weights:e.weightSpecs}]},t.next=3,(0,h.saveBlob)(e.weightData,r+".weights.bin","application/octet-stream");case 3:return t.next=5,(0,h.saveBlob)((0,a.default)(u.weightsManifest),r+".json","text/plain");case 5:i&&i();case 6:case"end":return t.stop()}},t,u)}));return function(e){return t.apply(this,arguments)}}()));case 4:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"load",value:function(){var t=(0,s.default)(o.default.mark(function t(){var e,n,u,c,d,h,p,m,g,v=this,y=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,b=arguments[1];return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!(y instanceof FileList)){t.next=11;break}return t.next=3,i.default.all((0,r.default)(y).map(function(){var t=(0,s.default)(o.default.mark(function t(e){var n;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!e.name.includes(".json")||e.name.includes("_meta")){t.next=4;break}return t.abrupt("return",{name:"model",file:e});case 4:if(!e.name.includes(".json")||!e.name.includes("_meta.json")){t.next=11;break}return t.next=7,e.text();case 7:return n=t.sent,t.abrupt("return",{name:"metadata",file:n});case 11:if(!e.name.includes(".bin")){t.next=13;break}return t.abrupt("return",{name:"weights",file:e});case 13:return t.abrupt("return",{name:null,file:null});case 14:case"end":return t.stop()}},t,v)}));return function(e){return t.apply(this,arguments)}}()));case 3:return e=t.sent,n=e.find(function(t){return"model"===t.name}).file,u=e.find(function(t){return"weights"===t.name}).file,t.next=8,l.loadLayersModel(l.io.browserFiles([n,u]));case 8:this.model=t.sent,t.next=30;break;case 11:if(!(y instanceof Object)){t.next=27;break}return t.next=14,f.default.get(y.model,{responseType:"text"});case 14:return c=t.sent,d=(0,a.default)(c.data),h=new File([d],"model.json",{type:"application/json"}),t.next=19,f.default.get(y.weights,{responseType:"blob"});case 19:return p=t.sent,m=p.data,g=new File([m],"model.weights.bin",{type:"application/macbinary"}),t.next=24,l.loadLayersModel(l.io.browserFiles([h,g]));case 24:this.model=t.sent,t.next=30;break;case 27:return t.next=29,l.loadLayersModel(y);case 29:this.model=t.sent;case 30:return this.isCompiled=!0,this.isLayered=!0,this.isTrained=!0,b&&b(),t.abrupt("return",this.model);case 35:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"dispose",value:function(){this.model.dispose()}},{key:"mutate",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:.1,n=arguments[1];l.tidy(function(){for(var r=t.model.getWeights(),i=[],a=0;a<r.length;a+=1){for(var o=r[a],s=r[a].shape,u=o.dataSync().slice(),c=0;c<u.length;c+=1)Math.random()<e&&(u[c]=n?n(u[c]):Math.min(Math.max(u[c]+(0,p.randomGaussian)(),-1),1));var f=l.tensor(u,s);i[a]=f}t.model.setWeights(i)})}},{key:"crossover",value:function(t){var e=this;return l.tidy(function(){for(var n=e.model.getWeights(),r=t.model.getWeights(),i=[],a=0;a<n.length;a+=1){for(var o=n[a],s=r[a],u=n[a].shape,c=o.dataSync().slice(),f=s.dataSync().slice(),d=0;d<c.length;d+=1)Math.random()<.5&&(c[d]=f[d]);var h=l.tensor(c,u);i[a]=h}e.model.setWeights(i)})}}]),t}();e.default=g},function(t,e,n){var r=n(23),i=n(207)(!0);r(r.S,"Object",{entries:function(t){return i(t)}})},function(t,e,n){n(308),t.exports=n(18).Object.entries},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=k(n(200)),i=k(n(47)),a=k(n(199)),o=k(n(83)),s=k(n(89)),u=k(n(9)),c=k(n(8)),l=k(n(54)),f=k(n(14)),d=k(n(90)),h=k(n(7)),p=k(n(10)),m=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(4)),g=k(n(307)),v=k(n(306)),y=k(n(305)),b=k(n(15)),x=k(n(197)),w=n(46);function k(t){return t&&t.__esModule?t:{default:t}}var _={inputs:[],outputs:[],dataUrl:null,modelUrl:null,layers:[],task:null,debug:!1,learningRate:.2,hiddenUnits:16,noTraining:!1},E=function(){function t(e,n){(0,h.default)(this,t),this.callback=n,"imageClassification"===e.task&&(_.learningRate=.02),this.options=(0,d.default)({},_,e)||_,this.neuralNetwork=new g.default,this.neuralNetworkData=new v.default,this.neuralNetworkVis=new y.default,this.data={training:[]},this.ready=!1,this.init=this.init.bind(this),this.addData=this.addData.bind(this),this.loadDataFromUrl=this.loadDataFromUrl.bind(this),this.loadDataInternal=this.loadDataInternal.bind(this),this.createMetaData=this.createMetaData.bind(this),this.prepareForTraining=this.prepareForTraining.bind(this),this.normalizeData=this.normalizeData.bind(this),this.normalizeInput=this.normalizeInput.bind(this),this.searchAndFormat=this.searchAndFormat.bind(this),this.formatInputItem=this.formatInputItem.bind(this),this.convertTrainingDataToTensors=this.convertTrainingDataToTensors.bind(this),this.formatInputsForPrediction=this.formatInputsForPrediction.bind(this),this.formatInputsForPredictionAll=this.formatInputsForPredictionAll.bind(this),this.isOneHotEncodedOrNormalized=this.isOneHotEncodedOrNormalized.bind(this),this.train=this.train.bind(this),this.trainInternal=this.trainInternal.bind(this),this.addLayer=this.addLayer.bind(this),this.createNetworkLayers=this.createNetworkLayers.bind(this),this.addDefaultLayers=this.addDefaultLayers.bind(this),this.compile=this.compile.bind(this),this.predict=this.predict.bind(this),this.predictMultiple=this.predictMultiple.bind(this),this.classify=this.classify.bind(this),this.classifyMultiple=this.classifyMultiple.bind(this),this.predictInternal=this.predictInternal.bind(this),this.classifyInternal=this.classifyInternal.bind(this),this.saveData=this.saveData.bind(this),this.loadData=this.loadData.bind(this),this.save=this.save.bind(this),this.load=this.load.bind(this),this.dispose=this.dispose.bind(this),this.mutate=this.mutate.bind(this),this.crossover=this.crossover.bind(this),this.init(this.callback)}return(0,p.default)(t,[{key:"init",value:function(t){!0===this.options.noTraining&&this.createLayersNoTraining(),null!==this.options.dataUrl?this.ready=this.loadDataFromUrl(this.options,t):null!==this.options.modelUrl?this.ready=this.load(this.options.modelUrl,t):this.ready=!0}},{key:"createLayersNoTraining",value:function(){var t=this.options,e=t.inputs,n=t.outputs;if("classification"===t.task)for(var r=0;r<n.length;r+=1){var i=new Array(e).fill(0);this.addData(i,[n[r]])}else{var a=new Array(e).fill(0),o=new Array(n).fill(0);this.addData(a,o)}this.neuralNetworkData.createMetadata(this.neuralNetworkData.data.raw),this.addDefaultLayers(this.options.task,this.neuralNetworkData.meta)}},{key:"copy",value:function(){var e=this,n=new t(this.options);return m.tidy(function(){for(var t=e.neuralNetwork.model.getWeights(),r=[],i=0;i<t.length;i+=1)r[i]=t[i].clone();return n.neuralNetwork.model.setWeights(r),n})}},{key:"addData",value:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=this.options,i=r.inputs,a=r.outputs,o=void 0,s=void 0;if(null!==n?(o=n.inputLabels,s=n.outputLabels):i.length>0&&a.length>0?(i.every(function(t){return"string"==typeof t})&&(o=i),a.every(function(t){return"string"==typeof t})&&(s=a)):"object"===(void 0===t?"undefined":(0,f.default)(t))&&"object"===(void 0===e?"undefined":(0,f.default)(e))?(o=(0,l.default)(t),s=(0,l.default)(e)):(o=x.default.createLabelsFromArrayValues(t,"input"),s=x.default.createLabelsFromArrayValues(e,"output")),!(o instanceof Array))throw new Error("inputLabels must be an array");if(!(s instanceof Array))throw new Error("outputLabels must be an array");var u=this.searchAndFormat(t),c=x.default.formatDataAsObject(u,o),d=x.default.formatDataAsObject(e,s);this.neuralNetworkData.addData(c,d)}},{key:"loadDataFromUrl",value:function(t,e){return(0,b.default)(this.loadDataInternal(t),e)}},{key:"loadDataInternal",value:function(){var t=(0,c.default)(u.default.mark(function t(e){var n,r,i,a;return u.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=e.dataUrl,r=e.inputs,i=e.outputs,t.next=3,this.neuralNetworkData.loadDataFromUrl(n,r,i);case 3:a=t.sent,this.createMetadata(a),this.prepareForTraining(a);case 6:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"createMetaData",value:function(t){var e=this.options.inputs,n=void 0;Array.isArray(e)&&e.length>0&&(n=e.every(function(t){return"number"==typeof t})&&e.length>0?e:null),this.neuralNetworkData.createMetadata(t,n)}},{key:"prepareForTraining",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e=null===t?this.neuralNetworkData.data.raw:t,n=this.neuralNetworkData.applyOneHotEncodingsToDataRaw(e);return this.data.training=n,this.neuralNetworkData.isWarmedUp=!0,n}},{key:"normalizeData",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e=null===t?this.neuralNetworkData.data.raw:t;this.neuralNetworkData.isMetadataReady||this.createMetaData(e),this.neuralNetworkData.isWarmedUp||this.prepareForTraining(e);var n=this.neuralNetworkData.normalizeDataRaw(e);return this.data.training=n,this.neuralNetworkData.meta.isNormalized=!0,n}},{key:"normalizeInput",value:function(t,e,n){var r=n[e],i=r.min,a=r.max;return x.default.normalizeValue(t,i,a)}},{key:"searchAndFormat",value:function(t){var e=this,n=void 0;if(Array.isArray(t))n=t.map(function(t){return e.formatInputItem(t)});else if("object"===(void 0===t?"undefined":(0,f.default)(t))){var r=(0,s.default)({},t);(0,l.default)(t).forEach(function(n){var i=t[n];r[n]=e.formatInputItem(i)}),n=r}return n}},{key:"formatInputItem",value:function(t){var e=void 0;return(0,w.isInstanceOfSupportedElement)(t)?e=t:"object"===(void 0===t?"undefined":(0,f.default)(t))&&(0,w.isInstanceOfSupportedElement)(t.elt)?e=t.elt:"object"===(void 0===t?"undefined":(0,f.default)(t))&&(0,w.isInstanceOfSupportedElement)(t.canvas)&&(e=t.canvas),e?(0,w.imgToPixelArray)(e):t}},{key:"convertTrainingDataToTensors",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=null===t?this.data.training:t,r=null===e?this.neuralNetworkData.meta:e;return this.neuralNetworkData.convertRawToTensors(n,r)}},{key:"formatInputsForPrediction",value:function(t,e,n){var r=this,i=[];return t instanceof Array?i=n.map(function(n,i){return r.isOneHotEncodedOrNormalized(t[i],n,e.inputs)}):t instanceof Object&&(i=n.map(function(n){return r.isOneHotEncodedOrNormalized(t[n],n,e.inputs)})),i=i.flat()}},{key:"formatInputsForPredictionAll",value:function(t,e,n){var r=this,i=void 0;return t instanceof Array&&t.every(function(t){return Array.isArray(t)})?(i=t.map(function(t){return r.formatInputsForPrediction(t,e,n)}),m.tensor(i,[t.length,n.length])):(i=this.formatInputsForPrediction(t,e,n),m.tensor([i]))}},{key:"isOneHotEncodedOrNormalized",value:function(t,e,n){var r=t,i=e,a=void 0;return"number"!=typeof t?a=n[i].legend[r]:(a=t,this.neuralNetworkData.meta.isNormalized&&(a=this.normalizeInput(t,i,n))),a}},{key:"train",value:function(t,e,n){var r=void 0,i=void 0,a=void 0;"object"===(void 0===t?"undefined":(0,f.default)(t))&&"function"==typeof e&&"function"==typeof n?(r=t,i=e,a=n):"object"===(void 0===t?"undefined":(0,f.default)(t))&&"function"==typeof e?(r=t,i=null,a=e):"function"==typeof t&&"function"==typeof e?(r={},i=t,a=e):(r={},i=null,a=t),this.trainInternal(r,i,a)}},{key:"trainInternal",value:function(t,e,n){var r=(0,d.default)({epochs:10,batchSize:32,validationSplit:.1,whileTraining:null},t);if(!0===this.options.debug?r.whileTraining=[this.neuralNetworkVis.trainingVis(),{onEpochEnd:e}]:r.whileTraining=[{onEpochEnd:e}],this.neuralNetworkData.isMetadataReady||this.createMetaData(this.neuralNetworkData.data.raw),this.neuralNetworkData.isWarmedUp||this.prepareForTraining(this.neuralNetworkData.data.raw),!r.inputs&&!r.outputs){var i=this.convertTrainingDataToTensors(),a=i.inputs,o=i.outputs;r.inputs=a,r.outputs=o}this.neuralNetwork.isLayered||(this.options.layers=this.createNetworkLayers(this.options.layers,this.neuralNetworkData.meta)),this.neuralNetwork.isLayered||(this.options.layers=this.addDefaultLayers(this.options.task,this.neuralNetworkData.meta)),this.neuralNetwork.isCompiled||this.compile(),this.neuralNetwork.train(r,n)}},{key:"addLayer",value:function(t){this.neuralNetwork.addLayer(t)}},{key:"createNetworkLayers",value:function(t,e){var n=this,r=[].concat((0,o.default)(t)),i=(0,s.default)({},e),a=i.inputUnits,u=i.outputUnits,c=r.length;if(!(r.length>=2))return!1;r[0].inputShape=r[0].inputShape?r[0].inputShape:a;var l=r[c-1];return l.units=l.units?l.units:u,r.forEach(function(t){n.addLayer(m.layers[t.type](t))}),r}},{key:"addDefaultLayers",value:function(t,e){var n=void 0;switch(t.toLowerCase()){case"classification":return n=[{type:"dense",units:this.options.hiddenUnits,activation:"relu"},{type:"dense",activation:"softmax"}],this.createNetworkLayers(n,e);case"regression":return n=[{type:"dense",units:this.options.hiddenUnits,activation:"relu"},{type:"dense",activation:"sigmoid"}],this.createNetworkLayers(n,e);case"imageclassification":return n=[{type:"conv2d",filters:8,kernelSize:5,strides:1,activation:"relu",kernelInitializer:"varianceScaling"},{type:"maxPooling2d",poolSize:[2,2],strides:[2,2]},{type:"conv2d",filters:16,kernelSize:5,strides:1,activation:"relu",kernelInitializer:"varianceScaling"},{type:"maxPooling2d",poolSize:[2,2],strides:[2,2]},{type:"flatten"},{type:"dense",kernelInitializer:"varianceScaling",activation:"softmax"}],this.createNetworkLayers(n,e);default:return console.log("no imputUnits or outputUnits defined"),n=[{type:"dense",units:this.options.hiddenUnits,activation:"relu"},{type:"dense",activation:"sigmoid"}],this.createNetworkLayers(n,e)}}},{key:"compile",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=null===e?this.options.learningRate:e,r={};null!==t?r=(0,d.default)({},t):"classification"===this.options.task||"imageClassification"===this.options.task?r={loss:"categoricalCrossentropy",optimizer:m.train.sgd,metrics:["accuracy"]}:"regression"===this.options.task&&(r={loss:"meanSquaredError",optimizer:m.train.adam,metrics:["accuracy"]}),r.optimizer=r.optimizer?this.neuralNetwork.setOptimizerFunction(n,r.optimizer):this.neuralNetwork.setOptimizerFunction(n,m.train.sgd),this.neuralNetwork.compile(r),this.options.debug&&this.neuralNetworkVis.modelSummary({name:"Model Summary"},this.neuralNetwork.model)}},{key:"predictSync",value:function(t){return this.predictSyncInternal(t)}},{key:"predict",value:function(t,e){return(0,b.default)(this.predictInternal(t),e)}},{key:"predictMultiple",value:function(t,e){return(0,b.default)(this.predictInternal(t),e)}},{key:"classifySync",value:function(t){return this.classifySyncInternal(t)}},{key:"classify",value:function(t,e){return(0,b.default)(this.classifyInternal(t),e)}},{key:"classifyMultiple",value:function(t,e){return(0,b.default)(this.classifyInternal(t),e)}},{key:"predictSyncInternal",value:function(t){var e=this.neuralNetworkData.meta,n=(0,l.default)(e.inputs),r=this.formatInputsForPredictionAll(t,e,n),i=this.neuralNetwork.predictSync(r);if(r.dispose(),null!==e){var o=(0,l.default)(e.outputs),s=i.map(function(t){return o.map(function(n,r){var i,s=void 0,u=void 0;if(e.isNormalized){var c=e.outputs[n],l=c.min,f=c.max;s=x.default.unnormalizeValue(t[r],l,f),u=t[r]}else s=t[r];var d=(i={},(0,a.default)(i,o[r],s),(0,a.default)(i,"label",n),(0,a.default)(i,"value",s),i);return u&&(d.unNormalizedValue=u),d})});return s.length<2?s[0]:s}return i}},{key:"predictInternal",value:function(){var t=(0,c.default)(u.default.mark(function t(e){var n,r,i,o,s,c;return u.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=this.neuralNetworkData.meta,r=(0,l.default)(n.inputs),i=this.formatInputsForPredictionAll(e,n,r),t.next=5,this.neuralNetwork.predict(i);case 5:if(o=t.sent,i.dispose(),null===n){t.next=13;break}if(s=(0,l.default)(n.outputs),!((c=o.map(function(t){return s.map(function(e,r){var i,o=void 0,u=void 0;if(n.isNormalized){var c=n.outputs[e],l=c.min,f=c.max;o=x.default.unnormalizeValue(t[r],l,f),u=t[r]}else o=t[r];var d=(i={},(0,a.default)(i,s[r],o),(0,a.default)(i,"label",e),(0,a.default)(i,"value",o),i);return u&&(d.unNormalizedValue=u),d})})).length<2)){t.next=12;break}return t.abrupt("return",c[0]);case 12:return t.abrupt("return",c);case 13:return t.abrupt("return",o);case 14:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"classifySyncInternal",value:function(t){var e=this.neuralNetworkData.meta,n=(0,l.default)(e.inputs),s=void 0;if("imageClassification"===this.options.task){if(s=this.searchAndFormat(t),s=Array.isArray(s)?s.flat():s[n[0]],e.isNormalized){var u=e.inputs[n[0]],c=u.min,f=u.max;s=this.neuralNetworkData.normalizeArray((0,i.default)(s),{min:c,max:f})}else s=(0,i.default)(s);s=m.tensor([s],[1].concat((0,o.default)(e.inputUnits)))}else s=this.formatInputsForPredictionAll(t,e,n);var d=this.neuralNetwork.classifySync(s);if(s.dispose(),null!==e){var h=(0,l.default)(e.outputs)[0],p=(0,r.default)(e.outputs[h].legend),g=d.map(function(t){return p.map(function(e,n){var r;return r={},(0,a.default)(r,e[0],t[n]),(0,a.default)(r,"label",e[0]),(0,a.default)(r,"confidence",t[n]),r}).sort(function(t,e){return e.confidence-t.confidence})});return g.length<2?g[0]:g}return d}},{key:"classifyInternal",value:function(){var t=(0,c.default)(u.default.mark(function t(e){var n,s,c,f,d,h,p,g,v,y;return u.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=this.neuralNetworkData.meta,s=(0,l.default)(n.inputs),c=void 0,"imageClassification"===this.options.task?(c=this.searchAndFormat(e),c=Array.isArray(c)?c.flat():c[s[0]],n.isNormalized?(f=n.inputs[s[0]],d=f.min,h=f.max,c=this.neuralNetworkData.normalizeArray((0,i.default)(c),{min:d,max:h})):c=(0,i.default)(c),c=m.tensor([c],[1].concat((0,o.default)(n.inputUnits)))):c=this.formatInputsForPredictionAll(e,n,s),t.next=6,this.neuralNetwork.classify(c);case 6:if(p=t.sent,c.dispose(),null===n){t.next=15;break}if(g=(0,l.default)(n.outputs)[0],v=(0,r.default)(n.outputs[g].legend),!((y=p.map(function(t){return v.map(function(e,n){var r;return r={},(0,a.default)(r,e[0],t[n]),(0,a.default)(r,"label",e[0]),(0,a.default)(r,"confidence",t[n]),r}).sort(function(t,e){return e.confidence-t.confidence})})).length<2)){t.next=14;break}return t.abrupt("return",y[0]);case 14:return t.abrupt("return",y);case 15:return t.abrupt("return",p);case 16:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"saveData",value:function(t){this.neuralNetworkData.saveData(t)}},{key:"loadData",value:function(){var t=(0,c.default)(u.default.mark(function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,n=arguments[1];return u.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:this.neuralNetworkData.loadData(e,n);case 1:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"save",value:function(t,e){var n=this,r=void 0,i=void 0;"function"==typeof t?(r="model",i=t):"string"==typeof t?(r=t,"function"==typeof e&&(i=e)):r="model",this.neuralNetwork.save(r,function(){n.neuralNetworkData.saveMeta(r,i)})}},{key:"load",value:function(){var t=(0,c.default)(u.default.mark(function t(){var e,n=this,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,i=arguments[1];return u.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:e=void 0,i&&(e=i),this.neuralNetwork.load(r,function(){return n.neuralNetworkData.loadMeta(r,e),n.neuralNetwork.model});case 3:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"dispose",value:function(){this.neuralNetwork.dispose()}},{key:"mutate",value:function(t,e){this.neuralNetwork.mutate(t,e)}},{key:"crossover",value:function(t){var e=this.copy();return e.neuralNetwork.crossover(t.neuralNetwork),e}}]),t}();e.default=function(t,e,n){var r=void 0,i=void 0;return t instanceof Object?(r=t,i=e):(r={inputs:t,outputs:e},i=n),new E(r,i)}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default={leftFace:{id:0,color:[110,64,170]},rightFace:{id:1,color:[106,72,183]},rightUpperLegFront:{id:2,color:[100,81,196]},rightLowerLegBack:{id:3,color:[92,91,206]},rightUpperLegBack:{id:4,color:[84,101,214]},leftLowerLegFront:{id:5,color:[75,113,221]},leftUpperLegFront:{id:6,color:[66,125,224]},leftUpperLegBack:{id:7,color:[56,138,226]},leftLowerLegBack:{id:8,color:[48,150,224]},rightFeet:{id:9,color:[40,163,220]},rightLowerLegFront:{id:10,color:[33,176,214]},leftFeet:{id:11,color:[29,188,205]},torsoFront:{id:12,color:[26,199,194]},torsoBack:{id:13,color:[26,210,182]},rightUpperArmFront:{id:14,color:[28,219,169]},rightUpperArmBack:{id:15,color:[33,227,155]},rightLowerArmBack:{id:16,color:[41,234,141]},leftLowerArmFront:{id:17,color:[51,240,128]},leftUpperArmFront:{id:18,color:[64,243,116]},leftUpperArmBack:{id:19,color:[79,246,105]},leftLowerArmBack:{id:20,color:[96,247,97]},rightHand:{id:21,color:[115,246,91]},rightLowerArmFront:{id:22,color:[134,245,88]},leftHand:{id:23,color:[155,243,88]}}},function(t,e,n){"use strict";n.r(e),n.d(e,"BodyPix",function(){return w}),n.d(e,"load",function(){return k}),n.d(e,"checkpoints",function(){return h}),n.d(e,"decodePartSegmentation",function(){return m}),n.d(e,"toMask",function(){return p}),n.d(e,"drawBokehEffect",function(){return P}),n.d(e,"drawMask",function(){return F}),n.d(e,"drawPixelatedMask",function(){return j}),n.d(e,"toColoredPartImageData",function(){return M}),n.d(e,"toMaskImageData",function(){return D}),n.d(e,"partChannels",function(){return L}),n.d(e,"resizeAndPadTo",function(){return y}),n.d(e,"scaleAndCropToInputTensorShape",function(){return b});var r=n(0),i=n(20);
  305. /**
  306. * @license
  307. * Copyright 2019 Google LLC. All Rights Reserved.
  308. * Licensed under the Apache License, Version 2.0 (the "License");
  309. * you may not use this file except in compliance with the License.
  310. * You may obtain a copy of the License at
  311. *
  312. * http://www.apache.org/licenses/LICENSE-2.0
  313. *
  314. * Unless required by applicable law or agreed to in writing, software
  315. * distributed under the License is distributed on an "AS IS" BASIS,
  316. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  317. * See the License for the specific language governing permissions and
  318. * limitations under the License.
  319. * =============================================================================
  320. */
  321. function a(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})}function o(t,e){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=(i=o.trys).length>0&&i[i.length-1])&&(6===a[0]||2===a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}var s=[["conv2d",2],["separableConv",1],["separableConv",2],["separableConv",1],["separableConv",2],["separableConv",1],["separableConv",2],["separableConv",1],["separableConv",1],["separableConv",1],["separableConv",1],["separableConv",1],["separableConv",1],["separableConv",1]],u=[8,16,32];function c(t){r.util.assert("number"==typeof t,function(){return"outputStride is not a number"}),r.util.assert(u.indexOf(t)>=0,function(){return"outputStride of "+t+" is invalid. It must be either 8, 16, or 32"})}var l={100:[["conv2d",2],["separableConv",1],["separableConv",2],["separableConv",1],["separableConv",2],["separableConv",1],["separableConv",2],["separableConv",1],["separableConv",1],["separableConv",1],["separableConv",1],["separableConv",1],["separableConv",2],["separableConv",1]],75:[["conv2d",2],["separableConv",1],["separableConv",2],["separableConv",1],["separableConv",2],["separableConv",1],["separableConv",2],["separableConv",1],["separableConv",1],["separableConv",1],["separableConv",1],["separableConv",1],["separableConv",1],["separableConv",1]],50:s,25:s};var f=function(){function t(t,e){this.PREPROCESS_DIVISOR=Object(r.scalar)(127.5),this.ONE=Object(r.scalar)(1),this.modelWeights=t,this.convolutionDefinitions=e}return t.prototype.predict=function(t,e){var n=this,i=Object(r.div)(t.toFloat(),this.PREPROCESS_DIVISOR),a=Object(r.sub)(i,this.ONE);return function(t,e){var n=1,r=1;return t.map(function(t,i){var a,o,s=t[0],u=t[1];return n===e?(a=1,o=r,r*=u):(a=u,o=1,n*=u),{blockId:i,convType:s,stride:a,rate:o,outputStride:n}})}(this.convolutionDefinitions,e).reduce(function(t,e){var r=e.blockId,i=e.stride,a=e.convType,o=e.rate;if("conv2d"===a)return n.conv(t,i,r);if("separableConv"===a)return n.separableConv(t,i,r,o);throw Error("Unknown conv type of "+a)},a)},t.prototype.convToOutput=function(t,e){return t.conv2d(this.weights(e),1,"same").add(this.convBias(e,!1))},t.prototype.conv=function(t,e,n){var r=this.weights("Conv2d_"+String(n));return t.conv2d(r,e,"same").add(this.convBias("Conv2d_"+String(n))).clipByValue(0,6)},t.prototype.separableConv=function(t,e,n,r){void 0===r&&(r=1);var i="Conv2d_"+String(n)+"_depthwise",a="Conv2d_"+String(n)+"_pointwise";return t.depthwiseConv2D(this.depthwiseWeights(i),e,"same","NHWC",r).add(this.depthwiseBias(i)).clipByValue(0,6).conv2d(this.weights(a),[1,1],"same").add(this.convBias(a)).clipByValue(0,6)},t.prototype.weights=function(t){return this.modelWeights.weights(t)},t.prototype.convBias=function(t,e){return void 0===e&&(e=!0),this.modelWeights.convBias(t,e)},t.prototype.depthwiseBias=function(t){return this.modelWeights.depthwiseBias(t)},t.prototype.depthwiseWeights=function(t){return this.modelWeights.depthwiseWeights(t)},t.prototype.dispose=function(){this.modelWeights.dispose()},t}(),d="https://storage.googleapis.com/tfjs-models/savedmodel/",h={1:{url:d+"posenet_mobilenet_100_partmap/",architecture:l[100]},.75:{url:d+"posenet_mobilenet_075_partmap/",architecture:l[75]},.5:{url:d+"posenet_mobilenet_050_partmap/",architecture:l[50]},.25:{url:d+"posenet_mobilenet_025_partmap/",architecture:l[25]}};function p(t,e){return Object(r.tidy)(function(){return t.greater(Object(r.scalar)(e)).toInt()})}function m(t,e){var n=e.shape,i=n[0],a=n[1],o=n[2];return Object(r.tidy)(function(){var n=function(t){var e=t.shape[2],n=t.argMax(2).reshape([-1]);return Object(r.oneHot)(n,e)}(e),s=Object(r.range)(0,o,1,"int32").expandDims(1);return function(t,e){return t.mul(e)}(n.matMul(s).toInt().reshape([i,a]).add(Object(r.scalar)(1,"int32")),t).sub(Object(r.scalar)(1,"int32"))})}var g=function(){function t(t){this.graphModel=t}return t.prototype.weights=function(t){return this.getVariable("MobilenetV1/"+t+"/weights")},t.prototype.convBias=function(t,e){return void 0===e&&(e=!0),this.getVariable("MobilenetV1/"+t+"/Conv2D_bias")},t.prototype.depthwiseBias=function(t){return this.getVariable("MobilenetV1/"+t+"/depthwise_bias")},t.prototype.depthwiseWeights=function(t){return this.getVariable("MobilenetV1/"+t+"/depthwise_weights")},t.prototype.getVariable=function(t){return this.graphModel.weights[""+t][0]},t.prototype.dispose=function(){this.graphModel.dispose()},t}();function v(t){return t instanceof r.Tensor?t:r.browser.fromPixels(t)}function y(t,e,n){var i=e[0],a=e[1];void 0===n&&(n=!1);var o,s,u,c,l,f,d=t.shape,h=d[0],p=d[1]/h;if(p>a/i){o=a;var m=i-(s=Math.ceil(o/p));u=0,c=0,l=Math.floor(m/2),f=i-(s+l)}else{s=i;var g=a-(o=Math.ceil(i*p));u=Math.floor(g/2),c=a-(o+u),l=0,f=0}return{resizedAndPadded:Object(r.tidy)(function(){var e;return e=n?t.reverse(1).resizeBilinear([s,o]):t.resizeBilinear([s,o]),Object(r.pad3d)(e,[[l,f],[u,c],[0,0]])}),paddedBy:[[l,f],[u,c]]}}function b(t,e,n,i){var a=e[0],o=e[1],s=n[0],u=n[1],c=i[0],l=c[0],f=c[1],d=i[1],h=d[0],p=d[1];return Object(r.tidy)(function(){return function(t,e,n){var i=e[0],a=e[1],o=n[0],s=o[0],u=o[1],c=n[1],l=c[0],f=c[1],d=t.shape,h=d[0],p=d[1],m=h-(s+u),g=p-(l+f);return Object(r.tidy)(function(){return Object(r.slice3d)(t,[s,l,0],[m,g,t.shape[2]]).resizeBilinear([i,a],!0)})}(t.resizeBilinear([s,u],!0),[a,o],[[l,f],[h,p]])})}var x=[353,257],w=function(){function t(t){this.mobileNet=t}return t.prototype.predictForSegmentation=function(t,e){var n=this;return void 0===e&&(e=16),c(e),Object(r.tidy)(function(){var r=n.mobileNet.predict(t,e);return n.mobileNet.convToOutput(r,"segment_2").sigmoid()})},t.prototype.predictForPartMap=function(t,e){var n=this;return void 0===e&&(e=16),c(e),Object(r.tidy)(function(){var r=n.mobileNet.predict(t,e),i=n.mobileNet.convToOutput(r,"segment_2"),a=n.mobileNet.convToOutput(r,"part_heatmap_2");return{segmentScores:i.sigmoid(),partHeatmapScores:a.sigmoid()}})},t.prototype.estimatePersonSegmentationActivation=function(t,e,n){var i=this;return void 0===e&&(e=16),void 0===n&&(n=.5),c(e),Object(r.tidy)(function(){var r=v(t),a=y(r,x),o=a.resizedAndPadded,s=a.paddedBy,u=i.predictForSegmentation(o,e),c=o.shape,l=c[0],f=c[1],d=r.shape;return p(b(u,[d[0],d[1]],[l,f],s).squeeze(),n)})},t.prototype.estimatePersonSegmentation=function(t,e,n){return void 0===e&&(e=16),void 0===n&&(n=.5),a(this,void 0,void 0,function(){var r,i,a,s,u;return o(this,function(o){switch(o.label){case 0:return r=this.estimatePersonSegmentationActivation(t,e,n),i=r.shape,a=i[0],s=i[1],[4,r.data()];case 1:return u=o.sent(),r.dispose(),[2,{height:a,width:s,data:u}]}})})},t.prototype.estimatePartSegmentationActivation=function(t,e,n){var i=this;return void 0===e&&(e=16),void 0===n&&(n=.5),c(e),Object(r.tidy)(function(){var r=v(t),a=y(r,x),o=a.resizedAndPadded,s=a.paddedBy,u=i.predictForPartMap(o,e),c=u.segmentScores,l=u.partHeatmapScores,f=o.shape,d=f[0],h=f[1],g=r.shape,w=g[0],k=g[1],_=b(c,[w,k],[d,h],s),E=b(l,[w,k],[d,h],s);return m(p(_.squeeze(),n),E)})},t.prototype.estimatePartSegmentation=function(t,e,n){return void 0===e&&(e=16),void 0===n&&(n=.5),a(this,void 0,void 0,function(){var r,i,a,s,u;return o(this,function(o){switch(o.label){case 0:return r=this.estimatePartSegmentationActivation(t,e,n),i=r.shape,a=i[0],s=i[1],[4,r.data()];case 1:return u=o.sent(),r.dispose(),[2,{height:a,width:s,data:u}]}})})},t.prototype.dispose=function(){this.mobileNet.dispose()},t}();function k(t){return void 0===t&&(t=.75),a(this,void 0,void 0,function(){var e,n;return o(this,function(i){switch(i.label){case 0:if(null==r)throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please also include @tensorflow/tfjs on the page before using this model.");return e=Object.keys(h),r.util.assert("number"==typeof t,function(){return"got multiplier type of "+typeof t+" when it should be a number."}),r.util.assert(e.indexOf(t.toString())>=0,function(){return"invalid multiplier value of "+t+". No checkpoint exists for that multiplier. Must be one of "+e.join(",")+"."}),[4,_.load(t)];case 1:return n=i.sent(),[2,new w(n)]}})})}var _={load:function(t){return a(void 0,void 0,void 0,function(){var e,n,r,a;return o(this,function(o){switch(o.label){case 0:return e=h[t],n=e.url,[4,Object(i.c)(n+"model.json")];case 1:return r=o.sent(),a=new g(r),[2,new f(a,e.architecture)]}})})}};var E={};function O(t,e,n,r){var i=t.width,a=t.height,o=e.width,s=e.height;if(i!==o||a!==s)throw new Error("error: dimensions must match. "+n+" has dimensions "+i+"x"+a+", "+r+" has dimensions "+o+"x"+s)}function S(t){var e=t.getContext("2d");e.scale(-1,1),e.translate(-t.width,0)}function C(t,e,n){t.globalCompositeOperation=n,t.drawImage(e,0,0)}function A(t){return E[t]||(E[t]=document.createElement("canvas")),E[t]}function N(t,e,n){var r=t.height,i=t.width,a=n.getContext("2d");n.width=i,n.height=r,a.clearRect(0,0,i,r),a.save(),/^((?!chrome|android).)*safari/i.test(navigator.userAgent)?function(t,e,n){for(var r=t.getContext("2d"),i=0,a=1/(2*Math.PI*5*5),o=n<3?1:2,s=-n;s<=n;s+=o)for(var u=-n;u<=n;u+=o)i+=a*Math.exp(-(u*u+s*s)/50);for(s=-n;s<=n;s+=o)for(u=-n;u<=n;u+=o)r.globalAlpha=a*Math.exp(-(u*u+s*s)/50)/i*n,r.drawImage(e,u,s);r.globalAlpha=1}(n,t,e):(a.filter="blur("+e+"px)",a.drawImage(t,0,0,i,r)),a.restore()}function T(t,e,n){var r=A(n);return 0===e?function(t,e){var n=t.width,r=t.height;e.width=n,e.height=r,e.getContext("2d").drawImage(t,0,0,n,r)}(t,r):N(t,e,r),r}function I(t,e){var n=A(e);return function(t,e){e.width=t.width,e.height=t.height,e.getContext("2d").putImageData(t,0,0)}(t,n),n}function D(t,e){void 0===e&&(e=!0);for(var n=t.width,r=t.height,i=t.data,a=new Uint8ClampedArray(n*r*4),o=0;o<r*n;++o){var s=255*(e?1-i[o]:i[o]),u=4*o;a[u+0]=0,a[u+1]=0,a[u+2]=0,a[u+3]=Math.round(s)}return new ImageData(a,n,r)}function M(t,e){for(var n=t.width,r=t.height,i=t.data,a=new Uint8ClampedArray(n*r*4),o=0;o<r*n;++o){var s=Math.round(i[o]),u=4*o;if(-1===s)a[u+0]=255,a[u+1]=255,a[u+2]=255,a[u+3]=255;else{var c=e[s];if(!c)throw new Error("No color could be found for part id "+s);a[u+0]=c[0],a[u+1]=c[1],a[u+2]=c[2],a[u+3]=255}}return new ImageData(a,n,r)}var R={blurred:"blurred",blurredMask:"blurred-mask",mask:"mask",lowresPartMask:"lowres-part-mask"};function F(t,e,n,r,i,a){void 0===r&&(r=.7),void 0===i&&(i=0),void 0===a&&(a=!1),O(e,n,"image","mask");var o=T(I(n,R.mask),i,R.blurredMask);t.width=o.width,t.height=o.height;var s=t.getContext("2d");s.save(),a&&S(t),s.drawImage(e,0,0),s.globalAlpha=r,s.drawImage(o,0,0),s.restore()}function j(t,e,n,r,i,a,o){void 0===r&&(r=.7),void 0===i&&(i=0),void 0===a&&(a=!1),void 0===o&&(o=10),O(e,n,"image","mask");var s=T(I(n,R.mask),i,R.blurredMask);t.width=s.width,t.height=s.height;var u=t.getContext("2d");u.save(),a&&S(t);var c=A(R.lowresPartMask),l=c.getContext("2d");c.width=s.width*(1/o),c.height=s.height*(1/o),l.drawImage(s,0,0,s.width,s.height,0,0,c.width,c.height),u.imageSmoothingEnabled=!1,u.drawImage(c,0,0,c.width,c.height,0,0,t.width,t.height);for(var f=0;f<c.width;f++)u.beginPath(),u.strokeStyle="#ffffff",u.moveTo(o*f,0),u.lineTo(o*f,t.height),u.stroke();for(f=0;f<c.height;f++)u.beginPath(),u.strokeStyle="#ffffff",u.moveTo(0,o*f),u.lineTo(t.width,o*f),u.stroke();u.globalAlpha=1-r,u.drawImage(e,0,0),u.restore()}function P(t,e,n,r,i,a){void 0===r&&(r=3),void 0===i&&(i=3),void 0===a&&(a=!1),O(e,n,"image","segmentation");var o=T(e,r,R.blurred),s=function(t,e){var n=I(D(t,!1),R.mask);return 0===e?n:T(n,e,R.blurredMask)}(n,i),u=t.getContext("2d");u.save(),a&&S(t),u.drawImage(e,0,0),C(u,s,"destination-in"),C(u,o,"destination-over"),u.restore()}var L=["leftFace","rightFace","rightUpperLegFront","rightLowerLegBack","rightUpperLegBack","leftLowerLegFront","leftUpperLegFront","leftUpperLegBack","leftLowerLegBack","rightFeet","rightLowerLegFront","leftFeet","torsoFront","torsoBack","rightUpperArmFront","rightUpperArmBack","rightLowerArmBack","leftLowerArmFront","leftUpperArmFront","leftUpperArmBack","leftLowerArmBack","rightHand","rightLowerArmFront","leftHand"]},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=v(n(14)),i=v(n(83)),a=v(n(24)),o=v(n(54)),s=v(n(65)),u=v(n(9)),c=v(n(8)),l=v(n(7)),f=v(n(10)),d=g(n(4)),h=g(n(312)),p=v(n(15)),m=v(n(64));function g(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}function v(t){return t&&t.__esModule?t:{default:t}}var y={multiplier:.75,outputStride:16,segmentationThreshold:.5,palette:v(n(311)).default,returnTensors:!1},b=function(){function t(e,n,r){(0,l.default)(this,t),this.video=e,this.model=null,this.modelReady=!1,this.modelPath="",this.config={multiplier:n.multiplier||y.multiplier,outputStride:n.outputStride||y.outputStride,segmentationThreshold:n.segmentationThreshold||y.segmentationThreshold,palette:n.palette||y.palette,returnTensors:n.returnTensors||y.returnTensors},this.ready=(0,p.default)(this.loadModel(),r)}return(0,f.default)(t,[{key:"loadModel",value:function(){var t=(0,c.default)(u.default.mark(function t(){return u.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,h.load(this.config.multiplier);case 2:return this.model=t.sent,this.modelReady=!0,t.abrupt("return",this);case 5:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"p5Color2RGB",value:function(t){var e=/\(([^)]+)\)/.exec(t.toString("rgb"))[1].split(","),n=(0,s.default)(e,3);return[n[0],n[1],n[2]]}},{key:"convertToP5Image",value:function(){var t=(0,c.default)(u.default.mark(function t(e,n,r){var i,a;return u.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,m.default.rawToBlob(e,n,r);case 2:return i=t.sent,t.next=5,m.default.blobToP5Image(i);case 5:return a=t.sent,t.abrupt("return",a);case 7:case"end":return t.stop()}},t,this)}));return function(e,n,r){return t.apply(this,arguments)}}()},{key:"bodyPartsSpec",value:function(t){var e=this,n=void 0!==t||(0,o.default)(t).length>=24?t:this.config.palette;return m.default.checkP5()&&void 0!==n&&(0,o.default)(n).length>=24&&(0,o.default)(n).forEach(function(t){n[t].color instanceof window.p5.Color?n[t].color=e.p5Color2RGB(n[t].color):n[t].color=n[t].color}),n}},{key:"segmentWithPartsInternal",value:function(){var t=(0,c.default)(u.default.mark(function t(e,n){var r,s,c,l,f,p,g,v,y,b,x,w=this;return u.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.ready;case 2:return t.next=4,d.nextFrame();case 4:if(!this.video||0!==this.video.readyState){t.next=7;break}return t.next=7,new a.default(function(t){w.video.onloadeddata=function(){return t()}});case 7:return this.config.palette=n.palette||this.config.palette,this.config.outputStride=n.outputStride||this.config.outputStride,this.config.segmentationThreshold=n.segmentationThreshold||this.config.segmentationThreshold,t.next=12,this.model.estimatePartSegmentation(e,this.config.outputStride,this.config.segmentationThreshold);case 12:return r=t.sent,s=this.bodyPartsSpec(this.config.palette),c=(0,o.default)(s).map(function(t){return s[t].color}),(l={segmentation:r,raw:{personMask:null,backgroundMask:null,partMask:null},tensor:{personMask:null,backgroundMask:null,partMask:null},personMask:null,backgroundMask:null,partMask:null,bodyParts:s}).raw.backgroundMask=h.toMaskImageData(r,!0),l.raw.personMask=h.toMaskImageData(r,!1),l.raw.partMask=h.toColoredPartImageData(r,c),f=d.tidy(function(){var t=d.browser.fromPixels(e),n=d.ones([r.height,r.width,1]).tile([1,1,1]).mul(255);t=t.concat(n,2);var a=d.tensor(r.data,[r.height,r.width,1]),o=d.tensor(r.data,[r.height,r.width,1]),s=d.tensor([].concat((0,i.default)(l.raw.partMask.data)),[r.height,r.width,4]);return{personMask:a=d.cast(a.add(.2).sign().relu().mul(t),"int32"),backgroundMask:o=d.cast(o.add(.2).sign().neg().relu().mul(t),"int32"),partMask:s=d.cast(s,"int32")}}),p=f.personMask,g=f.backgroundMask,v=f.partMask,t.next=22,d.browser.toPixels(p);case 22:return y=t.sent,t.next=25,d.browser.toPixels(g);case 25:return b=t.sent,t.next=28,d.browser.toPixels(v);case 28:if(x=t.sent,l.personMask=y,l.backgroundMask=b,l.partMask=x,!m.default.checkP5()){t.next=42;break}return t.next=35,this.convertToP5Image(y,r.width,r.height);case 35:return l.personMask=t.sent,t.next=38,this.convertToP5Image(b,r.width,r.height);case 38:return l.backgroundMask=t.sent,t.next=41,this.convertToP5Image(x,r.width,r.height);case 41:l.partMask=t.sent;case 42:return this.config.returnTensors?(l.tensor.personMask=p,l.tensor.backgroundMask=g,l.tensor.partMask=v):(p.dispose(),g.dispose(),v.dispose()),t.abrupt("return",l);case 44:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"segmentWithParts",value:function(){var t=(0,c.default)(u.default.mark(function t(e,n,i){var a,o,s;return u.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(a=this.video,o=void 0,s=this.config,"function"!=typeof e){t.next=8;break}a=this.video,o=e,t.next=26;break;case 8:if(!(e instanceof HTMLImageElement||e instanceof HTMLCanvasElement||e instanceof HTMLVideoElement||e instanceof ImageData)){t.next=12;break}a=e,t.next=26;break;case 12:if("object"!==(void 0===e?"undefined":(0,r.default)(e))||!(e.elt instanceof HTMLImageElement||e.elt instanceof HTMLCanvasElement||e.elt instanceof ImageData)){t.next=16;break}a=e.elt,t.next=26;break;case 16:if(!("object"===(void 0===e?"undefined":(0,r.default)(e))&&e.canvas instanceof HTMLCanvasElement)){t.next=20;break}a=e.canvas,t.next=26;break;case 20:if(!("object"===(void 0===e?"undefined":(0,r.default)(e))&&e.elt instanceof HTMLVideoElement)){t.next=24;break}a=e.elt,t.next=26;break;case 24:if(this.video instanceof HTMLVideoElement){t.next=26;break}throw new Error("No input image provided. If you want to classify a video, pass the video element in the constructor. ");case 26:return"object"===(void 0===n?"undefined":(0,r.default)(n))?s=n:"function"==typeof n&&(o=n),"function"==typeof i&&(o=i),t.abrupt("return",(0,p.default)(this.segmentWithPartsInternal(a,s),o));case 29:case"end":return t.stop()}},t,this)}));return function(e,n,r){return t.apply(this,arguments)}}()},{key:"segmentInternal",value:function(){var t=(0,c.default)(u.default.mark(function t(e,n){var r,i,o,s,c,l,f,p=this;return u.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.ready;case 2:return t.next=4,d.nextFrame();case 4:if(!this.video||0!==this.video.readyState){t.next=7;break}return t.next=7,new a.default(function(t){p.video.onloadeddata=function(){return t()}});case 7:return this.config.outputStride=n.outputStride||this.config.outputStride,this.config.segmentationThreshold=n.segmentationThreshold||this.config.segmentationThreshold,t.next=11,this.model.estimatePersonSegmentation(e,this.config.outputStride,this.config.segmentationThreshold);case 11:return r=t.sent,(i={segmentation:r,raw:{personMask:null,backgroundMask:null},tensor:{personMask:null,backgroundMask:null},personMask:null,backgroundMask:null}).raw.backgroundMask=h.toMaskImageData(r,!0),i.raw.personMask=h.toMaskImageData(r,!1),o=d.tidy(function(){var t=d.browser.fromPixels(e),n=d.ones([r.height,r.width,1]).tile([1,1,1]).mul(255);t=t.concat(n,2);var i=d.tensor(r.data,[r.height,r.width,1]),a=d.tensor(r.data,[r.height,r.width,1]);return{personMask:i=d.cast(i.neg().add(1).mul(t),"int32"),backgroundMask:a=d.cast(a.mul(t),"int32")}}),s=o.personMask,c=o.backgroundMask,t.next=18,d.browser.toPixels(s);case 18:return l=t.sent,t.next=21,d.browser.toPixels(c);case 21:if(f=t.sent,!m.default.checkP5()){t.next=31;break}return t.next=25,this.convertToP5Image(l,r.width,r.height);case 25:return i.personMask=t.sent,t.next=28,this.convertToP5Image(f,r.width,r.height);case 28:i.backgroundMask=t.sent,t.next=33;break;case 31:i.personMask=l,i.backgroundMask=f;case 33:return this.config.returnTensors?(i.tensor.personMask=s,i.tensor.backgroundMask=c):(s.dispose(),c.dispose()),t.abrupt("return",i);case 35:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"segment",value:function(){var t=(0,c.default)(u.default.mark(function t(e,n,i){var a,o,s;return u.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(a=this.video,o=void 0,s=this.config,"function"!=typeof e){t.next=8;break}a=this.video,o=e,t.next=26;break;case 8:if(!(e instanceof HTMLImageElement||e instanceof HTMLCanvasElement||e instanceof HTMLVideoElement||e instanceof ImageData)){t.next=12;break}a=e,t.next=26;break;case 12:if("object"!==(void 0===e?"undefined":(0,r.default)(e))||!(e.elt instanceof HTMLImageElement||e.elt instanceof HTMLCanvasElement||e.elt instanceof ImageData)){t.next=16;break}a=e.elt,t.next=26;break;case 16:if(!("object"===(void 0===e?"undefined":(0,r.default)(e))&&e.canvas instanceof HTMLCanvasElement)){t.next=20;break}a=e.canvas,t.next=26;break;case 20:if(!("object"===(void 0===e?"undefined":(0,r.default)(e))&&e.elt instanceof HTMLVideoElement)){t.next=24;break}a=e.elt,t.next=26;break;case 24:if(this.video instanceof HTMLVideoElement){t.next=26;break}throw new Error("No input image provided. If you want to classify a video, pass the video element in the constructor. ");case 26:return"object"===(void 0===n?"undefined":(0,r.default)(n))?s=n:"function"==typeof n&&(o=n),"function"==typeof i&&(o=i),t.abrupt("return",(0,p.default)(this.segmentInternal(a,s),o));case 29:case"end":return t.stop()}},t,this)}));return function(e,n,r){return t.apply(this,arguments)}}()}]),t}();e.default=function(t,e,n){var i=void 0,a={},o=n;t instanceof HTMLVideoElement?i=t:"object"===(void 0===t?"undefined":(0,r.default)(t))&&t.elt instanceof HTMLVideoElement?i=t.elt:"object"===(void 0===t?"undefined":(0,r.default)(t))?a=t:"function"==typeof t&&(o=t),"object"===(void 0===e?"undefined":(0,r.default)(e))?a=e:"function"==typeof e&&(o=e);var s=new b(i,a,o);return o?s:s.ready}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=f(n(9)),i=f(n(8)),a=f(n(7)),o=f(n(10)),s=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(4)),u=f(n(55)),c=f(n(15)),l=f(n(142));function f(t){return t&&t.__esModule?t:{default:t}}var d=0;var h=function(){function t(e,n){(0,a.default)(this,t),this.ready=(0,c.default)(this.loadModel(e),n)}return(0,o.default)(t,[{key:"loadModel",value:function(){var t=(0,i.default)(r.default.mark(function t(e){var n,i,a,o;return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(n={model:null,metadata:null},"moviereviews"!==e.toLowerCase()){t.next=6;break}n.model="https://storage.googleapis.com/tfjs-models/tfjs/sentiment_cnn_v1/model.json",n.metadata="https://storage.googleapis.com/tfjs-models/tfjs/sentiment_cnn_v1/metadata.json",t.next=14;break;case 6:if(!0!==l.default.isAbsoluteURL(e)){t.next=12;break}i=l.default.getModelPath(e),n.model=i+"/model.json",n.metadata=i+"/metadata.json",t.next=14;break;case 12:return console.error("problem loading model"),t.abrupt("return",this);case 14:return t.next=16,s.loadLayersModel(n.model);case 16:return this.model=t.sent,t.next=19,u.default.get(n.metadata);case 19:return a=t.sent,o=a.data,this.indexFrom=o.index_from,this.maxLen=o.max_len,this.wordIndex=o.word_index,this.vocabularySize=o.vocabulary_size,t.abrupt("return",this);case 26:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"predict",value:function(t){var e=this,n=function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"pre",r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"pre",i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:d;return t.map(function(t){if(t.length>e&&("pre"===r?t.splice(0,t.length-e):t.splice(e,t.length-e)),t.length<e){for(var a=[],o=0;o<e-t.length;o+=1)a.push(i);t="pre"===n?a.concat(t):t.concat(a)}return t})}([t.trim().toLowerCase().replace(/[.,?!]/g,"").split(" ").map(function(t){var n=e.wordIndex[t]+e.indexFrom;return n>e.vocabularySize&&(n=2),n})],this.maxLen),r=s.tensor2d(n,[1,this.maxLen]),i=this.model.predict(r),a=i.dataSync()[0];return i.dispose(),r.dispose(),{score:a}}}]),t}();e.default=function(t,e){return new h(t,e)}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=a(n(83)),i=a(n(54));function a(t){return t&&t.__esModule?t:{default:t}}e.default=function(t){if("undefined"==typeof window)return t;if(void 0===window.p5)return t;if(void 0===window.p5.prototype)return t;if(void 0===window.p5.prototype.registerPreloadMethod)return t;var e=t;return(0,i.default)(t).forEach(function(n){var i=t[n];e[n]=function(){for(var e=null,n=arguments.length,a=Array(n),o=0;o<n;o++)a[o]=arguments[o];var s=a.length;return"function"==typeof a[s-1]&&(e=a[s-1],s-=1),i.apply(t,[].concat((0,r.default)(a.slice(0,s)),[function(){try{e&&e()}catch(t){console.error(t)}return window._decrementPreload?window._decrementPreload():null}]))},window.p5.prototype.registerPreloadMethod(""+n,t)}),t}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=h(n(14)),i=h(n(9)),a=h(n(65)),o=h(n(8)),s=h(n(7)),u=h(n(10)),c=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(4)),l=h(n(55)),f=h(n(15)),d=h(n(64));function h(t){return t&&t.__esModule?t:{default:t}}var p=function(){function t(e,n,r){(0,s.default)(this,t),this.model={},this.modelPath=e,this.modelInfo={},this.modelPathPrefix="",this.modelReady=!1,this.config={returnTensors:n.returnTensors||!1},this.ready=(0,f.default)(this.loadModel(),r)}return(0,u.default)(t,[{key:"loadModel",value:function(){var t=(0,o.default)(i.default.mark(function t(){var e,n,r,o,s,u;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,l.default.get(this.modelPath);case 2:return e=t.sent,n=e.data,this.modelInfo=n,r=this.modelPath.split("manifest.json"),o=(0,a.default)(r,1),s=o[0],u=this.isAbsoluteURL(s)?this.modelInfo.model:this.modelPathPrefix+this.modelInfo.model,t.next=9,c.loadLayersModel(u);case 9:return this.model=t.sent,this.modelReady=!0,t.abrupt("return",this);case 12:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"generate",value:function(){var t=(0,o.default)(i.default.mark(function t(e,n){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.ready;case 2:return t.abrupt("return",(0,f.default)(this.generateInternal(n),e));case 3:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"compute",value:function(){var t=(0,o.default)(i.default.mark(function t(e,n){var r,a=this;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=c.tidy(function(){var t=void 0;if(!1===Array.isArray(n))t=c.randomNormal([1,e]);else{for(var r=c.buffer([1,e]),i=0;i<e;i+=1)r.set(n[i],0,i);t=r.toTensor()}return a.model.predict(t).squeeze().transpose([1,2,0]).div(c.scalar(2)).add(c.scalar(.5))}),t.abrupt("return",r);case 2:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"generateInternal",value:function(){var t=(0,o.default)(i.default.mark(function t(e){var n,r,o,s,u,l,f,h,p;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=this.modelInfo.modelLatentDim,t.next=3,this.compute(n,e);case 3:return r=t.sent,t.next=6,c.browser.toPixels(r);case 6:return o=t.sent,s=(0,a.default)(r.shape,2),u=s[0],l=s[1],t.next=10,d.default.rawToBlob(o,l,u);case 10:if(f=t.sent,h=void 0,!d.default.checkP5()){t.next=16;break}return t.next=15,d.default.blobToP5Image(f);case 15:h=t.sent;case 16:return(p={}).blob=f,p.raw=o,d.default.checkP5()&&(p.image=h),this.config.returnTensors?p.tensor=r:(p.tensor=null,r.dispose()),t.abrupt("return",p);case 22:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"isAbsoluteURL",value:function(t){return!!new RegExp("^(?:[a-z]+:)?//","i").test(t)}}]),t}();e.default=function(t,e,n){var i=void 0,a={};if("string"!=typeof t)throw new Error('Please specify a path to a "manifest.json" file: \n\n "models/face/manifest.json" \n\n\n This "manifest.json" file should include:\n\n {\n "description": "DCGAN, human faces, 64x64",\n "model": "https://raw.githubusercontent.com/viztopia/ml5dcgan/master/model/model.json", // "https://github.com/viztopia/ml5dcgan/blob/master/model/model.json",\n "modelSize": 64,\n "modelLatentDim": 128 \n }\n ');"function"==typeof e?i=e:"object"===(void 0===e?"undefined":(0,r.default)(e))&&(a=e,i=n);var o=new p(t,a,i);return i?o:o.ready}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=d(n(65)),i=d(n(24)),a=d(n(9)),o=d(n(8)),s=d(n(7)),u=d(n(10)),c=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(4)),l=d(n(15)),f=d(n(64));function d(t){return t&&t.__esModule?t:{default:t}}var h=function(){function t(e,n){var r=this;(0,s.default)(this,t),this.ready=!1,this.model={},this.latentDim=c.randomUniform([1,16]),this.modelPath=e,this.modelPathPrefix="",this.jsonLoader().then(function(t){r.modelPathPrefix=r.modelPath.split("manifest.json")[0],r.ready=(0,l.default)(r.loadCVAEModel(r.modelPathPrefix+t.model),n),r.labels=t.labels,r.labelVector=Array(r.labels.length+1).fill(0)})}return(0,u.default)(t,[{key:"loadCVAEModel",value:function(){var t=(0,o.default)(a.default.mark(function t(e){return a.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,c.loadLayersModel(e);case 2:return this.model=t.sent,t.abrupt("return",this);case 4:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"generate",value:function(){var t=(0,o.default)(a.default.mark(function t(e,n){return a.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",(0,l.default)(this.generateInternal(e),n));case 1:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"loadAsync",value:function(t){var e=this;return new i.default(function(n,r){e.ready||r(),loadImage(t,function(t){n(t)})})}},{key:"getBlob",value:function(t){var e=this;return new i.default(function(n,r){e.ready||r(),t.toBlob(function(t){n(t)})})}},{key:"generateInternal",value:function(){var t=(0,o.default)(a.default.mark(function t(e){var n,i,o,s,u,l,d,h,p,m,g,v,y=this;return a.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=c.tidy(function(){y.latentDim=c.randomUniform([1,16]);var t=y.labels.indexOf(e);if(t<0)return console.log("Wrong input of the label!"),[void 0,void 0];y.labelVector=y.labelVector.map(function(){return 0}),y.labelVector[t+1]=1;var n=c.tensor([y.labelVector]),r=y.model.predict([y.latentDim,n]);return r.reshape([r.shape[1],r.shape[2],r.shape[3]])}),t.next=3,c.browser.toPixels(n);case 3:for(i=t.sent,n.dispose(),o=document.createElement("canvas"),s=o.getContext("2d"),u=(0,r.default)(n.shape,2),l=u[0],d=u[1],o.width=l,o.height=d,h=s.createImageData(l,d),p=h.data,m=0;m<l*d*4;m+=1)p[m]=i[m];return s.putImageData(h,0,0),t.t0=URL,t.next=17,this.getBlob(o);case 17:if(t.t1=t.sent,g=t.t0.createObjectURL.call(t.t0,t.t1),v=void 0,!f.default.checkP5()){t.next=24;break}return t.next=23,this.loadAsync(g);case 23:v=t.sent;case 24:return t.abrupt("return",{src:g,raws:i,image:v});case 25:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"jsonLoader",value:function(){var t=(0,o.default)(a.default.mark(function t(){var e=this;return a.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new i.default(function(t,n){var r=new XMLHttpRequest;r.open("GET",e.modelPath),r.onload=function(){var e=JSON.parse(r.responseText);t(e)},r.onerror=function(t){n(t)},r.send()}));case 1:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()}]),t}();e.default=function(t,e){return new h(t,e)}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=d(n(14)),i=d(n(9)),a=d(n(8)),o=d(n(7)),s=d(n(10)),u=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(4)),c=d(n(15)),l=n(46),f=d(n(64));function d(t){return t&&t.__esModule?t:{default:t}}var h={modelPath:"https://raw.githubusercontent.com/zaidalyafeai/HostedModels/master/unet-128/model.json",imageSize:128,returnTensors:!1},p=function(){function t(e,n,r){(0,o.default)(this,t),this.modelReady=!1,this.isPredicting=!1,this.config={modelPath:void 0!==n.modelPath?n.modelPath:h.modelPath,imageSize:void 0!==n.imageSize?n.imageSize:h.imageSize,returnTensors:void 0!==n.returnTensors?n.returnTensors:h.returnTensors},this.ready=(0,c.default)(this.loadModel(),r)}return(0,s.default)(t,[{key:"loadModel",value:function(){var t=(0,a.default)(i.default.mark(function t(){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,u.loadLayersModel(this.config.modelPath);case 2:return this.model=t.sent,this.modelReady=!0,t.abrupt("return",this);case 5:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"segment",value:function(){var t=(0,a.default)(i.default.mark(function t(e,n){var a,o;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.ready;case 2:return a=void 0,o=n,e instanceof HTMLImageElement||e instanceof HTMLVideoElement||e instanceof HTMLCanvasElement||e instanceof ImageData?a=e:"object"===(void 0===e?"undefined":(0,r.default)(e))&&(e.elt instanceof HTMLImageElement||e.elt instanceof HTMLVideoElement||e.elt instanceof HTMLCanvasElement||e.elt instanceof ImageData)?a=e.elt:"function"==typeof e&&(a=this.video,o=e),t.abrupt("return",(0,c.default)(this.segmentInternal(a),o));case 6:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"convertToP5Image",value:function(){var t=(0,a.default)(i.default.mark(function t(e){var n,r;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,f.default.rawToBlob(e,this.config.imageSize,this.config.imageSize);case 2:return n=t.sent,t.next=5,f.default.blobToP5Image(n);case 5:return r=t.sent,t.abrupt("return",r);case 7:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"segmentInternal",value:function(){var e=(0,a.default)(i.default.mark(function e(n){var r,a,o,s,c,d,h,p,m,g,v,y,b,x,w=this;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ready;case 2:if(!(n instanceof HTMLVideoElement)){e.next=5;break}return e.next=5,u.nextFrame();case 5:return this.isPredicting=!0,r=u.tidy(function(){var t=u.browser.fromPixels(n).toFloat(),e=u.image.resizeBilinear(t,[w.config.imageSize,w.config.imageSize]).div(u.scalar(255)),r=e.expandDims(0),i=w.model.predict(r),a=u.ones([128,128,1]).tile([1,1,1]);e=e.concat(a,2);var o=i.squeeze([0]),s=(o=(o=o.tile([1,1,4])).sub(.3).sign().relu().neg().add(1)).mul(e),c=i.squeeze([0]),l=(c=(c=c.tile([1,1,4])).sub(.3).sign().relu()).mul(e),f=u.ones([128,128,1]).tile([1,1,1]).mul(255),d=i.squeeze([0]);return{featureMask:s,backgroundMask:l,segmentation:d=(d=u.cast(d.tile([1,1,3]).sub(.3).sign().relu().mul(255),"int32")).concat(f,2)}}),a=r.featureMask,o=r.backgroundMask,s=r.segmentation,this.isPredicting=!1,e.next=10,u.browser.toPixels(a);case 10:return c=e.sent,e.next=13,u.browser.toPixels(o);case 13:return d=e.sent,e.next=16,u.browser.toPixels(s);case 16:if(h=e.sent,p=(0,l.array3DToImage)(a),m=(0,l.array3DToImage)(o),g=t.dataURLtoBlob(p.src),v=t.dataURLtoBlob(m.src),y=void 0,b=void 0,x=void 0,!f.default.checkP5()){e.next=34;break}return e.next=27,this.convertToP5Image(c);case 27:return y=e.sent,e.next=30,this.convertToP5Image(d);case 30:return b=e.sent,e.next=33,this.convertToP5Image(h);case 33:x=e.sent;case 34:return this.config.returnTensors||(a.dispose(),o.dispose(),s.dispose()),e.abrupt("return",{segmentation:h,blob:{featureMask:g,backgroundMask:v},tensor:{featureMask:a,backgroundMask:o},raw:{featureMask:c,backgroundMask:d},featureMask:y,backgroundMask:b,mask:x});case 36:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()}],[{key:"dataURLtoBlob",value:function(t){for(var e=t.split(","),n=e[0].match(/:(.*?);/)[1],r=atob(e[1]),i=r.length,a=new Uint8Array(i);i;)a[i]=r.charCodeAt(i),i-=1;return new Blob([a],{type:n})}}]),t}();e.default=function(t,e,n){var i=null,a={},o=n;return t instanceof HTMLVideoElement?i=t:"object"===(void 0===t?"undefined":(0,r.default)(t))&&t.elt instanceof HTMLVideoElement?i=t.elt:"function"==typeof t?o=t:"object"===(void 0===t?"undefined":(0,r.default)(t))&&(a=t),"object"===(void 0===e?"undefined":(0,r.default)(e))?a=e:"function"==typeof e&&(o=e),new p(i,a,o)}},function(t,e,n){"use strict";var r=n(23),i=n(109),a=n(56),o=n(100);t.exports=function(t){r(r.S,t,{from:function(t){var e,n,r,s,u=arguments[1];return i(this),(e=void 0!==u)&&i(u),void 0==t?new this:(n=[],e?(r=0,s=a(u,arguments[2],2),o(t,!1,function(t){n.push(s(t,r++))})):o(t,!1,n.push,n),new this(n))}})}},function(t,e,n){n(319)("Set")},function(t,e,n){"use strict";var r=n(23);t.exports=function(t){r(r.S,t,{of:function(){for(var t=arguments.length,e=new Array(t);t--;)e[t]=arguments[t];return new this(e)}})}},function(t,e,n){n(321)("Set")},function(t,e,n){var r=n(100);t.exports=function(t,e){var n=[];return r(t,!1,n.push,n,e),n}},function(t,e,n){var r=n(116),i=n(323);t.exports=function(t){return function(){if(r(this)!=t)throw TypeError(t+"#toJSON isn't generic");return i(this)}}},function(t,e,n){var r=n(23);r(r.P+r.R,"Set",{toJSON:n(324)("Set")})},function(t,e,n){var r=n(38),i=n(221),a=n(25)("species");t.exports=function(t){var e;return i(t)&&("function"!=typeof(e=t.constructor)||e!==Array&&!i(e.prototype)||(e=void 0),r(e)&&null===(e=e[a])&&(e=void 0)),void 0===e?Array:e}},function(t,e,n){var r=n(326);t.exports=function(t,e){return new(r(t))(e)}},function(t,e,n){var r=n(56),i=n(163),a=n(66),o=n(122),s=n(327);t.exports=function(t,e){var n=1==t,u=2==t,c=3==t,l=4==t,f=6==t,d=5==t||f,h=e||s;return function(e,s,p){for(var m,g,v=a(e),y=i(v),b=r(s,p,3),x=o(y.length),w=0,k=n?h(e,x):u?h(e,0):void 0;x>w;w++)if((d||w in y)&&(g=b(m=y[w],w,v),t))if(n)k[w]=g;else if(g)switch(t){case 3:return!0;case 5:return m;case 6:return w;case 2:k.push(m)}else if(l)return!1;return f?-1:c||l?l:k}}},function(t,e,n){"use strict";var r=n(26),i=n(23),a=n(146),o=n(69),s=n(60),u=n(148),c=n(100),l=n(151),f=n(38),d=n(102),h=n(39).f,p=n(328)(0),m=n(32);t.exports=function(t,e,n,g,v,y){var b=r[t],x=b,w=v?"set":"add",k=x&&x.prototype,_={};return m&&"function"==typeof x&&(y||k.forEach&&!o(function(){(new x).entries().next()}))?(x=e(function(e,n){l(e,x,t,"_c"),e._c=new b,void 0!=n&&c(n,v,e[w],e)}),p("add,clear,delete,forEach,get,has,set,keys,values,entries,toJSON".split(","),function(t){var e="add"==t||"set"==t;t in k&&(!y||"clear"!=t)&&s(x.prototype,t,function(n,r){if(l(this,x,t),!e&&y&&!f(n))return"get"==t&&void 0;var i=this._c[t](0===n?0:n,r);return e?this:i})}),y||h(x.prototype,"size",{get:function(){return this._c.size}})):(x=g.getConstructor(e,t,v,w),u(x.prototype,n),a.NEED=!0),d(x,t),_[t]=x,i(i.G+i.W+i.F,_),y||g.setStrong(x,t,v),x}},function(t,e,n){"use strict";var r=n(39).f,i=n(117),a=n(148),o=n(56),s=n(151),u=n(100),c=n(152),l=n(231),f=n(224),d=n(32),h=n(146).fastKey,p=n(202),m=d?"_s":"size",g=function(t,e){var n,r=h(e);if("F"!==r)return t._i[r];for(n=t._f;n;n=n.n)if(n.k==e)return n};t.exports={getConstructor:function(t,e,n,c){var l=t(function(t,r){s(t,l,e,"_i"),t._t=e,t._i=i(null),t._f=void 0,t._l=void 0,t[m]=0,void 0!=r&&u(r,n,t[c],t)});return a(l.prototype,{clear:function(){for(var t=p(this,e),n=t._i,r=t._f;r;r=r.n)r.r=!0,r.p&&(r.p=r.p.n=void 0),delete n[r.i];t._f=t._l=void 0,t[m]=0},delete:function(t){var n=p(this,e),r=g(n,t);if(r){var i=r.n,a=r.p;delete n._i[r.i],r.r=!0,a&&(a.n=i),i&&(i.p=a),n._f==r&&(n._f=i),n._l==r&&(n._l=a),n[m]--}return!!r},forEach:function(t){p(this,e);for(var n,r=o(t,arguments.length>1?arguments[1]:void 0,3);n=n?n.n:this._f;)for(r(n.v,n.k,this);n&&n.r;)n=n.p},has:function(t){return!!g(p(this,e),t)}}),d&&r(l.prototype,"size",{get:function(){return p(this,e)[m]}}),l},def:function(t,e,n){var r,i,a=g(t,e);return a?a.v=n:(t._l=a={i:i=h(e,!0),k:e,v:n,p:r=t._l,n:void 0,r:!1},t._f||(t._f=a),r&&(r.n=a),t[m]++,"F"!==i&&(t._i[i]=a)),t},getEntry:g,setStrong:function(t,e,n){c(t,e,function(t,n){this._t=p(t,e),this._k=n,this._l=void 0},function(){for(var t=this._k,e=this._l;e&&e.r;)e=e.p;return this._t&&(this._l=e=e?e.n:this._t._f)?l(0,"keys"==t?e.k:"values"==t?e.v:[e.k,e.v]):(this._t=void 0,l(1))},n?"entries":"values",!n,!0),f(e)}}},function(t,e,n){"use strict";var r=n(330),i=n(202);t.exports=n(329)("Set",function(t){return function(){return t(this,arguments.length>0?arguments[0]:void 0)}},{add:function(t){return r.def(i(this,"Set"),t=0===t?0:t,t)}},r)},function(t,e,n){n(153),n(85),n(101),n(331),n(325),n(322),n(320),t.exports=n(18).Set},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=new(function(t){return t&&t.__esModule?t:{default:t}}(n(203)).default)(["alarm_clock","ambulance","angel","ant","antyoga","backpack","barn","basket","bear","bee","beeflower","bicycle","bird","book","brain","bridge","bulldozer","bus","butterfly","cactus","calendar","castle","cat","catbus","catpig","chair","couch","crab","crabchair","crabrabbitfacepig","cruise_ship","diving_board","dog","dogbunny","dolphin","duck","elephant","elephantpig","eye","face","fan","fire_hydrant","firetruck","flamingo","flower","floweryoga","frog","frogsofa","garden","hand","hedgeberry","hedgehog","helicopter","kangaroo","key","lantern","lighthouse","lion","lionsheep","lobster","map","mermaid","monapassport","monkey","mosquito","octopus","owl","paintbrush","palm_tree","parrot","passport","peas","penguin","pig","pigsheep","pineapple","pool","postcard","power_outlet","rabbit","rabbitturtle","radio","radioface","rain","rhinoceros","rifle","roller_coaster","sandwich","scorpion","sea_turtle","sheep","skull","snail","snowflake","speedboat","spider","squirrel","steak","stove","strawberry","swan","swing_set","the_mona_lisa","tiger","toothbrush","toothpaste","tractor","trombone","truck","whale","windmill","yoga","yogabicycle","everything"]);e.default=r},function(t,e,n){"use strict";function r(t){return new Uint8Array(atob(t).split("").map(function(t){return t.charCodeAt(0)}))}Object.defineProperty(e,"__esModule",{value:!0}),e.stringToUint8array=r,e.stringToArray=function(t){var e=r(t);return new Int16Array(e.buffer)};var i=!1,a=0;function o(){if(i)return i=!1,a;var t=2*Math.random()-1,e=2*Math.random()-1,n=t*t+e*e;if(0===n||n>1)return o();var r=Math.sqrt(-2*Math.log(n)/n);return a=e*r,i=!0,t*r}function s(t,e){return Math.random()*(e-t)+t}function u(t,e){return t+o()*e}function c(t,e){void 0===e&&(e=2);var n=e;function r(t,e){return[t[0]-e[0],t[1]-e[1]]}function i(t,e){return t[0]*e[0]+t[1]*e[1]}function a(t){return t[0]*t[0]+t[1]*t[1]}function o(t,e){return a(r(t,e))}var s,u,c,l,f=t.length,d=[],h=n*n,p=[],m=[];for(p[0]=t[0],s=u=1,l=0;s<f;s++)o(t[s],t[l])<h||(p[u++]=t[s],l=s);for(l<f-1&&(p[u++]=t[f-1]),m[0]=m[u-1]=1,function t(e,n,s,u,c){if(!(u<=s+1)){for(var l,f,d,h,p=s,m=0,g=e*e,v=[n[s],n[u]],y=r(v[1],v[0]),b=a(y),x=s+1;x<u;x++)(d=i(r(n[x],v[0]),y))<=0?h=o(n[x],v[0]):b<=d?h=o(n[x],v[1]):(f=d/b,l=[v[0][0]+f*y[0],v[0][1]+f*y[1]],h=o(n[x],l)),h<=m||(p=x,m=h);m>g&&(c[p]=1,t(e,n,s,p,c),t(e,n,p,u,c))}}(n,p,0,u-1,m),s=c=0;s<u;s++)m[s]&&(d[c++]=p[s]);return d}e.gaussRandom=o,e.randf=s,e.randi=function(t,e){return Math.floor(Math.random()*(e-t)+t)},e.randn=u,e.birandn=function(t,e,n,r,i){var a=u(0,1),o=u(0,1);return[Math.sqrt(1-i*i)*n*a+i*n*o+t,r*o+e]},e.sampleSoftmax=function(t){var e,n=s(0,1),r=t.length,i=0;for(e=0;e<r;e++)if((i+=t[e])>=n)return e;return console.log("error sampling pi index"),-1},e.simplifyLine=c,e.simplifyLines=function(t,e){var n=[],r=2;e&&(r=e);for(var i=0;i<t.length;i++)n.push(c(t[i],r));return n},e.linesToStrokes=function(t){var e,n,r,i,a,o,s,u,c,l,f=0,d=0,h=[];for(s=0;s<t.length;s++)if((c=t[s].length)>1)for(u=0;u<c;u++)e=(l=t[s][u])[0],n=l[1],u===c-1?(o=1,a=0):(o=0,a=1),r=e-f,i=n-d,f=e,d=n,h.push([r,i,a,o,0]);return h.push([0,0,0,0,1]),h.slice(1)},e.lineToStroke=function(t,e){var n,r,i,a,o,s,u,c,l,f,d,h=[];if(l=e[0],f=e[1],(i=t.length)>1)for(d=0;d<i;d++)u=(a=t[d])[0],c=a[1],d===i-1?(r=1,n=0):(r=0,n=1),o=u-l,s=c-f,l=u,f=c,h.push([o,s,n,r,0]);return h}},function(t,e,n){"use strict";var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})},i=this&&this.__generator||function(t,e){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=(i=o.trys).length>0&&i[i.length-1])&&(6===a[0]||2===a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}};Object.defineProperty(e,"__esModule",{value:!0});var a=n(0),o=n(334),s=function(){function t(t){this.NMIXTURE=20,this.checkpointURL=t,this.initialized=!1}return t.prototype.isInitialized=function(){return this.initialized},t.prototype.instantiateFromJSON=function(t,e,n){var r;this.forgetBias=a.scalar(1),this.info=t,this.setPixelFactor(2),this.weightDims=e,this.numUnits=this.weightDims[0][0];this.weights=[];for(var i=0;i<n.length;i++){for(var s=(r=new Float32Array(o.stringToArray(n[i]))).length,u=0;u<s;u++)r[u]=10*r[u]/32767;this.weights.push(r)}this.outputKernel=a.tensor2d(this.weights[0],[this.weightDims[0][0],this.weightDims[0][1]]),this.outputBias=a.tensor1d(this.weights[1]);var c=a.tensor2d(this.weights[2],[this.weightDims[2][0],this.weightDims[2][1]]),l=a.tensor2d(this.weights[3],[this.weightDims[3][0],this.weightDims[3][1]]);this.lstmKernel=a.concat2d([c,l],0),this.lstmBias=a.tensor1d(this.weights[4]),this.rawVars=[this.outputKernel,this.outputBias,this.lstmKernel,this.lstmBias]},t.prototype.initialize=function(){return r(this,void 0,void 0,function(){var t;return i(this,function(e){switch(e.label){case 0:return this.dispose(),[4,fetch(this.checkpointURL).then(function(t){return t.json()})];case 1:return t=e.sent(),this.instantiateFromJSON(t[0],t[1],t[2]),this.initialized=!0,console.log("Initialized SketchRNN."),[2]}})})},t.prototype.dispose=function(){if(this.rawVars){for(var t=0;t<this.rawVars.length;t++)this.rawVars[t].dispose();this.rawVars=void 0}this.forgetBias&&(this.forgetBias.dispose(),this.forgetBias=void 0),this.initialized=!1},t.prototype.setPixelFactor=function(t){this.pixelFactor=t,this.scaleFactor=this.info.scale_factor/this.pixelFactor},t.prototype.update=function(t,e){var n=this,r=a.tidy(function(){var r=n.numUnits,i=n.scaleFactor,o=[t[0]/i,t[1]/i,t[2],t[3],t[4]],s=a.tensor2d(o,[1,5]),u=a.tensor2d(e.c,[1,r]),c=a.tensor2d(e.h,[1,r]),l=a.basicLSTMCell(n.forgetBias,n.lstmKernel,n.lstmBias,s,u,c);return a.concat(l,1)}),i=r.dataSync();r.dispose();var o=i.slice(0,this.numUnits),s=i.slice(this.numUnits,2*this.numUnits);return{c:new Float32Array(o),h:new Float32Array(s)}},t.prototype.updateStrokes=function(t,e,n){var r=this,i=a.tidy(function(){var i,o,s,u,c,l=r.numUnits,f=r.scaleFactor,d=t.length;n&&(d=n),s=a.tensor2d(e.c,[1,l]),u=a.tensor2d(e.h,[1,l]);for(var h=0;h<d;h++)i=[t[h][0]/f,t[h][1]/f,t[h][2],t[h][3],t[h][4]],o=a.tensor2d(i,[1,5]),s=(c=a.basicLSTMCell(r.forgetBias,r.lstmKernel,r.lstmBias,o,s,u))[0],u=c[1];return a.concat(c,1)}),o=i.dataSync();i.dispose();var s=o.slice(0,this.numUnits),u=o.slice(this.numUnits,2*this.numUnits);return{c:new Float32Array(s),h:new Float32Array(u)}},t.prototype.getPDF=function(t,e,n){var r=this;void 0===e&&(e=.65);var i=e,o=.5+.5*i;n&&(o=n);var s=this.NMIXTURE,u=a.tidy(function(){var e=r.numUnits,n=a.tensor2d(t.h,[1,e]),u=a.scalar(Math.sqrt(i)),c=a.scalar(o),l=a.add(a.matMul(n,r.outputKernel),r.outputBias).squeeze(),f=a.split(l,[3,6*s]),d=f[0],h=f[1],p=a.split(h,6),m=p[0],g=p[1],v=p[2],y=p[3],b=p[4],x=p[5],w=a.softmax(d.div(c)),k=[a.softmax(m.div(c)),g,v,a.exp(y).mul(u),a.exp(b).mul(u),a.tanh(x),w];return a.concat(k)}),c=u.dataSync();return u.dispose(),{pi:new Float32Array(c.slice(0,s)),muX:new Float32Array(c.slice(1*s,2*s)),muY:new Float32Array(c.slice(2*s,3*s)),sigmaX:new Float32Array(c.slice(3*s,4*s)),sigmaY:new Float32Array(c.slice(4*s,15*s)),corr:new Float32Array(c.slice(5*s,6*s)),pen:new Float32Array(c.slice(6*s,6*s+3))}},t.prototype.zeroState=function(){return{c:new Float32Array(this.numUnits),h:new Float32Array(this.numUnits)}},t.prototype.copyState=function(t){return{c:new Float32Array(t.c),h:new Float32Array(t.h)}},t.prototype.zeroInput=function(){return[0,0,1,0,0]},t.prototype.sample=function(t){var e=o.sampleSoftmax(t.pi),n=t.muX[e],r=t.muY[e],i=t.sigmaX[e],a=t.sigmaY[e],s=t.corr[e],u=[0,0,0];u[o.sampleSoftmax(t.pen)]=1;var c=o.birandn(n,r,i,a,s);return[c[0]*this.scaleFactor,c[1]*this.scaleFactor,u[0],u[1],u[2]]},t.prototype.simplifyLine=function(t,e){return o.simplifyLine(t,e)},t.prototype.simplifyLines=function(t,e){return o.simplifyLines(t,e)},t.prototype.linesToStroke=function(t){return o.linesToStrokes(t)},t.prototype.lineToStroke=function(t,e){return o.lineToStroke(t,e)},t}();e.SketchRNN=s},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(335);e.SketchRNN=r.SketchRNN},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(4);e.tf=r,function(t){for(var n in t)e.hasOwnProperty(n)||(e[n]=t[n])}(n(336))},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=f(n(9)),i=f(n(8)),a=f(n(7)),o=f(n(10)),s=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(337)),u=f(n(15)),c=f(n(333)),l=f(n(142));function f(t){return t&&t.__esModule?t:{default:t}}var d={modelPath:"https://storage.googleapis.com/quickdraw-models/sketchRNN/large_models/",modelPath_large:"https://storage.googleapis.com/quickdraw-models/sketchRNN/models/",modelPath_small:"https://storage.googleapis.com/quickdraw-models/sketchRNN/models/",PATH_END:".gen.json",temperature:.65,pixelFactor:3},h=function(){function t(e,n){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];(0,a.default)(this,t);var i=e;if(this.config={temperature:.65,pixelFactor:3,modelPath:d.modelPath,modelPath_small:d.modelPath_small,modelPath_large:d.modelPath_large,PATH_END:d.PATH_END},!0===l.default.isAbsoluteURL(i)){var o=l.default.getModelPath(i);this.config.modelPath=o}else{if(!c.default.has(i))return console.log("no model found!"),this;i=(r?this.config.modelPath:this.config.modelPath_small)+i+this.config.PATH_END,this.config.modelPath=i}this.model=new s.SketchRNN(this.config.modelPath),this.penState=this.model.zeroInput(),this.ready=(0,u.default)(this.model.initialize(),n)}return(0,o.default)(t,[{key:"generateInternal",value:function(){var t=(0,i.default)(r.default.mark(function t(e,n){var i,a,o,s;return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return i=+e.temperature||this.config.temperature,a=+e.pixelFactor||this.config.pixelFactor,t.next=4,this.ready;case 4:return this.rnnState||(this.rnnState=this.model.zeroState(),this.model.setPixelFactor(a)),Array.isArray(n)&&n.length&&(this.rnnState=this.model.updateStrokes(n,this.rnnState)),this.rnnState=this.model.update(this.penState,this.rnnState),o=this.model.getPDF(this.rnnState,i),this.penState=this.model.sample(o),s={dx:this.penState[0],dy:this.penState[1]},1===this.penState[2]?s.pen="down":1===this.penState[3]?s.pen="up":1===this.penState[4]&&(s.pen="end"),t.abrupt("return",s);case 12:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"generate",value:function(){var t=(0,i.default)(r.default.mark(function t(e,n,i){var a,o,s,c;return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return a=void 0,o=void 0,s=void 0,"function"==typeof e?(o={},s=[],a=e):Array.isArray(e)?(o={},s=e,a=n):"function"==typeof n?(o=e||{},s=[],a=n):(o=e||{},s=n||[],a=i),c=s.map(function(t){var e="up"===t.pen?1:0,n="down"===t.pen?1:0,r="end"===t.pen?1:0;return[t.dx,t.dy,n,e,r]}),t.abrupt("return",(0,u.default)(this.generateInternal(o,c),a));case 6:case"end":return t.stop()}},t,this)}));return function(e,n,r){return t.apply(this,arguments)}}()},{key:"reset",value:function(){this.penState=this.model.zeroInput(),this.rnnState&&(this.rnnState=this.model.zeroState())}}]),t}();e.default=function(t,e){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return new h(t,e,n)}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=s(n(24)),i=s(n(7)),a=s(n(10)),o=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(4));function s(t){return t&&t.__esModule?t:{default:t}}var u=function(){function t(e){(0,i.default)(this,t),this.urlPath=e}return(0,a.default)(t,[{key:"getAllVariables",value:function(){var t=this;return new r.default(function(e,n){var r={};if(t.urlPath in r)e(r[t.urlPath]);else{var i=new XMLHttpRequest;i.open("GET",t.urlPath,!0),i.responseType="arraybuffer",i.onload=function(){if(200===i.status){var a=i.response;if(a){for(var s=[],u=0;u<a.byteLength;){var c=new Uint8Array(a.slice(u,u+4));u+=4;var l=(c[0]<<24)+(c[1]<<16)+(c[2]<<8)+c[3];s.push(a.slice(u,u+l)),u+=l}for(var f=JSON.parse(new TextDecoder("utf8").decode(s[0])),d=new Float32Array(s[1]),h=new Uint8Array(s[2]),p=new Float32Array(h.length),m=0;m<p.length;m+=1)p[m]=d[h[m]];var g={};u=0;for(var v=0;v<f.length;v+=1){var y=f[v].shape,b=y.reduce(function(t,e){return t*e}),x=p.slice(u,u+b),w=o.tensor1d(x,"float32");g[f[v].name]=w.reshape(y),u+=b}r[t.urlPath]=g,e(g)}else n(new Error("invalid arraybuffer"))}else n(new Error("missing model"))},i.send(null)}})}}]),t}();e.default=u},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=f(n(9)),i=f(n(8)),a=f(n(7)),o=f(n(10)),s=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(4)),u=f(n(339)),c=n(46),l=f(n(15));function f(t){return t&&t.__esModule?t:{default:t}}var d=function(){function t(e,n){(0,a.default)(this,t),this.ready=(0,l.default)(this.loadCheckpoints(e),n)}return(0,o.default)(t,[{key:"loadCheckpoints",value:function(){var t=(0,i.default)(r.default.mark(function t(e){var n;return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=new u.default(e),t.next=3,n.getAllVariables();case 3:return this.variables=t.sent,t.abrupt("return",this);case 5:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"transfer",value:function(){var t=(0,i.default)(r.default.mark(function t(e,n){return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",(0,l.default)(this.transferInternal(e),n));case 1:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"transferInternal",value:function(){var e=(0,i.default)(r.default.mark(function e(n){var i,a=this;return r.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return i=(0,c.array3DToImage)(s.tidy(function(){var e=s.browser.fromPixels(n),r=e.dataSync(),i=s.tensor3d(r,e.shape),o=s.div(i,s.scalar(255)),u=t.preprocess(o),c=[],l=a.variables["generator/encoder_1/conv2d/kernel"],f=a.variables["generator/encoder_1/conv2d/bias"],d=t.conv2d(u,l,f);c.push(d);for(var h=2;h<=8;h+=1){var p="generator/encoder_"+h.toString();l=a.variables[p+"/conv2d/kernel"];var m=a.variables[p+"/conv2d/bias"],g=c[c.length-1],v=s.leakyRelu(g,.2);d=t.conv2d(v,l,m);var y=a.variables[p+"/batch_normalization/gamma"],b=a.variables[p+"/batch_normalization/beta"],x=t.batchnorm(d,y,b);c.push(x)}for(var w=8;w>=2;w-=1){var k=void 0;if(8===w)k=c[c.length-1];else{var _=w-1;k=s.concat([c[c.length-1],c[_]],2)}var E=s.relu(k),O="generator/decoder_"+w.toString();l=a.variables[O+"/conv2d_transpose/kernel"],f=a.variables[O+"/conv2d_transpose/bias"],d=t.deconv2d(E,l,f);var S=a.variables[O+"/batch_normalization/gamma"],C=a.variables[O+"/batch_normalization/beta"],A=t.batchnorm(d,S,C);c.push(A)}var N=s.concat([c[c.length-1],c[0]],2),T=s.relu(N);l=a.variables["generator/decoder_1/conv2d_transpose/kernel"];var I=a.variables["generator/decoder_1/conv2d_transpose/bias"];d=t.deconv2d(T,l,I),T=s.tanh(d),c.push(T);var D=c[c.length-1];return t.deprocess(D)})),e.next=3,s.nextFrame();case 3:return e.abrupt("return",i);case 4:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()}],[{key:"preprocess",value:function(t){var e=s.tidy(function(){return s.sub(s.mul(t,s.scalar(2)),s.scalar(1))});return t.dispose(),e}},{key:"deprocess",value:function(t){var e=s.tidy(function(){return s.div(s.add(t,s.scalar(1)),s.scalar(2))});return t.dispose(),e}},{key:"batchnorm",value:function(t,e,n){var r=s.tidy(function(){var r=s.moments(t,[0,1]);return s.batchNorm(t,r.mean,r.variance,n,e,1e-5)});return t.dispose(),r}},{key:"conv2d",value:function(t,e){var n=e.clone(),r=s.tidy(function(){return s.conv2d(t,n,[2,2],"same")});return t.dispose(),n.dispose(),r}},{key:"deconv2d",value:function(t,e,n){var r=s.tidy(function(){var r=s.conv2dTranspose(t,e,[2*t.shape[0],2*t.shape[1],e.shape[2]],[2,2],"same");return s.add(r,n)});return t.dispose(),e.dispose(),n.dispose(),r}}]),t}();e.default=function(t,e){var n=new d(t,e);return e?n:n.ready}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});e.default=function(t){for(var e=Math.random(),n=0,r=void 0,i=0;i<t.length;i+=1)if(e<(n+=t[i])){r=i;break}return r}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=p(n(47)),i=p(n(9)),a=p(n(54)),o=p(n(8)),s=p(n(7)),u=p(n(10)),c=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(4)),l=p(n(55)),f=p(n(341)),d=p(n(204)),h=p(n(15));function p(t){return t&&t.__esModule?t:{default:t}}var m=/cell_[0-9]|lstm_[0-9]/gi,g=/weights|weight|kernel|kernels|w/gi,v=/softmax/gi,y=function(){function t(e,n){(0,s.default)(this,t),this.ready=!1,this.model={},this.cellsAmount=0,this.cells=[],this.zeroState={c:[],h:[]},this.state={c:[],h:[]},this.vocab={},this.vocabSize=0,this.probabilities=[],this.defaults={seed:"a",length:20,temperature:.5,stateful:!1},this.ready=(0,h.default)(this.loadCheckpoints(e),n)}return(0,u.default)(t,[{key:"resetState",value:function(){this.state=this.zeroState}},{key:"setState",value:function(t){this.state=t}},{key:"getState",value:function(){return this.state}},{key:"loadCheckpoints",value:function(){var t=(0,o.default)(i.default.mark(function t(e){var n,r,o=this;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=new d.default(e),t.next=3,n.getAllVariables();case 3:return r=t.sent,(0,a.default)(r).forEach(function(t){t.match(m)?t.match(g)?(o.model["Kernel_"+t.match(/[0-9]/)[0]]=r[t],o.cellsAmount+=1):o.model["Bias_"+t.match(/[0-9]/)[0]]=r[t]:t.match(v)?t.match(g)?o.model.fullyConnectedWeights=r[t]:o.model.fullyConnectedBiases=r[t]:o.model[t]=r[t]}),t.next=7,this.loadVocab(e);case 7:return t.next=9,this.initCells();case 9:return t.abrupt("return",this);case 10:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"loadVocab",value:function(){var t=(0,o.default)(i.default.mark(function t(e){var n,r;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,l.default.get(e+"/vocab.json");case 3:return n=t.sent,r=n.data,this.vocab=r,this.vocabSize=(0,a.default)(r).length,t.abrupt("return",this.vocab);case 10:return t.prev=10,t.t0=t.catch(0),t.abrupt("return",t.t0);case 13:case"end":return t.stop()}},t,this,[[0,10]])}));return function(e){return t.apply(this,arguments)}}()},{key:"initCells",value:function(){var t=(0,o.default)(i.default.mark(function t(){var e,n,r,a=this;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:for(this.cells=[],this.zeroState={c:[],h:[]},e=c.tensor(1),n=function(t){return function(n,r,i){return c.basicLSTMCell(e,a.model["Kernel_"+t],a.model["Bias_"+t],n,r,i)}},r=0;r<this.cellsAmount;r+=1)this.zeroState.c.push(c.zeros([1,this.model["Bias_"+r].shape[0]/4])),this.zeroState.h.push(c.zeros([1,this.model["Bias_"+r].shape[0]/4])),this.cells.push(n(r));this.state=this.zeroState;case 6:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"generateInternal",value:function(){var t=(0,o.default)(i.default.mark(function t(e){var n,o,s,u,l,d,h,p,m,g,v,y,b,x,w,k,_,E,O,S=this;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.ready;case 2:n=e.seed||this.defaults.seed,o=+e.length||this.defaults.length,s=+e.temperature||this.defaults.temperature,e.stateful||this.defaults.stateful||(this.state=this.zeroState),u=[],l=(0,r.default)(n),d=[],l.forEach(function(t){d.push(S.vocab[t])}),h=d[0],p=[],m=0;case 14:if(!(m<l.length+o+-1)){t.next=36;break}return t.next=17,c.buffer([1,this.vocabSize]);case 17:return(g=t.sent).set(1,0,h),v=g.toTensor(),y=void 0,this.model.embedding?(b=c.matMul(v,this.model.embedding),y=c.multiRNNCell(this.cells,b,this.state.c,this.state.h)):y=c.multiRNNCell(this.cells,v,this.state.c,this.state.h),this.state.c=y[0],this.state.h=y[1],x=this.state.h[1],w=c.matMul(x,this.model.fullyConnectedWeights),k=c.add(w,this.model.fullyConnectedBiases),_=c.div(k,c.tensor(s)),E=c.exp(_),t.next=31,c.div(E,c.sum(E)).data();case 31:p=t.sent,m<l.length-1?h=d[m+1]:(h=(0,f.default)(p),u.push(h));case 33:m+=1,t.next=14;break;case 36:return O="",u.forEach(function(t){var e=(0,a.default)(S.vocab).find(function(e){return S.vocab[e]===t});e&&(O+=e)}),this.probabilities=p,t.abrupt("return",{sample:O,state:this.state});case 40:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"reset",value:function(){this.state=this.zeroState}},{key:"generate",value:function(){var t=(0,o.default)(i.default.mark(function t(e,n){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.reset(),t.abrupt("return",(0,h.default)(this.generateInternal(e),n));case 2:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"predict",value:function(){var t=(0,o.default)(i.default.mark(function t(e,n){var r,o,s,u,l,d,h,p,m,g,v=this;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=[],o=e>0?e:.1,s=this.state.h[1],u=c.matMul(s,this.model.fullyConnectedWeights),l=c.add(u,this.model.fullyConnectedBiases),d=c.div(l,c.tensor(o)),h=c.exp(d),t.next=9,c.div(h,c.sum(h)).data();case 9:return r=t.sent,p=(0,f.default)(r),m=(0,a.default)(this.vocab).find(function(t){return v.vocab[t]===p}),this.probabilities=r,n&&n(m),g=(0,a.default)(this.vocab).map(function(t){return{char:t,probability:v.probabilities[v.vocab[t]]}}),t.abrupt("return",{sample:m,probabilities:g});case 16:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"feed",value:function(){var t=(0,o.default)(i.default.mark(function t(e,n){var a,o,s,u,l,f,d,h,p=this;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.ready;case 2:a=(0,r.default)(e),o=[],a.forEach(function(t){o.push(p.vocab[t])}),s=o[0],u=0;case 7:if(!(u<a.length)){t.next=21;break}return t.next=10,c.buffer([1,this.vocabSize]);case 10:(l=t.sent).set(1,0,s),f=l.toTensor(),d=void 0,this.model.embedding?(h=c.matMul(f,this.model.embedding),d=c.multiRNNCell(this.cells,h,this.state.c,this.state.h)):d=c.multiRNNCell(this.cells,f,this.state.c,this.state.h),this.state.c=d[0],this.state.h=d[1],s=o[u];case 18:u+=1,t.next=7;break;case 21:n&&n();case 22:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()}]),t}();e.default=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"./",e=arguments[1];return new y(t,e)}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=y(n(14)),i=y(n(65)),a=y(n(9)),o=y(n(8)),s=y(n(98)),u=y(n(7)),c=y(n(10)),l=y(n(97)),f=y(n(96)),d=y(n(24)),h=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(4)),p=y(n(143)),m=y(n(204)),g=n(46),v=y(n(15));function y(t){return t&&t.__esModule?t:{default:t}}var b=200,x=function(t){return new d.default(function(e){var n=new Image(b,b);n.onload=function(){return e(n)},n.src=t.toDataURL()})},w=function(t){function e(t,n,r){(0,u.default)(this,e);var i=(0,l.default)(this,(e.__proto__||(0,s.default)(e)).call(this,n,b));return i.ready=!1,i.variableDictionary={},i.timesScalar=h.scalar(150),i.plusScalar=h.scalar(127.5),i.epsilonScalar=h.scalar(.001),i.video=null,i.ready=(0,v.default)(i.load(t),r),i}return(0,f.default)(e,t),(0,c.default)(e,[{key:"load",value:function(){var t=(0,o.default)(a.default.mark(function t(e){return a.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.videoElt){t.next=4;break}return t.next=3,this.loadVideo();case 3:this.videoReady=!0;case 4:return t.next=6,this.loadCheckpoints(e);case 6:return t.abrupt("return",this);case 7:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"loadCheckpoints",value:function(){var t=(0,o.default)(a.default.mark(function t(e){var n;return a.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=new m.default(e),t.next=3,n.getAllVariables();case 3:this.variables=t.sent;case 4:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"instanceNorm",value:function(t,n){var r=this;return h.tidy(function(){var a=(0,i.default)(t.shape,3),o=a[0],s=a[1],u=a[2],c=h.moments(t,[0,1]),l=c.mean,f=c.variance,d=r.variables[e.getVariableName(n)],p=r.variables[e.getVariableName(n+1)],m=r.epsilonScalar,g=h.div(h.sub(t.asType("float32"),l),h.sqrt(h.add(f,m)));return h.add(h.mul(p,g),d).as3D(o,s,u)})}},{key:"convLayer",value:function(t,n,r,i){var a=h.conv2d(t,this.variables[e.getVariableName(i)],[n,n],"same"),o=this.instanceNorm(a,i+1);return r?h.relu(o):o}},{key:"residualBlock",value:function(t,e){var n=this.convLayer(t,1,!0,e),r=this.convLayer(n,1,!1,e+3);return h.add(r,t)}},{key:"convTransposeLayer",value:function(t,n,r,a){var o=(0,i.default)(t.shape,2),s=[o[0]*r,o[1]*r,n],u=h.conv2dTranspose(t,this.variables[e.getVariableName(a)],s,[r,r],"same"),c=this.instanceNorm(u,a+1);return h.relu(c)}},{key:"transfer",value:function(){var t=(0,o.default)(a.default.mark(function t(e,n){var i,o;return a.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(i=void 0,o=n,!(e instanceof HTMLVideoElement||e instanceof HTMLImageElement||e instanceof ImageData)){t.next=6;break}i=e,t.next=19;break;case 6:if(!(e instanceof HTMLCanvasElement)){t.next=12;break}return t.next=9,x(e);case 9:i=t.sent,t.next=19;break;case 12:if(!("object"===(void 0===e?"undefined":(0,r.default)(e))&&e.elt instanceof HTMLCanvasElement)){t.next=18;break}return t.next=15,x(e.elt);case 15:i=t.sent,t.next=19;break;case 18:"object"===(void 0===e?"undefined":(0,r.default)(e))&&(e.elt instanceof HTMLVideoElement||e.elt instanceof HTMLImageElement||e.elt instanceof ImageData)?i=e.elt:"function"==typeof e&&(i=this.video,o=e);case 19:return t.abrupt("return",(0,v.default)(this.transferInternal(i),o));case 20:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"transferInternal",value:function(){var t=(0,o.default)(a.default.mark(function t(e){var n,r,i=this;return a.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=h.browser.fromPixels(e),r=(0,g.array3DToImage)(h.tidy(function(){var t=i.convLayer(n,1,!0,0),e=i.convLayer(t,2,!0,3),r=i.convLayer(e,2,!0,6),a=i.residualBlock(r,9),o=i.residualBlock(a,15),s=i.residualBlock(o,21),u=i.residualBlock(s,27),c=i.residualBlock(u,33),l=i.convTransposeLayer(c,64,2,39),f=i.convTransposeLayer(l,32,2,42),d=i.convLayer(f,1,!1,45),p=h.tanh(d),m=h.mul(i.timesScalar,p),g=h.add(i.plusScalar,m),v=h.clipByValue(g,0,255);return h.div(v,h.scalar(255))})),n.dispose(),t.next=5,h.nextFrame();case 5:return t.abrupt("return",r);case 6:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()}],[{key:"getVariableName",value:function(t){return 0===t?"Variable":"Variable_"+t}}]),e}(p.default);e.default=function(t,e,n){var r=n;"function"==typeof e&&(r=e);var i=new w(t,e,r);return r?i:i.ready}},function(t,e,n){"use strict";n.r(e),n.d(e,"decodeMultiplePoses",function(){return R}),n.d(e,"decodeSinglePose",function(){return L}),n.d(e,"MobileNet",function(){return f}),n.d(e,"partChannels",function(){return x}),n.d(e,"partIds",function(){return v}),n.d(e,"partNames",function(){return m}),n.d(e,"poseChain",function(){return y}),n.d(e,"load",function(){return ht}),n.d(e,"PoseNet",function(){return lt}),n.d(e,"getAdjacentKeyPoints",function(){return V}),n.d(e,"getBoundingBox",function(){return G}),n.d(e,"getBoundingBoxPoints",function(){return $}),n.d(e,"scaleAndFlipPoses",function(){return nt}),n.d(e,"scalePose",function(){return K}),n.d(e,"version",function(){return pt});var r=n(0),i=n(20),a=function(t,e){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function o(t,e){function n(){this.constructor=t}a(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var s=function(){return(s=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function u(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})}function c(t,e){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=(i=o.trys).length>0&&i[i.length-1])&&(6===a[0]||2===a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}var l=function(){function t(t,e){this.model=t,this.outputStride=e;var n=this.model.inputs[0].shape;r.util.assert(-1===n[1]&&-1===n[2],function(){return"Input shape ["+n[1]+", "+n[2]+"] must both be equal to or -1"})}return t.prototype.predict=function(t){var e=this;return Object(r.tidy)(function(){var n=e.preprocessInput(t.toFloat()).expandDims(0),r=e.model.predict(n).map(function(t){return t.squeeze([0])}),i=e.nameOutputResults(r);return{heatmapScores:i.heatmap.sigmoid(),offsets:i.offsets,displacementFwd:i.displacementFwd,displacementBwd:i.displacementBwd}})},t.prototype.dispose=function(){this.model.dispose()},t}(),f=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),e.prototype.preprocessInput=function(t){return Object(r.tidy)(function(){return Object(r.div)(t,127.5).sub(1)})},e.prototype.nameOutputResults=function(t){return{offsets:t[0],heatmap:t[1],displacementFwd:t[2],displacementBwd:t[3]}},e}(l);function d(t){return Math.floor(t/2)}var h=function(){function t(t,e){this.priorityQueue=new Array(t),this.numberOfElements=-1,this.getElementValue=e}return t.prototype.enqueue=function(t){this.priorityQueue[++this.numberOfElements]=t,this.swim(this.numberOfElements)},t.prototype.dequeue=function(){var t=this.priorityQueue[0];return this.exchange(0,this.numberOfElements--),this.sink(0),this.priorityQueue[this.numberOfElements+1]=null,t},t.prototype.empty=function(){return-1===this.numberOfElements},t.prototype.size=function(){return this.numberOfElements+1},t.prototype.all=function(){return this.priorityQueue.slice(0,this.numberOfElements+1)},t.prototype.max=function(){return this.priorityQueue[0]},t.prototype.swim=function(t){for(;t>0&&this.less(d(t),t);)this.exchange(t,d(t)),t=d(t)},t.prototype.sink=function(t){for(;2*t<=this.numberOfElements;){var e=2*t;if(e<this.numberOfElements&&this.less(e,e+1)&&e++,!this.less(t,e))break;this.exchange(t,e),t=e}},t.prototype.getValueAt=function(t){return this.getElementValue(this.priorityQueue[t])},t.prototype.less=function(t,e){return this.getValueAt(t)<this.getValueAt(e)},t.prototype.exchange=function(t,e){var n=this.priorityQueue[t];this.priorityQueue[t]=this.priorityQueue[e],this.priorityQueue[e]=n},t}();function p(t,e,n,r,i,a){for(var o=a.shape,s=o[0],u=o[1],c=!0,l=Math.max(n-i,0),f=Math.min(n+i+1,s),d=l;d<f;++d){for(var h=Math.max(r-i,0),p=Math.min(r+i+1,u),m=h;m<p;++m)if(a.get(d,m,t)>e){c=!1;break}if(!c)break}return c}var m=["nose","leftEye","rightEye","leftEar","rightEar","leftShoulder","rightShoulder","leftElbow","rightElbow","leftWrist","rightWrist","leftHip","rightHip","leftKnee","rightKnee","leftAnkle","rightAnkle"],g=m.length,v=m.reduce(function(t,e,n){return t[e]=n,t},{}),y=[["nose","leftEye"],["leftEye","leftEar"],["nose","rightEye"],["rightEye","rightEar"],["nose","leftShoulder"],["leftShoulder","leftElbow"],["leftElbow","leftWrist"],["leftShoulder","leftHip"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["nose","rightShoulder"],["rightShoulder","rightElbow"],["rightElbow","rightWrist"],["rightShoulder","rightHip"],["rightHip","rightKnee"],["rightKnee","rightAnkle"]],b=[["leftHip","leftShoulder"],["leftElbow","leftShoulder"],["leftElbow","leftWrist"],["leftHip","leftKnee"],["leftKnee","leftAnkle"],["rightHip","rightShoulder"],["rightElbow","rightShoulder"],["rightElbow","rightWrist"],["rightHip","rightKnee"],["rightKnee","rightAnkle"],["leftShoulder","rightShoulder"],["leftHip","rightHip"]].map(function(t){var e=t[0],n=t[1];return[v[e],v[n]]}),x=["left_face","right_face","right_upper_leg_front","right_lower_leg_back","right_upper_leg_back","left_lower_leg_front","left_upper_leg_front","left_upper_leg_back","left_lower_leg_back","right_feet","right_lower_leg_front","left_feet","torso_front","torso_back","right_upper_arm_front","right_upper_arm_back","right_lower_arm_back","left_lower_arm_front","left_upper_arm_front","left_upper_arm_back","left_lower_arm_back","right_hand","right_lower_arm_front","left_hand"];function w(t,e,n,r){return{y:r.get(t,e,n),x:r.get(t,e,n+g)}}function k(t,e,n){var r=w(t.heatmapY,t.heatmapX,t.id,n),i=r.y,a=r.x;return{x:t.heatmapX*e+a,y:t.heatmapY*e+i}}function _(t,e,n){return t<e?e:t>n?n:t}function E(t,e){return{x:t.x+e.x,y:t.y+e.y}}var O=y.map(function(t){var e=t[0],n=t[1];return[v[e],v[n]]}),S=O.map(function(t){return t[1]}),C=O.map(function(t){return t[0]});function A(t,e,n,r){return{y:_(Math.round(t.y/e),0,n-1),x:_(Math.round(t.x/e),0,r-1)}}function N(t,e,n,r,i,a,o,s){void 0===s&&(s=2);for(var u=r.shape,c=u[0],l=u[1],f=function(t,e,n){var r=n.shape[2]/2;return{y:n.get(e.y,e.x,t),x:n.get(e.y,e.x,r+t)}}(t,A(e.position,a,c,l),o),d=E(e.position,f),h=0;h<s;h++){var p=A(d,a,c,l),g=w(p.y,p.x,n,i);d=E({x:p.x*a,y:p.y*a},{x:g.x,y:g.y})}var v=A(d,a,c,l),y=r.get(v.y,v.x,n);return{position:d,part:m[n],score:y}}function T(t,e,n,r,i,a){var o=e.shape[2],s=S.length,u=new Array(o),c=t.part,l=t.score,f=k(c,r,n);u[c.id]={score:l,part:m[c.id],position:f};for(var d=s-1;d>=0;--d){var h=S[d],p=C[d];u[h]&&!u[p]&&(u[p]=N(d,u[h],p,e,n,r,a))}for(d=0;d<s;++d)h=C[d],p=S[d],u[h]&&!u[p]&&(u[p]=N(d,u[h],p,e,n,r,i));return u}function I(t,e,n,r){var i=n.x,a=n.y;return t.some(function(t){var n=t.keypoints[r].position;return function(t,e,n,r){var i=n-t,a=r-e;return i*i+a*a}(a,i,n.y,n.x)<=e})}function D(t,e,n){return n.reduce(function(n,r,i){var a=r.position,o=r.score;return I(t,e,a,i)||(n+=o),n},0)/n.length}var M=1;function R(t,e,n,r,i,a,o,s){void 0===o&&(o=.5),void 0===s&&(s=20);for(var u=[],c=function(t,e,n){for(var r=n.shape,i=r[0],a=r[1],o=r[2],s=new h(i*a*o,function(t){return t.score}),u=0;u<i;++u)for(var c=0;c<a;++c)for(var l=0;l<o;++l){var f=n.get(u,c,l);f<t||p(l,f,u,c,e,n)&&s.enqueue({score:f,part:{heatmapY:u,heatmapX:c,id:l}})}return s}(o,M,t),l=s*s;u.length<a&&!c.empty();){var f=c.dequeue();if(!I(u,l,k(f.part,i,e),f.part.id)){var d=T(f,t,e,i,n,r),m=D(u,l,d);u.push({keypoints:d,score:m})}}return u}function F(t){var e=t.shape,n=e[0],i=e[1],a=e[2];return Object(r.tidy)(function(){var e=t.reshape([n*i,a]).argMax(0),o=e.div(Object(r.scalar)(i,"int32")).expandDims(1),s=function(t,e){return Object(r.tidy)(function(){var n=t.div(Object(r.scalar)(e,"int32"));return t.sub(n.mul(Object(r.scalar)(e,"int32")))})}(e,i).expandDims(1);return Object(r.concat)([o,s],1)})}function j(t,e,n,r){return{y:r.get(t,e,n),x:r.get(t,e,n+g)}}function P(t,e,n){return Object(r.tidy)(function(){var i=function(t,e){for(var n=[],i=0;i<g;i++){var a=j(t.get(i,0).valueOf(),t.get(i,1).valueOf(),i,e),o=a.x,s=a.y;n.push(s),n.push(o)}return Object(r.tensor2d)(n,[g,2])}(t,n);return t.toTensor().mul(Object(r.scalar)(e,"int32")).toFloat().add(i)})}function L(t,e,n){return u(this,void 0,void 0,function(){var r,i,a,o,s,u,l,f,d,h;return c(this,function(c){switch(c.label){case 0:return r=0,i=F(t),[4,Promise.all([t.buffer(),e.buffer(),i.buffer()])];case 1:return a=c.sent(),o=a[0],s=a[1],u=a[2],[4,(l=P(u,n,s)).buffer()];case 2:return f=c.sent(),d=Array.from(function(t,e){for(var n=e.shape[0],r=new Float32Array(n),i=0;i<n;i++){var a=e.get(i,0),o=e.get(i,1);r[i]=t.get(a,o,i)}return r}(o,u)),h=d.map(function(t,e){return r+=t,{position:{y:f.get(e,0),x:f.get(e,1)},part:m[e],score:t}}),i.dispose(),l.dispose(),[2,{keypoints:h,score:r/h.length}]}})})}var z="https://storage.googleapis.com/tfjs-models/savedmodel/posenet/mobilenet/",B="https://storage.googleapis.com/tfjs-models/savedmodel/posenet/resnet50/";var U=[-123.15,-115.9,-103.06],W=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return o(e,t),e.prototype.preprocessInput=function(t){return t.add(U)},e.prototype.nameOutputResults=function(t){var e=t[0],n=t[1];return{offsets:t[2],heatmap:t[3],displacementFwd:e,displacementBwd:n}},e}(l);function V(t,e){return b.reduce(function(n,r){var i=r[0],a=r[1];return function(t,e,n){return t<n||e<n}(t[i].score,t[a].score,e)?n:(n.push([t[i],t[a]]),n)},[])}var q=Number.NEGATIVE_INFINITY,H=Number.POSITIVE_INFINITY;function G(t){return t.reduce(function(t,e){var n=t.maxX,r=t.maxY,i=t.minX,a=t.minY,o=e.position,s=o.x,u=o.y;return{maxX:Math.max(n,s),maxY:Math.max(r,u),minX:Math.min(i,s),minY:Math.min(a,u)}},{maxX:q,maxY:q,minX:H,minY:H})}function $(t){var e=G(t),n=e.minX,r=e.minY,i=e.maxX,a=e.maxY;return[{x:n,y:r},{x:i,y:r},{x:i,y:a},{x:n,y:a}]}function K(t,e,n,r,i){return void 0===r&&(r=0),void 0===i&&(i=0),{score:t.score,keypoints:t.keypoints.map(function(t){var a=t.score,o=t.part,s=t.position;return{score:a,part:o,position:{x:s.x*n+i,y:s.y*e+r}}})}}function X(t,e){return Q(t,e)?t:Math.floor(t/e)*e+1}function Y(t){r.util.assert("number"==typeof t||"object"==typeof t,function(){return"Invalid inputResolution "+t+". Should be a number or an object with width and height"}),"object"==typeof t&&(r.util.assert("number"==typeof t.width,function(){return"inputResolution.width has a value of "+t.width+" which is invalid; it must be a number"}),r.util.assert("number"==typeof t.height,function(){return"inputResolution.height has a value of "+t.height+" which is invalid; it must be a number"}))}function J(t,e){return Y(t),"object"==typeof t?[X(t.height,e),X(t.width,e)]:[X(t,e),X(t,e)]}var Z=[8,16,32];function Q(t,e){return(t-1)%e==0}function tt(t){return t instanceof r.Tensor?[t.shape[0],t.shape[1]]:[t.height,t.width]}function et(t,e){var n=e[0],i=e[1],a=tt(t),o=a[0],s=a[1],u=i/n,c=[0,0,0,0],l=c[0],f=c[1],d=c[2],h=c[3];return s/o<u?(l=0,f=0,d=Math.round(.5*(u*o-s)),h=Math.round(.5*(u*o-s))):(l=Math.round(.5*(1/u*s-o)),f=Math.round(.5*(1/u*s-o)),d=0,h=0),{resized:Object(r.tidy)(function(){var e=function(t){return t instanceof r.Tensor?t:r.browser.fromPixels(t)}(t);return(e=Object(r.pad3d)(e,[[l,f],[d,h],[0,0]])).resizeBilinear([n,i])}),padding:{top:l,left:d,right:h,bottom:f}}}function nt(t,e,n,r,i){var a=e[0],o=e[1],s=n[0],u=n[1],c=function(t,e,n,r,i){return void 0===r&&(r=0),void 0===i&&(i=0),1===n&&1===e&&0===r&&0===i?t:t.map(function(t){return K(t,e,n,r,i)})}(t,(a+r.top+r.bottom)/s,(o+r.left+r.right)/u,-r.top,-r.left);return i?function(t,e){return e<=0?t:t.map(function(t){return function(t,e){return{score:t.score,keypoints:t.keypoints.map(function(t){var n=t.score,r=t.part,i=t.position;return{score:n,part:r,position:{x:e-1-i.x,y:i.y}}})}}(t,e)})}(c,o):c}var rt={architecture:"MobileNetV1",outputStride:16,multiplier:.75,inputResolution:257},it=["MobileNetV1","ResNet50"],at={MobileNetV1:[8,16,32],ResNet50:[32,16]},ot={MobileNetV1:[.5,.75,1],ResNet50:[1]},st=[1,2,4];var ut={flipHorizontal:!1},ct={flipHorizontal:!1,maxDetections:5,scoreThreshold:.5,nmsRadius:20};var lt=function(){function t(t,e){(function(t){r.util.assert("number"==typeof t,function(){return"outputStride is not a number"}),r.util.assert(Z.indexOf(t)>=0,function(){return"outputStride of "+t+" is invalid. It must be either 8, 16, or 32"})})(t.outputStride),function(t,e){r.util.assert("number"==typeof t[0]&&"number"==typeof t[1],function(){return"both resolution values must be a number but had values "+t}),r.util.assert(Q(t[0],e),function(){return"height of "+t[0]+" is invalid for output stride "+e+"."}),r.util.assert(Q(t[1],e),function(){return"width of "+t[1]+" is invalid for output stride "+e+"."})}(e,t.outputStride),this.baseModel=t,this.inputResolution=e}return t.prototype.estimateMultiplePoses=function(t,e){return void 0===e&&(e=ct),u(this,void 0,void 0,function(){var n,r,i,a,o,l,f,d,h,p,m,g,v,y,b,x,w,k,_,E,O;return c(this,function(S){switch(S.label){case 0:return n=s({},ct,e),function(t){var e=t.maxDetections,n=t.scoreThreshold,r=t.nmsRadius;if(e<=0)throw new Error("Invalid maxDetections "+e+". Should be > 0");if(n<0||n>1)throw new Error("Invalid scoreThreshold "+n+". Should be in range [0.0, 1.0]");if(r<=0)throw new Error("Invalid nmsRadius "+r+".")}(e),r=this.baseModel.outputStride,i=this.inputResolution,a=tt(t),o=a[0],l=a[1],f=et(t,i),d=f.resized,h=f.padding,p=this.baseModel.predict(d),m=p.heatmapScores,g=p.offsets,v=p.displacementFwd,y=p.displacementBwd,[4,function(t){return u(this,void 0,void 0,function(){return c(this,function(e){return[2,Promise.all(t.map(function(t){return t.buffer()}))]})})}([m,g,v,y])];case 1:return b=S.sent(),x=b[0],w=b[1],k=b[2],_=b[3],[4,R(x,w,k,_,r,n.maxDetections,n.scoreThreshold,n.nmsRadius)];case 2:return E=S.sent(),O=nt(E,[o,l],i,h,n.flipHorizontal),m.dispose(),g.dispose(),v.dispose(),y.dispose(),d.dispose(),[2,O]}})})},t.prototype.estimateSinglePose=function(t,e){return void 0===e&&(e=ut),u(this,void 0,void 0,function(){var n,r,i,a,o,u,l,f,d,h,p,m,g,v,y,b;return c(this,function(c){switch(c.label){case 0:return n=s({},ut,e),r=this.baseModel.outputStride,i=this.inputResolution,a=tt(t),o=a[0],u=a[1],l=et(t,i),f=l.resized,d=l.padding,h=this.baseModel.predict(f),p=h.heatmapScores,m=h.offsets,g=h.displacementFwd,v=h.displacementBwd,[4,L(p,m,r)];case 1:return y=c.sent(),b=nt([y],[o,u],i,d,n.flipHorizontal),p.dispose(),m.dispose(),g.dispose(),v.dispose(),f.dispose(),[2,b[0]]}})})},t.prototype.estimatePoses=function(t,e){return u(this,void 0,void 0,function(){return c(this,function(n){switch(n.label){case 0:return"single-person"!==e.decodingMethod?[3,2]:[4,this.estimateSinglePose(t,e)];case 1:return[2,[n.sent()]];case 2:return[2,this.estimateMultiplePoses(t,e)]}})})},t.prototype.dispose=function(){this.baseModel.dispose()},t}();function ft(t){return u(this,void 0,void 0,function(){var e,n,a,o,s,u,l;return c(this,function(c){switch(c.label){case 0:if(e=t.outputStride,n=t.quantBytes,a=t.multiplier,null==r)throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please also include @tensorflow/tfjs on the page before using this\n model.");return o=function(t,e,n){var r={1:"100",.75:"075",.5:"050"},i="model-stride"+t+".json";return 4===n?z+"float/"+r[e]+"/"+i:z+"quant"+n+"/"+r[e]+"/"+i}(e,a,n),[4,Object(i.c)(t.modelUrl||o)];case 1:return s=c.sent(),u=new f(s,e),l=J(t.inputResolution,u.outputStride),[2,new lt(u,l)]}})})}function dt(t){return u(this,void 0,void 0,function(){var e,n,a,o,s,u;return c(this,function(c){switch(c.label){case 0:if(e=t.outputStride,n=t.quantBytes,null==r)throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please also include @tensorflow/tfjs on the page before using this\n model.");return a=function(t,e){var n="model-stride"+t+".json";return 4===e?B+"float/"+n:B+"quant"+e+"/"+n}(e,n),[4,Object(i.c)(t.modelUrl||a)];case 1:return o=c.sent(),s=new W(o,e),u=J(t.inputResolution,s.outputStride),[2,new lt(s,u)]}})})}function ht(t){return void 0===t&&(t=rt),u(this,void 0,void 0,function(){return c(this,function(e){return"ResNet50"===(t=function(t){if(null==(t=t||rt).architecture&&(t.architecture="MobileNetV1"),it.indexOf(t.architecture)<0)throw new Error("Invalid architecture "+t.architecture+". Should be one of "+it);if(null==t.inputResolution&&(t.inputResolution=257),Y(t.inputResolution),null==t.outputStride&&(t.outputStride=16),at[t.architecture].indexOf(t.outputStride)<0)throw new Error("Invalid outputStride "+t.outputStride+". Should be one of "+at[t.architecture]+" for architecutre "+t.architecture+".");if(null==t.multiplier&&(t.multiplier=1),ot[t.architecture].indexOf(t.multiplier)<0)throw new Error("Invalid multiplier "+t.multiplier+". Should be one of "+ot[t.architecture]+" for architecutre "+t.architecture+".");if(null==t.quantBytes&&(t.quantBytes=4),st.indexOf(t.quantBytes)<0)throw new Error("Invalid quantBytes "+t.quantBytes+". Should be one of "+st+" for architecutre "+t.architecture+".");return t}(t)).architecture?[2,dt(t)]:"MobileNetV1"===t.architecture?[2,ft(t)]:[2,null]})})}var pt="2.2.1"},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=y(n(14)),i=y(n(99)),a=y(n(9)),o=y(n(24)),s=y(n(8)),u=y(n(98)),c=y(n(7)),l=y(n(10)),f=y(n(97)),d=y(n(96)),h=y(n(141)),p=v(n(4)),m=v(n(344)),g=y(n(15));function v(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}function y(t){return t&&t.__esModule?t:{default:t}}var b={architecture:"MobileNetV1",outputStride:16,flipHorizontal:!1,minConfidence:.5,maxPoseDetections:5,scoreThreshold:.5,nmsRadius:20,detectionType:"multiple",inputResolution:256,multiplier:.75,quantBytes:2,modelUrl:null},x=function(t){function e(t,n,r,i){(0,c.default)(this,e);var a=(0,f.default)(this,(e.__proto__||(0,u.default)(e)).call(this));return a.video=t,a.modelUrl=n.modelUrl||null,a.architecture=n.architecture||b.architecture,a.detectionType=r||n.detectionType||b.detectionType,a.outputStride=n.outputStride||b.outputStride,a.flipHorizontal=n.flipHorizontal||b.flipHorizontal,a.scoreThreshold=n.scoreThreshold||b.scoreThreshold,a.minConfidence=n.minConfidence||b.minConfidence,a.maxPoseDetections=n.maxPoseDetections||b.maxPoseDetections,a.multiplier=n.multiplier||b.multiplier,a.inputResolution=n.inputResolution||b.inputResolution,a.quantBytes=n.quantBytes||b.quantBytes,a.nmsRadius=n.nmsRadius||b.nmsRadius,a.ready=(0,g.default)(a.load(),i),a}return(0,d.default)(e,t),(0,l.default)(e,[{key:"load",value:function(){var t=(0,s.default)(a.default.mark(function t(){var e,n=this;return a.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=void 0,e="mobilenetv1"===this.architecture.toLowerCase()?{architecture:this.architecture,outputStride:this.outputStride,inputResolution:this.inputResolution,multiplier:this.multiplier,quantBytes:this.quantBytes,modelUrl:this.modelUrl}:{architecture:this.architecture,outputStride:this.outputStride,inputResolution:this.inputResolution,quantBytes:this.quantBytes},t.next=4,m.load(e);case 4:if(this.net=t.sent,!this.video){t.next=10;break}if(0!==this.video.readyState){t.next=9;break}return t.next=9,new o.default(function(t){n.video.onloadeddata=function(){return t()}});case 9:"single"===this.detectionType?this.singlePose():this.multiPose();case 10:return t.abrupt("return",this);case 11:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"skeleton",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.minConfidence;return m.getAdjacentKeyPoints(t,e)}},{key:"mapParts",value:function(t){var e=JSON.parse((0,i.default)(t));return e.keypoints.forEach(function(t){e[t.part]={x:t.position.x,y:t.position.y,confidence:t.score}}),e}},{key:"getInput",value:function(t){return t instanceof HTMLImageElement||t instanceof HTMLVideoElement||t instanceof HTMLCanvasElement||t instanceof ImageData?t:"object"===(void 0===t?"undefined":(0,r.default)(t))&&(t.elt instanceof HTMLImageElement||t.elt instanceof HTMLVideoElement||t.elt instanceof ImageData)?t.elt:"object"===(void 0===t?"undefined":(0,r.default)(t))&&t.canvas instanceof HTMLCanvasElement?t.canvas:this.video}},{key:"singlePose",value:function(){var t=(0,s.default)(a.default.mark(function t(e,n){var r,i,o,s,u=this;return a.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=this.getInput(e),t.next=3,this.net.estimateSinglePose(r,{flipHorizontal:this.flipHorizontal});case 3:if(i=t.sent,o=this.mapParts(i),s=[{pose:o,skeleton:this.skeleton(i.keypoints)}],this.emit("pose",s),!this.video){t.next=9;break}return t.abrupt("return",p.nextFrame().then(function(){return u.singlePose()}));case 9:return"function"==typeof n&&n(s),t.abrupt("return",s);case 11:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"multiPose",value:function(){var t=(0,s.default)(a.default.mark(function t(e,n){var r,i,o,s,u=this;return a.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=this.getInput(e),t.next=3,this.net.estimateMultiplePoses(r,{flipHorizontal:this.flipHorizontal,maxDetections:this.maxPoseDetections,scoreThreshold:this.scoreThreshold,nmsRadius:this.nmsRadius});case 3:if(i=t.sent,o=i.map(function(t){return u.mapParts(t)}),s=o.map(function(t){return{pose:t,skeleton:u.skeleton(t.keypoints)}}),this.emit("pose",s),!this.video){t.next=9;break}return t.abrupt("return",p.nextFrame().then(function(){return u.multiPose()}));case 9:return"function"==typeof n&&n(s),t.abrupt("return",s);case 11:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()}]),e}(h.default);e.default=function(t,e,n){var i=void 0,a={},o=n,s=null;return t instanceof HTMLVideoElement?i=t:"object"===(void 0===t?"undefined":(0,r.default)(t))&&t.elt instanceof HTMLVideoElement?i=t.elt:"object"===(void 0===t?"undefined":(0,r.default)(t))?a=t:"function"==typeof t&&(o=t),"object"===(void 0===e?"undefined":(0,r.default)(e))?a=e:"string"==typeof e&&(s=e),"function"==typeof e&&(o=e),new x(i,a,s,o)}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=u(n(14)),i=u(n(90)),a=u(n(7)),o=n(206),s=n(205);function u(t){return t&&t.__esModule?t:{default:t}}e.default=function(t,e,n,u){var c=void 0,l={},f=u,d=t;if("string"!=typeof d)throw new Error('Please specify a model to use. E.g: "YOLO"');-1===d.indexOf("http")&&(d=t.toLowerCase()),e instanceof HTMLVideoElement?c=e:"object"===(void 0===e?"undefined":(0,r.default)(e))&&e.elt instanceof HTMLVideoElement?c=e.elt:"object"===(void 0===e?"undefined":(0,r.default)(e))?l=e:"function"==typeof e&&(f=e),"object"===(void 0===n?"undefined":(0,r.default)(n))?l=n:"function"==typeof n&&(f=n);var h=new function t(e,n,r,u){switch((0,a.default)(this,t),this.video=n,this.modelNameOrUrl=e,this.options=r||{},this.callback=u,e){case"yolo":return this.model=new o.YOLO(this.video,(0,i.default)({disableDeprecationNotice:!0},this.options),u),this;case"cocossd":default:return this.model=new s.CocoSsd(this.video,this.options,u),this}}(d,c,l,f);return h.model.callback?h.model:h.model.ready}},function(t,e,n){"use strict";n.r(e),n.d(e,"load",function(){return l}),n.d(e,"ObjectDetection",function(){return f}),n.d(e,"version",function(){return u});var r=n(20),i=n(0);
  322. /**
  323. * @license
  324. * Copyright 2020 Google LLC. All Rights Reserved.
  325. * Licensed under the Apache License, Version 2.0 (the "License");
  326. * you may not use this file except in compliance with the License.
  327. * You may obtain a copy of the License at
  328. *
  329. * http://www.apache.org/licenses/LICENSE-2.0
  330. *
  331. * Unless required by applicable law or agreed to in writing, software
  332. * distributed under the License is distributed on an "AS IS" BASIS,
  333. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  334. * See the License for the specific language governing permissions and
  335. * limitations under the License.
  336. * =============================================================================
  337. */
  338. function a(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})}function o(t,e){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=(i=o.trys).length>0&&i[i.length-1])&&(6===a[0]||2===a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}var s={1:{name:"/m/01g317",id:1,displayName:"person"},2:{name:"/m/0199g",id:2,displayName:"bicycle"},3:{name:"/m/0k4j",id:3,displayName:"car"},4:{name:"/m/04_sv",id:4,displayName:"motorcycle"},5:{name:"/m/05czz6l",id:5,displayName:"airplane"},6:{name:"/m/01bjv",id:6,displayName:"bus"},7:{name:"/m/07jdr",id:7,displayName:"train"},8:{name:"/m/07r04",id:8,displayName:"truck"},9:{name:"/m/019jd",id:9,displayName:"boat"},10:{name:"/m/015qff",id:10,displayName:"traffic light"},11:{name:"/m/01pns0",id:11,displayName:"fire hydrant"},13:{name:"/m/02pv19",id:13,displayName:"stop sign"},14:{name:"/m/015qbp",id:14,displayName:"parking meter"},15:{name:"/m/0cvnqh",id:15,displayName:"bench"},16:{name:"/m/015p6",id:16,displayName:"bird"},17:{name:"/m/01yrx",id:17,displayName:"cat"},18:{name:"/m/0bt9lr",id:18,displayName:"dog"},19:{name:"/m/03k3r",id:19,displayName:"horse"},20:{name:"/m/07bgp",id:20,displayName:"sheep"},21:{name:"/m/01xq0k1",id:21,displayName:"cow"},22:{name:"/m/0bwd_0j",id:22,displayName:"elephant"},23:{name:"/m/01dws",id:23,displayName:"bear"},24:{name:"/m/0898b",id:24,displayName:"zebra"},25:{name:"/m/03bk1",id:25,displayName:"giraffe"},27:{name:"/m/01940j",id:27,displayName:"backpack"},28:{name:"/m/0hnnb",id:28,displayName:"umbrella"},31:{name:"/m/080hkjn",id:31,displayName:"handbag"},32:{name:"/m/01rkbr",id:32,displayName:"tie"},33:{name:"/m/01s55n",id:33,displayName:"suitcase"},34:{name:"/m/02wmf",id:34,displayName:"frisbee"},35:{name:"/m/071p9",id:35,displayName:"skis"},36:{name:"/m/06__v",id:36,displayName:"snowboard"},37:{name:"/m/018xm",id:37,displayName:"sports ball"},38:{name:"/m/02zt3",id:38,displayName:"kite"},39:{name:"/m/03g8mr",id:39,displayName:"baseball bat"},40:{name:"/m/03grzl",id:40,displayName:"baseball glove"},41:{name:"/m/06_fw",id:41,displayName:"skateboard"},42:{name:"/m/019w40",id:42,displayName:"surfboard"},43:{name:"/m/0dv9c",id:43,displayName:"tennis racket"},44:{name:"/m/04dr76w",id:44,displayName:"bottle"},46:{name:"/m/09tvcd",id:46,displayName:"wine glass"},47:{name:"/m/08gqpm",id:47,displayName:"cup"},48:{name:"/m/0dt3t",id:48,displayName:"fork"},49:{name:"/m/04ctx",id:49,displayName:"knife"},50:{name:"/m/0cmx8",id:50,displayName:"spoon"},51:{name:"/m/04kkgm",id:51,displayName:"bowl"},52:{name:"/m/09qck",id:52,displayName:"banana"},53:{name:"/m/014j1m",id:53,displayName:"apple"},54:{name:"/m/0l515",id:54,displayName:"sandwich"},55:{name:"/m/0cyhj_",id:55,displayName:"orange"},56:{name:"/m/0hkxq",id:56,displayName:"broccoli"},57:{name:"/m/0fj52s",id:57,displayName:"carrot"},58:{name:"/m/01b9xk",id:58,displayName:"hot dog"},59:{name:"/m/0663v",id:59,displayName:"pizza"},60:{name:"/m/0jy4k",id:60,displayName:"donut"},61:{name:"/m/0fszt",id:61,displayName:"cake"},62:{name:"/m/01mzpv",id:62,displayName:"chair"},63:{name:"/m/02crq1",id:63,displayName:"couch"},64:{name:"/m/03fp41",id:64,displayName:"potted plant"},65:{name:"/m/03ssj5",id:65,displayName:"bed"},67:{name:"/m/04bcr3",id:67,displayName:"dining table"},70:{name:"/m/09g1w",id:70,displayName:"toilet"},72:{name:"/m/07c52",id:72,displayName:"tv"},73:{name:"/m/01c648",id:73,displayName:"laptop"},74:{name:"/m/020lf",id:74,displayName:"mouse"},75:{name:"/m/0qjjc",id:75,displayName:"remote"},76:{name:"/m/01m2v",id:76,displayName:"keyboard"},77:{name:"/m/050k8",id:77,displayName:"cell phone"},78:{name:"/m/0fx9l",id:78,displayName:"microwave"},79:{name:"/m/029bxz",id:79,displayName:"oven"},80:{name:"/m/01k6s3",id:80,displayName:"toaster"},81:{name:"/m/0130jx",id:81,displayName:"sink"},82:{name:"/m/040b_t",id:82,displayName:"refrigerator"},84:{name:"/m/0bt_c3",id:84,displayName:"book"},85:{name:"/m/01x3z",id:85,displayName:"clock"},86:{name:"/m/02s195",id:86,displayName:"vase"},87:{name:"/m/01lsmm",id:87,displayName:"scissors"},88:{name:"/m/0kmg4",id:88,displayName:"teddy bear"},89:{name:"/m/03wvsk",id:89,displayName:"hair drier"},90:{name:"/m/012xff",id:90,displayName:"toothbrush"}},u="2.0.3",c="https://storage.googleapis.com/tfjs-models/savedmodel/";function l(t){return void 0===t&&(t={}),a(this,void 0,void 0,function(){var e,n,r;return o(this,function(a){switch(a.label){case 0:if(null==i)throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please also include @tensorflow/tfjs on the page before using this model.");if(e=t.base||"lite_mobilenet_v2",n=t.modelUrl,-1===["mobilenet_v1","mobilenet_v2","lite_mobilenet_v2"].indexOf(e))throw new Error("ObjectDetection constructed with invalid base model "+e+". Valid names are 'mobilenet_v1', 'mobilenet_v2' and 'lite_mobilenet_v2'.");return[4,(r=new f(e,n)).load()];case 1:return a.sent(),[2,r]}})})}var f=function(){function t(t,e){this.modelPath=e||""+c+this.getPrefix(t)+"/model.json"}return t.prototype.getPrefix=function(t){return"lite_mobilenet_v2"===t?"ssd"+t:"ssd_"+t},t.prototype.load=function(){return a(this,void 0,void 0,function(){var t,e,n;return o(this,function(a){switch(a.label){case 0:return t=this,[4,Object(r.c)(this.modelPath)];case 1:return t.model=a.sent(),e=Object(i.zeros)([1,300,300,3],"int32"),[4,this.model.executeAsync(e)];case 2:return n=a.sent(),[4,Promise.all(n.map(function(t){return t.data()}))];case 3:return a.sent(),n.map(function(t){return t.dispose()}),e.dispose(),[2]}})})},t.prototype.infer=function(t,e){return a(this,void 0,void 0,function(){var n,r,a,s,u,c,l,f,d,h,p,m;return o(this,function(o){switch(o.label){case 0:return n=Object(i.tidy)(function(){return t instanceof i.Tensor||(t=i.browser.fromPixels(t)),t.expandDims(0)}),r=n.shape[1],a=n.shape[2],[4,this.model.executeAsync(n)];case 1:return s=o.sent(),u=s[0].dataSync(),c=s[1].dataSync(),n.dispose(),Object(i.dispose)(s),l=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,a=n.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(r=a.next()).done;)o.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=a.return)&&n.call(a)}finally{if(i)throw i.error}}return o}(this.calculateMaxScores(u,s[0].shape[1],s[0].shape[2]),2),f=l[0],d=l[1],h=Object(i.getBackend)(),Object(i.setBackend)("cpu"),p=Object(i.tidy)(function(){var t=Object(i.tensor2d)(c,[s[1].shape[1],s[1].shape[3]]);return i.image.nonMaxSuppression(t,f,e,.5,.5)}),m=p.dataSync(),p.dispose(),Object(i.setBackend)(h),[2,this.buildDetectedObjects(a,r,c,f,m,d)]}})})},t.prototype.buildDetectedObjects=function(t,e,n,r,i,a){for(var o=i.length,u=[],c=0;c<o;c++){for(var l=[],f=0;f<4;f++)l[f]=n[4*i[c]+f];var d=l[0]*e,h=l[1]*t,p=l[2]*e,m=l[3]*t;l[0]=h,l[1]=d,l[2]=m-h,l[3]=p-d,u.push({bbox:l,class:s[a[i[c]]+1].displayName,score:r[i[c]]})}return u},t.prototype.calculateMaxScores=function(t,e,n){for(var r=[],i=[],a=0;a<e;a++){for(var o=Number.MIN_VALUE,s=-1,u=0;u<n;u++)t[a*n+u]>o&&(o=t[a*n+u],s=u);r[a]=o,i[a]=s}return[r,i]},t.prototype.detect=function(t,e){return void 0===e&&(e=20),a(this,void 0,void 0,function(){return o(this,function(n){return[2,this.infer(t,e)]})})},t.prototype.dispose=function(){null!=this.model&&this.model.dispose()},t}()},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.nonMaxSuppression=e.boxesToCorners=e.filterBoxes=e.boxIOU=e.boxUnion=e.boxIntersection=void 0;var r=o(n(9)),i=o(n(8));e.filterBoxes=function(){var t=(0,i.default)(r.default.mark(function t(e,n,i,o){return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",a.tidy(function(){for(var t=a.mul(n,i),r=a.argMax(t,-1),s=a.max(t,-1),u=a.greaterEqual(s,a.scalar(o)).dataSync(),c=[],l=0;l<u.length;l+=1){u[l]&&c.push(l)}if(0===c.length)return[null,null,null];var f=a.tensor1d(c,"int32");return[a.gather(e.reshape([u.length,4]),f),a.gather(s.flatten(),f),a.gather(r.flatten(),f)]}));case 1:case"end":return t.stop()}},t,this)}));return function(e,n,r,i){return t.apply(this,arguments)}}();e.head=function(t,e,n){return a.tidy(function(){var r=e.shape[0],i=a.reshape(e,[1,1,r,2]),o=t.shape.slice(1,3),s=o[0],u=o[1],c=a.range(0,o[0]),l=a.range(0,o[1]);c=a.tile(c,[o[1]]),l=a.tile(a.expandDims(l,0),[o[0],1]),l=a.transpose(l).flatten();var f=a.transpose(a.stack([c,l]));f=a.reshape(f,[o[0],o[1],1,2]),f=a.cast(f,t.dtype),t=a.reshape(t,[o[0],o[1],r,n+5]),o=a.cast(a.reshape(a.tensor1d(o),[1,1,1,2]),t.dtype);var d=a.sigmoid(t.slice([0,0,0,0],[s,u,r,2])),h=a.exp(t.slice([0,0,0,2],[s,u,r,2])),p=a.sigmoid(t.slice([0,0,0,4],[s,u,r,1])),m=a.softmax(t.slice([0,0,0,5],[s,u,r,n]));return d=a.div(a.add(d,f),o),h=a.div(a.mul(h,i),o),[d,h,p,m]})};var a=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(4));function o(t){return t&&t.__esModule?t:{default:t}}var s=e.boxIntersection=function(t,e){var n=Math.min(t[3],e[3])-Math.max(t[1],e[1]),r=Math.min(t[2],e[2])-Math.max(t[0],e[0]);return n<0||r<0?0:n*r},u=e.boxUnion=function(t,e){var n=s(t,e);return(t[3]-t[1])*(t[2]-t[0])+(e[3]-e[1])*(e[2]-e[0])-n},c=e.boxIOU=function(t,e){return s(t,e)/u(t,e)};e.boxesToCorners=function(t,e){return a.tidy(function(){var n=a.tensor1d([2]),r=a.sub(t,a.div(e,n)),i=a.add(t,a.div(e,n)),o=[r.shape[0],r.shape[1],r.shape[2],1];return a.concat([r.slice([0,0,0,1],o),r.slice([0,0,0,0],o),i.slice([0,0,0,1],o),i.slice([0,0,0,0],o)],3)})},e.nonMaxSuppression=function(t,e,n){return a.tidy(function(){for(var r=[],i=0;i<e.length;i+=1)r.push([e[i],[t[4*i],t[4*i+1],t[4*i+2],t[4*i+3]],i]);var a=[];return r.sort(function(t,e){return e[0]-t[0]}).forEach(function(t){for(var e=!0,r=0;r<a.length;r+=1){if(c(t[1],a[r][1])>n){e=!1;break}}e&&a.push(t)}),[a.map(function(t){return t[2]}),a.map(function(t){return t[1]}),a.map(function(t){return t[0]})]})}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=["person","bicycle","car","motorbike","aeroplane","bus","train","truck","boat","traffic light","fire hydrant","stop sign","parking meter","bench","bird","cat","dog","horse","sheep","cow","elephant","bear","zebra","giraffe","backpack","umbrella","handbag","tie","suitcase","frisbee","skis","snowboard","sports ball","kite","baseball bat","baseball glove","skateboard","surfboard","tennis racket","bottle","wine glass","cup","fork","knife","spoon","bowl","banana","apple","sandwich","orange","broccoli","carrot","hot dog","pizza","donut","cake","chair","sofa","pottedplant","bed","diningtable","toilet","tvmonitor","laptop","mouse","remote","keyboard","cell phone","microwave","oven","toaster","sink","refrigerator","book","clock","vase","scissors","teddy bear","hair drier","toothbrush"]},function(t,e,n){var r=n(23);r(r.S,"Object",{create:n(117)})},function(t,e,n){n(350);var r=n(18).Object;t.exports=function(t,e){return r.create(t,e)}},function(t,e,n){t.exports={default:n(351),__esModule:!0}},function(t,e,n){var r=n(38),i=n(48),a=function(t,e){if(i(t),!r(e)&&null!==e)throw TypeError(e+": can't set as prototype!")};t.exports={set:Object.setPrototypeOf||("__proto__"in{}?function(t,e,r){try{(r=n(56)(Function.call,n(219).f(Object.prototype,"__proto__").set,2))(t,[]),e=!(t instanceof Array)}catch(t){e=!0}return function(t,n){return a(t,n),e?t.__proto__=n:r(t,n),t}}({},!1):void 0),check:a}},function(t,e,n){var r=n(23);r(r.S,"Object",{setPrototypeOf:n(353).set})},function(t,e,n){n(354),t.exports=n(18).Object.setPrototypeOf},function(t,e,n){t.exports={default:n(355),__esModule:!0}},function(t,e,n){var r=n(66),i=n(232);n(209)("getPrototypeOf",function(){return function(t){return i(r(t))}})},function(t,e,n){n(357),t.exports=n(18).Object.getPrototypeOf},function(t,e,n){var r=n(23),i=n(207)(!1);r(r.S,"Object",{values:function(t){return i(t)}})},function(t,e,n){n(359),t.exports=n(18).Object.values},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=d(n(208)),i=d(n(9)),a=d(n(54)),o=d(n(8)),s=d(n(7)),u=d(n(10)),c=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(4)),l=d(n(55)),f=d(n(15));function d(t){return t&&t.__esModule?t:{default:t}}var h=function(){function t(e,n){(0,s.default)(this,t),this.model={},this.modelPath=e,this.modelSize=0,this.modelLoaded=!1,this.ready=(0,f.default)(this.loadModel(),n)}return(0,u.default)(t,[{key:"loadModel",value:function(){var t=(0,o.default)(i.default.mark(function t(){var e,n,r=this;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,l.default.get(this.modelPath);case 2:return e=t.sent,n=e.data,(0,a.default)(n.vectors).forEach(function(t){r.model[t]=c.tensor1d(n.vectors[t])}),this.modelSize=(0,a.default)(this.model).length,this.modelLoaded=!0,t.abrupt("return",this);case 8:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"dispose",value:function(t){(0,r.default)(this.model).forEach(function(t){return t.dispose()}),t&&t()}},{key:"add",value:function(){var e=(0,o.default)(i.default.mark(function e(n,r,a){var o,s,u,l=this;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return o=t.parser(r,a,10),s=o.max,u=o.callback,e.next=3,this.ready;case 3:return e.abrupt("return",c.tidy(function(){var e=t.addOrSubtract(l.model,n,"ADD"),r=t.nearest(l.model,e,n.length,n.length+s);return u&&u(void 0,r),r}));case 4:case"end":return e.stop()}},e,this)}));return function(t,n,r){return e.apply(this,arguments)}}()},{key:"subtract",value:function(){var e=(0,o.default)(i.default.mark(function e(n,r,a){var o,s,u,l=this;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return o=t.parser(r,a,10),s=o.max,u=o.callback,e.next=3,this.ready;case 3:return e.abrupt("return",c.tidy(function(){var e=t.addOrSubtract(l.model,n,"SUBTRACT"),r=t.nearest(l.model,e,n.length,n.length+s);return u&&u(void 0,r),r}));case 4:case"end":return e.stop()}},e,this)}));return function(t,n,r){return e.apply(this,arguments)}}()},{key:"average",value:function(){var e=(0,o.default)(i.default.mark(function e(n,r,a){var o,s,u,l=this;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return o=t.parser(r,a,10),s=o.max,u=o.callback,e.next=3,this.ready;case 3:return e.abrupt("return",c.tidy(function(){var e=t.addOrSubtract(l.model,n,"ADD"),r=c.div(e,c.tensor(n.length)),i=t.nearest(l.model,r,n.length,n.length+s);return u&&u(void 0,i),i}));case 4:case"end":return e.stop()}},e,this)}));return function(t,n,r){return e.apply(this,arguments)}}()},{key:"nearest",value:function(){var e=(0,o.default)(i.default.mark(function e(n,r,a){var o,s,u,c,l;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return o=t.parser(r,a,10),s=o.max,u=o.callback,e.next=3,this.ready;case 3:return c=this.model[n],l=void 0,l=c?t.nearest(this.model,c,1,s+1):null,u&&u(void 0,l),e.abrupt("return",l);case 8:case"end":return e.stop()}},e,this)}));return function(t,n,r){return e.apply(this,arguments)}}()},{key:"nearestFromSet",value:function(){var e=(0,o.default)(i.default.mark(function e(n,r,a,o){var s,u,c,l,f,d,h=this;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return s=t.parser(a,o,10),u=s.max,c=s.callback,e.next=3,this.ready;case 3:if(l=this.model[n]){e.next=7;break}return c&&c(void 0,null),e.abrupt("return",null);case 7:if(f={},r.forEach(function(t){h.model[t]&&(f[t]=h.model[t])}),f.length){e.next=12;break}return c&&c(void 0,null),e.abrupt("return",null);case 12:return d=t.nearest(f,l,1,u+1),c&&c(void 0,d),e.abrupt("return",d);case 15:case"end":return e.stop()}},e,this)}));return function(t,n,r,i){return e.apply(this,arguments)}}()},{key:"getRandomWord",value:function(){var t=(0,o.default)(i.default.mark(function t(e){var n,r;return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.ready;case 2:return n=(0,a.default)(this.model),r=n[Math.floor(Math.random()*n.length)],e&&e(void 0,r),t.abrupt("return",r);case 6:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()}],[{key:"parser",value:function(t,e,n){var r=n,i=e;return"function"==typeof t?i=t:"number"==typeof t&&(r=t),{max:r,callback:i}}},{key:"addOrSubtract",value:function(t,e,n){return c.tidy(function(){var r=[],i=[];if(e.length<2)throw new Error("Invalid input, must be passed more than 1 value");if(e.forEach(function(e){var n=t[e];n?r.push(n):i.push(e)}),i.length>0)throw new Error("Invalid input, vector not found for: "+i.toString());var a=r[0];if("ADD"===n)for(var o=1;o<r.length;o+=1)a=c.add(a,r[o]);else for(var s=1;s<r.length;s+=1)a=c.sub(a,r[s]);return a})}},{key:"nearest",value:function(t,e,n,r){var i=[];return(0,a.default)(t).forEach(function(n){var r=c.util.distSquared(e.dataSync(),t[n].dataSync());i.push({word:n,distance:r})}),i.sort(function(t,e){return t.distance-e.distance}),i.slice(n,r)}}]),t}();e.default=function(t,e){return new h(t,e)}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=v(n(99)),i=v(n(47)),a=v(n(89)),o=v(n(14)),s=v(n(9)),u=v(n(8)),c=v(n(7)),l=v(n(10)),f=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(4)),d=v(n(55)),h=v(n(143)),p=n(46),m=n(115),g=v(n(15));function v(t){return t&&t.__esModule?t:{default:t}}var y=224,b=[y,y],x="https://storage.googleapis.com/tfjs-models/tfjs/mobilenet_v",w={version:1,alpha:.25,topk:3,learningRate:1e-4,hiddenUnits:100,epochs:20,numLabels:2,batchSize:.4,layer:"conv_pw_13_relu"},k={1:{.25:"https://tfhub.dev/google/imagenet/mobilenet_v1_025_224/classification/1",.5:"https://tfhub.dev/google/imagenet/mobilenet_v1_050_224/classification/1",.75:"https://tfhub.dev/google/imagenet/mobilenet_v1_075_224/classification/1",1:"https://tfhub.dev/google/imagenet/mobilenet_v1_100_224/classification/1"},2:{.5:"https://tfhub.dev/google/imagenet/mobilenet_v2_050_224/classification/2",.75:"https://tfhub.dev/google/imagenet/mobilenet_v2_075_224/classification/2",1:"https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/2"}},_={1:"module_apply_default/MobilenetV1/Logits/global_pool",2:"module_apply_default/MobilenetV2/Logits/AvgPool"},E=function(){function t(e,n){(0,c.default)(this,t),this.mobilenet=null,this.topKPredictions=10,this.hasAnyTrainedClass=!1,this.customModel=null,this.jointModel=null,this.config={epochs:e.epochs||w.epochs,version:e.version||w.version,hiddenUnits:e.hiddenUnits||w.hiddenUnits,numLabels:e.numLabels||w.numLabels,learningRate:e.learningRate||w.learningRate,batchSize:e.batchSize||w.batchSize,layer:e.layer||w.layer,alpha:e.alpha||w.alpha},this.model=null,this.url=k[this.config.version][this.config.alpha],this.normalizationOffset=f.scalar(127.5),this.mobilenetURL=e.mobilenetURL||""+x+this.config.version+"_"+this.config.alpha+"_"+y+"/model.json",this.graphModelURL=e.graphModelURL||this.url,this.isPredicting=!1,this.mapStringToIndex=[],this.usageType=null,this.ready=(0,g.default)(this.loadModel(),n)}return(0,l.default)(t,[{key:"loadModel",value:function(){var t=(0,u.default)(s.default.mark(function t(){var e;return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,f.loadLayersModel(this.mobilenetURL);case 2:if(this.mobilenet=t.sent,!this.graphModelURL.includes("https://tfhub.dev/")){t.next=9;break}return t.next=6,f.loadGraphModel(this.graphModelURL,{fromTFHub:!0});case 6:this.model=t.sent,t.next=12;break;case 9:return t.next=11,f.loadGraphModel(this.graphModelURL,{fromTFHub:!1});case 11:this.model=t.sent;case 12:return e=this.mobilenet.getLayer(this.config.layer),t.next=15,f.model({inputs:this.mobilenet.inputs,outputs:e.output});case 15:if(this.mobilenetFeatures=t.sent,!this.video){t.next=19;break}return t.next=19,this.mobilenetFeatures.predict((0,p.imgToTensor)(this.video,b));case 19:return t.abrupt("return",this);case 20:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"classification",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments[2],r=void 0;return this.usageType="classifier","object"===(void 0===e?"undefined":(0,o.default)(e))?(0,a.default)(this.config,e):"function"==typeof e&&(r=e),"function"==typeof n&&(r=n),t&&(0,g.default)(this.loadVideo(t),r),this}},{key:"regression",value:function(t,e){return this.usageType="regressor",t&&(0,g.default)(this.loadVideo(t),e),this}},{key:"loadVideo",value:function(){var t=(0,u.default)(s.default.mark(function t(e){var n,r;return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(n=null,e instanceof HTMLVideoElement?n=e:"object"===(void 0===e?"undefined":(0,o.default)(e))&&e.elt instanceof HTMLVideoElement&&(n=e.elt),!n){t.next=7;break}return r=new h.default(n,y),t.next=6,r.loadVideo();case 6:this.video=t.sent;case 7:return t.abrupt("return",this);case 8:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"addImage",value:function(){var t=(0,u.default)(s.default.mark(function t(e,n,r){var i,a,u;return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return i=void 0,a=void 0,u=r,e instanceof HTMLImageElement||e instanceof HTMLVideoElement||e instanceof HTMLCanvasElement||e.elt instanceof ImageData?i=e:"object"===(void 0===e?"undefined":(0,o.default)(e))&&(e.elt instanceof HTMLImageElement||e.elt instanceof HTMLVideoElement||e.elt instanceof HTMLCanvasElement||e.elt instanceof ImageData)?i=e.elt:"string"!=typeof e&&"number"!=typeof e||(i=this.video,a=e),"string"==typeof n||"number"==typeof n?a=n:"function"==typeof n&&(u=n),"string"==typeof a&&(a=this.mapStringToIndex.includes(a)?this.mapStringToIndex.indexOf(a):this.mapStringToIndex.push(a)-1),t.abrupt("return",(0,g.default)(this.addImageInternal(i,a),u));case 7:case"end":return t.stop()}},t,this)}));return function(e,n,r){return t.apply(this,arguments)}}()},{key:"addImageInternal",value:function(){var t=(0,u.default)(s.default.mark(function t(e,n){var r=this;return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.ready;case 2:return f.tidy(function(){var t=(0,p.imgToTensor)(e,b),i=r.mobilenetFeatures.predict(t),a=void 0;if("classifier"===r.usageType?a=f.tidy(function(){return f.oneHot(f.tensor1d([n],"int32"),r.config.numLabels)}):"regressor"===r.usageType&&(a=f.tensor2d([[n]])),null==r.xs)r.xs=f.keep(i),r.ys=f.keep(a),r.hasAnyTrainedClass=!0;else{var o=r.xs;r.xs=f.keep(o.concat(i,0));var s=r.ys;r.ys=f.keep(s.concat(a,0)),o.dispose(),s.dispose(),a.dispose()}}),t.abrupt("return",this);case 4:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"train",value:function(){var t=(0,u.default)(s.default.mark(function t(e){var n,r,i=this;return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.hasAnyTrainedClass){t.next=2;break}throw new Error("Add some examples before training!");case 2:if(this.isPredicting=!1,"classifier"===this.usageType?(this.loss="categoricalCrossentropy",this.customModel=f.sequential({layers:[f.layers.flatten({inputShape:[7,7,256]}),f.layers.dense({units:this.config.hiddenUnits,activation:"relu",kernelInitializer:"varianceScaling",useBias:!0}),f.layers.dense({units:this.config.numLabels,kernelInitializer:"varianceScaling",useBias:!1,activation:"softmax"})]})):"regressor"===this.usageType&&(this.loss="meanSquaredError",this.customModel=f.sequential({layers:[f.layers.flatten({inputShape:[7,7,256]}),f.layers.dense({units:this.config.hiddenUnits,activation:"relu",kernelInitializer:"varianceScaling",useBias:!0}),f.layers.dense({units:1,useBias:!1,kernelInitializer:"Zeros",activation:"linear"})]})),this.jointModel=f.sequential(),this.jointModel.add(this.mobilenetFeatures),this.jointModel.add(this.customModel),n=f.train.adam(this.config.learningRate),this.customModel.compile({optimizer:n,loss:this.loss}),(r=Math.floor(this.xs.shape[0]*this.config.batchSize))>0){t.next=12;break}throw new Error("Batch size is 0 or NaN. Please choose a non-zero fraction.");case 12:return t.abrupt("return",this.customModel.fit(this.xs,this.ys,{batchSize:r,epochs:this.config.epochs,callbacks:{onBatchEnd:function(){var t=(0,u.default)(s.default.mark(function t(n,r){return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e(r.loss.toFixed(5)),t.next=3,f.nextFrame();case 3:case"end":return t.stop()}},t,i)}));return function(e,n){return t.apply(this,arguments)}}(),onTrainEnd:function(){return e(null)}}}));case 13:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"classify",value:function(){var t=(0,u.default)(s.default.mark(function t(e,n){var r,i;return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=void 0,i=void 0,e instanceof HTMLImageElement||e instanceof HTMLVideoElement||e instanceof HTMLCanvasElement||e instanceof ImageData?r=e:"object"===(void 0===e?"undefined":(0,o.default)(e))&&(e.elt instanceof HTMLImageElement||e.elt instanceof HTMLVideoElement||e.elt instanceof HTMLCanvasElement||e.elt instanceof ImageData)?r=e.elt:"function"==typeof e&&(r=this.video,i=e),"function"==typeof n&&(i=n),t.abrupt("return",(0,g.default)(this.classifyInternal(r),i));case 5:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"classifyInternal",value:function(){var t=(0,u.default)(s.default.mark(function t(e){var n,r,a=this;return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if("classifier"===this.usageType){t.next=2;break}throw new Error("Mobilenet Feature Extraction has not been set to be a classifier.");case 2:return t.next=4,f.nextFrame();case 4:return this.isPredicting=!0,n=f.tidy(function(){var t=(0,p.imgToTensor)(e,b),n=a.jointModel.predict(t);return(0,i.default)(n.as1D().dataSync())}),t.next=8,n.map(function(t,e){return{label:a.mapStringToIndex.length>0&&a.mapStringToIndex[e]?a.mapStringToIndex[e]:e,confidence:t}}).sort(function(t,e){return e.confidence-t.confidence});case 8:return r=t.sent,t.abrupt("return",r);case 10:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"predict",value:function(){var t=(0,u.default)(s.default.mark(function t(e,n){var r,i;return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=void 0,i=void 0,e instanceof HTMLImageElement||e instanceof HTMLVideoElement||e instanceof HTMLCanvasElement||e instanceof ImageData?r=e:"object"===(void 0===e?"undefined":(0,o.default)(e))&&(e.elt instanceof HTMLImageElement||e.elt instanceof HTMLVideoElement||e.elt instanceof HTMLCanvasElement||e.elt instanceof ImageData)?r=e.elt:"function"==typeof e&&(r=this.video,i=e),"function"==typeof n&&(i=n),t.abrupt("return",(0,g.default)(this.predictInternal(r),i));case 5:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"predictInternal",value:function(){var t=(0,u.default)(s.default.mark(function t(e){var n,r,i=this;return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if("regressor"===this.usageType){t.next=2;break}throw new Error("Mobilenet Feature Extraction has not been set to be a regressor.");case 2:return t.next=4,f.nextFrame();case 4:return this.isPredicting=!0,n=f.tidy(function(){var t=(0,p.imgToTensor)(e,b);return i.jointModel.predict(t).as1D()}),t.next=8,n.data();case 8:return r=t.sent,n.dispose(),t.abrupt("return",{value:r[0]});case 11:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"load",value:function(){var t=(0,u.default)(s.default.mark(function t(){var e,n,r,a,o=this,u=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,c=arguments[1];return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if("string"==typeof u){t.next=9;break}return e=null,n=null,(0,i.default)(u).forEach(function(t){if(t.name.includes(".json")){e=t;var r=new FileReader;r.onload=function(t){JSON.parse(t.target.result).ml5Specs&&(o.mapStringToIndex=JSON.parse(t.target.result).ml5Specs.mapStringToIndex)},r.readAsText(t)}else t.name.includes(".bin")&&(n=t)}),t.next=6,f.loadLayersModel(f.io.browserFiles([e,n]));case 6:this.jointModel=t.sent,t.next=18;break;case 9:return t.next=11,d.default.get(u);case 11:return r=t.sent,(a=r.data).ml5Specs&&(this.mapStringToIndex=a.ml5Specs.mapStringToIndex),t.next=16,f.loadLayersModel(u);case 16:this.jointModel=t.sent,c&&c();case 18:return t.abrupt("return",this.jointModel);case 19:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"save",value:function(){var t=(0,u.default)(s.default.mark(function t(e,n){var i=this;return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.jointModel){t.next=2;break}throw new Error("No model found.");case 2:this.jointModel.save(f.io.withSaveHandler(function(){var t=(0,u.default)(s.default.mark(function t(a){var o;return s.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return o="model",n&&(o=n),i.weightsManifest={modelTopology:a.modelTopology,weightsManifest:[{paths:["./"+o+".weights.bin"],weights:a.weightSpecs}],ml5Specs:{mapStringToIndex:i.mapStringToIndex}},t.next=5,(0,m.saveBlob)(a.weightData,o+".weights.bin","application/octet-stream");case 5:return t.next=7,(0,m.saveBlob)((0,r.default)(i.weightsManifest),o+".json","text/plain");case 7:e&&e();case 8:case"end":return t.stop()}},t,i)}));return function(e){return t.apply(this,arguments)}}()));case 3:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"mobilenetInfer",value:function(t){var e=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=t;return r instanceof f.Tensor||r instanceof ImageData||r instanceof HTMLImageElement||r instanceof HTMLCanvasElement||r instanceof HTMLVideoElement?f.tidy(function(){r instanceof f.Tensor||(r=f.browser.fromPixels(r));var t=r.toFloat().sub(e.normalizationOffset).div(e.normalizationOffset),i=t;if(r.shape[0]!==y||r.shape[1]!==y){i=f.image.resizeBilinear(t,b,!0)}var a=i.reshape([-1,y,y,3]),o=void 0;if(n){var s=_[e.config.version];o=e.model.execute(a,s).squeeze([1,2])}else{o=e.model.predict(a).slice([0,1],[-1,1e3])}return o}):null}},{key:"infer",value:function(t,e){var n=void 0,r=void 0;if(t instanceof HTMLImageElement||t instanceof HTMLVideoElement||t instanceof HTMLCanvasElement||t instanceof ImageData)n=t;else{if("object"!==(void 0===t?"undefined":(0,o.default)(t))||!(t.elt instanceof HTMLImageElement||t.elt instanceof HTMLVideoElement||t.elt instanceof HTMLCanvasElement||t.elt instanceof ImageData))throw new Error("No input image found.");n=t.elt}return r=e&&"string"==typeof e?e:"conv_preds",this.mobilenetInfer(n,r)}}]),t}();e.default=E},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=a(n(14)),i=a(n(362));function a(t){return t&&t.__esModule?t:{default:t}}e.default=function(t,e,n){var a=void 0;if("string"!=typeof t)throw new Error('Please specify a model to use. E.g: "MobileNet"');a=t.toLowerCase();var o={},s=n;if("object"===(void 0===e?"undefined":(0,r.default)(e))?o=e:"function"==typeof e&&(s=e),"mobilenet"===a)return new i.default(o,s);throw new Error(a+" is not a valid model.")}},function(t,e,n){"use strict";n.r(e),n.d(e,"KNNClassifier",function(){return o}),n.d(e,"create",function(){return s});var r=n(0);function i(t,e){return null==t&&null==e?null:null==t?e.clone():null===e?t.clone():t.concat(e,0)}function a(t,e){for(var n=[],r=0;r<t.length;r++)n.push({value:t[r],index:r});n.sort(function(t,e){return e.value-t.value});var i=new Float32Array(e),a=new Int32Array(e);for(r=0;r<e;r++)i[r]=n[r].value,a[r]=n[r].index;return{values:i,indices:a}}var o=function(){function t(){this.classDatasetMatrices={},this.classExampleCount={},this.labelToClassId={},this.nextClassId=0}return t.prototype.addExample=function(t,e){var n=this;if(null==this.exampleShape&&(this.exampleShape=t.shape),!r.util.arraysEqual(this.exampleShape,t.shape))throw new Error("Example shape provided, "+t.shape+" does not match previously provided example shapes "+this.exampleShape+".");this.clearTrainDatasetMatrix(),e in this.labelToClassId||(this.labelToClassId[e]=this.nextClassId++),Object(r.tidy)(function(){var i=n.normalizeVectorToUnitLength(t.flatten()),a=i.shape[0];if(null==n.classDatasetMatrices[e])n.classDatasetMatrices[e]=i.as2D(1,a);else{var o=n.classDatasetMatrices[e].as2D(n.classExampleCount[e],a).concat(i.as2D(1,a),0);n.classDatasetMatrices[e].dispose(),n.classDatasetMatrices[e]=o}Object(r.keep)(n.classDatasetMatrices[e]),null==n.classExampleCount[e]&&(n.classExampleCount[e]=0),n.classExampleCount[e]++})},t.prototype.similarities=function(t){var e=this;return Object(r.tidy)(function(){var n=e.normalizeVectorToUnitLength(t.flatten()),a=n.shape[0];if(null==e.trainDatasetMatrix){var o=null;for(var s in e.classDatasetMatrices)o=i(o,e.classDatasetMatrices[s]);e.trainDatasetMatrix=o}if(null==e.trainDatasetMatrix)return console.warn("Cannot predict without providing training examples."),null;Object(r.keep)(e.trainDatasetMatrix);var u=e.getNumExamples();return e.trainDatasetMatrix.as2D(u,a).matMul(n.as2D(a,1)).as1D()})},t.prototype.predictClass=function(t,e){return void 0===e&&(e=3),function(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})}(this,void 0,void 0,function(){var n,i,o,s,u=this;return function(t,e){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=(i=o.trys).length>0&&i[i.length-1])&&(6===a[0]||2===a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}(this,function(c){switch(c.label){case 0:if(e<1)throw new Error("Please provide a positive integer k value to predictClass.");if(0===this.getNumExamples())throw new Error("You have not added any examples to the KNN classifier. Please add examples before calling predictClass.");return n=Object(r.tidy)(function(){return u.similarities(t).asType("float32")}),i=Math.min(e,this.getNumExamples()),s=a,[4,n.data()];case 1:return o=s.apply(void 0,[c.sent(),i]).indices,n.dispose(),[2,this.calculateTopClass(o,i)]}})})},t.prototype.clearClass=function(t){if(null==this.classDatasetMatrices[t])throw new Error("Cannot clear invalid class "+t);delete this.classDatasetMatrices[t],delete this.classExampleCount[t],this.clearTrainDatasetMatrix()},t.prototype.clearAllClasses=function(){for(var t in this.classDatasetMatrices)this.clearClass(t)},t.prototype.getClassExampleCount=function(){return this.classExampleCount},t.prototype.getClassifierDataset=function(){return this.classDatasetMatrices},t.prototype.getNumClasses=function(){return Object.keys(this.classExampleCount).length},t.prototype.setClassifierDataset=function(t){for(var e in this.clearTrainDatasetMatrix(),this.classDatasetMatrices=t,t)this.classExampleCount[e]=t[e].shape[0]},t.prototype.calculateTopClass=function(t,e){var n,r={};if(null==t)return{classIndex:this.labelToClassId[n],label:n,confidences:r};var i={},a=0;for(var o in this.classDatasetMatrices)a+=this.classExampleCount[o],i[o]=a;var s={};for(var o in this.classDatasetMatrices)s[o]=0;for(var u=0;u<t.length;u++){var c=t[u];for(var o in this.classDatasetMatrices)if(c<i[o]){s[o]++;break}}var l=0;for(var o in this.classDatasetMatrices){var f=s[o]/e;f>l&&(l=f,n=o),r[o]=f}return{classIndex:this.labelToClassId[n],label:n,confidences:r}},t.prototype.clearTrainDatasetMatrix=function(){null!=this.trainDatasetMatrix&&(this.trainDatasetMatrix.dispose(),this.trainDatasetMatrix=null)},t.prototype.normalizeVectorToUnitLength=function(t){return Object(r.tidy)(function(){var e=t.norm();return Object(r.div)(t,e)})},t.prototype.getNumExamples=function(){var t=0;for(var e in this.classDatasetMatrices)t+=this.classExampleCount[e];return t},t.prototype.dispose=function(){for(var t in this.clearTrainDatasetMatrix(),this.classDatasetMatrices)this.classDatasetMatrices[t].dispose()},t}();function s(){return new o}},function(t,e,n){var r=n(66),i=n(88);n(209)("keys",function(){return function(t){return i(r(t))}})},function(t,e,n){n(365),t.exports=n(18).Object.keys},function(t,e,n){var r=n(18),i=r.JSON||(r.JSON={stringify:JSON.stringify});t.exports=function(t){return i.stringify.apply(i,arguments)}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=m(n(14)),i=m(n(99)),a=m(n(54)),o=m(n(9)),s=m(n(8)),u=m(n(7)),c=m(n(10)),l=p(n(4)),f=p(n(364)),d=p(n(115)),h=m(n(15));function p(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}function m(t){return t&&t.__esModule?t:{default:t}}var g=function(){function t(){(0,u.default)(this,t),this.knnClassifier=f.create(),this.mapStringToIndex=[]}return(0,c.default)(t,[{key:"addExample",value:function(t,e){var n=void 0,r=void 0;"string"==typeof e?n=this.mapStringToIndex.includes(e)?this.mapStringToIndex.indexOf(e):this.mapStringToIndex.push(e)-1:"number"==typeof e&&(n=e),r=Array.isArray(t)?l.tensor(t):t,this.knnClassifier.addExample(r,n)}},{key:"classify",value:function(){var t=(0,s.default)(o.default.mark(function t(e,n,r){var i,a,s;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return i=3,a=r,s=void 0,"number"==typeof n?i=n:"function"==typeof n&&(a=n),s=Array.isArray(e)?l.tensor(e):e,t.abrupt("return",(0,h.default)(this.classifyInternal(s,i),a));case 6:case"end":return t.stop()}},t,this)}));return function(e,n,r){return t.apply(this,arguments)}}()},{key:"classifyInternal",value:function(){var t=(0,s.default)(o.default.mark(function t(e,n){var r,i,s,u=this;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!(this.knnClassifier.getNumClasses()<=0)){t.next=5;break}throw new Error("There is no example in any class");case 5:return t.next=7,this.knnClassifier.predictClass(e,n);case 7:return r=t.sent,this.mapStringToIndex.length>0&&((r.classIndex||0===r.classIndex)&&(i=this.mapStringToIndex[r.classIndex])&&(r.label=i),r.confidences&&(r.confidencesByLabel={},s=r.confidences,(0,a.default)(s).forEach(function(t){var e=u.mapStringToIndex[t];r.confidencesByLabel[e]=s[t]}))),t.abrupt("return",r);case 10:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"clearLabel",value:function(t){var e=void 0;"string"==typeof t?this.mapStringToIndex.includes(t)&&(e=this.mapStringToIndex.indexOf(t)):"number"==typeof t&&(e=t),this.knnClassifier.clearClass(e)}},{key:"clearAllLabels",value:function(){this.mapStringToIndex=[],this.knnClassifier.clearAllClasses()}},{key:"getCountByLabel",value:function(){var t=this,e=this.knnClassifier.getClassExampleCount();if(this.mapStringToIndex.length>0){var n={};return(0,a.default)(e).forEach(function(r){if(t.mapStringToIndex[r]){var i=t.mapStringToIndex[r];n[i]=e[r]}}),n}return e}},{key:"getCount",value:function(){return this.knnClassifier.getClassExampleCount()}},{key:"getClassifierDataset",value:function(){return this.knnClassifier.getClassifierDataset()}},{key:"setClassifierDataset",value:function(t){this.knnClassifier.setClassifierDataset(t)}},{key:"getNumLabels",value:function(){return this.knnClassifier.getNumClasses()}},{key:"dispose",value:function(){this.knnClassifier.dispose()}},{key:"save",value:function(){var t=(0,s.default)(o.default.mark(function t(e){var n,r,s,u=this;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=this.knnClassifier.getClassifierDataset(),this.mapStringToIndex.length>0&&(0,a.default)(n).forEach(function(t){u.mapStringToIndex[t]&&(n[t].label=u.mapStringToIndex[t])}),r=(0,a.default)(n).map(function(t){var e=n[t];return e?e.dataSync():null}),s="myKNN.json",e&&(s=e.endsWith(".json")?e:e+".json"),t.next=7,d.saveBlob((0,i.default)({dataset:n,tensors:r}),s,"application/octet-stream");case 7:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"load",value:function(){var t=(0,s.default)(o.default.mark(function t(e,n){var i,s,u,c,f;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(i=void 0,"object"!==(void 0===e?"undefined":(0,r.default)(e))){t.next=5;break}i=e,t.next=8;break;case 5:return t.next=7,d.loadFile(e);case 7:i=t.sent;case 8:i&&(u=(s=i).dataset,c=s.tensors,this.mapStringToIndex=(0,a.default)(u).map(function(t){return u[t].label}),f=c.map(function(t,e){if(t){var n=(0,a.default)(t).map(function(e){return t[e]});return l.tensor(n,u[e].shape,u[e].dtype)}return null}).reduce(function(t,e,n){return t[n]=e,t},{}),this.knnClassifier.setClassifierDataset(f),n&&n());case 9:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()}]),t}();e.default=function(){return new g}},function(t,e,n){"use strict";n.r(e),n.d(e,"create",function(){return B}),n.d(e,"utils",function(){return U}),n.d(e,"BACKGROUND_NOISE_TAG",function(){return _}),n.d(e,"Dataset",function(){return E}),n.d(e,"getMaxIntensityFrameIndex",function(){return N}),n.d(e,"spectrogram2IntensityCurve",function(){return A}),n.d(e,"deleteSavedTransferModel",function(){return z}),n.d(e,"listSavedTransferModels",function(){return L}),n.d(e,"UNKNOWN_TAG",function(){return I}),n.d(e,"version",function(){return T});var r=n(4),i=function(t,e){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};
  339. /**
  340. * @license
  341. * Copyright 2019 Google LLC. All Rights Reserved.
  342. * Licensed under the Apache License, Version 2.0 (the "License");
  343. * you may not use this file except in compliance with the License.
  344. * You may obtain a copy of the License at
  345. *
  346. * http://www.apache.org/licenses/LICENSE-2.0
  347. *
  348. * Unless required by applicable law or agreed to in writing, software
  349. * distributed under the License is distributed on an "AS IS" BASIS,
  350. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  351. * See the License for the specific language governing permissions and
  352. * limitations under the License.
  353. * =============================================================================
  354. */var a=function(){return(a=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function o(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})}function s(t,e){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=(i=o.trys).length>0&&i[i.length-1])&&(6===a[0]||2===a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}function u(t){var e="function"==typeof Symbol&&t[Symbol.iterator],n=0;return e?e.call(t):{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}function c(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,a=n.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(r=a.next()).done;)o.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=a.return)&&n.call(a)}finally{if(i)throw i.error}}return o}function l(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(c(arguments[e]));return t}var f=null;function d(t){return null==f&&(f=Object(r.backend)().epsilon()),Object(r.tidy)(function(){var e=Object(r.moments)(t),n=e.mean,i=e.variance;return t.sub(n).div(i.sqrt().add(f))})}var h=function(){function t(t){var e=this;if(null==t)throw new Error("Required configuration object is missing for BrowserFftFeatureExtractor constructor");if(null==t.spectrogramCallback)throw new Error("spectrogramCallback cannot be null or undefined");if(!(t.numFramesPerSpectrogram>0))throw new Error("Invalid value in numFramesPerSpectrogram: "+t.numFramesPerSpectrogram);if(t.suppressionTimeMillis<0)throw new Error("Expected suppressionTimeMillis to be >= 0, but got "+t.suppressionTimeMillis);if(this.suppressionTimeMillis=t.suppressionTimeMillis,this.spectrogramCallback=t.spectrogramCallback,this.numFrames=t.numFramesPerSpectrogram,this.sampleRateHz=t.sampleRateHz||44100,this.fftSize=t.fftSize||1024,this.frameDurationMillis=this.fftSize/this.sampleRateHz*1e3,this.columnTruncateLength=t.columnTruncateLength||this.fftSize,this.overlapFactor=t.overlapFactor,this.includeRawAudio=t.includeRawAudio,r.util.assert(this.overlapFactor>=0&&this.overlapFactor<1,function(){return"Expected overlapFactor to be >= 0 and < 1, but got "+e.overlapFactor}),this.columnTruncateLength>this.fftSize)throw new Error("columnTruncateLength "+this.columnTruncateLength+" exceeds fftSize ("+this.fftSize+").");this.audioContextConstructor=window.AudioContext||window.webkitAudioContext}return t.prototype.start=function(t){return o(this,void 0,void 0,function(){var e,n,r;return s(this,function(i){switch(i.label){case 0:if(null!=this.frameIntervalTask)throw new Error("Cannot start already-started BrowserFftFeatureExtractor");return e=this,[4,function(t){return o(this,void 0,void 0,function(){return s(this,function(e){switch(e.label){case 0:return[4,navigator.mediaDevices.getUserMedia({audio:null==t||t,video:!1})];case 1:return[2,e.sent()]}})})}(t)];case 1:return e.stream=i.sent(),this.audioContext=new this.audioContextConstructor,this.audioContext.sampleRate!==this.sampleRateHz&&console.warn("Mismatch in sampling rate: Expected: "+this.sampleRateHz+"; Actual: "+this.audioContext.sampleRate),n=this.audioContext.createMediaStreamSource(this.stream),this.analyser=this.audioContext.createAnalyser(),this.analyser.fftSize=2*this.fftSize,this.analyser.smoothingTimeConstant=0,n.connect(this.analyser),this.freqDataQueue=[],this.freqData=new Float32Array(this.fftSize),this.includeRawAudio&&(this.timeDataQueue=[],this.timeData=new Float32Array(this.fftSize)),r=Math.max(1,Math.round(this.numFrames*(1-this.overlapFactor))),this.tracker=new g(r,Math.round(this.suppressionTimeMillis/this.frameDurationMillis)),this.frameIntervalTask=setInterval(this.onAudioFrame.bind(this),this.fftSize/this.sampleRateHz*1e3),[2]}})})},t.prototype.onAudioFrame=function(){return o(this,void 0,void 0,function(){var t,e,n,i;return s(this,function(a){switch(a.label){case 0:return this.analyser.getFloatFrequencyData(this.freqData),this.freqData[0]===-1/0?[2]:(this.freqDataQueue.push(this.freqData.slice(0,this.columnTruncateLength)),this.includeRawAudio&&(this.analyser.getFloatTimeDomainData(this.timeData),this.timeDataQueue.push(this.timeData.slice())),this.freqDataQueue.length>this.numFrames&&this.freqDataQueue.shift(),this.tracker.tick()?(t=p(this.freqDataQueue),e=m(t,[1,this.numFrames,this.columnTruncateLength,1]),n=void 0,this.includeRawAudio&&(i=p(this.timeDataQueue),n=m(i,[1,this.numFrames*this.fftSize])),[4,this.spectrogramCallback(e,n)]):[3,2]);case 1:a.sent()&&this.tracker.suppress(),Object(r.dispose)([e,n]),a.label=2;case 2:return[2]}})})},t.prototype.stop=function(){return o(this,void 0,void 0,function(){return s(this,function(t){if(null==this.frameIntervalTask)throw new Error("Cannot stop because there is no ongoing streaming activity.");return clearInterval(this.frameIntervalTask),this.frameIntervalTask=null,this.analyser.disconnect(),this.audioContext.close(),null!=this.stream&&this.stream.getTracks().length>0&&this.stream.getTracks()[0].stop(),[2]})})},t.prototype.setConfig=function(t){throw new Error("setConfig() is not implemented for BrowserFftFeatureExtractor.")},t.prototype.getFeatures=function(){throw new Error("getFeatures() is not implemented for BrowserFftFeatureExtractor. Use the spectrogramCallback field of the constructor config instead.")},t}();function p(t){var e=t[0].length,n=new Float32Array(t.length*e);return t.forEach(function(t,r){return n.set(t,r*e)}),n}function m(t,e){var n=new Float32Array(r.util.sizeFromShape(e));return n.set(t,n.length-t.length),Object(r.tensor)(n,e)}var g=function(){function t(t,e){var n=this;this.period=t,this.suppressionTime=null==e?0:e,this.counter=0,r.util.assert(this.period>0,function(){return"Expected period to be positive, but got "+n.period})}return t.prototype.tick=function(){return this.counter++,this.counter%this.period==0&&(null==this.suppressionOnset||this.counter-this.suppressionOnset>this.suppressionTime)},t.prototype.suppress=function(){this.suppressionOnset=this.counter},t}();function v(t){var e=0;t.forEach(function(t){e+=t.byteLength});var n=new Uint8Array(e),r=0;return t.forEach(function(t){n.set(new Uint8Array(t),r),r+=t.byteLength}),n.buffer}function y(t){var e=0;t.forEach(function(t){return e+=t.length});var n=new Float32Array(e),r=0;return t.forEach(function(t){n.set(t,r),r+=t.length}),n}function b(t){if(null==t)throw new Error("Received null or undefind string");for(var e=unescape(encodeURIComponent(t)),n=new Uint8Array(e.length),r=0;r<e.length;++r)n[r]=e.charCodeAt(r);return n.buffer}function x(t){if(null==t)throw new Error("Received null or undefind buffer");var e=new Uint8Array(t);return decodeURIComponent(escape(String.fromCharCode.apply(String,l(e))))}var w="TFJSSCDS",k=1,_="_background_noise_",E=function(){function t(t){if(this.examples={},this.label2Ids={},null!=t)for(var e=function(t){r.util.assert(null!=t,function(){return"Received null or undefined buffer"});var e=0,n=x(t.slice(e,w.length));r.util.assert(n===w,function(){return"Deserialization error: Invalid descriptor"}),e+=w.length,e+=4;var i=new Uint32Array(t,e,1),a=e+=4;e=a+i[0];var o=x(t.slice(a,e));return{manifest:JSON.parse(o),data:t.slice(e)}}(t),n=0,i=0;i<e.manifest.length;++i){var a=e.manifest[i],o=a.spectrogramNumFrames*a.spectrogramFrameSize;null!=a.rawAudioNumSamples&&(o+=a.rawAudioNumSamples),o*=4,this.addExample(S({spec:a,data:e.data.slice(n,n+o)})),n+=o}}return t.prototype.addExample=function(t){r.util.assert(null!=t,function(){return"Got null or undefined example"}),r.util.assert(null!=t.label&&t.label.length>0,function(){return"Expected label to be a non-empty string, but got "+JSON.stringify(t.label)});var e=function(){function t(){return Math.floor(65536*(1+Math.random())).toString(16).substring(1)}return t()+t()+"-"+t()+"-"+t()+"-"+t()+"-"+t()+t()+t()}();return this.examples[e]=t,t.label in this.label2Ids||(this.label2Ids[t.label]=[]),this.label2Ids[t.label].push(e),e},t.prototype.merge=function(t){var e,n,i,a;r.util.assert(t!==this,function(){return"Cannot merge a dataset into itself"});var o=t.getVocabulary();try{for(var s=u(o),c=s.next();!c.done;c=s.next()){var l=c.value,f=t.getExamples(l);try{for(var d=u(f),h=d.next();!h.done;h=d.next()){var p=h.value;this.addExample(p.example)}}catch(t){i={error:t}}finally{try{h&&!h.done&&(a=d.return)&&a.call(d)}finally{if(i)throw i.error}}}}catch(t){e={error:t}}finally{try{c&&!c.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}},t.prototype.getExampleCounts=function(){var t={};for(var e in this.examples){var n=this.examples[e];n.label in t||(t[n.label]=0),t[n.label]++}return t},t.prototype.getExamples=function(t){var e=this;r.util.assert(null!=t,function(){return"Expected label to be a string, but got "+JSON.stringify(t)}),r.util.assert(t in this.label2Ids,function(){return'No example of label "'+t+'" exists in dataset'});var n=[];return this.label2Ids[t].forEach(function(t){n.push({uid:t,example:e.examples[t]})}),n},t.prototype.getData=function(t,e){var n=this;r.util.assert(this.size()>0,function(){return"Cannot get spectrograms as tensors because the dataset is empty"});var i=this.getVocabulary();null!=t?r.util.assert(-1!==i.indexOf(t),function(){return"Label "+t+" is not in the vocabulary ("+JSON.stringify(i)+")"}):r.util.assert(i.length>1,function(){return"One-hot encoding of labels requires the vocabulary to have at least two words, but it has only "+i.length+" word."}),null==e&&(e={});var a,o,s=this.getSortedUniqueNumFrames();1===s.length?(a=null==e.numFrames?s[0]:e.numFrames,o=null==e.hopFrames?1:e.hopFrames):(a=e.numFrames,r.util.assert(null!=a&&Number.isInteger(a)&&a>0,function(){return"There are "+s.length+" unique lengths among the "+n.size()+" examples of this Dataset, hence numFrames is required. But it is not provided."}),r.util.assert(a<=s[0],function(){return"numFrames ("+a+") exceeds the minimum numFrames ("+s[0]+") among the examples of the Dataset."}),o=e.hopFrames,r.util.assert(null!=o&&Number.isInteger(o)&&o>0,function(){return"There are "+s.length+" unique lengths among the "+n.size()+" examples of this Dataset, hence hopFrames is required. But it is not provided."}));var c=null==e.normalize||e.normalize;return Object(r.tidy)(function(){for(var s,l,f,h=[],p=[],m=[],g=0;g<i.length;++g){var v=i[g];if(null==t||v===t){var y=n.label2Ids[v],b=function(i){var s,l,y=n.examples[i].spectrogram,b=y.frameSize;null==f?f=b:r.util.assert(b===f,function(){return"Mismatch in frameSize ("+b+" vs "+f+")"});var x=y.data.length/b,w=null;v!==_&&(w=null==y.keyFrameIndex?N(y).dataSync()[0]:y.keyFrameIndex);var k=Object(r.tensor3d)(y.data,[x,b,1]),E=C(x,w,a,o),O=function(n){var i=Object(r.tidy)(function(){var t=k.slice([n[0],0,0],[n[1]-n[0],-1,-1]);return c?d(t):t});e.getDataset?p.push(i.dataSync()):h.push(i),null==t&&m.push(g)};try{for(var S=u(E),A=S.next();!A.done;A=S.next())O(A.value)}catch(t){s={error:t}}finally{try{A&&!A.done&&(l=S.return)&&l.call(S)}finally{if(s)throw s.error}}Object(r.dispose)(k)};try{for(var x=u(y),w=x.next();!w.done;w=x.next())b(w.value)}catch(t){s={error:t}}finally{try{w&&!w.done&&(l=x.return)&&l.call(x)}finally{if(s)throw s.error}}}}null!=e.augmentByMixingNoiseRatio&&n.augmentByMixingNoise(e.getDataset?p:h,m,e.augmentByMixingNoiseRatio);var k=null==e.shuffle||e.shuffle;if(e.getDataset){var E=null==e.datasetBatchSize?32:e.datasetBatchSize,O=null==e.datasetValidationSplit?.15:e.datasetValidationSplit;r.util.assert(O>0&&O<1,function(){return"Invalid dataset validation split: "+O});var S=p.map(function(t,e){return[t,m[e]]});r.util.shuffle(S),p=S.map(function(t){return t[0]});var A=S.map(function(t){return t[1]}),T=function(t,e,n){var i,a,o,s,c,l,f,d;r.util.assert(n>0&&n<1,function(){return"validationSplit is expected to be >0 and <1, but got "+n});for(var h=!Array.isArray(t[0]),p=e,m=[],g=0;g<p.length;++g){var v=p[g];null==m[v]&&(m[v]=[]),m[v].push(g)}var y=m.length,b=[],x=[];for(m.map(function(t){return r.util.shuffle(t)}),g=0;g<y;++g)for(var w=m[g],k=Math.round(w.length*(1-n)),_=0;_<w.length;++_)_<k?b.push(w[_]):x.push(w[_]);if(h){var E=[],O=[],S=[],C=[];try{for(var A=u(b),N=A.next();!N.done;N=A.next()){var T=N.value;E.push(t[T]),O.push(e[T])}}catch(t){i={error:t}}finally{try{N&&!N.done&&(a=A.return)&&a.call(A)}finally{if(i)throw i.error}}try{for(var I=u(x),D=I.next();!D.done;D=I.next())T=D.value,S.push(t[T]),C.push(e[T])}catch(t){o={error:t}}finally{try{D&&!D.done&&(s=I.return)&&s.call(I)}finally{if(o)throw o.error}}return{trainXs:E,trainYs:O,valXs:S,valYs:C}}E=[],O=[],S=[],C=[];try{for(var M=u(b),R=M.next();!R.done;R=M.next())T=R.value,E.push(t[T]),O.push(e[T])}catch(t){c={error:t}}finally{try{R&&!R.done&&(l=M.return)&&l.call(M)}finally{if(c)throw c.error}}try{for(var F=u(x),j=F.next();!j.done;j=F.next())T=j.value,S.push(t[T]),C.push(e[T])}catch(t){f={error:t}}finally{try{j&&!j.done&&(d=F.return)&&d.call(F)}finally{if(f)throw f.error}}return{trainXs:E,trainYs:O,valXs:S,valYs:C}}(p,A,O),I=T.trainXs,D=T.trainYs,M=T.valXs,R=T.valYs,F=r.data.array(I).map(function(t){return Object(r.tensor3d)(t,[a,f,1])}),j=r.data.array(D).map(function(t){return Object(r.oneHot)([t],i.length).squeeze([0])}),P=r.data.zip({xs:F,ys:j});k&&(P=P.shuffle(p.length)),P=P.batch(E).prefetch(4);var L=r.data.array(M).map(function(t){return Object(r.tensor3d)(t,[a,f,1])}),z=r.data.array(R).map(function(t){return Object(r.oneHot)([t],i.length).squeeze([0])}),B=r.data.zip({xs:L,ys:z});return[P,B=B.batch(E).prefetch(4)]}if(k){var U=[];h.forEach(function(t,e){U.push({x:t,y:m[e]})}),r.util.shuffle(U),h=U.map(function(t){return t.x}),m=U.map(function(t){return t.y})}var W=null==t?Object(r.oneHot)(Object(r.tensor1d)(m,"int32"),i.length).asType("float32"):void 0;return{xs:Object(r.stack)(h),ys:W}})},t.prototype.augmentByMixingNoise=function(t,e,n){var i,a;if(null==t||0===t.length)throw new Error("Cannot perform augmentation because data is null or empty");for(var o=t[0]instanceof Float32Array,s=this.getVocabulary(),c=[],f=[],h=0;h<e.length;++h)s[e[h]]===_?c.push(h):f.push(h);if(0===c.length)throw new Error("Cannot perform augmentation by mixing with noise when there is no example with label "+_);var p=[],m=[],g=function(i){var a=c[function(t,e){return Math.floor((e-t)*Math.random())+t}(0,c.length)],s=o?Object(r.tensor1d)(t[i]):t[i],u=o?Object(r.tensor1d)(t[a]):t[a],l=Object(r.tidy)(function(){return d(s.add(u.mul(n)))});o?p.push(l.dataSync()):p.push(l),m.push(e[i])};try{for(var v=u(f),y=v.next();!y.done;y=v.next())g(y.value)}catch(t){i={error:t}}finally{try{y&&!y.done&&(a=v.return)&&a.call(v)}finally{if(i)throw i.error}}console.log("Data augmentation: mixing noise: added "+p.length+" examples"),p.forEach(function(e){return t.push(e)}),e.push.apply(e,l(m))},t.prototype.getSortedUniqueNumFrames=function(){for(var t,e,n=new Set,r=this.getVocabulary(),i=0;i<r.length;++i){var a=r[i],o=this.label2Ids[a];try{for(var s=u(o),c=s.next();!c.done;c=s.next()){var f=c.value,d=this.examples[f].spectrogram,h=d.data.length/d.frameSize;n.add(h)}}catch(e){t={error:e}}finally{try{c&&!c.done&&(e=s.return)&&e.call(s)}finally{if(t)throw t.error}}}var p=l(n);return p.sort(),p},t.prototype.removeExample=function(t){if(!(t in this.examples))throw new Error("Nonexistent example UID: "+t);var e=this.examples[t].label;delete this.examples[t];var n=this.label2Ids[e].indexOf(t);this.label2Ids[e].splice(n,1),0===this.label2Ids[e].length&&delete this.label2Ids[e]},t.prototype.setExampleKeyFrameIndex=function(t,e){if(!(t in this.examples))throw new Error("Nonexistent example UID: "+t);var n=this.examples[t].spectrogram,i=n.data.length/n.frameSize;r.util.assert(e>=0&&e<i&&Number.isInteger(e),function(){return"Invalid keyFrameIndex: "+e+". Must be >= 0, < "+i+", and an integer."}),n.keyFrameIndex=e},t.prototype.size=function(){return Object.keys(this.examples).length},t.prototype.durationMillis=function(){var t=0;for(var e in this.examples){var n=this.examples[e].spectrogram,r=23.22|n.frameDurationMillis;t+=n.data.length/n.frameSize*r}return t},t.prototype.empty=function(){return 0===this.size()},t.prototype.clear=function(){this.examples={}},t.prototype.getVocabulary=function(){var t=new Set;for(var e in this.examples){var n=this.examples[e];t.add(n.label)}var r=l(t);return r.sort(),r},t.prototype.serialize=function(t){var e,n,i,a,o=this.getVocabulary();r.util.assert(!this.empty(),function(){return"Cannot serialize empty Dataset"}),null!=t&&(Array.isArray(t)||(t=[t]),t.forEach(function(t){if(-1===o.indexOf(t))throw new Error('Word label "'+t+'" does not exist in the vocabulary of this dataset. The vocabulary is: '+JSON.stringify(o)+".")}));var s=[],c=[];try{for(var l=u(o),f=l.next();!f.done;f=l.next()){var d=f.value;if(null==t||-1!==t.indexOf(d)){var h=this.label2Ids[d];try{for(var p=u(h),m=p.next();!m.done;m=p.next()){var g=m.value,y=O(this.examples[g]);s.push(y.spec),c.push(y.data)}}catch(t){i={error:t}}finally{try{m&&!m.done&&(a=p.return)&&a.call(p)}finally{if(i)throw i.error}}}}}catch(t){e={error:t}}finally{try{f&&!f.done&&(n=l.return)&&n.call(l)}finally{if(e)throw e.error}}return function(t){var e=b(JSON.stringify(t.manifest)),n=b(w),r=new Uint32Array([k]),i=new Uint32Array([e.byteLength]);return v([v([n,r.buffer,i.buffer]),e,t.data])}({manifest:s,data:v(c)})},t}();function O(t){var e=null!=t.rawAudio,n={label:t.label,spectrogramNumFrames:t.spectrogram.data.length/t.spectrogram.frameSize,spectrogramFrameSize:t.spectrogram.frameSize};null!=t.spectrogram.keyFrameIndex&&(n.spectrogramKeyFrameIndex=t.spectrogram.keyFrameIndex);var r=t.spectrogram.data.buffer.slice(0);return e&&(n.rawAudioNumSamples=t.rawAudio.data.length,n.rawAudioSampleRateHz=t.rawAudio.sampleRateHz,r=v([r,t.rawAudio.data.buffer])),{spec:n,data:r}}function S(t){var e={frameSize:t.spec.spectrogramFrameSize,data:new Float32Array(t.data.slice(0,4*t.spec.spectrogramFrameSize*t.spec.spectrogramNumFrames))};null!=t.spec.spectrogramKeyFrameIndex&&(e.keyFrameIndex=t.spec.spectrogramKeyFrameIndex);var n={label:t.spec.label,spectrogram:e};return null!=t.spec.rawAudioNumSamples&&(n.rawAudio={sampleRateHz:t.spec.rawAudioSampleRateHz,data:new Float32Array(t.data.slice(4*t.spec.spectrogramFrameSize*t.spec.spectrogramNumFrames))}),n}function C(t,e,n,i){if(r.util.assert(Number.isInteger(t)&&t>0,function(){return"snippetLength must be a positive integer, but got "+t}),null!=e&&r.util.assert(Number.isInteger(e)&&e>=0,function(){return"focusIndex must be a non-negative integer, but got "+e}),r.util.assert(Number.isInteger(n)&&n>0,function(){return"windowLength must be a positive integer, but got "+n}),r.util.assert(Number.isInteger(i)&&i>0,function(){return"windowHop must be a positive integer, but got "+i}),r.util.assert(n<=t,function(){return"windowLength ("+n+") exceeds snippetLength ("+t+")"}),r.util.assert(e<t,function(){return"focusIndex ("+e+") equals or exceeds snippetLength ("+t+")"}),n===t)return[[0,t]];var a=[];if(null==e){for(var o=0;o+n<=t;)a.push([o,o+n]),o+=i;return a}var s=Math.floor(n/2),u=e-s;for(u<0?u=0:u+n>t&&(u=t-n);!(u-i<0||e>=u-i+n);)u-=i;for(;u+n<=t&&!(e<u);)a.push([u,u+n]),u+=i;return a}function A(t){return Object(r.tidy)(function(){var e=t.data.length/t.frameSize;return Object(r.tensor2d)(t.data,[e,t.frameSize]).mean(-1)})}function N(t){return Object(r.tidy)(function(){return A(t).argMax()})}var T="0.3.9",I="_unknown_",D="tfjs-speech-commands-saved-model-metadata",M="indexeddb://tfjs-speech-commands-model/",R={localStorage:"undefined"==typeof window?null:window.localStorage};var F=function(){function t(e,n,i){this.MODEL_URL_PREFIX="https://storage.googleapis.com/tfjs-models/tfjs/speech-commands/v"+function(t){return t.split(".").slice(0,2).join(".")}(T)+"/browser_fft",this.SAMPLE_RATE_HZ=44100,this.FFT_SIZE=1024,this.DEFAULT_SUPPRESSION_TIME_MILLIS=0,this.streaming=!1,this.transferRecognizers={},r.util.assert(null==n&&null==i||null!=n&&null!=i,function(){return"modelURL and metadataURL must be both provided or both not provided."}),null==n?(null==e?e=t.DEFAULT_VOCABULARY_NAME:r.util.assert(-1!==t.VALID_VOCABULARY_NAMES.indexOf(e),function(){return"Invalid vocabulary name: '"+e+"'"}),this.vocabulary=e,this.modelArtifactsOrURL=this.MODEL_URL_PREFIX+"/"+this.vocabulary+"/model.json",this.metadataOrURL=this.MODEL_URL_PREFIX+"/"+this.vocabulary+"/metadata.json"):(r.util.assert(null==e,function(){return"vocabulary name must be null or undefined when modelURL is provided"}),this.modelArtifactsOrURL=n,this.metadataOrURL=i),this.parameters={sampleRateHz:this.SAMPLE_RATE_HZ,fftSize:this.FFT_SIZE}}return t.prototype.listen=function(t,e){return o(this,void 0,void 0,function(){var n,i,a,u,f,p=this;return s(this,function(m){switch(m.label){case 0:if(this.streaming)throw new Error("Cannot start streaming again when streaming is ongoing.");return[4,this.ensureModelLoaded()];case 1:if(m.sent(),null==e&&(e={}),n=null==e.probabilityThreshold?0:e.probabilityThreshold,e.includeEmbedding&&(n=0),r.util.assert(n>=0&&n<=1,function(){return"Invalid probabilityThreshold value: "+n}),i=null!=e.invokeCallbackOnNoiseAndUnknown&&e.invokeCallbackOnNoiseAndUnknown,e.includeEmbedding&&(i=!0),e.suppressionTimeMillis<0)throw new Error("suppressionTimeMillis is expected to be >= 0, but got "+e.suppressionTimeMillis);return a=null==e.overlapFactor?.5:e.overlapFactor,r.util.assert(a>=0&&a<1,function(){return"Expected overlapFactor to be >= 0 and < 1, but got "+a}),u=function(a,u){return o(p,void 0,void 0,function(){var o,u,f,h,p,m,g,v,y,b,x;return s(this,function(s){switch(s.label){case 0:return u=d(a),e.includeEmbedding?[4,this.ensureModelWithEmbeddingOutputCreated()]:[3,2];case 1:return s.sent(),o=c(this.modelWithEmbeddingOutput.predict(u),2),f=o[0],h=o[1],[3,3];case 2:f=this.model.predict(u),s.label=3;case 3:return[4,f.data()];case 4:return p=s.sent(),[4,(m=f.argMax(-1)).data()];case 5:return g=s.sent()[0],v=Math.max.apply(Math,l(p)),Object(r.dispose)([f,m,u]),v<n?[2,!1]:[3,6];case 6:return y=void 0,e.includeSpectrogram?(b={},[4,a.data()]):[3,8];case 7:b.data=s.sent(),b.frameSize=this.nonBatchInputShape[1],y=b,s.label=8;case 8:return x=!0,i||this.words[g]!==_&&this.words[g]!==I||(x=!1),x&&t({scores:p,spectrogram:y,embedding:h}),[2,x]}})})},f=null==e.suppressionTimeMillis?this.DEFAULT_SUPPRESSION_TIME_MILLIS:e.suppressionTimeMillis,this.audioDataExtractor=new h({sampleRateHz:this.parameters.sampleRateHz,numFramesPerSpectrogram:this.nonBatchInputShape[0],columnTruncateLength:this.nonBatchInputShape[1],suppressionTimeMillis:f,spectrogramCallback:u,overlapFactor:a}),[4,this.audioDataExtractor.start(e.audioTrackConstraints)];case 2:return m.sent(),this.streaming=!0,[2]}})})},t.prototype.ensureModelLoaded=function(){return o(this,void 0,void 0,function(){var t,e,n,i,a=this;return s(this,function(o){switch(o.label){case 0:return null!=this.model?[2]:[4,this.ensureMetadataLoaded()];case 1:return o.sent(),"string"!=typeof this.modelArtifactsOrURL?[3,3]:[4,Object(r.loadLayersModel)(this.modelArtifactsOrURL)];case 2:return t=o.sent(),[3,5];case 3:return[4,Object(r.loadLayersModel)(r.io.fromMemory(this.modelArtifactsOrURL.modelTopology,this.modelArtifactsOrURL.weightSpecs,this.modelArtifactsOrURL.weightData))];case 4:t=o.sent(),o.label=5;case 5:if(1!==t.inputs.length)throw new Error("Expected model to have 1 input, but got a model with "+t.inputs.length+" inputs");if(4!==t.inputs[0].shape.length)throw new Error("Expected model to have an input shape of rank 4, but got an input shape of rank "+t.inputs[0].shape.length);if(1!==t.inputs[0].shape[3])throw new Error("Expected model to have an input shape with 1 as the last dimension, but got input shape"+JSON.stringify(t.inputs[0].shape[3])+"}");if(2!==(e=t.outputShape).length)throw new Error("Expected loaded model to have an output shape of rank 2,but received shape "+JSON.stringify(e));if(e[1]!==this.words.length)throw new Error("Mismatch between the last dimension of model's output shape ("+e[1]+") and number of words ("+this.words.length+").");return this.model=t,this.freezeModel(),this.nonBatchInputShape=t.inputs[0].shape.slice(1),this.elementsPerExample=1,t.inputs[0].shape.slice(1).forEach(function(t){return a.elementsPerExample*=t}),this.warmUpModel(),n=this.parameters.fftSize/this.parameters.sampleRateHz*1e3,i=t.inputs[0].shape[1],this.parameters.spectrogramDurationMillis=i*n,[2]}})})},t.prototype.ensureModelWithEmbeddingOutputCreated=function(){return o(this,void 0,void 0,function(){var t,e;return s(this,function(n){switch(n.label){case 0:return null!=this.modelWithEmbeddingOutput?[2]:[4,this.ensureModelLoaded()];case 1:for(n.sent(),e=this.model.layers.length-2;e>=0;--e)if("Dense"===this.model.layers[e].getClassName()){t=this.model.layers[e];break}if(null==t)throw new Error("Failed to find second last dense layer in the original model.");return this.modelWithEmbeddingOutput=Object(r.model)({inputs:this.model.inputs,outputs:[this.model.outputs[0],t.output]}),[2]}})})},t.prototype.warmUpModel=function(){var t=this;Object(r.tidy)(function(){for(var e=Object(r.zeros)([1].concat(t.nonBatchInputShape)),n=0;n<3;++n)t.model.predict(e)})},t.prototype.ensureMetadataLoaded=function(){return o(this,void 0,void 0,function(){var t,e,r;return s(this,function(i){switch(i.label){case 0:return null!=this.words?[2]:"string"!=typeof this.metadataOrURL?[3,2]:[4,function(t){return o(this,void 0,void 0,function(){return s(this,function(e){return[2,new Promise(function(e,r){0===t.indexOf("http://")||0===t.indexOf("https://")?fetch(t).then(function(t){t.json().then(function(t){return e(t)})}):0===t.indexOf("file://")?n(210).readFile(t.slice("file://".length),{encoding:"utf-8"},function(t,n){return e(JSON.parse(n))}):r(new Error("Unsupported URL scheme in metadata URL: "+t+". Supported schemes are: http://, https://, and (node.js-only) file://"))})]})})}(this.metadataOrURL)];case 1:return e=i.sent(),[3,3];case 2:e=this.metadataOrURL,i.label=3;case 3:if(null==(t=e).wordLabels){if(null==(r=t.words))throw new Error('Cannot find field "words" or "wordLabels" in metadata JSON file');this.words=r}else this.words=t.wordLabels;return[2]}})})},t.prototype.stopListening=function(){return o(this,void 0,void 0,function(){return s(this,function(t){switch(t.label){case 0:if(!this.streaming)throw new Error("Cannot stop streaming when streaming is not ongoing.");return[4,this.audioDataExtractor.stop()];case 1:return t.sent(),this.streaming=!1,[2]}})})},t.prototype.isListening=function(){return this.streaming},t.prototype.wordLabels=function(){return this.words},t.prototype.params=function(){return this.parameters},t.prototype.modelInputShape=function(){if(null==this.model)throw new Error("Model has not been loaded yet. Load model by calling ensureModelLoaded(), recognize(), or listen().");return this.model.inputs[0].shape},t.prototype.recognize=function(t,e){return o(this,void 0,void 0,function(){var n,i,a,o,u,c,l,f,d,h,p,m,g;return s(this,function(s){switch(s.label){case 0:return null==e&&(e={}),[4,this.ensureModelLoaded()];case 1:return s.sent(),null!=t?[3,3]:[4,this.recognizeOnline()];case 2:n=s.sent(),t=n.data,s.label=3;case 3:if(t instanceof r.Tensor)this.checkInputTensorShape(t),a=t,i=t.shape[0];else{if((t=t).length%this.elementsPerExample)throw new Error("The length of the input Float32Array "+t.length+" is not divisible by the number of tensor elements per per example expected by the model "+this.elementsPerExample+".");i=t.length/this.elementsPerExample,a=Object(r.tensor4d)(t,[i].concat(this.nonBatchInputShape))}return u={scores:null},e.includeEmbedding?[4,this.ensureModelWithEmbeddingOutputCreated()]:[3,5];case 4:return s.sent(),c=this.modelWithEmbeddingOutput.predict(a),o=c[0],u.embedding=c[1],[3,6];case 5:o=this.model.predict(a),s.label=6;case 6:return 1!==i?[3,8]:(l=u,[4,o.data()]);case 7:return l.scores=s.sent(),[3,10];case 8:return f=Object(r.unstack)(o),d=f.map(function(t){return t.data()}),h=u,[4,Promise.all(d)];case 9:h.scores=s.sent(),Object(r.dispose)(f),s.label=10;case 10:return e.includeSpectrogram?(p=u,m={},t instanceof r.Tensor?[4,t.data()]:[3,12]):[3,14];case 11:return g=s.sent(),[3,13];case 12:g=t,s.label=13;case 13:p.spectrogram=(m.data=g,m.frameSize=this.nonBatchInputShape[1],m),s.label=14;case 14:return[2,u]}})})},t.prototype.recognizeOnline=function(){return o(this,void 0,void 0,function(){var t=this;return s(this,function(e){return[2,new Promise(function(e,n){t.audioDataExtractor=new h({sampleRateHz:t.parameters.sampleRateHz,numFramesPerSpectrogram:t.nonBatchInputShape[0],columnTruncateLength:t.nonBatchInputShape[1],suppressionTimeMillis:0,spectrogramCallback:function(n){return o(t,void 0,void 0,function(){var t,r,i;return s(this,function(a){switch(a.label){case 0:return t=d(n),[4,this.audioDataExtractor.stop()];case 1:return a.sent(),r=e,i={},[4,t.data()];case 2:return r.apply(void 0,[(i.data=a.sent(),i.frameSize=this.nonBatchInputShape[1],i)]),t.dispose(),[2,!1]}})})},overlapFactor:0}),t.audioDataExtractor.start()})]})})},t.prototype.createTransfer=function(t){if(null==this.model)throw new Error("Model has not been loaded yet. Load model by calling ensureModelLoaded(), recognizer(), or listen().");r.util.assert(null!=t&&"string"==typeof t&&t.length>1,function(){return"Expected the name for a transfer-learning recognized to be a non-empty string, but got "+JSON.stringify(t)}),r.util.assert(null==this.transferRecognizers[t],function(){return"There is already a transfer-learning model named '"+t+"'"});var e=new j(t,this.parameters,this.model);return this.transferRecognizers[t]=e,e},t.prototype.freezeModel=function(){var t,e;try{for(var n=u(this.model.layers),r=n.next();!r.done;r=n.next())r.value.trainable=!1}catch(e){t={error:e}}finally{try{r&&!r.done&&(e=n.return)&&e.call(n)}finally{if(t)throw t.error}}},t.prototype.checkInputTensorShape=function(t){var e=this.model.inputs[0].shape.length;if(t.shape.length!==e)throw new Error("Expected input Tensor to have rank "+e+", but got rank "+t.shape.length+" that differs ");var n=t.shape.slice(1),i=this.model.inputs[0].shape.slice(1);if(!r.util.arraysEqual(n,i))throw new Error("Expected input to have shape [null,"+i+"], but got shape [null,"+n+"]")},t.VALID_VOCABULARY_NAMES=["18w","directional4w"],t.DEFAULT_VOCABULARY_NAME="18w",t}(),j=function(t){function e(e,n,i){var a=t.call(this)||this;return a.name=e,a.parameters=n,a.baseModel=i,r.util.assert(null!=e&&"string"==typeof e&&e.length>0,function(){return"The name of a transfer model must be a non-empty string, but got "+JSON.stringify(e)}),a.nonBatchInputShape=a.baseModel.inputs[0].shape.slice(1),a.words=null,a.dataset=new E,a}return function(t,e){function n(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(e,t),e.prototype.collectExample=function(t,e){return o(this,void 0,void 0,function(){var n,i,a,u,c=this;return s(this,function(l){if(r.util.assert(!this.streaming,function(){return"Cannot start collection of transfer-learning example because a streaming recognition or transfer-learning example collection is ongoing"}),r.util.assert(null!=t&&"string"==typeof t&&t.length>0,function(){return"Must provide a non-empty string when collecting transfer-learning example"}),null==e&&(e={}),null!=e.durationMultiplier&&null!=e.durationSec)throw new Error("durationMultiplier and durationSec are mutually exclusive, but are both specified.");return null!=e.durationSec?(r.util.assert(e.durationSec>0,function(){return"Expected durationSec to be > 0, but got "+e.durationSec}),i=this.parameters.fftSize/this.parameters.sampleRateHz,n=Math.ceil(e.durationSec/i)):null!=e.durationMultiplier?(r.util.assert(e.durationMultiplier>=1,function(){return"Expected duration multiplier to be >= 1, but got "+e.durationMultiplier}),n=Math.round(this.nonBatchInputShape[0]*e.durationMultiplier)):n=this.nonBatchInputShape[0],null!=e.snippetDurationSec&&(r.util.assert(e.snippetDurationSec>0,function(){return"snippetDurationSec is expected to be > 0, but got "+e.snippetDurationSec}),r.util.assert(null!=e.onSnippet,function(){return"onSnippet must be provided if snippetDurationSec is provided."})),null!=e.onSnippet&&r.util.assert(null!=e.snippetDurationSec,function(){return"snippetDurationSec must be provided if onSnippet is provided."}),a=this.parameters.fftSize/this.parameters.sampleRateHz,u=a*n,this.streaming=!0,[2,new Promise(function(i){var a=null==e.snippetDurationSec?1:e.snippetDurationSec/u,l=1-a,p=Math.round(1/a),m=0,g=-1,v=[];c.audioDataExtractor=new h({sampleRateHz:c.parameters.sampleRateHz,numFramesPerSpectrogram:n,columnTruncateLength:c.nonBatchInputShape[1],suppressionTimeMillis:0,spectrogramCallback:function(n,a){return o(c,void 0,void 0,function(){var o,u,c,l,h,b,x,w,k,_,E,O,S,C,A,N,T,I,D,M;return s(this,function(s){switch(s.label){case 0:return null!=e.onSnippet?[3,7]:(o=d(n),c=(u=this.dataset).addExample,l={label:t},h={},[4,o.data()]);case 1:return l.spectrogram=(h.data=s.sent(),h.frameSize=this.nonBatchInputShape[1],h),e.includeRawAudio?(x={},[4,a.data()]):[3,3];case 2:return x.data=s.sent(),x.sampleRateHz=this.audioDataExtractor.sampleRateHz,b=x,[3,4];case 3:b=void 0,s.label=4;case 4:return c.apply(u,[(l.rawAudio=b,l)]),o.dispose(),[4,this.audioDataExtractor.stop()];case 5:return s.sent(),this.streaming=!1,this.collateTransferWords(),w=i,k={},[4,n.data()];case 6:return w.apply(void 0,[(k.data=s.sent(),k.frameSize=this.nonBatchInputShape[1],k)]),[3,13];case 7:return[4,n.data()];case 8:for(_=s.sent(),-1===g&&(g=_.length),E=g-1;0!==_[E]&&E>=0;)E--;return O=g-E-1,g=E+1,S=_.slice(_.length-O,_.length),v.push(S),null!=e.onSnippet&&e.onSnippet({data:S,frameSize:this.nonBatchInputShape[1]}),m++!==p?[3,13]:[4,this.audioDataExtractor.stop()];case 9:return s.sent(),this.streaming=!1,this.collateTransferWords(),C=function(t){if(t.length<2)throw new Error("Cannot normalize a Float32Array with fewer than 2 elements.");return null==f&&(f=Object(r.backend)().epsilon()),Object(r.tidy)(function(){var e=Object(r.moments)(Object(r.tensor1d)(t)),n=e.mean,i=e.variance,a=n.arraySync(),o=Math.sqrt(i.arraySync()),s=Array.from(t).map(function(t){return(t-a)/(o+f)});return new Float32Array(s)})}(y(v)),A={data:C,frameSize:this.nonBatchInputShape[1]},T=(N=this.dataset).addExample,I={label:t,spectrogram:A},e.includeRawAudio?(M={},[4,a.data()]):[3,11];case 10:return M.data=s.sent(),M.sampleRateHz=this.audioDataExtractor.sampleRateHz,D=M,[3,12];case 11:D=void 0,s.label=12;case 12:T.apply(N,[(I.rawAudio=D,I)]),i(A),s.label=13;case 13:return[2,!1]}})})},overlapFactor:l,includeRawAudio:e.includeRawAudio}),c.audioDataExtractor.start(e.audioTrackConstraints)})]})})},e.prototype.clearExamples=function(){var t=this;r.util.assert(null!=this.words&&this.words.length>0&&!this.dataset.empty(),function(){return"No transfer learning examples exist for model name "+t.name}),this.dataset.clear(),this.words=null},e.prototype.countExamples=function(){if(this.dataset.empty())throw new Error("No examples have been collected for transfer-learning model named '"+this.name+"' yet.");return this.dataset.getExampleCounts()},e.prototype.getExamples=function(t){return this.dataset.getExamples(t)},e.prototype.setExampleKeyFrameIndex=function(t,e){this.dataset.setExampleKeyFrameIndex(t,e)},e.prototype.removeExample=function(t){this.dataset.removeExample(t),this.collateTransferWords()},e.prototype.isDatasetEmpty=function(){return this.dataset.empty()},e.prototype.loadExamples=function(t,e){var n,r,i,a;void 0===e&&(e=!1);var o=new E(t);e&&this.clearExamples();var s=o.getVocabulary();try{for(var c=u(s),l=c.next();!l.done;l=c.next()){var f=l.value,d=o.getExamples(f);try{for(var h=u(d),p=h.next();!p.done;p=h.next()){var m=p.value;this.dataset.addExample(m.example)}}catch(t){i={error:t}}finally{try{p&&!p.done&&(a=h.return)&&a.call(h)}finally{if(i)throw i.error}}}}catch(t){n={error:t}}finally{try{l&&!l.done&&(r=c.return)&&r.call(c)}finally{if(n)throw n.error}}this.collateTransferWords()},e.prototype.serializeExamples=function(t){return this.dataset.serialize(t)},e.prototype.collateTransferWords=function(){this.words=this.dataset.getVocabulary()},e.prototype.collectTransferDataAsTensors=function(t,e){var n=this.nonBatchInputShape[0];t=t||.25;var r=Math.round(t*n),i=this.dataset.getData(null,a({numFrames:n,hopFrames:r},e));return{xs:i.xs,ys:i.ys}},e.prototype.collectTransferDataAsTfDataset=function(t,e,n,r){void 0===e&&(e=.15),void 0===n&&(n=32);var i=this.nonBatchInputShape[0];t=t||.25;var o=Math.round(t*i);return this.dataset.getData(null,a({numFrames:i,hopFrames:o,getDataset:!0,datasetBatchSize:n,datasetValidationSplit:e},r))},e.prototype.train=function(t){return o(this,void 0,void 0,function(){var e,n=this;return s(this,function(i){switch(i.label){case 0:return r.util.assert(null!=this.words&&this.words.length>0,function(){return"Cannot train transfer-learning model '"+n.name+"' because no transfer learning example has been collected."}),r.util.assert(this.words.length>1,function(){return"Cannot train transfer-learning model '"+n.name+"' because only 1 word label ('"+JSON.stringify(n.words)+"') has been collected for transfer learning. Requires at least 2."}),null!=t.fineTuningEpochs&&r.util.assert(t.fineTuningEpochs>=0&&Number.isInteger(t.fineTuningEpochs),function(){return"If specified, fineTuningEpochs must be a non-negative integer, but received "+t.fineTuningEpochs}),null==t&&(t={}),null==this.model&&this.createTransferModelFromBaseModel(),this.secondLastBaseDenseLayer.trainable=!1,this.model.compile({loss:"categoricalCrossentropy",optimizer:t.optimizer||"sgd",metrics:["acc"]}),e=null==t.fitDatasetDurationMillisThreshold?6e4:t.fitDatasetDurationMillisThreshold,this.dataset.durationMillis()>e?(console.log("Detected large dataset: total duration = "+this.dataset.durationMillis()+" ms > "+e+" ms. Training transfer model using fitDataset() instead of fit()"),[4,this.trainOnDataset(t)]):[3,2];case 1:return[2,i.sent()];case 2:return[4,this.trainOnTensors(t)];case 3:return[2,i.sent()]}})})},e.prototype.trainOnDataset=function(t){return o(this,void 0,void 0,function(){var e,n,i,a,o,u,l,f,d;return s(this,function(s){switch(s.label){case 0:return r.util.assert(t.epochs>0,function(){return"Invalid config.epochs"}),e=null==t.batchSize?32:t.batchSize,n=t.windowHopRatio||.25,i=c(this.collectTransferDataAsTfDataset(n,t.validationSplit,e,{augmentByMixingNoiseRatio:t.augmentByMixingNoiseRatio}),2),a=i[0],o=i[1],u=r.util.now(),[4,this.model.fitDataset(a,{epochs:t.epochs,validationData:t.validationSplit>0?o:null,callbacks:null==t.callback?null:[t.callback]})];case 1:return l=s.sent(),console.log("fitDataset() took "+(r.util.now()-u).toFixed(2)+" ms"),null!=t.fineTuningEpochs&&t.fineTuningEpochs>0?(f=r.util.now(),[4,this.fineTuningUsingTfDatasets(t,a,o)]):[3,3];case 2:return d=s.sent(),console.log("fitDataset() (fine-tuning) took "+(r.util.now()-f).toFixed(2)+" ms"),[2,[l,d]];case 3:return[2,l]}})})},e.prototype.trainOnTensors=function(t){return o(this,void 0,void 0,function(){var e,n,i,a,o,u,c,l,f,d;return s(this,function(s){switch(s.label){case 0:e=t.windowHopRatio||.25,n=this.collectTransferDataAsTensors(e,{augmentByMixingNoiseRatio:t.augmentByMixingNoiseRatio}),i=n.xs,a=n.ys,console.log("Training data: xs.shape = "+i.shape+", ys.shape = "+a.shape),s.label=1;case 1:return s.trys.push([1,,6,7]),null!=t.validationSplit?(l=function(t,e,n){return r.util.assert(n>0&&n<1,function(){return"validationSplit is expected to be >0 and <1, but got "+n}),Object(r.tidy)(function(){for(var i=e.argMax(-1).dataSync(),a=[],o=0;o<i.length;++o){var s=i[o];null==a[s]&&(a[s]=[]),a[s].push(o)}var u=a.length,c=[],l=[];for(a.map(function(t){return r.util.shuffle(t)}),o=0;o<u;++o)for(var f=a[o],d=Math.round(f.length*(1-n)),h=0;h<f.length;++h)h<d?c.push(f[h]):l.push(f[h]);return{trainXs:Object(r.gather)(t,c),trainYs:Object(r.gather)(e,c),valXs:Object(r.gather)(t,l),valYs:Object(r.gather)(e,l)}})}(i,a,t.validationSplit),o=l.trainXs,u=l.trainYs,c=[l.valXs,l.valYs]):(o=i,u=a),[4,this.model.fit(o,u,{epochs:null==t.epochs?20:t.epochs,validationData:c,batchSize:t.batchSize,callbacks:null==t.callback?null:[t.callback]})];case 2:return f=s.sent(),null!=t.fineTuningEpochs&&t.fineTuningEpochs>0?[4,this.fineTuningUsingTensors(t,o,u,c)]:[3,4];case 3:return d=s.sent(),[2,[f,d]];case 4:return[2,f];case 5:return[3,7];case 6:return Object(r.dispose)([i,a,o,u,c]),[7];case 7:return[2]}})})},e.prototype.fineTuningUsingTfDatasets=function(t,e,n){return o(this,void 0,void 0,function(){var r,i,a;return s(this,function(o){switch(o.label){case 0:return r=this.secondLastBaseDenseLayer.trainable,this.secondLastBaseDenseLayer.trainable=!0,i=null==t.fineTuningOptimizer?"sgd":t.fineTuningOptimizer,this.model.compile({loss:"categoricalCrossentropy",optimizer:i,metrics:["acc"]}),[4,this.model.fitDataset(e,{epochs:t.fineTuningEpochs,validationData:n,callbacks:null==t.callback?null:[t.callback]})];case 1:return a=o.sent(),this.secondLastBaseDenseLayer.trainable=r,[2,a]}})})},e.prototype.fineTuningUsingTensors=function(t,e,n,r){return o(this,void 0,void 0,function(){var i,a,o;return s(this,function(s){switch(s.label){case 0:return i=this.secondLastBaseDenseLayer.trainable,this.secondLastBaseDenseLayer.trainable=!0,a=null==t.fineTuningOptimizer?"sgd":t.fineTuningOptimizer,this.model.compile({loss:"categoricalCrossentropy",optimizer:a,metrics:["acc"]}),[4,this.model.fit(e,n,{epochs:t.fineTuningEpochs,validationData:r,batchSize:t.batchSize,callbacks:null==t.fineTuningCallback?null:[t.fineTuningCallback]})];case 1:return o=s.sent(),this.secondLastBaseDenseLayer.trainable=i,[2,o]}})})},e.prototype.evaluate=function(t){return o(this,void 0,void 0,function(){var e,n=this;return s(this,function(i){return r.util.assert(null!=t.wordProbThresholds&&t.wordProbThresholds.length>0,function(){return"Received null or empty wordProbThresholds"}),e=0,r.util.assert(this.words[e]===_,function(){return"Cannot perform evaluation when the first tag is not "+_}),[2,Object(r.tidy)(function(){for(var i=[],a=0,o=n.collectTransferDataAsTensors(t.windowHopRatio),s=o.xs,u=o.ys.argMax(-1).dataSync(),c=n.model.predict(s),l=c.slice([0,1],[c.shape[0],c.shape[1]-1]).max(-1),f=c.shape[0],d=0;d<t.wordProbThresholds.length;++d){for(var h=t.wordProbThresholds[d],p=l.greater(Object(r.scalar)(h)).dataSync(),m=0,g=0,v=0,y=0,b=0;b<f;++b)u[b]===e?(m++,p[b]&&v++):(g++,p[b]&&y++);var x=v/m,w=y/g;i.push({probThreshold:h,fpr:x,tpr:w}),console.log("ROC thresh="+h+": fpr="+x.toFixed(4)+", tpr="+w.toFixed(4)),d>0&&(a+=Math.abs(i[d-1].fpr-i[d].fpr)*(i[d-1].tpr+i[d].tpr)/2)}return{rocCurve:i,auc:a}})]})})},e.prototype.createTransferModelFromBaseModel=function(){var t=this;r.util.assert(null!=this.words,function(){return"No word example is available for tranfer-learning model of name "+t.name});for(var e=this.baseModel.layers,n=e.length-2;n>=0&&"dense"!==e[n].getClassName().toLowerCase();)n--;if(n<0)throw new Error("Cannot find a hidden dense layer in the base model.");this.secondLastBaseDenseLayer=e[n];var i=this.secondLastBaseDenseLayer.output;this.transferHead=Object(r.sequential)(),this.transferHead.add(r.layers.dense({units:this.words.length,activation:"softmax",inputShape:i.shape.slice(1),name:"NewHeadDense"}));var a=this.transferHead.apply(i);this.model=Object(r.model)({inputs:this.baseModel.inputs,outputs:a})},e.prototype.modelInputShape=function(){return this.baseModel.inputs[0].shape},e.prototype.getMetadata=function(){return{tfjsSpeechCommandsVersion:T,modelName:this.name,timeStamp:(new Date).toISOString(),wordLabels:this.wordLabels()}},e.prototype.save=function(t){return o(this,void 0,void 0,function(){var e,n,r;return s(this,function(i){return e=null!=t,t=t||P(this.name),e||(n=R.localStorage.getItem(D),(r=null==n?{}:JSON.parse(n))[this.name]=this.getMetadata(),R.localStorage.setItem(D,JSON.stringify(r))),console.log("Saving model to "+t),[2,this.model.save(t)]})})},e.prototype.load=function(t){return o(this,void 0,void 0,function(){var e,n,i;return s(this,function(a){switch(a.label){case 0:if(e=null!=t,t=t||P(this.name),!e){if(null==(n=JSON.parse(R.localStorage.getItem(D)))||null==n[this.name])throw new Error("Cannot find metadata for transfer model named "+this.name+'"');this.words=n[this.name].wordLabels,console.log("Loaded word list for model named "+this.name+": "+this.words)}return i=this,[4,Object(r.loadLayersModel)(t)];case 1:return i.model=a.sent(),console.log("Loaded model from "+t+":"),this.model.summary(),[2]}})})},e.prototype.createTransfer=function(t){throw new Error("Creating transfer-learned recognizer from a transfer-learned recognizer is not supported.")},e}(F);function P(t){return""+M+t}function L(){return o(this,void 0,void 0,function(){var t,e,n;return s(this,function(i){switch(i.label){case 0:return[4,r.io.listModels()];case 1:for(n in t=i.sent(),e=[],t)n.startsWith(M)&&e.push(n.slice(M.length));return[2,e]}})})}function z(t){return o(this,void 0,void 0,function(){var e;return s(this,function(n){switch(n.label){case 0:return null==(e=JSON.parse(R.localStorage.getItem(D)))&&(e={}),null!=e[t]&&delete e[t],R.localStorage.setItem(D,JSON.stringify(e)),[4,r.io.removeModel(P(t))];case 1:return n.sent(),[2]}})})}function B(t,e,n,i){if(r.util.assert(null==n&&null==i||null!=n&&null!=i,function(){return"customModelURL and customMetadataURL must be both provided or both not provided."}),null!=n&&r.util.assert(null==e,function(){return"vocabulary name must be null or undefined when modelURL is provided."}),"BROWSER_FFT"===t)return new F(e,n,i);throw"SOFT_FFT"===t?new Error("SOFT_FFT SpeechCommandRecognizer has not been implemented yet."):new Error("Invalid fftType: '"+t+"'")}var U={concatenateFloat32Arrays:y,playRawAudio:function(t,e){var n=new(window.AudioContext||window.webkitAudioContext),r=n.createBuffer(1,t.data.length,t.sampleRateHz);r.getChannelData(0).set(t.data);var i=n.createBufferSource();i.buffer=r,i.connect(n.destination),i.start(),i.onended=function(){null!=e&&e()}}}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.load=e.SpeechCommands=void 0;var r=c(n(9)),i=c(n(8)),a=c(n(7)),o=c(n(10)),s=(e.load=function(){var t=(0,i.default)(r.default.mark(function t(e,n){var i;return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return i=new l(e),t.next=3,i.load(n);case 3:return t.abrupt("return",i);case 4:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}(),function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(369))),u=n(144);function c(t){return t&&t.__esModule?t:{default:t}}var l=e.SpeechCommands=function(){function t(e){(0,a.default)(this,t),this.options=e}return(0,o.default)(t,[{key:"load",value:function(){var t=(0,i.default)(r.default.mark(function t(e){var n,i,a;return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e?(n=e.split("/"),i=n.slice(0,n.length-1).join("/"),a=i+"/metadata.json",this.model=s.create("BROWSER_FFT",void 0,e,a)):this.model=s.create("BROWSER_FFT"),t.next=3,this.model.ensureModelLoaded();case 3:this.allLabels=this.model.wordLabels();case 4:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"classify",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.allLabels.length,n=arguments[1];return this.model.listen(function(r){if(r.scores){var i=(0,u.getTopKClassesFromArray)(r.scores,e,t.allLabels).map(function(t){return{label:t.className,confidence:t.probability}});return n(null,i)}return n("ERROR: Cannot find scores in result: "+r)},this.options).catch(function(t){return n("ERROR: "+t.message)})}}]),t}()},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=d(n(14)),i=d(n(9)),a=d(n(8)),o=d(n(7)),s=d(n(10)),u=f(n(4)),c=f(n(370)),l=d(n(15));function f(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}function d(t){return t&&t.__esModule?t:{default:t}}var h=["speechcommands18w"],p=function(){function t(e,n,r){if((0,o.default)(this,t),this.model=null,this.options=n,"string"==typeof e)if(h.includes(e))switch(this.modelName=e,this.modelUrl=null,this.modelName){case"speechcommands18w":this.modelToUse=c;break;default:this.modelToUse=null}else this.modelToUse=c,this.modelUrl=e;this.ready=(0,l.default)(this.loadModel(n,this.modelUrl),r)}return(0,s.default)(t,[{key:"loadModel",value:function(){var t=(0,a.default)(i.default.mark(function t(e){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.modelToUse.load(e,this.modelUrl);case 2:return this.model=t.sent,t.abrupt("return",this);case 4:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"classifyInternal",value:function(){var t=(0,a.default)(i.default.mark(function t(e,n){return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.ready;case 2:return t.next=4,u.nextFrame();case 4:return t.abrupt("return",this.model.classify(e,n));case 5:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"classify",value:function(){var t=(0,a.default)(i.default.mark(function t(){var e,n,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,a=arguments[1];return i.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.topk,n=void 0,"number"==typeof r?e=r:"function"==typeof r&&(n=r),"function"==typeof a&&(n=a),t.abrupt("return",this.classifyInternal(e,n));case 5:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()}]),t}();e.default=function(t,e,n){var i={},a=n,o=t;if("string"!=typeof o)throw new Error('Please specify a model to use. E.g: "SpeechCommands18w"');-1===o.indexOf("http")&&(o=t.toLowerCase()),"object"===(void 0===e?"undefined":(0,r.default)(e))?i=e:"function"==typeof e&&(a=e);var s=new p(o,i,a);return a?s:s.ready}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=["flashlight","belt","mushroom","pond","strawberry","pineapple","sun","cow","ear","bush","pliers","watermelon","apple","baseball","feather","shoe","leaf","lollipop","crown","ocean","horse","mountain","mosquito","mug","hospital","saw","castle","angel","underwear","traffic_light","cruise_ship","marker","blueberry","flamingo","face","hockey_stick","bucket","campfire","asparagus","skateboard","door","suitcase","skull","cloud","paint_can","hockey_puck","steak","house_plant","sleeping_bag","bench","snowman","arm","crayon","fan","shovel","leg","washing_machine","harp","toothbrush","tree","bear","rake","megaphone","knee","guitar","calculator","hurricane","grapes","paintbrush","couch","nose","square","wristwatch","penguin","bridge","octagon","submarine","screwdriver","rollerskates","ladder","wine_bottle","cake","bracelet","broom","yoga","finger","fish","line","truck","snake","bus","stitches","snorkel","shorts","bowtie","pickup_truck","tooth","snail","foot","crab","school_bus","train","dresser","sock","tractor","map","hedgehog","coffee_cup","computer","matches","beard","frog","crocodile","bathtub","rain","moon","bee","knife","boomerang","lighthouse","chandelier","jail","pool","stethoscope","frying_pan","cell_phone","binoculars","purse","lantern","birthday_cake","clarinet","palm_tree","aircraft_carrier","vase","eraser","shark","skyscraper","bicycle","sink","teapot","circle","tornado","bird","stereo","mouth","key","hot_dog","spoon","laptop","cup","bottlecap","The_Great_Wall_of_China","The_Mona_Lisa","smiley_face","waterslide","eyeglasses","ceiling_fan","lobster","moustache","carrot","garden","police_car","postcard","necklace","helmet","blackberry","beach","golf_club","car","panda","alarm_clock","t-shirt","dog","bread","wine_glass","lighter","flower","bandage","drill","butterfly","swan","owl","raccoon","squiggle","calendar","giraffe","elephant","trumpet","rabbit","trombone","sheep","onion","church","flip_flops","spreadsheet","pear","clock","roller_coaster","parachute","kangaroo","duck","remote_control","compass","monkey","rainbow","tennis_racquet","lion","pencil","string_bean","oven","star","cat","pizza","soccer_ball","syringe","flying_saucer","eye","cookie","floor_lamp","mouse","toilet","toaster","The_Eiffel_Tower","airplane","stove","cello","stop_sign","tent","diving_board","light_bulb","hammer","scorpion","headphones","basket","spider","paper_clip","sweater","ice_cream","envelope","sea_turtle","donut","hat","hourglass","broccoli","jacket","backpack","book","lightning","drums","snowflake","radio","banana","camel","canoe","toothpaste","chair","picture_frame","parrot","sandwich","lipstick","pants","violin","brain","power_outlet","triangle","hamburger","dragon","bulldozer","cannon","dolphin","zebra","animal_migration","camouflage","scissors","basketball","elbow","umbrella","windmill","table","rifle","hexagon","potato","anvil","sword","peanut","axe","television","rhinoceros","baseball_bat","speedboat","sailboat","zigzag","garden_hose","river","house","pillow","ant","tiger","stairs","cooler","see_saw","piano","fireplace","popsicle","dumbbell","mailbox","barn","hot_tub","teddy-bear","fork","dishwasher","peas","hot_air_balloon","keyboard","microwave","wheel","fire_hydrant","van","camera","whale","candle","octopus","pig","swing_set","helicopter","saxophone","passport","bat","ambulance","diamond","goatee","fence","grass","mermaid","motorbike","microphone","toe","cactus","nail","telephone","hand","squirrel","streetlight","bed","firetruck"]},function(t,e,n){var r=n(48),i=n(150);t.exports=n(18).getIterator=function(t){var e=i(t);if("function"!=typeof e)throw TypeError(t+" is not iterable!");return r(e.call(t))}},function(t,e,n){n(101),n(85),t.exports=n(373)},function(t,e,n){t.exports={default:n(374),__esModule:!0}},function(t,e,n){var r=n(116),i=n(25)("iterator"),a=n(84);t.exports=n(18).isIterable=function(t){var e=Object(t);return void 0!==e[i]||"@@iterator"in e||a.hasOwnProperty(r(e))}},function(t,e,n){n(101),n(85),t.exports=n(376)},function(t,e,n){t.exports={default:n(377),__esModule:!0}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.load=e.Doodlenet=void 0;var r=d(n(9)),i=d(n(8)),a=d(n(7)),o=d(n(10)),s=d(n(65)),u=d(n(14)),c=(e.load=function(){var t=(0,i.default)(r.default.mark(function t(){var e;return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=new m,t.next=3,e.load();case 3:return t.abrupt("return",e);case 4:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}(),function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(4))),l=n(144),f=d(n(372));function d(t){return t&&t.__esModule?t:{default:t}}var h={DOODLENET_URL:"https://cdn.jsdelivr.net/gh/ml5js/ml5-data-and-models@master/models/doodlenet/model.json",IMAGE_SIZE_DOODLENET:28};function p(t,e){var n=void 0;t instanceof c.Tensor?n=t:t instanceof HTMLImageElement||t instanceof HTMLVideoElement||t instanceof HTMLCanvasElement||t instanceof ImageData?n=c.browser.fromPixels(t):"object"===(void 0===t?"undefined":(0,u.default)(t))&&(t.elt instanceof HTMLImageElement||t.elt instanceof HTMLVideoElement||t.elt instanceof HTMLCanvasElement||t.elt instanceof ImageData)&&(n=c.browser.fromPixels(t.elt));var r=c.scalar(1).sub(n.toFloat().div(c.scalar(255))),i=r;r.shape[0]===e&&r.shape[1]===e||(i=c.image.resizeBilinear(r,[e,e]));var a=c.split(i,3,3),o=(0,s.default)(a,3),l=o[0],f=o[1],d=o[2];return l.add(f).add(d).div(c.scalar(3)).floor().reshape([1,e,e,1])}var m=e.Doodlenet=function(){function t(){(0,a.default)(this,t),this.imgSize=h.IMAGE_SIZE_DOODLENET}return(0,o.default)(t,[{key:"load",value:function(){var t=(0,i.default)(r.default.mark(function t(){var e,n=this;return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,c.loadLayersModel(h.DOODLENET_URL);case 2:return this.model=t.sent,e=c.tidy(function(){return n.model.predict(c.zeros([1,n.imgSize,n.imgSize,1]))}),t.next=6,e.data();case 6:e.dispose();case 7:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"classify",value:function(){var t=(0,i.default)(r.default.mark(function t(e){var n,i,a=this,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10;return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=c.tidy(function(){var t=p(e,a.imgSize);return a.model.predict(t)}),t.next=3,(0,l.getTopKClassesFromTensor)(n,o,f.default);case 3:return i=t.sent,n.dispose(),t.abrupt("return",i);case 6:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()}]),t}()},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=["kit fox","English setter","Siberian husky","Australian terrier","English springer","grey whale","lesser panda","Egyptian cat","ibex","Persian cat","cougar","gazelle","porcupine","sea lion","malamute","badger","Great Dane","Walker hound","Welsh springer spaniel","whippet","Scottish deerhound","killer whale","mink","African elephant","Weimaraner","soft-coated wheaten terrier","Dandie Dinmont","red wolf","Old English sheepdog","jaguar","otterhound","bloodhound","Airedale","hyena","meerkat","giant schnauzer","titi","three-toed sloth","sorrel","black-footed ferret","dalmatian","black-and-tan coonhound","papillon","skunk","Staffordshire bullterrier","Mexican hairless","Bouvier des Flandres","weasel","miniature poodle","Cardigan","malinois","bighorn","fox squirrel","colobus","tiger cat","Lhasa","impala","coyote","Yorkshire terrier","Newfoundland","brown bear","red fox","Norwegian elkhound","Rottweiler","hartebeest","Saluki","grey fox","schipperke","Pekinese","Brabancon griffon","West Highland white terrier","Sealyham terrier","guenon","mongoose","indri","tiger","Irish wolfhound","wild boar","EntleBucher","zebra","ram","French bulldog","orangutan","basenji","leopard","Bernese mountain dog","Maltese dog","Norfolk terrier","toy terrier","vizsla","cairn","squirrel monkey","groenendael","clumber","Siamese cat","chimpanzee","komondor","Afghan hound","Japanese spaniel","proboscis monkey","guinea pig","white wolf","ice bear","gorilla","borzoi","toy poodle","Kerry blue terrier","ox","Scotch terrier","Tibetan mastiff","spider monkey","Doberman","Boston bull","Greater Swiss Mountain dog","Appenzeller","Shih-Tzu","Irish water spaniel","Pomeranian","Bedlington terrier","warthog","Arabian camel","siamang","miniature schnauzer","collie","golden retriever","Irish terrier","affenpinscher","Border collie","hare","boxer","silky terrier","beagle","Leonberg","German short-haired pointer","patas","dhole","baboon","macaque","Chesapeake Bay retriever","bull mastiff","kuvasz","capuchin","pug","curly-coated retriever","Norwich terrier","flat-coated retriever","hog","keeshond","Eskimo dog","Brittany spaniel","standard poodle","Lakeland terrier","snow leopard","Gordon setter","dingo","standard schnauzer","hamster","Tibetan terrier","Arctic fox","wire-haired fox terrier","basset","water buffalo","American black bear","Angora","bison","howler monkey","hippopotamus","chow","giant panda","American Staffordshire terrier","Shetland sheepdog","Great Pyrenees","Chihuahua","tabby","marmoset","Labrador retriever","Saint Bernard","armadillo","Samoyed","bluetick","redbone","polecat","marmot","kelpie","gibbon","llama","miniature pinscher","wood rabbit","Italian greyhound","lion","cocker spaniel","Irish setter","dugong","Indian elephant","beaver","Sussex spaniel","Pembroke","Blenheim spaniel","Madagascar cat","Rhodesian ridgeback","lynx","African hunting dog","langur","Ibizan hound","timber wolf","cheetah","English foxhound","briard","sloth bear","Border terrier","German shepherd","otter","koala","tusker","echidna","wallaby","platypus","wombat","revolver","umbrella","schooner","soccer ball","accordion","ant","starfish","chambered nautilus","grand piano","laptop","strawberry","airliner","warplane","airship","balloon","space shuttle","fireboat","gondola","speedboat","lifeboat","canoe","yawl","catamaran","trimaran","container ship","liner","pirate","aircraft carrier","submarine","wreck","half track","tank","missile","bobsled","dogsled","bicycle-built-for-two","mountain bike","freight car","passenger car","barrow","shopping cart","motor scooter","forklift","electric locomotive","steam locomotive","amphibian","ambulance","beach wagon","cab","convertible","jeep","limousine","minivan","Model T","racer","sports car","go-kart","golfcart","moped","snowplow","fire engine","garbage truck","pickup","tow truck","trailer truck","moving van","police van","recreational vehicle","streetcar","snowmobile","tractor","mobile home","tricycle","unicycle","horse cart","jinrikisha","oxcart","bassinet","cradle","crib","four-poster","bookcase","china cabinet","medicine chest","chiffonier","table lamp","file","park bench","barber chair","throne","folding chair","rocking chair","studio couch","toilet seat","desk","pool table","dining table","entertainment center","wardrobe","Granny Smith","orange","lemon","fig","pineapple","banana","jackfruit","custard apple","pomegranate","acorn","hip","ear","rapeseed","corn","buckeye","organ","upright","chime","drum","gong","maraca","marimba","steel drum","banjo","cello","violin","harp","acoustic guitar","electric guitar","cornet","French horn","trombone","harmonica","ocarina","panpipe","bassoon","oboe","sax","flute","daisy","yellow lady's slipper","cliff","valley","alp","volcano","promontory","sandbar","coral reef","lakeside","seashore","geyser","hatchet","cleaver","letter opener","plane","power drill","lawn mower","hammer","corkscrew","can opener","plunger","screwdriver","shovel","plow","chain saw","cock","hen","ostrich","brambling","goldfinch","house finch","junco","indigo bunting","robin","bulbul","jay","magpie","chickadee","water ouzel","kite","bald eagle","vulture","great grey owl","black grouse","ptarmigan","ruffed grouse","prairie chicken","peacock","quail","partridge","African grey","macaw","sulphur-crested cockatoo","lorikeet","coucal","bee eater","hornbill","hummingbird","jacamar","toucan","drake","red-breasted merganser","goose","black swan","white stork","black stork","spoonbill","flamingo","American egret","little blue heron","bittern","crane","limpkin","American coot","bustard","ruddy turnstone","red-backed sandpiper","redshank","dowitcher","oystercatcher","European gallinule","pelican","king penguin","albatross","great white shark","tiger shark","hammerhead","electric ray","stingray","barracouta","coho","tench","goldfish","eel","rock beauty","anemone fish","lionfish","puffer","sturgeon","gar","loggerhead","leatherback turtle","mud turtle","terrapin","box turtle","banded gecko","common iguana","American chameleon","whiptail","agama","frilled lizard","alligator lizard","Gila monster","green lizard","African chameleon","Komodo dragon","triceratops","African crocodile","American alligator","thunder snake","ringneck snake","hognose snake","green snake","king snake","garter snake","water snake","vine snake","night snake","boa constrictor","rock python","Indian cobra","green mamba","sea snake","horned viper","diamondback","sidewinder","European fire salamander","common newt","eft","spotted salamander","axolotl","bullfrog","tree frog","tailed frog","whistle","wing","paintbrush","hand blower","oxygen mask","snorkel","loudspeaker","microphone","screen","mouse","electric fan","oil filter","strainer","space heater","stove","guillotine","barometer","rule","odometer","scale","analog clock","digital clock","wall clock","hourglass","sundial","parking meter","stopwatch","digital watch","stethoscope","syringe","magnetic compass","binoculars","projector","sunglasses","loupe","radio telescope","bow","cannon","assault rifle","rifle","projectile","computer keyboard","typewriter keyboard","crane","lighter","abacus","cash machine","slide rule","desktop computer","hand-held computer","notebook","web site","harvester","thresher","printer","slot","vending machine","sewing machine","joystick","switch","hook","car wheel","paddlewheel","pinwheel","potter's wheel","gas pump","carousel","swing","reel","radiator","puck","hard disc","sunglass","pick","car mirror","solar dish","remote control","disk brake","buckle","hair slide","knot","combination lock","padlock","nail","safety pin","screw","muzzle","seat belt","ski","candle","jack-o'-lantern","spotlight","torch","neck brace","pier","tripod","maypole","mousetrap","spider web","trilobite","harvestman","scorpion","black and gold garden spider","barn spider","garden spider","black widow","tarantula","wolf spider","tick","centipede","isopod","Dungeness crab","rock crab","fiddler crab","king crab","American lobster","spiny lobster","crayfish","hermit crab","tiger beetle","ladybug","ground beetle","long-horned beetle","leaf beetle","dung beetle","rhinoceros beetle","weevil","fly","bee","grasshopper","cricket","walking stick","cockroach","mantis","cicada","leafhopper","lacewing","dragonfly","damselfly","admiral","ringlet","monarch","cabbage butterfly","sulphur butterfly","lycaenid","jellyfish","sea anemone","brain coral","flatworm","nematode","conch","snail","slug","sea slug","chiton","sea urchin","sea cucumber","iron","espresso maker","microwave","Dutch oven","rotisserie","toaster","waffle iron","vacuum","dishwasher","refrigerator","washer","Crock Pot","frying pan","wok","caldron","coffeepot","teapot","spatula","altar","triumphal arch","patio","steel arch bridge","suspension bridge","viaduct","barn","greenhouse","palace","monastery","library","apiary","boathouse","church","mosque","stupa","planetarium","restaurant","cinema","home theater","lumbermill","coil","obelisk","totem pole","castle","prison","grocery store","bakery","barbershop","bookshop","butcher shop","confectionery","shoe shop","tobacco shop","toyshop","fountain","cliff dwelling","yurt","dock","brass","megalith","bannister","breakwater","dam","chainlink fence","picket fence","worm fence","stone wall","grille","sliding door","turnstile","mountain tent","scoreboard","honeycomb","plate rack","pedestal","beacon","mashed potato","bell pepper","head cabbage","broccoli","cauliflower","zucchini","spaghetti squash","acorn squash","butternut squash","cucumber","artichoke","cardoon","mushroom","shower curtain","jean","carton","handkerchief","sandal","ashcan","safe","plate","necklace","croquet ball","fur coat","thimble","pajama","running shoe","cocktail shaker","chest","manhole cover","modem","tub","tray","balance beam","bagel","prayer rug","kimono","hot pot","whiskey jug","knee pad","book jacket","spindle","ski mask","beer bottle","crash helmet","bottlecap","tile roof","mask","maillot","Petri dish","football helmet","bathing cap","teddy","holster","pop bottle","photocopier","vestment","crossword puzzle","golf ball","trifle","suit","water tower","feather boa","cloak","red wine","drumstick","shield","Christmas stocking","hoopskirt","menu","stage","bonnet","meat loaf","baseball","face powder","scabbard","sunscreen","beer glass","hen-of-the-woods","guacamole","lampshade","wool","hay","bow tie","mailbag","water jug","bucket","dishrag","soup bowl","eggnog","mortar","trench coat","paddle","chain","swab","mixing bowl","potpie","wine bottle","shoji","bulletproof vest","drilling platform","binder","cardigan","sweatshirt","pot","birdhouse","hamper","ping-pong ball","pencil box","pay-phone","consomme","apron","punching bag","backpack","groom","bearskin","pencil sharpener","broom","mosquito net","abaya","mortarboard","poncho","crutch","Polaroid camera","space bar","cup","racket","traffic light","quill","radio","dough","cuirass","military uniform","lipstick","shower cap","monitor","oscilloscope","mitten","brassiere","French loaf","vase","milk can","rugby ball","paper towel","earthstar","envelope","miniskirt","cowboy hat","trolleybus","perfume","bathtub","hotdog","coral fungus","bullet train","pillow","toilet tissue","cassette","carpenter's kit","ladle","stinkhorn","lotion","hair spray","academic gown","dome","crate","wig","burrito","pill bottle","chain mail","theater curtain","window shade","barrel","washbasin","ballpoint","basketball","bath towel","cowboy boot","gown","window screen","agaric","cellular telephone","nipple","barbell","mailbox","lab coat","fire screen","minibus","packet","maze","pole","horizontal bar","sombrero","pickelhaube","rain barrel","wallet","cassette player","comic book","piggy bank","street sign","bell cote","fountain pen","Windsor tie","volleyball","overskirt","sarong","purse","bolo tie","bib","parachute","sleeping bag","television","swimming trunks","measuring cup","espresso","pizza","breastplate","shopping basket","wooden spoon","saltshaker","chocolate sauce","ballplayer","goblet","gyromitra","stretcher","water bottle","dial telephone","soap dispenser","jersey","school bus","jigsaw puzzle","plastic bag","reflex camera","diaper","Band Aid","ice lolly","velvet","tennis ball","gasmask","doormat","Loafer","ice cream","pretzel","quilt","maillot","tape player","clog","iPod","bolete","scuba diver","pitcher","matchstick","bikini","sock","CD player","lens cap","thatch","vault","beaker","bubble","cheeseburger","parallel bars","flagpole","coffee mug","rubber eraser","stole","carbonara","dumbbell"]},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.load=e.Darknet=void 0;var r=f(n(9)),i=f(n(8)),a=f(n(7)),o=f(n(10)),s=f(n(14)),u=(e.load=function(){var t=(0,i.default)(r.default.mark(function t(e){var n;return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if("reference"===e||"tiny"===e){t.next=2;break}throw new Error("Please select a version: darknet-reference or darknet-tiny");case 2:return n=new p(e),t.next=5,n.load();case 5:return t.abrupt("return",n);case 6:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}(),function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(4))),c=n(144),l=f(n(380));function f(t){return t&&t.__esModule?t:{default:t}}var d={DARKNET_URL:"https://cdn.jsdelivr.net/gh/ml5js/ml5-data-and-models@master/models/darknetclassifier/darknetreference/model.json",DARKNET_TINY_URL:"https://cdn.jsdelivr.net/gh/ml5js/ml5-data-and-models@master/models/darknetclassifier/darknettiny/model.json",IMAGE_SIZE_DARKNET:256,IMAGE_SIZE_DARKNET_TINY:224};function h(t,e){var n=void 0;t instanceof u.Tensor?n=t:t instanceof HTMLImageElement||t instanceof HTMLVideoElement||t instanceof HTMLCanvasElement||t instanceof ImageData?n=u.browser.fromPixels(t):"object"===(void 0===t?"undefined":(0,s.default)(t))&&(t.elt instanceof HTMLImageElement||t.elt instanceof HTMLVideoElement||t.elt instanceof HTMLCanvasElement||t.elt instanceof ImageData)&&(n=u.browser.fromPixels(t.elt));var r=n.toFloat().div(u.scalar(255)),i=r;if(r.shape[0]!==e||r.shape[1]!==e){i=u.image.resizeBilinear(r,[e,e],!0)}return i.reshape([1,e,e,3])}var p=e.Darknet=function(){function t(e){switch((0,a.default)(this,t),this.version=e,this.version){case"reference":this.imgSize=d.IMAGE_SIZE_DARKNET;break;case"tiny":this.imgSize=d.IMAGE_SIZE_DARKNET_TINY}}return(0,o.default)(t,[{key:"load",value:function(){var t=(0,i.default)(r.default.mark(function t(){var e,n=this;return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:t.t0=this.version,t.next="reference"===t.t0?3:"tiny"===t.t0?7:11;break;case 3:return t.next=5,u.loadLayersModel(d.DARKNET_URL);case 5:return this.model=t.sent,t.abrupt("break",12);case 7:return t.next=9,u.loadLayersModel(d.DARKNET_TINY_URL);case 9:return this.model=t.sent,t.abrupt("break",12);case 11:return t.abrupt("break",12);case 12:return e=u.tidy(function(){return n.model.predict(u.zeros([1,n.imgSize,n.imgSize,3]))}),t.next=15,e.data();case 15:e.dispose();case 16:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"classify",value:function(){var t=(0,i.default)(r.default.mark(function t(e){var n,i,a=this,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:3;return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=u.tidy(function(){var t=h(e,a.imgSize),n=a.model.predict(t);return u.softmax(n)}),t.next=3,(0,c.getTopKClassesFromTensor)(n,o,l.default);case 3:return i=t.sent,n.dispose(),t.abrupt("return",i);case 6:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()}]),t}()},function(t,e,n){"use strict";n.r(e),n.d(e,"load",function(){return l});var r=n(20),i=n(0);
  355. /**
  356. * @license
  357. * Copyright 2019 Google LLC. All Rights Reserved.
  358. * Licensed under the Apache License, Version 2.0 (the "License");
  359. * you may not use this file except in compliance with the License.
  360. * You may obtain a copy of the License at
  361. *
  362. * http://www.apache.org/licenses/LICENSE-2.0
  363. *
  364. * Unless required by applicable law or agreed to in writing, software
  365. * distributed under the License is distributed on an "AS IS" BASIS,
  366. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  367. * See the License for the specific language governing permissions and
  368. * limitations under the License.
  369. * =============================================================================
  370. */
  371. function a(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})}function o(t,e){var n,r,i,a,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=(i=o.trys).length>0&&i[i.length-1])&&(6===a[0]||2===a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=e.call(t,o)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}var s={0:"tench, Tinca tinca",1:"goldfish, Carassius auratus",2:"great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias",3:"tiger shark, Galeocerdo cuvieri",4:"hammerhead, hammerhead shark",5:"electric ray, crampfish, numbfish, torpedo",6:"stingray",7:"cock",8:"hen",9:"ostrich, Struthio camelus",10:"brambling, Fringilla montifringilla",11:"goldfinch, Carduelis carduelis",12:"house finch, linnet, Carpodacus mexicanus",13:"junco, snowbird",14:"indigo bunting, indigo finch, indigo bird, Passerina cyanea",15:"robin, American robin, Turdus migratorius",16:"bulbul",17:"jay",18:"magpie",19:"chickadee",20:"water ouzel, dipper",21:"kite",22:"bald eagle, American eagle, Haliaeetus leucocephalus",23:"vulture",24:"great grey owl, great gray owl, Strix nebulosa",25:"European fire salamander, Salamandra salamandra",26:"common newt, Triturus vulgaris",27:"eft",28:"spotted salamander, Ambystoma maculatum",29:"axolotl, mud puppy, Ambystoma mexicanum",30:"bullfrog, Rana catesbeiana",31:"tree frog, tree-frog",32:"tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui",33:"loggerhead, loggerhead turtle, Caretta caretta",34:"leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea",35:"mud turtle",36:"terrapin",37:"box turtle, box tortoise",38:"banded gecko",39:"common iguana, iguana, Iguana iguana",40:"American chameleon, anole, Anolis carolinensis",41:"whiptail, whiptail lizard",42:"agama",43:"frilled lizard, Chlamydosaurus kingi",44:"alligator lizard",45:"Gila monster, Heloderma suspectum",46:"green lizard, Lacerta viridis",47:"African chameleon, Chamaeleo chamaeleon",48:"Komodo dragon, Komodo lizard, dragon lizard, giant lizard, Varanus komodoensis",49:"African crocodile, Nile crocodile, Crocodylus niloticus",50:"American alligator, Alligator mississipiensis",51:"triceratops",52:"thunder snake, worm snake, Carphophis amoenus",53:"ringneck snake, ring-necked snake, ring snake",54:"hognose snake, puff adder, sand viper",55:"green snake, grass snake",56:"king snake, kingsnake",57:"garter snake, grass snake",58:"water snake",59:"vine snake",60:"night snake, Hypsiglena torquata",61:"boa constrictor, Constrictor constrictor",62:"rock python, rock snake, Python sebae",63:"Indian cobra, Naja naja",64:"green mamba",65:"sea snake",66:"horned viper, cerastes, sand viper, horned asp, Cerastes cornutus",67:"diamondback, diamondback rattlesnake, Crotalus adamanteus",68:"sidewinder, horned rattlesnake, Crotalus cerastes",69:"trilobite",70:"harvestman, daddy longlegs, Phalangium opilio",71:"scorpion",72:"black and gold garden spider, Argiope aurantia",73:"barn spider, Araneus cavaticus",74:"garden spider, Aranea diademata",75:"black widow, Latrodectus mactans",76:"tarantula",77:"wolf spider, hunting spider",78:"tick",79:"centipede",80:"black grouse",81:"ptarmigan",82:"ruffed grouse, partridge, Bonasa umbellus",83:"prairie chicken, prairie grouse, prairie fowl",84:"peacock",85:"quail",86:"partridge",87:"African grey, African gray, Psittacus erithacus",88:"macaw",89:"sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita",90:"lorikeet",91:"coucal",92:"bee eater",93:"hornbill",94:"hummingbird",95:"jacamar",96:"toucan",97:"drake",98:"red-breasted merganser, Mergus serrator",99:"goose",100:"black swan, Cygnus atratus",101:"tusker",102:"echidna, spiny anteater, anteater",103:"platypus, duckbill, duckbilled platypus, duck-billed platypus, Ornithorhynchus anatinus",104:"wallaby, brush kangaroo",105:"koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus",106:"wombat",107:"jelly fish",108:"sea anemone, anemone",109:"brain coral",110:"flatworm, platyhelminth",111:"nematode, nematode worm, roundworm",112:"conch",113:"snail",114:"slug",115:"sea slug, nudibranch",116:"chiton, coat-of-mail shell, sea cradle, polyplacophore",117:"chambered nautilus, pearly nautilus, nautilus",118:"Dungeness crab, Cancer magister",119:"rock crab, Cancer irroratus",120:"fiddler crab",121:"king crab, Alaska crab, Alaskan king crab, Alaska king crab, Paralithodes camtschatica",122:"American lobster, Northern lobster, Maine lobster, Homarus americanus",123:"spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish",124:"crayfish, crawfish, crawdad, crawdaddy",125:"hermit crab",126:"isopod",127:"white stork, Ciconia ciconia",128:"black stork, Ciconia nigra",129:"spoonbill",130:"flamingo",131:"little blue heron, Egretta caerulea",132:"American egret, great white heron, Egretta albus",133:"bittern",134:"crane",135:"limpkin, Aramus pictus",136:"European gallinule, Porphyrio porphyrio",137:"American coot, marsh hen, mud hen, water hen, Fulica americana",138:"bustard",139:"ruddy turnstone, Arenaria interpres",140:"red-backed sandpiper, dunlin, Erolia alpina",141:"redshank, Tringa totanus",142:"dowitcher",143:"oystercatcher, oyster catcher",144:"pelican",145:"king penguin, Aptenodytes patagonica",146:"albatross, mollymawk",147:"grey whale, gray whale, devilfish, Eschrichtius gibbosus, Eschrichtius robustus",148:"killer whale, killer, orca, grampus, sea wolf, Orcinus orca",149:"dugong, Dugong dugon",150:"sea lion",151:"Chihuahua",152:"Japanese spaniel",153:"Maltese dog, Maltese terrier, Maltese",154:"Pekinese, Pekingese, Peke",155:"Shih-Tzu",156:"Blenheim spaniel",157:"papillon",158:"toy terrier",159:"Rhodesian ridgeback",160:"Afghan hound, Afghan",161:"basset, basset hound",162:"beagle",163:"bloodhound, sleuthhound",164:"bluetick",165:"black-and-tan coonhound",166:"Walker hound, Walker foxhound",167:"English foxhound",168:"redbone",169:"borzoi, Russian wolfhound",170:"Irish wolfhound",171:"Italian greyhound",172:"whippet",173:"Ibizan hound, Ibizan Podenco",174:"Norwegian elkhound, elkhound",175:"otterhound, otter hound",176:"Saluki, gazelle hound",177:"Scottish deerhound, deerhound",178:"Weimaraner",179:"Staffordshire bullterrier, Staffordshire bull terrier",180:"American Staffordshire terrier, Staffordshire terrier, American pit bull terrier, pit bull terrier",181:"Bedlington terrier",182:"Border terrier",183:"Kerry blue terrier",184:"Irish terrier",185:"Norfolk terrier",186:"Norwich terrier",187:"Yorkshire terrier",188:"wire-haired fox terrier",189:"Lakeland terrier",190:"Sealyham terrier, Sealyham",191:"Airedale, Airedale terrier",192:"cairn, cairn terrier",193:"Australian terrier",194:"Dandie Dinmont, Dandie Dinmont terrier",195:"Boston bull, Boston terrier",196:"miniature schnauzer",197:"giant schnauzer",198:"standard schnauzer",199:"Scotch terrier, Scottish terrier, Scottie",200:"Tibetan terrier, chrysanthemum dog",201:"silky terrier, Sydney silky",202:"soft-coated wheaten terrier",203:"West Highland white terrier",204:"Lhasa, Lhasa apso",205:"flat-coated retriever",206:"curly-coated retriever",207:"golden retriever",208:"Labrador retriever",209:"Chesapeake Bay retriever",210:"German short-haired pointer",211:"vizsla, Hungarian pointer",212:"English setter",213:"Irish setter, red setter",214:"Gordon setter",215:"Brittany spaniel",216:"clumber, clumber spaniel",217:"English springer, English springer spaniel",218:"Welsh springer spaniel",219:"cocker spaniel, English cocker spaniel, cocker",220:"Sussex spaniel",221:"Irish water spaniel",222:"kuvasz",223:"schipperke",224:"groenendael",225:"malinois",226:"briard",227:"kelpie",228:"komondor",229:"Old English sheepdog, bobtail",230:"Shetland sheepdog, Shetland sheep dog, Shetland",231:"collie",232:"Border collie",233:"Bouvier des Flandres, Bouviers des Flandres",234:"Rottweiler",235:"German shepherd, German shepherd dog, German police dog, alsatian",236:"Doberman, Doberman pinscher",237:"miniature pinscher",238:"Greater Swiss Mountain dog",239:"Bernese mountain dog",240:"Appenzeller",241:"EntleBucher",242:"boxer",243:"bull mastiff",244:"Tibetan mastiff",245:"French bulldog",246:"Great Dane",247:"Saint Bernard, St Bernard",248:"Eskimo dog, husky",249:"malamute, malemute, Alaskan malamute",250:"Siberian husky",251:"dalmatian, coach dog, carriage dog",252:"affenpinscher, monkey pinscher, monkey dog",253:"basenji",254:"pug, pug-dog",255:"Leonberg",256:"Newfoundland, Newfoundland dog",257:"Great Pyrenees",258:"Samoyed, Samoyede",259:"Pomeranian",260:"chow, chow chow",261:"keeshond",262:"Brabancon griffon",263:"Pembroke, Pembroke Welsh corgi",264:"Cardigan, Cardigan Welsh corgi",265:"toy poodle",266:"miniature poodle",267:"standard poodle",268:"Mexican hairless",269:"timber wolf, grey wolf, gray wolf, Canis lupus",270:"white wolf, Arctic wolf, Canis lupus tundrarum",271:"red wolf, maned wolf, Canis rufus, Canis niger",272:"coyote, prairie wolf, brush wolf, Canis latrans",273:"dingo, warrigal, warragal, Canis dingo",274:"dhole, Cuon alpinus",275:"African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus",276:"hyena, hyaena",277:"red fox, Vulpes vulpes",278:"kit fox, Vulpes macrotis",279:"Arctic fox, white fox, Alopex lagopus",280:"grey fox, gray fox, Urocyon cinereoargenteus",281:"tabby, tabby cat",282:"tiger cat",283:"Persian cat",284:"Siamese cat, Siamese",285:"Egyptian cat",286:"cougar, puma, catamount, mountain lion, painter, panther, Felis concolor",287:"lynx, catamount",288:"leopard, Panthera pardus",289:"snow leopard, ounce, Panthera uncia",290:"jaguar, panther, Panthera onca, Felis onca",291:"lion, king of beasts, Panthera leo",292:"tiger, Panthera tigris",293:"cheetah, chetah, Acinonyx jubatus",294:"brown bear, bruin, Ursus arctos",295:"American black bear, black bear, Ursus americanus, Euarctos americanus",296:"ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus",297:"sloth bear, Melursus ursinus, Ursus ursinus",298:"mongoose",299:"meerkat, mierkat",300:"tiger beetle",301:"ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle",302:"ground beetle, carabid beetle",303:"long-horned beetle, longicorn, longicorn beetle",304:"leaf beetle, chrysomelid",305:"dung beetle",306:"rhinoceros beetle",307:"weevil",308:"fly",309:"bee",310:"ant, emmet, pismire",311:"grasshopper, hopper",312:"cricket",313:"walking stick, walkingstick, stick insect",314:"cockroach, roach",315:"mantis, mantid",316:"cicada, cicala",317:"leafhopper",318:"lacewing, lacewing fly",319:"dragonfly, darning needle, devil's darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk",320:"damselfly",321:"admiral",322:"ringlet, ringlet butterfly",323:"monarch, monarch butterfly, milkweed butterfly, Danaus plexippus",324:"cabbage butterfly",325:"sulphur butterfly, sulfur butterfly",326:"lycaenid, lycaenid butterfly",327:"starfish, sea star",328:"sea urchin",329:"sea cucumber, holothurian",330:"wood rabbit, cottontail, cottontail rabbit",331:"hare",332:"Angora, Angora rabbit",333:"hamster",334:"porcupine, hedgehog",335:"fox squirrel, eastern fox squirrel, Sciurus niger",336:"marmot",337:"beaver",338:"guinea pig, Cavia cobaya",339:"sorrel",340:"zebra",341:"hog, pig, grunter, squealer, Sus scrofa",342:"wild boar, boar, Sus scrofa",343:"warthog",344:"hippopotamus, hippo, river horse, Hippopotamus amphibius",345:"ox",346:"water buffalo, water ox, Asiatic buffalo, Bubalus bubalis",347:"bison",348:"ram, tup",349:"bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky Mountain sheep, Ovis canadensis",350:"ibex, Capra ibex",351:"hartebeest",352:"impala, Aepyceros melampus",353:"gazelle",354:"Arabian camel, dromedary, Camelus dromedarius",355:"llama",356:"weasel",357:"mink",358:"polecat, fitch, foulmart, foumart, Mustela putorius",359:"black-footed ferret, ferret, Mustela nigripes",360:"otter",361:"skunk, polecat, wood pussy",362:"badger",363:"armadillo",364:"three-toed sloth, ai, Bradypus tridactylus",365:"orangutan, orang, orangutang, Pongo pygmaeus",366:"gorilla, Gorilla gorilla",367:"chimpanzee, chimp, Pan troglodytes",368:"gibbon, Hylobates lar",369:"siamang, Hylobates syndactylus, Symphalangus syndactylus",370:"guenon, guenon monkey",371:"patas, hussar monkey, Erythrocebus patas",372:"baboon",373:"macaque",374:"langur",375:"colobus, colobus monkey",376:"proboscis monkey, Nasalis larvatus",377:"marmoset",378:"capuchin, ringtail, Cebus capucinus",379:"howler monkey, howler",380:"titi, titi monkey",381:"spider monkey, Ateles geoffroyi",382:"squirrel monkey, Saimiri sciureus",383:"Madagascar cat, ring-tailed lemur, Lemur catta",384:"indri, indris, Indri indri, Indri brevicaudatus",385:"Indian elephant, Elephas maximus",386:"African elephant, Loxodonta africana",387:"lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens",388:"giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca",389:"barracouta, snoek",390:"eel",391:"coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus kisutch",392:"rock beauty, Holocanthus tricolor",393:"anemone fish",394:"sturgeon",395:"gar, garfish, garpike, billfish, Lepisosteus osseus",396:"lionfish",397:"puffer, pufferfish, blowfish, globefish",398:"abacus",399:"abaya",400:"academic gown, academic robe, judge's robe",401:"accordion, piano accordion, squeeze box",402:"acoustic guitar",403:"aircraft carrier, carrier, flattop, attack aircraft carrier",404:"airliner",405:"airship, dirigible",406:"altar",407:"ambulance",408:"amphibian, amphibious vehicle",409:"analog clock",410:"apiary, bee house",411:"apron",412:"ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, dustbin, trash barrel, trash bin",413:"assault rifle, assault gun",414:"backpack, back pack, knapsack, packsack, rucksack, haversack",415:"bakery, bakeshop, bakehouse",416:"balance beam, beam",417:"balloon",418:"ballpoint, ballpoint pen, ballpen, Biro",419:"Band Aid",420:"banjo",421:"bannister, banister, balustrade, balusters, handrail",422:"barbell",423:"barber chair",424:"barbershop",425:"barn",426:"barometer",427:"barrel, cask",428:"barrow, garden cart, lawn cart, wheelbarrow",429:"baseball",430:"basketball",431:"bassinet",432:"bassoon",433:"bathing cap, swimming cap",434:"bath towel",435:"bathtub, bathing tub, bath, tub",436:"beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon",437:"beacon, lighthouse, beacon light, pharos",438:"beaker",439:"bearskin, busby, shako",440:"beer bottle",441:"beer glass",442:"bell cote, bell cot",443:"bib",444:"bicycle-built-for-two, tandem bicycle, tandem",445:"bikini, two-piece",446:"binder, ring-binder",447:"binoculars, field glasses, opera glasses",448:"birdhouse",449:"boathouse",450:"bobsled, bobsleigh, bob",451:"bolo tie, bolo, bola tie, bola",452:"bonnet, poke bonnet",453:"bookcase",454:"bookshop, bookstore, bookstall",455:"bottlecap",456:"bow",457:"bow tie, bow-tie, bowtie",458:"brass, memorial tablet, plaque",459:"brassiere, bra, bandeau",460:"breakwater, groin, groyne, mole, bulwark, seawall, jetty",461:"breastplate, aegis, egis",462:"broom",463:"bucket, pail",464:"buckle",465:"bulletproof vest",466:"bullet train, bullet",467:"butcher shop, meat market",468:"cab, hack, taxi, taxicab",469:"caldron, cauldron",470:"candle, taper, wax light",471:"cannon",472:"canoe",473:"can opener, tin opener",474:"cardigan",475:"car mirror",476:"carousel, carrousel, merry-go-round, roundabout, whirligig",477:"carpenter's kit, tool kit",478:"carton",479:"car wheel",480:"cash machine, cash dispenser, automated teller machine, automatic teller machine, automated teller, automatic teller, ATM",481:"cassette",482:"cassette player",483:"castle",484:"catamaran",485:"CD player",486:"cello, violoncello",487:"cellular telephone, cellular phone, cellphone, cell, mobile phone",488:"chain",489:"chainlink fence",490:"chain mail, ring mail, mail, chain armor, chain armour, ring armor, ring armour",491:"chain saw, chainsaw",492:"chest",493:"chiffonier, commode",494:"chime, bell, gong",495:"china cabinet, china closet",496:"Christmas stocking",497:"church, church building",498:"cinema, movie theater, movie theatre, movie house, picture palace",499:"cleaver, meat cleaver, chopper",500:"cliff dwelling",501:"cloak",502:"clog, geta, patten, sabot",503:"cocktail shaker",504:"coffee mug",505:"coffeepot",506:"coil, spiral, volute, whorl, helix",507:"combination lock",508:"computer keyboard, keypad",509:"confectionery, confectionary, candy store",510:"container ship, containership, container vessel",511:"convertible",512:"corkscrew, bottle screw",513:"cornet, horn, trumpet, trump",514:"cowboy boot",515:"cowboy hat, ten-gallon hat",516:"cradle",517:"crane",518:"crash helmet",519:"crate",520:"crib, cot",521:"Crock Pot",522:"croquet ball",523:"crutch",524:"cuirass",525:"dam, dike, dyke",526:"desk",527:"desktop computer",528:"dial telephone, dial phone",529:"diaper, nappy, napkin",530:"digital clock",531:"digital watch",532:"dining table, board",533:"dishrag, dishcloth",534:"dishwasher, dish washer, dishwashing machine",535:"disk brake, disc brake",536:"dock, dockage, docking facility",537:"dogsled, dog sled, dog sleigh",538:"dome",539:"doormat, welcome mat",540:"drilling platform, offshore rig",541:"drum, membranophone, tympan",542:"drumstick",543:"dumbbell",544:"Dutch oven",545:"electric fan, blower",546:"electric guitar",547:"electric locomotive",548:"entertainment center",549:"envelope",550:"espresso maker",551:"face powder",552:"feather boa, boa",553:"file, file cabinet, filing cabinet",554:"fireboat",555:"fire engine, fire truck",556:"fire screen, fireguard",557:"flagpole, flagstaff",558:"flute, transverse flute",559:"folding chair",560:"football helmet",561:"forklift",562:"fountain",563:"fountain pen",564:"four-poster",565:"freight car",566:"French horn, horn",567:"frying pan, frypan, skillet",568:"fur coat",569:"garbage truck, dustcart",570:"gasmask, respirator, gas helmet",571:"gas pump, gasoline pump, petrol pump, island dispenser",572:"goblet",573:"go-kart",574:"golf ball",575:"golfcart, golf cart",576:"gondola",577:"gong, tam-tam",578:"gown",579:"grand piano, grand",580:"greenhouse, nursery, glasshouse",581:"grille, radiator grille",582:"grocery store, grocery, food market, market",583:"guillotine",584:"hair slide",585:"hair spray",586:"half track",587:"hammer",588:"hamper",589:"hand blower, blow dryer, blow drier, hair dryer, hair drier",590:"hand-held computer, hand-held microcomputer",591:"handkerchief, hankie, hanky, hankey",592:"hard disc, hard disk, fixed disk",593:"harmonica, mouth organ, harp, mouth harp",594:"harp",595:"harvester, reaper",596:"hatchet",597:"holster",598:"home theater, home theatre",599:"honeycomb",600:"hook, claw",601:"hoopskirt, crinoline",602:"horizontal bar, high bar",603:"horse cart, horse-cart",604:"hourglass",605:"iPod",606:"iron, smoothing iron",607:"jack-o'-lantern",608:"jean, blue jean, denim",609:"jeep, landrover",610:"jersey, T-shirt, tee shirt",611:"jigsaw puzzle",612:"jinrikisha, ricksha, rickshaw",613:"joystick",614:"kimono",615:"knee pad",616:"knot",617:"lab coat, laboratory coat",618:"ladle",619:"lampshade, lamp shade",620:"laptop, laptop computer",621:"lawn mower, mower",622:"lens cap, lens cover",623:"letter opener, paper knife, paperknife",624:"library",625:"lifeboat",626:"lighter, light, igniter, ignitor",627:"limousine, limo",628:"liner, ocean liner",629:"lipstick, lip rouge",630:"Loafer",631:"lotion",632:"loudspeaker, speaker, speaker unit, loudspeaker system, speaker system",633:"loupe, jeweler's loupe",634:"lumbermill, sawmill",635:"magnetic compass",636:"mailbag, postbag",637:"mailbox, letter box",638:"maillot",639:"maillot, tank suit",640:"manhole cover",641:"maraca",642:"marimba, xylophone",643:"mask",644:"matchstick",645:"maypole",646:"maze, labyrinth",647:"measuring cup",648:"medicine chest, medicine cabinet",649:"megalith, megalithic structure",650:"microphone, mike",651:"microwave, microwave oven",652:"military uniform",653:"milk can",654:"minibus",655:"miniskirt, mini",656:"minivan",657:"missile",658:"mitten",659:"mixing bowl",660:"mobile home, manufactured home",661:"Model T",662:"modem",663:"monastery",664:"monitor",665:"moped",666:"mortar",667:"mortarboard",668:"mosque",669:"mosquito net",670:"motor scooter, scooter",671:"mountain bike, all-terrain bike, off-roader",672:"mountain tent",673:"mouse, computer mouse",674:"mousetrap",675:"moving van",676:"muzzle",677:"nail",678:"neck brace",679:"necklace",680:"nipple",681:"notebook, notebook computer",682:"obelisk",683:"oboe, hautboy, hautbois",684:"ocarina, sweet potato",685:"odometer, hodometer, mileometer, milometer",686:"oil filter",687:"organ, pipe organ",688:"oscilloscope, scope, cathode-ray oscilloscope, CRO",689:"overskirt",690:"oxcart",691:"oxygen mask",692:"packet",693:"paddle, boat paddle",694:"paddlewheel, paddle wheel",695:"padlock",696:"paintbrush",697:"pajama, pyjama, pj's, jammies",698:"palace",699:"panpipe, pandean pipe, syrinx",700:"paper towel",701:"parachute, chute",702:"parallel bars, bars",703:"park bench",704:"parking meter",705:"passenger car, coach, carriage",706:"patio, terrace",707:"pay-phone, pay-station",708:"pedestal, plinth, footstall",709:"pencil box, pencil case",710:"pencil sharpener",711:"perfume, essence",712:"Petri dish",713:"photocopier",714:"pick, plectrum, plectron",715:"pickelhaube",716:"picket fence, paling",717:"pickup, pickup truck",718:"pier",719:"piggy bank, penny bank",720:"pill bottle",721:"pillow",722:"ping-pong ball",723:"pinwheel",724:"pirate, pirate ship",725:"pitcher, ewer",726:"plane, carpenter's plane, woodworking plane",727:"planetarium",728:"plastic bag",729:"plate rack",730:"plow, plough",731:"plunger, plumber's helper",732:"Polaroid camera, Polaroid Land camera",733:"pole",734:"police van, police wagon, paddy wagon, patrol wagon, wagon, black Maria",735:"poncho",736:"pool table, billiard table, snooker table",737:"pop bottle, soda bottle",738:"pot, flowerpot",739:"potter's wheel",740:"power drill",741:"prayer rug, prayer mat",742:"printer",743:"prison, prison house",744:"projectile, missile",745:"projector",746:"puck, hockey puck",747:"punching bag, punch bag, punching ball, punchball",748:"purse",749:"quill, quill pen",750:"quilt, comforter, comfort, puff",751:"racer, race car, racing car",752:"racket, racquet",753:"radiator",754:"radio, wireless",755:"radio telescope, radio reflector",756:"rain barrel",757:"recreational vehicle, RV, R.V.",758:"reel",759:"reflex camera",760:"refrigerator, icebox",761:"remote control, remote",762:"restaurant, eating house, eating place, eatery",763:"revolver, six-gun, six-shooter",764:"rifle",765:"rocking chair, rocker",766:"rotisserie",767:"rubber eraser, rubber, pencil eraser",768:"rugby ball",769:"rule, ruler",770:"running shoe",771:"safe",772:"safety pin",773:"saltshaker, salt shaker",774:"sandal",775:"sarong",776:"sax, saxophone",777:"scabbard",778:"scale, weighing machine",779:"school bus",780:"schooner",781:"scoreboard",782:"screen, CRT screen",783:"screw",784:"screwdriver",785:"seat belt, seatbelt",786:"sewing machine",787:"shield, buckler",788:"shoe shop, shoe-shop, shoe store",789:"shoji",790:"shopping basket",791:"shopping cart",792:"shovel",793:"shower cap",794:"shower curtain",795:"ski",796:"ski mask",797:"sleeping bag",798:"slide rule, slipstick",799:"sliding door",800:"slot, one-armed bandit",801:"snorkel",802:"snowmobile",803:"snowplow, snowplough",804:"soap dispenser",805:"soccer ball",806:"sock",807:"solar dish, solar collector, solar furnace",808:"sombrero",809:"soup bowl",810:"space bar",811:"space heater",812:"space shuttle",813:"spatula",814:"speedboat",815:"spider web, spider's web",816:"spindle",817:"sports car, sport car",818:"spotlight, spot",819:"stage",820:"steam locomotive",821:"steel arch bridge",822:"steel drum",823:"stethoscope",824:"stole",825:"stone wall",826:"stopwatch, stop watch",827:"stove",828:"strainer",829:"streetcar, tram, tramcar, trolley, trolley car",830:"stretcher",831:"studio couch, day bed",832:"stupa, tope",833:"submarine, pigboat, sub, U-boat",834:"suit, suit of clothes",835:"sundial",836:"sunglass",837:"sunglasses, dark glasses, shades",838:"sunscreen, sunblock, sun blocker",839:"suspension bridge",840:"swab, swob, mop",841:"sweatshirt",842:"swimming trunks, bathing trunks",843:"swing",844:"switch, electric switch, electrical switch",845:"syringe",846:"table lamp",847:"tank, army tank, armored combat vehicle, armoured combat vehicle",848:"tape player",849:"teapot",850:"teddy, teddy bear",851:"television, television system",852:"tennis ball",853:"thatch, thatched roof",854:"theater curtain, theatre curtain",855:"thimble",856:"thresher, thrasher, threshing machine",857:"throne",858:"tile roof",859:"toaster",860:"tobacco shop, tobacconist shop, tobacconist",861:"toilet seat",862:"torch",863:"totem pole",864:"tow truck, tow car, wrecker",865:"toyshop",866:"tractor",867:"trailer truck, tractor trailer, trucking rig, rig, articulated lorry, semi",868:"tray",869:"trench coat",870:"tricycle, trike, velocipede",871:"trimaran",872:"tripod",873:"triumphal arch",874:"trolleybus, trolley coach, trackless trolley",875:"trombone",876:"tub, vat",877:"turnstile",878:"typewriter keyboard",879:"umbrella",880:"unicycle, monocycle",881:"upright, upright piano",882:"vacuum, vacuum cleaner",883:"vase",884:"vault",885:"velvet",886:"vending machine",887:"vestment",888:"viaduct",889:"violin, fiddle",890:"volleyball",891:"waffle iron",892:"wall clock",893:"wallet, billfold, notecase, pocketbook",894:"wardrobe, closet, press",895:"warplane, military plane",896:"washbasin, handbasin, washbowl, lavabo, wash-hand basin",897:"washer, automatic washer, washing machine",898:"water bottle",899:"water jug",900:"water tower",901:"whiskey jug",902:"whistle",903:"wig",904:"window screen",905:"window shade",906:"Windsor tie",907:"wine bottle",908:"wing",909:"wok",910:"wooden spoon",911:"wool, woolen, woollen",912:"worm fence, snake fence, snake-rail fence, Virginia fence",913:"wreck",914:"yawl",915:"yurt",916:"web site, website, internet site, site",917:"comic book",918:"crossword puzzle, crossword",919:"street sign",920:"traffic light, traffic signal, stoplight",921:"book jacket, dust cover, dust jacket, dust wrapper",922:"menu",923:"plate",924:"guacamole",925:"consomme",926:"hot pot, hotpot",927:"trifle",928:"ice cream, icecream",929:"ice lolly, lolly, lollipop, popsicle",930:"French loaf",931:"bagel, beigel",932:"pretzel",933:"cheeseburger",934:"hotdog, hot dog, red hot",935:"mashed potato",936:"head cabbage",937:"broccoli",938:"cauliflower",939:"zucchini, courgette",940:"spaghetti squash",941:"acorn squash",942:"butternut squash",943:"cucumber, cuke",944:"artichoke, globe artichoke",945:"bell pepper",946:"cardoon",947:"mushroom",948:"Granny Smith",949:"strawberry",950:"orange",951:"lemon",952:"fig",953:"pineapple, ananas",954:"banana",955:"jackfruit, jak, jack",956:"custard apple",957:"pomegranate",958:"hay",959:"carbonara",960:"chocolate sauce, chocolate syrup",961:"dough",962:"meat loaf, meatloaf",963:"pizza, pizza pie",964:"potpie",965:"burrito",966:"red wine",967:"espresso",968:"cup",969:"eggnog",970:"alp",971:"bubble",972:"cliff, drop, drop-off",973:"coral reef",974:"geyser",975:"lakeside, lakeshore",976:"promontory, headland, head, foreland",977:"sandbar, sand bar",978:"seashore, coast, seacoast, sea-coast",979:"valley, vale",980:"volcano",981:"ballplayer, baseball player",982:"groom, bridegroom",983:"scuba diver",984:"rapeseed",985:"daisy",986:"yellow lady's slipper, yellow lady-slipper, Cypripedium calceolus, Cypripedium parviflorum",987:"corn",988:"acorn",989:"hip, rose hip, rosehip",990:"buckeye, horse chestnut, conker",991:"coral fungus",992:"agaric",993:"gyromitra",994:"stinkhorn, carrion fungus",995:"earthstar",996:"hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola frondosa",997:"bolete",998:"ear, spike, capitulum",999:"toilet tissue, toilet paper, bathroom tissue"},u={"1.00":"module_apply_default/MobilenetV1/Logits/global_pool","2.00":"module_apply_default/MobilenetV2/Logits/AvgPool"},c={"1.00":{.25:{url:"https://tfhub.dev/google/imagenet/mobilenet_v1_025_224/classification/1",inputRange:[0,1]},"0.50":{url:"https://tfhub.dev/google/imagenet/mobilenet_v1_050_224/classification/1",inputRange:[0,1]},.75:{url:"https://tfhub.dev/google/imagenet/mobilenet_v1_075_224/classification/1",inputRange:[0,1]},"1.00":{url:"https://tfhub.dev/google/imagenet/mobilenet_v1_100_224/classification/1",inputRange:[0,1]}},"2.00":{"0.50":{url:"https://tfhub.dev/google/imagenet/mobilenet_v2_050_224/classification/2",inputRange:[0,1]},.75:{url:"https://tfhub.dev/google/imagenet/mobilenet_v2_075_224/classification/2",inputRange:[0,1]},"1.00":{url:"https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/classification/2",inputRange:[0,1]}}};function l(t){return void 0===t&&(t={version:1,alpha:1}),a(this,void 0,void 0,function(){var e,n,r,a,s,u;return o(this,function(o){switch(o.label){case 0:if(null==i)throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please also include @tensorflow/tfjs on the page before using this model.");if(n=t.version.toFixed(2),r=t.alpha?t.alpha.toFixed(2):"",a=-1,s=1,null==t.modelUrl){if(!(n in c))throw new Error("Invalid version of MobileNet. Valid versions are: "+Object.keys(c));if(!(r in c[n]))throw new Error("MobileNet constructed with invalid alpha "+t.alpha+". Valid multipliers for this version are: "+Object.keys(c[n])+".");e=c[n][r].inputRange,a=e[0],s=e[1]}return[4,(u=new f(n,r,t.modelUrl,a,s)).load()];case 1:return o.sent(),[2,u]}})})}var f=function(){function t(t,e,n,r,i){void 0===r&&(r=-1),void 0===i&&(i=1),this.version=t,this.alpha=e,this.modelUrl=n,this.inputMin=r,this.inputMax=i,this.inputRange=i-r}return t.prototype.load=function(){return a(this,void 0,void 0,function(){var t,e,n,a,s=this;return o(this,function(o){switch(o.label){case 0:return this.modelUrl?(t=this,[4,Object(r.c)(this.modelUrl)]):[3,2];case 1:return t.model=o.sent(),[3,4];case 2:return e=c[this.version][this.alpha].url,n=this,[4,Object(r.c)(e,{fromTFHub:!0})];case 3:n.model=o.sent(),o.label=4;case 4:return[4,(a=Object(i.tidy)(function(){return s.model.predict(Object(i.zeros)([1,224,224,3]))})).data()];case 5:return o.sent(),a.dispose(),[2]}})})},t.prototype.infer=function(t,e){var n=this;return void 0===e&&(e=!1),Object(i.tidy)(function(){t instanceof i.Tensor||(t=i.browser.fromPixels(t));var r=t.toFloat().mul(n.inputRange).add(n.inputMin),a=r;224===t.shape[0]&&224===t.shape[1]||(a=i.image.resizeBilinear(r,[224,224],!0));var o,s=a.reshape([-1,224,224,3]);if(e){var c=u[n.version];o=n.model.execute(s,c).squeeze([1,2])}else o=n.model.predict(s).slice([0,1],[-1,1e3]);return o})},t.prototype.classify=function(t,e){return void 0===e&&(e=3),a(this,void 0,void 0,function(){var n,r;return o(this,function(i){switch(i.label){case 0:return[4,function(t,e){return a(this,void 0,void 0,function(){var n,r,i,a,u,c,l;return o(this,function(o){switch(o.label){case 0:return[4,(n=t.softmax()).data()];case 1:for(r=o.sent(),n.dispose(),i=[],l=0;l<r.length;l++)i.push({value:r[l],index:l});for(i.sort(function(t,e){return e.value-t.value}),a=new Float32Array(e),u=new Int32Array(e),l=0;l<e;l++)a[l]=i[l].value,u[l]=i[l].index;for(c=[],l=0;l<u.length;l++)c.push({className:s[u[l]],probability:a[l]});return[2,c]}})})}(n=this.infer(t),e)];case 1:return r=i.sent(),n.dispose(),[2,r]}})})},t}()},function(t,e,n){"use strict";t.exports=function(t){return function(e){return t.apply(null,e)}}},function(t,e,n){"use strict";var r=n(211);function i(t){if("function"!=typeof t)throw new TypeError("executor must be a function.");var e;this.promise=new Promise(function(t){e=t});var n=this;t(function(t){n.reason||(n.reason=new r(t),e(n.reason))})}i.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},i.source=function(){var t;return{token:new i(function(e){t=e}),cancel:t}},t.exports=i},function(t,e,n){"use strict";var r=n(28);t.exports=r.isStandardBrowserEnv()?{write:function(t,e,n,i,a,o){var s=[];s.push(t+"="+encodeURIComponent(e)),r.isNumber(n)&&s.push("expires="+new Date(n).toGMTString()),r.isString(i)&&s.push("path="+i),r.isString(a)&&s.push("domain="+a),!0===o&&s.push("secure"),document.cookie=s.join("; ")},read:function(t){var e=document.cookie.match(new RegExp("(^|;\\s*)("+t+")=([^;]*)"));return e?decodeURIComponent(e[3]):null},remove:function(t){this.write(t,"",Date.now()-864e5)}}:{write:function(){},read:function(){return null},remove:function(){}}},function(t,e,n){"use strict";var r=n(28);t.exports=r.isStandardBrowserEnv()?function(){var t,e=/(msie|trident)/i.test(navigator.userAgent),n=document.createElement("a");function i(t){var r=t;return e&&(n.setAttribute("href",r),r=n.href),n.setAttribute("href",r),{href:n.href,protocol:n.protocol?n.protocol.replace(/:$/,""):"",host:n.host,search:n.search?n.search.replace(/^\?/,""):"",hash:n.hash?n.hash.replace(/^#/,""):"",hostname:n.hostname,port:n.port,pathname:"/"===n.pathname.charAt(0)?n.pathname:"/"+n.pathname}}return t=i(window.location.href),function(e){var n=r.isString(e)?i(e):e;return n.protocol===t.protocol&&n.host===t.host}}():function(){return!0}},function(t,e,n){"use strict";var r=n(28),i=["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"];t.exports=function(t){var e,n,a,o={};return t?(r.forEach(t.split("\n"),function(t){if(a=t.indexOf(":"),e=r.trim(t.substr(0,a)).toLowerCase(),n=r.trim(t.substr(a+1)),e){if(o[e]&&i.indexOf(e)>=0)return;o[e]="set-cookie"===e?(o[e]?o[e]:[]).concat([n]):o[e]?o[e]+", "+n:n}}),o):o}},function(t,e,n){"use strict";t.exports=function(t,e){return e?t.replace(/\/+$/,"")+"/"+e.replace(/^\/+/,""):t}},function(t,e,n){"use strict";t.exports=function(t){return/^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(t)}},function(t,e,n){"use strict";var r=n(389),i=n(388);t.exports=function(t,e){return t&&!r(e)?i(t,e):e}},function(t,e,n){"use strict";t.exports=function(t,e,n,r,i){return t.config=e,n&&(t.code=n),t.request=r,t.response=i,t.isAxiosError=!0,t.toJSON=function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:this.config,code:this.code}},t}},function(t,e,n){"use strict";var r=n(213);t.exports=function(t,e,n){var i=n.config.validateStatus;!i||i(n.status)?t(n):e(r("Request failed with status code "+n.status,n.config,null,n.request,n))}},function(t,e,n){"use strict";var r=n(28);t.exports=function(t,e){r.forEach(t,function(n,r){r!==e&&r.toUpperCase()===e.toUpperCase()&&(t[e]=n,delete t[r])})}},function(t,e,n){"use strict";var r=n(28);t.exports=function(t,e,n){return r.forEach(n,function(n){t=n(t,e)}),t}},function(t,e,n){"use strict";var r=n(28),i=n(394),a=n(216),o=n(215);function s(t){t.cancelToken&&t.cancelToken.throwIfRequested()}t.exports=function(t){return s(t),t.headers=t.headers||{},t.data=i(t.data,t.headers,t.transformRequest),t.headers=r.merge(t.headers.common||{},t.headers[t.method]||{},t.headers),r.forEach(["delete","get","head","post","put","patch","common"],function(e){delete t.headers[e]}),(t.adapter||o.adapter)(t).then(function(e){return s(t),e.data=i(e.data,e.headers,t.transformResponse),e},function(e){return a(e)||(s(t),e&&e.response&&(e.response.data=i(e.response.data,e.response.headers,t.transformResponse))),Promise.reject(e)})}},function(t,e,n){"use strict";var r=n(28);function i(){this.handlers=[]}i.prototype.use=function(t,e){return this.handlers.push({fulfilled:t,rejected:e}),this.handlers.length-1},i.prototype.eject=function(t){this.handlers[t]&&(this.handlers[t]=null)},i.prototype.forEach=function(t){r.forEach(this.handlers,function(e){null!==e&&t(e)})},t.exports=i},function(t,e,n){"use strict";var r=n(28),i=n(217),a=n(396),o=n(395),s=n(212);function u(t){this.defaults=t,this.interceptors={request:new a,response:new a}}u.prototype.request=function(t){"string"==typeof t?(t=arguments[1]||{}).url=arguments[0]:t=t||{},(t=s(this.defaults,t)).method?t.method=t.method.toLowerCase():this.defaults.method?t.method=this.defaults.method.toLowerCase():t.method="get";var e=[o,void 0],n=Promise.resolve(t);for(this.interceptors.request.forEach(function(t){e.unshift(t.fulfilled,t.rejected)}),this.interceptors.response.forEach(function(t){e.push(t.fulfilled,t.rejected)});e.length;)n=n.then(e.shift(),e.shift());return n},u.prototype.getUri=function(t){return t=s(this.defaults,t),i(t.url,t.params,t.paramsSerializer).replace(/^\?/,"")},r.forEach(["delete","get","head","options"],function(t){u.prototype[t]=function(e,n){return this.request(r.merge(n||{},{method:t,url:e}))}}),r.forEach(["post","put","patch"],function(t){u.prototype[t]=function(e,n,i){return this.request(r.merge(i||{},{method:t,url:e,data:n}))}}),t.exports=u},function(t,e,n){"use strict";var r=n(28),i=n(218),a=n(397),o=n(212);function s(t){var e=new a(t),n=i(a.prototype.request,e);return r.extend(n,a.prototype,e),r.extend(n,e),n}var u=s(n(215));u.Axios=a,u.create=function(t){return s(o(u.defaults,t))},u.Cancel=n(211),u.CancelToken=n(384),u.isCancel=n(216),u.all=function(t){return Promise.all(t)},u.spread=n(383),t.exports=u,t.exports.default=u},function(t,e,n){"use strict";var r=n(39),i=n(108);t.exports=function(t,e,n){e in t?r.f(t,e,i(0,n)):t[e]=n}},function(t,e,n){"use strict";var r=n(56),i=n(23),a=n(66),o=n(230),s=n(229),u=n(122),c=n(399),l=n(150);i(i.S+i.F*!n(223)(function(t){Array.from(t)}),"Array",{from:function(t){var e,n,i,f,d=a(t),h="function"==typeof this?this:Array,p=arguments.length,m=p>1?arguments[1]:void 0,g=void 0!==m,v=0,y=l(d);if(g&&(m=r(m,p>2?arguments[2]:void 0,2)),void 0==y||h==Array&&s(y))for(n=new h(e=u(d.length));e>v;v++)c(n,v,g?m(d[v],v):d[v]);else for(f=y.call(d),n=new h;!(i=f.next()).done;v++)c(n,v,g?o(f,m,[i.value,v],!0):i.value);return n.length=v,n}})},function(t,e,n){n(85),n(400),t.exports=n(18).Array.from},function(t,e,n){n(145)("observable")},function(t,e,n){n(145)("asyncIterator")},function(t,e,n){var r=n(67),i=n(220).f,a={}.toString,o="object"==typeof window&&window&&Object.getOwnPropertyNames?Object.getOwnPropertyNames(window):[];t.exports.f=function(t){return o&&"[object Window]"==a.call(t)?function(t){try{return i(t)}catch(t){return o.slice()}}(t):i(r(t))}},function(t,e,n){var r=n(88),i=n(157),a=n(105);t.exports=function(t){var e=r(t),n=i.f;if(n)for(var o,s=n(t),u=a.f,c=0;s.length>c;)u.call(t,o=s[c++])&&e.push(o);return e}},function(t,e,n){"use strict";var r=n(26),i=n(68),a=n(32),o=n(23),s=n(234),u=n(146).KEY,c=n(69),l=n(159),f=n(102),d=n(121),h=n(25),p=n(147),m=n(145),g=n(405),v=n(221),y=n(48),b=n(38),x=n(66),w=n(67),k=n(164),_=n(108),E=n(117),O=n(404),S=n(219),C=n(157),A=n(39),N=n(88),T=S.f,I=A.f,D=O.f,M=r.Symbol,R=r.JSON,F=R&&R.stringify,j=h("_hidden"),P=h("toPrimitive"),L={}.propertyIsEnumerable,z=l("symbol-registry"),B=l("symbols"),U=l("op-symbols"),W=Object.prototype,V="function"==typeof M&&!!C.f,q=r.QObject,H=!q||!q.prototype||!q.prototype.findChild,G=a&&c(function(){return 7!=E(I({},"a",{get:function(){return I(this,"a",{value:7}).a}})).a})?function(t,e,n){var r=T(W,e);r&&delete W[e],I(t,e,n),r&&t!==W&&I(W,e,r)}:I,$=function(t){var e=B[t]=E(M.prototype);return e._k=t,e},K=V&&"symbol"==typeof M.iterator?function(t){return"symbol"==typeof t}:function(t){return t instanceof M},X=function(t,e,n){return t===W&&X(U,e,n),y(t),e=k(e,!0),y(n),i(B,e)?(n.enumerable?(i(t,j)&&t[j][e]&&(t[j][e]=!1),n=E(n,{enumerable:_(0,!1)})):(i(t,j)||I(t,j,_(1,{})),t[j][e]=!0),G(t,e,n)):I(t,e,n)},Y=function(t,e){y(t);for(var n,r=g(e=w(e)),i=0,a=r.length;a>i;)X(t,n=r[i++],e[n]);return t},J=function(t){var e=L.call(this,t=k(t,!0));return!(this===W&&i(B,t)&&!i(U,t))&&(!(e||!i(this,t)||!i(B,t)||i(this,j)&&this[j][t])||e)},Z=function(t,e){if(t=w(t),e=k(e,!0),t!==W||!i(B,e)||i(U,e)){var n=T(t,e);return!n||!i(B,e)||i(t,j)&&t[j][e]||(n.enumerable=!0),n}},Q=function(t){for(var e,n=D(w(t)),r=[],a=0;n.length>a;)i(B,e=n[a++])||e==j||e==u||r.push(e);return r},tt=function(t){for(var e,n=t===W,r=D(n?U:w(t)),a=[],o=0;r.length>o;)!i(B,e=r[o++])||n&&!i(W,e)||a.push(B[e]);return a};V||(s((M=function(){if(this instanceof M)throw TypeError("Symbol is not a constructor!");var t=d(arguments.length>0?arguments[0]:void 0),e=function(n){this===W&&e.call(U,n),i(this,j)&&i(this[j],t)&&(this[j][t]=!1),G(this,t,_(1,n))};return a&&H&&G(W,t,{configurable:!0,set:e}),$(t)}).prototype,"toString",function(){return this._k}),S.f=Z,A.f=X,n(220).f=O.f=Q,n(105).f=J,C.f=tt,a&&!n(106)&&s(W,"propertyIsEnumerable",J,!0),p.f=function(t){return $(h(t))}),o(o.G+o.W+o.F*!V,{Symbol:M});for(var et="hasInstance,isConcatSpreadable,iterator,match,replace,search,species,split,toPrimitive,toStringTag,unscopables".split(","),nt=0;et.length>nt;)h(et[nt++]);for(var rt=N(h.store),it=0;rt.length>it;)m(rt[it++]);o(o.S+o.F*!V,"Symbol",{for:function(t){return i(z,t+="")?z[t]:z[t]=M(t)},keyFor:function(t){if(!K(t))throw TypeError(t+" is not a symbol!");for(var e in z)if(z[e]===t)return e},useSetter:function(){H=!0},useSimple:function(){H=!1}}),o(o.S+o.F*!V,"Object",{create:function(t,e){return void 0===e?E(t):Y(E(t),e)},defineProperty:X,defineProperties:Y,getOwnPropertyDescriptor:Z,getOwnPropertyNames:Q,getOwnPropertySymbols:tt});var at=c(function(){C.f(1)});o(o.S+o.F*at,"Object",{getOwnPropertySymbols:function(t){return C.f(x(t))}}),R&&o(o.S+o.F*(!V||c(function(){var t=M();return"[null]"!=F([t])||"{}"!=F({a:t})||"{}"!=F(Object(t))})),"JSON",{stringify:function(t){for(var e,n,r=[t],i=1;arguments.length>i;)r.push(arguments[i++]);if(n=e=r[1],(b(e)||void 0!==t)&&!K(t))return v(e)||(e=function(t,e){if("function"==typeof n&&(e=n.call(this,t,e)),!K(e))return e}),r[1]=e,F.apply(R,r)}}),M.prototype[P]||n(60)(M.prototype,P,M.prototype.valueOf),f(M,"Symbol"),f(Math,"Math",!0),f(r.JSON,"JSON",!0)},function(t,e,n){n(406),n(153),n(403),n(402),t.exports=n(18).Symbol},function(t,e,n){t.exports={default:n(407),__esModule:!0}},function(t,e,n){n(85),n(101),t.exports=n(147).f("iterator")},function(t,e,n){t.exports={default:n(409),__esModule:!0}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=y(n(14)),i=y(n(47)),a=y(n(24)),o=y(n(9)),s=y(n(8)),u=y(n(7)),c=y(n(10)),l=v(n(4)),f=y(n(55)),d=v(n(382)),h=v(n(381)),p=v(n(379)),m=y(n(15)),g=n(46);function v(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}function y(t){return t&&t.__esModule?t:{default:t}}var b={mobilenet:{version:2,alpha:1,topk:3}},x=["mobilenet","darknet","darknet-tiny","doodlenet"],w=function(){function t(e,n,r,i){if((0,u.default)(this,t),this.video=n,this.model=null,this.mapStringToIndex=[],"string"==typeof e)if(x.includes(e))switch(this.modelName=e,this.modelUrl=null,this.modelName){case"mobilenet":this.modelToUse=d,this.version=r.version||b.mobilenet.version,this.alpha=r.alpha||b.mobilenet.alpha,this.topk=r.topk||b.mobilenet.topk;break;case"darknet":this.version="reference",this.modelToUse=h;break;case"darknet-tiny":this.version="tiny",this.modelToUse=h;break;case"doodlenet":this.modelToUse=p;break;default:this.modelToUse=null}else this.modelUrl=e;this.ready=(0,m.default)(this.loadModel(this.modelUrl),i)}return(0,c.default)(t,[{key:"loadModel",value:function(){var t=(0,s.default)(o.default.mark(function t(e){return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!e){t.next=6;break}return t.next=3,this.loadModelFrom(e);case 3:this.model=t.sent,t.next=9;break;case 6:return t.next=8,this.modelToUse.load({version:this.version,alpha:this.alpha});case 8:this.model=t.sent;case 9:return t.abrupt("return",this);case 10:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"loadModelFrom",value:function(){var t=(0,s.default)(o.default.mark(function t(){var e,n,r,i,a,s,u,c=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(t.prev=0,e=void 0,null===c){t.next=7;break}return t.next=5,f.default.get(c);case 5:n=t.sent,e=n.data;case 7:if(e.ml5Specs&&(this.mapStringToIndex=e.ml5Specs.mapStringToIndex),0!==this.mapStringToIndex.length){t.next=16;break}return r=c.split("/"),i=r.slice(0,r.length-1).join("/"),a=i+"/metadata.json",t.next=14,f.default.get(a).catch(function(t){console.log("Tried to fetch metadata.json, but it seems to be missing.",t)});case 14:(s=t.sent)&&(u=s.data).labels&&(this.mapStringToIndex=u.labels);case 16:return t.next=18,l.loadLayersModel(c);case 18:return this.model=t.sent,t.abrupt("return",this.model);case 22:return t.prev=22,t.t0=t.catch(0),console.error(t.t0),t.abrupt("return",t.t0);case 26:case"end":return t.stop()}},t,this,[[0,22]])}));return function(){return t.apply(this,arguments)}}()},{key:"classifyInternal",value:function(){var t=(0,s.default)(o.default.mark(function t(e,n){var r,s,u,c,f,d,h=this;return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.ready;case 2:return t.next=4,l.nextFrame();case 4:if(!(e instanceof HTMLVideoElement&&0===e.readyState)){t.next=8;break}return r=e,t.next=8,new a.default(function(t){r.onloadeddata=function(){return t()}});case 8:if(!this.video||0!==this.video.readyState){t.next=11;break}return t.next=11,new a.default(function(t){h.video.onloadeddata=function(){return t()}});case 11:if(s=[224,224],!this.modelUrl){t.next=20;break}return t.next=15,l.nextFrame();case 15:return u=l.tidy(function(){var t=(0,g.imgToTensor)(e,s),n=h.model.predict(t);return(0,i.default)(n.as1D().dataSync())}),t.next=18,u.map(function(t,e){return{label:h.mapStringToIndex.length>0&&h.mapStringToIndex[e]?h.mapStringToIndex[e]:e,confidence:t}}).sort(function(t,e){return e.confidence-t.confidence});case 18:return c=t.sent,t.abrupt("return",c);case 20:return f=(0,g.imgToTensor)(e,s),d=this.model.classify(f,n).then(function(t){return t.map(function(t){return{label:t.className,confidence:t.probability}})}),f.dispose(),t.abrupt("return",d);case 24:case"end":return t.stop()}},t,this)}));return function(e,n){return t.apply(this,arguments)}}()},{key:"classify",value:function(){var t=(0,s.default)(o.default.mark(function t(e){var n,i,a,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,u=arguments[2];return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(n=this.video,i=this.topk,a=void 0,"function"!=typeof e){t.next=8;break}n=this.video,a=e,t.next=27;break;case 8:if("number"!=typeof e){t.next=13;break}n=this.video,i=e,t.next=27;break;case 13:if(!(e instanceof HTMLVideoElement||e instanceof HTMLImageElement||e instanceof HTMLCanvasElement||e instanceof ImageData)){t.next=17;break}n=e,t.next=27;break;case 17:if("object"!==(void 0===e?"undefined":(0,r.default)(e))||!(e.elt instanceof HTMLVideoElement||e.elt instanceof HTMLImageElement||e.elt instanceof HTMLCanvasElement||e.elt instanceof ImageData)){t.next=21;break}n=e.elt,t.next=27;break;case 21:if(!("object"===(void 0===e?"undefined":(0,r.default)(e))&&e.canvas instanceof HTMLCanvasElement)){t.next=25;break}n=e.canvas,t.next=27;break;case 25:if(this.video instanceof HTMLVideoElement){t.next=27;break}throw new Error("No input image provided. If you want to classify a video, pass the video element in the constructor. ");case 27:return"number"==typeof s?i=s:"function"==typeof s&&(a=s),"function"==typeof u&&(a=u),t.abrupt("return",(0,m.default)(this.classifyInternal(n,i),a));case 30:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"predict",value:function(){var t=(0,s.default)(o.default.mark(function t(e,n,r){return o.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.classify(e,n||null,r));case 1:case"end":return t.stop()}},t,this)}));return function(e,n,r){return t.apply(this,arguments)}}()}]),t}();e.default=function(t,e,n,i){var a=void 0,o={},s=i,u=t;if("string"!=typeof u)throw new Error('Please specify a model to use. E.g: "MobileNet"');-1===u.indexOf("http")&&(u=t.toLowerCase()),e instanceof HTMLVideoElement?a=e:"object"===(void 0===e?"undefined":(0,r.default)(e))&&e.elt instanceof HTMLVideoElement?a=e.elt:"object"===(void 0===e?"undefined":(0,r.default)(e))?o=e:"function"==typeof e&&(s=e),"object"===(void 0===n?"undefined":(0,r.default)(n))?o=n:"function"==typeof n&&(s=n);var c=new w(u,a,o,s);return s?c:c.ready}},function(t,e,n){var r=n(23);r(r.S+r.F*!n(32),"Object",{defineProperty:n(39).f})},function(t,e,n){n(412);var r=n(18).Object;t.exports=function(t,e,n){return r.defineProperty(t,e,n)}},function(t,e,n){"use strict";var r=n(23),i=n(149),a=n(226);r(r.S,"Promise",{try:function(t){var e=i.f(this),n=a(t);return(n.e?e.reject:e.resolve)(n.v),e.promise}})},function(t,e,n){"use strict";var r=n(23),i=n(18),a=n(26),o=n(228),s=n(225);r(r.P+r.R,"Promise",{finally:function(t){var e=o(this,i.Promise||a.Promise),n="function"==typeof t;return this.then(n?function(n){return s(e,t()).then(function(){return n})}:t,n?function(n){return s(e,t()).then(function(){throw n})}:t)}})},function(t,e,n){var r=n(26).navigator;t.exports=r&&r.userAgent||""},function(t,e,n){var r=n(26),i=n(227).set,a=r.MutationObserver||r.WebKitMutationObserver,o=r.process,s=r.Promise,u="process"==n(107)(o);t.exports=function(){var t,e,n,c=function(){var r,i;for(u&&(r=o.domain)&&r.exit();t;){i=t.fn,t=t.next;try{i()}catch(r){throw t?n():e=void 0,r}}e=void 0,r&&r.enter()};if(u)n=function(){o.nextTick(c)};else if(!a||r.navigator&&r.navigator.standalone)if(s&&s.resolve){var l=s.resolve(void 0);n=function(){l.then(c)}}else n=function(){i.call(r,c)};else{var f=!0,d=document.createTextNode("");new a(c).observe(d,{characterData:!0}),n=function(){d.data=f=!f}}return function(r){var i={fn:r,next:void 0};e&&(e.next=i),t||(t=i,n()),e=i}}},function(t,e){t.exports=function(t,e,n){var r=void 0===n;switch(e.length){case 0:return r?t():t.call(n);case 1:return r?t(e[0]):t.call(n,e[0]);case 2:return r?t(e[0],e[1]):t.call(n,e[0],e[1]);case 3:return r?t(e[0],e[1],e[2]):t.call(n,e[0],e[1],e[2]);case 4:return r?t(e[0],e[1],e[2],e[3]):t.call(n,e[0],e[1],e[2],e[3])}return t.apply(n,e)}},function(t,e,n){"use strict";var r,i,a,o,s=n(106),u=n(26),c=n(56),l=n(116),f=n(23),d=n(38),h=n(109),p=n(151),m=n(100),g=n(228),v=n(227).set,y=n(417)(),b=n(149),x=n(226),w=n(416),k=n(225),_=u.TypeError,E=u.process,O=E&&E.versions,S=O&&O.v8||"",C=u.Promise,A="process"==l(E),N=function(){},T=i=b.f,I=!!function(){try{var t=C.resolve(1),e=(t.constructor={})[n(25)("species")]=function(t){t(N,N)};return(A||"function"==typeof PromiseRejectionEvent)&&t.then(N)instanceof e&&0!==S.indexOf("6.6")&&-1===w.indexOf("Chrome/66")}catch(t){}}(),D=function(t){var e;return!(!d(t)||"function"!=typeof(e=t.then))&&e},M=function(t,e){if(!t._n){t._n=!0;var n=t._c;y(function(){for(var r=t._v,i=1==t._s,a=0,o=function(e){var n,a,o,s=i?e.ok:e.fail,u=e.resolve,c=e.reject,l=e.domain;try{s?(i||(2==t._h&&j(t),t._h=1),!0===s?n=r:(l&&l.enter(),n=s(r),l&&(l.exit(),o=!0)),n===e.promise?c(_("Promise-chain cycle")):(a=D(n))?a.call(n,u,c):u(n)):c(r)}catch(t){l&&!o&&l.exit(),c(t)}};n.length>a;)o(n[a++]);t._c=[],t._n=!1,e&&!t._h&&R(t)})}},R=function(t){v.call(u,function(){var e,n,r,i=t._v,a=F(t);if(a&&(e=x(function(){A?E.emit("unhandledRejection",i,t):(n=u.onunhandledrejection)?n({promise:t,reason:i}):(r=u.console)&&r.error&&r.error("Unhandled promise rejection",i)}),t._h=A||F(t)?2:1),t._a=void 0,a&&e.e)throw e.v})},F=function(t){return 1!==t._h&&0===(t._a||t._c).length},j=function(t){v.call(u,function(){var e;A?E.emit("rejectionHandled",t):(e=u.onrejectionhandled)&&e({promise:t,reason:t._v})})},P=function(t){var e=this;e._d||(e._d=!0,(e=e._w||e)._v=t,e._s=2,e._a||(e._a=e._c.slice()),M(e,!0))},L=function(t){var e,n=this;if(!n._d){n._d=!0,n=n._w||n;try{if(n===t)throw _("Promise can't be resolved itself");(e=D(t))?y(function(){var r={_w:n,_d:!1};try{e.call(t,c(L,r,1),c(P,r,1))}catch(t){P.call(r,t)}}):(n._v=t,n._s=1,M(n,!1))}catch(t){P.call({_w:n,_d:!1},t)}}};I||(C=function(t){p(this,C,"Promise","_h"),h(t),r.call(this);try{t(c(L,this,1),c(P,this,1))}catch(t){P.call(this,t)}},(r=function(t){this._c=[],this._a=void 0,this._s=0,this._d=!1,this._v=void 0,this._h=0,this._n=!1}).prototype=n(148)(C.prototype,{then:function(t,e){var n=T(g(this,C));return n.ok="function"!=typeof t||t,n.fail="function"==typeof e&&e,n.domain=A?E.domain:void 0,this._c.push(n),this._a&&this._a.push(n),this._s&&M(this,!1),n.promise},catch:function(t){return this.then(void 0,t)}}),a=function(){var t=new r;this.promise=t,this.resolve=c(L,t,1),this.reject=c(P,t,1)},b.f=T=function(t){return t===C||t===o?new a(t):i(t)}),f(f.G+f.W+f.F*!I,{Promise:C}),n(102)(C,"Promise"),n(224)("Promise"),o=n(18).Promise,f(f.S+f.F*!I,"Promise",{reject:function(t){var e=T(this);return(0,e.reject)(t),e.promise}}),f(f.S+f.F*(s||!I),"Promise",{resolve:function(t){return k(s&&this===o?C:this,t)}}),f(f.S+f.F*!(I&&n(223)(function(t){C.all(t).catch(N)})),"Promise",{all:function(t){var e=this,n=T(e),r=n.resolve,i=n.reject,a=x(function(){var n=[],a=0,o=1;m(t,!1,function(t){var s=a++,u=!1;n.push(void 0),o++,e.resolve(t).then(function(t){u||(u=!0,n[s]=t,--o||r(n))},i)}),--o||r(n)});return a.e&&i(a.v),n.promise},race:function(t){var e=this,n=T(e),r=n.reject,i=x(function(){m(t,!1,function(t){e.resolve(t).then(n.resolve,r)})});return i.e&&r(i.v),n.promise}})},function(t,e){t.exports=function(){}},function(t,e,n){"use strict";var r=n(420),i=n(231),a=n(84),o=n(67);t.exports=n(152)(Array,"Array",function(t,e){this._t=o(t),this._i=0,this._k=e},function(){var t=this._t,e=this._k,n=this._i++;return!t||n>=t.length?(this._t=void 0,i(1)):i(0,"keys"==e?n:"values"==e?t[n]:[n,t[n]])},"values"),a.Arguments=a.Array,r("keys"),r("values"),r("entries")},function(t,e,n){var r=n(39),i=n(48),a=n(88);t.exports=n(32)?Object.defineProperties:function(t,e){i(t);for(var n,o=a(e),s=o.length,u=0;s>u;)r.f(t,n=o[u++],e[n]);return t}},function(t,e,n){"use strict";var r=n(117),i=n(108),a=n(102),o={};n(60)(o,n(25)("iterator"),function(){return this}),t.exports=function(t,e,n){t.prototype=r(o,{next:i(1,n)}),a(t,e+" Iterator")}},function(t,e,n){var r=n(161),i=n(162);t.exports=function(t){return function(e,n){var a,o,s=String(i(e)),u=r(n),c=s.length;return u<0||u>=c?t?"":void 0:(a=s.charCodeAt(u))<55296||a>56319||u+1===c||(o=s.charCodeAt(u+1))<56320||o>57343?t?s.charAt(u):a:t?s.slice(u,u+2):o-56320+(a-55296<<10)+65536}}},function(t,e,n){n(153),n(85),n(101),n(419),n(415),n(414),t.exports=n(18).Promise},function(t,e){!function(e){"use strict";var n,r=Object.prototype,i=r.hasOwnProperty,a="function"==typeof Symbol?Symbol:{},o=a.iterator||"@@iterator",s=a.asyncIterator||"@@asyncIterator",u=a.toStringTag||"@@toStringTag",c="object"==typeof t,l=e.regeneratorRuntime;if(l)c&&(t.exports=l);else{(l=e.regeneratorRuntime=c?t.exports:{}).wrap=x;var f="suspendedStart",d="suspendedYield",h="executing",p="completed",m={},g={};g[o]=function(){return this};var v=Object.getPrototypeOf,y=v&&v(v(I([])));y&&y!==r&&i.call(y,o)&&(g=y);var b=E.prototype=k.prototype=Object.create(g);_.prototype=b.constructor=E,E.constructor=_,E[u]=_.displayName="GeneratorFunction",l.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===_||"GeneratorFunction"===(e.displayName||e.name))},l.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,E):(t.__proto__=E,u in t||(t[u]="GeneratorFunction")),t.prototype=Object.create(b),t},l.awrap=function(t){return{__await:t}},O(S.prototype),S.prototype[s]=function(){return this},l.AsyncIterator=S,l.async=function(t,e,n,r){var i=new S(x(t,e,n,r));return l.isGeneratorFunction(e)?i:i.next().then(function(t){return t.done?t.value:i.next()})},O(b),b[u]="Generator",b[o]=function(){return this},b.toString=function(){return"[object Generator]"},l.keys=function(t){var e=[];for(var n in t)e.push(n);return e.reverse(),function n(){for(;e.length;){var r=e.pop();if(r in t)return n.value=r,n.done=!1,n}return n.done=!0,n}},l.values=I,T.prototype={constructor:T,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=n,this.done=!1,this.delegate=null,this.method="next",this.arg=n,this.tryEntries.forEach(N),!t)for(var e in this)"t"===e.charAt(0)&&i.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=n)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(r,i){return s.type="throw",s.arg=t,e.next=r,i&&(e.method="next",e.arg=n),!!i}for(var a=this.tryEntries.length-1;a>=0;--a){var o=this.tryEntries[a],s=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var u=i.call(o,"catchLoc"),c=i.call(o,"finallyLoc");if(u&&c){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(u){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&i.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var a=r;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var o=a?a.completion:{};return o.type=t,o.arg=e,a?(this.method="next",this.next=a.finallyLoc,m):this.complete(o)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),m},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),N(n),m}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var i=r.arg;N(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:I(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=n),m}}}function x(t,e,n,r){var i=e&&e.prototype instanceof k?e:k,a=Object.create(i.prototype),o=new T(r||[]);return a._invoke=function(t,e,n){var r=f;return function(i,a){if(r===h)throw new Error("Generator is already running");if(r===p){if("throw"===i)throw a;return D()}for(n.method=i,n.arg=a;;){var o=n.delegate;if(o){var s=C(o,n);if(s){if(s===m)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(r===f)throw r=p,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r=h;var u=w(t,e,n);if("normal"===u.type){if(r=n.done?p:d,u.arg===m)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r=p,n.method="throw",n.arg=u.arg)}}}(t,n,o),a}function w(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}function k(){}function _(){}function E(){}function O(t){["next","throw","return"].forEach(function(e){t[e]=function(t){return this._invoke(e,t)}})}function S(t){var e;this._invoke=function(n,r){function a(){return new Promise(function(e,a){!function e(n,r,a,o){var s=w(t[n],t,r);if("throw"!==s.type){var u=s.arg,c=u.value;return c&&"object"==typeof c&&i.call(c,"__await")?Promise.resolve(c.__await).then(function(t){e("next",t,a,o)},function(t){e("throw",t,a,o)}):Promise.resolve(c).then(function(t){u.value=t,a(u)},o)}o(s.arg)}(n,r,e,a)})}return e=e?e.then(a,a):a()}}function C(t,e){var r=t.iterator[e.method];if(r===n){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=n,C(t,e),"throw"===e.method))return m;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return m}var i=w(r,t.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,m;var a=i.arg;return a?a.done?(e[t.resultName]=a.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=n),e.delegate=null,m):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,m)}function A(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function N(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function T(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(A,this),this.reset(!0)}function I(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,a=function e(){for(;++r<t.length;)if(i.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=n,e.done=!0,e};return a.next=a}}return{next:D}}function D(){return{value:n,done:!0}}}(function(){return this}()||Function("return this")())},function(t,e,n){var r=function(){return this}()||Function("return this")(),i=r.regeneratorRuntime&&Object.getOwnPropertyNames(r).indexOf("regeneratorRuntime")>=0,a=i&&r.regeneratorRuntime;if(r.regeneratorRuntime=void 0,t.exports=n(426),i)r.regeneratorRuntime=a;else try{delete r.regeneratorRuntime}catch(t){r.regeneratorRuntime=void 0}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=c(n(9)),i=c(n(8)),a=c(n(7)),o=c(n(10)),s=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(4)),u=c(n(15));function c(t){return t&&t.__esModule?t:{default:t}}var l=function(){function t(e,n,r,i){(0,a.default)(this,t),this.model=e,this.audioContext=n,this.stream=r,this.frequency=null,this.ready=(0,u.default)(this.loadModel(e),i)}return(0,o.default)(t,[{key:"loadModel",value:function(){var t=(0,i.default)(r.default.mark(function t(e){return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s.loadLayersModel(e+"/model.json");case 2:if(this.model=t.sent,!this.audioContext){t.next=8;break}return t.next=6,this.processStream();case 6:t.next=9;break;case 8:throw new Error("Could not access microphone - getUserMedia not available");case 9:return t.abrupt("return",this);case 10:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()},{key:"processStream",value:function(){var t=(0,i.default)(r.default.mark(function t(){var e,n,i,a,o;return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s.nextFrame();case 2:for(e=this.audioContext.createMediaStreamSource(this.stream),n=this.audioContext.sampleRate/16e3*1024,i=4;i<n;)i*=2;(a=this.audioContext.createScriptProcessor(i,1,1)).onaudioprocess=this.processMicrophoneBuffer.bind(this),(o=this.audioContext.createGain()).gain.setValueAtTime(0,this.audioContext.currentTime),e.connect(a),a.connect(o),o.connect(this.audioContext.destination),"running"!==this.audioContext.state&&console.warn("User gesture needed to start AudioContext, please click");case 14:case"end":return t.stop()}},t,this)}));return function(){return t.apply(this,arguments)}}()},{key:"processMicrophoneBuffer",value:function(){var e=(0,i.default)(r.default.mark(function e(n){var i=this;return r.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,s.nextFrame();case 2:this.results={},t.resample(n.inputBuffer,function(t){s.tidy(function(){var e=s.add(s.linspace(0,7180,360),s.tensor(1997.379408437619));i.running=!0;var n=s.tensor(t.slice(0,1024)),r=s.sub(n,s.mean(n)),a=s.tensor(s.norm(r).dataSync()/Math.sqrt(1024)),o=s.div(r,a).reshape([1,1024]),u=i.model.predict([o]).reshape([360]),c=u.max().dataSync()[0],l=u.argMax().dataSync()[0];i.results.confidence=c.toFixed(3);var f=Math.max(0,l-4),d=Math.min(360,l+5),h=u.slice([f],[d-f]),p=e.slice([f],[d-f]),m=s.mul(h,p).dataSync().reduce(function(t,e){return t+e},0)/h.dataSync().reduce(function(t,e){return t+e},0),g=10*Math.pow(2,m/1200),v=c>.5?g:null;i.frequency=v})});case 4:case"end":return e.stop()}},e,this)}));return function(t){return e.apply(this,arguments)}}()},{key:"getPitch",value:function(){var t=(0,i.default)(r.default.mark(function t(e){var n;return r.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.ready;case 2:return t.next=4,s.nextFrame();case 4:return n=this.frequency,e&&e(void 0,n),t.abrupt("return",n);case 7:case"end":return t.stop()}},t,this)}));return function(e){return t.apply(this,arguments)}}()}],[{key:"resample",value:function(t,e){for(var n=t.sampleRate%16e3!=0,r=t.sampleRate/16e3,i=t.getChannelData(0),a=new Float32Array(1024),o=0;o<1024;o+=1)if(n){var s=Math.floor(o*r),u=s+1,c=o*r-s;a[o]=(1-c)*i[s]+c*i[u]}else a[o]=i[o*r];e(a)}}]),t}();e.default=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"./",e=arguments[1],n=arguments[2],r=arguments[3];return new l(t,e,n,r)}},function(t,e,n){"use strict";
  372. /** @license See the LICENSE file. */Object.defineProperty(e,"__esModule",{value:!0});e.version="1.4.0"},function(t,e,n){"use strict";
  373. /**
  374. * @license
  375. * Copyright 2018 Google LLC. All Rights Reserved.
  376. * Licensed under the Apache License, Version 2.0 (the "License");
  377. * you may not use this file except in compliance with the License.
  378. * You may obtain a copy of the License at
  379. *
  380. * http://www.apache.org/licenses/LICENSE-2.0
  381. *
  382. * Unless required by applicable law or agreed to in writing, software
  383. * distributed under the License is distributed on an "AS IS" BASIS,
  384. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  385. * See the License for the specific language governing permissions and
  386. * limitations under the License.
  387. * =============================================================================
  388. */var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})};Object.defineProperty(e,"__esModule",{value:!0});const i=n(154),a=n(37),o=n(119);e.valuesDistribution=function(t,e){return r(this,void 0,void 0,function*(){const n=a.getDrawArea(t),r=yield o.tensorStats(e),s=yield e.data();i.histogram(n,s,{height:150,stats:r})})}},function(t,e,n){"use strict";
  389. /**
  390. * @license
  391. * Copyright 2018 Google LLC. All Rights Reserved.
  392. * Licensed under the Apache License, Version 2.0 (the "License");
  393. * you may not use this file except in compliance with the License.
  394. * You may obtain a copy of the License at
  395. *
  396. * http://www.apache.org/licenses/LICENSE-2.0
  397. *
  398. * Unless required by applicable law or agreed to in writing, software
  399. * distributed under the License is distributed on an "AS IS" BASIS,
  400. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  401. * See the License for the specific language governing permissions and
  402. * limitations under the License.
  403. * =============================================================================
  404. */var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})};Object.defineProperty(e,"__esModule",{value:!0});const i=n(37),a=n(118);e.showPerClassAccuracy=function(t,e,n){return r(this,void 0,void 0,function*(){const r=i.getDrawArea(t),o=[];for(let t=0;t<e.length;t++){const r=n?n[t]:t.toString(),i=e[t];o.push([r,i.accuracy,i.count])}return a.table(r,{headers:["Class","Accuracy","# Samples"],values:o})})}},function(t,e,n){"use strict";
  405. /**
  406. * @license
  407. * Copyright 2018 Google LLC. All Rights Reserved.
  408. * Licensed under the Apache License, Version 2.0 (the "License");
  409. * you may not use this file except in compliance with the License.
  410. * You may obtain a copy of the License at
  411. *
  412. * http://www.apache.org/licenses/LICENSE-2.0
  413. *
  414. * Unless required by applicable law or agreed to in writing, software
  415. * distributed under the License is distributed on an "AS IS" BASIS,
  416. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  417. * See the License for the specific language governing permissions and
  418. * limitations under the License.
  419. * =============================================================================
  420. */var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})};Object.defineProperty(e,"__esModule",{value:!0});const i=n(154),a=n(37),o=n(118),s=n(59),u=n(119);function c(t){let e;if(Array.isArray(t.outputShape[0])){e=`[${t.outputShape.map(t=>l(t)).join(", ")}]`}else e=l(t.outputShape);return{name:t.name,trainable:t.trainable,parameters:t.countParams(),outputShape:e}}function l(t){const e=t.slice();return 0===e.length?"Scalar":(null===e[0]&&(e[0]="batch"),`[${e.join(",")}]`)}e.modelSummary=function(t,e){return r(this,void 0,void 0,function*(){const n=a.getDrawArea(t),r=function(t){return{layers:t.layers.map(c)}}(e).layers.map(t=>[t.name,t.outputShape,t.parameters,t.trainable]);o.table(n,{headers:["Layer Name","Output Shape","# Of Params","Trainable"],values:r})})},e.layer=function(t,e){return r(this,void 0,void 0,function*(){const n=a.getDrawArea(t),c=yield function(t){return r(this,void 0,void 0,function*(){const e=t.getWeights(),n=t.weights,r=e.map(u.tensorStats),i=yield Promise.all(r),a=e.map(t=>t.shape);return e.map((t,e)=>({name:n[e].name,stats:i[e],shape:l(a[e]),weight:t}))})}(e),f=s.subSurface(n,"layer-weights-info"),d=c.map(t=>[t.name,t.shape,t.stats.min,t.stats.max,t.weight.size,t.stats.numZeros,t.stats.numNans,t.stats.numInfs]);o.table(f,{headers:["Weight Name","Shape","Min","Max","# Params","# Zeros","# NaNs","# Infinity"],values:d});const h=s.subSurface(n,"select-layer"),p=s.subSurface(n,"param-distribution");!function(t,e,n){const r=`<div><button>Show Values Distribution for:</button>${`\n <select>\n ${t.map(t=>`<option value=${t}>${t}</option>`)}\n </select>\n `}</div>`;e.innerHTML=r;const i=e.querySelector("button"),a=e.querySelector("select");i.addEventListener("click",()=>{n(a.selectedOptions[0].label)})}(c.map(t=>t.name),h,t=>r(this,void 0,void 0,function*(){const e=yield c.filter(e=>e.name===t)[0].weight.data();i.histogram(p,e,{height:150,width:460,stats:!1})}))})}},function(t,e,n){"use strict";
  421. /**
  422. * @license
  423. * Copyright 2018 Google LLC. All Rights Reserved.
  424. * Licensed under the Apache License, Version 2.0 (the "License");
  425. * you may not use this file except in compliance with the License.
  426. * You may obtain a copy of the License at
  427. *
  428. * http://www.apache.org/licenses/LICENSE-2.0
  429. *
  430. * Unless required by applicable law or agreed to in writing, software
  431. * distributed under the License is distributed on an "AS IS" BASIS,
  432. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  433. * See the License for the specific language governing permissions and
  434. * limitations under the License.
  435. * =============================================================================
  436. */var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})};Object.defineProperty(e,"__esModule",{value:!0});const i=n(235),a=n(37),o=n(59);function s(t,e,n,s={}){return r(this,void 0,void 0,function*(){const r=a.getDrawArea(t),l={};for(const t of n)if(/val_/.test(t)){const r=t.replace("val_","");u(l,r);const i=c(e,t,n.indexOf(t));l[r].series.push(t),l[r].values.push(i)}else{const r=c(e,t,n.indexOf(t));u(l,t),l[t].series.push(t),l[t].values.push(r)}const f=Object.keys(l),d=Object.assign({},{xLabel:"Iteration",yLabel:"Value"},s),h=[];for(const t of f){const e=o.subSurface(r,t),n=l[t].series,a=l[t].values;n.every(t=>Boolean(t.match("acc")))&&(d.zoomToFitAccuracy?d.zoomToFit=!0:(d.yAxisDomain=[0,1],delete d.zoomToFit));const s=i.linechart(e,{values:a,series:n},d);h.push(s)}yield Promise.all(h)})}function u(t,e){null==t[e]&&(t[e]={series:[],values:[]})}function c(t,e,n){if(Array.isArray(t)){const r=Array.isArray(t[0])?t[n]:t,i=[];for(let t=0;t<r.length;t++){const n=r[t];i.push({x:t,y:n[e]})}return i}return t.history[e].map((t,e)=>({x:e,y:t}))}function l(t,e,n){return null==t[e]&&(t[e]={}),null==t[e][n]&&(t[e][n]=[]),t[e][n]}e.history=s,e.fitCallbacks=function(t,e,n={}){const i={},u=n.callbacks||["onEpochEnd","onBatchEnd"],c=a.getDrawArea(t),f=Object.assign({},n);delete f.callbacks;const d={};return u.forEach(t=>{d[t]=function(t){return(n,u)=>r(this,void 0,void 0,function*(){/batch/i.test(t)?f.xLabel="Batch":/epoch/i.test(t)&&(f.xLabel="Epoch");const n=[],r=[];for(const a of e)if(null!=u[a]){r.push(a);const e=l(i,t,a);e.push({[a]:u[a]}),n.push(e)}s(o.subSurface(c,t,{title:t}),n,r,f),yield a.nextFrame()})}(t)}),d}},function(t,e,n){"use strict";
  437. /**
  438. * @license
  439. * Copyright 2018 Google LLC. All Rights Reserved.
  440. * Licensed under the Apache License, Version 2.0 (the "License");
  441. * you may not use this file except in compliance with the License.
  442. * You may obtain a copy of the License at
  443. *
  444. * http://www.apache.org/licenses/LICENSE-2.0
  445. *
  446. * Unless required by applicable law or agreed to in writing, software
  447. * distributed under the License is distributed on an "AS IS" BASIS,
  448. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  449. * See the License for the specific language governing permissions and
  450. * limitations under the License.
  451. * =============================================================================
  452. */var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})},i=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const a=i(n(82)),o=n(59),s=n(120),u=n(37);e.scatterplot=function(t,e,n={}){return r(this,void 0,void 0,function*(){let r=e.values;const i=null==e.series?[]:e.series,l=[];(r=Array.isArray(r[0])?r:[r]).forEach((t,e)=>{const n=null!=i[e]?i[e]:`Series ${e+1}`,r=t.map(t=>Object.assign({},t,{series:n}));l.push(...r)}),null!=n.seriesColors&&s.assert(n.seriesColors.length===r.length,"Must have an equal number of series colors as there are data series");const f=u.getDrawArea(t),d=Object.assign({},c,n),h={width:d.width||o.getDefaultWidth(f),height:d.height||o.getDefaultHeight(f),padding:0,autosize:{type:"fit",contains:"padding",resize:!0},config:{axis:{labelFontSize:d.fontSize,titleFontSize:d.fontSize},text:{fontSize:d.fontSize},legend:{labelFontSize:d.fontSize,titleFontSize:d.fontSize}},data:{values:l},mark:{type:"point",clip:!0,tooltip:{content:"data"}},encoding:{x:{field:"x",type:d.xType,title:d.xLabel,scale:d.zoomToFit?{zero:!1}:null!=d.xAxisDomain?{domain:d.xAxisDomain}:void 0},y:{field:"y",type:d.yType,title:d.yLabel,scale:d.zoomToFit?{zero:!1}:null!=d.yAxisDomain?{domain:d.yAxisDomain}:void 0},color:{field:"series",type:"nominal",scale:{range:d.seriesColors}},shape:{field:"series",type:"nominal"}}};return yield a.default(f,h,{actions:!1,mode:"vega-lite",defaultStyle:!1}),Promise.resolve()})};const c={xLabel:"x",yLabel:"y",xType:"quantitative",yType:"quantitative",zoomToFit:!1,fontSize:11}},function(t,e,n){"use strict";
  453. /**
  454. * @license
  455. * Copyright 2018 Google LLC. All Rights Reserved.
  456. * Licensed under the Apache License, Version 2.0 (the "License");
  457. * you may not use this file except in compliance with the License.
  458. * You may obtain a copy of the License at
  459. *
  460. * http://www.apache.org/licenses/LICENSE-2.0
  461. *
  462. * Unless required by applicable law or agreed to in writing, software
  463. * distributed under the License is distributed on an "AS IS" BASIS,
  464. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  465. * See the License for the specific language governing permissions and
  466. * limitations under the License.
  467. * =============================================================================
  468. */var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})},i=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e},a=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const o=i(n(4)),s=a(n(82)),u=n(59),c=n(120),l=n(37);function f(t,e,n){const r=t instanceof o.Tensor?t.shape:[t.length,t[0].length];0===n?c.assert(r[0]===e.length,`Length of xTickLabels (${e.length}) must match number of rows`+` (${r[0]})`):1===n&&c.assert(r[1]===e.length,`Length of yTickLabels (${e.length}) must match number of columns (${r[1]})`)}e.heatmap=function(t,e,n={}){return r(this,void 0,void 0,function*(){const i=Object.assign({},d,n),a=l.getDrawArea(t);let h=e.values;i.rowMajor&&(h=yield function(t){return r(this,void 0,void 0,function*(){let e,n;t instanceof o.Tensor?(e=t.shape,n=t.transpose()):(e=[t.length,t[0].length],n=o.tidy(()=>o.tensor2d(t).transpose())),c.assert(2===n.rank,"Input to renderHeatmap must be a 2d array or Tensor2d");const r=yield n.array();n.dispose();const i=[r.length,r[0].length];return c.assert(e[0]===i[1]&&e[1]===i[0],`Unexpected transposed shape. Original ${e} : Transposed ${i}`),r})}(e.values));const{xTickLabels:p,yTickLabels:m}=e;null!=p&&f(h,p,0),null!=m&&f(h,m,1);const g=[];if(h instanceof o.Tensor){c.assert(2===h.rank,"Input to renderHeatmap must be a 2d array or Tensor2d");const t=yield h.data(),[e,n]=h.shape;for(let r=0;r<e;r++){const e=p?`${p[r]}@tfidx@${r}`:r;for(let i=0;i<n;i++){const a=m?`${m[i]}@tfidx@${i}`:i,o=t[r*n+i];g.push({x:e,y:a,value:o})}}}else{const t=h;for(let e=0;e<t.length;e++){const n=p?`${p[e]}@tfidx@${e}`:e;for(let r=0;r<t[e].length;r++){const i=m?`${m[r]}@tfidx@${r}`:r,a=t[e][r];g.push({x:n,y:i,value:a})}}}const v={actions:!1,mode:"vega-lite",defaultStyle:!1},y={width:i.width||u.getDefaultWidth(a),height:i.height||u.getDefaultHeight(a),padding:0,autosize:{type:"fit",contains:"padding",resize:!0},config:{axis:{labelFontSize:i.fontSize,titleFontSize:i.fontSize},text:{fontSize:i.fontSize},legend:{labelFontSize:i.fontSize,titleFontSize:i.fontSize},scale:{bandPaddingInner:0,bandPaddingOuter:0}},data:{values:g},mark:{type:"rect",tooltip:!0},encoding:{x:{field:"x",type:i.xType,title:i.xLabel,sort:"x"},y:{field:"y",type:i.yType,title:i.yLabel,sort:"y"},fill:{field:"value",type:"quantitative"}}},b=new RegExp("@tfidx@\\d+$");let x;switch(p&&(y.encoding.x.axis={labelExpr:"replace(datum.value, regexp(/@tfidx@\\d+$/), '')"}),m&&(y.encoding.y.axis={labelExpr:"replace(datum.value, regexp(/@tfidx@\\d+$/), '')"}),(p||m)&&(v.tooltip={sanitize:t=>String(t).replace(b,"")}),i.colorMap){case"blues":x=["#f7fbff","#4292c6"];break;case"greyscale":x=["#000000","#ffffff"];break;case"viridis":default:x="viridis"}if("viridis"!==x&&(y.encoding.fill.scale={range:x}),i.domain){const t=y.encoding.fill;null!=t.scale?t.scale=Object.assign({},t.scale,{domain:i.domain}):t.scale={domain:i.domain}}yield s.default(a,y,v)})};const d={xLabel:null,yLabel:null,xType:"ordinal",yType:"ordinal",colorMap:"viridis",fontSize:12,domain:null,rowMajor:!1}},function(t,e,n){"use strict";
  469. /**
  470. * @license
  471. * Copyright 2018 Google LLC. All Rights Reserved.
  472. * Licensed under the Apache License, Version 2.0 (the "License");
  473. * you may not use this file except in compliance with the License.
  474. * You may obtain a copy of the License at
  475. *
  476. * http://www.apache.org/licenses/LICENSE-2.0
  477. *
  478. * Unless required by applicable law or agreed to in writing, software
  479. * distributed under the License is distributed on an "AS IS" BASIS,
  480. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  481. * See the License for the specific language governing permissions and
  482. * limitations under the License.
  483. * =============================================================================
  484. */var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})},i=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const a=i(n(82)),o=n(59),s=n(37);e.confusionMatrix=function(t,e,n={}){return r(this,void 0,void 0,function*(){const r=Object.assign({},u,n),i=s.getDrawArea(t),c=[],l=e.values,f=e.tickLabels||[],d=0===f.length;let h=!0;for(let t=0;t<l.length;t++){const e=d?`Class ${t}`:f[t];d&&f.push(e);for(let n=0;n<l[t].length;n++){const i=d?`Class ${n}`:f[n],a=l[t][n];t!==n||r.shadeDiagonal?(c.push({label:e,prediction:i,count:a,scaleCount:a}),0!==a&&(h=!1)):c.push({label:e,prediction:i,count:a,noFill:!0})}}if(!r.shadeDiagonal&&h)for(const t of c)!0===t.noFill&&(t.noFill=!1,t.scaleCount=t.count);const p={width:r.width||o.getDefaultWidth(i),height:r.height||o.getDefaultHeight(i),padding:0,autosize:{type:"fit",contains:"padding",resize:!0},config:{axis:{labelFontSize:r.fontSize,titleFontSize:r.fontSize},text:{fontSize:r.fontSize},legend:{labelFontSize:r.fontSize,titleFontSize:r.fontSize}},data:{values:c},encoding:{x:{field:"prediction",type:"ordinal",title:r.xLabel||"prediction",scale:{domain:f}},y:{field:"label",type:"ordinal",title:r.yLabel||"label",scale:{domain:f}}},layer:[{transform:[{filter:"datum.noFill != true"}],mark:{type:"rect"},encoding:{color:{field:"scaleCount",type:"quantitative",scale:{range:r.colorMap}},tooltip:[{field:"label",type:"nominal"},{field:"prediction",type:"nominal"},{field:"count",type:"quantitative"}]}}]};!1===r.shadeDiagonal&&p.layer.push({transform:[{filter:"datum.noFill == true"}],mark:{type:"rect",fill:"white"},encoding:{tooltip:[{field:"label",type:"nominal"},{field:"prediction",type:"nominal"},{field:"count",type:"quantitative"}]}}),r.showTextOverlay&&p.layer.push({mark:{type:"text",baseline:"middle"},encoding:{text:{field:"count",type:"nominal"}}});const m="string"==typeof r.colorMap?{scheme:r.colorMap}:r.colorMap;p.layer[0].encoding.color.scale.range=m,yield a.default(i,p,{actions:!1,mode:"vega-lite",defaultStyle:!1})})};const u={xLabel:null,yLabel:null,xType:"nominal",yType:"nominal",shadeDiagonal:!0,fontSize:12,showTextOverlay:!0,height:400,colorMap:["#f7fbff","#4292c6"]}},function(t,e,n){"use strict";
  485. /**
  486. * @license
  487. * Copyright 2018 Google LLC. All Rights Reserved.
  488. * Licensed under the Apache License, Version 2.0 (the "License");
  489. * you may not use this file except in compliance with the License.
  490. * You may obtain a copy of the License at
  491. *
  492. * http://www.apache.org/licenses/LICENSE-2.0
  493. *
  494. * Unless required by applicable law or agreed to in writing, software
  495. * distributed under the License is distributed on an "AS IS" BASIS,
  496. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  497. * See the License for the specific language governing permissions and
  498. * limitations under the License.
  499. * =============================================================================
  500. */Object.defineProperty(e,"__esModule",{value:!0});const r=n(155),i=n(104);e.Tabs=class extends r.Component{render(){const{tabNames:t,activeTab:e,handleClick:n}=this.props,o=t.length>0?t.map(t=>r.h(a,{key:t,id:t,handleClick:n,isActive:t===e},t)):null,s=i.css({overflowX:"scroll",overflowY:"hidden",whiteSpace:"nowrap",borderBottomStyle:"solid",borderBottomWidth:"1px",borderColor:"#eee",paddingBottom:"1rem",marginTop:"1rem"});return r.h("div",{className:`${s} visor-tabs`},o)}};class a extends r.Component{render(){const{children:t,isActive:e,handleClick:n,id:a}=this.props,o=i.css({borderBottomColor:e?"#357EDD":"#AAAAAA",borderBottomWidth:"1px",borderBottomStyle:"solid",cursor:"pointer",":hover":{color:"#357EDD"},display:"inline-block",marginRight:"1rem",padding:".5rem",fontSize:"1rem",fontWeight:"bold"});return r.h("a",{className:`${o} tf-tab`,"data-isactive":e,onClick:()=>n(a)},t)}}},function(t,e,n){"use strict";
  501. /**
  502. * @license
  503. * Copyright 2018 Google LLC. All Rights Reserved.
  504. * Licensed under the Apache License, Version 2.0 (the "License");
  505. * you may not use this file except in compliance with the License.
  506. * You may obtain a copy of the License at
  507. *
  508. * http://www.apache.org/licenses/LICENSE-2.0
  509. *
  510. * Unless required by applicable law or agreed to in writing, software
  511. * distributed under the License is distributed on an "AS IS" BASIS,
  512. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  513. * See the License for the specific language governing permissions and
  514. * limitations under the License.
  515. * =============================================================================
  516. */Object.defineProperty(e,"__esModule",{value:!0});const r=n(155),i=n(104);class a extends r.Component{componentDidMount(){const{name:t,tab:e}=this.props;this.props.registerSurface(t,e,this)}componentDidUpdate(){return!1}render(){const{name:t,visible:e,styles:n}=this.props,o=Object.assign({},a.defaultStyles,n),{width:s,height:u}=o;let{maxHeight:c,maxWidth:l}=o;c=u===a.defaultStyles.height?c:u,l=s===a.defaultStyles.width?l:s;const f=i.css({display:e?"block":"none",backgroundColor:"white",marginTop:"10px",marginBottom:"10px",boxShadow:"0 0 6px -3px #777",padding:"10px !important",height:u,width:s,maxHeight:c,maxWidth:l,overflow:"auto"}),d=i.css({backgroundColor:"white",boxSizing:"border-box",borderBottom:"1px solid #357EDD",lineHeight:"2em",marginBottom:"20px",fontWeight:"600",textAlign:"center"}),h=i.css({boxSizing:"border-box"});return r.h("div",{className:`${f} tf-surface`,ref:t=>this.container=t,"data-visible":e},r.h("div",{className:`${d} tf-label`,ref:t=>this.label=t},t),r.h("div",{className:`${h} tf-draw-area`,ref:t=>this.drawArea=t}))}}a.defaultStyles={maxWidth:"550px",maxHeight:"580px",height:"auto",width:"auto"},e.SurfaceComponent=a},function(t,e,n){"use strict";
  517. /**
  518. * @license
  519. * Copyright 2018 Google LLC. All Rights Reserved.
  520. * Licensed under the Apache License, Version 2.0 (the "License");
  521. * you may not use this file except in compliance with the License.
  522. * You may obtain a copy of the License at
  523. *
  524. * http://www.apache.org/licenses/LICENSE-2.0
  525. *
  526. * Unless required by applicable law or agreed to in writing, software
  527. * distributed under the License is distributed on an "AS IS" BASIS,
  528. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  529. * See the License for the specific language governing permissions and
  530. * limitations under the License.
  531. * =============================================================================
  532. */Object.defineProperty(e,"__esModule",{value:!0});const r=n(155),i=n(104),a=n(438),o=n(437);class s extends r.Component{static render(t,e,n){return r.render(r.h(s,Object.assign({},n)),t,e)}constructor(t){super(t),this.surfaces=new Map;const e=null==t.startOpen||t.startOpen;this.state={isOpen:e,isFullscreen:!1,activeTab:null,tabs:new Set},this.keyHandler=this.keyHandler.bind(this)}close(){this.setState({isOpen:!1})}open(){this.setState({isOpen:!0})}toggle(){this.setState({isOpen:!this.state.isOpen})}toggleFullScreen(){this.setState({isFullscreen:!this.state.isFullscreen})}isOpen(){return this.state.isOpen}isFullscreen(){return this.state.isFullscreen}getSurface(t,e){const n=this.surfaceId(t,e);let r;if(!this.surfaces.has(n))throw Error(`Surface not found with id: ${n}`);return{container:(r=this.surfaces.get(n)).container,label:r.label,drawArea:r.drawArea}}bindKeys(){document.addEventListener("keydown",this.keyHandler,!1)}unbindKeys(){document.removeEventListener("keydown",this.keyHandler)}surfaceId(t,e){return t+e}setTabs(t){const e=t.map(t=>t.tab),n=this.state.tabs;let r;for(const t of e)n.has(t)||(n.add(t),r=t);null!=r&&this.setState({tabs:n,activeTab:r})}getTabs(){return this.state.tabs}registerSurface(t,e,n){const r=this.surfaceId(t,e);this.surfaces.set(r,n)}keyHandler(t){192===t.keyCode&&(t.shiftKey?this.toggleFullScreen():this.toggle())}setActiveTab(t){this.setState({activeTab:t})}componentDidMount(){this.bindKeys()}componentWillMount(){this.setTabs(this.props.surfaceList)}componentWillReceiveProps(t){this.setTabs(t.surfaceList)}render(){const{isOpen:t,isFullscreen:e,activeTab:n}=this.state,{surfaceList:s}=this.props,c=Array.from(this.getTabs().values()),l=e?"90vw":"550px",f=i.css({width:l,height:"100%",backgroundColor:"#fafafa",boxSizing:"border-box",padding:"10px",position:"fixed",top:"0px",transition:"right 0.5s cubic-bezier(0.645, 0.045, 0.355, 1), width 0.5s cubic-bezier(0.645, 0.045, 0.355, 1)",boxShadow:"0 2px 5px rgba(0, 0, 0, 0.12), 0 2px 5px rgba(0, 0, 0, 0.24)",overflow:"auto",fontFamily:"sans-serif",fontSize:"14px",zIndex:1e3}),d=i.css({right:"0"}),h=i.css({right:`calc(-${l} - 10px)`}),p=t?d:h,m=i.css({});return r.h("div",{className:`${f} ${p} visor`,"data-isopen":t,"data-isfullscreen":e},r.h(u,{fullScreenHandler:this.toggleFullScreen.bind(this),closeHandler:this.close.bind(this),isFullScreen:e}),r.h(o.Tabs,{tabNames:c,activeTab:n,handleClick:this.setActiveTab.bind(this)}),r.h("div",{className:`${m} visor-surfaces`},s.map(t=>r.h(a.SurfaceComponent,{key:t.name+t.tab,name:t.name,tab:t.tab,styles:t.styles,registerSurface:this.registerSurface.bind(this),visible:n===t.tab}))))}}function u(t){const{isFullScreen:e,fullScreenHandler:n,closeHandler:a}=t,o=i.css({display:"flex",backgroundColor:"white",border:"1px solid white",padding:"6px",paddingTop:"10px",marginBottom:"10px",borderRadius:"6px",marginTop:"-16px"}),s=i.css({fontSize:".875rem",borderRadius:".25rem",paddingLeft:"1rem",paddingRight:"1rem",paddingTop:".5rem",paddingBottom:".5rem",textDecoration:"none",transition:"color .15s ease-in",color:"#111"}),u=i.css({marginLeft:"auto"});return r.h("div",{className:`${o} visor-controls`},r.h("button",{className:`${s}`,onClick:n},e?"Minimize":"Maximize"),r.h("button",{className:`${s} ${u}`,onClick:a},"Hide"))}e.VisorComponent=s},function(t,e,n){"use strict";function r(t,e){return t.charCodeAt(e++)+(t.charCodeAt(e++)<<8)+(t.charCodeAt(e++)<<16)+(t.charCodeAt(e)<<24)}function i(t,e){return t.charCodeAt(e++)+(t.charCodeAt(e++)<<8)}function a(t,e){return(65535&(t|=0))*(e|=0)+(((t>>>16)*e&65535)<<16)|0}Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){var n=1540483477,o=e^t.length,s=t.length,u=0;for(;s>=4;){var c=r(t,u);c=a(c,n),c=a(c^=c>>>24,n),o=a(o,n),o^=c,u+=4,s-=4}switch(s){case 3:o^=i(t,u),o=a(o^=t.charCodeAt(u+2)<<16,n);break;case 2:o=a(o^=i(t,u),n);break;case 1:o=a(o^=t.charCodeAt(u),n)}return o=a(o^=o>>>13,n),(o^=o>>>15)>>>0}},function(t,e,n){"use strict";n.r(e);var r=/[A-Z]/g,i=/^ms-/,a={};function o(t){return"-"+t.toLowerCase()}e.default=function(t){if(a.hasOwnProperty(t))return a[t];var e=t.replace(r,o);return a[t]=i.test(e)?"-"+e:e}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){return(0,r.default)(t)};var r=function(t){return t&&t.__esModule?t:{default:t}}(n(441));t.exports=e.default},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e,n,o){if("string"==typeof e&&s.hasOwnProperty(t)){var c=function(t,e){if((0,i.default)(t))return t;for(var n=t.split(/,(?![^()]*(?:\([^()]*\))?\))/g),a=0,o=n.length;a<o;++a){var s=n[a],c=[s];for(var l in e){var f=(0,r.default)(l);if(s.indexOf(f)>-1&&"order"!==f)for(var d=e[l],h=0,p=d.length;h<p;++h)c.unshift(s.replace(f,u[d[h]]+f))}n[a]=c.join(",")}return n.join(",")}(e,o),l=c.split(/,(?![^()]*(?:\([^()]*\))?\))/g).filter(function(t){return!/-moz-|-ms-/.test(t)}).join(",");if(t.indexOf("Webkit")>-1)return l;var f=c.split(/,(?![^()]*(?:\([^()]*\))?\))/g).filter(function(t){return!/-webkit-|-ms-/.test(t)}).join(",");return t.indexOf("Moz")>-1?f:(n["Webkit"+(0,a.default)(t)]=l,n["Moz"+(0,a.default)(t)]=f,c)}};var r=o(n(442)),i=o(n(103)),a=o(n(238));function o(t){return t&&t.__esModule?t:{default:t}}var s={transition:!0,transitionProperty:!0,WebkitTransition:!0,WebkitTransitionProperty:!0,MozTransition:!0,MozTransitionProperty:!0},u={Webkit:"-webkit-",Moz:"-moz-",ms:"-ms-"};t.exports=e.default},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){if(i.hasOwnProperty(t)&&a.hasOwnProperty(e))return r.map(function(t){return t+e})};var r=["-webkit-","-moz-",""],i={maxHeight:!0,maxWidth:!0,width:!0,height:!0,columnWidth:!0,minWidth:!0,minHeight:!0},a={"min-content":!0,"max-content":!0,"fill-available":!0,"fit-content":!0,"contain-floats":!0};t.exports=e.default},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){if("position"===t&&"sticky"===e)return["-webkit-sticky","sticky"]},t.exports=e.default},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){if("string"==typeof e&&!(0,r.default)(e)&&e.indexOf("image-set(")>-1)return i.map(function(t){return e.replace(/image-set\(/g,t+"image-set(")})};var r=function(t){return t&&t.__esModule?t:{default:t}}(n(103));var i=["-webkit-",""];t.exports=e.default},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){if("string"==typeof e&&!(0,r.default)(e)&&a.test(e))return i.map(function(t){return t+e})};var r=function(t){return t&&t.__esModule?t:{default:t}}(n(103));var i=["-webkit-","-moz-",""],a=/linear-gradient|radial-gradient|repeating-linear-gradient|repeating-radial-gradient/;t.exports=e.default},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e,n){"flexDirection"===t&&"string"==typeof e&&(e.indexOf("column")>-1?n.WebkitBoxOrient="vertical":n.WebkitBoxOrient="horizontal",e.indexOf("reverse")>-1?n.WebkitBoxDirection="reverse":n.WebkitBoxDirection="normal");i.hasOwnProperty(t)&&(n[i[t]]=r[e]||e)};var r={"space-around":"justify","space-between":"justify","flex-start":"start","flex-end":"end","wrap-reverse":"multiple",wrap:"multiple"},i={alignItems:"WebkitBoxAlign",justifyContent:"WebkitBoxPack",flexWrap:"WebkitBoxLines"};t.exports=e.default},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){if("display"===t&&r.hasOwnProperty(e))return r[e]};var r={flex:["-webkit-box","-moz-box","-ms-flexbox","-webkit-flex","flex"],"inline-flex":["-webkit-inline-box","-moz-inline-box","-ms-inline-flexbox","-webkit-inline-flex","inline-flex"]};t.exports=e.default},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){if("string"==typeof e&&!(0,r.default)(e)&&e.indexOf("filter(")>-1)return i.map(function(t){return e.replace(/filter\(/g,t+"filter(")})};var r=function(t){return t&&t.__esModule?t:{default:t}}(n(103));var i=["-webkit-",""];t.exports=e.default},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){if("string"==typeof e&&!(0,r.default)(e)&&e.indexOf("cross-fade(")>-1)return i.map(function(t){return e.replace(/cross-fade\(/g,t+"cross-fade(")})};var r=function(t){return t&&t.__esModule?t:{default:t}}(n(103));var i=["-webkit-",""];t.exports=e.default},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){if("cursor"===t&&i.hasOwnProperty(e))return r.map(function(t){return t+e})};var r=["-webkit-","-moz-",""],i={"zoom-in":!0,"zoom-out":!0,grab:!0,grabbing:!0};t.exports=e.default},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e,n,r,i){for(var a=0,o=t.length;a<o;++a){var s=t[a](e,n,r,i);if(s)return s}},t.exports=e.default},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e,n){if(t.hasOwnProperty(e))for(var i=t[e],a=0,o=i.length;a<o;++a)n[i[a]+(0,r.default)(e)]=n[e]};var r=function(t){return t&&t.__esModule?t:{default:t}}(n(238));t.exports=e.default},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=["Webkit"],i=["Moz"],a=["ms"],o=["Webkit","Moz"],s=["Webkit","ms"],u=["Webkit","Moz","ms"];e.default={plugins:[],prefixMap:{appearance:o,userSelect:u,textEmphasisPosition:r,textEmphasis:r,textEmphasisStyle:r,textEmphasisColor:r,boxDecorationBreak:r,clipPath:r,maskImage:r,maskMode:r,maskRepeat:r,maskPosition:r,maskClip:r,maskOrigin:r,maskSize:r,maskComposite:r,mask:r,maskBorderSource:r,maskBorderMode:r,maskBorderSlice:r,maskBorderWidth:r,maskBorderOutset:r,maskBorderRepeat:r,maskBorder:r,maskType:r,textDecorationStyle:r,textDecorationSkip:r,textDecorationLine:r,textDecorationColor:r,filter:r,fontFeatureSettings:r,breakAfter:u,breakBefore:u,breakInside:u,columnCount:o,columnFill:o,columnGap:o,columnRule:o,columnRuleColor:o,columnRuleStyle:o,columnRuleWidth:o,columns:o,columnSpan:o,columnWidth:o,writingMode:s,flex:r,flexBasis:r,flexDirection:r,flexGrow:r,flexFlow:r,flexShrink:r,flexWrap:r,alignContent:r,alignItems:r,alignSelf:r,justifyContent:r,order:r,transform:r,transformOrigin:r,transformOriginX:r,transformOriginY:r,backfaceVisibility:r,perspective:r,perspectiveOrigin:r,transformStyle:r,transformOriginZ:r,animation:r,animationDelay:r,animationDirection:r,animationFillMode:r,animationDuration:r,animationIterationCount:r,animationName:r,animationPlayState:r,animationTimingFunction:r,backdropFilter:r,fontKerning:r,scrollSnapType:s,scrollSnapPointsX:s,scrollSnapPointsY:s,scrollSnapDestination:s,scrollSnapCoordinate:s,shapeImageThreshold:r,shapeImageMargin:r,shapeImageOutside:r,hyphens:u,flowInto:s,flowFrom:s,regionFragment:s,textAlignLast:i,tabSize:i,wrapFlow:a,wrapThrough:a,wrapMargin:a,gridTemplateColumns:a,gridTemplateRows:a,gridTemplateAreas:a,gridTemplate:a,gridAutoColumns:a,gridAutoRows:a,gridAutoFlow:a,grid:a,gridRowStart:a,gridColumnStart:a,gridRowEnd:a,gridRow:a,gridColumn:a,gridColumnEnd:a,gridColumnGap:a,gridRowGap:a,gridArea:a,gridGap:a,textSizeAdjust:s,borderImage:r,borderImageOutset:r,borderImageRepeat:r,borderImageSlice:r,borderImageSource:r,borderImageWidth:r,transitionDelay:r,transitionDuration:r,transitionProperty:r,transitionTimingFunction:r}},t.exports=e.default},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){for(var e in t){var n=t[e],r=(0,a.default)(v,e,n,t,y);r&&(t[e]=r),(0,i.default)(y,e,t)}return t};var r=g(n(455)),i=g(n(454)),a=g(n(453)),o=g(n(452)),s=g(n(451)),u=g(n(450)),c=g(n(449)),l=g(n(448)),f=g(n(447)),d=g(n(446)),h=g(n(445)),p=g(n(444)),m=g(n(443));function g(t){return t&&t.__esModule?t:{default:t}}var v=[s.default,o.default,u.default,l.default,f.default,d.default,h.default,p.default,m.default,c.default],y=r.default.prefixMap},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t};e.PluginSet=u,e.fallbacks=function(t){if(Object.keys(t.style).map(function(e){return Array.isArray(t.style[e])}).indexOf(!0)>=0){var e=t.style,n=Object.keys(e).reduce(function(t,n){return t[n]=Array.isArray(e[n])?e[n].join("; "+(0,a.processStyleName)(n)+": "):e[n],t},{});return(0,i.default)({},t,{style:n})}return t},e.contentWrap=function(t){if(t.style.content){var e=t.style.content;return c.indexOf(e)>=0?t:/^(attr|calc|counters?|url)\(/.test(e)?t:e.charAt(0)!==e.charAt(e.length-1)||'"'!==e.charAt(0)&&"'"!==e.charAt(0)?r({},t,{style:r({},t.style,{content:'"'+e+'"'})}):t}return t},e.prefixes=function(t){return(0,i.default)({},t,{style:(0,o.default)(r({},t.style))})};var i=s(n(156)),a=n(240),o=s(n(456));function s(t){return t&&t.__esModule?t:{default:t}}function u(t){this.fns=t||[]}(0,i.default)(u.prototype,{add:function(){for(var t=this,e=arguments.length,n=Array(e),r=0;r<e;r++)n[r]=arguments[r];n.forEach(function(e){t.fns.indexOf(e)>=0||(t.fns=[e].concat(t.fns))})},remove:function(t){this.fns=this.fns.filter(function(e){return e!==t})},clear:function(){this.fns=[]},transform:function(t){return this.fns.reduce(function(t,e){return e(t)},t)}});var c=["normal","none","counter","open-quote","close-quote","no-open-quote","no-close-quote","initial","inherit"]},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};function i(t){if(function(t){return null===t||void 0===t||!1===t||"object"===(void 0===t?"undefined":r(t))&&0===Object.keys(t).length}(t))return null;if("object"!==(void 0===t?"undefined":r(t)))return t;for(var e={},n=Object.keys(t),i=!1,o=0;o<n.length;o++){var s=t[n[o]],u=a(s);null!==u&&u===s||(i=!0),null!==u&&(e[n[o]]=u)}return 0===Object.keys(e).length?null:i?e:t}function a(t){return Array.isArray(t)?function(t){var e=!1,n=[];return t.forEach(function(t){var r=a(t);null!==r&&r===t||(e=!0),null!==r&&n.push(r)}),0==n.length?null:e?n:t}(t):i(t)}e.default=a},function(t,e,n){"use strict";t.exports=function(t){var e={};return function(n){return e.hasOwnProperty(n)||(e[n]=t.call(this,n)),e[n]}}},function(t,e,n){"use strict";var r=/([A-Z])/g;t.exports=function(t){return t.replace(r,"-$1").toLowerCase()}},function(t,e,n){"use strict";var r=n(460),i=/^ms-/;t.exports=function(t){return r(t).replace(i,"-ms-")}},function(t,e,n){"use strict";function r(t){return function(){return t}}var i=function(){};i.thatReturns=r,i.thatReturnsFalse=r(!1),i.thatReturnsTrue=r(!0),i.thatReturnsNull=r(null),i.thatReturnsThis=function(){return this},i.thatReturnsArgument=function(t){return t},t.exports=i},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r={animationIterationCount:!0,borderImageOutset:!0,borderImageSlice:!0,borderImageWidth:!0,boxFlex:!0,boxFlexGroup:!0,boxOrdinalGroup:!0,columnCount:!0,flex:!0,flexGrow:!0,flexPositive:!0,flexShrink:!0,flexNegative:!0,flexOrder:!0,gridRow:!0,gridRowStart:!0,gridRowEnd:!0,gridColumn:!0,gridColumnStart:!0,gridColumnEnd:!0,fontWeight:!0,lineClamp:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,tabSize:!0,widows:!0,zIndex:!0,zoom:!0,fillOpacity:!0,floodOpacity:!0,stopOpacity:!0,strokeDasharray:!0,strokeDashoffset:!0,strokeMiterlimit:!0,strokeOpacity:!0,strokeWidth:!0};var i=["Webkit","ms","Moz","O"];Object.keys(r).forEach(function(t){i.forEach(function(e){r[function(t,e){return t+e.charAt(0).toUpperCase()+e.substring(1)}(e,t)]=r[t]})});var a={isUnitlessNumber:r,shorthandPropertyExpansions:{background:{backgroundAttachment:!0,backgroundColor:!0,backgroundImage:!0,backgroundPositionX:!0,backgroundPositionY:!0,backgroundRepeat:!0},backgroundPosition:{backgroundPositionX:!0,backgroundPositionY:!0},border:{borderWidth:!0,borderStyle:!0,borderColor:!0},borderBottom:{borderBottomWidth:!0,borderBottomStyle:!0,borderBottomColor:!0},borderLeft:{borderLeftWidth:!0,borderLeftStyle:!0,borderLeftColor:!0},borderRight:{borderRightWidth:!0,borderRightStyle:!0,borderRightColor:!0},borderTop:{borderTopWidth:!0,borderTopStyle:!0,borderTopColor:!0},font:{fontStyle:!0,fontVariant:!0,fontWeight:!0,fontSize:!0,lineHeight:!0,fontFamily:!0},outline:{outlineWidth:!0,outlineStyle:!0,outlineColor:!0}}};e.default=a},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=i(n(463));i(n(239));function i(t){return t&&t.__esModule?t:{default:t}}var a=r.default.isUnitlessNumber;e.default=function(t,e,n){return null==e||"boolean"==typeof e||""===e?"":isNaN(e)||0===e||a.hasOwnProperty(t)&&a[t]?""+e:("string"==typeof e&&(e=e.trim()),e+"px")}},function(t,e,n){"use strict";var r=/-(.)/g;t.exports=function(t){return t.replace(r,function(t,e){return e.toUpperCase()})}},function(t,e,n){"use strict";var r=n(465),i=/^-ms-/;t.exports=function(t){return r(t.replace(i,"ms-"))}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.StyleSheet=f;var r=function(t){return t&&t.__esModule?t:{default:t}}(n(156));function i(t){return t[t.length-1]}function a(t){if(t.sheet)return t.sheet;for(var e=0;e<document.styleSheets.length;e++)if(document.styleSheets[e].ownerNode===t)return document.styleSheets[e]}var o="undefined"!=typeof window,s=!1,u=!1,c=function(){if(o){var t=document.createElement("div");return t.innerHTML="\x3c!--[if lt IE 10]><i></i><![endif]--\x3e",1===t.getElementsByTagName("i").length}}();function l(){var t=document.createElement("style");return t.type="text/css",t.setAttribute("data-glamor",""),t.appendChild(document.createTextNode("")),(document.head||document.getElementsByTagName("head")[0]).appendChild(t),t}function f(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=t.speedy,n=void 0===e?!s&&!u:e,r=t.maxLength,i=void 0===r?o&&c?4e3:65e3:r;this.isSpeedy=n,this.sheet=void 0,this.tags=[],this.maxLength=i,this.ctr=0}(0,r.default)(f.prototype,{getSheet:function(){return a(i(this.tags))},inject:function(){var t=this;if(this.injected)throw new Error("already injected stylesheet!");o?this.tags[0]=l():this.sheet={cssRules:[],insertRule:function(e){t.sheet.cssRules.push({cssText:e})}},this.injected=!0},speedy:function(t){if(0!==this.ctr)throw new Error("cannot change speedy mode after inserting any rule to sheet. Either call speedy("+t+") earlier in your app, or call flush() before speedy("+t+")");this.isSpeedy=!!t},_insert:function(t){try{var e=this.getSheet();e.insertRule(t,-1!==t.indexOf("@import")?0:e.cssRules.length)}catch(e){s&&console.warn("whoops, illegal rule inserted",t)}},insert:function(t){if(o)if(this.isSpeedy&&this.getSheet().insertRule)this._insert(t);else if(-1!==t.indexOf("@import")){var e=i(this.tags);e.insertBefore(document.createTextNode(t),e.firstChild)}else i(this.tags).appendChild(document.createTextNode(t));else this.sheet.insertRule(t,-1!==t.indexOf("@import")?0:this.sheet.cssRules.length);return this.ctr++,o&&this.ctr%this.maxLength==0&&this.tags.push(l()),this.ctr-1},delete:function(t){return this.replace(t,"")},flush:function(){o?(this.tags.forEach(function(t){return t.parentNode.removeChild(t)}),this.tags=[],this.sheet=null,this.ctr=0):this.sheet.cssRules=[],this.injected=!1},rules:function(){if(!o)return this.sheet.cssRules;var t=[];return this.tags.forEach(function(e){return t.splice.apply(t,[t.length,0].concat(function(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}(Array.from(a(e).cssRules))))}),t}})},function(t,e,n){"use strict";n.r(e);var r=n(288),i=n(null);var a=+new Date("2000-01-01T00:00:00.000Z")?function(t){var e=new Date(t);return isNaN(e)?null:e}:Object(i.e)(r.isoSpecifier);e.default=a},function(t,e,n){"use strict";n.r(e);var r=n(null);e.default=function(t,e){return t=Math.abs(t),e=Math.abs(e)-t,Math.max(0,Object(r.a)(e)-Object(r.a)(t))+1}},function(t,e,n){"use strict";n.r(e);var r=n(null);e.default=function(t,e){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(Object(r.a)(e)/3)))-Object(r.a)(Math.abs(t)))}},function(t,e,n){"use strict";n.r(e);var r=n(null);e.default=function(t){return Math.max(0,-Object(r.a)(Math.abs(t)))}},function(t,e,n){"use strict";n.r(e),n.d(e,"default",function(){return u});var r=n(null),i=n(null),a=n(null),o=n(null),s=n(null);function u(){var t=[],e=o.c;function n(n){if(!isNaN(n=+n))return e((Object(r.b)(t,n,1)-1)/(t.length-1))}return n.domain=function(e){if(!arguments.length)return t.slice();t=[];for(let n of e)null==n||isNaN(n=+n)||t.push(n);return t.sort(i.a),n},n.interpolator=function(t){return arguments.length?(e=t,n):e},n.range=function(){return t.map((n,r)=>e(r/(t.length-1)))},n.quantiles=function(e){return Array.from({length:e+1},(n,r)=>Object(a.a)(t,r/e))},n.copy=function(){return u(e).domain(t)},s.b.apply(n,arguments)}},function(t,e,n){"use strict";n.r(e),n.d(e,"default",function(){return u});var r=n(null),i=n(null),a=n(null),o=n(null);function s(t){return Math.sign(t)*t*t}function u(){var t,e=Object(r.a)(),n=[0,1],c=!1;function l(n){var r=function(t){return Math.sign(t)*Math.sqrt(Math.abs(t))}(e(n));return isNaN(r)?t:c?Math.round(r):r}return l.invert=function(t){return e.invert(s(t))},l.domain=function(t){return arguments.length?(e.domain(t),l):e.domain()},l.range=function(t){return arguments.length?(e.range((n=Array.from(t,o.a)).map(s)),l):n.slice()},l.rangeRound=function(t){return l.range(t).round(!0)},l.round=function(t){return arguments.length?(c=!!t,l):c},l.clamp=function(t){return arguments.length?(e.clamp(t),l):e.clamp()},l.unknown=function(e){return arguments.length?(t=e,l):t},l.copy=function(){return u(e.domain(),n).round(c).clamp(e.clamp()).unknown(t)},i.a.apply(l,arguments),Object(a.b)(l)}},function(t,e,n){"use strict";
  533. /**
  534. * @license
  535. * Copyright 2018 Google LLC. All Rights Reserved.
  536. * Licensed under the Apache License, Version 2.0 (the "License");
  537. * you may not use this file except in compliance with the License.
  538. * You may obtain a copy of the License at
  539. *
  540. * http://www.apache.org/licenses/LICENSE-2.0
  541. *
  542. * Unless required by applicable law or agreed to in writing, software
  543. * distributed under the License is distributed on an "AS IS" BASIS,
  544. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  545. * See the License for the specific language governing permissions and
  546. * limitations under the License.
  547. * =============================================================================
  548. */var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(i,a){function o(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(t)}}function u(t){t.done?i(t.value):new n(function(e){e(t.value)}).then(o,s)}u((r=r.apply(t,e||[])).next())})},i=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const a=i(n(82)),o=n(59),s=n(37);e.barchart=function(t,e,n={}){return r(this,void 0,void 0,function*(){const r=s.getDrawArea(t),i=e,l=Object.assign({},u,n);if(c.has(r)){const t=c.get(r);if(s.shallowEquals(l,t.lastOptions)){yield s.nextFrame();const e=t.view,n=e.changeset().remove(()=>!0).insert(i);return void(yield e.change("values",n).runAsync())}}const{xLabel:f,yLabel:d,xType:h,yType:p}=l;let m=null;null!=f&&(m={title:f});let g,v=null;null!=d&&(v={title:d}),g=null!=l.color?Array.isArray(l.color)?{field:"index",type:"nominal",scale:{range:l.color}}:{value:l.color}:{value:"#4C78A0"};const y={width:l.width||o.getDefaultWidth(r),height:l.height||o.getDefaultHeight(r),padding:0,autosize:{type:"fit",contains:"padding",resize:!0},config:{axis:{labelFontSize:l.fontSize,titleFontSize:l.fontSize},text:{fontSize:l.fontSize},legend:{labelFontSize:l.fontSize,titleFontSize:l.fontSize}},data:{values:i,name:"values"},mark:{type:"bar",tooltip:!0},encoding:{x:{field:"index",type:h,axis:m},y:{field:"value",type:p,axis:v},color:g}};yield s.nextFrame();const b=yield a.default(r,y,{actions:!1,mode:"vega-lite",defaultStyle:!1});c.set(r,{view:b.view,lastOptions:l})})};const u={xLabel:"",yLabel:"",xType:"ordinal",yType:"quantitative",fontSize:11},c=new Map},function(t,e){},function(t,e){},function(t,e){},function(t,e){},function(t,e){},function(t,e){},function(t,e,n){(function(t,e){!function(t,n){"use strict";if(!t.setImmediate){var r,i=1,a={},o=!1,s=t.document,u=Object.getPrototypeOf&&Object.getPrototypeOf(t);u=u&&u.setTimeout?u:t,"[object process]"==={}.toString.call(t.process)?r=function(t){e.nextTick(function(){l(t)})}:function(){if(t.postMessage&&!t.importScripts){var e=!0,n=t.onmessage;return t.onmessage=function(){e=!1},t.postMessage("","*"),t.onmessage=n,e}}()?function(){var e="setImmediate$"+Math.random()+"$",n=function(n){n.source===t&&"string"==typeof n.data&&0===n.data.indexOf(e)&&l(+n.data.slice(e.length))};t.addEventListener?t.addEventListener("message",n,!1):t.attachEvent("onmessage",n),r=function(n){t.postMessage(e+n,"*")}}():t.MessageChannel?function(){var t=new MessageChannel;t.port1.onmessage=function(t){l(t.data)},r=function(e){t.port2.postMessage(e)}}():s&&"onreadystatechange"in s.createElement("script")?function(){var t=s.documentElement;r=function(e){var n=s.createElement("script");n.onreadystatechange=function(){l(e),n.onreadystatechange=null,t.removeChild(n),n=null},t.appendChild(n)}}():r=function(t){setTimeout(l,0,t)},u.setImmediate=function(t){"function"!=typeof t&&(t=new Function(""+t));for(var e=new Array(arguments.length-1),n=0;n<e.length;n++)e[n]=arguments[n+1];var o={callback:t,args:e};return a[i]=o,r(i),i++},u.clearImmediate=c}function c(t){delete a[t]}function l(t){if(o)setTimeout(l,0,t);else{var e=a[t];if(e){o=!0;try{!function(t){var e=t.callback,r=t.args;switch(r.length){case 0:e();break;case 1:e(r[0]);break;case 2:e(r[0],r[1]);break;case 3:e(r[0],r[1],r[2]);break;default:e.apply(n,r)}}(e)}finally{c(t),o=!1}}}}}("undefined"==typeof self?void 0===t?this:t:self)}).call(this,n(53),n(87))},function(t,e){var n={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==n.call(t)}},function(t,e){e.read=function(t,e,n,r,i){var a,o,s=8*i-r-1,u=(1<<s)-1,c=u>>1,l=-7,f=n?i-1:0,d=n?-1:1,h=t[e+f];for(f+=d,a=h&(1<<-l)-1,h>>=-l,l+=s;l>0;a=256*a+t[e+f],f+=d,l-=8);for(o=a&(1<<-l)-1,a>>=-l,l+=r;l>0;o=256*o+t[e+f],f+=d,l-=8);if(0===a)a=1-c;else{if(a===u)return o?NaN:1/0*(h?-1:1);o+=Math.pow(2,r),a-=c}return(h?-1:1)*o*Math.pow(2,a-r)},e.write=function(t,e,n,r,i,a){var o,s,u,c=8*a-i-1,l=(1<<c)-1,f=l>>1,d=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,h=r?0:a-1,p=r?1:-1,m=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(s=isNaN(e)?1:0,o=l):(o=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-o))<1&&(o--,u*=2),(e+=o+f>=1?d/u:d*Math.pow(2,1-f))*u>=2&&(o++,u/=2),o+f>=l?(s=0,o=l):o+f>=1?(s=(e*u-1)*Math.pow(2,i),o+=f):(s=e*Math.pow(2,f-1)*Math.pow(2,i),o=0));i>=8;t[n+h]=255&s,h+=p,s/=256,i-=8);for(o=o<<i|s,c+=i;c>0;t[n+h]=255&o,h+=p,o/=256,c-=8);t[n+h-p]|=128*m}},function(t,e,n){"use strict";e.byteLength=function(t){var e=c(t),n=e[0],r=e[1];return 3*(n+r)/4-r},e.toByteArray=function(t){var e,n,r=c(t),o=r[0],s=r[1],u=new a(function(t,e,n){return 3*(e+n)/4-n}(0,o,s)),l=0,f=s>0?o-4:o;for(n=0;n<f;n+=4)e=i[t.charCodeAt(n)]<<18|i[t.charCodeAt(n+1)]<<12|i[t.charCodeAt(n+2)]<<6|i[t.charCodeAt(n+3)],u[l++]=e>>16&255,u[l++]=e>>8&255,u[l++]=255&e;2===s&&(e=i[t.charCodeAt(n)]<<2|i[t.charCodeAt(n+1)]>>4,u[l++]=255&e);1===s&&(e=i[t.charCodeAt(n)]<<10|i[t.charCodeAt(n+1)]<<4|i[t.charCodeAt(n+2)]>>2,u[l++]=e>>8&255,u[l++]=255&e);return u},e.fromByteArray=function(t){for(var e,n=t.length,i=n%3,a=[],o=0,s=n-i;o<s;o+=16383)a.push(f(t,o,o+16383>s?s:o+16383));1===i?(e=t[n-1],a.push(r[e>>2]+r[e<<4&63]+"==")):2===i&&(e=(t[n-2]<<8)+t[n-1],a.push(r[e>>10]+r[e>>4&63]+r[e<<2&63]+"="));return a.join("")};for(var r=[],i=[],a="undefined"!=typeof Uint8Array?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=0,u=o.length;s<u;++s)r[s]=o[s],i[o.charCodeAt(s)]=s;function c(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=t.indexOf("=");return-1===n&&(n=e),[n,n===e?0:4-n%4]}function l(t){return r[t>>18&63]+r[t>>12&63]+r[t>>6&63]+r[63&t]}function f(t,e,n){for(var r,i=[],a=e;a<n;a+=3)r=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(255&t[a+2]),i.push(l(r));return i.join("")}i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63},function(t,e,n){var r=n(161),i=Math.max,a=Math.min;t.exports=function(t,e){return(t=r(t))<0?i(t+e,0):a(t,e)}},function(t,e,n){var r=n(67),i=n(122),a=n(485);t.exports=function(t){return function(e,n,o){var s,u=r(e),c=i(u.length),l=a(o,c);if(t&&n!=n){for(;c>l;)if((s=u[l++])!=s)return!0}else for(;c>l;l++)if((t||l in u)&&u[l]===n)return t||l||0;return!t&&-1}}},function(t,e,n){"use strict";var r=n(32),i=n(88),a=n(157),o=n(105),s=n(66),u=n(163),c=Object.assign;t.exports=!c||n(69)(function(){var t={},e={},n=Symbol(),r="abcdefghijklmnopqrst";return t[n]=7,r.split("").forEach(function(t){e[t]=t}),7!=c({},t)[n]||Object.keys(c({},e)).join("")!=r})?function(t,e){for(var n=s(t),c=arguments.length,l=1,f=a.f,d=o.f;c>l;)for(var h,p=u(arguments[l++]),m=f?i(p).concat(f(p)):i(p),g=m.length,v=0;g>v;)h=m[v++],r&&!d.call(p,h)||(n[h]=p[h]);return n}:c},function(t,e,n){var r=n(23);r(r.S+r.F,"Object",{assign:n(487)})},function(t,e,n){n(488),t.exports=n(18).Object.assign},function(t,e,n){"use strict";var r=B(n(90)),i=B(n(89)),a=z(n(4)),o=z(n(243)),s=B(n(428)),u=B(n(411)),c=B(n(371)),l=B(n(368)),f=B(n(363)),d=B(n(361)),h=n(206),p=n(205),m=B(n(346)),g=B(n(345)),v=z(n(46)),y=B(n(343)),b=B(n(342)),x=B(n(340)),w=B(n(338)),k=B(n(318)),_=B(n(317)),E=B(n(316)),O=B(n(315)),S=n(201),C=B(n(314)),A=B(n(313)),N=B(n(310)),T=B(n(304)),I=B(n(300)),D=B(n(299)),M=B(n(298)),R=B(n(296)),F=B(n(294)),j=B(n(64)),P=B(n(292)),L=z(n(291));function z(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}function B(t){return t&&t.__esModule?t:{default:t}}var U={charRNN:b.default,CVAE:_.default,cartoon:D.default,DCGAN:E.default,featureExtractor:f.default,imageClassifier:u.default,kmeans:I.default,soundClassifier:c.default,pitchDetection:s.default,pix2pix:x.default,poseNet:g.default,sketchRNN:w.default,styleTransfer:y.default,word2vec:d.default,YOLO:h.YOLO,CocoSsd:p.CocoSsd,objectDetector:m.default,uNet:k.default,sentiment:C.default,bodyPix:A.default,faceApi:T.default,universalSentenceEncoder:M.default,facemesh:R.default,handpose:F.default};(0,P.default)(),t.exports=(0,i.default)({p5Utils:j.default},(0,O.default)(U),(0,r.default)({KNNClassifier:l.default,communityStatement:P.default},v,{tf:a,tfvis:o,version:S.version,neuralNetwork:N.default,testingUtils:L}))},function(t,e){t.exports=function(t,e){var n=e===Object(e)?function(t){return e[t]}:e;return function(e){return String(e).replace(t,n)}}},function(t,e,n){var r=n(5),i=n(491)(/[\\^$*+?.()|[\]{}]/g,"\\$&");r(r.S,"RegExp",{escape:function(t){return i(t)}})},function(t,e,n){n(492),t.exports=n(44).RegExp.escape},function(t,e,n){(function(e){!function(e){"use strict";var n,r=Object.prototype,i=r.hasOwnProperty,a="function"==typeof Symbol?Symbol:{},o=a.iterator||"@@iterator",s=a.asyncIterator||"@@asyncIterator",u=a.toStringTag||"@@toStringTag",c="object"==typeof t,l=e.regeneratorRuntime;if(l)c&&(t.exports=l);else{(l=e.regeneratorRuntime=c?t.exports:{}).wrap=x;var f="suspendedStart",d="suspendedYield",h="executing",p="completed",m={},g={};g[o]=function(){return this};var v=Object.getPrototypeOf,y=v&&v(v(I([])));y&&y!==r&&i.call(y,o)&&(g=y);var b=E.prototype=k.prototype=Object.create(g);_.prototype=b.constructor=E,E.constructor=_,E[u]=_.displayName="GeneratorFunction",l.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===_||"GeneratorFunction"===(e.displayName||e.name))},l.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,E):(t.__proto__=E,u in t||(t[u]="GeneratorFunction")),t.prototype=Object.create(b),t},l.awrap=function(t){return{__await:t}},O(S.prototype),S.prototype[s]=function(){return this},l.AsyncIterator=S,l.async=function(t,e,n,r){var i=new S(x(t,e,n,r));return l.isGeneratorFunction(e)?i:i.next().then(function(t){return t.done?t.value:i.next()})},O(b),b[u]="Generator",b[o]=function(){return this},b.toString=function(){return"[object Generator]"},l.keys=function(t){var e=[];for(var n in t)e.push(n);return e.reverse(),function n(){for(;e.length;){var r=e.pop();if(r in t)return n.value=r,n.done=!1,n}return n.done=!0,n}},l.values=I,T.prototype={constructor:T,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=n,this.done=!1,this.delegate=null,this.method="next",this.arg=n,this.tryEntries.forEach(N),!t)for(var e in this)"t"===e.charAt(0)&&i.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=n)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(r,i){return s.type="throw",s.arg=t,e.next=r,i&&(e.method="next",e.arg=n),!!i}for(var a=this.tryEntries.length-1;a>=0;--a){var o=this.tryEntries[a],s=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var u=i.call(o,"catchLoc"),c=i.call(o,"finallyLoc");if(u&&c){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(u){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&i.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var a=r;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var o=a?a.completion:{};return o.type=t,o.arg=e,a?(this.method="next",this.next=a.finallyLoc,m):this.complete(o)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),m},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),N(n),m}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var i=r.arg;N(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:I(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=n),m}}}function x(t,e,n,r){var i=e&&e.prototype instanceof k?e:k,a=Object.create(i.prototype),o=new T(r||[]);return a._invoke=function(t,e,n){var r=f;return function(i,a){if(r===h)throw new Error("Generator is already running");if(r===p){if("throw"===i)throw a;return D()}for(n.method=i,n.arg=a;;){var o=n.delegate;if(o){var s=C(o,n);if(s){if(s===m)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(r===f)throw r=p,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r=h;var u=w(t,e,n);if("normal"===u.type){if(r=n.done?p:d,u.arg===m)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r=p,n.method="throw",n.arg=u.arg)}}}(t,n,o),a}function w(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}function k(){}function _(){}function E(){}function O(t){["next","throw","return"].forEach(function(e){t[e]=function(t){return this._invoke(e,t)}})}function S(t){function n(e,r,a,o){var s=w(t[e],t,r);if("throw"!==s.type){var u=s.arg,c=u.value;return c&&"object"==typeof c&&i.call(c,"__await")?Promise.resolve(c.__await).then(function(t){n("next",t,a,o)},function(t){n("throw",t,a,o)}):Promise.resolve(c).then(function(t){u.value=t,a(u)},o)}o(s.arg)}var r;"object"==typeof e.process&&e.process.domain&&(n=e.process.domain.bind(n)),this._invoke=function(t,e){function i(){return new Promise(function(r,i){n(t,e,r,i)})}return r=r?r.then(i,i):i()}}function C(t,e){var r=t.iterator[e.method];if(r===n){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=n,C(t,e),"throw"===e.method))return m;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return m}var i=w(r,t.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,m;var a=i.arg;return a?a.done?(e[t.resultName]=a.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=n),e.delegate=null,m):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,m)}function A(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function N(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function T(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(A,this),this.reset(!0)}function I(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,a=function e(){for(;++r<t.length;)if(i.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=n,e.done=!0,e};return a.next=a}}return{next:D}}function D(){return{value:n,done:!0}}}("object"==typeof e?e:"object"==typeof window?window:"object"==typeof self?self:this)}).call(this,n(53))},function(t,e,n){for(var r=n(172),i=n(78),a=n(30),o=n(11),s=n(31),u=n(91),c=n(16),l=c("iterator"),f=c("toStringTag"),d=u.Array,h={CSSRuleList:!0,CSSStyleDeclaration:!1,CSSValueList:!1,ClientRectList:!1,DOMRectList:!1,DOMStringList:!1,DOMTokenList:!0,DataTransferItemList:!1,FileList:!1,HTMLAllCollection:!1,HTMLCollection:!1,HTMLFormElement:!1,HTMLSelectElement:!1,MediaList:!0,MimeTypeArray:!1,NamedNodeMap:!1,NodeList:!0,PaintRequestList:!1,Plugin:!1,PluginArray:!1,SVGLengthList:!1,SVGNumberList:!1,SVGPathSegList:!1,SVGPointList:!1,SVGStringList:!1,SVGTransformList:!1,SourceBufferList:!1,StyleSheetList:!0,TextTrackCueList:!1,TextTrackList:!1,TouchList:!1},p=i(h),m=0;m<p.length;m++){var g,v=p[m],y=h[v],b=o[v],x=b&&b.prototype;if(x&&(x[l]||s(x,l,d),x[f]||s(x,f,v),u[v]=d,y))for(g in r)x[g]||a(x,g,r[g],!0)}},function(t,e,n){var r=n(5),i=n(169);r(r.G+r.B,{setImmediate:i.set,clearImmediate:i.clear})},function(t,e,n){var r=n(11),i=n(5),a=n(128),o=[].slice,s=/MSIE .\./.test(a),u=function(t){return function(e,n){var r=arguments.length>2,i=!!r&&o.call(arguments,2);return t(r?function(){("function"==typeof e?e:Function(e)).apply(this,i)}:e,n)}};i(i.G+i.B+i.F*s,{setTimeout:u(r.setTimeout),setInterval:u(r.setInterval)})},function(t,e,n){"use strict";var r=n(5),i=n(11),a=n(44),o=n(168)(),s=n(16)("observable"),u=n(27),c=n(6),l=n(73),f=n(71),d=n(31),h=n(72),p=h.RETURN,m=function(t){return null==t?void 0:u(t)},g=function(t){var e=t._c;e&&(t._c=void 0,e())},v=function(t){return void 0===t._o},y=function(t){v(t)||(t._o=void 0,g(t))},b=function(t,e){c(t),this._c=void 0,this._o=t,t=new x(this);try{var n=e(t),r=n;null!=n&&("function"==typeof n.unsubscribe?n=function(){r.unsubscribe()}:u(n),this._c=n)}catch(e){return void t.error(e)}v(this)&&g(this)};b.prototype=f({},{unsubscribe:function(){y(this)}});var x=function(t){this._s=t};x.prototype=f({},{next:function(t){var e=this._s;if(!v(e)){var n=e._o;try{var r=m(n.next);if(r)return r.call(n,t)}catch(t){try{y(e)}finally{throw t}}}},error:function(t){var e=this._s;if(v(e))throw t;var n=e._o;e._o=void 0;try{var r=m(n.error);if(!r)throw t;t=r.call(n,t)}catch(t){try{g(e)}finally{throw t}}return g(e),t},complete:function(t){var e=this._s;if(!v(e)){var n=e._o;e._o=void 0;try{var r=m(n.complete);t=r?r.call(n,t):void 0}catch(t){try{g(e)}finally{throw t}}return g(e),t}}});var w=function(t){l(this,w,"Observable","_f")._f=u(t)};f(w.prototype,{subscribe:function(t){return new b(t,this._f)},forEach:function(t){var e=this;return new(a.Promise||i.Promise)(function(n,r){u(t);var i=e.subscribe({next:function(e){try{return t(e)}catch(t){r(t),i.unsubscribe()}},error:r,complete:n})})}}),f(w,{from:function(t){var e="function"==typeof this?this:w,n=m(c(t)[s]);if(n){var r=c(n.call(t));return r.constructor===e?r:new e(function(t){return r.subscribe(t)})}return new e(function(e){var n=!1;return o(function(){if(!n){try{if(h(t,!1,function(t){if(e.next(t),n)return p})===p)return}catch(t){if(n)throw t;return void e.error(t)}e.complete()}}),function(){n=!0}})},of:function(){for(var t=0,e=arguments.length,n=new Array(e);t<e;)n[t]=arguments[t++];return new("function"==typeof this?this:w)(function(t){var e=!1;return o(function(){if(!e){for(var r=0;r<n.length;++r)if(t.next(n[r]),e)return;t.complete()}}),function(){e=!0}})}}),d(w.prototype,s,function(){return this}),r(r.G,{Observable:w}),n(74)("Observable")},function(t,e,n){var r=n(5),i=n(168)(),a=n(11).process,o="process"==n(42)(a);r(r.G,{asap:function(t){var e=o&&a.domain;i(e?e.bind(t):t)}})},function(t,e,n){var r=n(57),i=n(6),a=n(27),o=r.key,s=r.set;r.exp({metadata:function(t,e){return function(n,r){s(t,e,(void 0!==r?i:a)(n),o(r))}}})},function(t,e,n){var r=n(57),i=n(6),a=r.has,o=r.key;r.exp({hasOwnMetadata:function(t,e){return a(t,i(e),arguments.length<3?void 0:o(arguments[2]))}})},function(t,e,n){var r=n(57),i=n(6),a=n(33),o=r.has,s=r.key,u=function(t,e,n){if(o(t,e,n))return!0;var r=a(e);return null!==r&&u(t,r,n)};r.exp({hasMetadata:function(t,e){return u(t,i(e),arguments.length<3?void 0:s(arguments[2]))}})},function(t,e,n){var r=n(57),i=n(6),a=r.keys,o=r.key;r.exp({getOwnMetadataKeys:function(t){return a(i(t),arguments.length<2?void 0:o(arguments[1]))}})},function(t,e,n){var r=n(57),i=n(6),a=r.get,o=r.key;r.exp({getOwnMetadata:function(t,e){return a(t,i(e),arguments.length<3?void 0:o(arguments[2]))}})},function(t,e,n){var r=n(257),i=n(248),a=n(57),o=n(6),s=n(33),u=a.keys,c=a.key,l=function(t,e){var n=u(t,e),a=s(t);if(null===a)return n;var o=l(a,e);return o.length?n.length?i(new r(n.concat(o))):o:n};a.exp({getMetadataKeys:function(t){return l(o(t),arguments.length<2?void 0:c(arguments[1]))}})},function(t,e,n){var r=n(57),i=n(6),a=n(33),o=r.has,s=r.get,u=r.key,c=function(t,e,n){if(o(t,e,n))return s(t,e,n);var r=a(e);return null!==r?c(t,r,n):void 0};r.exp({getMetadata:function(t,e){return c(t,i(e),arguments.length<3?void 0:u(arguments[2]))}})},function(t,e,n){var r=n(57),i=n(6),a=r.key,o=r.map,s=r.store;r.exp({deleteMetadata:function(t,e){var n=arguments.length<3?void 0:a(arguments[2]),r=o(i(e),n,!1);if(void 0===r||!r.delete(t))return!1;if(r.size)return!0;var u=s.get(e);return u.delete(n),!!u.size||s.delete(e)}})},function(t,e,n){var r=n(57),i=n(6),a=r.key,o=r.set;r.exp({defineMetadata:function(t,e,n,r){o(t,e,i(n),a(r))}})},function(t,e,n){"use strict";var r=n(5),i=n(167),a=n(261);r(r.S,"Promise",{try:function(t){var e=i.f(this),n=a(t);return(n.e?e.reject:e.resolve)(n.v),e.promise}})},function(t,e,n){"use strict";var r=n(5),i=n(44),a=n(11),o=n(110),s=n(260);r(r.P+r.R,"Promise",{finally:function(t){var e=o(this,i.Promise||a.Promise),n="function"==typeof t;return this.then(n?function(n){return s(e,t()).then(function(){return n})}:t,n?function(n){return s(e,t()).then(function(){throw n})}:t)}})},function(t,e,n){var r=n(5);r(r.S,"Math",{signbit:function(t){return(t=+t)!=t?t:0==t?1/t==1/0:t>0}})},function(t,e,n){var r=n(5);r(r.S,"Math",{umulh:function(t,e){var n=+t,r=+e,i=65535&n,a=65535&r,o=n>>>16,s=r>>>16,u=(o*a>>>0)+(i*a>>>16);return o*s+(u>>>16)+((i*s>>>0)+(65535&u)>>>16)}})},function(t,e,n){var r=n(5);r(r.S,"Math",{scale:n(247)})},function(t,e,n){var r=n(5),i=Math.PI/180;r(r.S,"Math",{radians:function(t){return t*i}})},function(t,e,n){var r=n(5);r(r.S,"Math",{RAD_PER_DEG:180/Math.PI})},function(t,e,n){var r=n(5);r(r.S,"Math",{imulh:function(t,e){var n=+t,r=+e,i=65535&n,a=65535&r,o=n>>16,s=r>>16,u=(o*a>>>0)+(i*a>>>16);return o*s+(u>>16)+((i*s>>>0)+(65535&u)>>16)}})},function(t,e,n){var r=n(5);r(r.S,"Math",{isubh:function(t,e,n,r){var i=t>>>0,a=n>>>0;return(e>>>0)-(r>>>0)-((~i&a|~(i^a)&i-a>>>0)>>>31)|0}})},function(t,e,n){var r=n(5);r(r.S,"Math",{iaddh:function(t,e,n,r){var i=t>>>0,a=n>>>0;return(e>>>0)+(r>>>0)+((i&a|(i|a)&~(i+a>>>0))>>>31)|0}})},function(t,e,n){var r=n(5),i=n(247),a=n(268);r(r.S,"Math",{fscale:function(t,e,n,r,o){return a(i(t,e,n,r,o))}})},function(t,e,n){var r=n(5),i=180/Math.PI;r(r.S,"Math",{degrees:function(t){return t*i}})},function(t,e,n){var r=n(5);r(r.S,"Math",{DEG_PER_RAD:Math.PI/180})},function(t,e,n){var r=n(5);r(r.S,"Math",{clamp:function(t,e,n){return Math.min(n,Math.max(e,t))}})},function(t,e,n){var r=n(5),i=n(42);r(r.S,"Error",{isError:function(t){return"Error"===i(t)}})},function(t,e,n){var r=n(5);r(r.S,"System",{global:n(11)})},function(t,e,n){var r=n(5);r(r.G,{global:n(11)})},function(t,e,n){n(123)("WeakSet")},function(t,e,n){n(123)("WeakMap")},function(t,e,n){n(123)("Set")},function(t,e,n){n(123)("Map")},function(t,e,n){n(124)("WeakSet")},function(t,e,n){n(124)("WeakMap")},function(t,e,n){n(124)("Set")},function(t,e,n){n(124)("Map")},function(t,e,n){var r=n(5);r(r.P+r.R,"Set",{toJSON:n(249)("Set")})},function(t,e,n){var r=n(5);r(r.P+r.R,"Map",{toJSON:n(249)("Map")})},function(t,e,n){"use strict";var r=n(5),i=n(22),a=n(52),o=n(33),s=n(34).f;n(19)&&r(r.P+n(125),"Object",{__lookupSetter__:function(t){var e,n=i(this),r=a(t,!0);do{if(e=s(n,r))return e.set}while(n=o(n))}})},function(t,e,n){"use strict";var r=n(5),i=n(22),a=n(52),o=n(33),s=n(34).f;n(19)&&r(r.P+n(125),"Object",{__lookupGetter__:function(t){var e,n=i(this),r=a(t,!0);do{if(e=s(n,r))return e.get}while(n=o(n))}})},function(t,e,n){"use strict";var r=n(5),i=n(22),a=n(27),o=n(21);n(19)&&r(r.P+n(125),"Object",{__defineSetter__:function(t,e){o.f(i(this),t,{set:a(e),enumerable:!0,configurable:!0})}})},function(t,e,n){"use strict";var r=n(5),i=n(22),a=n(27),o=n(21);n(19)&&r(r.P+n(125),"Object",{__defineGetter__:function(t,e){o.f(i(this),t,{get:a(e),enumerable:!0,configurable:!0})}})},function(t,e,n){var r=n(5),i=n(250)(!0);r(r.S,"Object",{entries:function(t){return i(t)}})},function(t,e,n){var r=n(5),i=n(250)(!1);r(r.S,"Object",{values:function(t){return i(t)}})},function(t,e,n){var r=n(5),i=n(253),a=n(35),o=n(34),s=n(176);r(r.S,"Object",{getOwnPropertyDescriptors:function(t){for(var e,n,r=a(t),u=o.f,c=i(r),l={},f=0;c.length>f;)void 0!==(n=u(r,e=c[f++]))&&s(l,e,n);return l}})},function(t,e,n){n(191)("observable")},function(t,e,n){n(191)("asyncIterator")},function(t,e,n){"use strict";var r=n(5),i=n(51),a=n(17),o=n(132),s=n(111),u=RegExp.prototype,c=function(t,e){this._r=t,this._s=e};n(180)(c,"RegExp String",function(){var t=this._r.exec(this._s);return{value:t,done:null===t}}),r(r.P,"String",{matchAll:function(t){if(i(this),!o(t))throw TypeError(t+" is not a regexp!");var e=String(this),n="flags"in u?String(t.flags):s.call(t),r=new RegExp(t.source,~n.indexOf("g")?n:"g"+n);return r.lastIndex=a(t.lastIndex),new c(r,e)}})},function(t,e,n){"use strict";n(92)("trimRight",function(t){return function(){return t(this,2)}},"trimEnd")},function(t,e,n){"use strict";n(92)("trimLeft",function(t){return function(){return t(this,1)}},"trimStart")},function(t,e,n){"use strict";var r=n(5),i=n(251),a=n(128),o=/Version\/10\.\d+(\.\d+)?( Mobile\/\w+)? Safari\//.test(a);r(r.P+r.F*o,"String",{padEnd:function(t){return i(this,t,arguments.length>1?arguments[1]:void 0,!1)}})},function(t,e,n){"use strict";var r=n(5),i=n(251),a=n(128),o=/Version\/10\.\d+(\.\d+)?( Mobile\/\w+)? Safari\//.test(a);r(r.P+r.F*o,"String",{padStart:function(t){return i(this,t,arguments.length>1?arguments[1]:void 0,!0)}})},function(t,e,n){"use strict";var r=n(5),i=n(133)(!0);r(r.P,"String",{at:function(t){return i(this,t)}})},function(t,e,n){"use strict";var r=n(5),i=n(252),a=n(22),o=n(17),s=n(41),u=n(174);r(r.P,"Array",{flatten:function(){var t=arguments[0],e=a(this),n=o(e.length),r=u(e,0);return i(r,e,e,n,0,void 0===t?1:s(t)),r}}),n(61)("flatten")},function(t,e,n){"use strict";var r=n(5),i=n(252),a=n(22),o=n(17),s=n(27),u=n(174);r(r.P,"Array",{flatMap:function(t){var e,n,r=a(this);return s(t),e=o(r.length),n=u(r,0),i(n,r,r,e,0,1,t,arguments[1]),n}}),n(61)("flatMap")},function(t,e,n){"use strict";var r=n(5),i=n(136)(!0);r(r.P,"Array",{includes:function(t){return i(this,t,arguments.length>1?arguments[1]:void 0)}}),n(61)("includes")},function(t,e,n){var r=n(5),i=n(187);i&&r(r.S,"Reflect",{setPrototypeOf:function(t,e){i.check(t,e);try{return i.set(t,e),!0}catch(t){return!1}}})},function(t,e,n){var r=n(21),i=n(34),a=n(33),o=n(36),s=n(5),u=n(80),c=n(6),l=n(13);s(s.S,"Reflect",{set:function t(e,n,s){var f,d,h=arguments.length<4?e:arguments[3],p=i.f(c(e),n);if(!p){if(l(d=a(e)))return t(d,n,s,h);p=u(0)}if(o(p,"value")){if(!1===p.writable||!l(h))return!1;if(f=i.f(h,n)){if(f.get||f.set||!1===f.writable)return!1;f.value=s,r.f(h,n,f)}else r.f(h,n,u(0,s));return!0}return void 0!==p.set&&(p.set.call(h,s),!0)}})},function(t,e,n){var r=n(5),i=n(6),a=Object.preventExtensions;r(r.S,"Reflect",{preventExtensions:function(t){i(t);try{return a&&a(t),!0}catch(t){return!1}}})},function(t,e,n){var r=n(5);r(r.S,"Reflect",{ownKeys:n(253)})},function(t,e,n){var r=n(5),i=n(6),a=Object.isExtensible;r(r.S,"Reflect",{isExtensible:function(t){return i(t),!a||a(t)}})},function(t,e,n){var r=n(5);r(r.S,"Reflect",{has:function(t,e){return e in t}})},function(t,e,n){var r=n(5),i=n(33),a=n(6);r(r.S,"Reflect",{getPrototypeOf:function(t){return i(a(t))}})},function(t,e,n){var r=n(34),i=n(5),a=n(6);i(i.S,"Reflect",{getOwnPropertyDescriptor:function(t,e){return r.f(a(t),e)}})},function(t,e,n){var r=n(34),i=n(33),a=n(36),o=n(5),s=n(13),u=n(6);o(o.S,"Reflect",{get:function t(e,n){var o,c,l=arguments.length<3?e:arguments[2];return u(e)===l?e[n]:(o=r.f(e,n))?a(o,"value")?o.value:void 0!==o.get?o.get.call(l):void 0:s(c=i(e))?t(c,n,l):void 0}})},function(t,e,n){"use strict";var r=n(5),i=n(6),a=function(t){this._t=i(t),this._i=0;var e,n=this._k=[];for(e in t)n.push(e)};n(180)(a,"Object",function(){var t,e=this._k;do{if(this._i>=e.length)return{value:void 0,done:!0}}while(!((t=e[this._i++])in this._t));return{value:t,done:!1}}),r(r.S,"Reflect",{enumerate:function(t){return new a(t)}})},function(t,e,n){var r=n(5),i=n(34).f,a=n(6);r(r.S,"Reflect",{deleteProperty:function(t,e){var n=i(a(t),e);return!(n&&!n.configurable)&&delete t[e]}})},function(t,e,n){var r=n(21),i=n(5),a=n(6),o=n(52);i(i.S+i.F*n(12)(function(){Reflect.defineProperty(r.f({},1,{value:1}),1,{value:2})}),"Reflect",{defineProperty:function(t,e,n){a(t),e=o(e,!0),a(n);try{return r.f(t,e,n),!0}catch(t){return!1}}})},function(t,e,n){var r=n(5),i=n(76),a=n(27),o=n(6),s=n(13),u=n(12),c=n(275),l=(n(11).Reflect||{}).construct,f=u(function(){function t(){}return!(l(function(){},[],t)instanceof t)}),d=!u(function(){l(function(){})});r(r.S+r.F*(f||d),"Reflect",{construct:function(t,e){a(t),o(e);var n=arguments.length<3?t:a(arguments[2]);if(d&&!f)return l(t,e,n);if(t==n){switch(e.length){case 0:return new t;case 1:return new t(e[0]);case 2:return new t(e[0],e[1]);case 3:return new t(e[0],e[1],e[2]);case 4:return new t(e[0],e[1],e[2],e[3])}var r=[null];return r.push.apply(r,e),new(c.apply(t,r))}var u=n.prototype,h=i(s(u)?u:Object.prototype),p=Function.apply.call(t,h,e);return s(p)?p:h}})},function(t,e,n){var r=n(5),i=n(27),a=n(6),o=(n(11).Reflect||{}).apply,s=Function.apply;r(r.S+r.F*!n(12)(function(){o(function(){})}),"Reflect",{apply:function(t,e,n){var r=i(t),u=a(n);return o?o(r,e,u):s.call(r,e,u)}})},function(t,e,n){n(58)("Float64",8,function(t){return function(e,n,r){return t(this,e,n,r)}})},function(t,e,n){n(58)("Float32",4,function(t){return function(e,n,r){return t(this,e,n,r)}})},function(t,e,n){n(58)("Uint32",4,function(t){return function(e,n,r){return t(this,e,n,r)}})},function(t,e,n){n(58)("Int32",4,function(t){return function(e,n,r){return t(this,e,n,r)}})},function(t,e,n){n(58)("Uint16",2,function(t){return function(e,n,r){return t(this,e,n,r)}})},function(t,e,n){n(58)("Int16",2,function(t){return function(e,n,r){return t(this,e,n,r)}})},function(t,e,n){n(58)("Uint8",1,function(t){return function(e,n,r){return t(this,e,n,r)}},!0)},function(t,e,n){n(58)("Uint8",1,function(t){return function(e,n,r){return t(this,e,n,r)}})},function(t,e,n){n(58)("Int8",1,function(t){return function(e,n,r){return t(this,e,n,r)}})},function(t,e,n){var r=n(5);r(r.G+r.W+r.F*!n(126).ABV,{DataView:n(166).DataView})},function(t,e,n){"use strict";var r=n(5),i=n(126),a=n(166),o=n(6),s=n(77),u=n(17),c=n(13),l=n(11).ArrayBuffer,f=n(110),d=a.ArrayBuffer,h=a.DataView,p=i.ABV&&l.isView,m=d.prototype.slice,g=i.VIEW;r(r.G+r.W+r.F*(l!==d),{ArrayBuffer:d}),r(r.S+r.F*!i.CONSTR,"ArrayBuffer",{isView:function(t){return p&&p(t)||c(t)&&g in t}}),r(r.P+r.U+r.F*n(12)(function(){return!new d(2).slice(1,void 0).byteLength}),"ArrayBuffer",{slice:function(t,e){if(void 0!==m&&void 0===e)return m.call(o(this),t);for(var n=o(this).byteLength,r=s(t,n),i=s(void 0===e?n:e,n),a=new(f(this,d))(u(i-r)),c=new h(this),l=new h(a),p=0;r<i;)l.setUint8(p++,c.getUint8(r++));return a}}),n(74)("ArrayBuffer")},function(t,e,n){"use strict";var r=n(255),i=n(70);n(127)("WeakSet",function(t){return function(){return t(this,arguments.length>0?arguments[0]:void 0)}},{add:function(t){return r.def(i(this,"WeakSet"),t,!0)}},r,!1,!0)},function(t,e,n){"use strict";var r,i,a,o,s=n(63),u=n(11),c=n(43),l=n(93),f=n(5),d=n(13),h=n(27),p=n(73),m=n(72),g=n(110),v=n(169).set,y=n(168)(),b=n(167),x=n(261),w=n(128),k=n(260),_=u.TypeError,E=u.process,O=E&&E.versions,S=O&&O.v8||"",C=u.Promise,A="process"==l(E),N=function(){},T=i=b.f,I=!!function(){try{var t=C.resolve(1),e=(t.constructor={})[n(16)("species")]=function(t){t(N,N)};return(A||"function"==typeof PromiseRejectionEvent)&&t.then(N)instanceof e&&0!==S.indexOf("6.6")&&-1===w.indexOf("Chrome/66")}catch(t){}}(),D=function(t){var e;return!(!d(t)||"function"!=typeof(e=t.then))&&e},M=function(t,e){if(!t._n){t._n=!0;var n=t._c;y(function(){for(var r=t._v,i=1==t._s,a=0,o=function(e){var n,a,o,s=i?e.ok:e.fail,u=e.resolve,c=e.reject,l=e.domain;try{s?(i||(2==t._h&&j(t),t._h=1),!0===s?n=r:(l&&l.enter(),n=s(r),l&&(l.exit(),o=!0)),n===e.promise?c(_("Promise-chain cycle")):(a=D(n))?a.call(n,u,c):u(n)):c(r)}catch(t){l&&!o&&l.exit(),c(t)}};n.length>a;)o(n[a++]);t._c=[],t._n=!1,e&&!t._h&&R(t)})}},R=function(t){v.call(u,function(){var e,n,r,i=t._v,a=F(t);if(a&&(e=x(function(){A?E.emit("unhandledRejection",i,t):(n=u.onunhandledrejection)?n({promise:t,reason:i}):(r=u.console)&&r.error&&r.error("Unhandled promise rejection",i)}),t._h=A||F(t)?2:1),t._a=void 0,a&&e.e)throw e.v})},F=function(t){return 1!==t._h&&0===(t._a||t._c).length},j=function(t){v.call(u,function(){var e;A?E.emit("rejectionHandled",t):(e=u.onrejectionhandled)&&e({promise:t,reason:t._v})})},P=function(t){var e=this;e._d||(e._d=!0,(e=e._w||e)._v=t,e._s=2,e._a||(e._a=e._c.slice()),M(e,!0))},L=function(t){var e,n=this;if(!n._d){n._d=!0,n=n._w||n;try{if(n===t)throw _("Promise can't be resolved itself");(e=D(t))?y(function(){var r={_w:n,_d:!1};try{e.call(t,c(L,r,1),c(P,r,1))}catch(t){P.call(r,t)}}):(n._v=t,n._s=1,M(n,!1))}catch(t){P.call({_w:n,_d:!1},t)}}};I||(C=function(t){p(this,C,"Promise","_h"),h(t),r.call(this);try{t(c(L,this,1),c(P,this,1))}catch(t){P.call(this,t)}},(r=function(t){this._c=[],this._a=void 0,this._s=0,this._d=!1,this._v=void 0,this._h=0,this._n=!1}).prototype=n(71)(C.prototype,{then:function(t,e){var n=T(g(this,C));return n.ok="function"!=typeof t||t,n.fail="function"==typeof e&&e,n.domain=A?E.domain:void 0,this._c.push(n),this._a&&this._a.push(n),this._s&&M(this,!1),n.promise},catch:function(t){return this.then(void 0,t)}}),a=function(){var t=new r;this.promise=t,this.resolve=c(L,t,1),this.reject=c(P,t,1)},b.f=T=function(t){return t===C||t===o?new a(t):i(t)}),f(f.G+f.W+f.F*!I,{Promise:C}),n(94)(C,"Promise"),n(74)("Promise"),o=n(44).Promise,f(f.S+f.F*!I,"Promise",{reject:function(t){var e=T(this);return(0,e.reject)(t),e.promise}}),f(f.S+f.F*(s||!I),"Promise",{resolve:function(t){return k(s&&this===o?C:this,t)}}),f(f.S+f.F*!(I&&n(131)(function(t){C.all(t).catch(N)})),"Promise",{all:function(t){var e=this,n=T(e),r=n.resolve,i=n.reject,a=x(function(){var n=[],a=0,o=1;m(t,!1,function(t){var s=a++,u=!1;n.push(void 0),o++,e.resolve(t).then(function(t){u||(u=!0,n[s]=t,--o||r(n))},i)}),--o||r(n)});return a.e&&i(a.v),n.promise},race:function(t){var e=this,n=T(e),r=n.reject,i=x(function(){m(t,!1,function(t){e.resolve(t).then(n.resolve,r)})});return i.e&&r(i.v),n.promise}})},function(t,e,n){"use strict";var r=n(132),i=n(6),a=n(110),o=n(170),s=n(17),u=n(130),c=n(171),l=n(12),f=Math.min,d=[].push,h=!l(function(){RegExp(4294967295,"y")});n(129)("split",2,function(t,e,n,l){var p;return p="c"=="abbc".split(/(b)*/)[1]||4!="test".split(/(?:)/,-1).length||2!="ab".split(/(?:ab)*/).length||4!=".".split(/(.?)(.?)/).length||".".split(/()()/).length>1||"".split(/.?/).length?function(t,e){var i=String(this);if(void 0===t&&0===e)return[];if(!r(t))return n.call(i,t,e);for(var a,o,s,u=[],l=(t.ignoreCase?"i":"")+(t.multiline?"m":"")+(t.unicode?"u":"")+(t.sticky?"y":""),f=0,h=void 0===e?4294967295:e>>>0,p=new RegExp(t.source,l+"g");(a=c.call(p,i))&&!((o=p.lastIndex)>f&&(u.push(i.slice(f,a.index)),a.length>1&&a.index<i.length&&d.apply(u,a.slice(1)),s=a[0].length,f=o,u.length>=h));)p.lastIndex===a.index&&p.lastIndex++;return f===i.length?!s&&p.test("")||u.push(""):u.push(i.slice(f)),u.length>h?u.slice(0,h):u}:"0".split(void 0,0).length?function(t,e){return void 0===t&&0===e?[]:n.call(this,t,e)}:n,[function(n,r){var i=t(this),a=void 0==n?void 0:n[e];return void 0!==a?a.call(n,i,r):p.call(String(i),n,r)},function(t,e){var r=l(p,t,this,e,p!==n);if(r.done)return r.value;var c=i(t),d=String(this),m=a(c,RegExp),g=c.unicode,v=(c.ignoreCase?"i":"")+(c.multiline?"m":"")+(c.unicode?"u":"")+(h?"y":"g"),y=new m(h?c:"^(?:"+c.source+")",v),b=void 0===e?4294967295:e>>>0;if(0===b)return[];if(0===d.length)return null===u(y,d)?[d]:[];for(var x=0,w=0,k=[];w<d.length;){y.lastIndex=h?w:0;var _,E=u(y,h?d:d.slice(w));if(null===E||(_=f(s(y.lastIndex+(h?0:w)),d.length))===x)w=o(d,w,g);else{if(k.push(d.slice(x,w)),k.length===b)return k;for(var O=1;O<=E.length-1;O++)if(k.push(E[O]),k.length===b)return k;w=x=_}}return k.push(d.slice(x)),k}]})},function(t,e,n){"use strict";var r=n(6),i=n(276),a=n(130);n(129)("search",1,function(t,e,n,o){return[function(n){var r=t(this),i=void 0==n?void 0:n[e];return void 0!==i?i.call(n,r):new RegExp(n)[e](String(r))},function(t){var e=o(n,t,this);if(e.done)return e.value;var s=r(t),u=String(this),c=s.lastIndex;i(c,0)||(s.lastIndex=0);var l=a(s,u);return i(s.lastIndex,c)||(s.lastIndex=c),null===l?-1:l.index}]})},function(t,e,n){"use strict";var r=n(6),i=n(22),a=n(17),o=n(41),s=n(170),u=n(130),c=Math.max,l=Math.min,f=Math.floor,d=/\$([$&`']|\d\d?|<[^>]*>)/g,h=/\$([$&`']|\d\d?)/g,p=function(t){return void 0===t?t:String(t)};n(129)("replace",2,function(t,e,n,m){return[function(r,i){var a=t(this),o=void 0==r?void 0:r[e];return void 0!==o?o.call(r,a,i):n.call(String(a),r,i)},function(t,e){var i=m(n,t,this,e);if(i.done)return i.value;var f=r(t),d=String(this),h="function"==typeof e;h||(e=String(e));var v=f.global;if(v){var y=f.unicode;f.lastIndex=0}for(var b=[];;){var x=u(f,d);if(null===x)break;if(b.push(x),!v)break;""===String(x[0])&&(f.lastIndex=s(d,a(f.lastIndex),y))}for(var w="",k=0,_=0;_<b.length;_++){x=b[_];for(var E=String(x[0]),O=c(l(o(x.index),d.length),0),S=[],C=1;C<x.length;C++)S.push(p(x[C]));var A=x.groups;if(h){var N=[E].concat(S,O,d);void 0!==A&&N.push(A);var T=String(e.apply(void 0,N))}else T=g(E,d,O,S,A,e);O>=k&&(w+=d.slice(k,O)+T,k=O+E.length)}return w+d.slice(k)}];function g(t,e,r,a,o,s){var u=r+t.length,c=a.length,l=h;return void 0!==o&&(o=i(o),l=d),n.call(s,l,function(n,i){var s;switch(i.charAt(0)){case"$":return"$";case"&":return t;case"`":return e.slice(0,r);case"'":return e.slice(u);case"<":s=o[i.slice(1,-1)];break;default:var l=+i;if(0===l)return n;if(l>c){var d=f(l/10);return 0===d?n:d<=c?void 0===a[d-1]?i.charAt(1):a[d-1]+i.charAt(1):n}s=a[l-1]}return void 0===s?"":s})}})},function(t,e,n){"use strict";var r=n(6),i=n(17),a=n(170),o=n(130);n(129)("match",1,function(t,e,n,s){return[function(n){var r=t(this),i=void 0==n?void 0:n[e];return void 0!==i?i.call(n,r):new RegExp(n)[e](String(r))},function(t){var e=s(n,t,this);if(e.done)return e.value;var u=r(t),c=String(this);if(!u.global)return o(u,c);var l=u.unicode;u.lastIndex=0;for(var f,d=[],h=0;null!==(f=o(u,c));){var p=String(f[0]);d[h]=p,""===p&&(u.lastIndex=a(c,i(u.lastIndex),l)),h++}return 0===h?null:d}]})},function(t,e,n){"use strict";n(262);var r=n(6),i=n(111),a=n(19),o=/./.toString,s=function(t){n(30)(RegExp.prototype,"toString",t,!0)};n(12)(function(){return"/a/b"!=o.call({source:"a",flags:"b"})})?s(function(){var t=r(this);return"/".concat(t.source,"/","flags"in t?t.flags:!a&&t instanceof RegExp?i.call(t):void 0)}):"toString"!=o.name&&s(function(){return o.call(this)})},function(t,e,n){var r=n(11),i=n(185),a=n(21).f,o=n(75).f,s=n(132),u=n(111),c=r.RegExp,l=c,f=c.prototype,d=/a/g,h=/a/g,p=new c(d)!==d;if(n(19)&&(!p||n(12)(function(){return h[n(16)("match")]=!1,c(d)!=d||c(h)==h||"/a/i"!=c(d,"i")}))){c=function(t,e){var n=this instanceof c,r=s(t),a=void 0===e;return!n&&r&&t.constructor===c&&a?t:i(p?new l(r&&!a?t.source:t,e):l((r=t instanceof c)?t.source:t,r&&a?u.call(t):e),n?this:f,c)};for(var m=function(t){t in c||a(c,t,{configurable:!0,get:function(){return l[t]},set:function(e){l[t]=e}})},g=o(l),v=0;g.length>v;)m(g[v++]);f.constructor=c,c.prototype=f,n(30)(r,"RegExp",c)}n(74)("RegExp")},function(t,e,n){n(74)("Array")},function(t,e,n){"use strict";var r=n(5),i=n(49)(6),a="findIndex",o=!0;a in[]&&Array(1)[a](function(){o=!1}),r(r.P+r.F*o,"Array",{findIndex:function(t){return i(this,t,arguments.length>1?arguments[1]:void 0)}}),n(61)(a)},function(t,e,n){"use strict";var r=n(5),i=n(49)(5),a=!0;"find"in[]&&Array(1).find(function(){a=!1}),r(r.P+r.F*a,"Array",{find:function(t){return i(this,t,arguments.length>1?arguments[1]:void 0)}}),n(61)("find")},function(t,e,n){var r=n(5);r(r.P,"Array",{fill:n(173)}),n(61)("fill")},function(t,e,n){var r=n(5);r(r.P,"Array",{copyWithin:n(265)}),n(61)("copyWithin")},function(t,e,n){"use strict";var r=n(5),i=n(35),a=n(41),o=n(17),s=[].lastIndexOf,u=!!s&&1/[1].lastIndexOf(1,-0)<0;r(r.P+r.F*(u||!n(40)(s)),"Array",{lastIndexOf:function(t){if(u)return s.apply(this,arguments)||0;var e=i(this),n=o(e.length),r=n-1;for(arguments.length>1&&(r=Math.min(r,a(arguments[1]))),r<0&&(r=n+r);r>=0;r--)if(r in e&&e[r]===t)return r||0;return-1}})},function(t,e,n){"use strict";var r=n(5),i=n(136)(!1),a=[].indexOf,o=!!a&&1/[1].indexOf(1,-0)<0;r(r.P+r.F*(o||!n(40)(a)),"Array",{indexOf:function(t){return o?a.apply(this,arguments)||0:i(this,t,arguments[1])}})},function(t,e,n){"use strict";var r=n(5),i=n(266);r(r.P+r.F*!n(40)([].reduceRight,!0),"Array",{reduceRight:function(t){return i(this,t,arguments.length,arguments[1],!0)}})},function(t,e,n){"use strict";var r=n(5),i=n(266);r(r.P+r.F*!n(40)([].reduce,!0),"Array",{reduce:function(t){return i(this,t,arguments.length,arguments[1],!1)}})},function(t,e,n){"use strict";var r=n(5),i=n(49)(4);r(r.P+r.F*!n(40)([].every,!0),"Array",{every:function(t){return i(this,t,arguments[1])}})},function(t,e,n){"use strict";var r=n(5),i=n(49)(3);r(r.P+r.F*!n(40)([].some,!0),"Array",{some:function(t){return i(this,t,arguments[1])}})},function(t,e,n){"use strict";var r=n(5),i=n(49)(2);r(r.P+r.F*!n(40)([].filter,!0),"Array",{filter:function(t){return i(this,t,arguments[1])}})},function(t,e,n){"use strict";var r=n(5),i=n(49)(1);r(r.P+r.F*!n(40)([].map,!0),"Array",{map:function(t){return i(this,t,arguments[1])}})},function(t,e,n){var r=n(13),i=n(134),a=n(16)("species");t.exports=function(t){var e;return i(t)&&("function"!=typeof(e=t.constructor)||e!==Array&&!i(e.prototype)||(e=void 0),r(e)&&null===(e=e[a])&&(e=void 0)),void 0===e?Array:e}},function(t,e,n){"use strict";var r=n(5),i=n(49)(0),a=n(40)([].forEach,!0);r(r.P+r.F*!a,"Array",{forEach:function(t){return i(this,t,arguments[1])}})},function(t,e,n){"use strict";var r=n(5),i=n(27),a=n(22),o=n(12),s=[].sort,u=[1,2,3];r(r.P+r.F*(o(function(){u.sort(void 0)})||!o(function(){u.sort(null)})||!n(40)(s)),"Array",{sort:function(t){return void 0===t?s.call(a(this)):s.call(a(this),i(t))}})},function(t,e,n){"use strict";var r=n(5),i=n(188),a=n(42),o=n(77),s=n(17),u=[].slice;r(r.P+r.F*n(12)(function(){i&&u.call(i)}),"Array",{slice:function(t,e){var n=s(this.length),r=a(this);if(e=void 0===e?n:e,"Array"==r)return u.call(this,t,e);for(var i=o(t,n),c=o(e,n),l=s(c-i),f=new Array(l),d=0;d<l;d++)f[d]="String"==r?this.charAt(i+d):this[i+d];return f}})},function(t,e,n){"use strict";var r=n(5),i=n(35),a=[].join;r(r.P+r.F*(n(113)!=Object||!n(40)(a)),"Array",{join:function(t){return a.call(i(this),void 0===t?",":t)}})},function(t,e,n){"use strict";var r=n(5),i=n(176);r(r.S+r.F*n(12)(function(){function t(){}return!(Array.of.call(t)instanceof t)}),"Array",{of:function(){for(var t=0,e=arguments.length,n=new("function"==typeof this?this:Array)(e);e>t;)i(n,t,arguments[t++]);return n.length=e,n}})},function(t,e,n){"use strict";var r=n(43),i=n(5),a=n(22),o=n(267),s=n(177),u=n(17),c=n(176),l=n(175);i(i.S+i.F*!n(131)(function(t){Array.from(t)}),"Array",{from:function(t){var e,n,i,f,d=a(t),h="function"==typeof this?this:Array,p=arguments.length,m=p>1?arguments[1]:void 0,g=void 0!==m,v=0,y=l(d);if(g&&(m=r(m,p>2?arguments[2]:void 0,2)),void 0==y||h==Array&&s(y))for(n=new h(e=u(d.length));e>v;v++)c(n,v,g?m(d[v],v):d[v]);else for(f=y.call(d),n=new h;!(i=f.next()).done;v++)c(n,v,g?o(f,m,[i.value,v],!0):i.value);return n.length=v,n}})},function(t,e,n){var r=n(5);r(r.S,"Array",{isArray:n(134)})},function(t,e,n){"use strict";var r=n(6),i=n(52);t.exports=function(t){if("string"!==t&&"number"!==t&&"default"!==t)throw TypeError("Incorrect hint");return i(r(this),"number"!=t)}},function(t,e,n){var r=n(16)("toPrimitive"),i=Date.prototype;r in i||n(31)(i,r,n(608))},function(t,e,n){var r=Date.prototype,i=r.toString,a=r.getTime;new Date(NaN)+""!="Invalid Date"&&n(30)(r,"toString",function(){var t=a.call(this);return t==t?i.call(this):"Invalid Date"})},function(t,e,n){"use strict";var r=n(12),i=Date.prototype.getTime,a=Date.prototype.toISOString,o=function(t){return t>9?t:"0"+t};t.exports=r(function(){return"0385-07-25T07:06:39.999Z"!=a.call(new Date(-5e13-1))})||!r(function(){a.call(new Date(NaN))})?function(){if(!isFinite(i.call(this)))throw RangeError("Invalid time value");var t=this,e=t.getUTCFullYear(),n=t.getUTCMilliseconds(),r=e<0?"-":e>9999?"+":"";return r+("00000"+Math.abs(e)).slice(r?-6:-4)+"-"+o(t.getUTCMonth()+1)+"-"+o(t.getUTCDate())+"T"+o(t.getUTCHours())+":"+o(t.getUTCMinutes())+":"+o(t.getUTCSeconds())+"."+(n>99?n:"0"+o(n))+"Z"}:a},function(t,e,n){var r=n(5),i=n(611);r(r.P+r.F*(Date.prototype.toISOString!==i),"Date",{toISOString:i})},function(t,e,n){"use strict";var r=n(5),i=n(22),a=n(52);r(r.P+r.F*n(12)(function(){return null!==new Date(NaN).toJSON()||1!==Date.prototype.toJSON.call({toISOString:function(){return 1}})}),"Date",{toJSON:function(t){var e=i(this),n=a(e);return"number"!=typeof n||isFinite(n)?e.toISOString():null}})},function(t,e,n){var r=n(5);r(r.S,"Date",{now:function(){return(new Date).getTime()}})},function(t,e,n){"use strict";n(29)("sup",function(t){return function(){return t(this,"sup","","")}})},function(t,e,n){"use strict";n(29)("sub",function(t){return function(){return t(this,"sub","","")}})},function(t,e,n){"use strict";n(29)("strike",function(t){return function(){return t(this,"strike","","")}})},function(t,e,n){"use strict";n(29)("small",function(t){return function(){return t(this,"small","","")}})},function(t,e,n){"use strict";n(29)("link",function(t){return function(e){return t(this,"a","href",e)}})},function(t,e,n){"use strict";n(29)("italics",function(t){return function(){return t(this,"i","","")}})},function(t,e,n){"use strict";n(29)("fontsize",function(t){return function(e){return t(this,"font","size",e)}})},function(t,e,n){"use strict";n(29)("fontcolor",function(t){return function(e){return t(this,"font","color",e)}})},function(t,e,n){"use strict";n(29)("fixed",function(t){return function(){return t(this,"tt","","")}})},function(t,e,n){"use strict";n(29)("bold",function(t){return function(){return t(this,"b","","")}})},function(t,e,n){"use strict";n(29)("blink",function(t){return function(){return t(this,"blink","","")}})},function(t,e,n){"use strict";n(29)("big",function(t){return function(){return t(this,"big","","")}})},function(t,e,n){"use strict";n(29)("anchor",function(t){return function(e){return t(this,"a","name",e)}})},function(t,e,n){"use strict";var r=n(5),i=n(17),a=n(179),o="".startsWith;r(r.P+r.F*n(178)("startsWith"),"String",{startsWith:function(t){var e=a(this,t,"startsWith"),n=i(Math.min(arguments.length>1?arguments[1]:void 0,e.length)),r=String(t);return o?o.call(e,r,n):e.slice(n,n+r.length)===r}})},function(t,e,n){var r=n(5);r(r.P,"String",{repeat:n(184)})},function(t,e,n){"use strict";var r=n(5),i=n(179);r(r.P+r.F*n(178)("includes"),"String",{includes:function(t){return!!~i(this,t,"includes").indexOf(t,arguments.length>1?arguments[1]:void 0)}})},function(t,e,n){"use strict";var r=n(5),i=n(17),a=n(179),o="".endsWith;r(r.P+r.F*n(178)("endsWith"),"String",{endsWith:function(t){var e=a(this,t,"endsWith"),n=arguments.length>1?arguments[1]:void 0,r=i(e.length),s=void 0===n?r:Math.min(i(n),r),u=String(t);return o?o.call(e,u,s):e.slice(s-u.length,s)===u}})},function(t,e,n){"use strict";var r=n(5),i=n(133)(!1);r(r.P,"String",{codePointAt:function(t){return i(this,t)}})},function(t,e,n){"use strict";var r=n(133)(!0);n(181)(String,"String",function(t){this._t=String(t),this._i=0},function(){var t,e=this._t,n=this._i;return n>=e.length?{value:void 0,done:!0}:(t=r(e,n),this._i+=t.length,{value:t,done:!1})})},function(t,e,n){"use strict";n(92)("trim",function(t){return function(){return t(this,3)}})},function(t,e,n){var r=n(5),i=n(35),a=n(17);r(r.S,"String",{raw:function(t){for(var e=i(t.raw),n=a(e.length),r=arguments.length,o=[],s=0;n>s;)o.push(String(e[s++])),s<r&&o.push(String(arguments[s]));return o.join("")}})},function(t,e,n){var r=n(5),i=n(77),a=String.fromCharCode,o=String.fromCodePoint;r(r.S+r.F*(!!o&&1!=o.length),"String",{fromCodePoint:function(t){for(var e,n=[],r=arguments.length,o=0;r>o;){if(e=+arguments[o++],i(e,1114111)!==e)throw RangeError(e+" is not a valid code point");n.push(e<65536?a(e):a(55296+((e-=65536)>>10),e%1024+56320))}return n.join("")}})},function(t,e,n){var r=n(5);r(r.S,"Math",{trunc:function(t){return(t>0?Math.floor:Math.ceil)(t)}})},function(t,e,n){var r=n(5),i=n(182),a=Math.exp;r(r.S,"Math",{tanh:function(t){var e=i(t=+t),n=i(-t);return e==1/0?1:n==1/0?-1:(e-n)/(a(t)+a(-t))}})},function(t,e,n){var r=n(5),i=n(182),a=Math.exp;r(r.S+r.F*n(12)(function(){return-2e-17!=!Math.sinh(-2e-17)}),"Math",{sinh:function(t){return Math.abs(t=+t)<1?(i(t)-i(-t))/2:(a(t-1)-a(-t-1))*(Math.E/2)}})},function(t,e,n){var r=n(5);r(r.S,"Math",{sign:n(183)})},function(t,e,n){var r=n(5);r(r.S,"Math",{log2:function(t){return Math.log(t)/Math.LN2}})},function(t,e,n){var r=n(5);r(r.S,"Math",{log1p:n(269)})},function(t,e,n){var r=n(5);r(r.S,"Math",{log10:function(t){return Math.log(t)*Math.LOG10E}})},function(t,e,n){var r=n(5),i=Math.imul;r(r.S+r.F*n(12)(function(){return-5!=i(4294967295,5)||2!=i.length}),"Math",{imul:function(t,e){var n=+t,r=+e,i=65535&n,a=65535&r;return 0|i*a+((65535&n>>>16)*a+i*(65535&r>>>16)<<16>>>0)}})},function(t,e,n){var r=n(5),i=Math.abs;r(r.S,"Math",{hypot:function(t,e){for(var n,r,a=0,o=0,s=arguments.length,u=0;o<s;)u<(n=i(arguments[o++]))?(a=a*(r=u/n)*r+1,u=n):a+=n>0?(r=n/u)*r:n;return u===1/0?1/0:u*Math.sqrt(a)}})},function(t,e,n){var r=n(5);r(r.S,"Math",{fround:n(268)})},function(t,e,n){var r=n(5),i=n(182);r(r.S+r.F*(i!=Math.expm1),"Math",{expm1:i})},function(t,e,n){var r=n(5),i=Math.exp;r(r.S,"Math",{cosh:function(t){return(i(t=+t)+i(-t))/2}})},function(t,e,n){var r=n(5);r(r.S,"Math",{clz32:function(t){return(t>>>=0)?31-Math.floor(Math.log(t+.5)*Math.LOG2E):32}})},function(t,e,n){var r=n(5),i=n(183);r(r.S,"Math",{cbrt:function(t){return i(t=+t)*Math.pow(Math.abs(t),1/3)}})},function(t,e,n){var r=n(5),i=Math.atanh;r(r.S+r.F*!(i&&1/i(-0)<0),"Math",{atanh:function(t){return 0==(t=+t)?t:Math.log((1+t)/(1-t))/2}})},function(t,e,n){var r=n(5),i=Math.asinh;r(r.S+r.F*!(i&&1/i(0)>0),"Math",{asinh:function t(e){return isFinite(e=+e)&&0!=e?e<0?-t(-e):Math.log(e+Math.sqrt(e*e+1)):e}})},function(t,e,n){var r=n(5),i=n(269),a=Math.sqrt,o=Math.acosh;r(r.S+r.F*!(o&&710==Math.floor(o(Number.MAX_VALUE))&&o(1/0)==1/0),"Math",{acosh:function(t){return(t=+t)<1?NaN:t>94906265.62425156?Math.log(t)+Math.LN2:i(t-1+a(t-1)*a(t+1))}})},function(t,e,n){var r=n(5),i=n(273);r(r.S+r.F*(Number.parseInt!=i),"Number",{parseInt:i})},function(t,e,n){var r=n(5),i=n(272);r(r.S+r.F*(Number.parseFloat!=i),"Number",{parseFloat:i})},function(t,e,n){var r=n(5);r(r.S,"Number",{MIN_SAFE_INTEGER:-9007199254740991})},function(t,e,n){var r=n(5);r(r.S,"Number",{MAX_SAFE_INTEGER:9007199254740991})},function(t,e,n){var r=n(5),i=n(270),a=Math.abs;r(r.S,"Number",{isSafeInteger:function(t){return i(t)&&a(t)<=9007199254740991}})},function(t,e,n){var r=n(5);r(r.S,"Number",{isNaN:function(t){return t!=t}})},function(t,e,n){var r=n(5);r(r.S,"Number",{isInteger:n(270)})},function(t,e,n){var r=n(5),i=n(11).isFinite;r(r.S,"Number",{isFinite:function(t){return"number"==typeof t&&i(t)}})},function(t,e,n){var r=n(5);r(r.S,"Number",{EPSILON:Math.pow(2,-52)})},function(t,e,n){"use strict";var r=n(5),i=n(12),a=n(271),o=1..toPrecision;r(r.P+r.F*(i(function(){return"1"!==o.call(1,void 0)})||!i(function(){o.call({})})),"Number",{toPrecision:function(t){var e=a(this,"Number#toPrecision: incorrect invocation!");return void 0===t?o.call(e):o.call(e,t)}})},function(t,e,n){"use strict";var r=n(5),i=n(41),a=n(271),o=n(184),s=1..toFixed,u=Math.floor,c=[0,0,0,0,0,0],l="Number.toFixed: incorrect invocation!",f=function(t,e){for(var n=-1,r=e;++n<6;)r+=t*c[n],c[n]=r%1e7,r=u(r/1e7)},d=function(t){for(var e=6,n=0;--e>=0;)n+=c[e],c[e]=u(n/t),n=n%t*1e7},h=function(){for(var t=6,e="";--t>=0;)if(""!==e||0===t||0!==c[t]){var n=String(c[t]);e=""===e?n:e+o.call("0",7-n.length)+n}return e},p=function(t,e,n){return 0===e?n:e%2==1?p(t,e-1,n*t):p(t*t,e/2,n)};r(r.P+r.F*(!!s&&("0.000"!==8e-5.toFixed(3)||"1"!==.9.toFixed(0)||"1.25"!==1.255.toFixed(2)||"1000000000000000128"!==(0xde0b6b3a7640080).toFixed(0))||!n(12)(function(){s.call({})})),"Number",{toFixed:function(t){var e,n,r,s,u=a(this,l),c=i(t),m="",g="0";if(c<0||c>20)throw RangeError(l);if(u!=u)return"NaN";if(u<=-1e21||u>=1e21)return String(u);if(u<0&&(m="-",u=-u),u>1e-21)if(n=(e=function(t){for(var e=0,n=t;n>=4096;)e+=12,n/=4096;for(;n>=2;)e+=1,n/=2;return e}(u*p(2,69,1))-69)<0?u*p(2,-e,1):u/p(2,e,1),n*=4503599627370496,(e=52-e)>0){for(f(0,n),r=c;r>=7;)f(1e7,0),r-=7;for(f(p(10,r,1),0),r=e-1;r>=23;)d(1<<23),r-=23;d(1<<r),f(1,1),d(2),g=h()}else f(0,n),f(1<<-e,0),g=h()+o.call("0",c);return g=c>0?m+((s=g.length)<=c?"0."+o.call("0",c-s)+g:g.slice(0,s-c)+"."+g.slice(s-c)):m+g}})},function(t,e,n){"use strict";var r=n(11),i=n(36),a=n(42),o=n(185),s=n(52),u=n(12),c=n(75).f,l=n(34).f,f=n(21).f,d=n(92).trim,h=r.Number,p=h,m=h.prototype,g="Number"==a(n(76)(m)),v="trim"in String.prototype,y=function(t){var e=s(t,!1);if("string"==typeof e&&e.length>2){var n,r,i,a=(e=v?e.trim():d(e,3)).charCodeAt(0);if(43===a||45===a){if(88===(n=e.charCodeAt(2))||120===n)return NaN}else if(48===a){switch(e.charCodeAt(1)){case 66:case 98:r=2,i=49;break;case 79:case 111:r=8,i=55;break;default:return+e}for(var o,u=e.slice(2),c=0,l=u.length;c<l;c++)if((o=u.charCodeAt(c))<48||o>i)return NaN;return parseInt(u,r)}}return+e};if(!h(" 0o1")||!h("0b1")||h("+0x1")){h=function(t){var e=arguments.length<1?0:t,n=this;return n instanceof h&&(g?u(function(){m.valueOf.call(n)}):"Number"!=a(n))?o(new p(y(e)),n,h):y(e)};for(var b,x=n(19)?c(p):"MAX_VALUE,MIN_VALUE,NaN,NEGATIVE_INFINITY,POSITIVE_INFINITY,EPSILON,isFinite,isInteger,isNaN,isSafeInteger,MAX_SAFE_INTEGER,MIN_SAFE_INTEGER,parseFloat,parseInt,isInteger".split(","),w=0;x.length>w;w++)i(p,b=x[w])&&!i(h,b)&&f(h,b,l(p,b));h.prototype=m,m.constructor=h,n(30)(r,"Number",h)}},function(t,e,n){var r=n(5),i=n(272);r(r.G+r.F*(parseFloat!=i),{parseFloat:i})},function(t,e,n){var r=n(5),i=n(273);r(r.G+r.F*(parseInt!=i),{parseInt:i})},function(t,e,n){"use strict";var r=n(13),i=n(33),a=n(16)("hasInstance"),o=Function.prototype;a in o||n(21).f(o,a,{value:function(t){if("function"!=typeof this||!r(t))return!1;if(!r(this.prototype))return t instanceof this;for(;t=i(t);)if(this.prototype===t)return!0;return!1}})},function(t,e,n){var r=n(21).f,i=Function.prototype,a=/^\s*function ([^ (]*)/;"name"in i||n(19)&&r(i,"name",{configurable:!0,get:function(){try{return(""+this).match(a)[1]}catch(t){return""}}})},function(t,e,n){var r=n(5);r(r.P,"Function",{bind:n(275)})},function(t,e,n){"use strict";var r=n(93),i={};i[n(16)("toStringTag")]="z",i+""!="[object z]"&&n(30)(Object.prototype,"toString",function(){return"[object "+r(this)+"]"},!0)},function(t,e,n){var r=n(5);r(r.S,"Object",{setPrototypeOf:n(187).set})},function(t,e,n){var r=n(5);r(r.S,"Object",{is:n(276)})},function(t,e,n){var r=n(5);r(r.S+r.F,"Object",{assign:n(277)})},function(t,e,n){var r=n(13);n(50)("isExtensible",function(t){return function(e){return!!r(e)&&(!t||t(e))}})},function(t,e,n){var r=n(13);n(50)("isSealed",function(t){return function(e){return!r(e)||!!t&&t(e)}})},function(t,e,n){var r=n(13);n(50)("isFrozen",function(t){return function(e){return!r(e)||!!t&&t(e)}})},function(t,e,n){var r=n(13),i=n(62).onFreeze;n(50)("preventExtensions",function(t){return function(e){return t&&r(e)?t(i(e)):e}})},function(t,e,n){var r=n(13),i=n(62).onFreeze;n(50)("seal",function(t){return function(e){return t&&r(e)?t(i(e)):e}})},function(t,e,n){var r=n(13),i=n(62).onFreeze;n(50)("freeze",function(t){return function(e){return t&&r(e)?t(i(e)):e}})},function(t,e,n){n(50)("getOwnPropertyNames",function(){return n(278).f})},function(t,e,n){var r=n(22),i=n(78);n(50)("keys",function(){return function(t){return i(r(t))}})},function(t,e,n){var r=n(22),i=n(33);n(50)("getPrototypeOf",function(){return function(t){return i(r(t))}})},function(t,e,n){var r=n(35),i=n(34).f;n(50)("getOwnPropertyDescriptor",function(){return function(t,e){return i(r(t),e)}})},function(t,e,n){var r=n(5);r(r.S+r.F*!n(19),"Object",{defineProperties:n(279)})},function(t,e,n){var r=n(5);r(r.S+r.F*!n(19),"Object",{defineProperty:n(21).f})},function(t,e,n){var r=n(5);r(r.S,"Object",{create:n(76)})},function(t,e,n){var r=n(78),i=n(135),a=n(112);t.exports=function(t){var e=r(t),n=i.f;if(n)for(var o,s=n(t),u=a.f,c=0;s.length>c;)u.call(t,o=s[c++])&&e.push(o);return e}},function(t,e,n){t.exports=n(114)("native-function-to-string",Function.toString)},function(t,e,n){"use strict";var r=n(11),i=n(36),a=n(19),o=n(5),s=n(30),u=n(62).KEY,c=n(12),l=n(114),f=n(94),d=n(79),h=n(16),p=n(281),m=n(191),g=n(688),v=n(134),y=n(6),b=n(13),x=n(22),w=n(35),k=n(52),_=n(80),E=n(76),O=n(278),S=n(34),C=n(135),A=n(21),N=n(78),T=S.f,I=A.f,D=O.f,M=r.Symbol,R=r.JSON,F=R&&R.stringify,j=h("_hidden"),P=h("toPrimitive"),L={}.propertyIsEnumerable,z=l("symbol-registry"),B=l("symbols"),U=l("op-symbols"),W=Object.prototype,V="function"==typeof M&&!!C.f,q=r.QObject,H=!q||!q.prototype||!q.prototype.findChild,G=a&&c(function(){return 7!=E(I({},"a",{get:function(){return I(this,"a",{value:7}).a}})).a})?function(t,e,n){var r=T(W,e);r&&delete W[e],I(t,e,n),r&&t!==W&&I(W,e,r)}:I,$=function(t){var e=B[t]=E(M.prototype);return e._k=t,e},K=V&&"symbol"==typeof M.iterator?function(t){return"symbol"==typeof t}:function(t){return t instanceof M},X=function(t,e,n){return t===W&&X(U,e,n),y(t),e=k(e,!0),y(n),i(B,e)?(n.enumerable?(i(t,j)&&t[j][e]&&(t[j][e]=!1),n=E(n,{enumerable:_(0,!1)})):(i(t,j)||I(t,j,_(1,{})),t[j][e]=!0),G(t,e,n)):I(t,e,n)},Y=function(t,e){y(t);for(var n,r=g(e=w(e)),i=0,a=r.length;a>i;)X(t,n=r[i++],e[n]);return t},J=function(t){var e=L.call(this,t=k(t,!0));return!(this===W&&i(B,t)&&!i(U,t))&&(!(e||!i(this,t)||!i(B,t)||i(this,j)&&this[j][t])||e)},Z=function(t,e){if(t=w(t),e=k(e,!0),t!==W||!i(B,e)||i(U,e)){var n=T(t,e);return!n||!i(B,e)||i(t,j)&&t[j][e]||(n.enumerable=!0),n}},Q=function(t){for(var e,n=D(w(t)),r=[],a=0;n.length>a;)i(B,e=n[a++])||e==j||e==u||r.push(e);return r},tt=function(t){for(var e,n=t===W,r=D(n?U:w(t)),a=[],o=0;r.length>o;)!i(B,e=r[o++])||n&&!i(W,e)||a.push(B[e]);return a};V||(s((M=function(){if(this instanceof M)throw TypeError("Symbol is not a constructor!");var t=d(arguments.length>0?arguments[0]:void 0),e=function(n){this===W&&e.call(U,n),i(this,j)&&i(this[j],t)&&(this[j][t]=!1),G(this,t,_(1,n))};return a&&H&&G(W,t,{configurable:!0,set:e}),$(t)}).prototype,"toString",function(){return this._k}),S.f=Z,A.f=X,n(75).f=O.f=Q,n(112).f=J,C.f=tt,a&&!n(63)&&s(W,"propertyIsEnumerable",J,!0),p.f=function(t){return $(h(t))}),o(o.G+o.W+o.F*!V,{Symbol:M});for(var et="hasInstance,isConcatSpreadable,iterator,match,replace,search,species,split,toPrimitive,toStringTag,unscopables".split(","),nt=0;et.length>nt;)h(et[nt++]);for(var rt=N(h.store),it=0;rt.length>it;)m(rt[it++]);o(o.S+o.F*!V,"Symbol",{for:function(t){return i(z,t+="")?z[t]:z[t]=M(t)},keyFor:function(t){if(!K(t))throw TypeError(t+" is not a symbol!");for(var e in z)if(z[e]===t)return e},useSetter:function(){H=!0},useSimple:function(){H=!1}}),o(o.S+o.F*!V,"Object",{create:function(t,e){return void 0===e?E(t):Y(E(t),e)},defineProperty:X,defineProperties:Y,getOwnPropertyDescriptor:Z,getOwnPropertyNames:Q,getOwnPropertySymbols:tt});var at=c(function(){C.f(1)});o(o.S+o.F*at,"Object",{getOwnPropertySymbols:function(t){return C.f(x(t))}}),R&&o(o.S+o.F*(!V||c(function(){var t=M();return"[null]"!=F([t])||"{}"!=F({a:t})||"{}"!=F(Object(t))})),"JSON",{stringify:function(t){for(var e,n,r=[t],i=1;arguments.length>i;)r.push(arguments[i++]);if(n=e=r[1],(b(e)||void 0!==t)&&!K(t))return v(e)||(e=function(t,e){if("function"==typeof n&&(e=n.call(this,t,e)),!K(e))return e}),r[1]=e,F.apply(R,r)}}),M.prototype[P]||n(31)(M.prototype,P,M.prototype.valueOf),f(M,"Symbol"),f(Math,"Math",!0),f(r.JSON,"JSON",!0)},function(t,e,n){n(690),n(687),n(686),n(685),n(684),n(683),n(682),n(681),n(680),n(679),n(678),n(677),n(676),n(675),n(674),n(673),n(672),n(671),n(670),n(669),n(668),n(667),n(666),n(665),n(664),n(663),n(662),n(661),n(660),n(659),n(658),n(657),n(656),n(655),n(654),n(653),n(652),n(651),n(650),n(649),n(648),n(647),n(646),n(645),n(644),n(643),n(642),n(641),n(640),n(639),n(638),n(637),n(636),n(635),n(634),n(633),n(632),n(631),n(630),n(629),n(628),n(627),n(626),n(625),n(624),n(623),n(622),n(621),n(620),n(619),n(618),n(617),n(616),n(615),n(614),n(613),n(612),n(610),n(609),n(607),n(606),n(605),n(604),n(603),n(602),n(601),n(599),n(598),n(597),n(596),n(595),n(594),n(593),n(592),n(591),n(590),n(589),n(588),n(587),n(172),n(586),n(263),n(585),n(262),n(584),n(583),n(582),n(581),n(580),n(259),n(257),n(256),n(579),n(578),n(577),n(576),n(575),n(574),n(573),n(572),n(571),n(570),n(569),n(568),n(567),n(566),n(565),n(564),n(563),n(562),n(561),n(560),n(559),n(558),n(557),n(556),n(555),n(554),n(553),n(552),n(551),n(550),n(549),n(548),n(547),n(546),n(545),n(544),n(543),n(542),n(541),n(540),n(539),n(538),n(537),n(536),n(535),n(534),n(533),n(532),n(531),n(530),n(529),n(528),n(527),n(526),n(525),n(524),n(523),n(522),n(521),n(520),n(519),n(518),n(517),n(516),n(515),n(514),n(513),n(512),n(511),n(510),n(509),n(508),n(507),n(506),n(505),n(504),n(503),n(502),n(501),n(500),n(499),n(498),n(497),n(496),n(495),t.exports=n(44)},function(t,e,n){"use strict";(function(t){if(n(691),n(494),n(493),t._babelPolyfill)throw new Error("only one instance of babel-polyfill is allowed");t._babelPolyfill=!0;var e="defineProperty";function r(t,n,r){t[n]||Object[e](t,n,{writable:!0,configurable:!0,value:r})}r(String.prototype,"padLeft","".padStart),r(String.prototype,"padRight","".padEnd),"pop,reverse,shift,keys,values,entries,indexOf,every,some,forEach,map,filter,find,findIndex,includes,join,slice,concat,push,splice,unshift,sort,lastIndexOf,reduce,reduceRight,copyWithin,fill".split(",").forEach(function(t){[][t]&&r(Array,t,Function.call.bind([][t]))})}).call(this,n(53))},function(t,e,n){n(692),t.exports=n(490)}])});
  549. //# sourceMappingURL=ml5.min.js.map