@teachinglab/omd 0.1.4 → 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.
Files changed (42) 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/package.json +1 -1
@@ -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": 300,
39
- "level2": 200
40
- }
41
- }
42
- }
43
- ```
44
-
45
- ## Core Functions
46
-
47
-
48
- ```javascript
49
- import {
50
- initializeConfig,
51
- getConfig,
52
- getConfigSync,
53
- setConfig,
54
- getConfigValue,
55
- setConfigValue,
56
- getDefaultConfig,
57
- isEnabled,
58
- useImplicitMultiplication,
59
- getMultiplicationSymbol,
60
- updateConfig,
61
- resetConfig,
62
- reloadConfig,
63
- getConfigAsync,
64
- getDotRadius,
65
- getFontWeight
66
- } from 'omd-library';
67
- ```
68
-
69
-
70
- #### `initializeConfig(configSource)`
71
- Loads the configuration. This should be called once when your application starts.
72
- - **Parameters:**
73
- - `configSource` {string | Object} (optional) - A path to a JSON configuration file or a configuration object to use directly.
74
- - **Returns:** `Promise<void>`
75
-
76
- ```javascript
77
- // Load from default path ('./omd/config/omdConfig.json')
78
- await initializeConfig();
79
-
80
- // Or load from a specific path
81
- await initializeConfig('./my-custom-config.json');
82
-
83
- // Or provide a config object directly
84
- await initializeConfig({ multiplication: { symbol: '*' } });
85
- ```
86
-
87
- ---
88
-
89
-
90
- #### `getConfig()`
91
- Asynchronously gets the entire configuration object. Loads it with defaults if it hasn't been loaded yet.
92
- - **Returns:** `Promise<Object>` - A promise that resolves to the configuration object.
93
-
94
- ---
95
-
96
-
97
- #### `getConfigSync()`
98
- Synchronously gets the entire configuration object. **Note:** If the configuration has not been loaded yet, this will return the default configuration.
99
- - **Returns:** `Object` - The configuration object.
100
-
101
- ---
102
-
103
-
104
- #### `setConfig(config)`
105
- Sets the entire configuration, merging it with the default values.
106
- - **Parameters:**
107
- - `config` {Object} - The configuration object to set.
108
-
109
- ---
110
-
111
-
112
- #### `getConfigValue(path)`
113
- Gets a specific configuration value using a dot-separated path.
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 has no children.
4
-
5
- ## Class: `omdConstantNode extends omdLeafNode`
6
-
7
- ```javascript
8
- import { omdConstantNode } from './omd/nodes/omdConstantNode.js';
9
- ```
10
-
11
- ### Constructor
12
-
13
- ```javascript
14
- new omdConstantNode(nodeData)
15
- ```
16
-
17
-
18
- **Parameters:**
19
- - `nodeData` {Object|number} - The math.js AST node data (should have a `value` property) or a raw numeric value.
20
-
21
- **Description:**
22
- Creates a node representing a numeric constant. This is typically done automatically by the parser when an expression is processed.
23
-
24
- ### Static Methods
25
-
26
-
27
- #### `fromValue(value)`
28
- Creates an `omdConstantNode` from a simple numeric value.
29
-
30
- ```javascript
31
- const constantNode = omdConstantNode.fromValue(42);
32
- ```
33
- - **Parameters:**
34
- - `value` {number} - The numeric value for the constant.
35
- - **Returns:** `omdConstantNode` A new instance of `omdConstantNode`.
36
-
37
- ### Properties
38
-
39
- Inherits all properties from [`omdLeafNode`](./omdLeafNode.md), plus:
40
-
41
-
42
- #### `number`
43
- - **Type:** `number`
44
- - **Description:** The numeric value of the constant.
45
-
46
- ### Methods
47
-
48
- Inherits all methods from [`omdLeafNode`](./omdLeafNode.md). Key methods include:
49
-
50
-
51
- #### `getValue()`
52
- Gets the numeric value of the constant.
53
- - **Returns:** `number` - The constant's value.
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.