axentix
Version:
Axentix is a framework mixing fully customizable components & utility-first classes, leaving the design choice to the developer.
63 lines (62 loc) • 2.07 kB
JavaScript
const a = {
components: [],
plugins: [],
prefix: "ax",
mode: ""
}, l = (t) => a.components.find((e) => e.name === t).class, u = () => {
const t = a.components.filter((o) => o.dataDetection), e = a.plugins.filter((o) => o.dataDetection);
return [...t, ...e].map((o) => o.name);
}, p = (t) => t.replace(/[\w]([A-Z])/g, (e) => e[0] + "-" + e[1]).toLowerCase(), f = (t, e = "") => {
const o = p(t);
return e ? e + "-" + o : o;
}, g = (t, e, o, s, r = "") => {
const n = e[0].toUpperCase() + e.slice(1).toLowerCase();
u().includes(n) && o !== "Collapsible" && n !== "Sidenav" && (t[e] = l(n).getDefaultOptions());
const c = r ? r + "-" + e : e, i = d(t[e], o, s, c);
if (!(Object.keys(i).length === 0 && t.constructor === Object)) return i;
}, d = (t, e, o, s = "") => Object.keys(t).reduce((r, n) => {
if (typeof t[n] == "object" && t[n] !== null) {
const c = g(t, n, e, o, s);
c && (r[n] = c);
} else if (t[n] !== null) {
const c = "data-" + e.toLowerCase() + "-" + f(n, s);
if (o.hasAttribute(c)) {
const i = o.getAttribute(c);
r[n] = typeof t[n] == "number" ? Number(i) : i, typeof t[n] == "boolean" && (r[n] = i === "true");
}
}
return r;
}, {}), A = (t, e) => {
const o = Object.assign({}, l(t).getDefaultOptions());
return d(o, t, e);
}, x = () => {
document.querySelectorAll("[data-ax]").forEach((e) => {
let o = e.dataset.ax;
if (o = o[0].toUpperCase() + o.slice(1).toLowerCase(), !u().includes(o)) {
console.error(
`[Axentix] Error: ${o} component doesn't exist.
Did you forget to register him ?`,
e
);
return;
}
try {
const s = l(o);
new s(`#${e.id}`);
} catch (s) {
console.error("[Axentix] Data: Unable to load " + o, s);
}
});
}, O = () => {
try {
new Axentix.Axentix("all");
} catch (t) {
console.error("[Axentix] Unable to auto init.", t);
}
};
document.addEventListener("DOMContentLoaded", () => {
document.documentElement.dataset.axentix && O(), x();
});
export {
A as formatOptions
};