tailwind-merge
Version:
Merge Tailwind CSS classes without style conflicts
1,531 lines (1,527 loc) • 91.6 kB
JavaScript
'use strict';
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
Object.defineProperty(exports, Symbol.toStringTag, {
value: 'Module'
});
var CLASS_PART_SEPARATOR = '-';
var createClassGroupUtils = function createClassGroupUtils(config) {
var classMap = createClassMap(config);
var conflictingClassGroups = config.conflictingClassGroups,
conflictingClassGroupModifiers = config.conflictingClassGroupModifiers;
var getClassGroupId = function getClassGroupId(className) {
var classParts = className.split(CLASS_PART_SEPARATOR);
// Classes like `-inset-1` produce an empty string as first classPart. We assume that classes for negative values are used correctly and remove it from classParts.
if (classParts[0] === '' && classParts.length !== 1) {
classParts.shift();
}
return _getGroupRecursive(classParts, classMap) || getGroupIdForArbitraryProperty(className);
};
var getConflictingClassGroupIds = function getConflictingClassGroupIds(classGroupId, hasPostfixModifier) {
var conflicts = conflictingClassGroups[classGroupId] || [];
if (hasPostfixModifier && conflictingClassGroupModifiers[classGroupId]) {
return [].concat(conflicts, conflictingClassGroupModifiers[classGroupId]);
}
return conflicts;
};
return {
getClassGroupId: getClassGroupId,
getConflictingClassGroupIds: getConflictingClassGroupIds
};
};
var _getGroupRecursive = function getGroupRecursive(classParts, classPartObject) {
var _classPartObject$vali;
if (classParts.length === 0) {
return classPartObject.classGroupId;
}
var currentClassPart = classParts[0];
var nextClassPartObject = classPartObject.nextPart.get(currentClassPart);
var classGroupFromNextClassPart = nextClassPartObject ? _getGroupRecursive(classParts.slice(1), nextClassPartObject) : undefined;
if (classGroupFromNextClassPart) {
return classGroupFromNextClassPart;
}
if (classPartObject.validators.length === 0) {
return undefined;
}
var classRest = classParts.join(CLASS_PART_SEPARATOR);
return (_classPartObject$vali = classPartObject.validators.find(function (_ref) {
var validator = _ref.validator;
return validator(classRest);
})) == null ? void 0 : _classPartObject$vali.classGroupId;
};
var arbitraryPropertyRegex = /^\[(.+)\]$/;
var getGroupIdForArbitraryProperty = function getGroupIdForArbitraryProperty(className) {
if (arbitraryPropertyRegex.test(className)) {
var arbitraryPropertyClassName = arbitraryPropertyRegex.exec(className)[1];
var property = arbitraryPropertyClassName == null ? void 0 : arbitraryPropertyClassName.substring(0, arbitraryPropertyClassName.indexOf(':'));
if (property) {
// I use two dots here because one dot is used as prefix for class groups in plugins
return 'arbitrary..' + property;
}
}
};
/**
* Exported for testing only
*/
var createClassMap = function createClassMap(config) {
var theme = config.theme,
classGroups = config.classGroups;
var classMap = {
nextPart: new Map(),
validators: []
};
for (var classGroupId in classGroups) {
_processClassesRecursively(classGroups[classGroupId], classMap, classGroupId, theme);
}
return classMap;
};
var _processClassesRecursively = function processClassesRecursively(classGroup, classPartObject, classGroupId, theme) {
classGroup.forEach(function (classDefinition) {
if (typeof classDefinition === 'string') {
var classPartObjectToEdit = classDefinition === '' ? classPartObject : getPart(classPartObject, classDefinition);
classPartObjectToEdit.classGroupId = classGroupId;
return;
}
if (typeof classDefinition === 'function') {
if (isThemeGetter(classDefinition)) {
_processClassesRecursively(classDefinition(theme), classPartObject, classGroupId, theme);
return;
}
classPartObject.validators.push({
validator: classDefinition,
classGroupId: classGroupId
});
return;
}
Object.entries(classDefinition).forEach(function (_ref2) {
var key = _ref2[0],
classGroup = _ref2[1];
_processClassesRecursively(classGroup, getPart(classPartObject, key), classGroupId, theme);
});
});
};
var getPart = function getPart(classPartObject, path) {
var currentClassPartObject = classPartObject;
path.split(CLASS_PART_SEPARATOR).forEach(function (pathPart) {
if (!currentClassPartObject.nextPart.has(pathPart)) {
currentClassPartObject.nextPart.set(pathPart, {
nextPart: new Map(),
validators: []
});
}
currentClassPartObject = currentClassPartObject.nextPart.get(pathPart);
});
return currentClassPartObject;
};
var isThemeGetter = function isThemeGetter(func) {
return func.isThemeGetter;
};
// LRU cache inspired from hashlru (https://github.com/dominictarr/hashlru/blob/v1.0.4/index.js) but object replaced with Map to improve performance
var createLruCache = function createLruCache(maxCacheSize) {
if (maxCacheSize < 1) {
return {
get: function get() {
return undefined;
},
set: function set() {}
};
}
var cacheSize = 0;
var cache = new Map();
var previousCache = new Map();
var update = function update(key, value) {
cache.set(key, value);
cacheSize++;
if (cacheSize > maxCacheSize) {
cacheSize = 0;
previousCache = cache;
cache = new Map();
}
};
return {
get: function get(key) {
var value = cache.get(key);
if (value !== undefined) {
return value;
}
if ((value = previousCache.get(key)) !== undefined) {
update(key, value);
return value;
}
},
set: function set(key, value) {
if (cache.has(key)) {
cache.set(key, value);
} else {
update(key, value);
}
}
};
};
var IMPORTANT_MODIFIER = '!';
var MODIFIER_SEPARATOR = ':';
var MODIFIER_SEPARATOR_LENGTH = MODIFIER_SEPARATOR.length;
var createParseClassName = function createParseClassName(config) {
var prefix = config.prefix,
experimentalParseClassName = config.experimentalParseClassName;
/**
* Parse class name into parts.
*
* Inspired by `splitAtTopLevelOnly` used in Tailwind CSS
* @see https://github.com/tailwindlabs/tailwindcss/blob/v3.2.2/src/util/splitAtTopLevelOnly.js
*/
var parseClassName = function parseClassName(className) {
var modifiers = [];
var bracketDepth = 0;
var parenDepth = 0;
var modifierStart = 0;
var postfixModifierPosition;
for (var index = 0; index < className.length; index++) {
var currentCharacter = className[index];
if (bracketDepth === 0 && parenDepth === 0) {
if (currentCharacter === MODIFIER_SEPARATOR) {
modifiers.push(className.slice(modifierStart, index));
modifierStart = index + MODIFIER_SEPARATOR_LENGTH;
continue;
}
if (currentCharacter === '/') {
postfixModifierPosition = index;
continue;
}
}
if (currentCharacter === '[') {
bracketDepth++;
} else if (currentCharacter === ']') {
bracketDepth--;
} else if (currentCharacter === '(') {
parenDepth++;
} else if (currentCharacter === ')') {
parenDepth--;
}
}
var baseClassNameWithImportantModifier = modifiers.length === 0 ? className : className.substring(modifierStart);
var baseClassName = stripImportantModifier(baseClassNameWithImportantModifier);
var hasImportantModifier = baseClassName !== baseClassNameWithImportantModifier;
var maybePostfixModifierPosition = postfixModifierPosition && postfixModifierPosition > modifierStart ? postfixModifierPosition - modifierStart : undefined;
return {
modifiers: modifiers,
hasImportantModifier: hasImportantModifier,
baseClassName: baseClassName,
maybePostfixModifierPosition: maybePostfixModifierPosition
};
};
if (prefix) {
var fullPrefix = prefix + MODIFIER_SEPARATOR;
var parseClassNameOriginal = parseClassName;
parseClassName = function parseClassName(className) {
return className.startsWith(fullPrefix) ? parseClassNameOriginal(className.substring(fullPrefix.length)) : {
isExternal: true,
modifiers: [],
hasImportantModifier: false,
baseClassName: className,
maybePostfixModifierPosition: undefined
};
};
}
if (experimentalParseClassName) {
var _parseClassNameOriginal = parseClassName;
parseClassName = function parseClassName(className) {
return experimentalParseClassName({
className: className,
parseClassName: _parseClassNameOriginal
});
};
}
return parseClassName;
};
var stripImportantModifier = function stripImportantModifier(baseClassName) {
if (baseClassName.endsWith(IMPORTANT_MODIFIER)) {
return baseClassName.substring(0, baseClassName.length - 1);
}
/**
* In Tailwind CSS v3 the important modifier was at the start of the base class name. This is still supported for legacy reasons.
* @see https://github.com/dcastil/tailwind-merge/issues/513#issuecomment-2614029864
*/
if (baseClassName.startsWith(IMPORTANT_MODIFIER)) {
return baseClassName.substring(1);
}
return baseClassName;
};
/**
* Sorts modifiers according to following schema:
* - Predefined modifiers are sorted alphabetically
* - When an arbitrary variant appears, it must be preserved which modifiers are before and after it
*/
var createSortModifiers = function createSortModifiers(config) {
var orderSensitiveModifiers = Object.fromEntries(config.orderSensitiveModifiers.map(function (modifier) {
return [modifier, true];
}));
var sortModifiers = function sortModifiers(modifiers) {
if (modifiers.length <= 1) {
return modifiers;
}
var sortedModifiers = [];
var unsortedModifiers = [];
modifiers.forEach(function (modifier) {
var isPositionSensitive = modifier[0] === '[' || orderSensitiveModifiers[modifier];
if (isPositionSensitive) {
sortedModifiers.push.apply(sortedModifiers, unsortedModifiers.sort().concat([modifier]));
unsortedModifiers = [];
} else {
unsortedModifiers.push(modifier);
}
});
sortedModifiers.push.apply(sortedModifiers, unsortedModifiers.sort());
return sortedModifiers;
};
return sortModifiers;
};
var createConfigUtils = function createConfigUtils(config) {
return _extends({
cache: createLruCache(config.cacheSize),
parseClassName: createParseClassName(config),
sortModifiers: createSortModifiers(config)
}, createClassGroupUtils(config));
};
var SPLIT_CLASSES_REGEX = /\s+/;
var mergeClassList = function mergeClassList(classList, configUtils) {
var parseClassName = configUtils.parseClassName,
getClassGroupId = configUtils.getClassGroupId,
getConflictingClassGroupIds = configUtils.getConflictingClassGroupIds,
sortModifiers = configUtils.sortModifiers;
/**
* Set of classGroupIds in following format:
* `{importantModifier}{variantModifiers}{classGroupId}`
* @example 'float'
* @example 'hover:focus:bg-color'
* @example 'md:!pr'
*/
var classGroupsInConflict = [];
var classNames = classList.trim().split(SPLIT_CLASSES_REGEX);
var result = '';
for (var index = classNames.length - 1; index >= 0; index -= 1) {
var originalClassName = classNames[index];
var _parseClassName = parseClassName(originalClassName),
isExternal = _parseClassName.isExternal,
modifiers = _parseClassName.modifiers,
hasImportantModifier = _parseClassName.hasImportantModifier,
baseClassName = _parseClassName.baseClassName,
maybePostfixModifierPosition = _parseClassName.maybePostfixModifierPosition;
if (isExternal) {
result = originalClassName + (result.length > 0 ? ' ' + result : result);
continue;
}
var hasPostfixModifier = !!maybePostfixModifierPosition;
var classGroupId = getClassGroupId(hasPostfixModifier ? baseClassName.substring(0, maybePostfixModifierPosition) : baseClassName);
if (!classGroupId) {
if (!hasPostfixModifier) {
// Not a Tailwind class
result = originalClassName + (result.length > 0 ? ' ' + result : result);
continue;
}
classGroupId = getClassGroupId(baseClassName);
if (!classGroupId) {
// Not a Tailwind class
result = originalClassName + (result.length > 0 ? ' ' + result : result);
continue;
}
hasPostfixModifier = false;
}
var variantModifier = sortModifiers(modifiers).join(':');
var modifierId = hasImportantModifier ? variantModifier + IMPORTANT_MODIFIER : variantModifier;
var classId = modifierId + classGroupId;
if (classGroupsInConflict.includes(classId)) {
// Tailwind class omitted due to conflict
continue;
}
classGroupsInConflict.push(classId);
var conflictGroups = getConflictingClassGroupIds(classGroupId, hasPostfixModifier);
for (var i = 0; i < conflictGroups.length; ++i) {
var group = conflictGroups[i];
classGroupsInConflict.push(modifierId + group);
}
// Tailwind class not in conflict
result = originalClassName + (result.length > 0 ? ' ' + result : result);
}
return result;
};
/**
* The code in this file is copied from https://github.com/lukeed/clsx and modified to suit the needs of tailwind-merge better.
*
* Specifically:
* - Runtime code from https://github.com/lukeed/clsx/blob/v1.2.1/src/index.js
* - TypeScript types from https://github.com/lukeed/clsx/blob/v1.2.1/clsx.d.ts
*
* Original code has MIT license: Copyright (c) Luke Edwards <luke.edwards05@gmail.com> (lukeed.com)
*/
function twJoin() {
var index = 0;
var argument;
var resolvedValue;
var string = '';
while (index < arguments.length) {
if (argument = arguments[index++]) {
if (resolvedValue = _toValue(argument)) {
string && (string += ' ');
string += resolvedValue;
}
}
}
return string;
}
var _toValue = function toValue(mix) {
if (typeof mix === 'string') {
return mix;
}
var resolvedValue;
var string = '';
for (var k = 0; k < mix.length; k++) {
if (mix[k]) {
if (resolvedValue = _toValue(mix[k])) {
string && (string += ' ');
string += resolvedValue;
}
}
}
return string;
};
function createTailwindMerge(createConfigFirst) {
for (var _len = arguments.length, createConfigRest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
createConfigRest[_key - 1] = arguments[_key];
}
var configUtils;
var cacheGet;
var cacheSet;
var functionToCall = initTailwindMerge;
function initTailwindMerge(classList) {
var config = createConfigRest.reduce(function (previousConfig, createConfigCurrent) {
return createConfigCurrent(previousConfig);
}, createConfigFirst());
configUtils = createConfigUtils(config);
cacheGet = configUtils.cache.get;
cacheSet = configUtils.cache.set;
functionToCall = tailwindMerge;
return tailwindMerge(classList);
}
function tailwindMerge(classList) {
var cachedResult = cacheGet(classList);
if (cachedResult) {
return cachedResult;
}
var result = mergeClassList(classList, configUtils);
cacheSet(classList, result);
return result;
}
return function callTailwindMerge() {
return functionToCall(twJoin.apply(null, arguments));
};
}
var fromTheme = function fromTheme(key) {
var themeGetter = function themeGetter(theme) {
return theme[key] || [];
};
themeGetter.isThemeGetter = true;
return themeGetter;
};
var arbitraryValueRegex = /^\[(?:(\w[\w-]*):)?(.+)\]$/i;
var arbitraryVariableRegex = /^\((?:(\w[\w-]*):)?(.+)\)$/i;
var fractionRegex = /^\d+\/\d+$/;
var tshirtUnitRegex = /^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/;
var lengthUnitRegex = /\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/;
var colorFunctionRegex = /^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/;
// Shadow always begins with x and y offset separated by underscore optionally prepended by inset
var shadowRegex = /^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/;
var imageRegex = /^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/;
var isFraction = function isFraction(value) {
return fractionRegex.test(value);
};
var isNumber = function isNumber(value) {
return Boolean(value) && !Number.isNaN(Number(value));
};
var isInteger = function isInteger(value) {
return Boolean(value) && Number.isInteger(Number(value));
};
var isPercent = function isPercent(value) {
return value.endsWith('%') && isNumber(value.slice(0, -1));
};
var isTshirtSize = function isTshirtSize(value) {
return tshirtUnitRegex.test(value);
};
var isAny = function isAny() {
return true;
};
var isLengthOnly = function isLengthOnly(value) {
return (
// `colorFunctionRegex` check is necessary because color functions can have percentages in them which which would be incorrectly classified as lengths.
// For example, `hsl(0 0% 0%)` would be classified as a length without this check.
// I could also use lookbehind assertion in `lengthUnitRegex` but that isn't supported widely enough.
lengthUnitRegex.test(value) && !colorFunctionRegex.test(value)
);
};
var isNever = function isNever() {
return false;
};
var isShadow = function isShadow(value) {
return shadowRegex.test(value);
};
var isImage = function isImage(value) {
return imageRegex.test(value);
};
var isAnyNonArbitrary = function isAnyNonArbitrary(value) {
return !isArbitraryValue(value) && !isArbitraryVariable(value);
};
var isArbitrarySize = function isArbitrarySize(value) {
return getIsArbitraryValue(value, isLabelSize, isNever);
};
var isArbitraryValue = function isArbitraryValue(value) {
return arbitraryValueRegex.test(value);
};
var isArbitraryLength = function isArbitraryLength(value) {
return getIsArbitraryValue(value, isLabelLength, isLengthOnly);
};
var isArbitraryNumber = function isArbitraryNumber(value) {
return getIsArbitraryValue(value, isLabelNumber, isNumber);
};
var isArbitraryPosition = function isArbitraryPosition(value) {
return getIsArbitraryValue(value, isLabelPosition, isNever);
};
var isArbitraryImage = function isArbitraryImage(value) {
return getIsArbitraryValue(value, isLabelImage, isImage);
};
var isArbitraryShadow = function isArbitraryShadow(value) {
return getIsArbitraryValue(value, isNever, isShadow);
};
var isArbitraryVariable = function isArbitraryVariable(value) {
return arbitraryVariableRegex.test(value);
};
var isArbitraryVariableLength = function isArbitraryVariableLength(value) {
return getIsArbitraryVariable(value, isLabelLength);
};
var isArbitraryVariableFamilyName = function isArbitraryVariableFamilyName(value) {
return getIsArbitraryVariable(value, isLabelFamilyName);
};
var isArbitraryVariablePosition = function isArbitraryVariablePosition(value) {
return getIsArbitraryVariable(value, isLabelPosition);
};
var isArbitraryVariableSize = function isArbitraryVariableSize(value) {
return getIsArbitraryVariable(value, isLabelSize);
};
var isArbitraryVariableImage = function isArbitraryVariableImage(value) {
return getIsArbitraryVariable(value, isLabelImage);
};
var isArbitraryVariableShadow = function isArbitraryVariableShadow(value) {
return getIsArbitraryVariable(value, isLabelShadow, true);
};
// Helpers
var getIsArbitraryValue = function getIsArbitraryValue(value, testLabel, testValue) {
var result = arbitraryValueRegex.exec(value);
if (result) {
if (result[1]) {
return testLabel(result[1]);
}
return testValue(result[2]);
}
return false;
};
var getIsArbitraryVariable = function getIsArbitraryVariable(value, testLabel, shouldMatchNoLabel) {
if (shouldMatchNoLabel === void 0) {
shouldMatchNoLabel = false;
}
var result = arbitraryVariableRegex.exec(value);
if (result) {
if (result[1]) {
return testLabel(result[1]);
}
return shouldMatchNoLabel;
}
return false;
};
// Labels
var isLabelPosition = function isLabelPosition(label) {
return label === 'position';
};
var imageLabels = /*#__PURE__*/new Set(['image', 'url']);
var isLabelImage = function isLabelImage(label) {
return imageLabels.has(label);
};
var sizeLabels = /*#__PURE__*/new Set(['length', 'size', 'percentage']);
var isLabelSize = function isLabelSize(label) {
return sizeLabels.has(label);
};
var isLabelLength = function isLabelLength(label) {
return label === 'length';
};
var isLabelNumber = function isLabelNumber(label) {
return label === 'number';
};
var isLabelFamilyName = function isLabelFamilyName(label) {
return label === 'family-name';
};
var isLabelShadow = function isLabelShadow(label) {
return label === 'shadow';
};
var validators = /*#__PURE__*/Object.defineProperty({
__proto__: null,
isAny: isAny,
isAnyNonArbitrary: isAnyNonArbitrary,
isArbitraryImage: isArbitraryImage,
isArbitraryLength: isArbitraryLength,
isArbitraryNumber: isArbitraryNumber,
isArbitraryPosition: isArbitraryPosition,
isArbitraryShadow: isArbitraryShadow,
isArbitrarySize: isArbitrarySize,
isArbitraryValue: isArbitraryValue,
isArbitraryVariable: isArbitraryVariable,
isArbitraryVariableFamilyName: isArbitraryVariableFamilyName,
isArbitraryVariableImage: isArbitraryVariableImage,
isArbitraryVariableLength: isArbitraryVariableLength,
isArbitraryVariablePosition: isArbitraryVariablePosition,
isArbitraryVariableShadow: isArbitraryVariableShadow,
isArbitraryVariableSize: isArbitraryVariableSize,
isFraction: isFraction,
isInteger: isInteger,
isNumber: isNumber,
isPercent: isPercent,
isTshirtSize: isTshirtSize
}, Symbol.toStringTag, {
value: 'Module'
});
var getDefaultConfig = function getDefaultConfig() {
/**
* Theme getters for theme variable namespaces
* @see https://tailwindcss.com/docs/theme#theme-variable-namespaces
*/
/***/
var themeColor = fromTheme('color');
var themeFont = fromTheme('font');
var themeText = fromTheme('text');
var themeFontWeight = fromTheme('font-weight');
var themeTracking = fromTheme('tracking');
var themeLeading = fromTheme('leading');
var themeBreakpoint = fromTheme('breakpoint');
var themeContainer = fromTheme('container');
var themeSpacing = fromTheme('spacing');
var themeRadius = fromTheme('radius');
var themeShadow = fromTheme('shadow');
var themeInsetShadow = fromTheme('inset-shadow');
var themeDropShadow = fromTheme('drop-shadow');
var themeBlur = fromTheme('blur');
var themePerspective = fromTheme('perspective');
var themeAspect = fromTheme('aspect');
var themeEase = fromTheme('ease');
var themeAnimate = fromTheme('animate');
/**
* Helpers to avoid repeating the same scales
*
* We use functions that create a new array every time they're called instead of static arrays.
* This ensures that users who modify any scale by mutating the array (e.g. with `array.push(element)`) don't accidentally mutate arrays in other parts of the config.
*/
/***/
var scaleBreak = function scaleBreak() {
return ['auto', 'avoid', 'all', 'avoid-page', 'page', 'left', 'right', 'column'];
};
var scalePosition = function scalePosition() {
return ['bottom', 'center', 'left', 'left-bottom', 'left-top', 'right', 'right-bottom', 'right-top', 'top'];
};
var scaleOverflow = function scaleOverflow() {
return ['auto', 'hidden', 'clip', 'visible', 'scroll'];
};
var scaleOverscroll = function scaleOverscroll() {
return ['auto', 'contain', 'none'];
};
var scaleUnambiguousSpacing = function scaleUnambiguousSpacing() {
return [isArbitraryVariable, isArbitraryValue, themeSpacing];
};
var scaleInset = function scaleInset() {
return [isFraction, 'full', 'auto'].concat(scaleUnambiguousSpacing());
};
var scaleGridTemplateColsRows = function scaleGridTemplateColsRows() {
return [isInteger, 'none', 'subgrid', isArbitraryVariable, isArbitraryValue];
};
var scaleGridColRowStartAndEnd = function scaleGridColRowStartAndEnd() {
return ['auto', {
span: ['full', isInteger, isArbitraryVariable, isArbitraryValue]
}, isInteger, isArbitraryVariable, isArbitraryValue];
};
var scaleGridColRowStartOrEnd = function scaleGridColRowStartOrEnd() {
return [isInteger, 'auto', isArbitraryVariable, isArbitraryValue];
};
var scaleGridAutoColsRows = function scaleGridAutoColsRows() {
return ['auto', 'min', 'max', 'fr', isArbitraryVariable, isArbitraryValue];
};
var scaleAlignPrimaryAxis = function scaleAlignPrimaryAxis() {
return ['start', 'end', 'center', 'between', 'around', 'evenly', 'stretch', 'baseline'];
};
var scaleAlignSecondaryAxis = function scaleAlignSecondaryAxis() {
return ['start', 'end', 'center', 'stretch'];
};
var scaleMargin = function scaleMargin() {
return ['auto'].concat(scaleUnambiguousSpacing());
};
var scaleSizing = function scaleSizing() {
return [isFraction, 'auto', 'full', 'dvw', 'dvh', 'lvw', 'lvh', 'svw', 'svh', 'min', 'max', 'fit'].concat(scaleUnambiguousSpacing());
};
var scaleColor = function scaleColor() {
return [themeColor, isArbitraryVariable, isArbitraryValue];
};
var scaleGradientStopPosition = function scaleGradientStopPosition() {
return [isPercent, isArbitraryVariableLength, isArbitraryLength];
};
var scaleRadius = function scaleRadius() {
return [
// Deprecated since Tailwind CSS v4.0.0
'', 'none', 'full', themeRadius, isArbitraryVariable, isArbitraryValue];
};
var scaleBorderWidth = function scaleBorderWidth() {
return ['', isNumber, isArbitraryVariableLength, isArbitraryLength];
};
var scaleLineStyle = function scaleLineStyle() {
return ['solid', 'dashed', 'dotted', 'double'];
};
var scaleBlendMode = function scaleBlendMode() {
return ['normal', 'multiply', 'screen', 'overlay', 'darken', 'lighten', 'color-dodge', 'color-burn', 'hard-light', 'soft-light', 'difference', 'exclusion', 'hue', 'saturation', 'color', 'luminosity'];
};
var scaleBlur = function scaleBlur() {
return [
// Deprecated since Tailwind CSS v4.0.0
'', 'none', themeBlur, isArbitraryVariable, isArbitraryValue];
};
var scaleOrigin = function scaleOrigin() {
return ['center', 'top', 'top-right', 'right', 'bottom-right', 'bottom', 'bottom-left', 'left', 'top-left', isArbitraryVariable, isArbitraryValue];
};
var scaleRotate = function scaleRotate() {
return ['none', isNumber, isArbitraryVariable, isArbitraryValue];
};
var scaleScale = function scaleScale() {
return ['none', isNumber, isArbitraryVariable, isArbitraryValue];
};
var scaleSkew = function scaleSkew() {
return [isNumber, isArbitraryVariable, isArbitraryValue];
};
var scaleTranslate = function scaleTranslate() {
return [isFraction, 'full'].concat(scaleUnambiguousSpacing());
};
return {
cacheSize: 500,
theme: {
animate: ['spin', 'ping', 'pulse', 'bounce'],
aspect: ['video'],
blur: [isTshirtSize],
breakpoint: [isTshirtSize],
color: [isAny],
container: [isTshirtSize],
'drop-shadow': [isTshirtSize],
ease: ['in', 'out', 'in-out'],
font: [isAnyNonArbitrary],
'font-weight': ['thin', 'extralight', 'light', 'normal', 'medium', 'semibold', 'bold', 'extrabold', 'black'],
'inset-shadow': [isTshirtSize],
leading: ['none', 'tight', 'snug', 'normal', 'relaxed', 'loose'],
perspective: ['dramatic', 'near', 'normal', 'midrange', 'distant', 'none'],
radius: [isTshirtSize],
shadow: [isTshirtSize],
spacing: ['px', isNumber],
text: [isTshirtSize],
tracking: ['tighter', 'tight', 'normal', 'wide', 'wider', 'widest']
},
classGroups: {
// --------------
// --- Layout ---
// --------------
/**
* Aspect Ratio
* @see https://tailwindcss.com/docs/aspect-ratio
*/
aspect: [{
aspect: ['auto', 'square', isFraction, isArbitraryValue, isArbitraryVariable, themeAspect]
}],
/**
* Container
* @see https://tailwindcss.com/docs/container
* @deprecated since Tailwind CSS v4.0.0
*/
container: ['container'],
/**
* Columns
* @see https://tailwindcss.com/docs/columns
*/
columns: [{
columns: [isNumber, isArbitraryValue, isArbitraryVariable, themeContainer]
}],
/**
* Break After
* @see https://tailwindcss.com/docs/break-after
*/
'break-after': [{
'break-after': scaleBreak()
}],
/**
* Break Before
* @see https://tailwindcss.com/docs/break-before
*/
'break-before': [{
'break-before': scaleBreak()
}],
/**
* Break Inside
* @see https://tailwindcss.com/docs/break-inside
*/
'break-inside': [{
'break-inside': ['auto', 'avoid', 'avoid-page', 'avoid-column']
}],
/**
* Box Decoration Break
* @see https://tailwindcss.com/docs/box-decoration-break
*/
'box-decoration': [{
'box-decoration': ['slice', 'clone']
}],
/**
* Box Sizing
* @see https://tailwindcss.com/docs/box-sizing
*/
box: [{
box: ['border', 'content']
}],
/**
* Display
* @see https://tailwindcss.com/docs/display
*/
display: ['block', 'inline-block', 'inline', 'flex', 'inline-flex', 'table', 'inline-table', 'table-caption', 'table-cell', 'table-column', 'table-column-group', 'table-footer-group', 'table-header-group', 'table-row-group', 'table-row', 'flow-root', 'grid', 'inline-grid', 'contents', 'list-item', 'hidden'],
/**
* Screen Reader Only
* @see https://tailwindcss.com/docs/display#screen-reader-only
*/
sr: ['sr-only', 'not-sr-only'],
/**
* Floats
* @see https://tailwindcss.com/docs/float
*/
"float": [{
"float": ['right', 'left', 'none', 'start', 'end']
}],
/**
* Clear
* @see https://tailwindcss.com/docs/clear
*/
clear: [{
clear: ['left', 'right', 'both', 'none', 'start', 'end']
}],
/**
* Isolation
* @see https://tailwindcss.com/docs/isolation
*/
isolation: ['isolate', 'isolation-auto'],
/**
* Object Fit
* @see https://tailwindcss.com/docs/object-fit
*/
'object-fit': [{
object: ['contain', 'cover', 'fill', 'none', 'scale-down']
}],
/**
* Object Position
* @see https://tailwindcss.com/docs/object-position
*/
'object-position': [{
object: [].concat(scalePosition(), [isArbitraryValue, isArbitraryVariable])
}],
/**
* Overflow
* @see https://tailwindcss.com/docs/overflow
*/
overflow: [{
overflow: scaleOverflow()
}],
/**
* Overflow X
* @see https://tailwindcss.com/docs/overflow
*/
'overflow-x': [{
'overflow-x': scaleOverflow()
}],
/**
* Overflow Y
* @see https://tailwindcss.com/docs/overflow
*/
'overflow-y': [{
'overflow-y': scaleOverflow()
}],
/**
* Overscroll Behavior
* @see https://tailwindcss.com/docs/overscroll-behavior
*/
overscroll: [{
overscroll: scaleOverscroll()
}],
/**
* Overscroll Behavior X
* @see https://tailwindcss.com/docs/overscroll-behavior
*/
'overscroll-x': [{
'overscroll-x': scaleOverscroll()
}],
/**
* Overscroll Behavior Y
* @see https://tailwindcss.com/docs/overscroll-behavior
*/
'overscroll-y': [{
'overscroll-y': scaleOverscroll()
}],
/**
* Position
* @see https://tailwindcss.com/docs/position
*/
position: ['static', 'fixed', 'absolute', 'relative', 'sticky'],
/**
* Top / Right / Bottom / Left
* @see https://tailwindcss.com/docs/top-right-bottom-left
*/
inset: [{
inset: scaleInset()
}],
/**
* Right / Left
* @see https://tailwindcss.com/docs/top-right-bottom-left
*/
'inset-x': [{
'inset-x': scaleInset()
}],
/**
* Top / Bottom
* @see https://tailwindcss.com/docs/top-right-bottom-left
*/
'inset-y': [{
'inset-y': scaleInset()
}],
/**
* Start
* @see https://tailwindcss.com/docs/top-right-bottom-left
*/
start: [{
start: scaleInset()
}],
/**
* End
* @see https://tailwindcss.com/docs/top-right-bottom-left
*/
end: [{
end: scaleInset()
}],
/**
* Top
* @see https://tailwindcss.com/docs/top-right-bottom-left
*/
top: [{
top: scaleInset()
}],
/**
* Right
* @see https://tailwindcss.com/docs/top-right-bottom-left
*/
right: [{
right: scaleInset()
}],
/**
* Bottom
* @see https://tailwindcss.com/docs/top-right-bottom-left
*/
bottom: [{
bottom: scaleInset()
}],
/**
* Left
* @see https://tailwindcss.com/docs/top-right-bottom-left
*/
left: [{
left: scaleInset()
}],
/**
* Visibility
* @see https://tailwindcss.com/docs/visibility
*/
visibility: ['visible', 'invisible', 'collapse'],
/**
* Z-Index
* @see https://tailwindcss.com/docs/z-index
*/
z: [{
z: [isInteger, 'auto', isArbitraryVariable, isArbitraryValue]
}],
// ------------------------
// --- Flexbox and Grid ---
// ------------------------
/**
* Flex Basis
* @see https://tailwindcss.com/docs/flex-basis
*/
basis: [{
basis: [isFraction, 'full', 'auto', themeContainer].concat(scaleUnambiguousSpacing())
}],
/**
* Flex Direction
* @see https://tailwindcss.com/docs/flex-direction
*/
'flex-direction': [{
flex: ['row', 'row-reverse', 'col', 'col-reverse']
}],
/**
* Flex Wrap
* @see https://tailwindcss.com/docs/flex-wrap
*/
'flex-wrap': [{
flex: ['nowrap', 'wrap', 'wrap-reverse']
}],
/**
* Flex
* @see https://tailwindcss.com/docs/flex
*/
flex: [{
flex: [isNumber, isFraction, 'auto', 'initial', 'none', isArbitraryValue]
}],
/**
* Flex Grow
* @see https://tailwindcss.com/docs/flex-grow
*/
grow: [{
grow: ['', isNumber, isArbitraryVariable, isArbitraryValue]
}],
/**
* Flex Shrink
* @see https://tailwindcss.com/docs/flex-shrink
*/
shrink: [{
shrink: ['', isNumber, isArbitraryVariable, isArbitraryValue]
}],
/**
* Order
* @see https://tailwindcss.com/docs/order
*/
order: [{
order: [isInteger, 'first', 'last', 'none', isArbitraryVariable, isArbitraryValue]
}],
/**
* Grid Template Columns
* @see https://tailwindcss.com/docs/grid-template-columns
*/
'grid-cols': [{
'grid-cols': scaleGridTemplateColsRows()
}],
/**
* Grid Column Start / End
* @see https://tailwindcss.com/docs/grid-column
*/
'col-start-end': [{
col: scaleGridColRowStartAndEnd()
}],
/**
* Grid Column Start
* @see https://tailwindcss.com/docs/grid-column
*/
'col-start': [{
'col-start': scaleGridColRowStartOrEnd()
}],
/**
* Grid Column End
* @see https://tailwindcss.com/docs/grid-column
*/
'col-end': [{
'col-end': scaleGridColRowStartOrEnd()
}],
/**
* Grid Template Rows
* @see https://tailwindcss.com/docs/grid-template-rows
*/
'grid-rows': [{
'grid-rows': scaleGridTemplateColsRows()
}],
/**
* Grid Row Start / End
* @see https://tailwindcss.com/docs/grid-row
*/
'row-start-end': [{
row: scaleGridColRowStartAndEnd()
}],
/**
* Grid Row Start
* @see https://tailwindcss.com/docs/grid-row
*/
'row-start': [{
'row-start': scaleGridColRowStartOrEnd()
}],
/**
* Grid Row End
* @see https://tailwindcss.com/docs/grid-row
*/
'row-end': [{
'row-end': scaleGridColRowStartOrEnd()
}],
/**
* Grid Auto Flow
* @see https://tailwindcss.com/docs/grid-auto-flow
*/
'grid-flow': [{
'grid-flow': ['row', 'col', 'dense', 'row-dense', 'col-dense']
}],
/**
* Grid Auto Columns
* @see https://tailwindcss.com/docs/grid-auto-columns
*/
'auto-cols': [{
'auto-cols': scaleGridAutoColsRows()
}],
/**
* Grid Auto Rows
* @see https://tailwindcss.com/docs/grid-auto-rows
*/
'auto-rows': [{
'auto-rows': scaleGridAutoColsRows()
}],
/**
* Gap
* @see https://tailwindcss.com/docs/gap
*/
gap: [{
gap: scaleUnambiguousSpacing()
}],
/**
* Gap X
* @see https://tailwindcss.com/docs/gap
*/
'gap-x': [{
'gap-x': scaleUnambiguousSpacing()
}],
/**
* Gap Y
* @see https://tailwindcss.com/docs/gap
*/
'gap-y': [{
'gap-y': scaleUnambiguousSpacing()
}],
/**
* Justify Content
* @see https://tailwindcss.com/docs/justify-content
*/
'justify-content': [{
justify: [].concat(scaleAlignPrimaryAxis(), ['normal'])
}],
/**
* Justify Items
* @see https://tailwindcss.com/docs/justify-items
*/
'justify-items': [{
'justify-items': [].concat(scaleAlignSecondaryAxis(), ['normal'])
}],
/**
* Justify Self
* @see https://tailwindcss.com/docs/justify-self
*/
'justify-self': [{
'justify-self': ['auto'].concat(scaleAlignSecondaryAxis())
}],
/**
* Align Content
* @see https://tailwindcss.com/docs/align-content
*/
'align-content': [{
content: ['normal'].concat(scaleAlignPrimaryAxis())
}],
/**
* Align Items
* @see https://tailwindcss.com/docs/align-items
*/
'align-items': [{
items: [].concat(scaleAlignSecondaryAxis(), ['baseline'])
}],
/**
* Align Self
* @see https://tailwindcss.com/docs/align-self
*/
'align-self': [{
self: ['auto'].concat(scaleAlignSecondaryAxis(), ['baseline'])
}],
/**
* Place Content
* @see https://tailwindcss.com/docs/place-content
*/
'place-content': [{
'place-content': scaleAlignPrimaryAxis()
}],
/**
* Place Items
* @see https://tailwindcss.com/docs/place-items
*/
'place-items': [{
'place-items': [].concat(scaleAlignSecondaryAxis(), ['baseline'])
}],
/**
* Place Self
* @see https://tailwindcss.com/docs/place-self
*/
'place-self': [{
'place-self': ['auto'].concat(scaleAlignSecondaryAxis())
}],
// Spacing
/**
* Padding
* @see https://tailwindcss.com/docs/padding
*/
p: [{
p: scaleUnambiguousSpacing()
}],
/**
* Padding X
* @see https://tailwindcss.com/docs/padding
*/
px: [{
px: scaleUnambiguousSpacing()
}],
/**
* Padding Y
* @see https://tailwindcss.com/docs/padding
*/
py: [{
py: scaleUnambiguousSpacing()
}],
/**
* Padding Start
* @see https://tailwindcss.com/docs/padding
*/
ps: [{
ps: scaleUnambiguousSpacing()
}],
/**
* Padding End
* @see https://tailwindcss.com/docs/padding
*/
pe: [{
pe: scaleUnambiguousSpacing()
}],
/**
* Padding Top
* @see https://tailwindcss.com/docs/padding
*/
pt: [{
pt: scaleUnambiguousSpacing()
}],
/**
* Padding Right
* @see https://tailwindcss.com/docs/padding
*/
pr: [{
pr: scaleUnambiguousSpacing()
}],
/**
* Padding Bottom
* @see https://tailwindcss.com/docs/padding
*/
pb: [{
pb: scaleUnambiguousSpacing()
}],
/**
* Padding Left
* @see https://tailwindcss.com/docs/padding
*/
pl: [{
pl: scaleUnambiguousSpacing()
}],
/**
* Margin
* @see https://tailwindcss.com/docs/margin
*/
m: [{
m: scaleMargin()
}],
/**
* Margin X
* @see https://tailwindcss.com/docs/margin
*/
mx: [{
mx: scaleMargin()
}],
/**
* Margin Y
* @see https://tailwindcss.com/docs/margin
*/
my: [{
my: scaleMargin()
}],
/**
* Margin Start
* @see https://tailwindcss.com/docs/margin
*/
ms: [{
ms: scaleMargin()
}],
/**
* Margin End
* @see https://tailwindcss.com/docs/margin
*/
me: [{
me: scaleMargin()
}],
/**
* Margin Top
* @see https://tailwindcss.com/docs/margin
*/
mt: [{
mt: scaleMargin()
}],
/**
* Margin Right
* @see https://tailwindcss.com/docs/margin
*/
mr: [{
mr: scaleMargin()
}],
/**
* Margin Bottom
* @see https://tailwindcss.com/docs/margin
*/
mb: [{
mb: scaleMargin()
}],
/**
* Margin Left
* @see https://tailwindcss.com/docs/margin
*/
ml: [{
ml: scaleMargin()
}],
/**
* Space Between X
* @see https://tailwindcss.com/docs/margin#adding-space-between-children
*/
'space-x': [{
'space-x': scaleUnambiguousSpacing()
}],
/**
* Space Between X Reverse
* @see https://tailwindcss.com/docs/margin#adding-space-between-children
*/
'space-x-reverse': ['space-x-reverse'],
/**
* Space Between Y
* @see https://tailwindcss.com/docs/margin#adding-space-between-children
*/
'space-y': [{
'space-y': scaleUnambiguousSpacing()
}],
/**
* Space Between Y Reverse
* @see https://tailwindcss.com/docs/margin#adding-space-between-children
*/
'space-y-reverse': ['space-y-reverse'],
// --------------
// --- Sizing ---
// --------------
/**
* Size
* @see https://tailwindcss.com/docs/width#setting-both-width-and-height
*/
size: [{
size: scaleSizing()
}],
/**
* Width
* @see https://tailwindcss.com/docs/width
*/
w: [{
w: [themeContainer, 'screen'].concat(scaleSizing())
}],
/**
* Min-Width
* @see https://tailwindcss.com/docs/min-width
*/
'min-w': [{
'min-w': [themeContainer, 'screen', /** Deprecated. @see https://github.com/tailwindlabs/tailwindcss.com/issues/2027#issuecomment-2620152757 */
'none'].concat(scaleSizing())
}],
/**
* Max-Width
* @see https://tailwindcss.com/docs/max-width
*/
'max-w': [{
'max-w': [themeContainer, 'screen', 'none', /** Deprecated since Tailwind CSS v4.0.0. @see https://github.com/tailwindlabs/tailwindcss.com/issues/2027#issuecomment-2620152757 */
'prose', /** Deprecated since Tailwind CSS v4.0.0. @see https://github.com/tailwindlabs/tailwindcss.com/issues/2027#issuecomment-2620152757 */
{
screen: [themeBreakpoint]
}].concat(scaleSizing())
}],
/**
* Height
* @see https://tailwindcss.com/docs/height
*/
h: [{
h: ['screen'].concat(scaleSizing())
}],
/**
* Min-Height
* @see https://tailwindcss.com/docs/min-height
*/
'min-h': [{
'min-h': ['screen', 'none'].concat(scaleSizing())
}],
/**
* Max-Height
* @see https://tailwindcss.com/docs/max-height
*/
'max-h': [{
'max-h': ['screen'].concat(scaleSizing())
}],
// ------------------
// --- Typography ---
// ------------------
/**
* Font Size
* @see https://tailwindcss.com/docs/font-size
*/
'font-size': [{
text: ['base', themeText, isArbitraryVariableLength, isArbitraryLength]
}],
/**
* Font Smoothing
* @see https://tailwindcss.com/docs/font-smoothing
*/
'font-smoothing': ['antialiased', 'subpixel-antialiased'],
/**
* Font Style
* @see https://tailwindcss.com/docs/font-style
*/
'font-style': ['italic', 'not-italic'],
/**
* Font Weight
* @see https://tailwindcss.com/docs/font-weight
*/
'font-weight': [{
font: [themeFontWeight, isArbitraryVariable, isArbitraryNumber]
}],
/**
* Font Stretch
* @see https://tailwindcss.com/docs/font-stretch
*/
'font-stretch': [{
'font-stretch': ['ultra-condensed', 'extra-condensed', 'condensed', 'semi-condensed', 'normal', 'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded', isPercent, isArbitraryValue]
}],
/**
* Font Family
* @see https://tailwindcss.com/docs/font-family
*/
'font-family': [{
font: [isArbitraryVariableFamilyName, isArbitraryValue, themeFont]
}],
/**
* Font Variant Numeric
* @see https://tailwindcss.com/docs/font-variant-numeric
*/
'fvn-normal': ['normal-nums'],
/**
* Font Variant Numeric
* @see https://tailwindcss.com/docs/font-variant-numeric
*/
'fvn-ordinal': ['ordinal'],
/**
* Font Variant Numeric
* @see https://tailwindcss.com/docs/font-variant-numeric
*/
'fvn-slashed-zero': ['slashed-zero'],
/**
* Font Variant Numeric
* @see https://tailwindcss.com/docs/font-variant-numeric
*/
'fvn-figure': ['lining-nums', 'oldstyle-nums'],
/**
* Font Variant Numeric
* @see https://tailwindcss.com/docs/font-variant-numeric
*/
'fvn-spacing': ['proportional-nums', 'tabular-nums'],
/**
* Font Variant Numeric
* @see https://tailwindcss.com/docs/font-variant-numeric
*/
'fvn-fraction': ['diagonal-fractions', 'stacked-fractions'],
/**
* Letter Spacing
* @see https://tailwindcss.com/docs/letter-spacing
*/
tracking: [{
tracking: [themeTracking, isArbitraryVariable, isArbitraryValue]
}],
/**
* Line Clamp
* @see https://tailwindcss.com/docs/line-clamp
*/
'line-clamp': [{
'line-clamp': [isNumber, 'none', isArbitraryVariable, isArbitraryNumber]
}],
/**
* Line Height
* @see https://tailwindcss.com/docs/line-height
*/
leading: [{
leading: [/** Deprecated since Tailwind CSS v4.0.0. @see https://github.com/tailwindlabs/tailwindcss.com/issues/2027#issuecomment-2620152757 */
themeLeading].concat(scaleUnambiguousSpacing())
}],
/**
* List Style Image
* @see https://tailwindcss.com/docs/list-style-image
*/
'list-image': [{
'list-image': ['none', isArbitraryVariable, isArbitraryValue]
}],
/**
* List Style Position
* @see https://tailwindcss.com/docs/list-style-position
*/
'list-style-position': [{
list: ['inside', 'outside']
}],
/**
* List Style Type
* @see https://tailwindcss.com/docs/list-style-type
*/
'list-style-type': [{
list: ['disc', 'decimal', 'none', isArbitraryVariable, isArbitraryValue]
}],
/**
* Text Alignment
* @see https://tailwindcss.com/docs/text-align
*/
'text-alignment': [{
text: ['left', 'center', 'right', 'justify', 'start', 'end']
}],
/**
* Placeholder Color
* @deprecated since Tailwind CSS v3.0.0
* @see https://v3.tailwindcss.com/docs/placeholder-color
*/
'placeholder-color': [{
placeholder: scaleColor()
}],
/**
* Text Color
* @see https://tailwindcss.com/docs/text-color
*/
'text-color': [{
text: scaleColor()
}],
/**
* Text Decoration
* @see https://tailwindcss.com/docs/text-decoration
*/
'text-decoration': ['underline', 'overline', 'line-through', 'no-underline'],
/**
* Text Decoration Style
* @see https://tailwindcss.com/docs/text-decoration-style
*/
'text-decoration-style': [{
decoration: [].concat(scaleLineStyle(), ['wavy'])
}],
/**
* Text Decoration Thickness
* @see https://tailwindcss.com/docs/text-decoration-thickness
*/
'text-decoration-thickness': [{
decoration: [isNumber, 'from-font', 'auto', isArbitraryVariable, isArbitraryLength]
}],
/**
* Text Decoration Color
* @see https://tailwindcss.com/docs