scratch-storage 2.3.284 → 3.0.1

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.
Files changed (61) hide show
  1. package/.browserslistrc +7 -0
  2. package/CHANGELOG.md +18 -0
  3. package/dist/{web/f6240eab828e6d415177.worker.js → node/chunks/fetch-worker.3bf90a691c26a60b5752.js} +262 -231
  4. package/dist/node/chunks/fetch-worker.3bf90a691c26a60b5752.js.map +1 -0
  5. package/dist/node/scratch-storage.js +4019 -6348
  6. package/dist/node/scratch-storage.js.map +1 -1
  7. package/dist/types/Asset.d.ts +38 -0
  8. package/dist/types/AssetType.d.ts +49 -0
  9. package/dist/types/BuiltinHelper.d.ts +69 -0
  10. package/dist/types/DataFormat.d.ts +15 -0
  11. package/dist/types/FetchTool.d.ts +33 -0
  12. package/dist/types/FetchWorkerTool.d.ts +29 -0
  13. package/dist/types/Helper.d.ts +20 -0
  14. package/dist/types/ProxyTool.d.ts +53 -0
  15. package/dist/types/ScratchStorage.d.ts +202 -0
  16. package/dist/types/Tool.d.ts +13 -0
  17. package/dist/types/WebHelper.d.ts +59 -0
  18. package/dist/types/index.d.ts +11 -0
  19. package/dist/types/log.d.ts +2 -0
  20. package/dist/types/memoizedToString.d.ts +5 -0
  21. package/dist/web/chunks/fetch-worker.42ee2f0bc3b8de590472.js +2 -0
  22. package/dist/web/chunks/fetch-worker.42ee2f0bc3b8de590472.js.map +1 -0
  23. package/dist/web/chunks/fetch-worker.cd3a909d7b876aabf94a.js +782 -0
  24. package/dist/web/chunks/fetch-worker.cd3a909d7b876aabf94a.js.map +1 -0
  25. package/dist/web/scratch-storage.js +2143 -2798
  26. package/dist/web/scratch-storage.js.map +1 -1
  27. package/dist/web/scratch-storage.min.js +2 -6398
  28. package/dist/web/scratch-storage.min.js.LICENSE.txt +18 -0
  29. package/dist/web/scratch-storage.min.js.map +1 -1
  30. package/jest.config.js +32 -0
  31. package/package.json +19 -14
  32. package/src/.eslintrc.js +13 -1
  33. package/src/Asset.ts +100 -0
  34. package/src/{AssetType.js → AssetType.ts} +10 -5
  35. package/src/{BuiltinHelper.js → BuiltinHelper.ts} +44 -35
  36. package/src/{DataFormat.js → DataFormat.ts} +3 -3
  37. package/src/{FetchTool.js → FetchTool.ts} +8 -9
  38. package/src/{FetchWorkerTool.js → FetchWorkerTool.ts} +47 -22
  39. package/src/{Helper.js → Helper.ts} +10 -5
  40. package/src/{ProxyTool.js → ProxyTool.ts} +32 -29
  41. package/src/{ScratchStorage.js → ScratchStorage.ts} +57 -34
  42. package/src/Tool.ts +10 -0
  43. package/src/{WebHelper.js → WebHelper.ts} +42 -15
  44. package/src/index.ts +19 -0
  45. package/src/log.ts +4 -0
  46. package/src/{Asset.js → memoizedToString.ts} +16 -76
  47. package/src/scratchFetch.js +10 -15
  48. package/src/types.d.ts +3 -0
  49. package/test/integration/download-known-assets.test.js +1 -1
  50. package/test/unit/add-helper.test.js +1 -1
  51. package/test/unit/fetch-tool.test.js +1 -1
  52. package/test/unit/load-default-assets.test.js +1 -1
  53. package/test/unit/metadata.test.js +6 -6
  54. package/tsconfig.json +29 -0
  55. package/tsconfig.test.json +11 -0
  56. package/webpack.config.js +63 -67
  57. package/dist/node/ce8a01e629587e4f90e4.worker.js +0 -4274
  58. package/dist/node/ce8a01e629587e4f90e4.worker.js.map +0 -1
  59. package/dist/web/f6240eab828e6d415177.worker.js.map +0 -1
  60. package/src/index.js +0 -7
  61. package/src/log.js +0 -4
@@ -0,0 +1,782 @@
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if(typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if(typeof define === 'function' && define.amd)
5
+ define([], factory);
6
+ else if(typeof exports === 'object')
7
+ exports["ScratchStorage"] = factory();
8
+ else
9
+ root["ScratchStorage"] = factory();
10
+ })(self, () => {
11
+ return /******/ (() => { // webpackBootstrap
12
+ /******/ var __webpack_modules__ = ({
13
+
14
+ /***/ 945:
15
+ /***/ ((module, exports, __webpack_require__) => {
16
+
17
+ // Save global object in a variable
18
+ var __global__ =
19
+ (typeof globalThis !== 'undefined' && globalThis) ||
20
+ (typeof self !== 'undefined' && self) ||
21
+ (typeof __webpack_require__.g !== 'undefined' && __webpack_require__.g);
22
+ // Create an object that extends from __global__ without the fetch function
23
+ var __globalThis__ = (function () {
24
+ function F() {
25
+ this.fetch = false;
26
+ this.DOMException = __global__.DOMException
27
+ }
28
+ F.prototype = __global__; // Needed for feature detection on whatwg-fetch's code
29
+ return new F();
30
+ })();
31
+ // Wraps whatwg-fetch with a function scope to hijack the global object
32
+ // "globalThis" that's going to be patched
33
+ (function(globalThis) {
34
+
35
+ var irrelevant = (function (exports) {
36
+
37
+ var global =
38
+ (typeof globalThis !== 'undefined' && globalThis) ||
39
+ (typeof self !== 'undefined' && self) ||
40
+ (typeof global !== 'undefined' && global);
41
+
42
+ var support = {
43
+ searchParams: 'URLSearchParams' in global,
44
+ iterable: 'Symbol' in global && 'iterator' in Symbol,
45
+ blob:
46
+ 'FileReader' in global &&
47
+ 'Blob' in global &&
48
+ (function() {
49
+ try {
50
+ new Blob();
51
+ return true
52
+ } catch (e) {
53
+ return false
54
+ }
55
+ })(),
56
+ formData: 'FormData' in global,
57
+ arrayBuffer: 'ArrayBuffer' in global
58
+ };
59
+
60
+ function isDataView(obj) {
61
+ return obj && DataView.prototype.isPrototypeOf(obj)
62
+ }
63
+
64
+ if (support.arrayBuffer) {
65
+ var viewClasses = [
66
+ '[object Int8Array]',
67
+ '[object Uint8Array]',
68
+ '[object Uint8ClampedArray]',
69
+ '[object Int16Array]',
70
+ '[object Uint16Array]',
71
+ '[object Int32Array]',
72
+ '[object Uint32Array]',
73
+ '[object Float32Array]',
74
+ '[object Float64Array]'
75
+ ];
76
+
77
+ var isArrayBufferView =
78
+ ArrayBuffer.isView ||
79
+ function(obj) {
80
+ return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
81
+ };
82
+ }
83
+
84
+ function normalizeName(name) {
85
+ if (typeof name !== 'string') {
86
+ name = String(name);
87
+ }
88
+ if (/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(name) || name === '') {
89
+ throw new TypeError('Invalid character in header field name: "' + name + '"')
90
+ }
91
+ return name.toLowerCase()
92
+ }
93
+
94
+ function normalizeValue(value) {
95
+ if (typeof value !== 'string') {
96
+ value = String(value);
97
+ }
98
+ return value
99
+ }
100
+
101
+ // Build a destructive iterator for the value list
102
+ function iteratorFor(items) {
103
+ var iterator = {
104
+ next: function() {
105
+ var value = items.shift();
106
+ return {done: value === undefined, value: value}
107
+ }
108
+ };
109
+
110
+ if (support.iterable) {
111
+ iterator[Symbol.iterator] = function() {
112
+ return iterator
113
+ };
114
+ }
115
+
116
+ return iterator
117
+ }
118
+
119
+ function Headers(headers) {
120
+ this.map = {};
121
+
122
+ if (headers instanceof Headers) {
123
+ headers.forEach(function(value, name) {
124
+ this.append(name, value);
125
+ }, this);
126
+ } else if (Array.isArray(headers)) {
127
+ headers.forEach(function(header) {
128
+ this.append(header[0], header[1]);
129
+ }, this);
130
+ } else if (headers) {
131
+ Object.getOwnPropertyNames(headers).forEach(function(name) {
132
+ this.append(name, headers[name]);
133
+ }, this);
134
+ }
135
+ }
136
+
137
+ Headers.prototype.append = function(name, value) {
138
+ name = normalizeName(name);
139
+ value = normalizeValue(value);
140
+ var oldValue = this.map[name];
141
+ this.map[name] = oldValue ? oldValue + ', ' + value : value;
142
+ };
143
+
144
+ Headers.prototype['delete'] = function(name) {
145
+ delete this.map[normalizeName(name)];
146
+ };
147
+
148
+ Headers.prototype.get = function(name) {
149
+ name = normalizeName(name);
150
+ return this.has(name) ? this.map[name] : null
151
+ };
152
+
153
+ Headers.prototype.has = function(name) {
154
+ return this.map.hasOwnProperty(normalizeName(name))
155
+ };
156
+
157
+ Headers.prototype.set = function(name, value) {
158
+ this.map[normalizeName(name)] = normalizeValue(value);
159
+ };
160
+
161
+ Headers.prototype.forEach = function(callback, thisArg) {
162
+ for (var name in this.map) {
163
+ if (this.map.hasOwnProperty(name)) {
164
+ callback.call(thisArg, this.map[name], name, this);
165
+ }
166
+ }
167
+ };
168
+
169
+ Headers.prototype.keys = function() {
170
+ var items = [];
171
+ this.forEach(function(value, name) {
172
+ items.push(name);
173
+ });
174
+ return iteratorFor(items)
175
+ };
176
+
177
+ Headers.prototype.values = function() {
178
+ var items = [];
179
+ this.forEach(function(value) {
180
+ items.push(value);
181
+ });
182
+ return iteratorFor(items)
183
+ };
184
+
185
+ Headers.prototype.entries = function() {
186
+ var items = [];
187
+ this.forEach(function(value, name) {
188
+ items.push([name, value]);
189
+ });
190
+ return iteratorFor(items)
191
+ };
192
+
193
+ if (support.iterable) {
194
+ Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
195
+ }
196
+
197
+ function consumed(body) {
198
+ if (body.bodyUsed) {
199
+ return Promise.reject(new TypeError('Already read'))
200
+ }
201
+ body.bodyUsed = true;
202
+ }
203
+
204
+ function fileReaderReady(reader) {
205
+ return new Promise(function(resolve, reject) {
206
+ reader.onload = function() {
207
+ resolve(reader.result);
208
+ };
209
+ reader.onerror = function() {
210
+ reject(reader.error);
211
+ };
212
+ })
213
+ }
214
+
215
+ function readBlobAsArrayBuffer(blob) {
216
+ var reader = new FileReader();
217
+ var promise = fileReaderReady(reader);
218
+ reader.readAsArrayBuffer(blob);
219
+ return promise
220
+ }
221
+
222
+ function readBlobAsText(blob) {
223
+ var reader = new FileReader();
224
+ var promise = fileReaderReady(reader);
225
+ reader.readAsText(blob);
226
+ return promise
227
+ }
228
+
229
+ function readArrayBufferAsText(buf) {
230
+ var view = new Uint8Array(buf);
231
+ var chars = new Array(view.length);
232
+
233
+ for (var i = 0; i < view.length; i++) {
234
+ chars[i] = String.fromCharCode(view[i]);
235
+ }
236
+ return chars.join('')
237
+ }
238
+
239
+ function bufferClone(buf) {
240
+ if (buf.slice) {
241
+ return buf.slice(0)
242
+ } else {
243
+ var view = new Uint8Array(buf.byteLength);
244
+ view.set(new Uint8Array(buf));
245
+ return view.buffer
246
+ }
247
+ }
248
+
249
+ function Body() {
250
+ this.bodyUsed = false;
251
+
252
+ this._initBody = function(body) {
253
+ /*
254
+ fetch-mock wraps the Response object in an ES6 Proxy to
255
+ provide useful test harness features such as flush. However, on
256
+ ES5 browsers without fetch or Proxy support pollyfills must be used;
257
+ the proxy-pollyfill is unable to proxy an attribute unless it exists
258
+ on the object before the Proxy is created. This change ensures
259
+ Response.bodyUsed exists on the instance, while maintaining the
260
+ semantic of setting Request.bodyUsed in the constructor before
261
+ _initBody is called.
262
+ */
263
+ this.bodyUsed = this.bodyUsed;
264
+ this._bodyInit = body;
265
+ if (!body) {
266
+ this._bodyText = '';
267
+ } else if (typeof body === 'string') {
268
+ this._bodyText = body;
269
+ } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
270
+ this._bodyBlob = body;
271
+ } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
272
+ this._bodyFormData = body;
273
+ } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
274
+ this._bodyText = body.toString();
275
+ } else if (support.arrayBuffer && support.blob && isDataView(body)) {
276
+ this._bodyArrayBuffer = bufferClone(body.buffer);
277
+ // IE 10-11 can't handle a DataView body.
278
+ this._bodyInit = new Blob([this._bodyArrayBuffer]);
279
+ } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
280
+ this._bodyArrayBuffer = bufferClone(body);
281
+ } else {
282
+ this._bodyText = body = Object.prototype.toString.call(body);
283
+ }
284
+
285
+ if (!this.headers.get('content-type')) {
286
+ if (typeof body === 'string') {
287
+ this.headers.set('content-type', 'text/plain;charset=UTF-8');
288
+ } else if (this._bodyBlob && this._bodyBlob.type) {
289
+ this.headers.set('content-type', this._bodyBlob.type);
290
+ } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
291
+ this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
292
+ }
293
+ }
294
+ };
295
+
296
+ if (support.blob) {
297
+ this.blob = function() {
298
+ var rejected = consumed(this);
299
+ if (rejected) {
300
+ return rejected
301
+ }
302
+
303
+ if (this._bodyBlob) {
304
+ return Promise.resolve(this._bodyBlob)
305
+ } else if (this._bodyArrayBuffer) {
306
+ return Promise.resolve(new Blob([this._bodyArrayBuffer]))
307
+ } else if (this._bodyFormData) {
308
+ throw new Error('could not read FormData body as blob')
309
+ } else {
310
+ return Promise.resolve(new Blob([this._bodyText]))
311
+ }
312
+ };
313
+
314
+ this.arrayBuffer = function() {
315
+ if (this._bodyArrayBuffer) {
316
+ var isConsumed = consumed(this);
317
+ if (isConsumed) {
318
+ return isConsumed
319
+ }
320
+ if (ArrayBuffer.isView(this._bodyArrayBuffer)) {
321
+ return Promise.resolve(
322
+ this._bodyArrayBuffer.buffer.slice(
323
+ this._bodyArrayBuffer.byteOffset,
324
+ this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength
325
+ )
326
+ )
327
+ } else {
328
+ return Promise.resolve(this._bodyArrayBuffer)
329
+ }
330
+ } else {
331
+ return this.blob().then(readBlobAsArrayBuffer)
332
+ }
333
+ };
334
+ }
335
+
336
+ this.text = function() {
337
+ var rejected = consumed(this);
338
+ if (rejected) {
339
+ return rejected
340
+ }
341
+
342
+ if (this._bodyBlob) {
343
+ return readBlobAsText(this._bodyBlob)
344
+ } else if (this._bodyArrayBuffer) {
345
+ return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))
346
+ } else if (this._bodyFormData) {
347
+ throw new Error('could not read FormData body as text')
348
+ } else {
349
+ return Promise.resolve(this._bodyText)
350
+ }
351
+ };
352
+
353
+ if (support.formData) {
354
+ this.formData = function() {
355
+ return this.text().then(decode)
356
+ };
357
+ }
358
+
359
+ this.json = function() {
360
+ return this.text().then(JSON.parse)
361
+ };
362
+
363
+ return this
364
+ }
365
+
366
+ // HTTP methods whose capitalization should be normalized
367
+ var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'];
368
+
369
+ function normalizeMethod(method) {
370
+ var upcased = method.toUpperCase();
371
+ return methods.indexOf(upcased) > -1 ? upcased : method
372
+ }
373
+
374
+ function Request(input, options) {
375
+ if (!(this instanceof Request)) {
376
+ throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.')
377
+ }
378
+
379
+ options = options || {};
380
+ var body = options.body;
381
+
382
+ if (input instanceof Request) {
383
+ if (input.bodyUsed) {
384
+ throw new TypeError('Already read')
385
+ }
386
+ this.url = input.url;
387
+ this.credentials = input.credentials;
388
+ if (!options.headers) {
389
+ this.headers = new Headers(input.headers);
390
+ }
391
+ this.method = input.method;
392
+ this.mode = input.mode;
393
+ this.signal = input.signal;
394
+ if (!body && input._bodyInit != null) {
395
+ body = input._bodyInit;
396
+ input.bodyUsed = true;
397
+ }
398
+ } else {
399
+ this.url = String(input);
400
+ }
401
+
402
+ this.credentials = options.credentials || this.credentials || 'same-origin';
403
+ if (options.headers || !this.headers) {
404
+ this.headers = new Headers(options.headers);
405
+ }
406
+ this.method = normalizeMethod(options.method || this.method || 'GET');
407
+ this.mode = options.mode || this.mode || null;
408
+ this.signal = options.signal || this.signal;
409
+ this.referrer = null;
410
+
411
+ if ((this.method === 'GET' || this.method === 'HEAD') && body) {
412
+ throw new TypeError('Body not allowed for GET or HEAD requests')
413
+ }
414
+ this._initBody(body);
415
+
416
+ if (this.method === 'GET' || this.method === 'HEAD') {
417
+ if (options.cache === 'no-store' || options.cache === 'no-cache') {
418
+ // Search for a '_' parameter in the query string
419
+ var reParamSearch = /([?&])_=[^&]*/;
420
+ if (reParamSearch.test(this.url)) {
421
+ // If it already exists then set the value with the current time
422
+ this.url = this.url.replace(reParamSearch, '$1_=' + new Date().getTime());
423
+ } else {
424
+ // Otherwise add a new '_' parameter to the end with the current time
425
+ var reQueryString = /\?/;
426
+ this.url += (reQueryString.test(this.url) ? '&' : '?') + '_=' + new Date().getTime();
427
+ }
428
+ }
429
+ }
430
+ }
431
+
432
+ Request.prototype.clone = function() {
433
+ return new Request(this, {body: this._bodyInit})
434
+ };
435
+
436
+ function decode(body) {
437
+ var form = new FormData();
438
+ body
439
+ .trim()
440
+ .split('&')
441
+ .forEach(function(bytes) {
442
+ if (bytes) {
443
+ var split = bytes.split('=');
444
+ var name = split.shift().replace(/\+/g, ' ');
445
+ var value = split.join('=').replace(/\+/g, ' ');
446
+ form.append(decodeURIComponent(name), decodeURIComponent(value));
447
+ }
448
+ });
449
+ return form
450
+ }
451
+
452
+ function parseHeaders(rawHeaders) {
453
+ var headers = new Headers();
454
+ // Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space
455
+ // https://tools.ietf.org/html/rfc7230#section-3.2
456
+ var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' ');
457
+ // Avoiding split via regex to work around a common IE11 bug with the core-js 3.6.0 regex polyfill
458
+ // https://github.com/github/fetch/issues/748
459
+ // https://github.com/zloirock/core-js/issues/751
460
+ preProcessedHeaders
461
+ .split('\r')
462
+ .map(function(header) {
463
+ return header.indexOf('\n') === 0 ? header.substr(1, header.length) : header
464
+ })
465
+ .forEach(function(line) {
466
+ var parts = line.split(':');
467
+ var key = parts.shift().trim();
468
+ if (key) {
469
+ var value = parts.join(':').trim();
470
+ headers.append(key, value);
471
+ }
472
+ });
473
+ return headers
474
+ }
475
+
476
+ Body.call(Request.prototype);
477
+
478
+ function Response(bodyInit, options) {
479
+ if (!(this instanceof Response)) {
480
+ throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.')
481
+ }
482
+ if (!options) {
483
+ options = {};
484
+ }
485
+
486
+ this.type = 'default';
487
+ this.status = options.status === undefined ? 200 : options.status;
488
+ this.ok = this.status >= 200 && this.status < 300;
489
+ this.statusText = options.statusText === undefined ? '' : '' + options.statusText;
490
+ this.headers = new Headers(options.headers);
491
+ this.url = options.url || '';
492
+ this._initBody(bodyInit);
493
+ }
494
+
495
+ Body.call(Response.prototype);
496
+
497
+ Response.prototype.clone = function() {
498
+ return new Response(this._bodyInit, {
499
+ status: this.status,
500
+ statusText: this.statusText,
501
+ headers: new Headers(this.headers),
502
+ url: this.url
503
+ })
504
+ };
505
+
506
+ Response.error = function() {
507
+ var response = new Response(null, {status: 0, statusText: ''});
508
+ response.type = 'error';
509
+ return response
510
+ };
511
+
512
+ var redirectStatuses = [301, 302, 303, 307, 308];
513
+
514
+ Response.redirect = function(url, status) {
515
+ if (redirectStatuses.indexOf(status) === -1) {
516
+ throw new RangeError('Invalid status code')
517
+ }
518
+
519
+ return new Response(null, {status: status, headers: {location: url}})
520
+ };
521
+
522
+ exports.DOMException = global.DOMException;
523
+ try {
524
+ new exports.DOMException();
525
+ } catch (err) {
526
+ exports.DOMException = function(message, name) {
527
+ this.message = message;
528
+ this.name = name;
529
+ var error = Error(message);
530
+ this.stack = error.stack;
531
+ };
532
+ exports.DOMException.prototype = Object.create(Error.prototype);
533
+ exports.DOMException.prototype.constructor = exports.DOMException;
534
+ }
535
+
536
+ function fetch(input, init) {
537
+ return new Promise(function(resolve, reject) {
538
+ var request = new Request(input, init);
539
+
540
+ if (request.signal && request.signal.aborted) {
541
+ return reject(new exports.DOMException('Aborted', 'AbortError'))
542
+ }
543
+
544
+ var xhr = new XMLHttpRequest();
545
+
546
+ function abortXhr() {
547
+ xhr.abort();
548
+ }
549
+
550
+ xhr.onload = function() {
551
+ var options = {
552
+ status: xhr.status,
553
+ statusText: xhr.statusText,
554
+ headers: parseHeaders(xhr.getAllResponseHeaders() || '')
555
+ };
556
+ options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL');
557
+ var body = 'response' in xhr ? xhr.response : xhr.responseText;
558
+ setTimeout(function() {
559
+ resolve(new Response(body, options));
560
+ }, 0);
561
+ };
562
+
563
+ xhr.onerror = function() {
564
+ setTimeout(function() {
565
+ reject(new TypeError('Network request failed'));
566
+ }, 0);
567
+ };
568
+
569
+ xhr.ontimeout = function() {
570
+ setTimeout(function() {
571
+ reject(new TypeError('Network request failed'));
572
+ }, 0);
573
+ };
574
+
575
+ xhr.onabort = function() {
576
+ setTimeout(function() {
577
+ reject(new exports.DOMException('Aborted', 'AbortError'));
578
+ }, 0);
579
+ };
580
+
581
+ function fixUrl(url) {
582
+ try {
583
+ return url === '' && global.location.href ? global.location.href : url
584
+ } catch (e) {
585
+ return url
586
+ }
587
+ }
588
+
589
+ xhr.open(request.method, fixUrl(request.url), true);
590
+
591
+ if (request.credentials === 'include') {
592
+ xhr.withCredentials = true;
593
+ } else if (request.credentials === 'omit') {
594
+ xhr.withCredentials = false;
595
+ }
596
+
597
+ if ('responseType' in xhr) {
598
+ if (support.blob) {
599
+ xhr.responseType = 'blob';
600
+ } else if (
601
+ support.arrayBuffer &&
602
+ request.headers.get('Content-Type') &&
603
+ request.headers.get('Content-Type').indexOf('application/octet-stream') !== -1
604
+ ) {
605
+ xhr.responseType = 'arraybuffer';
606
+ }
607
+ }
608
+
609
+ if (init && typeof init.headers === 'object' && !(init.headers instanceof Headers)) {
610
+ Object.getOwnPropertyNames(init.headers).forEach(function(name) {
611
+ xhr.setRequestHeader(name, normalizeValue(init.headers[name]));
612
+ });
613
+ } else {
614
+ request.headers.forEach(function(value, name) {
615
+ xhr.setRequestHeader(name, value);
616
+ });
617
+ }
618
+
619
+ if (request.signal) {
620
+ request.signal.addEventListener('abort', abortXhr);
621
+
622
+ xhr.onreadystatechange = function() {
623
+ // DONE (success or failure)
624
+ if (xhr.readyState === 4) {
625
+ request.signal.removeEventListener('abort', abortXhr);
626
+ }
627
+ };
628
+ }
629
+
630
+ xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit);
631
+ })
632
+ }
633
+
634
+ fetch.polyfill = true;
635
+
636
+ if (!global.fetch) {
637
+ global.fetch = fetch;
638
+ global.Headers = Headers;
639
+ global.Request = Request;
640
+ global.Response = Response;
641
+ }
642
+
643
+ exports.Headers = Headers;
644
+ exports.Request = Request;
645
+ exports.Response = Response;
646
+ exports.fetch = fetch;
647
+
648
+ return exports;
649
+
650
+ })({});
651
+ })(__globalThis__);
652
+ // This is a ponyfill, so...
653
+ __globalThis__.fetch.ponyfill = true;
654
+ delete __globalThis__.fetch.polyfill;
655
+ // Choose between native implementation (__global__) or custom implementation (__globalThis__)
656
+ var ctx = __global__.fetch ? __global__ : __globalThis__;
657
+ exports = ctx.fetch // To enable: import fetch from 'cross-fetch'
658
+ exports["default"] = ctx.fetch // For TypeScript consumers without esModuleInterop.
659
+ exports.fetch = ctx.fetch // To enable: import {fetch} from 'cross-fetch'
660
+ exports.Headers = ctx.Headers
661
+ exports.Request = ctx.Request
662
+ exports.Response = ctx.Response
663
+ module.exports = exports
664
+
665
+
666
+ /***/ })
667
+
668
+ /******/ });
669
+ /************************************************************************/
670
+ /******/ // The module cache
671
+ /******/ var __webpack_module_cache__ = {};
672
+ /******/
673
+ /******/ // The require function
674
+ /******/ function __webpack_require__(moduleId) {
675
+ /******/ // Check if module is in cache
676
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
677
+ /******/ if (cachedModule !== undefined) {
678
+ /******/ return cachedModule.exports;
679
+ /******/ }
680
+ /******/ // Create a new module (and put it into the cache)
681
+ /******/ var module = __webpack_module_cache__[moduleId] = {
682
+ /******/ // no module.id needed
683
+ /******/ // no module.loaded needed
684
+ /******/ exports: {}
685
+ /******/ };
686
+ /******/
687
+ /******/ // Execute the module function
688
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
689
+ /******/
690
+ /******/ // Return the exports of the module
691
+ /******/ return module.exports;
692
+ /******/ }
693
+ /******/
694
+ /************************************************************************/
695
+ /******/ /* webpack/runtime/global */
696
+ /******/ (() => {
697
+ /******/ __webpack_require__.g = (function() {
698
+ /******/ if (typeof globalThis === 'object') return globalThis;
699
+ /******/ try {
700
+ /******/ return this || new Function('return this')();
701
+ /******/ } catch (e) {
702
+ /******/ if (typeof window === 'object') return window;
703
+ /******/ }
704
+ /******/ })();
705
+ /******/ })();
706
+ /******/
707
+ /************************************************************************/
708
+ var __webpack_exports__ = {};
709
+ /* eslint-env worker */
710
+
711
+ const crossFetch = (__webpack_require__(945)["default"]);
712
+ let jobsActive = 0;
713
+ const complete = [];
714
+ let intervalId = null;
715
+
716
+ /**
717
+ * Register a step function.
718
+ *
719
+ * Step checks if there are completed jobs and if there are sends them to the
720
+ * parent. Then it checks the jobs count. If there are no further jobs, clear
721
+ * the step.
722
+ */
723
+ const registerStep = function registerStep() {
724
+ intervalId = setInterval(() => {
725
+ if (complete.length) {
726
+ // Send our chunk of completed requests and instruct postMessage to
727
+ // transfer the buffers instead of copying them.
728
+ postMessage(complete.slice(),
729
+ // Instruct postMessage that these buffers in the sent message
730
+ // should use their Transferable trait. After the postMessage
731
+ // call the "buffers" will still be in complete if you looked,
732
+ // but they will all be length 0 as the data they reference has
733
+ // been sent to the window. This lets us send a lot of data
734
+ // without the normal postMessage behaviour of making a copy of
735
+ // all of the data for the window.
736
+ complete.map(response => response.buffer).filter(Boolean));
737
+ complete.length = 0;
738
+ }
739
+ if (jobsActive === 0) {
740
+ clearInterval(intervalId);
741
+ intervalId = null;
742
+ }
743
+ }, 1);
744
+ };
745
+
746
+ /**
747
+ * Receive a job from the parent and fetch the requested data.
748
+ * @param {object} options.job A job id, url, and options descriptor to perform.
749
+ */
750
+ const onMessage = _ref => {
751
+ let {
752
+ data: job
753
+ } = _ref;
754
+ if (jobsActive === 0 && !intervalId) {
755
+ registerStep();
756
+ }
757
+ jobsActive++;
758
+ crossFetch(job.url, job.options).then(result => {
759
+ if (result.ok) return result.arrayBuffer();
760
+ if (result.status === 404) return null;
761
+ return Promise.reject(result.status);
762
+ }).then(buffer => complete.push({
763
+ id: job.id,
764
+ buffer
765
+ })).catch(error => complete.push({
766
+ id: job.id,
767
+ error: error && error.message || "Failed request: ".concat(job.url)
768
+ })).then(() => jobsActive--);
769
+ };
770
+
771
+ // crossFetch means "fetch" is now always supported
772
+ postMessage({
773
+ support: {
774
+ fetch: true
775
+ }
776
+ });
777
+ self.addEventListener('message', onMessage);
778
+ /******/ return __webpack_exports__;
779
+ /******/ })()
780
+ ;
781
+ });
782
+ //# sourceMappingURL=fetch-worker.cd3a909d7b876aabf94a.js.map