Skip to content
Calm motion: animations on this site only fade, with no movement

InfiniteCanvas ​

A surface you pan and zoom, with your own things on it

A viewport onto a larger plane: a story board, a flow editor, a map-like diagram, a photo wall. Whatever you put inside is positioned in the canvas' own coordinates and moves and scales with the view. For a list the reader scrolls, use ScrollArea. For a diagram with draggable nodes and links, NodeGraph is built on this.

Board of cards
100% at 40, 40
Intro
Plot
Characters
Ending
  • Place children with position: absolute; left; top in canvas coordinates: the origin is where view.x, view.y puts it. The canvas needs a height (it fills the width).
  • Mouse and pen: drag the background to pan (middle button works over children too). The wheel pans, Ctrl+wheel or a trackpad pinch zooms around the pointer, wheelZoom makes the plain wheel zoom. Touch: one finger pans, two pinch and pan.
  • Keyboard: focus the canvas, arrows pan (Shift: further), + / − zoom, 0 or Home resets, and the zoom is announced. Keys pressed inside a child belong to the child. Buttons in the corner zoom and reset (:controls="false" hides them).
  • v-model:view is { x, y, zoom }. The exposed fit(rect), centerOn(x, y), zoomBy(factor), reset() and toWorld(clientX, clientY) drive and read it. Children can inject(blessCanvasKey) for the view and toWorld.
  • minZoom / maxZoom bound the zoom. grid draws a dot grid that moves and scales with the view.

Usage ​

ts
import { BlessInfiniteCanvas, blessCanvasKey } from "blessing-ui";

API ​

Props

NameTypeDefaultDescription
minZoomnumber0.25
maxZoomnumber4
gridbooleantruedraw a dot grid that moves and scales with the view
controlsbooleantruethe + / − / fit buttons in the corner
wheelZoomboolean—turn the plain mouse wheel into zoom (otherwise it pans, and Ctrl+wheel or a pinch zooms)
labelstring"Canvas"
labelsPartial<{ zoomIn: string; zoomOut: string; reset: string; zoom: (percent: number) => string; hint: string; }>—
viewCanvasView{ x: 0, y: 0, zoom: 1 }

Events

NamePayloadDescription
update:view[value: CanvasView]

Slots

NameScopeDescription
default{ view: CanvasView; zoom: number; }

Exposed

NameTypeDescription
zoomBy(factor: number, at?: { x: number; y: number; } | undefined) => void
reset() => void
fit(rect: { x: number; y: number; width: number; height: number; }, pad?: number) => void
centerOn(x: number, y: number) => void
toWorld(cx: number, cy: number) => { x: number; y: number; }

Released under the MIT License. Character names and artwork belong to their owners.