UNPKG

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