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: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function resolveStops(v: string[]): ColorStop[] {
return stops
}

const REGEX = /^(-?\d+\.?\d*)(%|vw|vh|px|em|rem|deg|rad|grad|turn|ch|vmin|vmax)$/
const REGEX = /^(-?\d+\.?\d*)(%|vw|vh|px|em|rem|deg|rad|grad|turn|ch|vmin|vmax)?$/

function isHint(v: string) {
return REGEX.test(v)
Expand All @@ -63,5 +63,5 @@ export function resolveLength(v?: string) {

const [, value, unit] = v.trim().match(REGEX) || []

return { value, unit }
return { value, unit: unit ?? 'px' }
}
50 changes: 50 additions & 0 deletions test/radial.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,56 @@ describe('radial', () => {
{ color: 'red', offset: undefined }
]
})
})

it('should parse pure number', () => {
const g = parseRadialGradient('radial-gradient(circle at 0 50%, blue, red)')

expect(g).toEqual({
shape: 'circle',
repeating: false,
position: {
x: { type: 'length', value: {
value: "0", unit: 'px'
}},
y: { type: 'length', value: {
value: "50", unit: '%'
} },
},
size: [{ type: 'keyword', value: 'farthest-corner'}],
stops: [
{ color: 'blue', offset: undefined },
{ color: 'red', offset: undefined }
]
})
})

it('should parse repeating-radial-gradient(black,black 30px,white 30px,white 60px)', () => {
const g = parseRadialGradient('repeating-radial-gradient(black,black 30px,white 30px,white 60px)')

expect(g).toEqual({
shape: 'ellipse',
repeating: true,
position: {
x: { type: 'keyword', value: 'center' },
y: { type: 'keyword', value: 'center' },
},
size: [{ type: 'keyword', value: 'farthest-corner'}],
stops: [
{ color: 'black', offset: undefined },
{ color: 'black', offset: {
unit: 'px',
value: '30'
} },
{ color: 'white', offset: {
unit: 'px',
value: '30'
} },
{ color: 'white', offset: {
unit: 'px',
value: '60'
} }
]
})
})
})
Loading