easy-web-worker 1.1.9 → 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -17
- package/lib/EasyWebWorker.d.ts +21 -3
- package/lib/EasyWebWorkerFixtures.d.ts +1 -1
- package/lib/bundle.js +1 -1
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# easy-web-worker
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This library extends the capabilities of the **Worker** by integrating a pattern of cancelable promises from the library **cancelable-promise-jq**. For simple workers it removes the necessity of having to configure webpack or whatever bundler you are using. But when more complex solutions are needed, the class **StaticEasyWebWorker** allows you to integrate the easy worker and cancelable promises capabilities into your static worker.
|
|
4
4
|
|
|
5
5
|
## Creating a simple Web Worker
|
|
6
6
|
|
|
@@ -15,7 +15,7 @@ const backgroundWorker = new EasyWebWorker<string, string>((easyWorker) => {
|
|
|
15
15
|
});
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const messageResult = await backgroundWorker.send('hello!');
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
### Important notes:
|
|
@@ -25,7 +25,7 @@ EasyWebWorker<IPayload, IResult> has two generic parameters... They will affect
|
|
|
25
25
|
- If IResult is null, the _resolve_ method will not require parameters
|
|
26
26
|
- If IPayload is null, the _send_ method will not require parameters
|
|
27
27
|
|
|
28
|
-
Take into consideration that the _workerBody_ is a template to create a worker in run time, so you'll not be able to use anything outside of the Worker-Scope
|
|
28
|
+
Take into consideration that the _workerBody_ is a template to create a worker in run time, so you'll not be able to use anything outside of the Worker-Scope.
|
|
29
29
|
|
|
30
30
|
```TS
|
|
31
31
|
const message = 'Hello';
|
|
@@ -54,10 +54,18 @@ easyWorker.onMessage((message) => {
|
|
|
54
54
|
// the message could resolve the *send* promise.
|
|
55
55
|
message.resolve();
|
|
56
56
|
|
|
57
|
-
// the message could
|
|
57
|
+
// the message could be rejected from the worker
|
|
58
58
|
message.reject(new Error());
|
|
59
59
|
|
|
60
|
-
//
|
|
60
|
+
// this message could be cancelled from inside the worker
|
|
61
|
+
message.cancel();
|
|
62
|
+
|
|
63
|
+
// the message is also able to listen to cancelation evens
|
|
64
|
+
message.onCancel(() => {
|
|
65
|
+
// release resources
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
// you could also report progress to the principal thread if you configured a onProgress callback
|
|
61
69
|
message.reportProgress(25);
|
|
62
70
|
});
|
|
63
71
|
```
|
|
@@ -118,11 +126,7 @@ This is a very simple example, but you could import a whole library into your wo
|
|
|
118
126
|
|
|
119
127
|
## StaticEasyWebWorker
|
|
120
128
|
|
|
121
|
-
If you want to create a _Worker_ with a static .js file and don't want to lose the structure of messages and promises and the onProgress callback from the library... you could use
|
|
122
|
-
|
|
123
|
-
trust me, talking about performance it's going to be the same. but may if you are trying to create something very complex and huge into a _Worker_... OK, a static js file could be a good option.
|
|
124
|
-
|
|
125
|
-
Workers are gonna work just as the javascript you have in your main thread, but into another thread, so, the user experience could improve!!
|
|
129
|
+
If you want to create a _Worker_ with a static .js file and don't want to lose the structure of messages and promises and the onProgress callback from the library... you could use StaticEasyWebWorker<IPayload = null, IResult = void>\_ directly in your Worker.
|
|
126
130
|
|
|
127
131
|
let's see how to use it:
|
|
128
132
|
|
|
@@ -131,20 +135,18 @@ let's see how to use it:
|
|
|
131
135
|
// onMessage Callback is gonna receive all _send_ method calls.
|
|
132
136
|
|
|
133
137
|
```TS
|
|
134
|
-
|
|
138
|
+
// this is gonna create the same message structure the runtime Workers
|
|
139
|
+
const worker = new StaticEasyWebWorker((message) => {
|
|
135
140
|
setTimeout(() => {
|
|
136
141
|
message.resolve(200);
|
|
137
142
|
}, 5000);
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
// this is gonna create the same message structure the runtime Workers
|
|
141
|
-
new StaticEasyWebWorker<null, number>(onMessageCallback);
|
|
143
|
+
});
|
|
142
144
|
```
|
|
143
145
|
|
|
144
146
|
and in your main thread:
|
|
145
147
|
|
|
146
148
|
```TS
|
|
147
|
-
const worker = new EasyWebWorker<null,number>('
|
|
149
|
+
const worker = new EasyWebWorker<null,number>('./worker.js');
|
|
148
150
|
await worker.send();
|
|
149
151
|
```
|
|
150
152
|
|
|
@@ -223,4 +225,53 @@ the output should be:
|
|
|
223
225
|
|
|
224
226
|
Of course this is a very tiny array, but is just to give you and idea, actually you also could make fetch requests into workers... give it a try.
|
|
225
227
|
|
|
226
|
-
|
|
228
|
+
# Methods
|
|
229
|
+
|
|
230
|
+
### `EasyWebWorker.reboot(reason?: unknown): CancelableCancelablePromise<void>[]`
|
|
231
|
+
|
|
232
|
+
This method will reboot the worker and cancel all the messages in the queue.
|
|
233
|
+
|
|
234
|
+
- `reason` - (optional) reason why the worker will be restarted.
|
|
235
|
+
|
|
236
|
+
Returns an array of promises that are resolved with the rejection reason provided when the messages are canceled.
|
|
237
|
+
|
|
238
|
+
Example usage:
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
const worker = new EasyWebWorker<string, string>((easyWorker) => {
|
|
242
|
+
easyWorker.onMessage(async (message) => {
|
|
243
|
+
message.resolve(`Received message: ${message.payload}`);
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
const messagePromise = worker.send('Hello!');
|
|
248
|
+
|
|
249
|
+
worker.reboot('Worker was restarted');
|
|
250
|
+
|
|
251
|
+
// The message promise will be rejected with the reason 'Worker was restarted'
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### override(payload?, reason?, config?): CancelablePromise
|
|
255
|
+
|
|
256
|
+
Cancel all current messages and send a new one.
|
|
257
|
+
|
|
258
|
+
### cancelAll(reason?: unknown): CancelablePromise<void>[]
|
|
259
|
+
|
|
260
|
+
Cancels all messages that are currently waiting to be processed by the worker.
|
|
261
|
+
|
|
262
|
+
- `reason` - (optional) The reason for the cancellation.
|
|
263
|
+
|
|
264
|
+
Returns an array of promises that are resolved with the rejection reason provided when the messages are canceled.
|
|
265
|
+
|
|
266
|
+
### overrideAfterCurrent(payload?, reason?, config?): CancelablePromise
|
|
267
|
+
|
|
268
|
+
Cancel all the messages but the current execution and add a new message
|
|
269
|
+
|
|
270
|
+
### send(payload?, reason?, config?): CancelablePromise
|
|
271
|
+
|
|
272
|
+
Sends a message to the worker
|
|
273
|
+
|
|
274
|
+
- `payload` - (optional) The message payload.
|
|
275
|
+
- `options` - (optional) Additional send options.
|
|
276
|
+
|
|
277
|
+
**_Thanks for reading, hope this help someone_**
|
package/lib/EasyWebWorker.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference lib="webworker" />
|
|
2
|
+
import { EasyWebWorkerMessage } from './EasyWebWorkerMessage';
|
|
2
3
|
import { CancelablePromise } from 'cancelable-promise-jq';
|
|
3
4
|
/**
|
|
4
5
|
* EasyWorker Config
|
|
@@ -110,6 +111,12 @@ export interface IEasyWorkerInstance<IPayload = null, IResult = void> {
|
|
|
110
111
|
* */
|
|
111
112
|
close(): void;
|
|
112
113
|
}
|
|
114
|
+
type TOverrideConfig = {
|
|
115
|
+
/**
|
|
116
|
+
* If true, the worker reboots and cancel instantly all the messages that are currently in the queue
|
|
117
|
+
*/
|
|
118
|
+
force?: boolean;
|
|
119
|
+
};
|
|
113
120
|
/**
|
|
114
121
|
* This type defined the structure that a WorkerBody should have.
|
|
115
122
|
* @template IPayload - Indicates if your WORKERS messages requires a parameter to be provided, NULL indicates they doesn't
|
|
@@ -220,8 +227,13 @@ export declare class EasyWebWorker<TPayload = null, TResult = void> {
|
|
|
220
227
|
/**
|
|
221
228
|
* Execute the cancel callback of each message in the queue if provided
|
|
222
229
|
* @param {unknown} reason - reason messages where canceled
|
|
230
|
+
* @param {boolean} force - if true, the messages will be cancelled immediately without waiting for the worker to respond
|
|
231
|
+
* This action will reboot the worker
|
|
223
232
|
*/
|
|
224
|
-
cancelAll(reason?: unknown
|
|
233
|
+
cancelAll(reason?: unknown, { force }?: {
|
|
234
|
+
force?: boolean;
|
|
235
|
+
}): any;
|
|
236
|
+
protected addMessageToQueue(message: EasyWebWorkerMessage<TPayload, TResult>): void;
|
|
225
237
|
/**
|
|
226
238
|
* Send a message to the worker queue
|
|
227
239
|
* @param {TPayload} payload - whatever json data you want to send to the worker
|
|
@@ -234,16 +246,22 @@ export declare class EasyWebWorker<TPayload = null, TResult = void> {
|
|
|
234
246
|
* @param {unknown} reason - reason why the worker was terminated
|
|
235
247
|
* @returns {IMessagePromise<TResult>} generated defer that will be resolved when the message completed
|
|
236
248
|
*/
|
|
237
|
-
override: TPayload extends null ? (reason?: unknown) => CancelablePromise<TResult> : (payload: TPayload, reason?: unknown) => CancelablePromise<TResult>;
|
|
249
|
+
override: TPayload extends null ? (reason?: unknown, config?: TOverrideConfig) => CancelablePromise<TResult> : (payload: TPayload, reason?: unknown, config?: TOverrideConfig) => CancelablePromise<TResult>;
|
|
238
250
|
/**
|
|
239
251
|
* This method will alow the current message to be completed and send a new one to the worker queue after it, all the messages after the current one will be canceled
|
|
240
252
|
* @param {TPayload} payload - whatever json data you want to send to the worker should be serializable
|
|
241
253
|
* @param {unknown} reason - reason why the worker was terminated
|
|
242
254
|
* @returns {IMessagePromise<TResult>} generated defer that will be resolved when the message completed
|
|
243
255
|
*/
|
|
244
|
-
overrideAfterCurrent: TPayload extends null ? (reason?: unknown) => CancelablePromise<TResult> : (payload: TPayload, reason?: unknown) => CancelablePromise<TResult>;
|
|
256
|
+
overrideAfterCurrent: TPayload extends null ? (reason?: unknown, TOverrideConfig?: any) => CancelablePromise<TResult> : (payload: TPayload, reason?: unknown, config?: TOverrideConfig) => CancelablePromise<TResult>;
|
|
257
|
+
/**
|
|
258
|
+
* This method will reboot the worker and cancel all the messages in the queue
|
|
259
|
+
* @param {unknown} reason - reason why the worker will be restarted
|
|
260
|
+
*/
|
|
261
|
+
reboot(reason?: unknown): any;
|
|
245
262
|
/**
|
|
246
263
|
* This method will remove the WebWorker and the BlobUrl
|
|
247
264
|
*/
|
|
248
265
|
dispose(): Promise<void>;
|
|
249
266
|
}
|
|
267
|
+
export {};
|
|
@@ -3,4 +3,4 @@ export declare const generatedId: () => string;
|
|
|
3
3
|
* This is the template of the worker, should be and string to avoid compilation issues
|
|
4
4
|
*/
|
|
5
5
|
export declare const getWorkerTemplate: () => string;
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const simpleMinifier: (code: string) => string;
|
package/lib/bundle.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see bundle.js.LICENSE.txt */
|
|
2
|
-
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports["easy-web-worker"]=r():e["easy-web-worker"]=r()}(this,(()=>{return e={30:(e,r,t)=>{"use strict";function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function o(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,o,a,i,c=[],s=!0,l=!1;try{if(a=(t=t.call(e)).next,0===r){if(Object(t)!==t)return;s=!1}else for(;!(s=(n=a.call(t)).done)&&(c.push(n.value),c.length!==r);s=!0);}catch(e){l=!0,o=e}finally{try{if(!s&&null!=t.return&&(i=t.return(),Object(i)!==i))return}finally{if(l)throw o}}return c}}(e,r)||a(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(e,r){if(e){if("string"==typeof e)return i(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?i(e,r):void 0}}function i(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function c(){c=function(){return e};var e={},r=Object.prototype,t=r.hasOwnProperty,o=Object.defineProperty||function(e,r,t){e[r]=t.value},a="function"==typeof Symbol?Symbol:{},i=a.iterator||"@@iterator",s=a.asyncIterator||"@@asyncIterator",l=a.toStringTag||"@@toStringTag";function u(e,r,t){return Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}),e[r]}try{u({},"")}catch(e){u=function(e,r,t){return e[r]=t}}function f(e,r,t,n){var a=r&&r.prototype instanceof y?r:y,i=Object.create(a.prototype),c=new x(n||[]);return o(i,"_invoke",{value:j(e,t,c)}),i}function p(e,r,t){try{return{type:"normal",arg:e.call(r,t)}}catch(e){return{type:"throw",arg:e}}}e.wrap=f;var d={};function y(){}function h(){}function v(){}var m={};u(m,i,(function(){return this}));var b=Object.getPrototypeOf,g=b&&b(b(S([])));g&&g!==r&&t.call(g,i)&&(m=g);var w=v.prototype=y.prototype=Object.create(m);function P(e){["next","throw","return"].forEach((function(r){u(e,r,(function(e){return this._invoke(r,e)}))}))}function k(e,r){function a(o,i,c,s){var l=p(e[o],e,i);if("throw"!==l.type){var u=l.arg,f=u.value;return f&&"object"==n(f)&&t.call(f,"__await")?r.resolve(f.__await).then((function(e){a("next",e,c,s)}),(function(e){a("throw",e,c,s)})):r.resolve(f).then((function(e){u.value=e,c(u)}),(function(e){return a("throw",e,c,s)}))}s(l.arg)}var i;o(this,"_invoke",{value:function(e,t){function n(){return new r((function(r,n){a(e,t,r,n)}))}return i=i?i.then(n,n):n()}})}function j(e,r,t){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return{value:void 0,done:!0}}for(t.method=o,t.arg=a;;){var i=t.delegate;if(i){var c=C(i,t);if(c){if(c===d)continue;return c}}if("next"===t.method)t.sent=t._sent=t.arg;else if("throw"===t.method){if("suspendedStart"===n)throw n="completed",t.arg;t.dispatchException(t.arg)}else"return"===t.method&&t.abrupt("return",t.arg);n="executing";var s=p(e,r,t);if("normal"===s.type){if(n=t.done?"completed":"suspendedYield",s.arg===d)continue;return{value:s.arg,done:t.done}}"throw"===s.type&&(n="completed",t.method="throw",t.arg=s.arg)}}}function C(e,r){var t=r.method,n=e.iterator[t];if(void 0===n)return r.delegate=null,"throw"===t&&e.iterator.return&&(r.method="return",r.arg=void 0,C(e,r),"throw"===r.method)||"return"!==t&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+t+"' method")),d;var o=p(n,e.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,d;var a=o.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,d):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,d)}function O(e){var r={tryLoc:e[0]};1 in e&&(r.catchLoc=e[1]),2 in e&&(r.finallyLoc=e[2],r.afterLoc=e[3]),this.tryEntries.push(r)}function E(e){var r=e.completion||{};r.type="normal",delete r.arg,e.completion=r}function x(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(O,this),this.reset(!0)}function S(e){if(e){var r=e[i];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,o=function r(){for(;++n<e.length;)if(t.call(e,n))return r.value=e[n],r.done=!1,r;return r.value=void 0,r.done=!0,r};return o.next=o}}return{next:M}}function M(){return{value:void 0,done:!0}}return h.prototype=v,o(w,"constructor",{value:v,configurable:!0}),o(v,"constructor",{value:h,configurable:!0}),h.displayName=u(v,l,"GeneratorFunction"),e.isGeneratorFunction=function(e){var r="function"==typeof e&&e.constructor;return!!r&&(r===h||"GeneratorFunction"===(r.displayName||r.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,v):(e.__proto__=v,u(e,l,"GeneratorFunction")),e.prototype=Object.create(w),e},e.awrap=function(e){return{__await:e}},P(k.prototype),u(k.prototype,s,(function(){return this})),e.AsyncIterator=k,e.async=function(r,t,n,o,a){void 0===a&&(a=Promise);var i=new k(f(r,t,n,o),a);return e.isGeneratorFunction(t)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},P(w),u(w,l,"Generator"),u(w,i,(function(){return this})),u(w,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var r=Object(e),t=[];for(var n in r)t.push(n);return t.reverse(),function e(){for(;t.length;){var n=t.pop();if(n in r)return e.value=n,e.done=!1,e}return e.done=!0,e}},e.values=S,x.prototype={constructor:x,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!e)for(var r in this)"t"===r.charAt(0)&&t.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(t,n){return i.type="throw",i.arg=e,r.next=t,n&&(r.method="next",r.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var c=t.call(a,"catchLoc"),s=t.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(e,r){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&t.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=r&&r<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=r,a?(this.method="next",this.next=a.finallyLoc,d):this.complete(i)},complete:function(e,r){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&r&&(this.next=r),d},finish:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.finallyLoc===e)return this.complete(t.completion,t.afterLoc),E(t),d}},catch:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.tryLoc===e){var n=t.completion;if("throw"===n.type){var o=n.arg;E(t)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,t){return this.delegate={iterator:S(e),resultName:r,nextLoc:t},"next"===this.method&&(this.arg=void 0),d}},e}function s(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,(void 0,a=function(e,r){if("object"!==n(e)||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var o=t.call(e,"string");if("object"!==n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(o.key),"symbol"===n(a)?a:String(a)),o)}var a}var l=function(e,r,t,n){return new(t||(t=Promise))((function(o,a){function i(e){try{s(n.next(e))}catch(e){a(e)}}function c(e){try{s(n.throw(e))}catch(e){a(e)}}function s(e){var r;e.done?o(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(i,c)}s((n=n.apply(e,r||[])).next())}))};Object.defineProperty(r,"__esModule",{value:!0}),r.EasyWebWorker=r.createBlobWorker=void 0;var u=t(213),f=t(726),p=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return e.length?'self.importScripts(["'.concat(e.join('","'),'"]);'):""};r.createBlobWorker=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",n=(0,f.getWorkerTemplate)(),o=Array.isArray(e)?e:[e];return(window.URL||window.webkitURL).createObjectURL(new Blob(["".concat(p(r),"\n ").concat(n,"\n ").concat(o.map((function(e){return'\n \n var easyWorker = createEasyWebWorker("'.concat(t,'");\n \n (').concat(e,")(easyWorker, self);")})).join("\n\n"))],{type:"application/javascript"}))};var d=function(){function e(r){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=n.scripts,i=void 0===a?[]:a,s=n.name,p=n.onWorkerError,d=void 0===p?null:p;!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),this.workerBody=r,this.messagesQueue=new Map,this.scripts=[],this.send=function(){for(var e,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];var a=n[0],i=new u.EasyWebWorkerMessage,c=i.messageId,s=i.decoupledPromise,l=s.cancel;s.promise.cancel=function(e){var r;s.cancel=l;var n={messageId:c,cancelation:{reason:e}};return null===(r=t.worker)||void 0===r||r.postMessage(n),s.promise},t.messagesQueue.set(i.messageId,i);var f={messageId:c,execution:{payload:a}};return null===(e=t.worker)||void 0===e||e.postMessage(f),s.promise},this.override=function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];var o=r[0],a=r[1];return l(t,void 0,void 0,c().mark((function e(){return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.cancelAll(a);case 2:return e.abrupt("return",this.send.apply(this,[o]));case 3:case"end":return e.stop()}}),e,this)})))},this.overrideAfterCurrent=function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];var a=r[0],i=r[1];return l(t,void 0,void 0,c().mark((function e(){var r,t,n,s;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.messagesQueue.size){e.next=7;break}return r=o(this.messagesQueue,1),t=r[0],n=o(t,2),s=n[1],this.messagesQueue.delete(s.messageId),e.next=6,this.cancelAll(i);case 6:this.messagesQueue.set(s.messageId,s);case 7:return e.abrupt("return",this.send.apply(this,[a]));case 8:case"end":return e.stop()}}),e,this)})))},this.name=s||(0,f.generatedId)(),this.scripts=i,this.worker=this.initializeWorker(),this.onWorkerError=d}var t,n;return t=e,(n=[{key:"isExternalWorkerFile",get:function(){return"string"==typeof this.workerBody}},{key:"RemoveMessageFromQueue",value:function(e){this.messagesQueue.delete(e)}},{key:"executeMessageCallback",value:function(e){var r,t,n=null!==(r=this.messagesQueue.get(e.data.messageId))&&void 0!==r?r:null;if(n){var o=e.data.progress;if(this.worker){var c=n.decoupledPromise;if(o){var s=o.percentage,l=o.payload;c.reportProgress(s,l)}else{this.RemoveMessageFromQueue(n.messageId);var u=e.data.worker_canceled;if(u){var f=u.reason;c.reject(f)}else{var p=e.data.rejected;if(p){var d=p.reason;c.reject(d)}else{var y=e.data.resolved.payload;c.resolve.apply(c,function(e){if(Array.isArray(e))return i(e)}(t=null!=y?y:[])||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(t)||a(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.")}())}}}}else this.RemoveMessageFromQueue(n.messageId)}}},{key:"getWorkerUrl",value:function(){return this.isExternalWorkerFile?this.workerBody:(0,r.createBlobWorker)(this.workerBody,this.scripts)}},{key:"initializeWorker",value:function(){var e,r=this;this.workerUrl=null!==(e=this.workerUrl)&&void 0!==e?e:this.getWorkerUrl();var t=new Worker(this.workerUrl,{name:this.name});return t.onmessage=function(e){r.executeMessageCallback(e)},t.onerror=function(e){if(!r.onWorkerError)throw e;r.onWorkerError(e)},t}},{key:"cancelAll",value:function(e){var r=Array.from(this.messagesQueue.values()),t=100/r.length,n=r.map((function(r){var n=r.decoupledPromise.promise;return n.cancel(e).catch((function(e){return n.reportProgress(t,e),e}))}));return Promise.all(n)}},{key:"dispose",value:function(){return l(this,void 0,void 0,c().mark((function e(){return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.cancelAll();case 2:URL.revokeObjectURL(this.workerUrl),this.worker=null;case 4:case"end":return e.stop()}}),e,this)})))}}])&&s(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();r.EasyWebWorker=d},726:(e,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.minifyJS=r.getWorkerTemplate=r.generatedId=void 0,r.generatedId=function(){return"".concat((new Date).getTime()).concat(Math.random().toString(36).substr(2,9))},r.getWorkerTemplate=function(){return"/*this-code-was auto-generated*/\nconst createEasyWebWorker = (targetOrigin) => {\n /* Keep track of the messages sent allowing us to cancel them */\n const workerMessages = new Map();\n\n /* This structure allows us to have multiple callbacks for the same worker */\n const workerCallbacks = new Map([\n [\n '',\n () => {\n throw \"you didn't defined a message-callback, please assign a callback by calling IEasyWorkerInstance.onMessage\";\n },\n ],\n ]);\n\n const createMessage = ({ messageId, payload, origin }) => {\n const cancelCallbacks = new Set();\n\n const postMessage = (data) => {\n const { progress } = data;\n\n if (!progress) {\n /* If it's not a progress message means that the message is resolved | rejected | canceled */\n workerMessages.delete(messageId);\n }\n\n self.postMessage({ messageId, ...data }, origin);\n };\n\n const resolve = (...result) => {\n postMessage({ resolved: { payload: result } });\n };\n\n const reject = (reason) => {\n postMessage({ rejected: { reason } });\n };\n\n const cancel = (reason) => {\n const callbacks = [...cancelCallbacks];\n\n callbacks.forEach((callback) => callback(reason));\n\n postMessage({ worker_canceled: { reason } });\n };\n\n const reportProgress = (percentage, payload) => {\n postMessage({ progress: { percentage, payload } });\n };\n\n /* Returns a function that can be used to unsubscribe from the cancelation */\n const onCancel = (callback) => {\n cancelCallbacks.add(callback);\n\n return () => cancelCallbacks.delete(callback);\n };\n\n return {\n payload,\n resolve,\n reject,\n cancel,\n onCancel,\n reportProgress,\n };\n };\n\n const importScripts = (...scripts) => {\n self.importScripts(...scripts);\n };\n\n const onMessage = (...args) => {\n const [param1, param2] = args;\n const hasCustomCallbackKey = typeof param1 === 'string';\n\n if (hasCustomCallbackKey) {\n const callbackKey = param1;\n const callback = param2;\n\n workerCallbacks.set(callbackKey, callback);\n\n return;\n }\n\n const callback = param1;\n workerCallbacks.set('', callback);\n };\n\n const close = () => {\n /* should cancel all the promises of the main thread */\n const messages = [...workerMessages.values()];\n\n messages.forEach((message) => message.reject(new Error('worker closed')));\n\n self.close();\n };\n\n self.onmessage = (event) => {\n const { data, origin } = event;\n const { messageId, cancelation } = data;\n\n if (cancelation) {\n const { reason } = cancelation;\n\n const message = workerMessages.get(messageId);\n\n message.cancel(reason);\n\n return;\n }\n\n const { method, execution } = data;\n const { payload } = execution;\n\n const message = createMessage({\n messageId,\n payload,\n origin: targetOrigin || origin || undefined,\n });\n\n workerMessages.set(messageId, message);\n\n const callback = workerCallbacks.get(method || '');\n\n callback(message, event);\n };\n\n return {\n importScripts,\n onMessage,\n close,\n };\n};"},r.minifyJS=function(e){var r=e.replace(/\/\/.*|\/\*[\s\S]*?\*\//g,"");r=r.replace(/\s+/g," ");for(var t="",n=!1,o="",a=0;a<r.length;a++){var i=r[a],c=r[a+1];'"'!==i||"\\"===r[a-1]?/\s/.test(i)||(";"!==i||"}"!==c?/[\+\-\*\/%=<>!&|^?:]/.test(i)?(t+=o.trimRight()+i,o=""):(o+=i,n||(t+=o,o="")):a++):(n=!n,o+=i)}return t+o.trimRight()}},213:(e,r,t)=>{"use strict";function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function o(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,(void 0,a=function(e,r){if("object"!==n(e)||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var o=t.call(e,"string");if("object"!==n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(o.key),"symbol"===n(a)?a:String(a)),o)}var a}function a(e,r,t){return r&&o(e.prototype,r),t&&o(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}Object.defineProperty(r,"__esModule",{value:!0}),r.EasyWebWorkerMessage=void 0;var i=t(367),c=t(726),s=a((function e(){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),this.messageId=(0,c.generatedId)(),this.decoupledPromise=(0,i.createDecoupledPromise)()}));r.EasyWebWorkerMessage=s},973:(e,r)=>{"use strict";function t(e){return function(e){if(Array.isArray(e))return n(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,r){if(e){if("string"==typeof e)return n(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?n(e,r):void 0}}(e)||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.")}()}function n(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}Object.defineProperty(r,"__esModule",{value:!0}),r.createStaticEasyWebWorker=r.StaticEasyWebWorker=void 0,r.StaticEasyWebWorker=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=new Map,o=new Map([["",function(){throw"you didn't defined a message-callback, please assign a callback by calling IEasyWorkerInstance.onMessage"}]]),a=function(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];var n=r[0],a=r[1];if("string"==typeof n){var i=n,c=a;o.set(i,c)}else{var s=n;o.set("",s)}};self.onmessage=function(e){var a=e.data,i=e.origin,c=a.messageId,s=a.cancelation;if(s){var l=s.reason;n.get(c).cancel(l)}else{var u=e.data,f=u.method,p=function(e){var r=e.messageId,n=e.payload,o=e.origin,a=new Set,i=function(e){self.postMessage(Object.assign({messageId:r},e),o)};return{payload:n,resolve:function(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];i({resolved:{payload:r}})},reject:function(e){i({rejected:{reason:e}})},cancel:function(e){t(a).forEach((function(r){return r(e)})),i({canceled:{reason:e}})},onCancel:function(e){return a.add(e),function(){return a.delete(e)}},reportProgress:function(e,r){i({progress:{percentage:e,payload:r}})}}}({messageId:c,payload:u.execution.payload,origin:r||i||"*"});o.get(f||"")(p,e)}},e&&a(e),this.importScripts=function(){var e;(e=self).importScripts.apply(e,arguments)},this.close=function(){t(n.values()).forEach((function(e){return e.reject(new Error("worker closed"))})),self.close()},this.onMessage=a},r.createStaticEasyWebWorker=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return new r.StaticEasyWebWorker(e,t)}},991:(e,r,t)=>{"use strict";var n=Object.create?function(e,r,t,n){void 0===n&&(n=t);var o=Object.getOwnPropertyDescriptor(r,t);o&&!("get"in o?!r.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,n,o)}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]},o=function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||n(r,e,t)};Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0;var a=t(30);Object.defineProperty(r,"default",{enumerable:!0,get:function(){return a.EasyWebWorker}}),o(t(30),r),o(t(973),r)},367:function(e){var r;r=()=>(()=>{"use strict";var e={399:(e,r)=>{function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}function n(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function o(){return o="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,r,t){var n=function(e,r){for(;!Object.prototype.hasOwnProperty.call(e,r)&&null!==(e=l(e)););return e}(e,r);if(n){var o=Object.getOwnPropertyDescriptor(n,r);return o.get?o.get.call(arguments.length<3?e:t):o.value}},o.apply(this,arguments)}function a(e){var r="function"==typeof Map?new Map:void 0;return a=function(e){if(null===e||(t=e,-1===Function.toString.call(t).indexOf("[native code]")))return e;var t;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(e))return r.get(e);r.set(e,n)}function n(){return i(e,arguments,l(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),s(n,e)},a(e)}function i(e,r,t){return i=c()?Reflect.construct.bind():function(e,r,t){var n=[null];n.push.apply(n,r);var o=new(Function.bind.apply(e,n));return t&&s(o,t.prototype),o},i.apply(null,arguments)}function c(){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(e){return!1}}function s(e,r){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,r){return e.__proto__=r,e},s(e,r)}function l(e){return l=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},l(e)}Object.defineProperty(r,"__esModule",{value:!0}),r.CancelablePromise=void 0;var u=function(e){!function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),r&&s(e,r)}(f,e);var r,a,i,u=(a=f,i=c(),function(){var e,r=l(a);if(i){var o=l(this).constructor;e=Reflect.construct(r,arguments,o)}else e=r.apply(this,arguments);return function(e,r){if(r&&("object"===t(r)||"function"==typeof r))return r;if(void 0!==r)throw new TypeError("Derived constructors may only return object or undefined");return n(e)}(this,e)});function f(e){var r,t,a,i,c;return function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,f),(a=u.call(this,(function(e,r){i=e,c=r}))).status="pending",a.data={},a.cancelCallbacks=[],a.ownCancelCallbacks=[],a.onProgressCallbacks=[],a.subscribeToOwnCancelEvent=function(e){a.ownCancelCallbacks.push(e)},a.cancel=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if("pending"===a.status)return a.status="canceled",a.ownCancelCallbacks.forEach((function(r){return r(e)})),a.cancelCallbacks.forEach((function(r){return r(e)})),a.reject(e),a.cancelCallbacks=[],a.ownCancelCallbacks=[],n(a)},a.onCancel=function(e){return a.cancelCallbacks.push(e),n(a)},a.onProgress=function(e){return a.onProgressCallbacks.push(e),n(a)},a.reportProgress=function(e,r){return a.onProgressCallbacks.forEach((function(t){return t(e,r)})),n(a)},a.createChildPromise=function(){var e,r,t=new f((function(t,n,o){e=t,r=n}));return t.onProgressCallbacks=a.onProgressCallbacks,t.onCancel((function(e){a.cancel(e)})),{promise:t,resolve:e,reject:r}},a.resolve=i,a.reject=c,e((function(e){a.status="resolved",a.resolve(e)}),(function(e){a.status="rejected",a.reject(e)}),{cancel:function(e){return a.cancel(e)},onCancel:function(e){return a.subscribeToOwnCancelEvent(e),n(a)},onProgress:function(e){return a.onProgress(e)},reportProgress:function(e,r){a.reportProgress(e,r)}}),a.then=function(e,t){var i=a.createChildPromise(),c=i.promise,s=i.resolve,u=i.reject;return o((r=n(a),l(f.prototype)),"then",r).call(r,e,t).then(s,u),c},a.catch=function(e){var r=a.createChildPromise(),i=r.promise,c=r.resolve,s=r.reject;return o((t=n(a),l(f.prototype)),"catch",t).call(t,e).then(c,s),i},a}return r=f,Object.defineProperty(r,"prototype",{writable:!1}),r}(a(Promise));r.CancelablePromise=u,u.prototype.constructor=Promise},716:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.toCancelablePromise=r.isPromise=r.groupAsCancelablePromise=r.createDecoupledPromise=void 0;var n=t(399);function o(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}r.createDecoupledPromise=function(){var e,r,t,o=new n.CancelablePromise((function(n,o,a){e=n,r=o,t=a}));return Object.assign(Object.assign({resolve:e,reject:r},t),{promise:o})};var a=function e(r){if(r instanceof n.CancelablePromise)return r;if("function"==typeof r)return e(r());if(!i(r))return new n.CancelablePromise((function(e){return e(r)}));var t,o,a=new n.CancelablePromise((function(e,n,a){t=e,o=n,r.then(t,o)}));return a.onCancel((function(e){o(e)})),a};r.toCancelablePromise=a,r.groupAsCancelablePromise=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e.length)return null;var t,i=r.maxConcurrent,c=void 0===i?8:i,s=r.executeInOrder,l=void 0!==s&&s,u=r.beforeEachCallback,f=void 0===u?null:u,p=r.afterEachCallback,d=void 0===p?null:p,y=r.onQueueEmptyCallback,h=void 0===y?null:y,v=function(e){if(Array.isArray(e))return o(e)}(t=e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(t)||function(e,r){if(e){if("string"==typeof e)return o(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?o(e,r):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.")}(),m=[];return new n.CancelablePromise((function(e,r,t){return function e(){if(v.length){var r=v.splice(0,c).map((function(e){var r="function"==typeof e?e():e;null==f||f();var n=a(r);return t.onCancel((function(){n.cancel()})),n.then((function(e){m.push(e),null==d||d(e)})),l?n.then((function(e){return e})):n}));return Promise.all(r).then((function(){return e()}))}}().then((function(){null==h||h(m),e(m)}))}))};var i=function(e){return Promise.resolve(e)===e};r.isPromise=i},522:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),Object.defineProperty(r,"CancelablePromise",{enumerable:!0,get:function(){return n.CancelablePromise}}),Object.defineProperty(r,"createDecoupledPromise",{enumerable:!0,get:function(){return o.createDecoupledPromise}}),Object.defineProperty(r,"groupAsCancelablePromise",{enumerable:!0,get:function(){return o.groupAsCancelablePromise}}),Object.defineProperty(r,"isPromise",{enumerable:!0,get:function(){return o.isPromise}}),Object.defineProperty(r,"toCancelablePromise",{enumerable:!0,get:function(){return o.toCancelablePromise}});var n=t(399),o=t(716)},335:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),Object.defineProperty(r,"tryCatch",{enumerable:!0,get:function(){return n.tryCatch}}),Object.defineProperty(r,"tryCatchPromise",{enumerable:!0,get:function(){return n.tryCatchPromise}});var n=t(969)},969:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),Object.defineProperty(r,"tryCatch",{enumerable:!0,get:function(){return n.tryCatch}}),Object.defineProperty(r,"tryCatchPromise",{enumerable:!0,get:function(){return n.tryCatchPromise}});var n=t(948)},948:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.tryCatchPromise=r.tryCatch=void 0;var n=t(522);r.tryCatch=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=r.defaultResult,n=void 0===t?null:t,o=r.exceptionHandlingType,a=void 0===o?"error":o;try{return{error:null,result:e()}}catch(e){return"ignore"!==a&&console[a](e),{error:e,result:n}}},r.tryCatchPromise=function(e,r){var t=r||{},o=t.defaultResult,a=void 0===o?null:o,i=t.exceptionHandlingType,c=void 0===i?"error":i,s=t.ignoreCancel,l=void 0===s||s,u=null,f=null,p=function(e){f=e,"ignore"!=c&&("canceled"===u.status&&l||console[c](f))};try{if(e instanceof n.CancelablePromise)return u=e,new Promise((function(e){u.then((function(e){return{error:null,result:e,promise:u}})).catch((function(e){return p(e),{error:e,result:a,promise:u}}))}));var d=e(),y=d instanceof n.CancelablePromise;return u=y?d:(0,n.toCancelablePromise)(d),new Promise((function(e){u.then((function(r){e({error:null,result:r,promise:u})})).catch((function(r){p(r),e({error:r,result:a,promise:u})}))}))}catch(e){return p(e),Promise.resolve({error:f,result:a,promise:u})}}}},r={};function t(n){var o=r[n];if(void 0!==o)return o.exports;var a=r[n]={exports:{}};return e[n](a,a.exports,t),a.exports}var n={};return(()=>{var e=n;Object.defineProperty(e,"__esModule",{value:!0}),Object.defineProperty(e,"CancelablePromise",{enumerable:!0,get:function(){return r.CancelablePromise}}),Object.defineProperty(e,"createDecoupledPromise",{enumerable:!0,get:function(){return r.createDecoupledPromise}}),Object.defineProperty(e,"groupAsCancelablePromise",{enumerable:!0,get:function(){return r.groupAsCancelablePromise}}),Object.defineProperty(e,"isPromise",{enumerable:!0,get:function(){return r.isPromise}}),Object.defineProperty(e,"toCancelablePromise",{enumerable:!0,get:function(){return r.toCancelablePromise}}),Object.defineProperty(e,"tryCatch",{enumerable:!0,get:function(){return o.tryCatch}}),Object.defineProperty(e,"tryCatchPromise",{enumerable:!0,get:function(){return o.tryCatchPromise}});var r=t(522),o=t(335)})(),n})(),e.exports=r()}},r={},function t(n){var o=r[n];if(void 0!==o)return o.exports;var a=r[n]={exports:{}};return e[n].call(a.exports,a,a.exports,t),a.exports}(991);var e,r}));
|
|
2
|
+
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports["easy-web-worker"]=r():e["easy-web-worker"]=r()}(this,(()=>{return e={30:(e,r,t)=>{"use strict";function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function o(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,o,a,i,c=[],s=!0,l=!1;try{if(a=(t=t.call(e)).next,0===r){if(Object(t)!==t)return;s=!1}else for(;!(s=(n=a.call(t)).done)&&(c.push(n.value),c.length!==r);s=!0);}catch(e){l=!0,o=e}finally{try{if(!s&&null!=t.return&&(i=t.return(),Object(i)!==i))return}finally{if(l)throw o}}return c}}(e,r)||a(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(e,r){if(e){if("string"==typeof e)return i(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?i(e,r):void 0}}function i(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function c(){c=function(){return e};var e={},r=Object.prototype,t=r.hasOwnProperty,o=Object.defineProperty||function(e,r,t){e[r]=t.value},a="function"==typeof Symbol?Symbol:{},i=a.iterator||"@@iterator",s=a.asyncIterator||"@@asyncIterator",l=a.toStringTag||"@@toStringTag";function u(e,r,t){return Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}),e[r]}try{u({},"")}catch(e){u=function(e,r,t){return e[r]=t}}function f(e,r,t,n){var a=r&&r.prototype instanceof y?r:y,i=Object.create(a.prototype),c=new x(n||[]);return o(i,"_invoke",{value:j(e,t,c)}),i}function p(e,r,t){try{return{type:"normal",arg:e.call(r,t)}}catch(e){return{type:"throw",arg:e}}}e.wrap=f;var d={};function y(){}function h(){}function v(){}var m={};u(m,i,(function(){return this}));var b=Object.getPrototypeOf,g=b&&b(b(S([])));g&&g!==r&&t.call(g,i)&&(m=g);var w=v.prototype=y.prototype=Object.create(m);function k(e){["next","throw","return"].forEach((function(r){u(e,r,(function(e){return this._invoke(r,e)}))}))}function P(e,r){function a(o,i,c,s){var l=p(e[o],e,i);if("throw"!==l.type){var u=l.arg,f=u.value;return f&&"object"==n(f)&&t.call(f,"__await")?r.resolve(f.__await).then((function(e){a("next",e,c,s)}),(function(e){a("throw",e,c,s)})):r.resolve(f).then((function(e){u.value=e,c(u)}),(function(e){return a("throw",e,c,s)}))}s(l.arg)}var i;o(this,"_invoke",{value:function(e,t){function n(){return new r((function(r,n){a(e,t,r,n)}))}return i=i?i.then(n,n):n()}})}function j(e,r,t){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return{value:void 0,done:!0}}for(t.method=o,t.arg=a;;){var i=t.delegate;if(i){var c=C(i,t);if(c){if(c===d)continue;return c}}if("next"===t.method)t.sent=t._sent=t.arg;else if("throw"===t.method){if("suspendedStart"===n)throw n="completed",t.arg;t.dispatchException(t.arg)}else"return"===t.method&&t.abrupt("return",t.arg);n="executing";var s=p(e,r,t);if("normal"===s.type){if(n=t.done?"completed":"suspendedYield",s.arg===d)continue;return{value:s.arg,done:t.done}}"throw"===s.type&&(n="completed",t.method="throw",t.arg=s.arg)}}}function C(e,r){var t=r.method,n=e.iterator[t];if(void 0===n)return r.delegate=null,"throw"===t&&e.iterator.return&&(r.method="return",r.arg=void 0,C(e,r),"throw"===r.method)||"return"!==t&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+t+"' method")),d;var o=p(n,e.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,d;var a=o.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,d):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,d)}function O(e){var r={tryLoc:e[0]};1 in e&&(r.catchLoc=e[1]),2 in e&&(r.finallyLoc=e[2],r.afterLoc=e[3]),this.tryEntries.push(r)}function E(e){var r=e.completion||{};r.type="normal",delete r.arg,e.completion=r}function x(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(O,this),this.reset(!0)}function S(e){if(e){var r=e[i];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,o=function r(){for(;++n<e.length;)if(t.call(e,n))return r.value=e[n],r.done=!1,r;return r.value=void 0,r.done=!0,r};return o.next=o}}return{next:M}}function M(){return{value:void 0,done:!0}}return h.prototype=v,o(w,"constructor",{value:v,configurable:!0}),o(v,"constructor",{value:h,configurable:!0}),h.displayName=u(v,l,"GeneratorFunction"),e.isGeneratorFunction=function(e){var r="function"==typeof e&&e.constructor;return!!r&&(r===h||"GeneratorFunction"===(r.displayName||r.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,v):(e.__proto__=v,u(e,l,"GeneratorFunction")),e.prototype=Object.create(w),e},e.awrap=function(e){return{__await:e}},k(P.prototype),u(P.prototype,s,(function(){return this})),e.AsyncIterator=P,e.async=function(r,t,n,o,a){void 0===a&&(a=Promise);var i=new P(f(r,t,n,o),a);return e.isGeneratorFunction(t)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},k(w),u(w,l,"Generator"),u(w,i,(function(){return this})),u(w,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var r=Object(e),t=[];for(var n in r)t.push(n);return t.reverse(),function e(){for(;t.length;){var n=t.pop();if(n in r)return e.value=n,e.done=!1,e}return e.done=!0,e}},e.values=S,x.prototype={constructor:x,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!e)for(var r in this)"t"===r.charAt(0)&&t.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(t,n){return i.type="throw",i.arg=e,r.next=t,n&&(r.method="next",r.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var c=t.call(a,"catchLoc"),s=t.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(e,r){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&t.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=r&&r<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=r,a?(this.method="next",this.next=a.finallyLoc,d):this.complete(i)},complete:function(e,r){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&r&&(this.next=r),d},finish:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.finallyLoc===e)return this.complete(t.completion,t.afterLoc),E(t),d}},catch:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.tryLoc===e){var n=t.completion;if("throw"===n.type){var o=n.arg;E(t)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,t){return this.delegate={iterator:S(e),resultName:r,nextLoc:t},"next"===this.method&&(this.arg=void 0),d}},e}function s(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,(void 0,a=function(e,r){if("object"!==n(e)||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var o=t.call(e,"string");if("object"!==n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(o.key),"symbol"===n(a)?a:String(a)),o)}var a}var l=function(e,r,t,n){return new(t||(t=Promise))((function(o,a){function i(e){try{s(n.next(e))}catch(e){a(e)}}function c(e){try{s(n.throw(e))}catch(e){a(e)}}function s(e){var r;e.done?o(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(i,c)}s((n=n.apply(e,r||[])).next())}))};Object.defineProperty(r,"__esModule",{value:!0}),r.EasyWebWorker=r.createBlobWorker=void 0;var u=t(213),f=t(726),p=t(367);r.createBlobWorker=function(e){var r,t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",a="true"==(null===(t=null===(r=window.process)||void 0===r?void 0:r.env)||void 0===t?void 0:t.DEV_MODE),i=(0,f.getWorkerTemplate)(),c=Array.isArray(e)?e:[e],s="".concat(function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];return e.length?'self.importScripts(["'.concat(e.join('","'),'"]);'):""}(n),"\n ").concat(i,"\n ").concat(c.map((function(e){return'\n \n var easyWorker = createEasyWebWorker("'.concat(o,'");\n \n (').concat(e,")(easyWorker, self);")})).join("\n\n"));return s=a?s:(0,f.simpleMinifier)(s),(window.URL||window.webkitURL).createObjectURL(new Blob([s],{type:"application/javascript"}))};var d=function(){function e(r){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=n.scripts,i=void 0===a?[]:a,s=n.name,d=n.onWorkerError,y=void 0===d?null:d;!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),this.workerBody=r,this.messagesQueue=new Map,this.scripts=[],this.send=function(){for(var e,r=arguments.length,n=new Array(r),o=0;o<r;o++)n[o]=arguments[o];var a=n[0],i=new u.EasyWebWorkerMessage,c=i.messageId,s=i.decoupledPromise,l=s.cancel;s.promise.cancel=function(e){var r;s.cancel=l;var n={messageId:c,cancelation:{reason:e}};return t.worker?(null===(r=t.worker)||void 0===r||r.postMessage(n),s.promise):(l(e),(0,p.toCancelablePromise)(Promise.reject(e)))},t.addMessageToQueue(i);var f={messageId:c,execution:{payload:a}};return null===(e=t.worker)||void 0===e||e.postMessage(f),s.promise},this.override=function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];var o=r[0],a=r[1],i=r[2];return l(t,void 0,void 0,c().mark((function e(){return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.cancelAll(a,i);case 2:return e.abrupt("return",this.send.apply(this,[o]));case 3:case"end":return e.stop()}}),e,this)})))},this.overrideAfterCurrent=function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];var a=r[0],i=r[1],s=r[2];return l(t,void 0,void 0,c().mark((function e(){var r,t,n,l;return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.messagesQueue.size){e.next=7;break}return r=o(this.messagesQueue,1),t=r[0],n=o(t,2),l=n[1],this.RemoveMessageFromQueue(l.messageId),e.next=6,this.cancelAll(i,s);case 6:this.addMessageToQueue(l);case 7:return e.abrupt("return",this.send.apply(this,[a]));case 8:case"end":return e.stop()}}),e,this)})))},this.name=s||(0,f.generatedId)(),this.scripts=i,this.worker=this.initializeWorker(),this.onWorkerError=y}var t,n;return t=e,n=[{key:"isExternalWorkerFile",get:function(){return"string"==typeof this.workerBody}},{key:"RemoveMessageFromQueue",value:function(e){this.messagesQueue.delete(e)}},{key:"executeMessageCallback",value:function(e){var r,t,n=null!==(r=this.messagesQueue.get(e.data.messageId))&&void 0!==r?r:null;if(n){var o=e.data.progress;if(this.worker){var c=n.decoupledPromise;if(o){var s=o.percentage,l=o.payload;c.reportProgress(s,l)}else{this.RemoveMessageFromQueue(n.messageId);var u=e.data.worker_canceled;if(u){var f=u.reason;c.reject(f)}else{var p=e.data.rejected;if(p){var d=p.reason;c.reject(d)}else{var y=e.data.resolved.payload;c.resolve.apply(c,function(e){if(Array.isArray(e))return i(e)}(t=null!=y?y:[])||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(t)||a(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.")}())}}}}else this.RemoveMessageFromQueue(n.messageId)}}},{key:"getWorkerUrl",value:function(){return this.isExternalWorkerFile?this.workerBody:(0,r.createBlobWorker)(this.workerBody,this.scripts)}},{key:"initializeWorker",value:function(){var e,r=this;this.workerUrl=null!==(e=this.workerUrl)&&void 0!==e?e:this.getWorkerUrl();var t=new Worker(this.workerUrl,{name:this.name});return t.onmessage=function(e){r.executeMessageCallback(e)},t.onerror=function(e){if(!r.onWorkerError)throw e;r.onWorkerError(e)},t}},{key:"cancelAll",value:function(e){var r=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{}).force,t=void 0!==r&&r,n=Array.from(this.messagesQueue.values()),o=100/n.length;if(t)return this.reboot(e);var a=n.map((function(r){var t=r.decoupledPromise.promise;return t.cancel(e).catch((function(e){return t.reportProgress(o,e),e}))}));return Promise.all(a)}},{key:"addMessageToQueue",value:function(e){this.messagesQueue.set(e.messageId,e)}},{key:"reboot",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Worker was rebooted";this.worker.terminate(),this.worker=null;var r=this.cancelAll(e);return this.worker=this.initializeWorker(),r}},{key:"dispose",value:function(){return l(this,void 0,void 0,c().mark((function e(){return c().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.cancelAll(null);case 2:URL.revokeObjectURL(this.workerUrl),this.worker.terminate(),this.worker=null;case 5:case"end":return e.stop()}}),e,this)})))}}],n&&s(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),e}();r.EasyWebWorker=d},726:(e,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.simpleMinifier=r.getWorkerTemplate=r.generatedId=void 0,r.generatedId=function(){return"".concat((new Date).getTime()).concat(Math.random().toString(36).substr(2,9))},r.getWorkerTemplate=function(){return"/*this-code-was auto-generated*/\n const createEasyWebWorker = (targetOrigin) => {\n /* Keep track of the messages sent allowing us to cancel them */\n const workerMessages = new Map();\n \n /* This structure allows us to have multiple callbacks for the same worker */\n const workerCallbacks = new Map([\n [\n '',\n () => {\n throw \"you didn't defined a message-callback, please assign a callback by calling IEasyWorkerInstance.onMessage\";\n },\n ],\n ]);\n \n const createMessage = ({ messageId, payload, origin }) => {\n const cancelCallbacks = new Set();\n \n const postMessage = (data) => {\n const { progress } = data;\n \n if (!progress) {\n /* If it's not a progress message means that the message is resolved | rejected | canceled */\n workerMessages.delete(messageId);\n }\n \n self.postMessage({ messageId, ...data }, origin);\n };\n \n const resolve = (...result) => {\n postMessage({ resolved: { payload: result } });\n };\n \n const reject = (reason) => {\n postMessage({ rejected: { reason } });\n };\n \n const cancel = (reason) => {\n const callbacks = [...cancelCallbacks];\n \n callbacks.forEach((callback) => callback(reason));\n \n postMessage({ worker_canceled: { reason } });\n };\n \n const reportProgress = (percentage, payload) => {\n postMessage({ progress: { percentage, payload } });\n };\n \n /* Returns a function that can be used to unsubscribe from the cancelation */\n const onCancel = (callback) => {\n cancelCallbacks.add(callback);\n \n return () => cancelCallbacks.delete(callback);\n };\n \n return {\n payload,\n resolve,\n reject,\n cancel,\n onCancel,\n reportProgress,\n };\n };\n \n const importScripts = (...scripts) => {\n self.importScripts(...scripts);\n };\n \n const onMessage = (...args) => {\n const [param1, param2] = args;\n const hasCustomCallbackKey = typeof param1 === 'string';\n \n if (hasCustomCallbackKey) {\n const callbackKey = param1;\n const callback = param2;\n \n workerCallbacks.set(callbackKey, callback);\n \n return;\n }\n \n const callback = param1;\n workerCallbacks.set('', callback);\n };\n \n const close = () => {\n /* should cancel all the promises of the main thread */\n const messages = [...workerMessages.values()];\n \n messages.forEach((message) => message.reject(new Error('worker closed')));\n \n self.close();\n };\n \n self.onmessage = (event) => {\n const { data, origin } = event;\n const { messageId, cancelation } = data;\n \n if (cancelation) {\n const { reason } = cancelation;\n \n const message = workerMessages.get(messageId);\n \n message.cancel(reason);\n \n return;\n }\n \n const { method, execution } = data;\n const { payload } = execution;\n \n const message = createMessage({\n messageId,\n payload,\n origin: targetOrigin || origin || undefined,\n });\n \n workerMessages.set(messageId, message);\n \n const callback = workerCallbacks.get(method || '');\n \n callback(message, event);\n };\n \n return {\n importScripts,\n onMessage,\n close,\n };\n };"},r.simpleMinifier=function(e){for(var r="",t=!1,n=!1,o=0;o<e.length;o++){var a=e.charAt(o);t?"*"===a&&"/"===e.charAt(o+1)&&(t=!1,o++):n?(r+=a,'"'===a&&"\\"!==e.charAt(o-1)&&(n=!1)):"/"!==a||"*"!==e.charAt(o+1)?'"'!==a?"\n"!==a&&"\r"!==a&&(r+=a):(n=!0,r+=a):(t=!0,o++)}return r.replace(/\s+/g," ").trim()}},213:(e,r,t)=>{"use strict";function n(e){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(e)}function o(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,(void 0,a=function(e,r){if("object"!==n(e)||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var o=t.call(e,"string");if("object"!==n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(o.key),"symbol"===n(a)?a:String(a)),o)}var a}function a(e,r,t){return r&&o(e.prototype,r),t&&o(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}Object.defineProperty(r,"__esModule",{value:!0}),r.EasyWebWorkerMessage=void 0;var i=t(367),c=t(726),s=a((function e(){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),this.messageId=(0,c.generatedId)(),this.decoupledPromise=(0,i.createDecoupledPromise)()}));r.EasyWebWorkerMessage=s},973:(e,r)=>{"use strict";function t(e){return function(e){if(Array.isArray(e))return n(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,r){if(e){if("string"==typeof e)return n(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?n(e,r):void 0}}(e)||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.")}()}function n(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}Object.defineProperty(r,"__esModule",{value:!0}),r.createStaticEasyWebWorker=r.StaticEasyWebWorker=void 0,r.StaticEasyWebWorker=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=new Map,o=new Map([["",function(){throw"you didn't defined a message-callback, please assign a callback by calling IEasyWorkerInstance.onMessage"}]]),a=function(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];var n=r[0],a=r[1];if("string"==typeof n){var i=n,c=a;o.set(i,c)}else{var s=n;o.set("",s)}};self.onmessage=function(e){var a=e.data,i=e.origin,c=a.messageId,s=a.cancelation;if(s){var l=s.reason;n.get(c).cancel(l)}else{var u=e.data,f=u.method,p=function(e){var r=e.messageId,n=e.payload,o=e.origin,a=new Set,i=function(e){self.postMessage(Object.assign({messageId:r},e),o)};return{payload:n,resolve:function(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];i({resolved:{payload:r}})},reject:function(e){i({rejected:{reason:e}})},cancel:function(e){t(a).forEach((function(r){return r(e)})),i({canceled:{reason:e}})},onCancel:function(e){return a.add(e),function(){return a.delete(e)}},reportProgress:function(e,r){i({progress:{percentage:e,payload:r}})}}}({messageId:c,payload:u.execution.payload,origin:r||i||"*"});o.get(f||"")(p,e)}},e&&a(e),this.importScripts=function(){var e;(e=self).importScripts.apply(e,arguments)},this.close=function(){t(n.values()).forEach((function(e){return e.reject(new Error("worker closed"))})),self.close()},this.onMessage=a},r.createStaticEasyWebWorker=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return new r.StaticEasyWebWorker(e,t)}},991:(e,r,t)=>{"use strict";var n=Object.create?function(e,r,t,n){void 0===n&&(n=t);var o=Object.getOwnPropertyDescriptor(r,t);o&&!("get"in o?!r.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,n,o)}:function(e,r,t,n){void 0===n&&(n=t),e[n]=r[t]},o=function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||n(r,e,t)};Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0;var a=t(30);Object.defineProperty(r,"default",{enumerable:!0,get:function(){return a.EasyWebWorker}}),o(t(30),r),o(t(973),r)},367:function(e){var r;r=()=>(()=>{"use strict";var e={399:(e,r)=>{function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}function n(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function o(){return o="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,r,t){var n=function(e,r){for(;!Object.prototype.hasOwnProperty.call(e,r)&&null!==(e=l(e)););return e}(e,r);if(n){var o=Object.getOwnPropertyDescriptor(n,r);return o.get?o.get.call(arguments.length<3?e:t):o.value}},o.apply(this,arguments)}function a(e){var r="function"==typeof Map?new Map:void 0;return a=function(e){if(null===e||(t=e,-1===Function.toString.call(t).indexOf("[native code]")))return e;var t;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(e))return r.get(e);r.set(e,n)}function n(){return i(e,arguments,l(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),s(n,e)},a(e)}function i(e,r,t){return i=c()?Reflect.construct.bind():function(e,r,t){var n=[null];n.push.apply(n,r);var o=new(Function.bind.apply(e,n));return t&&s(o,t.prototype),o},i.apply(null,arguments)}function c(){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(e){return!1}}function s(e,r){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,r){return e.__proto__=r,e},s(e,r)}function l(e){return l=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},l(e)}Object.defineProperty(r,"__esModule",{value:!0}),r.CancelablePromise=void 0;var u=function(e){!function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),r&&s(e,r)}(f,e);var r,a,i,u=(a=f,i=c(),function(){var e,r=l(a);if(i){var o=l(this).constructor;e=Reflect.construct(r,arguments,o)}else e=r.apply(this,arguments);return function(e,r){if(r&&("object"===t(r)||"function"==typeof r))return r;if(void 0!==r)throw new TypeError("Derived constructors may only return object or undefined");return n(e)}(this,e)});function f(e){var r,t,a,i,c;return function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,f),(a=u.call(this,(function(e,r){i=e,c=r}))).status="pending",a.data={},a.cancelCallbacks=[],a.ownCancelCallbacks=[],a.onProgressCallbacks=[],a.subscribeToOwnCancelEvent=function(e){a.ownCancelCallbacks.push(e)},a.cancel=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;if("pending"===a.status)return a.status="canceled",a.ownCancelCallbacks.forEach((function(r){return r(e)})),a.cancelCallbacks.forEach((function(r){return r(e)})),a.reject(e),a.cancelCallbacks=[],a.ownCancelCallbacks=[],n(a)},a.onCancel=function(e){return a.cancelCallbacks.push(e),n(a)},a.onProgress=function(e){return a.onProgressCallbacks.push(e),n(a)},a.reportProgress=function(e,r){return a.onProgressCallbacks.forEach((function(t){return t(e,r)})),n(a)},a.createChildPromise=function(){var e,r,t=new f((function(t,n,o){e=t,r=n}));return t.onProgressCallbacks=a.onProgressCallbacks,t.onCancel((function(e){a.cancel(e)})),{promise:t,resolve:e,reject:r}},a.resolve=i,a.reject=c,e((function(e){a.status="resolved",a.resolve(e)}),(function(e){a.status="rejected",a.reject(e)}),{cancel:function(e){return a.cancel(e)},onCancel:function(e){return a.subscribeToOwnCancelEvent(e),n(a)},onProgress:function(e){return a.onProgress(e)},reportProgress:function(e,r){a.reportProgress(e,r)}}),a.then=function(e,t){var i=a.createChildPromise(),c=i.promise,s=i.resolve,u=i.reject;return o((r=n(a),l(f.prototype)),"then",r).call(r,e,t).then(s,u),c},a.catch=function(e){var r=a.createChildPromise(),i=r.promise,c=r.resolve,s=r.reject;return o((t=n(a),l(f.prototype)),"catch",t).call(t,e).then(c,s),i},a}return r=f,Object.defineProperty(r,"prototype",{writable:!1}),r}(a(Promise));r.CancelablePromise=u,u.prototype.constructor=Promise},716:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.toCancelablePromise=r.isPromise=r.groupAsCancelablePromise=r.createDecoupledPromise=void 0;var n=t(399);function o(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}r.createDecoupledPromise=function(){var e,r,t,o=new n.CancelablePromise((function(n,o,a){e=n,r=o,t=a}));return Object.assign(Object.assign({resolve:e,reject:r},t),{promise:o})};var a=function e(r){if(r instanceof n.CancelablePromise)return r;if("function"==typeof r)return e(r());if(!i(r))return new n.CancelablePromise((function(e){return e(r)}));var t,o,a=new n.CancelablePromise((function(e,n,a){t=e,o=n,r.then(t,o)}));return a.onCancel((function(e){o(e)})),a};r.toCancelablePromise=a,r.groupAsCancelablePromise=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e.length)return null;var t,i=r.maxConcurrent,c=void 0===i?8:i,s=r.executeInOrder,l=void 0!==s&&s,u=r.beforeEachCallback,f=void 0===u?null:u,p=r.afterEachCallback,d=void 0===p?null:p,y=r.onQueueEmptyCallback,h=void 0===y?null:y,v=function(e){if(Array.isArray(e))return o(e)}(t=e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(t)||function(e,r){if(e){if("string"==typeof e)return o(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?o(e,r):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.")}(),m=[];return new n.CancelablePromise((function(e,r,t){return function e(){if(v.length){var r=v.splice(0,c).map((function(e){var r="function"==typeof e?e():e;null==f||f();var n=a(r);return t.onCancel((function(){n.cancel()})),n.then((function(e){m.push(e),null==d||d(e)})),l?n.then((function(e){return e})):n}));return Promise.all(r).then((function(){return e()}))}}().then((function(){null==h||h(m),e(m)}))}))};var i=function(e){return Promise.resolve(e)===e};r.isPromise=i},522:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),Object.defineProperty(r,"CancelablePromise",{enumerable:!0,get:function(){return n.CancelablePromise}}),Object.defineProperty(r,"createDecoupledPromise",{enumerable:!0,get:function(){return o.createDecoupledPromise}}),Object.defineProperty(r,"groupAsCancelablePromise",{enumerable:!0,get:function(){return o.groupAsCancelablePromise}}),Object.defineProperty(r,"isPromise",{enumerable:!0,get:function(){return o.isPromise}}),Object.defineProperty(r,"toCancelablePromise",{enumerable:!0,get:function(){return o.toCancelablePromise}});var n=t(399),o=t(716)},335:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),Object.defineProperty(r,"tryCatch",{enumerable:!0,get:function(){return n.tryCatch}}),Object.defineProperty(r,"tryCatchPromise",{enumerable:!0,get:function(){return n.tryCatchPromise}});var n=t(969)},969:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),Object.defineProperty(r,"tryCatch",{enumerable:!0,get:function(){return n.tryCatch}}),Object.defineProperty(r,"tryCatchPromise",{enumerable:!0,get:function(){return n.tryCatchPromise}});var n=t(948)},948:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0}),r.tryCatchPromise=r.tryCatch=void 0;var n=t(522);r.tryCatch=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=r.defaultResult,n=void 0===t?null:t,o=r.exceptionHandlingType,a=void 0===o?"error":o;try{return{error:null,result:e()}}catch(e){return"ignore"!==a&&console[a](e),{error:e,result:n}}},r.tryCatchPromise=function(e,r){var t=r||{},o=t.defaultResult,a=void 0===o?null:o,i=t.exceptionHandlingType,c=void 0===i?"error":i,s=t.ignoreCancel,l=void 0===s||s,u=null,f=null,p=function(e){f=e,"ignore"!=c&&("canceled"===u.status&&l||console[c](f))};try{if(e instanceof n.CancelablePromise)return u=e,new Promise((function(e){u.then((function(e){return{error:null,result:e,promise:u}})).catch((function(e){return p(e),{error:e,result:a,promise:u}}))}));var d=e(),y=d instanceof n.CancelablePromise;return u=y?d:(0,n.toCancelablePromise)(d),new Promise((function(e){u.then((function(r){e({error:null,result:r,promise:u})})).catch((function(r){p(r),e({error:r,result:a,promise:u})}))}))}catch(e){return p(e),Promise.resolve({error:f,result:a,promise:u})}}}},r={};function t(n){var o=r[n];if(void 0!==o)return o.exports;var a=r[n]={exports:{}};return e[n](a,a.exports,t),a.exports}var n={};return(()=>{var e=n;Object.defineProperty(e,"__esModule",{value:!0}),Object.defineProperty(e,"CancelablePromise",{enumerable:!0,get:function(){return r.CancelablePromise}}),Object.defineProperty(e,"createDecoupledPromise",{enumerable:!0,get:function(){return r.createDecoupledPromise}}),Object.defineProperty(e,"groupAsCancelablePromise",{enumerable:!0,get:function(){return r.groupAsCancelablePromise}}),Object.defineProperty(e,"isPromise",{enumerable:!0,get:function(){return r.isPromise}}),Object.defineProperty(e,"toCancelablePromise",{enumerable:!0,get:function(){return r.toCancelablePromise}}),Object.defineProperty(e,"tryCatch",{enumerable:!0,get:function(){return o.tryCatch}}),Object.defineProperty(e,"tryCatchPromise",{enumerable:!0,get:function(){return o.tryCatchPromise}});var r=t(522),o=t(335)})(),n})(),e.exports=r()}},r={},function t(n){var o=r[n];if(void 0!==o)return o.exports;var a=r[n]={exports:{}};return e[n].call(a.exports,a,a.exports,t),a.exports}(991);var e,r}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easy-web-worker",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.11",
|
|
4
4
|
"description": "This is a library to easily handle and create web-workers, if you are a web developer and never tried this... do not wait any longer! Workers are an amazing option to improve user experience and make your webpages even greater",
|
|
5
5
|
"main": "lib/bundle.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -61,5 +61,8 @@
|
|
|
61
61
|
"cancelable-promise-jq": {
|
|
62
62
|
"optional": false
|
|
63
63
|
}
|
|
64
|
+
},
|
|
65
|
+
"easy-web-worker": {
|
|
66
|
+
"DEV_MODE": true
|
|
64
67
|
}
|
|
65
68
|
}
|