mirror of
https://github.com/jaandrle/deka-dom-el
synced 2024-11-21 23: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:
parent
a8ae99962e
commit
55a8f14b6b
@ -1,2 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
npx size-limit
|
||||
npx jshint index.js src
|
||||
|
289
dist/dde-with-signals.js
vendored
289
dist/dde-with-signals.js
vendored
@ -18,27 +18,27 @@
|
||||
return !1;
|
||||
},
|
||||
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);
|
||||
}
|
||||
function C(e) {
|
||||
function j(e) {
|
||||
return m.isPrototypeOf(e) && e !== m ? e : m;
|
||||
}
|
||||
|
||||
// src/dom.js
|
||||
var w = "html";
|
||||
var O = "html";
|
||||
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) {
|
||||
return w = "html", t;
|
||||
return O = "html", t;
|
||||
}
|
||||
};
|
||||
}
|
||||
function ee(e, t, ...n) {
|
||||
let r = C(this), o;
|
||||
let r = j(this), o;
|
||||
if (e === "<>") {
|
||||
if (r.isReactiveAtrribute(t))
|
||||
return r.reactiveElement(t, ...n);
|
||||
@ -49,57 +49,57 @@
|
||||
o = e(t || void 0);
|
||||
break;
|
||||
case e === "#text":
|
||||
o = N(document.createTextNode(""), t);
|
||||
o = A(document.createTextNode(""), t);
|
||||
break;
|
||||
case w !== "html":
|
||||
o = N(document.createElementNS(w, e), t);
|
||||
case O !== "html":
|
||||
o = A(document.createElementNS(O, e), t);
|
||||
break;
|
||||
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();
|
||||
function N(e, ...t) {
|
||||
let n = C(this);
|
||||
var x = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]'));
|
||||
function A(e, ...t) {
|
||||
let n = j(this);
|
||||
if (!t.length)
|
||||
return e;
|
||||
let r = e instanceof SVGElement, o = (r ? I : _).bind(null, e, "Attribute");
|
||||
return Object.entries(Object.assign({}, ...t)).forEach(function l([f, u]) {
|
||||
n.isReactiveAtrribute(u, f) && (u = n.processReactiveAttribute(el, f, u, l));
|
||||
let [p] = f;
|
||||
let r = e instanceof SVGElement, o = (r ? z : P).bind(null, e, "Attribute");
|
||||
return Object.entries(Object.assign({}, ...t)).forEach(function a([u, i]) {
|
||||
n.isReactiveAtrribute(i, u) && (i = n.processReactiveAttribute(e, u, i, a));
|
||||
let [p] = u;
|
||||
if (p === "=")
|
||||
return o(f.slice(1), u);
|
||||
return o(u.slice(1), i);
|
||||
if (p === ".")
|
||||
return L(e, f.slice(1), u);
|
||||
if (typeof u == "object")
|
||||
switch (f) {
|
||||
return L(e, u.slice(1), i);
|
||||
if (typeof i == "object")
|
||||
switch (u) {
|
||||
case "style":
|
||||
return E(u, _.bind(null, e.style, "Property"));
|
||||
return w(i, P.bind(null, e.style, "Property"));
|
||||
case "dataset":
|
||||
return E(u, L.bind(null, e.dataset));
|
||||
return w(i, L.bind(null, e.dataset));
|
||||
case "ariaset":
|
||||
return E(u, (x, v) => o("aria-" + x, v));
|
||||
return w(i, (E, v) => o("aria-" + E, v));
|
||||
case "classList":
|
||||
return q(e, u);
|
||||
return k(e, i);
|
||||
default:
|
||||
return Reflect.set(e, f, u);
|
||||
return Reflect.set(e, u, i);
|
||||
}
|
||||
if (/(aria|data)([A-Z])/.test(f))
|
||||
return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(f, u);
|
||||
switch (f) {
|
||||
if (/(aria|data)([A-Z])/.test(u))
|
||||
return u = u.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(u, i);
|
||||
switch (u) {
|
||||
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":
|
||||
if (!r)
|
||||
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;
|
||||
}
|
||||
function q(e, t) {
|
||||
return typeof t != "object" || E(
|
||||
function k(e, t) {
|
||||
return typeof t != "object" || w(
|
||||
t,
|
||||
(n, r) => e.classList.toggle(n, r === -1 ? void 0 : !!r)
|
||||
), e;
|
||||
@ -107,124 +107,127 @@
|
||||
function te(e) {
|
||||
return Array.from(e.children).forEach((t) => t.remove()), e;
|
||||
}
|
||||
function z(e, t) {
|
||||
let n = e.nodeName + "," + t;
|
||||
if (S.has(n))
|
||||
return S.get(n);
|
||||
let r = D(e, t), o = !y(r.set);
|
||||
return S.set(n, o), o;
|
||||
function q(e, t) {
|
||||
let n = "HTMLElement," + t;
|
||||
if (e instanceof HTMLElement && x.has(n))
|
||||
return x.get(n);
|
||||
let r = e.nodeName + "," + t;
|
||||
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)
|
||||
return {};
|
||||
let n = Object.getOwnPropertyDescriptor(e, t);
|
||||
return n || D(e, t);
|
||||
return [{}, n, e];
|
||||
let r = Object.getOwnPropertyDescriptor(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));
|
||||
}
|
||||
function y(e) {
|
||||
function N(e) {
|
||||
return typeof e > "u";
|
||||
}
|
||||
function _(e, t, n, r) {
|
||||
return e[(y(r) ? "remove" : "set") + t](n, r);
|
||||
function P(e, t, n, r) {
|
||||
return e[(N(r) ? "remove" : "set") + t](n, r);
|
||||
}
|
||||
function I(e, t, n, r, o = null) {
|
||||
return e[(y(r) ? "remove" : "set") + t + "NS"](o, n, r);
|
||||
function z(e, t, n, r, o = null) {
|
||||
return e[(N(r) ? "remove" : "set") + t + "NS"](o, n, r);
|
||||
}
|
||||
function L(e, t, n) {
|
||||
return Reflect[y(n) ? "deleteProperty" : "set"](e, t, n);
|
||||
return Reflect.set(e, t, n);
|
||||
}
|
||||
|
||||
// src/events.js
|
||||
function T(e, t, n) {
|
||||
function D(e, t, n) {
|
||||
return (r) => (r.addEventListener(e, t, n), r);
|
||||
}
|
||||
var O = W();
|
||||
T.connected = function(e, t) {
|
||||
var y = I();
|
||||
D.connected = function(e, t) {
|
||||
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) {
|
||||
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) {
|
||||
for (let i of c)
|
||||
if (i.type === "childList") {
|
||||
if (x(i.addedNodes, !0)) {
|
||||
f();
|
||||
for (let s of c)
|
||||
if (s.type === "childList") {
|
||||
if (E(s.addedNodes, !0)) {
|
||||
u();
|
||||
continue;
|
||||
}
|
||||
v(i.removedNodes, !0) && f();
|
||||
v(s.removedNodes, !0) && u();
|
||||
}
|
||||
});
|
||||
return {
|
||||
onConnected(c, i) {
|
||||
l(), o(c).connected.push(i);
|
||||
onConnected(c, s) {
|
||||
a(), o(c).connected.push(s);
|
||||
},
|
||||
offConnected(c, i) {
|
||||
offConnected(c, s) {
|
||||
if (!e.has(c))
|
||||
return;
|
||||
let s = e.get(c), a = s.connected;
|
||||
a.splice(a.indexOf(i), 1), r(c, s);
|
||||
let f = e.get(c), d = f.connected;
|
||||
d.splice(d.indexOf(s), 1), r(c, f);
|
||||
},
|
||||
onDisconnected(c, i) {
|
||||
l(), o(c).disconnected.push(i);
|
||||
onDisconnected(c, s) {
|
||||
a(), o(c).disconnected.push(s);
|
||||
},
|
||||
offDisconnected(c, i) {
|
||||
offDisconnected(c, s) {
|
||||
if (!e.has(c))
|
||||
return;
|
||||
let s = e.get(c), a = s.disconnected;
|
||||
a.splice(a.indexOf(i), 1), r(c, s);
|
||||
let f = e.get(c), d = f.disconnected;
|
||||
d.splice(d.indexOf(s), 1), r(c, f);
|
||||
}
|
||||
};
|
||||
function r(c, i) {
|
||||
i.connected.length || i.disconnect.length || (e.delete(c), f());
|
||||
function r(c, s) {
|
||||
s.connected.length || s.disconnect.length || (e.delete(c), u());
|
||||
}
|
||||
function o(c) {
|
||||
if (e.has(c))
|
||||
return e.get(c);
|
||||
let i = { connected: [], disconnected: [] };
|
||||
return e.set(c, i), i;
|
||||
let s = { connected: [], disconnected: [] };
|
||||
return e.set(c, s), s;
|
||||
}
|
||||
function l() {
|
||||
function a() {
|
||||
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
|
||||
}
|
||||
function f() {
|
||||
function u() {
|
||||
!t || e.size || (t = !1, n.disconnect());
|
||||
}
|
||||
function u() {
|
||||
function i() {
|
||||
return new Promise(function(c) {
|
||||
(requestIdleCallback || requestAnimationFrame)(c);
|
||||
});
|
||||
}
|
||||
async function p(c) {
|
||||
e.size > 30 && await u();
|
||||
let i = [];
|
||||
e.size > 30 && await i();
|
||||
let s = [];
|
||||
if (!(c instanceof Node))
|
||||
return i;
|
||||
for (let s of e.keys())
|
||||
s === c || !(s instanceof Node) || c.contains(s) && i.push(s);
|
||||
return i;
|
||||
return s;
|
||||
for (let f of e.keys())
|
||||
f === c || !(f instanceof Node) || c.contains(f) && s.push(f);
|
||||
return s;
|
||||
}
|
||||
function x(c, i) {
|
||||
for (let s of c) {
|
||||
if (i && p(s).then(x), !e.has(s))
|
||||
function E(c, s) {
|
||||
for (let f of c) {
|
||||
if (s && p(f).then(E), !e.has(f))
|
||||
return !1;
|
||||
let a = e.get(s);
|
||||
return a.connected.forEach((j) => j(s)), a.connected.length = 0, a.disconnected.length || e.delete(s), !0;
|
||||
let d = e.get(f);
|
||||
return d.connected.forEach((C) => C(f)), d.connected.length = 0, d.disconnected.length || e.delete(f), !0;
|
||||
}
|
||||
}
|
||||
function v(c, i) {
|
||||
for (let s of c) {
|
||||
if (i && p(s).then(v), !e.has(s))
|
||||
function v(c, s) {
|
||||
for (let f of c) {
|
||||
if (s && p(f).then(v), !e.has(f))
|
||||
return !1;
|
||||
let a = e.get(s);
|
||||
return a.disconnected.forEach((j) => j(s)), a.connected.length = 0, a.disconnected.length = 0, e.delete(s), !0;
|
||||
let d = e.get(f);
|
||||
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
|
||||
var d = Symbol.for("signal");
|
||||
var l = Symbol.for("signal");
|
||||
function b(e) {
|
||||
try {
|
||||
return Reflect.has(e, d);
|
||||
return Reflect.has(e, l);
|
||||
} catch {
|
||||
return !1;
|
||||
}
|
||||
}
|
||||
function R(e, t) {
|
||||
if (typeof e != "function")
|
||||
return F(e, t);
|
||||
return M(e, t);
|
||||
if (b(e))
|
||||
return e;
|
||||
let n = F();
|
||||
return M(() => n(e())), n;
|
||||
let n = M();
|
||||
return $(() => n(e())), n;
|
||||
}
|
||||
R.action = function(e, t, ...n) {
|
||||
if (!b(e))
|
||||
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))
|
||||
throw new Error(`'${e}' has no action with name '${t}'!`);
|
||||
if (o[t].apply(r, n), 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) {
|
||||
if (Array.isArray(t))
|
||||
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) {
|
||||
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) {
|
||||
return b(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) {
|
||||
return P(n, (o) => r([t, o])), n();
|
||||
return _(n, (o) => r([t, o])), n();
|
||||
},
|
||||
reactiveElement(e, t) {
|
||||
let n = document.createComment("<> #reactive"), r = document.createComment("</> #reactive"), o = document.createDocumentFragment();
|
||||
o.append(n, r);
|
||||
let l = (f) => {
|
||||
let a = (u) => {
|
||||
if (!n.parentNode || !r.parentNode)
|
||||
return k(e, l);
|
||||
let u = t(f);
|
||||
Array.isArray(u) || (u = [u]);
|
||||
return F(e, a);
|
||||
let i = t(u);
|
||||
Array.isArray(i) || (i = [i]);
|
||||
let p = n;
|
||||
for (; (p = n.nextSibling) !== r; )
|
||||
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) {
|
||||
let n = (...r) => r.length ? U(n, r[0]) : H(n);
|
||||
return B(n, e, t);
|
||||
function M(e, t) {
|
||||
let n = (...r) => r.length ? J(n, r[0]) : G(n);
|
||||
return Z(n, e, t);
|
||||
}
|
||||
var Z = Object.assign(/* @__PURE__ */ Object.create(null), {
|
||||
var W = Object.assign(/* @__PURE__ */ Object.create(null), {
|
||||
stopPropagation() {
|
||||
this.skip = !0;
|
||||
}
|
||||
});
|
||||
function B(e, t, n) {
|
||||
return h(n) !== "[object Object]" && (n = {}), e[d] = {
|
||||
function Z(e, t, n) {
|
||||
return h(n) !== "[object Object]" && (n = {}), e[l] = {
|
||||
value: t,
|
||||
actions: n,
|
||||
listeners: /* @__PURE__ */ new Set()
|
||||
}, Object.setPrototypeOf(e[d], Z), e;
|
||||
}, Object.setPrototypeOf(e[l], W), e;
|
||||
}
|
||||
var g = [];
|
||||
function M(e) {
|
||||
function $(e) {
|
||||
let t = function() {
|
||||
g.push(t), e(), g.pop();
|
||||
};
|
||||
g.push(t), e(), g.pop();
|
||||
}
|
||||
function G() {
|
||||
function B() {
|
||||
return g[g.length - 1];
|
||||
}
|
||||
function H(e) {
|
||||
if (!e[d])
|
||||
function G(e) {
|
||||
if (!e[l])
|
||||
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;
|
||||
}
|
||||
function U(e, t) {
|
||||
if (!e[d])
|
||||
function J(e, t) {
|
||||
if (!e[l])
|
||||
return;
|
||||
let n = e[d];
|
||||
let n = e[l];
|
||||
if (n.value !== t)
|
||||
return n.value = t, n.listeners.forEach((r) => r(t)), t;
|
||||
}
|
||||
function V(e) {
|
||||
return e[d].value;
|
||||
function U(e) {
|
||||
return e[l].value;
|
||||
}
|
||||
function P(e, t) {
|
||||
return e[d].listeners.add(t);
|
||||
function _(e, t) {
|
||||
return e[l].listeners.add(t);
|
||||
}
|
||||
function k(e, t) {
|
||||
return e[d].listeners.delete(t);
|
||||
function F(e, t) {
|
||||
return e[l].listeners.delete(t);
|
||||
}
|
||||
|
||||
// src/signals.js
|
||||
A($);
|
||||
S(H);
|
||||
|
||||
globalThis.dde= {
|
||||
S: R,
|
||||
assign: N,
|
||||
classListDeclartive: q,
|
||||
assign: A,
|
||||
classListDeclartive: k,
|
||||
createElement: ee,
|
||||
el: ee,
|
||||
empty: te,
|
||||
isSignal: b,
|
||||
namespace: Y,
|
||||
on: T,
|
||||
registerReactivity: A,
|
||||
watch: M
|
||||
on: D,
|
||||
registerReactivity: S,
|
||||
watch: $
|
||||
};
|
||||
|
||||
})();
|
221
dist/dde.js
vendored
221
dist/dde.js
vendored
@ -1,7 +1,7 @@
|
||||
//deka-dom-el library is available via global namespace `dde`
|
||||
(()=> {
|
||||
// src/helpers.js
|
||||
function y(e) {
|
||||
function N(e) {
|
||||
let t = typeof e;
|
||||
return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e);
|
||||
}
|
||||
@ -12,16 +12,16 @@
|
||||
return !1;
|
||||
},
|
||||
isTextContent(e) {
|
||||
return y(e) !== "[object Object]";
|
||||
return N(e) !== "[object Object]";
|
||||
},
|
||||
processReactiveAttribute(e, t, n, r) {
|
||||
processReactiveAttribute(e, t, r, n) {
|
||||
return !1;
|
||||
},
|
||||
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);
|
||||
}
|
||||
function O(e) {
|
||||
@ -29,181 +29,184 @@
|
||||
}
|
||||
|
||||
// src/dom.js
|
||||
var m = "html";
|
||||
var x = "html";
|
||||
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) {
|
||||
return m = "html", t;
|
||||
return x = "html", t;
|
||||
}
|
||||
};
|
||||
}
|
||||
function I(e, t, ...n) {
|
||||
let r = O(this), i;
|
||||
function F(e, t, ...r) {
|
||||
let n = O(this), f;
|
||||
if (e === "<>") {
|
||||
if (r.isReactiveAtrribute(t))
|
||||
return r.reactiveElement(t, ...n);
|
||||
i = document.createDocumentFragment();
|
||||
if (n.isReactiveAtrribute(t))
|
||||
return n.reactiveElement(t, ...r);
|
||||
f = document.createDocumentFragment();
|
||||
}
|
||||
switch (r.isTextContent(t) && (t = { textContent: t }), !0) {
|
||||
switch (n.isTextContent(t) && (t = { textContent: t }), !0) {
|
||||
case typeof e == "function":
|
||||
i = e(t || void 0);
|
||||
f = e(t || void 0);
|
||||
break;
|
||||
case e === "#text":
|
||||
i = C(document.createTextNode(""), t);
|
||||
f = w(document.createTextNode(""), t);
|
||||
break;
|
||||
case m !== "html":
|
||||
i = C(document.createElementNS(m, e), t);
|
||||
case x !== "html":
|
||||
f = w(document.createElementNS(x, e), t);
|
||||
break;
|
||||
case !i:
|
||||
i = C(document.createElement(e), t);
|
||||
case !f:
|
||||
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();
|
||||
function C(e, ...t) {
|
||||
let n = O(this);
|
||||
var h = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]'));
|
||||
function w(e, ...t) {
|
||||
let r = O(this);
|
||||
if (!t.length)
|
||||
return e;
|
||||
let r = e instanceof SVGElement, i = (r ? S : R).bind(null, e, "Attribute");
|
||||
return Object.entries(Object.assign({}, ...t)).forEach(function d([u, f]) {
|
||||
n.isReactiveAtrribute(f, u) && (f = n.processReactiveAttribute(el, u, f, d));
|
||||
let [l] = u;
|
||||
let n = e instanceof SVGElement, f = (n ? M : j).bind(null, e, "Attribute");
|
||||
return Object.entries(Object.assign({}, ...t)).forEach(function d([i, u]) {
|
||||
r.isReactiveAtrribute(u, i) && (u = r.processReactiveAttribute(e, i, u, d));
|
||||
let [l] = i;
|
||||
if (l === "=")
|
||||
return i(u.slice(1), f);
|
||||
return f(i.slice(1), u);
|
||||
if (l === ".")
|
||||
return j(e, u.slice(1), f);
|
||||
if (typeof f == "object")
|
||||
switch (u) {
|
||||
return C(e, i.slice(1), u);
|
||||
if (typeof u == "object")
|
||||
switch (i) {
|
||||
case "style":
|
||||
return b(f, R.bind(null, e.style, "Property"));
|
||||
return m(u, j.bind(null, e.style, "Property"));
|
||||
case "dataset":
|
||||
return b(f, j.bind(null, e.dataset));
|
||||
return m(u, C.bind(null, e.dataset));
|
||||
case "ariaset":
|
||||
return b(f, (h, g) => i("aria-" + h, g));
|
||||
return m(u, (g, b) => f("aria-" + g, b));
|
||||
case "classList":
|
||||
return L(e, f);
|
||||
return T(e, u);
|
||||
default:
|
||||
return Reflect.set(e, u, f);
|
||||
return Reflect.set(e, i, u);
|
||||
}
|
||||
if (/(aria|data)([A-Z])/.test(u))
|
||||
return u = u.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(u, f);
|
||||
switch (u) {
|
||||
if (/(aria|data)([A-Z])/.test(i))
|
||||
return i = i.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), f(i, u);
|
||||
switch (i) {
|
||||
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":
|
||||
if (!r)
|
||||
if (!n)
|
||||
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;
|
||||
}
|
||||
function L(e, t) {
|
||||
return typeof t != "object" || b(
|
||||
function T(e, t) {
|
||||
return typeof t != "object" || m(
|
||||
t,
|
||||
(n, r) => e.classList.toggle(n, r === -1 ? void 0 : !!r)
|
||||
(r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n)
|
||||
), e;
|
||||
}
|
||||
function Z(e) {
|
||||
function I(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;
|
||||
if (w.has(n))
|
||||
return w.get(n);
|
||||
let r = A(e, t), i = !x(r.set);
|
||||
return w.set(n, i), i;
|
||||
if (h.has(n))
|
||||
return h.get(n);
|
||||
let [f, d, i] = y(e, t), u = !L(f.set);
|
||||
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)
|
||||
return {};
|
||||
return [{}, r, e];
|
||||
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) {
|
||||
return Object.entries(e).forEach(([n, r]) => t(n, r));
|
||||
function m(e, t) {
|
||||
return Object.entries(e).forEach(([r, n]) => t(r, n));
|
||||
}
|
||||
function x(e) {
|
||||
function L(e) {
|
||||
return typeof e > "u";
|
||||
}
|
||||
function R(e, t, n, r) {
|
||||
return e[(x(r) ? "remove" : "set") + t](n, r);
|
||||
function j(e, t, r, n) {
|
||||
return e[(L(n) ? "remove" : "set") + t](r, n);
|
||||
}
|
||||
function S(e, t, n, r, i = null) {
|
||||
return e[(x(r) ? "remove" : "set") + t + "NS"](i, n, r);
|
||||
function M(e, t, r, n, f = null) {
|
||||
return e[(L(n) ? "remove" : "set") + t + "NS"](f, r, n);
|
||||
}
|
||||
function j(e, t, n) {
|
||||
return Reflect[x(n) ? "deleteProperty" : "set"](e, t, n);
|
||||
function C(e, t, r) {
|
||||
return Reflect.set(e, t, r);
|
||||
}
|
||||
|
||||
// src/events.js
|
||||
function N(e, t, n) {
|
||||
return (r) => (r.addEventListener(e, t, n), r);
|
||||
function R(e, t, r) {
|
||||
return (n) => (n.addEventListener(e, t, r), n);
|
||||
}
|
||||
var v = T();
|
||||
N.connected = function(e, t) {
|
||||
return function(r) {
|
||||
v.onConnected(r, e), t && t.signal && t.signal.addEventListener("abort", () => v.offConnected(r, e));
|
||||
var E = P();
|
||||
R.connected = function(e, t) {
|
||||
return function(n) {
|
||||
E.onConnected(n, e), t && t.signal && t.signal.addEventListener("abort", () => E.offConnected(n, e));
|
||||
};
|
||||
};
|
||||
N.disconnected = function(e, t) {
|
||||
return function(r) {
|
||||
v.onDisconnected(r, e), t && t.signal && t.signal.addEventListener("abort", () => v.offDisconnected(r, e));
|
||||
R.disconnected = function(e, t) {
|
||||
return function(n) {
|
||||
E.onDisconnected(n, e), t && t.signal && t.signal.addEventListener("abort", () => E.offDisconnected(n, e));
|
||||
};
|
||||
};
|
||||
function T() {
|
||||
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(o) {
|
||||
function P() {
|
||||
let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(o) {
|
||||
for (let c of o)
|
||||
if (c.type === "childList") {
|
||||
if (h(c.addedNodes, !0)) {
|
||||
u();
|
||||
if (g(c.addedNodes, !0)) {
|
||||
i();
|
||||
continue;
|
||||
}
|
||||
g(c.removedNodes, !0) && u();
|
||||
b(c.removedNodes, !0) && i();
|
||||
}
|
||||
});
|
||||
return {
|
||||
onConnected(o, c) {
|
||||
d(), i(o).connected.push(c);
|
||||
d(), f(o).connected.push(c);
|
||||
},
|
||||
offConnected(o, c) {
|
||||
if (!e.has(o))
|
||||
return;
|
||||
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) {
|
||||
d(), i(o).disconnected.push(c);
|
||||
d(), f(o).disconnected.push(c);
|
||||
},
|
||||
offDisconnected(o, c) {
|
||||
if (!e.has(o))
|
||||
return;
|
||||
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) {
|
||||
c.connected.length || c.disconnect.length || (e.delete(o), u());
|
||||
function n(o, c) {
|
||||
c.connected.length || c.disconnect.length || (e.delete(o), i());
|
||||
}
|
||||
function i(o) {
|
||||
function f(o) {
|
||||
if (e.has(o))
|
||||
return e.get(o);
|
||||
let c = { connected: [], disconnected: [] };
|
||||
return e.set(o, c), c;
|
||||
}
|
||||
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() {
|
||||
!t || e.size || (t = !1, n.disconnect());
|
||||
}
|
||||
function f() {
|
||||
return new Promise(function(o) {
|
||||
(requestIdleCallback || requestAnimationFrame)(o);
|
||||
});
|
||||
}
|
||||
async function l(o) {
|
||||
e.size > 30 && await f();
|
||||
e.size > 30 && await u();
|
||||
let c = [];
|
||||
if (!(o instanceof Node))
|
||||
return c;
|
||||
@ -211,20 +214,20 @@
|
||||
s === o || !(s instanceof Node) || o.contains(s) && c.push(s);
|
||||
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) {
|
||||
for (let s of o) {
|
||||
if (c && l(s).then(g), !e.has(s))
|
||||
return !1;
|
||||
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
|
||||
[HTMLElement, DocumentFragment].forEach((e) => {
|
||||
let { append: t } = e.prototype;
|
||||
e.prototype.append = function(...n) {
|
||||
return t.apply(this, n), this;
|
||||
e.prototype.append = function(...r) {
|
||||
return t.apply(this, r), this;
|
||||
};
|
||||
});
|
||||
|
||||
globalThis.dde= {
|
||||
assign: C,
|
||||
classListDeclartive: L,
|
||||
createElement: I,
|
||||
el: I,
|
||||
empty: Z,
|
||||
assign: w,
|
||||
classListDeclartive: T,
|
||||
createElement: F,
|
||||
el: F,
|
||||
empty: I,
|
||||
namespace: z,
|
||||
on: N,
|
||||
registerReactivity: D
|
||||
on: R,
|
||||
registerReactivity: A
|
||||
};
|
||||
|
||||
})();
|
289
dist/esm-with-signals.js
vendored
289
dist/esm-with-signals.js
vendored
@ -16,27 +16,27 @@ var m = {
|
||||
return !1;
|
||||
},
|
||||
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);
|
||||
}
|
||||
function C(e) {
|
||||
function j(e) {
|
||||
return m.isPrototypeOf(e) && e !== m ? e : m;
|
||||
}
|
||||
|
||||
// src/dom.js
|
||||
var w = "html";
|
||||
var O = "html";
|
||||
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) {
|
||||
return w = "html", t;
|
||||
return O = "html", t;
|
||||
}
|
||||
};
|
||||
}
|
||||
function ee(e, t, ...n) {
|
||||
let r = C(this), o;
|
||||
let r = j(this), o;
|
||||
if (e === "<>") {
|
||||
if (r.isReactiveAtrribute(t))
|
||||
return r.reactiveElement(t, ...n);
|
||||
@ -47,57 +47,57 @@ function ee(e, t, ...n) {
|
||||
o = e(t || void 0);
|
||||
break;
|
||||
case e === "#text":
|
||||
o = N(document.createTextNode(""), t);
|
||||
o = A(document.createTextNode(""), t);
|
||||
break;
|
||||
case w !== "html":
|
||||
o = N(document.createElementNS(w, e), t);
|
||||
case O !== "html":
|
||||
o = A(document.createElementNS(O, e), t);
|
||||
break;
|
||||
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();
|
||||
function N(e, ...t) {
|
||||
let n = C(this);
|
||||
var x = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]'));
|
||||
function A(e, ...t) {
|
||||
let n = j(this);
|
||||
if (!t.length)
|
||||
return e;
|
||||
let r = e instanceof SVGElement, o = (r ? I : _).bind(null, e, "Attribute");
|
||||
return Object.entries(Object.assign({}, ...t)).forEach(function l([f, u]) {
|
||||
n.isReactiveAtrribute(u, f) && (u = n.processReactiveAttribute(el, f, u, l));
|
||||
let [p] = f;
|
||||
let r = e instanceof SVGElement, o = (r ? z : P).bind(null, e, "Attribute");
|
||||
return Object.entries(Object.assign({}, ...t)).forEach(function a([u, i]) {
|
||||
n.isReactiveAtrribute(i, u) && (i = n.processReactiveAttribute(e, u, i, a));
|
||||
let [p] = u;
|
||||
if (p === "=")
|
||||
return o(f.slice(1), u);
|
||||
return o(u.slice(1), i);
|
||||
if (p === ".")
|
||||
return L(e, f.slice(1), u);
|
||||
if (typeof u == "object")
|
||||
switch (f) {
|
||||
return L(e, u.slice(1), i);
|
||||
if (typeof i == "object")
|
||||
switch (u) {
|
||||
case "style":
|
||||
return E(u, _.bind(null, e.style, "Property"));
|
||||
return w(i, P.bind(null, e.style, "Property"));
|
||||
case "dataset":
|
||||
return E(u, L.bind(null, e.dataset));
|
||||
return w(i, L.bind(null, e.dataset));
|
||||
case "ariaset":
|
||||
return E(u, (x, v) => o("aria-" + x, v));
|
||||
return w(i, (E, v) => o("aria-" + E, v));
|
||||
case "classList":
|
||||
return q(e, u);
|
||||
return k(e, i);
|
||||
default:
|
||||
return Reflect.set(e, f, u);
|
||||
return Reflect.set(e, u, i);
|
||||
}
|
||||
if (/(aria|data)([A-Z])/.test(f))
|
||||
return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(f, u);
|
||||
switch (f) {
|
||||
if (/(aria|data)([A-Z])/.test(u))
|
||||
return u = u.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), o(u, i);
|
||||
switch (u) {
|
||||
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":
|
||||
if (!r)
|
||||
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;
|
||||
}
|
||||
function q(e, t) {
|
||||
return typeof t != "object" || E(
|
||||
function k(e, t) {
|
||||
return typeof t != "object" || w(
|
||||
t,
|
||||
(n, r) => e.classList.toggle(n, r === -1 ? void 0 : !!r)
|
||||
), e;
|
||||
@ -105,124 +105,127 @@ function q(e, t) {
|
||||
function te(e) {
|
||||
return Array.from(e.children).forEach((t) => t.remove()), e;
|
||||
}
|
||||
function z(e, t) {
|
||||
let n = e.nodeName + "," + t;
|
||||
if (S.has(n))
|
||||
return S.get(n);
|
||||
let r = D(e, t), o = !y(r.set);
|
||||
return S.set(n, o), o;
|
||||
function q(e, t) {
|
||||
let n = "HTMLElement," + t;
|
||||
if (e instanceof HTMLElement && x.has(n))
|
||||
return x.get(n);
|
||||
let r = e.nodeName + "," + t;
|
||||
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)
|
||||
return {};
|
||||
let n = Object.getOwnPropertyDescriptor(e, t);
|
||||
return n || D(e, t);
|
||||
return [{}, n, e];
|
||||
let r = Object.getOwnPropertyDescriptor(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));
|
||||
}
|
||||
function y(e) {
|
||||
function N(e) {
|
||||
return typeof e > "u";
|
||||
}
|
||||
function _(e, t, n, r) {
|
||||
return e[(y(r) ? "remove" : "set") + t](n, r);
|
||||
function P(e, t, n, r) {
|
||||
return e[(N(r) ? "remove" : "set") + t](n, r);
|
||||
}
|
||||
function I(e, t, n, r, o = null) {
|
||||
return e[(y(r) ? "remove" : "set") + t + "NS"](o, n, r);
|
||||
function z(e, t, n, r, o = null) {
|
||||
return e[(N(r) ? "remove" : "set") + t + "NS"](o, n, r);
|
||||
}
|
||||
function L(e, t, n) {
|
||||
return Reflect[y(n) ? "deleteProperty" : "set"](e, t, n);
|
||||
return Reflect.set(e, t, n);
|
||||
}
|
||||
|
||||
// src/events.js
|
||||
function T(e, t, n) {
|
||||
function D(e, t, n) {
|
||||
return (r) => (r.addEventListener(e, t, n), r);
|
||||
}
|
||||
var O = W();
|
||||
T.connected = function(e, t) {
|
||||
var y = I();
|
||||
D.connected = function(e, t) {
|
||||
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) {
|
||||
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) {
|
||||
for (let i of c)
|
||||
if (i.type === "childList") {
|
||||
if (x(i.addedNodes, !0)) {
|
||||
f();
|
||||
for (let s of c)
|
||||
if (s.type === "childList") {
|
||||
if (E(s.addedNodes, !0)) {
|
||||
u();
|
||||
continue;
|
||||
}
|
||||
v(i.removedNodes, !0) && f();
|
||||
v(s.removedNodes, !0) && u();
|
||||
}
|
||||
});
|
||||
return {
|
||||
onConnected(c, i) {
|
||||
l(), o(c).connected.push(i);
|
||||
onConnected(c, s) {
|
||||
a(), o(c).connected.push(s);
|
||||
},
|
||||
offConnected(c, i) {
|
||||
offConnected(c, s) {
|
||||
if (!e.has(c))
|
||||
return;
|
||||
let s = e.get(c), a = s.connected;
|
||||
a.splice(a.indexOf(i), 1), r(c, s);
|
||||
let f = e.get(c), d = f.connected;
|
||||
d.splice(d.indexOf(s), 1), r(c, f);
|
||||
},
|
||||
onDisconnected(c, i) {
|
||||
l(), o(c).disconnected.push(i);
|
||||
onDisconnected(c, s) {
|
||||
a(), o(c).disconnected.push(s);
|
||||
},
|
||||
offDisconnected(c, i) {
|
||||
offDisconnected(c, s) {
|
||||
if (!e.has(c))
|
||||
return;
|
||||
let s = e.get(c), a = s.disconnected;
|
||||
a.splice(a.indexOf(i), 1), r(c, s);
|
||||
let f = e.get(c), d = f.disconnected;
|
||||
d.splice(d.indexOf(s), 1), r(c, f);
|
||||
}
|
||||
};
|
||||
function r(c, i) {
|
||||
i.connected.length || i.disconnect.length || (e.delete(c), f());
|
||||
function r(c, s) {
|
||||
s.connected.length || s.disconnect.length || (e.delete(c), u());
|
||||
}
|
||||
function o(c) {
|
||||
if (e.has(c))
|
||||
return e.get(c);
|
||||
let i = { connected: [], disconnected: [] };
|
||||
return e.set(c, i), i;
|
||||
let s = { connected: [], disconnected: [] };
|
||||
return e.set(c, s), s;
|
||||
}
|
||||
function l() {
|
||||
function a() {
|
||||
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
|
||||
}
|
||||
function f() {
|
||||
function u() {
|
||||
!t || e.size || (t = !1, n.disconnect());
|
||||
}
|
||||
function u() {
|
||||
function i() {
|
||||
return new Promise(function(c) {
|
||||
(requestIdleCallback || requestAnimationFrame)(c);
|
||||
});
|
||||
}
|
||||
async function p(c) {
|
||||
e.size > 30 && await u();
|
||||
let i = [];
|
||||
e.size > 30 && await i();
|
||||
let s = [];
|
||||
if (!(c instanceof Node))
|
||||
return i;
|
||||
for (let s of e.keys())
|
||||
s === c || !(s instanceof Node) || c.contains(s) && i.push(s);
|
||||
return i;
|
||||
return s;
|
||||
for (let f of e.keys())
|
||||
f === c || !(f instanceof Node) || c.contains(f) && s.push(f);
|
||||
return s;
|
||||
}
|
||||
function x(c, i) {
|
||||
for (let s of c) {
|
||||
if (i && p(s).then(x), !e.has(s))
|
||||
function E(c, s) {
|
||||
for (let f of c) {
|
||||
if (s && p(f).then(E), !e.has(f))
|
||||
return !1;
|
||||
let a = e.get(s);
|
||||
return a.connected.forEach((j) => j(s)), a.connected.length = 0, a.disconnected.length || e.delete(s), !0;
|
||||
let d = e.get(f);
|
||||
return d.connected.forEach((C) => C(f)), d.connected.length = 0, d.disconnected.length || e.delete(f), !0;
|
||||
}
|
||||
}
|
||||
function v(c, i) {
|
||||
for (let s of c) {
|
||||
if (i && p(s).then(v), !e.has(s))
|
||||
function v(c, s) {
|
||||
for (let f of c) {
|
||||
if (s && p(f).then(v), !e.has(f))
|
||||
return !1;
|
||||
let a = e.get(s);
|
||||
return a.disconnected.forEach((j) => j(s)), a.connected.length = 0, a.disconnected.length = 0, e.delete(s), !0;
|
||||
let d = e.get(f);
|
||||
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
|
||||
var d = Symbol.for("signal");
|
||||
var l = Symbol.for("signal");
|
||||
function b(e) {
|
||||
try {
|
||||
return Reflect.has(e, d);
|
||||
return Reflect.has(e, l);
|
||||
} catch {
|
||||
return !1;
|
||||
}
|
||||
}
|
||||
function R(e, t) {
|
||||
if (typeof e != "function")
|
||||
return F(e, t);
|
||||
return M(e, t);
|
||||
if (b(e))
|
||||
return e;
|
||||
let n = F();
|
||||
return M(() => n(e())), n;
|
||||
let n = M();
|
||||
return $(() => n(e())), n;
|
||||
}
|
||||
R.action = function(e, t, ...n) {
|
||||
if (!b(e))
|
||||
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))
|
||||
throw new Error(`'${e}' has no action with name '${t}'!`);
|
||||
if (o[t].apply(r, n), 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) {
|
||||
if (Array.isArray(t))
|
||||
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) {
|
||||
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) {
|
||||
return b(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) {
|
||||
return P(n, (o) => r([t, o])), n();
|
||||
return _(n, (o) => r([t, o])), n();
|
||||
},
|
||||
reactiveElement(e, t) {
|
||||
let n = document.createComment("<> #reactive"), r = document.createComment("</> #reactive"), o = document.createDocumentFragment();
|
||||
o.append(n, r);
|
||||
let l = (f) => {
|
||||
let a = (u) => {
|
||||
if (!n.parentNode || !r.parentNode)
|
||||
return k(e, l);
|
||||
let u = t(f);
|
||||
Array.isArray(u) || (u = [u]);
|
||||
return F(e, a);
|
||||
let i = t(u);
|
||||
Array.isArray(i) || (i = [i]);
|
||||
let p = n;
|
||||
for (; (p = n.nextSibling) !== r; )
|
||||
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) {
|
||||
let n = (...r) => r.length ? U(n, r[0]) : H(n);
|
||||
return B(n, e, t);
|
||||
function M(e, t) {
|
||||
let n = (...r) => r.length ? J(n, r[0]) : G(n);
|
||||
return Z(n, e, t);
|
||||
}
|
||||
var Z = Object.assign(/* @__PURE__ */ Object.create(null), {
|
||||
var W = Object.assign(/* @__PURE__ */ Object.create(null), {
|
||||
stopPropagation() {
|
||||
this.skip = !0;
|
||||
}
|
||||
});
|
||||
function B(e, t, n) {
|
||||
return h(n) !== "[object Object]" && (n = {}), e[d] = {
|
||||
function Z(e, t, n) {
|
||||
return h(n) !== "[object Object]" && (n = {}), e[l] = {
|
||||
value: t,
|
||||
actions: n,
|
||||
listeners: /* @__PURE__ */ new Set()
|
||||
}, Object.setPrototypeOf(e[d], Z), e;
|
||||
}, Object.setPrototypeOf(e[l], W), e;
|
||||
}
|
||||
var g = [];
|
||||
function M(e) {
|
||||
function $(e) {
|
||||
let t = function() {
|
||||
g.push(t), e(), g.pop();
|
||||
};
|
||||
g.push(t), e(), g.pop();
|
||||
}
|
||||
function G() {
|
||||
function B() {
|
||||
return g[g.length - 1];
|
||||
}
|
||||
function H(e) {
|
||||
if (!e[d])
|
||||
function G(e) {
|
||||
if (!e[l])
|
||||
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;
|
||||
}
|
||||
function U(e, t) {
|
||||
if (!e[d])
|
||||
function J(e, t) {
|
||||
if (!e[l])
|
||||
return;
|
||||
let n = e[d];
|
||||
let n = e[l];
|
||||
if (n.value !== t)
|
||||
return n.value = t, n.listeners.forEach((r) => r(t)), t;
|
||||
}
|
||||
function V(e) {
|
||||
return e[d].value;
|
||||
function U(e) {
|
||||
return e[l].value;
|
||||
}
|
||||
function P(e, t) {
|
||||
return e[d].listeners.add(t);
|
||||
function _(e, t) {
|
||||
return e[l].listeners.add(t);
|
||||
}
|
||||
function k(e, t) {
|
||||
return e[d].listeners.delete(t);
|
||||
function F(e, t) {
|
||||
return e[l].listeners.delete(t);
|
||||
}
|
||||
|
||||
// src/signals.js
|
||||
A($);
|
||||
S(H);
|
||||
export {
|
||||
R as S,
|
||||
N as assign,
|
||||
q as classListDeclartive,
|
||||
A as assign,
|
||||
k as classListDeclartive,
|
||||
ee as createElement,
|
||||
ee as el,
|
||||
te as empty,
|
||||
b as isSignal,
|
||||
Y as namespace,
|
||||
T as on,
|
||||
A as registerReactivity,
|
||||
M as watch
|
||||
D as on,
|
||||
S as registerReactivity,
|
||||
$ as watch
|
||||
};
|
||||
|
221
dist/esm.js
vendored
221
dist/esm.js
vendored
@ -1,5 +1,5 @@
|
||||
// src/helpers.js
|
||||
function y(e) {
|
||||
function N(e) {
|
||||
let t = typeof e;
|
||||
return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e);
|
||||
}
|
||||
@ -10,16 +10,16 @@ var p = {
|
||||
return !1;
|
||||
},
|
||||
isTextContent(e) {
|
||||
return y(e) !== "[object Object]";
|
||||
return N(e) !== "[object Object]";
|
||||
},
|
||||
processReactiveAttribute(e, t, n, r) {
|
||||
processReactiveAttribute(e, t, r, n) {
|
||||
return !1;
|
||||
},
|
||||
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);
|
||||
}
|
||||
function O(e) {
|
||||
@ -27,181 +27,184 @@ function O(e) {
|
||||
}
|
||||
|
||||
// src/dom.js
|
||||
var m = "html";
|
||||
var x = "html";
|
||||
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) {
|
||||
return m = "html", t;
|
||||
return x = "html", t;
|
||||
}
|
||||
};
|
||||
}
|
||||
function I(e, t, ...n) {
|
||||
let r = O(this), i;
|
||||
function F(e, t, ...r) {
|
||||
let n = O(this), f;
|
||||
if (e === "<>") {
|
||||
if (r.isReactiveAtrribute(t))
|
||||
return r.reactiveElement(t, ...n);
|
||||
i = document.createDocumentFragment();
|
||||
if (n.isReactiveAtrribute(t))
|
||||
return n.reactiveElement(t, ...r);
|
||||
f = document.createDocumentFragment();
|
||||
}
|
||||
switch (r.isTextContent(t) && (t = { textContent: t }), !0) {
|
||||
switch (n.isTextContent(t) && (t = { textContent: t }), !0) {
|
||||
case typeof e == "function":
|
||||
i = e(t || void 0);
|
||||
f = e(t || void 0);
|
||||
break;
|
||||
case e === "#text":
|
||||
i = C(document.createTextNode(""), t);
|
||||
f = w(document.createTextNode(""), t);
|
||||
break;
|
||||
case m !== "html":
|
||||
i = C(document.createElementNS(m, e), t);
|
||||
case x !== "html":
|
||||
f = w(document.createElementNS(x, e), t);
|
||||
break;
|
||||
case !i:
|
||||
i = C(document.createElement(e), t);
|
||||
case !f:
|
||||
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();
|
||||
function C(e, ...t) {
|
||||
let n = O(this);
|
||||
var h = new Map(JSON.parse('[["#text,textContent",true],["HTMLElement,textContent",true],["HTMLElement,className",true]]'));
|
||||
function w(e, ...t) {
|
||||
let r = O(this);
|
||||
if (!t.length)
|
||||
return e;
|
||||
let r = e instanceof SVGElement, i = (r ? S : R).bind(null, e, "Attribute");
|
||||
return Object.entries(Object.assign({}, ...t)).forEach(function d([u, f]) {
|
||||
n.isReactiveAtrribute(f, u) && (f = n.processReactiveAttribute(el, u, f, d));
|
||||
let [l] = u;
|
||||
let n = e instanceof SVGElement, f = (n ? M : j).bind(null, e, "Attribute");
|
||||
return Object.entries(Object.assign({}, ...t)).forEach(function d([i, u]) {
|
||||
r.isReactiveAtrribute(u, i) && (u = r.processReactiveAttribute(e, i, u, d));
|
||||
let [l] = i;
|
||||
if (l === "=")
|
||||
return i(u.slice(1), f);
|
||||
return f(i.slice(1), u);
|
||||
if (l === ".")
|
||||
return j(e, u.slice(1), f);
|
||||
if (typeof f == "object")
|
||||
switch (u) {
|
||||
return C(e, i.slice(1), u);
|
||||
if (typeof u == "object")
|
||||
switch (i) {
|
||||
case "style":
|
||||
return b(f, R.bind(null, e.style, "Property"));
|
||||
return m(u, j.bind(null, e.style, "Property"));
|
||||
case "dataset":
|
||||
return b(f, j.bind(null, e.dataset));
|
||||
return m(u, C.bind(null, e.dataset));
|
||||
case "ariaset":
|
||||
return b(f, (h, g) => i("aria-" + h, g));
|
||||
return m(u, (g, b) => f("aria-" + g, b));
|
||||
case "classList":
|
||||
return L(e, f);
|
||||
return T(e, u);
|
||||
default:
|
||||
return Reflect.set(e, u, f);
|
||||
return Reflect.set(e, i, u);
|
||||
}
|
||||
if (/(aria|data)([A-Z])/.test(u))
|
||||
return u = u.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(u, f);
|
||||
switch (u) {
|
||||
if (/(aria|data)([A-Z])/.test(i))
|
||||
return i = i.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), f(i, u);
|
||||
switch (i) {
|
||||
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":
|
||||
if (!r)
|
||||
if (!n)
|
||||
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;
|
||||
}
|
||||
function L(e, t) {
|
||||
return typeof t != "object" || b(
|
||||
function T(e, t) {
|
||||
return typeof t != "object" || m(
|
||||
t,
|
||||
(n, r) => e.classList.toggle(n, r === -1 ? void 0 : !!r)
|
||||
(r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n)
|
||||
), e;
|
||||
}
|
||||
function Z(e) {
|
||||
function I(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;
|
||||
if (w.has(n))
|
||||
return w.get(n);
|
||||
let r = A(e, t), i = !x(r.set);
|
||||
return w.set(n, i), i;
|
||||
if (h.has(n))
|
||||
return h.get(n);
|
||||
let [f, d, i] = y(e, t), u = !L(f.set);
|
||||
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)
|
||||
return {};
|
||||
return [{}, r, e];
|
||||
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) {
|
||||
return Object.entries(e).forEach(([n, r]) => t(n, r));
|
||||
function m(e, t) {
|
||||
return Object.entries(e).forEach(([r, n]) => t(r, n));
|
||||
}
|
||||
function x(e) {
|
||||
function L(e) {
|
||||
return typeof e > "u";
|
||||
}
|
||||
function R(e, t, n, r) {
|
||||
return e[(x(r) ? "remove" : "set") + t](n, r);
|
||||
function j(e, t, r, n) {
|
||||
return e[(L(n) ? "remove" : "set") + t](r, n);
|
||||
}
|
||||
function S(e, t, n, r, i = null) {
|
||||
return e[(x(r) ? "remove" : "set") + t + "NS"](i, n, r);
|
||||
function M(e, t, r, n, f = null) {
|
||||
return e[(L(n) ? "remove" : "set") + t + "NS"](f, r, n);
|
||||
}
|
||||
function j(e, t, n) {
|
||||
return Reflect[x(n) ? "deleteProperty" : "set"](e, t, n);
|
||||
function C(e, t, r) {
|
||||
return Reflect.set(e, t, r);
|
||||
}
|
||||
|
||||
// src/events.js
|
||||
function N(e, t, n) {
|
||||
return (r) => (r.addEventListener(e, t, n), r);
|
||||
function R(e, t, r) {
|
||||
return (n) => (n.addEventListener(e, t, r), n);
|
||||
}
|
||||
var v = T();
|
||||
N.connected = function(e, t) {
|
||||
return function(r) {
|
||||
v.onConnected(r, e), t && t.signal && t.signal.addEventListener("abort", () => v.offConnected(r, e));
|
||||
var E = P();
|
||||
R.connected = function(e, t) {
|
||||
return function(n) {
|
||||
E.onConnected(n, e), t && t.signal && t.signal.addEventListener("abort", () => E.offConnected(n, e));
|
||||
};
|
||||
};
|
||||
N.disconnected = function(e, t) {
|
||||
return function(r) {
|
||||
v.onDisconnected(r, e), t && t.signal && t.signal.addEventListener("abort", () => v.offDisconnected(r, e));
|
||||
R.disconnected = function(e, t) {
|
||||
return function(n) {
|
||||
E.onDisconnected(n, e), t && t.signal && t.signal.addEventListener("abort", () => E.offDisconnected(n, e));
|
||||
};
|
||||
};
|
||||
function T() {
|
||||
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(o) {
|
||||
function P() {
|
||||
let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(o) {
|
||||
for (let c of o)
|
||||
if (c.type === "childList") {
|
||||
if (h(c.addedNodes, !0)) {
|
||||
u();
|
||||
if (g(c.addedNodes, !0)) {
|
||||
i();
|
||||
continue;
|
||||
}
|
||||
g(c.removedNodes, !0) && u();
|
||||
b(c.removedNodes, !0) && i();
|
||||
}
|
||||
});
|
||||
return {
|
||||
onConnected(o, c) {
|
||||
d(), i(o).connected.push(c);
|
||||
d(), f(o).connected.push(c);
|
||||
},
|
||||
offConnected(o, c) {
|
||||
if (!e.has(o))
|
||||
return;
|
||||
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) {
|
||||
d(), i(o).disconnected.push(c);
|
||||
d(), f(o).disconnected.push(c);
|
||||
},
|
||||
offDisconnected(o, c) {
|
||||
if (!e.has(o))
|
||||
return;
|
||||
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) {
|
||||
c.connected.length || c.disconnect.length || (e.delete(o), u());
|
||||
function n(o, c) {
|
||||
c.connected.length || c.disconnect.length || (e.delete(o), i());
|
||||
}
|
||||
function i(o) {
|
||||
function f(o) {
|
||||
if (e.has(o))
|
||||
return e.get(o);
|
||||
let c = { connected: [], disconnected: [] };
|
||||
return e.set(o, c), c;
|
||||
}
|
||||
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() {
|
||||
!t || e.size || (t = !1, n.disconnect());
|
||||
}
|
||||
function f() {
|
||||
return new Promise(function(o) {
|
||||
(requestIdleCallback || requestAnimationFrame)(o);
|
||||
});
|
||||
}
|
||||
async function l(o) {
|
||||
e.size > 30 && await f();
|
||||
e.size > 30 && await u();
|
||||
let c = [];
|
||||
if (!(o instanceof Node))
|
||||
return c;
|
||||
@ -209,20 +212,20 @@ function T() {
|
||||
s === o || !(s instanceof Node) || o.contains(s) && c.push(s);
|
||||
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) {
|
||||
for (let s of o) {
|
||||
if (c && l(s).then(g), !e.has(s))
|
||||
return !1;
|
||||
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
|
||||
[HTMLElement, DocumentFragment].forEach((e) => {
|
||||
let { append: t } = e.prototype;
|
||||
e.prototype.append = function(...n) {
|
||||
return t.apply(this, n), this;
|
||||
e.prototype.append = function(...r) {
|
||||
return t.apply(this, r), this;
|
||||
};
|
||||
});
|
||||
export {
|
||||
C as assign,
|
||||
L as classListDeclartive,
|
||||
I as createElement,
|
||||
I as el,
|
||||
Z as empty,
|
||||
w as assign,
|
||||
T as classListDeclartive,
|
||||
F as createElement,
|
||||
F as el,
|
||||
I as empty,
|
||||
z as namespace,
|
||||
N as on,
|
||||
D as registerReactivity
|
||||
R as on,
|
||||
A as registerReactivity
|
||||
};
|
||||
|
4149
package-lock.json
generated
4149
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"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.",
|
||||
"author": "Jan Andrle <andrle.jan@centrum.cz>",
|
||||
"license": "MIT",
|
||||
@ -58,13 +58,16 @@
|
||||
"node": ">=18"
|
||||
},
|
||||
"jshintConfig": {
|
||||
"esversion": 6,
|
||||
"node": "true",
|
||||
"esversion": 11,
|
||||
"browser": true,
|
||||
"undef": "true",
|
||||
"latedef": "true",
|
||||
"maxparams": 4,
|
||||
"maxparams": 5,
|
||||
"maxdepth": 3,
|
||||
"maxcomplexity": 19
|
||||
"maxcomplexity": 10,
|
||||
"globals": {
|
||||
"requestIdleCallback": false
|
||||
}
|
||||
},
|
||||
"size-limit": [
|
||||
{
|
||||
@ -93,6 +96,7 @@
|
||||
"devDependencies": {
|
||||
"@size-limit/preset-small-lib": "^8.2.6",
|
||||
"esbuild": "^0.19.2",
|
||||
"jshint": "^2.13.6",
|
||||
"nodejsscript": "github:jaandrle/nodejsscript#dev-v1",
|
||||
"size-limit-node-esbuild": "^0.2.0"
|
||||
}
|
||||
|
28
src/dom.js
28
src/dom.js
@ -1,5 +1,6 @@
|
||||
import { signals } from "./signals-common.js";
|
||||
|
||||
/** @type {"html"|"svg"|string} */
|
||||
let namespace_curr= "html";
|
||||
export function namespace(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 };
|
||||
|
||||
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){
|
||||
const s= signals(this);
|
||||
if(!attributes.length) return element;
|
||||
const is_svg= element instanceof SVGElement;
|
||||
const setRemoveAttr= (is_svg ? setRemoveNS : setRemove).bind(null, element, "Attribute");
|
||||
|
||||
/* jshint maxcomplexity:15 */
|
||||
Object.entries(Object.assign({}, ...attributes)).forEach(function assignNth([ key, attr ]){
|
||||
if(s.isReactiveAtrribute(attr, key))
|
||||
attr= s.processReactiveAttribute(el, key, attr, assignNth);
|
||||
attr= s.processReactiveAttribute(element, key, attr, assignNth);
|
||||
const [ k ]= key;
|
||||
if("="===k) return setRemoveAttr(key.slice(1), attr);
|
||||
if("."===k) return setDelete(element, key.slice(1), attr);
|
||||
if(typeof attr === "object"){
|
||||
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 "ariaset": return forEachEntries(attr, (key, val)=> setRemoveAttr("aria-"+key, val));
|
||||
case "classList": return classListDeclartive(element, attr);
|
||||
@ -71,7 +74,7 @@ export function classListDeclartive(element, toggle){
|
||||
|
||||
forEachEntries(toggle,
|
||||
(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;
|
||||
}
|
||||
export function empty(el){
|
||||
@ -79,18 +82,23 @@ export function empty(el){
|
||||
return el;
|
||||
}
|
||||
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;
|
||||
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);
|
||||
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;
|
||||
}
|
||||
function getPropDescriptor(p, key){
|
||||
function getPropDescriptor(p, key, level= 0){
|
||||
p= Object.getPrototypeOf(p);
|
||||
if(!p) return {};
|
||||
if(!p) return [ {}, level, p ];
|
||||
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)); }
|
||||
@ -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 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); }
|
||||
|
@ -3,13 +3,14 @@ export const signals_global= {
|
||||
isReactiveAtrribute(attr, key){ return false; },
|
||||
isTextContent(attributes){ return typeOf(attributes)!=="[object Object]"; },
|
||||
processReactiveAttribute(el, key, attr, assignNth){ return false; },
|
||||
reactiveElement(attributes, ...connect){ return document.createDocumentFragment(); }
|
||||
reactiveElement(attributes, ...connect){ return null; }
|
||||
};
|
||||
export function registerReactivity(def, global= true){
|
||||
if(global) return Object.assign(signals_global, def);
|
||||
Object.setPrototypeOf(def, signals_global);
|
||||
return def;
|
||||
}
|
||||
/** @param {unknown} _this @returns {typeof signals_global} */
|
||||
export function signals(_this){
|
||||
return signals_global.isPrototypeOf(_this) && _this!==signals_global ? _this : signals_global;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ S.on= function on(signals, listener, options){
|
||||
if(options && options.signal)
|
||||
options.signal.addEventListener("abort", ()=> removeSignalListener(signals, listener));
|
||||
//TODO cleanup when signal removed (also TODO)
|
||||
}
|
||||
};
|
||||
S.clear= function(...signals){
|
||||
for(const signal of signals){
|
||||
signal[mark].listeners.clear();
|
||||
@ -100,7 +100,7 @@ export function watch(context){
|
||||
stack_watch.push(contextReWatch);
|
||||
context();
|
||||
stack_watch.pop();
|
||||
};
|
||||
}
|
||||
function currentContext(){
|
||||
return stack_watch[stack_watch.length - 1];
|
||||
}
|
||||
@ -116,7 +116,7 @@ function write(signal, value){
|
||||
const s= signal[mark];
|
||||
if(s.value===value) return;
|
||||
s.value= value;
|
||||
s.listeners.forEach(fn=> fn(value))
|
||||
s.listeners.forEach(fn=> fn(value));
|
||||
return value;
|
||||
}
|
||||
|
||||
|
@ -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 { empty, namespace, on, dispatch } from "../index.js";
|
||||
// import "../dist/dde-with-signals.js";
|
||||
// Object.assign(globalThis, dde);
|
||||
// import { el, on, off, S } from "../dist/esm-with-signals.js";
|
||||
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 };
|
||||
|
||||
function createStyle(){
|
||||
|
Loading…
Reference in New Issue
Block a user