Skip to content

AI-native design editor. Open-source Figma alternative.

feat: add plus darker and plus lighter blend modes and blend strokes by their paint's mode (#1611)

Andrew Avsenin884e228ceada
diff --git a/changes/1611/added.md b/changes/1611/added.md
new file mode 100644
index 000000000..8e9ea465e
--- /dev/null
+++ b/changes/1611/added.md
@@ -0,0 +1 @@
+- Plus darker and plus lighter blend modes for layers, fills, strokes and effects: drawn on the canvas, kept through `.fig` import and export, exported to SVG, and available in the blend mode menu, the plugin API and design JSX.
diff --git a/changes/1611/fixed.md b/changes/1611/fixed.md
new file mode 100644
index 000000000..817730d58
--- /dev/null
+++ b/changes/1611/fixed.md
@@ -0,0 +1 @@
+- Strokes blend with what is under them by their paint's blend mode.
diff --git a/packages/core/src/canvas/blend.ts b/packages/core/src/canvas/blend.ts
index 0c7c7dbdd..fb31e4cf9 100644
--- a/packages/core/src/canvas/blend.ts
+++ b/packages/core/src/canvas/blend.ts
@@ -1,8 +1,31 @@
-import type { BlendMode as SkBlendMode, CanvasKit } from 'canvaskit-wasm'
+import type { Blender, BlendMode as SkBlendMode, CanvasKit, Paint } from 'canvaskit-wasm'
import type { BlendMode } from '@open-pencil/scene-graph'
-export function figmaBlendModeToSkia(ck: CanvasKit, mode?: BlendMode): SkBlendMode {
+import type { SkiaRenderer } from './renderer'
+
+type LinearBlendMode = 'LINEAR_BURN' | 'LINEAR_DODGE'
+
+/**
+ * Figma's plus darker and plus lighter, in premultiplied sRGB with source-over coverage: the sum
+ * less the overlap clamped at zero, and the sum clamped at the coverage (live-measured).
+ */
+const LINEAR_BLEND_COLORS: Record<LinearBlendMode, string> = {
+ LINEAR_BURN: 'max(src.rgb + dst.rgb - src.a * dst.a, half3(0))',
+ LINEAR_DODGE: 'min(src.rgb + dst.rgb, half3(alpha))'
+}
+
+function linearBlendSource(mode: LinearBlendMode): string {
+ return `half4 main(half4 src, half4 dst) {
+ half alpha = src.a + dst.a * (1 - src.a);
+ return half4(${LINEAR_BLEND_COLORS[mode]}, alpha);
+}`
+}
+
+export function figmaBlendModeToSkia(
+ ck: CanvasKit,
+ mode?: Exclude<BlendMode, LinearBlendMode>
+): SkBlendMode {
switch (mode) {
case 'DARKEN':
return ck.BlendMode.Darken
@@ -39,6 +62,31 @@ export function figmaBlendModeToSkia(ck: CanvasKit, mode?: BlendMode): SkBlendMo
}
}
+export function setPaintBlendMode(r: SkiaRenderer, paint: Paint, mode?: BlendMode): void {
+ if (mode === 'LINEAR_BURN' || mode === 'LINEAR_DODGE') {
+ paint.setBlender(linearBlender(r, mode))
+ return
+ }
+ paint.setBlendMode(figmaBlendModeToSkia(r.ck, mode))
+}
+
+/** Skia has no blend mode for either: they are runtime blenders, compiled once per renderer. */
+function linearBlender(r: SkiaRenderer, mode: LinearBlendMode): Blender {
+ if (mode === 'LINEAR_BURN') return (r.linearBurnBlender ??= compileLinearBlender(r.ck, mode))
+ return (r.linearDodgeBlender ??= compileLinearBlender(r.ck, mode))
+}
+
+function compileLinearBlender(ck: CanvasKit, mode: LinearBlendMode): Blender {
+ let error = ''
+ const effect = ck.RuntimeEffect.MakeForBlender(linearBlendSource(mode), (message) => {
+ error = message
+ })
+ if (!effect) throw new Error(`Cannot compile ${mode} blender: ${error}`)
+ const blender = effect.makeBlender([])
+ effect.delete()
+ return blender
+}
+
export function needsIsolatedBlendLayer(mode?: BlendMode): boolean {
return mode !== undefined && mode !== 'NORMAL' && mode !== 'PASS_THROUGH'
}
diff --git a/packages/core/src/canvas/fills.ts b/packages/core/src/canvas/fills.ts
index c39028628..f204ed681 100644
--- a/packages/core/src/canvas/fills.ts
+++ b/packages/core/src/canvas/fills.ts
@@ -5,7 +5,7 @@ import { invertGradientTransform } from '@open-pencil/scene-graph/gradient'
import Matrix from '@open-pencil/scene-graph/matrix'
import type { Color, Rect, Vector } from '@open-pencil/scene-graph/primitives'
-import { figmaBlendModeToSkia } from './blend'
+import { setPaintBlendMode } from './blend'
import { makeDiamondGradient } from './gradients/diamond'
import { previewEdge } from './images/previews'
import type { SkiaRenderer } from './renderer'
@@ -33,7 +33,7 @@ export function paintFills(
: r.applyFill(fill, node, graph, fillIndex)
if (!applied) continue
r.fillPaint.setAlphaf(fill.opacity)
- r.fillPaint.setBlendMode(figmaBlendModeToSkia(r.ck, fill.blendMode))
+ setPaintBlendMode(r, r.fillPaint, fill.blendMode)
draw(fill)
r.fillPaint.setShader(null)
r.fillPaint.setBlendMode(r.ck.BlendMode.SrcOver)
diff --git a/packages/core/src/canvas/renderer.ts b/packages/core/src/canvas/renderer.ts
index 9552a3cca..3f945347d 100644
--- a/packages/core/src/canvas/renderer.ts
+++ b/packages/core/src/canvas/renderer.ts
@@ -53,6 +53,7 @@ import type {
CanvasKit,
Surface,
Canvas,
+ Blender,
Paint,
Font,
FontMgr,
@@ -102,6 +103,8 @@ export class SkiaRenderer {
declare fillPaint: Paint
diamondGradientEffect: RuntimeEffect | null = null
pixelGridEffect: RuntimeEffect | null = null
+ linearBurnBlender: Blender | null = null
+ linearDodgeBlender: Blender | null = null
declare strokePaint: Paint
declare selectionPaint: Paint
declare parentOutlinePaint: Paint
diff --git a/packages/core/src/canvas/renderer/lifecycle.ts b/packages/core/src/canvas/renderer/lifecycle.ts
index 77ec48c50..e204052f9 100644
--- a/packages/core/src/canvas/renderer/lifecycle.ts
+++ b/packages/core/src/canvas/renderer/lifecycle.ts
@@ -25,6 +25,17 @@ export function releaseLiveImages(r: Pick<SkiaRenderer, 'liveImages' | 'surface'
r.liveImages.clear()
}
+function releaseRuntimeEffects(r: SkiaRenderer): void {
+ r.diamondGradientEffect?.delete()
+ r.diamondGradientEffect = null
+ r.pixelGridEffect?.delete()
+ r.pixelGridEffect = null
+ r.linearBurnBlender?.delete()
+ r.linearBurnBlender = null
+ r.linearDodgeBlender?.delete()
+ r.linearDodgeBlender = null
+}
+
export function destroyRenderer(r: SkiaRenderer): void {
if (r.destroyed) return
r.destroyed = true
@@ -36,10 +47,7 @@ export function destroyRenderer(r: SkiaRenderer): void {
releaseLiveImages(r)
disposePathCaches(r)
r.fillPaint.delete()
- r.diamondGradientEffect?.delete()
- r.diamondGradientEffect = null
- r.pixelGridEffect?.delete()
- r.pixelGridEffect = null
+ releaseRuntimeEffects(r)
r.strokePaint.delete()
r.selectionPaint.delete()
r.parentOutlinePaint.delete()
diff --git a/packages/core/src/canvas/scene.ts b/packages/core/src/canvas/scene.ts
index 1c14de2b4..7bb7613bb 100644
--- a/packages/core/src/canvas/scene.ts
+++ b/packages/core/src/canvas/scene.ts
@@ -24,7 +24,7 @@ import {
} from '#core/vector'
import { isOpenVectorNetwork } from '#core/vector/connectivity'
-import { figmaBlendModeToSkia, needsIsolatedBlendLayer } from './blend'
+import { needsIsolatedBlendLayer, setPaintBlendMode } from './blend'
import { renderBooleanOperation } from './boolean'
import { blurSigma } from './effects'
import { drawVectorMultiStyleFills, paintFills } from './fills'
@@ -47,7 +47,8 @@ import {
drawStyledRRectStroke,
getStrokeCapEntity,
getStrokeJoinEntity,
- normalizeDashPattern
+ normalizeDashPattern,
+ setStrokeBlendMode
} from './strokes'
import { drawLineStroke } from './strokes/line'
import { drawOutlinedDashes } from './strokes/outlined-dashes'
@@ -357,7 +358,7 @@ export function renderNode(
if (needsNodeLayer) {
const layerBounds = nodeIsolationLayerBounds(r, graph, node, overlays.rotationPreview)
r.opacityPaint.setAlphaf(node.opacity)
- r.opacityPaint.setBlendMode(figmaBlendModeToSkia(r.ck, node.blendMode))
+ setPaintBlendMode(r, r.opacityPaint, node.blendMode)
canvas.saveLayer(r.opacityPaint, layerBounds)
}
@@ -434,11 +435,13 @@ function forVisibleStrokes(
const stroke = node.strokes[index]
if (!stroke.visible) continue
const draws = applyStrokeShader(r, stroke, index, node, graph)
+ setStrokeBlendMode(r, stroke.blendMode)
try {
if (draws) draw(stroke, r.resolveStrokeColor(stroke, index, node, graph))
} finally {
r.strokePaint.setShader(null)
r.fillPaint.setShader(null)
+ setStrokeBlendMode(r, 'NORMAL')
}
}
}
diff --git a/packages/core/src/canvas/shadows.ts b/packages/core/src/canvas/shadows.ts
index f97be877d..0fa6f6761 100644
--- a/packages/core/src/canvas/shadows.ts
+++ b/packages/core/src/canvas/shadows.ts
@@ -1,11 +1,11 @@
-import type { BlendMode, Canvas, ImageFilter } from 'canvaskit-wasm'
+import type { Canvas, ImageFilter } from 'canvaskit-wasm'
-import type { Effect, SceneGraph, SceneNode } from '@open-pencil/scene-graph'
+import type { BlendMode, Effect, SceneGraph, SceneNode } from '@open-pencil/scene-graph'
import Matrix from '@open-pencil/scene-graph/matrix'
import { nodeOrientationMatrix } from '#core/geometry'
-import { figmaBlendModeToSkia, needsIsolatedBlendLayer } from './blend'
+import { needsIsolatedBlendLayer, setPaintBlendMode } from './blend'
import { makeBooleanOperationPath } from './boolean'
import { blurSigma, renderNoiseEffects } from './effects'
import type { SkiaRenderer } from './renderer'
@@ -101,7 +101,7 @@ function drawSilhouetteDropShadow(
effect: Effect,
spread: number,
bounds: Float32Array,
- blendMode: BlendMode,
+ blendMode: BlendMode | undefined,
draw: () => void
): void {
const ck = r.ck
@@ -120,7 +120,7 @@ function drawSilhouetteDropShadow(
: r.getCachedDropShadow(effect.offset.x, effect.offset.y, sigma, color)
const paint = new ck.Paint()
paint.setImageFilter(filter)
- paint.setBlendMode(blendMode)
+ setPaintBlendMode(r, paint, blendMode)
canvas.saveLayer(paint, bounds)
try {
draw()
@@ -156,7 +156,7 @@ function drawOwnShapeDropShadow(
node: SceneNode,
effect: Effect,
spread: number,
- blendMode: BlendMode,
+ blendMode: BlendMode | undefined,
knockout: boolean
): boolean {
const outline = regularStrokeOutline(node, spread)
@@ -222,7 +222,7 @@ function renderDropShadow(
): void {
if (!includeChildren && !paintsCastShadow(node)) return
const spread = shadowSpread(node, effect)
- const blendMode = figmaBlendModeToSkia(r.ck, effect.blendMode)
+ const blendMode = effect.blendMode
const knockout =
effect.showShadowBehindNode === false && !paintsOverKnockout(graph, node, includeChildren)
const children = includeChildren
@@ -246,7 +246,7 @@ function renderDropShadow(
const bounds = shadowLayerBounds(r, graph, node, effect, spread, includeChildren)
const isolation = knockout ? new r.ck.Paint() : null
if (isolation) {
- isolation.setBlendMode(blendMode)
+ setPaintBlendMode(r, isolation, blendMode)
canvas.saveLayer(isolation, bounds)
}
try {
@@ -256,7 +256,7 @@ function renderDropShadow(
effect,
spread,
bounds,
- isolation ? r.ck.BlendMode.SrcOver : blendMode,
+ isolation ? 'NORMAL' : blendMode,
() => drawSilhouette(r, canvas, graph, node, 'cast', includeChildren)
)
if (knockout) {
@@ -289,7 +289,7 @@ function drawSilhouetteInnerShadow(
let solidBlackFilter: ReturnType<typeof ck.ColorFilter.MakeBlend> | null = null
try {
- r.effectLayerPaint.setBlendMode(figmaBlendModeToSkia(ck, effect.blendMode))
+ setPaintBlendMode(r, r.effectLayerPaint, effect.blendMode)
canvas.saveLayer(r.effectLayerPaint, bounds)
restoreCount++
r.effectLayerPaint.setBlendMode(ck.BlendMode.SrcOver)
diff --git a/packages/core/src/canvas/shadows/shape.ts b/packages/core/src/canvas/shadows/shape.ts
index 966eb7eb3..56a684c15 100644
--- a/packages/core/src/canvas/shadows/shape.ts
+++ b/packages/core/src/canvas/shadows/shape.ts
@@ -1,8 +1,8 @@
-import type { BlendMode, Canvas, Path } from 'canvaskit-wasm'
+import type { Canvas, Path } from 'canvaskit-wasm'
-import type { Effect, SceneNode, Stroke } from '@open-pencil/scene-graph'
+import type { BlendMode, Effect, SceneNode, Stroke } from '@open-pencil/scene-graph'
-import { figmaBlendModeToSkia } from '#core/canvas/blend'
+import { setPaintBlendMode } from '#core/canvas/blend'
import { blurSigma } from '#core/canvas/effects'
import type { SkiaRenderer } from '#core/canvas/renderer'
import { drawOutline, makeNodeShapePath, nodeHasRadius, withNodeOutline } from '#core/canvas/shapes'
@@ -125,13 +125,13 @@ function drawMaskShadow(
r: SkiaRenderer,
canvas: Canvas,
effect: Effect,
- blendMode: BlendMode,
+ blendMode: BlendMode | undefined,
draw: () => void
): void {
r.auxFill.setColor(r.color4f(effect.color.r, effect.color.g, effect.color.b, effect.color.a))
r.auxFill.setMaskFilter(r.getCachedMaskBlur(blurSigma(effect.radius)))
r.auxFill.setImageFilter(null)
- r.auxFill.setBlendMode(blendMode)
+ setPaintBlendMode(r, r.auxFill, blendMode)
canvas.save()
try {
canvas.translate(effect.offset.x, effect.offset.y)
@@ -150,7 +150,7 @@ export function drawShapeDropShadow(
node: SceneNode,
effect: Effect,
spread: number,
- blendMode: BlendMode
+ blendMode: BlendMode | undefined
): void {
drawMaskShadow(r, canvas, effect, blendMode, () =>
withNodeOutline(r, node, (outline) => drawOutline(canvas, outline, r.auxFill), spread)
@@ -170,7 +170,7 @@ export function drawOutlineDropShadow(
effect: Effect,
outline: StrokeOutline,
spread: number,
- blendMode: BlendMode
+ blendMode: BlendMode | undefined
): void {
drawMaskShadow(r, canvas, effect, blendMode, () => {
if (outline.even) {
@@ -188,7 +188,7 @@ export function drawRingDropShadow(
effect: Effect,
outline: StrokeOutline,
spread: number,
- blendMode: BlendMode
+ blendMode: BlendMode | undefined
): void {
const builder = new r.ck.PathBuilder()
if (outline.even) {
@@ -275,7 +275,7 @@ export function drawShapeInnerShadow(
canvas.drawPath(shadowPath, r.auxFill)
r.auxFill.setBlendMode(r.ck.BlendMode.Plus)
} else {
- r.auxFill.setBlendMode(figmaBlendModeToSkia(r.ck, effect.blendMode))
+ setPaintBlendMode(r, r.auxFill, effect.blendMode)
}
r.clipNodeShape(canvas, node)
canvas.drawPath(shadowPath, r.auxFill)
diff --git a/packages/core/src/canvas/strokes.ts b/packages/core/src/canvas/strokes.ts
index cd94fe3f7..58da96bdb 100644
--- a/packages/core/src/canvas/strokes.ts
+++ b/packages/core/src/canvas/strokes.ts
@@ -1,6 +1,6 @@
import type { Canvas, EmbindEnumEntity, Paint, Path } from 'canvaskit-wasm'
-import type { SceneGraph, SceneNode, Stroke } from '@open-pencil/scene-graph'
+import type { BlendMode, SceneGraph, SceneNode, Stroke } from '@open-pencil/scene-graph'
import type { ArrowEndpoint, ArrowWing } from '@open-pencil/scene-graph/arrow-caps'
import {
arrowLinesSegments,
@@ -11,6 +11,7 @@ import {
} from '@open-pencil/scene-graph/arrow-caps'
import type { Color, Vector } from '@open-pencil/scene-graph/primitives'
+import { setPaintBlendMode } from './blend'
import { applyGradientFill, applyImageFill } from './fills'
import type { SkiaRenderer } from './renderer'
import {
@@ -287,6 +288,11 @@ export function applyStrokeShader(
return true
}
+export function setStrokeBlendMode(r: SkiaRenderer, mode: BlendMode | undefined): void {
+ setPaintBlendMode(r, r.strokePaint, mode)
+ setPaintBlendMode(r, r.fillPaint, mode)
+}
+
/** Leaves any shader in place: a shaded stroke's color is unused, but its alpha still applies. */
export function configureStrokePaint(
r: SkiaRenderer,
diff --git a/packages/core/src/figma-api/compatibility.ts b/packages/core/src/figma-api/compatibility.ts
index 91a9a4d01..c8d08104f 100644
--- a/packages/core/src/figma-api/compatibility.ts
+++ b/packages/core/src/figma-api/compatibility.ts
@@ -128,19 +128,12 @@ const _effectShapeMatch: EffectShapeMatch = true
// `Paint` here is Figma's plugin-typings union. `fills`, `strokes`, and `backgrounds` share one
// paint type: every paint they read is one of Figma's, apart from the noise and custom paints
-// OpenPencil models and Figma has no type for, and they take every paint Figma's types allow but
-// for the linear burn and dodge blend modes, which OpenPencil does not model.
+// OpenPencil models and Figma has no type for, and they take every paint Figma's types allow.
type ReadPaint = Exclude<Exclude<FigmaNodeProxy['fills'], symbol>[number], OpenPencilPaint>
-type WithoutLinearBlends<T> = T extends unknown
- ? Omit<T, 'blendMode'> & { blendMode?: Exclude<BlendMode, 'LINEAR_BURN' | 'LINEAR_DODGE'> }
- : never
type PaintShapeMatch = Expect<Extends<ReadPaint, Paint>>
const _paintShapeMatch: PaintShapeMatch = true
type PaintArgumentMatch = Expect<
- Extends<
- WithoutLinearBlends<SolidPaint | GradientPaint | ImagePaint | VideoPaint | PatternPaint>,
- ReadPaint
- >
+ Extends<SolidPaint | GradientPaint | ImagePaint | VideoPaint | PatternPaint, ReadPaint>
>
const _paintArgumentMatch: PaintArgumentMatch = true
diff --git a/packages/core/src/figma-api/effects.ts b/packages/core/src/figma-api/effects.ts
index 9efa0d9e5..70558d857 100644
--- a/packages/core/src/figma-api/effects.ts
+++ b/packages/core/src/figma-api/effects.ts
@@ -8,9 +8,11 @@ const BLEND_MODE_KEYS = {
NORMAL: true,
DARKEN: true,
MULTIPLY: true,
+ LINEAR_BURN: true,
COLOR_BURN: true,
LIGHTEN: true,
SCREEN: true,
+ LINEAR_DODGE: true,
COLOR_DODGE: true,
OVERLAY: true,
SOFT_LIGHT: true,
diff --git a/packages/core/src/io/formats/svg/defs.ts b/packages/core/src/io/formats/svg/defs.ts
index 8f1db25c7..7a98792dc 100644
--- a/packages/core/src/io/formats/svg/defs.ts
+++ b/packages/core/src/io/formats/svg/defs.ts
@@ -316,7 +316,9 @@ export const SVG_BLEND_MODE: Record<string, string> = {
MULTIPLY: 'multiply',
COLOR_BURN: 'color-burn',
LIGHTEN: 'lighten',
+ LINEAR_BURN: 'plus-darker',
SCREEN: 'screen',
+ LINEAR_DODGE: 'plus-lighter',
COLOR_DODGE: 'color-dodge',
OVERLAY: 'overlay',
SOFT_LIGHT: 'soft-light',
diff --git a/packages/core/src/tools/modify/state.ts b/packages/core/src/tools/modify/state.ts
index 816c8e912..432d900f7 100644
--- a/packages/core/src/tools/modify/state.ts
+++ b/packages/core/src/tools/modify/state.ts
@@ -31,9 +31,11 @@ export const setBlend = defineTool({
'NORMAL',
'DARKEN',
'MULTIPLY',
+ 'LINEAR_BURN',
'COLOR_BURN',
'LIGHTEN',
'SCREEN',
+ 'LINEAR_DODGE',
'COLOR_DODGE',
'OVERLAY',
'SOFT_LIGHT',
diff --git a/packages/core/tests/canvas/blend.test.ts b/packages/core/tests/canvas/blend.test.ts
new file mode 100644
index 000000000..09a8a24b7
--- /dev/null
+++ b/packages/core/tests/canvas/blend.test.ts
@@ -0,0 +1,165 @@
+import { afterAll, describe, expect, test } from 'bun:test'
+
+import { expectDefined } from '#core-tests/helpers/assert'
+
+import { SkiaRenderer } from '@open-pencil/core/canvas'
+import { initCanvasKit } from '@open-pencil/core/io/formats/raster'
+import { SceneGraph, type BlendMode, type Fill } from '@open-pencil/scene-graph'
+
+const SIZE = 40
+
+const ck = await initCanvasKit()
+const renderer = new SkiaRenderer(ck, expectDefined(ck.MakeSurface(SIZE, SIZE), 'surface'))
+afterAll(() => renderer.destroy())
+
+const BACKDROP = { r: 0.6, g: 0.4, b: 0.2 }
+const SOURCE = { r: 0.2, g: 0.8, b: 0.7 }
+
+function solid(color: { r: number; g: number; b: number }, blendMode: BlendMode = 'NORMAL'): Fill {
+ return { type: 'SOLID', color: { ...color, a: 1 }, opacity: 1, visible: true, blendMode }
+}
+
+type Scene = (graph: SceneGraph, pageId: string) => void
+
+function backdrop(graph: SceneGraph, pageId: string) {
+ graph.createNode('RECTANGLE', pageId, { width: SIZE, height: SIZE, fills: [solid(BACKDROP)] })
+}
+
+function renderCenter(build: Scene, under: Scene = backdrop): number[] {
+ const graph = new SceneGraph()
+ const page = graph.getPages()[0]
+ under(graph, page.id)
+ build(graph, page.id)
+ renderer.pageId = page.id
+ const canvas = renderer.surface.getCanvas()
+ canvas.clear(ck.TRANSPARENT)
+ renderer.renderSceneToCanvas(canvas, graph, page.id)
+ renderer.surface.flush()
+ const image = renderer.surface.makeImageSnapshot()
+ try {
+ const pixels = expectDefined(
+ image.readPixels(SIZE / 2, SIZE / 2, {
+ width: 1,
+ height: 1,
+ colorType: ck.ColorType.RGBA_8888,
+ alphaType: ck.AlphaType.Unpremul,
+ colorSpace: ck.ColorSpace.SRGB
+ }),
+ 'pixels'
+ )
+ return Array.from(pixels.subarray(0, 4))
+ } finally {
+ image.delete()
+ }
+}
+
+function overlay(fills: Fill[], blendMode: BlendMode = 'PASS_THROUGH') {
+ return (graph: SceneGraph, pageId: string) => {
+ graph.createNode('RECTANGLE', pageId, { width: SIZE, height: SIZE, fills, blendMode })
+ }
+}
+
+function expectChannelsNear(actual: number[], expected: number[]) {
+ expected.forEach((channel, index) => expect(Math.abs(actual[index] - channel)).toBeLessThan(2))
+}
+
+// Live-measured in Figma: SOURCE over BACKDROP, opaque and at half opacity.
+const LINEAR_DODGE = [204, 255, 229]
+const LINEAR_BURN = [0, 51, 0]
+
+describe('linear blend modes, as Figma draws them', () => {
+ test('plus lighter adds a fill to what is under it', () => {
+ expectChannelsNear(renderCenter(overlay([solid(SOURCE, 'LINEAR_DODGE')])), LINEAR_DODGE)
+ })
+
+ test('plus darker adds a fill to what is under it, less white, and only that fill', () => {
+ expectChannelsNear(renderCenter(overlay([solid(SOURCE, 'LINEAR_BURN')])), LINEAR_BURN)
+ const burnedThenCovered = renderCenter(overlay([solid(SOURCE, 'LINEAR_BURN'), solid(SOURCE)]))
+ expectChannelsNear(burnedThenCovered, [51, 204, 179])
+ })
+
+ test('plus darker over nothing draws the fill as normal', () => {
+ const nothing: Scene = () => undefined
+ expectChannelsNear(
+ renderCenter(overlay([solid(SOURCE, 'LINEAR_BURN')]), nothing),
+ [51, 204, 179, 255]
+ )
+ })
+
+ test('a half transparent plus lighter fill mixes its sum with what is under it', () => {
+ const halfDodge = { ...solid(SOURCE, 'LINEAR_DODGE'), opacity: 0.5 }
+ expectChannelsNear(renderCenter(overlay([halfDodge])), [179, 204, 140, 255])
+ })
+
+ test('a half transparent plus darker fill takes the overlap off the sum, not off the blend', () => {
+ const halfBurn = { ...solid(SOURCE, 'LINEAR_BURN'), opacity: 0.5 }
+ expectChannelsNear(renderCenter(overlay([halfBurn])), [51, 76, 12, 255])
+ })
+
+ // Live-measured in Figma: a 60% grey backdrop at 50% opacity under (0.7, 0.2, 0.5).
+ test('blends over a half transparent backdrop as Figma does', () => {
+ const halfGrey: Scene = (graph, pageId) => {
+ const grey = { ...solid({ r: 0.6, g: 0.6, b: 0.6 }), opacity: 0.5 }
+ graph.createNode('RECTANGLE', pageId, { width: SIZE, height: SIZE, fills: [grey] })
+ }
+ const paint = { r: 0.7, g: 0.2, b: 0.5 }
+ expectChannelsNear(
+ renderCenter(overlay([solid(paint, 'LINEAR_BURN')]), halfGrey),
+ [127, 0, 77, 255]
+ )
+ const halfDodge = { ...solid(paint, 'LINEAR_DODGE'), opacity: 0.5 }
+ expectChannelsNear(renderCenter(overlay([halfDodge]), halfGrey), [220, 137, 187, 192])
+ const halfBurn = { ...solid(paint, 'LINEAR_BURN'), opacity: 0.5 }
+ expectChannelsNear(renderCenter(overlay([halfBurn]), halfGrey), [136, 51, 103, 191])
+ })
+
+ test('a half transparent fill over nothing stays half transparent', () => {
+ const nothing: Scene = () => undefined
+ for (const blendMode of ['LINEAR_DODGE', 'LINEAR_BURN'] as const) {
+ const half = { ...solid(SOURCE, blendMode), opacity: 0.5 }
+ expectChannelsNear(renderCenter(overlay([half]), nothing), [51, 204, 179, 128])
+ }
+ })
+
+ test('a half transparent fill over a half transparent backdrop covers three quarters', () => {
+ const halfBackdrop: Scene = (graph, pageId) => {
+ graph.createNode('RECTANGLE', pageId, {
+ width: SIZE,
+ height: SIZE,
+ fills: [{ ...solid(BACKDROP), opacity: 0.5 }]
+ })
+ }
+ for (const blendMode of ['LINEAR_DODGE', 'LINEAR_BURN'] as const) {
+ const half = { ...solid(SOURCE, blendMode), opacity: 0.5 }
+ expect(Math.abs(renderCenter(overlay([half]), halfBackdrop)[3] - 191)).toBeLessThan(2)
+ }
+ })
+
+ test('a drop shadow blends the same way as a fill', () => {
+ const castsOntoCenter: Scene = (graph, pageId) => {
+ graph.createNode('RECTANGLE', pageId, {
+ width: 10,
+ height: 10,
+ fills: [solid(BACKDROP)],
+ effects: [
+ {
+ type: 'DROP_SHADOW',
+ color: { ...SOURCE, a: 1 },
+ offset: { x: 15, y: 15 },
+ radius: 0,
+ spread: 0,
+ visible: true,
+ blendMode: 'LINEAR_BURN',
+ showShadowBehindNode: false
+ }
+ ]
+ })
+ }
+ expectChannelsNear(renderCenter(castsOntoCenter), LINEAR_BURN)
+ })
+
+ test('a layer blends the same way as a fill', () => {
+ expectChannelsNear(renderCenter(overlay([solid(SOURCE)], 'LINEAR_BURN')), LINEAR_BURN)
+ expectChannelsNear(renderCenter(overlay([solid(SOURCE)], 'LINEAR_DODGE')), LINEAR_DODGE)
+ })
+})
diff --git a/packages/core/tests/canvas/strokes/blend-mode.test.ts b/packages/core/tests/canvas/strokes/blend-mode.test.ts
new file mode 100644
index 000000000..17856871c
--- /dev/null
+++ b/packages/core/tests/canvas/strokes/blend-mode.test.ts
@@ -0,0 +1,157 @@
+import { afterAll, describe, expect, test } from 'bun:test'
+
+import { expectDefined } from '#core-tests/helpers/assert'
+
+import { SkiaRenderer } from '@open-pencil/core/canvas'
+import { initCanvasKit } from '@open-pencil/core/io/formats/raster'
+import { SceneGraph, type BlendMode, type SceneNode } from '@open-pencil/scene-graph'
+
+const SIZE = 120
+
+const ck = await initCanvasKit()
+const renderer = new SkiaRenderer(ck, expectDefined(ck.MakeSurface(SIZE, SIZE), 'surface'))
+afterAll(() => renderer.destroy())
+
+const RED_FILL = [
+ { type: 'SOLID' as const, color: { r: 1, g: 0, b: 0, a: 1 }, opacity: 1, visible: true }
+]
+
+function greenStroke(blendMode: BlendMode) {
+ return {
+ type: 'SOLID' as const,
+ color: { r: 0, g: 1, b: 0, a: 1 },
+ opacity: 1,
+ visible: true,
+ weight: 10,
+ align: 'INSIDE' as const,
+ blendMode
+ }
+}
+
+function squareVector(): SceneNode['vectorNetwork'] {
+ return {
+ vertices: [
+ { x: 0, y: 0 },
+ { x: 40, y: 0 },
+ { x: 40, y: 40 },
+ { x: 0, y: 40 }
+ ],
+ segments: [0, 1, 2, 3].map((start) => ({
+ start,
+ end: (start + 1) % 4,
+ tangentStart: { x: 0, y: 0 },
+ tangentEnd: { x: 0, y: 0 }
+ })),
+ regions: [{ windingRule: 'NONZERO', loops: [[0, 1, 2, 3]] }]
+ }
+}
+
+type Scene = (graph: SceneGraph, pageId: string) => void
+
+function renderPixels(scene: Scene): Uint8Array {
+ const graph = new SceneGraph()
+ const page = graph.getPages()[0]
+ scene(graph, page.id)
+ renderer.pageId = page.id
+ const canvas = renderer.surface.getCanvas()
+ canvas.clear(ck.TRANSPARENT)
+ renderer.renderSceneToCanvas(canvas, graph, page.id)
+ renderer.surface.flush()
+ const image = renderer.surface.makeImageSnapshot()
+ try {
+ return Uint8Array.from(
+ expectDefined(
+ image.readPixels(0, 0, {
+ width: SIZE,
+ height: SIZE,
+ colorType: ck.ColorType.RGBA_8888,
+ alphaType: ck.AlphaType.Unpremul,
+ colorSpace: ck.ColorSpace.SRGB
+ }),
+ 'pixels'
+ )
+ )
+ } finally {
+ image.delete()
+ }
+}
+
+function rgbAt(pixels: Uint8Array, x: number, y: number): number[] {
+ const offset = (y * SIZE + x) * 4
+ return Array.from(pixels.subarray(offset, offset + 3))
+}
+
+describe('a stroke paint blends with what is under it, as a fill paint does', () => {
+ test('on a shape stroked by its outline', () => {
+ const pixels = renderPixels((graph, pageId) => {
+ graph.createNode('RECTANGLE', pageId, {
+ x: 10,
+ y: 10,
+ width: 40,
+ height: 40,
+ fills: RED_FILL,
+ strokes: [greenStroke('MULTIPLY')]
+ })
+ })
+ expect(rgbAt(pixels, 12, 30)).toEqual([0, 0, 0])
+ expect(rgbAt(pixels, 30, 30)).toEqual([255, 0, 0])
+ })
+
+ test('on a vector stroked by its path', () => {
+ const pixels = renderPixels((graph, pageId) => {
+ graph.createNode('VECTOR', pageId, {
+ x: 10,
+ y: 10,
+ width: 40,
+ height: 40,
+ vectorNetwork: squareVector(),
+ fills: RED_FILL,
+ strokes: [greenStroke('MULTIPLY')]
+ })
+ })
+ expect(rgbAt(pixels, 12, 30)).toEqual([0, 0, 0])
+ expect(rgbAt(pixels, 30, 30)).toEqual([255, 0, 0])
+ })
+
+ test('by its own mode, so a normal stroke after a blended one covers what is under it', () => {
+ const pixels = renderPixels((graph, pageId) => {
+ graph.createNode('RECTANGLE', pageId, {
+ x: 10,
+ y: 10,
+ width: 40,
+ height: 40,
+ fills: RED_FILL,
+ strokes: [greenStroke('MULTIPLY'), { ...greenStroke('NORMAL'), weight: 4 }]
+ })
+ graph.createNode('RECTANGLE', pageId, {
+ x: 60,
+ y: 10,
+ width: 40,
+ height: 40,
+ fills: RED_FILL,
+ strokes: [greenStroke('NORMAL')]
+ })
+ })
+ expect(rgbAt(pixels, 12, 30)).toEqual([0, 255, 0])
+ expect(rgbAt(pixels, 17, 30)).toEqual([0, 0, 0])
+ expect(rgbAt(pixels, 62, 30)).toEqual([0, 255, 0])
+ })
+})
+
+test('a plus darker stroke adds itself to what is under it, less white', () => {
+ const pixels = renderPixels((graph, pageId) => {
+ graph.createNode('RECTANGLE', pageId, {
+ x: 10,
+ y: 10,
+ width: 40,
+ height: 40,
+ fills: [{ ...RED_FILL[0], color: { r: 0.6, g: 0.4, b: 0.2, a: 1 } }],
+ strokes: [{ ...greenStroke('LINEAR_BURN'), color: { r: 0.2, g: 0.8, b: 0.7, a: 1 } }]
+ })
+ })
+ const burned = [0, 51, 0]
+ rgbAt(pixels, 12, 30).forEach((channel, index) => {
+ expect(Math.abs(channel - burned[index])).toBeLessThan(2)
+ })
+ expect(rgbAt(pixels, 30, 30)).toEqual([153, 102, 51])
+})
diff --git a/packages/core/tests/io/formats/fig/roundtrip/blend-mode.test.ts b/packages/core/tests/io/formats/fig/roundtrip/blend-mode.test.ts
index 6a2398a9a..7a098d293 100644
--- a/packages/core/tests/io/formats/fig/roundtrip/blend-mode.test.ts
+++ b/packages/core/tests/io/formats/fig/roundtrip/blend-mode.test.ts
@@ -25,4 +25,43 @@ describe('roundtrip: layer blend modes', () => {
'PASS_THROUGH'
])
})
+
+ test('plus darker and plus lighter survive on layers and paints', async () => {
+ const graph = new SceneGraph()
+ const page = graph.getPages()[0]
+ for (const blendMode of ['LINEAR_BURN', 'LINEAR_DODGE'] as const) {
+ graph.createNode('RECTANGLE', page.id, {
+ name: blendMode,
+ width: 80,
+ height: 80,
+ blendMode,
+ fills: [
+ { type: 'SOLID', color: { r: 1, g: 0, b: 0, a: 1 }, opacity: 1, visible: true, blendMode }
+ ],
+ strokes: [
+ {
+ type: 'SOLID',
+ color: { r: 0, g: 0, b: 1, a: 1 },
+ opacity: 1,
+ visible: true,
+ weight: 2,
+ align: 'INSIDE',
+ blendMode
+ }
+ ]
+ })
+ }
+
+ const reImported = await parseFigFile((await exportFigFile(graph)).buffer as ArrayBuffer)
+ const [reImportedPage] = reImported.getPages()
+ populateFigPage(reImported, reImportedPage.id)
+
+ const children = reImported.getChildren(reImportedPage.id)
+ expect(children.map((node) => node.blendMode)).toEqual(['LINEAR_BURN', 'LINEAR_DODGE'])
+ expect(children.map((node) => node.fills[0].blendMode)).toEqual(['LINEAR_BURN', 'LINEAR_DODGE'])
+ expect(children.map((node) => node.strokes[0].blendMode)).toEqual([
+ 'LINEAR_BURN',
+ 'LINEAR_DODGE'
+ ])
+ })
})
diff --git a/packages/design-jsx/src/enums.ts b/packages/design-jsx/src/enums.ts
index 52a2476a5..f5fce1ad7 100644
--- a/packages/design-jsx/src/enums.ts
+++ b/packages/design-jsx/src/enums.ts
@@ -103,9 +103,11 @@ export const BLEND_MODE = lowercaseEnum<BlendMode>([
'NORMAL',
'DARKEN',
'MULTIPLY',
+ 'LINEAR_BURN',
'COLOR_BURN',
'LIGHTEN',
'SCREEN',
+ 'LINEAR_DODGE',
'COLOR_DODGE',
'OVERLAY',
'SOFT_LIGHT',
diff --git a/packages/scene-graph/src/types.ts b/packages/scene-graph/src/types.ts
index 8fe7c03f3..97969c9e2 100644
--- a/packages/scene-graph/src/types.ts
+++ b/packages/scene-graph/src/types.ts
@@ -142,9 +142,11 @@ export type BlendMode =
| 'NORMAL'
| 'DARKEN'
| 'MULTIPLY'
+ | 'LINEAR_BURN'
| 'COLOR_BURN'
| 'LIGHTEN'
| 'SCREEN'
+ | 'LINEAR_DODGE'
| 'COLOR_DODGE'
| 'OVERLAY'
| 'SOFT_LIGHT'
diff --git a/packages/vue/src/i18n/locales/de/panels.json b/packages/vue/src/i18n/locales/de/panels.json
index ff6c4194e..9380ef956 100644
--- a/packages/vue/src/i18n/locales/de/panels.json
+++ b/packages/vue/src/i18n/locales/de/panels.json
@@ -487,9 +487,11 @@
"blendModeNormal": "Normal",
"blendModeDarken": "Abdunkeln",
"blendModeMultiply": "Multiplizieren",
+ "blendModeLinearBurn": "Linear nachbelichten",
"blendModeColorBurn": "Farbig nachbelichten",
"blendModeLighten": "Aufhellen",
"blendModeScreen": "Negativ multiplizieren",
+ "blendModeLinearDodge": "Linear abwedeln",
"blendModeColorDodge": "Farbig abwedeln",
"blendModeOverlay": "Überlagern",
"blendModeSoftLight": "Weiches Licht",
diff --git a/packages/vue/src/i18n/locales/es/panels.json b/packages/vue/src/i18n/locales/es/panels.json
index 77c7b50a5..d0f9ff5fc 100644
--- a/packages/vue/src/i18n/locales/es/panels.json
+++ b/packages/vue/src/i18n/locales/es/panels.json
@@ -487,9 +487,11 @@
"blendModeNormal": "Normal",
"blendModeDarken": "Oscurecer",
"blendModeMultiply": "Multiplicar",
+ "blendModeLinearBurn": "Subexponer lineal",
"blendModeColorBurn": "Subexponer color",
"blendModeLighten": "Aclarar",
"blendModeScreen": "Trama",
+ "blendModeLinearDodge": "Sobreexponer lineal",
"blendModeColorDodge": "Sobreexponer color",
"blendModeOverlay": "Superponer",
"blendModeSoftLight": "Luz suave",
diff --git a/packages/vue/src/i18n/locales/fr/panels.json b/packages/vue/src/i18n/locales/fr/panels.json
index 9651b8e3b..05d4a7513 100644
--- a/packages/vue/src/i18n/locales/fr/panels.json
+++ b/packages/vue/src/i18n/locales/fr/panels.json
@@ -487,9 +487,11 @@
"blendModeNormal": "Normal",
"blendModeDarken": "Obscurcir",
"blendModeMultiply": "Produit",
+ "blendModeLinearBurn": "Densité linéaire +",
"blendModeColorBurn": "Densité couleur +",
"blendModeLighten": "Éclaircir",
"blendModeScreen": "Écran",
+ "blendModeLinearDodge": "Densité linéaire -",
"blendModeColorDodge": "Densité couleur -",
"blendModeOverlay": "Incrustation",
"blendModeSoftLight": "Lumière tamisée",
diff --git a/packages/vue/src/i18n/locales/it/panels.json b/packages/vue/src/i18n/locales/it/panels.json
index 90fdf2b70..b1750e703 100644
--- a/packages/vue/src/i18n/locales/it/panels.json
+++ b/packages/vue/src/i18n/locales/it/panels.json
@@ -487,9 +487,11 @@
"blendModeNormal": "Normale",
"blendModeDarken": "Scurisci",
"blendModeMultiply": "Moltiplica",
+ "blendModeLinearBurn": "Brucia lineare",
"blendModeColorBurn": "Brucia colore",
"blendModeLighten": "Schiarisci",
"blendModeScreen": "Scolora",
+ "blendModeLinearDodge": "Scherma lineare",
"blendModeColorDodge": "Scherma colore",
"blendModeOverlay": "Sovrapponi",
"blendModeSoftLight": "Luce soffusa",
diff --git a/packages/vue/src/i18n/locales/ja/panels.json b/packages/vue/src/i18n/locales/ja/panels.json
index 1870b80b2..31a5a8dfe 100644
--- a/packages/vue/src/i18n/locales/ja/panels.json
+++ b/packages/vue/src/i18n/locales/ja/panels.json
@@ -481,9 +481,11 @@
"blendModeNormal": "通常",
"blendModeDarken": "比較(暗)",
"blendModeMultiply": "乗算",
+ "blendModeLinearBurn": "焼き込み(リニア)",
"blendModeColorBurn": "焼き込みカラー",
"blendModeLighten": "比較(明)",
"blendModeScreen": "スクリーン",
+ "blendModeLinearDodge": "覆い焼き(リニア)",
"blendModeColorDodge": "覆い焼きカラー",
"blendModeOverlay": "オーバーレイ",
"blendModeSoftLight": "ソフトライト",
diff --git a/packages/vue/src/i18n/locales/pl/panels.json b/packages/vue/src/i18n/locales/pl/panels.json
index a40c95dbe..a65a32b72 100644
--- a/packages/vue/src/i18n/locales/pl/panels.json
+++ b/packages/vue/src/i18n/locales/pl/panels.json
@@ -493,9 +493,11 @@
"blendModeNormal": "Normalny",
"blendModeDarken": "Ciemniej",
"blendModeMultiply": "Mnożenie",
+ "blendModeLinearBurn": "Ściemnianie liniowe",
"blendModeColorBurn": "Ściemnianie koloru",
"blendModeLighten": "Jaśniej",
"blendModeScreen": "Ekran",
+ "blendModeLinearDodge": "Rozjaśnianie liniowe",
"blendModeColorDodge": "Rozjaśnianie koloru",
"blendModeOverlay": "Nakładka",
"blendModeSoftLight": "Łagodne światło",
diff --git a/packages/vue/src/i18n/locales/ru/panels.json b/packages/vue/src/i18n/locales/ru/panels.json
index a064305ab..348756ccd 100644
--- a/packages/vue/src/i18n/locales/ru/panels.json
+++ b/packages/vue/src/i18n/locales/ru/panels.json
@@ -493,9 +493,11 @@
"blendModeNormal": "Обычный",
"blendModeDarken": "Затемнение",
"blendModeMultiply": "Умножение",
+ "blendModeLinearBurn": "Линейный затемнитель",
"blendModeColorBurn": "Затемнение основы",
"blendModeLighten": "Осветление",
"blendModeScreen": "Экран",
+ "blendModeLinearDodge": "Линейный осветлитель",
"blendModeColorDodge": "Осветление основы",
"blendModeOverlay": "Перекрытие",
"blendModeSoftLight": "Мягкий свет",
diff --git a/packages/vue/src/i18n/locales/zh-cn/panels.json b/packages/vue/src/i18n/locales/zh-cn/panels.json
index e496b968d..f3996f90f 100644
--- a/packages/vue/src/i18n/locales/zh-cn/panels.json
+++ b/packages/vue/src/i18n/locales/zh-cn/panels.json
@@ -481,9 +481,11 @@
"blendModeNormal": "正常",
"blendModeDarken": "变暗",
"blendModeMultiply": "正片叠底",
+ "blendModeLinearBurn": "线性加深",
"blendModeColorBurn": "颜色加深",
"blendModeLighten": "变亮",
"blendModeScreen": "滤色",
+ "blendModeLinearDodge": "线性减淡",
"blendModeColorDodge": "颜色减淡",
"blendModeOverlay": "叠加",
"blendModeSoftLight": "柔光",
diff --git a/packages/vue/src/i18n/messages/panels.ts b/packages/vue/src/i18n/messages/panels.ts
index 9a306fcfa..8b9c4226b 100644
--- a/packages/vue/src/i18n/messages/panels.ts
+++ b/packages/vue/src/i18n/messages/panels.ts
@@ -397,9 +397,11 @@ export const panelMessageDefaults = {
blendModeNormal: 'Normal',
blendModeDarken: 'Darken',
blendModeMultiply: 'Multiply',
+ blendModeLinearBurn: 'Plus darker',
blendModeColorBurn: 'Color burn',
blendModeLighten: 'Lighten',
blendModeScreen: 'Screen',
+ blendModeLinearDodge: 'Plus lighter',
blendModeColorDodge: 'Color dodge',
blendModeOverlay: 'Overlay',
blendModeSoftLight: 'Soft light',
diff --git a/src/components/properties/blend-mode/use.ts b/src/components/properties/blend-mode/use.ts
index 1780c8455..cd2b91fb4 100644
--- a/src/components/properties/blend-mode/use.ts
+++ b/src/components/properties/blend-mode/use.ts
@@ -26,6 +26,7 @@ export function useBlendModeGroups(includePassThrough = false) {
options: [
{ value: 'DARKEN', label: panels.value.blendModeDarken },
{ value: 'MULTIPLY', label: panels.value.blendModeMultiply },
+ { value: 'LINEAR_BURN', label: panels.value.blendModeLinearBurn },
{ value: 'COLOR_BURN', label: panels.value.blendModeColorBurn }
]
},
@@ -33,6 +34,7 @@ export function useBlendModeGroups(includePassThrough = false) {
options: [
{ value: 'LIGHTEN', label: panels.value.blendModeLighten },
{ value: 'SCREEN', label: panels.value.blendModeScreen },
+ { value: 'LINEAR_DODGE', label: panels.value.blendModeLinearDodge },
{ value: 'COLOR_DODGE', label: panels.value.blendModeColorDodge }
]
},
diff --git a/tests/e2e/canvas/blend-modes-visual.spec.ts b/tests/e2e/canvas/blend-modes-visual.spec.ts
new file mode 100644
index 000000000..386a3b846
--- /dev/null
+++ b/tests/e2e/canvas/blend-modes-visual.spec.ts
@@ -0,0 +1,14 @@
+import { expect, test, useEditorSetupWithClear } from '#tests/e2e/fixtures'
+import { linearBlendDriver } from '#tests/helpers/canvas/blend/driver'
+
+const editor = useEditorSetupWithClear('/?test&no-chrome&no-rulers')
+const scene = linearBlendDriver(() => editor.page)
+
+test('plus darker and plus lighter on layers, fills and strokes', async () => {
+ await scene.show()
+ await editor.canvas.waitForRender()
+ editor.canvas.assertNoErrors()
+ expect(await editor.canvas.screenshotCanvasRegion()).toMatchSnapshot(
+ 'plus-darker-plus-lighter.png'
+ )
+})
diff --git a/tests/e2e/canvas/blend-modes-visual.spec.ts-snapshots/plus-darker-plus-lighter-openpencil-darwin.png b/tests/e2e/canvas/blend-modes-visual.spec.ts-snapshots/plus-darker-plus-lighter-openpencil-darwin.png
new file mode 100644
index 000000000..ea72f71ec
Binary files /dev/null and b/tests/e2e/canvas/blend-modes-visual.spec.ts-snapshots/plus-darker-plus-lighter-openpencil-darwin.png differ
diff --git a/tests/engine/io/svg/export/render.test.ts b/tests/engine/io/svg/export/render.test.ts
index 29a61942f..8ed59a6e3 100644
--- a/tests/engine/io/svg/export/render.test.ts
+++ b/tests/engine/io/svg/export/render.test.ts
@@ -488,6 +488,30 @@ describe('renderNodesToSVG()', () => {
expect(result).toContain('mix-blend-mode: multiply')
})
+ test('plus lighter blend mode', () => {
+ const graph = makeGraph()
+ const node = graph.createNode('RECTANGLE', pageId(graph), {
+ width: 100,
+ height: 100,
+ blendMode: 'LINEAR_DODGE',
+ fills: [{ type: 'SOLID', color: { r: 1, g: 0, b: 0, a: 1 }, opacity: 1, visible: true }]
+ })
+ const result = exportSVGOrThrow(graph, [node.id])
+ expect(result).toContain('mix-blend-mode: plus-lighter')
+ })
+
+ test('plus darker blend mode', () => {
+ const graph = makeGraph()
+ const node = graph.createNode('RECTANGLE', pageId(graph), {
+ width: 100,
+ height: 100,
+ blendMode: 'LINEAR_BURN',
+ fills: [{ type: 'SOLID', color: { r: 1, g: 0, b: 0, a: 1 }, opacity: 1, visible: true }]
+ })
+ const result = exportSVGOrThrow(graph, [node.id])
+ expect(result).toContain('mix-blend-mode: plus-darker')
+ })
+
test('fill with opacity < 1', () => {
const graph = makeGraph()
const node = graph.createNode('RECTANGLE', pageId(graph), {
diff --git a/tests/engine/render/canvas/blend.test.ts b/tests/engine/render/canvas/blend.test.ts
index f82234b60..6d04eab4d 100644
--- a/tests/engine/render/canvas/blend.test.ts
+++ b/tests/engine/render/canvas/blend.test.ts
@@ -29,7 +29,8 @@ const blendModes = {
Hue: 'Hue',
Saturation: 'Saturation',
Color: 'Color',
- Luminosity: 'Luminosity'
+ Luminosity: 'Luminosity',
+ Plus: 'Plus'
}
function createCanvas() {
@@ -87,7 +88,8 @@ function calls(fn: ReturnType<typeof mock>): unknown[][] {
describe('canvas blend modes', () => {
test('maps Figma blend modes to CanvasKit blend modes', () => {
const ck = asCanvasKit({ BlendMode: blendModes })
- const cases: Array<[BlendMode, string]> = [
+ // Plus darker and plus lighter have no CanvasKit mode; they draw through runtime blenders.
+ const cases: Array<[Exclude<BlendMode, 'LINEAR_BURN' | 'LINEAR_DODGE'>, string]> = [
['NORMAL', 'SrcOver'],
['PASS_THROUGH', 'SrcOver'],
['DARKEN', 'Darken'],
diff --git a/tests/helpers/canvas/blend/driver.ts b/tests/helpers/canvas/blend/driver.ts
new file mode 100644
index 000000000..ca3f9aed4
--- /dev/null
+++ b/tests/helpers/canvas/blend/driver.ts
@@ -0,0 +1,21 @@
+import type { Page } from '@playwright/test'
+
+import type * as BlendScenes from '#tests/helpers/canvas/blend/scene'
+
+export function linearBlendDriver(page: () => Page) {
+ return {
+ show() {
+ return page().evaluate(async () => {
+ const store = window.openPencil?.getStore?.()
+ if (!store) {
+ throw new Error('OpenPencil store not initialized')
+ }
+ const sceneURL = '/tests/helpers/canvas/blend/scene.ts'
+ const scenes: typeof BlendScenes = await import(sceneURL)
+ scenes.createLinearBlendScene(store.graph, store.state.currentPageId)
+ store.clearSelection()
+ store.requestRender()
+ })
+ }
+ }
+}
diff --git a/tests/helpers/canvas/blend/scene.ts b/tests/helpers/canvas/blend/scene.ts
new file mode 100644
index 000000000..c0cea4b69
--- /dev/null
+++ b/tests/helpers/canvas/blend/scene.ts
@@ -0,0 +1,79 @@
+import type { SceneGraph } from '@open-pencil/scene-graph'
+
+const LINEAR_MODES = ['LINEAR_BURN', 'LINEAR_DODGE'] as const
+
+const solid = (r: number, g: number, b: number) => ({
+ type: 'SOLID' as const,
+ color: { r, g, b, a: 1 },
+ opacity: 1,
+ visible: true
+})
+
+function addBackdrops(graph: SceneGraph, pageId: string): void {
+ const colors = [solid(0.2, 0.45, 0.85), solid(0.55, 0.55, 0.55), solid(0.9, 0.6, 0.2)]
+ for (const [index, fill] of colors.entries()) {
+ graph.createNode('RECTANGLE', pageId, {
+ name: `Backdrop ${index}`,
+ x: 60 + index * 160,
+ y: 60,
+ width: 160,
+ height: 320,
+ fills: [fill]
+ })
+ }
+}
+
+export function createLinearBlendScene(graph: SceneGraph, pageId: string): void {
+ addBackdrops(graph, pageId)
+ const paint = solid(0.5, 0.35, 0.6)
+ for (const [row, blendMode] of LINEAR_MODES.entries()) {
+ const y = 90 + row * 150
+ graph.createNode('RECTANGLE', pageId, {
+ name: `${blendMode} layer`,
+ x: 80,
+ y,
+ width: 420,
+ height: 36,
+ blendMode,
+ fills: [paint]
+ })
+ graph.createNode('RECTANGLE', pageId, {
+ name: `${blendMode} fill`,
+ x: 80,
+ y: y + 46,
+ width: 420,
+ height: 36,
+ fills: [{ ...paint, blendMode }]
+ })
+ graph.createNode('RECTANGLE', pageId, {
+ name: `${blendMode} stroke`,
+ x: 92,
+ y: y + 98,
+ width: 396,
+ height: 12,
+ fills: [],
+ strokes: [{ ...paint, weight: 12, align: 'OUTSIDE', blendMode }]
+ })
+ // A thin bar casting a blended shadow below it into the gap before the next row.
+ graph.createNode('RECTANGLE', pageId, {
+ name: `${blendMode} shadow`,
+ x: 80,
+ y: y + 124,
+ width: 420,
+ height: 6,
+ fills: [paint],
+ effects: [
+ {
+ type: 'DROP_SHADOW',
+ color: { ...paint.color },
+ offset: { x: 0, y: 10 },
+ radius: 0,
+ spread: 0,
+ visible: true,
+ blendMode,
+ showShadowBehindNode: false
+ }
+ ]
+ })
+ }
+}