Skip to content

Commit

Permalink
fix: should render text-shadow with color like 'rgba(8, 15, 30, 50%)' (
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackie1210 authored Apr 18, 2023
1 parent 4405d09 commit 54102a8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/handler/expand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function handleSpecialCase(
// Handle multiple text shadows if provided.
value = value.toString().trim()
if (value.includes(',')) {
const shadows = value.split(',')
const shadows = splitTextShadow(value)
const result = {}
for (const shadow of shadows) {
const styles = getStylesForProperty('textShadow', shadow, true)
Expand All @@ -190,6 +190,29 @@ function handleSpecialCase(
return
}

function splitTextShadow(str: string) {
const result: string[] = []
let skip = false
let startPos = 0
const len = str.length

for (let i = 0; i < len; ++i) {
const t = str[i]
if (t === ')') skip = false
if (skip) continue
if (t === '(') skip = true

if (t === ',') {
result.push(str.substring(startPos, i))
startPos = i + 1
}
}

result.push(str.substring(startPos, len))

return result.map((s) => s.trim())
}

function getErrorHint(name: string) {
if (name === 'transform') {
return ' Only absolute lengths such as `10px` are supported.'
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions test/shadow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,25 @@ describe('Shadow', () => {
)
expect(toImage(svg, 100)).toMatchImageSnapshot()
})

it('should support text shadows if exist unexpected comma', async () => {
const svg = await satori(
<div
style={{
background: 'white',
width: 100,
height: 100,
fontSize: 40,
textShadow:
'2px 2px red, 4px 4px #4bf542, 6px 6px rgb(186, 147, 17)',
}}
>
Lynn
</div>,
{ width: 100, height: 100, fonts }
)

expect(toImage(svg, 100)).toMatchImageSnapshot()
})
})
})

1 comment on commit 54102a8

@vercel
Copy link

@vercel vercel bot commented on 54102a8 Apr 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.