UNPKG

eslint-plugin-better-tailwindcss

Version:

auto-wraps tailwind classes after a certain print width or class count into multiple lines to improve readability.

54 lines 2.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getShorthandClasses = getShorthandClasses; const class_variants_async_v4_js_1 = require("./class-variants.async.v4.js"); const prefix_async_v4_js_1 = require("./prefix.async.v4.js"); const shorthand_classes_async_js_1 = require("./shorthand-classes.async.js"); const unregistered_classes_async_v4_js_1 = require("./unregistered-classes.async.v4.js"); function getShorthandClasses(context, classes) { const variants = (0, class_variants_async_v4_js_1.getClassVariants)(context, classes); const prefix = (0, prefix_async_v4_js_1.getPrefix)(context); const separator = ":"; const rawMap = classes.reduce((acc, className) => { const classVariants = variants.find(([name]) => name === className)?.[1] ?? []; let base = className .replace(classVariants.join(separator), "") .replace(prefix, "") .replace(/^:/, ""); const isNegative = base.startsWith("-"); base = base.replace(/^-/, ""); const isImportant = base.endsWith("!"); base = base.replace(/!$/, ""); acc[base] = { className, isImportant, isNegative, variants: classVariants }; return acc; }, {}); return (0, shorthand_classes_async_js_1.getShorthands)(Object.keys(rawMap)) .reduce((acc, shorthandGroups) => { for (const [longhands, shorthands] of shorthandGroups) { const { isImportant, isNegative, variants } = rawMap[longhands[0]]; const important = isImportant ? "!" : ""; const negative = isNegative ? "-" : ""; const longhandClasses = longhands.map(longhand => rawMap[longhand].className); const shorthandClasses = shorthands.map(shorthand => [ prefix, ...variants, [ negative, shorthand, important ].join("") ].filter(chunk => !!chunk).join(separator)); if (longhands.some(longhand => rawMap[longhand].isImportant !== isImportant) || longhands.some(longhand => rawMap[longhand].isNegative !== isNegative) || longhands.some(longhand => rawMap[longhand].variants.join(separator) !== variants.join(separator)) || shorthandClasses.length === 0 || (0, unregistered_classes_async_v4_js_1.getUnregisteredClasses)(context, shorthandClasses).length > 0) { continue; } acc.push([longhandClasses, shorthandClasses]); break; } return acc; }, []); } //# sourceMappingURL=shorthand-classes.async.v4.js.map