From 6047d534fd9e27bfa1da23451ae7c931fdcd55c4 Mon Sep 17 00:00:00 2001 From: Dany Castillo <31006608+dcastil@users.noreply.github.com> Date: Thu, 21 Dec 2023 16:52:16 +0100 Subject: [PATCH 01/11] add support for `svh`, `lvh` and dvh` scale values --- src/lib/default-config.ts | 40 ++++++++++++++++++++++++++--- tests/tailwind-css-versions.test.ts | 4 +++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/lib/default-config.ts b/src/lib/default-config.ts index a29892df..10b6cd83 100644 --- a/src/lib/default-config.ts +++ b/src/lib/default-config.ts @@ -581,7 +581,21 @@ export function getDefaultConfig() { * Width * @see https://tailwindcss.com/docs/width */ - w: [{ w: ['auto', 'min', 'max', 'fit', isArbitraryValue, spacing] }], + w: [ + { + w: [ + 'auto', + 'min', + 'max', + 'fit', + 'svw', + 'lvw', + 'dvw', + isArbitraryValue, + spacing, + ], + }, + ], /** * Min-Width * @see https://tailwindcss.com/docs/min-width @@ -611,17 +625,35 @@ export function getDefaultConfig() { * Height * @see https://tailwindcss.com/docs/height */ - h: [{ h: [isArbitraryValue, spacing, 'auto', 'min', 'max', 'fit'] }], + h: [ + { + h: [ + isArbitraryValue, + spacing, + 'auto', + 'min', + 'max', + 'fit', + 'svh', + 'lvh', + 'dvh', + ], + }, + ], /** * Min-Height * @see https://tailwindcss.com/docs/min-height */ - 'min-h': [{ 'min-h': ['min', 'max', 'fit', isLength, isArbitraryValue] }], + 'min-h': [ + { 'min-h': ['min', 'max', 'fit', 'svh', 'lvh', 'dvh', isLength, isArbitraryValue] }, + ], /** * Max-Height * @see https://tailwindcss.com/docs/max-height */ - 'max-h': [{ 'max-h': [isArbitraryValue, spacing, 'min', 'max', 'fit'] }], + 'max-h': [ + { 'max-h': [isArbitraryValue, spacing, 'min', 'max', 'fit', 'svh', 'lvh', 'dvh'] }, + ], // Typography /** * Font Size diff --git a/tests/tailwind-css-versions.test.ts b/tests/tailwind-css-versions.test.ts index c4e7c697..91d85a21 100644 --- a/tests/tailwind-css-versions.test.ts +++ b/tests/tailwind-css-versions.test.ts @@ -34,3 +34,7 @@ test('supports Tailwind CSS v3.3 features', () => { expect(twMerge('content-normal content-center content-stretch')).toBe('content-stretch') expect(twMerge('whitespace-nowrap whitespace-break-spaces')).toBe('whitespace-break-spaces') }) + +test('supports Tailwind CSS v3.4 features', () => { + expect(twMerge('h-svh h-dvh w-svw w-dvw')).toBe('h-dvh w-dvw') +}) From 1274ad5341e97eb5329e309aa1a6cef7ced074e8 Mon Sep 17 00:00:00 2001 From: Dany Castillo <31006608+dcastil@users.noreply.github.com> Date: Thu, 21 Dec 2023 17:11:08 +0100 Subject: [PATCH 02/11] add `text-wrap` utilities --- src/lib/default-config.ts | 5 +++++ src/lib/types.ts | 1 + tests/class-map.test.ts | 9 ++++++++- tests/tailwind-css-versions.test.ts | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/lib/default-config.ts b/src/lib/default-config.ts index 10b6cd83..e336dab8 100644 --- a/src/lib/default-config.ts +++ b/src/lib/default-config.ts @@ -843,6 +843,11 @@ export function getDefaultConfig() { * @see https://tailwindcss.com/docs/text-overflow */ 'text-overflow': ['truncate', 'text-ellipsis', 'text-clip'], + /** + * Text Wrap + * @see https://tailwindcss.com/docs/text-wrap + */ + 'text-wrap': [{ text: ['wrap', 'nowrap', 'balance', 'pretty'] }], /** * Text Indent * @see https://tailwindcss.com/docs/text-indent diff --git a/src/lib/types.ts b/src/lib/types.ts index 25eabaf5..4983df16 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -384,6 +384,7 @@ export type DefaultClassGroupIds = | 'text-opacity' | 'text-overflow' | 'text-transform' + | 'text-wrap' | 'top' | 'touch' | 'touch-x' diff --git a/tests/class-map.test.ts b/tests/class-map.test.ts index b3340743..8e7d0347 100644 --- a/tests/class-map.test.ts +++ b/tests/class-map.test.ts @@ -246,7 +246,14 @@ test('class map has correct class groups at first part', () => { subpixel: ['font-smoothing'], table: ['display', 'table-layout'], tabular: ['fvn-spacing'], - text: ['font-size', 'text-alignment', 'text-color', 'text-opacity', 'text-overflow'], + text: [ + 'font-size', + 'text-alignment', + 'text-color', + 'text-opacity', + 'text-overflow', + 'text-wrap', + ], to: ['gradient-to', 'gradient-to-pos'], top: ['top'], touch: ['touch', 'touch-pz', 'touch-x', 'touch-y'], diff --git a/tests/tailwind-css-versions.test.ts b/tests/tailwind-css-versions.test.ts index 91d85a21..15b476e1 100644 --- a/tests/tailwind-css-versions.test.ts +++ b/tests/tailwind-css-versions.test.ts @@ -37,4 +37,5 @@ test('supports Tailwind CSS v3.3 features', () => { test('supports Tailwind CSS v3.4 features', () => { expect(twMerge('h-svh h-dvh w-svw w-dvw')).toBe('h-dvh w-dvw') + expect(twMerge('text-wrap text-pretty')).toBe('text-pretty') }) From 729e2e55c3bc945a867b95bae0acfc09dc31ac48 Mon Sep 17 00:00:00 2001 From: Dany Castillo <31006608+dcastil@users.noreply.github.com> Date: Thu, 21 Dec 2023 17:14:05 +0100 Subject: [PATCH 03/11] add test cases for `has-*` variants --- tests/tailwind-css-versions.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/tailwind-css-versions.test.ts b/tests/tailwind-css-versions.test.ts index 15b476e1..09b38ee7 100644 --- a/tests/tailwind-css-versions.test.ts +++ b/tests/tailwind-css-versions.test.ts @@ -37,5 +37,10 @@ test('supports Tailwind CSS v3.3 features', () => { test('supports Tailwind CSS v3.4 features', () => { expect(twMerge('h-svh h-dvh w-svw w-dvw')).toBe('h-dvh w-dvw') + expect( + twMerge( + 'has-[[data-potato]]:p-1 has-[[data-potato]]:p-2 group-has-[:checked]:grid group-has-[:checked]:flex', + ), + ).toBe('has-[[data-potato]]:p-2 group-has-[:checked]:flex') expect(twMerge('text-wrap text-pretty')).toBe('text-pretty') }) From 7dd86589f43e84494eec3dd98608cac3ff0c2ce4 Mon Sep 17 00:00:00 2001 From: Dany Castillo <31006608+dcastil@users.noreply.github.com> Date: Thu, 21 Dec 2023 17:31:49 +0100 Subject: [PATCH 04/11] add `size-*` shorthand --- src/lib/default-config.ts | 6 ++++++ src/lib/types.ts | 5 +++-- tests/class-map.test.ts | 1 + tests/tailwind-css-versions.test.ts | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lib/default-config.ts b/src/lib/default-config.ts index e336dab8..01e391f2 100644 --- a/src/lib/default-config.ts +++ b/src/lib/default-config.ts @@ -654,6 +654,11 @@ export function getDefaultConfig() { 'max-h': [ { 'max-h': [isArbitraryValue, spacing, 'min', 'max', 'fit', 'svh', 'lvh', 'dvh'] }, ], + /** + * Size + * @see https://tailwindcss.com/docs/size + */ + size: [{ size: [isArbitraryValue, spacing, 'auto', 'min', 'max', 'fit'] }], // Typography /** * Font Size @@ -1764,6 +1769,7 @@ export function getDefaultConfig() { m: ['mx', 'my', 'ms', 'me', 'mt', 'mr', 'mb', 'ml'], mx: ['mr', 'ml'], my: ['mt', 'mb'], + size: ['w', 'h'], 'font-size': ['leading'], 'fvn-normal': [ 'fvn-ordinal', diff --git a/src/lib/types.ts b/src/lib/types.ts index 4983df16..51f07a55 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -360,6 +360,7 @@ export type DefaultClassGroupIds = | 'shadow-color' | 'shadow' | 'shrink' + | 'size' | 'skew-x' | 'skew-y' | 'snap-align' @@ -386,10 +387,10 @@ export type DefaultClassGroupIds = | 'text-transform' | 'text-wrap' | 'top' - | 'touch' + | 'touch-pz' | 'touch-x' | 'touch-y' - | 'touch-pz' + | 'touch' | 'tracking' | 'transform-origin' | 'transform' diff --git a/tests/class-map.test.ts b/tests/class-map.test.ts index 8e7d0347..9d32edc7 100644 --- a/tests/class-map.test.ts +++ b/tests/class-map.test.ts @@ -233,6 +233,7 @@ test('class map has correct class groups at first part', () => { sepia: ['sepia'], shadow: ['shadow', 'shadow-color'], shrink: ['shrink'], + size: ['size'], skew: ['skew-x', 'skew-y'], slashed: ['fvn-slashed-zero'], snap: ['snap-align', 'snap-stop', 'snap-strictness', 'snap-type'], diff --git a/tests/tailwind-css-versions.test.ts b/tests/tailwind-css-versions.test.ts index 09b38ee7..3748844f 100644 --- a/tests/tailwind-css-versions.test.ts +++ b/tests/tailwind-css-versions.test.ts @@ -43,4 +43,5 @@ test('supports Tailwind CSS v3.4 features', () => { ), ).toBe('has-[[data-potato]]:p-2 group-has-[:checked]:flex') expect(twMerge('text-wrap text-pretty')).toBe('text-pretty') + expect(twMerge('w-5 h-3 size-10 w-12')).toBe('size-10 w-12') }) From a37e24b2e84c1c2c5b28b24290bf13de391652c9 Mon Sep 17 00:00:00 2001 From: Dany Castillo <31006608+dcastil@users.noreply.github.com> Date: Thu, 21 Dec 2023 17:37:05 +0100 Subject: [PATCH 05/11] add test case for subgrid utilities --- tests/tailwind-css-versions.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/tailwind-css-versions.test.ts b/tests/tailwind-css-versions.test.ts index 3748844f..0e9b7bc9 100644 --- a/tests/tailwind-css-versions.test.ts +++ b/tests/tailwind-css-versions.test.ts @@ -44,4 +44,7 @@ test('supports Tailwind CSS v3.4 features', () => { ).toBe('has-[[data-potato]]:p-2 group-has-[:checked]:flex') expect(twMerge('text-wrap text-pretty')).toBe('text-pretty') expect(twMerge('w-5 h-3 size-10 w-12')).toBe('size-10 w-12') + expect(twMerge('grid-cols-2 grid-cols-subgrid grid-rows-5 grid-rows-subgrid')).toBe( + 'grid-cols-subgrid grid-rows-subgrid', + ) }) From 96f03ecf3b460b74a858658590576c3b344500a3 Mon Sep 17 00:00:00 2001 From: Dany Castillo <31006608+dcastil@users.noreply.github.com> Date: Thu, 21 Dec 2023 17:45:58 +0100 Subject: [PATCH 06/11] add spacing scale to `min-width`, `min-height` and `max-width` --- src/lib/default-config.ts | 8 ++++---- tests/tailwind-css-versions.test.ts | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lib/default-config.ts b/src/lib/default-config.ts index 01e391f2..52cce609 100644 --- a/src/lib/default-config.ts +++ b/src/lib/default-config.ts @@ -600,7 +600,7 @@ export function getDefaultConfig() { * Min-Width * @see https://tailwindcss.com/docs/min-width */ - 'min-w': [{ 'min-w': ['min', 'max', 'fit', isArbitraryValue, isLength] }], + 'min-w': [{ 'min-w': [isArbitraryValue, spacing, 'min', 'max', 'fit'] }], /** * Max-Width * @see https://tailwindcss.com/docs/max-width @@ -608,7 +608,8 @@ export function getDefaultConfig() { 'max-w': [ { 'max-w': [ - '0', + isArbitraryValue, + spacing, 'none', 'full', 'min', @@ -617,7 +618,6 @@ export function getDefaultConfig() { 'prose', { screen: [isTshirtSize] }, isTshirtSize, - isArbitraryValue, ], }, ], @@ -645,7 +645,7 @@ export function getDefaultConfig() { * @see https://tailwindcss.com/docs/min-height */ 'min-h': [ - { 'min-h': ['min', 'max', 'fit', 'svh', 'lvh', 'dvh', isLength, isArbitraryValue] }, + { 'min-h': [isArbitraryValue, spacing, 'min', 'max', 'fit', 'svh', 'lvh', 'dvh'] }, ], /** * Max-Height diff --git a/tests/tailwind-css-versions.test.ts b/tests/tailwind-css-versions.test.ts index 0e9b7bc9..3e8eab14 100644 --- a/tests/tailwind-css-versions.test.ts +++ b/tests/tailwind-css-versions.test.ts @@ -47,4 +47,5 @@ test('supports Tailwind CSS v3.4 features', () => { expect(twMerge('grid-cols-2 grid-cols-subgrid grid-rows-5 grid-rows-subgrid')).toBe( 'grid-cols-subgrid grid-rows-subgrid', ) + expect(twMerge('min-w-0 min-w-50 min-w-px max-w-0 max-w-50 max-w-px')).toBe('min-w-px max-w-px') }) From 3b770bcc19d50c5471ddb844e2cb1c7effa8faef Mon Sep 17 00:00:00 2001 From: Dany Castillo <31006608+dcastil@users.noreply.github.com> Date: Thu, 21 Dec 2023 17:54:05 +0100 Subject: [PATCH 07/11] add `forced-color-adjust` utilities --- src/lib/default-config.ts | 5 +++++ src/lib/types.ts | 1 + tests/class-map.test.ts | 1 + tests/tailwind-css-versions.test.ts | 3 +++ 4 files changed, 10 insertions(+) diff --git a/src/lib/default-config.ts b/src/lib/default-config.ts index 52cce609..0a25e511 100644 --- a/src/lib/default-config.ts +++ b/src/lib/default-config.ts @@ -1754,6 +1754,11 @@ export function getDefaultConfig() { * @see https://tailwindcss.com/docs/screen-readers */ sr: ['sr-only', 'not-sr-only'], + /** + * Forced Color Adjust + * @see https://tailwindcss.com/docs/forced-color-adjust + */ + 'forced-color-adjust': [{ 'forced-color-adjust': ['auto', 'none'] }], }, conflictingClassGroups: { overflow: ['overflow-x', 'overflow-y'], diff --git a/src/lib/types.ts b/src/lib/types.ts index 51f07a55..54ed0876 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -223,6 +223,7 @@ export type DefaultClassGroupIds = | 'font-smoothing' | 'font-style' | 'font-weight' + | 'forced-color-adjust' | 'fvn-figure' | 'fvn-fraction' | 'fvn-normal' diff --git a/tests/class-map.test.ts b/tests/class-map.test.ts index 9d32edc7..0dd5eb82 100644 --- a/tests/class-map.test.ts +++ b/tests/class-map.test.ts @@ -112,6 +112,7 @@ test('class map has correct class groups at first part', () => { float: ['float'], flow: ['display'], font: ['font-family', 'font-weight'], + forced: ['forced-color-adjust'], from: ['gradient-from', 'gradient-from-pos'], gap: ['gap', 'gap-x', 'gap-y'], grayscale: ['grayscale'], diff --git a/tests/tailwind-css-versions.test.ts b/tests/tailwind-css-versions.test.ts index 3e8eab14..61a6170b 100644 --- a/tests/tailwind-css-versions.test.ts +++ b/tests/tailwind-css-versions.test.ts @@ -48,4 +48,7 @@ test('supports Tailwind CSS v3.4 features', () => { 'grid-cols-subgrid grid-rows-subgrid', ) expect(twMerge('min-w-0 min-w-50 min-w-px max-w-0 max-w-50 max-w-px')).toBe('min-w-px max-w-px') + expect(twMerge('forced-color-adjust-none forced-color-adjust-auto')).toBe( + 'forced-color-adjust-auto', + ) }) From a258e10189bdc73d3516c1e81703cd18e6c69663 Mon Sep 17 00:00:00 2001 From: Dany Castillo <31006608+dcastil@users.noreply.github.com> Date: Thu, 21 Dec 2023 17:57:54 +0100 Subject: [PATCH 08/11] add `appearance-auto` utility --- src/lib/default-config.ts | 2 +- tests/tailwind-css-versions.test.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/default-config.ts b/src/lib/default-config.ts index 0a25e511..545d7855 100644 --- a/src/lib/default-config.ts +++ b/src/lib/default-config.ts @@ -1510,7 +1510,7 @@ export function getDefaultConfig() { * Appearance * @see https://tailwindcss.com/docs/appearance */ - appearance: ['appearance-none'], + appearance: [{ appearance: ['none', 'auto'] }], /** * Cursor * @see https://tailwindcss.com/docs/cursor diff --git a/tests/tailwind-css-versions.test.ts b/tests/tailwind-css-versions.test.ts index 61a6170b..08a1a8ed 100644 --- a/tests/tailwind-css-versions.test.ts +++ b/tests/tailwind-css-versions.test.ts @@ -51,4 +51,5 @@ test('supports Tailwind CSS v3.4 features', () => { expect(twMerge('forced-color-adjust-none forced-color-adjust-auto')).toBe( 'forced-color-adjust-auto', ) + expect(twMerge('appearance-none appearance-auto')).toBe('appearance-auto') }) From 2c0da8cae94ad54f90646683c97d29867d537415 Mon Sep 17 00:00:00 2001 From: Dany Castillo <31006608+dcastil@users.noreply.github.com> Date: Thu, 21 Dec 2023 19:12:03 +0100 Subject: [PATCH 09/11] add logical properties support for float and clear --- src/lib/default-config.ts | 4 ++-- tests/tailwind-css-versions.test.ts | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/default-config.ts b/src/lib/default-config.ts index 545d7855..c0ccbe2e 100644 --- a/src/lib/default-config.ts +++ b/src/lib/default-config.ts @@ -193,12 +193,12 @@ export function getDefaultConfig() { * Floats * @see https://tailwindcss.com/docs/float */ - float: [{ float: ['right', 'left', 'none'] }], + float: [{ float: ['right', 'left', 'none', 'start', 'end'] }], /** * Clear * @see https://tailwindcss.com/docs/clear */ - clear: [{ clear: ['left', 'right', 'both', 'none'] }], + clear: [{ clear: ['left', 'right', 'both', 'none', 'start', 'end'] }], /** * Isolation * @see https://tailwindcss.com/docs/isolation diff --git a/tests/tailwind-css-versions.test.ts b/tests/tailwind-css-versions.test.ts index 08a1a8ed..bb2082e1 100644 --- a/tests/tailwind-css-versions.test.ts +++ b/tests/tailwind-css-versions.test.ts @@ -52,4 +52,5 @@ test('supports Tailwind CSS v3.4 features', () => { 'forced-color-adjust-auto', ) expect(twMerge('appearance-none appearance-auto')).toBe('appearance-auto') + expect(twMerge('float-start float-end clear-start clear-end')).toBe('float-end clear-end') }) From c2e9f0321e3390791b1f3ccfc224c7d3caf3d6cc Mon Sep 17 00:00:00 2001 From: Dany Castillo <31006608+dcastil@users.noreply.github.com> Date: Thu, 21 Dec 2023 20:33:49 +0100 Subject: [PATCH 10/11] add test case for `*` variant --- tests/tailwind-css-versions.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/tailwind-css-versions.test.ts b/tests/tailwind-css-versions.test.ts index bb2082e1..3c08b607 100644 --- a/tests/tailwind-css-versions.test.ts +++ b/tests/tailwind-css-versions.test.ts @@ -53,4 +53,5 @@ test('supports Tailwind CSS v3.4 features', () => { ) expect(twMerge('appearance-none appearance-auto')).toBe('appearance-auto') expect(twMerge('float-start float-end clear-start clear-end')).toBe('float-end clear-end') + expect(twMerge('*:p-10 *:p-20 hover:*:p-10 hover:*:p-20')).toBe('*:p-20 hover:*:p-20') }) From f283c089e7d2641ad9d656e1b5366d576eebfde2 Mon Sep 17 00:00:00 2001 From: Dany Castillo <31006608+dcastil@users.noreply.github.com> Date: Thu, 21 Dec 2023 20:46:29 +0100 Subject: [PATCH 11/11] update supported Tailwind versions in docs --- docs/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 8c8a822d..48c351f6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -16,8 +16,8 @@ twMerge('px-2 py-1 bg-red hover:bg-dark-red', 'p-3 bg-[#B91C1C]') // → 'hover:bg-dark-red p-3 bg-[#B91C1C]' ``` -- Supports Tailwind v3.0 up to v3.3 (if you use Tailwind v2, use [tailwind-merge v0.9.0](https://github.com/dcastil/tailwind-merge/tree/v0.9.0)) -- Works in all modern browsers and Node >=12 +- Supports Tailwind v3.0 up to v3.4 (if you use Tailwind v2, use [tailwind-merge v0.9.0](https://github.com/dcastil/tailwind-merge/tree/v0.9.0)) +- Works in all modern browsers and maintained Node versions - Fully typed - [Check bundle size on Bundlephobia](https://bundlephobia.com/package/tailwind-merge)