1 |
|
2 | var basePath = "";
|
3 | function setBasePath(path) {
|
4 | basePath = path;
|
5 | }
|
6 | function getBasePath() {
|
7 | if (!basePath) {
|
8 | const scripts = [...document.getElementsByTagName("script")];
|
9 | const configScript = scripts.find((script) => script.hasAttribute("data-shoelace"));
|
10 | if (configScript) {
|
11 | setBasePath(configScript.getAttribute("data-shoelace"));
|
12 | } else {
|
13 | const fallbackScript = scripts.find((s) => /shoelace(\.min)?\.js($|\?)/.test(s.src));
|
14 | let path = "";
|
15 | if (fallbackScript) {
|
16 | path = fallbackScript.getAttribute("src");
|
17 | }
|
18 | setBasePath(path.split("/").slice(0, -1).join("/"));
|
19 | }
|
20 | }
|
21 | return basePath.replace(/\/$/, "");
|
22 | }
|
23 |
|
24 | export {
|
25 | setBasePath,
|
26 | getBasePath
|
27 | };
|