({
classList,
api,
removeDuplicates,
}: {
classList: string[]
api: UnifiedApi
removeDuplicates: boolean
})
| 93 | } |
| 94 | |
| 95 | export function sortClassList({ |
| 96 | classList, |
| 97 | api, |
| 98 | removeDuplicates, |
| 99 | }: { |
| 100 | classList: string[] |
| 101 | api: UnifiedApi |
| 102 | removeDuplicates: boolean |
| 103 | }) { |
| 104 | // Re-order classes based on the Tailwind CSS configuration |
| 105 | let orderedClasses = api.getClassOrder(classList) |
| 106 | |
| 107 | orderedClasses.sort(([nameA, a], [nameZ, z]) => { |
| 108 | // Move `...` to the end of the list |
| 109 | if (nameA === '...' || nameA === '…') return 1 |
| 110 | if (nameZ === '...' || nameZ === '…') return -1 |
| 111 | |
| 112 | if (a === z) return 0 |
| 113 | if (a === null) return -1 |
| 114 | if (z === null) return 1 |
| 115 | return bigSign(a - z) |
| 116 | }) |
| 117 | |
| 118 | // Remove duplicate Tailwind classes |
| 119 | let removedIndices = new Set<number>() |
| 120 | |
| 121 | if (removeDuplicates) { |
| 122 | let seenClasses = new Set<string>() |
| 123 | |
| 124 | orderedClasses = orderedClasses.filter(([cls, order], index) => { |
| 125 | if (seenClasses.has(cls)) { |
| 126 | removedIndices.add(index) |
| 127 | return false |
| 128 | } |
| 129 | |
| 130 | // Only consider known classes when removing duplicates |
| 131 | if (order !== null) { |
| 132 | seenClasses.add(cls) |
| 133 | } |
| 134 | |
| 135 | return true |
| 136 | }) |
| 137 | } |
| 138 | |
| 139 | return { |
| 140 | classList: orderedClasses.map(([className]) => className), |
| 141 | removedIndices, |
| 142 | } |
| 143 | } |
no test coverage detected
searching dependent graphs…