@serendie/ui
Version:
Adaptive UI component library as part of Serendie Design System by Mitsubishi Electric
215 lines (214 loc) • 6.4 kB
JavaScript
function p(t) {
return typeof t == "object" && t != null && !Array.isArray(t);
}
var P = (t) => typeof t == "object" && t !== null;
function v(t) {
return Object.fromEntries(Object.entries(t ?? {}).filter(([n, r]) => r !== void 0));
}
var V = (t) => t === "base";
function R(t) {
return t.slice().filter((n) => !V(n));
}
function b(t) {
return String.fromCharCode(t + (t > 25 ? 39 : 97));
}
function _(t) {
let n = "", r;
for (r = Math.abs(t); r > 52; r = r / 52 | 0)
n = b(r % 52) + n;
return b(r % 52) + n;
}
function z(t, n) {
let r = n.length;
for (; r; )
t = t * 33 ^ n.charCodeAt(--r);
return t;
}
function N(t) {
return _(z(5381, t) >>> 0);
}
var O = /\s*!(important)?/i;
function q(t) {
return typeof t == "string" ? O.test(t) : !1;
}
function $(t) {
return typeof t == "string" ? t.replace(O, "").trim() : t;
}
function rt(t) {
return typeof t == "string" ? t.replaceAll(" ", "_") : t;
}
var g = (t) => {
const n = /* @__PURE__ */ new Map();
return (...s) => {
const e = JSON.stringify(s);
if (n.has(e))
return n.get(e);
const o = t(...s);
return n.set(e, o), o;
};
}, M = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
function j(...t) {
return t.reduce((n, r) => (r && Object.keys(r).forEach((s) => {
if (M.has(s))
return;
const e = n[s], o = r[s];
p(e) && p(o) ? n[s] = j(e, o) : n[s] = o;
}), n), {});
}
var k = (t) => t != null;
function y(t, n, r = {}) {
const { stop: s, getKey: e } = r;
function o(i, a = []) {
if (P(i)) {
const f = {};
for (const [c, l] of Object.entries(i)) {
const u = (e == null ? void 0 : e(c, l)) ?? c, m = [...a, u];
if (s != null && s(i, m))
return n(i, a);
const h = o(l, m);
k(h) && (f[u] = h);
}
return f;
}
return n(i, a);
}
return o(t);
}
function B(t, n) {
return Array.isArray(t) ? t.map((r) => n(r)) : p(t) ? y(t, (r) => n(r)) : n(t);
}
function H(t, n) {
return t.reduce(
(r, s, e) => {
const o = n[e];
return s != null && (r[o] = s), r;
},
{}
);
}
function A(t, n, r = !0) {
const { utility: s, conditions: e } = n, { hasShorthand: o, resolveShorthand: i } = s;
return y(
t,
(a) => Array.isArray(a) ? H(a, e.breakpoints.keys) : a,
{
stop: (a) => Array.isArray(a),
getKey: r ? (a) => o ? i(a) : a : void 0
}
);
}
var F = {
shift: (t) => t,
finalize: (t) => t,
breakpoints: { keys: [] }
}, L = (t) => typeof t == "string" ? t.replaceAll(/[\n\s]+/g, " ") : t;
function et(t) {
const { utility: n, hash: r, conditions: s = F } = t, e = (i) => [n.prefix, i].filter(Boolean).join("-"), o = (i, a) => {
let f;
if (r) {
const c = [...s.finalize(i), a];
f = e(n.toHash(c, N));
} else
f = [...s.finalize(i), e(a)].join(":");
return f;
};
return g(({ base: i, ...a } = {}) => {
const f = Object.assign(a, i), c = A(f, t), l = /* @__PURE__ */ new Set();
return y(c, (u, m) => {
if (u == null)
return;
const h = q(u), [w, ...S] = s.shift(m), x = R(S), E = n.transform(w, $(L(u)));
let d = o(x, E.className);
h && (d = `${d}!`), l.add(d);
}), Array.from(l).join(" ");
});
}
function T(...t) {
return t.flat().filter((n) => p(n) && Object.keys(v(n)).length > 0);
}
function st(t) {
function n(e) {
const o = T(...e);
return o.length === 1 ? o : o.map((i) => A(i, t));
}
function r(...e) {
return j(...n(e));
}
function s(...e) {
return Object.assign({}, ...n(e));
}
return { mergeCss: g(r), assignCss: s };
}
var U = /([A-Z])/g, I = /^ms-/, ot = g((t) => t.startsWith("--") ? t : t.replace(U, "-$1").replace(I, "-ms-").toLowerCase()), W = ["min", "max", "clamp", "calc"], D = new RegExp(`^(${W.join("|")})\\(.*\\)`), G = (t) => typeof t == "string" && D.test(t), J = "cm,mm,Q,in,pc,pt,px,em,ex,ch,rem,lh,rlh,vw,vh,vmin,vmax,vb,vi,svw,svh,lvw,lvh,dvw,dvh,cqw,cqh,cqi,cqb,cqmin,cqmax,%", K = `(?:${J.split(",").join("|")})`, Q = new RegExp(`^[+-]?[0-9]*.?[0-9]+(?:[eE][+-]?[0-9]+)?${K}$`), Z = (t) => typeof t == "string" && Q.test(t), X = (t) => typeof t == "string" && /^var\(--.+\)$/.test(t), it = {
map: B,
isCssFunction: G,
isCssVar: X,
isCssUnit: Z
}, at = (t, n) => {
if (!(t != null && t.defaultValues))
return n;
const r = typeof t.defaultValues == "function" ? t.defaultValues(n) : t.defaultValues;
return Object.assign({}, r, v(n));
}, ct = (t = {}) => {
const n = (e) => {
var o;
return {
className: [t.className, e].filter(Boolean).join("__"),
base: ((o = t.base) == null ? void 0 : o[e]) ?? {},
variants: {},
defaultVariants: t.defaultVariants ?? {},
compoundVariants: t.compoundVariants ? Y(t.compoundVariants, e) : []
};
}, s = (t.slots ?? []).map((e) => [e, n(e)]);
for (const [e, o] of Object.entries(t.variants ?? {}))
for (const [i, a] of Object.entries(o))
s.forEach(([f, c]) => {
var l;
(l = c.variants)[e] ?? (l[e] = {}), c.variants[e][i] = a[f] ?? {};
});
return Object.fromEntries(s);
}, Y = (t, n) => t.filter((r) => r.css[n]).map((r) => ({ ...r, css: r.css[n] }));
function ft(t, ...n) {
const r = Object.getOwnPropertyDescriptors(t), s = Object.keys(r), e = (i) => {
const a = {};
for (let f = 0; f < i.length; f++) {
const c = i[f];
r[c] && (Object.defineProperty(a, c, r[c]), delete r[c]);
}
return a;
}, o = (i) => e(Array.isArray(i) ? i : s.filter(i));
return n.map(o).concat(e(s));
}
var lt = (...t) => {
const n = t.reduce((r, s) => (s && s.forEach((e) => r.add(e)), r), /* @__PURE__ */ new Set([]));
return Array.from(n);
}, C = ["htmlSize", "htmlTranslate", "htmlWidth", "htmlHeight"];
function tt(t) {
return C.includes(t) ? t.replace("html", "").toLowerCase() : t;
}
function nt(t) {
return Object.fromEntries(Object.entries(t).map(([n, r]) => [tt(n), r]));
}
nt.keys = C;
export {
v as compact,
et as createCss,
st as createMergeCss,
R as filterBaseConditions,
at as getPatternStyles,
Y as getSlotCompoundVariant,
ct as getSlotRecipes,
ot as hypenateProperty,
V as isBaseCondition,
p as isObject,
B as mapObject,
g as memo,
j as mergeProps,
nt as normalizeHTMLProps,
it as patternFns,
ft as splitProps,
N as toHash,
lt as uniq,
y as walkObject,
rt as withoutSpace
};