Getting started
By the end of this page you have a board in your app that you can draw on and that survives a reload.
Install
npm install @fieldnotes/core
@fieldnotes/core has no runtime dependencies and needs no framework. It ships ES module and CommonJS builds with TypeScript types.
Mount a board
Create a Viewport on any element. Passing tools: 'default' registers select, pencil, eraser,
shapes, arrows, notes, text, frames and pan, and starts on select. Frame uses F.
import { Viewport } from '@fieldnotes/core';
const viewport = new Viewport(document.getElementById('board')!, {
background: { pattern: 'dots', spacing: 24 },
tools: 'default',
});
Save and restore
The whole board, including layers and camera, serialises to one JSON string. Store it anywhere that holds text.
const saved = localStorage.getItem('board');
if (saved) viewport.loadJSON(saved);
let timer: ReturnType<typeof setTimeout> | undefined;
viewport.onStateChange(() => {
clearTimeout(timer);
timer = setTimeout(() => localStorage.setItem('board', viewport.exportJSON()), 250);
});
Saving and loading shows AutoSave, which debounces the save for you and can write to IndexedDB.
Clean up
Call viewport.destroy() when the board leaves the page. It removes the board’s DOM and listeners, stops the render loop and frees cached images.
viewport.destroy();