@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
+ # omdPopup
2
+
3
+ The `omdPopup` class handles the creation and management of popups for node overlays. These popups can be used for text input or for drawing with a pen tool.
4
+
5
+ ## Class Definition
6
+
7
+ ```javascript
8
+ export class omdPopup {
9
+ // ...
10
+ }
11
+ ```
12
+
13
+ ## Constructor
14
+
15
+ ### `new omdPopup(targetNode, parentElement, [options])`
16
+
17
+ Creates a new `omdPopup` instance.
18
+
19
+ * **targetNode** (`omdNode`): The node to which the popup is attached.
20
+ * **parentElement** (`jsvgElement`): The parent element for the popup.
21
+ * **[options]** (`object`, optional): Configuration options for the popup.
22
+ * **editable** (`boolean`, optional): Whether the popup is editable. Defaults to `true`.
23
+ * **animationDuration** (`number`, optional): The duration of the show/hide animation in milliseconds. Defaults to `200`.
24
+
25
+ ## Public Methods
26
+
27
+ ### `show(x, y)`
28
+
29
+ Creates and shows the popup at the specified coordinates.
30
+
31
+ * **x** (`number`): The x-coordinate for the popup.
32
+ * **y** (`number`): The y-coordinate for the popup.
33
+ * **Returns**: `Promise` - A promise that resolves when the show animation is complete.
34
+
35
+ ### `hide()`
36
+
37
+ Hides the popup.
38
+
39
+ * **Returns**: `Promise` - A promise that resolves when the hide animation is complete.
40
+
41
+ ### `toggle(x, y)`
42
+
43
+ Toggles the visibility of the popup.
44
+
45
+ * **x** (`number`): The x-coordinate for showing the popup.
46
+ * **y** (`number`): The y-coordinate for showing the popup.
47
+ * **Returns**: `Promise` - A promise that resolves when the animation is complete.
48
+
49
+ ### `setValidationCallback(callback)`
50
+
51
+ Sets the callback function to be called when the user submits their input.
52
+
53
+ * **callback** (`Function`): The function to call for validation.
54
+
55
+ ### `setClearCallback(callback)`
56
+
57
+ Sets the callback function to be called when the user clears the input.
58
+
59
+ * **callback** (`Function`): The function to call when clearing.
60
+
61
+ ### `getValue()`
62
+
63
+ Gets the current input value from the popup.
64
+
65
+ * **Returns**: `string` - The current input value.
66
+
67
+ ### `setValue(value)`
68
+
69
+ Sets the input value of the popup.
70
+
71
+ * **value** (`string`): The value to set.
72
+
73
+ ### `switchToMode(mode)`
74
+
75
+ Switches the popup between `'text'` and `'pen'` mode.
76
+
77
+ * **mode** (`string`): The mode to switch to. Can be `'text'` or `'pen'`.
78
+
79
+ ### `flashValidation(isValid)`
80
+
81
+ Flashes the popup background to indicate whether the user's input was valid.
82
+
83
+ * **isValid** (`boolean`): Whether the validation was successful.
84
+
85
+ ### `destroy()`
86
+
87
+ Destroys the popup and cleans up all associated elements.
88
+
89
+ ## Modes
90
+
91
+ The `omdPopup` has two modes:
92
+
93
+ * **Text Mode**: This is the default mode. It provides a simple text input field.
94
+ * **Pen Mode**: This mode allows the user to draw inside the popup using a pen tool. The drawing can then be transcribed to text using an OCR service.
95
+
96
+ The user can switch between modes using the 'T' and 'P' buttons on the popup.
97
+
98
+ ## Example Usage
99
+
100
+ ```javascript
101
+ // Create a popup for a node
102
+ const popup = new omdPopup(node, parentElement);
103
+
104
+ // Set a validation callback
105
+ popup.setValidationCallback(() => {
106
+ const value = popup.getValue();
107
+ if (value === 'correct') {
108
+ popup.flashValidation(true);
109
+ popup.hide();
110
+ } else {
111
+ popup.flashValidation(false);
112
+ }
113
+ });
114
+
115
+ // Show the popup
116
+ popup.show(100, 100);
117
+ ```
@@ -0,0 +1,127 @@
1
+ # omdPowerNode
2
+
3
+ Represents an exponentiation in a mathematical expression, such as `x^2` or `(a+b)^c`. It handles the specific layout requirements of a base and a superscripted exponent.
4
+
5
+ ## Class: `omdPowerNode extends omdNode`
6
+
7
+ ```javascript
8
+ import { omdPowerNode } from './omd/nodes/omdPowerNode.js';
9
+ ```
10
+
11
+ ### Constructor
12
+
13
+ ```javascript
14
+ new omdPowerNode(ast)
15
+ ```
16
+
17
+
18
+ **Parameters:**
19
+ - `ast` {Object} - The math.js AST for the power operation. It must be an `OperatorNode` with `op: '^'` and an `args` array containing two elements: the base and the exponent.
20
+
21
+ ### Static Methods
22
+
23
+
24
+ #### `fromString(expressionString)`
25
+ Creates an `omdPowerNode` from a string.
26
+
27
+ ```javascript
28
+ const powerNode = omdPowerNode.fromString('x^2');
29
+ ```
30
+ - **Parameters:**
31
+ - `expressionString` {string} - The power expression as a string.
32
+ - **Returns:** `omdPowerNode` A new instance.
33
+ - **Throws:** Error if math.js is not available or the string is not a valid power expression.
34
+
35
+ ### Properties
36
+
37
+ Inherits properties from [`omdNode`](./omdNode.md), plus:
38
+
39
+ #### `base`
40
+ - **Type:** [`omdNode`](./omdNode.md)
41
+ - **Description:** The node representing the base of the power operation.
42
+
43
+ #### `exponent`
44
+ - **Type:** [`omdNode`](./omdNode.md)
45
+ - **Description:** The node representing the exponent.
46
+
47
+ ### Methods
48
+
49
+ Inherits methods from [`omdNode`](./omdNode.md). Key methods include:
50
+
51
+
52
+ #### `evaluate(variables)`
53
+ Evaluates the expression by raising the evaluated base to the power of the evaluated exponent.
54
+ - **Parameters:**
55
+ - `variables` {Object} - A map of variable names to their numeric values.
56
+ - **Returns:** `number` - The result of the exponentiation, or `NaN` if base or exponent cannot be evaluated.
57
+
58
+ ---
59
+
60
+
61
+ #### `simplify()`
62
+ Delegates to the central simplification engine to simplify the base and exponent.
63
+ - **Returns:** `Object` - An object indicating the result: `{ success, newRoot, message }`.
64
+ - **Note:** This method is not implemented directly on `omdPowerNode`, but is available via the central simplification engine (see [omdSimplification](./omdSimplification.md)).
65
+
66
+ ---
67
+
68
+
69
+ #### `isSquare()`
70
+ Checks if the exponent is the constant value `2`.
71
+ - **Returns:** `boolean`.
72
+
73
+ ---
74
+
75
+
76
+ #### `isCube()`
77
+ Checks if the exponent is the constant value `3`.
78
+ - **Returns:** `boolean`.
79
+
80
+ ---
81
+
82
+
83
+ #### `getAlignmentBaseline()`
84
+ Calculates the vertical alignment point for the node, which is determined by the baseline of its `base` expression.
85
+ - **Returns:** `number` - The y-coordinate for alignment.
86
+
87
+ ---
88
+
89
+
90
+ #### `toMathJSNode()`
91
+ Converts the node back into its math.js AST representation.
92
+ - **Returns:** `Object` - A math.js `OperatorNode` for the power operation.
93
+
94
+ ---
95
+
96
+
97
+ #### `toString()`
98
+ Converts the node to its string representation, adding parentheses where necessary to preserve order of operations.
99
+ - **Returns:** `string` - e.g., `"(x+1)^2"`.
100
+
101
+ ### Example
102
+
103
+ ```javascript
104
+ // Create a node representing x^2
105
+ const ast = math.parse('x^2');
106
+ const powerNode = new omdPowerNode(ast);
107
+
108
+ // Set font size and render
109
+ powerNode.setFontSize(32);
110
+ powerNode.initialize();
111
+
112
+ // Check properties
113
+ console.log(powerNode.isSquare()); // true
114
+
115
+ // Evaluate
116
+ console.log(powerNode.evaluate({ x: 5 })); // 25
117
+
118
+ // Add to an SVG container to display
119
+ const svgContainer = new jsvgContainer();
120
+ svgContainer.addChild(powerNode);
121
+ document.body.appendChild(svgContainer.svgObject);
122
+ ```
123
+
124
+ ### See Also
125
+
126
+ - [`omdNode`](./omdNode.md) - The base class.
127
+ - [`omdBinaryExpressionNode`](./omdBinaryExpressionNode.md) - Can be used for complex bases or exponents.
@@ -0,0 +1,128 @@
1
+ # omdRationalNode
2
+
3
+ Represents a fraction, with a numerator and a denominator, such as `1/2` or `(x+1)/(x-1)`. It handles the distinct visual layout of a fraction, with the numerator positioned above the denominator, separated by a horizontal line.
4
+
5
+ ## Class: `omdRationalNode extends omdNode`
6
+
7
+ ```javascript
8
+ import { omdRationalNode } from './omd/nodes/omdRationalNode.js';
9
+ ```
10
+
11
+ ### Constructor
12
+
13
+ ```javascript
14
+ new omdRationalNode(astNodeData)
15
+ ```
16
+
17
+ **Parameters:**
18
+ - `astNodeData` {Object} - The math.js AST for the division operation. It must be an `OperatorNode` with `op: '/'` and an `args` array containing two elements: the numerator and the denominator.
19
+
20
+ ### Static Methods
21
+
22
+
23
+ #### `fromString(expressionString)`
24
+ Creates an `omdRationalNode` from a string containing a division.
25
+
26
+ ```javascript
27
+ const rationalNode = omdRationalNode.fromString('x / 2');
28
+ ```
29
+ - **Parameters:**
30
+ - `expressionString` {string} - The fractional expression as a string.
31
+ - **Returns:** `omdRationalNode` A new instance.
32
+ - **Throws:** Error if math.js is not available or the string is not a valid division expression.
33
+
34
+ ### Properties
35
+
36
+ Inherits properties from [`omdNode`](./omdNode.md), plus:
37
+
38
+ #### `numerator`
39
+ - **Type:** [`omdNode`](./omdNode.md)
40
+ - **Description:** The node representing the top part of the fraction.
41
+
42
+ #### `denominator`
43
+ - **Type:** [`omdNode`](./omdNode.md)
44
+ - **Description:** The node representing the bottom part of the fraction.
45
+
46
+ ### Methods
47
+
48
+ Inherits methods from [`omdNode`](./omdNode.md). Key methods include:
49
+
50
+
51
+ #### `evaluate(variables)`
52
+ Evaluates the fraction by dividing the evaluated numerator by the evaluated denominator.
53
+ - **Parameters:**
54
+ - `variables` {Object} - A map of variable names to their numeric values.
55
+ - **Returns:** `number` - The result of the division.
56
+ - **Throws:** Error if the denominator evaluates to zero.
57
+
58
+ ---
59
+
60
+
61
+ #### `simplify()`
62
+ Delegates to the central simplification engine to simplify the numerator and denominator and to reduce the fraction.
63
+ - **Returns:** `Object` - An object indicating the result: `{ success, newRoot, message }`.
64
+ - **Note:** This method is not implemented directly on `omdRationalNode`, but is available via the central simplification engine (see [omdSimplification](./omdSimplification.md)).
65
+
66
+ ---
67
+
68
+
69
+ #### `reduce()`
70
+ If the fraction is constant, reduces it to its lowest terms (e.g., `4/8` becomes `1/2`). If the new denominator is `1`, it returns an `omdConstantNode`.
71
+ - **Returns:** `omdRationalNode | omdConstantNode` The reduced node, or a clone of the original if it's not constant.
72
+
73
+ ---
74
+
75
+
76
+ #### `isProper()`
77
+ Checks if the fraction is proper (the absolute value of the numerator is less than the absolute value of the denominator). Only applies to constant fractions.
78
+ - **Returns:** `boolean | null` - `true` if proper, `false` if improper, `null` if not constant.
79
+
80
+ ---
81
+
82
+
83
+ #### `getAlignmentBaseline()`
84
+ Calculates the vertical alignment point for the node, which is the y-position of the fraction bar.
85
+ - **Returns:** `number` - The y-coordinate for alignment.
86
+
87
+ ---
88
+
89
+
90
+ #### `toMathJSNode()`
91
+ Converts the node back into its math.js AST representation.
92
+ - **Returns:** `Object` - A math.js `OperatorNode` for division.
93
+
94
+ ---
95
+
96
+
97
+ #### `toString()`
98
+ Converts the node to its string representation, adding parentheses where necessary.
99
+ - **Returns:** `string` - e.g., `"(x + 1) / (x - 1)"`.
100
+
101
+ fraction.initialize();
102
+ document.body.appendChild(svgContainer.svgObject);
103
+
104
+ ### Example
105
+
106
+ ```javascript
107
+ // Create a fraction from a string
108
+ const fraction = omdRationalNode.fromString('(a+b)/(a-b)');
109
+
110
+ // Set font size and render
111
+ fraction.setFontSize(28);
112
+ fraction.initialize();
113
+
114
+ // Evaluate with given variables
115
+ const result = fraction.evaluate({ a: 3, b: 1 });
116
+ console.log(result); // Output: 2 (since (3+1)/(3-1) = 4/2 = 2)
117
+
118
+ // Add to an SVG container to display
119
+ const svgContainer = new jsvgContainer();
120
+ svgContainer.addChild(fraction);
121
+ document.body.appendChild(svgContainer.svgObject);
122
+ ```
123
+
124
+ ### See Also
125
+
126
+ - [`omdNode`](./omdNode.md) - The base class.
127
+ - [`omdConstantNode`](./omdConstantNode.md) - For constant numerators/denominators.
128
+ - [`omdBinaryExpressionNode`](./omdBinaryExpressionNode.md) - For complex numerators/denominators.
@@ -0,0 +1,128 @@
1
+ # omdEquationSequenceNode
2
+
3
+ Represents a sequence of mathematical steps, typically a series of equations that show the process of solving a problem. This node is a container that manages the layout, alignment, and simplification history of its steps.
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<[`omdNode`](./omdNode.md)>} - An array of nodes (usually `omdEquationNode` or `omdOperationDisplayNode`) that make up the sequence.
19
+
20
+
21
+ ### Static Methods
22
+
23
+ #### `fromSteps(stepsArray)`
24
+ Creates an `omdEquationSequenceNode` from an array of expression strings.
25
+
26
+ ```javascript
27
+ const sequence = omdEquationSequenceNode.fromSteps([
28
+ '2x + 4 = 10',
29
+ '2x = 6',
30
+ 'x = 3'
31
+ ]);
32
+ ```
33
+ - **Parameters:**
34
+ - `stepsArray` {Array<string>} - An array of strings, where each string is a step (either an equation or an expression).
35
+ - **Returns:** `omdEquationSequenceNode` A new instance.
36
+ - **Throws:** Error if a string is not a valid equation or expression, or if math.js is not available.
37
+
38
+ ### Core Methods
39
+
40
+
41
+ #### `addStep(step, options)`
42
+ Adds a new step to the end of the sequence.
43
+
44
+ - **Parameters:**
45
+ - `step` {omdNode | string} - The node or expression string to add. If a string, it is parsed as an equation or expression.
46
+ - `options` {Object|string} (optional) - Options for the step, such as `description` and `stepMark` (importance level), or a description string for backward compatibility.
47
+ - `importance` {number} (optional) - Importance level (0, 1, or 2) if using legacy signature.
48
+ - **Returns:** `number` - The index of the newly added step.
49
+
50
+ ---
51
+
52
+
53
+ #### `simplify()`
54
+ Applies one round of simplification to the **last step** in the sequence and adds the result as a new step.
55
+
56
+ - **Returns:** `Object` - An object detailing the result: `{ success, foldedCount, isFinalSimplification, message }`.
57
+
58
+ ---
59
+
60
+
61
+ #### `simplifyAll(maxIterations)`
62
+ Repeatedly calls `simplify()` on the last step until no more simplifications can be applied or the iteration limit is reached.
63
+
64
+ - **Parameters:**
65
+ - `maxIterations` {number} (optional) - A safeguard against infinite loops. Defaults to `50`.
66
+ - **Returns:** `Object` - An object summarizing the process: `{ success, totalSteps, iterations, message }`.
67
+
68
+ ---
69
+
70
+
71
+ #### `applyEquationOperation(value, operation)`
72
+ Applies an operation (e.g., 'add', 'subtract', 'multiply', 'divide') to both sides of the last equation in the sequence. This typically adds two new steps: a visual display of the operation and the resulting new equation.
73
+
74
+ - **Parameters:**
75
+ - `value` {number} - The value to apply.
76
+ - `operation` {string} - The name of the operation ('add', 'subtract', 'multiply', 'divide').
77
+ - **Returns:** `omdEquationSequenceNode` The sequence instance, for chaining.
78
+
79
+ ---
80
+
81
+
82
+ #### `applyEquationFunction(functionName)`
83
+ Applies a function (e.g., 'sqrt') to both sides of the last equation and adds the result as a new step.
84
+
85
+ - **Parameters:**
86
+ - `functionName` {string} - The name of the function.
87
+ - **Returns:** `omdEquationSequenceNode` The sequence instance, for chaining.
88
+
89
+
90
+ ### Other Key Methods
91
+
92
+ - `getCurrentEquation()`: Returns the last `omdEquationNode` in the sequence, or `null` if none.
93
+ - `getCurrentStep()`: Returns the current step node (may not be an equation).
94
+ - `getSimplificationHistory()`: Returns an array of all simplification events that have occurred.
95
+ - `rebuildNodeMap()`: Re-indexes all nodes within the sequence, which is crucial for provenance tracking and highlighting.
96
+ - `updateStepsVisibility(predicate)`: Shows or hides steps based on a provided function, useful for filtering and UI.
97
+ - `clear()`: Removes all steps and history from the sequence.
98
+ - `navigateToStep(index)`: Navigates to a specific step by index.
99
+ - `nextStep()`, `previousStep()`: Navigate forward/backward through steps.
100
+
101
+
102
+ ### Layout and Provenance
103
+
104
+ The `omdEquationSequenceNode` automatically aligns all `omdEquationNode` steps by their equals signs, creating a clean, readable layout. It also tracks provenance for all nodes, supporting step-by-step highlighting and history.
105
+
106
+
107
+ ### Example
108
+
109
+ ```javascript
110
+ // Create a sequence with an initial equation
111
+ const sequence = omdEquationSequenceNode.fromSteps([
112
+ '2 * (x + 1) = 10'
113
+ ]);
114
+
115
+ // Apply operations and simplifications
116
+ sequence.applyEquationOperation(2, 'divide'); // Adds a step: (2*(x+1))/2 = 10/2
117
+ sequence.simplifyAll(); // Simplifies to x+1=5, then x=4
118
+
119
+ // Add the sequence to a display
120
+ const display = new omdDisplay(document.getElementById('container'));
121
+ display.render(sequence);
122
+ ```
123
+
124
+ ### See Also
125
+
126
+ - [`omdNode`](./omdNode.md) - The base class.
127
+ - [`omdEquationNode`](./omdEquationNode.md) - The primary type of node held within a sequence.
128
+ - [`omdStepVisualizer`](./omdStepVisualizer.md) - A subclass that adds interactive dots and explanations to the sequence.
@@ -0,0 +1,110 @@
1
+ # omdSimplification
2
+
3
+ Core module that provides the main entry points for expression simplification.
4
+
5
+ ## Functions
6
+
7
+
8
+ ### `simplifyExpression(rootNode)`
9
+
10
+ Simplifies an entire mathematical expression tree by repeatedly applying simplification rules.
11
+
12
+ **Parameters:**
13
+ - `rootNode` (`omdNode`): The root node of the expression to simplify.
14
+
15
+ **Returns:** `{ foldedCount: number, newRoot: omdNode }`
16
+ - `foldedCount`: Number of simplifications applied.
17
+ - `newRoot`: The simplified expression tree (fresh clone if any simplifications occurred).
18
+
19
+ **Notes:**
20
+ - Limited to 50 iterations to prevent infinite loops.
21
+ - Preserves font size from the original node.
22
+ - Handles errors gracefully by returning the original node if an error occurs.
23
+
24
+ **Example:**
25
+ ```javascript
26
+ import { simplifyExpression } from './omd/simplification/omdSimplification.js';
27
+
28
+ const result = simplifyExpression(node);
29
+ console.log(result.newRoot.toString());
30
+ console.log(`Applied ${result.foldedCount} simplifications`);
31
+ ```
32
+
33
+
34
+ ### `simplifyStep(rootNode)`
35
+
36
+ Applies a single simplification step to the expression tree.
37
+
38
+ **Parameters:**
39
+ - `rootNode` (`omdNode`): The root node of the expression.
40
+
41
+ **Returns:** `{ foldedCount: number, newRoot: omdNode, historyEntry: object|null }`
42
+ - `foldedCount`: 1 if a simplification was applied, 0 otherwise.
43
+ - `newRoot`: The expression tree after applying the step.
44
+ - `historyEntry`: Object describing the applied simplification, or `null` if none.
45
+
46
+ **Notes:**
47
+ - Only applies the first matching rule found.
48
+ - Preserves font size from the original node.
49
+ - Handles errors gracefully by returning the original node if an error occurs.
50
+
51
+ **Example:**
52
+ ```javascript
53
+ import { simplifyStep } from './omd/simplification/omdSimplification.js';
54
+
55
+ const stepResult = simplifyStep(node);
56
+ if (stepResult.historyEntry) {
57
+ console.log('Applied:', stepResult.historyEntry);
58
+ }
59
+ ```
60
+
61
+
62
+ ### `findSimplificationOpportunities(rootNode)`
63
+
64
+ Finds all possible simplification opportunities in an expression tree.
65
+
66
+ **Parameters:**
67
+ - `rootNode` (`omdNode`): The root node to search.
68
+
69
+ **Returns:** `Array<{ node: omdNode, rule: object, ruleData: object }>`
70
+ - `node`: The node where a rule can be applied.
71
+ - `rule`: The applicable rule.
72
+ - `ruleData`: Data needed to apply the rule.
73
+
74
+ **Notes:**
75
+ - Uses depth-first traversal.
76
+ - Skips already visited nodes.
77
+ - Only checks rules relevant to each node type.
78
+ - Stops after finding the first applicable rule for each node.
79
+
80
+
81
+ ### Debug Functions
82
+
83
+ > **Note:** The following functions are intended for development and debugging, not for production use.
84
+
85
+ #### `getAvailableRulesForNode(node)`
86
+
87
+ Lists all rules that could potentially apply to a node.
88
+
89
+ **Parameters:**
90
+ - `node` (`omdNode`): The node to check.
91
+
92
+ **Returns:** `Array<string>` - Array of rule names.
93
+
94
+ #### `getApplicableRulesForNode(node)`
95
+
96
+ Lists rules that can actually be applied to a node.
97
+
98
+ **Parameters:**
99
+ - `node` (`omdNode`): The node to check.
100
+
101
+ **Returns:** `Array<string>` - Array of applicable rule names.
102
+
103
+ **Notes:**
104
+ - Handles errors gracefully by skipping failed rule checks.
105
+
106
+ ## See Also
107
+
108
+ - [Simplification Rules](./simplificationRules.md)
109
+ - [Simplification Engine](./simplificationEngine.md)
110
+ - [Configuration Options](./configuration-options.md)
@@ -0,0 +1,79 @@
1
+ # omdSqrtNode
2
+
3
+ Represents a square root node in the mathematical expression tree. Handles rendering of the radical symbol and the expression under the root.
4
+
5
+ ## Class: `omdSqrtNode extends omdNode`
6
+
7
+ ```js
8
+ import { omdSqrtNode } from './omd/nodes/omdSqrtNode.js';
9
+ ```
10
+
11
+ ### Constructor
12
+
13
+ ```js
14
+ new omdSqrtNode(astNodeData)
15
+ ```
16
+ - `astNodeData` {Object}: Math.js AST node with a single argument (the radicand)
17
+
18
+ ### Properties
19
+
20
+ Inherits all properties from [omdNode](./omdNode.md), plus:
21
+
22
+ - `argument` (`omdNode`): The radicand node (expression under the root)
23
+ - `value` (`string`): Always "sqrt"
24
+ - `radicalPath` (`jsvgPath`): The radical symbol (√)
25
+ - `radicalLine` (`jsvgLine`): The horizontal line above the radicand
26
+
27
+ ### Methods
28
+
29
+ Inherits all methods from [omdNode](./omdNode.md), plus:
30
+
31
+ - `toString()`: Returns string representation, e.g. `sqrt(x+1)`
32
+ - `toMathJSNode()`: Converts to a math.js-compatible AST node
33
+ - `evaluate(variables)`: Evaluates the square root numerically
34
+ - `variables` {Object}: Variable name to value mapping
35
+ - **Returns:** `number` (or `NaN` if radicand can't be evaluated)
36
+ - `simplify()`: Attempts to simplify the expression (delegates to central simplification engine)
37
+ - **Returns:** `{ success, newRoot, message }`
38
+ - `clone()`: Deep clone of the node
39
+ - `highlightAll()`, `unhighlightAll()`: Recursively highlight/unhighlight this node and its argument
40
+ - `toPowerForm()`: Returns an equivalent `omdPowerNode` (x^(1/2)), or `null` if no argument
41
+
42
+ #### Static Methods
43
+
44
+ - `fromString(expressionString)`: Create a sqrt node from a string (must be a sqrt function)
45
+ - `expressionString` {string}
46
+ - **Returns:** `omdSqrtNode`
47
+ - **Throws:** Error if not a sqrt function or if math.js is not available
48
+
49
+ ### Example
50
+
51
+ ```js
52
+ import { omdSqrtNode } from './omd/nodes/omdSqrtNode.js';
53
+
54
+ // Create from AST
55
+ const node = new omdSqrtNode({
56
+ type: 'FunctionNode',
57
+ fn: { name: 'sqrt' },
58
+ args: [ { type: 'SymbolNode', name: 'x' } ]
59
+ });
60
+
61
+ // Or from string (if static method is available)
62
+ const node2 = omdSqrtNode.fromString('sqrt(x+1)');
63
+
64
+ // Render and layout
65
+ node.setFontSize(24);
66
+ node.computeDimensions();
67
+ node.updateLayout();
68
+
69
+ // Evaluate
70
+ const val = node.evaluate({ x: 9 }); // 3
71
+
72
+ // Convert to power form
73
+ const powerNode = node.toPowerForm(); // x^(1/2)
74
+ ```
75
+
76
+ ### See Also
77
+ - [omdNode](./omdNode.md) — Parent class
78
+ - [omdPowerNode](./omdPowerNode.md) — For power form (x^(1/2))
79
+ - [omdFunctionNode](./omdFunctionNode.md) — For other functions