@inweb/markup 25.8.20 → 25.8.22

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 (41) hide show
  1. package/dist/markup.js +35 -34
  2. package/dist/markup.js.map +1 -1
  3. package/dist/markup.min.js +1 -1
  4. package/dist/markup.module.js +22 -22
  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/KonvaLine.d.ts +2 -11
  19. package/lib/markup/Konva/KonvaMarkup.d.ts +2 -2
  20. package/lib/markup/Konva/MarkupColor.d.ts +19 -18
  21. package/package.json +3 -3
  22. package/src/index.ts +1 -1
  23. package/src/markup/IMarkup.ts +28 -16
  24. package/src/markup/IMarkupArrow.ts +8 -16
  25. package/src/markup/IMarkupCloud.ts +9 -18
  26. package/src/markup/IMarkupColorable.ts +5 -4
  27. package/src/markup/IMarkupEllipse.ts +9 -18
  28. package/src/markup/IMarkupImage.ts +14 -17
  29. package/src/markup/IMarkupLine.ts +46 -11
  30. package/src/markup/IMarkupObject.ts +25 -15
  31. package/src/markup/IMarkupRectangle.ts +9 -18
  32. package/src/markup/IMarkupText.ts +7 -14
  33. package/src/markup/IWorldTransform.ts +1 -1
  34. package/src/markup/Konva/KonvaArrow.ts +1 -1
  35. package/src/markup/Konva/KonvaCloud.ts +1 -1
  36. package/src/markup/Konva/KonvaEllipse.ts +1 -1
  37. package/src/markup/Konva/KonvaImage.ts +1 -1
  38. package/src/markup/Konva/KonvaLine.ts +3 -12
  39. package/src/markup/Konva/KonvaMarkup.ts +15 -15
  40. package/src/markup/Konva/KonvaText.ts +1 -1
  41. package/src/markup/Konva/MarkupColor.ts +22 -23
@@ -25,55 +25,46 @@ import { IMarkupObject } from "./IMarkupObject";
25
25
  import { IMarkupColorable } from "./IMarkupColorable";
26
26
 
27
27
  /**
28
- * Rectangle Markup object
28
+ * 2D markup Rectangle object interface.
29
29
  */
30
30
  export interface IMarkupRectangle extends IMarkupObject, IMarkupColorable {
31
31
  /**
32
- * Get position of the Rectangle
32
+ * Returns the coordinates of the top-left point (position) of the rectangle.
33
33
  */
34
34
  getPosition(): { x: number; y: number };
35
35
 
36
36
  /**
37
- * Set position of the Rectangle
38
- *
39
- * @param x - value of X coordinate
40
- * @param y - value of Y coordinate
37
+ * Sets the coordinates of the top-left point (position) of the rectangle.
41
38
  */
42
39
  setPosition(x: number, y: number);
43
40
 
44
41
  /**
45
- * Get width of the Rectangle. Default value is 200
42
+ * Returns the width of the rectangle.
46
43
  */
47
44
  getWidth(): number;
48
45
 
49
46
  /**
50
- * Set width of the Rectangle
51
- *
52
- * @param w - value of width. Default value is 200
47
+ * Sets the width of the rectangle.
53
48
  */
54
49
  setWidth(w: number);
55
50
 
56
51
  /**
57
- * Get height of the Rectangle. Default value is 200
52
+ * Returns the height of the rectangle.
58
53
  */
59
54
  getHeigth(): number;
60
55
 
61
56
  /**
62
- * Set height of the Rectangle
63
- *
64
- * @param h - value of height. Default value is 200
57
+ * Sets the height of the rectangle.
65
58
  */
66
59
  setHeight(h: number);
67
60
 
68
61
  /**
69
- * Get line width of the Rectangle. Defailt value is 4
62
+ * Returns the line width of the rectangle.
70
63
  */
71
64
  getLineWidth(): number;
72
65
 
73
66
  /**
74
- * Set line width of the Rectangle
75
- *
76
- * @param size - value of width. Defailt value is 4
67
+ * Sets the line width of the rectangle.
77
68
  */
78
69
  setLineWidth(size: number);
79
70
  }
@@ -25,43 +25,36 @@ import { IMarkupObject } from "./IMarkupObject";
25
25
  import { IMarkupColorable } from "./IMarkupColorable";
26
26
 
27
27
  /**
28
- * Text Markup object
28
+ * 2D markup Text object interface.
29
29
  */
30
30
  export interface IMarkupText extends IMarkupObject, IMarkupColorable {
31
31
  /**
32
- * Get Text value
32
+ * Returns the text string.
33
33
  */
34
34
  getText(): string;
35
35
 
36
36
  /**
37
- * Set Text value
38
- *
39
- * @param text - string value
37
+ * Sets the text string.
40
38
  */
41
39
  setText(text: string): void;
42
40
 
43
41
  /**
44
- * Get position of the Text
42
+ * Returns the coordinates of the top-left point (position) of the text.
45
43
  */
46
44
  getPosition(): { x: number; y: number };
47
45
 
48
46
  /**
49
- * Set position of the Text
50
- *
51
- * @param x - value of X coordinate
52
- * @param y - value of Y coordinate
47
+ * Sets the coordinates of the top-left point (position) of the text.
53
48
  */
54
49
  setPosition(x: number, y: number);
55
50
 
56
51
  /**
57
- * Get font size. Default value is 34
52
+ * Returns the font size of the text.
58
53
  */
59
54
  getFontSize();
60
55
 
61
56
  /**
62
- * Set font size. Default value is 34
63
- *
64
- * @param size
57
+ * Sets the font size of the text.
65
58
  */
66
59
  setFontSize(size: number);
67
60
  }
@@ -22,7 +22,7 @@
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
24
  /**
25
- * Viewer coordiate system transformer.
25
+ * Viewer coordiate system transformer interface.
26
26
  */
27
27
  export interface IWorldTransform {
28
28
  /**
@@ -74,7 +74,7 @@ export class KonvaArrow implements IMarkupArrow {
74
74
  return this._ref.id();
75
75
  }
76
76
 
77
- enableMouseEditing(value: boolean) {
77
+ enableMouseEditing(value: boolean): void {
78
78
  this._ref.draggable(value);
79
79
  }
80
80
 
@@ -142,7 +142,7 @@ export class KonvaCloud implements IMarkupCloud {
142
142
  return this._ref.id();
143
143
  }
144
144
 
145
- enableMouseEditing(value: boolean) {
145
+ enableMouseEditing(value: boolean): void {
146
146
  this._ref.draggable(value);
147
147
  }
148
148
 
@@ -112,7 +112,7 @@ export class KonvaEllipse implements IMarkupEllipse {
112
112
  return this._ref.id();
113
113
  }
114
114
 
115
- enableMouseEditing(value: boolean) {
115
+ enableMouseEditing(value: boolean): void {
116
116
  this._ref.draggable(value);
117
117
  }
118
118
 
@@ -159,7 +159,7 @@ export class KonvaImage implements IMarkupImage {
159
159
  return this._ref.id();
160
160
  }
161
161
 
162
- enableMouseEditing(value: boolean) {
162
+ enableMouseEditing(value: boolean): void {
163
163
  this._ref.draggable(value);
164
164
  }
165
165
 
@@ -1,5 +1,5 @@
1
1
  import Konva from "konva";
2
- import { IMarkupLine, MarkupLineType } from "../IMarkupLine";
2
+ import { IMarkupLine, IMarkupLineParams, MarkupLineType } from "../IMarkupLine";
3
3
 
4
4
  const LineTypeSpecs = new Map<string, number[]>([
5
5
  ["solid", []],
@@ -10,16 +10,7 @@ const LineTypeSpecs = new Map<string, number[]>([
10
10
  export class KonvaLine implements IMarkupLine {
11
11
  private _ref: Konva.Line;
12
12
 
13
- constructor(
14
- params: {
15
- points?: { x: number; y: number }[];
16
- type?: MarkupLineType;
17
- width?: number;
18
- color?: string;
19
- id?: string;
20
- },
21
- ref = null
22
- ) {
13
+ constructor(params: IMarkupLineParams, ref = null) {
23
14
  if (ref) {
24
15
  this._ref = ref;
25
16
  return;
@@ -64,7 +55,7 @@ export class KonvaLine implements IMarkupLine {
64
55
  return this._ref.id();
65
56
  }
66
57
 
67
- enableMouseEditing(value: boolean) {
58
+ enableMouseEditing(value: boolean): void {
68
59
  this._ref.draggable(value);
69
60
  }
70
61
 
@@ -92,7 +92,7 @@ export class KonvaMarkup implements IMarkup {
92
92
  private _viewer: IEventEmitter;
93
93
  private _worldTransformer: IWorldTransform;
94
94
  private _container: HTMLElement;
95
- private _pointerEvents: string[] = [];
95
+ private _containerEvents: string[] = [];
96
96
  private _markupIsActive = false;
97
97
  private _markupMode: MarkupMode;
98
98
  private _markupColor = new MarkupColor(255, 0, 0);
@@ -117,7 +117,7 @@ export class KonvaMarkup implements IMarkup {
117
117
 
118
118
  initialize(
119
119
  container: HTMLElement,
120
- pointerEvents?: string[],
120
+ containerEvents?: string[],
121
121
  viewer?: IEventEmitter,
122
122
  worldTransformer?: IWorldTransform
123
123
  ): void {
@@ -129,7 +129,7 @@ export class KonvaMarkup implements IMarkup {
129
129
  this._viewer = viewer;
130
130
  this._worldTransformer = worldTransformer ?? new WorldTransform();
131
131
  this._container = container;
132
- this._pointerEvents = pointerEvents ?? [];
132
+ this._containerEvents = containerEvents ?? [];
133
133
 
134
134
  this._markupContainer = document.createElement("div");
135
135
  this._markupContainer.id = "markup-container";
@@ -150,7 +150,7 @@ export class KonvaMarkup implements IMarkup {
150
150
  this.initializeKonva();
151
151
 
152
152
  if (this._viewer) {
153
- this._pointerEvents.forEach((x) => this._markupContainer.addEventListener(x, this.redirectToViewer));
153
+ this._containerEvents.forEach((x) => this._markupContainer.addEventListener(x, this.redirectToViewer));
154
154
  this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
155
155
  this._viewer.addEventListener("pan", this.pan);
156
156
  }
@@ -160,7 +160,7 @@ export class KonvaMarkup implements IMarkup {
160
160
  if (this._viewer) {
161
161
  this._viewer.removeEventListener("pan", this.pan);
162
162
  this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
163
- this._pointerEvents.forEach((x) => this._markupContainer.removeEventListener(x, this.redirectToViewer));
163
+ this._containerEvents.forEach((x) => this._markupContainer.removeEventListener(x, this.redirectToViewer));
164
164
  }
165
165
 
166
166
  this.destroyKonva();
@@ -224,7 +224,7 @@ export class KonvaMarkup implements IMarkup {
224
224
  }
225
225
 
226
226
  getMarkupColor(): { r: number; g: number; b: number } {
227
- return this._markupColor.RGB;
227
+ return this._markupColor.asRGB();
228
228
  }
229
229
 
230
230
  setMarkupColor(r: number, g: number, b: number): void {
@@ -232,12 +232,12 @@ export class KonvaMarkup implements IMarkup {
232
232
  }
233
233
 
234
234
  colorizeAllMarkup(r: number, g: number, b: number): void {
235
- const hexColor = new MarkupColor(r, g, b).HexColor;
235
+ const hexColor = new MarkupColor(r, g, b).asHex();
236
236
  this.getObjects().filter((obj: any) => obj.setColor?.(hexColor));
237
237
  }
238
238
 
239
239
  colorizeSelectedMarkups(r: number, g: number, b: number): void {
240
- const hexColor = new MarkupColor(r, g, b).HexColor;
240
+ const hexColor = new MarkupColor(r, g, b).asHex();
241
241
  this.getSelectedObjects().filter((obj: any) => obj.setColor?.(hexColor));
242
242
  }
243
243
 
@@ -863,7 +863,7 @@ export class KonvaMarkup implements IMarkup {
863
863
  points,
864
864
  type: type || this.lineType,
865
865
  width: width || this.lineWidth,
866
- color: color || this._markupColor.HexColor,
866
+ color: color || this._markupColor.asHex(),
867
867
  id,
868
868
  });
869
869
 
@@ -882,7 +882,7 @@ export class KonvaMarkup implements IMarkup {
882
882
  this._textInputRef.style.top = inputY + "px";
883
883
  this._textInputRef.style.left = inputX + "px";
884
884
  this._textInputRef.style.fontSize = `${this.fontSize}px`;
885
- this._textInputRef.style.color = `${this._markupColor.HexColor}`;
885
+ this._textInputRef.style.color = `${this._markupColor.asHex()}`;
886
886
  this._textInputRef.style.fontFamily = "Calibri";
887
887
 
888
888
  this._textInputRef.onkeydown = (event) => {
@@ -989,7 +989,7 @@ export class KonvaMarkup implements IMarkup {
989
989
  text,
990
990
  rotation: angle,
991
991
  fontSize: fontSize || this.fontSize,
992
- color: color || this._markupColor.HexColor,
992
+ color: color || this._markupColor.asHex(),
993
993
  id,
994
994
  });
995
995
 
@@ -1012,7 +1012,7 @@ export class KonvaMarkup implements IMarkup {
1012
1012
  width,
1013
1013
  height,
1014
1014
  lineWidth: lineWidth || this.lineWidth,
1015
- color: color || this._markupColor.HexColor,
1015
+ color: color || this._markupColor.asHex(),
1016
1016
  id,
1017
1017
  });
1018
1018
 
@@ -1033,7 +1033,7 @@ export class KonvaMarkup implements IMarkup {
1033
1033
  position,
1034
1034
  radius,
1035
1035
  lineWidth,
1036
- color: color || this._markupColor.HexColor,
1036
+ color: color || this._markupColor.asHex(),
1037
1037
  id,
1038
1038
  });
1039
1039
 
@@ -1052,7 +1052,7 @@ export class KonvaMarkup implements IMarkup {
1052
1052
  const konvaArrow = new KonvaArrow({
1053
1053
  start,
1054
1054
  end,
1055
- color: color || this._markupColor.HexColor,
1055
+ color: color || this._markupColor.asHex(),
1056
1056
  id,
1057
1057
  });
1058
1058
 
@@ -1074,7 +1074,7 @@ export class KonvaMarkup implements IMarkup {
1074
1074
  position,
1075
1075
  width,
1076
1076
  height,
1077
- color: color || this._markupColor.HexColor,
1077
+ color: color || this._markupColor.asHex(),
1078
1078
  lineWidth: lineWidth || this.lineWidth,
1079
1079
  id,
1080
1080
  });
@@ -79,7 +79,7 @@ export class KonvaText implements IMarkupText {
79
79
  return this._ref.id();
80
80
  }
81
81
 
82
- enableMouseEditing(value: boolean) {
82
+ enableMouseEditing(value: boolean): void {
83
83
  this._ref.draggable(value);
84
84
  }
85
85
 
@@ -22,57 +22,56 @@
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
24
  /**
25
- * Markup color.
25
+ * Defines the markup color helper object.
26
26
  */
27
27
  export class MarkupColor {
28
28
  public R: number;
29
29
  public G: number;
30
30
  public B: number;
31
-
32
- private _hex: string;
31
+ public HEX: string;
33
32
 
34
33
  /**
35
- * Color in #000000 format
34
+ * Creates an instance of the color.
35
+ *
36
+ * @param r - The `red` component of the color, as a number between 0 and 255.
37
+ * @param g - The `green` component of the color, as a number between 0 and 255.
38
+ * @param b - The `blue` component of the color, as a number between 0 and 255.
36
39
  */
37
- get HexColor(): string {
38
- return "#" + this._hex;
40
+ constructor(r: number, g: number, b: number) {
41
+ this.setColor(r, g, b);
39
42
  }
40
43
 
41
44
  /**
42
- * Color as object with r,g,b properties
45
+ * Returns the color as a string in hexadecimal color syntax `#RGB` using its primary color
46
+ * components (red, green, blue) written as hexadecimal numbers.
43
47
  */
44
- get RGB(): { r: number; g: number; b: number } {
45
- return { r: this.R, g: this.G, b: this.B };
48
+ public asHex(): string {
49
+ return "#" + this.HEX;
46
50
  }
47
51
 
48
52
  /**
49
- * Create an instance of Color
50
- *
51
- * @param r - Red color in [0,255] range
52
- * @param g - Green color in [0,255] range
53
- * @param b - Blue color in [0,255] range
53
+ * Returns the color as an {r, g, b} object.
54
54
  */
55
- constructor(r: number, g: number, b: number) {
56
- this.setColor(r, g, b);
55
+ public asRGB(): { r: number; g: number; b: number } {
56
+ return { r: this.R, g: this.G, b: this.B };
57
57
  }
58
58
 
59
59
  /**
60
- * Set Color for current instance
60
+ * Sets the color.
61
61
  *
62
- * @param r - Red color in [0,255] range
63
- * @param g - Green color in [0,255] range
64
- * @param b - Blue color in [0,255] range
62
+ * @param r - The `red` component of the color, as a number between 0 and 255.
63
+ * @param g - The `green` component of the color, as a number between 0 and 255.
64
+ * @param b - The `blue` component of the color, as a number between 0 and 255.
65
65
  */
66
66
  public setColor(r: number, g: number, b: number): void {
67
67
  this.R = r;
68
68
  this.G = g;
69
69
  this.B = b;
70
-
71
- this._hex = this.rgbToHex(r, g, b);
70
+ this.HEX = this.rgbToHex(r, g, b);
72
71
  }
73
72
 
74
73
  private rgbToHex(r: number, g: number, b: number): string {
75
- const valueToHex = (c) => {
74
+ const valueToHex = (c: number) => {
76
75
  const hex = c.toString(16);
77
76
  return hex === "0" ? "00" : hex;
78
77
  };