wj-elements
Version:
WebJET Elements is a modern set of user interface tools harnessing the power of web components designed to simplify web application development.
38 lines (37 loc) • 958 B
JavaScript
let basePath = "";
function resolveBasePathFromModuleUrl() {
var _a;
if (typeof ((_a = import.meta) == null ? void 0 : _a.url) !== "string" || import.meta.url === "") {
return "";
}
try {
return new URL(
/* @vite-ignore */
".",
import.meta.url
).href;
} catch {
return "";
}
}
function setBasePath(path) {
basePath = path;
}
function getBasePath(appendedPath = "") {
if (!basePath) {
const scripts = [...document.getElementsByTagName("script")];
const basePathScript = scripts.find((script) => script.hasAttribute("data-base-path"));
if (basePathScript) {
setBasePath(basePathScript.dataset.basePath || "");
} else {
setBasePath(resolveBasePathFromModuleUrl());
}
}
const subPath = appendedPath.replace(/^\//, "");
return basePath.replace(/\/$/, "") + (appendedPath ? "/" + subPath : "");
}
export {
getBasePath,
setBasePath
};
//# sourceMappingURL=base-path.js.map