From e3c2786a7228533df80a2d2a105a172e95ea57b9 Mon Sep 17 00:00:00 2001 From: Jan Andrle Date: Thu, 21 Sep 2023 16:27:00 +0200 Subject: [PATCH] :package: --- dist/dde-with-signals.js | 151 +++++++++++++++++----------------- dist/dde.js | 171 +++++++++++++++++++-------------------- dist/esm-with-signals.js | 151 +++++++++++++++++----------------- dist/esm.js | 171 +++++++++++++++++++-------------------- 4 files changed, 308 insertions(+), 336 deletions(-) diff --git a/dist/dde-with-signals.js b/dist/dde-with-signals.js index 91e639a..7e4636d 100644 --- a/dist/dde-with-signals.js +++ b/dist/dde-with-signals.js @@ -1,7 +1,7 @@ //deka-dom-el library is available via global namespace `dde` (()=> { // src/signals-common.js - var x = { + var E = { isSignal(e) { return !1; }, @@ -10,10 +10,10 @@ } }; function C(e, t = !0) { - return t ? Object.assign(x, e) : (Object.setPrototypeOf(e, x), e); + return t ? Object.assign(E, e) : (Object.setPrototypeOf(e, E), e); } - function v(e) { - return x.isPrototypeOf(e) && e !== x ? e : x; + function x(e) { + return E.isPrototypeOf(e) && e !== E ? e : E; } // src/helpers.js @@ -37,7 +37,7 @@ var P = { setDeleteAttr: W }; function W(e, t, n) { if (Reflect.set(e, t, n), !!m(n)) { - if (e instanceof HTMLElement && e.getAttribute(t) === "undefined") + if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined") return e.removeAttribute(t); if (Reflect.get(e, t) === "undefined") return Reflect.set(e, t, ""); @@ -45,78 +45,71 @@ } // src/dom.js - var S = "html"; + var w = "html"; function oe(e) { - return S = e === "svg" ? "http://www.w3.org/2000/svg" : e, { + return w = e === "svg" ? "http://www.w3.org/2000/svg" : e, { append(...t) { - return S = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t); + return w = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t); } }; } function ce(e, t, ...n) { - let r = v(this), o; + let r = x(this), o; switch ((Object(t) !== t || r.isSignal(t)) && (t = { textContent: t }), !0) { case typeof e == "function": { o = e(t || void 0, (p) => p ? (n.unshift(p), void 0) : o); break; } case e === "#text": - o = w(document.createTextNode(""), t); + o = S(document.createTextNode(""), t); break; case e === "<>": - o = w(document.createDocumentFragment(), t); + o = S(document.createDocumentFragment(), t); break; - case S !== "html": - o = w(document.createElementNS(S, e), t); + case w !== "html": + o = S(document.createElementNS(w, e), t); break; case !o: - o = w(document.createElement(e), t); + o = S(document.createElement(e), t); } return n.forEach((i) => i(o)), o; } var { setDeleteAttr: j } = P; - function w(e, ...t) { - let n = this, r = v(this); + function S(e, ...t) { + let n = this, r = x(this); if (!t.length) return e; - let o = e instanceof SVGElement, i = (o ? J : I).bind(null, e, "Attribute"); + let i = (e instanceof SVGElement ? I : H).bind(null, e, "Attribute"); 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(f.slice(1), a); if (b === ".") - return T(e, f.slice(1), a); + return F(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( - f, - a, - /* this applies only to SVG elements, see setRemove/setRemoveNS */ - "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, f, a); + return j(e, f, a); case "style": + if (typeof a != "object") + break; case "dataset": - return N(r, a, T.bind(null, e[f])); + return D(r, a, F.bind(null, e[f])); case "ariaset": - return N(r, a, (E, c) => i("aria-" + E, c)); + return D(r, a, (v, c) => i("aria-" + v, c)); case "classList": return B.call(n, e, a); } - return H(e, f) ? j(e, f, a) : i(f, a); + return G(e, f) ? j(e, f, a) : i(f, a); }), e; } function B(e, t) { - let n = v(this); - return N( + let n = x(this); + return D( n, t, (r, o) => e.classList.toggle(r, o === -1 ? void 0 : !!o) @@ -125,34 +118,34 @@ function se(e) { return Array.from(e.children).forEach((t) => t.remove()), e; } - function H(e, t) { + function G(e, t) { if (!Reflect.has(e, t)) return !1; - let n = F(e, t); + let n = M(e, t); return !m(n.set); } - function F(e, t, n = 0) { + function M(e, t) { if (e = Object.getPrototypeOf(e), !e) return {}; - let r = Object.getOwnPropertyDescriptor(e, t); - return r || F(e, t, n + 1); + let n = Object.getOwnPropertyDescriptor(e, t); + return n || M(e, t); } - function N(e, t, n) { - if (typeof t == "object") + function D(e, t, n) { + if (!(typeof t != "object" || t === null)) 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 z(e) { return Array.isArray(e) ? e.filter(Boolean).join(" ") : e; } - function I(e, t, n, r) { - return e[(m(r) ? "remove" : "set") + t](n, M(r)); + function H(e, t, n, r) { + return e[(m(r) ? "remove" : "set") + t](n, z(r)); } - function J(e, t, n, r, o = null) { - return e[(m(r) ? "remove" : "set") + t + "NS"](o, n, M(r)); + function I(e, t, n, r, o = null) { + return e[(m(r) ? "remove" : "set") + t + "NS"](o, n, z(r)); } - function T(e, t, n) { + function F(e, t, n) { if (Reflect.set(e, t, n), !!m(n)) return Reflect.deleteProperty(e, t); } @@ -162,23 +155,23 @@ let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); return e.dispatchEvent(r); } - function z(e, t, n) { + function T(e, t, n) { return function(o) { return o.addEventListener(e, t, n), o; }; } - var O = Z(); - z.connected = function(e, t) { + var O = J(); + T.connected = function(e, t) { return function(r) { return typeof r.connectedCallback == "function" ? (r.addEventListener("dde:connected", e, t), r) : (L(t && t.signal, () => O.offConnected(r, e)) && (r.isConnected ? e(new Event("dde:connected")) : O.onConnected(r, e)), r); }; }; - z.disconnected = function(e, t) { + T.disconnected = function(e, t) { return function(r) { return typeof r.disconnectedCallback == "function" ? (r.addEventListener("dde:disconnected", e, t), r) : (L(t && t.signal, () => O.offDisconnected(r, e)) && O.onDisconnected(r, e), r); }; }; - function Z() { + function J() { let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) { for (let s of c) if (s.type === "childList") { @@ -186,7 +179,7 @@ p(); continue; } - E(s.removedNodes, !0) && p(); + v(s.removedNodes, !0) && p(); } }); return { @@ -243,23 +236,23 @@ 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 l.connected.forEach((A) => A(u)), l.connected.length = 0, l.disconnected.length || e.delete(u), !0; } return !1; } - function E(c, s) { + function v(c, s) { for (let u of c) { - if (s && a(u).then(E), !e.has(u)) + if (s && a(u).then(v), !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; + return l.disconnected.forEach((A) => A(u)), l.connected.length = 0, l.disconnected.length = 0, e.delete(u), !0; } return !1; } } // index.js - [HTMLElement, DocumentFragment].forEach((e) => { + [HTMLElement, SVGElement, DocumentFragment].forEach((e) => { let { append: t } = e.prototype; e.prototype.append = function(...n) { return t.apply(this, n), this; @@ -268,7 +261,7 @@ // src/signals-lib.js var d = Symbol.for("Signal"); - function A(e) { + function y(e) { try { return Reflect.has(e, d); } catch { @@ -279,10 +272,10 @@ function g(e, t) { if (typeof e != "function") return U(e, t); - if (A(e)) + if (y(e)) return e; let n = U(""), r = () => n(e()); - return h.set(r, /* @__PURE__ */ new Set([n])), K(r), n; + return h.set(r, /* @__PURE__ */ new Set([n])), k(r), n; } g.action = function(e, t, ...n) { let r = e[d], { actions: o } = r; @@ -297,7 +290,7 @@ if (!(o && o.aborted)) { if (Array.isArray(t)) return t.forEach((i) => e(i, n, r)); - D(t, n), o && o.addEventListener("abort", () => q(t, n)); + N(t, n), o && o.addEventListener("abort", () => q(t, n)); } }; g.symbols = { @@ -332,54 +325,54 @@ a.remove(); n.after(...f); }; - return D(e, i), i(e()), o; + return N(e, i), i(e()), o; }; var $ = { - isSignal: A, + isSignal: y, processReactiveAttribute(e, t, n, r) { - return A(n) ? (D(n, (o) => r([t, o])), n()) : n; + return y(n) ? (N(n, (o) => r([t, o])), n()) : n; } }; function U(e, t) { - let n = (...r) => r.length ? Y(n, r[0]) : X(n); - return V(n, e, t); + let n = (...r) => r.length ? X(n, r[0]) : Q(n); + return Z(n, e, t); } - var G = Object.assign(/* @__PURE__ */ Object.create(null), { + var V = Object.assign(/* @__PURE__ */ Object.create(null), { stopPropagation() { this.skip = !0; } }); - function V(e, t, n) { + function Z(e, t, n) { return _(n) !== "[object Object]" && (n = {}), e[d] = { value: t, actions: n, listeners: /* @__PURE__ */ new Set() - }, e.toJSON = () => e(), Object.setPrototypeOf(e[d], G), e; + }, e.toJSON = () => e(), Object.setPrototypeOf(e[d], V), e; } var R = []; - function K(e) { + function k(e) { let t = function() { R.push(t), e(), R.pop(); }; h.has(e) && (h.set(t, h.get(e)), h.delete(e)), t(); } - function Q() { + function K() { return R[R.length - 1]; } - function X(e) { + function Q(e) { if (!e[d]) return; - let { value: t, listeners: n } = e[d], r = Q(); + let { value: t, listeners: n } = e[d], r = K(); return r && n.add(r), h.has(r) && h.get(r).add(e), t; } - function Y(e, t) { + function X(e, t) { if (!e[d]) return; let n = e[d]; if (n.value !== t) return n.value = t, n.listeners.forEach((r) => r(t)), t; } - function D(e, t) { + function N(e, t) { if (e[d]) return e[d].listeners.add(t); } @@ -393,15 +386,15 @@ globalThis.dde= { S: g, - assign: w, + assign: S, classListDeclarative: B, createElement: ce, dispatchEvent: ae, el: ce, empty: se, - isSignal: A, + isSignal: y, namespace: oe, - on: z, + on: T, registerReactivity: C }; diff --git a/dist/dde.js b/dist/dde.js index 3ebd9b5..784ceb6 100644 --- a/dist/dde.js +++ b/dist/dde.js @@ -5,11 +5,11 @@ isSignal(e) { return !1; }, - processReactiveAttribute(e, t, r, n) { - return r; + processReactiveAttribute(e, t, n, r) { + return n; } }; - function P(e, t = !0) { + function y(e, t = !0) { return t ? Object.assign(g, e) : (Object.setPrototypeOf(e, g), e); } function v(e) { @@ -30,10 +30,10 @@ } // src/dom-common.js - 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") + var R = { setDeleteAttr: P }; + function P(e, t, n) { + if (Reflect.set(e, t, n), !!p(n)) { + if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined") return e.removeAttribute(t); if (Reflect.get(e, t) === "undefined") return Reflect.set(e, t, ""); @@ -41,43 +41,43 @@ } // src/dom.js - var m = "html"; - function I(e) { - return m = e === "svg" ? "http://www.w3.org/2000/svg" : e, { + var x = "html"; + function H(e) { + return x = e === "svg" ? "http://www.w3.org/2000/svg" : e, { append(...t) { - return m = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t); + return x = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t); } }; } - function Z(e, t, ...r) { - let n = v(this), c; - switch ((Object(t) !== t || n.isSignal(t)) && (t = { textContent: t }), !0) { + function I(e, t, ...n) { + let r = v(this), c; + switch ((Object(t) !== t || r.isSignal(t)) && (t = { textContent: t }), !0) { case typeof e == "function": { - c = e(t || void 0, (l) => l ? (r.unshift(l), void 0) : c); + c = e(t || void 0, (l) => l ? (n.unshift(l), void 0) : c); break; } case e === "#text": - c = x(document.createTextNode(""), t); + c = m(document.createTextNode(""), t); break; case e === "<>": - c = x(document.createDocumentFragment(), t); + c = m(document.createDocumentFragment(), t); break; - case m !== "html": - c = x(document.createElementNS(m, e), t); + case x !== "html": + c = m(document.createElementNS(x, e), t); break; case !c: - c = x(document.createElement(e), t); + c = m(document.createElement(e), t); } - return r.forEach((d) => d(c)), c; + return n.forEach((d) => d(c)), c; } - var { setDeleteAttr: R } = C; - function x(e, ...t) { - let r = this, n = v(this); + var { setDeleteAttr: C } = R; + function m(e, ...t) { + let n = this, r = v(this); if (!t.length) return e; - let c = e instanceof SVGElement, d = (c ? F : j).bind(null, e, "Attribute"); + let d = (e instanceof SVGElement ? M : F).bind(null, e, "Attribute"); return Object.entries(Object.assign({}, ...t)).forEach(function l([f, u]) { - u = n.processReactiveAttribute(e, f, u, l); + u = r.processReactiveAttribute(e, f, u, l); let [h] = f; if (h === "=") return d(f.slice(1), u); @@ -86,96 +86,89 @@ 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) { - case "href": - case "src": - case "class": case "xlink:href": - return d( - f, - u, - /* this applies only to SVG elements, see setRemove/setRemoveNS */ - "http://www.w3.org/1999/xlink" - ); + return d(f, u, "http://www.w3.org/1999/xlink"); case "textContent": - case "innerText": - return c ? e.appendChild(document.createTextNode(u)) : R(e, f, u); + return C(e, f, u); case "style": + if (typeof u != "object") + break; case "dataset": - return O(n, u, D.bind(null, e[f])); + return O(r, u, D.bind(null, e[f])); case "ariaset": - return O(n, u, (E, o) => d("aria-" + E, o)); + return O(r, u, (E, o) => d("aria-" + E, o)); case "classList": - return _.call(r, e, u); + return _.call(n, e, u); } - return T(e, f) ? R(e, f, u) : d(f, u); + return j(e, f) ? C(e, f, u) : d(f, u); }), e; } function _(e, t) { - let r = v(this); + let n = v(this); return O( - r, + n, t, - (n, c) => e.classList.toggle(n, c === -1 ? void 0 : !!c) + (r, c) => e.classList.toggle(r, c === -1 ? void 0 : !!c) ), e; } - function G(e) { + function Z(e) { return Array.from(e.children).forEach((t) => t.remove()), e; } - function T(e, t) { + function j(e, t) { if (!Reflect.has(e, t)) return !1; - let r = L(e, t); - return !p(r.set); + let n = L(e, t); + return !p(n.set); } - function L(e, t, r = 0) { + function L(e, t) { if (e = Object.getPrototypeOf(e), !e) return {}; let n = Object.getOwnPropertyDescriptor(e, t); - return n || L(e, t, r + 1); + return n || L(e, t); } - function O(e, t, r) { - if (typeof t == "object") + function O(e, t, n) { + if (!(typeof t != "object" || t === null)) return Object.entries(t).forEach(function([c, d]) { - c && (d = e.processReactiveAttribute(t, c, d, (l) => r(...l)), r(c, d)); + c && (d = e.processReactiveAttribute(t, c, d, (l) => n(...l)), n(c, d)); }); } - function N(e) { + function S(e) { return Array.isArray(e) ? e.filter(Boolean).join(" ") : e; } - function j(e, t, r, n) { - return e[(p(n) ? "remove" : "set") + t](r, N(n)); + function F(e, t, n, r) { + return e[(p(r) ? "remove" : "set") + t](n, S(r)); } - function F(e, t, r, n, c = null) { - return e[(p(n) ? "remove" : "set") + t + "NS"](c, r, N(n)); + function M(e, t, n, r, c = null) { + return e[(p(r) ? "remove" : "set") + t + "NS"](c, n, S(r)); } - function D(e, t, r) { - if (Reflect.set(e, t, r), !!p(r)) + function D(e, t, n) { + if (Reflect.set(e, t, n), !!p(n)) return Reflect.deleteProperty(e, t); } // src/events.js - function J(e, t, ...r) { - let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t); - return e.dispatchEvent(n); + function J(e, t, ...n) { + let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); + return e.dispatchEvent(r); } - function S(e, t, r) { + function N(e, t, n) { return function(c) { - return c.addEventListener(e, t, r), c; + return c.addEventListener(e, t, n), c; }; } - 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, () => b.offConnected(n, e)) && (n.isConnected ? e(new Event("dde:connected")) : b.onConnected(n, e)), n); + var b = T(); + N.connected = function(e, t) { + return function(r) { + return typeof r.connectedCallback == "function" ? (r.addEventListener("dde:connected", e, t), r) : (w(t && t.signal, () => b.offConnected(r, e)) && (r.isConnected ? e(new Event("dde:connected")) : b.onConnected(r, e)), r); }; }; - S.disconnected = function(e, t) { - return function(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); + N.disconnected = function(e, t) { + return function(r) { + return typeof r.disconnectedCallback == "function" ? (r.addEventListener("dde:disconnected", e, t), r) : (w(t && t.signal, () => b.offDisconnected(r, e)) && b.onDisconnected(r, e), r); }; }; - function M() { - let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(o) { + function T() { + let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(o) { for (let s of o) if (s.type === "childList") { if (h(s.addedNodes, !0)) { @@ -193,7 +186,7 @@ if (!e.has(o)) return; let i = e.get(o), a = i.connected; - a.splice(a.indexOf(s), 1), n(o, i); + a.splice(a.indexOf(s), 1), r(o, i); }, onDisconnected(o, s) { d(), c(o).disconnected.push(s); @@ -202,10 +195,10 @@ if (!e.has(o)) return; let i = e.get(o), a = i.disconnected; - a.splice(a.indexOf(s), 1), n(o, i); + a.splice(a.indexOf(s), 1), r(o, i); } }; - function n(o, s) { + function r(o, s) { s.connected.length || s.disconnected.length || (e.delete(o), l()); } function c(o) { @@ -215,10 +208,10 @@ return e.set(o, s), s; } function d() { - t || (t = !0, r.observe(document.body, { childList: !0, subtree: !0 })); + t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 })); } function l() { - !t || e.size || (t = !1, r.disconnect()); + !t || e.size || (t = !1, n.disconnect()); } function f() { return new Promise(function(o) { @@ -255,23 +248,23 @@ } // index.js - [HTMLElement, DocumentFragment].forEach((e) => { + [HTMLElement, SVGElement, 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; }; }); globalThis.dde= { - assign: x, + assign: m, classListDeclarative: _, - createElement: Z, + createElement: I, dispatchEvent: J, - el: Z, - empty: G, - namespace: I, - on: S, - registerReactivity: P + el: I, + empty: Z, + namespace: H, + on: N, + registerReactivity: y }; })(); \ No newline at end of file diff --git a/dist/esm-with-signals.js b/dist/esm-with-signals.js index 5f98945..6df6e24 100644 --- a/dist/esm-with-signals.js +++ b/dist/esm-with-signals.js @@ -1,5 +1,5 @@ // src/signals-common.js -var x = { +var E = { isSignal(e) { return !1; }, @@ -8,10 +8,10 @@ var x = { } }; function C(e, t = !0) { - return t ? Object.assign(x, e) : (Object.setPrototypeOf(e, x), e); + return t ? Object.assign(E, e) : (Object.setPrototypeOf(e, E), e); } -function v(e) { - return x.isPrototypeOf(e) && e !== x ? e : x; +function x(e) { + return E.isPrototypeOf(e) && e !== E ? e : E; } // src/helpers.js @@ -35,7 +35,7 @@ function L(e, t) { var P = { setDeleteAttr: W }; function W(e, t, n) { if (Reflect.set(e, t, n), !!m(n)) { - if (e instanceof HTMLElement && e.getAttribute(t) === "undefined") + if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined") return e.removeAttribute(t); if (Reflect.get(e, t) === "undefined") return Reflect.set(e, t, ""); @@ -43,78 +43,71 @@ function W(e, t, n) { } // src/dom.js -var S = "html"; +var w = "html"; function oe(e) { - return S = e === "svg" ? "http://www.w3.org/2000/svg" : e, { + return w = e === "svg" ? "http://www.w3.org/2000/svg" : e, { append(...t) { - return S = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t); + return w = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t); } }; } function ce(e, t, ...n) { - let r = v(this), o; + let r = x(this), o; switch ((Object(t) !== t || r.isSignal(t)) && (t = { textContent: t }), !0) { case typeof e == "function": { o = e(t || void 0, (p) => p ? (n.unshift(p), void 0) : o); break; } case e === "#text": - o = w(document.createTextNode(""), t); + o = S(document.createTextNode(""), t); break; case e === "<>": - o = w(document.createDocumentFragment(), t); + o = S(document.createDocumentFragment(), t); break; - case S !== "html": - o = w(document.createElementNS(S, e), t); + case w !== "html": + o = S(document.createElementNS(w, e), t); break; case !o: - o = w(document.createElement(e), t); + o = S(document.createElement(e), t); } return n.forEach((i) => i(o)), o; } var { setDeleteAttr: j } = P; -function w(e, ...t) { - let n = this, r = v(this); +function S(e, ...t) { + let n = this, r = x(this); if (!t.length) return e; - let o = e instanceof SVGElement, i = (o ? J : I).bind(null, e, "Attribute"); + let i = (e instanceof SVGElement ? I : H).bind(null, e, "Attribute"); 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(f.slice(1), a); if (b === ".") - return T(e, f.slice(1), a); + return F(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( - f, - a, - /* this applies only to SVG elements, see setRemove/setRemoveNS */ - "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, f, a); + return j(e, f, a); case "style": + if (typeof a != "object") + break; case "dataset": - return N(r, a, T.bind(null, e[f])); + return D(r, a, F.bind(null, e[f])); case "ariaset": - return N(r, a, (E, c) => i("aria-" + E, c)); + return D(r, a, (v, c) => i("aria-" + v, c)); case "classList": return B.call(n, e, a); } - return H(e, f) ? j(e, f, a) : i(f, a); + return G(e, f) ? j(e, f, a) : i(f, a); }), e; } function B(e, t) { - let n = v(this); - return N( + let n = x(this); + return D( n, t, (r, o) => e.classList.toggle(r, o === -1 ? void 0 : !!o) @@ -123,34 +116,34 @@ function B(e, t) { function se(e) { return Array.from(e.children).forEach((t) => t.remove()), e; } -function H(e, t) { +function G(e, t) { if (!Reflect.has(e, t)) return !1; - let n = F(e, t); + let n = M(e, t); return !m(n.set); } -function F(e, t, n = 0) { +function M(e, t) { if (e = Object.getPrototypeOf(e), !e) return {}; - let r = Object.getOwnPropertyDescriptor(e, t); - return r || F(e, t, n + 1); + let n = Object.getOwnPropertyDescriptor(e, t); + return n || M(e, t); } -function N(e, t, n) { - if (typeof t == "object") +function D(e, t, n) { + if (!(typeof t != "object" || t === null)) 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 z(e) { return Array.isArray(e) ? e.filter(Boolean).join(" ") : e; } -function I(e, t, n, r) { - return e[(m(r) ? "remove" : "set") + t](n, M(r)); +function H(e, t, n, r) { + return e[(m(r) ? "remove" : "set") + t](n, z(r)); } -function J(e, t, n, r, o = null) { - return e[(m(r) ? "remove" : "set") + t + "NS"](o, n, M(r)); +function I(e, t, n, r, o = null) { + return e[(m(r) ? "remove" : "set") + t + "NS"](o, n, z(r)); } -function T(e, t, n) { +function F(e, t, n) { if (Reflect.set(e, t, n), !!m(n)) return Reflect.deleteProperty(e, t); } @@ -160,23 +153,23 @@ function ae(e, t, ...n) { let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); return e.dispatchEvent(r); } -function z(e, t, n) { +function T(e, t, n) { return function(o) { return o.addEventListener(e, t, n), o; }; } -var O = Z(); -z.connected = function(e, t) { +var O = J(); +T.connected = function(e, t) { return function(r) { return typeof r.connectedCallback == "function" ? (r.addEventListener("dde:connected", e, t), r) : (L(t && t.signal, () => O.offConnected(r, e)) && (r.isConnected ? e(new Event("dde:connected")) : O.onConnected(r, e)), r); }; }; -z.disconnected = function(e, t) { +T.disconnected = function(e, t) { return function(r) { return typeof r.disconnectedCallback == "function" ? (r.addEventListener("dde:disconnected", e, t), r) : (L(t && t.signal, () => O.offDisconnected(r, e)) && O.onDisconnected(r, e), r); }; }; -function Z() { +function J() { let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) { for (let s of c) if (s.type === "childList") { @@ -184,7 +177,7 @@ function Z() { p(); continue; } - E(s.removedNodes, !0) && p(); + v(s.removedNodes, !0) && p(); } }); return { @@ -241,23 +234,23 @@ function Z() { 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 l.connected.forEach((A) => A(u)), l.connected.length = 0, l.disconnected.length || e.delete(u), !0; } return !1; } - function E(c, s) { + function v(c, s) { for (let u of c) { - if (s && a(u).then(E), !e.has(u)) + if (s && a(u).then(v), !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; + return l.disconnected.forEach((A) => A(u)), l.connected.length = 0, l.disconnected.length = 0, e.delete(u), !0; } return !1; } } // index.js -[HTMLElement, DocumentFragment].forEach((e) => { +[HTMLElement, SVGElement, DocumentFragment].forEach((e) => { let { append: t } = e.prototype; e.prototype.append = function(...n) { return t.apply(this, n), this; @@ -266,7 +259,7 @@ function Z() { // src/signals-lib.js var d = Symbol.for("Signal"); -function A(e) { +function y(e) { try { return Reflect.has(e, d); } catch { @@ -277,10 +270,10 @@ var h = /* @__PURE__ */ new WeakMap(); function g(e, t) { if (typeof e != "function") return U(e, t); - if (A(e)) + if (y(e)) return e; let n = U(""), r = () => n(e()); - return h.set(r, /* @__PURE__ */ new Set([n])), K(r), n; + return h.set(r, /* @__PURE__ */ new Set([n])), k(r), n; } g.action = function(e, t, ...n) { let r = e[d], { actions: o } = r; @@ -295,7 +288,7 @@ g.on = function e(t, n, r = {}) { if (!(o && o.aborted)) { if (Array.isArray(t)) return t.forEach((i) => e(i, n, r)); - D(t, n), o && o.addEventListener("abort", () => q(t, n)); + N(t, n), o && o.addEventListener("abort", () => q(t, n)); } }; g.symbols = { @@ -330,54 +323,54 @@ g.el = function(e, t) { a.remove(); n.after(...f); }; - return D(e, i), i(e()), o; + return N(e, i), i(e()), o; }; var $ = { - isSignal: A, + isSignal: y, processReactiveAttribute(e, t, n, r) { - return A(n) ? (D(n, (o) => r([t, o])), n()) : n; + return y(n) ? (N(n, (o) => r([t, o])), n()) : n; } }; function U(e, t) { - let n = (...r) => r.length ? Y(n, r[0]) : X(n); - return V(n, e, t); + let n = (...r) => r.length ? X(n, r[0]) : Q(n); + return Z(n, e, t); } -var G = Object.assign(/* @__PURE__ */ Object.create(null), { +var V = Object.assign(/* @__PURE__ */ Object.create(null), { stopPropagation() { this.skip = !0; } }); -function V(e, t, n) { +function Z(e, t, n) { return _(n) !== "[object Object]" && (n = {}), e[d] = { value: t, actions: n, listeners: /* @__PURE__ */ new Set() - }, e.toJSON = () => e(), Object.setPrototypeOf(e[d], G), e; + }, e.toJSON = () => e(), Object.setPrototypeOf(e[d], V), e; } var R = []; -function K(e) { +function k(e) { let t = function() { R.push(t), e(), R.pop(); }; h.has(e) && (h.set(t, h.get(e)), h.delete(e)), t(); } -function Q() { +function K() { return R[R.length - 1]; } -function X(e) { +function Q(e) { if (!e[d]) return; - let { value: t, listeners: n } = e[d], r = Q(); + let { value: t, listeners: n } = e[d], r = K(); return r && n.add(r), h.has(r) && h.get(r).add(e), t; } -function Y(e, t) { +function X(e, t) { if (!e[d]) return; let n = e[d]; if (n.value !== t) return n.value = t, n.listeners.forEach((r) => r(t)), t; } -function D(e, t) { +function N(e, t) { if (e[d]) return e[d].listeners.add(t); } @@ -390,14 +383,14 @@ function q(e, t) { C($); export { g as S, - w as assign, + S as assign, B as classListDeclarative, ce as createElement, ae as dispatchEvent, ce as el, se as empty, - A as isSignal, + y as isSignal, oe as namespace, - z as on, + T as on, C as registerReactivity }; diff --git a/dist/esm.js b/dist/esm.js index f52d872..271a60e 100644 --- a/dist/esm.js +++ b/dist/esm.js @@ -3,11 +3,11 @@ var g = { isSignal(e) { return !1; }, - processReactiveAttribute(e, t, r, n) { - return r; + processReactiveAttribute(e, t, n, r) { + return n; } }; -function P(e, t = !0) { +function y(e, t = !0) { return t ? Object.assign(g, e) : (Object.setPrototypeOf(e, g), e); } function v(e) { @@ -28,10 +28,10 @@ function w(e, t) { } // src/dom-common.js -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") +var R = { setDeleteAttr: P }; +function P(e, t, n) { + if (Reflect.set(e, t, n), !!p(n)) { + if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined") return e.removeAttribute(t); if (Reflect.get(e, t) === "undefined") return Reflect.set(e, t, ""); @@ -39,43 +39,43 @@ function y(e, t, r) { } // src/dom.js -var m = "html"; -function I(e) { - return m = e === "svg" ? "http://www.w3.org/2000/svg" : e, { +var x = "html"; +function H(e) { + return x = e === "svg" ? "http://www.w3.org/2000/svg" : e, { append(...t) { - return m = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t); + return x = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t); } }; } -function Z(e, t, ...r) { - let n = v(this), c; - switch ((Object(t) !== t || n.isSignal(t)) && (t = { textContent: t }), !0) { +function I(e, t, ...n) { + let r = v(this), c; + switch ((Object(t) !== t || r.isSignal(t)) && (t = { textContent: t }), !0) { case typeof e == "function": { - c = e(t || void 0, (l) => l ? (r.unshift(l), void 0) : c); + c = e(t || void 0, (l) => l ? (n.unshift(l), void 0) : c); break; } case e === "#text": - c = x(document.createTextNode(""), t); + c = m(document.createTextNode(""), t); break; case e === "<>": - c = x(document.createDocumentFragment(), t); + c = m(document.createDocumentFragment(), t); break; - case m !== "html": - c = x(document.createElementNS(m, e), t); + case x !== "html": + c = m(document.createElementNS(x, e), t); break; case !c: - c = x(document.createElement(e), t); + c = m(document.createElement(e), t); } - return r.forEach((d) => d(c)), c; + return n.forEach((d) => d(c)), c; } -var { setDeleteAttr: R } = C; -function x(e, ...t) { - let r = this, n = v(this); +var { setDeleteAttr: C } = R; +function m(e, ...t) { + let n = this, r = v(this); if (!t.length) return e; - let c = e instanceof SVGElement, d = (c ? F : j).bind(null, e, "Attribute"); + let d = (e instanceof SVGElement ? M : F).bind(null, e, "Attribute"); return Object.entries(Object.assign({}, ...t)).forEach(function l([f, u]) { - u = n.processReactiveAttribute(e, f, u, l); + u = r.processReactiveAttribute(e, f, u, l); let [h] = f; if (h === "=") return d(f.slice(1), u); @@ -84,96 +84,89 @@ function x(e, ...t) { 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) { - case "href": - case "src": - case "class": case "xlink:href": - return d( - f, - u, - /* this applies only to SVG elements, see setRemove/setRemoveNS */ - "http://www.w3.org/1999/xlink" - ); + return d(f, u, "http://www.w3.org/1999/xlink"); case "textContent": - case "innerText": - return c ? e.appendChild(document.createTextNode(u)) : R(e, f, u); + return C(e, f, u); case "style": + if (typeof u != "object") + break; case "dataset": - return O(n, u, D.bind(null, e[f])); + return O(r, u, D.bind(null, e[f])); case "ariaset": - return O(n, u, (E, o) => d("aria-" + E, o)); + return O(r, u, (E, o) => d("aria-" + E, o)); case "classList": - return _.call(r, e, u); + return _.call(n, e, u); } - return T(e, f) ? R(e, f, u) : d(f, u); + return j(e, f) ? C(e, f, u) : d(f, u); }), e; } function _(e, t) { - let r = v(this); + let n = v(this); return O( - r, + n, t, - (n, c) => e.classList.toggle(n, c === -1 ? void 0 : !!c) + (r, c) => e.classList.toggle(r, c === -1 ? void 0 : !!c) ), e; } -function G(e) { +function Z(e) { return Array.from(e.children).forEach((t) => t.remove()), e; } -function T(e, t) { +function j(e, t) { if (!Reflect.has(e, t)) return !1; - let r = L(e, t); - return !p(r.set); + let n = L(e, t); + return !p(n.set); } -function L(e, t, r = 0) { +function L(e, t) { if (e = Object.getPrototypeOf(e), !e) return {}; let n = Object.getOwnPropertyDescriptor(e, t); - return n || L(e, t, r + 1); + return n || L(e, t); } -function O(e, t, r) { - if (typeof t == "object") +function O(e, t, n) { + if (!(typeof t != "object" || t === null)) return Object.entries(t).forEach(function([c, d]) { - c && (d = e.processReactiveAttribute(t, c, d, (l) => r(...l)), r(c, d)); + c && (d = e.processReactiveAttribute(t, c, d, (l) => n(...l)), n(c, d)); }); } -function N(e) { +function S(e) { return Array.isArray(e) ? e.filter(Boolean).join(" ") : e; } -function j(e, t, r, n) { - return e[(p(n) ? "remove" : "set") + t](r, N(n)); +function F(e, t, n, r) { + return e[(p(r) ? "remove" : "set") + t](n, S(r)); } -function F(e, t, r, n, c = null) { - return e[(p(n) ? "remove" : "set") + t + "NS"](c, r, N(n)); +function M(e, t, n, r, c = null) { + return e[(p(r) ? "remove" : "set") + t + "NS"](c, n, S(r)); } -function D(e, t, r) { - if (Reflect.set(e, t, r), !!p(r)) +function D(e, t, n) { + if (Reflect.set(e, t, n), !!p(n)) return Reflect.deleteProperty(e, t); } // src/events.js -function J(e, t, ...r) { - let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t); - return e.dispatchEvent(n); +function J(e, t, ...n) { + let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); + return e.dispatchEvent(r); } -function S(e, t, r) { +function N(e, t, n) { return function(c) { - return c.addEventListener(e, t, r), c; + return c.addEventListener(e, t, n), c; }; } -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, () => b.offConnected(n, e)) && (n.isConnected ? e(new Event("dde:connected")) : b.onConnected(n, e)), n); +var b = T(); +N.connected = function(e, t) { + return function(r) { + return typeof r.connectedCallback == "function" ? (r.addEventListener("dde:connected", e, t), r) : (w(t && t.signal, () => b.offConnected(r, e)) && (r.isConnected ? e(new Event("dde:connected")) : b.onConnected(r, e)), r); }; }; -S.disconnected = function(e, t) { - return function(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); +N.disconnected = function(e, t) { + return function(r) { + return typeof r.disconnectedCallback == "function" ? (r.addEventListener("dde:disconnected", e, t), r) : (w(t && t.signal, () => b.offDisconnected(r, e)) && b.onDisconnected(r, e), r); }; }; -function M() { - let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(o) { +function T() { + let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(o) { for (let s of o) if (s.type === "childList") { if (h(s.addedNodes, !0)) { @@ -191,7 +184,7 @@ function M() { if (!e.has(o)) return; let i = e.get(o), a = i.connected; - a.splice(a.indexOf(s), 1), n(o, i); + a.splice(a.indexOf(s), 1), r(o, i); }, onDisconnected(o, s) { d(), c(o).disconnected.push(s); @@ -200,10 +193,10 @@ function M() { if (!e.has(o)) return; let i = e.get(o), a = i.disconnected; - a.splice(a.indexOf(s), 1), n(o, i); + a.splice(a.indexOf(s), 1), r(o, i); } }; - function n(o, s) { + function r(o, s) { s.connected.length || s.disconnected.length || (e.delete(o), l()); } function c(o) { @@ -213,10 +206,10 @@ function M() { return e.set(o, s), s; } function d() { - t || (t = !0, r.observe(document.body, { childList: !0, subtree: !0 })); + t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 })); } function l() { - !t || e.size || (t = !1, r.disconnect()); + !t || e.size || (t = !1, n.disconnect()); } function f() { return new Promise(function(o) { @@ -253,20 +246,20 @@ function M() { } // index.js -[HTMLElement, DocumentFragment].forEach((e) => { +[HTMLElement, SVGElement, 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; }; }); export { - x as assign, + m as assign, _ as classListDeclarative, - Z as createElement, + I as createElement, J as dispatchEvent, - Z as el, - G as empty, - I as namespace, - S as on, - P as registerReactivity + I as el, + Z as empty, + H as namespace, + N as on, + y as registerReactivity };