@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
@@ -1,24 +1,24 @@
1
1
  import Konva from "konva";
2
2
 
3
3
  class MarkupColor {
4
- get HexColor() {
5
- return "#" + this._hex;
4
+ constructor(r, g, b) {
5
+ this.setColor(r, g, b);
6
+ }
7
+ asHex() {
8
+ return "#" + this.HEX;
6
9
  }
7
- get RGB() {
10
+ asRGB() {
8
11
  return {
9
12
  r: this.R,
10
13
  g: this.G,
11
14
  b: this.B
12
15
  };
13
16
  }
14
- constructor(r, g, b) {
15
- this.setColor(r, g, b);
16
- }
17
17
  setColor(r, g, b) {
18
18
  this.R = r;
19
19
  this.G = g;
20
20
  this.B = b;
21
- this._hex = this.rgbToHex(r, g, b);
21
+ this.HEX = this.rgbToHex(r, g, b);
22
22
  }
23
23
  rgbToHex(r, g, b) {
24
24
  const valueToHex = c => {
@@ -61,7 +61,14 @@ class KonvaLine {
61
61
  this._ref = ref;
62
62
  return;
63
63
  }
64
- if (!params || !params.points) return;
64
+ if (!params) params = {};
65
+ if (!params.points) params.points = [ {
66
+ x: 50,
67
+ y: 50
68
+ }, {
69
+ x: 100,
70
+ y: 100
71
+ } ];
65
72
  const konvaPoints = [];
66
73
  params.points.forEach((point => konvaPoints.push(point.x, point.y)));
67
74
  this._ref = new Konva.Line({
@@ -163,7 +170,12 @@ class KonvaText {
163
170
  this._ref = ref;
164
171
  return;
165
172
  }
166
- if (!params || !params.position || !params.text) return;
173
+ if (!params) params = {};
174
+ if (!params.position) params.position = {
175
+ x: 100,
176
+ y: 100
177
+ };
178
+ if (!params.text) params.text = "default";
167
179
  this._ref = new Konva.Text({
168
180
  x: params.position.x,
169
181
  y: params.position.y,
@@ -265,7 +277,11 @@ class KonvaRectangle {
265
277
  this._ref = ref;
266
278
  return;
267
279
  }
268
- if (!params || !params.position) return;
280
+ if (!params) params = {};
281
+ if (!params.position) params.position = {
282
+ x: 100,
283
+ y: 100
284
+ };
269
285
  this._ref = new Konva.Rect({
270
286
  stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
271
287
  strokeWidth: (_b = params.lineWidth) !== null && _b !== void 0 ? _b : 4,
@@ -375,7 +391,15 @@ class KonvaEllipse {
375
391
  this._ref = ref;
376
392
  return;
377
393
  }
378
- if (!params || !params.position || !params.radius) return;
394
+ if (!params) params = {};
395
+ if (!params.position) params.position = {
396
+ x: 100,
397
+ y: 100
398
+ };
399
+ if (!params.radius) params.radius = {
400
+ x: 25,
401
+ y: 25
402
+ };
379
403
  this._ref = new Konva.Ellipse({
380
404
  stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
381
405
  strokeWidth: (_b = params.lineWidth) !== null && _b !== void 0 ? _b : 4,
@@ -497,7 +521,15 @@ class KonvaArrow {
497
521
  this._ref = ref;
498
522
  return;
499
523
  }
500
- if (!params || !params.start || !params.end) return;
524
+ if (!params) params = {};
525
+ if (!params.start) params.start = {
526
+ x: 50,
527
+ y: 50
528
+ };
529
+ if (!params.end) params.end = {
530
+ x: 100,
531
+ y: 100
532
+ };
501
533
  this._ref = new Konva.Arrow({
502
534
  stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
503
535
  fill: (_b = params.color) !== null && _b !== void 0 ? _b : "#ff0000",
@@ -594,22 +626,24 @@ class KonvaImage {
594
626
  var _a, _b;
595
627
  this._ratio = 1;
596
628
  this.EPSILON = 1e-5;
629
+ 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=";
630
+ this.BASE64_HEADER_START = "data:image/";
597
631
  if (ref) {
632
+ if (!ref.src || !ref.src.startsWith(this.BASE64_HEADER_START)) ref.src = this.BASE64_NOT_FOUND;
633
+ if (ref.height() <= this.EPSILON) ref.height(32);
634
+ if (ref.width() <= this.EPSILON) ref.width(32);
598
635
  this._ref = ref;
599
636
  this._canvasImage = ref.image();
600
637
  this._ratio = this._ref.height() <= this.EPSILON || this._ref.width() <= this.EPSILON ? 1 : this._ref.height() / this._ref.width();
601
638
  return;
602
639
  }
603
- if (!params || !params.position || !params.src) return;
640
+ if (!params) params = {};
641
+ if (!params.position) params.position = {
642
+ x: 50,
643
+ y: 50
644
+ };
645
+ if (!params.src || !params.src.startsWith(this.BASE64_HEADER_START)) params.src = this.BASE64_NOT_FOUND;
604
646
  this._canvasImage = new Image;
605
- this._ref = new Konva.Image({
606
- x: params.position.x,
607
- y: params.position.y,
608
- image: this._canvasImage,
609
- width: (_a = params.width) !== null && _a !== void 0 ? _a : 0,
610
- height: (_b = params.height) !== null && _b !== void 0 ? _b : 0,
611
- draggable: true
612
- });
613
647
  this._canvasImage.onload = () => {
614
648
  this._ref.image(this._canvasImage);
615
649
  if (this._ref.height() <= this.EPSILON) this._ref.height(this._canvasImage.height);
@@ -629,7 +663,19 @@ class KonvaImage {
629
663
  }
630
664
  }
631
665
  };
666
+ this._canvasImage.onerror = () => {
667
+ this._canvasImage.onerror = function() {};
668
+ this._canvasImage.src = this.BASE64_NOT_FOUND;
669
+ };
632
670
  this._canvasImage.src = params.src;
671
+ this._ref = new Konva.Image({
672
+ x: params.position.x,
673
+ y: params.position.y,
674
+ image: this._canvasImage,
675
+ width: (_a = params.width) !== null && _a !== void 0 ? _a : 0,
676
+ height: (_b = params.height) !== null && _b !== void 0 ? _b : 0,
677
+ draggable: true
678
+ });
633
679
  this._ref.on("transform", (e => {
634
680
  const attrs = e.target.attrs;
635
681
  if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
@@ -728,7 +774,11 @@ class KonvaCloud {
728
774
  this._ref = ref;
729
775
  return;
730
776
  }
731
- if (!params || !params.position) return;
777
+ if (!params) params = {};
778
+ if (!params.position) params.position = {
779
+ x: 100,
780
+ y: 100
781
+ };
732
782
  const arcRadius = 16;
733
783
  this._ref = new Konva.Shape({
734
784
  x: params.position.x,
@@ -933,7 +983,7 @@ const MarkupMode2Konva = {
933
983
 
934
984
  class KonvaMarkup {
935
985
  constructor() {
936
- this._pointerEvents = [];
986
+ this._containerEvents = [];
937
987
  this._markupIsActive = false;
938
988
  this._markupColor = new MarkupColor(255, 0, 0);
939
989
  this.lineWidth = 4;
@@ -965,12 +1015,12 @@ class KonvaMarkup {
965
1015
  if (this._viewer) this._viewer.emit(event);
966
1016
  };
967
1017
  }
968
- initialize(container, pointerEvents, viewer, worldTransformer) {
1018
+ initialize(container, containerEvents, viewer, worldTransformer) {
969
1019
  if (!Konva) 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?');
970
1020
  this._viewer = viewer;
971
1021
  this._worldTransformer = worldTransformer !== null && worldTransformer !== void 0 ? worldTransformer : new WorldTransform;
972
1022
  this._container = container;
973
- this._pointerEvents = pointerEvents !== null && pointerEvents !== void 0 ? pointerEvents : [];
1023
+ this._containerEvents = containerEvents !== null && containerEvents !== void 0 ? containerEvents : [];
974
1024
  this._markupContainer = document.createElement("div");
975
1025
  this._markupContainer.id = "markup-container";
976
1026
  this._markupContainer.style.position = "absolute";
@@ -984,7 +1034,7 @@ class KonvaMarkup {
984
1034
  this._markupColor.setColor(255, 0, 0);
985
1035
  this.initializeKonva();
986
1036
  if (this._viewer) {
987
- this._pointerEvents.forEach((x => this._markupContainer.addEventListener(x, this.redirectToViewer)));
1037
+ this._containerEvents.forEach((x => this._markupContainer.addEventListener(x, this.redirectToViewer)));
988
1038
  this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
989
1039
  this._viewer.addEventListener("pan", this.pan);
990
1040
  }
@@ -994,7 +1044,7 @@ class KonvaMarkup {
994
1044
  if (this._viewer) {
995
1045
  this._viewer.removeEventListener("pan", this.pan);
996
1046
  this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
997
- this._pointerEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
1047
+ this._containerEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
998
1048
  }
999
1049
  this.destroyKonva();
1000
1050
  (_a = this._resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
@@ -1014,20 +1064,20 @@ class KonvaMarkup {
1014
1064
  this.getObjects().forEach((obj => obj.delete()));
1015
1065
  }
1016
1066
  getMarkupColor() {
1017
- return this._markupColor.RGB;
1067
+ return this._markupColor.asRGB();
1018
1068
  }
1019
1069
  setMarkupColor(r, g, b) {
1020
1070
  this._markupColor.setColor(r, g, b);
1021
1071
  }
1022
1072
  colorizeAllMarkup(r, g, b) {
1023
- const hexColor = new MarkupColor(r, g, b).HexColor;
1073
+ const hexColor = new MarkupColor(r, g, b).asHex();
1024
1074
  this.getObjects().filter((obj => {
1025
1075
  var _a;
1026
1076
  return (_a = obj.setColor) === null || _a === void 0 ? void 0 : _a.call(obj, hexColor);
1027
1077
  }));
1028
1078
  }
1029
1079
  colorizeSelectedMarkups(r, g, b) {
1030
- const hexColor = new MarkupColor(r, g, b).HexColor;
1080
+ const hexColor = new MarkupColor(r, g, b).asHex();
1031
1081
  this.getSelectedObjects().filter((obj => {
1032
1082
  var _a;
1033
1083
  return (_a = obj.setColor) === null || _a === void 0 ? void 0 : _a.call(obj, hexColor);
@@ -1551,7 +1601,7 @@ class KonvaMarkup {
1551
1601
  points: points,
1552
1602
  type: type || this.lineType,
1553
1603
  width: width || this.lineWidth,
1554
- color: color || this._markupColor.HexColor,
1604
+ color: color || this._markupColor.asHex(),
1555
1605
  id: id
1556
1606
  });
1557
1607
  this.addObject(konvaLine);
@@ -1568,7 +1618,7 @@ class KonvaMarkup {
1568
1618
  this._textInputRef.style.top = inputY + "px";
1569
1619
  this._textInputRef.style.left = inputX + "px";
1570
1620
  this._textInputRef.style.fontSize = `${this.fontSize}px`;
1571
- this._textInputRef.style.color = `${this._markupColor.HexColor}`;
1621
+ this._textInputRef.style.color = `${this._markupColor.asHex()}`;
1572
1622
  this._textInputRef.style.fontFamily = "Calibri";
1573
1623
  this._textInputRef.onkeydown = event => {
1574
1624
  if (event.key === "Enter" && !event.shiftKey) {
@@ -1658,7 +1708,7 @@ class KonvaMarkup {
1658
1708
  text: text,
1659
1709
  rotation: angle,
1660
1710
  fontSize: fontSize || this.fontSize,
1661
- color: color || this._markupColor.HexColor,
1711
+ color: color || this._markupColor.asHex(),
1662
1712
  id: id
1663
1713
  });
1664
1714
  this.addObject(konvaText);
@@ -1671,7 +1721,7 @@ class KonvaMarkup {
1671
1721
  width: width,
1672
1722
  height: height,
1673
1723
  lineWidth: lineWidth || this.lineWidth,
1674
- color: color || this._markupColor.HexColor,
1724
+ color: color || this._markupColor.asHex(),
1675
1725
  id: id
1676
1726
  });
1677
1727
  this.addObject(konvaRectangle);
@@ -1683,7 +1733,7 @@ class KonvaMarkup {
1683
1733
  position: position,
1684
1734
  radius: radius,
1685
1735
  lineWidth: lineWidth,
1686
- color: color || this._markupColor.HexColor,
1736
+ color: color || this._markupColor.asHex(),
1687
1737
  id: id
1688
1738
  });
1689
1739
  this.addObject(konvaEllipse);
@@ -1694,7 +1744,7 @@ class KonvaMarkup {
1694
1744
  const konvaArrow = new KonvaArrow({
1695
1745
  start: start,
1696
1746
  end: end,
1697
- color: color || this._markupColor.HexColor,
1747
+ color: color || this._markupColor.asHex(),
1698
1748
  id: id
1699
1749
  });
1700
1750
  this.addObject(konvaArrow);
@@ -1706,7 +1756,7 @@ class KonvaMarkup {
1706
1756
  position: position,
1707
1757
  width: width,
1708
1758
  height: height,
1709
- color: color || this._markupColor.HexColor,
1759
+ color: color || this._markupColor.asHex(),
1710
1760
  lineWidth: lineWidth || this.lineWidth,
1711
1761
  id: id
1712
1762
  });