UNPKG

4.43 kBJavaScriptView Raw
1'use strict';
2
3const index = require('./index-46f37d00.js');
4
5/*
6 Stencil Client Patch v1.15.0 | MIT Licensed | https://stenciljs.com
7 */
8const getDynamicImportFunction = (namespace) => `__sc_import_${namespace.replace(/\s|-/g, '_')}`;
9const patchEsm = () => {
10 // NOTE!! This fn cannot use async/await!
11 // @ts-ignore
12 if ( !(index.CSS && index.CSS.supports && index.CSS.supports('color', 'var(--c)'))) {
13 // @ts-ignore
14 return Promise.resolve().then(function () { return require(/* webpackChunkName: "polyfills-css-shim" */ './css-shim-564371aa.js'); }).then(() => {
15 if ((index.plt.$cssShim$ = index.win.__cssshim)) {
16 return index.plt.$cssShim$.i();
17 }
18 else {
19 // for better minification
20 return 0;
21 }
22 });
23 }
24 return index.promiseResolve();
25};
26const patchBrowser = () => {
27 {
28 // shim css vars
29 index.plt.$cssShim$ = index.win.__cssshim;
30 }
31 // @ts-ignore
32 const scriptElm = Array.from(index.doc.querySelectorAll('script')).find(s => new RegExp(`\/${index.NAMESPACE}(\\.esm)?\\.js($|\\?|#)`).test(s.src) || s.getAttribute('data-stencil-namespace') === index.NAMESPACE)
33 ;
34 const opts = scriptElm['data-opts'] || {} ;
35 if ( 'onbeforeload' in scriptElm && !history.scrollRestoration /* IS_ESM_BUILD */) {
36 // Safari < v11 support: This IF is true if it's Safari below v11.
37 // This fn cannot use async/await since Safari didn't support it until v11,
38 // however, Safari 10 did support modules. Safari 10 also didn't support "nomodule",
39 // so both the ESM file and nomodule file would get downloaded. Only Safari
40 // has 'onbeforeload' in the script, and "history.scrollRestoration" was added
41 // to Safari in v11. Return a noop then() so the async/await ESM code doesn't continue.
42 // IS_ESM_BUILD is replaced at build time so this check doesn't happen in systemjs builds.
43 return {
44 then() {
45 /* promise noop */
46 },
47 };
48 }
49 {
50 opts.resourcesUrl = new URL('.', new URL(scriptElm.getAttribute('data-resources-url') || scriptElm.src, index.win.location.href)).href;
51 {
52 patchDynamicImport(opts.resourcesUrl, scriptElm);
53 }
54 if ( !index.win.customElements) {
55 // module support, but no custom elements support (Old Edge)
56 // @ts-ignore
57 return Promise.resolve().then(function () { return require(/* webpackChunkName: "polyfills-dom" */ './dom-6b1463fe.js'); }).then(() => opts);
58 }
59 }
60 return index.promiseResolve(opts);
61};
62const patchDynamicImport = (base, orgScriptElm) => {
63 const importFunctionName = getDynamicImportFunction(index.NAMESPACE);
64 try {
65 // test if this browser supports dynamic imports
66 // There is a caching issue in V8, that breaks using import() in Function
67 // By generating a random string, we can workaround it
68 // Check https://bugs.chromium.org/p/chromium/issues/detail?id=990810 for more info
69 index.win[importFunctionName] = new Function('w', `return import(w);//${Math.random()}`);
70 }
71 catch (e) {
72 // this shim is specifically for browsers that do support "esm" imports
73 // however, they do NOT support "dynamic" imports
74 // basically this code is for old Edge, v18 and below
75 const moduleMap = new Map();
76 index.win[importFunctionName] = (src) => {
77 const url = new URL(src, base).href;
78 let mod = moduleMap.get(url);
79 if (!mod) {
80 const script = index.doc.createElement('script');
81 script.type = 'module';
82 script.crossOrigin = orgScriptElm.crossOrigin;
83 script.src = URL.createObjectURL(new Blob([`import * as m from '${url}'; window.${importFunctionName}.m = m;`], { type: 'application/javascript' }));
84 mod = new Promise(resolve => {
85 script.onload = () => {
86 resolve(index.win[importFunctionName].m);
87 script.remove();
88 };
89 });
90 moduleMap.set(url, mod);
91 index.doc.head.appendChild(script);
92 }
93 return mod;
94 };
95 }
96};
97
98exports.patchBrowser = patchBrowser;
99exports.patchEsm = patchEsm;