@nextgensoftwares/folio-canvas-board
The browser board on folio-canvas: stylus, finger, mouse and smart-board input with palm rejection, pinch, pan and wheel zoom, a low-latency live layer, select / move / resize / rotate with smart guides, shape and sticky tools, a laser pointer, partial erasing, an external smart-pen bridge and lecture capture. No framework; the React app is folio-plugin-canvas. Guide: Boards.
import { createCanvasBoard, followFolioTheme } from '@nextgensoftwares/folio-canvas-board';
const board = createCanvasBoard(el, { pageSize: { width: 1600, height: 1000 }, background: 'grid', tool: 'pen' });
followFolioTheme(board, el); // canvas colours from Folio's tokens
board.store.subscribe((e, origin) => origin === 'local' && save(e));Board
| Export | Description |
|---|---|
createCanvasBoard(el, options?) → CanvasBoard | mount a board in el (it fills it). The board holds the store, per-user history, tool, style, camera and selection; it draws, selects, edits (updateSelection, updateObjects, arrange, duplicateSelection, insertImage, setPage, deleteSelection, nudge, align, distribute, group, ungroup), copies and pastes (copy, cut, paste), types (editText, editing, stopEditing, toggleBold), sets the laser's look (laser, setLaser), reports a gesture in progress (busy), navigates pages, exports SVG, and calls onChange listeners |
CanvasBoardOptions | document or shared store, page size, background, input, zoom limits, theme, text engine, image cache (default: the board loads each picture itself), images (pictures can be pasted and dropped; default on), tool, the tools that can be picked (by keys or setTool; default all), style, create style, eraser size and mode, the laser (colour, core width, glow, tail length; laserColor too), snapping, author and id prefix, read-only, camera sharing and following (sharingCamera, followingCamera; panning or zooming yourself stops following), keyboard (while the board has focus, 'page': anywhere on the page but in fields, menus and dialogs, or off), keepTool (stay on a create tool after placing; by default the board goes back to select with the new object selected) (the pen and the marker each keep their own thickness) |
BoardTool | select, pen, highlighter, eraser, hand, laser, shape, sticky, text, connector, frame |
BoardClip, CLIP_TYPE, clipOf(store, ids), parseClip(text), clipText(clip) | objects on the clipboard: what copy writes (as application/x-folio-canvas, with their text as plain text for other apps) and paste reads |
CreateStyle | what the shape, sticky and connector tools create (native shape, Office preset, colours, connector route and arrowheads) |
ArrangeOp | front, forward, backward, back (one step past what the selection overlaps) |
PagePatch | page settings to change; undefined clears one |
Overlay | what the live layer draws besides ink (selection, handles, guides, marquee) |
canvasThemeFrom(el, opts?), followFolioTheme(board, el, opts?), CanvasThemeOptions | canvas colours from Folio's tokens: surroundings and selection follow the app, ink and grid follow the paper. paper: 'page' (default) is the document page, white in the dark theme too; paper: 'app' follows the app's background (whiteboards) |
Text
Stickies, shapes and text boxes are typed into in place: double-click one, press Enter with it selected, or call board.editText(id). A new sticky opens for typing as soon as it is placed. The text tool (T) makes a text box: click for one as wide as its text, drag across for one that wraps at that width.
A transparent textarea sits on the object's text frame in the same size, family and alignment while the board paints the object without its text, so the caret is where the text is drawn. Each keystroke is a field update: collaborators see the text as it is typed, a peer's edit to the same text shows up in the editor, and the edit (with the sticky or text box it created) is one undo step. A text box is not created until something is typed and is removed if it is left empty. Escape, Ctrl+Enter or a click elsewhere finishes; board shortcuts never fire while typing.
Clipboard, frames and nudging
Ctrl+C, Ctrl+X and Ctrl+V copy, cut and paste objects through the system clipboard, so they move between boards and tabs; other apps get their text. A paste lands under the pointer when it is over the board, otherwise a step along from the originals while they are in view (each paste a step further), else mid-view, with new ids, on top and selected. Connectors copied with both ends keep joining the copies; an end left behind becomes a free point where it was. Pictures pasted or dropped onto the board land where they fall (several fan out); plain text pastes as a text box when the text tool is on offer. A copied frame brings what is inside it. The arrow keys nudge the selection a unit (ten with Shift), a run of them one undo step; they are left to the page when nothing is selected or focus is on a toolbar or field.
Objects sharing a group id act as one: a click picks the whole group, a double-click picks one member inside it (another types into it), Shift+click toggles the group, and align and distribute treat it as one box. Ctrl+G groups the selection (groups in it merge), Ctrl+Shift+G ungroups; copies make a group of their own. align(mode) lines the selection up (a lone object on a bounded page with the page) and distribute(axis) evens out the gaps between three or more, each one undo step.
The frame tool (F) drags out a titled area (a click gives a default size). Frames go under everything, so what they are drawn around ends up inside them, and moving one carries its contents. They are picked by their title or edge; inside, clicks and marquees reach the contents.
Connectors
The connector tool (C) drags a line from wherever it starts to wherever it ends. Each end attaches to the shape, sticky, text box or picture under it: dropped near a side centre it pins there, anywhere else on the object it takes the nearest edge, so it slides round the object as things move. On empty board an end is a free point. While the tool hovers, the object an end would attach to and its side centres are shown. A selected connector shows handles on its ends: drag one to re-attach it. Lines route straight, as an elbow or curved, with optional arrowheads at either end (createStyle.route, startArrow, endArrow). Peers watch the line drawn; the gesture is one undo step.
Connecting doesn't need the tool: with the select tool, a lone selected object shows a connect handle outside each side. Drag one to another object to join them from that side, or onto empty board for a new object like it there, already joined and selected. Placing anything with a create tool goes back to select with it selected, so a second click selects rather than stamping another, and a double-click (or Enter) types into it.
Ink stays ink: with the select tool a click goes through a drawing to what is under it; a marquee picks drawings up, and once selected they drag, resize, recolour and change thickness (no rotate handle). On a thin selection, pressing the object itself moves it rather than grabbing a side handle.
The laser draws a comet: a slim, hot core in a soft glow, its tail thinning behind the tip and gone laser.tail ms after the last move (peers' trails too, in their colour).
Input
| Export | Description |
|---|---|
InputOptions, DEFAULT_INPUT, TouchMode | what fingers do (auto: draw until a pen is seen; draw; navigate), palm size, large contacts (ignore or erase), wheel, barrel button |
classifyPointer(info, state, options), PointerInfo, PolicyState, PointerAction | the input policy: what a pointer does from down to up (palm rejection, pen beats touch, pinch) |
isEraserEnd, isBarrel, strokeWasGestureStart | stylus eraser end and barrel button; whether a short stroke was really the start of a pinch |
createExternalPen(...), ExternalPen, ExternalPenOptions, ExternalCoords | Bluetooth smart pens and smart-board SDKs feed the same events as the stylus (board.externalPen()) |
Lectures
| Export | Description |
|---|---|
startLecture(board, options?), LectureCapture, LectureCaptureOptions, LectureResult | record ink, page turns and the presenter's camera with voice on one clock |
playLecture(board, recording, audio?), LecturePlayback | play it back (the audio is the clock), seek, follow the presenter's camera |