@teachinglab/omd 0.6.0 → 0.6.2
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.
- package/README.md +257 -251
- package/README.old.md +137 -137
- package/canvas/core/canvasConfig.js +202 -202
- package/canvas/drawing/segment.js +167 -167
- package/canvas/drawing/stroke.js +385 -385
- package/canvas/events/eventManager.js +444 -444
- package/canvas/events/pointerEventHandler.js +262 -262
- package/canvas/index.js +48 -48
- package/canvas/tools/PointerTool.js +71 -71
- package/canvas/tools/tool.js +222 -222
- package/canvas/utils/boundingBox.js +377 -377
- package/canvas/utils/mathUtils.js +258 -258
- package/docs/api/configuration-options.md +198 -198
- package/docs/api/eventManager.md +82 -82
- package/docs/api/focusFrameManager.md +144 -144
- package/docs/api/index.md +105 -105
- package/docs/api/main.md +62 -62
- package/docs/api/omdBinaryExpressionNode.md +86 -86
- package/docs/api/omdCanvas.md +83 -83
- package/docs/api/omdConfigManager.md +112 -112
- package/docs/api/omdConstantNode.md +52 -52
- package/docs/api/omdDisplay.md +87 -87
- package/docs/api/omdEquationNode.md +174 -174
- package/docs/api/omdEquationSequenceNode.md +258 -258
- package/docs/api/omdEquationStack.md +192 -192
- package/docs/api/omdFunctionNode.md +82 -82
- package/docs/api/omdGroupNode.md +78 -78
- package/docs/api/omdHelpers.md +87 -87
- package/docs/api/omdLeafNode.md +85 -85
- package/docs/api/omdNode.md +201 -201
- package/docs/api/omdOperationDisplayNode.md +117 -117
- package/docs/api/omdOperatorNode.md +91 -91
- package/docs/api/omdParenthesisNode.md +133 -133
- package/docs/api/omdPopup.md +191 -191
- package/docs/api/omdPowerNode.md +131 -131
- package/docs/api/omdRationalNode.md +144 -144
- package/docs/api/omdSequenceNode.md +128 -128
- package/docs/api/omdSimplification.md +78 -78
- package/docs/api/omdSqrtNode.md +144 -144
- package/docs/api/omdStepVisualizer.md +146 -146
- package/docs/api/omdStepVisualizerHighlighting.md +65 -65
- package/docs/api/omdStepVisualizerInteractiveSteps.md +108 -108
- package/docs/api/omdStepVisualizerLayout.md +70 -70
- package/docs/api/omdStepVisualizerNodeUtils.md +140 -140
- package/docs/api/omdStepVisualizerTextBoxes.md +76 -76
- package/docs/api/omdToolbar.md +130 -130
- package/docs/api/omdTranscriptionService.md +95 -95
- package/docs/api/omdTreeDiff.md +169 -169
- package/docs/api/omdUnaryExpressionNode.md +137 -137
- package/docs/api/omdUtilities.md +82 -82
- package/docs/api/omdVariableNode.md +123 -123
- package/docs/api/selectTool.md +74 -74
- package/docs/api/simplificationEngine.md +97 -97
- package/docs/api/simplificationRules.md +76 -76
- package/docs/api/simplificationUtils.md +64 -64
- package/docs/api/transcribe.md +43 -43
- package/docs/api-reference.md +85 -85
- package/docs/index.html +453 -453
- package/docs/index.md +38 -38
- package/docs/omd-objects.md +258 -258
- package/index.js +79 -79
- package/jsvg/index.js +3 -0
- package/jsvg/jsvg.js +898 -898
- package/jsvg/jsvgComponents.js +357 -358
- package/npm-docs/DOCUMENTATION_SUMMARY.md +220 -220
- package/npm-docs/README.md +251 -251
- package/npm-docs/api/api-reference.md +85 -85
- package/npm-docs/api/configuration-options.md +198 -198
- package/npm-docs/api/eventManager.md +82 -82
- package/npm-docs/api/expression-nodes.md +561 -561
- package/npm-docs/api/focusFrameManager.md +144 -144
- package/npm-docs/api/index.md +105 -105
- package/npm-docs/api/main.md +62 -62
- package/npm-docs/api/omdBinaryExpressionNode.md +86 -86
- package/npm-docs/api/omdCanvas.md +83 -83
- package/npm-docs/api/omdConfigManager.md +112 -112
- package/npm-docs/api/omdConstantNode.md +52 -52
- package/npm-docs/api/omdDisplay.md +87 -87
- package/npm-docs/api/omdEquationNode.md +174 -174
- package/npm-docs/api/omdEquationSequenceNode.md +258 -258
- package/npm-docs/api/omdEquationStack.md +192 -192
- package/npm-docs/api/omdFunctionNode.md +82 -82
- package/npm-docs/api/omdGroupNode.md +78 -78
- package/npm-docs/api/omdHelpers.md +87 -87
- package/npm-docs/api/omdLeafNode.md +85 -85
- package/npm-docs/api/omdNode.md +201 -201
- package/npm-docs/api/omdOperationDisplayNode.md +117 -117
- package/npm-docs/api/omdOperatorNode.md +91 -91
- package/npm-docs/api/omdParenthesisNode.md +133 -133
- package/npm-docs/api/omdPopup.md +191 -191
- package/npm-docs/api/omdPowerNode.md +131 -131
- package/npm-docs/api/omdRationalNode.md +144 -144
- package/npm-docs/api/omdSequenceNode.md +128 -128
- package/npm-docs/api/omdSimplification.md +78 -78
- package/npm-docs/api/omdSqrtNode.md +144 -144
- package/npm-docs/api/omdStepVisualizer.md +146 -146
- package/npm-docs/api/omdStepVisualizerHighlighting.md +65 -65
- package/npm-docs/api/omdStepVisualizerInteractiveSteps.md +108 -108
- package/npm-docs/api/omdStepVisualizerLayout.md +70 -70
- package/npm-docs/api/omdStepVisualizerNodeUtils.md +140 -140
- package/npm-docs/api/omdStepVisualizerTextBoxes.md +76 -76
- package/npm-docs/api/omdToolbar.md +130 -130
- package/npm-docs/api/omdTranscriptionService.md +95 -95
- package/npm-docs/api/omdTreeDiff.md +169 -169
- package/npm-docs/api/omdUnaryExpressionNode.md +137 -137
- package/npm-docs/api/omdUtilities.md +82 -82
- package/npm-docs/api/omdVariableNode.md +123 -123
- package/npm-docs/api/selectTool.md +74 -74
- package/npm-docs/api/simplificationEngine.md +97 -97
- package/npm-docs/api/simplificationRules.md +76 -76
- package/npm-docs/api/simplificationUtils.md +64 -64
- package/npm-docs/api/transcribe.md +43 -43
- package/npm-docs/guides/equations.md +854 -854
- package/npm-docs/guides/factory-functions.md +354 -354
- package/npm-docs/guides/getting-started.md +318 -318
- package/npm-docs/guides/quick-examples.md +525 -525
- package/npm-docs/guides/visualizations.md +682 -682
- package/npm-docs/index.html +12 -0
- package/npm-docs/json-schemas.md +826 -826
- package/omd/config/omdConfigManager.js +279 -267
- package/omd/core/index.js +158 -158
- package/omd/core/omdEquationStack.js +546 -546
- package/omd/core/omdUtilities.js +113 -113
- package/omd/display/omdDisplay.js +969 -962
- package/omd/display/omdToolbar.js +501 -501
- package/omd/nodes/omdBinaryExpressionNode.js +459 -459
- package/omd/nodes/omdConstantNode.js +141 -141
- package/omd/nodes/omdEquationNode.js +1327 -1327
- package/omd/nodes/omdFunctionNode.js +351 -351
- package/omd/nodes/omdGroupNode.js +67 -67
- package/omd/nodes/omdLeafNode.js +76 -76
- package/omd/nodes/omdNode.js +556 -556
- package/omd/nodes/omdOperationDisplayNode.js +321 -321
- package/omd/nodes/omdOperatorNode.js +108 -108
- package/omd/nodes/omdParenthesisNode.js +292 -292
- package/omd/nodes/omdPowerNode.js +235 -235
- package/omd/nodes/omdRationalNode.js +295 -295
- package/omd/nodes/omdSqrtNode.js +307 -307
- package/omd/nodes/omdUnaryExpressionNode.js +227 -227
- package/omd/nodes/omdVariableNode.js +122 -122
- package/omd/simplification/omdSimplification.js +140 -140
- package/omd/simplification/omdSimplificationEngine.js +887 -887
- package/omd/simplification/package.json +5 -5
- package/omd/simplification/rules/binaryRules.js +1037 -1037
- package/omd/simplification/rules/functionRules.js +111 -111
- package/omd/simplification/rules/index.js +48 -48
- package/omd/simplification/rules/parenthesisRules.js +19 -19
- package/omd/simplification/rules/powerRules.js +143 -143
- package/omd/simplification/rules/rationalRules.js +725 -725
- package/omd/simplification/rules/sqrtRules.js +48 -48
- package/omd/simplification/rules/unaryRules.js +37 -37
- package/omd/simplification/simplificationRules.js +31 -31
- package/omd/simplification/simplificationUtils.js +1055 -1055
- package/omd/step-visualizer/omdStepVisualizer.js +947 -947
- package/omd/step-visualizer/omdStepVisualizerHighlighting.js +246 -246
- package/omd/step-visualizer/omdStepVisualizerLayout.js +892 -892
- package/omd/step-visualizer/omdStepVisualizerTextBoxes.js +200 -200
- package/omd/utils/aiNextEquationStep.js +106 -106
- package/omd/utils/omdNodeOverlay.js +638 -638
- package/omd/utils/omdPopup.js +1203 -1203
- package/omd/utils/omdStepVisualizerInteractiveSteps.js +684 -684
- package/omd/utils/omdStepVisualizerNodeUtils.js +267 -267
- package/omd/utils/omdTranscriptionService.js +123 -123
- package/omd/utils/omdTreeDiff.js +733 -733
- package/package.json +59 -56
- package/readme.html +184 -120
- package/src/index.js +74 -74
- package/src/json-schemas.md +576 -576
- package/src/omd-json-samples.js +147 -147
- package/src/omdApp.js +391 -391
- package/src/omdAppCanvas.js +335 -335
- package/src/omdBalanceHanger.js +199 -199
- package/src/omdColor.js +13 -13
- package/src/omdCoordinatePlane.js +541 -541
- package/src/omdExpression.js +115 -115
- package/src/omdFactory.js +150 -150
- package/src/omdFunction.js +114 -114
- package/src/omdMetaExpression.js +290 -290
- package/src/omdNaturalExpression.js +563 -563
- package/src/omdNode.js +383 -383
- package/src/omdNumber.js +52 -52
- package/src/omdNumberLine.js +114 -112
- package/src/omdNumberTile.js +118 -118
- package/src/omdOperator.js +72 -72
- package/src/omdPowerExpression.js +91 -91
- package/src/omdProblem.js +259 -259
- package/src/omdRatioChart.js +251 -251
- package/src/omdRationalExpression.js +114 -114
- package/src/omdSampleData.js +215 -215
- package/src/omdShapes.js +512 -512
- package/src/omdSpinner.js +151 -151
- package/src/omdString.js +49 -49
- package/src/omdTable.js +498 -498
- package/src/omdTapeDiagram.js +244 -244
- package/src/omdTerm.js +91 -91
- package/src/omdTileEquation.js +349 -349
- package/src/omdUtils.js +84 -84
- package/src/omdVariable.js +51 -51
|
@@ -1,145 +1,145 @@
|
|
|
1
|
-
# FocusFrameManager
|
|
2
|
-
|
|
3
|
-
The `FocusFrameManager` is a feature that allows you to define rectangular regions on the canvas called "focus frames." These frames can be used to highlight specific areas of interest, capture their contents as separate SVG or bitmap images, and manage them independently.
|
|
4
|
-
|
|
5
|
-
This is particularly useful for applications where you need to isolate and process or export specific parts of a larger drawing, such as individual mathematical problems on a worksheet or specific diagrams in a complex scene.
|
|
6
|
-
|
|
7
|
-
## Class Definition
|
|
8
|
-
|
|
9
|
-
```javascript
|
|
10
|
-
export class FocusFrameManager {
|
|
11
|
-
// ...
|
|
12
|
-
}
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Constructor
|
|
16
|
-
|
|
17
|
-
### `new FocusFrameManager(canvas)`
|
|
18
|
-
|
|
19
|
-
Creates a new `FocusFrameManager` instance.
|
|
20
|
-
|
|
21
|
-
- **`canvas`** (`OMDCanvas`): The main canvas instance.
|
|
22
|
-
|
|
23
|
-
## Public Methods
|
|
24
|
-
|
|
25
|
-
### `createFrame([options])`
|
|
26
|
-
|
|
27
|
-
Creates a new, independent focus frame on the canvas.
|
|
28
|
-
|
|
29
|
-
- **`options`** (`object`, optional): Configuration for the new frame.
|
|
30
|
-
- `x` (`number`, optional): The x-coordinate of the top-left corner. Default: `0`.
|
|
31
|
-
- `y` (`number`, optional): The y-coordinate of the top-left corner. Default: `0`.
|
|
32
|
-
- `width` (`number`, optional): The width of the frame. Default: `200`.
|
|
33
|
-
- `height` (`number`, optional): The height of the frame. Default: `150`.
|
|
34
|
-
- `showOutline` (`boolean`, optional): Whether to display the frame's border. Default: `true`.
|
|
35
|
-
- `outlineColor` (`string`, optional): The color of the border. Default: `'#007bff'`.
|
|
36
|
-
- `outlineWidth` (`number`, optional): The thickness of the border. Default: `2`.
|
|
37
|
-
- `outlineDashed` (`boolean`, optional): Whether the border should be a dashed line. Default: `false`.
|
|
38
|
-
- **Returns**: `object` - An object containing the `id` of the new frame and a reference to the `frame` instance (`{ id, frame }`).
|
|
39
|
-
- **Emits**: `focusFrameCreated` with `{ id, frame }`.
|
|
40
|
-
|
|
41
|
-
### `removeFrame(frameId)`
|
|
42
|
-
|
|
43
|
-
Removes a specific focus frame from the canvas.
|
|
44
|
-
|
|
45
|
-
- **`frameId`** (`string`): The unique ID of the frame to remove.
|
|
46
|
-
- **Returns**: `boolean` - `true` if the frame was found and removed, `false` otherwise.
|
|
47
|
-
- **Emits**: `focusFrameRemoved` with `{ frameId }`.
|
|
48
|
-
|
|
49
|
-
### `getFrame(frameId)`
|
|
50
|
-
|
|
51
|
-
Retrieves a focus frame instance by its ID.
|
|
52
|
-
|
|
53
|
-
- **`frameId`** (`string`): The ID of the frame to retrieve.
|
|
54
|
-
- **Returns**: `FocusFrame` or `undefined` - The frame instance, or `undefined` if no frame with that ID exists.
|
|
55
|
-
|
|
56
|
-
### `setActiveFrame(frameId)`
|
|
57
|
-
|
|
58
|
-
Sets a specific frame as the "active" one, which can be useful for highlighting or targeting operations.
|
|
59
|
-
|
|
60
|
-
- **`frameId`** (`string`): The ID of the frame to activate.
|
|
61
|
-
- **Returns**: `boolean` - `true` if the frame was successfully activated.
|
|
62
|
-
- **Emits**: `focusFrameActivated` with `{ frameId, frame }`.
|
|
63
|
-
|
|
64
|
-
### `getActiveFrame()`
|
|
65
|
-
|
|
66
|
-
Gets the currently active focus frame.
|
|
67
|
-
|
|
68
|
-
- **Returns**: `FocusFrame` or `null` - The active frame instance, or `null` if no frame is currently active.
|
|
69
|
-
|
|
70
|
-
### `captureActiveFrame()`
|
|
71
|
-
|
|
72
|
-
Captures the SVG content of the currently active focus frame.
|
|
73
|
-
|
|
74
|
-
- **Returns**: `string` or `null` - A string of the SVG content within the active frame's bounds, or `null` if there is no active frame.
|
|
75
|
-
|
|
76
|
-
### `captureAllFrames()`
|
|
77
|
-
|
|
78
|
-
Captures the content of every focus frame on the canvas.
|
|
79
|
-
|
|
80
|
-
- **Returns**: `Map<string, string>` - A Map where keys are frame IDs and values are the SVG content strings for each frame.
|
|
81
|
-
|
|
82
|
-
### `clearAllFrames()`
|
|
83
|
-
|
|
84
|
-
Removes all focus frames from the canvas.
|
|
85
|
-
|
|
86
|
-
- **Emits**: `focusFramesCleared`.
|
|
87
|
-
|
|
88
|
-
### `getFrameIds()`
|
|
89
|
-
|
|
90
|
-
Gets the IDs of all current focus frames.
|
|
91
|
-
|
|
92
|
-
- **Returns**: `Array<string>` - An array of all frame IDs.
|
|
93
|
-
|
|
94
|
-
### `destroy()`
|
|
95
|
-
|
|
96
|
-
Destroys the manager and removes all associated frames and event listeners.
|
|
97
|
-
|
|
98
|
-
---
|
|
99
|
-
|
|
100
|
-
## The `FocusFrame` Class (Internal)
|
|
101
|
-
|
|
102
|
-
The `FocusFrame` class represents a single rectangular frame. It is not exported directly but is returned by `FocusFrameManager` methods.
|
|
103
|
-
|
|
104
|
-
### `setActive(active)`
|
|
105
|
-
|
|
106
|
-
Sets the frame's visual state to active or inactive.
|
|
107
|
-
|
|
108
|
-
- **`active`** (`boolean`): `true` to activate, `false` to deactivate.
|
|
109
|
-
|
|
110
|
-
### `capture()`
|
|
111
|
-
|
|
112
|
-
Captures the canvas content within the frame's bounds.
|
|
113
|
-
|
|
114
|
-
- **Returns**: `string` - The SVG content of the frame as an XML string.
|
|
115
|
-
|
|
116
|
-
### `async toBitmap([format], [quality])`
|
|
117
|
-
|
|
118
|
-
Converts the frame's captured content into a bitmap image.
|
|
119
|
-
|
|
120
|
-
- **`format`** (`string`, optional): The image format (e.g., `'png'`, `'jpeg'`). Default: `'png'`.
|
|
121
|
-
- **`quality`** (`number`, optional): The image quality for formats that support it (0 to 1). Default: `1`.
|
|
122
|
-
- **Returns**: `Promise<Blob>` - A promise that resolves with the image data as a `Blob`.
|
|
123
|
-
|
|
124
|
-
### `async downloadAsBitmap([filename], [format])`
|
|
125
|
-
|
|
126
|
-
Triggers a browser download of the frame's content as a bitmap image.
|
|
127
|
-
|
|
128
|
-
- **`filename`** (`string`, optional): The desired filename. Default: `focus-frame-{id}.png`.
|
|
129
|
-
- **`format`** (`string`, optional): The image format. Default: `'png'`.
|
|
130
|
-
|
|
131
|
-
### `updateBounds(bounds)`
|
|
132
|
-
|
|
133
|
-
Resizes and/or repositions the frame.
|
|
134
|
-
|
|
135
|
-
- **`bounds`** (`object`): An object with the new dimensions and coordinates (`{ x, y, width, height }`).
|
|
136
|
-
|
|
137
|
-
### `getBounds()`
|
|
138
|
-
|
|
139
|
-
Gets the current position and size of the frame.
|
|
140
|
-
|
|
141
|
-
- **Returns**: `object` - An object containing the frame's bounds (`{ x, y, width, height }`).
|
|
142
|
-
|
|
143
|
-
### `destroy()`
|
|
144
|
-
|
|
1
|
+
# FocusFrameManager
|
|
2
|
+
|
|
3
|
+
The `FocusFrameManager` is a feature that allows you to define rectangular regions on the canvas called "focus frames." These frames can be used to highlight specific areas of interest, capture their contents as separate SVG or bitmap images, and manage them independently.
|
|
4
|
+
|
|
5
|
+
This is particularly useful for applications where you need to isolate and process or export specific parts of a larger drawing, such as individual mathematical problems on a worksheet or specific diagrams in a complex scene.
|
|
6
|
+
|
|
7
|
+
## Class Definition
|
|
8
|
+
|
|
9
|
+
```javascript
|
|
10
|
+
export class FocusFrameManager {
|
|
11
|
+
// ...
|
|
12
|
+
}
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Constructor
|
|
16
|
+
|
|
17
|
+
### `new FocusFrameManager(canvas)`
|
|
18
|
+
|
|
19
|
+
Creates a new `FocusFrameManager` instance.
|
|
20
|
+
|
|
21
|
+
- **`canvas`** (`OMDCanvas`): The main canvas instance.
|
|
22
|
+
|
|
23
|
+
## Public Methods
|
|
24
|
+
|
|
25
|
+
### `createFrame([options])`
|
|
26
|
+
|
|
27
|
+
Creates a new, independent focus frame on the canvas.
|
|
28
|
+
|
|
29
|
+
- **`options`** (`object`, optional): Configuration for the new frame.
|
|
30
|
+
- `x` (`number`, optional): The x-coordinate of the top-left corner. Default: `0`.
|
|
31
|
+
- `y` (`number`, optional): The y-coordinate of the top-left corner. Default: `0`.
|
|
32
|
+
- `width` (`number`, optional): The width of the frame. Default: `200`.
|
|
33
|
+
- `height` (`number`, optional): The height of the frame. Default: `150`.
|
|
34
|
+
- `showOutline` (`boolean`, optional): Whether to display the frame's border. Default: `true`.
|
|
35
|
+
- `outlineColor` (`string`, optional): The color of the border. Default: `'#007bff'`.
|
|
36
|
+
- `outlineWidth` (`number`, optional): The thickness of the border. Default: `2`.
|
|
37
|
+
- `outlineDashed` (`boolean`, optional): Whether the border should be a dashed line. Default: `false`.
|
|
38
|
+
- **Returns**: `object` - An object containing the `id` of the new frame and a reference to the `frame` instance (`{ id, frame }`).
|
|
39
|
+
- **Emits**: `focusFrameCreated` with `{ id, frame }`.
|
|
40
|
+
|
|
41
|
+
### `removeFrame(frameId)`
|
|
42
|
+
|
|
43
|
+
Removes a specific focus frame from the canvas.
|
|
44
|
+
|
|
45
|
+
- **`frameId`** (`string`): The unique ID of the frame to remove.
|
|
46
|
+
- **Returns**: `boolean` - `true` if the frame was found and removed, `false` otherwise.
|
|
47
|
+
- **Emits**: `focusFrameRemoved` with `{ frameId }`.
|
|
48
|
+
|
|
49
|
+
### `getFrame(frameId)`
|
|
50
|
+
|
|
51
|
+
Retrieves a focus frame instance by its ID.
|
|
52
|
+
|
|
53
|
+
- **`frameId`** (`string`): The ID of the frame to retrieve.
|
|
54
|
+
- **Returns**: `FocusFrame` or `undefined` - The frame instance, or `undefined` if no frame with that ID exists.
|
|
55
|
+
|
|
56
|
+
### `setActiveFrame(frameId)`
|
|
57
|
+
|
|
58
|
+
Sets a specific frame as the "active" one, which can be useful for highlighting or targeting operations.
|
|
59
|
+
|
|
60
|
+
- **`frameId`** (`string`): The ID of the frame to activate.
|
|
61
|
+
- **Returns**: `boolean` - `true` if the frame was successfully activated.
|
|
62
|
+
- **Emits**: `focusFrameActivated` with `{ frameId, frame }`.
|
|
63
|
+
|
|
64
|
+
### `getActiveFrame()`
|
|
65
|
+
|
|
66
|
+
Gets the currently active focus frame.
|
|
67
|
+
|
|
68
|
+
- **Returns**: `FocusFrame` or `null` - The active frame instance, or `null` if no frame is currently active.
|
|
69
|
+
|
|
70
|
+
### `captureActiveFrame()`
|
|
71
|
+
|
|
72
|
+
Captures the SVG content of the currently active focus frame.
|
|
73
|
+
|
|
74
|
+
- **Returns**: `string` or `null` - A string of the SVG content within the active frame's bounds, or `null` if there is no active frame.
|
|
75
|
+
|
|
76
|
+
### `captureAllFrames()`
|
|
77
|
+
|
|
78
|
+
Captures the content of every focus frame on the canvas.
|
|
79
|
+
|
|
80
|
+
- **Returns**: `Map<string, string>` - A Map where keys are frame IDs and values are the SVG content strings for each frame.
|
|
81
|
+
|
|
82
|
+
### `clearAllFrames()`
|
|
83
|
+
|
|
84
|
+
Removes all focus frames from the canvas.
|
|
85
|
+
|
|
86
|
+
- **Emits**: `focusFramesCleared`.
|
|
87
|
+
|
|
88
|
+
### `getFrameIds()`
|
|
89
|
+
|
|
90
|
+
Gets the IDs of all current focus frames.
|
|
91
|
+
|
|
92
|
+
- **Returns**: `Array<string>` - An array of all frame IDs.
|
|
93
|
+
|
|
94
|
+
### `destroy()`
|
|
95
|
+
|
|
96
|
+
Destroys the manager and removes all associated frames and event listeners.
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## The `FocusFrame` Class (Internal)
|
|
101
|
+
|
|
102
|
+
The `FocusFrame` class represents a single rectangular frame. It is not exported directly but is returned by `FocusFrameManager` methods.
|
|
103
|
+
|
|
104
|
+
### `setActive(active)`
|
|
105
|
+
|
|
106
|
+
Sets the frame's visual state to active or inactive.
|
|
107
|
+
|
|
108
|
+
- **`active`** (`boolean`): `true` to activate, `false` to deactivate.
|
|
109
|
+
|
|
110
|
+
### `capture()`
|
|
111
|
+
|
|
112
|
+
Captures the canvas content within the frame's bounds.
|
|
113
|
+
|
|
114
|
+
- **Returns**: `string` - The SVG content of the frame as an XML string.
|
|
115
|
+
|
|
116
|
+
### `async toBitmap([format], [quality])`
|
|
117
|
+
|
|
118
|
+
Converts the frame's captured content into a bitmap image.
|
|
119
|
+
|
|
120
|
+
- **`format`** (`string`, optional): The image format (e.g., `'png'`, `'jpeg'`). Default: `'png'`.
|
|
121
|
+
- **`quality`** (`number`, optional): The image quality for formats that support it (0 to 1). Default: `1`.
|
|
122
|
+
- **Returns**: `Promise<Blob>` - A promise that resolves with the image data as a `Blob`.
|
|
123
|
+
|
|
124
|
+
### `async downloadAsBitmap([filename], [format])`
|
|
125
|
+
|
|
126
|
+
Triggers a browser download of the frame's content as a bitmap image.
|
|
127
|
+
|
|
128
|
+
- **`filename`** (`string`, optional): The desired filename. Default: `focus-frame-{id}.png`.
|
|
129
|
+
- **`format`** (`string`, optional): The image format. Default: `'png'`.
|
|
130
|
+
|
|
131
|
+
### `updateBounds(bounds)`
|
|
132
|
+
|
|
133
|
+
Resizes and/or repositions the frame.
|
|
134
|
+
|
|
135
|
+
- **`bounds`** (`object`): An object with the new dimensions and coordinates (`{ x, y, width, height }`).
|
|
136
|
+
|
|
137
|
+
### `getBounds()`
|
|
138
|
+
|
|
139
|
+
Gets the current position and size of the frame.
|
|
140
|
+
|
|
141
|
+
- **Returns**: `object` - An object containing the frame's bounds (`{ x, y, width, height }`).
|
|
142
|
+
|
|
143
|
+
### `destroy()`
|
|
144
|
+
|
|
145
145
|
Removes the frame's visual element from the canvas.
|
package/docs/api/index.md
CHANGED
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
# OMD Library Entry Point
|
|
2
|
-
|
|
3
|
-
This module (`omd/core/index.js`) serves as the main entry point for the OMD (
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
When you import from `@teachinglab/omd` (or directly from `omd/core/index.js`), you gain access to a comprehensive set of tools for building and manipulating mathematical expressions and their visual representations.
|
|
8
|
-
|
|
9
|
-
## Named Exports
|
|
10
|
-
|
|
11
|
-
The primary way to use the library is through its named exports.
|
|
12
|
-
|
|
13
|
-
### Core Node Classes
|
|
14
|
-
|
|
15
|
-
All classes extending `omdNode` are re-exported, allowing you to construct and work with various types of mathematical expressions:
|
|
16
|
-
|
|
17
|
-
- [`omdNode`](./omdNode.md)
|
|
18
|
-
- [`omdBinaryExpressionNode`](./omdBinaryExpressionNode.md)
|
|
19
|
-
- [`omdConstantNode`](./omdConstantNode.md)
|
|
20
|
-
- [`omdEquationNode`](./omdEquationNode.md)
|
|
21
|
-
- [`omdEquationSequenceNode`](./omdEquationSequenceNode.md)
|
|
22
|
-
- [`omdEquationStack`](./omdEquationStack.md)
|
|
23
|
-
- [`omdFunctionNode`](./omdFunctionNode.md)
|
|
24
|
-
- [`omdGroupNode`](./omdGroupNode.md)
|
|
25
|
-
- [`omdLeafNode`](./omdLeafNode.md)
|
|
26
|
-
- [`omdOperationDisplayNode`](./omdOperationDisplayNode.md)
|
|
27
|
-
- [`omdOperatorNode`](./omdOperatorNode.md)
|
|
28
|
-
- [`omdParenthesisNode`](./omdParenthesisNode.md)
|
|
29
|
-
- [`omdPowerNode`](./omdPowerNode.md)
|
|
30
|
-
- [`omdRationalNode`](./omdRationalNode.md)
|
|
31
|
-
- [`omdSqrtNode`](./omdSqrtNode.md)
|
|
32
|
-
- [`omdUnaryExpressionNode`](./omdUnaryExpressionNode.md)
|
|
33
|
-
- [`omdVariableNode`](./omdVariableNode.md)
|
|
34
|
-
|
|
35
|
-
### Visualization Components
|
|
36
|
-
|
|
37
|
-
These classes provide high-level components for rendering and interacting with mathematical expressions:
|
|
38
|
-
|
|
39
|
-
- [`omdStepVisualizer`](./omdStepVisualizer.md)
|
|
40
|
-
- [`omdDisplay`](./omdDisplay.md)
|
|
41
|
-
- [`omdToolbar`](./omdToolbar.md)
|
|
42
|
-
|
|
43
|
-
### Utilities
|
|
44
|
-
|
|
45
|
-
Essential utility functions and classes for parsing, simplification, and configuration management:
|
|
46
|
-
|
|
47
|
-
- `getNodeForAST`: A factory function to get the correct `omdNode` class for a given math.js AST.
|
|
48
|
-
- `simplifyStep`: Applies a single simplification step to an expression.
|
|
49
|
-
- `initializeConfig`: Initializes the OMD configuration.
|
|
50
|
-
- `setConfig`: Sets the OMD configuration.
|
|
51
|
-
- `getDefaultConfig`: Retrieves the default OMD configuration.
|
|
52
|
-
- `omdExpression`: A base class for expressions.
|
|
53
|
-
- `omdColor`: A utility class for working with colors.
|
|
54
|
-
|
|
55
|
-
### `omdHelpers`
|
|
56
|
-
|
|
57
|
-
A collection of convenience functions for common operations:
|
|
58
|
-
|
|
59
|
-
#### `createNodeFromExpression(expression, mathjs)`
|
|
60
|
-
- Creates an `omdNode` instance from a string expression using a provided math.js instance.
|
|
61
|
-
|
|
62
|
-
#### `createEquation(equationString)`
|
|
63
|
-
- Creates an `omdEquationNode` from a string representation of an equation.
|
|
64
|
-
|
|
65
|
-
#### `createStepVisualizer(equationStrings)`
|
|
66
|
-
- Creates an `omdStepVisualizer` instance from an array of equation strings.
|
|
67
|
-
|
|
68
|
-
## Re-Exports
|
|
69
|
-
|
|
70
|
-
The index also re-exports all named exports from the following modules:
|
|
71
|
-
|
|
72
|
-
- `../step-visualizer/omdStepVisualizer.js`
|
|
73
|
-
- `./omdUtilities.js`
|
|
74
|
-
- `../display/omdToolbar.js`
|
|
75
|
-
|
|
76
|
-
This means you can import their functions directly from the main entry point.
|
|
77
|
-
|
|
78
|
-
## Default Export
|
|
79
|
-
|
|
80
|
-
The module also provides a default export, which is an object containing all the re-exported classes and functions, organized into logical groups (`nodes`, `helpers`, etc.). This allows for a more structured import if preferred.
|
|
81
|
-
|
|
82
|
-
```javascript
|
|
83
|
-
import OMD from '@teachinglab/omd';
|
|
84
|
-
|
|
85
|
-
const equation = new OMD.nodes.omdEquationNode(...);
|
|
86
|
-
const display = new OMD.omdDisplay(...);
|
|
87
|
-
const helpers = OMD.helpers;
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
## Example Usage
|
|
91
|
-
|
|
92
|
-
```javascript
|
|
93
|
-
import { omdDisplay, omdEquationNode, omdHelpers } from '@teachinglab/omd';
|
|
94
|
-
|
|
95
|
-
// Create an equation using a helper
|
|
96
|
-
const equation = omdHelpers.createEquation('2x + 5 = 15');
|
|
97
|
-
|
|
98
|
-
// Create a display and render the equation
|
|
99
|
-
const displayContainer = document.getElementById('math-container');
|
|
100
|
-
const display = new omdDisplay(displayContainer);
|
|
101
|
-
|
|
102
|
-
display.render(equation);
|
|
103
|
-
|
|
104
|
-
// You can also directly access node classes
|
|
105
|
-
const constant = new omdConstantNode({ value: 10 });
|
|
1
|
+
# OMD Library Entry Point
|
|
2
|
+
|
|
3
|
+
This module (`omd/core/index.js`) serves as the main entry point for the OMD (On-screen Math Display) library. It re-exports all core classes, visualization components, and utility functions, making them easily accessible from a single import.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
When you import from `@teachinglab/omd` (or directly from `omd/core/index.js`), you gain access to a comprehensive set of tools for building and manipulating mathematical expressions and their visual representations.
|
|
8
|
+
|
|
9
|
+
## Named Exports
|
|
10
|
+
|
|
11
|
+
The primary way to use the library is through its named exports.
|
|
12
|
+
|
|
13
|
+
### Core Node Classes
|
|
14
|
+
|
|
15
|
+
All classes extending `omdNode` are re-exported, allowing you to construct and work with various types of mathematical expressions:
|
|
16
|
+
|
|
17
|
+
- [`omdNode`](./omdNode.md)
|
|
18
|
+
- [`omdBinaryExpressionNode`](./omdBinaryExpressionNode.md)
|
|
19
|
+
- [`omdConstantNode`](./omdConstantNode.md)
|
|
20
|
+
- [`omdEquationNode`](./omdEquationNode.md)
|
|
21
|
+
- [`omdEquationSequenceNode`](./omdEquationSequenceNode.md)
|
|
22
|
+
- [`omdEquationStack`](./omdEquationStack.md)
|
|
23
|
+
- [`omdFunctionNode`](./omdFunctionNode.md)
|
|
24
|
+
- [`omdGroupNode`](./omdGroupNode.md)
|
|
25
|
+
- [`omdLeafNode`](./omdLeafNode.md)
|
|
26
|
+
- [`omdOperationDisplayNode`](./omdOperationDisplayNode.md)
|
|
27
|
+
- [`omdOperatorNode`](./omdOperatorNode.md)
|
|
28
|
+
- [`omdParenthesisNode`](./omdParenthesisNode.md)
|
|
29
|
+
- [`omdPowerNode`](./omdPowerNode.md)
|
|
30
|
+
- [`omdRationalNode`](./omdRationalNode.md)
|
|
31
|
+
- [`omdSqrtNode`](./omdSqrtNode.md)
|
|
32
|
+
- [`omdUnaryExpressionNode`](./omdUnaryExpressionNode.md)
|
|
33
|
+
- [`omdVariableNode`](./omdVariableNode.md)
|
|
34
|
+
|
|
35
|
+
### Visualization Components
|
|
36
|
+
|
|
37
|
+
These classes provide high-level components for rendering and interacting with mathematical expressions:
|
|
38
|
+
|
|
39
|
+
- [`omdStepVisualizer`](./omdStepVisualizer.md)
|
|
40
|
+
- [`omdDisplay`](./omdDisplay.md)
|
|
41
|
+
- [`omdToolbar`](./omdToolbar.md)
|
|
42
|
+
|
|
43
|
+
### Utilities
|
|
44
|
+
|
|
45
|
+
Essential utility functions and classes for parsing, simplification, and configuration management:
|
|
46
|
+
|
|
47
|
+
- `getNodeForAST`: A factory function to get the correct `omdNode` class for a given math.js AST.
|
|
48
|
+
- `simplifyStep`: Applies a single simplification step to an expression.
|
|
49
|
+
- `initializeConfig`: Initializes the OMD configuration.
|
|
50
|
+
- `setConfig`: Sets the OMD configuration.
|
|
51
|
+
- `getDefaultConfig`: Retrieves the default OMD configuration.
|
|
52
|
+
- `omdExpression`: A base class for expressions.
|
|
53
|
+
- `omdColor`: A utility class for working with colors.
|
|
54
|
+
|
|
55
|
+
### `omdHelpers`
|
|
56
|
+
|
|
57
|
+
A collection of convenience functions for common operations:
|
|
58
|
+
|
|
59
|
+
#### `createNodeFromExpression(expression, mathjs)`
|
|
60
|
+
- Creates an `omdNode` instance from a string expression using a provided math.js instance.
|
|
61
|
+
|
|
62
|
+
#### `createEquation(equationString)`
|
|
63
|
+
- Creates an `omdEquationNode` from a string representation of an equation.
|
|
64
|
+
|
|
65
|
+
#### `createStepVisualizer(equationStrings)`
|
|
66
|
+
- Creates an `omdStepVisualizer` instance from an array of equation strings.
|
|
67
|
+
|
|
68
|
+
## Re-Exports
|
|
69
|
+
|
|
70
|
+
The index also re-exports all named exports from the following modules:
|
|
71
|
+
|
|
72
|
+
- `../step-visualizer/omdStepVisualizer.js`
|
|
73
|
+
- `./omdUtilities.js`
|
|
74
|
+
- `../display/omdToolbar.js`
|
|
75
|
+
|
|
76
|
+
This means you can import their functions directly from the main entry point.
|
|
77
|
+
|
|
78
|
+
## Default Export
|
|
79
|
+
|
|
80
|
+
The module also provides a default export, which is an object containing all the re-exported classes and functions, organized into logical groups (`nodes`, `helpers`, etc.). This allows for a more structured import if preferred.
|
|
81
|
+
|
|
82
|
+
```javascript
|
|
83
|
+
import OMD from '@teachinglab/omd';
|
|
84
|
+
|
|
85
|
+
const equation = new OMD.nodes.omdEquationNode(...);
|
|
86
|
+
const display = new OMD.omdDisplay(...);
|
|
87
|
+
const helpers = OMD.helpers;
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Example Usage
|
|
91
|
+
|
|
92
|
+
```javascript
|
|
93
|
+
import { omdDisplay, omdEquationNode, omdHelpers } from '@teachinglab/omd';
|
|
94
|
+
|
|
95
|
+
// Create an equation using a helper
|
|
96
|
+
const equation = omdHelpers.createEquation('2x + 5 = 15');
|
|
97
|
+
|
|
98
|
+
// Create a display and render the equation
|
|
99
|
+
const displayContainer = document.getElementById('math-container');
|
|
100
|
+
const display = new omdDisplay(displayContainer);
|
|
101
|
+
|
|
102
|
+
display.render(equation);
|
|
103
|
+
|
|
104
|
+
// You can also directly access node classes
|
|
105
|
+
const constant = new omdConstantNode({ value: 10 });
|
|
106
106
|
```
|
package/docs/api/main.md
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
# main.js - OMD AI Visual Generator
|
|
2
|
-
|
|
3
|
-
This `main.js` file powers the OMD AI Visual Generator, an interactive web page that uses AI to create mathematical visualizations from natural language prompts.
|
|
4
|
-
|
|
5
|
-
## Core Functionality: The `OMDVisualGenerator` Class
|
|
6
|
-
|
|
7
|
-
The entire application is encapsulated within the `OMDVisualGenerator` class, which manages the UI, handles user input, and orchestrates the process of generating and rendering visuals.
|
|
8
|
-
|
|
9
|
-
### Initialization
|
|
10
|
-
|
|
11
|
-
When the DOM is loaded, a new `OMDVisualGenerator` instance is created. The constructor calls:
|
|
12
|
-
|
|
13
|
-
- `initializeElements()`: Caches references to all necessary DOM elements (input fields, buttons, result panels).
|
|
14
|
-
- `attachEventListeners()`: Sets up all event listeners for user interactions.
|
|
15
|
-
|
|
16
|
-
### Event Listeners
|
|
17
|
-
|
|
18
|
-
The application responds to the following user actions:
|
|
19
|
-
|
|
20
|
-
- **Generate Button Click / Enter Key**: Triggers the `generateVisual()` method.
|
|
21
|
-
- **Example Buttons**: Populate the input field with a predefined request and trigger `generateVisual()`.
|
|
22
|
-
- **Copy SVG Button**: Calls `copySvgToClipboard()` to save the generated visual.
|
|
23
|
-
- **Manual JSON Input**: A separate workflow allows users to bypass the AI and render a visual directly from their own OMD JSON.
|
|
24
|
-
|
|
25
|
-
## Visual Generation Process
|
|
26
|
-
|
|
27
|
-
The core workflow is handled by the `generateVisual()` method:
|
|
28
|
-
|
|
29
|
-
1. **Get Input**: Retrieves the user's natural language request from the input field.
|
|
30
|
-
2. **Set Loading State**: Disables the UI to prevent multiple submissions while a request is in progress.
|
|
31
|
-
3. **API Call**: Sends a `fetch` request to the Netlify serverless function at `/.netlify/functions/ai-omd-lookup`. The user's request is passed as a URL parameter.
|
|
32
|
-
4. **Receive JSON**: The serverless function (not detailed in this file) communicates with an AI service and returns a JSON object that conforms to the OMD specification for a particular visual (e.g., a `balanceHanger` or `tapeDiagram`).
|
|
33
|
-
5. **Display JSON**: The raw JSON response is pretty-printed and displayed in the UI for inspection.
|
|
34
|
-
6. **Render Visual**: The `renderVisual(jsonData)` method is called.
|
|
35
|
-
|
|
36
|
-
## Rendering the Visual (`renderVisual`)
|
|
37
|
-
|
|
38
|
-
This method is responsible for turning the AI-generated JSON into an SVG image:
|
|
39
|
-
|
|
40
|
-
1. **Clear Previous Visual**: Removes any existing SVG from the display area.
|
|
41
|
-
2. **Select OMD Class**: A `switch` statement reads the `omdType` property from the JSON to determine which OMD class to instantiate (e.g., `omdBalanceHanger`, `omdTable`).
|
|
42
|
-
3. **Load Data**: The `loadFromJSON(jsonData)` method of the instantiated OMD object is called, configuring the object based on the AI-provided data.
|
|
43
|
-
4. **Create SVG**: An SVG wrapper is created, and the OMD object's internal SVG group (`omdObject.svgObject`) is appended to it.
|
|
44
|
-
5. **Display SVG**: The final SVG is added to the `visualResult` panel in the DOM.
|
|
45
|
-
|
|
46
|
-
## Manual JSON Input
|
|
47
|
-
|
|
48
|
-
For testing and debugging, users can click the "Manual JSON Input" button to reveal a text area. They can paste their own OMD-compliant JSON and click "Render" to see it visualized, skipping the AI step entirely.
|
|
49
|
-
|
|
50
|
-
## Utility Methods
|
|
51
|
-
|
|
52
|
-
- **`copySvgToClipboard()`**: An advanced feature that converts the generated SVG into a high-resolution PNG and uses the Clipboard API (`navigator.clipboard.write`) to copy it to the user's clipboard.
|
|
53
|
-
- **`setLoading(isLoading)`**: Toggles the disabled state of UI elements.
|
|
54
|
-
- **`showMessage(message, type)` / `showError(message)`**: Displays status messages (e.g., "Generating...", "Error") to the user.
|
|
55
|
-
|
|
56
|
-
## Usage
|
|
57
|
-
|
|
58
|
-
This script is designed to be used with an `index.html` file that provides the necessary UI layout. It allows users to:
|
|
59
|
-
|
|
60
|
-
- Enter a description of a math concept (e.g., "a balance hanger with 2x + 3 on the left and 7 on the right").
|
|
61
|
-
- Click "Generate" to see it visualized by the AI.
|
|
62
|
-
- Inspect the underlying OMD JSON.
|
|
1
|
+
# main.js - OMD AI Visual Generator
|
|
2
|
+
|
|
3
|
+
This `main.js` file powers the OMD AI Visual Generator, an interactive web page that uses AI to create mathematical visualizations from natural language prompts.
|
|
4
|
+
|
|
5
|
+
## Core Functionality: The `OMDVisualGenerator` Class
|
|
6
|
+
|
|
7
|
+
The entire application is encapsulated within the `OMDVisualGenerator` class, which manages the UI, handles user input, and orchestrates the process of generating and rendering visuals.
|
|
8
|
+
|
|
9
|
+
### Initialization
|
|
10
|
+
|
|
11
|
+
When the DOM is loaded, a new `OMDVisualGenerator` instance is created. The constructor calls:
|
|
12
|
+
|
|
13
|
+
- `initializeElements()`: Caches references to all necessary DOM elements (input fields, buttons, result panels).
|
|
14
|
+
- `attachEventListeners()`: Sets up all event listeners for user interactions.
|
|
15
|
+
|
|
16
|
+
### Event Listeners
|
|
17
|
+
|
|
18
|
+
The application responds to the following user actions:
|
|
19
|
+
|
|
20
|
+
- **Generate Button Click / Enter Key**: Triggers the `generateVisual()` method.
|
|
21
|
+
- **Example Buttons**: Populate the input field with a predefined request and trigger `generateVisual()`.
|
|
22
|
+
- **Copy SVG Button**: Calls `copySvgToClipboard()` to save the generated visual.
|
|
23
|
+
- **Manual JSON Input**: A separate workflow allows users to bypass the AI and render a visual directly from their own OMD JSON.
|
|
24
|
+
|
|
25
|
+
## Visual Generation Process
|
|
26
|
+
|
|
27
|
+
The core workflow is handled by the `generateVisual()` method:
|
|
28
|
+
|
|
29
|
+
1. **Get Input**: Retrieves the user's natural language request from the input field.
|
|
30
|
+
2. **Set Loading State**: Disables the UI to prevent multiple submissions while a request is in progress.
|
|
31
|
+
3. **API Call**: Sends a `fetch` request to the Netlify serverless function at `/.netlify/functions/ai-omd-lookup`. The user's request is passed as a URL parameter.
|
|
32
|
+
4. **Receive JSON**: The serverless function (not detailed in this file) communicates with an AI service and returns a JSON object that conforms to the OMD specification for a particular visual (e.g., a `balanceHanger` or `tapeDiagram`).
|
|
33
|
+
5. **Display JSON**: The raw JSON response is pretty-printed and displayed in the UI for inspection.
|
|
34
|
+
6. **Render Visual**: The `renderVisual(jsonData)` method is called.
|
|
35
|
+
|
|
36
|
+
## Rendering the Visual (`renderVisual`)
|
|
37
|
+
|
|
38
|
+
This method is responsible for turning the AI-generated JSON into an SVG image:
|
|
39
|
+
|
|
40
|
+
1. **Clear Previous Visual**: Removes any existing SVG from the display area.
|
|
41
|
+
2. **Select OMD Class**: A `switch` statement reads the `omdType` property from the JSON to determine which OMD class to instantiate (e.g., `omdBalanceHanger`, `omdTable`).
|
|
42
|
+
3. **Load Data**: The `loadFromJSON(jsonData)` method of the instantiated OMD object is called, configuring the object based on the AI-provided data.
|
|
43
|
+
4. **Create SVG**: An SVG wrapper is created, and the OMD object's internal SVG group (`omdObject.svgObject`) is appended to it.
|
|
44
|
+
5. **Display SVG**: The final SVG is added to the `visualResult` panel in the DOM.
|
|
45
|
+
|
|
46
|
+
## Manual JSON Input
|
|
47
|
+
|
|
48
|
+
For testing and debugging, users can click the "Manual JSON Input" button to reveal a text area. They can paste their own OMD-compliant JSON and click "Render" to see it visualized, skipping the AI step entirely.
|
|
49
|
+
|
|
50
|
+
## Utility Methods
|
|
51
|
+
|
|
52
|
+
- **`copySvgToClipboard()`**: An advanced feature that converts the generated SVG into a high-resolution PNG and uses the Clipboard API (`navigator.clipboard.write`) to copy it to the user's clipboard.
|
|
53
|
+
- **`setLoading(isLoading)`**: Toggles the disabled state of UI elements.
|
|
54
|
+
- **`showMessage(message, type)` / `showError(message)`**: Displays status messages (e.g., "Generating...", "Error") to the user.
|
|
55
|
+
|
|
56
|
+
## Usage
|
|
57
|
+
|
|
58
|
+
This script is designed to be used with an `index.html` file that provides the necessary UI layout. It allows users to:
|
|
59
|
+
|
|
60
|
+
- Enter a description of a math concept (e.g., "a balance hanger with 2x + 3 on the left and 7 on the right").
|
|
61
|
+
- Click "Generate" to see it visualized by the AI.
|
|
62
|
+
- Inspect the underlying OMD JSON.
|
|
63
63
|
- Copy the resulting visual as a PNG image.
|