@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
@@ -35,6 +35,7 @@ import {
35
35
  IViewpoint,
36
36
  PanEvent,
37
37
  ZoomAtEvent,
38
+ ResizeEvent,
38
39
  } from "@inweb/viewer-core";
39
40
 
40
41
  import { IMarkup, MarkupMode } from "../IMarkup";
@@ -58,34 +59,47 @@ const MarkupMode2Konva = {
58
59
  },
59
60
  Line: {
60
61
  name: "Line",
61
- initializer: (ref: any, params = null) => new KonvaLine(params, ref),
62
+ initializer: (ref: any, params = null, ...attr: any) => new KonvaLine(params, ref, ...attr),
62
63
  },
63
64
  Text: {
64
65
  name: "Text",
65
- initializer: (ref: any, params = null) => new KonvaText(params, ref),
66
+ initializer: (ref: any, params = null, ...attr: any) => new KonvaText(params, ref, ...attr),
66
67
  },
67
68
  Rectangle: {
68
69
  name: "Rect",
69
- initializer: (ref: any, params = null) => new KonvaRectangle(params, ref),
70
+ initializer: (ref: any, params = null, ...attr: any) => new KonvaRectangle(params, ref, ...attr),
70
71
  },
71
72
  Ellipse: {
72
73
  name: "Ellipse",
73
- initializer: (ref: any, params = null) => new KonvaEllipse(params, ref),
74
+ initializer: (ref: any, params = null, ...attr: any) => new KonvaEllipse(params, ref, ...attr),
74
75
  },
75
76
  Arrow: {
76
77
  name: "Arrow",
77
- initializer: (ref: any, params = null) => new KonvaArrow(params, ref),
78
+ initializer: (ref: any, params = null, ...attr: any) => new KonvaArrow(params, ref, ...attr),
78
79
  },
79
80
  Image: {
80
81
  name: "Image",
81
- initializer: (ref: any, params = null) => new KonvaImage(params, ref),
82
+ initializer: (ref: any, params = null, ...attr: any) => new KonvaImage(params, ref, ...attr),
82
83
  },
83
84
  Cloud: {
84
85
  name: "Cloud",
85
- initializer: (ref: any, params = null) => new KonvaCloud(params, ref),
86
+ initializer: (ref: any, params = null, ...attr: any) => new KonvaCloud(params, ref, ...attr),
86
87
  },
87
88
  };
88
89
 
90
+ function debounce(func, wait: number) {
91
+ let timeout = null;
92
+ return (...args) => {
93
+ if (timeout) {
94
+ clearTimeout(timeout);
95
+ }
96
+ timeout = setTimeout(() => {
97
+ timeout = null;
98
+ func(...args);
99
+ }, wait);
100
+ };
101
+ }
102
+
89
103
  /**
90
104
  * 2D markup core.
91
105
  */
@@ -93,7 +107,6 @@ export class KonvaMarkup implements IMarkup {
93
107
  private _viewer: IEventEmitter;
94
108
  private _worldTransformer: IWorldTransform;
95
109
  private _container: HTMLElement;
96
- private _containerEvents: string[] = [];
97
110
  private _markupIsActive = false;
98
111
  private _markupMode: MarkupMode;
99
112
  private _markupColor = new MarkupColor(255, 0, 0);
@@ -130,7 +143,6 @@ export class KonvaMarkup implements IMarkup {
130
143
  this._viewer = viewer;
131
144
  this._worldTransformer = worldTransformer ?? new WorldTransform();
132
145
  this._container = container;
133
- this._containerEvents = containerEvents ?? [];
134
146
 
135
147
  this._markupContainer = document.createElement("div");
136
148
  this._markupContainer.id = "markup-container";
@@ -143,15 +155,14 @@ export class KonvaMarkup implements IMarkup {
143
155
  const parentDiv = this._container.parentElement;
144
156
  parentDiv.appendChild(this._markupContainer);
145
157
 
146
- this._resizeObserver = new ResizeObserver(this.resizeContainer);
147
- this._resizeObserver.observe(parentDiv);
158
+ if (viewer) this._viewer.addEventListener("resize", this.resizeViewer);
159
+ else this._resizeObserver = new ResizeObserver(debounce(this.resizeContainer, 100));
148
160
 
149
161
  this._markupColor.setColor(255, 0, 0);
150
162
 
151
163
  this.initializeKonva();
152
164
 
153
165
  if (this._viewer) {
154
- // this._containerEvents.forEach((x) => this._markupContainer.addEventListener(x, this.redirectToViewer));
155
166
  this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
156
167
  this._viewer.addEventListener("pan", this.pan);
157
168
  this._viewer.addEventListener("zoomat", this.zoomAt);
@@ -163,7 +174,6 @@ export class KonvaMarkup implements IMarkup {
163
174
  this._viewer.removeEventListener("zoomat", this.zoomAt);
164
175
  this._viewer.removeEventListener("pan", this.pan);
165
176
  this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
166
- // this._containerEvents.forEach((x) => this._markupContainer.removeEventListener(x, this.redirectToViewer));
167
177
  }
168
178
 
169
179
  this.destroyKonva();
@@ -205,25 +215,36 @@ export class KonvaMarkup implements IMarkup {
205
215
 
206
216
  this._konvaStage.width(width);
207
217
  this._konvaStage.height(height);
218
+
219
+ this.getObjects().forEach((markupObject) => {
220
+ markupObject.updateScreenCoordinates();
221
+ });
222
+ };
223
+
224
+ resizeViewer = (event: ResizeEvent) => {
225
+ const { width, height } = event;
226
+
227
+ if (!width || !height) return; // <- invisible container, or container with parent removed
228
+ if (!this._konvaStage) return;
229
+
230
+ this._konvaStage.width(width);
231
+ this._konvaStage.height(height);
232
+
233
+ this.getObjects().forEach((markupObject) => {
234
+ markupObject.updateScreenCoordinates();
235
+ });
208
236
  };
209
237
 
210
238
  pan = (event: PanEvent) => {
211
- const newPos = {
212
- x: this._konvaStage.x() + event.dX,
213
- y: this._konvaStage.y() + event.dY,
214
- };
215
- this._konvaStage.position(newPos);
239
+ this.getObjects().forEach((markupObject) => {
240
+ markupObject.updateScreenCoordinates();
241
+ });
216
242
  };
217
243
 
218
244
  zoomAt = (event: ZoomAtEvent) => {
219
- const newScale = this._konvaStage.scaleX() * event.data;
220
- this._konvaStage.scale({ x: newScale, y: newScale });
221
-
222
- const newPos = {
223
- x: event.x - (event.x - this._konvaStage.x()) * event.data,
224
- y: event.y - (event.y - this._konvaStage.y()) * event.data,
225
- };
226
- this._konvaStage.position(newPos);
245
+ this.getObjects().forEach((markupObject) => {
246
+ markupObject.updateScreenCoordinates();
247
+ });
227
248
  };
228
249
 
229
250
  redirectToViewer = (event: any) => {
@@ -285,12 +306,23 @@ export class KonvaMarkup implements IMarkup {
285
306
 
286
307
  viewpoint.rectangles?.forEach((rect: IRectangle) => {
287
308
  const screenPoint = this._worldTransformer.worldToScreen(rect.position);
288
- this.addRectangle(screenPoint, rect.width, rect.height, rect.line_width, rect.color, rect.id);
309
+ const screenPoint2 = rect.position2 ? this._worldTransformer.worldToScreen(rect.position2) : null;
310
+ this.addRectangle(screenPoint, screenPoint2, rect.width, rect.height, rect.line_width, rect.color, rect.id);
289
311
  });
290
312
 
291
313
  viewpoint.ellipses?.forEach((ellipse: IEllipse) => {
292
314
  const screenPoint = this._worldTransformer.worldToScreen(ellipse.position);
293
- this.addEllipse(screenPoint, ellipse.radius, ellipse.line_width, ellipse.color, ellipse.id);
315
+ const screenPoint2 = ellipse.position2 ? this._worldTransformer.worldToScreen(ellipse.position2) : null;
316
+ const screenPoint3 = ellipse.position3 ? this._worldTransformer.worldToScreen(ellipse.position3) : null;
317
+ this.addEllipse(
318
+ screenPoint,
319
+ screenPoint2,
320
+ screenPoint3,
321
+ ellipse.radius,
322
+ ellipse.line_width,
323
+ ellipse.color,
324
+ ellipse.id
325
+ );
294
326
  });
295
327
 
296
328
  viewpoint.arrows?.forEach((arrow: IArrow) => {
@@ -301,12 +333,14 @@ export class KonvaMarkup implements IMarkup {
301
333
 
302
334
  viewpoint.clouds?.forEach((cloud: ICloud) => {
303
335
  const screenPoint = this._worldTransformer.worldToScreen(cloud.position);
304
- this.addCloud(screenPoint, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
336
+ const screenPoint2 = cloud.position2 ? this._worldTransformer.worldToScreen(cloud.position2) : null;
337
+ this.addCloud(screenPoint, screenPoint2, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
305
338
  });
306
339
 
307
340
  viewpoint.images?.forEach((image: IImage) => {
308
341
  const screenPoint = this._worldTransformer.worldToScreen(image.position);
309
- this.addImage(screenPoint, image.src, image.width, image.height, image.id);
342
+ const screenPoint2 = image.position2 ? this._worldTransformer.worldToScreen(image.position2) : null;
343
+ this.addImage(screenPoint, screenPoint2, image.src, image.width, image.height, image.id);
310
344
  });
311
345
  }
312
346
 
@@ -347,7 +381,7 @@ export class KonvaMarkup implements IMarkup {
347
381
  if (!konvaShape || !konvaShape.initializer)
348
382
  throw new Error(`Markup CreateObject - unsupported markup type ${type}`);
349
383
 
350
- const object = konvaShape.initializer(null, params);
384
+ const object = konvaShape.initializer(null, params, this._worldTransformer);
351
385
  this.addObject(object);
352
386
 
353
387
  return object;
@@ -357,7 +391,9 @@ export class KonvaMarkup implements IMarkup {
357
391
  const objects = [];
358
392
  Object.keys(MarkupMode2Konva).forEach((type) => {
359
393
  const konvaShape = MarkupMode2Konva[type];
360
- this.konvaLayerFind(type).forEach((ref) => objects.push(konvaShape.initializer(ref)));
394
+ this.konvaLayerFind(type).forEach((ref) =>
395
+ objects.push(konvaShape.initializer(ref, null, this._worldTransformer))
396
+ );
361
397
  });
362
398
  return objects;
363
399
  }
@@ -370,7 +406,7 @@ export class KonvaMarkup implements IMarkup {
370
406
  .map((ref) => {
371
407
  const name = ref.className;
372
408
  const konvaShape = Object.values(MarkupMode2Konva).find((shape) => shape.name === name);
373
- return konvaShape ? konvaShape.initializer(ref) : null;
409
+ return konvaShape ? konvaShape.initializer(ref, null, this._worldTransformer) : null;
374
410
  })
375
411
  .filter((x) => x);
376
412
  }
@@ -490,16 +526,16 @@ export class KonvaMarkup implements IMarkup {
490
526
  const dY = defParams ? 200 : Math.abs(mouseDownPos.y - pos.y);
491
527
  if (defParams) {
492
528
  if (this._markupMode === "Rectangle") {
493
- this.addRectangle({ x: startX, y: startY }, dX, dY);
529
+ this.addRectangle({ x: startX, y: startY }, null, dX, dY);
494
530
  } else if (this._markupMode === "Ellipse") {
495
- this.addEllipse({ x: startX, y: startY }, { x: dX / 2, y: dY / 2 });
531
+ this.addEllipse({ x: startX, y: startY }, null, null, { x: dX / 2, y: dY / 2 });
496
532
  } else if (this._markupMode === "Arrow") {
497
533
  this.addArrow(
498
534
  { x: mouseDownPos.x, y: mouseDownPos.y },
499
535
  { x: defParams ? mouseDownPos.x + 200 : pos.x, y: defParams ? startY : pos.y }
500
536
  );
501
537
  } else if (this._markupMode === "Cloud") {
502
- this.addCloud({ x: startX, y: startY }, Math.max(100, dX), Math.max(100, dY));
538
+ this.addCloud({ x: startX, y: startY }, null, Math.max(100, dX), Math.max(100, dY));
503
539
  }
504
540
  }
505
541
  }
@@ -534,19 +570,19 @@ export class KonvaMarkup implements IMarkup {
534
570
  lastObj.setPosition(startX, startY);
535
571
  lastObj.setWidth(dX);
536
572
  lastObj.setHeight(dY);
537
- } else lastObj = this.addRectangle({ x: startX, y: startY }, dX, dY);
573
+ } else lastObj = this.addRectangle({ x: startX, y: startY }, null, dX, dY);
538
574
  } else if (this._markupMode === "Ellipse") {
539
575
  if (lastObj) {
540
576
  lastObj.setPosition(startX, startY);
541
577
  lastObj.setRadiusX(dX);
542
578
  lastObj.setRadiusY(dY);
543
- } else lastObj = this.addEllipse({ x: startX, y: startY }, { x: dX, y: dY });
579
+ } else lastObj = this.addEllipse({ x: startX, y: startY }, null, null, { x: dX, y: dY });
544
580
  } else if (this._markupMode === "Cloud") {
545
581
  if (lastObj) {
546
582
  lastObj.setPosition(startX, startY);
547
583
  lastObj.setWidth(Math.max(100, dX));
548
584
  lastObj.setHeight(Math.max(100, dY));
549
- } else lastObj = this.addCloud({ x: startX, y: startY }, dX, dY);
585
+ } else lastObj = this.addCloud({ x: startX, y: startY }, null, dX, dY);
550
586
  }
551
587
  });
552
588
 
@@ -567,6 +603,7 @@ export class KonvaMarkup implements IMarkup {
567
603
  if (this._imageInputRef && this._imageInputRef.value)
568
604
  this.addImage(
569
605
  { x: this._imageInputPos.x, y: this._imageInputPos.y },
606
+ null,
570
607
  this._imageInputRef.value,
571
608
  0,
572
609
  0,
@@ -602,7 +639,7 @@ export class KonvaMarkup implements IMarkup {
602
639
  if (this._markupMode === "Image" || this._markupMode === "SelectMarkup") {
603
640
  if (e.target.className === "Image" && transformer.nodes().length === 1 && transformer.nodes()[0] === e.target) {
604
641
  if (this._imageInputRef && this._imageInputRef.value)
605
- this.addImage(this._imageInputPos, this._imageInputRef.value, 0, 0);
642
+ this.addImage(this._imageInputPos, null, this._imageInputRef.value, 0, 0);
606
643
  else this.createImageInput({ x: e.target.attrs.x, y: e.target.attrs.y });
607
644
  return;
608
645
  } else {
@@ -678,27 +715,13 @@ export class KonvaMarkup implements IMarkup {
678
715
  const lines = [];
679
716
 
680
717
  this.konvaLayerFind("Line").forEach((ref) => {
681
- const linePoints = ref.points();
682
- if (!linePoints) return;
683
-
684
- const worldPoints = [];
685
- const absoluteTransform = ref.getAbsoluteTransform();
686
- for (let i = 0; i < linePoints.length; i += 2) {
687
- // we need getAbsoluteTransform because inside Konva position starts from {0, 0}
688
- // https://stackoverflow.com/a/57641487 - check answer's comments
689
- const atPoint = absoluteTransform.point({
690
- x: linePoints[i],
691
- y: linePoints[i + 1],
692
- });
693
- const worldPoint = this._worldTransformer.screenToWorld(atPoint);
694
-
695
- worldPoints.push(worldPoint);
696
- }
718
+ const wcsPoints = ref.getAttr("wcsPoints");
719
+ if (!wcsPoints) return;
697
720
 
698
- const konvaLine = new KonvaLine(null, ref);
721
+ const konvaLine = new KonvaLine(null, ref, this._worldTransformer);
699
722
  const line: ILine = {
700
723
  id: konvaLine.id(),
701
- points: worldPoints,
724
+ points: wcsPoints,
702
725
  color: konvaLine.getColor() || "#ff0000",
703
726
  type: konvaLine.getLineType() || this.lineType,
704
727
  width: konvaLine.getLineWidth() || this.lineWidth,
@@ -717,16 +740,13 @@ export class KonvaMarkup implements IMarkup {
717
740
  const textSize = 0.02;
718
741
  const textScale = this._worldTransformer.getScale();
719
742
 
720
- const position = ref.position();
743
+ const wcsPosition = ref.getAttr("wcsStart");
721
744
  const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
722
- const atPoint = stageAbsoluteTransform.point({ x: position.x, y: position.y });
723
745
 
724
- const worldPoint = this._worldTransformer.screenToWorld(atPoint);
725
-
726
- const shape = new KonvaText(null, ref);
746
+ const shape = new KonvaText(null, ref, this._worldTransformer);
727
747
  const text: IText = {
728
748
  id: shape.id(),
729
- position: worldPoint,
749
+ position: wcsPosition,
730
750
  text: shape.getText(),
731
751
  text_size: textSize * textScale.y,
732
752
  angle: shape.getRotation(),
@@ -744,18 +764,18 @@ export class KonvaMarkup implements IMarkup {
744
764
  const rectangles = [];
745
765
 
746
766
  this.konvaLayerFind("Rectangle").forEach((ref) => {
747
- const position = ref.position();
748
- const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
749
- const atPoint = stageAbsoluteTransform.point({ x: position.x, y: position.y });
750
- const worldPoint = this._worldTransformer.screenToWorld(atPoint);
751
- const scale = stageAbsoluteTransform.getMatrix()[0];
767
+ const wcsStart = ref.getAttr("wcsStart");
768
+ const wcsEnd = ref.getAttr("wcsEnd");
769
+ const screenStart = this._worldTransformer.worldToScreen(wcsStart);
770
+ const screenEnd = this._worldTransformer.worldToScreen(wcsEnd);
752
771
 
753
- const shape = new KonvaRectangle(null, ref);
772
+ const shape = new KonvaRectangle(null, ref, this._worldTransformer);
754
773
  const rectangle: IRectangle = {
755
774
  id: shape.id(),
756
- position: worldPoint,
757
- width: shape.getWidth() * scale,
758
- height: shape.getHeigth() * scale,
775
+ position: wcsStart,
776
+ position2: wcsEnd,
777
+ width: Math.abs(screenStart.x - screenEnd.x),
778
+ height: Math.abs(screenStart.y - screenEnd.y),
759
779
  line_width: shape.getLineWidth(),
760
780
  color: shape.getColor(),
761
781
  };
@@ -770,16 +790,18 @@ export class KonvaMarkup implements IMarkup {
770
790
  const ellipses = [];
771
791
 
772
792
  this.konvaLayerFind("Ellipse").forEach((ref) => {
773
- const position = ref.position();
793
+ const wcsPosition = ref.getAttr("wcsPosition");
794
+ const wcsPosition2 = ref.getAttr("wcsRadiusX");
795
+ const wcsPosition3 = ref.getAttr("wcsRadiusY");
774
796
  const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
775
- const atPoint = stageAbsoluteTransform.point({ x: position.x, y: position.y });
776
- const worldPoint = this._worldTransformer.screenToWorld(atPoint);
777
797
  const scale = stageAbsoluteTransform.getMatrix()[0];
778
798
 
779
- const shape = new KonvaEllipse(null, ref);
799
+ const shape = new KonvaEllipse(null, ref, this._worldTransformer);
780
800
  const ellipse: IEllipse = {
781
801
  id: shape.id(),
782
- position: worldPoint,
802
+ position: wcsPosition,
803
+ position2: wcsPosition2,
804
+ position3: wcsPosition3,
783
805
  radius: {
784
806
  x: ref.getRadiusX() * scale,
785
807
  y: ref.getRadiusY() * scale,
@@ -799,25 +821,14 @@ export class KonvaMarkup implements IMarkup {
799
821
 
800
822
  this.konvaLayerFind("Arrow").forEach((ref) => {
801
823
  // we need getAbsoluteTransform because inside Konva position starts from {0, 0}
802
- const absoluteTransform = ref.getAbsoluteTransform();
803
-
804
- const atStartPoint = absoluteTransform.point({
805
- x: ref.points()[0],
806
- y: ref.points()[1],
807
- });
808
- const worldStartPoint = this._worldTransformer.screenToWorld(atStartPoint);
824
+ const wcsStart = ref.getAttr("wcsStart");
825
+ const wcsEnd = ref.getAttr("wcsEnd");
809
826
 
810
- const atEndPoint = absoluteTransform.point({
811
- x: ref.points()[2],
812
- y: ref.points()[3],
813
- });
814
- const worldEndPoint = this._worldTransformer.screenToWorld(atEndPoint);
815
-
816
- const shape = new KonvaArrow(null, ref);
827
+ const shape = new KonvaArrow(null, ref, this._worldTransformer);
817
828
  const arrow: IArrow = {
818
829
  id: shape.id(),
819
- start: worldStartPoint,
820
- end: worldEndPoint,
830
+ start: wcsStart,
831
+ end: wcsEnd,
821
832
  color: shape.getColor(),
822
833
  };
823
834
 
@@ -831,16 +842,16 @@ export class KonvaMarkup implements IMarkup {
831
842
  const images = [];
832
843
 
833
844
  this.konvaLayerFind("Image").forEach((ref) => {
834
- const position = ref.position();
845
+ const wcsStart = ref.getAttr("wcsStart");
846
+ const wcsEnd = ref.getAttr("wcsEnd");
835
847
  const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
836
- const atPoint = stageAbsoluteTransform.point({ x: position.x, y: position.y });
837
- const worldPoint = this._worldTransformer.screenToWorld(atPoint);
838
848
  const scale = stageAbsoluteTransform.getMatrix()[0];
839
849
 
840
- const shape = new KonvaImage(null, ref);
850
+ const shape = new KonvaImage(null, ref, this._worldTransformer);
841
851
  const image: IImage = {
842
852
  id: shape.id(),
843
- position: worldPoint,
853
+ position: wcsStart,
854
+ position2: wcsEnd,
844
855
  src: shape.getSrc(),
845
856
  width: shape.getWidth() * scale,
846
857
  height: shape.getHeight() * scale,
@@ -856,18 +867,18 @@ export class KonvaMarkup implements IMarkup {
856
867
  const clouds = [];
857
868
 
858
869
  this.konvaLayerFind("Cloud").forEach((ref) => {
859
- const position = ref.position();
860
- const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
861
- const atPoint = stageAbsoluteTransform.point({ x: position.x, y: position.y });
862
- const worldPoint = this._worldTransformer.screenToWorld(atPoint);
863
- const scale = stageAbsoluteTransform.getMatrix()[0];
870
+ const wcsStart = ref.getAttr("wcsStart");
871
+ const wcsEnd = ref.getAttr("wcsEnd");
872
+ const screenStart = this._worldTransformer.worldToScreen(wcsStart);
873
+ const screenEnd = this._worldTransformer.worldToScreen(wcsEnd);
864
874
 
865
- const shape = new KonvaCloud(null, ref);
875
+ const shape = new KonvaCloud(null, ref, this._worldTransformer);
866
876
  const cloud: ICloud = {
867
877
  id: shape.id(),
868
- position: worldPoint,
869
- width: shape.getWidth() * scale,
870
- height: shape.getHeigth() * scale,
878
+ position: wcsStart,
879
+ position2: wcsEnd,
880
+ width: Math.abs(screenStart.x - screenEnd.x),
881
+ height: Math.abs(screenStart.y - screenEnd.y),
871
882
  line_width: shape.getLineWidth(),
872
883
  color: shape.getColor(),
873
884
  };
@@ -908,13 +919,17 @@ export class KonvaMarkup implements IMarkup {
908
919
  points.push({ x: linePoints[i], y: linePoints[i + 1] });
909
920
  }
910
921
 
911
- const konvaLine = new KonvaLine({
912
- points,
913
- type: type || this.lineType,
914
- width: width || this.lineWidth,
915
- color: color || this._markupColor.asHex(),
916
- id,
917
- });
922
+ const konvaLine = new KonvaLine(
923
+ {
924
+ points,
925
+ type: type || this.lineType,
926
+ width: width || this.lineWidth,
927
+ color: color || this._markupColor.asHex(),
928
+ id,
929
+ },
930
+ null,
931
+ this._worldTransformer
932
+ );
918
933
 
919
934
  this.addObject(konvaLine);
920
935
  return konvaLine;
@@ -987,7 +1002,7 @@ export class KonvaMarkup implements IMarkup {
987
1002
  this._imageInputRef.onchange = async (event) => {
988
1003
  const file = (event.target as HTMLInputElement).files[0];
989
1004
  const base64 = await convertBase64(file);
990
- this.addImage({ x: this._imageInputPos.x, y: this._imageInputPos.y }, base64.toString(), 0, 0);
1005
+ this.addImage({ x: this._imageInputPos.x, y: this._imageInputPos.y }, null, base64.toString(), 0, 0);
991
1006
  };
992
1007
  this._imageInputRef.oncancel = (event) => {
993
1008
  this.removeImageInput();
@@ -1033,14 +1048,18 @@ export class KonvaMarkup implements IMarkup {
1033
1048
  fontSize = textSize / (scale.y / size) / 34;
1034
1049
  }
1035
1050
 
1036
- const konvaText = new KonvaText({
1037
- position: { x: position.x, y: position.y },
1038
- text,
1039
- rotation: angle,
1040
- fontSize: fontSize || this.fontSize,
1041
- color: color || this._markupColor.asHex(),
1042
- id,
1043
- });
1051
+ const konvaText = new KonvaText(
1052
+ {
1053
+ position: { x: position.x, y: position.y },
1054
+ text,
1055
+ rotation: angle,
1056
+ fontSize: fontSize || this.fontSize,
1057
+ color: color || this._markupColor.asHex(),
1058
+ id,
1059
+ },
1060
+ null,
1061
+ this._worldTransformer
1062
+ );
1044
1063
 
1045
1064
  this.addObject(konvaText);
1046
1065
  return konvaText;
@@ -1048,6 +1067,7 @@ export class KonvaMarkup implements IMarkup {
1048
1067
 
1049
1068
  private addRectangle(
1050
1069
  position: Konva.Vector2d,
1070
+ position2: Konva.Vector2d,
1051
1071
  width: number,
1052
1072
  height: number,
1053
1073
  lineWidth?: number,
@@ -1056,61 +1076,74 @@ export class KonvaMarkup implements IMarkup {
1056
1076
  ): KonvaRectangle | void {
1057
1077
  if (!position) return;
1058
1078
 
1059
- const konvaRectangle = new KonvaRectangle({
1060
- position,
1061
- width,
1062
- height,
1063
- lineWidth: lineWidth || this.lineWidth,
1064
- color: color || this._markupColor.asHex(),
1065
- id,
1066
- });
1079
+ const konvaRectangle = new KonvaRectangle(
1080
+ {
1081
+ position,
1082
+ position2,
1083
+ width,
1084
+ height,
1085
+ lineWidth: lineWidth || this.lineWidth,
1086
+ color: color || this._markupColor.asHex(),
1087
+ id,
1088
+ },
1089
+ null,
1090
+ this._worldTransformer
1091
+ );
1067
1092
 
1068
1093
  this.addObject(konvaRectangle);
1069
1094
  return konvaRectangle;
1070
1095
  }
1071
1096
 
1072
1097
  private addEllipse(
1073
- position: { x: number; y: number },
1074
- radius: { x: number; y: number },
1098
+ position: Konva.Vector2d,
1099
+ position2: Konva.Vector2d,
1100
+ position3: Konva.Vector2d,
1101
+ radius: Konva.Vector2d,
1075
1102
  lineWidth?: number,
1076
1103
  color?: string,
1077
1104
  id?: string
1078
1105
  ): KonvaEllipse | void {
1079
1106
  if (!position) return;
1080
1107
 
1081
- const konvaEllipse = new KonvaEllipse({
1082
- position,
1083
- radius,
1084
- lineWidth,
1085
- color: color || this._markupColor.asHex(),
1086
- id,
1087
- });
1108
+ const konvaEllipse = new KonvaEllipse(
1109
+ {
1110
+ position,
1111
+ position2,
1112
+ position3,
1113
+ radius,
1114
+ lineWidth,
1115
+ color: color || this._markupColor.asHex(),
1116
+ id,
1117
+ },
1118
+ null,
1119
+ this._worldTransformer
1120
+ );
1088
1121
 
1089
1122
  this.addObject(konvaEllipse);
1090
1123
  return konvaEllipse;
1091
1124
  }
1092
1125
 
1093
- private addArrow(
1094
- start: { x: number; y: number },
1095
- end: { x: number; y: number },
1096
- color?: string,
1097
- id?: string
1098
- ): KonvaArrow | void {
1126
+ private addArrow(start: Konva.Vector2d, end: Konva.Vector2d, color?: string, id?: string): KonvaArrow | void {
1099
1127
  if (!start || !end) return;
1100
1128
 
1101
- const konvaArrow = new KonvaArrow({
1102
- start,
1103
- end,
1104
- color: color || this._markupColor.asHex(),
1105
- id,
1106
- });
1129
+ const konvaArrow = new KonvaArrow(
1130
+ {
1131
+ start,
1132
+ end,
1133
+ color: color || this._markupColor.asHex(),
1134
+ id,
1135
+ },
1136
+ null,
1137
+ this._worldTransformer
1138
+ );
1107
1139
 
1108
1140
  this.addObject(konvaArrow);
1109
1141
  return konvaArrow;
1110
1142
  }
1111
1143
 
1112
1144
  private addCloud(
1113
- position: { x: number; y: number },
1145
+ position: Konva.Vector2d,
1146
+ position2: Konva.Vector2d,
1114
1147
  width: number,
1115
1148
  height: number,
1116
1149
  lineWidth?: number,
@@ -1119,21 +1152,27 @@ export class KonvaMarkup implements IMarkup {
1119
1152
  ): KonvaCloud | void {
1120
1153
  if (!position || !width || !height) return;
1121
1154
 
1122
- const konvaCloud = new KonvaCloud({
1123
- position,
1124
- width,
1125
- height,
1126
- color: color || this._markupColor.asHex(),
1127
- lineWidth: lineWidth || this.lineWidth,
1128
- id,
1129
- });
1155
+ const konvaCloud = new KonvaCloud(
1156
+ {
1157
+ position,
1158
+ position2,
1159
+ width,
1160
+ height,
1161
+ color: color || this._markupColor.asHex(),
1162
+ lineWidth: lineWidth || this.lineWidth,
1163
+ id,
1164
+ },
1165
+ null,
1166
+ this._worldTransformer
1167
+ );
1130
1168
 
1131
1169
  this.addObject(konvaCloud);
1132
1170
  return konvaCloud;
1133
1171
  }
1134
1172
 
1135
1173
  private addImage(
1136
- position: { x: number; y: number },
1174
+ position: Konva.Vector2d,
1175
+ position2: Konva.Vector2d,
1137
1176
  src: string,
1138
1177
  width?: number,
1139
1178
  height?: number,
@@ -1147,15 +1186,20 @@ export class KonvaMarkup implements IMarkup {
1147
1186
  this.clearSelected();
1148
1187
  this.removeImageInput();
1149
1188
 
1150
- const konvaImage = new KonvaImage({
1151
- position,
1152
- src,
1153
- width,
1154
- height,
1155
- maxWidth: this._konvaStage.width() - position.x,
1156
- maxHeight: this._konvaStage.height() - position.y,
1157
- id,
1158
- });
1189
+ const konvaImage = new KonvaImage(
1190
+ {
1191
+ position,
1192
+ position2,
1193
+ src,
1194
+ width,
1195
+ height,
1196
+ maxWidth: this._konvaStage.width() - position.x,
1197
+ maxHeight: this._konvaStage.height() - position.y,
1198
+ id,
1199
+ },
1200
+ null,
1201
+ this._worldTransformer
1202
+ );
1159
1203
 
1160
1204
  this.addObject(konvaImage);
1161
1205
  return konvaImage;