1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2024-11-22 16:55:23 +01:00

🐛 Process primitives & signals correctly in createElement/assign

This commit is contained in:
Jan Andrle 2023-09-21 12:35:27 +02:00
parent 84bcac0ec9
commit cc69018d99
Signed by: jaandrle
GPG Key ID: B3A25AED155AFFAB
11 changed files with 610 additions and 613 deletions

View File

@ -1,30 +1,30 @@
//deka-dom-el library is available via global namespace `dde` //deka-dom-el library is available via global namespace `dde`
(()=> { (()=> {
// src/signals-common.js // src/signals-common.js
var b = { var x = {
isTextContent(e) { isSignal(e) {
return typeof e == "string"; return !1;
}, },
processReactiveAttribute(e, t, n, r) { processReactiveAttribute(e, t, n, r) {
return n; return n;
} }
}; };
function _(e, t = !0) { function C(e, t = !0) {
return t ? Object.assign(b, e) : (Object.setPrototypeOf(e, b), e); return t ? Object.assign(x, e) : (Object.setPrototypeOf(e, x), e);
} }
function N(e) { function v(e) {
return b.isPrototypeOf(e) && e !== b ? e : b; return x.isPrototypeOf(e) && e !== x ? e : x;
} }
// src/helpers.js // src/helpers.js
function m(e) { function m(e) {
return typeof e > "u"; return typeof e > "u";
} }
function w(e) { function _(e) {
let t = typeof e; let t = typeof e;
return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e); return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e);
} }
function D(e, t) { function L(e, t) {
if (!e || !(e instanceof AbortSignal)) if (!e || !(e instanceof AbortSignal))
return !0; return !0;
if (!e.aborted) if (!e.aborted)
@ -34,175 +34,177 @@
} }
// src/dom-common.js // src/dom-common.js
var x = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')), j = { setDeleteAttr: k }; var P = { setDeleteAttr: W };
function k(e, t, n) { function W(e, t, n) {
Reflect.set(e, t, n), m(n) && e.getAttribute(t) === "undefined" && e.removeAttribute(t); if (Reflect.set(e, t, n), !!m(n)) {
if (e instanceof HTMLElement && e.getAttribute(t) === "undefined")
return e.removeAttribute(t);
if (Reflect.get(e, t) === "undefined")
return Reflect.set(e, t, "");
}
} }
// src/dom.js // src/dom.js
var S = "html"; var S = "html";
function ce(e) { function oe(e) {
return S = e === "svg" ? "http://www.w3.org/2000/svg" : e, { return S = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(...t) { append(...t) {
return S = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t); return S = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t);
} }
}; };
} }
function ie(e, t, ...n) { function ce(e, t, ...n) {
let r = N(this), o; let r = v(this), o;
switch (r.isTextContent(t) && (t = { textContent: t }), !0) { switch ((Object(t) !== t || r.isSignal(t)) && (t = { textContent: t }), !0) {
case typeof e == "function": { case typeof e == "function": {
o = e(t || void 0, (s) => s ? (n.unshift(s), void 0) : o); o = e(t || void 0, (p) => p ? (n.unshift(p), void 0) : o);
break; break;
} }
case e === "#text": case e === "#text":
o = y(document.createTextNode(""), t); o = w(document.createTextNode(""), t);
break; break;
case e === "<>": case e === "<>":
o = y(document.createDocumentFragment(), t); o = w(document.createDocumentFragment(), t);
break; break;
case S !== "html": case S !== "html":
o = y(document.createElementNS(S, e), t); o = w(document.createElementNS(S, e), t);
break; break;
case !o: case !o:
o = y(document.createElement(e), t); o = w(document.createElement(e), t);
} }
return n.forEach((a) => a(o)), o; return n.forEach((i) => i(o)), o;
} }
var { setDeleteAttr: q } = j; var { setDeleteAttr: j } = P;
function y(e, ...t) { function w(e, ...t) {
let n = N(this); let n = this, r = v(this);
if (!t.length) if (!t.length)
return e; return e;
let r = e instanceof SVGElement, o = (r ? I : T).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 a([s, i]) { return Object.entries(Object.assign({}, ...t)).forEach(function p([s, a]) {
i = n.processReactiveAttribute(e, s, i, a); a = r.processReactiveAttribute(e, s, a, p);
let [h] = s; let [b] = s;
if (h === "=") if (b === "=")
return o(s.slice(1), i); return i(s.slice(1), a);
if (h === ".") if (b === ".")
return M(e, s.slice(1), i); return T(e, s.slice(1), a);
if (typeof i == "object" && i !== null) if (typeof a == "object" && a !== null && !Array.isArray(a))
switch (s) { switch (s) {
case "style": case "style":
return O(i, T.bind(null, e.style, "Property")); return N(r, a, T.bind(null, e[s]));
case "dataset":
return O(i, M.bind(null, e.dataset));
case "ariaset": case "ariaset":
return O(i, (E, v) => o("aria-" + E, v)); return N(r, a, (E, c) => i("aria-" + E, c));
case "classList": case "classList":
return J(e, i); return B.call(n, e, a);
default: default:
return Reflect.set(e, s, i); return Reflect.set(e, s, a);
} }
if (/(aria|data)([A-Z])/.test(s)) if (/(aria|data)([A-Z])/.test(s))
return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(s, i); return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(s, a);
switch (s) { switch (s === "className" && (s = "class"), s) {
case "href": case "href":
return o(s, i); return i(s, a, "http://www.w3.org/1999/xlink");
case "xlink:href":
return o(s, i, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
if (!r) return o ? e.appendChild(document.createTextNode(a)) : j(e, s, a);
break;
return e.appendChild(document.createTextNode(i));
} }
return W(e, s) ? q(e, s, i) : o(s, i); return H(e, s) ? j(e, s, a) : i(s, a);
}), e; }), e;
} }
function J(e, t) { function B(e, t) {
return typeof t != "object" || O( let n = v(this);
return typeof t != "object" || N(
n,
t, t,
(n, r) => e.classList.toggle(n, r === -1 ? void 0 : !!r) (r, o) => e.classList.toggle(r, o === -1 ? void 0 : !!o)
), e; ), e;
} }
function fe(e) { function se(e) {
return Array.from(e.children).forEach((t) => t.remove()), e; return Array.from(e.children).forEach((t) => t.remove()), e;
} }
function W(e, t) { function H(e, t) {
let n = "HTMLElement," + t; if (!Reflect.has(e, t))
if (e instanceof HTMLElement && x.has(n)) return !1;
return x.get(n); let n = F(e, t);
let r = e.nodeName + "," + t; return !m(n.set);
if (x.has(r))
return x.get(r);
let [o, a, s] = H(e, t), i = !m(o.set);
return (!i || a) && x.set(s === HTMLElement.prototype ? n : r, i), i;
} }
function H(e, t, n = 0) { function F(e, t, n = 0) {
if (e = Object.getPrototypeOf(e), !e) if (e = Object.getPrototypeOf(e), !e)
return [{}, n, e]; return {};
let r = Object.getOwnPropertyDescriptor(e, t); let r = Object.getOwnPropertyDescriptor(e, t);
return r ? [r, n, e] : H(e, t, n + 1); return r || F(e, t, n + 1);
} }
function O(e, t) { function N(e, t, n) {
return Object.entries(e).forEach(([n, r]) => n && t(n, r)); return Object.entries(t).forEach(function([o, i]) {
o && (i = e.processReactiveAttribute(t, o, i, (p) => n(...p)), n(o, i));
});
} }
function T(e, t, n, r) { function M(e) {
return e[(m(r) ? "remove" : "set") + t](n, r); return Array.isArray(e) ? e.filter(Boolean).join(" ") : e;
} }
function I(e, t, n, r, o = null) { function I(e, t, n, r) {
return e[(m(r) ? "remove" : "set") + t + "NS"](o, n, r); return e[(m(r) ? "remove" : "set") + t](n, M(r));
} }
function M(e, t, n) { function J(e, t, n, r, o = null) {
return e[(m(r) ? "remove" : "set") + t + "NS"](o, n, M(r));
}
function T(e, t, n) {
if (Reflect.set(e, t, n), !!m(n)) if (Reflect.set(e, t, n), !!m(n))
return Reflect.deleteProperty(e, t); return Reflect.deleteProperty(e, t);
} }
// src/events.js // src/events.js
function de(e, t, ...n) { function ae(e, t, ...n) {
let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t);
return e.dispatchEvent(r); return e.dispatchEvent(r);
} }
function F(e, t, n) { function z(e, t, n) {
return function(o) { return function(o) {
return o.addEventListener(e, t, n), o; return o.addEventListener(e, t, n), o;
}; };
} }
var C = Z(); var O = Z();
F.connected = function(e, t) { z.connected = function(e, t) {
return function(r) { 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); 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);
}; };
}; };
F.disconnected = function(e, t) { z.disconnected = function(e, t) {
return function(r) { 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); 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 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 f of c)
if (f.type === "childList") { if (f.type === "childList") {
if (E(f.addedNodes, !0)) { if (b(f.addedNodes, !0)) {
s(); p();
continue; continue;
} }
v(f.removedNodes, !0) && s(); E(f.removedNodes, !0) && p();
} }
}); });
return { return {
onConnected(c, f) { onConnected(c, f) {
a(), o(c).connected.push(f); i(), o(c).connected.push(f);
}, },
offConnected(c, f) { offConnected(c, f) {
if (!e.has(c)) if (!e.has(c))
return; return;
let u = e.get(c), p = u.connected; let u = e.get(c), l = u.connected;
p.splice(p.indexOf(f), 1), r(c, u); l.splice(l.indexOf(f), 1), r(c, u);
}, },
onDisconnected(c, f) { onDisconnected(c, f) {
a(), o(c).disconnected.push(f); i(), o(c).disconnected.push(f);
}, },
offDisconnected(c, f) { offDisconnected(c, f) {
if (!e.has(c)) if (!e.has(c))
return; return;
let u = e.get(c), p = u.disconnected; let u = e.get(c), l = u.disconnected;
p.splice(p.indexOf(f), 1), r(c, u); l.splice(l.indexOf(f), 1), r(c, u);
} }
}; };
function r(c, f) { function r(c, f) {
f.connected.length || f.disconnected.length || (e.delete(c), s()); f.connected.length || f.disconnected.length || (e.delete(c), p());
} }
function o(c) { function o(c) {
if (e.has(c)) if (e.has(c))
@ -210,19 +212,19 @@
let f = { connected: [], disconnected: [] }; let f = { connected: [], disconnected: [] };
return e.set(c, f), f; return e.set(c, f), f;
} }
function a() { function i() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
} }
function s() { function p() {
!t || e.size || (t = !1, n.disconnect()); !t || e.size || (t = !1, n.disconnect());
} }
function i() { function s() {
return new Promise(function(c) { return new Promise(function(c) {
(requestIdleCallback || requestAnimationFrame)(c); (requestIdleCallback || requestAnimationFrame)(c);
}); });
} }
async function h(c) { async function a(c) {
e.size > 30 && await i(); e.size > 30 && await s();
let f = []; let f = [];
if (!(c instanceof Node)) if (!(c instanceof Node))
return f; return f;
@ -230,21 +232,21 @@
u === c || !(u instanceof Node) || c.contains(u) && f.push(u); u === c || !(u instanceof Node) || c.contains(u) && f.push(u);
return f; return f;
} }
function E(c, f) { function b(c, f) {
for (let u of c) { for (let u of c) {
if (f && h(u).then(E), !e.has(u)) if (f && a(u).then(b), !e.has(u))
continue; continue;
let p = e.get(u); let l = e.get(u);
return p.connected.forEach((L) => L(u)), p.connected.length = 0, p.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 v(c, f) { function E(c, f) {
for (let u of c) { for (let u of c) {
if (f && h(u).then(v), !e.has(u)) if (f && a(u).then(E), !e.has(u))
continue; continue;
let p = e.get(u); let l = e.get(u);
return p.disconnected.forEach((L) => L(u)), p.connected.length = 0, p.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;
} }
return !1; return !1;
} }
@ -260,21 +262,21 @@
// src/signals-lib.js // src/signals-lib.js
var d = Symbol.for("Signal"); var d = Symbol.for("Signal");
function R(e) { function A(e) {
try { try {
return Reflect.has(e, d); return Reflect.has(e, d);
} catch { } catch {
return !1; return !1;
} }
} }
var l = /* @__PURE__ */ new WeakMap(); var h = /* @__PURE__ */ new WeakMap();
function g(e, t) { function g(e, t) {
if (typeof e != "function") if (typeof e != "function")
return z(e, t); return U(e, t);
if (R(e)) if (A(e))
return e; return e;
let n = z(""), r = () => n(e()); let n = U(""), r = () => n(e());
return l.set(r, /* @__PURE__ */ new Set([n])), V(r), n; return h.set(r, /* @__PURE__ */ new Set([n])), K(r), n;
} }
g.action = function(e, t, ...n) { g.action = function(e, t, ...n) {
let r = e[d], { actions: o } = r; let r = e[d], { actions: o } = r;
@ -282,14 +284,14 @@
throw new Error(`'${e}' has no action with name '${t}'!`); throw new Error(`'${e}' has no action with name '${t}'!`);
if (o[t].apply(r, n), r.skip) if (o[t].apply(r, n), r.skip)
return Reflect.deleteProperty(r, "skip"); return Reflect.deleteProperty(r, "skip");
r.listeners.forEach((a) => a(r.value)); r.listeners.forEach((i) => i(r.value));
}; };
g.on = function e(t, n, r = {}) { g.on = function e(t, n, r = {}) {
let { signal: o } = r; let { signal: o } = r;
if (!(o && o.aborted)) { if (!(o && o.aborted)) {
if (Array.isArray(t)) if (Array.isArray(t))
return t.forEach((a) => e(a, n, r)); return t.forEach((i) => e(i, n, r));
P(t, n), o && o.addEventListener("abort", () => $(t, n)); D(t, n), o && o.addEventListener("abort", () => q(t, n));
} }
}; };
g.symbols = { g.symbols = {
@ -304,102 +306,97 @@
} }
function t(n, r) { function t(n, r) {
r.listeners.forEach((o) => { r.listeners.forEach((o) => {
if (r.listeners.delete(o), !l.has(o)) if (r.listeners.delete(o), !h.has(o))
return; return;
let a = l.get(o); let i = h.get(o);
a.delete(n), !(a.size > 1) && (g.clear(...a), l.delete(o)); i.delete(n), !(i.size > 1) && (g.clear(...i), h.delete(o));
}); });
} }
}; };
g.el = function(e, t) { g.el = function(e, t) {
let n = document.createComment("<#reactive>"), r = document.createComment("</#reactive>"), o = document.createDocumentFragment(); let n = document.createComment("<#reactive>"), r = document.createComment("</#reactive>"), o = document.createDocumentFragment();
o.append(n, r); o.append(n, r);
let a = (s) => { let i = (p) => {
if (!n.parentNode || !r.parentNode) if (!n.parentNode || !r.parentNode)
return $(e, a); return q(e, i);
let i = t(s); let s = t(p);
Array.isArray(i) || (i = [i]); Array.isArray(s) || (s = [s]);
let h = n; let a = n;
for (; (h = n.nextSibling) !== r; ) for (; (a = n.nextSibling) !== r; )
h.remove(); a.remove();
n.after(...i); n.after(...s);
}; };
return P(e, a), a(e()), o; return D(e, i), i(e()), o;
}; };
var U = { var $ = {
isTextContent(e) { isSignal: A,
return w(e) === "string" || R(e) && w(Y(e)) === "string";
},
processReactiveAttribute(e, t, n, r) { processReactiveAttribute(e, t, n, r) {
return R(n) ? (P(n, (o) => r([t, o])), n()) : n; return A(n) ? (D(n, (o) => r([t, o])), n()) : n;
} }
}; };
function z(e, t) { function U(e, t) {
let n = (...r) => r.length ? X(n, r[0]) : Q(n); let n = (...r) => r.length ? Y(n, r[0]) : X(n);
return G(n, e, t); return V(n, e, t);
} }
var B = Object.assign(/* @__PURE__ */ Object.create(null), { var G = Object.assign(/* @__PURE__ */ Object.create(null), {
stopPropagation() { stopPropagation() {
this.skip = !0; this.skip = !0;
} }
}); });
function G(e, t, n) { function V(e, t, n) {
return w(n) !== "[object Object]" && (n = {}), e[d] = { return _(n) !== "[object Object]" && (n = {}), e[d] = {
value: t, value: t,
actions: n, actions: n,
listeners: /* @__PURE__ */ new Set() listeners: /* @__PURE__ */ new Set()
}, e.toJSON = () => e(), Object.setPrototypeOf(e[d], B), e; }, e.toJSON = () => e(), Object.setPrototypeOf(e[d], G), e;
} }
var A = []; var R = [];
function V(e) { function K(e) {
let t = function() { let t = function() {
A.push(t), e(), A.pop(); R.push(t), e(), R.pop();
}; };
l.has(e) && (l.set(t, l.get(e)), l.delete(e)), t(); h.has(e) && (h.set(t, h.get(e)), h.delete(e)), t();
} }
function K() { function Q() {
return A[A.length - 1]; return R[R.length - 1];
} }
function Q(e) { function X(e) {
if (!e[d]) if (!e[d])
return; return;
let { value: t, listeners: n } = e[d], r = K(); let { value: t, listeners: n } = e[d], r = Q();
return r && n.add(r), l.has(r) && l.get(r).add(e), t; return r && n.add(r), h.has(r) && h.get(r).add(e), t;
} }
function X(e, t) { function Y(e, t) {
if (!e[d]) if (!e[d])
return; return;
let n = e[d]; let n = e[d];
if (n.value !== t) if (n.value !== t)
return n.value = t, n.listeners.forEach((r) => r(t)), t; return n.value = t, n.listeners.forEach((r) => r(t)), t;
} }
function Y(e) { function D(e, t) {
return e[d].value;
}
function P(e, t) {
if (e[d]) if (e[d])
return e[d].listeners.add(t); return e[d].listeners.add(t);
} }
function $(e, t) { function q(e, t) {
if (e[d]) if (e[d])
return e[d].listeners.delete(t); return e[d].listeners.delete(t);
} }
// signals.js // signals.js
_(U); C($);
globalThis.dde= { globalThis.dde= {
S: g, S: g,
assign: y, assign: w,
classListDeclarative: J, classListDeclarative: B,
createElement: ie, createElement: ce,
dispatchEvent: de, dispatchEvent: ae,
el: ie, el: ce,
empty: fe, empty: se,
isSignal: R, isSignal: A,
namespace: ce, namespace: oe,
on: F, on: z,
registerReactivity: _ registerReactivity: C
}; };
})(); })();

250
dist/dde.js vendored
View File

@ -2,17 +2,17 @@
(()=> { (()=> {
// src/signals-common.js // src/signals-common.js
var g = { var g = {
isTextContent(e) { isSignal(e) {
return typeof e == "string"; return !1;
}, },
processReactiveAttribute(e, t, r, n) { processReactiveAttribute(e, t, r, n) {
return r; return r;
} }
}; };
function _(e, t = !0) { function y(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 O(e) { function v(e) {
return g.isPrototypeOf(e) && e !== g ? e : g; return g.isPrototypeOf(e) && e !== g ? e : g;
} }
@ -20,7 +20,7 @@
function p(e) { function p(e) {
return typeof e > "u"; return typeof e > "u";
} }
function L(e, t) { function w(e, t) {
if (!e || !(e instanceof AbortSignal)) if (!e || !(e instanceof AbortSignal))
return !0; return !0;
if (!e.aborted) if (!e.aborted)
@ -30,186 +30,188 @@
} }
// src/dom-common.js // src/dom-common.js
var l = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')), A = { setDeleteAttr: T }; var C = { setDeleteAttr: P };
function T(e, t, r) { function P(e, t, r) {
Reflect.set(e, t, r), p(r) && e.getAttribute(t) === "undefined" && e.removeAttribute(t); if (Reflect.set(e, t, r), !!p(r)) {
if (e instanceof HTMLElement && e.getAttribute(t) === "undefined")
return e.removeAttribute(t);
if (Reflect.get(e, t) === "undefined")
return Reflect.set(e, t, "");
}
} }
// src/dom.js // src/dom.js
var v = "html"; var b = "html";
function Z(e) { function I(e) {
return v = e === "svg" ? "http://www.w3.org/2000/svg" : e, { return b = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(...t) { append(...t) {
return v = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t); return b = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t);
} }
}; };
} }
function $(e, t, ...r) { function Z(e, t, ...r) {
let n = O(this), c; let n = v(this), c;
switch (n.isTextContent(t) && (t = { textContent: t }), !0) { switch ((Object(t) !== t || n.isSignal(t)) && (t = { textContent: t }), !0) {
case typeof e == "function": { case typeof e == "function": {
c = e(t || void 0, (s) => s ? (r.unshift(s), void 0) : c); c = e(t || void 0, (l) => l ? (r.unshift(l), void 0) : c);
break; break;
} }
case e === "#text": case e === "#text":
c = b(document.createTextNode(""), t); c = x(document.createTextNode(""), t);
break; break;
case e === "<>": case e === "<>":
c = b(document.createDocumentFragment(), t); c = x(document.createDocumentFragment(), t);
break; break;
case v !== "html": case b !== "html":
c = b(document.createElementNS(v, e), t); c = x(document.createElementNS(b, e), t);
break; break;
case !c: case !c:
c = b(document.createElement(e), t); c = x(document.createElement(e), t);
} }
return r.forEach((a) => a(c)), c; return r.forEach((d) => d(c)), c;
} }
var { setDeleteAttr: M } = A; var { setDeleteAttr: R } = C;
function b(e, ...t) { function x(e, ...t) {
let r = O(this); let r = this, n = v(this);
if (!t.length) if (!t.length)
return e; return e;
let n = e instanceof SVGElement, c = (n ? j : N).bind(null, e, "Attribute"); let c = e instanceof SVGElement, d = (c ? F : T).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function a([s, f]) { return Object.entries(Object.assign({}, ...t)).forEach(function l([f, u]) {
f = r.processReactiveAttribute(e, s, f, a); u = n.processReactiveAttribute(e, f, u, l);
let [h] = s; let [h] = f;
if (h === "=") if (h === "=")
return c(s.slice(1), f); return d(f.slice(1), u);
if (h === ".") if (h === ".")
return y(e, s.slice(1), f); return D(e, f.slice(1), u);
if (typeof f == "object" && f !== null) if (typeof u == "object" && u !== null && !Array.isArray(u))
switch (s) { switch (f) {
case "style": case "style":
return m(f, N.bind(null, e.style, "Property")); return O(n, u, D.bind(null, e[f]));
case "dataset":
return m(f, y.bind(null, e.dataset));
case "ariaset": case "ariaset":
return m(f, (x, E) => c("aria-" + x, E)); return O(n, u, (E, o) => d("aria-" + E, o));
case "classList": case "classList":
return P(e, f); return j.call(r, e, u);
default: default:
return Reflect.set(e, s, f); return Reflect.set(e, f, u);
} }
if (/(aria|data)([A-Z])/.test(s)) if (/(aria|data)([A-Z])/.test(f))
return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), c(s, f); return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), d(f, u);
switch (s) { switch (f === "className" && (f = "class"), f) {
case "href": case "href":
return c(s, f); return d(f, u, "http://www.w3.org/1999/xlink");
case "xlink:href":
return c(s, f, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
if (!n) return c ? e.appendChild(document.createTextNode(u)) : R(e, f, u);
break;
return e.appendChild(document.createTextNode(f));
} }
return S(e, s) ? M(e, s, f) : c(s, f); return _(e, f) ? R(e, f, u) : d(f, u);
}), e; }), e;
} }
function P(e, t) { function j(e, t) {
return typeof t != "object" || m( let r = v(this);
return typeof t != "object" || O(
r,
t, t,
(r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n) (n, c) => e.classList.toggle(n, c === -1 ? void 0 : !!c)
), e; ), e;
} }
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 S(e, t) { function _(e, t) {
let r = "HTMLElement," + t; if (!Reflect.has(e, t))
if (e instanceof HTMLElement && l.has(r)) return !1;
return l.get(r); let r = L(e, t);
let n = e.nodeName + "," + t; return !p(r.set);
if (l.has(n))
return l.get(n);
let [c, a, s] = D(e, t), f = !p(c.set);
return (!f || a) && l.set(s === HTMLElement.prototype ? r : n, f), f;
} }
function D(e, t, r = 0) { function L(e, t, r = 0) {
if (e = Object.getPrototypeOf(e), !e) if (e = Object.getPrototypeOf(e), !e)
return [{}, r, e]; return {};
let n = Object.getOwnPropertyDescriptor(e, t); let n = Object.getOwnPropertyDescriptor(e, t);
return n ? [n, r, e] : D(e, t, r + 1); return n || L(e, t, r + 1);
} }
function m(e, t) { function O(e, t, r) {
return Object.entries(e).forEach(([r, n]) => r && t(r, n)); return Object.entries(t).forEach(function([c, d]) {
c && (d = e.processReactiveAttribute(t, c, d, (l) => r(...l)), r(c, d));
});
} }
function N(e, t, r, n) { function N(e) {
return e[(p(n) ? "remove" : "set") + t](r, n); return Array.isArray(e) ? e.filter(Boolean).join(" ") : e;
} }
function j(e, t, r, n, c = null) { function T(e, t, r, n) {
return e[(p(n) ? "remove" : "set") + t + "NS"](c, r, n); return e[(p(n) ? "remove" : "set") + t](r, N(n));
} }
function y(e, t, r) { function F(e, t, r, n, c = null) {
return e[(p(n) ? "remove" : "set") + t + "NS"](c, r, N(n));
}
function D(e, t, r) {
if (Reflect.set(e, t, r), !!p(r)) if (Reflect.set(e, t, r), !!p(r))
return Reflect.deleteProperty(e, t); return Reflect.deleteProperty(e, t);
} }
// src/events.js // src/events.js
function W(e, t, ...r) { function J(e, t, ...r) {
let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t); let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t);
return e.dispatchEvent(n); return e.dispatchEvent(n);
} }
function R(e, t, r) { function S(e, t, r) {
return function(c) { return function(c) {
return c.addEventListener(e, t, r), c; return c.addEventListener(e, t, r), c;
}; };
} }
var w = H(); var m = M();
R.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) : (L(t && t.signal, () => w.offConnected(n, e)) && (n.isConnected ? e(new Event("dde:connected")) : w.onConnected(n, e)), 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);
}; };
}; };
R.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) : (L(t && t.signal, () => w.offDisconnected(n, e)) && w.onDisconnected(n, e), 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);
}; };
}; };
function H() { function M() {
let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(o) { let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(o) {
for (let i of o) for (let s of o)
if (i.type === "childList") { if (s.type === "childList") {
if (x(i.addedNodes, !0)) { if (h(s.addedNodes, !0)) {
s(); l();
continue; continue;
} }
E(i.removedNodes, !0) && s(); E(s.removedNodes, !0) && l();
} }
}); });
return { return {
onConnected(o, i) { onConnected(o, s) {
a(), c(o).connected.push(i); d(), c(o).connected.push(s);
}, },
offConnected(o, i) { offConnected(o, s) {
if (!e.has(o)) if (!e.has(o))
return; return;
let u = e.get(o), d = u.connected; let i = e.get(o), a = i.connected;
d.splice(d.indexOf(i), 1), n(o, u); a.splice(a.indexOf(s), 1), n(o, i);
}, },
onDisconnected(o, i) { onDisconnected(o, s) {
a(), c(o).disconnected.push(i); d(), c(o).disconnected.push(s);
}, },
offDisconnected(o, i) { offDisconnected(o, s) {
if (!e.has(o)) if (!e.has(o))
return; return;
let u = e.get(o), d = u.disconnected; let i = e.get(o), a = i.disconnected;
d.splice(d.indexOf(i), 1), n(o, u); a.splice(a.indexOf(s), 1), n(o, i);
} }
}; };
function n(o, i) { function n(o, s) {
i.connected.length || i.disconnected.length || (e.delete(o), s()); s.connected.length || s.disconnected.length || (e.delete(o), l());
} }
function c(o) { function c(o) {
if (e.has(o)) if (e.has(o))
return e.get(o); return e.get(o);
let i = { connected: [], disconnected: [] }; let s = { connected: [], disconnected: [] };
return e.set(o, i), i; return e.set(o, s), s;
} }
function a() { function d() {
t || (t = !0, r.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, r.observe(document.body, { childList: !0, subtree: !0 }));
} }
function s() { function l() {
!t || e.size || (t = !1, r.disconnect()); !t || e.size || (t = !1, r.disconnect());
} }
function f() { function f() {
@ -217,30 +219,30 @@
(requestIdleCallback || requestAnimationFrame)(o); (requestIdleCallback || requestAnimationFrame)(o);
}); });
} }
async function h(o) { async function u(o) {
e.size > 30 && await f(); e.size > 30 && await f();
let i = []; let s = [];
if (!(o instanceof Node)) if (!(o instanceof Node))
return i; return s;
for (let u of e.keys()) for (let i of e.keys())
u === o || !(u instanceof Node) || o.contains(u) && i.push(u); i === o || !(i instanceof Node) || o.contains(i) && s.push(i);
return i; return s;
} }
function x(o, i) { function h(o, s) {
for (let u of o) { for (let i of o) {
if (i && h(u).then(x), !e.has(u)) if (s && u(i).then(h), !e.has(i))
continue; continue;
let d = e.get(u); let a = e.get(i);
return d.connected.forEach((C) => C(u)), d.connected.length = 0, d.disconnected.length || e.delete(u), !0; return a.connected.forEach((A) => A(i)), a.connected.length = 0, a.disconnected.length || e.delete(i), !0;
} }
return !1; return !1;
} }
function E(o, i) { function E(o, s) {
for (let u of o) { for (let i of o) {
if (i && h(u).then(E), !e.has(u)) if (s && u(i).then(E), !e.has(i))
continue; continue;
let d = e.get(u); let a = e.get(i);
return d.disconnected.forEach((C) => C(u)), d.connected.length = 0, d.disconnected.length = 0, e.delete(u), !0; return a.disconnected.forEach((A) => A(i)), a.connected.length = 0, a.disconnected.length = 0, e.delete(i), !0;
} }
return !1; return !1;
} }
@ -255,15 +257,15 @@
}); });
globalThis.dde= { globalThis.dde= {
assign: b, assign: x,
classListDeclarative: P, classListDeclarative: j,
createElement: $, createElement: Z,
dispatchEvent: W, dispatchEvent: J,
el: $, el: Z,
empty: G, empty: G,
namespace: Z, namespace: I,
on: R, on: S,
registerReactivity: _ registerReactivity: y
}; };
})(); })();

View File

@ -1,28 +1,28 @@
// src/signals-common.js // src/signals-common.js
var b = { var x = {
isTextContent(e) { isSignal(e) {
return typeof e == "string"; return !1;
}, },
processReactiveAttribute(e, t, n, r) { processReactiveAttribute(e, t, n, r) {
return n; return n;
} }
}; };
function _(e, t = !0) { function C(e, t = !0) {
return t ? Object.assign(b, e) : (Object.setPrototypeOf(e, b), e); return t ? Object.assign(x, e) : (Object.setPrototypeOf(e, x), e);
} }
function N(e) { function v(e) {
return b.isPrototypeOf(e) && e !== b ? e : b; return x.isPrototypeOf(e) && e !== x ? e : x;
} }
// src/helpers.js // src/helpers.js
function m(e) { function m(e) {
return typeof e > "u"; return typeof e > "u";
} }
function w(e) { function _(e) {
let t = typeof e; let t = typeof e;
return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e); return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e);
} }
function D(e, t) { function L(e, t) {
if (!e || !(e instanceof AbortSignal)) if (!e || !(e instanceof AbortSignal))
return !0; return !0;
if (!e.aborted) if (!e.aborted)
@ -32,175 +32,177 @@ function D(e, t) {
} }
// src/dom-common.js // src/dom-common.js
var x = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')), j = { setDeleteAttr: k }; var P = { setDeleteAttr: W };
function k(e, t, n) { function W(e, t, n) {
Reflect.set(e, t, n), m(n) && e.getAttribute(t) === "undefined" && e.removeAttribute(t); if (Reflect.set(e, t, n), !!m(n)) {
if (e instanceof HTMLElement && e.getAttribute(t) === "undefined")
return e.removeAttribute(t);
if (Reflect.get(e, t) === "undefined")
return Reflect.set(e, t, "");
}
} }
// src/dom.js // src/dom.js
var S = "html"; var S = "html";
function ce(e) { function oe(e) {
return S = e === "svg" ? "http://www.w3.org/2000/svg" : e, { return S = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(...t) { append(...t) {
return S = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t); return S = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t);
} }
}; };
} }
function ie(e, t, ...n) { function ce(e, t, ...n) {
let r = N(this), o; let r = v(this), o;
switch (r.isTextContent(t) && (t = { textContent: t }), !0) { switch ((Object(t) !== t || r.isSignal(t)) && (t = { textContent: t }), !0) {
case typeof e == "function": { case typeof e == "function": {
o = e(t || void 0, (s) => s ? (n.unshift(s), void 0) : o); o = e(t || void 0, (p) => p ? (n.unshift(p), void 0) : o);
break; break;
} }
case e === "#text": case e === "#text":
o = y(document.createTextNode(""), t); o = w(document.createTextNode(""), t);
break; break;
case e === "<>": case e === "<>":
o = y(document.createDocumentFragment(), t); o = w(document.createDocumentFragment(), t);
break; break;
case S !== "html": case S !== "html":
o = y(document.createElementNS(S, e), t); o = w(document.createElementNS(S, e), t);
break; break;
case !o: case !o:
o = y(document.createElement(e), t); o = w(document.createElement(e), t);
} }
return n.forEach((a) => a(o)), o; return n.forEach((i) => i(o)), o;
} }
var { setDeleteAttr: q } = j; var { setDeleteAttr: j } = P;
function y(e, ...t) { function w(e, ...t) {
let n = N(this); let n = this, r = v(this);
if (!t.length) if (!t.length)
return e; return e;
let r = e instanceof SVGElement, o = (r ? I : T).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 a([s, i]) { return Object.entries(Object.assign({}, ...t)).forEach(function p([s, a]) {
i = n.processReactiveAttribute(e, s, i, a); a = r.processReactiveAttribute(e, s, a, p);
let [h] = s; let [b] = s;
if (h === "=") if (b === "=")
return o(s.slice(1), i); return i(s.slice(1), a);
if (h === ".") if (b === ".")
return M(e, s.slice(1), i); return T(e, s.slice(1), a);
if (typeof i == "object" && i !== null) if (typeof a == "object" && a !== null && !Array.isArray(a))
switch (s) { switch (s) {
case "style": case "style":
return O(i, T.bind(null, e.style, "Property")); return N(r, a, T.bind(null, e[s]));
case "dataset":
return O(i, M.bind(null, e.dataset));
case "ariaset": case "ariaset":
return O(i, (E, v) => o("aria-" + E, v)); return N(r, a, (E, c) => i("aria-" + E, c));
case "classList": case "classList":
return J(e, i); return B.call(n, e, a);
default: default:
return Reflect.set(e, s, i); return Reflect.set(e, s, a);
} }
if (/(aria|data)([A-Z])/.test(s)) if (/(aria|data)([A-Z])/.test(s))
return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(s, i); return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(s, a);
switch (s) { switch (s === "className" && (s = "class"), s) {
case "href": case "href":
return o(s, i); return i(s, a, "http://www.w3.org/1999/xlink");
case "xlink:href":
return o(s, i, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
if (!r) return o ? e.appendChild(document.createTextNode(a)) : j(e, s, a);
break;
return e.appendChild(document.createTextNode(i));
} }
return W(e, s) ? q(e, s, i) : o(s, i); return H(e, s) ? j(e, s, a) : i(s, a);
}), e; }), e;
} }
function J(e, t) { function B(e, t) {
return typeof t != "object" || O( let n = v(this);
return typeof t != "object" || N(
n,
t, t,
(n, r) => e.classList.toggle(n, r === -1 ? void 0 : !!r) (r, o) => e.classList.toggle(r, o === -1 ? void 0 : !!o)
), e; ), e;
} }
function fe(e) { function se(e) {
return Array.from(e.children).forEach((t) => t.remove()), e; return Array.from(e.children).forEach((t) => t.remove()), e;
} }
function W(e, t) { function H(e, t) {
let n = "HTMLElement," + t; if (!Reflect.has(e, t))
if (e instanceof HTMLElement && x.has(n)) return !1;
return x.get(n); let n = F(e, t);
let r = e.nodeName + "," + t; return !m(n.set);
if (x.has(r))
return x.get(r);
let [o, a, s] = H(e, t), i = !m(o.set);
return (!i || a) && x.set(s === HTMLElement.prototype ? n : r, i), i;
} }
function H(e, t, n = 0) { function F(e, t, n = 0) {
if (e = Object.getPrototypeOf(e), !e) if (e = Object.getPrototypeOf(e), !e)
return [{}, n, e]; return {};
let r = Object.getOwnPropertyDescriptor(e, t); let r = Object.getOwnPropertyDescriptor(e, t);
return r ? [r, n, e] : H(e, t, n + 1); return r || F(e, t, n + 1);
} }
function O(e, t) { function N(e, t, n) {
return Object.entries(e).forEach(([n, r]) => n && t(n, r)); return Object.entries(t).forEach(function([o, i]) {
o && (i = e.processReactiveAttribute(t, o, i, (p) => n(...p)), n(o, i));
});
} }
function T(e, t, n, r) { function M(e) {
return e[(m(r) ? "remove" : "set") + t](n, r); return Array.isArray(e) ? e.filter(Boolean).join(" ") : e;
} }
function I(e, t, n, r, o = null) { function I(e, t, n, r) {
return e[(m(r) ? "remove" : "set") + t + "NS"](o, n, r); return e[(m(r) ? "remove" : "set") + t](n, M(r));
} }
function M(e, t, n) { function J(e, t, n, r, o = null) {
return e[(m(r) ? "remove" : "set") + t + "NS"](o, n, M(r));
}
function T(e, t, n) {
if (Reflect.set(e, t, n), !!m(n)) if (Reflect.set(e, t, n), !!m(n))
return Reflect.deleteProperty(e, t); return Reflect.deleteProperty(e, t);
} }
// src/events.js // src/events.js
function de(e, t, ...n) { function ae(e, t, ...n) {
let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t);
return e.dispatchEvent(r); return e.dispatchEvent(r);
} }
function F(e, t, n) { function z(e, t, n) {
return function(o) { return function(o) {
return o.addEventListener(e, t, n), o; return o.addEventListener(e, t, n), o;
}; };
} }
var C = Z(); var O = Z();
F.connected = function(e, t) { z.connected = function(e, t) {
return function(r) { 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); 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);
}; };
}; };
F.disconnected = function(e, t) { z.disconnected = function(e, t) {
return function(r) { 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); 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 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 f of c)
if (f.type === "childList") { if (f.type === "childList") {
if (E(f.addedNodes, !0)) { if (b(f.addedNodes, !0)) {
s(); p();
continue; continue;
} }
v(f.removedNodes, !0) && s(); E(f.removedNodes, !0) && p();
} }
}); });
return { return {
onConnected(c, f) { onConnected(c, f) {
a(), o(c).connected.push(f); i(), o(c).connected.push(f);
}, },
offConnected(c, f) { offConnected(c, f) {
if (!e.has(c)) if (!e.has(c))
return; return;
let u = e.get(c), p = u.connected; let u = e.get(c), l = u.connected;
p.splice(p.indexOf(f), 1), r(c, u); l.splice(l.indexOf(f), 1), r(c, u);
}, },
onDisconnected(c, f) { onDisconnected(c, f) {
a(), o(c).disconnected.push(f); i(), o(c).disconnected.push(f);
}, },
offDisconnected(c, f) { offDisconnected(c, f) {
if (!e.has(c)) if (!e.has(c))
return; return;
let u = e.get(c), p = u.disconnected; let u = e.get(c), l = u.disconnected;
p.splice(p.indexOf(f), 1), r(c, u); l.splice(l.indexOf(f), 1), r(c, u);
} }
}; };
function r(c, f) { function r(c, f) {
f.connected.length || f.disconnected.length || (e.delete(c), s()); f.connected.length || f.disconnected.length || (e.delete(c), p());
} }
function o(c) { function o(c) {
if (e.has(c)) if (e.has(c))
@ -208,19 +210,19 @@ function Z() {
let f = { connected: [], disconnected: [] }; let f = { connected: [], disconnected: [] };
return e.set(c, f), f; return e.set(c, f), f;
} }
function a() { function i() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
} }
function s() { function p() {
!t || e.size || (t = !1, n.disconnect()); !t || e.size || (t = !1, n.disconnect());
} }
function i() { function s() {
return new Promise(function(c) { return new Promise(function(c) {
(requestIdleCallback || requestAnimationFrame)(c); (requestIdleCallback || requestAnimationFrame)(c);
}); });
} }
async function h(c) { async function a(c) {
e.size > 30 && await i(); e.size > 30 && await s();
let f = []; let f = [];
if (!(c instanceof Node)) if (!(c instanceof Node))
return f; return f;
@ -228,21 +230,21 @@ function Z() {
u === c || !(u instanceof Node) || c.contains(u) && f.push(u); u === c || !(u instanceof Node) || c.contains(u) && f.push(u);
return f; return f;
} }
function E(c, f) { function b(c, f) {
for (let u of c) { for (let u of c) {
if (f && h(u).then(E), !e.has(u)) if (f && a(u).then(b), !e.has(u))
continue; continue;
let p = e.get(u); let l = e.get(u);
return p.connected.forEach((L) => L(u)), p.connected.length = 0, p.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 v(c, f) { function E(c, f) {
for (let u of c) { for (let u of c) {
if (f && h(u).then(v), !e.has(u)) if (f && a(u).then(E), !e.has(u))
continue; continue;
let p = e.get(u); let l = e.get(u);
return p.disconnected.forEach((L) => L(u)), p.connected.length = 0, p.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;
} }
return !1; return !1;
} }
@ -258,21 +260,21 @@ function Z() {
// src/signals-lib.js // src/signals-lib.js
var d = Symbol.for("Signal"); var d = Symbol.for("Signal");
function R(e) { function A(e) {
try { try {
return Reflect.has(e, d); return Reflect.has(e, d);
} catch { } catch {
return !1; return !1;
} }
} }
var l = /* @__PURE__ */ new WeakMap(); var h = /* @__PURE__ */ new WeakMap();
function g(e, t) { function g(e, t) {
if (typeof e != "function") if (typeof e != "function")
return z(e, t); return U(e, t);
if (R(e)) if (A(e))
return e; return e;
let n = z(""), r = () => n(e()); let n = U(""), r = () => n(e());
return l.set(r, /* @__PURE__ */ new Set([n])), V(r), n; return h.set(r, /* @__PURE__ */ new Set([n])), K(r), n;
} }
g.action = function(e, t, ...n) { g.action = function(e, t, ...n) {
let r = e[d], { actions: o } = r; let r = e[d], { actions: o } = r;
@ -280,14 +282,14 @@ g.action = function(e, t, ...n) {
throw new Error(`'${e}' has no action with name '${t}'!`); throw new Error(`'${e}' has no action with name '${t}'!`);
if (o[t].apply(r, n), r.skip) if (o[t].apply(r, n), r.skip)
return Reflect.deleteProperty(r, "skip"); return Reflect.deleteProperty(r, "skip");
r.listeners.forEach((a) => a(r.value)); r.listeners.forEach((i) => i(r.value));
}; };
g.on = function e(t, n, r = {}) { g.on = function e(t, n, r = {}) {
let { signal: o } = r; let { signal: o } = r;
if (!(o && o.aborted)) { if (!(o && o.aborted)) {
if (Array.isArray(t)) if (Array.isArray(t))
return t.forEach((a) => e(a, n, r)); return t.forEach((i) => e(i, n, r));
P(t, n), o && o.addEventListener("abort", () => $(t, n)); D(t, n), o && o.addEventListener("abort", () => q(t, n));
} }
}; };
g.symbols = { g.symbols = {
@ -302,99 +304,94 @@ g.clear = function(...e) {
} }
function t(n, r) { function t(n, r) {
r.listeners.forEach((o) => { r.listeners.forEach((o) => {
if (r.listeners.delete(o), !l.has(o)) if (r.listeners.delete(o), !h.has(o))
return; return;
let a = l.get(o); let i = h.get(o);
a.delete(n), !(a.size > 1) && (g.clear(...a), l.delete(o)); i.delete(n), !(i.size > 1) && (g.clear(...i), h.delete(o));
}); });
} }
}; };
g.el = function(e, t) { g.el = function(e, t) {
let n = document.createComment("<#reactive>"), r = document.createComment("</#reactive>"), o = document.createDocumentFragment(); let n = document.createComment("<#reactive>"), r = document.createComment("</#reactive>"), o = document.createDocumentFragment();
o.append(n, r); o.append(n, r);
let a = (s) => { let i = (p) => {
if (!n.parentNode || !r.parentNode) if (!n.parentNode || !r.parentNode)
return $(e, a); return q(e, i);
let i = t(s); let s = t(p);
Array.isArray(i) || (i = [i]); Array.isArray(s) || (s = [s]);
let h = n; let a = n;
for (; (h = n.nextSibling) !== r; ) for (; (a = n.nextSibling) !== r; )
h.remove(); a.remove();
n.after(...i); n.after(...s);
}; };
return P(e, a), a(e()), o; return D(e, i), i(e()), o;
}; };
var U = { var $ = {
isTextContent(e) { isSignal: A,
return w(e) === "string" || R(e) && w(Y(e)) === "string";
},
processReactiveAttribute(e, t, n, r) { processReactiveAttribute(e, t, n, r) {
return R(n) ? (P(n, (o) => r([t, o])), n()) : n; return A(n) ? (D(n, (o) => r([t, o])), n()) : n;
} }
}; };
function z(e, t) { function U(e, t) {
let n = (...r) => r.length ? X(n, r[0]) : Q(n); let n = (...r) => r.length ? Y(n, r[0]) : X(n);
return G(n, e, t); return V(n, e, t);
} }
var B = Object.assign(/* @__PURE__ */ Object.create(null), { var G = Object.assign(/* @__PURE__ */ Object.create(null), {
stopPropagation() { stopPropagation() {
this.skip = !0; this.skip = !0;
} }
}); });
function G(e, t, n) { function V(e, t, n) {
return w(n) !== "[object Object]" && (n = {}), e[d] = { return _(n) !== "[object Object]" && (n = {}), e[d] = {
value: t, value: t,
actions: n, actions: n,
listeners: /* @__PURE__ */ new Set() listeners: /* @__PURE__ */ new Set()
}, e.toJSON = () => e(), Object.setPrototypeOf(e[d], B), e; }, e.toJSON = () => e(), Object.setPrototypeOf(e[d], G), e;
} }
var A = []; var R = [];
function V(e) { function K(e) {
let t = function() { let t = function() {
A.push(t), e(), A.pop(); R.push(t), e(), R.pop();
}; };
l.has(e) && (l.set(t, l.get(e)), l.delete(e)), t(); h.has(e) && (h.set(t, h.get(e)), h.delete(e)), t();
} }
function K() { function Q() {
return A[A.length - 1]; return R[R.length - 1];
} }
function Q(e) { function X(e) {
if (!e[d]) if (!e[d])
return; return;
let { value: t, listeners: n } = e[d], r = K(); let { value: t, listeners: n } = e[d], r = Q();
return r && n.add(r), l.has(r) && l.get(r).add(e), t; return r && n.add(r), h.has(r) && h.get(r).add(e), t;
} }
function X(e, t) { function Y(e, t) {
if (!e[d]) if (!e[d])
return; return;
let n = e[d]; let n = e[d];
if (n.value !== t) if (n.value !== t)
return n.value = t, n.listeners.forEach((r) => r(t)), t; return n.value = t, n.listeners.forEach((r) => r(t)), t;
} }
function Y(e) { function D(e, t) {
return e[d].value;
}
function P(e, t) {
if (e[d]) if (e[d])
return e[d].listeners.add(t); return e[d].listeners.add(t);
} }
function $(e, t) { function q(e, t) {
if (e[d]) if (e[d])
return e[d].listeners.delete(t); return e[d].listeners.delete(t);
} }
// signals.js // signals.js
_(U); C($);
export { export {
g as S, g as S,
y as assign, w as assign,
J as classListDeclarative, B as classListDeclarative,
ie as createElement, ce as createElement,
de as dispatchEvent, ae as dispatchEvent,
ie as el, ce as el,
fe as empty, se as empty,
R as isSignal, A as isSignal,
ce as namespace, oe as namespace,
F as on, z as on,
_ as registerReactivity C as registerReactivity
}; };

250
dist/esm.js vendored
View File

@ -1,16 +1,16 @@
// src/signals-common.js // src/signals-common.js
var g = { var g = {
isTextContent(e) { isSignal(e) {
return typeof e == "string"; return !1;
}, },
processReactiveAttribute(e, t, r, n) { processReactiveAttribute(e, t, r, n) {
return r; return r;
} }
}; };
function _(e, t = !0) { function y(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 O(e) { function v(e) {
return g.isPrototypeOf(e) && e !== g ? e : g; return g.isPrototypeOf(e) && e !== g ? e : g;
} }
@ -18,7 +18,7 @@ function O(e) {
function p(e) { function p(e) {
return typeof e > "u"; return typeof e > "u";
} }
function L(e, t) { function w(e, t) {
if (!e || !(e instanceof AbortSignal)) if (!e || !(e instanceof AbortSignal))
return !0; return !0;
if (!e.aborted) if (!e.aborted)
@ -28,186 +28,188 @@ function L(e, t) {
} }
// src/dom-common.js // src/dom-common.js
var l = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')), A = { setDeleteAttr: T }; var C = { setDeleteAttr: P };
function T(e, t, r) { function P(e, t, r) {
Reflect.set(e, t, r), p(r) && e.getAttribute(t) === "undefined" && e.removeAttribute(t); if (Reflect.set(e, t, r), !!p(r)) {
if (e instanceof HTMLElement && e.getAttribute(t) === "undefined")
return e.removeAttribute(t);
if (Reflect.get(e, t) === "undefined")
return Reflect.set(e, t, "");
}
} }
// src/dom.js // src/dom.js
var v = "html"; var b = "html";
function Z(e) { function I(e) {
return v = e === "svg" ? "http://www.w3.org/2000/svg" : e, { return b = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(...t) { append(...t) {
return v = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t); return b = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t);
} }
}; };
} }
function $(e, t, ...r) { function Z(e, t, ...r) {
let n = O(this), c; let n = v(this), c;
switch (n.isTextContent(t) && (t = { textContent: t }), !0) { switch ((Object(t) !== t || n.isSignal(t)) && (t = { textContent: t }), !0) {
case typeof e == "function": { case typeof e == "function": {
c = e(t || void 0, (s) => s ? (r.unshift(s), void 0) : c); c = e(t || void 0, (l) => l ? (r.unshift(l), void 0) : c);
break; break;
} }
case e === "#text": case e === "#text":
c = b(document.createTextNode(""), t); c = x(document.createTextNode(""), t);
break; break;
case e === "<>": case e === "<>":
c = b(document.createDocumentFragment(), t); c = x(document.createDocumentFragment(), t);
break; break;
case v !== "html": case b !== "html":
c = b(document.createElementNS(v, e), t); c = x(document.createElementNS(b, e), t);
break; break;
case !c: case !c:
c = b(document.createElement(e), t); c = x(document.createElement(e), t);
} }
return r.forEach((a) => a(c)), c; return r.forEach((d) => d(c)), c;
} }
var { setDeleteAttr: M } = A; var { setDeleteAttr: R } = C;
function b(e, ...t) { function x(e, ...t) {
let r = O(this); let r = this, n = v(this);
if (!t.length) if (!t.length)
return e; return e;
let n = e instanceof SVGElement, c = (n ? j : N).bind(null, e, "Attribute"); let c = e instanceof SVGElement, d = (c ? F : T).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function a([s, f]) { return Object.entries(Object.assign({}, ...t)).forEach(function l([f, u]) {
f = r.processReactiveAttribute(e, s, f, a); u = n.processReactiveAttribute(e, f, u, l);
let [h] = s; let [h] = f;
if (h === "=") if (h === "=")
return c(s.slice(1), f); return d(f.slice(1), u);
if (h === ".") if (h === ".")
return y(e, s.slice(1), f); return D(e, f.slice(1), u);
if (typeof f == "object" && f !== null) if (typeof u == "object" && u !== null && !Array.isArray(u))
switch (s) { switch (f) {
case "style": case "style":
return m(f, N.bind(null, e.style, "Property")); return O(n, u, D.bind(null, e[f]));
case "dataset":
return m(f, y.bind(null, e.dataset));
case "ariaset": case "ariaset":
return m(f, (x, E) => c("aria-" + x, E)); return O(n, u, (E, o) => d("aria-" + E, o));
case "classList": case "classList":
return P(e, f); return j.call(r, e, u);
default: default:
return Reflect.set(e, s, f); return Reflect.set(e, f, u);
} }
if (/(aria|data)([A-Z])/.test(s)) if (/(aria|data)([A-Z])/.test(f))
return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), c(s, f); return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), d(f, u);
switch (s) { switch (f === "className" && (f = "class"), f) {
case "href": case "href":
return c(s, f); return d(f, u, "http://www.w3.org/1999/xlink");
case "xlink:href":
return c(s, f, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
if (!n) return c ? e.appendChild(document.createTextNode(u)) : R(e, f, u);
break;
return e.appendChild(document.createTextNode(f));
} }
return S(e, s) ? M(e, s, f) : c(s, f); return _(e, f) ? R(e, f, u) : d(f, u);
}), e; }), e;
} }
function P(e, t) { function j(e, t) {
return typeof t != "object" || m( let r = v(this);
return typeof t != "object" || O(
r,
t, t,
(r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n) (n, c) => e.classList.toggle(n, c === -1 ? void 0 : !!c)
), e; ), e;
} }
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 S(e, t) { function _(e, t) {
let r = "HTMLElement," + t; if (!Reflect.has(e, t))
if (e instanceof HTMLElement && l.has(r)) return !1;
return l.get(r); let r = L(e, t);
let n = e.nodeName + "," + t; return !p(r.set);
if (l.has(n))
return l.get(n);
let [c, a, s] = D(e, t), f = !p(c.set);
return (!f || a) && l.set(s === HTMLElement.prototype ? r : n, f), f;
} }
function D(e, t, r = 0) { function L(e, t, r = 0) {
if (e = Object.getPrototypeOf(e), !e) if (e = Object.getPrototypeOf(e), !e)
return [{}, r, e]; return {};
let n = Object.getOwnPropertyDescriptor(e, t); let n = Object.getOwnPropertyDescriptor(e, t);
return n ? [n, r, e] : D(e, t, r + 1); return n || L(e, t, r + 1);
} }
function m(e, t) { function O(e, t, r) {
return Object.entries(e).forEach(([r, n]) => r && t(r, n)); return Object.entries(t).forEach(function([c, d]) {
c && (d = e.processReactiveAttribute(t, c, d, (l) => r(...l)), r(c, d));
});
} }
function N(e, t, r, n) { function N(e) {
return e[(p(n) ? "remove" : "set") + t](r, n); return Array.isArray(e) ? e.filter(Boolean).join(" ") : e;
} }
function j(e, t, r, n, c = null) { function T(e, t, r, n) {
return e[(p(n) ? "remove" : "set") + t + "NS"](c, r, n); return e[(p(n) ? "remove" : "set") + t](r, N(n));
} }
function y(e, t, r) { function F(e, t, r, n, c = null) {
return e[(p(n) ? "remove" : "set") + t + "NS"](c, r, N(n));
}
function D(e, t, r) {
if (Reflect.set(e, t, r), !!p(r)) if (Reflect.set(e, t, r), !!p(r))
return Reflect.deleteProperty(e, t); return Reflect.deleteProperty(e, t);
} }
// src/events.js // src/events.js
function W(e, t, ...r) { function J(e, t, ...r) {
let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t); let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t);
return e.dispatchEvent(n); return e.dispatchEvent(n);
} }
function R(e, t, r) { function S(e, t, r) {
return function(c) { return function(c) {
return c.addEventListener(e, t, r), c; return c.addEventListener(e, t, r), c;
}; };
} }
var w = H(); var m = M();
R.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) : (L(t && t.signal, () => w.offConnected(n, e)) && (n.isConnected ? e(new Event("dde:connected")) : w.onConnected(n, e)), 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);
}; };
}; };
R.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) : (L(t && t.signal, () => w.offDisconnected(n, e)) && w.onDisconnected(n, e), 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);
}; };
}; };
function H() { function M() {
let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(o) { let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(o) {
for (let i of o) for (let s of o)
if (i.type === "childList") { if (s.type === "childList") {
if (x(i.addedNodes, !0)) { if (h(s.addedNodes, !0)) {
s(); l();
continue; continue;
} }
E(i.removedNodes, !0) && s(); E(s.removedNodes, !0) && l();
} }
}); });
return { return {
onConnected(o, i) { onConnected(o, s) {
a(), c(o).connected.push(i); d(), c(o).connected.push(s);
}, },
offConnected(o, i) { offConnected(o, s) {
if (!e.has(o)) if (!e.has(o))
return; return;
let u = e.get(o), d = u.connected; let i = e.get(o), a = i.connected;
d.splice(d.indexOf(i), 1), n(o, u); a.splice(a.indexOf(s), 1), n(o, i);
}, },
onDisconnected(o, i) { onDisconnected(o, s) {
a(), c(o).disconnected.push(i); d(), c(o).disconnected.push(s);
}, },
offDisconnected(o, i) { offDisconnected(o, s) {
if (!e.has(o)) if (!e.has(o))
return; return;
let u = e.get(o), d = u.disconnected; let i = e.get(o), a = i.disconnected;
d.splice(d.indexOf(i), 1), n(o, u); a.splice(a.indexOf(s), 1), n(o, i);
} }
}; };
function n(o, i) { function n(o, s) {
i.connected.length || i.disconnected.length || (e.delete(o), s()); s.connected.length || s.disconnected.length || (e.delete(o), l());
} }
function c(o) { function c(o) {
if (e.has(o)) if (e.has(o))
return e.get(o); return e.get(o);
let i = { connected: [], disconnected: [] }; let s = { connected: [], disconnected: [] };
return e.set(o, i), i; return e.set(o, s), s;
} }
function a() { function d() {
t || (t = !0, r.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, r.observe(document.body, { childList: !0, subtree: !0 }));
} }
function s() { function l() {
!t || e.size || (t = !1, r.disconnect()); !t || e.size || (t = !1, r.disconnect());
} }
function f() { function f() {
@ -215,30 +217,30 @@ function H() {
(requestIdleCallback || requestAnimationFrame)(o); (requestIdleCallback || requestAnimationFrame)(o);
}); });
} }
async function h(o) { async function u(o) {
e.size > 30 && await f(); e.size > 30 && await f();
let i = []; let s = [];
if (!(o instanceof Node)) if (!(o instanceof Node))
return i; return s;
for (let u of e.keys()) for (let i of e.keys())
u === o || !(u instanceof Node) || o.contains(u) && i.push(u); i === o || !(i instanceof Node) || o.contains(i) && s.push(i);
return i; return s;
} }
function x(o, i) { function h(o, s) {
for (let u of o) { for (let i of o) {
if (i && h(u).then(x), !e.has(u)) if (s && u(i).then(h), !e.has(i))
continue; continue;
let d = e.get(u); let a = e.get(i);
return d.connected.forEach((C) => C(u)), d.connected.length = 0, d.disconnected.length || e.delete(u), !0; return a.connected.forEach((A) => A(i)), a.connected.length = 0, a.disconnected.length || e.delete(i), !0;
} }
return !1; return !1;
} }
function E(o, i) { function E(o, s) {
for (let u of o) { for (let i of o) {
if (i && h(u).then(E), !e.has(u)) if (s && u(i).then(E), !e.has(i))
continue; continue;
let d = e.get(u); let a = e.get(i);
return d.disconnected.forEach((C) => C(u)), d.connected.length = 0, d.disconnected.length = 0, e.delete(u), !0; return a.disconnected.forEach((A) => A(i)), a.connected.length = 0, a.disconnected.length = 0, e.delete(i), !0;
} }
return !1; return !1;
} }
@ -252,13 +254,13 @@ function H() {
}; };
}); });
export { export {
b as assign, x as assign,
P as classListDeclarative, j as classListDeclarative,
$ as createElement, Z as createElement,
W as dispatchEvent, J as dispatchEvent,
$ as el, Z as el,
G as empty, G as empty,
Z as namespace, I as namespace,
R as on, S as on,
_ as registerReactivity y as registerReactivity
}; };

View File

@ -1,6 +1,6 @@
{ {
"name": "deka-dom-el", "name": "deka-dom-el",
"version": "0.2.2", "version": "0.3.0",
"description": "A low-code library that simplifies the creation of native DOM elements/components using small wrappers and tweaks.", "description": "A low-code library that simplifies the creation of native DOM elements/components using small wrappers and tweaks.",
"author": "Jan Andrle <andrle.jan@centrum.cz>", "author": "Jan Andrle <andrle.jan@centrum.cz>",
"license": "MIT", "license": "MIT",

View File

@ -1,5 +1,3 @@
/** @type {Map<string, boolean>} */
export const prop_cache= new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]'));
export const prop_process= { setDeleteAttr }; export const prop_process= { setDeleteAttr };
import { isUndef } from './helpers.js'; import { isUndef } from './helpers.js';
function setDeleteAttr(obj, prop, val){ function setDeleteAttr(obj, prop, val){
@ -13,6 +11,9 @@ function setDeleteAttr(obj, prop, val){
4. Point 2. with checks for coincidence (e.g. use special string) 4. Point 2. with checks for coincidence (e.g. use special string)
*/ */
Reflect.set(obj, prop, val); Reflect.set(obj, prop, val);
if(isUndef(val) && obj.getAttribute(prop)==="undefined") if(!isUndef(val)) return;
obj.removeAttribute(prop); if(obj instanceof HTMLElement && obj.getAttribute(prop)==="undefined")
return obj.removeAttribute(prop);
if(Reflect.get(obj, prop)==="undefined")
return Reflect.set(obj, prop, "");
} }

View File

@ -17,7 +17,7 @@ export function createElement(tag, attributes, ...connect){
const s= signals(this); const s= signals(this);
let el; let el;
//TODO Array.isArray(tag) ⇒ set key (cache els) //TODO Array.isArray(tag) ⇒ set key (cache els)
if(s.isTextContent(attributes)) if(Object(attributes)!==attributes || s.isSignal(attributes))
attributes= { textContent: attributes }; attributes= { textContent: attributes };
switch(true){ switch(true){
case typeof tag==="function": { case typeof tag==="function": {
@ -35,40 +35,39 @@ export function createElement(tag, attributes, ...connect){
} }
export { createElement as el }; export { createElement as el };
import { prop_cache, prop_process } from './dom-common.js'; import { prop_process } from './dom-common.js';
const { setDeleteAttr }= prop_process; const { setDeleteAttr }= prop_process;
export function assign(element, ...attributes){ export function assign(element, ...attributes){
const _this= this;
const s= signals(this); const s= signals(this);
if(!attributes.length) return element; if(!attributes.length) return element;
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:17 */ /* jshint maxcomplexity:20 */
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){ if(typeof attr === "object" && attr!==null && !Array.isArray(attr)){
switch(key){ switch(key){
case "style": return forEachEntries(attr, setRemove.bind(null, element.style, "Property")); case "style" || "dataset": return forEachEntries(s, attr, setDelete.bind(null, element[key]));
case "dataset": return forEachEntries(attr, setDelete.bind(null, element.dataset)); case "ariaset": return forEachEntries(s, attr, (key, val)=> setRemoveAttr("aria-"+key, val));
case "ariaset": return forEachEntries(attr, (key, val)=> setRemoveAttr("aria-"+key, val)); case "classList": return classListDeclarative.call(_this, element, attr);
case "classList": return classListDeclarative(element, attr); default: return Reflect.set(element, key, 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);
} }
if("className"===key) key= "class";
switch(key){ switch(key){
case "href" || "src": case "href" || "src" || "class" || "xlink:href":
return setRemoveAttr(key, attr);
case "xlink:href":
return setRemoveAttr(key, attr, "http://www.w3.org/1999/xlink"); return setRemoveAttr(key, attr, "http://www.w3.org/1999/xlink");
case "textContent" || "innerText": case "textContent" || "innerText":
if(!is_svg) break; if(!is_svg) return setDeleteAttr(element, key, attr);
return element.appendChild(document.createTextNode(attr)); return element.appendChild(document.createTextNode(attr));
} }
return isPropSetter(element, key) ? setDeleteAttr(element, key, attr) : setRemoveAttr(key, attr); return isPropSetter(element, key) ? setDeleteAttr(element, key, attr) : setRemoveAttr(key, attr);
@ -76,9 +75,10 @@ export function assign(element, ...attributes){
return element; return element;
} }
export function classListDeclarative(element, toggle){ export function classListDeclarative(element, toggle){
const s= signals(this);
if(typeof toggle !== "object") return element; if(typeof toggle !== "object") return element;
forEachEntries(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)));
return element; return element;
@ -89,28 +89,28 @@ export function empty(el){
} }
import { isUndef } from "./helpers.js"; import { isUndef } from "./helpers.js";
function isPropSetter(el, key){ function isPropSetter(el, key){
const cache_key_he= "HTMLElement,"+key; if(!Reflect.has(el, key)) return false;
if(el instanceof HTMLElement && prop_cache.has(cache_key_he)) const des= getPropDescriptor(el, key);
return prop_cache.get(cache_key_he); return !isUndef(des.set);
const cache_key= el.nodeName+","+key;
if(prop_cache.has(cache_key)) return prop_cache.get(cache_key);
const [ des, level, p ]= getPropDescriptor(el, key);
const is_set= !isUndef(des.set);
if(!is_set || level)
prop_cache.set(p===HTMLElement.prototype ? cache_key_he : cache_key, is_set);
return is_set;
} }
function getPropDescriptor(p, key, level= 0){ function getPropDescriptor(p, key, level= 0){
p= Object.getPrototypeOf(p); p= Object.getPrototypeOf(p);
if(!p) return [ {}, level, p ]; if(!p) return {};
const des= Object.getOwnPropertyDescriptor(p, key); const des= Object.getOwnPropertyDescriptor(p, key);
if(!des) return getPropDescriptor(p, key, level+1); if(!des) return getPropDescriptor(p, key, level+1);
return [ des, level, p ]; return des;
} }
/** @template {Record<any, any>} T @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(obj, cb){ return Object.entries(obj).forEach(([ key, val ])=> key && cb(key, val)); } function forEachEntries(s, obj, cb){
return Object.entries(obj).forEach(function process([ key, val ]){
if(!key) return;
val= s.processReactiveAttribute(obj, key, val, a=> cb(...a));
cb(key, val);
});
}
function setRemove(obj, prop, key, val){ return obj[ (isUndef(val) ? "remove" : "set") + prop ](key, val); } function attrArrToStr(attr){ return Array.isArray(attr) ? attr.filter(Boolean).join(" ") : attr; }
function setRemoveNS(obj, prop, key, val, ns= null){ return obj[ (isUndef(val) ? "remove" : "set") + prop + "NS" ](ns, key, val); } function setRemove(obj, prop, key, val){ return obj[ (isUndef(val) ? "remove" : "set") + prop ](key, attrArrToStr(val)); }
function setRemoveNS(obj, prop, key, val, ns= null){ return obj[ (isUndef(val) ? "remove" : "set") + prop + "NS" ](ns, key, attrArrToStr(val)); }
function setDelete(obj, key, val){ Reflect.set(obj, key, val); if(!isUndef(val)) return; return Reflect.deleteProperty(obj, key); } function setDelete(obj, key, val){ Reflect.set(obj, key, val); if(!isUndef(val)) return; return Reflect.deleteProperty(obj, key); }

View File

@ -1,6 +1,6 @@
export const signals_global= { export const signals_global= {
isTextContent(attributes){ return typeof attributes==="string"; }, isSignal(attributes){ return false; },
processReactiveAttribute(el, key, attr, assignNth){ return attr; }, processReactiveAttribute(obj, key, attr, assignNth){ return attr; },
}; };
export function registerReactivity(def, global= true){ export function registerReactivity(def, global= true){
if(global) return Object.assign(signals_global, def); if(global) return Object.assign(signals_global, def);

View File

@ -84,9 +84,7 @@ S.el= function(signal, map){
import { typeOf } from './helpers.js'; import { typeOf } from './helpers.js';
export const signals_config= { export const signals_config= {
isTextContent(attributes){ isSignal,
return typeOf(attributes)==="string" || ( isSignal(attributes) && typeOf(valueOfSignal(attributes))==="string" );
},
processReactiveAttribute(_, key, attrs, assignNth){ processReactiveAttribute(_, key, attrs, assignNth){
//TODO DOC: once the signal is used as attribute, there is no reason to use assign again (if for some reason needed, use imperative listeners clear with `S.clear`) //TODO DOC: once the signal is used as attribute, there is no reason to use assign again (if for some reason needed, use imperative listeners clear with `S.clear`)
if(!isSignal(attrs)) return attrs; if(!isSignal(attrs)) return attrs;

View File

@ -21,7 +21,7 @@ export function fullNameComponent(){
), ),
el("p").append( el("p").append(
el("strong", "Full name"), el("strong", "Full name"),
el("#text", ": "), ": ",
el("#text", full_name) el("#text", full_name)
) )
); );

View File

@ -1,7 +1,7 @@
import * as dde_dom from "../index.js"; import * as dde_dom from "../index.js";
export * from "../index.js"; export * from "../index.js";
import * as dde_s from "../src/signals.js"; import * as dde_s from "../signals.js";
export * from "../src/signals.js"; export * from "../signals.js";
// import { empty, namespace, on, dispatch } from "../index.js"; // import { empty, namespace, on, dispatch } from "../index.js";
// import "../dist/dde-with-signals.js"; // import "../dist/dde-with-signals.js";
// Object.assign(globalThis, dde); // Object.assign(globalThis, dde);