Archived
Template
1
Fork 0
This repository has been archived on 2024-09-04. You can view files and clone it, but cannot push or open issues or pull requests.
Contour/public/@shoelace-style/shoelace/cdn/chunks/chunk.GU4BSX44.js
2024-01-30 10:59:28 -05:00

74 lines
1.8 KiB
JavaScript

import {
include_styles_default
} from "./chunk.WZV5AYCR.js";
import {
requestInclude
} from "./chunk.XNEONNEJ.js";
import {
watch
} from "./chunk.FA5RT4K4.js";
import {
ShoelaceElement,
n
} from "./chunk.SEXBCYCU.js";
import {
x
} from "./chunk.CXZZ2LVK.js";
import {
__decorateClass
} from "./chunk.KIILAQWQ.js";
// src/components/include/include.component.ts
var SlInclude = class extends ShoelaceElement {
constructor() {
super(...arguments);
this.mode = "cors";
this.allowScripts = false;
}
executeScript(script) {
const newScript = document.createElement("script");
[...script.attributes].forEach((attr) => newScript.setAttribute(attr.name, attr.value));
newScript.textContent = script.textContent;
script.parentNode.replaceChild(newScript, script);
}
async handleSrcChange() {
try {
const src = this.src;
const file = await requestInclude(src, this.mode);
if (src !== this.src) {
return;
}
if (!file.ok) {
this.emit("sl-error", { detail: { status: file.status } });
return;
}
this.innerHTML = file.html;
if (this.allowScripts) {
[...this.querySelectorAll("script")].forEach((script) => this.executeScript(script));
}
this.emit("sl-load");
} catch (e) {
this.emit("sl-error", { detail: { status: -1 } });
}
}
render() {
return x`<slot></slot>`;
}
};
SlInclude.styles = include_styles_default;
__decorateClass([
n()
], SlInclude.prototype, "src", 2);
__decorateClass([
n()
], SlInclude.prototype, "mode", 2);
__decorateClass([
n({ attribute: "allow-scripts", type: Boolean })
], SlInclude.prototype, "allowScripts", 2);
__decorateClass([
watch("src")
], SlInclude.prototype, "handleSrcChange", 1);
export {
SlInclude
};