1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2024-11-22 07:49:38 +01:00
This commit is contained in:
Jan Andrle 2023-09-11 18:32:05 +02:00
parent 4b0a7d4554
commit 1dd05518b8
Signed by: jaandrle
GPG Key ID: B3A25AED155AFFAB
4 changed files with 430 additions and 430 deletions

View File

@ -1,7 +1,7 @@
//deka-dom-el library is available via global namespace `dde` //deka-dom-el library is available via global namespace `dde`
(()=> { (()=> {
// src/helpers.js // src/helpers.js
function g(e) { function m(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);
} }
@ -17,10 +17,10 @@
// src/signals-common.js // src/signals-common.js
var b = { var b = {
isTextContent(e) { isTextContent(e) {
return g(e) !== "[object Object]"; return m(e) !== "[object Object]";
}, },
processReactiveAttribute(e, t, n, r) { processReactiveAttribute(e, t, r, n) {
return n; return r;
} }
}; };
function N(e, t = !0) { function N(e, t = !0) {
@ -31,19 +31,19 @@
} }
// src/dom.js // src/dom.js
var y = "html"; var O = "html";
function te(e) { function te(e) {
return y = e === "svg" ? "http://www.w3.org/2000/svg" : e, { return O = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(t) { append(t) {
return y = "html", t; return O = "html", t;
} }
}; };
} }
function ne(e, t, ...n) { function ne(e, t, ...r) {
let r = A(this), o; let n = A(this), o;
switch (r.isTextContent(t) && (t = { textContent: t }), !0) { switch (n.isTextContent(t) && (t = { textContent: t }), !0) {
case typeof e == "function": { case typeof e == "function": {
o = e(t || void 0, (s) => s ? (n.unshift(s), void 0) : o); o = e(t || void 0, (i) => i ? (r.unshift(i), void 0) : o);
break; break;
} }
case e === "#text": case e === "#text":
@ -52,126 +52,126 @@
case e === "<>": case e === "<>":
o = w(document.createDocumentFragment(), t); o = w(document.createDocumentFragment(), t);
break; break;
case y !== "html": case O !== "html":
o = w(document.createElementNS(y, e), t); o = w(document.createElementNS(O, e), t);
break; break;
case !o: case !o:
o = w(document.createElement(e), t); o = w(document.createElement(e), t);
} }
return n.forEach((a) => a(o)), o; return r.forEach((a) => a(o)), o;
} }
var x = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')); var x = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]'));
function w(e, ...t) { function w(e, ...t) {
let n = A(this); let r = A(this);
if (!t.length) if (!t.length)
return e; return e;
let r = e instanceof SVGElement, o = (r ? J : T).bind(null, e, "Attribute"); let n = e instanceof SVGElement, o = (n ? J : T).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function a([s, i]) { return Object.entries(Object.assign({}, ...t)).forEach(function a([i, s]) {
i = n.processReactiveAttribute(e, s, i, a); s = r.processReactiveAttribute(e, i, s, a);
let [h] = s; let [h] = i;
if (h === "=") if (h === "=")
return o(s.slice(1), i); return o(i.slice(1), s);
if (h === ".") if (h === ".")
return _(e, s.slice(1), i); return _(e, i.slice(1), s);
if (typeof i == "object") if (typeof s == "object")
switch (s) { switch (i) {
case "style": case "style":
return O(i, T.bind(null, e.style, "Property")); return y(s, T.bind(null, e.style, "Property"));
case "dataset": case "dataset":
return O(i, _.bind(null, e.dataset)); return y(s, _.bind(null, e.dataset));
case "ariaset": case "ariaset":
return O(i, (E, v) => o("aria-" + E, v)); return y(s, (E, v) => o("aria-" + E, v));
case "classList": case "classList":
return k(e, i); return $(e, s);
default: default:
return Reflect.set(e, s, i); return Reflect.set(e, i, s);
} }
if (/(aria|data)([A-Z])/.test(s)) if (/(aria|data)([A-Z])/.test(i))
return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(s, i); return i = i.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(i, s);
switch (s) { switch (i) {
case "href": case "href":
return o(s, i); return o(i, s);
case "xlink:href": case "xlink:href":
return o(s, i, "http://www.w3.org/1999/xlink"); return o(i, s, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
if (!r) if (!n)
break; break;
return e.appendChild(document.createTextNode(i)); return e.appendChild(document.createTextNode(s));
} }
return q(e, s) ? _(e, s, i) : o(s, i); return q(e, i) ? _(e, i, s) : o(i, s);
}), e; }), e;
} }
function k(e, t) { function $(e, t) {
return typeof t != "object" || O( return typeof t != "object" || y(
t, t,
(n, r) => e.classList.toggle(n, r === -1 ? void 0 : !!r) (r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n)
), e; ), e;
} }
function re(e) { function re(e) {
return Array.from(e.children).forEach((t) => t.remove()), e; return Array.from(e.children).forEach((t) => t.remove()), e;
} }
function q(e, t) { function q(e, t) {
let n = "HTMLElement," + t; let r = "HTMLElement," + t;
if (e instanceof HTMLElement && x.has(n)) if (e instanceof HTMLElement && x.has(r))
return x.get(n);
let r = e.nodeName + "," + t;
if (x.has(r))
return x.get(r); return x.get(r);
let [o, a, s] = M(e, t), i = !P(o.set); let n = e.nodeName + "," + t;
return (!i || a) && x.set(s === HTMLElement.prototype ? n : r, i), i; if (x.has(n))
return x.get(n);
let [o, a, i] = M(e, t), s = !P(o.set);
return (!s || a) && x.set(i === HTMLElement.prototype ? r : n, s), s;
} }
function M(e, t, n = 0) { function M(e, t, r = 0) {
if (e = Object.getPrototypeOf(e), !e) if (e = Object.getPrototypeOf(e), !e)
return [{}, n, e]; return [{}, r, e];
let r = Object.getOwnPropertyDescriptor(e, t); let n = Object.getOwnPropertyDescriptor(e, t);
return r ? [r, n, e] : M(e, t, n + 1); return n ? [n, r, e] : M(e, t, r + 1);
} }
function O(e, t) { function y(e, t) {
return Object.entries(e).forEach(([n, r]) => t(n, r)); return Object.entries(e).forEach(([r, n]) => t(r, n));
} }
function P(e) { function P(e) {
return typeof e > "u"; return typeof e > "u";
} }
function T(e, t, n, r) { function T(e, t, r, n) {
return e[(P(r) ? "remove" : "set") + t](n, r); return e[(P(n) ? "remove" : "set") + t](r, n);
} }
function J(e, t, n, r, o = null) { function J(e, t, r, n, o = null) {
return e[(P(r) ? "remove" : "set") + t + "NS"](o, n, r); return e[(P(n) ? "remove" : "set") + t + "NS"](o, r, n);
} }
function _(e, t, n) { function _(e, t, r) {
return Reflect.set(e, t, n); return Reflect.set(e, t, r);
} }
// src/events.js // src/events.js
function ce(e, t, ...n) { function ce(e, t, ...r) {
let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t);
return e.dispatchEvent(r); return e.dispatchEvent(n);
} }
function H(e, t, n) { function H(e, t, r) {
return function(o) { return function(o) {
return o.addEventListener(e, t, n), o; return o.addEventListener(e, t, r), o;
}; };
} }
var S = W(); var S = W();
H.connected = function(e, t) { H.connected = function(e, t) {
return function(r) { return function(n) {
return j(t && t.signal, () => S.offConnected(r, e)) && S.onConnected(r, e), r; return typeof n.connectedCallback == "function" ? (n.addEventListener("dde:connected", e, t), n) : (j(t && t.signal, () => S.offConnected(n, e)) && (n.isConnected ? e(new Event("dde:connected")) : S.onConnected(n, e)), n);
}; };
}; };
H.disconnected = function(e, t) { H.disconnected = function(e, t) {
return function(r) { return function(n) {
return j(t && t.signal, () => S.offDisconnected(r, e)) && S.onDisconnected(r, e), r; return typeof n.disconnectedCallback == "function" ? (n.addEventListener("dde:disconnected", e, t), n) : (j(t && t.signal, () => S.offDisconnected(n, e)) && S.onDisconnected(n, e), n);
}; };
}; };
function W() { function W() {
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) { let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(c) {
for (let f of c) for (let f of c)
if (f.type === "childList") { if (f.type === "childList") {
if (E(f.addedNodes, !0)) { if (E(f.addedNodes, !0)) {
s(); i();
continue; continue;
} }
v(f.removedNodes, !0) && s(); v(f.removedNodes, !0) && i();
} }
}); });
return { return {
@ -181,8 +181,8 @@
offConnected(c, f) { offConnected(c, f) {
if (!e.has(c)) if (!e.has(c))
return; return;
let u = e.get(c), l = u.connected; let u = e.get(c), p = u.connected;
l.splice(l.indexOf(f), 1), r(c, u); p.splice(p.indexOf(f), 1), n(c, u);
}, },
onDisconnected(c, f) { onDisconnected(c, f) {
a(), o(c).disconnected.push(f); a(), o(c).disconnected.push(f);
@ -190,12 +190,12 @@
offDisconnected(c, f) { offDisconnected(c, f) {
if (!e.has(c)) if (!e.has(c))
return; return;
let u = e.get(c), l = u.disconnected; let u = e.get(c), p = u.disconnected;
l.splice(l.indexOf(f), 1), r(c, u); p.splice(p.indexOf(f), 1), n(c, u);
} }
}; };
function r(c, f) { function n(c, f) {
f.connected.length || f.disconnected.length || (e.delete(c), s()); f.connected.length || f.disconnected.length || (e.delete(c), i());
} }
function o(c) { function o(c) {
if (e.has(c)) if (e.has(c))
@ -204,18 +204,18 @@
return e.set(c, f), f; return e.set(c, f), f;
} }
function a() { function a() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, r.observe(document.body, { childList: !0, subtree: !0 }));
}
function s() {
!t || e.size || (t = !1, n.disconnect());
} }
function i() { function i() {
!t || e.size || (t = !1, r.disconnect());
}
function s() {
return new Promise(function(c) { return new Promise(function(c) {
(requestIdleCallback || requestAnimationFrame)(c); (requestIdleCallback || requestAnimationFrame)(c);
}); });
} }
async function h(c) { async function h(c) {
e.size > 30 && await i(); e.size > 30 && await s();
let f = []; let f = [];
if (!(c instanceof Node)) if (!(c instanceof Node))
return f; return f;
@ -227,8 +227,8 @@
for (let u of c) { for (let u of c) {
if (f && h(u).then(E), !e.has(u)) if (f && h(u).then(E), !e.has(u))
continue; continue;
let l = e.get(u); let p = e.get(u);
return l.connected.forEach((L) => L(u)), l.connected.length = 0, l.disconnected.length || e.delete(u), !0; return p.connected.forEach((R) => R(u)), p.connected.length = 0, p.disconnected.length || e.delete(u), !0;
} }
return !1; return !1;
} }
@ -236,8 +236,8 @@
for (let u of c) { for (let u of c) {
if (f && h(u).then(v), !e.has(u)) if (f && h(u).then(v), !e.has(u))
continue; continue;
let l = e.get(u); let p = e.get(u);
return l.disconnected.forEach((L) => L(u)), l.connected.length = 0, l.disconnected.length = 0, e.delete(u), !0; return p.disconnected.forEach((R) => R(u)), p.connected.length = 0, p.disconnected.length = 0, e.delete(u), !0;
} }
return !1; return !1;
} }
@ -246,8 +246,8 @@
// 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(...n) { e.prototype.append = function(...r) {
return t.apply(this, n), this; return t.apply(this, r), this;
}; };
}); });
@ -260,111 +260,111 @@
return !1; return !1;
} }
} }
var p = /* @__PURE__ */ new WeakMap(); var l = /* @__PURE__ */ new WeakMap();
function m(e, t) { function g(e, t) {
if (typeof e != "function") if (typeof e != "function")
return z(e, t); return k(e, t);
if (C(e)) if (C(e))
return e; return e;
let n = z(""), r = () => n(e()); let r = k(""), n = () => r(e());
return p.set(r, /* @__PURE__ */ new Set([n])), Z(r), n; return l.set(n, /* @__PURE__ */ new Set([r])), Z(n), r;
} }
m.action = function(e, t, ...n) { g.action = function(e, t, ...r) {
let r = e[d], { actions: o } = r; let n = e[d], { actions: o } = n;
if (!o || !Reflect.has(o, t)) if (!o || !Reflect.has(o, t))
throw new Error(`'${e}' has no action with name '${t}'!`); throw new Error(`'${e}' has no action with name '${t}'!`);
if (o[t].apply(r, n), r.skip) if (o[t].apply(n, r), n.skip)
return Reflect.deleteProperty(r, "skip"); return Reflect.deleteProperty(n, "skip");
r.listeners.forEach((a) => a(r.value)); n.listeners.forEach((a) => a(n.value));
}; };
m.on = function e(t, n, r = {}) { g.on = function e(t, r, n = {}) {
let { signal: o } = r; let { signal: o } = n;
if (!(o && o.aborted)) { if (!(o && o.aborted)) {
if (Array.isArray(t)) if (Array.isArray(t))
return t.forEach((a) => e(a, n, r)); return t.forEach((a) => e(a, r, n));
D(t, n), o && o.addEventListener("abort", () => $(t, n)); D(t, r), o && o.addEventListener("abort", () => F(t, r));
} }
}; };
m.symbols = { g.symbols = {
signal: d, signal: d,
onclear: Symbol.for("Signal.onclear") onclear: Symbol.for("Signal.onclear")
}; };
m.clear = function(...e) { g.clear = function(...e) {
for (let n of e) { for (let r of e) {
Reflect.deleteProperty(n, "toJSON"); Reflect.deleteProperty(r, "toJSON");
let r = n[d], { onclear: o } = m.symbols; let n = r[d], { onclear: o } = g.symbols;
r.actions && r.actions[o] && r.actions[o].call(r), t(n, r), Reflect.deleteProperty(n, d); n.actions && n.actions[o] && n.actions[o].call(n), t(r, n), Reflect.deleteProperty(r, d);
} }
function t(n, r) { function t(r, n) {
r.listeners.forEach((o) => { n.listeners.forEach((o) => {
if (r.listeners.delete(o), !p.has(o)) if (n.listeners.delete(o), !l.has(o))
return; return;
let a = p.get(o); let a = l.get(o);
a.delete(n), !(a.size > 1) && (m.clear(...a), p.delete(o)); a.delete(r), !(a.size > 1) && (g.clear(...a), l.delete(o));
}); });
} }
}; };
m.el = function(e, t) { g.el = function(e, t) {
let n = document.createComment("<#reactive>"), r = document.createComment("</#reactive>"), o = document.createDocumentFragment(); let r = document.createComment("<#reactive>"), n = document.createComment("</#reactive>"), o = document.createDocumentFragment();
o.append(n, r); o.append(r, n);
let a = (s) => { let a = (i) => {
if (!n.parentNode || !r.parentNode) if (!r.parentNode || !n.parentNode)
return $(e, a); return F(e, a);
let i = t(s); let s = t(i);
Array.isArray(i) || (i = [i]); Array.isArray(s) || (s = [s]);
let h = n; let h = r;
for (; (h = n.nextSibling) !== r; ) for (; (h = r.nextSibling) !== n; )
h.remove(); h.remove();
n.after(...i); r.after(...s);
}; };
return D(e, a), a(e()), o; return D(e, a), a(e()), o;
}; };
var F = { var z = {
isTextContent(e) { isTextContent(e) {
return g(e) === "string" || C(e) && g(K(e)) === "string"; return m(e) === "string" || C(e) && m(K(e)) === "string";
}, },
processReactiveAttribute(e, t, n, r) { processReactiveAttribute(e, t, r, n) {
return C(n) ? (D(n, (o) => r([t, o])), n()) : n; return C(r) ? (D(r, (o) => n([t, o])), r()) : r;
} }
}; };
function z(e, t) { function k(e, t) {
let n = (...r) => r.length ? V(n, r[0]) : G(n); let r = (...n) => n.length ? V(r, n[0]) : G(r);
return U(n, e, t); return U(r, e, t);
} }
var I = Object.assign(/* @__PURE__ */ Object.create(null), { var I = Object.assign(/* @__PURE__ */ Object.create(null), {
stopPropagation() { stopPropagation() {
this.skip = !0; this.skip = !0;
} }
}); });
function U(e, t, n) { function U(e, t, r) {
return g(n) !== "[object Object]" && (n = {}), e[d] = { return m(r) !== "[object Object]" && (r = {}), e[d] = {
value: t, value: t,
actions: n, actions: r,
listeners: /* @__PURE__ */ new Set() listeners: /* @__PURE__ */ new Set()
}, e.toJSON = () => e(), Object.setPrototypeOf(e[d], I), e; }, e.toJSON = () => e(), Object.setPrototypeOf(e[d], I), e;
} }
var R = []; var L = [];
function Z(e) { function Z(e) {
let t = function() { let t = function() {
R.push(t), e(), R.pop(); L.push(t), e(), L.pop();
}; };
p.has(e) && (p.set(t, p.get(e)), p.delete(e)), t(); l.has(e) && (l.set(t, l.get(e)), l.delete(e)), t();
} }
function B() { function B() {
return R[R.length - 1]; return L[L.length - 1];
} }
function G(e) { function G(e) {
if (!e[d]) if (!e[d])
return; return;
let { value: t, listeners: n } = e[d], r = B(); let { value: t, listeners: r } = e[d], n = B();
return r && n.add(r), p.has(r) && p.get(r).add(e), t; return n && r.add(n), l.has(n) && l.get(n).add(e), t;
} }
function V(e, t) { function V(e, t) {
if (!e[d]) if (!e[d])
return; return;
let n = e[d]; let r = e[d];
if (n.value !== t) if (r.value !== t)
return n.value = t, n.listeners.forEach((r) => r(t)), t; return r.value = t, r.listeners.forEach((n) => n(t)), t;
} }
function K(e) { function K(e) {
return e[d].value; return e[d].value;
@ -373,18 +373,18 @@
if (e[d]) if (e[d])
return e[d].listeners.add(t); return e[d].listeners.add(t);
} }
function $(e, t) { function F(e, t) {
if (e[d]) if (e[d])
return e[d].listeners.delete(t); return e[d].listeners.delete(t);
} }
// src/signals.js // src/signals.js
N(F); N(z);
globalThis.dde= { globalThis.dde= {
S: m, S: g,
assign: w, assign: w,
classListDeclarative: k, classListDeclarative: $,
createElement: ne, createElement: ne,
dispatchEvent: ce, dispatchEvent: ce,
el: ne, el: ne,

138
dist/dde.js vendored
View File

@ -1,11 +1,11 @@
//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 j(e) { function N(e) {
let t = typeof e; let t = typeof e;
return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e); return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e);
} }
function w(e, t) { function O(e, t) {
if (!e || !(e instanceof AbortSignal)) if (!e || !(e instanceof AbortSignal))
return !0; return !0;
if (!e.aborted) if (!e.aborted)
@ -17,10 +17,10 @@
// src/signals-common.js // src/signals-common.js
var l = { var l = {
isTextContent(e) { isTextContent(e) {
return j(e) !== "[object Object]"; return N(e) !== "[object Object]";
}, },
processReactiveAttribute(e, t, n, r) { processReactiveAttribute(e, t, r, n) {
return n; return r;
} }
}; };
function D(e, t = !0) { function D(e, t = !0) {
@ -31,43 +31,43 @@
} }
// src/dom.js // src/dom.js
var m = "html"; var v = "html";
function F(e) { function F(e) {
return m = e === "svg" ? "http://www.w3.org/2000/svg" : e, { return v = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(t) { append(t) {
return m = "html", t; return v = "html", t;
} }
}; };
} }
function I(e, t, ...n) { function I(e, t, ...r) {
let r = C(this), c; let n = C(this), c;
switch (r.isTextContent(t) && (t = { textContent: t }), !0) { switch (n.isTextContent(t) && (t = { textContent: t }), !0) {
case typeof e == "function": { case typeof e == "function": {
c = e(t || void 0, (s) => s ? (n.unshift(s), void 0) : c); c = e(t || void 0, (s) => s ? (r.unshift(s), void 0) : c);
break; break;
} }
case e === "#text": case e === "#text":
c = x(document.createTextNode(""), t); c = E(document.createTextNode(""), t);
break; break;
case e === "<>": case e === "<>":
c = x(document.createDocumentFragment(), t); c = E(document.createDocumentFragment(), t);
break; break;
case m !== "html": case v !== "html":
c = x(document.createElementNS(m, e), t); c = E(document.createElementNS(v, e), t);
break; break;
case !c: case !c:
c = x(document.createElement(e), t); c = E(document.createElement(e), t);
} }
return n.forEach((a) => a(c)), c; return r.forEach((a) => a(c)), c;
} }
var h = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')); var h = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]'));
function x(e, ...t) { function E(e, ...t) {
let n = C(this); let r = C(this);
if (!t.length) if (!t.length)
return e; return e;
let r = e instanceof SVGElement, c = (r ? S : y).bind(null, e, "Attribute"); let n = e instanceof SVGElement, c = (n ? S : j).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function a([s, f]) { return Object.entries(Object.assign({}, ...t)).forEach(function a([s, f]) {
f = n.processReactiveAttribute(e, s, f, a); f = r.processReactiveAttribute(e, s, f, a);
let [p] = s; let [p] = s;
if (p === "=") if (p === "=")
return c(s.slice(1), f); return c(s.slice(1), f);
@ -76,11 +76,11 @@
if (typeof f == "object") if (typeof f == "object")
switch (s) { switch (s) {
case "style": case "style":
return E(f, y.bind(null, e.style, "Property")); return x(f, j.bind(null, e.style, "Property"));
case "dataset": case "dataset":
return E(f, L.bind(null, e.dataset)); return x(f, L.bind(null, e.dataset));
case "ariaset": case "ariaset":
return E(f, (g, b) => c("aria-" + g, b)); return x(f, (g, b) => c("aria-" + g, b));
case "classList": case "classList":
return R(e, f); return R(e, f);
default: default:
@ -94,7 +94,7 @@
case "xlink:href": case "xlink:href":
return c(s, f, "http://www.w3.org/1999/xlink"); return c(s, f, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
if (!r) if (!n)
break; break;
return e.appendChild(document.createTextNode(f)); return e.appendChild(document.createTextNode(f));
} }
@ -102,69 +102,69 @@
}), e; }), e;
} }
function R(e, t) { function R(e, t) {
return typeof t != "object" || E( return typeof t != "object" || x(
t, t,
(n, r) => e.classList.toggle(n, r === -1 ? void 0 : !!r) (r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n)
), e; ), e;
} }
function U(e) { function U(e) {
return Array.from(e.children).forEach((t) => t.remove()), e; return Array.from(e.children).forEach((t) => t.remove()), e;
} }
function M(e, t) { function M(e, t) {
let n = "HTMLElement," + t; let r = "HTMLElement," + t;
if (e instanceof HTMLElement && h.has(n)) if (e instanceof HTMLElement && h.has(r))
return h.get(n);
let r = e.nodeName + "," + t;
if (h.has(r))
return h.get(r); return h.get(r);
let [c, a, s] = A(e, t), f = !N(c.set); let n = e.nodeName + "," + t;
return (!f || a) && h.set(s === HTMLElement.prototype ? n : r, f), f; if (h.has(n))
return h.get(n);
let [c, a, s] = A(e, t), f = !y(c.set);
return (!f || a) && h.set(s === HTMLElement.prototype ? r : n, f), f;
} }
function A(e, t, n = 0) { function A(e, t, r = 0) {
if (e = Object.getPrototypeOf(e), !e) if (e = Object.getPrototypeOf(e), !e)
return [{}, n, e]; return [{}, r, e];
let r = Object.getOwnPropertyDescriptor(e, t); let n = Object.getOwnPropertyDescriptor(e, t);
return r ? [r, n, e] : A(e, t, n + 1); return n ? [n, r, e] : A(e, t, r + 1);
} }
function E(e, t) { function x(e, t) {
return Object.entries(e).forEach(([n, r]) => t(n, r)); return Object.entries(e).forEach(([r, n]) => t(r, n));
} }
function N(e) { function y(e) {
return typeof e > "u"; return typeof e > "u";
} }
function y(e, t, n, r) { function j(e, t, r, n) {
return e[(N(r) ? "remove" : "set") + t](n, r); return e[(y(n) ? "remove" : "set") + t](r, n);
} }
function S(e, t, n, r, c = null) { function S(e, t, r, n, c = null) {
return e[(N(r) ? "remove" : "set") + t + "NS"](c, n, r); return e[(y(n) ? "remove" : "set") + t + "NS"](c, r, n);
} }
function L(e, t, n) { function L(e, t, r) {
return Reflect.set(e, t, n); return Reflect.set(e, t, r);
} }
// src/events.js // src/events.js
function $(e, t, ...n) { function $(e, t, ...r) {
let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t);
return e.dispatchEvent(r); return e.dispatchEvent(n);
} }
function T(e, t, n) { function T(e, t, r) {
return function(c) { return function(c) {
return c.addEventListener(e, t, n), c; return c.addEventListener(e, t, r), c;
}; };
} }
var v = _(); var m = _();
T.connected = function(e, t) { T.connected = function(e, t) {
return function(r) { return function(n) {
return w(t && t.signal, () => v.offConnected(r, e)) && v.onConnected(r, e), r; return typeof n.connectedCallback == "function" ? (n.addEventListener("dde:connected", e, t), n) : (O(t && t.signal, () => m.offConnected(n, e)) && (n.isConnected ? e(new Event("dde:connected")) : m.onConnected(n, e)), n);
}; };
}; };
T.disconnected = function(e, t) { T.disconnected = function(e, t) {
return function(r) { return function(n) {
return w(t && t.signal, () => v.offDisconnected(r, e)) && v.onDisconnected(r, e), r; return typeof n.disconnectedCallback == "function" ? (n.addEventListener("dde:disconnected", e, t), n) : (O(t && t.signal, () => m.offDisconnected(n, e)) && m.onDisconnected(n, e), n);
}; };
}; };
function _() { function _() {
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(o) { let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(o) {
for (let i of o) for (let i of o)
if (i.type === "childList") { if (i.type === "childList") {
if (g(i.addedNodes, !0)) { if (g(i.addedNodes, !0)) {
@ -182,7 +182,7 @@
if (!e.has(o)) if (!e.has(o))
return; return;
let u = e.get(o), d = u.connected; let u = e.get(o), d = u.connected;
d.splice(d.indexOf(i), 1), r(o, u); d.splice(d.indexOf(i), 1), n(o, u);
}, },
onDisconnected(o, i) { onDisconnected(o, i) {
a(), c(o).disconnected.push(i); a(), c(o).disconnected.push(i);
@ -191,10 +191,10 @@
if (!e.has(o)) if (!e.has(o))
return; return;
let u = e.get(o), d = u.disconnected; let u = e.get(o), d = u.disconnected;
d.splice(d.indexOf(i), 1), r(o, u); d.splice(d.indexOf(i), 1), n(o, u);
} }
}; };
function r(o, i) { function n(o, i) {
i.connected.length || i.disconnected.length || (e.delete(o), s()); i.connected.length || i.disconnected.length || (e.delete(o), s());
} }
function c(o) { function c(o) {
@ -204,10 +204,10 @@
return e.set(o, i), i; return e.set(o, i), i;
} }
function a() { function a() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, r.observe(document.body, { childList: !0, subtree: !0 }));
} }
function s() { function s() {
!t || e.size || (t = !1, n.disconnect()); !t || e.size || (t = !1, r.disconnect());
} }
function f() { function f() {
return new Promise(function(o) { return new Promise(function(o) {
@ -228,7 +228,7 @@
if (i && p(u).then(g), !e.has(u)) if (i && p(u).then(g), !e.has(u))
continue; continue;
let d = e.get(u); let d = e.get(u);
return d.connected.forEach((O) => O(u)), d.connected.length = 0, d.disconnected.length || e.delete(u), !0; return d.connected.forEach((w) => w(u)), d.connected.length = 0, d.disconnected.length || e.delete(u), !0;
} }
return !1; return !1;
} }
@ -237,7 +237,7 @@
if (i && p(u).then(b), !e.has(u)) if (i && p(u).then(b), !e.has(u))
continue; continue;
let d = e.get(u); let d = e.get(u);
return d.disconnected.forEach((O) => O(u)), d.connected.length = 0, d.disconnected.length = 0, e.delete(u), !0; return d.disconnected.forEach((w) => w(u)), d.connected.length = 0, d.disconnected.length = 0, e.delete(u), !0;
} }
return !1; return !1;
} }
@ -246,13 +246,13 @@
// 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(...n) { e.prototype.append = function(...r) {
return t.apply(this, n), this; return t.apply(this, r), this;
}; };
}); });
globalThis.dde= { globalThis.dde= {
assign: x, assign: E,
classListDeclarative: R, classListDeclarative: R,
createElement: I, createElement: I,
dispatchEvent: $, dispatchEvent: $,

View File

@ -1,5 +1,5 @@
// src/helpers.js // src/helpers.js
function g(e) { function m(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);
} }
@ -15,10 +15,10 @@ function j(e, t) {
// src/signals-common.js // src/signals-common.js
var b = { var b = {
isTextContent(e) { isTextContent(e) {
return g(e) !== "[object Object]"; return m(e) !== "[object Object]";
}, },
processReactiveAttribute(e, t, n, r) { processReactiveAttribute(e, t, r, n) {
return n; return r;
} }
}; };
function N(e, t = !0) { function N(e, t = !0) {
@ -29,19 +29,19 @@ function A(e) {
} }
// src/dom.js // src/dom.js
var y = "html"; var O = "html";
function te(e) { function te(e) {
return y = e === "svg" ? "http://www.w3.org/2000/svg" : e, { return O = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(t) { append(t) {
return y = "html", t; return O = "html", t;
} }
}; };
} }
function ne(e, t, ...n) { function ne(e, t, ...r) {
let r = A(this), o; let n = A(this), o;
switch (r.isTextContent(t) && (t = { textContent: t }), !0) { switch (n.isTextContent(t) && (t = { textContent: t }), !0) {
case typeof e == "function": { case typeof e == "function": {
o = e(t || void 0, (s) => s ? (n.unshift(s), void 0) : o); o = e(t || void 0, (i) => i ? (r.unshift(i), void 0) : o);
break; break;
} }
case e === "#text": case e === "#text":
@ -50,126 +50,126 @@ function ne(e, t, ...n) {
case e === "<>": case e === "<>":
o = w(document.createDocumentFragment(), t); o = w(document.createDocumentFragment(), t);
break; break;
case y !== "html": case O !== "html":
o = w(document.createElementNS(y, e), t); o = w(document.createElementNS(O, e), t);
break; break;
case !o: case !o:
o = w(document.createElement(e), t); o = w(document.createElement(e), t);
} }
return n.forEach((a) => a(o)), o; return r.forEach((a) => a(o)), o;
} }
var x = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')); var x = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]'));
function w(e, ...t) { function w(e, ...t) {
let n = A(this); let r = A(this);
if (!t.length) if (!t.length)
return e; return e;
let r = e instanceof SVGElement, o = (r ? J : T).bind(null, e, "Attribute"); let n = e instanceof SVGElement, o = (n ? J : T).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function a([s, i]) { return Object.entries(Object.assign({}, ...t)).forEach(function a([i, s]) {
i = n.processReactiveAttribute(e, s, i, a); s = r.processReactiveAttribute(e, i, s, a);
let [h] = s; let [h] = i;
if (h === "=") if (h === "=")
return o(s.slice(1), i); return o(i.slice(1), s);
if (h === ".") if (h === ".")
return _(e, s.slice(1), i); return _(e, i.slice(1), s);
if (typeof i == "object") if (typeof s == "object")
switch (s) { switch (i) {
case "style": case "style":
return O(i, T.bind(null, e.style, "Property")); return y(s, T.bind(null, e.style, "Property"));
case "dataset": case "dataset":
return O(i, _.bind(null, e.dataset)); return y(s, _.bind(null, e.dataset));
case "ariaset": case "ariaset":
return O(i, (E, v) => o("aria-" + E, v)); return y(s, (E, v) => o("aria-" + E, v));
case "classList": case "classList":
return k(e, i); return $(e, s);
default: default:
return Reflect.set(e, s, i); return Reflect.set(e, i, s);
} }
if (/(aria|data)([A-Z])/.test(s)) if (/(aria|data)([A-Z])/.test(i))
return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(s, i); return i = i.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(i, s);
switch (s) { switch (i) {
case "href": case "href":
return o(s, i); return o(i, s);
case "xlink:href": case "xlink:href":
return o(s, i, "http://www.w3.org/1999/xlink"); return o(i, s, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
if (!r) if (!n)
break; break;
return e.appendChild(document.createTextNode(i)); return e.appendChild(document.createTextNode(s));
} }
return q(e, s) ? _(e, s, i) : o(s, i); return q(e, i) ? _(e, i, s) : o(i, s);
}), e; }), e;
} }
function k(e, t) { function $(e, t) {
return typeof t != "object" || O( return typeof t != "object" || y(
t, t,
(n, r) => e.classList.toggle(n, r === -1 ? void 0 : !!r) (r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n)
), e; ), e;
} }
function re(e) { function re(e) {
return Array.from(e.children).forEach((t) => t.remove()), e; return Array.from(e.children).forEach((t) => t.remove()), e;
} }
function q(e, t) { function q(e, t) {
let n = "HTMLElement," + t; let r = "HTMLElement," + t;
if (e instanceof HTMLElement && x.has(n)) if (e instanceof HTMLElement && x.has(r))
return x.get(n);
let r = e.nodeName + "," + t;
if (x.has(r))
return x.get(r); return x.get(r);
let [o, a, s] = M(e, t), i = !P(o.set); let n = e.nodeName + "," + t;
return (!i || a) && x.set(s === HTMLElement.prototype ? n : r, i), i; if (x.has(n))
return x.get(n);
let [o, a, i] = M(e, t), s = !P(o.set);
return (!s || a) && x.set(i === HTMLElement.prototype ? r : n, s), s;
} }
function M(e, t, n = 0) { function M(e, t, r = 0) {
if (e = Object.getPrototypeOf(e), !e) if (e = Object.getPrototypeOf(e), !e)
return [{}, n, e]; return [{}, r, e];
let r = Object.getOwnPropertyDescriptor(e, t); let n = Object.getOwnPropertyDescriptor(e, t);
return r ? [r, n, e] : M(e, t, n + 1); return n ? [n, r, e] : M(e, t, r + 1);
} }
function O(e, t) { function y(e, t) {
return Object.entries(e).forEach(([n, r]) => t(n, r)); return Object.entries(e).forEach(([r, n]) => t(r, n));
} }
function P(e) { function P(e) {
return typeof e > "u"; return typeof e > "u";
} }
function T(e, t, n, r) { function T(e, t, r, n) {
return e[(P(r) ? "remove" : "set") + t](n, r); return e[(P(n) ? "remove" : "set") + t](r, n);
} }
function J(e, t, n, r, o = null) { function J(e, t, r, n, o = null) {
return e[(P(r) ? "remove" : "set") + t + "NS"](o, n, r); return e[(P(n) ? "remove" : "set") + t + "NS"](o, r, n);
} }
function _(e, t, n) { function _(e, t, r) {
return Reflect.set(e, t, n); return Reflect.set(e, t, r);
} }
// src/events.js // src/events.js
function ce(e, t, ...n) { function ce(e, t, ...r) {
let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t);
return e.dispatchEvent(r); return e.dispatchEvent(n);
} }
function H(e, t, n) { function H(e, t, r) {
return function(o) { return function(o) {
return o.addEventListener(e, t, n), o; return o.addEventListener(e, t, r), o;
}; };
} }
var S = W(); var S = W();
H.connected = function(e, t) { H.connected = function(e, t) {
return function(r) { return function(n) {
return j(t && t.signal, () => S.offConnected(r, e)) && S.onConnected(r, e), r; return typeof n.connectedCallback == "function" ? (n.addEventListener("dde:connected", e, t), n) : (j(t && t.signal, () => S.offConnected(n, e)) && (n.isConnected ? e(new Event("dde:connected")) : S.onConnected(n, e)), n);
}; };
}; };
H.disconnected = function(e, t) { H.disconnected = function(e, t) {
return function(r) { return function(n) {
return j(t && t.signal, () => S.offDisconnected(r, e)) && S.onDisconnected(r, e), r; return typeof n.disconnectedCallback == "function" ? (n.addEventListener("dde:disconnected", e, t), n) : (j(t && t.signal, () => S.offDisconnected(n, e)) && S.onDisconnected(n, e), n);
}; };
}; };
function W() { function W() {
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) { let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(c) {
for (let f of c) for (let f of c)
if (f.type === "childList") { if (f.type === "childList") {
if (E(f.addedNodes, !0)) { if (E(f.addedNodes, !0)) {
s(); i();
continue; continue;
} }
v(f.removedNodes, !0) && s(); v(f.removedNodes, !0) && i();
} }
}); });
return { return {
@ -179,8 +179,8 @@ function W() {
offConnected(c, f) { offConnected(c, f) {
if (!e.has(c)) if (!e.has(c))
return; return;
let u = e.get(c), l = u.connected; let u = e.get(c), p = u.connected;
l.splice(l.indexOf(f), 1), r(c, u); p.splice(p.indexOf(f), 1), n(c, u);
}, },
onDisconnected(c, f) { onDisconnected(c, f) {
a(), o(c).disconnected.push(f); a(), o(c).disconnected.push(f);
@ -188,12 +188,12 @@ function W() {
offDisconnected(c, f) { offDisconnected(c, f) {
if (!e.has(c)) if (!e.has(c))
return; return;
let u = e.get(c), l = u.disconnected; let u = e.get(c), p = u.disconnected;
l.splice(l.indexOf(f), 1), r(c, u); p.splice(p.indexOf(f), 1), n(c, u);
} }
}; };
function r(c, f) { function n(c, f) {
f.connected.length || f.disconnected.length || (e.delete(c), s()); f.connected.length || f.disconnected.length || (e.delete(c), i());
} }
function o(c) { function o(c) {
if (e.has(c)) if (e.has(c))
@ -202,18 +202,18 @@ function W() {
return e.set(c, f), f; return e.set(c, f), f;
} }
function a() { function a() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, r.observe(document.body, { childList: !0, subtree: !0 }));
}
function s() {
!t || e.size || (t = !1, n.disconnect());
} }
function i() { function i() {
!t || e.size || (t = !1, r.disconnect());
}
function s() {
return new Promise(function(c) { return new Promise(function(c) {
(requestIdleCallback || requestAnimationFrame)(c); (requestIdleCallback || requestAnimationFrame)(c);
}); });
} }
async function h(c) { async function h(c) {
e.size > 30 && await i(); e.size > 30 && await s();
let f = []; let f = [];
if (!(c instanceof Node)) if (!(c instanceof Node))
return f; return f;
@ -225,8 +225,8 @@ function W() {
for (let u of c) { for (let u of c) {
if (f && h(u).then(E), !e.has(u)) if (f && h(u).then(E), !e.has(u))
continue; continue;
let l = e.get(u); let p = e.get(u);
return l.connected.forEach((L) => L(u)), l.connected.length = 0, l.disconnected.length || e.delete(u), !0; return p.connected.forEach((R) => R(u)), p.connected.length = 0, p.disconnected.length || e.delete(u), !0;
} }
return !1; return !1;
} }
@ -234,8 +234,8 @@ function W() {
for (let u of c) { for (let u of c) {
if (f && h(u).then(v), !e.has(u)) if (f && h(u).then(v), !e.has(u))
continue; continue;
let l = e.get(u); let p = e.get(u);
return l.disconnected.forEach((L) => L(u)), l.connected.length = 0, l.disconnected.length = 0, e.delete(u), !0; return p.disconnected.forEach((R) => R(u)), p.connected.length = 0, p.disconnected.length = 0, e.delete(u), !0;
} }
return !1; return !1;
} }
@ -244,8 +244,8 @@ function W() {
// index.js // index.js
[HTMLElement, DocumentFragment].forEach((e) => { [HTMLElement, DocumentFragment].forEach((e) => {
let { append: t } = e.prototype; let { append: t } = e.prototype;
e.prototype.append = function(...n) { e.prototype.append = function(...r) {
return t.apply(this, n), this; return t.apply(this, r), this;
}; };
}); });
@ -258,111 +258,111 @@ function C(e) {
return !1; return !1;
} }
} }
var p = /* @__PURE__ */ new WeakMap(); var l = /* @__PURE__ */ new WeakMap();
function m(e, t) { function g(e, t) {
if (typeof e != "function") if (typeof e != "function")
return z(e, t); return k(e, t);
if (C(e)) if (C(e))
return e; return e;
let n = z(""), r = () => n(e()); let r = k(""), n = () => r(e());
return p.set(r, /* @__PURE__ */ new Set([n])), Z(r), n; return l.set(n, /* @__PURE__ */ new Set([r])), Z(n), r;
} }
m.action = function(e, t, ...n) { g.action = function(e, t, ...r) {
let r = e[d], { actions: o } = r; let n = e[d], { actions: o } = n;
if (!o || !Reflect.has(o, t)) if (!o || !Reflect.has(o, t))
throw new Error(`'${e}' has no action with name '${t}'!`); throw new Error(`'${e}' has no action with name '${t}'!`);
if (o[t].apply(r, n), r.skip) if (o[t].apply(n, r), n.skip)
return Reflect.deleteProperty(r, "skip"); return Reflect.deleteProperty(n, "skip");
r.listeners.forEach((a) => a(r.value)); n.listeners.forEach((a) => a(n.value));
}; };
m.on = function e(t, n, r = {}) { g.on = function e(t, r, n = {}) {
let { signal: o } = r; let { signal: o } = n;
if (!(o && o.aborted)) { if (!(o && o.aborted)) {
if (Array.isArray(t)) if (Array.isArray(t))
return t.forEach((a) => e(a, n, r)); return t.forEach((a) => e(a, r, n));
D(t, n), o && o.addEventListener("abort", () => $(t, n)); D(t, r), o && o.addEventListener("abort", () => F(t, r));
} }
}; };
m.symbols = { g.symbols = {
signal: d, signal: d,
onclear: Symbol.for("Signal.onclear") onclear: Symbol.for("Signal.onclear")
}; };
m.clear = function(...e) { g.clear = function(...e) {
for (let n of e) { for (let r of e) {
Reflect.deleteProperty(n, "toJSON"); Reflect.deleteProperty(r, "toJSON");
let r = n[d], { onclear: o } = m.symbols; let n = r[d], { onclear: o } = g.symbols;
r.actions && r.actions[o] && r.actions[o].call(r), t(n, r), Reflect.deleteProperty(n, d); n.actions && n.actions[o] && n.actions[o].call(n), t(r, n), Reflect.deleteProperty(r, d);
} }
function t(n, r) { function t(r, n) {
r.listeners.forEach((o) => { n.listeners.forEach((o) => {
if (r.listeners.delete(o), !p.has(o)) if (n.listeners.delete(o), !l.has(o))
return; return;
let a = p.get(o); let a = l.get(o);
a.delete(n), !(a.size > 1) && (m.clear(...a), p.delete(o)); a.delete(r), !(a.size > 1) && (g.clear(...a), l.delete(o));
}); });
} }
}; };
m.el = function(e, t) { g.el = function(e, t) {
let n = document.createComment("<#reactive>"), r = document.createComment("</#reactive>"), o = document.createDocumentFragment(); let r = document.createComment("<#reactive>"), n = document.createComment("</#reactive>"), o = document.createDocumentFragment();
o.append(n, r); o.append(r, n);
let a = (s) => { let a = (i) => {
if (!n.parentNode || !r.parentNode) if (!r.parentNode || !n.parentNode)
return $(e, a); return F(e, a);
let i = t(s); let s = t(i);
Array.isArray(i) || (i = [i]); Array.isArray(s) || (s = [s]);
let h = n; let h = r;
for (; (h = n.nextSibling) !== r; ) for (; (h = r.nextSibling) !== n; )
h.remove(); h.remove();
n.after(...i); r.after(...s);
}; };
return D(e, a), a(e()), o; return D(e, a), a(e()), o;
}; };
var F = { var z = {
isTextContent(e) { isTextContent(e) {
return g(e) === "string" || C(e) && g(K(e)) === "string"; return m(e) === "string" || C(e) && m(K(e)) === "string";
}, },
processReactiveAttribute(e, t, n, r) { processReactiveAttribute(e, t, r, n) {
return C(n) ? (D(n, (o) => r([t, o])), n()) : n; return C(r) ? (D(r, (o) => n([t, o])), r()) : r;
} }
}; };
function z(e, t) { function k(e, t) {
let n = (...r) => r.length ? V(n, r[0]) : G(n); let r = (...n) => n.length ? V(r, n[0]) : G(r);
return U(n, e, t); return U(r, e, t);
} }
var I = Object.assign(/* @__PURE__ */ Object.create(null), { var I = Object.assign(/* @__PURE__ */ Object.create(null), {
stopPropagation() { stopPropagation() {
this.skip = !0; this.skip = !0;
} }
}); });
function U(e, t, n) { function U(e, t, r) {
return g(n) !== "[object Object]" && (n = {}), e[d] = { return m(r) !== "[object Object]" && (r = {}), e[d] = {
value: t, value: t,
actions: n, actions: r,
listeners: /* @__PURE__ */ new Set() listeners: /* @__PURE__ */ new Set()
}, e.toJSON = () => e(), Object.setPrototypeOf(e[d], I), e; }, e.toJSON = () => e(), Object.setPrototypeOf(e[d], I), e;
} }
var R = []; var L = [];
function Z(e) { function Z(e) {
let t = function() { let t = function() {
R.push(t), e(), R.pop(); L.push(t), e(), L.pop();
}; };
p.has(e) && (p.set(t, p.get(e)), p.delete(e)), t(); l.has(e) && (l.set(t, l.get(e)), l.delete(e)), t();
} }
function B() { function B() {
return R[R.length - 1]; return L[L.length - 1];
} }
function G(e) { function G(e) {
if (!e[d]) if (!e[d])
return; return;
let { value: t, listeners: n } = e[d], r = B(); let { value: t, listeners: r } = e[d], n = B();
return r && n.add(r), p.has(r) && p.get(r).add(e), t; return n && r.add(n), l.has(n) && l.get(n).add(e), t;
} }
function V(e, t) { function V(e, t) {
if (!e[d]) if (!e[d])
return; return;
let n = e[d]; let r = e[d];
if (n.value !== t) if (r.value !== t)
return n.value = t, n.listeners.forEach((r) => r(t)), t; return r.value = t, r.listeners.forEach((n) => n(t)), t;
} }
function K(e) { function K(e) {
return e[d].value; return e[d].value;
@ -371,17 +371,17 @@ function D(e, t) {
if (e[d]) if (e[d])
return e[d].listeners.add(t); return e[d].listeners.add(t);
} }
function $(e, t) { function F(e, t) {
if (e[d]) if (e[d])
return e[d].listeners.delete(t); return e[d].listeners.delete(t);
} }
// src/signals.js // src/signals.js
N(F); N(z);
export { export {
m as S, g as S,
w as assign, w as assign,
k as classListDeclarative, $ as classListDeclarative,
ne as createElement, ne as createElement,
ce as dispatchEvent, ce as dispatchEvent,
ne as el, ne as el,

138
dist/esm.js vendored
View File

@ -1,9 +1,9 @@
// src/helpers.js // src/helpers.js
function j(e) { function N(e) {
let t = typeof e; let t = typeof e;
return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e); return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e);
} }
function w(e, t) { function O(e, t) {
if (!e || !(e instanceof AbortSignal)) if (!e || !(e instanceof AbortSignal))
return !0; return !0;
if (!e.aborted) if (!e.aborted)
@ -15,10 +15,10 @@ function w(e, t) {
// src/signals-common.js // src/signals-common.js
var l = { var l = {
isTextContent(e) { isTextContent(e) {
return j(e) !== "[object Object]"; return N(e) !== "[object Object]";
}, },
processReactiveAttribute(e, t, n, r) { processReactiveAttribute(e, t, r, n) {
return n; return r;
} }
}; };
function D(e, t = !0) { function D(e, t = !0) {
@ -29,43 +29,43 @@ function C(e) {
} }
// src/dom.js // src/dom.js
var m = "html"; var v = "html";
function F(e) { function F(e) {
return m = e === "svg" ? "http://www.w3.org/2000/svg" : e, { return v = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(t) { append(t) {
return m = "html", t; return v = "html", t;
} }
}; };
} }
function I(e, t, ...n) { function I(e, t, ...r) {
let r = C(this), c; let n = C(this), c;
switch (r.isTextContent(t) && (t = { textContent: t }), !0) { switch (n.isTextContent(t) && (t = { textContent: t }), !0) {
case typeof e == "function": { case typeof e == "function": {
c = e(t || void 0, (s) => s ? (n.unshift(s), void 0) : c); c = e(t || void 0, (s) => s ? (r.unshift(s), void 0) : c);
break; break;
} }
case e === "#text": case e === "#text":
c = x(document.createTextNode(""), t); c = E(document.createTextNode(""), t);
break; break;
case e === "<>": case e === "<>":
c = x(document.createDocumentFragment(), t); c = E(document.createDocumentFragment(), t);
break; break;
case m !== "html": case v !== "html":
c = x(document.createElementNS(m, e), t); c = E(document.createElementNS(v, e), t);
break; break;
case !c: case !c:
c = x(document.createElement(e), t); c = E(document.createElement(e), t);
} }
return n.forEach((a) => a(c)), c; return r.forEach((a) => a(c)), c;
} }
var h = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')); var h = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]'));
function x(e, ...t) { function E(e, ...t) {
let n = C(this); let r = C(this);
if (!t.length) if (!t.length)
return e; return e;
let r = e instanceof SVGElement, c = (r ? S : y).bind(null, e, "Attribute"); let n = e instanceof SVGElement, c = (n ? S : j).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function a([s, f]) { return Object.entries(Object.assign({}, ...t)).forEach(function a([s, f]) {
f = n.processReactiveAttribute(e, s, f, a); f = r.processReactiveAttribute(e, s, f, a);
let [p] = s; let [p] = s;
if (p === "=") if (p === "=")
return c(s.slice(1), f); return c(s.slice(1), f);
@ -74,11 +74,11 @@ function x(e, ...t) {
if (typeof f == "object") if (typeof f == "object")
switch (s) { switch (s) {
case "style": case "style":
return E(f, y.bind(null, e.style, "Property")); return x(f, j.bind(null, e.style, "Property"));
case "dataset": case "dataset":
return E(f, L.bind(null, e.dataset)); return x(f, L.bind(null, e.dataset));
case "ariaset": case "ariaset":
return E(f, (g, b) => c("aria-" + g, b)); return x(f, (g, b) => c("aria-" + g, b));
case "classList": case "classList":
return R(e, f); return R(e, f);
default: default:
@ -92,7 +92,7 @@ function x(e, ...t) {
case "xlink:href": case "xlink:href":
return c(s, f, "http://www.w3.org/1999/xlink"); return c(s, f, "http://www.w3.org/1999/xlink");
case "textContent": case "textContent":
if (!r) if (!n)
break; break;
return e.appendChild(document.createTextNode(f)); return e.appendChild(document.createTextNode(f));
} }
@ -100,69 +100,69 @@ function x(e, ...t) {
}), e; }), e;
} }
function R(e, t) { function R(e, t) {
return typeof t != "object" || E( return typeof t != "object" || x(
t, t,
(n, r) => e.classList.toggle(n, r === -1 ? void 0 : !!r) (r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n)
), e; ), e;
} }
function U(e) { function U(e) {
return Array.from(e.children).forEach((t) => t.remove()), e; return Array.from(e.children).forEach((t) => t.remove()), e;
} }
function M(e, t) { function M(e, t) {
let n = "HTMLElement," + t; let r = "HTMLElement," + t;
if (e instanceof HTMLElement && h.has(n)) if (e instanceof HTMLElement && h.has(r))
return h.get(n);
let r = e.nodeName + "," + t;
if (h.has(r))
return h.get(r); return h.get(r);
let [c, a, s] = A(e, t), f = !N(c.set); let n = e.nodeName + "," + t;
return (!f || a) && h.set(s === HTMLElement.prototype ? n : r, f), f; if (h.has(n))
return h.get(n);
let [c, a, s] = A(e, t), f = !y(c.set);
return (!f || a) && h.set(s === HTMLElement.prototype ? r : n, f), f;
} }
function A(e, t, n = 0) { function A(e, t, r = 0) {
if (e = Object.getPrototypeOf(e), !e) if (e = Object.getPrototypeOf(e), !e)
return [{}, n, e]; return [{}, r, e];
let r = Object.getOwnPropertyDescriptor(e, t); let n = Object.getOwnPropertyDescriptor(e, t);
return r ? [r, n, e] : A(e, t, n + 1); return n ? [n, r, e] : A(e, t, r + 1);
} }
function E(e, t) { function x(e, t) {
return Object.entries(e).forEach(([n, r]) => t(n, r)); return Object.entries(e).forEach(([r, n]) => t(r, n));
} }
function N(e) { function y(e) {
return typeof e > "u"; return typeof e > "u";
} }
function y(e, t, n, r) { function j(e, t, r, n) {
return e[(N(r) ? "remove" : "set") + t](n, r); return e[(y(n) ? "remove" : "set") + t](r, n);
} }
function S(e, t, n, r, c = null) { function S(e, t, r, n, c = null) {
return e[(N(r) ? "remove" : "set") + t + "NS"](c, n, r); return e[(y(n) ? "remove" : "set") + t + "NS"](c, r, n);
} }
function L(e, t, n) { function L(e, t, r) {
return Reflect.set(e, t, n); return Reflect.set(e, t, r);
} }
// src/events.js // src/events.js
function $(e, t, ...n) { function $(e, t, ...r) {
let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t);
return e.dispatchEvent(r); return e.dispatchEvent(n);
} }
function T(e, t, n) { function T(e, t, r) {
return function(c) { return function(c) {
return c.addEventListener(e, t, n), c; return c.addEventListener(e, t, r), c;
}; };
} }
var v = _(); var m = _();
T.connected = function(e, t) { T.connected = function(e, t) {
return function(r) { return function(n) {
return w(t && t.signal, () => v.offConnected(r, e)) && v.onConnected(r, e), r; return typeof n.connectedCallback == "function" ? (n.addEventListener("dde:connected", e, t), n) : (O(t && t.signal, () => m.offConnected(n, e)) && (n.isConnected ? e(new Event("dde:connected")) : m.onConnected(n, e)), n);
}; };
}; };
T.disconnected = function(e, t) { T.disconnected = function(e, t) {
return function(r) { return function(n) {
return w(t && t.signal, () => v.offDisconnected(r, e)) && v.onDisconnected(r, e), r; return typeof n.disconnectedCallback == "function" ? (n.addEventListener("dde:disconnected", e, t), n) : (O(t && t.signal, () => m.offDisconnected(n, e)) && m.onDisconnected(n, e), n);
}; };
}; };
function _() { function _() {
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(o) { let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(o) {
for (let i of o) for (let i of o)
if (i.type === "childList") { if (i.type === "childList") {
if (g(i.addedNodes, !0)) { if (g(i.addedNodes, !0)) {
@ -180,7 +180,7 @@ function _() {
if (!e.has(o)) if (!e.has(o))
return; return;
let u = e.get(o), d = u.connected; let u = e.get(o), d = u.connected;
d.splice(d.indexOf(i), 1), r(o, u); d.splice(d.indexOf(i), 1), n(o, u);
}, },
onDisconnected(o, i) { onDisconnected(o, i) {
a(), c(o).disconnected.push(i); a(), c(o).disconnected.push(i);
@ -189,10 +189,10 @@ function _() {
if (!e.has(o)) if (!e.has(o))
return; return;
let u = e.get(o), d = u.disconnected; let u = e.get(o), d = u.disconnected;
d.splice(d.indexOf(i), 1), r(o, u); d.splice(d.indexOf(i), 1), n(o, u);
} }
}; };
function r(o, i) { function n(o, i) {
i.connected.length || i.disconnected.length || (e.delete(o), s()); i.connected.length || i.disconnected.length || (e.delete(o), s());
} }
function c(o) { function c(o) {
@ -202,10 +202,10 @@ function _() {
return e.set(o, i), i; return e.set(o, i), i;
} }
function a() { function a() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 })); t || (t = !0, r.observe(document.body, { childList: !0, subtree: !0 }));
} }
function s() { function s() {
!t || e.size || (t = !1, n.disconnect()); !t || e.size || (t = !1, r.disconnect());
} }
function f() { function f() {
return new Promise(function(o) { return new Promise(function(o) {
@ -226,7 +226,7 @@ function _() {
if (i && p(u).then(g), !e.has(u)) if (i && p(u).then(g), !e.has(u))
continue; continue;
let d = e.get(u); let d = e.get(u);
return d.connected.forEach((O) => O(u)), d.connected.length = 0, d.disconnected.length || e.delete(u), !0; return d.connected.forEach((w) => w(u)), d.connected.length = 0, d.disconnected.length || e.delete(u), !0;
} }
return !1; return !1;
} }
@ -235,7 +235,7 @@ function _() {
if (i && p(u).then(b), !e.has(u)) if (i && p(u).then(b), !e.has(u))
continue; continue;
let d = e.get(u); let d = e.get(u);
return d.disconnected.forEach((O) => O(u)), d.connected.length = 0, d.disconnected.length = 0, e.delete(u), !0; return d.disconnected.forEach((w) => w(u)), d.connected.length = 0, d.disconnected.length = 0, e.delete(u), !0;
} }
return !1; return !1;
} }
@ -244,12 +244,12 @@ function _() {
// 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(...n) { e.prototype.append = function(...r) {
return t.apply(this, n), this; return t.apply(this, r), this;
}; };
}); });
export { export {
x as assign, E as assign,
R as classListDeclarative, R as classListDeclarative,
I as createElement, I as createElement,
$ as dispatchEvent, $ as dispatchEvent,