UNPKG

flowbite-react

Version:

Official React components built for Flowbite and Tailwind CSS

1 lines 4.79 kB
{"version":3,"file":"build-class-list.cjs","sources":["../../../src/cli/utils/build-class-list.ts"],"sourcesContent":["import { applyPrefix } from \"../../helpers/apply-prefix\";\nimport { applyPrefixV3 } from \"../../helpers/apply-prefix-v3\";\nimport { convertUtilitiesToV4 } from \"../../helpers/convert-utilities-to-v4\";\nimport { getTailwindVersion } from \"../../helpers/get-tailwind-version\";\nimport { stripDark } from \"../../helpers/strip-dark\";\nimport { CLASS_LIST_MAP, COMPONENT_TO_CLASS_LIST_MAP } from \"../../metadata/class-list\";\nimport { DEPENDENCY_LIST_MAP } from \"../../metadata/dependency-list\";\n\n/**\n * Builds a list of CSS classes based on the provided components and prefix.\n *\n * @param {Object} options - The options for building the class list.\n * @param {string[]} options.components - The components to include in the class list.\n * @param {boolean} options.dark - Whether to include dark mode classes.\n * @param {string} options.prefix - The prefix to apply to the class names.\n * @returns {string[]} The sorted list of CSS classes.\n */\nexport function buildClassList({\n components,\n dark,\n prefix,\n}: {\n components: string[];\n dark: boolean;\n prefix: string;\n}): string[] {\n const version = getTailwindVersion();\n\n let classList: string[] = [];\n\n if (components.includes(\"*\")) {\n classList = [...new Set(Object.values(CLASS_LIST_MAP).flat())];\n } else {\n const resolvedComponents = new Set<string>();\n const visited = new Set<string>();\n\n // eslint-disable-next-line no-inner-declarations\n function resolveDependencies(name: string) {\n if (visited.has(name)) {\n return;\n }\n visited.add(name);\n\n if (name in DEPENDENCY_LIST_MAP) {\n resolvedComponents.add(name);\n\n for (const dependency of DEPENDENCY_LIST_MAP[name as keyof typeof DEPENDENCY_LIST_MAP]) {\n if (dependency in DEPENDENCY_LIST_MAP) {\n resolvedComponents.add(dependency);\n resolveDependencies(dependency);\n }\n }\n }\n }\n\n for (const name of components) {\n resolveDependencies(name);\n }\n\n classList = [\n ...new Set(\n [...resolvedComponents].flatMap((name) => {\n const classListKey = COMPONENT_TO_CLASS_LIST_MAP[name as keyof typeof COMPONENT_TO_CLASS_LIST_MAP];\n const resolvedClassList = CLASS_LIST_MAP[classListKey as keyof typeof CLASS_LIST_MAP];\n\n return resolvedClassList || [];\n }),\n ),\n ];\n }\n\n if (dark === false) {\n classList = classList.map(stripDark).filter(Boolean);\n }\n if (version === 4) {\n classList = classList.map(convertUtilitiesToV4);\n }\n if (prefix?.trim()) {\n classList = classList.map((className) =>\n version === 3 ? applyPrefixV3(className, prefix) : applyPrefix(className, prefix),\n );\n }\n\n return classList.sort();\n}\n"],"names":["getTailwindVersion","classList","CLASS_LIST_MAP","DEPENDENCY_LIST_MAP","COMPONENT_TO_CLASS_LIST_MAP","stripDark","convertUtilitiesToV4","applyPrefixV3","applyPrefix"],"mappings":";;;;;;;;;;AAQO,SAAS,cAAc,CAAC;AAC/B,EAAE,UAAU;AACZ,EAAE,IAAI;AACN,EAAE;AACF,CAAC,EAAE;AACH,EAAE,MAAM,OAAO,GAAGA,qCAAkB,EAAE;AACtC,EAAE,IAAIC,WAAS,GAAG,EAAE;AACpB,EAAE,IAAI,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;AAChC,IAAIA,WAAS,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAACC,wBAAc,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AAClE,GAAG,MAAM;AACT,IAAI,IAAI,oBAAoB,GAAG,SAAS,IAAI,EAAE;AAC9C,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;AAC7B,QAAQ;AACR;AACA,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;AACvB,MAAM,IAAI,IAAI,IAAIC,kCAAmB,EAAE;AACvC,QAAQ,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC;AACpC,QAAQ,KAAK,MAAM,UAAU,IAAIA,kCAAmB,CAAC,IAAI,CAAC,EAAE;AAC5D,UAAU,IAAI,UAAU,IAAIA,kCAAmB,EAAE;AACjD,Y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