summit/frontend/node_modules/@monogrid/gainmap-js/dist/worker-interface.umd.min.cjs

6 lines
5.5 KiB
JavaScript

/**
* @monogrid/gainmap-js v3.4.0
* With ❤️, by MONOGRID <gainmap@monogrid.com>
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["worker-interface"]={})}(this,function(e){"use strict";var t,n,r,o,i,s,u="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function c(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function a(){if(o)return r;o=1;var e=function(){if(n)return t;n=1;var e,r,o=u.MutationObserver||u.WebKitMutationObserver;if(process.browser)if(o){var i=0,s=new o(f),c=u.document.createTextNode("");s.observe(c,{characterData:!0}),e=function(){c.data=i=++i%2}}else if(u.setImmediate||void 0===u.MessageChannel)e="document"in u&&"onreadystatechange"in u.document.createElement("script")?function(){var e=u.document.createElement("script");e.onreadystatechange=function(){f(),e.onreadystatechange=null,e.parentNode.removeChild(e),e=null},u.document.documentElement.appendChild(e)}:function(){setTimeout(f,0)};else{var a=new u.MessageChannel;a.port1.onmessage=f,e=function(){a.port2.postMessage(0)}}else e=function(){process.nextTick(f)};var l=[];function f(){var e,t;r=!0;for(var n=l.length;n;){for(t=l,l=[],e=-1;++e<n;)t[e]();n=l.length}r=!1}return t=function(t){1!==l.push(t)||r||e()}}();function i(){}var s={},c=["REJECTED"],a=["FULFILLED"],l=["PENDING"];if(!process.browser)var f=["UNHANDLED"];function h(e){if("function"!=typeof e)throw new TypeError("resolver must be a function");this.state=l,this.queue=[],this.outcome=void 0,process.browser||(this.handled=f),e!==i&&y(this,e)}function p(e,t,n){this.promise=e,"function"==typeof t&&(this.onFulfilled=t,this.callFulfilled=this.otherCallFulfilled),"function"==typeof n&&(this.onRejected=n,this.callRejected=this.otherCallRejected)}function d(t,n,r){e(function(){var e;try{e=n(r)}catch(e){return s.reject(t,e)}e===t?s.reject(t,new TypeError("Cannot resolve promise with itself")):s.resolve(t,e)})}function v(e){var t=e&&e.then;if(e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof t)return function(){t.apply(e,arguments)}}function y(e,t){var n=!1;function r(t){n||(n=!0,s.reject(e,t))}function o(t){n||(n=!0,s.resolve(e,t))}var i=m(function(){t(o,r)});"error"===i.status&&r(i.value)}function m(e,t){var n={};try{n.value=e(t),n.status="success"}catch(e){n.status="error",n.value=e}return n}return r=h,h.prototype.finally=function(e){if("function"!=typeof e)return this;var t=this.constructor;return this.then(function(n){return t.resolve(e()).then(function(){return n})},function(n){return t.resolve(e()).then(function(){throw n})})},h.prototype.catch=function(e){return this.then(null,e)},h.prototype.then=function(e,t){if("function"!=typeof e&&this.state===a||"function"!=typeof t&&this.state===c)return this;var n=new this.constructor(i);(process.browser||this.handled===f&&(this.handled=null),this.state!==l)?d(n,this.state===a?e:t,this.outcome):this.queue.push(new p(n,e,t));return n},p.prototype.callFulfilled=function(e){s.resolve(this.promise,e)},p.prototype.otherCallFulfilled=function(e){d(this.promise,this.onFulfilled,e)},p.prototype.callRejected=function(e){s.reject(this.promise,e)},p.prototype.otherCallRejected=function(e){d(this.promise,this.onRejected,e)},s.resolve=function(e,t){var n=m(v,t);if("error"===n.status)return s.reject(e,n.value);var r=n.value;if(r)y(e,r);else{e.state=a,e.outcome=t;for(var o=-1,i=e.queue.length;++o<i;)e.queue[o].callFulfilled(t)}return e},s.reject=function(t,n){t.state=c,t.outcome=n,process.browser||t.handled===f&&e(function(){t.handled===f&&process.emit("unhandledRejection",n,t)});for(var r=-1,o=t.queue.length;++r<o;)t.queue[r].callRejected(n);return t},h.resolve=function(e){if(e instanceof this)return e;return s.resolve(new this(i),e)},h.reject=function(e){var t=new this(i);return s.reject(t,e)},h.all=function(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var n=e.length,r=!1;if(!n)return this.resolve([]);var o=new Array(n),u=0,c=-1,a=new this(i);for(;++c<n;)l(e[c],c);return a;function l(e,i){t.resolve(e).then(function(e){o[i]=e,++u!==n||r||(r=!0,s.resolve(a,o))},function(e){r||(r=!0,s.reject(a,e))})}},h.race=function(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var n=e.length,r=!1;if(!n)return this.resolve([]);var o=-1,u=new this(i);for(;++o<n;)c(e[o]);return u;function c(e){t.resolve(e).then(function(e){r||(r=!0,s.resolve(u,e))},function(e){r||(r=!0,s.reject(u,e))})}},r}var l=function(){if(s)return i;s=1;var e="undefined"!=typeof Promise?Promise:a(),t=0;function n(e,t){var n=t.data;if(Array.isArray(n)&&!(n.length<2)){var r=n[0],o=n[1],i=n[2],s=e._callbacks[r];s&&(delete e._callbacks[r],s(o,i))}}function r(e){var t=this;t._worker=e,t._callbacks={},e.addEventListener("message",function(e){n(t,e)})}return r.prototype.postMessage=function(r,o){var i=this,s=t++,u=[s,r];return new e(function(e,t){if(i._callbacks[s]=function(n,r){if(n)return t(new Error(n.message));e(r)},void 0!==i._worker.controller){var r=new MessageChannel;r.port1.onmessage=function(e){n(i,e)},i._worker.controller.postMessage(u,[r.port2].concat(o))}else i._worker.postMessage(u,o)})},r.prototype.terminate=function(){this._worker.terminate()},i=r}(),f=c(l);e.getPromiseWorker=e=>new f(e),e.getWorkerInterface=e=>({compress:t=>e.postMessage({type:"compress",payload:t})})});