@teachinglab/omd 0.1.3 → 0.1.5
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/canvas/tools/EraserTool.js +1 -1
- package/canvas/tools/PencilTool.js +1 -1
- package/canvas/tools/SelectTool.js +1 -1
- package/docs/api/configuration-options.md +198 -104
- package/docs/api/eventManager.md +83 -68
- package/docs/api/focusFrameManager.md +145 -150
- package/docs/api/index.md +106 -91
- package/docs/api/main.md +63 -58
- package/docs/api/omdBinaryExpressionNode.md +86 -227
- package/docs/api/omdCanvas.md +84 -142
- package/docs/api/omdConfigManager.md +113 -192
- package/docs/api/omdConstantNode.md +53 -117
- package/docs/api/omdDisplay.md +87 -121
- package/docs/api/omdEquationNode.md +174 -161
- package/docs/api/omdEquationSequenceNode.md +259 -301
- package/docs/api/omdEquationStack.md +157 -103
- package/docs/api/omdFunctionNode.md +83 -141
- package/docs/api/omdGroupNode.md +79 -182
- package/docs/api/omdHelpers.md +88 -96
- package/docs/api/omdLeafNode.md +86 -163
- package/docs/api/omdNode.md +202 -101
- package/docs/api/omdOperationDisplayNode.md +118 -139
- package/docs/api/omdOperatorNode.md +92 -127
- package/docs/api/omdParenthesisNode.md +134 -122
- package/docs/api/omdPopup.md +192 -117
- package/docs/api/omdPowerNode.md +132 -127
- package/docs/api/omdRationalNode.md +145 -128
- package/docs/api/omdSimplification.md +79 -110
- package/docs/api/omdSqrtNode.md +144 -79
- package/docs/api/omdStepVisualizer.md +147 -115
- package/docs/api/omdStepVisualizerHighlighting.md +66 -61
- package/docs/api/omdStepVisualizerInteractiveSteps.md +109 -129
- package/docs/api/omdStepVisualizerLayout.md +71 -60
- package/docs/api/omdStepVisualizerTextBoxes.md +77 -68
- package/docs/api/omdToolbar.md +131 -102
- package/docs/api/omdTranscriptionService.md +96 -76
- package/docs/api/omdTreeDiff.md +170 -134
- package/docs/api/omdUnaryExpressionNode.md +137 -174
- package/docs/api/omdUtilities.md +83 -70
- package/docs/api/omdVariableNode.md +123 -148
- package/index.js +2 -2
- package/package.json +1 -1
- /package/canvas/drawing/{segment.js → Segment.js} +0 -0
|
@@ -1,192 +1,113 @@
|
|
|
1
|
-
# omdConfigManager
|
|
2
|
-
|
|
3
|
-
A module for managing the configuration of the OMD library. It handles loading settings from a JSON file, providing default values, and allowing runtime modifications.
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
The configuration is managed as a single JSON object. The system can be initialized with a path to a `omdConfig.json` file, or it will fall back to a default configuration. The manager supports both asynchronous and synchronous access to configuration values.
|
|
8
|
-
|
|
9
|
-
### Default Configuration
|
|
10
|
-
|
|
11
|
-
If no `omdConfig.json` is found, the following default structure is used:
|
|
12
|
-
|
|
13
|
-
```json
|
|
14
|
-
{
|
|
15
|
-
"multiplication": {
|
|
16
|
-
"symbol": "·",
|
|
17
|
-
"forceImplicit": false,
|
|
18
|
-
"implicitCombinations": {
|
|
19
|
-
"constantVariable": true,
|
|
20
|
-
"variableConstant": false,
|
|
21
|
-
"parenthesisAfterVariable": true,
|
|
22
|
-
"parenthesisAfterConstant": true,
|
|
23
|
-
"variableParenthesis": true,
|
|
24
|
-
"parenthesisParenthesis": true,
|
|
25
|
-
"parenthesisVariable": true,
|
|
26
|
-
"parenthesisConstant": true,
|
|
27
|
-
"variableVariable": true
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
"stepVisualizer": {
|
|
31
|
-
"dotSizes": {
|
|
32
|
-
"level0": 8,
|
|
33
|
-
"level1": 6,
|
|
34
|
-
"level2": 4
|
|
35
|
-
},
|
|
36
|
-
"fontWeights": {
|
|
37
|
-
"level0": 400,
|
|
38
|
-
"level1":
|
|
39
|
-
"level2":
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
## Core Functions
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
- **Parameters:**
|
|
115
|
-
- `path` {string} - The path to the value (e.g., `'multiplication.symbol'`).
|
|
116
|
-
- **Returns:** `any` - The value at the specified path.
|
|
117
|
-
|
|
118
|
-
---
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
#### `setConfigValue(path, value)`
|
|
122
|
-
Sets a specific configuration value using a dot-separated path.
|
|
123
|
-
- **Parameters:**
|
|
124
|
-
- `path` {string} - The path to the value.
|
|
125
|
-
- `value` {any} - The new value to set.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
## Utility Functions
|
|
129
|
-
|
|
130
|
-
#### `getMultiplicationSymbol()`
|
|
131
|
-
- **Returns:** `string` - The configured symbol for multiplication.
|
|
132
|
-
|
|
133
|
-
#### `useImplicitMultiplication(combination)`
|
|
134
|
-
- **Parameters:**
|
|
135
|
-
- `combination` {string} (optional) - The context of the multiplication (e.g., `'constantVariable'`).
|
|
136
|
-
- **Returns:** `boolean` - Whether to use implicit multiplication in that context or globally if no combination is provided.
|
|
137
|
-
|
|
138
|
-
#### `getDotRadius(level)`
|
|
139
|
-
- **Parameters:**
|
|
140
|
-
- `level` {number} - The step level (0, 1, or 2).
|
|
141
|
-
- **Returns:** `number` - The configured dot radius for that level in the step visualizer.
|
|
142
|
-
|
|
143
|
-
#### `getFontWeight(level)`
|
|
144
|
-
- **Parameters:**
|
|
145
|
-
- `level` {number} - The step level (0, 1, or 2).
|
|
146
|
-
- **Returns:** `number` - The configured font weight for that level.
|
|
147
|
-
#### `getDefaultConfig()`
|
|
148
|
-
- **Returns:** `Object` - The default configuration object.
|
|
149
|
-
|
|
150
|
-
#### `isEnabled(category, setting)`
|
|
151
|
-
- **Parameters:**
|
|
152
|
-
- `category` {string} - The configuration category (e.g., 'multiplication').
|
|
153
|
-
- `setting` {string} - The specific setting to check.
|
|
154
|
-
- **Returns:** `boolean` - Whether the setting is enabled.
|
|
155
|
-
|
|
156
|
-
#### `updateConfig(category, setting, value)`
|
|
157
|
-
- **Parameters:**
|
|
158
|
-
- `category` {string} - The configuration category.
|
|
159
|
-
- `setting` {string} - The setting to update.
|
|
160
|
-
- `value` {any} - The new value.
|
|
161
|
-
|
|
162
|
-
#### `resetConfig()`
|
|
163
|
-
- **Throws:** Always throws an error. (Direct file editing is required.)
|
|
164
|
-
|
|
165
|
-
#### `reloadConfig()`
|
|
166
|
-
- **Returns:** `Promise<Object>` - Promise that resolves to the reloaded configuration.
|
|
167
|
-
|
|
168
|
-
#### `getConfigAsync()`
|
|
169
|
-
- **Returns:** `Promise<Object>` - Promise that resolves to the configuration object.
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
## Example Usage
|
|
173
|
-
|
|
174
|
-
```javascript
|
|
175
|
-
import { initializeConfig, getConfigValue, setConfigValue, getMultiplicationSymbol } from 'omd-library';
|
|
176
|
-
|
|
177
|
-
// Initialize at the start of your application
|
|
178
|
-
(async () => {
|
|
179
|
-
await initializeConfig();
|
|
180
|
-
|
|
181
|
-
// Get a specific value
|
|
182
|
-
const multSymbol = getConfigValue('multiplication.symbol');
|
|
183
|
-
console.log(`Multiplication symbol is: ${multSymbol}`); // Output: ·
|
|
184
|
-
|
|
185
|
-
// Or use a dedicated utility function
|
|
186
|
-
console.log(`Multiplication symbol is: ${getMultiplicationSymbol()}`); // Output: ·
|
|
187
|
-
|
|
188
|
-
// Change a value at runtime
|
|
189
|
-
setConfigValue('multiplication.symbol', '*');
|
|
190
|
-
console.log(`New multiplication symbol is: ${getMultiplicationSymbol()}`); // Output: *
|
|
191
|
-
})();
|
|
192
|
-
```
|
|
1
|
+
# omdConfigManager
|
|
2
|
+
|
|
3
|
+
A module for managing the configuration of the OMD library. It handles loading settings from a JSON file, providing default values, and allowing runtime modifications.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The configuration is managed as a single JSON object. The system can be initialized with a path to a `omdConfig.json` file, or it will fall back to a default configuration. The manager supports both asynchronous and synchronous access to configuration values.
|
|
8
|
+
|
|
9
|
+
### Default Configuration
|
|
10
|
+
|
|
11
|
+
If no `omdConfig.json` is found, the following default structure is used:
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"multiplication": {
|
|
16
|
+
"symbol": "·",
|
|
17
|
+
"forceImplicit": false,
|
|
18
|
+
"implicitCombinations": {
|
|
19
|
+
"constantVariable": true,
|
|
20
|
+
"variableConstant": false,
|
|
21
|
+
"parenthesisAfterVariable": true,
|
|
22
|
+
"parenthesisAfterConstant": true,
|
|
23
|
+
"variableParenthesis": true,
|
|
24
|
+
"parenthesisParenthesis": true,
|
|
25
|
+
"parenthesisVariable": true,
|
|
26
|
+
"parenthesisConstant": true,
|
|
27
|
+
"variableVariable": true
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"stepVisualizer": {
|
|
31
|
+
"dotSizes": {
|
|
32
|
+
"level0": 8,
|
|
33
|
+
"level1": 6,
|
|
34
|
+
"level2": 4
|
|
35
|
+
},
|
|
36
|
+
"fontWeights": {
|
|
37
|
+
"level0": 400,
|
|
38
|
+
"level1": 400,
|
|
39
|
+
"level2": 400
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Core Functions
|
|
46
|
+
|
|
47
|
+
### `async initializeConfig(configSource)`
|
|
48
|
+
|
|
49
|
+
Loads the configuration from a file or object. It automatically detects the environment (browser or Node.js) to use the appropriate file loading mechanism (`fetch` or `fs`). This should be called once when your application starts.
|
|
50
|
+
|
|
51
|
+
- **`configSource`** (`string` | `object`, optional): A path to a JSON configuration file or a configuration object to use directly.
|
|
52
|
+
- **Returns**: `Promise<void>`
|
|
53
|
+
|
|
54
|
+
### `async getConfig()`
|
|
55
|
+
|
|
56
|
+
Asynchronously gets the entire configuration object. If it hasn't been loaded yet, it will trigger the loading process with default settings.
|
|
57
|
+
|
|
58
|
+
- **Returns**: `Promise<object>` - A promise that resolves to the configuration object.
|
|
59
|
+
|
|
60
|
+
### `getConfigSync()`
|
|
61
|
+
|
|
62
|
+
Synchronously gets the configuration object.
|
|
63
|
+
|
|
64
|
+
**Warning:** If called before `initializeConfig` has completed, this will return the default configuration, not the loaded one.
|
|
65
|
+
|
|
66
|
+
- **Returns**: `object` - The configuration object.
|
|
67
|
+
|
|
68
|
+
### `setConfig(config)`
|
|
69
|
+
|
|
70
|
+
Sets the entire configuration directly, merging it with the default values.
|
|
71
|
+
|
|
72
|
+
- **`config`** (`object`): The configuration object to set.
|
|
73
|
+
|
|
74
|
+
### `getConfigValue(path)`
|
|
75
|
+
|
|
76
|
+
Gets a specific configuration value using a dot-separated path (e.g., `'multiplication.symbol'`).
|
|
77
|
+
|
|
78
|
+
- **Returns**: The value at the specified path.
|
|
79
|
+
|
|
80
|
+
### `setConfigValue(path, value)`
|
|
81
|
+
|
|
82
|
+
Sets a specific configuration value using a dot-separated path.
|
|
83
|
+
|
|
84
|
+
## Utility Functions
|
|
85
|
+
|
|
86
|
+
- **`getMultiplicationSymbol()`**: Returns the configured symbol for multiplication.
|
|
87
|
+
- **`useImplicitMultiplication(combination)`**: Checks if implicit multiplication should be used, either globally or for a specific combination of operand types.
|
|
88
|
+
- **`getDotRadius(level)`**: Gets the dot radius for a given step level in the `omdStepVisualizer`.
|
|
89
|
+
- **`getFontWeight(level)`**: Gets the font weight for a given step level.
|
|
90
|
+
- **`getDefaultConfig()`**: Returns a copy of the default configuration object.
|
|
91
|
+
- **`isEnabled(category, setting)`**: Checks if a specific boolean setting is enabled.
|
|
92
|
+
- **`updateConfig(category, setting, value)`**: Updates a top-level configuration setting.
|
|
93
|
+
- **`resetConfig()`**: Throws an error. Direct file editing is required to reset the configuration.
|
|
94
|
+
- **`async reloadConfig()`**: Forces a reload of the configuration from the original file path.
|
|
95
|
+
- **`async getConfigAsync()`**: An alias for `getConfig()`.
|
|
96
|
+
|
|
97
|
+
## Example
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
import { initializeConfig, getConfigValue, setConfigValue } from '@teachinglab/omd';
|
|
101
|
+
|
|
102
|
+
// Initialize at the start of your application
|
|
103
|
+
(async () => {
|
|
104
|
+
await initializeConfig();
|
|
105
|
+
|
|
106
|
+
// Get a specific value
|
|
107
|
+
const multSymbol = getConfigValue('multiplication.symbol'); // -> '·'
|
|
108
|
+
|
|
109
|
+
// Change a value at runtime
|
|
110
|
+
setConfigValue('multiplication.symbol', '*');
|
|
111
|
+
const newSymbol = getConfigValue('multiplication.symbol'); // -> '*'
|
|
112
|
+
})();
|
|
113
|
+
```
|
|
@@ -1,117 +1,53 @@
|
|
|
1
|
-
# omdConstantNode
|
|
2
|
-
|
|
3
|
-
Represents a numeric constant in a mathematical expression. This is a leaf node, meaning it
|
|
4
|
-
|
|
5
|
-
## Class
|
|
6
|
-
|
|
7
|
-
```javascript
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
-
|
|
54
|
-
|
|
55
|
-
---
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
#### `evaluate()`
|
|
59
|
-
Evaluates the node, which for a constant simply returns its value.
|
|
60
|
-
- **Returns:** `number` - The numeric value.
|
|
61
|
-
|
|
62
|
-
---
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
#### `getRationalValue()`
|
|
66
|
-
Gets the value as a rational number (a fraction with a denominator of 1).
|
|
67
|
-
- **Returns:** `Object` - An object `{ num: number, den: 1 }`.
|
|
68
|
-
|
|
69
|
-
---
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
#### `toMathJSNode()`
|
|
73
|
-
Converts the node to its math.js AST representation.
|
|
74
|
-
- **Returns:** `Object` - A math.js-compatible AST node for a constant, with a `clone()` method for compatibility.
|
|
75
|
-
|
|
76
|
-
---
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
#### `simplify()`
|
|
80
|
-
A constant cannot be simplified further.
|
|
81
|
-
- **Returns:** `Object` - An object indicating failure: `{ success: false, ... }`.
|
|
82
|
-
|
|
83
|
-
---
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
#### `toString()`
|
|
87
|
-
Converts the node to its string representation.
|
|
88
|
-
- **Returns:** `string` - The numeric value as a string.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
#### `isConstant()`
|
|
92
|
-
Checks if the node is a constant (always true for omdConstantNode).
|
|
93
|
-
- **Returns:** `boolean`
|
|
94
|
-
|
|
95
|
-
### Example
|
|
96
|
-
|
|
97
|
-
```javascript
|
|
98
|
-
// Create a constant node from a number
|
|
99
|
-
const pi = omdConstantNode.fromValue(3.14159);
|
|
100
|
-
|
|
101
|
-
// Set its font size and render it
|
|
102
|
-
pi.setFontSize(24);
|
|
103
|
-
pi.initialize(); // Computes dimensions and layout
|
|
104
|
-
|
|
105
|
-
// Get its value
|
|
106
|
-
console.log(pi.getValue()); // 3.14159
|
|
107
|
-
|
|
108
|
-
// Add it to an SVG container to display
|
|
109
|
-
const svgContainer = new jsvgContainer();
|
|
110
|
-
svgContainer.addChild(pi);
|
|
111
|
-
document.body.appendChild(svgContainer.svgObject);
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
### See Also
|
|
115
|
-
|
|
116
|
-
- [`omdLeafNode`](./omdLeafNode.md) - The parent class.
|
|
117
|
-
- [`omdVariableNode`](./omdVariableNode.md) - For symbolic variables like 'x'.
|
|
1
|
+
# omdConstantNode
|
|
2
|
+
|
|
3
|
+
Represents a numeric constant in a mathematical expression. This node is a leaf node in the expression tree, meaning it does not have any children.
|
|
4
|
+
|
|
5
|
+
## Class Definition
|
|
6
|
+
|
|
7
|
+
```javascript
|
|
8
|
+
export class omdConstantNode extends omdLeafNode
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Constructor
|
|
12
|
+
|
|
13
|
+
### `new omdConstantNode(ast)`
|
|
14
|
+
|
|
15
|
+
Creates a new `omdConstantNode` instance.
|
|
16
|
+
|
|
17
|
+
- **`ast`** (`object`): The abstract syntax tree (AST) node from a parser like math.js. It must contain:
|
|
18
|
+
- `value`: The numeric value of the constant.
|
|
19
|
+
|
|
20
|
+
## Public Properties
|
|
21
|
+
|
|
22
|
+
- **`value`** (`number`): The numeric value of the constant.
|
|
23
|
+
|
|
24
|
+
## Public Methods
|
|
25
|
+
|
|
26
|
+
### `isConstant()`
|
|
27
|
+
|
|
28
|
+
Checks if the node represents a constant value.
|
|
29
|
+
|
|
30
|
+
- **Returns**: `boolean` - Always `true` for `omdConstantNode`.
|
|
31
|
+
|
|
32
|
+
### `evaluate()`
|
|
33
|
+
|
|
34
|
+
Evaluates the constant node. Since it's a constant, it simply returns its value.
|
|
35
|
+
|
|
36
|
+
- **Returns**: `number` - The numeric value of the constant.
|
|
37
|
+
|
|
38
|
+
### `toMathJSNode()`
|
|
39
|
+
|
|
40
|
+
Converts the node back into a math.js-compatible AST format.
|
|
41
|
+
|
|
42
|
+
- **Returns**: `object` - A math.js ConstantNode.
|
|
43
|
+
|
|
44
|
+
### `toString()`
|
|
45
|
+
|
|
46
|
+
Converts the constant node into its string representation.
|
|
47
|
+
|
|
48
|
+
- **Returns**: `string` - The string representation of the constant.
|
|
49
|
+
|
|
50
|
+
## Internal Methods
|
|
51
|
+
|
|
52
|
+
- **`computeDimensions()`**: Calculates the bounding box of the constant.
|
|
53
|
+
- **`updateLayout()`**: Positions the constant within its bounding box.
|