es-module-shims 2.1.2 → 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,115 +1,283 @@
1
- /* ES Module Shims 2.1.2 */
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(/\.debug\.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 enableLatest = esmsInitOptions.polyfillEnable === 'latest' || enable.includes('latest');
53
- const cssModulesEnabled = enable.includes('css-modules') || enableAll || enableLatest;
54
- const jsonModulesEnabled = enable.includes('json-modules') || enableAll || enableLatest;
55
- const wasmInstancePhaseEnabled =
56
- enable.includes('wasm-modules') || enable.includes('wasm-module-instances') || enableAll;
57
- const wasmSourcePhaseEnabled =
58
- enable.includes('wasm-modules') || enable.includes('wasm-module-sources') || enableAll;
59
- const deferPhaseEnabled = enable.includes('import-defer') || enableAll;
60
- const typescriptEnabled = enable.includes('typescript') || enableAll;
61
-
62
- const onpolyfill =
63
- esmsInitOptions.onpolyfill ?
64
- globalHook(esmsInitOptions.onpolyfill)
65
- : () => {
66
- console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
67
- };
68
-
69
- const baseUrl =
70
- hasDocument ?
71
- document.baseURI
72
- : `${location.protocol}//${location.host}${
73
- location.pathname.includes('/') ?
74
- location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
75
- : location.pathname
76
- }`;
77
-
78
- const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
79
- let { skip } = esmsInitOptions;
80
- if (Array.isArray(skip)) {
81
- const l = skip.map(s => new URL(s, baseUrl).href);
82
- skip = s => l.some(i => (i[i.length - 1] === '/' && s.startsWith(i)) || s === i);
83
- } else if (typeof skip === 'string') {
84
- const r = new RegExp(skip);
85
- skip = s => r.test(s);
86
- } else if (skip instanceof RegExp) {
87
- skip = s => skip.test(s);
88
- }
89
-
90
- const dispatchError = error => self.dispatchEvent(Object.assign(new Event('error'), { error }));
91
-
92
- const throwError = err => {
93
- (self.reportError || dispatchError)(err), void onerror(err);
94
- };
95
-
96
- function fromParent(parent) {
97
- 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
+ console.info(`es-module-shims: hot reload ${url}`);
94
+ const hotState = hotRegistry[url];
95
+ if (hotState) {
96
+ hotState.A = false;
97
+ if (
98
+ hotState.a &&
99
+ hotState.a.some(([d]) => d && (typeof d === 'string' ? d === fromUrl : d.includes(fromUrl)))
100
+ ) {
101
+ curInvalidationRoots.add(fromUrl);
102
+ } else {
103
+ if (hotState.e || hotState.a) curInvalidationRoots.add(url);
104
+ hotState.v++;
105
+ if (!hotState.a) for (const parent of hotState.p) invalidate(parent, url, seen);
106
+ }
107
+ }
108
+ }
109
+ if (!curInvalidationInterval)
110
+ curInvalidationInterval = setTimeout(() => {
111
+ curInvalidationInterval = null;
112
+ const earlyRoots = new Set();
113
+ for (const root of curInvalidationRoots) {
114
+ const hotState = hotRegistry[root];
115
+ importShim(toVersioned(root)).then(m => {
116
+ if (hotState.a) {
117
+ hotState.a.every(([d, c]) => d === null && !earlyRoots.has(c) && c(m));
118
+ // unload should be the latest unload handler from the just loaded module
119
+ if (hotState.u) {
120
+ hotState.u(hotState.d);
121
+ hotState.u = null;
122
+ }
123
+ }
124
+ for (const parent of hotState.p) {
125
+ const hotState = hotRegistry[parent];
126
+ if (hotState && hotState.a)
127
+ hotState.a.every(async ([d, c]) => {
128
+ return (
129
+ d &&
130
+ !earlyRoots.has(c) &&
131
+ (typeof d === 'string' ?
132
+ d === root && c(m)
133
+ : c(await Promise.all(d.map(d => (earlyRoots.push(c), importShim(toVersioned(d)))))))
134
+ );
135
+ });
136
+ }
137
+ }, noop);
138
+ }
139
+ curInvalidationRoots = new Set();
140
+ }, hotReloadInterval);
141
+ };
142
+
143
+ return [
144
+ _importHook ?
145
+ (url, opts, parentUrl) => {
146
+ _importHook(url, opts, parentUrl);
147
+ hotImportHook(url);
148
+ }
149
+ : hotImportHook,
150
+ _resolveHook ?
151
+ (id, parent, defaultResolve) =>
152
+ hotResolveHook(id, parent, (id, parent) => _resolveHook(id, parent, defaultResolve))
153
+ : hotResolveHook,
154
+ _metaHook ?
155
+ (metaObj, url) => {
156
+ _metaHook(metaObj, url);
157
+ hotMetaHook(metaObj, url);
158
+ }
159
+ : hotMetaHook
160
+ ];
161
+ };
162
+
163
+ if (self.importShim) {
164
+ console.info(
165
+ `es-module-shims: skipping initialization as importShim was already registered by another polyfill instance`
166
+ );
167
+ return;
168
+ }
169
+
170
+ const hasDocument = typeof document !== 'undefined';
171
+
172
+ const noop = () => {};
173
+
174
+ const dynamicImport = (u, errUrl) => import(u);
175
+
176
+ const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
177
+
178
+ const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
179
+ Object.assign(esmsInitOptions, self.esmsInitOptions || {});
180
+
181
+ // shim mode is determined on initialization, no late shim mode
182
+ const shimMode =
183
+ esmsInitOptions.shimMode ||
184
+ (hasDocument &&
185
+ document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
186
+ .length > 0);
187
+
188
+ let importHook,
189
+ resolveHook,
190
+ fetchHook = fetch,
191
+ metaHook = noop,
192
+ tsTransform =
193
+ (hasDocument && document.currentScript && document.currentScript.src.replace(/(\.\w+)?\.js$/, '-typescript.js')) ||
194
+ './es-module-shims-typescript.js';
195
+
196
+ const {
197
+ revokeBlobURLs,
198
+ noLoadEventRetriggers,
199
+ enforceIntegrity,
200
+ hotReload,
201
+ hotReloadInterval = 100,
202
+ nativePassthrough = !hotReload
203
+ } = esmsInitOptions;
204
+
205
+ const globalHook = name => (typeof name === 'string' ? self[name] : name);
206
+
207
+ if (esmsInitOptions.onimport) importHook = globalHook(esmsInitOptions.onimport);
208
+ if (esmsInitOptions.resolve) resolveHook = globalHook(esmsInitOptions.resolve);
209
+ if (esmsInitOptions.fetch) fetchHook = globalHook(esmsInitOptions.fetch);
210
+ if (esmsInitOptions.meta) metaHook = globalHook(esmsInitOptions.meta);
211
+ if (esmsInitOptions.tsTransform) tsTransform = globalHook(esmsInitOptions.tsTransform);
212
+
213
+ if (hotReload) [importHook, resolveHook, metaHook] = initHotReload();
214
+
215
+ const mapOverrides = esmsInitOptions.mapOverrides;
216
+
217
+ let nonce = esmsInitOptions.nonce;
218
+ if (!nonce && hasDocument) {
219
+ const nonceElement = document.querySelector('script[nonce]');
220
+ if (nonceElement) nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
98
221
  }
99
222
 
223
+ const onerror = globalHook(esmsInitOptions.onerror || noop);
224
+
225
+ const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
226
+ const enableAll = esmsInitOptions.polyfillEnable === 'all' || enable.includes('all');
227
+ const wasmInstancePhaseEnabled =
228
+ enable.includes('wasm-modules') || enable.includes('wasm-module-instances') || enableAll;
229
+ const wasmSourcePhaseEnabled =
230
+ enable.includes('wasm-modules') || enable.includes('wasm-module-sources') || enableAll;
231
+ const deferPhaseEnabled = enable.includes('import-defer') || enableAll;
232
+
233
+ const onpolyfill =
234
+ esmsInitOptions.onpolyfill ?
235
+ globalHook(esmsInitOptions.onpolyfill)
236
+ : () => {
237
+ console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
238
+ };
239
+
240
+ const baseUrl =
241
+ hasDocument ?
242
+ document.baseURI
243
+ : `${location.protocol}//${location.host}${
244
+ location.pathname.includes('/') ?
245
+ location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
246
+ : location.pathname
247
+ }`;
248
+
249
+ const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
250
+ let { skip } = esmsInitOptions;
251
+ if (Array.isArray(skip)) {
252
+ const l = skip.map(s => new URL(s, baseUrl).href);
253
+ skip = s => l.some(i => (i[i.length - 1] === '/' && s.startsWith(i)) || s === i);
254
+ } else if (typeof skip === 'string') {
255
+ const r = new RegExp(skip);
256
+ skip = s => r.test(s);
257
+ } else if (skip instanceof RegExp) {
258
+ skip = s => skip.test(s);
259
+ }
260
+
261
+ const dispatchError = error => self.dispatchEvent(Object.assign(new Event('error'), { error }));
262
+
263
+ const throwError = err => {
264
+ (self.reportError || dispatchError)(err), void onerror(err);
265
+ };
266
+
267
+ const fromParent = parent => (parent ? ` imported from ${parent}` : '');
268
+
100
269
  const backslashRegEx = /\\/g;
101
270
 
102
- function asURL(url) {
271
+ const asURL = url => {
103
272
  try {
104
273
  if (url.indexOf(':') !== -1) return new URL(url).href;
105
274
  } catch (_) {}
106
- }
275
+ };
107
276
 
108
- function resolveUrl(relUrl, parentUrl) {
109
- return resolveIfNotPlainOrUrl(relUrl, parentUrl) || asURL(relUrl) || resolveIfNotPlainOrUrl('./' + relUrl, parentUrl);
110
- }
277
+ const resolveUrl = (relUrl, parentUrl) =>
278
+ resolveIfNotPlainOrUrl(relUrl, parentUrl) || asURL(relUrl) || resolveIfNotPlainOrUrl('./' + relUrl, parentUrl);
111
279
 
112
- function resolveIfNotPlainOrUrl(relUrl, parentUrl) {
280
+ const resolveIfNotPlainOrUrl = (relUrl, parentUrl) => {
113
281
  const hIdx = parentUrl.indexOf('#'),
114
282
  qIdx = parentUrl.indexOf('?');
115
283
  if (hIdx + qIdx > -2)
@@ -197,9 +365,9 @@
197
365
  if (segmentIndex !== -1) output.push(segmented.slice(segmentIndex));
198
366
  return parentUrl.slice(0, parentUrl.length - pathname.length) + output.join('');
199
367
  }
200
- }
368
+ };
201
369
 
202
- function resolveAndComposeImportMap(json, baseUrl, parentMap) {
370
+ const resolveAndComposeImportMap = (json, baseUrl, parentMap) => {
203
371
  const outMap = {
204
372
  imports: Object.assign({}, parentMap.imports),
205
373
  scopes: Object.assign({}, parentMap.scopes),
@@ -222,27 +390,27 @@
222
390
  if (json.integrity) resolveAndComposeIntegrity(json.integrity, outMap.integrity, baseUrl);
223
391
 
224
392
  return outMap;
225
- }
393
+ };
226
394
 
227
- function getMatch(path, matchObj) {
395
+ const getMatch = (path, matchObj) => {
228
396
  if (matchObj[path]) return path;
229
397
  let sepIndex = path.length;
230
398
  do {
231
399
  const segment = path.slice(0, sepIndex + 1);
232
400
  if (segment in matchObj) return segment;
233
401
  } while ((sepIndex = path.lastIndexOf('/', sepIndex - 1)) !== -1);
234
- }
402
+ };
235
403
 
236
- function applyPackages(id, packages) {
404
+ const applyPackages = (id, packages) => {
237
405
  const pkgName = getMatch(id, packages);
238
406
  if (pkgName) {
239
407
  const pkg = packages[pkgName];
240
408
  if (pkg === null) return;
241
409
  return pkg + id.slice(pkgName.length);
242
410
  }
243
- }
411
+ };
244
412
 
245
- function resolveImportMap(importMap, resolvedOrPlain, parentUrl) {
413
+ const resolveImportMap = (importMap, resolvedOrPlain, parentUrl) => {
246
414
  let scopeUrl = parentUrl && getMatch(parentUrl, importMap.scopes);
247
415
  while (scopeUrl) {
248
416
  const packageResolution = applyPackages(resolvedOrPlain, importMap.scopes[scopeUrl]);
@@ -250,9 +418,9 @@
250
418
  scopeUrl = getMatch(scopeUrl.slice(0, scopeUrl.lastIndexOf('/')), importMap.scopes);
251
419
  }
252
420
  return applyPackages(resolvedOrPlain, importMap.imports) || (resolvedOrPlain.indexOf(':') !== -1 && resolvedOrPlain);
253
- }
421
+ };
254
422
 
255
- function resolveAndComposePackages(packages, outPackages, baseUrl, parentMap) {
423
+ const resolveAndComposePackages = (packages, outPackages, baseUrl, parentMap) => {
256
424
  for (let p in packages) {
257
425
  const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
258
426
  if (
@@ -274,9 +442,9 @@
274
442
  }
275
443
  console.warn(`es-module-shims: Mapping "${p}" -> "${packages[p]}" does not resolve`);
276
444
  }
277
- }
445
+ };
278
446
 
279
- function resolveAndComposeIntegrity(integrity, outIntegrity, baseUrl) {
447
+ const resolveAndComposeIntegrity = (integrity, outIntegrity, baseUrl) => {
280
448
  for (let p in integrity) {
281
449
  const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
282
450
  if (
@@ -290,7 +458,7 @@
290
458
  }
291
459
  outIntegrity[resolvedLhs] = integrity[p];
292
460
  }
293
- }
461
+ };
294
462
 
295
463
  // support browsers without dynamic import support (eg Firefox 6x)
296
464
  let supportsJsonType = false;
@@ -308,16 +476,16 @@
308
476
  let featureDetectionPromise = (async function () {
309
477
  if (!hasDocument)
310
478
  return Promise.all([
311
- cssModulesEnabled &&
312
- import(createBlob(`import"${createBlob('', 'text/css')}"with{type:"css"}`)).then(
313
- () => (supportsCssType = true),
314
- noop
315
- ),
316
- jsonModulesEnabled &&
317
- import(createBlob(`import"${createBlob('{}', 'text/json')}"with{type:"json"}`)).then(
318
- () => (supportsJsonType = true),
319
- noop
479
+ import(createBlob(`import"${createBlob('{}', 'text/json')}"with{type:"json"}`)).then(
480
+ () => (
481
+ (supportsJsonType = true),
482
+ import(createBlob(`import"${createBlob('', 'text/css')}"with{type:"css"}`)).then(
483
+ () => (supportsCssType = true),
484
+ noop
485
+ )
320
486
  ),
487
+ noop
488
+ ),
321
489
  wasmInstancePhaseEnabled &&
322
490
  import(createBlob(`import"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
323
491
  () => (supportsWasmInstancePhase = true),
@@ -341,8 +509,8 @@
341
509
  ,
342
510
  supportsImportMaps,
343
511
  supportsMultipleImportMaps,
344
- supportsCssType,
345
512
  supportsJsonType,
513
+ supportsCssType,
346
514
  supportsWasmSourcePhase,
347
515
  supportsWasmInstancePhase
348
516
  ] = data;
@@ -352,17 +520,15 @@
352
520
  }
353
521
  window.addEventListener('message', cb, false);
354
522
 
355
- // Feature checking with careful avoidance of unnecessary work - all gated on initial import map supports check. JSON gates on CSS feature check, Wasm instance phase gates on wasm source phase check.
523
+ // 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.
356
524
  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=${
357
- supportsImportMaps && cssModulesEnabled ? `c(b(\`import"\${b('','text/css')}"with{type:"css"}\`))` : 'false'
525
+ supportsImportMaps ? `c(b(\`import"\${b('{}','text/json')}"with{type:"json"}\`))` : 'false'
358
526
  };sp=${
359
527
  supportsImportMaps && wasmSourcePhaseEnabled ?
360
528
  `c(b(\`import source x from "\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))`
361
529
  : 'false'
362
530
  };Promise.all([${supportsImportMaps ? 'true' : "c('x')"},${supportsImportMaps ? "c('y')" : false},cm,${
363
- supportsImportMaps && jsonModulesEnabled ?
364
- `${cssModulesEnabled ? 'cm.then(s=>s?' : ''}c(b(\`import"\${b('{}','text/json')\}"with{type:"json"}\`))${cssModulesEnabled ? ':false)' : ''}`
365
- : 'false'
531
+ supportsImportMaps ? `cm.then(s=>s?c(b(\`import"\${b('','text/css')\}"with{type:"css"}\`)):false)` : 'false'
366
532
  },sp,${
367
533
  supportsImportMaps && wasmInstancePhaseEnabled ?
368
534
  `${wasmSourcePhaseEnabled ? 'sp.then(s=>s?' : ''}c(b(\`import"\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))${wasmSourcePhaseEnabled ? ':false)' : ''}`
@@ -413,7 +579,7 @@
413
579
  /* es-module-lexer 1.7.0 */
414
580
  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})}
415
581
 
416
- function _resolve(id, parentUrl = baseUrl) {
582
+ const _resolve = (id, parentUrl = baseUrl) => {
417
583
  const urlResolved = resolveIfNotPlainOrUrl(id, parentUrl) || asURL(id);
418
584
  const firstResolved = firstImportMap && resolveImportMap(firstImportMap, urlResolved || id, parentUrl);
419
585
  const composedResolved =
@@ -436,96 +602,105 @@
436
602
  if (firstResolved && resolved !== firstResolved) N = true;
437
603
  }
438
604
  return { r: resolved, n, N };
439
- }
605
+ };
440
606
 
441
- const resolve =
442
- resolveHook ?
443
- (id, parentUrl = baseUrl) => {
444
- const result = resolveHook(id, parentUrl, defaultResolve);
445
- return result ? { r: result, n: true, N: true } : _resolve(id, parentUrl);
446
- }
447
- : _resolve;
607
+ const resolve = (id, parentUrl) => {
608
+ if (!resolveHook) return _resolve(id, parentUrl);
609
+ const result = resolveHook(id, parentUrl, defaultResolve);
448
610
 
449
- async function importHandler(id, opts, parentUrl = baseUrl, sourcePhase) {
450
- await initPromise; // needed for shim check
451
- console.info(
452
- `es-module-shims: importShim${sourcePhase ? '.source' : ''}("${id}"${opts ? ', ' + JSON.stringify(opts) : ''})`
453
- );
454
- if (importHook) await importHook(id, opts, parentUrl);
455
- if (shimMode || !baselinePassthrough) {
456
- if (hasDocument) processScriptsAndPreloads();
457
- legacyAcceptingImportMaps = false;
458
- }
459
- await importMapPromise;
460
- return resolve(id, parentUrl).r;
461
- }
611
+ return result ? { r: result, n: true, N: true } : _resolve(id, parentUrl);
612
+ };
462
613
 
463
614
  // import()
464
- async function importShim(id, opts, parentUrl) {
615
+ async function importShim$1(id, opts, parentUrl) {
465
616
  if (typeof opts === 'string') {
466
617
  parentUrl = opts;
467
618
  opts = undefined;
468
619
  }
469
- // we mock import('./x.css', { with: { type: 'css' }}) support via an inline static reexport
470
- // because we can't syntactically pass through to dynamic import with a second argument
471
- let url = await importHandler(id, opts, parentUrl, false);
472
- let source = null;
473
- if (typeof opts === 'object' && typeof opts.with === 'object' && typeof opts.with.type === 'string') {
474
- source = `export{default}from'${url}'with{type:"${opts.with.type}"}`;
475
- url += '?entry';
620
+ await initPromise; // needed for shim check
621
+ console.info(`es-module-shims: importShim("${id}"${opts ? ', ' + JSON.stringify(opts) : ''})`);
622
+ if (shimMode || !baselinePassthrough) {
623
+ if (hasDocument) processScriptsAndPreloads();
624
+ legacyAcceptingImportMaps = false;
625
+ }
626
+ let sourceType = undefined;
627
+ if (typeof opts === 'object') {
628
+ if (opts.lang === 'ts') sourceType = 'ts';
629
+ if (typeof opts.with === 'object' && typeof opts.with.type === 'string') {
630
+ sourceType = opts.with.type;
631
+ }
476
632
  }
477
- return topLevelLoad(url, { credentials: 'same-origin' }, source, undefined, undefined);
633
+ return topLevelLoad(
634
+ id,
635
+ parentUrl || baseUrl,
636
+ { credentials: 'same-origin' },
637
+ undefined,
638
+ undefined,
639
+ undefined,
640
+ sourceType
641
+ );
478
642
  }
479
643
 
480
644
  // import.source()
481
645
  // (opts not currently supported as no use cases yet)
482
646
  if (shimMode || wasmSourcePhaseEnabled)
483
- importShim.source = async function (specifier, opts, parentUrl) {
647
+ importShim$1.source = async (id, opts, parentUrl) => {
484
648
  if (typeof opts === 'string') {
485
649
  parentUrl = opts;
486
650
  opts = undefined;
487
651
  }
488
- const url = await importHandler(specifier, opts, parentUrl, true);
489
- const load = getOrCreateLoad(url, { credentials: 'same-origin' }, null, null);
652
+ await initPromise; // needed for shim check
653
+ console.info(`es-module-shims: importShim.source("${id}"${opts ? ', ' + JSON.stringify(opts) : ''})`);
654
+ if (shimMode || !baselinePassthrough) {
655
+ if (hasDocument) processScriptsAndPreloads();
656
+ legacyAcceptingImportMaps = false;
657
+ }
658
+ await importMapPromise;
659
+ const url = resolve(id, parentUrl || baseUrl).r;
660
+ const load = getOrCreateLoad(url, { credentials: 'same-origin' }, undefined, undefined);
490
661
  if (firstPolyfillLoad && !shimMode && load.n && nativelyLoaded) {
491
662
  onpolyfill();
492
663
  firstPolyfillLoad = false;
493
664
  }
494
665
  await load.f;
495
- return importShim._s[load.r];
666
+ return importShim$1._s[load.r];
496
667
  };
497
668
 
498
669
  // import.defer() is just a proxy for import(), since we can't actually defer
499
- if (shimMode || deferPhaseEnabled) importShim.defer = importShim;
670
+ if (shimMode || deferPhaseEnabled) importShim$1.defer = importShim$1;
500
671
 
501
- self.importShim = importShim;
672
+ if (hotReload) importShim$1.hotReload = hotReload$1;
502
673
 
503
- function defaultResolve(id, parentUrl) {
674
+ self.importShim = importShim$1;
675
+
676
+ const defaultResolve = (id, parentUrl) => {
504
677
  return (
505
678
  resolveImportMap(composedImportMap, resolveIfNotPlainOrUrl(id, parentUrl) || id, parentUrl) ||
506
679
  throwUnresolved(id, parentUrl)
507
680
  );
508
- }
681
+ };
509
682
 
510
- function throwUnresolved(id, parentUrl) {
683
+ const throwUnresolved = (id, parentUrl) => {
511
684
  throw Error(`Unable to resolve specifier '${id}'${fromParent(parentUrl)}`);
512
- }
685
+ };
513
686
 
514
- function metaResolve(id, parentUrl = this.url) {
687
+ const metaResolve = function (id, parentUrl = this.url) {
515
688
  return resolve(id, `${parentUrl}`).r;
516
- }
689
+ };
517
690
 
518
- importShim.resolve = (id, parentUrl) => resolve(id, parentUrl).r;
519
- importShim.getImportMap = () => JSON.parse(JSON.stringify(composedImportMap));
520
- importShim.addImportMap = importMapIn => {
691
+ importShim$1.resolve = (id, parentUrl) => resolve(id, parentUrl).r;
692
+ importShim$1.getImportMap = () => JSON.parse(JSON.stringify(composedImportMap));
693
+ importShim$1.addImportMap = importMapIn => {
521
694
  if (!shimMode) throw new Error('Unsupported in polyfill mode.');
522
695
  composedImportMap = resolveAndComposeImportMap(importMapIn, baseUrl, composedImportMap);
523
696
  };
524
697
 
525
- const registry = (importShim._r = {});
526
- const sourceCache = (importShim._s = {});
698
+ const registry = (importShim$1._r = {});
699
+ // Wasm caches
700
+ const sourceCache = (importShim$1._s = {});
701
+ (importShim$1._i = new WeakMap());
527
702
 
528
- async function loadAll(load, seen) {
703
+ const loadAll = async (load, seen) => {
529
704
  seen[load.u] = 1;
530
705
  await load.L;
531
706
  await Promise.all(
@@ -535,7 +710,7 @@
535
710
  return loadAll(dep, seen);
536
711
  })
537
712
  );
538
- }
713
+ };
539
714
 
540
715
  let importMapSrc = false;
541
716
  let multipleImportMaps = false;
@@ -548,43 +723,39 @@
548
723
  baselinePassthrough =
549
724
  esmsInitOptions.polyfillEnable !== true &&
550
725
  supportsImportMaps &&
551
- (!jsonModulesEnabled || supportsJsonType) &&
552
- (!cssModulesEnabled || supportsCssType) &&
726
+ supportsJsonType &&
727
+ supportsCssType &&
553
728
  (!wasmInstancePhaseEnabled || supportsWasmInstancePhase) &&
554
729
  (!wasmSourcePhaseEnabled || supportsWasmSourcePhase) &&
555
730
  !deferPhaseEnabled &&
556
731
  (!multipleImportMaps || supportsMultipleImportMaps) &&
557
- !importMapSrc &&
558
- !typescriptEnabled;
559
- if (
560
- !shimMode &&
561
- wasmSourcePhaseEnabled &&
562
- typeof WebAssembly !== 'undefined' &&
563
- !Object.getPrototypeOf(WebAssembly.Module).name
564
- ) {
565
- const s = Symbol();
566
- const brand = m =>
567
- Object.defineProperty(m, s, { writable: false, configurable: false, value: 'WebAssembly.Module' });
568
- class AbstractModuleSource {
569
- get [Symbol.toStringTag]() {
570
- if (this[s]) return this[s];
571
- throw new TypeError('Not an AbstractModuleSource');
732
+ !importMapSrc;
733
+ if (!shimMode && typeof WebAssembly !== 'undefined') {
734
+ if (wasmSourcePhaseEnabled && !Object.getPrototypeOf(WebAssembly.Module).name) {
735
+ const s = Symbol();
736
+ const brand = m =>
737
+ Object.defineProperty(m, s, { writable: false, configurable: false, value: 'WebAssembly.Module' });
738
+ class AbstractModuleSource {
739
+ get [Symbol.toStringTag]() {
740
+ if (this[s]) return this[s];
741
+ throw new TypeError('Not an AbstractModuleSource');
742
+ }
572
743
  }
744
+ const { Module: wasmModule, compile: wasmCompile, compileStreaming: wasmCompileStreaming } = WebAssembly;
745
+ WebAssembly.Module = Object.setPrototypeOf(
746
+ Object.assign(function Module(...args) {
747
+ return brand(new wasmModule(...args));
748
+ }, wasmModule),
749
+ AbstractModuleSource
750
+ );
751
+ WebAssembly.Module.prototype = Object.setPrototypeOf(wasmModule.prototype, AbstractModuleSource.prototype);
752
+ WebAssembly.compile = function compile(...args) {
753
+ return wasmCompile(...args).then(brand);
754
+ };
755
+ WebAssembly.compileStreaming = function compileStreaming(...args) {
756
+ return wasmCompileStreaming(...args).then(brand);
757
+ };
573
758
  }
574
- const { Module: wasmModule, compile: wasmCompile, compileStreaming: wasmCompileStreaming } = WebAssembly;
575
- WebAssembly.Module = Object.setPrototypeOf(
576
- Object.assign(function Module(...args) {
577
- return brand(new wasmModule(...args));
578
- }, wasmModule),
579
- AbstractModuleSource
580
- );
581
- WebAssembly.Module.prototype = Object.setPrototypeOf(wasmModule.prototype, AbstractModuleSource.prototype);
582
- WebAssembly.compile = function compile(...args) {
583
- return wasmCompile(...args).then(brand);
584
- };
585
- WebAssembly.compileStreaming = function compileStreaming(...args) {
586
- return wasmCompileStreaming(...args).then(brand);
587
- };
588
759
  }
589
760
  if (hasDocument) {
590
761
  if (!supportsImportMaps) {
@@ -596,14 +767,6 @@
596
767
  if (document.readyState === 'complete') {
597
768
  readyStateCompleteCheck();
598
769
  } else {
599
- async function readyListener() {
600
- await initPromise;
601
- processScriptsAndPreloads();
602
- if (document.readyState === 'complete') {
603
- readyStateCompleteCheck();
604
- document.removeEventListener('readystatechange', readyListener);
605
- }
606
- }
607
770
  document.addEventListener('readystatechange', readyListener);
608
771
  }
609
772
  }
@@ -612,7 +775,7 @@
612
775
  return undefined;
613
776
  });
614
777
 
615
- function attachMutationObserver() {
778
+ const attachMutationObserver = () => {
616
779
  const observer = new MutationObserver(mutations => {
617
780
  for (const mutation of mutations) {
618
781
  if (mutation.type !== 'childList') continue;
@@ -633,26 +796,34 @@
633
796
  observer.observe(document, { childList: true });
634
797
  observer.observe(document.head, { childList: true });
635
798
  processScriptsAndPreloads();
636
- }
799
+ };
637
800
 
638
801
  let importMapPromise = initPromise;
639
802
  let firstPolyfillLoad = true;
640
803
  let legacyAcceptingImportMaps = true;
641
804
 
642
- async function topLevelLoad(url, fetchOpts, source, nativelyLoaded, lastStaticLoadPromise) {
643
- legacyAcceptingImportMaps = false;
805
+ const topLevelLoad = async (url, parentUrl, fetchOpts, source, nativelyLoaded, lastStaticLoadPromise, sourceType) => {
644
806
  await initPromise;
645
807
  await importMapPromise;
646
- if (importHook) await importHook(url, typeof fetchOpts !== 'string' ? fetchOpts : {}, '');
808
+ url = (await resolve(url, parentUrl)).r;
809
+
810
+ // we mock import('./x.css', { with: { type: 'css' }}) support via an inline static reexport
811
+ // because we can't syntactically pass through to dynamic import with a second argument
812
+ if (sourceType === 'css' || sourceType === 'json') {
813
+ source = `export{default}from'${url}'with{type:"${sourceType}"}`;
814
+ url += '?entry';
815
+ }
816
+
817
+ if (importHook) await importHook(url, typeof fetchOpts !== 'string' ? fetchOpts : {}, parentUrl);
647
818
  // early analysis opt-out - no need to even fetch if we have feature support
648
- if (!shimMode && baselinePassthrough) {
819
+ if (!shimMode && baselinePassthrough && nativePassthrough && sourceType !== 'ts') {
649
820
  console.info(`es-module-shims: early exit for ${url} due to baseline modules support`);
650
821
  // for polyfill case, only dynamic import needs a return value here, and dynamic import will never pass nativelyLoaded
651
822
  if (nativelyLoaded) return null;
652
823
  await lastStaticLoadPromise;
653
824
  return dynamicImport(source ? createBlob(source) : url);
654
825
  }
655
- const load = getOrCreateLoad(url, fetchOpts, null, source);
826
+ const load = getOrCreateLoad(url, fetchOpts, undefined, source);
656
827
  linkLoad(load, fetchOpts);
657
828
  const seen = {};
658
829
  await loadAll(load, seen);
@@ -673,37 +844,55 @@
673
844
  onpolyfill();
674
845
  firstPolyfillLoad = false;
675
846
  }
676
- const module = await (!shimMode && !load.n && !load.N ? import(load.u) : dynamicImport(load.b, load.u));
847
+ const module = await (shimMode || load.n || load.N || !nativePassthrough || (!nativelyLoaded && source) ?
848
+ dynamicImport(load.b, load.u)
849
+ : import(load.u));
677
850
  // if the top-level load is a shell, run its update function
678
851
  if (load.s) (await dynamicImport(load.s, load.u)).u$_(module);
679
852
  if (revokeBlobURLs) revokeObjectURLs(Object.keys(seen));
680
- // when tla is supported, this should return the tla promise as an actual handle
681
- // so readystate can still correspond to the sync subgraph exec completions
682
853
  return module;
683
- }
854
+ };
684
855
 
685
- function revokeObjectURLs(registryKeys) {
686
- let batch = 0;
687
- const keysLength = registryKeys.length;
688
- const schedule = self.requestIdleCallback ? self.requestIdleCallback : self.requestAnimationFrame;
689
- schedule(cleanup);
856
+ const revokeObjectURLs = registryKeys => {
857
+ let curIdx = 0;
858
+ const handler = self.requestIdleCallback || self.requestAnimationFrame;
859
+ handler(cleanup);
690
860
  function cleanup() {
691
- const batchStartIndex = batch * 100;
692
- if (batchStartIndex > keysLength) return;
693
- for (const key of registryKeys.slice(batchStartIndex, batchStartIndex + 100)) {
861
+ for (const key of registryKeys.slice(curIdx, (curIdx += 100))) {
694
862
  const load = registry[key];
695
- if (load && load.b) URL.revokeObjectURL(load.b);
863
+ if (load && load.b && load.b !== load.u) URL.revokeObjectURL(load.b);
696
864
  }
697
- batch++;
698
- schedule(cleanup);
865
+ if (curIdx < registryKeys.length) handler(cleanup);
699
866
  }
700
- }
867
+ };
701
868
 
702
- function urlJsString(url) {
703
- return `'${url.replace(/'/g, "\\'")}'`;
704
- }
869
+ const urlJsString = url => `'${url.replace(/'/g, "\\'")}'`;
705
870
 
706
- function resolveDeps(load, seen) {
871
+ let resolvedSource, lastIndex;
872
+ const pushStringTo = (load, originalIndex, dynamicImportEndStack) => {
873
+ while (dynamicImportEndStack[dynamicImportEndStack.length - 1] < originalIndex) {
874
+ const dynamicImportEnd = dynamicImportEndStack.pop();
875
+ resolvedSource += `${load.S.slice(lastIndex, dynamicImportEnd)}, ${urlJsString(load.r)}`;
876
+ lastIndex = dynamicImportEnd;
877
+ }
878
+ resolvedSource += load.S.slice(lastIndex, originalIndex);
879
+ lastIndex = originalIndex;
880
+ };
881
+
882
+ const pushSourceURL = (load, commentPrefix, commentStart, dynamicImportEndStack) => {
883
+ const urlStart = commentStart + commentPrefix.length;
884
+ const commentEnd = load.S.indexOf('\n', urlStart);
885
+ const urlEnd = commentEnd !== -1 ? commentEnd : load.S.length;
886
+ let sourceUrl = load.S.slice(urlStart, urlEnd);
887
+ try {
888
+ sourceUrl = new URL(sourceUrl, load.r).href;
889
+ } catch {}
890
+ pushStringTo(load, urlStart, dynamicImportEndStack);
891
+ resolvedSource += sourceUrl;
892
+ lastIndex = urlEnd;
893
+ };
894
+
895
+ const resolveDeps = (load, seen) => {
707
896
  if (load.b || !seen[load.u]) return;
708
897
  seen[load.u] = 0;
709
898
 
@@ -716,7 +905,7 @@
716
905
 
717
906
  // use native loader whenever possible (n = needs shim) via executable subgraph passthrough
718
907
  // so long as the module doesn't use dynamic import or unsupported URL mappings (N = should shim)
719
- if (!shimMode && !load.n && !load.N) {
908
+ if (nativePassthrough && !shimMode && !load.n && !load.N) {
720
909
  load.b = load.u;
721
910
  load.S = undefined;
722
911
  return;
@@ -727,38 +916,36 @@
727
916
  const [imports, exports] = load.a;
728
917
 
729
918
  // "execution"
730
- const source = load.S;
731
-
732
- let resolvedSource = '';
919
+ let source = load.S,
920
+ depIndex = 0,
921
+ dynamicImportEndStack = [];
733
922
 
734
923
  // once all deps have loaded we can inline the dependency resolution blobs
735
924
  // and define this blob
736
- let lastIndex = 0,
737
- depIndex = 0,
738
- dynamicImportEndStack = [];
739
- function pushStringTo(originalIndex) {
740
- while (dynamicImportEndStack[dynamicImportEndStack.length - 1] < originalIndex) {
741
- const dynamicImportEnd = dynamicImportEndStack.pop();
742
- resolvedSource += `${source.slice(lastIndex, dynamicImportEnd)}, ${urlJsString(load.r)}`;
743
- lastIndex = dynamicImportEnd;
744
- }
745
- resolvedSource += source.slice(lastIndex, originalIndex);
746
- lastIndex = originalIndex;
747
- }
925
+ (resolvedSource = ''), (lastIndex = 0);
748
926
 
749
927
  for (const { s: start, e: end, ss: statementStart, se: statementEnd, d: dynamicImportIndex, t, a } of imports) {
750
928
  // source phase
751
929
  if (t === 4) {
752
930
  let { l: depLoad } = load.d[depIndex++];
753
- pushStringTo(statementStart);
931
+ pushStringTo(load, statementStart, dynamicImportEndStack);
754
932
  resolvedSource += `${source.slice(statementStart, start - 1).replace('source', '')}/*${source.slice(start - 1, end + 1)}*/'${createBlob(`export default importShim._s[${urlJsString(depLoad.r)}]`)}'`;
755
933
  lastIndex = end + 1;
756
934
  }
757
935
  // dependency source replacements
758
936
  else if (dynamicImportIndex === -1) {
937
+ let keepAssertion = false;
938
+ if (a > 0 && !shimMode) {
939
+ const assertion = source.slice(a, statementEnd - 1);
940
+ // strip assertions only when unsupported in polyfill mode
941
+ keepAssertion =
942
+ nativePassthrough &&
943
+ ((supportsJsonType && assertion.includes('json')) || (supportsCssType && assertion.includes('css')));
944
+ }
945
+
759
946
  // defer phase stripping
760
947
  if (t === 6) {
761
- pushStringTo(statementStart);
948
+ pushStringTo(load, statementStart, dynamicImportEndStack);
762
949
  resolvedSource += source.slice(statementStart, start - 1).replace('defer', '');
763
950
  lastIndex = start;
764
951
  }
@@ -783,10 +970,7 @@
783
970
  }
784
971
  }
785
972
 
786
- // strip import assertions unless we support them
787
- const stripAssertion = (!supportsCssType && !supportsJsonType) || !(a > 0);
788
-
789
- pushStringTo(start - 1);
973
+ pushStringTo(load, start - 1, dynamicImportEndStack);
790
974
  resolvedSource += `/*${source.slice(start - 1, end + 1)}*/'${blobUrl}'`;
791
975
 
792
976
  // circular shell execution
@@ -794,19 +978,19 @@
794
978
  resolvedSource += `;import*as m$_${depIndex} from'${depLoad.b}';import{u$_ as u$_${depIndex}}from'${depLoad.s}';u$_${depIndex}(m$_${depIndex})`;
795
979
  depLoad.s = undefined;
796
980
  }
797
- lastIndex = stripAssertion ? statementEnd : end + 1;
981
+ lastIndex = keepAssertion ? end + 1 : statementEnd;
798
982
  }
799
983
  // import.meta
800
984
  else if (dynamicImportIndex === -2) {
801
985
  load.m = { url: load.r, resolve: metaResolve };
802
- metaHook(load.m, load.u);
803
- pushStringTo(start);
986
+ if (metaHook) metaHook(load.m, load.u);
987
+ pushStringTo(load, start, dynamicImportEndStack);
804
988
  resolvedSource += `importShim._r[${urlJsString(load.u)}].m`;
805
989
  lastIndex = statementEnd;
806
990
  }
807
991
  // dynamic import
808
992
  else {
809
- pushStringTo(statementStart + 6);
993
+ pushStringTo(load, statementStart + 6, dynamicImportEndStack);
810
994
  resolvedSource += `Shim${t === 5 ? '.source' : ''}(`;
811
995
  dynamicImportEndStack.push(statementEnd - 1);
812
996
  lastIndex = start;
@@ -820,19 +1004,6 @@
820
1004
  .map(({ s, e, ln }) => `${source.slice(s, e)}:${ln}`)
821
1005
  .join(',')}})}catch(_){};\n`;
822
1006
 
823
- function pushSourceURL(commentPrefix, commentStart) {
824
- const urlStart = commentStart + commentPrefix.length;
825
- const commentEnd = source.indexOf('\n', urlStart);
826
- const urlEnd = commentEnd !== -1 ? commentEnd : source.length;
827
- let sourceUrl = source.slice(urlStart, urlEnd);
828
- try {
829
- sourceUrl = new URL(sourceUrl, load.r).href;
830
- } catch {}
831
- pushStringTo(urlStart);
832
- resolvedSource += sourceUrl;
833
- lastIndex = urlEnd;
834
- }
835
-
836
1007
  let sourceURLCommentStart = source.lastIndexOf(sourceURLCommentPrefix);
837
1008
  let sourceMapURLCommentStart = source.lastIndexOf(sourceMapURLCommentPrefix);
838
1009
 
@@ -845,23 +1016,23 @@
845
1016
  sourceURLCommentStart !== -1 &&
846
1017
  (sourceMapURLCommentStart === -1 || sourceMapURLCommentStart > sourceURLCommentStart)
847
1018
  ) {
848
- pushSourceURL(sourceURLCommentPrefix, sourceURLCommentStart);
1019
+ pushSourceURL(load, sourceURLCommentPrefix, sourceURLCommentStart, dynamicImportEndStack);
849
1020
  }
850
1021
  // sourceMappingURL
851
1022
  if (sourceMapURLCommentStart !== -1) {
852
- pushSourceURL(sourceMapURLCommentPrefix, sourceMapURLCommentStart);
1023
+ pushSourceURL(load, sourceMapURLCommentPrefix, sourceMapURLCommentStart, dynamicImportEndStack);
853
1024
  // sourceURL last
854
1025
  if (sourceURLCommentStart !== -1 && sourceURLCommentStart > sourceMapURLCommentStart)
855
- pushSourceURL(sourceURLCommentPrefix, sourceURLCommentStart);
1026
+ pushSourceURL(load, sourceURLCommentPrefix, sourceURLCommentStart, dynamicImportEndStack);
856
1027
  }
857
1028
 
858
- pushStringTo(source.length);
1029
+ pushStringTo(load, source.length, dynamicImportEndStack);
859
1030
 
860
1031
  if (sourceURLCommentStart === -1) resolvedSource += sourceURLCommentPrefix + load.r;
861
1032
 
862
1033
  load.b = createBlob(resolvedSource);
863
- load.S = undefined;
864
- }
1034
+ load.S = resolvedSource = undefined;
1035
+ };
865
1036
 
866
1037
  const sourceURLCommentPrefix = '\n//# sourceURL=';
867
1038
  const sourceMapURLCommentPrefix = '\n//# sourceMappingURL=';
@@ -877,15 +1048,15 @@
877
1048
  // restrict in-flight fetches to a pool of 100
878
1049
  let p = [];
879
1050
  let c = 0;
880
- function pushFetchPool() {
1051
+ const pushFetchPool = () => {
881
1052
  if (++c > 100) return new Promise(r => p.push(r));
882
- }
883
- function popFetchPool() {
1053
+ };
1054
+ const popFetchPool = () => {
884
1055
  c--;
885
1056
  if (p.length) p.shift()();
886
- }
1057
+ };
887
1058
 
888
- async function doFetch(url, fetchOpts, parent) {
1059
+ const doFetch = async (url, fetchOpts, parent) => {
889
1060
  if (enforceIntegrity && !fetchOpts.integrity) throw Error(`No integrity for ${url}${fromParent(parent)}.`);
890
1061
  const poolQueue = pushFetchPool();
891
1062
  if (poolQueue) await poolQueue;
@@ -904,15 +1075,16 @@
904
1075
  throw error;
905
1076
  }
906
1077
  return res;
907
- }
1078
+ };
908
1079
 
909
1080
  let esmsTsTransform;
910
- async function initTs() {
1081
+ const initTs = async () => {
911
1082
  const m = await import(tsTransform);
912
1083
  if (!esmsTsTransform) esmsTsTransform = m.transform;
913
- }
1084
+ };
914
1085
 
915
- async function fetchModule(url, fetchOpts, parent) {
1086
+ const hotPrefix = 'var h=import.meta.hot,';
1087
+ const fetchModule = async (url, fetchOpts, parent) => {
916
1088
  const mapIntegrity = composedImportMap.integrity[url];
917
1089
  const res = await doFetch(
918
1090
  url,
@@ -923,69 +1095,68 @@
923
1095
  const contentType = res.headers.get('content-type');
924
1096
  if (jsContentType.test(contentType)) return { r, s: await res.text(), t: 'js' };
925
1097
  else if (wasmContentType.test(contentType)) {
926
- const module = await (sourceCache[r] || (sourceCache[r] = WebAssembly.compileStreaming(res)));
927
- sourceCache[r] = module;
928
- let s = '',
1098
+ const wasmModule = await (sourceCache[r] || (sourceCache[r] = WebAssembly.compileStreaming(res)));
1099
+ const exports = WebAssembly.Module.exports(wasmModule);
1100
+ sourceCache[r] = wasmModule;
1101
+ const rStr = urlJsString(r);
1102
+ let s = `import*as $_ns from${rStr};`,
929
1103
  i = 0,
930
- importObj = '';
931
- for (const impt of WebAssembly.Module.imports(module)) {
932
- const specifier = urlJsString(impt.module);
933
- s += `import * as impt${i} from ${specifier};\n`;
934
- importObj += `${specifier}:impt${i++},`;
1104
+ obj = '';
1105
+ for (const { module, kind } of WebAssembly.Module.imports(wasmModule)) {
1106
+ const specifier = urlJsString(module);
1107
+ s += `import*as impt${i} from${specifier};\n`;
1108
+ obj += `${specifier}:${kind === 'global' ? `importShim._i.get(impt${i})||impt${i++}` : `impt${i++}`},`;
935
1109
  }
936
- i = 0;
937
- s += `const instance = await WebAssembly.instantiate(importShim._s[${urlJsString(r)}], {${importObj}});\n`;
938
- for (const expt of WebAssembly.Module.exports(module)) {
939
- s += `export const ${expt.name} = instance.exports['${expt.name}'];\n`;
1110
+ s += `${hotPrefix}i=await WebAssembly.instantiate(importShim._s[${rStr}],{${obj}});importShim._i.set($_ns,i);`;
1111
+ obj = '';
1112
+ for (const { name, kind } of exports) {
1113
+ s += `export let ${name}=i.exports['${name}'];`;
1114
+ if (kind === 'global') s += `try{${name}=${name}.value}catch{${name}=undefined}`;
1115
+ obj += `${name},`;
940
1116
  }
1117
+ s += `if(h)h.accept(m=>({${obj}}=m))`;
941
1118
  return { r, s, t: 'wasm' };
942
- } else if (jsonContentType.test(contentType)) return { r, s: `export default ${await res.text()}`, t: 'json' };
1119
+ } else if (jsonContentType.test(contentType))
1120
+ return { r, s: `${hotPrefix}j=${await res.text()};export{j as default};if(h)h.accept(m=>j=m.default)`, t: 'json' };
943
1121
  else if (cssContentType.test(contentType)) {
944
1122
  return {
945
1123
  r,
946
- s: `var s=new CSSStyleSheet();s.replaceSync(${JSON.stringify(
1124
+ s: `${hotPrefix}s=h&&h.data.s||new CSSStyleSheet();s.replaceSync(${JSON.stringify(
947
1125
  (await res.text()).replace(
948
1126
  cssUrlRegEx,
949
1127
  (_match, quotes = '', relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`
950
1128
  )
951
- )});export default s;`,
1129
+ )});if(h){h.data.s=s;h.accept(()=>{})}export default s`,
952
1130
  t: 'css'
953
1131
  };
954
- } else if (
955
- (shimMode || typescriptEnabled) &&
956
- (tsContentType.test(contentType) || url.endsWith('.ts') || url.endsWith('.mts'))
957
- ) {
1132
+ } else if (tsContentType.test(contentType) || url.endsWith('.ts') || url.endsWith('.mts')) {
958
1133
  const source = await res.text();
959
1134
  if (!esmsTsTransform) await initTs();
960
1135
  const transformed = esmsTsTransform(source, url);
961
- return { r, s: transformed === undefined ? source : transformed, t: transformed !== undefined ? 'ts' : 'js' };
1136
+ // even if the TypeScript is valid JavaScript, unless it was a top-level inline source, it wasn't served with
1137
+ // a valid JS MIME here, so we must still polyfill it
1138
+ return { r, s: transformed === undefined ? source : transformed, t: 'ts' };
962
1139
  } else
963
1140
  throw Error(
964
1141
  `Unsupported Content-Type "${contentType}" loading ${url}${fromParent(parent)}. Modules must be served with a valid MIME type like application/javascript.`
965
1142
  );
966
- }
1143
+ };
967
1144
 
968
- function isUnsupportedType(type) {
969
- if (
970
- (type === 'css' && !cssModulesEnabled) ||
971
- (type === 'json' && !jsonModulesEnabled) ||
972
- (type === 'wasm' && !wasmInstancePhaseEnabled && !wasmSourcePhaseEnabled) ||
973
- (type === 'ts' && !typescriptEnabled)
974
- )
975
- throw featErr(`${type}-modules`);
1145
+ const isUnsupportedType = type => {
1146
+ if (type === 'wasm' && !wasmInstancePhaseEnabled && !wasmSourcePhaseEnabled) throw featErr(`wasm-modules`);
976
1147
  return (
977
1148
  (type === 'css' && !supportsCssType) ||
978
1149
  (type === 'json' && !supportsJsonType) ||
979
1150
  (type === 'wasm' && !supportsWasmInstancePhase && !supportsWasmSourcePhase) ||
980
1151
  type === 'ts'
981
1152
  );
982
- }
1153
+ };
983
1154
 
984
- function getOrCreateLoad(url, fetchOpts, parent, source) {
1155
+ const getOrCreateLoad = (url, fetchOpts, parent, source) => {
985
1156
  if (source && registry[url]) {
986
1157
  let i = 0;
987
- while (registry[url + ++i]);
988
- url += i;
1158
+ while (registry[url + '?' + ++i]);
1159
+ url += '?' + i;
989
1160
  }
990
1161
  let load = registry[url];
991
1162
  if (load) return load;
@@ -1008,9 +1179,9 @@
1008
1179
  b: undefined,
1009
1180
  // shellUrl
1010
1181
  s: undefined,
1011
- // needsShim
1182
+ // needsShim: does it fail execution in the current native loader?
1012
1183
  n: false,
1013
- // shouldShim
1184
+ // shouldShim: does it need to be loaded by the polyfill loader?
1014
1185
  N: false,
1015
1186
  // type
1016
1187
  t: null,
@@ -1018,7 +1189,7 @@
1018
1189
  m: null
1019
1190
  };
1020
1191
  load.f = (async () => {
1021
- if (!load.S) {
1192
+ if (load.S === undefined) {
1022
1193
  // preload fetch options override fetch options (race)
1023
1194
  ({ r: load.r, s: load.S, t: load.t } = await (fetchCache[url] || fetchModule(url, fetchOpts, parent)));
1024
1195
  if (!load.n && load.t !== 'js' && !shimMode && isUnsupportedType(load.t)) {
@@ -1034,29 +1205,37 @@
1034
1205
  return load;
1035
1206
  })();
1036
1207
  return load;
1037
- }
1208
+ };
1038
1209
 
1039
1210
  const featErr = feat =>
1040
1211
  Error(
1041
1212
  `${feat} feature must be enabled via <script type="esms-options">{ "polyfillEnable": ["${feat}"] }<${''}/script>`
1042
1213
  );
1043
1214
 
1044
- function linkLoad(load, fetchOpts) {
1215
+ const linkLoad = (load, fetchOpts) => {
1045
1216
  if (load.L) return;
1046
1217
  load.L = load.f.then(async () => {
1047
1218
  let childFetchOpts = fetchOpts;
1048
1219
  load.d = load.a[0]
1049
- .map(({ n, d, t, a }) => {
1220
+ .map(({ n, d, t, a, se }) => {
1050
1221
  const phaseImport = t >= 4;
1051
1222
  const sourcePhase = phaseImport && t < 6;
1052
1223
  if (phaseImport) {
1053
1224
  if (!shimMode && (sourcePhase ? !wasmSourcePhaseEnabled : !deferPhaseEnabled))
1054
- throw featErr(sourcePhase ? 'source-phase' : 'defer-phase');
1225
+ throw featErr(sourcePhase ? 'wasm-module-sources' : 'import-defer');
1055
1226
  if (!sourcePhase || !supportsWasmSourcePhase) load.n = true;
1056
1227
  }
1057
- if (a > 0) {
1058
- if (!shimMode && !cssModulesEnabled && !jsonModulesEnabled) throw featErr('css-modules / json-modules');
1059
- if (!supportsCssType && !supportsJsonType) load.n = true;
1228
+ let source = undefined;
1229
+ if (a > 0 && !shimMode && nativePassthrough) {
1230
+ const assertion = load.S.slice(a, se - 1);
1231
+ // no need to fetch JSON/CSS if supported, since it's a leaf node, we'll just strip the assertion syntax
1232
+ if (assertion.includes('json')) {
1233
+ if (supportsJsonType) source = '';
1234
+ else load.n = true;
1235
+ } else if (assertion.includes('css')) {
1236
+ if (supportsCssType) source = '';
1237
+ else load.n = true;
1238
+ }
1060
1239
  }
1061
1240
  if (d !== -1 || !n) return;
1062
1241
  const resolved = resolve(n, load.r || load.u);
@@ -1065,16 +1244,18 @@
1065
1244
  if (d !== -1) return;
1066
1245
  if (skip && skip(resolved.r) && !sourcePhase) return { l: { b: resolved.r }, s: false };
1067
1246
  if (childFetchOpts.integrity) childFetchOpts = Object.assign({}, childFetchOpts, { integrity: undefined });
1068
- const child = { l: getOrCreateLoad(resolved.r, childFetchOpts, load.r, null), s: sourcePhase };
1247
+ const child = { l: getOrCreateLoad(resolved.r, childFetchOpts, load.r, source), s: sourcePhase };
1248
+ // assertion case -> inline the CSS / JSON URL directly
1249
+ if (source === '') child.l.b = child.l.u;
1069
1250
  if (!child.s) linkLoad(child.l, fetchOpts);
1070
1251
  // load, sourcePhase
1071
1252
  return child;
1072
1253
  })
1073
1254
  .filter(l => l);
1074
1255
  });
1075
- }
1256
+ };
1076
1257
 
1077
- function processScriptsAndPreloads() {
1258
+ const processScriptsAndPreloads = () => {
1078
1259
  for (const link of document.querySelectorAll(shimMode ? 'link[rel=modulepreload-shim]' : 'link[rel=modulepreload]')) {
1079
1260
  if (!link.ep) processPreload(link);
1080
1261
  }
@@ -1086,9 +1267,9 @@
1086
1267
  if (!script.ep) processScript(script);
1087
1268
  }
1088
1269
  }
1089
- }
1270
+ };
1090
1271
 
1091
- function getFetchOpts(script) {
1272
+ const getFetchOpts = script => {
1092
1273
  const fetchOpts = {};
1093
1274
  if (script.integrity) fetchOpts.integrity = script.integrity;
1094
1275
  if (script.referrerPolicy) fetchOpts.referrerPolicy = script.referrerPolicy;
@@ -1097,43 +1278,68 @@
1097
1278
  else if (script.crossOrigin === 'anonymous') fetchOpts.credentials = 'omit';
1098
1279
  else fetchOpts.credentials = 'same-origin';
1099
1280
  return fetchOpts;
1100
- }
1281
+ };
1101
1282
 
1102
1283
  let lastStaticLoadPromise = Promise.resolve();
1103
1284
 
1285
+ let domContentLoaded = false;
1104
1286
  let domContentLoadedCnt = 1;
1105
- function domContentLoadedCheck() {
1287
+ const domContentLoadedCheck = m => {
1288
+ if (m === undefined) {
1289
+ if (domContentLoaded) return;
1290
+ domContentLoaded = true;
1291
+ domContentLoadedCnt--;
1292
+ }
1106
1293
  if (--domContentLoadedCnt === 0 && !noLoadEventRetriggers && (shimMode || !baselinePassthrough)) {
1107
1294
  console.info(`es-module-shims: DOMContentLoaded refire`);
1295
+ document.removeEventListener('DOMContentLoaded', domContentLoadedEvent);
1108
1296
  document.dispatchEvent(new Event('DOMContentLoaded'));
1109
1297
  }
1110
- }
1298
+ };
1111
1299
  let loadCnt = 1;
1112
- function loadCheck() {
1300
+ const loadCheck = () => {
1113
1301
  if (--loadCnt === 0 && !noLoadEventRetriggers && (shimMode || !baselinePassthrough)) {
1114
1302
  console.info(`es-module-shims: load refire`);
1303
+ window.removeEventListener('load', loadEvent);
1115
1304
  window.dispatchEvent(new Event('load'));
1116
1305
  }
1117
- }
1306
+ };
1307
+
1308
+ const domContentLoadedEvent = async () => {
1309
+ await initPromise;
1310
+ domContentLoadedCheck();
1311
+ };
1312
+ const loadEvent = async () => {
1313
+ await initPromise;
1314
+ domContentLoadedCheck();
1315
+ loadCheck();
1316
+ };
1317
+
1118
1318
  // this should always trigger because we assume es-module-shims is itself a domcontentloaded requirement
1119
1319
  if (hasDocument) {
1120
- document.addEventListener('DOMContentLoaded', async () => {
1121
- await initPromise;
1122
- domContentLoadedCheck();
1123
- });
1124
- window.addEventListener('load', async () => {
1125
- await initPromise;
1126
- loadCheck();
1127
- });
1320
+ document.addEventListener('DOMContentLoaded', domContentLoadedEvent);
1321
+ window.addEventListener('load', loadEvent);
1128
1322
  }
1129
1323
 
1324
+ const readyListener = async () => {
1325
+ await initPromise;
1326
+ processScriptsAndPreloads();
1327
+ if (document.readyState === 'complete') {
1328
+ readyStateCompleteCheck();
1329
+ }
1330
+ };
1331
+
1130
1332
  let readyStateCompleteCnt = 1;
1131
- function readyStateCompleteCheck() {
1132
- if (--readyStateCompleteCnt === 0 && !noLoadEventRetriggers && (shimMode || !baselinePassthrough)) {
1133
- console.info(`es-module-shims: readystatechange complete refire`);
1134
- document.dispatchEvent(new Event('readystatechange'));
1333
+ const readyStateCompleteCheck = () => {
1334
+ if (--readyStateCompleteCnt === 0) {
1335
+ domContentLoadedCheck();
1336
+ if (!noLoadEventRetriggers && (shimMode || !baselinePassthrough)) {
1337
+ console.info(`es-module-shims: readystatechange complete refire`);
1338
+ document.removeEventListener('readystatechange', readyListener);
1339
+ document.dispatchEvent(new Event('readystatechange'));
1340
+ }
1135
1341
  }
1136
- }
1342
+ };
1137
1343
 
1138
1344
  const hasNext = script => script.nextSibling || (script.parentNode && hasNext(script.parentNode));
1139
1345
  const epCheck = (script, ready) =>
@@ -1142,7 +1348,7 @@
1142
1348
  script.getAttribute('noshim') !== null ||
1143
1349
  !(script.ep = true);
1144
1350
 
1145
- function processImportMap(script, ready = readyStateCompleteCnt > 0) {
1351
+ const processImportMap = (script, ready = readyStateCompleteCnt > 0) => {
1146
1352
  if (epCheck(script, ready)) return;
1147
1353
  console.info(`es-module-shims: reading import map`);
1148
1354
  // we dont currently support external import maps in polyfill mode to match native
@@ -1173,56 +1379,64 @@
1173
1379
  }
1174
1380
  }
1175
1381
  legacyAcceptingImportMaps = false;
1176
- }
1382
+ };
1177
1383
 
1178
- function processScript(script, ready = readyStateCompleteCnt > 0) {
1384
+ const processScript = (script, ready = readyStateCompleteCnt > 0) => {
1179
1385
  if (epCheck(script, ready)) return;
1180
- if (script.lang === 'ts' && !script.src) {
1181
- const source = script.innerHTML;
1182
- return initTs()
1386
+ console.info(`es-module-shims: checking script ${script.src || '<inline>'}`);
1387
+ // does this load block readystate complete
1388
+ const isBlockingReadyScript = script.getAttribute('async') === null && readyStateCompleteCnt > 0;
1389
+ // does this load block DOMContentLoaded
1390
+ const isDomContentLoadedScript = domContentLoadedCnt > 0;
1391
+ const isLoadScript = loadCnt > 0;
1392
+ if (isLoadScript) loadCnt++;
1393
+ if (isBlockingReadyScript) readyStateCompleteCnt++;
1394
+ if (isDomContentLoadedScript) domContentLoadedCnt++;
1395
+ let loadPromise;
1396
+ const ts = script.lang === 'ts';
1397
+ if (ts && !script.src) {
1398
+ loadPromise = Promise.resolve(esmsTsTransform || initTs())
1183
1399
  .then(() => {
1184
- const transformed = esmsTsTransform(source, baseUrl);
1400
+ const transformed = esmsTsTransform(script.innerHTML, baseUrl);
1185
1401
  if (transformed !== undefined) {
1186
1402
  onpolyfill();
1187
1403
  firstPolyfillLoad = false;
1188
1404
  }
1189
1405
  return topLevelLoad(
1406
+ script.src || baseUrl,
1190
1407
  baseUrl,
1191
1408
  getFetchOpts(script),
1192
- transformed === undefined ? source : transformed,
1193
- transformed === undefined,
1194
- undefined
1409
+ transformed === undefined ? script.innerHTML : transformed,
1410
+ !shimMode && transformed === undefined,
1411
+ isBlockingReadyScript && lastStaticLoadPromise,
1412
+ 'ts'
1195
1413
  );
1196
1414
  })
1197
1415
  .catch(throwError);
1416
+ } else {
1417
+ loadPromise = topLevelLoad(
1418
+ script.src || baseUrl,
1419
+ baseUrl,
1420
+ getFetchOpts(script),
1421
+ !script.src ? script.innerHTML : undefined,
1422
+ !shimMode,
1423
+ isBlockingReadyScript && lastStaticLoadPromise,
1424
+ 'ts'
1425
+ ).catch(throwError);
1198
1426
  }
1199
- console.info(`es-module-shims: checking script ${script.src || '<inline>'}`);
1200
- // does this load block readystate complete
1201
- const isBlockingReadyScript = script.getAttribute('async') === null && readyStateCompleteCnt > 0;
1202
- // does this load block DOMContentLoaded
1203
- const isDomContentLoadedScript = domContentLoadedCnt > 0;
1204
- const isLoadScript = loadCnt > 0;
1205
- if (isLoadScript) loadCnt++;
1206
- if (isBlockingReadyScript) readyStateCompleteCnt++;
1207
- if (isDomContentLoadedScript) domContentLoadedCnt++;
1208
- const loadPromise = topLevelLoad(
1209
- script.src || baseUrl,
1210
- getFetchOpts(script),
1211
- !script.src && script.innerHTML,
1212
- !shimMode,
1213
- isBlockingReadyScript && lastStaticLoadPromise
1214
- ).catch(throwError);
1215
1427
  if (!noLoadEventRetriggers) loadPromise.then(() => script.dispatchEvent(new Event('load')));
1216
- if (isBlockingReadyScript) lastStaticLoadPromise = loadPromise.then(readyStateCompleteCheck);
1428
+ if (isBlockingReadyScript && !ts) {
1429
+ lastStaticLoadPromise = loadPromise.then(readyStateCompleteCheck);
1430
+ }
1217
1431
  if (isDomContentLoadedScript) loadPromise.then(domContentLoadedCheck);
1218
1432
  if (isLoadScript) loadPromise.then(loadCheck);
1219
- }
1433
+ };
1220
1434
 
1221
1435
  const fetchCache = {};
1222
- function processPreload(link) {
1436
+ const processPreload = link => {
1223
1437
  link.ep = true;
1224
1438
  if (fetchCache[link.href]) return;
1225
1439
  fetchCache[link.href] = fetchModule(link.href, getFetchOpts(link));
1226
- }
1440
+ };
1227
1441
 
1228
1442
  })();