tailwind-merge
Advanced tools
Comparing version 2.5.1-dev.056b2a31bf7d9244aa97cc859e110bdbae6723e5 to 2.5.1-dev.0f0f53e1b3d930b21560eea24b467e0870854f52
{ | ||
"name": "tailwind-merge", | ||
"version": "2.5.1-dev.056b2a31bf7d9244aa97cc859e110bdbae6723e5", | ||
"version": "2.5.1-dev.0f0f53e1b3d930b21560eea24b467e0870854f52", | ||
"description": "Merge Tailwind CSS classes without style conflicts", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -6,3 +6,3 @@ <!-- This file is autogenerated. If you want to change this content, please do the changes in `./docs/README.md` instead. --> | ||
<a href="https://github.com/dcastil/tailwind-merge"> | ||
<img src="https://github.com/dcastil/tailwind-merge/raw/056b2a31bf7d9244aa97cc859e110bdbae6723e5/assets/logo.svg" alt="tailwind-merge" height="150px" /> | ||
<img src="https://github.com/dcastil/tailwind-merge/raw/0f0f53e1b3d930b21560eea24b467e0870854f52/assets/logo.svg" alt="tailwind-merge" height="150px" /> | ||
</a> | ||
@@ -29,12 +29,12 @@ </div> | ||
- [What is it for](https://github.com/dcastil/tailwind-merge/tree/056b2a31bf7d9244aa97cc859e110bdbae6723e5/docs/what-is-it-for.md) | ||
- [When and how to use it](https://github.com/dcastil/tailwind-merge/tree/056b2a31bf7d9244aa97cc859e110bdbae6723e5/docs/when-and-how-to-use-it.md) | ||
- [Features](https://github.com/dcastil/tailwind-merge/tree/056b2a31bf7d9244aa97cc859e110bdbae6723e5/docs/features.md) | ||
- [Limitations](https://github.com/dcastil/tailwind-merge/tree/056b2a31bf7d9244aa97cc859e110bdbae6723e5/docs/limitations.md) | ||
- [Configuration](https://github.com/dcastil/tailwind-merge/tree/056b2a31bf7d9244aa97cc859e110bdbae6723e5/docs/configuration.md) | ||
- [Recipes](https://github.com/dcastil/tailwind-merge/tree/056b2a31bf7d9244aa97cc859e110bdbae6723e5/docs/recipes.md) | ||
- [API reference](https://github.com/dcastil/tailwind-merge/tree/056b2a31bf7d9244aa97cc859e110bdbae6723e5/docs/api-reference.md) | ||
- [Writing plugins](https://github.com/dcastil/tailwind-merge/tree/056b2a31bf7d9244aa97cc859e110bdbae6723e5/docs/writing-plugins.md) | ||
- [Versioning](https://github.com/dcastil/tailwind-merge/tree/056b2a31bf7d9244aa97cc859e110bdbae6723e5/docs/versioning.md) | ||
- [Contributing](https://github.com/dcastil/tailwind-merge/tree/056b2a31bf7d9244aa97cc859e110bdbae6723e5/docs/contributing.md) | ||
- [Similar packages](https://github.com/dcastil/tailwind-merge/tree/056b2a31bf7d9244aa97cc859e110bdbae6723e5/docs/similar-packages.md) | ||
- [What is it for](https://github.com/dcastil/tailwind-merge/tree/0f0f53e1b3d930b21560eea24b467e0870854f52/docs/what-is-it-for.md) | ||
- [When and how to use it](https://github.com/dcastil/tailwind-merge/tree/0f0f53e1b3d930b21560eea24b467e0870854f52/docs/when-and-how-to-use-it.md) | ||
- [Features](https://github.com/dcastil/tailwind-merge/tree/0f0f53e1b3d930b21560eea24b467e0870854f52/docs/features.md) | ||
- [Limitations](https://github.com/dcastil/tailwind-merge/tree/0f0f53e1b3d930b21560eea24b467e0870854f52/docs/limitations.md) | ||
- [Configuration](https://github.com/dcastil/tailwind-merge/tree/0f0f53e1b3d930b21560eea24b467e0870854f52/docs/configuration.md) | ||
- [Recipes](https://github.com/dcastil/tailwind-merge/tree/0f0f53e1b3d930b21560eea24b467e0870854f52/docs/recipes.md) | ||
- [API reference](https://github.com/dcastil/tailwind-merge/tree/0f0f53e1b3d930b21560eea24b467e0870854f52/docs/api-reference.md) | ||
- [Writing plugins](https://github.com/dcastil/tailwind-merge/tree/0f0f53e1b3d930b21560eea24b467e0870854f52/docs/writing-plugins.md) | ||
- [Versioning](https://github.com/dcastil/tailwind-merge/tree/0f0f53e1b3d930b21560eea24b467e0870854f52/docs/versioning.md) | ||
- [Contributing](https://github.com/dcastil/tailwind-merge/tree/0f0f53e1b3d930b21560eea24b467e0870854f52/docs/contributing.md) | ||
- [Similar packages](https://github.com/dcastil/tailwind-merge/tree/0f0f53e1b3d930b21560eea24b467e0870854f52/docs/similar-packages.md) |
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) => { | ||
@@ -15,20 +17,9 @@ const { parseClassName, getClassGroupId, getConflictingClassGroupIds } = configUtils | ||
const classGroupsInConflict: string[] = [] | ||
const classNames = classList.trim().split(SPLIT_CLASSES_REGEX) | ||
let result = '' | ||
let index = classList.length - 1 | ||
while (index >= 0) { | ||
while (classList[index] === ' ') { | ||
index -= 1 | ||
} | ||
for (let index = classNames.length - 1; index >= 0; index -= 1) { | ||
const originalClassName = classNames[index]! | ||
if (index < 0) { | ||
break | ||
} | ||
const nextIndex = classList.lastIndexOf(' ', index) | ||
const originalClassName = classList.slice(nextIndex + 1, index + 1) | ||
index = nextIndex | ||
const { modifiers, hasImportantModifier, baseClassName, maybePostfixModifierPosition } = | ||
@@ -46,2 +37,3 @@ parseClassName(originalClassName) | ||
if (!hasPostfixModifier) { | ||
// Not a Tailwind class | ||
result = originalClassName + (result.length > 0 ? ' ' + result : result) | ||
@@ -54,2 +46,3 @@ continue | ||
if (!classGroupId) { | ||
// Not a Tailwind class | ||
result = originalClassName + (result.length > 0 ? ' ' + result : result) | ||
@@ -71,2 +64,3 @@ continue | ||
if (classGroupsInConflict.includes(classId)) { | ||
// Tailwind class omitted due to conflict | ||
continue | ||
@@ -83,2 +77,3 @@ } | ||
// Tailwind class not in conflict | ||
result = originalClassName + (result.length > 0 ? ' ' + result : result) | ||
@@ -85,0 +80,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
709166
15512