@inweb/viewer-three 26.4.0 → 26.4.1

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.
@@ -12410,10 +12410,29 @@
12410
12410
  const LineTypeSpecs = new Map([ [ "solid", [] ], [ "dot", [ 30, 30, .001, 30 ] ], [ "dash", [ 30, 30 ] ] ]);
12411
12411
 
12412
12412
  class KonvaLine {
12413
- constructor(params, ref = null) {
12413
+ constructor(params, ref = null, worldTransformer = new WorldTransform) {
12414
12414
  var _a, _b;
12415
+ this._worldTransformer = worldTransformer;
12415
12416
  if (ref) {
12416
12417
  this._ref = ref;
12418
+ let wcsPoints = this._ref.getAttr("wcsPoints");
12419
+ if (!wcsPoints) {
12420
+ wcsPoints = [];
12421
+ let points = this._ref.points();
12422
+ let wcsPoint;
12423
+ for (let i = 0; i < points.length; i += 2) {
12424
+ wcsPoint = this._worldTransformer.screenToWorld({
12425
+ x: points[i],
12426
+ y: points[i + 1]
12427
+ });
12428
+ wcsPoints.push({
12429
+ x: wcsPoint.x,
12430
+ y: wcsPoint.y,
12431
+ z: wcsPoint.z
12432
+ });
12433
+ }
12434
+ this._ref.setAttr("wcsPoints", wcsPoints);
12435
+ }
12417
12436
  return;
12418
12437
  }
12419
12438
  if (!params) params = {};
@@ -12425,7 +12444,19 @@
12425
12444
  y: 100
12426
12445
  } ];
12427
12446
  const konvaPoints = [];
12428
- params.points.forEach((point => konvaPoints.push(point.x, point.y)));
12447
+ const wcsPoints = [];
12448
+ params.points.forEach((point => {
12449
+ konvaPoints.push(point.x, point.y);
12450
+ let wcsPoint = this._worldTransformer.screenToWorld({
12451
+ x: point.x,
12452
+ y: point.y
12453
+ });
12454
+ wcsPoints.push({
12455
+ x: wcsPoint.x,
12456
+ y: wcsPoint.y,
12457
+ z: wcsPoint.z
12458
+ });
12459
+ }));
12429
12460
  this._ref = new Konva.Line({
12430
12461
  stroke: (_a = params.color) !== null && _a !== undefined ? _a : "#ff0000",
12431
12462
  strokeWidth: (_b = params.width) !== null && _b !== undefined ? _b : 4,
@@ -12437,10 +12468,55 @@
12437
12468
  strokeScaleEnabled: false,
12438
12469
  dash: LineTypeSpecs.get(params.type) || []
12439
12470
  });
12471
+ this._ref.setAttr("wcsPoints", wcsPoints);
12440
12472
  this._ref.on("transform", (e => {
12441
12473
  const attrs = e.target.attrs;
12442
12474
  if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
12443
12475
  }));
12476
+ this._ref.on("transformend", (e => {
12477
+ const absoluteTransform = this._ref.getAbsoluteTransform();
12478
+ let wcsPoints = [];
12479
+ let points = this._ref.points();
12480
+ let wcsPoint;
12481
+ for (let i = 0; i < points.length; i += 2) {
12482
+ const position = absoluteTransform.point({
12483
+ x: points[i],
12484
+ y: points[i + 1]
12485
+ });
12486
+ wcsPoint = this._worldTransformer.screenToWorld({
12487
+ x: position.x,
12488
+ y: position.y
12489
+ });
12490
+ wcsPoints.push({
12491
+ x: wcsPoint.x,
12492
+ y: wcsPoint.y,
12493
+ z: wcsPoint.z
12494
+ });
12495
+ }
12496
+ this._ref.setAttr("wcsPoints", wcsPoints);
12497
+ }));
12498
+ this._ref.on("dragend", (e => {
12499
+ const absoluteTransform = this._ref.getAbsoluteTransform();
12500
+ let wcsPoints = [];
12501
+ let points = this._ref.points();
12502
+ let wcsPoint;
12503
+ for (let i = 0; i < points.length; i += 2) {
12504
+ const position = absoluteTransform.point({
12505
+ x: points[i],
12506
+ y: points[i + 1]
12507
+ });
12508
+ wcsPoint = this._worldTransformer.screenToWorld({
12509
+ x: position.x,
12510
+ y: position.y
12511
+ });
12512
+ wcsPoints.push({
12513
+ x: wcsPoint.x,
12514
+ y: wcsPoint.y,
12515
+ z: wcsPoint.z
12516
+ });
12517
+ }
12518
+ this._ref.setAttr("wcsPoints", wcsPoints);
12519
+ }));
12444
12520
  this._ref.id(this._ref._id.toString());
12445
12521
  }
12446
12522
  ref() {
@@ -12510,19 +12586,48 @@
12510
12586
  }
12511
12587
  addPoints(points) {
12512
12588
  let newPoints = this._ref.points();
12589
+ let wcsPoints = this._ref.getAttr("wcsPoints");
12513
12590
  points.forEach((point => {
12514
12591
  newPoints = newPoints.concat([ point.x, point.y ]);
12592
+ let wcsPoint = this._worldTransformer.screenToWorld(point);
12593
+ wcsPoints.push(wcsPoint);
12515
12594
  }));
12516
12595
  this._ref.points(newPoints);
12517
12596
  }
12597
+ updateScreenCoordinates() {
12598
+ let wcsPoints = this._ref.getAttr("wcsPoints");
12599
+ let points = [];
12600
+ let invert = this._ref.getAbsoluteTransform().copy();
12601
+ invert = invert.invert();
12602
+ wcsPoints.forEach((point => {
12603
+ let screenPoint = this._worldTransformer.worldToScreen(point);
12604
+ screenPoint = invert.point({
12605
+ x: screenPoint.x,
12606
+ y: screenPoint.y
12607
+ });
12608
+ points.push(screenPoint.x);
12609
+ points.push(screenPoint.y);
12610
+ }));
12611
+ this._ref.points([]);
12612
+ this._ref.points(points);
12613
+ this._ref.clearCache();
12614
+ }
12518
12615
  }
12519
12616
 
12520
12617
  class KonvaText {
12521
- constructor(params, ref = null) {
12618
+ constructor(params, ref = null, worldTransformer = new WorldTransform) {
12522
12619
  var _a, _b, _c;
12523
12620
  this.TEXT_FONT_FAMILY = "Calibri";
12621
+ this._worldTransformer = worldTransformer;
12524
12622
  if (ref) {
12525
12623
  this._ref = ref;
12624
+ const wcsStart = this._ref.getAttr("wcsStart");
12625
+ if (!wcsStart) {
12626
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
12627
+ x: ref.x(),
12628
+ y: ref.y()
12629
+ }));
12630
+ }
12526
12631
  return;
12527
12632
  }
12528
12633
  if (!params) params = {};
@@ -12543,6 +12648,10 @@
12543
12648
  rotation: (_c = params.rotation) !== null && _c !== undefined ? _c : 0
12544
12649
  });
12545
12650
  this._ref.width(this._ref.getTextWidth());
12651
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
12652
+ x: params.position.x,
12653
+ y: params.position.y
12654
+ }));
12546
12655
  this._ref.on("transform", (e => {
12547
12656
  const attrs = e.target.attrs;
12548
12657
  if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
@@ -12566,6 +12675,24 @@
12566
12675
  y: 1
12567
12676
  });
12568
12677
  }));
12678
+ this._ref.on("transformend", (e => {
12679
+ const attrs = e.target.attrs;
12680
+ if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
12681
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
12682
+ const position = absoluteTransform.point({
12683
+ x: this._ref.x(),
12684
+ y: this._ref.y()
12685
+ });
12686
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
12687
+ }));
12688
+ this._ref.on("dragend", (e => {
12689
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
12690
+ const position = absoluteTransform.point({
12691
+ x: this._ref.x(),
12692
+ y: this._ref.y()
12693
+ });
12694
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
12695
+ }));
12569
12696
  this._ref.id(this._ref._id.toString());
12570
12697
  }
12571
12698
  ref() {
@@ -12616,6 +12743,10 @@
12616
12743
  x: x,
12617
12744
  y: y
12618
12745
  });
12746
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
12747
+ x: x,
12748
+ y: y
12749
+ }));
12619
12750
  }
12620
12751
  getFontSize() {
12621
12752
  return this._ref.fontSize();
@@ -12623,13 +12754,42 @@
12623
12754
  setFontSize(size) {
12624
12755
  this._ref.fontSize(size);
12625
12756
  }
12757
+ updateScreenCoordinates() {
12758
+ let screenPositionStart = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
12759
+ let invert = this._ref.getStage().getAbsoluteTransform().copy();
12760
+ invert = invert.invert();
12761
+ const positionStart = invert.point(screenPositionStart);
12762
+ this._ref.position({
12763
+ x: positionStart.x,
12764
+ y: positionStart.y
12765
+ });
12766
+ }
12626
12767
  }
12627
12768
 
12628
12769
  class KonvaRectangle {
12629
- constructor(params, ref = null) {
12770
+ constructor(params, ref = null, worldTransformer = new WorldTransform) {
12630
12771
  var _a, _b, _c, _d;
12772
+ this._worldTransformer = worldTransformer;
12631
12773
  if (ref) {
12632
12774
  this._ref = ref;
12775
+ const wcsStart = this._ref.getAttr("wcsStart");
12776
+ const wcsEnd = this._ref.getAttr("wcsEnd");
12777
+ if (!wcsStart) {
12778
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
12779
+ x: ref.x(),
12780
+ y: ref.y()
12781
+ }));
12782
+ }
12783
+ if (!wcsEnd) {
12784
+ const rightBottomPoint = {
12785
+ x: ref.x() + ref.width(),
12786
+ y: ref.y() + ref.height()
12787
+ };
12788
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
12789
+ x: rightBottomPoint.x,
12790
+ y: rightBottomPoint.y
12791
+ }));
12792
+ }
12633
12793
  return;
12634
12794
  }
12635
12795
  if (!params) params = {};
@@ -12637,6 +12797,24 @@
12637
12797
  x: 0,
12638
12798
  y: 0
12639
12799
  };
12800
+ if (params.position2) {
12801
+ params.width = params.position.x - params.position2.x;
12802
+ params.height = params.position.y - params.position2.y;
12803
+ } else {
12804
+ if (!params.width || !params.height) {
12805
+ params.position2 = {
12806
+ x: 200,
12807
+ y: 200
12808
+ };
12809
+ params.width = 200;
12810
+ params.height = 200;
12811
+ } else {
12812
+ params.position2 = {
12813
+ x: params.position.x + params.width,
12814
+ y: params.position.y + params.height
12815
+ };
12816
+ }
12817
+ }
12640
12818
  this._ref = new Konva.Rect({
12641
12819
  stroke: (_a = params.color) !== null && _a !== undefined ? _a : "#ff0000",
12642
12820
  strokeWidth: (_b = params.lineWidth) !== null && _b !== undefined ? _b : 4,
@@ -12650,9 +12828,16 @@
12650
12828
  draggable: true,
12651
12829
  strokeScaleEnabled: false
12652
12830
  });
12831
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
12832
+ x: params.position.x,
12833
+ y: params.position.y
12834
+ }));
12835
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
12836
+ x: params.position2.x,
12837
+ y: params.position2.y
12838
+ }));
12653
12839
  this._ref.on("transform", (e => {
12654
12840
  const attrs = e.target.attrs;
12655
- if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
12656
12841
  const scaleByX = Math.abs(attrs.scaleX - 1) > 1e-5;
12657
12842
  const scaleByY = Math.abs(attrs.scaleY - 1) > 1e-5;
12658
12843
  let newWidth = this._ref.width();
@@ -12674,6 +12859,32 @@
12674
12859
  y: 1
12675
12860
  });
12676
12861
  }));
12862
+ this._ref.on("transformend", (e => {
12863
+ const attrs = e.target.attrs;
12864
+ if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
12865
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
12866
+ const position = absoluteTransform.point({
12867
+ x: this._ref.x(),
12868
+ y: this._ref.y()
12869
+ });
12870
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
12871
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
12872
+ x: position.x + this._ref.width(),
12873
+ y: position.y + this._ref.height()
12874
+ }));
12875
+ }));
12876
+ this._ref.on("dragend", (e => {
12877
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
12878
+ const position = absoluteTransform.point({
12879
+ x: this._ref.x(),
12880
+ y: this._ref.y()
12881
+ });
12882
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
12883
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
12884
+ x: position.x + this._ref.width(),
12885
+ y: position.y + this._ref.height()
12886
+ }));
12887
+ }));
12677
12888
  this._ref.id(this._ref._id.toString());
12678
12889
  }
12679
12890
  getPosition() {
@@ -12687,15 +12898,31 @@
12687
12898
  }
12688
12899
  setWidth(w) {
12689
12900
  this._ref.width(w);
12901
+ const rightLowerPoint = {
12902
+ x: this._ref.x() + w,
12903
+ y: this._ref.y() + this._ref.height()
12904
+ };
12905
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
12906
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
12690
12907
  }
12691
12908
  setHeight(h) {
12692
12909
  this._ref.height(h);
12910
+ const rightLowerPoint = {
12911
+ x: this._ref.x() + this._ref.width(),
12912
+ y: this._ref.y() + h
12913
+ };
12914
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
12915
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
12693
12916
  }
12694
12917
  setPosition(x, y) {
12695
12918
  this._ref.setPosition({
12696
12919
  x: x,
12697
12920
  y: y
12698
12921
  });
12922
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
12923
+ x: x,
12924
+ y: y
12925
+ }));
12699
12926
  }
12700
12927
  ref() {
12701
12928
  return this._ref;
@@ -12737,13 +12964,49 @@
12737
12964
  getLineWidth() {
12738
12965
  return this._ref.strokeWidth();
12739
12966
  }
12967
+ updateScreenCoordinates() {
12968
+ let screenPositionStart = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
12969
+ let screenPositionEnd = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));
12970
+ let invert = this._ref.getStage().getAbsoluteTransform().copy();
12971
+ invert = invert.invert();
12972
+ const positionStart = invert.point(screenPositionStart);
12973
+ const positionEnd = invert.point(screenPositionEnd);
12974
+ this._ref.position({
12975
+ x: positionStart.x,
12976
+ y: positionStart.y
12977
+ });
12978
+ this._ref.width(Math.abs(positionEnd.x - positionStart.x));
12979
+ this._ref.height(Math.abs(positionEnd.y - positionStart.y));
12980
+ }
12740
12981
  }
12741
12982
 
12742
12983
  class KonvaEllipse {
12743
- constructor(params, ref = null) {
12984
+ constructor(params, ref = null, worldTransformer = new WorldTransform) {
12744
12985
  var _a, _b;
12986
+ this._worldTransformer = worldTransformer;
12745
12987
  if (ref) {
12746
12988
  this._ref = ref;
12989
+ const wcsPosition = this._ref.getAttr("wcsPosition");
12990
+ const radiusX = this._ref.getAttr("wcsRadiusX");
12991
+ const radiusY = this._ref.getAttr("wcsRadiusY");
12992
+ if (!wcsPosition) {
12993
+ this._ref.setAttr("wcsPosition", this._worldTransformer.screenToWorld({
12994
+ x: ref.x(),
12995
+ y: ref.y()
12996
+ }));
12997
+ }
12998
+ if (!radiusX) {
12999
+ this._ref.setAttr("wcsRadiusX", this._worldTransformer.screenToWorld({
13000
+ x: ref.x() + ref.radiusX(),
13001
+ y: ref.y()
13002
+ }));
13003
+ }
13004
+ if (!radiusY) {
13005
+ this._ref.setAttr("wcsRadiusY", this._worldTransformer.screenToWorld({
13006
+ x: ref.x(),
13007
+ y: ref.y() + ref.radiusY()
13008
+ }));
13009
+ }
12747
13010
  return;
12748
13011
  }
12749
13012
  if (!params) params = {};
@@ -12768,6 +13031,18 @@
12768
13031
  draggable: true,
12769
13032
  strokeScaleEnabled: false
12770
13033
  });
13034
+ this._ref.setAttr("wcsPosition", this._worldTransformer.screenToWorld({
13035
+ x: params.position.x,
13036
+ y: params.position.y
13037
+ }));
13038
+ this._ref.setAttr("wcsRadiusX", this._worldTransformer.screenToWorld({
13039
+ x: this._ref.x() + params.radius.x,
13040
+ y: this._ref.y()
13041
+ }));
13042
+ this._ref.setAttr("wcsRadiusY", this._worldTransformer.screenToWorld({
13043
+ x: this._ref.x(),
13044
+ y: this._ref.y() + params.radius.y
13045
+ }));
12771
13046
  this._ref.on("transform", (e => {
12772
13047
  const attrs = e.target.attrs;
12773
13048
  if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
@@ -12804,6 +13079,42 @@
12804
13079
  y: 1
12805
13080
  });
12806
13081
  }));
13082
+ this._ref.on("transformend", (e => {
13083
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
13084
+ const position = absoluteTransform.point({
13085
+ x: this._ref.x(),
13086
+ y: this._ref.y()
13087
+ });
13088
+ this._ref.setAttr("wcsPosition", this._worldTransformer.screenToWorld(position));
13089
+ const radiusX = absoluteTransform.point({
13090
+ x: this._ref.x() + this._ref.radiusX(),
13091
+ y: this._ref.y()
13092
+ });
13093
+ this._ref.setAttr("wcsRadiusX", this._worldTransformer.screenToWorld(radiusX));
13094
+ const radiusY = absoluteTransform.point({
13095
+ x: this._ref.x(),
13096
+ y: this._ref.y() + this._ref.radiusY()
13097
+ });
13098
+ this._ref.setAttr("wcsRadiusY", this._worldTransformer.screenToWorld(radiusY));
13099
+ }));
13100
+ this._ref.on("dragend", (e => {
13101
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
13102
+ const position = absoluteTransform.point({
13103
+ x: this._ref.x(),
13104
+ y: this._ref.y()
13105
+ });
13106
+ this._ref.setAttr("wcsPosition", this._worldTransformer.screenToWorld(position));
13107
+ const radiusX = absoluteTransform.point({
13108
+ x: this._ref.x() + this._ref.radiusX(),
13109
+ y: this._ref.y()
13110
+ });
13111
+ this._ref.setAttr("wcsRadiusX", this._worldTransformer.screenToWorld(radiusX));
13112
+ const radiusY = absoluteTransform.point({
13113
+ x: this._ref.x(),
13114
+ y: this._ref.y() + this._ref.radiusY()
13115
+ });
13116
+ this._ref.setAttr("wcsRadiusY", this._worldTransformer.screenToWorld(radiusY));
13117
+ }));
12807
13118
  this._ref.id(this._ref._id.toString());
12808
13119
  }
12809
13120
  getPosition() {
@@ -12814,18 +13125,30 @@
12814
13125
  x: x,
12815
13126
  y: y
12816
13127
  });
13128
+ this._ref.setAttr("wcsPosition", this._worldTransformer.screenToWorld({
13129
+ x: x,
13130
+ y: y
13131
+ }));
12817
13132
  }
12818
13133
  getRadiusX() {
12819
13134
  return this._ref.radiusX();
12820
13135
  }
12821
13136
  setRadiusX(r) {
12822
13137
  this._ref.radiusX(r);
13138
+ this._ref.setAttr("wcsRadiusX", this._worldTransformer.screenToWorld({
13139
+ x: this._ref.x() + r,
13140
+ y: this._ref.y()
13141
+ }));
12823
13142
  }
12824
13143
  getRadiusY() {
12825
13144
  return this._ref.radiusY();
12826
13145
  }
12827
13146
  setRadiusY(r) {
12828
13147
  this._ref.radiusY(r);
13148
+ this._ref.setAttr("wcsRadiusY", this._worldTransformer.screenToWorld({
13149
+ x: this._ref.x(),
13150
+ y: this._ref.y() + r
13151
+ }));
12829
13152
  }
12830
13153
  getLineWidth() {
12831
13154
  return this._ref.strokeWidth();
@@ -12867,13 +13190,43 @@
12867
13190
  this._ref.destroy();
12868
13191
  this._ref = null;
12869
13192
  }
13193
+ updateScreenCoordinates() {
13194
+ let screenPosition = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsPosition"));
13195
+ let radiusX = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsRadiusX"));
13196
+ let radiusY = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsRadiusY"));
13197
+ let invert = this._ref.getStage().getAbsoluteTransform().copy();
13198
+ invert = invert.invert();
13199
+ const position = invert.point({
13200
+ x: screenPosition.x,
13201
+ y: screenPosition.y
13202
+ });
13203
+ this._ref.position({
13204
+ x: position.x,
13205
+ y: position.y
13206
+ });
13207
+ this._ref.radius({
13208
+ x: Math.abs(invert.point(radiusX).x - position.x),
13209
+ y: Math.abs(invert.point(radiusY).y - position.y)
13210
+ });
13211
+ }
12870
13212
  }
12871
13213
 
12872
13214
  class KonvaArrow {
12873
- constructor(params, ref = null) {
13215
+ constructor(params, ref = null, worldTransformer = new WorldTransform) {
12874
13216
  var _a, _b;
13217
+ this._worldTransformer = worldTransformer;
12875
13218
  if (ref) {
12876
13219
  this._ref = ref;
13220
+ const wcsStart = this._ref.getAttr("wcsStart");
13221
+ const wcsEnd = this._ref.getAttr("wcsEnd");
13222
+ if (!wcsStart) this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
13223
+ x: ref.points()[0],
13224
+ y: ref.points()[1]
13225
+ }));
13226
+ if (!wcsEnd) this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
13227
+ x: ref.points()[2],
13228
+ y: ref.points()[3]
13229
+ }));
12877
13230
  return;
12878
13231
  }
12879
13232
  if (!params) params = {};
@@ -12896,9 +13249,43 @@
12896
13249
  draggable: true,
12897
13250
  strokeScaleEnabled: false
12898
13251
  });
12899
- this._ref.on("transform", (e => {
13252
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
13253
+ x: params.start.x,
13254
+ y: params.start.y
13255
+ }));
13256
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
13257
+ x: params.end.x,
13258
+ y: params.end.y
13259
+ }));
13260
+ this._ref.on("transformend", (e => {
12900
13261
  const attrs = e.target.attrs;
12901
13262
  if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
13263
+ const points = this._ref.points();
13264
+ const absoluteTransform = this._ref.getAbsoluteTransform();
13265
+ const transformStart = absoluteTransform.point({
13266
+ x: points[0],
13267
+ y: points[1]
13268
+ });
13269
+ const transformEnd = absoluteTransform.point({
13270
+ x: points[2],
13271
+ y: points[3]
13272
+ });
13273
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(transformStart));
13274
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld(transformEnd));
13275
+ }));
13276
+ this._ref.on("dragend", (e => {
13277
+ const points = this._ref.points();
13278
+ const absoluteTransform = e.target.getAbsoluteTransform();
13279
+ const transformStart = absoluteTransform.point({
13280
+ x: points[0],
13281
+ y: points[1]
13282
+ });
13283
+ const transformEnd = absoluteTransform.point({
13284
+ x: points[2],
13285
+ y: points[3]
13286
+ });
13287
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(transformStart));
13288
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld(transformEnd));
12902
13289
  }));
12903
13290
  this._ref.id(this._ref._id.toString());
12904
13291
  }
@@ -12949,6 +13336,14 @@
12949
13336
  }
12950
13337
  setPoints(points) {
12951
13338
  if (points.length === 2) {
13339
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
13340
+ x: points[0].x,
13341
+ y: points[0].y
13342
+ }));
13343
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
13344
+ x: points[1].x,
13345
+ y: points[1].y
13346
+ }));
12952
13347
  this._ref.points([ points[0].x, points[0].y, points[1].x, points[1].y ]);
12953
13348
  }
12954
13349
  }
@@ -12962,6 +13357,10 @@
12962
13357
  setStartPoint(x, y) {
12963
13358
  const points = this._ref.points();
12964
13359
  this._ref.points([ x, y, points[2], points[3] ]);
13360
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
13361
+ x: x,
13362
+ y: y
13363
+ }));
12965
13364
  }
12966
13365
  getEndPoint() {
12967
13366
  const points = this._ref.points();
@@ -12973,16 +13372,36 @@
12973
13372
  setEndPoint(x, y) {
12974
13373
  const points = this._ref.points();
12975
13374
  this._ref.points([ points[0], points[1], x, y ]);
13375
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
13376
+ x: x,
13377
+ y: y
13378
+ }));
13379
+ }
13380
+ updateScreenCoordinates() {
13381
+ let screenStartPoint = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
13382
+ let screenEndPoint = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));
13383
+ let invert = this._ref.getAbsoluteTransform().copy();
13384
+ invert = invert.invert();
13385
+ const startPoint = invert.point({
13386
+ x: screenStartPoint.x,
13387
+ y: screenStartPoint.y
13388
+ });
13389
+ const endPoint = invert.point({
13390
+ x: screenEndPoint.x,
13391
+ y: screenEndPoint.y
13392
+ });
13393
+ this._ref.points([ startPoint.x, startPoint.y, endPoint.x, endPoint.y ]);
12976
13394
  }
12977
13395
  }
12978
13396
 
12979
13397
  class KonvaImage {
12980
- constructor(params, ref = null) {
13398
+ constructor(params, ref = null, worldTransformer = new WorldTransform) {
12981
13399
  var _a, _b;
12982
13400
  this._ratio = 1;
12983
13401
  this.EPSILON = 1e-5;
12984
13402
  this.BASE64_HEADER_START = "data:image/";
12985
13403
  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=";
13404
+ this._worldTransformer = worldTransformer;
12986
13405
  if (ref) {
12987
13406
  if (!ref.src || !ref.src.startsWith(this.BASE64_HEADER_START)) ref.src = this.BASE64_NOT_FOUND;
12988
13407
  if (ref.height() <= this.EPSILON) ref.height(32);
@@ -12990,6 +13409,13 @@
12990
13409
  this._ref = ref;
12991
13410
  this._canvasImage = ref.image();
12992
13411
  this._ratio = this._ref.height() <= this.EPSILON || this._ref.width() <= this.EPSILON ? 1 : this._ref.height() / this._ref.width();
13412
+ const wcsStart = this._ref.getAttr("wcsStart");
13413
+ if (!wcsStart) {
13414
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
13415
+ x: ref.x(),
13416
+ y: ref.y()
13417
+ }));
13418
+ }
12993
13419
  return;
12994
13420
  }
12995
13421
  if (!params) params = {};
@@ -13031,6 +13457,10 @@
13031
13457
  height: (_b = params.height) !== null && _b !== undefined ? _b : 0,
13032
13458
  draggable: true
13033
13459
  });
13460
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
13461
+ x: params.position.x,
13462
+ y: params.position.y
13463
+ }));
13034
13464
  this._ref.on("transform", (e => {
13035
13465
  const attrs = e.target.attrs;
13036
13466
  if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
@@ -13061,6 +13491,22 @@
13061
13491
  y: 1
13062
13492
  });
13063
13493
  }));
13494
+ this._ref.on("transformend", (e => {
13495
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
13496
+ const position = absoluteTransform.point({
13497
+ x: this._ref.x(),
13498
+ y: this._ref.y()
13499
+ });
13500
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
13501
+ }));
13502
+ this._ref.on("dragend", (e => {
13503
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
13504
+ const position = absoluteTransform.point({
13505
+ x: this._ref.x(),
13506
+ y: this._ref.y()
13507
+ });
13508
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
13509
+ }));
13064
13510
  this._ref.id(this._ref._id.toString());
13065
13511
  }
13066
13512
  getSrc() {
@@ -13119,14 +13565,47 @@
13119
13565
  x: x,
13120
13566
  y: y
13121
13567
  });
13568
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
13569
+ x: x,
13570
+ y: y
13571
+ }));
13572
+ }
13573
+ updateScreenCoordinates() {
13574
+ let screenPositionStart = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
13575
+ let invert = this._ref.getStage().getAbsoluteTransform().copy();
13576
+ invert = invert.invert();
13577
+ const positionStart = invert.point(screenPositionStart);
13578
+ this._ref.position({
13579
+ x: positionStart.x,
13580
+ y: positionStart.y
13581
+ });
13122
13582
  }
13123
13583
  }
13124
13584
 
13125
13585
  class KonvaCloud {
13126
- constructor(params, ref = null) {
13586
+ constructor(params, ref = null, worldTransformer = new WorldTransform) {
13127
13587
  var _a, _b, _c, _d;
13588
+ this._worldTransformer = worldTransformer;
13128
13589
  if (ref) {
13129
13590
  this._ref = ref;
13591
+ const wcsStart = this._ref.getAttr("wcsStart");
13592
+ const wcsEnd = this._ref.getAttr("wcsEnd");
13593
+ if (!wcsStart) {
13594
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
13595
+ x: ref.x(),
13596
+ y: ref.y()
13597
+ }));
13598
+ }
13599
+ if (!wcsEnd) {
13600
+ const rightBottomPoint = {
13601
+ x: ref.x() + ref.width(),
13602
+ y: ref.y() + ref.height()
13603
+ };
13604
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
13605
+ x: rightBottomPoint.x,
13606
+ y: rightBottomPoint.y
13607
+ }));
13608
+ }
13130
13609
  return;
13131
13610
  }
13132
13611
  if (!params) params = {};
@@ -13134,7 +13613,25 @@
13134
13613
  x: 0,
13135
13614
  y: 0
13136
13615
  };
13137
- const arcRadius = 16;
13616
+ if (params.position2) {
13617
+ params.width = params.position.x - params.position2.x;
13618
+ params.height = params.position.y - params.position2.y;
13619
+ } else {
13620
+ if (!params.width || !params.height) {
13621
+ params.position2 = {
13622
+ x: 200,
13623
+ y: 200
13624
+ };
13625
+ params.width = 200;
13626
+ params.height = 200;
13627
+ } else {
13628
+ params.position2 = {
13629
+ x: params.position.x + params.width,
13630
+ y: params.position.y + params.height
13631
+ };
13632
+ }
13633
+ }
13634
+ const ARC_RADIUS = 16;
13138
13635
  this._ref = new Konva.Shape({
13139
13636
  x: params.position.x,
13140
13637
  y: params.position.y,
@@ -13193,9 +13690,9 @@
13193
13690
  const counterClockwise = pX > midPoint.x && pY > midPoint.y;
13194
13691
  for (let iArc = 0; iArc < arcCount; iArc++) {
13195
13692
  if (counterClockwise) {
13196
- context.arc(pX, pY, arcRadius, endAngle, startAngle);
13693
+ context.arc(pX, pY, ARC_RADIUS, endAngle, startAngle);
13197
13694
  } else {
13198
- context.arc(pX, pY, arcRadius, startAngle, endAngle);
13695
+ context.arc(pX, pY, ARC_RADIUS, startAngle, endAngle);
13199
13696
  }
13200
13697
  pX += dx / arcCount;
13201
13698
  pY += dy / arcCount;
@@ -13206,9 +13703,16 @@
13206
13703
  }
13207
13704
  });
13208
13705
  this._ref.className = "Cloud";
13706
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
13707
+ x: params.position.x,
13708
+ y: params.position.y
13709
+ }));
13710
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
13711
+ x: params.position2.x,
13712
+ y: params.position2.y
13713
+ }));
13209
13714
  this._ref.on("transform", (e => {
13210
13715
  const attrs = e.target.attrs;
13211
- if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
13212
13716
  const scaleByX = Math.abs(attrs.scaleX - 1) > 1e-5;
13213
13717
  const scaleByY = Math.abs(attrs.scaleY - 1) > 1e-5;
13214
13718
  let newWidth = this._ref.width();
@@ -13230,11 +13734,37 @@
13230
13734
  y: 1
13231
13735
  });
13232
13736
  }));
13737
+ this._ref.on("transformend", (e => {
13738
+ const attrs = e.target.attrs;
13739
+ if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
13740
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
13741
+ const position = absoluteTransform.point({
13742
+ x: this._ref.x(),
13743
+ y: this._ref.y()
13744
+ });
13745
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
13746
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
13747
+ x: position.x + this._ref.width(),
13748
+ y: position.y + this._ref.height()
13749
+ }));
13750
+ }));
13751
+ this._ref.on("dragend", (e => {
13752
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
13753
+ const position = absoluteTransform.point({
13754
+ x: this._ref.x(),
13755
+ y: this._ref.y()
13756
+ });
13757
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
13758
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
13759
+ x: position.x + this._ref.width(),
13760
+ y: position.y + this._ref.height()
13761
+ }));
13762
+ }));
13233
13763
  this._ref.getSelfRect = () => ({
13234
- x: 0 - arcRadius,
13235
- y: 0 - arcRadius,
13236
- width: this._ref.width() + 2 * arcRadius,
13237
- height: this._ref.height() + 2 * arcRadius
13764
+ x: 0 - ARC_RADIUS,
13765
+ y: 0 - ARC_RADIUS,
13766
+ width: this._ref.width() + 2 * ARC_RADIUS,
13767
+ height: this._ref.height() + 2 * ARC_RADIUS
13238
13768
  });
13239
13769
  this._ref.id(this._ref._id.toString());
13240
13770
  }
@@ -13280,18 +13810,34 @@
13280
13810
  x: x,
13281
13811
  y: y
13282
13812
  });
13813
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
13814
+ x: x,
13815
+ y: y
13816
+ }));
13283
13817
  }
13284
13818
  getWidth() {
13285
13819
  return this._ref.width();
13286
13820
  }
13287
13821
  setWidth(w) {
13288
13822
  this._ref.width(w);
13823
+ const rightLowerPoint = {
13824
+ x: this._ref.x() + w,
13825
+ y: this._ref.y() + this._ref.height()
13826
+ };
13827
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
13828
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
13289
13829
  }
13290
13830
  getHeigth() {
13291
13831
  return this._ref.height();
13292
13832
  }
13293
13833
  setHeight(h) {
13294
13834
  this._ref.height(h);
13835
+ const rightLowerPoint = {
13836
+ x: this._ref.x() + this._ref.width(),
13837
+ y: this._ref.y() + h
13838
+ };
13839
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
13840
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
13295
13841
  }
13296
13842
  getLineWidth() {
13297
13843
  return this._ref.strokeWidth();
@@ -13299,6 +13845,20 @@
13299
13845
  setLineWidth(size) {
13300
13846
  this._ref.strokeWidth(size);
13301
13847
  }
13848
+ updateScreenCoordinates() {
13849
+ let screenPositionStart = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
13850
+ let screenPositionEnd = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));
13851
+ let invert = this._ref.getStage().getAbsoluteTransform().copy();
13852
+ invert = invert.invert();
13853
+ const positionStart = invert.point(screenPositionStart);
13854
+ const positionEnd = invert.point(screenPositionEnd);
13855
+ this._ref.position({
13856
+ x: positionStart.x,
13857
+ y: positionStart.y
13858
+ });
13859
+ this._ref.width(Math.abs(positionEnd.x - positionStart.x));
13860
+ this._ref.height(Math.abs(positionEnd.y - positionStart.y));
13861
+ }
13302
13862
  }
13303
13863
 
13304
13864
  const MarkupMode2Konva = {
@@ -13308,37 +13868,49 @@
13308
13868
  },
13309
13869
  Line: {
13310
13870
  name: "Line",
13311
- initializer: (ref, params = null) => new KonvaLine(params, ref)
13871
+ initializer: (ref, params = null, ...attr) => new KonvaLine(params, ref, ...attr)
13312
13872
  },
13313
13873
  Text: {
13314
13874
  name: "Text",
13315
- initializer: (ref, params = null) => new KonvaText(params, ref)
13875
+ initializer: (ref, params = null, ...attr) => new KonvaText(params, ref, ...attr)
13316
13876
  },
13317
13877
  Rectangle: {
13318
13878
  name: "Rect",
13319
- initializer: (ref, params = null) => new KonvaRectangle(params, ref)
13879
+ initializer: (ref, params = null, ...attr) => new KonvaRectangle(params, ref, ...attr)
13320
13880
  },
13321
13881
  Ellipse: {
13322
13882
  name: "Ellipse",
13323
- initializer: (ref, params = null) => new KonvaEllipse(params, ref)
13883
+ initializer: (ref, params = null, ...attr) => new KonvaEllipse(params, ref, ...attr)
13324
13884
  },
13325
13885
  Arrow: {
13326
13886
  name: "Arrow",
13327
- initializer: (ref, params = null) => new KonvaArrow(params, ref)
13887
+ initializer: (ref, params = null, ...attr) => new KonvaArrow(params, ref, ...attr)
13328
13888
  },
13329
13889
  Image: {
13330
13890
  name: "Image",
13331
- initializer: (ref, params = null) => new KonvaImage(params, ref)
13891
+ initializer: (ref, params = null, ...attr) => new KonvaImage(params, ref, ...attr)
13332
13892
  },
13333
13893
  Cloud: {
13334
13894
  name: "Cloud",
13335
- initializer: (ref, params = null) => new KonvaCloud(params, ref)
13895
+ initializer: (ref, params = null, ...attr) => new KonvaCloud(params, ref, ...attr)
13336
13896
  }
13337
13897
  };
13338
13898
 
13899
+ function debounce(func, wait) {
13900
+ let timeout = null;
13901
+ return (...args) => {
13902
+ if (timeout) {
13903
+ clearTimeout(timeout);
13904
+ }
13905
+ timeout = setTimeout((() => {
13906
+ timeout = null;
13907
+ func(...args);
13908
+ }), wait);
13909
+ };
13910
+ }
13911
+
13339
13912
  class KonvaMarkup {
13340
13913
  constructor() {
13341
- this._containerEvents = [];
13342
13914
  this._markupIsActive = false;
13343
13915
  this._markupColor = new MarkupColor(255, 0, 0);
13344
13916
  this.lineWidth = 4;
@@ -13357,25 +13929,29 @@
13357
13929
  if (!this._konvaStage) return;
13358
13930
  this._konvaStage.width(width);
13359
13931
  this._konvaStage.height(height);
13932
+ this.getObjects().forEach((markupObject => {
13933
+ markupObject.updateScreenCoordinates();
13934
+ }));
13935
+ };
13936
+ this.resizeViewer = event => {
13937
+ const {width: width, height: height} = event;
13938
+ if (!width || !height) return;
13939
+ if (!this._konvaStage) return;
13940
+ this._konvaStage.width(width);
13941
+ this._konvaStage.height(height);
13942
+ this.getObjects().forEach((markupObject => {
13943
+ markupObject.updateScreenCoordinates();
13944
+ }));
13360
13945
  };
13361
13946
  this.pan = event => {
13362
- const newPos = {
13363
- x: this._konvaStage.x() + event.dX,
13364
- y: this._konvaStage.y() + event.dY
13365
- };
13366
- this._konvaStage.position(newPos);
13947
+ this.getObjects().forEach((markupObject => {
13948
+ markupObject.updateScreenCoordinates();
13949
+ }));
13367
13950
  };
13368
13951
  this.zoomAt = event => {
13369
- const newScale = this._konvaStage.scaleX() * event.data;
13370
- this._konvaStage.scale({
13371
- x: newScale,
13372
- y: newScale
13373
- });
13374
- const newPos = {
13375
- x: event.x - (event.x - this._konvaStage.x()) * event.data,
13376
- y: event.y - (event.y - this._konvaStage.y()) * event.data
13377
- };
13378
- this._konvaStage.position(newPos);
13952
+ this.getObjects().forEach((markupObject => {
13953
+ markupObject.updateScreenCoordinates();
13954
+ }));
13379
13955
  };
13380
13956
  this.redirectToViewer = event => {
13381
13957
  if (this._viewer) this._viewer.emit(event);
@@ -13392,7 +13968,6 @@
13392
13968
  this._viewer = viewer;
13393
13969
  this._worldTransformer = worldTransformer !== null && worldTransformer !== undefined ? worldTransformer : new WorldTransform;
13394
13970
  this._container = container;
13395
- this._containerEvents = containerEvents !== null && containerEvents !== undefined ? containerEvents : [];
13396
13971
  this._markupContainer = document.createElement("div");
13397
13972
  this._markupContainer.id = "markup-container";
13398
13973
  this._markupContainer.style.position = "absolute";
@@ -13402,8 +13977,7 @@
13402
13977
  this._markupContainer.style.pointerEvents = "none";
13403
13978
  const parentDiv = this._container.parentElement;
13404
13979
  parentDiv.appendChild(this._markupContainer);
13405
- this._resizeObserver = new ResizeObserver(this.resizeContainer);
13406
- this._resizeObserver.observe(parentDiv);
13980
+ if (viewer) this._viewer.addEventListener("resize", this.resizeViewer); else this._resizeObserver = new ResizeObserver(debounce(this.resizeContainer, 100));
13407
13981
  this._markupColor.setColor(255, 0, 0);
13408
13982
  this.initializeKonva();
13409
13983
  if (this._viewer) {
@@ -13498,7 +14072,7 @@
13498
14072
  }));
13499
14073
  (_d = viewpoint.rectangles) === null || _d === undefined ? undefined : _d.forEach((rect => {
13500
14074
  const screenPoint = this._worldTransformer.worldToScreen(rect.position);
13501
- this.addRectangle(screenPoint, rect.width, rect.height, rect.line_width, rect.color, rect.id);
14075
+ this.addRectangle(screenPoint, null, rect.width, rect.height, rect.line_width, rect.color, rect.id);
13502
14076
  }));
13503
14077
  (_e = viewpoint.ellipses) === null || _e === undefined ? undefined : _e.forEach((ellipse => {
13504
14078
  const screenPoint = this._worldTransformer.worldToScreen(ellipse.position);
@@ -13511,7 +14085,7 @@
13511
14085
  }));
13512
14086
  (_g = viewpoint.clouds) === null || _g === undefined ? undefined : _g.forEach((cloud => {
13513
14087
  const screenPoint = this._worldTransformer.worldToScreen(cloud.position);
13514
- this.addCloud(screenPoint, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
14088
+ this.addCloud(screenPoint, null, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
13515
14089
  }));
13516
14090
  (_h = viewpoint.images) === null || _h === undefined ? undefined : _h.forEach((image => {
13517
14091
  const screenPoint = this._worldTransformer.worldToScreen(image.position);
@@ -13552,7 +14126,7 @@
13552
14126
  createObject(type, params) {
13553
14127
  const konvaShape = MarkupMode2Konva[type];
13554
14128
  if (!konvaShape || !konvaShape.initializer) throw new Error(`Markup CreateObject - unsupported markup type ${type}`);
13555
- const object = konvaShape.initializer(null, params);
14129
+ const object = konvaShape.initializer(null, params, this._worldTransformer);
13556
14130
  this.addObject(object);
13557
14131
  return object;
13558
14132
  }
@@ -13560,7 +14134,7 @@
13560
14134
  const objects = [];
13561
14135
  Object.keys(MarkupMode2Konva).forEach((type => {
13562
14136
  const konvaShape = MarkupMode2Konva[type];
13563
- this.konvaLayerFind(type).forEach((ref => objects.push(konvaShape.initializer(ref))));
14137
+ this.konvaLayerFind(type).forEach((ref => objects.push(konvaShape.initializer(ref, null, this._worldTransformer))));
13564
14138
  }));
13565
14139
  return objects;
13566
14140
  }
@@ -13569,7 +14143,7 @@
13569
14143
  return this._konvaTransformer.nodes().map((ref => {
13570
14144
  const name = ref.className;
13571
14145
  const konvaShape = Object.values(MarkupMode2Konva).find((shape => shape.name === name));
13572
- return konvaShape ? konvaShape.initializer(ref) : null;
14146
+ return konvaShape ? konvaShape.initializer(ref, null, this._worldTransformer) : null;
13573
14147
  })).filter((x => x));
13574
14148
  }
13575
14149
  selectObjects(objects) {
@@ -13645,7 +14219,7 @@
13645
14219
  this.addRectangle({
13646
14220
  x: startX,
13647
14221
  y: startY
13648
- }, dX, dY);
14222
+ }, null, dX, dY);
13649
14223
  } else if (this._markupMode === "Ellipse") {
13650
14224
  this.addEllipse({
13651
14225
  x: startX,
@@ -13666,7 +14240,7 @@
13666
14240
  this.addCloud({
13667
14241
  x: startX,
13668
14242
  y: startY
13669
- }, Math.max(100, dX), Math.max(100, dY));
14243
+ }, null, Math.max(100, dX), Math.max(100, dY));
13670
14244
  }
13671
14245
  }
13672
14246
  }
@@ -13705,7 +14279,7 @@
13705
14279
  } else lastObj = this.addRectangle({
13706
14280
  x: startX,
13707
14281
  y: startY
13708
- }, dX, dY);
14282
+ }, null, dX, dY);
13709
14283
  } else if (this._markupMode === "Ellipse") {
13710
14284
  if (lastObj) {
13711
14285
  lastObj.setPosition(startX, startY);
@@ -13726,7 +14300,7 @@
13726
14300
  } else lastObj = this.addCloud({
13727
14301
  x: startX,
13728
14302
  y: startY
13729
- }, dX, dY);
14303
+ }, null, dX, dY);
13730
14304
  }
13731
14305
  }));
13732
14306
  stage.on("click tap", (e => {
@@ -13818,22 +14392,12 @@
13818
14392
  getMarkupLines() {
13819
14393
  const lines = [];
13820
14394
  this.konvaLayerFind("Line").forEach((ref => {
13821
- const linePoints = ref.points();
13822
- if (!linePoints) return;
13823
- const worldPoints = [];
13824
- const absoluteTransform = ref.getAbsoluteTransform();
13825
- for (let i = 0; i < linePoints.length; i += 2) {
13826
- const atPoint = absoluteTransform.point({
13827
- x: linePoints[i],
13828
- y: linePoints[i + 1]
13829
- });
13830
- const worldPoint = this._worldTransformer.screenToWorld(atPoint);
13831
- worldPoints.push(worldPoint);
13832
- }
13833
- const konvaLine = new KonvaLine(null, ref);
14395
+ const wcsPoints = ref.getAttr("wcsPoints");
14396
+ if (!wcsPoints) return;
14397
+ const konvaLine = new KonvaLine(null, ref, this._worldTransformer);
13834
14398
  const line = {
13835
14399
  id: konvaLine.id(),
13836
- points: worldPoints,
14400
+ points: wcsPoints,
13837
14401
  color: konvaLine.getColor() || "#ff0000",
13838
14402
  type: konvaLine.getLineType() || this.lineType,
13839
14403
  width: konvaLine.getLineWidth() || this.lineWidth
@@ -13847,17 +14411,12 @@
13847
14411
  this.konvaLayerFind("Text").forEach((ref => {
13848
14412
  const textSize = .02;
13849
14413
  const textScale = this._worldTransformer.getScale();
13850
- const position = ref.position();
14414
+ const wcsPosition = ref.getAttr("wcsStart");
13851
14415
  const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
13852
- const atPoint = stageAbsoluteTransform.point({
13853
- x: position.x,
13854
- y: position.y
13855
- });
13856
- const worldPoint = this._worldTransformer.screenToWorld(atPoint);
13857
- const shape = new KonvaText(null, ref);
14416
+ const shape = new KonvaText(null, ref, this._worldTransformer);
13858
14417
  const text = {
13859
14418
  id: shape.id(),
13860
- position: worldPoint,
14419
+ position: wcsPosition,
13861
14420
  text: shape.getText(),
13862
14421
  text_size: textSize * textScale.y,
13863
14422
  angle: shape.getRotation(),
@@ -13871,20 +14430,16 @@
13871
14430
  getMarkupRectangles() {
13872
14431
  const rectangles = [];
13873
14432
  this.konvaLayerFind("Rectangle").forEach((ref => {
13874
- const position = ref.position();
13875
- const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
13876
- const atPoint = stageAbsoluteTransform.point({
13877
- x: position.x,
13878
- y: position.y
13879
- });
13880
- const worldPoint = this._worldTransformer.screenToWorld(atPoint);
13881
- const scale = stageAbsoluteTransform.getMatrix()[0];
13882
- const shape = new KonvaRectangle(null, ref);
14433
+ const wcsStart = ref.getAttr("wcsStart");
14434
+ const wcsEnd = ref.getAttr("wcsEnd");
14435
+ const screenStart = this._worldTransformer.worldToScreen(wcsStart);
14436
+ const screenEnd = this._worldTransformer.worldToScreen(wcsEnd);
14437
+ const shape = new KonvaRectangle(null, ref, this._worldTransformer);
13883
14438
  const rectangle = {
13884
14439
  id: shape.id(),
13885
- position: worldPoint,
13886
- width: shape.getWidth() * scale,
13887
- height: shape.getHeigth() * scale,
14440
+ position: wcsStart,
14441
+ width: Math.abs(screenStart.x - screenEnd.x),
14442
+ height: Math.abs(screenStart.y - screenEnd.y),
13888
14443
  line_width: shape.getLineWidth(),
13889
14444
  color: shape.getColor()
13890
14445
  };
@@ -13895,18 +14450,13 @@
13895
14450
  getMarkupEllipses() {
13896
14451
  const ellipses = [];
13897
14452
  this.konvaLayerFind("Ellipse").forEach((ref => {
13898
- const position = ref.position();
14453
+ const wcsPosition = ref.getAttr("wcsPosition");
13899
14454
  const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
13900
- const atPoint = stageAbsoluteTransform.point({
13901
- x: position.x,
13902
- y: position.y
13903
- });
13904
- const worldPoint = this._worldTransformer.screenToWorld(atPoint);
13905
14455
  const scale = stageAbsoluteTransform.getMatrix()[0];
13906
- const shape = new KonvaEllipse(null, ref);
14456
+ const shape = new KonvaEllipse(null, ref, this._worldTransformer);
13907
14457
  const ellipse = {
13908
14458
  id: shape.id(),
13909
- position: worldPoint,
14459
+ position: wcsPosition,
13910
14460
  radius: {
13911
14461
  x: ref.getRadiusX() * scale,
13912
14462
  y: ref.getRadiusY() * scale
@@ -13921,22 +14471,13 @@
13921
14471
  getMarkupArrows() {
13922
14472
  const arrows = [];
13923
14473
  this.konvaLayerFind("Arrow").forEach((ref => {
13924
- const absoluteTransform = ref.getAbsoluteTransform();
13925
- const atStartPoint = absoluteTransform.point({
13926
- x: ref.points()[0],
13927
- y: ref.points()[1]
13928
- });
13929
- const worldStartPoint = this._worldTransformer.screenToWorld(atStartPoint);
13930
- const atEndPoint = absoluteTransform.point({
13931
- x: ref.points()[2],
13932
- y: ref.points()[3]
13933
- });
13934
- const worldEndPoint = this._worldTransformer.screenToWorld(atEndPoint);
13935
- const shape = new KonvaArrow(null, ref);
14474
+ const wcsStart = ref.getAttr("wcsStart");
14475
+ const wcsEnd = ref.getAttr("wcsEnd");
14476
+ const shape = new KonvaArrow(null, ref, this._worldTransformer);
13936
14477
  const arrow = {
13937
14478
  id: shape.id(),
13938
- start: worldStartPoint,
13939
- end: worldEndPoint,
14479
+ start: wcsStart,
14480
+ end: wcsEnd,
13940
14481
  color: shape.getColor()
13941
14482
  };
13942
14483
  arrows.push(arrow);
@@ -13946,18 +14487,13 @@
13946
14487
  getMarkupImages() {
13947
14488
  const images = [];
13948
14489
  this.konvaLayerFind("Image").forEach((ref => {
13949
- const position = ref.position();
14490
+ const wcsStart = ref.getAttr("wcsStart");
13950
14491
  const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
13951
- const atPoint = stageAbsoluteTransform.point({
13952
- x: position.x,
13953
- y: position.y
13954
- });
13955
- const worldPoint = this._worldTransformer.screenToWorld(atPoint);
13956
14492
  const scale = stageAbsoluteTransform.getMatrix()[0];
13957
- const shape = new KonvaImage(null, ref);
14493
+ const shape = new KonvaImage(null, ref, this._worldTransformer);
13958
14494
  const image = {
13959
14495
  id: shape.id(),
13960
- position: worldPoint,
14496
+ position: wcsStart,
13961
14497
  src: shape.getSrc(),
13962
14498
  width: shape.getWidth() * scale,
13963
14499
  height: shape.getHeight() * scale
@@ -13969,20 +14505,16 @@
13969
14505
  getMarkupClouds() {
13970
14506
  const clouds = [];
13971
14507
  this.konvaLayerFind("Cloud").forEach((ref => {
13972
- const position = ref.position();
13973
- const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
13974
- const atPoint = stageAbsoluteTransform.point({
13975
- x: position.x,
13976
- y: position.y
13977
- });
13978
- const worldPoint = this._worldTransformer.screenToWorld(atPoint);
13979
- const scale = stageAbsoluteTransform.getMatrix()[0];
13980
- const shape = new KonvaCloud(null, ref);
14508
+ const wcsStart = ref.getAttr("wcsStart");
14509
+ const wcsEnd = ref.getAttr("wcsEnd");
14510
+ const screenStart = this._worldTransformer.worldToScreen(wcsStart);
14511
+ const screenEnd = this._worldTransformer.worldToScreen(wcsEnd);
14512
+ const shape = new KonvaCloud(null, ref, this._worldTransformer);
13981
14513
  const cloud = {
13982
14514
  id: shape.id(),
13983
- position: worldPoint,
13984
- width: shape.getWidth() * scale,
13985
- height: shape.getHeigth() * scale,
14515
+ position: wcsStart,
14516
+ width: Math.abs(screenStart.x - screenEnd.x),
14517
+ height: Math.abs(screenStart.y - screenEnd.y),
13986
14518
  line_width: shape.getLineWidth(),
13987
14519
  color: shape.getColor()
13988
14520
  };
@@ -14019,7 +14551,7 @@
14019
14551
  width: width || this.lineWidth,
14020
14552
  color: color || this._markupColor.asHex(),
14021
14553
  id: id
14022
- });
14554
+ }, null, this._worldTransformer);
14023
14555
  this.addObject(konvaLine);
14024
14556
  return konvaLine;
14025
14557
  }
@@ -14126,20 +14658,21 @@
14126
14658
  fontSize: fontSize || this.fontSize,
14127
14659
  color: color || this._markupColor.asHex(),
14128
14660
  id: id
14129
- });
14661
+ }, null, this._worldTransformer);
14130
14662
  this.addObject(konvaText);
14131
14663
  return konvaText;
14132
14664
  }
14133
- addRectangle(position, width, height, lineWidth, color, id) {
14665
+ addRectangle(position, position2, width, height, lineWidth, color, id) {
14134
14666
  if (!position) return;
14135
14667
  const konvaRectangle = new KonvaRectangle({
14136
14668
  position: position,
14669
+ position2: position2,
14137
14670
  width: width,
14138
14671
  height: height,
14139
14672
  lineWidth: lineWidth || this.lineWidth,
14140
14673
  color: color || this._markupColor.asHex(),
14141
14674
  id: id
14142
- });
14675
+ }, null, this._worldTransformer);
14143
14676
  this.addObject(konvaRectangle);
14144
14677
  return konvaRectangle;
14145
14678
  }
@@ -14151,7 +14684,7 @@
14151
14684
  lineWidth: lineWidth,
14152
14685
  color: color || this._markupColor.asHex(),
14153
14686
  id: id
14154
- });
14687
+ }, null, this._worldTransformer);
14155
14688
  this.addObject(konvaEllipse);
14156
14689
  return konvaEllipse;
14157
14690
  }
@@ -14162,20 +14695,21 @@
14162
14695
  end: end,
14163
14696
  color: color || this._markupColor.asHex(),
14164
14697
  id: id
14165
- });
14698
+ }, null, this._worldTransformer);
14166
14699
  this.addObject(konvaArrow);
14167
14700
  return konvaArrow;
14168
14701
  }
14169
- addCloud(position, width, height, lineWidth, color, id) {
14702
+ addCloud(position, position2, width, height, lineWidth, color, id) {
14170
14703
  if (!position || !width || !height) return;
14171
14704
  const konvaCloud = new KonvaCloud({
14172
14705
  position: position,
14706
+ position2: position2,
14173
14707
  width: width,
14174
14708
  height: height,
14175
14709
  color: color || this._markupColor.asHex(),
14176
14710
  lineWidth: lineWidth || this.lineWidth,
14177
14711
  id: id
14178
- });
14712
+ }, null, this._worldTransformer);
14179
14713
  this.addObject(konvaCloud);
14180
14714
  return konvaCloud;
14181
14715
  }
@@ -14193,7 +14727,7 @@
14193
14727
  maxWidth: this._konvaStage.width() - position.x,
14194
14728
  maxHeight: this._konvaStage.height() - position.y,
14195
14729
  id: id
14196
- });
14730
+ }, null, this._worldTransformer);
14197
14731
  this.addObject(konvaImage);
14198
14732
  return konvaImage;
14199
14733
  }