@inweb/markup 25.7.4
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/LICENSE +20 -0
- package/README.md +7 -0
- package/dist/markup.js +13390 -0
- package/dist/markup.js.map +1 -0
- package/dist/markup.min.js +1 -0
- package/dist/markup.module.js +1838 -0
- package/dist/markup.module.js.map +1 -0
- package/lib/index.d.ts +12 -0
- package/lib/markup/IMarkup.d.ts +130 -0
- package/lib/markup/IMarkupArrow.d.ts +52 -0
- package/lib/markup/IMarkupCloud.d.ts +50 -0
- package/lib/markup/IMarkupColorable.d.ts +15 -0
- package/lib/markup/IMarkupEllipse.d.ts +50 -0
- package/lib/markup/IMarkupImage.d.ts +50 -0
- package/lib/markup/IMarkupLine.d.ts +43 -0
- package/lib/markup/IMarkupObject.d.ts +47 -0
- package/lib/markup/IMarkupRectangle.d.ts +50 -0
- package/lib/markup/IMarkupText.d.ts +40 -0
- package/lib/markup/IWorldTransform.d.ts +39 -0
- package/lib/markup/Konva/KonvaArrow.d.ts +46 -0
- package/lib/markup/Konva/KonvaCloud.d.ts +35 -0
- package/lib/markup/Konva/KonvaEllipse.d.ts +40 -0
- package/lib/markup/Konva/KonvaImage.d.ts +36 -0
- package/lib/markup/Konva/KonvaLine.d.ts +35 -0
- package/lib/markup/Konva/KonvaMarkup.d.ts +82 -0
- package/lib/markup/Konva/KonvaRectangle.d.ts +38 -0
- package/lib/markup/Konva/KonvaText.d.ts +37 -0
- package/lib/markup/Konva/MarkupColor.d.ts +38 -0
- package/package.json +40 -0
- package/src/index.ts +35 -0
- package/src/markup/IMarkup.ts +173 -0
- package/src/markup/IMarkupArrow.ts +69 -0
- package/src/markup/IMarkupCloud.ts +78 -0
- package/src/markup/IMarkupColorable.ts +39 -0
- package/src/markup/IMarkupEllipse.ts +78 -0
- package/src/markup/IMarkupImage.ts +78 -0
- package/src/markup/IMarkupLine.ts +70 -0
- package/src/markup/IMarkupObject.ts +78 -0
- package/src/markup/IMarkupRectangle.ts +78 -0
- package/src/markup/IMarkupText.ts +66 -0
- package/src/markup/IWorldTransform.ts +46 -0
- package/src/markup/Konva/KonvaArrow.ts +147 -0
- package/src/markup/Konva/KonvaCloud.ts +213 -0
- package/src/markup/Konva/KonvaEllipse.ts +150 -0
- package/src/markup/Konva/KonvaImage.ts +149 -0
- package/src/markup/Konva/KonvaLine.ts +136 -0
- package/src/markup/Konva/KonvaMarkup.ts +1264 -0
- package/src/markup/Konva/KonvaRectangle.ts +149 -0
- package/src/markup/Konva/KonvaText.ts +141 -0
- package/src/markup/Konva/MarkupColor.ts +82 -0
|
@@ -0,0 +1,1838 @@
|
|
|
1
|
+
import Konva from "konva";
|
|
2
|
+
|
|
3
|
+
var MarkupMode;
|
|
4
|
+
|
|
5
|
+
(function(MarkupMode) {
|
|
6
|
+
MarkupMode["SelectMarkup"] = "SelectMarkup";
|
|
7
|
+
MarkupMode["Line"] = "Line";
|
|
8
|
+
MarkupMode["Text"] = "Text";
|
|
9
|
+
MarkupMode["Rectangle"] = "Rectangle";
|
|
10
|
+
MarkupMode["Ellipse"] = "Ellipse";
|
|
11
|
+
MarkupMode["Arrow"] = "Arrow";
|
|
12
|
+
MarkupMode["Image"] = "Image";
|
|
13
|
+
MarkupMode["Cloud"] = "Cloud";
|
|
14
|
+
})(MarkupMode || (MarkupMode = {}));
|
|
15
|
+
|
|
16
|
+
class MarkupColor {
|
|
17
|
+
get HexColor() {
|
|
18
|
+
return "#" + this._hex;
|
|
19
|
+
}
|
|
20
|
+
get RGB() {
|
|
21
|
+
return {
|
|
22
|
+
r: this.R,
|
|
23
|
+
g: this.G,
|
|
24
|
+
b: this.B
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
constructor(r, g, b) {
|
|
28
|
+
this.setColor(r, g, b);
|
|
29
|
+
}
|
|
30
|
+
setColor(r, g, b) {
|
|
31
|
+
this.R = r;
|
|
32
|
+
this.G = g;
|
|
33
|
+
this.B = b;
|
|
34
|
+
this._hex = this.rgbToHex(r, g, b);
|
|
35
|
+
}
|
|
36
|
+
rgbToHex(r, g, b) {
|
|
37
|
+
const valueToHex = c => {
|
|
38
|
+
const hex = c.toString(16);
|
|
39
|
+
return hex === "0" ? "00" : hex;
|
|
40
|
+
};
|
|
41
|
+
return valueToHex(r) + valueToHex(g) + valueToHex(b);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const LineTypeSpecs = new Map([ [ "solid", [] ], [ "dot", [ 30, 30, .001, 30 ] ], [ "dash", [ 30, 30 ] ] ]);
|
|
46
|
+
|
|
47
|
+
class KonvaLine {
|
|
48
|
+
constructor(params, ref = null) {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
if (ref) {
|
|
51
|
+
this._ref = ref;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (!params.points) return;
|
|
55
|
+
const konvaPoints = [];
|
|
56
|
+
params.points.forEach((point => konvaPoints.push(point.x, point.y)));
|
|
57
|
+
this._ref = new Konva.Line({
|
|
58
|
+
stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
|
|
59
|
+
strokeWidth: (_b = params.width) !== null && _b !== void 0 ? _b : 4,
|
|
60
|
+
globalCompositeOperation: "source-over",
|
|
61
|
+
lineCap: "round",
|
|
62
|
+
lineJoin: "round",
|
|
63
|
+
points: konvaPoints,
|
|
64
|
+
draggable: true,
|
|
65
|
+
strokeScaleEnabled: false,
|
|
66
|
+
dash: LineTypeSpecs.get(params.type) || []
|
|
67
|
+
});
|
|
68
|
+
this._ref.on("transform", (e => {
|
|
69
|
+
const attrs = e.target.attrs;
|
|
70
|
+
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
71
|
+
}));
|
|
72
|
+
this._ref.id(this._ref._id.toString());
|
|
73
|
+
}
|
|
74
|
+
ref() {
|
|
75
|
+
return this._ref;
|
|
76
|
+
}
|
|
77
|
+
id() {
|
|
78
|
+
return this._ref.id();
|
|
79
|
+
}
|
|
80
|
+
enableMouseEditing(value) {
|
|
81
|
+
this._ref.draggable(value);
|
|
82
|
+
}
|
|
83
|
+
type() {
|
|
84
|
+
return "line";
|
|
85
|
+
}
|
|
86
|
+
getColor() {
|
|
87
|
+
return this._ref.stroke();
|
|
88
|
+
}
|
|
89
|
+
setColor(hex) {
|
|
90
|
+
this._ref.stroke(hex);
|
|
91
|
+
}
|
|
92
|
+
getRotation() {
|
|
93
|
+
return this._ref.rotation();
|
|
94
|
+
}
|
|
95
|
+
setRotation(degrees) {
|
|
96
|
+
this._ref.rotation(degrees);
|
|
97
|
+
}
|
|
98
|
+
getZIndex() {
|
|
99
|
+
return this._ref.zIndex();
|
|
100
|
+
}
|
|
101
|
+
setZIndex(zIndex) {
|
|
102
|
+
this._ref.zIndex(zIndex);
|
|
103
|
+
}
|
|
104
|
+
delete() {
|
|
105
|
+
this._ref.destroy();
|
|
106
|
+
this._ref = null;
|
|
107
|
+
}
|
|
108
|
+
getPoints() {
|
|
109
|
+
return this._ref.points();
|
|
110
|
+
}
|
|
111
|
+
setLineWidth(size) {
|
|
112
|
+
this._ref.strokeWidth(size);
|
|
113
|
+
}
|
|
114
|
+
getLineWidth() {
|
|
115
|
+
return this._ref.strokeWidth();
|
|
116
|
+
}
|
|
117
|
+
getLineType() {
|
|
118
|
+
const typeSpecs = this._ref.dash() || [];
|
|
119
|
+
let type;
|
|
120
|
+
switch (typeSpecs) {
|
|
121
|
+
case LineTypeSpecs.get("dot"):
|
|
122
|
+
type = "dot";
|
|
123
|
+
break;
|
|
124
|
+
|
|
125
|
+
case LineTypeSpecs.get("dash"):
|
|
126
|
+
type = "dash";
|
|
127
|
+
break;
|
|
128
|
+
|
|
129
|
+
default:
|
|
130
|
+
type = "solid";
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
return type;
|
|
134
|
+
}
|
|
135
|
+
setLineType(type) {
|
|
136
|
+
const specs = LineTypeSpecs.get(type);
|
|
137
|
+
if (specs) this._ref.dash(specs);
|
|
138
|
+
}
|
|
139
|
+
addPoints(points) {
|
|
140
|
+
let newPoints = this._ref.points();
|
|
141
|
+
points.forEach((point => {
|
|
142
|
+
newPoints = newPoints.concat([ point.x, point.y ]);
|
|
143
|
+
}));
|
|
144
|
+
this._ref.points(newPoints);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
class KonvaText {
|
|
149
|
+
constructor(params, ref = null) {
|
|
150
|
+
var _a, _b, _c;
|
|
151
|
+
this.TEXT_FONT_FAMILY = "Calibri";
|
|
152
|
+
if (ref) {
|
|
153
|
+
this._ref = ref;
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (!params || !params.text) return;
|
|
157
|
+
this._ref = new Konva.Text({
|
|
158
|
+
x: params.position.x,
|
|
159
|
+
y: params.position.y,
|
|
160
|
+
text: params.text,
|
|
161
|
+
fontSize: (_a = params.fontSize) !== null && _a !== void 0 ? _a : 34,
|
|
162
|
+
fontFamily: this.TEXT_FONT_FAMILY,
|
|
163
|
+
fill: (_b = params.color) !== null && _b !== void 0 ? _b : "#ff0000",
|
|
164
|
+
align: "left",
|
|
165
|
+
draggable: true,
|
|
166
|
+
rotation: (_c = params.rotation) !== null && _c !== void 0 ? _c : 0
|
|
167
|
+
});
|
|
168
|
+
this._ref.width(this._ref.getTextWidth());
|
|
169
|
+
this._ref.on("transform", (e => {
|
|
170
|
+
const attrs = e.target.attrs;
|
|
171
|
+
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
172
|
+
const scaleByX = Math.abs(attrs.scaleX - 1) > 1e-5;
|
|
173
|
+
const scaleByY = Math.abs(attrs.scaleY - 1) > 1e-5;
|
|
174
|
+
let newWidth = this._ref.width();
|
|
175
|
+
if (scaleByX) newWidth *= attrs.scaleX;
|
|
176
|
+
let newHeight = this._ref.height();
|
|
177
|
+
if (scaleByY) newHeight *= attrs.scaleY;
|
|
178
|
+
const minWidth = 50;
|
|
179
|
+
if (newWidth < minWidth) newWidth = minWidth;
|
|
180
|
+
if (newHeight < Math.round(this.getFontSize())) newHeight = Math.round(this.getFontSize());
|
|
181
|
+
if (scaleByX) {
|
|
182
|
+
this._ref.width(newWidth);
|
|
183
|
+
}
|
|
184
|
+
if (scaleByY) {
|
|
185
|
+
this._ref.height(newHeight);
|
|
186
|
+
}
|
|
187
|
+
this._ref.scale({
|
|
188
|
+
x: 1,
|
|
189
|
+
y: 1
|
|
190
|
+
});
|
|
191
|
+
}));
|
|
192
|
+
this._ref.id(this._ref._id.toString());
|
|
193
|
+
}
|
|
194
|
+
ref() {
|
|
195
|
+
return this._ref;
|
|
196
|
+
}
|
|
197
|
+
id() {
|
|
198
|
+
return this._ref.id();
|
|
199
|
+
}
|
|
200
|
+
enableMouseEditing(value) {
|
|
201
|
+
this._ref.draggable(value);
|
|
202
|
+
}
|
|
203
|
+
type() {
|
|
204
|
+
return "text";
|
|
205
|
+
}
|
|
206
|
+
getColor() {
|
|
207
|
+
return this._ref.fill();
|
|
208
|
+
}
|
|
209
|
+
setColor(hex) {
|
|
210
|
+
this._ref.fill(hex);
|
|
211
|
+
}
|
|
212
|
+
getRotation() {
|
|
213
|
+
return this._ref.rotation();
|
|
214
|
+
}
|
|
215
|
+
setRotation(degrees) {
|
|
216
|
+
this._ref.rotation(degrees);
|
|
217
|
+
}
|
|
218
|
+
getZIndex() {
|
|
219
|
+
return this._ref.zIndex();
|
|
220
|
+
}
|
|
221
|
+
setZIndex(zIndex) {
|
|
222
|
+
this._ref.zIndex(zIndex);
|
|
223
|
+
}
|
|
224
|
+
delete() {
|
|
225
|
+
this._ref.destroy();
|
|
226
|
+
this._ref = null;
|
|
227
|
+
}
|
|
228
|
+
getText() {
|
|
229
|
+
return this._ref.text();
|
|
230
|
+
}
|
|
231
|
+
setText(text) {
|
|
232
|
+
this._ref.text(text);
|
|
233
|
+
}
|
|
234
|
+
getPosition() {
|
|
235
|
+
return this._ref.getPosition();
|
|
236
|
+
}
|
|
237
|
+
setPosition(x, y) {
|
|
238
|
+
this._ref.setPosition({
|
|
239
|
+
x: x,
|
|
240
|
+
y: y
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
getFontSize() {
|
|
244
|
+
return this._ref.fontSize();
|
|
245
|
+
}
|
|
246
|
+
setFontSize(size) {
|
|
247
|
+
this._ref.fontSize(size);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
class KonvaRectangle {
|
|
252
|
+
constructor(params, ref = null) {
|
|
253
|
+
var _a, _b, _c, _d;
|
|
254
|
+
if (ref) {
|
|
255
|
+
this._ref = ref;
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (!params.position) return;
|
|
259
|
+
this._ref = new Konva.Rect({
|
|
260
|
+
stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
|
|
261
|
+
strokeWidth: (_b = params.lineWidth) !== null && _b !== void 0 ? _b : 4,
|
|
262
|
+
globalCompositeOperation: "source-over",
|
|
263
|
+
lineCap: "round",
|
|
264
|
+
lineJoin: "round",
|
|
265
|
+
x: params.position.x,
|
|
266
|
+
y: params.position.y,
|
|
267
|
+
width: (_c = params.width) !== null && _c !== void 0 ? _c : 200,
|
|
268
|
+
height: (_d = params.height) !== null && _d !== void 0 ? _d : 200,
|
|
269
|
+
draggable: true,
|
|
270
|
+
strokeScaleEnabled: false
|
|
271
|
+
});
|
|
272
|
+
this._ref.on("transform", (e => {
|
|
273
|
+
const attrs = e.target.attrs;
|
|
274
|
+
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
275
|
+
const scaleByX = Math.abs(attrs.scaleX - 1) > 1e-5;
|
|
276
|
+
const scaleByY = Math.abs(attrs.scaleY - 1) > 1e-5;
|
|
277
|
+
let newWidth = this._ref.width();
|
|
278
|
+
if (scaleByX) newWidth *= attrs.scaleX;
|
|
279
|
+
let newHeight = this._ref.height();
|
|
280
|
+
if (scaleByY) newHeight *= attrs.scaleY;
|
|
281
|
+
const minWidth = 50;
|
|
282
|
+
const minHeight = 50;
|
|
283
|
+
if (newWidth < minWidth) newWidth = minWidth;
|
|
284
|
+
if (newHeight < minHeight) newHeight = minHeight;
|
|
285
|
+
if (scaleByX) {
|
|
286
|
+
this._ref.width(newWidth);
|
|
287
|
+
}
|
|
288
|
+
if (scaleByY) {
|
|
289
|
+
this._ref.height(newHeight);
|
|
290
|
+
}
|
|
291
|
+
this._ref.scale({
|
|
292
|
+
x: 1,
|
|
293
|
+
y: 1
|
|
294
|
+
});
|
|
295
|
+
}));
|
|
296
|
+
this._ref.id(this._ref._id.toString());
|
|
297
|
+
}
|
|
298
|
+
getPosition() {
|
|
299
|
+
return this._ref.position();
|
|
300
|
+
}
|
|
301
|
+
getWidth() {
|
|
302
|
+
return this._ref.width();
|
|
303
|
+
}
|
|
304
|
+
getHeigth() {
|
|
305
|
+
return this._ref.height();
|
|
306
|
+
}
|
|
307
|
+
setWidth(w) {
|
|
308
|
+
this._ref.width(w);
|
|
309
|
+
}
|
|
310
|
+
setHeight(h) {
|
|
311
|
+
this._ref.height(h);
|
|
312
|
+
}
|
|
313
|
+
setPosition(x, y) {
|
|
314
|
+
this._ref.setPosition({
|
|
315
|
+
x: x,
|
|
316
|
+
y: y
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
ref() {
|
|
320
|
+
return this._ref;
|
|
321
|
+
}
|
|
322
|
+
id() {
|
|
323
|
+
return this._ref.id();
|
|
324
|
+
}
|
|
325
|
+
enableMouseEditing(value) {
|
|
326
|
+
this._ref.draggable(value);
|
|
327
|
+
}
|
|
328
|
+
type() {
|
|
329
|
+
return "rectangle";
|
|
330
|
+
}
|
|
331
|
+
getColor() {
|
|
332
|
+
return this._ref.stroke();
|
|
333
|
+
}
|
|
334
|
+
setColor(hex) {
|
|
335
|
+
this._ref.stroke(hex);
|
|
336
|
+
}
|
|
337
|
+
getRotation() {
|
|
338
|
+
return this._ref.rotation();
|
|
339
|
+
}
|
|
340
|
+
setRotation(degrees) {
|
|
341
|
+
this._ref.rotation(degrees);
|
|
342
|
+
}
|
|
343
|
+
getZIndex() {
|
|
344
|
+
return this._ref.zIndex();
|
|
345
|
+
}
|
|
346
|
+
setZIndex(zIndex) {
|
|
347
|
+
this._ref.zIndex(zIndex);
|
|
348
|
+
}
|
|
349
|
+
delete() {
|
|
350
|
+
this._ref.destroy();
|
|
351
|
+
this._ref = null;
|
|
352
|
+
}
|
|
353
|
+
setLineWidth(size) {
|
|
354
|
+
this._ref.strokeWidth(size);
|
|
355
|
+
}
|
|
356
|
+
getLineWidth() {
|
|
357
|
+
return this._ref.strokeWidth();
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
class KonvaEllipse {
|
|
362
|
+
constructor(params, ref = null) {
|
|
363
|
+
var _a, _b;
|
|
364
|
+
if (ref) {
|
|
365
|
+
this._ref = ref;
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
if (!params.position) return;
|
|
369
|
+
this._ref = new Konva.Ellipse({
|
|
370
|
+
stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
|
|
371
|
+
strokeWidth: (_b = params.lineWidth) !== null && _b !== void 0 ? _b : 4,
|
|
372
|
+
globalCompositeOperation: "source-over",
|
|
373
|
+
lineCap: "round",
|
|
374
|
+
lineJoin: "round",
|
|
375
|
+
x: params.position.x,
|
|
376
|
+
y: params.position.y,
|
|
377
|
+
radiusX: params.radius.x,
|
|
378
|
+
radiusY: params.radius.y,
|
|
379
|
+
draggable: true,
|
|
380
|
+
strokeScaleEnabled: false
|
|
381
|
+
});
|
|
382
|
+
this._ref.on("transform", (e => {
|
|
383
|
+
const attrs = e.target.attrs;
|
|
384
|
+
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
385
|
+
const scaleByX = Math.abs(attrs.scaleX - 1) > 1e-5;
|
|
386
|
+
const scaleByY = Math.abs(attrs.scaleY - 1) > 1e-5;
|
|
387
|
+
let newRadiusX = this._ref.radiusX();
|
|
388
|
+
if (scaleByX) newRadiusX *= attrs.scaleX;
|
|
389
|
+
let newRadiusY = this._ref.radiusY();
|
|
390
|
+
if (scaleByY) newRadiusY *= attrs.scaleY;
|
|
391
|
+
const minRadiusX = 25;
|
|
392
|
+
const minRadiusY = 25;
|
|
393
|
+
if (newRadiusX < minRadiusX) newRadiusX = minRadiusX;
|
|
394
|
+
if (newRadiusY < minRadiusY) newRadiusY = minRadiusY;
|
|
395
|
+
if (e.evt.ctrlKey || e.evt.shiftKey) {
|
|
396
|
+
if (scaleByX) {
|
|
397
|
+
this._ref.radius({
|
|
398
|
+
x: newRadiusX,
|
|
399
|
+
y: newRadiusX
|
|
400
|
+
});
|
|
401
|
+
} else {
|
|
402
|
+
this._ref.radius({
|
|
403
|
+
x: newRadiusY,
|
|
404
|
+
y: newRadiusY
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
} else {
|
|
408
|
+
this._ref.radius({
|
|
409
|
+
x: newRadiusX,
|
|
410
|
+
y: newRadiusY
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
this._ref.scale({
|
|
414
|
+
x: 1,
|
|
415
|
+
y: 1
|
|
416
|
+
});
|
|
417
|
+
}));
|
|
418
|
+
this._ref.id(this._ref._id.toString());
|
|
419
|
+
}
|
|
420
|
+
getPosition() {
|
|
421
|
+
return this._ref.position();
|
|
422
|
+
}
|
|
423
|
+
setPosition(x, y) {
|
|
424
|
+
this._ref.setPosition({
|
|
425
|
+
x: x,
|
|
426
|
+
y: y
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
getRadiusX() {
|
|
430
|
+
return this._ref.radiusX();
|
|
431
|
+
}
|
|
432
|
+
setRadiusX(r) {
|
|
433
|
+
this._ref.radiusX(r);
|
|
434
|
+
}
|
|
435
|
+
getRadiusY() {
|
|
436
|
+
return this._ref.radiusY();
|
|
437
|
+
}
|
|
438
|
+
setRadiusY(r) {
|
|
439
|
+
this._ref.radiusY(r);
|
|
440
|
+
}
|
|
441
|
+
getLineWidth() {
|
|
442
|
+
return this._ref.strokeWidth();
|
|
443
|
+
}
|
|
444
|
+
setLineWidth(size) {
|
|
445
|
+
this._ref.strokeWidth(size);
|
|
446
|
+
}
|
|
447
|
+
ref() {
|
|
448
|
+
return this._ref;
|
|
449
|
+
}
|
|
450
|
+
id() {
|
|
451
|
+
return this._ref.id();
|
|
452
|
+
}
|
|
453
|
+
enableMouseEditing(value) {
|
|
454
|
+
this._ref.draggable(value);
|
|
455
|
+
}
|
|
456
|
+
type() {
|
|
457
|
+
return "ellipse";
|
|
458
|
+
}
|
|
459
|
+
getColor() {
|
|
460
|
+
return this._ref.stroke();
|
|
461
|
+
}
|
|
462
|
+
setColor(hex) {
|
|
463
|
+
this._ref.stroke(hex);
|
|
464
|
+
}
|
|
465
|
+
getRotation() {
|
|
466
|
+
return this._ref.rotation();
|
|
467
|
+
}
|
|
468
|
+
setRotation(degrees) {
|
|
469
|
+
this._ref.rotation(degrees);
|
|
470
|
+
}
|
|
471
|
+
getZIndex() {
|
|
472
|
+
return this._ref.zIndex();
|
|
473
|
+
}
|
|
474
|
+
setZIndex(zIndex) {
|
|
475
|
+
this._ref.zIndex(zIndex);
|
|
476
|
+
}
|
|
477
|
+
delete() {
|
|
478
|
+
this._ref.destroy();
|
|
479
|
+
this._ref = null;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
class KonvaArrow {
|
|
484
|
+
constructor(params, ref = null) {
|
|
485
|
+
var _a, _b;
|
|
486
|
+
if (ref) {
|
|
487
|
+
this._ref = ref;
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
if (!params.start || !params.end) return;
|
|
491
|
+
this._ref = new Konva.Arrow({
|
|
492
|
+
stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
|
|
493
|
+
fill: (_b = params.color) !== null && _b !== void 0 ? _b : "#ff0000",
|
|
494
|
+
strokeWidth: 4,
|
|
495
|
+
globalCompositeOperation: "source-over",
|
|
496
|
+
lineCap: "round",
|
|
497
|
+
lineJoin: "round",
|
|
498
|
+
points: [ params.start.x, params.start.y, params.end.x, params.end.y ],
|
|
499
|
+
draggable: true,
|
|
500
|
+
strokeScaleEnabled: false
|
|
501
|
+
});
|
|
502
|
+
this._ref.on("transform", (e => {
|
|
503
|
+
const attrs = e.target.attrs;
|
|
504
|
+
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
505
|
+
}));
|
|
506
|
+
this._ref.id(this._ref._id.toString());
|
|
507
|
+
}
|
|
508
|
+
ref() {
|
|
509
|
+
return this._ref;
|
|
510
|
+
}
|
|
511
|
+
id() {
|
|
512
|
+
return this._ref.id();
|
|
513
|
+
}
|
|
514
|
+
enableMouseEditing(value) {
|
|
515
|
+
this._ref.draggable(value);
|
|
516
|
+
}
|
|
517
|
+
type() {
|
|
518
|
+
return "arrow";
|
|
519
|
+
}
|
|
520
|
+
getColor() {
|
|
521
|
+
return this._ref.stroke();
|
|
522
|
+
}
|
|
523
|
+
setColor(hex) {
|
|
524
|
+
this._ref.stroke(hex);
|
|
525
|
+
this._ref.fill(hex);
|
|
526
|
+
}
|
|
527
|
+
getRotation() {
|
|
528
|
+
return this._ref.rotation();
|
|
529
|
+
}
|
|
530
|
+
setRotation(degrees) {
|
|
531
|
+
this._ref.rotation(degrees);
|
|
532
|
+
}
|
|
533
|
+
getZIndex() {
|
|
534
|
+
return this._ref.zIndex();
|
|
535
|
+
}
|
|
536
|
+
setZIndex(zIndex) {
|
|
537
|
+
this._ref.zIndex(zIndex);
|
|
538
|
+
}
|
|
539
|
+
delete() {
|
|
540
|
+
this._ref.destroy();
|
|
541
|
+
this._ref = null;
|
|
542
|
+
}
|
|
543
|
+
getPoints() {
|
|
544
|
+
const points = this._ref.points();
|
|
545
|
+
return [ {
|
|
546
|
+
x: points[0],
|
|
547
|
+
y: points[1]
|
|
548
|
+
}, {
|
|
549
|
+
x: points[2],
|
|
550
|
+
y: points[3]
|
|
551
|
+
} ];
|
|
552
|
+
}
|
|
553
|
+
setPoints(points) {
|
|
554
|
+
if (points.length === 2) {
|
|
555
|
+
this._ref.points([ points[0].x, points[0].y, points[1].x, points[1].y ]);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
getStartPoint() {
|
|
559
|
+
const points = this._ref.points();
|
|
560
|
+
return {
|
|
561
|
+
x: points[0],
|
|
562
|
+
y: points[1]
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
setStartPoint(x, y) {
|
|
566
|
+
const points = this._ref.points();
|
|
567
|
+
this._ref.points([ x, y, points[2], points[3] ]);
|
|
568
|
+
}
|
|
569
|
+
getEndPoint() {
|
|
570
|
+
const points = this._ref.points();
|
|
571
|
+
return {
|
|
572
|
+
x: points[2],
|
|
573
|
+
y: points[3]
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
setEndPoint(x, y) {
|
|
577
|
+
const points = this._ref.points();
|
|
578
|
+
this._ref.points([ points[0], points[1], x, y ]);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
class KonvaImage {
|
|
583
|
+
constructor(params, ref = null) {
|
|
584
|
+
this._ratio = 1;
|
|
585
|
+
if (ref) {
|
|
586
|
+
if (ref.height() === 0 || ref.width() === 0) return;
|
|
587
|
+
this._ref = ref;
|
|
588
|
+
this._canvasImage = ref.image();
|
|
589
|
+
this._ratio = this._ref.height() / this._ref.width();
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
if (!params.position || !params.src) return;
|
|
593
|
+
this._canvasImage = new Image;
|
|
594
|
+
this._ref = new Konva.Image({
|
|
595
|
+
x: params.position.x,
|
|
596
|
+
y: params.position.y,
|
|
597
|
+
image: this._canvasImage,
|
|
598
|
+
width: params.width,
|
|
599
|
+
height: params.height,
|
|
600
|
+
draggable: true
|
|
601
|
+
});
|
|
602
|
+
this._canvasImage.onload = () => {
|
|
603
|
+
this._ref.image(this._canvasImage);
|
|
604
|
+
if (this._ref.height() === 0) this._ref.height(this._canvasImage.height);
|
|
605
|
+
if (this._ref.width() === 0) this._ref.width(this._canvasImage.width);
|
|
606
|
+
this._ratio = this._ref.height() === 0 || this._ref.width() === 0 ? 1 : this._ref.height() / this._ref.width();
|
|
607
|
+
};
|
|
608
|
+
this._canvasImage.src = params.src;
|
|
609
|
+
this._ref.on("transform", (e => {
|
|
610
|
+
const attrs = e.target.attrs;
|
|
611
|
+
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
612
|
+
const scaleByX = Math.abs(attrs.scaleX - 1) > 1e-5;
|
|
613
|
+
const scaleByY = Math.abs(attrs.scaleY - 1) > 1e-5;
|
|
614
|
+
let newWidth = this._ref.width();
|
|
615
|
+
if (scaleByX) newWidth *= attrs.scaleX;
|
|
616
|
+
let newHeight = this._ref.height();
|
|
617
|
+
if (scaleByY) newHeight *= attrs.scaleY;
|
|
618
|
+
if (e.evt.ctrlKey || e.evt.shiftKey) {
|
|
619
|
+
if (scaleByX) {
|
|
620
|
+
this._ref.width(newWidth);
|
|
621
|
+
this._ref.height(newWidth * this._ratio);
|
|
622
|
+
} else {
|
|
623
|
+
this._ref.width(newHeight / this._ratio);
|
|
624
|
+
this._ref.height(newHeight);
|
|
625
|
+
}
|
|
626
|
+
} else {
|
|
627
|
+
if (scaleByX) {
|
|
628
|
+
this._ref.width(newWidth);
|
|
629
|
+
}
|
|
630
|
+
if (scaleByY) {
|
|
631
|
+
this._ref.height(newHeight);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
this._ref.scale({
|
|
635
|
+
x: 1,
|
|
636
|
+
y: 1
|
|
637
|
+
});
|
|
638
|
+
}));
|
|
639
|
+
this._ref.id(this._ref._id.toString());
|
|
640
|
+
}
|
|
641
|
+
getSrc() {
|
|
642
|
+
return this._canvasImage.src;
|
|
643
|
+
}
|
|
644
|
+
setSrc(src) {
|
|
645
|
+
this._canvasImage.src = src;
|
|
646
|
+
}
|
|
647
|
+
getWidth() {
|
|
648
|
+
return this._ref.width();
|
|
649
|
+
}
|
|
650
|
+
setWidth(w) {
|
|
651
|
+
this._ref.width(w);
|
|
652
|
+
this._ref.height(w * this._ratio);
|
|
653
|
+
}
|
|
654
|
+
getHeight() {
|
|
655
|
+
return this._ref.height();
|
|
656
|
+
}
|
|
657
|
+
setHeight(h) {
|
|
658
|
+
this._ref.height(h);
|
|
659
|
+
this._ref.width(h / this._ratio);
|
|
660
|
+
}
|
|
661
|
+
ref() {
|
|
662
|
+
return this._ref;
|
|
663
|
+
}
|
|
664
|
+
id() {
|
|
665
|
+
return this._ref.id();
|
|
666
|
+
}
|
|
667
|
+
enableMouseEditing(value) {
|
|
668
|
+
this._ref.draggable(value);
|
|
669
|
+
}
|
|
670
|
+
type() {
|
|
671
|
+
return "image";
|
|
672
|
+
}
|
|
673
|
+
getRotation() {
|
|
674
|
+
return this._ref.rotation();
|
|
675
|
+
}
|
|
676
|
+
setRotation(degrees) {
|
|
677
|
+
this._ref.rotation(degrees);
|
|
678
|
+
}
|
|
679
|
+
getZIndex() {
|
|
680
|
+
return this._ref.zIndex();
|
|
681
|
+
}
|
|
682
|
+
setZIndex(zIndex) {
|
|
683
|
+
this._ref.zIndex(zIndex);
|
|
684
|
+
}
|
|
685
|
+
delete() {
|
|
686
|
+
this._ref.destroy();
|
|
687
|
+
this._ref = null;
|
|
688
|
+
}
|
|
689
|
+
getPosition() {
|
|
690
|
+
return this._ref.getPosition();
|
|
691
|
+
}
|
|
692
|
+
setPosition(x, y) {
|
|
693
|
+
this._ref.setPosition({
|
|
694
|
+
x: x,
|
|
695
|
+
y: y
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
class KonvaCloud {
|
|
701
|
+
constructor(params, ref = null) {
|
|
702
|
+
var _a, _b, _c, _d;
|
|
703
|
+
if (ref) {
|
|
704
|
+
this._ref = ref;
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
if (!params.position || !params.width || !params.height) return;
|
|
708
|
+
const arcRadius = 16;
|
|
709
|
+
this._ref = new Konva.Shape({
|
|
710
|
+
x: params.position.x,
|
|
711
|
+
y: params.position.y,
|
|
712
|
+
width: (_a = params.width) !== null && _a !== void 0 ? _a : 200,
|
|
713
|
+
height: (_b = params.height) !== null && _b !== void 0 ? _b : 200,
|
|
714
|
+
stroke: (_c = params.color) !== null && _c !== void 0 ? _c : "#ff0000",
|
|
715
|
+
strokeWidth: (_d = params.lineWidth) !== null && _d !== void 0 ? _d : 4,
|
|
716
|
+
draggable: true,
|
|
717
|
+
strokeScaleEnabled: false,
|
|
718
|
+
globalCompositeOperation: "source-over",
|
|
719
|
+
sceneFunc: (context, shape) => {
|
|
720
|
+
function calculateMidpoint(position, width, height) {
|
|
721
|
+
const midX = position.x + width / 2;
|
|
722
|
+
const midY = position.y + height / 2;
|
|
723
|
+
return {
|
|
724
|
+
x: midX,
|
|
725
|
+
y: midY
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
const points = [ {
|
|
729
|
+
x: 0,
|
|
730
|
+
y: 0
|
|
731
|
+
}, {
|
|
732
|
+
x: 0 + this._ref.width(),
|
|
733
|
+
y: 0
|
|
734
|
+
}, {
|
|
735
|
+
x: 0 + this._ref.width(),
|
|
736
|
+
y: 0 + this._ref.height()
|
|
737
|
+
}, {
|
|
738
|
+
x: 0,
|
|
739
|
+
y: 0 + this._ref.height()
|
|
740
|
+
}, {
|
|
741
|
+
x: 0,
|
|
742
|
+
y: 0
|
|
743
|
+
} ];
|
|
744
|
+
const midPoint = calculateMidpoint({
|
|
745
|
+
x: 0,
|
|
746
|
+
y: 0
|
|
747
|
+
}, this._ref.width(), this._ref.height());
|
|
748
|
+
const baseArcLength = 30;
|
|
749
|
+
context.beginPath();
|
|
750
|
+
for (let iPoint = 0; iPoint < points.length - 1; iPoint++) {
|
|
751
|
+
let approxArcLength = baseArcLength;
|
|
752
|
+
const dx = points[iPoint + 1].x - points[iPoint].x;
|
|
753
|
+
const dy = points[iPoint + 1].y - points[iPoint].y;
|
|
754
|
+
const length = Math.sqrt(dx * dx + dy * dy);
|
|
755
|
+
const arcCount = Math.floor(length / approxArcLength);
|
|
756
|
+
const lengthMod = length % approxArcLength;
|
|
757
|
+
approxArcLength = baseArcLength + arcCount / lengthMod;
|
|
758
|
+
let pX = points[iPoint].x + dx / arcCount / 2;
|
|
759
|
+
let pY = points[iPoint].y + dy / arcCount / 2;
|
|
760
|
+
const pEndX = points[iPoint + 1].x;
|
|
761
|
+
const pEndY = points[iPoint + 1].y;
|
|
762
|
+
const endAngle = Math.atan((pEndY - pY) / (pEndX - pX));
|
|
763
|
+
const startAngle = endAngle + Math.PI;
|
|
764
|
+
const counterClockwise = pX > midPoint.x && pY > midPoint.y;
|
|
765
|
+
for (let iArc = 0; iArc < arcCount; iArc++) {
|
|
766
|
+
if (counterClockwise) {
|
|
767
|
+
context.arc(pX, pY, arcRadius, endAngle, startAngle);
|
|
768
|
+
} else {
|
|
769
|
+
context.arc(pX, pY, arcRadius, startAngle, endAngle);
|
|
770
|
+
}
|
|
771
|
+
pX += dx / arcCount;
|
|
772
|
+
pY += dy / arcCount;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
context.closePath();
|
|
776
|
+
context.fillStrokeShape(shape);
|
|
777
|
+
}
|
|
778
|
+
});
|
|
779
|
+
this._ref.className = "Cloud";
|
|
780
|
+
this._ref.on("transform", (e => {
|
|
781
|
+
const attrs = e.target.attrs;
|
|
782
|
+
if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
|
|
783
|
+
const scaleByX = Math.abs(attrs.scaleX - 1) > 1e-5;
|
|
784
|
+
const scaleByY = Math.abs(attrs.scaleY - 1) > 1e-5;
|
|
785
|
+
let newWidth = this._ref.width();
|
|
786
|
+
if (scaleByX) newWidth *= attrs.scaleX;
|
|
787
|
+
let newHeight = this._ref.height();
|
|
788
|
+
if (scaleByY) newHeight *= attrs.scaleY;
|
|
789
|
+
const minWidth = 100;
|
|
790
|
+
const minHeight = 100;
|
|
791
|
+
if (newWidth < minWidth) newWidth = minWidth;
|
|
792
|
+
if (newHeight < minHeight) newHeight = minHeight;
|
|
793
|
+
if (scaleByX) {
|
|
794
|
+
this._ref.width(newWidth);
|
|
795
|
+
}
|
|
796
|
+
if (scaleByY) {
|
|
797
|
+
this._ref.height(newHeight);
|
|
798
|
+
}
|
|
799
|
+
this._ref.scale({
|
|
800
|
+
x: 1,
|
|
801
|
+
y: 1
|
|
802
|
+
});
|
|
803
|
+
}));
|
|
804
|
+
this._ref.getSelfRect = () => ({
|
|
805
|
+
x: 0 - arcRadius,
|
|
806
|
+
y: 0 - arcRadius,
|
|
807
|
+
width: this._ref.width() + 2 * arcRadius,
|
|
808
|
+
height: this._ref.height() + 2 * arcRadius
|
|
809
|
+
});
|
|
810
|
+
this._ref.id(this._ref._id.toString());
|
|
811
|
+
}
|
|
812
|
+
ref() {
|
|
813
|
+
return this._ref;
|
|
814
|
+
}
|
|
815
|
+
id() {
|
|
816
|
+
return this._ref.id();
|
|
817
|
+
}
|
|
818
|
+
enableMouseEditing(value) {
|
|
819
|
+
this._ref.draggable(value);
|
|
820
|
+
}
|
|
821
|
+
type() {
|
|
822
|
+
return "cloud";
|
|
823
|
+
}
|
|
824
|
+
getColor() {
|
|
825
|
+
return this._ref.stroke();
|
|
826
|
+
}
|
|
827
|
+
setColor(hex) {
|
|
828
|
+
this._ref.stroke(hex);
|
|
829
|
+
}
|
|
830
|
+
getRotation() {
|
|
831
|
+
return this._ref.rotation();
|
|
832
|
+
}
|
|
833
|
+
setRotation(degrees) {
|
|
834
|
+
this._ref.rotation(degrees);
|
|
835
|
+
}
|
|
836
|
+
getZIndex() {
|
|
837
|
+
return this._ref.zIndex();
|
|
838
|
+
}
|
|
839
|
+
setZIndex(zIndex) {
|
|
840
|
+
this._ref.zIndex(zIndex);
|
|
841
|
+
}
|
|
842
|
+
delete() {
|
|
843
|
+
this._ref.destroy();
|
|
844
|
+
this._ref = null;
|
|
845
|
+
}
|
|
846
|
+
getPosition() {
|
|
847
|
+
return this._ref.position();
|
|
848
|
+
}
|
|
849
|
+
setPosition(x, y) {
|
|
850
|
+
this._ref.position({
|
|
851
|
+
x: x,
|
|
852
|
+
y: y
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
getWidth() {
|
|
856
|
+
return this._ref.width();
|
|
857
|
+
}
|
|
858
|
+
setWidth(w) {
|
|
859
|
+
this._ref.width(w);
|
|
860
|
+
}
|
|
861
|
+
getHeigth() {
|
|
862
|
+
return this._ref.height();
|
|
863
|
+
}
|
|
864
|
+
setHeight(h) {
|
|
865
|
+
this._ref.height(h);
|
|
866
|
+
}
|
|
867
|
+
getLineWidth() {
|
|
868
|
+
return this._ref.strokeWidth();
|
|
869
|
+
}
|
|
870
|
+
setLineWidth(size) {
|
|
871
|
+
this._ref.strokeWidth(size);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
const MarkupMode2Konva = new Map([ [ MarkupMode.SelectMarkup, {
|
|
876
|
+
name: "SelectMarkup",
|
|
877
|
+
initializer: () => {}
|
|
878
|
+
} ], [ MarkupMode.Line, {
|
|
879
|
+
name: "Line",
|
|
880
|
+
initializer: ref => new KonvaLine(null, ref)
|
|
881
|
+
} ], [ MarkupMode.Text, {
|
|
882
|
+
name: "Text",
|
|
883
|
+
initializer: ref => new KonvaText(null, ref)
|
|
884
|
+
} ], [ MarkupMode.Rectangle, {
|
|
885
|
+
name: "Rect",
|
|
886
|
+
initializer: ref => new KonvaRectangle(null, ref)
|
|
887
|
+
} ], [ MarkupMode.Ellipse, {
|
|
888
|
+
name: "Ellipse",
|
|
889
|
+
initializer: ref => new KonvaEllipse(null, ref)
|
|
890
|
+
} ], [ MarkupMode.Arrow, {
|
|
891
|
+
name: "Arrow",
|
|
892
|
+
initializer: ref => new KonvaArrow(null, ref)
|
|
893
|
+
} ], [ MarkupMode.Image, {
|
|
894
|
+
name: "Image",
|
|
895
|
+
initializer: ref => new KonvaImage(null, ref)
|
|
896
|
+
} ], [ MarkupMode.Cloud, {
|
|
897
|
+
name: "Cloud",
|
|
898
|
+
initializer: ref => new KonvaCloud(null, ref)
|
|
899
|
+
} ] ]);
|
|
900
|
+
|
|
901
|
+
class KonvaMarkup {
|
|
902
|
+
constructor() {
|
|
903
|
+
this._isInitialized = false;
|
|
904
|
+
this._markupIsActive = false;
|
|
905
|
+
this._markupColor = new MarkupColor(255, 0, 0);
|
|
906
|
+
this._zIndex = 1;
|
|
907
|
+
this._markupContainerName = "markupContainer";
|
|
908
|
+
this.lineWidth = 4;
|
|
909
|
+
this.lineType = "solid";
|
|
910
|
+
this.fontSize = 34;
|
|
911
|
+
this.changeActiveDragger = event => {
|
|
912
|
+
const draggerName = event.data;
|
|
913
|
+
this._markupContainer.className = this._canvasOriginal.className.split(" ").filter((x => !x.startsWith("oda-cursor-"))).filter((x => x)).concat(`oda-cursor-${draggerName.toLowerCase()}`).join(" ");
|
|
914
|
+
this.removeTextInput();
|
|
915
|
+
this.removeImageInput();
|
|
916
|
+
const markupMode = MarkupMode[draggerName];
|
|
917
|
+
const konvaMode = MarkupMode2Konva.get(markupMode);
|
|
918
|
+
if (konvaMode) {
|
|
919
|
+
this._markupMode = markupMode;
|
|
920
|
+
this._markupIsActive = true;
|
|
921
|
+
} else {
|
|
922
|
+
this._markupIsActive = false;
|
|
923
|
+
this._konvaTransformer.nodes([]);
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
this.resize = () => {
|
|
927
|
+
var _a, _b;
|
|
928
|
+
(_a = this._konvaStage) === null || _a === void 0 ? void 0 : _a.width(this._canvasOriginal.clientWidth);
|
|
929
|
+
(_b = this._konvaStage) === null || _b === void 0 ? void 0 : _b.height(this._canvasOriginal.clientHeight);
|
|
930
|
+
};
|
|
931
|
+
this.pan = event => {
|
|
932
|
+
const dX = event.dX / window.devicePixelRatio;
|
|
933
|
+
const dY = event.dY / window.devicePixelRatio;
|
|
934
|
+
Object.values(MarkupMode).forEach((mode => this.konvaLayerFind(mode).forEach((x => x.move({
|
|
935
|
+
x: dX,
|
|
936
|
+
y: dY
|
|
937
|
+
})))));
|
|
938
|
+
};
|
|
939
|
+
this.redirectToViewer = event => {
|
|
940
|
+
if (this._viewer) this._viewer.emit(event);
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
initialize(canvas, canvasEvents, viewer, worldTransformer) {
|
|
944
|
+
if (!Konva) throw new Error('Markup: Error during initialization. Konva is not initialized. Update node_modules or add to your page <script src="https://unpkg.com/konva@9/konva.min.js"><\/script>');
|
|
945
|
+
this._viewer = viewer;
|
|
946
|
+
this._worldTransformer = worldTransformer;
|
|
947
|
+
this._canvasOriginal = canvas;
|
|
948
|
+
this._canvasEvents = canvasEvents !== null && canvasEvents !== void 0 ? canvasEvents : [];
|
|
949
|
+
this._markupContainer = document.createElement("div");
|
|
950
|
+
this._markupContainer.id = this._markupContainerName;
|
|
951
|
+
this._markupContainer.style.position = "absolute";
|
|
952
|
+
this._markupContainer.style.top = "0px";
|
|
953
|
+
this._markupContainer.style.left = "0px";
|
|
954
|
+
this._markupContainer.style.outline = "0px";
|
|
955
|
+
const parentDiv = this._canvasOriginal.parentElement;
|
|
956
|
+
parentDiv.appendChild(this._markupContainer);
|
|
957
|
+
this._markupColor.setColor(255, 0, 0);
|
|
958
|
+
this.initializeKonva();
|
|
959
|
+
this.resize();
|
|
960
|
+
this._canvasEvents.forEach((x => this._markupContainer.addEventListener(x, this.redirectToViewer)));
|
|
961
|
+
if (this._viewer) {
|
|
962
|
+
this._viewer.addEventListener("resize", this.resize);
|
|
963
|
+
this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
|
|
964
|
+
this._viewer.addEventListener("pan", this.pan);
|
|
965
|
+
}
|
|
966
|
+
this._isInitialized = true;
|
|
967
|
+
}
|
|
968
|
+
dispose() {
|
|
969
|
+
if (!this._isInitialized) return;
|
|
970
|
+
if (this._viewer) {
|
|
971
|
+
this._viewer.removeEventListener("pan", this.pan);
|
|
972
|
+
this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
|
|
973
|
+
this._viewer.removeEventListener("resize", this.resize);
|
|
974
|
+
}
|
|
975
|
+
this._canvasEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
|
|
976
|
+
this.destroyKonva();
|
|
977
|
+
this._markupContainer.remove();
|
|
978
|
+
this._markupContainer = undefined;
|
|
979
|
+
this._canvasOriginal = undefined;
|
|
980
|
+
this._viewer = undefined;
|
|
981
|
+
this._worldTransformer = undefined;
|
|
982
|
+
this._markupIsActive = false;
|
|
983
|
+
this._isInitialized = false;
|
|
984
|
+
}
|
|
985
|
+
syncOverlay() {}
|
|
986
|
+
clearOverlay() {
|
|
987
|
+
this.removeTextInput();
|
|
988
|
+
this.removeImageInput();
|
|
989
|
+
this._konvaTransformer.nodes([]);
|
|
990
|
+
Object.values(MarkupMode).forEach((mode => this.konvaLayerFind(mode).forEach((x => x.destroy()))));
|
|
991
|
+
}
|
|
992
|
+
getMarkupColor() {
|
|
993
|
+
return this._markupColor.RGB;
|
|
994
|
+
}
|
|
995
|
+
setMarkupColor(r, g, b) {
|
|
996
|
+
this._markupColor.setColor(r, g, b);
|
|
997
|
+
}
|
|
998
|
+
colorizeAllMarkup(r = 255, g = 0, b = 0) {
|
|
999
|
+
const hex = new MarkupColor(r, g, b).HexColor;
|
|
1000
|
+
Object.values(MarkupMode).forEach((mode => {
|
|
1001
|
+
this.konvaLayerFind(mode).forEach((x => {
|
|
1002
|
+
var _a;
|
|
1003
|
+
const konvaObj = (_a = MarkupMode2Konva.get(mode)) === null || _a === void 0 ? void 0 : _a.initializer(x);
|
|
1004
|
+
if (konvaObj && konvaObj.setColor) konvaObj.setColor(hex);
|
|
1005
|
+
}));
|
|
1006
|
+
}));
|
|
1007
|
+
this._konvaLayer.draw();
|
|
1008
|
+
}
|
|
1009
|
+
colorizeSelectedMarkups(r, g, b) {
|
|
1010
|
+
this.getSelectedObjects().forEach((obj => {
|
|
1011
|
+
const colorable = obj;
|
|
1012
|
+
if (colorable && colorable.setColor) {
|
|
1013
|
+
colorable.setColor(new MarkupColor(r, g, b).HexColor);
|
|
1014
|
+
}
|
|
1015
|
+
}));
|
|
1016
|
+
}
|
|
1017
|
+
setViewpoint(viewpoint) {
|
|
1018
|
+
const markupColor = viewpoint.custom_fields.markup_color || {
|
|
1019
|
+
r: 255,
|
|
1020
|
+
g: 0,
|
|
1021
|
+
b: 0
|
|
1022
|
+
};
|
|
1023
|
+
this.setMarkupColor(markupColor.r, markupColor.g, markupColor.b);
|
|
1024
|
+
this.loadMarkup(viewpoint);
|
|
1025
|
+
}
|
|
1026
|
+
getViewpoint() {
|
|
1027
|
+
const viewpoint = {
|
|
1028
|
+
lines: [],
|
|
1029
|
+
texts: [],
|
|
1030
|
+
arrows: [],
|
|
1031
|
+
clouds: [],
|
|
1032
|
+
ellipses: [],
|
|
1033
|
+
images: [],
|
|
1034
|
+
rectangles: []
|
|
1035
|
+
};
|
|
1036
|
+
viewpoint.snapshot = {
|
|
1037
|
+
data: this.combineMarkupWithDrawing()
|
|
1038
|
+
};
|
|
1039
|
+
viewpoint.custom_fields = {
|
|
1040
|
+
markup_color: this.getMarkupColor()
|
|
1041
|
+
};
|
|
1042
|
+
this.fillViewpointShapes(viewpoint);
|
|
1043
|
+
viewpoint.description = (new Date).toDateString();
|
|
1044
|
+
return viewpoint;
|
|
1045
|
+
}
|
|
1046
|
+
createObject(type, params) {
|
|
1047
|
+
let object = null;
|
|
1048
|
+
let zIndex = this._zIndex;
|
|
1049
|
+
switch (type.toLocaleLowerCase()) {
|
|
1050
|
+
case "line":
|
|
1051
|
+
object = new KonvaLine(params);
|
|
1052
|
+
zIndex = 1;
|
|
1053
|
+
break;
|
|
1054
|
+
|
|
1055
|
+
case "text":
|
|
1056
|
+
object = new KonvaText(params);
|
|
1057
|
+
break;
|
|
1058
|
+
|
|
1059
|
+
case "rectangle":
|
|
1060
|
+
object = new KonvaRectangle(params);
|
|
1061
|
+
zIndex = 1;
|
|
1062
|
+
break;
|
|
1063
|
+
|
|
1064
|
+
case "ellipse":
|
|
1065
|
+
object = new KonvaEllipse(params);
|
|
1066
|
+
zIndex = 1;
|
|
1067
|
+
break;
|
|
1068
|
+
|
|
1069
|
+
case "arrow":
|
|
1070
|
+
object = new KonvaArrow(params);
|
|
1071
|
+
break;
|
|
1072
|
+
|
|
1073
|
+
case "image":
|
|
1074
|
+
object = new KonvaImage(params);
|
|
1075
|
+
zIndex = 0;
|
|
1076
|
+
break;
|
|
1077
|
+
|
|
1078
|
+
case "cloud":
|
|
1079
|
+
object = new KonvaCloud(params);
|
|
1080
|
+
zIndex = 1;
|
|
1081
|
+
break;
|
|
1082
|
+
|
|
1083
|
+
default:
|
|
1084
|
+
throw new Error("Markup CreateObject - unsupported type has been detected.");
|
|
1085
|
+
}
|
|
1086
|
+
this.addObject(object);
|
|
1087
|
+
object.setZIndex(zIndex);
|
|
1088
|
+
this._zIndex++;
|
|
1089
|
+
return object;
|
|
1090
|
+
}
|
|
1091
|
+
getObjects() {
|
|
1092
|
+
const objects = [];
|
|
1093
|
+
this.konvaLayerFind(MarkupMode.Line).forEach((line => {
|
|
1094
|
+
objects.push(new KonvaLine(null, line));
|
|
1095
|
+
}));
|
|
1096
|
+
this.konvaLayerFind(MarkupMode.Text).forEach((text => {
|
|
1097
|
+
objects.push(new KonvaText(null, text));
|
|
1098
|
+
}));
|
|
1099
|
+
this.konvaLayerFind(MarkupMode.Rectangle).forEach((rectangle => {
|
|
1100
|
+
objects.push(new KonvaRectangle(null, rectangle));
|
|
1101
|
+
}));
|
|
1102
|
+
this.konvaLayerFind(MarkupMode.Ellipse).forEach((ellipse => {
|
|
1103
|
+
objects.push(new KonvaEllipse(null, ellipse));
|
|
1104
|
+
}));
|
|
1105
|
+
this.konvaLayerFind(MarkupMode.Arrow).forEach((arrow => {
|
|
1106
|
+
objects.push(new KonvaArrow(null, arrow));
|
|
1107
|
+
}));
|
|
1108
|
+
this.konvaLayerFind(MarkupMode.Image).forEach((image => {
|
|
1109
|
+
objects.push(new KonvaImage(null, image));
|
|
1110
|
+
}));
|
|
1111
|
+
this.konvaLayerFind(MarkupMode.Cloud).forEach((cloud => {
|
|
1112
|
+
objects.push(new KonvaCloud(null, cloud));
|
|
1113
|
+
}));
|
|
1114
|
+
return objects;
|
|
1115
|
+
}
|
|
1116
|
+
getSelectedObjects() {
|
|
1117
|
+
const objects = [];
|
|
1118
|
+
this._konvaTransformer.nodes().forEach((obj => {
|
|
1119
|
+
const konvaShapeName = obj.className;
|
|
1120
|
+
switch (konvaShapeName) {
|
|
1121
|
+
case "Line":
|
|
1122
|
+
objects.push(new KonvaLine(null, obj));
|
|
1123
|
+
break;
|
|
1124
|
+
|
|
1125
|
+
case "Text":
|
|
1126
|
+
objects.push(new KonvaText(null, obj));
|
|
1127
|
+
break;
|
|
1128
|
+
|
|
1129
|
+
case "Rect":
|
|
1130
|
+
objects.push(new KonvaRectangle(null, obj));
|
|
1131
|
+
break;
|
|
1132
|
+
|
|
1133
|
+
case "Ellipse":
|
|
1134
|
+
objects.push(new KonvaEllipse(null, obj));
|
|
1135
|
+
break;
|
|
1136
|
+
|
|
1137
|
+
case "Arrow":
|
|
1138
|
+
objects.push(new KonvaArrow(null, obj));
|
|
1139
|
+
break;
|
|
1140
|
+
|
|
1141
|
+
case "Image":
|
|
1142
|
+
objects.push(new KonvaImage(null, obj));
|
|
1143
|
+
break;
|
|
1144
|
+
|
|
1145
|
+
case "Cloud":
|
|
1146
|
+
objects.push(new KonvaCloud(null, obj));
|
|
1147
|
+
break;
|
|
1148
|
+
}
|
|
1149
|
+
}));
|
|
1150
|
+
return objects;
|
|
1151
|
+
}
|
|
1152
|
+
selectObjects(objects) {
|
|
1153
|
+
const selectedObjs = this._konvaTransformer.nodes().concat(objects.map((x => x.ref())));
|
|
1154
|
+
this._konvaTransformer.nodes(selectedObjs);
|
|
1155
|
+
}
|
|
1156
|
+
clearSelected() {
|
|
1157
|
+
this._konvaTransformer.nodes([]);
|
|
1158
|
+
}
|
|
1159
|
+
getPoint3dFromArray(array) {
|
|
1160
|
+
return {
|
|
1161
|
+
x: array[0],
|
|
1162
|
+
y: array[1],
|
|
1163
|
+
z: array[2]
|
|
1164
|
+
};
|
|
1165
|
+
}
|
|
1166
|
+
fillViewpointShapes(viewpoint) {
|
|
1167
|
+
const markupLines = this.getMarkupLines();
|
|
1168
|
+
if (markupLines && markupLines.length > 0) {
|
|
1169
|
+
markupLines === null || markupLines === void 0 ? void 0 : markupLines.forEach((line => {
|
|
1170
|
+
viewpoint.lines.push(line);
|
|
1171
|
+
}));
|
|
1172
|
+
}
|
|
1173
|
+
const markupTexts = this.getMarkupTexts();
|
|
1174
|
+
if (markupTexts && markupTexts.length > 0) {
|
|
1175
|
+
markupTexts === null || markupTexts === void 0 ? void 0 : markupTexts.forEach((text => {
|
|
1176
|
+
viewpoint.texts.push(text);
|
|
1177
|
+
}));
|
|
1178
|
+
}
|
|
1179
|
+
const markupRectangles = this.getMarkupRectangles();
|
|
1180
|
+
if (markupRectangles && markupRectangles.length > 0) {
|
|
1181
|
+
markupRectangles === null || markupRectangles === void 0 ? void 0 : markupRectangles.forEach((rectangle => {
|
|
1182
|
+
viewpoint.rectangles.push(rectangle);
|
|
1183
|
+
}));
|
|
1184
|
+
}
|
|
1185
|
+
const markupEllipses = this.getMarkupEllipses();
|
|
1186
|
+
if (markupEllipses && markupEllipses.length > 0) {
|
|
1187
|
+
markupEllipses === null || markupEllipses === void 0 ? void 0 : markupEllipses.forEach((ellipse => {
|
|
1188
|
+
viewpoint.ellipses.push(ellipse);
|
|
1189
|
+
}));
|
|
1190
|
+
}
|
|
1191
|
+
const markupArrows = this.getMarkupArrows();
|
|
1192
|
+
if (markupArrows && markupArrows.length > 0) {
|
|
1193
|
+
markupArrows === null || markupArrows === void 0 ? void 0 : markupArrows.forEach((arrow => {
|
|
1194
|
+
viewpoint.arrows.push(arrow);
|
|
1195
|
+
}));
|
|
1196
|
+
}
|
|
1197
|
+
const markupImages = this.getMarkupImages();
|
|
1198
|
+
if (markupImages && markupImages.length > 0) {
|
|
1199
|
+
markupImages === null || markupImages === void 0 ? void 0 : markupImages.forEach((image => {
|
|
1200
|
+
viewpoint.images.push(image);
|
|
1201
|
+
}));
|
|
1202
|
+
}
|
|
1203
|
+
const markupClouds = this.getMarkupClouds();
|
|
1204
|
+
if (markupClouds && markupClouds.length > 0) {
|
|
1205
|
+
markupClouds === null || markupClouds === void 0 ? void 0 : markupClouds.forEach((cloud => {
|
|
1206
|
+
viewpoint.clouds.push(cloud);
|
|
1207
|
+
}));
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
addObject(object) {
|
|
1211
|
+
this._konvaLayer.add(object.ref());
|
|
1212
|
+
}
|
|
1213
|
+
konvaLayerFind(markupShape) {
|
|
1214
|
+
const konvaShape = MarkupMode2Konva.get(markupShape);
|
|
1215
|
+
if (konvaShape) {
|
|
1216
|
+
const konvaShapes = this._konvaLayer.find(konvaShape.name).filter((x => x.parent instanceof Konva.Layer));
|
|
1217
|
+
return konvaShapes;
|
|
1218
|
+
}
|
|
1219
|
+
return [];
|
|
1220
|
+
}
|
|
1221
|
+
initializeKonva() {
|
|
1222
|
+
this._konvaStage = new Konva.Stage({
|
|
1223
|
+
container: this._markupContainerName,
|
|
1224
|
+
width: this._canvasOriginal.clientWidth,
|
|
1225
|
+
height: this._canvasOriginal.clientHeight
|
|
1226
|
+
});
|
|
1227
|
+
const stage = this._konvaStage;
|
|
1228
|
+
const layer = new Konva.Layer({
|
|
1229
|
+
pixelRation: window.devicePixelRatio
|
|
1230
|
+
});
|
|
1231
|
+
stage.add(layer);
|
|
1232
|
+
this._konvaLayer = layer;
|
|
1233
|
+
const transformer = new Konva.Transformer({
|
|
1234
|
+
shouldOverdrawWholeArea: false,
|
|
1235
|
+
keepRatio: false,
|
|
1236
|
+
flipEnabled: false
|
|
1237
|
+
});
|
|
1238
|
+
this._konvaTransformer = transformer;
|
|
1239
|
+
layer.add(transformer);
|
|
1240
|
+
let isPaint = false;
|
|
1241
|
+
let lastLine;
|
|
1242
|
+
let mouseDownPos;
|
|
1243
|
+
let lastObj;
|
|
1244
|
+
stage.on("mousedown touchstart", (e => {
|
|
1245
|
+
if (!this._markupIsActive || e.target !== stage || this._markupMode === MarkupMode.Text || this._markupMode === MarkupMode.Image) return;
|
|
1246
|
+
if (e.target === stage && transformer.nodes().length > 0) {
|
|
1247
|
+
transformer.nodes([]);
|
|
1248
|
+
return;
|
|
1249
|
+
}
|
|
1250
|
+
const pos = stage.getPointerPosition();
|
|
1251
|
+
mouseDownPos = pos;
|
|
1252
|
+
isPaint = [ MarkupMode.Arrow, MarkupMode.Cloud, MarkupMode.Ellipse, MarkupMode.Line, MarkupMode.Rectangle ].some((m => m === this._markupMode));
|
|
1253
|
+
if (this._markupMode === MarkupMode.Line) {
|
|
1254
|
+
lastLine = this.addLine([ pos.x, pos.y, pos.x, pos.y ]);
|
|
1255
|
+
}
|
|
1256
|
+
}));
|
|
1257
|
+
stage.on("mouseup touchend", (e => {
|
|
1258
|
+
if (!this._markupIsActive) return;
|
|
1259
|
+
if (isPaint) {
|
|
1260
|
+
const pos = stage.getPointerPosition();
|
|
1261
|
+
const defParams = mouseDownPos && pos.x === mouseDownPos.x && pos.y === mouseDownPos.y;
|
|
1262
|
+
const startX = defParams ? mouseDownPos.x : Math.min(mouseDownPos.x, pos.x);
|
|
1263
|
+
const startY = defParams ? mouseDownPos.y : Math.min(mouseDownPos.y, pos.y);
|
|
1264
|
+
const dX = defParams ? 200 : Math.abs(mouseDownPos.x - pos.x);
|
|
1265
|
+
const dY = defParams ? 200 : Math.abs(mouseDownPos.y - pos.y);
|
|
1266
|
+
if (defParams) {
|
|
1267
|
+
if (this._markupMode === MarkupMode.Rectangle) {
|
|
1268
|
+
this.addRectangle({
|
|
1269
|
+
x: startX,
|
|
1270
|
+
y: startY
|
|
1271
|
+
}, dX, dY);
|
|
1272
|
+
} else if (this._markupMode === MarkupMode.Ellipse) {
|
|
1273
|
+
this.addEllipse({
|
|
1274
|
+
x: startX,
|
|
1275
|
+
y: startY
|
|
1276
|
+
}, {
|
|
1277
|
+
x: dX / 2,
|
|
1278
|
+
y: dY / 2
|
|
1279
|
+
});
|
|
1280
|
+
} else if (this._markupMode === MarkupMode.Arrow) {
|
|
1281
|
+
this.addArrow({
|
|
1282
|
+
x: mouseDownPos.x,
|
|
1283
|
+
y: mouseDownPos.y
|
|
1284
|
+
}, {
|
|
1285
|
+
x: defParams ? mouseDownPos.x + 200 : pos.x,
|
|
1286
|
+
y: defParams ? startY : pos.y
|
|
1287
|
+
});
|
|
1288
|
+
} else if (this._markupMode === MarkupMode.Cloud) {
|
|
1289
|
+
this.addCloud({
|
|
1290
|
+
x: startX,
|
|
1291
|
+
y: startY
|
|
1292
|
+
}, Math.max(100, dX), Math.max(100, dY));
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
lastObj = undefined;
|
|
1297
|
+
isPaint = false;
|
|
1298
|
+
}));
|
|
1299
|
+
stage.on("mousemove touchmove", (e => {
|
|
1300
|
+
if (!this._markupIsActive) return;
|
|
1301
|
+
if (!isPaint) {
|
|
1302
|
+
return;
|
|
1303
|
+
}
|
|
1304
|
+
const pos = stage.getPointerPosition();
|
|
1305
|
+
const defParams = mouseDownPos && pos.x === mouseDownPos.x && pos.y === mouseDownPos.y;
|
|
1306
|
+
const startX = defParams ? mouseDownPos.x : Math.min(mouseDownPos.x, pos.x);
|
|
1307
|
+
const startY = defParams ? mouseDownPos.y : Math.min(mouseDownPos.y, pos.y);
|
|
1308
|
+
const dX = defParams ? 200 : Math.abs(mouseDownPos.x - pos.x);
|
|
1309
|
+
const dY = defParams ? 200 : Math.abs(mouseDownPos.y - pos.y);
|
|
1310
|
+
if (this._markupMode === MarkupMode.Line) {
|
|
1311
|
+
lastLine.addPoints([ {
|
|
1312
|
+
x: pos.x,
|
|
1313
|
+
y: pos.y
|
|
1314
|
+
} ]);
|
|
1315
|
+
} else if (this._markupMode === MarkupMode.Arrow) {
|
|
1316
|
+
if (lastObj) lastObj.setEndPoint(pos.x, pos.y); else lastObj = this.addArrow({
|
|
1317
|
+
x: mouseDownPos.x,
|
|
1318
|
+
y: mouseDownPos.y
|
|
1319
|
+
}, {
|
|
1320
|
+
x: pos.x,
|
|
1321
|
+
y: pos.y
|
|
1322
|
+
});
|
|
1323
|
+
} else if (this._markupMode === MarkupMode.Rectangle) {
|
|
1324
|
+
if (lastObj) {
|
|
1325
|
+
lastObj.setPosition(startX, startY);
|
|
1326
|
+
lastObj.setWidth(dX);
|
|
1327
|
+
lastObj.setHeight(dY);
|
|
1328
|
+
} else lastObj = this.addRectangle({
|
|
1329
|
+
x: startX,
|
|
1330
|
+
y: startY
|
|
1331
|
+
}, dX, dY);
|
|
1332
|
+
} else if (this._markupMode === MarkupMode.Ellipse) {
|
|
1333
|
+
if (lastObj) {
|
|
1334
|
+
lastObj.setPosition(startX, startY);
|
|
1335
|
+
lastObj.setRadiusX(dX);
|
|
1336
|
+
lastObj.setRadiusY(dY);
|
|
1337
|
+
} else lastObj = this.addEllipse({
|
|
1338
|
+
x: startX,
|
|
1339
|
+
y: startY
|
|
1340
|
+
}, {
|
|
1341
|
+
x: dX,
|
|
1342
|
+
y: dY
|
|
1343
|
+
});
|
|
1344
|
+
} else if (this._markupMode === MarkupMode.Cloud) {
|
|
1345
|
+
if (lastObj) {
|
|
1346
|
+
lastObj.setPosition(startX, startY);
|
|
1347
|
+
lastObj.setWidth(Math.max(100, dX));
|
|
1348
|
+
lastObj.setHeight(Math.max(100, dY));
|
|
1349
|
+
} else lastObj = this.addCloud({
|
|
1350
|
+
x: startX,
|
|
1351
|
+
y: startY
|
|
1352
|
+
}, dX, dY);
|
|
1353
|
+
}
|
|
1354
|
+
}));
|
|
1355
|
+
stage.on("click tap", (e => {
|
|
1356
|
+
if (!this._markupIsActive) return;
|
|
1357
|
+
if (e.target === stage) {
|
|
1358
|
+
if (this._markupMode === MarkupMode.Text) {
|
|
1359
|
+
if (this._textInputRef && this._textInputRef.value) this.addText(this._textInputRef.value, this._textInputPos, this._textInputAngle); else if (transformer.nodes().length === 0) {
|
|
1360
|
+
const pos = stage.getPointerPosition();
|
|
1361
|
+
this.createTextInput(pos, e.evt.pageX, e.evt.pageY, 0, null);
|
|
1362
|
+
}
|
|
1363
|
+
} else if (this._markupMode === MarkupMode.Image) {
|
|
1364
|
+
if (this._imageInputRef && this._imageInputRef.value) this.addImage({
|
|
1365
|
+
x: this._imageInputPos.x,
|
|
1366
|
+
y: this._imageInputPos.y
|
|
1367
|
+
}, this._imageInputRef.value, 0, 0, this._imageInputRef.value); else if (transformer.nodes().length === 0) {
|
|
1368
|
+
const pos = stage.getPointerPosition();
|
|
1369
|
+
this.createImageInput(pos);
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
transformer.nodes([]);
|
|
1373
|
+
return;
|
|
1374
|
+
}
|
|
1375
|
+
if (this._markupMode === MarkupMode.Text || this._markupMode === MarkupMode.SelectMarkup) {
|
|
1376
|
+
if (e.target.className === "Text" && transformer.nodes().length === 1 && transformer.nodes()[0] === e.target) {
|
|
1377
|
+
if (this._textInputRef && this._textInputRef.value) this.addText(this._textInputRef.value, this._textInputPos, this._textInputAngle); else this.createTextInput({
|
|
1378
|
+
x: e.target.attrs.x,
|
|
1379
|
+
y: e.target.attrs.y
|
|
1380
|
+
}, e.evt.pageX, e.evt.pageY, e.target.attrs.rotation, e.target.attrs.text);
|
|
1381
|
+
return;
|
|
1382
|
+
} else {
|
|
1383
|
+
this.removeTextInput();
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
if (this._markupMode === MarkupMode.Image || this._markupMode === MarkupMode.SelectMarkup) {
|
|
1387
|
+
if (e.target.className === "Image" && transformer.nodes().length === 1 && transformer.nodes()[0] === e.target) {
|
|
1388
|
+
if (this._imageInputRef && this._imageInputRef.value) this.addImage(this._imageInputPos, this._imageInputRef.value, 0, 0); else this.createImageInput({
|
|
1389
|
+
x: e.target.attrs.x,
|
|
1390
|
+
y: e.target.attrs.y
|
|
1391
|
+
});
|
|
1392
|
+
return;
|
|
1393
|
+
} else {
|
|
1394
|
+
this.removeImageInput();
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
if (transformer.nodes().filter((x => x.className === "Cloud")).length > 0 || e.target.className === "Cloud") {
|
|
1398
|
+
transformer.rotateEnabled(false);
|
|
1399
|
+
} else {
|
|
1400
|
+
transformer.rotateEnabled(true);
|
|
1401
|
+
}
|
|
1402
|
+
const metaPressed = e.evt.shiftKey || e.evt.ctrlKey || e.evt.metaKey;
|
|
1403
|
+
const isSelected = transformer.nodes().indexOf(e.target) >= 0;
|
|
1404
|
+
if (!metaPressed && !isSelected) {
|
|
1405
|
+
transformer.nodes([ e.target ]);
|
|
1406
|
+
} else if (metaPressed && isSelected) {
|
|
1407
|
+
const nodes = transformer.nodes().slice();
|
|
1408
|
+
nodes.splice(nodes.indexOf(e.target), 1);
|
|
1409
|
+
transformer.nodes(nodes);
|
|
1410
|
+
} else if (metaPressed && !isSelected) {
|
|
1411
|
+
const nodes = transformer.nodes().concat([ e.target ]);
|
|
1412
|
+
transformer.nodes(nodes);
|
|
1413
|
+
}
|
|
1414
|
+
}));
|
|
1415
|
+
const container = stage.container();
|
|
1416
|
+
container.tabIndex = 1;
|
|
1417
|
+
container.focus();
|
|
1418
|
+
container.addEventListener("keydown", (e => {
|
|
1419
|
+
if (!this._markupIsActive) return;
|
|
1420
|
+
if (e.code === "Delete") {
|
|
1421
|
+
const trNodes = this._konvaTransformer.nodes();
|
|
1422
|
+
if (trNodes.length > 0) {
|
|
1423
|
+
this._konvaTransformer.nodes().forEach((x => x.destroy()));
|
|
1424
|
+
this._konvaTransformer.nodes([]);
|
|
1425
|
+
}
|
|
1426
|
+
layer.draw();
|
|
1427
|
+
return;
|
|
1428
|
+
}
|
|
1429
|
+
e.preventDefault();
|
|
1430
|
+
}));
|
|
1431
|
+
}
|
|
1432
|
+
destroyKonva() {
|
|
1433
|
+
this.clearOverlay();
|
|
1434
|
+
this._konvaStage.destroy();
|
|
1435
|
+
this._konvaLayer = undefined;
|
|
1436
|
+
this._konvaTransformer = undefined;
|
|
1437
|
+
this._konvaStage = undefined;
|
|
1438
|
+
}
|
|
1439
|
+
getMarkupLines() {
|
|
1440
|
+
const lines = [];
|
|
1441
|
+
this.konvaLayerFind(MarkupMode.Line).forEach((line => {
|
|
1442
|
+
const linePoints = line.points();
|
|
1443
|
+
if (!linePoints) return;
|
|
1444
|
+
const worldPoints = [];
|
|
1445
|
+
const absoluteTransform = line.getAbsoluteTransform();
|
|
1446
|
+
for (let i = 0; i < linePoints.length; i += 2) {
|
|
1447
|
+
const atPoint = absoluteTransform.point({
|
|
1448
|
+
x: linePoints[i],
|
|
1449
|
+
y: linePoints[i + 1]
|
|
1450
|
+
});
|
|
1451
|
+
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
1452
|
+
worldPoints.push(worldPoint);
|
|
1453
|
+
}
|
|
1454
|
+
const konvaLine = new KonvaLine(null, line);
|
|
1455
|
+
lines.push({
|
|
1456
|
+
id: konvaLine.id(),
|
|
1457
|
+
points: worldPoints.map((p => this.getPoint3dFromArray(p))),
|
|
1458
|
+
color: konvaLine.getColor() || "#ff0000",
|
|
1459
|
+
type: konvaLine.getLineType() || this.lineType,
|
|
1460
|
+
width: konvaLine.getLineWidth() || this.lineWidth
|
|
1461
|
+
});
|
|
1462
|
+
}));
|
|
1463
|
+
return lines;
|
|
1464
|
+
}
|
|
1465
|
+
getMarkupTexts() {
|
|
1466
|
+
const texts = [];
|
|
1467
|
+
const textSize = .02;
|
|
1468
|
+
const textScale = this._worldTransformer.getScale();
|
|
1469
|
+
this.konvaLayerFind(MarkupMode.Text).forEach((text => {
|
|
1470
|
+
if (!text) return;
|
|
1471
|
+
const position = this._worldTransformer.screenToWorld({
|
|
1472
|
+
x: text.x(),
|
|
1473
|
+
y: text.y()
|
|
1474
|
+
});
|
|
1475
|
+
const shape = new KonvaText(null, text);
|
|
1476
|
+
texts.push({
|
|
1477
|
+
id: shape.id(),
|
|
1478
|
+
position: this.getPoint3dFromArray(position),
|
|
1479
|
+
text: shape.getText(),
|
|
1480
|
+
text_size: textSize * textScale.y,
|
|
1481
|
+
angle: shape.getRotation(),
|
|
1482
|
+
color: shape.getColor(),
|
|
1483
|
+
font_size: shape.getFontSize()
|
|
1484
|
+
});
|
|
1485
|
+
}));
|
|
1486
|
+
return texts;
|
|
1487
|
+
}
|
|
1488
|
+
getMarkupRectangles() {
|
|
1489
|
+
const rectangles = [];
|
|
1490
|
+
this.konvaLayerFind(MarkupMode.Rectangle).forEach((rect => {
|
|
1491
|
+
const position = rect.position();
|
|
1492
|
+
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
1493
|
+
const shape = new KonvaRectangle(null, rect);
|
|
1494
|
+
rectangles.push({
|
|
1495
|
+
id: shape.id(),
|
|
1496
|
+
position: this.getPoint3dFromArray(worldPoint),
|
|
1497
|
+
width: shape.getWidth(),
|
|
1498
|
+
height: shape.getHeigth(),
|
|
1499
|
+
line_width: shape.getLineWidth(),
|
|
1500
|
+
color: shape.getColor()
|
|
1501
|
+
});
|
|
1502
|
+
}));
|
|
1503
|
+
return rectangles;
|
|
1504
|
+
}
|
|
1505
|
+
getMarkupEllipses() {
|
|
1506
|
+
const ellipses = [];
|
|
1507
|
+
this.konvaLayerFind(MarkupMode.Ellipse).forEach((ellipse => {
|
|
1508
|
+
const position = ellipse.position();
|
|
1509
|
+
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
1510
|
+
const shape = new KonvaEllipse(null, ellipse);
|
|
1511
|
+
ellipses.push({
|
|
1512
|
+
id: shape.id(),
|
|
1513
|
+
position: this.getPoint3dFromArray(worldPoint),
|
|
1514
|
+
radius: {
|
|
1515
|
+
x: ellipse.getRadiusX(),
|
|
1516
|
+
y: ellipse.getRadiusY()
|
|
1517
|
+
},
|
|
1518
|
+
line_width: shape.getLineWidth(),
|
|
1519
|
+
color: shape.getColor()
|
|
1520
|
+
});
|
|
1521
|
+
}));
|
|
1522
|
+
return ellipses;
|
|
1523
|
+
}
|
|
1524
|
+
getMarkupArrows() {
|
|
1525
|
+
const arrows = [];
|
|
1526
|
+
this.konvaLayerFind(MarkupMode.Arrow).forEach((arrow => {
|
|
1527
|
+
const absoluteTransform = arrow.getAbsoluteTransform();
|
|
1528
|
+
const atStartPoint = absoluteTransform.point({
|
|
1529
|
+
x: arrow.points()[0],
|
|
1530
|
+
y: arrow.points()[1]
|
|
1531
|
+
});
|
|
1532
|
+
const worldStartPoint = this._worldTransformer.screenToWorld(atStartPoint);
|
|
1533
|
+
const atEndPoint = absoluteTransform.point({
|
|
1534
|
+
x: arrow.points()[2],
|
|
1535
|
+
y: arrow.points()[3]
|
|
1536
|
+
});
|
|
1537
|
+
const worldEndPoint = this._worldTransformer.screenToWorld(atEndPoint);
|
|
1538
|
+
const shape = new KonvaArrow(null, arrow);
|
|
1539
|
+
arrows.push({
|
|
1540
|
+
id: shape.id(),
|
|
1541
|
+
start: this.getPoint3dFromArray(worldStartPoint),
|
|
1542
|
+
end: this.getPoint3dFromArray(worldEndPoint),
|
|
1543
|
+
color: shape.getColor()
|
|
1544
|
+
});
|
|
1545
|
+
}));
|
|
1546
|
+
return arrows;
|
|
1547
|
+
}
|
|
1548
|
+
getMarkupImages() {
|
|
1549
|
+
const images = [];
|
|
1550
|
+
this.konvaLayerFind(MarkupMode.Image).forEach((image => {
|
|
1551
|
+
const position = image.position();
|
|
1552
|
+
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
1553
|
+
const shape = new KonvaImage(null, image);
|
|
1554
|
+
images.push({
|
|
1555
|
+
id: shape.id(),
|
|
1556
|
+
position: this.getPoint3dFromArray(worldPoint),
|
|
1557
|
+
src: shape.getSrc(),
|
|
1558
|
+
width: shape.getWidth(),
|
|
1559
|
+
height: shape.getHeight()
|
|
1560
|
+
});
|
|
1561
|
+
}));
|
|
1562
|
+
return images;
|
|
1563
|
+
}
|
|
1564
|
+
getMarkupClouds() {
|
|
1565
|
+
const clouds = [];
|
|
1566
|
+
this.konvaLayerFind(MarkupMode.Cloud).forEach((cloud => {
|
|
1567
|
+
const position = cloud.position();
|
|
1568
|
+
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
1569
|
+
const shape = new KonvaCloud(null, cloud);
|
|
1570
|
+
clouds.push({
|
|
1571
|
+
id: shape.id(),
|
|
1572
|
+
position: this.getPoint3dFromArray(worldPoint),
|
|
1573
|
+
width: shape.getWidth(),
|
|
1574
|
+
height: shape.getHeigth(),
|
|
1575
|
+
line_width: shape.getLineWidth(),
|
|
1576
|
+
color: shape.getColor()
|
|
1577
|
+
});
|
|
1578
|
+
}));
|
|
1579
|
+
return clouds;
|
|
1580
|
+
}
|
|
1581
|
+
loadMarkup(viewpoint) {
|
|
1582
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1583
|
+
(_a = viewpoint.lines) === null || _a === void 0 ? void 0 : _a.forEach((vpLine => {
|
|
1584
|
+
const linePoints = [];
|
|
1585
|
+
vpLine.points.forEach((point => {
|
|
1586
|
+
const screenPoint = this._worldTransformer.worldToScreen(point);
|
|
1587
|
+
linePoints.push(screenPoint.x);
|
|
1588
|
+
linePoints.push(screenPoint.y);
|
|
1589
|
+
}));
|
|
1590
|
+
this.addLine(linePoints, vpLine.color, vpLine.type, vpLine.width, vpLine.id);
|
|
1591
|
+
}));
|
|
1592
|
+
(_b = viewpoint.texts) === null || _b === void 0 ? void 0 : _b.forEach((vpText => {
|
|
1593
|
+
const screenPoint = this._worldTransformer.worldToScreen(vpText.position);
|
|
1594
|
+
this.addText(vpText.text, screenPoint, vpText.angle, vpText.color, vpText.text_size, vpText.font_size, vpText.id);
|
|
1595
|
+
}));
|
|
1596
|
+
(_c = viewpoint.rectangles) === null || _c === void 0 ? void 0 : _c.forEach((vpRect => {
|
|
1597
|
+
const screenPoint = this._worldTransformer.worldToScreen(vpRect.position);
|
|
1598
|
+
this.addRectangle(screenPoint, vpRect.width, vpRect.height, vpRect.line_width, vpRect.color, vpRect.id);
|
|
1599
|
+
}));
|
|
1600
|
+
(_d = viewpoint.ellipses) === null || _d === void 0 ? void 0 : _d.forEach((vpEllipse => {
|
|
1601
|
+
const screenPoint = this._worldTransformer.worldToScreen(vpEllipse.position);
|
|
1602
|
+
this.addEllipse(screenPoint, vpEllipse.radius, vpEllipse.line_width, vpEllipse.color, vpEllipse.id);
|
|
1603
|
+
}));
|
|
1604
|
+
(_e = viewpoint.arrows) === null || _e === void 0 ? void 0 : _e.forEach((vpArrow => {
|
|
1605
|
+
const startPoint = this._worldTransformer.worldToScreen(vpArrow.start);
|
|
1606
|
+
const endPoint = this._worldTransformer.worldToScreen(vpArrow.end);
|
|
1607
|
+
this.addArrow(startPoint, endPoint, vpArrow.color, vpArrow.id);
|
|
1608
|
+
}));
|
|
1609
|
+
(_f = viewpoint.clouds) === null || _f === void 0 ? void 0 : _f.forEach((vpCloud => {
|
|
1610
|
+
const screenPoint = this._worldTransformer.worldToScreen(vpCloud.position);
|
|
1611
|
+
this.addCloud(screenPoint, vpCloud.width, vpCloud.height, vpCloud.line_width, vpCloud.color, vpCloud.id);
|
|
1612
|
+
}));
|
|
1613
|
+
(_g = viewpoint.images) === null || _g === void 0 ? void 0 : _g.forEach((vpImage => {
|
|
1614
|
+
const screenPoint = this._worldTransformer.worldToScreen(vpImage.position);
|
|
1615
|
+
this.addImage(screenPoint, vpImage.src, vpImage.width, vpImage.height, vpImage.id);
|
|
1616
|
+
}));
|
|
1617
|
+
}
|
|
1618
|
+
combineMarkupWithDrawing() {
|
|
1619
|
+
const trNodes = this._konvaTransformer.nodes();
|
|
1620
|
+
if (trNodes.length > 0) {
|
|
1621
|
+
this._konvaTransformer.nodes([]);
|
|
1622
|
+
}
|
|
1623
|
+
const tempCanvas = document.createElement("canvas");
|
|
1624
|
+
tempCanvas.height = this._canvasOriginal.height;
|
|
1625
|
+
tempCanvas.width = this._canvasOriginal.width;
|
|
1626
|
+
const ctx = tempCanvas.getContext("2d");
|
|
1627
|
+
ctx.drawImage(this._canvasOriginal, 0, 0);
|
|
1628
|
+
ctx.drawImage(this._konvaStage.toCanvas({
|
|
1629
|
+
pixelRatio: window.devicePixelRatio
|
|
1630
|
+
}), 0, 0);
|
|
1631
|
+
return tempCanvas.toDataURL("image/jpeg", .25);
|
|
1632
|
+
}
|
|
1633
|
+
addLine(linePoints, color, type, width, id) {
|
|
1634
|
+
if (!linePoints || linePoints.length === 0) return;
|
|
1635
|
+
const points = [];
|
|
1636
|
+
for (let i = 0; i < linePoints.length; i += 2) {
|
|
1637
|
+
points.push({
|
|
1638
|
+
x: linePoints[i],
|
|
1639
|
+
y: linePoints[i + 1]
|
|
1640
|
+
});
|
|
1641
|
+
}
|
|
1642
|
+
const konvaLine = new KonvaLine({
|
|
1643
|
+
points: points,
|
|
1644
|
+
type: type || this.lineType,
|
|
1645
|
+
width: width || this.lineWidth,
|
|
1646
|
+
color: color || this._markupColor.HexColor,
|
|
1647
|
+
id: id
|
|
1648
|
+
});
|
|
1649
|
+
const obj = konvaLine.ref();
|
|
1650
|
+
this._konvaLayer.add(obj);
|
|
1651
|
+
return konvaLine;
|
|
1652
|
+
}
|
|
1653
|
+
createTextInput(pos, inputX, inputY, angle, text) {
|
|
1654
|
+
if (!this._textInputRef) {
|
|
1655
|
+
this._textInputPos = pos;
|
|
1656
|
+
this._textInputAngle = angle;
|
|
1657
|
+
this._textInputRef = document.createElement("textarea");
|
|
1658
|
+
this._textInputRef.style.zIndex = "9999";
|
|
1659
|
+
this._textInputRef.style.position = "absolute";
|
|
1660
|
+
this._textInputRef.style.display = "block";
|
|
1661
|
+
this._textInputRef.style.top = inputY + "px";
|
|
1662
|
+
this._textInputRef.style.left = inputX + "px";
|
|
1663
|
+
this._textInputRef.onkeydown = event => {
|
|
1664
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
1665
|
+
event.preventDefault();
|
|
1666
|
+
this.addText(this._textInputRef.value, this._textInputPos, this._textInputAngle);
|
|
1667
|
+
}
|
|
1668
|
+
if (event.key === "Escape") {
|
|
1669
|
+
event.preventDefault();
|
|
1670
|
+
this.removeTextInput();
|
|
1671
|
+
}
|
|
1672
|
+
};
|
|
1673
|
+
if (text) this._textInputRef.value = text;
|
|
1674
|
+
document.body.appendChild(this._textInputRef);
|
|
1675
|
+
setTimeout((() => {
|
|
1676
|
+
this._textInputRef.focus();
|
|
1677
|
+
}), 50);
|
|
1678
|
+
} else {
|
|
1679
|
+
this.removeTextInput();
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
removeTextInput() {
|
|
1683
|
+
var _a;
|
|
1684
|
+
(_a = this._textInputRef) === null || _a === void 0 ? void 0 : _a.remove();
|
|
1685
|
+
this._textInputRef = null;
|
|
1686
|
+
this._textInputPos = null;
|
|
1687
|
+
this._textInputAngle = 0;
|
|
1688
|
+
}
|
|
1689
|
+
createImageInput(pos) {
|
|
1690
|
+
if (!this._imageInputRef) {
|
|
1691
|
+
const convertBase64 = file => new Promise(((resolve, reject) => {
|
|
1692
|
+
const fileReader = new FileReader;
|
|
1693
|
+
fileReader.readAsDataURL(file);
|
|
1694
|
+
fileReader.onload = () => {
|
|
1695
|
+
resolve(fileReader.result);
|
|
1696
|
+
};
|
|
1697
|
+
fileReader.onerror = error => {
|
|
1698
|
+
reject(error);
|
|
1699
|
+
};
|
|
1700
|
+
}));
|
|
1701
|
+
this._imageInputPos = pos;
|
|
1702
|
+
this._imageInputRef = document.createElement("input");
|
|
1703
|
+
this._imageInputRef.style.display = "none";
|
|
1704
|
+
this._imageInputRef.type = "file";
|
|
1705
|
+
this._imageInputRef.accept = "image/png, image/jpeg";
|
|
1706
|
+
this._imageInputRef.onchange = async event => {
|
|
1707
|
+
const file = event.target.files[0];
|
|
1708
|
+
const base64 = await convertBase64(file);
|
|
1709
|
+
this.addImage({
|
|
1710
|
+
x: this._imageInputPos.x,
|
|
1711
|
+
y: this._imageInputPos.y
|
|
1712
|
+
}, base64.toString(), 0, 0);
|
|
1713
|
+
};
|
|
1714
|
+
this._imageInputRef.oncancel = event => {
|
|
1715
|
+
this.removeImageInput();
|
|
1716
|
+
};
|
|
1717
|
+
document.body.appendChild(this._imageInputRef);
|
|
1718
|
+
setTimeout((() => {
|
|
1719
|
+
this._imageInputRef.click();
|
|
1720
|
+
}), 50);
|
|
1721
|
+
} else {
|
|
1722
|
+
this.removeImageInput();
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
removeImageInput() {
|
|
1726
|
+
var _a;
|
|
1727
|
+
(_a = this._imageInputRef) === null || _a === void 0 ? void 0 : _a.remove();
|
|
1728
|
+
this._imageInputRef = null;
|
|
1729
|
+
this._imageInputPos = null;
|
|
1730
|
+
}
|
|
1731
|
+
addText(specifiedText, position, angle, color, textSize, fontSize, id) {
|
|
1732
|
+
const trNodes = this._konvaTransformer.nodes();
|
|
1733
|
+
if (trNodes.length > 0) {
|
|
1734
|
+
trNodes[0].destroy();
|
|
1735
|
+
this._konvaTransformer.nodes([]);
|
|
1736
|
+
}
|
|
1737
|
+
this.removeTextInput();
|
|
1738
|
+
if (specifiedText) {
|
|
1739
|
+
const tolerance = 1e-6;
|
|
1740
|
+
if (textSize && textSize > tolerance && (!fontSize || fontSize < tolerance)) {
|
|
1741
|
+
const size = .02;
|
|
1742
|
+
const scale = this._worldTransformer.getScale();
|
|
1743
|
+
fontSize = textSize / (scale.y / size) / 34;
|
|
1744
|
+
}
|
|
1745
|
+
const konvaText = new KonvaText({
|
|
1746
|
+
position: {
|
|
1747
|
+
x: position.x,
|
|
1748
|
+
y: position.y
|
|
1749
|
+
},
|
|
1750
|
+
text: specifiedText,
|
|
1751
|
+
rotation: angle,
|
|
1752
|
+
fontSize: fontSize || this.fontSize,
|
|
1753
|
+
color: color || this._markupColor.HexColor,
|
|
1754
|
+
id: id
|
|
1755
|
+
});
|
|
1756
|
+
this._konvaLayer.add(konvaText.ref());
|
|
1757
|
+
return konvaText;
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
addRectangle(position, width, height, lineWidth, color, id) {
|
|
1761
|
+
if (!position) return;
|
|
1762
|
+
const konvaRectangle = new KonvaRectangle({
|
|
1763
|
+
position: position,
|
|
1764
|
+
width: width,
|
|
1765
|
+
height: height,
|
|
1766
|
+
lineWidth: lineWidth || this.lineWidth,
|
|
1767
|
+
color: color || this._markupColor.HexColor,
|
|
1768
|
+
id: id
|
|
1769
|
+
});
|
|
1770
|
+
const obj = konvaRectangle.ref();
|
|
1771
|
+
this._konvaLayer.add(obj);
|
|
1772
|
+
return konvaRectangle;
|
|
1773
|
+
}
|
|
1774
|
+
addEllipse(position, radius, lineWidth, color, id) {
|
|
1775
|
+
if (!position) return;
|
|
1776
|
+
const konvaEllipse = new KonvaEllipse({
|
|
1777
|
+
position: position,
|
|
1778
|
+
radius: radius,
|
|
1779
|
+
lineWidth: lineWidth,
|
|
1780
|
+
color: color || this._markupColor.HexColor,
|
|
1781
|
+
id: id
|
|
1782
|
+
});
|
|
1783
|
+
const obj = konvaEllipse.ref();
|
|
1784
|
+
this._konvaLayer.add(obj);
|
|
1785
|
+
return konvaEllipse;
|
|
1786
|
+
}
|
|
1787
|
+
addArrow(start, end, color, id) {
|
|
1788
|
+
if (!start || !end) return;
|
|
1789
|
+
const konvaArrow = new KonvaArrow({
|
|
1790
|
+
start: start,
|
|
1791
|
+
end: end,
|
|
1792
|
+
color: color || this._markupColor.HexColor,
|
|
1793
|
+
id: id
|
|
1794
|
+
});
|
|
1795
|
+
const obj = konvaArrow.ref();
|
|
1796
|
+
this._konvaLayer.add(obj);
|
|
1797
|
+
return konvaArrow;
|
|
1798
|
+
}
|
|
1799
|
+
addCloud(position, width, height, lineWidth, color, id) {
|
|
1800
|
+
if (!position || !width || !height) return;
|
|
1801
|
+
const konvaCloud = new KonvaCloud({
|
|
1802
|
+
position: position,
|
|
1803
|
+
width: width,
|
|
1804
|
+
height: height,
|
|
1805
|
+
color: color || this._markupColor.HexColor,
|
|
1806
|
+
lineWidth: lineWidth || this.lineWidth,
|
|
1807
|
+
id: id
|
|
1808
|
+
});
|
|
1809
|
+
const obj = konvaCloud.ref();
|
|
1810
|
+
this._konvaLayer.add(obj);
|
|
1811
|
+
return konvaCloud;
|
|
1812
|
+
}
|
|
1813
|
+
addImage(position, src, width, height, id) {
|
|
1814
|
+
if (!position) return;
|
|
1815
|
+
let konvaImage;
|
|
1816
|
+
if (src) {
|
|
1817
|
+
konvaImage = new KonvaImage({
|
|
1818
|
+
position: position,
|
|
1819
|
+
src: src,
|
|
1820
|
+
width: width,
|
|
1821
|
+
height: height,
|
|
1822
|
+
id: id
|
|
1823
|
+
});
|
|
1824
|
+
const obj = konvaImage.ref();
|
|
1825
|
+
this._konvaLayer.add(obj);
|
|
1826
|
+
const trNodes = this._konvaTransformer.nodes();
|
|
1827
|
+
if (trNodes.length > 0) {
|
|
1828
|
+
trNodes[0].destroy();
|
|
1829
|
+
this._konvaTransformer.nodes([]);
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
this.removeImageInput();
|
|
1833
|
+
return konvaImage;
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1837
|
+
export { KonvaMarkup as Markup, MarkupMode };
|
|
1838
|
+
//# sourceMappingURL=markup.module.js.map
|