Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/tailwindcss/src/canonicalize-candidates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s',
['[color:var(--color-red-500)]/[25%]', 'text-red-500/25'],
['[color:var(--color-red-500)]/[100%]', 'text-red-500'],
['[color:var(--color-red-500)]/100', 'text-red-500'],
['[color:var(--color-red-500)]/[10%]', 'text-red-500/10'],
['[color:var(--color-red-500)]/[10.0%]', 'text-red-500/10'],
['[color:var(--color-red-500)]/[.1]', 'text-red-500/10'],
['[color:var(--color-red-500)]/[.10]', 'text-red-500/10'],
// No need for `/50` because that's already encoded in the `--color-primary`
// value
['[color:oklch(62.3%_0.214_259.815)]/50', 'text-primary'],
Expand Down
6 changes: 5 additions & 1 deletion packages/tailwindcss/src/canonicalize-candidates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,11 @@ function optimizeModifier(designSystem: DesignSystem, candidate: Candidate): Can
{
let newModifier: NamedUtilityValue = {
kind: 'named',
value: modifier.value.endsWith('%') ? modifier.value.slice(0, -1) : modifier.value,
value: modifier.value.endsWith('%')
? modifier.value.includes('.')
? `${Number(modifier.value.slice(0, -1))}`
: modifier.value.slice(0, -1)
: modifier.value,
fraction: null,
}

Expand Down
13 changes: 13 additions & 0 deletions packages/tailwindcss/src/signatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { dimensions } from './utils/dimensions'
import { isValidSpacingMultiplier } from './utils/infer-data-type'
import * as ValueParser from './value-parser'

const FLOATING_POINT_PERCENTAGE = /\d*\.\d+(?:[eE][+-]?\d+)?%/g

// Given a utility, compute a signature that represents the utility. The
// signature will be a normalised form of the generated CSS for the utility, or
// a unique symbol if the utility is not valid. The class in the selector will
Expand Down Expand Up @@ -59,6 +61,17 @@ export const computeUtilitySignature = new DefaultMap<
if (node.value === undefined || node.property === '--tw-sort') {
replaceWith([])
}

// Normalize percentages by removing unnecessary dots and zeros.
//
// E.g.: `50.0%` → `50%`
else if (node.value.includes('%')) {
FLOATING_POINT_PERCENTAGE.lastIndex = 0
node.value = node.value.replaceAll(
FLOATING_POINT_PERCENTAGE,
(match) => `${Number(match.slice(0, -1))}%`,
)
}
}

// Replace special nodes with its children
Expand Down