Comparing version 2.0.1 to 2.1.0
@@ -1,39 +0,48 @@ | ||
function c(t, ...e) { | ||
return Array.isArray(t) ? t.concat(e) : t.split(/\s+/).concat(e); | ||
function c(e, ...t) { | ||
return Array.isArray(e) ? e.concat(t) : e.split(/\s+/).concat(t); | ||
} | ||
function i(t, e, ...n) { | ||
const s = c(e, ...n); | ||
return t.classList.add(...s), t; | ||
function a(e, t, ...n) { | ||
const s = c(t, ...n); | ||
return e.classList.add(...s), e; | ||
} | ||
function l(t, e, ...n) { | ||
const s = c(e, ...n); | ||
return t.classList.remove(...s), t; | ||
function m(e, t, ...n) { | ||
const s = c(t, ...n); | ||
return e.classList.remove(...s), e; | ||
} | ||
function y(t, e, n) { | ||
return t.classList.toggle(e, n), t; | ||
function y(e, t, n) { | ||
return e.classList.toggle(t, n), e; | ||
} | ||
function a(t, e) { | ||
return window.getComputedStyle(t).getPropertyValue(e); | ||
function d(e) { | ||
return e.charAt(0).toLowerCase() + e.slice(1); | ||
} | ||
function m(t, e, n) { | ||
return t.style.setProperty(e, n), t; | ||
function f(e) { | ||
return d(e).replace(/_/g, "-").replace(/.[A-Z]+/g, (t) => t[0] + "-" + t.slice(1).toLowerCase()); | ||
} | ||
function d(t, e) { | ||
return !t || !e || !("style" in t) || Object.entries(e).forEach(([n, s]) => { | ||
t.style.setProperty(n, s); | ||
}), t; | ||
function p(e, t) { | ||
return window.getComputedStyle(e).getPropertyValue(f(t)); | ||
} | ||
function b(t, e, n) { | ||
return typeof e == "string" ? n ? (m(t, e, n), t) : a(t, e) : d(t, e); | ||
function u(e, t, n) { | ||
if (!e || !t || !n || !("style" in e)) | ||
return e; | ||
let s = ""; | ||
return typeof n == "string" && n.endsWith("!important") && (s = "important", n = n.slice(0, -10).trim()), e.style.setProperty(f(t), n, s), e; | ||
} | ||
function E(t, e, n, s) { | ||
return t.addEventListener(e, n, s), () => { | ||
t.removeEventListener(e, n, s); | ||
function b(e, t) { | ||
return Object.entries(t).forEach(([n, s]) => { | ||
u(e, n, s); | ||
}), e; | ||
} | ||
function E(e, t, n) { | ||
return typeof t == "string" ? n ? u(e, t, n) : p(e, t) : b(e, t); | ||
} | ||
function g(e, t, n, s) { | ||
return e.addEventListener(t, n, s), () => { | ||
e.removeEventListener(t, n, s); | ||
}; | ||
} | ||
function p(t) { | ||
const e = t; | ||
return e.$addClass = i.bind(null, e), e.$removeClass = l.bind(null, e), e.$toggleClass = y.bind(null, e), e.$css = b.bind(null, e), e.$on = E.bind(null, e), e.$text = function(n) { | ||
function A(e) { | ||
const t = e; | ||
return t.$addClass = a.bind(null, t), t.$removeClass = m.bind(null, t), t.$toggleClass = y.bind(null, t), t.$css = E.bind(null, t), t.$on = g.bind(null, t), t.$text = function(n) { | ||
return typeof n > "u" ? this.textContent || "" : (this.textContent = n, this); | ||
}, e; | ||
}, t; | ||
} | ||
@@ -45,8 +54,8 @@ /** | ||
*/ | ||
function A(t, e, n) { | ||
function C(e, t, n) { | ||
let s = null; | ||
if (typeof t == "string") | ||
s = document.createElement(t); | ||
else if (typeof t == "object" && (t instanceof Element || t instanceof SVGElement)) | ||
s = t; | ||
if (typeof e == "string") | ||
s = document.createElement(e); | ||
else if (typeof e == "object" && (e instanceof Element || e instanceof SVGElement)) | ||
s = e; | ||
else | ||
@@ -58,28 +67,28 @@ throw new TypeError( | ||
return null; | ||
const o = p(s); | ||
return (typeof e == "string" || e instanceof Element) && (e = [e]), Array.isArray(e) ? o.replaceChildren(...e) : typeof e == "object" && e !== null && Object.entries(e).forEach(([u, r]) => { | ||
if (typeof r > "u") { | ||
o.removeAttribute(u); | ||
const r = A(s); | ||
return (typeof t == "string" || t instanceof Element) && (t = [t]), Array.isArray(t) ? r.replaceChildren(...t) : typeof t == "object" && t !== null && Object.entries(t).forEach(([i, o]) => { | ||
if (typeof o > "u") { | ||
r.removeAttribute(i); | ||
return; | ||
} | ||
if (u === "style") | ||
typeof r == "string" ? o.style && (o.style.cssText = r) : o.$css(r); | ||
else if (u === "class") | ||
o.$addClass(r); | ||
else if (u.startsWith("on")) { | ||
const f = u.slice(2).toLowerCase(); | ||
o.$on(f, r); | ||
if (i === "style") | ||
typeof o == "string" ? r.style && (r.style.cssText = o) : r.$css(o); | ||
else if (i === "class") | ||
r.$addClass(o); | ||
else if (i.startsWith("on")) { | ||
const l = i.slice(2).toLowerCase(); | ||
r.$on(l, o); | ||
} else | ||
o.setAttribute(u, r); | ||
}), (typeof n == "string" || n instanceof Element) && (n = [n]), Array.isArray(n) && o.replaceChildren(...n), o; | ||
r.setAttribute(i, o); | ||
}), (typeof n == "string" || n instanceof Element) && (n = [n]), Array.isArray(n) && r.replaceChildren(...n), r; | ||
} | ||
const g = document.querySelector.bind(document), $ = document.querySelectorAll.bind(document); | ||
const L = document.querySelector.bind(document), $ = document.querySelectorAll.bind(document); | ||
export { | ||
A as createElement, | ||
A as h, | ||
g as q, | ||
C as createElement, | ||
C as h, | ||
L as q, | ||
$ as qq, | ||
g as querySelector, | ||
L as querySelector, | ||
$ as querySelectorAll | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -16,7 +16,16 @@ "use strict"; | ||
function computedStyleValue(el, prop) { | ||
return window.getComputedStyle(el).getPropertyValue(prop); | ||
return window.getComputedStyle(el).getPropertyValue((0, string_js_1.kebabCase)(prop)); | ||
} | ||
exports.computedStyleValue = computedStyleValue; | ||
function setStyle(el, prop, value) { | ||
el.style.setProperty(prop, value); | ||
if (!el || !prop || !value) | ||
return el; | ||
if (!('style' in el)) | ||
return el; | ||
let priority = ''; | ||
if (typeof value === 'string' && value.endsWith('!important')) { | ||
priority = 'important'; | ||
value = value.slice(0, -10).trim(); | ||
} | ||
el.style.setProperty((0, string_js_1.kebabCase)(prop), value, priority); | ||
return el; | ||
@@ -26,8 +35,4 @@ } | ||
function setStyles(el, styles) { | ||
if (!el || !styles) | ||
return el; | ||
if (!('style' in el)) | ||
return el; | ||
Object.entries(styles).forEach(([key, value]) => { | ||
el.style.setProperty(key, value); | ||
setStyle(el, key, value); | ||
}); | ||
@@ -40,4 +45,3 @@ return el; | ||
if (value) { | ||
setStyle(el, prop, value); | ||
return el; | ||
return setStyle(el, prop, value); | ||
} | ||
@@ -44,0 +48,0 @@ return computedStyleValue(el, prop); |
{ | ||
"name": "dom-plus", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Very simple DOM generator with types declaration", | ||
@@ -47,4 +47,5 @@ "main": "lib/index.js", | ||
"build": "npm run clear && vite build && tsc", | ||
"clear": "rimraf dist lib" | ||
"clear": "rimraf dist lib", | ||
"prepublish": "npm run build" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
83566
685