@inweb/markup 25.8.19 → 25.8.21

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 (48) hide show
  1. package/dist/markup.js +94 -57
  2. package/dist/markup.js.map +1 -1
  3. package/dist/markup.min.js +1 -1
  4. package/dist/markup.module.js +87 -37
  5. package/dist/markup.module.js.map +1 -1
  6. package/lib/index.d.ts +1 -1
  7. package/lib/markup/IMarkup.d.ts +27 -16
  8. package/lib/markup/IMarkupArrow.d.ts +8 -16
  9. package/lib/markup/IMarkupCloud.d.ts +9 -18
  10. package/lib/markup/IMarkupColorable.d.ts +5 -4
  11. package/lib/markup/IMarkupEllipse.d.ts +9 -18
  12. package/lib/markup/IMarkupImage.d.ts +14 -17
  13. package/lib/markup/IMarkupLine.d.ts +44 -11
  14. package/lib/markup/IMarkupObject.d.ts +25 -15
  15. package/lib/markup/IMarkupRectangle.d.ts +9 -18
  16. package/lib/markup/IMarkupText.d.ts +7 -14
  17. package/lib/markup/IWorldTransform.d.ts +1 -1
  18. package/lib/markup/Konva/KonvaArrow.d.ts +2 -2
  19. package/lib/markup/Konva/KonvaCloud.d.ts +1 -1
  20. package/lib/markup/Konva/KonvaEllipse.d.ts +2 -2
  21. package/lib/markup/Konva/KonvaImage.d.ts +4 -2
  22. package/lib/markup/Konva/KonvaLine.d.ts +2 -11
  23. package/lib/markup/Konva/KonvaMarkup.d.ts +2 -2
  24. package/lib/markup/Konva/KonvaRectangle.d.ts +1 -1
  25. package/lib/markup/Konva/KonvaText.d.ts +2 -2
  26. package/lib/markup/Konva/MarkupColor.d.ts +19 -18
  27. package/package.json +3 -3
  28. package/src/index.ts +1 -1
  29. package/src/markup/IMarkup.ts +28 -16
  30. package/src/markup/IMarkupArrow.ts +8 -16
  31. package/src/markup/IMarkupCloud.ts +9 -18
  32. package/src/markup/IMarkupColorable.ts +5 -4
  33. package/src/markup/IMarkupEllipse.ts +9 -18
  34. package/src/markup/IMarkupImage.ts +14 -17
  35. package/src/markup/IMarkupLine.ts +46 -11
  36. package/src/markup/IMarkupObject.ts +25 -15
  37. package/src/markup/IMarkupRectangle.ts +9 -18
  38. package/src/markup/IMarkupText.ts +7 -14
  39. package/src/markup/IWorldTransform.ts +1 -1
  40. package/src/markup/Konva/KonvaArrow.ts +6 -4
  41. package/src/markup/Konva/KonvaCloud.ts +4 -3
  42. package/src/markup/Konva/KonvaEllipse.ts +6 -4
  43. package/src/markup/Konva/KonvaImage.ts +27 -14
  44. package/src/markup/Konva/KonvaLine.ts +9 -13
  45. package/src/markup/Konva/KonvaMarkup.ts +15 -15
  46. package/src/markup/Konva/KonvaRectangle.ts +3 -2
  47. package/src/markup/Konva/KonvaText.ts +6 -4
  48. package/src/markup/Konva/MarkupColor.ts +22 -23
package/dist/markup.js CHANGED
@@ -11478,43 +11478,44 @@
11478
11478
  // acknowledge and accept the above terms.
11479
11479
  ///////////////////////////////////////////////////////////////////////////////
11480
11480
  /**
11481
- * Markup color.
11481
+ * Defines the markup color helper object.
11482
11482
  */
11483
11483
  class MarkupColor {
11484
11484
  /**
11485
- * Color in #000000 format
11485
+ * Creates an instance of the color.
11486
+ *
11487
+ * @param r - The `red` component of the color, as a number between 0 and 255.
11488
+ * @param g - The `green` component of the color, as a number between 0 and 255.
11489
+ * @param b - The `blue` component of the color, as a number between 0 and 255.
11486
11490
  */
11487
- get HexColor() {
11488
- return "#" + this._hex;
11491
+ constructor(r, g, b) {
11492
+ this.setColor(r, g, b);
11489
11493
  }
11490
11494
  /**
11491
- * Color as object with r,g,b properties
11495
+ * Returns the color as a string in hexadecimal color syntax `#RGB` using its primary color
11496
+ * components (red, green, blue) written as hexadecimal numbers.
11492
11497
  */
11493
- get RGB() {
11494
- return { r: this.R, g: this.G, b: this.B };
11498
+ asHex() {
11499
+ return "#" + this.HEX;
11495
11500
  }
11496
11501
  /**
11497
- * Create an instance of Color
11498
- *
11499
- * @param r - Red color in [0,255] range
11500
- * @param g - Green color in [0,255] range
11501
- * @param b - Blue color in [0,255] range
11502
+ * Returns the color as an {r, g, b} object.
11502
11503
  */
11503
- constructor(r, g, b) {
11504
- this.setColor(r, g, b);
11504
+ asRGB() {
11505
+ return { r: this.R, g: this.G, b: this.B };
11505
11506
  }
11506
11507
  /**
11507
- * Set Color for current instance
11508
+ * Sets the color.
11508
11509
  *
11509
- * @param r - Red color in [0,255] range
11510
- * @param g - Green color in [0,255] range
11511
- * @param b - Blue color in [0,255] range
11510
+ * @param r - The `red` component of the color, as a number between 0 and 255.
11511
+ * @param g - The `green` component of the color, as a number between 0 and 255.
11512
+ * @param b - The `blue` component of the color, as a number between 0 and 255.
11512
11513
  */
11513
11514
  setColor(r, g, b) {
11514
11515
  this.R = r;
11515
11516
  this.G = g;
11516
11517
  this.B = b;
11517
- this._hex = this.rgbToHex(r, g, b);
11518
+ this.HEX = this.rgbToHex(r, g, b);
11518
11519
  }
11519
11520
  rgbToHex(r, g, b) {
11520
11521
  const valueToHex = (c) => {
@@ -11571,8 +11572,13 @@
11571
11572
  this._ref = ref;
11572
11573
  return;
11573
11574
  }
11574
- if (!params || !params.points)
11575
- return;
11575
+ if (!params)
11576
+ params = {};
11577
+ if (!params.points)
11578
+ params.points = [
11579
+ { x: 50, y: 50 },
11580
+ { x: 100, y: 100 },
11581
+ ];
11576
11582
  const konvaPoints = [];
11577
11583
  params.points.forEach((point) => konvaPoints.push(point.x, point.y));
11578
11584
  this._ref = new Konva.Line({
@@ -11674,8 +11680,12 @@
11674
11680
  this._ref = ref;
11675
11681
  return;
11676
11682
  }
11677
- if (!params || !params.position || !params.text)
11678
- return;
11683
+ if (!params)
11684
+ params = {};
11685
+ if (!params.position)
11686
+ params.position = { x: 100, y: 100 };
11687
+ if (!params.text)
11688
+ params.text = "default";
11679
11689
  this._ref = new Konva.Text({
11680
11690
  x: params.position.x,
11681
11691
  y: params.position.y,
@@ -11776,8 +11786,10 @@
11776
11786
  this._ref = ref;
11777
11787
  return;
11778
11788
  }
11779
- if (!params || !params.position)
11780
- return;
11789
+ if (!params)
11790
+ params = {};
11791
+ if (!params.position)
11792
+ params.position = { x: 100, y: 100 };
11781
11793
  this._ref = new Konva.Rect({
11782
11794
  stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
11783
11795
  strokeWidth: (_b = params.lineWidth) !== null && _b !== void 0 ? _b : 4,
@@ -11886,8 +11898,12 @@
11886
11898
  this._ref = ref;
11887
11899
  return;
11888
11900
  }
11889
- if (!params || !params.position || !params.radius)
11890
- return;
11901
+ if (!params)
11902
+ params = {};
11903
+ if (!params.position)
11904
+ params.position = { x: 100, y: 100 };
11905
+ if (!params.radius)
11906
+ params.radius = { x: 25, y: 25 };
11891
11907
  this._ref = new Konva.Ellipse({
11892
11908
  stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
11893
11909
  strokeWidth: (_b = params.lineWidth) !== null && _b !== void 0 ? _b : 4,
@@ -12002,8 +12018,12 @@
12002
12018
  this._ref = ref;
12003
12019
  return;
12004
12020
  }
12005
- if (!params || !params.start || !params.end)
12006
- return;
12021
+ if (!params)
12022
+ params = {};
12023
+ if (!params.start)
12024
+ params.start = { x: 50, y: 50 };
12025
+ if (!params.end)
12026
+ params.end = { x: 100, y: 100 };
12007
12027
  this._ref = new Konva.Arrow({
12008
12028
  stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
12009
12029
  fill: (_b = params.color) !== null && _b !== void 0 ? _b : "#ff0000",
@@ -12092,8 +12112,15 @@
12092
12112
  var _a, _b;
12093
12113
  this._ratio = 1;
12094
12114
  this.EPSILON = 10e-6;
12115
+ this.BASE64_NOT_FOUND = "data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAADsAAAA7AF5KHG9AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAmhJREFUWIXtlr9rVEEQxz+H8RQUJIdeIopYm0vkCg0GBBtbG1NF7Kxt7dR/IGIw/uhTaBNLERURg2kCEUyCYCPi70b0InjGS57FzOZN3r19d+9HJIVfWO52dma/s7Mz8xa2KAaBCWAR+AkECWOmSOIdwC1gtQOpHc+NfQ8wClQ8+1d0vcdH/lQ3bSIRGAZ2pTjAqNovANXIWlXlAXA2zvi2Ln4AjqYgtagYEutENSLvjRoOImFv5iB32Ae8UrLXwFBk3h9ndF0VJnKSO9gTu3yKu5Z1LKnS8YIcABgw5Ks692JZFXcXRJ46Aq6kikCnHNi/mQ50WwVtfaIoBzL3gRk2drSscJ2wrc4VvUoe2wn/41/iBfoVLRnBGnDSY3AAKacy8AmYR+o7K1zCl6wgrgpOAc/MuhvfgMuk+1JGHQgSBcAloKXy78AjYBppJk5/noTulseBMZ23iD/piHFkEdgTQzKk+5wHjmHC3cmBg0BD5xcSTrFXyQPgIWFtDwMvab+2N8DpbhyY1v/3E8gdDgNfVX9SCVZ0/gW4B0wB71S2BpxLcuCM/jaQSHSDEeAX4VMuAG4gTzyHbcAVXXO6GxxwIX+vvxe7JHcYQ07nHqklj96UIW/YhSWzMKcep8VVtf8B1Dw6h4DfhB+sdbgn2R+gnoEc5NR3dZ+3QJ9H74HqXLPCGlJyTfI9y3YCs0owq3OLOpKkLeBI1HhSDT/mdKIPiUCARMTlQx34TMLjtww8IczmO8AJ/N/2JNSQXAiQ671JePePge0+wzJSQq4FFzlaenIvucUAkiQLhC/mLGNZ9xgn5s63BP4CCk0QDtm4BhoAAAAASUVORK5CYII=";
12116
+ this.BASE64_HEADER_START = "data:image/";
12095
12117
  if (ref) {
12096
- // if (ref.height() === 0 || ref.width() === 0) return;
12118
+ if (!ref.src || !ref.src.startsWith(this.BASE64_HEADER_START))
12119
+ ref.src = this.BASE64_NOT_FOUND;
12120
+ if (ref.height() <= this.EPSILON)
12121
+ ref.height(32);
12122
+ if (ref.width() <= this.EPSILON)
12123
+ ref.width(32);
12097
12124
  this._ref = ref;
12098
12125
  this._canvasImage = ref.image();
12099
12126
  this._ratio =
@@ -12102,17 +12129,13 @@
12102
12129
  : this._ref.height() / this._ref.width();
12103
12130
  return;
12104
12131
  }
12105
- if (!params || !params.position || !params.src)
12106
- return;
12132
+ if (!params)
12133
+ params = {};
12134
+ if (!params.position)
12135
+ params.position = { x: 50, y: 50 };
12136
+ if (!params.src || !params.src.startsWith(this.BASE64_HEADER_START))
12137
+ params.src = this.BASE64_NOT_FOUND;
12107
12138
  this._canvasImage = new Image();
12108
- this._ref = new Konva.Image({
12109
- x: params.position.x,
12110
- y: params.position.y,
12111
- image: this._canvasImage,
12112
- width: (_a = params.width) !== null && _a !== void 0 ? _a : 0,
12113
- height: (_b = params.height) !== null && _b !== void 0 ? _b : 0,
12114
- draggable: true,
12115
- });
12116
12139
  this._canvasImage.onload = () => {
12117
12140
  this._ref.image(this._canvasImage);
12118
12141
  if (this._ref.height() <= this.EPSILON)
@@ -12140,7 +12163,19 @@
12140
12163
  }
12141
12164
  }
12142
12165
  };
12166
+ this._canvasImage.onerror = () => {
12167
+ this._canvasImage.onerror = function () { };
12168
+ this._canvasImage.src = this.BASE64_NOT_FOUND;
12169
+ };
12143
12170
  this._canvasImage.src = params.src;
12171
+ this._ref = new Konva.Image({
12172
+ x: params.position.x,
12173
+ y: params.position.y,
12174
+ image: this._canvasImage,
12175
+ width: (_a = params.width) !== null && _a !== void 0 ? _a : 0,
12176
+ height: (_b = params.height) !== null && _b !== void 0 ? _b : 0,
12177
+ draggable: true,
12178
+ });
12144
12179
  this._ref.on("transform", (e) => {
12145
12180
  const attrs = e.target.attrs;
12146
12181
  if (attrs.rotation !== this._ref.rotation())
@@ -12238,8 +12273,10 @@
12238
12273
  this._ref = ref;
12239
12274
  return;
12240
12275
  }
12241
- if (!params || !params.position)
12242
- return;
12276
+ if (!params)
12277
+ params = {};
12278
+ if (!params.position)
12279
+ params.position = { x: 100, y: 100 };
12243
12280
  const arcRadius = 16;
12244
12281
  this._ref = new Konva.Shape({
12245
12282
  x: params.position.x,
@@ -12436,7 +12473,7 @@
12436
12473
  */
12437
12474
  class KonvaMarkup {
12438
12475
  constructor() {
12439
- this._pointerEvents = [];
12476
+ this._containerEvents = [];
12440
12477
  this._markupIsActive = false;
12441
12478
  this._markupColor = new MarkupColor(255, 0, 0);
12442
12479
  this.lineWidth = 4;
@@ -12473,13 +12510,13 @@
12473
12510
  this._viewer.emit(event);
12474
12511
  };
12475
12512
  }
12476
- initialize(container, pointerEvents, viewer, worldTransformer) {
12513
+ initialize(container, containerEvents, viewer, worldTransformer) {
12477
12514
  if (!Konva)
12478
12515
  throw new Error('Markup error: Konva is not initialized. Forgot to add <script src="https://unpkg.com/konva@9/konva.min.js"></script> to your page?');
12479
12516
  this._viewer = viewer;
12480
12517
  this._worldTransformer = worldTransformer !== null && worldTransformer !== void 0 ? worldTransformer : new WorldTransform();
12481
12518
  this._container = container;
12482
- this._pointerEvents = pointerEvents !== null && pointerEvents !== void 0 ? pointerEvents : [];
12519
+ this._containerEvents = containerEvents !== null && containerEvents !== void 0 ? containerEvents : [];
12483
12520
  this._markupContainer = document.createElement("div");
12484
12521
  this._markupContainer.id = "markup-container";
12485
12522
  this._markupContainer.style.position = "absolute";
@@ -12494,7 +12531,7 @@
12494
12531
  this._markupColor.setColor(255, 0, 0);
12495
12532
  this.initializeKonva();
12496
12533
  if (this._viewer) {
12497
- this._pointerEvents.forEach((x) => this._markupContainer.addEventListener(x, this.redirectToViewer));
12534
+ this._containerEvents.forEach((x) => this._markupContainer.addEventListener(x, this.redirectToViewer));
12498
12535
  this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
12499
12536
  this._viewer.addEventListener("pan", this.pan);
12500
12537
  }
@@ -12504,7 +12541,7 @@
12504
12541
  if (this._viewer) {
12505
12542
  this._viewer.removeEventListener("pan", this.pan);
12506
12543
  this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
12507
- this._pointerEvents.forEach((x) => this._markupContainer.removeEventListener(x, this.redirectToViewer));
12544
+ this._containerEvents.forEach((x) => this._markupContainer.removeEventListener(x, this.redirectToViewer));
12508
12545
  }
12509
12546
  this.destroyKonva();
12510
12547
  (_a = this._resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
@@ -12524,17 +12561,17 @@
12524
12561
  this.getObjects().forEach((obj) => obj.delete());
12525
12562
  }
12526
12563
  getMarkupColor() {
12527
- return this._markupColor.RGB;
12564
+ return this._markupColor.asRGB();
12528
12565
  }
12529
12566
  setMarkupColor(r, g, b) {
12530
12567
  this._markupColor.setColor(r, g, b);
12531
12568
  }
12532
12569
  colorizeAllMarkup(r, g, b) {
12533
- const hexColor = new MarkupColor(r, g, b).HexColor;
12570
+ const hexColor = new MarkupColor(r, g, b).asHex();
12534
12571
  this.getObjects().filter((obj) => { var _a; return (_a = obj.setColor) === null || _a === void 0 ? void 0 : _a.call(obj, hexColor); });
12535
12572
  }
12536
12573
  colorizeSelectedMarkups(r, g, b) {
12537
- const hexColor = new MarkupColor(r, g, b).HexColor;
12574
+ const hexColor = new MarkupColor(r, g, b).asHex();
12538
12575
  this.getSelectedObjects().filter((obj) => { var _a; return (_a = obj.setColor) === null || _a === void 0 ? void 0 : _a.call(obj, hexColor); });
12539
12576
  }
12540
12577
  setViewpoint(viewpoint) {
@@ -13071,7 +13108,7 @@
13071
13108
  points,
13072
13109
  type: type || this.lineType,
13073
13110
  width: width || this.lineWidth,
13074
- color: color || this._markupColor.HexColor,
13111
+ color: color || this._markupColor.asHex(),
13075
13112
  id,
13076
13113
  });
13077
13114
  this.addObject(konvaLine);
@@ -13088,7 +13125,7 @@
13088
13125
  this._textInputRef.style.top = inputY + "px";
13089
13126
  this._textInputRef.style.left = inputX + "px";
13090
13127
  this._textInputRef.style.fontSize = `${this.fontSize}px`;
13091
- this._textInputRef.style.color = `${this._markupColor.HexColor}`;
13128
+ this._textInputRef.style.color = `${this._markupColor.asHex()}`;
13092
13129
  this._textInputRef.style.fontFamily = "Calibri";
13093
13130
  this._textInputRef.onkeydown = (event) => {
13094
13131
  if (event.key === "Enter" && !event.shiftKey) {
@@ -13180,7 +13217,7 @@
13180
13217
  text,
13181
13218
  rotation: angle,
13182
13219
  fontSize: fontSize || this.fontSize,
13183
- color: color || this._markupColor.HexColor,
13220
+ color: color || this._markupColor.asHex(),
13184
13221
  id,
13185
13222
  });
13186
13223
  this.addObject(konvaText);
@@ -13194,7 +13231,7 @@
13194
13231
  width,
13195
13232
  height,
13196
13233
  lineWidth: lineWidth || this.lineWidth,
13197
- color: color || this._markupColor.HexColor,
13234
+ color: color || this._markupColor.asHex(),
13198
13235
  id,
13199
13236
  });
13200
13237
  this.addObject(konvaRectangle);
@@ -13207,7 +13244,7 @@
13207
13244
  position,
13208
13245
  radius,
13209
13246
  lineWidth,
13210
- color: color || this._markupColor.HexColor,
13247
+ color: color || this._markupColor.asHex(),
13211
13248
  id,
13212
13249
  });
13213
13250
  this.addObject(konvaEllipse);
@@ -13219,7 +13256,7 @@
13219
13256
  const konvaArrow = new KonvaArrow({
13220
13257
  start,
13221
13258
  end,
13222
- color: color || this._markupColor.HexColor,
13259
+ color: color || this._markupColor.asHex(),
13223
13260
  id,
13224
13261
  });
13225
13262
  this.addObject(konvaArrow);
@@ -13232,7 +13269,7 @@
13232
13269
  position,
13233
13270
  width,
13234
13271
  height,
13235
- color: color || this._markupColor.HexColor,
13272
+ color: color || this._markupColor.asHex(),
13236
13273
  lineWidth: lineWidth || this.lineWidth,
13237
13274
  id,
13238
13275
  });