@inweb/markup 25.8.20 → 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.
- package/dist/markup.js +35 -34
- package/dist/markup.js.map +1 -1
- package/dist/markup.min.js +1 -1
- package/dist/markup.module.js +22 -22
- package/dist/markup.module.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/markup/IMarkup.d.ts +27 -16
- package/lib/markup/IMarkupArrow.d.ts +8 -16
- package/lib/markup/IMarkupCloud.d.ts +9 -18
- package/lib/markup/IMarkupColorable.d.ts +5 -4
- package/lib/markup/IMarkupEllipse.d.ts +9 -18
- package/lib/markup/IMarkupImage.d.ts +14 -17
- package/lib/markup/IMarkupLine.d.ts +44 -11
- package/lib/markup/IMarkupObject.d.ts +25 -15
- package/lib/markup/IMarkupRectangle.d.ts +9 -18
- package/lib/markup/IMarkupText.d.ts +7 -14
- package/lib/markup/IWorldTransform.d.ts +1 -1
- package/lib/markup/Konva/KonvaLine.d.ts +2 -11
- package/lib/markup/Konva/KonvaMarkup.d.ts +2 -2
- package/lib/markup/Konva/MarkupColor.d.ts +19 -18
- package/package.json +3 -3
- package/src/index.ts +1 -1
- package/src/markup/IMarkup.ts +28 -16
- package/src/markup/IMarkupArrow.ts +8 -16
- package/src/markup/IMarkupCloud.ts +9 -18
- package/src/markup/IMarkupColorable.ts +5 -4
- package/src/markup/IMarkupEllipse.ts +9 -18
- package/src/markup/IMarkupImage.ts +14 -17
- package/src/markup/IMarkupLine.ts +46 -11
- package/src/markup/IMarkupObject.ts +25 -15
- package/src/markup/IMarkupRectangle.ts +9 -18
- package/src/markup/IMarkupText.ts +7 -14
- package/src/markup/IWorldTransform.ts +1 -1
- package/src/markup/Konva/KonvaArrow.ts +1 -1
- package/src/markup/Konva/KonvaCloud.ts +1 -1
- package/src/markup/Konva/KonvaEllipse.ts +1 -1
- package/src/markup/Konva/KonvaImage.ts +1 -1
- package/src/markup/Konva/KonvaLine.ts +3 -12
- package/src/markup/Konva/KonvaMarkup.ts +15 -15
- package/src/markup/Konva/KonvaText.ts +1 -1
- 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
|
|
28
|
+
* 2D markup Rectangle object interface.
|
|
29
29
|
*/
|
|
30
30
|
export interface IMarkupRectangle extends IMarkupObject, IMarkupColorable {
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
42
|
+
* Returns the width of the rectangle.
|
|
46
43
|
*/
|
|
47
44
|
getWidth(): number;
|
|
48
45
|
|
|
49
46
|
/**
|
|
50
|
-
*
|
|
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
|
-
*
|
|
52
|
+
* Returns the height of the rectangle.
|
|
58
53
|
*/
|
|
59
54
|
getHeigth(): number;
|
|
60
55
|
|
|
61
56
|
/**
|
|
62
|
-
*
|
|
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
|
-
*
|
|
62
|
+
* Returns the line width of the rectangle.
|
|
70
63
|
*/
|
|
71
64
|
getLineWidth(): number;
|
|
72
65
|
|
|
73
66
|
/**
|
|
74
|
-
*
|
|
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
|
|
28
|
+
* 2D markup Text object interface.
|
|
29
29
|
*/
|
|
30
30
|
export interface IMarkupText extends IMarkupObject, IMarkupColorable {
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* Returns the text string.
|
|
33
33
|
*/
|
|
34
34
|
getText(): string;
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* @param text - string value
|
|
37
|
+
* Sets the text string.
|
|
40
38
|
*/
|
|
41
39
|
setText(text: string): void;
|
|
42
40
|
|
|
43
41
|
/**
|
|
44
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
52
|
+
* Returns the font size of the text.
|
|
58
53
|
*/
|
|
59
54
|
getFontSize();
|
|
60
55
|
|
|
61
56
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* @param size
|
|
57
|
+
* Sets the font size of the text.
|
|
65
58
|
*/
|
|
66
59
|
setFontSize(size: number);
|
|
67
60
|
}
|
|
@@ -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
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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).
|
|
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).
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
1077
|
+
color: color || this._markupColor.asHex(),
|
|
1078
1078
|
lineWidth: lineWidth || this.lineWidth,
|
|
1079
1079
|
id,
|
|
1080
1080
|
});
|
|
@@ -22,57 +22,56 @@
|
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
38
|
-
|
|
40
|
+
constructor(r: number, g: number, b: number) {
|
|
41
|
+
this.setColor(r, g, b);
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
/**
|
|
42
|
-
*
|
|
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
|
-
|
|
45
|
-
return
|
|
48
|
+
public asHex(): string {
|
|
49
|
+
return "#" + this.HEX;
|
|
46
50
|
}
|
|
47
51
|
|
|
48
52
|
/**
|
|
49
|
-
*
|
|
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
|
-
|
|
56
|
-
this.
|
|
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
|
-
*
|
|
60
|
+
* Sets the color.
|
|
61
61
|
*
|
|
62
|
-
* @param r -
|
|
63
|
-
* @param g -
|
|
64
|
-
* @param b -
|
|
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
|
};
|