1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2024-11-22 07:49:38 +01:00

🐛 el leave scope correctly

This commit is contained in:
Jan Andrle 2023-10-13 17:13:03 +02:00
parent 06ab87c06f
commit 4c571354c4
Signed by: jaandrle
GPG Key ID: B3A25AED155AFFAB
6 changed files with 270 additions and 268 deletions

View File

@ -77,25 +77,25 @@
} }
}; };
function ie(e, t, ...n) { function ie(e, t, ...n) {
let r = this, o = x(this), { namespace: c } = E, a; let r = this, o = x(this), { namespace: c } = E, d = !1, s;
switch ((Object(t) !== t || o.isSignal(t)) && (t = { textContent: t }), !0) { switch ((Object(t) !== t || o.isSignal(t)) && (t = { textContent: t }), !0) {
case typeof e == "function": { case typeof e == "function": {
E.push({ scope: e, host: (s) => s ? (n.unshift(s), void 0) : a }), a = e(t || void 0), E.pop(); d = !0, E.push({ scope: e, host: (f) => f ? (n.unshift(f), void 0) : s }), s = e(t || void 0);
break; break;
} }
case e === "#text": case e === "#text":
a = O.call(r, document.createTextNode(""), t); s = O.call(r, document.createTextNode(""), t);
break; break;
case e === "<>": case e === "<>":
a = O.call(r, document.createDocumentFragment(), t); s = O.call(r, document.createDocumentFragment(), t);
break; break;
case c !== "html": case c !== "html":
a = O.call(r, document.createElementNS(c, e), t); s = O.call(r, document.createElementNS(c, e), t);
break; break;
case !a: case !s:
a = O.call(r, document.createElement(e), t); s = O.call(r, document.createElement(e), t);
} }
return n.forEach((s) => s(a)), a; return n.forEach((f) => f(s)), d && E.pop(), s;
} }
var { setDeleteAttr: M } = T; var { setDeleteAttr: M } = T;
function O(e, ...t) { function O(e, ...t) {
@ -103,31 +103,31 @@
if (!t.length) if (!t.length)
return e; return e;
let c = (e instanceof SVGElement ? J : I).bind(null, e, "Attribute"); let c = (e instanceof SVGElement ? J : I).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function a([s, d]) { return Object.entries(Object.assign({}, ...t)).forEach(function d([s, f]) {
d = r.processReactiveAttribute(e, s, d, a); f = r.processReactiveAttribute(e, s, f, d);
let [m] = s; let [m] = s;
if (m === "=") if (m === "=")
return c(s.slice(1), d); return c(s.slice(1), f);
if (m === ".") if (m === ".")
return F(e, s.slice(1), d); return F(e, s.slice(1), f);
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(), c(s, d); return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), c(s, f);
switch (s === "className" && (s = "class"), s) { switch (s === "className" && (s = "class"), s) {
case "xlink:href": case "xlink:href":
return c(s, d, "http://www.w3.org/1999/xlink"); return c(s, f, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
return M(e, s, d); return M(e, s, f);
case "style": case "style":
if (typeof d != "object") if (typeof f != "object")
break; break;
case "dataset": case "dataset":
return D(r, d, F.bind(null, e[s])); return D(r, f, F.bind(null, e[s]));
case "ariaset": case "ariaset":
return D(r, d, (b, i) => c("aria-" + b, i)); return D(r, f, (b, i) => c("aria-" + b, i));
case "classList": case "classList":
return B.call(n, e, d); return B.call(n, e, f);
} }
return G(e, s) ? M(e, s, d) : c(s, d); return G(e, s) ? M(e, s, f) : c(s, f);
}), e; }), e;
} }
function B(e, t) { function B(e, t) {
@ -156,7 +156,7 @@
function D(e, t, n) { function D(e, t, n) {
if (!(typeof t != "object" || t === null)) if (!(typeof t != "object" || t === null))
return Object.entries(t).forEach(function([o, c]) { return Object.entries(t).forEach(function([o, c]) {
o && (c = e.processReactiveAttribute(t, o, c, (a) => n(...a)), n(o, c)); o && (c = e.processReactiveAttribute(t, o, c, (d) => n(...d)), n(o, c));
}); });
} }
function U(e) { function U(e) {
@ -204,13 +204,13 @@
let c = "dde:" + n; let c = "dde:" + n;
if (o.addEventListener(c, e, t), o.__dde_lifecycleToEvents || V.has(o)) if (o.addEventListener(c, e, t), o.__dde_lifecycleToEvents || V.has(o))
return o; return o;
let a = new MutationObserver(function(d) { let d = new MutationObserver(function(f) {
for (let { attributeName: m, target: b } of d) for (let { attributeName: m, target: b } of f)
b.dispatchEvent( b.dispatchEvent(
new CustomEvent(c, { detail: [m, b.getAttribute(m)] }) new CustomEvent(c, { detail: [m, b.getAttribute(m)] })
); );
}); });
return A(t.signal, () => a.disconnect()) && a.observe(o, { attributes: !0 }), o; return A(t.signal, () => d.disconnect()) && d.observe(o, { attributes: !0 }), o;
}; };
}; };
function Z() { function Z() {
@ -218,38 +218,38 @@
for (let u of i) for (let u of i)
if (u.type === "childList") { if (u.type === "childList") {
if (m(u.addedNodes, !0)) { if (m(u.addedNodes, !0)) {
a(); d();
continue; continue;
} }
b(u.removedNodes, !0) && a(); b(u.removedNodes, !0) && d();
} }
}); });
return { return {
onConnected(i, u) { onConnected(i, u) {
c(); c();
let f = o(i); let a = o(i);
f.connected.has(u) || (f.connected.add(u), f.length_c += 1); a.connected.has(u) || (a.connected.add(u), a.length_c += 1);
}, },
offConnected(i, u) { offConnected(i, u) {
if (!e.has(i)) if (!e.has(i))
return; return;
let f = e.get(i); let a = e.get(i);
f.connected.has(u) && (f.connected.delete(u), f.length_c -= 1, r(i, f)); a.connected.has(u) && (a.connected.delete(u), a.length_c -= 1, r(i, a));
}, },
onDisconnected(i, u) { onDisconnected(i, u) {
c(); c();
let f = o(i); let a = o(i);
f.disconnected.has(u) || (f.disconnected.add(u), f.length_d += 1); a.disconnected.has(u) || (a.disconnected.add(u), a.length_d += 1);
}, },
offDisconnected(i, u) { offDisconnected(i, u) {
if (!e.has(i)) if (!e.has(i))
return; return;
let f = e.get(i); let a = e.get(i);
f.disconnected.has(u) && (f.disconnected.delete(u), f.length_d -= 1, r(i, f)); a.disconnected.has(u) && (a.disconnected.delete(u), a.length_d -= 1, r(i, a));
} }
}; };
function r(i, u) { function r(i, u) {
u.length_c || u.length_d || (e.delete(i), a()); u.length_c || u.length_d || (e.delete(i), d());
} }
function o(i) { function o(i) {
if (e.has(i)) if (e.has(i))
@ -265,7 +265,7 @@
function c() { function c() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
} }
function a() { function d() {
!t || e.size || (t = !1, n.disconnect()); !t || e.size || (t = !1, n.disconnect());
} }
function s() { function s() {
@ -273,30 +273,30 @@
(requestIdleCallback || requestAnimationFrame)(i); (requestIdleCallback || requestAnimationFrame)(i);
}); });
} }
async function d(i) { async function f(i) {
e.size > 30 && await s(); e.size > 30 && await s();
let u = []; let u = [];
if (!(i instanceof Node)) if (!(i instanceof Node))
return u; return u;
for (let f of e.keys()) for (let a of e.keys())
f === i || !(f instanceof Node) || i.contains(f) && u.push(f); a === i || !(a instanceof Node) || i.contains(a) && u.push(a);
return u; return u;
} }
function m(i, u) { function m(i, u) {
let f = !1; let a = !1;
for (let p of i) { for (let p of i) {
if (u && d(p).then(m), !e.has(p)) if (u && f(p).then(m), !e.has(p))
continue; continue;
let _ = e.get(p); let _ = e.get(p);
_.length_c && (p.dispatchEvent(new Event("dde:connected")), _.connected = /* @__PURE__ */ new WeakSet(), _.length_c = 0, _.length_d || e.delete(p), f = !0); _.length_c && (p.dispatchEvent(new Event("dde:connected")), _.connected = /* @__PURE__ */ new WeakSet(), _.length_c = 0, _.length_d || e.delete(p), a = !0);
} }
return f; return a;
} }
function b(i, u) { function b(i, u) {
let f = !1; let a = !1;
for (let p of i) for (let p of i)
u && d(p).then(b), !(!e.has(p) || !e.get(p).length_d) && (p.dispatchEvent(new Event("dde:disconnected")), e.delete(p), f = !0); u && f(p).then(b), !(!e.has(p) || !e.get(p).length_d) && (p.dispatchEvent(new Event("dde:disconnected")), e.delete(p), a = !0);
return f; return a;
} }
} }
@ -352,9 +352,9 @@
o.abort(); o.abort();
} }
}); });
return E.host(S.attributeChanged(function({ detail: a }) { return E.host(S.attributeChanged(function({ detail: d }) {
let [s, d] = a; let [s, f] = d;
s === e && c(d); s === e && c(f);
}, { signal: o.signal })), c; }, { signal: o.signal })), c;
}; };
h.clear = function(...e) { h.clear = function(...e) {
@ -375,14 +375,14 @@
h.el = function(e, t) { h.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 c = (a) => { let c = (d) => {
if (!n.parentNode || !r.parentNode) if (!n.parentNode || !r.parentNode)
return H(e, c); return H(e, c);
let s = t(a); let s = t(d);
Array.isArray(s) || (s = [s]); Array.isArray(s) || (s = [s]);
let d = n; let f = n;
for (; (d = n.nextSibling) !== r; ) for (; (f = n.nextSibling) !== r; )
d.remove(); f.remove();
n.after(...s); n.after(...s);
}; };
return P(e, c), c(e()), o; return P(e, c), c(e()), o;

158
dist/dde.js vendored
View File

@ -5,7 +5,7 @@
isSignal(e) { isSignal(e) {
return !1; return !1;
}, },
processReactiveAttribute(e, t, n, s) { processReactiveAttribute(e, t, n, i) {
return n; return n;
} }
}; };
@ -73,57 +73,57 @@
} }
}; };
function V(e, t, ...n) { function V(e, t, ...n) {
let s = this, r = b(this), { namespace: f } = x, a; let i = this, r = b(this), { namespace: f } = x, d = !1, o;
switch ((Object(t) !== t || r.isSignal(t)) && (t = { textContent: t }), !0) { switch ((Object(t) !== t || r.isSignal(t)) && (t = { textContent: t }), !0) {
case typeof e == "function": { case typeof e == "function": {
x.push({ scope: e, host: (u) => u ? (n.unshift(u), void 0) : a }), a = e(t || void 0), x.pop(); d = !0, x.push({ scope: e, host: (a) => a ? (n.unshift(a), void 0) : o }), o = e(t || void 0);
break; break;
} }
case e === "#text": case e === "#text":
a = w.call(s, document.createTextNode(""), t); o = w.call(i, document.createTextNode(""), t);
break; break;
case e === "<>": case e === "<>":
a = w.call(s, document.createDocumentFragment(), t); o = w.call(i, document.createDocumentFragment(), t);
break; break;
case f !== "html": case f !== "html":
a = w.call(s, document.createElementNS(f, e), t); o = w.call(i, document.createElementNS(f, e), t);
break; break;
case !a: case !o:
a = w.call(s, document.createElement(e), t); o = w.call(i, document.createElement(e), t);
} }
return n.forEach((u) => u(a)), a; return n.forEach((a) => a(o)), d && x.pop(), o;
} }
var { setDeleteAttr: S } = C; var { setDeleteAttr: S } = C;
function w(e, ...t) { function w(e, ...t) {
let n = this, s = b(this); let n = this, i = b(this);
if (!t.length) if (!t.length)
return e; return e;
let f = (e instanceof SVGElement ? F : W).bind(null, e, "Attribute"); let f = (e instanceof SVGElement ? F : W).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function a([u, d]) { return Object.entries(Object.assign({}, ...t)).forEach(function d([o, a]) {
d = s.processReactiveAttribute(e, u, d, a); a = i.processReactiveAttribute(e, o, a, d);
let [h] = u; let [l] = o;
if (h === "=") if (l === "=")
return f(u.slice(1), d); return f(o.slice(1), a);
if (h === ".") if (l === ".")
return L(e, u.slice(1), d); return L(e, o.slice(1), a);
if (/(aria|data)([A-Z])/.test(u)) if (/(aria|data)([A-Z])/.test(o))
return u = u.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), f(u, d); return o = o.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), f(o, a);
switch (u === "className" && (u = "class"), u) { switch (o === "className" && (o = "class"), o) {
case "xlink:href": case "xlink:href":
return f(u, d, "http://www.w3.org/1999/xlink"); return f(o, a, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
return S(e, u, d); return S(e, o, a);
case "style": case "style":
if (typeof d != "object") if (typeof a != "object")
break; break;
case "dataset": case "dataset":
return O(s, d, L.bind(null, e[u])); return O(i, a, L.bind(null, e[o]));
case "ariaset": case "ariaset":
return O(s, d, (l, c) => f("aria-" + l, c)); return O(i, a, (h, c) => f("aria-" + h, c));
case "classList": case "classList":
return T.call(n, e, d); return T.call(n, e, a);
} }
return M(e, u) ? S(e, u, d) : f(u, d); return M(e, o) ? S(e, o, a) : f(o, a);
}), e; }), e;
} }
function T(e, t) { function T(e, t) {
@ -131,7 +131,7 @@
return O( return O(
n, n,
t, t,
(s, r) => e.classList.toggle(s, r === -1 ? void 0 : !!r) (i, r) => e.classList.toggle(i, r === -1 ? void 0 : !!r)
), e; ), e;
} }
function $(e) { function $(e) {
@ -152,17 +152,17 @@
function O(e, t, n) { function O(e, t, n) {
if (!(typeof t != "object" || t === null)) if (!(typeof t != "object" || t === null))
return Object.entries(t).forEach(function([r, f]) { return Object.entries(t).forEach(function([r, f]) {
r && (f = e.processReactiveAttribute(t, r, f, (a) => n(...a)), n(r, f)); r && (f = e.processReactiveAttribute(t, r, f, (d) => n(...d)), n(r, f));
}); });
} }
function N(e) { function N(e) {
return Array.isArray(e) ? e.filter(Boolean).join(" ") : e; return Array.isArray(e) ? e.filter(Boolean).join(" ") : e;
} }
function W(e, t, n, s) { function W(e, t, n, i) {
return e[(g(s) ? "remove" : "set") + t](n, N(s)); return e[(g(i) ? "remove" : "set") + t](n, N(i));
} }
function F(e, t, n, s, r = null) { function F(e, t, n, i, r = null) {
return e[(g(s) ? "remove" : "set") + t + "NS"](r, n, N(s)); return e[(g(i) ? "remove" : "set") + t + "NS"](r, n, N(i));
} }
function L(e, t, n) { function L(e, t, n) {
if (Reflect.set(e, t, n), !!g(n)) if (Reflect.set(e, t, n), !!g(n))
@ -171,8 +171,8 @@
// src/events.js // src/events.js
function Q(e, t, ...n) { function Q(e, t, ...n) {
let s = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); let i = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t);
return e.dispatchEvent(s); return e.dispatchEvent(i);
} }
function y(e, t, n) { function y(e, t, n) {
return function(r) { return function(r) {
@ -200,99 +200,99 @@
let f = "dde:" + n; let f = "dde:" + n;
if (r.addEventListener(f, e, t), r.__dde_lifecycleToEvents || U.has(r)) if (r.addEventListener(f, e, t), r.__dde_lifecycleToEvents || U.has(r))
return r; return r;
let a = new MutationObserver(function(d) { let d = new MutationObserver(function(a) {
for (let { attributeName: h, target: l } of d) for (let { attributeName: l, target: h } of a)
l.dispatchEvent( h.dispatchEvent(
new CustomEvent(f, { detail: [h, l.getAttribute(h)] }) new CustomEvent(f, { detail: [l, h.getAttribute(l)] })
); );
}); });
return _(t.signal, () => a.disconnect()) && a.observe(r, { attributes: !0 }), r; return _(t.signal, () => d.disconnect()) && d.observe(r, { attributes: !0 }), r;
}; };
}; };
function q() { function q() {
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 o of c) for (let s of c)
if (o.type === "childList") { if (s.type === "childList") {
if (h(o.addedNodes, !0)) { if (l(s.addedNodes, !0)) {
a(); d();
continue; continue;
} }
l(o.removedNodes, !0) && a(); h(s.removedNodes, !0) && d();
} }
}); });
return { return {
onConnected(c, o) { onConnected(c, s) {
f(); f();
let i = r(c); let u = r(c);
i.connected.has(o) || (i.connected.add(o), i.length_c += 1); u.connected.has(s) || (u.connected.add(s), u.length_c += 1);
}, },
offConnected(c, o) { offConnected(c, s) {
if (!e.has(c)) if (!e.has(c))
return; return;
let i = e.get(c); let u = e.get(c);
i.connected.has(o) && (i.connected.delete(o), i.length_c -= 1, s(c, i)); u.connected.has(s) && (u.connected.delete(s), u.length_c -= 1, i(c, u));
}, },
onDisconnected(c, o) { onDisconnected(c, s) {
f(); f();
let i = r(c); let u = r(c);
i.disconnected.has(o) || (i.disconnected.add(o), i.length_d += 1); u.disconnected.has(s) || (u.disconnected.add(s), u.length_d += 1);
}, },
offDisconnected(c, o) { offDisconnected(c, s) {
if (!e.has(c)) if (!e.has(c))
return; return;
let i = e.get(c); let u = e.get(c);
i.disconnected.has(o) && (i.disconnected.delete(o), i.length_d -= 1, s(c, i)); u.disconnected.has(s) && (u.disconnected.delete(s), u.length_d -= 1, i(c, u));
} }
}; };
function s(c, o) { function i(c, s) {
o.length_c || o.length_d || (e.delete(c), a()); s.length_c || s.length_d || (e.delete(c), d());
} }
function r(c) { function r(c) {
if (e.has(c)) if (e.has(c))
return e.get(c); return e.get(c);
let o = { let s = {
connected: /* @__PURE__ */ new WeakSet(), connected: /* @__PURE__ */ new WeakSet(),
length_c: 0, length_c: 0,
disconnected: /* @__PURE__ */ new WeakSet(), disconnected: /* @__PURE__ */ new WeakSet(),
length_d: 0 length_d: 0
}; };
return e.set(c, o), o; return e.set(c, s), s;
} }
function f() { function f() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
} }
function a() { function d() {
!t || e.size || (t = !1, n.disconnect()); !t || e.size || (t = !1, n.disconnect());
} }
function u() { function o() {
return new Promise(function(c) { return new Promise(function(c) {
(requestIdleCallback || requestAnimationFrame)(c); (requestIdleCallback || requestAnimationFrame)(c);
}); });
} }
async function d(c) { async function a(c) {
e.size > 30 && await u(); e.size > 30 && await o();
let o = []; let s = [];
if (!(c instanceof Node)) if (!(c instanceof Node))
return o; return s;
for (let i of e.keys()) for (let u of e.keys())
i === c || !(i instanceof Node) || c.contains(i) && o.push(i); u === c || !(u instanceof Node) || c.contains(u) && s.push(u);
return o; return s;
} }
function h(c, o) { function l(c, s) {
let i = !1; let u = !1;
for (let p of c) { for (let p of c) {
if (o && d(p).then(h), !e.has(p)) if (s && a(p).then(l), !e.has(p))
continue; continue;
let v = e.get(p); let v = e.get(p);
v.length_c && (p.dispatchEvent(new Event("dde:connected")), v.connected = /* @__PURE__ */ new WeakSet(), v.length_c = 0, v.length_d || e.delete(p), i = !0); v.length_c && (p.dispatchEvent(new Event("dde:connected")), v.connected = /* @__PURE__ */ new WeakSet(), v.length_c = 0, v.length_d || e.delete(p), u = !0);
} }
return i; return u;
} }
function l(c, o) { function h(c, s) {
let i = !1; let u = !1;
for (let p of c) for (let p of c)
o && d(p).then(l), !(!e.has(p) || !e.get(p).length_d) && (p.dispatchEvent(new Event("dde:disconnected")), e.delete(p), i = !0); s && a(p).then(h), !(!e.has(p) || !e.get(p).length_d) && (p.dispatchEvent(new Event("dde:disconnected")), e.delete(p), u = !0);
return i; return u;
} }
} }

View File

@ -75,25 +75,25 @@ var y = [{ scope: document.body, namespace: "html", host: (e) => e ? e(document.
} }
}; };
function ie(e, t, ...n) { function ie(e, t, ...n) {
let r = this, o = x(this), { namespace: c } = E, a; let r = this, o = x(this), { namespace: c } = E, d = !1, s;
switch ((Object(t) !== t || o.isSignal(t)) && (t = { textContent: t }), !0) { switch ((Object(t) !== t || o.isSignal(t)) && (t = { textContent: t }), !0) {
case typeof e == "function": { case typeof e == "function": {
E.push({ scope: e, host: (s) => s ? (n.unshift(s), void 0) : a }), a = e(t || void 0), E.pop(); d = !0, E.push({ scope: e, host: (f) => f ? (n.unshift(f), void 0) : s }), s = e(t || void 0);
break; break;
} }
case e === "#text": case e === "#text":
a = O.call(r, document.createTextNode(""), t); s = O.call(r, document.createTextNode(""), t);
break; break;
case e === "<>": case e === "<>":
a = O.call(r, document.createDocumentFragment(), t); s = O.call(r, document.createDocumentFragment(), t);
break; break;
case c !== "html": case c !== "html":
a = O.call(r, document.createElementNS(c, e), t); s = O.call(r, document.createElementNS(c, e), t);
break; break;
case !a: case !s:
a = O.call(r, document.createElement(e), t); s = O.call(r, document.createElement(e), t);
} }
return n.forEach((s) => s(a)), a; return n.forEach((f) => f(s)), d && E.pop(), s;
} }
var { setDeleteAttr: M } = T; var { setDeleteAttr: M } = T;
function O(e, ...t) { function O(e, ...t) {
@ -101,31 +101,31 @@ function O(e, ...t) {
if (!t.length) if (!t.length)
return e; return e;
let c = (e instanceof SVGElement ? J : I).bind(null, e, "Attribute"); let c = (e instanceof SVGElement ? J : I).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function a([s, d]) { return Object.entries(Object.assign({}, ...t)).forEach(function d([s, f]) {
d = r.processReactiveAttribute(e, s, d, a); f = r.processReactiveAttribute(e, s, f, d);
let [m] = s; let [m] = s;
if (m === "=") if (m === "=")
return c(s.slice(1), d); return c(s.slice(1), f);
if (m === ".") if (m === ".")
return F(e, s.slice(1), d); return F(e, s.slice(1), f);
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(), c(s, d); return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), c(s, f);
switch (s === "className" && (s = "class"), s) { switch (s === "className" && (s = "class"), s) {
case "xlink:href": case "xlink:href":
return c(s, d, "http://www.w3.org/1999/xlink"); return c(s, f, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
return M(e, s, d); return M(e, s, f);
case "style": case "style":
if (typeof d != "object") if (typeof f != "object")
break; break;
case "dataset": case "dataset":
return D(r, d, F.bind(null, e[s])); return D(r, f, F.bind(null, e[s]));
case "ariaset": case "ariaset":
return D(r, d, (b, i) => c("aria-" + b, i)); return D(r, f, (b, i) => c("aria-" + b, i));
case "classList": case "classList":
return B.call(n, e, d); return B.call(n, e, f);
} }
return G(e, s) ? M(e, s, d) : c(s, d); return G(e, s) ? M(e, s, f) : c(s, f);
}), e; }), e;
} }
function B(e, t) { function B(e, t) {
@ -154,7 +154,7 @@ function z(e, t) {
function D(e, t, n) { function D(e, t, n) {
if (!(typeof t != "object" || t === null)) if (!(typeof t != "object" || t === null))
return Object.entries(t).forEach(function([o, c]) { return Object.entries(t).forEach(function([o, c]) {
o && (c = e.processReactiveAttribute(t, o, c, (a) => n(...a)), n(o, c)); o && (c = e.processReactiveAttribute(t, o, c, (d) => n(...d)), n(o, c));
}); });
} }
function U(e) { function U(e) {
@ -202,13 +202,13 @@ S.attributeChanged = function(e, t) {
let c = "dde:" + n; let c = "dde:" + n;
if (o.addEventListener(c, e, t), o.__dde_lifecycleToEvents || V.has(o)) if (o.addEventListener(c, e, t), o.__dde_lifecycleToEvents || V.has(o))
return o; return o;
let a = new MutationObserver(function(d) { let d = new MutationObserver(function(f) {
for (let { attributeName: m, target: b } of d) for (let { attributeName: m, target: b } of f)
b.dispatchEvent( b.dispatchEvent(
new CustomEvent(c, { detail: [m, b.getAttribute(m)] }) new CustomEvent(c, { detail: [m, b.getAttribute(m)] })
); );
}); });
return A(t.signal, () => a.disconnect()) && a.observe(o, { attributes: !0 }), o; return A(t.signal, () => d.disconnect()) && d.observe(o, { attributes: !0 }), o;
}; };
}; };
function Z() { function Z() {
@ -216,38 +216,38 @@ function Z() {
for (let u of i) for (let u of i)
if (u.type === "childList") { if (u.type === "childList") {
if (m(u.addedNodes, !0)) { if (m(u.addedNodes, !0)) {
a(); d();
continue; continue;
} }
b(u.removedNodes, !0) && a(); b(u.removedNodes, !0) && d();
} }
}); });
return { return {
onConnected(i, u) { onConnected(i, u) {
c(); c();
let f = o(i); let a = o(i);
f.connected.has(u) || (f.connected.add(u), f.length_c += 1); a.connected.has(u) || (a.connected.add(u), a.length_c += 1);
}, },
offConnected(i, u) { offConnected(i, u) {
if (!e.has(i)) if (!e.has(i))
return; return;
let f = e.get(i); let a = e.get(i);
f.connected.has(u) && (f.connected.delete(u), f.length_c -= 1, r(i, f)); a.connected.has(u) && (a.connected.delete(u), a.length_c -= 1, r(i, a));
}, },
onDisconnected(i, u) { onDisconnected(i, u) {
c(); c();
let f = o(i); let a = o(i);
f.disconnected.has(u) || (f.disconnected.add(u), f.length_d += 1); a.disconnected.has(u) || (a.disconnected.add(u), a.length_d += 1);
}, },
offDisconnected(i, u) { offDisconnected(i, u) {
if (!e.has(i)) if (!e.has(i))
return; return;
let f = e.get(i); let a = e.get(i);
f.disconnected.has(u) && (f.disconnected.delete(u), f.length_d -= 1, r(i, f)); a.disconnected.has(u) && (a.disconnected.delete(u), a.length_d -= 1, r(i, a));
} }
}; };
function r(i, u) { function r(i, u) {
u.length_c || u.length_d || (e.delete(i), a()); u.length_c || u.length_d || (e.delete(i), d());
} }
function o(i) { function o(i) {
if (e.has(i)) if (e.has(i))
@ -263,7 +263,7 @@ function Z() {
function c() { function c() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
} }
function a() { function d() {
!t || e.size || (t = !1, n.disconnect()); !t || e.size || (t = !1, n.disconnect());
} }
function s() { function s() {
@ -271,30 +271,30 @@ function Z() {
(requestIdleCallback || requestAnimationFrame)(i); (requestIdleCallback || requestAnimationFrame)(i);
}); });
} }
async function d(i) { async function f(i) {
e.size > 30 && await s(); e.size > 30 && await s();
let u = []; let u = [];
if (!(i instanceof Node)) if (!(i instanceof Node))
return u; return u;
for (let f of e.keys()) for (let a of e.keys())
f === i || !(f instanceof Node) || i.contains(f) && u.push(f); a === i || !(a instanceof Node) || i.contains(a) && u.push(a);
return u; return u;
} }
function m(i, u) { function m(i, u) {
let f = !1; let a = !1;
for (let p of i) { for (let p of i) {
if (u && d(p).then(m), !e.has(p)) if (u && f(p).then(m), !e.has(p))
continue; continue;
let _ = e.get(p); let _ = e.get(p);
_.length_c && (p.dispatchEvent(new Event("dde:connected")), _.connected = /* @__PURE__ */ new WeakSet(), _.length_c = 0, _.length_d || e.delete(p), f = !0); _.length_c && (p.dispatchEvent(new Event("dde:connected")), _.connected = /* @__PURE__ */ new WeakSet(), _.length_c = 0, _.length_d || e.delete(p), a = !0);
} }
return f; return a;
} }
function b(i, u) { function b(i, u) {
let f = !1; let a = !1;
for (let p of i) for (let p of i)
u && d(p).then(b), !(!e.has(p) || !e.get(p).length_d) && (p.dispatchEvent(new Event("dde:disconnected")), e.delete(p), f = !0); u && f(p).then(b), !(!e.has(p) || !e.get(p).length_d) && (p.dispatchEvent(new Event("dde:disconnected")), e.delete(p), a = !0);
return f; return a;
} }
} }
@ -350,9 +350,9 @@ h.attribute = function(e, t = void 0) {
o.abort(); o.abort();
} }
}); });
return E.host(S.attributeChanged(function({ detail: a }) { return E.host(S.attributeChanged(function({ detail: d }) {
let [s, d] = a; let [s, f] = d;
s === e && c(d); s === e && c(f);
}, { signal: o.signal })), c; }, { signal: o.signal })), c;
}; };
h.clear = function(...e) { h.clear = function(...e) {
@ -373,14 +373,14 @@ h.clear = function(...e) {
h.el = function(e, t) { h.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 c = (a) => { let c = (d) => {
if (!n.parentNode || !r.parentNode) if (!n.parentNode || !r.parentNode)
return H(e, c); return H(e, c);
let s = t(a); let s = t(d);
Array.isArray(s) || (s = [s]); Array.isArray(s) || (s = [s]);
let d = n; let f = n;
for (; (d = n.nextSibling) !== r; ) for (; (f = n.nextSibling) !== r; )
d.remove(); f.remove();
n.after(...s); n.after(...s);
}; };
return P(e, c), c(e()), o; return P(e, c), c(e()), o;

158
dist/esm.js vendored
View File

@ -3,7 +3,7 @@ var m = {
isSignal(e) { isSignal(e) {
return !1; return !1;
}, },
processReactiveAttribute(e, t, n, s) { processReactiveAttribute(e, t, n, i) {
return n; return n;
} }
}; };
@ -71,57 +71,57 @@ var E = [{ scope: document.body, namespace: "html", host: (e) => e ? e(document.
} }
}; };
function V(e, t, ...n) { function V(e, t, ...n) {
let s = this, r = b(this), { namespace: f } = x, a; let i = this, r = b(this), { namespace: f } = x, d = !1, o;
switch ((Object(t) !== t || r.isSignal(t)) && (t = { textContent: t }), !0) { switch ((Object(t) !== t || r.isSignal(t)) && (t = { textContent: t }), !0) {
case typeof e == "function": { case typeof e == "function": {
x.push({ scope: e, host: (u) => u ? (n.unshift(u), void 0) : a }), a = e(t || void 0), x.pop(); d = !0, x.push({ scope: e, host: (a) => a ? (n.unshift(a), void 0) : o }), o = e(t || void 0);
break; break;
} }
case e === "#text": case e === "#text":
a = w.call(s, document.createTextNode(""), t); o = w.call(i, document.createTextNode(""), t);
break; break;
case e === "<>": case e === "<>":
a = w.call(s, document.createDocumentFragment(), t); o = w.call(i, document.createDocumentFragment(), t);
break; break;
case f !== "html": case f !== "html":
a = w.call(s, document.createElementNS(f, e), t); o = w.call(i, document.createElementNS(f, e), t);
break; break;
case !a: case !o:
a = w.call(s, document.createElement(e), t); o = w.call(i, document.createElement(e), t);
} }
return n.forEach((u) => u(a)), a; return n.forEach((a) => a(o)), d && x.pop(), o;
} }
var { setDeleteAttr: S } = C; var { setDeleteAttr: S } = C;
function w(e, ...t) { function w(e, ...t) {
let n = this, s = b(this); let n = this, i = b(this);
if (!t.length) if (!t.length)
return e; return e;
let f = (e instanceof SVGElement ? F : W).bind(null, e, "Attribute"); let f = (e instanceof SVGElement ? F : W).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function a([u, d]) { return Object.entries(Object.assign({}, ...t)).forEach(function d([o, a]) {
d = s.processReactiveAttribute(e, u, d, a); a = i.processReactiveAttribute(e, o, a, d);
let [h] = u; let [l] = o;
if (h === "=") if (l === "=")
return f(u.slice(1), d); return f(o.slice(1), a);
if (h === ".") if (l === ".")
return L(e, u.slice(1), d); return L(e, o.slice(1), a);
if (/(aria|data)([A-Z])/.test(u)) if (/(aria|data)([A-Z])/.test(o))
return u = u.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), f(u, d); return o = o.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), f(o, a);
switch (u === "className" && (u = "class"), u) { switch (o === "className" && (o = "class"), o) {
case "xlink:href": case "xlink:href":
return f(u, d, "http://www.w3.org/1999/xlink"); return f(o, a, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
return S(e, u, d); return S(e, o, a);
case "style": case "style":
if (typeof d != "object") if (typeof a != "object")
break; break;
case "dataset": case "dataset":
return O(s, d, L.bind(null, e[u])); return O(i, a, L.bind(null, e[o]));
case "ariaset": case "ariaset":
return O(s, d, (l, c) => f("aria-" + l, c)); return O(i, a, (h, c) => f("aria-" + h, c));
case "classList": case "classList":
return T.call(n, e, d); return T.call(n, e, a);
} }
return M(e, u) ? S(e, u, d) : f(u, d); return M(e, o) ? S(e, o, a) : f(o, a);
}), e; }), e;
} }
function T(e, t) { function T(e, t) {
@ -129,7 +129,7 @@ function T(e, t) {
return O( return O(
n, n,
t, t,
(s, r) => e.classList.toggle(s, r === -1 ? void 0 : !!r) (i, r) => e.classList.toggle(i, r === -1 ? void 0 : !!r)
), e; ), e;
} }
function $(e) { function $(e) {
@ -150,17 +150,17 @@ function D(e, t) {
function O(e, t, n) { function O(e, t, n) {
if (!(typeof t != "object" || t === null)) if (!(typeof t != "object" || t === null))
return Object.entries(t).forEach(function([r, f]) { return Object.entries(t).forEach(function([r, f]) {
r && (f = e.processReactiveAttribute(t, r, f, (a) => n(...a)), n(r, f)); r && (f = e.processReactiveAttribute(t, r, f, (d) => n(...d)), n(r, f));
}); });
} }
function N(e) { function N(e) {
return Array.isArray(e) ? e.filter(Boolean).join(" ") : e; return Array.isArray(e) ? e.filter(Boolean).join(" ") : e;
} }
function W(e, t, n, s) { function W(e, t, n, i) {
return e[(g(s) ? "remove" : "set") + t](n, N(s)); return e[(g(i) ? "remove" : "set") + t](n, N(i));
} }
function F(e, t, n, s, r = null) { function F(e, t, n, i, r = null) {
return e[(g(s) ? "remove" : "set") + t + "NS"](r, n, N(s)); return e[(g(i) ? "remove" : "set") + t + "NS"](r, n, N(i));
} }
function L(e, t, n) { function L(e, t, n) {
if (Reflect.set(e, t, n), !!g(n)) if (Reflect.set(e, t, n), !!g(n))
@ -169,8 +169,8 @@ function L(e, t, n) {
// src/events.js // src/events.js
function Q(e, t, ...n) { function Q(e, t, ...n) {
let s = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); let i = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t);
return e.dispatchEvent(s); return e.dispatchEvent(i);
} }
function y(e, t, n) { function y(e, t, n) {
return function(r) { return function(r) {
@ -198,99 +198,99 @@ y.attributeChanged = function(e, t) {
let f = "dde:" + n; let f = "dde:" + n;
if (r.addEventListener(f, e, t), r.__dde_lifecycleToEvents || U.has(r)) if (r.addEventListener(f, e, t), r.__dde_lifecycleToEvents || U.has(r))
return r; return r;
let a = new MutationObserver(function(d) { let d = new MutationObserver(function(a) {
for (let { attributeName: h, target: l } of d) for (let { attributeName: l, target: h } of a)
l.dispatchEvent( h.dispatchEvent(
new CustomEvent(f, { detail: [h, l.getAttribute(h)] }) new CustomEvent(f, { detail: [l, h.getAttribute(l)] })
); );
}); });
return _(t.signal, () => a.disconnect()) && a.observe(r, { attributes: !0 }), r; return _(t.signal, () => d.disconnect()) && d.observe(r, { attributes: !0 }), r;
}; };
}; };
function q() { function q() {
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 o of c) for (let s of c)
if (o.type === "childList") { if (s.type === "childList") {
if (h(o.addedNodes, !0)) { if (l(s.addedNodes, !0)) {
a(); d();
continue; continue;
} }
l(o.removedNodes, !0) && a(); h(s.removedNodes, !0) && d();
} }
}); });
return { return {
onConnected(c, o) { onConnected(c, s) {
f(); f();
let i = r(c); let u = r(c);
i.connected.has(o) || (i.connected.add(o), i.length_c += 1); u.connected.has(s) || (u.connected.add(s), u.length_c += 1);
}, },
offConnected(c, o) { offConnected(c, s) {
if (!e.has(c)) if (!e.has(c))
return; return;
let i = e.get(c); let u = e.get(c);
i.connected.has(o) && (i.connected.delete(o), i.length_c -= 1, s(c, i)); u.connected.has(s) && (u.connected.delete(s), u.length_c -= 1, i(c, u));
}, },
onDisconnected(c, o) { onDisconnected(c, s) {
f(); f();
let i = r(c); let u = r(c);
i.disconnected.has(o) || (i.disconnected.add(o), i.length_d += 1); u.disconnected.has(s) || (u.disconnected.add(s), u.length_d += 1);
}, },
offDisconnected(c, o) { offDisconnected(c, s) {
if (!e.has(c)) if (!e.has(c))
return; return;
let i = e.get(c); let u = e.get(c);
i.disconnected.has(o) && (i.disconnected.delete(o), i.length_d -= 1, s(c, i)); u.disconnected.has(s) && (u.disconnected.delete(s), u.length_d -= 1, i(c, u));
} }
}; };
function s(c, o) { function i(c, s) {
o.length_c || o.length_d || (e.delete(c), a()); s.length_c || s.length_d || (e.delete(c), d());
} }
function r(c) { function r(c) {
if (e.has(c)) if (e.has(c))
return e.get(c); return e.get(c);
let o = { let s = {
connected: /* @__PURE__ */ new WeakSet(), connected: /* @__PURE__ */ new WeakSet(),
length_c: 0, length_c: 0,
disconnected: /* @__PURE__ */ new WeakSet(), disconnected: /* @__PURE__ */ new WeakSet(),
length_d: 0 length_d: 0
}; };
return e.set(c, o), o; return e.set(c, s), s;
} }
function f() { function f() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
} }
function a() { function d() {
!t || e.size || (t = !1, n.disconnect()); !t || e.size || (t = !1, n.disconnect());
} }
function u() { function o() {
return new Promise(function(c) { return new Promise(function(c) {
(requestIdleCallback || requestAnimationFrame)(c); (requestIdleCallback || requestAnimationFrame)(c);
}); });
} }
async function d(c) { async function a(c) {
e.size > 30 && await u(); e.size > 30 && await o();
let o = []; let s = [];
if (!(c instanceof Node)) if (!(c instanceof Node))
return o; return s;
for (let i of e.keys()) for (let u of e.keys())
i === c || !(i instanceof Node) || c.contains(i) && o.push(i); u === c || !(u instanceof Node) || c.contains(u) && s.push(u);
return o; return s;
} }
function h(c, o) { function l(c, s) {
let i = !1; let u = !1;
for (let p of c) { for (let p of c) {
if (o && d(p).then(h), !e.has(p)) if (s && a(p).then(l), !e.has(p))
continue; continue;
let v = e.get(p); let v = e.get(p);
v.length_c && (p.dispatchEvent(new Event("dde:connected")), v.connected = /* @__PURE__ */ new WeakSet(), v.length_c = 0, v.length_d || e.delete(p), i = !0); v.length_c && (p.dispatchEvent(new Event("dde:connected")), v.connected = /* @__PURE__ */ new WeakSet(), v.length_c = 0, v.length_d || e.delete(p), u = !0);
} }
return i; return u;
} }
function l(c, o) { function h(c, s) {
let i = !1; let u = !1;
for (let p of c) for (let p of c)
o && d(p).then(l), !(!e.has(p) || !e.get(p).length_d) && (p.dispatchEvent(new Event("dde:disconnected")), e.delete(p), i = !0); s && a(p).then(h), !(!e.has(p) || !e.get(p).length_d) && (p.dispatchEvent(new Event("dde:disconnected")), e.delete(p), u = !0);
return i; return u;
} }
} }

View File

@ -31,15 +31,16 @@ export function createElement(tag, attributes, ...connect){
const _this= this; const _this= this;
const s= signals(this); const s= signals(this);
const { namespace }= scope; const { namespace }= scope;
let scoped= false;
let el; let el;
//TODO Array.isArray(tag) ⇒ set key (cache els) //TODO Array.isArray(tag) ⇒ set key (cache els)
if(Object(attributes)!==attributes || s.isSignal(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": {
scoped= true;
scope.push({ scope: tag, host: c=> c ? (connect.unshift(c), undefined) : el }); scope.push({ scope: tag, host: c=> c ? (connect.unshift(c), undefined) : el });
el= tag(attributes || undefined); el= tag(attributes || undefined);
scope.pop();
break; break;
} }
case tag==="#text": el= assign.call(_this, document.createTextNode(""), attributes); break; case tag==="#text": el= assign.call(_this, document.createTextNode(""), attributes); break;
@ -48,6 +49,7 @@ export function createElement(tag, attributes, ...connect){
case !el: el= assign.call(_this, document.createElement(tag), attributes); case !el: el= assign.call(_this, document.createElement(tag), attributes);
} }
connect.forEach(c=> c(el)); connect.forEach(c=> c(el));
if(scoped) scope.pop();
return el; return el;
} }
export { createElement as el }; export { createElement as el };

View File

@ -24,7 +24,7 @@ on.connected= function(listener, options){
const event= "dde:"+name; const event= "dde:"+name;
element.addEventListener(event, listener, options); element.addEventListener(event, listener, options);
if(element.__dde_lifecycleToEvents) return element; if(element.__dde_lifecycleToEvents) return element;
if(element.isConnected) return ( element.dispatchEvent(new Event(event)), element ) if(element.isConnected) return ( element.dispatchEvent(new Event(event)), element );
const c= onAbort(options.signal, ()=> c_ch_o.offConnected(element, listener)); const c= onAbort(options.signal, ()=> c_ch_o.offConnected(element, listener));
if(c) c_ch_o.onConnected(element, listener); if(c) c_ch_o.onConnected(element, listener);