From 78fdb45ea746df449aa64b4349bf8f748618ccc0 Mon Sep 17 00:00:00 2001 From: Jan Andrle Date: Tue, 19 Sep 2023 12:34:42 +0200 Subject: [PATCH] :bug: update dom-common.js setDelete to setDeleteAttr --- dist/dde-with-signals.js | 268 ++++++++++++++++++++------------------- dist/dde.js | 100 ++++++++------- dist/esm-with-signals.js | 268 ++++++++++++++++++++------------------- dist/esm.js | 100 ++++++++------- jsdom.js | 6 +- package.json | 2 +- src/dom-common.js | 4 +- src/dom.js | 7 +- 8 files changed, 386 insertions(+), 369 deletions(-) diff --git a/dist/dde-with-signals.js b/dist/dde-with-signals.js index 38bb13a..533a6fa 100644 --- a/dist/dde-with-signals.js +++ b/dist/dde-with-signals.js @@ -1,19 +1,19 @@ //deka-dom-el library is available via global namespace `dde` (()=> { // src/signals-common.js - var x = { + var b = { isTextContent(e) { return typeof e == "string"; }, - processReactiveAttribute(e, t, r, n) { - return r; + processReactiveAttribute(e, t, n, r) { + return n; } }; function _(e, t = !0) { - return t ? Object.assign(x, e) : (Object.setPrototypeOf(e, x), e); + return t ? Object.assign(b, e) : (Object.setPrototypeOf(e, b), e); } function N(e) { - return x.isPrototypeOf(e) && e !== x ? e : x; + return b.isPrototypeOf(e) && e !== b ? e : b; } // src/helpers.js @@ -24,7 +24,7 @@ let t = typeof e; return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e); } - function j(e, t) { + function D(e, t) { if (!e || !(e instanceof AbortSignal)) return !0; if (!e.aborted) @@ -34,25 +34,25 @@ } // src/dom-common.js - var b = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')), T = { setDelete: $ }; - function $(e, t, r) { - Reflect.set(e, t, r), m(r) && e.getAttribute(t) === "undefined" && e.removeAttribute(t); + var x = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')), j = { setDeleteAttr: k }; + function k(e, t, n) { + Reflect.set(e, t, n), m(n) && e.getAttribute(t) === "undefined" && e.removeAttribute(t); } // src/dom.js var S = "html"; - function oe(e) { + function ce(e) { return S = e === "svg" ? "http://www.w3.org/2000/svg" : e, { append(...t) { return S = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t); } }; } - function ce(e, t, ...r) { - let n = N(this), o; - switch (n.isTextContent(t) && (t = { textContent: t }), !0) { + function ie(e, t, ...n) { + let r = N(this), o; + switch (r.isTextContent(t) && (t = { textContent: t }), !0) { case typeof e == "function": { - o = e(t || void 0, (i) => i ? (r.unshift(i), void 0) : o); + o = e(t || void 0, (i) => i ? (n.unshift(i), void 0) : o); break; } case e === "#text": @@ -67,31 +67,31 @@ case !o: o = y(document.createElement(e), t); } - return r.forEach((a) => a(o)), o; + return n.forEach((a) => a(o)), o; } - var { setDelete: D } = T; + var { setDeleteAttr: q } = j; function y(e, ...t) { - let r = N(this); + let n = N(this); if (!t.length) return e; - let n = e instanceof SVGElement, o = (n ? W : M).bind(null, e, "Attribute"); + let r = e instanceof SVGElement, o = (r ? I : T).bind(null, e, "Attribute"); return Object.entries(Object.assign({}, ...t)).forEach(function a([i, s]) { - s = r.processReactiveAttribute(e, i, s, a); + s = n.processReactiveAttribute(e, i, s, a); let [h] = i; if (h === "=") return o(i.slice(1), s); if (h === ".") - return D(e, i.slice(1), s); + return M(e, i.slice(1), s); if (typeof s == "object") switch (i) { case "style": - return O(s, M.bind(null, e.style, "Property")); + return O(s, T.bind(null, e.style, "Property")); case "dataset": - return O(s, D.bind(null, e.dataset)); + return O(s, M.bind(null, e.dataset)); case "ariaset": return O(s, (E, v) => o("aria-" + E, v)); case "classList": - return q(e, s); + return J(e, s); default: return Reflect.set(e, i, s); } @@ -103,71 +103,75 @@ case "xlink:href": return o(i, s, "http://www.w3.org/1999/xlink"); case "textContent": - if (!n) + if (!r) break; return e.appendChild(document.createTextNode(s)); } - return J(e, i) ? D(e, i, s) : o(i, s); + return W(e, i) ? q(e, i, s) : o(i, s); }), e; } - function q(e, t) { + function J(e, t) { return typeof t != "object" || O( t, - (r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n) + (n, r) => e.classList.toggle(n, r === -1 ? void 0 : !!r) ), e; } - function se(e) { + function fe(e) { return Array.from(e.children).forEach((t) => t.remove()), e; } - function J(e, t) { - let r = "HTMLElement," + t; - if (e instanceof HTMLElement && b.has(r)) - return b.get(r); - let n = e.nodeName + "," + t; - if (b.has(n)) - return b.get(n); + function W(e, t) { + let n = "HTMLElement," + t; + if (e instanceof HTMLElement && x.has(n)) + return x.get(n); + let r = e.nodeName + "," + t; + if (x.has(r)) + return x.get(r); let [o, a, i] = H(e, t), s = !m(o.set); - return (!s || a) && b.set(i === HTMLElement.prototype ? r : n, s), s; + return (!s || a) && x.set(i === HTMLElement.prototype ? n : r, s), s; } - function H(e, t, r = 0) { + function H(e, t, n = 0) { if (e = Object.getPrototypeOf(e), !e) - return [{}, r, e]; - let n = Object.getOwnPropertyDescriptor(e, t); - return n ? [n, r, e] : H(e, t, r + 1); + return [{}, n, e]; + let r = Object.getOwnPropertyDescriptor(e, t); + return r ? [r, n, e] : H(e, t, n + 1); } function O(e, t) { - return Object.entries(e).forEach(([r, n]) => t(r, n)); + return Object.entries(e).forEach(([n, r]) => n && t(n, r)); } - function M(e, t, r, n) { - return e[(m(n) ? "remove" : "set") + t](r, n); + function T(e, t, n, r) { + return e[(m(r) ? "remove" : "set") + t](n, r); } - function W(e, t, r, n, o = null) { - return e[(m(n) ? "remove" : "set") + t + "NS"](o, r, n); + function I(e, t, n, r, o = null) { + return e[(m(r) ? "remove" : "set") + t + "NS"](o, n, r); + } + function M(e, t, n) { + if (Reflect.set(e, t, n), !!m(n)) + return Reflect.deleteProperty(e, t); } // src/events.js - function ae(e, t, ...r) { - let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t); - return e.dispatchEvent(n); + function de(e, t, ...n) { + let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); + return e.dispatchEvent(r); } - function k(e, t, r) { + function F(e, t, n) { return function(o) { - return o.addEventListener(e, t, r), o; + return o.addEventListener(e, t, n), o; }; } - var C = I(); - k.connected = function(e, t) { - return function(n) { - return typeof n.connectedCallback == "function" ? (n.addEventListener("dde:connected", e, t), n) : (j(t && t.signal, () => C.offConnected(n, e)) && (n.isConnected ? e(new Event("dde:connected")) : C.onConnected(n, e)), n); + var C = Z(); + F.connected = function(e, t) { + return function(r) { + return typeof r.connectedCallback == "function" ? (r.addEventListener("dde:connected", e, t), r) : (D(t && t.signal, () => C.offConnected(r, e)) && (r.isConnected ? e(new Event("dde:connected")) : C.onConnected(r, e)), r); }; }; - k.disconnected = function(e, t) { - return function(n) { - return typeof n.disconnectedCallback == "function" ? (n.addEventListener("dde:disconnected", e, t), n) : (j(t && t.signal, () => C.offDisconnected(n, e)) && C.onDisconnected(n, e), n); + F.disconnected = function(e, t) { + return function(r) { + return typeof r.disconnectedCallback == "function" ? (r.addEventListener("dde:disconnected", e, t), r) : (D(t && t.signal, () => C.offDisconnected(r, e)) && C.onDisconnected(r, e), r); }; }; - function I() { - let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(c) { + function Z() { + let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) { for (let f of c) if (f.type === "childList") { if (E(f.addedNodes, !0)) { @@ -185,7 +189,7 @@ if (!e.has(c)) return; let u = e.get(c), p = u.connected; - p.splice(p.indexOf(f), 1), n(c, u); + p.splice(p.indexOf(f), 1), r(c, u); }, onDisconnected(c, f) { a(), o(c).disconnected.push(f); @@ -194,10 +198,10 @@ if (!e.has(c)) return; let u = e.get(c), p = u.disconnected; - p.splice(p.indexOf(f), 1), n(c, u); + p.splice(p.indexOf(f), 1), r(c, u); } }; - function n(c, f) { + function r(c, f) { f.connected.length || f.disconnected.length || (e.delete(c), i()); } function o(c) { @@ -207,10 +211,10 @@ return e.set(c, f), f; } function a() { - t || (t = !0, r.observe(document.body, { childList: !0, subtree: !0 })); + t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 })); } function i() { - !t || e.size || (t = !1, r.disconnect()); + !t || e.size || (t = !1, n.disconnect()); } function s() { return new Promise(function(c) { @@ -231,7 +235,7 @@ if (f && h(u).then(E), !e.has(u)) continue; let p = e.get(u); - return p.connected.forEach((A) => A(u)), p.connected.length = 0, p.disconnected.length || e.delete(u), !0; + return p.connected.forEach((L) => L(u)), p.connected.length = 0, p.disconnected.length || e.delete(u), !0; } return !1; } @@ -240,7 +244,7 @@ if (f && h(u).then(v), !e.has(u)) continue; let p = e.get(u); - return p.disconnected.forEach((A) => A(u)), p.connected.length = 0, p.disconnected.length = 0, e.delete(u), !0; + return p.disconnected.forEach((L) => L(u)), p.connected.length = 0, p.disconnected.length = 0, e.delete(u), !0; } return !1; } @@ -249,14 +253,14 @@ // index.js [HTMLElement, DocumentFragment].forEach((e) => { let { append: t } = e.prototype; - e.prototype.append = function(...r) { - return t.apply(this, r), this; + e.prototype.append = function(...n) { + return t.apply(this, n), this; }; }); // src/signals-lib.js var d = Symbol.for("Signal"); - function L(e) { + function R(e) { try { return Reflect.has(e, d); } catch { @@ -266,26 +270,26 @@ var l = /* @__PURE__ */ new WeakMap(); function g(e, t) { if (typeof e != "function") - return F(e, t); - if (L(e)) + return z(e, t); + if (R(e)) return e; - let r = F(""), n = () => r(e()); - return l.set(n, /* @__PURE__ */ new Set([r])), G(n), r; + let n = z(""), r = () => n(e()); + return l.set(r, /* @__PURE__ */ new Set([n])), V(r), n; } - g.action = function(e, t, ...r) { - let n = e[d], { actions: o } = n; + g.action = function(e, t, ...n) { + let r = e[d], { actions: o } = r; if (!o || !Reflect.has(o, t)) throw new Error(`'${e}' has no action with name '${t}'!`); - if (o[t].apply(n, r), n.skip) - return Reflect.deleteProperty(n, "skip"); - n.listeners.forEach((a) => a(n.value)); + if (o[t].apply(r, n), r.skip) + return Reflect.deleteProperty(r, "skip"); + r.listeners.forEach((a) => a(r.value)); }; - g.on = function e(t, r, n = {}) { - let { signal: o } = n; + g.on = function e(t, n, r = {}) { + let { signal: o } = r; if (!(o && o.aborted)) { if (Array.isArray(t)) - return t.forEach((a) => e(a, r, n)); - P(t, r), o && o.addEventListener("abort", () => U(t, r)); + return t.forEach((a) => e(a, n, r)); + P(t, n), o && o.addEventListener("abort", () => $(t, n)); } }; g.symbols = { @@ -293,108 +297,108 @@ onclear: Symbol.for("Signal.onclear") }; g.clear = function(...e) { - for (let r of e) { - Reflect.deleteProperty(r, "toJSON"); - let n = r[d], { onclear: o } = g.symbols; - n.actions && n.actions[o] && n.actions[o].call(n), t(r, n), Reflect.deleteProperty(r, d); + for (let n of e) { + Reflect.deleteProperty(n, "toJSON"); + let r = n[d], { onclear: o } = g.symbols; + r.actions && r.actions[o] && r.actions[o].call(r), t(n, r), Reflect.deleteProperty(n, d); } - function t(r, n) { - n.listeners.forEach((o) => { - if (n.listeners.delete(o), !l.has(o)) + function t(n, r) { + r.listeners.forEach((o) => { + if (r.listeners.delete(o), !l.has(o)) return; let a = l.get(o); - a.delete(r), !(a.size > 1) && (g.clear(...a), l.delete(o)); + a.delete(n), !(a.size > 1) && (g.clear(...a), l.delete(o)); }); } }; g.el = function(e, t) { - let r = document.createComment("<#reactive>"), n = document.createComment(""), o = document.createDocumentFragment(); - o.append(r, n); + let n = document.createComment("<#reactive>"), r = document.createComment(""), o = document.createDocumentFragment(); + o.append(n, r); let a = (i) => { - if (!r.parentNode || !n.parentNode) - return U(e, a); + if (!n.parentNode || !r.parentNode) + return $(e, a); let s = t(i); Array.isArray(s) || (s = [s]); - let h = r; - for (; (h = r.nextSibling) !== n; ) + let h = n; + for (; (h = n.nextSibling) !== r; ) h.remove(); - r.after(...s); + n.after(...s); }; return P(e, a), a(e()), o; }; - var z = { + var U = { isTextContent(e) { - return w(e) === "string" || L(e) && w(X(e)) === "string"; + return w(e) === "string" || R(e) && w(Y(e)) === "string"; }, - processReactiveAttribute(e, t, r, n) { - return L(r) ? (P(r, (o) => n([t, o])), r()) : r; + processReactiveAttribute(e, t, n, r) { + return R(n) ? (P(n, (o) => r([t, o])), n()) : n; } }; - function F(e, t) { - let r = (...n) => n.length ? Q(r, n[0]) : K(r); - return B(r, e, t); + function z(e, t) { + let n = (...r) => r.length ? X(n, r[0]) : Q(n); + return G(n, e, t); } - var Z = Object.assign(/* @__PURE__ */ Object.create(null), { + var B = Object.assign(/* @__PURE__ */ Object.create(null), { stopPropagation() { this.skip = !0; } }); - function B(e, t, r) { - return w(r) !== "[object Object]" && (r = {}), e[d] = { + function G(e, t, n) { + return w(n) !== "[object Object]" && (n = {}), e[d] = { value: t, - actions: r, + actions: n, listeners: /* @__PURE__ */ new Set() - }, e.toJSON = () => e(), Object.setPrototypeOf(e[d], Z), e; + }, e.toJSON = () => e(), Object.setPrototypeOf(e[d], B), e; } - var R = []; - function G(e) { + var A = []; + function V(e) { let t = function() { - R.push(t), e(), R.pop(); + A.push(t), e(), A.pop(); }; l.has(e) && (l.set(t, l.get(e)), l.delete(e)), t(); } - function V() { - return R[R.length - 1]; + function K() { + return A[A.length - 1]; } - function K(e) { + function Q(e) { if (!e[d]) return; - let { value: t, listeners: r } = e[d], n = V(); - return n && r.add(n), l.has(n) && l.get(n).add(e), t; + let { value: t, listeners: n } = e[d], r = K(); + return r && n.add(r), l.has(r) && l.get(r).add(e), t; } - function Q(e, t) { + function X(e, t) { if (!e[d]) return; - let r = e[d]; - if (r.value !== t) - return r.value = t, r.listeners.forEach((n) => n(t)), t; + let n = e[d]; + if (n.value !== t) + return n.value = t, n.listeners.forEach((r) => r(t)), t; } - function X(e) { + function Y(e) { return e[d].value; } function P(e, t) { if (e[d]) return e[d].listeners.add(t); } - function U(e, t) { + function $(e, t) { if (e[d]) return e[d].listeners.delete(t); } // signals.js - _(z); + _(U); globalThis.dde= { S: g, assign: y, - classListDeclarative: q, - createElement: ce, - dispatchEvent: ae, - el: ce, - empty: se, - isSignal: L, - namespace: oe, - on: k, + classListDeclarative: J, + createElement: ie, + dispatchEvent: de, + el: ie, + empty: fe, + isSignal: R, + namespace: ce, + on: F, registerReactivity: _ }; diff --git a/dist/dde.js b/dist/dde.js index 1a06edc..477f13d 100644 --- a/dist/dde.js +++ b/dist/dde.js @@ -9,7 +9,7 @@ return r; } }; - function T(e, t = !0) { + function _(e, t = !0) { return t ? Object.assign(g, e) : (Object.setPrototypeOf(e, g), e); } function O(e) { @@ -30,21 +30,21 @@ } // src/dom-common.js - var h = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')), A = { setDelete: R }; - function R(e, t, r) { + var l = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')), A = { setDeleteAttr: T }; + function T(e, t, r) { Reflect.set(e, t, r), p(r) && e.getAttribute(t) === "undefined" && e.removeAttribute(t); } // src/dom.js var v = "html"; - function I(e) { + function Z(e) { return v = e === "svg" ? "http://www.w3.org/2000/svg" : e, { append(...t) { return v = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t); } }; } - function Z(e, t, ...r) { + function $(e, t, ...r) { let n = O(this), c; switch (n.isTextContent(t) && (t = { textContent: t }), !0) { case typeof e == "function": { @@ -52,31 +52,31 @@ break; } case e === "#text": - c = E(document.createTextNode(""), t); + c = b(document.createTextNode(""), t); break; case e === "<>": - c = E(document.createDocumentFragment(), t); + c = b(document.createDocumentFragment(), t); break; case v !== "html": - c = E(document.createElementNS(v, e), t); + c = b(document.createElementNS(v, e), t); break; case !c: - c = E(document.createElement(e), t); + c = b(document.createElement(e), t); } return r.forEach((a) => a(c)), c; } - var { setDelete: y } = A; - function E(e, ...t) { + var { setDeleteAttr: M } = A; + function b(e, ...t) { let r = O(this); if (!t.length) return e; - let n = e instanceof SVGElement, c = (n ? S : N).bind(null, e, "Attribute"); + let n = e instanceof SVGElement, c = (n ? j : N).bind(null, e, "Attribute"); return Object.entries(Object.assign({}, ...t)).forEach(function a([s, f]) { f = r.processReactiveAttribute(e, s, f, a); - let [l] = s; - if (l === "=") + let [h] = s; + if (h === "=") return c(s.slice(1), f); - if (l === ".") + if (h === ".") return y(e, s.slice(1), f); if (typeof f == "object") switch (s) { @@ -85,9 +85,9 @@ case "dataset": return m(f, y.bind(null, e.dataset)); case "ariaset": - return m(f, (x, b) => c("aria-" + x, b)); + return m(f, (x, E) => c("aria-" + x, E)); case "classList": - return j(e, f); + return P(e, f); default: return Reflect.set(e, s, f); } @@ -103,27 +103,27 @@ break; return e.appendChild(document.createTextNode(f)); } - return M(e, s) ? y(e, s, f) : c(s, f); + return S(e, s) ? M(e, s, f) : c(s, f); }), e; } - function j(e, t) { + function P(e, t) { return typeof t != "object" || m( t, (r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n) ), e; } - function B(e) { + function G(e) { return Array.from(e.children).forEach((t) => t.remove()), e; } - function M(e, t) { + function S(e, t) { let r = "HTMLElement," + t; - if (e instanceof HTMLElement && h.has(r)) - return h.get(r); + if (e instanceof HTMLElement && l.has(r)) + return l.get(r); let n = e.nodeName + "," + t; - if (h.has(n)) - return h.get(n); + if (l.has(n)) + return l.get(n); let [c, a, s] = D(e, t), f = !p(c.set); - return (!f || a) && h.set(s === HTMLElement.prototype ? r : n, f), f; + return (!f || a) && l.set(s === HTMLElement.prototype ? r : n, f), f; } function D(e, t, r = 0) { if (e = Object.getPrototypeOf(e), !e) @@ -132,37 +132,41 @@ return n ? [n, r, e] : D(e, t, r + 1); } function m(e, t) { - return Object.entries(e).forEach(([r, n]) => t(r, n)); + return Object.entries(e).forEach(([r, n]) => r && t(r, n)); } function N(e, t, r, n) { return e[(p(n) ? "remove" : "set") + t](r, n); } - function S(e, t, r, n, c = null) { + function j(e, t, r, n, c = null) { return e[(p(n) ? "remove" : "set") + t + "NS"](c, r, n); } + function y(e, t, r) { + if (Reflect.set(e, t, r), !!p(r)) + return Reflect.deleteProperty(e, t); + } // src/events.js - function V(e, t, ...r) { + function W(e, t, ...r) { let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t); return e.dispatchEvent(n); } - function _(e, t, r) { + function R(e, t, r) { return function(c) { return c.addEventListener(e, t, r), c; }; } - var w = P(); - _.connected = function(e, t) { + var w = H(); + R.connected = function(e, t) { return function(n) { return typeof n.connectedCallback == "function" ? (n.addEventListener("dde:connected", e, t), n) : (L(t && t.signal, () => w.offConnected(n, e)) && (n.isConnected ? e(new Event("dde:connected")) : w.onConnected(n, e)), n); }; }; - _.disconnected = function(e, t) { + R.disconnected = function(e, t) { return function(n) { return typeof n.disconnectedCallback == "function" ? (n.addEventListener("dde:disconnected", e, t), n) : (L(t && t.signal, () => w.offDisconnected(n, e)) && w.onDisconnected(n, e), n); }; }; - function P() { + function H() { let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(o) { for (let i of o) if (i.type === "childList") { @@ -170,7 +174,7 @@ s(); continue; } - b(i.removedNodes, !0) && s(); + E(i.removedNodes, !0) && s(); } }); return { @@ -213,7 +217,7 @@ (requestIdleCallback || requestAnimationFrame)(o); }); } - async function l(o) { + async function h(o) { e.size > 30 && await f(); let i = []; if (!(o instanceof Node)) @@ -224,16 +228,16 @@ } function x(o, i) { for (let u of o) { - if (i && l(u).then(x), !e.has(u)) + if (i && h(u).then(x), !e.has(u)) continue; let d = e.get(u); return d.connected.forEach((C) => C(u)), d.connected.length = 0, d.disconnected.length || e.delete(u), !0; } return !1; } - function b(o, i) { + function E(o, i) { for (let u of o) { - if (i && l(u).then(b), !e.has(u)) + if (i && h(u).then(E), !e.has(u)) continue; let d = e.get(u); return d.disconnected.forEach((C) => C(u)), d.connected.length = 0, d.disconnected.length = 0, e.delete(u), !0; @@ -251,15 +255,15 @@ }); globalThis.dde= { - assign: E, - classListDeclarative: j, - createElement: Z, - dispatchEvent: V, - el: Z, - empty: B, - namespace: I, - on: _, - registerReactivity: T + assign: b, + classListDeclarative: P, + createElement: $, + dispatchEvent: W, + el: $, + empty: G, + namespace: Z, + on: R, + registerReactivity: _ }; })(); \ No newline at end of file diff --git a/dist/esm-with-signals.js b/dist/esm-with-signals.js index 570f84e..10a4a94 100644 --- a/dist/esm-with-signals.js +++ b/dist/esm-with-signals.js @@ -1,17 +1,17 @@ // src/signals-common.js -var x = { +var b = { isTextContent(e) { return typeof e == "string"; }, - processReactiveAttribute(e, t, r, n) { - return r; + processReactiveAttribute(e, t, n, r) { + return n; } }; function _(e, t = !0) { - return t ? Object.assign(x, e) : (Object.setPrototypeOf(e, x), e); + return t ? Object.assign(b, e) : (Object.setPrototypeOf(e, b), e); } function N(e) { - return x.isPrototypeOf(e) && e !== x ? e : x; + return b.isPrototypeOf(e) && e !== b ? e : b; } // src/helpers.js @@ -22,7 +22,7 @@ function w(e) { let t = typeof e; return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e); } -function j(e, t) { +function D(e, t) { if (!e || !(e instanceof AbortSignal)) return !0; if (!e.aborted) @@ -32,25 +32,25 @@ function j(e, t) { } // src/dom-common.js -var b = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')), T = { setDelete: $ }; -function $(e, t, r) { - Reflect.set(e, t, r), m(r) && e.getAttribute(t) === "undefined" && e.removeAttribute(t); +var x = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')), j = { setDeleteAttr: k }; +function k(e, t, n) { + Reflect.set(e, t, n), m(n) && e.getAttribute(t) === "undefined" && e.removeAttribute(t); } // src/dom.js var S = "html"; -function oe(e) { +function ce(e) { return S = e === "svg" ? "http://www.w3.org/2000/svg" : e, { append(...t) { return S = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t); } }; } -function ce(e, t, ...r) { - let n = N(this), o; - switch (n.isTextContent(t) && (t = { textContent: t }), !0) { +function ie(e, t, ...n) { + let r = N(this), o; + switch (r.isTextContent(t) && (t = { textContent: t }), !0) { case typeof e == "function": { - o = e(t || void 0, (i) => i ? (r.unshift(i), void 0) : o); + o = e(t || void 0, (i) => i ? (n.unshift(i), void 0) : o); break; } case e === "#text": @@ -65,31 +65,31 @@ function ce(e, t, ...r) { case !o: o = y(document.createElement(e), t); } - return r.forEach((a) => a(o)), o; + return n.forEach((a) => a(o)), o; } -var { setDelete: D } = T; +var { setDeleteAttr: q } = j; function y(e, ...t) { - let r = N(this); + let n = N(this); if (!t.length) return e; - let n = e instanceof SVGElement, o = (n ? W : M).bind(null, e, "Attribute"); + let r = e instanceof SVGElement, o = (r ? I : T).bind(null, e, "Attribute"); return Object.entries(Object.assign({}, ...t)).forEach(function a([i, s]) { - s = r.processReactiveAttribute(e, i, s, a); + s = n.processReactiveAttribute(e, i, s, a); let [h] = i; if (h === "=") return o(i.slice(1), s); if (h === ".") - return D(e, i.slice(1), s); + return M(e, i.slice(1), s); if (typeof s == "object") switch (i) { case "style": - return O(s, M.bind(null, e.style, "Property")); + return O(s, T.bind(null, e.style, "Property")); case "dataset": - return O(s, D.bind(null, e.dataset)); + return O(s, M.bind(null, e.dataset)); case "ariaset": return O(s, (E, v) => o("aria-" + E, v)); case "classList": - return q(e, s); + return J(e, s); default: return Reflect.set(e, i, s); } @@ -101,71 +101,75 @@ function y(e, ...t) { case "xlink:href": return o(i, s, "http://www.w3.org/1999/xlink"); case "textContent": - if (!n) + if (!r) break; return e.appendChild(document.createTextNode(s)); } - return J(e, i) ? D(e, i, s) : o(i, s); + return W(e, i) ? q(e, i, s) : o(i, s); }), e; } -function q(e, t) { +function J(e, t) { return typeof t != "object" || O( t, - (r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n) + (n, r) => e.classList.toggle(n, r === -1 ? void 0 : !!r) ), e; } -function se(e) { +function fe(e) { return Array.from(e.children).forEach((t) => t.remove()), e; } -function J(e, t) { - let r = "HTMLElement," + t; - if (e instanceof HTMLElement && b.has(r)) - return b.get(r); - let n = e.nodeName + "," + t; - if (b.has(n)) - return b.get(n); +function W(e, t) { + let n = "HTMLElement," + t; + if (e instanceof HTMLElement && x.has(n)) + return x.get(n); + let r = e.nodeName + "," + t; + if (x.has(r)) + return x.get(r); let [o, a, i] = H(e, t), s = !m(o.set); - return (!s || a) && b.set(i === HTMLElement.prototype ? r : n, s), s; + return (!s || a) && x.set(i === HTMLElement.prototype ? n : r, s), s; } -function H(e, t, r = 0) { +function H(e, t, n = 0) { if (e = Object.getPrototypeOf(e), !e) - return [{}, r, e]; - let n = Object.getOwnPropertyDescriptor(e, t); - return n ? [n, r, e] : H(e, t, r + 1); + return [{}, n, e]; + let r = Object.getOwnPropertyDescriptor(e, t); + return r ? [r, n, e] : H(e, t, n + 1); } function O(e, t) { - return Object.entries(e).forEach(([r, n]) => t(r, n)); + return Object.entries(e).forEach(([n, r]) => n && t(n, r)); } -function M(e, t, r, n) { - return e[(m(n) ? "remove" : "set") + t](r, n); +function T(e, t, n, r) { + return e[(m(r) ? "remove" : "set") + t](n, r); } -function W(e, t, r, n, o = null) { - return e[(m(n) ? "remove" : "set") + t + "NS"](o, r, n); +function I(e, t, n, r, o = null) { + return e[(m(r) ? "remove" : "set") + t + "NS"](o, n, r); +} +function M(e, t, n) { + if (Reflect.set(e, t, n), !!m(n)) + return Reflect.deleteProperty(e, t); } // src/events.js -function ae(e, t, ...r) { - let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t); - return e.dispatchEvent(n); +function de(e, t, ...n) { + let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); + return e.dispatchEvent(r); } -function k(e, t, r) { +function F(e, t, n) { return function(o) { - return o.addEventListener(e, t, r), o; + return o.addEventListener(e, t, n), o; }; } -var C = I(); -k.connected = function(e, t) { - return function(n) { - return typeof n.connectedCallback == "function" ? (n.addEventListener("dde:connected", e, t), n) : (j(t && t.signal, () => C.offConnected(n, e)) && (n.isConnected ? e(new Event("dde:connected")) : C.onConnected(n, e)), n); +var C = Z(); +F.connected = function(e, t) { + return function(r) { + return typeof r.connectedCallback == "function" ? (r.addEventListener("dde:connected", e, t), r) : (D(t && t.signal, () => C.offConnected(r, e)) && (r.isConnected ? e(new Event("dde:connected")) : C.onConnected(r, e)), r); }; }; -k.disconnected = function(e, t) { - return function(n) { - return typeof n.disconnectedCallback == "function" ? (n.addEventListener("dde:disconnected", e, t), n) : (j(t && t.signal, () => C.offDisconnected(n, e)) && C.onDisconnected(n, e), n); +F.disconnected = function(e, t) { + return function(r) { + return typeof r.disconnectedCallback == "function" ? (r.addEventListener("dde:disconnected", e, t), r) : (D(t && t.signal, () => C.offDisconnected(r, e)) && C.onDisconnected(r, e), r); }; }; -function I() { - let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(c) { +function Z() { + let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) { for (let f of c) if (f.type === "childList") { if (E(f.addedNodes, !0)) { @@ -183,7 +187,7 @@ function I() { if (!e.has(c)) return; let u = e.get(c), p = u.connected; - p.splice(p.indexOf(f), 1), n(c, u); + p.splice(p.indexOf(f), 1), r(c, u); }, onDisconnected(c, f) { a(), o(c).disconnected.push(f); @@ -192,10 +196,10 @@ function I() { if (!e.has(c)) return; let u = e.get(c), p = u.disconnected; - p.splice(p.indexOf(f), 1), n(c, u); + p.splice(p.indexOf(f), 1), r(c, u); } }; - function n(c, f) { + function r(c, f) { f.connected.length || f.disconnected.length || (e.delete(c), i()); } function o(c) { @@ -205,10 +209,10 @@ function I() { return e.set(c, f), f; } function a() { - t || (t = !0, r.observe(document.body, { childList: !0, subtree: !0 })); + t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 })); } function i() { - !t || e.size || (t = !1, r.disconnect()); + !t || e.size || (t = !1, n.disconnect()); } function s() { return new Promise(function(c) { @@ -229,7 +233,7 @@ function I() { if (f && h(u).then(E), !e.has(u)) continue; let p = e.get(u); - return p.connected.forEach((A) => A(u)), p.connected.length = 0, p.disconnected.length || e.delete(u), !0; + return p.connected.forEach((L) => L(u)), p.connected.length = 0, p.disconnected.length || e.delete(u), !0; } return !1; } @@ -238,7 +242,7 @@ function I() { if (f && h(u).then(v), !e.has(u)) continue; let p = e.get(u); - return p.disconnected.forEach((A) => A(u)), p.connected.length = 0, p.disconnected.length = 0, e.delete(u), !0; + return p.disconnected.forEach((L) => L(u)), p.connected.length = 0, p.disconnected.length = 0, e.delete(u), !0; } return !1; } @@ -247,14 +251,14 @@ function I() { // index.js [HTMLElement, DocumentFragment].forEach((e) => { let { append: t } = e.prototype; - e.prototype.append = function(...r) { - return t.apply(this, r), this; + e.prototype.append = function(...n) { + return t.apply(this, n), this; }; }); // src/signals-lib.js var d = Symbol.for("Signal"); -function L(e) { +function R(e) { try { return Reflect.has(e, d); } catch { @@ -264,26 +268,26 @@ function L(e) { var l = /* @__PURE__ */ new WeakMap(); function g(e, t) { if (typeof e != "function") - return F(e, t); - if (L(e)) + return z(e, t); + if (R(e)) return e; - let r = F(""), n = () => r(e()); - return l.set(n, /* @__PURE__ */ new Set([r])), G(n), r; + let n = z(""), r = () => n(e()); + return l.set(r, /* @__PURE__ */ new Set([n])), V(r), n; } -g.action = function(e, t, ...r) { - let n = e[d], { actions: o } = n; +g.action = function(e, t, ...n) { + let r = e[d], { actions: o } = r; if (!o || !Reflect.has(o, t)) throw new Error(`'${e}' has no action with name '${t}'!`); - if (o[t].apply(n, r), n.skip) - return Reflect.deleteProperty(n, "skip"); - n.listeners.forEach((a) => a(n.value)); + if (o[t].apply(r, n), r.skip) + return Reflect.deleteProperty(r, "skip"); + r.listeners.forEach((a) => a(r.value)); }; -g.on = function e(t, r, n = {}) { - let { signal: o } = n; +g.on = function e(t, n, r = {}) { + let { signal: o } = r; if (!(o && o.aborted)) { if (Array.isArray(t)) - return t.forEach((a) => e(a, r, n)); - P(t, r), o && o.addEventListener("abort", () => U(t, r)); + return t.forEach((a) => e(a, n, r)); + P(t, n), o && o.addEventListener("abort", () => $(t, n)); } }; g.symbols = { @@ -291,106 +295,106 @@ g.symbols = { onclear: Symbol.for("Signal.onclear") }; g.clear = function(...e) { - for (let r of e) { - Reflect.deleteProperty(r, "toJSON"); - let n = r[d], { onclear: o } = g.symbols; - n.actions && n.actions[o] && n.actions[o].call(n), t(r, n), Reflect.deleteProperty(r, d); + for (let n of e) { + Reflect.deleteProperty(n, "toJSON"); + let r = n[d], { onclear: o } = g.symbols; + r.actions && r.actions[o] && r.actions[o].call(r), t(n, r), Reflect.deleteProperty(n, d); } - function t(r, n) { - n.listeners.forEach((o) => { - if (n.listeners.delete(o), !l.has(o)) + function t(n, r) { + r.listeners.forEach((o) => { + if (r.listeners.delete(o), !l.has(o)) return; let a = l.get(o); - a.delete(r), !(a.size > 1) && (g.clear(...a), l.delete(o)); + a.delete(n), !(a.size > 1) && (g.clear(...a), l.delete(o)); }); } }; g.el = function(e, t) { - let r = document.createComment("<#reactive>"), n = document.createComment(""), o = document.createDocumentFragment(); - o.append(r, n); + let n = document.createComment("<#reactive>"), r = document.createComment(""), o = document.createDocumentFragment(); + o.append(n, r); let a = (i) => { - if (!r.parentNode || !n.parentNode) - return U(e, a); + if (!n.parentNode || !r.parentNode) + return $(e, a); let s = t(i); Array.isArray(s) || (s = [s]); - let h = r; - for (; (h = r.nextSibling) !== n; ) + let h = n; + for (; (h = n.nextSibling) !== r; ) h.remove(); - r.after(...s); + n.after(...s); }; return P(e, a), a(e()), o; }; -var z = { +var U = { isTextContent(e) { - return w(e) === "string" || L(e) && w(X(e)) === "string"; + return w(e) === "string" || R(e) && w(Y(e)) === "string"; }, - processReactiveAttribute(e, t, r, n) { - return L(r) ? (P(r, (o) => n([t, o])), r()) : r; + processReactiveAttribute(e, t, n, r) { + return R(n) ? (P(n, (o) => r([t, o])), n()) : n; } }; -function F(e, t) { - let r = (...n) => n.length ? Q(r, n[0]) : K(r); - return B(r, e, t); +function z(e, t) { + let n = (...r) => r.length ? X(n, r[0]) : Q(n); + return G(n, e, t); } -var Z = Object.assign(/* @__PURE__ */ Object.create(null), { +var B = Object.assign(/* @__PURE__ */ Object.create(null), { stopPropagation() { this.skip = !0; } }); -function B(e, t, r) { - return w(r) !== "[object Object]" && (r = {}), e[d] = { +function G(e, t, n) { + return w(n) !== "[object Object]" && (n = {}), e[d] = { value: t, - actions: r, + actions: n, listeners: /* @__PURE__ */ new Set() - }, e.toJSON = () => e(), Object.setPrototypeOf(e[d], Z), e; + }, e.toJSON = () => e(), Object.setPrototypeOf(e[d], B), e; } -var R = []; -function G(e) { +var A = []; +function V(e) { let t = function() { - R.push(t), e(), R.pop(); + A.push(t), e(), A.pop(); }; l.has(e) && (l.set(t, l.get(e)), l.delete(e)), t(); } -function V() { - return R[R.length - 1]; +function K() { + return A[A.length - 1]; } -function K(e) { +function Q(e) { if (!e[d]) return; - let { value: t, listeners: r } = e[d], n = V(); - return n && r.add(n), l.has(n) && l.get(n).add(e), t; + let { value: t, listeners: n } = e[d], r = K(); + return r && n.add(r), l.has(r) && l.get(r).add(e), t; } -function Q(e, t) { +function X(e, t) { if (!e[d]) return; - let r = e[d]; - if (r.value !== t) - return r.value = t, r.listeners.forEach((n) => n(t)), t; + let n = e[d]; + if (n.value !== t) + return n.value = t, n.listeners.forEach((r) => r(t)), t; } -function X(e) { +function Y(e) { return e[d].value; } function P(e, t) { if (e[d]) return e[d].listeners.add(t); } -function U(e, t) { +function $(e, t) { if (e[d]) return e[d].listeners.delete(t); } // signals.js -_(z); +_(U); export { g as S, y as assign, - q as classListDeclarative, - ce as createElement, - ae as dispatchEvent, - ce as el, - se as empty, - L as isSignal, - oe as namespace, - k as on, + J as classListDeclarative, + ie as createElement, + de as dispatchEvent, + ie as el, + fe as empty, + R as isSignal, + ce as namespace, + F as on, _ as registerReactivity }; diff --git a/dist/esm.js b/dist/esm.js index 0857c02..3384678 100644 --- a/dist/esm.js +++ b/dist/esm.js @@ -7,7 +7,7 @@ var g = { return r; } }; -function T(e, t = !0) { +function _(e, t = !0) { return t ? Object.assign(g, e) : (Object.setPrototypeOf(e, g), e); } function O(e) { @@ -28,21 +28,21 @@ function L(e, t) { } // src/dom-common.js -var h = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')), A = { setDelete: R }; -function R(e, t, r) { +var l = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')), A = { setDeleteAttr: T }; +function T(e, t, r) { Reflect.set(e, t, r), p(r) && e.getAttribute(t) === "undefined" && e.removeAttribute(t); } // src/dom.js var v = "html"; -function I(e) { +function Z(e) { return v = e === "svg" ? "http://www.w3.org/2000/svg" : e, { append(...t) { return v = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t); } }; } -function Z(e, t, ...r) { +function $(e, t, ...r) { let n = O(this), c; switch (n.isTextContent(t) && (t = { textContent: t }), !0) { case typeof e == "function": { @@ -50,31 +50,31 @@ function Z(e, t, ...r) { break; } case e === "#text": - c = E(document.createTextNode(""), t); + c = b(document.createTextNode(""), t); break; case e === "<>": - c = E(document.createDocumentFragment(), t); + c = b(document.createDocumentFragment(), t); break; case v !== "html": - c = E(document.createElementNS(v, e), t); + c = b(document.createElementNS(v, e), t); break; case !c: - c = E(document.createElement(e), t); + c = b(document.createElement(e), t); } return r.forEach((a) => a(c)), c; } -var { setDelete: y } = A; -function E(e, ...t) { +var { setDeleteAttr: M } = A; +function b(e, ...t) { let r = O(this); if (!t.length) return e; - let n = e instanceof SVGElement, c = (n ? S : N).bind(null, e, "Attribute"); + let n = e instanceof SVGElement, c = (n ? j : N).bind(null, e, "Attribute"); return Object.entries(Object.assign({}, ...t)).forEach(function a([s, f]) { f = r.processReactiveAttribute(e, s, f, a); - let [l] = s; - if (l === "=") + let [h] = s; + if (h === "=") return c(s.slice(1), f); - if (l === ".") + if (h === ".") return y(e, s.slice(1), f); if (typeof f == "object") switch (s) { @@ -83,9 +83,9 @@ function E(e, ...t) { case "dataset": return m(f, y.bind(null, e.dataset)); case "ariaset": - return m(f, (x, b) => c("aria-" + x, b)); + return m(f, (x, E) => c("aria-" + x, E)); case "classList": - return j(e, f); + return P(e, f); default: return Reflect.set(e, s, f); } @@ -101,27 +101,27 @@ function E(e, ...t) { break; return e.appendChild(document.createTextNode(f)); } - return M(e, s) ? y(e, s, f) : c(s, f); + return S(e, s) ? M(e, s, f) : c(s, f); }), e; } -function j(e, t) { +function P(e, t) { return typeof t != "object" || m( t, (r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n) ), e; } -function B(e) { +function G(e) { return Array.from(e.children).forEach((t) => t.remove()), e; } -function M(e, t) { +function S(e, t) { let r = "HTMLElement," + t; - if (e instanceof HTMLElement && h.has(r)) - return h.get(r); + if (e instanceof HTMLElement && l.has(r)) + return l.get(r); let n = e.nodeName + "," + t; - if (h.has(n)) - return h.get(n); + if (l.has(n)) + return l.get(n); let [c, a, s] = D(e, t), f = !p(c.set); - return (!f || a) && h.set(s === HTMLElement.prototype ? r : n, f), f; + return (!f || a) && l.set(s === HTMLElement.prototype ? r : n, f), f; } function D(e, t, r = 0) { if (e = Object.getPrototypeOf(e), !e) @@ -130,37 +130,41 @@ function D(e, t, r = 0) { return n ? [n, r, e] : D(e, t, r + 1); } function m(e, t) { - return Object.entries(e).forEach(([r, n]) => t(r, n)); + return Object.entries(e).forEach(([r, n]) => r && t(r, n)); } function N(e, t, r, n) { return e[(p(n) ? "remove" : "set") + t](r, n); } -function S(e, t, r, n, c = null) { +function j(e, t, r, n, c = null) { return e[(p(n) ? "remove" : "set") + t + "NS"](c, r, n); } +function y(e, t, r) { + if (Reflect.set(e, t, r), !!p(r)) + return Reflect.deleteProperty(e, t); +} // src/events.js -function V(e, t, ...r) { +function W(e, t, ...r) { let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t); return e.dispatchEvent(n); } -function _(e, t, r) { +function R(e, t, r) { return function(c) { return c.addEventListener(e, t, r), c; }; } -var w = P(); -_.connected = function(e, t) { +var w = H(); +R.connected = function(e, t) { return function(n) { return typeof n.connectedCallback == "function" ? (n.addEventListener("dde:connected", e, t), n) : (L(t && t.signal, () => w.offConnected(n, e)) && (n.isConnected ? e(new Event("dde:connected")) : w.onConnected(n, e)), n); }; }; -_.disconnected = function(e, t) { +R.disconnected = function(e, t) { return function(n) { return typeof n.disconnectedCallback == "function" ? (n.addEventListener("dde:disconnected", e, t), n) : (L(t && t.signal, () => w.offDisconnected(n, e)) && w.onDisconnected(n, e), n); }; }; -function P() { +function H() { let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(o) { for (let i of o) if (i.type === "childList") { @@ -168,7 +172,7 @@ function P() { s(); continue; } - b(i.removedNodes, !0) && s(); + E(i.removedNodes, !0) && s(); } }); return { @@ -211,7 +215,7 @@ function P() { (requestIdleCallback || requestAnimationFrame)(o); }); } - async function l(o) { + async function h(o) { e.size > 30 && await f(); let i = []; if (!(o instanceof Node)) @@ -222,16 +226,16 @@ function P() { } function x(o, i) { for (let u of o) { - if (i && l(u).then(x), !e.has(u)) + if (i && h(u).then(x), !e.has(u)) continue; let d = e.get(u); return d.connected.forEach((C) => C(u)), d.connected.length = 0, d.disconnected.length || e.delete(u), !0; } return !1; } - function b(o, i) { + function E(o, i) { for (let u of o) { - if (i && l(u).then(b), !e.has(u)) + if (i && h(u).then(E), !e.has(u)) continue; let d = e.get(u); return d.disconnected.forEach((C) => C(u)), d.connected.length = 0, d.disconnected.length = 0, e.delete(u), !0; @@ -248,13 +252,13 @@ function P() { }; }); export { - E as assign, - j as classListDeclarative, - Z as createElement, - V as dispatchEvent, - Z as el, - B as empty, - I as namespace, - _ as on, - T as registerReactivity + b as assign, + P as classListDeclarative, + $ as createElement, + W as dispatchEvent, + $ as el, + G as empty, + Z as namespace, + R as on, + _ as registerReactivity }; diff --git a/jsdom.js b/jsdom.js index 4128fe0..f1ec7fb 100644 --- a/jsdom.js +++ b/jsdom.js @@ -1,9 +1,9 @@ //TODO: https://www.npmjs.com/package/html-element import { prop_process } from './src/dom-common.js'; -const { setDelete }= prop_process; +const { setDeleteAttr }= prop_process; /** @param {HTMLElement} obj */ -prop_process.setDelete= function(obj, prop, value){ - if("checked"!==prop) return setDelete(obj, prop, value); +prop_process.setDeleteAttr= function(obj, prop, value){ + if("checked"!==prop) return setDeleteAttr(obj, prop, value); if(value) return obj.setAttribute("checked", ""); obj.removeAttribute("checked"); }; diff --git a/package.json b/package.json index 91a508f..3b8fdc2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "deka-dom-el", - "version": "0.2.1", + "version": "0.2.2", "description": "A low-code library that simplifies the creation of native DOM elements/components using small wrappers and tweaks.", "author": "Jan Andrle ", "license": "MIT", diff --git a/src/dom-common.js b/src/dom-common.js index 94c1af5..1d63203 100644 --- a/src/dom-common.js +++ b/src/dom-common.js @@ -1,8 +1,8 @@ /** @type {Map} */ export const prop_cache= new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')); -export const prop_process= { setDelete }; +export const prop_process= { setDeleteAttr }; import { isUndef } from './helpers.js'; -function setDelete(obj, prop, val){ +function setDeleteAttr(obj, prop, val){ /* Issue For some native attrs you can unset only to set empty string. This can be confusing as it is seen in inspector `<… id=""`. diff --git a/src/dom.js b/src/dom.js index 4e4eee2..cd78d1f 100644 --- a/src/dom.js +++ b/src/dom.js @@ -36,7 +36,7 @@ export function createElement(tag, attributes, ...connect){ export { createElement as el }; import { prop_cache, prop_process } from './dom-common.js'; -const { setDelete }= prop_process; +const { setDeleteAttr }= prop_process; export function assign(element, ...attributes){ const s= signals(this); if(!attributes.length) return element; @@ -71,7 +71,7 @@ export function assign(element, ...attributes){ if(!is_svg) break; return element.appendChild(document.createTextNode(attr)); } - return isPropSetter(element, key) ? setDelete(element, key, attr) : setRemoveAttr(key, attr); + return isPropSetter(element, key) ? setDeleteAttr(element, key, attr) : setRemoveAttr(key, attr); }); return element; } @@ -109,7 +109,8 @@ function getPropDescriptor(p, key, level= 0){ } /** @template {Record} T @param {T} obj @param {(param: [ keyof T, T[keyof T] ])=> void} cb */ -function forEachEntries(obj, cb){ return Object.entries(obj).forEach(([ key, val ])=> cb(key, val)); } +function forEachEntries(obj, cb){ return Object.entries(obj).forEach(([ key, val ])=> key && cb(key, val)); } function setRemove(obj, prop, key, val){ return obj[ (isUndef(val) ? "remove" : "set") + prop ](key, val); } function setRemoveNS(obj, prop, key, val, ns= null){ return obj[ (isUndef(val) ? "remove" : "set") + prop + "NS" ](ns, key, val); } +function setDelete(obj, key, val){ Reflect.set(obj, key, val); if(!isUndef(val)) return; return Reflect.deleteProperty(obj, key); }