@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.
@@ -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
@@ -1,4 +1,6 @@
1
1
  import {omdColor} from '../../src/omdColor.js';
2
+ import { jsvgRect, jsvgGroup } from '@teachinglab/jsvg';
3
+ import { jsvgButton } from '@teachinglab/jsvg';
2
4
 
3
5
  export class Toolbar {
4
6
  /**
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teachinglab/omd",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "description": "omd",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",
@@ -42,42 +42,69 @@ export class omdEquation extends omdMetaExpression
42
42
 
43
43
  loadFromJSON( data )
44
44
  {
45
- if ( typeof data.leftExpression != "undefined" )
45
+ // If explicit left/right JSON provided, build them according to their omdType
46
+ if ( typeof data.leftExpression != "undefined" && data.leftExpression )
46
47
  {
47
- // console.log("A");
48
- // console.log( data.leftExpression );
49
- if ( data.leftExpression.omdType == "expression" )
50
- this.leftExpression = new omdExpression();
51
- if ( data.leftExpression.omdType == "number" )
52
- this.leftExpression = new omdNumber();
53
- if ( data.leftExpression.omdType == "variable" )
54
- this.leftExpression = new omdVariable();
55
- if ( data.leftExpression.omdType == "term" )
56
- this.leftExpression = new omdTerm();
57
- this.leftExpression.loadFromJSON( data.leftExpression );
58
- this.leftHolder.removeAllChildren();
59
- this.leftHolder.addChild( this.leftExpression );
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
- if ( typeof data.rightExpression != "undefined" )
64
+
65
+ if ( typeof data.rightExpression != "undefined" && data.rightExpression )
62
66
  {
63
- // console.log("B");
64
- // console.log( data.exponentExpression );
65
- if ( data.rightExpression.omdType == "expression" )
66
- this.rightExpression = new omdExpression();
67
- if ( data.rightExpression.omdType == "number" )
68
- this.rightExpression = new omdNumber();
69
- if ( data.rightExpression.omdType == "variable" )
70
- this.rightExpression = new omdVariable();
71
- if ( data.rightExpression.omdType == "term" )
72
- this.rightExpression = new omdTerm();
73
- this.rightExpression.loadFromJSON( data.rightExpression );
74
- this.rightHolder.removeAllChildren();
75
- this.rightHolder.addChild( this.rightExpression );
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
- this.equalSign.hideBackgroundByDefault();
79
- this.leftExpression.hideBackgroundByDefault();
80
- this.rightExpression.hideBackgroundByDefault();
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();