es-module-shims 2.4.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -30,7 +30,7 @@ Because we are still using the native module loader the edge cases work out comp
30
30
  Include ES Module Shims with a `async` attribute on the script, then include an import map and module scripts normally:
31
31
 
32
32
  ```html
33
- <script async src="https://ga.jspm.io/npm:es-module-shims@2.4.0/dist/es-module-shims.js"></script>
33
+ <script async src="https://ga.jspm.io/npm:es-module-shims@2.4.1/dist/es-module-shims.js"></script>
34
34
 
35
35
  <!-- https://generator.jspm.io/#U2NhYGBkDM0rySzJSU1hKEpNTC5xMLTQM9Az0C1K1jMAAKFS5w0gAA -->
36
36
  <script type="importmap">
@@ -1,4 +1,4 @@
1
- /** ES Module Shims @version 2.4.0 */
1
+ /** ES Module Shims @version 2.4.1 */
2
2
  (function (exports) {
3
3
 
4
4
  let invalidate;
@@ -182,8 +182,10 @@
182
182
  const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
183
183
  Object.assign(esmsInitOptions, self.esmsInitOptions || {});
184
184
 
185
+ const version = "2.4.1";
186
+
185
187
  const r$1 = esmsInitOptions.version;
186
- if (self.importShim || (r$1 && r$1 !== "2.4.0")) {
188
+ if (self.importShim || (r$1 && r$1 !== version)) {
187
189
  console.info(
188
190
  `es-module-shims: skipping initialization as ${r$1 ? `configured for ${r$1}` : 'another instance has already registered'}`
189
191
  );
@@ -280,314 +282,315 @@
280
282
 
281
283
  const fromParent = parent => (parent ? ` imported from ${parent}` : '');
282
284
 
283
- const backslashRegEx = /\\/g;
284
-
285
- const asURL = url => {
286
- try {
287
- if (url.indexOf(':') !== -1) return new URL(url).href;
288
- } catch (_) {}
289
- };
290
-
291
- const resolveUrl = (relUrl, parentUrl) =>
292
- resolveIfNotPlainOrUrl(relUrl, parentUrl) || asURL(relUrl) || resolveIfNotPlainOrUrl('./' + relUrl, parentUrl);
293
-
294
- const resolveIfNotPlainOrUrl = (relUrl, parentUrl) => {
295
- const hIdx = parentUrl.indexOf('#'),
296
- qIdx = parentUrl.indexOf('?');
297
- if (hIdx + qIdx > -2)
298
- parentUrl = parentUrl.slice(
299
- 0,
300
- hIdx === -1 ? qIdx
301
- : qIdx === -1 || qIdx > hIdx ? hIdx
302
- : qIdx
303
- );
304
- if (relUrl.indexOf('\\') !== -1) relUrl = relUrl.replace(backslashRegEx, '/');
305
- // protocol-relative
306
- if (relUrl[0] === '/' && relUrl[1] === '/') {
307
- return parentUrl.slice(0, parentUrl.indexOf(':') + 1) + relUrl;
308
- }
309
- // relative-url
310
- else if (
311
- (relUrl[0] === '.' &&
312
- (relUrl[1] === '/' ||
313
- (relUrl[1] === '.' && (relUrl[2] === '/' || (relUrl.length === 2 && (relUrl += '/')))) ||
314
- (relUrl.length === 1 && (relUrl += '/')))) ||
315
- relUrl[0] === '/'
316
- ) {
317
- const parentProtocol = parentUrl.slice(0, parentUrl.indexOf(':') + 1);
318
- if (parentProtocol === 'blob:') {
319
- throw new TypeError(
320
- `Failed to resolve module specifier "${relUrl}". Invalid relative url or base scheme isn't hierarchical.`
321
- );
322
- }
323
- // Disabled, but these cases will give inconsistent results for deep backtracking
324
- //if (parentUrl[parentProtocol.length] !== '/')
325
- // throw new Error('Cannot resolve');
326
- // read pathname from parent URL
327
- // pathname taken to be part after leading "/"
328
- let pathname;
329
- if (parentUrl[parentProtocol.length + 1] === '/') {
330
- // resolving to a :// so we need to read out the auth and host
331
- if (parentProtocol !== 'file:') {
332
- pathname = parentUrl.slice(parentProtocol.length + 2);
333
- pathname = pathname.slice(pathname.indexOf('/') + 1);
334
- } else {
335
- pathname = parentUrl.slice(8);
336
- }
337
- } else {
338
- // resolving to :/ so pathname is the /... part
339
- pathname = parentUrl.slice(parentProtocol.length + (parentUrl[parentProtocol.length] === '/'));
340
- }
341
-
342
- if (relUrl[0] === '/') return parentUrl.slice(0, parentUrl.length - pathname.length - 1) + relUrl;
343
-
344
- // join together and split for removal of .. and . segments
345
- // looping the string instead of anything fancy for perf reasons
346
- // '../../../../../z' resolved to 'x/y' is just 'z'
347
- const segmented = pathname.slice(0, pathname.lastIndexOf('/') + 1) + relUrl;
348
-
349
- const output = [];
350
- let segmentIndex = -1;
351
- for (let i = 0; i < segmented.length; i++) {
352
- // busy reading a segment - only terminate on '/'
353
- if (segmentIndex !== -1) {
354
- if (segmented[i] === '/') {
355
- output.push(segmented.slice(segmentIndex, i + 1));
356
- segmentIndex = -1;
357
- }
358
- continue;
359
- }
360
- // new segment - check if it is relative
361
- else if (segmented[i] === '.') {
362
- // ../ segment
363
- if (segmented[i + 1] === '.' && (segmented[i + 2] === '/' || i + 2 === segmented.length)) {
364
- output.pop();
365
- i += 2;
366
- continue;
367
- }
368
- // ./ segment
369
- else if (segmented[i + 1] === '/' || i + 1 === segmented.length) {
370
- i += 1;
371
- continue;
372
- }
373
- }
374
- // it is the start of a new segment
375
- while (segmented[i] === '/') i++;
376
- segmentIndex = i;
377
- }
378
- // finish reading out the last segment
379
- if (segmentIndex !== -1) output.push(segmented.slice(segmentIndex));
380
- return parentUrl.slice(0, parentUrl.length - pathname.length) + output.join('');
381
- }
382
- };
383
-
384
- const resolveAndComposeImportMap = (json, baseUrl, parentMap) => {
385
- const outMap = {
386
- imports: { ...parentMap.imports },
387
- scopes: { ...parentMap.scopes },
388
- integrity: { ...parentMap.integrity }
389
- };
390
-
391
- if (json.imports) resolveAndComposePackages(json.imports, outMap.imports, baseUrl, parentMap);
392
-
393
- if (json.scopes)
394
- for (let s in json.scopes) {
395
- const resolvedScope = resolveUrl(s, baseUrl);
396
- resolveAndComposePackages(
397
- json.scopes[s],
398
- outMap.scopes[resolvedScope] || (outMap.scopes[resolvedScope] = {}),
399
- baseUrl,
400
- parentMap
401
- );
402
- }
403
-
404
- if (json.integrity) resolveAndComposeIntegrity(json.integrity, outMap.integrity, baseUrl);
405
-
406
- return outMap;
407
- };
408
-
409
- const getMatch = (path, matchObj) => {
410
- if (matchObj[path]) return path;
411
- let sepIndex = path.length;
412
- do {
413
- const segment = path.slice(0, sepIndex + 1);
414
- if (segment in matchObj) return segment;
415
- } while ((sepIndex = path.lastIndexOf('/', sepIndex - 1)) !== -1);
416
- };
417
-
418
- const applyPackages = (id, packages) => {
419
- const pkgName = getMatch(id, packages);
420
- if (pkgName) {
421
- const pkg = packages[pkgName];
422
- if (pkg === null) return;
423
- return pkg + id.slice(pkgName.length);
424
- }
425
- };
426
-
427
- const resolveImportMap = (importMap, resolvedOrPlain, parentUrl) => {
428
- let scopeUrl = parentUrl && getMatch(parentUrl, importMap.scopes);
429
- while (scopeUrl) {
430
- const packageResolution = applyPackages(resolvedOrPlain, importMap.scopes[scopeUrl]);
431
- if (packageResolution) return packageResolution;
432
- scopeUrl = getMatch(scopeUrl.slice(0, scopeUrl.lastIndexOf('/')), importMap.scopes);
433
- }
434
- return applyPackages(resolvedOrPlain, importMap.imports) || (resolvedOrPlain.indexOf(':') !== -1 && resolvedOrPlain);
435
- };
436
-
437
- const resolveAndComposePackages = (packages, outPackages, baseUrl, parentMap) => {
438
- for (let p in packages) {
439
- const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
440
- if (
441
- (!shimMode || !mapOverrides) &&
442
- outPackages[resolvedLhs] &&
443
- outPackages[resolvedLhs] !== packages[resolvedLhs]
444
- ) {
445
- console.warn(
446
- `es-module-shims: Rejected map override "${resolvedLhs}" from ${outPackages[resolvedLhs]} to ${packages[resolvedLhs]}.`
447
- );
448
- continue;
449
- }
450
- let target = packages[p];
451
- if (typeof target !== 'string') continue;
452
- const mapped = resolveImportMap(parentMap, resolveIfNotPlainOrUrl(target, baseUrl) || target, baseUrl);
453
- if (mapped) {
454
- outPackages[resolvedLhs] = mapped;
455
- continue;
456
- }
457
- console.warn(`es-module-shims: Mapping "${p}" -> "${packages[p]}" does not resolve`);
458
- }
459
- };
460
-
461
- const resolveAndComposeIntegrity = (integrity, outIntegrity, baseUrl) => {
462
- for (let p in integrity) {
463
- const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
464
- if (
465
- (!shimMode || !mapOverrides) &&
466
- outIntegrity[resolvedLhs] &&
467
- outIntegrity[resolvedLhs] !== integrity[resolvedLhs]
468
- ) {
469
- console.warn(
470
- `es-module-shims: Rejected map integrity override "${resolvedLhs}" from ${outIntegrity[resolvedLhs]} to ${integrity[resolvedLhs]}.`
471
- );
472
- }
473
- outIntegrity[resolvedLhs] = integrity[p];
474
- }
475
- };
285
+ const backslashRegEx = /\\/g;
476
286
 
477
- // support browsers without dynamic import support (eg Firefox 6x)
478
- let supportsJsonType = false;
479
- let supportsCssType = false;
287
+ const asURL = url => {
288
+ try {
289
+ if (url.indexOf(':') !== -1) return new URL(url).href;
290
+ } catch (_) {}
291
+ };
480
292
 
481
- const supports = hasDocument && HTMLScriptElement.supports;
293
+ const resolveUrl = (relUrl, parentUrl) =>
294
+ resolveIfNotPlainOrUrl(relUrl, parentUrl) || asURL(relUrl) || resolveIfNotPlainOrUrl('./' + relUrl, parentUrl);
482
295
 
483
- let supportsImportMaps = supports && supports.name === 'supports' && supports('importmap');
484
- let supportsWasmInstancePhase = false;
485
- let supportsWasmSourcePhase = false;
486
- let supportsMultipleImportMaps = false;
296
+ const resolveIfNotPlainOrUrl = (relUrl, parentUrl) => {
297
+ const hIdx = parentUrl.indexOf('#'),
298
+ qIdx = parentUrl.indexOf('?');
299
+ if (hIdx + qIdx > -2)
300
+ parentUrl = parentUrl.slice(
301
+ 0,
302
+ hIdx === -1 ? qIdx
303
+ : qIdx === -1 || qIdx > hIdx ? hIdx
304
+ : qIdx
305
+ );
306
+ if (relUrl.indexOf('\\') !== -1) relUrl = relUrl.replace(backslashRegEx, '/');
307
+ // protocol-relative
308
+ if (relUrl[0] === '/' && relUrl[1] === '/') {
309
+ return parentUrl.slice(0, parentUrl.indexOf(':') + 1) + relUrl;
310
+ }
311
+ // relative-url
312
+ else if (
313
+ (relUrl[0] === '.' &&
314
+ (relUrl[1] === '/' ||
315
+ (relUrl[1] === '.' && (relUrl[2] === '/' || (relUrl.length === 2 && (relUrl += '/')))) ||
316
+ (relUrl.length === 1 && (relUrl += '/')))) ||
317
+ relUrl[0] === '/'
318
+ ) {
319
+ const parentProtocol = parentUrl.slice(0, parentUrl.indexOf(':') + 1);
320
+ if (parentProtocol === 'blob:') {
321
+ throw new TypeError(
322
+ `Failed to resolve module specifier "${relUrl}". Invalid relative url or base scheme isn't hierarchical.`
323
+ );
324
+ }
325
+ // Disabled, but these cases will give inconsistent results for deep backtracking
326
+ //if (parentUrl[parentProtocol.length] !== '/')
327
+ // throw new Error('Cannot resolve');
328
+ // read pathname from parent URL
329
+ // pathname taken to be part after leading "/"
330
+ let pathname;
331
+ if (parentUrl[parentProtocol.length + 1] === '/') {
332
+ // resolving to a :// so we need to read out the auth and host
333
+ if (parentProtocol !== 'file:') {
334
+ pathname = parentUrl.slice(parentProtocol.length + 2);
335
+ pathname = pathname.slice(pathname.indexOf('/') + 1);
336
+ } else {
337
+ pathname = parentUrl.slice(8);
338
+ }
339
+ } else {
340
+ // resolving to :/ so pathname is the /... part
341
+ pathname = parentUrl.slice(parentProtocol.length + (parentUrl[parentProtocol.length] === '/'));
342
+ }
487
343
 
488
- const wasmBytes = [0, 97, 115, 109, 1, 0, 0, 0];
344
+ if (relUrl[0] === '/') return parentUrl.slice(0, parentUrl.length - pathname.length - 1) + relUrl;
489
345
 
490
- let featureDetectionPromise = (async function () {
491
- if (!hasDocument)
492
- return Promise.all([
493
- import(createBlob(`import"${createBlob('{}', 'text/json')}"with{type:"json"}`)).then(
494
- () => (
495
- (supportsJsonType = true),
496
- import(createBlob(`import"${createBlob('', 'text/css')}"with{type:"css"}`)).then(
497
- () => (supportsCssType = true),
498
- noop
499
- )
500
- ),
501
- noop
502
- ),
503
- wasmInstancePhaseEnabled &&
504
- import(createBlob(`import"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
505
- () => (supportsWasmInstancePhase = true),
506
- noop
507
- ),
508
- wasmSourcePhaseEnabled &&
509
- import(createBlob(`import source x from"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
510
- () => (supportsWasmSourcePhase = true),
511
- noop
512
- )
513
- ]);
346
+ // join together and split for removal of .. and . segments
347
+ // looping the string instead of anything fancy for perf reasons
348
+ // '../../../../../z' resolved to 'x/y' is just 'z'
349
+ const segmented = pathname.slice(0, pathname.lastIndexOf('/') + 1) + relUrl;
514
350
 
515
- return new Promise(resolve => {
516
- const iframe = document.createElement('iframe');
517
- iframe.style.display = 'none';
518
- iframe.setAttribute('nonce', nonce);
519
- function cb({ data }) {
520
- const isFeatureDetectionMessage = Array.isArray(data) && data[0] === 'esms';
521
- if (!isFeatureDetectionMessage) return;
522
- [
523
- ,
524
- supportsImportMaps,
525
- supportsMultipleImportMaps,
526
- supportsJsonType,
527
- supportsCssType,
528
- supportsWasmSourcePhase,
529
- supportsWasmInstancePhase
530
- ] = data;
531
- resolve();
532
- document.head.removeChild(iframe);
533
- window.removeEventListener('message', cb, false);
351
+ const output = [];
352
+ let segmentIndex = -1;
353
+ for (let i = 0; i < segmented.length; i++) {
354
+ // busy reading a segment - only terminate on '/'
355
+ if (segmentIndex !== -1) {
356
+ if (segmented[i] === '/') {
357
+ output.push(segmented.slice(segmentIndex, i + 1));
358
+ segmentIndex = -1;
359
+ }
360
+ continue;
361
+ }
362
+ // new segment - check if it is relative
363
+ else if (segmented[i] === '.') {
364
+ // ../ segment
365
+ if (segmented[i + 1] === '.' && (segmented[i + 2] === '/' || i + 2 === segmented.length)) {
366
+ output.pop();
367
+ i += 2;
368
+ continue;
369
+ }
370
+ // ./ segment
371
+ else if (segmented[i + 1] === '/' || i + 1 === segmented.length) {
372
+ i += 1;
373
+ continue;
374
+ }
375
+ }
376
+ // it is the start of a new segment
377
+ while (segmented[i] === '/') i++;
378
+ segmentIndex = i;
534
379
  }
535
- window.addEventListener('message', cb, false);
380
+ // finish reading out the last segment
381
+ if (segmentIndex !== -1) output.push(segmented.slice(segmentIndex));
382
+ return parentUrl.slice(0, parentUrl.length - pathname.length) + output.join('');
383
+ }
384
+ };
536
385
 
537
- // 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.
538
- 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=${
539
- supportsImportMaps ? `c(b(\`import"\${b('{}','text/json')}"with{type:"json"}\`))` : 'false'
540
- };sp=${
541
- supportsImportMaps && wasmSourcePhaseEnabled ?
542
- `c(b(\`import source x from "\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))`
543
- : 'false'
544
- };Promise.all([${supportsImportMaps ? 'true' : "c('x')"},${supportsImportMaps ? "c('y')" : false},cm,${
545
- supportsImportMaps ? `cm.then(s=>s?c(b(\`import"\${b('','text/css')\}"with{type:"css"}\`)):false)` : 'false'
546
- },sp,${
547
- supportsImportMaps && wasmInstancePhaseEnabled ?
548
- `${wasmSourcePhaseEnabled ? 'sp.then(s=>s?' : ''}c(b(\`import"\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))${wasmSourcePhaseEnabled ? ':false)' : ''}`
549
- : 'false'
550
- }]).then(a=>parent.postMessage(['esms'].concat(a),'*'))<${''}/script>`;
386
+ const resolveAndComposeImportMap = (json, baseUrl, parentMap) => {
387
+ const outMap = {
388
+ imports: { ...parentMap.imports },
389
+ scopes: { ...parentMap.scopes },
390
+ integrity: { ...parentMap.integrity }
391
+ };
551
392
 
552
- // Safari will call onload eagerly on head injection, but we don't want the Wechat
553
- // path to trigger before setting srcdoc, therefore we track the timing
554
- let readyForOnload = false,
555
- onloadCalledWhileNotReady = false;
556
- function doOnload() {
557
- if (!readyForOnload) {
558
- onloadCalledWhileNotReady = true;
559
- return;
560
- }
561
- // WeChat browser doesn't support setting srcdoc scripts
562
- // But iframe sandboxes don't support contentDocument so we do this as a fallback
563
- const doc = iframe.contentDocument;
564
- if (doc && doc.head.childNodes.length === 0) {
565
- const s = doc.createElement('script');
566
- if (nonce) s.setAttribute('nonce', nonce);
567
- s.innerHTML = importMapTest.slice(15 + (nonce ? nonce.length : 0), -9);
568
- doc.head.appendChild(s);
569
- }
393
+ if (json.imports) resolveAndComposePackages(json.imports, outMap.imports, baseUrl, parentMap);
394
+
395
+ if (json.scopes)
396
+ for (let s in json.scopes) {
397
+ const resolvedScope = resolveUrl(s, baseUrl);
398
+ resolveAndComposePackages(
399
+ json.scopes[s],
400
+ outMap.scopes[resolvedScope] || (outMap.scopes[resolvedScope] = {}),
401
+ baseUrl,
402
+ parentMap
403
+ );
570
404
  }
571
405
 
572
- iframe.onload = doOnload;
573
- // WeChat browser requires append before setting srcdoc
574
- document.head.appendChild(iframe);
406
+ if (json.integrity) resolveAndComposeIntegrity(json.integrity, outMap.integrity, baseUrl);
575
407
 
576
- // setting srcdoc is not supported in React native webviews on iOS
577
- // setting src to a blob URL results in a navigation event in webviews
578
- // document.write gives usability warnings
579
- readyForOnload = true;
580
- if ('srcdoc' in iframe) iframe.srcdoc = importMapTest;
581
- else iframe.contentDocument.write(importMapTest);
582
- // retrigger onload for Safari only if necessary
583
- if (onloadCalledWhileNotReady) doOnload();
584
- });
585
- })();
408
+ return outMap;
409
+ };
586
410
 
587
- featureDetectionPromise = featureDetectionPromise.then(() => {
588
- console.info(
589
- `es-module-shims: detected native support - module types: (${[...(supportsJsonType ? ['json'] : []), ...(supportsCssType ? ['css'] : []), ...(supportsWasmInstancePhase ? ['wasm'] : [])].join(', ')}), ${supportsWasmSourcePhase ? 'source phase' : 'no source phase'}, ${supportsMultipleImportMaps ? '' : 'no '}multiple import maps, ${supportsImportMaps ? '' : 'no '}import maps`
590
- );
411
+ const getMatch = (path, matchObj) => {
412
+ if (matchObj[path]) return path;
413
+ let sepIndex = path.length;
414
+ do {
415
+ const segment = path.slice(0, sepIndex + 1);
416
+ if (segment in matchObj) return segment;
417
+ } while ((sepIndex = path.lastIndexOf('/', sepIndex - 1)) !== -1);
418
+ };
419
+
420
+ const applyPackages = (id, packages) => {
421
+ const pkgName = getMatch(id, packages);
422
+ if (pkgName) {
423
+ const pkg = packages[pkgName];
424
+ if (pkg === null) return;
425
+ return pkg + id.slice(pkgName.length);
426
+ }
427
+ };
428
+
429
+ const resolveImportMap = (importMap, resolvedOrPlain, parentUrl) => {
430
+ let scopeUrl = parentUrl && getMatch(parentUrl, importMap.scopes);
431
+ while (scopeUrl) {
432
+ const packageResolution = applyPackages(resolvedOrPlain, importMap.scopes[scopeUrl]);
433
+ if (packageResolution) return packageResolution;
434
+ scopeUrl = getMatch(scopeUrl.slice(0, scopeUrl.lastIndexOf('/')), importMap.scopes);
435
+ }
436
+ return applyPackages(resolvedOrPlain, importMap.imports) || (resolvedOrPlain.indexOf(':') !== -1 && resolvedOrPlain);
437
+ };
438
+
439
+ const resolveAndComposePackages = (packages, outPackages, baseUrl, parentMap) => {
440
+ for (let p in packages) {
441
+ const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
442
+ if (
443
+ (!shimMode || !mapOverrides) &&
444
+ outPackages[resolvedLhs] &&
445
+ outPackages[resolvedLhs] !== packages[resolvedLhs]
446
+ ) {
447
+ console.warn(
448
+ `es-module-shims: Rejected map override "${resolvedLhs}" from ${outPackages[resolvedLhs]} to ${packages[resolvedLhs]}.`
449
+ );
450
+ continue;
451
+ }
452
+ let target = packages[p];
453
+ if (typeof target !== 'string') continue;
454
+ const mapped = resolveImportMap(parentMap, resolveIfNotPlainOrUrl(target, baseUrl) || target, baseUrl);
455
+ if (mapped) {
456
+ outPackages[resolvedLhs] = mapped;
457
+ continue;
458
+ }
459
+ console.warn(`es-module-shims: Mapping "${p}" -> "${packages[p]}" does not resolve`);
460
+ }
461
+ };
462
+
463
+ const resolveAndComposeIntegrity = (integrity, outIntegrity, baseUrl) => {
464
+ for (let p in integrity) {
465
+ const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
466
+ if (
467
+ (!shimMode || !mapOverrides) &&
468
+ outIntegrity[resolvedLhs] &&
469
+ outIntegrity[resolvedLhs] !== integrity[resolvedLhs]
470
+ ) {
471
+ console.warn(
472
+ `es-module-shims: Rejected map integrity override "${resolvedLhs}" from ${outIntegrity[resolvedLhs]} to ${integrity[resolvedLhs]}.`
473
+ );
474
+ }
475
+ outIntegrity[resolvedLhs] = integrity[p];
476
+ }
477
+ };
478
+
479
+ // support browsers without dynamic import support (eg Firefox 6x)
480
+ let supportsJsonType = false;
481
+ let supportsCssType = false;
482
+
483
+ const supports = hasDocument && HTMLScriptElement.supports;
484
+
485
+ let supportsImportMaps = supports && supports.name === 'supports' && supports('importmap');
486
+ let supportsWasmInstancePhase = false;
487
+ let supportsWasmSourcePhase = false;
488
+ let supportsMultipleImportMaps = false;
489
+
490
+ const wasmBytes = [0, 97, 115, 109, 1, 0, 0, 0];
491
+
492
+ let featureDetectionPromise = (async function () {
493
+ if (!hasDocument)
494
+ return Promise.all([
495
+ import(createBlob(`import"${createBlob('{}', 'text/json')}"with{type:"json"}`)).then(
496
+ () => (
497
+ (supportsJsonType = true),
498
+ import(createBlob(`import"${createBlob('', 'text/css')}"with{type:"css"}`)).then(
499
+ () => (supportsCssType = true),
500
+ noop
501
+ )
502
+ ),
503
+ noop
504
+ ),
505
+ wasmInstancePhaseEnabled &&
506
+ import(createBlob(`import"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
507
+ () => (supportsWasmInstancePhase = true),
508
+ noop
509
+ ),
510
+ wasmSourcePhaseEnabled &&
511
+ import(createBlob(`import source x from"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
512
+ () => (supportsWasmSourcePhase = true),
513
+ noop
514
+ )
515
+ ]);
516
+
517
+ const msgTag = `s${version}`;
518
+ return new Promise(resolve => {
519
+ const iframe = document.createElement('iframe');
520
+ iframe.style.display = 'none';
521
+ iframe.setAttribute('nonce', nonce);
522
+ function cb({ data }) {
523
+ const isFeatureDetectionMessage = Array.isArray(data) && data[0] === msgTag;
524
+ if (!isFeatureDetectionMessage) return;
525
+ [
526
+ ,
527
+ supportsImportMaps,
528
+ supportsMultipleImportMaps,
529
+ supportsJsonType,
530
+ supportsCssType,
531
+ supportsWasmSourcePhase,
532
+ supportsWasmInstancePhase
533
+ ] = data;
534
+ resolve();
535
+ document.head.removeChild(iframe);
536
+ window.removeEventListener('message', cb, false);
537
+ }
538
+ window.addEventListener('message', cb, false);
539
+
540
+ // 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.
541
+ 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=${
542
+ supportsImportMaps ? `c(b(\`import"\${b('{}','text/json')}"with{type:"json"}\`))` : 'false'
543
+ };sp=${
544
+ supportsImportMaps && wasmSourcePhaseEnabled ?
545
+ `c(b(\`import source x from "\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))`
546
+ : 'false'
547
+ };Promise.all([${supportsImportMaps ? 'true' : "c('x')"},${supportsImportMaps ? "c('y')" : false},cm,${
548
+ supportsImportMaps ? `cm.then(s=>s?c(b(\`import"\${b('','text/css')\}"with{type:"css"}\`)):false)` : 'false'
549
+ },sp,${
550
+ supportsImportMaps && wasmInstancePhaseEnabled ?
551
+ `${wasmSourcePhaseEnabled ? 'sp.then(s=>s?' : ''}c(b(\`import"\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))${wasmSourcePhaseEnabled ? ':false)' : ''}`
552
+ : 'false'
553
+ }]).then(a=>parent.postMessage(['${msgTag}'].concat(a),'*'))<${''}/script>`;
554
+
555
+ // Safari will call onload eagerly on head injection, but we don't want the Wechat
556
+ // path to trigger before setting srcdoc, therefore we track the timing
557
+ let readyForOnload = false,
558
+ onloadCalledWhileNotReady = false;
559
+ function doOnload() {
560
+ if (!readyForOnload) {
561
+ onloadCalledWhileNotReady = true;
562
+ return;
563
+ }
564
+ // WeChat browser doesn't support setting srcdoc scripts
565
+ // But iframe sandboxes don't support contentDocument so we do this as a fallback
566
+ const doc = iframe.contentDocument;
567
+ if (doc && doc.head.childNodes.length === 0) {
568
+ const s = doc.createElement('script');
569
+ if (nonce) s.setAttribute('nonce', nonce);
570
+ s.innerHTML = importMapTest.slice(15 + (nonce ? nonce.length : 0), -9);
571
+ doc.head.appendChild(s);
572
+ }
573
+ }
574
+
575
+ iframe.onload = doOnload;
576
+ // WeChat browser requires append before setting srcdoc
577
+ document.head.appendChild(iframe);
578
+
579
+ // setting srcdoc is not supported in React native webviews on iOS
580
+ // setting src to a blob URL results in a navigation event in webviews
581
+ // document.write gives usability warnings
582
+ readyForOnload = true;
583
+ if ('srcdoc' in iframe) iframe.srcdoc = importMapTest;
584
+ else iframe.contentDocument.write(importMapTest);
585
+ // retrigger onload for Safari only if necessary
586
+ if (onloadCalledWhileNotReady) doOnload();
587
+ });
588
+ })();
589
+
590
+ featureDetectionPromise = featureDetectionPromise.then(() => {
591
+ console.info(
592
+ `es-module-shims: detected native support - module types: (${[...(supportsJsonType ? ['json'] : []), ...(supportsCssType ? ['css'] : []), ...(supportsWasmInstancePhase ? ['wasm'] : [])].join(', ')}), ${supportsWasmSourcePhase ? 'source phase' : 'no source phase'}, ${supportsMultipleImportMaps ? '' : 'no '}multiple import maps, ${supportsImportMaps ? '' : 'no '}import maps`
593
+ );
591
594
  });
592
595
 
593
596
  /* es-module-lexer 1.7.0 */
@@ -698,6 +701,7 @@
698
701
  if (!shimMode) throw new Error('Unsupported in polyfill mode.');
699
702
  composedImportMap = resolveAndComposeImportMap(importMapIn, baseUrl, composedImportMap);
700
703
  };
704
+ importShim$1.version = version;
701
705
 
702
706
  const registry = (importShim$1._r = {});
703
707
  // Wasm caches
@@ -709,7 +713,6 @@
709
713
  const shimModeOptions = { ...esmsInitOptions, shimMode: true };
710
714
  if (optionsScript) optionsScript.innerHTML = JSON.stringify(shimModeOptions);
711
715
  self.esmsInitOptions = shimModeOptions;
712
- defineValue(self, '_d', undefined);
713
716
 
714
717
  const loadAll = async (load, seen) => {
715
718
  seen[load.u] = 1;