1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2024-11-25 01:39:37 +01:00

🚧 types, linting, caching

♻️ add linting to codebase
♻️ Update prototype methods
🐛 update maxcomplexity in jshintConfig
♻️ Improve DOM element property handling
♻️ update setDelete function
 Add type annotation for signals()
♻️ Cleanup when signal removed
This commit is contained in:
Jan Andrle 2023-09-07 13:52:09 +02:00
parent a8ae99962e
commit 55a8f14b6b
Signed by: jaandrle
GPG Key ID: B3A25AED155AFFAB
11 changed files with 2721 additions and 2504 deletions

View File

@ -1,2 +1,3 @@
#!/usr/bin/env bash #!/usr/bin/env bash
npx size-limit npx size-limit
npx jshint index.js src

View File

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

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

View File

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

221
dist/esm.js vendored
View File

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

195
package-lock.json generated
View File

@ -1,16 +1,17 @@
{ {
"name": "deka-dom-el", "name": "deka-dom-el",
"version": "0.1.0", "version": "0.1.2",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "deka-dom-el", "name": "deka-dom-el",
"version": "0.1.0", "version": "0.1.2",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@size-limit/preset-small-lib": "^8.2.6", "@size-limit/preset-small-lib": "^8.2.6",
"esbuild": "^0.19.2", "esbuild": "^0.19.2",
"jshint": "^2.13.6",
"nodejsscript": "github:jaandrle/nodejsscript#dev-v1", "nodejsscript": "github:jaandrle/nodejsscript#dev-v1",
"size-limit-node-esbuild": "^0.2.0" "size-limit-node-esbuild": "^0.2.0"
}, },
@ -1047,6 +1048,19 @@
"fsevents": "~2.3.2" "fsevents": "~2.3.2"
} }
}, },
"node_modules/cli": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/cli/-/cli-1.0.1.tgz",
"integrity": "sha512-41U72MB56TfUMGndAKK8vJ78eooOD4Z5NOL4xEfjc0c23s+6EYKXlXsmACBVclLP1yOfWCgEganVzddVrSNoTg==",
"dev": true,
"dependencies": {
"exit": "0.1.2",
"glob": "^7.1.1"
},
"engines": {
"node": ">=0.2.5"
}
},
"node_modules/color-convert": { "node_modules/color-convert": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
@ -1071,6 +1085,21 @@
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
"dev": true "dev": true
}, },
"node_modules/console-browserify": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.1.0.tgz",
"integrity": "sha512-duS7VP5pvfsNLDvL1O4VOEbw37AI3A4ZUQYemvDlnpGrNu9tprR7BYWpDYwC0Xia0Zxz5ZupdiIrUp0GH1aXfg==",
"dev": true,
"dependencies": {
"date-now": "^0.1.4"
}
},
"node_modules/core-util-is": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==",
"dev": true
},
"node_modules/css-in-console": { "node_modules/css-in-console": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/css-in-console/-/css-in-console-2.0.0.tgz", "resolved": "https://registry.npmjs.org/css-in-console/-/css-in-console-2.0.0.tgz",
@ -1089,6 +1118,12 @@
"node": ">= 12" "node": ">= 12"
} }
}, },
"node_modules/date-now": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz",
"integrity": "sha512-AsElvov3LoNB7tf5k37H2jYSB+ZZPMT5sG2QjJCcdlV5chIv6htBUBUui2IKRjgtKAKtCBN7Zbwa+MtwLjSeNw==",
"dev": true
},
"node_modules/dir-glob": { "node_modules/dir-glob": {
"version": "3.0.1", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz",
@ -1101,12 +1136,74 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/dom-serializer": {
"version": "0.2.2",
"resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.2.2.tgz",
"integrity": "sha512-2/xPb3ORsQ42nHYiSunXkDjPLBaEj/xTwUO4B7XCZQTRk7EBtTOPaygh10YAAh2OI1Qrp6NWfpAhzswj0ydt9g==",
"dev": true,
"dependencies": {
"domelementtype": "^2.0.1",
"entities": "^2.0.0"
}
},
"node_modules/dom-serializer/node_modules/domelementtype": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz",
"integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==",
"dev": true,
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/fb55"
}
]
},
"node_modules/dom-serializer/node_modules/entities": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/entities/-/entities-2.2.0.tgz",
"integrity": "sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==",
"dev": true,
"funding": {
"url": "https://github.com/fb55/entities?sponsor=1"
}
},
"node_modules/domelementtype": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.3.1.tgz",
"integrity": "sha512-BSKB+TSpMpFI/HOxCNr1O8aMOTZ8hT3pM3GQ0w/mWRmkhEDSFJkkyzz4XQsBV44BChwGkrDfMyjVD0eA2aFV3w==",
"dev": true
},
"node_modules/domhandler": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.3.0.tgz",
"integrity": "sha512-q9bUwjfp7Eif8jWxxxPSykdRZAb6GkguBGSgvvCrhI9wB71W2K/Kvv4E61CF/mcCfnVJDeDWx/Vb/uAqbDj6UQ==",
"dev": true,
"dependencies": {
"domelementtype": "1"
}
},
"node_modules/domutils": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/domutils/-/domutils-1.5.1.tgz",
"integrity": "sha512-gSu5Oi/I+3wDENBsOWBiRK1eoGxcywYSqg3rR960/+EfY0CF4EX1VPkgHOZ3WiS/Jg2DtliF6BhWcHlfpYUcGw==",
"dev": true,
"dependencies": {
"dom-serializer": "0",
"domelementtype": "1"
}
},
"node_modules/emoji-regex": { "node_modules/emoji-regex": {
"version": "8.0.0", "version": "8.0.0",
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
"integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
"dev": true "dev": true
}, },
"node_modules/entities": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/entities/-/entities-1.0.0.tgz",
"integrity": "sha512-LbLqfXgJMmy81t+7c14mnulFHJ170cM6E+0vMXR9k/ZiZwgX8i5pNgjTCX3SO4VeUsFLV+8InixoretwU+MjBQ==",
"dev": true
},
"node_modules/esbuild": { "node_modules/esbuild": {
"version": "0.19.2", "version": "0.19.2",
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.19.2.tgz", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.19.2.tgz",
@ -1153,6 +1250,15 @@
"node": ">=6" "node": ">=6"
} }
}, },
"node_modules/exit": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/exit/-/exit-0.1.2.tgz",
"integrity": "sha512-Zk/eNKV2zbjpKzrsQ+n1G6poVbErQxJ0LBOJXaKZ1EViLzH+hrLu9cdXI4zw9dBQJslwBEpbQ2P1oS7nDxs6jQ==",
"dev": true,
"engines": {
"node": ">= 0.8.0"
}
},
"node_modules/fast-glob": { "node_modules/fast-glob": {
"version": "3.3.1", "version": "3.3.1",
"resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.1.tgz", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.1.tgz",
@ -1315,6 +1421,19 @@
"node": ">= 0.4.0" "node": ">= 0.4.0"
} }
}, },
"node_modules/htmlparser2": {
"version": "3.8.3",
"resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.8.3.tgz",
"integrity": "sha512-hBxEg3CYXe+rPIua8ETe7tmG3XDn9B0edOE/e9wH2nLczxzgdu0m0aNHY+5wFZiviLWLdANPJTssa92dMcXQ5Q==",
"dev": true,
"dependencies": {
"domelementtype": "1",
"domhandler": "2.3",
"domutils": "1.5",
"entities": "1.0",
"readable-stream": "1.1"
}
},
"node_modules/ignore": { "node_modules/ignore": {
"version": "5.2.4", "version": "5.2.4",
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.4.tgz", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.4.tgz",
@ -1418,6 +1537,42 @@
"node": ">=0.12.0" "node": ">=0.12.0"
} }
}, },
"node_modules/isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==",
"dev": true
},
"node_modules/jshint": {
"version": "2.13.6",
"resolved": "https://registry.npmjs.org/jshint/-/jshint-2.13.6.tgz",
"integrity": "sha512-IVdB4G0NTTeQZrBoM8C5JFVLjV2KtZ9APgybDA1MK73xb09qFs0jCXyQLnCOp1cSZZZbvhq/6mfXHUTaDkffuQ==",
"dev": true,
"dependencies": {
"cli": "~1.0.0",
"console-browserify": "1.1.x",
"exit": "0.1.x",
"htmlparser2": "3.8.x",
"lodash": "~4.17.21",
"minimatch": "~3.0.2",
"strip-json-comments": "1.0.x"
},
"bin": {
"jshint": "bin/jshint"
}
},
"node_modules/jshint/node_modules/minimatch": {
"version": "3.0.8",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.8.tgz",
"integrity": "sha512-6FsRAQsxQ61mw+qP1ZzbL9Bc78x2p5OqNgNpnoAFLTrX8n5Kxph0CsnhmKKNXTWjXqU5L0pGPR7hYk+XWZr60Q==",
"dev": true,
"dependencies": {
"brace-expansion": "^1.1.7"
},
"engines": {
"node": "*"
}
},
"node_modules/just-flatten-it": { "node_modules/just-flatten-it": {
"version": "2.2.1", "version": "2.2.1",
"resolved": "https://registry.npmjs.org/just-flatten-it/-/just-flatten-it-2.2.1.tgz", "resolved": "https://registry.npmjs.org/just-flatten-it/-/just-flatten-it-2.2.1.tgz",
@ -1439,6 +1594,12 @@
"node": ">=10" "node": ">=10"
} }
}, },
"node_modules/lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
"dev": true
},
"node_modules/log-update-async-hook": { "node_modules/log-update-async-hook": {
"version": "2.0.7", "version": "2.0.7",
"resolved": "https://registry.npmjs.org/log-update-async-hook/-/log-update-async-hook-2.0.7.tgz", "resolved": "https://registry.npmjs.org/log-update-async-hook/-/log-update-async-hook-2.0.7.tgz",
@ -1695,6 +1856,18 @@
} }
] ]
}, },
"node_modules/readable-stream": {
"version": "1.1.14",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz",
"integrity": "sha512-+MeVjFf4L44XUkhM1eYbD8fyEsxcV81pqMSR5gblfcLCHfZvbrqy4/qYHE+/R5HoBUT11WV5O08Cr1n3YXkWVQ==",
"dev": true,
"dependencies": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.1",
"isarray": "0.0.1",
"string_decoder": "~0.10.x"
}
},
"node_modules/readdirp": { "node_modules/readdirp": {
"version": "3.6.0", "version": "3.6.0",
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz",
@ -1871,6 +2044,12 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ==",
"dev": true
},
"node_modules/string-width": { "node_modules/string-width": {
"version": "4.2.3", "version": "4.2.3",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
@ -1897,6 +2076,18 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/strip-json-comments": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-1.0.4.tgz",
"integrity": "sha512-AOPG8EBc5wAikaG1/7uFCNFJwnKOuQwFTpYBdTW6OvWHeZBQBrAA/amefHGrEiOnCPcLFZK6FUPtWVKpQVIRgg==",
"dev": true,
"bin": {
"strip-json-comments": "cli.js"
},
"engines": {
"node": ">=0.8.0"
}
},
"node_modules/supports-preserve-symlinks-flag": { "node_modules/supports-preserve-symlinks-flag": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz",

View File

@ -1,6 +1,6 @@
{ {
"name": "deka-dom-el", "name": "deka-dom-el",
"version": "0.1.1", "version": "0.1.2",
"description": "A low-code library that simplifies the creation of native DOM elements/components using small wrappers and tweaks.", "description": "A low-code library that simplifies the creation of native DOM elements/components using small wrappers and tweaks.",
"author": "Jan Andrle <andrle.jan@centrum.cz>", "author": "Jan Andrle <andrle.jan@centrum.cz>",
"license": "MIT", "license": "MIT",
@ -58,13 +58,16 @@
"node": ">=18" "node": ">=18"
}, },
"jshintConfig": { "jshintConfig": {
"esversion": 6, "esversion": 11,
"node": "true", "browser": true,
"undef": "true", "undef": "true",
"latedef": "true", "latedef": "true",
"maxparams": 4, "maxparams": 5,
"maxdepth": 3, "maxdepth": 3,
"maxcomplexity": 19 "maxcomplexity": 10,
"globals": {
"requestIdleCallback": false
}
}, },
"size-limit": [ "size-limit": [
{ {
@ -93,6 +96,7 @@
"devDependencies": { "devDependencies": {
"@size-limit/preset-small-lib": "^8.2.6", "@size-limit/preset-small-lib": "^8.2.6",
"esbuild": "^0.19.2", "esbuild": "^0.19.2",
"jshint": "^2.13.6",
"nodejsscript": "github:jaandrle/nodejsscript#dev-v1", "nodejsscript": "github:jaandrle/nodejsscript#dev-v1",
"size-limit-node-esbuild": "^0.2.0" "size-limit-node-esbuild": "^0.2.0"
} }

View File

@ -1,5 +1,6 @@
import { signals } from "./signals-common.js"; import { signals } from "./signals-common.js";
/** @type {"html"|"svg"|string} */
let namespace_curr= "html"; let namespace_curr= "html";
export function namespace(namespace){ export function namespace(namespace){
namespace_curr= namespace==="svg" ? "http://www.w3.org/2000/svg" : namespace; namespace_curr= namespace==="svg" ? "http://www.w3.org/2000/svg" : namespace;
@ -29,22 +30,24 @@ export function createElement(tag, attributes, ...connect){
} }
export { createElement as el }; export { createElement as el };
const prop_cache= new Map(); /** @type {Map<string, boolean>} */
const prop_cache= new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]'));
export function assign(element, ...attributes){ export function assign(element, ...attributes){
const s= signals(this); const s= signals(this);
if(!attributes.length) return element; if(!attributes.length) return element;
const is_svg= element instanceof SVGElement; const is_svg= element instanceof SVGElement;
const setRemoveAttr= (is_svg ? setRemoveNS : setRemove).bind(null, element, "Attribute"); const setRemoveAttr= (is_svg ? setRemoveNS : setRemove).bind(null, element, "Attribute");
/* jshint maxcomplexity:15 */
Object.entries(Object.assign({}, ...attributes)).forEach(function assignNth([ key, attr ]){ Object.entries(Object.assign({}, ...attributes)).forEach(function assignNth([ key, attr ]){
if(s.isReactiveAtrribute(attr, key)) if(s.isReactiveAtrribute(attr, key))
attr= s.processReactiveAttribute(el, key, attr, assignNth); attr= s.processReactiveAttribute(element, key, attr, assignNth);
const [ k ]= key; const [ k ]= key;
if("="===k) return setRemoveAttr(key.slice(1), attr); if("="===k) return setRemoveAttr(key.slice(1), attr);
if("."===k) return setDelete(element, key.slice(1), attr); if("."===k) return setDelete(element, key.slice(1), attr);
if(typeof attr === "object"){ if(typeof attr === "object"){
switch(key){ switch(key){
case "style": return forEachEntries(attr, setRemove.bind(null, element.style, "Property")) case "style": return forEachEntries(attr, setRemove.bind(null, element.style, "Property"));
case "dataset": return forEachEntries(attr, setDelete.bind(null, element.dataset)); case "dataset": return forEachEntries(attr, setDelete.bind(null, element.dataset));
case "ariaset": return forEachEntries(attr, (key, val)=> setRemoveAttr("aria-"+key, val)); case "ariaset": return forEachEntries(attr, (key, val)=> setRemoveAttr("aria-"+key, val));
case "classList": return classListDeclartive(element, attr); case "classList": return classListDeclartive(element, attr);
@ -71,7 +74,7 @@ export function classListDeclartive(element, toggle){
forEachEntries(toggle, forEachEntries(toggle,
(class_name, val)=> (class_name, val)=>
element.classList.toggle(class_name, val===-1 ? undefined : Boolean(val))) element.classList.toggle(class_name, val===-1 ? undefined : Boolean(val)));
return element; return element;
} }
export function empty(el){ export function empty(el){
@ -79,18 +82,23 @@ export function empty(el){
return el; return el;
} }
function isPropSetter(el, key){ function isPropSetter(el, key){
const cache_key_he= "HTMLElement,"+key;
if(el instanceof HTMLElement && prop_cache.has(cache_key_he))
return prop_cache.get(cache_key_he);
const cache_key= el.nodeName+","+key; const cache_key= el.nodeName+","+key;
if(prop_cache.has(cache_key)) return prop_cache.get(cache_key); if(prop_cache.has(cache_key)) return prop_cache.get(cache_key);
const des= getPropDescriptor(el, key); const [ des, level, p ]= getPropDescriptor(el, key);
const is_set= !isUndef(des.set); const is_set= !isUndef(des.set);
prop_cache.set(cache_key, is_set); if(!is_set || level)
prop_cache.set(p===HTMLElement.prototype ? cache_key_he : cache_key, is_set);
return is_set; return is_set;
} }
function getPropDescriptor(p, key){ function getPropDescriptor(p, key, level= 0){
p= Object.getPrototypeOf(p); p= Object.getPrototypeOf(p);
if(!p) return {}; if(!p) return [ {}, level, p ];
const des= Object.getOwnPropertyDescriptor(p, key); const des= Object.getOwnPropertyDescriptor(p, key);
return des ? des : getPropDescriptor(p, key); if(!des) return getPropDescriptor(p, key, level+1);
return [ des, level, p ];
} }
function forEachEntries(obj, cb){ return Object.entries(obj).forEach(([ key, val ])=> cb(key, val)); } function forEachEntries(obj, cb){ return Object.entries(obj).forEach(([ key, val ])=> cb(key, val)); }
@ -98,4 +106,4 @@ function isUndef(value){ return typeof value==="undefined"; }
function setRemove(obj, prop, key, val){ return obj[ (isUndef(val) ? "remove" : "set") + prop ](key, val); } function setRemove(obj, prop, key, val){ return obj[ (isUndef(val) ? "remove" : "set") + prop ](key, val); }
function setRemoveNS(obj, prop, key, val, ns= null){ return obj[ (isUndef(val) ? "remove" : "set") + prop + "NS" ](ns, key, val); } function setRemoveNS(obj, prop, key, val, ns= null){ return obj[ (isUndef(val) ? "remove" : "set") + prop + "NS" ](ns, key, val); }
function setDelete(obj, prop, val){ return Reflect[ isUndef(val) ? "deleteProperty" : "set" ](obj, prop, val); } function setDelete(obj, prop, val){ return Reflect.set(obj, prop, val); }

View File

@ -3,13 +3,14 @@ export const signals_global= {
isReactiveAtrribute(attr, key){ return false; }, isReactiveAtrribute(attr, key){ return false; },
isTextContent(attributes){ return typeOf(attributes)!=="[object Object]"; }, isTextContent(attributes){ return typeOf(attributes)!=="[object Object]"; },
processReactiveAttribute(el, key, attr, assignNth){ return false; }, processReactiveAttribute(el, key, attr, assignNth){ return false; },
reactiveElement(attributes, ...connect){ return document.createDocumentFragment(); } reactiveElement(attributes, ...connect){ return null; }
}; };
export function registerReactivity(def, global= true){ export function registerReactivity(def, global= true){
if(global) return Object.assign(signals_global, def); if(global) return Object.assign(signals_global, def);
Object.setPrototypeOf(def, signals_global); Object.setPrototypeOf(def, signals_global);
return def; return def;
} }
/** @param {unknown} _this @returns {typeof signals_global} */
export function signals(_this){ export function signals(_this){
return signals_global.isPrototypeOf(_this) && _this!==signals_global ? _this : signals_global; return signals_global.isPrototypeOf(_this) && _this!==signals_global ? _this : signals_global;
} }

View File

@ -29,7 +29,7 @@ S.on= function on(signals, listener, options){
if(options && options.signal) if(options && options.signal)
options.signal.addEventListener("abort", ()=> removeSignalListener(signals, listener)); options.signal.addEventListener("abort", ()=> removeSignalListener(signals, listener));
//TODO cleanup when signal removed (also TODO) //TODO cleanup when signal removed (also TODO)
} };
S.clear= function(...signals){ S.clear= function(...signals){
for(const signal of signals){ for(const signal of signals){
signal[mark].listeners.clear(); signal[mark].listeners.clear();
@ -100,7 +100,7 @@ export function watch(context){
stack_watch.push(contextReWatch); stack_watch.push(contextReWatch);
context(); context();
stack_watch.pop(); stack_watch.pop();
}; }
function currentContext(){ function currentContext(){
return stack_watch[stack_watch.length - 1]; return stack_watch[stack_watch.length - 1];
} }
@ -116,7 +116,7 @@ function write(signal, value){
const s= signal[mark]; const s= signal[mark];
if(s.value===value) return; if(s.value===value) return;
s.value= value; s.value= value;
s.listeners.forEach(fn=> fn(value)) s.listeners.forEach(fn=> fn(value));
return value; return value;
} }

View File

@ -1,11 +1,11 @@
import { namespace, el, on, registerReactivity } from "../index.js"; import { namespace, el, assign, on, registerReactivity } from "../index.js";
import { S } from "../src/signals.js"; import { S } from "../src/signals.js";
// import { empty, namespace, on, dispatch } from "../index.js"; // import { empty, namespace, on, dispatch } from "../index.js";
// import "../dist/dde-with-signals.js"; // import "../dist/dde-with-signals.js";
// Object.assign(globalThis, dde); // Object.assign(globalThis, dde);
// import { el, on, off, S } from "../dist/esm-with-signals.js"; // import { el, on, off, S } from "../dist/esm-with-signals.js";
const style= createStyle(); const style= createStyle();
Object.assign(globalThis, { S, el, namespace, on, registerReactivity, style }); Object.assign(globalThis, { S, el, assign, namespace, on, registerReactivity, style });
export { S, el, on, registerReactivity, style }; export { S, el, on, registerReactivity, style };
function createStyle(){ function createStyle(){