UNPKG

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