@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,87 +1,141 @@
1
-
2
- # omdEquationStack
3
-
4
- A renderable component that bundles a sequence of mathematical equations with optional UI controls (toolbar). It extends `jsvgGroup` and acts as a node that can be rendered by an `omdDisplay`.
5
-
6
- ## Class: `omdEquationStack extends jsvgGroup`
7
-
8
- ```js
9
- import { omdEquationStack } from './omd/core/omdEquationStack.js';
10
- ```
11
-
12
- ## Constructor
13
-
14
- ```js
15
- new omdEquationStack(steps = [], options = {})
16
- ```
17
- - `steps` (`Array<omdNode>`): Initial array of equation steps (default: empty array)
18
- - `options` (`Object`): Configuration options:
19
- - `toolbar` (`boolean`): If `true`, creates a toolbar for equation operations (default: `false`)
20
- - `stepVisualizer` (`boolean`): If `true`, creates a sequence with step visualization (default: `false`)
21
-
22
-
23
- ## Properties
24
-
25
- - `sequence` (`omdEquationSequenceNode` | `omdStepVisualizer`): The underlying sequence component
26
- - `toolbar` (`omdToolbar` | `undefined`): The toolbar component (if enabled)
27
- - `layoutGroup` (`jsvgLayoutGroup`): Layout container for sequence and toolbar
28
- - `options` (`Object`): Configuration options passed to constructor
29
-
30
- ## Methods
31
-
32
- ### `updateLayout()`
33
- Updates the layout and positioning of internal components. Centers the toolbar under the equation stack if their widths differ.
34
-
35
- ### `getSequence()`
36
- Returns the underlying sequence instance.
37
- - **Returns:** `omdEquationSequenceNode` | `omdStepVisualizer`
38
-
39
- ### `getToolbar()`
40
- Returns the toolbar instance, if one was created.
41
- - **Returns:** `omdToolbar` | `undefined`
42
-
43
-
44
- ## Usage
45
-
46
- The `omdEquationStack` component is a complete equation solving interface that combines an equation sequence with an optional toolbar. It automatically handles layout and positioning.
47
-
48
- ```javascript
49
- import { omdDisplay } from 'omd';
50
- import { omdEquationStack } from 'omd';
51
- import { omdEquationNode } from 'omd';
52
-
53
- // Create display
54
- const container = document.getElementById('math-display');
55
- const display = new omdDisplay(container);
56
-
57
- // Create equation steps
58
- const steps = [
59
- omdEquationNode.fromString('2x + 3 = 11'),
60
- omdEquationNode.fromString('2x = 8'),
61
- omdEquationNode.fromString('x = 4')
62
- ];
63
-
64
- // Basic equation stack with toolbar
65
- const stack = new omdEquationStack(steps, {
66
- toolbar: true
67
- });
68
-
69
- // Render the stack
70
- display.render(stack);
71
-
72
- // Alternative: Create with step visualizer
73
- const stackWithVisualizer = new omdEquationStack(steps, {
74
- toolbar: true,
75
- stepVisualizer: true
76
- });
77
-
78
- display.render(stackWithVisualizer);
79
- ```
80
-
81
- ## Integration
82
-
83
- The equation stack integrates seamlessly with the step visualizer:
84
-
1
+ # omdEquationStack
2
+
3
+ A renderable component that bundles a sequence of mathematical equations with optional UI controls (toolbar). It extends `jsvgGroup` and acts as a node that can be rendered by an `omdDisplay`.
4
+
5
+ ## Class Definition
6
+
7
+ ```js
8
+ import { omdEquationStack } from './omd/core/omdEquationStack.js';
9
+ ```
10
+
11
+ ## Constructor
12
+
13
+ ### `new omdEquationStack(steps, options)`
14
+
15
+ Creates a new `omdEquationStack` instance.
16
+
17
+ - **`steps`** (`Array<omdNode>`, optional): An initial array of equation steps. Default: empty array.
18
+ - **`options`** (`object`, optional): Configuration options:
19
+ - **`toolbar`** (`boolean` | `object`): If `true`, creates a toolbar for equation operations. Can also be an object for more granular control:
20
+ - `enabled` (`boolean`): Whether the toolbar is enabled. Default: `false`.
21
+ - `position` (`string`): Where the toolbar should be positioned (`'bottom'`, `'overlay-bottom'`). Default: `'bottom'`.
22
+ - `showUndoButton` (`boolean`): Whether to show an undo button. Default: `false`.
23
+ - `onUndo` (`function`): Custom undo handler. If not provided, it attempts to call `window.onOMDToolbarUndo`.
24
+ - `overlayPadding` (`number`): Padding from the bottom edge when `position` is `'overlay-bottom'`. Default: `34`.
25
+ - **`stepVisualizer`** (`boolean`): If `true`, the underlying sequence will be an `omdStepVisualizer` instead of a plain `omdEquationSequenceNode`. Default: `false`.
26
+ - **`styling`** (`object`): Styling options for the equation stack:
27
+ - `equationBackground` (`object`): Default background style for equation steps (e.g., `{ backgroundColor: '#f0f0f0', cornerRadius: 8, pill: true }`).
28
+
29
+ ## Public Properties
30
+
31
+ - **`sequence`** (`omdEquationSequenceNode` | `omdStepVisualizer`): The underlying sequence component that manages the equation steps.
32
+ - **`toolbar`** (`omdToolbar` | `undefined`): The toolbar component instance, if enabled.
33
+ - **`layoutGroup`** (`jsvgLayoutGroup`): The internal layout container that arranges the sequence and toolbar vertically.
34
+ - **`options`** (`object`): The merged configuration options passed to the constructor.
35
+ - **`overlayPadding`** (`number`): The calculated padding for the toolbar when it's in an overlay position.
36
+
37
+ ## Public Methods
38
+
39
+ ### `updateLayout()`
40
+
41
+ Updates the layout and positioning of internal components. This method ensures the sequence and toolbar are correctly arranged and that the toolbar is horizontally centered if it's in-flow.
42
+
43
+ ### `getSequence()`
44
+
45
+ Returns the underlying sequence instance (either `omdEquationSequenceNode` or `omdStepVisualizer`).
46
+
47
+ - **Returns**: `omdEquationSequenceNode` | `omdStepVisualizer`.
48
+
49
+ ### `getToolbar()`
50
+
51
+ Returns the toolbar instance, if one was created during construction.
52
+
53
+ - **Returns**: `omdToolbar` | `undefined`.
54
+
55
+ ### `getOverlayPadding()`
56
+
57
+ Returns the padding value used for positioning the toolbar when it's in an overlay mode.
58
+
59
+ - **Returns**: `number`.
60
+
61
+ ### `getToolbarVisualHeight()`
62
+
63
+ Returns the unscaled visual height of the toolbar's background element, if the toolbar is present.
64
+
65
+ - **Returns**: `number`.
66
+
67
+ ### `isToolbarOverlay()`
68
+
69
+ Checks if the toolbar is configured to be overlaid at the bottom of the container.
70
+
71
+ - **Returns**: `boolean`.
72
+
73
+ ### `positionToolbarOverlay(containerWidth, containerHeight, padding)`
74
+
75
+ Positions the toolbar overlay at the bottom center of the container. This method is typically called by the `omdDisplay` to ensure the toolbar remains visible and correctly placed even when the main content scales.
76
+
77
+ - **`containerWidth`** (`number`): The width of the parent container.
78
+ - **`containerHeight`** (`number`): The height of the parent container.
79
+ - **`padding`** (`number`, optional): Padding from the bottom edge. Default: `16`.
80
+
81
+ ### `undoLastOperation()`
82
+
83
+ Removes the last equation step and any preceding operation display node from the sequence. This method also triggers a re-layout and updates any associated step visualizer.
84
+
85
+ - **Returns**: `boolean` - `true` if an operation was successfully undone, `false` otherwise.
86
+
87
+ ## Usage
88
+
89
+ The `omdEquationStack` component is a complete equation solving interface that combines an equation sequence with an optional toolbar. It automatically handles layout and positioning.
90
+
91
+ ```javascript
92
+ import { omdDisplay } from 'omd';
93
+ import { omdEquationStack } from 'omd';
94
+ import { omdEquationNode } from 'omd';
95
+
96
+ // Create display
97
+ const container = document.getElementById('math-display');
98
+ const display = new omdDisplay(container);
99
+
100
+ // Create equation steps
101
+ const steps = [
102
+ omdEquationNode.fromString('2x + 3 = 11'),
103
+ omdEquationNode.fromString('2x = 8'),
104
+ omdEquationNode.fromString('x = 4')
105
+ ];
106
+
107
+ // Basic equation stack with toolbar
108
+ const stack = new omdEquationStack(steps, {
109
+ toolbar: true
110
+ });
111
+
112
+ // Render the stack
113
+ display.render(stack);
114
+
115
+ // Alternative: Create with step visualizer and custom toolbar options
116
+ const stackWithVisualizer = new omdEquationStack(steps, {
117
+ toolbar: {
118
+ enabled: true,
119
+ showUndoButton: true,
120
+ position: 'overlay-bottom'
121
+ },
122
+ stepVisualizer: true,
123
+ styling: {
124
+ equationBackground: {
125
+ backgroundColor: '#e0f7fa',
126
+ cornerRadius: 10,
127
+ pill: true
128
+ }
129
+ }
130
+ });
131
+
132
+ display.render(stackWithVisualizer);
133
+ ```
134
+
135
+ ## Integration
136
+
137
+ The equation stack integrates seamlessly with the step visualizer:
138
+
85
139
  ```javascript
86
140
  import { omdEquationStack } from 'omd';
87
141
  import { omdEquationNode } from 'omd';
@@ -108,15 +162,15 @@ display.render(stack);
108
162
  // Access the visualizer for programmatic control
109
163
  const visualizer = stack.getSequence();
110
164
  // visualizer.nextStep(); // Progress through solution steps if interactive
111
- ```
112
-
113
- ## Layout Behavior
114
-
115
- The equation stack automatically manages its internal layout:
116
- - The sequence is positioned at the top
117
- - The toolbar (if present) is centered below the sequence
118
- - Layout updates automatically when content changes
119
-
165
+ ```
166
+
167
+ ## Layout Behavior
168
+
169
+ The equation stack automatically manages its internal layout:
170
+ - The sequence is positioned at the top
171
+ - The toolbar (if present) is centered below the sequence
172
+ - Layout updates automatically when content changes
173
+
120
174
  ```javascript
121
175
  // Create a stack and let it handle layout automatically
122
176
  const stack = new omdEquationStack(steps, { toolbar: true });
@@ -127,13 +181,13 @@ stack.updateLayout();
127
181
  // Access components
128
182
  const sequence = stack.getSequence();
129
183
  const toolbar = stack.getToolbar();
130
- ```
131
-
132
- ---
133
-
134
- ### See Also
135
-
136
- - [`omdEquationSequenceNode`](./omdEquationSequenceNode.md)
137
- - [`omdStepVisualizer`](./omdStepVisualizer.md)
138
- - [`omdToolbar`](./omdToolbar.md)
139
- - [`jsvgGroup`](../../jsvg/jsvg.js)
184
+ ```
185
+
186
+ ---
187
+
188
+ ### See Also
189
+
190
+ - [`omdEquationSequenceNode`](./omdEquationSequenceNode.md)
191
+ - [`omdStepVisualizer`](./omdStepVisualizer.md)
192
+ - [`omdToolbar`](./omdToolbar.md)
193
+ - [`jsvgGroup`](../../jsvg/jsvg.js)
@@ -1,141 +1,83 @@
1
-
2
- # omdFunctionNode
3
-
4
- Represents a mathematical function call, such as `sin(x)`, `sqrt(9)`, or `log(x, 10)`. Handles rendering of the function name, its arguments, and parentheses, and supports evaluation and conversion to math.js AST.
5
-
6
- ## Class: `omdFunctionNode extends omdNode`
7
-
8
- ```javascript
9
- import { omdFunctionNode } from './omd/nodes/omdFunctionNode.js';
10
- ```
11
-
12
- ### Constructor
13
-
14
- ```javascript
15
- new omdFunctionNode(astNodeData)
16
- ```
17
-
18
- **Parameters:**
19
- - `astNodeData` {Object} - The math.js AST node for the function, which should contain:
20
- - `fn.name` or `name`: The name of the function (e.g., "sin").
21
- - `args`: An array of AST nodes for the function's arguments.
22
-
23
-
24
- ### Static Methods
25
-
26
- #### `fromString(functionString)`
27
-
28
- Creates an `omdFunctionNode` from a string representation. Requires `window.math` (math.js) to be available.
29
-
30
- ```javascript
31
- const sqrtNode = omdFunctionNode.fromString('sqrt(16)');
32
- ```
33
-
34
- - **Parameters:**
35
- - `functionString` {string} - The function call as a string.
36
- - **Returns:** {omdFunctionNode} A new instance of `omdFunctionNode`.
37
- - **Throws:** `Error` if `math.js` is not available or the string is not a valid function.
38
-
39
-
40
- ### Example
41
-
42
- ```javascript
43
- // Create a function node from a string
44
- const funcNode = omdFunctionNode.fromString('log(100, 10)');
45
-
46
- // Set its font size and render it
47
- funcNode.setFontSize(32);
48
- funcNode.initialize(); // Computes dimensions and layout
49
-
50
- // Evaluate the function
51
- const result = funcNode.evaluate();
52
- console.log(result); // Output: 2
53
-
54
- // Add it to an SVG container to display
55
- const svgContainer = new jsvgContainer();
56
- svgContainer.addChild(funcNode);
57
- document.body.appendChild(svgContainer.svgObject);
58
- ```
59
-
60
- ### See Also
61
-
62
- - [`omdNode`](./omdNode.md) - The base class for all nodes.
63
- - [`omdConstantNode`](./omdConstantNode.md) - For numeric arguments.
64
- - [`omdVariableNode`](./omdVariableNode.md) - For variable arguments.
65
- - [`jsvgTextLine`](../../jsvg/jsvgComponents.js) - For SVG text rendering.
66
- Evaluates the function by first evaluating its arguments and then applying the function to the results. Uses `math.js` if available, otherwise falls back to standard JavaScript `Math` functions for common cases.
67
-
68
- - **Parameters:**
69
- - `variables` {Object} - A map of variable names to their numeric values (e.g., `{ x: 2 }`).
70
- - **Returns:** `number` - The result of the function evaluation.
71
- - **Throws:** `Error` if the function is unknown or cannot be evaluated.
72
-
73
- ---
74
-
75
- #### `simplify()`
76
-
77
- Delegates to the central simplification engine to simplify the function and its arguments.
78
-
79
- - **Returns:** `Object` - An object indicating the result: `{ success, newRoot, message }`.
80
-
81
- ---
82
-
83
- #### `clone()`
84
-
85
- Creates a deep, structural clone of the function node, including all its argument nodes and SVG elements. The clone's provenance array is updated to include the original node's ID.
86
-
87
- - **Returns:** {omdFunctionNode} A new, identical instance of the function node.
88
-
89
- ---
90
-
91
- #### `toMathJSNode()`
92
-
93
- Converts the node back into its math.js AST representation, including a `clone` method for compatibility.
94
-
95
- - **Returns:** `Object` - A math.js-compatible AST node.
96
-
97
- ---
98
-
99
- #### `toString()`
100
-
101
- Converts the function node to its string representation.
102
-
103
- - **Returns:** `string` - The function as a string, e.g., `"sqrt(x^2)"`.
104
-
105
- ---
106
-
107
- #### `highlightAll()` / `unhighlightAll()`
108
-
109
- Highlights or unhighlights the function node and all its arguments.
110
-
111
- ---
112
-
113
- #### `computeDimensions()` / `updateLayout()`
114
-
115
- Calculates and updates the layout and dimensions of the function node and its children.
116
-
117
- ### Example
118
-
119
- ```javascript
120
- // Create a function node from a string
121
- const funcNode = omdFunctionNode.fromString('log(100, 10)');
122
-
123
- // Set its font size and render it
124
- funcNode.setFontSize(32);
125
- funcNode.initialize(); // Computes dimensions and layout
126
-
127
- // Evaluate the function
128
- const result = funcNode.evaluate();
129
- console.log(result); // Output: 2
130
-
131
- // Add it to an SVG container to display
132
- const svgContainer = new jsvgContainer();
133
- svgContainer.addChild(funcNode);
134
- document.body.appendChild(svgContainer.svgObject);
135
- ```
136
-
137
- ### See Also
138
-
139
- - [`omdNode`](./omdNode.md) - The base class for all nodes.
140
- - [`omdConstantNode`](./omdConstantNode.md) - For numeric arguments.
141
- - [`omdVariableNode`](./omdVariableNode.md) - For variable arguments.
1
+ # omdFunctionNode
2
+
3
+ Represents a mathematical function call, such as `sin(x)`, `sqrt(9)`, or `log(x, 10)`. This node handles the rendering of the function name, its arguments, and surrounding parentheses. It supports evaluation, simplification, and conversion to/from math.js AST.
4
+
5
+ ## Class Definition
6
+
7
+ ```javascript
8
+ export class omdFunctionNode extends omdNode
9
+ ```
10
+
11
+ ## Constructor
12
+
13
+ ### `new omdFunctionNode(astNodeData)`
14
+
15
+ Creates a new `omdFunctionNode` instance.
16
+
17
+ - **`astNodeData`** (`object`): The math.js AST node for the function. It should contain:
18
+ - `fn.name` or `name`: The name of the function (e.g., `"sin"`, `"log"`).
19
+ - `args`: An array of AST nodes for the function's arguments.
20
+
21
+ ## Static Methods
22
+
23
+ ### `fromString(functionString)`
24
+
25
+ Creates an `omdFunctionNode` from a string representation of a function call. This method requires `window.math` (math.js library) to be available globally for parsing.
26
+
27
+ - **`functionString`** (`string`): The function call as a string (e.g., `"sqrt(16)"`, `"log(100, 10)"`).
28
+ - **Returns**: `omdFunctionNode` - A new instance of `omdFunctionNode`.
29
+ - **Throws**: `Error` if `math.js` is not available, if the string cannot be parsed, or if it does not represent a valid function call.
30
+
31
+ ## Public Properties
32
+
33
+ - **`functionName`** (`string`): The name of the function (e.g., `"sin"`, `"log"`).
34
+ - **`args`** (`Array<omdNode>`): An array of `omdNode` instances representing the arguments of the function.
35
+
36
+ ## Public Methods
37
+
38
+ ### `computeDimensions()`
39
+
40
+ Calculates the bounding box of the function node, taking into account the dimensions of the function name, arguments, and parentheses. It also sets the font sizes for the function name and arguments (arguments are typically scaled down slightly).
41
+
42
+ ### `updateLayout()`
43
+
44
+ Positions the function name, arguments, and parentheses within the node's bounding box. It ensures proper spacing and vertical alignment of all elements.
45
+
46
+ ### `highlightAll()`
47
+
48
+ Applies a highlight to the function node itself (its background rectangle) and recursively highlights all of its argument nodes.
49
+
50
+ ### `unhighlightAll()`
51
+
52
+ Removes the highlight from the function node and recursively unhighlights all of its argument nodes.
53
+
54
+ ### `clone()`
55
+
56
+ Creates a deep, structural clone of the function node, including all its argument nodes and their associated SVG elements. The clone's provenance array is updated to include the original node's ID.
57
+
58
+ - **Returns**: `omdFunctionNode` - A new, identical instance of the function node.
59
+
60
+ ### `toMathJSNode()`
61
+
62
+ Converts the `omdFunctionNode` back into its math.js AST representation. This includes converting its function name and all argument nodes.
63
+
64
+ - **Returns**: `object` - A math.js-compatible `FunctionNode` AST object.
65
+
66
+ ### `toString()`
67
+
68
+ Converts the function node to its string representation (e.g., `"sqrt(x^2)"`, `"log(100, 10)"`).
69
+
70
+ - **Returns**: `string` - The function as a string.
71
+
72
+ ### `evaluate(variables)`
73
+
74
+ Evaluates the function by first evaluating its arguments and then applying the function to the results. It primarily uses `window.math` (math.js) for evaluation. If `math.js` is not available, it falls back to standard JavaScript `Math` functions for common cases (e.g., `sin`, `cos`, `sqrt`).
75
+
76
+ - **`variables`** (`object`, optional): A map of variable names to their numeric values (e.g., `{ x: 2 }`).
77
+ - **Returns**: `number` - The result of the function evaluation.
78
+ - **Throws**: `Error` if the function is unknown or cannot be evaluated.
79
+
80
+ ## Internal Methods
81
+
82
+ - **`createTextElements()`**: Creates `jsvgTextLine` elements for the function name and parentheses.
83
+ - **`createArgumentNodes()`**: Iterates through the AST arguments, creates corresponding `omdNode` instances for each, and adds them as children.