@roukara/nodo
Version:
A class designed to facilitate the manipulation of DOM elements within web pages.
33 lines (32 loc) • 973 B
JavaScript
var n = Object.defineProperty;
var i = (r, e, t) => e in r ? n(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
var f = (r, e, t) => i(r, typeof e != "symbol" ? e + "" : e, t);
class l {
constructor(e, t = {}) {
f(this, "el");
f(this, "props");
f(this, "refs", {});
if (typeof e == "string") {
if (this.el = document.querySelector(`[data-el="${e}"]`), !this.el)
throw new Error(`Element not found with data-el attribute: ${e}`);
} else if (e instanceof HTMLElement)
this.el = e;
else
throw new Error(`Invalid type for el: ${e}`);
this.props = t, this.findRefs();
}
findRefs() {
const e = this.el.querySelectorAll("[data-ref]"), t = {};
e.forEach((o) => {
const s = o.dataset.ref;
s && (t[s] || (t[s] = []), t[s].push(o));
});
for (const o in t) {
const s = t[o];
this.refs[o] = s.length > 1 ? s : s[0];
}
}
}
export {
l as default
};