import { defaultPrefixList } from "./prefix-list"; function prefixParce(cls: string): { prefix: string; rest: string } { const index = cls.indexOf("-"); if (index === -1) return { prefix: "", rest: cls }; const prefix = cls.slice(0, index); const rest = cls.slice(index + 1); return { prefix, rest }; } export function cpm( options?: { externalPrefixList?: string[] }, ...classes: (string | string[])[] ): string { const map = new Map(); const mergedPrefixList: string[] = [ ...new Set([...(options?.externalPrefixList ?? []), ...defaultPrefixList]), ]; classes.forEach((item) => { if (Array.isArray(item)) { item.forEach((i) => { const { prefix, rest } = prefixParce(i); if (mergedPrefixList.includes(prefix)) { map.set(prefix, rest); } }); return; } if (typeof item === "string") { const { prefix, rest } = prefixParce(item); if (mergedPrefixList.includes(prefix)) { map.set(prefix, rest); } } }); return Array.from(map.entries()) .map(([prefix, rest]) => `${prefix}-${rest}`) .join(" "); }