@teachinglab/omd 0.1.0

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 (144) hide show
  1. package/README.md +138 -0
  2. package/canvas/core/canvasConfig.js +203 -0
  3. package/canvas/core/omdCanvas.js +475 -0
  4. package/canvas/drawing/segment.js +168 -0
  5. package/canvas/drawing/stroke.js +386 -0
  6. package/canvas/events/eventManager.js +435 -0
  7. package/canvas/events/pointerEventHandler.js +263 -0
  8. package/canvas/features/focusFrameManager.js +287 -0
  9. package/canvas/index.js +49 -0
  10. package/canvas/tools/eraserTool.js +322 -0
  11. package/canvas/tools/pencilTool.js +319 -0
  12. package/canvas/tools/selectTool.js +457 -0
  13. package/canvas/tools/tool.js +223 -0
  14. package/canvas/tools/toolManager.js +394 -0
  15. package/canvas/ui/cursor.js +438 -0
  16. package/canvas/ui/toolbar.js +304 -0
  17. package/canvas/utils/boundingBox.js +378 -0
  18. package/canvas/utils/mathUtils.js +259 -0
  19. package/docs/api/configuration-options.md +104 -0
  20. package/docs/api/eventManager.md +68 -0
  21. package/docs/api/focusFrameManager.md +150 -0
  22. package/docs/api/index.md +91 -0
  23. package/docs/api/main.md +58 -0
  24. package/docs/api/omdBinaryExpressionNode.md +227 -0
  25. package/docs/api/omdCanvas.md +142 -0
  26. package/docs/api/omdConfigManager.md +192 -0
  27. package/docs/api/omdConstantNode.md +117 -0
  28. package/docs/api/omdDisplay.md +121 -0
  29. package/docs/api/omdEquationNode.md +161 -0
  30. package/docs/api/omdEquationSequenceNode.md +301 -0
  31. package/docs/api/omdEquationStack.md +139 -0
  32. package/docs/api/omdFunctionNode.md +141 -0
  33. package/docs/api/omdGroupNode.md +182 -0
  34. package/docs/api/omdHelpers.md +96 -0
  35. package/docs/api/omdLeafNode.md +163 -0
  36. package/docs/api/omdNode.md +101 -0
  37. package/docs/api/omdOperationDisplayNode.md +139 -0
  38. package/docs/api/omdOperatorNode.md +127 -0
  39. package/docs/api/omdParenthesisNode.md +122 -0
  40. package/docs/api/omdPopup.md +117 -0
  41. package/docs/api/omdPowerNode.md +127 -0
  42. package/docs/api/omdRationalNode.md +128 -0
  43. package/docs/api/omdSequenceNode.md +128 -0
  44. package/docs/api/omdSimplification.md +110 -0
  45. package/docs/api/omdSqrtNode.md +79 -0
  46. package/docs/api/omdStepVisualizer.md +115 -0
  47. package/docs/api/omdStepVisualizerHighlighting.md +61 -0
  48. package/docs/api/omdStepVisualizerInteractiveSteps.md +129 -0
  49. package/docs/api/omdStepVisualizerLayout.md +60 -0
  50. package/docs/api/omdStepVisualizerNodeUtils.md +140 -0
  51. package/docs/api/omdStepVisualizerTextBoxes.md +68 -0
  52. package/docs/api/omdToolbar.md +102 -0
  53. package/docs/api/omdTranscriptionService.md +76 -0
  54. package/docs/api/omdTreeDiff.md +134 -0
  55. package/docs/api/omdUnaryExpressionNode.md +174 -0
  56. package/docs/api/omdUtilities.md +70 -0
  57. package/docs/api/omdVariableNode.md +148 -0
  58. package/docs/api/selectTool.md +74 -0
  59. package/docs/api/simplificationEngine.md +98 -0
  60. package/docs/api/simplificationRules.md +77 -0
  61. package/docs/api/simplificationUtils.md +64 -0
  62. package/docs/api/transcribe.md +43 -0
  63. package/docs/api-reference.md +85 -0
  64. package/docs/index.html +454 -0
  65. package/docs/user-guide.md +9 -0
  66. package/index.js +67 -0
  67. package/omd/config/omdConfigManager.js +267 -0
  68. package/omd/core/index.js +150 -0
  69. package/omd/core/omdEquationStack.js +347 -0
  70. package/omd/core/omdUtilities.js +115 -0
  71. package/omd/display/omdDisplay.js +443 -0
  72. package/omd/display/omdToolbar.js +502 -0
  73. package/omd/nodes/omdBinaryExpressionNode.js +460 -0
  74. package/omd/nodes/omdConstantNode.js +142 -0
  75. package/omd/nodes/omdEquationNode.js +1223 -0
  76. package/omd/nodes/omdEquationSequenceNode.js +1273 -0
  77. package/omd/nodes/omdFunctionNode.js +352 -0
  78. package/omd/nodes/omdGroupNode.js +68 -0
  79. package/omd/nodes/omdLeafNode.js +77 -0
  80. package/omd/nodes/omdNode.js +557 -0
  81. package/omd/nodes/omdOperationDisplayNode.js +322 -0
  82. package/omd/nodes/omdOperatorNode.js +109 -0
  83. package/omd/nodes/omdParenthesisNode.js +293 -0
  84. package/omd/nodes/omdPowerNode.js +236 -0
  85. package/omd/nodes/omdRationalNode.js +295 -0
  86. package/omd/nodes/omdSqrtNode.js +308 -0
  87. package/omd/nodes/omdUnaryExpressionNode.js +178 -0
  88. package/omd/nodes/omdVariableNode.js +123 -0
  89. package/omd/simplification/omdSimplification.js +171 -0
  90. package/omd/simplification/omdSimplificationEngine.js +886 -0
  91. package/omd/simplification/package.json +6 -0
  92. package/omd/simplification/rules/binaryRules.js +1037 -0
  93. package/omd/simplification/rules/functionRules.js +111 -0
  94. package/omd/simplification/rules/index.js +48 -0
  95. package/omd/simplification/rules/parenthesisRules.js +19 -0
  96. package/omd/simplification/rules/powerRules.js +143 -0
  97. package/omd/simplification/rules/rationalRules.js +475 -0
  98. package/omd/simplification/rules/sqrtRules.js +48 -0
  99. package/omd/simplification/rules/unaryRules.js +37 -0
  100. package/omd/simplification/simplificationRules.js +32 -0
  101. package/omd/simplification/simplificationUtils.js +1056 -0
  102. package/omd/step-visualizer/omdStepVisualizer.js +597 -0
  103. package/omd/step-visualizer/omdStepVisualizerHighlighting.js +206 -0
  104. package/omd/step-visualizer/omdStepVisualizerLayout.js +245 -0
  105. package/omd/step-visualizer/omdStepVisualizerTextBoxes.js +163 -0
  106. package/omd/utils/omdNodeOverlay.js +638 -0
  107. package/omd/utils/omdPopup.js +1084 -0
  108. package/omd/utils/omdStepVisualizerInteractiveSteps.js +491 -0
  109. package/omd/utils/omdStepVisualizerNodeUtils.js +268 -0
  110. package/omd/utils/omdTranscriptionService.js +125 -0
  111. package/omd/utils/omdTreeDiff.js +734 -0
  112. package/package.json +46 -0
  113. package/src/index.js +62 -0
  114. package/src/json-schemas.md +109 -0
  115. package/src/omd-json-samples.js +115 -0
  116. package/src/omd.js +109 -0
  117. package/src/omdApp.js +391 -0
  118. package/src/omdAppCanvas.js +336 -0
  119. package/src/omdBalanceHanger.js +172 -0
  120. package/src/omdColor.js +13 -0
  121. package/src/omdCoordinatePlane.js +467 -0
  122. package/src/omdEquation.js +125 -0
  123. package/src/omdExpression.js +104 -0
  124. package/src/omdFunction.js +113 -0
  125. package/src/omdMetaExpression.js +287 -0
  126. package/src/omdNaturalExpression.js +564 -0
  127. package/src/omdNode.js +384 -0
  128. package/src/omdNumber.js +53 -0
  129. package/src/omdNumberLine.js +107 -0
  130. package/src/omdNumberTile.js +119 -0
  131. package/src/omdOperator.js +73 -0
  132. package/src/omdPowerExpression.js +92 -0
  133. package/src/omdProblem.js +55 -0
  134. package/src/omdRatioChart.js +232 -0
  135. package/src/omdRationalExpression.js +115 -0
  136. package/src/omdSampleData.js +215 -0
  137. package/src/omdShapes.js +476 -0
  138. package/src/omdSpinner.js +148 -0
  139. package/src/omdString.js +39 -0
  140. package/src/omdTable.js +369 -0
  141. package/src/omdTapeDiagram.js +245 -0
  142. package/src/omdTerm.js +92 -0
  143. package/src/omdTileEquation.js +349 -0
  144. package/src/omdVariable.js +51 -0
@@ -0,0 +1,139 @@
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
+
85
+ ```javascript
86
+ import { omdEquationStack } from 'omd';
87
+ import { omdEquationNode } from 'omd';
88
+ import { omdDisplay } from 'omd';
89
+
90
+ // Create steps for a more complex equation
91
+ const steps = [
92
+ omdEquationNode.fromString('x/2 + 3 = 7'),
93
+ omdEquationNode.fromString('x/2 = 4'),
94
+ omdEquationNode.fromString('x = 8')
95
+ ];
96
+
97
+ // Enable step visualizer with highlighting
98
+ const stack = new omdEquationStack(steps, {
99
+ toolbar: true,
100
+ stepVisualizer: true
101
+ });
102
+
103
+ // Render in display
104
+ const container = document.getElementById('equation-display');
105
+ const display = new omdDisplay(container);
106
+ display.render(stack);
107
+
108
+ // Access the visualizer for programmatic control
109
+ const visualizer = stack.getSequence();
110
+ // 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
+
120
+ ```javascript
121
+ // Create a stack and let it handle layout automatically
122
+ const stack = new omdEquationStack(steps, { toolbar: true });
123
+
124
+ // Manual layout update (rarely needed)
125
+ stack.updateLayout();
126
+
127
+ // Access components
128
+ const sequence = stack.getSequence();
129
+ 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)
@@ -0,0 +1,141 @@
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.
@@ -0,0 +1,182 @@
1
+
2
+ Represents a single grouping symbol, such as `(` or `)`, as a leaf node in the expression tree. This node is typically used for visual representation.
3
+
4
+ ## Class: `omdGroupNode extends omdLeafNode`
5
+
6
+ ```javascript
7
+ import { omdGroupNode } from './omd/nodes/omdGroupNode.js';
8
+ ```
9
+
10
+ ### Constructor
11
+
12
+ ```javascript
13
+ new omdGroupNode(nodeData)
14
+ ```
15
+
16
+ **Parameters:**
17
+
18
+ **Description:**
19
+ Creates a leaf node that visually represents a grouping symbol.
20
+
21
+ ### Properties
22
+
23
+ Inherits all properties from [`omdLeafNode`](./omdLeafNode.md), plus:
24
+
25
+ #### `symbol`
26
+
27
+ #### `type`
28
+
29
+ #### `textElement`
30
+
31
+ ### Methods
32
+
33
+ Inherits all methods from [`omdLeafNode`](./omdLeafNode.md), plus:
34
+
35
+ #### `parseSymbol(nodeData)`
36
+ Internal method to extract symbol from input.
37
+
38
+
39
+ #### `parseType()`
40
+ Internal method to set node type.
41
+
42
+
43
+ #### `clone()`
44
+ Creates a clone of the group node.
45
+ - Same text content
46
+ - Original node's ID added to provenance array
47
+
48
+
49
+ #### `computeDimensions()`
50
+ Calculates node dimensions based on text content.
51
+ Does NOT add padding, unlike other leaf nodes.
52
+ Overrides base class method.
53
+
54
+
55
+ #### `updateLayout()`
56
+ Updates the position of the node.
57
+ Overrides base class method.
58
+
59
+
60
+ #### `toMathJSNode()`
61
+ Converts to math.js AST format.
62
+ - `type`: "SymbolNode"
63
+ - `name`: The grouping symbol
64
+
65
+ ### Examples
66
+
67
+ ```javascript
68
+ // Create grouping symbols
69
+ const leftParen = new omdGroupNode('(');
70
+ const rightParen = new omdGroupNode(')');
71
+ const leftBracket = new omdGroupNode('[');
72
+
73
+ // Render a symbol
74
+ const node = new omdGroupNode('(');
75
+ node.setFontSize(24);
76
+ node.computeDimensions(); // Calculate size (no padding)
77
+ node.updateLayout(); // Position the text element
78
+ ```
79
+
80
+ ### See Also
81
+
82
+ # omdGroupNode
83
+
84
+ Represents a single grouping symbol, such as `(` or `)`, as a leaf node in the expression tree. This node is typically used for visual representation.
85
+
86
+ ## Class: `omdGroupNode extends omdLeafNode`
87
+
88
+ ```javascript
89
+ import { omdGroupNode } from './omd/nodes/omdGroupNode.js';
90
+ ```
91
+
92
+ ### Constructor
93
+
94
+ ```javascript
95
+ new omdGroupNode(nodeData)
96
+ ```
97
+
98
+ **Parameters:**
99
+ - `nodeData` {string} - The grouping symbol character to display
100
+
101
+ **Description:**
102
+ Creates a leaf node that visually represents a grouping symbol.
103
+
104
+ ### Properties
105
+
106
+ Inherits all properties from [`omdLeafNode`](./omdLeafNode.md), plus:
107
+
108
+ #### `symbol`
109
+ - **Type:** string
110
+ - **Description:** The grouping symbol character (e.g., '(' or ')')
111
+
112
+ #### `type`
113
+ - **Type:** string
114
+ - **Description:** Always "parenthesis"
115
+
116
+ #### `textElement`
117
+ - **Type:** jsvgTextLine
118
+ - **Description:** The SVG text element displaying the symbol
119
+
120
+ ### Methods
121
+
122
+ Inherits all methods from [`omdLeafNode`](./omdLeafNode.md), plus:
123
+
124
+ #### `parseSymbol(nodeData)`
125
+ Internal method to extract symbol from input.
126
+ - **Returns:** string - The input symbol unchanged
127
+
128
+ ---
129
+
130
+ #### `parseType()`
131
+ Internal method to set node type.
132
+ - **Returns:** "parenthesis"
133
+
134
+ ---
135
+
136
+ #### `clone()`
137
+ Creates a clone of the group node.
138
+ - **Returns:** omdGroupNode - A new instance with:
139
+ - Same text content
140
+ - Original node's ID added to provenance array
141
+
142
+ ---
143
+
144
+ #### `computeDimensions()`
145
+ Calculates node dimensions based on text content.
146
+ Does NOT add padding, unlike other leaf nodes.
147
+ Overrides base class method.
148
+
149
+ ---
150
+
151
+ #### `updateLayout()`
152
+ Updates the position of the node.
153
+ Overrides base class method.
154
+
155
+ ---
156
+
157
+ #### `toMathJSNode()`
158
+ Converts to math.js AST format.
159
+ - **Returns:** Object - A math.js-compatible AST node with:
160
+ - `type`: "SymbolNode"
161
+ - `name`: The grouping symbol
162
+
163
+ ### Example
164
+
165
+ ```javascript
166
+ // Create grouping symbols
167
+ const leftParen = new omdGroupNode('(');
168
+ const rightParen = new omdGroupNode(')');
169
+ const leftBracket = new omdGroupNode('[');
170
+
171
+ // Render a symbol
172
+ const node = new omdGroupNode('(');
173
+ node.setFontSize(24);
174
+ node.computeDimensions(); // Calculate size (no padding)
175
+ node.updateLayout(); // Position the text element
176
+ ```
177
+
178
+ ### See Also
179
+
180
+ - [omdLeafNode](./omdLeafNode.md) - Parent class
181
+ - [omdNode](./omdNode.md) - Base class
182
+ - [omdParenthesisNode](./omdParenthesisNode.md) - For complete parenthetical expressions
@@ -0,0 +1,96 @@
1
+
2
+ # omdHelpers
3
+
4
+ `omdHelpers` is a collection of convenience functions designed to simplify common tasks when working with the OMD library. These helpers abstract away underlying complexities, making it easier to create and manipulate mathematical expressions and visualizations.
5
+
6
+ ## Overview
7
+
8
+ The `omdHelpers` object is exported from the main `omd/index.js` entry point, making its functions readily available for use in your project.
9
+
10
+ ## Functions
11
+
12
+ ### `createNodeFromExpression(expression, mathjs)`
13
+
14
+ Creates an `omdNode` instance from a string representation of a mathematical expression. This function parses the expression using math.js and instantiates the appropriate `omdNode` subclass.
15
+
16
+ - **Parameters:**
17
+ - `expression` {string} - The mathematical expression as a string (e.g., `"x^2 + 2x + 1"`).
18
+ - `mathjs` {object} - The math.js instance to use for parsing the expression.
19
+ - **Returns:** {omdNode} The root `omdNode` of the created expression tree.
20
+
21
+ ```javascript
22
+ import { omdHelpers } from 'omd-library';
23
+ import * as math from 'mathjs';
24
+
25
+ const expressionNode = omdHelpers.createNodeFromExpression('2x + 5', math);
26
+ // expressionNode will be an instance of omdBinaryExpressionNode or another omdNode subclass
27
+ ```
28
+
29
+ ---
30
+
31
+ ### `createEquation(equationString)`
32
+
33
+ Creates an `omdEquationNode` instance from a string representation of an equation. This is a specialized helper for equations, ensuring proper parsing and node creation.
34
+
35
+ - **Parameters:**
36
+ - `equationString` {string} - The equation as a string (e.g., `"x + 2 = 5"`).
37
+ - **Returns:** {omdEquationNode} The created `omdEquationNode`.
38
+
39
+ ```javascript
40
+ import { omdHelpers } from 'omd-library';
41
+
42
+ const equation = omdHelpers.createEquation('3y - 7 = 14');
43
+ // equation will be an instance of omdEquationNode
44
+ ```
45
+
46
+ ---
47
+
48
+ ### `createStepVisualizer(equationStrings)`
49
+
50
+ Creates an `omdStepVisualizer` instance from an array of equation strings. This is useful for quickly setting up a step-by-step solution display.
51
+
52
+ - **Parameters:**
53
+ - `equationStrings` {Array<string>} - An array of strings, where each string represents an equation step (e.g., `["2x = 10", "x = 5"]`).
54
+ - **Returns:** {omdStepVisualizer} The created `omdStepVisualizer` instance.
55
+
56
+ ```javascript
57
+ import { omdHelpers } from 'omd-library';
58
+
59
+ const steps = [
60
+ '4x + 8 = 20',
61
+ '4x = 12',
62
+ 'x = 3'
63
+ ];
64
+ const visualizer = omdHelpers.createStepVisualizer(steps);
65
+ // visualizer will be an instance of omdStepVisualizer
66
+ ```
67
+
68
+ ## Example Usage
69
+
70
+ ```javascript
71
+ import { omdDisplay, omdHelpers } from 'omd-library';
72
+ import * as math from 'mathjs';
73
+
74
+ // Get a container element (assuming it exists in your HTML)
75
+ const container = document.getElementById('math-display-area');
76
+
77
+ // Create an expression node using a helper
78
+ const expression = omdHelpers.createNodeFromExpression('a^2 + b^2', math);
79
+
80
+ // Create an equation using a helper
81
+ const equation = omdHelpers.createEquation('E = mc^2');
82
+
83
+ // Create a step visualizer using a helper
84
+ const solutionSteps = [
85
+ 'x + 5 = 10',
86
+ 'x = 5'
87
+ ];
88
+ const stepVisualizer = omdHelpers.createStepVisualizer(solutionSteps);
89
+
90
+ // You can then render these nodes using omdDisplay or omdCanvas
91
+ const display = new omdDisplay(container);
92
+ display.render(expression);
93
+
94
+ // Or for the step visualizer
95
+ // display.render(stepVisualizer);
96
+ ```