Skip to content
Open
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
10 changes: 9 additions & 1 deletion src/builder/mask-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ export default async function buildMaskImage(
})
}

mask = buildXMLString('mask', { id: miId }, mask)
const mode = maskImage[0]?.mode
const maskType =
mode === 'alpha' ? 'alpha' : mode === 'luminance' ? 'luminance' : undefined

mask = buildXMLString(
'mask',
{ id: miId, ...(maskType ? { 'mask-type': maskType } : {}) },
mask
)

return [miId, mask]
}
2 changes: 2 additions & 0 deletions src/parser/mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface MaskProperty {
repeat: string
origin: string
clip: string
mode: string
}

export function parseMask(
Expand All @@ -26,6 +27,7 @@ export function parseMask(
repeat: getMaskProperty(style, 'repeat') || 'repeat',
origin: getMaskProperty(style, 'origin') || 'border-box',
clip: getMaskProperty(style, 'origin') || 'border-box',
mode: getMaskProperty(style, 'mode') || 'match-source',
}

let maskImages = splitEffects(maskImage).filter((v) => v && v !== 'none')
Expand Down
28 changes: 28 additions & 0 deletions test/mask-image.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,34 @@ describe('Mask-*', () => {
expect(toImage(svg, 100)).toMatchImageSnapshot()
})

it('should support mask-mode', async () => {
const svgs = await Promise.all(
(['alpha', 'luminance', 'match-source'] as const).map((maskMode) =>
satori(
<div
style={{
width: '100%',
height: '100%',
display: 'flex',
backgroundImage: `url(${PNG_SAMPLE})`,
maskImage: 'linear-gradient(to right, blue, transparent)',
maskMode,
}}
></div>,
{ width: 100, height: 100, fonts }
)
)
)

expect(svgs[0]).toContain('mask-type="alpha"')
expect(svgs[1]).toContain('mask-type="luminance"')
expect(svgs[2]).not.toContain('mask-type=')

svgs.forEach((svg) => {
expect(toImage(svg, 100)).toMatchImageSnapshot()
})
})

it('should support mask-image on positioned elements', async () => {
const svg = await satori(
<div
Expand Down
Loading