@teachinglab/omd 0.1.0

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 (144) hide show
  1. package/README.md +138 -0
  2. package/canvas/core/canvasConfig.js +203 -0
  3. package/canvas/core/omdCanvas.js +475 -0
  4. package/canvas/drawing/segment.js +168 -0
  5. package/canvas/drawing/stroke.js +386 -0
  6. package/canvas/events/eventManager.js +435 -0
  7. package/canvas/events/pointerEventHandler.js +263 -0
  8. package/canvas/features/focusFrameManager.js +287 -0
  9. package/canvas/index.js +49 -0
  10. package/canvas/tools/eraserTool.js +322 -0
  11. package/canvas/tools/pencilTool.js +319 -0
  12. package/canvas/tools/selectTool.js +457 -0
  13. package/canvas/tools/tool.js +223 -0
  14. package/canvas/tools/toolManager.js +394 -0
  15. package/canvas/ui/cursor.js +438 -0
  16. package/canvas/ui/toolbar.js +304 -0
  17. package/canvas/utils/boundingBox.js +378 -0
  18. package/canvas/utils/mathUtils.js +259 -0
  19. package/docs/api/configuration-options.md +104 -0
  20. package/docs/api/eventManager.md +68 -0
  21. package/docs/api/focusFrameManager.md +150 -0
  22. package/docs/api/index.md +91 -0
  23. package/docs/api/main.md +58 -0
  24. package/docs/api/omdBinaryExpressionNode.md +227 -0
  25. package/docs/api/omdCanvas.md +142 -0
  26. package/docs/api/omdConfigManager.md +192 -0
  27. package/docs/api/omdConstantNode.md +117 -0
  28. package/docs/api/omdDisplay.md +121 -0
  29. package/docs/api/omdEquationNode.md +161 -0
  30. package/docs/api/omdEquationSequenceNode.md +301 -0
  31. package/docs/api/omdEquationStack.md +139 -0
  32. package/docs/api/omdFunctionNode.md +141 -0
  33. package/docs/api/omdGroupNode.md +182 -0
  34. package/docs/api/omdHelpers.md +96 -0
  35. package/docs/api/omdLeafNode.md +163 -0
  36. package/docs/api/omdNode.md +101 -0
  37. package/docs/api/omdOperationDisplayNode.md +139 -0
  38. package/docs/api/omdOperatorNode.md +127 -0
  39. package/docs/api/omdParenthesisNode.md +122 -0
  40. package/docs/api/omdPopup.md +117 -0
  41. package/docs/api/omdPowerNode.md +127 -0
  42. package/docs/api/omdRationalNode.md +128 -0
  43. package/docs/api/omdSequenceNode.md +128 -0
  44. package/docs/api/omdSimplification.md +110 -0
  45. package/docs/api/omdSqrtNode.md +79 -0
  46. package/docs/api/omdStepVisualizer.md +115 -0
  47. package/docs/api/omdStepVisualizerHighlighting.md +61 -0
  48. package/docs/api/omdStepVisualizerInteractiveSteps.md +129 -0
  49. package/docs/api/omdStepVisualizerLayout.md +60 -0
  50. package/docs/api/omdStepVisualizerNodeUtils.md +140 -0
  51. package/docs/api/omdStepVisualizerTextBoxes.md +68 -0
  52. package/docs/api/omdToolbar.md +102 -0
  53. package/docs/api/omdTranscriptionService.md +76 -0
  54. package/docs/api/omdTreeDiff.md +134 -0
  55. package/docs/api/omdUnaryExpressionNode.md +174 -0
  56. package/docs/api/omdUtilities.md +70 -0
  57. package/docs/api/omdVariableNode.md +148 -0
  58. package/docs/api/selectTool.md +74 -0
  59. package/docs/api/simplificationEngine.md +98 -0
  60. package/docs/api/simplificationRules.md +77 -0
  61. package/docs/api/simplificationUtils.md +64 -0
  62. package/docs/api/transcribe.md +43 -0
  63. package/docs/api-reference.md +85 -0
  64. package/docs/index.html +454 -0
  65. package/docs/user-guide.md +9 -0
  66. package/index.js +67 -0
  67. package/omd/config/omdConfigManager.js +267 -0
  68. package/omd/core/index.js +150 -0
  69. package/omd/core/omdEquationStack.js +347 -0
  70. package/omd/core/omdUtilities.js +115 -0
  71. package/omd/display/omdDisplay.js +443 -0
  72. package/omd/display/omdToolbar.js +502 -0
  73. package/omd/nodes/omdBinaryExpressionNode.js +460 -0
  74. package/omd/nodes/omdConstantNode.js +142 -0
  75. package/omd/nodes/omdEquationNode.js +1223 -0
  76. package/omd/nodes/omdEquationSequenceNode.js +1273 -0
  77. package/omd/nodes/omdFunctionNode.js +352 -0
  78. package/omd/nodes/omdGroupNode.js +68 -0
  79. package/omd/nodes/omdLeafNode.js +77 -0
  80. package/omd/nodes/omdNode.js +557 -0
  81. package/omd/nodes/omdOperationDisplayNode.js +322 -0
  82. package/omd/nodes/omdOperatorNode.js +109 -0
  83. package/omd/nodes/omdParenthesisNode.js +293 -0
  84. package/omd/nodes/omdPowerNode.js +236 -0
  85. package/omd/nodes/omdRationalNode.js +295 -0
  86. package/omd/nodes/omdSqrtNode.js +308 -0
  87. package/omd/nodes/omdUnaryExpressionNode.js +178 -0
  88. package/omd/nodes/omdVariableNode.js +123 -0
  89. package/omd/simplification/omdSimplification.js +171 -0
  90. package/omd/simplification/omdSimplificationEngine.js +886 -0
  91. package/omd/simplification/package.json +6 -0
  92. package/omd/simplification/rules/binaryRules.js +1037 -0
  93. package/omd/simplification/rules/functionRules.js +111 -0
  94. package/omd/simplification/rules/index.js +48 -0
  95. package/omd/simplification/rules/parenthesisRules.js +19 -0
  96. package/omd/simplification/rules/powerRules.js +143 -0
  97. package/omd/simplification/rules/rationalRules.js +475 -0
  98. package/omd/simplification/rules/sqrtRules.js +48 -0
  99. package/omd/simplification/rules/unaryRules.js +37 -0
  100. package/omd/simplification/simplificationRules.js +32 -0
  101. package/omd/simplification/simplificationUtils.js +1056 -0
  102. package/omd/step-visualizer/omdStepVisualizer.js +597 -0
  103. package/omd/step-visualizer/omdStepVisualizerHighlighting.js +206 -0
  104. package/omd/step-visualizer/omdStepVisualizerLayout.js +245 -0
  105. package/omd/step-visualizer/omdStepVisualizerTextBoxes.js +163 -0
  106. package/omd/utils/omdNodeOverlay.js +638 -0
  107. package/omd/utils/omdPopup.js +1084 -0
  108. package/omd/utils/omdStepVisualizerInteractiveSteps.js +491 -0
  109. package/omd/utils/omdStepVisualizerNodeUtils.js +268 -0
  110. package/omd/utils/omdTranscriptionService.js +125 -0
  111. package/omd/utils/omdTreeDiff.js +734 -0
  112. package/package.json +46 -0
  113. package/src/index.js +62 -0
  114. package/src/json-schemas.md +109 -0
  115. package/src/omd-json-samples.js +115 -0
  116. package/src/omd.js +109 -0
  117. package/src/omdApp.js +391 -0
  118. package/src/omdAppCanvas.js +336 -0
  119. package/src/omdBalanceHanger.js +172 -0
  120. package/src/omdColor.js +13 -0
  121. package/src/omdCoordinatePlane.js +467 -0
  122. package/src/omdEquation.js +125 -0
  123. package/src/omdExpression.js +104 -0
  124. package/src/omdFunction.js +113 -0
  125. package/src/omdMetaExpression.js +287 -0
  126. package/src/omdNaturalExpression.js +564 -0
  127. package/src/omdNode.js +384 -0
  128. package/src/omdNumber.js +53 -0
  129. package/src/omdNumberLine.js +107 -0
  130. package/src/omdNumberTile.js +119 -0
  131. package/src/omdOperator.js +73 -0
  132. package/src/omdPowerExpression.js +92 -0
  133. package/src/omdProblem.js +55 -0
  134. package/src/omdRatioChart.js +232 -0
  135. package/src/omdRationalExpression.js +115 -0
  136. package/src/omdSampleData.js +215 -0
  137. package/src/omdShapes.js +476 -0
  138. package/src/omdSpinner.js +148 -0
  139. package/src/omdString.js +39 -0
  140. package/src/omdTable.js +369 -0
  141. package/src/omdTapeDiagram.js +245 -0
  142. package/src/omdTerm.js +92 -0
  143. package/src/omdTileEquation.js +349 -0
  144. package/src/omdVariable.js +51 -0
package/README.md ADDED
@@ -0,0 +1,138 @@
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
+ ![OMD Demo](https://i.imgur.com/CdtEi33.png)
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
+ **Ready to get started?** Check out our [examples](examples/index.html) or dive into the [documentation](docs/api-reference.md)!
@@ -0,0 +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 || ['pencil', 'eraser', 'select'];
18
+ this.defaultTool = options.defaultTool || 'pencil';
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 = ['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
+ }