es-module-shims 1.10.1 → 2.0.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,4 +1,4 @@
1
- /* ES Module Shims DEBUG BUILD 1.10.1 */
1
+ /* ES Module Shims DEBUG BUILD 2.0.0 */
2
2
  (function () {
3
3
 
4
4
  const hasDocument = typeof document !== 'undefined';
@@ -10,7 +10,13 @@
10
10
  const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
11
11
  Object.assign(esmsInitOptions, self.esmsInitOptions || {});
12
12
 
13
- let shimMode = hasDocument ? !!esmsInitOptions.shimMode : true;
13
+ // shim mode is determined on initialization, no late shim mode
14
+ const shimMode =
15
+ hasDocument ?
16
+ esmsInitOptions.shimMode ||
17
+ document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
18
+ .length > 0
19
+ : true;
14
20
 
15
21
  const importHook = globalHook(shimMode && esmsInitOptions.onimport);
16
22
  const resolveHook = globalHook(shimMode && esmsInitOptions.resolve);
@@ -22,15 +28,14 @@
22
28
  let nonce = esmsInitOptions.nonce;
23
29
  if (!nonce && hasDocument) {
24
30
  const nonceElement = document.querySelector('script[nonce]');
25
- if (nonceElement)
26
- nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
31
+ if (nonceElement) nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
27
32
  }
28
33
 
29
34
  const onerror = globalHook(esmsInitOptions.onerror || noop);
30
35
 
31
- const { revokeBlobURLs, noLoadEventRetriggers, globalLoadEventRetrigger, enforceIntegrity } = esmsInitOptions;
36
+ const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
32
37
 
33
- function globalHook (name) {
38
+ function globalHook(name) {
34
39
  return typeof name === 'string' ? self[name] : name;
35
40
  }
36
41
 
@@ -40,25 +45,30 @@
40
45
  const wasmModulesEnabled = enable.includes('wasm-modules');
41
46
  const sourcePhaseEnabled = enable.includes('source-phase');
42
47
 
43
- const onpolyfill = esmsInitOptions.onpolyfill ? globalHook(esmsInitOptions.onpolyfill) : () => {
44
- console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
45
- };
48
+ const onpolyfill =
49
+ esmsInitOptions.onpolyfill ?
50
+ globalHook(esmsInitOptions.onpolyfill)
51
+ : () => {
52
+ console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
53
+ };
46
54
 
47
55
  const edge = !navigator.userAgentData && !!navigator.userAgent.match(/Edge\/\d+\.\d+/);
48
56
 
49
- const baseUrl = hasDocument
50
- ? document.baseURI
51
- : `${location.protocol}//${location.host}${location.pathname.includes('/')
52
- ? location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
53
- : location.pathname}`;
57
+ const baseUrl =
58
+ hasDocument ?
59
+ document.baseURI
60
+ : `${location.protocol}//${location.host}${
61
+ location.pathname.includes('/') ?
62
+ location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
63
+ : location.pathname
64
+ }`;
54
65
 
55
66
  const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
56
67
  let { skip } = esmsInitOptions;
57
68
  if (Array.isArray(skip)) {
58
69
  const l = skip.map(s => new URL(s, baseUrl).href);
59
- skip = s => l.some(i => i[i.length - 1] === '/' && s.startsWith(i) || s === i);
60
- }
61
- else if (typeof skip === 'string') {
70
+ skip = s => l.some(i => (i[i.length - 1] === '/' && s.startsWith(i)) || s === i);
71
+ } else if (typeof skip === 'string') {
62
72
  const r = new RegExp(skip);
63
73
  skip = s => r.test(s);
64
74
  } else if (skip instanceof RegExp) {
@@ -67,418 +77,466 @@
67
77
 
68
78
  const dispatchError = error => self.dispatchEvent(Object.assign(new Event('error'), { error }));
69
79
 
70
- const throwError = err => { (self.reportError || dispatchError)(err), void onerror(err); };
80
+ const throwError = err => {
81
+ (self.reportError || dispatchError)(err), void onerror(err);
82
+ };
71
83
 
72
- function fromParent (parent) {
84
+ function fromParent(parent) {
73
85
  return parent ? ` imported from ${parent}` : '';
74
- }
75
-
76
- let importMapSrcOrLazy = false;
77
-
78
- function setImportMapSrcOrLazy () {
79
- importMapSrcOrLazy = true;
80
- }
81
-
82
- // shim mode is determined on initialization, no late shim mode
83
- if (!shimMode) {
84
- if (document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]').length) {
85
- shimMode = true;
86
- }
87
- else {
88
- let seenScript = false;
89
- for (const script of document.querySelectorAll('script[type=module],script[type=importmap]')) {
90
- if (!seenScript) {
91
- if (script.type === 'module' && !script.ep)
92
- seenScript = true;
93
- }
94
- else if (script.type === 'importmap' && seenScript) {
95
- importMapSrcOrLazy = true;
96
- break;
97
- }
98
- }
99
- }
100
86
  }
101
87
 
102
- const backslashRegEx = /\\/g;
103
-
104
- function asURL (url) {
105
- try {
106
- if (url.indexOf(':') !== -1)
107
- return new URL(url).href;
108
- }
109
- catch (_) {}
110
- }
111
-
112
- function resolveUrl (relUrl, parentUrl) {
113
- return resolveIfNotPlainOrUrl(relUrl, parentUrl) || (asURL(relUrl) || resolveIfNotPlainOrUrl('./' + relUrl, parentUrl));
114
- }
115
-
116
- function resolveIfNotPlainOrUrl (relUrl, parentUrl) {
117
- const hIdx = parentUrl.indexOf('#'), qIdx = parentUrl.indexOf('?');
118
- if (hIdx + qIdx > -2)
119
- parentUrl = parentUrl.slice(0, hIdx === -1 ? qIdx : qIdx === -1 || qIdx > hIdx ? hIdx : qIdx);
120
- if (relUrl.indexOf('\\') !== -1)
121
- relUrl = relUrl.replace(backslashRegEx, '/');
122
- // protocol-relative
123
- if (relUrl[0] === '/' && relUrl[1] === '/') {
124
- return parentUrl.slice(0, parentUrl.indexOf(':') + 1) + relUrl;
125
- }
126
- // relative-url
127
- else if (relUrl[0] === '.' && (relUrl[1] === '/' || relUrl[1] === '.' && (relUrl[2] === '/' || relUrl.length === 2 && (relUrl += '/')) ||
128
- relUrl.length === 1 && (relUrl += '/')) ||
129
- relUrl[0] === '/') {
130
- const parentProtocol = parentUrl.slice(0, parentUrl.indexOf(':') + 1);
131
- if (parentProtocol === 'blob:') {
132
- throw new TypeError(`Failed to resolve module specifier "${relUrl}". Invalid relative url or base scheme isn't hierarchical.`);
133
- }
134
- // Disabled, but these cases will give inconsistent results for deep backtracking
135
- //if (parentUrl[parentProtocol.length] !== '/')
136
- // throw new Error('Cannot resolve');
137
- // read pathname from parent URL
138
- // pathname taken to be part after leading "/"
139
- let pathname;
140
- if (parentUrl[parentProtocol.length + 1] === '/') {
141
- // resolving to a :// so we need to read out the auth and host
142
- if (parentProtocol !== 'file:') {
143
- pathname = parentUrl.slice(parentProtocol.length + 2);
144
- pathname = pathname.slice(pathname.indexOf('/') + 1);
145
- }
146
- else {
147
- pathname = parentUrl.slice(8);
148
- }
149
- }
150
- else {
151
- // resolving to :/ so pathname is the /... part
152
- pathname = parentUrl.slice(parentProtocol.length + (parentUrl[parentProtocol.length] === '/'));
153
- }
154
-
155
- if (relUrl[0] === '/')
156
- return parentUrl.slice(0, parentUrl.length - pathname.length - 1) + relUrl;
157
-
158
- // join together and split for removal of .. and . segments
159
- // looping the string instead of anything fancy for perf reasons
160
- // '../../../../../z' resolved to 'x/y' is just 'z'
161
- const segmented = pathname.slice(0, pathname.lastIndexOf('/') + 1) + relUrl;
162
-
163
- const output = [];
164
- let segmentIndex = -1;
165
- for (let i = 0; i < segmented.length; i++) {
166
- // busy reading a segment - only terminate on '/'
167
- if (segmentIndex !== -1) {
168
- if (segmented[i] === '/') {
169
- output.push(segmented.slice(segmentIndex, i + 1));
170
- segmentIndex = -1;
171
- }
172
- continue;
173
- }
174
- // new segment - check if it is relative
175
- else if (segmented[i] === '.') {
176
- // ../ segment
177
- if (segmented[i + 1] === '.' && (segmented[i + 2] === '/' || i + 2 === segmented.length)) {
178
- output.pop();
179
- i += 2;
180
- continue;
181
- }
182
- // ./ segment
183
- else if (segmented[i + 1] === '/' || i + 1 === segmented.length) {
184
- i += 1;
185
- continue;
186
- }
187
- }
188
- // it is the start of a new segment
189
- while (segmented[i] === '/') i++;
190
- segmentIndex = i;
191
- }
192
- // finish reading out the last segment
193
- if (segmentIndex !== -1)
194
- output.push(segmented.slice(segmentIndex));
195
- return parentUrl.slice(0, parentUrl.length - pathname.length) + output.join('');
196
- }
197
- }
198
-
199
- function resolveAndComposeImportMap (json, baseUrl, parentMap) {
200
- const outMap = { imports: Object.assign({}, parentMap.imports), scopes: Object.assign({}, parentMap.scopes), integrity: Object.assign({}, parentMap.integrity) };
201
-
202
- if (json.imports)
203
- resolveAndComposePackages(json.imports, outMap.imports, baseUrl, parentMap);
204
-
205
- if (json.scopes)
206
- for (let s in json.scopes) {
207
- const resolvedScope = resolveUrl(s, baseUrl);
208
- resolveAndComposePackages(json.scopes[s], outMap.scopes[resolvedScope] || (outMap.scopes[resolvedScope] = {}), baseUrl, parentMap);
209
- }
210
-
211
- if (json.integrity)
212
- resolveAndComposeIntegrity(json.integrity, outMap.integrity, baseUrl);
213
-
214
- return outMap;
215
- }
216
-
217
- function getMatch (path, matchObj) {
218
- if (matchObj[path])
219
- return path;
220
- let sepIndex = path.length;
221
- do {
222
- const segment = path.slice(0, sepIndex + 1);
223
- if (segment in matchObj)
224
- return segment;
225
- } while ((sepIndex = path.lastIndexOf('/', sepIndex - 1)) !== -1)
226
- }
227
-
228
- function applyPackages (id, packages) {
229
- const pkgName = getMatch(id, packages);
230
- if (pkgName) {
231
- const pkg = packages[pkgName];
232
- if (pkg === null) return;
233
- return pkg + id.slice(pkgName.length);
234
- }
235
- }
236
-
237
-
238
- function resolveImportMap (importMap, resolvedOrPlain, parentUrl) {
239
- let scopeUrl = parentUrl && getMatch(parentUrl, importMap.scopes);
240
- while (scopeUrl) {
241
- const packageResolution = applyPackages(resolvedOrPlain, importMap.scopes[scopeUrl]);
242
- if (packageResolution)
243
- return packageResolution;
244
- scopeUrl = getMatch(scopeUrl.slice(0, scopeUrl.lastIndexOf('/')), importMap.scopes);
245
- }
246
- return applyPackages(resolvedOrPlain, importMap.imports) || resolvedOrPlain.indexOf(':') !== -1 && resolvedOrPlain;
247
- }
248
-
249
- function resolveAndComposePackages (packages, outPackages, baseUrl, parentMap) {
250
- for (let p in packages) {
251
- const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
252
- if ((!shimMode || !mapOverrides) && outPackages[resolvedLhs] && (outPackages[resolvedLhs] !== packages[resolvedLhs])) {
253
- throw Error(`Rejected map override "${resolvedLhs}" from ${outPackages[resolvedLhs]} to ${packages[resolvedLhs]}.`);
254
- }
255
- let target = packages[p];
256
- if (typeof target !== 'string')
257
- continue;
258
- const mapped = resolveImportMap(parentMap, resolveIfNotPlainOrUrl(target, baseUrl) || target, baseUrl);
259
- if (mapped) {
260
- outPackages[resolvedLhs] = mapped;
261
- continue;
262
- }
263
- console.warn(`Mapping "${p}" -> "${packages[p]}" does not resolve`);
264
- }
265
- }
266
-
267
- function resolveAndComposeIntegrity (integrity, outIntegrity, baseUrl) {
268
- for (let p in integrity) {
269
- const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
270
- if ((!shimMode || !mapOverrides) && outIntegrity[resolvedLhs] && (outIntegrity[resolvedLhs] !== integrity[resolvedLhs])) {
271
- throw Error(`Rejected map integrity override "${resolvedLhs}" from ${outIntegrity[resolvedLhs]} to ${integrity[resolvedLhs]}.`);
272
- }
273
- outIntegrity[resolvedLhs] = integrity[p];
274
- }
88
+ const backslashRegEx = /\\/g;
89
+
90
+ function asURL(url) {
91
+ try {
92
+ if (url.indexOf(':') !== -1) return new URL(url).href;
93
+ } catch (_) {}
275
94
  }
276
95
 
277
- let dynamicImport = !hasDocument && (0, eval)('u=>import(u)');
278
-
279
- let supportsDynamicImport;
280
-
281
- const dynamicImportCheck = hasDocument && new Promise(resolve => {
282
- const s = Object.assign(document.createElement('script'), {
283
- src: createBlob('self._d=u=>import(u)'),
284
- ep: true
285
- });
286
- s.setAttribute('nonce', nonce);
287
- s.addEventListener('load', () => {
288
- if (!(supportsDynamicImport = !!(dynamicImport = self._d))) {
289
- let err;
290
- window.addEventListener('error', _err => err = _err);
291
- dynamicImport = (url, opts) => new Promise((resolve, reject) => {
292
- const s = Object.assign(document.createElement('script'), {
293
- type: 'module',
294
- src: createBlob(`import*as m from'${url}';self._esmsi=m`)
295
- });
296
- err = undefined;
297
- s.ep = true;
298
- if (nonce)
299
- s.setAttribute('nonce', nonce);
300
- // Safari is unique in supporting module script error events
301
- s.addEventListener('error', cb);
302
- s.addEventListener('load', cb);
303
- function cb (_err) {
304
- document.head.removeChild(s);
305
- if (self._esmsi) {
306
- resolve(self._esmsi, baseUrl);
307
- self._esmsi = undefined;
308
- }
309
- else {
310
- reject(!(_err instanceof Event) && _err || err && err.error || new Error(`Error loading ${opts && opts.errUrl || url} (${s.src}).`));
311
- err = undefined;
312
- }
313
- }
314
- document.head.appendChild(s);
315
- });
316
- }
317
- document.head.removeChild(s);
318
- delete self._d;
319
- resolve();
320
- });
321
- document.head.appendChild(s);
96
+ function resolveUrl(relUrl, parentUrl) {
97
+ return resolveIfNotPlainOrUrl(relUrl, parentUrl) || asURL(relUrl) || resolveIfNotPlainOrUrl('./' + relUrl, parentUrl);
98
+ }
99
+
100
+ function resolveIfNotPlainOrUrl(relUrl, parentUrl) {
101
+ const hIdx = parentUrl.indexOf('#'),
102
+ qIdx = parentUrl.indexOf('?');
103
+ if (hIdx + qIdx > -2)
104
+ parentUrl = parentUrl.slice(
105
+ 0,
106
+ hIdx === -1 ? qIdx
107
+ : qIdx === -1 || qIdx > hIdx ? hIdx
108
+ : qIdx
109
+ );
110
+ if (relUrl.indexOf('\\') !== -1) relUrl = relUrl.replace(backslashRegEx, '/');
111
+ // protocol-relative
112
+ if (relUrl[0] === '/' && relUrl[1] === '/') {
113
+ return parentUrl.slice(0, parentUrl.indexOf(':') + 1) + relUrl;
114
+ }
115
+ // relative-url
116
+ else if (
117
+ (relUrl[0] === '.' &&
118
+ (relUrl[1] === '/' ||
119
+ (relUrl[1] === '.' && (relUrl[2] === '/' || (relUrl.length === 2 && (relUrl += '/')))) ||
120
+ (relUrl.length === 1 && (relUrl += '/')))) ||
121
+ relUrl[0] === '/'
122
+ ) {
123
+ const parentProtocol = parentUrl.slice(0, parentUrl.indexOf(':') + 1);
124
+ if (parentProtocol === 'blob:') {
125
+ throw new TypeError(
126
+ `Failed to resolve module specifier "${relUrl}". Invalid relative url or base scheme isn't hierarchical.`
127
+ );
128
+ }
129
+ // Disabled, but these cases will give inconsistent results for deep backtracking
130
+ //if (parentUrl[parentProtocol.length] !== '/')
131
+ // throw new Error('Cannot resolve');
132
+ // read pathname from parent URL
133
+ // pathname taken to be part after leading "/"
134
+ let pathname;
135
+ if (parentUrl[parentProtocol.length + 1] === '/') {
136
+ // resolving to a :// so we need to read out the auth and host
137
+ if (parentProtocol !== 'file:') {
138
+ pathname = parentUrl.slice(parentProtocol.length + 2);
139
+ pathname = pathname.slice(pathname.indexOf('/') + 1);
140
+ } else {
141
+ pathname = parentUrl.slice(8);
142
+ }
143
+ } else {
144
+ // resolving to :/ so pathname is the /... part
145
+ pathname = parentUrl.slice(parentProtocol.length + (parentUrl[parentProtocol.length] === '/'));
146
+ }
147
+
148
+ if (relUrl[0] === '/') return parentUrl.slice(0, parentUrl.length - pathname.length - 1) + relUrl;
149
+
150
+ // join together and split for removal of .. and . segments
151
+ // looping the string instead of anything fancy for perf reasons
152
+ // '../../../../../z' resolved to 'x/y' is just 'z'
153
+ const segmented = pathname.slice(0, pathname.lastIndexOf('/') + 1) + relUrl;
154
+
155
+ const output = [];
156
+ let segmentIndex = -1;
157
+ for (let i = 0; i < segmented.length; i++) {
158
+ // busy reading a segment - only terminate on '/'
159
+ if (segmentIndex !== -1) {
160
+ if (segmented[i] === '/') {
161
+ output.push(segmented.slice(segmentIndex, i + 1));
162
+ segmentIndex = -1;
163
+ }
164
+ continue;
165
+ }
166
+ // new segment - check if it is relative
167
+ else if (segmented[i] === '.') {
168
+ // ../ segment
169
+ if (segmented[i + 1] === '.' && (segmented[i + 2] === '/' || i + 2 === segmented.length)) {
170
+ output.pop();
171
+ i += 2;
172
+ continue;
173
+ }
174
+ // ./ segment
175
+ else if (segmented[i + 1] === '/' || i + 1 === segmented.length) {
176
+ i += 1;
177
+ continue;
178
+ }
179
+ }
180
+ // it is the start of a new segment
181
+ while (segmented[i] === '/') i++;
182
+ segmentIndex = i;
183
+ }
184
+ // finish reading out the last segment
185
+ if (segmentIndex !== -1) output.push(segmented.slice(segmentIndex));
186
+ return parentUrl.slice(0, parentUrl.length - pathname.length) + output.join('');
187
+ }
188
+ }
189
+
190
+ function resolveAndComposeImportMap(json, baseUrl, parentMap) {
191
+ const outMap = {
192
+ imports: Object.assign({}, parentMap.imports),
193
+ scopes: Object.assign({}, parentMap.scopes),
194
+ integrity: Object.assign({}, parentMap.integrity)
195
+ };
196
+
197
+ if (json.imports) resolveAndComposePackages(json.imports, outMap.imports, baseUrl, parentMap);
198
+
199
+ if (json.scopes)
200
+ for (let s in json.scopes) {
201
+ const resolvedScope = resolveUrl(s, baseUrl);
202
+ resolveAndComposePackages(
203
+ json.scopes[s],
204
+ outMap.scopes[resolvedScope] || (outMap.scopes[resolvedScope] = {}),
205
+ baseUrl,
206
+ parentMap
207
+ );
208
+ }
209
+
210
+ if (json.integrity) resolveAndComposeIntegrity(json.integrity, outMap.integrity, baseUrl);
211
+
212
+ return outMap;
213
+ }
214
+
215
+ function getMatch(path, matchObj) {
216
+ if (matchObj[path]) return path;
217
+ let sepIndex = path.length;
218
+ do {
219
+ const segment = path.slice(0, sepIndex + 1);
220
+ if (segment in matchObj) return segment;
221
+ } while ((sepIndex = path.lastIndexOf('/', sepIndex - 1)) !== -1);
222
+ }
223
+
224
+ function applyPackages(id, packages) {
225
+ const pkgName = getMatch(id, packages);
226
+ if (pkgName) {
227
+ const pkg = packages[pkgName];
228
+ if (pkg === null) return;
229
+ return pkg + id.slice(pkgName.length);
230
+ }
231
+ }
232
+
233
+ function resolveImportMap(importMap, resolvedOrPlain, parentUrl) {
234
+ let scopeUrl = parentUrl && getMatch(parentUrl, importMap.scopes);
235
+ while (scopeUrl) {
236
+ const packageResolution = applyPackages(resolvedOrPlain, importMap.scopes[scopeUrl]);
237
+ if (packageResolution) return packageResolution;
238
+ scopeUrl = getMatch(scopeUrl.slice(0, scopeUrl.lastIndexOf('/')), importMap.scopes);
239
+ }
240
+ return applyPackages(resolvedOrPlain, importMap.imports) || (resolvedOrPlain.indexOf(':') !== -1 && resolvedOrPlain);
241
+ }
242
+
243
+ function resolveAndComposePackages(packages, outPackages, baseUrl, parentMap) {
244
+ for (let p in packages) {
245
+ const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
246
+ if (
247
+ (!shimMode || !mapOverrides) &&
248
+ outPackages[resolvedLhs] &&
249
+ outPackages[resolvedLhs] !== packages[resolvedLhs]
250
+ ) {
251
+ console.warn(
252
+ `es-module-shims: Rejected map override "${resolvedLhs}" from ${outPackages[resolvedLhs]} to ${packages[resolvedLhs]}.`
253
+ );
254
+ continue;
255
+ }
256
+ let target = packages[p];
257
+ if (typeof target !== 'string') continue;
258
+ const mapped = resolveImportMap(parentMap, resolveIfNotPlainOrUrl(target, baseUrl) || target, baseUrl);
259
+ if (mapped) {
260
+ outPackages[resolvedLhs] = mapped;
261
+ continue;
262
+ }
263
+ console.warn(`es-module-shims: Mapping "${p}" -> "${packages[p]}" does not resolve`);
264
+ }
265
+ }
266
+
267
+ function resolveAndComposeIntegrity(integrity, outIntegrity, baseUrl) {
268
+ for (let p in integrity) {
269
+ const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
270
+ if (
271
+ (!shimMode || !mapOverrides) &&
272
+ outIntegrity[resolvedLhs] &&
273
+ outIntegrity[resolvedLhs] !== integrity[resolvedLhs]
274
+ ) {
275
+ console.warn(
276
+ `es-module-shims: Rejected map integrity override "${resolvedLhs}" from ${outIntegrity[resolvedLhs]} to ${integrity[resolvedLhs]}.`
277
+ );
278
+ }
279
+ outIntegrity[resolvedLhs] = integrity[p];
280
+ }
281
+ }
282
+
283
+ let dynamicImport = !hasDocument && (0, eval)('u=>import(u)');
284
+
285
+ let supportsDynamicImport;
286
+
287
+ const dynamicImportCheck =
288
+ hasDocument &&
289
+ new Promise(resolve => {
290
+ const s = Object.assign(document.createElement('script'), {
291
+ src: createBlob('self._d=u=>import(u)'),
292
+ ep: true
293
+ });
294
+ s.setAttribute('nonce', nonce);
295
+ s.addEventListener('load', () => {
296
+ if (!(supportsDynamicImport = !!(dynamicImport = self._d))) {
297
+ let err;
298
+ window.addEventListener('error', _err => (err = _err));
299
+ dynamicImport = (url, opts) =>
300
+ new Promise((resolve, reject) => {
301
+ const s = Object.assign(document.createElement('script'), {
302
+ type: 'module',
303
+ src: createBlob(`import*as m from'${url}';self._esmsi=m`)
304
+ });
305
+ err = undefined;
306
+ s.ep = true;
307
+ if (nonce) s.setAttribute('nonce', nonce);
308
+ // Safari is unique in supporting module script error events
309
+ s.addEventListener('error', cb);
310
+ s.addEventListener('load', cb);
311
+ function cb(_err) {
312
+ document.head.removeChild(s);
313
+ if (self._esmsi) {
314
+ resolve(self._esmsi, baseUrl);
315
+ self._esmsi = undefined;
316
+ } else {
317
+ reject(
318
+ (!(_err instanceof Event) && _err) ||
319
+ (err && err.error) ||
320
+ new Error(`Error loading ${(opts && opts.errUrl) || url} (${s.src}).`)
321
+ );
322
+ err = undefined;
323
+ }
324
+ }
325
+ document.head.appendChild(s);
326
+ });
327
+ }
328
+ document.head.removeChild(s);
329
+ delete self._d;
330
+ resolve();
331
+ });
332
+ document.head.appendChild(s);
333
+ });
334
+
335
+ // support browsers without dynamic import support (eg Firefox 6x)
336
+ let supportsJsonType = false;
337
+ let supportsCssType = false;
338
+
339
+ const supports = hasDocument && HTMLScriptElement.supports;
340
+
341
+ let supportsImportMaps = supports && supports.name === 'supports' && supports('importmap');
342
+ let supportsImportMeta = supportsDynamicImport;
343
+ let supportsWasmModules = false;
344
+ let supportsSourcePhase = false;
345
+ let supportsMultipleImportMaps = false;
346
+
347
+ const wasmBytes = [0, 97, 115, 109, 1, 0, 0, 0];
348
+
349
+ let featureDetectionPromise = Promise.resolve(dynamicImportCheck).then(() => {
350
+ if (!supportsDynamicImport) return;
351
+ if (!hasDocument)
352
+ return Promise.all([
353
+ supportsImportMaps || dynamicImport(createBlob('import.meta')).then(() => (supportsImportMeta = true), noop),
354
+ cssModulesEnabled &&
355
+ dynamicImport(createBlob(`import"${createBlob('', 'text/css')}"with{type:"css"}`)).then(
356
+ () => (supportsCssType = true),
357
+ noop
358
+ ),
359
+ jsonModulesEnabled &&
360
+ dynamicImport(createBlob(`import"${createBlob('{}', 'text/json')}"with{type:"json"}`)).then(
361
+ () => (supportsJsonType = true),
362
+ noop
363
+ ),
364
+ wasmModulesEnabled &&
365
+ dynamicImport(createBlob(`import"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
366
+ () => (supportsWasmModules = true),
367
+ noop
368
+ ),
369
+ wasmModulesEnabled &&
370
+ sourcePhaseEnabled &&
371
+ dynamicImport(
372
+ createBlob(`import source x from"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)
373
+ ).then(() => (supportsSourcePhase = true), noop)
374
+ ]);
375
+
376
+ return new Promise(resolve => {
377
+ const iframe = document.createElement('iframe');
378
+ iframe.style.display = 'none';
379
+ iframe.setAttribute('nonce', nonce);
380
+ function cb({ data }) {
381
+ const isFeatureDetectionMessage = Array.isArray(data) && data[0] === 'esms';
382
+ if (!isFeatureDetectionMessage) return;
383
+ [
384
+ ,
385
+ supportsImportMaps,
386
+ supportsImportMeta,
387
+ supportsMultipleImportMaps,
388
+ supportsCssType,
389
+ supportsJsonType,
390
+ supportsWasmModules,
391
+ supportsSourcePhase
392
+ ] = data;
393
+ resolve();
394
+ document.head.removeChild(iframe);
395
+ window.removeEventListener('message', cb, false);
396
+ }
397
+ window.addEventListener('message', cb, false);
398
+
399
+ const importMapTest = `<script nonce=${nonce || ''}>b=(s,type='text/javascript')=>URL.createObjectURL(new Blob([s],{type}));i=innerText=>document.head.appendChild(Object.assign(document.createElement('script'),{type:'importmap',nonce:"${nonce}",innerText}));i(\`{"imports":{"x":"\${b('')}"}}\`);i(\`{"imports":{"y":"\${b('')}"}}\`);Promise.all([${
400
+ supportsImportMaps ? 'true,true' : `'x',b('import.meta')`
401
+ },'y',${cssModulesEnabled ? `b(\`import"\${b('','text/css')}"with{type:"css"}\`)` : 'false'}, ${
402
+ jsonModulesEnabled ? `b(\`import"\${b('{}','text/json')\}"with{type:"json"}\`)` : 'false'
403
+ },${
404
+ wasmModulesEnabled ?
405
+ `b(\`import"\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`)`
406
+ : 'false'
407
+ },${
408
+ wasmModulesEnabled && sourcePhaseEnabled ?
409
+ `b(\`import source x from "\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`)`
410
+ : 'false'
411
+ }].map(x =>typeof x==='string'?import(x).then(()=>true,()=>false):x)).then(a=>parent.postMessage(['esms'].concat(a),'*'))<${''}/script>`;
412
+
413
+ // Safari will call onload eagerly on head injection, but we don't want the Wechat
414
+ // path to trigger before setting srcdoc, therefore we track the timing
415
+ let readyForOnload = false,
416
+ onloadCalledWhileNotReady = false;
417
+ function doOnload() {
418
+ if (!readyForOnload) {
419
+ onloadCalledWhileNotReady = true;
420
+ return;
421
+ }
422
+ // WeChat browser doesn't support setting srcdoc scripts
423
+ // But iframe sandboxes don't support contentDocument so we do this as a fallback
424
+ const doc = iframe.contentDocument;
425
+ if (doc && doc.head.childNodes.length === 0) {
426
+ const s = doc.createElement('script');
427
+ if (nonce) s.setAttribute('nonce', nonce);
428
+ s.innerHTML = importMapTest.slice(15 + (nonce ? nonce.length : 0), -9);
429
+ doc.head.appendChild(s);
430
+ }
431
+ }
432
+
433
+ iframe.onload = doOnload;
434
+ // WeChat browser requires append before setting srcdoc
435
+ document.head.appendChild(iframe);
436
+
437
+ // setting srcdoc is not supported in React native webviews on iOS
438
+ // setting src to a blob URL results in a navigation event in webviews
439
+ // document.write gives usability warnings
440
+ readyForOnload = true;
441
+ if ('srcdoc' in iframe) iframe.srcdoc = importMapTest;
442
+ else iframe.contentDocument.write(importMapTest);
443
+ // retrigger onload for Safari only if necessary
444
+ if (onloadCalledWhileNotReady) doOnload();
445
+ });
322
446
  });
323
447
 
324
- // support browsers without dynamic import support (eg Firefox 6x)
325
- let supportsJsonAssertions = false;
326
- let supportsCssAssertions = false;
327
-
328
- const supports = hasDocument && HTMLScriptElement.supports;
329
-
330
- let supportsImportMaps = supports && supports.name === 'supports' && supports('importmap');
331
- let supportsImportMeta = supportsDynamicImport;
332
- let supportsWasmModules = false;
333
- let supportsSourcePhase = false;
334
-
335
- const wasmBytes = [0,97,115,109,1,0,0,0];
336
-
337
- let featureDetectionPromise = Promise.resolve(dynamicImportCheck).then(() => {
338
- if (!supportsDynamicImport)
339
- return;
340
- if (!hasDocument)
341
- return Promise.all([
342
- supportsImportMaps || dynamicImport(createBlob('import.meta')).then(() => supportsImportMeta = true, noop),
343
- cssModulesEnabled && dynamicImport(createBlob(`import"${createBlob('', 'text/css')}"with{type:"css"}`)).then(() => supportsCssAssertions = true, noop),
344
- jsonModulesEnabled && dynamicImport(createBlob(`import"${createBlob('{}', 'text/json')}"with{type:"json"}`)).then(() => supportsJsonAssertions = true, noop),
345
- wasmModulesEnabled && dynamicImport(createBlob(`import"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(() => supportsWasmModules = true, noop),
346
- wasmModulesEnabled && sourcePhaseEnabled && dynamicImport(createBlob(`import source x from"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(() => supportsSourcePhase = true, noop),
347
- ]);
348
-
349
- return new Promise(resolve => {
350
- console.info(`es-module-shims: performing feature detections for ${`${supportsImportMaps ? '' : 'import maps, '}${cssModulesEnabled ? 'css modules, ' : ''}${jsonModulesEnabled ? 'json modules, ' : ''}${wasmModulesEnabled ? 'wasm modules, ' : ''}${wasmModulesEnabled && sourcePhaseEnabled ? 'source phase, ' : ''}`.slice(0, -2)}`);
351
- const iframe = document.createElement('iframe');
352
- iframe.style.display = 'none';
353
- iframe.setAttribute('nonce', nonce);
354
- function cb ({ data }) {
355
- const isFeatureDetectionMessage = Array.isArray(data) && data[0] === 'esms';
356
- if (!isFeatureDetectionMessage)
357
- return;
358
- [, supportsImportMaps, supportsImportMeta, supportsCssAssertions, supportsJsonAssertions, supportsWasmModules, supportsSourcePhase] = data;
359
- resolve();
360
- document.head.removeChild(iframe);
361
- window.removeEventListener('message', cb, false);
362
- }
363
- window.addEventListener('message', cb, false);
364
-
365
- const importMapTest = `<script nonce=${nonce || ''}>b=(s,type='text/javascript')=>URL.createObjectURL(new Blob([s],{type}));document.head.appendChild(Object.assign(document.createElement('script'),{type:'importmap',nonce:"${nonce}",innerText:\`{"imports":{"x":"\${b('')}"}}\`}));Promise.all([${
366
- supportsImportMaps ? 'true,true' : `'x',b('import.meta')`}, ${
367
- cssModulesEnabled ? `b(\`import"\${b('','text/css')}"with{type:"css"}\`)` : 'false'}, ${
368
- jsonModulesEnabled ? `b(\`import"\${b('{}','text/json')\}"with{type:"json"}\`)` : 'false'}, ${
369
- wasmModulesEnabled ? `b(\`import"\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`)` : 'false'}, ${
370
- wasmModulesEnabled && sourcePhaseEnabled ? `b(\`import source x from "\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`)` : 'false'}].map(x =>typeof x==='string'?import(x).then(()=>true,()=>false):x)).then(a=>parent.postMessage(['esms'].concat(a),'*'))<${''}/script>`;
371
-
372
- // Safari will call onload eagerly on head injection, but we don't want the Wechat
373
- // path to trigger before setting srcdoc, therefore we track the timing
374
- let readyForOnload = false, onloadCalledWhileNotReady = false;
375
- function doOnload () {
376
- if (!readyForOnload) {
377
- onloadCalledWhileNotReady = true;
378
- return;
379
- }
380
- // WeChat browser doesn't support setting srcdoc scripts
381
- // But iframe sandboxes don't support contentDocument so we do this as a fallback
382
- const doc = iframe.contentDocument;
383
- if (doc && doc.head.childNodes.length === 0) {
384
- const s = doc.createElement('script');
385
- if (nonce)
386
- s.setAttribute('nonce', nonce);
387
- s.innerHTML = importMapTest.slice(15 + (nonce ? nonce.length : 0), -9);
388
- doc.head.appendChild(s);
389
- }
390
- }
391
-
392
- iframe.onload = doOnload;
393
- // WeChat browser requires append before setting srcdoc
394
- document.head.appendChild(iframe);
395
-
396
- // setting srcdoc is not supported in React native webviews on iOS
397
- // setting src to a blob URL results in a navigation event in webviews
398
- // document.write gives usability warnings
399
- readyForOnload = true;
400
- if ('srcdoc' in iframe)
401
- iframe.srcdoc = importMapTest;
402
- else
403
- iframe.contentDocument.write(importMapTest);
404
- // retrigger onload for Safari only if necessary
405
- if (onloadCalledWhileNotReady) doOnload();
406
- });
407
- });
408
-
409
- featureDetectionPromise = featureDetectionPromise.then(() => {
410
- console.info(`es-module-shims: detected native support - ${supportsDynamicImport ? '' : 'no '}dynamic import, ${supportsImportMeta ? '' : 'no '}import meta, ${supportsImportMaps ? '' : 'no '}import maps`);
448
+ featureDetectionPromise = featureDetectionPromise.then(() => {
449
+ console.info(
450
+ `es-module-shims: detected native support - module types: (${[...(supportsJsonType ? ['json'] : []), ...(supportsCssType ? ['css'] : []), ...(supportsWasmModules ? 'wasm' : '')].join(', ')}), ${supportsMultipleImportMaps ? '' : 'no '}multiple import maps, ${supportsDynamicImport ? '' : 'no '}dynamic import, ${supportsImportMeta ? '' : 'no '}import meta, ${supportsImportMaps ? '' : 'no '}import maps`
451
+ );
411
452
  });
412
453
 
413
- /* es-module-lexer 1.5.4 */
454
+ /* es-module-lexer 1.6.0 */
414
455
  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="xportmportlassforetaourceromsyncunctionssertvoyiedelecontininstantybreareturdebuggeawaithrwhileifcatcfinallels";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,110)),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[804]=1;i[803]=0;s[399]=0;s[400]=0;f[69]=f[2];i[805]=0;f[68]=0;i[802]=0;f[70]=u+2048;f[71]=u;i[806]=0;e=(f[3]|0)+-2|0;f[72]=e;a=e+(f[66]<<1)|0;f[73]=a;e:while(1){r=e+2|0;f[72]=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[400]|0)==0?H(r)|0:0)?(m(e+4|0,16,10)|0)==0:0)?(k(),(i[804]|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[69]=f[72];}e=f[72]|0;a=f[73]|0;}if((t|0)==9){e=f[72]|0;f[69]=e;t=19;}else if((t|0)==16){i[804]=0;f[72]=e;t=19;}else if((t|0)==18)if(!(i[802]|0)){e=r;t=19;}else e=0;do{if((t|0)==19){e:while(1){a=e+2|0;f[72]=a;if(e>>>0>=(f[73]|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[400]|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[806]=1;t=91;}else t=91;break}case 40:{r=f[70]|0;e=s[400]|0;t=e&65535;f[r+(t<<3)>>2]=1;a=f[69]|0;s[400]=e+1<<16>>16;f[r+(t<<3)+4>>2]=a;t=91;break}case 41:{a=s[400]|0;if(!(a<<16>>16)){t=36;break e}r=a+-1<<16>>16;s[400]=r;t=s[399]|0;a=t&65535;if(t<<16>>16!=0?(f[(f[70]|0)+((r&65535)<<3)>>2]|0)==5:0){a=f[(f[71]|0)+(a+-1<<2)>>2]|0;r=a+4|0;if(!(f[r>>2]|0))f[r>>2]=(f[69]|0)+2;f[a+12>>2]=e+4;s[399]=t+-1<<16>>16;t=91;}else t=91;break}case 123:{t=f[69]|0;r=f[63]|0;e=t;do{if((s[t>>1]|0)==41&(r|0)!=0?(f[r+4>>2]|0)==(t|0):0){a=f[64]|0;f[63]=a;if(!a){f[59]=0;break}else {f[a+32>>2]=0;break}}}while(0);r=f[70]|0;a=s[400]|0;t=a&65535;f[r+(t<<3)>>2]=(i[806]|0)==0?2:6;s[400]=a+1<<16>>16;f[r+(t<<3)+4>>2]=e;i[806]=0;t=91;break}case 125:{e=s[400]|0;if(!(e<<16>>16)){t=49;break e}r=f[70]|0;t=e+-1<<16>>16;s[400]=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[69]|0;a=s[e>>1]|0;r:do{if(!(U(a)|0))if(a<<16>>16==41){r=s[400]|0;if(!(D(f[(f[70]|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[400]|0;t=65;}r:do{if((t|0)==65){t=0;if(r<<16>>16!=0?(c=f[70]|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[70]|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[805]|0)break r;break}default:{}}t=f[65]|0;if((t|0?e>>>0>=(f[t>>2]|0)>>>0:0)?e>>>0<=(f[t+4>>2]|0)>>>0:0){g();i[805]=0;t=91;break a}r=f[3]|0;do{if(e>>>0<=r>>>0)break;e=e+-2|0;f[69]=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[69]=e;}while(F(s[e>>1]|0)|0);if(j(e)|0){g();i[805]=0;t=91;break a}}i[805]=1;t=91;break a}}}while(0);g();i[805]=0;t=91;break a}}case 96:{r=f[70]|0;a=s[400]|0;t=a&65535;f[r+(t<<3)+4>>2]=f[69];s[400]=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[69]=f[72];}e=f[72]|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[802]|0)==0?(s[399]|s[400])<<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[72]|0;l=f[65]|0;g=k+12|0;f[72]=g;r=w(1)|0;e=f[72]|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[72]=e+2;e=w(1)|0;a=f[72]|0;while(1){if(W(e)|0){v(e);e=(f[72]|0)+2|0;f[72]=e;}else {q(e)|0;e=f[72]|0;}w(1)|0;e=A(a,e)|0;if(e<<16>>16==44){f[72]=(f[72]|0)+2;e=w(1)|0;}if(e<<16>>16==125){C=15;break}g=a;a=f[72]|0;if((a|0)==(g|0)){C=12;break}if(a>>>0>(f[73]|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[803]=1;f[72]=(f[72]|0)+2;break a}break}case 42:{f[72]=e+2;w(1)|0;g=f[72]|0;A(g,g)|0;break}default:{i[804]=0;switch(r<<16>>16){case 100:{k=e+14|0;f[72]=k;switch((w(1)|0)<<16>>16){case 97:{a=f[72]|0;if((m(a+2|0,72,8)|0)==0?(c=a+10|0,F(s[c>>1]|0)|0):0){f[72]=c;w(0)|0;C=22;}break}case 102:{C=22;break}case 99:{a=f[72]|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[72]=t,n=w(1)|0,n<<16>>16!=123):0){d=n;C=31;}break}default:{}}r:do{if((C|0)==22?(b=f[72]|0,(m(b+2|0,80,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[72]=r;a=w(1)|0;if(a<<16>>16==42){f[72]=(f[72]|0)+2;a=w(1)|0;}if(a<<16>>16!=40){d=a;C=31;}}}while(0);if((C|0)==31?(o=f[72]|0,q(d)|0,h=f[72]|0,h>>>0>o>>>0):0){O(e,k,o,h);f[72]=(f[72]|0)+-2;break e}O(e,k,0,0);f[72]=e+12;break e}case 97:{f[72]=e+10;w(0)|0;e=f[72]|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[72]=a;g=w(1)|0;C=f[72]|0;q(g)|0;g=f[72]|0;O(C,g,C,g);f[72]=(f[72]|0)+-2;break e}e=e+4|0;f[72]=e;break}case 108:case 118:break;default:break e}if((C|0)==35){f[72]=e+16;e=w(1)|0;if(e<<16>>16==42){f[72]=(f[72]|0)+2;e=w(1)|0;}C=f[72]|0;q(e)|0;g=f[72]|0;O(C,g,C,g);f[72]=(f[72]|0)+-2;break e}f[72]=e+6;i[804]=0;r=w(1)|0;e=f[72]|0;r=(q(r)|0|32)<<16>>16==123;t=f[72]|0;if(r){f[72]=t+2;g=w(1)|0;e=f[72]|0;q(g)|0;}r:while(1){a=f[72]|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[72]|0;if(a<<16>>16!=44){C=51;break}f[72]=e+2;a=w(1)|0;e=f[72]|0;switch(a<<16>>16){case 91:case 123:{C=51;break r}default:{}}q(a)|0;}if((C|0)==51)f[72]=e+-2;if(!r)break e;f[72]=t+-2;break e}}}while(0);g=(w(1)|0)<<16>>16==102;e=f[72]|0;if(g?(m(e+2|0,66,6)|0)==0:0){f[72]=e+8;u(k,w(1)|0,0);e=(l|0)==0?240: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[72]=e+-2;}}while(0);return}function l(){var e=0,a=0,r=0,t=0,c=0,n=0,b=0;c=f[72]|0;r=c+12|0;f[72]=r;t=w(1)|0;a=f[72]|0;e:do{if(t<<16>>16!=46)if(t<<16>>16==115&a>>>0>r>>>0)if((m(a+2|0,56,10)|0)==0?(e=a+12|0,V(s[e>>1]|0)|0):0)n=14;else {a=6;r=0;n=46;}else {e=t;r=0;n=15;}else {f[72]=a+2;switch((w(1)|0)<<16>>16){case 109:{e=f[72]|0;if(m(e+2|0,50,6)|0)break e;a=f[69]|0;if(!(G(a)|0)?(s[a>>1]|0)==46:0)break e;d(c,c,e+8|0,2);break e}case 115:{e=f[72]|0;if(m(e+2|0,56,10)|0)break e;a=f[69]|0;if(!(G(a)|0)?(s[a>>1]|0)==46:0)break e;e=e+12|0;n=14;break e}default:break e}}}while(0);if((n|0)==14){f[72]=e;e=w(1)|0;r=1;n=15;}e:do{if((n|0)==15)switch(e<<16>>16){case 40:{a=f[70]|0;b=s[400]|0;t=b&65535;f[a+(t<<3)>>2]=5;e=f[72]|0;s[400]=b+1<<16>>16;f[a+(t<<3)+4>>2]=e;if((s[f[69]>>1]|0)==46)break e;f[72]=e+2;a=w(1)|0;d(c,f[72]|0,0,e);if(r){e=f[63]|0;f[e+28>>2]=5;}else e=f[63]|0;c=f[71]|0;b=s[399]|0;s[399]=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[72]=(f[72]|0)+-2;break e}}e=(f[72]|0)+2|0;f[72]=e;switch((w(1)|0)<<16>>16){case 44:{f[72]=(f[72]|0)+2;w(1)|0;c=f[63]|0;f[c+4>>2]=e;b=f[72]|0;f[c+16>>2]=b;i[c+24>>0]=1;f[72]=b+-2;break e}case 41:{s[400]=(s[400]|0)+-1<<16>>16;b=f[63]|0;f[b+4>>2]=e;f[b+12>>2]=(f[72]|0)+2;i[b+24>>0]=1;s[399]=(s[399]|0)+-1<<16>>16;break e}default:{f[72]=(f[72]|0)+-2;break e}}}case 123:{if(r){a=12;r=1;n=46;break e}e=f[72]|0;if(s[400]|0){f[72]=e+-2;break e}while(1){if(e>>>0>=(f[73]|0)>>>0)break;e=w(1)|0;if(!(W(e)|0)){if(e<<16>>16==125){n=36;break}}else v(e);e=(f[72]|0)+2|0;f[72]=e;}if((n|0)==36)f[72]=(f[72]|0)+2;b=(w(1)|0)<<16>>16==102;e=f[72]|0;if(b?m(e+2|0,66,6)|0:0){T();break e}f[72]=e+8;e=w(1)|0;if(W(e)|0){u(c,e,0);break e}else {T();break e}}default:{if(r){a=12;r=1;n=46;break e}switch(e<<16>>16){case 42:case 39:case 34:{r=0;n=48;break e}default:{a=6;r=0;n=46;break e}}}}}while(0);if((n|0)==46){e=f[72]|0;if((e|0)==(c+(a<<1)|0))f[72]=e+-2;else n=48;}do{if((n|0)==48){if(s[400]|0){f[72]=(f[72]|0)+-2;break}e=f[73]|0;a=f[72]|0;while(1){if(a>>>0>=e>>>0){n=55;break}t=s[a>>1]|0;if(W(t)|0){n=53;break}b=a+2|0;f[72]=b;a=b;}if((n|0)==53){u(c,t,r);break}else if((n|0)==55){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[72]|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[72]|0,1);if(r)f[(f[63]|0)+28>>2]=4;f[72]=(f[72]|0)+2;a=w(0)|0;r=a<<16>>16==97;if(r){i=f[72]|0;if(m(i+2|0,94,10)|0)t=13;}else {i=f[72]|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[72]=i+-2;break}f[72]=i+((r?6:4)<<1);if((w(1)|0)<<16>>16!=123){f[72]=i;break}r=f[72]|0;a=r;e:while(1){f[72]=a+2;a=w(1)|0;switch(a<<16>>16){case 39:{v(39);f[72]=(f[72]|0)+2;a=w(1)|0;break}case 34:{v(34);f[72]=(f[72]|0)+2;a=w(1)|0;break}default:a=q(a)|0;}if(a<<16>>16!=58){t=22;break}f[72]=(f[72]|0)+2;switch((w(1)|0)<<16>>16){case 39:{v(39);break}case 34:{v(34);break}default:{t=26;break e}}f[72]=(f[72]|0)+2;switch((w(1)|0)<<16>>16){case 125:{t=31;break e}case 44:break;default:{t=30;break e}}f[72]=(f[72]|0)+2;if((w(1)|0)<<16>>16==125){t=31;break}a=f[72]|0;}if((t|0)==22){f[72]=i;break}else if((t|0)==26){f[72]=i;break}else if((t|0)==30){f[72]=i;break}else if((t|0)==31){t=f[63]|0;f[t+16>>2]=r;f[t+12>>2]=(f[72]|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,104,2)|0;break e}case 108:{e=$(e+-4|0,108,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,114,4)|0;break e}case 117:{e=$(e+-4|0,122,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,134,6)|0;break e}case 112:{e=$(e+-8|0,146,2)|0;break e}default:{e=0;break e}}else e=0;break}case 107:{e=$(e+-2|0,150,4)|0;break}case 110:{e=e+-2|0;if(B(e,105)|0)e=1;else e=$(e,158,5)|0;break}case 111:{e=B(e+-2|0,100)|0;break}case 114:{e=$(e+-2|0,168,7)|0;break}case 116:{e=$(e+-2|0,182,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,190,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[73]|0;r=f[72]|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[72]=e;a=f[70]|0;i=s[400]|0;r=i&65535;f[a+(r<<3)>>2]=4;s[400]=i+1<<16>>16;f[a+(r<<3)+4>>2]=e;}else if((a|0)==7){f[72]=e;r=f[70]|0;i=(s[400]|0)+-1<<16>>16;s[400]=i;if((f[r+((i&65535)<<3)>>2]|0)!=3)T();}else if((a|0)==10){f[72]=e;T();}return}function w(e){e=e|0;var a=0,r=0,i=0;r=f[72]|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[72]|0;r=i+2|0;f[72]=r;}while(i>>>0<(f[73]|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[67]|0;f[67]=c+36;t=f[63]|0;f[((t|0)==0?236:t+32|0)>>2]=c;f[64]=t;f[63]=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[803]=1;return}function v(e){e=e|0;var a=0,r=0,i=0,t=0;t=f[73]|0;a=f[72]|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[72]=i;T();}else if((a|0)==10)f[72]=i;return}function A(e,a){e=e|0;a=a|0;var r=0,i=0,t=0,c=0;r=f[72]|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[72]=r+4;r=w(1)|0;e=f[72]|0;if(W(r)|0){v(r);a=(f[72]|0)+2|0;f[72]=a;}else {q(r)|0;a=f[72]|0;}i=w(1)|0;r=f[72]|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[73]|0;a=f[72]|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[72]=e;T();e=0;}else if((a|0)==7){f[72]=e;e=93;}return e|0}function g(){var e=0,a=0,r=0;e:while(1){e=f[72]|0;a=e+2|0;f[72]=a;if(e>>>0>=(f[73]|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[72]=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,210,4)|0;break}case 121:{e=$(e+-2|0,218,6)|0;break}case 101:{e=$(e+-2|0,230,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[72]|0)+2|0;f[72]=t;r=f[73]|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[72]=a;a=t+4|0;}f[72]=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[66]=e;a=f[3]|0;t=a+(e<<1)|0;e=t+2|0;s[t>>1]=0;f[i>>2]=e;f[67]=e;f[59]=0;f[63]=0;f[61]=0;f[60]=0;f[65]=0;f[62]=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[67]|0;f[67]=t+20;c=f[65]|0;f[((c|0)==0?240:c+16|0)>>2]=t;f[65]=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[803]=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,150,4)|0;break}case 101:{if((s[e+-2>>1]|0)==117)e=$(e+-4|0,122,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[73]|0;r=f[72]|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[72]=a;return}function q(e){e=e|0;while(1){if(V(e)|0)break;if(I(e)|0)break;e=(f[72]|0)+2|0;f[72]=e;e=s[e>>1]|0;if(!(e<<16>>16)){e=0;break}}return e|0}function z(){var e=0;e=f[(f[61]|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,196,5)|0)?!($(e,44,3)|0):0)e=$(e,206,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[62]|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[61]|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[62]|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[61]|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[61]|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[61]|0;e=f[((e|0)==0?236:e+32|0)>>2]|0;f[61]=e;return (e|0)!=0|0}function R(){var e=0;e=f[62]|0;e=f[((e|0)==0?240:e+16|0)>>2]|0;f[62]=e;return (e|0)!=0|0}function T(){i[802]=1;f[68]=(f[72]|0)-(f[3]|0)>>1;f[72]=(f[73]|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[61]|0)+8>>2]|0)-(f[3]|0)>>1|0}function Y(){return (f[(f[62]|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[61]>>2]|0)-(f[3]|0)>>1|0}function ee(){return (f[f[62]>>2]|0)-(f[3]|0)>>1|0}function ae(){return t[(f[61]|0)+24>>0]|0|0}function re(e){e=e|0;f[3]=e;return}function ie(){return f[(f[61]|0)+28>>2]|0}function se(){return (i[803]|0)!=0|0}function fe(){return (i[804]|0)!=0|0}function te(){return f[68]|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
456
 
416
- async function _resolve (id, parentUrl) {
457
+ async function _resolve(id, parentUrl) {
417
458
  const urlResolved = resolveIfNotPlainOrUrl(id, parentUrl) || asURL(id);
418
- return {
419
- r: resolveImportMap(importMap, urlResolved || id, parentUrl) || throwUnresolved(id, parentUrl),
420
- // b = bare specifier
421
- b: !urlResolved && !asURL(id)
422
- };
459
+ const firstResolved = firstImportMap && resolveImportMap(firstImportMap, urlResolved || id, parentUrl);
460
+ const composedResolved =
461
+ composedImportMap === firstImportMap ? firstResolved : (
462
+ resolveImportMap(composedImportMap, urlResolved || id, parentUrl)
463
+ );
464
+ const resolved = composedResolved || firstResolved || throwUnresolved(id, parentUrl);
465
+ // needsShim, shouldShim per load record to set on parent
466
+ let n = false,
467
+ N = false;
468
+ if (!supportsImportMaps) {
469
+ // bare specifier -> needs shim
470
+ if (!urlResolved) n = true;
471
+ // url mapping -> should shim
472
+ else if (urlResolved !== resolved) N = true;
473
+ } else if (!supportsMultipleImportMaps) {
474
+ // bare specifier and not resolved by first import map -> needs shim
475
+ if (!urlResolved && !firstResolved) n = true;
476
+ // resolution doesn't match first import map -> should shim
477
+ if (firstResolved && resolved !== firstResolved) N = true;
478
+ }
479
+ return { r: resolved, n, N };
423
480
  }
424
481
 
425
- const resolve = resolveHook ? async (id, parentUrl) => {
426
- let result = resolveHook(id, parentUrl, defaultResolve);
427
- // will be deprecated in next major
428
- if (result && result.then)
429
- result = await result;
430
- return result ? { r: result, b: !resolveIfNotPlainOrUrl(id, parentUrl) && !asURL(id) } : _resolve(id, parentUrl);
431
- } : _resolve;
482
+ const resolve =
483
+ resolveHook ?
484
+ (id, parentUrl) => {
485
+ const result = resolveHook(id, parentUrl, defaultResolve);
486
+ return result ? { r: result, n: true, N: true } : _resolve(id, parentUrl);
487
+ }
488
+ : _resolve;
432
489
 
433
490
  // supports:
434
491
  // import('mod');
435
492
  // import('mod', { opts });
436
493
  // import('mod', { opts }, parentUrl);
437
494
  // import('mod', parentUrl);
438
- async function importHandler (id, ...args) {
495
+ async function importHandler(id, ...args) {
439
496
  // parentUrl if present will be the last argument
440
497
  let parentUrl = args[args.length - 1];
441
- if (typeof parentUrl !== 'string')
442
- parentUrl = baseUrl;
498
+ if (typeof parentUrl !== 'string') parentUrl = baseUrl;
443
499
  // needed for shim check
444
500
  await initPromise;
445
501
  if (importHook) await importHook(id, typeof args[1] !== 'string' ? args[1] : {}, parentUrl);
446
- if (acceptingImportMaps || shimMode || !baselinePassthrough) {
447
- if (hasDocument)
448
- processScriptsAndPreloads(true);
449
- if (!shimMode)
450
- acceptingImportMaps = false;
502
+ if (shimMode || !baselinePassthrough) {
503
+ if (hasDocument) processScriptsAndPreloads();
504
+ legacyAcceptingImportMaps = false;
451
505
  }
452
506
  await importMapPromise;
453
507
  return (await resolve(id, parentUrl)).r;
454
508
  }
455
509
 
456
510
  // import()
457
- async function importShim (...args) {
511
+ async function importShim(...args) {
512
+ console.info(`es-module-shims: importShim("${args[0]}")`);
458
513
  return topLevelLoad(await importHandler(...args), { credentials: 'same-origin' });
459
514
  }
460
515
 
461
516
  // import.source()
462
517
  if (sourcePhaseEnabled)
463
- importShim.source = async function importShimSource (...args) {
464
- const url = await importHandler(...args);
465
- const load = getOrCreateLoad(url, { credentials: 'same-origin' }, null, null);
466
- lastLoad = undefined;
467
- if (firstPolyfillLoad && !shimMode && load.n && nativelyLoaded) {
468
- onpolyfill();
469
- firstPolyfillLoad = false;
470
- }
471
- await load.f;
472
- return importShim._s[load.r];
473
- };
518
+ importShim.source = async function importShimSource(...args) {
519
+ const url = await importHandler(...args);
520
+ const load = getOrCreateLoad(url, { credentials: 'same-origin' }, null, null);
521
+ lastLoad = undefined;
522
+ if (firstPolyfillLoad && !shimMode && load.n && nativelyLoaded) {
523
+ onpolyfill();
524
+ firstPolyfillLoad = false;
525
+ }
526
+ await load.f;
527
+ return importShim._s[load.r];
528
+ };
474
529
 
475
530
  self.importShim = importShim;
476
531
 
477
- function defaultResolve (id, parentUrl) {
478
- return resolveImportMap(importMap, resolveIfNotPlainOrUrl(id, parentUrl) || id, parentUrl) || throwUnresolved(id, parentUrl);
532
+ function defaultResolve(id, parentUrl) {
533
+ return (
534
+ resolveImportMap(composedImportMap, resolveIfNotPlainOrUrl(id, parentUrl) || id, parentUrl) ||
535
+ throwUnresolved(id, parentUrl)
536
+ );
479
537
  }
480
538
 
481
- function throwUnresolved (id, parentUrl) {
539
+ function throwUnresolved(id, parentUrl) {
482
540
  throw Error(`Unable to resolve specifier '${id}'${fromParent(parentUrl)}`);
483
541
  }
484
542
 
@@ -488,43 +546,59 @@
488
546
  return result && !result.then ? result : defaultResolve(id, parentUrl);
489
547
  };
490
548
 
491
- function metaResolve (id, parentUrl = this.url) {
549
+ function metaResolve(id, parentUrl = this.url) {
492
550
  return resolveSync(id, parentUrl);
493
551
  }
494
552
 
495
553
  importShim.resolve = resolveSync;
496
- importShim.getImportMap = () => JSON.parse(JSON.stringify(importMap));
554
+ importShim.getImportMap = () => JSON.parse(JSON.stringify(composedImportMap));
497
555
  importShim.addImportMap = importMapIn => {
498
556
  if (!shimMode) throw new Error('Unsupported in polyfill mode.');
499
- importMap = resolveAndComposeImportMap(importMapIn, baseUrl, importMap);
557
+ composedImportMap = resolveAndComposeImportMap(importMapIn, baseUrl, composedImportMap);
500
558
  };
501
559
 
502
- const registry = importShim._r = {};
503
- const sourceCache = importShim._s = {};
560
+ const registry = (importShim._r = {});
561
+ const sourceCache = (importShim._s = {});
504
562
 
505
- async function loadAll (load, seen) {
563
+ async function loadAll(load, seen) {
506
564
  seen[load.u] = 1;
507
565
  await load.L;
508
- await Promise.all(load.d.map(({ l: dep, s: sourcePhase }) => {
509
- if (dep.b || seen[dep.u])
510
- return;
511
- if (sourcePhase)
512
- return dep.f;
513
- return loadAll(dep, seen);
514
- }));
515
- if (!load.n)
516
- load.n = load.d.some(dep => dep.l.n);
566
+ await Promise.all(
567
+ load.d.map(({ l: dep, s: sourcePhase }) => {
568
+ if (dep.b || seen[dep.u]) return;
569
+ if (sourcePhase) return dep.f;
570
+ return loadAll(dep, seen);
571
+ })
572
+ );
573
+ if (!load.n) load.n = load.d.some(dep => dep.l.n);
517
574
  }
518
575
 
519
- let importMap = { imports: {}, scopes: {}, integrity: {} };
576
+ let importMapSrc = false;
577
+ let multipleImportMaps = false;
578
+ let firstImportMap = null;
579
+ // To support polyfilling multiple import maps, we separately track the composed import map from the first import map
580
+ let composedImportMap = { imports: {}, scopes: {}, integrity: {} };
520
581
  let baselinePassthrough;
521
582
 
522
583
  const initPromise = featureDetectionPromise.then(() => {
523
- baselinePassthrough = esmsInitOptions.polyfillEnable !== true && supportsDynamicImport && supportsImportMeta && supportsImportMaps && (!jsonModulesEnabled || supportsJsonAssertions) && (!cssModulesEnabled || supportsCssAssertions) && (!wasmModulesEnabled || supportsWasmModules) && (!sourcePhaseEnabled || supportsSourcePhase) && !importMapSrcOrLazy;
524
- console.info(`es-module-shims: init ${shimMode ? 'shim mode' : 'polyfill mode'}, ${baselinePassthrough ? 'baseline passthrough' : 'polyfill engaged'}`);
584
+ baselinePassthrough =
585
+ esmsInitOptions.polyfillEnable !== true &&
586
+ supportsDynamicImport &&
587
+ supportsImportMeta &&
588
+ supportsImportMaps &&
589
+ (!jsonModulesEnabled || supportsJsonType) &&
590
+ (!cssModulesEnabled || supportsCssType) &&
591
+ (!wasmModulesEnabled || supportsWasmModules) &&
592
+ (!sourcePhaseEnabled || supportsSourcePhase) &&
593
+ (!multipleImportMaps || supportsMultipleImportMaps) &&
594
+ !importMapSrc;
595
+ console.info(
596
+ `es-module-shims: init ${shimMode ? 'shim mode' : 'polyfill mode'}, ${baselinePassthrough ? 'baseline passthrough' : 'polyfill engaged'}`
597
+ );
525
598
  if (sourcePhaseEnabled && typeof WebAssembly !== 'undefined' && !Object.getPrototypeOf(WebAssembly.Module).name) {
526
599
  const s = Symbol();
527
- const brand = m => Object.defineProperty(m, s, { writable: false, configurable: false, value: 'WebAssembly.Module' });
600
+ const brand = m =>
601
+ Object.defineProperty(m, s, { writable: false, configurable: false, value: 'WebAssembly.Module' });
528
602
  class AbstractModuleSource {
529
603
  get [Symbol.toStringTag]() {
530
604
  if (this[s]) return this[s];
@@ -532,11 +606,14 @@
532
606
  }
533
607
  }
534
608
  const { Module: wasmModule, compile: wasmCompile, compileStreaming: wasmCompileStreaming } = WebAssembly;
535
- WebAssembly.Module = Object.setPrototypeOf(Object.assign(function Module (...args) {
536
- return brand(new wasmModule(...args));
537
- }, wasmModule), AbstractModuleSource);
609
+ WebAssembly.Module = Object.setPrototypeOf(
610
+ Object.assign(function Module(...args) {
611
+ return brand(new wasmModule(...args));
612
+ }, wasmModule),
613
+ AbstractModuleSource
614
+ );
538
615
  WebAssembly.Module.prototype = Object.setPrototypeOf(wasmModule.prototype, AbstractModuleSource.prototype);
539
- WebAssembly.compile = function compile (...args) {
616
+ WebAssembly.compile = function compile(...args) {
540
617
  return wasmCompile(...args).then(brand);
541
618
  };
542
619
  WebAssembly.compileStreaming = function compileStreaming(...args) {
@@ -549,27 +626,10 @@
549
626
  HTMLScriptElement.supports = type => type === 'importmap' || supports(type);
550
627
  }
551
628
  if (shimMode || !baselinePassthrough) {
552
- new MutationObserver(mutations => {
553
- for (const mutation of mutations) {
554
- if (mutation.type !== 'childList') continue;
555
- for (const node of mutation.addedNodes) {
556
- if (node.tagName === 'SCRIPT') {
557
- if (node.type === (shimMode ? 'module-shim' : 'module'))
558
- processScript(node, true);
559
- if (node.type === (shimMode ? 'importmap-shim' : 'importmap'))
560
- processImportMap(node, true);
561
- }
562
- else if (node.tagName === 'LINK' && node.rel === (shimMode ? 'modulepreload-shim' : 'modulepreload')) {
563
- processPreload(node);
564
- }
565
- }
566
- }
567
- }).observe(document, {childList: true, subtree: true});
568
- processScriptsAndPreloads();
629
+ attachMutationObserver();
569
630
  if (document.readyState === 'complete') {
570
631
  readyStateCompleteCheck();
571
- }
572
- else {
632
+ } else {
573
633
  async function readyListener() {
574
634
  await initPromise;
575
635
  processScriptsAndPreloads();
@@ -582,26 +642,49 @@
582
642
  }
583
643
  }
584
644
  }
645
+ processScriptsAndPreloads();
585
646
  return undefined;
586
647
  });
648
+
649
+ function attachMutationObserver() {
650
+ new MutationObserver(mutations => {
651
+ for (const mutation of mutations) {
652
+ if (mutation.type !== 'childList') continue;
653
+ for (const node of mutation.addedNodes) {
654
+ if (node.tagName === 'SCRIPT') {
655
+ if (node.type === (shimMode ? 'module-shim' : 'module') && !node.ep) processScript(node, true);
656
+ if (node.type === (shimMode ? 'importmap-shim' : 'importmap') && !node.ep) processImportMap(node, true);
657
+ } else if (
658
+ node.tagName === 'LINK' &&
659
+ node.rel === (shimMode ? 'modulepreload-shim' : 'modulepreload') &&
660
+ !node.ep
661
+ ) {
662
+ processPreload(node);
663
+ }
664
+ }
665
+ }
666
+ }).observe(document, { childList: true, subtree: true });
667
+ processScriptsAndPreloads();
668
+ }
669
+
587
670
  let importMapPromise = initPromise;
588
671
  let firstPolyfillLoad = true;
589
- let acceptingImportMaps = true;
672
+ let legacyAcceptingImportMaps = true;
590
673
 
591
- async function topLevelLoad (url, fetchOpts, source, nativelyLoaded, lastStaticLoadPromise) {
592
- if (!shimMode)
593
- acceptingImportMaps = false;
674
+ async function topLevelLoad(url, fetchOpts, source, nativelyLoaded, lastStaticLoadPromise) {
675
+ legacyAcceptingImportMaps = false;
594
676
  await initPromise;
595
677
  await importMapPromise;
596
678
  if (importHook) await importHook(url, typeof fetchOpts !== 'string' ? fetchOpts : {}, '');
597
679
  // early analysis opt-out - no need to even fetch if we have feature support
598
680
  if (!shimMode && baselinePassthrough) {
599
- console.info(`es-module-shims: load skipping polyfill due to baseline passthrough applying: ${url}`);
681
+ console.info(`es-module-shims: early load exit as we have baseline modules support ${url}`);
600
682
  // for polyfill case, only dynamic import needs a return value here, and dynamic import will never pass nativelyLoaded
601
- if (nativelyLoaded)
602
- return null;
683
+ if (nativelyLoaded) return null;
603
684
  await lastStaticLoadPromise;
604
- return dynamicImport(source ? createBlob(source) : url, { errUrl: url || source });
685
+ return dynamicImport(source ? createBlob(source) : url, {
686
+ errUrl: url || source
687
+ });
605
688
  }
606
689
  const load = getOrCreateLoad(url, fetchOpts, null, source);
607
690
  linkLoad(load, fetchOpts);
@@ -621,8 +704,7 @@
621
704
  }
622
705
  const module = await dynamicImport(!shimMode && !load.n && nativelyLoaded ? load.u : load.b, { errUrl: load.u });
623
706
  // if the top-level load is a shell, run its update function
624
- if (load.s)
625
- (await dynamicImport(load.s)).u$_(module);
707
+ if (load.s) (await dynamicImport(load.s)).u$_(module);
626
708
  if (revokeBlobURLs) revokeObjectURLs(Object.keys(seen));
627
709
  // when tla is supported, this should return the tla promise as an actual handle
628
710
  // so readystate can still correspond to the sync subgraph exec completions
@@ -636,7 +718,7 @@
636
718
  schedule(cleanup);
637
719
  function cleanup() {
638
720
  const batchStartIndex = batch * 100;
639
- if (batchStartIndex > keysLength) return
721
+ if (batchStartIndex > keysLength) return;
640
722
  for (const key of registryKeys.slice(batchStartIndex, batchStartIndex + 100)) {
641
723
  const load = registry[key];
642
724
  if (load) URL.revokeObjectURL(load.b);
@@ -646,21 +728,29 @@
646
728
  }
647
729
  }
648
730
 
649
- function urlJsString (url) {
731
+ function urlJsString(url) {
650
732
  return `'${url.replace(/'/g, "\\'")}'`;
651
733
  }
652
734
 
653
735
  let lastLoad;
654
- function resolveDeps (load, seen) {
655
- if (load.b || !seen[load.u])
656
- return;
736
+ function resolveDeps(load, seen) {
737
+ if (load.b || !seen[load.u]) return;
657
738
  seen[load.u] = 0;
658
739
 
659
740
  for (const { l: dep, s: sourcePhase } of load.d) {
660
- if (!sourcePhase)
661
- resolveDeps(dep, seen);
741
+ if (!sourcePhase) resolveDeps(dep, seen);
742
+ }
743
+
744
+ // use native loader whenever possible (n = needs shim) via executable subgraph passthrough
745
+ // so long as the module doesn't use dynamic import or unsupported URL mappings (N = should shim)
746
+ if (!shimMode && !load.n && !load.N) {
747
+ load.b = lastLoad = load.u;
748
+ load.S = undefined;
749
+ return;
662
750
  }
663
751
 
752
+ console.info(`es-module-shims: polyfilling ${load.u}`);
753
+
664
754
  const [imports, exports] = load.a;
665
755
 
666
756
  // "execution"
@@ -671,8 +761,10 @@
671
761
 
672
762
  // once all deps have loaded we can inline the dependency resolution blobs
673
763
  // and define this blob
674
- let lastIndex = 0, depIndex = 0, dynamicImportEndStack = [];
675
- function pushStringTo (originalIndex) {
764
+ let lastIndex = 0,
765
+ depIndex = 0,
766
+ dynamicImportEndStack = [];
767
+ function pushStringTo(originalIndex) {
676
768
  while (dynamicImportEndStack[dynamicImportEndStack.length - 1] < originalIndex) {
677
769
  const dynamicImportEnd = dynamicImportEndStack.pop();
678
770
  resolvedSource += `${source.slice(lastIndex, dynamicImportEnd)}, ${urlJsString(load.r)}`;
@@ -695,20 +787,24 @@
695
787
  }
696
788
  // dependency source replacements
697
789
  else if (dynamicImportIndex === -1) {
698
- let { l: depLoad } = load.d[depIndex++], blobUrl = depLoad.b, cycleShell = !blobUrl;
790
+ let { l: depLoad } = load.d[depIndex++],
791
+ blobUrl = depLoad.b,
792
+ cycleShell = !blobUrl;
699
793
  if (cycleShell) {
700
794
  // circular shell creation
701
795
  if (!(blobUrl = depLoad.s)) {
702
- blobUrl = depLoad.s = createBlob(`export function u$_(m){${
703
- depLoad.a[1].map(({ s, e }, i) => {
704
- const q = depLoad.S[s] === '"' || depLoad.S[s] === "'";
705
- return `e$_${i}=m${q ? `[` : '.'}${depLoad.S.slice(s, e)}${q ? `]` : ''}`;
706
- }).join(',')
707
- }}${
708
- depLoad.a[1].length ? `let ${depLoad.a[1].map((_, i) => `e$_${i}`).join(',')};` : ''
709
- }export {${
710
- depLoad.a[1].map(({ s, e }, i) => `e$_${i} as ${depLoad.S.slice(s, e)}`).join(',')
711
- }}\n//# sourceURL=${depLoad.r}?cycle`);
796
+ blobUrl = depLoad.s = createBlob(
797
+ `export function u$_(m){${depLoad.a[1]
798
+ .map(({ s, e }, i) => {
799
+ const q = depLoad.S[s] === '"' || depLoad.S[s] === "'";
800
+ return `e$_${i}=m${q ? `[` : '.'}${depLoad.S.slice(s, e)}${q ? `]` : ''}`;
801
+ })
802
+ .join(',')}}${
803
+ depLoad.a[1].length ? `let ${depLoad.a[1].map((_, i) => `e$_${i}`).join(',')};` : ''
804
+ }export {${depLoad.a[1]
805
+ .map(({ s, e }, i) => `e$_${i} as ${depLoad.S.slice(s, e)}`)
806
+ .join(',')}}\n//# sourceURL=${depLoad.r}?cycle`
807
+ );
712
808
  }
713
809
  }
714
810
 
@@ -741,9 +837,12 @@
741
837
 
742
838
  // support progressive cycle binding updates (try statement avoids tdz errors)
743
839
  if (load.s && (imports.length === 0 || imports[imports.length - 1].d === -1))
744
- resolvedSource += `\n;import{u$_}from'${load.s}';try{u$_({${exports.filter(e => e.ln).map(({ s, e, ln }) => `${source.slice(s, e)}:${ln}`).join(',')}})}catch(_){};\n`;
840
+ resolvedSource += `\n;import{u$_}from'${load.s}';try{u$_({${exports
841
+ .filter(e => e.ln)
842
+ .map(({ s, e, ln }) => `${source.slice(s, e)}:${ln}`)
843
+ .join(',')}})}catch(_){};\n`;
745
844
 
746
- function pushSourceURL (commentPrefix, commentStart) {
845
+ function pushSourceURL(commentPrefix, commentStart) {
747
846
  const urlStart = commentStart + commentPrefix.length;
748
847
  const commentEnd = source.indexOf('\n', urlStart);
749
848
  const urlEnd = commentEnd !== -1 ? commentEnd : source.length;
@@ -764,21 +863,23 @@
764
863
  if (sourceMapURLCommentStart < lastIndex) sourceMapURLCommentStart = -1;
765
864
 
766
865
  // sourceURL first / only
767
- if (sourceURLCommentStart !== -1 && (sourceMapURLCommentStart === -1 || sourceMapURLCommentStart > sourceURLCommentStart)) {
866
+ if (
867
+ sourceURLCommentStart !== -1 &&
868
+ (sourceMapURLCommentStart === -1 || sourceMapURLCommentStart > sourceURLCommentStart)
869
+ ) {
768
870
  pushSourceURL(sourceURLCommentPrefix, sourceURLCommentStart);
769
871
  }
770
872
  // sourceMappingURL
771
873
  if (sourceMapURLCommentStart !== -1) {
772
874
  pushSourceURL(sourceMapURLCommentPrefix, sourceMapURLCommentStart);
773
875
  // sourceURL last
774
- if (sourceURLCommentStart !== -1 && (sourceURLCommentStart > sourceMapURLCommentStart))
876
+ if (sourceURLCommentStart !== -1 && sourceURLCommentStart > sourceMapURLCommentStart)
775
877
  pushSourceURL(sourceURLCommentPrefix, sourceURLCommentStart);
776
878
  }
777
879
 
778
880
  pushStringTo(source.length);
779
881
 
780
- if (sourceURLCommentStart === -1)
781
- resolvedSource += sourceURLCommentPrefix + load.r;
882
+ if (sourceURLCommentStart === -1) resolvedSource += sourceURLCommentPrefix + load.r;
782
883
 
783
884
  load.b = lastLoad = createBlob(resolvedSource);
784
885
  load.S = undefined;
@@ -797,29 +898,24 @@
797
898
  // restrict in-flight fetches to a pool of 100
798
899
  let p = [];
799
900
  let c = 0;
800
- function pushFetchPool () {
801
- if (++c > 100)
802
- return new Promise(r => p.push(r));
901
+ function pushFetchPool() {
902
+ if (++c > 100) return new Promise(r => p.push(r));
803
903
  }
804
- function popFetchPool () {
904
+ function popFetchPool() {
805
905
  c--;
806
- if (p.length)
807
- p.shift()();
906
+ if (p.length) p.shift()();
808
907
  }
809
908
 
810
- async function doFetch (url, fetchOpts, parent) {
811
- if (enforceIntegrity && !fetchOpts.integrity)
812
- throw Error(`No integrity for ${url}${fromParent(parent)}.`);
909
+ async function doFetch(url, fetchOpts, parent) {
910
+ if (enforceIntegrity && !fetchOpts.integrity) throw Error(`No integrity for ${url}${fromParent(parent)}.`);
813
911
  const poolQueue = pushFetchPool();
814
912
  if (poolQueue) await poolQueue;
815
913
  try {
816
914
  var res = await fetchHook(url, fetchOpts);
817
- }
818
- catch (e) {
915
+ } catch (e) {
819
916
  e.message = `Unable to fetch ${url}${fromParent(parent)} - see network log for details.\n` + e.message;
820
917
  throw e;
821
- }
822
- finally {
918
+ } finally {
823
919
  popFetchPool();
824
920
  }
825
921
 
@@ -831,17 +927,22 @@
831
927
  return res;
832
928
  }
833
929
 
834
- async function fetchModule (url, fetchOpts, parent) {
835
- const mapIntegrity = importMap.integrity[url];
836
- const res = await doFetch(url, mapIntegrity && !fetchOpts.integrity ? Object.assign({}, fetchOpts, { integrity: mapIntegrity }) : fetchOpts, parent);
930
+ async function fetchModule(url, fetchOpts, parent) {
931
+ const mapIntegrity = composedImportMap.integrity[url];
932
+ const res = await doFetch(
933
+ url,
934
+ mapIntegrity && !fetchOpts.integrity ? Object.assign({}, fetchOpts, { integrity: mapIntegrity }) : fetchOpts,
935
+ parent
936
+ );
837
937
  const r = res.url;
838
938
  const contentType = res.headers.get('content-type');
839
- if (jsContentType.test(contentType))
840
- return { r, s: await res.text(), sp: null, t: 'js' };
939
+ if (jsContentType.test(contentType)) return { r, s: await res.text(), sp: null, t: 'js' };
841
940
  else if (wasmContentType.test(contentType)) {
842
941
  const module = await (sourceCache[r] || (sourceCache[r] = WebAssembly.compileStreaming(res)));
843
942
  sourceCache[r] = module;
844
- let s = '', i = 0, importObj = '';
943
+ let s = '',
944
+ i = 0,
945
+ importObj = '';
845
946
  for (const impt of WebAssembly.Module.imports(module)) {
846
947
  const specifier = urlJsString(impt.module);
847
948
  s += `import * as impt${i} from ${specifier};\n`;
@@ -853,19 +954,27 @@
853
954
  s += `export const ${expt.name} = instance.exports['${expt.name}'];\n`;
854
955
  }
855
956
  return { r, s, t: 'wasm' };
856
- }
857
- else if (jsonContentType.test(contentType))
957
+ } else if (jsonContentType.test(contentType))
858
958
  return { r, s: `export default ${await res.text()}`, sp: null, t: 'json' };
859
959
  else if (cssContentType.test(contentType)) {
860
- return { r, s: `var s=new CSSStyleSheet();s.replaceSync(${
861
- JSON.stringify((await res.text()).replace(cssUrlRegEx, (_match, quotes = '', relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`))
862
- });export default s;`, ss: null, t: 'css' };
863
- }
864
- else
865
- throw Error(`Unsupported Content-Type "${contentType}" loading ${url}${fromParent(parent)}. Modules must be served with a valid MIME type like application/javascript.`);
960
+ return {
961
+ r,
962
+ s: `var s=new CSSStyleSheet();s.replaceSync(${JSON.stringify(
963
+ (await res.text()).replace(
964
+ cssUrlRegEx,
965
+ (_match, quotes = '', relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`
966
+ )
967
+ )});export default s;`,
968
+ ss: null,
969
+ t: 'css'
970
+ };
971
+ } else
972
+ throw Error(
973
+ `Unsupported Content-Type "${contentType}" loading ${url}${fromParent(parent)}. Modules must be served with a valid MIME type like application/javascript.`
974
+ );
866
975
  }
867
976
 
868
- function getOrCreateLoad (url, fetchOpts, parent, source) {
977
+ function getOrCreateLoad(url, fetchOpts, parent, source) {
869
978
  if (source && registry[url]) {
870
979
  let i = 0;
871
980
  while (registry[url + ++i]);
@@ -894,6 +1003,8 @@
894
1003
  s: undefined,
895
1004
  // needsShim
896
1005
  n: false,
1006
+ // shouldShim
1007
+ N: false,
897
1008
  // type
898
1009
  t: null,
899
1010
  // meta
@@ -905,16 +1016,23 @@
905
1016
  let t;
906
1017
  ({ r: load.r, s: load.S, t } = await (fetchCache[url] || fetchModule(url, fetchOpts, parent)));
907
1018
  if (t && !shimMode) {
908
- if (t === 'css' && !cssModulesEnabled || t === 'json' && !jsonModulesEnabled || t === 'wasm' && !wasmModulesEnabled)
1019
+ if (
1020
+ (t === 'css' && !cssModulesEnabled) ||
1021
+ (t === 'json' && !jsonModulesEnabled) ||
1022
+ (t === 'wasm' && !wasmModulesEnabled)
1023
+ )
909
1024
  throw featErr(`${t}-modules`);
910
- if (t === 'css' && !supportsCssAssertions || t === 'json' && !supportsJsonAssertions || t === 'wasm' && !supportsWasmModules)
1025
+ if (
1026
+ (t === 'css' && !supportsCssType) ||
1027
+ (t === 'json' && !supportsJsonType) ||
1028
+ (t === 'wasm' && !supportsWasmModules)
1029
+ )
911
1030
  load.n = true;
912
1031
  }
913
1032
  }
914
1033
  try {
915
1034
  load.a = parse(load.S, load.u);
916
- }
917
- catch (e) {
1035
+ } catch (e) {
918
1036
  throwError(e);
919
1037
  load.a = [[], [], false];
920
1038
  }
@@ -923,76 +1041,81 @@
923
1041
  return load;
924
1042
  }
925
1043
 
926
- const featErr = feat => Error(`${feat} feature must be enabled via <script type="esms-options">{ "polyfillEnable": ["${feat}"] }<${''}/script>`);
1044
+ const featErr = feat =>
1045
+ Error(
1046
+ `${feat} feature must be enabled via <script type="esms-options">{ "polyfillEnable": ["${feat}"] }<${''}/script>`
1047
+ );
927
1048
 
928
- function linkLoad (load, fetchOpts) {
1049
+ function linkLoad(load, fetchOpts) {
929
1050
  if (load.L) return;
930
1051
  load.L = load.f.then(async () => {
931
1052
  let childFetchOpts = fetchOpts;
932
- load.d = (await Promise.all(load.a[0].map(async ({ n, d, t }) => {
933
- const sourcePhase = t >= 4;
934
- if (sourcePhase && !sourcePhaseEnabled)
935
- throw featErr('source-phase');
936
- if (d >= 0 && !supportsDynamicImport || d === -2 && !supportsImportMeta || sourcePhase && !supportsSourcePhase)
937
- load.n = true;
938
- if (d !== -1 || !n) return;
939
- const { r, b } = await resolve(n, load.r || load.u);
940
- if (b && (!supportsImportMaps || importMapSrcOrLazy))
941
- load.n = true;
942
- if (d !== -1) return;
943
- if (skip && skip(r) && !sourcePhase) return { l: { b: r }, s: false };
944
- if (childFetchOpts.integrity)
945
- childFetchOpts = Object.assign({}, childFetchOpts, { integrity: undefined });
946
- const child = { l: getOrCreateLoad(r, childFetchOpts, load.r, null), s: sourcePhase };
947
- if (!child.s)
948
- linkLoad(child.l, fetchOpts);
949
- // load, sourcePhase
950
- return child;
951
- }))).filter(l => l);
1053
+ load.d = (
1054
+ await Promise.all(
1055
+ load.a[0].map(async ({ n, d, t }) => {
1056
+ const sourcePhase = t >= 4;
1057
+ if (sourcePhase && !sourcePhaseEnabled) throw featErr('source-phase');
1058
+ if (
1059
+ (d >= 0 && !supportsDynamicImport) ||
1060
+ (d === -2 && !supportsImportMeta) ||
1061
+ (sourcePhase && !supportsSourcePhase)
1062
+ )
1063
+ load.n = true;
1064
+ if (d !== -1 || !n) return;
1065
+ const resolved = await resolve(n, load.r || load.u);
1066
+ if (resolved.n) load.n = true;
1067
+ if (d >= 0 || resolved.N) load.N = true;
1068
+ if (d !== -1) return;
1069
+ if (skip && skip(resolved.r) && !sourcePhase) return { l: { b: resolved.r }, s: false };
1070
+ if (childFetchOpts.integrity) childFetchOpts = Object.assign({}, childFetchOpts, { integrity: undefined });
1071
+ const child = { l: getOrCreateLoad(resolved.r, childFetchOpts, load.r, null), s: sourcePhase };
1072
+ if (!child.s) linkLoad(child.l, fetchOpts);
1073
+ // load, sourcePhase
1074
+ return child;
1075
+ })
1076
+ )
1077
+ ).filter(l => l);
952
1078
  });
953
1079
  }
954
1080
 
955
- function processScriptsAndPreloads (mapsOnly = false) {
1081
+ function processScriptsAndPreloads() {
956
1082
  console.info(`es-module-shims: processing scripts`);
957
- if (!mapsOnly)
958
- for (const link of document.querySelectorAll(shimMode ? 'link[rel=modulepreload-shim]' : 'link[rel=modulepreload]'))
959
- processPreload(link);
960
- for (const script of document.querySelectorAll(shimMode ? 'script[type=importmap-shim]' : 'script[type=importmap]'))
961
- processImportMap(script);
962
- if (!mapsOnly)
963
- for (const script of document.querySelectorAll(shimMode ? 'script[type=module-shim]' : 'script[type=module]'))
964
- processScript(script);
1083
+ for (const link of document.querySelectorAll(shimMode ? 'link[rel=modulepreload-shim]' : 'link[rel=modulepreload]')) {
1084
+ if (!link.ep) processPreload(link);
1085
+ }
1086
+ for (const script of document.querySelectorAll('script[type]')) {
1087
+ if (script.type === 'importmap' + (shimMode ? '-shim' : '')) {
1088
+ if (!script.ep) processImportMap(script);
1089
+ } else if (script.type === 'module' + (shimMode ? '-shim' : '')) {
1090
+ legacyAcceptingImportMaps = false;
1091
+ if (!script.ep) processScript(script);
1092
+ }
1093
+ }
965
1094
  }
966
1095
 
967
- function getFetchOpts (script) {
1096
+ function getFetchOpts(script) {
968
1097
  const fetchOpts = {};
969
- if (script.integrity)
970
- fetchOpts.integrity = script.integrity;
971
- if (script.referrerPolicy)
972
- fetchOpts.referrerPolicy = script.referrerPolicy;
973
- if (script.fetchPriority)
974
- fetchOpts.priority = script.fetchPriority;
975
- if (script.crossOrigin === 'use-credentials')
976
- fetchOpts.credentials = 'include';
977
- else if (script.crossOrigin === 'anonymous')
978
- fetchOpts.credentials = 'omit';
979
- else
980
- fetchOpts.credentials = 'same-origin';
1098
+ if (script.integrity) fetchOpts.integrity = script.integrity;
1099
+ if (script.referrerPolicy) fetchOpts.referrerPolicy = script.referrerPolicy;
1100
+ if (script.fetchPriority) fetchOpts.priority = script.fetchPriority;
1101
+ if (script.crossOrigin === 'use-credentials') fetchOpts.credentials = 'include';
1102
+ else if (script.crossOrigin === 'anonymous') fetchOpts.credentials = 'omit';
1103
+ else fetchOpts.credentials = 'same-origin';
981
1104
  return fetchOpts;
982
1105
  }
983
1106
 
984
1107
  let lastStaticLoadPromise = Promise.resolve();
985
1108
 
986
1109
  let domContentLoadedCnt = 1;
987
- function domContentLoadedCheck () {
1110
+ function domContentLoadedCheck() {
988
1111
  if (--domContentLoadedCnt === 0 && !noLoadEventRetriggers && (shimMode || !baselinePassthrough)) {
989
1112
  console.info(`es-module-shims: DOMContentLoaded refire`);
990
1113
  document.dispatchEvent(new Event('DOMContentLoaded'));
991
1114
  }
992
1115
  }
993
1116
  let loadCnt = 1;
994
- function loadCheck () {
995
- if (--loadCnt === 0 && globalLoadEventRetrigger && !noLoadEventRetriggers && (shimMode || !baselinePassthrough)) {
1117
+ function loadCheck() {
1118
+ if (--loadCnt === 0 && !noLoadEventRetriggers && (shimMode || !baselinePassthrough)) {
996
1119
  console.info(`es-module-shims: load refire`);
997
1120
  window.dispatchEvent(new Event('load'));
998
1121
  }
@@ -1010,41 +1133,54 @@
1010
1133
  }
1011
1134
 
1012
1135
  let readyStateCompleteCnt = 1;
1013
- function readyStateCompleteCheck () {
1136
+ function readyStateCompleteCheck() {
1014
1137
  if (--readyStateCompleteCnt === 0 && !noLoadEventRetriggers && (shimMode || !baselinePassthrough)) {
1015
1138
  console.info(`es-module-shims: readystatechange complete refire`);
1016
1139
  document.dispatchEvent(new Event('readystatechange'));
1017
1140
  }
1018
1141
  }
1019
1142
 
1020
- const hasNext = script => script.nextSibling || script.parentNode && hasNext(script.parentNode);
1021
- const epCheck = (script, ready) => script.ep || !ready && (!script.src && !script.innerHTML || !hasNext(script)) || script.getAttribute('noshim') !== null || !(script.ep = true);
1143
+ const hasNext = script => script.nextSibling || (script.parentNode && hasNext(script.parentNode));
1144
+ const epCheck = (script, ready) =>
1145
+ script.ep ||
1146
+ (!ready && ((!script.src && !script.innerHTML) || !hasNext(script))) ||
1147
+ script.getAttribute('noshim') !== null ||
1148
+ !(script.ep = true);
1022
1149
 
1023
- function processImportMap (script, ready = readyStateCompleteCnt > 0) {
1150
+ function processImportMap(script, ready = readyStateCompleteCnt > 0) {
1024
1151
  if (epCheck(script, ready)) return;
1025
- // we dont currently support multiple, external or dynamic imports maps in polyfill mode to match native
1152
+ // we dont currently support external import maps in polyfill mode to match native
1026
1153
  if (script.src) {
1027
- if (!shimMode)
1028
- return;
1029
- setImportMapSrcOrLazy();
1154
+ if (!shimMode) return;
1155
+ importMapSrc = true;
1030
1156
  }
1031
- if (acceptingImportMaps) {
1032
- importMapPromise = importMapPromise
1033
- .then(async () => {
1034
- importMap = resolveAndComposeImportMap(script.src ? await (await doFetch(script.src, getFetchOpts(script))).json() : JSON.parse(script.innerHTML), script.src || baseUrl, importMap);
1035
- })
1036
- .catch(e => {
1037
- console.log(e);
1038
- if (e instanceof SyntaxError)
1039
- e = new Error(`Unable to parse import map ${e.message} in: ${script.src || script.innerHTML}`);
1040
- throwError(e);
1041
- });
1042
- if (!shimMode)
1043
- acceptingImportMaps = false;
1157
+ importMapPromise = importMapPromise
1158
+ .then(async () => {
1159
+ composedImportMap = resolveAndComposeImportMap(
1160
+ script.src ? await (await doFetch(script.src, getFetchOpts(script))).json() : JSON.parse(script.innerHTML),
1161
+ script.src || baseUrl,
1162
+ composedImportMap
1163
+ );
1164
+ })
1165
+ .catch(e => {
1166
+ console.log(e);
1167
+ if (e instanceof SyntaxError)
1168
+ e = new Error(`Unable to parse import map ${e.message} in: ${script.src || script.innerHTML}`);
1169
+ throwError(e);
1170
+ });
1171
+ if (!firstImportMap && legacyAcceptingImportMaps) importMapPromise.then(() => (firstImportMap = composedImportMap));
1172
+ if (!legacyAcceptingImportMaps && !multipleImportMaps) {
1173
+ multipleImportMaps = true;
1174
+ if (baselinePassthrough && !supportsMultipleImportMaps) {
1175
+ console.info(`es-module-shims: disabling baseline passthrough due to multiple import maps`);
1176
+ baselinePassthrough = false;
1177
+ if (hasDocument) attachMutationObserver();
1178
+ }
1044
1179
  }
1180
+ legacyAcceptingImportMaps = false;
1045
1181
  }
1046
1182
 
1047
- function processScript (script, ready = readyStateCompleteCnt > 0) {
1183
+ function processScript(script, ready = readyStateCompleteCnt > 0) {
1048
1184
  if (epCheck(script, ready)) return;
1049
1185
  // does this load block readystate complete
1050
1186
  const isBlockingReadyScript = script.getAttribute('async') === null && readyStateCompleteCnt > 0;
@@ -1054,25 +1190,24 @@
1054
1190
  if (isLoadScript) loadCnt++;
1055
1191
  if (isBlockingReadyScript) readyStateCompleteCnt++;
1056
1192
  if (isDomContentLoadedScript) domContentLoadedCnt++;
1057
- console.info(`es-module-shims: processing ${script.src || '<inline>'}`);
1058
- const loadPromise = topLevelLoad(script.src || baseUrl, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, isBlockingReadyScript && lastStaticLoadPromise)
1059
- .catch(throwError);
1060
- if (!noLoadEventRetriggers)
1061
- loadPromise.then(() => script.dispatchEvent(new Event('load')));
1062
- if (isBlockingReadyScript)
1063
- lastStaticLoadPromise = loadPromise.then(readyStateCompleteCheck);
1064
- if (isDomContentLoadedScript)
1065
- loadPromise.then(domContentLoadedCheck);
1066
- if (isLoadScript)
1067
- loadPromise.then(loadCheck);
1193
+ console.info(`es-module-shims: loading ${script.src || '<inline>'}`);
1194
+ const loadPromise = topLevelLoad(
1195
+ script.src || baseUrl,
1196
+ getFetchOpts(script),
1197
+ !script.src && script.innerHTML,
1198
+ !shimMode,
1199
+ isBlockingReadyScript && lastStaticLoadPromise
1200
+ ).catch(throwError);
1201
+ if (!noLoadEventRetriggers) loadPromise.then(() => script.dispatchEvent(new Event('load')));
1202
+ if (isBlockingReadyScript) lastStaticLoadPromise = loadPromise.then(readyStateCompleteCheck);
1203
+ if (isDomContentLoadedScript) loadPromise.then(domContentLoadedCheck);
1204
+ if (isLoadScript) loadPromise.then(loadCheck);
1068
1205
  }
1069
1206
 
1070
1207
  const fetchCache = {};
1071
- function processPreload (link) {
1072
- if (link.ep) return;
1208
+ function processPreload(link) {
1073
1209
  link.ep = true;
1074
- if (fetchCache[link.href])
1075
- return;
1210
+ if (fetchCache[link.href]) return;
1076
1211
  fetchCache[link.href] = fetchModule(link.href, getFetchOpts(link));
1077
1212
  }
1078
1213