1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2025-04-03 04:25:53 +02:00

builds

This commit is contained in:
Jan Andrle 2024-12-12 17:17:27 +01:00
parent 94ac2becfc
commit 5098fb7fa2
Signed by: jaandrle
GPG Key ID: B3A25AED155AFFAB
6 changed files with 218 additions and 194 deletions

View File

@ -51,7 +51,9 @@ var d = {
F: globalThis.DocumentFragment, F: globalThis.DocumentFragment,
H: globalThis.HTMLElement, H: globalThis.HTMLElement,
S: globalThis.SVGElement, S: globalThis.SVGElement,
M: globalThis.MutationObserver M: globalThis.MutationObserver,
qa: (t) => t,
qw: () => Promise.resolve()
}; };
function pt(t, e, n) { function pt(t, e, n) {
if (Reflect.set(t, e, n), !!A(n)) { if (Reflect.set(t, e, n), !!A(n)) {
@ -64,6 +66,9 @@ function pt(t, e, n) {
var O = "__dde_lifecyclesToEvents", _ = "dde:connected", S = "dde:disconnected", T = "dde:attributeChanged"; var O = "__dde_lifecyclesToEvents", _ = "dde:connected", S = "dde:disconnected", T = "dde:attributeChanged";
// src/dom.js // src/dom.js
function Mt(t) {
return d.qa(t);
}
var y = [{ var y = [{
get scope() { get scope() {
return d.D.body; return d.D.body;
@ -107,16 +112,16 @@ function M(t, e, ...n) {
switch ((Object(e) !== e || r.isSignal(e)) && (e = { textContent: e }), !0) { switch ((Object(e) !== e || r.isSignal(e)) && (e = { textContent: e }), !0) {
case typeof t == "function": { case typeof t == "function": {
o = 1; o = 1;
let a = (...h) => h.length ? (o === 1 ? n.unshift(...h) : h.forEach((m) => m(u)), void 0) : u; let a = (...l) => l.length ? (o === 1 ? n.unshift(...l) : l.forEach((m) => m(u)), void 0) : u;
x.push({ scope: t, host: a }), c = t(e || void 0); x.push({ scope: t, host: a }), c = t(e || void 0);
let l = c instanceof d.F; let h = c instanceof d.F;
if (c.nodeName === "#comment") break; if (c.nodeName === "#comment") break;
let v = M.mark({ let v = M.mark({
type: "component", type: "component",
name: t.name, name: t.name,
host: l ? "this" : "parentElement" host: h ? "this" : "parentElement"
}); });
c.prepend(v), l && (u = v); c.prepend(v), h && (u = v);
break; break;
} }
case t === "#text": case t === "#text":
@ -138,7 +143,7 @@ M.mark = function(t, e = !1) {
let n = e ? "" : "/", r = d.D.createComment(`<dde:mark ${t}${d.ssr}${n}>`); let n = e ? "" : "/", r = d.D.createComment(`<dde:mark ${t}${d.ssr}${n}>`);
return e && (r.end = d.D.createComment("</dde:mark>")), r; return e && (r.end = d.D.createComment("</dde:mark>")), r;
}; };
function Mt(t) { function jt(t) {
let e = this; let e = this;
return function(...r) { return function(...r) {
$ = t; $ = t;
@ -146,22 +151,22 @@ function Mt(t) {
return $ = void 0, o; return $ = void 0, o;
}; };
} }
function jt(t, e = t) { function Pt(t, e = t) {
let n = "\xB9\u2070", r = "\u2713", o = Object.fromEntries( let n = "\xB9\u2070", r = "\u2713", o = Object.fromEntries(
Array.from(e.querySelectorAll("slot")).filter((c) => !c.name.endsWith(n)).map((c) => [c.name += n, c]) Array.from(e.querySelectorAll("slot")).filter((c) => !c.name.endsWith(n)).map((c) => [c.name += n, c])
); );
if (t.append = new Proxy(t.append, { if (t.append = new Proxy(t.append, {
apply(c, u, a) { apply(c, u, a) {
if (a[0] === e) return c.apply(t, a); if (a[0] === e) return c.apply(t, a);
for (let l of a) { for (let h of a) {
let v = (l.slot || "") + n; let v = (h.slot || "") + n;
try { try {
bt(l, "remove", "slot"); bt(h, "remove", "slot");
} catch { } catch {
} }
let h = o[v]; let l = o[v];
if (!h) return; if (!l) return;
v.startsWith(r) || h.childNodes.forEach((m) => m.remove()), h.append(l), h.name = r + v; l.name.startsWith(r) || (l.childNodes.forEach((m) => m.remove()), l.name = r + v), l.append(h);
} }
return t.append = c, t; return t.append = c, t;
} }
@ -185,7 +190,7 @@ function nt(t, e, n) {
t, t,
e, e,
n, n,
(a, l) => nt.call(c, t, a, l) (a, h) => nt.call(c, t, a, h)
); );
let [u] = e; let [u] = e;
if (u === "=") return r(e.slice(1), n); if (u === "=") return r(e.slice(1), n);
@ -203,7 +208,7 @@ function nt(t, e, n) {
case "dataset": case "dataset":
return B(o, n, et.bind(null, t[e])); return B(o, n, et.bind(null, t[e]));
case "ariaset": case "ariaset":
return B(o, n, (a, l) => r("aria-" + a, l)); return B(o, n, (a, h) => r("aria-" + a, h));
case "classList": case "classList":
return ht.call(c, t, n); return ht.call(c, t, n);
} }
@ -263,7 +268,7 @@ function mt() {
let t = /* @__PURE__ */ new Map(), e = !1, n = (i) => function(s) { let t = /* @__PURE__ */ new Map(), e = !1, n = (i) => function(s) {
for (let f of s) for (let f of s)
if (f.type === "childList") { if (f.type === "childList") {
if (h(f.addedNodes, !0)) { if (l(f.addedNodes, !0)) {
i(); i();
continue; continue;
} }
@ -316,23 +321,23 @@ function mt() {
function a() { function a() {
!e || t.size || (e = !1, r.disconnect()); !e || t.size || (e = !1, r.disconnect());
} }
function l() { function h() {
return new Promise(function(i) { return new Promise(function(i) {
(requestIdleCallback || requestAnimationFrame)(i); (requestIdleCallback || requestAnimationFrame)(i);
}); });
} }
async function v(i) { async function v(i) {
t.size > 30 && await l(); t.size > 30 && await h();
let s = []; let s = [];
if (!(i instanceof Node)) return s; if (!(i instanceof Node)) return s;
for (let f of t.keys()) for (let f of t.keys())
f === i || !(f instanceof Node) || i.contains(f) && s.push(f); f === i || !(f instanceof Node) || i.contains(f) && s.push(f);
return s; return s;
} }
function h(i, s) { function l(i, s) {
let f = !1; let f = !1;
for (let b of i) { for (let b of i) {
if (s && v(b).then(h), !t.has(b)) continue; if (s && v(b).then(l), !t.has(b)) continue;
let L = t.get(b); let L = t.get(b);
L.length_c && (b.dispatchEvent(new Event(_)), L.connected = /* @__PURE__ */ new WeakSet(), L.length_c = 0, L.length_d || t.delete(b), f = !0); L.length_c && (b.dispatchEvent(new Event(_)), L.connected = /* @__PURE__ */ new WeakSet(), L.length_c = 0, L.length_d || t.delete(b), f = !0);
} }
@ -352,7 +357,7 @@ function mt() {
} }
// src/customElement.js // src/customElement.js
function Ht(t, e, n, r = wt) { function It(t, e, n, r = wt) {
x.push({ x.push({
scope: t, scope: t,
host: (...u) => u.length ? u.forEach((a) => a(t)) : t host: (...u) => u.length ? u.forEach((a) => a(t)) : t
@ -385,7 +390,7 @@ function wt(t) {
} }
// src/events.js // src/events.js
function Zt(t, e, n) { function Gt(t, e, n) {
return e || (e = {}), function(o, ...c) { return e || (e = {}), function(o, ...c) {
n && (c.unshift(o), o = typeof n == "function" ? n() : n); n && (c.unshift(o), o = typeof n == "function" ? n() : n);
let u = c.length ? new CustomEvent(t, Object.assign({ detail: c[0] }, e)) : new Event(t, e); let u = c.length ? new CustomEvent(t, Object.assign({ detail: c[0] }, e)) : new Event(t, e);
@ -419,9 +424,9 @@ w.attributeChanged = function(t, e) {
return typeof e != "object" && (e = {}), function(r) { return typeof e != "object" && (e = {}), function(r) {
if (r.addEventListener(T, t, e), r[O] || _t.has(r) || !d.M) return r; if (r.addEventListener(T, t, e), r[O] || _t.has(r) || !d.M) return r;
let o = new d.M(function(u) { let o = new d.M(function(u) {
for (let { attributeName: a, target: l } of u) for (let { attributeName: a, target: h } of u)
l.dispatchEvent( h.dispatchEvent(
new CustomEvent(T, { detail: [a, l.getAttribute(a)] }) new CustomEvent(T, { detail: [a, h.getAttribute(a)] })
); );
}); });
return P(e.signal, () => o.disconnect()) && o.observe(r, { attributes: !0 }), r; return P(e.signal, () => o.disconnect()) && o.observe(r, { attributes: !0 }), r;
@ -462,7 +467,7 @@ E.on = function t(e, n, r = {}) {
let { signal: o } = r; let { signal: o } = r;
if (!(o && o.aborted)) { if (!(o && o.aborted)) {
if (Array.isArray(e)) return e.forEach((c) => t(c, n, r)); if (Array.isArray(e)) return e.forEach((c) => t(c, n, r));
Q(e, n), o && o.addEventListener("abort", () => R(e, n)); K(e, n), o && o.addEventListener("abort", () => R(e, n));
} }
}; };
E.symbols = { E.symbols = {
@ -486,24 +491,24 @@ var D = "__dde_reactive";
E.el = function(t, e) { E.el = function(t, e) {
let n = M.mark({ type: "reactive" }, !0), r = n.end, o = d.D.createDocumentFragment(); let n = M.mark({ type: "reactive" }, !0), r = n.end, o = d.D.createDocumentFragment();
o.append(n, r); o.append(n, r);
let { current: c } = x, u = {}, a = (l) => { let { current: c } = x, u = {}, a = (h) => {
if (!n.parentNode || !r.parentNode) if (!n.parentNode || !r.parentNode)
return R(t, a); return R(t, a);
let v = u; let v = u;
u = {}, x.push(c); u = {}, x.push(c);
let h = e(l, function(s, f) { let l = e(h, function(s, f) {
let b; let b;
return I(v, s) ? (b = v[s], delete v[s]) : b = f(), u[s] = b, b; return I(v, s) ? (b = v[s], delete v[s]) : b = f(), u[s] = b, b;
}); });
x.pop(), Array.isArray(h) || (h = [h]); x.pop(), Array.isArray(l) || (l = [l]);
let m = document.createComment(""); let m = document.createComment("");
h.push(m), n.after(...h); l.push(m), n.after(...l);
let k; let k;
for (; (k = m.nextSibling) && k !== r; ) for (; (k = m.nextSibling) && k !== r; )
k.remove(); k.remove();
m.remove(), n.isConnected && yt(c.host()); m.remove(), n.isConnected && yt(c.host());
}; };
return Q(t, a), ut(t, a, n, e), a(t()), o; return K(t, a), ut(t, a, n, e), a(t()), o;
}; };
function yt(t) { function yt(t) {
!t || !t[D] || (requestIdleCallback || setTimeout)(function() { !t || !t[D] || (requestIdleCallback || setTimeout)(function() {
@ -517,7 +522,7 @@ var At = {
}; };
function Ot(t) { function Ot(t) {
return function(e, n) { return function(e, n) {
let r = (...c) => c.length ? e.setAttribute(n, ...c) : K(r), o = ft(r, e.getAttribute(n), At); let r = (...c) => c.length ? e.setAttribute(n, ...c) : V(r), o = ft(r, e.getAttribute(n), At);
return t[n] = o, o; return t[n] = o, o;
}; };
} }
@ -544,7 +549,7 @@ var st = {
return R(n, o); return R(n, o);
r(e, c); r(e, c);
}; };
return Q(n, o), ut(n, o, t, e), n(); return K(n, o), ut(n, o, t, e), n();
} }
}; };
function ut(t, e, ...n) { function ut(t, e, ...n) {
@ -562,14 +567,14 @@ function ut(t, e, ...n) {
}); });
} }
function it(t, e, n) { function it(t, e, n) {
let r = t ? () => K(r) : (...o) => o.length ? at(r, ...o) : K(r); let r = t ? () => V(r) : (...o) => o.length ? at(r, ...o) : V(r);
return ft(r, e, n, t); return ft(r, e, n, t);
} }
var St = Object.assign(/* @__PURE__ */ Object.create(null), { var St = Object.assign(/* @__PURE__ */ Object.create(null), {
stopPropagation() { stopPropagation() {
this.skip = !0; this.skip = !0;
} }
}), V = class extends Error { }), Q = class extends Error {
constructor() { constructor() {
super(); super();
let [e, ...n] = this.stack.split(` let [e, ...n] = this.stack.split(`
@ -590,7 +595,7 @@ function ft(t, e, n, r = !1) {
onclear: o, onclear: o,
host: u, host: u,
listeners: /* @__PURE__ */ new Set(), listeners: /* @__PURE__ */ new Set(),
defined: new V().stack, defined: new Q().stack,
readonly: r readonly: r
}, },
enumerable: !1, enumerable: !1,
@ -601,7 +606,7 @@ function ft(t, e, n, r = !1) {
function Ct() { function Ct() {
return z[z.length - 1]; return z[z.length - 1];
} }
function K(t) { function V(t) {
if (!t[p]) return; if (!t[p]) return;
let { value: e, listeners: n } = t[p], r = Ct(); let { value: e, listeners: n } = t[p], r = Ct();
return r && n.add(r), g.has(r) && g.get(r).add(t), e; return r && n.add(r), g.has(r) && g.get(r).add(t), e;
@ -612,7 +617,7 @@ function at(t, e, n) {
if (!(!n && r.value === e)) if (!(!n && r.value === e))
return r.value = e, r.listeners.forEach((o) => o(e)), e; return r.value = e, r.listeners.forEach((o) => o(e)), e;
} }
function Q(t, e) { function K(t, e) {
if (t[p]) if (t[p])
return t[p].listeners.add(e); return t[p].listeners.add(e);
} }
@ -636,15 +641,16 @@ globalThis.dde= {
S: E, S: E,
assign: q, assign: q,
assignAttribute: nt, assignAttribute: nt,
asyncQueueAdd: Mt,
chainableAppend: lt, chainableAppend: lt,
classListDeclarative: ht, classListDeclarative: ht,
createElement: M, createElement: M,
createElementNS: Mt, createElementNS: jt,
customElementRender: Ht, customElementRender: It,
customElementWithDDE: xt, customElementWithDDE: xt,
dispatchEvent: Zt, dispatchEvent: Gt,
el: M, el: M,
elNS: Mt, elNS: jt,
elementAttribute: bt, elementAttribute: bt,
isSignal: U, isSignal: U,
lifecyclesToEvents: xt, lifecyclesToEvents: xt,
@ -653,7 +659,7 @@ globalThis.dde= {
registerReactivity: H, registerReactivity: H,
scope: x, scope: x,
signal: E, signal: E,
simulateSlots: jt simulateSlots: Pt
}; };
})(); })();

102
dist/dde.js vendored
View File

@ -40,15 +40,17 @@ function G(t) {
// src/dom-common.js // src/dom-common.js
var f = { var f = {
setDeleteAttr: V, setDeleteAttr: Q,
ssr: "", ssr: "",
D: globalThis.document, D: globalThis.document,
F: globalThis.DocumentFragment, F: globalThis.DocumentFragment,
H: globalThis.HTMLElement, H: globalThis.HTMLElement,
S: globalThis.SVGElement, S: globalThis.SVGElement,
M: globalThis.MutationObserver M: globalThis.MutationObserver,
qa: (t) => t,
qw: () => Promise.resolve()
}; };
function V(t, e, n) { function Q(t, e, n) {
if (Reflect.set(t, e, n), !!x(n)) { if (Reflect.set(t, e, n), !!x(n)) {
if (Reflect.deleteProperty(t, e), t instanceof f.H && t.getAttribute(e) === "undefined") if (Reflect.deleteProperty(t, e), t instanceof f.H && t.getAttribute(e) === "undefined")
return t.removeAttribute(e); return t.removeAttribute(e);
@ -56,10 +58,13 @@ function V(t, e, n) {
return Reflect.set(t, e, ""); return Reflect.set(t, e, "");
} }
} }
var w = "__dde_lifecyclesToEvents", g = "dde:connected", y = "dde:disconnected", O = "dde:attributeChanged"; var w = "__dde_lifecyclesToEvents", v = "dde:connected", m = "dde:disconnected", O = "dde:attributeChanged";
// src/dom.js // src/dom.js
var v = [{ function dt(t) {
return f.qa(t);
}
var g = [{
get scope() { get scope() {
return f.D.body; return f.D.body;
}, },
@ -67,7 +72,7 @@ var v = [{
prevent: !0 prevent: !0
}], D = { }], D = {
get current() { get current() {
return v[v.length - 1]; return g[g.length - 1];
}, },
get host() { get host() {
return this.current.host; return this.current.host;
@ -77,27 +82,27 @@ var v = [{
return t.prevent = !0, t; return t.prevent = !0, t;
}, },
get state() { get state() {
return [...v]; return [...g];
}, },
push(t = {}) { push(t = {}) {
return v.push(Object.assign({}, this.current, { prevent: !1 }, t)); return g.push(Object.assign({}, this.current, { prevent: !1 }, t));
}, },
pushRoot() { pushRoot() {
return v.push(v[0]); return g.push(g[0]);
}, },
pop() { pop() {
if (v.length !== 1) if (g.length !== 1)
return v.pop(); return g.pop();
} }
}; };
function q(...t) { function q(...t) {
return this.appendOriginal(...t), this; return this.appendOriginal(...t), this;
} }
function J(t) { function V(t) {
return t.append === q || (t.appendOriginal = t.append, t.append = q), t; return t.append === q || (t.appendOriginal = t.append, t.append = q), t;
} }
var T; var T;
function k(t, e, ...n) { function P(t, e, ...n) {
let r = S(this), o = 0, c, a; let r = S(this), o = 0, c, a;
switch ((Object(e) !== e || r.isSignal(e)) && (e = { textContent: e }), !0) { switch ((Object(e) !== e || r.isSignal(e)) && (e = { textContent: e }), !0) {
case typeof t == "function": { case typeof t == "function": {
@ -106,7 +111,7 @@ function k(t, e, ...n) {
D.push({ scope: t, host: d }), c = t(e || void 0); D.push({ scope: t, host: d }), c = t(e || void 0);
let p = c instanceof f.F; let p = c instanceof f.F;
if (c.nodeName === "#comment") break; if (c.nodeName === "#comment") break;
let b = k.mark({ let b = P.mark({
type: "component", type: "component",
name: t.name, name: t.name,
host: p ? "this" : "parentElement" host: p ? "this" : "parentElement"
@ -126,22 +131,22 @@ function k(t, e, ...n) {
case !c: case !c:
c = R.call(this, f.D.createElement(t), e); c = R.call(this, f.D.createElement(t), e);
} }
return J(c), a || (a = c), n.forEach((d) => d(a)), o && D.pop(), o = 2, c; return V(c), a || (a = c), n.forEach((d) => d(a)), o && D.pop(), o = 2, c;
} }
k.mark = function(t, e = !1) { P.mark = function(t, e = !1) {
t = Object.entries(t).map(([o, c]) => o + `="${c}"`).join(" "); t = Object.entries(t).map(([o, c]) => o + `="${c}"`).join(" ");
let n = e ? "" : "/", r = f.D.createComment(`<dde:mark ${t}${f.ssr}${n}>`); let n = e ? "" : "/", r = f.D.createComment(`<dde:mark ${t}${f.ssr}${n}>`);
return e && (r.end = f.D.createComment("</dde:mark>")), r; return e && (r.end = f.D.createComment("</dde:mark>")), r;
}; };
function dt(t) { function pt(t) {
let e = this; let e = this;
return function(...r) { return function(...r) {
T = t; T = t;
let o = k.call(e, ...r); let o = P.call(e, ...r);
return T = void 0, o; return T = void 0, o;
}; };
} }
function pt(t, e = t) { function ht(t, e = t) {
let n = "\xB9\u2070", r = "\u2713", o = Object.fromEntries( let n = "\xB9\u2070", r = "\u2713", o = Object.fromEntries(
Array.from(e.querySelectorAll("slot")).filter((c) => !c.name.endsWith(n)).map((c) => [c.name += n, c]) Array.from(e.querySelectorAll("slot")).filter((c) => !c.name.endsWith(n)).map((c) => [c.name += n, c])
); );
@ -151,12 +156,12 @@ function pt(t, e = t) {
for (let p of d) { for (let p of d) {
let b = (p.slot || "") + n; let b = (p.slot || "") + n;
try { try {
Q(p, "remove", "slot"); K(p, "remove", "slot");
} catch { } catch {
} }
let h = o[b]; let h = o[b];
if (!h) return; if (!h) return;
b.startsWith(r) || h.childNodes.forEach((E) => E.remove()), h.append(p), h.name = r + b; h.name.startsWith(r) || (h.childNodes.forEach((E) => E.remove()), h.name = r + b), h.append(p);
} }
return t.append = c, t; return t.append = c, t;
} }
@ -200,7 +205,7 @@ function U(t, e, n) {
case "ariaset": case "ariaset":
return M(o, n, (d, p) => r("aria-" + d, p)); return M(o, n, (d, p) => r("aria-" + d, p));
case "classList": case "classList":
return K.call(c, t, n); return J.call(c, t, n);
} }
return X(t, e) ? $(t, e, n) : r(e, n); return X(t, e) ? $(t, e, n) : r(e, n);
} }
@ -209,7 +214,7 @@ function H(t, e) {
let r = (t instanceof f.S ? tt : Y).bind(null, t, "Attribute"), o = S(e); let r = (t instanceof f.S ? tt : Y).bind(null, t, "Attribute"), o = S(e);
return { setRemoveAttr: r, s: o }; return { setRemoveAttr: r, s: o };
} }
function K(t, e) { function J(t, e) {
let n = S(this); let n = S(this);
return M( return M(
n, n,
@ -217,7 +222,7 @@ function K(t, e) {
(r, o) => t.classList.toggle(r, o === -1 ? void 0 : !!o) (r, o) => t.classList.toggle(r, o === -1 ? void 0 : !!o)
), t; ), t;
} }
function Q(t, e, n, r) { function K(t, e, n, r) {
return t instanceof f.H ? t[e + "Attribute"](n, r) : t[e + "AttributeNS"](null, n, r); return t instanceof f.H ? t[e + "Attribute"](n, r) : t[e + "AttributeNS"](null, n, r);
} }
function X(t, e) { function X(t, e) {
@ -248,7 +253,7 @@ function F(t, e, n) {
} }
// src/events-observer.js // src/events-observer.js
var m = f.M ? et() : new Proxy({}, { var y = f.M ? et() : new Proxy({}, {
get() { get() {
return () => { return () => {
}; };
@ -329,7 +334,7 @@ function et() {
for (let l of s) { for (let l of s) {
if (u && b(l).then(h), !t.has(l)) continue; if (u && b(l).then(h), !t.has(l)) continue;
let A = t.get(l); let A = t.get(l);
A.length_c && (l.dispatchEvent(new Event(g)), A.connected = /* @__PURE__ */ new WeakSet(), A.length_c = 0, A.length_d || t.delete(l), i = !0); A.length_c && (l.dispatchEvent(new Event(v)), A.connected = /* @__PURE__ */ new WeakSet(), A.length_c = 0, A.length_d || t.delete(l), i = !0);
} }
return i; return i;
} }
@ -341,13 +346,13 @@ function et() {
} }
function I(s) { function I(s) {
return () => { return () => {
s.isConnected || (s.dispatchEvent(new Event(y)), t.delete(s)); s.isConnected || (s.dispatchEvent(new Event(m)), t.delete(s));
}; };
} }
} }
// src/customElement.js // src/customElement.js
function wt(t, e, n, r = rt) { function mt(t, e, n, r = rt) {
D.push({ D.push({
scope: t, scope: t,
host: (...a) => a.length ? a.forEach((d) => d(t)) : t host: (...a) => a.length ? a.forEach((d) => d(t)) : t
@ -355,23 +360,23 @@ function wt(t, e, n, r = rt) {
let o = t[w]; let o = t[w];
o || nt(t); o || nt(t);
let c = n.call(t, r); let c = n.call(t, r);
return o || t.dispatchEvent(new Event(g)), e.nodeType === 11 && typeof e.mode == "string" && t.addEventListener(y, m.observe(e), { once: !0 }), D.pop(), e.append(c); return o || t.dispatchEvent(new Event(v)), e.nodeType === 11 && typeof e.mode == "string" && t.addEventListener(m, y.observe(e), { once: !0 }), D.pop(), e.append(c);
} }
function nt(t) { function nt(t) {
return P(t.prototype, "connectedCallback", function(e, n, r) { return k(t.prototype, "connectedCallback", function(e, n, r) {
e.apply(n, r), n.dispatchEvent(new Event(g)); e.apply(n, r), n.dispatchEvent(new Event(v));
}), P(t.prototype, "disconnectedCallback", function(e, n, r) { }), k(t.prototype, "disconnectedCallback", function(e, n, r) {
e.apply(n, r), (globalThis.queueMicrotask || setTimeout)( e.apply(n, r), (globalThis.queueMicrotask || setTimeout)(
() => !n.isConnected && n.dispatchEvent(new Event(y)) () => !n.isConnected && n.dispatchEvent(new Event(m))
); );
}), P(t.prototype, "attributeChangedCallback", function(e, n, r) { }), k(t.prototype, "attributeChangedCallback", function(e, n, r) {
let [o, , c] = r; let [o, , c] = r;
n.dispatchEvent(new CustomEvent(O, { n.dispatchEvent(new CustomEvent(O, {
detail: [o, c] detail: [o, c]
})), e.apply(n, r); })), e.apply(n, r);
}), t.prototype[w] = !0, t; }), t.prototype[w] = !0, t;
} }
function P(t, e, n) { function k(t, e, n) {
t[e] = new Proxy(t[e] || (() => { t[e] = new Proxy(t[e] || (() => {
}), { apply: n }); }), { apply: n });
} }
@ -380,7 +385,7 @@ function rt(t) {
} }
// src/events.js // src/events.js
function Ct(t, e, n) { function Ot(t, e, n) {
return e || (e = {}), function(o, ...c) { return e || (e = {}), function(o, ...c) {
n && (c.unshift(o), o = typeof n == "function" ? n() : n); n && (c.unshift(o), o = typeof n == "function" ? n() : n);
let a = c.length ? new CustomEvent(t, Object.assign({ detail: c[0] }, e)) : new Event(t, e); let a = c.length ? new CustomEvent(t, Object.assign({ detail: c[0] }, e)) : new Event(t, e);
@ -395,12 +400,12 @@ function _(t, e, n) {
var B = (t) => Object.assign({}, typeof t == "object" ? t : null, { once: !0 }); var B = (t) => Object.assign({}, typeof t == "object" ? t : null, { once: !0 });
_.connected = function(t, e) { _.connected = function(t, e) {
return e = B(e), function(r) { return e = B(e), function(r) {
return r.addEventListener(g, t, e), r[w] ? r : r.isConnected ? (r.dispatchEvent(new Event(g)), r) : (L(e.signal, () => m.offConnected(r, t)) && m.onConnected(r, t), r); return r.addEventListener(v, t, e), r[w] ? r : r.isConnected ? (r.dispatchEvent(new Event(v)), r) : (L(e.signal, () => y.offConnected(r, t)) && y.onConnected(r, t), r);
}; };
}; };
_.disconnected = function(t, e) { _.disconnected = function(t, e) {
return e = B(e), function(r) { return e = B(e), function(r) {
return r.addEventListener(y, t, e), r[w] || L(e.signal, () => m.offDisconnected(r, t)) && m.onDisconnected(r, t), r; return r.addEventListener(m, t, e), r[w] || L(e.signal, () => y.offDisconnected(r, t)) && y.onDisconnected(r, t), r;
}; };
}; };
var j = /* @__PURE__ */ new WeakMap(); var j = /* @__PURE__ */ new WeakMap();
@ -426,22 +431,23 @@ _.attributeChanged = function(t, e) {
globalThis.dde= { globalThis.dde= {
assign: R, assign: R,
assignAttribute: U, assignAttribute: U,
chainableAppend: J, asyncQueueAdd: dt,
classListDeclarative: K, chainableAppend: V,
createElement: k, classListDeclarative: J,
createElementNS: dt, createElement: P,
customElementRender: wt, createElementNS: pt,
customElementRender: mt,
customElementWithDDE: nt, customElementWithDDE: nt,
dispatchEvent: Ct, dispatchEvent: Ot,
el: k, el: P,
elNS: dt, elNS: pt,
elementAttribute: Q, elementAttribute: K,
lifecyclesToEvents: nt, lifecyclesToEvents: nt,
observedAttributes: rt, observedAttributes: rt,
on: _, on: _,
registerReactivity: Z, registerReactivity: Z,
scope: D, scope: D,
simulateSlots: pt simulateSlots: ht
}; };
})(); })();

View File

@ -72,7 +72,7 @@ export function el<
TAG extends keyof ExtendedHTMLElementTagNameMap, TAG extends keyof ExtendedHTMLElementTagNameMap,
>( >(
tag_name: TAG, tag_name: TAG,
attrs?: ElementAttributes<ExtendedHTMLElementTagNameMap[NoInfer<TAG>]> | ddeString, attrs?: ElementAttributes<ExtendedHTMLElementTagNameMap[NoInfer<TAG>]> | ddeStringable,
...addons: ddeElementAddon< ...addons: ddeElementAddon<
ExtendedHTMLElementTagNameMap[NoInfer<TAG>] ExtendedHTMLElementTagNameMap[NoInfer<TAG>]
>[], // TODO: for now addons must have the same element >[], // TODO: for now addons must have the same element
@ -82,7 +82,7 @@ export function el(
): ddeDocumentFragment ): ddeDocumentFragment
export function el( export function el(
tag_name: string, tag_name: string,
attrs?: ElementAttributes<HTMLElement> | ddeString, attrs?: ElementAttributes<HTMLElement> | ddeStringable,
...addons: ddeElementAddon<HTMLElement>[] ...addons: ddeElementAddon<HTMLElement>[]
): ddeHTMLElement ): ddeHTMLElement
@ -90,7 +90,7 @@ export function el<
C extends (attr: ddeComponentAttributes)=> SupportedElement | ddeDocumentFragment C extends (attr: ddeComponentAttributes)=> SupportedElement | ddeDocumentFragment
>( >(
component: C, component: C,
attrs?: Parameters<C>[0] | ddeString, attrs?: Parameters<C>[0] | ddeStringable,
...addons: ddeElementAddon<ReturnType<C>>[] ...addons: ddeElementAddon<ReturnType<C>>[]
): ReturnType<C> extends ddeHTMLElementTagNameMap[keyof ddeHTMLElementTagNameMap] ): ReturnType<C> extends ddeHTMLElementTagNameMap[keyof ddeHTMLElementTagNameMap]
? ReturnType<C> ? ReturnType<C>
@ -104,7 +104,7 @@ export function elNS(
EL extends ( TAG extends keyof SVGElementTagNameMap ? SVGElementTagNameMap[TAG] : SVGElement ), EL extends ( TAG extends keyof SVGElementTagNameMap ? SVGElementTagNameMap[TAG] : SVGElement ),
>( >(
tag_name: TAG, tag_name: TAG,
attrs?: ElementAttributes<NoInfer<EL>> | ddeString, attrs?: ElementAttributes<NoInfer<EL>> | ddeStringable,
...addons: ddeElementAddon<NoInfer<EL>>[] ...addons: ddeElementAddon<NoInfer<EL>>[]
)=> TAG extends keyof ddeSVGElementTagNameMap ? ddeSVGElementTagNameMap[TAG] : ddeSVGElement )=> TAG extends keyof ddeSVGElementTagNameMap ? ddeSVGElementTagNameMap[TAG] : ddeSVGElement
export function elNS( export function elNS(
@ -114,7 +114,7 @@ export function elNS(
EL extends ( TAG extends keyof MathMLElementTagNameMap ? MathMLElementTagNameMap[TAG] : MathMLElement ), EL extends ( TAG extends keyof MathMLElementTagNameMap ? MathMLElementTagNameMap[TAG] : MathMLElement ),
>( >(
tag_name: TAG, tag_name: TAG,
attrs?: ddeString | Partial<{ attrs?: ddeStringable | Partial<{
[key in keyof EL]: EL[key] | ddeSignal<EL[key]> | string | number | boolean [key in keyof EL]: EL[key] | ddeSignal<EL[key]> | string | number | boolean
}>, }>,
...addons: ddeElementAddon<NoInfer<EL>>[] ...addons: ddeElementAddon<NoInfer<EL>>[]
@ -123,7 +123,7 @@ export function elNS(
namespace: string namespace: string
): ( ): (
tag_name: string, tag_name: string,
attrs?: string | ddeString | Record<string, any>, attrs?: string | ddeStringable | Record<string, any>,
...addons: ddeElementAddon<SupportedElement>[] ...addons: ddeElementAddon<SupportedElement>[]
)=> SupportedElement )=> SupportedElement
export { elNS as createElementNS } export { elNS as createElementNS }

View File

@ -49,7 +49,9 @@ var d = {
F: globalThis.DocumentFragment, F: globalThis.DocumentFragment,
H: globalThis.HTMLElement, H: globalThis.HTMLElement,
S: globalThis.SVGElement, S: globalThis.SVGElement,
M: globalThis.MutationObserver M: globalThis.MutationObserver,
qa: (t) => t,
qw: () => Promise.resolve()
}; };
function pt(t, e, n) { function pt(t, e, n) {
if (Reflect.set(t, e, n), !!A(n)) { if (Reflect.set(t, e, n), !!A(n)) {
@ -62,6 +64,9 @@ function pt(t, e, n) {
var O = "__dde_lifecyclesToEvents", _ = "dde:connected", S = "dde:disconnected", T = "dde:attributeChanged"; var O = "__dde_lifecyclesToEvents", _ = "dde:connected", S = "dde:disconnected", T = "dde:attributeChanged";
// src/dom.js // src/dom.js
function Mt(t) {
return d.qa(t);
}
var y = [{ var y = [{
get scope() { get scope() {
return d.D.body; return d.D.body;
@ -105,16 +110,16 @@ function M(t, e, ...n) {
switch ((Object(e) !== e || r.isSignal(e)) && (e = { textContent: e }), !0) { switch ((Object(e) !== e || r.isSignal(e)) && (e = { textContent: e }), !0) {
case typeof t == "function": { case typeof t == "function": {
o = 1; o = 1;
let a = (...h) => h.length ? (o === 1 ? n.unshift(...h) : h.forEach((m) => m(u)), void 0) : u; let a = (...l) => l.length ? (o === 1 ? n.unshift(...l) : l.forEach((m) => m(u)), void 0) : u;
x.push({ scope: t, host: a }), c = t(e || void 0); x.push({ scope: t, host: a }), c = t(e || void 0);
let l = c instanceof d.F; let h = c instanceof d.F;
if (c.nodeName === "#comment") break; if (c.nodeName === "#comment") break;
let v = M.mark({ let v = M.mark({
type: "component", type: "component",
name: t.name, name: t.name,
host: l ? "this" : "parentElement" host: h ? "this" : "parentElement"
}); });
c.prepend(v), l && (u = v); c.prepend(v), h && (u = v);
break; break;
} }
case t === "#text": case t === "#text":
@ -136,7 +141,7 @@ M.mark = function(t, e = !1) {
let n = e ? "" : "/", r = d.D.createComment(`<dde:mark ${t}${d.ssr}${n}>`); let n = e ? "" : "/", r = d.D.createComment(`<dde:mark ${t}${d.ssr}${n}>`);
return e && (r.end = d.D.createComment("</dde:mark>")), r; return e && (r.end = d.D.createComment("</dde:mark>")), r;
}; };
function Mt(t) { function jt(t) {
let e = this; let e = this;
return function(...r) { return function(...r) {
$ = t; $ = t;
@ -144,22 +149,22 @@ function Mt(t) {
return $ = void 0, o; return $ = void 0, o;
}; };
} }
function jt(t, e = t) { function Pt(t, e = t) {
let n = "\xB9\u2070", r = "\u2713", o = Object.fromEntries( let n = "\xB9\u2070", r = "\u2713", o = Object.fromEntries(
Array.from(e.querySelectorAll("slot")).filter((c) => !c.name.endsWith(n)).map((c) => [c.name += n, c]) Array.from(e.querySelectorAll("slot")).filter((c) => !c.name.endsWith(n)).map((c) => [c.name += n, c])
); );
if (t.append = new Proxy(t.append, { if (t.append = new Proxy(t.append, {
apply(c, u, a) { apply(c, u, a) {
if (a[0] === e) return c.apply(t, a); if (a[0] === e) return c.apply(t, a);
for (let l of a) { for (let h of a) {
let v = (l.slot || "") + n; let v = (h.slot || "") + n;
try { try {
bt(l, "remove", "slot"); bt(h, "remove", "slot");
} catch { } catch {
} }
let h = o[v]; let l = o[v];
if (!h) return; if (!l) return;
v.startsWith(r) || h.childNodes.forEach((m) => m.remove()), h.append(l), h.name = r + v; l.name.startsWith(r) || (l.childNodes.forEach((m) => m.remove()), l.name = r + v), l.append(h);
} }
return t.append = c, t; return t.append = c, t;
} }
@ -183,7 +188,7 @@ function nt(t, e, n) {
t, t,
e, e,
n, n,
(a, l) => nt.call(c, t, a, l) (a, h) => nt.call(c, t, a, h)
); );
let [u] = e; let [u] = e;
if (u === "=") return r(e.slice(1), n); if (u === "=") return r(e.slice(1), n);
@ -201,7 +206,7 @@ function nt(t, e, n) {
case "dataset": case "dataset":
return B(o, n, et.bind(null, t[e])); return B(o, n, et.bind(null, t[e]));
case "ariaset": case "ariaset":
return B(o, n, (a, l) => r("aria-" + a, l)); return B(o, n, (a, h) => r("aria-" + a, h));
case "classList": case "classList":
return ht.call(c, t, n); return ht.call(c, t, n);
} }
@ -261,7 +266,7 @@ function mt() {
let t = /* @__PURE__ */ new Map(), e = !1, n = (i) => function(s) { let t = /* @__PURE__ */ new Map(), e = !1, n = (i) => function(s) {
for (let f of s) for (let f of s)
if (f.type === "childList") { if (f.type === "childList") {
if (h(f.addedNodes, !0)) { if (l(f.addedNodes, !0)) {
i(); i();
continue; continue;
} }
@ -314,23 +319,23 @@ function mt() {
function a() { function a() {
!e || t.size || (e = !1, r.disconnect()); !e || t.size || (e = !1, r.disconnect());
} }
function l() { function h() {
return new Promise(function(i) { return new Promise(function(i) {
(requestIdleCallback || requestAnimationFrame)(i); (requestIdleCallback || requestAnimationFrame)(i);
}); });
} }
async function v(i) { async function v(i) {
t.size > 30 && await l(); t.size > 30 && await h();
let s = []; let s = [];
if (!(i instanceof Node)) return s; if (!(i instanceof Node)) return s;
for (let f of t.keys()) for (let f of t.keys())
f === i || !(f instanceof Node) || i.contains(f) && s.push(f); f === i || !(f instanceof Node) || i.contains(f) && s.push(f);
return s; return s;
} }
function h(i, s) { function l(i, s) {
let f = !1; let f = !1;
for (let b of i) { for (let b of i) {
if (s && v(b).then(h), !t.has(b)) continue; if (s && v(b).then(l), !t.has(b)) continue;
let L = t.get(b); let L = t.get(b);
L.length_c && (b.dispatchEvent(new Event(_)), L.connected = /* @__PURE__ */ new WeakSet(), L.length_c = 0, L.length_d || t.delete(b), f = !0); L.length_c && (b.dispatchEvent(new Event(_)), L.connected = /* @__PURE__ */ new WeakSet(), L.length_c = 0, L.length_d || t.delete(b), f = !0);
} }
@ -350,7 +355,7 @@ function mt() {
} }
// src/customElement.js // src/customElement.js
function Ht(t, e, n, r = wt) { function It(t, e, n, r = wt) {
x.push({ x.push({
scope: t, scope: t,
host: (...u) => u.length ? u.forEach((a) => a(t)) : t host: (...u) => u.length ? u.forEach((a) => a(t)) : t
@ -383,7 +388,7 @@ function wt(t) {
} }
// src/events.js // src/events.js
function Zt(t, e, n) { function Gt(t, e, n) {
return e || (e = {}), function(o, ...c) { return e || (e = {}), function(o, ...c) {
n && (c.unshift(o), o = typeof n == "function" ? n() : n); n && (c.unshift(o), o = typeof n == "function" ? n() : n);
let u = c.length ? new CustomEvent(t, Object.assign({ detail: c[0] }, e)) : new Event(t, e); let u = c.length ? new CustomEvent(t, Object.assign({ detail: c[0] }, e)) : new Event(t, e);
@ -417,9 +422,9 @@ w.attributeChanged = function(t, e) {
return typeof e != "object" && (e = {}), function(r) { return typeof e != "object" && (e = {}), function(r) {
if (r.addEventListener(T, t, e), r[O] || _t.has(r) || !d.M) return r; if (r.addEventListener(T, t, e), r[O] || _t.has(r) || !d.M) return r;
let o = new d.M(function(u) { let o = new d.M(function(u) {
for (let { attributeName: a, target: l } of u) for (let { attributeName: a, target: h } of u)
l.dispatchEvent( h.dispatchEvent(
new CustomEvent(T, { detail: [a, l.getAttribute(a)] }) new CustomEvent(T, { detail: [a, h.getAttribute(a)] })
); );
}); });
return P(e.signal, () => o.disconnect()) && o.observe(r, { attributes: !0 }), r; return P(e.signal, () => o.disconnect()) && o.observe(r, { attributes: !0 }), r;
@ -460,7 +465,7 @@ E.on = function t(e, n, r = {}) {
let { signal: o } = r; let { signal: o } = r;
if (!(o && o.aborted)) { if (!(o && o.aborted)) {
if (Array.isArray(e)) return e.forEach((c) => t(c, n, r)); if (Array.isArray(e)) return e.forEach((c) => t(c, n, r));
Q(e, n), o && o.addEventListener("abort", () => R(e, n)); K(e, n), o && o.addEventListener("abort", () => R(e, n));
} }
}; };
E.symbols = { E.symbols = {
@ -484,24 +489,24 @@ var D = "__dde_reactive";
E.el = function(t, e) { E.el = function(t, e) {
let n = M.mark({ type: "reactive" }, !0), r = n.end, o = d.D.createDocumentFragment(); let n = M.mark({ type: "reactive" }, !0), r = n.end, o = d.D.createDocumentFragment();
o.append(n, r); o.append(n, r);
let { current: c } = x, u = {}, a = (l) => { let { current: c } = x, u = {}, a = (h) => {
if (!n.parentNode || !r.parentNode) if (!n.parentNode || !r.parentNode)
return R(t, a); return R(t, a);
let v = u; let v = u;
u = {}, x.push(c); u = {}, x.push(c);
let h = e(l, function(s, f) { let l = e(h, function(s, f) {
let b; let b;
return I(v, s) ? (b = v[s], delete v[s]) : b = f(), u[s] = b, b; return I(v, s) ? (b = v[s], delete v[s]) : b = f(), u[s] = b, b;
}); });
x.pop(), Array.isArray(h) || (h = [h]); x.pop(), Array.isArray(l) || (l = [l]);
let m = document.createComment(""); let m = document.createComment("");
h.push(m), n.after(...h); l.push(m), n.after(...l);
let k; let k;
for (; (k = m.nextSibling) && k !== r; ) for (; (k = m.nextSibling) && k !== r; )
k.remove(); k.remove();
m.remove(), n.isConnected && yt(c.host()); m.remove(), n.isConnected && yt(c.host());
}; };
return Q(t, a), ut(t, a, n, e), a(t()), o; return K(t, a), ut(t, a, n, e), a(t()), o;
}; };
function yt(t) { function yt(t) {
!t || !t[D] || (requestIdleCallback || setTimeout)(function() { !t || !t[D] || (requestIdleCallback || setTimeout)(function() {
@ -515,7 +520,7 @@ var At = {
}; };
function Ot(t) { function Ot(t) {
return function(e, n) { return function(e, n) {
let r = (...c) => c.length ? e.setAttribute(n, ...c) : K(r), o = ft(r, e.getAttribute(n), At); let r = (...c) => c.length ? e.setAttribute(n, ...c) : V(r), o = ft(r, e.getAttribute(n), At);
return t[n] = o, o; return t[n] = o, o;
}; };
} }
@ -542,7 +547,7 @@ var st = {
return R(n, o); return R(n, o);
r(e, c); r(e, c);
}; };
return Q(n, o), ut(n, o, t, e), n(); return K(n, o), ut(n, o, t, e), n();
} }
}; };
function ut(t, e, ...n) { function ut(t, e, ...n) {
@ -560,14 +565,14 @@ function ut(t, e, ...n) {
}); });
} }
function it(t, e, n) { function it(t, e, n) {
let r = t ? () => K(r) : (...o) => o.length ? at(r, ...o) : K(r); let r = t ? () => V(r) : (...o) => o.length ? at(r, ...o) : V(r);
return ft(r, e, n, t); return ft(r, e, n, t);
} }
var St = Object.assign(/* @__PURE__ */ Object.create(null), { var St = Object.assign(/* @__PURE__ */ Object.create(null), {
stopPropagation() { stopPropagation() {
this.skip = !0; this.skip = !0;
} }
}), V = class extends Error { }), Q = class extends Error {
constructor() { constructor() {
super(); super();
let [e, ...n] = this.stack.split(` let [e, ...n] = this.stack.split(`
@ -588,7 +593,7 @@ function ft(t, e, n, r = !1) {
onclear: o, onclear: o,
host: u, host: u,
listeners: /* @__PURE__ */ new Set(), listeners: /* @__PURE__ */ new Set(),
defined: new V().stack, defined: new Q().stack,
readonly: r readonly: r
}, },
enumerable: !1, enumerable: !1,
@ -599,7 +604,7 @@ function ft(t, e, n, r = !1) {
function Ct() { function Ct() {
return z[z.length - 1]; return z[z.length - 1];
} }
function K(t) { function V(t) {
if (!t[p]) return; if (!t[p]) return;
let { value: e, listeners: n } = t[p], r = Ct(); let { value: e, listeners: n } = t[p], r = Ct();
return r && n.add(r), g.has(r) && g.get(r).add(t), e; return r && n.add(r), g.has(r) && g.get(r).add(t), e;
@ -610,7 +615,7 @@ function at(t, e, n) {
if (!(!n && r.value === e)) if (!(!n && r.value === e))
return r.value = e, r.listeners.forEach((o) => o(e)), e; return r.value = e, r.listeners.forEach((o) => o(e)), e;
} }
function Q(t, e) { function K(t, e) {
if (t[p]) if (t[p])
return t[p].listeners.add(e); return t[p].listeners.add(e);
} }
@ -633,15 +638,16 @@ export {
E as S, E as S,
q as assign, q as assign,
nt as assignAttribute, nt as assignAttribute,
Mt as asyncQueueAdd,
lt as chainableAppend, lt as chainableAppend,
ht as classListDeclarative, ht as classListDeclarative,
M as createElement, M as createElement,
Mt as createElementNS, jt as createElementNS,
Ht as customElementRender, It as customElementRender,
xt as customElementWithDDE, xt as customElementWithDDE,
Zt as dispatchEvent, Gt as dispatchEvent,
M as el, M as el,
Mt as elNS, jt as elNS,
bt as elementAttribute, bt as elementAttribute,
U as isSignal, U as isSignal,
xt as lifecyclesToEvents, xt as lifecyclesToEvents,
@ -650,5 +656,5 @@ export {
H as registerReactivity, H as registerReactivity,
x as scope, x as scope,
E as signal, E as signal,
jt as simulateSlots Pt as simulateSlots
}; };

12
dist/esm.d.ts vendored
View File

@ -72,7 +72,7 @@ export function el<
TAG extends keyof ExtendedHTMLElementTagNameMap, TAG extends keyof ExtendedHTMLElementTagNameMap,
>( >(
tag_name: TAG, tag_name: TAG,
attrs?: ElementAttributes<ExtendedHTMLElementTagNameMap[NoInfer<TAG>]> | ddeString, attrs?: ElementAttributes<ExtendedHTMLElementTagNameMap[NoInfer<TAG>]> | ddeStringable,
...addons: ddeElementAddon< ...addons: ddeElementAddon<
ExtendedHTMLElementTagNameMap[NoInfer<TAG>] ExtendedHTMLElementTagNameMap[NoInfer<TAG>]
>[], // TODO: for now addons must have the same element >[], // TODO: for now addons must have the same element
@ -82,7 +82,7 @@ export function el(
): ddeDocumentFragment ): ddeDocumentFragment
export function el( export function el(
tag_name: string, tag_name: string,
attrs?: ElementAttributes<HTMLElement> | ddeString, attrs?: ElementAttributes<HTMLElement> | ddeStringable,
...addons: ddeElementAddon<HTMLElement>[] ...addons: ddeElementAddon<HTMLElement>[]
): ddeHTMLElement ): ddeHTMLElement
@ -90,7 +90,7 @@ export function el<
C extends (attr: ddeComponentAttributes)=> SupportedElement | ddeDocumentFragment C extends (attr: ddeComponentAttributes)=> SupportedElement | ddeDocumentFragment
>( >(
component: C, component: C,
attrs?: Parameters<C>[0] | ddeString, attrs?: Parameters<C>[0] | ddeStringable,
...addons: ddeElementAddon<ReturnType<C>>[] ...addons: ddeElementAddon<ReturnType<C>>[]
): ReturnType<C> extends ddeHTMLElementTagNameMap[keyof ddeHTMLElementTagNameMap] ): ReturnType<C> extends ddeHTMLElementTagNameMap[keyof ddeHTMLElementTagNameMap]
? ReturnType<C> ? ReturnType<C>
@ -104,7 +104,7 @@ export function elNS(
EL extends ( TAG extends keyof SVGElementTagNameMap ? SVGElementTagNameMap[TAG] : SVGElement ), EL extends ( TAG extends keyof SVGElementTagNameMap ? SVGElementTagNameMap[TAG] : SVGElement ),
>( >(
tag_name: TAG, tag_name: TAG,
attrs?: ElementAttributes<NoInfer<EL>> | ddeString, attrs?: ElementAttributes<NoInfer<EL>> | ddeStringable,
...addons: ddeElementAddon<NoInfer<EL>>[] ...addons: ddeElementAddon<NoInfer<EL>>[]
)=> TAG extends keyof ddeSVGElementTagNameMap ? ddeSVGElementTagNameMap[TAG] : ddeSVGElement )=> TAG extends keyof ddeSVGElementTagNameMap ? ddeSVGElementTagNameMap[TAG] : ddeSVGElement
export function elNS( export function elNS(
@ -114,7 +114,7 @@ export function elNS(
EL extends ( TAG extends keyof MathMLElementTagNameMap ? MathMLElementTagNameMap[TAG] : MathMLElement ), EL extends ( TAG extends keyof MathMLElementTagNameMap ? MathMLElementTagNameMap[TAG] : MathMLElement ),
>( >(
tag_name: TAG, tag_name: TAG,
attrs?: ddeString | Partial<{ attrs?: ddeStringable | Partial<{
[key in keyof EL]: EL[key] | ddeSignal<EL[key]> | string | number | boolean [key in keyof EL]: EL[key] | ddeSignal<EL[key]> | string | number | boolean
}>, }>,
...addons: ddeElementAddon<NoInfer<EL>>[] ...addons: ddeElementAddon<NoInfer<EL>>[]
@ -123,7 +123,7 @@ export function elNS(
namespace: string namespace: string
): ( ): (
tag_name: string, tag_name: string,
attrs?: string | ddeString | Record<string, any>, attrs?: string | ddeStringable | Record<string, any>,
...addons: ddeElementAddon<SupportedElement>[] ...addons: ddeElementAddon<SupportedElement>[]
)=> SupportedElement )=> SupportedElement
export { elNS as createElementNS } export { elNS as createElementNS }

102
dist/esm.js vendored
View File

@ -38,15 +38,17 @@ function G(t) {
// src/dom-common.js // src/dom-common.js
var f = { var f = {
setDeleteAttr: V, setDeleteAttr: Q,
ssr: "", ssr: "",
D: globalThis.document, D: globalThis.document,
F: globalThis.DocumentFragment, F: globalThis.DocumentFragment,
H: globalThis.HTMLElement, H: globalThis.HTMLElement,
S: globalThis.SVGElement, S: globalThis.SVGElement,
M: globalThis.MutationObserver M: globalThis.MutationObserver,
qa: (t) => t,
qw: () => Promise.resolve()
}; };
function V(t, e, n) { function Q(t, e, n) {
if (Reflect.set(t, e, n), !!x(n)) { if (Reflect.set(t, e, n), !!x(n)) {
if (Reflect.deleteProperty(t, e), t instanceof f.H && t.getAttribute(e) === "undefined") if (Reflect.deleteProperty(t, e), t instanceof f.H && t.getAttribute(e) === "undefined")
return t.removeAttribute(e); return t.removeAttribute(e);
@ -54,10 +56,13 @@ function V(t, e, n) {
return Reflect.set(t, e, ""); return Reflect.set(t, e, "");
} }
} }
var w = "__dde_lifecyclesToEvents", g = "dde:connected", y = "dde:disconnected", O = "dde:attributeChanged"; var w = "__dde_lifecyclesToEvents", v = "dde:connected", m = "dde:disconnected", O = "dde:attributeChanged";
// src/dom.js // src/dom.js
var v = [{ function dt(t) {
return f.qa(t);
}
var g = [{
get scope() { get scope() {
return f.D.body; return f.D.body;
}, },
@ -65,7 +70,7 @@ var v = [{
prevent: !0 prevent: !0
}], D = { }], D = {
get current() { get current() {
return v[v.length - 1]; return g[g.length - 1];
}, },
get host() { get host() {
return this.current.host; return this.current.host;
@ -75,27 +80,27 @@ var v = [{
return t.prevent = !0, t; return t.prevent = !0, t;
}, },
get state() { get state() {
return [...v]; return [...g];
}, },
push(t = {}) { push(t = {}) {
return v.push(Object.assign({}, this.current, { prevent: !1 }, t)); return g.push(Object.assign({}, this.current, { prevent: !1 }, t));
}, },
pushRoot() { pushRoot() {
return v.push(v[0]); return g.push(g[0]);
}, },
pop() { pop() {
if (v.length !== 1) if (g.length !== 1)
return v.pop(); return g.pop();
} }
}; };
function q(...t) { function q(...t) {
return this.appendOriginal(...t), this; return this.appendOriginal(...t), this;
} }
function J(t) { function V(t) {
return t.append === q || (t.appendOriginal = t.append, t.append = q), t; return t.append === q || (t.appendOriginal = t.append, t.append = q), t;
} }
var T; var T;
function k(t, e, ...n) { function P(t, e, ...n) {
let r = S(this), o = 0, c, a; let r = S(this), o = 0, c, a;
switch ((Object(e) !== e || r.isSignal(e)) && (e = { textContent: e }), !0) { switch ((Object(e) !== e || r.isSignal(e)) && (e = { textContent: e }), !0) {
case typeof t == "function": { case typeof t == "function": {
@ -104,7 +109,7 @@ function k(t, e, ...n) {
D.push({ scope: t, host: d }), c = t(e || void 0); D.push({ scope: t, host: d }), c = t(e || void 0);
let p = c instanceof f.F; let p = c instanceof f.F;
if (c.nodeName === "#comment") break; if (c.nodeName === "#comment") break;
let b = k.mark({ let b = P.mark({
type: "component", type: "component",
name: t.name, name: t.name,
host: p ? "this" : "parentElement" host: p ? "this" : "parentElement"
@ -124,22 +129,22 @@ function k(t, e, ...n) {
case !c: case !c:
c = R.call(this, f.D.createElement(t), e); c = R.call(this, f.D.createElement(t), e);
} }
return J(c), a || (a = c), n.forEach((d) => d(a)), o && D.pop(), o = 2, c; return V(c), a || (a = c), n.forEach((d) => d(a)), o && D.pop(), o = 2, c;
} }
k.mark = function(t, e = !1) { P.mark = function(t, e = !1) {
t = Object.entries(t).map(([o, c]) => o + `="${c}"`).join(" "); t = Object.entries(t).map(([o, c]) => o + `="${c}"`).join(" ");
let n = e ? "" : "/", r = f.D.createComment(`<dde:mark ${t}${f.ssr}${n}>`); let n = e ? "" : "/", r = f.D.createComment(`<dde:mark ${t}${f.ssr}${n}>`);
return e && (r.end = f.D.createComment("</dde:mark>")), r; return e && (r.end = f.D.createComment("</dde:mark>")), r;
}; };
function dt(t) { function pt(t) {
let e = this; let e = this;
return function(...r) { return function(...r) {
T = t; T = t;
let o = k.call(e, ...r); let o = P.call(e, ...r);
return T = void 0, o; return T = void 0, o;
}; };
} }
function pt(t, e = t) { function ht(t, e = t) {
let n = "\xB9\u2070", r = "\u2713", o = Object.fromEntries( let n = "\xB9\u2070", r = "\u2713", o = Object.fromEntries(
Array.from(e.querySelectorAll("slot")).filter((c) => !c.name.endsWith(n)).map((c) => [c.name += n, c]) Array.from(e.querySelectorAll("slot")).filter((c) => !c.name.endsWith(n)).map((c) => [c.name += n, c])
); );
@ -149,12 +154,12 @@ function pt(t, e = t) {
for (let p of d) { for (let p of d) {
let b = (p.slot || "") + n; let b = (p.slot || "") + n;
try { try {
Q(p, "remove", "slot"); K(p, "remove", "slot");
} catch { } catch {
} }
let h = o[b]; let h = o[b];
if (!h) return; if (!h) return;
b.startsWith(r) || h.childNodes.forEach((E) => E.remove()), h.append(p), h.name = r + b; h.name.startsWith(r) || (h.childNodes.forEach((E) => E.remove()), h.name = r + b), h.append(p);
} }
return t.append = c, t; return t.append = c, t;
} }
@ -198,7 +203,7 @@ function U(t, e, n) {
case "ariaset": case "ariaset":
return M(o, n, (d, p) => r("aria-" + d, p)); return M(o, n, (d, p) => r("aria-" + d, p));
case "classList": case "classList":
return K.call(c, t, n); return J.call(c, t, n);
} }
return X(t, e) ? $(t, e, n) : r(e, n); return X(t, e) ? $(t, e, n) : r(e, n);
} }
@ -207,7 +212,7 @@ function H(t, e) {
let r = (t instanceof f.S ? tt : Y).bind(null, t, "Attribute"), o = S(e); let r = (t instanceof f.S ? tt : Y).bind(null, t, "Attribute"), o = S(e);
return { setRemoveAttr: r, s: o }; return { setRemoveAttr: r, s: o };
} }
function K(t, e) { function J(t, e) {
let n = S(this); let n = S(this);
return M( return M(
n, n,
@ -215,7 +220,7 @@ function K(t, e) {
(r, o) => t.classList.toggle(r, o === -1 ? void 0 : !!o) (r, o) => t.classList.toggle(r, o === -1 ? void 0 : !!o)
), t; ), t;
} }
function Q(t, e, n, r) { function K(t, e, n, r) {
return t instanceof f.H ? t[e + "Attribute"](n, r) : t[e + "AttributeNS"](null, n, r); return t instanceof f.H ? t[e + "Attribute"](n, r) : t[e + "AttributeNS"](null, n, r);
} }
function X(t, e) { function X(t, e) {
@ -246,7 +251,7 @@ function F(t, e, n) {
} }
// src/events-observer.js // src/events-observer.js
var m = f.M ? et() : new Proxy({}, { var y = f.M ? et() : new Proxy({}, {
get() { get() {
return () => { return () => {
}; };
@ -327,7 +332,7 @@ function et() {
for (let l of s) { for (let l of s) {
if (u && b(l).then(h), !t.has(l)) continue; if (u && b(l).then(h), !t.has(l)) continue;
let A = t.get(l); let A = t.get(l);
A.length_c && (l.dispatchEvent(new Event(g)), A.connected = /* @__PURE__ */ new WeakSet(), A.length_c = 0, A.length_d || t.delete(l), i = !0); A.length_c && (l.dispatchEvent(new Event(v)), A.connected = /* @__PURE__ */ new WeakSet(), A.length_c = 0, A.length_d || t.delete(l), i = !0);
} }
return i; return i;
} }
@ -339,13 +344,13 @@ function et() {
} }
function I(s) { function I(s) {
return () => { return () => {
s.isConnected || (s.dispatchEvent(new Event(y)), t.delete(s)); s.isConnected || (s.dispatchEvent(new Event(m)), t.delete(s));
}; };
} }
} }
// src/customElement.js // src/customElement.js
function wt(t, e, n, r = rt) { function mt(t, e, n, r = rt) {
D.push({ D.push({
scope: t, scope: t,
host: (...a) => a.length ? a.forEach((d) => d(t)) : t host: (...a) => a.length ? a.forEach((d) => d(t)) : t
@ -353,23 +358,23 @@ function wt(t, e, n, r = rt) {
let o = t[w]; let o = t[w];
o || nt(t); o || nt(t);
let c = n.call(t, r); let c = n.call(t, r);
return o || t.dispatchEvent(new Event(g)), e.nodeType === 11 && typeof e.mode == "string" && t.addEventListener(y, m.observe(e), { once: !0 }), D.pop(), e.append(c); return o || t.dispatchEvent(new Event(v)), e.nodeType === 11 && typeof e.mode == "string" && t.addEventListener(m, y.observe(e), { once: !0 }), D.pop(), e.append(c);
} }
function nt(t) { function nt(t) {
return P(t.prototype, "connectedCallback", function(e, n, r) { return k(t.prototype, "connectedCallback", function(e, n, r) {
e.apply(n, r), n.dispatchEvent(new Event(g)); e.apply(n, r), n.dispatchEvent(new Event(v));
}), P(t.prototype, "disconnectedCallback", function(e, n, r) { }), k(t.prototype, "disconnectedCallback", function(e, n, r) {
e.apply(n, r), (globalThis.queueMicrotask || setTimeout)( e.apply(n, r), (globalThis.queueMicrotask || setTimeout)(
() => !n.isConnected && n.dispatchEvent(new Event(y)) () => !n.isConnected && n.dispatchEvent(new Event(m))
); );
}), P(t.prototype, "attributeChangedCallback", function(e, n, r) { }), k(t.prototype, "attributeChangedCallback", function(e, n, r) {
let [o, , c] = r; let [o, , c] = r;
n.dispatchEvent(new CustomEvent(O, { n.dispatchEvent(new CustomEvent(O, {
detail: [o, c] detail: [o, c]
})), e.apply(n, r); })), e.apply(n, r);
}), t.prototype[w] = !0, t; }), t.prototype[w] = !0, t;
} }
function P(t, e, n) { function k(t, e, n) {
t[e] = new Proxy(t[e] || (() => { t[e] = new Proxy(t[e] || (() => {
}), { apply: n }); }), { apply: n });
} }
@ -378,7 +383,7 @@ function rt(t) {
} }
// src/events.js // src/events.js
function Ct(t, e, n) { function Ot(t, e, n) {
return e || (e = {}), function(o, ...c) { return e || (e = {}), function(o, ...c) {
n && (c.unshift(o), o = typeof n == "function" ? n() : n); n && (c.unshift(o), o = typeof n == "function" ? n() : n);
let a = c.length ? new CustomEvent(t, Object.assign({ detail: c[0] }, e)) : new Event(t, e); let a = c.length ? new CustomEvent(t, Object.assign({ detail: c[0] }, e)) : new Event(t, e);
@ -393,12 +398,12 @@ function _(t, e, n) {
var B = (t) => Object.assign({}, typeof t == "object" ? t : null, { once: !0 }); var B = (t) => Object.assign({}, typeof t == "object" ? t : null, { once: !0 });
_.connected = function(t, e) { _.connected = function(t, e) {
return e = B(e), function(r) { return e = B(e), function(r) {
return r.addEventListener(g, t, e), r[w] ? r : r.isConnected ? (r.dispatchEvent(new Event(g)), r) : (L(e.signal, () => m.offConnected(r, t)) && m.onConnected(r, t), r); return r.addEventListener(v, t, e), r[w] ? r : r.isConnected ? (r.dispatchEvent(new Event(v)), r) : (L(e.signal, () => y.offConnected(r, t)) && y.onConnected(r, t), r);
}; };
}; };
_.disconnected = function(t, e) { _.disconnected = function(t, e) {
return e = B(e), function(r) { return e = B(e), function(r) {
return r.addEventListener(y, t, e), r[w] || L(e.signal, () => m.offDisconnected(r, t)) && m.onDisconnected(r, t), r; return r.addEventListener(m, t, e), r[w] || L(e.signal, () => y.offDisconnected(r, t)) && y.onDisconnected(r, t), r;
}; };
}; };
var j = /* @__PURE__ */ new WeakMap(); var j = /* @__PURE__ */ new WeakMap();
@ -423,20 +428,21 @@ _.attributeChanged = function(t, e) {
export { export {
R as assign, R as assign,
U as assignAttribute, U as assignAttribute,
J as chainableAppend, dt as asyncQueueAdd,
K as classListDeclarative, V as chainableAppend,
k as createElement, J as classListDeclarative,
dt as createElementNS, P as createElement,
wt as customElementRender, pt as createElementNS,
mt as customElementRender,
nt as customElementWithDDE, nt as customElementWithDDE,
Ct as dispatchEvent, Ot as dispatchEvent,
k as el, P as el,
dt as elNS, pt as elNS,
Q as elementAttribute, K as elementAttribute,
nt as lifecyclesToEvents, nt as lifecyclesToEvents,
rt as observedAttributes, rt as observedAttributes,
_ as on, _ as on,
Z as registerReactivity, Z as registerReactivity,
D as scope, D as scope,
pt as simulateSlots ht as simulateSlots
}; };