mm
This commit is contained in:
27
packages/css/src/styles/utils/cpm.ts
Normal file
27
packages/css/src/styles/utils/cpm.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user