@teachinglab/omd 0.5.7 → 0.5.8

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 (59) hide show
  1. package/index.js +3 -0
  2. package/npm-docs/DOCUMENTATION_SUMMARY.md +220 -0
  3. package/npm-docs/README.md +251 -0
  4. package/npm-docs/api/api-reference.md +85 -0
  5. package/npm-docs/api/configuration-options.md +198 -0
  6. package/npm-docs/api/eventManager.md +83 -0
  7. package/npm-docs/api/expression-nodes.md +561 -0
  8. package/npm-docs/api/focusFrameManager.md +145 -0
  9. package/npm-docs/api/index.md +106 -0
  10. package/npm-docs/api/main.md +63 -0
  11. package/npm-docs/api/omdBinaryExpressionNode.md +86 -0
  12. package/npm-docs/api/omdCanvas.md +84 -0
  13. package/npm-docs/api/omdConfigManager.md +113 -0
  14. package/npm-docs/api/omdConstantNode.md +53 -0
  15. package/npm-docs/api/omdDisplay.md +87 -0
  16. package/npm-docs/api/omdEquationNode.md +174 -0
  17. package/npm-docs/api/omdEquationSequenceNode.md +259 -0
  18. package/npm-docs/api/omdEquationStack.md +193 -0
  19. package/npm-docs/api/omdFunctionNode.md +83 -0
  20. package/npm-docs/api/omdGroupNode.md +79 -0
  21. package/npm-docs/api/omdHelpers.md +88 -0
  22. package/npm-docs/api/omdLeafNode.md +86 -0
  23. package/npm-docs/api/omdNode.md +202 -0
  24. package/npm-docs/api/omdOperationDisplayNode.md +118 -0
  25. package/npm-docs/api/omdOperatorNode.md +92 -0
  26. package/npm-docs/api/omdParenthesisNode.md +134 -0
  27. package/npm-docs/api/omdPopup.md +192 -0
  28. package/npm-docs/api/omdPowerNode.md +132 -0
  29. package/npm-docs/api/omdRationalNode.md +145 -0
  30. package/npm-docs/api/omdSequenceNode.md +128 -0
  31. package/npm-docs/api/omdSimplification.md +79 -0
  32. package/npm-docs/api/omdSqrtNode.md +144 -0
  33. package/npm-docs/api/omdStepVisualizer.md +147 -0
  34. package/npm-docs/api/omdStepVisualizerHighlighting.md +66 -0
  35. package/npm-docs/api/omdStepVisualizerInteractiveSteps.md +109 -0
  36. package/npm-docs/api/omdStepVisualizerLayout.md +71 -0
  37. package/npm-docs/api/omdStepVisualizerNodeUtils.md +140 -0
  38. package/npm-docs/api/omdStepVisualizerTextBoxes.md +77 -0
  39. package/npm-docs/api/omdToolbar.md +131 -0
  40. package/npm-docs/api/omdTranscriptionService.md +96 -0
  41. package/npm-docs/api/omdTreeDiff.md +170 -0
  42. package/npm-docs/api/omdUnaryExpressionNode.md +137 -0
  43. package/npm-docs/api/omdUtilities.md +83 -0
  44. package/npm-docs/api/omdVariableNode.md +123 -0
  45. package/npm-docs/api/selectTool.md +74 -0
  46. package/npm-docs/api/simplificationEngine.md +98 -0
  47. package/npm-docs/api/simplificationRules.md +77 -0
  48. package/npm-docs/api/simplificationUtils.md +64 -0
  49. package/npm-docs/api/transcribe.md +43 -0
  50. package/npm-docs/guides/equations.md +854 -0
  51. package/npm-docs/guides/factory-functions.md +354 -0
  52. package/npm-docs/guides/getting-started.md +318 -0
  53. package/npm-docs/guides/quick-examples.md +525 -0
  54. package/npm-docs/guides/visualizations.md +682 -0
  55. package/npm-docs/json-schemas.md +826 -0
  56. package/omd/utils/omdTranscriptionService.js +1 -1
  57. package/package.json +2 -1
  58. package/src/index.js +2 -0
  59. package/src/omdFactory.js +150 -0
@@ -0,0 +1,66 @@
1
+ # omdStepVisualizerHighlighting
2
+
3
+ Manages the highlighting of nodes within mathematical expressions displayed by the `omdStepVisualizer`. It uses a robust tree differencing algorithm to identify changes between consecutive steps and highlights affected nodes, providing visual feedback on transformations.
4
+
5
+ ## Class Definition
6
+
7
+ ```javascript
8
+ export class omdStepVisualizerHighlighting
9
+ ```
10
+
11
+ ## Constructor
12
+
13
+ ### `new omdStepVisualizerHighlighting(stepVisualizer)`
14
+
15
+ Creates a new `omdStepVisualizerHighlighting` instance.
16
+
17
+ - **`stepVisualizer`** (`omdStepVisualizer`): The step visualizer instance this highlighting manager is associated with.
18
+
19
+ During construction, it initializes a `Set` to track `highlightedNodes` and sets `educationalMode` to `true` by default.
20
+
21
+ ## Public Properties
22
+
23
+ - **`stepVisualizer`** (`omdStepVisualizer`): The associated step visualizer instance.
24
+ - **`highlightedNodes`** (`Set<omdNode>`): A set of `omdNode` instances that are currently highlighted by this manager.
25
+ - **`educationalMode`** (`boolean`): If `true`, enables highlighting of pedagogical simplifications (e.g., intermediate steps that might be skipped in a final solution). Default: `true`.
26
+
27
+ ## Public Methods
28
+
29
+ ### `highlightAffectedNodes(dotIndex, isOperation = false)`
30
+
31
+ This is the main method to trigger highlighting. It compares the equation at `dotIndex` with the previous visible equation in the sequence to identify changes and then applies appropriate highlighting.
32
+
33
+ - **`dotIndex`** (`number`): The index of the dot (step) for which to highlight affected nodes.
34
+ - **`isOperation`** (`boolean`, optional): If `true`, indicates that the step is an operation (e.g., adding to both sides), which affects how provenance is highlighted. Default: `false`.
35
+
36
+ **How it Works:**
37
+
38
+ 1. **Clear Existing Highlights**: First, any previously active highlights are cleared.
39
+ 2. **Identify Equations**: It determines the `currentEquation` (associated with `dotIndex`) and finds the `previousEquation` (the nearest visible equation before the current one).
40
+ 3. **Tree Differencing**: It uses `omdTreeDiff.findChangedNodes` to perform a robust comparison between the `previousEquation` and `currentEquation`. This algorithm identifies nodes that have been added, removed, or modified.
41
+ 4. **Direct Highlighting**: Nodes identified as directly changed by the diff algorithm are highlighted with a primary explanation color (`omdColor.explainColor`).
42
+ 5. **Provenance Highlighting**: For non-operation steps, the system traces the `provenance` (history) of the directly changed nodes back to their origins in the `previousEquation`. These originating nodes are then highlighted with a secondary provenance color (`omdColor.provenanceColor`), visually connecting the transformation.
43
+
44
+ ### `clearHighlights()`
45
+
46
+ Removes all active highlights managed by this class from the expression tree. It iterates through all `highlightedNodes` and calls `setExplainHighlight(false)` on them, then clears its internal `highlightedNodes` set.
47
+
48
+ ## Internal Methods
49
+
50
+ - **`_highlightNode(node)`**: Applies the standard explanation highlight color (`omdColor.explainColor`) to a single `omdNode` by calling its `setExplainHighlight(true)` method and adds the node to `highlightedNodes`.
51
+ - **`_findNearestVisibleEquationAbove(currentIndex)`**: Searches backward from `currentIndex` in the `stepVisualizer.steps` array to find the closest `omdEquationNode` that is currently visible.
52
+ - **`_highlightProvenanceNodes(changedNodes, previousEquation)`**: Iterates through `changedNodes` and their `provenance` chains to identify and highlight corresponding nodes in the `previousEquation` with `omdColor.provenanceColor`. It uses `rootNode.nodeMap` for efficient node lookup and a `visited` set to prevent redundant processing.
53
+ - **`_belongsToEquation(node, targetEquation)`**: Checks if a given `omdNode` is part of the subtree of a `targetEquation` by traversing up its parent chain.
54
+ - **`_highlightProvenanceNode(node)`**: Applies the secondary provenance highlighting style (`omdColor.provenanceColor`) to a single `omdNode` by calling its `setExplainHighlight(true, omdColor.provenanceColor)` method.
55
+
56
+ ## Example
57
+
58
+ This class is typically used internally by `omdStepVisualizer` when a step dot is clicked:
59
+
60
+ ```javascript
61
+ // Inside omdStepVisualizer's _handleDotClick method:
62
+ this.highlighting.highlightAffectedNodes(dotIndex, isOperation);
63
+
64
+ // Inside omdStepVisualizer's _clearActiveDot method:
65
+ this.highlighting.clearHighlights();
66
+ ```
@@ -0,0 +1,109 @@
1
+ # omdStepVisualizerInteractiveSteps
2
+
3
+ This class creates and manages the interactive text boxes that display detailed explanations for simplification steps within the `omdStepVisualizer`. It formats the messages, handles styling, and sets up hover and click interactions, allowing users to explore the mathematical transformations.
4
+
5
+ ## Class Definition
6
+
7
+ ```javascript
8
+ export class omdStepVisualizerInteractiveSteps
9
+ ```
10
+
11
+ ## Constructor
12
+
13
+ ### `new omdStepVisualizerInteractiveSteps(stepVisualizer, simplificationData)`
14
+
15
+ Creates a new `omdStepVisualizerInteractiveSteps` instance.
16
+
17
+ - **`stepVisualizer`** (`omdStepVisualizer`): A reference to the `omdStepVisualizer` instance this component is associated with.
18
+ - **`simplificationData`** (`object`): An object containing the simplification details for the step, typically including `message`, `rawMessages`, `ruleNames`, and potentially `operationValueNode`.
19
+
20
+ During construction, it extracts and cleans messages and rule names from the `simplificationData`, initializes layout properties (like `stepWidth`, `fontSize`), sets up the main `layoutGroup`, and creates the individual step elements.
21
+
22
+ ## Public Properties
23
+
24
+ - **`stepVisualizer`** (`omdStepVisualizer`): A reference to the associated `omdStepVisualizer` instance.
25
+ - **`simplificationData`** (`object`): The raw data describing the simplification step.
26
+ - **`messages`** (`Array<string>`): Cleaned and extracted messages for each sub-step.
27
+ - **`ruleNames`** (`Array<string>`): Extracted names of the simplification rules applied.
28
+ - **`stepElements`** (`Array<jsvgTextBox>`): An array of `jsvgTextBox` instances, each representing a line of explanation.
29
+ - **`layoutGroup`** (`jsvgLayoutGroup`): The main `jsvgLayoutGroup` that contains all the visual elements of the interactive steps, including the background and individual step messages.
30
+ - **`stepWidth`** (`number`): The fixed width for each step explanation box.
31
+ - **`baseStepHeight`** (`number`): The minimum height for a single step explanation box.
32
+ - **`headerHeight`** (`number`): The height reserved for the header text box.
33
+ - **`fontSize`** (`number`): The base font size for the explanation text.
34
+ - **`smallFontSize`** (`number`): A smaller font size used for secondary text (e.g., step numbers).
35
+ - **`backgroundRect`** (`jsvgRect`): The background rectangle for the entire group of interactive steps.
36
+ - **`contentGroup`** (`jsvgLayoutGroup`): An internal layout group that holds the header and individual step messages.
37
+ - **`onStepHover`** (`Function`): Callback function for hover events on step explanations.
38
+ - **`onStepClick`** (`Function`): Callback function for click events on step explanations.
39
+
40
+ ## Public Methods
41
+
42
+ ### `setOnStepHover(callback)`
43
+
44
+ Sets a callback function to be executed when the user hovers over a step explanation.
45
+
46
+ - **`callback`** (`Function`): A function that receives `(stepIndex, message, isEntering)` as arguments.
47
+
48
+ ### `setOnStepClick(callback)`
49
+
50
+ Sets a callback function to be executed when the user clicks on a step explanation.
51
+
52
+ - **`callback`** (`Function`): A function that receives `(stepIndex, message)` as arguments.
53
+
54
+ ### `getLayoutGroup()`
55
+
56
+ Returns the main `jsvgLayoutGroup` containing all the interactive step elements. This group should be added to the parent container (e.g., `omdStepVisualizer`'s `visualContainer`).
57
+
58
+ - **Returns**: `jsvgLayoutGroup`.
59
+
60
+ ### `setPosition(x, y)`
61
+
62
+ Sets the position of the entire interactive step group within its parent container.
63
+
64
+ - **`x`** (`number`): The X-coordinate.
65
+ - **`y`** (`number`): The Y-coordinate.
66
+
67
+ ### `getDimensions()`
68
+
69
+ Returns the calculated width and height of the interactive step group, including its background.
70
+
71
+ - **Returns**: `object` - An object with `width` and `height` properties.
72
+
73
+ ### `destroy()`
74
+
75
+ Cleans up the component by removing all its children, clearing references, and unsetting callbacks.
76
+
77
+ ## Internal Methods
78
+
79
+ - **`_extractMessages(data)`**: Extracts and cleans messages from the `simplificationData`, removing HTML tags and bullet points.
80
+ - **`_extractRuleNames(data)`**: Extracts rule names from the `simplificationData`, providing default values if not present.
81
+ - **`setupLayoutGroup()`**: Initializes the main `layoutGroup` and creates its `backgroundRect`, setting initial styling.
82
+ - **`createStepElements()`**: Orchestrates the creation of individual step explanation elements. It decides whether to create a single step element or multiple, based on the number of messages.
83
+ - **`createSingleStepElement(message, index)`**: Creates a header and a single `jsvgTextBox` for a step explanation when there's only one message.
84
+ - **`createMultipleStepElements()`**: Creates a header and multiple `jsvgTextBox` elements for step explanations when there are multiple messages, optionally including step numbers.
85
+ - **`createHeaderBox(headerText)`**: Creates a styled `jsvgTextBox` to serve as a header for the explanation group.
86
+ - **`createStepTextBox(message, index, isMultiple)`**: Creates an individual styled `jsvgTextBox` for a step message, calculates its height, and stores relevant step data.
87
+ - **`formatStepContent(message, index, isMultiple)`**: Formats the raw message content into HTML, adding styling for step numbers, bullets, and highlighting operation details (action, value).
88
+ - **`applyStepStyling(stepBox, content, isMultiple)`**: Applies CSS styling to the `jsvgTextBox`'s underlying DOM element and sets its `innerHTML` with the formatted content.
89
+ - **`setupStepInteractions(stepBox)`**: Sets up `mouseenter`, `mouseleave`, and `click` event listeners for a step box, triggering hover and click callbacks.
90
+ - **`calculateStepHeight(message)`**: Dynamically calculates the required height for a step box based on its content, using a temporary DOM element for accurate measurement.
91
+ - **`updateBackgroundSize()`**: Adjusts the size of the `backgroundRect` to fit the dynamically calculated content height and width.
92
+ - **`isOperationMessage(message)`**: Checks if a message string indicates an operation (e.g., "Added X to both sides").
93
+ - **`extractOperationAction(message)`**: Extracts the action verb (e.g., "Added", "Subtracted") from an operation message.
94
+ - **`extractOperationValue(message)`**: Extracts the value (e.g., "3", "x") from an operation message.
95
+ - **`extractOperationValueNode(message)`**: Attempts to extract the `omdNode` representing the value from an operation message, if available in the `simplificationData`.
96
+
97
+ ## How it Works
98
+
99
+ This class takes simplification data and renders it as a series of interactive text boxes. Each box represents a sub-step or a part of the explanation. It dynamically calculates sizes and positions to ensure the text boxes are readable and visually appealing. Hover and click events on these boxes can be used to trigger further actions, such as highlighting specific nodes in the main equation display.
100
+
101
+ ## Example
102
+
103
+ This class is typically used internally by `omdStepVisualizerTextBoxes`.
104
+
105
+ ```javascript
106
+ // Example of internal usage within omdStepVisualizerTextBoxes:
107
+ // const interactiveSteps = new omdStepVisualizerInteractiveSteps(this.stepVisualizer, simplificationData);
108
+ // this.stepVisualizer.visualContainer.addChild(interactiveSteps.getLayoutGroup());
109
+ ```
@@ -0,0 +1,71 @@
1
+ # omdStepVisualizerLayout
2
+
3
+ Manages the visual layout, positioning, and visibility of elements within the `omdStepVisualizer`. It ensures that step dots, connecting lines, and associated text boxes are correctly positioned relative to the mathematical equations, maintaining a clean and interactive display.
4
+
5
+ ## Class Definition
6
+
7
+ ```javascript
8
+ export class omdStepVisualizerLayout
9
+ ```
10
+
11
+ ## Constructor
12
+
13
+ ### `new omdStepVisualizerLayout(stepVisualizer)`
14
+
15
+ Creates a new `omdStepVisualizerLayout` instance.
16
+
17
+ - **`stepVisualizer`** (`omdStepVisualizer`): A reference to the `omdStepVisualizer` instance this layout manager will control.
18
+
19
+ ## Public Properties
20
+
21
+ - **`stepVisualizer`** (`omdStepVisualizer`): The associated `omdStepVisualizer` instance.
22
+
23
+ ## Public Methods
24
+
25
+ ### `updateVisualLayout()`
26
+
27
+ Calculates and applies the positions of all visual elements (dots, lines, text boxes) relative to the mathematical equations in the sequence. It ensures proper alignment and spacing, accounting for factors like equation background padding and the dynamic size of text boxes.
28
+
29
+ ### `findDotIndexForEquation(equation)`
30
+
31
+ Finds the index of the step dot associated with a given `omdEquationNode` within the `stepVisualizer.stepDots` array.
32
+
33
+ - **`equation`** (`omdEquationNode`): The equation node to find the corresponding dot for.
34
+ - **Returns**: `number` - The 0-based index of the dot, or `-1` if not found.
35
+
36
+ ### `updateVisualZOrder()`
37
+
38
+ Manages the z-order (stacking order) of the visual elements to ensure they are rendered correctly. Lines are placed behind dots, and text boxes are placed on top of everything else.
39
+
40
+ ### `updateAllLinePositions()`
41
+
42
+ Recalculates and updates the start and end points of all connecting lines between the step dots. This ensures lines accurately connect the centers of the dots, even after layout changes.
43
+
44
+ ### `updateVisualVisibility()`
45
+
46
+ Adjusts the visibility of the step dots and lines based on the visibility of their corresponding equations. It also dynamically re-creates line segments only between currently visible dots, ensuring no lines are drawn to hidden steps.
47
+
48
+ ### `updateDotClickability(dot)`
49
+
50
+ Enables or disables the click functionality for a specific step dot. It sets the cursor style to `"pointer"` when clickable and `"default"` otherwise, and attaches/detaches the `onclick` event handler.
51
+
52
+ - **`dot`** (`jsvgEllipse`): The `jsvgEllipse` element representing the dot.
53
+
54
+ ## Internal Methods
55
+
56
+ - **`_getMaxEquationEffectivePaddingX()`**: Computes the maximum effective horizontal padding (x) among all visible `omdEquationNode` steps. This value is used to offset the visual tracker, preventing overlap with equation backgrounds.
57
+
58
+ ## How it Works
59
+
60
+ This class works in conjunction with `omdStepVisualizer` to dynamically arrange the visual components. When the sequence of equations changes (e.g., steps are added or hidden), `omdStepVisualizer` calls methods on this layout manager to re-calculate and apply the new visual arrangement.
61
+
62
+ ## Example
63
+
64
+ This class is primarily used internally by `omdStepVisualizer`:
65
+
66
+ ```javascript
67
+ // Inside omdStepVisualizer's updateLayout method:
68
+ this.layoutManager.updateVisualLayout();
69
+ this.layoutManager.updateVisualVisibility();
70
+ this.layoutManager.updateAllLinePositions();
71
+ ```
@@ -0,0 +1,140 @@
1
+ # omdStepVisualizerNodeUtils
2
+
3
+ This module provides a collection of utility functions specifically designed to assist with node operations and analysis within the context of step visualizations, particularly for identifying and extracting information from `omdNode` instances.
4
+
5
+ ## Class: `omdStepVisualizerNodeUtils`
6
+
7
+ This class is not meant to be instantiated. All its methods are static.
8
+
9
+ ### Static Methods
10
+
11
+ #### `isLeafNode(node)`
12
+
13
+ Checks if a given `omdNode` is a leaf node (e.g., `omdConstantNode`, `omdVariableNode`, `omdOperatorNode`).
14
+
15
+ - **Parameters:**
16
+ - `node` {omdNode} - The node to check.
17
+ - **Returns:** {boolean} `true` if the node is a leaf node, `false` otherwise.
18
+
19
+ ---
20
+
21
+ #### `isBinaryNode(node)`
22
+
23
+ Checks if a given `omdNode` is an `omdBinaryExpressionNode` and has both `left` and `right` children.
24
+
25
+ - **Parameters:**
26
+ - `node` {omdNode} - The node to check.
27
+ - **Returns:** {boolean} `true` if it's a binary node, `false` otherwise.
28
+
29
+ ---
30
+
31
+ #### `isUnaryNode(node)`
32
+
33
+ Checks if a given `omdNode` is an `omdUnaryExpressionNode` and has an `argument` child.
34
+
35
+ - **Parameters:**
36
+ - `node` {omdNode} - The node to check.
37
+ - **Returns:** {boolean} `true` if it's a unary node, `false` otherwise.
38
+
39
+ ---
40
+
41
+ #### `hasExpression(node)`
42
+
43
+ Checks if a given `omdNode` has an `expression` property (common in nodes like `omdParenthesisNode`).
44
+
45
+ - **Parameters:**
46
+ - `node` {omdNode} - The node to check.
47
+ - **Returns:** {boolean} `true` if it has an expression property, `false` otherwise.
48
+
49
+ ---
50
+
51
+ #### `getNodeValue(node)`
52
+
53
+ Attempts to retrieve a string representation of the node's value. This is particularly useful for leaf nodes (constants, variables) but can also provide a string for more complex nodes.
54
+
55
+ - **Parameters:**
56
+ - `node` {omdNode} - The node to get the value from.
57
+ - **Returns:** {string} The string representation of the node's value.
58
+
59
+ ---
60
+
61
+ #### `findLeafNodes(node)`
62
+
63
+ Recursively finds all leaf nodes within the subtree rooted at the given node.
64
+
65
+ - **Parameters:**
66
+ - `node` {omdNode} - The root node to start the search from.
67
+ - **Returns:** {Array<omdNode>} An array of `omdNode` instances that are leaf nodes.
68
+
69
+ ---
70
+
71
+ #### `findVariableNodes(node)`
72
+
73
+ Finds all `omdVariableNode` instances within the subtree rooted at the given node.
74
+
75
+ - **Parameters:**
76
+ - `node` {omdNode} - The root node to start the search from.
77
+ - **Returns:** {Array<omdVariableNode>} An array of `omdVariableNode` instances.
78
+
79
+ ---
80
+
81
+ #### `findConstantNodes(node)`
82
+
83
+ Finds all `omdConstantNode` instances within the subtree rooted at the given node.
84
+
85
+ - **Parameters:**
86
+ - `node` {omdNode} - The root node to start the search from.
87
+ - **Returns:** {Array<omdConstantNode>} An array of `omdConstantNode` instances.
88
+
89
+ ---
90
+
91
+ #### `findLeafNodesWithValue(node, value)`
92
+
93
+ Finds leaf nodes within a subtree that match a specific string `value`. It performs exact matches first, then numeric matches for constants, and finally partial string matches.
94
+
95
+ - **Parameters:**
96
+ - `node` {omdNode} - The root node to start the search from.
97
+ - `value` {string} - The value to search for.
98
+ - **Returns:** {Array<omdNode>} An array of matching leaf nodes.
99
+
100
+ ---
101
+
102
+ #### `findAllNodes(node)`
103
+
104
+ Recursively finds all `omdNode` instances (including non-leaf nodes) within the subtree rooted at the given node.
105
+
106
+ - **Parameters:**
107
+ - `node` {omdNode} - The root node to start the search from.
108
+ - **Returns:** {Array<omdNode>} An array of all `omdNode` instances in the tree.
109
+
110
+ ---
111
+
112
+ #### `findRightmostNodeWithValue(node, value)`
113
+
114
+ Finds the rightmost leaf node within a subtree that matches a specific `value`. It has special handling for nodes that are the right operand of a subtraction.
115
+
116
+ - **Parameters:**
117
+ - `node` {omdNode} - The root node to start the search from.
118
+ - `value` {string} - The value to search for.
119
+ - **Returns:** {omdNode | null} The rightmost matching leaf node, or `null` if not found.
120
+
121
+ ### Example
122
+
123
+ ```javascript
124
+ import { omdStepVisualizerNodeUtils } from './omd/utils/omdStepVisualizerNodeUtils.js';
125
+ import { omdEquationNode } from './omd/nodes/omdEquationNode.js';
126
+
127
+ const equation = omdEquationNode.fromString('2x + 3 = 7');
128
+
129
+ // Find all leaf nodes
130
+ const leafNodes = omdStepVisualizerNodeUtils.findLeafNodes(equation);
131
+ console.log(leafNodes.map(node => node.toString())); // Output: ['2', 'x', '3', '7']
132
+
133
+ // Find all constant nodes
134
+ const constantNodes = omdStepVisualizerNodeUtils.findConstantNodes(equation);
135
+ console.log(constantNodes.map(node => node.getValue())); // Output: [2, 3, 7]
136
+
137
+ // Get the value of a specific node
138
+ const firstLeaf = leafNodes[0];
139
+ console.log(omdStepVisualizerNodeUtils.getNodeValue(firstLeaf)); // Output: '2'
140
+ ```
@@ -0,0 +1,77 @@
1
+ # omdStepVisualizerTextBoxes
2
+
3
+ Manages the interactive text boxes that appear when a step dot is clicked in the `omdStepVisualizer`. This class handles the creation, positioning, and removal of these explanation popups, and integrates with highlighting and layout managers for a cohesive user experience.
4
+
5
+ ## Class Definition
6
+
7
+ ```javascript
8
+ export class omdStepVisualizerTextBoxes
9
+ ```
10
+
11
+ ## Constructor
12
+
13
+ ### `new omdStepVisualizerTextBoxes(stepVisualizer, highlighting)`
14
+
15
+ Creates a new `omdStepVisualizerTextBoxes` instance.
16
+
17
+ - **`stepVisualizer`** (`omdStepVisualizer`): A reference to the `omdStepVisualizer` instance.
18
+ - **`highlighting`** (`omdStepVisualizerHighlighting`): A reference to the highlighting manager.
19
+
20
+ During construction, it initializes the `stepTextBoxes` array, which will store references to active text boxes.
21
+
22
+ ## Public Properties
23
+
24
+ - **`stepVisualizer`** (`omdStepVisualizer`): The associated step visualizer instance.
25
+ - **`highlighting`** (`omdStepVisualizerHighlighting`): The associated highlighting instance.
26
+ - **`stepTextBoxes`** (`Array<object>`): An array of objects, each representing an active text box. Each object contains `dotIndex`, `interactiveSteps` (the `omdStepVisualizerInteractiveSteps` instance), and `layoutGroup` (its `jsvgLayoutGroup`).
27
+
28
+ ## Public Methods
29
+
30
+ ### `createTextBoxForDot(dotIndex)`
31
+
32
+ Creates and displays an interactive text box for the specified step dot. This involves retrieving simplification data, finding the appropriate positioning reference, and then creating and adding the `omdStepVisualizerInteractiveSteps` component to the visualizer's container.
33
+
34
+ - **`dotIndex`** (`number`): The index of the dot for which to create the text box.
35
+
36
+ ### `removeTextBoxForDot(dotIndex)`
37
+
38
+ Removes the text box associated with the specified step dot. It destroys the `omdStepVisualizerInteractiveSteps` instance and removes its `layoutGroup` from the visual container, then triggers a layout update.
39
+
40
+ - **`dotIndex`** (`number`): The index of the dot whose text box should be removed.
41
+
42
+ ### `clearAllTextBoxes()`
43
+
44
+ Removes all active text boxes from the visualizer. It iterates through all tracked text boxes, destroys their `interactiveSteps` instances, removes their `layoutGroup`s from the visual container, and then clears the `stepTextBoxes` array. A layout update is triggered afterwards.
45
+
46
+ ### `getStepTextBoxes()`
47
+
48
+ Returns an array of all currently active text box objects managed by this class.
49
+
50
+ - **Returns**: `Array<object>`.
51
+
52
+ ## Internal Methods
53
+
54
+ - **`_createInteractiveStepsForDot(dotIndex, targetDot, simplificationData)`**: Creates and configures an `omdStepVisualizerInteractiveSteps` instance. It positions the text box relative to the `targetDot`, sets up hover and click interactions, and adds the text box's `layoutGroup` to the `stepVisualizer.visualContainer`.
55
+ - **`_findDotAboveForPositioning(dotIndex)`**: Determines the appropriate `omdEquationNode` (and its corresponding dot) to position the text box relative to. It searches for the nearest visible equation above the clicked dot, falling back to the clicked dot itself if no such equation is found.
56
+ - **`_getSimplificationDataForDot(dotIndex)`**: Retrieves the simplification data for a given dot by delegating the call to the `stepVisualizer`'s internal method (`stepVisualizer._getSimplificationDataForDot`).
57
+
58
+ ## How it Works
59
+
60
+ When a user clicks a step dot in the `omdStepVisualizer`, this class:
61
+
62
+ 1. **Fetches Data**: Requests simplification data from the step visualizer for the clicked step.
63
+ 2. **Creates UI**: Instantiates an `omdStepVisualizerInteractiveSteps` component, which renders the explanation text and interactive elements.
64
+ 3. **Positions**: Calculates the optimal position for the text box, usually to the right of the step dot, and ensures it doesn't overlap with other elements.
65
+ 4. **Highlighting Integration**: Works with `omdStepVisualizerHighlighting` to trigger visual feedback when the text box is displayed or interacted with.
66
+
67
+ ## Example
68
+
69
+ This class is primarily used internally by `omdStepVisualizer`:
70
+
71
+ ```javascript
72
+ // Inside omdStepVisualizer's _handleDotClick method:
73
+ this.textBoxManager.createTextBoxForDot(dotIndex);
74
+
75
+ // Inside omdStepVisualizer's _clearActiveDot method:
76
+ this.textBoxManager.removeTextBoxForDot(this.activeDotIndex);
77
+ ```
@@ -0,0 +1,131 @@
1
+ # omdToolbar
2
+
3
+ Provides a visual toolbar UI for applying mathematical operations and functions to an `omdEquationSequenceNode` in the OMD system. The toolbar is rendered as an SVG group and supports operations like add, subtract, multiply, divide, and function application (e.g., sqrt, cos, etc.). It features dynamic popups for selecting operations and inputting values.
4
+
5
+ ## Class Definition
6
+
7
+ ```javascript
8
+ export class omdToolbar
9
+ ```
10
+
11
+ ## Constructor
12
+
13
+ ### `new omdToolbar(parentContainer, sequence, [options])`
14
+
15
+ Creates an instance of the `omdToolbar`.
16
+
17
+ - **`parentContainer`** (`jsvgGroup`): The parent SVG group where the toolbar will be rendered.
18
+ - **`sequence`** (`omdEquationSequenceNode`): The sequence node to which operations will be applied.
19
+ - **`options`** (`object`, optional): Toolbar configuration options:
20
+ - `height` (`number`): Toolbar height. Default: `60`.
21
+ - `padding` (`number`): Padding around elements. Default: `6`.
22
+ - `spacing` (`number`): Spacing between elements. Default: `8`.
23
+ - `borderRadius` (`number`): Corner radius for background. Default: `30`.
24
+ - `fontFamily` (`string`): Font family. Default: `'Albert Sans', sans-serif`.
25
+ - `fontWeight` (`string`): Font weight. Default: `'500'`.
26
+ - `colors` (`object`): Color scheme:
27
+ - `background` (`string`): Toolbar background. Default: `omdColor.mediumGray`.
28
+ - `button` (`string`): Button background. Default: `'white'`.
29
+ - `popup` (`string`): Popup menu background. Default: `omdColor.lightGray`.
30
+ - `undo` (`string`): Undo button background. Default: `#87D143`.
31
+ - `buttonSize` (`number`): Button size. Default: `48`.
32
+ - `checkMarkSize` (`number`): Checkmark SVG size. Default: `24`.
33
+ - `mainFontSize` (`number`): Main button font size. Default: `32`.
34
+ - `inputFontSize` (`number`): Input text font size. Default: `28`.
35
+ - `menuFontSize` (`number`): Menu item font size. Default: `24`.
36
+ - `inputWidth` (`number`): Input button width. Default: `120`.
37
+ - `popupDirection` (`string`): Direction for popups (`'below'` or `'above'`). Default: `'below'`.
38
+ - `showUndoButton` (`boolean`): Whether to display an undo button. Default: `false`.
39
+ - `undoIconUrl` (`string`): Data URL for the undo button icon. Default: a base64 encoded SVG.
40
+ - `onUndo` (`function`): Custom callback function for the undo action. If not provided, it attempts to call `window.onOMDToolbarUndo`.
41
+ - `x`, `y` (`number`): Optional position of the toolbar in the parent container.
42
+ - `styles` (`object`): An object to provide structured styling options (e.g., `backgroundColor`, `buttonColor`, `popupBackgroundColor`, `borderRadius`, `buttonSize`, `mainFontSize`, `inputFontSize`, `menuFontSize`, `inputWidth`, `padding`, `spacing`). These override individual options.
43
+
44
+ ## Public Properties
45
+
46
+ - **`parentContainer`** (`jsvgGroup`): The SVG group where the toolbar is rendered.
47
+ - **`sequence`** (`omdEquationSequenceNode`): The sequence node the toolbar interacts with.
48
+ - **`config`** (`object`): The merged configuration options for the toolbar, including defaults and overrides.
49
+ - **`state`** (`object`): Internal state of the toolbar, including:
50
+ - `activePopup` (`object` | `null`): Tracks the currently active popup (`type`, `group`).
51
+ - `selectedOperation` (`string`): The currently selected operation (e.g., `'+'`, `'f'`).
52
+ - `inputValue` (`string`): The current value in the input field.
53
+ - **`elements`** (`object`): An object containing references to the various `jsvg` elements that make up the toolbar UI:
54
+ - `toolbarGroup` (`jsvgGroup`): The main SVG group for the entire toolbar.
55
+ - `background` (`jsvgRect`): The background rectangle of the toolbar.
56
+ - `leftButton` (`jsvgButton`): The button for selecting operations.
57
+ - `middleInputButton` (`jsvgButton`): The button for displaying and inputting values.
58
+ - `rightButton` (`jsvgButton`): The button for applying the operation.
59
+ - `undoButton` (`jsvgButton`): The optional undo button.
60
+
61
+ ## Public Methods
62
+
63
+ ### `setInputText(text)`
64
+
65
+ Sets the text displayed in the middle input button and updates the internal `inputValue` state. It also adjusts the font size of the button's text element for better centering.
66
+
67
+ - **`text`** (`string`): The text to display.
68
+
69
+ ### `destroy()`
70
+
71
+ Cleans up the toolbar component by removing its SVG elements from the DOM and clearing internal references.
72
+
73
+ ## Internal Methods
74
+
75
+ - **`_render()`**: Renders the initial toolbar UI components, including the background, operation button, input button, apply button, and optional undo button. It also sets up their initial positions and styling.
76
+ - **`_bringToFront(node)`**: Moves a `jsvgObject` to the top of its parent's stacking order to ensure it's visible.
77
+ - **`_togglePopup(popupType)`**: Toggles the visibility of a popup menu (either `'operations'` or `'input'`). It ensures only one popup is visible at a time and handles attaching/detaching the popup's SVG group to the toolbar's group.
78
+ - **`_renderPopup(contentFactory, anchorButton)`**: A generic method to create and position a popup group. It takes a `contentFactory` function (which generates the popup's content) and an `anchorButton` to position the popup relative to.
79
+ - **`_renderOperationsMenu()`**: Renders the operations menu popup, containing buttons for `'f'` (function), `'÷'`, `'×'`, `'–'`, and `'+'`.
80
+ - **`_renderFunctionMenu()`**: Renders the function selection menu popup, containing buttons for common functions like `'sqrt'`, `'cos'`, `'sin'`, `'tan'`, and `'ln'`.
81
+ - **`_renderDigitGrid()`**: Renders the digit grid (number pad) popup, including digits `0-9`, a backspace (`'←'`), and a variable (`'x'`).
82
+ - **`_handleFunctionClick(func)`**: Handles clicks on the function menu buttons, setting the input text to the selected function name.
83
+ - **`_handleDigitClick(digit)`**: Handles clicks on the digit grid buttons, updating the input value (appending digits or performing backspace).
84
+ - **`_selectOperation(operation)`**: Handles the selection of a new operation from the menu, updating the left button's text and potentially clearing the input text if switching to/from function mode.
85
+ - **`_applyOperation()`**: Applies the selected operation and value to the `sequence`. It parses the input value (as a number or math.js expression) and calls the appropriate method on the `sequence` (e.g., `applyEquationFunction`, `applyEquationOperation`). It also clears the input and notifies the host application to refresh the display.
86
+ - **`_createButton(config)`**: A factory method for creating `jsvgButton` instances with common styling and behavior. It supports text labels, SVG icons, and custom sizes.
87
+ - **`_updateApplyButtonState()`**: Updates the enabled/disabled state of the apply button based on whether there is an `inputValue`.
88
+ - **`_updateToolbarLayout()`**: Updates the positions of all toolbar elements (buttons, background) to ensure correct spacing and alignment.
89
+ - **`_handleUndo()`**: Handles the undo action, either by calling a custom `onUndo` callback or a global `window.onOMDToolbarUndo` hook.
90
+
91
+ ## Example
92
+
93
+ ```javascript
94
+ import { omdToolbar } from '@teachinglab/omd';
95
+ import { omdEquationSequenceNode } from '@teachinglab/omd';
96
+ import { omdEquationNode } from '@teachinglab/omd';
97
+
98
+ // Create an SVG container (e.g., from jsvgContainer)
99
+ // const svgContainer = new jsvgContainer();
100
+ // document.body.appendChild(svgContainer.svgObject);
101
+
102
+ // Create an initial sequence
103
+ const initialEquation = omdEquationNode.fromString('2x + 5 = 15');
104
+ const sequence = new omdEquationSequenceNode([initialEquation]);
105
+
106
+ // Create the toolbar and add it to the SVG container
107
+ const toolbar = new omdToolbar(svgContainer, sequence, {
108
+ x: 50, // Position the toolbar
109
+ y: 50,
110
+ showUndoButton: true, // Enable the undo button
111
+ styles: { // Example of structured styling
112
+ backgroundColor: '#34495e',
113
+ buttonColor: '#ecf0f1',
114
+ popupBackgroundColor: '#bdc3c7',
115
+ borderRadius: 10
116
+ }
117
+ });
118
+
119
+ // Interact with the toolbar to apply operations to the sequence.
120
+ // For example, click the '-' button and enter '5' to subtract 5 from both sides.
121
+ ```
122
+
123
+ ## Notes
124
+
125
+ - The toolbar can be styled via CSS for custom appearance.
126
+ - Supports dynamic updates (e.g., adding/removing tools or buttons at runtime).
127
+
128
+ ## See Also
129
+
130
+ - [`omdEquationSequenceNode`](./omdEquationSequenceNode.md) - The sequence node the toolbar operates on.
131
+ - [`omdEquationNode`](./omdEquationNode.md) - The type of nodes typically found in the sequence.