Skip to content

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

feat(canvas): round rectangle corners with on-canvas radius handles (#1043)

Danila Poyarkovc0204b2871fb
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9d7ce591b..2359e0612 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -40,10 +40,12 @@
- `buildDerivedTextDataV4` is removed from `@open-pencil/core`, and `sceneNodeToKiwi` no longer writes glyph outlines by itself: pass the `runtime` that `withFigExportRuntime(graph, canvasKit, write)` hands its callback. In `@open-pencil/fig/node-change`, `FigNodeChangeExportRuntime` takes `shapeText(node)` instead of `getGlyphOutlineMetrics`, `buildDerivedTextData` takes the `baselines` it writes, and `convertFigmaDerivedTextGlyphs` takes the text's characters.
- The `updates` messages from `@open-pencil/vue` no longer include `availableTitle`, `installPrompt`, `installedTitle`, and `downloading`, which only the system update dialogs and download toast used; `installed` now takes only `{ version }`, and `install` reads "Install Update". The Software Update window uses the new `windowTitle`, `currentVersion`, `whatsNew`, `installAndRestart`, `restartNow`, and related messages.
- `fetchIcon`, `fetchIcons`, `searchIcons`, `searchIconsBatch`, and `clearIconCache` are removed from `@open-pencil/core`. Icons come from an `IconProvider` instead: `iconify` is the default Iconify provider, `createIconifyProvider()` makes one with its own cache, and `placeIcon` places an icon that keeps its name. A custom provider also implements `previews()`, `collections()`, and `browse()`, which give pickers each icon's SVG markup, the sets, and a set's icons.
+- The editor's view state has a required `cornerRadiusHover`, the selected rectangle whose corner radius handles the canvas shows; code that creates editor state itself must set it, as `createDefaultEditorViewState` does.
- `defineTool` from `@open-pencil/core/tools` takes its `input` as a `v.strictObject` instead of a `v.object`, and `ToolDef.input` is a strict object schema, so a tool rejects arguments it does not declare.
### Added
+- Round a rectangle's corners on the canvas, as in Figma: while the pointer is over a selected rectangle at least 108 screen pixels across, a handle sits inside each corner. Dragging one sets every corner while they are equal and only that corner while they differ, <kbd>⌥</kbd> swaps the two, and <kbd>⇧</kbd> rounds to tens; a label beside the pointer shows the radius.
- Edit several layers at once as in Figma: the properties panel gives a multi-selection a Layout section with sizes, text resizing, flow, clip content, and a Spacing field that spaces a row or column evenly; Typography for the text among it; corner radius for the layers that have one; the stroke of the layers that have strokes; and Selection colors, which lists every fill and stroke colour in the selection and its children and recolours one everywhere it is used. The panel's header reads "N selected".
- Edit gradients on the canvas, as in Figma: while a fill or stroke gradient's picker is open, the layer shows the gradient's line or ellipse with its end dots and stop squares. Dragging a dot moves it, <kbd>Shift</kbd> turns it in 15° steps, and dragging a square slides its stop; the stop selected on the canvas is the one selected in the picker.
- Paste SVG markup copied as text, such as from a code editor or Figma's Copy as SVG, as layers.
diff --git a/packages/core/src/canvas/overlays/corner-radius.ts b/packages/core/src/canvas/overlays/corner-radius.ts
new file mode 100644
index 000000000..6132bc55f
--- /dev/null
+++ b/packages/core/src/canvas/overlays/corner-radius.ts
@@ -0,0 +1,99 @@
+import type { Canvas } from 'canvaskit-wasm'
+
+import type { SceneGraph } from '@open-pencil/scene-graph'
+
+import type { SkiaRenderer } from '#core/canvas/renderer'
+import {
+ HANDLE_HALF_SIZE,
+ SIZE_FONT_SIZE,
+ SIZE_PILL_HEIGHT,
+ SIZE_PILL_PADDING_X,
+ SIZE_PILL_RADIUS
+} from '#core/constants'
+import type { CornerRadiusHover } from '#core/editor/types'
+import {
+ CORNER_RADIUS_HANDLE,
+ cornerRadiusHandleLayout,
+ cornerRadii,
+ createSceneGeometry,
+ type RotationPreview
+} from '#core/geometry'
+
+/**
+ * The selected rectangle's corner radius handles while the pointer is over it: white circles the
+ * size of the resize handles with a border in the selection colour, dotted when a drag changes one
+ * corner, and a "Radius" label by the pointer for the handle in use, as in Figma desktop.
+ */
+export function drawCornerRadiusHandles(
+ r: SkiaRenderer,
+ canvas: Canvas,
+ graph: SceneGraph,
+ selectedIds: ReadonlySet<string>,
+ hover: CornerRadiusHover | null | undefined,
+ preview?: RotationPreview | null
+): void {
+ if (!hover || selectedIds.size !== 1 || !selectedIds.has(hover.nodeId)) return
+ const node = graph.getNode(hover.nodeId)
+ if (!node) return
+ const handles = cornerRadiusHandleLayout(node, createSceneGeometry(graph, preview), r)
+ if (!handles) return
+ const color = r.outlineColor(node, graph)
+ const fill = r.auxFill
+ const border = r.auxStroke
+ fill.setMaskFilter(null)
+ border.setPathEffect(null)
+ border.setStrokeWidth(1)
+ border.setColor(color)
+ for (const { point } of handles) {
+ fill.setColor(r.ck.WHITE)
+ canvas.drawCircle(point.x, point.y, HANDLE_HALF_SIZE, fill)
+ canvas.drawCircle(point.x, point.y, HANDLE_HALF_SIZE, border)
+ if (!hover.single) continue
+ fill.setColor(color)
+ canvas.drawCircle(point.x, point.y, CORNER_RADIUS_HANDLE.dotRadius, fill)
+ }
+
+ const provider = r.fontProvider
+ if (!hover.corner || !provider) return
+ // A paragraph rather than the size label's single font, so every script has a fallback face.
+ const text = `${hover.label} ${Math.round(cornerRadii(node)[hover.corner])}`
+ const white = r.ck.WHITE
+ const measured = r.labelParagraphCache.measure(
+ r.ck,
+ provider,
+ text,
+ SIZE_FONT_SIZE,
+ Number.POSITIVE_INFINITY,
+ white,
+ r.fontGeneration
+ )
+ const { labelOffset } = CORNER_RADIUS_HANDLE
+ const left = hover.pointer.x + labelOffset.x
+ const top = hover.pointer.y + labelOffset.y - SIZE_PILL_HEIGHT / 2
+ fill.setColor(color)
+ canvas.drawRRect(
+ r.ck.RRectXY(
+ r.ck.LTRBRect(
+ left,
+ top,
+ left + measured.width + SIZE_PILL_PADDING_X * 2,
+ top + SIZE_PILL_HEIGHT
+ ),
+ SIZE_PILL_RADIUS,
+ SIZE_PILL_RADIUS
+ ),
+ fill
+ )
+ r.labelParagraphCache.draw(
+ r.ck,
+ canvas,
+ provider,
+ text,
+ SIZE_FONT_SIZE,
+ Number.POSITIVE_INFINITY,
+ white,
+ r.fontGeneration,
+ left + SIZE_PILL_PADDING_X,
+ top + (SIZE_PILL_HEIGHT - measured.height) / 2
+ )
+}
diff --git a/packages/core/src/canvas/renderer/overlay-pass.ts b/packages/core/src/canvas/renderer/overlay-pass.ts
index ce9b59ee2..d9d52e8a6 100644
--- a/packages/core/src/canvas/renderer/overlay-pass.ts
+++ b/packages/core/src/canvas/renderer/overlay-pass.ts
@@ -6,6 +6,7 @@ import { drawGuides } from '#core/canvas/guides/draw'
import { drawIssueHighlight, drawIssueMarkers } from '#core/canvas/issues/draw'
import { layoutIssueMarkers } from '#core/canvas/issues/layout'
import { drawComponentSetBorders } from '#core/canvas/overlays/component-sets'
+import { drawCornerRadiusHandles } from '#core/canvas/overlays/corner-radius'
import { drawDropTarget, drawEditingText } from '#core/canvas/overlays/feedback'
import { drawGradientHandles } from '#core/canvas/overlays/gradient-handles'
import { drawLayoutOutlines } from '#core/canvas/overlays/layout-outlines'
@@ -118,7 +119,18 @@ export function drawOverlayPass(
// previewing canvas shows neither.
if (!overlays.playing && editedGradient(graph, overlays.gradientEdit))
drawGradientHandles(r, canvas, graph, overlays.gradientEdit, overlays.rotationPreview)
- else r.drawSelection(canvas, graph, selectedIds, overlays)
+ else {
+ r.drawSelection(canvas, graph, selectedIds, overlays)
+ if (!overlays.transforming)
+ drawCornerRadiusHandles(
+ r,
+ canvas,
+ graph,
+ selectedIds,
+ overlays.cornerRadiusHover,
+ overlays.rotationPreview
+ )
+ }
if (measuring) r.drawMeasurements(canvas, graph, selectedIds, overlays.hoveredNodeId)
r.profiler.endPhase('render:selection')
diff --git a/packages/core/src/canvas/renderer/pipeline.ts b/packages/core/src/canvas/renderer/pipeline.ts
index 931e5536d..6e499b4ee 100644
--- a/packages/core/src/canvas/renderer/pipeline.ts
+++ b/packages/core/src/canvas/renderer/pipeline.ts
@@ -109,7 +109,8 @@ export function renderFromEditorState(
presenceCursors: state.presenceCursors,
designIssues: state.designIssues,
codeFocusNodeId: state.codeFocusNodeId,
- autoLayoutHover: state.autoLayoutHover
+ autoLayoutHover: state.autoLayoutHover,
+ cornerRadiusHover: state.cornerRadiusHover
},
// Recorded pictures follow what the canvas draws, not every document change.
state.canvasVersion,
diff --git a/packages/core/src/canvas/renderer/types.ts b/packages/core/src/canvas/renderer/types.ts
index 142a0d713..e23b18340 100644
--- a/packages/core/src/canvas/renderer/types.ts
+++ b/packages/core/src/canvas/renderer/types.ts
@@ -4,7 +4,7 @@ import type { SnapGuide } from '@open-pencil/scene-graph/snap'
import type { GuideOverlayState } from '#core/canvas/guides/types'
import type { DesignIssueOverlay } from '#core/canvas/issues/types'
-import type { GradientEdit } from '#core/editor/types'
+import type { CornerRadiusHover, GradientEdit } from '#core/editor/types'
import type { RotationPreview } from '#core/geometry'
import type { TextEditor } from '#core/text/editor'
@@ -65,6 +65,8 @@ export interface RenderOverlays {
index?: number
side?: 'top' | 'right' | 'bottom' | 'left'
} | null
+ /** The selected rectangle's corner radius handles and the label of the one in use. */
+ cornerRadiusHover?: CornerRadiusHover | null
penState?: {
vertices: Vector[]
segments: Array<{
diff --git a/packages/core/src/editor/index.ts b/packages/core/src/editor/index.ts
index 5244822c1..467b2eaa1 100644
--- a/packages/core/src/editor/index.ts
+++ b/packages/core/src/editor/index.ts
@@ -57,6 +57,7 @@ export type {
EditorSharedState,
EditorViewState,
FigmaClipboardImageResolver,
+ CornerRadiusHover,
GradientEdit,
Tool
} from './types'
diff --git a/packages/core/src/editor/selection/overlays.ts b/packages/core/src/editor/selection/overlays.ts
index 1418c0196..39a70fbe9 100644
--- a/packages/core/src/editor/selection/overlays.ts
+++ b/packages/core/src/editor/selection/overlays.ts
@@ -1,8 +1,10 @@
+import { isEqual } from 'es-toolkit'
+
import type { Rect } from '@open-pencil/scene-graph/primitives'
import type { SnapGuide } from '@open-pencil/scene-graph/snap'
import type { GuidePreview } from '#core/canvas/guides/types'
-import type { EditorContext } from '#core/editor/types'
+import type { CornerRadiusHover, EditorContext } from '#core/editor/types'
export function createSelectionOverlayActions(ctx: EditorContext) {
function setMarquee(rect: Rect | null) {
@@ -96,6 +98,12 @@ export function createSelectionOverlayActions(ctx: EditorContext) {
ctx.requestRepaint()
}
+ function setCornerRadiusHover(hover: CornerRadiusHover | null) {
+ if (isEqual(ctx.state.cornerRadiusHover, hover)) return
+ ctx.state.cornerRadiusHover = hover
+ ctx.requestRepaint()
+ }
+
return {
setMarquee,
setSnapGuides,
@@ -110,6 +118,7 @@ export function createSelectionOverlayActions(ctx: EditorContext) {
setMeasurementMode,
setDropTarget,
setLayoutInsertIndicator,
- setAutoLayoutHover
+ setAutoLayoutHover,
+ setCornerRadiusHover
}
}
diff --git a/packages/core/src/editor/state/view.ts b/packages/core/src/editor/state/view.ts
index 8d9f873ff..12b1b65c7 100644
--- a/packages/core/src/editor/state/view.ts
+++ b/packages/core/src/editor/state/view.ts
@@ -20,6 +20,7 @@ export function createDefaultEditorViewState(pageId: string): EditorViewState {
penCursorX: null,
penCursorY: null,
autoLayoutHover: null,
+ cornerRadiusHover: null,
panX: 0,
pageColor: { ...CANVAS_BG_COLOR },
panY: 0,
@@ -45,6 +46,7 @@ export function copyEditorViewState(source: EditorViewState): EditorViewState {
layoutInsertIndicator: structuredClone(source.layoutInsertIndicator),
penState: structuredClone(source.penState),
autoLayoutHover: structuredClone(source.autoLayoutHover),
+ cornerRadiusHover: structuredClone(source.cornerRadiusHover),
pageColor: { ...source.pageColor },
navigation: { ...source.navigation },
nodeEditState: structuredClone(source.nodeEditState)
diff --git a/packages/core/src/editor/types.ts b/packages/core/src/editor/types.ts
index c376a9f59..2b941cbe3 100644
--- a/packages/core/src/editor/types.ts
+++ b/packages/core/src/editor/types.ts
@@ -20,7 +20,7 @@ import type { MeasurementMode, PresenceCursor, RenderOverlays } from '#core/canv
import type { InterfaceTheme } from '#core/constants'
import type { PlayState } from '#core/editor/play/actions'
import type { SnappingPreferences } from '#core/editor/preferences'
-import type { RotationPreview } from '#core/geometry'
+import type { RadiusCorner, RotationPreview } from '#core/geometry'
import type { IconProvider } from '#core/icons/provider'
import type { TextEditor } from '#core/text/editor'
import type { FontResolutionEvent, FontResolutionSnapshot } from '#core/text/resolver'
@@ -47,6 +47,19 @@ export interface GradientEdit {
stop: number
}
+/** The selected rectangle's corner radius handles, shown while the pointer is over it. */
+export interface CornerRadiusHover {
+ nodeId: string
+ /** Whether a drag changes only the corner it holds; each handle then shows a dot. */
+ single: boolean
+ /** The handle under the pointer or being dragged, whose radius the label shows. */
+ corner: RadiusCorner | null
+ /** The word before the radius in the label, in the interface language. */
+ label: string
+ /** The pointer in screen coordinates, which the label follows. */
+ pointer: Vector
+}
+
export interface EditorSharedState {
activeTool: Tool
snappingPreferences: SnappingPreferences
@@ -112,6 +125,7 @@ export interface EditorViewState {
index?: number
side?: 'top' | 'right' | 'bottom' | 'left'
} | null
+ cornerRadiusHover: CornerRadiusHover | null
panX: number
pageColor: Color
panY: number
diff --git a/packages/core/src/geometry/corner-radius.ts b/packages/core/src/geometry/corner-radius.ts
new file mode 100644
index 000000000..45a223e81
--- /dev/null
+++ b/packages/core/src/geometry/corner-radius.ts
@@ -0,0 +1,163 @@
+import type { SceneNode, Vector } from '@open-pencil/scene-graph'
+
+import type { SceneGeometry } from './scene'
+import type { ViewportTransform } from './types'
+
+/**
+ * On-canvas corner radius handles, as Figma desktop draws and drags them on a selected rectangle.
+ * Each handle sits at the centre of its corner's arc, kept a little inside small corners, and
+ * dragging one sets the radius whose arc centre is under the pointer.
+ */
+export const CORNER_RADIUS_HANDLE = {
+ /** The shortest on-screen side, in pixels, at which a rectangle shows its handles. */
+ minShapeSize: 108,
+ /** The closest a handle comes to its corner along each edge, in screen pixels. */
+ minInset: 12.5,
+ /** The dot that marks a drag of one corner only. */
+ dotRadius: 1,
+ /** How far from its centre a handle, drawn the size of a resize handle, takes the pointer. */
+ hitRadius: 7,
+ /** Shift rounds radii to this step. */
+ snapStep: 10,
+ /** Where the radius label sits relative to the pointer: its left edge and vertical centre. */
+ labelOffset: { x: 10, y: -20 }
+} as const
+
+export type RadiusCorner = 'topLeft' | 'topRight' | 'bottomRight' | 'bottomLeft'
+
+export const RADIUS_CORNERS: readonly RadiusCorner[] = [
+ 'topLeft',
+ 'topRight',
+ 'bottomRight',
+ 'bottomLeft'
+]
+
+/** The direction from each corner into the rectangle, along both edges. */
+const INWARD: Record<RadiusCorner, Vector> = {
+ topLeft: { x: 1, y: 1 },
+ topRight: { x: -1, y: 1 },
+ bottomRight: { x: -1, y: -1 },
+ bottomLeft: { x: 1, y: -1 }
+}
+
+export interface CornerRadiusHandle {
+ corner: RadiusCorner
+ /** The handle's centre in screen coordinates. */
+ point: Vector
+}
+
+/** Figma shows radius handles on rectangles only; frames, ellipses, and vectors have none. */
+export function hasCornerRadiusHandles(node: SceneNode): boolean {
+ return node.type === 'RECTANGLE'
+}
+
+export function cornerRadii(node: SceneNode): Record<RadiusCorner, number> {
+ if (!node.independentCorners) {
+ const radius = node.cornerRadius
+ return { topLeft: radius, topRight: radius, bottomRight: radius, bottomLeft: radius }
+ }
+ return {
+ topLeft: node.topLeftRadius,
+ topRight: node.topRightRadius,
+ bottomRight: node.bottomRightRadius,
+ bottomLeft: node.bottomLeftRadius
+ }
+}
+
+/**
+ * Whether a drag changes only the corner it holds. Corners that differ are dragged one at a time
+ * and equal ones all together; Alt reverses either, as in Figma.
+ */
+export function dragsSingleCorner(node: SceneNode, altKey: boolean): boolean {
+ const radii = Object.values(cornerRadii(node))
+ return radii.some((radius) => radius !== radii[0]) !== altKey
+}
+
+function maxRadius(node: SceneNode): number {
+ return Math.min(node.width, node.height) / 2
+}
+
+function cornerPoint(node: SceneNode, corner: RadiusCorner): Vector {
+ return {
+ x: corner === 'topLeft' || corner === 'bottomLeft' ? 0 : node.width,
+ y: corner === 'topLeft' || corner === 'topRight' ? 0 : node.height
+ }
+}
+
+/** The rectangle's handles on screen, or null when it is too small on screen to show them. */
+export function cornerRadiusHandleLayout(
+ node: SceneNode,
+ geometry: SceneGeometry,
+ viewport: ViewportTransform
+): CornerRadiusHandle[] | null {
+ if (!hasCornerRadiusHandles(node)) return null
+ if (Math.min(node.width, node.height) * viewport.zoom < CORNER_RADIUS_HANDLE.minShapeSize)
+ return null
+ const radii = cornerRadii(node)
+ const minInset = CORNER_RADIUS_HANDLE.minInset / viewport.zoom
+ return RADIUS_CORNERS.map((corner) => {
+ const origin = cornerPoint(node, corner)
+ const inset = Math.max(Math.min(radii[corner], maxRadius(node)), minInset)
+ const local = {
+ x: origin.x + INWARD[corner].x * inset,
+ y: origin.y + INWARD[corner].y * inset
+ }
+ return { corner, point: geometry.toScreen(node, local, viewport) }
+ })
+}
+
+export function hitTestCornerRadiusHandles(
+ handles: readonly CornerRadiusHandle[],
+ screen: Vector
+): RadiusCorner | null {
+ const hit = handles.find(
+ (handle) =>
+ Math.hypot(screen.x - handle.point.x, screen.y - handle.point.y) <=
+ CORNER_RADIUS_HANDLE.hitRadius
+ )
+ return hit?.corner ?? null
+}
+
+/**
+ * The radius whose arc centre lies under a node-local point: its distance from the corner along
+ * the diagonal, in whole pixels, or in steps of 10 with Shift.
+ */
+export function cornerRadiusAtPoint(
+ node: SceneNode,
+ corner: RadiusCorner,
+ local: Vector,
+ snap: boolean
+): number {
+ const origin = cornerPoint(node, corner)
+ const inward = INWARD[corner]
+ const distance = ((local.x - origin.x) * inward.x + (local.y - origin.y) * inward.y) / 2
+ const step = snap ? CORNER_RADIUS_HANDLE.snapStep : 1
+ return Math.min(Math.max(Math.round(distance / step) * step, 0), maxRadius(node))
+}
+
+/** The fields that set one corner, or all four, to a radius. */
+export function cornerRadiusChanges(
+ node: SceneNode,
+ corner: RadiusCorner,
+ radius: number,
+ single: boolean
+): Partial<SceneNode> {
+ if (!single) {
+ return {
+ cornerRadius: radius,
+ independentCorners: false,
+ topLeftRadius: radius,
+ topRightRadius: radius,
+ bottomRightRadius: radius,
+ bottomLeftRadius: radius
+ }
+ }
+ const radii = { ...cornerRadii(node), [corner]: radius }
+ return {
+ independentCorners: true,
+ topLeftRadius: radii.topLeft,
+ topRightRadius: radii.topRight,
+ bottomRightRadius: radii.bottomRight,
+ bottomLeftRadius: radii.bottomLeft
+ }
+}
diff --git a/packages/core/src/geometry/index.ts b/packages/core/src/geometry/index.ts
index 9af821b6f..26f5c6fd6 100644
--- a/packages/core/src/geometry/index.ts
+++ b/packages/core/src/geometry/index.ts
@@ -5,6 +5,18 @@ export {
panelRotation,
panelRotationChange
} from './figma'
+export {
+ CORNER_RADIUS_HANDLE,
+ RADIUS_CORNERS,
+ cornerRadiusAtPoint,
+ cornerRadiusChanges,
+ cornerRadiusHandleLayout,
+ cornerRadii,
+ dragsSingleCorner,
+ hasCornerRadiusHandles,
+ hitTestCornerRadiusHandles
+} from './corner-radius'
+export type { CornerRadiusHandle, RadiusCorner } from './corner-radius'
export {
GRADIENT_HANDLE,
gradientHandleLayout,
diff --git a/packages/core/tests/geometry/corner-radius.test.ts b/packages/core/tests/geometry/corner-radius.test.ts
new file mode 100644
index 000000000..53928aca5
--- /dev/null
+++ b/packages/core/tests/geometry/corner-radius.test.ts
@@ -0,0 +1,122 @@
+import { describe, expect, test } from 'bun:test'
+
+import {
+ cornerRadiusAtPoint,
+ cornerRadiusChanges,
+ cornerRadiusHandleLayout,
+ createSceneGeometry,
+ dragsSingleCorner,
+ hitTestCornerRadiusHandles
+} from '#core/geometry'
+import { SceneGraph, type SceneNode } from '@open-pencil/scene-graph'
+
+// Values measured on a 160 × 232 rectangle in Figma desktop, 2026-10-10.
+
+function rectangle(props: Partial<SceneNode> = {}, type: SceneNode['type'] = 'RECTANGLE') {
+ const graph = new SceneGraph()
+ const node = graph.createNode(type, graph.getPages()[0].id, {
+ x: 0,
+ y: 0,
+ width: 160,
+ height: 232,
+ ...props
+ })
+ return { graph, node }
+}
+
+function layout(props: Partial<SceneNode> = {}, zoom = 1, type: SceneNode['type'] = 'RECTANGLE') {
+ const { graph, node } = rectangle(props, type)
+ const handles = cornerRadiusHandleLayout(node, createSceneGeometry(graph), {
+ panX: 0,
+ panY: 0,
+ zoom
+ })
+ return handles?.map(({ corner, point }) => [corner, point.x, point.y])
+}
+
+describe('corner radius handles', () => {
+ test('sit 12.5 screen pixels inside corners whose radius is smaller', () => {
+ expect(layout()).toEqual([
+ ['topLeft', 12.5, 12.5],
+ ['topRight', 147.5, 12.5],
+ ['bottomRight', 147.5, 219.5],
+ ['bottomLeft', 12.5, 219.5]
+ ])
+ })
+
+ test('sit at the centre of each corner arc, at any zoom', () => {
+ expect(layout({ cornerRadius: 20 }, 2)?.[0]).toEqual(['topLeft', 40, 40])
+ expect(
+ layout({
+ independentCorners: true,
+ topLeftRadius: 10,
+ topRightRadius: 40,
+ bottomRightRadius: 0,
+ bottomLeftRadius: 20
+ })
+ ).toEqual([
+ ['topLeft', 12.5, 12.5],
+ ['topRight', 120, 40],
+ ['bottomRight', 147.5, 219.5],
+ ['bottomLeft', 20, 212]
+ ])
+ })
+
+ test('hide while the shorter side is under 108 screen pixels, and on other layer types', () => {
+ expect(layout({ width: 108, height: 108 })).toHaveLength(4)
+ expect(layout({ width: 107, height: 300 })).toBeUndefined()
+ expect(layout({ width: 216, height: 216 }, 0.5)).toHaveLength(4)
+ expect(layout({ width: 212, height: 212 }, 0.5)).toBeUndefined()
+ expect(layout({}, 1, 'FRAME')).toBeUndefined()
+ expect(layout({}, 1, 'ELLIPSE')).toBeUndefined()
+ })
+
+ test('take the pointer within their ring and a little beyond', () => {
+ const handles = [{ corner: 'topLeft' as const, point: { x: 12.5, y: 12.5 } }]
+ expect(hitTestCornerRadiusHandles(handles, { x: 18, y: 16 })).toBe('topLeft')
+ expect(hitTestCornerRadiusHandles(handles, { x: 22, y: 12.5 })).toBeNull()
+ })
+
+ test('set the radius whose arc centre is under the pointer', () => {
+ const { node } = rectangle()
+ expect(cornerRadiusAtPoint(node, 'topLeft', { x: 32.5, y: 32.5 }, false)).toBe(33)
+ expect(cornerRadiusAtPoint(node, 'topLeft', { x: 32.5, y: 12.5 }, false)).toBe(23)
+ expect(cornerRadiusAtPoint(node, 'topLeft', { x: 32.5, y: -7.5 }, false)).toBe(13)
+ expect(cornerRadiusAtPoint(node, 'bottomRight', { x: 127.5, y: 199.5 }, false)).toBe(33)
+ expect(cornerRadiusAtPoint(node, 'topLeft', { x: -10, y: -10 }, false)).toBe(0)
+ expect(cornerRadiusAtPoint(node, 'topLeft', { x: 220, y: 220 }, false)).toBe(80)
+ })
+
+ test('round to tens with Shift', () => {
+ const { node } = rectangle()
+ const snapped = [20.5, 26.5, 33.5, 39.5, 52.5].map((at) =>
+ cornerRadiusAtPoint(node, 'topLeft', { x: at, y: at }, true)
+ )
+ expect(snapped).toEqual([20, 30, 30, 40, 50])
+ })
+
+ test('drag equal corners together and differing ones alone, Alt reversing either', () => {
+ const uniform = rectangle({ cornerRadius: 20 }).node
+ const mixed = rectangle({ independentCorners: true, topLeftRadius: 10, topRightRadius: 40 }).node
+ expect(dragsSingleCorner(uniform, false)).toBe(false)
+ expect(dragsSingleCorner(uniform, true)).toBe(true)
+ expect(dragsSingleCorner(mixed, false)).toBe(true)
+ expect(dragsSingleCorner(mixed, true)).toBe(false)
+
+ expect(cornerRadiusChanges(uniform, 'bottomRight', 30, true)).toEqual({
+ independentCorners: true,
+ topLeftRadius: 20,
+ topRightRadius: 20,
+ bottomRightRadius: 30,
+ bottomLeftRadius: 20
+ })
+ expect(cornerRadiusChanges(mixed, 'topRight', 50, false)).toEqual({
+ cornerRadius: 50,
+ independentCorners: false,
+ topLeftRadius: 50,
+ topRightRadius: 50,
+ bottomRightRadius: 50,
+ bottomLeftRadius: 50
+ })
+ })
+})
diff --git a/packages/docs/reference/figma-compatibility.md b/packages/docs/reference/figma-compatibility.md
index 41fa8311e..277de4da0 100644
--- a/packages/docs/reference/figma-compatibility.md
+++ b/packages/docs/reference/figma-compatibility.md
@@ -132,7 +132,7 @@ Feature-by-feature comparison of Figma Design capabilities with Open Pencil's cu
| Dash patterns | ✅ | Dash-on/dash-off stroke pattern |
| Stroke alignment | ✅ | Inside/Center/Outside with clip-based rendering matching Figma behavior |
| Individual stroke weights per side | ✅ | Top/Right/Bottom/Left with side selector dropdown |
-| Corner radius | ✅ | Uniform and per-corner radius with independent toggle in properties panel |
+| Corner radius | ✅ | Uniform and per-corner radius with independent toggle in properties panel; canvas handles on rectangles |
| Corner smoothing (iOS-style) | 🔲 | Figma's continuous corner rounding |
| Multiple fills/strokes per layer | 🔲 | Figma allows stacking fills and strokes |
diff --git a/packages/docs/user-guide/drawing-shapes.md b/packages/docs/user-guide/drawing-shapes.md
index cbebeadba..95ae5b8ef 100644
--- a/packages/docs/user-guide/drawing-shapes.md
+++ b/packages/docs/user-guide/drawing-shapes.md
@@ -60,6 +60,8 @@ Add an outline to any shape. Stroke properties include:
Available for rectangles, frames, components, and instances. Click the independent corners toggle to set each corner (top-left, top-right, bottom-left, bottom-right) separately.
+On the canvas, hover a selected rectangle to show a handle inside each corner and drag one to round the corners. Equal corners change together and differing ones one at a time; hold <kbd>⌥</kbd> to swap the two and <kbd>⇧</kbd> to round to tens. The handles hide while the rectangle is under 108 pixels across on screen; zoom in to reach them.
+
### Effects
Add visual effects from the Effects section:
diff --git a/packages/vue/src/canvas/useCanvasInput.ts b/packages/vue/src/canvas/useCanvasInput.ts
index 200e9d150..8d8702d74 100644
--- a/packages/vue/src/canvas/useCanvasInput.ts
+++ b/packages/vue/src/canvas/useCanvasInput.ts
@@ -18,6 +18,7 @@ import {
} from '#vue/canvas/vector-input/input'
import { resolveAutoLayoutHover } from '#vue/shared/input/auto-layout-hover'
import { createClickCounter } from '#vue/shared/input/click-count'
+import { resolveCornerRadiusHover } from '#vue/shared/input/corner-radius'
import { handleDrawMove } from '#vue/shared/input/draw'
import { handleMoveMove, handleMoveUp } from '#vue/shared/input/move'
import { setupPanZoom } from '#vue/shared/input/pan-zoom'
@@ -61,7 +62,7 @@ export function useCanvasInput(
previous: number
} | null>(null)
const selectedIdsBeforeClickSequence = ref<ReadonlySet<string>>(new Set())
- const lastPointer = ref<{ cx: number; cy: number } | null>(null)
+ const lastPointer = ref<{ cx: number; cy: number; sx: number; sy: number } | null>(null)
const pointerInside = ref(false)
let altHeld = false
let metaHeld = false
@@ -110,6 +111,7 @@ export function useCanvasInput(
editor.setAutoLayoutHover(
mode === 'off' ? resolveAutoLayoutHover(pointer.cx, pointer.cy, editor) : null
)
+ editor.setCornerRadiusHover(resolveCornerRadiusHover(editor, pointer.sx, pointer.sy, altHeld))
}
function updateModifier(code: string, held: boolean) {
@@ -280,7 +282,7 @@ export function useCanvasInput(
if (!isEnabled()) return
pointerInside.value = true
const coords = getCoords(e)
- lastPointer.value = { cx: coords.cx, cy: coords.cy }
+ lastPointer.value = { cx: coords.cx, cy: coords.cy, sx: coords.sx, sy: coords.sy }
if (onCursorMove) {
onCursorMove(coords.cx, coords.cy)
}
@@ -293,8 +295,9 @@ export function useCanvasInput(
}
if (!drag.value) {
- const { cx, cy } = coords
+ const { cx, cy, sx, sy } = coords
updateNodeEditHover(editor, cx, cy)
+ editor.setCornerRadiusHover(resolveCornerRadiusHover(editor, sx, sy, e.altKey))
}
if (!drag.value && editor.state.activeTool === 'SELECT') {
@@ -324,7 +327,7 @@ export function useCanvasInput(
const { sx, sy, cx, cy } = getCoords(e)
- if (d.type === 'gradient') {
+ if (d.type === 'gradient' || d.type === 'corner-radius') {
d.update(sx, sy, e.shiftKey)
return
}
@@ -413,7 +416,7 @@ export function useCanvasInput(
editor.commitRotation(d.nodeId, d.origRotation)
}
if (editor.state.rotationPreview === preview) editor.setRotationPreview(null)
- } else if (d.type === 'draw' || d.type === 'gradient') d.commit()
+ } else if (d.type === 'draw' || d.type === 'gradient' || d.type === 'corner-radius') d.commit()
else if (d.type === 'marquee') editor.setMarquee(null)
drag.value = null
@@ -425,6 +428,7 @@ export function useCanvasInput(
editor.setSnapGuides([])
editor.setLayoutInsertIndicator(null)
editor.setDropTarget(null)
+ editor.setCornerRadiusHover(null)
guideInput.clearHoverAndPreview()
}
@@ -434,7 +438,11 @@ export function useCanvasInput(
drag.value = null
if (editor.state.rotationPreview?.nodeId === rotation.nodeId) editor.setRotationPreview(null)
}
- if (drag.value?.type === 'draw' || drag.value?.type === 'gradient') {
+ if (
+ drag.value?.type === 'draw' ||
+ drag.value?.type === 'gradient' ||
+ drag.value?.type === 'corner-radius'
+ ) {
const drawing = drag.value
drag.value = null
drawing.cancel()
@@ -524,6 +532,7 @@ export function useCanvasInput(
if (!drag.value) {
editor.setHoveredNode(null)
editor.setHoveredGuide(null)
+ editor.setCornerRadiusHover(null)
}
})
useEventListener(
diff --git a/packages/vue/src/i18n/locales/de/editor.json b/packages/vue/src/i18n/locales/de/editor.json
index 851ca073b..9005e9449 100644
--- a/packages/vue/src/i18n/locales/de/editor.json
+++ b/packages/vue/src/i18n/locales/de/editor.json
@@ -1,6 +1,7 @@
{
"toolOptions": "Optionen für {tool}",
"removeGradientStop": "Farbverlaufspunkt entfernen",
+ "cornerRadius": "Radius",
"showUI": "UI anzeigen ({shortcut})",
"previewing": "Vorschau",
"resetPreview": "Zurücksetzen",
diff --git a/packages/vue/src/i18n/locales/es/editor.json b/packages/vue/src/i18n/locales/es/editor.json
index 7e3d6751d..e00623c09 100644
--- a/packages/vue/src/i18n/locales/es/editor.json
+++ b/packages/vue/src/i18n/locales/es/editor.json
@@ -1,6 +1,7 @@
{
"toolOptions": "Opciones de {tool}",
"removeGradientStop": "Eliminar parada de degradado",
+ "cornerRadius": "Redondeado",
"showUI": "Mostrar interfaz ({shortcut})",
"previewing": "Vista previa",
"resetPreview": "Restablecer",
diff --git a/packages/vue/src/i18n/locales/fr/editor.json b/packages/vue/src/i18n/locales/fr/editor.json
index 8275446dd..274a2adbb 100644
--- a/packages/vue/src/i18n/locales/fr/editor.json
+++ b/packages/vue/src/i18n/locales/fr/editor.json
@@ -1,6 +1,7 @@
{
"toolOptions": "Options de {tool}",
"removeGradientStop": "Supprimer le point de dégradé",
+ "cornerRadius": "Rayon",
"showUI": "Afficher l’interface ({shortcut})",
"previewing": "Aperçu",
"resetPreview": "Réinitialiser",
diff --git a/packages/vue/src/i18n/locales/it/editor.json b/packages/vue/src/i18n/locales/it/editor.json
index f78efcad3..374b6be83 100644
--- a/packages/vue/src/i18n/locales/it/editor.json
+++ b/packages/vue/src/i18n/locales/it/editor.json
@@ -1,6 +1,7 @@
{
"toolOptions": "Opzioni di {tool}",
"removeGradientStop": "Rimuovi punto sfumatura",
+ "cornerRadius": "Raggio",
"showUI": "Mostra interfaccia ({shortcut})",
"previewing": "Anteprima",
"resetPreview": "Ripristina",
diff --git a/packages/vue/src/i18n/locales/ja/editor.json b/packages/vue/src/i18n/locales/ja/editor.json
index 9ee7015c1..737bd642e 100644
--- a/packages/vue/src/i18n/locales/ja/editor.json
+++ b/packages/vue/src/i18n/locales/ja/editor.json
@@ -1,6 +1,7 @@
{
"toolOptions": "{tool}のオプション",
"removeGradientStop": "グラデーション停止点を削除",
+ "cornerRadius": "角丸",
"showUI": "UIを表示 ({shortcut})",
"previewing": "プレビュー中",
"resetPreview": "リセット",
diff --git a/packages/vue/src/i18n/locales/pl/editor.json b/packages/vue/src/i18n/locales/pl/editor.json
index 2d2b71a63..3ef129542 100644
--- a/packages/vue/src/i18n/locales/pl/editor.json
+++ b/packages/vue/src/i18n/locales/pl/editor.json
@@ -1,6 +1,7 @@
{
"toolOptions": "Opcje narzędzia {tool}",
"removeGradientStop": "Usuń punkt gradientu",
+ "cornerRadius": "Promień",
"showUI": "Pokaż interfejs ({shortcut})",
"previewing": "Podgląd",
"resetPreview": "Resetuj",
diff --git a/packages/vue/src/i18n/locales/ru/editor.json b/packages/vue/src/i18n/locales/ru/editor.json
index dac18e61c..c5b4685d6 100644
--- a/packages/vue/src/i18n/locales/ru/editor.json
+++ b/packages/vue/src/i18n/locales/ru/editor.json
@@ -1,6 +1,7 @@
{
"toolOptions": "Параметры инструмента «{tool}»",
"removeGradientStop": "Удалить точку градиента",
+ "cornerRadius": "Радиус",
"showUI": "Показать интерфейс ({shortcut})",
"previewing": "Просмотр",
"resetPreview": "Сбросить",
diff --git a/packages/vue/src/i18n/locales/zh-cn/editor.json b/packages/vue/src/i18n/locales/zh-cn/editor.json
index d7723436b..74bd3c519 100644
--- a/packages/vue/src/i18n/locales/zh-cn/editor.json
+++ b/packages/vue/src/i18n/locales/zh-cn/editor.json
@@ -1,6 +1,7 @@
{
"toolOptions": "{tool}选项",
"removeGradientStop": "删除渐变色标",
+ "cornerRadius": "圆角",
"showUI": "显示界面({shortcut})",
"previewing": "预览中",
"resetPreview": "重置",
diff --git a/packages/vue/src/i18n/messages/editor.ts b/packages/vue/src/i18n/messages/editor.ts
index 43c8052dd..71543c84e 100644
--- a/packages/vue/src/i18n/messages/editor.ts
+++ b/packages/vue/src/i18n/messages/editor.ts
@@ -5,6 +5,8 @@ import { i18n } from '#vue/i18n/create'
export const editorMessageDefaults = {
toolOptions: params('{tool} options'),
removeGradientStop: 'Remove gradient stop',
+ /** The word before a corner's radius in the label beside a dragged radius handle. */
+ cornerRadius: 'Radius',
showUI: params('Show UI ({shortcut})'),
previewing: 'Previewing',
startPreview: params('Preview ({shortcut})'),
diff --git a/packages/vue/src/shared/input/corner-radius.ts b/packages/vue/src/shared/input/corner-radius.ts
new file mode 100644
index 000000000..d74d2ad68
--- /dev/null
+++ b/packages/vue/src/shared/input/corner-radius.ts
@@ -0,0 +1,101 @@
+import type { CornerRadiusHover, Editor } from '@open-pencil/core/editor'
+import {
+ cornerRadiusAtPoint,
+ cornerRadiusChanges,
+ cornerRadiusHandleLayout,
+ createSceneGeometry,
+ dragsSingleCorner,
+ hitTestCornerRadiusHandles
+} from '@open-pencil/core/geometry'
+
+import { editorMessages } from '#vue/i18n/messages/editor'
+import { isPastPointerDragThreshold } from '#vue/shared/input/drag-threshold'
+import type { DragCornerRadius, DragState } from '#vue/shared/input/types'
+
+/** Figma leaves the radius alone until the pointer has moved this far from the handle. */
+const RADIUS_DRAG_THRESHOLD_PX = 5
+
+/**
+ * The corner radius handles to show for the pointer at a screen point: those of the only selected
+ * rectangle while the pointer is over it or one of its handles, with the handle under the pointer.
+ */
+export function resolveCornerRadiusHover(
+ editor: Editor,
+ sx: number,
+ sy: number,
+ altKey: boolean
+): CornerRadiusHover | null {
+ const { state } = editor
+ if (
+ state.activeTool !== 'SELECT' ||
+ state.selectedIds.size !== 1 ||
+ state.editingTextId ||
+ state.nodeEditState ||
+ state.penState ||
+ state.gradientEdit
+ )
+ return null
+ const [id] = state.selectedIds
+ const node = editor.graph.getNode(id)
+ if (!node || node.locked) return null
+ const geometry = createSceneGeometry(editor.graph, state.rotationPreview)
+ const handles = cornerRadiusHandleLayout(node, geometry, state)
+ if (!handles) return null
+ const pointer = { x: sx, y: sy }
+ const corner = hitTestCornerRadiusHandles(handles, pointer)
+ if (!corner) {
+ const local = geometry.screenToLocal(node, pointer, state)
+ const inside =
+ local && local.x >= 0 && local.y >= 0 && local.x <= node.width && local.y <= node.height
+ if (!inside) return null
+ }
+ return {
+ nodeId: node.id,
+ single: dragsSingleCorner(node, altKey),
+ corner,
+ label: editorMessages.get().cornerRadius,
+ pointer
+ }
+}
+
+/**
+ * Starts dragging the corner radius handle under the pointer, if any. The radius follows the
+ * pointer rather than the distance dragged, Shift rounds it to tens, and each drag is one undo
+ * step, as in Figma desktop.
+ */
+export function tryStartCornerRadiusDrag(
+ editor: Editor,
+ sx: number,
+ sy: number,
+ altKey: boolean,
+ setDrag: (drag: DragState) => void
+): boolean {
+ const found = resolveCornerRadiusHover(editor, sx, sy, altKey)
+ if (!found?.corner) return false
+ const hover: CornerRadiusHover = found
+ const corner = found.corner
+ const preview = editor.beginNodePreview('Change corner radius')
+ let moved = false
+
+ function update(screenX: number, screenY: number, shiftKey: boolean) {
+ moved ||= isPastPointerDragThreshold(sx, sy, screenX, screenY, RADIUS_DRAG_THRESHOLD_PX)
+ const node = editor.graph.getNode(hover.nodeId)
+ if (!moved || !node) return
+ const pointer = { x: screenX, y: screenY }
+ const local = createSceneGeometry(editor.graph).screenToLocal(node, pointer, editor.state)
+ if (!local) return
+ const radius = cornerRadiusAtPoint(node, corner, local, shiftKey)
+ preview.update(node.id, cornerRadiusChanges(node, corner, radius, hover.single))
+ editor.setCornerRadiusHover({ ...hover, pointer })
+ }
+
+ const drag: DragCornerRadius = {
+ type: 'corner-radius',
+ update,
+ commit: () => preview.commit(),
+ cancel: () => preview.cancel()
+ }
+ editor.setCornerRadiusHover(hover)
+ setDrag(drag)
+ return true
+}
diff --git a/packages/vue/src/shared/input/select.ts b/packages/vue/src/shared/input/select.ts
index d402a6f6e..24d90b64c 100644
--- a/packages/vue/src/shared/input/select.ts
+++ b/packages/vue/src/shared/input/select.ts
@@ -5,6 +5,7 @@ export { updateHoverCursor } from '#vue/shared/input/select/hover'
import { editedGradient, type Editor } from '@open-pencil/core/editor'
import type { SceneNode } from '@open-pencil/scene-graph'
+import { tryStartCornerRadiusDrag } from '#vue/shared/input/corner-radius'
import { tryStartGradientDrag } from '#vue/shared/input/gradient'
import { tryStartResize } from '#vue/shared/input/resize'
import {
@@ -30,12 +31,16 @@ function startMarquee(cx: number, cy: number, editor: Editor, setDrag: (d: DragS
setDrag({ type: 'marquee', startX: cx, startY: cy, containerId: container?.id })
}
-/** Starts dragging a gradient handle, or else the selection's rotation or resize handles. */
+/**
+ * Starts dragging a gradient handle, or else the selection's corner radius, rotation, or resize
+ * handles.
+ */
function tryStartHandleDrag(
cx: number,
cy: number,
sx: number,
sy: number,
+ altKey: boolean,
editor: Editor,
tryStartRotation: (cx: number, cy: number) => boolean,
setDrag: (d: DragState) => void
@@ -43,6 +48,7 @@ function tryStartHandleDrag(
if (tryStartGradientDrag(editor, sx, sy, setDrag)) return true
// An open gradient's handles replace the layer's selection handles, which then do not respond.
if (editedGradient(editor.graph, editor.state.gradientEdit)) return false
+ if (tryStartCornerRadiusDrag(editor, sx, sy, altKey, setDrag)) return true
if (tryStartRotation(cx, cy)) return true
const resizeDrag = tryStartResize(cx, cy, editor)
if (resizeDrag) setDrag(resizeDrag)
@@ -71,7 +77,7 @@ export function handleSelectDown(
if (editor.state.editingTextId) editor.commitTextEdit()
- if (tryStartHandleDrag(cx, cy, sx, sy, editor, tryStartRotation, setDrag)) return
+ if (tryStartHandleDrag(cx, cy, sx, sy, e.altKey, editor, tryStartRotation, setDrag)) return
const hit = resolveHit(cx, cy, editor, fns, e.metaKey || e.ctrlKey)
if (!hit) {
diff --git a/packages/vue/src/shared/input/types.ts b/packages/vue/src/shared/input/types.ts
index 3810adfcf..7c0ac074b 100644
--- a/packages/vue/src/shared/input/types.ts
+++ b/packages/vue/src/shared/input/types.ts
@@ -175,7 +175,17 @@ export interface DragGradient {
cancel: () => void
}
+/** Dragging a corner radius handle of the selected rectangle. */
+export interface DragCornerRadius {
+ type: 'corner-radius'
+ /** Sets the radius under a screen point; Shift rounds it to tens. */
+ update: (screenX: number, screenY: number, shiftKey: boolean) => void
+ commit: () => void
+ cancel: () => void
+}
+
export type DragState =
+ | DragCornerRadius
| DragDraw
| DragGradient
| DragMove
diff --git a/src/app/editor/panes/state.ts b/src/app/editor/panes/state.ts
index 0042f54bb..4f0fa8ebc 100644
--- a/src/app/editor/panes/state.ts
+++ b/src/app/editor/panes/state.ts
@@ -39,6 +39,7 @@ export function cloneCanvasPaneState(id: string, source: CanvasPaneState): Canva
dropTargetId: null,
layoutInsertIndicator: null,
autoLayoutHover: null,
+ cornerRadiusHover: null,
penState: null,
penCursorX: null,
penCursorY: null,
diff --git a/tests/e2e/canvas/corner-radius/handles-visual.spec.ts b/tests/e2e/canvas/corner-radius/handles-visual.spec.ts
new file mode 100644
index 000000000..8bd057b53
--- /dev/null
+++ b/tests/e2e/canvas/corner-radius/handles-visual.spec.ts
@@ -0,0 +1,32 @@
+import { expect, test, useEditorSetupWithClear } from '#tests/e2e/fixtures'
+import { cornerRadiusDriver } from '#tests/helpers/canvas/corner-radius-driver'
+
+// Figma desktop: white handles ringed in the selection colour, at each arc's centre but at least
+// 12.5 px inside the corner; a dot marks a drag of one corner, and the handle under the pointer
+// shows its radius beside it.
+
+const editor = useEditorSetupWithClear('/?test&no-chrome&no-rulers')
+
+const corners = cornerRadiusDriver(() => editor.page)
+
+test('equal corners', async () => {
+ await corners.show({ cornerRadius: 20 })
+ const centre = corners.point(80, 116)
+ await editor.canvas.hover(centre.x, centre.y)
+ expect(await editor.canvas.screenshotCanvasRegion(360, 440)).toMatchSnapshot('equal.png')
+ editor.canvas.assertNoErrors()
+})
+
+test('differing corners, the top-right one hovered', async () => {
+ await corners.show({
+ independentCorners: true,
+ topLeftRadius: 10,
+ topRightRadius: 40,
+ bottomRightRadius: 0,
+ bottomLeftRadius: 20
+ })
+ const handle = corners.point(120, 40)
+ await editor.canvas.hover(handle.x, handle.y)
+ expect(await editor.canvas.screenshotCanvasRegion(360, 440)).toMatchSnapshot('differing.png')
+ editor.canvas.assertNoErrors()
+})
diff --git a/tests/e2e/canvas/corner-radius/handles-visual.spec.ts-snapshots/differing-openpencil-darwin.png b/tests/e2e/canvas/corner-radius/handles-visual.spec.ts-snapshots/differing-openpencil-darwin.png
new file mode 100644
index 000000000..5d1e98202
Binary files /dev/null and b/tests/e2e/canvas/corner-radius/handles-visual.spec.ts-snapshots/differing-openpencil-darwin.png differ
diff --git a/tests/e2e/canvas/corner-radius/handles-visual.spec.ts-snapshots/equal-openpencil-darwin.png b/tests/e2e/canvas/corner-radius/handles-visual.spec.ts-snapshots/equal-openpencil-darwin.png
new file mode 100644
index 000000000..e33cec62b
Binary files /dev/null and b/tests/e2e/canvas/corner-radius/handles-visual.spec.ts-snapshots/equal-openpencil-darwin.png differ
diff --git a/tests/e2e/canvas/corner-radius/handles.spec.ts b/tests/e2e/canvas/corner-radius/handles.spec.ts
new file mode 100644
index 000000000..7baafe9e9
--- /dev/null
+++ b/tests/e2e/canvas/corner-radius/handles.spec.ts
@@ -0,0 +1,56 @@
+import { expect, test, useEditorSetupWithClear } from '#tests/e2e/fixtures'
+import { cornerRadiusDriver } from '#tests/helpers/canvas/corner-radius-driver'
+
+// Figma desktop: a selected rectangle under the pointer shows a handle inside each corner.
+// Dragging one sets the radius whose arc centre is under the pointer, on every corner while they
+// are equal and on that corner alone while they differ; Alt swaps the two.
+
+const editor = useEditorSetupWithClear('/?test&no-rulers')
+
+const corners = cornerRadiusDriver(() => editor.page)
+
+/**
+ * Drags the top-left handle, which sits `inset` px inside the corner, to (at, at) of the rectangle.
+ */
+async function dragTopLeft(inset: number, at: number, modifier?: 'Alt' | 'Shift') {
+ const from = corners.point(inset, inset)
+ const to = corners.point(at, at)
+ if (modifier) await editor.page.keyboard.down(modifier)
+ await editor.canvas.drag(from.x, from.y, to.x, to.y)
+ if (modifier) await editor.page.keyboard.up(modifier)
+ await editor.canvas.waitForRender()
+}
+
+test('dragging a handle rounds every corner, in one undo step', async () => {
+ const nodeId = await corners.show()
+ await dragTopLeft(12, 40)
+ expect(await corners.radii(nodeId)).toEqual([40, 40, 40, 40])
+
+ await editor.canvas.undo()
+ expect(await corners.radii(nodeId)).toEqual([0, 0, 0, 0])
+ editor.canvas.assertNoErrors()
+})
+
+test('Alt rounds only the dragged corner, and Shift rounds to tens', async () => {
+ const nodeId = await corners.show()
+ await dragTopLeft(12, 40, 'Alt')
+ expect(await corners.radii(nodeId)).toEqual([40, 0, 0, 0])
+
+ await dragTopLeft(40, 33, 'Shift')
+ expect(await corners.radii(nodeId)).toEqual([30, 0, 0, 0])
+})
+
+test('differing corners drag alone, and Alt sets them all', async () => {
+ const nodeId = await corners.show({
+ independentCorners: true,
+ topLeftRadius: 0,
+ topRightRadius: 40,
+ bottomRightRadius: 0,
+ bottomLeftRadius: 20
+ })
+ await dragTopLeft(12, 24)
+ expect(await corners.radii(nodeId)).toEqual([24, 40, 0, 20])
+
+ await dragTopLeft(24, 50, 'Alt')
+ expect(await corners.radii(nodeId)).toEqual([50, 50, 50, 50])
+})
diff --git a/tests/helpers/canvas/corner-radius-driver.ts b/tests/helpers/canvas/corner-radius-driver.ts
new file mode 100644
index 000000000..732cc0372
--- /dev/null
+++ b/tests/helpers/canvas/corner-radius-driver.ts
@@ -0,0 +1,62 @@
+import type { Page } from '@playwright/test'
+
+import type { SceneNode } from '@open-pencil/scene-graph'
+
+type CornerProps = Partial<
+ Pick<
+ SceneNode,
+ | 'cornerRadius'
+ | 'independentCorners'
+ | 'topLeftRadius'
+ | 'topRightRadius'
+ | 'bottomRightRadius'
+ | 'bottomLeftRadius'
+ >
+>
+
+/** Shows a selected rectangle at 100% with its top-left 100 px into the canvas, and reads its radii. */
+export function cornerRadiusDriver(page: () => Page) {
+ return {
+ /** A 160 × 232 rectangle, selected. */
+ show(props: CornerProps = {}) {
+ return page().evaluate((props) => {
+ const store = window.openPencil?.getStore?.()
+ if (!store) throw new Error('OpenPencil store not initialized')
+ const node = store.graph.createNode('RECTANGLE', store.state.currentPageId, {
+ name: 'Card',
+ x: 0,
+ y: 0,
+ width: 160,
+ height: 232,
+ fills: [
+ { type: 'SOLID', visible: true, opacity: 1, color: { r: 0.8, g: 0.6, b: 0.6, a: 1 } }
+ ],
+ ...props
+ })
+ store.select([node.id])
+ store.state.zoom = 1
+ store.state.panX = 100
+ store.state.panY = 100
+ store.requestRender()
+ return node.id
+ }, props)
+ },
+
+ /** Canvas coordinates of a point in the rectangle's own pixels. */
+ point(x: number, y: number) {
+ return { x: 100 + x, y: 100 + y }
+ },
+
+ /** Top-left, top-right, bottom-right, and bottom-left radii as drawn. */
+ radii(nodeId: string) {
+ return page().evaluate((id) => {
+ const node = window.openPencil?.getStore?.().graph.getNode(id)
+ if (!node) return null
+ const { cornerRadius: radius } = node
+ return node.independentCorners
+ ? [node.topLeftRadius, node.topRightRadius, node.bottomRightRadius, node.bottomLeftRadius]
+ : [radius, radius, radius, radius]
+ }, nodeId)
+ }
+ }
+}
diff --git a/tools/checks/i18n/translation-baseline.txt b/tools/checks/i18n/translation-baseline.txt
index cb2d4fdfe..ad8173a8d 100644
--- a/tools/checks/i18n/translation-baseline.txt
+++ b/tools/checks/i18n/translation-baseline.txt
@@ -18,6 +18,7 @@ de:common.ok
de:diagnostics.categoryMCP
de:diagnostics.categoryRenderer
de:diagnostics.durationMs
+de:editor.cornerRadius
de:menu.text
de:panels.alpha
de:panels.blendModeNormal