@teachinglab/omd 0.6.1 → 0.6.3
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 +606 -547
- package/omd/core/omdUtilities.js +113 -113
- package/omd/display/omdDisplay.js +1045 -963
- 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 -57
- 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
package/README.old.md
CHANGED
|
@@ -1,138 +1,138 @@
|
|
|
1
|
-
# OMD (
|
|
2
|
-
|
|
3
|
-
OMD is a JavaScript library for creating interactive mathematical interfaces in web applications. Build everything from simple equation displays to complex step-by-step solution systems with rich visual feedback and user interaction.
|
|
4
|
-
|
|
5
|
-

|
|
6
|
-
|
|
7
|
-
## Features
|
|
8
|
-
|
|
9
|
-
### **Interactive Math Rendering**
|
|
10
|
-
- High-quality SVG-based mathematical notation
|
|
11
|
-
- Real-time expression manipulation and visualization
|
|
12
|
-
- Automatic layout and alignment for complex equations
|
|
13
|
-
|
|
14
|
-
### **Step-by-Step Solutions**
|
|
15
|
-
- Visual step tracking with detailed explanations
|
|
16
|
-
- Simplification engine with rule-based transformations
|
|
17
|
-
- Provenance tracking for highlighting related elements
|
|
18
|
-
|
|
19
|
-
### **Rich UI Components**
|
|
20
|
-
- Built-in toolbar for common mathematical operations
|
|
21
|
-
- Drag & drop interface for intuitive manipulation
|
|
22
|
-
- Customizable canvas for multi-expression layouts
|
|
23
|
-
|
|
24
|
-
### **Educational Features**
|
|
25
|
-
- Interactive learning experiences
|
|
26
|
-
- Progressive step revelation
|
|
27
|
-
- Visual operation feedback and highlighting
|
|
28
|
-
|
|
29
|
-
## Installation
|
|
30
|
-
|
|
31
|
-
### npm
|
|
32
|
-
```bash
|
|
33
|
-
npm install @teachinglab/omd
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Basic Usage
|
|
37
|
-
```javascript
|
|
38
|
-
import { omdDisplay } from '@teachinglab/omd';
|
|
39
|
-
|
|
40
|
-
// Create a math display
|
|
41
|
-
const container = document.getElementById('math-container');
|
|
42
|
-
const display = new omdDisplay(container);
|
|
43
|
-
|
|
44
|
-
// Render an equation
|
|
45
|
-
display.render('2x + 3 = 11');
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### Step-by-Step Solutions
|
|
49
|
-
```javascript
|
|
50
|
-
import { omdEquationStack, omdEquationNode } from '@teachinglab/omd';
|
|
51
|
-
|
|
52
|
-
// Create solution steps
|
|
53
|
-
const steps = [
|
|
54
|
-
omdEquationNode.fromString('2x + 3 = 11'),
|
|
55
|
-
omdEquationNode.fromString('2x = 8'),
|
|
56
|
-
omdEquationNode.fromString('x = 4')
|
|
57
|
-
];
|
|
58
|
-
|
|
59
|
-
// Create interactive equation stack
|
|
60
|
-
const stack = new omdEquationStack(steps, {
|
|
61
|
-
toolbar: true,
|
|
62
|
-
stepVisualizer: true
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
display.render(stack);
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
## Core Concepts
|
|
69
|
-
|
|
70
|
-
### **Nodes** - Building Blocks
|
|
71
|
-
Every mathematical element is a node in an expression tree:
|
|
72
|
-
- `omdEquationNode` - Complete equations (e.g., `2x + 3 = 11`)
|
|
73
|
-
- `omdConstantNode` - Numbers (e.g., `5`, `3.14`)
|
|
74
|
-
- `omdVariableNode` - Variables (e.g., `x`, `y`)
|
|
75
|
-
- `omdBinaryExpressionNode` - Operations (e.g., `+`, `-`, `*`, `/`)
|
|
76
|
-
|
|
77
|
-
### **Sequences** - Solution Steps
|
|
78
|
-
Group related equations for step-by-step solving:
|
|
79
|
-
```javascript
|
|
80
|
-
const sequence = new omdEquationSequenceNode([
|
|
81
|
-
equation1, equation2, equation3
|
|
82
|
-
]);
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
### **Display** - Rendering Engine
|
|
86
|
-
Handles layout, centering, and visualization:
|
|
87
|
-
```javascript
|
|
88
|
-
const display = new omdDisplay(container, {
|
|
89
|
-
fontSize: 36,
|
|
90
|
-
centerContent: true
|
|
91
|
-
});
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
## Interactive Examples
|
|
95
|
-
|
|
96
|
-
Explore OMD's capabilities with our comprehensive examples:
|
|
97
|
-
|
|
98
|
-
| Category | Example | Description |
|
|
99
|
-
|----------|---------|-------------|
|
|
100
|
-
| **Getting Started** | [Minimal](examples/minimal.html) | Basic equation rendering |
|
|
101
|
-
| | [Simple Usage](examples/simple-usage.html) | Interactive features |
|
|
102
|
-
| **Advanced** | [Expression Playground](examples/expression-playground.html) | Full manipulation interface |
|
|
103
|
-
| | [Drag & Drop](examples/drag-and-drop-playground.html) | Intuitive interaction |
|
|
104
|
-
| **Educational** | [Worked Solutions](examples/worked-solution.html) | Step-by-step solving |
|
|
105
|
-
| | [Kids Interactive](examples/kids-interactive.html) | Child-friendly interface |
|
|
106
|
-
| **Components** | [Equation Stack](examples/equation-stack-test.html) | Stacked equations |
|
|
107
|
-
| | [Canvas Demo](examples/canvas-multiple-nodes.html) | Multi-expression layouts |
|
|
108
|
-
|
|
109
|
-
**[Browse All Examples](examples/index.html)**
|
|
110
|
-
|
|
111
|
-
## Documentation
|
|
112
|
-
|
|
113
|
-
| Resource | Description |
|
|
114
|
-
|----------|-------------|
|
|
115
|
-
| **[API Reference](docs/api-reference.md)** | Complete component documentation |
|
|
116
|
-
| **[User Guide](docs/user-guide.md)** | Getting started and tutorials |
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
## Architecture
|
|
120
|
-
|
|
121
|
-
```
|
|
122
|
-
OMD Library Structure
|
|
123
|
-
├── Display Layer (omdDisplay)
|
|
124
|
-
├── Node System (Expression tree components)
|
|
125
|
-
├── UI Components (Toolbar, Step visualizer)
|
|
126
|
-
├── Core Systems (Simplification, Layout)
|
|
127
|
-
└── Utilities (Configuration, Helpers)
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
## Dependencies
|
|
131
|
-
|
|
132
|
-
- **JSVG** - High-performance SVG rendering
|
|
133
|
-
- **math.js** - Mathematical expression parsing
|
|
134
|
-
- **Modern Browser** - ES6 modules, SVG support
|
|
135
|
-
|
|
136
|
-
---
|
|
137
|
-
|
|
1
|
+
# OMD (On-screen Math Display)
|
|
2
|
+
|
|
3
|
+
OMD is a JavaScript library for creating interactive mathematical interfaces in web applications. Build everything from simple equation displays to complex step-by-step solution systems with rich visual feedback and user interaction.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
### **Interactive Math Rendering**
|
|
10
|
+
- High-quality SVG-based mathematical notation
|
|
11
|
+
- Real-time expression manipulation and visualization
|
|
12
|
+
- Automatic layout and alignment for complex equations
|
|
13
|
+
|
|
14
|
+
### **Step-by-Step Solutions**
|
|
15
|
+
- Visual step tracking with detailed explanations
|
|
16
|
+
- Simplification engine with rule-based transformations
|
|
17
|
+
- Provenance tracking for highlighting related elements
|
|
18
|
+
|
|
19
|
+
### **Rich UI Components**
|
|
20
|
+
- Built-in toolbar for common mathematical operations
|
|
21
|
+
- Drag & drop interface for intuitive manipulation
|
|
22
|
+
- Customizable canvas for multi-expression layouts
|
|
23
|
+
|
|
24
|
+
### **Educational Features**
|
|
25
|
+
- Interactive learning experiences
|
|
26
|
+
- Progressive step revelation
|
|
27
|
+
- Visual operation feedback and highlighting
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
### npm
|
|
32
|
+
```bash
|
|
33
|
+
npm install @teachinglab/omd
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Basic Usage
|
|
37
|
+
```javascript
|
|
38
|
+
import { omdDisplay } from '@teachinglab/omd';
|
|
39
|
+
|
|
40
|
+
// Create a math display
|
|
41
|
+
const container = document.getElementById('math-container');
|
|
42
|
+
const display = new omdDisplay(container);
|
|
43
|
+
|
|
44
|
+
// Render an equation
|
|
45
|
+
display.render('2x + 3 = 11');
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Step-by-Step Solutions
|
|
49
|
+
```javascript
|
|
50
|
+
import { omdEquationStack, omdEquationNode } from '@teachinglab/omd';
|
|
51
|
+
|
|
52
|
+
// Create solution steps
|
|
53
|
+
const steps = [
|
|
54
|
+
omdEquationNode.fromString('2x + 3 = 11'),
|
|
55
|
+
omdEquationNode.fromString('2x = 8'),
|
|
56
|
+
omdEquationNode.fromString('x = 4')
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
// Create interactive equation stack
|
|
60
|
+
const stack = new omdEquationStack(steps, {
|
|
61
|
+
toolbar: true,
|
|
62
|
+
stepVisualizer: true
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
display.render(stack);
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Core Concepts
|
|
69
|
+
|
|
70
|
+
### **Nodes** - Building Blocks
|
|
71
|
+
Every mathematical element is a node in an expression tree:
|
|
72
|
+
- `omdEquationNode` - Complete equations (e.g., `2x + 3 = 11`)
|
|
73
|
+
- `omdConstantNode` - Numbers (e.g., `5`, `3.14`)
|
|
74
|
+
- `omdVariableNode` - Variables (e.g., `x`, `y`)
|
|
75
|
+
- `omdBinaryExpressionNode` - Operations (e.g., `+`, `-`, `*`, `/`)
|
|
76
|
+
|
|
77
|
+
### **Sequences** - Solution Steps
|
|
78
|
+
Group related equations for step-by-step solving:
|
|
79
|
+
```javascript
|
|
80
|
+
const sequence = new omdEquationSequenceNode([
|
|
81
|
+
equation1, equation2, equation3
|
|
82
|
+
]);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### **Display** - Rendering Engine
|
|
86
|
+
Handles layout, centering, and visualization:
|
|
87
|
+
```javascript
|
|
88
|
+
const display = new omdDisplay(container, {
|
|
89
|
+
fontSize: 36,
|
|
90
|
+
centerContent: true
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Interactive Examples
|
|
95
|
+
|
|
96
|
+
Explore OMD's capabilities with our comprehensive examples:
|
|
97
|
+
|
|
98
|
+
| Category | Example | Description |
|
|
99
|
+
|----------|---------|-------------|
|
|
100
|
+
| **Getting Started** | [Minimal](examples/minimal.html) | Basic equation rendering |
|
|
101
|
+
| | [Simple Usage](examples/simple-usage.html) | Interactive features |
|
|
102
|
+
| **Advanced** | [Expression Playground](examples/expression-playground.html) | Full manipulation interface |
|
|
103
|
+
| | [Drag & Drop](examples/drag-and-drop-playground.html) | Intuitive interaction |
|
|
104
|
+
| **Educational** | [Worked Solutions](examples/worked-solution.html) | Step-by-step solving |
|
|
105
|
+
| | [Kids Interactive](examples/kids-interactive.html) | Child-friendly interface |
|
|
106
|
+
| **Components** | [Equation Stack](examples/equation-stack-test.html) | Stacked equations |
|
|
107
|
+
| | [Canvas Demo](examples/canvas-multiple-nodes.html) | Multi-expression layouts |
|
|
108
|
+
|
|
109
|
+
**[Browse All Examples](examples/index.html)**
|
|
110
|
+
|
|
111
|
+
## Documentation
|
|
112
|
+
|
|
113
|
+
| Resource | Description |
|
|
114
|
+
|----------|-------------|
|
|
115
|
+
| **[API Reference](docs/api-reference.md)** | Complete component documentation |
|
|
116
|
+
| **[User Guide](docs/user-guide.md)** | Getting started and tutorials |
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
## Architecture
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
OMD Library Structure
|
|
123
|
+
├── Display Layer (omdDisplay)
|
|
124
|
+
├── Node System (Expression tree components)
|
|
125
|
+
├── UI Components (Toolbar, Step visualizer)
|
|
126
|
+
├── Core Systems (Simplification, Layout)
|
|
127
|
+
└── Utilities (Configuration, Helpers)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Dependencies
|
|
131
|
+
|
|
132
|
+
- **JSVG** - High-performance SVG rendering
|
|
133
|
+
- **math.js** - Mathematical expression parsing
|
|
134
|
+
- **Modern Browser** - ES6 modules, SVG support
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
138
|
**Ready to get started?** Check out our [examples](examples/index.html) or dive into the [documentation](docs/api-reference.md)!
|
|
@@ -1,203 +1,203 @@
|
|
|
1
|
-
export class CanvasConfig {
|
|
2
|
-
/**
|
|
3
|
-
* @param {Object} options - Configuration options
|
|
4
|
-
*/
|
|
5
|
-
constructor(options = {}) {
|
|
6
|
-
// Default configuration
|
|
7
|
-
this.width = options.width || 800;
|
|
8
|
-
this.height = options.height || 500;
|
|
9
|
-
this.backgroundColor = options.backgroundColor || 'white';
|
|
10
|
-
|
|
11
|
-
// UI options
|
|
12
|
-
this.showToolbar = options.showToolbar !== false;
|
|
13
|
-
this.showGrid = options.showGrid || false;
|
|
14
|
-
this.gridSpacing = options.gridSpacing || 20;
|
|
15
|
-
|
|
16
|
-
// Tool configuration
|
|
17
|
-
this.enabledTools = options.enabledTools || ['pointer', 'pencil', 'eraser', 'select'];
|
|
18
|
-
this.defaultTool = options.defaultTool || 'pointer';
|
|
19
|
-
|
|
20
|
-
// Feature flags
|
|
21
|
-
this.enableFocusFrames = options.enableFocusFrames !== false;
|
|
22
|
-
this.enableKeyboardShortcuts = options.enableKeyboardShortcuts !== false;
|
|
23
|
-
this.enableMultiTouch = options.enableMultiTouch !== false;
|
|
24
|
-
|
|
25
|
-
// Tool defaults
|
|
26
|
-
this.tools = {
|
|
27
|
-
pencil: {
|
|
28
|
-
strokeWidth: 5,
|
|
29
|
-
strokeColor: '#000000',
|
|
30
|
-
strokeOpacity: 1,
|
|
31
|
-
smoothing: 0.5,
|
|
32
|
-
pressureSensitivity: true,
|
|
33
|
-
...options.tools?.pencil
|
|
34
|
-
},
|
|
35
|
-
eraser: {
|
|
36
|
-
size: 20,
|
|
37
|
-
hardness: 0.8,
|
|
38
|
-
...options.tools?.eraser
|
|
39
|
-
},
|
|
40
|
-
select: {
|
|
41
|
-
selectionColor: '#007bff',
|
|
42
|
-
selectionOpacity: 0.3,
|
|
43
|
-
...options.tools?.select
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
// Theme
|
|
48
|
-
this.theme = {
|
|
49
|
-
primary: '#007bff',
|
|
50
|
-
secondary: '#6c757d',
|
|
51
|
-
success: '#28a745',
|
|
52
|
-
warning: '#ffc107',
|
|
53
|
-
danger: '#dc3545',
|
|
54
|
-
...options.theme
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
// Validate configuration
|
|
58
|
-
this._validate();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Validate configuration
|
|
63
|
-
* @private
|
|
64
|
-
*/
|
|
65
|
-
_validate() {
|
|
66
|
-
// Validate dimensions
|
|
67
|
-
if (this.width <= 0 || this.height <= 0) {
|
|
68
|
-
throw new Error('Canvas dimensions must be positive numbers');
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Validate enabled tools
|
|
72
|
-
const availableTools = ['pointer', 'pencil', 'eraser', 'select'];
|
|
73
|
-
const invalidTools = this.enabledTools.filter(tool => !availableTools.includes(tool));
|
|
74
|
-
if (invalidTools.length > 0) {
|
|
75
|
-
console.warn(`Invalid tools specified: ${invalidTools.join(', ')}`);
|
|
76
|
-
this.enabledTools = this.enabledTools.filter(tool => availableTools.includes(tool));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Ensure at least one tool is enabled
|
|
80
|
-
if (this.enabledTools.length === 0) {
|
|
81
|
-
this.enabledTools = ['pencil'];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Validate default tool
|
|
85
|
-
if (!this.enabledTools.includes(this.defaultTool)) {
|
|
86
|
-
this.defaultTool = this.enabledTools[0];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Validate tool configurations
|
|
90
|
-
this._validateToolConfigs();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Validate tool configurations
|
|
95
|
-
* @private
|
|
96
|
-
*/
|
|
97
|
-
_validateToolConfigs() {
|
|
98
|
-
// Validate pencil config
|
|
99
|
-
if (this.tools.pencil.strokeWidth <= 0) {
|
|
100
|
-
this.tools.pencil.strokeWidth = 5;
|
|
101
|
-
}
|
|
102
|
-
if (this.tools.pencil.strokeOpacity < 0 || this.tools.pencil.strokeOpacity > 1) {
|
|
103
|
-
this.tools.pencil.strokeOpacity = 1;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Validate eraser config
|
|
107
|
-
if (this.tools.eraser.size <= 0) {
|
|
108
|
-
this.tools.eraser.size = 20;
|
|
109
|
-
}
|
|
110
|
-
if (this.tools.eraser.hardness < 0 || this.tools.eraser.hardness > 1) {
|
|
111
|
-
this.tools.eraser.hardness = 0.8;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Validate select config
|
|
115
|
-
if (this.tools.select.selectionOpacity < 0 || this.tools.select.selectionOpacity > 1) {
|
|
116
|
-
this.tools.select.selectionOpacity = 0.3;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Update configuration
|
|
122
|
-
* @param {Object} updates - Configuration updates
|
|
123
|
-
*/
|
|
124
|
-
update(updates) {
|
|
125
|
-
Object.assign(this, updates);
|
|
126
|
-
this._validate();
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Get tool configuration
|
|
131
|
-
* @param {string} toolName - Tool name
|
|
132
|
-
* @returns {Object} Tool configuration
|
|
133
|
-
*/
|
|
134
|
-
getToolConfig(toolName) {
|
|
135
|
-
return this.tools[toolName] || {};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Update tool configuration
|
|
140
|
-
* @param {string} toolName - Tool name
|
|
141
|
-
* @param {Object} config - Tool configuration updates
|
|
142
|
-
*/
|
|
143
|
-
updateToolConfig(toolName, config) {
|
|
144
|
-
if (!this.tools[toolName]) {
|
|
145
|
-
this.tools[toolName] = {};
|
|
146
|
-
}
|
|
147
|
-
Object.assign(this.tools[toolName], config);
|
|
148
|
-
this._validateToolConfigs();
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Clone configuration
|
|
153
|
-
* @returns {CanvasConfig} New configuration instance
|
|
154
|
-
*/
|
|
155
|
-
clone() {
|
|
156
|
-
return new CanvasConfig({
|
|
157
|
-
width: this.width,
|
|
158
|
-
height: this.height,
|
|
159
|
-
backgroundColor: this.backgroundColor,
|
|
160
|
-
showToolbar: this.showToolbar,
|
|
161
|
-
showGrid: this.showGrid,
|
|
162
|
-
gridSpacing: this.gridSpacing,
|
|
163
|
-
enabledTools: [...this.enabledTools],
|
|
164
|
-
defaultTool: this.defaultTool,
|
|
165
|
-
enableFocusFrames: this.enableFocusFrames,
|
|
166
|
-
enableKeyboardShortcuts: this.enableKeyboardShortcuts,
|
|
167
|
-
enableMultiTouch: this.enableMultiTouch,
|
|
168
|
-
tools: JSON.parse(JSON.stringify(this.tools)),
|
|
169
|
-
theme: { ...this.theme }
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Convert to JSON
|
|
175
|
-
* @returns {Object} JSON representation
|
|
176
|
-
*/
|
|
177
|
-
toJSON() {
|
|
178
|
-
return {
|
|
179
|
-
width: this.width,
|
|
180
|
-
height: this.height,
|
|
181
|
-
backgroundColor: this.backgroundColor,
|
|
182
|
-
showToolbar: this.showToolbar,
|
|
183
|
-
showGrid: this.showGrid,
|
|
184
|
-
gridSpacing: this.gridSpacing,
|
|
185
|
-
enabledTools: this.enabledTools,
|
|
186
|
-
defaultTool: this.defaultTool,
|
|
187
|
-
enableFocusFrames: this.enableFocusFrames,
|
|
188
|
-
enableKeyboardShortcuts: this.enableKeyboardShortcuts,
|
|
189
|
-
enableMultiTouch: this.enableMultiTouch,
|
|
190
|
-
tools: this.tools,
|
|
191
|
-
theme: this.theme
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Create from JSON
|
|
197
|
-
* @param {Object} data - JSON data
|
|
198
|
-
* @returns {CanvasConfig} New configuration instance
|
|
199
|
-
*/
|
|
200
|
-
static fromJSON(data) {
|
|
201
|
-
return new CanvasConfig(data);
|
|
202
|
-
}
|
|
1
|
+
export class CanvasConfig {
|
|
2
|
+
/**
|
|
3
|
+
* @param {Object} options - Configuration options
|
|
4
|
+
*/
|
|
5
|
+
constructor(options = {}) {
|
|
6
|
+
// Default configuration
|
|
7
|
+
this.width = options.width || 800;
|
|
8
|
+
this.height = options.height || 500;
|
|
9
|
+
this.backgroundColor = options.backgroundColor || 'white';
|
|
10
|
+
|
|
11
|
+
// UI options
|
|
12
|
+
this.showToolbar = options.showToolbar !== false;
|
|
13
|
+
this.showGrid = options.showGrid || false;
|
|
14
|
+
this.gridSpacing = options.gridSpacing || 20;
|
|
15
|
+
|
|
16
|
+
// Tool configuration
|
|
17
|
+
this.enabledTools = options.enabledTools || ['pointer', 'pencil', 'eraser', 'select'];
|
|
18
|
+
this.defaultTool = options.defaultTool || 'pointer';
|
|
19
|
+
|
|
20
|
+
// Feature flags
|
|
21
|
+
this.enableFocusFrames = options.enableFocusFrames !== false;
|
|
22
|
+
this.enableKeyboardShortcuts = options.enableKeyboardShortcuts !== false;
|
|
23
|
+
this.enableMultiTouch = options.enableMultiTouch !== false;
|
|
24
|
+
|
|
25
|
+
// Tool defaults
|
|
26
|
+
this.tools = {
|
|
27
|
+
pencil: {
|
|
28
|
+
strokeWidth: 5,
|
|
29
|
+
strokeColor: '#000000',
|
|
30
|
+
strokeOpacity: 1,
|
|
31
|
+
smoothing: 0.5,
|
|
32
|
+
pressureSensitivity: true,
|
|
33
|
+
...options.tools?.pencil
|
|
34
|
+
},
|
|
35
|
+
eraser: {
|
|
36
|
+
size: 20,
|
|
37
|
+
hardness: 0.8,
|
|
38
|
+
...options.tools?.eraser
|
|
39
|
+
},
|
|
40
|
+
select: {
|
|
41
|
+
selectionColor: '#007bff',
|
|
42
|
+
selectionOpacity: 0.3,
|
|
43
|
+
...options.tools?.select
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// Theme
|
|
48
|
+
this.theme = {
|
|
49
|
+
primary: '#007bff',
|
|
50
|
+
secondary: '#6c757d',
|
|
51
|
+
success: '#28a745',
|
|
52
|
+
warning: '#ffc107',
|
|
53
|
+
danger: '#dc3545',
|
|
54
|
+
...options.theme
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// Validate configuration
|
|
58
|
+
this._validate();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Validate configuration
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
65
|
+
_validate() {
|
|
66
|
+
// Validate dimensions
|
|
67
|
+
if (this.width <= 0 || this.height <= 0) {
|
|
68
|
+
throw new Error('Canvas dimensions must be positive numbers');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Validate enabled tools
|
|
72
|
+
const availableTools = ['pointer', 'pencil', 'eraser', 'select'];
|
|
73
|
+
const invalidTools = this.enabledTools.filter(tool => !availableTools.includes(tool));
|
|
74
|
+
if (invalidTools.length > 0) {
|
|
75
|
+
console.warn(`Invalid tools specified: ${invalidTools.join(', ')}`);
|
|
76
|
+
this.enabledTools = this.enabledTools.filter(tool => availableTools.includes(tool));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Ensure at least one tool is enabled
|
|
80
|
+
if (this.enabledTools.length === 0) {
|
|
81
|
+
this.enabledTools = ['pencil'];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Validate default tool
|
|
85
|
+
if (!this.enabledTools.includes(this.defaultTool)) {
|
|
86
|
+
this.defaultTool = this.enabledTools[0];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Validate tool configurations
|
|
90
|
+
this._validateToolConfigs();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Validate tool configurations
|
|
95
|
+
* @private
|
|
96
|
+
*/
|
|
97
|
+
_validateToolConfigs() {
|
|
98
|
+
// Validate pencil config
|
|
99
|
+
if (this.tools.pencil.strokeWidth <= 0) {
|
|
100
|
+
this.tools.pencil.strokeWidth = 5;
|
|
101
|
+
}
|
|
102
|
+
if (this.tools.pencil.strokeOpacity < 0 || this.tools.pencil.strokeOpacity > 1) {
|
|
103
|
+
this.tools.pencil.strokeOpacity = 1;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Validate eraser config
|
|
107
|
+
if (this.tools.eraser.size <= 0) {
|
|
108
|
+
this.tools.eraser.size = 20;
|
|
109
|
+
}
|
|
110
|
+
if (this.tools.eraser.hardness < 0 || this.tools.eraser.hardness > 1) {
|
|
111
|
+
this.tools.eraser.hardness = 0.8;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Validate select config
|
|
115
|
+
if (this.tools.select.selectionOpacity < 0 || this.tools.select.selectionOpacity > 1) {
|
|
116
|
+
this.tools.select.selectionOpacity = 0.3;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Update configuration
|
|
122
|
+
* @param {Object} updates - Configuration updates
|
|
123
|
+
*/
|
|
124
|
+
update(updates) {
|
|
125
|
+
Object.assign(this, updates);
|
|
126
|
+
this._validate();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Get tool configuration
|
|
131
|
+
* @param {string} toolName - Tool name
|
|
132
|
+
* @returns {Object} Tool configuration
|
|
133
|
+
*/
|
|
134
|
+
getToolConfig(toolName) {
|
|
135
|
+
return this.tools[toolName] || {};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Update tool configuration
|
|
140
|
+
* @param {string} toolName - Tool name
|
|
141
|
+
* @param {Object} config - Tool configuration updates
|
|
142
|
+
*/
|
|
143
|
+
updateToolConfig(toolName, config) {
|
|
144
|
+
if (!this.tools[toolName]) {
|
|
145
|
+
this.tools[toolName] = {};
|
|
146
|
+
}
|
|
147
|
+
Object.assign(this.tools[toolName], config);
|
|
148
|
+
this._validateToolConfigs();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Clone configuration
|
|
153
|
+
* @returns {CanvasConfig} New configuration instance
|
|
154
|
+
*/
|
|
155
|
+
clone() {
|
|
156
|
+
return new CanvasConfig({
|
|
157
|
+
width: this.width,
|
|
158
|
+
height: this.height,
|
|
159
|
+
backgroundColor: this.backgroundColor,
|
|
160
|
+
showToolbar: this.showToolbar,
|
|
161
|
+
showGrid: this.showGrid,
|
|
162
|
+
gridSpacing: this.gridSpacing,
|
|
163
|
+
enabledTools: [...this.enabledTools],
|
|
164
|
+
defaultTool: this.defaultTool,
|
|
165
|
+
enableFocusFrames: this.enableFocusFrames,
|
|
166
|
+
enableKeyboardShortcuts: this.enableKeyboardShortcuts,
|
|
167
|
+
enableMultiTouch: this.enableMultiTouch,
|
|
168
|
+
tools: JSON.parse(JSON.stringify(this.tools)),
|
|
169
|
+
theme: { ...this.theme }
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Convert to JSON
|
|
175
|
+
* @returns {Object} JSON representation
|
|
176
|
+
*/
|
|
177
|
+
toJSON() {
|
|
178
|
+
return {
|
|
179
|
+
width: this.width,
|
|
180
|
+
height: this.height,
|
|
181
|
+
backgroundColor: this.backgroundColor,
|
|
182
|
+
showToolbar: this.showToolbar,
|
|
183
|
+
showGrid: this.showGrid,
|
|
184
|
+
gridSpacing: this.gridSpacing,
|
|
185
|
+
enabledTools: this.enabledTools,
|
|
186
|
+
defaultTool: this.defaultTool,
|
|
187
|
+
enableFocusFrames: this.enableFocusFrames,
|
|
188
|
+
enableKeyboardShortcuts: this.enableKeyboardShortcuts,
|
|
189
|
+
enableMultiTouch: this.enableMultiTouch,
|
|
190
|
+
tools: this.tools,
|
|
191
|
+
theme: this.theme
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Create from JSON
|
|
197
|
+
* @param {Object} data - JSON data
|
|
198
|
+
* @returns {CanvasConfig} New configuration instance
|
|
199
|
+
*/
|
|
200
|
+
static fromJSON(data) {
|
|
201
|
+
return new CanvasConfig(data);
|
|
202
|
+
}
|
|
203
203
|
}
|