Skip to content

Commit de897c4

Browse files
committed
fix: trim whitespace in polygon clip-path point parsing
Fixes #763 The parsePolygon function split comma-separated points without trimming whitespace first. When CSS like 'polygon(100% 0, 81.844% 100%)' was parsed, the space after each comma created a phantom empty-string element during the subsequent .split(' '), causing x-coordinates to be resolved against height instead of width for all points except the first. This was invisible in tests because existing tests used square elements (width === height). Adding .trim() before .split(/\s+/) ensures correct index mapping for the width/height resolution.
1 parent b712d5b commit de897c4

4 files changed

Lines changed: 21 additions & 1 deletion

File tree

.husky/pre-commit

100755100644
File mode changed.

src/parser/shape.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ export function createShapeParser(
124124
.split(',')
125125
.map((v) =>
126126
v
127-
.split(' ')
127+
.trim()
128+
.split(/\s+/)
128129
.map((k, i) =>
129130
lengthToNumber(
130131
k,
Loading

test/clip-path.test.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,25 @@ describe('clipPath', () => {
104104
expect(toImage(svg)).toMatchImageSnapshot()
105105
})
106106

107+
it('should render polygon clip-path correctly on non-square elements', async () => {
108+
const svg = await satori(
109+
<div
110+
style={{
111+
height: '100%',
112+
width: '100%',
113+
display: 'flex',
114+
alignItems: 'center',
115+
justifyContent: 'center',
116+
backgroundColor: '#fff',
117+
clipPath: 'polygon(100% 0, 81.844% 100%, 0 100%, 18.156% 0)',
118+
}}
119+
/>,
120+
{ width: 180, height: 100, fonts }
121+
)
122+
const image = toImage(svg)
123+
expect(image).toMatchImageSnapshot()
124+
})
125+
107126
it('should respect left and top', async () => {
108127
const svg = await satori(
109128
<div

0 commit comments

Comments
 (0)