1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2024-11-21 23:39:37 +01:00

📦 dist and experiments

This commit is contained in:
Jan Andrle 2023-09-08 20:18:58 +02:00
parent 20e95e33d4
commit 7d5f3d17ae
Signed by: jaandrle
GPG Key ID: B3A25AED155AFFAB
7 changed files with 505 additions and 504 deletions

View File

@ -8,199 +8,191 @@
// src/signals-common.js // src/signals-common.js
var b = { var b = {
isReactiveAtrribute(e, t) {
return !1;
},
isTextContent(e) { isTextContent(e) {
return m(e) !== "[object Object]"; return m(e) !== "[object Object]";
}, },
processReactiveAttribute(e, t, r, n) { processReactiveAttribute(e, t, n, r) {
return !1; return n;
},
reactiveElement(e, ...t) {
return null;
} }
}; };
function L(e, t = !0) { function j(e, t = !0) {
return t ? Object.assign(b, e) : (Object.setPrototypeOf(e, b), e); return t ? Object.assign(b, e) : (Object.setPrototypeOf(e, b), e);
} }
function j(e) { function N(e) {
return b.isPrototypeOf(e) && e !== b ? e : b; return b.isPrototypeOf(e) && e !== b ? e : b;
} }
// src/dom.js // src/dom.js
var w = "html"; var v = "html";
function ee(e) { function ee(e) {
return w = e === "svg" ? "http://www.w3.org/2000/svg" : e, { return v = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(t) { append(t) {
return w = "html", t; return v = "html", t;
} }
}; };
} }
function te(e, t, ...r) { function te(e, t, ...n) {
let n = j(this), o; let r = N(this), o;
if (e === "<>") { switch (r.isTextContent(t) && (t = { textContent: t }), !0) {
if (n.isReactiveAtrribute(t))
return n.reactiveElement(t, ...r);
o = document.createDocumentFragment();
}
switch (n.isTextContent(t) && (t = { textContent: t }), !0) {
case typeof e == "function": case typeof e == "function":
o = e(t || void 0); o = e(t || void 0);
break; break;
case e === "#text": case e === "#text":
o = A(document.createTextNode(""), t); o = y(document.createTextNode(""), t);
break; break;
case w !== "html": case e === "<>":
o = A(document.createElementNS(w, e), t); o = y(document.createDocumentFragment(), t);
break;
case v !== "html":
o = y(document.createElementNS(v, e), t);
break; break;
case !o: case !o:
o = A(document.createElement(e), t); o = y(document.createElement(e), t);
} }
return r.forEach((a) => a(o)), o; return n.forEach((a) => a(o)), o;
} }
var x = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')); var x = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]'));
function A(e, ...t) { function y(e, ...t) {
let r = j(this); let n = N(this);
if (!t.length) if (!t.length)
return e; return e;
let n = e instanceof SVGElement, o = (n ? q : P).bind(null, e, "Attribute"); let r = e instanceof SVGElement, o = (r ? q : D).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function a([i, s]) { return Object.entries(Object.assign({}, ...t)).forEach(function a([f, s]) {
r.isReactiveAtrribute(s, i) && (s = r.processReactiveAttribute(e, i, s, a)); s = n.processReactiveAttribute(e, f, s, a);
let [h] = i; let [h] = f;
if (h === "=") if (h === "=")
return o(i.slice(1), s); return o(f.slice(1), s);
if (h === ".") if (h === ".")
return N(e, i.slice(1), s); return _(e, f.slice(1), s);
if (typeof s == "object") if (typeof s == "object")
switch (i) { switch (f) {
case "style": case "style":
return y(s, P.bind(null, e.style, "Property")); return w(s, D.bind(null, e.style, "Property"));
case "dataset": case "dataset":
return y(s, N.bind(null, e.dataset)); return w(s, _.bind(null, e.dataset));
case "ariaset": case "ariaset":
return y(s, (E, v) => o("aria-" + E, v)); return w(s, (E, O) => o("aria-" + E, O));
case "classList": case "classList":
return $(e, s); return $(e, s);
default: default:
return Reflect.set(e, i, s); return Reflect.set(e, f, s);
} }
if (/(aria|data)([A-Z])/.test(i)) if (/(aria|data)([A-Z])/.test(f))
return i = i.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(i, s); return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(f, s);
switch (i) { switch (f) {
case "href": case "href":
return o(i, s); return o(f, s);
case "xlink:href": case "xlink:href":
return o(i, s, "http://www.w3.org/1999/xlink"); return o(f, s, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
if (!n) if (!r)
break; break;
return e.appendChild(document.createTextNode(s)); return e.appendChild(document.createTextNode(s));
} }
return k(e, i) ? N(e, i, s) : o(i, s); return k(e, f) ? _(e, f, s) : o(f, s);
}), e; }), e;
} }
function $(e, t) { function $(e, t) {
return typeof t != "object" || y( return typeof t != "object" || w(
t, t,
(r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n) (n, r) => e.classList.toggle(n, r === -1 ? void 0 : !!r)
), e; ), e;
} }
function ne(e) { function ne(e) {
return Array.from(e.children).forEach((t) => t.remove()), e; return Array.from(e.children).forEach((t) => t.remove()), e;
} }
function k(e, t) { function k(e, t) {
let r = "HTMLElement," + t; let n = "HTMLElement," + t;
if (e instanceof HTMLElement && x.has(r)) if (e instanceof HTMLElement && x.has(n))
return x.get(r);
let n = e.nodeName + "," + t;
if (x.has(n))
return x.get(n); return x.get(n);
let [o, a, i] = T(e, t), s = !_(o.set); let r = e.nodeName + "," + t;
return (!s || a) && x.set(i === HTMLElement.prototype ? r : n, s), s; if (x.has(r))
return x.get(r);
let [o, a, f] = T(e, t), s = !A(o.set);
return (!s || a) && x.set(f === HTMLElement.prototype ? n : r, s), s;
} }
function T(e, t, r = 0) { function T(e, t, n = 0) {
if (e = Object.getPrototypeOf(e), !e) if (e = Object.getPrototypeOf(e), !e)
return [{}, r, e]; return [{}, n, e];
let n = Object.getOwnPropertyDescriptor(e, t); let r = Object.getOwnPropertyDescriptor(e, t);
return n ? [n, r, e] : T(e, t, r + 1); return r ? [r, n, e] : T(e, t, n + 1);
} }
function y(e, t) { function w(e, t) {
return Object.entries(e).forEach(([r, n]) => t(r, n)); return Object.entries(e).forEach(([n, r]) => t(n, r));
} }
function _(e) { function A(e) {
return typeof e > "u"; return typeof e > "u";
} }
function P(e, t, r, n) { function D(e, t, n, r) {
return e[(_(n) ? "remove" : "set") + t](r, n); return e[(A(r) ? "remove" : "set") + t](n, r);
} }
function q(e, t, r, n, o = null) { function q(e, t, n, r, o = null) {
return e[(_(n) ? "remove" : "set") + t + "NS"](o, r, n); return e[(A(r) ? "remove" : "set") + t + "NS"](o, n, r);
} }
function N(e, t, r) { function _(e, t, n) {
return Reflect.set(e, t, r); return Reflect.set(e, t, n);
} }
// src/events.js // src/events.js
function M(e, t, r) { function M(e, t, n) {
return (n) => (n.addEventListener(e, t, r), n); return (r) => (r.addEventListener(e, t, n), r);
} }
var O = W(); var S = J();
M.connected = function(e, t) { M.connected = function(e, t) {
return function(n) { return function(r) {
O.onConnected(n, e), t && t.signal && t.signal.addEventListener("abort", () => O.offConnected(n, e)); S.onConnected(r, e), t && t.signal && t.signal.addEventListener("abort", () => S.offConnected(r, e));
}; };
}; };
M.disconnected = function(e, t) { M.disconnected = function(e, t) {
return function(n) { return function(r) {
O.onDisconnected(n, e), t && t.signal && t.signal.addEventListener("abort", () => O.offDisconnected(n, e)); S.onDisconnected(r, e), t && t.signal && t.signal.addEventListener("abort", () => S.offDisconnected(r, e));
}; };
}; };
function W() { function J() {
let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(c) { let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) {
for (let f of c) for (let i of c)
if (f.type === "childList") { if (i.type === "childList") {
if (E(f.addedNodes, !0)) { if (E(i.addedNodes, !0)) {
i(); f();
continue; continue;
} }
v(f.removedNodes, !0) && i(); O(i.removedNodes, !0) && f();
} }
}); });
return { return {
onConnected(c, f) { onConnected(c, i) {
a(), o(c).connected.push(f); a(), o(c).connected.push(i);
}, },
offConnected(c, f) { offConnected(c, i) {
if (!e.has(c)) if (!e.has(c))
return; return;
let u = e.get(c), l = u.connected; let u = e.get(c), l = u.connected;
l.splice(l.indexOf(f), 1), n(c, u); l.splice(l.indexOf(i), 1), r(c, u);
}, },
onDisconnected(c, f) { onDisconnected(c, i) {
a(), o(c).disconnected.push(f); a(), o(c).disconnected.push(i);
}, },
offDisconnected(c, f) { offDisconnected(c, i) {
if (!e.has(c)) if (!e.has(c))
return; return;
let u = e.get(c), l = u.disconnected; let u = e.get(c), l = u.disconnected;
l.splice(l.indexOf(f), 1), n(c, u); l.splice(l.indexOf(i), 1), r(c, u);
} }
}; };
function n(c, f) { function r(c, i) {
f.connected.length || f.disconnect.length || (e.delete(c), i()); i.connected.length || i.disconnect.length || (e.delete(c), f());
} }
function o(c) { function o(c) {
if (e.has(c)) if (e.has(c))
return e.get(c); return e.get(c);
let f = { connected: [], disconnected: [] }; let i = { connected: [], disconnected: [] };
return e.set(c, f), f; return e.set(c, i), i;
} }
function a() { function a() {
t || (t = !0, r.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
} }
function i() { function f() {
!t || e.size || (t = !1, r.disconnect()); !t || e.size || (t = !1, n.disconnect());
} }
function s() { function s() {
return new Promise(function(c) { return new Promise(function(c) {
@ -209,27 +201,27 @@
} }
async function h(c) { async function h(c) {
e.size > 30 && await s(); e.size > 30 && await s();
let f = []; let i = [];
if (!(c instanceof Node)) if (!(c instanceof Node))
return f; return i;
for (let u of e.keys()) for (let u of e.keys())
u === c || !(u instanceof Node) || c.contains(u) && f.push(u); u === c || !(u instanceof Node) || c.contains(u) && i.push(u);
return f; return i;
} }
function E(c, f) { function E(c, i) {
for (let u of c) { for (let u of c) {
if (f && h(u).then(E), !e.has(u)) if (i && h(u).then(E), !e.has(u))
return !1; return !1;
let l = e.get(u); let l = e.get(u);
return l.connected.forEach((C) => C(u)), l.connected.length = 0, l.disconnected.length || e.delete(u), !0; return l.connected.forEach((L) => L(u)), l.connected.length = 0, l.disconnected.length || e.delete(u), !0;
} }
} }
function v(c, f) { function O(c, i) {
for (let u of c) { for (let u of c) {
if (f && h(u).then(v), !e.has(u)) if (i && h(u).then(O), !e.has(u))
return !1; return !1;
let l = e.get(u); let l = e.get(u);
return l.disconnected.forEach((C) => C(u)), l.connected.length = 0, l.disconnected.length = 0, e.delete(u), !0; return l.disconnected.forEach((L) => L(u)), l.connected.length = 0, l.disconnected.length = 0, e.delete(u), !0;
} }
} }
} }
@ -237,14 +229,14 @@
// index.js // index.js
[HTMLElement, DocumentFragment].forEach((e) => { [HTMLElement, DocumentFragment].forEach((e) => {
let { append: t } = e.prototype; let { append: t } = e.prototype;
e.prototype.append = function(...r) { e.prototype.append = function(...n) {
return t.apply(this, r), this; return t.apply(this, n), this;
}; };
}); });
// src/signals-lib.js // src/signals-lib.js
var d = Symbol.for("Signal"); var d = Symbol.for("Signal");
function R(e) { function C(e) {
try { try {
return Reflect.has(e, d); return Reflect.has(e, d);
} catch { } catch {
@ -255,25 +247,25 @@
function g(e, t) { function g(e, t) {
if (typeof e != "function") if (typeof e != "function")
return H(e, t); return H(e, t);
if (R(e)) if (C(e))
return e; return e;
let r = H(""), n = () => r(e()); let n = H(""), r = () => n(e());
return p.set(n, /* @__PURE__ */ new Set([r])), B(n), r; return p.set(r, /* @__PURE__ */ new Set([n])), Z(r), n;
} }
g.action = function(e, t, ...r) { g.action = function(e, t, ...n) {
let n = e[d], { actions: o } = n; let r = e[d], { actions: o } = r;
if (!o || !Reflect.has(o, t)) if (!o || !Reflect.has(o, t))
throw new Error(`'${e}' has no action with name '${t}'!`); throw new Error(`'${e}' has no action with name '${t}'!`);
if (o[t].apply(n, r), n.skip) if (o[t].apply(r, n), r.skip)
return Reflect.deleteProperty(n, "skip"); return Reflect.deleteProperty(r, "skip");
n.listeners.forEach((a) => a(n.value)); r.listeners.forEach((a) => a(r.value));
}; };
g.on = function e(t, r, n = {}) { g.on = function e(t, n, r = {}) {
let { signal: o } = n; let { signal: o } = r;
if (!(o && o.aborted)) { if (!(o && o.aborted)) {
if (Array.isArray(t)) if (Array.isArray(t))
return t.forEach((a) => e(a, r, n)); return t.forEach((a) => e(a, n, r));
D(t, r), o && o.addEventListener("abort", () => F(t, r)); P(t, n), o && o.addEventListener("abort", () => F(t, n));
} }
}; };
g.symbols = { g.symbols = {
@ -281,88 +273,86 @@
onclear: Symbol.for("Signal.onclear") onclear: Symbol.for("Signal.onclear")
}; };
g.clear = function(...e) { g.clear = function(...e) {
for (let r of e) { for (let n of e) {
let n = r[d], { onclear: o } = g.symbols; Reflect.deleteProperty(n, "toJSON");
n.actions && n.actions[o] && n.actions[o].call(n), t(r, n), Reflect.deleteProperty(r, d); let r = n[d], { onclear: o } = g.symbols;
r.actions && r.actions[o] && r.actions[o].call(r), t(n, r), Reflect.deleteProperty(n, d);
} }
function t(r, n) { function t(n, r) {
n.listeners.forEach((o) => { r.listeners.forEach((o) => {
if (n.listeners.delete(o), !p.has(o)) if (r.listeners.delete(o), !p.has(o))
return; return;
let a = p.get(o); let a = p.get(o);
a.delete(r), !(a.size > 1) && (g.clear(...a), p.delete(o)); a.delete(n), !(a.size > 1) && (g.clear(...a), p.delete(o));
}); });
} }
}; };
g.el = function(e, t) {
let n = document.createComment("<#reactive>"), r = document.createComment("</#reactive>"), o = document.createDocumentFragment();
o.append(n, r);
let a = (f) => {
if (!n.parentNode || !r.parentNode)
return F(e, a);
let s = t(f);
Array.isArray(s) || (s = [s]);
let h = n;
for (; (h = n.nextSibling) !== r; )
h.remove();
n.after(...s);
};
return P(e, a), a(e()), o;
};
var z = { var z = {
isReactiveAtrribute(e, t) {
return R(e);
},
isTextContent(e) { isTextContent(e) {
return m(e) === "string" || R(e) && m(V(e)) === "string"; return m(e) === "string" || C(e) && m(V(e)) === "string";
}, },
processReactiveAttribute(e, t, r, n) { processReactiveAttribute(e, t, n, r) {
return D(r, (o) => n([t, o])), r(); return C(n) ? (P(n, (o) => r([t, o])), n()) : n;
},
reactiveElement(e, t) {
let r = document.createComment("<#reactive>"), n = document.createComment("</#reactive>"), o = document.createDocumentFragment();
o.append(r, n);
let a = (i) => {
if (!r.parentNode || !n.parentNode)
return F(e, a);
let s = t(i);
Array.isArray(s) || (s = [s]);
let h = r;
for (; (h = r.nextSibling) !== n; )
h.remove();
r.after(...s);
};
return D(e, a), a(e()), o;
} }
}; };
function H(e, t) { function H(e, t) {
let r = (...n) => n.length ? U(r, n[0]) : J(r); let n = (...r) => r.length ? U(n, r[0]) : G(n);
return Z(r, e, t); return I(n, e, t);
} }
var I = Object.assign(/* @__PURE__ */ Object.create(null), { var W = Object.assign(/* @__PURE__ */ Object.create(null), {
stopPropagation() { stopPropagation() {
this.skip = !0; this.skip = !0;
} }
}); });
function Z(e, t, r) { function I(e, t, n) {
return m(r) !== "[object Object]" && (r = {}), e[d] = { return m(n) !== "[object Object]" && (n = {}), e[d] = {
value: t, value: t,
actions: r, actions: n,
listeners: /* @__PURE__ */ new Set() listeners: /* @__PURE__ */ new Set()
}, Object.setPrototypeOf(e[d], I), e; }, e.toJSON = () => e(), Object.setPrototypeOf(e[d], W), e;
} }
var S = []; var R = [];
function B(e) { function Z(e) {
let t = function() { let t = function() {
S.push(t), e(), S.pop(); R.push(t), e(), R.pop();
}; };
p.has(e) && (p.set(t, p.get(e)), p.delete(e)), t(); p.has(e) && (p.set(t, p.get(e)), p.delete(e)), t();
} }
function G() { function B() {
return S[S.length - 1]; return R[R.length - 1];
} }
function J(e) { function G(e) {
if (!e[d]) if (!e[d])
return; return;
let { value: t, listeners: r } = e[d], n = G(); let { value: t, listeners: n } = e[d], r = B();
return n && r.add(n), p.has(n) && p.get(n).add(e), t; return r && n.add(r), p.has(r) && p.get(r).add(e), t;
} }
function U(e, t) { function U(e, t) {
if (!e[d]) if (!e[d])
return; return;
let r = e[d]; let n = e[d];
if (r.value !== t) if (n.value !== t)
return r.value = t, r.listeners.forEach((n) => n(t)), t; return n.value = t, n.listeners.forEach((r) => r(t)), t;
} }
function V(e) { function V(e) {
return e[d].value; return e[d].value;
} }
function D(e, t) { function P(e, t) {
return e[d].listeners.add(t); return e[d].listeners.add(t);
} }
function F(e, t) { function F(e, t) {
@ -370,19 +360,19 @@
} }
// src/signals.js // src/signals.js
L(z); j(z);
globalThis.dde= { globalThis.dde= {
S: g, S: g,
assign: A, assign: y,
classListDeclarative: $, classListDeclarative: $,
createElement: te, createElement: te,
el: te, el: te,
empty: ne, empty: ne,
isSignal: R, isSignal: C,
namespace: ee, namespace: ee,
on: M, on: M,
registerReactivity: L registerReactivity: j
}; };
})(); })();

140
dist/dde.js vendored
View File

@ -8,99 +8,91 @@
// src/signals-common.js // src/signals-common.js
var p = { var p = {
isReactiveAtrribute(e, t) {
return !1;
},
isTextContent(e) { isTextContent(e) {
return N(e) !== "[object Object]"; return N(e) !== "[object Object]";
}, },
processReactiveAttribute(e, t, r, n) { processReactiveAttribute(e, t, r, n) {
return !1; return r;
},
reactiveElement(e, ...t) {
return null;
} }
}; };
function A(e, t = !0) { function D(e, t = !0) {
return t ? Object.assign(p, e) : (Object.setPrototypeOf(e, p), e); return t ? Object.assign(p, e) : (Object.setPrototypeOf(e, p), e);
} }
function O(e) { function w(e) {
return p.isPrototypeOf(e) && e !== p ? e : p; return p.isPrototypeOf(e) && e !== p ? e : p;
} }
// src/dom.js // src/dom.js
var x = "html"; var E = "html";
function z(e) { function z(e) {
return x = e === "svg" ? "http://www.w3.org/2000/svg" : e, { return E = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(t) { append(t) {
return x = "html", t; return E = "html", t;
} }
}; };
} }
function F(e, t, ...r) { function F(e, t, ...r) {
let n = O(this), f; let n = w(this), i;
if (e === "<>") {
if (n.isReactiveAtrribute(t))
return n.reactiveElement(t, ...r);
f = document.createDocumentFragment();
}
switch (n.isTextContent(t) && (t = { textContent: t }), !0) { switch (n.isTextContent(t) && (t = { textContent: t }), !0) {
case typeof e == "function": case typeof e == "function":
f = e(t || void 0); i = e(t || void 0);
break; break;
case e === "#text": case e === "#text":
f = w(document.createTextNode(""), t); i = x(document.createTextNode(""), t);
break; break;
case x !== "html": case e === "<>":
f = w(document.createElementNS(x, e), t); i = x(document.createDocumentFragment(), t);
break; break;
case !f: case E !== "html":
f = w(document.createElement(e), t); i = x(document.createElementNS(E, e), t);
break;
case !i:
i = x(document.createElement(e), t);
} }
return r.forEach((d) => d(f)), f; return r.forEach((d) => d(i)), i;
} }
var h = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')); var h = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]'));
function w(e, ...t) { function x(e, ...t) {
let r = O(this); let r = w(this);
if (!t.length) if (!t.length)
return e; return e;
let n = e instanceof SVGElement, f = (n ? M : j).bind(null, e, "Attribute"); let n = e instanceof SVGElement, i = (n ? M : j).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function d([i, u]) { return Object.entries(Object.assign({}, ...t)).forEach(function d([u, f]) {
r.isReactiveAtrribute(u, i) && (u = r.processReactiveAttribute(e, i, u, d)); f = r.processReactiveAttribute(e, u, f, d);
let [l] = i; let [l] = u;
if (l === "=") if (l === "=")
return f(i.slice(1), u); return i(u.slice(1), f);
if (l === ".") if (l === ".")
return C(e, i.slice(1), u); return C(e, u.slice(1), f);
if (typeof u == "object") if (typeof f == "object")
switch (i) { switch (u) {
case "style": case "style":
return m(u, j.bind(null, e.style, "Property")); return m(f, j.bind(null, e.style, "Property"));
case "dataset": case "dataset":
return m(u, C.bind(null, e.dataset)); return m(f, C.bind(null, e.dataset));
case "ariaset": case "ariaset":
return m(u, (g, b) => f("aria-" + g, b)); return m(f, (g, b) => i("aria-" + g, b));
case "classList": case "classList":
return T(e, u); return R(e, f);
default: default:
return Reflect.set(e, i, u); return Reflect.set(e, u, f);
} }
if (/(aria|data)([A-Z])/.test(i)) if (/(aria|data)([A-Z])/.test(u))
return i = i.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), f(i, u); return u = u.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(u, f);
switch (i) { switch (u) {
case "href": case "href":
return f(i, u); return i(u, f);
case "xlink:href": case "xlink:href":
return f(i, u, "http://www.w3.org/1999/xlink"); return i(u, f, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
if (!n) if (!n)
break; break;
return e.appendChild(document.createTextNode(u)); return e.appendChild(document.createTextNode(f));
} }
return D(e, i) ? C(e, i, u) : f(i, u); return A(e, u) ? C(e, u, f) : i(u, f);
}), e; }), e;
} }
function T(e, t) { function R(e, t) {
return typeof t != "object" || m( return typeof t != "object" || m(
t, t,
(r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n) (r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n)
@ -109,21 +101,21 @@
function I(e) { function I(e) {
return Array.from(e.children).forEach((t) => t.remove()), e; return Array.from(e.children).forEach((t) => t.remove()), e;
} }
function D(e, t) { function A(e, t) {
let r = "HTMLElement," + t; let r = "HTMLElement," + t;
if (e instanceof HTMLElement && h.has(r)) if (e instanceof HTMLElement && h.has(r))
return h.get(r); return h.get(r);
let n = e.nodeName + "," + t; let n = e.nodeName + "," + t;
if (h.has(n)) if (h.has(n))
return h.get(n); return h.get(n);
let [f, d, i] = R(e, t), u = !L(f.set); let [i, d, u] = y(e, t), f = !L(i.set);
return (!u || d) && h.set(i === HTMLElement.prototype ? r : n, u), u; return (!f || d) && h.set(u === HTMLElement.prototype ? r : n, f), f;
} }
function R(e, t, r = 0) { function y(e, t, r = 0) {
if (e = Object.getPrototypeOf(e), !e) if (e = Object.getPrototypeOf(e), !e)
return [{}, r, e]; return [{}, r, e];
let n = Object.getOwnPropertyDescriptor(e, t); let n = Object.getOwnPropertyDescriptor(e, t);
return n ? [n, r, e] : R(e, t, r + 1); return n ? [n, r, e] : y(e, t, r + 1);
} }
function m(e, t) { function m(e, t) {
return Object.entries(e).forEach(([r, n]) => t(r, n)); return Object.entries(e).forEach(([r, n]) => t(r, n));
@ -134,26 +126,26 @@
function j(e, t, r, n) { function j(e, t, r, n) {
return e[(L(n) ? "remove" : "set") + t](r, n); return e[(L(n) ? "remove" : "set") + t](r, n);
} }
function M(e, t, r, n, f = null) { function M(e, t, r, n, i = null) {
return e[(L(n) ? "remove" : "set") + t + "NS"](f, r, n); return e[(L(n) ? "remove" : "set") + t + "NS"](i, r, n);
} }
function C(e, t, r) { function C(e, t, r) {
return Reflect.set(e, t, r); return Reflect.set(e, t, r);
} }
// src/events.js // src/events.js
function y(e, t, r) { function T(e, t, r) {
return (n) => (n.addEventListener(e, t, r), n); return (n) => (n.addEventListener(e, t, r), n);
} }
var E = _(); var O = _();
y.connected = function(e, t) { T.connected = function(e, t) {
return function(n) { return function(n) {
E.onConnected(n, e), t && t.signal && t.signal.addEventListener("abort", () => E.offConnected(n, e)); O.onConnected(n, e), t && t.signal && t.signal.addEventListener("abort", () => O.offConnected(n, e));
}; };
}; };
y.disconnected = function(e, t) { T.disconnected = function(e, t) {
return function(n) { return function(n) {
E.onDisconnected(n, e), t && t.signal && t.signal.addEventListener("abort", () => E.offDisconnected(n, e)); O.onDisconnected(n, e), t && t.signal && t.signal.addEventListener("abort", () => O.offDisconnected(n, e));
}; };
}; };
function _() { function _() {
@ -161,15 +153,15 @@
for (let c of o) for (let c of o)
if (c.type === "childList") { if (c.type === "childList") {
if (g(c.addedNodes, !0)) { if (g(c.addedNodes, !0)) {
i(); u();
continue; continue;
} }
b(c.removedNodes, !0) && i(); b(c.removedNodes, !0) && u();
} }
}); });
return { return {
onConnected(o, c) { onConnected(o, c) {
d(), f(o).connected.push(c); d(), i(o).connected.push(c);
}, },
offConnected(o, c) { offConnected(o, c) {
if (!e.has(o)) if (!e.has(o))
@ -178,7 +170,7 @@
a.splice(a.indexOf(c), 1), n(o, s); a.splice(a.indexOf(c), 1), n(o, s);
}, },
onDisconnected(o, c) { onDisconnected(o, c) {
d(), f(o).disconnected.push(c); d(), i(o).disconnected.push(c);
}, },
offDisconnected(o, c) { offDisconnected(o, c) {
if (!e.has(o)) if (!e.has(o))
@ -188,9 +180,9 @@
} }
}; };
function n(o, c) { function n(o, c) {
c.connected.length || c.disconnect.length || (e.delete(o), i()); c.connected.length || c.disconnect.length || (e.delete(o), u());
} }
function f(o) { function i(o) {
if (e.has(o)) if (e.has(o))
return e.get(o); return e.get(o);
let c = { connected: [], disconnected: [] }; let c = { connected: [], disconnected: [] };
@ -199,16 +191,16 @@
function d() { function d() {
t || (t = !0, r.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, r.observe(document.body, { childList: !0, subtree: !0 }));
} }
function i() { function u() {
!t || e.size || (t = !1, r.disconnect()); !t || e.size || (t = !1, r.disconnect());
} }
function u() { function f() {
return new Promise(function(o) { return new Promise(function(o) {
(requestIdleCallback || requestAnimationFrame)(o); (requestIdleCallback || requestAnimationFrame)(o);
}); });
} }
async function l(o) { async function l(o) {
e.size > 30 && await u(); e.size > 30 && await f();
let c = []; let c = [];
if (!(o instanceof Node)) if (!(o instanceof Node))
return c; return c;
@ -243,14 +235,14 @@
}); });
globalThis.dde= { globalThis.dde= {
assign: w, assign: x,
classListDeclarative: T, classListDeclarative: R,
createElement: F, createElement: F,
el: F, el: F,
empty: I, empty: I,
namespace: z, namespace: z,
on: y, on: T,
registerReactivity: A registerReactivity: D
}; };
})(); })();

View File

@ -6,199 +6,191 @@ function m(e) {
// src/signals-common.js // src/signals-common.js
var b = { var b = {
isReactiveAtrribute(e, t) {
return !1;
},
isTextContent(e) { isTextContent(e) {
return m(e) !== "[object Object]"; return m(e) !== "[object Object]";
}, },
processReactiveAttribute(e, t, r, n) { processReactiveAttribute(e, t, n, r) {
return !1; return n;
},
reactiveElement(e, ...t) {
return null;
} }
}; };
function L(e, t = !0) { function j(e, t = !0) {
return t ? Object.assign(b, e) : (Object.setPrototypeOf(e, b), e); return t ? Object.assign(b, e) : (Object.setPrototypeOf(e, b), e);
} }
function j(e) { function N(e) {
return b.isPrototypeOf(e) && e !== b ? e : b; return b.isPrototypeOf(e) && e !== b ? e : b;
} }
// src/dom.js // src/dom.js
var w = "html"; var v = "html";
function ee(e) { function ee(e) {
return w = e === "svg" ? "http://www.w3.org/2000/svg" : e, { return v = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(t) { append(t) {
return w = "html", t; return v = "html", t;
} }
}; };
} }
function te(e, t, ...r) { function te(e, t, ...n) {
let n = j(this), o; let r = N(this), o;
if (e === "<>") { switch (r.isTextContent(t) && (t = { textContent: t }), !0) {
if (n.isReactiveAtrribute(t))
return n.reactiveElement(t, ...r);
o = document.createDocumentFragment();
}
switch (n.isTextContent(t) && (t = { textContent: t }), !0) {
case typeof e == "function": case typeof e == "function":
o = e(t || void 0); o = e(t || void 0);
break; break;
case e === "#text": case e === "#text":
o = A(document.createTextNode(""), t); o = y(document.createTextNode(""), t);
break; break;
case w !== "html": case e === "<>":
o = A(document.createElementNS(w, e), t); o = y(document.createDocumentFragment(), t);
break;
case v !== "html":
o = y(document.createElementNS(v, e), t);
break; break;
case !o: case !o:
o = A(document.createElement(e), t); o = y(document.createElement(e), t);
} }
return r.forEach((a) => a(o)), o; return n.forEach((a) => a(o)), o;
} }
var x = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')); var x = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]'));
function A(e, ...t) { function y(e, ...t) {
let r = j(this); let n = N(this);
if (!t.length) if (!t.length)
return e; return e;
let n = e instanceof SVGElement, o = (n ? q : P).bind(null, e, "Attribute"); let r = e instanceof SVGElement, o = (r ? q : D).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function a([i, s]) { return Object.entries(Object.assign({}, ...t)).forEach(function a([f, s]) {
r.isReactiveAtrribute(s, i) && (s = r.processReactiveAttribute(e, i, s, a)); s = n.processReactiveAttribute(e, f, s, a);
let [h] = i; let [h] = f;
if (h === "=") if (h === "=")
return o(i.slice(1), s); return o(f.slice(1), s);
if (h === ".") if (h === ".")
return N(e, i.slice(1), s); return _(e, f.slice(1), s);
if (typeof s == "object") if (typeof s == "object")
switch (i) { switch (f) {
case "style": case "style":
return y(s, P.bind(null, e.style, "Property")); return w(s, D.bind(null, e.style, "Property"));
case "dataset": case "dataset":
return y(s, N.bind(null, e.dataset)); return w(s, _.bind(null, e.dataset));
case "ariaset": case "ariaset":
return y(s, (E, v) => o("aria-" + E, v)); return w(s, (E, O) => o("aria-" + E, O));
case "classList": case "classList":
return $(e, s); return $(e, s);
default: default:
return Reflect.set(e, i, s); return Reflect.set(e, f, s);
} }
if (/(aria|data)([A-Z])/.test(i)) if (/(aria|data)([A-Z])/.test(f))
return i = i.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(i, s); return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(f, s);
switch (i) { switch (f) {
case "href": case "href":
return o(i, s); return o(f, s);
case "xlink:href": case "xlink:href":
return o(i, s, "http://www.w3.org/1999/xlink"); return o(f, s, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
if (!n) if (!r)
break; break;
return e.appendChild(document.createTextNode(s)); return e.appendChild(document.createTextNode(s));
} }
return k(e, i) ? N(e, i, s) : o(i, s); return k(e, f) ? _(e, f, s) : o(f, s);
}), e; }), e;
} }
function $(e, t) { function $(e, t) {
return typeof t != "object" || y( return typeof t != "object" || w(
t, t,
(r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n) (n, r) => e.classList.toggle(n, r === -1 ? void 0 : !!r)
), e; ), e;
} }
function ne(e) { function ne(e) {
return Array.from(e.children).forEach((t) => t.remove()), e; return Array.from(e.children).forEach((t) => t.remove()), e;
} }
function k(e, t) { function k(e, t) {
let r = "HTMLElement," + t; let n = "HTMLElement," + t;
if (e instanceof HTMLElement && x.has(r)) if (e instanceof HTMLElement && x.has(n))
return x.get(r);
let n = e.nodeName + "," + t;
if (x.has(n))
return x.get(n); return x.get(n);
let [o, a, i] = T(e, t), s = !_(o.set); let r = e.nodeName + "," + t;
return (!s || a) && x.set(i === HTMLElement.prototype ? r : n, s), s; if (x.has(r))
return x.get(r);
let [o, a, f] = T(e, t), s = !A(o.set);
return (!s || a) && x.set(f === HTMLElement.prototype ? n : r, s), s;
} }
function T(e, t, r = 0) { function T(e, t, n = 0) {
if (e = Object.getPrototypeOf(e), !e) if (e = Object.getPrototypeOf(e), !e)
return [{}, r, e]; return [{}, n, e];
let n = Object.getOwnPropertyDescriptor(e, t); let r = Object.getOwnPropertyDescriptor(e, t);
return n ? [n, r, e] : T(e, t, r + 1); return r ? [r, n, e] : T(e, t, n + 1);
} }
function y(e, t) { function w(e, t) {
return Object.entries(e).forEach(([r, n]) => t(r, n)); return Object.entries(e).forEach(([n, r]) => t(n, r));
} }
function _(e) { function A(e) {
return typeof e > "u"; return typeof e > "u";
} }
function P(e, t, r, n) { function D(e, t, n, r) {
return e[(_(n) ? "remove" : "set") + t](r, n); return e[(A(r) ? "remove" : "set") + t](n, r);
} }
function q(e, t, r, n, o = null) { function q(e, t, n, r, o = null) {
return e[(_(n) ? "remove" : "set") + t + "NS"](o, r, n); return e[(A(r) ? "remove" : "set") + t + "NS"](o, n, r);
} }
function N(e, t, r) { function _(e, t, n) {
return Reflect.set(e, t, r); return Reflect.set(e, t, n);
} }
// src/events.js // src/events.js
function M(e, t, r) { function M(e, t, n) {
return (n) => (n.addEventListener(e, t, r), n); return (r) => (r.addEventListener(e, t, n), r);
} }
var O = W(); var S = J();
M.connected = function(e, t) { M.connected = function(e, t) {
return function(n) { return function(r) {
O.onConnected(n, e), t && t.signal && t.signal.addEventListener("abort", () => O.offConnected(n, e)); S.onConnected(r, e), t && t.signal && t.signal.addEventListener("abort", () => S.offConnected(r, e));
}; };
}; };
M.disconnected = function(e, t) { M.disconnected = function(e, t) {
return function(n) { return function(r) {
O.onDisconnected(n, e), t && t.signal && t.signal.addEventListener("abort", () => O.offDisconnected(n, e)); S.onDisconnected(r, e), t && t.signal && t.signal.addEventListener("abort", () => S.offDisconnected(r, e));
}; };
}; };
function W() { function J() {
let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(c) { let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) {
for (let f of c) for (let i of c)
if (f.type === "childList") { if (i.type === "childList") {
if (E(f.addedNodes, !0)) { if (E(i.addedNodes, !0)) {
i(); f();
continue; continue;
} }
v(f.removedNodes, !0) && i(); O(i.removedNodes, !0) && f();
} }
}); });
return { return {
onConnected(c, f) { onConnected(c, i) {
a(), o(c).connected.push(f); a(), o(c).connected.push(i);
}, },
offConnected(c, f) { offConnected(c, i) {
if (!e.has(c)) if (!e.has(c))
return; return;
let u = e.get(c), l = u.connected; let u = e.get(c), l = u.connected;
l.splice(l.indexOf(f), 1), n(c, u); l.splice(l.indexOf(i), 1), r(c, u);
}, },
onDisconnected(c, f) { onDisconnected(c, i) {
a(), o(c).disconnected.push(f); a(), o(c).disconnected.push(i);
}, },
offDisconnected(c, f) { offDisconnected(c, i) {
if (!e.has(c)) if (!e.has(c))
return; return;
let u = e.get(c), l = u.disconnected; let u = e.get(c), l = u.disconnected;
l.splice(l.indexOf(f), 1), n(c, u); l.splice(l.indexOf(i), 1), r(c, u);
} }
}; };
function n(c, f) { function r(c, i) {
f.connected.length || f.disconnect.length || (e.delete(c), i()); i.connected.length || i.disconnect.length || (e.delete(c), f());
} }
function o(c) { function o(c) {
if (e.has(c)) if (e.has(c))
return e.get(c); return e.get(c);
let f = { connected: [], disconnected: [] }; let i = { connected: [], disconnected: [] };
return e.set(c, f), f; return e.set(c, i), i;
} }
function a() { function a() {
t || (t = !0, r.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
} }
function i() { function f() {
!t || e.size || (t = !1, r.disconnect()); !t || e.size || (t = !1, n.disconnect());
} }
function s() { function s() {
return new Promise(function(c) { return new Promise(function(c) {
@ -207,27 +199,27 @@ function W() {
} }
async function h(c) { async function h(c) {
e.size > 30 && await s(); e.size > 30 && await s();
let f = []; let i = [];
if (!(c instanceof Node)) if (!(c instanceof Node))
return f; return i;
for (let u of e.keys()) for (let u of e.keys())
u === c || !(u instanceof Node) || c.contains(u) && f.push(u); u === c || !(u instanceof Node) || c.contains(u) && i.push(u);
return f; return i;
} }
function E(c, f) { function E(c, i) {
for (let u of c) { for (let u of c) {
if (f && h(u).then(E), !e.has(u)) if (i && h(u).then(E), !e.has(u))
return !1; return !1;
let l = e.get(u); let l = e.get(u);
return l.connected.forEach((C) => C(u)), l.connected.length = 0, l.disconnected.length || e.delete(u), !0; return l.connected.forEach((L) => L(u)), l.connected.length = 0, l.disconnected.length || e.delete(u), !0;
} }
} }
function v(c, f) { function O(c, i) {
for (let u of c) { for (let u of c) {
if (f && h(u).then(v), !e.has(u)) if (i && h(u).then(O), !e.has(u))
return !1; return !1;
let l = e.get(u); let l = e.get(u);
return l.disconnected.forEach((C) => C(u)), l.connected.length = 0, l.disconnected.length = 0, e.delete(u), !0; return l.disconnected.forEach((L) => L(u)), l.connected.length = 0, l.disconnected.length = 0, e.delete(u), !0;
} }
} }
} }
@ -235,14 +227,14 @@ function W() {
// index.js // index.js
[HTMLElement, DocumentFragment].forEach((e) => { [HTMLElement, DocumentFragment].forEach((e) => {
let { append: t } = e.prototype; let { append: t } = e.prototype;
e.prototype.append = function(...r) { e.prototype.append = function(...n) {
return t.apply(this, r), this; return t.apply(this, n), this;
}; };
}); });
// src/signals-lib.js // src/signals-lib.js
var d = Symbol.for("Signal"); var d = Symbol.for("Signal");
function R(e) { function C(e) {
try { try {
return Reflect.has(e, d); return Reflect.has(e, d);
} catch { } catch {
@ -253,25 +245,25 @@ var p = /* @__PURE__ */ new WeakMap();
function g(e, t) { function g(e, t) {
if (typeof e != "function") if (typeof e != "function")
return H(e, t); return H(e, t);
if (R(e)) if (C(e))
return e; return e;
let r = H(""), n = () => r(e()); let n = H(""), r = () => n(e());
return p.set(n, /* @__PURE__ */ new Set([r])), B(n), r; return p.set(r, /* @__PURE__ */ new Set([n])), Z(r), n;
} }
g.action = function(e, t, ...r) { g.action = function(e, t, ...n) {
let n = e[d], { actions: o } = n; let r = e[d], { actions: o } = r;
if (!o || !Reflect.has(o, t)) if (!o || !Reflect.has(o, t))
throw new Error(`'${e}' has no action with name '${t}'!`); throw new Error(`'${e}' has no action with name '${t}'!`);
if (o[t].apply(n, r), n.skip) if (o[t].apply(r, n), r.skip)
return Reflect.deleteProperty(n, "skip"); return Reflect.deleteProperty(r, "skip");
n.listeners.forEach((a) => a(n.value)); r.listeners.forEach((a) => a(r.value));
}; };
g.on = function e(t, r, n = {}) { g.on = function e(t, n, r = {}) {
let { signal: o } = n; let { signal: o } = r;
if (!(o && o.aborted)) { if (!(o && o.aborted)) {
if (Array.isArray(t)) if (Array.isArray(t))
return t.forEach((a) => e(a, r, n)); return t.forEach((a) => e(a, n, r));
D(t, r), o && o.addEventListener("abort", () => F(t, r)); P(t, n), o && o.addEventListener("abort", () => F(t, n));
} }
}; };
g.symbols = { g.symbols = {
@ -279,88 +271,86 @@ g.symbols = {
onclear: Symbol.for("Signal.onclear") onclear: Symbol.for("Signal.onclear")
}; };
g.clear = function(...e) { g.clear = function(...e) {
for (let r of e) { for (let n of e) {
let n = r[d], { onclear: o } = g.symbols; Reflect.deleteProperty(n, "toJSON");
n.actions && n.actions[o] && n.actions[o].call(n), t(r, n), Reflect.deleteProperty(r, d); let r = n[d], { onclear: o } = g.symbols;
r.actions && r.actions[o] && r.actions[o].call(r), t(n, r), Reflect.deleteProperty(n, d);
} }
function t(r, n) { function t(n, r) {
n.listeners.forEach((o) => { r.listeners.forEach((o) => {
if (n.listeners.delete(o), !p.has(o)) if (r.listeners.delete(o), !p.has(o))
return; return;
let a = p.get(o); let a = p.get(o);
a.delete(r), !(a.size > 1) && (g.clear(...a), p.delete(o)); a.delete(n), !(a.size > 1) && (g.clear(...a), p.delete(o));
}); });
} }
}; };
g.el = function(e, t) {
let n = document.createComment("<#reactive>"), r = document.createComment("</#reactive>"), o = document.createDocumentFragment();
o.append(n, r);
let a = (f) => {
if (!n.parentNode || !r.parentNode)
return F(e, a);
let s = t(f);
Array.isArray(s) || (s = [s]);
let h = n;
for (; (h = n.nextSibling) !== r; )
h.remove();
n.after(...s);
};
return P(e, a), a(e()), o;
};
var z = { var z = {
isReactiveAtrribute(e, t) {
return R(e);
},
isTextContent(e) { isTextContent(e) {
return m(e) === "string" || R(e) && m(V(e)) === "string"; return m(e) === "string" || C(e) && m(V(e)) === "string";
}, },
processReactiveAttribute(e, t, r, n) { processReactiveAttribute(e, t, n, r) {
return D(r, (o) => n([t, o])), r(); return C(n) ? (P(n, (o) => r([t, o])), n()) : n;
},
reactiveElement(e, t) {
let r = document.createComment("<#reactive>"), n = document.createComment("</#reactive>"), o = document.createDocumentFragment();
o.append(r, n);
let a = (i) => {
if (!r.parentNode || !n.parentNode)
return F(e, a);
let s = t(i);
Array.isArray(s) || (s = [s]);
let h = r;
for (; (h = r.nextSibling) !== n; )
h.remove();
r.after(...s);
};
return D(e, a), a(e()), o;
} }
}; };
function H(e, t) { function H(e, t) {
let r = (...n) => n.length ? U(r, n[0]) : J(r); let n = (...r) => r.length ? U(n, r[0]) : G(n);
return Z(r, e, t); return I(n, e, t);
} }
var I = Object.assign(/* @__PURE__ */ Object.create(null), { var W = Object.assign(/* @__PURE__ */ Object.create(null), {
stopPropagation() { stopPropagation() {
this.skip = !0; this.skip = !0;
} }
}); });
function Z(e, t, r) { function I(e, t, n) {
return m(r) !== "[object Object]" && (r = {}), e[d] = { return m(n) !== "[object Object]" && (n = {}), e[d] = {
value: t, value: t,
actions: r, actions: n,
listeners: /* @__PURE__ */ new Set() listeners: /* @__PURE__ */ new Set()
}, Object.setPrototypeOf(e[d], I), e; }, e.toJSON = () => e(), Object.setPrototypeOf(e[d], W), e;
} }
var S = []; var R = [];
function B(e) { function Z(e) {
let t = function() { let t = function() {
S.push(t), e(), S.pop(); R.push(t), e(), R.pop();
}; };
p.has(e) && (p.set(t, p.get(e)), p.delete(e)), t(); p.has(e) && (p.set(t, p.get(e)), p.delete(e)), t();
} }
function G() { function B() {
return S[S.length - 1]; return R[R.length - 1];
} }
function J(e) { function G(e) {
if (!e[d]) if (!e[d])
return; return;
let { value: t, listeners: r } = e[d], n = G(); let { value: t, listeners: n } = e[d], r = B();
return n && r.add(n), p.has(n) && p.get(n).add(e), t; return r && n.add(r), p.has(r) && p.get(r).add(e), t;
} }
function U(e, t) { function U(e, t) {
if (!e[d]) if (!e[d])
return; return;
let r = e[d]; let n = e[d];
if (r.value !== t) if (n.value !== t)
return r.value = t, r.listeners.forEach((n) => n(t)), t; return n.value = t, n.listeners.forEach((r) => r(t)), t;
} }
function V(e) { function V(e) {
return e[d].value; return e[d].value;
} }
function D(e, t) { function P(e, t) {
return e[d].listeners.add(t); return e[d].listeners.add(t);
} }
function F(e, t) { function F(e, t) {
@ -368,16 +358,16 @@ function F(e, t) {
} }
// src/signals.js // src/signals.js
L(z); j(z);
export { export {
g as S, g as S,
A as assign, y as assign,
$ as classListDeclarative, $ as classListDeclarative,
te as createElement, te as createElement,
te as el, te as el,
ne as empty, ne as empty,
R as isSignal, C as isSignal,
ee as namespace, ee as namespace,
M as on, M as on,
L as registerReactivity j as registerReactivity
}; };

140
dist/esm.js vendored
View File

@ -6,99 +6,91 @@ function N(e) {
// src/signals-common.js // src/signals-common.js
var p = { var p = {
isReactiveAtrribute(e, t) {
return !1;
},
isTextContent(e) { isTextContent(e) {
return N(e) !== "[object Object]"; return N(e) !== "[object Object]";
}, },
processReactiveAttribute(e, t, r, n) { processReactiveAttribute(e, t, r, n) {
return !1; return r;
},
reactiveElement(e, ...t) {
return null;
} }
}; };
function A(e, t = !0) { function D(e, t = !0) {
return t ? Object.assign(p, e) : (Object.setPrototypeOf(e, p), e); return t ? Object.assign(p, e) : (Object.setPrototypeOf(e, p), e);
} }
function O(e) { function w(e) {
return p.isPrototypeOf(e) && e !== p ? e : p; return p.isPrototypeOf(e) && e !== p ? e : p;
} }
// src/dom.js // src/dom.js
var x = "html"; var E = "html";
function z(e) { function z(e) {
return x = e === "svg" ? "http://www.w3.org/2000/svg" : e, { return E = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(t) { append(t) {
return x = "html", t; return E = "html", t;
} }
}; };
} }
function F(e, t, ...r) { function F(e, t, ...r) {
let n = O(this), f; let n = w(this), i;
if (e === "<>") {
if (n.isReactiveAtrribute(t))
return n.reactiveElement(t, ...r);
f = document.createDocumentFragment();
}
switch (n.isTextContent(t) && (t = { textContent: t }), !0) { switch (n.isTextContent(t) && (t = { textContent: t }), !0) {
case typeof e == "function": case typeof e == "function":
f = e(t || void 0); i = e(t || void 0);
break; break;
case e === "#text": case e === "#text":
f = w(document.createTextNode(""), t); i = x(document.createTextNode(""), t);
break; break;
case x !== "html": case e === "<>":
f = w(document.createElementNS(x, e), t); i = x(document.createDocumentFragment(), t);
break; break;
case !f: case E !== "html":
f = w(document.createElement(e), t); i = x(document.createElementNS(E, e), t);
break;
case !i:
i = x(document.createElement(e), t);
} }
return r.forEach((d) => d(f)), f; return r.forEach((d) => d(i)), i;
} }
var h = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')); var h = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]'));
function w(e, ...t) { function x(e, ...t) {
let r = O(this); let r = w(this);
if (!t.length) if (!t.length)
return e; return e;
let n = e instanceof SVGElement, f = (n ? M : j).bind(null, e, "Attribute"); let n = e instanceof SVGElement, i = (n ? M : j).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function d([i, u]) { return Object.entries(Object.assign({}, ...t)).forEach(function d([u, f]) {
r.isReactiveAtrribute(u, i) && (u = r.processReactiveAttribute(e, i, u, d)); f = r.processReactiveAttribute(e, u, f, d);
let [l] = i; let [l] = u;
if (l === "=") if (l === "=")
return f(i.slice(1), u); return i(u.slice(1), f);
if (l === ".") if (l === ".")
return C(e, i.slice(1), u); return C(e, u.slice(1), f);
if (typeof u == "object") if (typeof f == "object")
switch (i) { switch (u) {
case "style": case "style":
return m(u, j.bind(null, e.style, "Property")); return m(f, j.bind(null, e.style, "Property"));
case "dataset": case "dataset":
return m(u, C.bind(null, e.dataset)); return m(f, C.bind(null, e.dataset));
case "ariaset": case "ariaset":
return m(u, (g, b) => f("aria-" + g, b)); return m(f, (g, b) => i("aria-" + g, b));
case "classList": case "classList":
return T(e, u); return R(e, f);
default: default:
return Reflect.set(e, i, u); return Reflect.set(e, u, f);
} }
if (/(aria|data)([A-Z])/.test(i)) if (/(aria|data)([A-Z])/.test(u))
return i = i.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), f(i, u); return u = u.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(u, f);
switch (i) { switch (u) {
case "href": case "href":
return f(i, u); return i(u, f);
case "xlink:href": case "xlink:href":
return f(i, u, "http://www.w3.org/1999/xlink"); return i(u, f, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
if (!n) if (!n)
break; break;
return e.appendChild(document.createTextNode(u)); return e.appendChild(document.createTextNode(f));
} }
return D(e, i) ? C(e, i, u) : f(i, u); return A(e, u) ? C(e, u, f) : i(u, f);
}), e; }), e;
} }
function T(e, t) { function R(e, t) {
return typeof t != "object" || m( return typeof t != "object" || m(
t, t,
(r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n) (r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n)
@ -107,21 +99,21 @@ function T(e, t) {
function I(e) { function I(e) {
return Array.from(e.children).forEach((t) => t.remove()), e; return Array.from(e.children).forEach((t) => t.remove()), e;
} }
function D(e, t) { function A(e, t) {
let r = "HTMLElement," + t; let r = "HTMLElement," + t;
if (e instanceof HTMLElement && h.has(r)) if (e instanceof HTMLElement && h.has(r))
return h.get(r); return h.get(r);
let n = e.nodeName + "," + t; let n = e.nodeName + "," + t;
if (h.has(n)) if (h.has(n))
return h.get(n); return h.get(n);
let [f, d, i] = R(e, t), u = !L(f.set); let [i, d, u] = y(e, t), f = !L(i.set);
return (!u || d) && h.set(i === HTMLElement.prototype ? r : n, u), u; return (!f || d) && h.set(u === HTMLElement.prototype ? r : n, f), f;
} }
function R(e, t, r = 0) { function y(e, t, r = 0) {
if (e = Object.getPrototypeOf(e), !e) if (e = Object.getPrototypeOf(e), !e)
return [{}, r, e]; return [{}, r, e];
let n = Object.getOwnPropertyDescriptor(e, t); let n = Object.getOwnPropertyDescriptor(e, t);
return n ? [n, r, e] : R(e, t, r + 1); return n ? [n, r, e] : y(e, t, r + 1);
} }
function m(e, t) { function m(e, t) {
return Object.entries(e).forEach(([r, n]) => t(r, n)); return Object.entries(e).forEach(([r, n]) => t(r, n));
@ -132,26 +124,26 @@ function L(e) {
function j(e, t, r, n) { function j(e, t, r, n) {
return e[(L(n) ? "remove" : "set") + t](r, n); return e[(L(n) ? "remove" : "set") + t](r, n);
} }
function M(e, t, r, n, f = null) { function M(e, t, r, n, i = null) {
return e[(L(n) ? "remove" : "set") + t + "NS"](f, r, n); return e[(L(n) ? "remove" : "set") + t + "NS"](i, r, n);
} }
function C(e, t, r) { function C(e, t, r) {
return Reflect.set(e, t, r); return Reflect.set(e, t, r);
} }
// src/events.js // src/events.js
function y(e, t, r) { function T(e, t, r) {
return (n) => (n.addEventListener(e, t, r), n); return (n) => (n.addEventListener(e, t, r), n);
} }
var E = _(); var O = _();
y.connected = function(e, t) { T.connected = function(e, t) {
return function(n) { return function(n) {
E.onConnected(n, e), t && t.signal && t.signal.addEventListener("abort", () => E.offConnected(n, e)); O.onConnected(n, e), t && t.signal && t.signal.addEventListener("abort", () => O.offConnected(n, e));
}; };
}; };
y.disconnected = function(e, t) { T.disconnected = function(e, t) {
return function(n) { return function(n) {
E.onDisconnected(n, e), t && t.signal && t.signal.addEventListener("abort", () => E.offDisconnected(n, e)); O.onDisconnected(n, e), t && t.signal && t.signal.addEventListener("abort", () => O.offDisconnected(n, e));
}; };
}; };
function _() { function _() {
@ -159,15 +151,15 @@ function _() {
for (let c of o) for (let c of o)
if (c.type === "childList") { if (c.type === "childList") {
if (g(c.addedNodes, !0)) { if (g(c.addedNodes, !0)) {
i(); u();
continue; continue;
} }
b(c.removedNodes, !0) && i(); b(c.removedNodes, !0) && u();
} }
}); });
return { return {
onConnected(o, c) { onConnected(o, c) {
d(), f(o).connected.push(c); d(), i(o).connected.push(c);
}, },
offConnected(o, c) { offConnected(o, c) {
if (!e.has(o)) if (!e.has(o))
@ -176,7 +168,7 @@ function _() {
a.splice(a.indexOf(c), 1), n(o, s); a.splice(a.indexOf(c), 1), n(o, s);
}, },
onDisconnected(o, c) { onDisconnected(o, c) {
d(), f(o).disconnected.push(c); d(), i(o).disconnected.push(c);
}, },
offDisconnected(o, c) { offDisconnected(o, c) {
if (!e.has(o)) if (!e.has(o))
@ -186,9 +178,9 @@ function _() {
} }
}; };
function n(o, c) { function n(o, c) {
c.connected.length || c.disconnect.length || (e.delete(o), i()); c.connected.length || c.disconnect.length || (e.delete(o), u());
} }
function f(o) { function i(o) {
if (e.has(o)) if (e.has(o))
return e.get(o); return e.get(o);
let c = { connected: [], disconnected: [] }; let c = { connected: [], disconnected: [] };
@ -197,16 +189,16 @@ function _() {
function d() { function d() {
t || (t = !0, r.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, r.observe(document.body, { childList: !0, subtree: !0 }));
} }
function i() { function u() {
!t || e.size || (t = !1, r.disconnect()); !t || e.size || (t = !1, r.disconnect());
} }
function u() { function f() {
return new Promise(function(o) { return new Promise(function(o) {
(requestIdleCallback || requestAnimationFrame)(o); (requestIdleCallback || requestAnimationFrame)(o);
}); });
} }
async function l(o) { async function l(o) {
e.size > 30 && await u(); e.size > 30 && await f();
let c = []; let c = [];
if (!(o instanceof Node)) if (!(o instanceof Node))
return c; return c;
@ -240,12 +232,12 @@ function _() {
}; };
}); });
export { export {
w as assign, x as assign,
T as classListDeclarative, R as classListDeclarative,
F as createElement, F as createElement,
F as el, F as el,
I as empty, I as empty,
z as namespace, z as namespace,
y as on, T as on,
A as registerReactivity D as registerReactivity
}; };

View File

@ -10,16 +10,18 @@ const className= style.host(todosComponent).css`
:host button{ :host button{
margin-inline-start: 1em; margin-inline-start: 1em;
} }
:host output{
white-space: pre;
}
`; `;
/** @param {{ todos: string[] }} */ /** @param {{ todos: string[] }} */
export function todosComponent({ todos= [ "A" ] }= {}){ export function todosComponent({ todos= [ "Task A" ] }= {}){
const todosS= S([], { const todosS= S([], {
add(v){ this.value.push(S(v)); }, add(v){ this.value.push(S(v)); },
remove(i){ this.value.splice(i, 1); }, remove(i){ this.value.splice(i, 1); },
[S.symbols.onclear](){ S.clear(...this.value); }, [S.symbols.onclear](){ S.clear(...this.value); },
}); });
todos.forEach(v=> S.action(todosS, "add", v)); todos.forEach(v=> S.action(todosS, "add", v));
console.log(todosS); //TODO
const name= "todoName"; const name= "todoName";
const onsubmitAdd= on("submit", event=> { const onsubmitAdd= on("submit", event=> {
const value= event.target.elements[name].value; const value= event.target.elements[name].value;
@ -33,16 +35,18 @@ export function todosComponent({ todos= [ "A" ] }= {}){
S.action(todosS, "remove", event.detail)); S.action(todosS, "remove", event.detail));
const ul_todos= el("ul").append( const ul_todos= el("ul").append(
el("<>", todosS, S.el(todosS, ts=> ts
ts=> ts.map((t, i)=> el(todoComponent, { textContent: t, value: i, className }, onremove)) .map((textContent, value)=>
el(todoComponent, { textContent, value, className }, onremove))
)); ));
return el("div", { className }).append( return el("div", { className }).append(
el("div").append( el("div").append(
el("h2", "Todos:"), el("h2", "Todos:"),
el("h3", "List of todos:"), el("h3", "List of todos:"),
el("<>", todosS, ts=> !ts.length S.el(todosS, ts=> !ts.length
? el("p", "No todos yet") ? el("p", "No todos yet")
: ul_todos) : ul_todos),
el("p", "Click to the text to edit it.")
), ),
el("form", null, onsubmitAdd).append( el("form", null, onsubmitAdd).append(
el("h3", "Add a todo:"), el("h3", "Add a todo:"),
@ -50,13 +54,17 @@ export function todosComponent({ todos= [ "A" ] }= {}){
el("input", { name, type: "text", required: true }), el("input", { name, type: "text", required: true }),
), ),
el("button", "+") el("button", "+")
),
el("div").append(
el("h3", "Output (JSON):"),
el("output", S(()=> JSON.stringify(todosS, null, "\t")))
) )
) )
} }
/** /**
* @type {ddeFires<[ "click" ]>} * @type {ddeFires<[ "click" ]>}
* @param {{ * @param {{
* textContent: string | ddeSignal<string, any> * textContent: ddeSignal<string, any>
* value: number * value: number
* }} * }}
* */ * */
@ -68,8 +76,16 @@ function todoComponent({ textContent, value }){
event.stopPropagation(); event.stopPropagation();
ref().dispatchEvent(new CustomEvent("remove", { detail: value })); ref().dispatchEvent(new CustomEvent("remove", { detail: value }));
}); });
const is_editable= S(false);
const onedited= on("change", ev=> {
textContent(ev.target.value);
is_editable(false);
});
return el("li", null, ref).append( return el("li", null, ref).append(
el("#text", textContent), S.el(is_editable, is=> is
? el("input", { value: textContent(), type: "text" }, onedited)
: el("span", textContent, on("click", ()=> is_editable(true))),
),
el("button", { type: "button", value, textContent: "-" }, onclick) el("button", { type: "button", value, textContent: "-" }, onclick)
); );
} }

View File

@ -1,12 +1,12 @@
import { namespace, el, assign, on, registerReactivity } from "../index.js"; import { namespace, el, assign, on, registerReactivity } from "../index.js";
import { S } from "../src/signals.js"; import { S, isSignal } from "../src/signals.js";
// import { empty, namespace, on, dispatch } from "../index.js"; // import { empty, namespace, on, dispatch } from "../index.js";
// import "../dist/dde-with-signals.js"; // import "../dist/dde-with-signals.js";
// Object.assign(globalThis, dde); // Object.assign(globalThis, dde);
// import { el, on, off, S } from "../dist/esm-with-signals.js"; // import { el, on, off, S } from "../dist/esm-with-signals.js";
const style= createStyle(); const style= createStyle();
Object.assign(globalThis, { S, el, assign, namespace, on, registerReactivity, style }); Object.assign(globalThis, { S, el, assign, namespace, on, registerReactivity, style });
export { S, el, on, registerReactivity, style }; export { S, isSignal, el, on, registerReactivity, style };
function createStyle(){ function createStyle(){
const element= el("style"); const element= el("style");

21
test/index-nosignals.html Normal file
View File

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- DEL CSP https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP | https://github.com/Prinzhorn/minimal-csp -->
<!-- DEL https://github.com/jensimmons/cssremedy -->
<!-- <link rel="stylesheet" href="https://github.com/jensimmons/cssremedy/raw/master/css/remedy.css"> -->
<title>Small DOM element creation enhancements</title>
<meta name="description" content="Making creatig elements easier">
<script type="module">
import { el } from "../index.js";
document.body.append(
el("p", { textContent: "Ahoj", style: { color: "green" } })
);
</script>
</head>
<body>
</body>
</html>