- Snap vector points, moved layers, and resized edges to geometry, objects, guides, and pixels - Add persistent snapping preferences with browser and native menu controls - Normalize canvas and layout guides across Scene Graph and .fig conversion - Clear transient snapping feedback across interrupted interactions
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import { describe, expect, test } from 'bun:test'
|
|
|
|
import type { Canvas } from 'canvaskit-wasm'
|
|
|
|
import type { SceneGraph, SceneNode } from '@open-pencil/scene-graph'
|
|
|
|
import { drawPageGuides } from '#core/canvas/page-guides'
|
|
|
|
import { createMockCanvas, createMockRenderer, mockCalls } from './effects/helpers'
|
|
|
|
function graphWithGuides(guides: SceneNode['guides']): SceneGraph {
|
|
const page = {
|
|
id: 'page',
|
|
guides
|
|
} as SceneNode
|
|
return {
|
|
rootId: 'root',
|
|
getNode: (id: string) => (id === 'page' ? page : null)
|
|
} as SceneGraph
|
|
}
|
|
|
|
describe('page guide rendering', () => {
|
|
test('renders imported Figma page guides in screen space', () => {
|
|
const r = createMockRenderer({
|
|
pageId: 'page',
|
|
panX: 10,
|
|
panY: 20,
|
|
zoom: 2,
|
|
viewportWidth: 300,
|
|
viewportHeight: 200
|
|
})
|
|
const canvas = createMockCanvas()
|
|
const graph = graphWithGuides([
|
|
{ axis: 'x', position: 42 },
|
|
{ axis: 'y', position: 84 }
|
|
])
|
|
|
|
drawPageGuides(r, canvas as Canvas, graph)
|
|
|
|
expect(mockCalls(canvas.drawRect)).toHaveLength(2)
|
|
expect(mockCalls(r.ck.LTRBRect)).toEqual([
|
|
[94, 0, 95, 200],
|
|
[0, 188, 300, 189]
|
|
])
|
|
})
|
|
|
|
test('ignores pages without guides', () => {
|
|
const r = createMockRenderer({ pageId: 'page' })
|
|
const canvas = createMockCanvas()
|
|
const graph = graphWithGuides([])
|
|
|
|
drawPageGuides(r, canvas as Canvas, graph)
|
|
|
|
expect(canvas.drawRect).not.toHaveBeenCalled()
|
|
})
|
|
})
|