AI-native design editor. Open-source Figma alternative.
feat: edit ellipse arcs with on-canvas handles as in Figma (#1359)
Danila Poyarkov66c6e58eded5
diff --git a/changes/1359/added.md b/changes/1359/added.mdnew file mode 100644index 000000000..db75805bb--- /dev/null+++ b/changes/1359/added.md@@ -0,0 +1 @@+- A selected ellipse shows Figma's arc handles: drag them to cut a slice, turn the arc, change its sweep, or open a hole, with Shift rounding to 15° and tenths.diff --git a/changes/1359/fixed.md b/changes/1359/fixed.mdnew file mode 100644index 000000000..7f1c5d726--- /dev/null+++ b/changes/1359/fixed.md@@ -0,0 +1 @@+- Ellipse arcs without stored outlines, such as ones set from design JSX or the plugin API, draw their cut edges back to the centre or across the ring instead of as a straight chord.diff --git a/packages/core/src/canvas/fills.ts b/packages/core/src/canvas/fills.tsindex d8498ec95..9334a96c8 100644--- a/packages/core/src/canvas/fills.ts+++ b/packages/core/src/canvas/fills.ts@@ -5,6 +5,8 @@ import { invertGradientTransform } from '@open-pencil/scene-graph/gradient'import Matrix from '@open-pencil/scene-graph/matrix'import type { Color, Rect, Vector } from '@open-pencil/scene-graph/primitives'+import { isWholeArc } from '#core/geometry'+import { figmaBlendModeToSkia } from './blend'import { makeDiamondGradient } from './gradients/diamond'import { previewEdge } from './images/previews'@@ -528,24 +530,29 @@ export function makeArcPath(r: SkiaRenderer, node: SceneNode) {const path = new r.ck.PathBuilder()const oval = r.ck.LTRBRect(0, 0, node.width, node.height)+ const isFullCircle = isWholeArc(arc)if (arc.innerRadius > 0) {- path.addArc(oval, startDeg, sweepDeg)const innerOval = r.ck.LTRBRect(cx - innerRx, cy - innerRy, cx + innerRx, cy + innerRy)- const innerPath = new r.ck.PathBuilder()- innerPath.addArc(innerOval, startDeg + sweepDeg, -sweepDeg)- const immutableInnerPath = innerPath.detachAndDelete()- path.addPath(immutableInnerPath)- immutableInnerPath.delete()+ if (isFullCircle) {+ // Two loops wound in opposite directions, so the hole stays empty under nonzero fill. A+ // full-turn `addArc` from an angle off the axes draws nothing.+ path.addOval(oval, false)+ path.addOval(innerOval, true)+ } else {+ // One outline whose ends run straight across the ring; `addArc` would start a new contour+ // for each edge and close them on their chords.+ path.arcToOval(oval, startDeg, sweepDeg, true)+ path.arcToOval(innerOval, startDeg + sweepDeg, -sweepDeg, false)+ }path.close()return path.detachAndDelete()}- const isFullCircle = Math.abs(sweepDeg) >= 359.99if (isFullCircle) {path.addOval(oval)} else {path.moveTo(cx, cy)- path.addArc(oval, startDeg, sweepDeg)+ path.arcToOval(oval, startDeg, sweepDeg, false)path.close()}return path.detachAndDelete()diff --git a/packages/core/src/canvas/overlays/shape-handles.ts b/packages/core/src/canvas/overlays/shape-handles.tsindex 31b0de124..50fdd866d 100644--- a/packages/core/src/canvas/overlays/shape-handles.ts+++ b/packages/core/src/canvas/overlays/shape-handles.ts@@ -20,10 +20,10 @@ import {} from '#core/geometry'/**- * The selected rectangle's, polygon's, or star's 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 label such as "Radius 12" by the pointer for the handle in use, as in- * Figma desktop.+ * The selected rectangle's, polygon's, star's, or ellipse's 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 on an arc's start, and a label such as "Radius 12" by the pointer+ * for the handle in use, as in Figma desktop.*/export function drawShapeHandles(r: SkiaRenderer,@@ -45,11 +45,11 @@ export function drawShapeHandles(border.setPathEffect(null)border.setStrokeWidth(1)border.setColor(color)- for (const { point } of handles) {+ for (const { handle, 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+ if (!hover.single && handle !== 'arcStart') continuefill.setColor(color)canvas.drawCircle(point.x, point.y, SHAPE_HANDLE.dotRadius, fill)}diff --git a/packages/core/src/geometry/handles/arc.ts b/packages/core/src/geometry/handles/arc.tsnew file mode 100644index 000000000..e9d4a6535--- /dev/null+++ b/packages/core/src/geometry/handles/arc.ts@@ -0,0 +1,154 @@+import { clamp } from 'es-toolkit'++import type { ArcData, SceneNode, Vector } from '@open-pencil/scene-graph'++/**+ * On-canvas arc handles, as Figma desktop draws and drags them on a selected ellipse. Angles run+ * clockwise from three o'clock in the ellipse's own space, scaled to a unit circle, so a handle+ * dragged to the bounding box's corner of a wide ellipse sits at 45°.+ */+export const ARC_HANDLE = {+ /** The shortest on-screen side, in pixels, at which an ellipse shows its handles. */+ minShapeSize: 75,+ /** How far inside a whole ellipse's edge its one handle sits, in screen pixels. */+ edgeInset: 10,+ /** Shift rounds angles to this step, in radians. */+ angleStep: Math.PI / 12,+ /** Shift rounds the ratio to this step. */+ ratioStep: 0.1+} as const++/** An arc's start, its end (whose label shows the sweep), and its inner ratio. */+export type ArcHandleKind = 'arcStart' | 'arcEnd' | 'arcRatio'++const FULL_TURN = 2 * Math.PI+/** How close to a full turn a sweep draws and edits as a whole ellipse: 0.01°. */+const WHOLE_TOLERANCE = (0.01 * Math.PI) / 180++/** The arc an ellipse is drawn with, a whole one when it has none. */+export function arcOf(node: SceneNode): ArcData {+ return node.arcData ?? { startingAngle: 0, endingAngle: FULL_TURN, innerRadius: 0 }+}++/** Whether an arc sweeps a whole turn, so it is drawn and edited as a whole ellipse or ring. */+export function isWholeArc(arc: ArcData): boolean {+ return Math.abs(arc.endingAngle - arc.startingAngle) >= FULL_TURN - WHOLE_TOLERANCE+}++/** The node-local point at an angle, a share of the way from the centre to the edge. */+function onEllipse(node: SceneNode, angle: number, share: number): Vector {+ const rx = node.width / 2+ const ry = node.height / 2+ return { x: rx + rx * share * Math.cos(angle), y: ry + ry * share * Math.sin(angle) }+}++/** The point a fixed number of node pixels inside the edge, towards the centre. */+function insideEdge(node: SceneNode, angle: number, inset: number): Vector {+ const edge = onEllipse(node, angle, 1)+ const dx = edge.x - node.width / 2+ const dy = edge.y - node.height / 2+ const length = Math.hypot(dx, dy)+ if (length === 0) return edge+ const share = Math.max(length - inset, 0) / length+ return { x: node.width / 2 + dx * share, y: node.height / 2 + dy * share }+}++/**+ * Where the handles sit, in node-local pixels. A whole ellipse has one end handle at its start, a+ * little inside the edge, or halfway across its ring when it has a hole, where the ratio handle+ * sits opposite on the inner edge. An arc's start and end handles sit halfway across their edges+ * and its ratio handle on the inner edge at the middle of the sweep, at the centre without a hole.+ * The end comes first so that it wins where the two meet and a closed arc can be opened again.+ */+export function arcHandles(+ node: SceneNode,+ zoom: number+): Array<{ handle: ArcHandleKind; local: Vector }> {+ const arc = arcOf(node)+ const { startingAngle: start, endingAngle: end, innerRadius: inner } = arc+ const middle = (1 + inner) / 2+ const ratio = { handle: 'arcRatio' as const, local: onEllipse(node, (start + end) / 2, inner) }+ if (isWholeArc(arc)) {+ if (inner === 0)+ return [{ handle: 'arcEnd', local: insideEdge(node, start, ARC_HANDLE.edgeInset / zoom) }]+ return [{ handle: 'arcEnd', local: onEllipse(node, start, middle) }, ratio]+ }+ return [+ { handle: 'arcEnd', local: onEllipse(node, end, middle) },+ { handle: 'arcStart', local: onEllipse(node, start, middle) },+ ratio+ ]+}++/** A node-local point relative to the shape's centre, with its ellipse scaled to a unit circle. */+export function unitOffset(node: SceneNode, local: Vector): Vector {+ return {+ x: (local.x - node.width / 2) / (node.width / 2),+ y: (local.y - node.height / 2) / (node.height / 2)+ }+}++function snapped(value: number, step: number, snap: boolean): number {+ return snap ? Math.round(value / step) * step : value+}++function angleAt(node: SceneNode, local: Vector, snap: boolean): number {+ const { x, y } = unitOffset(node, local)+ return snapped(Math.atan2(y, x), ARC_HANDLE.angleStep, snap)+}++/**+ * The arc a handle dragged to a node-local point gives, as in Figma. The start turns the whole+ * arc and is kept within one turn. The end follows the pointer without jumping, and a sweep that+ * passes a full turn continues from the other side, so the ellipse loses the slice the handle+ * crosses. The ratio is the pointer's distance from the centre in any direction. Shift rounds+ * angles to 15° and the ratio to tenths.+ */+export function arcAtPoint(+ node: SceneNode,+ handle: ArcHandleKind,+ local: Vector,+ snap: boolean+): ArcData {+ const arc = arcOf(node)+ const { startingAngle: start, endingAngle: end } = arc+ if (handle === 'arcRatio') {+ const { x, y } = unitOffset(node, local)+ const ratio = clamp(snapped(Math.hypot(x, y), ARC_HANDLE.ratioStep, snap), 0, 1)+ return { ...arc, innerRadius: ratio }+ }+ const angle = angleAt(node, local, snap)+ if (handle === 'arcStart') {+ const turned = ((angle % FULL_TURN) + FULL_TURN) % FULL_TURN+ return { ...arc, startingAngle: turned, endingAngle: turned + end - start }+ }+ let next = angle + Math.round((end - angle) / FULL_TURN) * FULL_TURN+ if (next - start > FULL_TURN) next -= 2 * FULL_TURN+ else if (next - start < -FULL_TURN) next += 2 * FULL_TURN+ return { ...arc, endingAngle: next }+}++function oneDecimal(value: number): string {+ return String(Math.round(value * 10) / 10 || 0)+}++/** What a handle's label shows: the start in degrees, or the sweep or ratio in percent. */+export function arcHandleValue(node: SceneNode, handle: ArcHandleKind): string {+ const { startingAngle: start, endingAngle: end, innerRadius } = arcOf(node)+ if (handle === 'arcStart') return `${oneDecimal((start * 180) / Math.PI)}°`+ if (handle === 'arcEnd') return `${oneDecimal(((end - start) / FULL_TURN) * 100)}%`+ return `${oneDecimal(innerRadius * 100)}%`+}++/**+ * The fields a handle dragged to a node-local point sets. The outline a `.fig` stored for the old+ * arc is dropped so that the ellipse is drawn from the new one.+ */+export function arcChanges(+ node: SceneNode,+ handle: ArcHandleKind,+ local: Vector,+ snap: boolean+): Partial<SceneNode> {+ return { arcData: arcAtPoint(node, handle, local, snap), fillGeometry: [], strokeGeometry: [] }+}diff --git a/packages/core/src/geometry/shape-handles.ts b/packages/core/src/geometry/handles/shape.tssimilarity index 87%rename from packages/core/src/geometry/shape-handles.tsrename to packages/core/src/geometry/handles/shape.tsindex 93ca68c43..247aeb242 100644--- a/packages/core/src/geometry/shape-handles.ts+++ b/packages/core/src/geometry/handles/shape.ts@@ -3,14 +3,17 @@ import { clamp } from 'es-toolkit'import type { SceneNode, Vector } from '@open-pencil/scene-graph'import { POINT_COUNT_RANGE, polygonCorners } from '@open-pencil/scene-graph/polygon'-import type { SceneGeometry } from './scene'-import type { ViewportTransform } from './types'+import type { SceneGeometry } from '#core/geometry/scene'+import type { ViewportTransform } from '#core/geometry/types'++import { ARC_HANDLE, arcHandles, arcHandleValue, unitOffset, type ArcHandleKind } from './arc'/*** On-canvas shape handles, as Figma desktop draws and drags them on a selected rectangle, polygon,* or star. A radius 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. A polygon's or- * star's next outer point sets its point count, and a star's first inner point its inner ratio.+ * star's next outer point sets its point count, and a star's first inner point its inner ratio. An+ * ellipse's arc handles are in `arc.ts`.*/export const SHAPE_HANDLE = {/** The shortest on-screen side, in pixels, at which a shape shows its handles. */@@ -34,8 +37,8 @@ const RECTANGLE_CORNERS = ['topLeft', 'topRight', 'bottomRight', 'bottomLeft'] atype RectangleCorner = (typeof RECTANGLE_CORNERS)[number]-/** A radius handle, or a polygon's or star's point count or a star's inner ratio. */-export type ShapeHandleKind = RadiusCorner | 'count' | 'ratio'+/** A radius handle, a polygon's or star's point count or a star's inner ratio, or an arc handle. */+export type ShapeHandleKind = RadiusCorner | 'count' | 'ratio' | ArcHandleKindexport interface ShapeHandle {handle: ShapeHandleKind@@ -59,10 +62,16 @@ interface RadiusCornerShape {/*** Figma shows radius handles on rectangles, polygons, and stars; a polygon or star has one, at its- * top point, since its corners share one radius. Frames, ellipses, and vectors have none.+ * top point, since its corners share one radius. Ellipses have arc handles; frames and vectors+ * have none.*/export function hasShapeHandles(node: SceneNode): boolean {- return node.type === 'RECTANGLE' || node.type === 'POLYGON' || node.type === 'STAR'+ return (+ node.type === 'RECTANGLE' ||+ node.type === 'POLYGON' ||+ node.type === 'STAR' ||+ node.type === 'ELLIPSE'+ )}export function cornerRadii(node: SceneNode): Record<RectangleCorner, number> {@@ -165,7 +174,14 @@ export function shapeHandleLayout(viewport: ViewportTransform): ShapeHandle[] | null {if (!hasShapeHandles(node)) return null- if (Math.min(node.width, node.height) * viewport.zoom < SHAPE_HANDLE.minShapeSize) return null+ const minSize = node.type === 'ELLIPSE' ? ARC_HANDLE.minShapeSize : SHAPE_HANDLE.minShapeSize+ if (Math.min(node.width, node.height) * viewport.zoom < minSize) return null+ if (node.type === 'ELLIPSE') {+ return arcHandles(node, viewport.zoom).map(({ handle, local }) => ({+ handle,+ point: geometry.toScreen(node, local, viewport)+ }))+ }const minDistance = SHAPE_HANDLE.minInset / HALF_DIAGONAL / viewport.zoomconst radii = radiusCorners(node).map(({ corner, vertex, inward, factor, radius }) => {const distance = Math.max(radius / factor, minDistance)@@ -190,25 +206,22 @@ export function hitTestShapeHandles(return hit?.handle ?? null}+export function isArcHandle(handle: ShapeHandleKind): handle is ArcHandleKind {+ return handle === 'arcStart' || handle === 'arcEnd' || handle === 'arcRatio'+}+export function isRadiusHandle(handle: ShapeHandleKind): handle is RadiusCorner {- return handle !== 'count' && handle !== 'ratio'+ return handle !== 'count' && handle !== 'ratio' && !isArcHandle(handle)}-/** What a handle's label shows after its name: the radius, the point count, or the ratio. */+/** What a handle's label shows after its name: the radius, the point count, the ratio, or the arc. */export function shapeHandleValue(node: SceneNode, handle: ShapeHandleKind): string {+ if (isArcHandle(handle)) return arcHandleValue(node, handle)if (handle === 'count') return String(node.pointCount)if (handle === 'ratio') return `${Math.round(node.starInnerRadius * 100)}%`return String(Math.round(cornerRadiusOf(node, handle)))}-/** A node-local point relative to the shape's centre, with its ellipse scaled to a unit circle. */-function unitOffset(node: SceneNode, local: Vector): Vector {- return {- x: (local.x - node.width / 2) / (node.width / 2),- y: (local.y - node.height / 2) / (node.height / 2)- }-}-/*** The point count whose next outer point lies in the direction of a node-local point: a full turn* over the angle from the top point, clockwise, within Figma's range.diff --git a/packages/core/src/geometry/index.ts b/packages/core/src/geometry/index.tsindex a70e82113..c384abc26 100644--- a/packages/core/src/geometry/index.ts+++ b/packages/core/src/geometry/index.ts@@ -14,13 +14,16 @@ export {cornerRadiusOf,dragsSingleCorner,hasShapeHandles,+ isArcHandle,isRadiusHandle,pointCountAtPoint,shapeHandleValue,starRatioAtPoint,hitTestShapeHandles-} from './shape-handles'-export type { RadiusCorner, ShapeHandle, ShapeHandleKind } from './shape-handles'+} from './handles/shape'+export type { RadiusCorner, ShapeHandle, ShapeHandleKind } from './handles/shape'+export { ARC_HANDLE, arcAtPoint, arcChanges, arcOf, isWholeArc } from './handles/arc'+export type { ArcHandleKind } from './handles/arc'export {GRADIENT_HANDLE,gradientHandleLayout,diff --git a/packages/core/tests/geometry/handles/arc.test.ts b/packages/core/tests/geometry/handles/arc.test.tsnew file mode 100644index 000000000..501406d5b--- /dev/null+++ b/packages/core/tests/geometry/handles/arc.test.ts@@ -0,0 +1,152 @@+import { describe, expect, test } from 'bun:test'++import {+ arcAtPoint,+ arcChanges,+ createSceneGeometry,+ shapeHandleLayout,+ shapeHandleValue+} from '#core/geometry'+import { SceneGraph, type ArcData, type SceneNode } from '@open-pencil/scene-graph'++// Values measured on ellipses in Figma desktop, 2026-10-21.++const DEGREE = Math.PI / 180++function ellipse(props: Partial<SceneNode> = {}) {+ const graph = new SceneGraph()+ const node = graph.createNode('ELLIPSE', graph.getPages()[0].id, {+ x: 0,+ y: 0,+ width: 300,+ height: 300,+ ...props+ })+ return { graph, node }+}++function arc(startDegrees: number, endDegrees: number, innerRadius = 0): ArcData {+ return { startingAngle: startDegrees * DEGREE, endingAngle: endDegrees * DEGREE, innerRadius }+}++function layout(props: Partial<SceneNode> = {}, zoom = 1) {+ const { graph, node } = ellipse(props)+ const handles = shapeHandleLayout(node, createSceneGeometry(graph), { panX: 0, panY: 0, zoom })+ const exact = (value: number) => Math.round(value * 1e6) / 1e6+ return handles?.map(({ handle, point }) => [handle, exact(point.x), exact(point.y)])+}++/** A node-local point at an angle and a distance from the centre of a 300 × 300 ellipse. */+function at(degrees: number, distance: number) {+ return {+ x: 150 + distance * Math.cos(degrees * DEGREE),+ y: 150 + distance * Math.sin(degrees * DEGREE)+ }+}++function degrees(value: ArcData) {+ const round = (angle: number) => Math.round((angle / DEGREE) * 1000) / 1000+ return [round(value.startingAngle), round(value.endingAngle), value.innerRadius]+}++describe('arc handles', () => {+ test('put one handle 10 screen pixels inside a whole ellipse at its start', () => {+ expect(layout()).toEqual([['arcEnd', 290, 150]])+ expect(layout({ arcData: arc(90, 450) })).toEqual([['arcEnd', 150, 290]])+ expect(layout({}, 2)).toEqual([['arcEnd', 590, 300]])+ })++ test('put a whole ring’s end halfway across it and its ratio on the inner edge opposite', () => {+ expect(layout({ arcData: arc(0, 360, 0.5) })).toEqual([+ ['arcEnd', 262.5, 150],+ ['arcRatio', 75, 150]+ ])+ })++ test('put an arc’s start and end halfway across their edges and its ratio mid-sweep', () => {+ expect(layout({ arcData: arc(0, 270) })).toEqual([+ ['arcEnd', 150, 75],+ ['arcStart', 225, 150],+ ['arcRatio', 150, 150]+ ])+ const ring = layout({ arcData: arc(0, 180, 0.5) })+ expect(ring?.[2]).toEqual(['arcRatio', 150, 225])+ })++ test('scale positions with the ellipse on a wide one', () => {+ expect(layout({ width: 300, height: 150, arcData: arc(0, 90) })).toEqual([+ ['arcEnd', 150, 112.5],+ ['arcStart', 225, 75],+ ['arcRatio', 150, 75]+ ])+ })++ test('hide while the shorter side is under 75 screen pixels', () => {+ expect(layout({ width: 75, height: 300 })).toHaveLength(1)+ expect(layout({ width: 74, height: 300 })).toBeUndefined()+ expect(layout({ width: 40, height: 40 }, 2)).toHaveLength(1)+ })++ test('turn the whole arc with the start, keeping it within one turn', () => {+ const { node } = ellipse({ arcData: arc(0, 270) })+ expect(degrees(arcAtPoint(node, 'arcStart', at(-90, 75), false))).toEqual([270, 540, 0])+ expect(degrees(arcAtPoint(node, 'arcStart', at(160, 75), false))).toEqual([160, 430, 0])+ expect(degrees(arcAtPoint(node, 'arcStart', at(40, 75), false))).toEqual([40, 310, 0])+ })++ test('cut the slice the end crosses from a whole ellipse', () => {+ const { node } = ellipse()+ expect(degrees(arcAtPoint(node, 'arcEnd', at(90, 140), false))).toEqual([0, -270, 0])+ expect(degrees(arcAtPoint(node, 'arcEnd', at(-90, 140), false))).toEqual([0, 270, 0])+ })++ test('keep the end continuous and wrap it past a full turn', () => {+ const { node } = ellipse({ arcData: arc(0, 270) })+ expect(degrees(arcAtPoint(node, 'arcEnd', at(20, 75), false))).toEqual([0, -340, 0])+ node.arcData = arc(0, 350)+ expect(degrees(arcAtPoint(node, 'arcEnd', at(5, 75), false))).toEqual([0, 365 - 720, 0])+ node.arcData = arc(0, -340)+ expect(degrees(arcAtPoint(node, 'arcEnd', at(30, 75), false))).toEqual([0, -330, 0])+ })++ test('treat a sweep within 0.01° of a full turn as a whole ellipse, as it is drawn', () => {+ expect(layout({ arcData: arc(0, 359.995) })).toHaveLength(1)+ expect(layout({ arcData: arc(0, 359.98) })).toHaveLength(3)+ })++ test('drop the outline a .fig stored for the old arc', () => {+ const outline = [{ commandsBlob: new Uint8Array([1]), windingRule: 'NONZERO' as const }]+ const { node } = ellipse({ fillGeometry: outline, strokeGeometry: outline })+ expect(arcChanges(node, 'arcEnd', at(-90, 140), false)).toEqual({+ arcData: arc(0, 270),+ fillGeometry: [],+ strokeGeometry: []+ })+ })++ test('take the angle in the ellipse’s own space', () => {+ const { node } = ellipse({ width: 300, height: 150, arcData: arc(0, 90) })+ const corner = arcAtPoint(node, 'arcStart', { x: 300, y: 150 }, false)+ expect(corner.startingAngle).toBeCloseTo(45 * DEGREE, 6)+ })++ test('set the ratio from the distance in any direction, up to 1', () => {+ const { node } = ellipse({ arcData: arc(0, 270) })+ expect(arcAtPoint(node, 'arcRatio', at(200, 60), false).innerRadius).toBeCloseTo(0.4, 6)+ expect(arcAtPoint(node, 'arcRatio', at(10, 400), false).innerRadius).toBe(1)+ })++ test('round angles to 15° and the ratio to tenths with Shift', () => {+ const { node } = ellipse({ arcData: arc(0, 270) })+ expect(degrees(arcAtPoint(node, 'arcStart', at(52, 75), true))).toEqual([45, 315, 0])+ expect(degrees(arcAtPoint(node, 'arcEnd', at(-62, 75), true))).toEqual([0, 300, 0])+ expect(arcAtPoint(node, 'arcRatio', at(0, 59), true).innerRadius).toBeCloseTo(0.4, 6)+ })++ test('label the start in degrees and the sweep and ratio in percent', () => {+ const { node } = ellipse({ arcData: arc(45, 45 - 270, 0.396) })+ expect(shapeHandleValue(node, 'arcStart')).toBe('45°')+ expect(shapeHandleValue(node, 'arcEnd')).toBe('-75%')+ expect(shapeHandleValue(node, 'arcRatio')).toBe('39.6%')+ })+})diff --git a/packages/core/tests/geometry/shape-handles.test.ts b/packages/core/tests/geometry/handles/shape.test.tssimilarity index 99%rename from packages/core/tests/geometry/shape-handles.test.tsrename to packages/core/tests/geometry/handles/shape.test.tsindex 1668d08ae..4c26f3d57 100644--- a/packages/core/tests/geometry/shape-handles.test.ts+++ b/packages/core/tests/geometry/handles/shape.test.ts@@ -72,7 +72,6 @@ describe('shape handles', () => {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()})// Figma desktop, 2026-10-10: a 160 × 160 triangle's one handle sits below its top point, at thediff --git a/packages/vue/src/i18n/locales/de/editor.json b/packages/vue/src/i18n/locales/de/editor.jsonindex 9d10ea7da..a2dd8b759 100644--- a/packages/vue/src/i18n/locales/de/editor.json+++ b/packages/vue/src/i18n/locales/de/editor.json@@ -4,6 +4,9 @@"cornerRadius": "Radius","pointCount": "Anzahl","starRatio": "Verhältnis",+ "arcStart": "Anfang",+ "arcSweep": "Bogen",+ "arcRatio": "Verhältnis","stickyPlaceholder": "Beliebigen Text eingeben, jemanden mit @ erwähnen","showUI": "UI anzeigen ({shortcut})","previewing": "Vorschau",diff --git a/packages/vue/src/i18n/locales/es/editor.json b/packages/vue/src/i18n/locales/es/editor.jsonindex 8a107612e..72091d01e 100644--- a/packages/vue/src/i18n/locales/es/editor.json+++ b/packages/vue/src/i18n/locales/es/editor.json@@ -4,6 +4,9 @@"cornerRadius": "Redondeado","pointCount": "Cantidad","starRatio": "Proporción",+ "arcStart": "Inicio",+ "arcSweep": "Barrido",+ "arcRatio": "Proporción","stickyPlaceholder": "Escribe lo que quieras, @menciona a alguien","showUI": "Mostrar interfaz ({shortcut})","previewing": "Vista previa",diff --git a/packages/vue/src/i18n/locales/fr/editor.json b/packages/vue/src/i18n/locales/fr/editor.jsonindex e75c6bbfd..768cf574e 100644--- a/packages/vue/src/i18n/locales/fr/editor.json+++ b/packages/vue/src/i18n/locales/fr/editor.json@@ -4,6 +4,9 @@"cornerRadius": "Rayon","pointCount": "Nombre","starRatio": "Rapport",+ "arcStart": "Début",+ "arcSweep": "Balayage",+ "arcRatio": "Rapport","stickyPlaceholder": "Écrivez ce que vous voulez, @mentionnez quelqu’un","showUI": "Afficher l’interface ({shortcut})","previewing": "Aperçu",diff --git a/packages/vue/src/i18n/locales/it/editor.json b/packages/vue/src/i18n/locales/it/editor.jsonindex 9b970e09a..abca48a5e 100644--- a/packages/vue/src/i18n/locales/it/editor.json+++ b/packages/vue/src/i18n/locales/it/editor.json@@ -4,6 +4,9 @@"cornerRadius": "Raggio","pointCount": "Numero","starRatio": "Rapporto",+ "arcStart": "Inizio",+ "arcSweep": "Ampiezza",+ "arcRatio": "Rapporto","stickyPlaceholder": "Scrivi qualsiasi cosa, @menziona qualcuno","showUI": "Mostra interfaccia ({shortcut})","previewing": "Anteprima",diff --git a/packages/vue/src/i18n/locales/ja/editor.json b/packages/vue/src/i18n/locales/ja/editor.jsonindex 8fd5f2ecb..f8815f548 100644--- a/packages/vue/src/i18n/locales/ja/editor.json+++ b/packages/vue/src/i18n/locales/ja/editor.json@@ -4,6 +4,9 @@"cornerRadius": "角丸","pointCount": "数","starRatio": "比率",+ "arcStart": "開始",+ "arcSweep": "スイープ",+ "arcRatio": "比率","stickyPlaceholder": "自由に入力、@で誰かをメンション","showUI": "UIを表示 ({shortcut})","previewing": "プレビュー中",diff --git a/packages/vue/src/i18n/locales/pl/editor.json b/packages/vue/src/i18n/locales/pl/editor.jsonindex d1daddefb..22437b23e 100644--- a/packages/vue/src/i18n/locales/pl/editor.json+++ b/packages/vue/src/i18n/locales/pl/editor.json@@ -4,6 +4,9 @@"cornerRadius": "Promień","pointCount": "Liczba","starRatio": "Proporcja",+ "arcStart": "Początek",+ "arcSweep": "Zakres",+ "arcRatio": "Proporcja","stickyPlaceholder": "Wpisz cokolwiek, @wspomnij kogoś","showUI": "Pokaż interfejs ({shortcut})","previewing": "Podgląd",diff --git a/packages/vue/src/i18n/locales/ru/editor.json b/packages/vue/src/i18n/locales/ru/editor.jsonindex e8112a637..76fc69bf3 100644--- a/packages/vue/src/i18n/locales/ru/editor.json+++ b/packages/vue/src/i18n/locales/ru/editor.json@@ -4,6 +4,9 @@"cornerRadius": "Радиус","pointCount": "Количество","starRatio": "Соотношение",+ "arcStart": "Начало",+ "arcSweep": "Охват",+ "arcRatio": "Соотношение","stickyPlaceholder": "Пишите что угодно, @упоминайте кого угодно","showUI": "Показать интерфейс ({shortcut})","previewing": "Просмотр",diff --git a/packages/vue/src/i18n/locales/zh-cn/editor.json b/packages/vue/src/i18n/locales/zh-cn/editor.jsonindex 837a59827..652ef294d 100644--- a/packages/vue/src/i18n/locales/zh-cn/editor.json+++ b/packages/vue/src/i18n/locales/zh-cn/editor.json@@ -4,6 +4,9 @@"cornerRadius": "圆角","pointCount": "数量","starRatio": "比例",+ "arcStart": "起点",+ "arcSweep": "扫掠",+ "arcRatio": "比例","stickyPlaceholder": "输入任意内容,@提及任何人","showUI": "显示界面({shortcut})","previewing": "预览中",diff --git a/packages/vue/src/i18n/messages/editor.ts b/packages/vue/src/i18n/messages/editor.tsindex 47653353c..c5874ccf2 100644--- a/packages/vue/src/i18n/messages/editor.ts+++ b/packages/vue/src/i18n/messages/editor.ts@@ -11,6 +11,12 @@ export const editorMessageDefaults = {pointCount: 'Count',/** The word before a star's inner ratio beside its dragged handle. */starRatio: 'Ratio',+ /** The word before an ellipse arc's start angle beside its dragged handle. */+ arcStart: 'Start',+ /** The word before an ellipse arc's sweep, in percent of a turn, beside its dragged end handle. */+ arcSweep: 'Sweep',+ /** The word before an ellipse arc's inner ratio beside its dragged handle. */+ arcRatio: 'Ratio',/** What an empty sticky note shows in its body on the canvas. */stickyPlaceholder: 'Type anything, @mention anyone',showUI: params('Show UI ({shortcut})'),diff --git a/packages/vue/src/shared/input/shape-handles.ts b/packages/vue/src/shared/input/shape-handles.tsindex 3360b38fe..8f47bf71f 100644--- a/packages/vue/src/shared/input/shape-handles.ts+++ b/packages/vue/src/shared/input/shape-handles.ts@@ -1,11 +1,12 @@import type { Editor, ShapeHandleHover } from '@open-pencil/core/editor'import {+ arcChanges,cornerRadiusAtPoint,cornerRadiusChanges,createSceneGeometry,dragsSingleCorner,hitTestShapeHandles,- isRadiusHandle,+ isArcHandle,pointCountAtPoint,shapeHandleLayout,starRatioAtPoint,@@ -22,12 +23,18 @@ const HANDLE_DRAG_THRESHOLD_PX = 5function handleLabel(handle: ShapeHandleKind | null): string {const messages = editorMessages.get()+ if (handle === 'arcStart') return messages.arcStart+ if (handle === 'arcEnd') return messages.arcSweep+ if (handle === 'arcRatio') return messages.arcRatioif (handle === 'count') return messages.pointCountif (handle === 'ratio') return messages.starRatioreturn messages.cornerRadius}function undoLabel(handle: ShapeHandleKind): string {+ if (handle === 'arcStart') return 'Change arc start'+ if (handle === 'arcEnd') return 'Change arc sweep'+ if (handle === 'arcRatio') return 'Change arc ratio'if (handle === 'count') return 'Change point count'if (handle === 'ratio') return 'Change star ratio'return 'Change corner radius'@@ -84,6 +91,7 @@ function handleChanges(single: boolean,shiftKey: boolean): Partial<SceneNode> {+ if (isArcHandle(handle)) return arcChanges(node, handle, local, shiftKey)if (handle === 'count') return { pointCount: pointCountAtPoint(node, local) }if (handle === 'ratio') return { starInnerRadius: starRatioAtPoint(node, local) }const radius = cornerRadiusAtPoint(node, handle, local, shiftKey)@@ -92,7 +100,7 @@ function handleChanges(/** How far a count or ratio handle's centre lies from where it was grabbed, in the node's pixels. */function grabOffset(editor: Editor, node: SceneNode, handle: ShapeHandleKind, screen: Vector) {- if (isRadiusHandle(handle)) return { x: 0, y: 0 }+ if (handle !== 'count' && handle !== 'ratio') return { x: 0, y: 0 }const geometry = createSceneGeometry(editor.graph, editor.state.rotationPreview)const centre = shapeHandleLayout(node, geometry, editor.state)?.find((candidate) => candidate.handle === handle@@ -103,8 +111,8 @@ function grabOffset(editor: Editor, node: SceneNode, handle: ShapeHandleKind, sc}/**- * Starts dragging the shape handle under the pointer, if any, as in Figma desktop. A radius- * follows the pointer rather than the distance dragged and Shift rounds it to tens; the count and+ * Starts dragging the shape handle under the pointer, if any, as in Figma desktop. A radius or an+ * arc follows the pointer rather than the distance dragged and Shift rounds it; the count and* ratio handles keep where they were grabbed. Each drag is one undo step.*/export function tryStartShapeHandleDrag(diff --git a/tests/e2e/canvas/shape-handles/drag.spec.ts b/tests/e2e/canvas/shape-handles/drag.spec.tsindex 8333ecd23..84449b0dd 100644--- a/tests/e2e/canvas/shape-handles/drag.spec.ts+++ b/tests/e2e/canvas/shape-handles/drag.spec.ts@@ -92,3 +92,52 @@ test('a star changes its point count and ratio from the handles on its points',await editor.canvas.waitForRender()expect((await corners.points(nodeId))?.ratio).toBe(0.5)})++/** Canvas coordinates of a point at an angle, clockwise from three o'clock, and a distance from+ * the centre of the driver's 160 × 160 ellipse. */+function aroundEllipse(degrees: number, distance: number) {+ return corners.point(+ 80 + distance * Math.cos((degrees * Math.PI) / 180),+ 80 + distance * Math.sin((degrees * Math.PI) / 180)+ )+}++// Figma desktop: a whole ellipse's one handle, 10 px inside its edge at the start, cuts out the+// slice it is dragged across, in one undo step.+test('dragging a whole ellipse’s handle cuts out the slice it crosses', async () => {+ const nodeId = await corners.show({}, 'ELLIPSE')+ const from = aroundEllipse(0, 70)+ const to = aroundEllipse(90, 70)+ await editor.canvas.drag(from.x, from.y, to.x, to.y)+ await editor.canvas.waitForRender()+ expect(await corners.arc(nodeId)).toEqual({ start: 0, end: -270, ratio: 0 })++ await editor.canvas.undo()+ expect(await corners.arc(nodeId)).toBeNull()+ editor.canvas.assertNoErrors()+})++// Figma desktop: an arc's start handle, halfway across its edge, turns the arc and keeps its+// sweep, Shift rounding to 15°; its ratio handle sets the hole from the distance to the centre,+// Shift rounding to tenths.+test('an arc turns from its start handle and opens a hole from its ratio handle', async () => {+ const nodeId = await corners.show(+ { arcData: { startingAngle: 0, endingAngle: Math.PI * 1.5, innerRadius: 0 } },+ 'ELLIPSE'+ )+ const start = aroundEllipse(0, 40)+ const turned = aroundEllipse(50, 40)+ await editor.page.keyboard.down('Shift')+ await editor.canvas.drag(start.x, start.y, turned.x, turned.y)+ await editor.page.keyboard.up('Shift')+ await editor.canvas.waitForRender()+ expect(await corners.arc(nodeId)).toEqual({ start: 45, end: 315, ratio: 0 })++ const centre = aroundEllipse(0, 0)+ const out = aroundEllipse(180, 43)+ await editor.page.keyboard.down('Shift')+ await editor.canvas.drag(centre.x, centre.y, out.x, out.y)+ await editor.page.keyboard.up('Shift')+ await editor.canvas.waitForRender()+ expect(await corners.arc(nodeId)).toEqual({ start: 45, end: 315, ratio: 0.5 })+})diff --git a/tests/e2e/canvas/shape-handles/visual.spec.ts b/tests/e2e/canvas/shape-handles/visual.spec.tsindex 35323b297..15cfe91fd 100644--- a/tests/e2e/canvas/shape-handles/visual.spec.ts+++ b/tests/e2e/canvas/shape-handles/visual.spec.ts@@ -41,3 +41,33 @@ test('a star under the pointer, its count handle hovered', async () => {expect(await editor.canvas.screenshotCanvasRegion(360, 360)).toMatchSnapshot('star.png')editor.canvas.assertNoErrors()})++// Figma desktop: an arc's start handle carries a dot, its end handle and the ratio handle on the+// inner edge mid-sweep are plain, and the dragged handle's label shows the sweep in percent.+test('a ring arc, its end handle hovered', async () => {+ await corners.show(+ { arcData: { startingAngle: Math.PI / 4, endingAngle: Math.PI * 1.75, innerRadius: 0.4 } },+ 'ELLIPSE'+ )+ const centre = corners.point(80, 140)+ await editor.canvas.hover(centre.x, centre.y)+ const angle = Math.PI * 1.75+ const end = corners.point(80 + 56 * Math.cos(angle), 80 + 56 * Math.sin(angle))+ await editor.canvas.hover(end.x, end.y)+ expect(await editor.canvas.screenshotCanvasRegion(360, 360)).toMatchSnapshot('arc.png')+ editor.canvas.assertNoErrors()+})++// Figma desktop: a pie's edges run straight to the centre, where its ratio handle sits.+test('a pie, its start handle hovered', async () => {+ await corners.show(+ { arcData: { startingAngle: 0, endingAngle: Math.PI * 1.5, innerRadius: 0 } },+ 'ELLIPSE'+ )+ const inside = corners.point(60, 120)+ await editor.canvas.hover(inside.x, inside.y)+ const start = corners.point(120, 80)+ await editor.canvas.hover(start.x, start.y)+ expect(await editor.canvas.screenshotCanvasRegion(360, 360)).toMatchSnapshot('pie.png')+ editor.canvas.assertNoErrors()+})diff --git a/tests/e2e/canvas/shape-handles/visual.spec.ts-snapshots/arc-openpencil-darwin.png b/tests/e2e/canvas/shape-handles/visual.spec.ts-snapshots/arc-openpencil-darwin.pngnew file mode 100644index 000000000..94376edd3Binary files /dev/null and b/tests/e2e/canvas/shape-handles/visual.spec.ts-snapshots/arc-openpencil-darwin.png differdiff --git a/tests/e2e/canvas/shape-handles/visual.spec.ts-snapshots/pie-openpencil-darwin.png b/tests/e2e/canvas/shape-handles/visual.spec.ts-snapshots/pie-openpencil-darwin.pngnew file mode 100644index 000000000..2f8ab6520Binary files /dev/null and b/tests/e2e/canvas/shape-handles/visual.spec.ts-snapshots/pie-openpencil-darwin.png differdiff --git a/tests/helpers/canvas/shape-handles-driver.ts b/tests/helpers/canvas/shape-handles-driver.tsindex 3ac5a54a0..bb065907b 100644--- a/tests/helpers/canvas/shape-handles-driver.ts+++ b/tests/helpers/canvas/shape-handles-driver.ts@@ -14,15 +14,16 @@ type CornerProps = Partial<| 'cornerSmoothing'| 'pointCount'| 'starInnerRadius'+ | 'arcData'>>-type CornerShape = 'RECTANGLE' | 'POLYGON' | 'STAR'+type CornerShape = 'RECTANGLE' | 'POLYGON' | 'STAR' | 'ELLIPSE'/** Shows a selected shape at 100% with its top-left 100 px into the canvas, and reads its radii. */export function shapeHandlesDriver(page: () => Page) {return {- /** A 160 × 232 rectangle, or a 160 × 160 polygon or star, selected. */+ /** A 160 × 232 rectangle, or a 160 × 160 polygon, star, or ellipse, selected. */show(props: CornerProps = {}, type: CornerShape = 'RECTANGLE') {return page().evaluate(({ props, type }) => {@@ -73,6 +74,20 @@ export function shapeHandlesDriver(page: () => Page) {const node = window.openPencil?.getStore?.().graph.getNode(id)return node ? { count: node.pointCount, ratio: node.starInnerRadius } : null}, nodeId)+ },++ /** An ellipse's start and end in whole degrees and its inner ratio, or null for a whole one. */+ arc(nodeId: string) {+ return page().evaluate((id) => {+ const arc = window.openPencil?.getStore?.().graph.getNode(id)?.arcData+ if (!arc) return null+ const degrees = (angle: number) => Math.round((angle * 180) / Math.PI)+ return {+ start: degrees(arc.startingAngle),+ end: degrees(arc.endingAngle),+ ratio: Math.round(arc.innerRadius * 1000) / 1000+ }+ }, nodeId)}}}