@stencil/core
Version:
A Compiler for Web Components and Progressive Web Apps
46 lines (44 loc) • 1.58 kB
JavaScript
/*
Stencil Client Patch Browser v4.35.2 | MIT Licensed | https://stenciljs.com
*/
// src/client/client-patch-browser.ts
import { BUILD, NAMESPACE } from "@stencil/core/internal/app-data";
import { consoleDevInfo, H, promiseResolve, win } from "@stencil/core";
var patchBrowser = () => {
if (BUILD.isDev && !BUILD.isTesting) {
consoleDevInfo("Running in development mode.");
}
if (BUILD.cloneNodeFix) {
patchCloneNodeFix(H.prototype);
}
const scriptElm = BUILD.scriptDataOpts ? win.document && Array.from(win.document.querySelectorAll("script")).find(
(s) => new RegExp(`/${NAMESPACE}(\\.esm)?\\.js($|\\?|#)`).test(s.src) || s.getAttribute("data-stencil-namespace") === NAMESPACE
) : null;
const importMeta = import.meta.url;
const opts = BUILD.scriptDataOpts ? (scriptElm || {})["data-opts"] || {} : {};
if (importMeta !== "") {
opts.resourcesUrl = new URL(".", importMeta).href;
}
return promiseResolve(opts);
};
var patchCloneNodeFix = (HTMLElementPrototype) => {
const nativeCloneNodeFn = HTMLElementPrototype.cloneNode;
HTMLElementPrototype.cloneNode = function(deep) {
if (this.nodeName === "TEMPLATE") {
return nativeCloneNodeFn.call(this, deep);
}
const clonedNode = nativeCloneNodeFn.call(this, false);
const srcChildNodes = this.childNodes;
if (deep) {
for (let i = 0; i < srcChildNodes.length; i++) {
if (srcChildNodes[i].nodeType !== 2) {
clonedNode.appendChild(srcChildNodes[i].cloneNode(true));
}
}
}
return clonedNode;
};
};
export {
patchBrowser
};