@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,117 @@
1
+ # omdConstantNode
2
+
3
+ Represents a numeric constant in a mathematical expression. This is a leaf node, meaning it has no children.
4
+
5
+ ## Class: `omdConstantNode extends omdLeafNode`
6
+
7
+ ```javascript
8
+ import { omdConstantNode } from './omd/nodes/omdConstantNode.js';
9
+ ```
10
+
11
+ ### Constructor
12
+
13
+ ```javascript
14
+ new omdConstantNode(nodeData)
15
+ ```
16
+
17
+
18
+ **Parameters:**
19
+ - `nodeData` {Object|number} - The math.js AST node data (should have a `value` property) or a raw numeric value.
20
+
21
+ **Description:**
22
+ Creates a node representing a numeric constant. This is typically done automatically by the parser when an expression is processed.
23
+
24
+ ### Static Methods
25
+
26
+
27
+ #### `fromValue(value)`
28
+ Creates an `omdConstantNode` from a simple numeric value.
29
+
30
+ ```javascript
31
+ const constantNode = omdConstantNode.fromValue(42);
32
+ ```
33
+ - **Parameters:**
34
+ - `value` {number} - The numeric value for the constant.
35
+ - **Returns:** `omdConstantNode` A new instance of `omdConstantNode`.
36
+
37
+ ### Properties
38
+
39
+ Inherits all properties from [`omdLeafNode`](./omdLeafNode.md), plus:
40
+
41
+
42
+ #### `number`
43
+ - **Type:** `number`
44
+ - **Description:** The numeric value of the constant.
45
+
46
+ ### Methods
47
+
48
+ Inherits all methods from [`omdLeafNode`](./omdLeafNode.md). Key methods include:
49
+
50
+
51
+ #### `getValue()`
52
+ Gets the numeric value of the constant.
53
+ - **Returns:** `number` - The constant's value.
54
+
55
+ ---
56
+
57
+
58
+ #### `evaluate()`
59
+ Evaluates the node, which for a constant simply returns its value.
60
+ - **Returns:** `number` - The numeric value.
61
+
62
+ ---
63
+
64
+
65
+ #### `getRationalValue()`
66
+ Gets the value as a rational number (a fraction with a denominator of 1).
67
+ - **Returns:** `Object` - An object `{ num: number, den: 1 }`.
68
+
69
+ ---
70
+
71
+
72
+ #### `toMathJSNode()`
73
+ Converts the node to its math.js AST representation.
74
+ - **Returns:** `Object` - A math.js-compatible AST node for a constant, with a `clone()` method for compatibility.
75
+
76
+ ---
77
+
78
+
79
+ #### `simplify()`
80
+ A constant cannot be simplified further.
81
+ - **Returns:** `Object` - An object indicating failure: `{ success: false, ... }`.
82
+
83
+ ---
84
+
85
+
86
+ #### `toString()`
87
+ Converts the node to its string representation.
88
+ - **Returns:** `string` - The numeric value as a string.
89
+
90
+
91
+ #### `isConstant()`
92
+ Checks if the node is a constant (always true for omdConstantNode).
93
+ - **Returns:** `boolean`
94
+
95
+ ### Example
96
+
97
+ ```javascript
98
+ // Create a constant node from a number
99
+ const pi = omdConstantNode.fromValue(3.14159);
100
+
101
+ // Set its font size and render it
102
+ pi.setFontSize(24);
103
+ pi.initialize(); // Computes dimensions and layout
104
+
105
+ // Get its value
106
+ console.log(pi.getValue()); // 3.14159
107
+
108
+ // Add it to an SVG container to display
109
+ const svgContainer = new jsvgContainer();
110
+ svgContainer.addChild(pi);
111
+ document.body.appendChild(svgContainer.svgObject);
112
+ ```
113
+
114
+ ### See Also
115
+
116
+ - [`omdLeafNode`](./omdLeafNode.md) - The parent class.
117
+ - [`omdVariableNode`](./omdVariableNode.md) - For symbolic variables like 'x'.
@@ -0,0 +1,121 @@
1
+ # omdDisplay
2
+
3
+ A high-level component for displaying a single mathematical expression or a series of equation steps with automatic centering and layout management.
4
+
5
+ ## Class: `omdDisplay`
6
+
7
+ ```javascript
8
+ import { omdDisplay } from 'omd-library';
9
+ ```
10
+
11
+ ### Constructor
12
+
13
+ ```javascript
14
+ new omdDisplay(container, options)
15
+ ```
16
+
17
+ **Parameters:**
18
+ - `container` {HTMLElement} - The DOM element where the expression will be rendered.
19
+ - `options` {Object} (optional) - Configuration options:
20
+ - `fontSize` {number} - The base font size in pixels for the expression. Defaults to `32`.
21
+ - `centerContent` {boolean} - If `true`, the content is automatically centered within the container. Defaults to `true`.
22
+ - `topMargin` {number} - The top margin in pixels, used when centering content. Defaults to `40`.
23
+
24
+ **Example:**
25
+ ```javascript
26
+ const displayContainer = document.getElementById('math-display');
27
+ const display = new omdDisplay(displayContainer, {
28
+ fontSize: 36,
29
+ topMargin: 50
30
+ });
31
+ ```
32
+
33
+ ### Methods
34
+
35
+
36
+ #### `render(expression)`
37
+ Renders a mathematical expression or equation. If a string is provided:
38
+ - If the string contains semicolons (`;`), it is treated as a sequence of equations and rendered as steps.
39
+ - If the string contains an equals sign (`=`), it is treated as a single equation and wrapped in an `omdStepVisualizer`.
40
+ - Otherwise, it is parsed as a single expression.
41
+
42
+ ```javascript
43
+ display.render('x^2 + 2x + 1 = 0');
44
+
45
+ // Renders a sequence of steps
46
+ display.render('2x + 4 = 10; 2x = 6; x = 3');
47
+ ```
48
+ - **Parameters:**
49
+ - `expression` {string | omdNode} - The mathematical expression string or a pre-existing `omdNode` instance.
50
+ - **Returns:** `omdNode` The root node of the rendered content (often an `omdStepVisualizer`).
51
+
52
+ ---
53
+
54
+ #### `update(newNode)`
55
+
56
+ Replaces the currently displayed node with a new one, applying the current font size and centering if enabled.
57
+
58
+ ```javascript
59
+ const newNode = omdEquationNode.fromString('y = mx + b');
60
+ display.update(newNode);
61
+ ```
62
+ - **Parameters:**
63
+ - `newNode` {omdNode} - The new node to display.
64
+
65
+ ---
66
+
67
+ #### `getCurrentNode()`
68
+
69
+ Returns the node currently being displayed.
70
+
71
+ ```javascript
72
+ const currentNode = display.getCurrentNode();
73
+ ```
74
+ - **Returns:** {omdNode | null} The current root node, or `null` if nothing is displayed.
75
+
76
+ ---
77
+
78
+ #### `centerNode()`
79
+
80
+ Manually triggers the centering logic for the current node. This is especially useful for `omdEquationSequenceNode` instances to align them by their equals signs.
81
+
82
+ ```javascript
83
+ display.centerNode();
84
+ ```
85
+
86
+ ---
87
+
88
+ #### `setFontSize(size)`
89
+
90
+ Updates the font size for the currently displayed node and for any future content rendered.
91
+
92
+ ```javascript
93
+ display.setFontSize(48);
94
+ ```
95
+ - **Parameters:**
96
+ - `size` {number} - The new font size in pixels.
97
+
98
+ ---
99
+
100
+ #### `clear()`
101
+
102
+ Removes the current expression from the display.
103
+
104
+ ```javascript
105
+ display.clear();
106
+ ```
107
+
108
+ ---
109
+
110
+ #### `destroy()`
111
+
112
+ Cleans up the component, removing all DOM elements and detaching the resize observer.
113
+
114
+ ```javascript
115
+ display.destroy();
116
+ ```
117
+
118
+
119
+ ### See Also
120
+ - [`omdStepVisualizer`](./omdStepVisualizer.md) - The component used to display steps.
121
+ - [`omdEquationNode`](./omdEquationNode.md) - The node for representing equations.
@@ -0,0 +1,161 @@
1
+ # omdEquationNode
2
+
3
+ Represents a mathematical equation, which consists of a left side, a right side, and an equals sign. This class provides extensive functionality for manipulating the equation, such as applying operations to both sides, swapping sides, and simplification.
4
+
5
+ ## Class: `omdEquationNode extends omdNode`
6
+
7
+ ```javascript
8
+ import { omdEquationNode } from './omd/nodes/omdEquationNode.js';
9
+ ```
10
+
11
+ ### Constructor
12
+
13
+ ```javascript
14
+ new omdEquationNode(ast)
15
+ ```
16
+
17
+
18
+ **Parameters:**
19
+ - `ast` {Object} - The math.js Abstract Syntax Tree (AST) for the equation. Typically an `AssignmentNode` with `object` (left side) and `value` (right side) properties, but can also be an `OperatorNode` with two arguments.
20
+
21
+ ### Static Methods
22
+
23
+
24
+ #### `fromString(equationString)`
25
+ Creates an `omdEquationNode` instance from a string representation of an equation.
26
+
27
+ ```javascript
28
+ const equation = omdEquationNode.fromString('2x + 4 = 10');
29
+ ```
30
+ - **Parameters:**
31
+ - `equationString` {string} - The string to parse (e.g., "2x+4=10").
32
+ - **Returns:** `omdEquationNode` A new instance of `omdEquationNode`.
33
+ - **Throws:** Error if the string is not a valid equation (must contain exactly one '=' and both sides must be non-empty).
34
+
35
+ ### Properties
36
+
37
+ Inherits all properties from [`omdNode`](./omdNode.md), plus:
38
+
39
+ #### `left`
40
+ - **Type:** [`omdNode`](./omdNode.md)
41
+ - **Description:** The node representing the left side of the equation.
42
+
43
+ #### `right`
44
+ - **Type:** [`omdNode`](./omdNode.md)
45
+ - **Description:** The node representing the right side of the equation.
46
+
47
+ #### `equalsSign`
48
+ - **Type:** [`omdOperatorNode`](./omdOperatorNode.md)
49
+ - **Description:** The node for the equals sign.
50
+
51
+ ### Methods
52
+
53
+ Inherits all methods from [`omdNode`](./omdNode.md), plus:
54
+
55
+
56
+ #### `addToBothSides(value)`
57
+ Returns a new equation with a value added to both sides.
58
+ - `value` {number|Object} - The value or math.js AST to add.
59
+ - **Returns:** `omdEquationNode` A new equation node with the operation applied.
60
+
61
+ ---
62
+
63
+
64
+ #### `subtractFromBothSides(value)`
65
+ Returns a new equation with a value subtracted from both sides.
66
+ - `value` {number|Object} - The value or math.js AST to subtract.
67
+ - **Returns:** `omdEquationNode` A new equation node.
68
+
69
+ ---
70
+
71
+
72
+ #### `multiplyBothSides(value)`
73
+ Returns a new equation with both sides multiplied by a value.
74
+ - `value` {number|Object} - The value or math.js AST to multiply by.
75
+ - **Returns:** `omdEquationNode` A new equation node.
76
+
77
+ ---
78
+
79
+
80
+ #### `divideBothSides(value)`
81
+ Returns a new equation with both sides divided by a value.
82
+ - `value` {number|Object} - The value or math.js AST to divide by.
83
+ - **Returns:** `omdEquationNode` A new equation node.
84
+
85
+ ---
86
+
87
+
88
+ #### `applyFunction(functionName)`
89
+ Applies a function (e.g., `sqrt`, `log`) to both sides of the equation.
90
+ - `functionName` {string} - The name of the function to apply.
91
+ - **Returns:** `omdEquationNode` A new equation with the function applied to both sides.
92
+
93
+ ---
94
+
95
+
96
+ #### `applyOperation(value, operation, side = 'both')`
97
+ Applies an arithmetic operation to one or both sides of the equation.
98
+ - `value` {number|omdNode} - The value to apply.
99
+ - `operation` {string} - The operation to perform: 'add', 'subtract', 'multiply', or 'divide'.
100
+ - `side` {string} - The side to apply the operation to: 'left', 'right', or 'both'. Defaults to 'both'.
101
+ - **Returns:** `omdEquationNode` A new equation node with the operation applied.
102
+
103
+ ---
104
+
105
+
106
+ #### `swapSides()`
107
+ Swaps the left and right sides of the equation.
108
+ - **Returns:** `omdEquationNode` A new equation node with the sides swapped.
109
+
110
+ ---
111
+
112
+
113
+ #### `simplify()`
114
+ Simplifies both sides of the equation using the simplification engine.
115
+ - **Returns:** `Object` An object containing `{ success, newRoot, message }`.
116
+
117
+ ---
118
+
119
+
120
+ #### `clone()`
121
+ Creates a deep clone of the equation node, preserving its structure and provenance.
122
+ - **Returns:** `omdEquationNode` A new, identical instance of the equation node.
123
+
124
+ ---
125
+
126
+
127
+ #### `toString()`
128
+ Converts the equation to its string representation.
129
+ - **Returns:** `string` The equation as a string (e.g., "x + 1 = 5").
130
+
131
+ ---
132
+
133
+
134
+ #### `evaluate(variables)`
135
+ Evaluates both sides of the equation with a given set of variables.
136
+ - `variables` {Object} - A map of variable names to their numeric values (e.g., `{ x: 2 }`).
137
+ - **Returns:** `Object` An object with the evaluated `left` and `right` side values.
138
+
139
+ ### Example
140
+
141
+ ```javascript
142
+ // Create an equation from a string
143
+ const equation = omdEquationNode.fromString('2 * (x + 1) = 10');
144
+
145
+ // Perform a series of operations
146
+ const step1 = equation.divideBothSides(2); // Result: x + 1 = 5
147
+ const step2 = step1.subtractFromBothSides(1); // Result: x = 4
148
+
149
+ // You can chain these operations
150
+ const finalResult = omdEquationNode.fromString('2 * (x + 1) = 10')
151
+ .divideBothSides(2)
152
+ .subtractFromBothSides(1);
153
+
154
+ console.log(finalResult.toString()); // Output: x = 4
155
+ ```
156
+
157
+ ### See Also
158
+
159
+ - [`omdNode`](./omdNode.md) - The base class for all nodes.
160
+ - [`omdBinaryExpressionNode`](./omdBinaryExpressionNode.md) - Often used for the sides of the equation.
161
+ - [`omdStepVisualizer`](./omdStepVisualizer.md) - For displaying a sequence of equation transformations.
@@ -0,0 +1,301 @@
1
+ # omdEquationSequenceNode
2
+
3
+ Represents a sequence of equations for step-by-step calculations. This node manages the layout of multiple equations, ensuring their equals signs are vertically aligned for readability. It's particularly useful for displaying mathematical problem-solving sequences where each step builds on the previous one.
4
+
5
+ ## Class: `omdEquationSequenceNode extends omdNode`
6
+
7
+ ```javascript
8
+ import { omdEquationSequenceNode } from './omd/nodes/omdEquationSequenceNode.js';
9
+ ```
10
+
11
+ ### Constructor
12
+
13
+ ```javascript
14
+ new omdEquationSequenceNode(steps)
15
+ ```
16
+
17
+ **Parameters:**
18
+ - `steps` {Array<omdEquationNode>} - An array of `omdEquationNode` objects representing the sequence of equations.
19
+
20
+ ### Static Methods
21
+
22
+ #### `fromStringArray(stepStrings)`
23
+ Creates an `omdEquationSequenceNode` instance from an array of equation strings.
24
+
25
+ ```javascript
26
+ const sequence = omdEquationSequenceNode.fromStringArray([
27
+ '2x + 4 = 10',
28
+ '2x = 6',
29
+ 'x = 3'
30
+ ]);
31
+ ```
32
+ - **Parameters:**
33
+ - `stepStrings` {Array<string>} - Array of strings, each representing an equation step.
34
+ - **Returns:** `omdEquationSequenceNode` A new instance.
35
+ - **Throws:** Error if any string is not a valid equation (must contain '=').
36
+
37
+ ---
38
+
39
+ #### `fromSteps(stepsArray)`
40
+ Creates a sequence from an array of expression strings (can be equations or expressions).
41
+
42
+ ```javascript
43
+ const sequence = omdEquationSequenceNode.fromSteps([
44
+ '2x + 4 = 10',
45
+ 'x = 3'
46
+ ]);
47
+ ```
48
+ - **Parameters:**
49
+ - `stepsArray` {Array<string>} - Array of expression strings.
50
+ - **Returns:** `omdEquationSequenceNode` A new sequence node.
51
+
52
+ ### Properties
53
+
54
+ Inherits all properties from [`omdNode`](./omdNode.md), plus:
55
+
56
+ #### `steps`
57
+ - **Type:** `Array<omdNode>`
58
+ - **Description:** Array of nodes representing each step in the sequence.
59
+
60
+ #### `currentStepIndex`
61
+ - **Type:** `number`
62
+ - **Description:** Index of the currently active step (0-based).
63
+
64
+ #### `stepDescriptions`
65
+ - **Type:** `Array<string>`
66
+ - **Description:** Optional descriptions for each step.
67
+
68
+ #### `importanceLevels`
69
+ - **Type:** `Array<number>`
70
+ - **Description:** Importance levels for filtering steps (0 = major, 1 = intermediate, 2 = minor).
71
+
72
+ #### `currentFilterLevels`
73
+ - **Type:** `Array<number>`
74
+ - **Description:** Currently active filter levels for step visibility.
75
+
76
+ ### Methods
77
+
78
+ Inherits all methods from [`omdNode`](./omdNode.md), plus:
79
+
80
+ #### `addStep(step, descriptionOrOptions, importance)`
81
+ Adds a new step to the sequence.
82
+
83
+ ```javascript
84
+ // Using options object
85
+ sequence.addStep(equationNode, {
86
+ description: 'Subtract 4 from both sides',
87
+ stepMark: 0
88
+ });
89
+
90
+ // Using separate parameters
91
+ sequence.addStep(equationNode, 'Subtract 4 from both sides', 0);
92
+
93
+ // Using string (will be parsed)
94
+ sequence.addStep('x = 3', 'Final result', 0);
95
+ ```
96
+ - **Parameters:**
97
+ - `step` {omdNode|string} - The node object or expression string for the step.
98
+ - `descriptionOrOptions` {Object|string} - Options object or description string.
99
+ - `importance` {number} - Importance level (0-2) if using string description.
100
+ - **Returns:** `number` The index of the added step.
101
+
102
+ ---
103
+
104
+ #### `getCurrentEquation()`
105
+ Gets the last equation in the sequence (the current working equation).
106
+ - **Returns:** `omdEquationNode|null` The last equation, or null if no equations exist.
107
+
108
+ ---
109
+
110
+ #### `getCurrentStep()`
111
+ Gets the current step node based on `currentStepIndex`.
112
+ - **Returns:** `omdNode|null` The current step node.
113
+
114
+ ---
115
+
116
+ #### `applyEquationOperation(value, operation)`
117
+ Applies a specified operation to the current equation and adds the result as a new step.
118
+
119
+ ```javascript
120
+ sequence.applyEquationOperation(4, 'subtract'); // Subtract 4 from both sides
121
+ sequence.applyEquationOperation(2, 'divide'); // Divide both sides by 2
122
+ ```
123
+ - **Parameters:**
124
+ - `value` {number|string} - The constant value or expression string to apply.
125
+ - `operation` {string} - The operation: 'add', 'subtract', 'multiply', or 'divide'.
126
+ - **Returns:** `omdEquationSequenceNode` Returns this sequence for chaining.
127
+
128
+ ---
129
+
130
+ #### `setFilterLevel(level)`
131
+ Sets the filter level for visible steps in the sequence.
132
+
133
+ ```javascript
134
+ sequence.setFilterLevel(0); // Show only major steps
135
+ sequence.setFilterLevel(1); // Show only intermediate steps
136
+ ```
137
+ - **Parameters:**
138
+ - `level` {number} - The stepMark level to show (default: 0 for major steps).
139
+
140
+ ---
141
+
142
+ #### `setFilterLevels(levels)`
143
+ Sets multiple filter levels for visible steps.
144
+
145
+ ```javascript
146
+ sequence.setFilterLevels([0, 1]); // Show major and intermediate steps
147
+ ```
148
+ - **Parameters:**
149
+ - `levels` {Array<number>} - Array of stepMark levels to show.
150
+
151
+ ---
152
+
153
+ #### `updateStepsVisibility(filterFunction)`
154
+ Updates the visibility of steps based on a filter function.
155
+
156
+ ```javascript
157
+ sequence.updateStepsVisibility(step => step.stepMark <= 1); // Show steps with importance 0 or 1
158
+ ```
159
+ - **Parameters:**
160
+ - `filterFunction` {Function} - Function that returns true for visible steps.
161
+
162
+ ---
163
+
164
+ #### `recordSimplificationHistory(name, affectedNodes, message, metadata)`
165
+ Records a simplification step in the history.
166
+
167
+ ```javascript
168
+ sequence.recordSimplificationHistory(
169
+ 'Combine Like Terms',
170
+ ['node1', 'node2'],
171
+ 'Combined 2x and 3x to get 5x',
172
+ { ruleType: 'arithmetic' }
173
+ );
174
+ ```
175
+ - **Parameters:**
176
+ - `name` {string} - Name of the simplification rule.
177
+ - `affectedNodes` {Array<string>} - Array of node IDs affected.
178
+ - `message` {string} - Human-readable description.
179
+ - `metadata` {Object} - Additional metadata (optional).
180
+
181
+ ---
182
+
183
+ #### `getSimplificationHistory()`
184
+ Gets the complete simplification history for this sequence.
185
+ - **Returns:** `Array<Object>` Array of simplification history entries.
186
+
187
+ ---
188
+
189
+ #### `clearSimplificationHistory()`
190
+ Clears the simplification history.
191
+
192
+ ---
193
+
194
+ #### `rebuildNodeMap()`
195
+ Rebuilds the internal node map used for tracking all nodes in the sequence.
196
+
197
+ ---
198
+
199
+ #### `findAllNodes()`
200
+ Finds all nodes contained within this sequence.
201
+ - **Returns:** `Array<omdNode>` Array of all contained nodes.
202
+
203
+ ---
204
+
205
+ #### `clear()`
206
+ Clears all steps from the sequence.
207
+
208
+ ```javascript
209
+ sequence.clear(); // Removes all steps and resets the sequence
210
+ ```
211
+
212
+ ---
213
+
214
+ #### `clone()`
215
+ Creates a deep clone of the sequence node.
216
+ - **Returns:** `omdEquationSequenceNode` A new, identical instance.
217
+
218
+ ---
219
+
220
+ #### `toString()`
221
+ Converts the entire sequence to a multi-line string.
222
+ - **Returns:** `string` Multi-line string representation of all steps.
223
+
224
+ ---
225
+
226
+ #### `setFontSize(fontSize)`
227
+ Sets the font size for the sequence and propagates to all steps.
228
+ - **Parameters:**
229
+ - `fontSize` {number} - The new font size.
230
+
231
+ ### Static Properties
232
+
233
+ #### `OPERATION_MAP`
234
+ Maps operation names to equation methods.
235
+
236
+ ```javascript
237
+ {
238
+ 'add': 'addToBothSides',
239
+ 'subtract': 'subtractFromBothSides',
240
+ 'multiply': 'multiplyBothSides',
241
+ 'divide': 'divideBothSides'
242
+ }
243
+ ```
244
+
245
+ ### Example Usage
246
+
247
+ ```javascript
248
+ // Create a sequence from equation strings
249
+ const sequence = omdEquationSequenceNode.fromStringArray([
250
+ '2x + 4 = 10'
251
+ ]);
252
+
253
+ // Add steps using operations
254
+ sequence.applyEquationOperation(4, 'subtract') // 2x + 4 - 4 = 10 - 4 → 2x = 6
255
+ .applyEquationOperation(2, 'divide'); // 2x ÷ 2 = 6 ÷ 2 → x = 3
256
+
257
+ // Filter to show only major steps
258
+ sequence.setFilterLevel(0);
259
+
260
+ // Add a custom step with description
261
+ const finalStep = omdEquationNode.fromString('x = 3');
262
+ sequence.addStep(finalStep, {
263
+ description: 'Solution found',
264
+ stepMark: 0
265
+ });
266
+
267
+ // Get the solution
268
+ console.log(sequence.getCurrentEquation().toString()); // "x = 3"
269
+
270
+ // View the complete sequence
271
+ console.log(sequence.toString());
272
+ ```
273
+
274
+ ### Advanced Example: Step Filtering
275
+
276
+ ```javascript
277
+ const sequence = new omdEquationSequenceNode([]);
278
+
279
+ // Add steps with different importance levels
280
+ sequence.addStep('2x + 4 = 10', 'Original equation', 0); // Major step
281
+ sequence.addStep('2x + 4 - 4 = 10 - 4', 'Subtract 4', 1); // Intermediate step
282
+ sequence.addStep('2x = 6', 'Simplified', 0); // Major step
283
+ sequence.addStep('2x ÷ 2 = 6 ÷ 2', 'Divide by 2', 1); // Intermediate step
284
+ sequence.addStep('x = 3', 'Final answer', 0); // Major step
285
+
286
+ // Show only major steps (0)
287
+ sequence.setFilterLevel(0); // Shows: 2x + 4 = 10, 2x = 6, x = 3
288
+
289
+ // Show major and intermediate steps
290
+ sequence.setFilterLevels([0, 1]); // Shows all steps
291
+
292
+ // Custom filtering
293
+ sequence.updateStepsVisibility(step => step.stepMark === 0); // Only major steps
294
+ ```
295
+
296
+ ### See Also
297
+
298
+ - [`omdEquationNode`](./omdEquationNode.md) - Individual equation representation.
299
+ - [`omdStepVisualizer`](./omdStepVisualizer.md) - Visual step tracker extending this class.
300
+ - [`omdOperationDisplayNode`](./omdOperationDisplayNode.md) - For displaying operation steps.
301
+ - [`omdNode`](./omdNode.md) - The base class for all nodes.