1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2024-11-24 17:39:36 +01:00
This commit is contained in:
Jan Andrle 2023-09-06 14:54:28 +02:00
parent dbd8dd557b
commit a8ae99962e
Signed by: jaandrle
GPG Key ID: B3A25AED155AFFAB
4 changed files with 536 additions and 480 deletions

View File

@ -21,24 +21,24 @@
return document.createDocumentFragment(); return document.createDocumentFragment();
} }
}; };
function R(e, t = !0) { function A(e, t = !0) {
return t ? Object.assign(m, e) : (Object.setPrototypeOf(e, m), e); return t ? Object.assign(m, e) : (Object.setPrototypeOf(e, m), e);
} }
function A(e) { function C(e) {
return m.isPrototypeOf(e) && e !== m ? e : m; return m.isPrototypeOf(e) && e !== m ? e : m;
} }
// src/dom.js // src/dom.js
var E = "html"; var w = "html";
function K(e) { function Y(e) {
return E = e === "svg" ? "http://www.w3.org/2000/svg" : e, { return w = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(t) { append(t) {
return E = "html", t; return w = "html", t;
} }
}; };
} }
function Q(e, t, ...n) { function ee(e, t, ...n) {
let r = A(this), o; let r = C(this), o;
if (e === "<>") { if (e === "<>") {
if (r.isReactiveAtrribute(t)) if (r.isReactiveAtrribute(t))
return r.reactiveElement(t, ...n); return r.reactiveElement(t, ...n);
@ -49,103 +49,117 @@
o = e(t || void 0); o = e(t || void 0);
break; break;
case e === "#text": case e === "#text":
o = C(document.createTextNode(""), t); o = N(document.createTextNode(""), t);
break; break;
case E !== "html": case w !== "html":
o = C(document.createElementNS(E, e), t); o = N(document.createElementNS(w, e), t);
break; break;
default: case !o:
o = C(document.createElement(e), t); o = N(document.createElement(e), t);
} }
return n.forEach((l) => l(o)), o; return n.forEach((l) => l(o)), o;
} }
function C(e, ...t) { var S = /* @__PURE__ */ new Map();
let n = A(this); function N(e, ...t) {
let n = C(this);
if (!t.length) if (!t.length)
return e; return e;
let r = e instanceof SVGElement, o = (r ? z : D).bind(null, e, "Attribute"); let r = e instanceof SVGElement, o = (r ? I : _).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function l([s, f]) { return Object.entries(Object.assign({}, ...t)).forEach(function l([f, u]) {
if (n.isReactiveAtrribute(f, s) && (f = n.processReactiveAttribute(el, s, f, l)), s[0] === "=") n.isReactiveAtrribute(u, f) && (u = n.processReactiveAttribute(el, f, u, l));
return o(s.slice(1), f); let [p] = f;
if (s[0] === ".") if (p === "=")
return S(e, s.slice(1), f); return o(f.slice(1), u);
if (typeof f == "object") if (p === ".")
switch (s) { return L(e, f.slice(1), u);
if (typeof u == "object")
switch (f) {
case "style": case "style":
return v(f, D.bind(null, e.style, "Property")); return E(u, _.bind(null, e.style, "Property"));
case "dataset": case "dataset":
return v(f, S.bind(null, e.dataset)); return E(u, L.bind(null, e.dataset));
case "ariaset": case "ariaset":
return v(f, (p, b) => o("aria-" + p, b)); return E(u, (x, v) => o("aria-" + x, v));
case "classList": case "classList":
return q(e, f); return q(e, u);
default: default:
return Reflect.set(e, s, f); return Reflect.set(e, f, u);
} }
if (/(aria|data)([A-Z])/.test(s)) if (/(aria|data)([A-Z])/.test(f))
return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(s, f); return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(f, u);
switch (s) { switch (f) {
case "href":
return o(s, f);
case "xlink:href": case "xlink:href":
return o(s, f, "http://www.w3.org/1999/xlink"); return o(f, u, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
if (!r) if (!r)
break; break;
return e.appendChild(document.createTextNode(f)); return e.appendChild(document.createTextNode(u));
} }
return s in e && !r ? S(e, s, f) : o(s, f); return z(e, f) ? L(e, f, u) : o(f, u);
}), e; }), e;
} }
function q(e, t) { function q(e, t) {
return typeof t != "object" || v( return typeof t != "object" || E(
t, t,
(n, r) => e.classList.toggle(n, r === -1 ? void 0 : !!r) (n, r) => e.classList.toggle(n, r === -1 ? void 0 : !!r)
), e; ), e;
} }
function X(e) { function te(e) {
return Array.from(e.children).forEach((t) => t.remove()), e; return Array.from(e.children).forEach((t) => t.remove()), e;
} }
function v(e, t) { function z(e, t) {
let n = e.nodeName + "," + t;
if (S.has(n))
return S.get(n);
let r = D(e, t), o = !y(r.set);
return S.set(n, o), o;
}
function D(e, t) {
if (e = Object.getPrototypeOf(e), !e)
return {};
let n = Object.getOwnPropertyDescriptor(e, t);
return n || D(e, t);
}
function E(e, t) {
return Object.entries(e).forEach(([n, r]) => t(n, r)); return Object.entries(e).forEach(([n, r]) => t(n, r));
} }
function j(e) { function y(e) {
return typeof e > "u"; return typeof e > "u";
} }
function D(e, t, n, r) { function _(e, t, n, r) {
return e[(j(r) ? "remove" : "set") + t](n, r); return e[(y(r) ? "remove" : "set") + t](n, r);
} }
function z(e, t, n, r, o = null) { function I(e, t, n, r, o = null) {
return e[(j(r) ? "remove" : "set") + t + "NS"](o, n, r); return e[(y(r) ? "remove" : "set") + t + "NS"](o, n, r);
} }
function S(e, t, n) { function L(e, t, n) {
return Reflect[j(n) ? "deleteProperty" : "set"](e, t, n); return Reflect[y(n) ? "deleteProperty" : "set"](e, t, n);
} }
// src/events.js // src/events.js
function _(e, t, n) { function T(e, t, n) {
return (r) => (r.addEventListener(e, t, n), r); return (r) => (r.addEventListener(e, t, n), r);
} }
var w = M(); var O = W();
_.connected = function(e, t) { T.connected = function(e, t) {
return function(r) { return function(r) {
w.onConnected(r, e), t && t.signal && t.signal.addEventListener("abort", () => w.offConnected(r, e)); O.onConnected(r, e), t && t.signal && t.signal.addEventListener("abort", () => O.offConnected(r, e));
}; };
}; };
_.disconnected = function(e, t) { T.disconnected = function(e, t) {
return function(r) { return function(r) {
w.onDisconnected(r, e), t && t.signal && t.signal.addEventListener("abort", () => w.offDisconnected(r, e)); O.onDisconnected(r, e), t && t.signal && t.signal.addEventListener("abort", () => O.offDisconnected(r, e));
}; };
}; };
function M() { function W() {
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) { let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) {
for (let i of c) for (let i of c)
if (i.type === "childList") { if (i.type === "childList") {
if (b(i.addedNodes, !0)) { if (x(i.addedNodes, !0)) {
s(); f();
continue; continue;
} }
N(i.removedNodes, !0) && s(); v(i.removedNodes, !0) && f();
} }
}); });
return { return {
@ -155,8 +169,8 @@
offConnected(c, i) { offConnected(c, i) {
if (!e.has(c)) if (!e.has(c))
return; return;
let u = e.get(c), a = u.connected; let s = e.get(c), a = s.connected;
a.splice(a.indexOf(i), 1), r(c, u); a.splice(a.indexOf(i), 1), r(c, s);
}, },
onDisconnected(c, i) { onDisconnected(c, i) {
l(), o(c).disconnected.push(i); l(), o(c).disconnected.push(i);
@ -164,12 +178,12 @@
offDisconnected(c, i) { offDisconnected(c, i) {
if (!e.has(c)) if (!e.has(c))
return; return;
let u = e.get(c), a = u.disconnected; let s = e.get(c), a = s.disconnected;
a.splice(a.indexOf(i), 1), r(c, u); a.splice(a.indexOf(i), 1), r(c, s);
} }
}; };
function r(c, i) { function r(c, i) {
i.connected.length || i.disconnect.length || (e.delete(c), s()); i.connected.length || i.disconnect.length || (e.delete(c), f());
} }
function o(c) { function o(c) {
if (e.has(c)) if (e.has(c))
@ -180,37 +194,37 @@
function l() { function l() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
} }
function s() { function f() {
!t || e.size || (t = !1, n.disconnect()); !t || e.size || (t = !1, n.disconnect());
} }
function f() { function u() {
return new Promise(function(c) { return new Promise(function(c) {
(requestIdleCallback || requestAnimationFrame)(c); (requestIdleCallback || requestAnimationFrame)(c);
}); });
} }
async function p(c) { async function p(c) {
e.size > 30 && await f(); e.size > 30 && await u();
let i = []; let i = [];
if (!(c instanceof Node)) if (!(c instanceof Node))
return i; return i;
for (let u of e.keys()) for (let s of e.keys())
u === c || !(u instanceof Node) || c.contains(u) && i.push(u); s === c || !(s instanceof Node) || c.contains(s) && i.push(s);
return i; return i;
} }
function b(c, i) { function x(c, i) {
for (let u of c) { for (let s of c) {
if (i && p(u).then(b), !e.has(u)) if (i && p(s).then(x), !e.has(s))
return !1; return !1;
let a = e.get(u); let a = e.get(s);
return a.connected.forEach((O) => O(u)), a.connected.length = 0, a.disconnected.length || e.delete(u), !0; return a.connected.forEach((j) => j(s)), a.connected.length = 0, a.disconnected.length || e.delete(s), !0;
} }
} }
function N(c, i) { function v(c, i) {
for (let u of c) { for (let s of c) {
if (i && p(u).then(N), !e.has(u)) if (i && p(s).then(v), !e.has(s))
return !1; return !1;
let a = e.get(u); let a = e.get(s);
return a.disconnected.forEach((O) => O(u)), a.connected.length = 0, a.disconnected.length = 0, e.delete(u), !0; return a.disconnected.forEach((j) => j(s)), a.connected.length = 0, a.disconnected.length = 0, e.delete(s), !0;
} }
} }
} }
@ -225,23 +239,23 @@
// src/signals-lib.js // src/signals-lib.js
var d = Symbol.for("signal"); var d = Symbol.for("signal");
function x(e) { function b(e) {
try { try {
return Reflect.has(e, d); return Reflect.has(e, d);
} catch { } catch {
return !1; return !1;
} }
} }
function y(e, t) { function R(e, t) {
if (typeof e != "function") if (typeof e != "function")
return P(e, t); return F(e, t);
if (x(e)) if (b(e))
return e; return e;
let n = P(); let n = F();
return F(() => n(e())), n; return M(() => n(e())), n;
} }
y.action = function(e, t, ...n) { R.action = function(e, t, ...n) {
if (!x(e)) if (!b(e))
throw new Error(`'${e}' is not a signal!`); throw new Error(`'${e}' is not a signal!`);
let r = e[d], { actions: o } = r; let r = e[d], { actions: o } = r;
if (!o || !Reflect.has(o, t)) if (!o || !Reflect.has(o, t))
@ -250,105 +264,105 @@
return Reflect.deleteProperty(r, "skip"); return Reflect.deleteProperty(r, "skip");
r.listeners.forEach((l) => l(r.value)); r.listeners.forEach((l) => l(r.value));
}; };
y.on = function e(t, n, r) { R.on = function e(t, n, r) {
if (Array.isArray(t)) if (Array.isArray(t))
return t.forEach((o) => e(o, n, r)); return t.forEach((o) => e(o, n, r));
L(t, n), r && r.signal && r.signal.addEventListener("abort", () => $(t, n)); P(t, n), r && r.signal && r.signal.addEventListener("abort", () => k(t, n));
}; };
y.clear = function(...e) { R.clear = function(...e) {
for (let t of e) for (let t of e)
t[d].listeners.clear(), Reflect.deleteProperty(t, d); t[d].listeners.clear(), Reflect.deleteProperty(t, d);
}; };
var T = { var $ = {
isReactiveAtrribute(e, t) { isReactiveAtrribute(e, t) {
return x(e); return b(e);
}, },
isTextContent(e) { isTextContent(e) {
return h(e) === "string" || x(e) && h(G(e)) === "string"; return h(e) === "string" || b(e) && h(V(e)) === "string";
}, },
processReactiveAttribute(e, t, n, r) { processReactiveAttribute(e, t, n, r) {
return L(n, (o) => r([t, o])), n(); return P(n, (o) => r([t, o])), n();
}, },
reactiveElement(e, t) { reactiveElement(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 l = (s) => { let l = (f) => {
if (!n.parentNode || !r.parentNode) if (!n.parentNode || !r.parentNode)
return $(e, l); return k(e, l);
let f = t(s); let u = t(f);
Array.isArray(f) || (f = [f]); Array.isArray(u) || (u = [u]);
let p = n; let p = n;
for (; (p = n.nextSibling) !== r; ) for (; (p = n.nextSibling) !== r; )
p.remove(); p.remove();
n.after(...f); n.after(...u);
}; };
return L(e, l), l(e()), o; return P(e, l), l(e()), o;
} }
}; };
function P(e, t) { function F(e, t) {
let n = (...r) => r.length ? B(n, r[0]) : k(n); let n = (...r) => r.length ? U(n, r[0]) : H(n);
return W(n, e, t); return B(n, e, t);
} }
var I = Object.assign(/* @__PURE__ */ Object.create(null), { var Z = Object.assign(/* @__PURE__ */ Object.create(null), {
stopPropagation() { stopPropagation() {
this.skip = !0; this.skip = !0;
} }
}); });
function W(e, t, n) { function B(e, t, n) {
return h(n) !== "[object Object]" && (n = {}), e[d] = { return h(n) !== "[object Object]" && (n = {}), e[d] = {
value: t, value: t,
actions: n, actions: n,
listeners: /* @__PURE__ */ new Set() listeners: /* @__PURE__ */ new Set()
}, Object.setPrototypeOf(e[d], I), e; }, Object.setPrototypeOf(e[d], Z), e;
} }
var g = []; var g = [];
function F(e) { function M(e) {
let t = function() { let t = function() {
g.push(t), e(), g.pop(); g.push(t), e(), g.pop();
}; };
g.push(t), e(), g.pop(); g.push(t), e(), g.pop();
} }
function Z() { function G() {
return g[g.length - 1]; return g[g.length - 1];
} }
function k(e) { function H(e) {
if (!e[d]) if (!e[d])
return; return;
let { value: t, listeners: n } = e[d], r = Z(); let { value: t, listeners: n } = e[d], r = G();
return r && n.add(r), t; return r && n.add(r), t;
} }
function B(e, t) { function U(e, t) {
if (!e[d]) if (!e[d])
return; return;
let n = e[d]; let n = e[d];
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 G(e) { function V(e) {
return e[d].value; return e[d].value;
} }
function L(e, t) { function P(e, t) {
return e[d].listeners.add(t); return e[d].listeners.add(t);
} }
function $(e, t) { function k(e, t) {
return e[d].listeners.delete(t); return e[d].listeners.delete(t);
} }
// src/signals.js // src/signals.js
R(T); A($);
globalThis.dde= { globalThis.dde= {
S: y, S: R,
assign: C, assign: N,
classListDeclartive: q, classListDeclartive: q,
createElement: Q, createElement: ee,
el: Q, el: ee,
empty: X, empty: te,
isSignal: x, isSignal: b,
namespace: K, namespace: Y,
on: _, on: T,
registerReactivity: R, registerReactivity: A,
watch: F watch: M
}; };
})(); })();

250
dist/dde.js vendored
View File

@ -1,216 +1,230 @@
//deka-dom-el library is available via global namespace `dde` //deka-dom-el library is available via global namespace `dde`
(()=> { (()=> {
// src/helpers.js // src/helpers.js
function R(e) { function y(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);
} }
// src/signals-common.js // src/signals-common.js
var l = { var p = {
isReactiveAtrribute(e, t) { isReactiveAtrribute(e, t) {
return !1; return !1;
}, },
isTextContent(e) { isTextContent(e) {
return R(e) !== "[object Object]"; return y(e) !== "[object Object]";
}, },
processReactiveAttribute(e, t, o, n) { processReactiveAttribute(e, t, n, r) {
return !1; return !1;
}, },
reactiveElement(e, ...t) { reactiveElement(e, ...t) {
return document.createDocumentFragment(); return document.createDocumentFragment();
} }
}; };
function y(e, t = !0) { function D(e, t = !0) {
return t ? Object.assign(l, e) : (Object.setPrototypeOf(e, l), e); return t ? Object.assign(p, e) : (Object.setPrototypeOf(e, p), e);
} }
function v(e) { function O(e) {
return l.isPrototypeOf(e) && e !== l ? e : l; return p.isPrototypeOf(e) && e !== p ? e : p;
} }
// src/dom.js // src/dom.js
var b = "html"; var m = "html";
function q(e) { function z(e) {
return b = e === "svg" ? "http://www.w3.org/2000/svg" : e, { return m = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(t) { append(t) {
return b = "html", t; return m = "html", t;
} }
}; };
} }
function z(e, t, ...o) { function I(e, t, ...n) {
let n = v(this), u; let r = O(this), i;
if (e === "<>") { if (e === "<>") {
if (n.isReactiveAtrribute(t)) if (r.isReactiveAtrribute(t))
return n.reactiveElement(t, ...o); return r.reactiveElement(t, ...n);
u = document.createDocumentFragment(); i = document.createDocumentFragment();
} }
switch (n.isTextContent(t) && (t = { textContent: t }), !0) { switch (r.isTextContent(t) && (t = { textContent: t }), !0) {
case typeof e == "function": case typeof e == "function":
u = e(t || void 0); i = e(t || void 0);
break; break;
case e === "#text": case e === "#text":
u = E(document.createTextNode(""), t); i = C(document.createTextNode(""), t);
break; break;
case b !== "html": case m !== "html":
u = E(document.createElementNS(b, e), t); i = C(document.createElementNS(m, e), t);
break; break;
default: case !i:
u = E(document.createElement(e), t); i = C(document.createElement(e), t);
} }
return o.forEach((d) => d(u)), u; return n.forEach((d) => d(i)), i;
} }
function E(e, ...t) { var w = /* @__PURE__ */ new Map();
let o = v(this); function C(e, ...t) {
let n = O(this);
if (!t.length) if (!t.length)
return e; return e;
let n = e instanceof SVGElement, u = (n ? L : A).bind(null, e, "Attribute"); let r = e instanceof SVGElement, i = (r ? S : R).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function d([i, f]) { return Object.entries(Object.assign({}, ...t)).forEach(function d([u, f]) {
if (o.isReactiveAtrribute(f, i) && (f = o.processReactiveAttribute(el, i, f, d)), i[0] === "=") n.isReactiveAtrribute(f, u) && (f = n.processReactiveAttribute(el, u, f, d));
return u(i.slice(1), f); let [l] = u;
if (i[0] === ".") if (l === "=")
return w(e, i.slice(1), f); return i(u.slice(1), f);
if (l === ".")
return j(e, u.slice(1), f);
if (typeof f == "object") if (typeof f == "object")
switch (i) { switch (u) {
case "style": case "style":
return g(f, A.bind(null, e.style, "Property")); return b(f, R.bind(null, e.style, "Property"));
case "dataset": case "dataset":
return g(f, w.bind(null, e.dataset)); return b(f, j.bind(null, e.dataset));
case "ariaset": case "ariaset":
return g(f, (p, h) => u("aria-" + p, h)); return b(f, (h, g) => i("aria-" + h, g));
case "classList": case "classList":
return N(e, f); return L(e, f);
default: default:
return Reflect.set(e, i, f); return Reflect.set(e, u, f);
} }
if (/(aria|data)([A-Z])/.test(i)) if (/(aria|data)([A-Z])/.test(u))
return i = i.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), u(i, f); return u = u.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(u, f);
switch (i) { switch (u) {
case "href":
return u(i, f);
case "xlink:href": case "xlink:href":
return u(i, f, "http://www.w3.org/1999/xlink"); return i(u, f, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
if (!n) if (!r)
break; break;
return e.appendChild(document.createTextNode(f)); return e.appendChild(document.createTextNode(f));
} }
return i in e && !n ? w(e, i, f) : u(i, f); return P(e, u) ? j(e, u, f) : i(u, f);
}), e; }), e;
} }
function N(e, t) { function L(e, t) {
return typeof t != "object" || g( return typeof t != "object" || b(
t, t,
(o, n) => e.classList.toggle(o, n === -1 ? void 0 : !!n) (n, r) => e.classList.toggle(n, r === -1 ? void 0 : !!r)
), e; ), e;
} }
function M(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 g(e, t) { function P(e, t) {
return Object.entries(e).forEach(([o, n]) => t(o, n)); let n = e.nodeName + "," + t;
if (w.has(n))
return w.get(n);
let r = A(e, t), i = !x(r.set);
return w.set(n, i), i;
} }
function O(e) { function A(e, t) {
if (e = Object.getPrototypeOf(e), !e)
return {};
let n = Object.getOwnPropertyDescriptor(e, t);
return n || A(e, t);
}
function b(e, t) {
return Object.entries(e).forEach(([n, r]) => t(n, r));
}
function x(e) {
return typeof e > "u"; return typeof e > "u";
} }
function A(e, t, o, n) { function R(e, t, n, r) {
return e[(O(n) ? "remove" : "set") + t](o, n); return e[(x(r) ? "remove" : "set") + t](n, r);
} }
function L(e, t, o, n, u = null) { function S(e, t, n, r, i = null) {
return e[(O(n) ? "remove" : "set") + t + "NS"](u, o, n); return e[(x(r) ? "remove" : "set") + t + "NS"](i, n, r);
} }
function w(e, t, o) { function j(e, t, n) {
return Reflect[O(o) ? "deleteProperty" : "set"](e, t, o); return Reflect[x(n) ? "deleteProperty" : "set"](e, t, n);
} }
// src/events.js // src/events.js
function j(e, t, o) { function N(e, t, n) {
return (n) => (n.addEventListener(e, t, o), n); return (r) => (r.addEventListener(e, t, n), r);
} }
var m = D(); var v = T();
j.connected = function(e, t) { N.connected = function(e, t) {
return function(n) { return function(r) {
m.onConnected(n, e), t && t.signal && t.signal.addEventListener("abort", () => m.offConnected(n, e)); v.onConnected(r, e), t && t.signal && t.signal.addEventListener("abort", () => v.offConnected(r, e));
}; };
}; };
j.disconnected = function(e, t) { N.disconnected = function(e, t) {
return function(n) { return function(r) {
m.onDisconnected(n, e), t && t.signal && t.signal.addEventListener("abort", () => m.offDisconnected(n, e)); v.onDisconnected(r, e), t && t.signal && t.signal.addEventListener("abort", () => v.offDisconnected(r, e));
}; };
}; };
function D() { function T() {
let e = /* @__PURE__ */ new Map(), t = !1, o = new MutationObserver(function(r) { let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(o) {
for (let c of r) for (let c of o)
if (c.type === "childList") { if (c.type === "childList") {
if (h(c.addedNodes, !0)) { if (h(c.addedNodes, !0)) {
i(); u();
continue; continue;
} }
C(c.removedNodes, !0) && i(); g(c.removedNodes, !0) && u();
} }
}); });
return { return {
onConnected(r, c) { onConnected(o, c) {
d(), u(r).connected.push(c); d(), i(o).connected.push(c);
}, },
offConnected(r, c) { offConnected(o, c) {
if (!e.has(r)) if (!e.has(o))
return; return;
let s = e.get(r), a = s.connected; let s = e.get(o), a = s.connected;
a.splice(a.indexOf(c), 1), n(r, s); a.splice(a.indexOf(c), 1), r(o, s);
}, },
onDisconnected(r, c) { onDisconnected(o, c) {
d(), u(r).disconnected.push(c); d(), i(o).disconnected.push(c);
}, },
offDisconnected(r, c) { offDisconnected(o, c) {
if (!e.has(r)) if (!e.has(o))
return; return;
let s = e.get(r), a = s.disconnected; let s = e.get(o), a = s.disconnected;
a.splice(a.indexOf(c), 1), n(r, s); a.splice(a.indexOf(c), 1), r(o, s);
} }
}; };
function n(r, c) { function r(o, c) {
c.connected.length || c.disconnect.length || (e.delete(r), i()); c.connected.length || c.disconnect.length || (e.delete(o), u());
} }
function u(r) { function i(o) {
if (e.has(r)) if (e.has(o))
return e.get(r); return e.get(o);
let c = { connected: [], disconnected: [] }; let c = { connected: [], disconnected: [] };
return e.set(r, c), c; return e.set(o, c), c;
} }
function d() { function d() {
t || (t = !0, o.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
} }
function i() { function u() {
!t || e.size || (t = !1, o.disconnect()); !t || e.size || (t = !1, n.disconnect());
} }
function f() { function f() {
return new Promise(function(r) { return new Promise(function(o) {
(requestIdleCallback || requestAnimationFrame)(r); (requestIdleCallback || requestAnimationFrame)(o);
}); });
} }
async function p(r) { async function l(o) {
e.size > 30 && await f(); e.size > 30 && await f();
let c = []; let c = [];
if (!(r instanceof Node)) if (!(o instanceof Node))
return c; return c;
for (let s of e.keys()) for (let s of e.keys())
s === r || !(s instanceof Node) || r.contains(s) && c.push(s); s === o || !(s instanceof Node) || o.contains(s) && c.push(s);
return c; return c;
} }
function h(r, c) { function h(o, c) {
for (let s of r) { for (let s of o) {
if (c && p(s).then(h), !e.has(s)) if (c && l(s).then(h), !e.has(s))
return !1; return !1;
let a = e.get(s); let a = e.get(s);
return a.connected.forEach((x) => x(s)), a.connected.length = 0, a.disconnected.length || e.delete(s), !0; return a.connected.forEach((E) => E(s)), a.connected.length = 0, a.disconnected.length || e.delete(s), !0;
} }
} }
function C(r, c) { function g(o, c) {
for (let s of r) { for (let s of o) {
if (c && p(s).then(C), !e.has(s)) if (c && l(s).then(g), !e.has(s))
return !1; return !1;
let a = e.get(s); let a = e.get(s);
return a.disconnected.forEach((x) => x(s)), a.connected.length = 0, a.disconnected.length = 0, e.delete(s), !0; return a.disconnected.forEach((E) => E(s)), a.connected.length = 0, a.disconnected.length = 0, e.delete(s), !0;
} }
} }
} }
@ -218,20 +232,20 @@
// index.js // index.js
[HTMLElement, DocumentFragment].forEach((e) => { [HTMLElement, DocumentFragment].forEach((e) => {
let { append: t } = e.prototype; let { append: t } = e.prototype;
e.prototype.append = function(...o) { e.prototype.append = function(...n) {
return t.apply(this, o), this; return t.apply(this, n), this;
}; };
}); });
globalThis.dde= { globalThis.dde= {
assign: E, assign: C,
classListDeclartive: N, classListDeclartive: L,
createElement: z, createElement: I,
el: z, el: I,
empty: M, empty: Z,
namespace: q, namespace: z,
on: j, on: N,
registerReactivity: y registerReactivity: D
}; };
})(); })();

View File

@ -19,24 +19,24 @@ var m = {
return document.createDocumentFragment(); return document.createDocumentFragment();
} }
}; };
function R(e, t = !0) { function A(e, t = !0) {
return t ? Object.assign(m, e) : (Object.setPrototypeOf(e, m), e); return t ? Object.assign(m, e) : (Object.setPrototypeOf(e, m), e);
} }
function A(e) { function C(e) {
return m.isPrototypeOf(e) && e !== m ? e : m; return m.isPrototypeOf(e) && e !== m ? e : m;
} }
// src/dom.js // src/dom.js
var E = "html"; var w = "html";
function K(e) { function Y(e) {
return E = e === "svg" ? "http://www.w3.org/2000/svg" : e, { return w = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(t) { append(t) {
return E = "html", t; return w = "html", t;
} }
}; };
} }
function Q(e, t, ...n) { function ee(e, t, ...n) {
let r = A(this), o; let r = C(this), o;
if (e === "<>") { if (e === "<>") {
if (r.isReactiveAtrribute(t)) if (r.isReactiveAtrribute(t))
return r.reactiveElement(t, ...n); return r.reactiveElement(t, ...n);
@ -47,103 +47,117 @@ function Q(e, t, ...n) {
o = e(t || void 0); o = e(t || void 0);
break; break;
case e === "#text": case e === "#text":
o = C(document.createTextNode(""), t); o = N(document.createTextNode(""), t);
break; break;
case E !== "html": case w !== "html":
o = C(document.createElementNS(E, e), t); o = N(document.createElementNS(w, e), t);
break; break;
default: case !o:
o = C(document.createElement(e), t); o = N(document.createElement(e), t);
} }
return n.forEach((l) => l(o)), o; return n.forEach((l) => l(o)), o;
} }
function C(e, ...t) { var S = /* @__PURE__ */ new Map();
let n = A(this); function N(e, ...t) {
let n = C(this);
if (!t.length) if (!t.length)
return e; return e;
let r = e instanceof SVGElement, o = (r ? z : D).bind(null, e, "Attribute"); let r = e instanceof SVGElement, o = (r ? I : _).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function l([s, f]) { return Object.entries(Object.assign({}, ...t)).forEach(function l([f, u]) {
if (n.isReactiveAtrribute(f, s) && (f = n.processReactiveAttribute(el, s, f, l)), s[0] === "=") n.isReactiveAtrribute(u, f) && (u = n.processReactiveAttribute(el, f, u, l));
return o(s.slice(1), f); let [p] = f;
if (s[0] === ".") if (p === "=")
return S(e, s.slice(1), f); return o(f.slice(1), u);
if (typeof f == "object") if (p === ".")
switch (s) { return L(e, f.slice(1), u);
if (typeof u == "object")
switch (f) {
case "style": case "style":
return v(f, D.bind(null, e.style, "Property")); return E(u, _.bind(null, e.style, "Property"));
case "dataset": case "dataset":
return v(f, S.bind(null, e.dataset)); return E(u, L.bind(null, e.dataset));
case "ariaset": case "ariaset":
return v(f, (p, b) => o("aria-" + p, b)); return E(u, (x, v) => o("aria-" + x, v));
case "classList": case "classList":
return q(e, f); return q(e, u);
default: default:
return Reflect.set(e, s, f); return Reflect.set(e, f, u);
} }
if (/(aria|data)([A-Z])/.test(s)) if (/(aria|data)([A-Z])/.test(f))
return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(s, f); return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(f, u);
switch (s) { switch (f) {
case "href":
return o(s, f);
case "xlink:href": case "xlink:href":
return o(s, f, "http://www.w3.org/1999/xlink"); return o(f, u, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
if (!r) if (!r)
break; break;
return e.appendChild(document.createTextNode(f)); return e.appendChild(document.createTextNode(u));
} }
return s in e && !r ? S(e, s, f) : o(s, f); return z(e, f) ? L(e, f, u) : o(f, u);
}), e; }), e;
} }
function q(e, t) { function q(e, t) {
return typeof t != "object" || v( return typeof t != "object" || E(
t, t,
(n, r) => e.classList.toggle(n, r === -1 ? void 0 : !!r) (n, r) => e.classList.toggle(n, r === -1 ? void 0 : !!r)
), e; ), e;
} }
function X(e) { function te(e) {
return Array.from(e.children).forEach((t) => t.remove()), e; return Array.from(e.children).forEach((t) => t.remove()), e;
} }
function v(e, t) { function z(e, t) {
let n = e.nodeName + "," + t;
if (S.has(n))
return S.get(n);
let r = D(e, t), o = !y(r.set);
return S.set(n, o), o;
}
function D(e, t) {
if (e = Object.getPrototypeOf(e), !e)
return {};
let n = Object.getOwnPropertyDescriptor(e, t);
return n || D(e, t);
}
function E(e, t) {
return Object.entries(e).forEach(([n, r]) => t(n, r)); return Object.entries(e).forEach(([n, r]) => t(n, r));
} }
function j(e) { function y(e) {
return typeof e > "u"; return typeof e > "u";
} }
function D(e, t, n, r) { function _(e, t, n, r) {
return e[(j(r) ? "remove" : "set") + t](n, r); return e[(y(r) ? "remove" : "set") + t](n, r);
} }
function z(e, t, n, r, o = null) { function I(e, t, n, r, o = null) {
return e[(j(r) ? "remove" : "set") + t + "NS"](o, n, r); return e[(y(r) ? "remove" : "set") + t + "NS"](o, n, r);
} }
function S(e, t, n) { function L(e, t, n) {
return Reflect[j(n) ? "deleteProperty" : "set"](e, t, n); return Reflect[y(n) ? "deleteProperty" : "set"](e, t, n);
} }
// src/events.js // src/events.js
function _(e, t, n) { function T(e, t, n) {
return (r) => (r.addEventListener(e, t, n), r); return (r) => (r.addEventListener(e, t, n), r);
} }
var w = M(); var O = W();
_.connected = function(e, t) { T.connected = function(e, t) {
return function(r) { return function(r) {
w.onConnected(r, e), t && t.signal && t.signal.addEventListener("abort", () => w.offConnected(r, e)); O.onConnected(r, e), t && t.signal && t.signal.addEventListener("abort", () => O.offConnected(r, e));
}; };
}; };
_.disconnected = function(e, t) { T.disconnected = function(e, t) {
return function(r) { return function(r) {
w.onDisconnected(r, e), t && t.signal && t.signal.addEventListener("abort", () => w.offDisconnected(r, e)); O.onDisconnected(r, e), t && t.signal && t.signal.addEventListener("abort", () => O.offDisconnected(r, e));
}; };
}; };
function M() { function W() {
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) { let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) {
for (let i of c) for (let i of c)
if (i.type === "childList") { if (i.type === "childList") {
if (b(i.addedNodes, !0)) { if (x(i.addedNodes, !0)) {
s(); f();
continue; continue;
} }
N(i.removedNodes, !0) && s(); v(i.removedNodes, !0) && f();
} }
}); });
return { return {
@ -153,8 +167,8 @@ function M() {
offConnected(c, i) { offConnected(c, i) {
if (!e.has(c)) if (!e.has(c))
return; return;
let u = e.get(c), a = u.connected; let s = e.get(c), a = s.connected;
a.splice(a.indexOf(i), 1), r(c, u); a.splice(a.indexOf(i), 1), r(c, s);
}, },
onDisconnected(c, i) { onDisconnected(c, i) {
l(), o(c).disconnected.push(i); l(), o(c).disconnected.push(i);
@ -162,12 +176,12 @@ function M() {
offDisconnected(c, i) { offDisconnected(c, i) {
if (!e.has(c)) if (!e.has(c))
return; return;
let u = e.get(c), a = u.disconnected; let s = e.get(c), a = s.disconnected;
a.splice(a.indexOf(i), 1), r(c, u); a.splice(a.indexOf(i), 1), r(c, s);
} }
}; };
function r(c, i) { function r(c, i) {
i.connected.length || i.disconnect.length || (e.delete(c), s()); i.connected.length || i.disconnect.length || (e.delete(c), f());
} }
function o(c) { function o(c) {
if (e.has(c)) if (e.has(c))
@ -178,37 +192,37 @@ function M() {
function l() { function l() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
} }
function s() { function f() {
!t || e.size || (t = !1, n.disconnect()); !t || e.size || (t = !1, n.disconnect());
} }
function f() { function u() {
return new Promise(function(c) { return new Promise(function(c) {
(requestIdleCallback || requestAnimationFrame)(c); (requestIdleCallback || requestAnimationFrame)(c);
}); });
} }
async function p(c) { async function p(c) {
e.size > 30 && await f(); e.size > 30 && await u();
let i = []; let i = [];
if (!(c instanceof Node)) if (!(c instanceof Node))
return i; return i;
for (let u of e.keys()) for (let s of e.keys())
u === c || !(u instanceof Node) || c.contains(u) && i.push(u); s === c || !(s instanceof Node) || c.contains(s) && i.push(s);
return i; return i;
} }
function b(c, i) { function x(c, i) {
for (let u of c) { for (let s of c) {
if (i && p(u).then(b), !e.has(u)) if (i && p(s).then(x), !e.has(s))
return !1; return !1;
let a = e.get(u); let a = e.get(s);
return a.connected.forEach((O) => O(u)), a.connected.length = 0, a.disconnected.length || e.delete(u), !0; return a.connected.forEach((j) => j(s)), a.connected.length = 0, a.disconnected.length || e.delete(s), !0;
} }
} }
function N(c, i) { function v(c, i) {
for (let u of c) { for (let s of c) {
if (i && p(u).then(N), !e.has(u)) if (i && p(s).then(v), !e.has(s))
return !1; return !1;
let a = e.get(u); let a = e.get(s);
return a.disconnected.forEach((O) => O(u)), a.connected.length = 0, a.disconnected.length = 0, e.delete(u), !0; return a.disconnected.forEach((j) => j(s)), a.connected.length = 0, a.disconnected.length = 0, e.delete(s), !0;
} }
} }
} }
@ -223,23 +237,23 @@ function M() {
// src/signals-lib.js // src/signals-lib.js
var d = Symbol.for("signal"); var d = Symbol.for("signal");
function x(e) { function b(e) {
try { try {
return Reflect.has(e, d); return Reflect.has(e, d);
} catch { } catch {
return !1; return !1;
} }
} }
function y(e, t) { function R(e, t) {
if (typeof e != "function") if (typeof e != "function")
return P(e, t); return F(e, t);
if (x(e)) if (b(e))
return e; return e;
let n = P(); let n = F();
return F(() => n(e())), n; return M(() => n(e())), n;
} }
y.action = function(e, t, ...n) { R.action = function(e, t, ...n) {
if (!x(e)) if (!b(e))
throw new Error(`'${e}' is not a signal!`); throw new Error(`'${e}' is not a signal!`);
let r = e[d], { actions: o } = r; let r = e[d], { actions: o } = r;
if (!o || !Reflect.has(o, t)) if (!o || !Reflect.has(o, t))
@ -248,102 +262,102 @@ y.action = function(e, t, ...n) {
return Reflect.deleteProperty(r, "skip"); return Reflect.deleteProperty(r, "skip");
r.listeners.forEach((l) => l(r.value)); r.listeners.forEach((l) => l(r.value));
}; };
y.on = function e(t, n, r) { R.on = function e(t, n, r) {
if (Array.isArray(t)) if (Array.isArray(t))
return t.forEach((o) => e(o, n, r)); return t.forEach((o) => e(o, n, r));
L(t, n), r && r.signal && r.signal.addEventListener("abort", () => $(t, n)); P(t, n), r && r.signal && r.signal.addEventListener("abort", () => k(t, n));
}; };
y.clear = function(...e) { R.clear = function(...e) {
for (let t of e) for (let t of e)
t[d].listeners.clear(), Reflect.deleteProperty(t, d); t[d].listeners.clear(), Reflect.deleteProperty(t, d);
}; };
var T = { var $ = {
isReactiveAtrribute(e, t) { isReactiveAtrribute(e, t) {
return x(e); return b(e);
}, },
isTextContent(e) { isTextContent(e) {
return h(e) === "string" || x(e) && h(G(e)) === "string"; return h(e) === "string" || b(e) && h(V(e)) === "string";
}, },
processReactiveAttribute(e, t, n, r) { processReactiveAttribute(e, t, n, r) {
return L(n, (o) => r([t, o])), n(); return P(n, (o) => r([t, o])), n();
}, },
reactiveElement(e, t) { reactiveElement(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 l = (s) => { let l = (f) => {
if (!n.parentNode || !r.parentNode) if (!n.parentNode || !r.parentNode)
return $(e, l); return k(e, l);
let f = t(s); let u = t(f);
Array.isArray(f) || (f = [f]); Array.isArray(u) || (u = [u]);
let p = n; let p = n;
for (; (p = n.nextSibling) !== r; ) for (; (p = n.nextSibling) !== r; )
p.remove(); p.remove();
n.after(...f); n.after(...u);
}; };
return L(e, l), l(e()), o; return P(e, l), l(e()), o;
} }
}; };
function P(e, t) { function F(e, t) {
let n = (...r) => r.length ? B(n, r[0]) : k(n); let n = (...r) => r.length ? U(n, r[0]) : H(n);
return W(n, e, t); return B(n, e, t);
} }
var I = Object.assign(/* @__PURE__ */ Object.create(null), { var Z = Object.assign(/* @__PURE__ */ Object.create(null), {
stopPropagation() { stopPropagation() {
this.skip = !0; this.skip = !0;
} }
}); });
function W(e, t, n) { function B(e, t, n) {
return h(n) !== "[object Object]" && (n = {}), e[d] = { return h(n) !== "[object Object]" && (n = {}), e[d] = {
value: t, value: t,
actions: n, actions: n,
listeners: /* @__PURE__ */ new Set() listeners: /* @__PURE__ */ new Set()
}, Object.setPrototypeOf(e[d], I), e; }, Object.setPrototypeOf(e[d], Z), e;
} }
var g = []; var g = [];
function F(e) { function M(e) {
let t = function() { let t = function() {
g.push(t), e(), g.pop(); g.push(t), e(), g.pop();
}; };
g.push(t), e(), g.pop(); g.push(t), e(), g.pop();
} }
function Z() { function G() {
return g[g.length - 1]; return g[g.length - 1];
} }
function k(e) { function H(e) {
if (!e[d]) if (!e[d])
return; return;
let { value: t, listeners: n } = e[d], r = Z(); let { value: t, listeners: n } = e[d], r = G();
return r && n.add(r), t; return r && n.add(r), t;
} }
function B(e, t) { function U(e, t) {
if (!e[d]) if (!e[d])
return; return;
let n = e[d]; let n = e[d];
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 G(e) { function V(e) {
return e[d].value; return e[d].value;
} }
function L(e, t) { function P(e, t) {
return e[d].listeners.add(t); return e[d].listeners.add(t);
} }
function $(e, t) { function k(e, t) {
return e[d].listeners.delete(t); return e[d].listeners.delete(t);
} }
// src/signals.js // src/signals.js
R(T); A($);
export { export {
y as S, R as S,
C as assign, N as assign,
q as classListDeclartive, q as classListDeclartive,
Q as createElement, ee as createElement,
Q as el, ee as el,
X as empty, te as empty,
x as isSignal, b as isSignal,
K as namespace, Y as namespace,
_ as on, T as on,
R as registerReactivity, A as registerReactivity,
F as watch M as watch
}; };

250
dist/esm.js vendored
View File

@ -1,214 +1,228 @@
// src/helpers.js // src/helpers.js
function R(e) { function y(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);
} }
// src/signals-common.js // src/signals-common.js
var l = { var p = {
isReactiveAtrribute(e, t) { isReactiveAtrribute(e, t) {
return !1; return !1;
}, },
isTextContent(e) { isTextContent(e) {
return R(e) !== "[object Object]"; return y(e) !== "[object Object]";
}, },
processReactiveAttribute(e, t, o, n) { processReactiveAttribute(e, t, n, r) {
return !1; return !1;
}, },
reactiveElement(e, ...t) { reactiveElement(e, ...t) {
return document.createDocumentFragment(); return document.createDocumentFragment();
} }
}; };
function y(e, t = !0) { function D(e, t = !0) {
return t ? Object.assign(l, e) : (Object.setPrototypeOf(e, l), e); return t ? Object.assign(p, e) : (Object.setPrototypeOf(e, p), e);
} }
function v(e) { function O(e) {
return l.isPrototypeOf(e) && e !== l ? e : l; return p.isPrototypeOf(e) && e !== p ? e : p;
} }
// src/dom.js // src/dom.js
var b = "html"; var m = "html";
function q(e) { function z(e) {
return b = e === "svg" ? "http://www.w3.org/2000/svg" : e, { return m = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(t) { append(t) {
return b = "html", t; return m = "html", t;
} }
}; };
} }
function z(e, t, ...o) { function I(e, t, ...n) {
let n = v(this), u; let r = O(this), i;
if (e === "<>") { if (e === "<>") {
if (n.isReactiveAtrribute(t)) if (r.isReactiveAtrribute(t))
return n.reactiveElement(t, ...o); return r.reactiveElement(t, ...n);
u = document.createDocumentFragment(); i = document.createDocumentFragment();
} }
switch (n.isTextContent(t) && (t = { textContent: t }), !0) { switch (r.isTextContent(t) && (t = { textContent: t }), !0) {
case typeof e == "function": case typeof e == "function":
u = e(t || void 0); i = e(t || void 0);
break; break;
case e === "#text": case e === "#text":
u = E(document.createTextNode(""), t); i = C(document.createTextNode(""), t);
break; break;
case b !== "html": case m !== "html":
u = E(document.createElementNS(b, e), t); i = C(document.createElementNS(m, e), t);
break; break;
default: case !i:
u = E(document.createElement(e), t); i = C(document.createElement(e), t);
} }
return o.forEach((d) => d(u)), u; return n.forEach((d) => d(i)), i;
} }
function E(e, ...t) { var w = /* @__PURE__ */ new Map();
let o = v(this); function C(e, ...t) {
let n = O(this);
if (!t.length) if (!t.length)
return e; return e;
let n = e instanceof SVGElement, u = (n ? L : A).bind(null, e, "Attribute"); let r = e instanceof SVGElement, i = (r ? S : R).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function d([i, f]) { return Object.entries(Object.assign({}, ...t)).forEach(function d([u, f]) {
if (o.isReactiveAtrribute(f, i) && (f = o.processReactiveAttribute(el, i, f, d)), i[0] === "=") n.isReactiveAtrribute(f, u) && (f = n.processReactiveAttribute(el, u, f, d));
return u(i.slice(1), f); let [l] = u;
if (i[0] === ".") if (l === "=")
return w(e, i.slice(1), f); return i(u.slice(1), f);
if (l === ".")
return j(e, u.slice(1), f);
if (typeof f == "object") if (typeof f == "object")
switch (i) { switch (u) {
case "style": case "style":
return g(f, A.bind(null, e.style, "Property")); return b(f, R.bind(null, e.style, "Property"));
case "dataset": case "dataset":
return g(f, w.bind(null, e.dataset)); return b(f, j.bind(null, e.dataset));
case "ariaset": case "ariaset":
return g(f, (p, h) => u("aria-" + p, h)); return b(f, (h, g) => i("aria-" + h, g));
case "classList": case "classList":
return N(e, f); return L(e, f);
default: default:
return Reflect.set(e, i, f); return Reflect.set(e, u, f);
} }
if (/(aria|data)([A-Z])/.test(i)) if (/(aria|data)([A-Z])/.test(u))
return i = i.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), u(i, f); return u = u.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(u, f);
switch (i) { switch (u) {
case "href":
return u(i, f);
case "xlink:href": case "xlink:href":
return u(i, f, "http://www.w3.org/1999/xlink"); return i(u, f, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
if (!n) if (!r)
break; break;
return e.appendChild(document.createTextNode(f)); return e.appendChild(document.createTextNode(f));
} }
return i in e && !n ? w(e, i, f) : u(i, f); return P(e, u) ? j(e, u, f) : i(u, f);
}), e; }), e;
} }
function N(e, t) { function L(e, t) {
return typeof t != "object" || g( return typeof t != "object" || b(
t, t,
(o, n) => e.classList.toggle(o, n === -1 ? void 0 : !!n) (n, r) => e.classList.toggle(n, r === -1 ? void 0 : !!r)
), e; ), e;
} }
function M(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 g(e, t) { function P(e, t) {
return Object.entries(e).forEach(([o, n]) => t(o, n)); let n = e.nodeName + "," + t;
if (w.has(n))
return w.get(n);
let r = A(e, t), i = !x(r.set);
return w.set(n, i), i;
} }
function O(e) { function A(e, t) {
if (e = Object.getPrototypeOf(e), !e)
return {};
let n = Object.getOwnPropertyDescriptor(e, t);
return n || A(e, t);
}
function b(e, t) {
return Object.entries(e).forEach(([n, r]) => t(n, r));
}
function x(e) {
return typeof e > "u"; return typeof e > "u";
} }
function A(e, t, o, n) { function R(e, t, n, r) {
return e[(O(n) ? "remove" : "set") + t](o, n); return e[(x(r) ? "remove" : "set") + t](n, r);
} }
function L(e, t, o, n, u = null) { function S(e, t, n, r, i = null) {
return e[(O(n) ? "remove" : "set") + t + "NS"](u, o, n); return e[(x(r) ? "remove" : "set") + t + "NS"](i, n, r);
} }
function w(e, t, o) { function j(e, t, n) {
return Reflect[O(o) ? "deleteProperty" : "set"](e, t, o); return Reflect[x(n) ? "deleteProperty" : "set"](e, t, n);
} }
// src/events.js // src/events.js
function j(e, t, o) { function N(e, t, n) {
return (n) => (n.addEventListener(e, t, o), n); return (r) => (r.addEventListener(e, t, n), r);
} }
var m = D(); var v = T();
j.connected = function(e, t) { N.connected = function(e, t) {
return function(n) { return function(r) {
m.onConnected(n, e), t && t.signal && t.signal.addEventListener("abort", () => m.offConnected(n, e)); v.onConnected(r, e), t && t.signal && t.signal.addEventListener("abort", () => v.offConnected(r, e));
}; };
}; };
j.disconnected = function(e, t) { N.disconnected = function(e, t) {
return function(n) { return function(r) {
m.onDisconnected(n, e), t && t.signal && t.signal.addEventListener("abort", () => m.offDisconnected(n, e)); v.onDisconnected(r, e), t && t.signal && t.signal.addEventListener("abort", () => v.offDisconnected(r, e));
}; };
}; };
function D() { function T() {
let e = /* @__PURE__ */ new Map(), t = !1, o = new MutationObserver(function(r) { let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(o) {
for (let c of r) for (let c of o)
if (c.type === "childList") { if (c.type === "childList") {
if (h(c.addedNodes, !0)) { if (h(c.addedNodes, !0)) {
i(); u();
continue; continue;
} }
C(c.removedNodes, !0) && i(); g(c.removedNodes, !0) && u();
} }
}); });
return { return {
onConnected(r, c) { onConnected(o, c) {
d(), u(r).connected.push(c); d(), i(o).connected.push(c);
}, },
offConnected(r, c) { offConnected(o, c) {
if (!e.has(r)) if (!e.has(o))
return; return;
let s = e.get(r), a = s.connected; let s = e.get(o), a = s.connected;
a.splice(a.indexOf(c), 1), n(r, s); a.splice(a.indexOf(c), 1), r(o, s);
}, },
onDisconnected(r, c) { onDisconnected(o, c) {
d(), u(r).disconnected.push(c); d(), i(o).disconnected.push(c);
}, },
offDisconnected(r, c) { offDisconnected(o, c) {
if (!e.has(r)) if (!e.has(o))
return; return;
let s = e.get(r), a = s.disconnected; let s = e.get(o), a = s.disconnected;
a.splice(a.indexOf(c), 1), n(r, s); a.splice(a.indexOf(c), 1), r(o, s);
} }
}; };
function n(r, c) { function r(o, c) {
c.connected.length || c.disconnect.length || (e.delete(r), i()); c.connected.length || c.disconnect.length || (e.delete(o), u());
} }
function u(r) { function i(o) {
if (e.has(r)) if (e.has(o))
return e.get(r); return e.get(o);
let c = { connected: [], disconnected: [] }; let c = { connected: [], disconnected: [] };
return e.set(r, c), c; return e.set(o, c), c;
} }
function d() { function d() {
t || (t = !0, o.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
} }
function i() { function u() {
!t || e.size || (t = !1, o.disconnect()); !t || e.size || (t = !1, n.disconnect());
} }
function f() { function f() {
return new Promise(function(r) { return new Promise(function(o) {
(requestIdleCallback || requestAnimationFrame)(r); (requestIdleCallback || requestAnimationFrame)(o);
}); });
} }
async function p(r) { async function l(o) {
e.size > 30 && await f(); e.size > 30 && await f();
let c = []; let c = [];
if (!(r instanceof Node)) if (!(o instanceof Node))
return c; return c;
for (let s of e.keys()) for (let s of e.keys())
s === r || !(s instanceof Node) || r.contains(s) && c.push(s); s === o || !(s instanceof Node) || o.contains(s) && c.push(s);
return c; return c;
} }
function h(r, c) { function h(o, c) {
for (let s of r) { for (let s of o) {
if (c && p(s).then(h), !e.has(s)) if (c && l(s).then(h), !e.has(s))
return !1; return !1;
let a = e.get(s); let a = e.get(s);
return a.connected.forEach((x) => x(s)), a.connected.length = 0, a.disconnected.length || e.delete(s), !0; return a.connected.forEach((E) => E(s)), a.connected.length = 0, a.disconnected.length || e.delete(s), !0;
} }
} }
function C(r, c) { function g(o, c) {
for (let s of r) { for (let s of o) {
if (c && p(s).then(C), !e.has(s)) if (c && l(s).then(g), !e.has(s))
return !1; return !1;
let a = e.get(s); let a = e.get(s);
return a.disconnected.forEach((x) => x(s)), a.connected.length = 0, a.disconnected.length = 0, e.delete(s), !0; return a.disconnected.forEach((E) => E(s)), a.connected.length = 0, a.disconnected.length = 0, e.delete(s), !0;
} }
} }
} }
@ -216,17 +230,17 @@ function D() {
// index.js // index.js
[HTMLElement, DocumentFragment].forEach((e) => { [HTMLElement, DocumentFragment].forEach((e) => {
let { append: t } = e.prototype; let { append: t } = e.prototype;
e.prototype.append = function(...o) { e.prototype.append = function(...n) {
return t.apply(this, o), this; return t.apply(this, n), this;
}; };
}); });
export { export {
E as assign, C as assign,
N as classListDeclartive, L as classListDeclartive,
z as createElement, I as createElement,
z as el, I as el,
M as empty, Z as empty,
q as namespace, z as namespace,
j as on, N as on,
y as registerReactivity D as registerReactivity
}; };