AI-native design editor. Open-source Figma alternative.
fix(canvas): apply a mask's opacity and blur to what it masks (#1030)
Danila Poyarkov139db0700ece
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6b72ae0ab..95b0d4757 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -148,6 +148,7 @@- Gradient stops in the fill picker show their full position and opacity, such as 100%, instead of cutting them off; each stop's colour, hex, and opacity share one field as in the properties panel.- Keep design variable bindings and honor `replace_id` and `insert_index` when `render` runs through the stdio MCP server (`openpencil-mcp`) against the desktop or web app, as it already did through the HTTP endpoint (#830).- Draw layers masked by a group, such as Figma's clip path groups, instead of hiding them; a group used as a mask masks with what its layers draw.+- Draw what a mask masks through the mask's opacity and layer blur, as Figma does, so a half-transparent or blurred mask fades or softens its layers instead of masking them fully. An outline mask ignores how opaque its fill is, and a luminance mask counts its opacity twice, as in Figma.- Import SVG files that start with an XML declaration or doctype, such as Illustrator and Inkscape exports, instead of reporting no supported elements.- Keep `fill-opacity` and `stroke-opacity` when importing SVG instead of drawing those paints opaque.- Use an API key saved in Settings for the open AI chat right away, including when asking again after a failed request, instead of only after reloading; the failure's notice closes once the request is sent again.diff --git a/packages/core/src/canvas/masks.ts b/packages/core/src/canvas/masks.tsindex 6ddd07959..9a812a1f2 100644--- a/packages/core/src/canvas/masks.ts+++ b/packages/core/src/canvas/masks.ts@@ -90,6 +90,13 @@ export function renderMaskedChildIds(r.effectLayerPaint.setColorFilter(lumaFilter)canvas.saveLayer(r.effectLayerPaint, layerBounds)renderMask(mask.id)+ // Skia's luma is that of the premultiplied color; Figma also scales it by the mask's+ // alpha, so a mask at half opacity shows a quarter of what it masks.+ resetMaskPaint(r)+ r.effectLayerPaint.setBlendMode(r.ck.BlendMode.DstIn)+ canvas.saveLayer(r.effectLayerPaint, layerBounds)+ renderMask(mask.id)+ canvas.restore()canvas.restore()continue}diff --git a/packages/core/src/canvas/scene.ts b/packages/core/src/canvas/scene.tsindex 706257193..13bd75681 100644--- a/packages/core/src/canvas/scene.ts+++ b/packages/core/src/canvas/scene.ts@@ -144,13 +144,39 @@ function renderMaskNodeContent(): void {canvas.save()canvas.translate(node.x, node.y)+ // As in Figma, a mask's opacity and layer blur reach what it masks; its blend mode does not.+ const blur = node.effects.find(+ (effect) =>+ effect.visible && (effect.type === 'LAYER_BLUR' || effect.type === 'FOREGROUND_BLUR')+ )+ const layered = node.opacity < 1 || blur !== undefined+ if (layered) {+ const padding = (blur?.radius ?? 0) * 2+ r.opacityPaint.setAlphaf(node.opacity)+ r.opacityPaint.setBlendMode(r.ck.BlendMode.SrcOver)+ r.opacityPaint.setImageFilter(blur ? r.getCachedBlur(blur.radius / 2) : null)+ canvas.saveLayer(+ r.opacityPaint,+ r.ck.LTRBRect(-padding, -padding, node.width + padding, node.height + padding)+ )+ r.opacityPaint.setImageFilter(null)+ }applyNodeTransforms(canvas, node, overlays)- renderNodeContent(r, canvas, graph, node, {})+ renderNodeContent(r, canvas, graph, node.maskType === 'VECTOR' ? opaqueFills(node) : node, {})// A group or frame used as a mask masks with what its layers draw, as in Figma.renderChildren(r, canvas, graph, node, overlays, absX + node.x, absY + node.y, true)+ if (layered) canvas.restore()canvas.restore()}+/** An outline mask masks with its shape alone, so Figma ignores how opaque its fills are. */+function opaqueFills(node: SceneNode): SceneNode {+ return {+ ...node,+ fills: node.fills.map((fill) => ({ ...fill, opacity: 1, color: { ...fill.color, a: 1 } }))+ }+}+function renderChildIds(r: SkiaRenderer,canvas: Canvas,diff --git a/packages/core/tests/canvas/masks.test.ts b/packages/core/tests/canvas/masks.test.tsnew file mode 100644index 000000000..d06741724--- /dev/null+++ b/packages/core/tests/canvas/masks.test.ts@@ -0,0 +1,79 @@+import { afterAll, describe, expect, test } from 'bun:test'++import { SkiaRenderer } from '@open-pencil/core'+import { initCanvasKit, renderNodesToImage } from '@open-pencil/core/io'+import { SceneGraph, type MaskType, type SceneNode } from '@open-pencil/scene-graph'++import { expectDefined } from '../helpers/assert'++const ck = await initCanvasKit()+const renderer = new SkiaRenderer(ck, expectDefined(ck.MakeSurface(1, 1)))+afterAll(() => renderer.destroy())++const solid = (r: number, g: number, b: number, opacity = 1) => ({+ type: 'SOLID' as const,+ color: { r, g, b, a: 1 },+ opacity,+ visible: true+})++/** The alpha of a red square masked by an 80px ellipse, at the centre of the 100px frame. */+function maskedAlpha(maskType: MaskType, mask: Partial<SceneNode>): number {+ const graph = new SceneGraph()+ const page = graph.getPages()[0].id+ const frame = graph.createNode('FRAME', page, { width: 100, height: 100, fills: [] })+ const group = graph.createNode('GROUP', frame.id, { width: 100, height: 100 })+ graph.createNode('ELLIPSE', group.id, {+ x: 10,+ y: 10,+ width: 80,+ height: 80,+ fills: [maskType === 'LUMINANCE' ? solid(1, 1, 1) : solid(0, 0, 0)],+ isMask: true,+ maskType,+ ...mask+ })+ graph.createNode('RECTANGLE', group.id, { width: 100, height: 100, fills: [solid(1, 0, 0)] })+ const png = expectDefined(+ renderNodesToImage(ck, renderer, graph, page, [frame.id], {+ scale: 1,+ format: 'PNG',+ trimTransparent: false+ })+ )+ const image = expectDefined(ck.MakeImageFromEncoded(png))+ try {+ const pixels = expectDefined(+ image.readPixels(50, 50, {+ width: 1,+ height: 1,+ alphaType: ck.AlphaType.Unpremul,+ colorType: ck.ColorType.RGBA_8888,+ colorSpace: ck.ColorSpace.SRGB+ })+ )+ return pixels[3]+ } finally {+ image.delete()+ }+}++// Values read from Figma 126 exports of the same scene.+describe('a mask draws what it masks as Figma does', () => {+ test('through its opacity, which a luminance mask applies twice', () => {+ expect(maskedAlpha('ALPHA', { opacity: 0.5 })).toBe(128)+ expect(maskedAlpha('VECTOR', { opacity: 0.5 })).toBe(128)+ expect(maskedAlpha('LUMINANCE', { opacity: 0.5 })).toBe(64)+ })++ test('with an outline mask ignoring how opaque its fill is', () => {+ expect(maskedAlpha('ALPHA', { fills: [solid(0, 0, 0, 0.5)] })).toBe(128)+ expect(maskedAlpha('VECTOR', { fills: [solid(0, 0, 0, 0.5)] })).toBe(255)+ })++ test('without its blend mode', () => {+ for (const maskType of ['ALPHA', 'VECTOR', 'LUMINANCE'] as const) {+ expect(maskedAlpha(maskType, { blendMode: 'MULTIPLY' })).toBe(255)+ }+ })+})diff --git a/tests/e2e/canvas/pattern-mask-visual.spec.ts b/tests/e2e/canvas/pattern-mask-visual.spec.tsindex 9cabf8cb2..065a290bf 100644--- a/tests/e2e/canvas/pattern-mask-visual.spec.ts+++ b/tests/e2e/canvas/pattern-mask-visual.spec.ts@@ -1,242 +1,27 @@import { expect, test, useEditorSetupWithClear } from '#tests/e2e/fixtures'+import { maskSceneDriver } from '#tests/helpers/canvas/masks/driver'const editor = useEditorSetupWithClear('/?test&no-chrome&no-rulers')+const scenes = maskSceneDriver(() => editor.page)async function expectCanvas(name: string) {+ await editor.canvas.waitForRender()editor.canvas.assertNoErrors()const buffer = await editor.canvas.screenshotCanvasRegion()expect(buffer).toMatchSnapshot(`${name}.png`)}test('pattern fills from source nodes', async () => {- await editor.page.evaluate(() => {- const store = window.openPencil?.getStore?.()- if (!store) throw new Error('OpenPencil store not initialized')- const pageId = store.state.currentPageId-- const source = store.graph.createNode('ELLIPSE', pageId, {- name: 'Pattern source dot',- x: -1000,- y: -1000,- width: 18,- height: 18,- visible: false,- fills: [- { type: 'SOLID', color: { r: 0.96, g: 0.35, b: 0.12, a: 1 }, visible: true, opacity: 1 }- ]- })-- store.graph.createNode('RECTANGLE', pageId, {- name: 'Pattern fill visual',- x: 84,- y: 80,- width: 240,- height: 150,- cornerRadius: 18,- fills: [- {- type: 'PATTERN',- sourceNodeId: source.id,- patternTileType: 'HORIZONTAL_HEXAGONAL',- scale: 1.25,- patternSpacing: { x: 0.45, y: 0.35 },- horizontalAlignment: 'CENTER',- verticalAlignment: 'CENTER',- color: { r: 0.96, g: 0.35, b: 0.12, a: 1 },- visible: true,- opacity: 1- }- ],- strokes: [- {- type: 'SOLID',- color: { r: 0.08, g: 0.1, b: 0.18, a: 0.18 },- weight: 2,- visible: true,- opacity: 1,- align: 'INSIDE'- }- ]- })-- store.clearSelection()- store.requestRender()- })- await editor.canvas.waitForRender()+ await scenes.show('pattern-fills')await expectCanvas('pattern-fills-from-source-nodes')})test('luminance masks and transformed tile fills', async () => {- await editor.page.evaluate(async () => {- const store = window.openPencil?.getStore?.()- if (!store) throw new Error('OpenPencil store not initialized')- const pageId = store.state.currentPageId-- const imageCanvas = document.createElement('canvas')- imageCanvas.width = 32- imageCanvas.height = 32- const ctx = imageCanvas.getContext('2d')- if (!ctx) throw new Error('Cannot create tile fixture canvas')- ctx.fillStyle = '#111827'- ctx.fillRect(0, 0, 32, 32)- ctx.fillStyle = '#f97316'- ctx.fillRect(0, 0, 16, 16)- ctx.fillStyle = '#38bdf8'- ctx.fillRect(16, 16, 16, 16)- ctx.fillStyle = '#facc15'- ctx.fillRect(20, 4, 8, 8)- const blob = await new Promise<Blob>((resolve, reject) => {- imageCanvas.toBlob((result) => {- if (result) {- resolve(result)- return- }- reject(new Error('Failed to encode tile fixture'))- }, 'image/png')- })- const imageHash = store.storeImage(new Uint8Array(await blob.arrayBuffer()))-- store.graph.createNode('RECTANGLE', pageId, {- name: 'Transformed tile fill visual',- x: 80,- y: 76,- width: 180,- height: 130,- cornerRadius: 18,- fills: [- {- type: 'IMAGE',- color: { r: 0, g: 0, b: 0, a: 1 },- visible: true,- opacity: 1,- imageHash,- imageScaleMode: 'TILE',- imageTransform: { m00: 3, m01: 0, m02: 0, m10: 0, m11: 3, m12: 0 }- }- ],- strokes: [- {- type: 'SOLID',- color: { r: 1, g: 1, b: 1, a: 0.85 },- weight: 2,- visible: true,- opacity: 1,- align: 'INSIDE'- }- ]- })-- const frame = store.graph.createNode('FRAME', pageId, {- name: 'Luminance mask stack visual',- x: 320,- y: 76,- width: 240,- height: 130,- cornerRadius: 18,- fills: [- { type: 'SOLID', color: { r: 0.08, g: 0.1, b: 0.18, a: 1 }, visible: true, opacity: 1 }- ]- })- store.graph.createNode('RECTANGLE', frame.id, {- name: 'Luminance mask gradient',- x: 24,- y: 20,- width: 192,- height: 90,- isMask: true,- maskType: 'LUMINANCE',- fills: [- {- type: 'GRADIENT_LINEAR',- color: { r: 0, g: 0, b: 0, a: 1 },- visible: true,- opacity: 1,- gradientStops: [- { color: { r: 0, g: 0, b: 0, a: 1 }, position: 0 },- { color: { r: 1, g: 1, b: 1, a: 1 }, position: 1 }- ],- gradientTransform: { m00: 1, m01: 0, m02: 0, m10: 0, m11: 1, m12: 0 }- }- ]- })- for (let index = 0; index < 5; index++) {- store.graph.createNode('RECTANGLE', frame.id, {- name: `Masked color stripe ${index + 1}`,- x: 24 + index * 38,- y: 20,- width: 34,- height: 90,- fills: [- {- type: 'SOLID',- color: [- { r: 0.96, g: 0.35, b: 0.35, a: 1 },- { r: 0.96, g: 0.64, b: 0.16, a: 1 },- { r: 0.08, g: 0.73, b: 0.73, a: 1 },- { r: 0.23, g: 0.51, b: 0.96, a: 1 },- { r: 0.58, g: 0.27, b: 0.95, a: 1 }- ][index],- visible: true,- opacity: 1- }- ]- })- }-- const multiMaskFrame = store.graph.createNode('FRAME', pageId, {- name: 'Consecutive mask stack visual',- x: 620,- y: 76,- width: 220,- height: 130,- cornerRadius: 18,- fills: [- { type: 'SOLID', color: { r: 0.08, g: 0.1, b: 0.18, a: 1 }, visible: true, opacity: 1 }- ]- })- store.graph.createNode('ELLIPSE', multiMaskFrame.id, {- name: 'First combined mask',- x: 18,- y: 16,- width: 112,- height: 98,- isMask: true,- fills: [{ type: 'SOLID', color: { r: 1, g: 1, b: 1, a: 1 }, visible: true, opacity: 1 }]- })- store.graph.createNode('ELLIPSE', multiMaskFrame.id, {- name: 'Second combined mask',- x: 90,- y: 16,- width: 112,- height: 98,- isMask: true,- fills: [{ type: 'SOLID', color: { r: 1, g: 1, b: 1, a: 1 }, visible: true, opacity: 1 }]- })- store.graph.createNode('RECTANGLE', multiMaskFrame.id, {- name: 'Consecutively masked content',- x: 18,- y: 16,- width: 184,- height: 98,- fills: [- {- type: 'GRADIENT_LINEAR',- color: { r: 0, g: 0, b: 0, a: 1 },- visible: true,- opacity: 1,- gradientStops: [- { color: { r: 0.96, g: 0.35, b: 0.35, a: 1 }, position: 0 },- { color: { r: 0.08, g: 0.73, b: 0.73, a: 1 }, position: 0.5 },- { color: { r: 0.58, g: 0.27, b: 0.95, a: 1 }, position: 1 }- ],- gradientTransform: { m00: 1, m01: 0, m02: 0, m10: 0, m11: 1, m12: 0 }- }- ]- })-- store.clearSelection()- store.requestRender()- })- await editor.canvas.waitForRender()+ await scenes.show('luminance-masks')await expectCanvas('luminance-masks-and-transformed-tile-fills')})++test('a mask applies its opacity and blur to what it masks', async () => {+ await scenes.show('mask-effects')+ await expectCanvas('mask-opacity-and-blur')+})diff --git a/tests/e2e/canvas/pattern-mask-visual.spec.ts-snapshots/mask-opacity-and-blur-openpencil-darwin.png b/tests/e2e/canvas/pattern-mask-visual.spec.ts-snapshots/mask-opacity-and-blur-openpencil-darwin.pngnew file mode 100644index 000000000..0667652eaBinary files /dev/null and b/tests/e2e/canvas/pattern-mask-visual.spec.ts-snapshots/mask-opacity-and-blur-openpencil-darwin.png differdiff --git a/tests/engine/render/canvas/masks.test.ts b/tests/engine/render/canvas/masks.test.tsindex 1e93e9bac..65de83f77 100644--- a/tests/engine/render/canvas/masks.test.ts+++ b/tests/engine/render/canvas/masks.test.ts@@ -144,7 +144,8 @@ describe('canvas masks', () => {renderNode(renderer, asCanvas(canvas), graph, frame.id, {})- expect(rendered).toEqual([frame.id, clipped.id, mask.id])+ // The mask draws once for its luma and once more to scale that by its alpha, as Figma does.+ expect(rendered).toEqual([frame.id, clipped.id, mask.id, mask.id])expect(renderer.ck.ColorFilter.MakeLuma).toHaveBeenCalled()expect(renderer.effectLayerPaint.setColorFilter).toHaveBeenCalledWith(expect.any(Object))expect(renderer.effectLayerPaint.setColorFilter).toHaveBeenLastCalledWith(null)diff --git a/tests/helpers/canvas/masks/driver.ts b/tests/helpers/canvas/masks/driver.tsnew file mode 100644index 000000000..7e687de53--- /dev/null+++ b/tests/helpers/canvas/masks/driver.ts@@ -0,0 +1,22 @@+import type { Page } from '@playwright/test'++import type * as MaskScenes from '#tests/helpers/canvas/masks/scene'++/** Builds a mask scene on the open page and leaves it unselected for a canvas snapshot. */+export function maskSceneDriver(page: () => Page) {+ return {+ show(name: MaskScenes.MaskSceneName) {+ return page().evaluate(async (name) => {+ const store = window.openPencil?.getStore?.()+ if (!store) throw new Error('OpenPencil store not initialized')+ const sceneURL = '/tests/helpers/canvas/masks/scene.ts'+ const scenes: typeof MaskScenes = await import(sceneURL)+ await scenes.MASK_SCENES[name](store.graph, store.state.currentPageId, (bytes) =>+ store.storeImage(bytes)+ )+ store.clearSelection()+ store.requestRender()+ }, name)+ }+ }+}diff --git a/tests/helpers/canvas/masks/scene.ts b/tests/helpers/canvas/masks/scene.tsnew file mode 100644index 000000000..421eb9061--- /dev/null+++ b/tests/helpers/canvas/masks/scene.ts@@ -0,0 +1,276 @@+import type { SceneGraph } from '@open-pencil/scene-graph'++/** Pattern fills drawn from a hidden source node. */+export function createPatternFillScene(graph: SceneGraph, pageId: string): void {+ const source = graph.createNode('ELLIPSE', pageId, {+ name: 'Pattern source dot',+ x: -1000,+ y: -1000,+ width: 18,+ height: 18,+ visible: false,+ fills: [+ { type: 'SOLID', color: { r: 0.96, g: 0.35, b: 0.12, a: 1 }, visible: true, opacity: 1 }+ ]+ })++ graph.createNode('RECTANGLE', pageId, {+ name: 'Pattern fill visual',+ x: 84,+ y: 80,+ width: 240,+ height: 150,+ cornerRadius: 18,+ fills: [+ {+ type: 'PATTERN',+ sourceNodeId: source.id,+ patternTileType: 'HORIZONTAL_HEXAGONAL',+ scale: 1.25,+ patternSpacing: { x: 0.45, y: 0.35 },+ horizontalAlignment: 'CENTER',+ verticalAlignment: 'CENTER',+ color: { r: 0.96, g: 0.35, b: 0.12, a: 1 },+ visible: true,+ opacity: 1+ }+ ],+ strokes: [+ {+ type: 'SOLID',+ color: { r: 0.08, g: 0.1, b: 0.18, a: 0.18 },+ weight: 2,+ visible: true,+ opacity: 1,+ align: 'INSIDE'+ }+ ]+ })+}++/** An image tile fill beside a luminance mask stack and two consecutive masks. */+export async function createLuminanceMaskScene(+ graph: SceneGraph,+ pageId: string,+ storeImage: (bytes: Uint8Array) => string+): Promise<void> {+ const imageCanvas = document.createElement('canvas')+ imageCanvas.width = 32+ imageCanvas.height = 32+ const ctx = imageCanvas.getContext('2d')+ if (!ctx) throw new Error('Cannot create tile fixture canvas')+ ctx.fillStyle = '#111827'+ ctx.fillRect(0, 0, 32, 32)+ ctx.fillStyle = '#f97316'+ ctx.fillRect(0, 0, 16, 16)+ ctx.fillStyle = '#38bdf8'+ ctx.fillRect(16, 16, 16, 16)+ ctx.fillStyle = '#facc15'+ ctx.fillRect(20, 4, 8, 8)+ const blob = await new Promise<Blob>((resolve, reject) => {+ imageCanvas.toBlob((result) => {+ if (result) {+ resolve(result)+ return+ }+ reject(new Error('Failed to encode tile fixture'))+ }, 'image/png')+ })+ const imageHash = storeImage(new Uint8Array(await blob.arrayBuffer()))++ graph.createNode('RECTANGLE', pageId, {+ name: 'Transformed tile fill visual',+ x: 80,+ y: 76,+ width: 180,+ height: 130,+ cornerRadius: 18,+ fills: [+ {+ type: 'IMAGE',+ color: { r: 0, g: 0, b: 0, a: 1 },+ visible: true,+ opacity: 1,+ imageHash,+ imageScaleMode: 'TILE',+ imageTransform: { m00: 3, m01: 0, m02: 0, m10: 0, m11: 3, m12: 0 }+ }+ ],+ strokes: [+ {+ type: 'SOLID',+ color: { r: 1, g: 1, b: 1, a: 0.85 },+ weight: 2,+ visible: true,+ opacity: 1,+ align: 'INSIDE'+ }+ ]+ })++ const frame = graph.createNode('FRAME', pageId, {+ name: 'Luminance mask stack visual',+ x: 320,+ y: 76,+ width: 240,+ height: 130,+ cornerRadius: 18,+ fills: [{ type: 'SOLID', color: { r: 0.08, g: 0.1, b: 0.18, a: 1 }, visible: true, opacity: 1 }]+ })+ graph.createNode('RECTANGLE', frame.id, {+ name: 'Luminance mask gradient',+ x: 24,+ y: 20,+ width: 192,+ height: 90,+ isMask: true,+ maskType: 'LUMINANCE',+ fills: [+ {+ type: 'GRADIENT_LINEAR',+ color: { r: 0, g: 0, b: 0, a: 1 },+ visible: true,+ opacity: 1,+ gradientStops: [+ { color: { r: 0, g: 0, b: 0, a: 1 }, position: 0 },+ { color: { r: 1, g: 1, b: 1, a: 1 }, position: 1 }+ ],+ gradientTransform: { m00: 1, m01: 0, m02: 0, m10: 0, m11: 1, m12: 0 }+ }+ ]+ })+ for (let index = 0; index < 5; index++) {+ graph.createNode('RECTANGLE', frame.id, {+ name: `Masked color stripe ${index + 1}`,+ x: 24 + index * 38,+ y: 20,+ width: 34,+ height: 90,+ fills: [+ {+ type: 'SOLID',+ color: [+ { r: 0.96, g: 0.35, b: 0.35, a: 1 },+ { r: 0.96, g: 0.64, b: 0.16, a: 1 },+ { r: 0.08, g: 0.73, b: 0.73, a: 1 },+ { r: 0.23, g: 0.51, b: 0.96, a: 1 },+ { r: 0.58, g: 0.27, b: 0.95, a: 1 }+ ][index],+ visible: true,+ opacity: 1+ }+ ]+ })+ }++ const multiMaskFrame = graph.createNode('FRAME', pageId, {+ name: 'Consecutive mask stack visual',+ x: 620,+ y: 76,+ width: 220,+ height: 130,+ cornerRadius: 18,+ fills: [{ type: 'SOLID', color: { r: 0.08, g: 0.1, b: 0.18, a: 1 }, visible: true, opacity: 1 }]+ })+ graph.createNode('ELLIPSE', multiMaskFrame.id, {+ name: 'First combined mask',+ x: 18,+ y: 16,+ width: 112,+ height: 98,+ isMask: true,+ fills: [{ type: 'SOLID', color: { r: 1, g: 1, b: 1, a: 1 }, visible: true, opacity: 1 }]+ })+ graph.createNode('ELLIPSE', multiMaskFrame.id, {+ name: 'Second combined mask',+ x: 90,+ y: 16,+ width: 112,+ height: 98,+ isMask: true,+ fills: [{ type: 'SOLID', color: { r: 1, g: 1, b: 1, a: 1 }, visible: true, opacity: 1 }]+ })+ graph.createNode('RECTANGLE', multiMaskFrame.id, {+ name: 'Consecutively masked content',+ x: 18,+ y: 16,+ width: 184,+ height: 98,+ fills: [+ {+ type: 'GRADIENT_LINEAR',+ color: { r: 0, g: 0, b: 0, a: 1 },+ visible: true,+ opacity: 1,+ gradientStops: [+ { color: { r: 0.96, g: 0.35, b: 0.35, a: 1 }, position: 0 },+ { color: { r: 0.08, g: 0.73, b: 0.73, a: 1 }, position: 0.5 },+ { color: { r: 0.58, g: 0.27, b: 0.95, a: 1 }, position: 1 }+ ],+ gradientTransform: { m00: 1, m01: 0, m02: 0, m10: 0, m11: 1, m12: 0 }+ }+ ]+ })+}++/** Masks with opacity, a translucent outline fill, luminance at half opacity, and a layer blur. */+export function createMaskEffectsScene(graph: SceneGraph, pageId: string): void {+ const solid = (r: number, g: number, b: number, opacity = 1) => ({+ type: 'SOLID' as const,+ color: { r, g, b, a: 1 },+ opacity,+ visible: true+ })+ const variants = [+ { maskType: 'ALPHA' as const, mask: { opacity: 0.5 } },+ { maskType: 'VECTOR' as const, mask: { fills: [solid(0, 0, 0, 0.3)] } },+ { maskType: 'LUMINANCE' as const, mask: { opacity: 0.5 } },+ {+ maskType: 'ALPHA' as const,+ mask: {+ effects: [+ {+ type: 'LAYER_BLUR' as const,+ radius: 12,+ spread: 0,+ offset: { x: 0, y: 0 },+ color: { r: 0, g: 0, b: 0, a: 1 },+ visible: true+ }+ ]+ }+ }+ ]+ for (const [index, { maskType, mask }] of variants.entries()) {+ const group = graph.createNode('GROUP', pageId, {+ name: `${maskType} mask`,+ x: 80 + index * 130,+ y: 100,+ width: 110,+ height: 110+ })+ graph.createNode('ELLIPSE', group.id, {+ x: 10,+ y: 10,+ width: 90,+ height: 90,+ fills: [maskType === 'LUMINANCE' ? solid(1, 1, 1) : solid(0, 0, 0)],+ isMask: true,+ maskType,+ ...mask+ })+ graph.createNode('RECTANGLE', group.id, {+ width: 110,+ height: 110,+ fills: [solid(0.31, 0.27, 0.9)]+ })+ }+}++export const MASK_SCENES = {+ 'pattern-fills': createPatternFillScene,+ 'luminance-masks': createLuminanceMaskScene,+ 'mask-effects': createMaskEffectsScene+}++export type MaskSceneName = keyof typeof MASK_SCENES