@teachinglab/omd 0.7.27 → 0.7.29

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.
@@ -45,26 +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 = 'none';
48
+ this.toolbarGroup.svgObject.style.cursor = 'pointer';
49
49
 
50
50
  // Stop pointer events from bubbling to canvas to prevent drawing while interacting with toolbar
51
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
+
52
61
  this.toolbarGroup.svgObject.addEventListener('pointerdown', stopPropagation);
62
+ this.toolbarGroup.svgObject.addEventListener('pointermove', stopPropagation);
53
63
  this.toolbarGroup.svgObject.addEventListener('pointerup', stopPropagation);
54
-
55
- // Keep the custom cursor alive while hovering toolbar controls.
56
- this.toolbarGroup.svgObject.addEventListener('pointermove', (e) => {
57
- e.stopPropagation();
58
- this._syncCanvasCursor(e);
59
- });
60
- this.toolbarGroup.svgObject.addEventListener('pointerenter', (e) => {
61
- this._syncCanvasCursor(e, true);
62
- });
63
- this.toolbarGroup.svgObject.addEventListener('pointerleave', () => {
64
- if (this.canvas.cursor) {
65
- this.canvas.cursor.hide();
66
- }
67
- });
64
+ this.toolbarGroup.svgObject.addEventListener('pointerenter', hideCanvasCursor);
65
+ this.toolbarGroup.svgObject.addEventListener('pointerleave', restoreCanvasCursor);
66
+ this.toolbarGroup.svgObject.addEventListener('pointercancel', restoreCanvasCursor);
68
67
 
69
68
  // Create background rectangle
70
69
  this.background = new jsvgRect();
@@ -326,21 +325,30 @@ export class Toolbar {
326
325
  this.buttons.clear();
327
326
  }
328
327
 
329
- _syncCanvasCursor(event, forceShow = false) {
330
- if (!this.canvas?.cursor || !this.canvas?.clientToSVG) return;
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
+ }
331
338
 
332
- const canvasCoords = this.canvas.clientToSVG(event.clientX, event.clientY);
333
- this.canvas.cursor.setPosition(canvasCoords.x, canvasCoords.y);
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
+ }
334
343
 
335
- if (forceShow) {
336
- this.canvas.cursor.show();
337
- const activeTool = this.canvas.toolManager?.getActiveTool?.();
338
- if (activeTool?.getCursor) {
339
- this.canvas.cursor.setShape(activeTool.getCursor());
340
- }
341
- if (activeTool?.config) {
342
- this.canvas.cursor.updateFromToolConfig(activeTool.config);
343
- }
344
+ const activeTool = this.canvas.toolManager?.getActiveTool?.();
345
+ if (activeTool?.getCursor) {
346
+ this.canvas.cursor.setShape(activeTool.getCursor());
344
347
  }
348
+ if (activeTool?.config) {
349
+ this.canvas.cursor.updateFromToolConfig(activeTool.config);
350
+ }
351
+
352
+ this.canvas.cursor.show();
345
353
  }
346
354
  }
package/jsvg/jsvg.js CHANGED
@@ -400,6 +400,25 @@ export class jsvgEllipse extends jsvgObject
400
400
  this.height = h;
401
401
  this.svgObject.setAttribute("ry", (this.height/2).toString() );
402
402
  }
403
+
404
+ setPosition( x, y )
405
+ {
406
+ this.xpos = x;
407
+ this.ypos = y;
408
+ this.svgObject.setAttribute("cx", x.toString() );
409
+ this.svgObject.setAttribute("cy", y.toString() );
410
+ this.svgObject.setAttribute("transform", "" );
411
+ }
412
+
413
+ updateTransform()
414
+ {
415
+ var transformParams = "";
416
+ if ( this.scale != 1.0 )
417
+ transformParams += " scale(" + this.scale.toString() + ")";
418
+ if ( this.rotation != 0.0 )
419
+ transformParams += " rotate(" + this.rotation + ")";
420
+ this.svgObject.setAttribute("transform", transformParams.trim() );
421
+ }
403
422
  }
404
423
 
405
424
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teachinglab/omd",
3
- "version": "0.7.27",
3
+ "version": "0.7.29",
4
4
  "description": "omd",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",
package/readme.html CHANGED
@@ -145,7 +145,7 @@
145
145
  </div>
146
146
 
147
147
  <div class="content">
148
- <h1 id="omd-on-screen-math-display">OMD (Open Math Display)</h1>
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>
package/src/omdShapes.js CHANGED
@@ -148,10 +148,15 @@ export class omdIsoscelesTriangle extends jsvgGroup
148
148
  {
149
149
  this.shapePath.clearPoints();
150
150
 
151
- this.shapePath.addPoint( -0.5*this.unitScale*this.triangleBase, 0 );
152
- this.shapePath.addPoint( 0.5*this.unitScale*this.triangleBase, 0 );
153
- this.shapePath.addPoint( 0, -1.0*this.unitScale*this.triangleHeight );
154
- this.shapePath.addPoint( -0.5*this.unitScale*this.triangleBase, 0 );
151
+ const baseWidth = this.unitScale * this.triangleBase;
152
+ const triangleHeight = this.unitScale * this.triangleHeight;
153
+ const offsetX = 10;
154
+ const offsetY = triangleHeight + 10;
155
+
156
+ this.shapePath.addPoint( offsetX, offsetY );
157
+ this.shapePath.addPoint( offsetX + baseWidth, offsetY );
158
+ this.shapePath.addPoint( offsetX + baseWidth * 0.5, offsetY - triangleHeight );
159
+ this.shapePath.addPoint( offsetX, offsetY );
155
160
 
156
161
  this.shapePath.updatePath();
157
162
 
@@ -286,7 +291,11 @@ export class omdEllipse extends jsvgGroup
286
291
 
287
292
  updateLayout()
288
293
  {
289
- this.shapePath.setWidthAndHeight( this.rectWidth*this.unitScale, this.rectHeight*this.unitScale );
294
+ const ellipseWidth = this.rectWidth * this.unitScale;
295
+ const ellipseHeight = this.rectHeight * this.unitScale;
296
+
297
+ this.shapePath.setWidthAndHeight( ellipseWidth, ellipseHeight );
298
+ this.shapePath.setPosition( ellipseWidth * 0.5 + 10, ellipseHeight * 0.5 + 10 );
290
299
 
291
300
  // Set dimensions and viewBox for API compatibility
292
301
  this.width = this.rectWidth * this.unitScale + 20;
@@ -330,7 +339,10 @@ export class omdCircle extends jsvgGroup
330
339
 
331
340
  updateLayout()
332
341
  {
333
- this.shapePath.setWidthAndHeight( 2.0*this.radius*this.unitScale, 2.0*this.radius*this.unitScale );
342
+ const diameter = 2.0 * this.radius * this.unitScale;
343
+
344
+ this.shapePath.setWidthAndHeight( diameter, diameter );
345
+ this.shapePath.setPosition( this.radius * this.unitScale + 10, this.radius * this.unitScale + 10 );
334
346
 
335
347
  // Set dimensions and viewBox for API compatibility
336
348
  this.width = 2.0 * this.radius * this.unitScale + 20;