@teachinglab/omd 0.7.26 → 0.7.28
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/ui/toolbar.js +40 -0
- package/package.json +1 -1
- package/readme.html +1 -1
package/canvas/ui/toolbar.js
CHANGED
|
@@ -45,12 +45,25 @@ export class Toolbar {
|
|
|
45
45
|
|
|
46
46
|
// Create a jsvgGroup for the toolbar
|
|
47
47
|
this.toolbarGroup = new jsvgGroup();
|
|
48
|
+
this.toolbarGroup.svgObject.style.cursor = 'pointer';
|
|
48
49
|
|
|
49
50
|
// Stop pointer events from bubbling to canvas to prevent drawing while interacting with toolbar
|
|
50
51
|
const stopPropagation = (e) => e.stopPropagation();
|
|
52
|
+
const hideCanvasCursor = (e) => {
|
|
53
|
+
e.stopPropagation();
|
|
54
|
+
this.canvas.cursor?.hide?.();
|
|
55
|
+
};
|
|
56
|
+
const restoreCanvasCursor = (e) => {
|
|
57
|
+
e.stopPropagation();
|
|
58
|
+
this._restoreCanvasCursor(e);
|
|
59
|
+
};
|
|
60
|
+
|
|
51
61
|
this.toolbarGroup.svgObject.addEventListener('pointerdown', stopPropagation);
|
|
52
62
|
this.toolbarGroup.svgObject.addEventListener('pointermove', stopPropagation);
|
|
53
63
|
this.toolbarGroup.svgObject.addEventListener('pointerup', stopPropagation);
|
|
64
|
+
this.toolbarGroup.svgObject.addEventListener('pointerenter', hideCanvasCursor);
|
|
65
|
+
this.toolbarGroup.svgObject.addEventListener('pointerleave', restoreCanvasCursor);
|
|
66
|
+
this.toolbarGroup.svgObject.addEventListener('pointercancel', restoreCanvasCursor);
|
|
54
67
|
|
|
55
68
|
// Create background rectangle
|
|
56
69
|
this.background = new jsvgRect();
|
|
@@ -311,4 +324,31 @@ export class Toolbar {
|
|
|
311
324
|
}
|
|
312
325
|
this.buttons.clear();
|
|
313
326
|
}
|
|
327
|
+
|
|
328
|
+
_restoreCanvasCursor(event) {
|
|
329
|
+
if (!this.canvas?.cursor) return;
|
|
330
|
+
|
|
331
|
+
const nextTarget = event?.relatedTarget;
|
|
332
|
+
const isStillInsideCanvas = !!(nextTarget && this.canvas?.svg?.contains?.(nextTarget));
|
|
333
|
+
|
|
334
|
+
if (!isStillInsideCanvas) {
|
|
335
|
+
this.canvas.cursor.hide();
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (this.canvas.clientToSVG && typeof event?.clientX === 'number' && typeof event?.clientY === 'number') {
|
|
340
|
+
const canvasCoords = this.canvas.clientToSVG(event.clientX, event.clientY);
|
|
341
|
+
this.canvas.cursor.setPosition(canvasCoords.x, canvasCoords.y);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const activeTool = this.canvas.toolManager?.getActiveTool?.();
|
|
345
|
+
if (activeTool?.getCursor) {
|
|
346
|
+
this.canvas.cursor.setShape(activeTool.getCursor());
|
|
347
|
+
}
|
|
348
|
+
if (activeTool?.config) {
|
|
349
|
+
this.canvas.cursor.updateFromToolConfig(activeTool.config);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
this.canvas.cursor.show();
|
|
353
|
+
}
|
|
314
354
|
}
|
package/package.json
CHANGED
package/readme.html
CHANGED
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
</div>
|
|
146
146
|
|
|
147
147
|
<div class="content">
|
|
148
|
-
<h1 id="omd-
|
|
148
|
+
<h1 id="omd-open-math-display">OMD (Open Math Display)</h1>
|
|
149
149
|
<blockquote>
|
|
150
150
|
<p>A JavaScript library for creating interactive mathematical interfaces in web applications</p>
|
|
151
151
|
</blockquote>
|