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