@picovoice/web-utils
Advanced tools
Comparing version 1.4.1 to 1.4.2
@@ -1,1 +0,1 @@ | ||
function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var e={exports:{}},r={exports:{}};!function(t){function e(r){return t.exports=e="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},t.exports.__esModule=!0,t.exports.default=t.exports,e(r)}t.exports=e,t.exports.__esModule=!0,t.exports.default=t.exports}(r);var n=r.exports;!function(t){var e=n.default;function r(){t.exports=r=function(){return o},t.exports.__esModule=!0,t.exports.default=t.exports;var n,o={},i=Object.prototype,a=i.hasOwnProperty,s=Object.defineProperty||function(t,e,r){t[e]=r.value},c="function"==typeof Symbol?Symbol:{},u=c.iterator||"@@iterator",f=c.asyncIterator||"@@asyncIterator",l=c.toStringTag||"@@toStringTag";function p(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{p({},"")}catch(n){p=function(t,e,r){return t[e]=r}}function h(t,e,r,n){var o=e&&e.prototype instanceof w?e:w,i=Object.create(o.prototype),a=new T(n||[]);return s(i,"_invoke",{value:j(t,r,a)}),i}function d(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}o.wrap=h;var v="suspendedStart",_="suspendedYield",y="executing",m="completed",g={};function w(){}function b(){}function x(){}var E={};p(E,u,(function(){return this}));var k=Object.getPrototypeOf,S=k&&k(k(L([])));S&&S!==i&&a.call(S,u)&&(E=S);var P=x.prototype=w.prototype=Object.create(E);function O(t){["next","throw","return"].forEach((function(e){p(t,e,(function(t){return this._invoke(e,t)}))}))}function A(t,r){function n(o,i,s,c){var u=d(t[o],t,i);if("throw"!==u.type){var f=u.arg,l=f.value;return l&&"object"==e(l)&&a.call(l,"__await")?r.resolve(l.__await).then((function(t){n("next",t,s,c)}),(function(t){n("throw",t,s,c)})):r.resolve(l).then((function(t){f.value=t,s(f)}),(function(t){return n("throw",t,s,c)}))}c(u.arg)}var o;s(this,"_invoke",{value:function(t,e){function i(){return new r((function(r,o){n(t,e,r,o)}))}return o=o?o.then(i,i):i()}})}function j(t,e,r){var o=v;return function(i,a){if(o===y)throw new Error("Generator is already running");if(o===m){if("throw"===i)throw a;return{value:n,done:!0}}for(r.method=i,r.arg=a;;){var s=r.delegate;if(s){var c=F(s,r);if(c){if(c===g)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(o===v)throw o=m,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=y;var u=d(t,e,r);if("normal"===u.type){if(o=r.done?m:_,u.arg===g)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(o=m,r.method="throw",r.arg=u.arg)}}}function F(t,e){var r=e.method,o=t.iterator[r];if(o===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=n,F(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),g;var i=d(o,t.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,g;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,g):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,g)}function I(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(I,this),this.reset(!0)}function L(t){if(t||""===t){var r=t[u];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function e(){for(;++o<t.length;)if(a.call(t,o))return e.value=t[o],e.done=!1,e;return e.value=n,e.done=!0,e};return i.next=i}}throw new TypeError(e(t)+" is not iterable")}return b.prototype=x,s(P,"constructor",{value:x,configurable:!0}),s(x,"constructor",{value:b,configurable:!0}),b.displayName=p(x,l,"GeneratorFunction"),o.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===b||"GeneratorFunction"===(e.displayName||e.name))},o.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,p(t,l,"GeneratorFunction")),t.prototype=Object.create(P),t},o.awrap=function(t){return{__await:t}},O(A.prototype),p(A.prototype,f,(function(){return this})),o.AsyncIterator=A,o.async=function(t,e,r,n,i){void 0===i&&(i=Promise);var a=new A(h(t,e,r,n),i);return o.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},O(P),p(P,l,"Generator"),p(P,u,(function(){return this})),p(P,"toString",(function(){return"[object Generator]"})),o.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},o.values=L,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)&&a.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,o){return s.type="throw",s.arg=t,e.next=r,o&&(e.method="next",e.arg=n),!!o}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],s=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var c=a.call(i,"catchLoc"),u=a.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&a.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,g):this.complete(i)},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),g},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),N(r),g}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;N(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:L(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=n),g}},o}t.exports=r,t.exports.__esModule=!0,t.exports.default=t.exports}(e);var o=(0,e.exports)(),i=o;try{regeneratorRuntime=o}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=o:Function("r","regeneratorRuntime = r")(o)}var a=t(i);function s(t,e,r,n){return new(r||(r=Promise))((function(o,i){function a(t){try{c(n.next(t))}catch(t){i(t)}}function s(t){try{c(n.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,s)}c((n=n.apply(t,e||[])).next())}))}const c=new WeakMap;function u(t,e){return new Proxy(t,{get:(t,r)=>e(t[r])})}class f{constructor(){this.value=void 0,this.exports=null}getState(){return this.exports.asyncify_get_state()}assertNoneState(){let t=this.getState();if(0!==t)throw new Error(`Invalid async state ${t}, expected 0.`)}wrapImportFn(t){return(...e)=>{if(2===this.getState())return this.exports.asyncify_stop_rewind(),this.value;this.assertNoneState();let r=t(...e);if(!(n=r)||"object"!=typeof n&&"function"!=typeof n||"function"!=typeof n.then)return r;var n;this.exports.asyncify_start_unwind(16),this.value=r}}wrapModuleImports(t){return u(t,(t=>"function"==typeof t?this.wrapImportFn(t):t))}wrapImports(t){if(void 0!==t)return u(t,((t=Object.create(null))=>this.wrapModuleImports(t)))}wrapExportFn(t){let e=c.get(t);return void 0!==e||(e=async(...e)=>{this.assertNoneState();let r=t(...e);for(;1===this.getState();)this.exports.asyncify_stop_unwind(),this.value=await this.value,this.assertNoneState(),this.exports.asyncify_start_rewind(16),r=t();return this.assertNoneState(),r},c.set(t,e)),e}wrapExports(t){let e=Object.create(null);for(let r in t){let n=t[r];"function"!=typeof n||r.startsWith("asyncify_")||(n=this.wrapExportFn(n)),Object.defineProperty(e,r,{enumerable:!0,value:n})}return c.set(t,e),e}init(t,e){const{exports:r}=t,n=r.memory||e.env&&e.env.memory;new Int32Array(n.buffer,16).set([24,1024]),this.exports=this.wrapExports(r),Object.setPrototypeOf(t,l.prototype)}}class l extends WebAssembly.Instance{constructor(t,e){let r=new f;super(t,r.wrapImports(e)),r.init(this,e)}get exports(){return c.get(super.exports)}}async function p(t,e){let r=new f,n=await WebAssembly.instantiate(t,r.wrapImports(e));return r.init(n instanceof WebAssembly.Instance?n:n.instance,e),n}async function h(t,e){let r=new f,n=await WebAssembly.instantiateStreaming(t,r.wrapImports(e));return r.init(n.instance,e),n}function d(t,e){return d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},d(t,e)}function v(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&d(t,e)}function _(t){return _="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},_(t)}function y(t,e){if(e&&("object"===_(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function m(t){return m=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},m(t)}function g(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function w(t){var e=function(t,e){if("object"!==_(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!==_(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"===_(e)?e:String(e)}function b(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,w(n.key),n)}}function x(t,e,r){return e&&b(t.prototype,e),r&&b(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}Object.defineProperty(l.prototype,"exports",{enumerable:!0});var E=function(){function t(){g(this,t),this._path=""}return x(t,[{key:"meta",get:function(){if(void 0!==this._meta)return Object.assign({version:0},this._meta)}},{key:"pageSize",get:function(){}}],[{key:"getPtr",value:function(e){if(t._filePtrs.has(e))return t._filePtrs.get(e);throw new Error("File instance not found.")}},{key:"setPtr",value:function(e,r){t._filePtrs.set(e,r)}},{key:"removePtr",value:function(e){t._filePtrs.delete(e)}}]),t}();function k(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=m(t);if(e){var o=m(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return y(this,r)}}E._filePtrs=new Map;var S="pv_db",P="pv_file";function O(){return new Promise((function(t,e){var r=self.indexedDB.open(S,3);r.onerror=function(){e(r.error)},r.onsuccess=function(){t(r.result)},r.onupgradeneeded=function(){r.result.objectStoreNames.contains(P)||r.result.createObjectStore(P)}}))}var A=function(){function t(){g(this,t),this._pos=0,this._data=new Uint8Array}return x(t,[{key:"get",value:function(t){if(!(this._pos>=this._data.length)){var e=this._data.slice(this._pos,this._pos+t);return this._pos+=t,e}}},{key:"set",value:function(t,e){this._pos=t,this._data=e}},{key:"clear",value:function(){this._pos=0,this._data=new Uint8Array}}]),t}(),j=function(t){v(r,E);var e=k(r);function r(t,n,o,i){var a;return g(this,r),(a=e.call(this))._pageSize=524288,a._pagePtr=0,a._pageOffset=0,a._path=t,a._meta=n,a._db=o,a._mode=i,a._cache=new A,a}return x(r,[{key:"pageSize",get:function(){return this._pageSize}},{key:"close",value:function(){return s(this,void 0,void 0,a.mark((function t(){return a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:this._db.close();case 1:case"end":return t.stop()}}),t,this)})))}},{key:"read",value:function(t,e){return s(this,void 0,void 0,a.mark((function n(){var o=this;return a.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",new Promise((function(n,i){if(o.exists()){if(o._isEOF){var a=new Error("EOF");return a.name="EndOfFile",void i(a)}var s=0,c=Math.min(t*e,o._meta.size),u=c-c%t,f=new Uint8Array(u),l=o._cache.get(u);if(l){if(s+=l.length,o._pageOffset+=l.length,o._pageOffset===o._pageSize&&(o._pagePtr+=1,o._pageOffset=0),u===s)return void n(l);f.set(l)}var p=IDBKeyRange.bound("".concat(o._path,"-").concat(r.createPage(o._pagePtr)),"".concat(o._path,"-").concat(r.createPage(o._pagePtr+Math.floor(u/o._pageSize)+1))),h=o._store,d=h.openCursor(p);d.onsuccess=function(){var t,e,r=d.result;if(r&&!o._isEOF){var n=Math.min(u-s,r.value.length-o._pageOffset);f.set(r.value.slice(o._pageOffset,o._pageOffset+n),s),s+=n,o._pageOffset+=n,o._pageOffset===o._pageSize&&(o._pagePtr+=1,o._pageOffset=0),s<u?r.continue():(0!==o._pageOffset?o._cache.set(o._pageOffset,r.value):o._cache.clear(),(null===(t=h.transaction)||void 0===t?void 0:t.commit)&&(null===(e=h.transaction)||void 0===e||e.commit()))}},h.transaction.onerror=function(){i(h.transaction.error)},h.transaction.oncomplete=function(){n(f.slice(0,s))}}else i(new Error("'".concat(o._path,"' doesn't exist.")))})));case 1:case"end":return n.stop()}}),n)})))}},{key:"write",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return s(this,void 0,void 0,a.mark((function n(){var o=this;return a.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",new Promise((function(n,i){return s(o,void 0,void 0,a.mark((function o(){var s,c,u,f,l,p,h,d,v,_,y,m=this;return a.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:if("readonly"!==this._mode){o.next=3;break}return i(new Error("Instance is readonly mode only.")),o.abrupt("return");case 3:if(!("number"!=typeof e&&e<=0)){o.next=6;break}return i(new Error("Version should be a positive number")),o.abrupt("return");case 6:return u=this._store,f=function(){return new Promise((function(t){var e=u.get("".concat(m._path,"-").concat(r.createPage(m._pagePtr)));e.onsuccess=function(){void 0!==e.result?t(e.result.slice(0,m._pageOffset)):t(new Uint8Array(0))}}))},o.next=10,f();case 10:for(l=o.sent,(p=new Uint8Array(l.length+t.length)).set(l),p.set(t,l.length),h=this._pagePtr*this._pageSize+p.length,d={size:h,numPages:Math.ceil(h/this._pageSize),version:e,pageSize:this._pageSize},u.put(d,this._path),v=Math.ceil(p.length/this._pageSize),_=0;_<v;_++)u.put(p.slice(_*this._pageSize,(_+1)*this._pageSize),"".concat(this._path,"-").concat(r.createPage(this._pagePtr+_)));this.exists()&&d.numPages<this._meta.numPages&&(y=IDBKeyRange.bound("".concat(this._path,"-").concat(r.createPage(d.numPages)),"".concat(this._path,"-").concat(r.createPage(this._meta.numPages)),!0),u.delete(y)),(null===(s=u.transaction)||void 0===s?void 0:s.commit)&&(null===(c=u.transaction)||void 0===c||c.commit()),u.transaction.onerror=function(){i(u.transaction.error)},u.transaction.oncomplete=function(){m._meta=d,m.seek(0,2),n()};case 23:case"end":return o.stop()}}),o,this)})))})));case 1:case"end":return n.stop()}}),n)})))}},{key:"seek",value:function(t,e){if(!this.exists()&&"readonly"===this._mode)throw new Error("'".concat(this._path,"' doesn't exist."));if(!this.exists())throw new Error("'".concat(this._path,"' doesn't exist."));if(t<0){var r=new Error("EOF");throw r.name="EndOfFile",r}var n;if(0===e)n=Math.min(t,this._meta.size);else if(1===e){var o=this._pageSize*this._pagePtr+this._pageOffset;n=Math.min(o+t,this._meta.size)}else{if(2!==e)throw new Error("Invalid operation: ".concat(e,"."));n=Math.min(this._meta.size+t,this._meta.size)}this._pageOffset=n%this._pageSize,this._pagePtr=Math.floor(n/this._pageSize),this._cache.clear()}},{key:"tell",value:function(){return this.exists()?this._pagePtr*this._pageSize+this._pageOffset:-1}},{key:"remove",value:function(){return s(this,void 0,void 0,a.mark((function t(){var e=this;return a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise((function(t,n){return s(e,void 0,void 0,a.mark((function e(){var o,i,s,c,u=this;return a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.exists()){e.next=3;break}return n(new Error("ENOENT")),e.abrupt("return");case 3:o=this._meta.numPages,i=IDBKeyRange.bound(this._path,"".concat(this._path,"-").concat(r.createPage(o))),s=this._store,(c=s.delete(i)).onerror=function(){n(c.error)},c.onsuccess=function(){u._meta=void 0,u._pageOffset=0,u._pagePtr=0,t()};case 9:case"end":return e.stop()}}),e,this)})))})));case 1:case"end":return t.stop()}}),t)})))}},{key:"exists",value:function(){return void 0!==this._meta}},{key:"_isEOF",get:function(){return this._pagePtr>=this._meta.numPages-1&&this._pageOffset>=this._meta.size%this._pageSize}},{key:"_store",get:function(){return this._db.transaction(P,this._mode).objectStore(P)}}],[{key:"open",value:function(t,e){var n=this;if(!self.indexedDB){var o=new Error("IndexedDB is not supported");throw o.name="IndexedDBNotSupported",o}return new Promise((function(o,i){return s(n,void 0,void 0,a.mark((function n(){var s,c,u;return a.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,n.next=3,O();case 3:s=n.sent,(c=s.transaction(P,"readwrite").objectStore(P).get(t)).onerror=function(){i(c.error)},c.onsuccess=function(){var n=c.result,a=e.includes("r")?"readonly":"readwrite";if(void 0===n&&"readonly"===a){var u=new Error("'".concat(t,"' doesn't exist."));return u.name="FileNotExists",void i(u)}var f=new r(t,n,s,a);e.includes("a")&&f.seek(0,2),o(f)},n.next=12;break;case 9:n.prev=9,n.t0=n.catch(0),"InvalidStateError"===n.t0.name?((u=new Error("IndexedDB is not supported")).name="IndexedDBNotSupported",i(u)):i(n.t0);case 12:case"end":return n.stop()}}),n,null,[[0,9]])})))}))}},{key:"createPage",value:function(t){return("00000"+t).slice(-6)}}]),r}();function F(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=m(t);if(e){var o=m(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return y(this,r)}}var I=function(t){v(r,E);var e=F(r);function r(t,n,o,i){var a;return g(this,r),(a=e.call(this))._pos=0,a._path=t,a._meta=n,a._mode=i,a}return x(r,[{key:"close",value:function(){}},{key:"read",value:function(t,e){if(!this.exists())throw new Error("'".concat(this._path,"' doesn't exist."));if(this._isEOF){var r=new Error("EOF");throw r.name="EndOfFile",r}var n=Math.min(t*e,this._file.length-this._pos),o=n-n%t,i=new Uint8Array(o);return i.set(this._file.slice(this._pos,this._pos+o),0),this._pos+=o,i}},{key:"write",value:function(t){var e=new Uint8Array(this._pos+t.length);void 0!==this._file?(e.set(this._file.slice(0,this._pos)),e.set(t,this._pos)):e.set(t),this._file=e,this._pos+=t.length}},{key:"seek",value:function(t,e){if(!this.exists()&&"readonly"===this._mode)throw new Error("'".concat(this._path,"' doesn't exist."));if(!this.exists())throw new Error("'".concat(this._path,"' doesn't exist."));if(t<0){var r=new Error("EOF");throw r.name="EndOfFile",r}var n;if(0===e)n=Math.min(t,this._file.length);else if(1===e)n=Math.min(this._pos+t,this._file.length);else{if(2!==e)throw new Error("Invalid operation: ".concat(e,"."));n=Math.min(this._file.length+t,this._file.length)}this._pos=n}},{key:"tell",value:function(){return this.exists()?this._pos:-1}},{key:"remove",value:function(){return s(this,void 0,void 0,a.mark((function t(){return a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.exists()){t.next=2;break}throw new Error("ENOENT");case 2:r._memFiles.delete(this._path),this._pos=0;case 4:case"end":return t.stop()}}),t,this)})))}},{key:"exists",value:function(){return void 0!==this._file}},{key:"_isEOF",get:function(){return this._pos>=this._file.length}},{key:"_file",get:function(){return r._memFiles.get(this._path)},set:function(t){r._memFiles.set(this._path,t)}}],[{key:"open",value:function(t,e){var n=r._memFiles.get(t),o=e.includes("r")?"readonly":"readwrite";if(void 0===n&&"readonly"===o){var i=new Error("'".concat(t,"' doesn't exist."));throw i.name="FileNotExists",i}var a=new r(t,void 0,void 0,o);return e.includes("a")&&a.seek(0,2),a}}]),r}();function N(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return T(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return T(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,s=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw i}}}}function T(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function L(t){return t<0?t>>>0:t}function M(t,e){for(var r=e;0!==t[r];)r++;return new TextDecoder("utf-8").decode(t.subarray(e,r))}function R(t){for(var e=atob(t),r=new Uint8Array(e.length),n=0;n<e.length;n++)r[n]=e.charCodeAt(n);return r}function z(t,e,r){for(var n="",o=0;o<e;o++)n+=String.fromCharCode(t[r+o]);return btoa(n)}function U(t){var e,r={},n=N(t.split("\r\n"));try{for(n.s();!(e=n.n()).done;){var o=e.value.split(": ");""!==o[0]&&(r[o[0]]=o[1])}}catch(t){n.e(t)}finally{n.f()}return r}function B(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:5e3;return s(this,void 0,void 0,a.mark((function n(){var o,i,s,c;return a.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return o=new AbortController,i=Object.assign(Object.assign({},e),{signal:o.signal}),s=setTimeout((function(){o.abort()}),r),n.next=5,fetch(t,i);case 5:return c=n.sent,clearTimeout(s),n.abrupt("return",c);case 8:case"end":return n.stop()}}),n)})))}function W(t){if("string"!=typeof t)return!1;var e=t.trim();if(""===e)return!1;try{return btoa(atob(e))===e}catch(t){return!1}}function D(t,e){return s(this,void 0,void 0,a.mark((function r(){var n;return a.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.prev=0,r.next=3,j.open(t,e);case 3:return r.abrupt("return",r.sent);case 6:if(r.prev=6,r.t0=r.catch(0),"IndexedDBNotSupported"===r.t0.name?console.warn("IndexedDB is not supported. Fallback to in-memory storage."):"FileNotExists"!==r.t0.name&&console.warn("Unable to access IndexedDB (".concat(r.t0.toString(),"). Fallback to in-memory storage.")),!("undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope)){r.next=16;break}if("FileNotExists"!==r.t0.name){r.next=12;break}throw r.t0;case 12:throw console.error("In-memory storage cannot be used inside a worker."),(n=new Error("Failed to start PvFile: ".concat(r.t0.toString()))).name="PvFileNotSupported",n;case 16:return r.abrupt("return",I.open(t,e));case 17:case"end":return r.stop()}}),r,null,[[0,6]])})))}function C(t,e,r,n){return s(this,void 0,void 0,a.mark((function o(){var i;return a.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return o.next=2,D(t,"w");case 2:if(i=o.sent,!(r||void 0===i.meta||n>i.meta.version||i.meta.pageSize!==i.pageSize)){o.next=6;break}return o.next=6,i.write(R(e),n);case 6:case"end":return o.stop()}}),o)})))}I._memFiles=new Map;var G=5e3,Y=2;function q(t,e,r,n,o){return s(this,void 0,void 0,a.mark((function i(){var s,c,u,f,l,p,h,d;return a.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return i.next=2,D(t,"w");case 2:if(s=i.sent,!(r||void 0===s.meta||n>s.meta.version||s.meta.pageSize!==s.pageSize)){i.next=43;break}if(!(o<0)){i.next=6;break}throw Error("numFetchRetries must be a positive number");case 6:c=Y,u=function(t){return new Promise((function(e){setTimeout(e,t)}))},f=o+1,l=null;case 10:if(!(f>0)){i.next=38;break}return l=null,i.prev=12,i.next=15,fetch(e,{cache:"no-cache"});case 15:if(!(p=i.sent).ok){i.next=23;break}return i.next=19,p.arrayBuffer();case 19:return h=i.sent,i.next=22,s.write(new Uint8Array(h),n);case 22:return i.abrupt("return");case 23:return i.next=25,p.text();case 25:d=i.sent,l=new Error("Error response returned while fetching model from '".concat(e,"': ").concat(d)),i.next=32;break;case 29:i.prev=29,i.t0=i.catch(12),l=new Error("Failed to fetch model from '".concat(e,"': ").concat(i.t0.message));case 32:return f--,i.next=35,u(c);case 35:c=Math.min(G,c*Y),i.next=10;break;case 38:if(null===l){i.next=42;break}throw l;case 42:throw new Error("Unexpected error encountered while fetching model from '".concat(e,"'"));case 43:case"end":return i.stop()}}),i,null,[[12,29]])})))}function H(t){return s(this,void 0,void 0,a.mark((function e(){var r,n,o,i,s,c,u,f,l;return a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=t){e.next=2;break}throw new Error("The model is undefined / empty");case 2:if(r=t.base64,n=t.publicPath,o=t.customWritePath,i=t.forceWrite,s=void 0!==i&&i,c=t.version,u=void 0===c?1:c,f=t.numFetchRetries,l=void 0===f?0:f,null!=o){e.next=5;break}throw new Error("The customWritePath of the provided model is undefined / empty");case 5:if(null==r){e.next=10;break}return e.next=8,C(o,r,s,u);case 8:case 13:e.next=16;break;case 10:if(null==n){e.next=15;break}return e.next=13,q(o,n,s,u,l);case 15:throw new Error("The provided model doesn't contain a valid publicPath or base64 value");case 16:return e.abrupt("return",o);case 17:case"end":return e.stop()}}),e)})))}var K={args_get:function(t){return 0},args_sizes_get:function(t){return 0},environ_get:function(t){return 0},environ_sizes_get:function(t){return 0},clock_res_get:function(t){return 0},clock_time_get:function(t){return 0},fd_advise:function(t){return 0},fd_allocate:function(t){return 0},fd_close:function(t){return 0},fd_datasync:function(t){return 0},fd_fdstat_get:function(t){return 0},fd_fdstat_set_flags:function(t){return 0},fd_fdstat_set_rights:function(t){return 0},fd_filestat_get:function(t){return 0},fd_filestat_set_size:function(t){return 0},fd_filestat_set_times:function(t){return 0},fd_pread:function(t){return 0},fd_prestat_get:function(t){return 0},fd_prestat_dir_name:function(t){return 0},fd_pwrite:function(t){return 0},fd_read:function(t){return 0},fd_readdir:function(t){return 0},fd_renumber:function(t){return 0},fd_seek:function(t){return 0},fd_sync:function(t){return 0},fd_tell:function(t){return 0},fd_write:function(t){return 0},path_create_directory:function(t){return 0},path_filestat_get:function(t){return 0},path_filestat_set_times:function(t){return 0},path_link:function(t){return 0},path_open:function(t){return 0},path_readlink:function(t){return 0},path_remove_directory:function(t){return 0},path_rename:function(t){return 0},path_symlink:function(t){return 0},path_unlink_file:function(t){return 0},poll_oneoff:function(t){return 0},proc_exit:function(t){return 0},proc_raise:function(t){return 0},sched_yield:function(t){return 0},random_get:function(t){return 0},sock_recv:function(t){return 0},sock_send:function(t){return 0},sock_shutdown:function(t){return 0}};function V(t,e,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return s(this,void 0,void 0,a.mark((function o(){var i,c,u,f,l,d,v,_,y,m,g,w,b,x,k,S,P,O,A,j,F;return a.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:if(i=function(e,r){new Int32Array(t.buffer)[e/Int32Array.BYTES_PER_ELEMENT]=r},c=function(t,e){return s(this,void 0,void 0,a.mark((function r(){var n;return a.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,F(t,e);case 2:return n=r.sent,r.abrupt("return",L(n));case 4:case"end":return r.stop()}}),r)})))},u=function(e){e=L(e);var r=new Uint8Array(t.buffer);console.log(M(r,e))},f=function(e,r,n){n=L(n);var o=new Uint8Array(t.buffer);if(0===e){var i=M(o,n);throw new Error("assertion failed at line ".concat(r,' in "').concat(i,'"'))}},l=function(){return Date.now()/1e3},d=function(e,n,o,u,f,l,p,h,d){return s(this,void 0,void 0,a.mark((function s(){var v,_,y,m,g,w,b,x,E,k,S,P,O;return a.wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return e=L(e),n=L(n),o=L(o),u=L(u),f=L(f),p=L(p),h=L(h),d=L(d),v=new Uint8Array(t.buffer),_=M(v,e),y=M(v,n),m=M(v,o),g=M(v,u),w=M(v,f),b=U(g),x={method:_},w.length>0&&(x.body=w),Object.keys(b).length>0&&(x.headers=b),a.prev=18,a.next=21,B("https://"+y+m,x,l);case 21:E=a.sent,S=E.status,a.next=29;break;case 25:return a.prev=25,a.t0=a.catch(18),null==r||r.addError("pvHttpsRequestWasm","Failed to fetch: ".concat(a.t0)),a.abrupt("return");case 29:return a.prev=29,a.next=32,E.text();case 32:k=a.sent,a.next=39;break;case 35:return a.prev=35,a.t1=a.catch(29),null==r||r.addError("pvHttpsRequestWasm","Failed to get response text: ".concat(a.t1)),a.abrupt("return");case 39:return a.next=41,c(Int8Array.BYTES_PER_ELEMENT,(k.length+1)*Int8Array.BYTES_PER_ELEMENT);case 41:if(0!==(P=a.sent)){a.next=46;break}return null==r||r.addError("pvMallocError","pvHttpsRequestWasm: cannot allocate memory for response"),i(p,0),a.abrupt("return");case 46:for(i(h,k.length+1),i(p,P),O=0;O<k.length;O++)v[P+O]=k.charCodeAt(O);v[P+k.length]=0,i(d,S);case 51:case"end":return a.stop()}}),s,null,[[18,25],[29,35]])})))},v=function(e){return s(this,void 0,void 0,a.mark((function n(){var o,s,u,f;return a.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return e=L(e),o=new Uint8Array(t.buffer),s=void 0!==navigator.userAgent?navigator.userAgent:"unknown",n.next=5,c(Uint8Array.BYTES_PER_ELEMENT,(s.length+1)*Uint8Array.BYTES_PER_ELEMENT);case 5:if(0!==(u=n.sent)){n.next=10;break}return null==r||r.addError("pvMallocError","pvGetBrowserInfo: cannot allocate memory for browser info"),i(e,0),n.abrupt("return");case 10:for(i(e,u),f=0;f<s.length;f++)o[u+f]=s.charCodeAt(f);o[u+s.length]=0;case 13:case"end":return n.stop()}}),n)})))},_=function(e){var n;return s(this,void 0,void 0,a.mark((function o(){var s,u,f,l,p;return a.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return e=L(e),s=new Uint8Array(t.buffer),u=null!==(n=self.origin)&&void 0!==n?n:self.location.origin,f=new URL(u).hostname,o.next=6,c(Uint8Array.BYTES_PER_ELEMENT,(f.length+1)*Uint8Array.BYTES_PER_ELEMENT);case 6:if(0!==(l=o.sent)){o.next=11;break}return null==r||r.addError("pvMallocError","pvGetOriginInfo: cannot allocate memory for origin info"),i(e,0),o.abrupt("return");case 11:for(i(e,l),p=0;p<f.length;p++)s[l+p]=f.charCodeAt(p);s[l+f.length]=0;case 14:case"end":return o.stop()}}),o)})))},y=function(e,n,o,c){return s(this,void 0,void 0,a.mark((function s(){var u,f,l,p;return a.wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return e=L(e),n=L(n),o=L(o),c=L(c),u=new Uint8Array(t.buffer),f=M(u,n),l=M(u,o),a.prev=7,a.next=10,D(f,l);case 10:p=a.sent,E.setPtr(e,p),i(c,0),a.next=19;break;case 15:a.prev=15,a.t0=a.catch(7),"FileNotExists"!==a.t0.name&&(null==r||r.addError("pvFileOpenWasm",a.t0)),i(c,-1);case 19:case"end":return a.stop()}}),s,null,[[7,15]])})))},m=function(t,e){return s(this,void 0,void 0,a.mark((function n(){var o;return a.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return t=L(t),e=L(e),n.prev=2,n.next=5,E.getPtr(t);case 5:return o=n.sent,n.next=8,o.close();case 8:i(e,0),n.next=15;break;case 11:n.prev=11,n.t0=n.catch(2),null==r||r.addError("pvFileCloseWasm",n.t0),i(e,-1);case 15:case"end":return n.stop()}}),n,null,[[2,11]])})))},g=function(e,n,o,c,u){return s(this,void 0,void 0,a.mark((function s(){var f,l,p;return a.wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return e=L(e),n=L(n),u=L(u),f=new Uint8Array(t.buffer),a.prev=4,l=E.getPtr(e),a.next=8,l.read(o,c);case 8:p=a.sent,f.set(p,L(n)),i(u,p.length/o),a.next=17;break;case 13:a.prev=13,a.t0=a.catch(4),null==r||r.addError("pvFileReadWasm",a.t0),i(u,-1);case 17:case"end":return a.stop()}}),s,null,[[4,13]])})))},w=function(e,n,o,c,u){return s(this,void 0,void 0,a.mark((function s(){var f,l,p;return a.wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return e=L(e),n=L(n),u=L(u),f=new Uint8Array(t.buffer),a.prev=4,l=E.getPtr(e),(p=new Uint8Array(o*c)).set(f.slice(L(n),L(n)+o*c),0),a.next=10,l.write(p);case 10:i(u,p.length/o),a.next=17;break;case 13:a.prev=13,a.t0=a.catch(4),null==r||r.addError("pvFileWriteWasm",a.t0),i(u,-1);case 17:case"end":return a.stop()}}),s,null,[[4,13]])})))},b=function(t,e,n,o){t=L(t),o=L(o);try{E.getPtr(t).seek(e,n),i(o,0)}catch(t){null==r||r.addError("pvFileSeekWasm",t),i(o,-1)}},x=function(t,e){t=L(t),e=L(e);try{var n=E.getPtr(t);i(e,n.tell())}catch(t){null==r||r.addError("pvFileTellWasm",t),i(e,-1)}},k=function(e,n){return s(this,void 0,void 0,a.mark((function o(){var s,c,u;return a.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return e=L(e),n=L(n),s=new Uint8Array(t.buffer),c=M(s,e),o.prev=4,o.next=7,D(c,"w");case 7:return u=o.sent,o.next=10,u.remove();case 10:i(n,0),o.next=17;break;case 13:o.prev=13,o.t0=o.catch(4),null==r||r.addError("pvFileRemoveWasm",o.t0),i(n,-1);case 17:case"end":return o.stop()}}),o,null,[[4,13]])})))},S={wasi_snapshot_preview1:K,env:Object.assign({memory:t,pv_console_log_wasm:u,pv_assert_wasm:f,pv_time_wasm:l,pv_https_request_wasm:d,pv_get_browser_info:v,pv_get_origin_info:_,pv_file_open_wasm:y,pv_file_close_wasm:m,pv_file_read_wasm:g,pv_file_write_wasm:w,pv_file_seek_wasm:b,pv_file_tell_wasm:x,pv_file_remove_wasm:k},n)},!(e instanceof Promise)){o.next=34;break}if(!h){o.next=23;break}return o.next=20,h(e,S);case 20:P=o.sent.instance,o.next=32;break;case 23:return o.next=25,e;case 25:return O=o.sent,o.next=28,O.arrayBuffer();case 28:return A=o.sent,o.next=31,p(new Uint8Array(A),S);case 31:P=o.sent.instance;case 32:o.next=38;break;case 34:return j=R(e),o.next=37,p(j,S);case 37:P=o.sent.instance;case 38:return F=P.exports.aligned_alloc,o.abrupt("return",Object.assign(Object.assign({},P.exports),{aligned_alloc:c}));case 40:case"end":return o.stop()}}),o)})))}function $(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function J(t){return function(t){if(Array.isArray(t))return $(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return $(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?$(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var Q=function(){function t(){g(this,t),this._maxNumErrors=10,this._errors=[],this._lastError=new Error("null")}return x(t,[{key:"addError",value:function(t,e){this._lastError=e instanceof Error?e:new Error(e),this._errors.length>=this._maxNumErrors&&this._errors.shift(),e instanceof Error?this._errors.push({key:t,message:e.toString()}):this._errors.push({key:t,message:JSON.stringify(e)})}},{key:"getErrors",value:function(){var t=J(this._errors);return this._errors=[],t}},{key:"getErrorString",value:function(){return this.getErrors().map((function(t){var e=t.key,r=t.message;return"'".concat(e,"' failed with: ").concat(r,".")})).join("\n")}},{key:"getLastError",value:function(){return this._lastError}},{key:"setMaxErrorNum",value:function(t){this._maxNumErrors=t}}]),t}(),X={DB_NAME:S,DB_VERSION:3,PV_FILE_STORE:P};export{Q as PvError,E as PvFile,j as PvFileIDB,I as PvFileMem,z as arrayBufferToBase64AtIndex,M as arrayBufferToStringAtIndex,R as base64ToUint8Array,V as buildWasm,X as dbConfig,B as fetchWithTimeout,C as fromBase64,q as fromPublicDirectory,O as getDB,W as isAccessKeyValid,H as loadModel,D as open,U as stringHeaderToObject,L as unsignedAddress}; | ||
function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var e={exports:{}},r={exports:{}};!function(t){function e(r){return t.exports=e="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},t.exports.__esModule=!0,t.exports.default=t.exports,e(r)}t.exports=e,t.exports.__esModule=!0,t.exports.default=t.exports}(r);var n=r.exports;!function(t){var e=n.default;function r(){t.exports=r=function(){return o},t.exports.__esModule=!0,t.exports.default=t.exports;var n,o={},i=Object.prototype,a=i.hasOwnProperty,s=Object.defineProperty||function(t,e,r){t[e]=r.value},c="function"==typeof Symbol?Symbol:{},u=c.iterator||"@@iterator",f=c.asyncIterator||"@@asyncIterator",l=c.toStringTag||"@@toStringTag";function p(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{p({},"")}catch(n){p=function(t,e,r){return t[e]=r}}function h(t,e,r,n){var o=e&&e.prototype instanceof w?e:w,i=Object.create(o.prototype),a=new T(n||[]);return s(i,"_invoke",{value:j(t,r,a)}),i}function d(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}o.wrap=h;var v="suspendedStart",_="suspendedYield",m="executing",y="completed",g={};function w(){}function b(){}function x(){}var E={};p(E,u,(function(){return this}));var k=Object.getPrototypeOf,S=k&&k(k(L([])));S&&S!==i&&a.call(S,u)&&(E=S);var O=x.prototype=w.prototype=Object.create(E);function P(t){["next","throw","return"].forEach((function(e){p(t,e,(function(t){return this._invoke(e,t)}))}))}function A(t,r){function n(o,i,s,c){var u=d(t[o],t,i);if("throw"!==u.type){var f=u.arg,l=f.value;return l&&"object"==e(l)&&a.call(l,"__await")?r.resolve(l.__await).then((function(t){n("next",t,s,c)}),(function(t){n("throw",t,s,c)})):r.resolve(l).then((function(t){f.value=t,s(f)}),(function(t){return n("throw",t,s,c)}))}c(u.arg)}var o;s(this,"_invoke",{value:function(t,e){function i(){return new r((function(r,o){n(t,e,r,o)}))}return o=o?o.then(i,i):i()}})}function j(t,e,r){var o=v;return function(i,a){if(o===m)throw new Error("Generator is already running");if(o===y){if("throw"===i)throw a;return{value:n,done:!0}}for(r.method=i,r.arg=a;;){var s=r.delegate;if(s){var c=F(s,r);if(c){if(c===g)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(o===v)throw o=y,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=m;var u=d(t,e,r);if("normal"===u.type){if(o=r.done?y:_,u.arg===g)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(o=y,r.method="throw",r.arg=u.arg)}}}function F(t,e){var r=e.method,o=t.iterator[r];if(o===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=n,F(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),g;var i=d(o,t.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,g;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,g):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,g)}function I(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(I,this),this.reset(!0)}function L(t){if(t||""===t){var r=t[u];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function e(){for(;++o<t.length;)if(a.call(t,o))return e.value=t[o],e.done=!1,e;return e.value=n,e.done=!0,e};return i.next=i}}throw new TypeError(e(t)+" is not iterable")}return b.prototype=x,s(O,"constructor",{value:x,configurable:!0}),s(x,"constructor",{value:b,configurable:!0}),b.displayName=p(x,l,"GeneratorFunction"),o.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===b||"GeneratorFunction"===(e.displayName||e.name))},o.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,p(t,l,"GeneratorFunction")),t.prototype=Object.create(O),t},o.awrap=function(t){return{__await:t}},P(A.prototype),p(A.prototype,f,(function(){return this})),o.AsyncIterator=A,o.async=function(t,e,r,n,i){void 0===i&&(i=Promise);var a=new A(h(t,e,r,n),i);return o.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},P(O),p(O,l,"Generator"),p(O,u,(function(){return this})),p(O,"toString",(function(){return"[object Generator]"})),o.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},o.values=L,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)&&a.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,o){return s.type="throw",s.arg=t,e.next=r,o&&(e.method="next",e.arg=n),!!o}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],s=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var c=a.call(i,"catchLoc"),u=a.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&a.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,g):this.complete(i)},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),g},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),N(r),g}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;N(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:L(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=n),g}},o}t.exports=r,t.exports.__esModule=!0,t.exports.default=t.exports}(e);var o=(0,e.exports)(),i=o;try{regeneratorRuntime=o}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=o:Function("r","regeneratorRuntime = r")(o)}var a=t(i);function s(t,e,r,n){return new(r||(r=Promise))((function(o,i){function a(t){try{c(n.next(t))}catch(t){i(t)}}function s(t){try{c(n.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,s)}c((n=n.apply(t,e||[])).next())}))}const c=new WeakMap;function u(t,e){return new Proxy(t,{get:(t,r)=>e(t[r])})}class f{constructor(){this.value=void 0,this.exports=null}getState(){return this.exports.asyncify_get_state()}assertNoneState(){let t=this.getState();if(0!==t)throw new Error(`Invalid async state ${t}, expected 0.`)}wrapImportFn(t){return(...e)=>{if(2===this.getState())return this.exports.asyncify_stop_rewind(),this.value;this.assertNoneState();let r=t(...e);if(!(n=r)||"object"!=typeof n&&"function"!=typeof n||"function"!=typeof n.then)return r;var n;this.exports.asyncify_start_unwind(16),this.value=r}}wrapModuleImports(t){return u(t,(t=>"function"==typeof t?this.wrapImportFn(t):t))}wrapImports(t){if(void 0!==t)return u(t,((t=Object.create(null))=>this.wrapModuleImports(t)))}wrapExportFn(t){let e=c.get(t);return void 0!==e||(e=async(...e)=>{this.assertNoneState();let r=t(...e);for(;1===this.getState();)this.exports.asyncify_stop_unwind(),this.value=await this.value,this.assertNoneState(),this.exports.asyncify_start_rewind(16),r=t();return this.assertNoneState(),r},c.set(t,e)),e}wrapExports(t){let e=Object.create(null);for(let r in t){let n=t[r];"function"!=typeof n||r.startsWith("asyncify_")||(n=this.wrapExportFn(n)),Object.defineProperty(e,r,{enumerable:!0,value:n})}return c.set(t,e),e}init(t,e){const{exports:r}=t,n=r.memory||e.env&&e.env.memory;new Int32Array(n.buffer,16).set([24,1024]),this.exports=this.wrapExports(r),Object.setPrototypeOf(t,l.prototype)}}class l extends WebAssembly.Instance{constructor(t,e){let r=new f;super(t,r.wrapImports(e)),r.init(this,e)}get exports(){return c.get(super.exports)}}async function p(t,e){let r=new f,n=await WebAssembly.instantiate(t,r.wrapImports(e));return r.init(n instanceof WebAssembly.Instance?n:n.instance,e),n}async function h(t,e){let r=new f,n=await WebAssembly.instantiateStreaming(t,r.wrapImports(e));return r.init(n.instance,e),n}function d(t,e){return d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},d(t,e)}function v(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&d(t,e)}function _(t){return _="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},_(t)}function m(t,e){if(e&&("object"===_(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function y(t){return y=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},y(t)}function g(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function w(t){var e=function(t,e){if("object"!==_(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!==_(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"===_(e)?e:String(e)}function b(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,w(n.key),n)}}function x(t,e,r){return e&&b(t.prototype,e),r&&b(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}Object.defineProperty(l.prototype,"exports",{enumerable:!0});var E=function(){function t(){g(this,t),this._path=""}return x(t,[{key:"meta",get:function(){if(void 0!==this._meta)return Object.assign({version:0},this._meta)}},{key:"pageSize",get:function(){}}],[{key:"getPtr",value:function(e){if(t._filePtrs.has(e))return t._filePtrs.get(e);throw new Error("File instance not found.")}},{key:"setPtr",value:function(e,r){t._filePtrs.set(e,r)}},{key:"removePtr",value:function(e){t._filePtrs.delete(e)}}]),t}();function k(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=y(t);if(e){var o=y(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return m(this,r)}}E._filePtrs=new Map;var S="pv_db",O="pv_file";function P(){return new Promise((function(t,e){var r=self.indexedDB.open(S,3);r.onerror=function(){e(r.error)},r.onsuccess=function(){t(r.result)},r.onupgradeneeded=function(){r.result.objectStoreNames.contains(O)||r.result.createObjectStore(O)}}))}var A=function(){function t(){g(this,t),this._pos=0,this._data=new Uint8Array}return x(t,[{key:"get",value:function(t){if(!(this._pos>=this._data.length)){var e=this._data.slice(this._pos,this._pos+t);return this._pos+=t,e}}},{key:"set",value:function(t,e){this._pos=t,this._data=e}},{key:"clear",value:function(){this._pos=0,this._data=new Uint8Array}}]),t}(),j=function(t){v(r,E);var e=k(r);function r(t,n,o,i){var a;return g(this,r),(a=e.call(this))._pageSize=524288,a._pagePtr=0,a._pageOffset=0,a._path=t,a._meta=n,a._db=o,a._mode=i,a._cache=new A,a}return x(r,[{key:"pageSize",get:function(){return this._pageSize}},{key:"close",value:function(){return s(this,void 0,void 0,a.mark((function t(){return a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:this._db.close();case 1:case"end":return t.stop()}}),t,this)})))}},{key:"read",value:function(t,e){return s(this,void 0,void 0,a.mark((function n(){var o=this;return a.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",new Promise((function(n,i){if(o.exists()){if(o._isEOF){var a=new Error("EOF");return a.name="EndOfFile",void i(a)}var s=0,c=Math.min(t*e,o._meta.size),u=c-c%t,f=new Uint8Array(u),l=o._cache.get(u);if(l){if(s+=l.length,o._pageOffset+=l.length,o._pageOffset===o._pageSize&&(o._pagePtr+=1,o._pageOffset=0),u===s)return void n(l);f.set(l)}var p=IDBKeyRange.bound("".concat(o._path,"-").concat(r.createPage(o._pagePtr)),"".concat(o._path,"-").concat(r.createPage(o._pagePtr+Math.floor(u/o._pageSize)+1))),h=o._store,d=h.openCursor(p);d.onsuccess=function(){var t,e,r=d.result;if(r&&!o._isEOF){var n=Math.min(u-s,r.value.length-o._pageOffset);f.set(r.value.slice(o._pageOffset,o._pageOffset+n),s),s+=n,o._pageOffset+=n,o._pageOffset===o._pageSize&&(o._pagePtr+=1,o._pageOffset=0),s<u?r.continue():(0!==o._pageOffset?o._cache.set(o._pageOffset,r.value):o._cache.clear(),(null===(t=h.transaction)||void 0===t?void 0:t.commit)&&(null===(e=h.transaction)||void 0===e||e.commit()))}},h.transaction.onerror=function(){i(h.transaction.error)},h.transaction.oncomplete=function(){n(f.slice(0,s))}}else i(new Error("'".concat(o._path,"' doesn't exist.")))})));case 1:case"end":return n.stop()}}),n)})))}},{key:"write",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return s(this,void 0,void 0,a.mark((function n(){var o=this;return a.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",new Promise((function(n,i){return s(o,void 0,void 0,a.mark((function o(){var s,c,u,f,l,p,h,d,v,_,m,y=this;return a.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:if("readonly"!==this._mode){o.next=3;break}return i(new Error("Instance is readonly mode only.")),o.abrupt("return");case 3:if(!("number"!=typeof e&&e<=0)){o.next=6;break}return i(new Error("Version should be a positive number")),o.abrupt("return");case 6:return u=this._store,f=function(){return new Promise((function(t){var e=u.get("".concat(y._path,"-").concat(r.createPage(y._pagePtr)));e.onsuccess=function(){void 0!==e.result?t(e.result.slice(0,y._pageOffset)):t(new Uint8Array(0))}}))},o.next=10,f();case 10:for(l=o.sent,(p=new Uint8Array(l.length+t.length)).set(l),p.set(t,l.length),h=this._pagePtr*this._pageSize+p.length,d={size:h,numPages:Math.ceil(h/this._pageSize),version:e,pageSize:this._pageSize},u.put(d,this._path),v=Math.ceil(p.length/this._pageSize),_=0;_<v;_++)u.put(p.slice(_*this._pageSize,(_+1)*this._pageSize),"".concat(this._path,"-").concat(r.createPage(this._pagePtr+_)));this.exists()&&d.numPages<this._meta.numPages&&(m=IDBKeyRange.bound("".concat(this._path,"-").concat(r.createPage(d.numPages)),"".concat(this._path,"-").concat(r.createPage(this._meta.numPages)),!0),u.delete(m)),(null===(s=u.transaction)||void 0===s?void 0:s.commit)&&(null===(c=u.transaction)||void 0===c||c.commit()),u.transaction.onerror=function(){i(u.transaction.error)},u.transaction.oncomplete=function(){y._meta=d,y.seek(0,2),n()};case 23:case"end":return o.stop()}}),o,this)})))})));case 1:case"end":return n.stop()}}),n)})))}},{key:"seek",value:function(t,e){if(!this.exists()&&"readonly"===this._mode)throw new Error("'".concat(this._path,"' doesn't exist."));if(!this.exists())throw new Error("'".concat(this._path,"' doesn't exist."));if(t<0){var r=new Error("EOF");throw r.name="EndOfFile",r}var n;if(0===e)n=Math.min(t,this._meta.size);else if(1===e){var o=this._pageSize*this._pagePtr+this._pageOffset;n=Math.min(o+t,this._meta.size)}else{if(2!==e)throw new Error("Invalid operation: ".concat(e,"."));n=Math.min(this._meta.size+t,this._meta.size)}this._pageOffset=n%this._pageSize,this._pagePtr=Math.floor(n/this._pageSize),this._cache.clear()}},{key:"tell",value:function(){return this.exists()?this._pagePtr*this._pageSize+this._pageOffset:-1}},{key:"remove",value:function(){return s(this,void 0,void 0,a.mark((function t(){var e=this;return a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise((function(t,n){return s(e,void 0,void 0,a.mark((function e(){var o,i,s,c,u=this;return a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.exists()){e.next=3;break}return n(new Error("ENOENT")),e.abrupt("return");case 3:o=this._meta.numPages,i=IDBKeyRange.bound(this._path,"".concat(this._path,"-").concat(r.createPage(o))),s=this._store,(c=s.delete(i)).onerror=function(){n(c.error)},c.onsuccess=function(){u._meta=void 0,u._pageOffset=0,u._pagePtr=0,t()};case 9:case"end":return e.stop()}}),e,this)})))})));case 1:case"end":return t.stop()}}),t)})))}},{key:"exists",value:function(){return void 0!==this._meta}},{key:"_isEOF",get:function(){return this._pagePtr>=this._meta.numPages-1&&this._pageOffset>=this._meta.size%this._pageSize}},{key:"_store",get:function(){return this._db.transaction(O,this._mode).objectStore(O)}}],[{key:"open",value:function(t,e){var n=this;if(!self.indexedDB){var o=new Error("IndexedDB is not supported");throw o.name="IndexedDBNotSupported",o}return new Promise((function(o,i){return s(n,void 0,void 0,a.mark((function n(){var s,c,u;return a.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,n.next=3,P();case 3:s=n.sent,(c=s.transaction(O,"readwrite").objectStore(O).get(t)).onerror=function(){i(c.error)},c.onsuccess=function(){var n=c.result,a=e.includes("r")?"readonly":"readwrite";if(void 0===n&&"readonly"===a){var u=new Error("'".concat(t,"' doesn't exist."));return u.name="FileNotExists",void i(u)}var f=new r(t,n,s,a);e.includes("a")&&f.seek(0,2),o(f)},n.next=12;break;case 9:n.prev=9,n.t0=n.catch(0),"InvalidStateError"===n.t0.name?((u=new Error("IndexedDB is not supported")).name="IndexedDBNotSupported",i(u)):i(n.t0);case 12:case"end":return n.stop()}}),n,null,[[0,9]])})))}))}},{key:"createPage",value:function(t){return("00000"+t).slice(-6)}}]),r}();function F(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=y(t);if(e){var o=y(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return m(this,r)}}var I=function(t){v(r,E);var e=F(r);function r(t,n,o,i){var a;return g(this,r),(a=e.call(this))._pos=0,a._path=t,a._meta=n,a._mode=i,a}return x(r,[{key:"close",value:function(){}},{key:"read",value:function(t,e){if(!this.exists())throw new Error("'".concat(this._path,"' doesn't exist."));if(this._isEOF){var r=new Error("EOF");throw r.name="EndOfFile",r}var n=Math.min(t*e,this._file.length-this._pos),o=n-n%t,i=new Uint8Array(o);return i.set(this._file.slice(this._pos,this._pos+o),0),this._pos+=o,i}},{key:"write",value:function(t){var e=new Uint8Array(this._pos+t.length);void 0!==this._file?(e.set(this._file.slice(0,this._pos)),e.set(t,this._pos)):e.set(t),this._file=e,this._pos+=t.length}},{key:"seek",value:function(t,e){if(!this.exists()&&"readonly"===this._mode)throw new Error("'".concat(this._path,"' doesn't exist."));if(!this.exists())throw new Error("'".concat(this._path,"' doesn't exist."));if(t<0){var r=new Error("EOF");throw r.name="EndOfFile",r}var n;if(0===e)n=Math.min(t,this._file.length);else if(1===e)n=Math.min(this._pos+t,this._file.length);else{if(2!==e)throw new Error("Invalid operation: ".concat(e,"."));n=Math.min(this._file.length+t,this._file.length)}this._pos=n}},{key:"tell",value:function(){return this.exists()?this._pos:-1}},{key:"remove",value:function(){return s(this,void 0,void 0,a.mark((function t(){return a.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.exists()){t.next=2;break}throw new Error("ENOENT");case 2:r._memFiles.delete(this._path),this._pos=0;case 4:case"end":return t.stop()}}),t,this)})))}},{key:"exists",value:function(){return void 0!==this._file}},{key:"_isEOF",get:function(){return this._pos>=this._file.length}},{key:"_file",get:function(){return r._memFiles.get(this._path)},set:function(t){r._memFiles.set(this._path,t)}}],[{key:"open",value:function(t,e){var n=r._memFiles.get(t),o=e.includes("r")?"readonly":"readwrite";if(void 0===n&&"readonly"===o){var i=new Error("'".concat(t,"' doesn't exist."));throw i.name="FileNotExists",i}var a=new r(t,void 0,void 0,o);return e.includes("a")&&a.seek(0,2),a}}]),r}();function N(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return T(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return T(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,s=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw i}}}}function T(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function L(t){return t<0?t>>>0:t}function M(t,e){for(var r=e;0!==t[r];)r++;return new TextDecoder("utf-8").decode(t.slice(e,r))}function R(t){for(var e=atob(t),r=new Uint8Array(e.length),n=0;n<e.length;n++)r[n]=e.charCodeAt(n);return r}function z(t,e,r){for(var n="",o=0;o<e;o++)n+=String.fromCharCode(t[r+o]);return btoa(n)}function U(t){var e,r={},n=N(t.split("\r\n"));try{for(n.s();!(e=n.n()).done;){var o=e.value.split(": ");""!==o[0]&&(r[o[0]]=o[1])}}catch(t){n.e(t)}finally{n.f()}return r}function B(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:5e3;return s(this,void 0,void 0,a.mark((function n(){var o,i,s,c;return a.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return o=new AbortController,i=Object.assign(Object.assign({},e),{signal:o.signal}),s=setTimeout((function(){o.abort()}),r),n.next=5,fetch(t,i);case 5:return c=n.sent,clearTimeout(s),n.abrupt("return",c);case 8:case"end":return n.stop()}}),n)})))}function W(t){if("string"!=typeof t)return!1;var e=t.trim();if(""===e)return!1;try{return btoa(atob(e))===e}catch(t){return!1}}function D(t,e){return s(this,void 0,void 0,a.mark((function r(){var n;return a.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.prev=0,r.next=3,j.open(t,e);case 3:return r.abrupt("return",r.sent);case 6:if(r.prev=6,r.t0=r.catch(0),"IndexedDBNotSupported"===r.t0.name?console.warn("IndexedDB is not supported. Fallback to in-memory storage."):"FileNotExists"!==r.t0.name&&console.warn("Unable to access IndexedDB (".concat(r.t0.toString(),"). Fallback to in-memory storage.")),!("undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope)){r.next=16;break}if("FileNotExists"!==r.t0.name){r.next=12;break}throw r.t0;case 12:throw console.error("In-memory storage cannot be used inside a worker."),(n=new Error("Failed to start PvFile: ".concat(r.t0.toString()))).name="PvFileNotSupported",n;case 16:return r.abrupt("return",I.open(t,e));case 17:case"end":return r.stop()}}),r,null,[[0,6]])})))}function C(t,e,r,n){return s(this,void 0,void 0,a.mark((function o(){var i;return a.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return o.next=2,D(t,"w");case 2:if(i=o.sent,!(r||void 0===i.meta||n>i.meta.version||i.meta.pageSize!==i.pageSize)){o.next=6;break}return o.next=6,i.write(R(e),n);case 6:case"end":return o.stop()}}),o)})))}I._memFiles=new Map;var G=5e3,Y=2;function q(t,e,r,n,o){return s(this,void 0,void 0,a.mark((function i(){var s,c,u,f,l,p,h,d;return a.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return i.next=2,D(t,"w");case 2:if(s=i.sent,!(r||void 0===s.meta||n>s.meta.version||s.meta.pageSize!==s.pageSize)){i.next=43;break}if(!(o<0)){i.next=6;break}throw Error("numFetchRetries must be a positive number");case 6:c=Y,u=function(t){return new Promise((function(e){setTimeout(e,t)}))},f=o+1,l=null;case 10:if(!(f>0)){i.next=38;break}return l=null,i.prev=12,i.next=15,fetch(e,{cache:"no-cache"});case 15:if(!(p=i.sent).ok){i.next=23;break}return i.next=19,p.arrayBuffer();case 19:return h=i.sent,i.next=22,s.write(new Uint8Array(h),n);case 22:return i.abrupt("return");case 23:return i.next=25,p.text();case 25:d=i.sent,l=new Error("Error response returned while fetching model from '".concat(e,"': ").concat(d)),i.next=32;break;case 29:i.prev=29,i.t0=i.catch(12),l=new Error("Failed to fetch model from '".concat(e,"': ").concat(i.t0.message));case 32:return f--,i.next=35,u(c);case 35:c=Math.min(G,c*Y),i.next=10;break;case 38:if(null===l){i.next=42;break}throw l;case 42:throw new Error("Unexpected error encountered while fetching model from '".concat(e,"'"));case 43:case"end":return i.stop()}}),i,null,[[12,29]])})))}function H(t){return s(this,void 0,void 0,a.mark((function e(){var r,n,o,i,s,c,u,f,l;return a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=t){e.next=2;break}throw new Error("The model is undefined / empty");case 2:if(r=t.base64,n=t.publicPath,o=t.customWritePath,i=t.forceWrite,s=void 0!==i&&i,c=t.version,u=void 0===c?1:c,f=t.numFetchRetries,l=void 0===f?0:f,null!=o){e.next=5;break}throw new Error("The customWritePath of the provided model is undefined / empty");case 5:if(null==r){e.next=10;break}return e.next=8,C(o,r,s,u);case 8:case 13:e.next=16;break;case 10:if(null==n){e.next=15;break}return e.next=13,q(o,n,s,u,l);case 15:throw new Error("The provided model doesn't contain a valid publicPath or base64 value");case 16:return e.abrupt("return",o);case 17:case"end":return e.stop()}}),e)})))}var K={args_get:function(t){return 0},args_sizes_get:function(t){return 0},environ_get:function(t){return 0},environ_sizes_get:function(t){return 0},clock_res_get:function(t){return 0},clock_time_get:function(t){return 0},fd_advise:function(t){return 0},fd_allocate:function(t){return 0},fd_close:function(t){return 0},fd_datasync:function(t){return 0},fd_fdstat_get:function(t){return 0},fd_fdstat_set_flags:function(t){return 0},fd_fdstat_set_rights:function(t){return 0},fd_filestat_get:function(t){return 0},fd_filestat_set_size:function(t){return 0},fd_filestat_set_times:function(t){return 0},fd_pread:function(t){return 0},fd_prestat_get:function(t){return 0},fd_prestat_dir_name:function(t){return 0},fd_pwrite:function(t){return 0},fd_read:function(t){return 0},fd_readdir:function(t){return 0},fd_renumber:function(t){return 0},fd_seek:function(t){return 0},fd_sync:function(t){return 0},fd_tell:function(t){return 0},fd_write:function(t){return 0},path_create_directory:function(t){return 0},path_filestat_get:function(t){return 0},path_filestat_set_times:function(t){return 0},path_link:function(t){return 0},path_open:function(t){return 0},path_readlink:function(t){return 0},path_remove_directory:function(t){return 0},path_rename:function(t){return 0},path_symlink:function(t){return 0},path_unlink_file:function(t){return 0},poll_oneoff:function(t){return 0},proc_exit:function(t){return 0},proc_raise:function(t){return 0},sched_yield:function(t){return 0},random_get:function(t){return 0},sock_recv:function(t){return 0},sock_send:function(t){return 0},sock_shutdown:function(t){return 0}};function V(t,e,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};return s(this,void 0,void 0,a.mark((function i(){var c,u,f,l,d,v,_,m,y,g,w,b,x,k,S,O,P,A,j,F,I;return a.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:if(c=function(e,r){new Int32Array(t.buffer)[e/Int32Array.BYTES_PER_ELEMENT]=r},u=function(t,e){return s(this,void 0,void 0,a.mark((function r(){var n;return a.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,I(t,e);case 2:return n=r.sent,r.abrupt("return",L(n));case 4:case"end":return r.stop()}}),r)})))},f=function(e){e=L(e);var r=new Uint8Array(t.buffer);console.log(M(r,e))},l=function(e,r,n){n=L(n);var o=new Uint8Array(t.buffer);if(0===e){var i=M(o,n);throw new Error("assertion failed at line ".concat(r,' in "').concat(i,'"'))}},d=function(){return Date.now()/1e3},v=function(e,n,o,i,f,l,p,h,d){return s(this,void 0,void 0,a.mark((function s(){var v,_,m,y,g,w,b,x,E,k,S,O,P;return a.wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return e=L(e),n=L(n),o=L(o),i=L(i),f=L(f),p=L(p),h=L(h),d=L(d),v=new Uint8Array(t.buffer),_=M(v,e),m=M(v,n),y=M(v,o),g=M(v,i),w=M(v,f),b=U(g),x={method:_},w.length>0&&(x.body=w),Object.keys(b).length>0&&(x.headers=b),a.prev=18,a.next=21,B("https://"+m+y,x,l);case 21:E=a.sent,S=E.status,a.next=29;break;case 25:return a.prev=25,a.t0=a.catch(18),null==r||r.addError("pvHttpsRequestWasm","Failed to fetch: ".concat(a.t0)),a.abrupt("return");case 29:return a.prev=29,a.next=32,E.text();case 32:k=a.sent,a.next=39;break;case 35:return a.prev=35,a.t1=a.catch(29),null==r||r.addError("pvHttpsRequestWasm","Failed to get response text: ".concat(a.t1)),a.abrupt("return");case 39:return a.next=41,u(Int8Array.BYTES_PER_ELEMENT,(k.length+1)*Int8Array.BYTES_PER_ELEMENT);case 41:if(0!==(O=a.sent)){a.next=46;break}return null==r||r.addError("pvMallocError","pvHttpsRequestWasm: cannot allocate memory for response"),c(p,0),a.abrupt("return");case 46:for(c(h,k.length+1),c(p,O),P=0;P<k.length;P++)v[O+P]=k.charCodeAt(P);v[O+k.length]=0,c(d,S);case 51:case"end":return a.stop()}}),s,null,[[18,25],[29,35]])})))},_=function(e){return s(this,void 0,void 0,a.mark((function n(){var o,i,s,f;return a.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return e=L(e),o=new Uint8Array(t.buffer),i=void 0!==navigator.userAgent?navigator.userAgent:"unknown",n.next=5,u(Uint8Array.BYTES_PER_ELEMENT,(i.length+1)*Uint8Array.BYTES_PER_ELEMENT);case 5:if(0!==(s=n.sent)){n.next=10;break}return null==r||r.addError("pvMallocError","pvGetBrowserInfo: cannot allocate memory for browser info"),c(e,0),n.abrupt("return");case 10:for(c(e,s),f=0;f<i.length;f++)o[s+f]=i.charCodeAt(f);o[s+i.length]=0;case 13:case"end":return n.stop()}}),n)})))},m=function(e){var n;return s(this,void 0,void 0,a.mark((function o(){var i,s,f,l,p;return a.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return e=L(e),i=new Uint8Array(t.buffer),s=null!==(n=self.origin)&&void 0!==n?n:self.location.origin,f=new URL(s).hostname,o.next=6,u(Uint8Array.BYTES_PER_ELEMENT,(f.length+1)*Uint8Array.BYTES_PER_ELEMENT);case 6:if(0!==(l=o.sent)){o.next=11;break}return null==r||r.addError("pvMallocError","pvGetOriginInfo: cannot allocate memory for origin info"),c(e,0),o.abrupt("return");case 11:for(c(e,l),p=0;p<f.length;p++)i[l+p]=f.charCodeAt(p);i[l+f.length]=0;case 14:case"end":return o.stop()}}),o)})))},y=function(e,n,o,i){return s(this,void 0,void 0,a.mark((function s(){var u,f,l,p;return a.wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return e=L(e),n=L(n),o=L(o),i=L(i),u=new Uint8Array(t.buffer),f=M(u,n),l=M(u,o),a.prev=7,a.next=10,D(f,l);case 10:p=a.sent,E.setPtr(e,p),c(i,0),a.next=19;break;case 15:a.prev=15,a.t0=a.catch(7),"FileNotExists"!==a.t0.name&&(null==r||r.addError("pvFileOpenWasm",a.t0)),c(i,-1);case 19:case"end":return a.stop()}}),s,null,[[7,15]])})))},g=function(t,e){return s(this,void 0,void 0,a.mark((function n(){var o;return a.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return t=L(t),e=L(e),n.prev=2,n.next=5,E.getPtr(t);case 5:return o=n.sent,n.next=8,o.close();case 8:c(e,0),n.next=15;break;case 11:n.prev=11,n.t0=n.catch(2),null==r||r.addError("pvFileCloseWasm",n.t0),c(e,-1);case 15:case"end":return n.stop()}}),n,null,[[2,11]])})))},w=function(e,n,o,i,u){return s(this,void 0,void 0,a.mark((function s(){var f,l,p;return a.wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return e=L(e),n=L(n),u=L(u),f=new Uint8Array(t.buffer),a.prev=4,l=E.getPtr(e),a.next=8,l.read(o,i);case 8:p=a.sent,f.set(p,L(n)),c(u,p.length/o),a.next=17;break;case 13:a.prev=13,a.t0=a.catch(4),null==r||r.addError("pvFileReadWasm",a.t0),c(u,-1);case 17:case"end":return a.stop()}}),s,null,[[4,13]])})))},b=function(e,n,o,i,u){return s(this,void 0,void 0,a.mark((function s(){var f,l,p;return a.wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return e=L(e),n=L(n),u=L(u),f=new Uint8Array(t.buffer),a.prev=4,l=E.getPtr(e),(p=new Uint8Array(o*i)).set(f.slice(L(n),L(n)+o*i),0),a.next=10,l.write(p);case 10:c(u,p.length/o),a.next=17;break;case 13:a.prev=13,a.t0=a.catch(4),null==r||r.addError("pvFileWriteWasm",a.t0),c(u,-1);case 17:case"end":return a.stop()}}),s,null,[[4,13]])})))},x=function(t,e,n,o){t=L(t),o=L(o);try{E.getPtr(t).seek(e,n),c(o,0)}catch(t){null==r||r.addError("pvFileSeekWasm",t),c(o,-1)}},k=function(t,e){t=L(t),e=L(e);try{var n=E.getPtr(t);c(e,n.tell())}catch(t){null==r||r.addError("pvFileTellWasm",t),c(e,-1)}},S=function(e,n){return s(this,void 0,void 0,a.mark((function o(){var i,s,u;return a.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return e=L(e),n=L(n),i=new Uint8Array(t.buffer),s=M(i,e),o.prev=4,o.next=7,D(s,"w");case 7:return u=o.sent,o.next=10,u.remove();case 10:c(n,0),o.next=17;break;case 13:o.prev=13,o.t0=o.catch(4),null==r||r.addError("pvFileRemoveWasm",o.t0),c(n,-1);case 17:case"end":return o.stop()}}),o,null,[[4,13]])})))},O={wasi_snapshot_preview1:K,env:Object.assign({memory:t,pv_console_log_wasm:f,pv_assert_wasm:l,pv_time_wasm:d,pv_https_request_wasm:v,pv_get_browser_info:_,pv_get_origin_info:m,pv_file_open_wasm:y,pv_file_close_wasm:g,pv_file_read_wasm:w,pv_file_write_wasm:b,pv_file_seek_wasm:x,pv_file_tell_wasm:k,pv_file_remove_wasm:S},n),wasi:Object.assign({},o)},!(e instanceof Promise)){i.next=34;break}if(!h){i.next=23;break}return i.next=20,h(e,O);case 20:P=i.sent.instance,i.next=32;break;case 23:return i.next=25,e;case 25:return A=i.sent,i.next=28,A.arrayBuffer();case 28:return j=i.sent,i.next=31,p(new Uint8Array(j),O);case 31:P=i.sent.instance;case 32:i.next=38;break;case 34:return F=R(e),i.next=37,p(F,O);case 37:P=i.sent.instance;case 38:return I=P.exports.aligned_alloc,i.abrupt("return",Object.assign(Object.assign({},P.exports),{aligned_alloc:u}));case 40:case"end":return i.stop()}}),i)})))}function $(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function J(t){return function(t){if(Array.isArray(t))return $(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return $(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?$(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var Q=function(){function t(){g(this,t),this._maxNumErrors=10,this._errors=[],this._lastError=new Error("null")}return x(t,[{key:"addError",value:function(t,e){this._lastError=e instanceof Error?e:new Error(e),this._errors.length>=this._maxNumErrors&&this._errors.shift(),e instanceof Error?this._errors.push({key:t,message:e.toString()}):this._errors.push({key:t,message:JSON.stringify(e)})}},{key:"getErrors",value:function(){var t=J(this._errors);return this._errors=[],t}},{key:"getErrorString",value:function(){return this.getErrors().map((function(t){var e=t.key,r=t.message;return"'".concat(e,"' failed with: ").concat(r,".")})).join("\n")}},{key:"getLastError",value:function(){return this._lastError}},{key:"setMaxErrorNum",value:function(t){this._maxNumErrors=t}}]),t}(),X={DB_NAME:S,DB_VERSION:3,PV_FILE_STORE:O};export{Q as PvError,E as PvFile,j as PvFileIDB,I as PvFileMem,z as arrayBufferToBase64AtIndex,M as arrayBufferToStringAtIndex,R as base64ToUint8Array,V as buildWasm,X as dbConfig,B as fetchWithTimeout,C as fromBase64,q as fromPublicDirectory,P as getDB,W as isAccessKeyValid,H as loadModel,D as open,U as stringHeaderToObject,L as unsignedAddress}; |
@@ -1,1 +0,1 @@ | ||
var WebUtils=function(t){"use strict";function e(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var r={exports:{}},n={exports:{}};!function(t){function e(r){return t.exports=e="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},t.exports.__esModule=!0,t.exports.default=t.exports,e(r)}t.exports=e,t.exports.__esModule=!0,t.exports.default=t.exports}(n);var o=n.exports;!function(t){var e=o.default;function r(){t.exports=r=function(){return o},t.exports.__esModule=!0,t.exports.default=t.exports;var n,o={},i=Object.prototype,a=i.hasOwnProperty,s=Object.defineProperty||function(t,e,r){t[e]=r.value},c="function"==typeof Symbol?Symbol:{},u=c.iterator||"@@iterator",f=c.asyncIterator||"@@asyncIterator",l=c.toStringTag||"@@toStringTag";function p(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{p({},"")}catch(n){p=function(t,e,r){return t[e]=r}}function h(t,e,r,n){var o=e&&e.prototype instanceof w?e:w,i=Object.create(o.prototype),a=new N(n||[]);return s(i,"_invoke",{value:F(t,r,a)}),i}function d(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}o.wrap=h;var v="suspendedStart",_="suspendedYield",y="executing",m="completed",g={};function w(){}function b(){}function x(){}var E={};p(E,u,(function(){return this}));var k=Object.getPrototypeOf,P=k&&k(k(M([])));P&&P!==i&&a.call(P,u)&&(E=P);var S=x.prototype=w.prototype=Object.create(E);function O(t){["next","throw","return"].forEach((function(e){p(t,e,(function(t){return this._invoke(e,t)}))}))}function A(t,r){function n(o,i,s,c){var u=d(t[o],t,i);if("throw"!==u.type){var f=u.arg,l=f.value;return l&&"object"==e(l)&&a.call(l,"__await")?r.resolve(l.__await).then((function(t){n("next",t,s,c)}),(function(t){n("throw",t,s,c)})):r.resolve(l).then((function(t){f.value=t,s(f)}),(function(t){return n("throw",t,s,c)}))}c(u.arg)}var o;s(this,"_invoke",{value:function(t,e){function i(){return new r((function(r,o){n(t,e,r,o)}))}return o=o?o.then(i,i):i()}})}function F(t,e,r){var o=v;return function(i,a){if(o===y)throw new Error("Generator is already running");if(o===m){if("throw"===i)throw a;return{value:n,done:!0}}for(r.method=i,r.arg=a;;){var s=r.delegate;if(s){var c=j(s,r);if(c){if(c===g)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(o===v)throw o=m,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=y;var u=d(t,e,r);if("normal"===u.type){if(o=r.done?m:_,u.arg===g)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(o=m,r.method="throw",r.arg=u.arg)}}}function j(t,e){var r=e.method,o=t.iterator[r];if(o===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=n,j(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),g;var i=d(o,t.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,g;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,g):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,g)}function I(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 T(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function N(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(I,this),this.reset(!0)}function M(t){if(t||""===t){var r=t[u];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function e(){for(;++o<t.length;)if(a.call(t,o))return e.value=t[o],e.done=!1,e;return e.value=n,e.done=!0,e};return i.next=i}}throw new TypeError(e(t)+" is not iterable")}return b.prototype=x,s(S,"constructor",{value:x,configurable:!0}),s(x,"constructor",{value:b,configurable:!0}),b.displayName=p(x,l,"GeneratorFunction"),o.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===b||"GeneratorFunction"===(e.displayName||e.name))},o.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,p(t,l,"GeneratorFunction")),t.prototype=Object.create(S),t},o.awrap=function(t){return{__await:t}},O(A.prototype),p(A.prototype,f,(function(){return this})),o.AsyncIterator=A,o.async=function(t,e,r,n,i){void 0===i&&(i=Promise);var a=new A(h(t,e,r,n),i);return o.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},O(S),p(S,l,"Generator"),p(S,u,(function(){return this})),p(S,"toString",(function(){return"[object Generator]"})),o.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},o.values=M,N.prototype={constructor:N,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(T),!t)for(var e in this)"t"===e.charAt(0)&&a.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,o){return s.type="throw",s.arg=t,e.next=r,o&&(e.method="next",e.arg=n),!!o}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],s=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var c=a.call(i,"catchLoc"),u=a.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&a.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,g):this.complete(i)},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),g},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),T(r),g}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;T(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:M(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=n),g}},o}t.exports=r,t.exports.__esModule=!0,t.exports.default=t.exports}(r);var i=(0,r.exports)(),a=i;try{regeneratorRuntime=i}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=i:Function("r","regeneratorRuntime = r")(i)}var s=e(a);function c(t,e,r,n){return new(r||(r=Promise))((function(o,i){function a(t){try{c(n.next(t))}catch(t){i(t)}}function s(t){try{c(n.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,s)}c((n=n.apply(t,e||[])).next())}))}const u=new WeakMap;function f(t,e){return new Proxy(t,{get:(t,r)=>e(t[r])})}class l{constructor(){this.value=void 0,this.exports=null}getState(){return this.exports.asyncify_get_state()}assertNoneState(){let t=this.getState();if(0!==t)throw new Error(`Invalid async state ${t}, expected 0.`)}wrapImportFn(t){return(...e)=>{if(2===this.getState())return this.exports.asyncify_stop_rewind(),this.value;this.assertNoneState();let r=t(...e);if(!(n=r)||"object"!=typeof n&&"function"!=typeof n||"function"!=typeof n.then)return r;var n;this.exports.asyncify_start_unwind(16),this.value=r}}wrapModuleImports(t){return f(t,(t=>"function"==typeof t?this.wrapImportFn(t):t))}wrapImports(t){if(void 0!==t)return f(t,((t=Object.create(null))=>this.wrapModuleImports(t)))}wrapExportFn(t){let e=u.get(t);return void 0!==e||(e=async(...e)=>{this.assertNoneState();let r=t(...e);for(;1===this.getState();)this.exports.asyncify_stop_unwind(),this.value=await this.value,this.assertNoneState(),this.exports.asyncify_start_rewind(16),r=t();return this.assertNoneState(),r},u.set(t,e)),e}wrapExports(t){let e=Object.create(null);for(let r in t){let n=t[r];"function"!=typeof n||r.startsWith("asyncify_")||(n=this.wrapExportFn(n)),Object.defineProperty(e,r,{enumerable:!0,value:n})}return u.set(t,e),e}init(t,e){const{exports:r}=t,n=r.memory||e.env&&e.env.memory;new Int32Array(n.buffer,16).set([24,1024]),this.exports=this.wrapExports(r),Object.setPrototypeOf(t,p.prototype)}}class p extends WebAssembly.Instance{constructor(t,e){let r=new l;super(t,r.wrapImports(e)),r.init(this,e)}get exports(){return u.get(super.exports)}}async function h(t,e){let r=new l,n=await WebAssembly.instantiate(t,r.wrapImports(e));return r.init(n instanceof WebAssembly.Instance?n:n.instance,e),n}async function d(t,e){let r=new l,n=await WebAssembly.instantiateStreaming(t,r.wrapImports(e));return r.init(n.instance,e),n}function v(t,e){return v=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},v(t,e)}function _(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&v(t,e)}function y(t){return y="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},y(t)}function m(t,e){if(e&&("object"===y(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function g(t){return g=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},g(t)}function w(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function b(t){var e=function(t,e){if("object"!==y(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!==y(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"===y(e)?e:String(e)}function x(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,b(n.key),n)}}function E(t,e,r){return e&&x(t.prototype,e),r&&x(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}Object.defineProperty(p.prototype,"exports",{enumerable:!0});var k=function(){function t(){w(this,t),this._path=""}return E(t,[{key:"meta",get:function(){if(void 0!==this._meta)return Object.assign({version:0},this._meta)}},{key:"pageSize",get:function(){}}],[{key:"getPtr",value:function(e){if(t._filePtrs.has(e))return t._filePtrs.get(e);throw new Error("File instance not found.")}},{key:"setPtr",value:function(e,r){t._filePtrs.set(e,r)}},{key:"removePtr",value:function(e){t._filePtrs.delete(e)}}]),t}();function P(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=g(t);if(e){var o=g(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return m(this,r)}}k._filePtrs=new Map;var S="pv_db",O="pv_file";function A(){return new Promise((function(t,e){var r=self.indexedDB.open(S,3);r.onerror=function(){e(r.error)},r.onsuccess=function(){t(r.result)},r.onupgradeneeded=function(){r.result.objectStoreNames.contains(O)||r.result.createObjectStore(O)}}))}var F=function(){function t(){w(this,t),this._pos=0,this._data=new Uint8Array}return E(t,[{key:"get",value:function(t){if(!(this._pos>=this._data.length)){var e=this._data.slice(this._pos,this._pos+t);return this._pos+=t,e}}},{key:"set",value:function(t,e){this._pos=t,this._data=e}},{key:"clear",value:function(){this._pos=0,this._data=new Uint8Array}}]),t}(),j=function(t){_(r,t);var e=P(r);function r(t,n,o,i){var a;return w(this,r),(a=e.call(this))._pageSize=524288,a._pagePtr=0,a._pageOffset=0,a._path=t,a._meta=n,a._db=o,a._mode=i,a._cache=new F,a}return E(r,[{key:"pageSize",get:function(){return this._pageSize}},{key:"close",value:function(){return c(this,void 0,void 0,s.mark((function t(){return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:this._db.close();case 1:case"end":return t.stop()}}),t,this)})))}},{key:"read",value:function(t,e){return c(this,void 0,void 0,s.mark((function n(){var o=this;return s.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",new Promise((function(n,i){if(o.exists()){if(o._isEOF){var a=new Error("EOF");return a.name="EndOfFile",void i(a)}var s=0,c=Math.min(t*e,o._meta.size),u=c-c%t,f=new Uint8Array(u),l=o._cache.get(u);if(l){if(s+=l.length,o._pageOffset+=l.length,o._pageOffset===o._pageSize&&(o._pagePtr+=1,o._pageOffset=0),u===s)return void n(l);f.set(l)}var p=IDBKeyRange.bound("".concat(o._path,"-").concat(r.createPage(o._pagePtr)),"".concat(o._path,"-").concat(r.createPage(o._pagePtr+Math.floor(u/o._pageSize)+1))),h=o._store,d=h.openCursor(p);d.onsuccess=function(){var t,e,r=d.result;if(r&&!o._isEOF){var n=Math.min(u-s,r.value.length-o._pageOffset);f.set(r.value.slice(o._pageOffset,o._pageOffset+n),s),s+=n,o._pageOffset+=n,o._pageOffset===o._pageSize&&(o._pagePtr+=1,o._pageOffset=0),s<u?r.continue():(0!==o._pageOffset?o._cache.set(o._pageOffset,r.value):o._cache.clear(),(null===(t=h.transaction)||void 0===t?void 0:t.commit)&&(null===(e=h.transaction)||void 0===e||e.commit()))}},h.transaction.onerror=function(){i(h.transaction.error)},h.transaction.oncomplete=function(){n(f.slice(0,s))}}else i(new Error("'".concat(o._path,"' doesn't exist.")))})));case 1:case"end":return n.stop()}}),n)})))}},{key:"write",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return c(this,void 0,void 0,s.mark((function n(){var o=this;return s.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",new Promise((function(n,i){return c(o,void 0,void 0,s.mark((function o(){var a,c,u,f,l,p,h,d,v,_,y,m=this;return s.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:if("readonly"!==this._mode){o.next=3;break}return i(new Error("Instance is readonly mode only.")),o.abrupt("return");case 3:if(!("number"!=typeof e&&e<=0)){o.next=6;break}return i(new Error("Version should be a positive number")),o.abrupt("return");case 6:return u=this._store,f=function(){return new Promise((function(t){var e=u.get("".concat(m._path,"-").concat(r.createPage(m._pagePtr)));e.onsuccess=function(){void 0!==e.result?t(e.result.slice(0,m._pageOffset)):t(new Uint8Array(0))}}))},o.next=10,f();case 10:for(l=o.sent,(p=new Uint8Array(l.length+t.length)).set(l),p.set(t,l.length),h=this._pagePtr*this._pageSize+p.length,d={size:h,numPages:Math.ceil(h/this._pageSize),version:e,pageSize:this._pageSize},u.put(d,this._path),v=Math.ceil(p.length/this._pageSize),_=0;_<v;_++)u.put(p.slice(_*this._pageSize,(_+1)*this._pageSize),"".concat(this._path,"-").concat(r.createPage(this._pagePtr+_)));this.exists()&&d.numPages<this._meta.numPages&&(y=IDBKeyRange.bound("".concat(this._path,"-").concat(r.createPage(d.numPages)),"".concat(this._path,"-").concat(r.createPage(this._meta.numPages)),!0),u.delete(y)),(null===(a=u.transaction)||void 0===a?void 0:a.commit)&&(null===(c=u.transaction)||void 0===c||c.commit()),u.transaction.onerror=function(){i(u.transaction.error)},u.transaction.oncomplete=function(){m._meta=d,m.seek(0,2),n()};case 23:case"end":return o.stop()}}),o,this)})))})));case 1:case"end":return n.stop()}}),n)})))}},{key:"seek",value:function(t,e){if(!this.exists()&&"readonly"===this._mode)throw new Error("'".concat(this._path,"' doesn't exist."));if(!this.exists())throw new Error("'".concat(this._path,"' doesn't exist."));if(t<0){var r=new Error("EOF");throw r.name="EndOfFile",r}var n;if(0===e)n=Math.min(t,this._meta.size);else if(1===e){var o=this._pageSize*this._pagePtr+this._pageOffset;n=Math.min(o+t,this._meta.size)}else{if(2!==e)throw new Error("Invalid operation: ".concat(e,"."));n=Math.min(this._meta.size+t,this._meta.size)}this._pageOffset=n%this._pageSize,this._pagePtr=Math.floor(n/this._pageSize),this._cache.clear()}},{key:"tell",value:function(){return this.exists()?this._pagePtr*this._pageSize+this._pageOffset:-1}},{key:"remove",value:function(){return c(this,void 0,void 0,s.mark((function t(){var e=this;return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise((function(t,n){return c(e,void 0,void 0,s.mark((function e(){var o,i,a,c,u=this;return s.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.exists()){e.next=3;break}return n(new Error("ENOENT")),e.abrupt("return");case 3:o=this._meta.numPages,i=IDBKeyRange.bound(this._path,"".concat(this._path,"-").concat(r.createPage(o))),a=this._store,(c=a.delete(i)).onerror=function(){n(c.error)},c.onsuccess=function(){u._meta=void 0,u._pageOffset=0,u._pagePtr=0,t()};case 9:case"end":return e.stop()}}),e,this)})))})));case 1:case"end":return t.stop()}}),t)})))}},{key:"exists",value:function(){return void 0!==this._meta}},{key:"_isEOF",get:function(){return this._pagePtr>=this._meta.numPages-1&&this._pageOffset>=this._meta.size%this._pageSize}},{key:"_store",get:function(){return this._db.transaction(O,this._mode).objectStore(O)}}],[{key:"open",value:function(t,e){var n=this;if(!self.indexedDB){var o=new Error("IndexedDB is not supported");throw o.name="IndexedDBNotSupported",o}return new Promise((function(o,i){return c(n,void 0,void 0,s.mark((function n(){var a,c,u;return s.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,n.next=3,A();case 3:a=n.sent,(c=a.transaction(O,"readwrite").objectStore(O).get(t)).onerror=function(){i(c.error)},c.onsuccess=function(){var n=c.result,s=e.includes("r")?"readonly":"readwrite";if(void 0===n&&"readonly"===s){var u=new Error("'".concat(t,"' doesn't exist."));return u.name="FileNotExists",void i(u)}var f=new r(t,n,a,s);e.includes("a")&&f.seek(0,2),o(f)},n.next=12;break;case 9:n.prev=9,n.t0=n.catch(0),"InvalidStateError"===n.t0.name?((u=new Error("IndexedDB is not supported")).name="IndexedDBNotSupported",i(u)):i(n.t0);case 12:case"end":return n.stop()}}),n,null,[[0,9]])})))}))}},{key:"createPage",value:function(t){return("00000"+t).slice(-6)}}]),r}(k);function I(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=g(t);if(e){var o=g(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return m(this,r)}}var T=function(t){_(r,t);var e=I(r);function r(t,n,o,i){var a;return w(this,r),(a=e.call(this))._pos=0,a._path=t,a._meta=n,a._mode=i,a}return E(r,[{key:"close",value:function(){}},{key:"read",value:function(t,e){if(!this.exists())throw new Error("'".concat(this._path,"' doesn't exist."));if(this._isEOF){var r=new Error("EOF");throw r.name="EndOfFile",r}var n=Math.min(t*e,this._file.length-this._pos),o=n-n%t,i=new Uint8Array(o);return i.set(this._file.slice(this._pos,this._pos+o),0),this._pos+=o,i}},{key:"write",value:function(t){var e=new Uint8Array(this._pos+t.length);void 0!==this._file?(e.set(this._file.slice(0,this._pos)),e.set(t,this._pos)):e.set(t),this._file=e,this._pos+=t.length}},{key:"seek",value:function(t,e){if(!this.exists()&&"readonly"===this._mode)throw new Error("'".concat(this._path,"' doesn't exist."));if(!this.exists())throw new Error("'".concat(this._path,"' doesn't exist."));if(t<0){var r=new Error("EOF");throw r.name="EndOfFile",r}var n;if(0===e)n=Math.min(t,this._file.length);else if(1===e)n=Math.min(this._pos+t,this._file.length);else{if(2!==e)throw new Error("Invalid operation: ".concat(e,"."));n=Math.min(this._file.length+t,this._file.length)}this._pos=n}},{key:"tell",value:function(){return this.exists()?this._pos:-1}},{key:"remove",value:function(){return c(this,void 0,void 0,s.mark((function t(){return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.exists()){t.next=2;break}throw new Error("ENOENT");case 2:r._memFiles.delete(this._path),this._pos=0;case 4:case"end":return t.stop()}}),t,this)})))}},{key:"exists",value:function(){return void 0!==this._file}},{key:"_isEOF",get:function(){return this._pos>=this._file.length}},{key:"_file",get:function(){return r._memFiles.get(this._path)},set:function(t){r._memFiles.set(this._path,t)}}],[{key:"open",value:function(t,e){var n=r._memFiles.get(t),o=e.includes("r")?"readonly":"readwrite";if(void 0===n&&"readonly"===o){var i=new Error("'".concat(t,"' doesn't exist."));throw i.name="FileNotExists",i}var a=new r(t,void 0,void 0,o);return e.includes("a")&&a.seek(0,2),a}}]),r}(k);function N(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return M(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return M(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,s=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw i}}}}function M(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function L(t){return t<0?t>>>0:t}function B(t,e){for(var r=e;0!==t[r];)r++;return new TextDecoder("utf-8").decode(t.subarray(e,r))}function R(t){for(var e=atob(t),r=new Uint8Array(e.length),n=0;n<e.length;n++)r[n]=e.charCodeAt(n);return r}function z(t){var e,r={},n=N(t.split("\r\n"));try{for(n.s();!(e=n.n()).done;){var o=e.value.split(": ");""!==o[0]&&(r[o[0]]=o[1])}}catch(t){n.e(t)}finally{n.f()}return r}function U(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:5e3;return c(this,void 0,void 0,s.mark((function n(){var o,i,a,c;return s.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return o=new AbortController,i=Object.assign(Object.assign({},e),{signal:o.signal}),a=setTimeout((function(){o.abort()}),r),n.next=5,fetch(t,i);case 5:return c=n.sent,clearTimeout(a),n.abrupt("return",c);case 8:case"end":return n.stop()}}),n)})))}function W(t,e){return c(this,void 0,void 0,s.mark((function r(){var n;return s.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.prev=0,r.next=3,j.open(t,e);case 3:return r.abrupt("return",r.sent);case 6:if(r.prev=6,r.t0=r.catch(0),"IndexedDBNotSupported"===r.t0.name?console.warn("IndexedDB is not supported. Fallback to in-memory storage."):"FileNotExists"!==r.t0.name&&console.warn("Unable to access IndexedDB (".concat(r.t0.toString(),"). Fallback to in-memory storage.")),!("undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope)){r.next=16;break}if("FileNotExists"!==r.t0.name){r.next=12;break}throw r.t0;case 12:throw console.error("In-memory storage cannot be used inside a worker."),(n=new Error("Failed to start PvFile: ".concat(r.t0.toString()))).name="PvFileNotSupported",n;case 16:return r.abrupt("return",T.open(t,e));case 17:case"end":return r.stop()}}),r,null,[[0,6]])})))}function D(t,e,r,n){return c(this,void 0,void 0,s.mark((function o(){var i;return s.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return o.next=2,W(t,"w");case 2:if(i=o.sent,!(r||void 0===i.meta||n>i.meta.version||i.meta.pageSize!==i.pageSize)){o.next=6;break}return o.next=6,i.write(R(e),n);case 6:case"end":return o.stop()}}),o)})))}T._memFiles=new Map;var C=5e3,G=2;function Y(t,e,r,n,o){return c(this,void 0,void 0,s.mark((function i(){var a,c,u,f,l,p,h,d;return s.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return i.next=2,W(t,"w");case 2:if(a=i.sent,!(r||void 0===a.meta||n>a.meta.version||a.meta.pageSize!==a.pageSize)){i.next=43;break}if(!(o<0)){i.next=6;break}throw Error("numFetchRetries must be a positive number");case 6:c=G,u=function(t){return new Promise((function(e){setTimeout(e,t)}))},f=o+1,l=null;case 10:if(!(f>0)){i.next=38;break}return l=null,i.prev=12,i.next=15,fetch(e,{cache:"no-cache"});case 15:if(!(p=i.sent).ok){i.next=23;break}return i.next=19,p.arrayBuffer();case 19:return h=i.sent,i.next=22,a.write(new Uint8Array(h),n);case 22:return i.abrupt("return");case 23:return i.next=25,p.text();case 25:d=i.sent,l=new Error("Error response returned while fetching model from '".concat(e,"': ").concat(d)),i.next=32;break;case 29:i.prev=29,i.t0=i.catch(12),l=new Error("Failed to fetch model from '".concat(e,"': ").concat(i.t0.message));case 32:return f--,i.next=35,u(c);case 35:c=Math.min(C,c*G),i.next=10;break;case 38:if(null===l){i.next=42;break}throw l;case 42:throw new Error("Unexpected error encountered while fetching model from '".concat(e,"'"));case 43:case"end":return i.stop()}}),i,null,[[12,29]])})))}var q={args_get:function(t){return 0},args_sizes_get:function(t){return 0},environ_get:function(t){return 0},environ_sizes_get:function(t){return 0},clock_res_get:function(t){return 0},clock_time_get:function(t){return 0},fd_advise:function(t){return 0},fd_allocate:function(t){return 0},fd_close:function(t){return 0},fd_datasync:function(t){return 0},fd_fdstat_get:function(t){return 0},fd_fdstat_set_flags:function(t){return 0},fd_fdstat_set_rights:function(t){return 0},fd_filestat_get:function(t){return 0},fd_filestat_set_size:function(t){return 0},fd_filestat_set_times:function(t){return 0},fd_pread:function(t){return 0},fd_prestat_get:function(t){return 0},fd_prestat_dir_name:function(t){return 0},fd_pwrite:function(t){return 0},fd_read:function(t){return 0},fd_readdir:function(t){return 0},fd_renumber:function(t){return 0},fd_seek:function(t){return 0},fd_sync:function(t){return 0},fd_tell:function(t){return 0},fd_write:function(t){return 0},path_create_directory:function(t){return 0},path_filestat_get:function(t){return 0},path_filestat_set_times:function(t){return 0},path_link:function(t){return 0},path_open:function(t){return 0},path_readlink:function(t){return 0},path_remove_directory:function(t){return 0},path_rename:function(t){return 0},path_symlink:function(t){return 0},path_unlink_file:function(t){return 0},poll_oneoff:function(t){return 0},proc_exit:function(t){return 0},proc_raise:function(t){return 0},sched_yield:function(t){return 0},random_get:function(t){return 0},sock_recv:function(t){return 0},sock_send:function(t){return 0},sock_shutdown:function(t){return 0}};function H(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function K(t){return function(t){if(Array.isArray(t))return H(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return H(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?H(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var V=function(){function t(){w(this,t),this._maxNumErrors=10,this._errors=[],this._lastError=new Error("null")}return E(t,[{key:"addError",value:function(t,e){this._lastError=e instanceof Error?e:new Error(e),this._errors.length>=this._maxNumErrors&&this._errors.shift(),e instanceof Error?this._errors.push({key:t,message:e.toString()}):this._errors.push({key:t,message:JSON.stringify(e)})}},{key:"getErrors",value:function(){var t=K(this._errors);return this._errors=[],t}},{key:"getErrorString",value:function(){return this.getErrors().map((function(t){var e=t.key,r=t.message;return"'".concat(e,"' failed with: ").concat(r,".")})).join("\n")}},{key:"getLastError",value:function(){return this._lastError}},{key:"setMaxErrorNum",value:function(t){this._maxNumErrors=t}}]),t}(),$={DB_NAME:S,DB_VERSION:3,PV_FILE_STORE:O};return t.PvError=V,t.PvFile=k,t.PvFileIDB=j,t.PvFileMem=T,t.arrayBufferToBase64AtIndex=function(t,e,r){for(var n="",o=0;o<e;o++)n+=String.fromCharCode(t[r+o]);return btoa(n)},t.arrayBufferToStringAtIndex=B,t.base64ToUint8Array=R,t.buildWasm=function(t,e,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return c(this,void 0,void 0,s.mark((function o(){var i,a,u,f,l,p,v,_,y,m,g,w,b,x,E,P,S,O,A,F,j;return s.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:if(i=function(e,r){new Int32Array(t.buffer)[e/Int32Array.BYTES_PER_ELEMENT]=r},a=function(t,e){return c(this,void 0,void 0,s.mark((function r(){var n;return s.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,j(t,e);case 2:return n=r.sent,r.abrupt("return",L(n));case 4:case"end":return r.stop()}}),r)})))},u=function(e){e=L(e);var r=new Uint8Array(t.buffer);console.log(B(r,e))},f=function(e,r,n){n=L(n);var o=new Uint8Array(t.buffer);if(0===e){var i=B(o,n);throw new Error("assertion failed at line ".concat(r,' in "').concat(i,'"'))}},l=function(){return Date.now()/1e3},p=function(e,n,o,u,f,l,p,h,d){return c(this,void 0,void 0,s.mark((function c(){var v,_,y,m,g,w,b,x,E,k,P,S,O;return s.wrap((function(s){for(;;)switch(s.prev=s.next){case 0:return e=L(e),n=L(n),o=L(o),u=L(u),f=L(f),p=L(p),h=L(h),d=L(d),v=new Uint8Array(t.buffer),_=B(v,e),y=B(v,n),m=B(v,o),g=B(v,u),w=B(v,f),b=z(g),x={method:_},w.length>0&&(x.body=w),Object.keys(b).length>0&&(x.headers=b),s.prev=18,s.next=21,U("https://"+y+m,x,l);case 21:E=s.sent,P=E.status,s.next=29;break;case 25:return s.prev=25,s.t0=s.catch(18),null==r||r.addError("pvHttpsRequestWasm","Failed to fetch: ".concat(s.t0)),s.abrupt("return");case 29:return s.prev=29,s.next=32,E.text();case 32:k=s.sent,s.next=39;break;case 35:return s.prev=35,s.t1=s.catch(29),null==r||r.addError("pvHttpsRequestWasm","Failed to get response text: ".concat(s.t1)),s.abrupt("return");case 39:return s.next=41,a(Int8Array.BYTES_PER_ELEMENT,(k.length+1)*Int8Array.BYTES_PER_ELEMENT);case 41:if(0!==(S=s.sent)){s.next=46;break}return null==r||r.addError("pvMallocError","pvHttpsRequestWasm: cannot allocate memory for response"),i(p,0),s.abrupt("return");case 46:for(i(h,k.length+1),i(p,S),O=0;O<k.length;O++)v[S+O]=k.charCodeAt(O);v[S+k.length]=0,i(d,P);case 51:case"end":return s.stop()}}),c,null,[[18,25],[29,35]])})))},v=function(e){return c(this,void 0,void 0,s.mark((function n(){var o,c,u,f;return s.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return e=L(e),o=new Uint8Array(t.buffer),c=void 0!==navigator.userAgent?navigator.userAgent:"unknown",n.next=5,a(Uint8Array.BYTES_PER_ELEMENT,(c.length+1)*Uint8Array.BYTES_PER_ELEMENT);case 5:if(0!==(u=n.sent)){n.next=10;break}return null==r||r.addError("pvMallocError","pvGetBrowserInfo: cannot allocate memory for browser info"),i(e,0),n.abrupt("return");case 10:for(i(e,u),f=0;f<c.length;f++)o[u+f]=c.charCodeAt(f);o[u+c.length]=0;case 13:case"end":return n.stop()}}),n)})))},_=function(e){var n;return c(this,void 0,void 0,s.mark((function o(){var c,u,f,l,p;return s.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return e=L(e),c=new Uint8Array(t.buffer),u=null!==(n=self.origin)&&void 0!==n?n:self.location.origin,f=new URL(u).hostname,o.next=6,a(Uint8Array.BYTES_PER_ELEMENT,(f.length+1)*Uint8Array.BYTES_PER_ELEMENT);case 6:if(0!==(l=o.sent)){o.next=11;break}return null==r||r.addError("pvMallocError","pvGetOriginInfo: cannot allocate memory for origin info"),i(e,0),o.abrupt("return");case 11:for(i(e,l),p=0;p<f.length;p++)c[l+p]=f.charCodeAt(p);c[l+f.length]=0;case 14:case"end":return o.stop()}}),o)})))},y=function(e,n,o,a){return c(this,void 0,void 0,s.mark((function c(){var u,f,l,p;return s.wrap((function(s){for(;;)switch(s.prev=s.next){case 0:return e=L(e),n=L(n),o=L(o),a=L(a),u=new Uint8Array(t.buffer),f=B(u,n),l=B(u,o),s.prev=7,s.next=10,W(f,l);case 10:p=s.sent,k.setPtr(e,p),i(a,0),s.next=19;break;case 15:s.prev=15,s.t0=s.catch(7),"FileNotExists"!==s.t0.name&&(null==r||r.addError("pvFileOpenWasm",s.t0)),i(a,-1);case 19:case"end":return s.stop()}}),c,null,[[7,15]])})))},m=function(t,e){return c(this,void 0,void 0,s.mark((function n(){var o;return s.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return t=L(t),e=L(e),n.prev=2,n.next=5,k.getPtr(t);case 5:return o=n.sent,n.next=8,o.close();case 8:i(e,0),n.next=15;break;case 11:n.prev=11,n.t0=n.catch(2),null==r||r.addError("pvFileCloseWasm",n.t0),i(e,-1);case 15:case"end":return n.stop()}}),n,null,[[2,11]])})))},g=function(e,n,o,a,u){return c(this,void 0,void 0,s.mark((function c(){var f,l,p;return s.wrap((function(s){for(;;)switch(s.prev=s.next){case 0:return e=L(e),n=L(n),u=L(u),f=new Uint8Array(t.buffer),s.prev=4,l=k.getPtr(e),s.next=8,l.read(o,a);case 8:p=s.sent,f.set(p,L(n)),i(u,p.length/o),s.next=17;break;case 13:s.prev=13,s.t0=s.catch(4),null==r||r.addError("pvFileReadWasm",s.t0),i(u,-1);case 17:case"end":return s.stop()}}),c,null,[[4,13]])})))},w=function(e,n,o,a,u){return c(this,void 0,void 0,s.mark((function c(){var f,l,p;return s.wrap((function(s){for(;;)switch(s.prev=s.next){case 0:return e=L(e),n=L(n),u=L(u),f=new Uint8Array(t.buffer),s.prev=4,l=k.getPtr(e),(p=new Uint8Array(o*a)).set(f.slice(L(n),L(n)+o*a),0),s.next=10,l.write(p);case 10:i(u,p.length/o),s.next=17;break;case 13:s.prev=13,s.t0=s.catch(4),null==r||r.addError("pvFileWriteWasm",s.t0),i(u,-1);case 17:case"end":return s.stop()}}),c,null,[[4,13]])})))},b=function(t,e,n,o){t=L(t),o=L(o);try{k.getPtr(t).seek(e,n),i(o,0)}catch(t){null==r||r.addError("pvFileSeekWasm",t),i(o,-1)}},x=function(t,e){t=L(t),e=L(e);try{var n=k.getPtr(t);i(e,n.tell())}catch(t){null==r||r.addError("pvFileTellWasm",t),i(e,-1)}},E=function(e,n){return c(this,void 0,void 0,s.mark((function o(){var a,c,u;return s.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return e=L(e),n=L(n),a=new Uint8Array(t.buffer),c=B(a,e),o.prev=4,o.next=7,W(c,"w");case 7:return u=o.sent,o.next=10,u.remove();case 10:i(n,0),o.next=17;break;case 13:o.prev=13,o.t0=o.catch(4),null==r||r.addError("pvFileRemoveWasm",o.t0),i(n,-1);case 17:case"end":return o.stop()}}),o,null,[[4,13]])})))},P={wasi_snapshot_preview1:q,env:Object.assign({memory:t,pv_console_log_wasm:u,pv_assert_wasm:f,pv_time_wasm:l,pv_https_request_wasm:p,pv_get_browser_info:v,pv_get_origin_info:_,pv_file_open_wasm:y,pv_file_close_wasm:m,pv_file_read_wasm:g,pv_file_write_wasm:w,pv_file_seek_wasm:b,pv_file_tell_wasm:x,pv_file_remove_wasm:E},n)},!(e instanceof Promise)){o.next=34;break}if(!d){o.next=23;break}return o.next=20,d(e,P);case 20:S=o.sent.instance,o.next=32;break;case 23:return o.next=25,e;case 25:return O=o.sent,o.next=28,O.arrayBuffer();case 28:return A=o.sent,o.next=31,h(new Uint8Array(A),P);case 31:S=o.sent.instance;case 32:o.next=38;break;case 34:return F=R(e),o.next=37,h(F,P);case 37:S=o.sent.instance;case 38:return j=S.exports.aligned_alloc,o.abrupt("return",Object.assign(Object.assign({},S.exports),{aligned_alloc:a}));case 40:case"end":return o.stop()}}),o)})))},t.dbConfig=$,t.fetchWithTimeout=U,t.fromBase64=D,t.fromPublicDirectory=Y,t.getDB=A,t.isAccessKeyValid=function(t){if("string"!=typeof t)return!1;var e=t.trim();if(""===e)return!1;try{return btoa(atob(e))===e}catch(t){return!1}},t.loadModel=function(t){return c(this,void 0,void 0,s.mark((function e(){var r,n,o,i,a,c,u,f,l;return s.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=t){e.next=2;break}throw new Error("The model is undefined / empty");case 2:if(r=t.base64,n=t.publicPath,o=t.customWritePath,i=t.forceWrite,a=void 0!==i&&i,c=t.version,u=void 0===c?1:c,f=t.numFetchRetries,l=void 0===f?0:f,null!=o){e.next=5;break}throw new Error("The customWritePath of the provided model is undefined / empty");case 5:if(null==r){e.next=10;break}return e.next=8,D(o,r,a,u);case 8:case 13:e.next=16;break;case 10:if(null==n){e.next=15;break}return e.next=13,Y(o,n,a,u,l);case 15:throw new Error("The provided model doesn't contain a valid publicPath or base64 value");case 16:return e.abrupt("return",o);case 17:case"end":return e.stop()}}),e)})))},t.open=W,t.stringHeaderToObject=z,t.unsignedAddress=L,Object.defineProperty(t,"__esModule",{value:!0}),t}({}); | ||
var WebUtils=function(t){"use strict";function e(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var r={exports:{}},n={exports:{}};!function(t){function e(r){return t.exports=e="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},t.exports.__esModule=!0,t.exports.default=t.exports,e(r)}t.exports=e,t.exports.__esModule=!0,t.exports.default=t.exports}(n);var o=n.exports;!function(t){var e=o.default;function r(){t.exports=r=function(){return o},t.exports.__esModule=!0,t.exports.default=t.exports;var n,o={},i=Object.prototype,a=i.hasOwnProperty,s=Object.defineProperty||function(t,e,r){t[e]=r.value},c="function"==typeof Symbol?Symbol:{},u=c.iterator||"@@iterator",f=c.asyncIterator||"@@asyncIterator",l=c.toStringTag||"@@toStringTag";function p(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{p({},"")}catch(n){p=function(t,e,r){return t[e]=r}}function h(t,e,r,n){var o=e&&e.prototype instanceof w?e:w,i=Object.create(o.prototype),a=new N(n||[]);return s(i,"_invoke",{value:j(t,r,a)}),i}function d(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}o.wrap=h;var v="suspendedStart",_="suspendedYield",y="executing",m="completed",g={};function w(){}function b(){}function x(){}var E={};p(E,u,(function(){return this}));var k=Object.getPrototypeOf,P=k&&k(k(M([])));P&&P!==i&&a.call(P,u)&&(E=P);var O=x.prototype=w.prototype=Object.create(E);function S(t){["next","throw","return"].forEach((function(e){p(t,e,(function(t){return this._invoke(e,t)}))}))}function A(t,r){function n(o,i,s,c){var u=d(t[o],t,i);if("throw"!==u.type){var f=u.arg,l=f.value;return l&&"object"==e(l)&&a.call(l,"__await")?r.resolve(l.__await).then((function(t){n("next",t,s,c)}),(function(t){n("throw",t,s,c)})):r.resolve(l).then((function(t){f.value=t,s(f)}),(function(t){return n("throw",t,s,c)}))}c(u.arg)}var o;s(this,"_invoke",{value:function(t,e){function i(){return new r((function(r,o){n(t,e,r,o)}))}return o=o?o.then(i,i):i()}})}function j(t,e,r){var o=v;return function(i,a){if(o===y)throw new Error("Generator is already running");if(o===m){if("throw"===i)throw a;return{value:n,done:!0}}for(r.method=i,r.arg=a;;){var s=r.delegate;if(s){var c=F(s,r);if(c){if(c===g)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(o===v)throw o=m,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=y;var u=d(t,e,r);if("normal"===u.type){if(o=r.done?m:_,u.arg===g)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(o=m,r.method="throw",r.arg=u.arg)}}}function F(t,e){var r=e.method,o=t.iterator[r];if(o===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=n,F(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),g;var i=d(o,t.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,g;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,g):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,g)}function I(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 T(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function N(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(I,this),this.reset(!0)}function M(t){if(t||""===t){var r=t[u];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function e(){for(;++o<t.length;)if(a.call(t,o))return e.value=t[o],e.done=!1,e;return e.value=n,e.done=!0,e};return i.next=i}}throw new TypeError(e(t)+" is not iterable")}return b.prototype=x,s(O,"constructor",{value:x,configurable:!0}),s(x,"constructor",{value:b,configurable:!0}),b.displayName=p(x,l,"GeneratorFunction"),o.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===b||"GeneratorFunction"===(e.displayName||e.name))},o.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,p(t,l,"GeneratorFunction")),t.prototype=Object.create(O),t},o.awrap=function(t){return{__await:t}},S(A.prototype),p(A.prototype,f,(function(){return this})),o.AsyncIterator=A,o.async=function(t,e,r,n,i){void 0===i&&(i=Promise);var a=new A(h(t,e,r,n),i);return o.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},S(O),p(O,l,"Generator"),p(O,u,(function(){return this})),p(O,"toString",(function(){return"[object Generator]"})),o.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},o.values=M,N.prototype={constructor:N,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(T),!t)for(var e in this)"t"===e.charAt(0)&&a.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,o){return s.type="throw",s.arg=t,e.next=r,o&&(e.method="next",e.arg=n),!!o}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],s=i.completion;if("root"===i.tryLoc)return r("end");if(i.tryLoc<=this.prev){var c=a.call(i,"catchLoc"),u=a.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return r(i.catchLoc,!0);if(this.prev<i.finallyLoc)return r(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return r(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return r(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&a.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,g):this.complete(i)},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),g},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),T(r),g}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;T(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:M(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=n),g}},o}t.exports=r,t.exports.__esModule=!0,t.exports.default=t.exports}(r);var i=(0,r.exports)(),a=i;try{regeneratorRuntime=i}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=i:Function("r","regeneratorRuntime = r")(i)}var s=e(a);function c(t,e,r,n){return new(r||(r=Promise))((function(o,i){function a(t){try{c(n.next(t))}catch(t){i(t)}}function s(t){try{c(n.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,s)}c((n=n.apply(t,e||[])).next())}))}const u=new WeakMap;function f(t,e){return new Proxy(t,{get:(t,r)=>e(t[r])})}class l{constructor(){this.value=void 0,this.exports=null}getState(){return this.exports.asyncify_get_state()}assertNoneState(){let t=this.getState();if(0!==t)throw new Error(`Invalid async state ${t}, expected 0.`)}wrapImportFn(t){return(...e)=>{if(2===this.getState())return this.exports.asyncify_stop_rewind(),this.value;this.assertNoneState();let r=t(...e);if(!(n=r)||"object"!=typeof n&&"function"!=typeof n||"function"!=typeof n.then)return r;var n;this.exports.asyncify_start_unwind(16),this.value=r}}wrapModuleImports(t){return f(t,(t=>"function"==typeof t?this.wrapImportFn(t):t))}wrapImports(t){if(void 0!==t)return f(t,((t=Object.create(null))=>this.wrapModuleImports(t)))}wrapExportFn(t){let e=u.get(t);return void 0!==e||(e=async(...e)=>{this.assertNoneState();let r=t(...e);for(;1===this.getState();)this.exports.asyncify_stop_unwind(),this.value=await this.value,this.assertNoneState(),this.exports.asyncify_start_rewind(16),r=t();return this.assertNoneState(),r},u.set(t,e)),e}wrapExports(t){let e=Object.create(null);for(let r in t){let n=t[r];"function"!=typeof n||r.startsWith("asyncify_")||(n=this.wrapExportFn(n)),Object.defineProperty(e,r,{enumerable:!0,value:n})}return u.set(t,e),e}init(t,e){const{exports:r}=t,n=r.memory||e.env&&e.env.memory;new Int32Array(n.buffer,16).set([24,1024]),this.exports=this.wrapExports(r),Object.setPrototypeOf(t,p.prototype)}}class p extends WebAssembly.Instance{constructor(t,e){let r=new l;super(t,r.wrapImports(e)),r.init(this,e)}get exports(){return u.get(super.exports)}}async function h(t,e){let r=new l,n=await WebAssembly.instantiate(t,r.wrapImports(e));return r.init(n instanceof WebAssembly.Instance?n:n.instance,e),n}async function d(t,e){let r=new l,n=await WebAssembly.instantiateStreaming(t,r.wrapImports(e));return r.init(n.instance,e),n}function v(t,e){return v=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},v(t,e)}function _(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&v(t,e)}function y(t){return y="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},y(t)}function m(t,e){if(e&&("object"===y(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function g(t){return g=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},g(t)}function w(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function b(t){var e=function(t,e){if("object"!==y(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!==y(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"===y(e)?e:String(e)}function x(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,b(n.key),n)}}function E(t,e,r){return e&&x(t.prototype,e),r&&x(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}Object.defineProperty(p.prototype,"exports",{enumerable:!0});var k=function(){function t(){w(this,t),this._path=""}return E(t,[{key:"meta",get:function(){if(void 0!==this._meta)return Object.assign({version:0},this._meta)}},{key:"pageSize",get:function(){}}],[{key:"getPtr",value:function(e){if(t._filePtrs.has(e))return t._filePtrs.get(e);throw new Error("File instance not found.")}},{key:"setPtr",value:function(e,r){t._filePtrs.set(e,r)}},{key:"removePtr",value:function(e){t._filePtrs.delete(e)}}]),t}();function P(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=g(t);if(e){var o=g(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return m(this,r)}}k._filePtrs=new Map;var O="pv_db",S="pv_file";function A(){return new Promise((function(t,e){var r=self.indexedDB.open(O,3);r.onerror=function(){e(r.error)},r.onsuccess=function(){t(r.result)},r.onupgradeneeded=function(){r.result.objectStoreNames.contains(S)||r.result.createObjectStore(S)}}))}var j=function(){function t(){w(this,t),this._pos=0,this._data=new Uint8Array}return E(t,[{key:"get",value:function(t){if(!(this._pos>=this._data.length)){var e=this._data.slice(this._pos,this._pos+t);return this._pos+=t,e}}},{key:"set",value:function(t,e){this._pos=t,this._data=e}},{key:"clear",value:function(){this._pos=0,this._data=new Uint8Array}}]),t}(),F=function(t){_(r,t);var e=P(r);function r(t,n,o,i){var a;return w(this,r),(a=e.call(this))._pageSize=524288,a._pagePtr=0,a._pageOffset=0,a._path=t,a._meta=n,a._db=o,a._mode=i,a._cache=new j,a}return E(r,[{key:"pageSize",get:function(){return this._pageSize}},{key:"close",value:function(){return c(this,void 0,void 0,s.mark((function t(){return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:this._db.close();case 1:case"end":return t.stop()}}),t,this)})))}},{key:"read",value:function(t,e){return c(this,void 0,void 0,s.mark((function n(){var o=this;return s.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",new Promise((function(n,i){if(o.exists()){if(o._isEOF){var a=new Error("EOF");return a.name="EndOfFile",void i(a)}var s=0,c=Math.min(t*e,o._meta.size),u=c-c%t,f=new Uint8Array(u),l=o._cache.get(u);if(l){if(s+=l.length,o._pageOffset+=l.length,o._pageOffset===o._pageSize&&(o._pagePtr+=1,o._pageOffset=0),u===s)return void n(l);f.set(l)}var p=IDBKeyRange.bound("".concat(o._path,"-").concat(r.createPage(o._pagePtr)),"".concat(o._path,"-").concat(r.createPage(o._pagePtr+Math.floor(u/o._pageSize)+1))),h=o._store,d=h.openCursor(p);d.onsuccess=function(){var t,e,r=d.result;if(r&&!o._isEOF){var n=Math.min(u-s,r.value.length-o._pageOffset);f.set(r.value.slice(o._pageOffset,o._pageOffset+n),s),s+=n,o._pageOffset+=n,o._pageOffset===o._pageSize&&(o._pagePtr+=1,o._pageOffset=0),s<u?r.continue():(0!==o._pageOffset?o._cache.set(o._pageOffset,r.value):o._cache.clear(),(null===(t=h.transaction)||void 0===t?void 0:t.commit)&&(null===(e=h.transaction)||void 0===e||e.commit()))}},h.transaction.onerror=function(){i(h.transaction.error)},h.transaction.oncomplete=function(){n(f.slice(0,s))}}else i(new Error("'".concat(o._path,"' doesn't exist.")))})));case 1:case"end":return n.stop()}}),n)})))}},{key:"write",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return c(this,void 0,void 0,s.mark((function n(){var o=this;return s.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",new Promise((function(n,i){return c(o,void 0,void 0,s.mark((function o(){var a,c,u,f,l,p,h,d,v,_,y,m=this;return s.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:if("readonly"!==this._mode){o.next=3;break}return i(new Error("Instance is readonly mode only.")),o.abrupt("return");case 3:if(!("number"!=typeof e&&e<=0)){o.next=6;break}return i(new Error("Version should be a positive number")),o.abrupt("return");case 6:return u=this._store,f=function(){return new Promise((function(t){var e=u.get("".concat(m._path,"-").concat(r.createPage(m._pagePtr)));e.onsuccess=function(){void 0!==e.result?t(e.result.slice(0,m._pageOffset)):t(new Uint8Array(0))}}))},o.next=10,f();case 10:for(l=o.sent,(p=new Uint8Array(l.length+t.length)).set(l),p.set(t,l.length),h=this._pagePtr*this._pageSize+p.length,d={size:h,numPages:Math.ceil(h/this._pageSize),version:e,pageSize:this._pageSize},u.put(d,this._path),v=Math.ceil(p.length/this._pageSize),_=0;_<v;_++)u.put(p.slice(_*this._pageSize,(_+1)*this._pageSize),"".concat(this._path,"-").concat(r.createPage(this._pagePtr+_)));this.exists()&&d.numPages<this._meta.numPages&&(y=IDBKeyRange.bound("".concat(this._path,"-").concat(r.createPage(d.numPages)),"".concat(this._path,"-").concat(r.createPage(this._meta.numPages)),!0),u.delete(y)),(null===(a=u.transaction)||void 0===a?void 0:a.commit)&&(null===(c=u.transaction)||void 0===c||c.commit()),u.transaction.onerror=function(){i(u.transaction.error)},u.transaction.oncomplete=function(){m._meta=d,m.seek(0,2),n()};case 23:case"end":return o.stop()}}),o,this)})))})));case 1:case"end":return n.stop()}}),n)})))}},{key:"seek",value:function(t,e){if(!this.exists()&&"readonly"===this._mode)throw new Error("'".concat(this._path,"' doesn't exist."));if(!this.exists())throw new Error("'".concat(this._path,"' doesn't exist."));if(t<0){var r=new Error("EOF");throw r.name="EndOfFile",r}var n;if(0===e)n=Math.min(t,this._meta.size);else if(1===e){var o=this._pageSize*this._pagePtr+this._pageOffset;n=Math.min(o+t,this._meta.size)}else{if(2!==e)throw new Error("Invalid operation: ".concat(e,"."));n=Math.min(this._meta.size+t,this._meta.size)}this._pageOffset=n%this._pageSize,this._pagePtr=Math.floor(n/this._pageSize),this._cache.clear()}},{key:"tell",value:function(){return this.exists()?this._pagePtr*this._pageSize+this._pageOffset:-1}},{key:"remove",value:function(){return c(this,void 0,void 0,s.mark((function t(){var e=this;return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise((function(t,n){return c(e,void 0,void 0,s.mark((function e(){var o,i,a,c,u=this;return s.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.exists()){e.next=3;break}return n(new Error("ENOENT")),e.abrupt("return");case 3:o=this._meta.numPages,i=IDBKeyRange.bound(this._path,"".concat(this._path,"-").concat(r.createPage(o))),a=this._store,(c=a.delete(i)).onerror=function(){n(c.error)},c.onsuccess=function(){u._meta=void 0,u._pageOffset=0,u._pagePtr=0,t()};case 9:case"end":return e.stop()}}),e,this)})))})));case 1:case"end":return t.stop()}}),t)})))}},{key:"exists",value:function(){return void 0!==this._meta}},{key:"_isEOF",get:function(){return this._pagePtr>=this._meta.numPages-1&&this._pageOffset>=this._meta.size%this._pageSize}},{key:"_store",get:function(){return this._db.transaction(S,this._mode).objectStore(S)}}],[{key:"open",value:function(t,e){var n=this;if(!self.indexedDB){var o=new Error("IndexedDB is not supported");throw o.name="IndexedDBNotSupported",o}return new Promise((function(o,i){return c(n,void 0,void 0,s.mark((function n(){var a,c,u;return s.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,n.next=3,A();case 3:a=n.sent,(c=a.transaction(S,"readwrite").objectStore(S).get(t)).onerror=function(){i(c.error)},c.onsuccess=function(){var n=c.result,s=e.includes("r")?"readonly":"readwrite";if(void 0===n&&"readonly"===s){var u=new Error("'".concat(t,"' doesn't exist."));return u.name="FileNotExists",void i(u)}var f=new r(t,n,a,s);e.includes("a")&&f.seek(0,2),o(f)},n.next=12;break;case 9:n.prev=9,n.t0=n.catch(0),"InvalidStateError"===n.t0.name?((u=new Error("IndexedDB is not supported")).name="IndexedDBNotSupported",i(u)):i(n.t0);case 12:case"end":return n.stop()}}),n,null,[[0,9]])})))}))}},{key:"createPage",value:function(t){return("00000"+t).slice(-6)}}]),r}(k);function I(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=g(t);if(e){var o=g(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return m(this,r)}}var T=function(t){_(r,t);var e=I(r);function r(t,n,o,i){var a;return w(this,r),(a=e.call(this))._pos=0,a._path=t,a._meta=n,a._mode=i,a}return E(r,[{key:"close",value:function(){}},{key:"read",value:function(t,e){if(!this.exists())throw new Error("'".concat(this._path,"' doesn't exist."));if(this._isEOF){var r=new Error("EOF");throw r.name="EndOfFile",r}var n=Math.min(t*e,this._file.length-this._pos),o=n-n%t,i=new Uint8Array(o);return i.set(this._file.slice(this._pos,this._pos+o),0),this._pos+=o,i}},{key:"write",value:function(t){var e=new Uint8Array(this._pos+t.length);void 0!==this._file?(e.set(this._file.slice(0,this._pos)),e.set(t,this._pos)):e.set(t),this._file=e,this._pos+=t.length}},{key:"seek",value:function(t,e){if(!this.exists()&&"readonly"===this._mode)throw new Error("'".concat(this._path,"' doesn't exist."));if(!this.exists())throw new Error("'".concat(this._path,"' doesn't exist."));if(t<0){var r=new Error("EOF");throw r.name="EndOfFile",r}var n;if(0===e)n=Math.min(t,this._file.length);else if(1===e)n=Math.min(this._pos+t,this._file.length);else{if(2!==e)throw new Error("Invalid operation: ".concat(e,"."));n=Math.min(this._file.length+t,this._file.length)}this._pos=n}},{key:"tell",value:function(){return this.exists()?this._pos:-1}},{key:"remove",value:function(){return c(this,void 0,void 0,s.mark((function t(){return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.exists()){t.next=2;break}throw new Error("ENOENT");case 2:r._memFiles.delete(this._path),this._pos=0;case 4:case"end":return t.stop()}}),t,this)})))}},{key:"exists",value:function(){return void 0!==this._file}},{key:"_isEOF",get:function(){return this._pos>=this._file.length}},{key:"_file",get:function(){return r._memFiles.get(this._path)},set:function(t){r._memFiles.set(this._path,t)}}],[{key:"open",value:function(t,e){var n=r._memFiles.get(t),o=e.includes("r")?"readonly":"readwrite";if(void 0===n&&"readonly"===o){var i=new Error("'".concat(t,"' doesn't exist."));throw i.name="FileNotExists",i}var a=new r(t,void 0,void 0,o);return e.includes("a")&&a.seek(0,2),a}}]),r}(k);function N(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return M(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return M(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,s=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return a=t.done,t},e:function(t){s=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw i}}}}function M(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function L(t){return t<0?t>>>0:t}function B(t,e){for(var r=e;0!==t[r];)r++;return new TextDecoder("utf-8").decode(t.slice(e,r))}function R(t){for(var e=atob(t),r=new Uint8Array(e.length),n=0;n<e.length;n++)r[n]=e.charCodeAt(n);return r}function z(t){var e,r={},n=N(t.split("\r\n"));try{for(n.s();!(e=n.n()).done;){var o=e.value.split(": ");""!==o[0]&&(r[o[0]]=o[1])}}catch(t){n.e(t)}finally{n.f()}return r}function U(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:5e3;return c(this,void 0,void 0,s.mark((function n(){var o,i,a,c;return s.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return o=new AbortController,i=Object.assign(Object.assign({},e),{signal:o.signal}),a=setTimeout((function(){o.abort()}),r),n.next=5,fetch(t,i);case 5:return c=n.sent,clearTimeout(a),n.abrupt("return",c);case 8:case"end":return n.stop()}}),n)})))}function W(t,e){return c(this,void 0,void 0,s.mark((function r(){var n;return s.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.prev=0,r.next=3,F.open(t,e);case 3:return r.abrupt("return",r.sent);case 6:if(r.prev=6,r.t0=r.catch(0),"IndexedDBNotSupported"===r.t0.name?console.warn("IndexedDB is not supported. Fallback to in-memory storage."):"FileNotExists"!==r.t0.name&&console.warn("Unable to access IndexedDB (".concat(r.t0.toString(),"). Fallback to in-memory storage.")),!("undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope)){r.next=16;break}if("FileNotExists"!==r.t0.name){r.next=12;break}throw r.t0;case 12:throw console.error("In-memory storage cannot be used inside a worker."),(n=new Error("Failed to start PvFile: ".concat(r.t0.toString()))).name="PvFileNotSupported",n;case 16:return r.abrupt("return",T.open(t,e));case 17:case"end":return r.stop()}}),r,null,[[0,6]])})))}function D(t,e,r,n){return c(this,void 0,void 0,s.mark((function o(){var i;return s.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return o.next=2,W(t,"w");case 2:if(i=o.sent,!(r||void 0===i.meta||n>i.meta.version||i.meta.pageSize!==i.pageSize)){o.next=6;break}return o.next=6,i.write(R(e),n);case 6:case"end":return o.stop()}}),o)})))}T._memFiles=new Map;var C=5e3,G=2;function Y(t,e,r,n,o){return c(this,void 0,void 0,s.mark((function i(){var a,c,u,f,l,p,h,d;return s.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return i.next=2,W(t,"w");case 2:if(a=i.sent,!(r||void 0===a.meta||n>a.meta.version||a.meta.pageSize!==a.pageSize)){i.next=43;break}if(!(o<0)){i.next=6;break}throw Error("numFetchRetries must be a positive number");case 6:c=G,u=function(t){return new Promise((function(e){setTimeout(e,t)}))},f=o+1,l=null;case 10:if(!(f>0)){i.next=38;break}return l=null,i.prev=12,i.next=15,fetch(e,{cache:"no-cache"});case 15:if(!(p=i.sent).ok){i.next=23;break}return i.next=19,p.arrayBuffer();case 19:return h=i.sent,i.next=22,a.write(new Uint8Array(h),n);case 22:return i.abrupt("return");case 23:return i.next=25,p.text();case 25:d=i.sent,l=new Error("Error response returned while fetching model from '".concat(e,"': ").concat(d)),i.next=32;break;case 29:i.prev=29,i.t0=i.catch(12),l=new Error("Failed to fetch model from '".concat(e,"': ").concat(i.t0.message));case 32:return f--,i.next=35,u(c);case 35:c=Math.min(C,c*G),i.next=10;break;case 38:if(null===l){i.next=42;break}throw l;case 42:throw new Error("Unexpected error encountered while fetching model from '".concat(e,"'"));case 43:case"end":return i.stop()}}),i,null,[[12,29]])})))}var q={args_get:function(t){return 0},args_sizes_get:function(t){return 0},environ_get:function(t){return 0},environ_sizes_get:function(t){return 0},clock_res_get:function(t){return 0},clock_time_get:function(t){return 0},fd_advise:function(t){return 0},fd_allocate:function(t){return 0},fd_close:function(t){return 0},fd_datasync:function(t){return 0},fd_fdstat_get:function(t){return 0},fd_fdstat_set_flags:function(t){return 0},fd_fdstat_set_rights:function(t){return 0},fd_filestat_get:function(t){return 0},fd_filestat_set_size:function(t){return 0},fd_filestat_set_times:function(t){return 0},fd_pread:function(t){return 0},fd_prestat_get:function(t){return 0},fd_prestat_dir_name:function(t){return 0},fd_pwrite:function(t){return 0},fd_read:function(t){return 0},fd_readdir:function(t){return 0},fd_renumber:function(t){return 0},fd_seek:function(t){return 0},fd_sync:function(t){return 0},fd_tell:function(t){return 0},fd_write:function(t){return 0},path_create_directory:function(t){return 0},path_filestat_get:function(t){return 0},path_filestat_set_times:function(t){return 0},path_link:function(t){return 0},path_open:function(t){return 0},path_readlink:function(t){return 0},path_remove_directory:function(t){return 0},path_rename:function(t){return 0},path_symlink:function(t){return 0},path_unlink_file:function(t){return 0},poll_oneoff:function(t){return 0},proc_exit:function(t){return 0},proc_raise:function(t){return 0},sched_yield:function(t){return 0},random_get:function(t){return 0},sock_recv:function(t){return 0},sock_send:function(t){return 0},sock_shutdown:function(t){return 0}};function H(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function K(t){return function(t){if(Array.isArray(t))return H(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return H(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?H(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var V=function(){function t(){w(this,t),this._maxNumErrors=10,this._errors=[],this._lastError=new Error("null")}return E(t,[{key:"addError",value:function(t,e){this._lastError=e instanceof Error?e:new Error(e),this._errors.length>=this._maxNumErrors&&this._errors.shift(),e instanceof Error?this._errors.push({key:t,message:e.toString()}):this._errors.push({key:t,message:JSON.stringify(e)})}},{key:"getErrors",value:function(){var t=K(this._errors);return this._errors=[],t}},{key:"getErrorString",value:function(){return this.getErrors().map((function(t){var e=t.key,r=t.message;return"'".concat(e,"' failed with: ").concat(r,".")})).join("\n")}},{key:"getLastError",value:function(){return this._lastError}},{key:"setMaxErrorNum",value:function(t){this._maxNumErrors=t}}]),t}(),$={DB_NAME:O,DB_VERSION:3,PV_FILE_STORE:S};return t.PvError=V,t.PvFile=k,t.PvFileIDB=F,t.PvFileMem=T,t.arrayBufferToBase64AtIndex=function(t,e,r){for(var n="",o=0;o<e;o++)n+=String.fromCharCode(t[r+o]);return btoa(n)},t.arrayBufferToStringAtIndex=B,t.base64ToUint8Array=R,t.buildWasm=function(t,e,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};return c(this,void 0,void 0,s.mark((function i(){var a,u,f,l,p,v,_,y,m,g,w,b,x,E,P,O,S,A,j,F,I;return s.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:if(a=function(e,r){new Int32Array(t.buffer)[e/Int32Array.BYTES_PER_ELEMENT]=r},u=function(t,e){return c(this,void 0,void 0,s.mark((function r(){var n;return s.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,I(t,e);case 2:return n=r.sent,r.abrupt("return",L(n));case 4:case"end":return r.stop()}}),r)})))},f=function(e){e=L(e);var r=new Uint8Array(t.buffer);console.log(B(r,e))},l=function(e,r,n){n=L(n);var o=new Uint8Array(t.buffer);if(0===e){var i=B(o,n);throw new Error("assertion failed at line ".concat(r,' in "').concat(i,'"'))}},p=function(){return Date.now()/1e3},v=function(e,n,o,i,f,l,p,h,d){return c(this,void 0,void 0,s.mark((function c(){var v,_,y,m,g,w,b,x,E,k,P,O,S;return s.wrap((function(s){for(;;)switch(s.prev=s.next){case 0:return e=L(e),n=L(n),o=L(o),i=L(i),f=L(f),p=L(p),h=L(h),d=L(d),v=new Uint8Array(t.buffer),_=B(v,e),y=B(v,n),m=B(v,o),g=B(v,i),w=B(v,f),b=z(g),x={method:_},w.length>0&&(x.body=w),Object.keys(b).length>0&&(x.headers=b),s.prev=18,s.next=21,U("https://"+y+m,x,l);case 21:E=s.sent,P=E.status,s.next=29;break;case 25:return s.prev=25,s.t0=s.catch(18),null==r||r.addError("pvHttpsRequestWasm","Failed to fetch: ".concat(s.t0)),s.abrupt("return");case 29:return s.prev=29,s.next=32,E.text();case 32:k=s.sent,s.next=39;break;case 35:return s.prev=35,s.t1=s.catch(29),null==r||r.addError("pvHttpsRequestWasm","Failed to get response text: ".concat(s.t1)),s.abrupt("return");case 39:return s.next=41,u(Int8Array.BYTES_PER_ELEMENT,(k.length+1)*Int8Array.BYTES_PER_ELEMENT);case 41:if(0!==(O=s.sent)){s.next=46;break}return null==r||r.addError("pvMallocError","pvHttpsRequestWasm: cannot allocate memory for response"),a(p,0),s.abrupt("return");case 46:for(a(h,k.length+1),a(p,O),S=0;S<k.length;S++)v[O+S]=k.charCodeAt(S);v[O+k.length]=0,a(d,P);case 51:case"end":return s.stop()}}),c,null,[[18,25],[29,35]])})))},_=function(e){return c(this,void 0,void 0,s.mark((function n(){var o,i,c,f;return s.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return e=L(e),o=new Uint8Array(t.buffer),i=void 0!==navigator.userAgent?navigator.userAgent:"unknown",n.next=5,u(Uint8Array.BYTES_PER_ELEMENT,(i.length+1)*Uint8Array.BYTES_PER_ELEMENT);case 5:if(0!==(c=n.sent)){n.next=10;break}return null==r||r.addError("pvMallocError","pvGetBrowserInfo: cannot allocate memory for browser info"),a(e,0),n.abrupt("return");case 10:for(a(e,c),f=0;f<i.length;f++)o[c+f]=i.charCodeAt(f);o[c+i.length]=0;case 13:case"end":return n.stop()}}),n)})))},y=function(e){var n;return c(this,void 0,void 0,s.mark((function o(){var i,c,f,l,p;return s.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return e=L(e),i=new Uint8Array(t.buffer),c=null!==(n=self.origin)&&void 0!==n?n:self.location.origin,f=new URL(c).hostname,o.next=6,u(Uint8Array.BYTES_PER_ELEMENT,(f.length+1)*Uint8Array.BYTES_PER_ELEMENT);case 6:if(0!==(l=o.sent)){o.next=11;break}return null==r||r.addError("pvMallocError","pvGetOriginInfo: cannot allocate memory for origin info"),a(e,0),o.abrupt("return");case 11:for(a(e,l),p=0;p<f.length;p++)i[l+p]=f.charCodeAt(p);i[l+f.length]=0;case 14:case"end":return o.stop()}}),o)})))},m=function(e,n,o,i){return c(this,void 0,void 0,s.mark((function c(){var u,f,l,p;return s.wrap((function(s){for(;;)switch(s.prev=s.next){case 0:return e=L(e),n=L(n),o=L(o),i=L(i),u=new Uint8Array(t.buffer),f=B(u,n),l=B(u,o),s.prev=7,s.next=10,W(f,l);case 10:p=s.sent,k.setPtr(e,p),a(i,0),s.next=19;break;case 15:s.prev=15,s.t0=s.catch(7),"FileNotExists"!==s.t0.name&&(null==r||r.addError("pvFileOpenWasm",s.t0)),a(i,-1);case 19:case"end":return s.stop()}}),c,null,[[7,15]])})))},g=function(t,e){return c(this,void 0,void 0,s.mark((function n(){var o;return s.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return t=L(t),e=L(e),n.prev=2,n.next=5,k.getPtr(t);case 5:return o=n.sent,n.next=8,o.close();case 8:a(e,0),n.next=15;break;case 11:n.prev=11,n.t0=n.catch(2),null==r||r.addError("pvFileCloseWasm",n.t0),a(e,-1);case 15:case"end":return n.stop()}}),n,null,[[2,11]])})))},w=function(e,n,o,i,u){return c(this,void 0,void 0,s.mark((function c(){var f,l,p;return s.wrap((function(s){for(;;)switch(s.prev=s.next){case 0:return e=L(e),n=L(n),u=L(u),f=new Uint8Array(t.buffer),s.prev=4,l=k.getPtr(e),s.next=8,l.read(o,i);case 8:p=s.sent,f.set(p,L(n)),a(u,p.length/o),s.next=17;break;case 13:s.prev=13,s.t0=s.catch(4),null==r||r.addError("pvFileReadWasm",s.t0),a(u,-1);case 17:case"end":return s.stop()}}),c,null,[[4,13]])})))},b=function(e,n,o,i,u){return c(this,void 0,void 0,s.mark((function c(){var f,l,p;return s.wrap((function(s){for(;;)switch(s.prev=s.next){case 0:return e=L(e),n=L(n),u=L(u),f=new Uint8Array(t.buffer),s.prev=4,l=k.getPtr(e),(p=new Uint8Array(o*i)).set(f.slice(L(n),L(n)+o*i),0),s.next=10,l.write(p);case 10:a(u,p.length/o),s.next=17;break;case 13:s.prev=13,s.t0=s.catch(4),null==r||r.addError("pvFileWriteWasm",s.t0),a(u,-1);case 17:case"end":return s.stop()}}),c,null,[[4,13]])})))},x=function(t,e,n,o){t=L(t),o=L(o);try{k.getPtr(t).seek(e,n),a(o,0)}catch(t){null==r||r.addError("pvFileSeekWasm",t),a(o,-1)}},E=function(t,e){t=L(t),e=L(e);try{var n=k.getPtr(t);a(e,n.tell())}catch(t){null==r||r.addError("pvFileTellWasm",t),a(e,-1)}},P=function(e,n){return c(this,void 0,void 0,s.mark((function o(){var i,c,u;return s.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return e=L(e),n=L(n),i=new Uint8Array(t.buffer),c=B(i,e),o.prev=4,o.next=7,W(c,"w");case 7:return u=o.sent,o.next=10,u.remove();case 10:a(n,0),o.next=17;break;case 13:o.prev=13,o.t0=o.catch(4),null==r||r.addError("pvFileRemoveWasm",o.t0),a(n,-1);case 17:case"end":return o.stop()}}),o,null,[[4,13]])})))},O={wasi_snapshot_preview1:q,env:Object.assign({memory:t,pv_console_log_wasm:f,pv_assert_wasm:l,pv_time_wasm:p,pv_https_request_wasm:v,pv_get_browser_info:_,pv_get_origin_info:y,pv_file_open_wasm:m,pv_file_close_wasm:g,pv_file_read_wasm:w,pv_file_write_wasm:b,pv_file_seek_wasm:x,pv_file_tell_wasm:E,pv_file_remove_wasm:P},n),wasi:Object.assign({},o)},!(e instanceof Promise)){i.next=34;break}if(!d){i.next=23;break}return i.next=20,d(e,O);case 20:S=i.sent.instance,i.next=32;break;case 23:return i.next=25,e;case 25:return A=i.sent,i.next=28,A.arrayBuffer();case 28:return j=i.sent,i.next=31,h(new Uint8Array(j),O);case 31:S=i.sent.instance;case 32:i.next=38;break;case 34:return F=R(e),i.next=37,h(F,O);case 37:S=i.sent.instance;case 38:return I=S.exports.aligned_alloc,i.abrupt("return",Object.assign(Object.assign({},S.exports),{aligned_alloc:u}));case 40:case"end":return i.stop()}}),i)})))},t.dbConfig=$,t.fetchWithTimeout=U,t.fromBase64=D,t.fromPublicDirectory=Y,t.getDB=A,t.isAccessKeyValid=function(t){if("string"!=typeof t)return!1;var e=t.trim();if(""===e)return!1;try{return btoa(atob(e))===e}catch(t){return!1}},t.loadModel=function(t){return c(this,void 0,void 0,s.mark((function e(){var r,n,o,i,a,c,u,f,l;return s.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=t){e.next=2;break}throw new Error("The model is undefined / empty");case 2:if(r=t.base64,n=t.publicPath,o=t.customWritePath,i=t.forceWrite,a=void 0!==i&&i,c=t.version,u=void 0===c?1:c,f=t.numFetchRetries,l=void 0===f?0:f,null!=o){e.next=5;break}throw new Error("The customWritePath of the provided model is undefined / empty");case 5:if(null==r){e.next=10;break}return e.next=8,D(o,r,a,u);case 8:case 13:e.next=16;break;case 10:if(null==n){e.next=15;break}return e.next=13,Y(o,n,a,u,l);case 15:throw new Error("The provided model doesn't contain a valid publicPath or base64 value");case 16:return e.abrupt("return",o);case 17:case"end":return e.stop()}}),e)})))},t.open=W,t.stringHeaderToObject=z,t.unsignedAddress=L,Object.defineProperty(t,"__esModule",{value:!0}),t}({}); |
@@ -11,5 +11,6 @@ import { PvError } from './pv_error'; | ||
* @param additionalImports Extra WASM imports. | ||
* @param wasiImports Additional WASI imports. | ||
* @returns An object containing the exported functions from WASM. | ||
*/ | ||
export declare function buildWasm(memory: WebAssembly.Memory, wasm: string | Promise<Response>, pvError?: PvError, additionalImports?: Record<string, any>): Promise<any>; | ||
export declare function buildWasm(memory: WebAssembly.Memory, wasm: string | Promise<Response>, pvError?: PvError, additionalImports?: Record<string, any>, wasiImports?: Record<string, any>): Promise<any>; | ||
//# sourceMappingURL=wasm.d.ts.map |
{ | ||
"name": "@picovoice/web-utils", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"description": "Picovoice web utility functions", | ||
@@ -5,0 +5,0 @@ "author": "Picovoice", |
@@ -45,3 +45,3 @@ /* | ||
const utf8decoder = new TextDecoder('utf-8'); | ||
return utf8decoder.decode(arrayBuffer.subarray(indexStart, indexEnd)); | ||
return utf8decoder.decode(arrayBuffer.slice(indexStart, indexEnd)); | ||
} | ||
@@ -48,0 +48,0 @@ |
@@ -40,2 +40,3 @@ /* | ||
* @param additionalImports Extra WASM imports. | ||
* @param wasiImports Additional WASI imports. | ||
* @returns An object containing the exported functions from WASM. | ||
@@ -48,2 +49,3 @@ */ | ||
additionalImports: Record<string, any> = {}, | ||
wasiImports: Record<string, any> = {} | ||
): Promise<any> { | ||
@@ -409,4 +411,7 @@ const setInt = (address: number, value: number) => { | ||
pv_file_remove_wasm: pvFileRemoveWasm, | ||
...additionalImports | ||
...additionalImports, | ||
}, | ||
wasi: { | ||
...wasiImports, | ||
} | ||
}; | ||
@@ -413,0 +418,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
368016
7476