plotboilerplate 1.20.1 → 1.21.0

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.
Files changed (141) hide show
  1. package/README.md +17 -1
  2. package/dist/index.esm.js +2065 -1397
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.esm.min.js +1 -1
  5. package/dist/index.esm.min.js.map +1 -1
  6. package/dist/plotboilerplate.browser.min.js +1 -1
  7. package/dist/plotboilerplate.browser.min.js.map +1 -1
  8. package/dist/plotboilerplate.js +1265 -584
  9. package/dist/plotboilerplate.min.js +1 -1
  10. package/package.json +2 -1
  11. package/src/cjs/BezierPath.d.ts +27 -49
  12. package/src/cjs/BezierPath.js +69 -237
  13. package/src/cjs/BezierPath.js.map +1 -1
  14. package/src/cjs/Bounds.d.ts +14 -1
  15. package/src/cjs/Bounds.js +21 -1
  16. package/src/cjs/Bounds.js.map +1 -1
  17. package/src/cjs/CubicBezierCurve.d.ts +70 -1
  18. package/src/cjs/CubicBezierCurve.js +130 -12
  19. package/src/cjs/CubicBezierCurve.js.map +1 -1
  20. package/src/cjs/Line.d.ts +2 -1
  21. package/src/cjs/Line.js +1 -0
  22. package/src/cjs/Line.js.map +1 -1
  23. package/src/cjs/PBText.d.ts +2 -1
  24. package/src/cjs/PBText.js +10 -9
  25. package/src/cjs/PBText.js.map +1 -1
  26. package/src/cjs/PlotBoilerplate.d.ts +10 -13
  27. package/src/cjs/PlotBoilerplate.js +136 -47
  28. package/src/cjs/PlotBoilerplate.js.map +1 -1
  29. package/src/cjs/Polygon.d.ts +35 -1
  30. package/src/cjs/Polygon.js +87 -1
  31. package/src/cjs/Polygon.js.map +1 -1
  32. package/src/cjs/Triangle.js +1 -0
  33. package/src/cjs/Triangle.js.map +1 -1
  34. package/src/cjs/VEllipse.js +1 -1
  35. package/src/cjs/VEllipse.js.map +1 -1
  36. package/src/cjs/Vector.d.ts +4 -4
  37. package/src/cjs/Vector.js +2 -2
  38. package/src/cjs/Vector.js.map +1 -1
  39. package/src/cjs/VertTuple.d.ts +2 -1
  40. package/src/cjs/VertTuple.js +4 -3
  41. package/src/cjs/VertTuple.js.map +1 -1
  42. package/src/cjs/Vertex.d.ts +14 -3
  43. package/src/cjs/Vertex.js +18 -3
  44. package/src/cjs/Vertex.js.map +1 -1
  45. package/src/cjs/draw.d.ts +159 -79
  46. package/src/cjs/draw.js +311 -139
  47. package/src/cjs/draw.js.map +1 -1
  48. package/src/cjs/drawgl.d.ts +93 -55
  49. package/src/cjs/drawgl.js +90 -34
  50. package/src/cjs/drawgl.js.map +1 -1
  51. package/src/cjs/drawutilssvg.d.ts +233 -58
  52. package/src/cjs/drawutilssvg.js +384 -95
  53. package/src/cjs/drawutilssvg.js.map +1 -1
  54. package/src/cjs/interfaces/DrawLib.d.ts +161 -82
  55. package/src/cjs/interfaces/DrawLib.js +7 -0
  56. package/src/cjs/interfaces/DrawLib.js.map +1 -1
  57. package/src/cjs/interfaces/core.d.ts +46 -32
  58. package/src/cjs/interfaces/core.js +2 -0
  59. package/src/cjs/interfaces/core.js.map +1 -1
  60. package/src/cjs/utils/creategui.js +16 -10
  61. package/src/cjs/utils/datastructures/Color.d.ts +3 -1
  62. package/src/cjs/utils/datastructures/Color.js +12 -1
  63. package/src/cjs/utils/datastructures/Color.js.map +1 -1
  64. package/src/cjs/utils/detectDarkMode.d.ts +10 -0
  65. package/src/cjs/utils/detectDarkMode.js +32 -0
  66. package/src/cjs/utils/detectDarkMode.js.map +1 -0
  67. package/src/cjs/utils/module.js +4 -2
  68. package/src/esm/BezierPath.d.ts +27 -49
  69. package/src/esm/BezierPath.js +69 -237
  70. package/src/esm/BezierPath.js.map +1 -1
  71. package/src/esm/Bounds.d.ts +14 -1
  72. package/src/esm/Bounds.js +19 -1
  73. package/src/esm/Bounds.js.map +1 -1
  74. package/src/esm/CubicBezierCurve.d.ts +70 -1
  75. package/src/esm/CubicBezierCurve.js +130 -12
  76. package/src/esm/CubicBezierCurve.js.map +1 -1
  77. package/src/esm/Line.d.ts +2 -1
  78. package/src/esm/Line.js +1 -0
  79. package/src/esm/Line.js.map +1 -1
  80. package/src/esm/PBText.d.ts +2 -1
  81. package/src/esm/PBText.js +10 -9
  82. package/src/esm/PBText.js.map +1 -1
  83. package/src/esm/PlotBoilerplate.d.ts +10 -13
  84. package/src/esm/PlotBoilerplate.js +136 -48
  85. package/src/esm/PlotBoilerplate.js.map +1 -1
  86. package/src/esm/Polygon.d.ts +35 -1
  87. package/src/esm/Polygon.js +85 -1
  88. package/src/esm/Polygon.js.map +1 -1
  89. package/src/esm/Triangle.js +1 -0
  90. package/src/esm/Triangle.js.map +1 -1
  91. package/src/esm/VEllipse.js +1 -1
  92. package/src/esm/VEllipse.js.map +1 -1
  93. package/src/esm/Vector.d.ts +4 -4
  94. package/src/esm/Vector.js +2 -2
  95. package/src/esm/Vector.js.map +1 -1
  96. package/src/esm/VertTuple.d.ts +2 -1
  97. package/src/esm/VertTuple.js +4 -3
  98. package/src/esm/VertTuple.js.map +1 -1
  99. package/src/esm/Vertex.d.ts +14 -3
  100. package/src/esm/Vertex.js +18 -3
  101. package/src/esm/Vertex.js.map +1 -1
  102. package/src/esm/draw.d.ts +159 -79
  103. package/src/esm/draw.js +307 -137
  104. package/src/esm/draw.js.map +1 -1
  105. package/src/esm/drawgl.d.ts +93 -55
  106. package/src/esm/drawgl.js +90 -34
  107. package/src/esm/drawgl.js.map +1 -1
  108. package/src/esm/drawutilssvg.d.ts +233 -58
  109. package/src/esm/drawutilssvg.js +379 -95
  110. package/src/esm/drawutilssvg.js.map +1 -1
  111. package/src/esm/interfaces/DrawLib.d.ts +161 -82
  112. package/src/esm/interfaces/DrawLib.js +7 -0
  113. package/src/esm/interfaces/DrawLib.js.map +1 -1
  114. package/src/esm/interfaces/core.d.ts +46 -32
  115. package/src/esm/interfaces/core.js +2 -0
  116. package/src/esm/interfaces/core.js.map +1 -1
  117. package/src/esm/utils/datastructures/Color.d.ts +3 -1
  118. package/src/esm/utils/datastructures/Color.js +12 -1
  119. package/src/esm/utils/datastructures/Color.js.map +1 -1
  120. package/src/esm/utils/detectDarkMode.d.ts +10 -0
  121. package/src/esm/utils/detectDarkMode.js +28 -0
  122. package/src/esm/utils/detectDarkMode.js.map +1 -0
  123. package/src/ts/BezierPath.ts +74 -244
  124. package/src/ts/Bounds.ts +25 -1
  125. package/src/ts/CubicBezierCurve.ts +139 -12
  126. package/src/ts/Line.ts +2 -1
  127. package/src/ts/PBText.ts +10 -9
  128. package/src/ts/PlotBoilerplate.ts +130 -50
  129. package/src/ts/Polygon.ts +91 -1
  130. package/src/ts/Triangle.ts +2 -1
  131. package/src/ts/VEllipse.ts +2 -2
  132. package/src/ts/Vector.ts +4 -4
  133. package/src/ts/VertTuple.ts +4 -3
  134. package/src/ts/Vertex.ts +20 -4
  135. package/src/ts/draw.ts +316 -119
  136. package/src/ts/drawgl.ts +141 -78
  137. package/src/ts/drawutilssvg.ts +562 -133
  138. package/src/ts/interfaces/DrawLib.ts +223 -86
  139. package/src/ts/interfaces/core.ts +47 -32
  140. package/src/ts/utils/datastructures/Color.ts +13 -1
  141. package/src/ts/utils/detectDarkMode.ts +30 -0
@@ -79,7 +79,12 @@
79
79
  * @modified 2022-10-25 Added the `origin` to the default draw config.
80
80
  * @modified 2022-11-06 Adding an XML declaration to the SVG export routine.
81
81
  * @modified 2022-11-23 Added the `drawRaster` (default=true) option to the config/drawconfig.
82
- * @version 1.17.0
82
+ * @modified 2023-02-04 Fixed a bug in the `drawDrawable` function; fill's current classname was not set.
83
+ * @modified 2023-02-10 Fixing an issue of the `style.position` setting when `fitToParent=true` from `absolute` to `static` (default).
84
+ * @modified 2023-02-10 Cleaning up most type errors in the main class (mostly null checks).
85
+ * @modified 2023-02-10 Adding `enableZoom` and `enablePan` (both default true) to have the option to disable these functions.
86
+ * @modified 2023-09-29 Adding proper dicionary key and value types to the params of `PlotBoilerplate.utils.safeMergeByKeys` (was `object` before).
87
+ * @version 1.17.3
83
88
  *
84
89
  * @file PlotBoilerplate
85
90
  * @fileoverview The main class.
@@ -191,6 +196,8 @@ var PlotBoilerplate = /** @class */ (function () {
191
196
  * @param {boolean=} [config.enableTouch=true] - Indicates if the application should handle touch events for you.
192
197
  * @param {boolean=} [config.enableKeys=true] - Indicates if the application should handle key events for you.
193
198
  * @param {boolean=} [config.enableMouseWheel=true] - Indicates if the application should handle mouse wheel events for you.
199
+ * @param {boolean=} [config.enablePan=true] - (default true) Set to false if you want to disable panning completely.
200
+ * @param {boolean=} [config.enableZoom=true] - (default true) Set to false if you want to disable zooming completely.
194
201
  * @param {boolean=} [config.enableGL=false] - Indicates if the application should use the experimental WebGL features (not recommended).
195
202
  * @param {boolean=} [config.enableSVGExport=true] - Indicates if the SVG export should be enabled (default is true).
196
203
  * Note that changes from the postDraw hook might not be visible in the export.
@@ -217,7 +224,7 @@ var PlotBoilerplate = /** @class */ (function () {
217
224
  draggable: true,
218
225
  visible: true
219
226
  };
220
- if (typeof config.canvas == "undefined") {
227
+ if (typeof config.canvas === "undefined") {
221
228
  throw "No canvas specified.";
222
229
  }
223
230
  /**
@@ -271,6 +278,8 @@ var PlotBoilerplate = /** @class */ (function () {
271
278
  enableTouch: f.bool(config, "enableTouch", true),
272
279
  enableKeys: f.bool(config, "enableKeys", true),
273
280
  enableMouseWheel: f.bool(config, "enableMouseWheel", true),
281
+ enableZoom: f.bool(config, "enableZoom", true),
282
+ enablePan: f.bool(config, "enablePan", true),
274
283
  // Experimental (and unfinished)
275
284
  enableGL: f.bool(config, "enableGL", false)
276
285
  }; // END confog
@@ -307,6 +316,10 @@ var PlotBoilerplate = /** @class */ (function () {
307
316
  fill: true
308
317
  }
309
318
  },
319
+ // bezierPath: {
320
+ // color: "#0022a8",
321
+ // lineWidth: 1
322
+ // },
310
323
  polygon: {
311
324
  color: "#0022a8",
312
325
  lineWidth: 1
@@ -366,7 +379,10 @@ var PlotBoilerplate = /** @class */ (function () {
366
379
  // +-------------------------------
367
380
  this.grid = new Grid_1.Grid(new Vertex_1.Vertex(0, 0), new Vertex_1.Vertex(50, 50));
368
381
  this.canvasSize = { width: PlotBoilerplate.DEFAULT_CANVAS_WIDTH, height: PlotBoilerplate.DEFAULT_CANVAS_HEIGHT };
369
- var canvasElement = typeof config.canvas == "string" ? document.querySelector(config.canvas) : config.canvas;
382
+ var canvasElement = typeof config.canvas === "string" ? document.querySelector(config.canvas) : config.canvas;
383
+ if (typeof canvasElement === "undefined") {
384
+ throw "Cannot initialize PlotBoilerplate with a null canvas (element \"" + config.canvas + " not found).";
385
+ }
370
386
  // Which renderer to use: Canvas2D, WebGL (experimental) or SVG?
371
387
  if (canvasElement.tagName.toLowerCase() === "canvas") {
372
388
  this.canvas = canvasElement;
@@ -935,7 +951,7 @@ var PlotBoilerplate = /** @class */ (function () {
935
951
  this.draw.setCurrentId(d.uid);
936
952
  this.fill.setCurrentId(d.uid);
937
953
  this.draw.setCurrentClassName(d.className);
938
- this.draw.setCurrentClassName(d.className);
954
+ this.fill.setCurrentClassName(d.className);
939
955
  this.drawDrawable(d, renderTime, draw, fill);
940
956
  }
941
957
  };
@@ -956,7 +972,13 @@ var PlotBoilerplate = /** @class */ (function () {
956
972
  **/
957
973
  PlotBoilerplate.prototype.drawDrawable = function (d, renderTime, draw, fill) {
958
974
  if (d instanceof BezierPath_1.BezierPath) {
975
+ var curveIndex = 0;
959
976
  for (var c in d.bezierCurves) {
977
+ // Restore these settings again in each loop (will be overwritten)
978
+ this.draw.setCurrentId(d.uid + "-" + curveIndex);
979
+ this.fill.setCurrentId(d.uid + "-" + curveIndex);
980
+ this.draw.setCurrentClassName(d.className);
981
+ this.fill.setCurrentClassName(d.className);
960
982
  draw.cubicBezier(d.bezierCurves[c].startPoint, d.bezierCurves[c].endPoint, d.bezierCurves[c].startControlPoint, d.bezierCurves[c].endControlPoint, this.drawConfig.bezier.color, this.drawConfig.bezier.lineWidth);
961
983
  if (this.drawConfig.drawBezierHandlePoints && this.drawConfig.drawHandlePoints) {
962
984
  if (d.bezierCurves[c].startPoint.attr.visible) {
@@ -1008,12 +1030,13 @@ var PlotBoilerplate = /** @class */ (function () {
1008
1030
  if (this.drawConfig.drawBezierHandleLines && this.drawConfig.drawHandleLines) {
1009
1031
  draw.setCurrentId(d.uid + "_l0");
1010
1032
  draw.setCurrentClassName(d.className + "-start-line");
1011
- draw.line(d.bezierCurves[c].startPoint, d.bezierCurves[c].startControlPoint, this.drawConfig.bezier.handleLine.color, this.drawConfig.bezier.handleLine.lineWidth);
1033
+ draw.handleLine(d.bezierCurves[c].startPoint, d.bezierCurves[c].startControlPoint);
1012
1034
  draw.setCurrentId(d.uid + "_l1");
1013
1035
  draw.setCurrentClassName(d.className + "-end-line");
1014
- draw.line(d.bezierCurves[c].endPoint, d.bezierCurves[c].endControlPoint, this.drawConfig.bezier.handleLine.color, this.drawConfig.bezier.handleLine.lineWidth);
1036
+ draw.handleLine(d.bezierCurves[c].endPoint, d.bezierCurves[c].endControlPoint);
1015
1037
  }
1016
- }
1038
+ curveIndex++;
1039
+ } // END for
1017
1040
  }
1018
1041
  else if (d instanceof Polygon_1.Polygon) {
1019
1042
  draw.polygon(d, this.drawConfig.polygon.color, this.drawConfig.polygon.lineWidth);
@@ -1033,11 +1056,11 @@ var PlotBoilerplate = /** @class */ (function () {
1033
1056
  draw.setCurrentId(d.uid + "_e0");
1034
1057
  draw.setCurrentClassName(d.className + "-v-line");
1035
1058
  // draw.line( d.center.clone().add(0,d.axis.y-d.center.y), d.axis, '#c8c8c8' );
1036
- draw.line(d.center.clone().add(0, d.signedRadiusV()).rotate(d.rotation, d.center), d.axis, "#c8c8c8");
1059
+ draw.handleLine(d.center.clone().add(0, d.signedRadiusV()).rotate(d.rotation, d.center), d.axis); // , "#c8c8c8");
1037
1060
  draw.setCurrentId(d.uid + "_e1");
1038
1061
  draw.setCurrentClassName(d.className + "-h-line");
1039
1062
  // draw.line( d.center.clone().add(d.axis.x-d.center.x,0), d.axis, '#c8c8c8' );
1040
- draw.line(d.center.clone().add(d.signedRadiusH(), 0).rotate(d.rotation, d.center), d.axis, "#c8c8c8");
1063
+ draw.handleLine(d.center.clone().add(d.signedRadiusH(), 0).rotate(d.rotation, d.center), d.axis); // , "#c8c8c8");
1041
1064
  }
1042
1065
  draw.setCurrentId(d.uid);
1043
1066
  draw.setCurrentClassName("" + d.className);
@@ -1124,10 +1147,10 @@ var PlotBoilerplate = /** @class */ (function () {
1124
1147
  else {
1125
1148
  console.error("Cannot draw object. Unknown class.");
1126
1149
  }
1127
- draw.setCurrentClassName(undefined);
1128
- draw.setCurrentId(undefined);
1129
- fill.setCurrentClassName(undefined);
1130
- fill.setCurrentId(undefined);
1150
+ draw.setCurrentClassName(null);
1151
+ draw.setCurrentId(null);
1152
+ fill.setCurrentClassName(null);
1153
+ fill.setCurrentId(null);
1131
1154
  };
1132
1155
  /**
1133
1156
  * Draw the select-polygon (if there is one).
@@ -1217,8 +1240,8 @@ var PlotBoilerplate = /** @class */ (function () {
1217
1240
  this.drawSelectPolygon(draw);
1218
1241
  // Clear IDs and classnames (postDraw hook might draw somthing and the do not want
1219
1242
  // to interfered with that).
1220
- draw.setCurrentId(undefined);
1221
- draw.setCurrentClassName(undefined);
1243
+ draw.setCurrentId(null);
1244
+ draw.setCurrentClassName(null);
1222
1245
  }; // END redraw
1223
1246
  /**
1224
1247
  * This function clears the canvas with the configured background color.<br>
@@ -1355,7 +1378,7 @@ var PlotBoilerplate = /** @class */ (function () {
1355
1378
  }
1356
1379
  else if (_self.config.fitToParent) {
1357
1380
  // Set editor size
1358
- _self.canvas.style.position = "absolute";
1381
+ _self.canvas.style.position = "static";
1359
1382
  var space = this.getAvailableContainerSpace();
1360
1383
  _self.canvas.style.width = ((_c = _self.config.canvasWidthFactor) !== null && _c !== void 0 ? _c : 1.0) * space.width + "px";
1361
1384
  _self.canvas.style.height = ((_d = _self.config.canvasHeightFactor) !== null && _d !== void 0 ? _d : 1.0) * space.height + "px";
@@ -1426,24 +1449,24 @@ var PlotBoilerplate = /** @class */ (function () {
1426
1449
  **/
1427
1450
  PlotBoilerplate.prototype.handleClick = function (e) {
1428
1451
  var _self = this;
1429
- var p = this.locatePointNear(_self.transformMousePosition(e.params.pos.x, e.params.pos.y), PlotBoilerplate.DEFAULT_CLICK_TOLERANCE / Math.min(_self.config.cssScaleX, _self.config.cssScaleY));
1430
- if (p) {
1431
- _self.vertices[p.vindex].listeners.fireClickEvent(e);
1452
+ var point = this.locatePointNear(_self.transformMousePosition(e.params.pos.x, e.params.pos.y), PlotBoilerplate.DEFAULT_CLICK_TOLERANCE / Math.min(_self.config.cssScaleX || 1.0, _self.config.cssScaleY || 1.0));
1453
+ if (point) {
1454
+ _self.vertices[point.vindex].listeners.fireClickEvent(e);
1432
1455
  if (this.keyHandler && this.keyHandler.isDown("shift")) {
1433
- if (p.typeName == "bpath") {
1434
- var vert = _self.paths[p.pindex].bezierCurves[p.cindex].getPointByID(p.pid);
1456
+ if (point.typeName == "bpath") {
1457
+ var vert = _self.paths[point.pindex].bezierCurves[point.cindex].getPointByID(point.pid);
1435
1458
  if (vert.attr.selectable)
1436
1459
  vert.attr.isSelected = !vert.attr.isSelected;
1437
1460
  }
1438
- else if (p.typeName == "vertex") {
1439
- var vert = _self.vertices[p.vindex];
1461
+ else if (point.typeName == "vertex") {
1462
+ var vert = _self.vertices[point.vindex];
1440
1463
  if (vert.attr.selectable)
1441
1464
  vert.attr.isSelected = !vert.attr.isSelected;
1442
1465
  }
1443
1466
  _self.redraw();
1444
1467
  }
1445
- else if (this.keyHandler.isDown("y")) {
1446
- _self.vertices[p.vindex].attr.bezierAutoAdjust = !_self.vertices[p.vindex].attr.bezierAutoAdjust;
1468
+ else if (this.keyHandler && this.keyHandler.isDown("y")) {
1469
+ _self.vertices[point.vindex].attr.bezierAutoAdjust = !_self.vertices[point.vindex].attr.bezierAutoAdjust;
1447
1470
  _self.redraw();
1448
1471
  }
1449
1472
  }
@@ -1510,11 +1533,11 @@ var PlotBoilerplate = /** @class */ (function () {
1510
1533
  var _self = this;
1511
1534
  if (e.button != 0)
1512
1535
  return; // Only react on left mouse or touch events
1513
- var p = _self.locatePointNear(_self.transformMousePosition(e.params.pos.x, e.params.pos.y), PlotBoilerplate.DEFAULT_CLICK_TOLERANCE / Math.min(_self.config.cssScaleX, _self.config.cssScaleY));
1514
- if (!p)
1536
+ var draggablePoint = _self.locatePointNear(_self.transformMousePosition(e.params.pos.x, e.params.pos.y), PlotBoilerplate.DEFAULT_CLICK_TOLERANCE / Math.min(_self.config.cssScaleX, _self.config.cssScaleY));
1537
+ if (!draggablePoint)
1515
1538
  return;
1516
1539
  // Drag all selected elements?
1517
- if (p.typeName == "vertex" && _self.vertices[p.vindex].attr.isSelected) {
1540
+ if (draggablePoint.typeName == "vertex" && _self.vertices[draggablePoint.vindex].attr.isSelected) {
1518
1541
  // Multi drag
1519
1542
  // for( var i in _self.vertices ) {
1520
1543
  for (var i = 0; i < _self.vertices.length; i++) {
@@ -1526,13 +1549,15 @@ var PlotBoilerplate = /** @class */ (function () {
1526
1549
  }
1527
1550
  else {
1528
1551
  // Single drag
1529
- if (!_self.vertices[p.vindex].attr.draggable)
1552
+ if (!_self.vertices[draggablePoint.vindex].attr.draggable)
1530
1553
  return;
1531
- _self.draggedElements.push(p);
1532
- if (p.typeName == "bpath")
1533
- _self.paths[p.pindex].bezierCurves[p.cindex].getPointByID(p.pid).listeners.fireDragStartEvent(e);
1534
- else if (p.typeName == "vertex")
1535
- _self.vertices[p.vindex].listeners.fireDragStartEvent(e);
1554
+ _self.draggedElements.push(draggablePoint);
1555
+ if (draggablePoint.typeName == "bpath")
1556
+ _self.paths[draggablePoint.pindex].bezierCurves[draggablePoint.cindex]
1557
+ .getPointByID(draggablePoint.pid)
1558
+ .listeners.fireDragStartEvent(e);
1559
+ else if (draggablePoint.typeName == "vertex")
1560
+ _self.vertices[draggablePoint.vindex].listeners.fireDragStartEvent(e);
1536
1561
  }
1537
1562
  _self.redraw();
1538
1563
  };
@@ -1559,7 +1584,10 @@ var PlotBoilerplate = /** @class */ (function () {
1559
1584
  // not this one. So this tab will never receive any [Ctrl-down] events
1560
1585
  // until next keypress; the implication is, that [Ctrl] would still
1561
1586
  // considered to be pressed which is not true.
1562
- if (this.keyHandler.isDown("alt") || this.keyHandler.isDown("spacebar")) {
1587
+ if (this.keyHandler && (this.keyHandler.isDown("alt") || this.keyHandler.isDown("spacebar"))) {
1588
+ if (!this.config.enablePan) {
1589
+ return;
1590
+ }
1563
1591
  _self.setOffset(_self.draw.offset.clone().add(e.params.dragAmount));
1564
1592
  _self.redraw();
1565
1593
  }
@@ -1628,6 +1656,9 @@ var PlotBoilerplate = /** @class */ (function () {
1628
1656
  * @return {void}
1629
1657
  **/
1630
1658
  PlotBoilerplate.prototype.mouseWheelHandler = function (e) {
1659
+ if (!this.config.enableZoom) {
1660
+ return;
1661
+ }
1631
1662
  var zoomStep = 1.25; // Make configurable?
1632
1663
  // CHANGED replaced _self by this
1633
1664
  var _self = this;
@@ -1693,6 +1724,7 @@ var PlotBoilerplate = /** @class */ (function () {
1693
1724
  this.setOffset({ x: newOffsetX, y: newOffsetY });
1694
1725
  };
1695
1726
  PlotBoilerplate.prototype.installInputListeners = function () {
1727
+ var _this = this;
1696
1728
  var _self = this;
1697
1729
  if (this.config.enableMouse) {
1698
1730
  // Install a mouse handler on the canvas.
@@ -1767,6 +1799,9 @@ var PlotBoilerplate = /** @class */ (function () {
1767
1799
  if (evt.touches.length == 1 && draggedElement) {
1768
1800
  evt.preventDefault();
1769
1801
  evt.stopPropagation();
1802
+ if (!touchDownPos || !touchMovePos) {
1803
+ return;
1804
+ }
1770
1805
  var rel = relPos_1({ x: evt.touches[0].clientX, y: evt.touches[0].clientY });
1771
1806
  var trans = _self.transformMousePosition(rel.x, rel.y);
1772
1807
  var diff = new Vertex_1.Vertex(_self.transformMousePosition(touchMovePos.x, touchMovePos.y)).difference(trans);
@@ -1791,6 +1826,9 @@ var PlotBoilerplate = /** @class */ (function () {
1791
1826
  touchMovePos = new Vertex_1.Vertex(rel);
1792
1827
  }
1793
1828
  else if (evt.touches.length == 2) {
1829
+ if (!_this.config.enablePan) {
1830
+ return;
1831
+ }
1794
1832
  // If at least two fingers touch and move, then change the draw offset (panning).
1795
1833
  evt.preventDefault();
1796
1834
  evt.stopPropagation();
@@ -1803,6 +1841,9 @@ var PlotBoilerplate = /** @class */ (function () {
1803
1841
  touchEnd: function (evt) {
1804
1842
  // Note: e.touches.length is 0 here
1805
1843
  if (draggedElement && draggedElement.typeName == "vertex") {
1844
+ if (!touchDownPos) {
1845
+ return;
1846
+ }
1806
1847
  var draggingVertex = _self.vertices[draggedElement.vindex];
1807
1848
  var fakeEvent = {
1808
1849
  isTouchEvent: true,
@@ -1835,9 +1876,17 @@ var PlotBoilerplate = /** @class */ (function () {
1835
1876
  multiTouchStartScale = null;
1836
1877
  },
1837
1878
  pinch: function (evt) {
1879
+ if (!_this.config.enableZoom) {
1880
+ return;
1881
+ }
1882
+ var touchItem0 = evt.touches.item(0);
1883
+ var touchItem1 = evt.touches.item(1);
1884
+ if (!evt.touches || !multiTouchStartScale || !touchItem0 || !touchItem1) {
1885
+ return;
1886
+ }
1838
1887
  // For pinching there must be at least two touch items
1839
- var fingerA = new Vertex_1.Vertex(evt.touches.item(0).clientX, evt.touches.item(0).clientY);
1840
- var fingerB = new Vertex_1.Vertex(evt.touches.item(1).clientX, evt.touches.item(1).clientY);
1888
+ var fingerA = new Vertex_1.Vertex(touchItem0.clientX, touchItem0.clientY);
1889
+ var fingerB = new Vertex_1.Vertex(touchItem1.clientX, touchItem1.clientY);
1841
1890
  var center = new Line_1.Line(fingerA, fingerB).vertAt(0.5);
1842
1891
  _self.setZoom(multiTouchStartScale.x * evt.zoom, multiTouchStartScale.y * evt.zoom, center);
1843
1892
  _self.redraw();
@@ -1950,22 +1999,35 @@ var PlotBoilerplate = /** @class */ (function () {
1950
1999
  **/
1951
2000
  safeMergeByKeys: function (base, extension) {
1952
2001
  for (var k in extension) {
1953
- if (!extension.hasOwnProperty(k))
2002
+ if (!extension.hasOwnProperty(k)) {
1954
2003
  continue;
2004
+ }
1955
2005
  if (base.hasOwnProperty(k)) {
1956
2006
  var typ = typeof base[k];
2007
+ var extVal = extension[k];
1957
2008
  try {
1958
- if (typ == "boolean")
1959
- base[k] = !!JSON.parse(extension[k]);
1960
- else if (typ == "number")
1961
- base[k] = JSON.parse(extension[k]) * 1;
1962
- else if (typ == "function" && typeof extension[k] == "function")
2009
+ if (typ == "boolean") {
2010
+ if (typeof extVal === "string")
2011
+ base[k] = Boolean(!!JSON.parse(extVal));
2012
+ else
2013
+ base[k] = extVal;
2014
+ }
2015
+ else if (typ == "number") {
2016
+ if (typeof extVal === "string")
2017
+ base[k] = Number(JSON.parse(extVal) * 1);
2018
+ else
2019
+ base[k] = extension[k];
2020
+ }
2021
+ else if (typ == "function" && typeof extVal == "function") {
1963
2022
  base[k] = extension[k];
1964
- else
2023
+ }
2024
+ else {
2025
+ // Probably a sting
1965
2026
  base[k] = extension[k];
2027
+ }
1966
2028
  }
1967
2029
  catch (e) {
1968
- console.error("error in key ", k, extension[k], e);
2030
+ console.error("error in key ", k, extVal, e);
1969
2031
  }
1970
2032
  }
1971
2033
  else {
@@ -1974,6 +2036,31 @@ var PlotBoilerplate = /** @class */ (function () {
1974
2036
  }
1975
2037
  return base;
1976
2038
  },
2039
+ /*
2040
+ __safeMergeByKeys: <KeyType extends string | number | symbol, ValueType extends boolean | number | string | Function>(
2041
+ base: Record<KeyType, ValueType>,
2042
+ extension: Record<KeyType, string>
2043
+ ): Record<KeyType, ValueType> => {
2044
+ for (var k in extension) {
2045
+ if (!extension.hasOwnProperty(k)) continue;
2046
+ if (base.hasOwnProperty(k)) {
2047
+ var typ = typeof base[k];
2048
+ try {
2049
+ if (typ == "boolean") base[k] = !!JSON.parse(extension[k]);
2050
+ else if (typ == "number") base[k] = JSON.parse(extension[k]) * 1;
2051
+ else if (typ == "function" && typeof extension[k] == "function") base[k] = extension[k];
2052
+ else base[k] = extension[k];
2053
+ } catch (e) {
2054
+ console.error("error in key ", k, extension[k], e);
2055
+ }
2056
+ } else {
2057
+ base[k] = extension[k];
2058
+ }
2059
+ }
2060
+ return base;
2061
+ },
2062
+ *()
2063
+
1977
2064
  /**
1978
2065
  * A helper function to scale elements (usually the canvas) using CSS.
1979
2066
  *
@@ -1986,8 +2073,10 @@ var PlotBoilerplate = /** @class */ (function () {
1986
2073
  **/
1987
2074
  setCSSscale: function (element, scaleX, scaleY) {
1988
2075
  element.style["transform-origin"] = "0 0";
1989
- if (scaleX == 1.0 && scaleY == 1.0)
1990
- element.style.transform = null;
2076
+ if (scaleX == 1.0 && scaleY == 1.0) {
2077
+ // element.style.transform = null;
2078
+ element.style.removeProperty("transform");
2079
+ }
1991
2080
  else
1992
2081
  element.style.transform = "scale(" + scaleX + "," + scaleY + ")";
1993
2082
  },