Skip to main content

Blend Modes (BlendMode type)

BlendMode is a union type that maps directly to the HTMLCanvasElement globalCompositeOperation values supported by Fuderu. It determines how a layer’s pixels combine with the layers beneath it.

import type { BlendMode } from "fuderu";

Type Definition

export type BlendMode =
| "source-over"
| "multiply"
| "screen"
| "overlay"
| "darken"
| "lighten"
| "color-dodge"
| "color-burn"
| "hard-light"
| "soft-light"
| "difference"
| "exclusion"
| "hue"
| "saturation"
| "color"
| "luminosity";

Visual Reference

ModeDescription
source-overDefault – normal stacking (source over destination).
multiplyMultiplies the colors; result is always darker.
screenInverts, multiplies, then inverts; result is always lighter.
overlayCombines multiply and screen – light parts become lighter, dark parts darker.
darkenKeeps the darker of the source or destination.
lightenKeeps the lighter of the source or destination.
color-dodgeBrightens the destination to reflect the source.
color-burnDarkens the destination to reflect the source.
hard-lightSimilar to overlay but with source and destination swapped.
soft-lightA softer version of hard‑light.
differenceSubtracts the darker color from the lighter (producing high contrast).
exclusionLike difference but with lower contrast.
hueUses the hue of the source, with saturation and luminosity of destination.
saturationUses the saturation of the source, with hue and luminosity of destination.
colorUses hue and saturation of the source, luminosity of destination.
luminosityUses luminosity of the source, with hue and saturation of destination.

Usage Example

import { Canvas } from "fuderu";

const painter = new Canvas({
canvas: "#myCanvas",
document: { width: 1024, height: 768 },
});

// Add a base color layer
const base = painter.createLayer({
name: "Base Color",
blendMode: "source-over",
});
// … draw your base colors …

// Add a shading layer that darkens the base
const shade = painter.createLayer({
name: "Shading",
blendMode: "multiply",
});
// … draw shadows with a dark color …