@randevcx/ranui
Version:
UI Component library based on `Web Component`
60 lines (59 loc) • 1.9 kB
JavaScript
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
import { H as HTMLElementSSR, c as createCustomError } from "./index-CSnBqUsQ.js";
class Content extends HTMLElementSSR() {
constructor() {
super();
__publicField(this, "observer");
__publicField(this, "callback", (mutations, observer) => {
for (const mutation of mutations) {
if (mutation.type === "childList") {
this.onChange(mutation);
} else if (mutation.type === "attributes") {
this.onChange(mutation);
}
}
});
__publicField(this, "onChange", (mutation) => {
this.dispatchEvent(
new CustomEvent("change", {
detail: {
type: mutation.type,
value: { content: this.children, mutation }
}
})
);
});
this.observer = new MutationObserver(this.callback);
}
connectedCallback() {
this.setAttribute("class", "ran-content");
this.observer.observe(this, { attributes: true, childList: true, subtree: true });
}
disconnectCallback() {
this.observer.disconnect();
}
}
function Custom() {
if (typeof document !== "undefined" && !customElements.get("r-content")) {
customElements.define("r-content", Content);
return Content;
} else {
return createCustomError("document is undefined or r-content is exist");
}
}
const index = Custom();
const index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
__proto__: null,
Content,
default: index
}, Symbol.toStringTag, { value: "Module" }));
export {
Content as C,
index as a,
index$1 as i
};