@teachinglab/omd 0.3.4 → 0.3.6
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/canvas/core/omdCanvas.js +1 -1
- package/canvas/index.js +0 -1
- package/canvas/ui/toolbar.js +2 -0
- package/index.js +4 -1
- package/package.json +1 -1
- package/src/omdEquation.js +59 -32
package/canvas/core/omdCanvas.js
CHANGED
|
@@ -7,7 +7,7 @@ import { SelectTool } from '../tools/SelectTool.js';
|
|
|
7
7
|
import { Cursor } from '../ui/cursor.js';
|
|
8
8
|
import { Toolbar } from '../ui/toolbar.js';
|
|
9
9
|
import { FocusFrameManager } from '../features/focusFrameManager.js';
|
|
10
|
-
|
|
10
|
+
import {jsvgGroup} from '@teachinglab/jsvg'
|
|
11
11
|
/**
|
|
12
12
|
* Main OMD Canvas class
|
|
13
13
|
* Provides the primary interface for creating and managing a drawing canvas
|
package/canvas/index.js
CHANGED
|
@@ -27,7 +27,6 @@ export { mathUtils } from './utils/mathUtils.js';
|
|
|
27
27
|
|
|
28
28
|
// Focus frame system
|
|
29
29
|
export { FocusFrameManager } from './features/focusFrameManager.js';
|
|
30
|
-
import { omdCanvas } from './core/omdCanvas.js';
|
|
31
30
|
/**
|
|
32
31
|
* Quick setup function for common use cases
|
|
33
32
|
* @param {HTMLElement|string} container - Container element or selector
|
package/canvas/ui/toolbar.js
CHANGED
package/index.js
CHANGED
|
@@ -13,10 +13,13 @@
|
|
|
13
13
|
|
|
14
14
|
// Export everything from the core OMD library (equations, nodes, display, etc.)
|
|
15
15
|
export * from './omd/core/index.js';
|
|
16
|
-
|
|
16
|
+
export * from './canvas/index.js';
|
|
17
17
|
// Export everything from the visualization components
|
|
18
18
|
export * from './src/index.js';
|
|
19
19
|
|
|
20
|
+
// Re-export canvas helpers/events so package consumers can import them from the package root
|
|
21
|
+
export { EventManager } from './canvas/events/eventManager.js';
|
|
22
|
+
|
|
20
23
|
// Export utility components
|
|
21
24
|
export { omdNodeOverlay, omdNodeOverlayPresets } from './omd/utils/omdNodeOverlay.js';
|
|
22
25
|
|
package/package.json
CHANGED
package/src/omdEquation.js
CHANGED
|
@@ -42,42 +42,69 @@ export class omdEquation extends omdMetaExpression
|
|
|
42
42
|
|
|
43
43
|
loadFromJSON( data )
|
|
44
44
|
{
|
|
45
|
-
|
|
45
|
+
// If explicit left/right JSON provided, build them according to their omdType
|
|
46
|
+
if ( typeof data.leftExpression != "undefined" && data.leftExpression )
|
|
46
47
|
{
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.
|
|
59
|
-
|
|
48
|
+
const left = data.leftExpression;
|
|
49
|
+
if ( left.omdType == "expression" ) this.leftExpression = new omdExpression();
|
|
50
|
+
else if ( left.omdType == "number" ) this.leftExpression = new omdNumber();
|
|
51
|
+
else if ( left.omdType == "variable" ) this.leftExpression = new omdVariable();
|
|
52
|
+
else if ( left.omdType == "term" ) this.leftExpression = new omdTerm();
|
|
53
|
+
else if ( left.omdType == "string" || typeof left == 'string' ) this.leftExpression = new omdString( typeof left == 'string' ? left : left.name || '' );
|
|
54
|
+
|
|
55
|
+
if (this.leftExpression && typeof this.leftExpression.loadFromJSON === 'function' && left && typeof left === 'object') {
|
|
56
|
+
this.leftExpression.loadFromJSON( left );
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (this.leftExpression) {
|
|
60
|
+
this.leftHolder.removeAllChildren();
|
|
61
|
+
this.leftHolder.addChild( this.leftExpression );
|
|
62
|
+
}
|
|
60
63
|
}
|
|
61
|
-
|
|
64
|
+
|
|
65
|
+
if ( typeof data.rightExpression != "undefined" && data.rightExpression )
|
|
62
66
|
{
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
this.
|
|
75
|
-
|
|
67
|
+
const right = data.rightExpression;
|
|
68
|
+
if ( right.omdType == "expression" ) this.rightExpression = new omdExpression();
|
|
69
|
+
else if ( right.omdType == "number" ) this.rightExpression = new omdNumber();
|
|
70
|
+
else if ( right.omdType == "variable" ) this.rightExpression = new omdVariable();
|
|
71
|
+
else if ( right.omdType == "term" ) this.rightExpression = new omdTerm();
|
|
72
|
+
else if ( right.omdType == "string" || typeof right == 'string' ) this.rightExpression = new omdString( typeof right == 'string' ? right : right.name || '' );
|
|
73
|
+
|
|
74
|
+
if (this.rightExpression && typeof this.rightExpression.loadFromJSON === 'function' && right && typeof right === 'object') {
|
|
75
|
+
this.rightExpression.loadFromJSON( right );
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (this.rightExpression) {
|
|
79
|
+
this.rightHolder.removeAllChildren();
|
|
80
|
+
this.rightHolder.addChild( this.rightExpression );
|
|
81
|
+
}
|
|
76
82
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this.leftExpression.
|
|
80
|
-
|
|
83
|
+
|
|
84
|
+
// If no structured left/right provided but an `equation` string exists, parse it into simple string nodes
|
|
85
|
+
if ( (!this.leftExpression || !this.rightExpression) && typeof data.equation === 'string' ) {
|
|
86
|
+
const eq = data.equation || '';
|
|
87
|
+
const parts = eq.split('=');
|
|
88
|
+
const leftStr = (parts[0] || '').trim();
|
|
89
|
+
const rightStr = (parts[1] || '').trim();
|
|
90
|
+
|
|
91
|
+
if (!this.leftExpression) this.leftExpression = new omdString(leftStr || '');
|
|
92
|
+
if (!this.rightExpression) this.rightExpression = new omdString(rightStr || '');
|
|
93
|
+
|
|
94
|
+
if (this.leftExpression) {
|
|
95
|
+
this.leftHolder.removeAllChildren();
|
|
96
|
+
this.leftHolder.addChild(this.leftExpression);
|
|
97
|
+
}
|
|
98
|
+
if (this.rightExpression) {
|
|
99
|
+
this.rightHolder.removeAllChildren();
|
|
100
|
+
this.rightHolder.addChild(this.rightExpression);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Guarded calls to hide backgrounds only when components exist
|
|
105
|
+
if (this.equalSign && typeof this.equalSign.hideBackgroundByDefault === 'function') this.equalSign.hideBackgroundByDefault();
|
|
106
|
+
if (this.leftExpression && typeof this.leftExpression.hideBackgroundByDefault === 'function') this.leftExpression.hideBackgroundByDefault();
|
|
107
|
+
if (this.rightExpression && typeof this.rightExpression.hideBackgroundByDefault === 'function') this.rightExpression.hideBackgroundByDefault();
|
|
81
108
|
|
|
82
109
|
this.centerEquation = false;
|
|
83
110
|
this.updateLayout();
|