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

130
dist/dde.js vendored
View File

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

View File

@ -18,7 +18,7 @@ function x(e) {
function m(e) {
return typeof e > "u";
}
function _(e) {
function N(e) {
let t = typeof 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) {
let r = x(this), o;
switch ((Object(t) !== t || r.isSignal(t)) && (t = { textContent: t }), !0) {
let r = this, o = x(this), c;
switch ((Object(t) !== t || o.isSignal(t)) && (t = { textContent: t }), !0) {
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;
}
case e === "#text":
o = S(document.createTextNode(""), t);
c = S.call(r, document.createTextNode(""), t);
break;
case e === "<>":
o = S(document.createDocumentFragment(), t);
c = S.call(r, document.createDocumentFragment(), t);
break;
case w !== "html":
o = S(document.createElementNS(w, e), t);
c = S.call(r, document.createElementNS(w, e), t);
break;
case !o:
o = S(document.createElement(e), t);
case !c:
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;
function S(e, ...t) {
let n = this, r = x(this);
if (!t.length)
return e;
let i = (e instanceof SVGElement ? I : H).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function p([f, a]) {
a = r.processReactiveAttribute(e, f, a, p);
let [b] = f;
let c = (e instanceof SVGElement ? I : H).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function p([s, a]) {
a = r.processReactiveAttribute(e, s, a, p);
let [b] = s;
if (b === "=")
return i(f.slice(1), a);
return c(s.slice(1), a);
if (b === ".")
return F(e, f.slice(1), a);
if (/(aria|data)([A-Z])/.test(f))
return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(f, a);
switch (f === "className" && (f = "class"), f) {
return F(e, s.slice(1), a);
if (/(aria|data)([A-Z])/.test(s))
return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), c(s, a);
switch (s === "className" && (s = "class"), s) {
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":
return j(e, f, a);
return j(e, s, a);
case "style":
if (typeof a != "object")
break;
case "dataset":
return D(r, a, F.bind(null, e[f]));
return _(r, a, F.bind(null, e[s]));
case "ariaset":
return D(r, a, (v, c) => i("aria-" + v, c));
return _(r, a, (v, i) => c("aria-" + v, i));
case "classList":
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;
}
function B(e, t) {
let n = x(this);
return D(
return _(
n,
t,
(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);
return n || M(e, t);
}
function D(e, t, n) {
function _(e, t, n) {
if (!(typeof t != "object" || t === null))
return Object.entries(t).forEach(function([o, i]) {
o && (i = e.processReactiveAttribute(t, o, i, (p) => n(...p)), n(o, i));
return Object.entries(t).forEach(function([o, c]) {
o && (c = e.processReactiveAttribute(t, o, c, (p) => n(...p)), n(o, c));
});
}
function z(e) {
@ -170,77 +170,77 @@ T.disconnected = function(e, t) {
};
};
function J() {
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) {
for (let s of c)
if (s.type === "childList") {
if (b(s.addedNodes, !0)) {
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(i) {
for (let f of i)
if (f.type === "childList") {
if (b(f.addedNodes, !0)) {
p();
continue;
}
v(s.removedNodes, !0) && p();
v(f.removedNodes, !0) && p();
}
});
return {
onConnected(c, s) {
i(), o(c).connected.push(s);
onConnected(i, f) {
c(), o(i).connected.push(f);
},
offConnected(c, s) {
if (!e.has(c))
offConnected(i, f) {
if (!e.has(i))
return;
let u = e.get(c), l = u.connected;
l.splice(l.indexOf(s), 1), r(c, u);
let u = e.get(i), l = u.connected;
l.splice(l.indexOf(f), 1), r(i, u);
},
onDisconnected(c, s) {
i(), o(c).disconnected.push(s);
onDisconnected(i, f) {
c(), o(i).disconnected.push(f);
},
offDisconnected(c, s) {
if (!e.has(c))
offDisconnected(i, f) {
if (!e.has(i))
return;
let u = e.get(c), l = u.disconnected;
l.splice(l.indexOf(s), 1), r(c, u);
let u = e.get(i), l = u.disconnected;
l.splice(l.indexOf(f), 1), r(i, u);
}
};
function r(c, s) {
s.connected.length || s.disconnected.length || (e.delete(c), p());
function r(i, f) {
f.connected.length || f.disconnected.length || (e.delete(i), p());
}
function o(c) {
if (e.has(c))
return e.get(c);
let s = { connected: [], disconnected: [] };
return e.set(c, s), s;
function o(i) {
if (e.has(i))
return e.get(i);
let f = { connected: [], disconnected: [] };
return e.set(i, f), f;
}
function i() {
function c() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
}
function p() {
!t || e.size || (t = !1, n.disconnect());
}
function f() {
return new Promise(function(c) {
(requestIdleCallback || requestAnimationFrame)(c);
function s() {
return new Promise(function(i) {
(requestIdleCallback || requestAnimationFrame)(i);
});
}
async function a(c) {
e.size > 30 && await f();
let s = [];
if (!(c instanceof Node))
return s;
async function a(i) {
e.size > 30 && await s();
let f = [];
if (!(i instanceof Node))
return f;
for (let u of e.keys())
u === c || !(u instanceof Node) || c.contains(u) && s.push(u);
return s;
u === i || !(u instanceof Node) || i.contains(u) && f.push(u);
return f;
}
function b(c, s) {
for (let u of c) {
if (s && a(u).then(b), !e.has(u))
function b(i, f) {
for (let u of i) {
if (f && a(u).then(b), !e.has(u))
continue;
let l = e.get(u);
return l.connected.forEach((A) => A(u)), l.connected.length = 0, l.disconnected.length || e.delete(u), !0;
}
return !1;
}
function v(c, s) {
for (let u of c) {
if (s && a(u).then(v), !e.has(u))
function v(i, f) {
for (let u of i) {
if (f && a(u).then(v), !e.has(u))
continue;
let l = e.get(u);
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}'!`);
if (o[t].apply(r, n), 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 = {}) {
let { signal: o } = r;
if (!(o && o.aborted)) {
if (Array.isArray(t))
return t.forEach((i) => e(i, n, r));
N(t, n), o && o.addEventListener("abort", () => q(t, n));
return t.forEach((c) => e(c, n, r));
D(t, n), o && o.addEventListener("abort", () => q(t, n));
}
};
g.symbols = {
@ -305,30 +305,30 @@ g.clear = function(...e) {
r.listeners.forEach((o) => {
if (r.listeners.delete(o), !h.has(o))
return;
let i = h.get(o);
i.delete(n), !(i.size > 1) && (g.clear(...i), h.delete(o));
let c = h.get(o);
c.delete(n), !(c.size > 1) && (g.clear(...c), h.delete(o));
});
}
};
g.el = function(e, t) {
let n = document.createComment("<#reactive>"), r = document.createComment("</#reactive>"), o = document.createDocumentFragment();
o.append(n, r);
let i = (p) => {
let c = (p) => {
if (!n.parentNode || !r.parentNode)
return q(e, i);
let f = t(p);
Array.isArray(f) || (f = [f]);
return q(e, c);
let s = t(p);
Array.isArray(s) || (s = [s]);
let a = n;
for (; (a = n.nextSibling) !== r; )
a.remove();
n.after(...f);
n.after(...s);
};
return N(e, i), i(e()), o;
return D(e, c), c(e()), o;
};
var $ = {
isSignal: y,
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) {
@ -341,7 +341,7 @@ var V = Object.assign(/* @__PURE__ */ Object.create(null), {
}
});
function Z(e, t, n) {
return _(n) !== "[object Object]" && (n = {}), e[d] = {
return N(n) !== "[object Object]" && (n = {}), e[d] = {
value: t,
actions: n,
listeners: /* @__PURE__ */ new Set()
@ -370,7 +370,7 @@ function X(e, t) {
if (n.value !== t)
return n.value = t, n.listeners.forEach((r) => r(t)), t;
}
function N(e, t) {
function D(e, t) {
if (e[d])
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) {
let r = v(this), c;
switch ((Object(t) !== t || r.isSignal(t)) && (t = { textContent: t }), !0) {
let r = this, u = v(this), i;
switch ((Object(t) !== t || u.isSignal(t)) && (t = { textContent: t }), !0) {
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;
}
case e === "#text":
c = m(document.createTextNode(""), t);
i = m.call(r, document.createTextNode(""), t);
break;
case e === "<>":
c = m(document.createDocumentFragment(), t);
i = m.call(r, document.createDocumentFragment(), t);
break;
case x !== "html":
c = m(document.createElementNS(x, e), t);
i = m.call(r, document.createElementNS(x, e), t);
break;
case !c:
c = m(document.createElement(e), t);
case !i:
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;
function m(e, ...t) {
let n = this, r = v(this);
if (!t.length)
return e;
let d = (e instanceof SVGElement ? M : F).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function l([f, u]) {
u = r.processReactiveAttribute(e, f, u, l);
let i = (e instanceof SVGElement ? M : F).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function l([f, d]) {
d = r.processReactiveAttribute(e, f, d, l);
let [h] = f;
if (h === "=")
return d(f.slice(1), u);
return i(f.slice(1), d);
if (h === ".")
return D(e, f.slice(1), u);
return D(e, f.slice(1), d);
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) {
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":
return C(e, f, u);
return C(e, f, d);
case "style":
if (typeof u != "object")
if (typeof d != "object")
break;
case "dataset":
return O(r, u, D.bind(null, e[f]));
return O(r, d, D.bind(null, e[f]));
case "ariaset":
return O(r, u, (E, o) => d("aria-" + E, o));
return O(r, d, (E, o) => i("aria-" + E, o));
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;
}
function _(e, t) {
@ -106,7 +106,7 @@ function _(e, t) {
return O(
n,
t,
(r, c) => e.classList.toggle(r, c === -1 ? void 0 : !!c)
(r, u) => e.classList.toggle(r, u === -1 ? void 0 : !!u)
), e;
}
function Z(e) {
@ -126,8 +126,8 @@ function L(e, t) {
}
function O(e, t, n) {
if (!(typeof t != "object" || t === null))
return Object.entries(t).forEach(function([c, d]) {
c && (d = e.processReactiveAttribute(t, c, d, (l) => n(...l)), n(c, d));
return Object.entries(t).forEach(function([u, i]) {
u && (i = e.processReactiveAttribute(t, u, i, (l) => n(...l)), n(u, i));
});
}
function S(e) {
@ -136,8 +136,8 @@ function S(e) {
function F(e, t, n, r) {
return e[(p(r) ? "remove" : "set") + t](n, S(r));
}
function M(e, t, n, r, c = null) {
return e[(p(r) ? "remove" : "set") + t + "NS"](c, n, S(r));
function M(e, t, n, r, u = null) {
return e[(p(r) ? "remove" : "set") + t + "NS"](u, n, S(r));
}
function D(e, t, n) {
if (Reflect.set(e, t, n), !!p(n))
@ -150,8 +150,8 @@ function J(e, t, ...n) {
return e.dispatchEvent(r);
}
function N(e, t, n) {
return function(c) {
return c.addEventListener(e, t, n), c;
return function(u) {
return u.addEventListener(e, t, n), u;
};
}
var b = T();
@ -167,45 +167,45 @@ N.disconnected = function(e, t) {
};
function T() {
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(o) {
for (let s of o)
if (s.type === "childList") {
if (h(s.addedNodes, !0)) {
for (let c of o)
if (c.type === "childList") {
if (h(c.addedNodes, !0)) {
l();
continue;
}
E(s.removedNodes, !0) && l();
E(c.removedNodes, !0) && l();
}
});
return {
onConnected(o, s) {
d(), c(o).connected.push(s);
onConnected(o, c) {
i(), u(o).connected.push(c);
},
offConnected(o, s) {
offConnected(o, c) {
if (!e.has(o))
return;
let i = e.get(o), a = i.connected;
a.splice(a.indexOf(s), 1), r(o, i);
let s = e.get(o), a = s.connected;
a.splice(a.indexOf(c), 1), r(o, s);
},
onDisconnected(o, s) {
d(), c(o).disconnected.push(s);
onDisconnected(o, c) {
i(), u(o).disconnected.push(c);
},
offDisconnected(o, s) {
offDisconnected(o, c) {
if (!e.has(o))
return;
let i = e.get(o), a = i.disconnected;
a.splice(a.indexOf(s), 1), r(o, i);
let s = e.get(o), a = s.disconnected;
a.splice(a.indexOf(c), 1), r(o, s);
}
};
function r(o, s) {
s.connected.length || s.disconnected.length || (e.delete(o), l());
function r(o, c) {
c.connected.length || c.disconnected.length || (e.delete(o), l());
}
function c(o) {
function u(o) {
if (e.has(o))
return e.get(o);
let s = { connected: [], disconnected: [] };
return e.set(o, s), s;
let c = { connected: [], disconnected: [] };
return e.set(o, c), c;
}
function d() {
function i() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
}
function l() {
@ -216,30 +216,30 @@ function T() {
(requestIdleCallback || requestAnimationFrame)(o);
});
}
async function u(o) {
async function d(o) {
e.size > 30 && await f();
let s = [];
let c = [];
if (!(o instanceof Node))
return s;
for (let i of e.keys())
i === o || !(i instanceof Node) || o.contains(i) && s.push(i);
return s;
return c;
for (let s of e.keys())
s === o || !(s instanceof Node) || o.contains(s) && c.push(s);
return c;
}
function h(o, s) {
for (let i of o) {
if (s && u(i).then(h), !e.has(i))
function h(o, c) {
for (let s of o) {
if (c && d(s).then(h), !e.has(s))
continue;
let a = e.get(i);
return a.connected.forEach((A) => A(i)), a.connected.length = 0, a.disconnected.length || e.delete(i), !0;
let a = e.get(s);
return a.connected.forEach((A) => A(s)), a.connected.length = 0, a.disconnected.length || e.delete(s), !0;
}
return !1;
}
function E(o, s) {
for (let i of o) {
if (s && u(i).then(E), !e.has(i))
function E(o, c) {
for (let s of o) {
if (c && d(s).then(E), !e.has(s))
continue;
let a = e.get(i);
return a.disconnected.forEach((A) => A(i)), a.connected.length = 0, a.disconnected.length = 0, e.delete(i), !0;
let a = e.get(s);
return a.disconnected.forEach((A) => A(s)), a.connected.length = 0, a.disconnected.length = 0, e.delete(s), !0;
}
return !1;
}

View File

@ -14,6 +14,7 @@ export function namespace(namespace){
};
}
export function createElement(tag, attributes, ...connect){
const _this= this;
const s= signals(this);
let el;
//TODO Array.isArray(tag) ⇒ set key (cache els)
@ -25,10 +26,10 @@ export function createElement(tag, attributes, ...connect){
el= tag(attributes || undefined, ref);
break;
}
case tag==="#text": el= assign(document.createTextNode(""), attributes); break;
case tag==="<>": el= assign(document.createDocumentFragment(), attributes); break;
case namespace_curr!=="html": el= assign(document.createElementNS(namespace_curr, tag), attributes); break;
case !el: el= assign(document.createElement(tag), attributes);
case tag==="#text": el= assign.call(_this, document.createTextNode(""), attributes); break;
case tag==="<>": el= assign.call(_this, document.createDocumentFragment(), attributes); break;
case namespace_curr!=="html": el= assign.call(_this, document.createElementNS(namespace_curr, tag), attributes); break;
case !el: el= assign.call(_this, document.createElement(tag), attributes);
}
connect.forEach(c=> c(el));
return el;