tailwind-merge
Version:
Merge Tailwind CSS classes without style conflicts
2,009 lines • 49.2 kB
JavaScript
import HLRU from 'hashlru';
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function getLruCache(cacheSize) {
if (cacheSize >= 1) {
return HLRU(cacheSize);
}
return {
get: () => undefined,
set: () => {}
};
}
const CLASS_PART_SEPARATOR = '-';
function createClassUtils(config) {
const classMap = createClassMap(config);
function getClassGroupId(className) {
const 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);
}
function getConflictingClassGroupIds(classGroupId) {
return config.conflictingClassGroups[classGroupId] || [];
}
return {
getClassGroupId,
getConflictingClassGroupIds
};
}
function getGroupRecursive(classParts, classPartObject) {
var _classPartObject$vali;
if (classParts.length === 0) {
return classPartObject.classGroupId;
}
const currentClassPart = classParts[0];
const nextClassPartObject = classPartObject.nextPart[currentClassPart];
const classGroupFromNextClassPart = nextClassPartObject ? getGroupRecursive(classParts.slice(1), nextClassPartObject) : undefined;
if (classGroupFromNextClassPart) {
return classGroupFromNextClassPart;
}
if (classPartObject.validators.length === 0) {
return undefined;
}
const classRest = classParts.join(CLASS_PART_SEPARATOR);
return (_classPartObject$vali = classPartObject.validators.find(({
validator
}) => validator(classRest))) == null ? void 0 : _classPartObject$vali.classGroupId;
}
/**
* Exported for testing only
*/
function createClassMap(config) {
const classMap = {
nextPart: {},
validators: []
};
Object.entries(config.classGroups).forEach(([classGroupId, classGroup]) => {
processClassesRecursively(classGroup, classMap, classGroupId);
});
return classMap;
}
function processClassesRecursively(classGroup, classPartObject, classGroupId) {
classGroup.forEach(classDefinition => {
if (typeof classDefinition === 'string') {
const classPartObjectToEdit = classDefinition === '' ? classPartObject : getPart(classPartObject, classDefinition);
classPartObjectToEdit.classGroupId = classGroupId;
} else if (typeof classDefinition === 'function') {
classPartObject.validators.push({
validator: classDefinition,
classGroupId
});
} else {
Object.entries(classDefinition).forEach(([key, classGroup]) => {
processClassesRecursively(classGroup, getPart(classPartObject, key), classGroupId);
});
}
});
}
function getPart(classPartObject, path) {
let currentClassPartObject = classPartObject;
path.split(CLASS_PART_SEPARATOR).forEach(pathPart => {
if (currentClassPartObject.nextPart[pathPart] === undefined) {
currentClassPartObject.nextPart[pathPart] = {
nextPart: {},
validators: []
};
}
currentClassPartObject = currentClassPartObject.nextPart[pathPart];
});
return currentClassPartObject;
}
function createConfigUtils(config) {
return _extends({
cache: getLruCache(config.cacheSize)
}, createClassUtils(config));
}
const SPLIT_CLASSES_REGEX = /\s+/;
const IMPORTANT_MODIFIER = '!'; // Regex is needed so we don't match against colons in labels for custom values like `text-[color:var(--mystery-var)]`
// I'd prefer to use a negative lookbehind for all supported labels, but lookbheinds don't have good browser support yet. More info: https://caniuse.com/js-regexp-lookbehind
const PREFIX_SEPARATOR_REGEX = /:(?![^[]*\])/;
const PREFIX_SEPARATOR = ':';
function mergeClassList(classList, configUtils) {
const {
getClassGroupId,
getConflictingClassGroupIds
} = configUtils;
/**
* Set of classGroupIds in following format:
* `{importantModifier}{variantPrefixes}{classGroupId}`
* @example 'float'
* @example 'hover:focus:bg-color'
* @example '!md:pr'
*/
const classGroupsInConflict = new Set();
return classList.trim().split(SPLIT_CLASSES_REGEX).map(originalClassName => {
const prefixes = originalClassName.split(PREFIX_SEPARATOR_REGEX);
const classNameWithImportantModifier = prefixes.pop();
const hasImportantModifier = classNameWithImportantModifier.startsWith(IMPORTANT_MODIFIER);
const className = hasImportantModifier ? classNameWithImportantModifier.substring(1) : classNameWithImportantModifier;
const classGroupId = getClassGroupId(className);
if (!classGroupId) {
return {
isTailwindClass: false,
originalClassName
};
}
const variantPrefix = prefixes.length === 0 ? '' : prefixes.sort().concat('').join(PREFIX_SEPARATOR);
const fullPrefix = hasImportantModifier ? IMPORTANT_MODIFIER + variantPrefix : variantPrefix;
return {
isTailwindClass: true,
prefix: fullPrefix,
classGroupId,
originalClassName
};
}).reverse() // Last class in conflict wins, so we need to filter conflicting classes in reverse order.
.filter(parsed => {
if (!parsed.isTailwindClass) {
return true;
}
const {
prefix,
classGroupId
} = parsed;
const classId = `${prefix}:${classGroupId}`;
if (classGroupsInConflict.has(classId)) {
return false;
}
classGroupsInConflict.add(classId);
getConflictingClassGroupIds(classGroupId).forEach(group => classGroupsInConflict.add(`${prefix}:${group}`));
return true;
}).reverse().map(parsed => parsed.originalClassName).join(' ');
}
function createTailwindMerge(...createConfig) {
let configUtils;
let cacheGet;
let cacheSet;
let functionToCall = initTailwindMerge;
function initTailwindMerge(classList) {
const [firstCreateConfig, ...restCreateConfig] = createConfig;
const config = restCreateConfig.reduce((previousConfig, createConfigCurrent) => createConfigCurrent(previousConfig), firstCreateConfig());
configUtils = createConfigUtils(config);
cacheGet = configUtils.cache.get;
cacheSet = configUtils.cache.set;
functionToCall = tailwindMerge;
return tailwindMerge(classList);
}
function tailwindMerge(classList) {
const cachedResult = cacheGet(classList);
if (cachedResult) {
return cachedResult;
}
const result = mergeClassList(classList, configUtils);
cacheSet(classList, result);
return result;
}
return function callTailwindMerge() {
let classList = '';
let temp; // Credits → https://github.com/lukeed/clsx/blob/v1.1.1/src/index.js
for (let index = 0; index < arguments.length; index += 1) {
if (temp = arguments[index]) {
classList && (classList += ' ');
classList += temp;
}
}
return functionToCall(classList);
};
}
const customValueRegex = /^\[(.+)\]$/;
const fractionRegex = /^\d+\/\d+$/;
const stringLengths = new Set(['px', 'full', 'screen']);
const lengthUnitRegex = /\d+(%|px|em|rem|vh|vw|pt|pc|in|cm|mm|cap|ch|ex|lh|rlh|vi|vb|vmin|vmax)/;
function isLength(classPart) {
return isCustomLength(classPart) || !Number.isNaN(Number(classPart)) || stringLengths.has(classPart) || fractionRegex.test(classPart);
}
function isCustomLength(classPart) {
var _customValueRegex$exe;
const customValue = (_customValueRegex$exe = customValueRegex.exec(classPart)) == null ? void 0 : _customValueRegex$exe[1];
if (customValue) {
return customValue.startsWith('length:') || lengthUnitRegex.test(customValue);
}
return false;
}
function isInteger(classPart) {
var _customValueRegex$exe2;
const customValue = (_customValueRegex$exe2 = customValueRegex.exec(classPart)) == null ? void 0 : _customValueRegex$exe2[1];
if (customValue) {
return Number.isInteger(Number(customValue));
}
return Number.isInteger(Number(classPart));
}
function isCustomValue(classPart) {
return customValueRegex.test(classPart);
}
function isAny() {
return true;
}
var validators = {
__proto__: null,
isLength: isLength,
isCustomLength: isCustomLength,
isInteger: isInteger,
isCustomValue: isCustomValue,
isAny: isAny
};
function getDefaultConfig() {
const getSizesSimple = () => ['sm', 'md', 'lg', 'xl', '2xl'];
const getSizesExtended = () => ['3xl', '4xl', '5xl', '6xl', '7xl'];
const getOverscroll = () => ['auto', 'contain', 'none'];
const getOverflow = () => ['auto', 'hidden', 'visible', 'scroll'];
const getLength = () => [isLength];
const getLengthWithAuto = () => ['auto', isLength];
const getLengthWithEmpty = () => ['', isLength];
const getInteger = () => [isInteger];
const getIntegerWithAuto = () => ['auto', isInteger];
const getAny = () => [isAny];
const getPositions = () => ['bottom', 'center', 'left', 'left-bottom', 'left-top', 'right', 'right-bottom', 'right-top', 'top'];
const getRounded = () => ['none', '', ...getSizesSimple(), '3xl', 'full', isCustomLength];
const getBorderStyles = () => ['solid', 'dashed', 'dotted', 'double', 'none'];
const getBlendModes = () => [{
blend: ['normal', 'multiply', 'screen', 'overlay', 'darken', 'lighten', 'color-dodge', 'color-burn', 'hard-light', 'soft-light', 'difference', 'exclusion', 'hue', 'saturation', 'color', 'luminosity']
}];
const getAlign = () => ['start', 'end', 'center', 'between', 'around', 'evenly'];
const getZeroAndEmpty = () => ['', '0'];
return {
cacheSize: 500,
classGroups: {
// Layout
/**
* Container
* @see https://tailwindcss.com/docs/container
*/
container: ['container'],
/**
* Box Decoration Break
* @see https://tailwindcss.com/docs/box-decoration-break
*/
decoration: [{
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'],
/**
* Floats
* @see https://tailwindcss.com/docs/float
*/
float: [{
float: ['right', 'left', 'none']
}],
/**
* Clear
* @see https://tailwindcss.com/docs/clear
*/
clear: [{
clear: ['left', 'right', 'both', 'none']
}],
/**
* 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: getPositions()
}],
/**
* Overflow
* @see https://tailwindcss.com/docs/overflow
*/
overflow: [{
overflow: getOverflow()
}],
/**
* Overflow X
* @see https://tailwindcss.com/docs/overflow
*/
'overflow-x': [{
'overflow-x': getOverflow()
}],
/**
* Overflow Y
* @see https://tailwindcss.com/docs/overflow
*/
'overflow-y': [{
'overflow-y': getOverflow()
}],
/**
* Overscroll Behavior
* @see https://tailwindcss.com/docs/overscroll-behavior
*/
overscroll: [{
overscroll: getOverscroll()
}],
/**
* Overscroll Behavior X
* @see https://tailwindcss.com/docs/overscroll-behavior
*/
'overscroll-x': [{
'overscroll-x': getOverscroll()
}],
/**
* Overscroll Behavior Y
* @see https://tailwindcss.com/docs/overscroll-behavior
*/
'overscroll-y': [{
'overscroll-y': getOverscroll()
}],
/**
* 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: getLengthWithAuto()
}],
/**
* Right / Left
* @see https://tailwindcss.com/docs/top-right-bottom-left
*/
'inset-x': [{
'inset-x': getLengthWithAuto()
}],
/**
* Top / Bottom
* @see https://tailwindcss.com/docs/top-right-bottom-left
*/
'inset-y': [{
'inset-y': getLengthWithAuto()
}],
/**
* Top
* @see https://tailwindcss.com/docs/top-right-bottom-left
*/
top: [{
top: getLengthWithAuto()
}],
/**
* Right
* @see https://tailwindcss.com/docs/top-right-bottom-left
*/
right: [{
right: getLengthWithAuto()
}],
/**
* Bottom
* @see https://tailwindcss.com/docs/top-right-bottom-left
*/
bottom: [{
bottom: getLengthWithAuto()
}],
/**
* Left
* @see https://tailwindcss.com/docs/top-right-bottom-left
*/
left: [{
left: getLengthWithAuto()
}],
/**
* Visibility
* @see https://tailwindcss.com/docs/visibility
*/
visibility: ['visible', 'invisible'],
/**
* Z-Index
* @see https://tailwindcss.com/docs/z-index
*/
z: [{
z: getLength()
}],
// Flexbox and Grid
/**
* 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: ['wrap', 'wrap-reverse', 'nowrap']
}],
/**
* Flex
* @see https://tailwindcss.com/docs/flex
*/
flex: [{
flex: ['1', 'auto', 'initial', 'none', isCustomValue]
}],
/**
* Flex Grow
* @see https://tailwindcss.com/docs/flex-grow
*/
'flex-grow': [{
'flex-grow': ['', isInteger]
}],
/**
* Flex Shrink
* @see https://tailwindcss.com/docs/flex-shrink
*/
'flex-shrink': [{
'flex-shrink': ['', isInteger]
}],
/**
* Order
* @see https://tailwindcss.com/docs/order
*/
order: [{
order: ['first', 'last', 'none', isInteger]
}],
/**
* Grid Template Columns
* @see https://tailwindcss.com/docs/grid-template-columns
*/
'grid-cols': [{
'grid-cols': getAny()
}],
/**
* Grid Column Start / End
* @see https://tailwindcss.com/docs/grid-column
*/
'col-start-end': [{
col: ['auto', {
span: getInteger()
}]
}],
/**
* Grid Column Start
* @see https://tailwindcss.com/docs/grid-column
*/
'col-start': [{
'col-start': getIntegerWithAuto()
}],
/**
* Grid Column End
* @see https://tailwindcss.com/docs/grid-column
*/
'col-end': [{
'col-end': getIntegerWithAuto()
}],
/**
* Grid Template Rows
* @see https://tailwindcss.com/docs/grid-template-rows
*/
'grid-rows': [{
'grid-rows': getAny()
}],
/**
* Grid Row Start / End
* @see https://tailwindcss.com/docs/grid-row
*/
'row-start-end': [{
row: ['auto', {
span: getInteger()
}]
}],
/**
* Grid Row Start
* @see https://tailwindcss.com/docs/grid-row
*/
'row-start': [{
'row-start': getIntegerWithAuto()
}],
/**
* Grid Row End
* @see https://tailwindcss.com/docs/grid-row
*/
'row-end': [{
'row-end': getIntegerWithAuto()
}],
/**
* Grid Auto Flow
* @see https://tailwindcss.com/docs/grid-auto-flow
*/
'grid-flow': [{
'grid-flow': ['row', 'col', 'row-dense', 'col-dense']
}],
/**
* Grid Auto Columns
* @see https://tailwindcss.com/docs/grid-auto-columns
*/
'auto-cols': [{
'auto-cols': ['auto', 'min', 'max', 'fr', isCustomValue]
}],
/**
* Grid Auto Rows
* @see https://tailwindcss.com/docs/grid-auto-rows
*/
'auto-rows': [{
'auto-rows': ['auto', 'min', 'max', 'fr', isCustomValue]
}],
/**
* Gap
* @see https://tailwindcss.com/docs/gap
*/
gap: [{
gap: getLength()
}],
/**
* Gap X
* @see https://tailwindcss.com/docs/gap
*/
'gap-x': [{
'gap-x': getLength()
}],
/**
* Gap Y
* @see https://tailwindcss.com/docs/gap
*/
'gap-y': [{
'gap-y': getLength()
}],
/**
* Justify Content
* @see https://tailwindcss.com/docs/justify-content
*/
'justify-content': [{
justify: getAlign()
}],
/**
* Justify Items
* @see https://tailwindcss.com/docs/justify-items
*/
'justify-items': [{
'justify-items': ['start', 'end', 'center', 'stretch']
}],
/**
* Justify Self
* @see https://tailwindcss.com/docs/justify-self
*/
'justify-self': [{
'justify-self': ['auto', 'start', 'end', 'center', 'stretch']
}],
/**
* Align Content
* @see https://tailwindcss.com/docs/align-content
*/
'align-content': [{
content: getAlign()
}],
/**
* Align Items
* @see https://tailwindcss.com/docs/align-items
*/
'align-items': [{
items: ['start', 'end', 'center', 'baseline', 'stretch']
}],
/**
* Align Self
* @see https://tailwindcss.com/docs/align-self
*/
'align-self': [{
self: ['auto', 'start', 'end', 'center', 'stretch', 'baseline']
}],
/**
* Place Content
* @see https://tailwindcss.com/docs/place-content
*/
'place-content': [{
'place-content': [...getAlign(), 'stretch']
}],
/**
* Place Items
* @see https://tailwindcss.com/docs/place-items
*/
'place-items': [{
'place-items': ['start', 'end', 'center', 'stretch']
}],
/**
* Place Self
* @see https://tailwindcss.com/docs/place-self
*/
'place-self': [{
'place-self': ['auto', 'start', 'end', 'center', 'stretch']
}],
// Spacing
/**
* Padding
* @see https://tailwindcss.com/docs/padding
*/
p: [{
p: getLength()
}],
/**
* Padding X
* @see https://tailwindcss.com/docs/padding
*/
px: [{
px: getLength()
}],
/**
* Padding Y
* @see https://tailwindcss.com/docs/padding
*/
py: [{
py: getLength()
}],
/**
* Padding Top
* @see https://tailwindcss.com/docs/padding
*/
pt: [{
pt: getLength()
}],
/**
* Padding Right
* @see https://tailwindcss.com/docs/padding
*/
pr: [{
pr: getLength()
}],
/**
* Padding Bottom
* @see https://tailwindcss.com/docs/padding
*/
pb: [{
pb: getLength()
}],
/**
* Padding Left
* @see https://tailwindcss.com/docs/padding
*/
pl: [{
pl: getLength()
}],
/**
* Margin
* @see https://tailwindcss.com/docs/margin
*/
m: [{
m: getLengthWithAuto()
}],
/**
* Margin X
* @see https://tailwindcss.com/docs/margin
*/
mx: [{
mx: getLengthWithAuto()
}],
/**
* Margin Y
* @see https://tailwindcss.com/docs/margin
*/
my: [{
my: getLengthWithAuto()
}],
/**
* Margin Top
* @see https://tailwindcss.com/docs/margin
*/
mt: [{
mt: getLengthWithAuto()
}],
/**
* Margin Right
* @see https://tailwindcss.com/docs/margin
*/
mr: [{
mr: getLengthWithAuto()
}],
/**
* Margin Bottom
* @see https://tailwindcss.com/docs/margin
*/
mb: [{
mb: getLengthWithAuto()
}],
/**
* Margin Left
* @see https://tailwindcss.com/docs/margin
*/
ml: [{
ml: getLengthWithAuto()
}],
/**
* Space Between X
* @see https://tailwindcss.com/docs/space
*/
'space-x': [{
'space-x': getLength()
}],
/**
* Space Between X Reverse
* @see https://tailwindcss.com/docs/space
*/
'space-x-reverse': ['space-x-reverse'],
/**
* Space Between Y
* @see https://tailwindcss.com/docs/space
*/
'space-y': [{
'space-y': getLength()
}],
/**
* Space Between Y Reverse
* @see https://tailwindcss.com/docs/space
*/
'space-y-reverse': ['space-y-reverse'],
// Sizing
/**
* Width
* @see https://tailwindcss.com/docs/width
*/
w: [{
w: ['auto', 'min', 'max', isLength]
}],
/**
* Min-Width
* @see https://tailwindcss.com/docs/min-width
*/
'min-w': [{
'min-w': ['full', 'min', 'max', isLength]
}],
/**
* Max-Width
* @see https://tailwindcss.com/docs/max-width
*/
'max-w': [{
'max-w': ['0', 'none', ...getSizesSimple(), ...getSizesExtended(), 'full', 'min', 'max', 'prose', {
screen: getSizesSimple()
}, isCustomLength]
}],
/**
* Height
* @see https://tailwindcss.com/docs/height
*/
h: [{
h: getLengthWithAuto()
}],
/**
* Min-Height
* @see https://tailwindcss.com/docs/min-height
*/
'min-h': [{
'min-h': ['full', 'screen', isLength]
}],
/**
* Max-Height
* @see https://tailwindcss.com/docs/max-height
*/
'max-h': [{
'max-h': getLength()
}],
// Typography
/**
* Font Family
* @see https://tailwindcss.com/docs/font-family
*/
'font-family': [{
font: getAny()
}],
/**
* Font Size
* @see https://tailwindcss.com/docs/font-size
*/
'font-size': [{
text: ['xs', ...getSizesSimple(), 'base', ...getSizesExtended(), '8xl', '9xl', isCustomLength]
}],
/**
* 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: ['thin', 'extralight', 'light', 'normal', 'medium', 'semibold', 'bold', 'extrabold', 'black']
}],
/**
* 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-fractons'],
/**
* Letter Spacing
* @see https://tailwindcss.com/docs/letter-spacing
*/
tracking: [{
tracking: ['tighter', 'tight', 'normal', 'wide', 'wider', 'widest', isCustomLength]
}],
/**
* Line Height
* @see https://tailwindcss.com/docs/line-height
*/
leading: [{
leading: ['none', 'tight', 'snug', 'normal', 'relaxed', 'loose', isLength]
}],
/**
* List Style Type
* @see https://tailwindcss.com/docs/list-style-type
*/
'list-style-type': [{
list: ['none', 'disc', 'decimal', isCustomValue]
}],
/**
* List Style Position
* @see https://tailwindcss.com/docs/list-style-position
*/
'list-style-position': [{
list: ['inside', 'outside']
}],
/**
* Placeholder Color
* @see https://tailwindcss.com/docs/placeholder-color
*/
'placeholder-color': [{
placeholder: getAny()
}],
/**
* Placeholder Opacity
* @see https://tailwindcss.com/docs/placeholder-opacity
*/
'placeholder-opacity': [{
'placeholder-opacity': getInteger()
}],
/**
* Text Alignment
* @see https://tailwindcss.com/docs/text-align
*/
'text-alignment': [{
text: ['left', 'center', 'right', 'justify']
}],
/**
* Text Color
* @see https://tailwindcss.com/docs/text-color
*/
'text-color': [{
text: getAny()
}],
/**
* Text Opacity
* @see https://tailwindcss.com/docs/text-opacity
*/
'text-opacity': [{
'text-opacity': getInteger()
}],
/**
* Text Decoration
* @see https://tailwindcss.com/docs/text-decoration
*/
'text-decoration': ['underline', 'line-through', 'no-underline'],
/**
* Text Transform
* @see https://tailwindcss.com/docs/text-transform
*/
'text-transform': ['uppercase', 'lowercase', 'capitalize', 'normal-case'],
/**
* Text Overflow
* @see https://tailwindcss.com/docs/text-overflow
*/
'text-overflow': ['truncate', 'overflow-ellipsis', 'overflow-clip'],
/**
* Vertical Alignment
* @see https://tailwindcss.com/docs/vertical-align
*/
'vertival-alignment': [{
align: ['baseline', 'top', 'middle', 'bottom', 'text-top', 'text-bottom']
}],
/**
* Whitespace
* @see https://tailwindcss.com/docs/whitespace
*/
whitespace: [{
whitespace: ['normal', 'nowrap', 'pre', 'pre-line', 'pre-wrap']
}],
/**
* Word Break
* @see https://tailwindcss.com/docs/word-break
*/
break: [{
break: ['normal', 'words', 'all']
}],
// Backgrounds
/**
* Background Attachment
* @see https://tailwindcss.com/docs/background-attachment
*/
'bg-attachment': [{
bg: ['fixed', 'local', 'scroll']
}],
/**
* Background Clip
* @see https://tailwindcss.com/docs/background-clip
*/
'bg-clip': [{
'bg-clip': ['border', 'padding', 'content', 'text']
}],
/**
* Background Opacity
* @see https://tailwindcss.com/docs/background-opacity
*/
'bg-opacity': [{
'bg-opacity': getInteger()
}],
/**
* Background Origin
* @see https://tailwindcss.com/docs/background-origin
*/
'bg-origin': [{
'bg-origin': ['border', 'padding', 'content']
}],
/**
* Background Position
* @see https://tailwindcss.com/docs/background-position
*/
'bg-position': [{
bg: getPositions()
}],
/**
* Background Repeat
* @see https://tailwindcss.com/docs/background-repeat
*/
'bg-repeeat': [{
bg: ['no-repeat', {
repeat: ['', 'x', 'y', 'round', 'space']
}]
}],
/**
* Background Size
* @see https://tailwindcss.com/docs/background-size
*/
'bg-size': [{
bg: ['auto', 'cover', 'contain']
}],
/**
* Background Image
* @see https://tailwindcss.com/docs/background-image
*/
'bg-image': [{
bg: ['none', {
'gradient-to': ['t', 'tr', 'r', 'br', 'b', 'bl', 'l', 'tl']
}]
}],
/**
* Background Blend Mode
* @see https://tailwindcss.com/docs/background-blend-mode
*/
'bg-blend': [{
bg: getBlendModes()
}],
/**
* Background Color
* @see https://tailwindcss.com/docs/background-color
*/
'bg-color': [{
bg: getAny()
}],
/**
* Gradient Color Stops From
* @see https://tailwindcss.com/docs/gradient-color-stops
*/
'gradient-from': [{
from: getAny()
}],
/**
* Gradient Color Stops Via
* @see https://tailwindcss.com/docs/gradient-color-stops
*/
'gradient-via': [{
via: getAny()
}],
/**
* Gradient Color Stops To
* @see https://tailwindcss.com/docs/gradient-color-stops
*/
'gradient-to': [{
to: getAny()
}],
// Borders
/**
* Border Radius
* @see https://tailwindcss.com/docs/border-radius
*/
rounded: [{
rounded: getRounded()
}],
/**
* Border Radius Top
* @see https://tailwindcss.com/docs/border-radius
*/
'rounded-t': [{
'rounded-t': getRounded()
}],
/**
* Border Radius Right
* @see https://tailwindcss.com/docs/border-radius
*/
'rounded-r': [{
'rounded-r': getRounded()
}],
/**
* Border Radius Bottom
* @see https://tailwindcss.com/docs/border-radius
*/
'rounded-b': [{
'rounded-b': getRounded()
}],
/**
* Border Radius Left
* @see https://tailwindcss.com/docs/border-radius
*/
'rounded-l': [{
'rounded-l': getRounded()
}],
/**
* Border Radius Top Left
* @see https://tailwindcss.com/docs/border-radius
*/
'rounded-tl': [{
'rounded-tl': getRounded()
}],
/**
* Border Radius Top Right
* @see https://tailwindcss.com/docs/border-radius
*/
'rounded-tr': [{
'rounded-tr': getRounded()
}],
/**
* Border Radius Bottom Right
* @see https://tailwindcss.com/docs/border-radius
*/
'rounded-br': [{
'rounded-br': getRounded()
}],
/**
* Border Radius Bottom Left
* @see https://tailwindcss.com/docs/border-radius
*/
'rounded-bl': [{
'rounded-bl': getRounded()
}],
/**
* Border Width
* @see https://tailwindcss.com/docs/border-width
*/
'border-w': [{
border: getLengthWithEmpty()
}],
/**
* Border Width Top
* @see https://tailwindcss.com/docs/border-width
*/
'border-w-t': [{
'border-t': getLengthWithEmpty()
}],
/**
* Border Width Right
* @see https://tailwindcss.com/docs/border-width
*/
'border-w-r': [{
'border-r': getLengthWithEmpty()
}],
/**
* Border Width Bottom
* @see https://tailwindcss.com/docs/border-width
*/
'border-w-b': [{
'border-b': getLengthWithEmpty()
}],
/**
* Border Width Left
* @see https://tailwindcss.com/docs/border-width
*/
'border-w-l': [{
'border-l': getLengthWithEmpty()
}],
/**
* Border Opacity
* @see https://tailwindcss.com/docs/border-opacity
*/
'border-opacity': [{
'border-opacity': getInteger()
}],
/**
* Border Style
* @see https://tailwindcss.com/docs/border-style
*/
'border-style': [{
border: getBorderStyles()
}],
/**
* Divide Width X
* @see https://tailwindcss.com/docs/divide-width
*/
'divide-x': [{
'divide-x': getLengthWithEmpty()
}],
/**
* Divide Width X Reverse
* @see https://tailwindcss.com/docs/divide-width
*/
'divide-x-reverse': ['divide-x-reverse'],
/**
* Divide Width Y
* @see https://tailwindcss.com/docs/divide-width
*/
'divide-y': [{
'divide-y': getLengthWithEmpty()
}],
/**
* Divide Width Y Reverse
* @see https://tailwindcss.com/docs/divide-width
*/
'divide-y-reverse': ['divide-y-reverse'],
/**
* Divide Opacity
* @see https://tailwindcss.com/docs/divide-opacity
*/
'divide-opacity': [{
'divide-opacity': getInteger()
}],
/**
* Divide Style
* @see https://tailwindcss.com/docs/divide-style
*/
'divide-style': [{
divide: getBorderStyles()
}],
/**
* Border Color
* @see https://tailwindcss.com/docs/border-color
*/
'border-color': [{
border: getAny()
}],
/**
* Border Color Top
* @see https://tailwindcss.com/docs/border-color
*/
'border-color-t': [{
'border-t': getAny()
}],
/**
* Border Color Right
* @see https://tailwindcss.com/docs/border-color
*/
'border-color-r': [{
'border-r': getAny()
}],
/**
* Border Color Bottom
* @see https://tailwindcss.com/docs/border-color
*/
'border-color-b': [{
'border-b': getAny()
}],
/**
* Border Color Left
* @see https://tailwindcss.com/docs/border-color
*/
'border-color-l': [{
'border-l': getAny()
}],
/**
* Divide Color
* @see https://tailwindcss.com/docs/divide-color
*/
'divide-color': [{
divide: getAny()
}],
/**
* Ring Width
* @see https://tailwindcss.com/docs/ring-width
*/
'ring-w': [{
ring: getLengthWithEmpty()
}],
/**
* Ring Width Inset
* @see https://tailwindcss.com/docs/ring-width
*/
'ring-w-inset': ['ring-inset'],
/**
* Ring Color
* @see https://tailwindcss.com/docs/ring-color
*/
'ring-color': [{
ring: getAny()
}],
/**
* Ring Opacity
* @see https://tailwindcss.com/docs/ring-opacity
*/
'ring-opacity': [{
'ring-opacity': getInteger()
}],
/**
* Ring Offset Width
* @see https://tailwindcss.com/docs/ring-offset-width
*/
'ring-offset-w': [{
'ring-offset': getLength()
}],
/**
* Ring Offset Color
* @see https://tailwindcss.com/docs/ring-offset-color
*/
'ring-offset-color': [{
'ring-offset': getAny()
}],
// Effects
/**
* Box Shadow
* @see https://tailwindcss.com/docs/box-shadow
*/
shadow: [{
shadow: ['', ...getSizesSimple(), 'inner', 'none']
}],
/**
* Opacity
* @see https://tailwindcss.com/docs/opacity
*/
opacity: [{
opacity: getInteger()
}],
/**
* Mix Beldn Mode
* @see https://tailwindcss.com/docs/mix-blend-mode
*/
'mix-blend': [{
'mix-blend': getBlendModes()
}],
// Filters
/**
* Filter
* @see https://tailwindcss.com/docs/filter
*/
filter: [{
filter: ['', 'none']
}],
/**
* Blur
* @see https://tailwindcss.com/docs/blur
*/
blur: [{
blur: ['none', '', ...getSizesSimple(), '3xl', isCustomLength]
}],
/**
* Brightness
* @see https://tailwindcss.com/docs/brightness
*/
brightness: [{
brightness: getInteger()
}],
/**
* Contrast
* @see https://tailwindcss.com/docs/contrast
*/
contrast: [{
contrast: getInteger()
}],
/**
* Drop Shadow
* @see https://tailwindcss.com/docs/drop-shadow
*/
'drop-shadow': [{
'drop-shadow': ['', ...getSizesSimple(), 'none']
}],
/**
* Grayscale
* @see https://tailwindcss.com/docs/grayscale
*/
grayscale: [{
grayscale: getZeroAndEmpty()
}],
/**
* Hue Rotate
* @see https://tailwindcss.com/docs/hue-rotate
*/
'hue-rotate': [{
'hue-rotate': getInteger()
}],
/**
* Invert
* @see https://tailwindcss.com/docs/invert
*/
invert: [{
invert: getZeroAndEmpty()
}],
/**
* Saturate
* @see https://tailwindcss.com/docs/saturate
*/
saturate: [{
saturate: getInteger()
}],
/**
* Sepia
* @see https://tailwindcss.com/docs/sepia
*/
sepia: [{
sepia: getZeroAndEmpty()
}],
/**
* Backdrop Filter
* @see https://tailwindcss.com/docs/backdrop-filter
*/
'backdrop-filter': [{
'backdrop-filter': ['', 'none']
}],
/**
* Backdrop Blur
* @see https://tailwindcss.com/docs/backdrop-blur
*/
'backdrop-blur': [{
'backdrop-blur': ['none', '', ...getSizesSimple(), '3xl']
}],
/**
* Backdrop Brightness
* @see https://tailwindcss.com/docs/backdrop-brightness
*/
'backdrop-brightness': [{
'backdrop-brightness': getInteger()
}],
/**
* Backdrop Contrast
* @see https://tailwindcss.com/docs/backdrop-contrast
*/
'backdrop-contrast': [{
'backdrop-contrast': getInteger()
}],
/**
* Backdrop Grayscale
* @see https://tailwindcss.com/docs/backdrop-grayscale
*/
'backdrop-grayscale': [{
'backdrop-grayscale': getZeroAndEmpty()
}],
/**
* Backdrop Hue Rotate
* @see https://tailwindcss.com/docs/backdrop-hue-rotate
*/
'backdrop-hue-rotate': [{
'backdrop-hue-rotate': getInteger()
}],
/**
* Backdrop Invert
* @see https://tailwindcss.com/docs/backdrop-invert
*/
'backdrop-invert': [{
'backdrop-invert': getZeroAndEmpty()
}],
/**
* Backdrop Opacity
* @see https://tailwindcss.com/docs/backdrop-opacity
*/
'backdrop-opacity': [{
'backdrop-opacity': getInteger()
}],
/**
* Backdrop Saturate
* @see https://tailwindcss.com/docs/backdrop-saturate
*/
'backdrop-saturate': [{
'backdrop-saturate': getInteger()
}],
/**
* Backdrop Sepia
* @see https://tailwindcss.com/docs/backdrop-sepia
*/
'backdrop-sepia': [{
'backdrop-sepia': getZeroAndEmpty()
}],
// Tables
/**
* Border Collapse
* @see https://tailwindcss.com/docs/border-collapse
*/
'border-collapse': [{
border: ['collapse', 'separate']
}],
/**
* Table Layout
* @see https://tailwindcss.com/docs/table-layout
*/
'table-layout': [{
table: ['auto', 'fixed']
}],
// Transitions and Animation
/**
* Tranisition Property
* @see https://tailwindcss.com/docs/transition-property
*/
transition: [{
transition: ['none', 'all', '', 'colors', 'opacity', 'shadow', 'transform', isCustomValue]
}],
/**
* Transition Duration
* @see https://tailwindcss.com/docs/transition-duration
*/
duration: [{
duration: getInteger()
}],
/**
* Transition Timing Function
* @see https://tailwindcss.com/docs/transition-timing-function
*/
ease: [{
ease: ['linear', 'in', 'out', 'in-out', isCustomValue]
}],
/**
* Transition Delay
* @see https://tailwindcss.com/docs/transition-delay
*/
delay: [{
delay: getInteger()
}],
/**
* Animation
* @see https://tailwindcss.com/docs/animation
*/
animate: [{
animate: ['none', 'spin', 'ping', 'pulse', 'bounce', isCustomValue]
}],
// Transforms
/**
* Transform
* @see https://tailwindcss.com/docs/transform
*/
transform: [{
transform: ['', 'gpu', 'none']
}],
/**
* Transform Origin
* @see https://tailwindcss.com/docs/transform-origin
*/
'transform-origin': [{
origin: ['center', 'top', 'top-right', 'right', 'bottom-right', 'bottom', 'bottom-left', 'left', 'top-left']
}],
/**
* Scale
* @see https://tailwindcss.com/docs/scale
*/
scale: [{
scale: getInteger()
}],
/**
* Scale X
* @see https://tailwindcss.com/docs/scale
*/
'scale-x': [{
'scale-x': getInteger()
}],
/**
* Scale Y
* @see https://tailwindcss.com/docs/scale
*/
'scale-y': [{
'scale-y': getInteger()
}],
/**
* Rotate
* @see https://tailwindcss.com/docs/rotate
*/
rotate: [{
rotate: getInteger()
}],
/**
* Translate X
* @see https://tailwindcss.com/docs/translate
*/
'translate-x': [{
'translate-x': getLength()
}],
/**
* Translate Y
* @see https://tailwindcss.com/docs/translate
*/
'translate-y': [{
'translate-y': getLength()
}],
/**
* Skew X
* @see https://tailwindcss.com/docs/skew
*/
'skew-x': [{
'skew-x': getInteger()
}],
/**
* Skew Y
* @see https://tailwindcss.com/docs/skew
*/
'skew-y': [{
'skew-y': getInteger()
}],
// Interactivity
/**
* Appearance
* @see https://tailwindcss.com/docs/appearance
*/
appearance: ['appearance-none'],
/**
* Cursor
* @see https://tailwindcss.com/docs/cursor
*/
cursor: [{
cursor: ['auto', 'default', 'pointer', 'wait', 'text', 'move', 'help', 'not-allowed', isCustomValue]
}],
/**
* Outline
* @see https://tailwindcss.com/docs/outline
*/
outline: [{
outline: ['none', 'white', 'black']
}],
/**
* Pointer Events
* @see https://tailwindcss.com/docs/pointer-events
*/
'pointer-events': [{
'pointer-events': ['none', 'auto']
}],
/**
* Resize
* @see https://tailwindcss.com/docs/resize
*/
resize: [{
resize: ['none', 'y', 'x', '']
}],
/**
* Select
* @see https://tailwindcss.com/docs/select
*/
select: [{
select: ['none', 'text', 'all', 'auto']
}],
// SVG
/**
* Fill
* @see https://tailwindcss.com/docs/fill
*/
fill: [{
fill: ['current', isCustomValue]
}],
/**
* Stroke
* @see https://tailwindcss.com/docs/stroke
*/
stroke: [{
stroke: ['current', isCustomValue]
}],
/**
* Stroke Width
* @see https://tailwindcss.com/docs/stroke-width
*/
'stroke-w': [{
stroke: getLength()
}],
// Accessibility
/**
* Screen Readers
* @see https://tailwindcss.com/docs/screen-readers
*/
sr: ['sr-only', 'not-sr-only'],
// Just-in-Time Mode
/**
* Content
* @see https://tailwindcss.com/docs/just-in-time-mode#content-utilities
*/
content: [{
content: [isCustomValue]
}],
/**
* Caret Color
* @see https://tailwindcss.com/docs/just-in-time-mode#caret-color-utilities
*/
'caret-color': [{
caret: getAny()
}]
},
conflictingClassGroups: {
overflow: ['overflow-x', 'overflow-y'],
overscroll: ['overscroll-x', 'overscroll-y'],
inset: ['inset-x', 'inset-y', 'top', 'right', 'bottom', 'left'],
'inset-x': ['right', 'left'],
'inset-y': ['top', 'bottom'],
flex: ['flex-grow', 'flex-shrink'],
'col-start-end': ['col-start', 'col-end'],
'row-start-end': ['row-start', 'row-end'],
gap: ['gap-x', 'gap-y'],
p: ['px', 'py', 'pt', 'pr', 'pb', 'pl'],
px: ['pr', 'pl'],
py: ['pt', 'pb'],
m: ['mx', 'my', 'mt', 'mr', 'mb', 'ml'],
mx: ['mr', 'ml'],
my: ['mt', 'mb'],
'font-size': ['leading'],
'fvn-normal': ['fvn-ordinal', 'fvn-slashed-zero', 'fvn-figure', 'fvn-spacing', 'fvn-fraction'],
'fvn-ordinal': ['fvn-normal'],
'fvn-slashed-zero': ['fvn-normal'],
'fvn-figure': ['fvn-normal'],
'fvn-spacing': ['fvn-normal'],
'fvn-fraction': ['fvn-normal'],
rounded: ['rounded-t', 'rounded-r', 'rounded-b', 'rounded-l', 'rounded-tl', 'rounded-tr', 'rounded-br', 'rounded-bl'],
'rounded-t': ['rounded-tl', 'rounded-tr'],
'rounded-r': ['rounded-tr', 'rounded-br'],
'rounded-b': ['rounded-br', 'rounded-bl'],
'rounded-l': ['rounded-tl', 'rounded-bl'],
'border-w': ['border-w-t', 'border-w-r', 'border-w-b', 'border-w-l'],
'border-color': ['border-color-t', 'border-color-r', 'border-color-b', 'border-color-l']
}
};
}
/**
* @param baseConfig Config where other config will be merged into. This object will be mutated.
* @param configExtension Partial config to merge into the `baseConfig`.
*/
function mergeConfigs(baseConfig, configExtension) {
for (const key in configExtension) {
mergePropertyRecursively(baseConfig, key, configExtension[key]);
}
return baseConfig;
}
const hasOwnProperty = Object.prototype.hasOwnProperty;
const overrideTypes = new Set(['string', 'number', 'boolean']);
function mergePropertyRecursively(baseObject, mergeKey, mergeValue) {
if (!hasOwnProperty.call(baseObject, mergeKey) || overrideTypes.has(typeof mergeValue) || mergeValue === null) {
baseObject[mergeKey] = mergeValue;
return;
}
if (Array.isArray(mergeValue) && Array.isArray(baseObject[mergeKey])) {
baseObject[mergeKey] = baseObject[mergeKey].concat(mergeValue);
return;
}
if (typeof mergeValue === 'object' && typeof baseObject[mergeKey] === 'object') {
if (baseObject[mergeKey] === null) {
baseObject[mergeKey] = mergeValue;
return;
}
for (const nextKey in mergeValue) {
mergePropertyRecursively(baseObject[mergeKey], nextKey, mergeValue[nextKey]);
}
}
}
function extendTailwindMerge(configExtension, ...createConfig) {
return typeof configExtension === 'function' ? createTailwindMerge(getDefaultConfig, configExtension, ...createConfig) : createTailwindMerge(() => mergeConfigs(getDefaultConfig(), configExtension), ...createConfig);
}
const twMerge = createTailwindMerge(getDefaultConfig);
export { createTailwindMerge, extendTailwindMerge, getDefaultConfig, mergeConfigs, twMerge, validators };
//# sourceMappingURL=index.js.map