@inweb/markup 26.4.0 → 26.5.0

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 (40) hide show
  1. package/dist/markup.js +636 -137
  2. package/dist/markup.js.map +1 -1
  3. package/dist/markup.min.js +1 -1
  4. package/dist/markup.module.js +772 -151
  5. package/dist/markup.module.js.map +1 -1
  6. package/lib/markup/IMarkupArrow.d.ts +8 -8
  7. package/lib/markup/IMarkupCloud.d.ts +12 -5
  8. package/lib/markup/IMarkupEllipse.d.ts +19 -4
  9. package/lib/markup/IMarkupImage.d.ts +15 -7
  10. package/lib/markup/IMarkupLine.d.ts +2 -2
  11. package/lib/markup/IMarkupObject.d.ts +4 -0
  12. package/lib/markup/IMarkupRectangle.d.ts +12 -5
  13. package/lib/markup/IMarkupText.d.ts +3 -3
  14. package/lib/markup/Konva/KonvaArrow.d.ts +4 -1
  15. package/lib/markup/Konva/KonvaCloud.d.ts +4 -1
  16. package/lib/markup/Konva/KonvaEllipse.d.ts +4 -1
  17. package/lib/markup/Konva/KonvaImage.d.ts +4 -1
  18. package/lib/markup/Konva/KonvaLine.d.ts +4 -1
  19. package/lib/markup/Konva/KonvaMarkup.d.ts +2 -2
  20. package/lib/markup/Konva/KonvaRectangle.d.ts +4 -1
  21. package/lib/markup/Konva/KonvaText.d.ts +4 -1
  22. package/lib/markup/Utils.d.ts +7 -0
  23. package/package.json +3 -3
  24. package/src/markup/IMarkupArrow.ts +8 -8
  25. package/src/markup/IMarkupCloud.ts +10 -5
  26. package/src/markup/IMarkupEllipse.ts +15 -4
  27. package/src/markup/IMarkupImage.ts +13 -7
  28. package/src/markup/IMarkupLine.ts +2 -2
  29. package/src/markup/IMarkupObject.ts +5 -0
  30. package/src/markup/IMarkupRectangle.ts +10 -5
  31. package/src/markup/IMarkupText.ts +3 -3
  32. package/src/markup/Konva/KonvaArrow.ts +49 -4
  33. package/src/markup/Konva/KonvaCloud.ts +113 -11
  34. package/src/markup/Konva/KonvaEllipse.ts +110 -3
  35. package/src/markup/Konva/KonvaImage.ts +101 -2
  36. package/src/markup/Konva/KonvaLine.ts +97 -3
  37. package/src/markup/Konva/KonvaMarkup.ts +216 -172
  38. package/src/markup/Konva/KonvaRectangle.ts +106 -4
  39. package/src/markup/Konva/KonvaText.ts +61 -2
  40. package/src/markup/Utils.ts +3 -0
@@ -55,10 +55,29 @@ class MarkupColor {
55
55
  const LineTypeSpecs = new Map([ [ "solid", [] ], [ "dot", [ 30, 30, .001, 30 ] ], [ "dash", [ 30, 30 ] ] ]);
56
56
 
57
57
  class KonvaLine {
58
- constructor(params, ref = null) {
58
+ constructor(params, ref = null, worldTransformer = new WorldTransform) {
59
59
  var _a, _b;
60
+ this._worldTransformer = worldTransformer;
60
61
  if (ref) {
61
62
  this._ref = ref;
63
+ let wcsPoints = this._ref.getAttr("wcsPoints");
64
+ if (!wcsPoints) {
65
+ wcsPoints = [];
66
+ let points = this._ref.points();
67
+ let wcsPoint;
68
+ for (let i = 0; i < points.length; i += 2) {
69
+ wcsPoint = this._worldTransformer.screenToWorld({
70
+ x: points[i],
71
+ y: points[i + 1]
72
+ });
73
+ wcsPoints.push({
74
+ x: wcsPoint.x,
75
+ y: wcsPoint.y,
76
+ z: wcsPoint.z
77
+ });
78
+ }
79
+ this._ref.setAttr("wcsPoints", wcsPoints);
80
+ }
62
81
  return;
63
82
  }
64
83
  if (!params) params = {};
@@ -70,7 +89,19 @@ class KonvaLine {
70
89
  y: 100
71
90
  } ];
72
91
  const konvaPoints = [];
73
- params.points.forEach((point => konvaPoints.push(point.x, point.y)));
92
+ const wcsPoints = [];
93
+ params.points.forEach((point => {
94
+ konvaPoints.push(point.x, point.y);
95
+ let wcsPoint = this._worldTransformer.screenToWorld({
96
+ x: point.x,
97
+ y: point.y
98
+ });
99
+ wcsPoints.push({
100
+ x: wcsPoint.x,
101
+ y: wcsPoint.y,
102
+ z: wcsPoint.z
103
+ });
104
+ }));
74
105
  this._ref = new Konva.Line({
75
106
  stroke: (_a = params.color) !== null && _a !== undefined ? _a : "#ff0000",
76
107
  strokeWidth: (_b = params.width) !== null && _b !== undefined ? _b : 4,
@@ -82,10 +113,55 @@ class KonvaLine {
82
113
  strokeScaleEnabled: false,
83
114
  dash: LineTypeSpecs.get(params.type) || []
84
115
  });
116
+ this._ref.setAttr("wcsPoints", wcsPoints);
85
117
  this._ref.on("transform", (e => {
86
118
  const attrs = e.target.attrs;
87
119
  if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
88
120
  }));
121
+ this._ref.on("transformend", (e => {
122
+ const absoluteTransform = this._ref.getAbsoluteTransform();
123
+ let wcsPoints = [];
124
+ let points = this._ref.points();
125
+ let wcsPoint;
126
+ for (let i = 0; i < points.length; i += 2) {
127
+ const position = absoluteTransform.point({
128
+ x: points[i],
129
+ y: points[i + 1]
130
+ });
131
+ wcsPoint = this._worldTransformer.screenToWorld({
132
+ x: position.x,
133
+ y: position.y
134
+ });
135
+ wcsPoints.push({
136
+ x: wcsPoint.x,
137
+ y: wcsPoint.y,
138
+ z: wcsPoint.z
139
+ });
140
+ }
141
+ this._ref.setAttr("wcsPoints", wcsPoints);
142
+ }));
143
+ this._ref.on("dragend", (e => {
144
+ const absoluteTransform = this._ref.getAbsoluteTransform();
145
+ let wcsPoints = [];
146
+ let points = this._ref.points();
147
+ let wcsPoint;
148
+ for (let i = 0; i < points.length; i += 2) {
149
+ const position = absoluteTransform.point({
150
+ x: points[i],
151
+ y: points[i + 1]
152
+ });
153
+ wcsPoint = this._worldTransformer.screenToWorld({
154
+ x: position.x,
155
+ y: position.y
156
+ });
157
+ wcsPoints.push({
158
+ x: wcsPoint.x,
159
+ y: wcsPoint.y,
160
+ z: wcsPoint.z
161
+ });
162
+ }
163
+ this._ref.setAttr("wcsPoints", wcsPoints);
164
+ }));
89
165
  this._ref.id(this._ref._id.toString());
90
166
  }
91
167
  ref() {
@@ -155,19 +231,48 @@ class KonvaLine {
155
231
  }
156
232
  addPoints(points) {
157
233
  let newPoints = this._ref.points();
234
+ let wcsPoints = this._ref.getAttr("wcsPoints");
158
235
  points.forEach((point => {
159
236
  newPoints = newPoints.concat([ point.x, point.y ]);
237
+ let wcsPoint = this._worldTransformer.screenToWorld(point);
238
+ wcsPoints.push(wcsPoint);
160
239
  }));
161
240
  this._ref.points(newPoints);
162
241
  }
242
+ updateScreenCoordinates() {
243
+ let wcsPoints = this._ref.getAttr("wcsPoints");
244
+ let points = [];
245
+ let invert = this._ref.getAbsoluteTransform().copy();
246
+ invert = invert.invert();
247
+ wcsPoints.forEach((point => {
248
+ let screenPoint = this._worldTransformer.worldToScreen(point);
249
+ screenPoint = invert.point({
250
+ x: screenPoint.x,
251
+ y: screenPoint.y
252
+ });
253
+ points.push(screenPoint.x);
254
+ points.push(screenPoint.y);
255
+ }));
256
+ this._ref.points([]);
257
+ this._ref.points(points);
258
+ this._ref.clearCache();
259
+ }
163
260
  }
164
261
 
165
262
  class KonvaText {
166
- constructor(params, ref = null) {
263
+ constructor(params, ref = null, worldTransformer = new WorldTransform) {
167
264
  var _a, _b, _c;
168
265
  this.TEXT_FONT_FAMILY = "Calibri";
266
+ this._worldTransformer = worldTransformer;
169
267
  if (ref) {
170
268
  this._ref = ref;
269
+ const wcsStart = this._ref.getAttr("wcsStart");
270
+ if (!wcsStart) {
271
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
272
+ x: ref.x(),
273
+ y: ref.y()
274
+ }));
275
+ }
171
276
  return;
172
277
  }
173
278
  if (!params) params = {};
@@ -188,6 +293,10 @@ class KonvaText {
188
293
  rotation: (_c = params.rotation) !== null && _c !== undefined ? _c : 0
189
294
  });
190
295
  this._ref.width(this._ref.getTextWidth());
296
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
297
+ x: params.position.x,
298
+ y: params.position.y
299
+ }));
191
300
  this._ref.on("transform", (e => {
192
301
  const attrs = e.target.attrs;
193
302
  if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
@@ -211,6 +320,24 @@ class KonvaText {
211
320
  y: 1
212
321
  });
213
322
  }));
323
+ this._ref.on("transformend", (e => {
324
+ const attrs = e.target.attrs;
325
+ if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
326
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
327
+ const position = absoluteTransform.point({
328
+ x: this._ref.x(),
329
+ y: this._ref.y()
330
+ });
331
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
332
+ }));
333
+ this._ref.on("dragend", (e => {
334
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
335
+ const position = absoluteTransform.point({
336
+ x: this._ref.x(),
337
+ y: this._ref.y()
338
+ });
339
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
340
+ }));
214
341
  this._ref.id(this._ref._id.toString());
215
342
  }
216
343
  ref() {
@@ -261,6 +388,10 @@ class KonvaText {
261
388
  x: x,
262
389
  y: y
263
390
  });
391
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
392
+ x: x,
393
+ y: y
394
+ }));
264
395
  }
265
396
  getFontSize() {
266
397
  return this._ref.fontSize();
@@ -268,13 +399,42 @@ class KonvaText {
268
399
  setFontSize(size) {
269
400
  this._ref.fontSize(size);
270
401
  }
402
+ updateScreenCoordinates() {
403
+ let screenPositionStart = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
404
+ let invert = this._ref.getStage().getAbsoluteTransform().copy();
405
+ invert = invert.invert();
406
+ const positionStart = invert.point(screenPositionStart);
407
+ this._ref.position({
408
+ x: positionStart.x,
409
+ y: positionStart.y
410
+ });
411
+ }
271
412
  }
272
413
 
273
414
  class KonvaRectangle {
274
- constructor(params, ref = null) {
415
+ constructor(params, ref = null, worldTransformer = new WorldTransform) {
275
416
  var _a, _b, _c, _d;
417
+ this._worldTransformer = worldTransformer;
276
418
  if (ref) {
277
419
  this._ref = ref;
420
+ const wcsStart = this._ref.getAttr("wcsStart");
421
+ const wcsEnd = this._ref.getAttr("wcsEnd");
422
+ if (!wcsStart) {
423
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
424
+ x: ref.x(),
425
+ y: ref.y()
426
+ }));
427
+ }
428
+ if (!wcsEnd) {
429
+ const rightBottomPoint = {
430
+ x: ref.x() + ref.width(),
431
+ y: ref.y() + ref.height()
432
+ };
433
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
434
+ x: rightBottomPoint.x,
435
+ y: rightBottomPoint.y
436
+ }));
437
+ }
278
438
  return;
279
439
  }
280
440
  if (!params) params = {};
@@ -282,6 +442,24 @@ class KonvaRectangle {
282
442
  x: 0,
283
443
  y: 0
284
444
  };
445
+ if (params.position2) {
446
+ params.width = params.position2.x - params.position.x;
447
+ params.height = params.position2.y - params.position.y;
448
+ } else {
449
+ if (!params.width || !params.height) {
450
+ params.position2 = {
451
+ x: 200,
452
+ y: 200
453
+ };
454
+ params.width = 200;
455
+ params.height = 200;
456
+ } else {
457
+ params.position2 = {
458
+ x: params.position.x + params.width,
459
+ y: params.position.y + params.height
460
+ };
461
+ }
462
+ }
285
463
  this._ref = new Konva.Rect({
286
464
  stroke: (_a = params.color) !== null && _a !== undefined ? _a : "#ff0000",
287
465
  strokeWidth: (_b = params.lineWidth) !== null && _b !== undefined ? _b : 4,
@@ -295,9 +473,16 @@ class KonvaRectangle {
295
473
  draggable: true,
296
474
  strokeScaleEnabled: false
297
475
  });
476
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
477
+ x: params.position.x,
478
+ y: params.position.y
479
+ }));
480
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
481
+ x: params.position2.x,
482
+ y: params.position2.y
483
+ }));
298
484
  this._ref.on("transform", (e => {
299
485
  const attrs = e.target.attrs;
300
- if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
301
486
  const scaleByX = Math.abs(attrs.scaleX - 1) > 1e-5;
302
487
  const scaleByY = Math.abs(attrs.scaleY - 1) > 1e-5;
303
488
  let newWidth = this._ref.width();
@@ -319,6 +504,32 @@ class KonvaRectangle {
319
504
  y: 1
320
505
  });
321
506
  }));
507
+ this._ref.on("transformend", (e => {
508
+ const attrs = e.target.attrs;
509
+ if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
510
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
511
+ const position = absoluteTransform.point({
512
+ x: this._ref.x(),
513
+ y: this._ref.y()
514
+ });
515
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
516
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
517
+ x: position.x + this._ref.width(),
518
+ y: position.y + this._ref.height()
519
+ }));
520
+ }));
521
+ this._ref.on("dragend", (e => {
522
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
523
+ const position = absoluteTransform.point({
524
+ x: this._ref.x(),
525
+ y: this._ref.y()
526
+ });
527
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
528
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
529
+ x: position.x + this._ref.width(),
530
+ y: position.y + this._ref.height()
531
+ }));
532
+ }));
322
533
  this._ref.id(this._ref._id.toString());
323
534
  }
324
535
  getPosition() {
@@ -332,15 +543,37 @@ class KonvaRectangle {
332
543
  }
333
544
  setWidth(w) {
334
545
  this._ref.width(w);
546
+ const rightLowerPoint = {
547
+ x: this._ref.x() + w,
548
+ y: this._ref.y() + this._ref.height()
549
+ };
550
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
551
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
335
552
  }
336
553
  setHeight(h) {
337
554
  this._ref.height(h);
555
+ const rightLowerPoint = {
556
+ x: this._ref.x() + this._ref.width(),
557
+ y: this._ref.y() + h
558
+ };
559
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
560
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
338
561
  }
339
562
  setPosition(x, y) {
340
563
  this._ref.setPosition({
341
564
  x: x,
342
565
  y: y
343
566
  });
567
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
568
+ x: x,
569
+ y: y
570
+ }));
571
+ const rightLowerPoint = {
572
+ x: x + this._ref.width(),
573
+ y: y + this._ref.y()
574
+ };
575
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
576
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
344
577
  }
345
578
  ref() {
346
579
  return this._ref;
@@ -382,13 +615,53 @@ class KonvaRectangle {
382
615
  getLineWidth() {
383
616
  return this._ref.strokeWidth();
384
617
  }
618
+ updateScreenCoordinates() {
619
+ let screenPositionStart = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
620
+ let screenPositionEnd = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));
621
+ let invert = this._ref.getStage().getAbsoluteTransform().copy();
622
+ invert = invert.invert();
623
+ const positionStart = invert.point(screenPositionStart);
624
+ const positionEnd = invert.point(screenPositionEnd);
625
+ this._ref.position({
626
+ x: positionStart.x,
627
+ y: positionStart.y
628
+ });
629
+ this._ref.width(Math.abs(positionEnd.x - positionStart.x));
630
+ this._ref.height(Math.abs(positionEnd.y - positionStart.y));
631
+ }
632
+ }
633
+
634
+ function getDistanceIn2D(p1, p2) {
635
+ return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));
385
636
  }
386
637
 
387
638
  class KonvaEllipse {
388
- constructor(params, ref = null) {
639
+ constructor(params, ref = null, worldTransformer = new WorldTransform) {
389
640
  var _a, _b;
641
+ this._worldTransformer = worldTransformer;
390
642
  if (ref) {
391
643
  this._ref = ref;
644
+ const wcsPosition = this._ref.getAttr("wcsPosition");
645
+ const radiusX = this._ref.getAttr("wcsRadiusX");
646
+ const radiusY = this._ref.getAttr("wcsRadiusY");
647
+ if (!wcsPosition) {
648
+ this._ref.setAttr("wcsPosition", this._worldTransformer.screenToWorld({
649
+ x: ref.x(),
650
+ y: ref.y()
651
+ }));
652
+ }
653
+ if (!radiusX) {
654
+ this._ref.setAttr("wcsRadiusX", this._worldTransformer.screenToWorld({
655
+ x: ref.x() + ref.radiusX(),
656
+ y: ref.y()
657
+ }));
658
+ }
659
+ if (!radiusY) {
660
+ this._ref.setAttr("wcsRadiusY", this._worldTransformer.screenToWorld({
661
+ x: ref.x(),
662
+ y: ref.y() + ref.radiusY()
663
+ }));
664
+ }
392
665
  return;
393
666
  }
394
667
  if (!params) params = {};
@@ -396,10 +669,15 @@ class KonvaEllipse {
396
669
  x: 0,
397
670
  y: 0
398
671
  };
399
- if (!params.radius) params.radius = {
400
- x: 25,
401
- y: 25
402
- };
672
+ if (params.position2) {
673
+ params.radius.x = getDistanceIn2D(params.position, params.position2);
674
+ if (params.position3) params.radius.y = getDistanceIn2D(params.position, params.position3); else params.radius.x = params.radius.y;
675
+ } else {
676
+ if (!params.radius) params.radius = {
677
+ x: 25,
678
+ y: 25
679
+ };
680
+ }
403
681
  this._ref = new Konva.Ellipse({
404
682
  stroke: (_a = params.color) !== null && _a !== undefined ? _a : "#ff0000",
405
683
  strokeWidth: (_b = params.lineWidth) !== null && _b !== undefined ? _b : 4,
@@ -413,6 +691,18 @@ class KonvaEllipse {
413
691
  draggable: true,
414
692
  strokeScaleEnabled: false
415
693
  });
694
+ this._ref.setAttr("wcsPosition", this._worldTransformer.screenToWorld({
695
+ x: params.position.x,
696
+ y: params.position.y
697
+ }));
698
+ this._ref.setAttr("wcsRadiusX", this._worldTransformer.screenToWorld({
699
+ x: this._ref.x() + params.radius.x,
700
+ y: this._ref.y()
701
+ }));
702
+ this._ref.setAttr("wcsRadiusY", this._worldTransformer.screenToWorld({
703
+ x: this._ref.x(),
704
+ y: this._ref.y() + params.radius.y
705
+ }));
416
706
  this._ref.on("transform", (e => {
417
707
  const attrs = e.target.attrs;
418
708
  if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
@@ -449,6 +739,42 @@ class KonvaEllipse {
449
739
  y: 1
450
740
  });
451
741
  }));
742
+ this._ref.on("transformend", (e => {
743
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
744
+ const position = absoluteTransform.point({
745
+ x: this._ref.x(),
746
+ y: this._ref.y()
747
+ });
748
+ this._ref.setAttr("wcsPosition", this._worldTransformer.screenToWorld(position));
749
+ const radiusX = absoluteTransform.point({
750
+ x: this._ref.x() + this._ref.radiusX(),
751
+ y: this._ref.y()
752
+ });
753
+ this._ref.setAttr("wcsRadiusX", this._worldTransformer.screenToWorld(radiusX));
754
+ const radiusY = absoluteTransform.point({
755
+ x: this._ref.x(),
756
+ y: this._ref.y() + this._ref.radiusY()
757
+ });
758
+ this._ref.setAttr("wcsRadiusY", this._worldTransformer.screenToWorld(radiusY));
759
+ }));
760
+ this._ref.on("dragend", (e => {
761
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
762
+ const position = absoluteTransform.point({
763
+ x: this._ref.x(),
764
+ y: this._ref.y()
765
+ });
766
+ this._ref.setAttr("wcsPosition", this._worldTransformer.screenToWorld(position));
767
+ const radiusX = absoluteTransform.point({
768
+ x: this._ref.x() + this._ref.radiusX(),
769
+ y: this._ref.y()
770
+ });
771
+ this._ref.setAttr("wcsRadiusX", this._worldTransformer.screenToWorld(radiusX));
772
+ const radiusY = absoluteTransform.point({
773
+ x: this._ref.x(),
774
+ y: this._ref.y() + this._ref.radiusY()
775
+ });
776
+ this._ref.setAttr("wcsRadiusY", this._worldTransformer.screenToWorld(radiusY));
777
+ }));
452
778
  this._ref.id(this._ref._id.toString());
453
779
  }
454
780
  getPosition() {
@@ -459,18 +785,30 @@ class KonvaEllipse {
459
785
  x: x,
460
786
  y: y
461
787
  });
788
+ this._ref.setAttr("wcsPosition", this._worldTransformer.screenToWorld({
789
+ x: x,
790
+ y: y
791
+ }));
462
792
  }
463
793
  getRadiusX() {
464
794
  return this._ref.radiusX();
465
795
  }
466
796
  setRadiusX(r) {
467
797
  this._ref.radiusX(r);
798
+ this._ref.setAttr("wcsRadiusX", this._worldTransformer.screenToWorld({
799
+ x: this._ref.x() + r,
800
+ y: this._ref.y()
801
+ }));
468
802
  }
469
803
  getRadiusY() {
470
804
  return this._ref.radiusY();
471
805
  }
472
806
  setRadiusY(r) {
473
807
  this._ref.radiusY(r);
808
+ this._ref.setAttr("wcsRadiusY", this._worldTransformer.screenToWorld({
809
+ x: this._ref.x(),
810
+ y: this._ref.y() + r
811
+ }));
474
812
  }
475
813
  getLineWidth() {
476
814
  return this._ref.strokeWidth();
@@ -512,13 +850,43 @@ class KonvaEllipse {
512
850
  this._ref.destroy();
513
851
  this._ref = null;
514
852
  }
853
+ updateScreenCoordinates() {
854
+ let screenPosition = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsPosition"));
855
+ let radiusX = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsRadiusX"));
856
+ let radiusY = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsRadiusY"));
857
+ let invert = this._ref.getStage().getAbsoluteTransform().copy();
858
+ invert = invert.invert();
859
+ const position = invert.point({
860
+ x: screenPosition.x,
861
+ y: screenPosition.y
862
+ });
863
+ this._ref.position({
864
+ x: position.x,
865
+ y: position.y
866
+ });
867
+ this._ref.radius({
868
+ x: Math.abs(invert.point(radiusX).x - position.x),
869
+ y: Math.abs(invert.point(radiusY).y - position.y)
870
+ });
871
+ }
515
872
  }
516
873
 
517
874
  class KonvaArrow {
518
- constructor(params, ref = null) {
875
+ constructor(params, ref = null, worldTransformer = new WorldTransform) {
519
876
  var _a, _b;
877
+ this._worldTransformer = worldTransformer;
520
878
  if (ref) {
521
879
  this._ref = ref;
880
+ const wcsStart = this._ref.getAttr("wcsStart");
881
+ const wcsEnd = this._ref.getAttr("wcsEnd");
882
+ if (!wcsStart) this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
883
+ x: ref.points()[0],
884
+ y: ref.points()[1]
885
+ }));
886
+ if (!wcsEnd) this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
887
+ x: ref.points()[2],
888
+ y: ref.points()[3]
889
+ }));
522
890
  return;
523
891
  }
524
892
  if (!params) params = {};
@@ -541,9 +909,43 @@ class KonvaArrow {
541
909
  draggable: true,
542
910
  strokeScaleEnabled: false
543
911
  });
544
- this._ref.on("transform", (e => {
912
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
913
+ x: params.start.x,
914
+ y: params.start.y
915
+ }));
916
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
917
+ x: params.end.x,
918
+ y: params.end.y
919
+ }));
920
+ this._ref.on("transformend", (e => {
545
921
  const attrs = e.target.attrs;
546
922
  if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
923
+ const points = this._ref.points();
924
+ const absoluteTransform = this._ref.getAbsoluteTransform();
925
+ const transformStart = absoluteTransform.point({
926
+ x: points[0],
927
+ y: points[1]
928
+ });
929
+ const transformEnd = absoluteTransform.point({
930
+ x: points[2],
931
+ y: points[3]
932
+ });
933
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(transformStart));
934
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld(transformEnd));
935
+ }));
936
+ this._ref.on("dragend", (e => {
937
+ const points = this._ref.points();
938
+ const absoluteTransform = e.target.getAbsoluteTransform();
939
+ const transformStart = absoluteTransform.point({
940
+ x: points[0],
941
+ y: points[1]
942
+ });
943
+ const transformEnd = absoluteTransform.point({
944
+ x: points[2],
945
+ y: points[3]
946
+ });
947
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(transformStart));
948
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld(transformEnd));
547
949
  }));
548
950
  this._ref.id(this._ref._id.toString());
549
951
  }
@@ -594,6 +996,14 @@ class KonvaArrow {
594
996
  }
595
997
  setPoints(points) {
596
998
  if (points.length === 2) {
999
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
1000
+ x: points[0].x,
1001
+ y: points[0].y
1002
+ }));
1003
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
1004
+ x: points[1].x,
1005
+ y: points[1].y
1006
+ }));
597
1007
  this._ref.points([ points[0].x, points[0].y, points[1].x, points[1].y ]);
598
1008
  }
599
1009
  }
@@ -607,6 +1017,10 @@ class KonvaArrow {
607
1017
  setStartPoint(x, y) {
608
1018
  const points = this._ref.points();
609
1019
  this._ref.points([ x, y, points[2], points[3] ]);
1020
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
1021
+ x: x,
1022
+ y: y
1023
+ }));
610
1024
  }
611
1025
  getEndPoint() {
612
1026
  const points = this._ref.points();
@@ -618,16 +1032,36 @@ class KonvaArrow {
618
1032
  setEndPoint(x, y) {
619
1033
  const points = this._ref.points();
620
1034
  this._ref.points([ points[0], points[1], x, y ]);
1035
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
1036
+ x: x,
1037
+ y: y
1038
+ }));
1039
+ }
1040
+ updateScreenCoordinates() {
1041
+ let screenStartPoint = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
1042
+ let screenEndPoint = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));
1043
+ let invert = this._ref.getAbsoluteTransform().copy();
1044
+ invert = invert.invert();
1045
+ const startPoint = invert.point({
1046
+ x: screenStartPoint.x,
1047
+ y: screenStartPoint.y
1048
+ });
1049
+ const endPoint = invert.point({
1050
+ x: screenEndPoint.x,
1051
+ y: screenEndPoint.y
1052
+ });
1053
+ this._ref.points([ startPoint.x, startPoint.y, endPoint.x, endPoint.y ]);
621
1054
  }
622
1055
  }
623
1056
 
624
1057
  class KonvaImage {
625
- constructor(params, ref = null) {
1058
+ constructor(params, ref = null, worldTransformer = new WorldTransform) {
626
1059
  var _a, _b;
627
1060
  this._ratio = 1;
628
1061
  this.EPSILON = 1e-5;
629
1062
  this.BASE64_HEADER_START = "data:image/";
630
1063
  this.BASE64_NOT_FOUND = "data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAADsAAAA7AF5KHG9AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAmhJREFUWIXtlr9rVEEQxz+H8RQUJIdeIopYm0vkCg0GBBtbG1NF7Kxt7dR/IGIw/uhTaBNLERURg2kCEUyCYCPi70b0InjGS57FzOZN3r19d+9HJIVfWO52dma/s7Mz8xa2KAaBCWAR+AkECWOmSOIdwC1gtQOpHc+NfQ8wClQ8+1d0vcdH/lQ3bSIRGAZ2pTjAqNovANXIWlXlAXA2zvi2Ln4AjqYgtagYEutENSLvjRoOImFv5iB32Ae8UrLXwFBk3h9ndF0VJnKSO9gTu3yKu5Z1LKnS8YIcABgw5Ks692JZFXcXRJ46Aq6kikCnHNi/mQ50WwVtfaIoBzL3gRk2drSscJ2wrc4VvUoe2wn/41/iBfoVLRnBGnDSY3AAKacy8AmYR+o7K1zCl6wgrgpOAc/MuhvfgMuk+1JGHQgSBcAloKXy78AjYBppJk5/noTulseBMZ23iD/piHFkEdgTQzKk+5wHjmHC3cmBg0BD5xcSTrFXyQPgIWFtDwMvab+2N8DpbhyY1v/3E8gdDgNfVX9SCVZ0/gW4B0wB71S2BpxLcuCM/jaQSHSDEeAX4VMuAG4gTzyHbcAVXXO6GxxwIX+vvxe7JHcYQ07nHqklj96UIW/YhSWzMKcep8VVtf8B1Dw6h4DfhB+sdbgn2R+gnoEc5NR3dZ+3QJ9H74HqXLPCGlJyTfI9y3YCs0owq3OLOpKkLeBI1HhSDT/mdKIPiUCARMTlQx34TMLjtww8IczmO8AJ/N/2JNSQXAiQ671JePePge0+wzJSQq4FFzlaenIvucUAkiQLhC/mLGNZ9xgn5s63BP4CCk0QDtm4BhoAAAAASUVORK5CYII=";
1064
+ this._worldTransformer = worldTransformer;
631
1065
  if (ref) {
632
1066
  if (!ref.src || !ref.src.startsWith(this.BASE64_HEADER_START)) ref.src = this.BASE64_NOT_FOUND;
633
1067
  if (ref.height() <= this.EPSILON) ref.height(32);
@@ -635,6 +1069,24 @@ class KonvaImage {
635
1069
  this._ref = ref;
636
1070
  this._canvasImage = ref.image();
637
1071
  this._ratio = this._ref.height() <= this.EPSILON || this._ref.width() <= this.EPSILON ? 1 : this._ref.height() / this._ref.width();
1072
+ const wcsStart = this._ref.getAttr("wcsStart");
1073
+ const wcsEnd = this._ref.getAttr("wcsEnd");
1074
+ if (!wcsStart) {
1075
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
1076
+ x: ref.x(),
1077
+ y: ref.y()
1078
+ }));
1079
+ }
1080
+ if (!wcsEnd) {
1081
+ const rightBottomPoint = {
1082
+ x: ref.x() + ref.width(),
1083
+ y: ref.y() + ref.height()
1084
+ };
1085
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
1086
+ x: rightBottomPoint.x,
1087
+ y: rightBottomPoint.y
1088
+ }));
1089
+ }
638
1090
  return;
639
1091
  }
640
1092
  if (!params) params = {};
@@ -643,6 +1095,10 @@ class KonvaImage {
643
1095
  y: 0
644
1096
  };
645
1097
  if (!params.src || !params.src.startsWith(this.BASE64_HEADER_START)) params.src = this.BASE64_NOT_FOUND;
1098
+ if (params.position2) {
1099
+ params.width = params.position2.x - params.position.x;
1100
+ params.height = params.position2.y - params.position.y;
1101
+ }
646
1102
  this._canvasImage = new Image;
647
1103
  this._canvasImage.onload = () => {
648
1104
  this._ref.image(this._canvasImage);
@@ -660,6 +1116,11 @@ class KonvaImage {
660
1116
  this._ref.width(params.maxHeight / this._ratio);
661
1117
  this._ref.height(params.maxHeight);
662
1118
  }
1119
+ const wcsEnd = this._worldTransformer.screenToWorld({
1120
+ x: params.position.x + this._ref.width(),
1121
+ y: params.position.y + this._ref.height()
1122
+ });
1123
+ this._ref.setAttr("wcsEnd", wcsEnd);
663
1124
  }
664
1125
  }
665
1126
  };
@@ -676,6 +1137,10 @@ class KonvaImage {
676
1137
  height: (_b = params.height) !== null && _b !== undefined ? _b : 0,
677
1138
  draggable: true
678
1139
  });
1140
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
1141
+ x: params.position.x,
1142
+ y: params.position.y
1143
+ }));
679
1144
  this._ref.on("transform", (e => {
680
1145
  const attrs = e.target.attrs;
681
1146
  if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
@@ -706,6 +1171,30 @@ class KonvaImage {
706
1171
  y: 1
707
1172
  });
708
1173
  }));
1174
+ this._ref.on("transformend", (e => {
1175
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
1176
+ const position = absoluteTransform.point({
1177
+ x: this._ref.x(),
1178
+ y: this._ref.y()
1179
+ });
1180
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
1181
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
1182
+ x: position.x + this._ref.width(),
1183
+ y: position.y + this._ref.height()
1184
+ }));
1185
+ }));
1186
+ this._ref.on("dragend", (e => {
1187
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
1188
+ const position = absoluteTransform.point({
1189
+ x: this._ref.x(),
1190
+ y: this._ref.y()
1191
+ });
1192
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
1193
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
1194
+ x: position.x + this._ref.width(),
1195
+ y: position.y + this._ref.height()
1196
+ }));
1197
+ }));
709
1198
  this._ref.id(this._ref._id.toString());
710
1199
  }
711
1200
  getSrc() {
@@ -720,6 +1209,12 @@ class KonvaImage {
720
1209
  setWidth(w) {
721
1210
  this._ref.width(w);
722
1211
  this._ref.height(w * this._ratio);
1212
+ const rightLowerPoint = {
1213
+ x: this._ref.x() + w,
1214
+ y: this._ref.y() + this._ref.height()
1215
+ };
1216
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
1217
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
723
1218
  }
724
1219
  getHeight() {
725
1220
  return this._ref.height();
@@ -727,6 +1222,12 @@ class KonvaImage {
727
1222
  setHeight(h) {
728
1223
  this._ref.height(h);
729
1224
  this._ref.width(h / this._ratio);
1225
+ const rightLowerPoint = {
1226
+ x: this._ref.x() + this._ref.width(),
1227
+ y: this._ref.y() + h
1228
+ };
1229
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
1230
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
730
1231
  }
731
1232
  ref() {
732
1233
  return this._ref;
@@ -764,14 +1265,57 @@ class KonvaImage {
764
1265
  x: x,
765
1266
  y: y
766
1267
  });
1268
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
1269
+ x: x,
1270
+ y: y
1271
+ }));
1272
+ const rightLowerPoint = {
1273
+ x: x + this._ref.width(),
1274
+ y: y + this._ref.y()
1275
+ };
1276
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
1277
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
1278
+ }
1279
+ updateScreenCoordinates() {
1280
+ let screenPositionStart = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
1281
+ let screenPositionEnd = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));
1282
+ let invert = this._ref.getStage().getAbsoluteTransform().copy();
1283
+ invert = invert.invert();
1284
+ const positionStart = invert.point(screenPositionStart);
1285
+ const positionEnd = invert.point(screenPositionEnd);
1286
+ this._ref.position({
1287
+ x: positionStart.x,
1288
+ y: positionStart.y
1289
+ });
1290
+ this._ref.width(Math.abs(positionEnd.x - positionStart.x));
1291
+ this._ref.height(Math.abs(positionEnd.y - positionStart.y));
767
1292
  }
768
1293
  }
769
1294
 
770
1295
  class KonvaCloud {
771
- constructor(params, ref = null) {
1296
+ constructor(params, ref = null, worldTransformer = new WorldTransform) {
772
1297
  var _a, _b, _c, _d;
1298
+ this._worldTransformer = worldTransformer;
773
1299
  if (ref) {
774
1300
  this._ref = ref;
1301
+ const wcsStart = this._ref.getAttr("wcsStart");
1302
+ const wcsEnd = this._ref.getAttr("wcsEnd");
1303
+ if (!wcsStart) {
1304
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
1305
+ x: ref.x(),
1306
+ y: ref.y()
1307
+ }));
1308
+ }
1309
+ if (!wcsEnd) {
1310
+ const rightBottomPoint = {
1311
+ x: ref.x() + ref.width(),
1312
+ y: ref.y() + ref.height()
1313
+ };
1314
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
1315
+ x: rightBottomPoint.x,
1316
+ y: rightBottomPoint.y
1317
+ }));
1318
+ }
775
1319
  return;
776
1320
  }
777
1321
  if (!params) params = {};
@@ -779,7 +1323,25 @@ class KonvaCloud {
779
1323
  x: 0,
780
1324
  y: 0
781
1325
  };
782
- const arcRadius = 16;
1326
+ if (params.position2) {
1327
+ params.width = params.position2.x - params.position.x;
1328
+ params.height = params.position2.y - params.position.y;
1329
+ } else {
1330
+ if (!params.width || !params.height) {
1331
+ params.position2 = {
1332
+ x: 200,
1333
+ y: 200
1334
+ };
1335
+ params.width = 200;
1336
+ params.height = 200;
1337
+ } else {
1338
+ params.position2 = {
1339
+ x: params.position.x + params.width,
1340
+ y: params.position.y + params.height
1341
+ };
1342
+ }
1343
+ }
1344
+ const ARC_RADIUS = 16;
783
1345
  this._ref = new Konva.Shape({
784
1346
  x: params.position.x,
785
1347
  y: params.position.y,
@@ -838,9 +1400,9 @@ class KonvaCloud {
838
1400
  const counterClockwise = pX > midPoint.x && pY > midPoint.y;
839
1401
  for (let iArc = 0; iArc < arcCount; iArc++) {
840
1402
  if (counterClockwise) {
841
- context.arc(pX, pY, arcRadius, endAngle, startAngle);
1403
+ context.arc(pX, pY, ARC_RADIUS, endAngle, startAngle);
842
1404
  } else {
843
- context.arc(pX, pY, arcRadius, startAngle, endAngle);
1405
+ context.arc(pX, pY, ARC_RADIUS, startAngle, endAngle);
844
1406
  }
845
1407
  pX += dx / arcCount;
846
1408
  pY += dy / arcCount;
@@ -851,9 +1413,16 @@ class KonvaCloud {
851
1413
  }
852
1414
  });
853
1415
  this._ref.className = "Cloud";
1416
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
1417
+ x: params.position.x,
1418
+ y: params.position.y
1419
+ }));
1420
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
1421
+ x: params.position2.x,
1422
+ y: params.position2.y
1423
+ }));
854
1424
  this._ref.on("transform", (e => {
855
1425
  const attrs = e.target.attrs;
856
- if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
857
1426
  const scaleByX = Math.abs(attrs.scaleX - 1) > 1e-5;
858
1427
  const scaleByY = Math.abs(attrs.scaleY - 1) > 1e-5;
859
1428
  let newWidth = this._ref.width();
@@ -875,11 +1444,37 @@ class KonvaCloud {
875
1444
  y: 1
876
1445
  });
877
1446
  }));
1447
+ this._ref.on("transformend", (e => {
1448
+ const attrs = e.target.attrs;
1449
+ if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
1450
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
1451
+ const position = absoluteTransform.point({
1452
+ x: this._ref.x(),
1453
+ y: this._ref.y()
1454
+ });
1455
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
1456
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
1457
+ x: position.x + this._ref.width(),
1458
+ y: position.y + this._ref.height()
1459
+ }));
1460
+ }));
1461
+ this._ref.on("dragend", (e => {
1462
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
1463
+ const position = absoluteTransform.point({
1464
+ x: this._ref.x(),
1465
+ y: this._ref.y()
1466
+ });
1467
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
1468
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
1469
+ x: position.x + this._ref.width(),
1470
+ y: position.y + this._ref.height()
1471
+ }));
1472
+ }));
878
1473
  this._ref.getSelfRect = () => ({
879
- x: 0 - arcRadius,
880
- y: 0 - arcRadius,
881
- width: this._ref.width() + 2 * arcRadius,
882
- height: this._ref.height() + 2 * arcRadius
1474
+ x: 0 - ARC_RADIUS,
1475
+ y: 0 - ARC_RADIUS,
1476
+ width: this._ref.width() + 2 * ARC_RADIUS,
1477
+ height: this._ref.height() + 2 * ARC_RADIUS
883
1478
  });
884
1479
  this._ref.id(this._ref._id.toString());
885
1480
  }
@@ -925,18 +1520,40 @@ class KonvaCloud {
925
1520
  x: x,
926
1521
  y: y
927
1522
  });
1523
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
1524
+ x: x,
1525
+ y: y
1526
+ }));
1527
+ const rightLowerPoint = {
1528
+ x: x + this._ref.width(),
1529
+ y: y + this._ref.y()
1530
+ };
1531
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
1532
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
928
1533
  }
929
1534
  getWidth() {
930
1535
  return this._ref.width();
931
1536
  }
932
1537
  setWidth(w) {
933
1538
  this._ref.width(w);
1539
+ const rightLowerPoint = {
1540
+ x: this._ref.x() + w,
1541
+ y: this._ref.y() + this._ref.height()
1542
+ };
1543
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
1544
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
934
1545
  }
935
1546
  getHeigth() {
936
1547
  return this._ref.height();
937
1548
  }
938
1549
  setHeight(h) {
939
1550
  this._ref.height(h);
1551
+ const rightLowerPoint = {
1552
+ x: this._ref.x() + this._ref.width(),
1553
+ y: this._ref.y() + h
1554
+ };
1555
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
1556
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
940
1557
  }
941
1558
  getLineWidth() {
942
1559
  return this._ref.strokeWidth();
@@ -944,6 +1561,20 @@ class KonvaCloud {
944
1561
  setLineWidth(size) {
945
1562
  this._ref.strokeWidth(size);
946
1563
  }
1564
+ updateScreenCoordinates() {
1565
+ let screenPositionStart = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
1566
+ let screenPositionEnd = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));
1567
+ let invert = this._ref.getStage().getAbsoluteTransform().copy();
1568
+ invert = invert.invert();
1569
+ const positionStart = invert.point(screenPositionStart);
1570
+ const positionEnd = invert.point(screenPositionEnd);
1571
+ this._ref.position({
1572
+ x: positionStart.x,
1573
+ y: positionStart.y
1574
+ });
1575
+ this._ref.width(Math.abs(positionEnd.x - positionStart.x));
1576
+ this._ref.height(Math.abs(positionEnd.y - positionStart.y));
1577
+ }
947
1578
  }
948
1579
 
949
1580
  const MarkupMode2Konva = {
@@ -953,37 +1584,49 @@ const MarkupMode2Konva = {
953
1584
  },
954
1585
  Line: {
955
1586
  name: "Line",
956
- initializer: (ref, params = null) => new KonvaLine(params, ref)
1587
+ initializer: (ref, params = null, ...attr) => new KonvaLine(params, ref, ...attr)
957
1588
  },
958
1589
  Text: {
959
1590
  name: "Text",
960
- initializer: (ref, params = null) => new KonvaText(params, ref)
1591
+ initializer: (ref, params = null, ...attr) => new KonvaText(params, ref, ...attr)
961
1592
  },
962
1593
  Rectangle: {
963
1594
  name: "Rect",
964
- initializer: (ref, params = null) => new KonvaRectangle(params, ref)
1595
+ initializer: (ref, params = null, ...attr) => new KonvaRectangle(params, ref, ...attr)
965
1596
  },
966
1597
  Ellipse: {
967
1598
  name: "Ellipse",
968
- initializer: (ref, params = null) => new KonvaEllipse(params, ref)
1599
+ initializer: (ref, params = null, ...attr) => new KonvaEllipse(params, ref, ...attr)
969
1600
  },
970
1601
  Arrow: {
971
1602
  name: "Arrow",
972
- initializer: (ref, params = null) => new KonvaArrow(params, ref)
1603
+ initializer: (ref, params = null, ...attr) => new KonvaArrow(params, ref, ...attr)
973
1604
  },
974
1605
  Image: {
975
1606
  name: "Image",
976
- initializer: (ref, params = null) => new KonvaImage(params, ref)
1607
+ initializer: (ref, params = null, ...attr) => new KonvaImage(params, ref, ...attr)
977
1608
  },
978
1609
  Cloud: {
979
1610
  name: "Cloud",
980
- initializer: (ref, params = null) => new KonvaCloud(params, ref)
1611
+ initializer: (ref, params = null, ...attr) => new KonvaCloud(params, ref, ...attr)
981
1612
  }
982
1613
  };
983
1614
 
1615
+ function debounce(func, wait) {
1616
+ let timeout = null;
1617
+ return (...args) => {
1618
+ if (timeout) {
1619
+ clearTimeout(timeout);
1620
+ }
1621
+ timeout = setTimeout((() => {
1622
+ timeout = null;
1623
+ func(...args);
1624
+ }), wait);
1625
+ };
1626
+ }
1627
+
984
1628
  class KonvaMarkup {
985
1629
  constructor() {
986
- this._containerEvents = [];
987
1630
  this._markupIsActive = false;
988
1631
  this._markupColor = new MarkupColor(255, 0, 0);
989
1632
  this.lineWidth = 4;
@@ -1002,25 +1645,29 @@ class KonvaMarkup {
1002
1645
  if (!this._konvaStage) return;
1003
1646
  this._konvaStage.width(width);
1004
1647
  this._konvaStage.height(height);
1648
+ this.getObjects().forEach((markupObject => {
1649
+ markupObject.updateScreenCoordinates();
1650
+ }));
1651
+ };
1652
+ this.resizeViewer = event => {
1653
+ const {width: width, height: height} = event;
1654
+ if (!width || !height) return;
1655
+ if (!this._konvaStage) return;
1656
+ this._konvaStage.width(width);
1657
+ this._konvaStage.height(height);
1658
+ this.getObjects().forEach((markupObject => {
1659
+ markupObject.updateScreenCoordinates();
1660
+ }));
1005
1661
  };
1006
1662
  this.pan = event => {
1007
- const newPos = {
1008
- x: this._konvaStage.x() + event.dX,
1009
- y: this._konvaStage.y() + event.dY
1010
- };
1011
- this._konvaStage.position(newPos);
1663
+ this.getObjects().forEach((markupObject => {
1664
+ markupObject.updateScreenCoordinates();
1665
+ }));
1012
1666
  };
1013
1667
  this.zoomAt = event => {
1014
- const newScale = this._konvaStage.scaleX() * event.data;
1015
- this._konvaStage.scale({
1016
- x: newScale,
1017
- y: newScale
1018
- });
1019
- const newPos = {
1020
- x: event.x - (event.x - this._konvaStage.x()) * event.data,
1021
- y: event.y - (event.y - this._konvaStage.y()) * event.data
1022
- };
1023
- this._konvaStage.position(newPos);
1668
+ this.getObjects().forEach((markupObject => {
1669
+ markupObject.updateScreenCoordinates();
1670
+ }));
1024
1671
  };
1025
1672
  this.redirectToViewer = event => {
1026
1673
  if (this._viewer) this._viewer.emit(event);
@@ -1037,7 +1684,6 @@ class KonvaMarkup {
1037
1684
  this._viewer = viewer;
1038
1685
  this._worldTransformer = worldTransformer !== null && worldTransformer !== undefined ? worldTransformer : new WorldTransform;
1039
1686
  this._container = container;
1040
- this._containerEvents = containerEvents !== null && containerEvents !== undefined ? containerEvents : [];
1041
1687
  this._markupContainer = document.createElement("div");
1042
1688
  this._markupContainer.id = "markup-container";
1043
1689
  this._markupContainer.style.position = "absolute";
@@ -1047,8 +1693,7 @@ class KonvaMarkup {
1047
1693
  this._markupContainer.style.pointerEvents = "none";
1048
1694
  const parentDiv = this._container.parentElement;
1049
1695
  parentDiv.appendChild(this._markupContainer);
1050
- this._resizeObserver = new ResizeObserver(this.resizeContainer);
1051
- this._resizeObserver.observe(parentDiv);
1696
+ if (viewer) this._viewer.addEventListener("resize", this.resizeViewer); else this._resizeObserver = new ResizeObserver(debounce(this.resizeContainer, 100));
1052
1697
  this._markupColor.setColor(255, 0, 0);
1053
1698
  this.initializeKonva();
1054
1699
  if (this._viewer) {
@@ -1143,11 +1788,14 @@ class KonvaMarkup {
1143
1788
  }));
1144
1789
  (_d = viewpoint.rectangles) === null || _d === undefined ? undefined : _d.forEach((rect => {
1145
1790
  const screenPoint = this._worldTransformer.worldToScreen(rect.position);
1146
- this.addRectangle(screenPoint, rect.width, rect.height, rect.line_width, rect.color, rect.id);
1791
+ const screenPoint2 = rect.position2 ? this._worldTransformer.worldToScreen(rect.position2) : null;
1792
+ this.addRectangle(screenPoint, screenPoint2, rect.width, rect.height, rect.line_width, rect.color, rect.id);
1147
1793
  }));
1148
1794
  (_e = viewpoint.ellipses) === null || _e === undefined ? undefined : _e.forEach((ellipse => {
1149
1795
  const screenPoint = this._worldTransformer.worldToScreen(ellipse.position);
1150
- this.addEllipse(screenPoint, ellipse.radius, ellipse.line_width, ellipse.color, ellipse.id);
1796
+ const screenPoint2 = ellipse.position2 ? this._worldTransformer.worldToScreen(ellipse.position2) : null;
1797
+ const screenPoint3 = ellipse.position3 ? this._worldTransformer.worldToScreen(ellipse.position3) : null;
1798
+ this.addEllipse(screenPoint, screenPoint2, screenPoint3, ellipse.radius, ellipse.line_width, ellipse.color, ellipse.id);
1151
1799
  }));
1152
1800
  (_f = viewpoint.arrows) === null || _f === undefined ? undefined : _f.forEach((arrow => {
1153
1801
  const startPoint = this._worldTransformer.worldToScreen(arrow.start);
@@ -1156,11 +1804,13 @@ class KonvaMarkup {
1156
1804
  }));
1157
1805
  (_g = viewpoint.clouds) === null || _g === undefined ? undefined : _g.forEach((cloud => {
1158
1806
  const screenPoint = this._worldTransformer.worldToScreen(cloud.position);
1159
- this.addCloud(screenPoint, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
1807
+ const screenPoint2 = cloud.position2 ? this._worldTransformer.worldToScreen(cloud.position2) : null;
1808
+ this.addCloud(screenPoint, screenPoint2, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
1160
1809
  }));
1161
1810
  (_h = viewpoint.images) === null || _h === undefined ? undefined : _h.forEach((image => {
1162
1811
  const screenPoint = this._worldTransformer.worldToScreen(image.position);
1163
- this.addImage(screenPoint, image.src, image.width, image.height, image.id);
1812
+ const screenPoint2 = image.position2 ? this._worldTransformer.worldToScreen(image.position2) : null;
1813
+ this.addImage(screenPoint, screenPoint2, image.src, image.width, image.height, image.id);
1164
1814
  }));
1165
1815
  }
1166
1816
  getViewpoint(viewpoint) {
@@ -1197,7 +1847,7 @@ class KonvaMarkup {
1197
1847
  createObject(type, params) {
1198
1848
  const konvaShape = MarkupMode2Konva[type];
1199
1849
  if (!konvaShape || !konvaShape.initializer) throw new Error(`Markup CreateObject - unsupported markup type ${type}`);
1200
- const object = konvaShape.initializer(null, params);
1850
+ const object = konvaShape.initializer(null, params, this._worldTransformer);
1201
1851
  this.addObject(object);
1202
1852
  return object;
1203
1853
  }
@@ -1205,7 +1855,7 @@ class KonvaMarkup {
1205
1855
  const objects = [];
1206
1856
  Object.keys(MarkupMode2Konva).forEach((type => {
1207
1857
  const konvaShape = MarkupMode2Konva[type];
1208
- this.konvaLayerFind(type).forEach((ref => objects.push(konvaShape.initializer(ref))));
1858
+ this.konvaLayerFind(type).forEach((ref => objects.push(konvaShape.initializer(ref, null, this._worldTransformer))));
1209
1859
  }));
1210
1860
  return objects;
1211
1861
  }
@@ -1214,7 +1864,7 @@ class KonvaMarkup {
1214
1864
  return this._konvaTransformer.nodes().map((ref => {
1215
1865
  const name = ref.className;
1216
1866
  const konvaShape = Object.values(MarkupMode2Konva).find((shape => shape.name === name));
1217
- return konvaShape ? konvaShape.initializer(ref) : null;
1867
+ return konvaShape ? konvaShape.initializer(ref, null, this._worldTransformer) : null;
1218
1868
  })).filter((x => x));
1219
1869
  }
1220
1870
  selectObjects(objects) {
@@ -1290,12 +1940,12 @@ class KonvaMarkup {
1290
1940
  this.addRectangle({
1291
1941
  x: startX,
1292
1942
  y: startY
1293
- }, dX, dY);
1943
+ }, null, dX, dY);
1294
1944
  } else if (this._markupMode === "Ellipse") {
1295
1945
  this.addEllipse({
1296
1946
  x: startX,
1297
1947
  y: startY
1298
- }, {
1948
+ }, null, null, {
1299
1949
  x: dX / 2,
1300
1950
  y: dY / 2
1301
1951
  });
@@ -1311,7 +1961,7 @@ class KonvaMarkup {
1311
1961
  this.addCloud({
1312
1962
  x: startX,
1313
1963
  y: startY
1314
- }, Math.max(100, dX), Math.max(100, dY));
1964
+ }, null, Math.max(100, dX), Math.max(100, dY));
1315
1965
  }
1316
1966
  }
1317
1967
  }
@@ -1350,7 +2000,7 @@ class KonvaMarkup {
1350
2000
  } else lastObj = this.addRectangle({
1351
2001
  x: startX,
1352
2002
  y: startY
1353
- }, dX, dY);
2003
+ }, null, dX, dY);
1354
2004
  } else if (this._markupMode === "Ellipse") {
1355
2005
  if (lastObj) {
1356
2006
  lastObj.setPosition(startX, startY);
@@ -1359,7 +2009,7 @@ class KonvaMarkup {
1359
2009
  } else lastObj = this.addEllipse({
1360
2010
  x: startX,
1361
2011
  y: startY
1362
- }, {
2012
+ }, null, null, {
1363
2013
  x: dX,
1364
2014
  y: dY
1365
2015
  });
@@ -1371,7 +2021,7 @@ class KonvaMarkup {
1371
2021
  } else lastObj = this.addCloud({
1372
2022
  x: startX,
1373
2023
  y: startY
1374
- }, dX, dY);
2024
+ }, null, dX, dY);
1375
2025
  }
1376
2026
  }));
1377
2027
  stage.on("click tap", (e => {
@@ -1386,7 +2036,7 @@ class KonvaMarkup {
1386
2036
  if (this._imageInputRef && this._imageInputRef.value) this.addImage({
1387
2037
  x: this._imageInputPos.x,
1388
2038
  y: this._imageInputPos.y
1389
- }, this._imageInputRef.value, 0, 0, this._imageInputRef.value); else if (transformer.nodes().length === 0) {
2039
+ }, null, this._imageInputRef.value, 0, 0, this._imageInputRef.value); else if (transformer.nodes().length === 0) {
1390
2040
  const pos = this.getRelativePointerPosition(stage);
1391
2041
  this.createImageInput(pos);
1392
2042
  }
@@ -1407,7 +2057,7 @@ class KonvaMarkup {
1407
2057
  }
1408
2058
  if (this._markupMode === "Image" || this._markupMode === "SelectMarkup") {
1409
2059
  if (e.target.className === "Image" && transformer.nodes().length === 1 && transformer.nodes()[0] === e.target) {
1410
- if (this._imageInputRef && this._imageInputRef.value) this.addImage(this._imageInputPos, this._imageInputRef.value, 0, 0); else this.createImageInput({
2060
+ if (this._imageInputRef && this._imageInputRef.value) this.addImage(this._imageInputPos, null, this._imageInputRef.value, 0, 0); else this.createImageInput({
1411
2061
  x: e.target.attrs.x,
1412
2062
  y: e.target.attrs.y
1413
2063
  });
@@ -1463,22 +2113,12 @@ class KonvaMarkup {
1463
2113
  getMarkupLines() {
1464
2114
  const lines = [];
1465
2115
  this.konvaLayerFind("Line").forEach((ref => {
1466
- const linePoints = ref.points();
1467
- if (!linePoints) return;
1468
- const worldPoints = [];
1469
- const absoluteTransform = ref.getAbsoluteTransform();
1470
- for (let i = 0; i < linePoints.length; i += 2) {
1471
- const atPoint = absoluteTransform.point({
1472
- x: linePoints[i],
1473
- y: linePoints[i + 1]
1474
- });
1475
- const worldPoint = this._worldTransformer.screenToWorld(atPoint);
1476
- worldPoints.push(worldPoint);
1477
- }
1478
- const konvaLine = new KonvaLine(null, ref);
2116
+ const wcsPoints = ref.getAttr("wcsPoints");
2117
+ if (!wcsPoints) return;
2118
+ const konvaLine = new KonvaLine(null, ref, this._worldTransformer);
1479
2119
  const line = {
1480
2120
  id: konvaLine.id(),
1481
- points: worldPoints,
2121
+ points: wcsPoints,
1482
2122
  color: konvaLine.getColor() || "#ff0000",
1483
2123
  type: konvaLine.getLineType() || this.lineType,
1484
2124
  width: konvaLine.getLineWidth() || this.lineWidth
@@ -1492,17 +2132,12 @@ class KonvaMarkup {
1492
2132
  this.konvaLayerFind("Text").forEach((ref => {
1493
2133
  const textSize = .02;
1494
2134
  const textScale = this._worldTransformer.getScale();
1495
- const position = ref.position();
2135
+ const wcsPosition = ref.getAttr("wcsStart");
1496
2136
  const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
1497
- const atPoint = stageAbsoluteTransform.point({
1498
- x: position.x,
1499
- y: position.y
1500
- });
1501
- const worldPoint = this._worldTransformer.screenToWorld(atPoint);
1502
- const shape = new KonvaText(null, ref);
2137
+ const shape = new KonvaText(null, ref, this._worldTransformer);
1503
2138
  const text = {
1504
2139
  id: shape.id(),
1505
- position: worldPoint,
2140
+ position: wcsPosition,
1506
2141
  text: shape.getText(),
1507
2142
  text_size: textSize * textScale.y,
1508
2143
  angle: shape.getRotation(),
@@ -1516,20 +2151,17 @@ class KonvaMarkup {
1516
2151
  getMarkupRectangles() {
1517
2152
  const rectangles = [];
1518
2153
  this.konvaLayerFind("Rectangle").forEach((ref => {
1519
- const position = ref.position();
1520
- const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
1521
- const atPoint = stageAbsoluteTransform.point({
1522
- x: position.x,
1523
- y: position.y
1524
- });
1525
- const worldPoint = this._worldTransformer.screenToWorld(atPoint);
1526
- const scale = stageAbsoluteTransform.getMatrix()[0];
1527
- const shape = new KonvaRectangle(null, ref);
2154
+ const wcsStart = ref.getAttr("wcsStart");
2155
+ const wcsEnd = ref.getAttr("wcsEnd");
2156
+ const screenStart = this._worldTransformer.worldToScreen(wcsStart);
2157
+ const screenEnd = this._worldTransformer.worldToScreen(wcsEnd);
2158
+ const shape = new KonvaRectangle(null, ref, this._worldTransformer);
1528
2159
  const rectangle = {
1529
2160
  id: shape.id(),
1530
- position: worldPoint,
1531
- width: shape.getWidth() * scale,
1532
- height: shape.getHeigth() * scale,
2161
+ position: wcsStart,
2162
+ position2: wcsEnd,
2163
+ width: Math.abs(screenStart.x - screenEnd.x),
2164
+ height: Math.abs(screenStart.y - screenEnd.y),
1533
2165
  line_width: shape.getLineWidth(),
1534
2166
  color: shape.getColor()
1535
2167
  };
@@ -1540,18 +2172,17 @@ class KonvaMarkup {
1540
2172
  getMarkupEllipses() {
1541
2173
  const ellipses = [];
1542
2174
  this.konvaLayerFind("Ellipse").forEach((ref => {
1543
- const position = ref.position();
2175
+ const wcsPosition = ref.getAttr("wcsPosition");
2176
+ const wcsPosition2 = ref.getAttr("wcsRadiusX");
2177
+ const wcsPosition3 = ref.getAttr("wcsRadiusY");
1544
2178
  const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
1545
- const atPoint = stageAbsoluteTransform.point({
1546
- x: position.x,
1547
- y: position.y
1548
- });
1549
- const worldPoint = this._worldTransformer.screenToWorld(atPoint);
1550
2179
  const scale = stageAbsoluteTransform.getMatrix()[0];
1551
- const shape = new KonvaEllipse(null, ref);
2180
+ const shape = new KonvaEllipse(null, ref, this._worldTransformer);
1552
2181
  const ellipse = {
1553
2182
  id: shape.id(),
1554
- position: worldPoint,
2183
+ position: wcsPosition,
2184
+ position2: wcsPosition2,
2185
+ position3: wcsPosition3,
1555
2186
  radius: {
1556
2187
  x: ref.getRadiusX() * scale,
1557
2188
  y: ref.getRadiusY() * scale
@@ -1566,22 +2197,13 @@ class KonvaMarkup {
1566
2197
  getMarkupArrows() {
1567
2198
  const arrows = [];
1568
2199
  this.konvaLayerFind("Arrow").forEach((ref => {
1569
- const absoluteTransform = ref.getAbsoluteTransform();
1570
- const atStartPoint = absoluteTransform.point({
1571
- x: ref.points()[0],
1572
- y: ref.points()[1]
1573
- });
1574
- const worldStartPoint = this._worldTransformer.screenToWorld(atStartPoint);
1575
- const atEndPoint = absoluteTransform.point({
1576
- x: ref.points()[2],
1577
- y: ref.points()[3]
1578
- });
1579
- const worldEndPoint = this._worldTransformer.screenToWorld(atEndPoint);
1580
- const shape = new KonvaArrow(null, ref);
2200
+ const wcsStart = ref.getAttr("wcsStart");
2201
+ const wcsEnd = ref.getAttr("wcsEnd");
2202
+ const shape = new KonvaArrow(null, ref, this._worldTransformer);
1581
2203
  const arrow = {
1582
2204
  id: shape.id(),
1583
- start: worldStartPoint,
1584
- end: worldEndPoint,
2205
+ start: wcsStart,
2206
+ end: wcsEnd,
1585
2207
  color: shape.getColor()
1586
2208
  };
1587
2209
  arrows.push(arrow);
@@ -1591,18 +2213,15 @@ class KonvaMarkup {
1591
2213
  getMarkupImages() {
1592
2214
  const images = [];
1593
2215
  this.konvaLayerFind("Image").forEach((ref => {
1594
- const position = ref.position();
2216
+ const wcsStart = ref.getAttr("wcsStart");
2217
+ const wcsEnd = ref.getAttr("wcsEnd");
1595
2218
  const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
1596
- const atPoint = stageAbsoluteTransform.point({
1597
- x: position.x,
1598
- y: position.y
1599
- });
1600
- const worldPoint = this._worldTransformer.screenToWorld(atPoint);
1601
2219
  const scale = stageAbsoluteTransform.getMatrix()[0];
1602
- const shape = new KonvaImage(null, ref);
2220
+ const shape = new KonvaImage(null, ref, this._worldTransformer);
1603
2221
  const image = {
1604
2222
  id: shape.id(),
1605
- position: worldPoint,
2223
+ position: wcsStart,
2224
+ position2: wcsEnd,
1606
2225
  src: shape.getSrc(),
1607
2226
  width: shape.getWidth() * scale,
1608
2227
  height: shape.getHeight() * scale
@@ -1614,20 +2233,17 @@ class KonvaMarkup {
1614
2233
  getMarkupClouds() {
1615
2234
  const clouds = [];
1616
2235
  this.konvaLayerFind("Cloud").forEach((ref => {
1617
- const position = ref.position();
1618
- const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
1619
- const atPoint = stageAbsoluteTransform.point({
1620
- x: position.x,
1621
- y: position.y
1622
- });
1623
- const worldPoint = this._worldTransformer.screenToWorld(atPoint);
1624
- const scale = stageAbsoluteTransform.getMatrix()[0];
1625
- const shape = new KonvaCloud(null, ref);
2236
+ const wcsStart = ref.getAttr("wcsStart");
2237
+ const wcsEnd = ref.getAttr("wcsEnd");
2238
+ const screenStart = this._worldTransformer.worldToScreen(wcsStart);
2239
+ const screenEnd = this._worldTransformer.worldToScreen(wcsEnd);
2240
+ const shape = new KonvaCloud(null, ref, this._worldTransformer);
1626
2241
  const cloud = {
1627
2242
  id: shape.id(),
1628
- position: worldPoint,
1629
- width: shape.getWidth() * scale,
1630
- height: shape.getHeigth() * scale,
2243
+ position: wcsStart,
2244
+ position2: wcsEnd,
2245
+ width: Math.abs(screenStart.x - screenEnd.x),
2246
+ height: Math.abs(screenStart.y - screenEnd.y),
1631
2247
  line_width: shape.getLineWidth(),
1632
2248
  color: shape.getColor()
1633
2249
  };
@@ -1664,7 +2280,7 @@ class KonvaMarkup {
1664
2280
  width: width || this.lineWidth,
1665
2281
  color: color || this._markupColor.asHex(),
1666
2282
  id: id
1667
- });
2283
+ }, null, this._worldTransformer);
1668
2284
  this.addObject(konvaLine);
1669
2285
  return konvaLine;
1670
2286
  }
@@ -1730,7 +2346,7 @@ class KonvaMarkup {
1730
2346
  this.addImage({
1731
2347
  x: this._imageInputPos.x,
1732
2348
  y: this._imageInputPos.y
1733
- }, base64.toString(), 0, 0);
2349
+ }, null, base64.toString(), 0, 0);
1734
2350
  };
1735
2351
  this._imageInputRef.oncancel = event => {
1736
2352
  this.removeImageInput();
@@ -1771,32 +2387,35 @@ class KonvaMarkup {
1771
2387
  fontSize: fontSize || this.fontSize,
1772
2388
  color: color || this._markupColor.asHex(),
1773
2389
  id: id
1774
- });
2390
+ }, null, this._worldTransformer);
1775
2391
  this.addObject(konvaText);
1776
2392
  return konvaText;
1777
2393
  }
1778
- addRectangle(position, width, height, lineWidth, color, id) {
2394
+ addRectangle(position, position2, width, height, lineWidth, color, id) {
1779
2395
  if (!position) return;
1780
2396
  const konvaRectangle = new KonvaRectangle({
1781
2397
  position: position,
2398
+ position2: position2,
1782
2399
  width: width,
1783
2400
  height: height,
1784
2401
  lineWidth: lineWidth || this.lineWidth,
1785
2402
  color: color || this._markupColor.asHex(),
1786
2403
  id: id
1787
- });
2404
+ }, null, this._worldTransformer);
1788
2405
  this.addObject(konvaRectangle);
1789
2406
  return konvaRectangle;
1790
2407
  }
1791
- addEllipse(position, radius, lineWidth, color, id) {
2408
+ addEllipse(position, position2, position3, radius, lineWidth, color, id) {
1792
2409
  if (!position) return;
1793
2410
  const konvaEllipse = new KonvaEllipse({
1794
2411
  position: position,
2412
+ position2: position2,
2413
+ position3: position3,
1795
2414
  radius: radius,
1796
2415
  lineWidth: lineWidth,
1797
2416
  color: color || this._markupColor.asHex(),
1798
2417
  id: id
1799
- });
2418
+ }, null, this._worldTransformer);
1800
2419
  this.addObject(konvaEllipse);
1801
2420
  return konvaEllipse;
1802
2421
  }
@@ -1807,24 +2426,25 @@ class KonvaMarkup {
1807
2426
  end: end,
1808
2427
  color: color || this._markupColor.asHex(),
1809
2428
  id: id
1810
- });
2429
+ }, null, this._worldTransformer);
1811
2430
  this.addObject(konvaArrow);
1812
2431
  return konvaArrow;
1813
2432
  }
1814
- addCloud(position, width, height, lineWidth, color, id) {
2433
+ addCloud(position, position2, width, height, lineWidth, color, id) {
1815
2434
  if (!position || !width || !height) return;
1816
2435
  const konvaCloud = new KonvaCloud({
1817
2436
  position: position,
2437
+ position2: position2,
1818
2438
  width: width,
1819
2439
  height: height,
1820
2440
  color: color || this._markupColor.asHex(),
1821
2441
  lineWidth: lineWidth || this.lineWidth,
1822
2442
  id: id
1823
- });
2443
+ }, null, this._worldTransformer);
1824
2444
  this.addObject(konvaCloud);
1825
2445
  return konvaCloud;
1826
2446
  }
1827
- addImage(position, src, width, height, id) {
2447
+ addImage(position, position2, src, width, height, id) {
1828
2448
  var _a;
1829
2449
  if (!position || !src) return;
1830
2450
  (_a = this.getSelectedObjects().at(0)) === null || _a === undefined ? undefined : _a.delete();
@@ -1832,13 +2452,14 @@ class KonvaMarkup {
1832
2452
  this.removeImageInput();
1833
2453
  const konvaImage = new KonvaImage({
1834
2454
  position: position,
2455
+ position2: position2,
1835
2456
  src: src,
1836
2457
  width: width,
1837
2458
  height: height,
1838
2459
  maxWidth: this._konvaStage.width() - position.x,
1839
2460
  maxHeight: this._konvaStage.height() - position.y,
1840
2461
  id: id
1841
- });
2462
+ }, null, this._worldTransformer);
1842
2463
  this.addObject(konvaImage);
1843
2464
  return konvaImage;
1844
2465
  }