Skip to content

Commit 9bc47fd

Browse files
pjewebshuding
andauthored
fix: positioned mask image (#566)
Resolves #565 --------- Co-authored-by: Shu Ding <[email protected]>
1 parent 69e4bb7 commit 9bc47fd

3 files changed

+31
-2
lines changed

src/builder/mask-image.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export default async function buildMaskImage(
3737
mask +=
3838
def +
3939
buildXMLString('rect', {
40-
x: 0,
41-
y: 0,
40+
x: left,
41+
y: top,
4242
width,
4343
height,
4444
fill: `url(#${_id})`,

test/mask-image.test.tsx

+29
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,33 @@ describe('Mask-*', () => {
209209
)
210210
expect(toImage(svg, 100)).toMatchImageSnapshot()
211211
})
212+
213+
it('should support mask-image on positioned elements', async () => {
214+
const svg = await satori(
215+
<div
216+
style={{
217+
height: '100%',
218+
width: '100%',
219+
display: 'flex',
220+
}}
221+
>
222+
<div
223+
style={{
224+
position: 'absolute',
225+
top: 20,
226+
left: 20,
227+
height: 100,
228+
width: 100,
229+
display: 'flex',
230+
background: 'green',
231+
maskImage:
232+
"url(data:image/svg+xml,%3Csvg viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Crect fill='white' width='100' height='100' /%3E%3C/svg%3E)",
233+
border: '1px solid red',
234+
}}
235+
></div>
236+
</div>,
237+
{ width: 120, height: 120, fonts }
238+
)
239+
expect(toImage(svg, 120)).toMatchImageSnapshot()
240+
})
212241
})

0 commit comments

Comments
 (0)