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)
|
if (!t.length)
|
||||||
return e;
|
return e;
|
||||||
let o = e instanceof SVGElement, i = (o ? J : I).bind(null, e, "Attribute");
|
let o = e instanceof SVGElement, i = (o ? J : I).bind(null, e, "Attribute");
|
||||||
return Object.entries(Object.assign({}, ...t)).forEach(function p([s, a]) {
|
return Object.entries(Object.assign({}, ...t)).forEach(function p([f, a]) {
|
||||||
a = r.processReactiveAttribute(e, s, a, p);
|
a = r.processReactiveAttribute(e, f, a, p);
|
||||||
let [b] = s;
|
let [b] = f;
|
||||||
if (b === "=")
|
if (b === "=")
|
||||||
return i(s.slice(1), a);
|
return i(f.slice(1), a);
|
||||||
if (b === ".")
|
if (b === ".")
|
||||||
return T(e, s.slice(1), a);
|
return T(e, f.slice(1), a);
|
||||||
if (typeof a == "object" && a !== null && !Array.isArray(a))
|
if (/(aria|data)([A-Z])/.test(f))
|
||||||
switch (s) {
|
return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(f, a);
|
||||||
case "style":
|
switch (f === "className" && (f = "class"), f) {
|
||||||
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) {
|
|
||||||
case "href":
|
case "href":
|
||||||
case "src":
|
case "src":
|
||||||
case "class":
|
case "class":
|
||||||
case "xlink:href":
|
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 "textContent":
|
||||||
case "innerText":
|
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;
|
}), e;
|
||||||
}
|
}
|
||||||
function B(e, t) {
|
function B(e, t) {
|
||||||
let n = v(this);
|
let n = v(this);
|
||||||
return typeof t != "object" || N(
|
return N(
|
||||||
n,
|
n,
|
||||||
t,
|
t,
|
||||||
(r, o) => e.classList.toggle(r, o === -1 ? void 0 : !!o)
|
(r, o) => e.classList.toggle(r, o === -1 ? void 0 : !!o)
|
||||||
@ -138,9 +133,10 @@
|
|||||||
return r || F(e, t, n + 1);
|
return r || F(e, t, n + 1);
|
||||||
}
|
}
|
||||||
function N(e, t, n) {
|
function N(e, t, n) {
|
||||||
return Object.entries(t).forEach(function([o, i]) {
|
if (typeof t == "object")
|
||||||
o && (i = e.processReactiveAttribute(t, o, i, (p) => n(...p)), n(o, i));
|
return Object.entries(t).forEach(function([o, i]) {
|
||||||
});
|
o && (i = e.processReactiveAttribute(t, o, i, (p) => n(...p)), n(o, i));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
function M(e) {
|
function M(e) {
|
||||||
return Array.isArray(e) ? e.filter(Boolean).join(" ") : e;
|
return Array.isArray(e) ? e.filter(Boolean).join(" ") : e;
|
||||||
@ -179,43 +175,43 @@
|
|||||||
};
|
};
|
||||||
function Z() {
|
function Z() {
|
||||||
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) {
|
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) {
|
||||||
for (let f of c)
|
for (let s of c)
|
||||||
if (f.type === "childList") {
|
if (s.type === "childList") {
|
||||||
if (b(f.addedNodes, !0)) {
|
if (b(s.addedNodes, !0)) {
|
||||||
p();
|
p();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
E(f.removedNodes, !0) && p();
|
E(s.removedNodes, !0) && p();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
onConnected(c, f) {
|
onConnected(c, s) {
|
||||||
i(), o(c).connected.push(f);
|
i(), o(c).connected.push(s);
|
||||||
},
|
},
|
||||||
offConnected(c, f) {
|
offConnected(c, s) {
|
||||||
if (!e.has(c))
|
if (!e.has(c))
|
||||||
return;
|
return;
|
||||||
let u = e.get(c), l = u.connected;
|
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) {
|
onDisconnected(c, s) {
|
||||||
i(), o(c).disconnected.push(f);
|
i(), o(c).disconnected.push(s);
|
||||||
},
|
},
|
||||||
offDisconnected(c, f) {
|
offDisconnected(c, s) {
|
||||||
if (!e.has(c))
|
if (!e.has(c))
|
||||||
return;
|
return;
|
||||||
let u = e.get(c), l = u.disconnected;
|
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) {
|
function r(c, s) {
|
||||||
f.connected.length || f.disconnected.length || (e.delete(c), p());
|
s.connected.length || s.disconnected.length || (e.delete(c), p());
|
||||||
}
|
}
|
||||||
function o(c) {
|
function o(c) {
|
||||||
if (e.has(c))
|
if (e.has(c))
|
||||||
return e.get(c);
|
return e.get(c);
|
||||||
let f = { connected: [], disconnected: [] };
|
let s = { connected: [], disconnected: [] };
|
||||||
return e.set(c, f), f;
|
return e.set(c, s), s;
|
||||||
}
|
}
|
||||||
function i() {
|
function i() {
|
||||||
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
|
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
|
||||||
@ -223,32 +219,32 @@
|
|||||||
function p() {
|
function p() {
|
||||||
!t || e.size || (t = !1, n.disconnect());
|
!t || e.size || (t = !1, n.disconnect());
|
||||||
}
|
}
|
||||||
function s() {
|
function f() {
|
||||||
return new Promise(function(c) {
|
return new Promise(function(c) {
|
||||||
(requestIdleCallback || requestAnimationFrame)(c);
|
(requestIdleCallback || requestAnimationFrame)(c);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async function a(c) {
|
async function a(c) {
|
||||||
e.size > 30 && await s();
|
e.size > 30 && await f();
|
||||||
let f = [];
|
let s = [];
|
||||||
if (!(c instanceof Node))
|
if (!(c instanceof Node))
|
||||||
return f;
|
return s;
|
||||||
for (let u of e.keys())
|
for (let u of e.keys())
|
||||||
u === c || !(u instanceof Node) || c.contains(u) && f.push(u);
|
u === c || !(u instanceof Node) || c.contains(u) && s.push(u);
|
||||||
return f;
|
return s;
|
||||||
}
|
}
|
||||||
function b(c, f) {
|
function b(c, s) {
|
||||||
for (let u of c) {
|
for (let u of c) {
|
||||||
if (f && a(u).then(b), !e.has(u))
|
if (s && a(u).then(b), !e.has(u))
|
||||||
continue;
|
continue;
|
||||||
let l = e.get(u);
|
let l = e.get(u);
|
||||||
return l.connected.forEach((y) => y(u)), l.connected.length = 0, l.disconnected.length || e.delete(u), !0;
|
return l.connected.forEach((y) => y(u)), l.connected.length = 0, l.disconnected.length || e.delete(u), !0;
|
||||||
}
|
}
|
||||||
return !1;
|
return !1;
|
||||||
}
|
}
|
||||||
function E(c, f) {
|
function E(c, s) {
|
||||||
for (let u of c) {
|
for (let u of c) {
|
||||||
if (f && a(u).then(E), !e.has(u))
|
if (s && a(u).then(E), !e.has(u))
|
||||||
continue;
|
continue;
|
||||||
let l = e.get(u);
|
let l = e.get(u);
|
||||||
return l.disconnected.forEach((y) => y(u)), l.connected.length = 0, l.disconnected.length = 0, e.delete(u), !0;
|
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) => {
|
let i = (p) => {
|
||||||
if (!n.parentNode || !r.parentNode)
|
if (!n.parentNode || !r.parentNode)
|
||||||
return q(e, i);
|
return q(e, i);
|
||||||
let s = t(p);
|
let f = t(p);
|
||||||
Array.isArray(s) || (s = [s]);
|
Array.isArray(f) || (f = [f]);
|
||||||
let a = n;
|
let a = n;
|
||||||
for (; (a = n.nextSibling) !== r; )
|
for (; (a = n.nextSibling) !== r; )
|
||||||
a.remove();
|
a.remove();
|
||||||
n.after(...s);
|
n.after(...f);
|
||||||
};
|
};
|
||||||
return D(e, i), i(e()), o;
|
return D(e, i), i(e()), o;
|
||||||
};
|
};
|
||||||
|
64
dist/dde.js
vendored
64
dist/dde.js
vendored
@ -9,7 +9,7 @@
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function y(e, t = !0) {
|
function P(e, t = !0) {
|
||||||
return t ? Object.assign(g, e) : (Object.setPrototypeOf(e, g), e);
|
return t ? Object.assign(g, e) : (Object.setPrototypeOf(e, g), e);
|
||||||
}
|
}
|
||||||
function v(e) {
|
function v(e) {
|
||||||
@ -30,8 +30,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// src/dom-common.js
|
// src/dom-common.js
|
||||||
var C = { setDeleteAttr: P };
|
var C = { setDeleteAttr: y };
|
||||||
function P(e, t, r) {
|
function y(e, t, r) {
|
||||||
if (Reflect.set(e, t, r), !!p(r)) {
|
if (Reflect.set(e, t, r), !!p(r)) {
|
||||||
if (e instanceof HTMLElement && e.getAttribute(t) === "undefined")
|
if (e instanceof HTMLElement && e.getAttribute(t) === "undefined")
|
||||||
return e.removeAttribute(t);
|
return e.removeAttribute(t);
|
||||||
@ -41,11 +41,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// src/dom.js
|
// src/dom.js
|
||||||
var b = "html";
|
var m = "html";
|
||||||
function I(e) {
|
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) {
|
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 === "<>":
|
case e === "<>":
|
||||||
c = x(document.createDocumentFragment(), t);
|
c = x(document.createDocumentFragment(), t);
|
||||||
break;
|
break;
|
||||||
case b !== "html":
|
case m !== "html":
|
||||||
c = x(document.createElementNS(b, e), t);
|
c = x(document.createElementNS(m, e), t);
|
||||||
break;
|
break;
|
||||||
case !c:
|
case !c:
|
||||||
c = x(document.createElement(e), t);
|
c = x(document.createElement(e), t);
|
||||||
@ -75,7 +75,7 @@
|
|||||||
let r = this, n = v(this);
|
let r = this, n = v(this);
|
||||||
if (!t.length)
|
if (!t.length)
|
||||||
return e;
|
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]) {
|
return Object.entries(Object.assign({}, ...t)).forEach(function l([f, u]) {
|
||||||
u = n.processReactiveAttribute(e, f, u, l);
|
u = n.processReactiveAttribute(e, f, u, l);
|
||||||
let [h] = f;
|
let [h] = f;
|
||||||
@ -83,18 +83,6 @@
|
|||||||
return d(f.slice(1), u);
|
return d(f.slice(1), u);
|
||||||
if (h === ".")
|
if (h === ".")
|
||||||
return D(e, f.slice(1), u);
|
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))
|
if (/(aria|data)([A-Z])/.test(f))
|
||||||
return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), d(f, u);
|
return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), d(f, u);
|
||||||
switch (f === "className" && (f = "class"), f) {
|
switch (f === "className" && (f = "class"), f) {
|
||||||
@ -106,13 +94,20 @@
|
|||||||
case "textContent":
|
case "textContent":
|
||||||
case "innerText":
|
case "innerText":
|
||||||
return c ? e.appendChild(document.createTextNode(u)) : R(e, f, u);
|
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;
|
}), e;
|
||||||
}
|
}
|
||||||
function j(e, t) {
|
function _(e, t) {
|
||||||
let r = v(this);
|
let r = v(this);
|
||||||
return typeof t != "object" || O(
|
return O(
|
||||||
r,
|
r,
|
||||||
t,
|
t,
|
||||||
(n, c) => e.classList.toggle(n, c === -1 ? void 0 : !!c)
|
(n, c) => e.classList.toggle(n, c === -1 ? void 0 : !!c)
|
||||||
@ -121,7 +116,7 @@
|
|||||||
function G(e) {
|
function G(e) {
|
||||||
return Array.from(e.children).forEach((t) => t.remove()), e;
|
return Array.from(e.children).forEach((t) => t.remove()), e;
|
||||||
}
|
}
|
||||||
function _(e, t) {
|
function T(e, t) {
|
||||||
if (!Reflect.has(e, t))
|
if (!Reflect.has(e, t))
|
||||||
return !1;
|
return !1;
|
||||||
let r = L(e, t);
|
let r = L(e, t);
|
||||||
@ -134,14 +129,15 @@
|
|||||||
return n || L(e, t, r + 1);
|
return n || L(e, t, r + 1);
|
||||||
}
|
}
|
||||||
function O(e, t, r) {
|
function O(e, t, r) {
|
||||||
return Object.entries(t).forEach(function([c, d]) {
|
if (typeof t == "object")
|
||||||
c && (d = e.processReactiveAttribute(t, c, d, (l) => r(...l)), r(c, d));
|
return Object.entries(t).forEach(function([c, d]) {
|
||||||
});
|
c && (d = e.processReactiveAttribute(t, c, d, (l) => r(...l)), r(c, d));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
function N(e) {
|
function N(e) {
|
||||||
return Array.isArray(e) ? e.filter(Boolean).join(" ") : 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));
|
return e[(p(n) ? "remove" : "set") + t](r, N(n));
|
||||||
}
|
}
|
||||||
function F(e, t, r, n, c = null) {
|
function F(e, t, r, n, c = null) {
|
||||||
@ -162,15 +158,15 @@
|
|||||||
return c.addEventListener(e, t, r), c;
|
return c.addEventListener(e, t, r), c;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
var m = M();
|
var b = M();
|
||||||
S.connected = function(e, t) {
|
S.connected = function(e, t) {
|
||||||
return function(n) {
|
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) {
|
S.disconnected = function(e, t) {
|
||||||
return function(n) {
|
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() {
|
function M() {
|
||||||
@ -263,14 +259,14 @@
|
|||||||
|
|
||||||
globalThis.dde= {
|
globalThis.dde= {
|
||||||
assign: x,
|
assign: x,
|
||||||
classListDeclarative: j,
|
classListDeclarative: _,
|
||||||
createElement: Z,
|
createElement: Z,
|
||||||
dispatchEvent: J,
|
dispatchEvent: J,
|
||||||
el: Z,
|
el: Z,
|
||||||
empty: G,
|
empty: G,
|
||||||
namespace: I,
|
namespace: I,
|
||||||
on: S,
|
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)
|
if (!t.length)
|
||||||
return e;
|
return e;
|
||||||
let o = e instanceof SVGElement, i = (o ? J : I).bind(null, e, "Attribute");
|
let o = e instanceof SVGElement, i = (o ? J : I).bind(null, e, "Attribute");
|
||||||
return Object.entries(Object.assign({}, ...t)).forEach(function p([s, a]) {
|
return Object.entries(Object.assign({}, ...t)).forEach(function p([f, a]) {
|
||||||
a = r.processReactiveAttribute(e, s, a, p);
|
a = r.processReactiveAttribute(e, f, a, p);
|
||||||
let [b] = s;
|
let [b] = f;
|
||||||
if (b === "=")
|
if (b === "=")
|
||||||
return i(s.slice(1), a);
|
return i(f.slice(1), a);
|
||||||
if (b === ".")
|
if (b === ".")
|
||||||
return T(e, s.slice(1), a);
|
return T(e, f.slice(1), a);
|
||||||
if (typeof a == "object" && a !== null && !Array.isArray(a))
|
if (/(aria|data)([A-Z])/.test(f))
|
||||||
switch (s) {
|
return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(f, a);
|
||||||
case "style":
|
switch (f === "className" && (f = "class"), f) {
|
||||||
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) {
|
|
||||||
case "href":
|
case "href":
|
||||||
case "src":
|
case "src":
|
||||||
case "class":
|
case "class":
|
||||||
case "xlink:href":
|
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 "textContent":
|
||||||
case "innerText":
|
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;
|
}), e;
|
||||||
}
|
}
|
||||||
function B(e, t) {
|
function B(e, t) {
|
||||||
let n = v(this);
|
let n = v(this);
|
||||||
return typeof t != "object" || N(
|
return N(
|
||||||
n,
|
n,
|
||||||
t,
|
t,
|
||||||
(r, o) => e.classList.toggle(r, o === -1 ? void 0 : !!o)
|
(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);
|
return r || F(e, t, n + 1);
|
||||||
}
|
}
|
||||||
function N(e, t, n) {
|
function N(e, t, n) {
|
||||||
return Object.entries(t).forEach(function([o, i]) {
|
if (typeof t == "object")
|
||||||
o && (i = e.processReactiveAttribute(t, o, i, (p) => n(...p)), n(o, i));
|
return Object.entries(t).forEach(function([o, i]) {
|
||||||
});
|
o && (i = e.processReactiveAttribute(t, o, i, (p) => n(...p)), n(o, i));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
function M(e) {
|
function M(e) {
|
||||||
return Array.isArray(e) ? e.filter(Boolean).join(" ") : e;
|
return Array.isArray(e) ? e.filter(Boolean).join(" ") : e;
|
||||||
@ -177,43 +173,43 @@ z.disconnected = function(e, t) {
|
|||||||
};
|
};
|
||||||
function Z() {
|
function Z() {
|
||||||
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) {
|
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) {
|
||||||
for (let f of c)
|
for (let s of c)
|
||||||
if (f.type === "childList") {
|
if (s.type === "childList") {
|
||||||
if (b(f.addedNodes, !0)) {
|
if (b(s.addedNodes, !0)) {
|
||||||
p();
|
p();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
E(f.removedNodes, !0) && p();
|
E(s.removedNodes, !0) && p();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
onConnected(c, f) {
|
onConnected(c, s) {
|
||||||
i(), o(c).connected.push(f);
|
i(), o(c).connected.push(s);
|
||||||
},
|
},
|
||||||
offConnected(c, f) {
|
offConnected(c, s) {
|
||||||
if (!e.has(c))
|
if (!e.has(c))
|
||||||
return;
|
return;
|
||||||
let u = e.get(c), l = u.connected;
|
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) {
|
onDisconnected(c, s) {
|
||||||
i(), o(c).disconnected.push(f);
|
i(), o(c).disconnected.push(s);
|
||||||
},
|
},
|
||||||
offDisconnected(c, f) {
|
offDisconnected(c, s) {
|
||||||
if (!e.has(c))
|
if (!e.has(c))
|
||||||
return;
|
return;
|
||||||
let u = e.get(c), l = u.disconnected;
|
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) {
|
function r(c, s) {
|
||||||
f.connected.length || f.disconnected.length || (e.delete(c), p());
|
s.connected.length || s.disconnected.length || (e.delete(c), p());
|
||||||
}
|
}
|
||||||
function o(c) {
|
function o(c) {
|
||||||
if (e.has(c))
|
if (e.has(c))
|
||||||
return e.get(c);
|
return e.get(c);
|
||||||
let f = { connected: [], disconnected: [] };
|
let s = { connected: [], disconnected: [] };
|
||||||
return e.set(c, f), f;
|
return e.set(c, s), s;
|
||||||
}
|
}
|
||||||
function i() {
|
function i() {
|
||||||
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
|
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
|
||||||
@ -221,32 +217,32 @@ function Z() {
|
|||||||
function p() {
|
function p() {
|
||||||
!t || e.size || (t = !1, n.disconnect());
|
!t || e.size || (t = !1, n.disconnect());
|
||||||
}
|
}
|
||||||
function s() {
|
function f() {
|
||||||
return new Promise(function(c) {
|
return new Promise(function(c) {
|
||||||
(requestIdleCallback || requestAnimationFrame)(c);
|
(requestIdleCallback || requestAnimationFrame)(c);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async function a(c) {
|
async function a(c) {
|
||||||
e.size > 30 && await s();
|
e.size > 30 && await f();
|
||||||
let f = [];
|
let s = [];
|
||||||
if (!(c instanceof Node))
|
if (!(c instanceof Node))
|
||||||
return f;
|
return s;
|
||||||
for (let u of e.keys())
|
for (let u of e.keys())
|
||||||
u === c || !(u instanceof Node) || c.contains(u) && f.push(u);
|
u === c || !(u instanceof Node) || c.contains(u) && s.push(u);
|
||||||
return f;
|
return s;
|
||||||
}
|
}
|
||||||
function b(c, f) {
|
function b(c, s) {
|
||||||
for (let u of c) {
|
for (let u of c) {
|
||||||
if (f && a(u).then(b), !e.has(u))
|
if (s && a(u).then(b), !e.has(u))
|
||||||
continue;
|
continue;
|
||||||
let l = e.get(u);
|
let l = e.get(u);
|
||||||
return l.connected.forEach((y) => y(u)), l.connected.length = 0, l.disconnected.length || e.delete(u), !0;
|
return l.connected.forEach((y) => y(u)), l.connected.length = 0, l.disconnected.length || e.delete(u), !0;
|
||||||
}
|
}
|
||||||
return !1;
|
return !1;
|
||||||
}
|
}
|
||||||
function E(c, f) {
|
function E(c, s) {
|
||||||
for (let u of c) {
|
for (let u of c) {
|
||||||
if (f && a(u).then(E), !e.has(u))
|
if (s && a(u).then(E), !e.has(u))
|
||||||
continue;
|
continue;
|
||||||
let l = e.get(u);
|
let l = e.get(u);
|
||||||
return l.disconnected.forEach((y) => y(u)), l.connected.length = 0, l.disconnected.length = 0, e.delete(u), !0;
|
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) => {
|
let i = (p) => {
|
||||||
if (!n.parentNode || !r.parentNode)
|
if (!n.parentNode || !r.parentNode)
|
||||||
return q(e, i);
|
return q(e, i);
|
||||||
let s = t(p);
|
let f = t(p);
|
||||||
Array.isArray(s) || (s = [s]);
|
Array.isArray(f) || (f = [f]);
|
||||||
let a = n;
|
let a = n;
|
||||||
for (; (a = n.nextSibling) !== r; )
|
for (; (a = n.nextSibling) !== r; )
|
||||||
a.remove();
|
a.remove();
|
||||||
n.after(...s);
|
n.after(...f);
|
||||||
};
|
};
|
||||||
return D(e, i), i(e()), o;
|
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;
|
return r;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function y(e, t = !0) {
|
function P(e, t = !0) {
|
||||||
return t ? Object.assign(g, e) : (Object.setPrototypeOf(e, g), e);
|
return t ? Object.assign(g, e) : (Object.setPrototypeOf(e, g), e);
|
||||||
}
|
}
|
||||||
function v(e) {
|
function v(e) {
|
||||||
@ -28,8 +28,8 @@ function w(e, t) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// src/dom-common.js
|
// src/dom-common.js
|
||||||
var C = { setDeleteAttr: P };
|
var C = { setDeleteAttr: y };
|
||||||
function P(e, t, r) {
|
function y(e, t, r) {
|
||||||
if (Reflect.set(e, t, r), !!p(r)) {
|
if (Reflect.set(e, t, r), !!p(r)) {
|
||||||
if (e instanceof HTMLElement && e.getAttribute(t) === "undefined")
|
if (e instanceof HTMLElement && e.getAttribute(t) === "undefined")
|
||||||
return e.removeAttribute(t);
|
return e.removeAttribute(t);
|
||||||
@ -39,11 +39,11 @@ function P(e, t, r) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// src/dom.js
|
// src/dom.js
|
||||||
var b = "html";
|
var m = "html";
|
||||||
function I(e) {
|
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) {
|
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 === "<>":
|
case e === "<>":
|
||||||
c = x(document.createDocumentFragment(), t);
|
c = x(document.createDocumentFragment(), t);
|
||||||
break;
|
break;
|
||||||
case b !== "html":
|
case m !== "html":
|
||||||
c = x(document.createElementNS(b, e), t);
|
c = x(document.createElementNS(m, e), t);
|
||||||
break;
|
break;
|
||||||
case !c:
|
case !c:
|
||||||
c = x(document.createElement(e), t);
|
c = x(document.createElement(e), t);
|
||||||
@ -73,7 +73,7 @@ function x(e, ...t) {
|
|||||||
let r = this, n = v(this);
|
let r = this, n = v(this);
|
||||||
if (!t.length)
|
if (!t.length)
|
||||||
return e;
|
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]) {
|
return Object.entries(Object.assign({}, ...t)).forEach(function l([f, u]) {
|
||||||
u = n.processReactiveAttribute(e, f, u, l);
|
u = n.processReactiveAttribute(e, f, u, l);
|
||||||
let [h] = f;
|
let [h] = f;
|
||||||
@ -81,18 +81,6 @@ function x(e, ...t) {
|
|||||||
return d(f.slice(1), u);
|
return d(f.slice(1), u);
|
||||||
if (h === ".")
|
if (h === ".")
|
||||||
return D(e, f.slice(1), u);
|
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))
|
if (/(aria|data)([A-Z])/.test(f))
|
||||||
return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), d(f, u);
|
return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), d(f, u);
|
||||||
switch (f === "className" && (f = "class"), f) {
|
switch (f === "className" && (f = "class"), f) {
|
||||||
@ -104,13 +92,20 @@ function x(e, ...t) {
|
|||||||
case "textContent":
|
case "textContent":
|
||||||
case "innerText":
|
case "innerText":
|
||||||
return c ? e.appendChild(document.createTextNode(u)) : R(e, f, u);
|
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;
|
}), e;
|
||||||
}
|
}
|
||||||
function j(e, t) {
|
function _(e, t) {
|
||||||
let r = v(this);
|
let r = v(this);
|
||||||
return typeof t != "object" || O(
|
return O(
|
||||||
r,
|
r,
|
||||||
t,
|
t,
|
||||||
(n, c) => e.classList.toggle(n, c === -1 ? void 0 : !!c)
|
(n, c) => e.classList.toggle(n, c === -1 ? void 0 : !!c)
|
||||||
@ -119,7 +114,7 @@ function j(e, t) {
|
|||||||
function G(e) {
|
function G(e) {
|
||||||
return Array.from(e.children).forEach((t) => t.remove()), e;
|
return Array.from(e.children).forEach((t) => t.remove()), e;
|
||||||
}
|
}
|
||||||
function _(e, t) {
|
function T(e, t) {
|
||||||
if (!Reflect.has(e, t))
|
if (!Reflect.has(e, t))
|
||||||
return !1;
|
return !1;
|
||||||
let r = L(e, t);
|
let r = L(e, t);
|
||||||
@ -132,14 +127,15 @@ function L(e, t, r = 0) {
|
|||||||
return n || L(e, t, r + 1);
|
return n || L(e, t, r + 1);
|
||||||
}
|
}
|
||||||
function O(e, t, r) {
|
function O(e, t, r) {
|
||||||
return Object.entries(t).forEach(function([c, d]) {
|
if (typeof t == "object")
|
||||||
c && (d = e.processReactiveAttribute(t, c, d, (l) => r(...l)), r(c, d));
|
return Object.entries(t).forEach(function([c, d]) {
|
||||||
});
|
c && (d = e.processReactiveAttribute(t, c, d, (l) => r(...l)), r(c, d));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
function N(e) {
|
function N(e) {
|
||||||
return Array.isArray(e) ? e.filter(Boolean).join(" ") : 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));
|
return e[(p(n) ? "remove" : "set") + t](r, N(n));
|
||||||
}
|
}
|
||||||
function F(e, t, r, n, c = null) {
|
function F(e, t, r, n, c = null) {
|
||||||
@ -160,15 +156,15 @@ function S(e, t, r) {
|
|||||||
return c.addEventListener(e, t, r), c;
|
return c.addEventListener(e, t, r), c;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
var m = M();
|
var b = M();
|
||||||
S.connected = function(e, t) {
|
S.connected = function(e, t) {
|
||||||
return function(n) {
|
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) {
|
S.disconnected = function(e, t) {
|
||||||
return function(n) {
|
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() {
|
function M() {
|
||||||
@ -260,12 +256,12 @@ function M() {
|
|||||||
});
|
});
|
||||||
export {
|
export {
|
||||||
x as assign,
|
x as assign,
|
||||||
j as classListDeclarative,
|
_ as classListDeclarative,
|
||||||
Z as createElement,
|
Z as createElement,
|
||||||
J as dispatchEvent,
|
J as dispatchEvent,
|
||||||
Z as el,
|
Z as el,
|
||||||
G as empty,
|
G as empty,
|
||||||
I as namespace,
|
I as namespace,
|
||||||
S as on,
|
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 is_svg= element instanceof SVGElement;
|
||||||
const setRemoveAttr= (is_svg ? setRemoveNS : setRemove).bind(null, element, "Attribute");
|
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 ]){
|
Object.entries(Object.assign({}, ...attributes)).forEach(function assignNth([ key, attr ]){
|
||||||
attr= s.processReactiveAttribute(element, key, attr, assignNth);
|
attr= s.processReactiveAttribute(element, key, attr, assignNth);
|
||||||
const [ k ]= key;
|
const [ k ]= key;
|
||||||
if("="===k) return setRemoveAttr(key.slice(1), attr);
|
if("="===k) return setRemoveAttr(key.slice(1), attr);
|
||||||
if("."===k) return setDelete(element, 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)){
|
if(/(aria|data)([A-Z])/.test(key)){
|
||||||
key= key.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
key= key.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
||||||
return setRemoveAttr(key, attr);
|
return setRemoveAttr(key, attr);
|
||||||
@ -69,6 +61,12 @@ export function assign(element, ...attributes){
|
|||||||
case "textContent": case "innerText":
|
case "textContent": case "innerText":
|
||||||
if(!is_svg) return setDeleteAttr(element, key, attr);
|
if(!is_svg) return setDeleteAttr(element, key, attr);
|
||||||
return element.appendChild(document.createTextNode(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);
|
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){
|
export function classListDeclarative(element, toggle){
|
||||||
const s= signals(this);
|
const s= signals(this);
|
||||||
if(typeof toggle !== "object") return element;
|
|
||||||
|
|
||||||
forEachEntries(s, toggle,
|
forEachEntries(s, toggle,
|
||||||
(class_name, val)=>
|
(class_name, val)=>
|
||||||
element.classList.toggle(class_name, val===-1 ? undefined : Boolean(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 */
|
/** @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){
|
function forEachEntries(s, obj, cb){
|
||||||
|
if(typeof obj !== "object") return;
|
||||||
return Object.entries(obj).forEach(function process([ key, val ]){
|
return Object.entries(obj).forEach(function process([ key, val ]){
|
||||||
if(!key) return;
|
if(!key) return;
|
||||||
val= s.processReactiveAttribute(obj, key, val, a=> cb(...a));
|
val= s.processReactiveAttribute(obj, key, val, a=> cb(...a));
|
||||||
|
Loading…
Reference in New Issue
Block a user