mirror of
https://github.com/jaandrle/deka-dom-el
synced 2024-11-25 17:49:37 +01:00
🚀 use native listeners & scope
This commit is contained in:
parent
7417565fa5
commit
ebbb76e9a0
@ -25,7 +25,7 @@ function toDDE(file, out){
|
|||||||
const name= "dde";
|
const name= "dde";
|
||||||
echo(`\n ${out} (${file} → globalThis.${name})\n`);
|
echo(`\n ${out} (${file} → globalThis.${name})\n`);
|
||||||
|
|
||||||
let content= s.cat(file).toString().split("export {");
|
let content= s.cat(file).toString().split(/export ?{/);
|
||||||
content.splice(1, 0, `\nglobalThis.${name}= {`);
|
content.splice(1, 0, `\nglobalThis.${name}= {`);
|
||||||
content[2]= content[2].replace(/^(\t*)(.*) as ([^,\n]*)(,?)$/mg, "$1$3: $2$4");
|
content[2]= content[2].replace(/^(\t*)(.*) as ([^,\n]*)(,?)$/mg, "$1$3: $2$4");
|
||||||
s.echo([
|
s.echo([
|
||||||
|
261
dist/dde-with-signals.js
vendored
261
dist/dde-with-signals.js
vendored
@ -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/signals-common.js
|
// src/signals-common.js
|
||||||
var E = {
|
var w = {
|
||||||
isSignal(e) {
|
isSignal(e) {
|
||||||
return !1;
|
return !1;
|
||||||
},
|
},
|
||||||
@ -9,22 +9,22 @@
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function C(e, t = !0) {
|
function A(e, t = !0) {
|
||||||
return t ? Object.assign(E, e) : (Object.setPrototypeOf(e, E), e);
|
return t ? Object.assign(w, e) : (Object.setPrototypeOf(e, w), e);
|
||||||
}
|
}
|
||||||
function x(e) {
|
function S(e) {
|
||||||
return E.isPrototypeOf(e) && e !== E ? e : E;
|
return w.isPrototypeOf(e) && e !== w ? e : w;
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/helpers.js
|
// src/helpers.js
|
||||||
function m(e) {
|
function m(e) {
|
||||||
return typeof e > "u";
|
return typeof e > "u";
|
||||||
}
|
}
|
||||||
function N(e) {
|
function D(e) {
|
||||||
let t = typeof e;
|
let t = typeof e;
|
||||||
return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e);
|
return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e);
|
||||||
}
|
}
|
||||||
function L(e, t) {
|
function C(e, t) {
|
||||||
if (!e || !(e instanceof AbortSignal))
|
if (!e || !(e instanceof AbortSignal))
|
||||||
return !0;
|
return !0;
|
||||||
if (!e.aborted)
|
if (!e.aborted)
|
||||||
@ -34,8 +34,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// src/dom-common.js
|
// src/dom-common.js
|
||||||
var P = { setDeleteAttr: W };
|
var P = { setDeleteAttr: q };
|
||||||
function W(e, t, n) {
|
function q(e, t, n) {
|
||||||
if (Reflect.set(e, t, n), !!m(n)) {
|
if (Reflect.set(e, t, n), !!m(n)) {
|
||||||
if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined")
|
if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined")
|
||||||
return e.removeAttribute(t);
|
return e.removeAttribute(t);
|
||||||
@ -45,77 +45,85 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// src/dom.js
|
// src/dom.js
|
||||||
var w = "html";
|
var b = "html", F = {
|
||||||
function oe(e) {
|
elNamespace(e) {
|
||||||
return w = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
|
return b = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
|
||||||
append(...t) {
|
append(...t) {
|
||||||
return w = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t);
|
return b = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
get namespace() {
|
||||||
|
return b;
|
||||||
|
},
|
||||||
|
set namespace(e) {
|
||||||
|
return b = e;
|
||||||
}
|
}
|
||||||
function ce(e, t, ...n) {
|
}, ce = Object.assign((e) => e ? e(document.body) : document.body, F);
|
||||||
let r = this, o = x(this), c;
|
function ie(e, t, ...n) {
|
||||||
|
let r = this, o = S(this), c;
|
||||||
switch ((Object(t) !== t || o.isSignal(t)) && (t = { textContent: t }), !0) {
|
switch ((Object(t) !== t || o.isSignal(t)) && (t = { textContent: t }), !0) {
|
||||||
case typeof e == "function": {
|
case typeof e == "function": {
|
||||||
c = e(t || void 0, (s) => s ? (n.unshift(s), void 0) : c);
|
let l = Object.assign((u) => u ? (n.unshift(u), void 0) : c, F);
|
||||||
|
c = e(t || void 0, l), b = "html";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case e === "#text":
|
case e === "#text":
|
||||||
c = S.call(r, document.createTextNode(""), t);
|
c = y.call(r, document.createTextNode(""), t);
|
||||||
break;
|
break;
|
||||||
case e === "<>":
|
case e === "<>":
|
||||||
c = S.call(r, document.createDocumentFragment(), t);
|
c = y.call(r, document.createDocumentFragment(), t);
|
||||||
break;
|
break;
|
||||||
case w !== "html":
|
case b !== "html":
|
||||||
c = S.call(r, document.createElementNS(w, e), t);
|
c = y.call(r, document.createElementNS(b, e), t);
|
||||||
break;
|
break;
|
||||||
case !c:
|
case !c:
|
||||||
c = S.call(r, document.createElement(e), t);
|
c = y.call(r, document.createElement(e), t);
|
||||||
}
|
}
|
||||||
return n.forEach((p) => p(c)), c;
|
return n.forEach((l) => l(c)), c;
|
||||||
}
|
}
|
||||||
var { setDeleteAttr: j } = P;
|
var { setDeleteAttr: j } = P;
|
||||||
function S(e, ...t) {
|
function y(e, ...t) {
|
||||||
let n = this, r = x(this);
|
let n = this, r = S(this);
|
||||||
if (!t.length)
|
if (!t.length)
|
||||||
return e;
|
return e;
|
||||||
let c = (e instanceof SVGElement ? I : H).bind(null, e, "Attribute");
|
let c = (e instanceof SVGElement ? I : H).bind(null, e, "Attribute");
|
||||||
return Object.entries(Object.assign({}, ...t)).forEach(function p([s, a]) {
|
return Object.entries(Object.assign({}, ...t)).forEach(function l([u, a]) {
|
||||||
a = r.processReactiveAttribute(e, s, a, p);
|
a = r.processReactiveAttribute(e, u, a, l);
|
||||||
let [b] = s;
|
let [v] = u;
|
||||||
if (b === "=")
|
if (v === "=")
|
||||||
return c(s.slice(1), a);
|
return c(u.slice(1), a);
|
||||||
if (b === ".")
|
if (v === ".")
|
||||||
return F(e, s.slice(1), a);
|
return W(e, u.slice(1), a);
|
||||||
if (/(aria|data)([A-Z])/.test(s))
|
if (/(aria|data)([A-Z])/.test(u))
|
||||||
return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), c(s, a);
|
return u = u.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), c(u, a);
|
||||||
switch (s === "className" && (s = "class"), s) {
|
switch (u === "className" && (u = "class"), u) {
|
||||||
case "xlink:href":
|
case "xlink:href":
|
||||||
return c(s, a, "http://www.w3.org/1999/xlink");
|
return c(u, a, "http://www.w3.org/1999/xlink");
|
||||||
case "textContent":
|
case "textContent":
|
||||||
return j(e, s, a);
|
return j(e, u, a);
|
||||||
case "style":
|
case "style":
|
||||||
if (typeof a != "object")
|
if (typeof a != "object")
|
||||||
break;
|
break;
|
||||||
case "dataset":
|
case "dataset":
|
||||||
return _(r, a, F.bind(null, e[s]));
|
return L(r, a, W.bind(null, e[u]));
|
||||||
case "ariaset":
|
case "ariaset":
|
||||||
return _(r, a, (v, i) => c("aria-" + v, i));
|
return L(r, a, (x, i) => c("aria-" + x, i));
|
||||||
case "classList":
|
case "classList":
|
||||||
return B.call(n, e, a);
|
return B.call(n, e, a);
|
||||||
}
|
}
|
||||||
return G(e, s) ? j(e, s, a) : c(s, a);
|
return G(e, u) ? j(e, u, a) : c(u, a);
|
||||||
}), e;
|
}), e;
|
||||||
}
|
}
|
||||||
function B(e, t) {
|
function B(e, t) {
|
||||||
let n = x(this);
|
let n = S(this);
|
||||||
return _(
|
return L(
|
||||||
n,
|
n,
|
||||||
t,
|
t,
|
||||||
(r, o) => e.classList.toggle(r, o === -1 ? void 0 : !!o)
|
(r, o) => e.classList.toggle(r, o === -1 ? void 0 : !!o)
|
||||||
), e;
|
), e;
|
||||||
}
|
}
|
||||||
function se(e) {
|
function fe(e) {
|
||||||
return Array.from(e.children).forEach((t) => t.remove()), e;
|
return Array.from(e.children).forEach((t) => t.remove()), e;
|
||||||
}
|
}
|
||||||
function G(e, t) {
|
function G(e, t) {
|
||||||
@ -130,10 +138,10 @@
|
|||||||
let n = Object.getOwnPropertyDescriptor(e, t);
|
let n = Object.getOwnPropertyDescriptor(e, t);
|
||||||
return n || M(e, t);
|
return n || M(e, t);
|
||||||
}
|
}
|
||||||
function _(e, t, n) {
|
function L(e, t, n) {
|
||||||
if (!(typeof t != "object" || t === null))
|
if (!(typeof t != "object" || t === null))
|
||||||
return Object.entries(t).forEach(function([o, c]) {
|
return Object.entries(t).forEach(function([o, c]) {
|
||||||
o && (c = e.processReactiveAttribute(t, o, c, (p) => n(...p)), n(o, c));
|
o && (c = e.processReactiveAttribute(t, o, c, (l) => n(...l)), n(o, c));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function z(e) {
|
function z(e) {
|
||||||
@ -145,13 +153,13 @@
|
|||||||
function I(e, t, n, r, o = null) {
|
function I(e, t, n, r, o = null) {
|
||||||
return e[(m(r) ? "remove" : "set") + t + "NS"](o, n, z(r));
|
return e[(m(r) ? "remove" : "set") + t + "NS"](o, n, z(r));
|
||||||
}
|
}
|
||||||
function F(e, t, n) {
|
function W(e, t, n) {
|
||||||
if (Reflect.set(e, t, n), !!m(n))
|
if (Reflect.set(e, t, n), !!m(n))
|
||||||
return Reflect.deleteProperty(e, t);
|
return Reflect.deleteProperty(e, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/events.js
|
// src/events.js
|
||||||
function ae(e, t, ...n) {
|
function de(e, t, ...n) {
|
||||||
let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t);
|
let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t);
|
||||||
return e.dispatchEvent(r);
|
return e.dispatchEvent(r);
|
||||||
}
|
}
|
||||||
@ -162,92 +170,99 @@
|
|||||||
}
|
}
|
||||||
var O = J();
|
var O = J();
|
||||||
T.connected = function(e, t) {
|
T.connected = function(e, t) {
|
||||||
return function(r) {
|
return typeof t != "object" && (t = {}), t.once = !0, function(r) {
|
||||||
return typeof r.connectedCallback == "function" ? (r.addEventListener("dde:connected", e, t), r) : (L(t && t.signal, () => O.offConnected(r, e)) && (r.isConnected ? e(new Event("dde:connected")) : O.onConnected(r, e)), r);
|
return r.addEventListener("dde:connected", e, t), typeof r.connectedCallback == "function" ? r : r.isConnected ? (r.dispatchEvent(new Event("dde:connected")), r) : (C(t.signal, () => O.offConnected(r, e)) && O.onConnected(r, e), r);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
T.disconnected = function(e, t) {
|
T.disconnected = function(e, t) {
|
||||||
return function(r) {
|
return typeof t != "object" && (t = {}), t.once = !0, function(r) {
|
||||||
return typeof r.disconnectedCallback == "function" ? (r.addEventListener("dde:disconnected", e, t), r) : (L(t && t.signal, () => O.offDisconnected(r, e)) && O.onDisconnected(r, e), r);
|
return r.addEventListener("dde:disconnected", e, t), typeof r.disconnectedCallback == "function" || C(t.signal, () => O.offDisconnected(r, e)) && O.onDisconnected(r, e), r;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
function J() {
|
function J() {
|
||||||
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(i) {
|
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(i) {
|
||||||
for (let f of i)
|
for (let s of i)
|
||||||
if (f.type === "childList") {
|
if (s.type === "childList") {
|
||||||
if (b(f.addedNodes, !0)) {
|
if (v(s.addedNodes, !0)) {
|
||||||
p();
|
l();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
v(f.removedNodes, !0) && p();
|
x(s.removedNodes, !0) && l();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
onConnected(i, f) {
|
onConnected(i, s) {
|
||||||
c(), o(i).connected.push(f);
|
c();
|
||||||
|
let f = o(i);
|
||||||
|
f.connected.has(s) || (f.connected.add(s), f.length_c += 1);
|
||||||
},
|
},
|
||||||
offConnected(i, f) {
|
offConnected(i, s) {
|
||||||
if (!e.has(i))
|
if (!e.has(i))
|
||||||
return;
|
return;
|
||||||
let u = e.get(i), l = u.connected;
|
let f = e.get(i);
|
||||||
l.splice(l.indexOf(f), 1), r(i, u);
|
f.connected.has(s) && (f.connected.delete(s), f.length_c -= 1, r(i, f));
|
||||||
},
|
},
|
||||||
onDisconnected(i, f) {
|
onDisconnected(i, s) {
|
||||||
c(), o(i).disconnected.push(f);
|
c();
|
||||||
|
let f = o(i);
|
||||||
|
f.disconnected.has(s) || (f.disconnected.add(s), f.length_d += 1);
|
||||||
},
|
},
|
||||||
offDisconnected(i, f) {
|
offDisconnected(i, s) {
|
||||||
if (!e.has(i))
|
if (!e.has(i))
|
||||||
return;
|
return;
|
||||||
let u = e.get(i), l = u.disconnected;
|
let f = e.get(i);
|
||||||
l.splice(l.indexOf(f), 1), r(i, u);
|
f.disconnected.has(s) && (f.disconnected.delete(s), f.length_d -= 1, r(i, f));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function r(i, f) {
|
function r(i, s) {
|
||||||
f.connected.length || f.disconnected.length || (e.delete(i), p());
|
s.length_c || s.length_d || (e.delete(i), l());
|
||||||
}
|
}
|
||||||
function o(i) {
|
function o(i) {
|
||||||
if (e.has(i))
|
if (e.has(i))
|
||||||
return e.get(i);
|
return e.get(i);
|
||||||
let f = { connected: [], disconnected: [] };
|
let s = {
|
||||||
return e.set(i, f), f;
|
connected: /* @__PURE__ */ new WeakSet(),
|
||||||
|
length_c: 0,
|
||||||
|
disconnected: /* @__PURE__ */ new WeakSet(),
|
||||||
|
length_d: 0
|
||||||
|
};
|
||||||
|
return e.set(i, s), s;
|
||||||
}
|
}
|
||||||
function c() {
|
function c() {
|
||||||
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
|
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
|
||||||
}
|
}
|
||||||
function p() {
|
function l() {
|
||||||
!t || e.size || (t = !1, n.disconnect());
|
!t || e.size || (t = !1, n.disconnect());
|
||||||
}
|
}
|
||||||
function s() {
|
function u() {
|
||||||
return new Promise(function(i) {
|
return new Promise(function(i) {
|
||||||
(requestIdleCallback || requestAnimationFrame)(i);
|
(requestIdleCallback || requestAnimationFrame)(i);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async function a(i) {
|
async function a(i) {
|
||||||
e.size > 30 && await s();
|
e.size > 30 && await u();
|
||||||
let f = [];
|
let s = [];
|
||||||
if (!(i instanceof Node))
|
if (!(i instanceof Node))
|
||||||
return f;
|
return s;
|
||||||
for (let u of e.keys())
|
for (let f of e.keys())
|
||||||
u === i || !(u instanceof Node) || i.contains(u) && f.push(u);
|
f === i || !(f instanceof Node) || i.contains(f) && s.push(f);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
function v(i, s) {
|
||||||
|
let f = !1;
|
||||||
|
for (let p of i) {
|
||||||
|
if (s && a(p).then(v), !e.has(p))
|
||||||
|
continue;
|
||||||
|
let E = e.get(p);
|
||||||
|
E.length_c && (p.dispatchEvent(new Event("dde:connected")), E.connected = /* @__PURE__ */ new WeakSet(), E.length_c = 0, E.length_d || e.delete(p), f = !0);
|
||||||
|
}
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
function b(i, f) {
|
function x(i, s) {
|
||||||
for (let u of i) {
|
let f = !1;
|
||||||
if (f && a(u).then(b), !e.has(u))
|
for (let p of i)
|
||||||
continue;
|
s && a(p).then(x), !(!e.has(p) || !e.get(p).length_d) && (p.dispatchEvent(new Event("dde:disconnected")), e.delete(p), f = !0);
|
||||||
let l = e.get(u);
|
return f;
|
||||||
return l.connected.forEach((A) => A(u)), l.connected.length = 0, l.disconnected.length || e.delete(u), !0;
|
|
||||||
}
|
|
||||||
return !1;
|
|
||||||
}
|
|
||||||
function v(i, f) {
|
|
||||||
for (let u of i) {
|
|
||||||
if (f && a(u).then(v), !e.has(u))
|
|
||||||
continue;
|
|
||||||
let l = e.get(u);
|
|
||||||
return l.disconnected.forEach((A) => A(u)), l.connected.length = 0, l.disconnected.length = 0, e.delete(u), !0;
|
|
||||||
}
|
|
||||||
return !1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,7 +276,7 @@
|
|||||||
|
|
||||||
// src/signals-lib.js
|
// src/signals-lib.js
|
||||||
var d = Symbol.for("Signal");
|
var d = Symbol.for("Signal");
|
||||||
function y(e) {
|
function _(e) {
|
||||||
try {
|
try {
|
||||||
return Reflect.has(e, d);
|
return Reflect.has(e, d);
|
||||||
} catch {
|
} catch {
|
||||||
@ -272,10 +287,10 @@
|
|||||||
function g(e, t) {
|
function g(e, t) {
|
||||||
if (typeof e != "function")
|
if (typeof e != "function")
|
||||||
return U(e, t);
|
return U(e, t);
|
||||||
if (y(e))
|
if (_(e))
|
||||||
return e;
|
return e;
|
||||||
let n = U(""), r = () => n(e());
|
let n = U(""), r = () => n(e());
|
||||||
return h.set(r, /* @__PURE__ */ new Set([n])), k(r), n;
|
return h.set(r, /* @__PURE__ */ new Set([n])), K(r), n;
|
||||||
}
|
}
|
||||||
g.action = function(e, t, ...n) {
|
g.action = function(e, t, ...n) {
|
||||||
let r = e[d], { actions: o } = r;
|
let r = e[d], { actions: o } = r;
|
||||||
@ -290,7 +305,7 @@
|
|||||||
if (!(o && o.aborted)) {
|
if (!(o && o.aborted)) {
|
||||||
if (Array.isArray(t))
|
if (Array.isArray(t))
|
||||||
return t.forEach((c) => e(c, n, r));
|
return t.forEach((c) => e(c, n, r));
|
||||||
D(t, n), o && o.addEventListener("abort", () => q(t, n));
|
N(t, n), o && o.addEventListener("abort", () => k(t, n));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
g.symbols = {
|
g.symbols = {
|
||||||
@ -315,26 +330,26 @@
|
|||||||
g.el = function(e, t) {
|
g.el = function(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 c = (p) => {
|
let c = (l) => {
|
||||||
if (!n.parentNode || !r.parentNode)
|
if (!n.parentNode || !r.parentNode)
|
||||||
return q(e, c);
|
return k(e, c);
|
||||||
let s = t(p);
|
let u = t(l);
|
||||||
Array.isArray(s) || (s = [s]);
|
Array.isArray(u) || (u = [u]);
|
||||||
let a = n;
|
let a = n;
|
||||||
for (; (a = n.nextSibling) !== r; )
|
for (; (a = n.nextSibling) !== r; )
|
||||||
a.remove();
|
a.remove();
|
||||||
n.after(...s);
|
n.after(...u);
|
||||||
};
|
};
|
||||||
return D(e, c), c(e()), o;
|
return N(e, c), c(e()), o;
|
||||||
};
|
};
|
||||||
var $ = {
|
var $ = {
|
||||||
isSignal: y,
|
isSignal: _,
|
||||||
processReactiveAttribute(e, t, n, r) {
|
processReactiveAttribute(e, t, n, r) {
|
||||||
return y(n) ? (D(n, (o) => r([t, o])), n()) : n;
|
return _(n) ? (N(n, (o) => r([t, o])), n()) : n;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function U(e, t) {
|
function U(e, t) {
|
||||||
let n = (...r) => r.length ? X(n, r[0]) : Q(n);
|
let n = (...r) => r.length ? Y(n, r[0]) : X(n);
|
||||||
return Z(n, e, t);
|
return Z(n, e, t);
|
||||||
}
|
}
|
||||||
var V = Object.assign(/* @__PURE__ */ Object.create(null), {
|
var V = Object.assign(/* @__PURE__ */ Object.create(null), {
|
||||||
@ -343,59 +358,59 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
function Z(e, t, n) {
|
function Z(e, t, n) {
|
||||||
return N(n) !== "[object Object]" && (n = {}), e[d] = {
|
return D(n) !== "[object Object]" && (n = {}), e[d] = {
|
||||||
value: t,
|
value: t,
|
||||||
actions: n,
|
actions: n,
|
||||||
listeners: /* @__PURE__ */ new Set()
|
listeners: /* @__PURE__ */ new Set()
|
||||||
}, e.toJSON = () => e(), Object.setPrototypeOf(e[d], V), e;
|
}, e.toJSON = () => e(), Object.setPrototypeOf(e[d], V), e;
|
||||||
}
|
}
|
||||||
var R = [];
|
var R = [];
|
||||||
function k(e) {
|
function K(e) {
|
||||||
let t = function() {
|
let t = function() {
|
||||||
R.push(t), e(), R.pop();
|
R.push(t), e(), R.pop();
|
||||||
};
|
};
|
||||||
h.has(e) && (h.set(t, h.get(e)), h.delete(e)), t();
|
h.has(e) && (h.set(t, h.get(e)), h.delete(e)), t();
|
||||||
}
|
}
|
||||||
function K() {
|
function Q() {
|
||||||
return R[R.length - 1];
|
return R[R.length - 1];
|
||||||
}
|
}
|
||||||
function Q(e) {
|
function X(e) {
|
||||||
if (!e[d])
|
if (!e[d])
|
||||||
return;
|
return;
|
||||||
let { value: t, listeners: n } = e[d], r = K();
|
let { value: t, listeners: n } = e[d], r = Q();
|
||||||
return r && n.add(r), h.has(r) && h.get(r).add(e), t;
|
return r && n.add(r), h.has(r) && h.get(r).add(e), t;
|
||||||
}
|
}
|
||||||
function X(e, t) {
|
function Y(e, t) {
|
||||||
if (!e[d])
|
if (!e[d])
|
||||||
return;
|
return;
|
||||||
let n = e[d];
|
let n = e[d];
|
||||||
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 D(e, t) {
|
function N(e, t) {
|
||||||
if (e[d])
|
if (e[d])
|
||||||
return e[d].listeners.add(t);
|
return e[d].listeners.add(t);
|
||||||
}
|
}
|
||||||
function q(e, t) {
|
function k(e, t) {
|
||||||
if (e[d])
|
if (e[d])
|
||||||
return e[d].listeners.delete(t);
|
return e[d].listeners.delete(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
// signals.js
|
// signals.js
|
||||||
C($);
|
A($);
|
||||||
|
|
||||||
globalThis.dde= {
|
globalThis.dde= {
|
||||||
S: g,
|
S: g,
|
||||||
assign: S,
|
assign: y,
|
||||||
classListDeclarative: B,
|
classListDeclarative: B,
|
||||||
createElement: ce,
|
createElement: ie,
|
||||||
dispatchEvent: ae,
|
dispatchEvent: de,
|
||||||
el: ce,
|
el: ie,
|
||||||
empty: se,
|
empty: fe,
|
||||||
isSignal: y,
|
isSignal: _,
|
||||||
namespace: oe,
|
|
||||||
on: T,
|
on: T,
|
||||||
registerReactivity: C
|
registerReactivity: A,
|
||||||
|
scope: ce
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
275
dist/dde.js
vendored
275
dist/dde.js
vendored
@ -1,26 +1,26 @@
|
|||||||
//deka-dom-el library is available via global namespace `dde`
|
//deka-dom-el library is available via global namespace `dde`
|
||||||
(()=> {
|
(()=> {
|
||||||
// src/signals-common.js
|
// src/signals-common.js
|
||||||
var g = {
|
var E = {
|
||||||
isSignal(e) {
|
isSignal(e) {
|
||||||
return !1;
|
return !1;
|
||||||
},
|
},
|
||||||
processReactiveAttribute(e, t, n, r) {
|
processReactiveAttribute(e, t, r, n) {
|
||||||
return n;
|
return r;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function y(e, t = !0) {
|
function N(e, t = !0) {
|
||||||
return t ? Object.assign(g, e) : (Object.setPrototypeOf(e, g), e);
|
return t ? Object.assign(E, e) : (Object.setPrototypeOf(e, E), e);
|
||||||
}
|
}
|
||||||
function v(e) {
|
function m(e) {
|
||||||
return g.isPrototypeOf(e) && e !== g ? e : g;
|
return E.isPrototypeOf(e) && e !== E ? e : E;
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/helpers.js
|
// src/helpers.js
|
||||||
function p(e) {
|
function p(e) {
|
||||||
return typeof e > "u";
|
return typeof e > "u";
|
||||||
}
|
}
|
||||||
function w(e, t) {
|
function _(e, t) {
|
||||||
if (!e || !(e instanceof AbortSignal))
|
if (!e || !(e instanceof AbortSignal))
|
||||||
return !0;
|
return !0;
|
||||||
if (!e.aborted)
|
if (!e.aborted)
|
||||||
@ -30,9 +30,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// src/dom-common.js
|
// src/dom-common.js
|
||||||
var R = { setDeleteAttr: P };
|
var O = { setDeleteAttr: P };
|
||||||
function P(e, t, n) {
|
function P(e, t, r) {
|
||||||
if (Reflect.set(e, t, n), !!p(n)) {
|
if (Reflect.set(e, t, r), !!p(r)) {
|
||||||
if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined")
|
if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined")
|
||||||
return e.removeAttribute(t);
|
return e.removeAttribute(t);
|
||||||
if (Reflect.get(e, t) === "undefined")
|
if (Reflect.get(e, t) === "undefined")
|
||||||
@ -41,230 +41,245 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// src/dom.js
|
// src/dom.js
|
||||||
var x = "html";
|
var h = "html", S = {
|
||||||
function H(e) {
|
elNamespace(e) {
|
||||||
return x = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
|
return h = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
|
||||||
append(...t) {
|
append(...t) {
|
||||||
return x = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t);
|
return h = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
get namespace() {
|
||||||
|
return h;
|
||||||
|
},
|
||||||
|
set namespace(e) {
|
||||||
|
return h = e;
|
||||||
}
|
}
|
||||||
function I(e, t, ...n) {
|
}, H = Object.assign((e) => e ? e(document.body) : document.body, S);
|
||||||
let r = this, u = v(this), i;
|
function I(e, t, ...r) {
|
||||||
|
let n = this, u = m(this), i;
|
||||||
switch ((Object(t) !== t || u.isSignal(t)) && (t = { textContent: t }), !0) {
|
switch ((Object(t) !== t || u.isSignal(t)) && (t = { textContent: t }), !0) {
|
||||||
case typeof e == "function": {
|
case typeof e == "function": {
|
||||||
i = e(t || void 0, (f) => f ? (n.unshift(f), void 0) : i);
|
let a = Object.assign((f) => f ? (r.unshift(f), void 0) : i, S);
|
||||||
|
i = e(t || void 0, a), h = "html";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case e === "#text":
|
case e === "#text":
|
||||||
i = m.call(r, document.createTextNode(""), t);
|
i = w.call(n, document.createTextNode(""), t);
|
||||||
break;
|
break;
|
||||||
case e === "<>":
|
case e === "<>":
|
||||||
i = m.call(r, document.createDocumentFragment(), t);
|
i = w.call(n, document.createDocumentFragment(), t);
|
||||||
break;
|
break;
|
||||||
case x !== "html":
|
case h !== "html":
|
||||||
i = m.call(r, document.createElementNS(x, e), t);
|
i = w.call(n, document.createElementNS(h, e), t);
|
||||||
break;
|
break;
|
||||||
case !i:
|
case !i:
|
||||||
i = m.call(r, document.createElement(e), t);
|
i = w.call(n, document.createElement(e), t);
|
||||||
}
|
}
|
||||||
return n.forEach((l) => l(i)), i;
|
return r.forEach((a) => a(i)), i;
|
||||||
}
|
}
|
||||||
var { setDeleteAttr: C } = R;
|
var { setDeleteAttr: R } = O;
|
||||||
function m(e, ...t) {
|
function w(e, ...t) {
|
||||||
let n = this, r = v(this);
|
let r = this, n = m(this);
|
||||||
if (!t.length)
|
if (!t.length)
|
||||||
return e;
|
return e;
|
||||||
let i = (e instanceof SVGElement ? M : F).bind(null, e, "Attribute");
|
let i = (e instanceof SVGElement ? T : M).bind(null, e, "Attribute");
|
||||||
return Object.entries(Object.assign({}, ...t)).forEach(function l([f, d]) {
|
return Object.entries(Object.assign({}, ...t)).forEach(function a([f, d]) {
|
||||||
d = r.processReactiveAttribute(e, f, d, l);
|
d = n.processReactiveAttribute(e, f, d, a);
|
||||||
let [h] = f;
|
let [g] = f;
|
||||||
if (h === "=")
|
if (g === "=")
|
||||||
return i(f.slice(1), d);
|
return i(f.slice(1), d);
|
||||||
if (h === ".")
|
if (g === ".")
|
||||||
return D(e, f.slice(1), d);
|
return C(e, f.slice(1), d);
|
||||||
if (/(aria|data)([A-Z])/.test(f))
|
if (/(aria|data)([A-Z])/.test(f))
|
||||||
return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(f, d);
|
return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(f, d);
|
||||||
switch (f === "className" && (f = "class"), f) {
|
switch (f === "className" && (f = "class"), f) {
|
||||||
case "xlink:href":
|
case "xlink:href":
|
||||||
return i(f, d, "http://www.w3.org/1999/xlink");
|
return i(f, d, "http://www.w3.org/1999/xlink");
|
||||||
case "textContent":
|
case "textContent":
|
||||||
return C(e, f, d);
|
return R(e, f, d);
|
||||||
case "style":
|
case "style":
|
||||||
if (typeof d != "object")
|
if (typeof d != "object")
|
||||||
break;
|
break;
|
||||||
case "dataset":
|
case "dataset":
|
||||||
return O(r, d, D.bind(null, e[f]));
|
return A(n, d, C.bind(null, e[f]));
|
||||||
case "ariaset":
|
case "ariaset":
|
||||||
return O(r, d, (E, o) => i("aria-" + E, o));
|
return A(n, d, (b, c) => i("aria-" + b, c));
|
||||||
case "classList":
|
case "classList":
|
||||||
return _.call(n, e, d);
|
return j.call(r, e, d);
|
||||||
}
|
}
|
||||||
return j(e, f) ? C(e, f, d) : i(f, d);
|
return F(e, f) ? R(e, f, d) : i(f, d);
|
||||||
}), e;
|
}), e;
|
||||||
}
|
}
|
||||||
function _(e, t) {
|
function j(e, t) {
|
||||||
let n = v(this);
|
let r = m(this);
|
||||||
return O(
|
return A(
|
||||||
n,
|
r,
|
||||||
t,
|
t,
|
||||||
(r, u) => e.classList.toggle(r, u === -1 ? void 0 : !!u)
|
(n, u) => e.classList.toggle(n, u === -1 ? void 0 : !!u)
|
||||||
), e;
|
), e;
|
||||||
}
|
}
|
||||||
function Z(e) {
|
function Z(e) {
|
||||||
return Array.from(e.children).forEach((t) => t.remove()), e;
|
return Array.from(e.children).forEach((t) => t.remove()), e;
|
||||||
}
|
}
|
||||||
function j(e, t) {
|
function F(e, t) {
|
||||||
if (!Reflect.has(e, t))
|
if (!Reflect.has(e, t))
|
||||||
return !1;
|
return !1;
|
||||||
let n = L(e, t);
|
let r = y(e, t);
|
||||||
return !p(n.set);
|
return !p(r.set);
|
||||||
}
|
}
|
||||||
function L(e, t) {
|
function y(e, t) {
|
||||||
if (e = Object.getPrototypeOf(e), !e)
|
if (e = Object.getPrototypeOf(e), !e)
|
||||||
return {};
|
return {};
|
||||||
let n = Object.getOwnPropertyDescriptor(e, t);
|
let r = Object.getOwnPropertyDescriptor(e, t);
|
||||||
return n || L(e, t);
|
return r || y(e, t);
|
||||||
}
|
}
|
||||||
function O(e, t, n) {
|
function A(e, t, r) {
|
||||||
if (!(typeof t != "object" || t === null))
|
if (!(typeof t != "object" || t === null))
|
||||||
return Object.entries(t).forEach(function([u, i]) {
|
return Object.entries(t).forEach(function([u, i]) {
|
||||||
u && (i = e.processReactiveAttribute(t, u, i, (l) => n(...l)), n(u, i));
|
u && (i = e.processReactiveAttribute(t, u, i, (a) => r(...a)), r(u, i));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function S(e) {
|
function D(e) {
|
||||||
return Array.isArray(e) ? e.filter(Boolean).join(" ") : e;
|
return Array.isArray(e) ? e.filter(Boolean).join(" ") : e;
|
||||||
}
|
}
|
||||||
function F(e, t, n, r) {
|
function M(e, t, r, n) {
|
||||||
return e[(p(r) ? "remove" : "set") + t](n, S(r));
|
return e[(p(n) ? "remove" : "set") + t](r, D(n));
|
||||||
}
|
}
|
||||||
function M(e, t, n, r, u = null) {
|
function T(e, t, r, n, u = null) {
|
||||||
return e[(p(r) ? "remove" : "set") + t + "NS"](u, n, S(r));
|
return e[(p(n) ? "remove" : "set") + t + "NS"](u, r, D(n));
|
||||||
}
|
}
|
||||||
function D(e, t, n) {
|
function C(e, t, r) {
|
||||||
if (Reflect.set(e, t, n), !!p(n))
|
if (Reflect.set(e, t, r), !!p(r))
|
||||||
return Reflect.deleteProperty(e, t);
|
return Reflect.deleteProperty(e, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/events.js
|
// src/events.js
|
||||||
function J(e, t, ...n) {
|
function K(e, t, ...r) {
|
||||||
let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t);
|
let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t);
|
||||||
return e.dispatchEvent(r);
|
return e.dispatchEvent(n);
|
||||||
}
|
}
|
||||||
function N(e, t, n) {
|
function L(e, t, r) {
|
||||||
return function(u) {
|
return function(u) {
|
||||||
return u.addEventListener(e, t, n), u;
|
return u.addEventListener(e, t, r), u;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
var b = T();
|
var x = U();
|
||||||
N.connected = function(e, t) {
|
L.connected = function(e, t) {
|
||||||
return function(r) {
|
return typeof t != "object" && (t = {}), t.once = !0, function(n) {
|
||||||
return typeof r.connectedCallback == "function" ? (r.addEventListener("dde:connected", e, t), r) : (w(t && t.signal, () => b.offConnected(r, e)) && (r.isConnected ? e(new Event("dde:connected")) : b.onConnected(r, e)), r);
|
return n.addEventListener("dde:connected", e, t), typeof n.connectedCallback == "function" ? n : n.isConnected ? (n.dispatchEvent(new Event("dde:connected")), n) : (_(t.signal, () => x.offConnected(n, e)) && x.onConnected(n, e), n);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
N.disconnected = function(e, t) {
|
L.disconnected = function(e, t) {
|
||||||
return function(r) {
|
return typeof t != "object" && (t = {}), t.once = !0, function(n) {
|
||||||
return typeof r.disconnectedCallback == "function" ? (r.addEventListener("dde:disconnected", e, t), r) : (w(t && t.signal, () => b.offDisconnected(r, e)) && b.onDisconnected(r, e), r);
|
return n.addEventListener("dde:disconnected", e, t), typeof n.disconnectedCallback == "function" || _(t.signal, () => x.offDisconnected(n, e)) && x.onDisconnected(n, e), n;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
function T() {
|
function U() {
|
||||||
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(o) {
|
let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(c) {
|
||||||
for (let c of o)
|
for (let o of c)
|
||||||
if (c.type === "childList") {
|
if (o.type === "childList") {
|
||||||
if (h(c.addedNodes, !0)) {
|
if (g(o.addedNodes, !0)) {
|
||||||
l();
|
a();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
E(c.removedNodes, !0) && l();
|
b(o.removedNodes, !0) && a();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
onConnected(o, c) {
|
onConnected(c, o) {
|
||||||
i(), u(o).connected.push(c);
|
i();
|
||||||
|
let s = u(c);
|
||||||
|
s.connected.has(o) || (s.connected.add(o), s.length_c += 1);
|
||||||
},
|
},
|
||||||
offConnected(o, c) {
|
offConnected(c, o) {
|
||||||
if (!e.has(o))
|
if (!e.has(c))
|
||||||
return;
|
return;
|
||||||
let s = e.get(o), a = s.connected;
|
let s = e.get(c);
|
||||||
a.splice(a.indexOf(c), 1), r(o, s);
|
s.connected.has(o) && (s.connected.delete(o), s.length_c -= 1, n(c, s));
|
||||||
},
|
},
|
||||||
onDisconnected(o, c) {
|
onDisconnected(c, o) {
|
||||||
i(), u(o).disconnected.push(c);
|
i();
|
||||||
|
let s = u(c);
|
||||||
|
s.disconnected.has(o) || (s.disconnected.add(o), s.length_d += 1);
|
||||||
},
|
},
|
||||||
offDisconnected(o, c) {
|
offDisconnected(c, o) {
|
||||||
if (!e.has(o))
|
if (!e.has(c))
|
||||||
return;
|
return;
|
||||||
let s = e.get(o), a = s.disconnected;
|
let s = e.get(c);
|
||||||
a.splice(a.indexOf(c), 1), r(o, s);
|
s.disconnected.has(o) && (s.disconnected.delete(o), s.length_d -= 1, n(c, s));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function r(o, c) {
|
function n(c, o) {
|
||||||
c.connected.length || c.disconnected.length || (e.delete(o), l());
|
o.length_c || o.length_d || (e.delete(c), a());
|
||||||
}
|
}
|
||||||
function u(o) {
|
function u(c) {
|
||||||
if (e.has(o))
|
if (e.has(c))
|
||||||
return e.get(o);
|
return e.get(c);
|
||||||
let c = { connected: [], disconnected: [] };
|
let o = {
|
||||||
return e.set(o, c), c;
|
connected: /* @__PURE__ */ new WeakSet(),
|
||||||
|
length_c: 0,
|
||||||
|
disconnected: /* @__PURE__ */ new WeakSet(),
|
||||||
|
length_d: 0
|
||||||
|
};
|
||||||
|
return e.set(c, o), o;
|
||||||
}
|
}
|
||||||
function i() {
|
function i() {
|
||||||
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
|
t || (t = !0, r.observe(document.body, { childList: !0, subtree: !0 }));
|
||||||
}
|
}
|
||||||
function l() {
|
function a() {
|
||||||
!t || e.size || (t = !1, n.disconnect());
|
!t || e.size || (t = !1, r.disconnect());
|
||||||
}
|
}
|
||||||
function f() {
|
function f() {
|
||||||
return new Promise(function(o) {
|
return new Promise(function(c) {
|
||||||
(requestIdleCallback || requestAnimationFrame)(o);
|
(requestIdleCallback || requestAnimationFrame)(c);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async function d(o) {
|
async function d(c) {
|
||||||
e.size > 30 && await f();
|
e.size > 30 && await f();
|
||||||
let c = [];
|
let o = [];
|
||||||
if (!(o instanceof Node))
|
if (!(c instanceof Node))
|
||||||
return c;
|
return o;
|
||||||
for (let s of e.keys())
|
for (let s of e.keys())
|
||||||
s === o || !(s instanceof Node) || o.contains(s) && c.push(s);
|
s === c || !(s instanceof Node) || c.contains(s) && o.push(s);
|
||||||
return c;
|
return o;
|
||||||
}
|
}
|
||||||
function h(o, c) {
|
function g(c, o) {
|
||||||
for (let s of o) {
|
let s = !1;
|
||||||
if (c && d(s).then(h), !e.has(s))
|
for (let l of c) {
|
||||||
|
if (o && d(l).then(g), !e.has(l))
|
||||||
continue;
|
continue;
|
||||||
let a = e.get(s);
|
let v = e.get(l);
|
||||||
return a.connected.forEach((A) => A(s)), a.connected.length = 0, a.disconnected.length || e.delete(s), !0;
|
v.length_c && (l.dispatchEvent(new Event("dde:connected")), v.connected = /* @__PURE__ */ new WeakSet(), v.length_c = 0, v.length_d || e.delete(l), s = !0);
|
||||||
}
|
}
|
||||||
return !1;
|
return s;
|
||||||
}
|
}
|
||||||
function E(o, c) {
|
function b(c, o) {
|
||||||
for (let s of o) {
|
let s = !1;
|
||||||
if (c && d(s).then(E), !e.has(s))
|
for (let l of c)
|
||||||
continue;
|
o && d(l).then(b), !(!e.has(l) || !e.get(l).length_d) && (l.dispatchEvent(new Event("dde:disconnected")), e.delete(l), s = !0);
|
||||||
let a = e.get(s);
|
return s;
|
||||||
return a.disconnected.forEach((A) => A(s)), a.connected.length = 0, a.disconnected.length = 0, e.delete(s), !0;
|
|
||||||
}
|
|
||||||
return !1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// index.js
|
// index.js
|
||||||
[HTMLElement, SVGElement, DocumentFragment].forEach((e) => {
|
[HTMLElement, SVGElement, 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: m,
|
assign: w,
|
||||||
classListDeclarative: _,
|
classListDeclarative: j,
|
||||||
createElement: I,
|
createElement: I,
|
||||||
dispatchEvent: J,
|
dispatchEvent: K,
|
||||||
el: I,
|
el: I,
|
||||||
empty: Z,
|
empty: Z,
|
||||||
namespace: H,
|
on: L,
|
||||||
on: N,
|
registerReactivity: N,
|
||||||
registerReactivity: y
|
scope: H
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
263
dist/esm-with-signals.js
vendored
263
dist/esm-with-signals.js
vendored
@ -1,5 +1,5 @@
|
|||||||
// src/signals-common.js
|
// src/signals-common.js
|
||||||
var E = {
|
var w = {
|
||||||
isSignal(e) {
|
isSignal(e) {
|
||||||
return !1;
|
return !1;
|
||||||
},
|
},
|
||||||
@ -7,22 +7,22 @@ var E = {
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function C(e, t = !0) {
|
function A(e, t = !0) {
|
||||||
return t ? Object.assign(E, e) : (Object.setPrototypeOf(e, E), e);
|
return t ? Object.assign(w, e) : (Object.setPrototypeOf(e, w), e);
|
||||||
}
|
}
|
||||||
function x(e) {
|
function S(e) {
|
||||||
return E.isPrototypeOf(e) && e !== E ? e : E;
|
return w.isPrototypeOf(e) && e !== w ? e : w;
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/helpers.js
|
// src/helpers.js
|
||||||
function m(e) {
|
function m(e) {
|
||||||
return typeof e > "u";
|
return typeof e > "u";
|
||||||
}
|
}
|
||||||
function N(e) {
|
function D(e) {
|
||||||
let t = typeof e;
|
let t = typeof e;
|
||||||
return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e);
|
return t !== "object" ? t : e === null ? "null" : Object.prototype.toString.call(e);
|
||||||
}
|
}
|
||||||
function L(e, t) {
|
function C(e, t) {
|
||||||
if (!e || !(e instanceof AbortSignal))
|
if (!e || !(e instanceof AbortSignal))
|
||||||
return !0;
|
return !0;
|
||||||
if (!e.aborted)
|
if (!e.aborted)
|
||||||
@ -32,8 +32,8 @@ function L(e, t) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// src/dom-common.js
|
// src/dom-common.js
|
||||||
var P = { setDeleteAttr: W };
|
var P = { setDeleteAttr: q };
|
||||||
function W(e, t, n) {
|
function q(e, t, n) {
|
||||||
if (Reflect.set(e, t, n), !!m(n)) {
|
if (Reflect.set(e, t, n), !!m(n)) {
|
||||||
if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined")
|
if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined")
|
||||||
return e.removeAttribute(t);
|
return e.removeAttribute(t);
|
||||||
@ -43,77 +43,85 @@ function W(e, t, n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// src/dom.js
|
// src/dom.js
|
||||||
var w = "html";
|
var b = "html", F = {
|
||||||
function oe(e) {
|
elNamespace(e) {
|
||||||
return w = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
|
return b = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
|
||||||
append(...t) {
|
append(...t) {
|
||||||
return w = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t);
|
return b = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
function ce(e, t, ...n) {
|
get namespace() {
|
||||||
let r = this, o = x(this), c;
|
return b;
|
||||||
|
},
|
||||||
|
set namespace(e) {
|
||||||
|
return b = e;
|
||||||
|
}
|
||||||
|
}, ce = Object.assign((e) => e ? e(document.body) : document.body, F);
|
||||||
|
function ie(e, t, ...n) {
|
||||||
|
let r = this, o = S(this), c;
|
||||||
switch ((Object(t) !== t || o.isSignal(t)) && (t = { textContent: t }), !0) {
|
switch ((Object(t) !== t || o.isSignal(t)) && (t = { textContent: t }), !0) {
|
||||||
case typeof e == "function": {
|
case typeof e == "function": {
|
||||||
c = e(t || void 0, (s) => s ? (n.unshift(s), void 0) : c);
|
let l = Object.assign((u) => u ? (n.unshift(u), void 0) : c, F);
|
||||||
|
c = e(t || void 0, l), b = "html";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case e === "#text":
|
case e === "#text":
|
||||||
c = S.call(r, document.createTextNode(""), t);
|
c = y.call(r, document.createTextNode(""), t);
|
||||||
break;
|
break;
|
||||||
case e === "<>":
|
case e === "<>":
|
||||||
c = S.call(r, document.createDocumentFragment(), t);
|
c = y.call(r, document.createDocumentFragment(), t);
|
||||||
break;
|
break;
|
||||||
case w !== "html":
|
case b !== "html":
|
||||||
c = S.call(r, document.createElementNS(w, e), t);
|
c = y.call(r, document.createElementNS(b, e), t);
|
||||||
break;
|
break;
|
||||||
case !c:
|
case !c:
|
||||||
c = S.call(r, document.createElement(e), t);
|
c = y.call(r, document.createElement(e), t);
|
||||||
}
|
}
|
||||||
return n.forEach((p) => p(c)), c;
|
return n.forEach((l) => l(c)), c;
|
||||||
}
|
}
|
||||||
var { setDeleteAttr: j } = P;
|
var { setDeleteAttr: j } = P;
|
||||||
function S(e, ...t) {
|
function y(e, ...t) {
|
||||||
let n = this, r = x(this);
|
let n = this, r = S(this);
|
||||||
if (!t.length)
|
if (!t.length)
|
||||||
return e;
|
return e;
|
||||||
let c = (e instanceof SVGElement ? I : H).bind(null, e, "Attribute");
|
let c = (e instanceof SVGElement ? I : H).bind(null, e, "Attribute");
|
||||||
return Object.entries(Object.assign({}, ...t)).forEach(function p([s, a]) {
|
return Object.entries(Object.assign({}, ...t)).forEach(function l([u, a]) {
|
||||||
a = r.processReactiveAttribute(e, s, a, p);
|
a = r.processReactiveAttribute(e, u, a, l);
|
||||||
let [b] = s;
|
let [v] = u;
|
||||||
if (b === "=")
|
if (v === "=")
|
||||||
return c(s.slice(1), a);
|
return c(u.slice(1), a);
|
||||||
if (b === ".")
|
if (v === ".")
|
||||||
return F(e, s.slice(1), a);
|
return W(e, u.slice(1), a);
|
||||||
if (/(aria|data)([A-Z])/.test(s))
|
if (/(aria|data)([A-Z])/.test(u))
|
||||||
return s = s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), c(s, a);
|
return u = u.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), c(u, a);
|
||||||
switch (s === "className" && (s = "class"), s) {
|
switch (u === "className" && (u = "class"), u) {
|
||||||
case "xlink:href":
|
case "xlink:href":
|
||||||
return c(s, a, "http://www.w3.org/1999/xlink");
|
return c(u, a, "http://www.w3.org/1999/xlink");
|
||||||
case "textContent":
|
case "textContent":
|
||||||
return j(e, s, a);
|
return j(e, u, a);
|
||||||
case "style":
|
case "style":
|
||||||
if (typeof a != "object")
|
if (typeof a != "object")
|
||||||
break;
|
break;
|
||||||
case "dataset":
|
case "dataset":
|
||||||
return _(r, a, F.bind(null, e[s]));
|
return L(r, a, W.bind(null, e[u]));
|
||||||
case "ariaset":
|
case "ariaset":
|
||||||
return _(r, a, (v, i) => c("aria-" + v, i));
|
return L(r, a, (x, i) => c("aria-" + x, i));
|
||||||
case "classList":
|
case "classList":
|
||||||
return B.call(n, e, a);
|
return B.call(n, e, a);
|
||||||
}
|
}
|
||||||
return G(e, s) ? j(e, s, a) : c(s, a);
|
return G(e, u) ? j(e, u, a) : c(u, a);
|
||||||
}), e;
|
}), e;
|
||||||
}
|
}
|
||||||
function B(e, t) {
|
function B(e, t) {
|
||||||
let n = x(this);
|
let n = S(this);
|
||||||
return _(
|
return L(
|
||||||
n,
|
n,
|
||||||
t,
|
t,
|
||||||
(r, o) => e.classList.toggle(r, o === -1 ? void 0 : !!o)
|
(r, o) => e.classList.toggle(r, o === -1 ? void 0 : !!o)
|
||||||
), e;
|
), e;
|
||||||
}
|
}
|
||||||
function se(e) {
|
function fe(e) {
|
||||||
return Array.from(e.children).forEach((t) => t.remove()), e;
|
return Array.from(e.children).forEach((t) => t.remove()), e;
|
||||||
}
|
}
|
||||||
function G(e, t) {
|
function G(e, t) {
|
||||||
@ -128,10 +136,10 @@ function M(e, t) {
|
|||||||
let n = Object.getOwnPropertyDescriptor(e, t);
|
let n = Object.getOwnPropertyDescriptor(e, t);
|
||||||
return n || M(e, t);
|
return n || M(e, t);
|
||||||
}
|
}
|
||||||
function _(e, t, n) {
|
function L(e, t, n) {
|
||||||
if (!(typeof t != "object" || t === null))
|
if (!(typeof t != "object" || t === null))
|
||||||
return Object.entries(t).forEach(function([o, c]) {
|
return Object.entries(t).forEach(function([o, c]) {
|
||||||
o && (c = e.processReactiveAttribute(t, o, c, (p) => n(...p)), n(o, c));
|
o && (c = e.processReactiveAttribute(t, o, c, (l) => n(...l)), n(o, c));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function z(e) {
|
function z(e) {
|
||||||
@ -143,13 +151,13 @@ function H(e, t, n, r) {
|
|||||||
function I(e, t, n, r, o = null) {
|
function I(e, t, n, r, o = null) {
|
||||||
return e[(m(r) ? "remove" : "set") + t + "NS"](o, n, z(r));
|
return e[(m(r) ? "remove" : "set") + t + "NS"](o, n, z(r));
|
||||||
}
|
}
|
||||||
function F(e, t, n) {
|
function W(e, t, n) {
|
||||||
if (Reflect.set(e, t, n), !!m(n))
|
if (Reflect.set(e, t, n), !!m(n))
|
||||||
return Reflect.deleteProperty(e, t);
|
return Reflect.deleteProperty(e, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/events.js
|
// src/events.js
|
||||||
function ae(e, t, ...n) {
|
function de(e, t, ...n) {
|
||||||
let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t);
|
let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t);
|
||||||
return e.dispatchEvent(r);
|
return e.dispatchEvent(r);
|
||||||
}
|
}
|
||||||
@ -160,92 +168,99 @@ function T(e, t, n) {
|
|||||||
}
|
}
|
||||||
var O = J();
|
var O = J();
|
||||||
T.connected = function(e, t) {
|
T.connected = function(e, t) {
|
||||||
return function(r) {
|
return typeof t != "object" && (t = {}), t.once = !0, function(r) {
|
||||||
return typeof r.connectedCallback == "function" ? (r.addEventListener("dde:connected", e, t), r) : (L(t && t.signal, () => O.offConnected(r, e)) && (r.isConnected ? e(new Event("dde:connected")) : O.onConnected(r, e)), r);
|
return r.addEventListener("dde:connected", e, t), typeof r.connectedCallback == "function" ? r : r.isConnected ? (r.dispatchEvent(new Event("dde:connected")), r) : (C(t.signal, () => O.offConnected(r, e)) && O.onConnected(r, e), r);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
T.disconnected = function(e, t) {
|
T.disconnected = function(e, t) {
|
||||||
return function(r) {
|
return typeof t != "object" && (t = {}), t.once = !0, function(r) {
|
||||||
return typeof r.disconnectedCallback == "function" ? (r.addEventListener("dde:disconnected", e, t), r) : (L(t && t.signal, () => O.offDisconnected(r, e)) && O.onDisconnected(r, e), r);
|
return r.addEventListener("dde:disconnected", e, t), typeof r.disconnectedCallback == "function" || C(t.signal, () => O.offDisconnected(r, e)) && O.onDisconnected(r, e), r;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
function J() {
|
function J() {
|
||||||
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(i) {
|
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(i) {
|
||||||
for (let f of i)
|
for (let s of i)
|
||||||
if (f.type === "childList") {
|
if (s.type === "childList") {
|
||||||
if (b(f.addedNodes, !0)) {
|
if (v(s.addedNodes, !0)) {
|
||||||
p();
|
l();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
v(f.removedNodes, !0) && p();
|
x(s.removedNodes, !0) && l();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
onConnected(i, f) {
|
onConnected(i, s) {
|
||||||
c(), o(i).connected.push(f);
|
c();
|
||||||
|
let f = o(i);
|
||||||
|
f.connected.has(s) || (f.connected.add(s), f.length_c += 1);
|
||||||
},
|
},
|
||||||
offConnected(i, f) {
|
offConnected(i, s) {
|
||||||
if (!e.has(i))
|
if (!e.has(i))
|
||||||
return;
|
return;
|
||||||
let u = e.get(i), l = u.connected;
|
let f = e.get(i);
|
||||||
l.splice(l.indexOf(f), 1), r(i, u);
|
f.connected.has(s) && (f.connected.delete(s), f.length_c -= 1, r(i, f));
|
||||||
},
|
},
|
||||||
onDisconnected(i, f) {
|
onDisconnected(i, s) {
|
||||||
c(), o(i).disconnected.push(f);
|
c();
|
||||||
|
let f = o(i);
|
||||||
|
f.disconnected.has(s) || (f.disconnected.add(s), f.length_d += 1);
|
||||||
},
|
},
|
||||||
offDisconnected(i, f) {
|
offDisconnected(i, s) {
|
||||||
if (!e.has(i))
|
if (!e.has(i))
|
||||||
return;
|
return;
|
||||||
let u = e.get(i), l = u.disconnected;
|
let f = e.get(i);
|
||||||
l.splice(l.indexOf(f), 1), r(i, u);
|
f.disconnected.has(s) && (f.disconnected.delete(s), f.length_d -= 1, r(i, f));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function r(i, f) {
|
function r(i, s) {
|
||||||
f.connected.length || f.disconnected.length || (e.delete(i), p());
|
s.length_c || s.length_d || (e.delete(i), l());
|
||||||
}
|
}
|
||||||
function o(i) {
|
function o(i) {
|
||||||
if (e.has(i))
|
if (e.has(i))
|
||||||
return e.get(i);
|
return e.get(i);
|
||||||
let f = { connected: [], disconnected: [] };
|
let s = {
|
||||||
return e.set(i, f), f;
|
connected: /* @__PURE__ */ new WeakSet(),
|
||||||
|
length_c: 0,
|
||||||
|
disconnected: /* @__PURE__ */ new WeakSet(),
|
||||||
|
length_d: 0
|
||||||
|
};
|
||||||
|
return e.set(i, s), s;
|
||||||
}
|
}
|
||||||
function c() {
|
function c() {
|
||||||
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
|
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
|
||||||
}
|
}
|
||||||
function p() {
|
function l() {
|
||||||
!t || e.size || (t = !1, n.disconnect());
|
!t || e.size || (t = !1, n.disconnect());
|
||||||
}
|
}
|
||||||
function s() {
|
function u() {
|
||||||
return new Promise(function(i) {
|
return new Promise(function(i) {
|
||||||
(requestIdleCallback || requestAnimationFrame)(i);
|
(requestIdleCallback || requestAnimationFrame)(i);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async function a(i) {
|
async function a(i) {
|
||||||
e.size > 30 && await s();
|
e.size > 30 && await u();
|
||||||
let f = [];
|
let s = [];
|
||||||
if (!(i instanceof Node))
|
if (!(i instanceof Node))
|
||||||
return f;
|
return s;
|
||||||
for (let u of e.keys())
|
for (let f of e.keys())
|
||||||
u === i || !(u instanceof Node) || i.contains(u) && f.push(u);
|
f === i || !(f instanceof Node) || i.contains(f) && s.push(f);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
function v(i, s) {
|
||||||
|
let f = !1;
|
||||||
|
for (let p of i) {
|
||||||
|
if (s && a(p).then(v), !e.has(p))
|
||||||
|
continue;
|
||||||
|
let E = e.get(p);
|
||||||
|
E.length_c && (p.dispatchEvent(new Event("dde:connected")), E.connected = /* @__PURE__ */ new WeakSet(), E.length_c = 0, E.length_d || e.delete(p), f = !0);
|
||||||
|
}
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
function b(i, f) {
|
function x(i, s) {
|
||||||
for (let u of i) {
|
let f = !1;
|
||||||
if (f && a(u).then(b), !e.has(u))
|
for (let p of i)
|
||||||
continue;
|
s && a(p).then(x), !(!e.has(p) || !e.get(p).length_d) && (p.dispatchEvent(new Event("dde:disconnected")), e.delete(p), f = !0);
|
||||||
let l = e.get(u);
|
return f;
|
||||||
return l.connected.forEach((A) => A(u)), l.connected.length = 0, l.disconnected.length || e.delete(u), !0;
|
|
||||||
}
|
|
||||||
return !1;
|
|
||||||
}
|
|
||||||
function v(i, f) {
|
|
||||||
for (let u of i) {
|
|
||||||
if (f && a(u).then(v), !e.has(u))
|
|
||||||
continue;
|
|
||||||
let l = e.get(u);
|
|
||||||
return l.disconnected.forEach((A) => A(u)), l.connected.length = 0, l.disconnected.length = 0, e.delete(u), !0;
|
|
||||||
}
|
|
||||||
return !1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,7 +274,7 @@ function J() {
|
|||||||
|
|
||||||
// src/signals-lib.js
|
// src/signals-lib.js
|
||||||
var d = Symbol.for("Signal");
|
var d = Symbol.for("Signal");
|
||||||
function y(e) {
|
function _(e) {
|
||||||
try {
|
try {
|
||||||
return Reflect.has(e, d);
|
return Reflect.has(e, d);
|
||||||
} catch {
|
} catch {
|
||||||
@ -270,10 +285,10 @@ var h = /* @__PURE__ */ new WeakMap();
|
|||||||
function g(e, t) {
|
function g(e, t) {
|
||||||
if (typeof e != "function")
|
if (typeof e != "function")
|
||||||
return U(e, t);
|
return U(e, t);
|
||||||
if (y(e))
|
if (_(e))
|
||||||
return e;
|
return e;
|
||||||
let n = U(""), r = () => n(e());
|
let n = U(""), r = () => n(e());
|
||||||
return h.set(r, /* @__PURE__ */ new Set([n])), k(r), n;
|
return h.set(r, /* @__PURE__ */ new Set([n])), K(r), n;
|
||||||
}
|
}
|
||||||
g.action = function(e, t, ...n) {
|
g.action = function(e, t, ...n) {
|
||||||
let r = e[d], { actions: o } = r;
|
let r = e[d], { actions: o } = r;
|
||||||
@ -288,7 +303,7 @@ g.on = function e(t, n, r = {}) {
|
|||||||
if (!(o && o.aborted)) {
|
if (!(o && o.aborted)) {
|
||||||
if (Array.isArray(t))
|
if (Array.isArray(t))
|
||||||
return t.forEach((c) => e(c, n, r));
|
return t.forEach((c) => e(c, n, r));
|
||||||
D(t, n), o && o.addEventListener("abort", () => q(t, n));
|
N(t, n), o && o.addEventListener("abort", () => k(t, n));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
g.symbols = {
|
g.symbols = {
|
||||||
@ -313,26 +328,26 @@ g.clear = function(...e) {
|
|||||||
g.el = function(e, t) {
|
g.el = function(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 c = (p) => {
|
let c = (l) => {
|
||||||
if (!n.parentNode || !r.parentNode)
|
if (!n.parentNode || !r.parentNode)
|
||||||
return q(e, c);
|
return k(e, c);
|
||||||
let s = t(p);
|
let u = t(l);
|
||||||
Array.isArray(s) || (s = [s]);
|
Array.isArray(u) || (u = [u]);
|
||||||
let a = n;
|
let a = n;
|
||||||
for (; (a = n.nextSibling) !== r; )
|
for (; (a = n.nextSibling) !== r; )
|
||||||
a.remove();
|
a.remove();
|
||||||
n.after(...s);
|
n.after(...u);
|
||||||
};
|
};
|
||||||
return D(e, c), c(e()), o;
|
return N(e, c), c(e()), o;
|
||||||
};
|
};
|
||||||
var $ = {
|
var $ = {
|
||||||
isSignal: y,
|
isSignal: _,
|
||||||
processReactiveAttribute(e, t, n, r) {
|
processReactiveAttribute(e, t, n, r) {
|
||||||
return y(n) ? (D(n, (o) => r([t, o])), n()) : n;
|
return _(n) ? (N(n, (o) => r([t, o])), n()) : n;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function U(e, t) {
|
function U(e, t) {
|
||||||
let n = (...r) => r.length ? X(n, r[0]) : Q(n);
|
let n = (...r) => r.length ? Y(n, r[0]) : X(n);
|
||||||
return Z(n, e, t);
|
return Z(n, e, t);
|
||||||
}
|
}
|
||||||
var V = Object.assign(/* @__PURE__ */ Object.create(null), {
|
var V = Object.assign(/* @__PURE__ */ Object.create(null), {
|
||||||
@ -341,56 +356,56 @@ var V = Object.assign(/* @__PURE__ */ Object.create(null), {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
function Z(e, t, n) {
|
function Z(e, t, n) {
|
||||||
return N(n) !== "[object Object]" && (n = {}), e[d] = {
|
return D(n) !== "[object Object]" && (n = {}), e[d] = {
|
||||||
value: t,
|
value: t,
|
||||||
actions: n,
|
actions: n,
|
||||||
listeners: /* @__PURE__ */ new Set()
|
listeners: /* @__PURE__ */ new Set()
|
||||||
}, e.toJSON = () => e(), Object.setPrototypeOf(e[d], V), e;
|
}, e.toJSON = () => e(), Object.setPrototypeOf(e[d], V), e;
|
||||||
}
|
}
|
||||||
var R = [];
|
var R = [];
|
||||||
function k(e) {
|
function K(e) {
|
||||||
let t = function() {
|
let t = function() {
|
||||||
R.push(t), e(), R.pop();
|
R.push(t), e(), R.pop();
|
||||||
};
|
};
|
||||||
h.has(e) && (h.set(t, h.get(e)), h.delete(e)), t();
|
h.has(e) && (h.set(t, h.get(e)), h.delete(e)), t();
|
||||||
}
|
}
|
||||||
function K() {
|
function Q() {
|
||||||
return R[R.length - 1];
|
return R[R.length - 1];
|
||||||
}
|
}
|
||||||
function Q(e) {
|
function X(e) {
|
||||||
if (!e[d])
|
if (!e[d])
|
||||||
return;
|
return;
|
||||||
let { value: t, listeners: n } = e[d], r = K();
|
let { value: t, listeners: n } = e[d], r = Q();
|
||||||
return r && n.add(r), h.has(r) && h.get(r).add(e), t;
|
return r && n.add(r), h.has(r) && h.get(r).add(e), t;
|
||||||
}
|
}
|
||||||
function X(e, t) {
|
function Y(e, t) {
|
||||||
if (!e[d])
|
if (!e[d])
|
||||||
return;
|
return;
|
||||||
let n = e[d];
|
let n = e[d];
|
||||||
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 D(e, t) {
|
function N(e, t) {
|
||||||
if (e[d])
|
if (e[d])
|
||||||
return e[d].listeners.add(t);
|
return e[d].listeners.add(t);
|
||||||
}
|
}
|
||||||
function q(e, t) {
|
function k(e, t) {
|
||||||
if (e[d])
|
if (e[d])
|
||||||
return e[d].listeners.delete(t);
|
return e[d].listeners.delete(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
// signals.js
|
// signals.js
|
||||||
C($);
|
A($);
|
||||||
export {
|
export {
|
||||||
g as S,
|
g as S,
|
||||||
S as assign,
|
y as assign,
|
||||||
B as classListDeclarative,
|
B as classListDeclarative,
|
||||||
ce as createElement,
|
ie as createElement,
|
||||||
ae as dispatchEvent,
|
de as dispatchEvent,
|
||||||
ce as el,
|
ie as el,
|
||||||
se as empty,
|
fe as empty,
|
||||||
y as isSignal,
|
_ as isSignal,
|
||||||
oe as namespace,
|
|
||||||
T as on,
|
T as on,
|
||||||
C as registerReactivity
|
A as registerReactivity,
|
||||||
|
ce as scope
|
||||||
};
|
};
|
||||||
|
277
dist/esm.js
vendored
277
dist/esm.js
vendored
@ -1,24 +1,24 @@
|
|||||||
// src/signals-common.js
|
// src/signals-common.js
|
||||||
var g = {
|
var E = {
|
||||||
isSignal(e) {
|
isSignal(e) {
|
||||||
return !1;
|
return !1;
|
||||||
},
|
},
|
||||||
processReactiveAttribute(e, t, n, r) {
|
processReactiveAttribute(e, t, r, n) {
|
||||||
return n;
|
return r;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function y(e, t = !0) {
|
function N(e, t = !0) {
|
||||||
return t ? Object.assign(g, e) : (Object.setPrototypeOf(e, g), e);
|
return t ? Object.assign(E, e) : (Object.setPrototypeOf(e, E), e);
|
||||||
}
|
}
|
||||||
function v(e) {
|
function m(e) {
|
||||||
return g.isPrototypeOf(e) && e !== g ? e : g;
|
return E.isPrototypeOf(e) && e !== E ? e : E;
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/helpers.js
|
// src/helpers.js
|
||||||
function p(e) {
|
function p(e) {
|
||||||
return typeof e > "u";
|
return typeof e > "u";
|
||||||
}
|
}
|
||||||
function w(e, t) {
|
function _(e, t) {
|
||||||
if (!e || !(e instanceof AbortSignal))
|
if (!e || !(e instanceof AbortSignal))
|
||||||
return !0;
|
return !0;
|
||||||
if (!e.aborted)
|
if (!e.aborted)
|
||||||
@ -28,9 +28,9 @@ function w(e, t) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// src/dom-common.js
|
// src/dom-common.js
|
||||||
var R = { setDeleteAttr: P };
|
var O = { setDeleteAttr: P };
|
||||||
function P(e, t, n) {
|
function P(e, t, r) {
|
||||||
if (Reflect.set(e, t, n), !!p(n)) {
|
if (Reflect.set(e, t, r), !!p(r)) {
|
||||||
if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined")
|
if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined")
|
||||||
return e.removeAttribute(t);
|
return e.removeAttribute(t);
|
||||||
if (Reflect.get(e, t) === "undefined")
|
if (Reflect.get(e, t) === "undefined")
|
||||||
@ -39,227 +39,242 @@ function P(e, t, n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// src/dom.js
|
// src/dom.js
|
||||||
var x = "html";
|
var h = "html", S = {
|
||||||
function H(e) {
|
elNamespace(e) {
|
||||||
return x = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
|
return h = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
|
||||||
append(...t) {
|
append(...t) {
|
||||||
return x = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t);
|
return h = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
function I(e, t, ...n) {
|
get namespace() {
|
||||||
let r = this, u = v(this), i;
|
return h;
|
||||||
|
},
|
||||||
|
set namespace(e) {
|
||||||
|
return h = e;
|
||||||
|
}
|
||||||
|
}, H = Object.assign((e) => e ? e(document.body) : document.body, S);
|
||||||
|
function I(e, t, ...r) {
|
||||||
|
let n = this, u = m(this), i;
|
||||||
switch ((Object(t) !== t || u.isSignal(t)) && (t = { textContent: t }), !0) {
|
switch ((Object(t) !== t || u.isSignal(t)) && (t = { textContent: t }), !0) {
|
||||||
case typeof e == "function": {
|
case typeof e == "function": {
|
||||||
i = e(t || void 0, (f) => f ? (n.unshift(f), void 0) : i);
|
let a = Object.assign((f) => f ? (r.unshift(f), void 0) : i, S);
|
||||||
|
i = e(t || void 0, a), h = "html";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case e === "#text":
|
case e === "#text":
|
||||||
i = m.call(r, document.createTextNode(""), t);
|
i = w.call(n, document.createTextNode(""), t);
|
||||||
break;
|
break;
|
||||||
case e === "<>":
|
case e === "<>":
|
||||||
i = m.call(r, document.createDocumentFragment(), t);
|
i = w.call(n, document.createDocumentFragment(), t);
|
||||||
break;
|
break;
|
||||||
case x !== "html":
|
case h !== "html":
|
||||||
i = m.call(r, document.createElementNS(x, e), t);
|
i = w.call(n, document.createElementNS(h, e), t);
|
||||||
break;
|
break;
|
||||||
case !i:
|
case !i:
|
||||||
i = m.call(r, document.createElement(e), t);
|
i = w.call(n, document.createElement(e), t);
|
||||||
}
|
}
|
||||||
return n.forEach((l) => l(i)), i;
|
return r.forEach((a) => a(i)), i;
|
||||||
}
|
}
|
||||||
var { setDeleteAttr: C } = R;
|
var { setDeleteAttr: R } = O;
|
||||||
function m(e, ...t) {
|
function w(e, ...t) {
|
||||||
let n = this, r = v(this);
|
let r = this, n = m(this);
|
||||||
if (!t.length)
|
if (!t.length)
|
||||||
return e;
|
return e;
|
||||||
let i = (e instanceof SVGElement ? M : F).bind(null, e, "Attribute");
|
let i = (e instanceof SVGElement ? T : M).bind(null, e, "Attribute");
|
||||||
return Object.entries(Object.assign({}, ...t)).forEach(function l([f, d]) {
|
return Object.entries(Object.assign({}, ...t)).forEach(function a([f, d]) {
|
||||||
d = r.processReactiveAttribute(e, f, d, l);
|
d = n.processReactiveAttribute(e, f, d, a);
|
||||||
let [h] = f;
|
let [g] = f;
|
||||||
if (h === "=")
|
if (g === "=")
|
||||||
return i(f.slice(1), d);
|
return i(f.slice(1), d);
|
||||||
if (h === ".")
|
if (g === ".")
|
||||||
return D(e, f.slice(1), d);
|
return C(e, f.slice(1), d);
|
||||||
if (/(aria|data)([A-Z])/.test(f))
|
if (/(aria|data)([A-Z])/.test(f))
|
||||||
return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(f, d);
|
return f = f.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), i(f, d);
|
||||||
switch (f === "className" && (f = "class"), f) {
|
switch (f === "className" && (f = "class"), f) {
|
||||||
case "xlink:href":
|
case "xlink:href":
|
||||||
return i(f, d, "http://www.w3.org/1999/xlink");
|
return i(f, d, "http://www.w3.org/1999/xlink");
|
||||||
case "textContent":
|
case "textContent":
|
||||||
return C(e, f, d);
|
return R(e, f, d);
|
||||||
case "style":
|
case "style":
|
||||||
if (typeof d != "object")
|
if (typeof d != "object")
|
||||||
break;
|
break;
|
||||||
case "dataset":
|
case "dataset":
|
||||||
return O(r, d, D.bind(null, e[f]));
|
return A(n, d, C.bind(null, e[f]));
|
||||||
case "ariaset":
|
case "ariaset":
|
||||||
return O(r, d, (E, o) => i("aria-" + E, o));
|
return A(n, d, (b, c) => i("aria-" + b, c));
|
||||||
case "classList":
|
case "classList":
|
||||||
return _.call(n, e, d);
|
return j.call(r, e, d);
|
||||||
}
|
}
|
||||||
return j(e, f) ? C(e, f, d) : i(f, d);
|
return F(e, f) ? R(e, f, d) : i(f, d);
|
||||||
}), e;
|
}), e;
|
||||||
}
|
}
|
||||||
function _(e, t) {
|
function j(e, t) {
|
||||||
let n = v(this);
|
let r = m(this);
|
||||||
return O(
|
return A(
|
||||||
n,
|
r,
|
||||||
t,
|
t,
|
||||||
(r, u) => e.classList.toggle(r, u === -1 ? void 0 : !!u)
|
(n, u) => e.classList.toggle(n, u === -1 ? void 0 : !!u)
|
||||||
), e;
|
), e;
|
||||||
}
|
}
|
||||||
function Z(e) {
|
function Z(e) {
|
||||||
return Array.from(e.children).forEach((t) => t.remove()), e;
|
return Array.from(e.children).forEach((t) => t.remove()), e;
|
||||||
}
|
}
|
||||||
function j(e, t) {
|
function F(e, t) {
|
||||||
if (!Reflect.has(e, t))
|
if (!Reflect.has(e, t))
|
||||||
return !1;
|
return !1;
|
||||||
let n = L(e, t);
|
let r = y(e, t);
|
||||||
return !p(n.set);
|
return !p(r.set);
|
||||||
}
|
}
|
||||||
function L(e, t) {
|
function y(e, t) {
|
||||||
if (e = Object.getPrototypeOf(e), !e)
|
if (e = Object.getPrototypeOf(e), !e)
|
||||||
return {};
|
return {};
|
||||||
let n = Object.getOwnPropertyDescriptor(e, t);
|
let r = Object.getOwnPropertyDescriptor(e, t);
|
||||||
return n || L(e, t);
|
return r || y(e, t);
|
||||||
}
|
}
|
||||||
function O(e, t, n) {
|
function A(e, t, r) {
|
||||||
if (!(typeof t != "object" || t === null))
|
if (!(typeof t != "object" || t === null))
|
||||||
return Object.entries(t).forEach(function([u, i]) {
|
return Object.entries(t).forEach(function([u, i]) {
|
||||||
u && (i = e.processReactiveAttribute(t, u, i, (l) => n(...l)), n(u, i));
|
u && (i = e.processReactiveAttribute(t, u, i, (a) => r(...a)), r(u, i));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function S(e) {
|
function D(e) {
|
||||||
return Array.isArray(e) ? e.filter(Boolean).join(" ") : e;
|
return Array.isArray(e) ? e.filter(Boolean).join(" ") : e;
|
||||||
}
|
}
|
||||||
function F(e, t, n, r) {
|
function M(e, t, r, n) {
|
||||||
return e[(p(r) ? "remove" : "set") + t](n, S(r));
|
return e[(p(n) ? "remove" : "set") + t](r, D(n));
|
||||||
}
|
}
|
||||||
function M(e, t, n, r, u = null) {
|
function T(e, t, r, n, u = null) {
|
||||||
return e[(p(r) ? "remove" : "set") + t + "NS"](u, n, S(r));
|
return e[(p(n) ? "remove" : "set") + t + "NS"](u, r, D(n));
|
||||||
}
|
}
|
||||||
function D(e, t, n) {
|
function C(e, t, r) {
|
||||||
if (Reflect.set(e, t, n), !!p(n))
|
if (Reflect.set(e, t, r), !!p(r))
|
||||||
return Reflect.deleteProperty(e, t);
|
return Reflect.deleteProperty(e, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/events.js
|
// src/events.js
|
||||||
function J(e, t, ...n) {
|
function K(e, t, ...r) {
|
||||||
let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t);
|
let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t);
|
||||||
return e.dispatchEvent(r);
|
return e.dispatchEvent(n);
|
||||||
}
|
}
|
||||||
function N(e, t, n) {
|
function L(e, t, r) {
|
||||||
return function(u) {
|
return function(u) {
|
||||||
return u.addEventListener(e, t, n), u;
|
return u.addEventListener(e, t, r), u;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
var b = T();
|
var x = U();
|
||||||
N.connected = function(e, t) {
|
L.connected = function(e, t) {
|
||||||
return function(r) {
|
return typeof t != "object" && (t = {}), t.once = !0, function(n) {
|
||||||
return typeof r.connectedCallback == "function" ? (r.addEventListener("dde:connected", e, t), r) : (w(t && t.signal, () => b.offConnected(r, e)) && (r.isConnected ? e(new Event("dde:connected")) : b.onConnected(r, e)), r);
|
return n.addEventListener("dde:connected", e, t), typeof n.connectedCallback == "function" ? n : n.isConnected ? (n.dispatchEvent(new Event("dde:connected")), n) : (_(t.signal, () => x.offConnected(n, e)) && x.onConnected(n, e), n);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
N.disconnected = function(e, t) {
|
L.disconnected = function(e, t) {
|
||||||
return function(r) {
|
return typeof t != "object" && (t = {}), t.once = !0, function(n) {
|
||||||
return typeof r.disconnectedCallback == "function" ? (r.addEventListener("dde:disconnected", e, t), r) : (w(t && t.signal, () => b.offDisconnected(r, e)) && b.onDisconnected(r, e), r);
|
return n.addEventListener("dde:disconnected", e, t), typeof n.disconnectedCallback == "function" || _(t.signal, () => x.offDisconnected(n, e)) && x.onDisconnected(n, e), n;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
function T() {
|
function U() {
|
||||||
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(o) {
|
let e = /* @__PURE__ */ new Map(), t = !1, r = new MutationObserver(function(c) {
|
||||||
for (let c of o)
|
for (let o of c)
|
||||||
if (c.type === "childList") {
|
if (o.type === "childList") {
|
||||||
if (h(c.addedNodes, !0)) {
|
if (g(o.addedNodes, !0)) {
|
||||||
l();
|
a();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
E(c.removedNodes, !0) && l();
|
b(o.removedNodes, !0) && a();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
onConnected(o, c) {
|
onConnected(c, o) {
|
||||||
i(), u(o).connected.push(c);
|
i();
|
||||||
|
let s = u(c);
|
||||||
|
s.connected.has(o) || (s.connected.add(o), s.length_c += 1);
|
||||||
},
|
},
|
||||||
offConnected(o, c) {
|
offConnected(c, o) {
|
||||||
if (!e.has(o))
|
if (!e.has(c))
|
||||||
return;
|
return;
|
||||||
let s = e.get(o), a = s.connected;
|
let s = e.get(c);
|
||||||
a.splice(a.indexOf(c), 1), r(o, s);
|
s.connected.has(o) && (s.connected.delete(o), s.length_c -= 1, n(c, s));
|
||||||
},
|
},
|
||||||
onDisconnected(o, c) {
|
onDisconnected(c, o) {
|
||||||
i(), u(o).disconnected.push(c);
|
i();
|
||||||
|
let s = u(c);
|
||||||
|
s.disconnected.has(o) || (s.disconnected.add(o), s.length_d += 1);
|
||||||
},
|
},
|
||||||
offDisconnected(o, c) {
|
offDisconnected(c, o) {
|
||||||
if (!e.has(o))
|
if (!e.has(c))
|
||||||
return;
|
return;
|
||||||
let s = e.get(o), a = s.disconnected;
|
let s = e.get(c);
|
||||||
a.splice(a.indexOf(c), 1), r(o, s);
|
s.disconnected.has(o) && (s.disconnected.delete(o), s.length_d -= 1, n(c, s));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function r(o, c) {
|
function n(c, o) {
|
||||||
c.connected.length || c.disconnected.length || (e.delete(o), l());
|
o.length_c || o.length_d || (e.delete(c), a());
|
||||||
}
|
}
|
||||||
function u(o) {
|
function u(c) {
|
||||||
if (e.has(o))
|
if (e.has(c))
|
||||||
return e.get(o);
|
return e.get(c);
|
||||||
let c = { connected: [], disconnected: [] };
|
let o = {
|
||||||
return e.set(o, c), c;
|
connected: /* @__PURE__ */ new WeakSet(),
|
||||||
|
length_c: 0,
|
||||||
|
disconnected: /* @__PURE__ */ new WeakSet(),
|
||||||
|
length_d: 0
|
||||||
|
};
|
||||||
|
return e.set(c, o), o;
|
||||||
}
|
}
|
||||||
function i() {
|
function i() {
|
||||||
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
|
t || (t = !0, r.observe(document.body, { childList: !0, subtree: !0 }));
|
||||||
}
|
}
|
||||||
function l() {
|
function a() {
|
||||||
!t || e.size || (t = !1, n.disconnect());
|
!t || e.size || (t = !1, r.disconnect());
|
||||||
}
|
}
|
||||||
function f() {
|
function f() {
|
||||||
return new Promise(function(o) {
|
return new Promise(function(c) {
|
||||||
(requestIdleCallback || requestAnimationFrame)(o);
|
(requestIdleCallback || requestAnimationFrame)(c);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async function d(o) {
|
async function d(c) {
|
||||||
e.size > 30 && await f();
|
e.size > 30 && await f();
|
||||||
let c = [];
|
let o = [];
|
||||||
if (!(o instanceof Node))
|
if (!(c instanceof Node))
|
||||||
return c;
|
return o;
|
||||||
for (let s of e.keys())
|
for (let s of e.keys())
|
||||||
s === o || !(s instanceof Node) || o.contains(s) && c.push(s);
|
s === c || !(s instanceof Node) || c.contains(s) && o.push(s);
|
||||||
return c;
|
return o;
|
||||||
}
|
}
|
||||||
function h(o, c) {
|
function g(c, o) {
|
||||||
for (let s of o) {
|
let s = !1;
|
||||||
if (c && d(s).then(h), !e.has(s))
|
for (let l of c) {
|
||||||
|
if (o && d(l).then(g), !e.has(l))
|
||||||
continue;
|
continue;
|
||||||
let a = e.get(s);
|
let v = e.get(l);
|
||||||
return a.connected.forEach((A) => A(s)), a.connected.length = 0, a.disconnected.length || e.delete(s), !0;
|
v.length_c && (l.dispatchEvent(new Event("dde:connected")), v.connected = /* @__PURE__ */ new WeakSet(), v.length_c = 0, v.length_d || e.delete(l), s = !0);
|
||||||
}
|
}
|
||||||
return !1;
|
return s;
|
||||||
}
|
}
|
||||||
function E(o, c) {
|
function b(c, o) {
|
||||||
for (let s of o) {
|
let s = !1;
|
||||||
if (c && d(s).then(E), !e.has(s))
|
for (let l of c)
|
||||||
continue;
|
o && d(l).then(b), !(!e.has(l) || !e.get(l).length_d) && (l.dispatchEvent(new Event("dde:disconnected")), e.delete(l), s = !0);
|
||||||
let a = e.get(s);
|
return s;
|
||||||
return a.disconnected.forEach((A) => A(s)), a.connected.length = 0, a.disconnected.length = 0, e.delete(s), !0;
|
|
||||||
}
|
|
||||||
return !1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// index.js
|
// index.js
|
||||||
[HTMLElement, SVGElement, DocumentFragment].forEach((e) => {
|
[HTMLElement, SVGElement, 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 {
|
||||||
m as assign,
|
w as assign,
|
||||||
_ as classListDeclarative,
|
j as classListDeclarative,
|
||||||
I as createElement,
|
I as createElement,
|
||||||
J as dispatchEvent,
|
K as dispatchEvent,
|
||||||
I as el,
|
I as el,
|
||||||
Z as empty,
|
Z as empty,
|
||||||
H as namespace,
|
L as on,
|
||||||
N as on,
|
N as registerReactivity,
|
||||||
y as registerReactivity
|
H as scope
|
||||||
};
|
};
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
import { style, el, on, S, namespace } from '../exports.js';
|
import { style, el, on, S } from '../exports.js';
|
||||||
const className= style.host(fullNameComponent).css`
|
const className= style.host(fullNameComponent).css`
|
||||||
:host form{
|
:host form{
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-flow: column nowrap;
|
flex-flow: column nowrap;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
export function fullNameComponent(){
|
export function fullNameComponent(_, scope){
|
||||||
const labels= [ "Name", "Surname" ];
|
const labels= [ "Name", "Surname" ];
|
||||||
const name= labels.map(_=> S(""));
|
const name= labels.map(_=> S(""));
|
||||||
const full_name= S(()=>
|
const full_name= S(()=>
|
||||||
name.map(l=> l()).filter(Boolean).join(" ") || "-");
|
name.map(l=> l()).filter(Boolean).join(" ") || "-");
|
||||||
|
scope(on.connected(()=> console.log(fullNameComponent)));
|
||||||
|
scope(on.disconnected(()=> console.log(fullNameComponent)))
|
||||||
|
|
||||||
return el("div", { className }).append(
|
return el("div", { className }).append(
|
||||||
el("h2", "Simple form:"),
|
el("h2", "Simple form:"),
|
||||||
@ -24,7 +26,7 @@ export function fullNameComponent(){
|
|||||||
": ",
|
": ",
|
||||||
el("#text", full_name)
|
el("#text", full_name)
|
||||||
),
|
),
|
||||||
namespace("svg").append(
|
scope.elNamespace("svg").append(
|
||||||
el("svg", { viewBox: "0 0 240 80", style: { height: "80px", display: "block" } }).append(
|
el("svg", { viewBox: "0 0 240 80", style: { height: "80px", display: "block" } }).append(
|
||||||
//el("style", { })
|
//el("style", { })
|
||||||
el("text", { x: 20, y: 35, textContent: "Text" })
|
el("text", { x: 20, y: 35, textContent: "Text" })
|
||||||
|
@ -17,7 +17,8 @@ export class CustomHTMLTestElement extends HTMLElement{
|
|||||||
}
|
}
|
||||||
|
|
||||||
render({ name, test, preName }, host){
|
render({ name, test, preName }, host){
|
||||||
host(on.connected(console.log));
|
host(on.connected(()=> console.log(CustomHTMLTestElement)));
|
||||||
|
host(on.disconnected(()=> console.log(CustomHTMLTestElement)));
|
||||||
return el("p").append(
|
return el("p").append(
|
||||||
el("#text", { textContent: name }),
|
el("#text", { textContent: name }),
|
||||||
el("#text", { textContent: test }),
|
el("#text", { textContent: test }),
|
||||||
|
8
index.d.ts
vendored
8
index.d.ts
vendored
@ -1,4 +1,4 @@
|
|||||||
import { Signal } from "./src/signals";
|
import { Signal } from "./signals";
|
||||||
//TODO?
|
//TODO?
|
||||||
/** Is filled when function is succesfully called ⇒ and returns component's root element. */
|
/** Is filled when function is succesfully called ⇒ and returns component's root element. */
|
||||||
type Host<el extends Element>= (extender?: ElementExtender<el>)=> el | undefined;
|
type Host<el extends Element>= (extender?: ElementExtender<el>)=> el | undefined;
|
||||||
@ -46,19 +46,17 @@ type ElementAttributes<T extends keyof ElementTagNameMap | ElementTagNameMap[key
|
|||||||
T extends keyof ElementTagNameMap ?
|
T extends keyof ElementTagNameMap ?
|
||||||
Omit<ElementTagNameMap[T],"classList"|"className"> & AttrsModified :
|
Omit<ElementTagNameMap[T],"classList"|"className"> & AttrsModified :
|
||||||
Omit<T,"classList"|"className"> & AttrsModified;
|
Omit<T,"classList"|"className"> & AttrsModified;
|
||||||
export function assign<El extends Element>(element: El, ...attrs_array: ElementAttributes<El>[]): El
|
export function assign<El extends Element>(element: El, ...attrs_array: Partial<ElementAttributes<El>>[]): El
|
||||||
|
|
||||||
type ElementExtender<El extends Element>= (element: El)=> El;
|
type ElementExtender<El extends Element>= (element: El)=> El;
|
||||||
type TagNameFragment= "<>";
|
type TagNameFragment= "<>";
|
||||||
export function el<TAG extends keyof ElementTagNameMap>(
|
export function el<TAG extends keyof ElementTagNameMap>(
|
||||||
tag_name: TAG,
|
tag_name: TAG,
|
||||||
attrs?: ElementAttributes<ElementTagNameMap[TAG]>,
|
attrs?: Partial<ElementAttributes<ElementTagNameMap[TAG]>>,
|
||||||
...extenders: ElementExtender<ElementTagNameMap[TAG]>[]
|
...extenders: ElementExtender<ElementTagNameMap[TAG]>[]
|
||||||
): ElementTagNameMap[TAG]
|
): ElementTagNameMap[TAG]
|
||||||
export function el<T>(
|
export function el<T>(
|
||||||
tag_name: TagNameFragment,
|
tag_name: TagNameFragment,
|
||||||
signal?: Signal<T, any>,
|
|
||||||
cb?: (a: T)=> HTMLElement | HTMLElement[]
|
|
||||||
): DocumentFragment
|
): DocumentFragment
|
||||||
export function el<R extends Element, T extends (attrs: any, host: Host<R>)=> R>(
|
export function el<R extends Element, T extends (attrs: any, host: Host<R>)=> R>(
|
||||||
fComponent: T,
|
fComponent: T,
|
||||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "deka-dom-el",
|
"name": "deka-dom-el",
|
||||||
"version": "0.3.0",
|
"version": "0.4.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "deka-dom-el",
|
"name": "deka-dom-el",
|
||||||
"version": "0.3.0",
|
"version": "0.4.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@size-limit/preset-small-lib": "^8.2.6",
|
"@size-limit/preset-small-lib": "^8.2.6",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "deka-dom-el",
|
"name": "deka-dom-el",
|
||||||
"version": "0.3.0",
|
"version": "0.4.0",
|
||||||
"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",
|
||||||
@ -71,8 +71,8 @@
|
|||||||
"gzip": false
|
"gzip": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "./test/components/webComponent.js",
|
"path": "./examples/components/webComponent.js",
|
||||||
"limit": "10kb",
|
"limit": "11kb",
|
||||||
"gzip": false
|
"gzip": false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
14
src/dom.js
14
src/dom.js
@ -2,7 +2,8 @@ import { signals } from "./signals-common.js";
|
|||||||
|
|
||||||
/** @type {"html"|"svg"|string} */
|
/** @type {"html"|"svg"|string} */
|
||||||
let namespace_curr= "html";
|
let namespace_curr= "html";
|
||||||
export function namespace(namespace){
|
const scopes= {
|
||||||
|
elNamespace(namespace){
|
||||||
namespace_curr= namespace==="svg" ? "http://www.w3.org/2000/svg" : namespace;
|
namespace_curr= namespace==="svg" ? "http://www.w3.org/2000/svg" : namespace;
|
||||||
return {
|
return {
|
||||||
append(...el){
|
append(...el){
|
||||||
@ -12,7 +13,11 @@ export function namespace(namespace){
|
|||||||
return f.append(...el);
|
return f.append(...el);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
|
get namespace(){ return namespace_curr; },
|
||||||
|
set namespace(v){ return ( namespace_curr= v ); },
|
||||||
|
};
|
||||||
|
export const scope= Object.assign(c=> c ? c(document.body) : document.body, scopes);
|
||||||
export function createElement(tag, attributes, ...connect){
|
export function createElement(tag, attributes, ...connect){
|
||||||
const _this= this;
|
const _this= this;
|
||||||
const s= signals(this);
|
const s= signals(this);
|
||||||
@ -22,8 +27,9 @@ export function createElement(tag, attributes, ...connect){
|
|||||||
attributes= { textContent: attributes };
|
attributes= { textContent: attributes };
|
||||||
switch(true){
|
switch(true){
|
||||||
case typeof tag==="function": {
|
case typeof tag==="function": {
|
||||||
const ref= c=> c ? (connect.unshift(c), undefined) : el;
|
const scope= Object.assign(c=> c ? (connect.unshift(c), undefined) : el, scopes);
|
||||||
el= tag(attributes || undefined, ref);
|
el= tag(attributes || undefined, scope);
|
||||||
|
namespace_curr= "html";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case tag==="#text": el= assign.call(_this, document.createTextNode(""), attributes); break;
|
case tag==="#text": el= assign.call(_this, document.createTextNode(""), attributes); break;
|
||||||
|
@ -15,25 +15,31 @@ const c_ch_o= connectionsChangesObserverConstructor();
|
|||||||
import { onAbort } from './helpers.js';
|
import { onAbort } from './helpers.js';
|
||||||
//TODO: cleanUp when event before abort?
|
//TODO: cleanUp when event before abort?
|
||||||
on.connected= function(listener, options){
|
on.connected= function(listener, options){
|
||||||
|
if(typeof options !== "object")
|
||||||
|
options= {};
|
||||||
|
options.once= true;
|
||||||
return function registerElement(element){
|
return function registerElement(element){
|
||||||
if(typeof element.connectedCallback === "function"){
|
|
||||||
element.addEventListener("dde:connected", listener, options);
|
element.addEventListener("dde:connected", listener, options);
|
||||||
|
if(typeof element.connectedCallback === "function") return element;
|
||||||
|
if(element.isConnected){
|
||||||
|
element.dispatchEvent(new Event("dde:connected"));
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
const c= onAbort(options && options.signal, ()=> c_ch_o.offConnected(element, listener));
|
|
||||||
if(!c) return element;
|
const c= onAbort(options.signal, ()=> c_ch_o.offConnected(element, listener));
|
||||||
if(element.isConnected) listener(new Event("dde:connected"));
|
if(c) c_ch_o.onConnected(element, listener);
|
||||||
else c_ch_o.onConnected(element, listener);
|
|
||||||
return element;
|
return element;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
on.disconnected= function(listener, options){
|
on.disconnected= function(listener, options){
|
||||||
|
if(typeof options !== "object")
|
||||||
|
options= {};
|
||||||
|
options.once= true;
|
||||||
return function registerElement(element){
|
return function registerElement(element){
|
||||||
if(typeof element.disconnectedCallback === "function"){
|
|
||||||
element.addEventListener("dde:disconnected", listener, options);
|
element.addEventListener("dde:disconnected", listener, options);
|
||||||
return element;
|
if(typeof element.disconnectedCallback === "function") return element;
|
||||||
}
|
|
||||||
const c= onAbort(options && options.signal, ()=> c_ch_o.offDisconnected(element, listener));
|
const c= onAbort(options.signal, ()=> c_ch_o.offDisconnected(element, listener));
|
||||||
if(c) c_ch_o.onDisconnected(element, listener);
|
if(c) c_ch_o.onDisconnected(element, listener);
|
||||||
return element;
|
return element;
|
||||||
};
|
};
|
||||||
@ -57,37 +63,48 @@ function connectionsChangesObserverConstructor(){
|
|||||||
onConnected(element, listener){
|
onConnected(element, listener){
|
||||||
start();
|
start();
|
||||||
const listeners= getElementStore(element);
|
const listeners= getElementStore(element);
|
||||||
listeners.connected.push(listener);
|
if(listeners.connected.has(listener)) return;
|
||||||
|
listeners.connected.add(listener);
|
||||||
|
listeners.length_c+= 1;
|
||||||
},
|
},
|
||||||
offConnected(element, listener){
|
offConnected(element, listener){
|
||||||
if(!store.has(element)) return;
|
if(!store.has(element)) return;
|
||||||
const ls= store.get(element);
|
const ls= store.get(element);
|
||||||
const l= ls.connected;
|
if(!ls.connected.has(listener)) return;
|
||||||
l.splice(l.indexOf(listener), 1);
|
ls.connected.delete(listener);
|
||||||
|
ls.length_c-= 1;
|
||||||
cleanWhenOff(element, ls);
|
cleanWhenOff(element, ls);
|
||||||
},
|
},
|
||||||
onDisconnected(element, listener){
|
onDisconnected(element, listener){
|
||||||
start();
|
start();
|
||||||
const listeners= getElementStore(element);
|
const listeners= getElementStore(element);
|
||||||
listeners.disconnected.push(listener);
|
if(listeners.disconnected.has(listener)) return;
|
||||||
|
listeners.disconnected.add(listener);
|
||||||
|
listeners.length_d+= 1;
|
||||||
},
|
},
|
||||||
offDisconnected(element, listener){
|
offDisconnected(element, listener){
|
||||||
if(!store.has(element)) return;
|
if(!store.has(element)) return;
|
||||||
const ls= store.get(element);
|
const ls= store.get(element);
|
||||||
const l= ls.disconnected;
|
if(!ls.disconnected.has(listener)) return;
|
||||||
l.splice(l.indexOf(listener), 1);
|
ls.disconnected.delete(listener);
|
||||||
|
ls.length_d-= 1;
|
||||||
cleanWhenOff(element, ls);
|
cleanWhenOff(element, ls);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function cleanWhenOff(element, ls){
|
function cleanWhenOff(element, ls){
|
||||||
if(ls.connected.length || ls.disconnected.length)
|
if(ls.length_c || ls.length_d)
|
||||||
return;
|
return;
|
||||||
store.delete(element);
|
store.delete(element);
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
function getElementStore(element){
|
function getElementStore(element){
|
||||||
if(store.has(element)) return store.get(element);
|
if(store.has(element)) return store.get(element);
|
||||||
const out= { connected: [], disconnected: [] };
|
const out= {
|
||||||
|
connected: new WeakSet(),
|
||||||
|
length_c: 0,
|
||||||
|
disconnected: new WeakSet(),
|
||||||
|
length_d: 0
|
||||||
|
};
|
||||||
store.set(element, out);
|
store.set(element, out);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
@ -118,31 +135,36 @@ function connectionsChangesObserverConstructor(){
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
function observerAdded(addedNodes, is_root){
|
function observerAdded(addedNodes, is_root){
|
||||||
|
let out= false;
|
||||||
for(const element of addedNodes){
|
for(const element of addedNodes){
|
||||||
if(is_root) collectChildren(element).then(observerAdded);
|
if(is_root) collectChildren(element).then(observerAdded);
|
||||||
if(!store.has(element)) continue;
|
if(!store.has(element)) continue;
|
||||||
|
|
||||||
const ls= store.get(element);
|
const ls= store.get(element);
|
||||||
ls.connected.forEach(listener=> listener(element));
|
if(!ls.length_c) continue;
|
||||||
ls.connected.length= 0;
|
|
||||||
if(!ls.disconnected.length) store.delete(element);
|
element.dispatchEvent(new Event("dde:connected"));
|
||||||
return true;
|
ls.connected= new WeakSet();
|
||||||
|
ls.length_c= 0;
|
||||||
|
if(!ls.length_d) store.delete(element);
|
||||||
|
out= true;
|
||||||
}
|
}
|
||||||
return false;
|
return out;
|
||||||
}
|
}
|
||||||
function observerRemoved(removedNodes, is_root){
|
function observerRemoved(removedNodes, is_root){
|
||||||
|
let out= false;
|
||||||
for(const element of removedNodes){
|
for(const element of removedNodes){
|
||||||
if(is_root) collectChildren(element).then(observerRemoved);
|
if(is_root) collectChildren(element).then(observerRemoved);
|
||||||
if(!store.has(element)) continue;
|
if(!store.has(element)) continue;
|
||||||
|
|
||||||
const ls= store.get(element);
|
const ls= store.get(element);
|
||||||
ls.disconnected.forEach(listener=> listener(element));
|
if(!ls.length_d) continue;
|
||||||
|
|
||||||
|
element.dispatchEvent(new Event("dde:disconnected"));
|
||||||
|
|
||||||
ls.connected.length= 0;
|
|
||||||
ls.disconnected.length= 0;
|
|
||||||
store.delete(element);
|
store.delete(element);
|
||||||
return true;
|
out= true;
|
||||||
}
|
}
|
||||||
return false;
|
return out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user