axentix
Version:
Axentix is a framework mixing fully customizable components & utility-first classes, leaving the design choice to the developer.
78 lines (77 loc) • 2.09 kB
JavaScript
var c = Object.defineProperty;
var l = (n, e, t) => e in n ? c(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
var i = (n, e, t) => l(n, typeof e != "symbol" ? e + "" : e, t);
const r = [], a = {
components: [],
plugins: [],
prefix: "ax",
mode: ""
}, d = (n) => a.components.find((e) => e.name === n).class, p = () => {
const n = a.components.filter((t) => t.dataDetection), e = a.plugins.filter((t) => t.dataDetection);
return [...n, ...e].map((t) => t.name);
}, m = () => {
document.querySelectorAll("[data-ax]").forEach((e) => {
let t = e.dataset.ax;
if (t = t[0].toUpperCase() + t.slice(1).toLowerCase(), !p().includes(t)) {
console.error(
`[Axentix] Error: ${t} component doesn't exist.
Did you forget to register him ?`,
e
);
return;
}
try {
const s = d(t);
new s(`#${e.id}`);
} catch (s) {
console.error("[Axentix] Data: Unable to load " + t, s);
}
});
}, x = () => {
try {
new Axentix.Axentix("all");
} catch (n) {
console.error("[Axentix] Unable to auto init.", n);
}
};
document.addEventListener("DOMContentLoaded", () => {
document.documentElement.dataset.axentix && x(), m();
});
const o = (n, e, t) => {
const s = new CustomEvent("ax." + e, {
detail: {},
bubbles: !0
});
n.dispatchEvent(s);
}, u = (n) => {
const e = r.find((t) => t.type !== "Toast" && "#" + t.instance.el.id === n);
return e ? e.instance : !1;
};
class h {
constructor() {
i(this, "el");
}
removeListeners() {
}
setupListeners() {
}
setup() {
}
preventDbInstance(e) {
if (e && u(e)) throw new Error(`Instance already exist on ${e}`);
}
sync() {
o(this.el, "component.sync"), this.removeListeners(), this.setupListeners();
}
reset() {
o(this.el, "component.reset"), this.removeListeners(), this.setup();
}
destroy() {
o(this.el, "component.destroy"), this.removeListeners();
const e = r.findIndex((t) => t.instance.el.id === this.el.id);
r.splice(e, 1);
}
}
export {
h as AxentixComponent
};