UNPKG

flowbite-react

Version:

Official React components built for Flowbite and Tailwind CSS

1 lines 3.59 kB
{"version":3,"file":"convert-utilities-to-v4.cjs","sources":["../../src/helpers/convert-utilities-to-v4.ts"],"sourcesContent":["const cache = new Map<string, string>();\n\n/**\n * Converts Tailwind CSS v3 utility classes to v4.\n *\n * @param {string} classNames - The string of class names to convert\n * @returns {string} The converted class names string\n */\nexport function convertUtilitiesToV4(classNames: string): string {\n if (!classNames.trim().length) {\n return classNames;\n }\n\n const cacheKey = classNames;\n const cacheValue = cache.get(cacheKey);\n\n if (cacheValue) {\n return cacheValue;\n }\n\n const parts = classNames.split(/(\\s+)/);\n const result = parts\n .map((part) => {\n if (/^\\s+$/.test(part)) {\n return part;\n }\n\n const processed = part;\n const modifierMatch = processed.match(/^([^:]+:)?(.+)$/);\n\n if (modifierMatch) {\n const [, modifier = \"\", baseClass] = modifierMatch;\n\n for (const [regex, replacement] of regexMap) {\n if (regex.test(baseClass)) {\n return modifier + baseClass.replace(regex, replacement);\n }\n }\n }\n\n return processed;\n })\n .join(\"\");\n\n cache.set(cacheKey, result);\n\n return result;\n}\n\n/**\n| v3 | v4 |\n| -------------- | -------------- |\n| shadow-sm | shadow-xs |\n| shadow | shadow-sm |\n| drop-shadow-sm | drop-shadow-xs |\n| drop-shadow | drop-shadow-sm |\n| blur-sm | blur-xs |\n| blur | blur-sm |\n| rounded-sm | rounded-xs |\n| rounded | rounded-sm |\n| outline-none | outline-hidden |\n| ring | ring-3 |\n */\nconst regexMap = [\n [/^shadow-sm$/, \"shadow-xs\"],\n [/^shadow$/, \"shadow-sm\"],\n [/^drop-shadow-sm$/, \"drop-shadow-xs\"],\n [/^drop-shadow$/, \"drop-shadow-sm\"],\n [/^blur-sm$/, \"blur-xs\"],\n [/^blur$/, \"blur-sm\"],\n [/^rounded-sm$/, \"rounded-xs\"],\n [/^rounded$/, \"rounded-sm\"],\n // TODO: revisit this - it breaks anything focused using tab\n // [/^outline-none$/, \"outline-hidden\"],\n [/^ring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