1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2024-11-22 07:49:38 +01:00

♻️ 🔨 🐛 e.g. better namespace #18

This commit is contained in:
Jan Andrle 2023-09-19 09:30:21 +02:00
parent 9c5ac96ab8
commit 1df797e316
Signed by: jaandrle
GPG Key ID: B3A25AED155AFFAB
9 changed files with 64 additions and 59 deletions

View File

@ -43,8 +43,8 @@
var S = "html"; var S = "html";
function oe(e) { function oe(e) {
return S = e === "svg" ? "http://www.w3.org/2000/svg" : e, { return S = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(t) { append(...t) {
return S = "html", t; return S = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t);
} }
}; };
} }
@ -266,10 +266,10 @@
var l = /* @__PURE__ */ new WeakMap(); var l = /* @__PURE__ */ new WeakMap();
function g(e, t) { function g(e, t) {
if (typeof e != "function") if (typeof e != "function")
return z(e, t); return F(e, t);
if (L(e)) if (L(e))
return e; return e;
let r = z(""), n = () => r(e()); let r = F(""), n = () => r(e());
return l.set(n, /* @__PURE__ */ new Set([r])), G(n), r; return l.set(n, /* @__PURE__ */ new Set([r])), G(n), r;
} }
g.action = function(e, t, ...r) { g.action = function(e, t, ...r) {
@ -322,7 +322,7 @@
}; };
return P(e, a), a(e()), o; return P(e, a), a(e()), o;
}; };
var F = { var z = {
isTextContent(e) { isTextContent(e) {
return w(e) === "string" || L(e) && w(X(e)) === "string"; return w(e) === "string" || L(e) && w(X(e)) === "string";
}, },
@ -330,7 +330,7 @@
return L(r) ? (P(r, (o) => n([t, o])), r()) : r; return L(r) ? (P(r, (o) => n([t, o])), r()) : r;
} }
}; };
function z(e, t) { function F(e, t) {
let r = (...n) => n.length ? Q(r, n[0]) : K(r); let r = (...n) => n.length ? Q(r, n[0]) : K(r);
return B(r, e, t); return B(r, e, t);
} }
@ -381,8 +381,8 @@
return e[d].listeners.delete(t); return e[d].listeners.delete(t);
} }
// src/signals.js // signals.js
_(F); _(z);
globalThis.dde= { globalThis.dde= {
S: g, S: g,

36
dist/dde.js vendored
View File

@ -36,11 +36,11 @@
} }
// src/dom.js // src/dom.js
var m = "html"; var v = "html";
function I(e) { function I(e) {
return m = e === "svg" ? "http://www.w3.org/2000/svg" : e, { return v = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(t) { append(...t) {
return m = "html", t; return v = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t);
} }
}; };
} }
@ -57,8 +57,8 @@
case e === "<>": case e === "<>":
c = E(document.createDocumentFragment(), t); c = E(document.createDocumentFragment(), t);
break; break;
case m !== "html": case v !== "html":
c = E(document.createElementNS(m, e), t); c = E(document.createElementNS(v, e), t);
break; break;
case !c: case !c:
c = E(document.createElement(e), t); c = E(document.createElement(e), t);
@ -81,11 +81,11 @@
if (typeof f == "object") if (typeof f == "object")
switch (s) { switch (s) {
case "style": case "style":
return v(f, N.bind(null, e.style, "Property")); return m(f, N.bind(null, e.style, "Property"));
case "dataset": case "dataset":
return v(f, y.bind(null, e.dataset)); return m(f, y.bind(null, e.dataset));
case "ariaset": case "ariaset":
return v(f, (x, b) => c("aria-" + x, b)); return m(f, (x, b) => c("aria-" + x, b));
case "classList": case "classList":
return j(e, f); return j(e, f);
default: default:
@ -107,7 +107,7 @@
}), e; }), e;
} }
function j(e, t) { function j(e, t) {
return typeof t != "object" || v( return typeof t != "object" || m(
t, t,
(r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n) (r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n)
), e; ), e;
@ -122,16 +122,16 @@
let n = e.nodeName + "," + t; let n = e.nodeName + "," + t;
if (h.has(n)) if (h.has(n))
return h.get(n); return h.get(n);
let [c, a, s] = _(e, t), f = !p(c.set); let [c, a, s] = D(e, t), f = !p(c.set);
return (!f || a) && h.set(s === HTMLElement.prototype ? r : n, f), f; return (!f || a) && h.set(s === HTMLElement.prototype ? r : n, f), f;
} }
function _(e, t, r = 0) { function D(e, t, r = 0) {
if (e = Object.getPrototypeOf(e), !e) if (e = Object.getPrototypeOf(e), !e)
return [{}, r, e]; return [{}, r, e];
let n = Object.getOwnPropertyDescriptor(e, t); let n = Object.getOwnPropertyDescriptor(e, t);
return n ? [n, r, e] : _(e, t, r + 1); return n ? [n, r, e] : D(e, t, r + 1);
} }
function v(e, t) { function m(e, t) {
return Object.entries(e).forEach(([r, n]) => t(r, n)); return Object.entries(e).forEach(([r, n]) => t(r, n));
} }
function N(e, t, r, n) { function N(e, t, r, n) {
@ -146,18 +146,18 @@
let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t); let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t);
return e.dispatchEvent(n); return e.dispatchEvent(n);
} }
function D(e, t, r) { function _(e, t, r) {
return function(c) { return function(c) {
return c.addEventListener(e, t, r), c; return c.addEventListener(e, t, r), c;
}; };
} }
var w = P(); var w = P();
D.connected = function(e, t) { _.connected = function(e, t) {
return function(n) { return function(n) {
return typeof n.connectedCallback == "function" ? (n.addEventListener("dde:connected", e, t), n) : (L(t && t.signal, () => w.offConnected(n, e)) && (n.isConnected ? e(new Event("dde:connected")) : w.onConnected(n, e)), n); return typeof n.connectedCallback == "function" ? (n.addEventListener("dde:connected", e, t), n) : (L(t && t.signal, () => w.offConnected(n, e)) && (n.isConnected ? e(new Event("dde:connected")) : w.onConnected(n, e)), n);
}; };
}; };
D.disconnected = function(e, t) { _.disconnected = function(e, t) {
return function(n) { return function(n) {
return typeof n.disconnectedCallback == "function" ? (n.addEventListener("dde:disconnected", e, t), n) : (L(t && t.signal, () => w.offDisconnected(n, e)) && w.onDisconnected(n, e), n); return typeof n.disconnectedCallback == "function" ? (n.addEventListener("dde:disconnected", e, t), n) : (L(t && t.signal, () => w.offDisconnected(n, e)) && w.onDisconnected(n, e), n);
}; };
@ -258,7 +258,7 @@
el: Z, el: Z,
empty: B, empty: B,
namespace: I, namespace: I,
on: D, on: _,
registerReactivity: T registerReactivity: T
}; };

View File

@ -41,8 +41,8 @@ function $(e, t, r) {
var S = "html"; var S = "html";
function oe(e) { function oe(e) {
return S = e === "svg" ? "http://www.w3.org/2000/svg" : e, { return S = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(t) { append(...t) {
return S = "html", t; return S = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t);
} }
}; };
} }
@ -264,10 +264,10 @@ function L(e) {
var l = /* @__PURE__ */ new WeakMap(); var l = /* @__PURE__ */ new WeakMap();
function g(e, t) { function g(e, t) {
if (typeof e != "function") if (typeof e != "function")
return z(e, t); return F(e, t);
if (L(e)) if (L(e))
return e; return e;
let r = z(""), n = () => r(e()); let r = F(""), n = () => r(e());
return l.set(n, /* @__PURE__ */ new Set([r])), G(n), r; return l.set(n, /* @__PURE__ */ new Set([r])), G(n), r;
} }
g.action = function(e, t, ...r) { g.action = function(e, t, ...r) {
@ -320,7 +320,7 @@ g.el = function(e, t) {
}; };
return P(e, a), a(e()), o; return P(e, a), a(e()), o;
}; };
var F = { var z = {
isTextContent(e) { isTextContent(e) {
return w(e) === "string" || L(e) && w(X(e)) === "string"; return w(e) === "string" || L(e) && w(X(e)) === "string";
}, },
@ -328,7 +328,7 @@ var F = {
return L(r) ? (P(r, (o) => n([t, o])), r()) : r; return L(r) ? (P(r, (o) => n([t, o])), r()) : r;
} }
}; };
function z(e, t) { function F(e, t) {
let r = (...n) => n.length ? Q(r, n[0]) : K(r); let r = (...n) => n.length ? Q(r, n[0]) : K(r);
return B(r, e, t); return B(r, e, t);
} }
@ -379,8 +379,8 @@ function U(e, t) {
return e[d].listeners.delete(t); return e[d].listeners.delete(t);
} }
// src/signals.js // signals.js
_(F); _(z);
export { export {
g as S, g as S,
y as assign, y as assign,

36
dist/esm.js vendored
View File

@ -34,11 +34,11 @@ function R(e, t, r) {
} }
// src/dom.js // src/dom.js
var m = "html"; var v = "html";
function I(e) { function I(e) {
return m = e === "svg" ? "http://www.w3.org/2000/svg" : e, { return v = e === "svg" ? "http://www.w3.org/2000/svg" : e, {
append(t) { append(...t) {
return m = "html", t; return v = "html", t.length === 1 ? t[0] : document.createDocumentFragment().append(...t);
} }
}; };
} }
@ -55,8 +55,8 @@ function Z(e, t, ...r) {
case e === "<>": case e === "<>":
c = E(document.createDocumentFragment(), t); c = E(document.createDocumentFragment(), t);
break; break;
case m !== "html": case v !== "html":
c = E(document.createElementNS(m, e), t); c = E(document.createElementNS(v, e), t);
break; break;
case !c: case !c:
c = E(document.createElement(e), t); c = E(document.createElement(e), t);
@ -79,11 +79,11 @@ function E(e, ...t) {
if (typeof f == "object") if (typeof f == "object")
switch (s) { switch (s) {
case "style": case "style":
return v(f, N.bind(null, e.style, "Property")); return m(f, N.bind(null, e.style, "Property"));
case "dataset": case "dataset":
return v(f, y.bind(null, e.dataset)); return m(f, y.bind(null, e.dataset));
case "ariaset": case "ariaset":
return v(f, (x, b) => c("aria-" + x, b)); return m(f, (x, b) => c("aria-" + x, b));
case "classList": case "classList":
return j(e, f); return j(e, f);
default: default:
@ -105,7 +105,7 @@ function E(e, ...t) {
}), e; }), e;
} }
function j(e, t) { function j(e, t) {
return typeof t != "object" || v( return typeof t != "object" || m(
t, t,
(r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n) (r, n) => e.classList.toggle(r, n === -1 ? void 0 : !!n)
), e; ), e;
@ -120,16 +120,16 @@ function M(e, t) {
let n = e.nodeName + "," + t; let n = e.nodeName + "," + t;
if (h.has(n)) if (h.has(n))
return h.get(n); return h.get(n);
let [c, a, s] = _(e, t), f = !p(c.set); let [c, a, s] = D(e, t), f = !p(c.set);
return (!f || a) && h.set(s === HTMLElement.prototype ? r : n, f), f; return (!f || a) && h.set(s === HTMLElement.prototype ? r : n, f), f;
} }
function _(e, t, r = 0) { function D(e, t, r = 0) {
if (e = Object.getPrototypeOf(e), !e) if (e = Object.getPrototypeOf(e), !e)
return [{}, r, e]; return [{}, r, e];
let n = Object.getOwnPropertyDescriptor(e, t); let n = Object.getOwnPropertyDescriptor(e, t);
return n ? [n, r, e] : _(e, t, r + 1); return n ? [n, r, e] : D(e, t, r + 1);
} }
function v(e, t) { function m(e, t) {
return Object.entries(e).forEach(([r, n]) => t(r, n)); return Object.entries(e).forEach(([r, n]) => t(r, n));
} }
function N(e, t, r, n) { function N(e, t, r, n) {
@ -144,18 +144,18 @@ function V(e, t, ...r) {
let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t); let n = r.length ? new CustomEvent(t, { detail: r[0] }) : new Event(t);
return e.dispatchEvent(n); return e.dispatchEvent(n);
} }
function D(e, t, r) { function _(e, t, r) {
return function(c) { return function(c) {
return c.addEventListener(e, t, r), c; return c.addEventListener(e, t, r), c;
}; };
} }
var w = P(); var w = P();
D.connected = function(e, t) { _.connected = function(e, t) {
return function(n) { return function(n) {
return typeof n.connectedCallback == "function" ? (n.addEventListener("dde:connected", e, t), n) : (L(t && t.signal, () => w.offConnected(n, e)) && (n.isConnected ? e(new Event("dde:connected")) : w.onConnected(n, e)), n); return typeof n.connectedCallback == "function" ? (n.addEventListener("dde:connected", e, t), n) : (L(t && t.signal, () => w.offConnected(n, e)) && (n.isConnected ? e(new Event("dde:connected")) : w.onConnected(n, e)), n);
}; };
}; };
D.disconnected = function(e, t) { _.disconnected = function(e, t) {
return function(n) { return function(n) {
return typeof n.disconnectedCallback == "function" ? (n.addEventListener("dde:disconnected", e, t), n) : (L(t && t.signal, () => w.offDisconnected(n, e)) && w.onDisconnected(n, e), n); return typeof n.disconnectedCallback == "function" ? (n.addEventListener("dde:disconnected", e, t), n) : (L(t && t.signal, () => w.offDisconnected(n, e)) && w.onDisconnected(n, e), n);
}; };
@ -255,6 +255,6 @@ export {
Z as el, Z as el,
B as empty, B as empty,
I as namespace, I as namespace,
D as on, _ as on,
T as registerReactivity T as registerReactivity
}; };

View File

@ -1,2 +1,2 @@
export * from "./index.js"; export * from "./index.js";
export * from "./src/signals.js"; export * from "./signals.js";

View File

@ -1,6 +1,6 @@
{ {
"name": "deka-dom-el", "name": "deka-dom-el",
"version": "0.2.0", "version": "0.2.1",
"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",

View File

@ -1,4 +1,4 @@
export { S, isSignal } from "src/signals-lib.js"; export { S, isSignal } from "./src/signals-lib.js";
import { signals_config } from "src/signals-lib.js"; import { signals_config } from "./src/signals-lib.js";
import { registerReactivity } from "src/signals-common.js"; import { registerReactivity } from "./src/signals-common.js";
registerReactivity(signals_config); registerReactivity(signals_config);

View File

@ -5,7 +5,12 @@ let namespace_curr= "html";
export function namespace(namespace){ export function namespace(namespace){
namespace_curr= namespace==="svg" ? "http://www.w3.org/2000/svg" : namespace; namespace_curr= namespace==="svg" ? "http://www.w3.org/2000/svg" : namespace;
return { return {
append(el){ namespace_curr= "html"; return el; } append(...el){
namespace_curr= "html";
if(el.length===1) return el[0];
const f= document.createDocumentFragment();
return f.append(...el);
}
}; };
} }
export function createElement(tag, attributes, ...connect){ export function createElement(tag, attributes, ...connect){

View File

@ -1,5 +1,5 @@
import { el } from "../../index.js"; import { el } from "../../index.js";
import { S } from "../../src/signals.js"; import { S } from "../../signals.js";
const { hasOwnProperty }= Object.prototype; const { hasOwnProperty }= Object.prototype;
const store= attrsPropsToSignals([ "test" ]); const store= attrsPropsToSignals([ "test" ]);