Skip to content
Closed
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
16 changes: 16 additions & 0 deletions packages/tailwindcss/src/utils/replace-shadow-colors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ describe('without replacer', () => {
expect(parsed).toMatchInlineSnapshot(`"1px 2px 3px 4px var(--tw-shadow-color, currentcolor)"`)
})

it('should handle CSS math functions as lengths', () => {
let parsed = replaceShadowColors('0 0 calc(1 * var(--spacing)) black', replacer)
expect(parsed).toMatchInlineSnapshot(
`"0 0 calc(1 * var(--spacing)) var(--tw-shadow-color, black)"`,
)

parsed = replaceShadowColors('0 0 min(1px, 2px) black', replacer)
expect(parsed).toMatchInlineSnapshot(`"0 0 min(1px, 2px) var(--tw-shadow-color, black)"`)

parsed = replaceShadowColors('0 0 max(1px, 2px) black', replacer)
expect(parsed).toMatchInlineSnapshot(`"0 0 max(1px, 2px) var(--tw-shadow-color, black)"`)

parsed = replaceShadowColors('0 0 clamp(1px, 2px, 3px) black', replacer)
expect(parsed).toMatchInlineSnapshot(`"0 0 clamp(1px, 2px, 3px) var(--tw-shadow-color, black)"`)
})
Comment thread
greptile-apps[bot] marked this conversation as resolved.

it('should handle multiple shadows', () => {
let parsed = replaceShadowColors(
['var(--my-shadow)', '1px 1px var(--my-color)', '0 0 1px var(--my-color)'].join(', '),
Expand Down
5 changes: 1 addition & 4 deletions packages/tailwindcss/src/utils/replace-shadow-colors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { segment } from './segment'

const KEYWORDS = new Set(['inset', 'inherit', 'initial', 'revert', 'unset'])
const LENGTH = /^-?(\d+|\.\d+)(.*?)$/g
const LENGTH = /^-?(?:(?:\d+|\.\d+).*|(?:calc|min|max|clamp)\(.*\))$/

export function replaceShadowColors(input: string, replacement: (color: string) => string) {
let shadows = segment(input, ',').map((shadow) => {
Expand All @@ -20,9 +20,6 @@ export function replaceShadowColors(input: string, replacement: (color: string)
} else if (offsetY === null) {
offsetY = part
}

// Reset index, since the regex is stateful.
LENGTH.lastIndex = 0
} else if (color === null) {
color = part
}
Expand Down