mirror of
https://github.com/jaandrle/deka-dom-el
synced 2024-11-22 07:49:38 +01:00
♻️ reduce complexity and simplify code
This commit is contained in:
parent
8df6aa19fe
commit
19051c256a
108
dist/dde-with-signals.js
vendored
108
dist/dde-with-signals.js
vendored
@ -80,43 +80,38 @@
|
||||
if (!t.length)
|
||||
return e;
|
||||
let o = e instanceof SVGElement, i = (o ? J : I).bind(null, e, "Attribute");
|
||||
return Object.entries(Object.assign({}, ...t)).forEach(function p([s, a]) {
|
||||
a = r.processReactiveAttribute(e, s, a, p);
|
||||
let [b] = s;
|
||||
return Object.entries(Object.assign({}, ...t)).forEach(function p([f, a]) {
|
||||
a = r.processReactiveAttribute(e, f, a, p);
|
||||
let [b] = f;
|
||||
if (b === "=")
|
||||
return i(s.slice(1), a);
|
||||
return i(f.slice(1), a);
|
||||
if (b === ".")
|
||||
return T(e, s.slice(1), a);
|
||||
if (typeof a == "object" && a !== null && !Array.isArray(a))
|
||||
switch (s) {
|
||||
case "style":
|
||||
case "dataset":
|
||||
return N(r, a, T.bind(null, e[s]));
|
||||
case "ariaset":
|
||||
return N(r, a, (E, c) => i("aria-" + E, c));
|
||||
case "classList":
|
||||
return B.call(n, e, a);
|
||||
default:
|
||||
return Reflect.set(e, s, a);
|
||||
}
|
||||
if (/(aria|data)([A-Z])/.test(s))
|
||||
return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(s, a);
|
||||
switch (s === "className" && (s = "class"), s) {
|
||||
return T(e, f.slice(1), a);
|
||||
if (/(aria|data)([A-Z])/.test(f))
|
||||
return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(f, a);
|
||||
switch (f === "className" && (f = "class"), f) {
|
||||
case "href":
|
||||
case "src":
|
||||
case "class":
|
||||
case "xlink:href":
|
||||
return i(s, a, "http://www.w3.org/1999/xlink");
|
||||
return i(f, a, "http://www.w3.org/1999/xlink");
|
||||
case "textContent":
|
||||
case "innerText":
|
||||
return o ? e.appendChild(document.createTextNode(a)) : j(e, s, a);
|
||||
return o ? e.appendChild(document.createTextNode(a)) : j(e, f, a);
|
||||
case "style":
|
||||
case "dataset":
|
||||
return N(r, a, T.bind(null, e[f]));
|
||||
case "ariaset":
|
||||
return N(r, a, (E, c) => i("aria-" + E, c));
|
||||
case "classList":
|
||||
return B.call(n, e, a);
|
||||
}
|
||||
return H(e, s) ? j(e, s, a) : i(s, a);
|
||||
return H(e, f) ? j(e, f, a) : i(f, a);
|
||||
}), e;
|
||||
}
|
||||
function B(e, t) {
|
||||
let n = v(this);
|
||||
return typeof t != "object" || N(
|
||||
return N(
|
||||
n,
|
||||
t,
|
||||
(r, o) => e.classList.toggle(r, o === -1 ? void 0 : !!o)
|
||||
@ -138,9 +133,10 @@
|
||||
return r || F(e, t, n + 1);
|
||||
}
|
||||
function N(e, t, n) {
|
||||
return Object.entries(t).forEach(function([o, i]) {
|
||||
o && (i = e.processReactiveAttribute(t, o, i, (p) => n(...p)), n(o, i));
|
||||
});
|
||||
if (typeof t == "object")
|
||||
return Object.entries(t).forEach(function([o, i]) {
|
||||
o && (i = e.processReactiveAttribute(t, o, i, (p) => n(...p)), n(o, i));
|
||||
});
|
||||
}
|
||||
function M(e) {
|
||||
return Array.isArray(e) ? e.filter(Boolean).join(" ") : e;
|
||||
@ -179,43 +175,43 @@
|
||||
};
|
||||
function Z() {
|
||||
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) {
|
||||
for (let f of c)
|
||||
if (f.type === "childList") {
|
||||
if (b(f.addedNodes, !0)) {
|
||||
for (let s of c)
|
||||
if (s.type === "childList") {
|
||||
if (b(s.addedNodes, !0)) {
|
||||
p();
|
||||
continue;
|
||||
}
|
||||
E(f.removedNodes, !0) && p();
|
||||
E(s.removedNodes, !0) && p();
|
||||
}
|
||||
});
|
||||
return {
|
||||
onConnected(c, f) {
|
||||
i(), o(c).connected.push(f);
|
||||
onConnected(c, s) {
|
||||
i(), o(c).connected.push(s);
|
||||
},
|
||||
offConnected(c, f) {
|
||||
offConnected(c, s) {
|
||||
if (!e.has(c))
|
||||
return;
|
||||
let u = e.get(c), l = u.connected;
|
||||
l.splice(l.indexOf(f), 1), r(c, u);
|
||||
l.splice(l.indexOf(s), 1), r(c, u);
|
||||
},
|
||||
onDisconnected(c, f) {
|
||||
i(), o(c).disconnected.push(f);
|
||||
onDisconnected(c, s) {
|
||||
i(), o(c).disconnected.push(s);
|
||||
},
|
||||
offDisconnected(c, f) {
|
||||
offDisconnected(c, s) {
|
||||
if (!e.has(c))
|
||||
return;
|
||||
let u = e.get(c), l = u.disconnected;
|
||||
l.splice(l.indexOf(f), 1), r(c, u);
|
||||
l.splice(l.indexOf(s), 1), r(c, u);
|
||||
}
|
||||
};
|
||||
function r(c, f) {
|
||||
f.connected.length || f.disconnected.length || (e.delete(c), p());
|
||||
function r(c, s) {
|
||||
s.connected.length || s.disconnected.length || (e.delete(c), p());
|
||||
}
|
||||
function o(c) {
|
||||
if (e.has(c))
|
||||
return e.get(c);
|
||||
let f = { connected: [], disconnected: [] };
|
||||
return e.set(c, f), f;
|
||||
let s = { connected: [], disconnected: [] };
|
||||
return e.set(c, s), s;
|
||||
}
|
||||
function i() {
|
||||
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
|
||||
@ -223,32 +219,32 @@
|
||||
function p() {
|
||||
!t || e.size || (t = !1, n.disconnect());
|
||||
}
|
||||
function s() {
|
||||
function f() {
|
||||
return new Promise(function(c) {
|
||||
(requestIdleCallback || requestAnimationFrame)(c);
|
||||
});
|
||||
}
|
||||
async function a(c) {
|
||||
e.size > 30 && await s();
|
||||
let f = [];
|
||||
e.size > 30 && await f();
|
||||
let s = [];
|
||||
if (!(c instanceof Node))
|
||||
return f;
|
||||
return s;
|
||||
for (let u of e.keys())
|
||||
u === c || !(u instanceof Node) || c.contains(u) && f.push(u);
|
||||
return f;
|
||||
u === c || !(u instanceof Node) || c.contains(u) && s.push(u);
|
||||
return s;
|
||||
}
|
||||
function b(c, f) {
|
||||
function b(c, s) {
|
||||
for (let u of c) {
|
||||
if (f && a(u).then(b), !e.has(u))
|
||||
if (s && a(u).then(b), !e.has(u))
|
||||
continue;
|
||||
let l = e.get(u);
|
||||
return l.connected.forEach((y) => y(u)), l.connected.length = 0, l.disconnected.length || e.delete(u), !0;
|
||||
}
|
||||
return !1;
|
||||
}
|
||||
function E(c, f) {
|
||||
function E(c, s) {
|
||||
for (let u of c) {
|
||||
if (f && a(u).then(E), !e.has(u))
|
||||
if (s && a(u).then(E), !e.has(u))
|
||||
continue;
|
||||
let l = e.get(u);
|
||||
return l.disconnected.forEach((y) => y(u)), l.connected.length = 0, l.disconnected.length = 0, e.delete(u), !0;
|
||||
@ -324,12 +320,12 @@
|
||||
let i = (p) => {
|
||||
if (!n.parentNode || !r.parentNode)
|
||||
return q(e, i);
|
||||
let s = t(p);
|
||||
Array.isArray(s) || (s = [s]);
|
||||
let f = t(p);
|
||||
Array.isArray(f) || (f = [f]);
|
||||
let a = n;
|
||||
for (; (a = n.nextSibling) !== r; )
|
||||
a.remove();
|
||||
n.after(...s);
|
||||
n.after(...f);
|
||||
};
|
||||
return D(e, i), i(e()), o;
|
||||
};
|
||||
|
64
dist/dde.js
vendored
64
dist/dde.js
vendored
@ -9,7 +9,7 @@
|
||||
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) {
|
||||
@ -30,8 +30,8 @@
|
||||
}
|
||||
|
||||
// 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);
|
||||
@ -41,11 +41,11 @@
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -62,8 +62,8 @@
|
||||
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);
|
||||
@ -75,7 +75,7 @@
|
||||
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;
|
||||
@ -83,18 +83,6 @@
|
||||
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) {
|
||||
@ -106,13 +94,20 @@
|
||||
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)
|
||||
@ -121,7 +116,7 @@
|
||||
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);
|
||||
@ -134,14 +129,15 @@
|
||||
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) {
|
||||
@ -162,15 +158,15 @@
|
||||
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() {
|
||||
@ -263,14 +259,14 @@
|
||||
|
||||
globalThis.dde= {
|
||||
assign: x,
|
||||
classListDeclarative: j,
|
||||
classListDeclarative: _,
|
||||
createElement: Z,
|
||||
dispatchEvent: J,
|
||||
el: Z,
|
||||
empty: G,
|
||||
namespace: I,
|
||||
on: S,
|
||||
registerReactivity: y
|
||||
registerReactivity: P
|
||||
};
|
||||
|
||||
})();
|
108
dist/esm-with-signals.js
vendored
108
dist/esm-with-signals.js
vendored
@ -78,43 +78,38 @@ function w(e, ...t) {
|
||||
if (!t.length)
|
||||
return e;
|
||||
let o = e instanceof SVGElement, i = (o ? J : I).bind(null, e, "Attribute");
|
||||
return Object.entries(Object.assign({}, ...t)).forEach(function p([s, a]) {
|
||||
a = r.processReactiveAttribute(e, s, a, p);
|
||||
let [b] = s;
|
||||
return Object.entries(Object.assign({}, ...t)).forEach(function p([f, a]) {
|
||||
a = r.processReactiveAttribute(e, f, a, p);
|
||||
let [b] = f;
|
||||
if (b === "=")
|
||||
return i(s.slice(1), a);
|
||||
return i(f.slice(1), a);
|
||||
if (b === ".")
|
||||
return T(e, s.slice(1), a);
|
||||
if (typeof a == "object" && a !== null && !Array.isArray(a))
|
||||
switch (s) {
|
||||
case "style":
|
||||
case "dataset":
|
||||
return N(r, a, T.bind(null, e[s]));
|
||||
case "ariaset":
|
||||
return N(r, a, (E, c) => i("aria-" + E, c));
|
||||
case "classList":
|
||||
return B.call(n, e, a);
|
||||
default:
|
||||
return Reflect.set(e, s, a);
|
||||
}
|
||||
if (/(aria|data)([A-Z])/.test(s))
|
||||
return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(s, a);
|
||||
switch (s === "className" && (s = "class"), s) {
|
||||
return T(e, f.slice(1), a);
|
||||
if (/(aria|data)([A-Z])/.test(f))
|
||||
return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(f, a);
|
||||
switch (f === "className" && (f = "class"), f) {
|
||||
case "href":
|
||||
case "src":
|
||||
case "class":
|
||||
case "xlink:href":
|
||||
return i(s, a, "http://www.w3.org/1999/xlink");
|
||||
return i(f, a, "http://www.w3.org/1999/xlink");
|
||||
case "textContent":
|
||||
case "innerText":
|
||||
return o ? e.appendChild(document.createTextNode(a)) : j(e, s, a);
|
||||
return o ? e.appendChild(document.createTextNode(a)) : j(e, f, a);
|
||||
case "style":
|
||||
case "dataset":
|
||||
return N(r, a, T.bind(null, e[f]));
|
||||
case "ariaset":
|
||||
return N(r, a, (E, c) => i("aria-" + E, c));
|
||||
case "classList":
|
||||
return B.call(n, e, a);
|
||||
}
|
||||
return H(e, s) ? j(e, s, a) : i(s, a);
|
||||
return H(e, f) ? j(e, f, a) : i(f, a);
|
||||
}), e;
|
||||
}
|
||||
function B(e, t) {
|
||||
let n = v(this);
|
||||
return typeof t != "object" || N(
|
||||
return N(
|
||||
n,
|
||||
t,
|
||||
(r, o) => e.classList.toggle(r, o === -1 ? void 0 : !!o)
|
||||
@ -136,9 +131,10 @@ function F(e, t, n = 0) {
|
||||
return r || F(e, t, n + 1);
|
||||
}
|
||||
function N(e, t, n) {
|
||||
return Object.entries(t).forEach(function([o, i]) {
|
||||
o && (i = e.processReactiveAttribute(t, o, i, (p) => n(...p)), n(o, i));
|
||||
});
|
||||
if (typeof t == "object")
|
||||
return Object.entries(t).forEach(function([o, i]) {
|
||||
o && (i = e.processReactiveAttribute(t, o, i, (p) => n(...p)), n(o, i));
|
||||
});
|
||||
}
|
||||
function M(e) {
|
||||
return Array.isArray(e) ? e.filter(Boolean).join(" ") : e;
|
||||
@ -177,43 +173,43 @@ z.disconnected = function(e, t) {
|
||||
};
|
||||
function Z() {
|
||||
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) {
|
||||
for (let f of c)
|
||||
if (f.type === "childList") {
|
||||
if (b(f.addedNodes, !0)) {
|
||||
for (let s of c)
|
||||
if (s.type === "childList") {
|
||||
if (b(s.addedNodes, !0)) {
|
||||
p();
|
||||
continue;
|
||||
}
|
||||
E(f.removedNodes, !0) && p();
|
||||
E(s.removedNodes, !0) && p();
|
||||
}
|
||||
});
|
||||
return {
|
||||
onConnected(c, f) {
|
||||
i(), o(c).connected.push(f);
|
||||
onConnected(c, s) {
|
||||
i(), o(c).connected.push(s);
|
||||
},
|
||||
offConnected(c, f) {
|
||||
offConnected(c, s) {
|
||||
if (!e.has(c))
|
||||
return;
|
||||
let u = e.get(c), l = u.connected;
|
||||
l.splice(l.indexOf(f), 1), r(c, u);
|
||||
l.splice(l.indexOf(s), 1), r(c, u);
|
||||
},
|
||||
onDisconnected(c, f) {
|
||||
i(), o(c).disconnected.push(f);
|
||||
onDisconnected(c, s) {
|
||||
i(), o(c).disconnected.push(s);
|
||||
},
|
||||
offDisconnected(c, f) {
|
||||
offDisconnected(c, s) {
|
||||
if (!e.has(c))
|
||||
return;
|
||||
let u = e.get(c), l = u.disconnected;
|
||||
l.splice(l.indexOf(f), 1), r(c, u);
|
||||
l.splice(l.indexOf(s), 1), r(c, u);
|
||||
}
|
||||
};
|
||||
function r(c, f) {
|
||||
f.connected.length || f.disconnected.length || (e.delete(c), p());
|
||||
function r(c, s) {
|
||||
s.connected.length || s.disconnected.length || (e.delete(c), p());
|
||||
}
|
||||
function o(c) {
|
||||
if (e.has(c))
|
||||
return e.get(c);
|
||||
let f = { connected: [], disconnected: [] };
|
||||
return e.set(c, f), f;
|
||||
let s = { connected: [], disconnected: [] };
|
||||
return e.set(c, s), s;
|
||||
}
|
||||
function i() {
|
||||
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
|
||||
@ -221,32 +217,32 @@ function Z() {
|
||||
function p() {
|
||||
!t || e.size || (t = !1, n.disconnect());
|
||||
}
|
||||
function s() {
|
||||
function f() {
|
||||
return new Promise(function(c) {
|
||||
(requestIdleCallback || requestAnimationFrame)(c);
|
||||
});
|
||||
}
|
||||
async function a(c) {
|
||||
e.size > 30 && await s();
|
||||
let f = [];
|
||||
e.size > 30 && await f();
|
||||
let s = [];
|
||||
if (!(c instanceof Node))
|
||||
return f;
|
||||
return s;
|
||||
for (let u of e.keys())
|
||||
u === c || !(u instanceof Node) || c.contains(u) && f.push(u);
|
||||
return f;
|
||||
u === c || !(u instanceof Node) || c.contains(u) && s.push(u);
|
||||
return s;
|
||||
}
|
||||
function b(c, f) {
|
||||
function b(c, s) {
|
||||
for (let u of c) {
|
||||
if (f && a(u).then(b), !e.has(u))
|
||||
if (s && a(u).then(b), !e.has(u))
|
||||
continue;
|
||||
let l = e.get(u);
|
||||
return l.connected.forEach((y) => y(u)), l.connected.length = 0, l.disconnected.length || e.delete(u), !0;
|
||||
}
|
||||
return !1;
|
||||
}
|
||||
function E(c, f) {
|
||||
function E(c, s) {
|
||||
for (let u of c) {
|
||||
if (f && a(u).then(E), !e.has(u))
|
||||
if (s && a(u).then(E), !e.has(u))
|
||||
continue;
|
||||
let l = e.get(u);
|
||||
return l.disconnected.forEach((y) => y(u)), l.connected.length = 0, l.disconnected.length = 0, e.delete(u), !0;
|
||||
@ -322,12 +318,12 @@ g.el = function(e, t) {
|
||||
let i = (p) => {
|
||||
if (!n.parentNode || !r.parentNode)
|
||||
return q(e, i);
|
||||
let s = t(p);
|
||||
Array.isArray(s) || (s = [s]);
|
||||
let f = t(p);
|
||||
Array.isArray(f) || (f = [f]);
|
||||
let a = n;
|
||||
for (; (a = n.nextSibling) !== r; )
|
||||
a.remove();
|
||||
n.after(...s);
|
||||
n.after(...f);
|
||||
};
|
||||
return D(e, i), i(e()), o;
|
||||
};
|
||||
|
64
dist/esm.js
vendored
64
dist/esm.js
vendored
@ -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
|
||||
};
|
||||
|
19
src/dom.js
19
src/dom.js
@ -44,20 +44,12 @@ export function assign(element, ...attributes){
|
||||
const is_svg= element instanceof SVGElement;
|
||||
const setRemoveAttr= (is_svg ? setRemoveNS : setRemove).bind(null, element, "Attribute");
|
||||
|
||||
/* jshint maxcomplexity:20 */
|
||||
/* jshint maxcomplexity:17 */
|
||||
Object.entries(Object.assign({}, ...attributes)).forEach(function assignNth([ key, attr ]){
|
||||
attr= s.processReactiveAttribute(element, key, attr, assignNth);
|
||||
const [ k ]= key;
|
||||
if("="===k) return setRemoveAttr(key.slice(1), attr);
|
||||
if("."===k) return setDelete(element, key.slice(1), attr);
|
||||
if(typeof attr === "object" && attr!==null && !Array.isArray(attr)){
|
||||
switch(key){
|
||||
case "style": case "dataset": return forEachEntries(s, attr, setDelete.bind(null, element[key]));
|
||||
case "ariaset": return forEachEntries(s, attr, (key, val)=> setRemoveAttr("aria-"+key, val));
|
||||
case "classList": return classListDeclarative.call(_this, element, attr);
|
||||
default: return Reflect.set(element, key, attr);
|
||||
}
|
||||
}
|
||||
if(/(aria|data)([A-Z])/.test(key)){
|
||||
key= key.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
||||
return setRemoveAttr(key, attr);
|
||||
@ -69,6 +61,12 @@ export function assign(element, ...attributes){
|
||||
case "textContent": case "innerText":
|
||||
if(!is_svg) return setDeleteAttr(element, key, attr);
|
||||
return element.appendChild(document.createTextNode(attr));
|
||||
case "style": case "dataset":
|
||||
return forEachEntries(s, attr, setDelete.bind(null, element[key]));
|
||||
case "ariaset":
|
||||
return forEachEntries(s, attr, (key, val)=> setRemoveAttr("aria-"+key, val));
|
||||
case "classList":
|
||||
return classListDeclarative.call(_this, element, attr);
|
||||
}
|
||||
return isPropSetter(element, key) ? setDeleteAttr(element, key, attr) : setRemoveAttr(key, attr);
|
||||
});
|
||||
@ -76,8 +74,6 @@ export function assign(element, ...attributes){
|
||||
}
|
||||
export function classListDeclarative(element, toggle){
|
||||
const s= signals(this);
|
||||
if(typeof toggle !== "object") return element;
|
||||
|
||||
forEachEntries(s, toggle,
|
||||
(class_name, val)=>
|
||||
element.classList.toggle(class_name, val===-1 ? undefined : Boolean(val)));
|
||||
@ -103,6 +99,7 @@ function getPropDescriptor(p, key, level= 0){
|
||||
|
||||
/** @template {Record<any, any>} T @param {object} s @param {T} obj @param {(param: [ keyof T, T[keyof T] ])=> void} cb */
|
||||
function forEachEntries(s, obj, cb){
|
||||
if(typeof obj !== "object") return;
|
||||
return Object.entries(obj).forEach(function process([ key, val ]){
|
||||
if(!key) return;
|
||||
val= s.processReactiveAttribute(obj, key, val, a=> cb(...a));
|
||||
|
Loading…
Reference in New Issue
Block a user