Skip to content

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

fix(components): make a component's vector path reach its instances (#1096)

Danila Poyarkove30e34c32553
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8ce5788bd..b9dd25fc3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@
### Added
+- Enter opens a selected vector's path for editing, as a double-click does, as in Figma.
- Text keeps a case, a link, text and fill styles, and variable bindings for any range of its characters, as in Figma: the canvas draws each range in its own case, `.fig` files and the Figma clipboard keep them, apart from font weight bindings, HTML, Tailwind, and JSX exports write links as `<a href>` and cases as `text-transform` and HTML import reads them back, Design JSX `<Span>` takes `textCase` and `href`, and the Typography section's text case changes the selected characters while text is edited. Scripts read and set them with `getRangeTextCase`, `setRangeTextCase`, `getRangeHyperlink`, `setRangeHyperlink`, `getRangeTextStyleId`, `setRangeTextStyleIdAsync`, `getRangeFillStyleId`, `setRangeFillStyleIdAsync`, `getRangeBoundVariable`, `setRangeBoundVariable`, and the text's `hyperlink`.
- Switch a frame to a group and back from the layer type menu in the properties panel header, as in Figma. A frame becomes a group that keeps its layers, effects, and opacity and fits them; a group becomes a frame of its bounds that clips.
- Edit the layout guides of several frames at once: the panel lists them while the frames' guides match and edits every frame in one undo step, and while they differ offers Add, which gives each frame one new guide. A new guide is Figma's 10 px grid.
@@ -26,6 +27,7 @@
- In scripts, `setProperties` switches an instance's variant, alongside its other properties, and fails without changing anything when no variant has the values, with Figma's messages; `resize` places a frame's layers by their constraints while `resizeWithoutConstraints` leaves them, and an instance's layers follow their constraints either way.
- **Settings…** (<kbd>⌘</kbd><kbd>,</kbd>) is in the **OpenPencil** menu on macOS and at the end of the **File** menu elsewhere, instead of under **View → Preferences**.
- The demo at `/demo` is a tour of one player card in eight chapters stacked on one canvas, each showing one thing with a numbered card that says what to try and draws the piece of the app to click: preview, the artwork slot, the controls' behaviours, the theme's modes, shader fills, the Code tab, Lint on a card with planted issues, and sharing and opening your own files. It opens on the first chapter with the rest below it and follows the app's light or dark theme. The welcome dialog on first launch offers it next to AI setup, and File > Open the Tour opens it any time.
+- In scripts, a vector inside an instance refuses `vectorPaths`, `vectorNetwork`, `setVectorNetworkAsync`, and `handleMirroring` with Figma's errors, such as `in set_vectorPaths: This property cannot be overridden in an instance: vector-data`, since its path always follows the component.
### Fixed
@@ -50,6 +52,7 @@
- The properties panel shows the shared styles layers use in opened `.fig` files, where it listed them as missing styles.
- Styles made in OpenPencil, by importing design tokens or by pasting layers from another document, are saved in `.fig` files as styles, and layers reopen with them. Saving wrote their references empty, so reopening dropped the styles, and saving into an opened file made them layers of the page in Figma.
- Layers and text that use a library style keep it in Figma after OpenPencil saves them, where Figma showed them with no style.
+- A path edited in a component reaches its instances, as in Figma, scaled with each copy where constraints or a resized instance changed its size; copies whose instance overrides their fill or stroke keep those. A vector inside an instance no longer opens for path editing, which would have been undone by the next component edit. Straight lines in resized instances of `.fig` files open at the length Figma draws them instead of their component's.
## 0.16.0-beta.1 — 2026-10-11
diff --git a/packages/core/src/figma-api/accessor-utils.ts b/packages/core/src/figma-api/accessor-utils.ts
index 79784c6a6..3a210077e 100644
--- a/packages/core/src/figma-api/accessor-utils.ts
+++ b/packages/core/src/figma-api/accessor-utils.ts
@@ -40,22 +40,29 @@ export function assertProxyEditable(target: ProxyThis, internals: NodeProxyInter
/**
* Readies an edit to a field a layer inside an instance always takes from its component. Figma
- * refuses it there, naming the property it would have overridden (Figma desktop 126). Slot
- * content is the instance's own and keeps the edit: a slot still showing the component's default
- * content is claimed first, as Figma does on the first edit, so a later sync leaves it alone.
+ * refuses it there, naming the setter and the property it would have overridden (Figma desktop
+ * 126); an async method's rejection names no setter, so it passes none. Slot content is the
+ * instance's own and keeps the edit: a slot still showing the component's default content is
+ * claimed first, as Figma does on the first edit, so a later sync leaves it alone.
*/
export function prepareFollowedFieldEdit(
scene: SceneGraph,
node: SceneNode,
- setter: string,
- property: 'relative-transform' | 'vertical-constraint' | 'is-mask' | 'mask-type'
+ setter: string | null,
+ property:
+ | 'relative-transform'
+ | 'vertical-constraint'
+ | 'is-mask'
+ | 'mask-type'
+ | 'vector-data'
+ | 'handle-mirroring'
): void {
if (!node.parentId) return
const scope = slotScope(scene, node.parentId)
- if (scope.kind === 'locked')
- throw new Error(
- `in set_${setter}: This property cannot be overridden in an instance: ${property}`
- )
+ if (scope.kind === 'locked') {
+ const message = `This property cannot be overridden in an instance: ${property}`
+ throw new Error(setter ? `in set_${setter}: ${message}` : message)
+ }
if (scope.kind === 'slot') claimSlotContent(scene, scope)
}
diff --git a/packages/core/src/figma-api/accessors/vector.ts b/packages/core/src/figma-api/accessors/vector.ts
index d3da69781..77d201708 100644
--- a/packages/core/src/figma-api/accessors/vector.ts
+++ b/packages/core/src/figma-api/accessors/vector.ts
@@ -17,6 +17,8 @@ import { copyFills } from '@open-pencil/scene-graph/copy'
import { parsePluginVectorPath } from '@open-pencil/scene-graph/parse-path'
import {
+ graph,
+ prepareFollowedFieldEdit,
raw,
updateNode,
type NodeProxyInternals,
@@ -144,16 +146,29 @@ function setGeometry(
})
}
+/** A vector inside an instance draws its component's path, which Figma refuses to override. */
+function prepareVectorDataEdit(
+ target: ProxyThis,
+ internals: NodeProxyInternals,
+ setter: string | null
+): void {
+ prepareFollowedFieldEdit(graph(target, internals), raw(target, internals), setter, 'vector-data')
+}
+
+/** Checks the network before readying the edit, so a rejected one leaves a slot unclaimed. */
function assignVectorNetwork(
target: ProxyThis,
internals: NodeProxyInternals,
- value: FigmaVectorNetwork
+ value: FigmaVectorNetwork,
+ setter: string | null
): void {
const errors = validateVectorNetwork(value)
if (errors.length > 0) throw new TypeError(`Invalid vectorNetwork: ${errors.join('; ')}`)
validateRegionPaintMetadata(value.regions ?? [])
const network = normalizeInputNetwork(value)
- setGeometry(target, internals, network, geometryForRegions(value.regions ?? []))
+ const fillGeometry = geometryForRegions(value.regions ?? [])
+ prepareVectorDataEdit(target, internals, setter)
+ setGeometry(target, internals, network, fillGeometry)
}
function vectorPathsForNetwork(network: SceneVectorNetwork): FigmaVectorPath[] {
@@ -266,7 +281,9 @@ export function installVectorNodeProxyAccessors(
},
set(this: ProxyThis, value: readonly FigmaVectorPath[]) {
if (!Array.isArray(value)) throw new TypeError('vectorPaths must be an array')
- setGeometry(this, internals, networkFromVectorPaths(value), [])
+ const network = networkFromVectorPaths(value)
+ prepareVectorDataEdit(this, internals, 'vectorPaths')
+ setGeometry(this, internals, network, [])
},
enumerable: true,
configurable: true
@@ -276,14 +293,19 @@ export function installVectorNodeProxyAccessors(
return readVectorNetwork(this, internals)
},
set(this: ProxyThis, value: FigmaVectorNetwork) {
- assignVectorNetwork(this, internals, value)
+ assignVectorNetwork(this, internals, value, 'vectorNetwork')
},
enumerable: true,
configurable: true
},
setVectorNetworkAsync: {
value(this: ProxyThis, value: FigmaVectorNetwork): Promise<void> {
- return Promise.resolve().then(() => assignVectorNetwork(this, internals, value))
+ try {
+ assignVectorNetwork(this, internals, value, null)
+ return Promise.resolve()
+ } catch (error) {
+ return Promise.reject(error instanceof Error ? error : new Error(String(error)))
+ }
},
enumerable: true,
configurable: true
@@ -297,6 +319,12 @@ export function installVectorNodeProxyAccessors(
throw new TypeError(`Invalid handleMirroring: ${String(value)}`)
}
const node = raw(this, internals)
+ prepareFollowedFieldEdit(
+ graph(this, internals),
+ node,
+ 'handleMirroring',
+ 'handle-mirroring'
+ )
updateNode(this, internals, {
handleMirroring: value,
vectorNetwork: node.vectorNetwork
diff --git a/packages/core/tests/figma-api/instance-overrides.test.ts b/packages/core/tests/figma-api/instance-overrides.test.ts
index 541fb4ae8..ddf9eaf99 100644
--- a/packages/core/tests/figma-api/instance-overrides.test.ts
+++ b/packages/core/tests/figma-api/instance-overrides.test.ts
@@ -3,7 +3,11 @@ import { expect, test } from 'bun:test'
import { expectDefined } from '#core-tests/helpers/assert'
import { FigmaAPI, type FigmaNodeProxy } from '@open-pencil/core/figma-api'
-import { createComponentPropertyId, hasInstanceOverride, SceneGraph } from '@open-pencil/scene-graph'
+import {
+ createComponentPropertyId,
+ hasInstanceOverride,
+ SceneGraph
+} from '@open-pencil/scene-graph'
// Recorded with the same script in Figma desktop 126.
@@ -25,9 +29,13 @@ test('a layer inside an instance refuses the fields it always takes from its com
expect(() => (layer.x = 5)).toThrow(refused('x', 'relative-transform'))
expect(() => (layer.y = 5)).toThrow(refused('y', 'relative-transform'))
expect(() => (layer.rotation = 10)).toThrow(refused('rotation', 'relative-transform'))
- expect(() => (layer.relativeTransform = [[1, 0, 3], [0, 1, 3]])).toThrow(
- refused('relativeTransform', 'relative-transform')
- )
+ expect(
+ () =>
+ (layer.relativeTransform = [
+ [1, 0, 3],
+ [0, 1, 3]
+ ])
+ ).toThrow(refused('relativeTransform', 'relative-transform'))
expect(() => (layer.constraints = { horizontal: 'MAX', vertical: 'MIN' })).toThrow(
refused('constraints', 'vertical-constraint')
)
@@ -35,6 +43,42 @@ test('a layer inside an instance refuses the fields it always takes from its com
expect(() => (layer.maskType = 'LUMINANCE')).toThrow(refused('maskType', 'mask-type'))
})
+test('a vector inside an instance refuses its path and handle mirroring', async () => {
+ const graph = new SceneGraph()
+ const figma = new FigmaAPI(graph)
+ const component = figma.createComponent()
+ component.resize(200, 120)
+ const shape = figma.createVector()
+ component.appendChild(shape)
+ shape.vectorPaths = [{ windingRule: 'NONZERO', data: 'M 0 0 L 100 0 L 50 80 Z' }]
+ const instance = component.createInstance()
+ const [copy] = instance.children as FigmaNodeProxy[]
+ const message = (property: string) =>
+ `This property cannot be overridden in an instance: ${property}`
+ const network = {
+ vertices: [
+ { x: 0, y: 0 },
+ { x: 60, y: 0 }
+ ],
+ segments: [{ start: 0, end: 1 }]
+ }
+ expect(() => (copy.vectorPaths = [{ windingRule: 'NONE', data: 'M 0 0 L 10 0' }])).toThrow(
+ `in set_vectorPaths: ${message('vector-data')}`
+ )
+ expect(() => (copy.vectorNetwork = network)).toThrow(
+ `in set_vectorNetwork: ${message('vector-data')}`
+ )
+ // Figma rejects the async edit with the bare message.
+ await expect(copy.setVectorNetworkAsync(network)).rejects.toThrow(
+ new RegExp(`^${message('vector-data')}$`)
+ )
+ expect(() => (copy.handleMirroring = 'ANGLE')).toThrow(
+ `in set_handleMirroring: ${message('handle-mirroring')}`
+ )
+ // The copy still draws the component's path.
+ expect(copy.vectorPaths).toEqual(shape.vectorPaths)
+})
+
test('a layer inside an instance can be locked and restyled, each recorded as an override', () => {
const { graph, instance, layer } = setup()
layer.locked = true
@@ -67,6 +111,36 @@ function slotSetup() {
return { graph, figma, card, note, slot }
}
+test('a path rejected for a slot’s vector leaves the slot following its component', () => {
+ const { graph, figma, card, slot } = slotSetup()
+ const shape = figma.createVector()
+ const host = expectDefined(figma.getNodeById(graph.getChildren(card.id)[0].id))
+ host.appendChild(shape)
+ shape.vectorPaths = [{ windingRule: 'NONZERO', data: 'M 0 0 L 10 0 L 5 10 Z' }]
+ graph.syncInstances(card.id)
+ const copy = expectDefined(
+ (slot.children as FigmaNodeProxy[]).find((child) => child.type === 'VECTOR')
+ )
+ const broken = {
+ vertices: [
+ { x: 0, y: 0 },
+ { x: 10, y: 0 },
+ { x: 5, y: 10 }
+ ],
+ segments: [
+ { start: 0, end: 1 },
+ { start: 1, end: 2 },
+ { start: 2, end: 0 }
+ ],
+ regions: [{ windingRule: 'NONZERO' as const, loops: [[0, 1, 2]], fills: [null] }]
+ }
+ expect(() => (copy.vectorNetwork = broken as never)).toThrow()
+ // Unclaimed, the slot's default content still takes the component's next edit.
+ shape.vectorPaths = [{ windingRule: 'NONZERO', data: 'M 0 0 L 20 0 L 10 20 Z' }]
+ graph.syncInstances(card.id)
+ expect(copy.vectorPaths).toEqual(shape.vectorPaths)
+})
+
test('slot content is the instance’s own and keeps its position and constraints', () => {
const { figma, slot } = slotSetup()
const added = figma.createRectangle()
diff --git a/packages/fig/src/node-change/vector/geometry.ts b/packages/fig/src/node-change/vector/geometry.ts
index a318aac31..66ef29165 100644
--- a/packages/fig/src/node-change/vector/geometry.ts
+++ b/packages/fig/src/node-change/vector/geometry.ts
@@ -56,9 +56,10 @@ export function resolveVectorNetwork(nc: NodeChange, blobs: Uint8Array[]): Vecto
const ns = vectorData.normalizedSize
const nodeW = nc.size?.x ?? 0
const nodeH = nc.size?.y ?? 0
- if (ns && nodeW > 0 && nodeH > 0 && (ns.x !== nodeW || ns.y !== nodeH)) {
- const sx = nodeW / ns.x
- const sy = nodeH / ns.y
+ // Each axis scales on its own: a straight line has no extent across it to scale.
+ const sx = ns && ns.x > 0 && nodeW > 0 ? nodeW / ns.x : 1
+ const sy = ns && ns.y > 0 && nodeH > 0 ? nodeH / ns.y : 1
+ if (sx !== 1 || sy !== 1) {
for (const v of network.vertices) {
v.x *= sx
v.y *= sy
diff --git a/packages/fig/tests/node-change/vector/geometry.test.ts b/packages/fig/tests/node-change/vector/geometry.test.ts
new file mode 100644
index 000000000..5f8cc1f88
--- /dev/null
+++ b/packages/fig/tests/node-change/vector/geometry.test.ts
@@ -0,0 +1,42 @@
+import { expect, test } from 'bun:test'
+
+import { resolveVectorNetwork } from '#fig/node-change/vector/geometry'
+import { encodeVectorNetworkBlob } from '#fig/node-change/vector/network'
+
+import type { NodeChange } from '@open-pencil/kiwi/fig/codec'
+import type { Vector } from '@open-pencil/scene-graph/primitives'
+
+/** A node whose path was saved at `normalized` and is drawn at `size`, as Figma saves copies. */
+function savedPath(normalized: Vector, size: Vector) {
+ const blob = encodeVectorNetworkBlob({
+ vertices: [
+ { x: 0, y: 0 },
+ { x: normalized.x, y: normalized.y }
+ ],
+ segments: [{ start: 0, end: 1, tangentStart: { x: 0, y: 0 }, tangentEnd: { x: 0, y: 0 } }],
+ regions: []
+ })
+ const node: NodeChange = {
+ size,
+ vectorData: { vectorNetworkBlob: 0, normalizedSize: normalized }
+ }
+ return resolveVectorNetwork(node, [blob])
+}
+
+test('a saved path scales to the size it is drawn at, a straight line along its length only', () => {
+ const ends = (normalized: Vector, size: Vector) =>
+ savedPath(normalized, size)?.vertices.map(({ x, y }) => [x, y])
+ expect(ends({ x: 12, y: 12 }, { x: 4, y: 4 })).toEqual([
+ [0, 0],
+ [4, 4]
+ ])
+ // A line in an instance scaled to 18 of 24 px, as Figma desktop 126 saves it.
+ expect(ends({ x: 9, y: 0 }, { x: 6.75, y: 0 })).toEqual([
+ [0, 0],
+ [6.75, 0]
+ ])
+ expect(ends({ x: 0, y: 16 }, { x: 0, y: 12 })).toEqual([
+ [0, 0],
+ [0, 12]
+ ])
+})
diff --git a/packages/scene-graph/src/instances/sync.ts b/packages/scene-graph/src/instances/sync.ts
index 1c204a4cb..f9cd87cd8 100644
--- a/packages/scene-graph/src/instances/sync.ts
+++ b/packages/scene-graph/src/instances/sync.ts
@@ -23,6 +23,7 @@ import {
} from './copies'
import { INSTANCE_SYNC_FIELD_OWNERS, INSTANCE_SYNC_FIELDS } from './fields'
import { PLACEMENT_FIELDS, placedByConstraints } from './placement'
+import { followVectorGeometry } from './vector-geometry'
function setSceneProp<K extends keyof SceneNode>(
target: Partial<SceneNode>,
@@ -152,6 +153,7 @@ function copySyncedFields(
if (isEqual(copy[key], from[key])) continue
copyProp(updates, from, key)
}
+ followVectorGeometry(updates, copy, source)
remeasureChangedText(updates, copy)
}
@@ -519,9 +521,7 @@ export function syncChildren(
overrides: InstanceOverrideState,
context: InstanceSyncContext = createInstanceSyncContext(instParentId, overrides)
): void {
- // Guard against cyclic sync: if the instance parent is inside the component's own
- // subtree, syncing would clone the component into itself — a self-referential cycle
- // that causes unbounded recursion and OOM.
+ // An instance inside its own component would clone the component into itself without end.
if (isCyclicSync(graph, compParentId, instParentId)) return
const compParent = graph.nodes.get(compParentId)
diff --git a/packages/scene-graph/src/instances/vector-geometry.ts b/packages/scene-graph/src/instances/vector-geometry.ts
new file mode 100644
index 000000000..f8900ad03
--- /dev/null
+++ b/packages/scene-graph/src/instances/vector-geometry.ts
@@ -0,0 +1,81 @@
+import { isEqual } from 'es-toolkit/predicate'
+
+import type { SceneNode, VectorNetwork } from '../'
+import { copyGeometryPaths, scaleGeometryPaths } from '../copy'
+import { cloneVectorNetwork, transformVectorNetwork } from '../vector-network'
+
+/** How far apart two paths' points may be and still count as one path, in pixels. */
+const PATH_TOLERANCE = 1e-3
+
+/** The stroke fields a vector's stroke outline is drawn from. */
+const STROKE_OUTLINE_FIELDS = [
+ 'strokes',
+ 'strokeWeight',
+ 'strokeAlign',
+ 'strokeCap',
+ 'strokeJoin',
+ 'strokeMiterLimit',
+ 'dashPattern'
+] as const
+
+const near = (a: number, b: number) => Math.abs(a - b) <= PATH_TOLERANCE
+
+/** Whether two paths are one, up to the float error that files and scaling leave. */
+function samePath(a: VectorNetwork | null, b: VectorNetwork | null): boolean {
+ if (!a || !b) return a === b
+ if (a.vertices.length !== b.vertices.length || a.segments.length !== b.segments.length)
+ return false
+ const sameVertices = a.vertices.every((vertex, index) => {
+ const { x, y, ...rest } = vertex
+ const { x: otherX, y: otherY, ...otherRest } = b.vertices[index]
+ return near(x, otherX) && near(y, otherY) && isEqual(rest, otherRest)
+ })
+ const sameSegments = a.segments.every((segment, index) => {
+ const other = b.segments[index]
+ return (
+ segment.start === other.start &&
+ segment.end === other.end &&
+ near(segment.tangentStart.x, other.tangentStart.x) &&
+ near(segment.tangentStart.y, other.tangentStart.y) &&
+ near(segment.tangentEnd.x, other.tangentEnd.x) &&
+ near(segment.tangentEnd.y, other.tangentEnd.y)
+ )
+ })
+ return sameVertices && sameSegments && isEqual(a.regions, b.regions)
+}
+
+/**
+ * Gives a vector's copy its component's path, which Figma refuses to override in an instance
+ * ("vector-data"), so every edit to the path reaches the copies, drawn at the size the copy ends
+ * up with. A copy whose path already matches keeps its own outlines, which may differ from the
+ * component's where the instance overrides its fills or strokes. A changed path brings the
+ * component's outlines with it, the stroke's only while the copy strokes as the component does;
+ * otherwise the canvas draws the stroke from the new path.
+ */
+export function followVectorGeometry(
+ updates: Partial<SceneNode>,
+ copy: SceneNode,
+ source: SceneNode
+): void {
+ if (source.type !== 'VECTOR') return
+ const width = updates.width ?? copy.width
+ const height = updates.height ?? copy.height
+ // A straight line has no extent across it, so that axis keeps its scale.
+ const sx = source.width > 0 ? width / source.width : 1
+ const sy = source.height > 0 ? height / source.height : 1
+ const scaled = sx !== 1 || sy !== 1
+ const scaledNetwork = (network: VectorNetwork) =>
+ scaled
+ ? transformVectorNetwork([sx, 0, 0, 0, sy, 0, 0, 0, 1], network)
+ : cloneVectorNetwork(network)
+ const network = source.vectorNetwork ? scaledNetwork(source.vectorNetwork) : null
+ if (samePath(copy.vectorNetwork, network)) return
+ const outlines = (paths: SceneNode['fillGeometry']) =>
+ scaled ? scaleGeometryPaths(paths, sx, sy) : copyGeometryPaths(paths)
+ const strokesAlike = STROKE_OUTLINE_FIELDS.every((field) =>
+ isEqual(updates[field] ?? copy[field], source[field])
+ )
+ updates.vectorNetwork = network
+ updates.fillGeometry = outlines(source.fillGeometry)
+ updates.strokeGeometry = strokesAlike ? outlines(source.strokeGeometry) : []
+}
diff --git a/packages/scene-graph/tests/components/sync-field-contract.test.ts b/packages/scene-graph/tests/components/sync-field-contract.test.ts
index a7804b945..912f6bfd7 100644
--- a/packages/scene-graph/tests/components/sync-field-contract.test.ts
+++ b/packages/scene-graph/tests/components/sync-field-contract.test.ts
@@ -136,6 +136,159 @@ test('restyled ranges reach instances, except one that overrides its text', () =
expect(copy.styleRuns).toEqual(runs)
})
+/** A closed polygon through the points, as a vector network. */
+function polygon(points: Array<[number, number]>): NonNullable<SceneNode['vectorNetwork']> {
+ return {
+ vertices: points.map(([x, y]) => ({ x, y })),
+ segments: points.map((_, index) => ({
+ start: index,
+ end: (index + 1) % points.length,
+ tangentStart: { x: 0, y: 0 },
+ tangentEnd: { x: 0, y: 0 }
+ })),
+ regions: [{ windingRule: 'NONZERO', loops: [points.map((_, index) => index)] }]
+ }
+}
+
+const corners = (network: SceneNode['vectorNetwork']) => network?.vertices.map(({ x, y }) => [x, y])
+
+test('a path edited in a component reaches its instances, drawn at their size', () => {
+ // Repeats a Figma desktop 126 script: an instance cannot override a vector's path
+ // ("vector-data"), so every edit of the component's path reaches it, scaled with the layer.
+ const graph = new SceneGraph()
+ const page = graph.getPages()[0].id
+ const card = graph.createNode('COMPONENT', page, { width: 200, height: 120 })
+ const shape = graph.createNode('VECTOR', card.id, {
+ x: 20,
+ y: 20,
+ width: 100,
+ height: 80,
+ vectorNetwork: polygon([
+ [0, 0],
+ [100, 0],
+ [50, 80]
+ ]),
+ horizontalConstraint: 'SCALE',
+ verticalConstraint: 'SCALE'
+ })
+ const plain = expectDefined(graph.createInstance(card.id, page))
+ const doubled = expectDefined(graph.createInstance(card.id, page))
+ // Resized as Figma's resize records it, as the instance's own size.
+ graph.updateNode(doubled.id, { width: 400, height: 240 })
+ for (const field of ['width', 'height'])
+ setInstanceOverride(doubled.instanceOverrides, doubled.id, doubled.id, field, true)
+ const copyIn = (instance: SceneNode) => graph.getChildren(instance.id)[0]
+
+ graph.updateNode(shape.id, {
+ width: 120,
+ height: 90,
+ vectorNetwork: polygon([
+ [0, 0],
+ [120, 0],
+ [60, 90]
+ ])
+ })
+ graph.syncInstances(card.id)
+ expect(corners(copyIn(plain).vectorNetwork)).toEqual([
+ [0, 0],
+ [120, 0],
+ [60, 90]
+ ])
+ expect([copyIn(doubled).width, copyIn(doubled).height]).toEqual([240, 180])
+ expect(corners(copyIn(doubled).vectorNetwork)).toEqual([
+ [0, 0],
+ [240, 0],
+ [120, 180]
+ ])
+})
+
+test('a copy keeps its own outlines while its path matches, and drops a stale stroke outline', () => {
+ // As in Figma files, a copy whose instance overrides its fill or stroke weight has outlines of
+ // its own; only a changed path replaces them.
+ const graph = new SceneGraph()
+ const page = graph.getPages()[0].id
+ const card = graph.createNode('COMPONENT', page, { width: 40, height: 40 })
+ const outline = (byte: number) => [
+ { windingRule: 'NONZERO' as const, commandsBlob: new Uint8Array([byte]) }
+ ]
+ const shape = graph.createNode('VECTOR', card.id, {
+ width: 20,
+ height: 20,
+ vectorNetwork: polygon([
+ [0, 0],
+ [20, 0],
+ [10, 20]
+ ]),
+ strokeGeometry: outline(1)
+ })
+ const instance = expectDefined(graph.createInstance(card.id, page))
+ const copy = graph.getChildren(instance.id)[0]
+ graph.updateNode(copy.id, {
+ strokeWeight: 4,
+ fillGeometry: outline(7),
+ strokeGeometry: outline(8)
+ })
+ setInstanceOverride(instance.instanceOverrides, instance.id, copy.id, 'strokeWeight', true)
+
+ graph.syncInstances(card.id)
+ expect([...copy.fillGeometry[0].commandsBlob, ...copy.strokeGeometry[0].commandsBlob]).toEqual([
+ 7, 8
+ ])
+
+ graph.updateNode(shape.id, {
+ vectorNetwork: polygon([
+ [0, 0],
+ [20, 0],
+ [20, 20]
+ ])
+ })
+ graph.syncInstances(card.id)
+ expect(corners(copy.vectorNetwork)).toEqual([
+ [0, 0],
+ [20, 0],
+ [20, 20]
+ ])
+ expect(copy.fillGeometry).toEqual([])
+ expect(copy.strokeGeometry).toEqual([])
+})
+
+test('a component line, with no height, still reaches its instances', () => {
+ const graph = new SceneGraph()
+ const page = graph.getPages()[0].id
+ const card = graph.createNode('COMPONENT', page, { width: 100, height: 40 })
+ const line = graph.createNode('VECTOR', card.id, {
+ y: 20,
+ width: 60,
+ height: 0,
+ vectorNetwork: {
+ vertices: [
+ { x: 0, y: 0 },
+ { x: 60, y: 0 }
+ ],
+ segments: [{ start: 0, end: 1, tangentStart: { x: 0, y: 0 }, tangentEnd: { x: 0, y: 0 } }],
+ regions: []
+ }
+ })
+ const instance = expectDefined(graph.createInstance(card.id, page))
+ const copy = graph.getChildren(instance.id)[0]
+ graph.updateNode(line.id, {
+ width: 80,
+ vectorNetwork: {
+ vertices: [
+ { x: 0, y: 0 },
+ { x: 80, y: 0 }
+ ],
+ segments: [{ start: 0, end: 1, tangentStart: { x: 0, y: 0 }, tangentEnd: { x: 0, y: 0 } }],
+ regions: []
+ }
+ })
+ graph.syncInstances(card.id)
+ expect(corners(copy.vectorNetwork)).toEqual([
+ [0, 0],
+ [80, 0]
+ ])
+})
+
test('a copy that sizes itself to its own content keeps that size through a component edit', () => {
// A badge's count, as in gold-preview's lists: the instance's text is its own, the component's
// a longer placeholder, and Figma sizes the count and its hugging frame to the instance's text.
diff --git a/src/app/editor/vector/lifecycle.ts b/src/app/editor/vector/lifecycle.ts
index 6cf698e29..2b846f71e 100644
--- a/src/app/editor/vector/lifecycle.ts
+++ b/src/app/editor/vector/lifecycle.ts
@@ -2,10 +2,11 @@ import type { Editor } from '@open-pencil/core/editor'
import { computeAccurateBounds, regenerateFillGeometry } from '@open-pencil/core/vector'
import {
cloneVectorNetwork,
+ slotScope,
transformVectorNetwork,
- vectorNetworksEqual
+ vectorNetworksEqual,
+ type VectorNetwork
} from '@open-pencil/scene-graph'
-import type { VectorNetwork } from '@open-pencil/scene-graph'
import { getNodeLocalMatrix, getWorldMatrix } from '@open-pencil/scene-graph/coordinate'
import Matrix from '@open-pencil/scene-graph/matrix'
@@ -93,6 +94,8 @@ export function createVectorEditLifecycle(editor: Editor, state: VectorEditState
function enterNodeEditMode(nodeId: string) {
const node = editor.graph.getNode(nodeId)
if (node?.type !== 'VECTOR' || !node.vectorNetwork) return
+ // A vector inside an instance draws its component's path, so Figma does not open it.
+ if (node.parentId && slotScope(editor.graph, node.parentId).kind === 'locked') return
const world = getWorldMatrix(node, editor.graph)
const absNetwork = transformVectorNetwork(world, node.vectorNetwork)
diff --git a/src/app/shell/keyboard/actions.ts b/src/app/shell/keyboard/actions.ts
index cdb40340e..49630db33 100644
--- a/src/app/shell/keyboard/actions.ts
+++ b/src/app/shell/keyboard/actions.ts
@@ -39,7 +39,7 @@ export function createKeyboardActions({
runCommand('selection.delete')
}
- function confirmOrEnterText() {
+ function confirmOrEditSelection() {
if (store.state.nodeEditState) {
store.exitNodeEditMode(true)
return
@@ -49,6 +49,11 @@ export function createKeyboardActions({
return
}
const node = store.selectedNode.value
+ // Figma opens a selected vector's path, as a double-click does.
+ if (node?.type === 'VECTOR') {
+ store.enterNodeEditMode(node.id)
+ return
+ }
if (node?.type === 'TEXT') {
requestAnimationFrame(() => {
store.startTextEditing(node.id)
@@ -146,7 +151,7 @@ export function createKeyboardActions({
return {
smartDelete,
- confirmOrEnterText,
+ confirmOrEditSelection,
escapeOrDeselect,
toggleAutoLayout,
toggleUI,
diff --git a/src/app/shell/keyboard/registry.ts b/src/app/shell/keyboard/registry.ts
index 34680dc3f..f38b089df 100644
--- a/src/app/shell/keyboard/registry.ts
+++ b/src/app/shell/keyboard/registry.ts
@@ -277,7 +277,7 @@ export function registerKeyboardShortcuts(options: KeyboardShortcutOptions) {
{ id: 'delete-backspace', keys: 'Backspace', run: ({ actions }) => actions.smartDelete(false) },
{ id: 'delete', keys: 'Delete', run: ({ actions }) => actions.smartDelete(false) },
{ id: 'delete-alt', keys: 'Alt+Delete', run: ({ actions }) => actions.smartDelete(true) },
- { id: 'enter', keys: 'Enter', run: ({ actions }) => actions.confirmOrEnterText() },
+ { id: 'enter', keys: 'Enter', run: ({ actions }) => actions.confirmOrEditSelection() },
{
id: 'escape',
keys: 'Escape',
diff --git a/src/app/shell/keyboard/types.ts b/src/app/shell/keyboard/types.ts
index 2b6f810fb..059874fb2 100644
--- a/src/app/shell/keyboard/types.ts
+++ b/src/app/shell/keyboard/types.ts
@@ -6,7 +6,7 @@ import type { EditorStore } from '@/app/editor/active-store'
export type KeyboardShortcutActions = {
smartDelete: (altKey: boolean) => void
- confirmOrEnterText: () => void
+ confirmOrEditSelection: () => void
escapeOrDeselect: () => void
toggleAutoLayout: () => void
toggleUI: () => void
diff --git a/tests/app/editor/vector/lifecycle.test.ts b/tests/app/editor/vector/lifecycle.test.ts
new file mode 100644
index 000000000..c76cd7d48
--- /dev/null
+++ b/tests/app/editor/vector/lifecycle.test.ts
@@ -0,0 +1,44 @@
+import { expect, test } from 'bun:test'
+
+import { createEditor } from '@open-pencil/core/editor'
+import { SceneGraph, type VectorNetwork } from '@open-pencil/scene-graph'
+
+import { createVectorEditLifecycle } from '@/app/editor/vector/lifecycle'
+import type { VectorEditState } from '@/app/editor/vector/types'
+
+import { expectDefined } from '#tests/helpers/assert'
+
+const TRIANGLE: VectorNetwork = {
+ vertices: [
+ { x: 0, y: 0 },
+ { x: 100, y: 0 },
+ { x: 50, y: 50 }
+ ],
+ segments: [0, 1, 2].map((start) => ({
+ start,
+ end: (start + 1) % 3,
+ tangentStart: { x: 0, y: 0 },
+ tangentEnd: { x: 0, y: 0 }
+ })),
+ regions: [{ windingRule: 'NONZERO', loops: [[0, 1, 2]] }]
+}
+
+test('opens a vector in a component but not its copy in an instance, as Figma does', () => {
+ const graph = new SceneGraph()
+ const pageId = expectDefined(graph.getPages()[0]).id
+ const component = graph.createNode('COMPONENT', pageId, { width: 200, height: 120 })
+ const vector = graph.createNode('VECTOR', component.id, {
+ width: 100,
+ height: 50,
+ vectorNetwork: TRIANGLE
+ })
+ const instance = expectDefined(graph.createInstance(component.id, pageId))
+ const copy = expectDefined(graph.getChildren(instance.id)[0])
+ const state = { nodeEditState: null } as VectorEditState
+ const lifecycle = createVectorEditLifecycle(createEditor({ graph }), state)
+
+ lifecycle.enterNodeEditMode(copy.id)
+ expect(state.nodeEditState).toBeNull()
+ lifecycle.enterNodeEditMode(vector.id)
+ expect(state.nodeEditState?.nodeId).toBe(vector.id)
+})
diff --git a/tests/e2e/canvas/gradient-handles-visual.spec.ts b/tests/e2e/canvas/gradient-handles-visual.spec.ts
index 5bce2d1c2..0fa5363e3 100644
--- a/tests/e2e/canvas/gradient-handles-visual.spec.ts
+++ b/tests/e2e/canvas/gradient-handles-visual.spec.ts
@@ -1,5 +1,5 @@
import { expect, test, useEditorSetupWithClear } from '#tests/e2e/fixtures'
-import { gradientDriver } from '#tests/helpers/canvas/gradient-driver'
+import { gradientDriver } from '#tests/helpers/canvas/gradient/driver'
// Figma desktop 126: a linear gradient shows its line, end dots, and stop squares; radial and
// diamond add a centre and a second radius dot; angular draws its ellipse with squares outside it.
diff --git a/tests/e2e/canvas/gradient-handles.spec.ts b/tests/e2e/canvas/gradient-handles.spec.ts
index 9232cd678..c5ecda6f2 100644
--- a/tests/e2e/canvas/gradient-handles.spec.ts
+++ b/tests/e2e/canvas/gradient-handles.spec.ts
@@ -1,5 +1,5 @@
import { expect, test, useEditorSetupWithClear } from '#tests/e2e/fixtures'
-import { gradientDriver } from '#tests/helpers/canvas/gradient-driver'
+import { gradientDriver } from '#tests/helpers/canvas/gradient/driver'
import { propertyItems } from '#tests/helpers/properties'
// Figma desktop 126: while a gradient's picker is open the canvas shows its handles. An end moves
diff --git a/tests/e2e/canvas/pixel-grid.spec.ts b/tests/e2e/canvas/pixel-grid.spec.ts
index a75c42fa4..e99cc73e0 100644
--- a/tests/e2e/canvas/pixel-grid.spec.ts
+++ b/tests/e2e/canvas/pixel-grid.spec.ts
@@ -1,5 +1,5 @@
import { expect, test, useEditorSetupWithClear } from '#tests/e2e/fixtures'
-import { pixelGridDriver } from '#tests/helpers/canvas/pixel-grid-driver'
+import { pixelGridDriver } from '#tests/helpers/canvas/pixel-grid/driver'
// Figma desktop 126: the pixel grid shows once a document pixel covers 8 device pixels (800% at
// 1×, 400% at 2×), Shift+' toggles it, and
diff --git a/tests/e2e/canvas/section-clicks.spec.ts b/tests/e2e/canvas/section-clicks.spec.ts
index 84cb588fe..3ae79e480 100644
--- a/tests/e2e/canvas/section-clicks.spec.ts
+++ b/tests/e2e/canvas/section-clicks.spec.ts
@@ -1,7 +1,7 @@
import { expect, test } from '@playwright/test'
import { CanvasHelper } from '#tests/helpers/canvas'
-import { sectionClicksDriver } from '#tests/helpers/canvas/section-clicks-driver'
+import { sectionClicksDriver } from '#tests/helpers/canvas/section-clicks/driver'
// Each case repeats a click in Figma desktop 126 on a section holding two frames.
diff --git a/tests/e2e/canvas/top-level-frame-click.spec.ts b/tests/e2e/canvas/top-level-frame-click.spec.ts
index bc0b57778..bc9a67b98 100644
--- a/tests/e2e/canvas/top-level-frame-click.spec.ts
+++ b/tests/e2e/canvas/top-level-frame-click.spec.ts
@@ -1,5 +1,5 @@
import { expect, test, useEditorSetupWithClear } from '#tests/e2e/fixtures'
-import { clickDepthDriver } from '#tests/helpers/canvas/click-depth-driver'
+import { clickDepthDriver } from '#tests/helpers/canvas/click-depth/driver'
// Matches Figma desktop 126 with the same pointer input: the gaps and padding of a top-level auto
// layout frame select, highlight, and drag it, while those of a plain top-level frame are background.
diff --git a/tests/e2e/canvas/vector/editing.spec.ts b/tests/e2e/canvas/vector/editing.spec.ts
index 61cff66fd..9ba1beeb5 100644
--- a/tests/e2e/canvas/vector/editing.spec.ts
+++ b/tests/e2e/canvas/vector/editing.spec.ts
@@ -1,4 +1,5 @@
import { expect, test, useEditorSetupWithClear } from '#tests/e2e/fixtures'
+import { vectorEditDriver } from '#tests/helpers/canvas/vector-edit/driver'
const editor = useEditorSetupWithClear('/?test&no-chrome&no-rulers')
@@ -280,3 +281,17 @@ test('dragging a vector point snaps to sibling bounds and clears guides on relea
editor.canvas.assertNoErrors()
})
+
+test('Enter opens a selected vector’s path, but not one an instance draws from its component', async () => {
+ const scene = vectorEditDriver(() => editor.page)
+ const ids = await scene.build()
+ const editedAfterEnter = async (id: string) => {
+ await scene.select(id)
+ await editor.page.keyboard.press('Enter')
+ const edited = await scene.editedNode()
+ await scene.closeEdit()
+ return edited
+ }
+ expect(await editedAfterEnter(ids.vector)).toBe(ids.vector)
+ expect(await editedAfterEnter(ids.copy)).toBeNull()
+})
diff --git a/tests/e2e/properties/mixed-selection.spec.ts b/tests/e2e/properties/mixed-selection.spec.ts
index 56420117e..6dba8d0fa 100644
--- a/tests/e2e/properties/mixed-selection.spec.ts
+++ b/tests/e2e/properties/mixed-selection.spec.ts
@@ -1,5 +1,5 @@
import { expect, test, useEditorSetupWithClear } from '#tests/e2e/fixtures'
-import { mixedSelectionDriver } from '#tests/helpers/canvas/mixed-selection-driver'
+import { mixedSelectionDriver } from '#tests/helpers/canvas/mixed-selection/driver'
import { propertyField, propertySection } from '#tests/helpers/properties'
// Figma desktop 126, probed with the same layers: a multi-selection shows layout, typography for
diff --git a/tests/helpers/canvas/click-depth-driver.ts b/tests/helpers/canvas/click-depth/driver.ts
similarity index 96%
rename from tests/helpers/canvas/click-depth-driver.ts
rename to tests/helpers/canvas/click-depth/driver.ts
index 1875adb69..758438102 100644
--- a/tests/helpers/canvas/click-depth-driver.ts
+++ b/tests/helpers/canvas/click-depth/driver.ts
@@ -1,6 +1,6 @@
import type { Page } from '@playwright/test'
-import type * as ClickDepthScenes from '#tests/helpers/canvas/click-depth'
+import type * as ClickDepthScenes from '#tests/helpers/canvas/click-depth/scene'
type SceneName = 'createClickDepthCards' | 'createNestedBoard'
@@ -11,7 +11,7 @@ export function clickDepthDriver(page: () => Page) {
return page().evaluate(async (scene) => {
const store = window.openPencil?.getStore?.()
if (!store) throw new Error('OpenPencil store not initialized')
- const fixtureURL = '/tests/helpers/canvas/click-depth.ts'
+ const fixtureURL = '/tests/helpers/canvas/click-depth/scene.ts'
const scenes: typeof ClickDepthScenes = await import(fixtureURL)
const ids = scenes[scene](store.graph, store.state.currentPageId)
store.clearSelection()
diff --git a/tests/helpers/canvas/click-depth.ts b/tests/helpers/canvas/click-depth/scene.ts
similarity index 100%
rename from tests/helpers/canvas/click-depth.ts
rename to tests/helpers/canvas/click-depth/scene.ts
diff --git a/tests/helpers/canvas/gradient-driver.ts b/tests/helpers/canvas/gradient/driver.ts
similarity index 97%
rename from tests/helpers/canvas/gradient-driver.ts
rename to tests/helpers/canvas/gradient/driver.ts
index e6c22f774..3932cb2f4 100644
--- a/tests/helpers/canvas/gradient-driver.ts
+++ b/tests/helpers/canvas/gradient/driver.ts
@@ -2,7 +2,7 @@ import type { Page } from '@playwright/test'
import type * as Geometry from '@open-pencil/core/geometry'
-import type * as GradientScene from '#tests/helpers/canvas/gradient'
+import type * as GradientScene from '#tests/helpers/canvas/gradient/scene'
type GradientType = Parameters<typeof GradientScene.createGradientScene>[2]
@@ -14,7 +14,7 @@ export function gradientDriver(page: () => Page) {
return page().evaluate(async (type) => {
const store = window.openPencil?.getStore?.()
if (!store) throw new Error('OpenPencil store not initialized')
- const fixtureURL = '/tests/helpers/canvas/gradient.ts'
+ const fixtureURL = '/tests/helpers/canvas/gradient/scene.ts'
const scene: typeof GradientScene = await import(fixtureURL)
const { nodeId } = scene.createGradientScene(store.graph, store.state.currentPageId, type)
store.select([nodeId])
diff --git a/tests/helpers/canvas/gradient.ts b/tests/helpers/canvas/gradient/scene.ts
similarity index 100%
rename from tests/helpers/canvas/gradient.ts
rename to tests/helpers/canvas/gradient/scene.ts
diff --git a/tests/helpers/canvas/mixed-selection-driver.ts b/tests/helpers/canvas/mixed-selection/driver.ts
similarity index 98%
rename from tests/helpers/canvas/mixed-selection-driver.ts
rename to tests/helpers/canvas/mixed-selection/driver.ts
index 11ce2f68d..75eaf9474 100644
--- a/tests/helpers/canvas/mixed-selection-driver.ts
+++ b/tests/helpers/canvas/mixed-selection/driver.ts
@@ -1,6 +1,6 @@
import type { Page } from '@playwright/test'
-import type * as MixedScene from '#tests/helpers/canvas/mixed-selection'
+import type * as MixedScene from '#tests/helpers/canvas/mixed-selection/scene'
type SceneIds = ReturnType<typeof MixedScene.createMixedSelectionScene>
export type MixedLayer = keyof SceneIds
@@ -20,7 +20,7 @@ export function mixedSelectionDriver(page: () => Page) {
ids = await page().evaluate(async () => {
const store = window.openPencil?.getStore?.()
if (!store) throw new Error('OpenPencil store not initialized')
- const fixtureURL = '/tests/helpers/canvas/mixed-selection.ts'
+ const fixtureURL = '/tests/helpers/canvas/mixed-selection/scene.ts'
const scene: typeof MixedScene = await import(fixtureURL)
const built = scene.createMixedSelectionScene(store.graph, store.state.currentPageId)
store.requestRender()
diff --git a/tests/helpers/canvas/mixed-selection.ts b/tests/helpers/canvas/mixed-selection/scene.ts
similarity index 100%
rename from tests/helpers/canvas/mixed-selection.ts
rename to tests/helpers/canvas/mixed-selection/scene.ts
diff --git a/tests/helpers/canvas/pixel-grid-driver.ts b/tests/helpers/canvas/pixel-grid/driver.ts
similarity index 92%
rename from tests/helpers/canvas/pixel-grid-driver.ts
rename to tests/helpers/canvas/pixel-grid/driver.ts
index b0c895b48..8ec70767e 100644
--- a/tests/helpers/canvas/pixel-grid-driver.ts
+++ b/tests/helpers/canvas/pixel-grid/driver.ts
@@ -1,6 +1,6 @@
import type { Page } from '@playwright/test'
-import type * as PixelGridScene from '#tests/helpers/canvas/pixel-grid'
+import type * as PixelGridScene from '#tests/helpers/canvas/pixel-grid/scene'
/** Builds the pixel grid scene at a zoom and reads back the snapping preference. */
export function pixelGridDriver(page: () => Page) {
@@ -10,7 +10,7 @@ export function pixelGridDriver(page: () => Page) {
return page().evaluate(async (zoom) => {
const store = window.openPencil?.getStore?.()
if (!store) throw new Error('OpenPencil store not initialized')
- const fixtureURL = '/tests/helpers/canvas/pixel-grid.ts'
+ const fixtureURL = '/tests/helpers/canvas/pixel-grid/scene.ts'
const scene: typeof PixelGridScene = await import(fixtureURL)
scene.createPixelGridScene(store.graph, store.state.currentPageId)
store.state.zoom = zoom
diff --git a/tests/helpers/canvas/pixel-grid.ts b/tests/helpers/canvas/pixel-grid/scene.ts
similarity index 100%
rename from tests/helpers/canvas/pixel-grid.ts
rename to tests/helpers/canvas/pixel-grid/scene.ts
diff --git a/tests/helpers/canvas/section-clicks-driver.ts b/tests/helpers/canvas/section-clicks/driver.ts
similarity index 98%
rename from tests/helpers/canvas/section-clicks-driver.ts
rename to tests/helpers/canvas/section-clicks/driver.ts
index 4aebc3d3c..c9669e331 100644
--- a/tests/helpers/canvas/section-clicks-driver.ts
+++ b/tests/helpers/canvas/section-clicks/driver.ts
@@ -1,6 +1,6 @@
import type { Page } from '@playwright/test'
-import type * as SectionScene from '#tests/helpers/canvas/section-clicks'
+import type * as SectionScene from '#tests/helpers/canvas/section-clicks/scene'
/** The view offset the scene is shown at, at zoom 1, so canvas points are scene points plus it. */
const PAN = 50
@@ -12,7 +12,7 @@ export function sectionClicksDriver(page: () => Page) {
return page().evaluate(async (pan) => {
const store = window.openPencil?.getStore?.()
if (!store) throw new Error('OpenPencil store not initialized')
- const fixtureURL = '/tests/helpers/canvas/section-clicks.ts'
+ const fixtureURL = '/tests/helpers/canvas/section-clicks/scene.ts'
const scene: typeof SectionScene = await import(fixtureURL)
scene.createSectionClickScene(store.graph, store.state.currentPageId)
store.state.zoom = 1
diff --git a/tests/helpers/canvas/section-clicks.ts b/tests/helpers/canvas/section-clicks/scene.ts
similarity index 100%
rename from tests/helpers/canvas/section-clicks.ts
rename to tests/helpers/canvas/section-clicks/scene.ts
diff --git a/tests/helpers/canvas/vector-edit/driver.ts b/tests/helpers/canvas/vector-edit/driver.ts
new file mode 100644
index 000000000..77b4c107c
--- /dev/null
+++ b/tests/helpers/canvas/vector-edit/driver.ts
@@ -0,0 +1,37 @@
+import type { Page } from '@playwright/test'
+
+import type * as VectorEditScene from '#tests/helpers/canvas/vector-edit/scene'
+
+/** Builds the component vector scene, selects its layers, and reads which path is open. */
+export function vectorEditDriver(page: () => Page) {
+ return {
+ build() {
+ return page().evaluate(async () => {
+ const store = window.openPencil?.getStore?.()
+ if (!store) throw new Error('OpenPencil store not initialized')
+ // An earlier case may leave its path open.
+ store.exitNodeEditMode(false)
+ const fixtureURL = '/tests/helpers/canvas/vector-edit/scene.ts'
+ const scene: typeof VectorEditScene = await import(fixtureURL)
+ const ids = scene.createComponentVectorScene(store.graph, store.state.currentPageId)
+ store.requestRender()
+ return ids
+ })
+ },
+
+ select(id: string) {
+ return page().evaluate((nodeId) => window.openPencil?.getStore?.().select([nodeId]), id)
+ },
+
+ /** The layer whose path is open for editing, if any. */
+ editedNode() {
+ return page().evaluate(
+ () => window.openPencil?.getStore?.().state.nodeEditState?.nodeId ?? null
+ )
+ },
+
+ closeEdit() {
+ return page().evaluate(() => window.openPencil?.getStore?.().exitNodeEditMode(true))
+ }
+ }
+}
diff --git a/tests/helpers/canvas/vector-edit/scene.ts b/tests/helpers/canvas/vector-edit/scene.ts
new file mode 100644
index 000000000..c6c00fd5e
--- /dev/null
+++ b/tests/helpers/canvas/vector-edit/scene.ts
@@ -0,0 +1,33 @@
+import type { SceneGraph, VectorNetwork } from '@open-pencil/scene-graph'
+
+// The browser loads this module itself, so it imports types only.
+const STRAIGHT = { x: 0, y: 0 }
+const TRIANGLE: VectorNetwork = {
+ vertices: [
+ { x: 0, y: 0 },
+ { x: 100, y: 0 },
+ { x: 50, y: 100 }
+ ],
+ segments: [
+ { start: 0, end: 1, tangentStart: STRAIGHT, tangentEnd: STRAIGHT },
+ { start: 1, end: 2, tangentStart: STRAIGHT, tangentEnd: STRAIGHT },
+ { start: 2, end: 0, tangentStart: STRAIGHT, tangentEnd: STRAIGHT }
+ ],
+ regions: [{ windingRule: 'NONZERO', loops: [[0, 1, 2]] }]
+}
+
+/** A component holding a triangle, and an instance of it, whose copy draws the component's path. */
+export function createComponentVectorScene(graph: SceneGraph, pageId: string) {
+ const card = graph.createNode('COMPONENT', pageId, { x: 100, y: 100, width: 120, height: 120 })
+ const vector = graph.createNode('VECTOR', card.id, {
+ x: 10,
+ y: 10,
+ width: 100,
+ height: 100,
+ vectorNetwork: structuredClone(TRIANGLE)
+ })
+ const instance = graph.createInstance(card.id, pageId, { x: 300, y: 100 })
+ const copy = instance ? graph.getChildren(instance.id)[0] : undefined
+ if (!copy) throw new Error('Expected an instance copy')
+ return { vector: vector.id, copy: copy.id }
+}