es-module-shims 2.2.0 → 2.3.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.
@@ -1,10 +1,184 @@
1
- /* ES Module Shims 2.2.0 */
2
- (function () {
1
+ /** ES Module Shims 2.3.1 */
2
+ (function (exports) {
3
3
 
4
+ let invalidate;
5
+ const hotReload$1 = url => invalidate(new URL(url, baseUrl).href);
6
+ const initHotReload = () => {
7
+ let _importHook = importHook,
8
+ _resolveHook = resolveHook,
9
+ _metaHook = metaHook;
10
+
11
+ let defaultResolve;
12
+ let hotResolveHook = (id, parent, _defaultResolve) => {
13
+ if (!defaultResolve) defaultResolve = _defaultResolve;
14
+ const originalParent = stripVersion(parent);
15
+ const url = stripVersion(defaultResolve(id, originalParent));
16
+ const parents = getHotState(url).p;
17
+ if (!parents.includes(originalParent)) parents.push(originalParent);
18
+ return toVersioned(url);
19
+ };
20
+ const hotImportHook = (url, _, __, source, sourceType) => {
21
+ const hotState = getHotState(url);
22
+ hotState.e = typeof source === 'string' ? source : true;
23
+ hotState.t = sourceType;
24
+ };
25
+ const hotMetaHook = (metaObj, url) => {
26
+ metaObj.hot = new Hot(url);
27
+ };
28
+
29
+ const Hot = class Hot {
30
+ constructor(url) {
31
+ this.data = getHotState((this.url = stripVersion(url))).d;
32
+ }
33
+ accept(deps, cb) {
34
+ if (typeof deps === 'function') {
35
+ cb = deps;
36
+ deps = null;
37
+ }
38
+ const hotState = getHotState(this.url);
39
+ if (!hotState.A) return;
40
+ (hotState.a = hotState.a || []).push([
41
+ typeof deps === 'string' ? defaultResolve(deps, this.url)
42
+ : deps ? deps.map(d => defaultResolve(d, this.url))
43
+ : null,
44
+ cb
45
+ ]);
46
+ }
47
+ dispose(cb) {
48
+ getHotState(this.url).u = cb;
49
+ }
50
+ invalidate() {
51
+ const hotState = getHotState(this.url);
52
+ hotState.a = null;
53
+ hotState.A = true;
54
+ const seen = [this.url];
55
+ for (const p of hotState.p) invalidate(p, this.url, seen);
56
+ }
57
+ };
58
+
59
+ const versionedRegEx = /\?v=\d+$/;
60
+ const stripVersion = url => {
61
+ const versionMatch = url.match(versionedRegEx);
62
+ return versionMatch ? url.slice(0, -versionMatch[0].length) : url;
63
+ };
64
+
65
+ const toVersioned = url => {
66
+ const v = getHotState(url).v;
67
+ return url + (v ? '?v=' + v : '');
68
+ };
69
+
70
+ let hotRegistry = {},
71
+ curInvalidationRoots = new Set(),
72
+ curInvalidationInterval;
73
+ const getHotState = url =>
74
+ hotRegistry[url] ||
75
+ (hotRegistry[url] = {
76
+ // version
77
+ v: 0,
78
+ // accept list ([deps, cb] pairs)
79
+ a: null,
80
+ // accepting acceptors
81
+ A: true,
82
+ // unload callback
83
+ u: null,
84
+ // entry point or inline script source
85
+ e: false,
86
+ // hot data
87
+ d: {},
88
+ // parents
89
+ p: [],
90
+ // source type
91
+ t: undefined
92
+ });
93
+
94
+ invalidate = (url, fromUrl, seen = []) => {
95
+ if (!seen.includes(url)) {
96
+ seen.push(url);
97
+ console.info(`es-module-shims: hot reload ${url}`);
98
+ const hotState = hotRegistry[url];
99
+ if (hotState) {
100
+ hotState.A = false;
101
+ if (
102
+ hotState.a &&
103
+ hotState.a.some(([d]) => d && (typeof d === 'string' ? d === fromUrl : d.includes(fromUrl)))
104
+ ) {
105
+ curInvalidationRoots.add(fromUrl);
106
+ } else {
107
+ if (hotState.e || hotState.a) curInvalidationRoots.add(url);
108
+ hotState.v++;
109
+ if (!hotState.a) for (const parent of hotState.p) invalidate(parent, url, seen);
110
+ }
111
+ }
112
+ }
113
+ if (!curInvalidationInterval)
114
+ curInvalidationInterval = setTimeout(() => {
115
+ curInvalidationInterval = null;
116
+ const earlyRoots = new Set();
117
+ for (const root of curInvalidationRoots) {
118
+ const hotState = hotRegistry[root];
119
+ topLevelLoad(
120
+ toVersioned(root),
121
+ baseUrl,
122
+ defaultFetchOpts,
123
+ typeof hotState.e === 'string' ? hotState.e : undefined,
124
+ false,
125
+ undefined,
126
+ hotState.t
127
+ ).then(m => {
128
+ if (hotState.a) {
129
+ hotState.a.every(([d, c]) => d === null && !earlyRoots.has(c) && c(m));
130
+ // unload should be the latest unload handler from the just loaded module
131
+ if (hotState.u) {
132
+ hotState.u(hotState.d);
133
+ hotState.u = null;
134
+ }
135
+ }
136
+ for (const parent of hotState.p) {
137
+ const hotState = hotRegistry[parent];
138
+ if (hotState && hotState.a)
139
+ hotState.a.every(async ([d, c]) => {
140
+ return (
141
+ d &&
142
+ !earlyRoots.has(c) &&
143
+ (typeof d === 'string' ?
144
+ d === root && c(m)
145
+ : c(await Promise.all(d.map(d => (earlyRoots.push(c), importShim(toVersioned(d)))))))
146
+ );
147
+ });
148
+ }
149
+ }, throwError);
150
+ }
151
+ curInvalidationRoots = new Set();
152
+ }, hotReloadInterval);
153
+ };
154
+
155
+ return [
156
+ _importHook ? chain(_importHook, hotImportHook) : hotImportHook,
157
+ _resolveHook ?
158
+ (id, parent, defaultResolve) =>
159
+ hotResolveHook(id, parent, (id, parent) => _resolveHook(id, parent, defaultResolve))
160
+ : hotResolveHook,
161
+ _metaHook ? chain(_metaHook, hotMetaHook) : hotMetaHook
162
+ ];
163
+ };
164
+
165
+ if (self.importShim) {
166
+ console.info(
167
+ `es-module-shims: skipping initialization as importShim was already registered by another polyfill instance`
168
+ );
169
+ return;
170
+ }
171
+
4
172
  const hasDocument = typeof document !== 'undefined';
5
173
 
6
174
  const noop = () => {};
7
175
 
176
+ const chain = (a, b) =>
177
+ function () {
178
+ a.apply(this, arguments);
179
+ b.apply(this, arguments);
180
+ };
181
+
8
182
  const dynamicImport = (u, errUrl) => import(u);
9
183
 
10
184
  const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
@@ -14,22 +188,39 @@
14
188
 
15
189
  // shim mode is determined on initialization, no late shim mode
16
190
  const shimMode =
17
- hasDocument ?
18
- esmsInitOptions.shimMode ||
19
- document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
20
- .length > 0
21
- : true;
22
-
23
- const importHook = globalHook(shimMode && esmsInitOptions.onimport);
24
- const resolveHook = globalHook(shimMode && esmsInitOptions.resolve);
25
- let fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
26
- const metaHook = esmsInitOptions.meta ? globalHook(shimMode && esmsInitOptions.meta) : noop;
27
- const tsTransform =
28
- esmsInitOptions.tsTransform ||
191
+ esmsInitOptions.shimMode ||
29
192
  (hasDocument &&
30
- document.currentScript &&
31
- document.currentScript.src.replace(/\.debug\.js$/ , '-typescript.js')) ||
32
- './es-module-shims-typescript.js';
193
+ document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
194
+ .length > 0);
195
+
196
+ let importHook,
197
+ resolveHook,
198
+ fetchHook = fetch,
199
+ metaHook,
200
+ tsTransform =
201
+ esmsInitOptions.tsTransform ||
202
+ (hasDocument && document.currentScript && document.currentScript.src.replace(/(\.\w+)?\.js$/, '-typescript.js')) ||
203
+ './es-module-shims-typescript.js';
204
+
205
+ const defaultFetchOpts = { credentials: 'same-origin' };
206
+
207
+ const {
208
+ revokeBlobURLs,
209
+ noLoadEventRetriggers,
210
+ enforceIntegrity,
211
+ hotReload,
212
+ hotReloadInterval = 100,
213
+ nativePassthrough = !hotReload
214
+ } = esmsInitOptions;
215
+
216
+ const globalHook = name => (typeof name === 'string' ? self[name] : name);
217
+
218
+ if (esmsInitOptions.onimport) importHook = globalHook(esmsInitOptions.onimport);
219
+ if (esmsInitOptions.resolve) resolveHook = globalHook(esmsInitOptions.resolve);
220
+ if (esmsInitOptions.fetch) fetchHook = globalHook(esmsInitOptions.fetch);
221
+ if (esmsInitOptions.meta) metaHook = globalHook(esmsInitOptions.meta);
222
+
223
+ if (hotReload) [importHook, resolveHook, metaHook] = initHotReload();
33
224
 
34
225
  const mapOverrides = esmsInitOptions.mapOverrides;
35
226
 
@@ -39,13 +230,7 @@
39
230
  if (nonceElement) nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
40
231
  }
41
232
 
42
- const onerror = globalHook(esmsInitOptions.onerror || noop);
43
-
44
- const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
45
-
46
- function globalHook(name) {
47
- return typeof name === 'string' ? self[name] : name;
48
- }
233
+ const onerror = globalHook(esmsInitOptions.onerror || console.error.bind(console));
49
234
 
50
235
  const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
51
236
  const enableAll = esmsInitOptions.polyfillEnable === 'all' || enable.includes('all');
@@ -89,23 +274,20 @@
89
274
  (self.reportError || dispatchError)(err), void onerror(err);
90
275
  };
91
276
 
92
- function fromParent(parent) {
93
- return parent ? ` imported from ${parent}` : '';
94
- }
277
+ const fromParent = parent => (parent ? ` imported from ${parent}` : '');
95
278
 
96
279
  const backslashRegEx = /\\/g;
97
280
 
98
- function asURL(url) {
281
+ const asURL = url => {
99
282
  try {
100
283
  if (url.indexOf(':') !== -1) return new URL(url).href;
101
284
  } catch (_) {}
102
- }
285
+ };
103
286
 
104
- function resolveUrl(relUrl, parentUrl) {
105
- return resolveIfNotPlainOrUrl(relUrl, parentUrl) || asURL(relUrl) || resolveIfNotPlainOrUrl('./' + relUrl, parentUrl);
106
- }
287
+ const resolveUrl = (relUrl, parentUrl) =>
288
+ resolveIfNotPlainOrUrl(relUrl, parentUrl) || asURL(relUrl) || resolveIfNotPlainOrUrl('./' + relUrl, parentUrl);
107
289
 
108
- function resolveIfNotPlainOrUrl(relUrl, parentUrl) {
290
+ const resolveIfNotPlainOrUrl = (relUrl, parentUrl) => {
109
291
  const hIdx = parentUrl.indexOf('#'),
110
292
  qIdx = parentUrl.indexOf('?');
111
293
  if (hIdx + qIdx > -2)
@@ -193,9 +375,9 @@
193
375
  if (segmentIndex !== -1) output.push(segmented.slice(segmentIndex));
194
376
  return parentUrl.slice(0, parentUrl.length - pathname.length) + output.join('');
195
377
  }
196
- }
378
+ };
197
379
 
198
- function resolveAndComposeImportMap(json, baseUrl, parentMap) {
380
+ const resolveAndComposeImportMap = (json, baseUrl, parentMap) => {
199
381
  const outMap = {
200
382
  imports: Object.assign({}, parentMap.imports),
201
383
  scopes: Object.assign({}, parentMap.scopes),
@@ -218,27 +400,27 @@
218
400
  if (json.integrity) resolveAndComposeIntegrity(json.integrity, outMap.integrity, baseUrl);
219
401
 
220
402
  return outMap;
221
- }
403
+ };
222
404
 
223
- function getMatch(path, matchObj) {
405
+ const getMatch = (path, matchObj) => {
224
406
  if (matchObj[path]) return path;
225
407
  let sepIndex = path.length;
226
408
  do {
227
409
  const segment = path.slice(0, sepIndex + 1);
228
410
  if (segment in matchObj) return segment;
229
411
  } while ((sepIndex = path.lastIndexOf('/', sepIndex - 1)) !== -1);
230
- }
412
+ };
231
413
 
232
- function applyPackages(id, packages) {
414
+ const applyPackages = (id, packages) => {
233
415
  const pkgName = getMatch(id, packages);
234
416
  if (pkgName) {
235
417
  const pkg = packages[pkgName];
236
418
  if (pkg === null) return;
237
419
  return pkg + id.slice(pkgName.length);
238
420
  }
239
- }
421
+ };
240
422
 
241
- function resolveImportMap(importMap, resolvedOrPlain, parentUrl) {
423
+ const resolveImportMap = (importMap, resolvedOrPlain, parentUrl) => {
242
424
  let scopeUrl = parentUrl && getMatch(parentUrl, importMap.scopes);
243
425
  while (scopeUrl) {
244
426
  const packageResolution = applyPackages(resolvedOrPlain, importMap.scopes[scopeUrl]);
@@ -246,9 +428,9 @@
246
428
  scopeUrl = getMatch(scopeUrl.slice(0, scopeUrl.lastIndexOf('/')), importMap.scopes);
247
429
  }
248
430
  return applyPackages(resolvedOrPlain, importMap.imports) || (resolvedOrPlain.indexOf(':') !== -1 && resolvedOrPlain);
249
- }
431
+ };
250
432
 
251
- function resolveAndComposePackages(packages, outPackages, baseUrl, parentMap) {
433
+ const resolveAndComposePackages = (packages, outPackages, baseUrl, parentMap) => {
252
434
  for (let p in packages) {
253
435
  const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
254
436
  if (
@@ -270,9 +452,9 @@
270
452
  }
271
453
  console.warn(`es-module-shims: Mapping "${p}" -> "${packages[p]}" does not resolve`);
272
454
  }
273
- }
455
+ };
274
456
 
275
- function resolveAndComposeIntegrity(integrity, outIntegrity, baseUrl) {
457
+ const resolveAndComposeIntegrity = (integrity, outIntegrity, baseUrl) => {
276
458
  for (let p in integrity) {
277
459
  const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
278
460
  if (
@@ -286,128 +468,128 @@
286
468
  }
287
469
  outIntegrity[resolvedLhs] = integrity[p];
288
470
  }
289
- }
471
+ };
290
472
 
291
- // support browsers without dynamic import support (eg Firefox 6x)
292
- let supportsJsonType = false;
293
- let supportsCssType = false;
294
-
295
- const supports = hasDocument && HTMLScriptElement.supports;
296
-
297
- let supportsImportMaps = supports && supports.name === 'supports' && supports('importmap');
298
- let supportsWasmInstancePhase = false;
299
- let supportsWasmSourcePhase = false;
300
- let supportsMultipleImportMaps = false;
301
-
302
- const wasmBytes = [0, 97, 115, 109, 1, 0, 0, 0];
303
-
304
- let featureDetectionPromise = (async function () {
305
- if (!hasDocument)
306
- return Promise.all([
307
- import(createBlob(`import"${createBlob('{}', 'text/json')}"with{type:"json"}`)).then(
308
- () => (
309
- (supportsJsonType = true),
310
- import(createBlob(`import"${createBlob('', 'text/css')}"with{type:"css"}`)).then(
311
- () => (supportsCssType = true),
312
- noop
313
- )
314
- ),
315
- noop
316
- ),
317
- wasmInstancePhaseEnabled &&
318
- import(createBlob(`import"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
319
- () => (supportsWasmInstancePhase = true),
320
- noop
321
- ),
322
- wasmSourcePhaseEnabled &&
323
- import(createBlob(`import source x from"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
324
- () => (supportsWasmSourcePhase = true),
325
- noop
326
- )
327
- ]);
328
-
329
- return new Promise(resolve => {
330
- const iframe = document.createElement('iframe');
331
- iframe.style.display = 'none';
332
- iframe.setAttribute('nonce', nonce);
333
- function cb({ data }) {
334
- const isFeatureDetectionMessage = Array.isArray(data) && data[0] === 'esms';
335
- if (!isFeatureDetectionMessage) return;
336
- [
337
- ,
338
- supportsImportMaps,
339
- supportsMultipleImportMaps,
340
- supportsJsonType,
341
- supportsCssType,
342
- supportsWasmSourcePhase,
343
- supportsWasmInstancePhase
344
- ] = data;
345
- resolve();
346
- document.head.removeChild(iframe);
347
- window.removeEventListener('message', cb, false);
348
- }
349
- window.addEventListener('message', cb, false);
350
-
351
- // Feature checking with careful avoidance of unnecessary work - all gated on initial import map supports check. CSS gates on JSON feature check, Wasm instance phase gates on wasm source phase check.
352
- const importMapTest = `<script nonce=${nonce || ''}>b=(s,type='text/javascript')=>URL.createObjectURL(new Blob([s],{type}));c=u=>import(u).then(()=>true,()=>false);i=innerText=>document.head.appendChild(Object.assign(document.createElement('script'),{type:'importmap',nonce:"${nonce}",innerText}));i(\`{"imports":{"x":"\${b('')}"}}\`);i(\`{"imports":{"y":"\${b('')}"}}\`);cm=${
353
- supportsImportMaps ? `c(b(\`import"\${b('{}','text/json')}"with{type:"json"}\`))` : 'false'
354
- };sp=${
355
- supportsImportMaps && wasmSourcePhaseEnabled ?
356
- `c(b(\`import source x from "\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))`
357
- : 'false'
358
- };Promise.all([${supportsImportMaps ? 'true' : "c('x')"},${supportsImportMaps ? "c('y')" : false},cm,${
359
- supportsImportMaps ? `cm.then(s=>s?c(b(\`import"\${b('','text/css')\}"with{type:"css"}\`)):false)` : 'false'
360
- },sp,${
361
- supportsImportMaps && wasmInstancePhaseEnabled ?
362
- `${wasmSourcePhaseEnabled ? 'sp.then(s=>s?' : ''}c(b(\`import"\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))${wasmSourcePhaseEnabled ? ':false)' : ''}`
363
- : 'false'
364
- }]).then(a=>parent.postMessage(['esms'].concat(a),'*'))<${''}/script>`;
365
-
366
- // Safari will call onload eagerly on head injection, but we don't want the Wechat
367
- // path to trigger before setting srcdoc, therefore we track the timing
368
- let readyForOnload = false,
369
- onloadCalledWhileNotReady = false;
370
- function doOnload() {
371
- if (!readyForOnload) {
372
- onloadCalledWhileNotReady = true;
373
- return;
374
- }
375
- // WeChat browser doesn't support setting srcdoc scripts
376
- // But iframe sandboxes don't support contentDocument so we do this as a fallback
377
- const doc = iframe.contentDocument;
378
- if (doc && doc.head.childNodes.length === 0) {
379
- const s = doc.createElement('script');
380
- if (nonce) s.setAttribute('nonce', nonce);
381
- s.innerHTML = importMapTest.slice(15 + (nonce ? nonce.length : 0), -9);
382
- doc.head.appendChild(s);
383
- }
384
- }
385
-
386
- iframe.onload = doOnload;
387
- // WeChat browser requires append before setting srcdoc
388
- document.head.appendChild(iframe);
389
-
390
- // setting srcdoc is not supported in React native webviews on iOS
391
- // setting src to a blob URL results in a navigation event in webviews
392
- // document.write gives usability warnings
393
- readyForOnload = true;
394
- if ('srcdoc' in iframe) iframe.srcdoc = importMapTest;
395
- else iframe.contentDocument.write(importMapTest);
396
- // retrigger onload for Safari only if necessary
397
- if (onloadCalledWhileNotReady) doOnload();
398
- });
399
- })();
400
-
401
- featureDetectionPromise = featureDetectionPromise.then(() => {
402
- console.info(
403
- `es-module-shims: detected native support - module types: (${[...(supportsJsonType ? ['json'] : []), ...(supportsCssType ? ['css'] : []), ...(supportsWasmInstancePhase ? ['wasm'] : [])].join(', ')}), ${supportsWasmSourcePhase ? 'source phase' : 'no source phase'}, ${supportsMultipleImportMaps ? '' : 'no '}multiple import maps, ${supportsImportMaps ? '' : 'no '}import maps`
404
- );
473
+ // support browsers without dynamic import support (eg Firefox 6x)
474
+ let supportsJsonType = false;
475
+ let supportsCssType = false;
476
+
477
+ const supports = hasDocument && HTMLScriptElement.supports;
478
+
479
+ let supportsImportMaps = supports && supports.name === 'supports' && supports('importmap');
480
+ let supportsWasmInstancePhase = false;
481
+ let supportsWasmSourcePhase = false;
482
+ let supportsMultipleImportMaps = false;
483
+
484
+ const wasmBytes = [0, 97, 115, 109, 1, 0, 0, 0];
485
+
486
+ let featureDetectionPromise = (async function () {
487
+ if (!hasDocument)
488
+ return Promise.all([
489
+ import(createBlob(`import"${createBlob('{}', 'text/json')}"with{type:"json"}`)).then(
490
+ () => (
491
+ (supportsJsonType = true),
492
+ import(createBlob(`import"${createBlob('', 'text/css')}"with{type:"css"}`)).then(
493
+ () => (supportsCssType = true),
494
+ noop
495
+ )
496
+ ),
497
+ noop
498
+ ),
499
+ wasmInstancePhaseEnabled &&
500
+ import(createBlob(`import"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
501
+ () => (supportsWasmInstancePhase = true),
502
+ noop
503
+ ),
504
+ wasmSourcePhaseEnabled &&
505
+ import(createBlob(`import source x from"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
506
+ () => (supportsWasmSourcePhase = true),
507
+ noop
508
+ )
509
+ ]);
510
+
511
+ return new Promise(resolve => {
512
+ const iframe = document.createElement('iframe');
513
+ iframe.style.display = 'none';
514
+ iframe.setAttribute('nonce', nonce);
515
+ function cb({ data }) {
516
+ const isFeatureDetectionMessage = Array.isArray(data) && data[0] === 'esms';
517
+ if (!isFeatureDetectionMessage) return;
518
+ [
519
+ ,
520
+ supportsImportMaps,
521
+ supportsMultipleImportMaps,
522
+ supportsJsonType,
523
+ supportsCssType,
524
+ supportsWasmSourcePhase,
525
+ supportsWasmInstancePhase
526
+ ] = data;
527
+ resolve();
528
+ document.head.removeChild(iframe);
529
+ window.removeEventListener('message', cb, false);
530
+ }
531
+ window.addEventListener('message', cb, false);
532
+
533
+ // Feature checking with careful avoidance of unnecessary work - all gated on initial import map supports check. CSS gates on JSON feature check, Wasm instance phase gates on wasm source phase check.
534
+ const importMapTest = `<script nonce=${nonce || ''}>b=(s,type='text/javascript')=>URL.createObjectURL(new Blob([s],{type}));c=u=>import(u).then(()=>true,()=>false);i=innerText=>document.head.appendChild(Object.assign(document.createElement('script'),{type:'importmap',nonce:"${nonce}",innerText}));i(\`{"imports":{"x":"\${b('')}"}}\`);i(\`{"imports":{"y":"\${b('')}"}}\`);cm=${
535
+ supportsImportMaps ? `c(b(\`import"\${b('{}','text/json')}"with{type:"json"}\`))` : 'false'
536
+ };sp=${
537
+ supportsImportMaps && wasmSourcePhaseEnabled ?
538
+ `c(b(\`import source x from "\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))`
539
+ : 'false'
540
+ };Promise.all([${supportsImportMaps ? 'true' : "c('x')"},${supportsImportMaps ? "c('y')" : false},cm,${
541
+ supportsImportMaps ? `cm.then(s=>s?c(b(\`import"\${b('','text/css')\}"with{type:"css"}\`)):false)` : 'false'
542
+ },sp,${
543
+ supportsImportMaps && wasmInstancePhaseEnabled ?
544
+ `${wasmSourcePhaseEnabled ? 'sp.then(s=>s?' : ''}c(b(\`import"\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))${wasmSourcePhaseEnabled ? ':false)' : ''}`
545
+ : 'false'
546
+ }]).then(a=>parent.postMessage(['esms'].concat(a),'*'))<${''}/script>`;
547
+
548
+ // Safari will call onload eagerly on head injection, but we don't want the Wechat
549
+ // path to trigger before setting srcdoc, therefore we track the timing
550
+ let readyForOnload = false,
551
+ onloadCalledWhileNotReady = false;
552
+ function doOnload() {
553
+ if (!readyForOnload) {
554
+ onloadCalledWhileNotReady = true;
555
+ return;
556
+ }
557
+ // WeChat browser doesn't support setting srcdoc scripts
558
+ // But iframe sandboxes don't support contentDocument so we do this as a fallback
559
+ const doc = iframe.contentDocument;
560
+ if (doc && doc.head.childNodes.length === 0) {
561
+ const s = doc.createElement('script');
562
+ if (nonce) s.setAttribute('nonce', nonce);
563
+ s.innerHTML = importMapTest.slice(15 + (nonce ? nonce.length : 0), -9);
564
+ doc.head.appendChild(s);
565
+ }
566
+ }
567
+
568
+ iframe.onload = doOnload;
569
+ // WeChat browser requires append before setting srcdoc
570
+ document.head.appendChild(iframe);
571
+
572
+ // setting srcdoc is not supported in React native webviews on iOS
573
+ // setting src to a blob URL results in a navigation event in webviews
574
+ // document.write gives usability warnings
575
+ readyForOnload = true;
576
+ if ('srcdoc' in iframe) iframe.srcdoc = importMapTest;
577
+ else iframe.contentDocument.write(importMapTest);
578
+ // retrigger onload for Safari only if necessary
579
+ if (onloadCalledWhileNotReady) doOnload();
580
+ });
581
+ })();
582
+
583
+ featureDetectionPromise = featureDetectionPromise.then(() => {
584
+ console.info(
585
+ `es-module-shims: detected native support - module types: (${[...(supportsJsonType ? ['json'] : []), ...(supportsCssType ? ['css'] : []), ...(supportsWasmInstancePhase ? ['wasm'] : [])].join(', ')}), ${supportsWasmSourcePhase ? 'source phase' : 'no source phase'}, ${supportsMultipleImportMaps ? '' : 'no '}multiple import maps, ${supportsImportMaps ? '' : 'no '}import maps`
586
+ );
405
587
  });
406
588
 
407
589
  /* es-module-lexer 1.7.0 */
408
590
  let e,a,r,i=2<<19;const s=1===new Uint8Array(new Uint16Array([1]).buffer)[0]?function(e,a){const r=e.length;let i=0;for(;i<r;)a[i]=e.charCodeAt(i++);}:function(e,a){const r=e.length;let i=0;for(;i<r;){const r=e.charCodeAt(i);a[i++]=(255&r)<<8|r>>>8;}},f="xportmportlassforetaourceeferromsyncunctionssertvoyiedelecontininstantybreareturdebuggeawaithrwhileifcatcfinallels";let t,c$1,n;function parse(k,l="@"){t=k,c$1=l;const u=2*t.length+(2<<18);if(u>i||!e){for(;u>i;)i*=2;a=new ArrayBuffer(i),s(f,new Uint16Array(a,16,114)),e=function(e,a,r){"use asm";var i=new e.Int8Array(r),s=new e.Int16Array(r),f=new e.Int32Array(r),t=new e.Uint8Array(r),c=new e.Uint16Array(r),n=1040;function b(){var e=0,a=0,r=0,t=0,c=0,b=0,u=0;u=n;n=n+10240|0;i[812]=1;i[811]=0;s[403]=0;s[404]=0;f[71]=f[2];i[813]=0;f[70]=0;i[810]=0;f[72]=u+2048;f[73]=u;i[814]=0;e=(f[3]|0)+-2|0;f[74]=e;a=e+(f[68]<<1)|0;f[75]=a;e:while(1){r=e+2|0;f[74]=r;if(e>>>0>=a>>>0){t=18;break}a:do{switch(s[r>>1]|0){case 9:case 10:case 11:case 12:case 13:case 32:break;case 101:{if((((s[404]|0)==0?H(r)|0:0)?(m(e+4|0,16,10)|0)==0:0)?(k(),(i[812]|0)==0):0){t=9;break e}else t=17;break}case 105:{if(H(r)|0?(m(e+4|0,26,10)|0)==0:0){l();t=17;}else t=17;break}case 59:{t=17;break}case 47:switch(s[e+4>>1]|0){case 47:{P();break a}case 42:{y(1);break a}default:{t=16;break e}}default:{t=16;break e}}}while(0);if((t|0)==17){t=0;f[71]=f[74];}e=f[74]|0;a=f[75]|0;}if((t|0)==9){e=f[74]|0;f[71]=e;t=19;}else if((t|0)==16){i[812]=0;f[74]=e;t=19;}else if((t|0)==18)if(!(i[810]|0)){e=r;t=19;}else e=0;do{if((t|0)==19){e:while(1){a=e+2|0;f[74]=a;if(e>>>0>=(f[75]|0)>>>0){t=92;break}a:do{switch(s[a>>1]|0){case 9:case 10:case 11:case 12:case 13:case 32:break;case 101:{if(((s[404]|0)==0?H(a)|0:0)?(m(e+4|0,16,10)|0)==0:0){k();t=91;}else t=91;break}case 105:{if(H(a)|0?(m(e+4|0,26,10)|0)==0:0){l();t=91;}else t=91;break}case 99:{if((H(a)|0?(m(e+4|0,36,8)|0)==0:0)?V(s[e+12>>1]|0)|0:0){i[814]=1;t=91;}else t=91;break}case 40:{r=f[72]|0;e=s[404]|0;t=e&65535;f[r+(t<<3)>>2]=1;a=f[71]|0;s[404]=e+1<<16>>16;f[r+(t<<3)+4>>2]=a;t=91;break}case 41:{a=s[404]|0;if(!(a<<16>>16)){t=36;break e}r=a+-1<<16>>16;s[404]=r;t=s[403]|0;a=t&65535;if(t<<16>>16!=0?(f[(f[72]|0)+((r&65535)<<3)>>2]|0)==5:0){a=f[(f[73]|0)+(a+-1<<2)>>2]|0;r=a+4|0;if(!(f[r>>2]|0))f[r>>2]=(f[71]|0)+2;f[a+12>>2]=e+4;s[403]=t+-1<<16>>16;t=91;}else t=91;break}case 123:{t=f[71]|0;r=f[65]|0;e=t;do{if((s[t>>1]|0)==41&(r|0)!=0?(f[r+4>>2]|0)==(t|0):0){a=f[66]|0;f[65]=a;if(!a){f[61]=0;break}else {f[a+32>>2]=0;break}}}while(0);r=f[72]|0;a=s[404]|0;t=a&65535;f[r+(t<<3)>>2]=(i[814]|0)==0?2:6;s[404]=a+1<<16>>16;f[r+(t<<3)+4>>2]=e;i[814]=0;t=91;break}case 125:{e=s[404]|0;if(!(e<<16>>16)){t=49;break e}r=f[72]|0;t=e+-1<<16>>16;s[404]=t;if((f[r+((t&65535)<<3)>>2]|0)==4){h();t=91;}else t=91;break}case 39:{v(39);t=91;break}case 34:{v(34);t=91;break}case 47:switch(s[e+4>>1]|0){case 47:{P();break a}case 42:{y(1);break a}default:{e=f[71]|0;a=s[e>>1]|0;r:do{if(!(U(a)|0))if(a<<16>>16==41){r=s[404]|0;if(!(D(f[(f[72]|0)+((r&65535)<<3)+4>>2]|0)|0))t=65;}else t=64;else switch(a<<16>>16){case 46:if(((s[e+-2>>1]|0)+-48&65535)<10){t=64;break r}else break r;case 43:if((s[e+-2>>1]|0)==43){t=64;break r}else break r;case 45:if((s[e+-2>>1]|0)==45){t=64;break r}else break r;default:break r}}while(0);if((t|0)==64){r=s[404]|0;t=65;}r:do{if((t|0)==65){t=0;if(r<<16>>16!=0?(c=f[72]|0,b=(r&65535)+-1|0,a<<16>>16==102?(f[c+(b<<3)>>2]|0)==1:0):0){if((s[e+-2>>1]|0)==111?$(f[c+(b<<3)+4>>2]|0,44,3)|0:0)break}else t=69;if((t|0)==69?(0,a<<16>>16==125):0){t=f[72]|0;r=r&65535;if(p(f[t+(r<<3)+4>>2]|0)|0)break;if((f[t+(r<<3)>>2]|0)==6)break}if(!(o(e)|0)){switch(a<<16>>16){case 0:break r;case 47:{if(i[813]|0)break r;break}default:{}}t=f[67]|0;if((t|0?e>>>0>=(f[t>>2]|0)>>>0:0)?e>>>0<=(f[t+4>>2]|0)>>>0:0){g();i[813]=0;t=91;break a}r=f[3]|0;do{if(e>>>0<=r>>>0)break;e=e+-2|0;f[71]=e;a=s[e>>1]|0;}while(!(E(a)|0));if(F(a)|0){do{if(e>>>0<=r>>>0)break;e=e+-2|0;f[71]=e;}while(F(s[e>>1]|0)|0);if(j(e)|0){g();i[813]=0;t=91;break a}}i[813]=1;t=91;break a}}}while(0);g();i[813]=0;t=91;break a}}case 96:{r=f[72]|0;a=s[404]|0;t=a&65535;f[r+(t<<3)+4>>2]=f[71];s[404]=a+1<<16>>16;f[r+(t<<3)>>2]=3;h();t=91;break}default:t=91;}}while(0);if((t|0)==91){t=0;f[71]=f[74];}e=f[74]|0;}if((t|0)==36){T();e=0;break}else if((t|0)==49){T();e=0;break}else if((t|0)==92){e=(i[810]|0)==0?(s[403]|s[404])<<16>>16==0:0;break}}}while(0);n=u;return e|0}function k(){var e=0,a=0,r=0,t=0,c=0,n=0,b=0,k=0,l=0,o=0,h=0,d=0,C=0,g=0;k=f[74]|0;l=f[67]|0;g=k+12|0;f[74]=g;r=w(1)|0;e=f[74]|0;if(!((e|0)==(g|0)?!(I(r)|0):0))C=3;e:do{if((C|0)==3){a:do{switch(r<<16>>16){case 123:{f[74]=e+2;e=w(1)|0;a=f[74]|0;while(1){if(W(e)|0){v(e);e=(f[74]|0)+2|0;f[74]=e;}else {q(e)|0;e=f[74]|0;}w(1)|0;e=A(a,e)|0;if(e<<16>>16==44){f[74]=(f[74]|0)+2;e=w(1)|0;}if(e<<16>>16==125){C=15;break}g=a;a=f[74]|0;if((a|0)==(g|0)){C=12;break}if(a>>>0>(f[75]|0)>>>0){C=14;break}}if((C|0)==12){T();break e}else if((C|0)==14){T();break e}else if((C|0)==15){i[811]=1;f[74]=(f[74]|0)+2;break a}break}case 42:{f[74]=e+2;w(1)|0;g=f[74]|0;A(g,g)|0;break}default:{i[812]=0;switch(r<<16>>16){case 100:{k=e+14|0;f[74]=k;switch((w(1)|0)<<16>>16){case 97:{a=f[74]|0;if((m(a+2|0,80,8)|0)==0?(c=a+10|0,F(s[c>>1]|0)|0):0){f[74]=c;w(0)|0;C=22;}break}case 102:{C=22;break}case 99:{a=f[74]|0;if(((m(a+2|0,36,8)|0)==0?(t=a+10|0,g=s[t>>1]|0,V(g)|0|g<<16>>16==123):0)?(f[74]=t,n=w(1)|0,n<<16>>16!=123):0){d=n;C=31;}break}default:{}}r:do{if((C|0)==22?(b=f[74]|0,(m(b+2|0,88,14)|0)==0):0){r=b+16|0;a=s[r>>1]|0;if(!(V(a)|0))switch(a<<16>>16){case 40:case 42:break;default:break r}f[74]=r;a=w(1)|0;if(a<<16>>16==42){f[74]=(f[74]|0)+2;a=w(1)|0;}if(a<<16>>16!=40){d=a;C=31;}}}while(0);if((C|0)==31?(o=f[74]|0,q(d)|0,h=f[74]|0,h>>>0>o>>>0):0){O(e,k,o,h);f[74]=(f[74]|0)+-2;break e}O(e,k,0,0);f[74]=e+12;break e}case 97:{f[74]=e+10;w(0)|0;e=f[74]|0;C=35;break}case 102:{C=35;break}case 99:{if((m(e+2|0,36,8)|0)==0?(a=e+10|0,E(s[a>>1]|0)|0):0){f[74]=a;g=w(1)|0;C=f[74]|0;q(g)|0;g=f[74]|0;O(C,g,C,g);f[74]=(f[74]|0)+-2;break e}e=e+4|0;f[74]=e;break}case 108:case 118:break;default:break e}if((C|0)==35){f[74]=e+16;e=w(1)|0;if(e<<16>>16==42){f[74]=(f[74]|0)+2;e=w(1)|0;}C=f[74]|0;q(e)|0;g=f[74]|0;O(C,g,C,g);f[74]=(f[74]|0)+-2;break e}f[74]=e+6;i[812]=0;r=w(1)|0;e=f[74]|0;r=(q(r)|0|32)<<16>>16==123;t=f[74]|0;if(r){f[74]=t+2;g=w(1)|0;e=f[74]|0;q(g)|0;}r:while(1){a=f[74]|0;if((a|0)==(e|0))break;O(e,a,e,a);a=w(1)|0;if(r)switch(a<<16>>16){case 93:case 125:break e;default:{}}e=f[74]|0;if(a<<16>>16!=44){C=51;break}f[74]=e+2;a=w(1)|0;e=f[74]|0;switch(a<<16>>16){case 91:case 123:{C=51;break r}default:{}}q(a)|0;}if((C|0)==51)f[74]=e+-2;if(!r)break e;f[74]=t+-2;break e}}}while(0);g=(w(1)|0)<<16>>16==102;e=f[74]|0;if(g?(m(e+2|0,74,6)|0)==0:0){f[74]=e+8;u(k,w(1)|0,0);e=(l|0)==0?248:l+16|0;while(1){e=f[e>>2]|0;if(!e)break e;f[e+12>>2]=0;f[e+8>>2]=0;e=e+16|0;}}f[74]=e+-2;}}while(0);return}function l(){var e=0,a=0,r=0,t=0,c=0,n=0,b=0;b=f[74]|0;c=b+12|0;f[74]=c;e=w(1)|0;t=f[74]|0;e:do{if(e<<16>>16!=46){if(!(e<<16>>16==115&t>>>0>c>>>0)){if(!(e<<16>>16==100&t>>>0>(b+10|0)>>>0)){t=0;n=28;break}if(m(t+2|0,66,8)|0){a=t;e=100;t=0;n=59;break}e=t+10|0;if(!(V(s[e>>1]|0)|0)){a=t;e=100;t=0;n=59;break}f[74]=e;e=w(1)|0;if(e<<16>>16==42){e=42;t=2;n=61;break}f[74]=t;t=0;n=28;break}if((m(t+2|0,56,10)|0)==0?(r=t+12|0,V(s[r>>1]|0)|0):0){f[74]=r;e=w(1)|0;a=f[74]|0;if((a|0)!=(r|0)){if(e<<16>>16!=102){t=1;n=28;break}if(m(a+2|0,74,6)|0){e=102;t=1;n=59;break}if(!(E(s[a+8>>1]|0)|0)){e=102;t=1;n=59;break}}f[74]=t;t=0;n=28;}else {a=t;e=115;t=0;n=59;}}else {f[74]=t+2;switch((w(1)|0)<<16>>16){case 109:{e=f[74]|0;if(m(e+2|0,50,6)|0)break e;a=f[71]|0;if(!(G(a)|0)?(s[a>>1]|0)==46:0)break e;d(b,b,e+8|0,2);break e}case 115:{e=f[74]|0;if(m(e+2|0,56,10)|0)break e;a=f[71]|0;if(!(G(a)|0)?(s[a>>1]|0)==46:0)break e;f[74]=e+12;e=w(1)|0;t=1;n=28;break e}case 100:{e=f[74]|0;if(m(e+2|0,66,8)|0)break e;a=f[71]|0;if(!(G(a)|0)?(s[a>>1]|0)==46:0)break e;f[74]=e+10;e=w(1)|0;t=2;n=28;break e}default:break e}}}while(0);e:do{if((n|0)==28){if(e<<16>>16==40){r=f[72]|0;a=s[404]|0;c=a&65535;f[r+(c<<3)>>2]=5;e=f[74]|0;s[404]=a+1<<16>>16;f[r+(c<<3)+4>>2]=e;if((s[f[71]>>1]|0)==46)break;f[74]=e+2;a=w(1)|0;d(b,f[74]|0,0,e);if(!t)e=f[65]|0;else {e=f[65]|0;f[e+28>>2]=(t|0)==1?5:7;}c=f[73]|0;b=s[403]|0;s[403]=b+1<<16>>16;f[c+((b&65535)<<2)>>2]=e;switch(a<<16>>16){case 39:{v(39);break}case 34:{v(34);break}default:{f[74]=(f[74]|0)+-2;break e}}e=(f[74]|0)+2|0;f[74]=e;switch((w(1)|0)<<16>>16){case 44:{f[74]=(f[74]|0)+2;w(1)|0;c=f[65]|0;f[c+4>>2]=e;b=f[74]|0;f[c+16>>2]=b;i[c+24>>0]=1;f[74]=b+-2;break e}case 41:{s[404]=(s[404]|0)+-1<<16>>16;b=f[65]|0;f[b+4>>2]=e;f[b+12>>2]=(f[74]|0)+2;i[b+24>>0]=1;s[403]=(s[403]|0)+-1<<16>>16;break e}default:{f[74]=(f[74]|0)+-2;break e}}}if(!((t|0)==0&e<<16>>16==123)){switch(e<<16>>16){case 42:case 39:case 34:{n=61;break e}default:{}}a=f[74]|0;n=59;break}e=f[74]|0;if(s[404]|0){f[74]=e+-2;break}while(1){if(e>>>0>=(f[75]|0)>>>0)break;e=w(1)|0;if(!(W(e)|0)){if(e<<16>>16==125){n=49;break}}else v(e);e=(f[74]|0)+2|0;f[74]=e;}if((n|0)==49)f[74]=(f[74]|0)+2;c=(w(1)|0)<<16>>16==102;e=f[74]|0;if(c?m(e+2|0,74,6)|0:0){T();break}f[74]=e+8;e=w(1)|0;if(W(e)|0){u(b,e,0);break}else {T();break}}}while(0);if((n|0)==59)if((a|0)==(c|0))f[74]=b+10;else n=61;do{if((n|0)==61){if(!((e<<16>>16==42|(t|0)!=2)&(s[404]|0)==0)){f[74]=(f[74]|0)+-2;break}e=f[75]|0;a=f[74]|0;while(1){if(a>>>0>=e>>>0){n=68;break}r=s[a>>1]|0;if(W(r)|0){n=66;break}n=a+2|0;f[74]=n;a=n;}if((n|0)==66){u(b,r,t);break}else if((n|0)==68){T();break}}}while(0);return}function u(e,a,r){e=e|0;a=a|0;r=r|0;var i=0,t=0;i=(f[74]|0)+2|0;switch(a<<16>>16){case 39:{v(39);t=5;break}case 34:{v(34);t=5;break}default:T();}do{if((t|0)==5){d(e,i,f[74]|0,1);if((r|0)>0)f[(f[65]|0)+28>>2]=(r|0)==1?4:6;f[74]=(f[74]|0)+2;a=w(0)|0;r=a<<16>>16==97;if(r){i=f[74]|0;if(m(i+2|0,102,10)|0)t=13;}else {i=f[74]|0;if(!(((a<<16>>16==119?(s[i+2>>1]|0)==105:0)?(s[i+4>>1]|0)==116:0)?(s[i+6>>1]|0)==104:0))t=13;}if((t|0)==13){f[74]=i+-2;break}f[74]=i+((r?6:4)<<1);if((w(1)|0)<<16>>16!=123){f[74]=i;break}r=f[74]|0;a=r;e:while(1){f[74]=a+2;a=w(1)|0;switch(a<<16>>16){case 39:{v(39);f[74]=(f[74]|0)+2;a=w(1)|0;break}case 34:{v(34);f[74]=(f[74]|0)+2;a=w(1)|0;break}default:a=q(a)|0;}if(a<<16>>16!=58){t=22;break}f[74]=(f[74]|0)+2;switch((w(1)|0)<<16>>16){case 39:{v(39);break}case 34:{v(34);break}default:{t=26;break e}}f[74]=(f[74]|0)+2;switch((w(1)|0)<<16>>16){case 125:{t=31;break e}case 44:break;default:{t=30;break e}}f[74]=(f[74]|0)+2;if((w(1)|0)<<16>>16==125){t=31;break}a=f[74]|0;}if((t|0)==22){f[74]=i;break}else if((t|0)==26){f[74]=i;break}else if((t|0)==30){f[74]=i;break}else if((t|0)==31){t=f[65]|0;f[t+16>>2]=r;f[t+12>>2]=(f[74]|0)+2;break}}}while(0);return}function o(e){e=e|0;e:do{switch(s[e>>1]|0){case 100:switch(s[e+-2>>1]|0){case 105:{e=$(e+-4|0,112,2)|0;break e}case 108:{e=$(e+-4|0,116,3)|0;break e}default:{e=0;break e}}case 101:switch(s[e+-2>>1]|0){case 115:switch(s[e+-4>>1]|0){case 108:{e=B(e+-6|0,101)|0;break e}case 97:{e=B(e+-6|0,99)|0;break e}default:{e=0;break e}}case 116:{e=$(e+-4|0,122,4)|0;break e}case 117:{e=$(e+-4|0,130,6)|0;break e}default:{e=0;break e}}case 102:{if((s[e+-2>>1]|0)==111?(s[e+-4>>1]|0)==101:0)switch(s[e+-6>>1]|0){case 99:{e=$(e+-8|0,142,6)|0;break e}case 112:{e=$(e+-8|0,154,2)|0;break e}default:{e=0;break e}}else e=0;break}case 107:{e=$(e+-2|0,158,4)|0;break}case 110:{e=e+-2|0;if(B(e,105)|0)e=1;else e=$(e,166,5)|0;break}case 111:{e=B(e+-2|0,100)|0;break}case 114:{e=$(e+-2|0,176,7)|0;break}case 116:{e=$(e+-2|0,190,4)|0;break}case 119:switch(s[e+-2>>1]|0){case 101:{e=B(e+-4|0,110)|0;break e}case 111:{e=$(e+-4|0,198,3)|0;break e}default:{e=0;break e}}default:e=0;}}while(0);return e|0}function h(){var e=0,a=0,r=0,i=0;a=f[75]|0;r=f[74]|0;e:while(1){e=r+2|0;if(r>>>0>=a>>>0){a=10;break}switch(s[e>>1]|0){case 96:{a=7;break e}case 36:{if((s[r+4>>1]|0)==123){a=6;break e}break}case 92:{e=r+4|0;break}default:{}}r=e;}if((a|0)==6){e=r+4|0;f[74]=e;a=f[72]|0;i=s[404]|0;r=i&65535;f[a+(r<<3)>>2]=4;s[404]=i+1<<16>>16;f[a+(r<<3)+4>>2]=e;}else if((a|0)==7){f[74]=e;r=f[72]|0;i=(s[404]|0)+-1<<16>>16;s[404]=i;if((f[r+((i&65535)<<3)>>2]|0)!=3)T();}else if((a|0)==10){f[74]=e;T();}return}function w(e){e=e|0;var a=0,r=0,i=0;r=f[74]|0;e:do{a=s[r>>1]|0;a:do{if(a<<16>>16!=47)if(e)if(V(a)|0)break;else break e;else if(F(a)|0)break;else break e;else switch(s[r+2>>1]|0){case 47:{P();break a}case 42:{y(e);break a}default:{a=47;break e}}}while(0);i=f[74]|0;r=i+2|0;f[74]=r;}while(i>>>0<(f[75]|0)>>>0);return a|0}function d(e,a,r,s){e=e|0;a=a|0;r=r|0;s=s|0;var t=0,c=0;c=f[69]|0;f[69]=c+36;t=f[65]|0;f[((t|0)==0?244:t+32|0)>>2]=c;f[66]=t;f[65]=c;f[c+8>>2]=e;if(2==(s|0)){e=3;t=r;}else {t=1==(s|0);e=t?1:2;t=t?r+2|0:0;}f[c+12>>2]=t;f[c+28>>2]=e;f[c>>2]=a;f[c+4>>2]=r;f[c+16>>2]=0;f[c+20>>2]=s;a=1==(s|0);i[c+24>>0]=a&1;f[c+32>>2]=0;if(a|2==(s|0))i[811]=1;return}function v(e){e=e|0;var a=0,r=0,i=0,t=0;t=f[75]|0;a=f[74]|0;while(1){i=a+2|0;if(a>>>0>=t>>>0){a=9;break}r=s[i>>1]|0;if(r<<16>>16==e<<16>>16){a=10;break}if(r<<16>>16==92){r=a+4|0;if((s[r>>1]|0)==13){a=a+6|0;a=(s[a>>1]|0)==10?a:r;}else a=r;}else if(Z(r)|0){a=9;break}else a=i;}if((a|0)==9){f[74]=i;T();}else if((a|0)==10)f[74]=i;return}function A(e,a){e=e|0;a=a|0;var r=0,i=0,t=0,c=0;r=f[74]|0;i=s[r>>1]|0;c=(e|0)==(a|0);t=c?0:e;c=c?0:a;if(i<<16>>16==97){f[74]=r+4;r=w(1)|0;e=f[74]|0;if(W(r)|0){v(r);a=(f[74]|0)+2|0;f[74]=a;}else {q(r)|0;a=f[74]|0;}i=w(1)|0;r=f[74]|0;}if((r|0)!=(e|0))O(e,a,t,c);return i|0}function C(){var e=0,a=0,r=0;r=f[75]|0;a=f[74]|0;e:while(1){e=a+2|0;if(a>>>0>=r>>>0){a=6;break}switch(s[e>>1]|0){case 13:case 10:{a=6;break e}case 93:{a=7;break e}case 92:{e=a+4|0;break}default:{}}a=e;}if((a|0)==6){f[74]=e;T();e=0;}else if((a|0)==7){f[74]=e;e=93;}return e|0}function g(){var e=0,a=0,r=0;e:while(1){e=f[74]|0;a=e+2|0;f[74]=a;if(e>>>0>=(f[75]|0)>>>0){r=7;break}switch(s[a>>1]|0){case 13:case 10:{r=7;break e}case 47:break e;case 91:{C()|0;break}case 92:{f[74]=e+4;break}default:{}}}if((r|0)==7)T();return}function p(e){e=e|0;switch(s[e>>1]|0){case 62:{e=(s[e+-2>>1]|0)==61;break}case 41:case 59:{e=1;break}case 104:{e=$(e+-2|0,218,4)|0;break}case 121:{e=$(e+-2|0,226,6)|0;break}case 101:{e=$(e+-2|0,238,3)|0;break}default:e=0;}return e|0}function y(e){e=e|0;var a=0,r=0,i=0,t=0,c=0;t=(f[74]|0)+2|0;f[74]=t;r=f[75]|0;while(1){a=t+2|0;if(t>>>0>=r>>>0)break;i=s[a>>1]|0;if(!e?Z(i)|0:0)break;if(i<<16>>16==42?(s[t+4>>1]|0)==47:0){c=8;break}t=a;}if((c|0)==8){f[74]=a;a=t+4|0;}f[74]=a;return}function m(e,a,r){e=e|0;a=a|0;r=r|0;var s=0,f=0;e:do{if(!r)e=0;else {while(1){s=i[e>>0]|0;f=i[a>>0]|0;if(s<<24>>24!=f<<24>>24)break;r=r+-1|0;if(!r){e=0;break e}else {e=e+1|0;a=a+1|0;}}e=(s&255)-(f&255)|0;}}while(0);return e|0}function I(e){e=e|0;e:do{switch(e<<16>>16){case 38:case 37:case 33:{e=1;break}default:if((e&-8)<<16>>16==40|(e+-58&65535)<6)e=1;else {switch(e<<16>>16){case 91:case 93:case 94:{e=1;break e}default:{}}e=(e+-123&65535)<4;}}}while(0);return e|0}function U(e){e=e|0;e:do{switch(e<<16>>16){case 38:case 37:case 33:break;default:if(!((e+-58&65535)<6|(e+-40&65535)<7&e<<16>>16!=41)){switch(e<<16>>16){case 91:case 94:break e;default:{}}return e<<16>>16!=125&(e+-123&65535)<4|0}}}while(0);return 1}function x(e){e=e|0;var a=0;a=s[e>>1]|0;e:do{if((a+-9&65535)>=5){switch(a<<16>>16){case 160:case 32:{a=1;break e}default:{}}if(I(a)|0)return a<<16>>16!=46|(G(e)|0)|0;else a=0;}else a=1;}while(0);return a|0}function S(e){e=e|0;var a=0,r=0,i=0,t=0;r=n;n=n+16|0;i=r;f[i>>2]=0;f[68]=e;a=f[3]|0;t=a+(e<<1)|0;e=t+2|0;s[t>>1]=0;f[i>>2]=e;f[69]=e;f[61]=0;f[65]=0;f[63]=0;f[62]=0;f[67]=0;f[64]=0;n=r;return a|0}function O(e,a,r,s){e=e|0;a=a|0;r=r|0;s=s|0;var t=0,c=0;t=f[69]|0;f[69]=t+20;c=f[67]|0;f[((c|0)==0?248:c+16|0)>>2]=t;f[67]=t;f[t>>2]=e;f[t+4>>2]=a;f[t+8>>2]=r;f[t+12>>2]=s;f[t+16>>2]=0;i[811]=1;return}function $(e,a,r){e=e|0;a=a|0;r=r|0;var i=0,s=0;i=e+(0-r<<1)|0;s=i+2|0;e=f[3]|0;if(s>>>0>=e>>>0?(m(s,a,r<<1)|0)==0:0)if((s|0)==(e|0))e=1;else e=x(i)|0;else e=0;return e|0}function j(e){e=e|0;switch(s[e>>1]|0){case 107:{e=$(e+-2|0,158,4)|0;break}case 101:{if((s[e+-2>>1]|0)==117)e=$(e+-4|0,130,6)|0;else e=0;break}default:e=0;}return e|0}function B(e,a){e=e|0;a=a|0;var r=0;r=f[3]|0;if(r>>>0<=e>>>0?(s[e>>1]|0)==a<<16>>16:0)if((r|0)==(e|0))r=1;else r=E(s[e+-2>>1]|0)|0;else r=0;return r|0}function E(e){e=e|0;e:do{if((e+-9&65535)<5)e=1;else {switch(e<<16>>16){case 32:case 160:{e=1;break e}default:{}}e=e<<16>>16!=46&(I(e)|0);}}while(0);return e|0}function P(){var e=0,a=0,r=0;e=f[75]|0;r=f[74]|0;e:while(1){a=r+2|0;if(r>>>0>=e>>>0)break;switch(s[a>>1]|0){case 13:case 10:break e;default:r=a;}}f[74]=a;return}function q(e){e=e|0;while(1){if(V(e)|0)break;if(I(e)|0)break;e=(f[74]|0)+2|0;f[74]=e;e=s[e>>1]|0;if(!(e<<16>>16)){e=0;break}}return e|0}function z(){var e=0;e=f[(f[63]|0)+20>>2]|0;switch(e|0){case 1:{e=-1;break}case 2:{e=-2;break}default:e=e-(f[3]|0)>>1;}return e|0}function D(e){e=e|0;if(!($(e,204,5)|0)?!($(e,44,3)|0):0)e=$(e,214,2)|0;else e=1;return e|0}function F(e){e=e|0;switch(e<<16>>16){case 160:case 32:case 12:case 11:case 9:{e=1;break}default:e=0;}return e|0}function G(e){e=e|0;if((s[e>>1]|0)==46?(s[e+-2>>1]|0)==46:0)e=(s[e+-4>>1]|0)==46;else e=0;return e|0}function H(e){e=e|0;if((f[3]|0)==(e|0))e=1;else e=x(e+-2|0)|0;return e|0}function J(){var e=0;e=f[(f[64]|0)+12>>2]|0;if(!e)e=-1;else e=e-(f[3]|0)>>1;return e|0}function K(){var e=0;e=f[(f[63]|0)+12>>2]|0;if(!e)e=-1;else e=e-(f[3]|0)>>1;return e|0}function L(){var e=0;e=f[(f[64]|0)+8>>2]|0;if(!e)e=-1;else e=e-(f[3]|0)>>1;return e|0}function M(){var e=0;e=f[(f[63]|0)+16>>2]|0;if(!e)e=-1;else e=e-(f[3]|0)>>1;return e|0}function N(){var e=0;e=f[(f[63]|0)+4>>2]|0;if(!e)e=-1;else e=e-(f[3]|0)>>1;return e|0}function Q(){var e=0;e=f[63]|0;e=f[((e|0)==0?244:e+32|0)>>2]|0;f[63]=e;return (e|0)!=0|0}function R(){var e=0;e=f[64]|0;e=f[((e|0)==0?248:e+16|0)>>2]|0;f[64]=e;return (e|0)!=0|0}function T(){i[810]=1;f[70]=(f[74]|0)-(f[3]|0)>>1;f[74]=(f[75]|0)+2;return}function V(e){e=e|0;return (e|128)<<16>>16==160|(e+-9&65535)<5|0}function W(e){e=e|0;return e<<16>>16==39|e<<16>>16==34|0}function X(){return (f[(f[63]|0)+8>>2]|0)-(f[3]|0)>>1|0}function Y(){return (f[(f[64]|0)+4>>2]|0)-(f[3]|0)>>1|0}function Z(e){e=e|0;return e<<16>>16==13|e<<16>>16==10|0}function _(){return (f[f[63]>>2]|0)-(f[3]|0)>>1|0}function ee(){return (f[f[64]>>2]|0)-(f[3]|0)>>1|0}function ae(){return t[(f[63]|0)+24>>0]|0|0}function re(e){e=e|0;f[3]=e;return}function ie(){return f[(f[63]|0)+28>>2]|0}function se(){return (i[811]|0)!=0|0}function fe(){return (i[812]|0)!=0|0}function te(){return f[70]|0}function ce(e){e=e|0;n=e+992+15&-16;return 992}return {su:ce,ai:M,e:te,ee:Y,ele:J,els:L,es:ee,f:fe,id:z,ie:N,ip:ae,is:_,it:ie,ms:se,p:b,re:R,ri:Q,sa:S,se:K,ses:re,ss:X}}("undefined"!=typeof self?self:global,{},a),r=e.su(i-(2<<17));}const h=t.length+1;e.ses(r),e.sa(h-1),s(t,new Uint16Array(a,r,h)),e.p()||(n=e.e(),o());const w=[],d=[];for(;e.ri();){const a=e.is(),r=e.ie(),i=e.ai(),s=e.id(),f=e.ss(),c=e.se(),n=e.it();let k;e.ip()&&(k=b(-1===s?a:a+1,t.charCodeAt(-1===s?a-1:a))),w.push({t:n,n:k,s:a,e:r,ss:f,se:c,d:s,a:i});}for(;e.re();){const a=e.es(),r=e.ee(),i=e.els(),s=e.ele(),f=t.charCodeAt(a),c=i>=0?t.charCodeAt(i):-1;d.push({s:a,e:r,ls:i,le:s,n:34===f||39===f?b(a+1,f):t.slice(a,r),ln:i<0?void 0:34===c||39===c?b(i+1,c):t.slice(i,s)});}return [w,d,!!e.f(),!!e.ms()]}function b(e,a){n=e;let r="",i=n;for(;;){n>=t.length&&o();const e=t.charCodeAt(n);if(e===a)break;92===e?(r+=t.slice(i,n),r+=k(),i=n):(8232===e||8233===e||u(e)&&o(),++n);}return r+=t.slice(i,n++),r}function k(){let e=t.charCodeAt(++n);switch(++n,e){case 110:return "\n";case 114:return "\r";case 120:return String.fromCharCode(l(2));case 117:return function(){const e=t.charCodeAt(n);let a;123===e?(++n,a=l(t.indexOf("}",n)-n),++n,a>1114111&&o()):a=l(4);return a<=65535?String.fromCharCode(a):(a-=65536,String.fromCharCode(55296+(a>>10),56320+(1023&a)))}();case 116:return "\t";case 98:return "\b";case 118:return "\v";case 102:return "\f";case 13:10===t.charCodeAt(n)&&++n;case 10:return "";case 56:case 57:o();default:if(e>=48&&e<=55){let a=t.substr(n-1,3).match(/^[0-7]+/)[0],r=parseInt(a,8);return r>255&&(a=a.slice(0,-1),r=parseInt(a,8)),n+=a.length-1,e=t.charCodeAt(n),"0"===a&&56!==e&&57!==e||o(),String.fromCharCode(r)}return u(e)?"":String.fromCharCode(e)}}function l(e){const a=n;let r=0,i=0;for(let a=0;a<e;++a,++n){let e,s=t.charCodeAt(n);if(95!==s){if(s>=97)e=s-97+10;else if(s>=65)e=s-65+10;else {if(!(s>=48&&s<=57))break;e=s-48;}if(e>=16)break;i=s,r=16*r+e;}else 95!==i&&0!==a||o(),i=s;}return 95!==i&&n-a===e||o(),r}function u(e){return 13===e||10===e}function o(){throw Object.assign(Error(`Parse error ${c$1}:${t.slice(0,n).split("\n").length}:${n-t.lastIndexOf("\n",n-1)}`),{idx:n})}
409
591
 
410
- function _resolve(id, parentUrl = baseUrl) {
592
+ const _resolve = (id, parentUrl = baseUrl) => {
411
593
  const urlResolved = resolveIfNotPlainOrUrl(id, parentUrl) || asURL(id);
412
594
  const firstResolved = firstImportMap && resolveImportMap(firstImportMap, urlResolved || id, parentUrl);
413
595
  const composedResolved =
@@ -430,100 +612,97 @@
430
612
  if (firstResolved && resolved !== firstResolved) N = true;
431
613
  }
432
614
  return { r: resolved, n, N };
433
- }
615
+ };
434
616
 
435
- const resolve =
436
- resolveHook ?
437
- (id, parentUrl = baseUrl) => {
438
- const result = resolveHook(id, parentUrl, defaultResolve);
439
- return result ? { r: result, n: true, N: true } : _resolve(id, parentUrl);
440
- }
441
- : _resolve;
617
+ const resolve = (id, parentUrl) => {
618
+ if (!resolveHook) return _resolve(id, parentUrl);
619
+ const result = resolveHook(id, parentUrl, defaultResolve);
442
620
 
443
- async function importHandler(id, opts, parentUrl = baseUrl, sourcePhase) {
444
- await initPromise; // needed for shim check
445
- console.info(
446
- `es-module-shims: importShim${sourcePhase ? '.source' : ''}("${id}"${opts ? ', ' + JSON.stringify(opts) : ''})`
447
- );
448
- if (importHook) await importHook(id, opts, parentUrl);
449
- if (shimMode || !baselinePassthrough) {
450
- if (hasDocument) processScriptsAndPreloads();
451
- legacyAcceptingImportMaps = false;
452
- }
453
- await importMapPromise;
454
- return resolve(id, parentUrl).r;
455
- }
621
+ return result ? { r: result, n: true, N: true } : _resolve(id, parentUrl);
622
+ };
456
623
 
457
624
  // import()
458
- async function importShim(id, opts, parentUrl) {
625
+ async function importShim$1(id, opts, parentUrl) {
459
626
  if (typeof opts === 'string') {
460
627
  parentUrl = opts;
461
628
  opts = undefined;
462
629
  }
463
- // we mock import('./x.css', { with: { type: 'css' }}) support via an inline static reexport
464
- // because we can't syntactically pass through to dynamic import with a second argument
465
- let url = await importHandler(id, opts, parentUrl, false);
466
- let source = undefined;
467
- let ts = false;
630
+ await initPromise; // needed for shim check
631
+ console.info(`es-module-shims: importShim("${id}"${opts ? ', ' + JSON.stringify(opts) : ''})`);
632
+ if (shimMode || !baselinePassthrough) {
633
+ if (hasDocument) processScriptsAndPreloads();
634
+ legacyAcceptingImportMaps = false;
635
+ }
636
+ let sourceType = undefined;
468
637
  if (typeof opts === 'object') {
469
- ts = opts.lang === 'ts';
638
+ if (opts.lang === 'ts') sourceType = 'ts';
470
639
  if (typeof opts.with === 'object' && typeof opts.with.type === 'string') {
471
- source = `export{default}from'${url}'with{type:"${opts.with.type}"}`;
472
- url += '?entry';
640
+ sourceType = opts.with.type;
473
641
  }
474
642
  }
475
- return topLevelLoad(url, { credentials: 'same-origin' }, source, undefined, undefined, ts);
643
+ return topLevelLoad(id, parentUrl || baseUrl, defaultFetchOpts, undefined, undefined, undefined, sourceType);
476
644
  }
477
645
 
478
646
  // import.source()
479
647
  // (opts not currently supported as no use cases yet)
480
648
  if (shimMode || wasmSourcePhaseEnabled)
481
- importShim.source = async function (specifier, opts, parentUrl) {
649
+ importShim$1.source = async (id, opts, parentUrl) => {
482
650
  if (typeof opts === 'string') {
483
651
  parentUrl = opts;
484
652
  opts = undefined;
485
653
  }
486
- const url = await importHandler(specifier, opts, parentUrl, true);
487
- const load = getOrCreateLoad(url, { credentials: 'same-origin' }, undefined, undefined);
654
+ await initPromise; // needed for shim check
655
+ console.info(`es-module-shims: importShim.source("${id}"${opts ? ', ' + JSON.stringify(opts) : ''})`);
656
+ if (shimMode || !baselinePassthrough) {
657
+ if (hasDocument) processScriptsAndPreloads();
658
+ legacyAcceptingImportMaps = false;
659
+ }
660
+ await importMapPromise;
661
+ const url = resolve(id, parentUrl || baseUrl).r;
662
+ const load = getOrCreateLoad(url, defaultFetchOpts, undefined, undefined);
488
663
  if (firstPolyfillLoad && !shimMode && load.n && nativelyLoaded) {
489
664
  onpolyfill();
490
665
  firstPolyfillLoad = false;
491
666
  }
492
667
  await load.f;
493
- return importShim._s[load.r];
668
+ return importShim$1._s[load.r];
494
669
  };
495
670
 
496
671
  // import.defer() is just a proxy for import(), since we can't actually defer
497
- if (shimMode || deferPhaseEnabled) importShim.defer = importShim;
672
+ if (shimMode || deferPhaseEnabled) importShim$1.defer = importShim$1;
498
673
 
499
- self.importShim = importShim;
674
+ if (hotReload) importShim$1.hotReload = hotReload$1;
500
675
 
501
- function defaultResolve(id, parentUrl) {
676
+ self.importShim = importShim$1;
677
+
678
+ const defaultResolve = (id, parentUrl) => {
502
679
  return (
503
680
  resolveImportMap(composedImportMap, resolveIfNotPlainOrUrl(id, parentUrl) || id, parentUrl) ||
504
681
  throwUnresolved(id, parentUrl)
505
682
  );
506
- }
683
+ };
507
684
 
508
- function throwUnresolved(id, parentUrl) {
685
+ const throwUnresolved = (id, parentUrl) => {
509
686
  throw Error(`Unable to resolve specifier '${id}'${fromParent(parentUrl)}`);
510
- }
687
+ };
511
688
 
512
- function metaResolve(id, parentUrl = this.url) {
689
+ const metaResolve = function (id, parentUrl = this.url) {
513
690
  return resolve(id, `${parentUrl}`).r;
514
- }
691
+ };
515
692
 
516
- importShim.resolve = (id, parentUrl) => resolve(id, parentUrl).r;
517
- importShim.getImportMap = () => JSON.parse(JSON.stringify(composedImportMap));
518
- importShim.addImportMap = importMapIn => {
693
+ importShim$1.resolve = (id, parentUrl) => resolve(id, parentUrl).r;
694
+ importShim$1.getImportMap = () => JSON.parse(JSON.stringify(composedImportMap));
695
+ importShim$1.addImportMap = importMapIn => {
519
696
  if (!shimMode) throw new Error('Unsupported in polyfill mode.');
520
697
  composedImportMap = resolveAndComposeImportMap(importMapIn, baseUrl, composedImportMap);
521
698
  };
522
699
 
523
- const registry = (importShim._r = {});
524
- const sourceCache = (importShim._s = {});
700
+ const registry = (importShim$1._r = {});
701
+ // Wasm caches
702
+ const sourceCache = (importShim$1._s = {});
703
+ (importShim$1._i = new WeakMap());
525
704
 
526
- async function loadAll(load, seen) {
705
+ const loadAll = async (load, seen) => {
527
706
  seen[load.u] = 1;
528
707
  await load.L;
529
708
  await Promise.all(
@@ -533,7 +712,7 @@
533
712
  return loadAll(dep, seen);
534
713
  })
535
714
  );
536
- }
715
+ };
537
716
 
538
717
  let importMapSrc = false;
539
718
  let multipleImportMaps = false;
@@ -553,35 +732,32 @@
553
732
  !deferPhaseEnabled &&
554
733
  (!multipleImportMaps || supportsMultipleImportMaps) &&
555
734
  !importMapSrc;
556
- if (
557
- !shimMode &&
558
- wasmSourcePhaseEnabled &&
559
- typeof WebAssembly !== 'undefined' &&
560
- !Object.getPrototypeOf(WebAssembly.Module).name
561
- ) {
562
- const s = Symbol();
563
- const brand = m =>
564
- Object.defineProperty(m, s, { writable: false, configurable: false, value: 'WebAssembly.Module' });
565
- class AbstractModuleSource {
566
- get [Symbol.toStringTag]() {
567
- if (this[s]) return this[s];
568
- throw new TypeError('Not an AbstractModuleSource');
735
+ if (!shimMode && typeof WebAssembly !== 'undefined') {
736
+ if (wasmSourcePhaseEnabled && !Object.getPrototypeOf(WebAssembly.Module).name) {
737
+ const s = Symbol();
738
+ const brand = m =>
739
+ Object.defineProperty(m, s, { writable: false, configurable: false, value: 'WebAssembly.Module' });
740
+ class AbstractModuleSource {
741
+ get [Symbol.toStringTag]() {
742
+ if (this[s]) return this[s];
743
+ throw new TypeError('Not an AbstractModuleSource');
744
+ }
569
745
  }
746
+ const { Module: wasmModule, compile: wasmCompile, compileStreaming: wasmCompileStreaming } = WebAssembly;
747
+ WebAssembly.Module = Object.setPrototypeOf(
748
+ Object.assign(function Module(...args) {
749
+ return brand(new wasmModule(...args));
750
+ }, wasmModule),
751
+ AbstractModuleSource
752
+ );
753
+ WebAssembly.Module.prototype = Object.setPrototypeOf(wasmModule.prototype, AbstractModuleSource.prototype);
754
+ WebAssembly.compile = function compile(...args) {
755
+ return wasmCompile(...args).then(brand);
756
+ };
757
+ WebAssembly.compileStreaming = function compileStreaming(...args) {
758
+ return wasmCompileStreaming(...args).then(brand);
759
+ };
570
760
  }
571
- const { Module: wasmModule, compile: wasmCompile, compileStreaming: wasmCompileStreaming } = WebAssembly;
572
- WebAssembly.Module = Object.setPrototypeOf(
573
- Object.assign(function Module(...args) {
574
- return brand(new wasmModule(...args));
575
- }, wasmModule),
576
- AbstractModuleSource
577
- );
578
- WebAssembly.Module.prototype = Object.setPrototypeOf(wasmModule.prototype, AbstractModuleSource.prototype);
579
- WebAssembly.compile = function compile(...args) {
580
- return wasmCompile(...args).then(brand);
581
- };
582
- WebAssembly.compileStreaming = function compileStreaming(...args) {
583
- return wasmCompileStreaming(...args).then(brand);
584
- };
585
761
  }
586
762
  if (hasDocument) {
587
763
  if (!supportsImportMaps) {
@@ -593,14 +769,6 @@
593
769
  if (document.readyState === 'complete') {
594
770
  readyStateCompleteCheck();
595
771
  } else {
596
- async function readyListener() {
597
- await initPromise;
598
- processScriptsAndPreloads();
599
- if (document.readyState === 'complete') {
600
- readyStateCompleteCheck();
601
- document.removeEventListener('readystatechange', readyListener);
602
- }
603
- }
604
772
  document.addEventListener('readystatechange', readyListener);
605
773
  }
606
774
  }
@@ -609,7 +777,7 @@
609
777
  return undefined;
610
778
  });
611
779
 
612
- function attachMutationObserver() {
780
+ const attachMutationObserver = () => {
613
781
  const observer = new MutationObserver(mutations => {
614
782
  for (const mutation of mutations) {
615
783
  if (mutation.type !== 'childList') continue;
@@ -630,18 +798,35 @@
630
798
  observer.observe(document, { childList: true });
631
799
  observer.observe(document.head, { childList: true });
632
800
  processScriptsAndPreloads();
633
- }
801
+ };
634
802
 
635
803
  let importMapPromise = initPromise;
636
804
  let firstPolyfillLoad = true;
637
805
  let legacyAcceptingImportMaps = true;
638
806
 
639
- async function topLevelLoad(url, fetchOpts, source, nativelyLoaded, lastStaticLoadPromise, typescript) {
807
+ const topLevelLoad = async (
808
+ url,
809
+ parentUrl,
810
+ fetchOpts,
811
+ source,
812
+ nativelyLoaded,
813
+ lastStaticLoadPromise,
814
+ sourceType
815
+ ) => {
640
816
  await initPromise;
641
817
  await importMapPromise;
642
- if (importHook) await importHook(url, typeof fetchOpts !== 'string' ? fetchOpts : {}, '');
818
+ url = (await resolve(url, parentUrl)).r;
819
+
820
+ // we mock import('./x.css', { with: { type: 'css' }}) support via an inline static reexport
821
+ // because we can't syntactically pass through to dynamic import with a second argument
822
+ if (sourceType === 'css' || sourceType === 'json') {
823
+ source = `export{default}from'${url}'with{type:"${sourceType}"}`;
824
+ url += '?entry';
825
+ }
826
+
827
+ if (importHook) await importHook(url, typeof fetchOpts !== 'string' ? fetchOpts : {}, parentUrl, source, sourceType);
643
828
  // early analysis opt-out - no need to even fetch if we have feature support
644
- if (!shimMode && baselinePassthrough && !typescript) {
829
+ if (!shimMode && baselinePassthrough && nativePassthrough && sourceType !== 'ts') {
645
830
  console.info(`es-module-shims: early exit for ${url} due to baseline modules support`);
646
831
  // for polyfill case, only dynamic import needs a return value here, and dynamic import will never pass nativelyLoaded
647
832
  if (nativelyLoaded) return null;
@@ -669,37 +854,55 @@
669
854
  onpolyfill();
670
855
  firstPolyfillLoad = false;
671
856
  }
672
- const module = await (shimMode || load.n || load.N || (!nativelyLoaded && source) ?
857
+ const module = await (shimMode || load.n || load.N || !nativePassthrough || (!nativelyLoaded && source) ?
673
858
  dynamicImport(load.b, load.u)
674
859
  : import(load.u));
675
860
  // if the top-level load is a shell, run its update function
676
861
  if (load.s) (await dynamicImport(load.s, load.u)).u$_(module);
677
862
  if (revokeBlobURLs) revokeObjectURLs(Object.keys(seen));
678
863
  return module;
679
- }
864
+ };
680
865
 
681
- function revokeObjectURLs(registryKeys) {
682
- let batch = 0;
683
- const keysLength = registryKeys.length;
684
- const schedule = self.requestIdleCallback ? self.requestIdleCallback : self.requestAnimationFrame;
685
- schedule(cleanup);
866
+ const revokeObjectURLs = registryKeys => {
867
+ let curIdx = 0;
868
+ const handler = self.requestIdleCallback || self.requestAnimationFrame;
869
+ handler(cleanup);
686
870
  function cleanup() {
687
- const batchStartIndex = batch * 100;
688
- if (batchStartIndex > keysLength) return;
689
- for (const key of registryKeys.slice(batchStartIndex, batchStartIndex + 100)) {
871
+ for (const key of registryKeys.slice(curIdx, (curIdx += 100))) {
690
872
  const load = registry[key];
691
873
  if (load && load.b && load.b !== load.u) URL.revokeObjectURL(load.b);
692
874
  }
693
- batch++;
694
- schedule(cleanup);
875
+ if (curIdx < registryKeys.length) handler(cleanup);
695
876
  }
696
- }
877
+ };
697
878
 
698
- function urlJsString(url) {
699
- return `'${url.replace(/'/g, "\\'")}'`;
700
- }
879
+ const urlJsString = url => `'${url.replace(/'/g, "\\'")}'`;
880
+
881
+ let resolvedSource, lastIndex;
882
+ const pushStringTo = (load, originalIndex, dynamicImportEndStack) => {
883
+ while (dynamicImportEndStack[dynamicImportEndStack.length - 1] < originalIndex) {
884
+ const dynamicImportEnd = dynamicImportEndStack.pop();
885
+ resolvedSource += `${load.S.slice(lastIndex, dynamicImportEnd)}, ${urlJsString(load.r)}`;
886
+ lastIndex = dynamicImportEnd;
887
+ }
888
+ resolvedSource += load.S.slice(lastIndex, originalIndex);
889
+ lastIndex = originalIndex;
890
+ };
891
+
892
+ const pushSourceURL = (load, commentPrefix, commentStart, dynamicImportEndStack) => {
893
+ const urlStart = commentStart + commentPrefix.length;
894
+ const commentEnd = load.S.indexOf('\n', urlStart);
895
+ const urlEnd = commentEnd !== -1 ? commentEnd : load.S.length;
896
+ let sourceUrl = load.S.slice(urlStart, urlEnd);
897
+ try {
898
+ sourceUrl = new URL(sourceUrl, load.r).href;
899
+ } catch {}
900
+ pushStringTo(load, urlStart, dynamicImportEndStack);
901
+ resolvedSource += sourceUrl;
902
+ lastIndex = urlEnd;
903
+ };
701
904
 
702
- function resolveDeps(load, seen) {
905
+ const resolveDeps = (load, seen) => {
703
906
  if (load.b || !seen[load.u]) return;
704
907
  seen[load.u] = 0;
705
908
 
@@ -712,7 +915,7 @@
712
915
 
713
916
  // use native loader whenever possible (n = needs shim) via executable subgraph passthrough
714
917
  // so long as the module doesn't use dynamic import or unsupported URL mappings (N = should shim)
715
- if (!shimMode && !load.n && !load.N) {
918
+ if (nativePassthrough && !shimMode && !load.n && !load.N) {
716
919
  load.b = load.u;
717
920
  load.S = undefined;
718
921
  return;
@@ -723,30 +926,19 @@
723
926
  const [imports, exports] = load.a;
724
927
 
725
928
  // "execution"
726
- const source = load.S;
727
-
728
- let resolvedSource = '';
929
+ let source = load.S,
930
+ depIndex = 0,
931
+ dynamicImportEndStack = [];
729
932
 
730
933
  // once all deps have loaded we can inline the dependency resolution blobs
731
934
  // and define this blob
732
- let lastIndex = 0,
733
- depIndex = 0,
734
- dynamicImportEndStack = [];
735
- function pushStringTo(originalIndex) {
736
- while (dynamicImportEndStack[dynamicImportEndStack.length - 1] < originalIndex) {
737
- const dynamicImportEnd = dynamicImportEndStack.pop();
738
- resolvedSource += `${source.slice(lastIndex, dynamicImportEnd)}, ${urlJsString(load.r)}`;
739
- lastIndex = dynamicImportEnd;
740
- }
741
- resolvedSource += source.slice(lastIndex, originalIndex);
742
- lastIndex = originalIndex;
743
- }
935
+ (resolvedSource = ''), (lastIndex = 0);
744
936
 
745
937
  for (const { s: start, e: end, ss: statementStart, se: statementEnd, d: dynamicImportIndex, t, a } of imports) {
746
938
  // source phase
747
939
  if (t === 4) {
748
940
  let { l: depLoad } = load.d[depIndex++];
749
- pushStringTo(statementStart);
941
+ pushStringTo(load, statementStart, dynamicImportEndStack);
750
942
  resolvedSource += `${source.slice(statementStart, start - 1).replace('source', '')}/*${source.slice(start - 1, end + 1)}*/'${createBlob(`export default importShim._s[${urlJsString(depLoad.r)}]`)}'`;
751
943
  lastIndex = end + 1;
752
944
  }
@@ -757,12 +949,13 @@
757
949
  const assertion = source.slice(a, statementEnd - 1);
758
950
  // strip assertions only when unsupported in polyfill mode
759
951
  keepAssertion =
760
- (supportsJsonType && assertion.includes('json')) || (supportsCssType && assertion.includes('css'));
952
+ nativePassthrough &&
953
+ ((supportsJsonType && assertion.includes('json')) || (supportsCssType && assertion.includes('css')));
761
954
  }
762
955
 
763
956
  // defer phase stripping
764
957
  if (t === 6) {
765
- pushStringTo(statementStart);
958
+ pushStringTo(load, statementStart, dynamicImportEndStack);
766
959
  resolvedSource += source.slice(statementStart, start - 1).replace('defer', '');
767
960
  lastIndex = start;
768
961
  }
@@ -787,7 +980,7 @@
787
980
  }
788
981
  }
789
982
 
790
- pushStringTo(start - 1);
983
+ pushStringTo(load, start - 1, dynamicImportEndStack);
791
984
  resolvedSource += `/*${source.slice(start - 1, end + 1)}*/'${blobUrl}'`;
792
985
 
793
986
  // circular shell execution
@@ -800,14 +993,14 @@
800
993
  // import.meta
801
994
  else if (dynamicImportIndex === -2) {
802
995
  load.m = { url: load.r, resolve: metaResolve };
803
- metaHook(load.m, load.u);
804
- pushStringTo(start);
996
+ if (metaHook) metaHook(load.m, load.u);
997
+ pushStringTo(load, start, dynamicImportEndStack);
805
998
  resolvedSource += `importShim._r[${urlJsString(load.u)}].m`;
806
999
  lastIndex = statementEnd;
807
1000
  }
808
1001
  // dynamic import
809
1002
  else {
810
- pushStringTo(statementStart + 6);
1003
+ pushStringTo(load, statementStart + 6, dynamicImportEndStack);
811
1004
  resolvedSource += `Shim${t === 5 ? '.source' : ''}(`;
812
1005
  dynamicImportEndStack.push(statementEnd - 1);
813
1006
  lastIndex = start;
@@ -821,19 +1014,6 @@
821
1014
  .map(({ s, e, ln }) => `${source.slice(s, e)}:${ln}`)
822
1015
  .join(',')}})}catch(_){};\n`;
823
1016
 
824
- function pushSourceURL(commentPrefix, commentStart) {
825
- const urlStart = commentStart + commentPrefix.length;
826
- const commentEnd = source.indexOf('\n', urlStart);
827
- const urlEnd = commentEnd !== -1 ? commentEnd : source.length;
828
- let sourceUrl = source.slice(urlStart, urlEnd);
829
- try {
830
- sourceUrl = new URL(sourceUrl, load.r).href;
831
- } catch {}
832
- pushStringTo(urlStart);
833
- resolvedSource += sourceUrl;
834
- lastIndex = urlEnd;
835
- }
836
-
837
1017
  let sourceURLCommentStart = source.lastIndexOf(sourceURLCommentPrefix);
838
1018
  let sourceMapURLCommentStart = source.lastIndexOf(sourceMapURLCommentPrefix);
839
1019
 
@@ -846,23 +1026,23 @@
846
1026
  sourceURLCommentStart !== -1 &&
847
1027
  (sourceMapURLCommentStart === -1 || sourceMapURLCommentStart > sourceURLCommentStart)
848
1028
  ) {
849
- pushSourceURL(sourceURLCommentPrefix, sourceURLCommentStart);
1029
+ pushSourceURL(load, sourceURLCommentPrefix, sourceURLCommentStart, dynamicImportEndStack);
850
1030
  }
851
1031
  // sourceMappingURL
852
1032
  if (sourceMapURLCommentStart !== -1) {
853
- pushSourceURL(sourceMapURLCommentPrefix, sourceMapURLCommentStart);
1033
+ pushSourceURL(load, sourceMapURLCommentPrefix, sourceMapURLCommentStart, dynamicImportEndStack);
854
1034
  // sourceURL last
855
1035
  if (sourceURLCommentStart !== -1 && sourceURLCommentStart > sourceMapURLCommentStart)
856
- pushSourceURL(sourceURLCommentPrefix, sourceURLCommentStart);
1036
+ pushSourceURL(load, sourceURLCommentPrefix, sourceURLCommentStart, dynamicImportEndStack);
857
1037
  }
858
1038
 
859
- pushStringTo(source.length);
1039
+ pushStringTo(load, source.length, dynamicImportEndStack);
860
1040
 
861
1041
  if (sourceURLCommentStart === -1) resolvedSource += sourceURLCommentPrefix + load.r;
862
1042
 
863
1043
  load.b = createBlob(resolvedSource);
864
- load.S = undefined;
865
- }
1044
+ load.S = resolvedSource = undefined;
1045
+ };
866
1046
 
867
1047
  const sourceURLCommentPrefix = '\n//# sourceURL=';
868
1048
  const sourceMapURLCommentPrefix = '\n//# sourceMappingURL=';
@@ -878,15 +1058,15 @@
878
1058
  // restrict in-flight fetches to a pool of 100
879
1059
  let p = [];
880
1060
  let c = 0;
881
- function pushFetchPool() {
1061
+ const pushFetchPool = () => {
882
1062
  if (++c > 100) return new Promise(r => p.push(r));
883
- }
884
- function popFetchPool() {
1063
+ };
1064
+ const popFetchPool = () => {
885
1065
  c--;
886
1066
  if (p.length) p.shift()();
887
- }
1067
+ };
888
1068
 
889
- async function doFetch(url, fetchOpts, parent) {
1069
+ const doFetch = async (url, fetchOpts, parent) => {
890
1070
  if (enforceIntegrity && !fetchOpts.integrity) throw Error(`No integrity for ${url}${fromParent(parent)}.`);
891
1071
  const poolQueue = pushFetchPool();
892
1072
  if (poolQueue) await poolQueue;
@@ -905,15 +1085,16 @@
905
1085
  throw error;
906
1086
  }
907
1087
  return res;
908
- }
1088
+ };
909
1089
 
910
1090
  let esmsTsTransform;
911
- async function initTs() {
1091
+ const initTs = async () => {
912
1092
  const m = await import(tsTransform);
913
1093
  if (!esmsTsTransform) esmsTsTransform = m.transform;
914
- }
1094
+ };
915
1095
 
916
- async function fetchModule(url, fetchOpts, parent) {
1096
+ const hotPrefix = 'var h=import.meta.hot,';
1097
+ const fetchModule = async (url, fetchOpts, parent) => {
917
1098
  const mapIntegrity = composedImportMap.integrity[url];
918
1099
  const res = await doFetch(
919
1100
  url,
@@ -924,32 +1105,38 @@
924
1105
  const contentType = res.headers.get('content-type');
925
1106
  if (jsContentType.test(contentType)) return { r, s: await res.text(), t: 'js' };
926
1107
  else if (wasmContentType.test(contentType)) {
927
- const module = await (sourceCache[r] || (sourceCache[r] = WebAssembly.compileStreaming(res)));
928
- sourceCache[r] = module;
929
- let s = '',
1108
+ const wasmModule = await (sourceCache[r] || (sourceCache[r] = WebAssembly.compileStreaming(res)));
1109
+ const exports = WebAssembly.Module.exports(wasmModule);
1110
+ sourceCache[r] = wasmModule;
1111
+ const rStr = urlJsString(r);
1112
+ let s = `import*as $_ns from${rStr};`,
930
1113
  i = 0,
931
- importObj = '';
932
- for (const impt of WebAssembly.Module.imports(module)) {
933
- const specifier = urlJsString(impt.module);
934
- s += `import * as impt${i} from ${specifier};\n`;
935
- importObj += `${specifier}:impt${i++},`;
1114
+ obj = '';
1115
+ for (const { module, kind } of WebAssembly.Module.imports(wasmModule)) {
1116
+ const specifier = urlJsString(module);
1117
+ s += `import*as impt${i} from${specifier};\n`;
1118
+ obj += `${specifier}:${kind === 'global' ? `importShim._i.get(impt${i})||impt${i++}` : `impt${i++}`},`;
936
1119
  }
937
- i = 0;
938
- s += `const instance = await WebAssembly.instantiate(importShim._s[${urlJsString(r)}], {${importObj}});\n`;
939
- for (const expt of WebAssembly.Module.exports(module)) {
940
- s += `export const ${expt.name} = instance.exports['${expt.name}'];\n`;
1120
+ s += `${hotPrefix}i=await WebAssembly.instantiate(importShim._s[${rStr}],{${obj}});importShim._i.set($_ns,i);`;
1121
+ obj = '';
1122
+ for (const { name, kind } of exports) {
1123
+ s += `export let ${name}=i.exports['${name}'];`;
1124
+ if (kind === 'global') s += `try{${name}=${name}.value}catch{${name}=undefined}`;
1125
+ obj += `${name},`;
941
1126
  }
1127
+ s += `if(h)h.accept(m=>({${obj}}=m))`;
942
1128
  return { r, s, t: 'wasm' };
943
- } else if (jsonContentType.test(contentType)) return { r, s: `export default ${await res.text()}`, t: 'json' };
1129
+ } else if (jsonContentType.test(contentType))
1130
+ return { r, s: `${hotPrefix}j=${await res.text()};export{j as default};if(h)h.accept(m=>j=m.default)`, t: 'json' };
944
1131
  else if (cssContentType.test(contentType)) {
945
1132
  return {
946
1133
  r,
947
- s: `var s=new CSSStyleSheet();s.replaceSync(${JSON.stringify(
1134
+ s: `${hotPrefix}s=h&&h.data.s||new CSSStyleSheet();s.replaceSync(${JSON.stringify(
948
1135
  (await res.text()).replace(
949
1136
  cssUrlRegEx,
950
1137
  (_match, quotes = '', relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`
951
1138
  )
952
- )});export default s;`,
1139
+ )});if(h){h.data.s=s;h.accept(()=>{})}export default s`,
953
1140
  t: 'css'
954
1141
  };
955
1142
  } else if (tsContentType.test(contentType) || url.endsWith('.ts') || url.endsWith('.mts')) {
@@ -963,9 +1150,9 @@
963
1150
  throw Error(
964
1151
  `Unsupported Content-Type "${contentType}" loading ${url}${fromParent(parent)}. Modules must be served with a valid MIME type like application/javascript.`
965
1152
  );
966
- }
1153
+ };
967
1154
 
968
- function isUnsupportedType(type) {
1155
+ const isUnsupportedType = type => {
969
1156
  if (type === 'wasm' && !wasmInstancePhaseEnabled && !wasmSourcePhaseEnabled) throw featErr(`wasm-modules`);
970
1157
  return (
971
1158
  (type === 'css' && !supportsCssType) ||
@@ -973,13 +1160,13 @@
973
1160
  (type === 'wasm' && !supportsWasmInstancePhase && !supportsWasmSourcePhase) ||
974
1161
  type === 'ts'
975
1162
  );
976
- }
1163
+ };
977
1164
 
978
- function getOrCreateLoad(url, fetchOpts, parent, source) {
1165
+ const getOrCreateLoad = (url, fetchOpts, parent, source) => {
979
1166
  if (source && registry[url]) {
980
1167
  let i = 0;
981
- while (registry[url + ++i]);
982
- url += i;
1168
+ while (registry[url + '#' + ++i]);
1169
+ url += '#' + i;
983
1170
  }
984
1171
  let load = registry[url];
985
1172
  if (load) return load;
@@ -1028,14 +1215,14 @@
1028
1215
  return load;
1029
1216
  })();
1030
1217
  return load;
1031
- }
1218
+ };
1032
1219
 
1033
1220
  const featErr = feat =>
1034
1221
  Error(
1035
1222
  `${feat} feature must be enabled via <script type="esms-options">{ "polyfillEnable": ["${feat}"] }<${''}/script>`
1036
1223
  );
1037
1224
 
1038
- function linkLoad(load, fetchOpts) {
1225
+ const linkLoad = (load, fetchOpts) => {
1039
1226
  if (load.L) return;
1040
1227
  load.L = load.f.then(async () => {
1041
1228
  let childFetchOpts = fetchOpts;
@@ -1049,7 +1236,7 @@
1049
1236
  if (!sourcePhase || !supportsWasmSourcePhase) load.n = true;
1050
1237
  }
1051
1238
  let source = undefined;
1052
- if (a > 0 && !shimMode) {
1239
+ if (a > 0 && !shimMode && nativePassthrough) {
1053
1240
  const assertion = load.S.slice(a, se - 1);
1054
1241
  // no need to fetch JSON/CSS if supported, since it's a leaf node, we'll just strip the assertion syntax
1055
1242
  if (assertion.includes('json')) {
@@ -1076,9 +1263,9 @@
1076
1263
  })
1077
1264
  .filter(l => l);
1078
1265
  });
1079
- }
1266
+ };
1080
1267
 
1081
- function processScriptsAndPreloads() {
1268
+ const processScriptsAndPreloads = () => {
1082
1269
  for (const link of document.querySelectorAll(shimMode ? 'link[rel=modulepreload-shim]' : 'link[rel=modulepreload]')) {
1083
1270
  if (!link.ep) processPreload(link);
1084
1271
  }
@@ -1090,9 +1277,9 @@
1090
1277
  if (!script.ep) processScript(script);
1091
1278
  }
1092
1279
  }
1093
- }
1280
+ };
1094
1281
 
1095
- function getFetchOpts(script) {
1282
+ const getFetchOpts = script => {
1096
1283
  const fetchOpts = {};
1097
1284
  if (script.integrity) fetchOpts.integrity = script.integrity;
1098
1285
  if (script.referrerPolicy) fetchOpts.referrerPolicy = script.referrerPolicy;
@@ -1101,43 +1288,68 @@
1101
1288
  else if (script.crossOrigin === 'anonymous') fetchOpts.credentials = 'omit';
1102
1289
  else fetchOpts.credentials = 'same-origin';
1103
1290
  return fetchOpts;
1104
- }
1291
+ };
1105
1292
 
1106
1293
  let lastStaticLoadPromise = Promise.resolve();
1107
1294
 
1295
+ let domContentLoaded = false;
1108
1296
  let domContentLoadedCnt = 1;
1109
- function domContentLoadedCheck() {
1297
+ const domContentLoadedCheck = m => {
1298
+ if (m === undefined) {
1299
+ if (domContentLoaded) return;
1300
+ domContentLoaded = true;
1301
+ domContentLoadedCnt--;
1302
+ }
1110
1303
  if (--domContentLoadedCnt === 0 && !noLoadEventRetriggers && (shimMode || !baselinePassthrough)) {
1111
1304
  console.info(`es-module-shims: DOMContentLoaded refire`);
1305
+ document.removeEventListener('DOMContentLoaded', domContentLoadedEvent);
1112
1306
  document.dispatchEvent(new Event('DOMContentLoaded'));
1113
1307
  }
1114
- }
1308
+ };
1115
1309
  let loadCnt = 1;
1116
- function loadCheck() {
1310
+ const loadCheck = () => {
1117
1311
  if (--loadCnt === 0 && !noLoadEventRetriggers && (shimMode || !baselinePassthrough)) {
1118
1312
  console.info(`es-module-shims: load refire`);
1313
+ window.removeEventListener('load', loadEvent);
1119
1314
  window.dispatchEvent(new Event('load'));
1120
1315
  }
1121
- }
1316
+ };
1317
+
1318
+ const domContentLoadedEvent = async () => {
1319
+ await initPromise;
1320
+ domContentLoadedCheck();
1321
+ };
1322
+ const loadEvent = async () => {
1323
+ await initPromise;
1324
+ domContentLoadedCheck();
1325
+ loadCheck();
1326
+ };
1327
+
1122
1328
  // this should always trigger because we assume es-module-shims is itself a domcontentloaded requirement
1123
1329
  if (hasDocument) {
1124
- document.addEventListener('DOMContentLoaded', async () => {
1125
- await initPromise;
1126
- domContentLoadedCheck();
1127
- });
1128
- window.addEventListener('load', async () => {
1129
- await initPromise;
1130
- loadCheck();
1131
- });
1330
+ document.addEventListener('DOMContentLoaded', domContentLoadedEvent);
1331
+ window.addEventListener('load', loadEvent);
1132
1332
  }
1133
1333
 
1334
+ const readyListener = async () => {
1335
+ await initPromise;
1336
+ processScriptsAndPreloads();
1337
+ if (document.readyState === 'complete') {
1338
+ readyStateCompleteCheck();
1339
+ }
1340
+ };
1341
+
1134
1342
  let readyStateCompleteCnt = 1;
1135
- function readyStateCompleteCheck() {
1136
- if (--readyStateCompleteCnt === 0 && !noLoadEventRetriggers && (shimMode || !baselinePassthrough)) {
1137
- console.info(`es-module-shims: readystatechange complete refire`);
1138
- document.dispatchEvent(new Event('readystatechange'));
1343
+ const readyStateCompleteCheck = () => {
1344
+ if (--readyStateCompleteCnt === 0) {
1345
+ domContentLoadedCheck();
1346
+ if (!noLoadEventRetriggers && (shimMode || !baselinePassthrough)) {
1347
+ console.info(`es-module-shims: readystatechange complete refire`);
1348
+ document.removeEventListener('readystatechange', readyListener);
1349
+ document.dispatchEvent(new Event('readystatechange'));
1350
+ }
1139
1351
  }
1140
- }
1352
+ };
1141
1353
 
1142
1354
  const hasNext = script => script.nextSibling || (script.parentNode && hasNext(script.parentNode));
1143
1355
  const epCheck = (script, ready) =>
@@ -1146,7 +1358,7 @@
1146
1358
  script.getAttribute('noshim') !== null ||
1147
1359
  !(script.ep = true);
1148
1360
 
1149
- function processImportMap(script, ready = readyStateCompleteCnt > 0) {
1361
+ const processImportMap = (script, ready = readyStateCompleteCnt > 0) => {
1150
1362
  if (epCheck(script, ready)) return;
1151
1363
  console.info(`es-module-shims: reading import map`);
1152
1364
  // we dont currently support external import maps in polyfill mode to match native
@@ -1177,9 +1389,9 @@
1177
1389
  }
1178
1390
  }
1179
1391
  legacyAcceptingImportMaps = false;
1180
- }
1392
+ };
1181
1393
 
1182
- function processScript(script, ready = readyStateCompleteCnt > 0) {
1394
+ const processScript = (script, ready = readyStateCompleteCnt > 0) => {
1183
1395
  if (epCheck(script, ready)) return;
1184
1396
  console.info(`es-module-shims: checking script ${script.src || '<inline>'}`);
1185
1397
  // does this load block readystate complete
@@ -1202,22 +1414,24 @@
1202
1414
  }
1203
1415
  return topLevelLoad(
1204
1416
  script.src || baseUrl,
1417
+ baseUrl,
1205
1418
  getFetchOpts(script),
1206
1419
  transformed === undefined ? script.innerHTML : transformed,
1207
1420
  !shimMode && transformed === undefined,
1208
1421
  isBlockingReadyScript && lastStaticLoadPromise,
1209
- true
1422
+ 'ts'
1210
1423
  );
1211
1424
  })
1212
1425
  .catch(throwError);
1213
1426
  } else {
1214
1427
  loadPromise = topLevelLoad(
1215
1428
  script.src || baseUrl,
1429
+ baseUrl,
1216
1430
  getFetchOpts(script),
1217
1431
  !script.src ? script.innerHTML : undefined,
1218
1432
  !shimMode,
1219
1433
  isBlockingReadyScript && lastStaticLoadPromise,
1220
- ts
1434
+ ts ? 'ts' : undefined
1221
1435
  ).catch(throwError);
1222
1436
  }
1223
1437
  if (!noLoadEventRetriggers) loadPromise.then(() => script.dispatchEvent(new Event('load')));
@@ -1226,13 +1440,19 @@
1226
1440
  }
1227
1441
  if (isDomContentLoadedScript) loadPromise.then(domContentLoadedCheck);
1228
1442
  if (isLoadScript) loadPromise.then(loadCheck);
1229
- }
1443
+ };
1230
1444
 
1231
1445
  const fetchCache = {};
1232
- function processPreload(link) {
1446
+ const processPreload = link => {
1233
1447
  link.ep = true;
1234
1448
  if (fetchCache[link.href]) return;
1235
1449
  fetchCache[link.href] = fetchModule(link.href, getFetchOpts(link));
1236
- }
1450
+ };
1451
+
1452
+ exports.topLevelLoad = topLevelLoad;
1453
+
1454
+ Object.defineProperty(exports, '__esModule', { value: true });
1455
+
1456
+ return exports;
1237
1457
 
1238
- })();
1458
+ })({});