AI-native design editor. Open-source Figma alternative.
fix(canvas): show every top-level frame's name and select frames by it (#930)
Danila Poyarkova6a87035da31
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 53d814ec1..dc1e9e940 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -4,6 +4,7 @@### Breaking changes+- `SkiaRenderer.hitTestFrameTitle` no longer takes the selected IDs: it finds the name of any frame on the page or in a section under a point, selected or not.- `SceneNode.booleanOperation` is a required key whose value may be `undefined`, like every other scene node field, so code that builds `SceneNode` objects itself must include it.- `sceneNodeToDesignDocument` from `@open-pencil/dom-css` takes an options object, `{ includeSourceIds, tokens }`, instead of a boolean third argument; `tokens: false` writes literal values instead of variable references.- `randomHex`, `randomInt`, and `randomIndex` moved from `@open-pencil/core/random` and the `@open-pencil/core` barrel to `@open-pencil/scene-graph/random`.@@ -69,7 +70,7 @@- `createInstance()` and `detachInstance()` in the plugin API return the node type they built, so reading `componentProperties`, `setProperties`, or `isExposedInstance` from a new instance no longer needs a cast; `FigmaInstanceNode` is exported alongside the other node types.- Name the tool and list every invalid argument with where it is when AI chat, the CLI, or WebMCP calls a tool wrongly, as MCP clients already saw, as in `Invalid arguments for create_shape:` followed by `× Invalid type: Expected ("FRAME" | …) but received "CIRCLE"` and `→ at type`. Design JSX component properties and gradient stops report their problems the same way. Previously only the first problem was named, without the tool or the argument.- HTML and Tailwind JSX export write variable-bound colors, spacing, radii, borders, sizes, type sizes, and opacity as the tokens they come from, such as `var(--color-primary)` or `bg-primary`, and put layers set to another mode in it with an attribute such as `data-theme="dark"`. Values CSS would not resolve as the canvas draws them stay literal, and standalone HTML includes the stylesheet for the tokens it uses.-- Clicking selects layers as in Figma: inside a top-level frame or section, a click selects the frame's direct child rather than the deepest layer, the empty part of a top-level frame or section that holds layers selects nothing, and once a layer is selected, clicks reach its siblings and cousins. Double-click goes one level deeper and ⌘-click (Ctrl-click on Windows and Linux) selects the deepest layer. A marquee started inside a top-level frame or section selects that container's layers, and from the page it selects a frame or section that holds layers only when fully enclosed.+- Clicking selects layers as in Figma: inside a top-level frame or section, a click selects the frame's direct child rather than the deepest layer, the empty part of a top-level frame or section that holds layers selects nothing, so every top-level frame shows its name above it, in the selection color while selected or hovered, and clicking or dragging the name selects or moves the frame; once a layer is selected, clicks reach its siblings and cousins. Double-click goes one level deeper and ⌘-click (Ctrl-click on Windows and Linux) selects the deepest layer. A marquee started inside a top-level frame or section selects that container's layers, and from the page it selects a frame or section that holds layers only when fully enclosed.- Drag, draw, duplicate, and paste follow Figma. A dragged layer lands in the frame under the cursor and leaves its frame as soon as the cursor does; groups and locked frames never take a drop, a component set takes back only its own variants, and a layer inside a group stays in it unless dropped on another frame. Groups and booleans fit their children after a move or nudge, and a group whose last layer leaves is removed. Pressing inside a selected frame, group, or component set drags it rather than the layer under the cursor, and an auto layout child dragged out lands where you drop it. Hold Space while dragging to keep layers in their parents, Shift to move along one axis, or Control to drop into auto layout as an absolute-positioned layer. Locked layers stay put when the rest of the selection moves. Shapes drawn inside a frame, auto layout, or slot go into it, a frame drawn over layers takes in the ones it fully covers, and a section does so when moved or resized too. Wrapped auto layout inserts on the line under the cursor. Duplicates keep their names, and duplicating a main component with ⌘D or Alt-drag creates an instance. ⌘D duplicates in place, placing a lone top-level frame's copy to its right, and ⌘V keeps the copied position, centering an axis that doesn't fit the selected frame; **Paste here** still pastes at the cursor.- Give popovers, menus, dropdowns, and pickers one look and motion: the same rounded panel with a thin outline that reads in light and dark themes, a short fade and grow from the side they open on, and an immediate close; with reduced motion they appear at once.- Add and remove items the same way across the properties panel: a section's + adds an item and a row's − removes it, now including grid columns and rows and variant properties. The + of a component set adds Property 1 ready to rename instead of showing a form, and a variant is removed with Delete like any layer.diff --git a/packages/core/src/canvas/labels/cache.ts b/packages/core/src/canvas/labels/cache.tsindex 0998cd643..d40502c30 100644--- a/packages/core/src/canvas/labels/cache.ts+++ b/packages/core/src/canvas/labels/cache.ts@@ -10,6 +10,13 @@ export interface CachedSection {nested: boolean}+/** A frame on the page or in a section, which shows its name above it. */+export interface CachedFrame {+ nodeId: string+ absX: number+ absY: number+}+export interface CachedComponent {nodeId: stringabsX: number@@ -25,6 +32,7 @@ interface Viewport {}const LABEL_TYPES = new Set(['COMPONENT', 'COMPONENT_SET'])+const FRAME_TITLE_PARENT_TYPES = new Set(['CANVAS', 'SECTION'])const COMPONENT_LABEL_PARENT_TYPES = new Set(['CANVAS', 'SECTION', 'COMPONENT_SET'])function isInViewport(absX: number, absY: number, w: number, h: number, vp: Viewport): boolean {@@ -57,6 +65,7 @@ function collectVisibleLabels<export class LabelCache {private sections: CachedSection[] = []private components: CachedComponent[] = []+ private frames: CachedFrame[] = []private cachedSceneVersion = -1private cachedPositionPreviewVersion = -1private cachedPageId: string | null = null@@ -86,6 +95,7 @@ export class LabelCache {this.cachedPageId = nullthis.sections = []this.components = []+ this.frames = []}getSections(@@ -120,6 +130,18 @@ export class LabelCache {)}+ getFrames(+ graph: SceneGraph,+ viewport: Viewport,+ preview?: RenderOverlays['rotationPreview']+ ): Array<{ node: SceneNode; absX: number; absY: number }> {+ return collectVisibleLabels(graph, viewport, this.frames, () => ({}), preview)+ }++ getAllFrames(): readonly CachedFrame[] {+ return this.frames+ }+getAllSections(): readonly CachedSection[] {return this.sections}@@ -131,6 +153,7 @@ export class LabelCache {private rebuild(graph: SceneGraph, pageId: string | null): void {this.sections = []this.components = []+ this.frames = []const pageNode = graph.getNode(pageId ?? graph.rootId)if (!pageNode) return@@ -164,8 +187,12 @@ export class LabelCache {if (child.childIds.length > 0) {this.walkChildren(graph, childId, insideSection)}- } else if (child.childIds.length > 0) {- this.walkChildren(graph, childId, insideSection)+ } else {+ if (child.type === 'FRAME' && FRAME_TITLE_PARENT_TYPES.has(parentType)) {+ const origin = graph.getAbsolutePosition(childId)+ this.frames.push({ nodeId: childId, absX: origin.x, absY: origin.y })+ }+ if (child.childIds.length > 0) this.walkChildren(graph, childId, insideSection)}}}diff --git a/packages/core/src/canvas/labels/draw.ts b/packages/core/src/canvas/labels/draw.tsindex 3033a4fa1..498d8802c 100644--- a/packages/core/src/canvas/labels/draw.ts+++ b/packages/core/src/canvas/labels/draw.ts@@ -5,9 +5,9 @@ import type { SceneNode, SceneGraph } from '@open-pencil/scene-graph'import type { RenderOverlays, SkiaRenderer } from '#core/canvas/renderer'import { SECTION_TITLE_RADIUS } from '#core/constants'-import { labelLayout } from './layout'-import { sectionLabelColors } from './style'-import { labelScreenMatrix, labelTransform } from './transform'+import { labelLayout, labelViewport } from './layout'+import { frameTitleColor, sectionLabelColors } from './style'+import { frameLabelPlacement, labelScreenMatrix, labelTransform } from './transform'export function drawSectionTitles(r: SkiaRenderer,@@ -18,7 +18,11 @@ export function drawSectionTitles(const provider = r.fontProviderif (!r.sectionTitleFont || !provider) return- const sections = r.labelCache.getSections(graph, r.worldViewport, overlays?.rotationPreview)+ const sections = r.labelCache.getSections(+ graph,+ labelViewport(r.worldViewport, r.zoom),+ overlays?.rotationPreview+ )if (sections.length === 0) returnfor (const { node, nested } of sections) {@@ -86,7 +90,11 @@ export function drawComponentLabels(): void {if (!r.componentLabelFont || !r.fontProvider) return- const components = r.labelCache.getComponents(graph, r.worldViewport, overlays?.rotationPreview)+ const components = r.labelCache.getComponents(+ graph,+ labelViewport(r.worldViewport, r.zoom),+ overlays?.rotationPreview+ )if (components.length === 0) returnconst provider = r.fontProvider@@ -158,3 +166,47 @@ export function drawComponentLabels(canvas.restore()}}++/**+ * Names above the frames on the page and in sections, as Figma shows them: faded, or in the+ * selection color while the frame is selected or hovered. A frame holding layers is a background+ * that a click on its body does not select, so its name is how it is picked.+ */+export function drawFrameTitles(+ r: SkiaRenderer,+ canvas: Canvas,+ graph: SceneGraph,+ selectedIds: ReadonlySet<string>,+ overlays?: RenderOverlays+): void {+ const provider = r.fontProvider+ if (!r.labelFont || !provider) return++ const frames = r.labelCache.getFrames(+ graph,+ labelViewport(r.worldViewport, r.zoom),+ overlays?.rotationPreview+ )+ for (const { node } of frames) {+ const transform = frameLabelPlacement(node, graph, overlays?.rotationPreview)+ const layout = labelLayout('frame', transform.width * r.zoom)+ if (!layout) continue+ const highlighted = selectedIds.has(node.id) || overlays?.hoveredNodeId === node.id+ canvas.save()+ canvas.concat(labelScreenMatrix(transform, r))+ r.labelParagraphCache.draw(+ r.ck,+ canvas,+ provider,+ node.name,+ layout.fontSize,+ layout.maxTextWidth,+ frameTitleColor(r, highlighted),+ r.fontGeneration,+ layout.text.x,+ layout.text.y,+ layout.fontWeight+ )+ canvas.restore()+ }+}diff --git a/packages/core/src/canvas/labels/hit-test.ts b/packages/core/src/canvas/labels/hit-test.tsindex 3b1d8a775..af9132299 100644--- a/packages/core/src/canvas/labels/hit-test.ts+++ b/packages/core/src/canvas/labels/hit-test.ts@@ -6,8 +6,8 @@ import type { RotationPreview } from '#core/geometry'import { LabelCache } from './cache'import {- hasFrameTitle,labelLayout,+ labelViewport,type LabelKind,type LabelLayout,type LabelTextMetrics@@ -62,7 +62,7 @@ function catalog(graph: SceneGraph, pageId: string, existing?: LabelCache): Labereturn cache}-function catalogHitTest(kind: 'section' | 'component') {+function catalogHitTest(kind: 'section' | 'component' | 'frame') {return function hitTest(graph: SceneGraph,canvasX: number,@@ -75,18 +75,24 @@ function catalogHitTest(kind: 'section' | 'component') {): SceneNode | null {if (!font) return nullconst cache = catalog(graph, pageId, labelCache)+ const viewport = options.viewport ? labelViewport(options.viewport, zoom) : undefinedlet candidates: Array<{ nodeId: string; inside: boolean }>if (kind === 'section') {- const sections = options.viewport+ const sections = viewport? cache- .getSections(graph, options.viewport, options.preview)+ .getSections(graph, viewport, options.preview).map(({ node, nested }) => ({ nodeId: node.id, nested })): cache.getAllSections()candidates = sections.map(({ nodeId, nested }) => ({ nodeId, inside: nested }))+ } else if (kind === 'frame') {+ const frames = viewport+ ? cache.getFrames(graph, viewport, options.preview).map(({ node }) => ({ nodeId: node.id }))+ : cache.getAllFrames()+ candidates = frames.map(({ nodeId }) => ({ nodeId, inside: false }))} else {- const components = options.viewport+ const components = viewport? cache- .getComponents(graph, options.viewport, options.preview)+ .getComponents(graph, viewport, options.preview).map(({ node }) => ({ nodeId: node.id })): cache.getAllComponents()candidates = components.map(({ nodeId }) => ({ nodeId, inside: false }))@@ -94,7 +100,8 @@ function catalogHitTest(kind: 'section' | 'component') {for (let i = candidates.length - 1; i >= 0; i--) {const candidate = candidates[i]const node = graph.getNode(candidate.nodeId)- if (!node?.visible) continue+ // Locked frames cannot be selected on the canvas, by their name either.+ if (!node?.visible || (kind === 'frame' && node.locked)) continueconst hit = hitLabel(node,graph,@@ -115,18 +122,8 @@ export const hitTestSectionTitle = catalogHitTest('section')export const hitTestComponentLabel = catalogHitTest('component')-export function hitTestFrameTitle(- graph: SceneGraph,- canvasX: number,- canvasY: number,- zoom: number,- selectedIds: Set<string>,- font: Font | null,- options: LabelHitOptions = {}-): SceneNode | null {- if (!font || selectedIds.size !== 1) return null- const node = graph.getNode([...selectedIds][0])- if (!node?.visible || !hasFrameTitle(node, node.parentId ? graph.getNode(node.parentId) : null))- return null- return hitLabel(node, graph, 'frame', false, canvasX, canvasY, zoom, font, options)-}+/**+ * The top-level frame whose name is under a point, selected or not: a frame on the page or in a+ * section shows its name, and clicking it selects the frame even when its body is a background.+ */+export const hitTestFrameTitle = catalogHitTest('frame')diff --git a/packages/core/src/canvas/labels/layout.ts b/packages/core/src/canvas/labels/layout.tsindex 39f5c93e5..6ed74ddd9 100644--- a/packages/core/src/canvas/labels/layout.ts+++ b/packages/core/src/canvas/labels/layout.ts@@ -100,3 +100,28 @@ export function labelLayout(maxTextWidth}}++/** How far, in screen pixels, a label can reach outside the node it names. */+const LABEL_REACH = Math.max(+ LABEL_OFFSET_Y + LABEL_FONT_SIZE,+ SECTION_TITLE_HEIGHT + SECTION_TITLE_GAP,+ COMPONENT_LABEL_GAP + COMPONENT_LABEL_FONT_SIZE+)++/**+ * The viewport widened by how far labels reach outside their nodes, so a node just outside the+ * view whose name is inside it still has its name drawn and clickable.+ */+export function labelViewport<T extends { x: number; y: number; w: number; h: number }>(+ viewport: T,+ zoom: number+): T {+ const reach = LABEL_REACH / zoom+ return {+ ...viewport,+ x: viewport.x - reach,+ y: viewport.y - reach,+ w: viewport.w + reach * 2,+ h: viewport.h + reach * 2+ }+}diff --git a/packages/core/src/canvas/labels/selection.ts b/packages/core/src/canvas/labels/selection.tsindex 17552bf3a..8482a19dd 100644--- a/packages/core/src/canvas/labels/selection.ts+++ b/packages/core/src/canvas/labels/selection.ts@@ -13,7 +13,6 @@ import {} from '#core/constants'import { createSceneGeometry } from '#core/geometry'-import { hasFrameTitle, labelLayout } from './layout'import { measureGlyphWidth } from './paragraph-cache'import { frameLabelPlacement, labelScreenMatrix } from './transform'@@ -36,43 +35,6 @@ function accumulateSelectionBounds(}}-function drawSingleFrameTitle(- r: SkiaRenderer,- canvas: Canvas,- graph: SceneGraph,- node: SceneNode,- overlays: RenderOverlays-): void {- const parentNode = node.parentId ? graph.getNode(node.parentId) : null- const provider = r.fontProvider- if (!hasFrameTitle(node, parentNode) || !provider) return-- const transform = frameLabelPlacement(node, graph, overlays.rotationPreview)-- r.auxFill.setColor(r.selColor())-- const layout = labelLayout('frame', transform.width * r.zoom)- if (!layout) return-- canvas.save()- canvas.concat(labelScreenMatrix(transform, r))-- r.labelParagraphCache.draw(- r.ck,- canvas,- provider,- node.name,- layout.fontSize,- layout.maxTextWidth,- r.selColor(),- r.fontGeneration,- layout.text.x,- layout.text.y,- layout.fontWeight- )- canvas.restore()-}-function drawSizePill(r: SkiaRenderer,canvas: Canvas,@@ -165,7 +127,6 @@ export function drawSelectionLabels(if (nodes.length === 0) returnif (nodes.length === 1) {- drawSingleFrameTitle(r, canvas, graph, nodes[0], activeOverlays)drawSingleSelectionSize(r, canvas, graph, nodes[0], activeOverlays, sizeFont)return}diff --git a/packages/core/src/canvas/labels/style.ts b/packages/core/src/canvas/labels/style.tsindex 2a973044a..5a50ce37f 100644--- a/packages/core/src/canvas/labels/style.ts+++ b/packages/core/src/canvas/labels/style.ts@@ -22,6 +22,19 @@ export function sectionLabelColors(r: SkiaRenderer, graph: SceneGraph, node: Sce}}+/** How far a frame's name fades into the canvas while the frame is not selected or hovered. */+const FRAME_TITLE_MUTED_ALPHA = 0.5++/**+ * A top-level frame's name: the selection color while the frame is selected or hovered, otherwise+ * the canvas's own text color, faded, so names read on light and dark canvases alike.+ */+export function frameTitleColor(r: SkiaRenderer, highlighted: boolean) {+ if (highlighted) return r.selColor()+ const foreground = canvasLabelForeground(r.pageColor)+ return r.ck.Color4f(foreground.r, foreground.g, foreground.b, FRAME_TITLE_MUTED_ALPHA)+}+/** Hit-testing reuses the same shaped paragraphs, constraints and paint keys as drawing. */export function measureLabel(r: SkiaRenderer,@@ -31,7 +44,7 @@ export function measureLabel(): LabelTextMetrics | null {const provider = r.fontProviderif (!provider) return null- let color = r.selColor()+ let color = frameTitleColor(r, false)if (layout.kind === 'section') color = sectionLabelColors(r, graph, node).foregroundelse if (layout.kind === 'component') color = r.compColor()return r.labelParagraphCache.measure(diff --git a/packages/core/src/canvas/renderer.ts b/packages/core/src/canvas/renderer.tsindex 4d8c2bc0c..9b992a659 100644--- a/packages/core/src/canvas/renderer.ts+++ b/packages/core/src/canvas/renderer.ts@@ -284,6 +284,12 @@ export class SkiaRenderer {selectedIds: Set<string>,guides?: RenderOverlays['guides']) => void+ declare drawFrameTitles: (+ canvas: Canvas,+ graph: SceneGraph,+ selectedIds: ReadonlySet<string>,+ overlays?: RenderOverlays+ ) => voiddeclare drawSectionTitles: (canvas: Canvas, graph: SceneGraph, overlays?: RenderOverlays) => voiddeclare drawComponentLabels: (canvas: Canvas,@@ -577,7 +583,6 @@ export class SkiaRenderer {graph: SceneGraph,canvasX: number,canvasY: number,- selectedIds: Set<string>,preview?: RenderOverlays['rotationPreview']): SceneNode | null {return LabelHitTest.hitTestFrameTitle(@@ -585,8 +590,9 @@ export class SkiaRenderer {canvasX,canvasY,this.zoom,- selectedIds,+ this.pageId ?? graph.rootId,this.labelFont,+ this.labelCache,labelHitOptions(this, graph, preview))}diff --git a/packages/core/src/canvas/renderer/methods.ts b/packages/core/src/canvas/renderer/methods.tsindex 60fade3e5..02e6a9262 100644--- a/packages/core/src/canvas/renderer/methods.ts+++ b/packages/core/src/canvas/renderer/methods.ts@@ -175,6 +175,15 @@ const rendererMethods: ThisType<SkiaRenderer> = {Rulers.drawRulers(this, canvas, graph, selectedIds, guides)},+ drawFrameTitles(+ canvas: Canvas,+ graph: SceneGraph,+ selectedIds: ReadonlySet<string>,+ overlays?: RenderOverlays+ ): void {+ Labels.drawFrameTitles(this, canvas, graph, selectedIds, overlays)+ },+drawSectionTitles(canvas: Canvas, graph: SceneGraph, overlays?: RenderOverlays): void {Labels.drawSectionTitles(this, canvas, graph, overlays)},diff --git a/packages/core/src/canvas/renderer/overlay-pass.ts b/packages/core/src/canvas/renderer/overlay-pass.tsindex e7d92d0ad..cc9f454c9 100644--- a/packages/core/src/canvas/renderer/overlay-pass.ts+++ b/packages/core/src/canvas/renderer/overlay-pass.ts@@ -25,9 +25,13 @@ export function drawLabelPass(r: SkiaRenderer,canvas: Canvas,graph: SceneGraph,+ selectedIds: ReadonlySet<string>,overlays?: RenderOverlays): void {const profiler = r.profiler+ profiler.beginPhase('render:frameTitles')+ r.drawFrameTitles(canvas, graph, selectedIds, overlays)+ profiler.endPhase('render:frameTitles')profiler.beginPhase('render:sectionTitles')r.drawSectionTitles(canvas, graph, overlays)profiler.endPhase('render:sectionTitles')diff --git a/packages/core/src/canvas/renderer/pipeline.ts b/packages/core/src/canvas/renderer/pipeline.tsindex e3abd0a49..8e6b20ce7 100644--- a/packages/core/src/canvas/renderer/pipeline.ts+++ b/packages/core/src/canvas/renderer/pipeline.ts@@ -277,7 +277,7 @@ export function render(canvas.save()canvas.scale(r.dpr, r.dpr)r.labelCache.update(graph, r.pageId, sceneVersion, graph.positionPreviewVersion)- drawLabelPass(r, canvas, graph, overlays)+ drawLabelPass(r, canvas, graph, selectedIds, overlays)canvas.restore()canvas.save()diff --git a/packages/vue/src/canvas/surface/overlays.ts b/packages/vue/src/canvas/surface/overlays.tsindex 9b23cdfab..e7cd93121 100644--- a/packages/vue/src/canvas/surface/overlays.ts+++ b/packages/vue/src/canvas/surface/overlays.ts@@ -45,7 +45,6 @@ export function createCanvasHitTests(editor: Editor, getRenderer: () => SkiaRendeditor.graph,canvasX,canvasY,- editor.state.selectedIds,editor.state.rotationPreview) ?? null)diff --git a/packages/vue/src/shared/input/select/hit.ts b/packages/vue/src/shared/input/select/hit.tsindex 818c20de3..2c86d5bd2 100644--- a/packages/vue/src/shared/input/select/hit.ts+++ b/packages/vue/src/shared/input/select/hit.ts@@ -11,10 +11,11 @@ export function resolveHit(fns: HitTestFns,deep = false): SceneNode | null {+ // Labels are drawn frames first, then sections, then components, so the topmost is tested first.const titleHit =- fns.hitTestFrameTitle(cx, cy) ??+ fns.hitTestComponentLabel(cx, cy) ??fns.hitTestSectionTitle(cx, cy) ??- fns.hitTestComponentLabel(cx, cy)+ fns.hitTestFrameTitle(cx, cy)if (titleHit) return titleHitconst hit = fns.hitTestInScope(cx, cy, deep)diff --git a/packages/vue/src/shared/input/select/hover.ts b/packages/vue/src/shared/input/select/hover.tsindex fb7195443..64d90d754 100644--- a/packages/vue/src/shared/input/select/hover.ts+++ b/packages/vue/src/shared/input/select/hover.ts@@ -51,13 +51,17 @@ function updateHoveredNode(cx: number,cy: number,editor: Editor,- fns: Pick<HitTestFns, 'hitTestInScope' | 'hitTestSectionTitle' | 'hitTestComponentLabel'>,+ fns: Pick<+ HitTestFns,+ 'hitTestInScope' | 'hitTestFrameTitle' | 'hitTestSectionTitle' | 'hitTestComponentLabel'+ >,deep: boolean) {const hit = deep? fns.hitTestInScope(cx, cy, true)- : (fns.hitTestSectionTitle(cx, cy) ??- fns.hitTestComponentLabel(cx, cy) ??+ : (fns.hitTestComponentLabel(cx, cy) ??+ fns.hitTestSectionTitle(cx, cy) ??+ fns.hitTestFrameTitle(cx, cy) ??fns.hitTestInScope(cx, cy, false))const editNodeId = getNodeEditState(editor)?.nodeIdeditor.setHoveredNode(@@ -69,7 +73,10 @@ export function updateHoverCursor(cx: number,cy: number,editor: Editor,- fns: Pick<HitTestFns, 'hitTestInScope' | 'hitTestSectionTitle' | 'hitTestComponentLabel'>,+ fns: Pick<+ HitTestFns,+ 'hitTestInScope' | 'hitTestFrameTitle' | 'hitTestSectionTitle' | 'hitTestComponentLabel'+ >,deep = false): string | null {if (getNodeEditState(editor)) {diff --git a/packages/vue/tests/shared/input/select/hit.test.ts b/packages/vue/tests/shared/input/select/hit.test.tsnew file mode 100644index 000000000..4255848fe--- /dev/null+++ b/packages/vue/tests/shared/input/select/hit.test.ts@@ -0,0 +1,38 @@+import { afterEach, describe, expect, test } from 'bun:test'++import { createEditor, type Editor } from '@open-pencil/core/editor'+import type { SceneNode } from '@open-pencil/scene-graph'++import type { HitTestFns } from '#vue/shared/input/select'+import { resolveHit } from '#vue/shared/input/select/hit'++let editor: Editor++afterEach(() => editor.dispose())++function labelHits(hits: Partial<Record<'frame' | 'section' | 'component', SceneNode>>): HitTestFns {+ return {+ hitTestInScope: () => null,+ isInsideContainerBounds: () => false,+ hitTestFrameTitle: () => hits.frame ?? null,+ hitTestSectionTitle: () => hits.section ?? null,+ hitTestComponentLabel: () => hits.component ?? null+ }+}++describe('label hits', () => {+ test('a press on overlapping labels picks the one drawn on top', () => {+ editor = createEditor()+ const pageId = editor.state.currentPageId+ const frame = editor.graph.createNode('FRAME', pageId, { name: 'Frame' })+ const section = editor.graph.createNode('SECTION', pageId, { name: 'Section' })+ const component = editor.graph.createNode('COMPONENT', pageId, { name: 'Button' })++ // Labels are drawn frames, then sections, then components.+ expect(resolveHit(0, 0, editor, labelHits({ frame, section, component }))?.id).toBe(+ component.id+ )+ expect(resolveHit(0, 0, editor, labelHits({ frame, section }))?.id).toBe(section.id)+ expect(resolveHit(0, 0, editor, labelHits({ frame }))?.id).toBe(frame.id)+ })+})diff --git a/tests/e2e/canvas/demo-workspace.spec.ts-snapshots/demo-components-and-variables-openpencil-darwin.png b/tests/e2e/canvas/demo-workspace.spec.ts-snapshots/demo-components-and-variables-openpencil-darwin.pngindex c4e466ae7..02c980b08 100644Binary files a/tests/e2e/canvas/demo-workspace.spec.ts-snapshots/demo-components-and-variables-openpencil-darwin.png and b/tests/e2e/canvas/demo-workspace.spec.ts-snapshots/demo-components-and-variables-openpencil-darwin.png differdiff --git a/tests/e2e/canvas/demo-workspace.spec.ts-snapshots/demo-typography-openpencil-darwin.png b/tests/e2e/canvas/demo-workspace.spec.ts-snapshots/demo-typography-openpencil-darwin.pngindex 88a4d6df7..2fbfe5c4e 100644Binary files a/tests/e2e/canvas/demo-workspace.spec.ts-snapshots/demo-typography-openpencil-darwin.png and b/tests/e2e/canvas/demo-workspace.spec.ts-snapshots/demo-typography-openpencil-darwin.png differdiff --git a/tests/e2e/canvas/labels/frame-title.spec.ts b/tests/e2e/canvas/labels/frame-title.spec.tsnew file mode 100644index 000000000..3f669f80c--- /dev/null+++ b/tests/e2e/canvas/labels/frame-title.spec.ts@@ -0,0 +1,70 @@+import type { Page } from '@playwright/test'++import { expect, test, useEditorSetupWithClear } from '#tests/e2e/fixtures'++const editor = useEditorSetupWithClear('/?test&no-chrome&no-rulers')++type Frame = { id: string; name: string; x: number; y: number; parentId: string | null }++function topLevelFrames(page: Page): Promise<Frame[]> {+ return page.evaluate(() => {+ const store = window.openPencil?.getStore?.()+ if (!store) throw new Error('OpenPencil store not initialized')+ const pageNode = store.graph.getNode(store.state.currentPageId)+ return (pageNode?.childIds ?? []).flatMap((id) => {+ const node = store.graph.getNode(id)+ return node?.type === 'FRAME'+ ? [{ id, name: node.name, x: node.x, y: node.y, parentId: node.parentId }]+ : []+ })+ })+}++function selection(page: Page): Promise<string[]> {+ return page.evaluate(() => {+ const store = window.openPencil?.getStore?.()+ if (!store) throw new Error('OpenPencil store not initialized')+ return [...store.state.selectedIds]+ })+}++/** A point on a frame's name, which sits just above its top-left corner, in canvas pixels. */+function namePoint(page: Page, frame: Frame) {+ return page.evaluate((target) => {+ const store = window.openPencil?.getStore?.()+ if (!store) throw new Error('OpenPencil store not initialized')+ const { zoom, panX, panY } = store.state+ return { x: target.x * zoom + panX + 6, y: target.y * zoom + panY - 13 }+ }, frame)+}++test('a frame holding a dragged-in frame is selected and moved by its name', async () => {+ const { canvas, page } = editor+ await canvas.selectTool('frame')+ await canvas.drag(100, 100, 500, 450)+ await canvas.selectTool('frame')+ await canvas.drag(650, 100, 800, 250)+ await canvas.selectTool('select')+ // Drag the second frame by its body into the first.+ await canvas.drag(725, 175, 300, 280)+ await canvas.waitForRender()++ const [outer] = await topLevelFrames(page)+ expect(await topLevelFrames(page)).toHaveLength(1)+ await page.keyboard.press('Escape')+ await page.keyboard.press('Escape')+ expect(await selection(page)).toEqual([])++ // Its body is a background now, as in Figma, so its name is how it is picked.+ const name = await namePoint(page, outer)+ await canvas.click(name.x, name.y)+ await expect.poll(() => selection(page)).toEqual([outer.id])++ await page.keyboard.press('Escape')+ await canvas.drag(name.x, name.y, name.x + 80, name.y + 40)+ await canvas.waitForRender()+ const [moved] = await topLevelFrames(page)+ expect(moved.id).toBe(outer.id)+ expect(moved.x).toBeCloseTo(outer.x + 80, 0)+ expect(moved.y).toBeCloseTo(outer.y + 40, 0)+})diff --git a/tests/engine/render/canvas/labels/layout.test.ts b/tests/engine/render/canvas/labels/layout.test.tsindex ef9b33378..f5af482db 100644--- a/tests/engine/render/canvas/labels/layout.test.ts+++ b/tests/engine/render/canvas/labels/layout.test.ts@@ -81,7 +81,7 @@ for (const flipX of [false, true]) {expect(transform.rotation).toBeGreaterThanOrEqual(-45)expect(transform.rotation).toBeLessThan(45)expect(- hitTestFrameTitle(graph, world.x, world.y, 2, new Set([frame.id]), font, { preview })?.id+ hitTestFrameTitle(graph, world.x, world.y, 2, page.id, font, undefined, { preview })?.id).toBe(frame.id)})}@@ -97,8 +97,69 @@ test('hidden component labels and the clipped-away part of long titles are not hwidth: 50,height: 100})- expect(hitTestFrameTitle(graph, 140, 90, 1, new Set([frame.id]), font)?.id).toBe(frame.id)- expect(hitTestFrameTitle(graph, 170, 90, 1, new Set([frame.id]), font)).toBeNull()+ expect(hitTestFrameTitle(graph, 140, 90, 1, page.id, font)?.id).toBe(frame.id)+ expect(hitTestFrameTitle(graph, 170, 90, 1, page.id, font)).toBeNull()graph.createNode('COMPONENT', frame.id, { name: 'Not drawn here', width: 80, height: 40 })expect(hitTestComponentLabel(graph, 104, 90, 1, page.id, font)).toBeNull()})++test('every frame on the page or in a section is hit by its name, selected or not', () => {+ const graph = new SceneGraph()+ const page = expectDefined(graph.getPages()[0], 'page')+ const outer = graph.createNode('FRAME', page.id, {+ name: 'Outer',+ x: 100,+ y: 100,+ width: 200,+ height: 200+ })+ const inner = graph.createNode('FRAME', outer.id, {+ name: 'Inner',+ x: 20,+ y: 40,+ width: 100,+ height: 100+ })+ const section = graph.createNode('SECTION', page.id, {+ name: 'Flows',+ x: 400,+ y: 100,+ width: 300,+ height: 300+ })+ const inSection = graph.createNode('FRAME', section.id, {+ name: 'Step',+ x: 20,+ y: 60,+ width: 100,+ height: 100+ })++ // No selection: the name above a frame holding layers still selects it.+ expect(hitTestFrameTitle(graph, 104, 90, 1, page.id, font)?.id).toBe(outer.id)+ expect(hitTestFrameTitle(graph, 424, 150, 1, page.id, font)?.id).toBe(inSection.id)+ // A frame inside another frame shows no name, so the spot above it is not a target.+ expect(hitTestFrameTitle(graph, 124, 130, 1, page.id, font)).toBeNull()+ expect(inner.parentId).toBe(outer.id)++ // Locked frames cannot be picked on the canvas, by their names either.+ graph.updateNode(outer.id, { locked: true })+ expect(hitTestFrameTitle(graph, 104, 90, 1, page.id, font)).toBeNull()+})++test('a frame just outside the view whose name is inside it is still hit by its name', () => {+ const graph = new SceneGraph()+ const page = expectDefined(graph.getPages()[0], 'page')+ const frame = graph.createNode('FRAME', page.id, {+ name: 'Below',+ x: 100,+ y: 205,+ width: 200,+ height: 100+ })+ // The view ends at y = 200, above the frame; its name sits just above the frame, in view.+ const viewport = { x: 0, y: 0, w: 400, h: 200 }+ expect(hitTestFrameTitle(graph, 104, 197, 1, page.id, font, undefined, { viewport })?.id).toBe(+ frame.id+ )+})diff --git a/tests/engine/render/canvas/labels/transform.test.ts b/tests/engine/render/canvas/labels/transform.test.tsindex a81c62d23..718517b19 100644--- a/tests/engine/render/canvas/labels/transform.test.ts+++ b/tests/engine/render/canvas/labels/transform.test.ts@@ -111,6 +111,6 @@ test('section and nested frame hit targets follow their rendered title transformexpect(hitTestSectionTitle(graph, 260, 54, 1, page.id, font, catalog)?.id).toBe(section.id)}// The readable frame title moves to the horizontal edge at (180, 70).- expect(hitTestFrameTitle(graph, 184, 60, 1, new Set([frame.id]), font)?.id).toBe(frame.id)- expect(hitTestFrameTitle(graph, 230, 74, 1, new Set([frame.id]), font)).toBeNull()+ expect(hitTestFrameTitle(graph, 184, 60, 1, page.id, font)?.id).toBe(frame.id)+ expect(hitTestFrameTitle(graph, 230, 74, 1, page.id, font)).toBeNull()})