Socket
Socket
Sign inDemoInstall

tailwind-merge

Package Overview
Dependencies
Maintainers
1
Versions
276
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tailwind-merge - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

dist/index.cjs

1658

dist/index.js

@@ -1,4 +0,1654 @@

import { createTailwindMerge } from './tailwind-merge';
export const twMerge = createTailwindMerge((defaultConfig) => defaultConfig());
export { createTailwindMerge };
//# sourceMappingURL=index.js.map
import HLRU from 'hashlru';
const CLASS_PART_SEPARATOR = '-';
function createClassUtils(config) {
const classMap = {
nextPart: {},
validators: []
};
processStandaloneClasses(config, classMap);
const processDynamicClasses = createProcessDynamicClasses(config, classMap);
function getGroup(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();
}
processDynamicClasses(classParts[0]);
return getGroupRecursive(classParts, classMap);
}
function getConflictingGroups(classGroupId) {
return config.conflictingGroups[classGroupId] || [];
}
return {
getGroup,
getConflictingGroups
};
}
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;
}
function processStandaloneClasses(config, classMap) {
config.standaloneClasses.forEach((classGroup, index) => {
const classGroupId = `standaloneClasses.${index}`;
classGroup.forEach(className => {
addToClassPart({
classPartObject: classMap,
path: className,
classGroupId
});
});
});
}
function createProcessDynamicClasses(config, classMap) {
const {
dynamicClasses
} = config;
const processedKeys = new Set();
return function processDynamicClasses(key) {
if (processedKeys.has(key) || dynamicClasses[key] === undefined) {
return;
}
const classPartObject = getNextPart(classMap, key);
dynamicClasses[key].forEach((classGroup, index) => {
processClassesRecursively(classGroup, classPartObject, `dynamicClasses.${key}.${index}`);
});
};
}
function processClassesRecursively(classGroup, classPartObject, classGroupId) {
classGroup.forEach(classDefinition => {
if (typeof classDefinition === 'string') {
addToClassPart({
classPartObject,
// We default to undefined to set classGroupId on current classPartObject when classDefinition === ''
path: classDefinition === '' ? undefined : classDefinition,
classGroupId
});
} else if (typeof classDefinition === 'function') {
addToClassPart({
classPartObject,
validator: {
validator: classDefinition,
classGroupId
}
});
} else {
Object.entries(classDefinition).forEach(([key, classGroup]) => {
processClassesRecursively(classGroup, getNextPart(classPartObject, key), classGroupId);
});
}
});
}
function addToClassPart({
path,
classPartObject,
validator,
classGroupId
}) {
let currentClassPartObject = classPartObject;
path == null ? void 0 : path.split(CLASS_PART_SEPARATOR).forEach(pathPart => {
currentClassPartObject = getNextPart(currentClassPartObject, pathPart);
});
if (classGroupId) {
currentClassPartObject.classGroupId = classGroupId;
}
if (validator) {
currentClassPartObject.validators.push(validator);
}
}
function getNextPart(classPartObject, nextPart) {
if (classPartObject.nextPart[nextPart] === undefined) {
classPartObject.nextPart[nextPart] = {
nextPart: {},
validators: []
};
}
return classPartObject.nextPart[nextPart];
}
function createPrefixUtils(config) {
const prefixToIndexMap = Object.fromEntries(config.prefixes.map((prefix, index) => [prefix, index]));
function isValid(maybePrefix) {
return prefixToIndexMap[maybePrefix] !== undefined;
}
function compare(firstPrefix, secondPrefix) {
return prefixToIndexMap[firstPrefix] - prefixToIndexMap[secondPrefix];
}
return {
isValid,
compare
};
}
function createConfigUtils(config) {
return {
prefix: createPrefixUtils(config),
class: createClassUtils(config)
};
}
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) {
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 !Number.isNaN(Number(classPart)) || stringLengths.has(classPart) || fractionRegex.test(classPart);
}
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 isAny() {
return true;
}
const SIZES_SIMPLE = ['sm', 'md', 'lg', 'xl', '2xl'];
const SIZES_EXTENDED = ['3xl', '4xl', '5xl', '6xl', '7xl'];
const OVERSCROLL = ['auto', 'contain', 'none'];
const OVERFLOW = ['auto', 'hidden', 'visible', 'scroll'];
const LENGTH = [isLength];
const MARGIN = ['auto', isLength];
const INTEGER = [isInteger];
const ANY = [isAny];
const POSITIONS = ['bottom', 'center', 'left', 'left-bottom', 'left-top', 'right', 'right-bottom', 'right-top', 'top'];
const ROUNDED = ['none', '', ...SIZES_SIMPLE, '3xl', 'full'];
const BORDER_STYLES = ['solid', 'dashed', 'dotted', 'double', 'none'];
const BLEND_MODES = [{
blend: ['normal', 'multiply', 'screen', 'overlay', 'darken', 'lighten', 'color-dodge', 'color-burn', 'hard-light', 'soft-light', 'difference', 'exclusion', 'hue', 'saturation', 'color', 'luminosity']
}];
function getDefaultConfig() {
return {
cacheSize: 500,
prefixes: [...SIZES_SIMPLE, 'dark', 'motion-safe', 'motion-reduce', 'first', 'last', 'odd', 'even', 'visited', 'checked', 'group-hover', 'group-focus', 'focus-within', 'hover', 'focus', 'focus-visible', 'active', 'disabled'],
dynamicClasses: {
// Layout
decoration: [
/**
* Box Decoration Break
* @see https://tailwindcss.com/docs/box-decoration-break
*/
['slice', 'clone']],
box: [
/**
* Box Sizing
* @see https://tailwindcss.com/docs/box-sizing
*/
['border', 'content']],
float: [
/**
* Floats
* @see https://tailwindcss.com/docs/float
*/
['right', 'left', 'none']],
clear: [
/**
* Clear
* @see https://tailwindcss.com/docs/clear
*/
['left', 'right', 'both', 'none']],
object: [
/**
* Object Fit
* @see https://tailwindcss.com/docs/object-fit
*/
['contain', 'cover', 'fill', 'none', 'scale-down'],
/**
* Object Position
* @see https://tailwindcss.com/docs/object-position
*/
POSITIONS],
overflow: [
/**
* Overflow
* @see https://tailwindcss.com/docs/overflow
*/
OVERFLOW,
/**
* Overflow X
* @see https://tailwindcss.com/docs/overflow
*/
[{
x: OVERFLOW
}],
/**
* Overflow Y
* @see https://tailwindcss.com/docs/overflow
*/
[{
y: OVERFLOW
}]],
overscroll: [
/**
* Overscroll Behavior
* @see https://tailwindcss.com/docs/overscroll-behavior
*/
OVERSCROLL,
/**
* Overscroll Behavior X
* @see https://tailwindcss.com/docs/overscroll-behavior
*/
[{
x: OVERSCROLL
}],
/**
* Overscroll Behavior Y
* @see https://tailwindcss.com/docs/overscroll-behavior
*/
[{
y: OVERSCROLL
}]],
inset: [
/**
* Right / Left
* @see https://tailwindcss.com/docs/top-right-bottom-left
*/
[{
x: LENGTH
}],
/**
* Top / Bottom
* @see https://tailwindcss.com/docs/top-right-bottom-left
*/
[{
y: LENGTH
}],
/**
* Top / Right / Bottom / Left
* @see https://tailwindcss.com/docs/top-right-bottom-left
*/
LENGTH],
top: [
/**
* Top
* @see https://tailwindcss.com/docs/top-right-bottom-left
*/
LENGTH],
right: [
/**
* Right
* @see https://tailwindcss.com/docs/top-right-bottom-left
*/
LENGTH],
bottom: [
/**
* Bottom
* @see https://tailwindcss.com/docs/top-right-bottom-left
*/
LENGTH],
left: [
/**
* Left
* @see https://tailwindcss.com/docs/top-right-bottom-left
*/
LENGTH],
z: [
/**
* Z-Index
* @see https://tailwindcss.com/docs/z-index
*/
LENGTH],
// Flexbox and Grid
flex: [
/**
* Flex Direction
* @see https://tailwindcss.com/docs/flex-direction
*/
['row', 'row-reverse', 'col', 'col-reverse'],
/**
* Flex Wrap
* @see https://tailwindcss.com/docs/flex-wrap
*/
['wrap', 'wrap-reverse', 'nowrap'],
/**
* Flex
* @see https://tailwindcss.com/docs/flex
*/
['1', 'auto', 'initial', 'none'],
/**
* Flex Grow
* @see https://tailwindcss.com/docs/flex-grow
*/
[{
grow: ['', isInteger]
}],
/**
* Flex Shrink
* @see https://tailwindcss.com/docs/flex-shrink
*/
[{
shrink: ['', isInteger]
}]],
order: [
/**
* Order
* @see https://tailwindcss.com/docs/order
*/
['first', 'last', 'none', isInteger]],
grid: [
/**
* Grid Template Columns
* @see https://tailwindcss.com/docs/grid-template-columns
*/
[{
cols: ANY
}],
/**
* Grid Template Rows
* @see https://tailwindcss.com/docs/grid-template-rows
*/
[{
rows: ANY
}],
/**
* Grid Auto Flow
* @see https://tailwindcss.com/docs/grid-auto-flow
*/
[{
flow: ['row', 'col', 'row-dense', 'col-dense']
}]],
col: [
/**
* Grid Column Start / End
* @see https://tailwindcss.com/docs/grid-column
*/
['auto', {
span: INTEGER
}],
/**
* Grid Column Start
* @see https://tailwindcss.com/docs/grid-column
*/
[{
start: ['auto', isInteger]
}],
/**
* Grid Column End
* @see https://tailwindcss.com/docs/grid-column
*/
[{
end: ['auto', isInteger]
}]],
row: [
/**
* Grid Row Start / End
* @see https://tailwindcss.com/docs/grid-row
*/
['auto', {
span: INTEGER
}],
/**
* Grid Row Start
* @see https://tailwindcss.com/docs/grid-row
*/
[{
start: ['auto', isInteger]
}],
/**
* Grid Row End
* @see https://tailwindcss.com/docs/grid-row
*/
[{
end: ['auto', isInteger]
}]],
auto: [
/**
* Grid Auto Columns
* @see https://tailwindcss.com/docs/grid-auto-columns
*/
[{
cols: ['auto', 'min', 'max', 'fr']
}],
/**
* Grid Auto Rows
* @see https://tailwindcss.com/docs/grid-auto-rows
*/
[{
rows: ['auto', 'min', 'max', 'fr']
}]],
gap: [
/**
* Gap X
* @see https://tailwindcss.com/docs/gap
*/
[{
x: LENGTH
}],
/**
* Gap Y
* @see https://tailwindcss.com/docs/gap
*/
[{
y: LENGTH
}],
/**
* Gap
* @see https://tailwindcss.com/docs/gap
*/
LENGTH],
justify: [
/**
* Justify Content
* @see https://tailwindcss.com/docs/justify-content
*/
['start', 'end', 'center', 'between', 'around', 'evenly'],
/**
* Justify Items
* @see https://tailwindcss.com/docs/justify-items
*/
[{
items: ['start', 'end', 'center', 'stretch']
}],
/**
* Justify Self
* @see https://tailwindcss.com/docs/justify-self
*/
[{
self: ['auto', 'start', 'end', 'center', 'stretch']
}]],
content: [
/**
* Align Content
* @see https://tailwindcss.com/docs/align-content
*/
['center', 'start', 'end', 'between', 'around', 'evenly']],
items: [
/**
* Align Items
* @see https://tailwindcss.com/docs/align-items
*/
['start', 'end', 'center', 'baseline', 'stretch']],
self: [
/**
* Align Self
* @see https://tailwindcss.com/docs/align-self
*/
['auto', 'start', 'end', 'center', 'stretch']],
place: [
/**
* Place Content
* @see https://tailwindcss.com/docs/place-content
*/
[{
content: ['center', 'start', 'end', 'between', 'around', 'evenly', 'stretch']
}],
/**
* Place Items
* @see https://tailwindcss.com/docs/place-items
*/
[{
items: ['start', 'end', 'center', 'stretch']
}],
/**
* Place Self
* @see https://tailwindcss.com/docs/place-self
*/
[{
self: ['auto', 'start', 'end', 'center', 'stretch']
}]],
// Spacing
p: [
/**
* Padding
* @see https://tailwindcss.com/docs/padding
*/
LENGTH],
px: [
/**
* Padding X
* @see https://tailwindcss.com/docs/padding
*/
LENGTH],
py: [
/**
* Padding Y
* @see https://tailwindcss.com/docs/padding
*/
LENGTH],
pt: [
/**
* Padding Top
* @see https://tailwindcss.com/docs/padding
*/
LENGTH],
pr: [
/**
* Padding Right
* @see https://tailwindcss.com/docs/padding
*/
LENGTH],
pb: [
/**
* Padding Bottom
* @see https://tailwindcss.com/docs/padding
*/
LENGTH],
pl: [
/**
* Padding Left
* @see https://tailwindcss.com/docs/padding
*/
LENGTH],
m: [
/**
* Margin
* @see https://tailwindcss.com/docs/margin
*/
MARGIN],
mx: [
/**
* Margin X
* @see https://tailwindcss.com/docs/margin
*/
MARGIN],
my: [
/**
* Margin Y
* @see https://tailwindcss.com/docs/margin
*/
MARGIN],
mt: [
/**
* Margin Top
* @see https://tailwindcss.com/docs/margin
*/
MARGIN],
mr: [
/**
* Margin Right
* @see https://tailwindcss.com/docs/margin
*/
MARGIN],
mb: [
/**
* Margin Bottom
* @see https://tailwindcss.com/docs/margin
*/
MARGIN],
ml: [
/**
* Margin Left
* @see https://tailwindcss.com/docs/margin
*/
MARGIN],
space: [
/**
* Space Between X Reverse
* @see https://tailwindcss.com/docs/space
*/
['x-reverse'],
/**
* Space Between X
* @see https://tailwindcss.com/docs/space
*/
[{
x: LENGTH
}],
/**
* Space Between Y Reverse
* @see https://tailwindcss.com/docs/space
*/
['y-reverse'],
/**
* Space Between Y
* @see https://tailwindcss.com/docs/space
*/
[{
y: LENGTH
}]],
// Sizing
w: [
/**
* Width
* @see https://tailwindcss.com/docs/width
*/
['auto', 'min', 'max', isLength]],
min: [
/**
* Min-Width
* @see https://tailwindcss.com/docs/min-width
*/
[{
w: ['full', 'min', 'max', isLength]
}],
/**
* Min-Height
* @see https://tailwindcss.com/docs/min-height
*/
[{
h: ['full', 'screen', isLength]
}]],
max: [
/**
* Max-Width
* @see https://tailwindcss.com/docs/max-width
*/
[{
w: ['0', 'none', ...SIZES_SIMPLE, ...SIZES_EXTENDED, 'full', 'min', 'max', 'prose', {
screen: SIZES_SIMPLE
}]
}],
/**
* Max-Height
* @see https://tailwindcss.com/docs/max-height
*/
[{
h: ['full', 'screen', isLength]
}]],
h: [
/**
* Height
* @see https://tailwindcss.com/docs/height
*/
['auto', isLength]],
// Typography
font: [
/**
* Font Family
* @see https://tailwindcss.com/docs/font-family
*/
['sans', 'serif', 'mono'],
/**
* Font Weight
* @see https://tailwindcss.com/docs/font-weight
*/
['thin', 'extralight', 'light', 'normal', 'medium', 'semibold', 'bold', 'extrabold', 'black']],
text: [
/**
* Font Size
* @see https://tailwindcss.com/docs/font-size
*/
['xs', ...SIZES_SIMPLE, 'base', ...SIZES_EXTENDED, '8xl', '9xl'],
/**
* Text Alignment
* @see https://tailwindcss.com/docs/text-align
*/
['left', 'center', 'right', 'justify'],
/**
* Text Opacity
* @see https://tailwindcss.com/docs/text-opacity
*/
[{
opacity: INTEGER
}],
/**
* Text Color
* @see https://tailwindcss.com/docs/text-color
*/
ANY],
tracking: [
/**
* Letter Spacing
* @see https://tailwindcss.com/docs/letter-spacing
*/
['tighter', 'tight', 'normal', 'wide', 'wider', 'widest']],
leading: [
/**
* Line Height
* @see https://tailwindcss.com/docs/line-height
*/
['none', 'tight', 'snug', 'normal', 'relaxed', 'loose', isLength]],
list: [
/**
* List Style Type
* @see https://tailwindcss.com/docs/list-style-type
*/
['none', 'disc', 'decimal'],
/**
* List Style Position
* @see https://tailwindcss.com/docs/list-style-position
*/
['inside', 'outside']],
placeholder: [
/**
* Placeholder Opacity
* @see https://tailwindcss.com/docs/placeholder-opacity
*/
[{
opacity: INTEGER
}],
/**
* Placeholder Color
* @see https://tailwindcss.com/docs/placeholder-color
*/
ANY],
align: [
/**
* Vertical Alignment
* @see https://tailwindcss.com/docs/vertical-align
*/
['baseline', 'top', 'middle', 'bottom', 'text-top', 'text-bottom']],
whitespace: [
/**
* Whitespace
* @see https://tailwindcss.com/docs/whitespace
*/
['normal', 'nowrap', 'pre', 'pre-line', 'pre-wrap']],
break: [
/**
* Word Break
* @see https://tailwindcss.com/docs/word-break
*/
['normal', 'words', 'all']],
// Backgrounds
bg: [
/**
* Background Attachment
* @see https://tailwindcss.com/docs/background-attachment
*/
['fixed', 'local', 'scroll'],
/**
* Background Clip
* @see https://tailwindcss.com/docs/background-clip
*/
[{
clip: ['border', 'padding', 'content', 'text']
}],
/**
* Background Opacity
* @see https://tailwindcss.com/docs/background-opacity
*/
[{
opacity: INTEGER
}],
/**
* Background Origin
* @see https://tailwindcss.com/docs/background-origin
*/
[{
origin: ['border', 'padding', 'content']
}],
/**
* Background Position
* @see https://tailwindcss.com/docs/background-position
*/
POSITIONS,
/**
* Background Repeat
* @see https://tailwindcss.com/docs/background-repeat
*/
['no-repeat', {
repeat: ['', 'x', 'y', 'round', 'space']
}],
/**
* Background Size
* @see https://tailwindcss.com/docs/background-size
*/
['auto', 'cover', 'contain'],
/**
* Background Image
* @see https://tailwindcss.com/docs/background-image
*/
['none', {
'gradient-to': ['t', 'tr', 'r', 'br', 'b', 'bl', 'l', 'tl']
}],
/**
* Background Blend Mode
* @see https://tailwindcss.com/docs/background-blend-mode
*/
BLEND_MODES,
/**
* Background Color
* @see https://tailwindcss.com/docs/background-color
*/
ANY],
from: [
/**
* Gradient Color Stops From
* @see https://tailwindcss.com/docs/gradient-color-stops
*/
ANY],
via: [
/**
* Gradient Color Stops Via
* @see https://tailwindcss.com/docs/gradient-color-stops
*/
ANY],
to: [
/**
* Gradient Color Stops To
* @see https://tailwindcss.com/docs/gradient-color-stops
*/
ANY],
// Borders
rounded: [
/**
* Border Radius
* @see https://tailwindcss.com/docs/border-radius
*/
ROUNDED,
/**
* Border Radius Top
* @see https://tailwindcss.com/docs/border-radius
*/
[{
t: ROUNDED
}],
/**
* Border Radius Right
* @see https://tailwindcss.com/docs/border-radius
*/
[{
r: ROUNDED
}],
/**
* Border Radius Bottom
* @see https://tailwindcss.com/docs/border-radius
*/
[{
b: ROUNDED
}],
/**
* Border Radius Left
* @see https://tailwindcss.com/docs/border-radius
*/
[{
l: ROUNDED
}],
/**
* Border Radius Top Left
* @see https://tailwindcss.com/docs/border-radius
*/
[{
tl: ROUNDED
}],
/**
* Border Radius Top Right
* @see https://tailwindcss.com/docs/border-radius
*/
[{
tr: ROUNDED
}],
/**
* Border Radius Bottom Right
* @see https://tailwindcss.com/docs/border-radius
*/
[{
br: ROUNDED
}],
/**
* Border Radius Bottom Left
* @see https://tailwindcss.com/docs/border-radius
*/
[{
bl: ROUNDED
}]],
border: [
/**
* Border Width
* @see https://tailwindcss.com/docs/border-width
*/
LENGTH,
/**
* Border Width Top
* @see https://tailwindcss.com/docs/border-width
*/
[{
t: LENGTH
}],
/**
* Border Width Right
* @see https://tailwindcss.com/docs/border-width
*/
[{
r: LENGTH
}],
/**
* Border Width Bottom
* @see https://tailwindcss.com/docs/border-width
*/
[{
b: LENGTH
}],
/**
* Border Width Left
* @see https://tailwindcss.com/docs/border-width
*/
[{
l: LENGTH
}],
/**
* Border Opacity
* @see https://tailwindcss.com/docs/border-opacity
*/
[{
opacity: INTEGER
}],
/**
* Border Style
* @see https://tailwindcss.com/docs/border-style
*/
BORDER_STYLES,
/**
* Border Collapse
* @see https://tailwindcss.com/docs/border-collapse
*/
['collapse', 'separate'],
/**
* Border Color
* @see https://tailwindcss.com/docs/border-color
*/
ANY],
divide: [
/**
* Divide Width X Reverse
* @see https://tailwindcss.com/docs/divide-width
*/
['x-reverse'],
/**
* Divide Width X
* @see https://tailwindcss.com/docs/divide-width
*/
[{
x: LENGTH
}],
/**
* Divide Width Y Reverse
* @see https://tailwindcss.com/docs/divide-width
*/
['y-reverse'],
/**
* Divide Width Y
* @see https://tailwindcss.com/docs/divide-width
*/
[{
y: LENGTH
}],
/**
* Divide Opacity
* @see https://tailwindcss.com/docs/divide-opacity
*/
[{
opacity: INTEGER
}],
/**
* Divide Style
* @see https://tailwindcss.com/docs/divide-style
*/
BORDER_STYLES,
/**
* Divide Color
* @see https://tailwindcss.com/docs/divide-color
*/
ANY],
ring: [
/**
* Ring Width
* @see https://tailwindcss.com/docs/ring-width
*/
['', isLength],
/**
* Ring Width Inset
* @see https://tailwindcss.com/docs/ring-width
*/
['inset'],
/**
* Ring Opacity
* @see https://tailwindcss.com/docs/ring-opacity
*/
[{
opacity: INTEGER
}],
/**
* Ring Offset Width
* @see https://tailwindcss.com/docs/ring-offset-width
*/
[{
offset: LENGTH
}],
/**
* Ring Offset Color
* @see https://tailwindcss.com/docs/ring-offset-color
*/
[{
offset: ANY
}],
/**
* Ring Color
* @see https://tailwindcss.com/docs/ring-color
*/
ANY],
// Effects
shadow: [
/**
* Box Shadow
* @see https://tailwindcss.com/docs/box-shadow
*/
['', ...SIZES_SIMPLE, 'inner', 'none']],
opacity: [
/**
* Opacity
* @see https://tailwindcss.com/docs/opacity
*/
INTEGER],
mix: [
/**
* Mix Beldn Mode
* @see https://tailwindcss.com/docs/mix-blend-mode
*/
BLEND_MODES],
// Filters
filter: [
/**
* Filter
* @see https://tailwindcss.com/docs/filter
*/
['', 'none']],
blur: [
/**
* Blur
* @see https://tailwindcss.com/docs/blur
*/
['none', '', ...SIZES_SIMPLE, '3xl']],
brightness: [
/**
* Brightness
* @see https://tailwindcss.com/docs/brightness
*/
INTEGER],
contrast: [
/**
* Contrast
* @see https://tailwindcss.com/docs/contrast
*/
INTEGER],
drop: [
/**
* Drop Shadow
* @see https://tailwindcss.com/docs/drop-shadow
*/
[{
shadow: ['', ...SIZES_SIMPLE, 'none']
}]],
grayscale: [
/**
* Grayscale
* @see https://tailwindcss.com/docs/grayscale
*/
['0', '']],
hue: [
/**
* Hue Rotate
* @see https://tailwindcss.com/docs/hue-rotate
*/
[{
rotate: INTEGER
}]],
invert: [
/**
* Invert
* @see https://tailwindcss.com/docs/invert
*/
['0', '']],
saturate: [
/**
* Saturate
* @see https://tailwindcss.com/docs/saturate
*/
INTEGER],
sepia: [
/**
* Sepia
* @see https://tailwindcss.com/docs/sepia
*/
['0', '']],
backdrop: [
/**
* Backdrop Filter
* @see https://tailwindcss.com/docs/backdrop-filter
*/
[{
filter: ['', 'none']
}],
/**
* Backdrop Blur
* @see https://tailwindcss.com/docs/backdrop-blur
*/
[{
blur: ['none', '', ...SIZES_SIMPLE, '3xl']
}],
/**
* Backdrop Brightness
* @see https://tailwindcss.com/docs/backdrop-brightness
*/
[{
brightness: INTEGER
}],
/**
* Backdrop Contrast
* @see https://tailwindcss.com/docs/backdrop-contrast
*/
[{
contrast: INTEGER
}],
/**
* Backdrop Grayscale
* @see https://tailwindcss.com/docs/backdrop-grayscale
*/
[{
grayscale: ['0', '']
}],
/**
* Backdrop Hue Rotate
* @see https://tailwindcss.com/docs/backdrop-hue-rotate
*/
[{
'hue-rotate': INTEGER
}],
/**
* Backdrop Invert
* @see https://tailwindcss.com/docs/backdrop-invert
*/
[{
invert: ['0', '']
}],
/**
* Backdrop Opacity
* @see https://tailwindcss.com/docs/backdrop-opacity
*/
[{
opacity: INTEGER
}],
/**
* Backdrop Saturate
* @see https://tailwindcss.com/docs/backdrop-saturate
*/
[{
saturate: INTEGER
}],
/**
* Backdrop Sepia
* @see https://tailwindcss.com/docs/backdrop-sepia
*/
[{
sepia: ['0', '']
}]],
// Tables
table: [
/**
* Table Layout
* @see https://tailwindcss.com/docs/table-layout
*/
['auto', 'fixed']],
// Transitions and Animation
transition: [
/**
* Tranisition Property
* @see https://tailwindcss.com/docs/transition-property
*/
['none', 'all', '', 'colors', 'opacity', 'shadow', 'transform']],
duration: [
/**
* Transition Duration
* @see https://tailwindcss.com/docs/transition-duration
*/
INTEGER],
ease: [
/**
* Transition Timing Function
* @see https://tailwindcss.com/docs/transition-timing-function
*/
['linear', 'in', 'out', 'in-out']],
delay: [
/**
* Transition Delay
* @see https://tailwindcss.com/docs/transition-delay
*/
INTEGER],
animate: [
/**
* Animation
* @see https://tailwindcss.com/docs/animation
*/
['none', 'spin', 'ping', 'pulse', 'bounce']],
// Transforms
transform: [
/**
* Transform
* @see https://tailwindcss.com/docs/transform
*/
['', 'gpu', 'none'],
/**
* Transform Origin
* @see https://tailwindcss.com/docs/transform-origin
*/
[{
origin: ['center', 'top', 'top-right', 'right', 'bottom-right', 'bottom', 'bottom-left', 'left', 'top-left']
}]],
scale: [
/**
* Scale
* @see https://tailwindcss.com/docs/scale
*/
INTEGER,
/**
* Scale X
* @see https://tailwindcss.com/docs/scale
*/
[{
x: INTEGER
}],
/**
* Scale Y
* @see https://tailwindcss.com/docs/scale
*/
[{
y: INTEGER
}]],
rotate: [
/**
* Rotate
* @see https://tailwindcss.com/docs/rotate
*/
INTEGER],
translate: [
/**
* Translate X
* @see https://tailwindcss.com/docs/translate
*/
[{
x: LENGTH
}],
/**
* Translate Y
* @see https://tailwindcss.com/docs/translate
*/
[{
y: LENGTH
}]],
skew: [
/**
* Skew X
* @see https://tailwindcss.com/docs/skew
*/
[{
x: INTEGER
}],
/**
* Skew Y
* @see https://tailwindcss.com/docs/skew
*/
[{
y: INTEGER
}]],
// Interactivity
cursor: [
/**
* Cursor
* @see https://tailwindcss.com/docs/cursor
*/
['auto', 'default', 'pointer', 'wait', 'text', 'move', 'help', 'not-allowed']],
outline: [
/**
* Outline
* @see https://tailwindcss.com/docs/outline
*/
['none', 'white', 'black']],
pointer: [
/**
* Pointer Events
* @see https://tailwindcss.com/docs/pointer-events
*/
[{
events: ['none', 'auto']
}]],
resize: [
/**
* Resize
* @see https://tailwindcss.com/docs/resize
*/
['none', 'y', 'x', '']],
select: [
/**
* Select
* @see https://tailwindcss.com/docs/select
*/
['none', 'text', 'all', 'auto']],
stroke: [
/**
* Stroke
* @see https://tailwindcss.com/docs/stroke
*/
['current'],
/**
* Stroke Width
* @see https://tailwindcss.com/docs/stroke-width
*/
LENGTH]
},
standaloneClasses: [// Layout
/**
* Container
* @see https://tailwindcss.com/docs/container
*/
['container'],
/**
* Display
* @see https://tailwindcss.com/docs/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'],
/**
* Isolation
* @see https://tailwindcss.com/docs/isolation
*/
['isolate', 'isolation-auto'],
/**
* Position
* @see https://tailwindcss.com/docs/position
*/
['static', 'fixed', 'absolute', 'relative', 'sticky'],
/**
* Visibility
* @see https://tailwindcss.com/docs/visibility
*/
['visible', 'invisible'], // Typography
/**
* Font Smoothing
* @see https://tailwindcss.com/docs/font-smoothing
*/
['antialiased', 'subpixel-antialiased'],
/**
* Font Style
* @see https://tailwindcss.com/docs/font-style
*/
['italic', 'not-italic'],
/**
* Font Variant Numeric
* @see https://tailwindcss.com/docs/font-variant-numeric
*/
['normal-nums', 'ordinal', 'slashed-zero', 'lining-nums', 'oldstyle-nums', 'tabular-nums', 'diagonal-nums', 'stacked-fractons'],
/**
* Text Decoration
* @see https://tailwindcss.com/docs/text-decoration
*/
['underline', 'line-through', 'no-underline'],
/**
* Text Transform
* @see https://tailwindcss.com/docs/text-transform
*/
['uppercase', 'lowercase', 'capitalize', 'normal-case'],
/**
* Text Overflow
* @see https://tailwindcss.com/docs/text-overflow
*/
['truncate', 'overflow-ellipsis', 'overflow-clip'], // Interactivity
/**
* Appearance
* @see https://tailwindcss.com/docs/appearance
*/
['appearance-none'], // SVG
/**
* Fill
* @see https://tailwindcss.com/docs/fill
*/
['fill-current'], // Accessibility
/**
* Screen Readers
* @see https://tailwindcss.com/docs/screen-readers
*/
['sr-only', 'not-sr-only']],
conflictingGroups: {
// Overflow
'dynamicClasses.overflow.0': [// Overflow X
'dynamicClasses.overflow.1', // Overflow Y
'dynamicClasses.overflow.2'],
// Overscroll
'dynamicClasses.overscroll.0': [// Overscroll X
'dynamicClasses.overscroll.1', // Overscroll Y
'dynamicClasses.overscroll.2'],
// Top / Right / Bottom / Left
'dynamicClasses.inset.2': [// Right / Left
'dynamicClasses.inset.0', // Top / Bottom
'dynamicClasses.inset.1', // Top
'dynamicClasses.top.0', // Right
'dynamicClasses.right.0', // Bottom
'dynamicClasses.bottom.0', // Left
'dynamicClasses.left.0'],
// Right / Left
'dynamicClasses.inset.0': [// Right
'dynamicClasses.right.0', // Left
'dynamicClasses.left.0'],
// Top / Bottom
'dynamicClasses.inset.1': [// Top
'dynamicClasses.top.0', // Bottom
'dynamicClasses.bottom.0'],
// Flex
'dynamicClasses.flex.2': [// Flex Grow
'dynamicClasses.flex.3', // Flex Shrink
'dynamicClasses.flex.4'],
// Grid Column Start / End
'dynamicClasses.col.0': [// Grid Column Start
'dynamicClasses.col.1', // Grid Column End
'dynamicClasses.col.2'],
// Grid Row Start / End
'dynamicClasses.row.0': [// Grid Row Start
'dynamicClasses.row.1', // Grid Row End
'dynamicClasses.row.2'],
// Gap
'dynamicClasses.gap.2': [// Gap X
'dynamicClasses.gap.0', // Gap Y
'dynamicClasses.gap.1'],
// Padding
'dynamicClasses.p.0': [// Padding X
'dynamicClasses.px.0', // Padding Y
'dynamicClasses.py.0', // Padding Top
'dynamicClasses.pt.0', // Padding Right
'dynamicClasses.pr.0', // Padding Bottom
'dynamicClasses.pb.0', // Padding Left
'dynamicClasses.pl.0'],
// Padding X
'dynamicClasses.px.0': [// Padding Right
'dynamicClasses.pr.0', // Padding Left
'dynamicClasses.pl.0'],
// Padding Y
'dynamicClasses.py.0': [// Padding Top
'dynamicClasses.pt.0', // Padding Bottom
'dynamicClasses.pb.0'],
// Margin
'dynamicClasses.m.0': [// Margin X
'dynamicClasses.mx.0', // Margin Y
'dynamicClasses.my.0', // Margin Top
'dynamicClasses.mt.0', // Margin Right
'dynamicClasses.mr.0', // Margin Bottom
'dynamicClasses.mb.0', // Margin Left
'dynamicClasses.ml.0'],
// Margin X
'dynamicClasses.mx.0': [// Margin Right
'dynamicClasses.mr.0', // Margin Left
'dynamicClasses.ml.0'],
// Margin Y
'dynamicClasses.my.0': [// Margin Top
'dynamicClasses.mt.0', // Margin Bottom
'dynamicClasses.mb.0'],
// Font Size
'dynamicClasses.text.0': [// Line Height
'dynamicClasses.leading.0'],
// Border Radius
'dynamicClasses.rounded.0': [// Border Radius Top
'dynamicClasses.rounded.1', // Border Radius Right
'dynamicClasses.rounded.2', // Border Radius Bottom
'dynamicClasses.rounded.3', // Border Radius Left
'dynamicClasses.rounded.4', // Border Radius Top Left
'dynamicClasses.rounded.5', // Border Radius Top Right
'dynamicClasses.rounded.6', // Border Radius Bottom Right
'dynamicClasses.rounded.7', // Border Radius Bottom Left
'dynamicClasses.rounded.8'],
// Border Radius Top
'dynamicClasses.rounded.1': [// Border Radius Top Left
'dynamicClasses.rounded.5', // Border Radius Top Right
'dynamicClasses.rounded.6'],
// Border Radius Right
'dynamicClasses.rounded.2': [// Border Radius Top Right
'dynamicClasses.rounded.6', // Border Radius Bottom Right
'dynamicClasses.rounded.7'],
// Border Radius Bottom
'dynamicClasses.rounded.3': [// Border Radius Bottom Right
'dynamicClasses.rounded.7', // Border Radius Bottom Left
'dynamicClasses.rounded.8'],
// Border Radius Left
'dynamicClasses.rounded.4': [// Border Radius Top Left
'dynamicClasses.rounded.5', // Border Radius Bottom Left
'dynamicClasses.rounded.8'],
// Border Width
'dynamicClasses.border.0': [// Border Width Top
'dynamicClasses.border.1', // Border Width Right
'dynamicClasses.border.2', // Border Width Bottom
'dynamicClasses.border.3', // Border Width Left
'dynamicClasses.border.4'],
// Ring Width
'dynamicClasses.ring.0': [// Ring Width
'dynamicClasses.ring.0', // Box Shadow
'dynamicClasses.shadow.0'],
// Box Shadow
'dynamicClasses.shadow.0': [// Ring Width
'dynamicClasses.ring.0', // Box Shadow
'dynamicClasses.shadow.0']
}
};
}
function getLruCache(cacheSize) {
if (cacheSize >= 1) {
return HLRU(cacheSize);
}
return {
get: () => undefined,
set: () => {}
};
}
// 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 = /:(?![^\s[]*\])/;
const PREFIX_SEPARATOR = ':';
function mergeClassList(classList, configUtils) {
/**
* Set of classGroupIds in following format:
* - No prefix: `:classGroupId`
* - With prefix: `prefix:classGroupId`
* @example ':standaloneClasses.1'
* @example 'hover:focus:dynamicClasses.bg.2'
*/
const classGroupsInConflict = new Set();
return classList.trim().split(/\s+/).map(originalClassName => {
const prefixes = originalClassName.split(PREFIX_SEPARATOR_REGEX);
const className = prefixes.pop();
const arePrefixesValid = prefixes.every(configUtils.prefix.isValid);
const classGroupId = arePrefixesValid ? configUtils.class.getGroup(className) : undefined;
if (!classGroupId) {
return {
isTailwindClass: false,
originalClassName
};
}
prefixes.sort(configUtils.prefix.compare);
return {
isTailwindClass: true,
prefix: prefixes.join(PREFIX_SEPARATOR),
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);
configUtils.class.getConflictingGroups(classGroupId).forEach(group => classGroupsInConflict.add(`${prefix}:${group}`));
return true;
}).reverse().map(parsed => parsed.originalClassName).join(' ');
}
function createTailwindMerge(createConfig) {
const config = createConfig(getDefaultConfig);
const configUtils = createConfigUtils(config);
const cache = getLruCache(config.cacheSize);
return function tailwindMerge(...classLists) {
const classList = classLists.filter(Boolean).join(' ');
const cachedResult = cache.get(classList);
if (cachedResult) {
return cachedResult;
}
const result = mergeClassList(classList, configUtils);
cache.set(classList, result);
return result;
};
}
const twMerge = createTailwindMerge(defaultConfig => defaultConfig());
export { createTailwindMerge, twMerge };
//# sourceMappingURL=index.js.map

13

package.json
{
"name": "tailwind-merge",
"version": "0.1.1",
"version": "0.1.2",
"description": "Merge Tailwind CSS classes without style conflicts",

@@ -26,4 +26,7 @@ "keywords": [

"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"source": "src/index.ts",
"exports": "./dist/index.js",
"module": "dist/index.module.js",
"main": "dist/index.cjs",
"types": "./dist/types/index.d.ts",
"repository": {

@@ -34,4 +37,5 @@ "type": "git",

"scripts": {
"build": "rm -rf dist/* && tsc --build",
"build": "rm -rf dist/* && microbundle --strict --no-compress --format modern,esm,cjs",
"test": "jest",
"type-check": "tsc --build",
"lint": "eslint --max-warnings 0 '**'"

@@ -50,2 +54,3 @@ },

"jest": "^27.0.6",
"microbundle": "^0.13.3",
"prettier": "^2.3.2",

@@ -52,0 +57,0 @@ "ts-jest": "^27.0.3",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc