Configuration
MathCanvas.init(target, options)
Every option is read at initialisation only. Changing one afterwards requires
destroy() and a fresh init(); document content is changed with
setDocument().
Options#
| Option | Type | Default | Description |
|---|---|---|---|
document |
object | string |
— | Document to load, see Data |
height |
number | string |
'620px' |
Frame height; numbers mean pixels |
width |
number | string |
'100%' |
Frame width |
className |
string |
— | Extra CSS class on the wrapper |
id |
string |
generated | Instance identifier, readable at board.id |
storageKey |
string | null |
null |
localStorage key for autosave; null disables it |
autoLabel |
boolean |
true |
Name points A, B, C… automatically |
showHints |
boolean |
true |
Hint line under the canvas |
canvasBg |
'cream' | 'white' |
'cream' |
Canvas background |
fonts |
boolean |
true |
Load Archivo and Lora |
keyboard |
'container' | 'window' | false |
'container' |
Keyboard shortcut scope |
autoFocus |
boolean |
false |
Take focus right after initialisation |
exportMode |
'handoff' | 'download' |
inferred | Behaviour of the two export buttons |
exportLabels |
{ svg, png } |
{ svg: 'SVG', png: 'PNG' } |
Labels of the two export buttons |
onReady |
function |
— | Same as on('ready', fn) |
onChange |
function |
— | Same as on('change', fn) |
onExport |
function |
— | Same as on('export', fn), and turns on exportMode: 'handoff' |
Notes#
target#
A CSS selector (string) or an Element. init throws an Error when
nothing matches. Initialising the same element twice returns the existing
instance.
height, width#
Numbers mean pixels; numeric strings mean pixels too (data-height="420");
strings with a unit are used as given ('70vh'). The value is applied to the
frame the bundle creates inside target; the board always fills that frame and
never grows with its content.
storageKey#
Off by default. When set, the drawing is written to localStorage 400 ms after
each change. Instances sharing a key overwrite each other. When both document
and storageKey are present, document wins.
keyboard#
| Value | Behaviour |
|---|---|
'container' |
Handle keys only while focus is inside the board |
'window' |
Handle keys at document scope |
false |
No keyboard shortcuts |
exportMode#
Inferred: with onExport → 'handoff'; without → 'download'. The state is
decided when the toolbar is built, so registering on('export', fn) after
initialisation cannot turn handoff on by itself. See
Data.