@teachinglab/omd 0.7.34 → 0.7.36
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 +23 -0
- package/browser/index.js +130 -0
- package/canvas/events/eventManager.js +2 -2
- package/dist/canvas/index.js +48 -0
- package/dist/jsvg/index.js +3 -0
- package/dist/omd.browser.js +53212 -0
- package/dist/omd.global.js +114 -0
- package/dist/src/index.js +90 -0
- package/omd/core/omdEquationStack.js +3 -5
- package/omd/display/omdDisplay.js +3 -2
- package/omd/nodes/omdEquationSequenceNode.js +2 -2
- package/omd/step-visualizer/omdStepVisualizerLayout.js +7 -7
- package/package.json +9 -2
package/README.md
CHANGED
|
@@ -36,6 +36,29 @@ const display = new omdDisplay(container);
|
|
|
36
36
|
display.render('2x + 3 = 11');
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
### No-Build Browser Usage
|
|
40
|
+
|
|
41
|
+
```html
|
|
42
|
+
<script src="https://unpkg.com/@teachinglab/omd"></script>
|
|
43
|
+
<script>
|
|
44
|
+
const { createFromJSON, omdDisplay } = window.OMD;
|
|
45
|
+
|
|
46
|
+
const display = new omdDisplay(document.getElementById('math-container'));
|
|
47
|
+
const graph = createFromJSON({
|
|
48
|
+
omdType: 'coordinatePlane',
|
|
49
|
+
xMin: -5,
|
|
50
|
+
xMax: 5,
|
|
51
|
+
yMin: -5,
|
|
52
|
+
yMax: 5,
|
|
53
|
+
graphEquations: [{ equation: 'y=x+1', color: '#0f766e' }]
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
display.render(graph);
|
|
57
|
+
</script>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The browser bundle auto-registers `window.math`, so you do not need a separate math setup script.
|
|
61
|
+
|
|
39
62
|
## Documentation
|
|
40
63
|
|
|
41
64
|
### Getting Started
|
package/browser/index.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import * as mathjs from 'mathjs';
|
|
2
|
+
|
|
3
|
+
import { getNodeForAST } from '../omd/core/omdUtilities.js';
|
|
4
|
+
import { omdEquationNode } from '../omd/nodes/omdEquationNode.js';
|
|
5
|
+
import { omdStepVisualizer } from '../omd/step-visualizer/omdStepVisualizer.js';
|
|
6
|
+
|
|
7
|
+
const globalScope = (() => {
|
|
8
|
+
if (typeof globalThis !== 'undefined') return globalThis;
|
|
9
|
+
if (typeof window !== 'undefined') return window;
|
|
10
|
+
if (typeof global !== 'undefined') return global;
|
|
11
|
+
return undefined;
|
|
12
|
+
})();
|
|
13
|
+
|
|
14
|
+
if (globalScope && !globalScope.math) {
|
|
15
|
+
try {
|
|
16
|
+
globalScope.math = mathjs;
|
|
17
|
+
} catch (_) {
|
|
18
|
+
// Ignore read-only global environments.
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const math = mathjs;
|
|
23
|
+
|
|
24
|
+
export const omdHelpers = {
|
|
25
|
+
createNodeFromExpression(expression, mathInstance = mathjs) {
|
|
26
|
+
const parsedAST = mathInstance.parse(expression);
|
|
27
|
+
const NodeClass = getNodeForAST(parsedAST);
|
|
28
|
+
return new NodeClass(parsedAST);
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
createEquation(equationString) {
|
|
32
|
+
return omdEquationNode.fromString(equationString);
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
createStepVisualizer(equationStrings) {
|
|
36
|
+
const steps = equationStrings.map((equationString) =>
|
|
37
|
+
omdEquationNode.fromString(equationString)
|
|
38
|
+
);
|
|
39
|
+
return new omdStepVisualizer(steps);
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { omdNode } from '../omd/nodes/omdNode.js';
|
|
44
|
+
export { omdBinaryExpressionNode } from '../omd/nodes/omdBinaryExpressionNode.js';
|
|
45
|
+
export { omdConstantNode } from '../omd/nodes/omdConstantNode.js';
|
|
46
|
+
export { omdEquationNode } from '../omd/nodes/omdEquationNode.js';
|
|
47
|
+
export { omdFunctionNode } from '../omd/nodes/omdFunctionNode.js';
|
|
48
|
+
export { omdGroupNode } from '../omd/nodes/omdGroupNode.js';
|
|
49
|
+
export { omdLeafNode } from '../omd/nodes/omdLeafNode.js';
|
|
50
|
+
export { omdOperationDisplayNode } from '../omd/nodes/omdOperationDisplayNode.js';
|
|
51
|
+
export { omdOperatorNode } from '../omd/nodes/omdOperatorNode.js';
|
|
52
|
+
export { omdParenthesisNode } from '../omd/nodes/omdParenthesisNode.js';
|
|
53
|
+
export { omdPowerNode } from '../omd/nodes/omdPowerNode.js';
|
|
54
|
+
export { omdRationalNode } from '../omd/nodes/omdRationalNode.js';
|
|
55
|
+
export { omdEquationSequenceNode } from '../omd/nodes/omdEquationSequenceNode.js';
|
|
56
|
+
export { omdSqrtNode } from '../omd/nodes/omdSqrtNode.js';
|
|
57
|
+
export { omdUnaryExpressionNode } from '../omd/nodes/omdUnaryExpressionNode.js';
|
|
58
|
+
export { omdVariableNode } from '../omd/nodes/omdVariableNode.js';
|
|
59
|
+
export { omdEquationStack } from '../omd/core/omdEquationStack.js';
|
|
60
|
+
export { omdStepVisualizer } from '../omd/step-visualizer/omdStepVisualizer.js';
|
|
61
|
+
export { omdDisplay } from '../omd/display/omdDisplay.js';
|
|
62
|
+
export { omdToolbar } from '../omd/display/omdToolbar.js';
|
|
63
|
+
export { omdNodeOverlay, omdNodeOverlayPresets } from '../omd/utils/omdNodeOverlay.js';
|
|
64
|
+
export { omdTranscriptionService } from '../omd/utils/omdTranscriptionService.js';
|
|
65
|
+
export { getNodeForAST } from '../omd/core/omdUtilities.js';
|
|
66
|
+
export { simplifyStep } from '../omd/simplification/omdSimplification.js';
|
|
67
|
+
export {
|
|
68
|
+
initializeConfig,
|
|
69
|
+
setConfig,
|
|
70
|
+
getDefaultConfig,
|
|
71
|
+
} from '../omd/config/omdConfigManager.js';
|
|
72
|
+
|
|
73
|
+
export { omdTable } from '../src/omdTable.js';
|
|
74
|
+
export { omdBalanceHanger } from '../src/omdBalanceHanger.js';
|
|
75
|
+
export { omdCoordinatePlane } from '../src/omdCoordinatePlane.js';
|
|
76
|
+
export { omdTapeDiagram } from '../src/omdTapeDiagram.js';
|
|
77
|
+
export { omdDoubleTapeDiagram } from '../src/omdDoubleTapeDiagram.js';
|
|
78
|
+
export { omdTileEquation } from '../src/omdTileEquation.js';
|
|
79
|
+
export { omdRatioChart } from '../src/omdRatioChart.js';
|
|
80
|
+
export { omdNumberLine } from '../src/omdNumberLine.js';
|
|
81
|
+
export { omdDoubleNumberLine } from '../src/omdDoubleNumberLine.js';
|
|
82
|
+
export { omdNumberTile } from '../src/omdNumberTile.js';
|
|
83
|
+
export { omdEquation } from '../src/omdEquation.js';
|
|
84
|
+
export { omdExpression } from '../src/omdExpression.js';
|
|
85
|
+
export { omdTerm } from '../src/omdTerm.js';
|
|
86
|
+
export { omdNumber } from '../src/omdNumber.js';
|
|
87
|
+
export { omdVariable } from '../src/omdVariable.js';
|
|
88
|
+
export { omdPowerExpression } from '../src/omdPowerExpression.js';
|
|
89
|
+
export { omdRationalExpression } from '../src/omdRationalExpression.js';
|
|
90
|
+
export { omdFunction } from '../src/omdFunction.js';
|
|
91
|
+
export { omdApp } from '../src/omdApp.js';
|
|
92
|
+
export { omdAppCanvas } from '../src/omdAppCanvas.js';
|
|
93
|
+
export { omd } from '../src/omd.js';
|
|
94
|
+
export { omdColor } from '../src/omdColor.js';
|
|
95
|
+
export {
|
|
96
|
+
createFromJSON,
|
|
97
|
+
getSupportedTypes,
|
|
98
|
+
isTypeSupported,
|
|
99
|
+
} from '../src/omdFactory.js';
|
|
100
|
+
export {
|
|
101
|
+
omdRightTriangle,
|
|
102
|
+
omdIsoscelesTriangle,
|
|
103
|
+
omdRectangle,
|
|
104
|
+
omdEllipse,
|
|
105
|
+
omdCircle,
|
|
106
|
+
omdRegularPolygon,
|
|
107
|
+
omdShapeLabelSet,
|
|
108
|
+
} from '../src/omdShapes.js';
|
|
109
|
+
export { omdSpinner } from '../src/omdSpinner.js';
|
|
110
|
+
export { omdLabel } from '../src/omdLabel.js';
|
|
111
|
+
export { omdProblem } from '../src/omdProblem.js';
|
|
112
|
+
|
|
113
|
+
export { omdCanvas } from '../canvas/core/omdCanvas.js';
|
|
114
|
+
export { CanvasConfig as canvasConfig } from '../canvas/core/canvasConfig.js';
|
|
115
|
+
export { EventManager } from '../canvas/events/eventManager.js';
|
|
116
|
+
export { pointerEventHandler } from '../canvas/events/pointerEventHandler.js';
|
|
117
|
+
export { ToolManager } from '../canvas/tools/toolManager.js';
|
|
118
|
+
export { Tool } from '../canvas/tools/tool.js';
|
|
119
|
+
export { PencilTool } from '../canvas/tools/PencilTool.js';
|
|
120
|
+
export { EraserTool } from '../canvas/tools/EraserTool.js';
|
|
121
|
+
export { Toolbar } from '../canvas/ui/toolbar.js';
|
|
122
|
+
export { Cursor } from '../canvas/ui/cursor.js';
|
|
123
|
+
export { Stroke } from '../canvas/drawing/stroke.js';
|
|
124
|
+
export { segment } from '../canvas/drawing/segment.js';
|
|
125
|
+
export { BoundingBox } from '../canvas/utils/boundingBox.js';
|
|
126
|
+
export { mathUtils } from '../canvas/utils/mathUtils.js';
|
|
127
|
+
export { FocusFrameManager } from '../canvas/features/focusFrameManager.js';
|
|
128
|
+
export { createCanvas, createMultipleCanvases } from '../canvas/index.js';
|
|
129
|
+
|
|
130
|
+
export * from '../jsvg/index.js';
|
|
@@ -95,7 +95,7 @@ export class EventManager {
|
|
|
95
95
|
activeTool.onPointerDown(normalizedEvent);
|
|
96
96
|
// If tool hasn't explicitly set isDrawing, set it for backwards compatibility
|
|
97
97
|
// (tools like PencilTool and EraserTool expect isDrawing to be true)
|
|
98
|
-
if (this.isDrawing === false && activeTool
|
|
98
|
+
if (this.isDrawing === false && activeTool?.name !== 'pointer') {
|
|
99
99
|
this.isDrawing = true;
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -447,4 +447,4 @@ export class EventManager {
|
|
|
447
447
|
this.isDrawing = false;
|
|
448
448
|
this.isInitialized = false;
|
|
449
449
|
}
|
|
450
|
-
}
|
|
450
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Core canvas system
|
|
2
|
+
import { omdCanvas } from './core/omdCanvas.js';
|
|
3
|
+
export { omdCanvas } from './core/omdCanvas.js';
|
|
4
|
+
export { CanvasConfig as canvasConfig } from './core/canvasConfig.js';
|
|
5
|
+
|
|
6
|
+
// Event handling
|
|
7
|
+
export { EventManager } from './events/eventManager.js';
|
|
8
|
+
export { pointerEventHandler } from './events/pointerEventHandler.js';
|
|
9
|
+
|
|
10
|
+
// Tool system
|
|
11
|
+
export { ToolManager } from './tools/toolManager.js';
|
|
12
|
+
export { Tool } from './tools/tool.js';
|
|
13
|
+
export { PencilTool } from './tools/PencilTool.js';
|
|
14
|
+
export { EraserTool } from './tools/EraserTool.js';
|
|
15
|
+
|
|
16
|
+
// UI components
|
|
17
|
+
export { Toolbar } from './ui/toolbar.js';
|
|
18
|
+
export { Cursor } from './ui/cursor.js';
|
|
19
|
+
|
|
20
|
+
// Drawing objects
|
|
21
|
+
export { Stroke } from './drawing/stroke.js';
|
|
22
|
+
export { segment } from './drawing/segment.js';
|
|
23
|
+
|
|
24
|
+
// Utilities
|
|
25
|
+
export { BoundingBox } from './utils/boundingBox.js';
|
|
26
|
+
export { mathUtils } from './utils/mathUtils.js';
|
|
27
|
+
|
|
28
|
+
// Focus frame system
|
|
29
|
+
export { FocusFrameManager } from './features/focusFrameManager.js';
|
|
30
|
+
/**
|
|
31
|
+
* Quick setup function for common use cases
|
|
32
|
+
* @param {HTMLElement|string} container - Container element or selector
|
|
33
|
+
* @param {Object} options - Configuration options
|
|
34
|
+
* @returns {omdCanvas} Configured canvas instance
|
|
35
|
+
*/
|
|
36
|
+
export function createCanvas(container, options = {}) {
|
|
37
|
+
const canvas = new omdCanvas(container, options);
|
|
38
|
+
return canvas;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Create multiple canvas instances for comparison or multi-canvas apps
|
|
43
|
+
* @param {Array} configs - Array of {container, options} objects
|
|
44
|
+
* @returns {Array<omdCanvas>} Array of canvas instances
|
|
45
|
+
*/
|
|
46
|
+
export function createMultipleCanvases(configs) {
|
|
47
|
+
return configs.map(config => createCanvas(config.container, config.options));
|
|
48
|
+
}
|