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

📦 dist

This commit is contained in:
Jan Andrle 2023-10-15 11:13:36 +02:00
parent f08d495a5c
commit 995bacde7a
Signed by: jaandrle
GPG Key ID: B3A25AED155AFFAB
4 changed files with 1024 additions and 964 deletions

View File

@ -2,57 +2,57 @@
(()=> { (()=> {
// src/signals-common.js // src/signals-common.js
var x = { var x = {
isSignal(e) { isSignal(t) {
return !1; return !1;
}, },
processReactiveAttribute(e, t, n, o) { processReactiveAttribute(t, e, n, o) {
return n; return n;
} }
}; };
function D(e, t = !0) { function P(t, e = !0) {
return t ? Object.assign(x, e) : (Object.setPrototypeOf(e, x), e); return e ? Object.assign(x, t) : (Object.setPrototypeOf(t, x), t);
} }
function y(e) { function S(t) {
return x.isPrototypeOf(e) && e !== x ? e : x; return x.isPrototypeOf(t) && t !== x ? t : x;
} }
// src/helpers.js // src/helpers.js
function E(e) { function E(t) {
return typeof e > "u"; return typeof t > "u";
} }
function T(e) { function M(t) {
let t = typeof e; let e = typeof t;
return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e); return e !== "object" ? e : t === null ? "null" : Object.prototype.toString.call(t);
} }
function A(e, t) { function A(t, e) {
if (!e || !(e instanceof AbortSignal)) if (!t || !(t instanceof AbortSignal))
return !0; return !0;
if (!e.aborted) if (!t.aborted)
return e.addEventListener("abort", t), function() { return t.addEventListener("abort", e), function() {
e.removeEventListener("abort", t); t.removeEventListener("abort", e);
}; };
} }
// src/dom-common.js // src/dom-common.js
var M = { setDeleteAttr: I }; var W = { setDeleteAttr: Z };
function I(e, t, n) { function Z(t, e, n) {
if (Reflect.set(e, t, n), !!E(n)) { if (Reflect.set(t, e, n), !!E(n)) {
if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined") if (Reflect.deleteProperty(t, e), t instanceof HTMLElement && t.getAttribute(e) === "undefined")
return e.removeAttribute(t); return t.removeAttribute(e);
if (Reflect.get(e, t) === "undefined") if (Reflect.get(t, e) === "undefined")
return Reflect.set(e, t, ""); return Reflect.set(t, e, "");
} }
} }
// src/dom.js // src/dom.js
var S = [{ var y = [{
scope: document.body, scope: document.body,
namespace: "html", namespace: "html",
host: (e) => e ? e(document.body) : document.body, host: (t) => t ? t(document.body) : document.body,
prevent: !0 prevent: !0
}], W = (e) => e === "svg" ? "http://www.w3.org/2000/svg" : e, b = { }], F = (t) => t === "svg" ? "http://www.w3.org/2000/svg" : t, m = {
get current() { get current() {
return S[S.length - 1]; return y[y.length - 1];
}, },
get host() { get host() {
return this.current.host; return this.current.host;
@ -60,444 +60,459 @@
get namespace() { get namespace() {
return this.current.namespace; return this.current.namespace;
}, },
set namespace(e) { set namespace(t) {
return this.current.namespace = W(e); return this.current.namespace = F(t);
}, },
preventDefault() { preventDefault() {
let { current: e } = this; let { current: t } = this;
return e.prevent = !0, e; return t.prevent = !0, t;
}, },
elNamespace(e) { elNamespace(t) {
let t = this.namespace; let e = this.namespace;
return this.namespace = e, { return this.namespace = t, {
append(...n) { append(...n) {
return b.namespace = t, n.length === 1 ? n[0] : document.createDocumentFragment().append(...n); return m.namespace = e, n.length === 1 ? n[0] : document.createDocumentFragment().append(...n);
} }
}; };
}, },
get state() { get state() {
return [...S]; return [...y];
}, },
push(e = {}) { push(t = {}) {
return e.namespace && (e.namespace = W(e.namespace)), S.push(Object.assign({}, this.current, { prevent: !1 }, e)); return t.namespace && (t.namespace = F(t.namespace)), y.push(Object.assign({}, this.current, { prevent: !1 }, t));
}, },
pop() { pop() {
return S.pop(); return y.pop();
} }
}; };
function ie(e, t, ...n) { function at(t, e, ...n) {
let o = y(this), { namespace: r } = b, c = 0, i; let o = S(this), { namespace: r } = m, c = 0, s;
switch ((Object(t) !== t || o.isSignal(t)) && (t = { textContent: t }), !0) { switch ((Object(e) !== e || o.isSignal(e)) && (e = { textContent: e }), !0) {
case typeof e == "function": { case typeof t == "function": {
c = 1, b.push({ scope: e, host: (s) => s ? (c === 1 ? n.unshift(s) : s(i), void 0) : i }), i = e(t || void 0), (i instanceof HTMLElement ? $ : q)(i, "Attribute", "dde-fun", e.name); c = 1, m.push({ scope: t, host: (a) => a ? (c === 1 ? n.unshift(a) : a(s), void 0) : s }), s = t(e || void 0), (s instanceof HTMLElement ? B : G)(s, "Attribute", "dde-fun", t.name);
break; break;
} }
case e === "#text": case t === "#text":
i = O.call(this, document.createTextNode(""), t); s = R.call(this, document.createTextNode(""), e);
break; break;
case e === "<>": case t === "<>":
i = O.call(this, document.createDocumentFragment(), t); s = R.call(this, document.createDocumentFragment(), e);
break; break;
case r !== "html": case r !== "html":
i = O.call(this, document.createElementNS(r, e), t); s = R.call(this, document.createElementNS(r, t), e);
break; break;
case !i: case !s:
i = O.call(this, document.createElement(e), t); s = R.call(this, document.createElement(t), e);
} }
return n.forEach((s) => s(i)), c && b.pop(), c = 2, i; return n.forEach((a) => a(s)), c && m.pop(), c = 2, s;
} }
var { setDeleteAttr: F } = M; var { setDeleteAttr: z } = W, O = /* @__PURE__ */ new WeakMap();
function O(e, ...t) { function R(t, ...e) {
let n = this, o = y(this); if (!e.length)
if (!t.length) return t;
return e; O.set(t, U(t, this));
let c = (e instanceof SVGElement ? q : $).bind(null, e, "Attribute"); for (let [n, o] of Object.entries(Object.assign({}, ...e)))
return Object.entries(Object.assign({}, ...t)).forEach(function i([s, d]) { H.call(this, t, n, o);
d = o.processReactiveAttribute(e, s, d, i); return O.delete(t), t;
let [m] = s;
if (m === "=")
return c(s.slice(1), d);
if (m === ".")
return z(e, s.slice(1), d);
if (/(aria|data)([A-Z])/.test(s))
return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), c(s, d);
switch (s === "className" && (s = "class"), s) {
case "xlink:href":
return c(s, d, "http://www.w3.org/1999/xlink");
case "textContent":
return F(e, s, d);
case "style":
if (typeof d != "object")
break;
case "dataset":
return P(o, d, z.bind(null, e[s]));
case "ariaset":
return P(o, d, (v, u) => c("aria-" + v, u));
case "classList":
return J.call(n, e, d);
}
return V(e, s) ? F(e, s, d) : c(s, d);
}), e;
} }
function J(e, t) { function H(t, e, n) {
let n = y(this); let { setRemoveAttr: o, s: r } = U(t, this), c = this;
return P( n = r.processReactiveAttribute(
n,
t, t,
(o, r) => e.classList.toggle(o, r === -1 ? void 0 : !!r) e,
), e; n,
(a, p) => H.call(c, t, a, p)
);
let [s] = e;
if (s === "=")
return o(e.slice(1), n);
if (s === ".")
return k(t, e.slice(1), n);
if (/(aria|data)([A-Z])/.test(e))
return e = e.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(e, n);
switch (e === "className" && (e = "class"), e) {
case "xlink:href":
return o(e, n, "http://www.w3.org/1999/xlink");
case "textContent":
return z(t, e, n);
case "style":
if (typeof n != "object")
break;
case "dataset":
return j(r, n, k.bind(null, t[e]));
case "ariaset":
return j(r, n, (a, p) => o("aria-" + a, p));
case "classList":
return K.call(c, t, n);
}
return Q(t, e) ? z(t, e, n) : o(e, n);
} }
function fe(e) { function U(t, e) {
return Array.from(e.children).forEach((t) => t.remove()), e; if (O.has(t))
return O.get(t);
let o = (t instanceof SVGElement ? G : B).bind(null, t, "Attribute"), r = S(e);
return { setRemoveAttr: o, s: r };
} }
function V(e, t) { function K(t, e) {
if (!Reflect.has(e, t)) let n = S(this);
return j(
n,
e,
(o, r) => t.classList.toggle(o, r === -1 ? void 0 : !!r)
), t;
}
function pt(t) {
return Array.from(t.children).forEach((e) => e.remove()), t;
}
function Q(t, e) {
if (!Reflect.has(t, e))
return !1; return !1;
let n = H(e, t); let n = $(t, e);
return !E(n.set); return !E(n.set);
} }
function H(e, t) { function $(t, e) {
if (e = Object.getPrototypeOf(e), !e) if (t = Object.getPrototypeOf(t), !t)
return {}; return {};
let n = Object.getOwnPropertyDescriptor(e, t); let n = Object.getOwnPropertyDescriptor(t, e);
return n || H(e, t); return n || $(t, e);
} }
function P(e, t, n) { function j(t, e, n) {
if (!(typeof t != "object" || t === null)) if (!(typeof e != "object" || e === null))
return Object.entries(t).forEach(function([r, c]) { return Object.entries(e).forEach(function([r, c]) {
r && (c = e.processReactiveAttribute(t, r, c, (i) => n(...i)), n(r, c)); r && (c = t.processReactiveAttribute(e, r, c, n), n(r, c));
}); });
} }
function U(e) { function q(t) {
return Array.isArray(e) ? e.filter(Boolean).join(" ") : e; return Array.isArray(t) ? t.filter(Boolean).join(" ") : t;
} }
function $(e, t, n, o) { function B(t, e, n, o) {
return e[(E(o) ? "remove" : "set") + t](n, U(o)); return t[(E(o) ? "remove" : "set") + e](n, q(o));
} }
function q(e, t, n, o, r = null) { function G(t, e, n, o, r = null) {
return e[(E(o) ? "remove" : "set") + t + "NS"](r, n, U(o)); return t[(E(o) ? "remove" : "set") + e + "NS"](r, n, q(o));
} }
function z(e, t, n) { function k(t, e, n) {
if (Reflect.set(e, t, n), !!E(n)) if (Reflect.set(t, e, n), !!E(n))
return Reflect.deleteProperty(e, t); return Reflect.deleteProperty(t, e);
} }
// src/events.js // src/events.js
function le(e, t, ...n) { function gt(t, e, ...n) {
let o = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); let o = n.length ? new CustomEvent(e, { detail: n[0] }) : new Event(e);
return e.dispatchEvent(o); return t.dispatchEvent(o);
} }
function _(e, t, n) { function v(t, e, n) {
return function(r) { return function(r) {
return r.addEventListener(e, t, n), r; return r.addEventListener(t, e, n), r;
}; };
} }
var R = K(), Z = /* @__PURE__ */ new WeakSet(); var C = Y(), X = /* @__PURE__ */ new WeakSet();
_.connected = function(e, t) { v.connected = function(t, e) {
let n = "connected"; let n = "connected";
return typeof t != "object" && (t = {}), t.once = !0, function(r) { return typeof e != "object" && (e = {}), e.once = !0, function(r) {
let c = "dde:" + n; let c = "dde:" + n;
return r.addEventListener(c, e, t), r.__dde_lifecycleToEvents ? r : r.isConnected ? (r.dispatchEvent(new Event(c)), r) : (A(t.signal, () => R.offConnected(r, e)) && R.onConnected(r, e), r); return r.addEventListener(c, t, e), r.__dde_lifecycleToEvents ? r : r.isConnected ? (r.dispatchEvent(new Event(c)), r) : (A(e.signal, () => C.offConnected(r, t)) && C.onConnected(r, t), r);
}; };
}; };
_.disconnected = function(e, t) { v.disconnected = function(t, e) {
let n = "disconnected"; let n = "disconnected";
return typeof t != "object" && (t = {}), t.once = !0, function(r) { return typeof e != "object" && (e = {}), e.once = !0, function(r) {
let c = "dde:" + n; let c = "dde:" + n;
return r.addEventListener(c, e, t), r.__dde_lifecycleToEvents || A(t.signal, () => R.offDisconnected(r, e)) && R.onDisconnected(r, e), r; return r.addEventListener(c, t, e), r.__dde_lifecycleToEvents || A(e.signal, () => C.offDisconnected(r, t)) && C.onDisconnected(r, t), r;
}; };
}; };
_.attributeChanged = function(e, t) { v.attributeChanged = function(t, e) {
let n = "attributeChanged"; let n = "attributeChanged";
return typeof t != "object" && (t = {}), function(r) { return typeof e != "object" && (e = {}), function(r) {
let c = "dde:" + n; let c = "dde:" + n;
if (r.addEventListener(c, e, t), r.__dde_lifecycleToEvents || Z.has(r)) if (r.addEventListener(c, t, e), r.__dde_lifecycleToEvents || X.has(r))
return r; return r;
let i = new MutationObserver(function(d) { let s = new MutationObserver(function(p) {
for (let { attributeName: m, target: v } of d) for (let { attributeName: b, target: _ } of p)
v.dispatchEvent( _.dispatchEvent(
new CustomEvent(c, { detail: [m, v.getAttribute(m)] }) new CustomEvent(c, { detail: [b, _.getAttribute(b)] })
); );
}); });
return A(t.signal, () => i.disconnect()) && i.observe(r, { attributes: !0 }), r; return A(e.signal, () => s.disconnect()) && s.observe(r, { attributes: !0 }), r;
}; };
}; };
function K() { function Y() {
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(u) { let t = /* @__PURE__ */ new Map(), e = !1, n = new MutationObserver(function(i) {
for (let f of u) for (let u of i)
if (f.type === "childList") { if (u.type === "childList") {
if (m(f.addedNodes, !0)) { if (b(u.addedNodes, !0)) {
i(); s();
continue; continue;
} }
v(f.removedNodes, !0) && i(); _(u.removedNodes, !0) && s();
} }
}); });
return { return {
onConnected(u, f) { onConnected(i, u) {
c(); c();
let a = r(u); let f = r(i);
a.connected.has(f) || (a.connected.add(f), a.length_c += 1); f.connected.has(u) || (f.connected.add(u), f.length_c += 1);
}, },
offConnected(u, f) { offConnected(i, u) {
if (!e.has(u)) if (!t.has(i))
return; return;
let a = e.get(u); let f = t.get(i);
a.connected.has(f) && (a.connected.delete(f), a.length_c -= 1, o(u, a)); f.connected.has(u) && (f.connected.delete(u), f.length_c -= 1, o(i, f));
}, },
onDisconnected(u, f) { onDisconnected(i, u) {
c(); c();
let a = r(u); let f = r(i);
a.disconnected.has(f) || (a.disconnected.add(f), a.length_d += 1); f.disconnected.has(u) || (f.disconnected.add(u), f.length_d += 1);
}, },
offDisconnected(u, f) { offDisconnected(i, u) {
if (!e.has(u)) if (!t.has(i))
return; return;
let a = e.get(u); let f = t.get(i);
a.disconnected.has(f) && (a.disconnected.delete(f), a.length_d -= 1, o(u, a)); f.disconnected.has(u) && (f.disconnected.delete(u), f.length_d -= 1, o(i, f));
} }
}; };
function o(u, f) { function o(i, u) {
f.length_c || f.length_d || (e.delete(u), i()); u.length_c || u.length_d || (t.delete(i), s());
} }
function r(u) { function r(i) {
if (e.has(u)) if (t.has(i))
return e.get(u); return t.get(i);
let f = { let u = {
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(u, f), f; return t.set(i, u), u;
} }
function c() { function c() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 })); e || (e = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
}
function i() {
!t || e.size || (t = !1, n.disconnect());
} }
function s() { function s() {
return new Promise(function(u) { !e || t.size || (e = !1, n.disconnect());
(requestIdleCallback || requestAnimationFrame)(u); }
function a() {
return new Promise(function(i) {
(requestIdleCallback || requestAnimationFrame)(i);
}); });
} }
async function d(u) { async function p(i) {
e.size > 30 && await s(); t.size > 30 && await a();
let f = []; let u = [];
if (!(u instanceof Node)) if (!(i instanceof Node))
return f; return u;
for (let a of e.keys()) for (let f of t.keys())
a === u || !(a instanceof Node) || u.contains(a) && f.push(a); f === i || !(f instanceof Node) || i.contains(f) && u.push(f);
return u;
}
function b(i, u) {
let f = !1;
for (let h of i) {
if (u && p(h).then(b), !t.has(h))
continue;
let w = t.get(h);
w.length_c && (h.dispatchEvent(new Event("dde:connected")), w.connected = /* @__PURE__ */ new WeakSet(), w.length_c = 0, w.length_d || t.delete(h), f = !0);
}
return f; return f;
} }
function m(u, f) { function _(i, u) {
let a = !1; let f = !1;
for (let h of u) { for (let h of i)
if (f && d(h).then(m), !e.has(h)) u && p(h).then(_), !(!t.has(h) || !t.get(h).length_d) && (h.dispatchEvent(new Event("dde:disconnected")), t.delete(h), f = !0);
continue; return f;
let w = e.get(h);
w.length_c && (h.dispatchEvent(new Event("dde:connected")), w.connected = /* @__PURE__ */ new WeakSet(), w.length_c = 0, w.length_d || e.delete(h), a = !0);
}
return a;
}
function v(u, f) {
let a = !1;
for (let h of u)
f && d(h).then(v), !(!e.has(h) || !e.get(h).length_d) && (h.dispatchEvent(new Event("dde:disconnected")), e.delete(h), a = !0);
return a;
} }
} }
// index.js // index.js
[HTMLElement, SVGElement, DocumentFragment].forEach((e) => { [HTMLElement, SVGElement, DocumentFragment].forEach((t) => {
let { append: t } = e.prototype; let { append: e } = t.prototype;
e.prototype.append = function(...n) { t.prototype.append = function(...n) {
return t.apply(this, n), this; return e.apply(this, n), this;
}; };
}); });
// src/signals-lib.js // src/signals-lib.js
var l = Symbol.for("Signal"); var d = Symbol.for("Signal");
function C(e) { function L(t) {
try { try {
return Reflect.has(e, l); return Reflect.has(t, d);
} catch { } catch {
return !1; return !1;
} }
} }
var L = [], g = /* @__PURE__ */ new WeakMap(); var D = [], g = /* @__PURE__ */ new WeakMap();
function p(e, t) { function l(t, e) {
if (typeof e != "function") if (typeof t != "function")
return k(e, t); return I(t, e);
if (C(e)) if (L(t))
return e; return t;
let n = k(), o = function() { let n = I(), o = function() {
L.push(o), n(e()), L.pop(); D.push(o), n(t()), D.pop();
}; };
return g.set(o, /* @__PURE__ */ new Set([n])), g.set(n[l], o), o(), n; return g.set(o, /* @__PURE__ */ new Set([n])), g.set(n[d], o), o(), n;
} }
p.action = function(e, t, ...n) { l.action = function(t, e, ...n) {
let o = e[l], { actions: r } = o; let o = t[d], { actions: r } = o;
if (!r || !Reflect.has(r, t)) if (!r || !Reflect.has(r, e))
throw new Error(`'${e}' has no action with name '${t}'!`); throw new Error(`'${t}' has no action with name '${e}'!`);
if (r[t].apply(o, n), o.skip) if (r[e].apply(o, n), o.skip)
return Reflect.deleteProperty(o, "skip"); return Reflect.deleteProperty(o, "skip");
o.listeners.forEach((c) => c(o.value)); o.listeners.forEach((c) => c(o.value));
}; };
p.on = function e(t, n, o = {}) { l.on = function t(e, n, o = {}) {
let { signal: r } = o; let { signal: r } = o;
if (!(r && r.aborted)) { if (!(r && r.aborted)) {
if (Array.isArray(t)) if (Array.isArray(e))
return t.forEach((c) => e(c, n, o)); return e.forEach((c) => t(c, n, o));
j(t, n), r && r.addEventListener("abort", () => N(t, n)); T(e, n), r && r.addEventListener("abort", () => N(e, n));
} }
}; };
p.symbols = { l.symbols = {
signal: l, signal: d,
onclear: Symbol.for("Signal.onclear") onclear: Symbol.for("Signal.onclear")
}; };
p.attribute = function(e, t = void 0) { l.attribute = function(t, e = void 0) {
let { host: n } = b, o = n() && n().hasAttribute(e) ? n().getAttribute(e) : t, r = new AbortController(), c = p(o, { let { host: n } = m, o = n() && n().hasAttribute(t) ? n().getAttribute(t) : e, r = new AbortController(), c = l(o, {
[p.symbols.onclear]() { [l.symbols.onclear]() {
r.abort(); r.abort();
} }
}); });
return b.host(_.attributeChanged(function({ detail: s }) { return m.host(v.attributeChanged(function({ detail: a }) {
let [d, m] = s; let [p, b] = a;
d === e && c(m); p === t && c(b);
}, { signal: r.signal })), c; }, { signal: r.signal })), c;
}; };
p.clear = function(...e) { l.clear = function(...t) {
for (let n of e) { for (let n of t) {
Reflect.deleteProperty(n, "toJSON"); Reflect.deleteProperty(n, "toJSON");
let o = n[l]; let o = n[d];
o.onclear.forEach((r) => r.call(o)), t(n, o), Reflect.deleteProperty(n, l); o.onclear.forEach((r) => r.call(o)), e(n, o), Reflect.deleteProperty(n, d);
} }
function t(n, o) { function e(n, o) {
o.listeners.forEach((r) => { o.listeners.forEach((r) => {
if (o.listeners.delete(r), !g.has(r)) if (o.listeners.delete(r), !g.has(r))
return; return;
let c = g.get(r); let c = g.get(r);
c.delete(n), !(c.size > 1) && (p.clear(...c), g.delete(r)); c.delete(n), !(c.size > 1) && (l.clear(...c), g.delete(r));
}); });
} }
}; };
p.el = function(e, t) { l.el = function(t, e) {
let n = document.createComment("<#reactive>"), o = document.createComment("</#reactive>"), r = document.createDocumentFragment(); let n = document.createComment("<#reactive>"), o = document.createComment("</#reactive>"), r = document.createDocumentFragment();
r.append(n, o); r.append(n, o);
let c = (i) => { let c = (s) => {
if (!n.parentNode || !o.parentNode) if (!n.parentNode || !o.parentNode)
return N(e, c); return N(t, c);
let s = t(i); let a = e(s);
Array.isArray(s) || (s = [s]); Array.isArray(a) || (a = [a]);
let d = n; let p = n;
for (; (d = n.nextSibling) !== o; ) for (; (p = n.nextSibling) !== o; )
d.remove(); p.remove();
n.after(...s); n.after(...a);
}; };
return j(e, c), G(e, c, n, t), c(e()), r; return T(t, c), V(t, c, n, e), c(t()), r;
}; };
var B = { var J = {
isSignal: C, isSignal: L,
processReactiveAttribute(e, t, n, o) { processReactiveAttribute(t, e, n, o) {
if (!C(n)) if (!L(n))
return n; return n;
let r = (c) => o([t, c]); let r = (c) => o(e, c);
return j(n, r), G(n, r, e, t), n(); return T(n, r), V(n, r, t, e), n();
} }
}; };
function G(e, t, ...n) { function V(t, e, ...n) {
let { current: o } = b; let { current: o } = m;
if (o.prevent) if (o.prevent)
return; return;
let r = "__dde_reactive"; let r = "__dde_reactive";
o.host(function(c) { o.host(function(c) {
c[r] || (c[r] = [], _.disconnected( c[r] || (c[r] = [], v.disconnected(
() => ( () => (
/*! /*!
* Clears all signals listeners added in the current scope/host (`S.el`, `assign`, ?). * Clears all signals listeners added in the current scope/host (`S.el`, `assign`, ?).
* You can investigate the `__dde_reactive` key of the element. * You can investigate the `__dde_reactive` key of the element.
* */ * */
c[r].forEach(([i]) => N(...i, e[l]?.host() === c)) c[r].forEach(([s]) => N(...s, t[d]?.host() === c))
) )
)(c)), c[r].push([[e, t], ...n]); )(c)), c[r].push([[t, e], ...n]);
}); });
} }
function k(e, t) { function I(t, e) {
let n = (...o) => o.length ? te(n, ...o) : ee(n); let n = (...o) => o.length ? ot(n, ...o) : rt(n);
return X(n, e, t); return et(n, t, e);
} }
var Q = Object.assign(/* @__PURE__ */ Object.create(null), { var tt = Object.assign(/* @__PURE__ */ Object.create(null), {
stopPropagation() { stopPropagation() {
this.skip = !0; this.skip = !0;
} }
}); });
function X(e, t, n) { function et(t, e, n) {
let o = []; let o = [];
T(n) !== "[object Object]" && (n = {}); M(n) !== "[object Object]" && (n = {});
let { onclear: r } = p.symbols; let { onclear: r } = l.symbols;
n[r] && (o.push(n[r]), Reflect.deleteProperty(n, r)); n[r] && (o.push(n[r]), Reflect.deleteProperty(n, r));
let { host: c } = b; let { host: c } = m;
return e[l] = { return t[d] = {
value: t, value: e,
actions: n, actions: n,
onclear: o, onclear: o,
host: c, host: c,
listeners: /* @__PURE__ */ new Set() listeners: /* @__PURE__ */ new Set()
}, e.toJSON = () => e(), Object.setPrototypeOf(e[l], Q), e; }, t.toJSON = () => t(), Object.setPrototypeOf(t[d], tt), t;
} }
function Y() { function nt() {
return L[L.length - 1]; return D[D.length - 1];
} }
function ee(e) { function rt(t) {
if (!e[l]) if (!t[d])
return; return;
let { value: t, listeners: n } = e[l], o = Y(); let { value: e, listeners: n } = t[d], o = nt();
return o && n.add(o), g.has(o) && g.get(o).add(e), t; return o && n.add(o), g.has(o) && g.get(o).add(t), e;
} }
function te(e, t, n) { function ot(t, e, n) {
if (!e[l]) if (!t[d])
return; return;
let o = e[l]; let o = t[d];
if (!(!n && o.value === t)) if (!(!n && o.value === e))
return o.value = t, o.listeners.forEach((r) => r(t)), t; return o.value = e, o.listeners.forEach((r) => r(e)), e;
} }
function j(e, t) { function T(t, e) {
if (e[l]) if (t[d])
return e[l].listeners.add(t); return t[d].listeners.add(e);
} }
function N(e, t, n) { function N(t, e, n) {
let o = e[l]; let o = t[d];
if (!o) if (!o)
return; return;
let r = o.listeners.delete(t); let r = o.listeners.delete(e);
if (n && !o.listeners.size) { if (n && !o.listeners.size) {
if (p.clear(e), !g.has(o)) if (l.clear(t), !g.has(o))
return r; return r;
let c = g.get(o); let c = g.get(o);
if (!g.has(c)) if (!g.has(c))
return r; return r;
g.get(c).forEach((i) => N(i, c, !0)); g.get(c).forEach((s) => N(s, c, !0));
} }
return r; return r;
} }
// signals.js // signals.js
D(B); P(J);
globalThis.dde= { globalThis.dde= {
S: p, S: l,
assign: O, assign: R,
classListDeclarative: J, assignAttribute: H,
createElement: ie, classListDeclarative: K,
dispatchEvent: le, createElement: at,
el: ie, dispatchEvent: gt,
empty: fe, el: at,
isSignal: C, empty: pt,
on: _, isSignal: L,
registerReactivity: D, on: v,
scope: b registerReactivity: P,
scope: m
}; };
})(); })();

399
dist/dde.js vendored
View File

@ -1,42 +1,42 @@
//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 m = { var v = {
isSignal(e) { isSignal(t) {
return !1; return !1;
}, },
processReactiveAttribute(e, t, n, u) { processReactiveAttribute(t, e, n, c) {
return n; return n;
} }
}; };
function T(e, t = !0) { function F(t, e = !0) {
return t ? Object.assign(m, e) : (Object.setPrototypeOf(e, m), e); return e ? Object.assign(v, t) : (Object.setPrototypeOf(t, v), t);
} }
function b(e) { function m(t) {
return m.isPrototypeOf(e) && e !== m ? e : m; return v.isPrototypeOf(t) && t !== v ? t : v;
} }
// src/helpers.js // src/helpers.js
function g(e) { function h(t) {
return typeof e > "u"; return typeof t > "u";
} }
function _(e, t) { function _(t, e) {
if (!e || !(e instanceof AbortSignal)) if (!t || !(t instanceof AbortSignal))
return !0; return !0;
if (!e.aborted) if (!t.aborted)
return e.addEventListener("abort", t), function() { return t.addEventListener("abort", e), function() {
e.removeEventListener("abort", t); t.removeEventListener("abort", e);
}; };
} }
// src/dom-common.js // src/dom-common.js
var C = { setDeleteAttr: M }; var R = { setDeleteAttr: H };
function M(e, t, n) { function H(t, e, n) {
if (Reflect.set(e, t, n), !!g(n)) { if (Reflect.set(t, e, n), !!h(n)) {
if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined") if (Reflect.deleteProperty(t, e), t instanceof HTMLElement && t.getAttribute(e) === "undefined")
return e.removeAttribute(t); return t.removeAttribute(e);
if (Reflect.get(e, t) === "undefined") if (Reflect.get(t, e) === "undefined")
return Reflect.set(e, t, ""); return Reflect.set(t, e, "");
} }
} }
@ -44,9 +44,9 @@
var E = [{ var E = [{
scope: document.body, scope: document.body,
namespace: "html", namespace: "html",
host: (e) => e ? e(document.body) : document.body, host: (t) => t ? t(document.body) : document.body,
prevent: !0 prevent: !0
}], R = (e) => e === "svg" ? "http://www.w3.org/2000/svg" : e, x = { }], S = (t) => t === "svg" ? "http://www.w3.org/2000/svg" : t, x = {
get current() { get current() {
return E[E.length - 1]; return E[E.length - 1];
}, },
@ -56,272 +56,287 @@
get namespace() { get namespace() {
return this.current.namespace; return this.current.namespace;
}, },
set namespace(e) { set namespace(t) {
return this.current.namespace = R(e); return this.current.namespace = S(t);
}, },
preventDefault() { preventDefault() {
let { current: e } = this; let { current: t } = this;
return e.prevent = !0, e; return t.prevent = !0, t;
}, },
elNamespace(e) { elNamespace(t) {
let t = this.namespace; let e = this.namespace;
return this.namespace = e, { return this.namespace = t, {
append(...n) { append(...n) {
return x.namespace = t, n.length === 1 ? n[0] : document.createDocumentFragment().append(...n); return x.namespace = e, n.length === 1 ? n[0] : document.createDocumentFragment().append(...n);
} }
}; };
}, },
get state() { get state() {
return [...E]; return [...E];
}, },
push(e = {}) { push(t = {}) {
return e.namespace && (e.namespace = R(e.namespace)), E.push(Object.assign({}, this.current, { prevent: !1 }, e)); return t.namespace && (t.namespace = S(t.namespace)), E.push(Object.assign({}, this.current, { prevent: !1 }, t));
}, },
pop() { pop() {
return E.pop(); return E.pop();
} }
}; };
function V(e, t, ...n) { function J(t, e, ...n) {
let u = b(this), { namespace: r } = x, f = 0, a; let c = m(this), { namespace: r } = x, f = 0, u;
switch ((Object(t) !== t || u.isSignal(t)) && (t = { textContent: t }), !0) { switch ((Object(e) !== e || c.isSignal(e)) && (e = { textContent: e }), !0) {
case typeof e == "function": { case typeof t == "function": {
f = 1, x.push({ scope: e, host: (i) => i ? (f === 1 ? n.unshift(i) : i(a), void 0) : a }), a = e(t || void 0), (a instanceof HTMLElement ? P : j)(a, "Attribute", "dde-fun", e.name); f = 1, x.push({ scope: t, host: (a) => a ? (f === 1 ? n.unshift(a) : a(u), void 0) : u }), u = t(e || void 0), (u instanceof HTMLElement ? M : W)(u, "Attribute", "dde-fun", t.name);
break; break;
} }
case e === "#text": case t === "#text":
a = w.call(this, document.createTextNode(""), t); u = w.call(this, document.createTextNode(""), e);
break; break;
case e === "<>": case t === "<>":
a = w.call(this, document.createDocumentFragment(), t); u = w.call(this, document.createDocumentFragment(), e);
break; break;
case r !== "html": case r !== "html":
a = w.call(this, document.createElementNS(r, e), t); u = w.call(this, document.createElementNS(r, t), e);
break; break;
case !a: case !u:
a = w.call(this, document.createElement(e), t); u = w.call(this, document.createElement(t), e);
} }
return n.forEach((i) => i(a)), f && x.pop(), f = 2, a; return n.forEach((a) => a(u)), f && x.pop(), f = 2, u;
} }
var { setDeleteAttr: S } = C; var { setDeleteAttr: L } = R, A = /* @__PURE__ */ new WeakMap();
function w(e, ...t) { function w(t, ...e) {
let n = this, u = b(this); if (!e.length)
if (!t.length) return t;
return e; A.set(t, P(t, this));
let f = (e instanceof SVGElement ? j : P).bind(null, e, "Attribute"); for (let [n, c] of Object.entries(Object.assign({}, ...e)))
return Object.entries(Object.assign({}, ...t)).forEach(function a([i, d]) { N.call(this, t, n, c);
d = u.processReactiveAttribute(e, i, d, a); return A.delete(t), t;
let [l] = i;
if (l === "=")
return f(i.slice(1), d);
if (l === ".")
return L(e, i.slice(1), d);
if (/(aria|data)([A-Z])/.test(i))
return i = i.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), f(i, d);
switch (i === "className" && (i = "class"), i) {
case "xlink:href":
return f(i, d, "http://www.w3.org/1999/xlink");
case "textContent":
return S(e, i, d);
case "style":
if (typeof d != "object")
break;
case "dataset":
return O(u, d, L.bind(null, e[i]));
case "ariaset":
return O(u, d, (h, c) => f("aria-" + h, c));
case "classList":
return W.call(n, e, d);
}
return F(e, i) ? S(e, i, d) : f(i, d);
}), e;
} }
function W(e, t) { function N(t, e, n) {
let n = b(this); let { setRemoveAttr: c, s: r } = P(t, this), f = this;
return O( n = r.processReactiveAttribute(
n,
t, t,
(u, r) => e.classList.toggle(u, r === -1 ? void 0 : !!r) e,
), e; n,
(a, p) => N.call(f, t, a, p)
);
let [u] = e;
if (u === "=")
return c(e.slice(1), n);
if (u === ".")
return D(t, e.slice(1), n);
if (/(aria|data)([A-Z])/.test(e))
return e = e.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), c(e, n);
switch (e === "className" && (e = "class"), e) {
case "xlink:href":
return c(e, n, "http://www.w3.org/1999/xlink");
case "textContent":
return L(t, e, n);
case "style":
if (typeof n != "object")
break;
case "dataset":
return y(r, n, D.bind(null, t[e]));
case "ariaset":
return y(r, n, (a, p) => c("aria-" + a, p));
case "classList":
return U.call(f, t, n);
}
return q(t, e) ? L(t, e, n) : c(e, n);
} }
function $(e) { function P(t, e) {
return Array.from(e.children).forEach((t) => t.remove()), e; if (A.has(t))
return A.get(t);
let c = (t instanceof SVGElement ? W : M).bind(null, t, "Attribute"), r = m(e);
return { setRemoveAttr: c, s: r };
} }
function F(e, t) { function U(t, e) {
if (!Reflect.has(e, t)) let n = m(this);
return y(
n,
e,
(c, r) => t.classList.toggle(c, r === -1 ? void 0 : !!r)
), t;
}
function Q(t) {
return Array.from(t.children).forEach((e) => e.remove()), t;
}
function q(t, e) {
if (!Reflect.has(t, e))
return !1; return !1;
let n = D(e, t); let n = j(t, e);
return !g(n.set); return !h(n.set);
} }
function D(e, t) { function j(t, e) {
if (e = Object.getPrototypeOf(e), !e) if (t = Object.getPrototypeOf(t), !t)
return {}; return {};
let n = Object.getOwnPropertyDescriptor(e, t); let n = Object.getOwnPropertyDescriptor(t, e);
return n || D(e, t); return n || j(t, e);
} }
function O(e, t, n) { function y(t, e, n) {
if (!(typeof t != "object" || t === null)) if (!(typeof e != "object" || e === null))
return Object.entries(t).forEach(function([r, f]) { return Object.entries(e).forEach(function([r, f]) {
r && (f = e.processReactiveAttribute(t, r, f, (a) => n(...a)), n(r, f)); r && (f = t.processReactiveAttribute(e, r, f, n), n(r, f));
}); });
} }
function N(e) { function T(t) {
return Array.isArray(e) ? e.filter(Boolean).join(" ") : e; return Array.isArray(t) ? t.filter(Boolean).join(" ") : t;
} }
function P(e, t, n, u) { function M(t, e, n, c) {
return e[(g(u) ? "remove" : "set") + t](n, N(u)); return t[(h(c) ? "remove" : "set") + e](n, T(c));
} }
function j(e, t, n, u, r = null) { function W(t, e, n, c, r = null) {
return e[(g(u) ? "remove" : "set") + t + "NS"](r, n, N(u)); return t[(h(c) ? "remove" : "set") + e + "NS"](r, n, T(c));
} }
function L(e, t, n) { function D(t, e, n) {
if (Reflect.set(e, t, n), !!g(n)) if (Reflect.set(t, e, n), !!h(n))
return Reflect.deleteProperty(e, t); return Reflect.deleteProperty(t, e);
} }
// src/events.js // src/events.js
function Q(e, t, ...n) { function k(t, e, ...n) {
let u = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); let c = n.length ? new CustomEvent(e, { detail: n[0] }) : new Event(e);
return e.dispatchEvent(u); return t.dispatchEvent(c);
} }
function y(e, t, n) { function C(t, e, n) {
return function(r) { return function(r) {
return r.addEventListener(e, t, n), r; return r.addEventListener(t, e, n), r;
}; };
} }
var A = U(), H = /* @__PURE__ */ new WeakSet(); var O = B(), z = /* @__PURE__ */ new WeakSet();
y.connected = function(e, t) { C.connected = function(t, e) {
let n = "connected"; let n = "connected";
return typeof t != "object" && (t = {}), t.once = !0, function(r) { return typeof e != "object" && (e = {}), e.once = !0, function(r) {
let f = "dde:" + n; let f = "dde:" + n;
return r.addEventListener(f, e, t), r.__dde_lifecycleToEvents ? r : r.isConnected ? (r.dispatchEvent(new Event(f)), r) : (_(t.signal, () => A.offConnected(r, e)) && A.onConnected(r, e), r); return r.addEventListener(f, t, e), r.__dde_lifecycleToEvents ? r : r.isConnected ? (r.dispatchEvent(new Event(f)), r) : (_(e.signal, () => O.offConnected(r, t)) && O.onConnected(r, t), r);
}; };
}; };
y.disconnected = function(e, t) { C.disconnected = function(t, e) {
let n = "disconnected"; let n = "disconnected";
return typeof t != "object" && (t = {}), t.once = !0, function(r) { return typeof e != "object" && (e = {}), e.once = !0, function(r) {
let f = "dde:" + n; let f = "dde:" + n;
return r.addEventListener(f, e, t), r.__dde_lifecycleToEvents || _(t.signal, () => A.offDisconnected(r, e)) && A.onDisconnected(r, e), r; return r.addEventListener(f, t, e), r.__dde_lifecycleToEvents || _(e.signal, () => O.offDisconnected(r, t)) && O.onDisconnected(r, t), r;
}; };
}; };
y.attributeChanged = function(e, t) { C.attributeChanged = function(t, e) {
let n = "attributeChanged"; let n = "attributeChanged";
return typeof t != "object" && (t = {}), function(r) { return typeof e != "object" && (e = {}), function(r) {
let f = "dde:" + n; let f = "dde:" + n;
if (r.addEventListener(f, e, t), r.__dde_lifecycleToEvents || H.has(r)) if (r.addEventListener(f, t, e), r.__dde_lifecycleToEvents || z.has(r))
return r; return r;
let a = new MutationObserver(function(d) { let u = new MutationObserver(function(p) {
for (let { attributeName: l, target: h } of d) for (let { attributeName: l, target: g } of p)
h.dispatchEvent( g.dispatchEvent(
new CustomEvent(f, { detail: [l, h.getAttribute(l)] }) new CustomEvent(f, { detail: [l, g.getAttribute(l)] })
); );
}); });
return _(t.signal, () => a.disconnect()) && a.observe(r, { attributes: !0 }), r; return _(e.signal, () => u.disconnect()) && u.observe(r, { attributes: !0 }), r;
}; };
}; };
function U() { function B() {
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) { let t = /* @__PURE__ */ new Map(), e = !1, n = new MutationObserver(function(o) {
for (let o of c) for (let s of o)
if (o.type === "childList") { if (s.type === "childList") {
if (l(o.addedNodes, !0)) { if (l(s.addedNodes, !0)) {
a(); u();
continue; continue;
} }
h(o.removedNodes, !0) && a(); g(s.removedNodes, !0) && u();
} }
}); });
return { return {
onConnected(c, o) { onConnected(o, s) {
f(); f();
let s = r(c); let i = r(o);
s.connected.has(o) || (s.connected.add(o), s.length_c += 1); i.connected.has(s) || (i.connected.add(s), i.length_c += 1);
}, },
offConnected(c, o) { offConnected(o, s) {
if (!e.has(c)) if (!t.has(o))
return; return;
let s = e.get(c); let i = t.get(o);
s.connected.has(o) && (s.connected.delete(o), s.length_c -= 1, u(c, s)); i.connected.has(s) && (i.connected.delete(s), i.length_c -= 1, c(o, i));
}, },
onDisconnected(c, o) { onDisconnected(o, s) {
f(); f();
let s = r(c); let i = r(o);
s.disconnected.has(o) || (s.disconnected.add(o), s.length_d += 1); i.disconnected.has(s) || (i.disconnected.add(s), i.length_d += 1);
}, },
offDisconnected(c, o) { offDisconnected(o, s) {
if (!e.has(c)) if (!t.has(o))
return; return;
let s = e.get(c); let i = t.get(o);
s.disconnected.has(o) && (s.disconnected.delete(o), s.length_d -= 1, u(c, s)); i.disconnected.has(s) && (i.disconnected.delete(s), i.length_d -= 1, c(o, i));
} }
}; };
function u(c, o) { function c(o, s) {
o.length_c || o.length_d || (e.delete(c), a()); s.length_c || s.length_d || (t.delete(o), u());
} }
function r(c) { function r(o) {
if (e.has(c)) if (t.has(o))
return e.get(c); return t.get(o);
let o = { let s = {
connected: /* @__PURE__ */ new WeakSet(), connected: /* @__PURE__ */ new WeakSet(),
length_c: 0, length_c: 0,
disconnected: /* @__PURE__ */ new WeakSet(), disconnected: /* @__PURE__ */ new WeakSet(),
length_d: 0 length_d: 0
}; };
return e.set(c, o), o; return t.set(o, s), s;
} }
function f() { function f() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 })); e || (e = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
}
function u() {
!e || t.size || (e = !1, n.disconnect());
} }
function a() { function a() {
!t || e.size || (t = !1, n.disconnect()); return new Promise(function(o) {
} (requestIdleCallback || requestAnimationFrame)(o);
function i() {
return new Promise(function(c) {
(requestIdleCallback || requestAnimationFrame)(c);
}); });
} }
async function d(c) { async function p(o) {
e.size > 30 && await i(); t.size > 30 && await a();
let o = []; let s = [];
if (!(c instanceof Node)) if (!(o instanceof Node))
return o; return s;
for (let s of e.keys()) for (let i of t.keys())
s === c || !(s instanceof Node) || c.contains(s) && o.push(s); i === o || !(i instanceof Node) || o.contains(i) && s.push(i);
return o; return s;
} }
function l(c, o) { function l(o, s) {
let s = !1; let i = !1;
for (let p of c) { for (let d of o) {
if (o && d(p).then(l), !e.has(p)) if (s && p(d).then(l), !t.has(d))
continue; continue;
let v = e.get(p); let b = t.get(d);
v.length_c && (p.dispatchEvent(new Event("dde:connected")), v.connected = /* @__PURE__ */ new WeakSet(), v.length_c = 0, v.length_d || e.delete(p), s = !0); b.length_c && (d.dispatchEvent(new Event("dde:connected")), b.connected = /* @__PURE__ */ new WeakSet(), b.length_c = 0, b.length_d || t.delete(d), i = !0);
} }
return s; return i;
} }
function h(c, o) { function g(o, s) {
let s = !1; let i = !1;
for (let p of c) for (let d of o)
o && d(p).then(h), !(!e.has(p) || !e.get(p).length_d) && (p.dispatchEvent(new Event("dde:disconnected")), e.delete(p), s = !0); s && p(d).then(g), !(!t.has(d) || !t.get(d).length_d) && (d.dispatchEvent(new Event("dde:disconnected")), t.delete(d), i = !0);
return s; return i;
} }
} }
// index.js // index.js
[HTMLElement, SVGElement, DocumentFragment].forEach((e) => { [HTMLElement, SVGElement, DocumentFragment].forEach((t) => {
let { append: t } = e.prototype; let { append: e } = t.prototype;
e.prototype.append = function(...n) { t.prototype.append = function(...n) {
return t.apply(this, n), this; return e.apply(this, n), this;
}; };
}); });
globalThis.dde= { globalThis.dde= {
assign: w, assign: w,
classListDeclarative: W, assignAttribute: N,
createElement: V, classListDeclarative: U,
dispatchEvent: Q, createElement: J,
el: V, dispatchEvent: k,
empty: $, el: J,
on: y, empty: Q,
registerReactivity: T, on: C,
registerReactivity: F,
scope: x scope: x
}; };

View File

@ -1,56 +1,56 @@
// src/signals-common.js // src/signals-common.js
var x = { var x = {
isSignal(e) { isSignal(t) {
return !1; return !1;
}, },
processReactiveAttribute(e, t, n, o) { processReactiveAttribute(t, e, n, o) {
return n; return n;
} }
}; };
function D(e, t = !0) { function P(t, e = !0) {
return t ? Object.assign(x, e) : (Object.setPrototypeOf(e, x), e); return e ? Object.assign(x, t) : (Object.setPrototypeOf(t, x), t);
} }
function y(e) { function S(t) {
return x.isPrototypeOf(e) && e !== x ? e : x; return x.isPrototypeOf(t) && t !== x ? t : x;
} }
// src/helpers.js // src/helpers.js
function E(e) { function E(t) {
return typeof e > "u"; return typeof t > "u";
} }
function T(e) { function M(t) {
let t = typeof e; let e = typeof t;
return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e); return e !== "object" ? e : t === null ? "null" : Object.prototype.toString.call(t);
} }
function A(e, t) { function A(t, e) {
if (!e || !(e instanceof AbortSignal)) if (!t || !(t instanceof AbortSignal))
return !0; return !0;
if (!e.aborted) if (!t.aborted)
return e.addEventListener("abort", t), function() { return t.addEventListener("abort", e), function() {
e.removeEventListener("abort", t); t.removeEventListener("abort", e);
}; };
} }
// src/dom-common.js // src/dom-common.js
var M = { setDeleteAttr: I }; var W = { setDeleteAttr: Z };
function I(e, t, n) { function Z(t, e, n) {
if (Reflect.set(e, t, n), !!E(n)) { if (Reflect.set(t, e, n), !!E(n)) {
if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined") if (Reflect.deleteProperty(t, e), t instanceof HTMLElement && t.getAttribute(e) === "undefined")
return e.removeAttribute(t); return t.removeAttribute(e);
if (Reflect.get(e, t) === "undefined") if (Reflect.get(t, e) === "undefined")
return Reflect.set(e, t, ""); return Reflect.set(t, e, "");
} }
} }
// src/dom.js // src/dom.js
var S = [{ var y = [{
scope: document.body, scope: document.body,
namespace: "html", namespace: "html",
host: (e) => e ? e(document.body) : document.body, host: (t) => t ? t(document.body) : document.body,
prevent: !0 prevent: !0
}], W = (e) => e === "svg" ? "http://www.w3.org/2000/svg" : e, b = { }], F = (t) => t === "svg" ? "http://www.w3.org/2000/svg" : t, m = {
get current() { get current() {
return S[S.length - 1]; return y[y.length - 1];
}, },
get host() { get host() {
return this.current.host; return this.current.host;
@ -58,441 +58,456 @@ var S = [{
get namespace() { get namespace() {
return this.current.namespace; return this.current.namespace;
}, },
set namespace(e) { set namespace(t) {
return this.current.namespace = W(e); return this.current.namespace = F(t);
}, },
preventDefault() { preventDefault() {
let { current: e } = this; let { current: t } = this;
return e.prevent = !0, e; return t.prevent = !0, t;
}, },
elNamespace(e) { elNamespace(t) {
let t = this.namespace; let e = this.namespace;
return this.namespace = e, { return this.namespace = t, {
append(...n) { append(...n) {
return b.namespace = t, n.length === 1 ? n[0] : document.createDocumentFragment().append(...n); return m.namespace = e, n.length === 1 ? n[0] : document.createDocumentFragment().append(...n);
} }
}; };
}, },
get state() { get state() {
return [...S]; return [...y];
}, },
push(e = {}) { push(t = {}) {
return e.namespace && (e.namespace = W(e.namespace)), S.push(Object.assign({}, this.current, { prevent: !1 }, e)); return t.namespace && (t.namespace = F(t.namespace)), y.push(Object.assign({}, this.current, { prevent: !1 }, t));
}, },
pop() { pop() {
return S.pop(); return y.pop();
} }
}; };
function ie(e, t, ...n) { function at(t, e, ...n) {
let o = y(this), { namespace: r } = b, c = 0, i; let o = S(this), { namespace: r } = m, c = 0, s;
switch ((Object(t) !== t || o.isSignal(t)) && (t = { textContent: t }), !0) { switch ((Object(e) !== e || o.isSignal(e)) && (e = { textContent: e }), !0) {
case typeof e == "function": { case typeof t == "function": {
c = 1, b.push({ scope: e, host: (s) => s ? (c === 1 ? n.unshift(s) : s(i), void 0) : i }), i = e(t || void 0), (i instanceof HTMLElement ? $ : q)(i, "Attribute", "dde-fun", e.name); c = 1, m.push({ scope: t, host: (a) => a ? (c === 1 ? n.unshift(a) : a(s), void 0) : s }), s = t(e || void 0), (s instanceof HTMLElement ? B : G)(s, "Attribute", "dde-fun", t.name);
break; break;
} }
case e === "#text": case t === "#text":
i = O.call(this, document.createTextNode(""), t); s = R.call(this, document.createTextNode(""), e);
break; break;
case e === "<>": case t === "<>":
i = O.call(this, document.createDocumentFragment(), t); s = R.call(this, document.createDocumentFragment(), e);
break; break;
case r !== "html": case r !== "html":
i = O.call(this, document.createElementNS(r, e), t); s = R.call(this, document.createElementNS(r, t), e);
break; break;
case !i: case !s:
i = O.call(this, document.createElement(e), t); s = R.call(this, document.createElement(t), e);
} }
return n.forEach((s) => s(i)), c && b.pop(), c = 2, i; return n.forEach((a) => a(s)), c && m.pop(), c = 2, s;
} }
var { setDeleteAttr: F } = M; var { setDeleteAttr: z } = W, O = /* @__PURE__ */ new WeakMap();
function O(e, ...t) { function R(t, ...e) {
let n = this, o = y(this); if (!e.length)
if (!t.length) return t;
return e; O.set(t, U(t, this));
let c = (e instanceof SVGElement ? q : $).bind(null, e, "Attribute"); for (let [n, o] of Object.entries(Object.assign({}, ...e)))
return Object.entries(Object.assign({}, ...t)).forEach(function i([s, d]) { H.call(this, t, n, o);
d = o.processReactiveAttribute(e, s, d, i); return O.delete(t), t;
let [m] = s;
if (m === "=")
return c(s.slice(1), d);
if (m === ".")
return z(e, s.slice(1), d);
if (/(aria|data)([A-Z])/.test(s))
return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), c(s, d);
switch (s === "className" && (s = "class"), s) {
case "xlink:href":
return c(s, d, "http://www.w3.org/1999/xlink");
case "textContent":
return F(e, s, d);
case "style":
if (typeof d != "object")
break;
case "dataset":
return P(o, d, z.bind(null, e[s]));
case "ariaset":
return P(o, d, (v, u) => c("aria-" + v, u));
case "classList":
return J.call(n, e, d);
}
return V(e, s) ? F(e, s, d) : c(s, d);
}), e;
} }
function J(e, t) { function H(t, e, n) {
let n = y(this); let { setRemoveAttr: o, s: r } = U(t, this), c = this;
return P( n = r.processReactiveAttribute(
n,
t, t,
(o, r) => e.classList.toggle(o, r === -1 ? void 0 : !!r) e,
), e; n,
(a, p) => H.call(c, t, a, p)
);
let [s] = e;
if (s === "=")
return o(e.slice(1), n);
if (s === ".")
return k(t, e.slice(1), n);
if (/(aria|data)([A-Z])/.test(e))
return e = e.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(e, n);
switch (e === "className" && (e = "class"), e) {
case "xlink:href":
return o(e, n, "http://www.w3.org/1999/xlink");
case "textContent":
return z(t, e, n);
case "style":
if (typeof n != "object")
break;
case "dataset":
return j(r, n, k.bind(null, t[e]));
case "ariaset":
return j(r, n, (a, p) => o("aria-" + a, p));
case "classList":
return K.call(c, t, n);
}
return Q(t, e) ? z(t, e, n) : o(e, n);
} }
function fe(e) { function U(t, e) {
return Array.from(e.children).forEach((t) => t.remove()), e; if (O.has(t))
return O.get(t);
let o = (t instanceof SVGElement ? G : B).bind(null, t, "Attribute"), r = S(e);
return { setRemoveAttr: o, s: r };
} }
function V(e, t) { function K(t, e) {
if (!Reflect.has(e, t)) let n = S(this);
return j(
n,
e,
(o, r) => t.classList.toggle(o, r === -1 ? void 0 : !!r)
), t;
}
function pt(t) {
return Array.from(t.children).forEach((e) => e.remove()), t;
}
function Q(t, e) {
if (!Reflect.has(t, e))
return !1; return !1;
let n = H(e, t); let n = $(t, e);
return !E(n.set); return !E(n.set);
} }
function H(e, t) { function $(t, e) {
if (e = Object.getPrototypeOf(e), !e) if (t = Object.getPrototypeOf(t), !t)
return {}; return {};
let n = Object.getOwnPropertyDescriptor(e, t); let n = Object.getOwnPropertyDescriptor(t, e);
return n || H(e, t); return n || $(t, e);
} }
function P(e, t, n) { function j(t, e, n) {
if (!(typeof t != "object" || t === null)) if (!(typeof e != "object" || e === null))
return Object.entries(t).forEach(function([r, c]) { return Object.entries(e).forEach(function([r, c]) {
r && (c = e.processReactiveAttribute(t, r, c, (i) => n(...i)), n(r, c)); r && (c = t.processReactiveAttribute(e, r, c, n), n(r, c));
}); });
} }
function U(e) { function q(t) {
return Array.isArray(e) ? e.filter(Boolean).join(" ") : e; return Array.isArray(t) ? t.filter(Boolean).join(" ") : t;
} }
function $(e, t, n, o) { function B(t, e, n, o) {
return e[(E(o) ? "remove" : "set") + t](n, U(o)); return t[(E(o) ? "remove" : "set") + e](n, q(o));
} }
function q(e, t, n, o, r = null) { function G(t, e, n, o, r = null) {
return e[(E(o) ? "remove" : "set") + t + "NS"](r, n, U(o)); return t[(E(o) ? "remove" : "set") + e + "NS"](r, n, q(o));
} }
function z(e, t, n) { function k(t, e, n) {
if (Reflect.set(e, t, n), !!E(n)) if (Reflect.set(t, e, n), !!E(n))
return Reflect.deleteProperty(e, t); return Reflect.deleteProperty(t, e);
} }
// src/events.js // src/events.js
function le(e, t, ...n) { function gt(t, e, ...n) {
let o = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); let o = n.length ? new CustomEvent(e, { detail: n[0] }) : new Event(e);
return e.dispatchEvent(o); return t.dispatchEvent(o);
} }
function _(e, t, n) { function v(t, e, n) {
return function(r) { return function(r) {
return r.addEventListener(e, t, n), r; return r.addEventListener(t, e, n), r;
}; };
} }
var R = K(), Z = /* @__PURE__ */ new WeakSet(); var C = Y(), X = /* @__PURE__ */ new WeakSet();
_.connected = function(e, t) { v.connected = function(t, e) {
let n = "connected"; let n = "connected";
return typeof t != "object" && (t = {}), t.once = !0, function(r) { return typeof e != "object" && (e = {}), e.once = !0, function(r) {
let c = "dde:" + n; let c = "dde:" + n;
return r.addEventListener(c, e, t), r.__dde_lifecycleToEvents ? r : r.isConnected ? (r.dispatchEvent(new Event(c)), r) : (A(t.signal, () => R.offConnected(r, e)) && R.onConnected(r, e), r); return r.addEventListener(c, t, e), r.__dde_lifecycleToEvents ? r : r.isConnected ? (r.dispatchEvent(new Event(c)), r) : (A(e.signal, () => C.offConnected(r, t)) && C.onConnected(r, t), r);
}; };
}; };
_.disconnected = function(e, t) { v.disconnected = function(t, e) {
let n = "disconnected"; let n = "disconnected";
return typeof t != "object" && (t = {}), t.once = !0, function(r) { return typeof e != "object" && (e = {}), e.once = !0, function(r) {
let c = "dde:" + n; let c = "dde:" + n;
return r.addEventListener(c, e, t), r.__dde_lifecycleToEvents || A(t.signal, () => R.offDisconnected(r, e)) && R.onDisconnected(r, e), r; return r.addEventListener(c, t, e), r.__dde_lifecycleToEvents || A(e.signal, () => C.offDisconnected(r, t)) && C.onDisconnected(r, t), r;
}; };
}; };
_.attributeChanged = function(e, t) { v.attributeChanged = function(t, e) {
let n = "attributeChanged"; let n = "attributeChanged";
return typeof t != "object" && (t = {}), function(r) { return typeof e != "object" && (e = {}), function(r) {
let c = "dde:" + n; let c = "dde:" + n;
if (r.addEventListener(c, e, t), r.__dde_lifecycleToEvents || Z.has(r)) if (r.addEventListener(c, t, e), r.__dde_lifecycleToEvents || X.has(r))
return r; return r;
let i = new MutationObserver(function(d) { let s = new MutationObserver(function(p) {
for (let { attributeName: m, target: v } of d) for (let { attributeName: b, target: _ } of p)
v.dispatchEvent( _.dispatchEvent(
new CustomEvent(c, { detail: [m, v.getAttribute(m)] }) new CustomEvent(c, { detail: [b, _.getAttribute(b)] })
); );
}); });
return A(t.signal, () => i.disconnect()) && i.observe(r, { attributes: !0 }), r; return A(e.signal, () => s.disconnect()) && s.observe(r, { attributes: !0 }), r;
}; };
}; };
function K() { function Y() {
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(u) { let t = /* @__PURE__ */ new Map(), e = !1, n = new MutationObserver(function(i) {
for (let f of u) for (let u of i)
if (f.type === "childList") { if (u.type === "childList") {
if (m(f.addedNodes, !0)) { if (b(u.addedNodes, !0)) {
i(); s();
continue; continue;
} }
v(f.removedNodes, !0) && i(); _(u.removedNodes, !0) && s();
} }
}); });
return { return {
onConnected(u, f) { onConnected(i, u) {
c(); c();
let a = r(u); let f = r(i);
a.connected.has(f) || (a.connected.add(f), a.length_c += 1); f.connected.has(u) || (f.connected.add(u), f.length_c += 1);
}, },
offConnected(u, f) { offConnected(i, u) {
if (!e.has(u)) if (!t.has(i))
return; return;
let a = e.get(u); let f = t.get(i);
a.connected.has(f) && (a.connected.delete(f), a.length_c -= 1, o(u, a)); f.connected.has(u) && (f.connected.delete(u), f.length_c -= 1, o(i, f));
}, },
onDisconnected(u, f) { onDisconnected(i, u) {
c(); c();
let a = r(u); let f = r(i);
a.disconnected.has(f) || (a.disconnected.add(f), a.length_d += 1); f.disconnected.has(u) || (f.disconnected.add(u), f.length_d += 1);
}, },
offDisconnected(u, f) { offDisconnected(i, u) {
if (!e.has(u)) if (!t.has(i))
return; return;
let a = e.get(u); let f = t.get(i);
a.disconnected.has(f) && (a.disconnected.delete(f), a.length_d -= 1, o(u, a)); f.disconnected.has(u) && (f.disconnected.delete(u), f.length_d -= 1, o(i, f));
} }
}; };
function o(u, f) { function o(i, u) {
f.length_c || f.length_d || (e.delete(u), i()); u.length_c || u.length_d || (t.delete(i), s());
} }
function r(u) { function r(i) {
if (e.has(u)) if (t.has(i))
return e.get(u); return t.get(i);
let f = { let u = {
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(u, f), f; return t.set(i, u), u;
} }
function c() { function c() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 })); e || (e = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
}
function i() {
!t || e.size || (t = !1, n.disconnect());
} }
function s() { function s() {
return new Promise(function(u) { !e || t.size || (e = !1, n.disconnect());
(requestIdleCallback || requestAnimationFrame)(u); }
function a() {
return new Promise(function(i) {
(requestIdleCallback || requestAnimationFrame)(i);
}); });
} }
async function d(u) { async function p(i) {
e.size > 30 && await s(); t.size > 30 && await a();
let f = []; let u = [];
if (!(u instanceof Node)) if (!(i instanceof Node))
return f; return u;
for (let a of e.keys()) for (let f of t.keys())
a === u || !(a instanceof Node) || u.contains(a) && f.push(a); f === i || !(f instanceof Node) || i.contains(f) && u.push(f);
return u;
}
function b(i, u) {
let f = !1;
for (let h of i) {
if (u && p(h).then(b), !t.has(h))
continue;
let w = t.get(h);
w.length_c && (h.dispatchEvent(new Event("dde:connected")), w.connected = /* @__PURE__ */ new WeakSet(), w.length_c = 0, w.length_d || t.delete(h), f = !0);
}
return f; return f;
} }
function m(u, f) { function _(i, u) {
let a = !1; let f = !1;
for (let h of u) { for (let h of i)
if (f && d(h).then(m), !e.has(h)) u && p(h).then(_), !(!t.has(h) || !t.get(h).length_d) && (h.dispatchEvent(new Event("dde:disconnected")), t.delete(h), f = !0);
continue; return f;
let w = e.get(h);
w.length_c && (h.dispatchEvent(new Event("dde:connected")), w.connected = /* @__PURE__ */ new WeakSet(), w.length_c = 0, w.length_d || e.delete(h), a = !0);
}
return a;
}
function v(u, f) {
let a = !1;
for (let h of u)
f && d(h).then(v), !(!e.has(h) || !e.get(h).length_d) && (h.dispatchEvent(new Event("dde:disconnected")), e.delete(h), a = !0);
return a;
} }
} }
// index.js // index.js
[HTMLElement, SVGElement, DocumentFragment].forEach((e) => { [HTMLElement, SVGElement, DocumentFragment].forEach((t) => {
let { append: t } = e.prototype; let { append: e } = t.prototype;
e.prototype.append = function(...n) { t.prototype.append = function(...n) {
return t.apply(this, n), this; return e.apply(this, n), this;
}; };
}); });
// src/signals-lib.js // src/signals-lib.js
var l = Symbol.for("Signal"); var d = Symbol.for("Signal");
function C(e) { function L(t) {
try { try {
return Reflect.has(e, l); return Reflect.has(t, d);
} catch { } catch {
return !1; return !1;
} }
} }
var L = [], g = /* @__PURE__ */ new WeakMap(); var D = [], g = /* @__PURE__ */ new WeakMap();
function p(e, t) { function l(t, e) {
if (typeof e != "function") if (typeof t != "function")
return k(e, t); return I(t, e);
if (C(e)) if (L(t))
return e; return t;
let n = k(), o = function() { let n = I(), o = function() {
L.push(o), n(e()), L.pop(); D.push(o), n(t()), D.pop();
}; };
return g.set(o, /* @__PURE__ */ new Set([n])), g.set(n[l], o), o(), n; return g.set(o, /* @__PURE__ */ new Set([n])), g.set(n[d], o), o(), n;
} }
p.action = function(e, t, ...n) { l.action = function(t, e, ...n) {
let o = e[l], { actions: r } = o; let o = t[d], { actions: r } = o;
if (!r || !Reflect.has(r, t)) if (!r || !Reflect.has(r, e))
throw new Error(`'${e}' has no action with name '${t}'!`); throw new Error(`'${t}' has no action with name '${e}'!`);
if (r[t].apply(o, n), o.skip) if (r[e].apply(o, n), o.skip)
return Reflect.deleteProperty(o, "skip"); return Reflect.deleteProperty(o, "skip");
o.listeners.forEach((c) => c(o.value)); o.listeners.forEach((c) => c(o.value));
}; };
p.on = function e(t, n, o = {}) { l.on = function t(e, n, o = {}) {
let { signal: r } = o; let { signal: r } = o;
if (!(r && r.aborted)) { if (!(r && r.aborted)) {
if (Array.isArray(t)) if (Array.isArray(e))
return t.forEach((c) => e(c, n, o)); return e.forEach((c) => t(c, n, o));
j(t, n), r && r.addEventListener("abort", () => N(t, n)); T(e, n), r && r.addEventListener("abort", () => N(e, n));
} }
}; };
p.symbols = { l.symbols = {
signal: l, signal: d,
onclear: Symbol.for("Signal.onclear") onclear: Symbol.for("Signal.onclear")
}; };
p.attribute = function(e, t = void 0) { l.attribute = function(t, e = void 0) {
let { host: n } = b, o = n() && n().hasAttribute(e) ? n().getAttribute(e) : t, r = new AbortController(), c = p(o, { let { host: n } = m, o = n() && n().hasAttribute(t) ? n().getAttribute(t) : e, r = new AbortController(), c = l(o, {
[p.symbols.onclear]() { [l.symbols.onclear]() {
r.abort(); r.abort();
} }
}); });
return b.host(_.attributeChanged(function({ detail: s }) { return m.host(v.attributeChanged(function({ detail: a }) {
let [d, m] = s; let [p, b] = a;
d === e && c(m); p === t && c(b);
}, { signal: r.signal })), c; }, { signal: r.signal })), c;
}; };
p.clear = function(...e) { l.clear = function(...t) {
for (let n of e) { for (let n of t) {
Reflect.deleteProperty(n, "toJSON"); Reflect.deleteProperty(n, "toJSON");
let o = n[l]; let o = n[d];
o.onclear.forEach((r) => r.call(o)), t(n, o), Reflect.deleteProperty(n, l); o.onclear.forEach((r) => r.call(o)), e(n, o), Reflect.deleteProperty(n, d);
} }
function t(n, o) { function e(n, o) {
o.listeners.forEach((r) => { o.listeners.forEach((r) => {
if (o.listeners.delete(r), !g.has(r)) if (o.listeners.delete(r), !g.has(r))
return; return;
let c = g.get(r); let c = g.get(r);
c.delete(n), !(c.size > 1) && (p.clear(...c), g.delete(r)); c.delete(n), !(c.size > 1) && (l.clear(...c), g.delete(r));
}); });
} }
}; };
p.el = function(e, t) { l.el = function(t, e) {
let n = document.createComment("<#reactive>"), o = document.createComment("</#reactive>"), r = document.createDocumentFragment(); let n = document.createComment("<#reactive>"), o = document.createComment("</#reactive>"), r = document.createDocumentFragment();
r.append(n, o); r.append(n, o);
let c = (i) => { let c = (s) => {
if (!n.parentNode || !o.parentNode) if (!n.parentNode || !o.parentNode)
return N(e, c); return N(t, c);
let s = t(i); let a = e(s);
Array.isArray(s) || (s = [s]); Array.isArray(a) || (a = [a]);
let d = n; let p = n;
for (; (d = n.nextSibling) !== o; ) for (; (p = n.nextSibling) !== o; )
d.remove(); p.remove();
n.after(...s); n.after(...a);
}; };
return j(e, c), G(e, c, n, t), c(e()), r; return T(t, c), V(t, c, n, e), c(t()), r;
}; };
var B = { var J = {
isSignal: C, isSignal: L,
processReactiveAttribute(e, t, n, o) { processReactiveAttribute(t, e, n, o) {
if (!C(n)) if (!L(n))
return n; return n;
let r = (c) => o([t, c]); let r = (c) => o(e, c);
return j(n, r), G(n, r, e, t), n(); return T(n, r), V(n, r, t, e), n();
} }
}; };
function G(e, t, ...n) { function V(t, e, ...n) {
let { current: o } = b; let { current: o } = m;
if (o.prevent) if (o.prevent)
return; return;
let r = "__dde_reactive"; let r = "__dde_reactive";
o.host(function(c) { o.host(function(c) {
c[r] || (c[r] = [], _.disconnected( c[r] || (c[r] = [], v.disconnected(
() => ( () => (
/*! /*!
* Clears all signals listeners added in the current scope/host (`S.el`, `assign`, ?). * Clears all signals listeners added in the current scope/host (`S.el`, `assign`, ?).
* You can investigate the `__dde_reactive` key of the element. * You can investigate the `__dde_reactive` key of the element.
* */ * */
c[r].forEach(([i]) => N(...i, e[l]?.host() === c)) c[r].forEach(([s]) => N(...s, t[d]?.host() === c))
) )
)(c)), c[r].push([[e, t], ...n]); )(c)), c[r].push([[t, e], ...n]);
}); });
} }
function k(e, t) { function I(t, e) {
let n = (...o) => o.length ? te(n, ...o) : ee(n); let n = (...o) => o.length ? ot(n, ...o) : rt(n);
return X(n, e, t); return et(n, t, e);
} }
var Q = Object.assign(/* @__PURE__ */ Object.create(null), { var tt = Object.assign(/* @__PURE__ */ Object.create(null), {
stopPropagation() { stopPropagation() {
this.skip = !0; this.skip = !0;
} }
}); });
function X(e, t, n) { function et(t, e, n) {
let o = []; let o = [];
T(n) !== "[object Object]" && (n = {}); M(n) !== "[object Object]" && (n = {});
let { onclear: r } = p.symbols; let { onclear: r } = l.symbols;
n[r] && (o.push(n[r]), Reflect.deleteProperty(n, r)); n[r] && (o.push(n[r]), Reflect.deleteProperty(n, r));
let { host: c } = b; let { host: c } = m;
return e[l] = { return t[d] = {
value: t, value: e,
actions: n, actions: n,
onclear: o, onclear: o,
host: c, host: c,
listeners: /* @__PURE__ */ new Set() listeners: /* @__PURE__ */ new Set()
}, e.toJSON = () => e(), Object.setPrototypeOf(e[l], Q), e; }, t.toJSON = () => t(), Object.setPrototypeOf(t[d], tt), t;
} }
function Y() { function nt() {
return L[L.length - 1]; return D[D.length - 1];
} }
function ee(e) { function rt(t) {
if (!e[l]) if (!t[d])
return; return;
let { value: t, listeners: n } = e[l], o = Y(); let { value: e, listeners: n } = t[d], o = nt();
return o && n.add(o), g.has(o) && g.get(o).add(e), t; return o && n.add(o), g.has(o) && g.get(o).add(t), e;
} }
function te(e, t, n) { function ot(t, e, n) {
if (!e[l]) if (!t[d])
return; return;
let o = e[l]; let o = t[d];
if (!(!n && o.value === t)) if (!(!n && o.value === e))
return o.value = t, o.listeners.forEach((r) => r(t)), t; return o.value = e, o.listeners.forEach((r) => r(e)), e;
} }
function j(e, t) { function T(t, e) {
if (e[l]) if (t[d])
return e[l].listeners.add(t); return t[d].listeners.add(e);
} }
function N(e, t, n) { function N(t, e, n) {
let o = e[l]; let o = t[d];
if (!o) if (!o)
return; return;
let r = o.listeners.delete(t); let r = o.listeners.delete(e);
if (n && !o.listeners.size) { if (n && !o.listeners.size) {
if (p.clear(e), !g.has(o)) if (l.clear(t), !g.has(o))
return r; return r;
let c = g.get(o); let c = g.get(o);
if (!g.has(c)) if (!g.has(c))
return r; return r;
g.get(c).forEach((i) => N(i, c, !0)); g.get(c).forEach((s) => N(s, c, !0));
} }
return r; return r;
} }
// signals.js // signals.js
D(B); P(J);
export { export {
p as S, l as S,
O as assign, R as assign,
J as classListDeclarative, H as assignAttribute,
ie as createElement, K as classListDeclarative,
le as dispatchEvent, at as createElement,
ie as el, gt as dispatchEvent,
fe as empty, at as el,
C as isSignal, pt as empty,
_ as on, L as isSignal,
D as registerReactivity, v as on,
b as scope P as registerReactivity,
m as scope
}; };

399
dist/esm.js vendored
View File

@ -1,40 +1,40 @@
// src/signals-common.js // src/signals-common.js
var m = { var v = {
isSignal(e) { isSignal(t) {
return !1; return !1;
}, },
processReactiveAttribute(e, t, n, u) { processReactiveAttribute(t, e, n, c) {
return n; return n;
} }
}; };
function T(e, t = !0) { function F(t, e = !0) {
return t ? Object.assign(m, e) : (Object.setPrototypeOf(e, m), e); return e ? Object.assign(v, t) : (Object.setPrototypeOf(t, v), t);
} }
function b(e) { function m(t) {
return m.isPrototypeOf(e) && e !== m ? e : m; return v.isPrototypeOf(t) && t !== v ? t : v;
} }
// src/helpers.js // src/helpers.js
function g(e) { function h(t) {
return typeof e > "u"; return typeof t > "u";
} }
function _(e, t) { function _(t, e) {
if (!e || !(e instanceof AbortSignal)) if (!t || !(t instanceof AbortSignal))
return !0; return !0;
if (!e.aborted) if (!t.aborted)
return e.addEventListener("abort", t), function() { return t.addEventListener("abort", e), function() {
e.removeEventListener("abort", t); t.removeEventListener("abort", e);
}; };
} }
// src/dom-common.js // src/dom-common.js
var C = { setDeleteAttr: M }; var R = { setDeleteAttr: H };
function M(e, t, n) { function H(t, e, n) {
if (Reflect.set(e, t, n), !!g(n)) { if (Reflect.set(t, e, n), !!h(n)) {
if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined") if (Reflect.deleteProperty(t, e), t instanceof HTMLElement && t.getAttribute(e) === "undefined")
return e.removeAttribute(t); return t.removeAttribute(e);
if (Reflect.get(e, t) === "undefined") if (Reflect.get(t, e) === "undefined")
return Reflect.set(e, t, ""); return Reflect.set(t, e, "");
} }
} }
@ -42,9 +42,9 @@ function M(e, t, n) {
var E = [{ var E = [{
scope: document.body, scope: document.body,
namespace: "html", namespace: "html",
host: (e) => e ? e(document.body) : document.body, host: (t) => t ? t(document.body) : document.body,
prevent: !0 prevent: !0
}], R = (e) => e === "svg" ? "http://www.w3.org/2000/svg" : e, x = { }], S = (t) => t === "svg" ? "http://www.w3.org/2000/svg" : t, x = {
get current() { get current() {
return E[E.length - 1]; return E[E.length - 1];
}, },
@ -54,270 +54,285 @@ var E = [{
get namespace() { get namespace() {
return this.current.namespace; return this.current.namespace;
}, },
set namespace(e) { set namespace(t) {
return this.current.namespace = R(e); return this.current.namespace = S(t);
}, },
preventDefault() { preventDefault() {
let { current: e } = this; let { current: t } = this;
return e.prevent = !0, e; return t.prevent = !0, t;
}, },
elNamespace(e) { elNamespace(t) {
let t = this.namespace; let e = this.namespace;
return this.namespace = e, { return this.namespace = t, {
append(...n) { append(...n) {
return x.namespace = t, n.length === 1 ? n[0] : document.createDocumentFragment().append(...n); return x.namespace = e, n.length === 1 ? n[0] : document.createDocumentFragment().append(...n);
} }
}; };
}, },
get state() { get state() {
return [...E]; return [...E];
}, },
push(e = {}) { push(t = {}) {
return e.namespace && (e.namespace = R(e.namespace)), E.push(Object.assign({}, this.current, { prevent: !1 }, e)); return t.namespace && (t.namespace = S(t.namespace)), E.push(Object.assign({}, this.current, { prevent: !1 }, t));
}, },
pop() { pop() {
return E.pop(); return E.pop();
} }
}; };
function V(e, t, ...n) { function J(t, e, ...n) {
let u = b(this), { namespace: r } = x, f = 0, a; let c = m(this), { namespace: r } = x, f = 0, u;
switch ((Object(t) !== t || u.isSignal(t)) && (t = { textContent: t }), !0) { switch ((Object(e) !== e || c.isSignal(e)) && (e = { textContent: e }), !0) {
case typeof e == "function": { case typeof t == "function": {
f = 1, x.push({ scope: e, host: (i) => i ? (f === 1 ? n.unshift(i) : i(a), void 0) : a }), a = e(t || void 0), (a instanceof HTMLElement ? P : j)(a, "Attribute", "dde-fun", e.name); f = 1, x.push({ scope: t, host: (a) => a ? (f === 1 ? n.unshift(a) : a(u), void 0) : u }), u = t(e || void 0), (u instanceof HTMLElement ? M : W)(u, "Attribute", "dde-fun", t.name);
break; break;
} }
case e === "#text": case t === "#text":
a = w.call(this, document.createTextNode(""), t); u = w.call(this, document.createTextNode(""), e);
break; break;
case e === "<>": case t === "<>":
a = w.call(this, document.createDocumentFragment(), t); u = w.call(this, document.createDocumentFragment(), e);
break; break;
case r !== "html": case r !== "html":
a = w.call(this, document.createElementNS(r, e), t); u = w.call(this, document.createElementNS(r, t), e);
break; break;
case !a: case !u:
a = w.call(this, document.createElement(e), t); u = w.call(this, document.createElement(t), e);
} }
return n.forEach((i) => i(a)), f && x.pop(), f = 2, a; return n.forEach((a) => a(u)), f && x.pop(), f = 2, u;
} }
var { setDeleteAttr: S } = C; var { setDeleteAttr: L } = R, A = /* @__PURE__ */ new WeakMap();
function w(e, ...t) { function w(t, ...e) {
let n = this, u = b(this); if (!e.length)
if (!t.length) return t;
return e; A.set(t, P(t, this));
let f = (e instanceof SVGElement ? j : P).bind(null, e, "Attribute"); for (let [n, c] of Object.entries(Object.assign({}, ...e)))
return Object.entries(Object.assign({}, ...t)).forEach(function a([i, d]) { N.call(this, t, n, c);
d = u.processReactiveAttribute(e, i, d, a); return A.delete(t), t;
let [l] = i;
if (l === "=")
return f(i.slice(1), d);
if (l === ".")
return L(e, i.slice(1), d);
if (/(aria|data)([A-Z])/.test(i))
return i = i.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), f(i, d);
switch (i === "className" && (i = "class"), i) {
case "xlink:href":
return f(i, d, "http://www.w3.org/1999/xlink");
case "textContent":
return S(e, i, d);
case "style":
if (typeof d != "object")
break;
case "dataset":
return O(u, d, L.bind(null, e[i]));
case "ariaset":
return O(u, d, (h, c) => f("aria-" + h, c));
case "classList":
return W.call(n, e, d);
}
return F(e, i) ? S(e, i, d) : f(i, d);
}), e;
} }
function W(e, t) { function N(t, e, n) {
let n = b(this); let { setRemoveAttr: c, s: r } = P(t, this), f = this;
return O( n = r.processReactiveAttribute(
n,
t, t,
(u, r) => e.classList.toggle(u, r === -1 ? void 0 : !!r) e,
), e; n,
(a, p) => N.call(f, t, a, p)
);
let [u] = e;
if (u === "=")
return c(e.slice(1), n);
if (u === ".")
return D(t, e.slice(1), n);
if (/(aria|data)([A-Z])/.test(e))
return e = e.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), c(e, n);
switch (e === "className" && (e = "class"), e) {
case "xlink:href":
return c(e, n, "http://www.w3.org/1999/xlink");
case "textContent":
return L(t, e, n);
case "style":
if (typeof n != "object")
break;
case "dataset":
return y(r, n, D.bind(null, t[e]));
case "ariaset":
return y(r, n, (a, p) => c("aria-" + a, p));
case "classList":
return U.call(f, t, n);
}
return q(t, e) ? L(t, e, n) : c(e, n);
} }
function $(e) { function P(t, e) {
return Array.from(e.children).forEach((t) => t.remove()), e; if (A.has(t))
return A.get(t);
let c = (t instanceof SVGElement ? W : M).bind(null, t, "Attribute"), r = m(e);
return { setRemoveAttr: c, s: r };
} }
function F(e, t) { function U(t, e) {
if (!Reflect.has(e, t)) let n = m(this);
return y(
n,
e,
(c, r) => t.classList.toggle(c, r === -1 ? void 0 : !!r)
), t;
}
function Q(t) {
return Array.from(t.children).forEach((e) => e.remove()), t;
}
function q(t, e) {
if (!Reflect.has(t, e))
return !1; return !1;
let n = D(e, t); let n = j(t, e);
return !g(n.set); return !h(n.set);
} }
function D(e, t) { function j(t, e) {
if (e = Object.getPrototypeOf(e), !e) if (t = Object.getPrototypeOf(t), !t)
return {}; return {};
let n = Object.getOwnPropertyDescriptor(e, t); let n = Object.getOwnPropertyDescriptor(t, e);
return n || D(e, t); return n || j(t, e);
} }
function O(e, t, n) { function y(t, e, n) {
if (!(typeof t != "object" || t === null)) if (!(typeof e != "object" || e === null))
return Object.entries(t).forEach(function([r, f]) { return Object.entries(e).forEach(function([r, f]) {
r && (f = e.processReactiveAttribute(t, r, f, (a) => n(...a)), n(r, f)); r && (f = t.processReactiveAttribute(e, r, f, n), n(r, f));
}); });
} }
function N(e) { function T(t) {
return Array.isArray(e) ? e.filter(Boolean).join(" ") : e; return Array.isArray(t) ? t.filter(Boolean).join(" ") : t;
} }
function P(e, t, n, u) { function M(t, e, n, c) {
return e[(g(u) ? "remove" : "set") + t](n, N(u)); return t[(h(c) ? "remove" : "set") + e](n, T(c));
} }
function j(e, t, n, u, r = null) { function W(t, e, n, c, r = null) {
return e[(g(u) ? "remove" : "set") + t + "NS"](r, n, N(u)); return t[(h(c) ? "remove" : "set") + e + "NS"](r, n, T(c));
} }
function L(e, t, n) { function D(t, e, n) {
if (Reflect.set(e, t, n), !!g(n)) if (Reflect.set(t, e, n), !!h(n))
return Reflect.deleteProperty(e, t); return Reflect.deleteProperty(t, e);
} }
// src/events.js // src/events.js
function Q(e, t, ...n) { function k(t, e, ...n) {
let u = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); let c = n.length ? new CustomEvent(e, { detail: n[0] }) : new Event(e);
return e.dispatchEvent(u); return t.dispatchEvent(c);
} }
function y(e, t, n) { function C(t, e, n) {
return function(r) { return function(r) {
return r.addEventListener(e, t, n), r; return r.addEventListener(t, e, n), r;
}; };
} }
var A = U(), H = /* @__PURE__ */ new WeakSet(); var O = B(), z = /* @__PURE__ */ new WeakSet();
y.connected = function(e, t) { C.connected = function(t, e) {
let n = "connected"; let n = "connected";
return typeof t != "object" && (t = {}), t.once = !0, function(r) { return typeof e != "object" && (e = {}), e.once = !0, function(r) {
let f = "dde:" + n; let f = "dde:" + n;
return r.addEventListener(f, e, t), r.__dde_lifecycleToEvents ? r : r.isConnected ? (r.dispatchEvent(new Event(f)), r) : (_(t.signal, () => A.offConnected(r, e)) && A.onConnected(r, e), r); return r.addEventListener(f, t, e), r.__dde_lifecycleToEvents ? r : r.isConnected ? (r.dispatchEvent(new Event(f)), r) : (_(e.signal, () => O.offConnected(r, t)) && O.onConnected(r, t), r);
}; };
}; };
y.disconnected = function(e, t) { C.disconnected = function(t, e) {
let n = "disconnected"; let n = "disconnected";
return typeof t != "object" && (t = {}), t.once = !0, function(r) { return typeof e != "object" && (e = {}), e.once = !0, function(r) {
let f = "dde:" + n; let f = "dde:" + n;
return r.addEventListener(f, e, t), r.__dde_lifecycleToEvents || _(t.signal, () => A.offDisconnected(r, e)) && A.onDisconnected(r, e), r; return r.addEventListener(f, t, e), r.__dde_lifecycleToEvents || _(e.signal, () => O.offDisconnected(r, t)) && O.onDisconnected(r, t), r;
}; };
}; };
y.attributeChanged = function(e, t) { C.attributeChanged = function(t, e) {
let n = "attributeChanged"; let n = "attributeChanged";
return typeof t != "object" && (t = {}), function(r) { return typeof e != "object" && (e = {}), function(r) {
let f = "dde:" + n; let f = "dde:" + n;
if (r.addEventListener(f, e, t), r.__dde_lifecycleToEvents || H.has(r)) if (r.addEventListener(f, t, e), r.__dde_lifecycleToEvents || z.has(r))
return r; return r;
let a = new MutationObserver(function(d) { let u = new MutationObserver(function(p) {
for (let { attributeName: l, target: h } of d) for (let { attributeName: l, target: g } of p)
h.dispatchEvent( g.dispatchEvent(
new CustomEvent(f, { detail: [l, h.getAttribute(l)] }) new CustomEvent(f, { detail: [l, g.getAttribute(l)] })
); );
}); });
return _(t.signal, () => a.disconnect()) && a.observe(r, { attributes: !0 }), r; return _(e.signal, () => u.disconnect()) && u.observe(r, { attributes: !0 }), r;
}; };
}; };
function U() { function B() {
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) { let t = /* @__PURE__ */ new Map(), e = !1, n = new MutationObserver(function(o) {
for (let o of c) for (let s of o)
if (o.type === "childList") { if (s.type === "childList") {
if (l(o.addedNodes, !0)) { if (l(s.addedNodes, !0)) {
a(); u();
continue; continue;
} }
h(o.removedNodes, !0) && a(); g(s.removedNodes, !0) && u();
} }
}); });
return { return {
onConnected(c, o) { onConnected(o, s) {
f(); f();
let s = r(c); let i = r(o);
s.connected.has(o) || (s.connected.add(o), s.length_c += 1); i.connected.has(s) || (i.connected.add(s), i.length_c += 1);
}, },
offConnected(c, o) { offConnected(o, s) {
if (!e.has(c)) if (!t.has(o))
return; return;
let s = e.get(c); let i = t.get(o);
s.connected.has(o) && (s.connected.delete(o), s.length_c -= 1, u(c, s)); i.connected.has(s) && (i.connected.delete(s), i.length_c -= 1, c(o, i));
}, },
onDisconnected(c, o) { onDisconnected(o, s) {
f(); f();
let s = r(c); let i = r(o);
s.disconnected.has(o) || (s.disconnected.add(o), s.length_d += 1); i.disconnected.has(s) || (i.disconnected.add(s), i.length_d += 1);
}, },
offDisconnected(c, o) { offDisconnected(o, s) {
if (!e.has(c)) if (!t.has(o))
return; return;
let s = e.get(c); let i = t.get(o);
s.disconnected.has(o) && (s.disconnected.delete(o), s.length_d -= 1, u(c, s)); i.disconnected.has(s) && (i.disconnected.delete(s), i.length_d -= 1, c(o, i));
} }
}; };
function u(c, o) { function c(o, s) {
o.length_c || o.length_d || (e.delete(c), a()); s.length_c || s.length_d || (t.delete(o), u());
} }
function r(c) { function r(o) {
if (e.has(c)) if (t.has(o))
return e.get(c); return t.get(o);
let o = { let s = {
connected: /* @__PURE__ */ new WeakSet(), connected: /* @__PURE__ */ new WeakSet(),
length_c: 0, length_c: 0,
disconnected: /* @__PURE__ */ new WeakSet(), disconnected: /* @__PURE__ */ new WeakSet(),
length_d: 0 length_d: 0
}; };
return e.set(c, o), o; return t.set(o, s), s;
} }
function f() { function f() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 })); e || (e = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
}
function u() {
!e || t.size || (e = !1, n.disconnect());
} }
function a() { function a() {
!t || e.size || (t = !1, n.disconnect()); return new Promise(function(o) {
} (requestIdleCallback || requestAnimationFrame)(o);
function i() {
return new Promise(function(c) {
(requestIdleCallback || requestAnimationFrame)(c);
}); });
} }
async function d(c) { async function p(o) {
e.size > 30 && await i(); t.size > 30 && await a();
let o = []; let s = [];
if (!(c instanceof Node)) if (!(o instanceof Node))
return o; return s;
for (let s of e.keys()) for (let i of t.keys())
s === c || !(s instanceof Node) || c.contains(s) && o.push(s); i === o || !(i instanceof Node) || o.contains(i) && s.push(i);
return o; return s;
} }
function l(c, o) { function l(o, s) {
let s = !1; let i = !1;
for (let p of c) { for (let d of o) {
if (o && d(p).then(l), !e.has(p)) if (s && p(d).then(l), !t.has(d))
continue; continue;
let v = e.get(p); let b = t.get(d);
v.length_c && (p.dispatchEvent(new Event("dde:connected")), v.connected = /* @__PURE__ */ new WeakSet(), v.length_c = 0, v.length_d || e.delete(p), s = !0); b.length_c && (d.dispatchEvent(new Event("dde:connected")), b.connected = /* @__PURE__ */ new WeakSet(), b.length_c = 0, b.length_d || t.delete(d), i = !0);
} }
return s; return i;
} }
function h(c, o) { function g(o, s) {
let s = !1; let i = !1;
for (let p of c) for (let d of o)
o && d(p).then(h), !(!e.has(p) || !e.get(p).length_d) && (p.dispatchEvent(new Event("dde:disconnected")), e.delete(p), s = !0); s && p(d).then(g), !(!t.has(d) || !t.get(d).length_d) && (d.dispatchEvent(new Event("dde:disconnected")), t.delete(d), i = !0);
return s; return i;
} }
} }
// index.js // index.js
[HTMLElement, SVGElement, DocumentFragment].forEach((e) => { [HTMLElement, SVGElement, DocumentFragment].forEach((t) => {
let { append: t } = e.prototype; let { append: e } = t.prototype;
e.prototype.append = function(...n) { t.prototype.append = function(...n) {
return t.apply(this, n), this; return e.apply(this, n), this;
}; };
}); });
export { export {
w as assign, w as assign,
W as classListDeclarative, N as assignAttribute,
V as createElement, U as classListDeclarative,
Q as dispatchEvent, J as createElement,
V as el, k as dispatchEvent,
$ as empty, J as el,
y as on, Q as empty,
T as registerReactivity, C as on,
F as registerReactivity,
x as scope x as scope
}; };