UNPKG

flowbite-react

Version:

Official React components built for Flowbite and Tailwind CSS

1 lines 2.77 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 let result = classNames;\n\n for (const [regex, replacement] of regexMap) {\n result = result.replace(regex, replacement);\n }\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 [/\\b(shadow-sm)\\b/g, \"shadow-xs\"],\n [/(?<!-)(shadow)(?!-)\\b/g, \"shadow-sm\"],\n [/\\b(drop-shadow-sm)\\b/g, \"drop-shadow-xs\"],\n [/\\b(drop-shadow)\\b(?!-)/g, \"drop-shadow-sm\"],\n [/\\b(blur-sm)\\b/g, \"blur-xs\"],\n [/\\b(blur)\\b(?!-)/g, \"blur-sm\"],\n [/\\b(rounded-sm)\\b/g, \"rounded-xs\"],\n [/\\b(rounded)\\b(?!-)/g, \"rounded-sm\"],\n // TODO: revisit this - it breaks anything focused using tab\n // [/\\b(outline-none)\\b/g, \"outline-hidden\"],\n [/\\b(ring)\\b(?!-)/g, \"ring-3\"],\n] as const;\n"],"names":[],"mappings":";;AACA,MAAM,KAAK,mBAAmB,IAAI,GAAG,EAAE;AAChC,SAAS,oBAAoB,CAAC,UAAU,EAAE;AACjD,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE;AACjC,IAAI,OAAO,UAAU;AACrB;AACA,EAAE,MAAM,QAAQ,GAAG,UAAU;AAC7B,EAAE,MAAM,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC;AACxC,EAAE,IAAI,UAAU,EAAE;AAClB,IAAI,OAAO,UAAU;AACrB;AACA,EAAE,IAAI,MAAM,GAAG,UAAU;AACzB,EAAE,KAAK,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,IAAI,QAAQ,EAAE;AAC/C,IAAI,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,WAAW,CAAC;AAC/C;AACA,EAAE,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC;AAC7B,EAAE,OAAO,MAAM;AACf;AACA,MAAM,QAAQ,GAAG;AACjB,EAAE,CAAC,kBAAkB,EAAE,WAAW,CAAC;AACnC,EAAE,CAAC,wBAAwB,EAAE,WAAW,CAAC;AACzC,EAAE,CAAC,uBAAuB,EAAE,gBAAgB,CAAC;AAC7C,EAAE,CAAC,yBAAyB,EAAE,gBAAgB,CAAC;AAC/C,EAAE,CAAC,gBAAgB,EAAE,SAAS,CAAC;AAC/B,EAAE,CAAC,kBAAkB,EAAE,SAAS,CAAC;AACjC,EAAE,CAAC,mBAAmB,EAAE,YAAY,CAAC;AACrC,EAAE,CAAC,qBAAqB,EAAE,YAAY,CAAC;AACvC;AACA;AACA,EAAE,CAAC,kBAAkB,EAAE,QAAQ;AAC/B,CAAC;;;;"}