@teachinglab/omd 0.7.21 → 0.7.22

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.
@@ -214,10 +214,15 @@ export class EventManager {
214
214
  // Show custom cursor when entering canvas
215
215
  if (this.canvas.cursor) {
216
216
  this.canvas.cursor.show();
217
- // Update cursor from current tool config
217
+ // Ensure the cursor shape matches the active tool (fixes stale crosshair on first entry)
218
218
  const activeTool = this.canvas.toolManager.getActiveTool();
219
- if (activeTool && activeTool.config) {
220
- this.canvas.cursor.updateFromToolConfig(activeTool.config);
219
+ if (activeTool) {
220
+ if (activeTool.getCursor) {
221
+ this.canvas.cursor.setShape(activeTool.getCursor());
222
+ }
223
+ if (activeTool.config) {
224
+ this.canvas.cursor.updateFromToolConfig(activeTool.config);
225
+ }
221
226
  }
222
227
  }
223
228
  // If mouse is down (event.buttons !== 0), start drawing
@@ -60,8 +60,8 @@ export class Cursor {
60
60
  this.element.appendChild(shape);
61
61
  });
62
62
 
63
- // Show default shape initially
64
- this.setShape('default');
63
+ // Show pencil (blue dot) shape initially so the first visible cursor is always a dot
64
+ this.setShape('pencil');
65
65
  }
66
66
 
67
67
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teachinglab/omd",
3
- "version": "0.7.21",
3
+ "version": "0.7.22",
4
4
  "description": "omd",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",
package/src/index.js CHANGED
@@ -48,6 +48,7 @@ export {
48
48
  omdShapeLabelSet
49
49
  } from './omdShapes.js';
50
50
  export { omdSpinner } from './omdSpinner.js';
51
+ export { omdLabel } from './omdLabel.js';
51
52
  export { omdProblem } from './omdProblem.js';
52
53
 
53
54
  // Default export for organized access
package/src/omdFactory.js CHANGED
@@ -42,6 +42,7 @@ import {
42
42
  omdCircle,
43
43
  omdRegularPolygon
44
44
  } from './omdShapes.js';
45
+ import { omdLabel } from './omdLabel.js';
45
46
 
46
47
  /**
47
48
  * Map of omdType strings to their corresponding class constructors
@@ -71,7 +72,8 @@ const OMD_TYPE_MAP = {
71
72
  'rectangle': omdRectangle,
72
73
  'ellipse': omdEllipse,
73
74
  'circle': omdCircle,
74
- 'regularPolygon': omdRegularPolygon
75
+ 'regularPolygon': omdRegularPolygon,
76
+ 'label': omdLabel,
75
77
  };
76
78
 
77
79
  /**
@@ -0,0 +1,66 @@
1
+ import { omdMetaExpression } from "./omdMetaExpression.js";
2
+ import { jsvgTextBox } from "@teachinglab/jsvg";
3
+
4
+ const SIZE_MAP = {
5
+ small: 14,
6
+ medium: 20,
7
+ large: 28,
8
+ };
9
+
10
+ export class omdLabel extends omdMetaExpression
11
+ {
12
+ constructor()
13
+ {
14
+ super();
15
+
16
+ this.type = "omdLabel";
17
+ this.text = "";
18
+ this.size = "medium"; // small | medium | large
19
+
20
+ this.textBox = new jsvgTextBox();
21
+ this.textBox.setFontFamily("Albert Sans");
22
+ this.textBox.setFontColor("black");
23
+ this.textBox.setVerticalCentering();
24
+ this.textBox.setAlignment("left");
25
+ this.addChild(this.textBox);
26
+
27
+ this.backRect.setFillColor("transparent");
28
+ this.backRect.setOpacity(0);
29
+ }
30
+
31
+ loadFromJSON(data)
32
+ {
33
+ if (typeof data === 'string') {
34
+ this.text = data;
35
+ } else {
36
+ if (typeof data.text !== "undefined") this.text = data.text;
37
+ if (typeof data.size !== "undefined") this.size = data.size;
38
+ if (typeof data.color !== "undefined") this.textBox.setFontColor(data.color);
39
+ }
40
+ this.updateLayout();
41
+ }
42
+
43
+ updateLayout()
44
+ {
45
+ const fontSize = SIZE_MAP[this.size] ?? SIZE_MAP.medium;
46
+ this.textBox.setFontSize(fontSize);
47
+
48
+ const padding = 8;
49
+ const approxCharW = fontSize * 0.58;
50
+ const W = Math.max(60, Math.ceil(String(this.text).length * approxCharW) + padding * 2);
51
+ const H = fontSize + padding * 2;
52
+
53
+ this.textBox.setWidthAndHeight(W, H);
54
+ this.textBox.setText(this.text ?? "");
55
+
56
+ this.backRect.setWidthAndHeight(W, H);
57
+ this.setWidthAndHeight(W, H);
58
+ this.width = W;
59
+ this.height = H;
60
+ }
61
+
62
+ hideBackgroundByDefault()
63
+ {
64
+ this.backRect.setOpacity(0);
65
+ }
66
+ }