@teachinglab/omd 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/canvas/tools/EraserTool.js +1 -1
  2. package/canvas/tools/PencilTool.js +1 -1
  3. package/canvas/tools/SelectTool.js +1 -1
  4. package/docs/api/configuration-options.md +198 -104
  5. package/docs/api/eventManager.md +83 -68
  6. package/docs/api/focusFrameManager.md +145 -150
  7. package/docs/api/index.md +106 -91
  8. package/docs/api/main.md +63 -58
  9. package/docs/api/omdBinaryExpressionNode.md +86 -227
  10. package/docs/api/omdCanvas.md +84 -142
  11. package/docs/api/omdConfigManager.md +113 -192
  12. package/docs/api/omdConstantNode.md +53 -117
  13. package/docs/api/omdDisplay.md +87 -121
  14. package/docs/api/omdEquationNode.md +174 -161
  15. package/docs/api/omdEquationSequenceNode.md +259 -301
  16. package/docs/api/omdEquationStack.md +157 -103
  17. package/docs/api/omdFunctionNode.md +83 -141
  18. package/docs/api/omdGroupNode.md +79 -182
  19. package/docs/api/omdHelpers.md +88 -96
  20. package/docs/api/omdLeafNode.md +86 -163
  21. package/docs/api/omdNode.md +202 -101
  22. package/docs/api/omdOperationDisplayNode.md +118 -139
  23. package/docs/api/omdOperatorNode.md +92 -127
  24. package/docs/api/omdParenthesisNode.md +134 -122
  25. package/docs/api/omdPopup.md +192 -117
  26. package/docs/api/omdPowerNode.md +132 -127
  27. package/docs/api/omdRationalNode.md +145 -128
  28. package/docs/api/omdSimplification.md +79 -110
  29. package/docs/api/omdSqrtNode.md +144 -79
  30. package/docs/api/omdStepVisualizer.md +147 -115
  31. package/docs/api/omdStepVisualizerHighlighting.md +66 -61
  32. package/docs/api/omdStepVisualizerInteractiveSteps.md +109 -129
  33. package/docs/api/omdStepVisualizerLayout.md +71 -60
  34. package/docs/api/omdStepVisualizerTextBoxes.md +77 -68
  35. package/docs/api/omdToolbar.md +131 -102
  36. package/docs/api/omdTranscriptionService.md +96 -76
  37. package/docs/api/omdTreeDiff.md +170 -134
  38. package/docs/api/omdUnaryExpressionNode.md +137 -174
  39. package/docs/api/omdUtilities.md +83 -70
  40. package/docs/api/omdVariableNode.md +123 -148
  41. package/index.js +2 -2
  42. package/package.json +1 -1
  43. /package/canvas/drawing/{segment.js → Segment.js} +0 -0
@@ -1,227 +1,86 @@
1
- # omdBinaryExpressionNode
2
-
3
- Represents binary operations (addition, subtraction, multiplication, division) in mathematical expressions.
4
-
5
- ## Class: `omdBinaryExpressionNode extends omdNode`
6
-
7
- ```javascript
8
- import { omdBinaryExpressionNode } from './omd/nodes/omdBinaryExpressionNode.js';
9
- ```
10
-
11
- ### Constructor
12
-
13
- ```javascript
14
- new omdBinaryExpressionNode(ast)
15
- ```
16
-
17
- **Parameters:**
18
- - `ast` {Object} - The AST node containing:
19
- - `args`: Array of at least 2 operand AST nodes
20
- - `op`: Operator symbol
21
- - `implicit`: Optional boolean for implicit multiplication
22
-
23
- **Description:**
24
- Creates a node representing a binary operation like `a + b`, `x * y`, etc.
25
-
26
- ### Properties
27
-
28
- Inherits all properties from [omdNode](./omdNode.md), plus:
29
-
30
- #### `left`
31
- - **Type:** [omdNode](./omdNode.md)
32
- - **Description:** The left operand node
33
-
34
-
35
- #### `operation`
36
- - **Type:** string
37
- - **Description:** The function name for the operation (e.g., 'add', 'multiply', 'subtract', 'divide').
38
-
39
-
40
- #### `op`
41
- - **Type:** [omdOperatorNode](./omdOperatorNode.md) | null
42
- - **Description:** The operator node (null for implicit multiplication). For multiplication, this may be removed and replaced with implicit multiplication based on configuration.
43
-
44
-
45
- #### `isImplicit`
46
- - **Type:** boolean
47
- - **Description:** Whether multiplication is implicit (e.g., `2x`). Determined by AST or configuration.
48
-
49
- #### `right`
50
- - **Type:** [omdNode](./omdNode.md)
51
- - **Description:** The right operand node
52
-
53
- ### Methods
54
-
55
- Inherits all methods from [omdNode](./omdNode.md), plus:
56
-
57
-
58
- #### `parseOperation()`
59
- Internal method to extract the function name for the operation from the AST.
60
- - **Returns:** string - Function name (e.g., 'add', 'multiply', etc.)
61
-
62
- ---
63
-
64
-
65
- #### `createExpressionNode(ast)`
66
- Internal method to create operand nodes.
67
- - `ast` {Object} - The AST for the operand
68
- - **Returns:** omdNode
69
-
70
- ---
71
-
72
-
73
- #### `createOperatorNode(ast)`
74
- Internal method to create operator node.
75
- - `ast` {Object} - The AST with operator info
76
- - **Returns:** omdOperatorNode
77
-
78
- ---
79
-
80
- #### `computeDimensions()`
81
- Calculates dimensions of expression.
82
- - Computes dimensions of all parts
83
- - Adds spacing between operator and operands
84
- - Sets total width and height
85
-
86
- ---
87
-
88
- #### `updateLayout()`
89
- Updates positions of all elements.
90
- - Aligns operands and operator on baseline
91
- - Handles spacing for implicit multiplication
92
-
93
- ---
94
-
95
-
96
- #### `getAlignmentBaseline()`
97
- Gets vertical alignment point.
98
- - **Returns:** number - Y-coordinate based on:
99
- - Operator baseline if explicit
100
- - Max child baseline if implicit
101
-
102
- ---
103
-
104
-
105
- #### `clone()`
106
- Creates a deep clone of the expression.
107
- - **Returns:** omdBinaryExpressionNode - A new instance with:
108
- - Cloned operands and operator
109
- - Rebuilt argument list
110
- - Copied AST data and operation
111
- - Original node's ID added to provenance array
112
-
113
- ---
114
-
115
-
116
- #### `getSpacing()`
117
- Gets horizontal spacing between elements.
118
- - **Returns:** number - 0 for implicit multiplication, otherwise scales with font size.
119
-
120
- ---
121
-
122
-
123
-
124
- #### `_shouldUseImplicitMultiplication(left, right)` (internal)
125
- Internal method to check if multiplication should be implicit.
126
- - Based on configuration and operand types
127
- - **Returns:** boolean
128
- > Note: This method is intended for internal use and may change without notice.
129
-
130
- ---
131
-
132
-
133
- #### `_shouldReorderMultiplication(left, right)` (internal)
134
- Internal method to check if operands should be reordered for coefficient multiplication (e.g., x*2 → 2*x).
135
- - **Returns:** boolean
136
- > Note: This method is intended for internal use and may change without notice.
137
-
138
- ---
139
-
140
-
141
- #### `toMathJSNode()`
142
- Converts to math.js AST format.
143
- - **Returns:** Object - A math.js-compatible AST node with:
144
- - `type`: "OperatorNode"
145
- - `op`: Operator symbol
146
- - `fn`: Function name
147
- - `args`: Operand ASTs
148
- - `implicit`: Boolean flag
149
- - `id`: Node ID
150
- - `provenance`: Provenance array
151
-
152
- ---
153
-
154
-
155
- #### `toString()`
156
- Convert to string representation.
157
- - **Returns:** string - Format depends on operation. Handles implicit multiplication and adds parentheses as needed for precedence.
158
-
159
- ---
160
-
161
-
162
-
163
- #### `evaluate(variables)`
164
- Evaluate the expression.
165
- - `variables` {Object} - Variable name to value mapping
166
- - **Returns:** number - The evaluated result
167
- - **Throws:** Error if division by zero is encountered or if the operation is unsupported.
168
-
169
-
170
- #### `needsParentheses()`
171
- Determines if parentheses are needed based on parent operator precedence.
172
- - **Returns:** boolean
173
-
174
- ### Examples
175
-
176
- ```javascript
177
- // Create from AST
178
- const node = new omdBinaryExpressionNode({
179
- type: 'OperatorNode',
180
- op: '+',
181
- fn: 'add',
182
- args: [
183
- { type: 'SymbolNode', name: 'x' },
184
- { type: 'ConstantNode', value: 2 }
185
- ]
186
- });
187
-
188
- // Implicit multiplication
189
- const implicitMult = new omdBinaryExpressionNode({
190
- type: 'OperatorNode',
191
- op: '*',
192
- fn: 'multiply',
193
- args: [
194
- { type: 'ConstantNode', value: 2 },
195
- { type: 'SymbolNode', name: 'x' }
196
- ],
197
- implicit: true
198
- });
199
-
200
- // Division by zero (throws error)
201
- try {
202
- const divByZero = new omdBinaryExpressionNode({
203
- type: 'OperatorNode',
204
- op: '/',
205
- fn: 'divide',
206
- args: [
207
- { type: 'ConstantNode', value: 5 },
208
- { type: 'ConstantNode', value: 0 }
209
- ]
210
- });
211
- divByZero.evaluate();
212
- } catch (e) {
213
- console.error('Error:', e.message); // Error: Division by zero.
214
- }
215
-
216
- // Render with proper spacing
217
- node.setFontSize(24);
218
- node.computeDimensions();
219
- node.updateLayout();
220
- ```
221
-
222
- ### See Also
223
-
224
- - [omdNode](./omdNode.md) - Parent class
225
- - [omdOperatorNode](./omdOperatorNode.md) - For operators
226
- - [omdConstantNode](./omdConstantNode.md) - For numeric operands
227
- - [omdVariableNode](./omdVariableNode.md) - For variable operands
1
+ # omdBinaryExpressionNode
2
+
3
+ Represents a binary operation in a mathematical expression, such as addition (`a + b`), subtraction, multiplication, or division. This node is a cornerstone of the expression tree, containing a left operand, a right operand, and an operator.
4
+
5
+ ## Class Definition
6
+
7
+ ```javascript
8
+ export class omdBinaryExpressionNode extends omdNode
9
+ ```
10
+
11
+ ## Constructor
12
+
13
+ ### `new omdBinaryExpressionNode(ast)`
14
+
15
+ Creates a new `omdBinaryExpressionNode` instance.
16
+
17
+ - **`ast`** (`object`): The abstract syntax tree (AST) node from a parser like math.js. It must contain:
18
+ - `args`: An array with at least two operand nodes.
19
+ - `op`: The operator symbol (e.g., `+`, `*`).
20
+ - `fn`: The function name for the operation (e.g., `add`, `multiply`).
21
+ - `implicit` (`boolean`, optional): `true` if the multiplication is implicit (e.g., `2x`).
22
+
23
+ During construction, the node automatically handles a critical piece of mathematical convention: **implicit multiplication**. Based on the configuration in `omdConfigManager`, it will:
24
+
25
+ 1. **Reorder Operands**: If it encounters an expression like `x * 2`, it will automatically reorder it to the conventional `2 * x` by swapping the left and right child nodes.
26
+ 2. **Determine Implicit Form**: It checks if the combination of operands (e.g., a constant and a variable) should be represented implicitly. If so, it removes the visible operator (`*`) and marks the node as implicit.
27
+
28
+ ## Public Properties
29
+
30
+ - **`left`** ([`omdNode`](./omdNode.md)): The node representing the left-hand side of the operation.
31
+ - **`right`** ([`omdNode`](./omdNode.md)): The node representing the right-hand side of the operation.
32
+ - **`op`** ([`omdOperatorNode`](./omdOperatorNode.md) | `null`): The node for the operator. This is `null` for implicit multiplication.
33
+ - **`operation`** (`string`): The name of the mathematical function (e.g., `'add'`, `'multiply'`).
34
+ - **`isImplicit`** (`boolean`): `true` if the node represents implicit multiplication.
35
+
36
+ ## Public Methods
37
+
38
+ ### `clone()`
39
+
40
+ Creates a deep, recursive clone of the node, including its children (`left`, `right`, `op`). The new node's `provenance` property will link back to the ID of this original node.
41
+
42
+ - **Returns**: A new `omdBinaryExpressionNode` instance.
43
+
44
+ ### `evaluate(variables)`
45
+
46
+ Recursively evaluates the expression and returns the numerical result.
47
+
48
+ - **`variables`** (`object`, optional): A map of variable names to their numeric values (e.g., `{ x: 5 }`).
49
+ - **Returns**: `number` - The result of the calculation.
50
+ - **Throws**: An `Error` for unsupported operations or division by zero.
51
+
52
+ ### `needsParentheses()`
53
+
54
+ Determines if this expression needs to be wrapped in parentheses to maintain the correct order of operations when it is a child of another binary expression.
55
+
56
+ - **Returns**: `boolean` - `true` if parentheses are required.
57
+
58
+ ### `setHighlight(highlightOn, color)`
59
+
60
+ Applies or removes a highlight from the node and all of its children (left, right, and operator).
61
+
62
+ - **`highlightOn`** (`boolean`): `true` to highlight, `false` to remove.
63
+ - **`color`** (`string`, optional): The color of the highlight.
64
+
65
+ ### `clearProvenanceHighlights()`
66
+
67
+ Recursively clears all provenance-related highlights from this node and its children.
68
+
69
+ ### `toMathJSNode()`
70
+
71
+ Converts the node back into a math.js-compatible AST format.
72
+
73
+ - **Returns**: `object` - A math.js OperatorNode.
74
+
75
+ ### `toString()`
76
+
77
+ Converts the node into a human-readable string, automatically handling parentheses for precedence.
78
+
79
+ - **Returns**: `string` - The string representation of the expression.
80
+
81
+ ## Internal Methods
82
+
83
+ - **`_shouldUseImplicitMultiplication(left, right)`**: Checks the configuration to decide if implicit multiplication is appropriate for the given operand types.
84
+ - **`_shouldReorderMultiplication(left, right)`**: Determines if operands should be swapped to follow convention (e.g., `variable * constant` -> `constant * variable`).
85
+ - **`computeDimensions()`**: Calculates the bounding box of the expression.
86
+ - **`updateLayout()`**: Positions the left operand, operator, and right operand correctly, aligning them along their baseline.
@@ -1,142 +1,84 @@
1
- # omdCanvas
2
-
3
- The `omdCanvas` class is the core component for creating and managing a drawing canvas. It provides the primary interface for interacting with the canvas, including drawing, selecting, and managing strokes, as well as handling events and integrating with various tools and features.
4
-
5
- ## Class Definition
6
-
7
- ```javascript
8
- export class omdCanvas {
9
- // ...
10
- }
11
- ```
12
-
13
- ## Constructor
14
-
15
- ### `new omdCanvas(container, [options])`
16
-
17
- Creates a new `omdCanvas` instance.
18
-
19
- * **container** (`HTMLElement` or `string`): The HTML element or a CSS selector string for the container where the canvas will be rendered.
20
- * **[options]** (`object`, optional): Configuration options for the canvas. These options are passed to `CanvasConfig`.
21
-
22
- ## Properties
23
-
24
- * **container** (`HTMLElement`): The HTML container element for the canvas.
25
- * **config** (`CanvasConfig`): The configuration object for the canvas.
26
- * **svg** (`SVGElement`): The main SVG element representing the canvas.
27
- * **backgroundLayer** (`SVGGElement`): The SVG group element for background elements (e.g., grid).
28
- * **drawingLayer** (`SVGGElement`): The SVG group element for drawing strokes.
29
- * **uiLayer** (`SVGGElement`): The SVG group element for UI elements (e.g., selection boxes).
30
- * **focusFrameLayer** (`SVGGElement`): The SVG group element for focus frames.
31
- * **strokes** (`Map<string, Stroke>`): A map of all strokes on the canvas, keyed by their ID.
32
- * **selectedStrokes** (`Set<string>`): A set of IDs of currently selected strokes.
33
- * **toolManager** (`ToolManager`): Manages the active drawing tools.
34
- * **eventManager** (`EventManager`): Manages all user input events.
35
- * **cursor** (`Cursor`): Manages the custom canvas cursor.
36
- * **toolbar** (`Toolbar`): The canvas toolbar (if enabled).
37
- * **focusFrameManager** (`FocusFrameManager`): Manages focus frames (if enabled).
38
-
39
- ## Public Methods
40
-
41
- ### `addStroke(stroke)`
42
-
43
- Adds a stroke to the canvas.
44
-
45
- * **stroke** (`Stroke`): The stroke object to add.
46
- * **Returns**: `string` - The ID of the added stroke.
47
-
48
- ### `removeStroke(strokeId)`
49
-
50
- Removes a stroke from the canvas.
51
-
52
- * **strokeId** (`string`): The ID of the stroke to remove.
53
- * **Returns**: `boolean` - `true` if the stroke was removed, `false` otherwise.
54
-
55
- ### `clear()`
56
-
57
- Clears all strokes from the canvas.
58
-
59
- ### `selectStrokes(strokeIds)`
60
-
61
- Selects a set of strokes by their IDs.
62
-
63
- * **strokeIds** (`Array<string>`): An array of stroke IDs to select.
64
-
65
- ### `clientToSVG(clientX, clientY)`
66
-
67
- Converts client (screen) coordinates to SVG (canvas) coordinates.
68
-
69
- * **clientX** (`number`): The client X coordinate.
70
- * **clientY** (`number`): The client Y coordinate.
71
- * **Returns**: `object` - An object with `x` and `y` properties representing the SVG coordinates.
72
-
73
- ### `exportSVG()`
74
-
75
- Exports the canvas content as an SVG string. UI elements like selection boxes and focus frames are excluded from the export.
76
-
77
- * **Returns**: `string` - The SVG content of the canvas.
78
-
79
- ### `exportImage([format], [quality])`
80
-
81
- Exports the canvas content as an image (PNG, JPEG, or WebP).
82
-
83
- * **[format]** (`string`, optional): The image format (`'png'`, `'jpeg'`, `'webp'`). Defaults to `'png'`.
84
- * **[quality]** (`number`, optional): The image quality (0-1) for JPEG/WebP. Defaults to `1`.
85
- * **Returns**: `Promise<Blob>` - A promise that resolves with the image data as a `Blob`.
86
-
87
- ### `resize(width, height)`
88
-
89
- Resizes the canvas to the specified dimensions.
90
-
91
- * **width** (`number`): The new width of the canvas.
92
- * **height** (`number`): The new height of the canvas.
93
-
94
- ### `toggleGrid()`
95
-
96
- Toggles the visibility of the background grid.
97
-
98
- ### `on(event, callback)`
99
-
100
- Registers an event listener for a custom canvas event.
101
-
102
- * **event** (`string`): The name of the event to listen for.
103
- * **callback** (`Function`): The callback function to execute when the event is emitted.
104
-
105
- ### `off(event, callback)`
106
-
107
- Removes an event listener.
108
-
109
- * **event** (`string`): The name of the event.
110
- * **callback** (`Function`): The callback function to remove.
111
-
112
- ### `emit(event, [data])`
113
-
114
- Emits a custom canvas event.
115
-
116
- * **event** (`string`): The name of the event to emit.
117
- * **[data]** (`object`, optional): Optional data to pass with the event.
118
-
119
- ### `getInfo()`
120
-
121
- Gets information about the current state of the canvas.
122
-
123
- * **Returns**: `object` - An object containing canvas dimensions, stroke counts, active tool, and other status information.
124
-
125
- ### `destroy()`
126
-
127
- Destroys the canvas instance, removes all DOM elements, and cleans up event listeners and managers.
128
-
129
- ## Events
130
-
131
- The `omdCanvas` emits the following custom events:
132
-
133
- * `strokeAdded`: Fired when a new stroke is added to the canvas.
134
- * `strokeRemoved`: Fired when a stroke is removed from the canvas.
135
- * `cleared`: Fired when all strokes are cleared from the canvas.
136
- * `selectionChanged`: Fired when the selection of strokes changes.
137
- * `resized`: Fired when the canvas is resized.
138
- * `pointerDown`, `pointerMove`, `pointerUp`, `pointerCancel`, `pointerEnter`, `pointerLeave`: Pointer events, normalized to canvas coordinates.
139
- * `keyDown`, `keyUp`: Keyboard events.
140
- * `wheel`: Wheel events.
141
- * `focusFrameCreated`, `focusFrameRemoved`, `focusFrameActivated`, `focusFramesCleared`: Events related to focus frame management.
142
- * `destroyed`: Fired when the canvas instance is destroyed.
1
+ # omdCanvas
2
+
3
+ The `omdCanvas` class is the core component for creating and managing an interactive 2D drawing surface. It provides the primary API for all canvas operations, including drawing and managing strokes, handling user input, and orchestrating various features like tools, a toolbar, and focus frames.
4
+
5
+ ## Class Definition
6
+
7
+ ```javascript
8
+ export class omdCanvas
9
+ ```
10
+
11
+ ## Constructor
12
+
13
+ ### `new omdCanvas(container, [options])`
14
+
15
+ Creates a new `omdCanvas` instance within a specified container element.
16
+
17
+ - **`container`** (`HTMLElement` | `string`): The HTML element or a CSS selector string for the container where the canvas will be rendered. Throws an error if the container is not found.
18
+ - **`options`** (`object`, optional): Configuration options for the canvas. These are passed to the `CanvasConfig` class. See the [Configuration Options](./configuration-options.md) for details.
19
+
20
+ ## Properties
21
+
22
+ - **`container`** (`HTMLElement`): The HTML container element for the canvas.
23
+ - **`config`** (`CanvasConfig`): The configuration object for the canvas.
24
+ - **`svg`** (`SVGElement`): The main `<svg>` element that serves as the drawing surface.
25
+ - **`backgroundLayer`** (`SVGGElement`): An SVG group (`<g>`) for background elements like the grid.
26
+ - **`drawingLayer`** (`SVGGElement`): The SVG group where all drawing strokes are rendered.
27
+ - **`uiLayer`** (`SVGGElement`): The SVG group for UI elements that overlay the drawing, such as selection boxes.
28
+ - **`focusFrameLayer`** (`SVGGElement`): The SVG group dedicated to holding `FocusFrame` elements.
29
+ - **`strokes`** (`Map<string, Stroke>`): A map of all stroke objects on the canvas, with their unique IDs as keys.
30
+ - **`selectedStrokes`** (`Set<string>`): A set of the IDs of all currently selected strokes.
31
+ - **`toolManager`** (`ToolManager`): The instance managing the active drawing tools (Pencil, Eraser, etc.).
32
+ - **`eventManager`** (`EventManager`): The instance managing all user input events.
33
+ - **`cursor`** (`Cursor`): The instance that manages the custom cursor's appearance and behavior.
34
+ - **`toolbar`** (`Toolbar`): The UI toolbar for tool selection (if enabled in config).
35
+ - **`focusFrameManager`** (`FocusFrameManager`): The instance managing focus frames (if enabled in config).
36
+
37
+ ## Public Methods
38
+
39
+ ### Stroke Management
40
+
41
+ - **`addStroke(stroke)`**: Adds a `Stroke` object to the canvas and renders it. Emits `strokeAdded`.
42
+ - **`removeStroke(strokeId)`**: Removes a stroke from the canvas by its ID. Emits `strokeRemoved`.
43
+ - **`clear()`**: Removes all strokes from the canvas. Emits `cleared`.
44
+
45
+ ### Selection
46
+
47
+ - **`selectStrokes(strokeIds)`**: Programmatically selects a set of strokes by their IDs. Emits `selectionChanged`.
48
+
49
+ ### Coordinate Conversion
50
+
51
+ - **`clientToSVG(clientX, clientY)`**: Converts screen coordinates (e.g., from a mouse event) to the canvas's local SVG coordinate system.
52
+ - **Returns**: `{ x, y }` object.
53
+
54
+ ### Exporting
55
+
56
+ - **`exportSVG()`**: Exports the canvas drawing as a clean SVG string. UI layers (`uiLayer`, `focusFrameLayer`) are excluded.
57
+ - **`async exportImage([format], [quality])`**: Exports the canvas as a bitmap image.
58
+ - **`format`** (`string`): `'png'`, `'jpeg'`, or `'webp'`. Default: `'png'`.
59
+ - **`quality`** (`number`): For JPEG/WebP, a value from 0 to 1. Default: `1`.
60
+ - **Returns**: `Promise<Blob>` that resolves with the image data.
61
+
62
+ ### Canvas Management
63
+
64
+ - **`resize(width, height)`**: Resizes the canvas. Emits `resized`.
65
+ - **`toggleGrid()`**: Toggles the visibility of the background grid.
66
+ - **`getInfo()`**: Returns an object with status information (dimensions, stroke count, active tool, etc.).
67
+ - **`destroy()`**: Completely removes the canvas and all associated managers, event listeners, and DOM elements. Emits `destroyed`.
68
+
69
+ ### Event Handling (Pub/Sub)
70
+
71
+ - **`on(event, callback)`**: Registers a listener for a custom canvas event.
72
+ - **`off(event, callback)`**: Removes a previously registered event listener.
73
+ - **`emit(event, [data])`**: Dispatches a custom event to all registered listeners.
74
+
75
+ ## Emitted Events
76
+
77
+ The `omdCanvas` is an event emitter. You can listen for these events using the `on()` method.
78
+
79
+ - `strokeAdded`, `strokeRemoved`, `cleared`: Fired for stroke operations.
80
+ - `selectionChanged`: Fired when the set of selected strokes changes.
81
+ - `resized`: Fired when the canvas dimensions change.
82
+ - `pointerDown`, `pointerMove`, `pointerUp`, etc.: Raw input events, normalized by the `EventManager`.
83
+ - `focusFrameCreated`, `focusFrameRemoved`, etc.: Events from the `FocusFrameManager`.
84
+ - `destroyed`: Fired when the `destroy()` method has completed.