@teachinglab/omd 0.7.21 → 0.7.23
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 +9 -2
- package/canvas/events/eventManager.js +8 -3
- package/canvas/ui/cursor.js +2 -2
- package/package.json +1 -1
- package/src/index.js +1 -0
- package/src/omdFactory.js +3 -1
- package/src/omdLabel.js +66 -0
package/canvas/core/omdCanvas.js
CHANGED
|
@@ -117,6 +117,8 @@ export class omdCanvas {
|
|
|
117
117
|
this.svg.setAttribute('viewBox', `0 0 ${this.config.width} ${this.config.height}`);
|
|
118
118
|
this.svg.style.cssText = `
|
|
119
119
|
display: block;
|
|
120
|
+
width: 100%;
|
|
121
|
+
height: 100%;
|
|
120
122
|
background: ${this.config.backgroundColor};
|
|
121
123
|
cursor: none;
|
|
122
124
|
touch-action: none;
|
|
@@ -441,11 +443,16 @@ export class omdCanvas {
|
|
|
441
443
|
}
|
|
442
444
|
|
|
443
445
|
/**
|
|
444
|
-
* Handle window resize
|
|
446
|
+
* Handle window resize — resize the canvas to match the container.
|
|
445
447
|
* @private
|
|
446
448
|
*/
|
|
447
449
|
_handleResize() {
|
|
448
|
-
|
|
450
|
+
if (!this.container) return;
|
|
451
|
+
const w = Math.max(400, this.container.clientWidth || this.container.getBoundingClientRect().width || 0);
|
|
452
|
+
const h = Math.max(400, this.container.clientHeight || this.container.getBoundingClientRect().height || 0);
|
|
453
|
+
if (!w || !h) return;
|
|
454
|
+
if (Math.abs(w - this.config.width) < 1 && Math.abs(h - this.config.height) < 1) return;
|
|
455
|
+
this.resize(w, h);
|
|
449
456
|
}
|
|
450
457
|
|
|
451
458
|
/**
|
|
@@ -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
|
-
//
|
|
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
|
|
220
|
-
|
|
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
|
package/canvas/ui/cursor.js
CHANGED
|
@@ -60,8 +60,8 @@ export class Cursor {
|
|
|
60
60
|
this.element.appendChild(shape);
|
|
61
61
|
});
|
|
62
62
|
|
|
63
|
-
// Show
|
|
64
|
-
this.setShape('
|
|
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
package/src/index.js
CHANGED
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
|
/**
|
package/src/omdLabel.js
ADDED
|
@@ -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
|
+
}
|