Skip to content

Commit

Permalink
Merge branch 'dcastil:main' into benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
XantreDev committed Aug 12, 2024
2 parents 966f37a + a72f2f4 commit 3f53e46
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 20 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div align="center">
<br />
<a href="https://github.com/dcastil/tailwind-merge">
<img src="https://github.com/dcastil/tailwind-merge/raw/v2.5.0/assets/logo.svg" alt="tailwind-merge" height="150px" />
<img src="https://github.com/dcastil/tailwind-merge/raw/v2.5.2/assets/logo.svg" alt="tailwind-merge" height="150px" />
</a>
</div>

Expand All @@ -25,14 +25,14 @@ twMerge('px-2 py-1 bg-red hover:bg-dark-red', 'p-3 bg-[#B91C1C]')

## Get started

- [What is it for](https://github.com/dcastil/tailwind-merge/tree/v2.5.0/docs/what-is-it-for.md)
- [When and how to use it](https://github.com/dcastil/tailwind-merge/tree/v2.5.0/docs/when-and-how-to-use-it.md)
- [Features](https://github.com/dcastil/tailwind-merge/tree/v2.5.0/docs/features.md)
- [Limitations](https://github.com/dcastil/tailwind-merge/tree/v2.5.0/docs/limitations.md)
- [Configuration](https://github.com/dcastil/tailwind-merge/tree/v2.5.0/docs/configuration.md)
- [Recipes](https://github.com/dcastil/tailwind-merge/tree/v2.5.0/docs/recipes.md)
- [API reference](https://github.com/dcastil/tailwind-merge/tree/v2.5.0/docs/api-reference.md)
- [Writing plugins](https://github.com/dcastil/tailwind-merge/tree/v2.5.0/docs/writing-plugins.md)
- [Versioning](https://github.com/dcastil/tailwind-merge/tree/v2.5.0/docs/versioning.md)
- [Contributing](https://github.com/dcastil/tailwind-merge/tree/v2.5.0/docs/contributing.md)
- [Similar packages](https://github.com/dcastil/tailwind-merge/tree/v2.5.0/docs/similar-packages.md)
- [What is it for](https://github.com/dcastil/tailwind-merge/tree/v2.5.2/docs/what-is-it-for.md)
- [When and how to use it](https://github.com/dcastil/tailwind-merge/tree/v2.5.2/docs/when-and-how-to-use-it.md)
- [Features](https://github.com/dcastil/tailwind-merge/tree/v2.5.2/docs/features.md)
- [Limitations](https://github.com/dcastil/tailwind-merge/tree/v2.5.2/docs/limitations.md)
- [Configuration](https://github.com/dcastil/tailwind-merge/tree/v2.5.2/docs/configuration.md)
- [Recipes](https://github.com/dcastil/tailwind-merge/tree/v2.5.2/docs/recipes.md)
- [API reference](https://github.com/dcastil/tailwind-merge/tree/v2.5.2/docs/api-reference.md)
- [Writing plugins](https://github.com/dcastil/tailwind-merge/tree/v2.5.2/docs/writing-plugins.md)
- [Versioning](https://github.com/dcastil/tailwind-merge/tree/v2.5.2/docs/versioning.md)
- [Contributing](https://github.com/dcastil/tailwind-merge/tree/v2.5.2/docs/contributing.md)
- [Similar packages](https://github.com/dcastil/tailwind-merge/tree/v2.5.2/docs/similar-packages.md)
20 changes: 20 additions & 0 deletions docs/changelog/v2-changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Changelog for v2 releases

## v2.5.2

### Bug Fixes

- Fix multiline input not working anymore by [@dcastil](https://github.com/dcastil) in [#459](https://github.com/dcastil/tailwind-merge/pull/459)

**Full Changelog**: [`v2.5.1...v2.5.2`](https://github.com/dcastil/tailwind-merge/compare/v2.5.1...v2.5.2)

Thanks to [@brandonmcconnell](https://github.com/brandonmcconnell), [@manavm1990](https://github.com/manavm1990), [@langy](https://github.com/langy), [@jamesreaco](https://github.com/jamesreaco) and [@jamaluddinrumi](https://github.com/jamaluddinrumi) for sponsoring tailwind-merge! ❤️

## v2.5.1

### Bug Fixes

- Fix space at beginning of input causing infinite loop by [@dcastil](https://github.com/dcastil) in [#457](https://github.com/dcastil/tailwind-merge/pull/457)

**Full Changelog**: [`v2.5.0...v2.5.1`](https://github.com/dcastil/tailwind-merge/compare/v2.5.0...v2.5.1)

Thanks to [@brandonmcconnell](https://github.com/brandonmcconnell), [@manavm1990](https://github.com/manavm1990), [@langy](https://github.com/langy), [@jamesreaco](https://github.com/jamesreaco) and [@jamaluddinrumi](https://github.com/jamaluddinrumi) for sponsoring tailwind-merge! ❤️

## v2.5.0

### New Features
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tailwind-merge",
"version": "2.5.0",
"version": "2.5.2",
"description": "Merge Tailwind CSS classes without style conflicts",
"keywords": [
"tailwindcss",
Expand Down
16 changes: 9 additions & 7 deletions src/lib/merge-classlist.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ConfigUtils } from './config-utils'
import { IMPORTANT_MODIFIER, sortModifiers } from './parse-class-name'

const SPLIT_CLASSES_REGEX = /\s+/

export const mergeClassList = (classList: string, configUtils: ConfigUtils) => {
const { parseClassName, getClassGroupId, getConflictingClassGroupIds } = configUtils

Expand All @@ -12,16 +14,12 @@ export const mergeClassList = (classList: string, configUtils: ConfigUtils) => {
* @example 'md:!pr'
*/
const classGroupsInConflict: string[] = []
const classNames = classList.trim().split(SPLIT_CLASSES_REGEX)

let result = ''

for (let i = classList.length - 1; i >= 0; ) {
while (classList[i] === ' ') {
--i
}
const nextI = classList.lastIndexOf(' ', i)
const originalClassName = classList.slice(nextI === -1 ? 0 : nextI + 1, i + 1)
i = nextI
for (let index = classNames.length - 1; index >= 0; index -= 1) {
const originalClassName = classNames[index]!

const { modifiers, hasImportantModifier, baseClassName, maybePostfixModifierPosition } =
parseClassName(originalClassName)
Expand All @@ -35,13 +33,15 @@ export const mergeClassList = (classList: string, configUtils: ConfigUtils) => {

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
}
Expand All @@ -58,6 +58,7 @@ export const mergeClassList = (classList: string, configUtils: ConfigUtils) => {
const classId = modifierId + classGroupId

if (classGroupsInConflict.includes(classId)) {
// Tailwind class omitted due to conflict
continue
}

Expand All @@ -69,6 +70,7 @@ export const mergeClassList = (classList: string, configUtils: ConfigUtils) => {
classGroupsInConflict.push(modifierId + group)
}

// Tailwind class not in conflict
result = originalClassName + (result.length > 0 ? ' ' + result : result)
}

Expand Down
15 changes: 15 additions & 0 deletions tests/wonky-inputs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { twMerge } from '../src'

test('handles wonky inputs', () => {
expect(twMerge(' block')).toBe('block')
expect(twMerge('block ')).toBe('block')
expect(twMerge(' block ')).toBe('block')
expect(twMerge(' block px-2 py-4 ')).toBe('block px-2 py-4')
expect(twMerge(' block px-2', ' ', ' py-4 ')).toBe('block px-2 py-4')
expect(twMerge('block\npx-2')).toBe('block px-2')
expect(twMerge('\nblock\npx-2\n')).toBe('block px-2')
expect(twMerge(' block\n \n px-2 \n py-4 ')).toBe('block px-2 py-4')
expect(twMerge('\r block\n\r \n px-2 \n py-4 ')).toBe(
'block px-2 py-4',
)
})

0 comments on commit 3f53e46

Please sign in to comment.