@prop-styles/core
Version:
The library provides a static method createPropStyles to create Style objects.
135 lines (134 loc) • 3.59 kB
JavaScript
/*!
* @prop-styles/core version 1.0.0-beta
* Author: Capricorncd<capricorncd@qq.com>
* Homepage: https://github.com/capricorncd/prop-styles#readme
* Released on: 2025-05-11 14:01:37 (GMT+0000)
*/
/*!
* @zx-libs/utils version 0.0.5
* Author: Capricorncd<capricorncd@qq.com>
* Homepage: https://github.com/capricorncd/zx-libs/libs/utils#readme
* Released on: 2024-04-30 20:19:27 (GMT+0900)
*/
/*!
* date-utils-2020 v1.1.1
* Author: Capricorncd
* Repository: https://github.com/capricorncd/date-utils-2020#readme
* Released on: 2024/04/02 21:28:40 GMT+0900
*/
function d(t) {
return typeof t == "string" ? /^-?\d+(\.\d+)?$/.test(t) : p(t);
}
function p(t) {
return Number.isFinite(t);
}
const f = /^((-?\d+(\.\d+)?)?([a-z]+|%)?\s*)+$/i, c = /(\d+\s|\s-?\d+(\.\d+)?$)/;
function s(t, n = "px") {
if (d(t))
return `${t}${n}`;
if (t && typeof t == "string") {
const r = t.trim().replace(/\s{2,}/g, " ");
return f.test(r) && c.test(r) ? r.trim().split(" ").map((e) => s(e, n)).join(" ") : r;
}
return "";
}
const m = /^(#[a-f0-9]{3,8}|(rgba?|hsla?|hwb|lab|lch|oklab|oklch|hwb|lch|light-dark)\(.+\))$/i;
function u(t) {
return typeof t != "string" ? !1 : m.test(t);
}
const i = (t, n, r) => !n && n !== 0 ? null : { key: t, value: r ?? String(n) }, h = (t, n) => {
const r = {};
let e;
for (const g of Object.keys(t)) {
if (e = n[g], !e)
continue;
const a = e(t[g], t);
if (a)
if (Array.isArray(a))
a.forEach((o) => {
o && (r[o.key] = o.value);
});
else {
const { key: o, value: l } = a;
r[o] = l;
}
}
return r;
}, b = /^-?\d+(\.\d+)?[a-z]+$/i, x = (t) => typeof t == "string" && b.test(t), y = (t) => d(t) || x(t) ? { key: "borderWidth", value: s(t) } : u(t) ? { key: "borderColor", value: t } : i("border", t), k = {
display: "display",
width: "width",
minWidth: "minWidth",
maxWidth: "maxWidth",
height: "height",
minHeight: "minHeight",
maxHeight: "maxHeight",
flex: "flex",
gap: "gap",
fd: "flexDirection",
ai: "alignItems",
ac: "alignContent",
ji: "justifyItems",
jc: "justifyContent",
ws: "whiteSpace",
p: "padding",
pt: "paddingTop",
pr: "paddingRight",
pb: "paddingBottom",
pl: "paddingLeft",
px: "paddingInline",
py: "paddingBlock",
m: "margin",
mt: "marginTop",
mr: "marginRight",
mb: "marginBottom",
ml: "marginLeft",
mx: "marginInline",
my: "marginBlock",
radius: "borderRadius",
fs: "fontSize",
lh: "lineHeight",
color: "color",
bg: "background",
fw: "fontWeight",
border: "border",
gtc: "gridTemplateColumns",
gtr: "gridTemplateRows",
ta: "textAlign",
position: "position",
top: "top",
right: "right",
bottom: "bottom",
left: "left",
zIndex: "zIndex",
inset: "inset",
transform: "transform"
}, w = {
column: (t) => i("flexDirection", t, "column"),
wrap: (t) => i("flexWrap", t, t === !0 ? "wrap" : String(t)),
breakWord: (t) => i("overflowWrap", t, "break-word"),
// overflow
scroll: (t) => i(
`overflow${typeof t == "string" ? t.toUpperCase() : ""}`,
t,
"auto"
)
}, S = {
...Object.entries(k).reduce((t, [n, r]) => (t[n] = (e) => i(r, e, s(e)), t), {}),
...w,
flex: (t) => i("flex", t),
border: y,
fw: (t) => i("fontWeight", t, String(t)),
gtc: (t) => i("gridTemplateColumns", t, s(t, "fr")),
gtr: (t) => i("gridTemplateRows", t, s(t, "fr")),
zIndex: (t) => i("zIndex", t, String(t))
}, C = (t, n) => {
const r = {
...S,
...n
};
return h(t, r);
};
export {
C as createPropStyles,
i as transform
};