es-module-shims 2.7.0 → 2.8.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.
- package/README.md +12 -1
- package/dist/es-module-shims.debug.js +142 -119
- package/dist/es-module-shims.js +136 -113
- package/dist/es-module-shims.wasm.js +136 -113
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ Because we are still using the native module loader the edge cases work out comp
|
|
|
31
31
|
Include ES Module Shims with a `async` attribute on the script, then include an import map and module scripts normally:
|
|
32
32
|
|
|
33
33
|
```html
|
|
34
|
-
<script async src="https://ga.jspm.io/npm:es-module-shims@2.
|
|
34
|
+
<script async src="https://ga.jspm.io/npm:es-module-shims@2.8.0/dist/es-module-shims.js"></script>
|
|
35
35
|
|
|
36
36
|
<!-- https://generator.jspm.io/#U2NhYGBkDM0rySzJSU1hKEpNTC5xMLTQM9Az0C1K1jMAAKFS5w0gAA -->
|
|
37
37
|
<script type="importmap">
|
|
@@ -469,6 +469,17 @@ import pkg from 'pkg';
|
|
|
469
469
|
</script>
|
|
470
470
|
```
|
|
471
471
|
|
|
472
|
+
## Trusted Types Support
|
|
473
|
+
|
|
474
|
+
ES Module Shims supports [Trusted Types](https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API) a browser security feature that prevents DOM-based XSS attacks. When your CSP includes `require-trusted-types-for 'script'`, the library automatically creates a policy named `es-module-shims` to handle its internal script creation and source rewriting. Browsers without Trusted Types support fall back to standard behavior automatically.
|
|
475
|
+
|
|
476
|
+
To enable it, add `es-module-shims` to your CSP's trusted-types directive. If you see errors about "TrustedScript assignment," you're missing this directive.
|
|
477
|
+
|
|
478
|
+
```html
|
|
479
|
+
<meta http-equiv="Content-Security-Policy"
|
|
480
|
+
content="require-trusted-types-for 'script'; trusted-types es-module-shims;">
|
|
481
|
+
```
|
|
482
|
+
|
|
472
483
|
#### Wasm Build
|
|
473
484
|
|
|
474
485
|
To use the Web Assembly / non-CSP build of ES Module Shims, this is available as a self-contained single file at `es-module-shims/wasm` or `es-module-shims/dist/es-module-shims.wasm.js` in the package folder.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** ES Module Shims @version 2.
|
|
1
|
+
/** ES Module Shims @version 2.8.0 */
|
|
2
2
|
(function () {
|
|
3
3
|
|
|
4
4
|
const self_ = typeof globalThis !== 'undefined' ? globalThis : self;
|
|
@@ -181,7 +181,7 @@
|
|
|
181
181
|
const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
|
|
182
182
|
Object.assign(esmsInitOptions, self_.esmsInitOptions || {});
|
|
183
183
|
|
|
184
|
-
const version = "2.
|
|
184
|
+
const version = "2.8.0";
|
|
185
185
|
|
|
186
186
|
const r$1 = esmsInitOptions.version;
|
|
187
187
|
if (self_.importShim || (r$1 && r$1 !== version)) {
|
|
@@ -490,123 +490,146 @@
|
|
|
490
490
|
}
|
|
491
491
|
};
|
|
492
492
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
() => (
|
|
511
|
-
(supportsJsonType = true),
|
|
512
|
-
import(createBlob(`import"${createBlob('', 'text/css')}"with{type:"css"}`)).then(
|
|
513
|
-
() => (supportsCssType = true),
|
|
514
|
-
noop
|
|
515
|
-
)
|
|
516
|
-
),
|
|
517
|
-
noop
|
|
518
|
-
),
|
|
519
|
-
wasmInstancePhaseEnabled &&
|
|
520
|
-
import(createBlob(`import"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
|
|
521
|
-
() => (supportsWasmInstancePhase = true),
|
|
522
|
-
noop
|
|
523
|
-
),
|
|
524
|
-
wasmSourcePhaseEnabled &&
|
|
525
|
-
import(createBlob(`import source x from"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
|
|
526
|
-
() => (supportsWasmSourcePhase = true),
|
|
527
|
-
noop
|
|
528
|
-
)
|
|
529
|
-
]);
|
|
530
|
-
|
|
531
|
-
const msgTag = `s${version}`;
|
|
532
|
-
return new Promise(resolve => {
|
|
533
|
-
const iframe = document.createElement('iframe');
|
|
534
|
-
iframe.style.display = 'none';
|
|
535
|
-
iframe.setAttribute('nonce', nonce);
|
|
536
|
-
function cb({ data }) {
|
|
537
|
-
const isFeatureDetectionMessage = Array.isArray(data) && data[0] === msgTag;
|
|
538
|
-
if (!isFeatureDetectionMessage) return;
|
|
539
|
-
[
|
|
540
|
-
,
|
|
541
|
-
supportsImportMaps,
|
|
542
|
-
supportsMultipleImportMaps,
|
|
543
|
-
supportsJsonType,
|
|
544
|
-
supportsCssType,
|
|
545
|
-
supportsWasmSourcePhase,
|
|
546
|
-
supportsWasmInstancePhase
|
|
547
|
-
] = data;
|
|
548
|
-
resolve();
|
|
549
|
-
document.head.removeChild(iframe);
|
|
550
|
-
window.removeEventListener('message', cb, false);
|
|
551
|
-
}
|
|
552
|
-
window.addEventListener('message', cb, false);
|
|
553
|
-
|
|
554
|
-
// 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.
|
|
555
|
-
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=${
|
|
556
|
-
supportsImportMaps && jsonModulesEnabled ? `c(b(\`import"\${b('{}','text/json')}"with{type:"json"}\`))` : 'false'
|
|
557
|
-
};sp=${
|
|
558
|
-
supportsImportMaps && wasmSourcePhaseEnabled ?
|
|
559
|
-
`c(b(\`import source x from "\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))`
|
|
560
|
-
: 'false'
|
|
561
|
-
};Promise.all([${supportsImportMaps ? 'true' : "c('x')"},${supportsImportMaps ? "c('y')" : false},cm,${
|
|
562
|
-
supportsImportMaps && cssModulesEnabled ?
|
|
563
|
-
`cm.then(s=>s?c(b(\`import"\${b('','text/css')\}"with{type:"css"}\`)):false)`
|
|
564
|
-
: 'false'
|
|
565
|
-
},sp,${
|
|
566
|
-
supportsImportMaps && wasmInstancePhaseEnabled ?
|
|
567
|
-
`${wasmSourcePhaseEnabled ? 'sp.then(s=>s?' : ''}c(b(\`import"\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))${wasmSourcePhaseEnabled ? ':false)' : ''}`
|
|
568
|
-
: 'false'
|
|
569
|
-
}]).then(a=>parent.postMessage(['${msgTag}'].concat(a),'*'))<${''}/script>`;
|
|
570
|
-
|
|
571
|
-
// Safari will call onload eagerly on head injection, but we don't want the Wechat
|
|
572
|
-
// path to trigger before setting srcdoc, therefore we track the timing
|
|
573
|
-
let readyForOnload = false,
|
|
574
|
-
onloadCalledWhileNotReady = false;
|
|
575
|
-
function doOnload() {
|
|
576
|
-
if (!readyForOnload) {
|
|
577
|
-
onloadCalledWhileNotReady = true;
|
|
578
|
-
return;
|
|
579
|
-
}
|
|
580
|
-
// WeChat browser doesn't support setting srcdoc scripts
|
|
581
|
-
// But iframe sandboxes don't support contentDocument so we do this as a fallback
|
|
582
|
-
const doc = iframe.contentDocument;
|
|
583
|
-
if (doc && doc.head.childNodes.length === 0) {
|
|
584
|
-
const s = doc.createElement('script');
|
|
585
|
-
if (nonce) s.setAttribute('nonce', nonce);
|
|
586
|
-
s.innerHTML = importMapTest.slice(15 + (nonce ? nonce.length : 0), -9);
|
|
587
|
-
doc.head.appendChild(s);
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
iframe.onload = doOnload;
|
|
592
|
-
// WeChat browser requires append before setting srcdoc
|
|
593
|
-
document.head.appendChild(iframe);
|
|
594
|
-
|
|
595
|
-
// setting srcdoc is not supported in React native webviews on iOS
|
|
596
|
-
// setting src to a blob URL results in a navigation event in webviews
|
|
597
|
-
// document.write gives usability warnings
|
|
598
|
-
readyForOnload = true;
|
|
599
|
-
if ('srcdoc' in iframe) iframe.srcdoc = importMapTest;
|
|
600
|
-
else iframe.contentDocument.write(importMapTest);
|
|
601
|
-
// retrigger onload for Safari only if necessary
|
|
602
|
-
if (onloadCalledWhileNotReady) doOnload();
|
|
603
|
-
});
|
|
604
|
-
})();
|
|
493
|
+
let policy;
|
|
494
|
+
if (typeof window.trustedTypes !== 'undefined' || typeof window.TrustedTypes !== 'undefined') {
|
|
495
|
+
try {
|
|
496
|
+
policy = (window.trustedTypes || window.TrustedTypes).createPolicy('es-module-shims', {
|
|
497
|
+
createHTML: html => html,
|
|
498
|
+
createScript: script => script
|
|
499
|
+
});
|
|
500
|
+
} catch {}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
function maybeTrustedInnerHTML(html) {
|
|
504
|
+
return policy ? policy.createHTML(html) : html;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
function maybeTrustedScript(script) {
|
|
508
|
+
return policy ? policy.createScript(script) : script;
|
|
509
|
+
}
|
|
605
510
|
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
511
|
+
// support browsers without dynamic import support (eg Firefox 6x)
|
|
512
|
+
let supportsJsonType = false;
|
|
513
|
+
let supportsCssType = false;
|
|
514
|
+
|
|
515
|
+
const supports = hasDocument && HTMLScriptElement.supports;
|
|
516
|
+
|
|
517
|
+
let supportsImportMaps = supports && supports.name === 'supports' && supports('importmap');
|
|
518
|
+
let supportsWasmInstancePhase = false;
|
|
519
|
+
let supportsWasmSourcePhase = false;
|
|
520
|
+
let supportsMultipleImportMaps = false;
|
|
521
|
+
|
|
522
|
+
const wasmBytes = [0, 97, 115, 109, 1, 0, 0, 0];
|
|
523
|
+
|
|
524
|
+
let featureDetectionPromise = (async function () {
|
|
525
|
+
if (!hasDocument)
|
|
526
|
+
return Promise.all([
|
|
527
|
+
import(createBlob(`import"${createBlob('{}', 'text/json')}"with{type:"json"}`)).then(
|
|
528
|
+
() => (
|
|
529
|
+
(supportsJsonType = true),
|
|
530
|
+
import(createBlob(`import"${createBlob('', 'text/css')}"with{type:"css"}`)).then(
|
|
531
|
+
() => (supportsCssType = true),
|
|
532
|
+
noop
|
|
533
|
+
)
|
|
534
|
+
),
|
|
535
|
+
noop
|
|
536
|
+
),
|
|
537
|
+
wasmInstancePhaseEnabled &&
|
|
538
|
+
import(createBlob(`import"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
|
|
539
|
+
() => (supportsWasmInstancePhase = true),
|
|
540
|
+
noop
|
|
541
|
+
),
|
|
542
|
+
wasmSourcePhaseEnabled &&
|
|
543
|
+
import(createBlob(`import source x from"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
|
|
544
|
+
() => (supportsWasmSourcePhase = true),
|
|
545
|
+
noop
|
|
546
|
+
)
|
|
547
|
+
]);
|
|
548
|
+
|
|
549
|
+
const msgTag = `s${version}`;
|
|
550
|
+
return new Promise(resolve => {
|
|
551
|
+
const iframe = document.createElement('iframe');
|
|
552
|
+
iframe.style.display = 'none';
|
|
553
|
+
iframe.setAttribute('nonce', nonce);
|
|
554
|
+
function cb({ data }) {
|
|
555
|
+
const isFeatureDetectionMessage = Array.isArray(data) && data[0] === msgTag;
|
|
556
|
+
if (!isFeatureDetectionMessage) return;
|
|
557
|
+
[
|
|
558
|
+
,
|
|
559
|
+
supportsImportMaps,
|
|
560
|
+
supportsMultipleImportMaps,
|
|
561
|
+
supportsJsonType,
|
|
562
|
+
supportsCssType,
|
|
563
|
+
supportsWasmSourcePhase,
|
|
564
|
+
supportsWasmInstancePhase
|
|
565
|
+
] = data;
|
|
566
|
+
resolve();
|
|
567
|
+
document.head.removeChild(iframe);
|
|
568
|
+
window.removeEventListener('message', cb, false);
|
|
569
|
+
}
|
|
570
|
+
window.addEventListener('message', cb, false);
|
|
571
|
+
// 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.
|
|
572
|
+
const importMapTest = `<script nonce=${nonce || ''}>${
|
|
573
|
+
policy ? 't=(window.trustedTypes||window.TrustedTypes).createPolicy("es-module-shims",{createScript:s=>s});' : ''
|
|
574
|
+
}b=(s,type='text/javascript')=>URL.createObjectURL(new Blob([s],{type}));c=u=>import(u).then(()=>true,()=>false);i=innerText=>${
|
|
575
|
+
policy ? 't.createScript(innerText=>' : ''
|
|
576
|
+
}document.head.appendChild(Object.assign(document.createElement('script'),{type:'importmap',nonce:"${nonce}",innerText}))${
|
|
577
|
+
policy ? ')' : ''
|
|
578
|
+
};i(\`{"imports":{"x":"\${b('')}"}}\`);i(\`{"imports":{"y":"\${b('')}"}}\`);cm=${
|
|
579
|
+
supportsImportMaps && jsonModulesEnabled ? `c(b(\`import"\${b('{}','text/json')}"with{type:"json"}\`))` : 'false'
|
|
580
|
+
};sp=${
|
|
581
|
+
supportsImportMaps && wasmSourcePhaseEnabled ?
|
|
582
|
+
`c(b(\`import source x from "\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))`
|
|
583
|
+
: 'false'
|
|
584
|
+
};Promise.all([${supportsImportMaps ? 'true' : "c('x')"},${supportsImportMaps ? "c('y')" : false},cm,${
|
|
585
|
+
supportsImportMaps && cssModulesEnabled ?
|
|
586
|
+
`cm.then(s=>s?c(b(\`import"\${b('','text/css')\}"with{type:"css"}\`)):false)`
|
|
587
|
+
: 'false'
|
|
588
|
+
},sp,${
|
|
589
|
+
supportsImportMaps && wasmInstancePhaseEnabled ?
|
|
590
|
+
`${wasmSourcePhaseEnabled ? 'sp.then(s=>s?' : ''}c(b(\`import"\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))${wasmSourcePhaseEnabled ? ':false)' : ''}`
|
|
591
|
+
: 'false'
|
|
592
|
+
}]).then(a=>parent.postMessage(['${msgTag}'].concat(a),'*'))<${''}/script>`;
|
|
593
|
+
|
|
594
|
+
// Safari will call onload eagerly on head injection, but we don't want the Wechat
|
|
595
|
+
// path to trigger before setting srcdoc, therefore we track the timing
|
|
596
|
+
let readyForOnload = false,
|
|
597
|
+
onloadCalledWhileNotReady = false;
|
|
598
|
+
function doOnload() {
|
|
599
|
+
if (!readyForOnload) {
|
|
600
|
+
onloadCalledWhileNotReady = true;
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
// WeChat browser doesn't support setting srcdoc scripts
|
|
604
|
+
// But iframe sandboxes don't support contentDocument so we do this as a fallback
|
|
605
|
+
const doc = iframe.contentDocument;
|
|
606
|
+
if (doc && doc.head.childNodes.length === 0) {
|
|
607
|
+
const s = doc.createElement('script');
|
|
608
|
+
if (nonce) s.setAttribute('nonce', nonce);
|
|
609
|
+
s.innerText = maybeTrustedScript(importMapTest.slice(15 + (nonce ? nonce.length : 0), -9));
|
|
610
|
+
doc.head.appendChild(s);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
iframe.onload = doOnload;
|
|
615
|
+
// WeChat browser requires append before setting srcdoc
|
|
616
|
+
document.head.appendChild(iframe);
|
|
617
|
+
|
|
618
|
+
// setting srcdoc is not supported in React native webviews on iOS
|
|
619
|
+
// setting src to a blob URL results in a navigation event in webviews
|
|
620
|
+
// document.write gives usability warnings
|
|
621
|
+
readyForOnload = true;
|
|
622
|
+
if ('srcdoc' in iframe) iframe.srcdoc = maybeTrustedInnerHTML(importMapTest);
|
|
623
|
+
else iframe.contentDocument.write(importMapTest);
|
|
624
|
+
// retrigger onload for Safari only if necessary
|
|
625
|
+
if (onloadCalledWhileNotReady) doOnload();
|
|
626
|
+
});
|
|
627
|
+
})();
|
|
628
|
+
|
|
629
|
+
featureDetectionPromise = featureDetectionPromise.then(() => {
|
|
630
|
+
console.info(
|
|
631
|
+
`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`
|
|
632
|
+
);
|
|
610
633
|
});
|
|
611
634
|
|
|
612
635
|
/* es-module-lexer 2.0.0 */
|
|
@@ -726,7 +749,7 @@
|
|
|
726
749
|
// Ensure this version is the only version
|
|
727
750
|
defineValue(self_, 'importShim', Object.freeze(importShim));
|
|
728
751
|
const shimModeOptions = { ...esmsInitOptions, shimMode: true };
|
|
729
|
-
if (optionsScript) optionsScript.
|
|
752
|
+
if (optionsScript) optionsScript.innerText = maybeTrustedScript(JSON.stringify(shimModeOptions));
|
|
730
753
|
self_.esmsInitOptions = shimModeOptions;
|
|
731
754
|
|
|
732
755
|
const loadAll = async (load, seen) => {
|
package/dist/es-module-shims.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** ES Module Shims @version 2.
|
|
1
|
+
/** ES Module Shims @version 2.8.0 */
|
|
2
2
|
(function () {
|
|
3
3
|
|
|
4
4
|
const self_ = typeof globalThis !== 'undefined' ? globalThis : self;
|
|
@@ -180,7 +180,7 @@
|
|
|
180
180
|
const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
|
|
181
181
|
Object.assign(esmsInitOptions, self_.esmsInitOptions || {});
|
|
182
182
|
|
|
183
|
-
const version = "2.
|
|
183
|
+
const version = "2.8.0";
|
|
184
184
|
|
|
185
185
|
const r$1 = esmsInitOptions.version;
|
|
186
186
|
if (self_.importShim || (r$1 && r$1 !== version)) {
|
|
@@ -486,117 +486,140 @@
|
|
|
486
486
|
}
|
|
487
487
|
};
|
|
488
488
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
() => (
|
|
507
|
-
(supportsJsonType = true),
|
|
508
|
-
import(createBlob(`import"${createBlob('', 'text/css')}"with{type:"css"}`)).then(
|
|
509
|
-
() => (supportsCssType = true),
|
|
510
|
-
noop
|
|
511
|
-
)
|
|
512
|
-
),
|
|
513
|
-
noop
|
|
514
|
-
),
|
|
515
|
-
wasmInstancePhaseEnabled &&
|
|
516
|
-
import(createBlob(`import"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
|
|
517
|
-
() => (supportsWasmInstancePhase = true),
|
|
518
|
-
noop
|
|
519
|
-
),
|
|
520
|
-
wasmSourcePhaseEnabled &&
|
|
521
|
-
import(createBlob(`import source x from"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
|
|
522
|
-
() => (supportsWasmSourcePhase = true),
|
|
523
|
-
noop
|
|
524
|
-
)
|
|
525
|
-
]);
|
|
526
|
-
|
|
527
|
-
const msgTag = `s${version}`;
|
|
528
|
-
return new Promise(resolve => {
|
|
529
|
-
const iframe = document.createElement('iframe');
|
|
530
|
-
iframe.style.display = 'none';
|
|
531
|
-
iframe.setAttribute('nonce', nonce);
|
|
532
|
-
function cb({ data }) {
|
|
533
|
-
const isFeatureDetectionMessage = Array.isArray(data) && data[0] === msgTag;
|
|
534
|
-
if (!isFeatureDetectionMessage) return;
|
|
535
|
-
[
|
|
536
|
-
,
|
|
537
|
-
supportsImportMaps,
|
|
538
|
-
supportsMultipleImportMaps,
|
|
539
|
-
supportsJsonType,
|
|
540
|
-
supportsCssType,
|
|
541
|
-
supportsWasmSourcePhase,
|
|
542
|
-
supportsWasmInstancePhase
|
|
543
|
-
] = data;
|
|
544
|
-
resolve();
|
|
545
|
-
document.head.removeChild(iframe);
|
|
546
|
-
window.removeEventListener('message', cb, false);
|
|
547
|
-
}
|
|
548
|
-
window.addEventListener('message', cb, false);
|
|
549
|
-
|
|
550
|
-
// 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.
|
|
551
|
-
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=${
|
|
552
|
-
supportsImportMaps && jsonModulesEnabled ? `c(b(\`import"\${b('{}','text/json')}"with{type:"json"}\`))` : 'false'
|
|
553
|
-
};sp=${
|
|
554
|
-
supportsImportMaps && wasmSourcePhaseEnabled ?
|
|
555
|
-
`c(b(\`import source x from "\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))`
|
|
556
|
-
: 'false'
|
|
557
|
-
};Promise.all([${supportsImportMaps ? 'true' : "c('x')"},${supportsImportMaps ? "c('y')" : false},cm,${
|
|
558
|
-
supportsImportMaps && cssModulesEnabled ?
|
|
559
|
-
`cm.then(s=>s?c(b(\`import"\${b('','text/css')\}"with{type:"css"}\`)):false)`
|
|
560
|
-
: 'false'
|
|
561
|
-
},sp,${
|
|
562
|
-
supportsImportMaps && wasmInstancePhaseEnabled ?
|
|
563
|
-
`${wasmSourcePhaseEnabled ? 'sp.then(s=>s?' : ''}c(b(\`import"\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))${wasmSourcePhaseEnabled ? ':false)' : ''}`
|
|
564
|
-
: 'false'
|
|
565
|
-
}]).then(a=>parent.postMessage(['${msgTag}'].concat(a),'*'))<${''}/script>`;
|
|
566
|
-
|
|
567
|
-
// Safari will call onload eagerly on head injection, but we don't want the Wechat
|
|
568
|
-
// path to trigger before setting srcdoc, therefore we track the timing
|
|
569
|
-
let readyForOnload = false,
|
|
570
|
-
onloadCalledWhileNotReady = false;
|
|
571
|
-
function doOnload() {
|
|
572
|
-
if (!readyForOnload) {
|
|
573
|
-
onloadCalledWhileNotReady = true;
|
|
574
|
-
return;
|
|
575
|
-
}
|
|
576
|
-
// WeChat browser doesn't support setting srcdoc scripts
|
|
577
|
-
// But iframe sandboxes don't support contentDocument so we do this as a fallback
|
|
578
|
-
const doc = iframe.contentDocument;
|
|
579
|
-
if (doc && doc.head.childNodes.length === 0) {
|
|
580
|
-
const s = doc.createElement('script');
|
|
581
|
-
if (nonce) s.setAttribute('nonce', nonce);
|
|
582
|
-
s.innerHTML = importMapTest.slice(15 + (nonce ? nonce.length : 0), -9);
|
|
583
|
-
doc.head.appendChild(s);
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
iframe.onload = doOnload;
|
|
588
|
-
// WeChat browser requires append before setting srcdoc
|
|
589
|
-
document.head.appendChild(iframe);
|
|
489
|
+
let policy;
|
|
490
|
+
if (typeof window.trustedTypes !== 'undefined' || typeof window.TrustedTypes !== 'undefined') {
|
|
491
|
+
try {
|
|
492
|
+
policy = (window.trustedTypes || window.TrustedTypes).createPolicy('es-module-shims', {
|
|
493
|
+
createHTML: html => html,
|
|
494
|
+
createScript: script => script
|
|
495
|
+
});
|
|
496
|
+
} catch {}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
function maybeTrustedInnerHTML(html) {
|
|
500
|
+
return policy ? policy.createHTML(html) : html;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
function maybeTrustedScript(script) {
|
|
504
|
+
return policy ? policy.createScript(script) : script;
|
|
505
|
+
}
|
|
590
506
|
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
507
|
+
// support browsers without dynamic import support (eg Firefox 6x)
|
|
508
|
+
let supportsJsonType = false;
|
|
509
|
+
let supportsCssType = false;
|
|
510
|
+
|
|
511
|
+
const supports = hasDocument && HTMLScriptElement.supports;
|
|
512
|
+
|
|
513
|
+
let supportsImportMaps = supports && supports.name === 'supports' && supports('importmap');
|
|
514
|
+
let supportsWasmInstancePhase = false;
|
|
515
|
+
let supportsWasmSourcePhase = false;
|
|
516
|
+
let supportsMultipleImportMaps = false;
|
|
517
|
+
|
|
518
|
+
const wasmBytes = [0, 97, 115, 109, 1, 0, 0, 0];
|
|
519
|
+
|
|
520
|
+
let featureDetectionPromise = (async function () {
|
|
521
|
+
if (!hasDocument)
|
|
522
|
+
return Promise.all([
|
|
523
|
+
import(createBlob(`import"${createBlob('{}', 'text/json')}"with{type:"json"}`)).then(
|
|
524
|
+
() => (
|
|
525
|
+
(supportsJsonType = true),
|
|
526
|
+
import(createBlob(`import"${createBlob('', 'text/css')}"with{type:"css"}`)).then(
|
|
527
|
+
() => (supportsCssType = true),
|
|
528
|
+
noop
|
|
529
|
+
)
|
|
530
|
+
),
|
|
531
|
+
noop
|
|
532
|
+
),
|
|
533
|
+
wasmInstancePhaseEnabled &&
|
|
534
|
+
import(createBlob(`import"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
|
|
535
|
+
() => (supportsWasmInstancePhase = true),
|
|
536
|
+
noop
|
|
537
|
+
),
|
|
538
|
+
wasmSourcePhaseEnabled &&
|
|
539
|
+
import(createBlob(`import source x from"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
|
|
540
|
+
() => (supportsWasmSourcePhase = true),
|
|
541
|
+
noop
|
|
542
|
+
)
|
|
543
|
+
]);
|
|
544
|
+
|
|
545
|
+
const msgTag = `s${version}`;
|
|
546
|
+
return new Promise(resolve => {
|
|
547
|
+
const iframe = document.createElement('iframe');
|
|
548
|
+
iframe.style.display = 'none';
|
|
549
|
+
iframe.setAttribute('nonce', nonce);
|
|
550
|
+
function cb({ data }) {
|
|
551
|
+
const isFeatureDetectionMessage = Array.isArray(data) && data[0] === msgTag;
|
|
552
|
+
if (!isFeatureDetectionMessage) return;
|
|
553
|
+
[
|
|
554
|
+
,
|
|
555
|
+
supportsImportMaps,
|
|
556
|
+
supportsMultipleImportMaps,
|
|
557
|
+
supportsJsonType,
|
|
558
|
+
supportsCssType,
|
|
559
|
+
supportsWasmSourcePhase,
|
|
560
|
+
supportsWasmInstancePhase
|
|
561
|
+
] = data;
|
|
562
|
+
resolve();
|
|
563
|
+
document.head.removeChild(iframe);
|
|
564
|
+
window.removeEventListener('message', cb, false);
|
|
565
|
+
}
|
|
566
|
+
window.addEventListener('message', cb, false);
|
|
567
|
+
// 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.
|
|
568
|
+
const importMapTest = `<script nonce=${nonce || ''}>${
|
|
569
|
+
policy ? 't=(window.trustedTypes||window.TrustedTypes).createPolicy("es-module-shims",{createScript:s=>s});' : ''
|
|
570
|
+
}b=(s,type='text/javascript')=>URL.createObjectURL(new Blob([s],{type}));c=u=>import(u).then(()=>true,()=>false);i=innerText=>${
|
|
571
|
+
policy ? 't.createScript(innerText=>' : ''
|
|
572
|
+
}document.head.appendChild(Object.assign(document.createElement('script'),{type:'importmap',nonce:"${nonce}",innerText}))${
|
|
573
|
+
policy ? ')' : ''
|
|
574
|
+
};i(\`{"imports":{"x":"\${b('')}"}}\`);i(\`{"imports":{"y":"\${b('')}"}}\`);cm=${
|
|
575
|
+
supportsImportMaps && jsonModulesEnabled ? `c(b(\`import"\${b('{}','text/json')}"with{type:"json"}\`))` : 'false'
|
|
576
|
+
};sp=${
|
|
577
|
+
supportsImportMaps && wasmSourcePhaseEnabled ?
|
|
578
|
+
`c(b(\`import source x from "\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))`
|
|
579
|
+
: 'false'
|
|
580
|
+
};Promise.all([${supportsImportMaps ? 'true' : "c('x')"},${supportsImportMaps ? "c('y')" : false},cm,${
|
|
581
|
+
supportsImportMaps && cssModulesEnabled ?
|
|
582
|
+
`cm.then(s=>s?c(b(\`import"\${b('','text/css')\}"with{type:"css"}\`)):false)`
|
|
583
|
+
: 'false'
|
|
584
|
+
},sp,${
|
|
585
|
+
supportsImportMaps && wasmInstancePhaseEnabled ?
|
|
586
|
+
`${wasmSourcePhaseEnabled ? 'sp.then(s=>s?' : ''}c(b(\`import"\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))${wasmSourcePhaseEnabled ? ':false)' : ''}`
|
|
587
|
+
: 'false'
|
|
588
|
+
}]).then(a=>parent.postMessage(['${msgTag}'].concat(a),'*'))<${''}/script>`;
|
|
589
|
+
|
|
590
|
+
// Safari will call onload eagerly on head injection, but we don't want the Wechat
|
|
591
|
+
// path to trigger before setting srcdoc, therefore we track the timing
|
|
592
|
+
let readyForOnload = false,
|
|
593
|
+
onloadCalledWhileNotReady = false;
|
|
594
|
+
function doOnload() {
|
|
595
|
+
if (!readyForOnload) {
|
|
596
|
+
onloadCalledWhileNotReady = true;
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
// WeChat browser doesn't support setting srcdoc scripts
|
|
600
|
+
// But iframe sandboxes don't support contentDocument so we do this as a fallback
|
|
601
|
+
const doc = iframe.contentDocument;
|
|
602
|
+
if (doc && doc.head.childNodes.length === 0) {
|
|
603
|
+
const s = doc.createElement('script');
|
|
604
|
+
if (nonce) s.setAttribute('nonce', nonce);
|
|
605
|
+
s.innerText = maybeTrustedScript(importMapTest.slice(15 + (nonce ? nonce.length : 0), -9));
|
|
606
|
+
doc.head.appendChild(s);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
iframe.onload = doOnload;
|
|
611
|
+
// WeChat browser requires append before setting srcdoc
|
|
612
|
+
document.head.appendChild(iframe);
|
|
613
|
+
|
|
614
|
+
// setting srcdoc is not supported in React native webviews on iOS
|
|
615
|
+
// setting src to a blob URL results in a navigation event in webviews
|
|
616
|
+
// document.write gives usability warnings
|
|
617
|
+
readyForOnload = true;
|
|
618
|
+
if ('srcdoc' in iframe) iframe.srcdoc = maybeTrustedInnerHTML(importMapTest);
|
|
619
|
+
else iframe.contentDocument.write(importMapTest);
|
|
620
|
+
// retrigger onload for Safari only if necessary
|
|
621
|
+
if (onloadCalledWhileNotReady) doOnload();
|
|
622
|
+
});
|
|
600
623
|
})();
|
|
601
624
|
|
|
602
625
|
/* es-module-lexer 2.0.0 */
|
|
@@ -714,7 +737,7 @@
|
|
|
714
737
|
// Ensure this version is the only version
|
|
715
738
|
defineValue(self_, 'importShim', Object.freeze(importShim));
|
|
716
739
|
const shimModeOptions = { ...esmsInitOptions, shimMode: true };
|
|
717
|
-
if (optionsScript) optionsScript.
|
|
740
|
+
if (optionsScript) optionsScript.innerText = maybeTrustedScript(JSON.stringify(shimModeOptions));
|
|
718
741
|
self_.esmsInitOptions = shimModeOptions;
|
|
719
742
|
|
|
720
743
|
const loadAll = async (load, seen) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** ES Module Shims Wasm @version 2.
|
|
1
|
+
/** ES Module Shims Wasm @version 2.8.0 */
|
|
2
2
|
(function () {
|
|
3
3
|
|
|
4
4
|
const self_ = typeof globalThis !== 'undefined' ? globalThis : self;
|
|
@@ -180,7 +180,7 @@
|
|
|
180
180
|
const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
|
|
181
181
|
Object.assign(esmsInitOptions, self_.esmsInitOptions || {});
|
|
182
182
|
|
|
183
|
-
const version = "2.
|
|
183
|
+
const version = "2.8.0";
|
|
184
184
|
|
|
185
185
|
const r = esmsInitOptions.version;
|
|
186
186
|
if (self_.importShim || (r && r !== version)) {
|
|
@@ -486,117 +486,140 @@
|
|
|
486
486
|
}
|
|
487
487
|
};
|
|
488
488
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
() => (
|
|
507
|
-
(supportsJsonType = true),
|
|
508
|
-
import(createBlob(`import"${createBlob('', 'text/css')}"with{type:"css"}`)).then(
|
|
509
|
-
() => (supportsCssType = true),
|
|
510
|
-
noop
|
|
511
|
-
)
|
|
512
|
-
),
|
|
513
|
-
noop
|
|
514
|
-
),
|
|
515
|
-
wasmInstancePhaseEnabled &&
|
|
516
|
-
import(createBlob(`import"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
|
|
517
|
-
() => (supportsWasmInstancePhase = true),
|
|
518
|
-
noop
|
|
519
|
-
),
|
|
520
|
-
wasmSourcePhaseEnabled &&
|
|
521
|
-
import(createBlob(`import source x from"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
|
|
522
|
-
() => (supportsWasmSourcePhase = true),
|
|
523
|
-
noop
|
|
524
|
-
)
|
|
525
|
-
]);
|
|
526
|
-
|
|
527
|
-
const msgTag = `s${version}`;
|
|
528
|
-
return new Promise(resolve => {
|
|
529
|
-
const iframe = document.createElement('iframe');
|
|
530
|
-
iframe.style.display = 'none';
|
|
531
|
-
iframe.setAttribute('nonce', nonce);
|
|
532
|
-
function cb({ data }) {
|
|
533
|
-
const isFeatureDetectionMessage = Array.isArray(data) && data[0] === msgTag;
|
|
534
|
-
if (!isFeatureDetectionMessage) return;
|
|
535
|
-
[
|
|
536
|
-
,
|
|
537
|
-
supportsImportMaps,
|
|
538
|
-
supportsMultipleImportMaps,
|
|
539
|
-
supportsJsonType,
|
|
540
|
-
supportsCssType,
|
|
541
|
-
supportsWasmSourcePhase,
|
|
542
|
-
supportsWasmInstancePhase
|
|
543
|
-
] = data;
|
|
544
|
-
resolve();
|
|
545
|
-
document.head.removeChild(iframe);
|
|
546
|
-
window.removeEventListener('message', cb, false);
|
|
547
|
-
}
|
|
548
|
-
window.addEventListener('message', cb, false);
|
|
549
|
-
|
|
550
|
-
// 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.
|
|
551
|
-
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=${
|
|
552
|
-
supportsImportMaps && jsonModulesEnabled ? `c(b(\`import"\${b('{}','text/json')}"with{type:"json"}\`))` : 'false'
|
|
553
|
-
};sp=${
|
|
554
|
-
supportsImportMaps && wasmSourcePhaseEnabled ?
|
|
555
|
-
`c(b(\`import source x from "\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))`
|
|
556
|
-
: 'false'
|
|
557
|
-
};Promise.all([${supportsImportMaps ? 'true' : "c('x')"},${supportsImportMaps ? "c('y')" : false},cm,${
|
|
558
|
-
supportsImportMaps && cssModulesEnabled ?
|
|
559
|
-
`cm.then(s=>s?c(b(\`import"\${b('','text/css')\}"with{type:"css"}\`)):false)`
|
|
560
|
-
: 'false'
|
|
561
|
-
},sp,${
|
|
562
|
-
supportsImportMaps && wasmInstancePhaseEnabled ?
|
|
563
|
-
`${wasmSourcePhaseEnabled ? 'sp.then(s=>s?' : ''}c(b(\`import"\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))${wasmSourcePhaseEnabled ? ':false)' : ''}`
|
|
564
|
-
: 'false'
|
|
565
|
-
}]).then(a=>parent.postMessage(['${msgTag}'].concat(a),'*'))<${''}/script>`;
|
|
566
|
-
|
|
567
|
-
// Safari will call onload eagerly on head injection, but we don't want the Wechat
|
|
568
|
-
// path to trigger before setting srcdoc, therefore we track the timing
|
|
569
|
-
let readyForOnload = false,
|
|
570
|
-
onloadCalledWhileNotReady = false;
|
|
571
|
-
function doOnload() {
|
|
572
|
-
if (!readyForOnload) {
|
|
573
|
-
onloadCalledWhileNotReady = true;
|
|
574
|
-
return;
|
|
575
|
-
}
|
|
576
|
-
// WeChat browser doesn't support setting srcdoc scripts
|
|
577
|
-
// But iframe sandboxes don't support contentDocument so we do this as a fallback
|
|
578
|
-
const doc = iframe.contentDocument;
|
|
579
|
-
if (doc && doc.head.childNodes.length === 0) {
|
|
580
|
-
const s = doc.createElement('script');
|
|
581
|
-
if (nonce) s.setAttribute('nonce', nonce);
|
|
582
|
-
s.innerHTML = importMapTest.slice(15 + (nonce ? nonce.length : 0), -9);
|
|
583
|
-
doc.head.appendChild(s);
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
iframe.onload = doOnload;
|
|
588
|
-
// WeChat browser requires append before setting srcdoc
|
|
589
|
-
document.head.appendChild(iframe);
|
|
489
|
+
let policy;
|
|
490
|
+
if (typeof window.trustedTypes !== 'undefined' || typeof window.TrustedTypes !== 'undefined') {
|
|
491
|
+
try {
|
|
492
|
+
policy = (window.trustedTypes || window.TrustedTypes).createPolicy('es-module-shims', {
|
|
493
|
+
createHTML: html => html,
|
|
494
|
+
createScript: script => script
|
|
495
|
+
});
|
|
496
|
+
} catch {}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
function maybeTrustedInnerHTML(html) {
|
|
500
|
+
return policy ? policy.createHTML(html) : html;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
function maybeTrustedScript(script) {
|
|
504
|
+
return policy ? policy.createScript(script) : script;
|
|
505
|
+
}
|
|
590
506
|
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
507
|
+
// support browsers without dynamic import support (eg Firefox 6x)
|
|
508
|
+
let supportsJsonType = false;
|
|
509
|
+
let supportsCssType = false;
|
|
510
|
+
|
|
511
|
+
const supports = hasDocument && HTMLScriptElement.supports;
|
|
512
|
+
|
|
513
|
+
let supportsImportMaps = supports && supports.name === 'supports' && supports('importmap');
|
|
514
|
+
let supportsWasmInstancePhase = false;
|
|
515
|
+
let supportsWasmSourcePhase = false;
|
|
516
|
+
let supportsMultipleImportMaps = false;
|
|
517
|
+
|
|
518
|
+
const wasmBytes = [0, 97, 115, 109, 1, 0, 0, 0];
|
|
519
|
+
|
|
520
|
+
let featureDetectionPromise = (async function () {
|
|
521
|
+
if (!hasDocument)
|
|
522
|
+
return Promise.all([
|
|
523
|
+
import(createBlob(`import"${createBlob('{}', 'text/json')}"with{type:"json"}`)).then(
|
|
524
|
+
() => (
|
|
525
|
+
(supportsJsonType = true),
|
|
526
|
+
import(createBlob(`import"${createBlob('', 'text/css')}"with{type:"css"}`)).then(
|
|
527
|
+
() => (supportsCssType = true),
|
|
528
|
+
noop
|
|
529
|
+
)
|
|
530
|
+
),
|
|
531
|
+
noop
|
|
532
|
+
),
|
|
533
|
+
wasmInstancePhaseEnabled &&
|
|
534
|
+
import(createBlob(`import"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
|
|
535
|
+
() => (supportsWasmInstancePhase = true),
|
|
536
|
+
noop
|
|
537
|
+
),
|
|
538
|
+
wasmSourcePhaseEnabled &&
|
|
539
|
+
import(createBlob(`import source x from"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
|
|
540
|
+
() => (supportsWasmSourcePhase = true),
|
|
541
|
+
noop
|
|
542
|
+
)
|
|
543
|
+
]);
|
|
544
|
+
|
|
545
|
+
const msgTag = `s${version}`;
|
|
546
|
+
return new Promise(resolve => {
|
|
547
|
+
const iframe = document.createElement('iframe');
|
|
548
|
+
iframe.style.display = 'none';
|
|
549
|
+
iframe.setAttribute('nonce', nonce);
|
|
550
|
+
function cb({ data }) {
|
|
551
|
+
const isFeatureDetectionMessage = Array.isArray(data) && data[0] === msgTag;
|
|
552
|
+
if (!isFeatureDetectionMessage) return;
|
|
553
|
+
[
|
|
554
|
+
,
|
|
555
|
+
supportsImportMaps,
|
|
556
|
+
supportsMultipleImportMaps,
|
|
557
|
+
supportsJsonType,
|
|
558
|
+
supportsCssType,
|
|
559
|
+
supportsWasmSourcePhase,
|
|
560
|
+
supportsWasmInstancePhase
|
|
561
|
+
] = data;
|
|
562
|
+
resolve();
|
|
563
|
+
document.head.removeChild(iframe);
|
|
564
|
+
window.removeEventListener('message', cb, false);
|
|
565
|
+
}
|
|
566
|
+
window.addEventListener('message', cb, false);
|
|
567
|
+
// 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.
|
|
568
|
+
const importMapTest = `<script nonce=${nonce || ''}>${
|
|
569
|
+
policy ? 't=(window.trustedTypes||window.TrustedTypes).createPolicy("es-module-shims",{createScript:s=>s});' : ''
|
|
570
|
+
}b=(s,type='text/javascript')=>URL.createObjectURL(new Blob([s],{type}));c=u=>import(u).then(()=>true,()=>false);i=innerText=>${
|
|
571
|
+
policy ? 't.createScript(innerText=>' : ''
|
|
572
|
+
}document.head.appendChild(Object.assign(document.createElement('script'),{type:'importmap',nonce:"${nonce}",innerText}))${
|
|
573
|
+
policy ? ')' : ''
|
|
574
|
+
};i(\`{"imports":{"x":"\${b('')}"}}\`);i(\`{"imports":{"y":"\${b('')}"}}\`);cm=${
|
|
575
|
+
supportsImportMaps && jsonModulesEnabled ? `c(b(\`import"\${b('{}','text/json')}"with{type:"json"}\`))` : 'false'
|
|
576
|
+
};sp=${
|
|
577
|
+
supportsImportMaps && wasmSourcePhaseEnabled ?
|
|
578
|
+
`c(b(\`import source x from "\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))`
|
|
579
|
+
: 'false'
|
|
580
|
+
};Promise.all([${supportsImportMaps ? 'true' : "c('x')"},${supportsImportMaps ? "c('y')" : false},cm,${
|
|
581
|
+
supportsImportMaps && cssModulesEnabled ?
|
|
582
|
+
`cm.then(s=>s?c(b(\`import"\${b('','text/css')\}"with{type:"css"}\`)):false)`
|
|
583
|
+
: 'false'
|
|
584
|
+
},sp,${
|
|
585
|
+
supportsImportMaps && wasmInstancePhaseEnabled ?
|
|
586
|
+
`${wasmSourcePhaseEnabled ? 'sp.then(s=>s?' : ''}c(b(\`import"\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))${wasmSourcePhaseEnabled ? ':false)' : ''}`
|
|
587
|
+
: 'false'
|
|
588
|
+
}]).then(a=>parent.postMessage(['${msgTag}'].concat(a),'*'))<${''}/script>`;
|
|
589
|
+
|
|
590
|
+
// Safari will call onload eagerly on head injection, but we don't want the Wechat
|
|
591
|
+
// path to trigger before setting srcdoc, therefore we track the timing
|
|
592
|
+
let readyForOnload = false,
|
|
593
|
+
onloadCalledWhileNotReady = false;
|
|
594
|
+
function doOnload() {
|
|
595
|
+
if (!readyForOnload) {
|
|
596
|
+
onloadCalledWhileNotReady = true;
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
// WeChat browser doesn't support setting srcdoc scripts
|
|
600
|
+
// But iframe sandboxes don't support contentDocument so we do this as a fallback
|
|
601
|
+
const doc = iframe.contentDocument;
|
|
602
|
+
if (doc && doc.head.childNodes.length === 0) {
|
|
603
|
+
const s = doc.createElement('script');
|
|
604
|
+
if (nonce) s.setAttribute('nonce', nonce);
|
|
605
|
+
s.innerText = maybeTrustedScript(importMapTest.slice(15 + (nonce ? nonce.length : 0), -9));
|
|
606
|
+
doc.head.appendChild(s);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
iframe.onload = doOnload;
|
|
611
|
+
// WeChat browser requires append before setting srcdoc
|
|
612
|
+
document.head.appendChild(iframe);
|
|
613
|
+
|
|
614
|
+
// setting srcdoc is not supported in React native webviews on iOS
|
|
615
|
+
// setting src to a blob URL results in a navigation event in webviews
|
|
616
|
+
// document.write gives usability warnings
|
|
617
|
+
readyForOnload = true;
|
|
618
|
+
if ('srcdoc' in iframe) iframe.srcdoc = maybeTrustedInnerHTML(importMapTest);
|
|
619
|
+
else iframe.contentDocument.write(importMapTest);
|
|
620
|
+
// retrigger onload for Safari only if necessary
|
|
621
|
+
if (onloadCalledWhileNotReady) doOnload();
|
|
622
|
+
});
|
|
600
623
|
})();
|
|
601
624
|
|
|
602
625
|
/* es-module-lexer 2.0.0 */
|
|
@@ -714,7 +737,7 @@
|
|
|
714
737
|
// Ensure this version is the only version
|
|
715
738
|
defineValue(self_, 'importShim', Object.freeze(importShim));
|
|
716
739
|
const shimModeOptions = { ...esmsInitOptions, shimMode: true };
|
|
717
|
-
if (optionsScript) optionsScript.
|
|
740
|
+
if (optionsScript) optionsScript.innerText = maybeTrustedScript(JSON.stringify(shimModeOptions));
|
|
718
741
|
self_.esmsInitOptions = shimModeOptions;
|
|
719
742
|
|
|
720
743
|
const loadAll = async (load, seen) => {
|