@teachinglab/omd 0.1.4 → 0.1.6

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 (47) hide show
  1. package/canvas/tools/EraserTool.js +1 -1
  2. package/canvas/tools/PencilTool.js +1 -1
  3. package/canvas/tools/SelectTool.js +1 -1
  4. package/docs/api/configuration-options.md +198 -104
  5. package/docs/api/eventManager.md +83 -68
  6. package/docs/api/focusFrameManager.md +145 -150
  7. package/docs/api/index.md +106 -91
  8. package/docs/api/main.md +63 -58
  9. package/docs/api/omdBinaryExpressionNode.md +86 -227
  10. package/docs/api/omdCanvas.md +84 -142
  11. package/docs/api/omdConfigManager.md +113 -192
  12. package/docs/api/omdConstantNode.md +53 -117
  13. package/docs/api/omdDisplay.md +87 -121
  14. package/docs/api/omdEquationNode.md +174 -161
  15. package/docs/api/omdEquationSequenceNode.md +259 -301
  16. package/docs/api/omdEquationStack.md +157 -103
  17. package/docs/api/omdFunctionNode.md +83 -141
  18. package/docs/api/omdGroupNode.md +79 -182
  19. package/docs/api/omdHelpers.md +88 -96
  20. package/docs/api/omdLeafNode.md +86 -163
  21. package/docs/api/omdNode.md +202 -101
  22. package/docs/api/omdOperationDisplayNode.md +118 -139
  23. package/docs/api/omdOperatorNode.md +92 -127
  24. package/docs/api/omdParenthesisNode.md +134 -122
  25. package/docs/api/omdPopup.md +192 -117
  26. package/docs/api/omdPowerNode.md +132 -127
  27. package/docs/api/omdRationalNode.md +145 -128
  28. package/docs/api/omdSimplification.md +79 -110
  29. package/docs/api/omdSqrtNode.md +144 -79
  30. package/docs/api/omdStepVisualizer.md +147 -115
  31. package/docs/api/omdStepVisualizerHighlighting.md +66 -61
  32. package/docs/api/omdStepVisualizerInteractiveSteps.md +109 -129
  33. package/docs/api/omdStepVisualizerLayout.md +71 -60
  34. package/docs/api/omdStepVisualizerTextBoxes.md +77 -68
  35. package/docs/api/omdToolbar.md +131 -102
  36. package/docs/api/omdTranscriptionService.md +96 -76
  37. package/docs/api/omdTreeDiff.md +170 -134
  38. package/docs/api/omdUnaryExpressionNode.md +137 -174
  39. package/docs/api/omdUtilities.md +83 -70
  40. package/docs/api/omdVariableNode.md +123 -148
  41. package/index.js +2 -2
  42. package/omd/core/index.js +9 -0
  43. package/omd/nodes/omdEquationSequenceNode.js +15 -0
  44. package/omd/utils/aiNextEquationStep.js +106 -0
  45. package/package.json +1 -1
  46. package/src/omdBalanceHanger.js +1 -1
  47. package/src/omdCoordinatePlane.js +1 -1
@@ -1,129 +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.
4
-
5
- ## Class: `omdStepVisualizerInteractiveSteps`
6
-
7
- ```javascript
8
- import { omdStepVisualizerInteractiveSteps } from './omd/utils/omdStepVisualizerInteractiveSteps.js';
9
- ```
10
-
11
- ### Constructor
12
-
13
- ```javascript
14
- new omdStepVisualizerInteractiveSteps(stepVisualizer, simplificationData)
15
- ```
16
-
17
- **Parameters:**
18
- - `stepVisualizer` {omdStepVisualizer} - A reference to the `omdStepVisualizer` instance.
19
- - `simplificationData` {Object} - An object containing the simplification details for the step, typically including `message`, `rawMessages`, and `ruleNames`.
20
-
21
- ### Properties
22
-
23
- #### `stepVisualizer`
24
- - **Type:** `omdStepVisualizer`
25
- - **Description:** A reference to the associated `omdStepVisualizer` instance.
26
-
27
- #### `simplificationData`
28
- - **Type:** `Object`
29
- - **Description:** The raw data describing the simplification step.
30
-
31
- #### `messages`
32
- - **Type:** `Array<string>`
33
- - **Description:** Cleaned and extracted messages for each sub-step.
34
-
35
- #### `ruleNames`
36
- - **Type:** `Array<string>`
37
- - **Description:** Extracted names of the simplification rules applied.
38
-
39
- #### `stepElements`
40
- - **Type:** `Array<jsvgTextBox>`
41
- - **Description:** An array of `jsvgTextBox` instances, each representing a line of explanation.
42
-
43
- #### `layoutGroup`
44
- - **Type:** `jsvgLayoutGroup`
45
- - **Description:** The main `jsvgLayoutGroup` that contains all the visual elements of the interactive steps, including the background and individual step messages.
46
-
47
- ### Methods
48
-
49
- #### `setOnStepHover(callback)`
50
-
51
- Sets a callback function to be executed when the user hovers over a step explanation.
52
-
53
- - **Parameters:**
54
- - `callback` {Function} - A function that receives `(stepIndex, message, isEntering)` as arguments.
55
-
56
- ---
57
-
58
- #### `setOnStepClick(callback)`
59
-
60
- Sets a callback function to be executed when the user clicks on a step explanation.
61
-
62
- - **Parameters:**
63
- - `callback` {Function} - A function that receives `(stepIndex, message)` as arguments.
64
-
65
- ---
66
-
67
- #### `getLayoutGroup()`
68
-
69
- Returns the main `jsvgLayoutGroup` containing all the interactive step elements. This group should be added to the parent container (e.g., `omdStepVisualizer`'s `visualContainer`).
70
-
71
- - **Returns:** `jsvgLayoutGroup`
72
-
73
- ---
74
-
75
- #### `setPosition(x, y)`
76
-
77
- Sets the position of the entire interactive step group.
78
-
79
- - **Parameters:**
80
- - `x` {number} - The X-coordinate.
81
- - `y` {number} - The Y-coordinate.
82
-
83
- ---
84
-
85
- #### `getDimensions()`
86
-
87
- Returns the calculated width and height of the interactive step group.
88
-
89
- - **Returns:** {Object} An object with `width` and `height` properties.
90
-
91
- ---
92
-
93
- #### `destroy()`
94
-
95
- Cleans up the component by removing all its children and clearing references.
96
-
97
- ### Private Methods
98
-
99
- - `_extractMessages(data)`: Extracts and cleans messages from the `simplificationData`.
100
- - `_extractRuleNames(data)`: Extracts rule names from the `simplificationData`.
101
- - `setupLayoutGroup()`: Initializes the main `layoutGroup` and its background rectangle.
102
- - `createStepElements()`: Creates individual `jsvgTextBox` elements for each message.
103
- - `createSingleStepElement(message, index)`: Creates elements for a single step explanation.
104
- - `createMultipleStepElements()`: Creates elements for multiple step explanations, including a header.
105
- - `createHeaderBox(headerText)`: Creates a styled header `jsvgTextBox`.
106
- - `createStepTextBox(message, index, isMultiple)`: Creates an individual styled `jsvgTextBox` for a step message.
107
- - `formatStepContent(message, index, isMultiple)`: Formats the message content with styling and optional step numbers.
108
- - `applyStepStyling(stepBox, content, isMultiple)`: Applies CSS styling to the `jsvgTextBox`'s underlying DOM element.
109
- - `setupStepInteractions(stepBox)`: Sets up `mouseenter`, `mouseleave`, and `click` event listeners for a step box.
110
- - `calculateStepHeight(message)`: Dynamically calculates the required height for a step box based on its content.
111
- - `updateBackgroundSize()`: Adjusts the size of the background rectangle to fit the content.
112
- - `isOperationMessage(message)`: Checks if a message describes an operation (e.g., "Added X to both sides").
113
- - `extractOperationAction(message)`: Extracts the action (e.g., "Added") from an operation message.
114
- - `extractOperationValue(message)`: Extracts the value (e.g., "3") from an operation message.
115
- - `extractOperationValueNode(message)`: Attempts to extract the `omdNode` representing the value from an operation message.
116
-
117
- ### How it Works
118
-
119
- 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.
120
-
121
- ### Example
122
-
123
- This class is typically used internally by `omdStepVisualizerTextBoxes`.
124
-
125
- ```javascript
126
- // Example of internal usage within omdStepVisualizerTextBoxes:
127
- // const interactiveSteps = new omdStepVisualizerInteractiveSteps(this.stepVisualizer, simplificationData);
128
- // this.stepVisualizer.visualContainer.addChild(interactiveSteps.getLayoutGroup());
129
- ```
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
+ ```
@@ -1,60 +1,71 @@
1
-
2
- # omdStepVisualizerLayout
3
-
4
- Manages the visual layout, positioning, and visibility of elements within the `omdStepVisualizer`. Ensures that step dots, connecting lines, and associated text boxes are correctly positioned relative to the mathematical equations.
5
-
6
- ## Import
7
-
8
- ```js
9
- import { omdStepVisualizerLayout } from './omd/step-visualizer/omdStepVisualizerLayout.js';
10
- ```
11
-
12
- ## Constructor
13
-
14
- ```js
15
- new omdStepVisualizerLayout(stepVisualizer)
16
- ```
17
-
18
- - `stepVisualizer` (`omdStepVisualizer`): Reference to the step visualizer instance this layout manager will control.
19
-
20
- ## Properties
21
-
22
- - `stepVisualizer` (`omdStepVisualizer`): The associated step visualizer instance.
23
-
24
- ## Methods
25
-
26
- ### `updateVisualLayout()`
27
- Calculates and applies the positions of all visual elements (dots, lines, text boxes) relative to the mathematical equations in the sequence. Ensures proper alignment and spacing.
28
-
29
- ### `findDotIndexForEquation(equation)`
30
- Finds the index of the step dot associated with a given `omdEquationNode`.
31
- - `equation` (`omdEquationNode`): The equation node to find the corresponding dot for.
32
- - **Returns:** `number` (index of the dot, or `-1` if not found)
33
-
34
- ### `updateVisualZOrder()`
35
- Manages the z-order (stacking order) of the visual elements to ensure they are rendered correctly (e.g., lines behind dots, text boxes on top).
36
-
37
- ### `updateAllLinePositions()`
38
- Recalculates and updates the start and end points of all connecting lines between the step dots.
39
-
40
- ### `updateVisualVisibility()`
41
- Adjusts the visibility of the step dots and lines based on the visibility of their corresponding equations. Re-creates lines only between currently visible dots.
42
-
43
- ### `updateDotClickability(dot)`
44
- Enables or disables the click functionality for a specific step dot, changing its cursor style accordingly.
45
- - `dot` (`jsvgEllipse`): The `jsvgEllipse` element representing the dot.
46
-
47
- ## How it Works
48
-
49
- 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.
50
-
51
- ## Example
52
-
53
- This class is primarily used internally by `omdStepVisualizer`:
54
-
55
- ```js
56
- // Inside omdStepVisualizer's updateLayout method:
57
- this.layoutManager.updateVisualLayout();
58
- this.layoutManager.updateVisualVisibility();
59
- this.layoutManager.updateAllLinePositions();
60
- ```
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
+ ```
@@ -1,68 +1,77 @@
1
-
2
- # omdStepVisualizerTextBoxes
3
-
4
- Manages the interactive text boxes that appear when a step dot is clicked in the `omdStepVisualizer`. Handles creation, positioning, and removal of these popups, and integrates with highlighting and layout managers for a cohesive user experience.
5
-
6
- ## Import
7
-
8
- ```js
9
- import { omdStepVisualizerTextBoxes } from './omd/step-visualizer/omdStepVisualizerTextBoxes.js';
10
- ```
11
-
12
- ## Constructor
13
-
14
- ```js
15
- new omdStepVisualizerTextBoxes(stepVisualizer, highlighting)
16
- ```
17
-
18
- - `stepVisualizer` (`omdStepVisualizer`): Reference to the step visualizer instance.
19
- - `highlighting` (`omdStepVisualizerHighlighting`): Reference to the highlighting manager.
20
-
21
- ## Properties
22
-
23
- - `stepVisualizer` (`omdStepVisualizer`): The associated step visualizer instance.
24
- - `highlighting` (`omdStepVisualizerHighlighting`): The associated highlighting instance.
25
- - `stepTextBoxes` (`Array<Object>`): Array of active text box objects, each with `dotIndex`, `interactiveSteps`, and `layoutGroup`.
26
-
27
- ## Methods
28
-
29
- ### `createTextBoxForDot(dotIndex)`
30
- Creates and displays an interactive text box for the specified step dot. Retrieves simplification data and positions the text box appropriately.
31
- - `dotIndex` (`number`): The index of the dot for which to create the text box.
32
-
33
- ### `removeTextBoxForDot(dotIndex)`
34
- Removes the text box associated with the specified step dot.
35
- - `dotIndex` (`number`): The index of the dot whose text box should be removed.
36
-
37
- ### `clearAllTextBoxes()`
38
- Removes all active text boxes from the visualizer.
39
-
40
- ### `getStepTextBoxes()`
41
- Returns an array of all currently active text box objects.
42
- - **Returns:** `Array<Object>`
43
-
44
- ### Private/Internal Methods
45
-
46
- - `_createInteractiveStepsForDot(dotIndex, targetDot, simplificationData)`: Creates and configures the `omdStepVisualizerInteractiveSteps` instance for a dot.
47
- - `_findDotAboveForPositioning(dotIndex)`: Determines the appropriate dot to position the text box relative to, ensuring correct placement even if some steps are hidden.
48
- - `_getSimplificationDataForDot(dotIndex)`: Retrieves simplification data for a given dot from the step visualizer.
49
-
50
- ## How it Works
51
-
52
- When a user clicks a step dot in the `omdStepVisualizer`, this class:
53
- 1. **Fetches Data:** Requests simplification data from the step visualizer for the clicked step.
54
- 2. **Creates UI:** Instantiates an `omdStepVisualizerInteractiveSteps` component, which renders the explanation text and interactive elements.
55
- 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.
56
- 4. **Highlighting Integration:** Works with `omdStepVisualizerHighlighting` to trigger visual feedback when the text box is displayed or interacted with.
57
-
58
- ## Example
59
-
60
- This class is primarily used internally by `omdStepVisualizer`:
61
-
62
- ```js
63
- // Inside omdStepVisualizer's _handleDotClick method:
64
- this.textBoxManager.createTextBoxForDot(dotIndex);
65
-
66
- // Inside omdStepVisualizer's _clearActiveDot method:
67
- this.textBoxManager.removeTextBoxForDot(this.activeDotIndex);
68
- ```
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
+ ```