UNPKG

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