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

♻️ Update scope and namespace handling (scope hook)

This commit is contained in:
Jan Andrle 2023-10-10 10:55:00 +02:00
parent ebbb76e9a0
commit 6a52972373
Signed by: jaandrle
GPG Key ID: B3A25AED155AFFAB
8 changed files with 693 additions and 619 deletions

View File

@ -1,7 +1,7 @@
//deka-dom-el library is available via global namespace `dde` //deka-dom-el library is available via global namespace `dde`
(()=> { (()=> {
// src/signals-common.js // src/signals-common.js
var w = { var E = {
isSignal(e) { isSignal(e) {
return !1; return !1;
}, },
@ -9,22 +9,22 @@
return n; return n;
} }
}; };
function A(e, t = !0) { function C(e, t = !0) {
return t ? Object.assign(w, e) : (Object.setPrototypeOf(e, w), e); return t ? Object.assign(E, e) : (Object.setPrototypeOf(e, E), e);
} }
function S(e) { function S(e) {
return w.isPrototypeOf(e) && e !== w ? e : w; return E.isPrototypeOf(e) && e !== E ? e : E;
} }
// src/helpers.js // src/helpers.js
function m(e) { function m(e) {
return typeof e > "u"; return typeof e > "u";
} }
function D(e) { function P(e) {
let t = typeof e; let t = typeof e;
return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e); return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e);
} }
function C(e, t) { function L(e, t) {
if (!e || !(e instanceof AbortSignal)) if (!e || !(e instanceof AbortSignal))
return !0; return !0;
if (!e.aborted) if (!e.aborted)
@ -34,8 +34,8 @@
} }
// src/dom-common.js // src/dom-common.js
var P = { setDeleteAttr: q }; var j = { setDeleteAttr: H };
function q(e, t, n) { function H(e, t, n) {
if (Reflect.set(e, t, n), !!m(n)) { if (Reflect.set(e, t, n), !!m(n)) {
if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined") if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined")
return e.removeAttribute(t); return e.removeAttribute(t);
@ -45,79 +45,94 @@
} }
// src/dom.js // src/dom.js
var b = "html", F = { var w = [{ scope: document.body, namespace: "html", host: (e) => e ? e(document.body) : document.body }], W = (e) => e === "svg" ? "http://www.w3.org/2000/svg" : e, O = {
get current() {
return w[w.length - 1];
},
get state() {
return [...w];
},
get host() {
return this.current.host;
},
get namespace() {
return this.current.namespace;
},
set namespace(e) {
return this.current.namespace = W(e);
},
elNamespace(e) { elNamespace(e) {
return b = e === "svg" ? "http://www.w3.org/2000/svg" : e, { let t = this.namespace;
append(...t) { return this.namespace = e, {
return b = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t); append(...n) {
return O.namespace = t, n.length === 1 ? n[0] : document.createDocumentFragment().append(...n);
} }
}; };
}, },
get namespace() { push(e = {}) {
return b; return e.namespace && (e.namespace = W(e.namespace)), w.push(Object.assign({}, this.current, e));
}, },
set namespace(e) { pop() {
return b = e; return w.pop();
} }
}, ce = Object.assign((e) => e ? e(document.body) : document.body, F); };
function ie(e, t, ...n) { function se(e, t, ...n) {
let r = this, o = S(this), c; let r = this, o = S(this), { namespace: u } = O, a;
switch ((Object(t) !== t || o.isSignal(t)) && (t = { textContent: t }), !0) { switch ((Object(t) !== t || o.isSignal(t)) && (t = { textContent: t }), !0) {
case typeof e == "function": { case typeof e == "function": {
let l = Object.assign((u) => u ? (n.unshift(u), void 0) : c, F); O.push({ scope: e, host: (s) => s ? (n.unshift(s), void 0) : a }), a = e(t || void 0), O.pop();
c = e(t || void 0, l), b = "html";
break; break;
} }
case e === "#text": case e === "#text":
c = y.call(r, document.createTextNode(""), t); a = y.call(r, document.createTextNode(""), t);
break; break;
case e === "<>": case e === "<>":
c = y.call(r, document.createDocumentFragment(), t); a = y.call(r, document.createDocumentFragment(), t);
break; break;
case b !== "html": case u !== "html":
c = y.call(r, document.createElementNS(b, e), t); a = y.call(r, document.createElementNS(u, e), t);
break; break;
case !c: case !a:
c = y.call(r, document.createElement(e), t); a = y.call(r, document.createElement(e), t);
} }
return n.forEach((l) => l(c)), c; return n.forEach((s) => s(a)), a;
} }
var { setDeleteAttr: j } = P; var { setDeleteAttr: F } = j;
function y(e, ...t) { function y(e, ...t) {
let n = this, r = S(this); let n = this, r = S(this);
if (!t.length) if (!t.length)
return e; return e;
let c = (e instanceof SVGElement ? I : H).bind(null, e, "Attribute"); let u = (e instanceof SVGElement ? J : I).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function l([u, a]) { return Object.entries(Object.assign({}, ...t)).forEach(function a([s, d]) {
a = r.processReactiveAttribute(e, u, a, l); d = r.processReactiveAttribute(e, s, d, a);
let [v] = u; let [b] = s;
if (v === "=") if (b === "=")
return c(u.slice(1), a); return u(s.slice(1), d);
if (v === ".") if (b === ".")
return W(e, u.slice(1), a); return M(e, s.slice(1), d);
if (/(aria|data)([A-Z])/.test(u)) if (/(aria|data)([A-Z])/.test(s))
return u = u.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), c(u, a); return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), u(s, d);
switch (u === "className" && (u = "class"), u) { switch (s === "className" && (s = "class"), s) {
case "xlink:href": case "xlink:href":
return c(u, a, "http://www.w3.org/1999/xlink"); return u(s, d, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
return j(e, u, a); return F(e, s, d);
case "style": case "style":
if (typeof a != "object") if (typeof d != "object")
break; break;
case "dataset": case "dataset":
return L(r, a, W.bind(null, e[u])); return N(r, d, M.bind(null, e[s]));
case "ariaset": case "ariaset":
return L(r, a, (x, i) => c("aria-" + x, i)); return N(r, d, (x, c) => u("aria-" + x, c));
case "classList": case "classList":
return B.call(n, e, a); return B.call(n, e, d);
} }
return G(e, u) ? j(e, u, a) : c(u, a); return G(e, s) ? F(e, s, d) : u(s, d);
}), e; }), e;
} }
function B(e, t) { function B(e, t) {
let n = S(this); let n = S(this);
return L( return N(
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)
@ -129,31 +144,31 @@
function G(e, t) { function G(e, t) {
if (!Reflect.has(e, t)) if (!Reflect.has(e, t))
return !1; return !1;
let n = M(e, t); let n = z(e, t);
return !m(n.set); return !m(n.set);
} }
function M(e, t) { function z(e, t) {
if (e = Object.getPrototypeOf(e), !e) if (e = Object.getPrototypeOf(e), !e)
return {}; return {};
let n = Object.getOwnPropertyDescriptor(e, t); let n = Object.getOwnPropertyDescriptor(e, t);
return n || M(e, t); return n || z(e, t);
} }
function L(e, t, n) { function N(e, t, n) {
if (!(typeof t != "object" || t === null)) if (!(typeof t != "object" || t === null))
return Object.entries(t).forEach(function([o, c]) { return Object.entries(t).forEach(function([o, u]) {
o && (c = e.processReactiveAttribute(t, o, c, (l) => n(...l)), n(o, c)); o && (u = e.processReactiveAttribute(t, o, u, (a) => n(...a)), n(o, u));
}); });
} }
function z(e) { function T(e) {
return Array.isArray(e) ? e.filter(Boolean).join(" ") : e; return Array.isArray(e) ? e.filter(Boolean).join(" ") : e;
} }
function H(e, t, n, r) { function I(e, t, n, r) {
return e[(m(r) ? "remove" : "set") + t](n, z(r)); return e[(m(r) ? "remove" : "set") + t](n, T(r));
} }
function I(e, t, n, r, o = null) { function J(e, t, n, r, o = null) {
return e[(m(r) ? "remove" : "set") + t + "NS"](o, n, z(r)); return e[(m(r) ? "remove" : "set") + t + "NS"](o, n, T(r));
} }
function W(e, t, n) { function M(e, t, n) {
if (Reflect.set(e, t, n), !!m(n)) if (Reflect.set(e, t, n), !!m(n))
return Reflect.deleteProperty(e, t); return Reflect.deleteProperty(e, t);
} }
@ -163,105 +178,105 @@
let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t);
return e.dispatchEvent(r); return e.dispatchEvent(r);
} }
function T(e, t, n) { function U(e, t, n) {
return function(o) { return function(o) {
return o.addEventListener(e, t, n), o; return o.addEventListener(e, t, n), o;
}; };
} }
var O = J(); var _ = V();
T.connected = function(e, t) { U.connected = function(e, t) {
return typeof t != "object" && (t = {}), t.once = !0, function(r) { return typeof t != "object" && (t = {}), t.once = !0, function(r) {
return r.addEventListener("dde:connected", e, t), typeof r.connectedCallback == "function" ? r : r.isConnected ? (r.dispatchEvent(new Event("dde:connected")), r) : (C(t.signal, () => O.offConnected(r, e)) && O.onConnected(r, e), r); return r.addEventListener("dde:connected", e, t), typeof r.connectedCallback == "function" ? r : r.isConnected ? (r.dispatchEvent(new Event("dde:connected")), r) : (L(t.signal, () => _.offConnected(r, e)) && _.onConnected(r, e), r);
}; };
}; };
T.disconnected = function(e, t) { U.disconnected = function(e, t) {
return typeof t != "object" && (t = {}), t.once = !0, function(r) { return typeof t != "object" && (t = {}), t.once = !0, function(r) {
return r.addEventListener("dde:disconnected", e, t), typeof r.disconnectedCallback == "function" || C(t.signal, () => O.offDisconnected(r, e)) && O.onDisconnected(r, e), r; return r.addEventListener("dde:disconnected", e, t), typeof r.disconnectedCallback == "function" || L(t.signal, () => _.offDisconnected(r, e)) && _.onDisconnected(r, e), r;
}; };
}; };
function J() { function V() {
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(i) { let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) {
for (let s of i) for (let i of c)
if (s.type === "childList") { if (i.type === "childList") {
if (v(s.addedNodes, !0)) { if (b(i.addedNodes, !0)) {
l(); a();
continue; continue;
} }
x(s.removedNodes, !0) && l(); x(i.removedNodes, !0) && a();
} }
}); });
return { return {
onConnected(i, s) { onConnected(c, i) {
c(); u();
let f = o(i); let f = o(c);
f.connected.has(s) || (f.connected.add(s), f.length_c += 1); f.connected.has(i) || (f.connected.add(i), f.length_c += 1);
}, },
offConnected(i, s) { offConnected(c, i) {
if (!e.has(i)) if (!e.has(c))
return; return;
let f = e.get(i); let f = e.get(c);
f.connected.has(s) && (f.connected.delete(s), f.length_c -= 1, r(i, f)); f.connected.has(i) && (f.connected.delete(i), f.length_c -= 1, r(c, f));
}, },
onDisconnected(i, s) { onDisconnected(c, i) {
c(); u();
let f = o(i); let f = o(c);
f.disconnected.has(s) || (f.disconnected.add(s), f.length_d += 1); f.disconnected.has(i) || (f.disconnected.add(i), f.length_d += 1);
}, },
offDisconnected(i, s) { offDisconnected(c, i) {
if (!e.has(i)) if (!e.has(c))
return; return;
let f = e.get(i); let f = e.get(c);
f.disconnected.has(s) && (f.disconnected.delete(s), f.length_d -= 1, r(i, f)); f.disconnected.has(i) && (f.disconnected.delete(i), f.length_d -= 1, r(c, f));
} }
}; };
function r(i, s) { function r(c, i) {
s.length_c || s.length_d || (e.delete(i), l()); i.length_c || i.length_d || (e.delete(c), a());
} }
function o(i) { function o(c) {
if (e.has(i)) if (e.has(c))
return e.get(i); return e.get(c);
let s = { let i = {
connected: /* @__PURE__ */ new WeakSet(), connected: /* @__PURE__ */ new WeakSet(),
length_c: 0, length_c: 0,
disconnected: /* @__PURE__ */ new WeakSet(), disconnected: /* @__PURE__ */ new WeakSet(),
length_d: 0 length_d: 0
}; };
return e.set(i, s), s; return e.set(c, i), i;
}
function c() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
}
function l() {
!t || e.size || (t = !1, n.disconnect());
} }
function u() { function u() {
return new Promise(function(i) { t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
(requestIdleCallback || requestAnimationFrame)(i); }
function a() {
!t || e.size || (t = !1, n.disconnect());
}
function s() {
return new Promise(function(c) {
(requestIdleCallback || requestAnimationFrame)(c);
}); });
} }
async function a(i) { async function d(c) {
e.size > 30 && await u(); e.size > 30 && await s();
let s = []; let i = [];
if (!(i instanceof Node)) if (!(c instanceof Node))
return s; return i;
for (let f of e.keys()) for (let f of e.keys())
f === i || !(f instanceof Node) || i.contains(f) && s.push(f); f === c || !(f instanceof Node) || c.contains(f) && i.push(f);
return s; return i;
} }
function v(i, s) { function b(c, i) {
let f = !1; let f = !1;
for (let p of i) { for (let l of c) {
if (s && a(p).then(v), !e.has(p)) if (i && d(l).then(b), !e.has(l))
continue; continue;
let E = e.get(p); let v = e.get(l);
E.length_c && (p.dispatchEvent(new Event("dde:connected")), E.connected = /* @__PURE__ */ new WeakSet(), E.length_c = 0, E.length_d || e.delete(p), f = !0); v.length_c && (l.dispatchEvent(new Event("dde:connected")), v.connected = /* @__PURE__ */ new WeakSet(), v.length_c = 0, v.length_d || e.delete(l), f = !0);
} }
return f; return f;
} }
function x(i, s) { function x(c, i) {
let f = !1; let f = !1;
for (let p of i) for (let l of c)
s && a(p).then(x), !(!e.has(p) || !e.get(p).length_d) && (p.dispatchEvent(new Event("dde:disconnected")), e.delete(p), f = !0); i && d(l).then(x), !(!e.has(l) || !e.get(l).length_d) && (l.dispatchEvent(new Event("dde:disconnected")), e.delete(l), f = !0);
return f; return f;
} }
} }
@ -275,10 +290,10 @@
}); });
// src/signals-lib.js // src/signals-lib.js
var d = Symbol.for("Signal"); var p = Symbol.for("Signal");
function _(e) { function R(e) {
try { try {
return Reflect.has(e, d); return Reflect.has(e, p);
} catch { } catch {
return !1; return !1;
} }
@ -286,131 +301,131 @@
var h = /* @__PURE__ */ new WeakMap(); var h = /* @__PURE__ */ new WeakMap();
function g(e, t) { function g(e, t) {
if (typeof e != "function") if (typeof e != "function")
return U(e, t); return $(e, t);
if (_(e)) if (R(e))
return e; return e;
let n = U(""), r = () => n(e()); let n = $(""), r = () => n(e());
return h.set(r, /* @__PURE__ */ new Set([n])), K(r), n; return h.set(r, /* @__PURE__ */ new Set([n])), Q(r), n;
} }
g.action = function(e, t, ...n) { g.action = function(e, t, ...n) {
let r = e[d], { actions: o } = r; let r = e[p], { 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(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((c) => c(r.value)); r.listeners.forEach((u) => u(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((c) => e(c, n, r)); return t.forEach((u) => e(u, n, r));
N(t, n), o && o.addEventListener("abort", () => k(t, n)); D(t, n), o && o.addEventListener("abort", () => q(t, n));
} }
}; };
g.symbols = { g.symbols = {
signal: d, signal: p,
onclear: Symbol.for("Signal.onclear") onclear: Symbol.for("Signal.onclear")
}; };
g.clear = function(...e) { g.clear = function(...e) {
for (let n of e) { for (let n of e) {
Reflect.deleteProperty(n, "toJSON"); Reflect.deleteProperty(n, "toJSON");
let r = n[d], { onclear: o } = g.symbols; let r = n[p], { onclear: o } = g.symbols;
r.actions && r.actions[o] && r.actions[o].call(r), t(n, r), Reflect.deleteProperty(n, d); r.actions && r.actions[o] && r.actions[o].call(r), t(n, r), Reflect.deleteProperty(n, p);
} }
function t(n, r) { function t(n, r) {
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 c = h.get(o); let u = h.get(o);
c.delete(n), !(c.size > 1) && (g.clear(...c), h.delete(o)); u.delete(n), !(u.size > 1) && (g.clear(...u), 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 c = (l) => { let u = (a) => {
if (!n.parentNode || !r.parentNode) if (!n.parentNode || !r.parentNode)
return k(e, c); return q(e, u);
let u = t(l); let s = t(a);
Array.isArray(u) || (u = [u]); Array.isArray(s) || (s = [s]);
let a = n; let d = n;
for (; (a = n.nextSibling) !== r; ) for (; (d = n.nextSibling) !== r; )
a.remove(); d.remove();
n.after(...u); n.after(...s);
}; };
return N(e, c), c(e()), o; return D(e, u), u(e()), o;
}; };
var $ = { var k = {
isSignal: _, isSignal: R,
processReactiveAttribute(e, t, n, r) { processReactiveAttribute(e, t, n, r) {
return _(n) ? (N(n, (o) => r([t, o])), n()) : n; return R(n) ? (D(n, (o) => r([t, o])), n()) : n;
} }
}; };
function U(e, t) { function $(e, t) {
let n = (...r) => r.length ? Y(n, r[0]) : X(n); let n = (...r) => r.length ? ee(n, r[0]) : Y(n);
return Z(n, e, t); return K(n, e, t);
} }
var V = Object.assign(/* @__PURE__ */ Object.create(null), { var Z = Object.assign(/* @__PURE__ */ Object.create(null), {
stopPropagation() { stopPropagation() {
this.skip = !0; this.skip = !0;
} }
}); });
function Z(e, t, n) { function K(e, t, n) {
return D(n) !== "[object Object]" && (n = {}), e[d] = { return P(n) !== "[object Object]" && (n = {}), e[p] = {
value: t, value: t,
actions: n, actions: n,
listeners: /* @__PURE__ */ new Set() listeners: /* @__PURE__ */ new Set()
}, e.toJSON = () => e(), Object.setPrototypeOf(e[d], V), e; }, e.toJSON = () => e(), Object.setPrototypeOf(e[p], Z), e;
} }
var R = []; var A = [];
function K(e) { function Q(e) {
let t = function() { let t = function() {
R.push(t), e(), R.pop(); A.push(t), e(), A.pop();
}; };
h.has(e) && (h.set(t, h.get(e)), h.delete(e)), t(); h.has(e) && (h.set(t, h.get(e)), h.delete(e)), t();
} }
function Q() { function X() {
return R[R.length - 1]; return A[A.length - 1];
} }
function X(e) { function Y(e) {
if (!e[d]) if (!e[p])
return; return;
let { value: t, listeners: n } = e[d], r = Q(); let { value: t, listeners: n } = e[p], r = X();
return r && n.add(r), h.has(r) && h.get(r).add(e), t; return r && n.add(r), h.has(r) && h.get(r).add(e), t;
} }
function Y(e, t) { function ee(e, t) {
if (!e[d]) if (!e[p])
return; return;
let n = e[d]; let n = e[p];
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[p])
return e[d].listeners.add(t); return e[p].listeners.add(t);
} }
function k(e, t) { function q(e, t) {
if (e[d]) if (e[p])
return e[d].listeners.delete(t); return e[p].listeners.delete(t);
} }
// signals.js // signals.js
A($); C(k);
globalThis.dde= { globalThis.dde= {
S: g, S: g,
assign: y, assign: y,
classListDeclarative: B, classListDeclarative: B,
createElement: ie, createElement: se,
dispatchEvent: de, dispatchEvent: de,
el: ie, el: se,
empty: fe, empty: fe,
isSignal: _, isSignal: R,
on: T, on: U,
registerReactivity: A, registerReactivity: C,
scope: ce scope: O
}; };
})(); })();

247
dist/dde.js vendored
View File

@ -1,23 +1,23 @@
//deka-dom-el library is available via global namespace `dde` //deka-dom-el library is available via global namespace `dde`
(()=> { (()=> {
// src/signals-common.js // src/signals-common.js
var E = { var m = {
isSignal(e) { isSignal(e) {
return !1; return !1;
}, },
processReactiveAttribute(e, t, r, n) { processReactiveAttribute(e, t, n, r) {
return r; return n;
} }
}; };
function N(e, t = !0) { function P(e, t = !0) {
return t ? Object.assign(E, e) : (Object.setPrototypeOf(e, E), e); return t ? Object.assign(m, e) : (Object.setPrototypeOf(e, m), e);
} }
function m(e) { function b(e) {
return E.isPrototypeOf(e) && e !== E ? e : E; return m.isPrototypeOf(e) && e !== m ? e : m;
} }
// src/helpers.js // src/helpers.js
function p(e) { function l(e) {
return typeof e > "u"; return typeof e > "u";
} }
function _(e, t) { function _(e, t) {
@ -30,9 +30,9 @@
} }
// src/dom-common.js // src/dom-common.js
var O = { setDeleteAttr: P }; var R = { setDeleteAttr: j };
function P(e, t, r) { function j(e, t, n) {
if (Reflect.set(e, t, r), !!p(r)) { if (Reflect.set(e, t, n), !!l(n)) {
if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined") if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined")
return e.removeAttribute(t); return e.removeAttribute(t);
if (Reflect.get(e, t) === "undefined") if (Reflect.get(e, t) === "undefined")
@ -41,154 +41,169 @@
} }
// src/dom.js // src/dom.js
var h = "html", S = { var v = [{ scope: document.body, namespace: "html", host: (e) => e ? e(document.body) : document.body }], C = (e) => e === "svg" ? "http://www.w3.org/2000/svg" : e, x = {
get current() {
return v[v.length - 1];
},
get state() {
return [...v];
},
get host() {
return this.current.host;
},
get namespace() {
return this.current.namespace;
},
set namespace(e) {
return this.current.namespace = C(e);
},
elNamespace(e) { elNamespace(e) {
return h = e === "svg" ? "http://www.w3.org/2000/svg" : e, { let t = this.namespace;
append(...t) { return this.namespace = e, {
return h = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t); append(...n) {
return x.namespace = t, n.length === 1 ? n[0] : document.createDocumentFragment().append(...n);
} }
}; };
}, },
get namespace() { push(e = {}) {
return h; return e.namespace && (e.namespace = C(e.namespace)), v.push(Object.assign({}, this.current, e));
}, },
set namespace(e) { pop() {
return h = e; return v.pop();
} }
}, H = Object.assign((e) => e ? e(document.body) : document.body, S); };
function I(e, t, ...r) { function I(e, t, ...n) {
let n = this, u = m(this), i; let r = this, u = b(this), { namespace: d } = x, f;
switch ((Object(t) !== t || u.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": {
let a = Object.assign((f) => f ? (r.unshift(f), void 0) : i, S); x.push({ scope: e, host: (i) => i ? (n.unshift(i), void 0) : f }), f = e(t || void 0), x.pop();
i = e(t || void 0, a), h = "html";
break; break;
} }
case e === "#text": case e === "#text":
i = w.call(n, document.createTextNode(""), t); f = w.call(r, document.createTextNode(""), t);
break; break;
case e === "<>": case e === "<>":
i = w.call(n, document.createDocumentFragment(), t); f = w.call(r, document.createDocumentFragment(), t);
break; break;
case h !== "html": case d !== "html":
i = w.call(n, document.createElementNS(h, e), t); f = w.call(r, document.createElementNS(d, e), t);
break; break;
case !i: case !f:
i = w.call(n, document.createElement(e), t); f = w.call(r, document.createElement(e), t);
} }
return r.forEach((a) => a(i)), i; return n.forEach((i) => i(f)), f;
} }
var { setDeleteAttr: R } = O; var { setDeleteAttr: S } = R;
function w(e, ...t) { function w(e, ...t) {
let r = this, n = m(this); let n = this, r = b(this);
if (!t.length) if (!t.length)
return e; return e;
let i = (e instanceof SVGElement ? T : M).bind(null, e, "Attribute"); let d = (e instanceof SVGElement ? U : T).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function a([f, d]) { return Object.entries(Object.assign({}, ...t)).forEach(function f([i, a]) {
d = n.processReactiveAttribute(e, f, d, a); a = r.processReactiveAttribute(e, i, a, f);
let [g] = f; let [h] = i;
if (g === "=") if (h === "=")
return i(f.slice(1), d); return d(i.slice(1), a);
if (g === ".") if (h === ".")
return C(e, f.slice(1), d); return y(e, i.slice(1), a);
if (/(aria|data)([A-Z])/.test(f)) if (/(aria|data)([A-Z])/.test(i))
return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(f, d); return i = i.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), d(i, a);
switch (f === "className" && (f = "class"), f) { switch (i === "className" && (i = "class"), i) {
case "xlink:href": case "xlink:href":
return i(f, d, "http://www.w3.org/1999/xlink"); return d(i, a, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
return R(e, f, d); return S(e, i, a);
case "style": case "style":
if (typeof d != "object") if (typeof a != "object")
break; break;
case "dataset": case "dataset":
return A(n, d, C.bind(null, e[f])); return O(r, a, y.bind(null, e[i]));
case "ariaset": case "ariaset":
return A(n, d, (b, c) => i("aria-" + b, c)); return O(r, a, (E, c) => d("aria-" + E, c));
case "classList": case "classList":
return j.call(r, e, d); return F.call(n, e, a);
} }
return F(e, f) ? R(e, f, d) : i(f, d); return M(e, i) ? S(e, i, a) : d(i, a);
}), e; }), e;
} }
function j(e, t) { function F(e, t) {
let r = m(this); let n = b(this);
return A( return O(
r, n,
t, t,
(n, u) => e.classList.toggle(n, u === -1 ? void 0 : !!u) (r, u) => e.classList.toggle(r, u === -1 ? void 0 : !!u)
), e; ), e;
} }
function Z(e) { function Z(e) {
return Array.from(e.children).forEach((t) => t.remove()), e; return Array.from(e.children).forEach((t) => t.remove()), e;
} }
function F(e, t) { function M(e, t) {
if (!Reflect.has(e, t)) if (!Reflect.has(e, t))
return !1; return !1;
let r = y(e, t); let n = D(e, t);
return !p(r.set); return !l(n.set);
} }
function y(e, t) { function D(e, t) {
if (e = Object.getPrototypeOf(e), !e) if (e = Object.getPrototypeOf(e), !e)
return {}; return {};
let r = Object.getOwnPropertyDescriptor(e, t); let n = Object.getOwnPropertyDescriptor(e, t);
return r || y(e, t); return n || D(e, t);
} }
function A(e, t, r) { function O(e, t, n) {
if (!(typeof t != "object" || t === null)) if (!(typeof t != "object" || t === null))
return Object.entries(t).forEach(function([u, i]) { return Object.entries(t).forEach(function([u, d]) {
u && (i = e.processReactiveAttribute(t, u, i, (a) => r(...a)), r(u, i)); u && (d = e.processReactiveAttribute(t, u, d, (f) => n(...f)), n(u, d));
}); });
} }
function D(e) { function L(e) {
return Array.isArray(e) ? e.filter(Boolean).join(" ") : e; return Array.isArray(e) ? e.filter(Boolean).join(" ") : e;
} }
function M(e, t, r, n) { function T(e, t, n, r) {
return e[(p(n) ? "remove" : "set") + t](r, D(n)); return e[(l(r) ? "remove" : "set") + t](n, L(r));
} }
function T(e, t, r, n, u = null) { function U(e, t, n, r, u = null) {
return e[(p(n) ? "remove" : "set") + t + "NS"](u, r, D(n)); return e[(l(r) ? "remove" : "set") + t + "NS"](u, n, L(r));
} }
function C(e, t, r) { function y(e, t, n) {
if (Reflect.set(e, t, r), !!p(r)) if (Reflect.set(e, t, n), !!l(n))
return Reflect.deleteProperty(e, t); return Reflect.deleteProperty(e, t);
} }
// src/events.js // src/events.js
function K(e, t, ...r) { function K(e, t, ...n) {
let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t); let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t);
return e.dispatchEvent(n); return e.dispatchEvent(r);
} }
function L(e, t, r) { function N(e, t, n) {
return function(u) { return function(u) {
return u.addEventListener(e, t, r), u; return u.addEventListener(e, t, n), u;
}; };
} }
var x = U(); var A = W();
L.connected = function(e, t) { N.connected = function(e, t) {
return typeof t != "object" && (t = {}), t.once = !0, function(n) { return typeof t != "object" && (t = {}), t.once = !0, function(r) {
return n.addEventListener("dde:connected", e, t), typeof n.connectedCallback == "function" ? n : n.isConnected ? (n.dispatchEvent(new Event("dde:connected")), n) : (_(t.signal, () => x.offConnected(n, e)) && x.onConnected(n, e), n); return r.addEventListener("dde:connected", e, t), typeof r.connectedCallback == "function" ? r : r.isConnected ? (r.dispatchEvent(new Event("dde:connected")), r) : (_(t.signal, () => A.offConnected(r, e)) && A.onConnected(r, e), r);
}; };
}; };
L.disconnected = function(e, t) { N.disconnected = function(e, t) {
return typeof t != "object" && (t = {}), t.once = !0, function(n) { return typeof t != "object" && (t = {}), t.once = !0, function(r) {
return n.addEventListener("dde:disconnected", e, t), typeof n.disconnectedCallback == "function" || _(t.signal, () => x.offDisconnected(n, e)) && x.onDisconnected(n, e), n; return r.addEventListener("dde:disconnected", e, t), typeof r.disconnectedCallback == "function" || _(t.signal, () => A.offDisconnected(r, e)) && A.onDisconnected(r, e), r;
}; };
}; };
function U() { function W() {
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 o of c) for (let o of c)
if (o.type === "childList") { if (o.type === "childList") {
if (g(o.addedNodes, !0)) { if (h(o.addedNodes, !0)) {
a(); f();
continue; continue;
} }
b(o.removedNodes, !0) && a(); E(o.removedNodes, !0) && f();
} }
}); });
return { return {
onConnected(c, o) { onConnected(c, o) {
i(); d();
let s = u(c); let s = u(c);
s.connected.has(o) || (s.connected.add(o), s.length_c += 1); s.connected.has(o) || (s.connected.add(o), s.length_c += 1);
}, },
@ -196,10 +211,10 @@
if (!e.has(c)) if (!e.has(c))
return; return;
let s = e.get(c); let s = e.get(c);
s.connected.has(o) && (s.connected.delete(o), s.length_c -= 1, n(c, s)); s.connected.has(o) && (s.connected.delete(o), s.length_c -= 1, r(c, s));
}, },
onDisconnected(c, o) { onDisconnected(c, o) {
i(); d();
let s = u(c); let s = u(c);
s.disconnected.has(o) || (s.disconnected.add(o), s.length_d += 1); s.disconnected.has(o) || (s.disconnected.add(o), s.length_d += 1);
}, },
@ -207,11 +222,11 @@
if (!e.has(c)) if (!e.has(c))
return; return;
let s = e.get(c); let s = e.get(c);
s.disconnected.has(o) && (s.disconnected.delete(o), s.length_d -= 1, n(c, s)); s.disconnected.has(o) && (s.disconnected.delete(o), s.length_d -= 1, r(c, s));
} }
}; };
function n(c, o) { function r(c, o) {
o.length_c || o.length_d || (e.delete(c), a()); o.length_c || o.length_d || (e.delete(c), f());
} }
function u(c) { function u(c) {
if (e.has(c)) if (e.has(c))
@ -224,19 +239,19 @@
}; };
return e.set(c, o), o; return e.set(c, o), o;
} }
function i() { function d() {
t || (t = !0, r.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
}
function a() {
!t || e.size || (t = !1, r.disconnect());
} }
function f() { function f() {
!t || e.size || (t = !1, n.disconnect());
}
function i() {
return new Promise(function(c) { return new Promise(function(c) {
(requestIdleCallback || requestAnimationFrame)(c); (requestIdleCallback || requestAnimationFrame)(c);
}); });
} }
async function d(c) { async function a(c) {
e.size > 30 && await f(); e.size > 30 && await i();
let o = []; let o = [];
if (!(c instanceof Node)) if (!(c instanceof Node))
return o; return o;
@ -244,20 +259,20 @@
s === c || !(s instanceof Node) || c.contains(s) && o.push(s); s === c || !(s instanceof Node) || c.contains(s) && o.push(s);
return o; return o;
} }
function g(c, o) { function h(c, o) {
let s = !1; let s = !1;
for (let l of c) { for (let p of c) {
if (o && d(l).then(g), !e.has(l)) if (o && a(p).then(h), !e.has(p))
continue; continue;
let v = e.get(l); let g = e.get(p);
v.length_c && (l.dispatchEvent(new Event("dde:connected")), v.connected = /* @__PURE__ */ new WeakSet(), v.length_c = 0, v.length_d || e.delete(l), s = !0); g.length_c && (p.dispatchEvent(new Event("dde:connected")), g.connected = /* @__PURE__ */ new WeakSet(), g.length_c = 0, g.length_d || e.delete(p), s = !0);
} }
return s; return s;
} }
function b(c, o) { function E(c, o) {
let s = !1; let s = !1;
for (let l of c) for (let p of c)
o && d(l).then(b), !(!e.has(l) || !e.get(l).length_d) && (l.dispatchEvent(new Event("dde:disconnected")), e.delete(l), s = !0); o && a(p).then(E), !(!e.has(p) || !e.get(p).length_d) && (p.dispatchEvent(new Event("dde:disconnected")), e.delete(p), s = !0);
return s; return s;
} }
} }
@ -265,21 +280,21 @@
// index.js // index.js
[HTMLElement, SVGElement, DocumentFragment].forEach((e) => { [HTMLElement, SVGElement, 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;
}; };
}); });
globalThis.dde= { globalThis.dde= {
assign: w, assign: w,
classListDeclarative: j, classListDeclarative: F,
createElement: I, createElement: I,
dispatchEvent: K, dispatchEvent: K,
el: I, el: I,
empty: Z, empty: Z,
on: L, on: N,
registerReactivity: N, registerReactivity: P,
scope: H scope: x
}; };
})(); })();

View File

@ -1,5 +1,5 @@
// src/signals-common.js // src/signals-common.js
var w = { var E = {
isSignal(e) { isSignal(e) {
return !1; return !1;
}, },
@ -7,22 +7,22 @@ var w = {
return n; return n;
} }
}; };
function A(e, t = !0) { function C(e, t = !0) {
return t ? Object.assign(w, e) : (Object.setPrototypeOf(e, w), e); return t ? Object.assign(E, e) : (Object.setPrototypeOf(e, E), e);
} }
function S(e) { function S(e) {
return w.isPrototypeOf(e) && e !== w ? e : w; return E.isPrototypeOf(e) && e !== E ? e : E;
} }
// src/helpers.js // src/helpers.js
function m(e) { function m(e) {
return typeof e > "u"; return typeof e > "u";
} }
function D(e) { function P(e) {
let t = typeof e; let t = typeof e;
return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e); return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e);
} }
function C(e, t) { function L(e, t) {
if (!e || !(e instanceof AbortSignal)) if (!e || !(e instanceof AbortSignal))
return !0; return !0;
if (!e.aborted) if (!e.aborted)
@ -32,8 +32,8 @@ function C(e, t) {
} }
// src/dom-common.js // src/dom-common.js
var P = { setDeleteAttr: q }; var j = { setDeleteAttr: H };
function q(e, t, n) { function H(e, t, n) {
if (Reflect.set(e, t, n), !!m(n)) { if (Reflect.set(e, t, n), !!m(n)) {
if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined") if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined")
return e.removeAttribute(t); return e.removeAttribute(t);
@ -43,79 +43,94 @@ function q(e, t, n) {
} }
// src/dom.js // src/dom.js
var b = "html", F = { var w = [{ scope: document.body, namespace: "html", host: (e) => e ? e(document.body) : document.body }], W = (e) => e === "svg" ? "http://www.w3.org/2000/svg" : e, O = {
get current() {
return w[w.length - 1];
},
get state() {
return [...w];
},
get host() {
return this.current.host;
},
get namespace() {
return this.current.namespace;
},
set namespace(e) {
return this.current.namespace = W(e);
},
elNamespace(e) { elNamespace(e) {
return b = e === "svg" ? "http://www.w3.org/2000/svg" : e, { let t = this.namespace;
append(...t) { return this.namespace = e, {
return b = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t); append(...n) {
return O.namespace = t, n.length === 1 ? n[0] : document.createDocumentFragment().append(...n);
} }
}; };
}, },
get namespace() { push(e = {}) {
return b; return e.namespace && (e.namespace = W(e.namespace)), w.push(Object.assign({}, this.current, e));
}, },
set namespace(e) { pop() {
return b = e; return w.pop();
} }
}, ce = Object.assign((e) => e ? e(document.body) : document.body, F); };
function ie(e, t, ...n) { function se(e, t, ...n) {
let r = this, o = S(this), c; let r = this, o = S(this), { namespace: u } = O, a;
switch ((Object(t) !== t || o.isSignal(t)) && (t = { textContent: t }), !0) { switch ((Object(t) !== t || o.isSignal(t)) && (t = { textContent: t }), !0) {
case typeof e == "function": { case typeof e == "function": {
let l = Object.assign((u) => u ? (n.unshift(u), void 0) : c, F); O.push({ scope: e, host: (s) => s ? (n.unshift(s), void 0) : a }), a = e(t || void 0), O.pop();
c = e(t || void 0, l), b = "html";
break; break;
} }
case e === "#text": case e === "#text":
c = y.call(r, document.createTextNode(""), t); a = y.call(r, document.createTextNode(""), t);
break; break;
case e === "<>": case e === "<>":
c = y.call(r, document.createDocumentFragment(), t); a = y.call(r, document.createDocumentFragment(), t);
break; break;
case b !== "html": case u !== "html":
c = y.call(r, document.createElementNS(b, e), t); a = y.call(r, document.createElementNS(u, e), t);
break; break;
case !c: case !a:
c = y.call(r, document.createElement(e), t); a = y.call(r, document.createElement(e), t);
} }
return n.forEach((l) => l(c)), c; return n.forEach((s) => s(a)), a;
} }
var { setDeleteAttr: j } = P; var { setDeleteAttr: F } = j;
function y(e, ...t) { function y(e, ...t) {
let n = this, r = S(this); let n = this, r = S(this);
if (!t.length) if (!t.length)
return e; return e;
let c = (e instanceof SVGElement ? I : H).bind(null, e, "Attribute"); let u = (e instanceof SVGElement ? J : I).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function l([u, a]) { return Object.entries(Object.assign({}, ...t)).forEach(function a([s, d]) {
a = r.processReactiveAttribute(e, u, a, l); d = r.processReactiveAttribute(e, s, d, a);
let [v] = u; let [b] = s;
if (v === "=") if (b === "=")
return c(u.slice(1), a); return u(s.slice(1), d);
if (v === ".") if (b === ".")
return W(e, u.slice(1), a); return M(e, s.slice(1), d);
if (/(aria|data)([A-Z])/.test(u)) if (/(aria|data)([A-Z])/.test(s))
return u = u.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), c(u, a); return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), u(s, d);
switch (u === "className" && (u = "class"), u) { switch (s === "className" && (s = "class"), s) {
case "xlink:href": case "xlink:href":
return c(u, a, "http://www.w3.org/1999/xlink"); return u(s, d, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
return j(e, u, a); return F(e, s, d);
case "style": case "style":
if (typeof a != "object") if (typeof d != "object")
break; break;
case "dataset": case "dataset":
return L(r, a, W.bind(null, e[u])); return N(r, d, M.bind(null, e[s]));
case "ariaset": case "ariaset":
return L(r, a, (x, i) => c("aria-" + x, i)); return N(r, d, (x, c) => u("aria-" + x, c));
case "classList": case "classList":
return B.call(n, e, a); return B.call(n, e, d);
} }
return G(e, u) ? j(e, u, a) : c(u, a); return G(e, s) ? F(e, s, d) : u(s, d);
}), e; }), e;
} }
function B(e, t) { function B(e, t) {
let n = S(this); let n = S(this);
return L( return N(
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)
@ -127,31 +142,31 @@ function fe(e) {
function G(e, t) { function G(e, t) {
if (!Reflect.has(e, t)) if (!Reflect.has(e, t))
return !1; return !1;
let n = M(e, t); let n = z(e, t);
return !m(n.set); return !m(n.set);
} }
function M(e, t) { function z(e, t) {
if (e = Object.getPrototypeOf(e), !e) if (e = Object.getPrototypeOf(e), !e)
return {}; return {};
let n = Object.getOwnPropertyDescriptor(e, t); let n = Object.getOwnPropertyDescriptor(e, t);
return n || M(e, t); return n || z(e, t);
} }
function L(e, t, n) { function N(e, t, n) {
if (!(typeof t != "object" || t === null)) if (!(typeof t != "object" || t === null))
return Object.entries(t).forEach(function([o, c]) { return Object.entries(t).forEach(function([o, u]) {
o && (c = e.processReactiveAttribute(t, o, c, (l) => n(...l)), n(o, c)); o && (u = e.processReactiveAttribute(t, o, u, (a) => n(...a)), n(o, u));
}); });
} }
function z(e) { function T(e) {
return Array.isArray(e) ? e.filter(Boolean).join(" ") : e; return Array.isArray(e) ? e.filter(Boolean).join(" ") : e;
} }
function H(e, t, n, r) { function I(e, t, n, r) {
return e[(m(r) ? "remove" : "set") + t](n, z(r)); return e[(m(r) ? "remove" : "set") + t](n, T(r));
} }
function I(e, t, n, r, o = null) { function J(e, t, n, r, o = null) {
return e[(m(r) ? "remove" : "set") + t + "NS"](o, n, z(r)); return e[(m(r) ? "remove" : "set") + t + "NS"](o, n, T(r));
} }
function W(e, t, n) { function M(e, t, n) {
if (Reflect.set(e, t, n), !!m(n)) if (Reflect.set(e, t, n), !!m(n))
return Reflect.deleteProperty(e, t); return Reflect.deleteProperty(e, t);
} }
@ -161,105 +176,105 @@ function de(e, t, ...n) {
let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t);
return e.dispatchEvent(r); return e.dispatchEvent(r);
} }
function T(e, t, n) { function U(e, t, n) {
return function(o) { return function(o) {
return o.addEventListener(e, t, n), o; return o.addEventListener(e, t, n), o;
}; };
} }
var O = J(); var _ = V();
T.connected = function(e, t) { U.connected = function(e, t) {
return typeof t != "object" && (t = {}), t.once = !0, function(r) { return typeof t != "object" && (t = {}), t.once = !0, function(r) {
return r.addEventListener("dde:connected", e, t), typeof r.connectedCallback == "function" ? r : r.isConnected ? (r.dispatchEvent(new Event("dde:connected")), r) : (C(t.signal, () => O.offConnected(r, e)) && O.onConnected(r, e), r); return r.addEventListener("dde:connected", e, t), typeof r.connectedCallback == "function" ? r : r.isConnected ? (r.dispatchEvent(new Event("dde:connected")), r) : (L(t.signal, () => _.offConnected(r, e)) && _.onConnected(r, e), r);
}; };
}; };
T.disconnected = function(e, t) { U.disconnected = function(e, t) {
return typeof t != "object" && (t = {}), t.once = !0, function(r) { return typeof t != "object" && (t = {}), t.once = !0, function(r) {
return r.addEventListener("dde:disconnected", e, t), typeof r.disconnectedCallback == "function" || C(t.signal, () => O.offDisconnected(r, e)) && O.onDisconnected(r, e), r; return r.addEventListener("dde:disconnected", e, t), typeof r.disconnectedCallback == "function" || L(t.signal, () => _.offDisconnected(r, e)) && _.onDisconnected(r, e), r;
}; };
}; };
function J() { function V() {
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(i) { let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) {
for (let s of i) for (let i of c)
if (s.type === "childList") { if (i.type === "childList") {
if (v(s.addedNodes, !0)) { if (b(i.addedNodes, !0)) {
l(); a();
continue; continue;
} }
x(s.removedNodes, !0) && l(); x(i.removedNodes, !0) && a();
} }
}); });
return { return {
onConnected(i, s) { onConnected(c, i) {
c(); u();
let f = o(i); let f = o(c);
f.connected.has(s) || (f.connected.add(s), f.length_c += 1); f.connected.has(i) || (f.connected.add(i), f.length_c += 1);
}, },
offConnected(i, s) { offConnected(c, i) {
if (!e.has(i)) if (!e.has(c))
return; return;
let f = e.get(i); let f = e.get(c);
f.connected.has(s) && (f.connected.delete(s), f.length_c -= 1, r(i, f)); f.connected.has(i) && (f.connected.delete(i), f.length_c -= 1, r(c, f));
}, },
onDisconnected(i, s) { onDisconnected(c, i) {
c(); u();
let f = o(i); let f = o(c);
f.disconnected.has(s) || (f.disconnected.add(s), f.length_d += 1); f.disconnected.has(i) || (f.disconnected.add(i), f.length_d += 1);
}, },
offDisconnected(i, s) { offDisconnected(c, i) {
if (!e.has(i)) if (!e.has(c))
return; return;
let f = e.get(i); let f = e.get(c);
f.disconnected.has(s) && (f.disconnected.delete(s), f.length_d -= 1, r(i, f)); f.disconnected.has(i) && (f.disconnected.delete(i), f.length_d -= 1, r(c, f));
} }
}; };
function r(i, s) { function r(c, i) {
s.length_c || s.length_d || (e.delete(i), l()); i.length_c || i.length_d || (e.delete(c), a());
} }
function o(i) { function o(c) {
if (e.has(i)) if (e.has(c))
return e.get(i); return e.get(c);
let s = { let i = {
connected: /* @__PURE__ */ new WeakSet(), connected: /* @__PURE__ */ new WeakSet(),
length_c: 0, length_c: 0,
disconnected: /* @__PURE__ */ new WeakSet(), disconnected: /* @__PURE__ */ new WeakSet(),
length_d: 0 length_d: 0
}; };
return e.set(i, s), s; return e.set(c, i), i;
}
function c() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
}
function l() {
!t || e.size || (t = !1, n.disconnect());
} }
function u() { function u() {
return new Promise(function(i) { t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
(requestIdleCallback || requestAnimationFrame)(i); }
function a() {
!t || e.size || (t = !1, n.disconnect());
}
function s() {
return new Promise(function(c) {
(requestIdleCallback || requestAnimationFrame)(c);
}); });
} }
async function a(i) { async function d(c) {
e.size > 30 && await u(); e.size > 30 && await s();
let s = []; let i = [];
if (!(i instanceof Node)) if (!(c instanceof Node))
return s; return i;
for (let f of e.keys()) for (let f of e.keys())
f === i || !(f instanceof Node) || i.contains(f) && s.push(f); f === c || !(f instanceof Node) || c.contains(f) && i.push(f);
return s; return i;
} }
function v(i, s) { function b(c, i) {
let f = !1; let f = !1;
for (let p of i) { for (let l of c) {
if (s && a(p).then(v), !e.has(p)) if (i && d(l).then(b), !e.has(l))
continue; continue;
let E = e.get(p); let v = e.get(l);
E.length_c && (p.dispatchEvent(new Event("dde:connected")), E.connected = /* @__PURE__ */ new WeakSet(), E.length_c = 0, E.length_d || e.delete(p), f = !0); v.length_c && (l.dispatchEvent(new Event("dde:connected")), v.connected = /* @__PURE__ */ new WeakSet(), v.length_c = 0, v.length_d || e.delete(l), f = !0);
} }
return f; return f;
} }
function x(i, s) { function x(c, i) {
let f = !1; let f = !1;
for (let p of i) for (let l of c)
s && a(p).then(x), !(!e.has(p) || !e.get(p).length_d) && (p.dispatchEvent(new Event("dde:disconnected")), e.delete(p), f = !0); i && d(l).then(x), !(!e.has(l) || !e.get(l).length_d) && (l.dispatchEvent(new Event("dde:disconnected")), e.delete(l), f = !0);
return f; return f;
} }
} }
@ -273,10 +288,10 @@ function J() {
}); });
// src/signals-lib.js // src/signals-lib.js
var d = Symbol.for("Signal"); var p = Symbol.for("Signal");
function _(e) { function R(e) {
try { try {
return Reflect.has(e, d); return Reflect.has(e, p);
} catch { } catch {
return !1; return !1;
} }
@ -284,128 +299,128 @@ function _(e) {
var h = /* @__PURE__ */ new WeakMap(); var h = /* @__PURE__ */ new WeakMap();
function g(e, t) { function g(e, t) {
if (typeof e != "function") if (typeof e != "function")
return U(e, t); return $(e, t);
if (_(e)) if (R(e))
return e; return e;
let n = U(""), r = () => n(e()); let n = $(""), r = () => n(e());
return h.set(r, /* @__PURE__ */ new Set([n])), K(r), n; return h.set(r, /* @__PURE__ */ new Set([n])), Q(r), n;
} }
g.action = function(e, t, ...n) { g.action = function(e, t, ...n) {
let r = e[d], { actions: o } = r; let r = e[p], { 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(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((c) => c(r.value)); r.listeners.forEach((u) => u(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((c) => e(c, n, r)); return t.forEach((u) => e(u, n, r));
N(t, n), o && o.addEventListener("abort", () => k(t, n)); D(t, n), o && o.addEventListener("abort", () => q(t, n));
} }
}; };
g.symbols = { g.symbols = {
signal: d, signal: p,
onclear: Symbol.for("Signal.onclear") onclear: Symbol.for("Signal.onclear")
}; };
g.clear = function(...e) { g.clear = function(...e) {
for (let n of e) { for (let n of e) {
Reflect.deleteProperty(n, "toJSON"); Reflect.deleteProperty(n, "toJSON");
let r = n[d], { onclear: o } = g.symbols; let r = n[p], { onclear: o } = g.symbols;
r.actions && r.actions[o] && r.actions[o].call(r), t(n, r), Reflect.deleteProperty(n, d); r.actions && r.actions[o] && r.actions[o].call(r), t(n, r), Reflect.deleteProperty(n, p);
} }
function t(n, r) { function t(n, r) {
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 c = h.get(o); let u = h.get(o);
c.delete(n), !(c.size > 1) && (g.clear(...c), h.delete(o)); u.delete(n), !(u.size > 1) && (g.clear(...u), 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 c = (l) => { let u = (a) => {
if (!n.parentNode || !r.parentNode) if (!n.parentNode || !r.parentNode)
return k(e, c); return q(e, u);
let u = t(l); let s = t(a);
Array.isArray(u) || (u = [u]); Array.isArray(s) || (s = [s]);
let a = n; let d = n;
for (; (a = n.nextSibling) !== r; ) for (; (d = n.nextSibling) !== r; )
a.remove(); d.remove();
n.after(...u); n.after(...s);
}; };
return N(e, c), c(e()), o; return D(e, u), u(e()), o;
}; };
var $ = { var k = {
isSignal: _, isSignal: R,
processReactiveAttribute(e, t, n, r) { processReactiveAttribute(e, t, n, r) {
return _(n) ? (N(n, (o) => r([t, o])), n()) : n; return R(n) ? (D(n, (o) => r([t, o])), n()) : n;
} }
}; };
function U(e, t) { function $(e, t) {
let n = (...r) => r.length ? Y(n, r[0]) : X(n); let n = (...r) => r.length ? ee(n, r[0]) : Y(n);
return Z(n, e, t); return K(n, e, t);
} }
var V = Object.assign(/* @__PURE__ */ Object.create(null), { var Z = Object.assign(/* @__PURE__ */ Object.create(null), {
stopPropagation() { stopPropagation() {
this.skip = !0; this.skip = !0;
} }
}); });
function Z(e, t, n) { function K(e, t, n) {
return D(n) !== "[object Object]" && (n = {}), e[d] = { return P(n) !== "[object Object]" && (n = {}), e[p] = {
value: t, value: t,
actions: n, actions: n,
listeners: /* @__PURE__ */ new Set() listeners: /* @__PURE__ */ new Set()
}, e.toJSON = () => e(), Object.setPrototypeOf(e[d], V), e; }, e.toJSON = () => e(), Object.setPrototypeOf(e[p], Z), e;
} }
var R = []; var A = [];
function K(e) { function Q(e) {
let t = function() { let t = function() {
R.push(t), e(), R.pop(); A.push(t), e(), A.pop();
}; };
h.has(e) && (h.set(t, h.get(e)), h.delete(e)), t(); h.has(e) && (h.set(t, h.get(e)), h.delete(e)), t();
} }
function Q() { function X() {
return R[R.length - 1]; return A[A.length - 1];
} }
function X(e) { function Y(e) {
if (!e[d]) if (!e[p])
return; return;
let { value: t, listeners: n } = e[d], r = Q(); let { value: t, listeners: n } = e[p], r = X();
return r && n.add(r), h.has(r) && h.get(r).add(e), t; return r && n.add(r), h.has(r) && h.get(r).add(e), t;
} }
function Y(e, t) { function ee(e, t) {
if (!e[d]) if (!e[p])
return; return;
let n = e[d]; let n = e[p];
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[p])
return e[d].listeners.add(t); return e[p].listeners.add(t);
} }
function k(e, t) { function q(e, t) {
if (e[d]) if (e[p])
return e[d].listeners.delete(t); return e[p].listeners.delete(t);
} }
// signals.js // signals.js
A($); C(k);
export { export {
g as S, g as S,
y as assign, y as assign,
B as classListDeclarative, B as classListDeclarative,
ie as createElement, se as createElement,
de as dispatchEvent, de as dispatchEvent,
ie as el, se as el,
fe as empty, fe as empty,
_ as isSignal, R as isSignal,
T as on, U as on,
A as registerReactivity, C as registerReactivity,
ce as scope O as scope
}; };

247
dist/esm.js vendored
View File

@ -1,21 +1,21 @@
// src/signals-common.js // src/signals-common.js
var E = { var m = {
isSignal(e) { isSignal(e) {
return !1; return !1;
}, },
processReactiveAttribute(e, t, r, n) { processReactiveAttribute(e, t, n, r) {
return r; return n;
} }
}; };
function N(e, t = !0) { function P(e, t = !0) {
return t ? Object.assign(E, e) : (Object.setPrototypeOf(e, E), e); return t ? Object.assign(m, e) : (Object.setPrototypeOf(e, m), e);
} }
function m(e) { function b(e) {
return E.isPrototypeOf(e) && e !== E ? e : E; return m.isPrototypeOf(e) && e !== m ? e : m;
} }
// src/helpers.js // src/helpers.js
function p(e) { function l(e) {
return typeof e > "u"; return typeof e > "u";
} }
function _(e, t) { function _(e, t) {
@ -28,9 +28,9 @@ function _(e, t) {
} }
// src/dom-common.js // src/dom-common.js
var O = { setDeleteAttr: P }; var R = { setDeleteAttr: j };
function P(e, t, r) { function j(e, t, n) {
if (Reflect.set(e, t, r), !!p(r)) { if (Reflect.set(e, t, n), !!l(n)) {
if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined") if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined")
return e.removeAttribute(t); return e.removeAttribute(t);
if (Reflect.get(e, t) === "undefined") if (Reflect.get(e, t) === "undefined")
@ -39,154 +39,169 @@ function P(e, t, r) {
} }
// src/dom.js // src/dom.js
var h = "html", S = { var v = [{ scope: document.body, namespace: "html", host: (e) => e ? e(document.body) : document.body }], C = (e) => e === "svg" ? "http://www.w3.org/2000/svg" : e, x = {
get current() {
return v[v.length - 1];
},
get state() {
return [...v];
},
get host() {
return this.current.host;
},
get namespace() {
return this.current.namespace;
},
set namespace(e) {
return this.current.namespace = C(e);
},
elNamespace(e) { elNamespace(e) {
return h = e === "svg" ? "http://www.w3.org/2000/svg" : e, { let t = this.namespace;
append(...t) { return this.namespace = e, {
return h = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t); append(...n) {
return x.namespace = t, n.length === 1 ? n[0] : document.createDocumentFragment().append(...n);
} }
}; };
}, },
get namespace() { push(e = {}) {
return h; return e.namespace && (e.namespace = C(e.namespace)), v.push(Object.assign({}, this.current, e));
}, },
set namespace(e) { pop() {
return h = e; return v.pop();
} }
}, H = Object.assign((e) => e ? e(document.body) : document.body, S); };
function I(e, t, ...r) { function I(e, t, ...n) {
let n = this, u = m(this), i; let r = this, u = b(this), { namespace: d } = x, f;
switch ((Object(t) !== t || u.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": {
let a = Object.assign((f) => f ? (r.unshift(f), void 0) : i, S); x.push({ scope: e, host: (i) => i ? (n.unshift(i), void 0) : f }), f = e(t || void 0), x.pop();
i = e(t || void 0, a), h = "html";
break; break;
} }
case e === "#text": case e === "#text":
i = w.call(n, document.createTextNode(""), t); f = w.call(r, document.createTextNode(""), t);
break; break;
case e === "<>": case e === "<>":
i = w.call(n, document.createDocumentFragment(), t); f = w.call(r, document.createDocumentFragment(), t);
break; break;
case h !== "html": case d !== "html":
i = w.call(n, document.createElementNS(h, e), t); f = w.call(r, document.createElementNS(d, e), t);
break; break;
case !i: case !f:
i = w.call(n, document.createElement(e), t); f = w.call(r, document.createElement(e), t);
} }
return r.forEach((a) => a(i)), i; return n.forEach((i) => i(f)), f;
} }
var { setDeleteAttr: R } = O; var { setDeleteAttr: S } = R;
function w(e, ...t) { function w(e, ...t) {
let r = this, n = m(this); let n = this, r = b(this);
if (!t.length) if (!t.length)
return e; return e;
let i = (e instanceof SVGElement ? T : M).bind(null, e, "Attribute"); let d = (e instanceof SVGElement ? U : T).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function a([f, d]) { return Object.entries(Object.assign({}, ...t)).forEach(function f([i, a]) {
d = n.processReactiveAttribute(e, f, d, a); a = r.processReactiveAttribute(e, i, a, f);
let [g] = f; let [h] = i;
if (g === "=") if (h === "=")
return i(f.slice(1), d); return d(i.slice(1), a);
if (g === ".") if (h === ".")
return C(e, f.slice(1), d); return y(e, i.slice(1), a);
if (/(aria|data)([A-Z])/.test(f)) if (/(aria|data)([A-Z])/.test(i))
return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(f, d); return i = i.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), d(i, a);
switch (f === "className" && (f = "class"), f) { switch (i === "className" && (i = "class"), i) {
case "xlink:href": case "xlink:href":
return i(f, d, "http://www.w3.org/1999/xlink"); return d(i, a, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
return R(e, f, d); return S(e, i, a);
case "style": case "style":
if (typeof d != "object") if (typeof a != "object")
break; break;
case "dataset": case "dataset":
return A(n, d, C.bind(null, e[f])); return O(r, a, y.bind(null, e[i]));
case "ariaset": case "ariaset":
return A(n, d, (b, c) => i("aria-" + b, c)); return O(r, a, (E, c) => d("aria-" + E, c));
case "classList": case "classList":
return j.call(r, e, d); return F.call(n, e, a);
} }
return F(e, f) ? R(e, f, d) : i(f, d); return M(e, i) ? S(e, i, a) : d(i, a);
}), e; }), e;
} }
function j(e, t) { function F(e, t) {
let r = m(this); let n = b(this);
return A( return O(
r, n,
t, t,
(n, u) => e.classList.toggle(n, u === -1 ? void 0 : !!u) (r, u) => e.classList.toggle(r, u === -1 ? void 0 : !!u)
), e; ), e;
} }
function Z(e) { function Z(e) {
return Array.from(e.children).forEach((t) => t.remove()), e; return Array.from(e.children).forEach((t) => t.remove()), e;
} }
function F(e, t) { function M(e, t) {
if (!Reflect.has(e, t)) if (!Reflect.has(e, t))
return !1; return !1;
let r = y(e, t); let n = D(e, t);
return !p(r.set); return !l(n.set);
} }
function y(e, t) { function D(e, t) {
if (e = Object.getPrototypeOf(e), !e) if (e = Object.getPrototypeOf(e), !e)
return {}; return {};
let r = Object.getOwnPropertyDescriptor(e, t); let n = Object.getOwnPropertyDescriptor(e, t);
return r || y(e, t); return n || D(e, t);
} }
function A(e, t, r) { function O(e, t, n) {
if (!(typeof t != "object" || t === null)) if (!(typeof t != "object" || t === null))
return Object.entries(t).forEach(function([u, i]) { return Object.entries(t).forEach(function([u, d]) {
u && (i = e.processReactiveAttribute(t, u, i, (a) => r(...a)), r(u, i)); u && (d = e.processReactiveAttribute(t, u, d, (f) => n(...f)), n(u, d));
}); });
} }
function D(e) { function L(e) {
return Array.isArray(e) ? e.filter(Boolean).join(" ") : e; return Array.isArray(e) ? e.filter(Boolean).join(" ") : e;
} }
function M(e, t, r, n) { function T(e, t, n, r) {
return e[(p(n) ? "remove" : "set") + t](r, D(n)); return e[(l(r) ? "remove" : "set") + t](n, L(r));
} }
function T(e, t, r, n, u = null) { function U(e, t, n, r, u = null) {
return e[(p(n) ? "remove" : "set") + t + "NS"](u, r, D(n)); return e[(l(r) ? "remove" : "set") + t + "NS"](u, n, L(r));
} }
function C(e, t, r) { function y(e, t, n) {
if (Reflect.set(e, t, r), !!p(r)) if (Reflect.set(e, t, n), !!l(n))
return Reflect.deleteProperty(e, t); return Reflect.deleteProperty(e, t);
} }
// src/events.js // src/events.js
function K(e, t, ...r) { function K(e, t, ...n) {
let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t); let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t);
return e.dispatchEvent(n); return e.dispatchEvent(r);
} }
function L(e, t, r) { function N(e, t, n) {
return function(u) { return function(u) {
return u.addEventListener(e, t, r), u; return u.addEventListener(e, t, n), u;
}; };
} }
var x = U(); var A = W();
L.connected = function(e, t) { N.connected = function(e, t) {
return typeof t != "object" && (t = {}), t.once = !0, function(n) { return typeof t != "object" && (t = {}), t.once = !0, function(r) {
return n.addEventListener("dde:connected", e, t), typeof n.connectedCallback == "function" ? n : n.isConnected ? (n.dispatchEvent(new Event("dde:connected")), n) : (_(t.signal, () => x.offConnected(n, e)) && x.onConnected(n, e), n); return r.addEventListener("dde:connected", e, t), typeof r.connectedCallback == "function" ? r : r.isConnected ? (r.dispatchEvent(new Event("dde:connected")), r) : (_(t.signal, () => A.offConnected(r, e)) && A.onConnected(r, e), r);
}; };
}; };
L.disconnected = function(e, t) { N.disconnected = function(e, t) {
return typeof t != "object" && (t = {}), t.once = !0, function(n) { return typeof t != "object" && (t = {}), t.once = !0, function(r) {
return n.addEventListener("dde:disconnected", e, t), typeof n.disconnectedCallback == "function" || _(t.signal, () => x.offDisconnected(n, e)) && x.onDisconnected(n, e), n; return r.addEventListener("dde:disconnected", e, t), typeof r.disconnectedCallback == "function" || _(t.signal, () => A.offDisconnected(r, e)) && A.onDisconnected(r, e), r;
}; };
}; };
function U() { function W() {
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 o of c) for (let o of c)
if (o.type === "childList") { if (o.type === "childList") {
if (g(o.addedNodes, !0)) { if (h(o.addedNodes, !0)) {
a(); f();
continue; continue;
} }
b(o.removedNodes, !0) && a(); E(o.removedNodes, !0) && f();
} }
}); });
return { return {
onConnected(c, o) { onConnected(c, o) {
i(); d();
let s = u(c); let s = u(c);
s.connected.has(o) || (s.connected.add(o), s.length_c += 1); s.connected.has(o) || (s.connected.add(o), s.length_c += 1);
}, },
@ -194,10 +209,10 @@ function U() {
if (!e.has(c)) if (!e.has(c))
return; return;
let s = e.get(c); let s = e.get(c);
s.connected.has(o) && (s.connected.delete(o), s.length_c -= 1, n(c, s)); s.connected.has(o) && (s.connected.delete(o), s.length_c -= 1, r(c, s));
}, },
onDisconnected(c, o) { onDisconnected(c, o) {
i(); d();
let s = u(c); let s = u(c);
s.disconnected.has(o) || (s.disconnected.add(o), s.length_d += 1); s.disconnected.has(o) || (s.disconnected.add(o), s.length_d += 1);
}, },
@ -205,11 +220,11 @@ function U() {
if (!e.has(c)) if (!e.has(c))
return; return;
let s = e.get(c); let s = e.get(c);
s.disconnected.has(o) && (s.disconnected.delete(o), s.length_d -= 1, n(c, s)); s.disconnected.has(o) && (s.disconnected.delete(o), s.length_d -= 1, r(c, s));
} }
}; };
function n(c, o) { function r(c, o) {
o.length_c || o.length_d || (e.delete(c), a()); o.length_c || o.length_d || (e.delete(c), f());
} }
function u(c) { function u(c) {
if (e.has(c)) if (e.has(c))
@ -222,19 +237,19 @@ function U() {
}; };
return e.set(c, o), o; return e.set(c, o), o;
} }
function i() { function d() {
t || (t = !0, r.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
}
function a() {
!t || e.size || (t = !1, r.disconnect());
} }
function f() { function f() {
!t || e.size || (t = !1, n.disconnect());
}
function i() {
return new Promise(function(c) { return new Promise(function(c) {
(requestIdleCallback || requestAnimationFrame)(c); (requestIdleCallback || requestAnimationFrame)(c);
}); });
} }
async function d(c) { async function a(c) {
e.size > 30 && await f(); e.size > 30 && await i();
let o = []; let o = [];
if (!(c instanceof Node)) if (!(c instanceof Node))
return o; return o;
@ -242,20 +257,20 @@ function U() {
s === c || !(s instanceof Node) || c.contains(s) && o.push(s); s === c || !(s instanceof Node) || c.contains(s) && o.push(s);
return o; return o;
} }
function g(c, o) { function h(c, o) {
let s = !1; let s = !1;
for (let l of c) { for (let p of c) {
if (o && d(l).then(g), !e.has(l)) if (o && a(p).then(h), !e.has(p))
continue; continue;
let v = e.get(l); let g = e.get(p);
v.length_c && (l.dispatchEvent(new Event("dde:connected")), v.connected = /* @__PURE__ */ new WeakSet(), v.length_c = 0, v.length_d || e.delete(l), s = !0); g.length_c && (p.dispatchEvent(new Event("dde:connected")), g.connected = /* @__PURE__ */ new WeakSet(), g.length_c = 0, g.length_d || e.delete(p), s = !0);
} }
return s; return s;
} }
function b(c, o) { function E(c, o) {
let s = !1; let s = !1;
for (let l of c) for (let p of c)
o && d(l).then(b), !(!e.has(l) || !e.get(l).length_d) && (l.dispatchEvent(new Event("dde:disconnected")), e.delete(l), s = !0); o && a(p).then(E), !(!e.has(p) || !e.get(p).length_d) && (p.dispatchEvent(new Event("dde:disconnected")), e.delete(p), s = !0);
return s; return s;
} }
} }
@ -263,18 +278,18 @@ function U() {
// index.js // index.js
[HTMLElement, SVGElement, DocumentFragment].forEach((e) => { [HTMLElement, SVGElement, 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;
}; };
}); });
export { export {
w as assign, w as assign,
j as classListDeclarative, F as classListDeclarative,
I as createElement, I as createElement,
K as dispatchEvent, K as dispatchEvent,
I as el, I as el,
Z as empty, Z as empty,
L as on, N as on,
N as registerReactivity, P as registerReactivity,
H as scope x as scope
}; };

View File

@ -1,17 +1,17 @@
import { style, el, on, S } from '../exports.js'; import { style, el, on, S, scope } from '../exports.js';
const className= style.host(fullNameComponent).css` const className= style.host(fullNameComponent).css`
:host form{ :host form{
display: flex; display: flex;
flex-flow: column nowrap; flex-flow: column nowrap;
} }
`; `;
export function fullNameComponent(_, scope){ export function fullNameComponent(){
const labels= [ "Name", "Surname" ]; const labels= [ "Name", "Surname" ];
const name= labels.map(_=> S("")); const name= labels.map(_=> S(""));
const full_name= S(()=> const full_name= S(()=>
name.map(l=> l()).filter(Boolean).join(" ") || "-"); name.map(l=> l()).filter(Boolean).join(" ") || "-");
scope(on.connected(()=> console.log(fullNameComponent))); scope.host(on.connected(()=> console.log(fullNameComponent)));
scope(on.disconnected(()=> console.log(fullNameComponent))) scope.host(on.disconnected(()=> console.log(fullNameComponent)))
return el("div", { className }).append( return el("div", { className }).append(
el("h2", "Simple form:"), el("h2", "Simple form:"),

View File

@ -1,4 +1,4 @@
import { style, el, dispatchEvent, on, S } from '../exports.js'; import { style, el, dispatchEvent, on, S, scope } from '../exports.js';
const className= style.host(todosComponent).css` const className= style.host(todosComponent).css`
:host{ :host{
display: flex; display: flex;
@ -18,7 +18,7 @@ const className= style.host(todosComponent).css`
export function todosComponent({ todos= [ "Task A" ] }= {}){ export function todosComponent({ todos= [ "Task A" ] }= {}){
const todosS= S(todos.map(t=> S(t)), { const todosS= S(todos.map(t=> S(t)), {
add(v){ this.value.push(S(v)); }, add(v){ this.value.push(S(v)); },
remove(i){ this.value.splice(i, 1); }, remove(i){ S.clear(this.value.splice(i, 1)[0]); },
[S.symbols.onclear](){ S.clear(...this.value); }, [S.symbols.onclear](){ S.clear(...this.value); },
}); });
const name= "todoName"; const name= "todoName";
@ -65,7 +65,8 @@ export function todosComponent({ todos= [ "Task A" ] }= {}){
* [ "click" ] * [ "click" ]
* >} * >}
* */ * */
function todoComponent({ textContent, value }, host){ function todoComponent({ textContent, value }){
const { host }= scope;
const onclick= on("click", event=> { const onclick= on("click", event=> {
const value= Number(event.target.value); const value= Number(event.target.value);
event.preventDefault(); event.preventDefault();

View File

@ -1,4 +1,4 @@
import { el } from "../../index.js"; import { el, scope } from "../../index.js";
import { S } from "../../signals.js"; import { S } from "../../signals.js";
const { hasOwnProperty }= Object.prototype; const { hasOwnProperty }= Object.prototype;
@ -16,9 +16,10 @@ export class CustomHTMLTestElement extends HTMLElement{
); );
} }
render({ name, test, preName }, host){ render({ name, test, preName }){
host(on.connected(()=> console.log(CustomHTMLTestElement))); console.log(scope.state);
host(on.disconnected(()=> console.log(CustomHTMLTestElement))); scope.host(on.connected(()=> console.log(CustomHTMLTestElement)));
scope.host(on.disconnected(()=> console.log(CustomHTMLTestElement)));
return el("p").append( return el("p").append(
el("#text", { textContent: name }), el("#text", { textContent: name }),
el("#text", { textContent: test }), el("#text", { textContent: test }),
@ -36,8 +37,10 @@ customElementsAssign(
customElements.define("custom-test", CustomHTMLTestElement); customElements.define("custom-test", CustomHTMLTestElement);
function customElementRender(_this, attrs, render){ function customElementRender(_this, attrs, render){
const host= (...a)=> a.length ? a[0](_this) : _this; scope.push({ scope: _this, host: (...a)=> a.length ? a[0](_this) : _this });
return render(attrs, host); const out= render(attrs);
scope.pop();
return out;
} }
/** @returns {HTMLElement} */ /** @returns {HTMLElement} */
function customElementsAssign(class_base, ...automatize){ function customElementsAssign(class_base, ...automatize){

View File

@ -1,41 +1,51 @@
import { signals } from "./signals-common.js"; import { signals } from "./signals-common.js";
/** @type {"html"|"svg"|string} */ /** @type {{ namespace: "html"|string, host: function }[]} */
let namespace_curr= "html"; const scopes= [ { scope: document.body, namespace: "html", host: c=> c ? c(document.body) : document.body } ];
const scopes= { const namespaceHelper= ns=> ns==="svg" ? "http://www.w3.org/2000/svg" : ns;
export const scope= {
get current(){ return scopes[scopes.length-1]; },
get state(){ return [ ...scopes ]; },
get host(){ return this.current.host; },
get namespace(){ return this.current.namespace; },
set namespace(namespace){ return ( this.current.namespace= namespaceHelper(namespace)); },
elNamespace(namespace){ elNamespace(namespace){
namespace_curr= namespace==="svg" ? "http://www.w3.org/2000/svg" : namespace; const ns= this.namespace;
this.namespace= namespace;
return { return {
append(...el){ append(...els){
namespace_curr= "html"; scope.namespace= ns;
if(el.length===1) return el[0]; if(els.length===1) return els[0];
const f= document.createDocumentFragment(); const f= document.createDocumentFragment();
return f.append(...el); return f.append(...els);
} }
}; };
}, },
get namespace(){ return namespace_curr; }, push(s= {}){
set namespace(v){ return ( namespace_curr= v ); }, if(s.namespace) s.namespace= namespaceHelper(s.namespace);
return scopes.push(Object.assign({}, this.current, s));
},
pop(){ return scopes.pop(); },
}; };
export const scope= Object.assign(c=> c ? c(document.body) : document.body, scopes);
export function createElement(tag, attributes, ...connect){ export function createElement(tag, attributes, ...connect){
const _this= this; const _this= this;
const s= signals(this); const s= signals(this);
const { namespace }= scope;
let el; let el;
//TODO Array.isArray(tag) ⇒ set key (cache els) //TODO Array.isArray(tag) ⇒ set key (cache els)
if(Object(attributes)!==attributes || s.isSignal(attributes)) if(Object(attributes)!==attributes || s.isSignal(attributes))
attributes= { textContent: attributes }; attributes= { textContent: attributes };
switch(true){ switch(true){
case typeof tag==="function": { case typeof tag==="function": {
const scope= Object.assign(c=> c ? (connect.unshift(c), undefined) : el, scopes); scope.push({ scope: tag, host: c=> c ? (connect.unshift(c), undefined) : el });
el= tag(attributes || undefined, scope); el= tag(attributes || undefined);
namespace_curr= "html"; scope.pop();
break; break;
} }
case tag==="#text": el= assign.call(_this, document.createTextNode(""), attributes); break; case tag==="#text": el= assign.call(_this, document.createTextNode(""), attributes); break;
case tag==="<>": el= assign.call(_this, document.createDocumentFragment(), 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 namespace!=="html": el= assign.call(_this, document.createElementNS(namespace, tag), attributes); break;
case !el: el= assign.call(_this, document.createElement(tag), attributes); case !el: el= assign.call(_this, document.createElement(tag), attributes);
} }
connect.forEach(c=> c(el)); connect.forEach(c=> c(el));
return el; return el;