1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2024-11-21 23:39:37 +01:00
This commit is contained in:
Jan Andrle 2023-09-13 13:20:00 +02:00
parent 5436e50a95
commit d7e0b17e38
Signed by: jaandrle
GPG Key ID: B3A25AED155AFFAB
6 changed files with 390 additions and 376 deletions

View File

@ -1,7 +1,26 @@
//deka-dom-el library is available via global namespace `dde`
(()=> {
// src/signals-common.js
var x = {
isTextContent(e) {
return typeof e == "string";
},
processReactiveAttribute(e, t, r, n) {
return r;
}
};
function _(e, t = !0) {
return t ? Object.assign(x, e) : (Object.setPrototypeOf(e, x), e);
}
function N(e) {
return x.isPrototypeOf(e) && e !== x ? e : x;
}
// src/helpers.js
function m(e) {
return typeof e > "u";
}
function w(e) {
let t = typeof e;
return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e);
}
@ -14,75 +33,65 @@
};
}
// src/signals-common.js
var b = {
isTextContent(e) {
return m(e) !== "[object Object]";
},
processReactiveAttribute(e, t, r, n) {
return r;
}
};
function N(e, t = !0) {
return t ? Object.assign(b, e) : (Object.setPrototypeOf(e, b), e);
}
function A(e) {
return b.isPrototypeOf(e) && e !== b ? e : b;
// src/dom-common.js
var b = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')), T = { setDelete: $ };
function $(e, t, r) {
Reflect.set(e, t, r), m(r) && e.getAttribute(t) === "undefined" && e.removeAttribute(t);
}
// src/dom.js
var O = "html";
function te(e) {
return O = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
var S = "html";
function oe(e) {
return S = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(t) {
return O = "html", t;
return S = "html", t;
}
};
}
function ne(e, t, ...r) {
let n = A(this), o;
function ce(e, t, ...r) {
let n = N(this), o;
switch (n.isTextContent(t) && (t = { textContent: t }), !0) {
case typeof e == "function": {
o = e(t || void 0, (i) => i ? (r.unshift(i), void 0) : o);
break;
}
case e === "#text":
o = w(document.createTextNode(""), t);
o = y(document.createTextNode(""), t);
break;
case e === "<>":
o = w(document.createDocumentFragment(), t);
o = y(document.createDocumentFragment(), t);
break;
case O !== "html":
o = w(document.createElementNS(O, e), t);
case S !== "html":
o = y(document.createElementNS(S, e), t);
break;
case !o:
o = w(document.createElement(e), t);
o = y(document.createElement(e), t);
}
return r.forEach((a) => a(o)), o;
}
var x = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]'));
function w(e, ...t) {
let r = A(this);
var { setDelete: D } = T;
function y(e, ...t) {
let r = N(this);
if (!t.length)
return e;
let n = e instanceof SVGElement, o = (n ? J : T).bind(null, e, "Attribute");
let n = e instanceof SVGElement, o = (n ? W : M).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function a([i, s]) {
s = r.processReactiveAttribute(e, i, s, a);
let [h] = i;
if (h === "=")
return o(i.slice(1), s);
if (h === ".")
return _(e, i.slice(1), s);
return D(e, i.slice(1), s);
if (typeof s == "object")
switch (i) {
case "style":
return y(s, T.bind(null, e.style, "Property"));
return O(s, M.bind(null, e.style, "Property"));
case "dataset":
return y(s, _.bind(null, e.dataset));
return O(s, D.bind(null, e.dataset));
case "ariaset":
return y(s, (E, v) => o("aria-" + E, v));
return O(s, (E, v) => o("aria-" + E, v));
case "classList":
return $(e, s);
return q(e, s);
default:
return Reflect.set(e, i, s);
}
@ -98,72 +107,66 @@
break;
return e.appendChild(document.createTextNode(s));
}
return q(e, i) ? _(e, i, s) : o(i, s);
return J(e, i) ? D(e, i, s) : o(i, s);
}), e;
}
function $(e, t) {
return typeof t != "object" || y(
function q(e, t) {
return typeof t != "object" || O(
t,
(r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n)
), e;
}
function re(e) {
function se(e) {
return Array.from(e.children).forEach((t) => t.remove()), e;
}
function q(e, t) {
function J(e, t) {
let r = "HTMLElement," + t;
if (e instanceof HTMLElement && x.has(r))
return x.get(r);
if (e instanceof HTMLElement && b.has(r))
return b.get(r);
let n = e.nodeName + "," + t;
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;
if (b.has(n))
return b.get(n);
let [o, a, i] = H(e, t), s = !m(o.set);
return (!s || a) && b.set(i === HTMLElement.prototype ? r : n, s), s;
}
function M(e, t, r = 0) {
function H(e, t, r = 0) {
if (e = Object.getPrototypeOf(e), !e)
return [{}, r, e];
let n = Object.getOwnPropertyDescriptor(e, t);
return n ? [n, r, e] : M(e, t, r + 1);
return n ? [n, r, e] : H(e, t, r + 1);
}
function y(e, t) {
function O(e, t) {
return Object.entries(e).forEach(([r, n]) => t(r, n));
}
function P(e) {
return typeof e > "u";
function M(e, t, r, n) {
return e[(m(n) ? "remove" : "set") + t](r, n);
}
function T(e, t, r, n) {
return e[(P(n) ? "remove" : "set") + t](r, n);
}
function J(e, t, r, n, o = null) {
return e[(P(n) ? "remove" : "set") + t + "NS"](o, r, n);
}
function _(e, t, r) {
return Reflect.set(e, t, r);
function W(e, t, r, n, o = null) {
return e[(m(n) ? "remove" : "set") + t + "NS"](o, r, n);
}
// src/events.js
function ce(e, t, ...r) {
function ae(e, t, ...r) {
let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t);
return e.dispatchEvent(n);
}
function H(e, t, r) {
function k(e, t, r) {
return function(o) {
return o.addEventListener(e, t, r), o;
};
}
var S = W();
H.connected = function(e, t) {
var C = I();
k.connected = function(e, t) {
return function(n) {
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);
return typeof n.connectedCallback == "function" ? (n.addEventListener("dde:connected", e, t), n) : (j(t && t.signal, () => C.offConnected(n, e)) && (n.isConnected ? e(new Event("dde:connected")) : C.onConnected(n, e)), n);
};
};
H.disconnected = function(e, t) {
k.disconnected = function(e, t) {
return function(n) {
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);
return typeof n.disconnectedCallback == "function" ? (n.addEventListener("dde:disconnected", e, t), n) : (j(t && t.signal, () => C.offDisconnected(n, e)) && C.onDisconnected(n, e), n);
};
};
function W() {
function I() {
let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(c) {
for (let f of c)
if (f.type === "childList") {
@ -228,7 +231,7 @@
if (f && h(u).then(E), !e.has(u))
continue;
let p = e.get(u);
return p.connected.forEach((R) => R(u)), p.connected.length = 0, p.disconnected.length || e.delete(u), !0;
return p.connected.forEach((A) => A(u)), p.connected.length = 0, p.disconnected.length || e.delete(u), !0;
}
return !1;
}
@ -237,7 +240,7 @@
if (f && h(u).then(v), !e.has(u))
continue;
let p = e.get(u);
return p.disconnected.forEach((R) => R(u)), p.connected.length = 0, p.disconnected.length = 0, e.delete(u), !0;
return p.disconnected.forEach((A) => A(u)), p.connected.length = 0, p.disconnected.length = 0, e.delete(u), !0;
}
return !1;
}
@ -253,7 +256,7 @@
// src/signals-lib.js
var d = Symbol.for("Signal");
function C(e) {
function L(e) {
try {
return Reflect.has(e, d);
} catch {
@ -263,11 +266,11 @@
var l = /* @__PURE__ */ new WeakMap();
function g(e, t) {
if (typeof e != "function")
return k(e, t);
if (C(e))
return z(e, t);
if (L(e))
return e;
let r = k(""), n = () => r(e());
return l.set(n, /* @__PURE__ */ new Set([r])), Z(n), r;
let r = z(""), n = () => r(e());
return l.set(n, /* @__PURE__ */ new Set([r])), G(n), r;
}
g.action = function(e, t, ...r) {
let n = e[d], { actions: o } = n;
@ -282,7 +285,7 @@
if (!(o && o.aborted)) {
if (Array.isArray(t))
return t.forEach((a) => e(a, r, n));
D(t, r), o && o.addEventListener("abort", () => F(t, r));
P(t, r), o && o.addEventListener("abort", () => U(t, r));
}
};
g.symbols = {
@ -309,7 +312,7 @@
o.append(r, n);
let a = (i) => {
if (!r.parentNode || !n.parentNode)
return F(e, a);
return U(e, a);
let s = t(i);
Array.isArray(s) || (s = [s]);
let h = r;
@ -317,82 +320,82 @@
h.remove();
r.after(...s);
};
return D(e, a), a(e()), o;
return P(e, a), a(e()), o;
};
var z = {
var F = {
isTextContent(e) {
return m(e) === "string" || C(e) && m(K(e)) === "string";
return w(e) === "string" || L(e) && w(X(e)) === "string";
},
processReactiveAttribute(e, t, r, n) {
return C(r) ? (D(r, (o) => n([t, o])), r()) : r;
return L(r) ? (P(r, (o) => n([t, o])), r()) : r;
}
};
function k(e, t) {
let r = (...n) => n.length ? V(r, n[0]) : G(r);
return U(r, e, t);
function z(e, t) {
let r = (...n) => n.length ? Q(r, n[0]) : K(r);
return B(r, e, t);
}
var I = Object.assign(/* @__PURE__ */ Object.create(null), {
var Z = Object.assign(/* @__PURE__ */ Object.create(null), {
stopPropagation() {
this.skip = !0;
}
});
function U(e, t, r) {
return m(r) !== "[object Object]" && (r = {}), e[d] = {
function B(e, t, r) {
return w(r) !== "[object Object]" && (r = {}), e[d] = {
value: t,
actions: r,
listeners: /* @__PURE__ */ new Set()
}, e.toJSON = () => e(), Object.setPrototypeOf(e[d], I), e;
}, e.toJSON = () => e(), Object.setPrototypeOf(e[d], Z), e;
}
var L = [];
function Z(e) {
var R = [];
function G(e) {
let t = function() {
L.push(t), e(), L.pop();
R.push(t), e(), R.pop();
};
l.has(e) && (l.set(t, l.get(e)), l.delete(e)), t();
}
function B() {
return L[L.length - 1];
function V() {
return R[R.length - 1];
}
function G(e) {
function K(e) {
if (!e[d])
return;
let { value: t, listeners: r } = e[d], n = B();
let { value: t, listeners: r } = e[d], n = V();
return n && r.add(n), l.has(n) && l.get(n).add(e), t;
}
function V(e, t) {
function Q(e, t) {
if (!e[d])
return;
let r = e[d];
if (r.value !== t)
return r.value = t, r.listeners.forEach((n) => n(t)), t;
}
function K(e) {
function X(e) {
return e[d].value;
}
function D(e, t) {
function P(e, t) {
if (e[d])
return e[d].listeners.add(t);
}
function F(e, t) {
function U(e, t) {
if (e[d])
return e[d].listeners.delete(t);
}
// src/signals.js
N(z);
_(F);
globalThis.dde= {
S: g,
assign: w,
classListDeclarative: $,
createElement: ne,
dispatchEvent: ce,
el: ne,
empty: re,
isSignal: C,
namespace: te,
on: H,
registerReactivity: N
assign: y,
classListDeclarative: q,
createElement: ce,
dispatchEvent: ae,
el: ce,
empty: se,
isSignal: L,
namespace: oe,
on: k,
registerReactivity: _
};
})();

155
dist/dde.js vendored
View File

@ -1,11 +1,26 @@
//deka-dom-el library is available via global namespace `dde`
(()=> {
// src/helpers.js
function N(e) {
let t = typeof e;
return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e);
// src/signals-common.js
var g = {
isTextContent(e) {
return typeof e == "string";
},
processReactiveAttribute(e, t, r, n) {
return r;
}
function O(e, t) {
};
function T(e, t = !0) {
return t ? Object.assign(g, e) : (Object.setPrototypeOf(e, g), e);
}
function O(e) {
return g.isPrototypeOf(e) && e !== g ? e : g;
}
// src/helpers.js
function p(e) {
return typeof e > "u";
}
function L(e, t) {
if (!e || !(e instanceof AbortSignal))
return !0;
if (!e.aborted)
@ -14,33 +29,23 @@
};
}
// src/signals-common.js
var l = {
isTextContent(e) {
return N(e) !== "[object Object]";
},
processReactiveAttribute(e, t, r, n) {
return r;
}
};
function D(e, t = !0) {
return t ? Object.assign(l, e) : (Object.setPrototypeOf(e, l), e);
}
function C(e) {
return l.isPrototypeOf(e) && e !== l ? e : l;
// src/dom-common.js
var h = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')), A = { setDelete: R };
function R(e, t, r) {
Reflect.set(e, t, r), p(r) && e.getAttribute(t) === "undefined" && e.removeAttribute(t);
}
// src/dom.js
var v = "html";
function F(e) {
return v = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
var m = "html";
function I(e) {
return m = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(t) {
return v = "html", t;
return m = "html", t;
}
};
}
function I(e, t, ...r) {
let n = C(this), c;
function Z(e, t, ...r) {
let n = O(this), c;
switch (n.isTextContent(t) && (t = { textContent: t }), !0) {
case typeof e == "function": {
c = e(t || void 0, (s) => s ? (r.unshift(s), void 0) : c);
@ -52,37 +57,37 @@
case e === "<>":
c = E(document.createDocumentFragment(), t);
break;
case v !== "html":
c = E(document.createElementNS(v, e), t);
case m !== "html":
c = E(document.createElementNS(m, e), t);
break;
case !c:
c = E(document.createElement(e), t);
}
return r.forEach((a) => a(c)), c;
}
var h = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]'));
var { setDelete: y } = A;
function E(e, ...t) {
let r = C(this);
let r = O(this);
if (!t.length)
return e;
let n = e instanceof SVGElement, c = (n ? S : j).bind(null, e, "Attribute");
let n = e instanceof SVGElement, c = (n ? S : N).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function a([s, f]) {
f = r.processReactiveAttribute(e, s, f, a);
let [p] = s;
if (p === "=")
let [l] = s;
if (l === "=")
return c(s.slice(1), f);
if (p === ".")
return L(e, s.slice(1), f);
if (l === ".")
return y(e, s.slice(1), f);
if (typeof f == "object")
switch (s) {
case "style":
return x(f, j.bind(null, e.style, "Property"));
return v(f, N.bind(null, e.style, "Property"));
case "dataset":
return x(f, L.bind(null, e.dataset));
return v(f, y.bind(null, e.dataset));
case "ariaset":
return x(f, (g, b) => c("aria-" + g, b));
return v(f, (x, b) => c("aria-" + x, b));
case "classList":
return R(e, f);
return j(e, f);
default:
return Reflect.set(e, s, f);
}
@ -98,16 +103,16 @@
break;
return e.appendChild(document.createTextNode(f));
}
return M(e, s) ? L(e, s, f) : c(s, f);
return M(e, s) ? y(e, s, f) : c(s, f);
}), e;
}
function R(e, t) {
return typeof t != "object" || x(
function j(e, t) {
return typeof t != "object" || v(
t,
(r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n)
), e;
}
function U(e) {
function B(e) {
return Array.from(e.children).forEach((t) => t.remove()), e;
}
function M(e, t) {
@ -117,57 +122,51 @@
let n = e.nodeName + "," + t;
if (h.has(n))
return h.get(n);
let [c, a, s] = A(e, t), f = !y(c.set);
let [c, a, s] = _(e, t), f = !p(c.set);
return (!f || a) && h.set(s === HTMLElement.prototype ? r : n, f), f;
}
function A(e, t, r = 0) {
function _(e, t, r = 0) {
if (e = Object.getPrototypeOf(e), !e)
return [{}, r, e];
let n = Object.getOwnPropertyDescriptor(e, t);
return n ? [n, r, e] : A(e, t, r + 1);
return n ? [n, r, e] : _(e, t, r + 1);
}
function x(e, t) {
function v(e, t) {
return Object.entries(e).forEach(([r, n]) => t(r, n));
}
function y(e) {
return typeof e > "u";
}
function j(e, t, r, n) {
return e[(y(n) ? "remove" : "set") + t](r, n);
function N(e, t, r, n) {
return e[(p(n) ? "remove" : "set") + t](r, n);
}
function S(e, t, r, n, c = null) {
return e[(y(n) ? "remove" : "set") + t + "NS"](c, r, n);
}
function L(e, t, r) {
return Reflect.set(e, t, r);
return e[(p(n) ? "remove" : "set") + t + "NS"](c, r, n);
}
// src/events.js
function $(e, t, ...r) {
function V(e, t, ...r) {
let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t);
return e.dispatchEvent(n);
}
function T(e, t, r) {
function D(e, t, r) {
return function(c) {
return c.addEventListener(e, t, r), c;
};
}
var m = _();
T.connected = function(e, t) {
var w = P();
D.connected = function(e, t) {
return function(n) {
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);
return typeof n.connectedCallback == "function" ? (n.addEventListener("dde:connected", e, t), n) : (L(t && t.signal, () => w.offConnected(n, e)) && (n.isConnected ? e(new Event("dde:connected")) : w.onConnected(n, e)), n);
};
};
T.disconnected = function(e, t) {
D.disconnected = function(e, t) {
return function(n) {
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);
return typeof n.disconnectedCallback == "function" ? (n.addEventListener("dde:disconnected", e, t), n) : (L(t && t.signal, () => w.offDisconnected(n, e)) && w.onDisconnected(n, e), n);
};
};
function _() {
function P() {
let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(o) {
for (let i of o)
if (i.type === "childList") {
if (g(i.addedNodes, !0)) {
if (x(i.addedNodes, !0)) {
s();
continue;
}
@ -214,7 +213,7 @@
(requestIdleCallback || requestAnimationFrame)(o);
});
}
async function p(o) {
async function l(o) {
e.size > 30 && await f();
let i = [];
if (!(o instanceof Node))
@ -223,21 +222,21 @@
u === o || !(u instanceof Node) || o.contains(u) && i.push(u);
return i;
}
function g(o, i) {
function x(o, i) {
for (let u of o) {
if (i && p(u).then(g), !e.has(u))
if (i && l(u).then(x), !e.has(u))
continue;
let d = e.get(u);
return d.connected.forEach((w) => w(u)), d.connected.length = 0, d.disconnected.length || e.delete(u), !0;
return d.connected.forEach((C) => C(u)), d.connected.length = 0, d.disconnected.length || e.delete(u), !0;
}
return !1;
}
function b(o, i) {
for (let u of o) {
if (i && p(u).then(b), !e.has(u))
if (i && l(u).then(b), !e.has(u))
continue;
let d = e.get(u);
return d.disconnected.forEach((w) => w(u)), d.connected.length = 0, d.disconnected.length = 0, e.delete(u), !0;
return d.disconnected.forEach((C) => C(u)), d.connected.length = 0, d.disconnected.length = 0, e.delete(u), !0;
}
return !1;
}
@ -253,14 +252,14 @@
globalThis.dde= {
assign: E,
classListDeclarative: R,
createElement: I,
dispatchEvent: $,
el: I,
empty: U,
namespace: F,
on: T,
registerReactivity: D
classListDeclarative: j,
createElement: Z,
dispatchEvent: V,
el: Z,
empty: B,
namespace: I,
on: D,
registerReactivity: T
};
})();

View File

@ -1,5 +1,24 @@
// src/signals-common.js
var x = {
isTextContent(e) {
return typeof e == "string";
},
processReactiveAttribute(e, t, r, n) {
return r;
}
};
function _(e, t = !0) {
return t ? Object.assign(x, e) : (Object.setPrototypeOf(e, x), e);
}
function N(e) {
return x.isPrototypeOf(e) && e !== x ? e : x;
}
// src/helpers.js
function m(e) {
return typeof e > "u";
}
function w(e) {
let t = typeof e;
return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e);
}
@ -12,75 +31,65 @@ function j(e, t) {
};
}
// src/signals-common.js
var b = {
isTextContent(e) {
return m(e) !== "[object Object]";
},
processReactiveAttribute(e, t, r, n) {
return r;
}
};
function N(e, t = !0) {
return t ? Object.assign(b, e) : (Object.setPrototypeOf(e, b), e);
}
function A(e) {
return b.isPrototypeOf(e) && e !== b ? e : b;
// src/dom-common.js
var b = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')), T = { setDelete: $ };
function $(e, t, r) {
Reflect.set(e, t, r), m(r) && e.getAttribute(t) === "undefined" && e.removeAttribute(t);
}
// src/dom.js
var O = "html";
function te(e) {
return O = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
var S = "html";
function oe(e) {
return S = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(t) {
return O = "html", t;
return S = "html", t;
}
};
}
function ne(e, t, ...r) {
let n = A(this), o;
function ce(e, t, ...r) {
let n = N(this), o;
switch (n.isTextContent(t) && (t = { textContent: t }), !0) {
case typeof e == "function": {
o = e(t || void 0, (i) => i ? (r.unshift(i), void 0) : o);
break;
}
case e === "#text":
o = w(document.createTextNode(""), t);
o = y(document.createTextNode(""), t);
break;
case e === "<>":
o = w(document.createDocumentFragment(), t);
o = y(document.createDocumentFragment(), t);
break;
case O !== "html":
o = w(document.createElementNS(O, e), t);
case S !== "html":
o = y(document.createElementNS(S, e), t);
break;
case !o:
o = w(document.createElement(e), t);
o = y(document.createElement(e), t);
}
return r.forEach((a) => a(o)), o;
}
var x = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]'));
function w(e, ...t) {
let r = A(this);
var { setDelete: D } = T;
function y(e, ...t) {
let r = N(this);
if (!t.length)
return e;
let n = e instanceof SVGElement, o = (n ? J : T).bind(null, e, "Attribute");
let n = e instanceof SVGElement, o = (n ? W : M).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function a([i, s]) {
s = r.processReactiveAttribute(e, i, s, a);
let [h] = i;
if (h === "=")
return o(i.slice(1), s);
if (h === ".")
return _(e, i.slice(1), s);
return D(e, i.slice(1), s);
if (typeof s == "object")
switch (i) {
case "style":
return y(s, T.bind(null, e.style, "Property"));
return O(s, M.bind(null, e.style, "Property"));
case "dataset":
return y(s, _.bind(null, e.dataset));
return O(s, D.bind(null, e.dataset));
case "ariaset":
return y(s, (E, v) => o("aria-" + E, v));
return O(s, (E, v) => o("aria-" + E, v));
case "classList":
return $(e, s);
return q(e, s);
default:
return Reflect.set(e, i, s);
}
@ -96,72 +105,66 @@ function w(e, ...t) {
break;
return e.appendChild(document.createTextNode(s));
}
return q(e, i) ? _(e, i, s) : o(i, s);
return J(e, i) ? D(e, i, s) : o(i, s);
}), e;
}
function $(e, t) {
return typeof t != "object" || y(
function q(e, t) {
return typeof t != "object" || O(
t,
(r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n)
), e;
}
function re(e) {
function se(e) {
return Array.from(e.children).forEach((t) => t.remove()), e;
}
function q(e, t) {
function J(e, t) {
let r = "HTMLElement," + t;
if (e instanceof HTMLElement && x.has(r))
return x.get(r);
if (e instanceof HTMLElement && b.has(r))
return b.get(r);
let n = e.nodeName + "," + t;
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;
if (b.has(n))
return b.get(n);
let [o, a, i] = H(e, t), s = !m(o.set);
return (!s || a) && b.set(i === HTMLElement.prototype ? r : n, s), s;
}
function M(e, t, r = 0) {
function H(e, t, r = 0) {
if (e = Object.getPrototypeOf(e), !e)
return [{}, r, e];
let n = Object.getOwnPropertyDescriptor(e, t);
return n ? [n, r, e] : M(e, t, r + 1);
return n ? [n, r, e] : H(e, t, r + 1);
}
function y(e, t) {
function O(e, t) {
return Object.entries(e).forEach(([r, n]) => t(r, n));
}
function P(e) {
return typeof e > "u";
function M(e, t, r, n) {
return e[(m(n) ? "remove" : "set") + t](r, n);
}
function T(e, t, r, n) {
return e[(P(n) ? "remove" : "set") + t](r, n);
}
function J(e, t, r, n, o = null) {
return e[(P(n) ? "remove" : "set") + t + "NS"](o, r, n);
}
function _(e, t, r) {
return Reflect.set(e, t, r);
function W(e, t, r, n, o = null) {
return e[(m(n) ? "remove" : "set") + t + "NS"](o, r, n);
}
// src/events.js
function ce(e, t, ...r) {
function ae(e, t, ...r) {
let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t);
return e.dispatchEvent(n);
}
function H(e, t, r) {
function k(e, t, r) {
return function(o) {
return o.addEventListener(e, t, r), o;
};
}
var S = W();
H.connected = function(e, t) {
var C = I();
k.connected = function(e, t) {
return function(n) {
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);
return typeof n.connectedCallback == "function" ? (n.addEventListener("dde:connected", e, t), n) : (j(t && t.signal, () => C.offConnected(n, e)) && (n.isConnected ? e(new Event("dde:connected")) : C.onConnected(n, e)), n);
};
};
H.disconnected = function(e, t) {
k.disconnected = function(e, t) {
return function(n) {
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);
return typeof n.disconnectedCallback == "function" ? (n.addEventListener("dde:disconnected", e, t), n) : (j(t && t.signal, () => C.offDisconnected(n, e)) && C.onDisconnected(n, e), n);
};
};
function W() {
function I() {
let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(c) {
for (let f of c)
if (f.type === "childList") {
@ -226,7 +229,7 @@ function W() {
if (f && h(u).then(E), !e.has(u))
continue;
let p = e.get(u);
return p.connected.forEach((R) => R(u)), p.connected.length = 0, p.disconnected.length || e.delete(u), !0;
return p.connected.forEach((A) => A(u)), p.connected.length = 0, p.disconnected.length || e.delete(u), !0;
}
return !1;
}
@ -235,7 +238,7 @@ function W() {
if (f && h(u).then(v), !e.has(u))
continue;
let p = e.get(u);
return p.disconnected.forEach((R) => R(u)), p.connected.length = 0, p.disconnected.length = 0, e.delete(u), !0;
return p.disconnected.forEach((A) => A(u)), p.connected.length = 0, p.disconnected.length = 0, e.delete(u), !0;
}
return !1;
}
@ -251,7 +254,7 @@ function W() {
// src/signals-lib.js
var d = Symbol.for("Signal");
function C(e) {
function L(e) {
try {
return Reflect.has(e, d);
} catch {
@ -261,11 +264,11 @@ function C(e) {
var l = /* @__PURE__ */ new WeakMap();
function g(e, t) {
if (typeof e != "function")
return k(e, t);
if (C(e))
return z(e, t);
if (L(e))
return e;
let r = k(""), n = () => r(e());
return l.set(n, /* @__PURE__ */ new Set([r])), Z(n), r;
let r = z(""), n = () => r(e());
return l.set(n, /* @__PURE__ */ new Set([r])), G(n), r;
}
g.action = function(e, t, ...r) {
let n = e[d], { actions: o } = n;
@ -280,7 +283,7 @@ g.on = function e(t, r, n = {}) {
if (!(o && o.aborted)) {
if (Array.isArray(t))
return t.forEach((a) => e(a, r, n));
D(t, r), o && o.addEventListener("abort", () => F(t, r));
P(t, r), o && o.addEventListener("abort", () => U(t, r));
}
};
g.symbols = {
@ -307,7 +310,7 @@ g.el = function(e, t) {
o.append(r, n);
let a = (i) => {
if (!r.parentNode || !n.parentNode)
return F(e, a);
return U(e, a);
let s = t(i);
Array.isArray(s) || (s = [s]);
let h = r;
@ -315,79 +318,79 @@ g.el = function(e, t) {
h.remove();
r.after(...s);
};
return D(e, a), a(e()), o;
return P(e, a), a(e()), o;
};
var z = {
var F = {
isTextContent(e) {
return m(e) === "string" || C(e) && m(K(e)) === "string";
return w(e) === "string" || L(e) && w(X(e)) === "string";
},
processReactiveAttribute(e, t, r, n) {
return C(r) ? (D(r, (o) => n([t, o])), r()) : r;
return L(r) ? (P(r, (o) => n([t, o])), r()) : r;
}
};
function k(e, t) {
let r = (...n) => n.length ? V(r, n[0]) : G(r);
return U(r, e, t);
function z(e, t) {
let r = (...n) => n.length ? Q(r, n[0]) : K(r);
return B(r, e, t);
}
var I = Object.assign(/* @__PURE__ */ Object.create(null), {
var Z = Object.assign(/* @__PURE__ */ Object.create(null), {
stopPropagation() {
this.skip = !0;
}
});
function U(e, t, r) {
return m(r) !== "[object Object]" && (r = {}), e[d] = {
function B(e, t, r) {
return w(r) !== "[object Object]" && (r = {}), e[d] = {
value: t,
actions: r,
listeners: /* @__PURE__ */ new Set()
}, e.toJSON = () => e(), Object.setPrototypeOf(e[d], I), e;
}, e.toJSON = () => e(), Object.setPrototypeOf(e[d], Z), e;
}
var L = [];
function Z(e) {
var R = [];
function G(e) {
let t = function() {
L.push(t), e(), L.pop();
R.push(t), e(), R.pop();
};
l.has(e) && (l.set(t, l.get(e)), l.delete(e)), t();
}
function B() {
return L[L.length - 1];
function V() {
return R[R.length - 1];
}
function G(e) {
function K(e) {
if (!e[d])
return;
let { value: t, listeners: r } = e[d], n = B();
let { value: t, listeners: r } = e[d], n = V();
return n && r.add(n), l.has(n) && l.get(n).add(e), t;
}
function V(e, t) {
function Q(e, t) {
if (!e[d])
return;
let r = e[d];
if (r.value !== t)
return r.value = t, r.listeners.forEach((n) => n(t)), t;
}
function K(e) {
function X(e) {
return e[d].value;
}
function D(e, t) {
function P(e, t) {
if (e[d])
return e[d].listeners.add(t);
}
function F(e, t) {
function U(e, t) {
if (e[d])
return e[d].listeners.delete(t);
}
// src/signals.js
N(z);
_(F);
export {
g as S,
w as assign,
$ as classListDeclarative,
ne as createElement,
ce as dispatchEvent,
ne as el,
re as empty,
C as isSignal,
te as namespace,
H as on,
N as registerReactivity
y as assign,
q as classListDeclarative,
ce as createElement,
ae as dispatchEvent,
ce as el,
se as empty,
L as isSignal,
oe as namespace,
k as on,
_ as registerReactivity
};

155
dist/esm.js vendored
View File

@ -1,9 +1,24 @@
// src/helpers.js
function N(e) {
let t = typeof e;
return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e);
// src/signals-common.js
var g = {
isTextContent(e) {
return typeof e == "string";
},
processReactiveAttribute(e, t, r, n) {
return r;
}
};
function T(e, t = !0) {
return t ? Object.assign(g, e) : (Object.setPrototypeOf(e, g), e);
}
function O(e, t) {
function O(e) {
return g.isPrototypeOf(e) && e !== g ? e : g;
}
// src/helpers.js
function p(e) {
return typeof e > "u";
}
function L(e, t) {
if (!e || !(e instanceof AbortSignal))
return !0;
if (!e.aborted)
@ -12,33 +27,23 @@ function O(e, t) {
};
}
// src/signals-common.js
var l = {
isTextContent(e) {
return N(e) !== "[object Object]";
},
processReactiveAttribute(e, t, r, n) {
return r;
}
};
function D(e, t = !0) {
return t ? Object.assign(l, e) : (Object.setPrototypeOf(e, l), e);
}
function C(e) {
return l.isPrototypeOf(e) && e !== l ? e : l;
// src/dom-common.js
var h = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]')), A = { setDelete: R };
function R(e, t, r) {
Reflect.set(e, t, r), p(r) && e.getAttribute(t) === "undefined" && e.removeAttribute(t);
}
// src/dom.js
var v = "html";
function F(e) {
return v = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
var m = "html";
function I(e) {
return m = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(t) {
return v = "html", t;
return m = "html", t;
}
};
}
function I(e, t, ...r) {
let n = C(this), c;
function Z(e, t, ...r) {
let n = O(this), c;
switch (n.isTextContent(t) && (t = { textContent: t }), !0) {
case typeof e == "function": {
c = e(t || void 0, (s) => s ? (r.unshift(s), void 0) : c);
@ -50,37 +55,37 @@ function I(e, t, ...r) {
case e === "<>":
c = E(document.createDocumentFragment(), t);
break;
case v !== "html":
c = E(document.createElementNS(v, e), t);
case m !== "html":
c = E(document.createElementNS(m, e), t);
break;
case !c:
c = E(document.createElement(e), t);
}
return r.forEach((a) => a(c)), c;
}
var h = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]'));
var { setDelete: y } = A;
function E(e, ...t) {
let r = C(this);
let r = O(this);
if (!t.length)
return e;
let n = e instanceof SVGElement, c = (n ? S : j).bind(null, e, "Attribute");
let n = e instanceof SVGElement, c = (n ? S : N).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function a([s, f]) {
f = r.processReactiveAttribute(e, s, f, a);
let [p] = s;
if (p === "=")
let [l] = s;
if (l === "=")
return c(s.slice(1), f);
if (p === ".")
return L(e, s.slice(1), f);
if (l === ".")
return y(e, s.slice(1), f);
if (typeof f == "object")
switch (s) {
case "style":
return x(f, j.bind(null, e.style, "Property"));
return v(f, N.bind(null, e.style, "Property"));
case "dataset":
return x(f, L.bind(null, e.dataset));
return v(f, y.bind(null, e.dataset));
case "ariaset":
return x(f, (g, b) => c("aria-" + g, b));
return v(f, (x, b) => c("aria-" + x, b));
case "classList":
return R(e, f);
return j(e, f);
default:
return Reflect.set(e, s, f);
}
@ -96,16 +101,16 @@ function E(e, ...t) {
break;
return e.appendChild(document.createTextNode(f));
}
return M(e, s) ? L(e, s, f) : c(s, f);
return M(e, s) ? y(e, s, f) : c(s, f);
}), e;
}
function R(e, t) {
return typeof t != "object" || x(
function j(e, t) {
return typeof t != "object" || v(
t,
(r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n)
), e;
}
function U(e) {
function B(e) {
return Array.from(e.children).forEach((t) => t.remove()), e;
}
function M(e, t) {
@ -115,57 +120,51 @@ function M(e, t) {
let n = e.nodeName + "," + t;
if (h.has(n))
return h.get(n);
let [c, a, s] = A(e, t), f = !y(c.set);
let [c, a, s] = _(e, t), f = !p(c.set);
return (!f || a) && h.set(s === HTMLElement.prototype ? r : n, f), f;
}
function A(e, t, r = 0) {
function _(e, t, r = 0) {
if (e = Object.getPrototypeOf(e), !e)
return [{}, r, e];
let n = Object.getOwnPropertyDescriptor(e, t);
return n ? [n, r, e] : A(e, t, r + 1);
return n ? [n, r, e] : _(e, t, r + 1);
}
function x(e, t) {
function v(e, t) {
return Object.entries(e).forEach(([r, n]) => t(r, n));
}
function y(e) {
return typeof e > "u";
}
function j(e, t, r, n) {
return e[(y(n) ? "remove" : "set") + t](r, n);
function N(e, t, r, n) {
return e[(p(n) ? "remove" : "set") + t](r, n);
}
function S(e, t, r, n, c = null) {
return e[(y(n) ? "remove" : "set") + t + "NS"](c, r, n);
}
function L(e, t, r) {
return Reflect.set(e, t, r);
return e[(p(n) ? "remove" : "set") + t + "NS"](c, r, n);
}
// src/events.js
function $(e, t, ...r) {
function V(e, t, ...r) {
let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t);
return e.dispatchEvent(n);
}
function T(e, t, r) {
function D(e, t, r) {
return function(c) {
return c.addEventListener(e, t, r), c;
};
}
var m = _();
T.connected = function(e, t) {
var w = P();
D.connected = function(e, t) {
return function(n) {
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);
return typeof n.connectedCallback == "function" ? (n.addEventListener("dde:connected", e, t), n) : (L(t && t.signal, () => w.offConnected(n, e)) && (n.isConnected ? e(new Event("dde:connected")) : w.onConnected(n, e)), n);
};
};
T.disconnected = function(e, t) {
D.disconnected = function(e, t) {
return function(n) {
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);
return typeof n.disconnectedCallback == "function" ? (n.addEventListener("dde:disconnected", e, t), n) : (L(t && t.signal, () => w.offDisconnected(n, e)) && w.onDisconnected(n, e), n);
};
};
function _() {
function P() {
let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(o) {
for (let i of o)
if (i.type === "childList") {
if (g(i.addedNodes, !0)) {
if (x(i.addedNodes, !0)) {
s();
continue;
}
@ -212,7 +211,7 @@ function _() {
(requestIdleCallback || requestAnimationFrame)(o);
});
}
async function p(o) {
async function l(o) {
e.size > 30 && await f();
let i = [];
if (!(o instanceof Node))
@ -221,21 +220,21 @@ function _() {
u === o || !(u instanceof Node) || o.contains(u) && i.push(u);
return i;
}
function g(o, i) {
function x(o, i) {
for (let u of o) {
if (i && p(u).then(g), !e.has(u))
if (i && l(u).then(x), !e.has(u))
continue;
let d = e.get(u);
return d.connected.forEach((w) => w(u)), d.connected.length = 0, d.disconnected.length || e.delete(u), !0;
return d.connected.forEach((C) => C(u)), d.connected.length = 0, d.disconnected.length || e.delete(u), !0;
}
return !1;
}
function b(o, i) {
for (let u of o) {
if (i && p(u).then(b), !e.has(u))
if (i && l(u).then(b), !e.has(u))
continue;
let d = e.get(u);
return d.disconnected.forEach((w) => w(u)), d.connected.length = 0, d.disconnected.length = 0, e.delete(u), !0;
return d.disconnected.forEach((C) => C(u)), d.connected.length = 0, d.disconnected.length = 0, e.delete(u), !0;
}
return !1;
}
@ -250,12 +249,12 @@ function _() {
});
export {
E as assign,
R as classListDeclarative,
I as createElement,
$ as dispatchEvent,
I as el,
U as empty,
F as namespace,
T as on,
D as registerReactivity
j as classListDeclarative,
Z as createElement,
V as dispatchEvent,
Z as el,
B as empty,
I as namespace,
D as on,
T as registerReactivity
};

View File

@ -73,12 +73,22 @@
"size-limit": [
{
"path": "./index.js",
"limit": "10 kB",
"limit": "7 kB",
"gzip": false
},
{
"path": "./index-with-signals.js",
"limit": "10 kB",
"path": "./src/signals.js",
"limit": "4 kB",
"gzip": false
},
{
"path": "./src/jsdom.js",
"limit": "8 kB",
"gzip": false
},
{
"path": "./test/components/webComponent.js",
"limit": "10kb",
"gzip": false
}
],

View File

@ -5,7 +5,7 @@ prop_process.setDelete= function(obj, prop, value){
if("checked"!==prop) return setDelete(obj, prop, value);
if(value) return obj.setAttribute("checked", "");
obj.removeAttribute("checked");
}
};
const keys= [ "HTMLElement", "SVGElement", "DocumentFragment", "MutationObserver", "document" ];
let dom_last;
export let el;