6 lines
5.1 KiB
JavaScript
6 lines
5.1 KiB
JavaScript
/**
|
|
* @monogrid/gainmap-js v3.4.0
|
|
* With ❤️, by MONOGRID <gainmap@monogrid.com>
|
|
*/
|
|
import{c as e,g as t}from"./_commonjsHelpers-CDmClQiF.js";var r,n,o,s,i,c;function u(){if(s)return o;s=1;var t=function(){if(n)return r;n=1;var t,o,s=e.MutationObserver||e.WebKitMutationObserver;if(process.browser)if(s){var i=0,c=new s(f),u=e.document.createTextNode("");c.observe(u,{characterData:!0}),t=function(){u.data=i=++i%2}}else if(e.setImmediate||void 0===e.MessageChannel)t="document"in e&&"onreadystatechange"in e.document.createElement("script")?function(){var t=e.document.createElement("script");t.onreadystatechange=function(){f(),t.onreadystatechange=null,t.parentNode.removeChild(t),t=null},e.document.documentElement.appendChild(t)}:function(){setTimeout(f,0)};else{var a=new e.MessageChannel;a.port1.onmessage=f,t=function(){a.port2.postMessage(0)}}else t=function(){process.nextTick(f)};var l=[];function f(){var e,t;o=!0;for(var r=l.length;r;){for(t=l,l=[],e=-1;++e<r;)t[e]();r=l.length}o=!1}return r=function(e){1!==l.push(e)||o||t()}}();function i(){}var c={},u=["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&&m(this,e)}function p(e,t,r){this.promise=e,"function"==typeof t&&(this.onFulfilled=t,this.callFulfilled=this.otherCallFulfilled),"function"==typeof r&&(this.onRejected=r,this.callRejected=this.otherCallRejected)}function v(e,r,n){t(function(){var t;try{t=r(n)}catch(t){return c.reject(e,t)}t===e?c.reject(e,new TypeError("Cannot resolve promise with itself")):c.resolve(e,t)})}function d(e){var t=e&&e.then;if(e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof t)return function(){t.apply(e,arguments)}}function m(e,t){var r=!1;function n(t){r||(r=!0,c.reject(e,t))}function o(t){r||(r=!0,c.resolve(e,t))}var s=y(function(){t(o,n)});"error"===s.status&&n(s.value)}function y(e,t){var r={};try{r.value=e(t),r.status="success"}catch(e){r.status="error",r.value=e}return r}return o=h,h.prototype.finally=function(e){if("function"!=typeof e)return this;var t=this.constructor;return this.then(function(r){return t.resolve(e()).then(function(){return r})},function(r){return t.resolve(e()).then(function(){throw r})})},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===u)return this;var r=new this.constructor(i);(process.browser||this.handled===f&&(this.handled=null),this.state!==l)?v(r,this.state===a?e:t,this.outcome):this.queue.push(new p(r,e,t));return r},p.prototype.callFulfilled=function(e){c.resolve(this.promise,e)},p.prototype.otherCallFulfilled=function(e){v(this.promise,this.onFulfilled,e)},p.prototype.callRejected=function(e){c.reject(this.promise,e)},p.prototype.otherCallRejected=function(e){v(this.promise,this.onRejected,e)},c.resolve=function(e,t){var r=y(d,t);if("error"===r.status)return c.reject(e,r.value);var n=r.value;if(n)m(e,n);else{e.state=a,e.outcome=t;for(var o=-1,s=e.queue.length;++o<s;)e.queue[o].callFulfilled(t)}return e},c.reject=function(e,r){e.state=u,e.outcome=r,process.browser||e.handled===f&&t(function(){e.handled===f&&process.emit("unhandledRejection",r,e)});for(var n=-1,o=e.queue.length;++n<o;)e.queue[n].callRejected(r);return e},h.resolve=function(e){if(e instanceof this)return e;return c.resolve(new this(i),e)},h.reject=function(e){var t=new this(i);return c.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 r=e.length,n=!1;if(!r)return this.resolve([]);var o=new Array(r),s=0,u=-1,a=new this(i);for(;++u<r;)l(e[u],u);return a;function l(e,i){t.resolve(e).then(function(e){o[i]=e,++s!==r||n||(n=!0,c.resolve(a,o))},function(e){n||(n=!0,c.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 r=e.length,n=!1;if(!r)return this.resolve([]);var o=-1,s=new this(i);for(;++o<r;)u(e[o]);return s;function u(e){t.resolve(e).then(function(e){n||(n=!0,c.resolve(s,e))},function(e){n||(n=!0,c.reject(s,e))})}},o}var a=function(){if(c)return i;c=1;var e="undefined"!=typeof Promise?Promise:u(),t=0;function r(e,t){var r=t.data;if(Array.isArray(r)&&!(r.length<2)){var n=r[0],o=r[1],s=r[2],i=e._callbacks[n];i&&(delete e._callbacks[n],i(o,s))}}function n(e){var t=this;t._worker=e,t._callbacks={},e.addEventListener("message",function(e){r(t,e)})}return n.prototype.postMessage=function(n,o){var s=this,i=t++,c=[i,n];return new e(function(e,t){if(s._callbacks[i]=function(r,n){if(r)return t(new Error(r.message));e(n)},void 0!==s._worker.controller){var n=new MessageChannel;n.port1.onmessage=function(e){r(s,e)},s._worker.controller.postMessage(c,[n.port2].concat(o))}else s._worker.postMessage(c,o)})},n.prototype.terminate=function(){this._worker.terminate()},i=n}(),l=t(a);const f=e=>new l(e),h=e=>({compress:t=>e.postMessage({type:"compress",payload:t})});export{f as getPromiseWorker,h as getWorkerInterface};
|