Skip to content

Commit

Permalink
fix: shoudl parse negative value
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackie1210 committed Oct 14, 2023
1 parent f010ac2 commit 21a7d6a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/radial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function parseRadialGradient(input: string): RadialResult {
const prefix = properties[0].split('at').map(v => v.trim())

const shape = ((prefix[0] || '').match(/(circle|ellipse)/) || [])[1]
const size: string[] = (prefix[0] || '').match(/(\d+\.?\d*(vw|vh|px|em|rem)?|closest-corner|closest-side|farthest-corner|farthest-side)/g) || []
const size: string[] = (prefix[0] || '').match(/(-?\d+\.?\d*(vw|vh|px|em|rem)?|closest-corner|closest-side|farthest-corner|farthest-side)/g) || []
const position = extendPosition((prefix[1] || '').split(' '))

if (!shape) {
Expand Down
18 changes: 18 additions & 0 deletions test/radial.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,22 @@ describe('radial', () => {
]
})
})

it('should parse negative radius', () => {
const g = parseRadialGradient('radial-gradient(circle -20px, #333, #eee 80%)')

expect(g).toEqual({
shape: 'circle',
repeating: false,
position: {
x: { type: 'keyword', value: 'center' },
y: { type: 'keyword', value: 'center' },
},
size: [{ type: 'length', value: '-20px'}],
stops: [
{ color: '#333' },
{ color: '#eee', offset: '80%' }
]
})
})
})

0 comments on commit 21a7d6a

Please sign in to comment.