Files
defgov/packages/css/src/styles/utils/cpm.ts
2026-06-08 04:19:23 +08:00

28 lines
623 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export function cpm(...classes: (string[] | string)[]) {
const map = new Map<string, string>();
function dealClass(cls: string) {
// 提取前缀和后缀
const prifix = cls.split("--")[0];
// 使用set覆盖自动新建而不是push
map.set(prifix, cls);
}
classes.forEach((item) => {
// 如果是 string 直接处理
if (typeof item === "string") {
dealClass(item);
} else {
// 否则肯定是 string[]
item.forEach((i) => {
dealClass(i);
});
}
});
const resultString = Array.from(map.values()).join(" ");
return resultString;
}