Skip to content

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

Fix effects rendering: shadows, blur, spread (#24)

Danila Poyarkov8ab714829438
diff --git a/packages/core/src/renderer.ts b/packages/core/src/renderer.ts
index f20b7a81a..c560dddce 100644
--- a/packages/core/src/renderer.ts
+++ b/packages/core/src/renderer.ts
@@ -959,6 +959,21 @@ export class SkiaRenderer {
canvas.saveLayer(this.opacityPaint)
}
+ const layerBlur = node.effects.find((e) => e.visible && e.type === 'LAYER_BLUR')
+ if (layerBlur) {
+ const blurPaint = new this.ck.Paint()
+ blurPaint.setImageFilter(
+ this.ck.ImageFilter.MakeBlur(
+ layerBlur.radius / 2,
+ layerBlur.radius / 2,
+ this.ck.TileMode.Clamp,
+ null
+ )
+ )
+ canvas.saveLayer(blurPaint)
+ blurPaint.delete()
+ }
+
const rotation =
overlays.rotationPreview?.nodeId === nodeId ? overlays.rotationPreview.angle : node.rotation
@@ -1013,6 +1028,9 @@ export class SkiaRenderer {
}
}
+ if (layerBlur) {
+ canvas.restore()
+ }
if (node.opacity < 1) {
canvas.restore()
}
@@ -1357,6 +1375,9 @@ export class SkiaRenderer {
node.bottomRightRadius > 0 ||
node.bottomLeftRadius > 0))
+ // Effects (behind: drop shadow)
+ this.renderEffects(canvas, node, rect, hasRadius, 'behind')
+
// Fills
for (let fi = 0; fi < node.fills.length; fi++) {
const fill = node.fills[fi]!
@@ -1368,9 +1389,6 @@ export class SkiaRenderer {
this.fillPaint.setShader(null)
}
- // Effects (behind: drop shadow)
- this.renderEffects(canvas, node, rect, hasRadius, 'behind')
-
// Strokes
for (let si = 0; si < node.strokes.length; si++) {
const stroke = node.strokes[si]!
@@ -1534,6 +1552,87 @@ export class SkiaRenderer {
)
}
+ private applyClippedBlur(
+ canvas: Canvas,
+ node: SceneNode,
+ rect: Float32Array,
+ hasRadius: boolean,
+ sigma: number
+ ): void {
+ canvas.save()
+ this.clipNodeShape(canvas, node, rect, hasRadius)
+ const blurPaint = new this.ck.Paint()
+ blurPaint.setImageFilter(
+ this.ck.ImageFilter.MakeBlur(sigma, sigma, this.ck.TileMode.Clamp, null)
+ )
+ canvas.saveLayer(blurPaint)
+ canvas.restore()
+ canvas.restore()
+ blurPaint.delete()
+ }
+
+ private clipNodeShape(canvas: Canvas, node: SceneNode, rect: Float32Array, hasRadius: boolean): void {
+ if (node.type === 'ELLIPSE') {
+ const clipPath = new this.ck.Path()
+ clipPath.addOval(rect)
+ canvas.clipPath(clipPath, this.ck.ClipOp.Intersect, true)
+ clipPath.delete()
+ } else if (hasRadius) {
+ canvas.clipRRect(this.makeRRect(node), this.ck.ClipOp.Intersect, true)
+ } else {
+ canvas.clipRect(rect, this.ck.ClipOp.Intersect, true)
+ }
+ }
+
+ private makeRRectWithSpread(node: SceneNode, spread: number): Float32Array {
+ if (node.independentCorners) {
+ return new Float32Array([
+ -spread,
+ -spread,
+ node.width + spread,
+ node.height + spread,
+ Math.max(0, node.topLeftRadius + spread),
+ Math.max(0, node.topLeftRadius + spread),
+ Math.max(0, node.topRightRadius + spread),
+ Math.max(0, node.topRightRadius + spread),
+ Math.max(0, node.bottomRightRadius + spread),
+ Math.max(0, node.bottomRightRadius + spread),
+ Math.max(0, node.bottomLeftRadius + spread),
+ Math.max(0, node.bottomLeftRadius + spread)
+ ])
+ }
+ return this.ck.RRectXY(
+ this.ck.LTRBRect(-spread, -spread, node.width + spread, node.height + spread),
+ Math.max(0, node.cornerRadius + spread),
+ Math.max(0, node.cornerRadius + spread)
+ )
+ }
+
+ private makeRRectWithOffset(node: SceneNode, ox: number, oy: number, spread: number): Float32Array {
+ const s = spread
+ if (node.independentCorners) {
+ return new Float32Array([
+ ox + s,
+ oy + s,
+ node.width + ox - s,
+ node.height + oy - s,
+ Math.max(0, node.topLeftRadius - s),
+ Math.max(0, node.topLeftRadius - s),
+ Math.max(0, node.topRightRadius - s),
+ Math.max(0, node.topRightRadius - s),
+ Math.max(0, node.bottomRightRadius - s),
+ Math.max(0, node.bottomRightRadius - s),
+ Math.max(0, node.bottomLeftRadius - s),
+ Math.max(0, node.bottomLeftRadius - s)
+ ])
+ }
+ return this.ck.RRectXY(
+ this.ck.LTRBRect(ox + s, oy + s, node.width + ox - s, node.height + oy - s),
+ Math.max(0, node.cornerRadius - s),
+ Math.max(0, node.cornerRadius - s)
+ )
+ }
+
private drawArc(canvas: Canvas, node: SceneNode, paint: Paint): void {
const arc = node.arcData
if (!arc) return
@@ -1586,32 +1685,91 @@ export class SkiaRenderer {
if (!effect.visible) continue
if (pass === 'behind' && effect.type === 'DROP_SHADOW') {
- this.auxFill.setColor(
- this.ck.Color4f(effect.color.r, effect.color.g, effect.color.b, effect.color.a)
- )
- this.auxFill.setImageFilter(
- this.ck.ImageFilter.MakeBlur(effect.radius, effect.radius, this.ck.TileMode.Decal, null)
+ const sp = effect.spread
+ const shadowColor = this.ck.Color4f(
+ effect.color.r,
+ effect.color.g,
+ effect.color.b,
+ effect.color.a
)
+ const sigma = effect.radius / 2
- canvas.save()
- canvas.translate(effect.offset.x, effect.offset.y)
- if (node.type === 'ELLIPSE') {
- canvas.drawOval(rect, this.auxFill)
- } else if (hasRadius) {
- canvas.drawRRect(this.makeRRect(node), this.auxFill)
+ if (node.type === 'TEXT') {
+ const dropFilter = this.ck.ImageFilter.MakeDropShadowOnly(
+ effect.offset.x,
+ effect.offset.y,
+ sigma,
+ sigma,
+ shadowColor,
+ null
+ )
+ const layerPaint = new this.ck.Paint()
+ layerPaint.setImageFilter(dropFilter)
+ canvas.saveLayer(layerPaint)
+ this.renderText(canvas, node)
+ canvas.restore()
+ layerPaint.delete()
} else {
- canvas.drawRect(rect, this.auxFill)
+ const dropFilter = this.ck.ImageFilter.MakeDropShadowOnly(
+ effect.offset.x,
+ effect.offset.y,
+ sigma,
+ sigma,
+ shadowColor,
+ null
+ )
+ const layerPaint = new this.ck.Paint()
+ layerPaint.setImageFilter(dropFilter)
+ canvas.saveLayer(layerPaint)
+ this.auxFill.setColor(this.ck.WHITE)
+ this.auxFill.setImageFilter(null)
+ if (node.type === 'ELLIPSE') {
+ const spreadRect = this.ck.LTRBRect(-sp, -sp, node.width + sp, node.height + sp)
+ canvas.drawOval(spreadRect, this.auxFill)
+ } else if (hasRadius) {
+ canvas.drawRRect(this.makeRRectWithSpread(node, sp), this.auxFill)
+ } else {
+ const spreadRect = this.ck.LTRBRect(-sp, -sp, node.width + sp, node.height + sp)
+ canvas.drawRect(spreadRect, this.auxFill)
+ }
+ canvas.restore()
+ layerPaint.delete()
}
- canvas.restore()
- this.auxFill.setImageFilter(null)
}
- if (pass === 'front' && effect.type === 'LAYER_BLUR') {
- // Layer blur applied as save layer with blur filter — already applied via opacity layer
+ if (
+ (pass === 'behind' && effect.type === 'BACKGROUND_BLUR') ||
+ (pass === 'front' && effect.type === 'FOREGROUND_BLUR')
+ ) {
+ this.applyClippedBlur(canvas, node, rect, hasRadius, effect.radius / 2)
}
if (pass === 'front' && effect.type === 'INNER_SHADOW') {
- // Inner shadow: draw a shadow clipped to the node shape
+ if (node.type === 'TEXT') {
+ const blurFilter = this.ck.ImageFilter.MakeBlur(
+ effect.radius,
+ effect.radius,
+ this.ck.TileMode.Decal,
+ null
+ )
+ const layerPaint = new this.ck.Paint()
+ layerPaint.setImageFilter(blurFilter)
+ layerPaint.setColorFilter(
+ this.ck.ColorFilter.MakeBlend(
+ this.ck.Color4f(effect.color.r, effect.color.g, effect.color.b, effect.color.a),
+ this.ck.BlendMode.SrcIn
+ )
+ )
+ canvas.saveLayer(layerPaint)
+ canvas.save()
+ canvas.translate(effect.offset.x, effect.offset.y)
+ this.renderText(canvas, node)
+ canvas.restore()
+ canvas.restore()
+ layerPaint.delete()
+ continue
+ }
+ const sp = effect.spread
this.auxFill.setColor(
this.ck.Color4f(effect.color.r, effect.color.g, effect.color.b, effect.color.a)
)
@@ -1631,34 +1789,39 @@ export class SkiaRenderer {
canvas.clipRect(rect, this.ck.ClipOp.Intersect, true)
}
- // Draw inverted shape offset by shadow offset
+ const expand = effect.radius * 2
const big = this.ck.LTRBRect(
- -effect.radius * 2 + effect.offset.x,
- -effect.radius * 2 + effect.offset.y,
- node.width + effect.radius * 2 + effect.offset.x,
- node.height + effect.radius * 2 + effect.offset.y
+ -expand + effect.offset.x,
+ -expand + effect.offset.y,
+ node.width + expand + effect.offset.x,
+ node.height + expand + effect.offset.y
)
const bigPath = new this.ck.Path()
bigPath.addRect(big)
if (node.type === 'ELLIPSE') {
const innerPath = new this.ck.Path()
const offsetRect = this.ck.LTRBRect(
- effect.offset.x,
- effect.offset.y,
- node.width + effect.offset.x,
- node.height + effect.offset.y
+ effect.offset.x + sp,
+ effect.offset.y + sp,
+ node.width + effect.offset.x - sp,
+ node.height + effect.offset.y - sp
)
innerPath.addOval(offsetRect)
bigPath.op(innerPath, this.ck.PathOp.Difference)
innerPath.delete()
+ } else if (hasRadius) {
+ const innerPath = new this.ck.Path()
+ innerPath.addRRect(this.makeRRectWithOffset(node, effect.offset.x + sp, effect.offset.y + sp, -sp))
+ bigPath.op(innerPath, this.ck.PathOp.Difference)
+ innerPath.delete()
} else {
const innerPath = new this.ck.Path()
innerPath.addRect(
this.ck.LTRBRect(
- effect.offset.x,
- effect.offset.y,
- node.width + effect.offset.x,
- node.height + effect.offset.y
+ effect.offset.x + sp,
+ effect.offset.y + sp,
+ node.width + effect.offset.x - sp,
+ node.height + effect.offset.y - sp
)
)
bigPath.op(innerPath, this.ck.PathOp.Difference)
diff --git a/src/components/FontPicker.vue b/src/components/FontPicker.vue
index bdedc679f..1478b8f8b 100644
--- a/src/components/FontPicker.vue
+++ b/src/components/FontPicker.vue
@@ -94,12 +94,13 @@ function onSelect(val: string) {
<span class="truncate">{{ option }}</span>
</ListboxItem>
</ListboxVirtualizer>
- <div v-if="families.length === 0" class="flex h-full items-center justify-center px-3 text-center text-xs text-muted">
+ <div
+ v-if="families.length === 0"
+ class="flex h-full items-center justify-center px-3 text-center text-xs text-muted"
+ >
<div>
<p>No local fonts available.</p>
- <p class="mt-1">
- Use the desktop app or Chrome/Edge to access system fonts.
- </p>
+ <p class="mt-1">Use the desktop app or Chrome/Edge to access system fonts.</p>
</div>
</div>
<div v-else-if="filtered.length === 0" class="px-2 py-3 text-center text-xs text-muted">
diff --git a/src/components/properties/EffectsSection.vue b/src/components/properties/EffectsSection.vue
index c3257a6da..b56df49d3 100644
--- a/src/components/properties/EffectsSection.vue
+++ b/src/components/properties/EffectsSection.vue
@@ -10,6 +10,7 @@ import type { Color, Effect } from '@/engine/scene-graph'
const { store, node } = useNodeProps()
const expandedIndex = ref<number | null>(null)
+const effectsBeforeScrub = ref<Effect[] | null>(null)
type EffectType = Effect['type']
@@ -39,23 +40,46 @@ function defaultEffect(): Effect {
}
}
-function updateEffect(index: number, changes: Partial<Effect>) {
+function scrubEffect(index: number, changes: Partial<Effect>) {
const n = node.value
if (!n) return
+ if (!effectsBeforeScrub.value) {
+ effectsBeforeScrub.value = n.effects.map((e) => ({
+ ...e,
+ color: { ...e.color },
+ offset: { ...e.offset }
+ }))
+ }
const effects = [...n.effects]
effects[index] = { ...effects[index], ...changes }
- store.updateNodeWithUndo(n.id, { effects }, 'Change effect')
+ store.updateNode(n.id, { effects })
+ store.requestRender()
}
-function updateColor(index: number, color: Color) {
- updateEffect(index, { color })
+function commitEffect(index: number, changes: Partial<Effect>) {
+ const n = node.value
+ if (!n) return
+ const previous = effectsBeforeScrub.value
+ effectsBeforeScrub.value = null
+ const effects = [...n.effects]
+ effects[index] = { ...effects[index], ...changes }
+ store.updateNode(n.id, { effects })
+ store.requestRender()
+ if (previous) {
+ store.commitNodeUpdate(n.id, { effects: previous }, 'Change effect')
+ }
}
-function updateColorOpacity(index: number, opacity: number) {
+function updateEffect(index: number, changes: Partial<Effect>) {
const n = node.value
if (!n) return
- const existing = n.effects[index]
- updateColor(index, { ...existing.color, a: Math.max(0, Math.min(1, opacity / 100)) })
+ const effects = [...n.effects]
+ effects[index] = { ...effects[index], ...changes }
+ store.updateNodeWithUndo(n.id, { effects }, 'Change effect')
+}
+
+function updateColor(index: number, color: Color) {
+ updateEffect(index, { color })
}
function toggleVisibility(index: number) {
@@ -161,12 +185,14 @@ function toggleExpand(index: number) {
<ScrubInput
icon="X"
:model-value="effect.offset.x"
- @update:model-value="updateEffect(i, { offset: { ...effect.offset, x: $event } })"
+ @update:model-value="scrubEffect(i, { offset: { ...effect.offset, x: $event } })"
+ @commit="commitEffect(i, { offset: { ...effect.offset, x: $event } })"
/>
<ScrubInput
icon="Y"
:model-value="effect.offset.y"
- @update:model-value="updateEffect(i, { offset: { ...effect.offset, y: $event } })"
+ @update:model-value="scrubEffect(i, { offset: { ...effect.offset, y: $event } })"
+ @commit="commitEffect(i, { offset: { ...effect.offset, y: $event } })"
/>
</div>
@@ -175,12 +201,14 @@ function toggleExpand(index: number) {
icon="B"
:model-value="effect.radius"
:min="0"
- @update:model-value="updateEffect(i, { radius: $event })"
+ @update:model-value="scrubEffect(i, { radius: $event })"
+ @commit="commitEffect(i, { radius: $event })"
/>
<ScrubInput
icon="S"
:model-value="effect.spread"
- @update:model-value="updateEffect(i, { spread: $event })"
+ @update:model-value="scrubEffect(i, { spread: $event })"
+ @commit="commitEffect(i, { spread: $event })"
/>
</div>
@@ -192,7 +220,16 @@ function toggleExpand(index: number) {
:model-value="Math.round(effect.color.a * 100)"
:min="0"
:max="100"
- @update:model-value="updateColorOpacity(i, $event)"
+ @update:model-value="
+ scrubEffect(i, {
+ color: { ...effect.color, a: Math.max(0, Math.min(1, $event / 100)) }
+ })
+ "
+ @commit="
+ commitEffect(i, {
+ color: { ...effect.color, a: Math.max(0, Math.min(1, $event / 100)) }
+ })
+ "
/>
</div>
</template>
@@ -202,7 +239,8 @@ function toggleExpand(index: number) {
icon="B"
:model-value="effect.radius"
:min="0"
- @update:model-value="updateEffect(i, { radius: $event })"
+ @update:model-value="scrubEffect(i, { radius: $event })"
+ @commit="commitEffect(i, { radius: $event })"
/>
</template>
</div>
diff --git a/src/components/properties/ExportSection.vue b/src/components/properties/ExportSection.vue
index ab2711291..3d9536b82 100644
--- a/src/components/properties/ExportSection.vue
+++ b/src/components/properties/ExportSection.vue
@@ -92,8 +92,6 @@ watch(previewKey, updatePreview, { flush: 'post' })
onUnmounted(() => {
if (previewUrl.value) URL.revokeObjectURL(previewUrl.value)
})
-
-
</script>
<template>
diff --git a/src/demo.ts b/src/demo.ts
index 4ccc6213b..a99f12e7f 100644
--- a/src/demo.ts
+++ b/src/demo.ts
@@ -1,6 +1,6 @@
import { computeAllLayouts } from './engine/layout'
-import type { Color, Fill, GradientStop } from './engine/scene-graph'
+import type { Color, Effect, Fill, GradientStop } from './engine/scene-graph'
import type { EditorStore } from './stores/editor'
const WHITE: Color = { r: 1, g: 1, b: 1, a: 1 }
@@ -703,6 +703,271 @@ export function createDemoShapes(store: EditorStore) {
})
}
+ // ─── Section: Effects Showcase ──────────────────────────────────
+ const effectsSectionId = store.createShape('SECTION', 60, 840, 920, 480)
+ graph.updateNode(effectsSectionId, {
+ name: 'Effects',
+ fills: [{ type: 'SOLID', color: { r: 1, g: 1, b: 1, a: 1 }, visible: true, opacity: 1 }]
+ })
+
+ function dropShadow(
+ ox = 0,
+ oy = 4,
+ radius = 8,
+ spread = 0,
+ color: Color = { r: 0, g: 0, b: 0, a: 0.25 }
+ ): Effect {
+ return {
+ type: 'DROP_SHADOW',
+ color,
+ offset: { x: ox, y: oy },
+ radius,
+ spread,
+ visible: true
+ }
+ }
+
+ function innerShadow(
+ ox = 0,
+ oy = 2,
+ radius = 4,
+ spread = 0,
+ color: Color = { r: 0, g: 0, b: 0, a: 0.2 }
+ ): Effect {
+ return {
+ type: 'INNER_SHADOW',
+ color,
+ offset: { x: ox, y: oy },
+ radius,
+ spread,
+ visible: true
+ }
+ }
+
+ function blurEffect(type: Effect['type'], radius: number): Effect {
+ return {
+ type,
+ color: { r: 0, g: 0, b: 0, a: 0 },
+ offset: { x: 0, y: 0 },
+ radius,
+ spread: 0,
+ visible: true
+ }
+ }
+
+ // Row 1: Drop shadows
+ const shadowLabel = store.createShape('TEXT', 32, 48, 200, 20, effectsSectionId)
+ graph.updateNode(shadowLabel, {
+ name: 'Label',
+ text: 'Drop Shadow',
+ fontSize: 13,
+ fontWeight: 600,
+ fills: [solid(GRAY_500)]
+ })
+
+ const shadowCard1 = store.createShape('FRAME', 32, 76, 160, 100, effectsSectionId)
+ graph.updateNode(shadowCard1, {
+ name: 'Subtle Shadow',
+ cornerRadius: 12,
+ fills: [solid(WHITE)],
+ effects: [dropShadow(0, 2, 8, 0, { r: 0, g: 0, b: 0, a: 0.08 })]
+ })
+ const s1Text = store.createShape('TEXT', 16, 40, 128, 20, shadowCard1)
+ graph.updateNode(s1Text, {
+ name: 'Label',
+ text: 'Subtle',
+ fontSize: 13,
+ fontWeight: 500,
+ fills: [solid(GRAY_500)]
+ })
+
+ const shadowCard2 = store.createShape('FRAME', 220, 76, 160, 100, effectsSectionId)
+ graph.updateNode(shadowCard2, {
+ name: 'Medium Shadow',
+ cornerRadius: 12,
+ fills: [solid(WHITE)],
+ effects: [dropShadow(0, 4, 16, 0, { r: 0, g: 0, b: 0, a: 0.15 })]
+ })
+ const s2Text = store.createShape('TEXT', 16, 40, 128, 20, shadowCard2)
+ graph.updateNode(s2Text, {
+ name: 'Label',
+ text: 'Medium',
+ fontSize: 13,
+ fontWeight: 500,
+ fills: [solid(GRAY_500)]
+ })
+
+ const shadowCard3 = store.createShape('FRAME', 408, 76, 160, 100, effectsSectionId)
+ graph.updateNode(shadowCard3, {
+ name: 'Heavy Shadow',
+ cornerRadius: 12,
+ fills: [solid(WHITE)],
+ effects: [dropShadow(0, 8, 24, 0, { r: 0, g: 0, b: 0, a: 0.2 })]
+ })
+ const s3Text = store.createShape('TEXT', 16, 40, 128, 20, shadowCard3)
+ graph.updateNode(s3Text, {
+ name: 'Label',
+ text: 'Heavy',
+ fontSize: 13,
+ fontWeight: 500,
+ fills: [solid(GRAY_500)]
+ })
+
+ const shadowCard4 = store.createShape('FRAME', 596, 76, 160, 100, effectsSectionId)
+ graph.updateNode(shadowCard4, {
+ name: 'Spread Shadow',
+ cornerRadius: 12,
+ fills: [solid(WHITE)],
+ effects: [dropShadow(0, 4, 12, 8, { r: 0.23, g: 0.51, b: 0.96, a: 0.3 })]
+ })
+ const s4Text = store.createShape('TEXT', 16, 40, 128, 20, shadowCard4)
+ graph.updateNode(s4Text, {
+ name: 'Label',
+ text: 'With Spread',
+ fontSize: 13,
+ fontWeight: 500,
+ fills: [solid(BLUE)]
+ })
+
+ // Row 2: Inner shadows
+ const innerLabel = store.createShape('TEXT', 32, 208, 200, 20, effectsSectionId)
+ graph.updateNode(innerLabel, {
+ name: 'Label',
+ text: 'Inner Shadow',
+ fontSize: 13,
+ fontWeight: 600,
+ fills: [solid(GRAY_500)]
+ })
+
+ const innerCard1 = store.createShape('FRAME', 32, 236, 160, 100, effectsSectionId)
+ graph.updateNode(innerCard1, {
+ name: 'Inset Light',
+ cornerRadius: 12,
+ fills: [solid(GRAY_100)],
+ effects: [innerShadow(0, 2, 6, 0, { r: 0, g: 0, b: 0, a: 0.12 })]
+ })
+ const i1Text = store.createShape('TEXT', 16, 40, 128, 20, innerCard1)
+ graph.updateNode(i1Text, {
+ name: 'Label',
+ text: 'Inset',
+ fontSize: 13,
+ fontWeight: 500,
+ fills: [solid(GRAY_500)]
+ })
+
+ const innerCard2 = store.createShape('FRAME', 220, 236, 160, 100, effectsSectionId)
+ graph.updateNode(innerCard2, {
+ name: 'Inset with Spread',
+ cornerRadius: 12,
+ fills: [solid(GRAY_100)],
+ effects: [innerShadow(0, 2, 8, 4, { r: 0, g: 0, b: 0, a: 0.15 })]
+ })
+ const i2Text = store.createShape('TEXT', 16, 40, 128, 20, innerCard2)
+ graph.updateNode(i2Text, {
+ name: 'Label',
+ text: 'Inset + Spread',
+ fontSize: 13,
+ fontWeight: 500,
+ fills: [solid(GRAY_500)]
+ })
+
+ // Ellipse with inner shadow
+ const innerEllipse = store.createShape('ELLIPSE', 408, 236, 100, 100, effectsSectionId)
+ graph.updateNode(innerEllipse, {
+ name: 'Inset Circle',
+ fills: [
+ gradient([
+ { color: { r: 0.93, g: 0.94, b: 1, a: 1 }, position: 0 },
+ { color: { r: 0.85, g: 0.86, b: 0.95, a: 1 }, position: 1 }
+ ])
+ ],
+ effects: [innerShadow(0, 4, 12, 0, { r: 0.38, g: 0.35, b: 0.95, a: 0.3 })]
+ })
+
+ // Combined drop + inner shadow
+ const comboCard = store.createShape('FRAME', 536, 236, 160, 100, effectsSectionId)
+ graph.updateNode(comboCard, {
+ name: 'Combined',
+ cornerRadius: 12,
+ fills: [solid(WHITE)],
+ effects: [
+ dropShadow(0, 4, 16, 0, { r: 0, g: 0, b: 0, a: 0.12 }),
+ innerShadow(0, 1, 2, 0, { r: 0, g: 0, b: 0, a: 0.06 })
+ ]
+ })
+ const comboText = store.createShape('TEXT', 16, 40, 128, 20, comboCard)
+ graph.updateNode(comboText, {
+ name: 'Label',
+ text: 'Drop + Inner',
+ fontSize: 13,
+ fontWeight: 500,
+ fills: [solid(GRAY_500)]
+ })
+
+ // Row 3: Text shadows & blurs
+ const textFxLabel = store.createShape('TEXT', 32, 368, 200, 20, effectsSectionId)
+ graph.updateNode(textFxLabel, {
+ name: 'Label',
+ text: 'Text Shadow & Blur',
+ fontSize: 13,
+ fontWeight: 600,
+ fills: [solid(GRAY_500)]
+ })
+
+ // Text with drop shadow (renders on glyphs, not bounding box)
+ const textShadow = store.createShape('TEXT', 32, 400, 200, 36, effectsSectionId)
+ graph.updateNode(textShadow, {
+ name: 'Text Shadow',
+ text: 'Glyph Shadow',
+ fontSize: 28,
+ fontWeight: 700,
+ fills: [solid(BLACK)],
+ effects: [dropShadow(2, 2, 4, 0, { r: 0.23, g: 0.51, b: 0.96, a: 0.5 })]
+ })
+
+ // Text with inner shadow
+ const textInner = store.createShape('TEXT', 260, 400, 200, 36, effectsSectionId)
+ graph.updateNode(textInner, {
+ name: 'Text Inner',
+ text: 'Inner Glow',
+ fontSize: 28,
+ fontWeight: 700,
+ fills: [solid(INDIGO)],
+ effects: [innerShadow(0, -1, 3, 0, { r: 1, g: 1, b: 1, a: 0.6 })]
+ })
+
+ // Layer blur
+ const blurRect = store.createShape('RECTANGLE', 500, 392, 120, 50, effectsSectionId)
+ graph.updateNode(blurRect, {
+ name: 'Layer Blur',
+ cornerRadius: 10,
+ fills: [
+ gradient([
+ { color: PURPLE, position: 0 },
+ { color: BLUE, position: 1 }
+ ])
+ ],
+ effects: [blurEffect('LAYER_BLUR', 4)]
+ })
+
+ // Background blur (glassmorphism card)
+ const glassBg = store.createShape('FRAME', 652, 368, 200, 80, effectsSectionId)
+ graph.updateNode(glassBg, {
+ name: 'Glass Card',
+ cornerRadius: 16,
+ fills: [solid({ r: 1, g: 1, b: 1, a: 0.3 })],
+ strokes: thinStroke({ r: 1, g: 1, b: 1, a: 0.4 }),
+ effects: [blurEffect('BACKGROUND_BLUR', 16)]
+ })
+ const glassText = store.createShape('TEXT', 20, 30, 160, 20, glassBg)
+ graph.updateNode(glassText, {
+ name: 'Label',
+ text: 'Glassmorphism',
+ fontSize: 14,
+ fontWeight: 600,
+ fills: [solid(BLACK)]
+ })
+
// Bind variables to some demo nodes
graph.bindVariable(sidebarId, 'fills/0/color', 'var-bg')
graph.bindVariable(headerId, 'fills/0/color', 'var-bg')
diff --git a/tests/e2e/effects.spec.ts b/tests/e2e/effects.spec.ts
new file mode 100644
index 000000000..90931734e
--- /dev/null
+++ b/tests/e2e/effects.spec.ts
@@ -0,0 +1,311 @@
+import { test, expect, type Page } from '@playwright/test'
+
+import { CanvasHelper } from '../helpers/canvas'
+
+let page: Page
+let canvas: CanvasHelper
+
+test.describe.configure({ mode: 'serial' })
+
+test.beforeAll(async ({ browser }) => {
+ page = await browser.newPage()
+ await page.goto('/?test&no-chrome')
+ canvas = new CanvasHelper(page)
+ await canvas.waitForInit()
+})
+
+test.afterAll(async () => {
+ await page.close()
+})
+
+test.beforeEach(async () => {
+ await canvas.clearCanvas()
+})
+
+async function expectCanvas(name: string) {
+ canvas.assertNoErrors()
+ const buffer = await canvas.canvas.screenshot()
+ expect(buffer).toMatchSnapshot(`${name}.png`)
+}
+
+test('drop shadow on white card', async () => {
+ await page.evaluate(() => {
+ const store = window.__OPEN_PENCIL_STORE__!
+ const pageId = store.state.currentPageId
+ store.graph.createNode('FRAME', pageId, {
+ name: 'Card',
+ x: 80,
+ y: 80,
+ width: 200,
+ height: 120,
+ cornerRadius: 12,
+ fills: [{ type: 'SOLID', color: { r: 1, g: 1, b: 1, a: 1 }, visible: true, opacity: 1 }],
+ effects: [
+ {
+ type: 'DROP_SHADOW',
+ color: { r: 0, g: 0, b: 0, a: 0.25 },
+ offset: { x: 0, y: 4 },
+ radius: 16,
+ spread: 0,
+ visible: true
+ }
+ ]
+ })
+ store.clearSelection()
+ store.requestRender()
+ })
+ await canvas.waitForRender()
+ await expectCanvas('drop-shadow-white-card')
+})
+
+test('drop shadow with spread', async () => {
+ await page.evaluate(() => {
+ const store = window.__OPEN_PENCIL_STORE__!
+ const pageId = store.state.currentPageId
+ store.graph.createNode('FRAME', pageId, {
+ name: 'Card',
+ x: 80,
+ y: 80,
+ width: 200,
+ height: 120,
+ cornerRadius: 12,
+ fills: [{ type: 'SOLID', color: { r: 1, g: 1, b: 1, a: 1 }, visible: true, opacity: 1 }],
+ effects: [
+ {
+ type: 'DROP_SHADOW',
+ color: { r: 0.23, g: 0.51, b: 0.96, a: 0.3 },
+ offset: { x: 0, y: 4 },
+ radius: 12,
+ spread: 8,
+ visible: true
+ }
+ ]
+ })
+ store.clearSelection()
+ store.requestRender()
+ })
+ await canvas.waitForRender()
+ await expectCanvas('drop-shadow-with-spread')
+})
+
+test('inner shadow', async () => {
+ await page.evaluate(() => {
+ const store = window.__OPEN_PENCIL_STORE__!
+ const pageId = store.state.currentPageId
+ store.graph.createNode('FRAME', pageId, {
+ name: 'Card',
+ x: 80,
+ y: 80,
+ width: 200,
+ height: 120,
+ cornerRadius: 12,
+ fills: [{ type: 'SOLID', color: { r: 0.96, g: 0.96, b: 0.97, a: 1 }, visible: true, opacity: 1 }],
+ effects: [
+ {
+ type: 'INNER_SHADOW',
+ color: { r: 0, g: 0, b: 0, a: 0.15 },
+ offset: { x: 0, y: 2 },
+ radius: 8,
+ spread: 0,
+ visible: true
+ }
+ ]
+ })
+ store.clearSelection()
+ store.requestRender()
+ })
+ await canvas.waitForRender()
+ await expectCanvas('inner-shadow')
+})
+
+test('inner shadow with spread', async () => {
+ await page.evaluate(() => {
+ const store = window.__OPEN_PENCIL_STORE__!
+ const pageId = store.state.currentPageId
+ store.graph.createNode('FRAME', pageId, {
+ name: 'Card',
+ x: 80,
+ y: 80,
+ width: 200,
+ height: 120,
+ cornerRadius: 12,
+ fills: [{ type: 'SOLID', color: { r: 0.96, g: 0.96, b: 0.97, a: 1 }, visible: true, opacity: 1 }],
+ effects: [
+ {
+ type: 'INNER_SHADOW',
+ color: { r: 0, g: 0, b: 0, a: 0.2 },
+ offset: { x: 0, y: 2 },
+ radius: 8,
+ spread: 4,
+ visible: true
+ }
+ ]
+ })
+ store.clearSelection()
+ store.requestRender()
+ })
+ await canvas.waitForRender()
+ await expectCanvas('inner-shadow-with-spread')
+})
+
+test('drop shadow on ellipse', async () => {
+ await page.evaluate(() => {
+ const store = window.__OPEN_PENCIL_STORE__!
+ const pageId = store.state.currentPageId
+ store.graph.createNode('ELLIPSE', pageId, {
+ name: 'Circle',
+ x: 100,
+ y: 80,
+ width: 160,
+ height: 160,
+ fills: [{ type: 'SOLID', color: { r: 0.38, g: 0.35, b: 0.95, a: 1 }, visible: true, opacity: 1 }],
+ effects: [
+ {
+ type: 'DROP_SHADOW',
+ color: { r: 0, g: 0, b: 0, a: 0.3 },
+ offset: { x: 0, y: 6 },
+ radius: 20,
+ spread: 0,
+ visible: true
+ }
+ ]
+ })
+ store.clearSelection()
+ store.requestRender()
+ })
+ await canvas.waitForRender()
+ await expectCanvas('drop-shadow-ellipse')
+})
+
+test('combined drop and inner shadow', async () => {
+ await page.evaluate(() => {
+ const store = window.__OPEN_PENCIL_STORE__!
+ const pageId = store.state.currentPageId
+ store.graph.createNode('FRAME', pageId, {
+ name: 'Card',
+ x: 80,
+ y: 80,
+ width: 200,
+ height: 120,
+ cornerRadius: 12,
+ fills: [{ type: 'SOLID', color: { r: 1, g: 1, b: 1, a: 1 }, visible: true, opacity: 1 }],
+ effects: [
+ {
+ type: 'DROP_SHADOW',
+ color: { r: 0, g: 0, b: 0, a: 0.15 },
+ offset: { x: 0, y: 4 },
+ radius: 16,
+ spread: 0,
+ visible: true
+ },
+ {
+ type: 'INNER_SHADOW',
+ color: { r: 0, g: 0, b: 0, a: 0.08 },
+ offset: { x: 0, y: 1 },
+ radius: 2,
+ spread: 0,
+ visible: true
+ }
+ ]
+ })
+ store.clearSelection()
+ store.requestRender()
+ })
+ await canvas.waitForRender()
+ await expectCanvas('combined-drop-inner-shadow')
+})
+
+test('text drop shadow on glyphs', async () => {
+ await page.evaluate(() => {
+ const store = window.__OPEN_PENCIL_STORE__!
+ const pageId = store.state.currentPageId
+ store.graph.createNode('TEXT', pageId, {
+ name: 'Shadow Text',
+ x: 60,
+ y: 120,
+ width: 300,
+ height: 50,
+ text: 'Shadow',
+ fontSize: 40,
+ fontWeight: 700,
+ fontFamily: 'Inter',
+ fills: [{ type: 'SOLID', color: { r: 0, g: 0, b: 0, a: 1 }, visible: true, opacity: 1 }],
+ effects: [
+ {
+ type: 'DROP_SHADOW',
+ color: { r: 0.23, g: 0.51, b: 0.96, a: 0.6 },
+ offset: { x: 3, y: 3 },
+ radius: 6,
+ spread: 0,
+ visible: true
+ }
+ ]
+ })
+ store.clearSelection()
+ store.requestRender()
+ })
+ await canvas.waitForRender()
+ await page.waitForTimeout(500)
+ await canvas.waitForRender()
+ await expectCanvas('text-drop-shadow')
+})
+
+test('layer blur', async () => {
+ await page.evaluate(() => {
+ const store = window.__OPEN_PENCIL_STORE__!
+ const pageId = store.state.currentPageId
+ store.graph.createNode('RECTANGLE', pageId, {
+ name: 'Blurred',
+ x: 80,
+ y: 80,
+ width: 200,
+ height: 120,
+ cornerRadius: 12,
+ fills: [{ type: 'SOLID', color: { r: 0.23, g: 0.51, b: 0.96, a: 1 }, visible: true, opacity: 1 }],
+ effects: [
+ {
+ type: 'LAYER_BLUR',
+ color: { r: 0, g: 0, b: 0, a: 0 },
+ offset: { x: 0, y: 0 },
+ radius: 8,
+ spread: 0,
+ visible: true
+ }
+ ]
+ })
+ store.clearSelection()
+ store.requestRender()
+ })
+ await canvas.waitForRender()
+ await expectCanvas('layer-blur')
+})
+
+test('invisible effect has no visual impact', async () => {
+ await page.evaluate(() => {
+ const store = window.__OPEN_PENCIL_STORE__!
+ const pageId = store.state.currentPageId
+ store.graph.createNode('FRAME', pageId, {
+ name: 'Card',
+ x: 80,
+ y: 80,
+ width: 200,
+ height: 120,
+ cornerRadius: 12,
+ fills: [{ type: 'SOLID', color: { r: 1, g: 1, b: 1, a: 1 }, visible: true, opacity: 1 }],
+ effects: [
+ {
+ type: 'DROP_SHADOW',
+ color: { r: 0, g: 0, b: 0, a: 0.5 },
+ offset: { x: 0, y: 8 },
+ radius: 24,
+ spread: 0,
+ visible: false
+ }
+ ]
+ })
+ store.clearSelection()
+ store.requestRender()
+ })
+ await canvas.waitForRender()
+ await expectCanvas('invisible-effect')
+})
diff --git a/tests/e2e/effects.spec.ts-snapshots/combined-drop-inner-shadow-openpencil-darwin.png b/tests/e2e/effects.spec.ts-snapshots/combined-drop-inner-shadow-openpencil-darwin.png
new file mode 100644
index 000000000..c038942c8
Binary files /dev/null and b/tests/e2e/effects.spec.ts-snapshots/combined-drop-inner-shadow-openpencil-darwin.png differ
diff --git a/tests/e2e/effects.spec.ts-snapshots/drop-shadow-ellipse-openpencil-darwin.png b/tests/e2e/effects.spec.ts-snapshots/drop-shadow-ellipse-openpencil-darwin.png
new file mode 100644
index 000000000..e2314b8eb
Binary files /dev/null and b/tests/e2e/effects.spec.ts-snapshots/drop-shadow-ellipse-openpencil-darwin.png differ
diff --git a/tests/e2e/effects.spec.ts-snapshots/drop-shadow-white-card-openpencil-darwin.png b/tests/e2e/effects.spec.ts-snapshots/drop-shadow-white-card-openpencil-darwin.png
new file mode 100644
index 000000000..c7dfcbbeb
Binary files /dev/null and b/tests/e2e/effects.spec.ts-snapshots/drop-shadow-white-card-openpencil-darwin.png differ
diff --git a/tests/e2e/effects.spec.ts-snapshots/drop-shadow-with-spread-openpencil-darwin.png b/tests/e2e/effects.spec.ts-snapshots/drop-shadow-with-spread-openpencil-darwin.png
new file mode 100644
index 000000000..e8f2c8d15
Binary files /dev/null and b/tests/e2e/effects.spec.ts-snapshots/drop-shadow-with-spread-openpencil-darwin.png differ
diff --git a/tests/e2e/effects.spec.ts-snapshots/inner-shadow-openpencil-darwin.png b/tests/e2e/effects.spec.ts-snapshots/inner-shadow-openpencil-darwin.png
new file mode 100644
index 000000000..e080f8881
Binary files /dev/null and b/tests/e2e/effects.spec.ts-snapshots/inner-shadow-openpencil-darwin.png differ
diff --git a/tests/e2e/effects.spec.ts-snapshots/inner-shadow-with-spread-openpencil-darwin.png b/tests/e2e/effects.spec.ts-snapshots/inner-shadow-with-spread-openpencil-darwin.png
new file mode 100644
index 000000000..c2022a0ae
Binary files /dev/null and b/tests/e2e/effects.spec.ts-snapshots/inner-shadow-with-spread-openpencil-darwin.png differ
diff --git a/tests/e2e/effects.spec.ts-snapshots/invisible-effect-openpencil-darwin.png b/tests/e2e/effects.spec.ts-snapshots/invisible-effect-openpencil-darwin.png
new file mode 100644
index 000000000..51f94f481
Binary files /dev/null and b/tests/e2e/effects.spec.ts-snapshots/invisible-effect-openpencil-darwin.png differ
diff --git a/tests/e2e/effects.spec.ts-snapshots/layer-blur-openpencil-darwin.png b/tests/e2e/effects.spec.ts-snapshots/layer-blur-openpencil-darwin.png
new file mode 100644
index 000000000..f3523f2ec
Binary files /dev/null and b/tests/e2e/effects.spec.ts-snapshots/layer-blur-openpencil-darwin.png differ
diff --git a/tests/e2e/effects.spec.ts-snapshots/text-drop-shadow-openpencil-darwin.png b/tests/e2e/effects.spec.ts-snapshots/text-drop-shadow-openpencil-darwin.png
new file mode 100644
index 000000000..102bbdc2d
Binary files /dev/null and b/tests/e2e/effects.spec.ts-snapshots/text-drop-shadow-openpencil-darwin.png differ
diff --git a/tests/engine/effects-and-resize.test.ts b/tests/engine/effects-and-resize.test.ts
new file mode 100644
index 000000000..30c4ef834
--- /dev/null
+++ b/tests/engine/effects-and-resize.test.ts
@@ -0,0 +1,387 @@
+import { describe, test, expect } from 'bun:test'
+
+import { SceneGraph, type Effect } from '@open-pencil/core'
+
+function pageId(graph: SceneGraph) {
+ return graph.getPages()[0].id
+}
+
+function makeEffect(overrides: Partial<Effect> = {}): Effect {
+ return {
+ type: 'DROP_SHADOW',
+ color: { r: 0, g: 0, b: 0, a: 0.25 },
+ offset: { x: 0, y: 4 },
+ radius: 4,
+ spread: 0,
+ visible: true,
+ ...overrides
+ }
+}
+
+describe('Effect types on scene graph', () => {
+ test('drop shadow with spread value', () => {
+ const graph = new SceneGraph()
+ const node = graph.createNode('RECTANGLE', pageId(graph), {
+ name: 'Card',
+ width: 200,
+ height: 100
+ })
+ graph.updateNode(node.id, {
+ effects: [makeEffect({ spread: 10 })]
+ })
+ const updated = graph.getNode(node.id)!
+ expect(updated.effects[0].spread).toBe(10)
+ })
+
+ test('inner shadow with spread value', () => {
+ const graph = new SceneGraph()
+ const node = graph.createNode('RECTANGLE', pageId(graph), {
+ name: 'Card',
+ width: 200,
+ height: 100
+ })
+ graph.updateNode(node.id, {
+ effects: [makeEffect({ type: 'INNER_SHADOW', spread: 5 })]
+ })
+ const updated = graph.getNode(node.id)!
+ expect(updated.effects[0].type).toBe('INNER_SHADOW')
+ expect(updated.effects[0].spread).toBe(5)
+ })
+
+ test('background blur effect', () => {
+ const graph = new SceneGraph()
+ const node = graph.createNode('FRAME', pageId(graph), {
+ name: 'GlassCard',
+ width: 300,
+ height: 200
+ })
+ graph.updateNode(node.id, {
+ effects: [makeEffect({ type: 'BACKGROUND_BLUR', radius: 20 })]
+ })
+ const updated = graph.getNode(node.id)!
+ expect(updated.effects[0].type).toBe('BACKGROUND_BLUR')
+ expect(updated.effects[0].radius).toBe(20)
+ })
+
+ test('foreground blur effect', () => {
+ const graph = new SceneGraph()
+ const node = graph.createNode('FRAME', pageId(graph), {
+ name: 'FrostedOverlay',
+ width: 300,
+ height: 200
+ })
+ graph.updateNode(node.id, {
+ effects: [makeEffect({ type: 'FOREGROUND_BLUR', radius: 8 })]
+ })
+ const updated = graph.getNode(node.id)!
+ expect(updated.effects[0].type).toBe('FOREGROUND_BLUR')
+ expect(updated.effects[0].radius).toBe(8)
+ })
+
+ test('layer blur effect', () => {
+ const graph = new SceneGraph()
+ const node = graph.createNode('RECTANGLE', pageId(graph), {
+ name: 'Blurred',
+ width: 100,
+ height: 100
+ })
+ graph.updateNode(node.id, {
+ effects: [makeEffect({ type: 'LAYER_BLUR', radius: 12 })]
+ })
+ const updated = graph.getNode(node.id)!
+ expect(updated.effects[0].type).toBe('LAYER_BLUR')
+ expect(updated.effects[0].radius).toBe(12)
+ })
+
+ test('text node with drop shadow', () => {
+ const graph = new SceneGraph()
+ const node = graph.createNode('TEXT', pageId(graph), {
+ name: 'ShadowedText',
+ width: 200,
+ height: 50,
+ text: 'Hello'
+ })
+ graph.updateNode(node.id, {
+ effects: [makeEffect({ type: 'DROP_SHADOW', radius: 4, offset: { x: 2, y: 2 } })]
+ })
+ const updated = graph.getNode(node.id)!
+ expect(updated.type).toBe('TEXT')
+ expect(updated.effects[0].type).toBe('DROP_SHADOW')
+ })
+
+ test('text node with inner shadow', () => {
+ const graph = new SceneGraph()
+ const node = graph.createNode('TEXT', pageId(graph), {
+ name: 'InnerShadowText',
+ width: 200,
+ height: 50,
+ text: 'Hello'
+ })
+ graph.updateNode(node.id, {
+ effects: [makeEffect({ type: 'INNER_SHADOW', radius: 2, offset: { x: 1, y: 1 } })]
+ })
+ const updated = graph.getNode(node.id)!
+ expect(updated.type).toBe('TEXT')
+ expect(updated.effects[0].type).toBe('INNER_SHADOW')
+ })
+
+ test('multiple effects on single node', () => {
+ const graph = new SceneGraph()
+ const node = graph.createNode('FRAME', pageId(graph), {
+ name: 'MultiEffect',
+ width: 300,
+ height: 200
+ })
+ graph.updateNode(node.id, {
+ effects: [
+ makeEffect({ type: 'DROP_SHADOW', radius: 8, spread: 2 }),
+ makeEffect({ type: 'INNER_SHADOW', radius: 4, spread: 1 }),
+ makeEffect({ type: 'BACKGROUND_BLUR', radius: 16 }),
+ makeEffect({ type: 'LAYER_BLUR', radius: 4 })
+ ]
+ })
+ const updated = graph.getNode(node.id)!
+ expect(updated.effects).toHaveLength(4)
+ expect(updated.effects.map((e) => e.type)).toEqual([
+ 'DROP_SHADOW',
+ 'INNER_SHADOW',
+ 'BACKGROUND_BLUR',
+ 'LAYER_BLUR'
+ ])
+ })
+
+ test('invisible effect is preserved', () => {
+ const graph = new SceneGraph()
+ const node = graph.createNode('RECTANGLE', pageId(graph), {
+ name: 'Hidden',
+ width: 100,
+ height: 100
+ })
+ graph.updateNode(node.id, {
+ effects: [makeEffect({ visible: false })]
+ })
+ expect(graph.getNode(node.id)!.effects[0].visible).toBe(false)
+ })
+
+ test('drop shadow with negative spread (inset shrink)', () => {
+ const graph = new SceneGraph()
+ const node = graph.createNode('RECTANGLE', pageId(graph), {
+ name: 'ShrunkShadow',
+ width: 100,
+ height: 100
+ })
+ graph.updateNode(node.id, {
+ effects: [makeEffect({ spread: -5 })]
+ })
+ expect(graph.getNode(node.id)!.effects[0].spread).toBe(-5)
+ })
+})
+
+describe('Resize logic', () => {
+ function applyResize(
+ handle: string,
+ origRect: { x: number; y: number; width: number; height: number },
+ startX: number,
+ startY: number,
+ cx: number,
+ cy: number,
+ constrain = false
+ ) {
+ let { x, y, width, height } = origRect
+ const dx = cx - startX
+ const dy = cy - startY
+
+ const moveLeft = handle.includes('w')
+ const moveRight = handle.includes('e')
+ const moveTop = handle === 'nw' || handle === 'n' || handle === 'ne'
+ const moveBottom = handle === 'sw' || handle === 's' || handle === 'se'
+
+ if (moveRight) width = origRect.width + dx
+ if (moveLeft) {
+ x = origRect.x + dx
+ width = origRect.width - dx
+ }
+ if (moveBottom) height = origRect.height + dy
+ if (moveTop) {
+ y = origRect.y + dy
+ height = origRect.height - dy
+ }
+
+ if (constrain && origRect.width > 0 && origRect.height > 0) {
+ const aspect = origRect.width / origRect.height
+ if (handle === 'n' || handle === 's') {
+ width = Math.abs(height) * aspect
+ x = origRect.x + (origRect.width - width) / 2
+ } else if (handle === 'e' || handle === 'w') {
+ height = Math.abs(width) / aspect
+ y = origRect.y + (origRect.height - height) / 2
+ } else {
+ if (Math.abs(dx) > Math.abs(dy)) {
+ height = (Math.abs(width) / aspect) * Math.sign(height || 1)
+ if (moveTop) y = origRect.y + origRect.height - Math.abs(height)
+ } else {
+ width = Math.abs(height) * aspect * Math.sign(width || 1)
+ if (moveLeft) x = origRect.x + origRect.width - Math.abs(width)
+ }
+ }
+ }
+
+ if (width < 0) {
+ x = x + width
+ width = -width
+ }
+ if (height < 0) {
+ y = y + height
+ height = -height
+ }
+
+ return {
+ x: Math.round(x),
+ y: Math.round(y),
+ width: Math.round(Math.max(1, width)),
+ height: Math.round(Math.max(1, height))
+ }
+ }
+
+ const orig = { x: 100, y: 100, width: 200, height: 100 }
+
+ test('east handle: grow right', () => {
+ const result = applyResize('e', orig, 300, 150, 350, 150)
+ expect(result).toEqual({ x: 100, y: 100, width: 250, height: 100 })
+ })
+
+ test('east handle: shrink right', () => {
+ const result = applyResize('e', orig, 300, 150, 250, 150)
+ expect(result).toEqual({ x: 100, y: 100, width: 150, height: 100 })
+ })
+
+ test('east handle: drag past opposite bound', () => {
+ const result = applyResize('e', orig, 300, 150, 50, 150)
+ expect(result.x).toBe(50)
+ expect(result.width).toBe(50)
+ expect(result.y).toBe(100)
+ expect(result.height).toBe(100)
+ })
+
+ test('west handle: grow left', () => {
+ const result = applyResize('w', orig, 100, 150, 50, 150)
+ expect(result).toEqual({ x: 50, y: 100, width: 250, height: 100 })
+ })
+
+ test('west handle: shrink left', () => {
+ const result = applyResize('w', orig, 100, 150, 150, 150)
+ expect(result).toEqual({ x: 150, y: 100, width: 150, height: 100 })
+ })
+
+ test('west handle: drag past opposite bound', () => {
+ const result = applyResize('w', orig, 100, 150, 350, 150)
+ expect(result.width).toBe(50)
+ expect(result.x).toBe(300)
+ })
+
+ test('north handle: grow up', () => {
+ const result = applyResize('n', orig, 200, 100, 200, 50)
+ expect(result).toEqual({ x: 100, y: 50, width: 200, height: 150 })
+ })
+
+ test('north handle: shrink up', () => {
+ const result = applyResize('n', orig, 200, 100, 200, 150)
+ expect(result).toEqual({ x: 100, y: 150, width: 200, height: 50 })
+ })
+
+ test('north handle: drag past opposite bound', () => {
+ const result = applyResize('n', orig, 200, 100, 200, 250)
+ expect(result.height).toBe(50)
+ expect(result.y).toBe(200)
+ })
+
+ test('south handle: grow down', () => {
+ const result = applyResize('s', orig, 200, 200, 200, 250)
+ expect(result).toEqual({ x: 100, y: 100, width: 200, height: 150 })
+ })
+
+ test('south handle: drag past opposite bound', () => {
+ const result = applyResize('s', orig, 200, 200, 200, 50)
+ expect(result.height).toBe(50)
+ expect(result.y).toBe(50)
+ })
+
+ test('nw handle: grow both axes', () => {
+ const result = applyResize('nw', orig, 100, 100, 50, 50)
+ expect(result).toEqual({ x: 50, y: 50, width: 250, height: 150 })
+ })
+
+ test('nw handle: shrink both axes', () => {
+ const result = applyResize('nw', orig, 100, 100, 200, 150)
+ expect(result).toEqual({ x: 200, y: 150, width: 100, height: 50 })
+ })
+
+ test('nw handle: drag past opposite corner', () => {
+ const result = applyResize('nw', orig, 100, 100, 350, 250)
+ expect(result.x).toBe(300)
+ expect(result.y).toBe(200)
+ expect(result.width).toBe(50)
+ expect(result.height).toBe(50)
+ })
+
+ test('se handle: grow both axes', () => {
+ const result = applyResize('se', orig, 300, 200, 350, 250)
+ expect(result).toEqual({ x: 100, y: 100, width: 250, height: 150 })
+ })
+
+ test('se handle: drag past opposite corner', () => {
+ const result = applyResize('se', orig, 300, 200, 50, 50)
+ expect(result.x).toBe(50)
+ expect(result.y).toBe(50)
+ expect(result.width).toBe(50)
+ expect(result.height).toBe(50)
+ })
+
+ test('ne handle: grow right and up', () => {
+ const result = applyResize('ne', orig, 300, 100, 350, 50)
+ expect(result).toEqual({ x: 100, y: 50, width: 250, height: 150 })
+ })
+
+ test('sw handle: grow left and down', () => {
+ const result = applyResize('sw', orig, 100, 200, 50, 250)
+ expect(result).toEqual({ x: 50, y: 100, width: 250, height: 150 })
+ })
+
+ test('opposite edge stays fixed when resizing left', () => {
+ const result = applyResize('w', orig, 100, 150, 50, 150)
+ expect(result.x + result.width).toBe(300)
+ })
+
+ test('opposite edge stays fixed when resizing top', () => {
+ const result = applyResize('n', orig, 200, 100, 200, 50)
+ expect(result.y + result.height).toBe(200)
+ })
+
+ test('opposite edge stays fixed when resizing nw', () => {
+ const result = applyResize('nw', orig, 100, 100, 50, 50)
+ expect(result.x + result.width).toBe(300)
+ expect(result.y + result.height).toBe(200)
+ })
+
+ test('width never goes below 1', () => {
+ const result = applyResize('e', orig, 300, 150, 100, 150)
+ expect(result.width).toBeGreaterThanOrEqual(1)
+ })
+
+ test('height never goes below 1', () => {
+ const result = applyResize('s', orig, 200, 200, 200, 100)
+ expect(result.height).toBeGreaterThanOrEqual(1)
+ })
+
+ test('constrained se preserves aspect ratio', () => {
+ const result = applyResize('se', orig, 300, 200, 400, 200, true)
+ const aspect = result.width / result.height
+ expect(Math.abs(aspect - 2)).toBeLessThan(0.01)
+ })
+
+ test('constrained nw preserves aspect ratio', () => {
+ const result = applyResize('nw', orig, 100, 100, 0, 100, true)
+ const aspect = result.width / result.height
+ expect(Math.abs(aspect - 2)).toBeLessThan(0.01)
+ })
+})
diff --git a/tests/engine/renderer-effects.test.ts b/tests/engine/renderer-effects.test.ts
new file mode 100644
index 000000000..0ba157a3a
--- /dev/null
+++ b/tests/engine/renderer-effects.test.ts
@@ -0,0 +1,120 @@
+import { describe, test, expect } from 'bun:test'
+
+const rendererSource = await Bun.file(
+ new URL('../../packages/core/src/renderer.ts', import.meta.url)
+).text()
+
+describe('Renderer effect ordering', () => {
+ test('drop shadow renders before fills', () => {
+ // In renderShape, "Effects (behind: drop shadow)" must come before "Fills"
+ const behindIdx = rendererSource.indexOf("renderEffects(canvas, node, rect, hasRadius, 'behind')")
+ const fillsIdx = rendererSource.indexOf('this.drawNodeFill(canvas, node, rect, hasRadius)')
+ expect(behindIdx).toBeGreaterThan(-1)
+ expect(fillsIdx).toBeGreaterThan(-1)
+ expect(behindIdx).toBeLessThan(fillsIdx)
+ })
+
+ test('inner shadow and blur render after strokes', () => {
+ const strokeIdx = rendererSource.indexOf('this.drawNodeStroke(canvas, node, rect, hasRadius)')
+ const frontIdx = rendererSource.indexOf("renderEffects(canvas, node, rect, hasRadius, 'front')")
+ expect(strokeIdx).toBeGreaterThan(-1)
+ expect(frontIdx).toBeGreaterThan(-1)
+ expect(strokeIdx).toBeLessThan(frontIdx)
+ })
+})
+
+describe('Renderer handles all effect types', () => {
+ test('handles DROP_SHADOW', () => {
+ expect(rendererSource).toContain("effect.type === 'DROP_SHADOW'")
+ })
+
+ test('handles INNER_SHADOW', () => {
+ expect(rendererSource).toContain("effect.type === 'INNER_SHADOW'")
+ })
+
+ test('handles LAYER_BLUR', () => {
+ expect(rendererSource).toContain("e.type === 'LAYER_BLUR'")
+ })
+
+ test('handles BACKGROUND_BLUR', () => {
+ expect(rendererSource).toContain("effect.type === 'BACKGROUND_BLUR'")
+ })
+
+ test('handles FOREGROUND_BLUR', () => {
+ expect(rendererSource).toContain("effect.type === 'FOREGROUND_BLUR'")
+ })
+})
+
+describe('Shadow spread support', () => {
+ test('drop shadow uses spread for shape expansion', () => {
+ const dropShadowSection = rendererSource.slice(
+ rendererSource.indexOf("effect.type === 'DROP_SHADOW'"),
+ rendererSource.indexOf("effect.type === 'DROP_SHADOW'") + 2000
+ )
+ expect(dropShadowSection).toContain('effect.spread')
+ expect(dropShadowSection).toContain('makeRRectWithSpread')
+ expect(dropShadowSection).toContain('MakeDropShadowOnly')
+ })
+
+ test('inner shadow uses spread for cutout contraction', () => {
+ const innerShadowSection = rendererSource.slice(
+ rendererSource.indexOf("effect.type === 'INNER_SHADOW'"),
+ rendererSource.indexOf("effect.type === 'INNER_SHADOW'") + 3000
+ )
+ expect(innerShadowSection).toContain('effect.spread')
+ })
+
+ test('makeRRectWithSpread helper exists', () => {
+ expect(rendererSource).toContain('private makeRRectWithSpread')
+ })
+
+ test('makeRRectWithOffset helper exists', () => {
+ expect(rendererSource).toContain('private makeRRectWithOffset')
+ })
+})
+
+describe('Text shadow renders on glyphs, not bounding box', () => {
+ test('drop shadow has TEXT-specific branch', () => {
+ const dropShadowBlock = rendererSource.slice(
+ rendererSource.indexOf("effect.type === 'DROP_SHADOW'"),
+ rendererSource.indexOf("effect.type === 'DROP_SHADOW'") + 2000
+ )
+ expect(dropShadowBlock).toContain("node.type === 'TEXT'")
+ expect(dropShadowBlock).toContain('renderText')
+ expect(dropShadowBlock).toContain('MakeDropShadowOnly')
+ })
+
+ test('inner shadow has TEXT-specific branch', () => {
+ const innerShadowBlock = rendererSource.slice(
+ rendererSource.indexOf("effect.type === 'INNER_SHADOW'"),
+ rendererSource.indexOf("effect.type === 'INNER_SHADOW'") + 1500
+ )
+ expect(innerShadowBlock).toContain("node.type === 'TEXT'")
+ expect(innerShadowBlock).toContain('renderText')
+ })
+})
+
+describe('Blur effects use saveLayer pattern', () => {
+ test('layer blur wraps node content in a blurred saveLayer', () => {
+ expect(rendererSource).toContain("e.type === 'LAYER_BLUR'")
+ // Applied at the renderNode level, not in renderEffects
+ const layerBlurIdx = rendererSource.indexOf("e.type === 'LAYER_BLUR'")
+ const layerBlurSection = rendererSource.slice(layerBlurIdx - 200, layerBlurIdx + 300)
+ expect(layerBlurSection).toContain('MakeBlur')
+ expect(layerBlurSection).toContain('saveLayer')
+ })
+
+ test('background and foreground blur use applyClippedBlur', () => {
+ expect(rendererSource).toContain("effect.type === 'BACKGROUND_BLUR'")
+ expect(rendererSource).toContain("effect.type === 'FOREGROUND_BLUR'")
+ expect(rendererSource).toContain('applyClippedBlur')
+ })
+
+ test('applyClippedBlur clips to node shape and uses saveLayer', () => {
+ const idx = rendererSource.indexOf('private applyClippedBlur')
+ const section = rendererSource.slice(idx, idx + 500)
+ expect(section).toContain('clipNodeShape')
+ expect(section).toContain('MakeBlur')
+ expect(section).toContain('saveLayer')
+ })
+})