1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2025-07-29 07:00:16 +02:00

♻️ reduce complexity and simplify code

This commit is contained in:
2023-09-21 14:37:20 +02:00
parent 8df6aa19fe
commit 19051c256a
5 changed files with 172 additions and 191 deletions

64
dist/esm.js vendored
View File

@@ -7,7 +7,7 @@ var g = {
return r;
}
};
function y(e, t = !0) {
function P(e, t = !0) {
return t ? Object.assign(g, e) : (Object.setPrototypeOf(e, g), e);
}
function v(e) {
@@ -28,8 +28,8 @@ function w(e, t) {
}
// src/dom-common.js
var C = { setDeleteAttr: P };
function P(e, t, r) {
var C = { setDeleteAttr: y };
function y(e, t, r) {
if (Reflect.set(e, t, r), !!p(r)) {
if (e instanceof HTMLElement && e.getAttribute(t) === "undefined")
return e.removeAttribute(t);
@@ -39,11 +39,11 @@ function P(e, t, r) {
}
// src/dom.js
var b = "html";
var m = "html";
function I(e) {
return b = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
return m = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(...t) {
return b = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t);
return m = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t);
}
};
}
@@ -60,8 +60,8 @@ function Z(e, t, ...r) {
case e === "<>":
c = x(document.createDocumentFragment(), t);
break;
case b !== "html":
c = x(document.createElementNS(b, e), t);
case m !== "html":
c = x(document.createElementNS(m, e), t);
break;
case !c:
c = x(document.createElement(e), t);
@@ -73,7 +73,7 @@ function x(e, ...t) {
let r = this, n = v(this);
if (!t.length)
return e;
let c = e instanceof SVGElement, d = (c ? F : T).bind(null, e, "Attribute");
let c = e instanceof SVGElement, d = (c ? F : j).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function l([f, u]) {
u = n.processReactiveAttribute(e, f, u, l);
let [h] = f;
@@ -81,18 +81,6 @@ function x(e, ...t) {
return d(f.slice(1), u);
if (h === ".")
return D(e, f.slice(1), u);
if (typeof u == "object" && u !== null && !Array.isArray(u))
switch (f) {
case "style":
case "dataset":
return O(n, u, D.bind(null, e[f]));
case "ariaset":
return O(n, u, (E, o) => d("aria-" + E, o));
case "classList":
return j.call(r, e, u);
default:
return Reflect.set(e, f, u);
}
if (/(aria|data)([A-Z])/.test(f))
return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), d(f, u);
switch (f === "className" && (f = "class"), f) {
@@ -104,13 +92,20 @@ function x(e, ...t) {
case "textContent":
case "innerText":
return c ? e.appendChild(document.createTextNode(u)) : R(e, f, u);
case "style":
case "dataset":
return O(n, u, D.bind(null, e[f]));
case "ariaset":
return O(n, u, (E, o) => d("aria-" + E, o));
case "classList":
return _.call(r, e, u);
}
return _(e, f) ? R(e, f, u) : d(f, u);
return T(e, f) ? R(e, f, u) : d(f, u);
}), e;
}
function j(e, t) {
function _(e, t) {
let r = v(this);
return typeof t != "object" || O(
return O(
r,
t,
(n, c) => e.classList.toggle(n, c === -1 ? void 0 : !!c)
@@ -119,7 +114,7 @@ function j(e, t) {
function G(e) {
return Array.from(e.children).forEach((t) => t.remove()), e;
}
function _(e, t) {
function T(e, t) {
if (!Reflect.has(e, t))
return !1;
let r = L(e, t);
@@ -132,14 +127,15 @@ function L(e, t, r = 0) {
return n || L(e, t, r + 1);
}
function O(e, t, r) {
return Object.entries(t).forEach(function([c, d]) {
c && (d = e.processReactiveAttribute(t, c, d, (l) => r(...l)), r(c, d));
});
if (typeof t == "object")
return Object.entries(t).forEach(function([c, d]) {
c && (d = e.processReactiveAttribute(t, c, d, (l) => r(...l)), r(c, d));
});
}
function N(e) {
return Array.isArray(e) ? e.filter(Boolean).join(" ") : e;
}
function T(e, t, r, n) {
function j(e, t, r, n) {
return e[(p(n) ? "remove" : "set") + t](r, N(n));
}
function F(e, t, r, n, c = null) {
@@ -160,15 +156,15 @@ function S(e, t, r) {
return c.addEventListener(e, t, r), c;
};
}
var m = M();
var b = M();
S.connected = function(e, t) {
return function(n) {
return typeof n.connectedCallback == "function" ? (n.addEventListener("dde:connected", e, t), n) : (w(t && t.signal, () => m.offConnected(n, e)) && (n.isConnected ? e(new Event("dde:connected")) : m.onConnected(n, e)), n);
return typeof n.connectedCallback == "function" ? (n.addEventListener("dde:connected", e, t), n) : (w(t && t.signal, () => b.offConnected(n, e)) && (n.isConnected ? e(new Event("dde:connected")) : b.onConnected(n, e)), n);
};
};
S.disconnected = function(e, t) {
return function(n) {
return typeof n.disconnectedCallback == "function" ? (n.addEventListener("dde:disconnected", e, t), n) : (w(t && t.signal, () => m.offDisconnected(n, e)) && m.onDisconnected(n, e), n);
return typeof n.disconnectedCallback == "function" ? (n.addEventListener("dde:disconnected", e, t), n) : (w(t && t.signal, () => b.offDisconnected(n, e)) && b.onDisconnected(n, e), n);
};
};
function M() {
@@ -260,12 +256,12 @@ function M() {
});
export {
x as assign,
j as classListDeclarative,
_ as classListDeclarative,
Z as createElement,
J as dispatchEvent,
Z as el,
G as empty,
I as namespace,
S as on,
y as registerReactivity
P as registerReactivity
};