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
3 changes: 3 additions & 0 deletions .changelog/abs-sign-math-functions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Fixed

- Add whitespace around math operators in `abs(…)` and `sign(…)`, and infer them as a length (e.g. `text-[abs(var(--size))]` generates `font-size` instead of `color`)
5 changes: 5 additions & 0 deletions packages/tailwindcss/src/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26597,6 +26597,7 @@ test('text', async () => {
'text-[clamp(1rem,2rem,3rem)]',
'text-[clamp(1rem,var(--size),3rem)]',
'text-[clamp(1rem,var(--size),3rem)]/9',
'text-[abs(var(--size))]',
'text-[--spacing(2)]',
'text-[1cap]',
'text-[1ic]',
Expand Down Expand Up @@ -26789,6 +26790,10 @@ test('text', async () => {
font-size: 50%;
}

.text-\\[abs\\(var\\(--size\\)\\)\\] {
font-size: abs(var(--size));
}

.text-\\[absolute-size\\:var\\(--my-size\\)\\] {
font-size: var(--my-size);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ describe('adds spaces around math operators', () => {
['round(1+2,1+3)', 'round(1 + 2, 1 + 3)'],
['round(to-zero,1+2,1+3)', 'round(to-zero, 1 + 2, 1 + 3)'],

// abs(…) and sign(…) functions
['abs(20%-100px)', 'abs(20% - 100px)'],
['sign(10px-20px)', 'sign(10px - 20px)'],
['calc(abs(1rem-2rem)*2)', 'calc(abs(1rem - 2rem) * 2)'],
['calc(1px*sign(var(--x)-50%))', 'calc(1px * sign(var(--x) - 50%))'],

// Nested parens in non-math functions don't format their contents
['env((safe-area-inset-bottom))', 'env((safe-area-inset-bottom))'],

Expand Down
28 changes: 15 additions & 13 deletions packages/tailwindcss/src/utils/math-operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,27 @@ const PERCENT = 0x25
const UNDERSCORE = 0x5f

const MATH_FUNCTIONS = [
'calc',
'min',
'max',
'clamp',
'mod',
'rem',
'sin',
'cos',
'tan',
'asin',
'abs',
'acos',
'asin',
'atan',
'atan2',
'pow',
'sqrt',
'calc',
'clamp',
'cos',
'exp',
'hypot',
'log',
'exp',
'max',
'min',
'mod',
'pow',
'rem',
'round',
'sign',
'sin',
'sqrt',
'tan',
]

const MATH_FUNCTIONS_SET = new Set(MATH_FUNCTIONS)
Expand Down
Loading