UNPKG

6.62 kBJavaScriptView Raw
1import { B as BUILD, C as CSS, p as plt, w as win, a as promiseResolve, c as consoleDevInfo, H, d as doc, N as NAMESPACE } from './index-d4feb066.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 (BUILD.cssVarShim && !(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 // NOTE!! This fn cannot use async/await!
39 if (BUILD.isDev && !BUILD.isTesting) {
40 consoleDevInfo('Running in development mode.');
41 }
42 if (BUILD.cssVarShim) {
43 // shim css vars
44 plt.$cssShim$ = win.__cssshim;
45 }
46 if (BUILD.cloneNodeFix) {
47 // opted-in to polyfill cloneNode() for slot polyfilled components
48 patchCloneNodeFix(H.prototype);
49 }
50 if (BUILD.profile && !performance.mark) {
51 // not all browsers support performance.mark/measure (Safari 10)
52 performance.mark = performance.measure = () => {
53 /*noop*/
54 };
55 performance.getEntriesByName = () => [];
56 }
57 // @ts-ignore
58 const scriptElm = BUILD.scriptDataOpts || BUILD.safari10 || BUILD.dynamicImportShim
59 ? Array.from(doc.querySelectorAll('script')).find(s => new RegExp(`\/${NAMESPACE}(\\.esm)?\\.js($|\\?|#)`).test(s.src) || s.getAttribute('data-stencil-namespace') === NAMESPACE)
60 : null;
61 const importMeta = "";
62 const opts = BUILD.scriptDataOpts ? scriptElm['data-opts'] || {} : {};
63 if (BUILD.safari10 && 'onbeforeload' in scriptElm && !history.scrollRestoration /* IS_ESM_BUILD */) {
64 // Safari < v11 support: This IF is true if it's Safari below v11.
65 // This fn cannot use async/await since Safari didn't support it until v11,
66 // however, Safari 10 did support modules. Safari 10 also didn't support "nomodule",
67 // so both the ESM file and nomodule file would get downloaded. Only Safari
68 // has 'onbeforeload' in the script, and "history.scrollRestoration" was added
69 // to Safari in v11. Return a noop then() so the async/await ESM code doesn't continue.
70 // IS_ESM_BUILD is replaced at build time so this check doesn't happen in systemjs builds.
71 return {
72 then() {
73 /* promise noop */
74 },
75 };
76 }
77 if (!BUILD.safari10 && importMeta !== '') {
78 opts.resourcesUrl = new URL('.', importMeta).href;
79 }
80 else if (BUILD.dynamicImportShim || BUILD.safari10) {
81 opts.resourcesUrl = new URL('.', new URL(scriptElm.getAttribute('data-resources-url') || scriptElm.src, win.location.href)).href;
82 if (BUILD.dynamicImportShim) {
83 patchDynamicImport(opts.resourcesUrl, scriptElm);
84 }
85 if (BUILD.dynamicImportShim && !win.customElements) {
86 // module support, but no custom elements support (Old Edge)
87 // @ts-ignore
88 return import(/* webpackChunkName: "polyfills-dom" */ './dom-4061ceba.js').then(() => opts);
89 }
90 }
91 return promiseResolve(opts);
92};
93const patchDynamicImport = (base, orgScriptElm) => {
94 const importFunctionName = getDynamicImportFunction(NAMESPACE);
95 try {
96 // test if this browser supports dynamic imports
97 // There is a caching issue in V8, that breaks using import() in Function
98 // By generating a random string, we can workaround it
99 // Check https://bugs.chromium.org/p/chromium/issues/detail?id=990810 for more info
100 win[importFunctionName] = new Function('w', `return import(w);//${Math.random()}`);
101 }
102 catch (e) {
103 // this shim is specifically for browsers that do support "esm" imports
104 // however, they do NOT support "dynamic" imports
105 // basically this code is for old Edge, v18 and below
106 const moduleMap = new Map();
107 win[importFunctionName] = (src) => {
108 const url = new URL(src, base).href;
109 let mod = moduleMap.get(url);
110 if (!mod) {
111 const script = doc.createElement('script');
112 script.type = 'module';
113 script.crossOrigin = orgScriptElm.crossOrigin;
114 script.src = URL.createObjectURL(new Blob([`import * as m from '${url}'; window.${importFunctionName}.m = m;`], { type: 'application/javascript' }));
115 mod = new Promise(resolve => {
116 script.onload = () => {
117 resolve(win[importFunctionName].m);
118 script.remove();
119 };
120 });
121 moduleMap.set(url, mod);
122 doc.head.appendChild(script);
123 }
124 return mod;
125 };
126 }
127};
128const patchCloneNodeFix = (HTMLElementPrototype) => {
129 const nativeCloneNodeFn = HTMLElementPrototype.cloneNode;
130 HTMLElementPrototype.cloneNode = function (deep) {
131 if (this.nodeName === 'TEMPLATE') {
132 return nativeCloneNodeFn.call(this, deep);
133 }
134 const clonedNode = nativeCloneNodeFn.call(this, false);
135 const srcChildNodes = this.childNodes;
136 if (deep) {
137 for (let i = 0; i < srcChildNodes.length; i++) {
138 // Node.ATTRIBUTE_NODE === 2, and checking because IE11
139 if (srcChildNodes[i].nodeType !== 2) {
140 clonedNode.appendChild(srcChildNodes[i].cloneNode(true));
141 }
142 }
143 }
144 return clonedNode;
145 };
146};
147
148const globalScripts = () => {};
149
150export { patchEsm as a, globalScripts as g, patchBrowser as p };