es-module-shims 2.2.0 → 2.3.0

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,111 +1,279 @@
1
- /* ES Module Shims 2.2.0 */
1
+ /** ES Module Shims 2.3.0 */
2
2
  (function () {
3
3
 
4
- const hasDocument = typeof document !== 'undefined';
5
-
6
- const noop = () => {};
7
-
8
- const dynamicImport = (u, errUrl) => import(u);
9
-
10
- const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
11
-
12
- const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
13
- Object.assign(esmsInitOptions, self.esmsInitOptions || {});
14
-
15
- // shim mode is determined on initialization, no late shim mode
16
- 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 ||
29
- (hasDocument &&
30
- document.currentScript &&
31
- document.currentScript.src.replace(/\.js$/, '-typescript.js')) ||
32
- './es-module-shims-typescript.js';
33
-
34
- const mapOverrides = esmsInitOptions.mapOverrides;
35
-
36
- let nonce = esmsInitOptions.nonce;
37
- if (!nonce && hasDocument) {
38
- const nonceElement = document.querySelector('script[nonce]');
39
- if (nonceElement) nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
40
- }
41
-
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
- }
49
-
50
- const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
51
- const enableAll = esmsInitOptions.polyfillEnable === 'all' || enable.includes('all');
52
- const wasmInstancePhaseEnabled =
53
- enable.includes('wasm-modules') || enable.includes('wasm-module-instances') || enableAll;
54
- const wasmSourcePhaseEnabled =
55
- enable.includes('wasm-modules') || enable.includes('wasm-module-sources') || enableAll;
56
- const deferPhaseEnabled = enable.includes('import-defer') || enableAll;
57
-
58
- const onpolyfill =
59
- esmsInitOptions.onpolyfill ?
60
- globalHook(esmsInitOptions.onpolyfill)
61
- : () => {
62
- console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
63
- };
64
-
65
- const baseUrl =
66
- hasDocument ?
67
- document.baseURI
68
- : `${location.protocol}//${location.host}${
69
- location.pathname.includes('/') ?
70
- location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
71
- : location.pathname
72
- }`;
73
-
74
- const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
75
- let { skip } = esmsInitOptions;
76
- if (Array.isArray(skip)) {
77
- const l = skip.map(s => new URL(s, baseUrl).href);
78
- skip = s => l.some(i => (i[i.length - 1] === '/' && s.startsWith(i)) || s === i);
79
- } else if (typeof skip === 'string') {
80
- const r = new RegExp(skip);
81
- skip = s => r.test(s);
82
- } else if (skip instanceof RegExp) {
83
- skip = s => skip.test(s);
84
- }
85
-
86
- const dispatchError = error => self.dispatchEvent(Object.assign(new Event('error'), { error }));
87
-
88
- const throwError = err => {
89
- (self.reportError || dispatchError)(err), void onerror(err);
90
- };
91
-
92
- function fromParent(parent) {
93
- return parent ? ` imported from ${parent}` : '';
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 => {
21
+ getHotState(url).e = true;
22
+ };
23
+ const hotMetaHook = (metaObj, url) => {
24
+ metaObj.hot = new Hot(url);
25
+ };
26
+
27
+ const Hot = class Hot {
28
+ constructor(url) {
29
+ this.data = getHotState((this.url = stripVersion(url))).d;
30
+ }
31
+ accept(deps, cb) {
32
+ if (typeof deps === 'function') {
33
+ cb = deps;
34
+ deps = null;
35
+ }
36
+ const hotState = getHotState(this.url);
37
+ if (!hotState.A) return;
38
+ (hotState.a = hotState.a || []).push([
39
+ typeof deps === 'string' ? defaultResolve(deps, this.url)
40
+ : deps ? deps.map(d => defaultResolve(d, this.url))
41
+ : null,
42
+ cb
43
+ ]);
44
+ }
45
+ dispose(cb) {
46
+ getHotState(this.url).u = cb;
47
+ }
48
+ invalidate() {
49
+ const hotState = getHotState(this.url);
50
+ hotState.a = null;
51
+ hotState.A = true;
52
+ const seen = [this.url];
53
+ for (const p of hotState.p) invalidate(p, this.url, seen);
54
+ }
55
+ };
56
+
57
+ const versionedRegEx = /\?v=\d+$/;
58
+ const stripVersion = url => {
59
+ const versionMatch = url.match(versionedRegEx);
60
+ return versionMatch ? url.slice(0, -versionMatch[0].length) : url;
61
+ };
62
+
63
+ const toVersioned = url => {
64
+ const v = getHotState(url).v;
65
+ return url + (v ? '?v=' + v : '');
66
+ };
67
+
68
+ let hotRegistry = {},
69
+ curInvalidationRoots = new Set(),
70
+ curInvalidationInterval;
71
+ const getHotState = url =>
72
+ hotRegistry[url] ||
73
+ (hotRegistry[url] = {
74
+ // version
75
+ v: 0,
76
+ // accept list ([deps, cb] pairs)
77
+ a: null,
78
+ // accepting acceptors
79
+ A: true,
80
+ // unload callback
81
+ u: null,
82
+ // entry point
83
+ e: false,
84
+ // hot data
85
+ d: {},
86
+ // parents
87
+ p: []
88
+ });
89
+
90
+ invalidate = (url, fromUrl, seen = []) => {
91
+ if (!seen.includes(url)) {
92
+ seen.push(url);
93
+ const hotState = hotRegistry[url];
94
+ if (hotState) {
95
+ hotState.A = false;
96
+ if (
97
+ hotState.a &&
98
+ hotState.a.some(([d]) => d && (typeof d === 'string' ? d === fromUrl : d.includes(fromUrl)))
99
+ ) {
100
+ curInvalidationRoots.add(fromUrl);
101
+ } else {
102
+ if (hotState.e || hotState.a) curInvalidationRoots.add(url);
103
+ hotState.v++;
104
+ if (!hotState.a) for (const parent of hotState.p) invalidate(parent, url, seen);
105
+ }
106
+ }
107
+ }
108
+ if (!curInvalidationInterval)
109
+ curInvalidationInterval = setTimeout(() => {
110
+ curInvalidationInterval = null;
111
+ const earlyRoots = new Set();
112
+ for (const root of curInvalidationRoots) {
113
+ const hotState = hotRegistry[root];
114
+ importShim(toVersioned(root)).then(m => {
115
+ if (hotState.a) {
116
+ hotState.a.every(([d, c]) => d === null && !earlyRoots.has(c) && c(m));
117
+ // unload should be the latest unload handler from the just loaded module
118
+ if (hotState.u) {
119
+ hotState.u(hotState.d);
120
+ hotState.u = null;
121
+ }
122
+ }
123
+ for (const parent of hotState.p) {
124
+ const hotState = hotRegistry[parent];
125
+ if (hotState && hotState.a)
126
+ hotState.a.every(async ([d, c]) => {
127
+ return (
128
+ d &&
129
+ !earlyRoots.has(c) &&
130
+ (typeof d === 'string' ?
131
+ d === root && c(m)
132
+ : c(await Promise.all(d.map(d => (earlyRoots.push(c), importShim(toVersioned(d)))))))
133
+ );
134
+ });
135
+ }
136
+ }, noop);
137
+ }
138
+ curInvalidationRoots = new Set();
139
+ }, hotReloadInterval);
140
+ };
141
+
142
+ return [
143
+ _importHook ?
144
+ (url, opts, parentUrl) => {
145
+ _importHook(url, opts, parentUrl);
146
+ hotImportHook(url);
147
+ }
148
+ : hotImportHook,
149
+ _resolveHook ?
150
+ (id, parent, defaultResolve) =>
151
+ hotResolveHook(id, parent, (id, parent) => _resolveHook(id, parent, defaultResolve))
152
+ : hotResolveHook,
153
+ _metaHook ?
154
+ (metaObj, url) => {
155
+ _metaHook(metaObj, url);
156
+ hotMetaHook(metaObj, url);
157
+ }
158
+ : hotMetaHook
159
+ ];
160
+ };
161
+
162
+ if (self.importShim) {
163
+ return;
164
+ }
165
+
166
+ const hasDocument = typeof document !== 'undefined';
167
+
168
+ const noop = () => {};
169
+
170
+ const dynamicImport = (u, errUrl) => import(u);
171
+
172
+ const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
173
+
174
+ const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
175
+ Object.assign(esmsInitOptions, self.esmsInitOptions || {});
176
+
177
+ // shim mode is determined on initialization, no late shim mode
178
+ const shimMode =
179
+ esmsInitOptions.shimMode ||
180
+ (hasDocument &&
181
+ document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
182
+ .length > 0);
183
+
184
+ let importHook,
185
+ resolveHook,
186
+ fetchHook = fetch,
187
+ metaHook = noop,
188
+ tsTransform =
189
+ (hasDocument && document.currentScript && document.currentScript.src.replace(/(\.\w+)?\.js$/, '-typescript.js')) ||
190
+ './es-module-shims-typescript.js';
191
+
192
+ const {
193
+ revokeBlobURLs,
194
+ noLoadEventRetriggers,
195
+ enforceIntegrity,
196
+ hotReload,
197
+ hotReloadInterval = 100,
198
+ nativePassthrough = !hotReload
199
+ } = esmsInitOptions;
200
+
201
+ const globalHook = name => (typeof name === 'string' ? self[name] : name);
202
+
203
+ if (esmsInitOptions.onimport) importHook = globalHook(esmsInitOptions.onimport);
204
+ if (esmsInitOptions.resolve) resolveHook = globalHook(esmsInitOptions.resolve);
205
+ if (esmsInitOptions.fetch) fetchHook = globalHook(esmsInitOptions.fetch);
206
+ if (esmsInitOptions.meta) metaHook = globalHook(esmsInitOptions.meta);
207
+ if (esmsInitOptions.tsTransform) tsTransform = globalHook(esmsInitOptions.tsTransform);
208
+
209
+ if (hotReload) [importHook, resolveHook, metaHook] = initHotReload();
210
+
211
+ const mapOverrides = esmsInitOptions.mapOverrides;
212
+
213
+ let nonce = esmsInitOptions.nonce;
214
+ if (!nonce && hasDocument) {
215
+ const nonceElement = document.querySelector('script[nonce]');
216
+ if (nonceElement) nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
217
+ }
218
+
219
+ const onerror = globalHook(esmsInitOptions.onerror || noop);
220
+
221
+ const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
222
+ const enableAll = esmsInitOptions.polyfillEnable === 'all' || enable.includes('all');
223
+ const wasmInstancePhaseEnabled =
224
+ enable.includes('wasm-modules') || enable.includes('wasm-module-instances') || enableAll;
225
+ const wasmSourcePhaseEnabled =
226
+ enable.includes('wasm-modules') || enable.includes('wasm-module-sources') || enableAll;
227
+ const deferPhaseEnabled = enable.includes('import-defer') || enableAll;
228
+
229
+ const onpolyfill =
230
+ esmsInitOptions.onpolyfill ?
231
+ globalHook(esmsInitOptions.onpolyfill)
232
+ : () => {
233
+ console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
234
+ };
235
+
236
+ const baseUrl =
237
+ hasDocument ?
238
+ document.baseURI
239
+ : `${location.protocol}//${location.host}${
240
+ location.pathname.includes('/') ?
241
+ location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
242
+ : location.pathname
243
+ }`;
244
+
245
+ const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
246
+ let { skip } = esmsInitOptions;
247
+ if (Array.isArray(skip)) {
248
+ const l = skip.map(s => new URL(s, baseUrl).href);
249
+ skip = s => l.some(i => (i[i.length - 1] === '/' && s.startsWith(i)) || s === i);
250
+ } else if (typeof skip === 'string') {
251
+ const r = new RegExp(skip);
252
+ skip = s => r.test(s);
253
+ } else if (skip instanceof RegExp) {
254
+ skip = s => skip.test(s);
94
255
  }
95
256
 
257
+ const dispatchError = error => self.dispatchEvent(Object.assign(new Event('error'), { error }));
258
+
259
+ const throwError = err => {
260
+ (self.reportError || dispatchError)(err), void onerror(err);
261
+ };
262
+
263
+ const fromParent = parent => (parent ? ` imported from ${parent}` : '');
264
+
96
265
  const backslashRegEx = /\\/g;
97
266
 
98
- function asURL(url) {
267
+ const asURL = url => {
99
268
  try {
100
269
  if (url.indexOf(':') !== -1) return new URL(url).href;
101
270
  } catch (_) {}
102
- }
271
+ };
103
272
 
104
- function resolveUrl(relUrl, parentUrl) {
105
- return resolveIfNotPlainOrUrl(relUrl, parentUrl) || asURL(relUrl) || resolveIfNotPlainOrUrl('./' + relUrl, parentUrl);
106
- }
273
+ const resolveUrl = (relUrl, parentUrl) =>
274
+ resolveIfNotPlainOrUrl(relUrl, parentUrl) || asURL(relUrl) || resolveIfNotPlainOrUrl('./' + relUrl, parentUrl);
107
275
 
108
- function resolveIfNotPlainOrUrl(relUrl, parentUrl) {
276
+ const resolveIfNotPlainOrUrl = (relUrl, parentUrl) => {
109
277
  const hIdx = parentUrl.indexOf('#'),
110
278
  qIdx = parentUrl.indexOf('?');
111
279
  if (hIdx + qIdx > -2)
@@ -193,9 +361,9 @@
193
361
  if (segmentIndex !== -1) output.push(segmented.slice(segmentIndex));
194
362
  return parentUrl.slice(0, parentUrl.length - pathname.length) + output.join('');
195
363
  }
196
- }
364
+ };
197
365
 
198
- function resolveAndComposeImportMap(json, baseUrl, parentMap) {
366
+ const resolveAndComposeImportMap = (json, baseUrl, parentMap) => {
199
367
  const outMap = {
200
368
  imports: Object.assign({}, parentMap.imports),
201
369
  scopes: Object.assign({}, parentMap.scopes),
@@ -218,27 +386,27 @@
218
386
  if (json.integrity) resolveAndComposeIntegrity(json.integrity, outMap.integrity, baseUrl);
219
387
 
220
388
  return outMap;
221
- }
389
+ };
222
390
 
223
- function getMatch(path, matchObj) {
391
+ const getMatch = (path, matchObj) => {
224
392
  if (matchObj[path]) return path;
225
393
  let sepIndex = path.length;
226
394
  do {
227
395
  const segment = path.slice(0, sepIndex + 1);
228
396
  if (segment in matchObj) return segment;
229
397
  } while ((sepIndex = path.lastIndexOf('/', sepIndex - 1)) !== -1);
230
- }
398
+ };
231
399
 
232
- function applyPackages(id, packages) {
400
+ const applyPackages = (id, packages) => {
233
401
  const pkgName = getMatch(id, packages);
234
402
  if (pkgName) {
235
403
  const pkg = packages[pkgName];
236
404
  if (pkg === null) return;
237
405
  return pkg + id.slice(pkgName.length);
238
406
  }
239
- }
407
+ };
240
408
 
241
- function resolveImportMap(importMap, resolvedOrPlain, parentUrl) {
409
+ const resolveImportMap = (importMap, resolvedOrPlain, parentUrl) => {
242
410
  let scopeUrl = parentUrl && getMatch(parentUrl, importMap.scopes);
243
411
  while (scopeUrl) {
244
412
  const packageResolution = applyPackages(resolvedOrPlain, importMap.scopes[scopeUrl]);
@@ -246,9 +414,9 @@
246
414
  scopeUrl = getMatch(scopeUrl.slice(0, scopeUrl.lastIndexOf('/')), importMap.scopes);
247
415
  }
248
416
  return applyPackages(resolvedOrPlain, importMap.imports) || (resolvedOrPlain.indexOf(':') !== -1 && resolvedOrPlain);
249
- }
417
+ };
250
418
 
251
- function resolveAndComposePackages(packages, outPackages, baseUrl, parentMap) {
419
+ const resolveAndComposePackages = (packages, outPackages, baseUrl, parentMap) => {
252
420
  for (let p in packages) {
253
421
  const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
254
422
  if (
@@ -270,9 +438,9 @@
270
438
  }
271
439
  console.warn(`es-module-shims: Mapping "${p}" -> "${packages[p]}" does not resolve`);
272
440
  }
273
- }
441
+ };
274
442
 
275
- function resolveAndComposeIntegrity(integrity, outIntegrity, baseUrl) {
443
+ const resolveAndComposeIntegrity = (integrity, outIntegrity, baseUrl) => {
276
444
  for (let p in integrity) {
277
445
  const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
278
446
  if (
@@ -286,122 +454,122 @@
286
454
  }
287
455
  outIntegrity[resolvedLhs] = integrity[p];
288
456
  }
289
- }
457
+ };
290
458
 
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
- });
459
+ // support browsers without dynamic import support (eg Firefox 6x)
460
+ let supportsJsonType = false;
461
+ let supportsCssType = false;
462
+
463
+ const supports = hasDocument && HTMLScriptElement.supports;
464
+
465
+ let supportsImportMaps = supports && supports.name === 'supports' && supports('importmap');
466
+ let supportsWasmInstancePhase = false;
467
+ let supportsWasmSourcePhase = false;
468
+ let supportsMultipleImportMaps = false;
469
+
470
+ const wasmBytes = [0, 97, 115, 109, 1, 0, 0, 0];
471
+
472
+ let featureDetectionPromise = (async function () {
473
+ if (!hasDocument)
474
+ return Promise.all([
475
+ import(createBlob(`import"${createBlob('{}', 'text/json')}"with{type:"json"}`)).then(
476
+ () => (
477
+ (supportsJsonType = true),
478
+ import(createBlob(`import"${createBlob('', 'text/css')}"with{type:"css"}`)).then(
479
+ () => (supportsCssType = true),
480
+ noop
481
+ )
482
+ ),
483
+ noop
484
+ ),
485
+ wasmInstancePhaseEnabled &&
486
+ import(createBlob(`import"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
487
+ () => (supportsWasmInstancePhase = true),
488
+ noop
489
+ ),
490
+ wasmSourcePhaseEnabled &&
491
+ import(createBlob(`import source x from"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
492
+ () => (supportsWasmSourcePhase = true),
493
+ noop
494
+ )
495
+ ]);
496
+
497
+ return new Promise(resolve => {
498
+ const iframe = document.createElement('iframe');
499
+ iframe.style.display = 'none';
500
+ iframe.setAttribute('nonce', nonce);
501
+ function cb({ data }) {
502
+ const isFeatureDetectionMessage = Array.isArray(data) && data[0] === 'esms';
503
+ if (!isFeatureDetectionMessage) return;
504
+ [
505
+ ,
506
+ supportsImportMaps,
507
+ supportsMultipleImportMaps,
508
+ supportsJsonType,
509
+ supportsCssType,
510
+ supportsWasmSourcePhase,
511
+ supportsWasmInstancePhase
512
+ ] = data;
513
+ resolve();
514
+ document.head.removeChild(iframe);
515
+ window.removeEventListener('message', cb, false);
516
+ }
517
+ window.addEventListener('message', cb, false);
518
+
519
+ // 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.
520
+ 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=${
521
+ supportsImportMaps ? `c(b(\`import"\${b('{}','text/json')}"with{type:"json"}\`))` : 'false'
522
+ };sp=${
523
+ supportsImportMaps && wasmSourcePhaseEnabled ?
524
+ `c(b(\`import source x from "\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))`
525
+ : 'false'
526
+ };Promise.all([${supportsImportMaps ? 'true' : "c('x')"},${supportsImportMaps ? "c('y')" : false},cm,${
527
+ supportsImportMaps ? `cm.then(s=>s?c(b(\`import"\${b('','text/css')\}"with{type:"css"}\`)):false)` : 'false'
528
+ },sp,${
529
+ supportsImportMaps && wasmInstancePhaseEnabled ?
530
+ `${wasmSourcePhaseEnabled ? 'sp.then(s=>s?' : ''}c(b(\`import"\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))${wasmSourcePhaseEnabled ? ':false)' : ''}`
531
+ : 'false'
532
+ }]).then(a=>parent.postMessage(['esms'].concat(a),'*'))<${''}/script>`;
533
+
534
+ // Safari will call onload eagerly on head injection, but we don't want the Wechat
535
+ // path to trigger before setting srcdoc, therefore we track the timing
536
+ let readyForOnload = false,
537
+ onloadCalledWhileNotReady = false;
538
+ function doOnload() {
539
+ if (!readyForOnload) {
540
+ onloadCalledWhileNotReady = true;
541
+ return;
542
+ }
543
+ // WeChat browser doesn't support setting srcdoc scripts
544
+ // But iframe sandboxes don't support contentDocument so we do this as a fallback
545
+ const doc = iframe.contentDocument;
546
+ if (doc && doc.head.childNodes.length === 0) {
547
+ const s = doc.createElement('script');
548
+ if (nonce) s.setAttribute('nonce', nonce);
549
+ s.innerHTML = importMapTest.slice(15 + (nonce ? nonce.length : 0), -9);
550
+ doc.head.appendChild(s);
551
+ }
552
+ }
553
+
554
+ iframe.onload = doOnload;
555
+ // WeChat browser requires append before setting srcdoc
556
+ document.head.appendChild(iframe);
557
+
558
+ // setting srcdoc is not supported in React native webviews on iOS
559
+ // setting src to a blob URL results in a navigation event in webviews
560
+ // document.write gives usability warnings
561
+ readyForOnload = true;
562
+ if ('srcdoc' in iframe) iframe.srcdoc = importMapTest;
563
+ else iframe.contentDocument.write(importMapTest);
564
+ // retrigger onload for Safari only if necessary
565
+ if (onloadCalledWhileNotReady) doOnload();
566
+ });
399
567
  })();
400
568
 
401
569
  /* es-module-lexer 1.7.0 */
402
570
  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})}
403
571
 
404
- function _resolve(id, parentUrl = baseUrl) {
572
+ const _resolve = (id, parentUrl = baseUrl) => {
405
573
  const urlResolved = resolveIfNotPlainOrUrl(id, parentUrl) || asURL(id);
406
574
  const firstResolved = firstImportMap && resolveImportMap(firstImportMap, urlResolved || id, parentUrl);
407
575
  const composedResolved =
@@ -424,97 +592,103 @@
424
592
  if (firstResolved && resolved !== firstResolved) N = true;
425
593
  }
426
594
  return { r: resolved, n, N };
427
- }
595
+ };
428
596
 
429
- const resolve =
430
- resolveHook ?
431
- (id, parentUrl = baseUrl) => {
432
- const result = resolveHook(id, parentUrl, defaultResolve);
433
- return result ? { r: result, n: true, N: true } : _resolve(id, parentUrl);
434
- }
435
- : _resolve;
597
+ const resolve = (id, parentUrl) => {
598
+ if (!resolveHook) return _resolve(id, parentUrl);
599
+ const result = resolveHook(id, parentUrl, defaultResolve);
436
600
 
437
- async function importHandler(id, opts, parentUrl = baseUrl, sourcePhase) {
438
- await initPromise; // needed for shim check
439
- if (importHook) await importHook(id, opts, parentUrl);
440
- if (shimMode || !baselinePassthrough) {
441
- if (hasDocument) processScriptsAndPreloads();
442
- legacyAcceptingImportMaps = false;
443
- }
444
- await importMapPromise;
445
- return resolve(id, parentUrl).r;
446
- }
601
+ return result ? { r: result, n: true, N: true } : _resolve(id, parentUrl);
602
+ };
447
603
 
448
604
  // import()
449
- async function importShim(id, opts, parentUrl) {
605
+ async function importShim$1(id, opts, parentUrl) {
450
606
  if (typeof opts === 'string') {
451
607
  parentUrl = opts;
452
608
  opts = undefined;
453
609
  }
454
- // we mock import('./x.css', { with: { type: 'css' }}) support via an inline static reexport
455
- // because we can't syntactically pass through to dynamic import with a second argument
456
- let url = await importHandler(id, opts, parentUrl);
457
- let source = undefined;
458
- let ts = false;
610
+ await initPromise; // needed for shim check
611
+ if (shimMode || !baselinePassthrough) {
612
+ if (hasDocument) processScriptsAndPreloads();
613
+ legacyAcceptingImportMaps = false;
614
+ }
615
+ let sourceType = undefined;
459
616
  if (typeof opts === 'object') {
460
- ts = opts.lang === 'ts';
617
+ if (opts.lang === 'ts') sourceType = 'ts';
461
618
  if (typeof opts.with === 'object' && typeof opts.with.type === 'string') {
462
- source = `export{default}from'${url}'with{type:"${opts.with.type}"}`;
463
- url += '?entry';
619
+ sourceType = opts.with.type;
464
620
  }
465
621
  }
466
- return topLevelLoad(url, { credentials: 'same-origin' }, source, undefined, undefined, ts);
622
+ return topLevelLoad(
623
+ id,
624
+ parentUrl || baseUrl,
625
+ { credentials: 'same-origin' },
626
+ undefined,
627
+ undefined,
628
+ undefined,
629
+ sourceType
630
+ );
467
631
  }
468
632
 
469
633
  // import.source()
470
634
  // (opts not currently supported as no use cases yet)
471
635
  if (shimMode || wasmSourcePhaseEnabled)
472
- importShim.source = async function (specifier, opts, parentUrl) {
636
+ importShim$1.source = async (id, opts, parentUrl) => {
473
637
  if (typeof opts === 'string') {
474
638
  parentUrl = opts;
475
639
  opts = undefined;
476
640
  }
477
- const url = await importHandler(specifier, opts, parentUrl);
641
+ await initPromise; // needed for shim check
642
+ if (shimMode || !baselinePassthrough) {
643
+ if (hasDocument) processScriptsAndPreloads();
644
+ legacyAcceptingImportMaps = false;
645
+ }
646
+ await importMapPromise;
647
+ const url = resolve(id, parentUrl || baseUrl).r;
478
648
  const load = getOrCreateLoad(url, { credentials: 'same-origin' }, undefined, undefined);
479
649
  if (firstPolyfillLoad && !shimMode && load.n && nativelyLoaded) {
480
650
  onpolyfill();
481
651
  firstPolyfillLoad = false;
482
652
  }
483
653
  await load.f;
484
- return importShim._s[load.r];
654
+ return importShim$1._s[load.r];
485
655
  };
486
656
 
487
657
  // import.defer() is just a proxy for import(), since we can't actually defer
488
- if (shimMode || deferPhaseEnabled) importShim.defer = importShim;
658
+ if (shimMode || deferPhaseEnabled) importShim$1.defer = importShim$1;
659
+
660
+ if (hotReload) importShim$1.hotReload = hotReload$1;
489
661
 
490
- self.importShim = importShim;
662
+ self.importShim = importShim$1;
491
663
 
492
- function defaultResolve(id, parentUrl) {
664
+ const defaultResolve = (id, parentUrl) => {
493
665
  return (
494
666
  resolveImportMap(composedImportMap, resolveIfNotPlainOrUrl(id, parentUrl) || id, parentUrl) ||
495
667
  throwUnresolved(id, parentUrl)
496
668
  );
497
- }
669
+ };
498
670
 
499
- function throwUnresolved(id, parentUrl) {
671
+ const throwUnresolved = (id, parentUrl) => {
500
672
  throw Error(`Unable to resolve specifier '${id}'${fromParent(parentUrl)}`);
501
- }
673
+ };
502
674
 
503
- function metaResolve(id, parentUrl = this.url) {
675
+ const metaResolve = function (id, parentUrl = this.url) {
504
676
  return resolve(id, `${parentUrl}`).r;
505
- }
677
+ };
506
678
 
507
- importShim.resolve = (id, parentUrl) => resolve(id, parentUrl).r;
508
- importShim.getImportMap = () => JSON.parse(JSON.stringify(composedImportMap));
509
- importShim.addImportMap = importMapIn => {
679
+ importShim$1.resolve = (id, parentUrl) => resolve(id, parentUrl).r;
680
+ importShim$1.getImportMap = () => JSON.parse(JSON.stringify(composedImportMap));
681
+ importShim$1.addImportMap = importMapIn => {
510
682
  if (!shimMode) throw new Error('Unsupported in polyfill mode.');
511
683
  composedImportMap = resolveAndComposeImportMap(importMapIn, baseUrl, composedImportMap);
512
684
  };
513
685
 
514
- const registry = (importShim._r = {});
515
- const sourceCache = (importShim._s = {});
686
+ const registry = (importShim$1._r = {});
687
+ // Wasm caches
688
+ const sourceCache = (importShim$1._s = {});
689
+ (importShim$1._i = new WeakMap());
516
690
 
517
- async function loadAll(load, seen) {
691
+ const loadAll = async (load, seen) => {
518
692
  seen[load.u] = 1;
519
693
  await load.L;
520
694
  await Promise.all(
@@ -524,7 +698,7 @@
524
698
  return loadAll(dep, seen);
525
699
  })
526
700
  );
527
- }
701
+ };
528
702
 
529
703
  let importMapSrc = false;
530
704
  let multipleImportMaps = false;
@@ -544,35 +718,32 @@
544
718
  !deferPhaseEnabled &&
545
719
  (!multipleImportMaps || supportsMultipleImportMaps) &&
546
720
  !importMapSrc;
547
- if (
548
- !shimMode &&
549
- wasmSourcePhaseEnabled &&
550
- typeof WebAssembly !== 'undefined' &&
551
- !Object.getPrototypeOf(WebAssembly.Module).name
552
- ) {
553
- const s = Symbol();
554
- const brand = m =>
555
- Object.defineProperty(m, s, { writable: false, configurable: false, value: 'WebAssembly.Module' });
556
- class AbstractModuleSource {
557
- get [Symbol.toStringTag]() {
558
- if (this[s]) return this[s];
559
- throw new TypeError('Not an AbstractModuleSource');
721
+ if (!shimMode && typeof WebAssembly !== 'undefined') {
722
+ if (wasmSourcePhaseEnabled && !Object.getPrototypeOf(WebAssembly.Module).name) {
723
+ const s = Symbol();
724
+ const brand = m =>
725
+ Object.defineProperty(m, s, { writable: false, configurable: false, value: 'WebAssembly.Module' });
726
+ class AbstractModuleSource {
727
+ get [Symbol.toStringTag]() {
728
+ if (this[s]) return this[s];
729
+ throw new TypeError('Not an AbstractModuleSource');
730
+ }
560
731
  }
732
+ const { Module: wasmModule, compile: wasmCompile, compileStreaming: wasmCompileStreaming } = WebAssembly;
733
+ WebAssembly.Module = Object.setPrototypeOf(
734
+ Object.assign(function Module(...args) {
735
+ return brand(new wasmModule(...args));
736
+ }, wasmModule),
737
+ AbstractModuleSource
738
+ );
739
+ WebAssembly.Module.prototype = Object.setPrototypeOf(wasmModule.prototype, AbstractModuleSource.prototype);
740
+ WebAssembly.compile = function compile(...args) {
741
+ return wasmCompile(...args).then(brand);
742
+ };
743
+ WebAssembly.compileStreaming = function compileStreaming(...args) {
744
+ return wasmCompileStreaming(...args).then(brand);
745
+ };
561
746
  }
562
- const { Module: wasmModule, compile: wasmCompile, compileStreaming: wasmCompileStreaming } = WebAssembly;
563
- WebAssembly.Module = Object.setPrototypeOf(
564
- Object.assign(function Module(...args) {
565
- return brand(new wasmModule(...args));
566
- }, wasmModule),
567
- AbstractModuleSource
568
- );
569
- WebAssembly.Module.prototype = Object.setPrototypeOf(wasmModule.prototype, AbstractModuleSource.prototype);
570
- WebAssembly.compile = function compile(...args) {
571
- return wasmCompile(...args).then(brand);
572
- };
573
- WebAssembly.compileStreaming = function compileStreaming(...args) {
574
- return wasmCompileStreaming(...args).then(brand);
575
- };
576
747
  }
577
748
  if (hasDocument) {
578
749
  if (!supportsImportMaps) {
@@ -584,14 +755,6 @@
584
755
  if (document.readyState === 'complete') {
585
756
  readyStateCompleteCheck();
586
757
  } else {
587
- async function readyListener() {
588
- await initPromise;
589
- processScriptsAndPreloads();
590
- if (document.readyState === 'complete') {
591
- readyStateCompleteCheck();
592
- document.removeEventListener('readystatechange', readyListener);
593
- }
594
- }
595
758
  document.addEventListener('readystatechange', readyListener);
596
759
  }
597
760
  }
@@ -600,7 +763,7 @@
600
763
  return undefined;
601
764
  });
602
765
 
603
- function attachMutationObserver() {
766
+ const attachMutationObserver = () => {
604
767
  const observer = new MutationObserver(mutations => {
605
768
  for (const mutation of mutations) {
606
769
  if (mutation.type !== 'childList') continue;
@@ -621,18 +784,27 @@
621
784
  observer.observe(document, { childList: true });
622
785
  observer.observe(document.head, { childList: true });
623
786
  processScriptsAndPreloads();
624
- }
787
+ };
625
788
 
626
789
  let importMapPromise = initPromise;
627
790
  let firstPolyfillLoad = true;
628
791
  let legacyAcceptingImportMaps = true;
629
792
 
630
- async function topLevelLoad(url, fetchOpts, source, nativelyLoaded, lastStaticLoadPromise, typescript) {
793
+ const topLevelLoad = async (url, parentUrl, fetchOpts, source, nativelyLoaded, lastStaticLoadPromise, sourceType) => {
631
794
  await initPromise;
632
795
  await importMapPromise;
633
- if (importHook) await importHook(url, typeof fetchOpts !== 'string' ? fetchOpts : {}, '');
796
+ url = (await resolve(url, parentUrl)).r;
797
+
798
+ // we mock import('./x.css', { with: { type: 'css' }}) support via an inline static reexport
799
+ // because we can't syntactically pass through to dynamic import with a second argument
800
+ if (sourceType === 'css' || sourceType === 'json') {
801
+ source = `export{default}from'${url}'with{type:"${sourceType}"}`;
802
+ url += '?entry';
803
+ }
804
+
805
+ if (importHook) await importHook(url, typeof fetchOpts !== 'string' ? fetchOpts : {}, parentUrl);
634
806
  // early analysis opt-out - no need to even fetch if we have feature support
635
- if (!shimMode && baselinePassthrough && !typescript) {
807
+ if (!shimMode && baselinePassthrough && nativePassthrough && sourceType !== 'ts') {
636
808
  // for polyfill case, only dynamic import needs a return value here, and dynamic import will never pass nativelyLoaded
637
809
  if (nativelyLoaded) return null;
638
810
  await lastStaticLoadPromise;
@@ -656,37 +828,55 @@
656
828
  onpolyfill();
657
829
  firstPolyfillLoad = false;
658
830
  }
659
- const module = await (shimMode || load.n || load.N || (!nativelyLoaded && source) ?
831
+ const module = await (shimMode || load.n || load.N || !nativePassthrough || (!nativelyLoaded && source) ?
660
832
  dynamicImport(load.b, load.u)
661
833
  : import(load.u));
662
834
  // if the top-level load is a shell, run its update function
663
835
  if (load.s) (await dynamicImport(load.s, load.u)).u$_(module);
664
836
  if (revokeBlobURLs) revokeObjectURLs(Object.keys(seen));
665
837
  return module;
666
- }
838
+ };
667
839
 
668
- function revokeObjectURLs(registryKeys) {
669
- let batch = 0;
670
- const keysLength = registryKeys.length;
671
- const schedule = self.requestIdleCallback ? self.requestIdleCallback : self.requestAnimationFrame;
672
- schedule(cleanup);
840
+ const revokeObjectURLs = registryKeys => {
841
+ let curIdx = 0;
842
+ const handler = self.requestIdleCallback || self.requestAnimationFrame;
843
+ handler(cleanup);
673
844
  function cleanup() {
674
- const batchStartIndex = batch * 100;
675
- if (batchStartIndex > keysLength) return;
676
- for (const key of registryKeys.slice(batchStartIndex, batchStartIndex + 100)) {
845
+ for (const key of registryKeys.slice(curIdx, (curIdx += 100))) {
677
846
  const load = registry[key];
678
847
  if (load && load.b && load.b !== load.u) URL.revokeObjectURL(load.b);
679
848
  }
680
- batch++;
681
- schedule(cleanup);
849
+ if (curIdx < registryKeys.length) handler(cleanup);
682
850
  }
683
- }
851
+ };
684
852
 
685
- function urlJsString(url) {
686
- return `'${url.replace(/'/g, "\\'")}'`;
687
- }
853
+ const urlJsString = url => `'${url.replace(/'/g, "\\'")}'`;
854
+
855
+ let resolvedSource, lastIndex;
856
+ const pushStringTo = (load, originalIndex, dynamicImportEndStack) => {
857
+ while (dynamicImportEndStack[dynamicImportEndStack.length - 1] < originalIndex) {
858
+ const dynamicImportEnd = dynamicImportEndStack.pop();
859
+ resolvedSource += `${load.S.slice(lastIndex, dynamicImportEnd)}, ${urlJsString(load.r)}`;
860
+ lastIndex = dynamicImportEnd;
861
+ }
862
+ resolvedSource += load.S.slice(lastIndex, originalIndex);
863
+ lastIndex = originalIndex;
864
+ };
688
865
 
689
- function resolveDeps(load, seen) {
866
+ const pushSourceURL = (load, commentPrefix, commentStart, dynamicImportEndStack) => {
867
+ const urlStart = commentStart + commentPrefix.length;
868
+ const commentEnd = load.S.indexOf('\n', urlStart);
869
+ const urlEnd = commentEnd !== -1 ? commentEnd : load.S.length;
870
+ let sourceUrl = load.S.slice(urlStart, urlEnd);
871
+ try {
872
+ sourceUrl = new URL(sourceUrl, load.r).href;
873
+ } catch {}
874
+ pushStringTo(load, urlStart, dynamicImportEndStack);
875
+ resolvedSource += sourceUrl;
876
+ lastIndex = urlEnd;
877
+ };
878
+
879
+ const resolveDeps = (load, seen) => {
690
880
  if (load.b || !seen[load.u]) return;
691
881
  seen[load.u] = 0;
692
882
 
@@ -699,7 +889,7 @@
699
889
 
700
890
  // use native loader whenever possible (n = needs shim) via executable subgraph passthrough
701
891
  // so long as the module doesn't use dynamic import or unsupported URL mappings (N = should shim)
702
- if (!shimMode && !load.n && !load.N) {
892
+ if (nativePassthrough && !shimMode && !load.n && !load.N) {
703
893
  load.b = load.u;
704
894
  load.S = undefined;
705
895
  return;
@@ -708,30 +898,19 @@
708
898
  const [imports, exports] = load.a;
709
899
 
710
900
  // "execution"
711
- const source = load.S;
712
-
713
- let resolvedSource = '';
901
+ let source = load.S,
902
+ depIndex = 0,
903
+ dynamicImportEndStack = [];
714
904
 
715
905
  // once all deps have loaded we can inline the dependency resolution blobs
716
906
  // and define this blob
717
- let lastIndex = 0,
718
- depIndex = 0,
719
- dynamicImportEndStack = [];
720
- function pushStringTo(originalIndex) {
721
- while (dynamicImportEndStack[dynamicImportEndStack.length - 1] < originalIndex) {
722
- const dynamicImportEnd = dynamicImportEndStack.pop();
723
- resolvedSource += `${source.slice(lastIndex, dynamicImportEnd)}, ${urlJsString(load.r)}`;
724
- lastIndex = dynamicImportEnd;
725
- }
726
- resolvedSource += source.slice(lastIndex, originalIndex);
727
- lastIndex = originalIndex;
728
- }
907
+ (resolvedSource = ''), (lastIndex = 0);
729
908
 
730
909
  for (const { s: start, e: end, ss: statementStart, se: statementEnd, d: dynamicImportIndex, t, a } of imports) {
731
910
  // source phase
732
911
  if (t === 4) {
733
912
  let { l: depLoad } = load.d[depIndex++];
734
- pushStringTo(statementStart);
913
+ pushStringTo(load, statementStart, dynamicImportEndStack);
735
914
  resolvedSource += `${source.slice(statementStart, start - 1).replace('source', '')}/*${source.slice(start - 1, end + 1)}*/'${createBlob(`export default importShim._s[${urlJsString(depLoad.r)}]`)}'`;
736
915
  lastIndex = end + 1;
737
916
  }
@@ -742,12 +921,13 @@
742
921
  const assertion = source.slice(a, statementEnd - 1);
743
922
  // strip assertions only when unsupported in polyfill mode
744
923
  keepAssertion =
745
- (supportsJsonType && assertion.includes('json')) || (supportsCssType && assertion.includes('css'));
924
+ nativePassthrough &&
925
+ ((supportsJsonType && assertion.includes('json')) || (supportsCssType && assertion.includes('css')));
746
926
  }
747
927
 
748
928
  // defer phase stripping
749
929
  if (t === 6) {
750
- pushStringTo(statementStart);
930
+ pushStringTo(load, statementStart, dynamicImportEndStack);
751
931
  resolvedSource += source.slice(statementStart, start - 1).replace('defer', '');
752
932
  lastIndex = start;
753
933
  }
@@ -772,7 +952,7 @@
772
952
  }
773
953
  }
774
954
 
775
- pushStringTo(start - 1);
955
+ pushStringTo(load, start - 1, dynamicImportEndStack);
776
956
  resolvedSource += `/*${source.slice(start - 1, end + 1)}*/'${blobUrl}'`;
777
957
 
778
958
  // circular shell execution
@@ -785,14 +965,14 @@
785
965
  // import.meta
786
966
  else if (dynamicImportIndex === -2) {
787
967
  load.m = { url: load.r, resolve: metaResolve };
788
- metaHook(load.m, load.u);
789
- pushStringTo(start);
968
+ if (metaHook) metaHook(load.m, load.u);
969
+ pushStringTo(load, start, dynamicImportEndStack);
790
970
  resolvedSource += `importShim._r[${urlJsString(load.u)}].m`;
791
971
  lastIndex = statementEnd;
792
972
  }
793
973
  // dynamic import
794
974
  else {
795
- pushStringTo(statementStart + 6);
975
+ pushStringTo(load, statementStart + 6, dynamicImportEndStack);
796
976
  resolvedSource += `Shim${t === 5 ? '.source' : ''}(`;
797
977
  dynamicImportEndStack.push(statementEnd - 1);
798
978
  lastIndex = start;
@@ -806,19 +986,6 @@
806
986
  .map(({ s, e, ln }) => `${source.slice(s, e)}:${ln}`)
807
987
  .join(',')}})}catch(_){};\n`;
808
988
 
809
- function pushSourceURL(commentPrefix, commentStart) {
810
- const urlStart = commentStart + commentPrefix.length;
811
- const commentEnd = source.indexOf('\n', urlStart);
812
- const urlEnd = commentEnd !== -1 ? commentEnd : source.length;
813
- let sourceUrl = source.slice(urlStart, urlEnd);
814
- try {
815
- sourceUrl = new URL(sourceUrl, load.r).href;
816
- } catch {}
817
- pushStringTo(urlStart);
818
- resolvedSource += sourceUrl;
819
- lastIndex = urlEnd;
820
- }
821
-
822
989
  let sourceURLCommentStart = source.lastIndexOf(sourceURLCommentPrefix);
823
990
  let sourceMapURLCommentStart = source.lastIndexOf(sourceMapURLCommentPrefix);
824
991
 
@@ -831,23 +998,23 @@
831
998
  sourceURLCommentStart !== -1 &&
832
999
  (sourceMapURLCommentStart === -1 || sourceMapURLCommentStart > sourceURLCommentStart)
833
1000
  ) {
834
- pushSourceURL(sourceURLCommentPrefix, sourceURLCommentStart);
1001
+ pushSourceURL(load, sourceURLCommentPrefix, sourceURLCommentStart, dynamicImportEndStack);
835
1002
  }
836
1003
  // sourceMappingURL
837
1004
  if (sourceMapURLCommentStart !== -1) {
838
- pushSourceURL(sourceMapURLCommentPrefix, sourceMapURLCommentStart);
1005
+ pushSourceURL(load, sourceMapURLCommentPrefix, sourceMapURLCommentStart, dynamicImportEndStack);
839
1006
  // sourceURL last
840
1007
  if (sourceURLCommentStart !== -1 && sourceURLCommentStart > sourceMapURLCommentStart)
841
- pushSourceURL(sourceURLCommentPrefix, sourceURLCommentStart);
1008
+ pushSourceURL(load, sourceURLCommentPrefix, sourceURLCommentStart, dynamicImportEndStack);
842
1009
  }
843
1010
 
844
- pushStringTo(source.length);
1011
+ pushStringTo(load, source.length, dynamicImportEndStack);
845
1012
 
846
1013
  if (sourceURLCommentStart === -1) resolvedSource += sourceURLCommentPrefix + load.r;
847
1014
 
848
1015
  load.b = createBlob(resolvedSource);
849
- load.S = undefined;
850
- }
1016
+ load.S = resolvedSource = undefined;
1017
+ };
851
1018
 
852
1019
  const sourceURLCommentPrefix = '\n//# sourceURL=';
853
1020
  const sourceMapURLCommentPrefix = '\n//# sourceMappingURL=';
@@ -863,15 +1030,15 @@
863
1030
  // restrict in-flight fetches to a pool of 100
864
1031
  let p = [];
865
1032
  let c = 0;
866
- function pushFetchPool() {
1033
+ const pushFetchPool = () => {
867
1034
  if (++c > 100) return new Promise(r => p.push(r));
868
- }
869
- function popFetchPool() {
1035
+ };
1036
+ const popFetchPool = () => {
870
1037
  c--;
871
1038
  if (p.length) p.shift()();
872
- }
1039
+ };
873
1040
 
874
- async function doFetch(url, fetchOpts, parent) {
1041
+ const doFetch = async (url, fetchOpts, parent) => {
875
1042
  if (enforceIntegrity && !fetchOpts.integrity) throw Error(`No integrity for ${url}${fromParent(parent)}.`);
876
1043
  const poolQueue = pushFetchPool();
877
1044
  if (poolQueue) await poolQueue;
@@ -890,15 +1057,16 @@
890
1057
  throw error;
891
1058
  }
892
1059
  return res;
893
- }
1060
+ };
894
1061
 
895
1062
  let esmsTsTransform;
896
- async function initTs() {
1063
+ const initTs = async () => {
897
1064
  const m = await import(tsTransform);
898
1065
  if (!esmsTsTransform) esmsTsTransform = m.transform;
899
- }
1066
+ };
900
1067
 
901
- async function fetchModule(url, fetchOpts, parent) {
1068
+ const hotPrefix = 'var h=import.meta.hot,';
1069
+ const fetchModule = async (url, fetchOpts, parent) => {
902
1070
  const mapIntegrity = composedImportMap.integrity[url];
903
1071
  const res = await doFetch(
904
1072
  url,
@@ -909,32 +1077,38 @@
909
1077
  const contentType = res.headers.get('content-type');
910
1078
  if (jsContentType.test(contentType)) return { r, s: await res.text(), t: 'js' };
911
1079
  else if (wasmContentType.test(contentType)) {
912
- const module = await (sourceCache[r] || (sourceCache[r] = WebAssembly.compileStreaming(res)));
913
- sourceCache[r] = module;
914
- let s = '',
1080
+ const wasmModule = await (sourceCache[r] || (sourceCache[r] = WebAssembly.compileStreaming(res)));
1081
+ const exports = WebAssembly.Module.exports(wasmModule);
1082
+ sourceCache[r] = wasmModule;
1083
+ const rStr = urlJsString(r);
1084
+ let s = `import*as $_ns from${rStr};`,
915
1085
  i = 0,
916
- importObj = '';
917
- for (const impt of WebAssembly.Module.imports(module)) {
918
- const specifier = urlJsString(impt.module);
919
- s += `import * as impt${i} from ${specifier};\n`;
920
- importObj += `${specifier}:impt${i++},`;
1086
+ obj = '';
1087
+ for (const { module, kind } of WebAssembly.Module.imports(wasmModule)) {
1088
+ const specifier = urlJsString(module);
1089
+ s += `import*as impt${i} from${specifier};\n`;
1090
+ obj += `${specifier}:${kind === 'global' ? `importShim._i.get(impt${i})||impt${i++}` : `impt${i++}`},`;
921
1091
  }
922
- i = 0;
923
- s += `const instance = await WebAssembly.instantiate(importShim._s[${urlJsString(r)}], {${importObj}});\n`;
924
- for (const expt of WebAssembly.Module.exports(module)) {
925
- s += `export const ${expt.name} = instance.exports['${expt.name}'];\n`;
1092
+ s += `${hotPrefix}i=await WebAssembly.instantiate(importShim._s[${rStr}],{${obj}});importShim._i.set($_ns,i);`;
1093
+ obj = '';
1094
+ for (const { name, kind } of exports) {
1095
+ s += `export let ${name}=i.exports['${name}'];`;
1096
+ if (kind === 'global') s += `try{${name}=${name}.value}catch{${name}=undefined}`;
1097
+ obj += `${name},`;
926
1098
  }
1099
+ s += `if(h)h.accept(m=>({${obj}}=m))`;
927
1100
  return { r, s, t: 'wasm' };
928
- } else if (jsonContentType.test(contentType)) return { r, s: `export default ${await res.text()}`, t: 'json' };
1101
+ } else if (jsonContentType.test(contentType))
1102
+ return { r, s: `${hotPrefix}j=${await res.text()};export{j as default};if(h)h.accept(m=>j=m.default)`, t: 'json' };
929
1103
  else if (cssContentType.test(contentType)) {
930
1104
  return {
931
1105
  r,
932
- s: `var s=new CSSStyleSheet();s.replaceSync(${JSON.stringify(
1106
+ s: `${hotPrefix}s=h&&h.data.s||new CSSStyleSheet();s.replaceSync(${JSON.stringify(
933
1107
  (await res.text()).replace(
934
1108
  cssUrlRegEx,
935
1109
  (_match, quotes = '', relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`
936
1110
  )
937
- )});export default s;`,
1111
+ )});if(h){h.data.s=s;h.accept(()=>{})}export default s`,
938
1112
  t: 'css'
939
1113
  };
940
1114
  } else if (tsContentType.test(contentType) || url.endsWith('.ts') || url.endsWith('.mts')) {
@@ -948,9 +1122,9 @@
948
1122
  throw Error(
949
1123
  `Unsupported Content-Type "${contentType}" loading ${url}${fromParent(parent)}. Modules must be served with a valid MIME type like application/javascript.`
950
1124
  );
951
- }
1125
+ };
952
1126
 
953
- function isUnsupportedType(type) {
1127
+ const isUnsupportedType = type => {
954
1128
  if (type === 'wasm' && !wasmInstancePhaseEnabled && !wasmSourcePhaseEnabled) throw featErr(`wasm-modules`);
955
1129
  return (
956
1130
  (type === 'css' && !supportsCssType) ||
@@ -958,13 +1132,13 @@
958
1132
  (type === 'wasm' && !supportsWasmInstancePhase && !supportsWasmSourcePhase) ||
959
1133
  type === 'ts'
960
1134
  );
961
- }
1135
+ };
962
1136
 
963
- function getOrCreateLoad(url, fetchOpts, parent, source) {
1137
+ const getOrCreateLoad = (url, fetchOpts, parent, source) => {
964
1138
  if (source && registry[url]) {
965
1139
  let i = 0;
966
- while (registry[url + ++i]);
967
- url += i;
1140
+ while (registry[url + '?' + ++i]);
1141
+ url += '?' + i;
968
1142
  }
969
1143
  let load = registry[url];
970
1144
  if (load) return load;
@@ -1013,14 +1187,14 @@
1013
1187
  return load;
1014
1188
  })();
1015
1189
  return load;
1016
- }
1190
+ };
1017
1191
 
1018
1192
  const featErr = feat =>
1019
1193
  Error(
1020
1194
  `${feat} feature must be enabled via <script type="esms-options">{ "polyfillEnable": ["${feat}"] }<${''}/script>`
1021
1195
  );
1022
1196
 
1023
- function linkLoad(load, fetchOpts) {
1197
+ const linkLoad = (load, fetchOpts) => {
1024
1198
  if (load.L) return;
1025
1199
  load.L = load.f.then(async () => {
1026
1200
  let childFetchOpts = fetchOpts;
@@ -1034,7 +1208,7 @@
1034
1208
  if (!sourcePhase || !supportsWasmSourcePhase) load.n = true;
1035
1209
  }
1036
1210
  let source = undefined;
1037
- if (a > 0 && !shimMode) {
1211
+ if (a > 0 && !shimMode && nativePassthrough) {
1038
1212
  const assertion = load.S.slice(a, se - 1);
1039
1213
  // no need to fetch JSON/CSS if supported, since it's a leaf node, we'll just strip the assertion syntax
1040
1214
  if (assertion.includes('json')) {
@@ -1061,9 +1235,9 @@
1061
1235
  })
1062
1236
  .filter(l => l);
1063
1237
  });
1064
- }
1238
+ };
1065
1239
 
1066
- function processScriptsAndPreloads() {
1240
+ const processScriptsAndPreloads = () => {
1067
1241
  for (const link of document.querySelectorAll(shimMode ? 'link[rel=modulepreload-shim]' : 'link[rel=modulepreload]')) {
1068
1242
  if (!link.ep) processPreload(link);
1069
1243
  }
@@ -1075,9 +1249,9 @@
1075
1249
  if (!script.ep) processScript(script);
1076
1250
  }
1077
1251
  }
1078
- }
1252
+ };
1079
1253
 
1080
- function getFetchOpts(script) {
1254
+ const getFetchOpts = script => {
1081
1255
  const fetchOpts = {};
1082
1256
  if (script.integrity) fetchOpts.integrity = script.integrity;
1083
1257
  if (script.referrerPolicy) fetchOpts.referrerPolicy = script.referrerPolicy;
@@ -1086,40 +1260,65 @@
1086
1260
  else if (script.crossOrigin === 'anonymous') fetchOpts.credentials = 'omit';
1087
1261
  else fetchOpts.credentials = 'same-origin';
1088
1262
  return fetchOpts;
1089
- }
1263
+ };
1090
1264
 
1091
1265
  let lastStaticLoadPromise = Promise.resolve();
1092
1266
 
1267
+ let domContentLoaded = false;
1093
1268
  let domContentLoadedCnt = 1;
1094
- function domContentLoadedCheck() {
1269
+ const domContentLoadedCheck = m => {
1270
+ if (m === undefined) {
1271
+ if (domContentLoaded) return;
1272
+ domContentLoaded = true;
1273
+ domContentLoadedCnt--;
1274
+ }
1095
1275
  if (--domContentLoadedCnt === 0 && !noLoadEventRetriggers && (shimMode || !baselinePassthrough)) {
1276
+ document.removeEventListener('DOMContentLoaded', domContentLoadedEvent);
1096
1277
  document.dispatchEvent(new Event('DOMContentLoaded'));
1097
1278
  }
1098
- }
1279
+ };
1099
1280
  let loadCnt = 1;
1100
- function loadCheck() {
1281
+ const loadCheck = () => {
1101
1282
  if (--loadCnt === 0 && !noLoadEventRetriggers && (shimMode || !baselinePassthrough)) {
1283
+ window.removeEventListener('load', loadEvent);
1102
1284
  window.dispatchEvent(new Event('load'));
1103
1285
  }
1104
- }
1286
+ };
1287
+
1288
+ const domContentLoadedEvent = async () => {
1289
+ await initPromise;
1290
+ domContentLoadedCheck();
1291
+ };
1292
+ const loadEvent = async () => {
1293
+ await initPromise;
1294
+ domContentLoadedCheck();
1295
+ loadCheck();
1296
+ };
1297
+
1105
1298
  // this should always trigger because we assume es-module-shims is itself a domcontentloaded requirement
1106
1299
  if (hasDocument) {
1107
- document.addEventListener('DOMContentLoaded', async () => {
1108
- await initPromise;
1109
- domContentLoadedCheck();
1110
- });
1111
- window.addEventListener('load', async () => {
1112
- await initPromise;
1113
- loadCheck();
1114
- });
1300
+ document.addEventListener('DOMContentLoaded', domContentLoadedEvent);
1301
+ window.addEventListener('load', loadEvent);
1115
1302
  }
1116
1303
 
1304
+ const readyListener = async () => {
1305
+ await initPromise;
1306
+ processScriptsAndPreloads();
1307
+ if (document.readyState === 'complete') {
1308
+ readyStateCompleteCheck();
1309
+ }
1310
+ };
1311
+
1117
1312
  let readyStateCompleteCnt = 1;
1118
- function readyStateCompleteCheck() {
1119
- if (--readyStateCompleteCnt === 0 && !noLoadEventRetriggers && (shimMode || !baselinePassthrough)) {
1120
- document.dispatchEvent(new Event('readystatechange'));
1313
+ const readyStateCompleteCheck = () => {
1314
+ if (--readyStateCompleteCnt === 0) {
1315
+ domContentLoadedCheck();
1316
+ if (!noLoadEventRetriggers && (shimMode || !baselinePassthrough)) {
1317
+ document.removeEventListener('readystatechange', readyListener);
1318
+ document.dispatchEvent(new Event('readystatechange'));
1319
+ }
1121
1320
  }
1122
- }
1321
+ };
1123
1322
 
1124
1323
  const hasNext = script => script.nextSibling || (script.parentNode && hasNext(script.parentNode));
1125
1324
  const epCheck = (script, ready) =>
@@ -1128,7 +1327,7 @@
1128
1327
  script.getAttribute('noshim') !== null ||
1129
1328
  !(script.ep = true);
1130
1329
 
1131
- function processImportMap(script, ready = readyStateCompleteCnt > 0) {
1330
+ const processImportMap = (script, ready = readyStateCompleteCnt > 0) => {
1132
1331
  if (epCheck(script, ready)) return;
1133
1332
  // we dont currently support external import maps in polyfill mode to match native
1134
1333
  if (script.src) {
@@ -1157,9 +1356,9 @@
1157
1356
  }
1158
1357
  }
1159
1358
  legacyAcceptingImportMaps = false;
1160
- }
1359
+ };
1161
1360
 
1162
- function processScript(script, ready = readyStateCompleteCnt > 0) {
1361
+ const processScript = (script, ready = readyStateCompleteCnt > 0) => {
1163
1362
  if (epCheck(script, ready)) return;
1164
1363
  // does this load block readystate complete
1165
1364
  const isBlockingReadyScript = script.getAttribute('async') === null && readyStateCompleteCnt > 0;
@@ -1181,22 +1380,24 @@
1181
1380
  }
1182
1381
  return topLevelLoad(
1183
1382
  script.src || baseUrl,
1383
+ baseUrl,
1184
1384
  getFetchOpts(script),
1185
1385
  transformed === undefined ? script.innerHTML : transformed,
1186
1386
  !shimMode && transformed === undefined,
1187
1387
  isBlockingReadyScript && lastStaticLoadPromise,
1188
- true
1388
+ 'ts'
1189
1389
  );
1190
1390
  })
1191
1391
  .catch(throwError);
1192
1392
  } else {
1193
1393
  loadPromise = topLevelLoad(
1194
1394
  script.src || baseUrl,
1395
+ baseUrl,
1195
1396
  getFetchOpts(script),
1196
1397
  !script.src ? script.innerHTML : undefined,
1197
1398
  !shimMode,
1198
1399
  isBlockingReadyScript && lastStaticLoadPromise,
1199
- ts
1400
+ 'ts'
1200
1401
  ).catch(throwError);
1201
1402
  }
1202
1403
  if (!noLoadEventRetriggers) loadPromise.then(() => script.dispatchEvent(new Event('load')));
@@ -1205,13 +1406,13 @@
1205
1406
  }
1206
1407
  if (isDomContentLoadedScript) loadPromise.then(domContentLoadedCheck);
1207
1408
  if (isLoadScript) loadPromise.then(loadCheck);
1208
- }
1409
+ };
1209
1410
 
1210
1411
  const fetchCache = {};
1211
- function processPreload(link) {
1412
+ const processPreload = link => {
1212
1413
  link.ep = true;
1213
1414
  if (fetchCache[link.href]) return;
1214
1415
  fetchCache[link.href] = fetchModule(link.href, getFetchOpts(link));
1215
- }
1416
+ };
1216
1417
 
1217
1418
  })();