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

🐛 use assign.call() for creating elements

This commit is contained in:
Jan Andrle 2023-09-21 17:04:40 +02:00
parent e3c2786a72
commit 3823abc2d7
Signed by: jaandrle
GPG Key ID: B3A25AED155AFFAB
5 changed files with 301 additions and 300 deletions

View File

@ -20,7 +20,7 @@
function m(e) { function m(e) {
return typeof e > "u"; return typeof e > "u";
} }
function _(e) { function N(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);
} }
@ -54,62 +54,62 @@
}; };
} }
function ce(e, t, ...n) { function ce(e, t, ...n) {
let r = x(this), o; let r = this, o = x(this), c;
switch ((Object(t) !== t || r.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": {
o = e(t || void 0, (p) => p ? (n.unshift(p), void 0) : o); c = e(t || void 0, (s) => s ? (n.unshift(s), void 0) : c);
break; break;
} }
case e === "#text": case e === "#text":
o = S(document.createTextNode(""), t); c = S.call(r, document.createTextNode(""), t);
break; break;
case e === "<>": case e === "<>":
o = S(document.createDocumentFragment(), t); c = S.call(r, document.createDocumentFragment(), t);
break; break;
case w !== "html": case w !== "html":
o = S(document.createElementNS(w, e), t); c = S.call(r, document.createElementNS(w, e), t);
break; break;
case !o: case !c:
o = S(document.createElement(e), t); c = S.call(r, document.createElement(e), t);
} }
return n.forEach((i) => i(o)), o; return n.forEach((p) => p(c)), c;
} }
var { setDeleteAttr: j } = P; var { setDeleteAttr: j } = P;
function S(e, ...t) { function S(e, ...t) {
let n = this, r = x(this); let n = this, r = x(this);
if (!t.length) if (!t.length)
return e; return e;
let i = (e instanceof SVGElement ? I : H).bind(null, e, "Attribute"); let c = (e instanceof SVGElement ? I : H).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function p([f, a]) { return Object.entries(Object.assign({}, ...t)).forEach(function p([s, a]) {
a = r.processReactiveAttribute(e, f, a, p); a = r.processReactiveAttribute(e, s, a, p);
let [b] = f; let [b] = s;
if (b === "=") if (b === "=")
return i(f.slice(1), a); return c(s.slice(1), a);
if (b === ".") if (b === ".")
return F(e, f.slice(1), a); return F(e, s.slice(1), a);
if (/(aria|data)([A-Z])/.test(f)) if (/(aria|data)([A-Z])/.test(s))
return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(f, a); return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), c(s, a);
switch (f === "className" && (f = "class"), f) { switch (s === "className" && (s = "class"), s) {
case "xlink:href": case "xlink:href":
return i(f, a, "http://www.w3.org/1999/xlink"); return c(s, a, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
return j(e, f, a); return j(e, s, a);
case "style": case "style":
if (typeof a != "object") if (typeof a != "object")
break; break;
case "dataset": case "dataset":
return D(r, a, F.bind(null, e[f])); return _(r, a, F.bind(null, e[s]));
case "ariaset": case "ariaset":
return D(r, a, (v, c) => i("aria-" + v, c)); return _(r, a, (v, i) => c("aria-" + v, i));
case "classList": case "classList":
return B.call(n, e, a); return B.call(n, e, a);
} }
return G(e, f) ? j(e, f, a) : i(f, a); return G(e, s) ? j(e, s, a) : c(s, a);
}), e; }), e;
} }
function B(e, t) { function B(e, t) {
let n = x(this); let n = x(this);
return D( return _(
n, n,
t, t,
(r, o) => e.classList.toggle(r, o === -1 ? void 0 : !!o) (r, o) => e.classList.toggle(r, o === -1 ? void 0 : !!o)
@ -130,10 +130,10 @@
let n = Object.getOwnPropertyDescriptor(e, t); let n = Object.getOwnPropertyDescriptor(e, t);
return n || M(e, t); return n || M(e, t);
} }
function D(e, t, n) { function _(e, t, n) {
if (!(typeof t != "object" || t === null)) if (!(typeof t != "object" || t === null))
return Object.entries(t).forEach(function([o, i]) { return Object.entries(t).forEach(function([o, c]) {
o && (i = e.processReactiveAttribute(t, o, i, (p) => n(...p)), n(o, i)); o && (c = e.processReactiveAttribute(t, o, c, (p) => n(...p)), n(o, c));
}); });
} }
function z(e) { function z(e) {
@ -172,77 +172,77 @@
}; };
}; };
function J() { function J() {
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) { let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(i) {
for (let s of c) for (let f of i)
if (s.type === "childList") { if (f.type === "childList") {
if (b(s.addedNodes, !0)) { if (b(f.addedNodes, !0)) {
p(); p();
continue; continue;
} }
v(s.removedNodes, !0) && p(); v(f.removedNodes, !0) && p();
} }
}); });
return { return {
onConnected(c, s) { onConnected(i, f) {
i(), o(c).connected.push(s); c(), o(i).connected.push(f);
}, },
offConnected(c, s) { offConnected(i, f) {
if (!e.has(c)) if (!e.has(i))
return; return;
let u = e.get(c), l = u.connected; let u = e.get(i), l = u.connected;
l.splice(l.indexOf(s), 1), r(c, u); l.splice(l.indexOf(f), 1), r(i, u);
}, },
onDisconnected(c, s) { onDisconnected(i, f) {
i(), o(c).disconnected.push(s); c(), o(i).disconnected.push(f);
}, },
offDisconnected(c, s) { offDisconnected(i, f) {
if (!e.has(c)) if (!e.has(i))
return; return;
let u = e.get(c), l = u.disconnected; let u = e.get(i), l = u.disconnected;
l.splice(l.indexOf(s), 1), r(c, u); l.splice(l.indexOf(f), 1), r(i, u);
} }
}; };
function r(c, s) { function r(i, f) {
s.connected.length || s.disconnected.length || (e.delete(c), p()); f.connected.length || f.disconnected.length || (e.delete(i), p());
} }
function o(c) { function o(i) {
if (e.has(c)) if (e.has(i))
return e.get(c); return e.get(i);
let s = { connected: [], disconnected: [] }; let f = { connected: [], disconnected: [] };
return e.set(c, s), s; return e.set(i, f), f;
} }
function i() { 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 p() { function p() {
!t || e.size || (t = !1, n.disconnect()); !t || e.size || (t = !1, n.disconnect());
} }
function f() { function s() {
return new Promise(function(c) { return new Promise(function(i) {
(requestIdleCallback || requestAnimationFrame)(c); (requestIdleCallback || requestAnimationFrame)(i);
}); });
} }
async function a(c) { async function a(i) {
e.size > 30 && await f(); e.size > 30 && await s();
let s = []; let f = [];
if (!(c instanceof Node)) if (!(i instanceof Node))
return s; return f;
for (let u of e.keys()) for (let u of e.keys())
u === c || !(u instanceof Node) || c.contains(u) && s.push(u); u === i || !(u instanceof Node) || i.contains(u) && f.push(u);
return s; return f;
} }
function b(c, s) { function b(i, f) {
for (let u of c) { for (let u of i) {
if (s && a(u).then(b), !e.has(u)) if (f && a(u).then(b), !e.has(u))
continue; continue;
let l = e.get(u); let l = e.get(u);
return l.connected.forEach((A) => A(u)), l.connected.length = 0, l.disconnected.length || e.delete(u), !0; return l.connected.forEach((A) => A(u)), l.connected.length = 0, l.disconnected.length || e.delete(u), !0;
} }
return !1; return !1;
} }
function v(c, s) { function v(i, f) {
for (let u of c) { for (let u of i) {
if (s && a(u).then(v), !e.has(u)) if (f && a(u).then(v), !e.has(u))
continue; continue;
let l = e.get(u); let l = e.get(u);
return l.disconnected.forEach((A) => A(u)), l.connected.length = 0, l.disconnected.length = 0, e.delete(u), !0; return l.disconnected.forEach((A) => A(u)), l.connected.length = 0, l.disconnected.length = 0, e.delete(u), !0;
@ -283,14 +283,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((i) => i(r.value)); r.listeners.forEach((c) => c(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((i) => e(i, n, r)); return t.forEach((c) => e(c, n, r));
N(t, n), o && o.addEventListener("abort", () => q(t, n)); D(t, n), o && o.addEventListener("abort", () => q(t, n));
} }
}; };
g.symbols = { g.symbols = {
@ -307,30 +307,30 @@
r.listeners.forEach((o) => { r.listeners.forEach((o) => {
if (r.listeners.delete(o), !h.has(o)) if (r.listeners.delete(o), !h.has(o))
return; return;
let i = h.get(o); let c = h.get(o);
i.delete(n), !(i.size > 1) && (g.clear(...i), h.delete(o)); c.delete(n), !(c.size > 1) && (g.clear(...c), 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 i = (p) => { let c = (p) => {
if (!n.parentNode || !r.parentNode) if (!n.parentNode || !r.parentNode)
return q(e, i); return q(e, c);
let f = t(p); let s = t(p);
Array.isArray(f) || (f = [f]); Array.isArray(s) || (s = [s]);
let a = n; let a = n;
for (; (a = n.nextSibling) !== r; ) for (; (a = n.nextSibling) !== r; )
a.remove(); a.remove();
n.after(...f); n.after(...s);
}; };
return N(e, i), i(e()), o; return D(e, c), c(e()), o;
}; };
var $ = { var $ = {
isSignal: y, isSignal: y,
processReactiveAttribute(e, t, n, r) { processReactiveAttribute(e, t, n, r) {
return y(n) ? (N(n, (o) => r([t, o])), n()) : n; return y(n) ? (D(n, (o) => r([t, o])), n()) : n;
} }
}; };
function U(e, t) { function U(e, t) {
@ -343,7 +343,7 @@
} }
}); });
function Z(e, t, n) { function Z(e, t, n) {
return _(n) !== "[object Object]" && (n = {}), e[d] = { return N(n) !== "[object Object]" && (n = {}), e[d] = {
value: t, value: t,
actions: n, actions: n,
listeners: /* @__PURE__ */ new Set() listeners: /* @__PURE__ */ new Set()
@ -372,7 +372,7 @@
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 N(e, t) { function D(e, t) {
if (e[d]) if (e[d])
return e[d].listeners.add(t); return e[d].listeners.add(t);
} }

130
dist/dde.js vendored
View File

@ -50,57 +50,57 @@
}; };
} }
function I(e, t, ...n) { function I(e, t, ...n) {
let r = v(this), c; let r = this, u = v(this), i;
switch ((Object(t) !== t || r.isSignal(t)) && (t = { textContent: t }), !0) { switch ((Object(t) !== t || u.isSignal(t)) && (t = { textContent: t }), !0) {
case typeof e == "function": { case typeof e == "function": {
c = e(t || void 0, (l) => l ? (n.unshift(l), void 0) : c); i = e(t || void 0, (f) => f ? (n.unshift(f), void 0) : i);
break; break;
} }
case e === "#text": case e === "#text":
c = m(document.createTextNode(""), t); i = m.call(r, document.createTextNode(""), t);
break; break;
case e === "<>": case e === "<>":
c = m(document.createDocumentFragment(), t); i = m.call(r, document.createDocumentFragment(), t);
break; break;
case x !== "html": case x !== "html":
c = m(document.createElementNS(x, e), t); i = m.call(r, document.createElementNS(x, e), t);
break; break;
case !c: case !i:
c = m(document.createElement(e), t); i = m.call(r, document.createElement(e), t);
} }
return n.forEach((d) => d(c)), c; return n.forEach((l) => l(i)), i;
} }
var { setDeleteAttr: C } = R; var { setDeleteAttr: C } = R;
function m(e, ...t) { function m(e, ...t) {
let n = this, r = v(this); let n = this, r = v(this);
if (!t.length) if (!t.length)
return e; return e;
let d = (e instanceof SVGElement ? M : F).bind(null, e, "Attribute"); let i = (e instanceof SVGElement ? M : F).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function l([f, u]) { return Object.entries(Object.assign({}, ...t)).forEach(function l([f, d]) {
u = r.processReactiveAttribute(e, f, u, l); d = r.processReactiveAttribute(e, f, d, l);
let [h] = f; let [h] = f;
if (h === "=") if (h === "=")
return d(f.slice(1), u); return i(f.slice(1), d);
if (h === ".") if (h === ".")
return D(e, f.slice(1), u); return D(e, f.slice(1), d);
if (/(aria|data)([A-Z])/.test(f)) if (/(aria|data)([A-Z])/.test(f))
return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), d(f, u); return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(f, d);
switch (f === "className" && (f = "class"), f) { switch (f === "className" && (f = "class"), f) {
case "xlink:href": case "xlink:href":
return d(f, u, "http://www.w3.org/1999/xlink"); return i(f, d, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
return C(e, f, u); return C(e, f, d);
case "style": case "style":
if (typeof u != "object") if (typeof d != "object")
break; break;
case "dataset": case "dataset":
return O(r, u, D.bind(null, e[f])); return O(r, d, D.bind(null, e[f]));
case "ariaset": case "ariaset":
return O(r, u, (E, o) => d("aria-" + E, o)); return O(r, d, (E, o) => i("aria-" + E, o));
case "classList": case "classList":
return _.call(n, e, u); return _.call(n, e, d);
} }
return j(e, f) ? C(e, f, u) : d(f, u); return j(e, f) ? C(e, f, d) : i(f, d);
}), e; }), e;
} }
function _(e, t) { function _(e, t) {
@ -108,7 +108,7 @@
return O( return O(
n, n,
t, t,
(r, c) => e.classList.toggle(r, c === -1 ? void 0 : !!c) (r, u) => e.classList.toggle(r, u === -1 ? void 0 : !!u)
), e; ), e;
} }
function Z(e) { function Z(e) {
@ -128,8 +128,8 @@
} }
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([c, d]) { return Object.entries(t).forEach(function([u, i]) {
c && (d = e.processReactiveAttribute(t, c, d, (l) => n(...l)), n(c, d)); u && (i = e.processReactiveAttribute(t, u, i, (l) => n(...l)), n(u, i));
}); });
} }
function S(e) { function S(e) {
@ -138,8 +138,8 @@
function F(e, t, n, r) { function F(e, t, n, r) {
return e[(p(r) ? "remove" : "set") + t](n, S(r)); return e[(p(r) ? "remove" : "set") + t](n, S(r));
} }
function M(e, t, n, r, c = null) { function M(e, t, n, r, u = null) {
return e[(p(r) ? "remove" : "set") + t + "NS"](c, n, S(r)); return e[(p(r) ? "remove" : "set") + t + "NS"](u, n, S(r));
} }
function D(e, t, n) { function D(e, t, n) {
if (Reflect.set(e, t, n), !!p(n)) if (Reflect.set(e, t, n), !!p(n))
@ -152,8 +152,8 @@
return e.dispatchEvent(r); return e.dispatchEvent(r);
} }
function N(e, t, n) { function N(e, t, n) {
return function(c) { return function(u) {
return c.addEventListener(e, t, n), c; return u.addEventListener(e, t, n), u;
}; };
} }
var b = T(); var b = T();
@ -169,45 +169,45 @@
}; };
function T() { function T() {
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(o) { let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(o) {
for (let s of o) for (let c of o)
if (s.type === "childList") { if (c.type === "childList") {
if (h(s.addedNodes, !0)) { if (h(c.addedNodes, !0)) {
l(); l();
continue; continue;
} }
E(s.removedNodes, !0) && l(); E(c.removedNodes, !0) && l();
} }
}); });
return { return {
onConnected(o, s) { onConnected(o, c) {
d(), c(o).connected.push(s); i(), u(o).connected.push(c);
}, },
offConnected(o, s) { offConnected(o, c) {
if (!e.has(o)) if (!e.has(o))
return; return;
let i = e.get(o), a = i.connected; let s = e.get(o), a = s.connected;
a.splice(a.indexOf(s), 1), r(o, i); a.splice(a.indexOf(c), 1), r(o, s);
}, },
onDisconnected(o, s) { onDisconnected(o, c) {
d(), c(o).disconnected.push(s); i(), u(o).disconnected.push(c);
}, },
offDisconnected(o, s) { offDisconnected(o, c) {
if (!e.has(o)) if (!e.has(o))
return; return;
let i = e.get(o), a = i.disconnected; let s = e.get(o), a = s.disconnected;
a.splice(a.indexOf(s), 1), r(o, i); a.splice(a.indexOf(c), 1), r(o, s);
} }
}; };
function r(o, s) { function r(o, c) {
s.connected.length || s.disconnected.length || (e.delete(o), l()); c.connected.length || c.disconnected.length || (e.delete(o), l());
} }
function c(o) { function u(o) {
if (e.has(o)) if (e.has(o))
return e.get(o); return e.get(o);
let s = { connected: [], disconnected: [] }; let c = { connected: [], disconnected: [] };
return e.set(o, s), s; return e.set(o, c), c;
} }
function d() { 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 l() { function l() {
@ -218,30 +218,30 @@
(requestIdleCallback || requestAnimationFrame)(o); (requestIdleCallback || requestAnimationFrame)(o);
}); });
} }
async function u(o) { async function d(o) {
e.size > 30 && await f(); e.size > 30 && await f();
let s = []; let c = [];
if (!(o instanceof Node)) if (!(o instanceof Node))
return s; return c;
for (let i of e.keys()) for (let s of e.keys())
i === o || !(i instanceof Node) || o.contains(i) && s.push(i); s === o || !(s instanceof Node) || o.contains(s) && c.push(s);
return s; return c;
} }
function h(o, s) { function h(o, c) {
for (let i of o) { for (let s of o) {
if (s && u(i).then(h), !e.has(i)) if (c && d(s).then(h), !e.has(s))
continue; continue;
let a = e.get(i); let a = e.get(s);
return a.connected.forEach((A) => A(i)), a.connected.length = 0, a.disconnected.length || e.delete(i), !0; return a.connected.forEach((A) => A(s)), a.connected.length = 0, a.disconnected.length || e.delete(s), !0;
} }
return !1; return !1;
} }
function E(o, s) { function E(o, c) {
for (let i of o) { for (let s of o) {
if (s && u(i).then(E), !e.has(i)) if (c && d(s).then(E), !e.has(s))
continue; continue;
let a = e.get(i); let a = e.get(s);
return a.disconnected.forEach((A) => A(i)), a.connected.length = 0, a.disconnected.length = 0, e.delete(i), !0; return a.disconnected.forEach((A) => A(s)), a.connected.length = 0, a.disconnected.length = 0, e.delete(s), !0;
} }
return !1; return !1;
} }

View File

@ -18,7 +18,7 @@ function x(e) {
function m(e) { function m(e) {
return typeof e > "u"; return typeof e > "u";
} }
function _(e) { function N(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);
} }
@ -52,62 +52,62 @@ function oe(e) {
}; };
} }
function ce(e, t, ...n) { function ce(e, t, ...n) {
let r = x(this), o; let r = this, o = x(this), c;
switch ((Object(t) !== t || r.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": {
o = e(t || void 0, (p) => p ? (n.unshift(p), void 0) : o); c = e(t || void 0, (s) => s ? (n.unshift(s), void 0) : c);
break; break;
} }
case e === "#text": case e === "#text":
o = S(document.createTextNode(""), t); c = S.call(r, document.createTextNode(""), t);
break; break;
case e === "<>": case e === "<>":
o = S(document.createDocumentFragment(), t); c = S.call(r, document.createDocumentFragment(), t);
break; break;
case w !== "html": case w !== "html":
o = S(document.createElementNS(w, e), t); c = S.call(r, document.createElementNS(w, e), t);
break; break;
case !o: case !c:
o = S(document.createElement(e), t); c = S.call(r, document.createElement(e), t);
} }
return n.forEach((i) => i(o)), o; return n.forEach((p) => p(c)), c;
} }
var { setDeleteAttr: j } = P; var { setDeleteAttr: j } = P;
function S(e, ...t) { function S(e, ...t) {
let n = this, r = x(this); let n = this, r = x(this);
if (!t.length) if (!t.length)
return e; return e;
let i = (e instanceof SVGElement ? I : H).bind(null, e, "Attribute"); let c = (e instanceof SVGElement ? I : H).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function p([f, a]) { return Object.entries(Object.assign({}, ...t)).forEach(function p([s, a]) {
a = r.processReactiveAttribute(e, f, a, p); a = r.processReactiveAttribute(e, s, a, p);
let [b] = f; let [b] = s;
if (b === "=") if (b === "=")
return i(f.slice(1), a); return c(s.slice(1), a);
if (b === ".") if (b === ".")
return F(e, f.slice(1), a); return F(e, s.slice(1), a);
if (/(aria|data)([A-Z])/.test(f)) if (/(aria|data)([A-Z])/.test(s))
return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(f, a); return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), c(s, a);
switch (f === "className" && (f = "class"), f) { switch (s === "className" && (s = "class"), s) {
case "xlink:href": case "xlink:href":
return i(f, a, "http://www.w3.org/1999/xlink"); return c(s, a, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
return j(e, f, a); return j(e, s, a);
case "style": case "style":
if (typeof a != "object") if (typeof a != "object")
break; break;
case "dataset": case "dataset":
return D(r, a, F.bind(null, e[f])); return _(r, a, F.bind(null, e[s]));
case "ariaset": case "ariaset":
return D(r, a, (v, c) => i("aria-" + v, c)); return _(r, a, (v, i) => c("aria-" + v, i));
case "classList": case "classList":
return B.call(n, e, a); return B.call(n, e, a);
} }
return G(e, f) ? j(e, f, a) : i(f, a); return G(e, s) ? j(e, s, a) : c(s, a);
}), e; }), e;
} }
function B(e, t) { function B(e, t) {
let n = x(this); let n = x(this);
return D( return _(
n, n,
t, t,
(r, o) => e.classList.toggle(r, o === -1 ? void 0 : !!o) (r, o) => e.classList.toggle(r, o === -1 ? void 0 : !!o)
@ -128,10 +128,10 @@ function M(e, t) {
let n = Object.getOwnPropertyDescriptor(e, t); let n = Object.getOwnPropertyDescriptor(e, t);
return n || M(e, t); return n || M(e, t);
} }
function D(e, t, n) { function _(e, t, n) {
if (!(typeof t != "object" || t === null)) if (!(typeof t != "object" || t === null))
return Object.entries(t).forEach(function([o, i]) { return Object.entries(t).forEach(function([o, c]) {
o && (i = e.processReactiveAttribute(t, o, i, (p) => n(...p)), n(o, i)); o && (c = e.processReactiveAttribute(t, o, c, (p) => n(...p)), n(o, c));
}); });
} }
function z(e) { function z(e) {
@ -170,77 +170,77 @@ T.disconnected = function(e, t) {
}; };
}; };
function J() { function J() {
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) { let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(i) {
for (let s of c) for (let f of i)
if (s.type === "childList") { if (f.type === "childList") {
if (b(s.addedNodes, !0)) { if (b(f.addedNodes, !0)) {
p(); p();
continue; continue;
} }
v(s.removedNodes, !0) && p(); v(f.removedNodes, !0) && p();
} }
}); });
return { return {
onConnected(c, s) { onConnected(i, f) {
i(), o(c).connected.push(s); c(), o(i).connected.push(f);
}, },
offConnected(c, s) { offConnected(i, f) {
if (!e.has(c)) if (!e.has(i))
return; return;
let u = e.get(c), l = u.connected; let u = e.get(i), l = u.connected;
l.splice(l.indexOf(s), 1), r(c, u); l.splice(l.indexOf(f), 1), r(i, u);
}, },
onDisconnected(c, s) { onDisconnected(i, f) {
i(), o(c).disconnected.push(s); c(), o(i).disconnected.push(f);
}, },
offDisconnected(c, s) { offDisconnected(i, f) {
if (!e.has(c)) if (!e.has(i))
return; return;
let u = e.get(c), l = u.disconnected; let u = e.get(i), l = u.disconnected;
l.splice(l.indexOf(s), 1), r(c, u); l.splice(l.indexOf(f), 1), r(i, u);
} }
}; };
function r(c, s) { function r(i, f) {
s.connected.length || s.disconnected.length || (e.delete(c), p()); f.connected.length || f.disconnected.length || (e.delete(i), p());
} }
function o(c) { function o(i) {
if (e.has(c)) if (e.has(i))
return e.get(c); return e.get(i);
let s = { connected: [], disconnected: [] }; let f = { connected: [], disconnected: [] };
return e.set(c, s), s; return e.set(i, f), f;
} }
function i() { 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 p() { function p() {
!t || e.size || (t = !1, n.disconnect()); !t || e.size || (t = !1, n.disconnect());
} }
function f() { function s() {
return new Promise(function(c) { return new Promise(function(i) {
(requestIdleCallback || requestAnimationFrame)(c); (requestIdleCallback || requestAnimationFrame)(i);
}); });
} }
async function a(c) { async function a(i) {
e.size > 30 && await f(); e.size > 30 && await s();
let s = []; let f = [];
if (!(c instanceof Node)) if (!(i instanceof Node))
return s; return f;
for (let u of e.keys()) for (let u of e.keys())
u === c || !(u instanceof Node) || c.contains(u) && s.push(u); u === i || !(u instanceof Node) || i.contains(u) && f.push(u);
return s; return f;
} }
function b(c, s) { function b(i, f) {
for (let u of c) { for (let u of i) {
if (s && a(u).then(b), !e.has(u)) if (f && a(u).then(b), !e.has(u))
continue; continue;
let l = e.get(u); let l = e.get(u);
return l.connected.forEach((A) => A(u)), l.connected.length = 0, l.disconnected.length || e.delete(u), !0; return l.connected.forEach((A) => A(u)), l.connected.length = 0, l.disconnected.length || e.delete(u), !0;
} }
return !1; return !1;
} }
function v(c, s) { function v(i, f) {
for (let u of c) { for (let u of i) {
if (s && a(u).then(v), !e.has(u)) if (f && a(u).then(v), !e.has(u))
continue; continue;
let l = e.get(u); let l = e.get(u);
return l.disconnected.forEach((A) => A(u)), l.connected.length = 0, l.disconnected.length = 0, e.delete(u), !0; return l.disconnected.forEach((A) => A(u)), l.connected.length = 0, l.disconnected.length = 0, e.delete(u), !0;
@ -281,14 +281,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((i) => i(r.value)); r.listeners.forEach((c) => c(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((i) => e(i, n, r)); return t.forEach((c) => e(c, n, r));
N(t, n), o && o.addEventListener("abort", () => q(t, n)); D(t, n), o && o.addEventListener("abort", () => q(t, n));
} }
}; };
g.symbols = { g.symbols = {
@ -305,30 +305,30 @@ g.clear = function(...e) {
r.listeners.forEach((o) => { r.listeners.forEach((o) => {
if (r.listeners.delete(o), !h.has(o)) if (r.listeners.delete(o), !h.has(o))
return; return;
let i = h.get(o); let c = h.get(o);
i.delete(n), !(i.size > 1) && (g.clear(...i), h.delete(o)); c.delete(n), !(c.size > 1) && (g.clear(...c), 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 i = (p) => { let c = (p) => {
if (!n.parentNode || !r.parentNode) if (!n.parentNode || !r.parentNode)
return q(e, i); return q(e, c);
let f = t(p); let s = t(p);
Array.isArray(f) || (f = [f]); Array.isArray(s) || (s = [s]);
let a = n; let a = n;
for (; (a = n.nextSibling) !== r; ) for (; (a = n.nextSibling) !== r; )
a.remove(); a.remove();
n.after(...f); n.after(...s);
}; };
return N(e, i), i(e()), o; return D(e, c), c(e()), o;
}; };
var $ = { var $ = {
isSignal: y, isSignal: y,
processReactiveAttribute(e, t, n, r) { processReactiveAttribute(e, t, n, r) {
return y(n) ? (N(n, (o) => r([t, o])), n()) : n; return y(n) ? (D(n, (o) => r([t, o])), n()) : n;
} }
}; };
function U(e, t) { function U(e, t) {
@ -341,7 +341,7 @@ var V = Object.assign(/* @__PURE__ */ Object.create(null), {
} }
}); });
function Z(e, t, n) { function Z(e, t, n) {
return _(n) !== "[object Object]" && (n = {}), e[d] = { return N(n) !== "[object Object]" && (n = {}), e[d] = {
value: t, value: t,
actions: n, actions: n,
listeners: /* @__PURE__ */ new Set() listeners: /* @__PURE__ */ new Set()
@ -370,7 +370,7 @@ function X(e, t) {
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 N(e, t) { function D(e, t) {
if (e[d]) if (e[d])
return e[d].listeners.add(t); return e[d].listeners.add(t);
} }

130
dist/esm.js vendored
View File

@ -48,57 +48,57 @@ function H(e) {
}; };
} }
function I(e, t, ...n) { function I(e, t, ...n) {
let r = v(this), c; let r = this, u = v(this), i;
switch ((Object(t) !== t || r.isSignal(t)) && (t = { textContent: t }), !0) { switch ((Object(t) !== t || u.isSignal(t)) && (t = { textContent: t }), !0) {
case typeof e == "function": { case typeof e == "function": {
c = e(t || void 0, (l) => l ? (n.unshift(l), void 0) : c); i = e(t || void 0, (f) => f ? (n.unshift(f), void 0) : i);
break; break;
} }
case e === "#text": case e === "#text":
c = m(document.createTextNode(""), t); i = m.call(r, document.createTextNode(""), t);
break; break;
case e === "<>": case e === "<>":
c = m(document.createDocumentFragment(), t); i = m.call(r, document.createDocumentFragment(), t);
break; break;
case x !== "html": case x !== "html":
c = m(document.createElementNS(x, e), t); i = m.call(r, document.createElementNS(x, e), t);
break; break;
case !c: case !i:
c = m(document.createElement(e), t); i = m.call(r, document.createElement(e), t);
} }
return n.forEach((d) => d(c)), c; return n.forEach((l) => l(i)), i;
} }
var { setDeleteAttr: C } = R; var { setDeleteAttr: C } = R;
function m(e, ...t) { function m(e, ...t) {
let n = this, r = v(this); let n = this, r = v(this);
if (!t.length) if (!t.length)
return e; return e;
let d = (e instanceof SVGElement ? M : F).bind(null, e, "Attribute"); let i = (e instanceof SVGElement ? M : F).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function l([f, u]) { return Object.entries(Object.assign({}, ...t)).forEach(function l([f, d]) {
u = r.processReactiveAttribute(e, f, u, l); d = r.processReactiveAttribute(e, f, d, l);
let [h] = f; let [h] = f;
if (h === "=") if (h === "=")
return d(f.slice(1), u); return i(f.slice(1), d);
if (h === ".") if (h === ".")
return D(e, f.slice(1), u); return D(e, f.slice(1), d);
if (/(aria|data)([A-Z])/.test(f)) if (/(aria|data)([A-Z])/.test(f))
return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), d(f, u); return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(f, d);
switch (f === "className" && (f = "class"), f) { switch (f === "className" && (f = "class"), f) {
case "xlink:href": case "xlink:href":
return d(f, u, "http://www.w3.org/1999/xlink"); return i(f, d, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
return C(e, f, u); return C(e, f, d);
case "style": case "style":
if (typeof u != "object") if (typeof d != "object")
break; break;
case "dataset": case "dataset":
return O(r, u, D.bind(null, e[f])); return O(r, d, D.bind(null, e[f]));
case "ariaset": case "ariaset":
return O(r, u, (E, o) => d("aria-" + E, o)); return O(r, d, (E, o) => i("aria-" + E, o));
case "classList": case "classList":
return _.call(n, e, u); return _.call(n, e, d);
} }
return j(e, f) ? C(e, f, u) : d(f, u); return j(e, f) ? C(e, f, d) : i(f, d);
}), e; }), e;
} }
function _(e, t) { function _(e, t) {
@ -106,7 +106,7 @@ function _(e, t) {
return O( return O(
n, n,
t, t,
(r, c) => e.classList.toggle(r, c === -1 ? void 0 : !!c) (r, u) => e.classList.toggle(r, u === -1 ? void 0 : !!u)
), e; ), e;
} }
function Z(e) { function Z(e) {
@ -126,8 +126,8 @@ function L(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([c, d]) { return Object.entries(t).forEach(function([u, i]) {
c && (d = e.processReactiveAttribute(t, c, d, (l) => n(...l)), n(c, d)); u && (i = e.processReactiveAttribute(t, u, i, (l) => n(...l)), n(u, i));
}); });
} }
function S(e) { function S(e) {
@ -136,8 +136,8 @@ function S(e) {
function F(e, t, n, r) { function F(e, t, n, r) {
return e[(p(r) ? "remove" : "set") + t](n, S(r)); return e[(p(r) ? "remove" : "set") + t](n, S(r));
} }
function M(e, t, n, r, c = null) { function M(e, t, n, r, u = null) {
return e[(p(r) ? "remove" : "set") + t + "NS"](c, n, S(r)); return e[(p(r) ? "remove" : "set") + t + "NS"](u, n, S(r));
} }
function D(e, t, n) { function D(e, t, n) {
if (Reflect.set(e, t, n), !!p(n)) if (Reflect.set(e, t, n), !!p(n))
@ -150,8 +150,8 @@ function J(e, t, ...n) {
return e.dispatchEvent(r); return e.dispatchEvent(r);
} }
function N(e, t, n) { function N(e, t, n) {
return function(c) { return function(u) {
return c.addEventListener(e, t, n), c; return u.addEventListener(e, t, n), u;
}; };
} }
var b = T(); var b = T();
@ -167,45 +167,45 @@ N.disconnected = function(e, t) {
}; };
function T() { function T() {
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(o) { let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(o) {
for (let s of o) for (let c of o)
if (s.type === "childList") { if (c.type === "childList") {
if (h(s.addedNodes, !0)) { if (h(c.addedNodes, !0)) {
l(); l();
continue; continue;
} }
E(s.removedNodes, !0) && l(); E(c.removedNodes, !0) && l();
} }
}); });
return { return {
onConnected(o, s) { onConnected(o, c) {
d(), c(o).connected.push(s); i(), u(o).connected.push(c);
}, },
offConnected(o, s) { offConnected(o, c) {
if (!e.has(o)) if (!e.has(o))
return; return;
let i = e.get(o), a = i.connected; let s = e.get(o), a = s.connected;
a.splice(a.indexOf(s), 1), r(o, i); a.splice(a.indexOf(c), 1), r(o, s);
}, },
onDisconnected(o, s) { onDisconnected(o, c) {
d(), c(o).disconnected.push(s); i(), u(o).disconnected.push(c);
}, },
offDisconnected(o, s) { offDisconnected(o, c) {
if (!e.has(o)) if (!e.has(o))
return; return;
let i = e.get(o), a = i.disconnected; let s = e.get(o), a = s.disconnected;
a.splice(a.indexOf(s), 1), r(o, i); a.splice(a.indexOf(c), 1), r(o, s);
} }
}; };
function r(o, s) { function r(o, c) {
s.connected.length || s.disconnected.length || (e.delete(o), l()); c.connected.length || c.disconnected.length || (e.delete(o), l());
} }
function c(o) { function u(o) {
if (e.has(o)) if (e.has(o))
return e.get(o); return e.get(o);
let s = { connected: [], disconnected: [] }; let c = { connected: [], disconnected: [] };
return e.set(o, s), s; return e.set(o, c), c;
} }
function d() { 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 l() { function l() {
@ -216,30 +216,30 @@ function T() {
(requestIdleCallback || requestAnimationFrame)(o); (requestIdleCallback || requestAnimationFrame)(o);
}); });
} }
async function u(o) { async function d(o) {
e.size > 30 && await f(); e.size > 30 && await f();
let s = []; let c = [];
if (!(o instanceof Node)) if (!(o instanceof Node))
return s; return c;
for (let i of e.keys()) for (let s of e.keys())
i === o || !(i instanceof Node) || o.contains(i) && s.push(i); s === o || !(s instanceof Node) || o.contains(s) && c.push(s);
return s; return c;
} }
function h(o, s) { function h(o, c) {
for (let i of o) { for (let s of o) {
if (s && u(i).then(h), !e.has(i)) if (c && d(s).then(h), !e.has(s))
continue; continue;
let a = e.get(i); let a = e.get(s);
return a.connected.forEach((A) => A(i)), a.connected.length = 0, a.disconnected.length || e.delete(i), !0; return a.connected.forEach((A) => A(s)), a.connected.length = 0, a.disconnected.length || e.delete(s), !0;
} }
return !1; return !1;
} }
function E(o, s) { function E(o, c) {
for (let i of o) { for (let s of o) {
if (s && u(i).then(E), !e.has(i)) if (c && d(s).then(E), !e.has(s))
continue; continue;
let a = e.get(i); let a = e.get(s);
return a.disconnected.forEach((A) => A(i)), a.connected.length = 0, a.disconnected.length = 0, e.delete(i), !0; return a.disconnected.forEach((A) => A(s)), a.connected.length = 0, a.disconnected.length = 0, e.delete(s), !0;
} }
return !1; return !1;
} }

View File

@ -14,6 +14,7 @@ export function namespace(namespace){
}; };
} }
export function createElement(tag, attributes, ...connect){ export function createElement(tag, attributes, ...connect){
const _this= this;
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)
@ -25,10 +26,10 @@ export function createElement(tag, attributes, ...connect){
el= tag(attributes || undefined, ref); el= tag(attributes || undefined, ref);
break; break;
} }
case tag==="#text": el= assign(document.createTextNode(""), attributes); break; case tag==="#text": el= assign.call(_this, document.createTextNode(""), attributes); break;
case tag==="<>": el= assign(document.createDocumentFragment(), attributes); break; case tag==="<>": el= assign.call(_this, document.createDocumentFragment(), attributes); break;
case namespace_curr!=="html": el= assign(document.createElementNS(namespace_curr, tag), attributes); break; case namespace_curr!=="html": el= assign.call(_this, document.createElementNS(namespace_curr, tag), attributes); break;
case !el: el= assign(document.createElement(tag), attributes); case !el: el= assign.call(_this, document.createElement(tag), attributes);
} }
connect.forEach(c=> c(el)); connect.forEach(c=> c(el));
return el; return el;