@teachinglab/omd 0.3.0 → 0.3.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.
Files changed (57) hide show
  1. package/docs/api/configuration-options.md +198 -198
  2. package/docs/api/eventManager.md +82 -82
  3. package/docs/api/focusFrameManager.md +144 -144
  4. package/docs/api/index.md +105 -105
  5. package/docs/api/main.md +62 -62
  6. package/docs/api/omdBinaryExpressionNode.md +86 -86
  7. package/docs/api/omdCanvas.md +83 -83
  8. package/docs/api/omdConfigManager.md +112 -112
  9. package/docs/api/omdConstantNode.md +52 -52
  10. package/docs/api/omdDisplay.md +87 -87
  11. package/docs/api/omdEquationNode.md +174 -174
  12. package/docs/api/omdEquationSequenceNode.md +258 -258
  13. package/docs/api/omdEquationStack.md +156 -156
  14. package/docs/api/omdFunctionNode.md +82 -82
  15. package/docs/api/omdGroupNode.md +78 -78
  16. package/docs/api/omdHelpers.md +87 -87
  17. package/docs/api/omdLeafNode.md +85 -85
  18. package/docs/api/omdNode.md +201 -201
  19. package/docs/api/omdOperationDisplayNode.md +117 -117
  20. package/docs/api/omdOperatorNode.md +91 -91
  21. package/docs/api/omdParenthesisNode.md +133 -133
  22. package/docs/api/omdPopup.md +191 -191
  23. package/docs/api/omdPowerNode.md +131 -131
  24. package/docs/api/omdRationalNode.md +144 -144
  25. package/docs/api/omdSimplification.md +78 -78
  26. package/docs/api/omdSqrtNode.md +144 -144
  27. package/docs/api/omdStepVisualizer.md +146 -146
  28. package/docs/api/omdStepVisualizerHighlighting.md +65 -65
  29. package/docs/api/omdStepVisualizerInteractiveSteps.md +108 -108
  30. package/docs/api/omdStepVisualizerLayout.md +70 -70
  31. package/docs/api/omdStepVisualizerTextBoxes.md +76 -76
  32. package/docs/api/omdTranscriptionService.md +95 -95
  33. package/docs/api/omdTreeDiff.md +169 -169
  34. package/docs/api/omdUnaryExpressionNode.md +137 -137
  35. package/docs/api/omdUtilities.md +82 -82
  36. package/docs/api/omdVariableNode.md +123 -123
  37. package/omd/nodes/omdConstantNode.js +141 -141
  38. package/omd/nodes/omdGroupNode.js +67 -67
  39. package/omd/nodes/omdLeafNode.js +76 -76
  40. package/omd/nodes/omdOperatorNode.js +108 -108
  41. package/omd/nodes/omdParenthesisNode.js +292 -292
  42. package/omd/nodes/omdPowerNode.js +235 -235
  43. package/omd/nodes/omdRationalNode.js +295 -295
  44. package/omd/nodes/omdVariableNode.js +122 -122
  45. package/omd/simplification/omdSimplification.js +140 -140
  46. package/omd/step-visualizer/omdStepVisualizer.js +947 -947
  47. package/omd/step-visualizer/omdStepVisualizerLayout.js +892 -892
  48. package/package.json +2 -1
  49. package/src/index.js +11 -0
  50. package/src/omdBalanceHanger.js +2 -1
  51. package/src/omdEquation.js +1 -1
  52. package/src/omdNumber.js +1 -1
  53. package/src/omdNumberLine.js +13 -7
  54. package/src/omdRatioChart.js +19 -0
  55. package/src/omdShapes.js +1 -1
  56. package/src/omdTapeDiagram.js +1 -1
  57. package/src/omdTerm.js +1 -1
@@ -1,137 +1,137 @@
1
- # omdUnaryExpressionNode
2
-
3
- Represents unary operations (like negation) in mathematical expressions (e.g., `-x`, `-(a + b)`). This node handles rendering, layout, evaluation, and conversion to math.js AST for expressions with a single operand.
4
-
5
- ## Class Definition
6
-
7
- ```javascript
8
- export class omdUnaryExpressionNode extends omdNode
9
- ```
10
-
11
- ## Constructor
12
-
13
- ### `new omdUnaryExpressionNode(ast)`
14
-
15
- Creates a new `omdUnaryExpressionNode` instance.
16
-
17
- - **`ast`** (`object`): The math.js AST node for the unary operation. It must contain:
18
- - `args`: An array with exactly one operand AST node.
19
- - `op`: The operator symbol (e.g., `'-'`, `'+'`).
20
- - `fn`: The operation name (e.g., `'unaryMinus'`, `'unaryPlus'`).
21
-
22
- During construction, it creates an `omdOperatorNode` for the unary operator and an `omdNode` for the operand. It throws an error if the AST does not have exactly one argument.
23
-
24
- ## Static Methods
25
-
26
- ### `fromString(expressionString)`
27
-
28
- Creates an `omdUnaryExpressionNode` from a string representation of a unary expression. Requires `window.math` (math.js) to be available globally for parsing.
29
-
30
- - **`expressionString`** (`string`): The unary expression as a string (e.g., `"-x"`, `"-(a+b)"`).
31
- - **Returns**: `omdUnaryExpressionNode` - A new instance.
32
- - **Throws**: `Error` if `math.js` is not available, if the string cannot be parsed, or if it does not represent a valid unary minus operation.
33
-
34
- ## Public Properties
35
-
36
- - **`op`** (`omdOperatorNode`): The `omdOperatorNode` representing the unary operator (e.g., `-`).
37
- - **`operand`** (`omdNode`): The `omdNode` representing the expression being operated on.
38
- - **`operation`** (`string`): The name of the operation (e.g., `'unaryMinus'`).
39
-
40
- ## Public Methods
41
-
42
- ### `computeDimensions()`
43
-
44
- Calculates the dimensions of the unary expression node. It sums the widths of the operator and the operand to get the total width. The height is the maximum of the operator's and operand's heights. No extra spacing is added between the unary operator and its operand.
45
-
46
- - **Overrides**: `omdNode.computeDimensions()`.
47
-
48
- ### `updateLayout()`
49
-
50
- Updates the layout of the unary expression node. It positions the operator to the left and the operand to its right, both vertically centered within the node's total height.
51
-
52
- - **Overrides**: `omdNode.updateLayout()`.
53
-
54
- ### `clone()`
55
-
56
- Creates a deep, structural clone of the unary expression node, including its `op` and `operand` nodes. The cloned node's `provenance` array is updated to include the original node's ID.
57
-
58
- - **Returns**: `omdUnaryExpressionNode` - A new, identical instance of the unary expression node.
59
-
60
- ### `toMathJSNode()`
61
-
62
- Converts the `omdUnaryExpressionNode` back into its math.js AST representation. It creates an `OperatorNode` with the unary operator and the converted operand AST.
63
-
64
- - **Returns**: `object` - A math.js `OperatorNode` for the unary operation. The returned object also includes a `clone` method for compatibility.
65
-
66
- ### `toString()`
67
-
68
- Converts the unary expression node to its string representation. It adds parentheses around the operand if `needsParentheses()` returns `true` (e.g., for binary expressions).
69
-
70
- - **Returns**: `string` - Format: `"-operand"` or `"-(operand)"`.
71
-
72
- ### `needsParentheses()`
73
-
74
- Checks if the operand needs to be wrapped in parentheses when converted to a string. This is typically `true` if the operand is a binary expression, to maintain correct order of operations.
75
-
76
- - **Returns**: `boolean` - `true` if parentheses are required around the operand.
77
-
78
- ### `evaluate(variables)`
79
-
80
- Evaluates the unary expression. It evaluates the `operand` and then applies the unary operation (e.g., negation for `'-'`).
81
-
82
- - **`variables`** (`object`): A map of variable names to their numeric values.
83
- - **Returns**: `number` - The result of the unary operation, or `NaN` if the operand cannot be evaluated to a number.
84
-
85
- ## Internal Methods
86
-
87
- - **`createOperatorNode(ast)`**: Creates an `omdOperatorNode` for the unary operator from its AST, setting its parent to this node.
88
- - **`createExpressionNode(ast)`**: Creates an `omdNode` instance for the operand from its AST, setting its parent to this node.
89
-
90
- ## Example
91
-
92
- ```javascript
93
- import { omdUnaryExpressionNode } from '@teachinglab/omd';
94
- import * as math from 'mathjs';
95
-
96
- // Create from AST: -x
97
- const node = new omdUnaryExpressionNode({
98
- type: 'OperatorNode',
99
- op: '-',
100
- fn: 'unaryMinus',
101
- args: [
102
- { type: 'SymbolNode', name: 'x' }
103
- ]
104
- });
105
-
106
- // Create from AST: -(x + 1)
107
- const complex = new omdUnaryExpressionNode({
108
- type: 'OperatorNode',
109
- op: '-',
110
- fn: 'unaryMinus',
111
- args: [{
112
- type: 'OperatorNode',
113
- op: '+',
114
- fn: 'add',
115
- args: [
116
- { type: 'SymbolNode', name: 'x' },
117
- { type: 'ConstantNode', value: 1 }
118
- ]
119
- }]
120
- });
121
-
122
- // Render and layout
123
- node.setFontSize(24);
124
- node.initialize();
125
-
126
- // Add to an SVG container to display
127
- // const svgContainer = new jsvgContainer();
128
- // svgContainer.addChild(node);
129
- // document.body.appendChild(svgContainer.svgObject);
130
- ```
131
-
132
- ## See Also
133
-
134
- - [`omdNode`](./omdNode.md) - Parent class.
135
- - [`omdOperatorNode`](./omdOperatorNode.md) - For the operator symbol.
136
- - [`omdBinaryExpressionNode`](./omdBinaryExpressionNode.md) - Often used for complex operands within a unary expression.
137
- - [`omdConstantNode`](./omdConstantNode.md) - For numeric operands.
1
+ # omdUnaryExpressionNode
2
+
3
+ Represents unary operations (like negation) in mathematical expressions (e.g., `-x`, `-(a + b)`). This node handles rendering, layout, evaluation, and conversion to math.js AST for expressions with a single operand.
4
+
5
+ ## Class Definition
6
+
7
+ ```javascript
8
+ export class omdUnaryExpressionNode extends omdNode
9
+ ```
10
+
11
+ ## Constructor
12
+
13
+ ### `new omdUnaryExpressionNode(ast)`
14
+
15
+ Creates a new `omdUnaryExpressionNode` instance.
16
+
17
+ - **`ast`** (`object`): The math.js AST node for the unary operation. It must contain:
18
+ - `args`: An array with exactly one operand AST node.
19
+ - `op`: The operator symbol (e.g., `'-'`, `'+'`).
20
+ - `fn`: The operation name (e.g., `'unaryMinus'`, `'unaryPlus'`).
21
+
22
+ During construction, it creates an `omdOperatorNode` for the unary operator and an `omdNode` for the operand. It throws an error if the AST does not have exactly one argument.
23
+
24
+ ## Static Methods
25
+
26
+ ### `fromString(expressionString)`
27
+
28
+ Creates an `omdUnaryExpressionNode` from a string representation of a unary expression. Requires `window.math` (math.js) to be available globally for parsing.
29
+
30
+ - **`expressionString`** (`string`): The unary expression as a string (e.g., `"-x"`, `"-(a+b)"`).
31
+ - **Returns**: `omdUnaryExpressionNode` - A new instance.
32
+ - **Throws**: `Error` if `math.js` is not available, if the string cannot be parsed, or if it does not represent a valid unary minus operation.
33
+
34
+ ## Public Properties
35
+
36
+ - **`op`** (`omdOperatorNode`): The `omdOperatorNode` representing the unary operator (e.g., `-`).
37
+ - **`operand`** (`omdNode`): The `omdNode` representing the expression being operated on.
38
+ - **`operation`** (`string`): The name of the operation (e.g., `'unaryMinus'`).
39
+
40
+ ## Public Methods
41
+
42
+ ### `computeDimensions()`
43
+
44
+ Calculates the dimensions of the unary expression node. It sums the widths of the operator and the operand to get the total width. The height is the maximum of the operator's and operand's heights. No extra spacing is added between the unary operator and its operand.
45
+
46
+ - **Overrides**: `omdNode.computeDimensions()`.
47
+
48
+ ### `updateLayout()`
49
+
50
+ Updates the layout of the unary expression node. It positions the operator to the left and the operand to its right, both vertically centered within the node's total height.
51
+
52
+ - **Overrides**: `omdNode.updateLayout()`.
53
+
54
+ ### `clone()`
55
+
56
+ Creates a deep, structural clone of the unary expression node, including its `op` and `operand` nodes. The cloned node's `provenance` array is updated to include the original node's ID.
57
+
58
+ - **Returns**: `omdUnaryExpressionNode` - A new, identical instance of the unary expression node.
59
+
60
+ ### `toMathJSNode()`
61
+
62
+ Converts the `omdUnaryExpressionNode` back into its math.js AST representation. It creates an `OperatorNode` with the unary operator and the converted operand AST.
63
+
64
+ - **Returns**: `object` - A math.js `OperatorNode` for the unary operation. The returned object also includes a `clone` method for compatibility.
65
+
66
+ ### `toString()`
67
+
68
+ Converts the unary expression node to its string representation. It adds parentheses around the operand if `needsParentheses()` returns `true` (e.g., for binary expressions).
69
+
70
+ - **Returns**: `string` - Format: `"-operand"` or `"-(operand)"`.
71
+
72
+ ### `needsParentheses()`
73
+
74
+ Checks if the operand needs to be wrapped in parentheses when converted to a string. This is typically `true` if the operand is a binary expression, to maintain correct order of operations.
75
+
76
+ - **Returns**: `boolean` - `true` if parentheses are required around the operand.
77
+
78
+ ### `evaluate(variables)`
79
+
80
+ Evaluates the unary expression. It evaluates the `operand` and then applies the unary operation (e.g., negation for `'-'`).
81
+
82
+ - **`variables`** (`object`): A map of variable names to their numeric values.
83
+ - **Returns**: `number` - The result of the unary operation, or `NaN` if the operand cannot be evaluated to a number.
84
+
85
+ ## Internal Methods
86
+
87
+ - **`createOperatorNode(ast)`**: Creates an `omdOperatorNode` for the unary operator from its AST, setting its parent to this node.
88
+ - **`createExpressionNode(ast)`**: Creates an `omdNode` instance for the operand from its AST, setting its parent to this node.
89
+
90
+ ## Example
91
+
92
+ ```javascript
93
+ import { omdUnaryExpressionNode } from '@teachinglab/omd';
94
+ import * as math from 'mathjs';
95
+
96
+ // Create from AST: -x
97
+ const node = new omdUnaryExpressionNode({
98
+ type: 'OperatorNode',
99
+ op: '-',
100
+ fn: 'unaryMinus',
101
+ args: [
102
+ { type: 'SymbolNode', name: 'x' }
103
+ ]
104
+ });
105
+
106
+ // Create from AST: -(x + 1)
107
+ const complex = new omdUnaryExpressionNode({
108
+ type: 'OperatorNode',
109
+ op: '-',
110
+ fn: 'unaryMinus',
111
+ args: [{
112
+ type: 'OperatorNode',
113
+ op: '+',
114
+ fn: 'add',
115
+ args: [
116
+ { type: 'SymbolNode', name: 'x' },
117
+ { type: 'ConstantNode', value: 1 }
118
+ ]
119
+ }]
120
+ });
121
+
122
+ // Render and layout
123
+ node.setFontSize(24);
124
+ node.initialize();
125
+
126
+ // Add to an SVG container to display
127
+ // const svgContainer = new jsvgContainer();
128
+ // svgContainer.addChild(node);
129
+ // document.body.appendChild(svgContainer.svgObject);
130
+ ```
131
+
132
+ ## See Also
133
+
134
+ - [`omdNode`](./omdNode.md) - Parent class.
135
+ - [`omdOperatorNode`](./omdOperatorNode.md) - For the operator symbol.
136
+ - [`omdBinaryExpressionNode`](./omdBinaryExpressionNode.md) - Often used for complex operands within a unary expression.
137
+ - [`omdConstantNode`](./omdConstantNode.md) - For numeric operands.
@@ -1,83 +1,83 @@
1
- # omdUtilities
2
-
3
- This module provides a collection of utility functions primarily used for mapping math.js AST nodes to OMD node classes, determining rendering behavior, and calculating text dimensions. These functions are internal helpers that support the core OMD node system.
4
-
5
- ## Functions
6
-
7
- ### `astToOmdType(type, ast)`
8
-
9
- Maps a math.js AST node type to its corresponding OMD node class. This function is crucial for dynamically creating the correct `omdNode` subclass based on the parsed expression.
10
-
11
- - **`type`** (`string`): The `type` property of the AST node (e.g., `"OperatorNode"`, `"ParenthesisNode"`).
12
- - **`ast`** (`object`): The full AST node object, which may contain additional context (e.g., `op` for `OperatorNode`, `fn` for `FunctionNode`).
13
- - **Returns**: `class` - The appropriate `omdNode` class constructor.
14
-
15
- **Detailed Logic:**
16
-
17
- - **`AssignmentNode`**: Returns `omdEquationNode`.
18
- - **`OperatorNode`**:
19
- - If `op` is `'-'` and `args.length` is `1` (unary minus), returns `omdUnaryExpressionNode`.
20
- - If `op` is `'='`, returns `omdEquationNode`.
21
- - If `op` is `'^'`, returns `omdPowerNode`.
22
- - If `op` is `'/'`, returns `omdRationalNode`.
23
- - Otherwise (binary operator), returns `omdBinaryExpressionNode`.
24
- - **`ParenthesisNode`**: Returns `omdParenthesisNode`.
25
- - **`ConstantNode`**: Returns `omdConstantNode`.
26
- - **`SymbolNode`**: Returns `omdVariableNode`.
27
- - **`FunctionNode`**:
28
- - If `fn.name` or `name` is `'multiply'` and `ast.implicit` is `true` (implicit multiplication), returns `omdBinaryExpressionNode`.
29
- - If `fn.name` or `name` is `'sqrt'`, returns `omdSqrtNode`.
30
- - Otherwise, returns `omdFunctionNode`.
31
- - **Default**: Returns `omdNode`.
32
-
33
- ### `getNodeForAST(ast)`
34
-
35
- A wrapper function that takes a complete math.js AST node and returns the corresponding OMD node class. It uses `astToOmdType` internally, handling cases where the AST might have a `mathjs` property indicating its type.
36
-
37
- - **`ast`** (`object`): The math.js AST node.
38
- - **Returns**: `class` - The appropriate `omdNode` class constructor.
39
-
40
- ### `getTextBounds(text, fontSize)`
41
-
42
- Calculates the rendered width and height of a given text string at a specific font size. This is achieved by creating a temporary, hidden `<span>` element in the DOM, applying the text and styling, measuring its dimensions, and then removing it.
43
-
44
- - **`text`** (`string`): The text content to measure.
45
- - **`fontSize`** (`number`): The font size in pixels.
46
- - **Returns**: `object` - An object with `width` and `height` properties.
47
-
48
- ### `shouldUseFractionNotation(ast)`
49
-
50
- Determines whether a division operation (represented by an AST node) should be rendered as a fraction (stacked numerator over denominator) or as a linear division (e.g., `a / b`). This decision is based on the complexity of the numerator and denominator.
51
-
52
- - **`ast`** (`object`): The AST node representing a division operation.
53
- - **Returns**: `boolean` - `true` if the division should be rendered as a fraction, `false` otherwise.
54
-
55
- ### `isComplexExpression(ast)`
56
-
57
- Checks if an AST node represents a "complex" expression, typically one that contains multiple operations or nested structures. This function is used by `shouldUseFractionNotation` to decide on the appropriate rendering style for fractions.
58
-
59
- - **`ast`** (`object`): The AST node to check.
60
- - **Returns**: `boolean` - `true` if the expression is considered complex, `false` otherwise.
61
-
62
- ## Example
63
-
64
- ```javascript
65
- import { getNodeForAST, getTextBounds } from '@teachinglab/omd'; // Assuming @teachinglab/omd exports these
66
- import * as math from 'mathjs';
67
-
68
- // Example of getting a node class for an expression
69
- const astExpression = math.parse('x + 2');
70
- const NodeClassExpression = getNodeForAST(astExpression);
71
- const nodeExpression = new NodeClassExpression(astExpression);
72
- console.log(nodeExpression.type); // e.g., "omdBinaryExpressionNode"
73
-
74
- // Example of getting a node class for an equation
75
- const astEquation = math.parse('y = 2x');
76
- const NodeClassEquation = getNodeForAST(astEquation);
77
- const nodeEquation = new NodeClassEquation(astEquation);
78
- console.log(nodeEquation.type); // "omdEquationNode"
79
-
80
- // Example of getting text bounds
81
- const bounds = getTextBounds('Hello World', 24);
82
- console.log(`Text width: ${bounds.width}, height: ${bounds.height}`);
1
+ # omdUtilities
2
+
3
+ This module provides a collection of utility functions primarily used for mapping math.js AST nodes to OMD node classes, determining rendering behavior, and calculating text dimensions. These functions are internal helpers that support the core OMD node system.
4
+
5
+ ## Functions
6
+
7
+ ### `astToOmdType(type, ast)`
8
+
9
+ Maps a math.js AST node type to its corresponding OMD node class. This function is crucial for dynamically creating the correct `omdNode` subclass based on the parsed expression.
10
+
11
+ - **`type`** (`string`): The `type` property of the AST node (e.g., `"OperatorNode"`, `"ParenthesisNode"`).
12
+ - **`ast`** (`object`): The full AST node object, which may contain additional context (e.g., `op` for `OperatorNode`, `fn` for `FunctionNode`).
13
+ - **Returns**: `class` - The appropriate `omdNode` class constructor.
14
+
15
+ **Detailed Logic:**
16
+
17
+ - **`AssignmentNode`**: Returns `omdEquationNode`.
18
+ - **`OperatorNode`**:
19
+ - If `op` is `'-'` and `args.length` is `1` (unary minus), returns `omdUnaryExpressionNode`.
20
+ - If `op` is `'='`, returns `omdEquationNode`.
21
+ - If `op` is `'^'`, returns `omdPowerNode`.
22
+ - If `op` is `'/'`, returns `omdRationalNode`.
23
+ - Otherwise (binary operator), returns `omdBinaryExpressionNode`.
24
+ - **`ParenthesisNode`**: Returns `omdParenthesisNode`.
25
+ - **`ConstantNode`**: Returns `omdConstantNode`.
26
+ - **`SymbolNode`**: Returns `omdVariableNode`.
27
+ - **`FunctionNode`**:
28
+ - If `fn.name` or `name` is `'multiply'` and `ast.implicit` is `true` (implicit multiplication), returns `omdBinaryExpressionNode`.
29
+ - If `fn.name` or `name` is `'sqrt'`, returns `omdSqrtNode`.
30
+ - Otherwise, returns `omdFunctionNode`.
31
+ - **Default**: Returns `omdNode`.
32
+
33
+ ### `getNodeForAST(ast)`
34
+
35
+ A wrapper function that takes a complete math.js AST node and returns the corresponding OMD node class. It uses `astToOmdType` internally, handling cases where the AST might have a `mathjs` property indicating its type.
36
+
37
+ - **`ast`** (`object`): The math.js AST node.
38
+ - **Returns**: `class` - The appropriate `omdNode` class constructor.
39
+
40
+ ### `getTextBounds(text, fontSize)`
41
+
42
+ Calculates the rendered width and height of a given text string at a specific font size. This is achieved by creating a temporary, hidden `<span>` element in the DOM, applying the text and styling, measuring its dimensions, and then removing it.
43
+
44
+ - **`text`** (`string`): The text content to measure.
45
+ - **`fontSize`** (`number`): The font size in pixels.
46
+ - **Returns**: `object` - An object with `width` and `height` properties.
47
+
48
+ ### `shouldUseFractionNotation(ast)`
49
+
50
+ Determines whether a division operation (represented by an AST node) should be rendered as a fraction (stacked numerator over denominator) or as a linear division (e.g., `a / b`). This decision is based on the complexity of the numerator and denominator.
51
+
52
+ - **`ast`** (`object`): The AST node representing a division operation.
53
+ - **Returns**: `boolean` - `true` if the division should be rendered as a fraction, `false` otherwise.
54
+
55
+ ### `isComplexExpression(ast)`
56
+
57
+ Checks if an AST node represents a "complex" expression, typically one that contains multiple operations or nested structures. This function is used by `shouldUseFractionNotation` to decide on the appropriate rendering style for fractions.
58
+
59
+ - **`ast`** (`object`): The AST node to check.
60
+ - **Returns**: `boolean` - `true` if the expression is considered complex, `false` otherwise.
61
+
62
+ ## Example
63
+
64
+ ```javascript
65
+ import { getNodeForAST, getTextBounds } from '@teachinglab/omd'; // Assuming @teachinglab/omd exports these
66
+ import * as math from 'mathjs';
67
+
68
+ // Example of getting a node class for an expression
69
+ const astExpression = math.parse('x + 2');
70
+ const NodeClassExpression = getNodeForAST(astExpression);
71
+ const nodeExpression = new NodeClassExpression(astExpression);
72
+ console.log(nodeExpression.type); // e.g., "omdBinaryExpressionNode"
73
+
74
+ // Example of getting a node class for an equation
75
+ const astEquation = math.parse('y = 2x');
76
+ const NodeClassEquation = getNodeForAST(astEquation);
77
+ const nodeEquation = new NodeClassEquation(astEquation);
78
+ console.log(nodeEquation.type); // "omdEquationNode"
79
+
80
+ // Example of getting text bounds
81
+ const bounds = getTextBounds('Hello World', 24);
82
+ console.log(`Text width: ${bounds.width}, height: ${bounds.height}`);
83
83
  ```