fui-fancyui
Version:
FancyUI Libary
31 lines (30 loc) • 1.28 kB
JavaScript
import y from "../getThemeOrValueAsCss/getThemeOrValueAsCss.js";
const b = (n) => {
const { borderRadius: r, padding: a, inset: p = !1, offset: h } = n;
let d;
typeof r == "object" && !Array.isArray(r) ? d = [r.t, r.r, r.b, r.l] : d = Array.isArray(r) ? r : [r];
let l;
typeof a == "object" && !Array.isArray(a) ? l = [a.t, a.r, a.b, a.l] : l = Array.isArray(a) ? a : [a];
const o = [], i = [];
if (d.forEach((s) => {
const e = y(s, "spacing"), t = e !== "0" ? e : `${e}px`;
i.push(t);
}), l.forEach((s) => {
const e = y(s, "spacing"), t = e !== "0" ? e : `${e}px`;
o.push(t);
}), i.length !== o.length && !(i.length > 0 && o.length === 1))
return console.error(
"borderRadius and padding should have the same number of values or borderRadius should have more than 1 value and padding should have 1 value"
), "";
const f = h ? ` + ${h}px` : "";
return i.map((s, e) => {
const t = A(s) ? s : "0px", g = o[e], u = A(g) ? g : "0px", c = p && parseFloat(u) < 0 ? ` + ${Math.abs(parseFloat(u))}px` : ` ${p ? "-" : "+"} ${u}`;
return c.trim() === "+" || c.trim() === "-" ? `${t}${f}` : `calc(${t}${c}${f})`;
}).join(" ");
};
function A(n) {
return typeof n == "string" && n.trim() !== "";
}
export {
b as default
};