@inweb/viewer-three 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.
@@ -68,25 +68,22 @@
68
68
 
69
69
  class DraggersRegistry {
70
70
  constructor() {
71
- this._draggers = new Map;
71
+ this._providers = new Map;
72
72
  }
73
73
  registerDragger(name, provider) {
74
- this._draggers.set(name, provider);
74
+ this._providers.set(name, provider);
75
75
  }
76
76
  registerDraggerAlias(name, alias) {
77
- const provider = this.getDragger(name);
77
+ const provider = this._providers.get(name);
78
78
  if (provider) this.registerDragger(alias, (viewer => provider(viewer)));
79
79
  }
80
- getDragger(name) {
81
- return this._draggers.get(name);
82
- }
83
80
  getDraggers() {
84
81
  const map = new Map;
85
- this._draggers.forEach(((value, key) => map.set(key, value)));
82
+ this._providers.forEach(((value, key) => map.set(key, value)));
86
83
  return map;
87
84
  }
88
85
  createDragger(name, viewer) {
89
- const provider = this.getDragger(name);
86
+ const provider = this._providers.get(name);
90
87
  if (!provider) return null;
91
88
  const dragger = provider(viewer);
92
89
  dragger.name = name;
@@ -114,25 +111,22 @@
114
111
 
115
112
  class Components {
116
113
  constructor() {
117
- this._components = new Map;
114
+ this._providers = new Map;
118
115
  }
119
116
  registerComponent(name, provider) {
120
- this._components.set(name, provider);
117
+ this._providers.set(name, provider);
121
118
  }
122
119
  registerComponentAlias(name, alias) {
123
- const provider = this.getComponent(name);
120
+ const provider = this._providers.get(name);
124
121
  if (provider) this.registerComponent(alias, (viewer => provider(viewer)));
125
122
  }
126
- getComponent(name) {
127
- return this._components.get(name);
128
- }
129
123
  getComponents() {
130
124
  const map = new Map;
131
- this._components.forEach(((value, key) => map.set(key, value)));
125
+ this._providers.forEach(((value, key) => map.set(key, value)));
132
126
  return map;
133
127
  }
134
128
  createComponent(name, viewer) {
135
- const provider = this.getComponent(name);
129
+ const provider = this._providers.get(name);
136
130
  if (!provider) return null;
137
131
  const component = provider(viewer);
138
132
  component.name = name;
@@ -12410,10 +12404,29 @@
12410
12404
  const LineTypeSpecs = new Map([ [ "solid", [] ], [ "dot", [ 30, 30, .001, 30 ] ], [ "dash", [ 30, 30 ] ] ]);
12411
12405
 
12412
12406
  class KonvaLine {
12413
- constructor(params, ref = null) {
12407
+ constructor(params, ref = null, worldTransformer = new WorldTransform) {
12414
12408
  var _a, _b;
12409
+ this._worldTransformer = worldTransformer;
12415
12410
  if (ref) {
12416
12411
  this._ref = ref;
12412
+ let wcsPoints = this._ref.getAttr("wcsPoints");
12413
+ if (!wcsPoints) {
12414
+ wcsPoints = [];
12415
+ let points = this._ref.points();
12416
+ let wcsPoint;
12417
+ for (let i = 0; i < points.length; i += 2) {
12418
+ wcsPoint = this._worldTransformer.screenToWorld({
12419
+ x: points[i],
12420
+ y: points[i + 1]
12421
+ });
12422
+ wcsPoints.push({
12423
+ x: wcsPoint.x,
12424
+ y: wcsPoint.y,
12425
+ z: wcsPoint.z
12426
+ });
12427
+ }
12428
+ this._ref.setAttr("wcsPoints", wcsPoints);
12429
+ }
12417
12430
  return;
12418
12431
  }
12419
12432
  if (!params) params = {};
@@ -12425,7 +12438,19 @@
12425
12438
  y: 100
12426
12439
  } ];
12427
12440
  const konvaPoints = [];
12428
- params.points.forEach((point => konvaPoints.push(point.x, point.y)));
12441
+ const wcsPoints = [];
12442
+ params.points.forEach((point => {
12443
+ konvaPoints.push(point.x, point.y);
12444
+ let wcsPoint = this._worldTransformer.screenToWorld({
12445
+ x: point.x,
12446
+ y: point.y
12447
+ });
12448
+ wcsPoints.push({
12449
+ x: wcsPoint.x,
12450
+ y: wcsPoint.y,
12451
+ z: wcsPoint.z
12452
+ });
12453
+ }));
12429
12454
  this._ref = new Konva.Line({
12430
12455
  stroke: (_a = params.color) !== null && _a !== undefined ? _a : "#ff0000",
12431
12456
  strokeWidth: (_b = params.width) !== null && _b !== undefined ? _b : 4,
@@ -12437,10 +12462,55 @@
12437
12462
  strokeScaleEnabled: false,
12438
12463
  dash: LineTypeSpecs.get(params.type) || []
12439
12464
  });
12465
+ this._ref.setAttr("wcsPoints", wcsPoints);
12440
12466
  this._ref.on("transform", (e => {
12441
12467
  const attrs = e.target.attrs;
12442
12468
  if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
12443
12469
  }));
12470
+ this._ref.on("transformend", (e => {
12471
+ const absoluteTransform = this._ref.getAbsoluteTransform();
12472
+ let wcsPoints = [];
12473
+ let points = this._ref.points();
12474
+ let wcsPoint;
12475
+ for (let i = 0; i < points.length; i += 2) {
12476
+ const position = absoluteTransform.point({
12477
+ x: points[i],
12478
+ y: points[i + 1]
12479
+ });
12480
+ wcsPoint = this._worldTransformer.screenToWorld({
12481
+ x: position.x,
12482
+ y: position.y
12483
+ });
12484
+ wcsPoints.push({
12485
+ x: wcsPoint.x,
12486
+ y: wcsPoint.y,
12487
+ z: wcsPoint.z
12488
+ });
12489
+ }
12490
+ this._ref.setAttr("wcsPoints", wcsPoints);
12491
+ }));
12492
+ this._ref.on("dragend", (e => {
12493
+ const absoluteTransform = this._ref.getAbsoluteTransform();
12494
+ let wcsPoints = [];
12495
+ let points = this._ref.points();
12496
+ let wcsPoint;
12497
+ for (let i = 0; i < points.length; i += 2) {
12498
+ const position = absoluteTransform.point({
12499
+ x: points[i],
12500
+ y: points[i + 1]
12501
+ });
12502
+ wcsPoint = this._worldTransformer.screenToWorld({
12503
+ x: position.x,
12504
+ y: position.y
12505
+ });
12506
+ wcsPoints.push({
12507
+ x: wcsPoint.x,
12508
+ y: wcsPoint.y,
12509
+ z: wcsPoint.z
12510
+ });
12511
+ }
12512
+ this._ref.setAttr("wcsPoints", wcsPoints);
12513
+ }));
12444
12514
  this._ref.id(this._ref._id.toString());
12445
12515
  }
12446
12516
  ref() {
@@ -12510,19 +12580,48 @@
12510
12580
  }
12511
12581
  addPoints(points) {
12512
12582
  let newPoints = this._ref.points();
12583
+ let wcsPoints = this._ref.getAttr("wcsPoints");
12513
12584
  points.forEach((point => {
12514
12585
  newPoints = newPoints.concat([ point.x, point.y ]);
12586
+ let wcsPoint = this._worldTransformer.screenToWorld(point);
12587
+ wcsPoints.push(wcsPoint);
12515
12588
  }));
12516
12589
  this._ref.points(newPoints);
12517
12590
  }
12591
+ updateScreenCoordinates() {
12592
+ let wcsPoints = this._ref.getAttr("wcsPoints");
12593
+ let points = [];
12594
+ let invert = this._ref.getAbsoluteTransform().copy();
12595
+ invert = invert.invert();
12596
+ wcsPoints.forEach((point => {
12597
+ let screenPoint = this._worldTransformer.worldToScreen(point);
12598
+ screenPoint = invert.point({
12599
+ x: screenPoint.x,
12600
+ y: screenPoint.y
12601
+ });
12602
+ points.push(screenPoint.x);
12603
+ points.push(screenPoint.y);
12604
+ }));
12605
+ this._ref.points([]);
12606
+ this._ref.points(points);
12607
+ this._ref.clearCache();
12608
+ }
12518
12609
  }
12519
12610
 
12520
12611
  class KonvaText {
12521
- constructor(params, ref = null) {
12612
+ constructor(params, ref = null, worldTransformer = new WorldTransform) {
12522
12613
  var _a, _b, _c;
12523
12614
  this.TEXT_FONT_FAMILY = "Calibri";
12615
+ this._worldTransformer = worldTransformer;
12524
12616
  if (ref) {
12525
12617
  this._ref = ref;
12618
+ const wcsStart = this._ref.getAttr("wcsStart");
12619
+ if (!wcsStart) {
12620
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
12621
+ x: ref.x(),
12622
+ y: ref.y()
12623
+ }));
12624
+ }
12526
12625
  return;
12527
12626
  }
12528
12627
  if (!params) params = {};
@@ -12543,6 +12642,10 @@
12543
12642
  rotation: (_c = params.rotation) !== null && _c !== undefined ? _c : 0
12544
12643
  });
12545
12644
  this._ref.width(this._ref.getTextWidth());
12645
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
12646
+ x: params.position.x,
12647
+ y: params.position.y
12648
+ }));
12546
12649
  this._ref.on("transform", (e => {
12547
12650
  const attrs = e.target.attrs;
12548
12651
  if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
@@ -12566,6 +12669,24 @@
12566
12669
  y: 1
12567
12670
  });
12568
12671
  }));
12672
+ this._ref.on("transformend", (e => {
12673
+ const attrs = e.target.attrs;
12674
+ if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
12675
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
12676
+ const position = absoluteTransform.point({
12677
+ x: this._ref.x(),
12678
+ y: this._ref.y()
12679
+ });
12680
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
12681
+ }));
12682
+ this._ref.on("dragend", (e => {
12683
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
12684
+ const position = absoluteTransform.point({
12685
+ x: this._ref.x(),
12686
+ y: this._ref.y()
12687
+ });
12688
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
12689
+ }));
12569
12690
  this._ref.id(this._ref._id.toString());
12570
12691
  }
12571
12692
  ref() {
@@ -12616,6 +12737,10 @@
12616
12737
  x: x,
12617
12738
  y: y
12618
12739
  });
12740
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
12741
+ x: x,
12742
+ y: y
12743
+ }));
12619
12744
  }
12620
12745
  getFontSize() {
12621
12746
  return this._ref.fontSize();
@@ -12623,13 +12748,42 @@
12623
12748
  setFontSize(size) {
12624
12749
  this._ref.fontSize(size);
12625
12750
  }
12751
+ updateScreenCoordinates() {
12752
+ let screenPositionStart = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
12753
+ let invert = this._ref.getStage().getAbsoluteTransform().copy();
12754
+ invert = invert.invert();
12755
+ const positionStart = invert.point(screenPositionStart);
12756
+ this._ref.position({
12757
+ x: positionStart.x,
12758
+ y: positionStart.y
12759
+ });
12760
+ }
12626
12761
  }
12627
12762
 
12628
12763
  class KonvaRectangle {
12629
- constructor(params, ref = null) {
12764
+ constructor(params, ref = null, worldTransformer = new WorldTransform) {
12630
12765
  var _a, _b, _c, _d;
12766
+ this._worldTransformer = worldTransformer;
12631
12767
  if (ref) {
12632
12768
  this._ref = ref;
12769
+ const wcsStart = this._ref.getAttr("wcsStart");
12770
+ const wcsEnd = this._ref.getAttr("wcsEnd");
12771
+ if (!wcsStart) {
12772
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
12773
+ x: ref.x(),
12774
+ y: ref.y()
12775
+ }));
12776
+ }
12777
+ if (!wcsEnd) {
12778
+ const rightBottomPoint = {
12779
+ x: ref.x() + ref.width(),
12780
+ y: ref.y() + ref.height()
12781
+ };
12782
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
12783
+ x: rightBottomPoint.x,
12784
+ y: rightBottomPoint.y
12785
+ }));
12786
+ }
12633
12787
  return;
12634
12788
  }
12635
12789
  if (!params) params = {};
@@ -12637,6 +12791,24 @@
12637
12791
  x: 0,
12638
12792
  y: 0
12639
12793
  };
12794
+ if (params.position2) {
12795
+ params.width = params.position2.x - params.position.x;
12796
+ params.height = params.position2.y - params.position.y;
12797
+ } else {
12798
+ if (!params.width || !params.height) {
12799
+ params.position2 = {
12800
+ x: 200,
12801
+ y: 200
12802
+ };
12803
+ params.width = 200;
12804
+ params.height = 200;
12805
+ } else {
12806
+ params.position2 = {
12807
+ x: params.position.x + params.width,
12808
+ y: params.position.y + params.height
12809
+ };
12810
+ }
12811
+ }
12640
12812
  this._ref = new Konva.Rect({
12641
12813
  stroke: (_a = params.color) !== null && _a !== undefined ? _a : "#ff0000",
12642
12814
  strokeWidth: (_b = params.lineWidth) !== null && _b !== undefined ? _b : 4,
@@ -12650,9 +12822,16 @@
12650
12822
  draggable: true,
12651
12823
  strokeScaleEnabled: false
12652
12824
  });
12825
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
12826
+ x: params.position.x,
12827
+ y: params.position.y
12828
+ }));
12829
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
12830
+ x: params.position2.x,
12831
+ y: params.position2.y
12832
+ }));
12653
12833
  this._ref.on("transform", (e => {
12654
12834
  const attrs = e.target.attrs;
12655
- if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
12656
12835
  const scaleByX = Math.abs(attrs.scaleX - 1) > 1e-5;
12657
12836
  const scaleByY = Math.abs(attrs.scaleY - 1) > 1e-5;
12658
12837
  let newWidth = this._ref.width();
@@ -12674,6 +12853,32 @@
12674
12853
  y: 1
12675
12854
  });
12676
12855
  }));
12856
+ this._ref.on("transformend", (e => {
12857
+ const attrs = e.target.attrs;
12858
+ if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
12859
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
12860
+ const position = absoluteTransform.point({
12861
+ x: this._ref.x(),
12862
+ y: this._ref.y()
12863
+ });
12864
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
12865
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
12866
+ x: position.x + this._ref.width(),
12867
+ y: position.y + this._ref.height()
12868
+ }));
12869
+ }));
12870
+ this._ref.on("dragend", (e => {
12871
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
12872
+ const position = absoluteTransform.point({
12873
+ x: this._ref.x(),
12874
+ y: this._ref.y()
12875
+ });
12876
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
12877
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
12878
+ x: position.x + this._ref.width(),
12879
+ y: position.y + this._ref.height()
12880
+ }));
12881
+ }));
12677
12882
  this._ref.id(this._ref._id.toString());
12678
12883
  }
12679
12884
  getPosition() {
@@ -12687,15 +12892,37 @@
12687
12892
  }
12688
12893
  setWidth(w) {
12689
12894
  this._ref.width(w);
12895
+ const rightLowerPoint = {
12896
+ x: this._ref.x() + w,
12897
+ y: this._ref.y() + this._ref.height()
12898
+ };
12899
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
12900
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
12690
12901
  }
12691
12902
  setHeight(h) {
12692
12903
  this._ref.height(h);
12904
+ const rightLowerPoint = {
12905
+ x: this._ref.x() + this._ref.width(),
12906
+ y: this._ref.y() + h
12907
+ };
12908
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
12909
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
12693
12910
  }
12694
12911
  setPosition(x, y) {
12695
12912
  this._ref.setPosition({
12696
12913
  x: x,
12697
12914
  y: y
12698
12915
  });
12916
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
12917
+ x: x,
12918
+ y: y
12919
+ }));
12920
+ const rightLowerPoint = {
12921
+ x: x + this._ref.width(),
12922
+ y: y + this._ref.y()
12923
+ };
12924
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
12925
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
12699
12926
  }
12700
12927
  ref() {
12701
12928
  return this._ref;
@@ -12737,13 +12964,53 @@
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
+ }
12981
+ }
12982
+
12983
+ function getDistanceIn2D(p1, p2) {
12984
+ return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));
12740
12985
  }
12741
12986
 
12742
12987
  class KonvaEllipse {
12743
- constructor(params, ref = null) {
12988
+ constructor(params, ref = null, worldTransformer = new WorldTransform) {
12744
12989
  var _a, _b;
12990
+ this._worldTransformer = worldTransformer;
12745
12991
  if (ref) {
12746
12992
  this._ref = ref;
12993
+ const wcsPosition = this._ref.getAttr("wcsPosition");
12994
+ const radiusX = this._ref.getAttr("wcsRadiusX");
12995
+ const radiusY = this._ref.getAttr("wcsRadiusY");
12996
+ if (!wcsPosition) {
12997
+ this._ref.setAttr("wcsPosition", this._worldTransformer.screenToWorld({
12998
+ x: ref.x(),
12999
+ y: ref.y()
13000
+ }));
13001
+ }
13002
+ if (!radiusX) {
13003
+ this._ref.setAttr("wcsRadiusX", this._worldTransformer.screenToWorld({
13004
+ x: ref.x() + ref.radiusX(),
13005
+ y: ref.y()
13006
+ }));
13007
+ }
13008
+ if (!radiusY) {
13009
+ this._ref.setAttr("wcsRadiusY", this._worldTransformer.screenToWorld({
13010
+ x: ref.x(),
13011
+ y: ref.y() + ref.radiusY()
13012
+ }));
13013
+ }
12747
13014
  return;
12748
13015
  }
12749
13016
  if (!params) params = {};
@@ -12751,10 +13018,15 @@
12751
13018
  x: 0,
12752
13019
  y: 0
12753
13020
  };
12754
- if (!params.radius) params.radius = {
12755
- x: 25,
12756
- y: 25
12757
- };
13021
+ if (params.position2) {
13022
+ params.radius.x = getDistanceIn2D(params.position, params.position2);
13023
+ if (params.position3) params.radius.y = getDistanceIn2D(params.position, params.position3); else params.radius.x = params.radius.y;
13024
+ } else {
13025
+ if (!params.radius) params.radius = {
13026
+ x: 25,
13027
+ y: 25
13028
+ };
13029
+ }
12758
13030
  this._ref = new Konva.Ellipse({
12759
13031
  stroke: (_a = params.color) !== null && _a !== undefined ? _a : "#ff0000",
12760
13032
  strokeWidth: (_b = params.lineWidth) !== null && _b !== undefined ? _b : 4,
@@ -12768,6 +13040,18 @@
12768
13040
  draggable: true,
12769
13041
  strokeScaleEnabled: false
12770
13042
  });
13043
+ this._ref.setAttr("wcsPosition", this._worldTransformer.screenToWorld({
13044
+ x: params.position.x,
13045
+ y: params.position.y
13046
+ }));
13047
+ this._ref.setAttr("wcsRadiusX", this._worldTransformer.screenToWorld({
13048
+ x: this._ref.x() + params.radius.x,
13049
+ y: this._ref.y()
13050
+ }));
13051
+ this._ref.setAttr("wcsRadiusY", this._worldTransformer.screenToWorld({
13052
+ x: this._ref.x(),
13053
+ y: this._ref.y() + params.radius.y
13054
+ }));
12771
13055
  this._ref.on("transform", (e => {
12772
13056
  const attrs = e.target.attrs;
12773
13057
  if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
@@ -12804,6 +13088,42 @@
12804
13088
  y: 1
12805
13089
  });
12806
13090
  }));
13091
+ this._ref.on("transformend", (e => {
13092
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
13093
+ const position = absoluteTransform.point({
13094
+ x: this._ref.x(),
13095
+ y: this._ref.y()
13096
+ });
13097
+ this._ref.setAttr("wcsPosition", this._worldTransformer.screenToWorld(position));
13098
+ const radiusX = absoluteTransform.point({
13099
+ x: this._ref.x() + this._ref.radiusX(),
13100
+ y: this._ref.y()
13101
+ });
13102
+ this._ref.setAttr("wcsRadiusX", this._worldTransformer.screenToWorld(radiusX));
13103
+ const radiusY = absoluteTransform.point({
13104
+ x: this._ref.x(),
13105
+ y: this._ref.y() + this._ref.radiusY()
13106
+ });
13107
+ this._ref.setAttr("wcsRadiusY", this._worldTransformer.screenToWorld(radiusY));
13108
+ }));
13109
+ this._ref.on("dragend", (e => {
13110
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
13111
+ const position = absoluteTransform.point({
13112
+ x: this._ref.x(),
13113
+ y: this._ref.y()
13114
+ });
13115
+ this._ref.setAttr("wcsPosition", this._worldTransformer.screenToWorld(position));
13116
+ const radiusX = absoluteTransform.point({
13117
+ x: this._ref.x() + this._ref.radiusX(),
13118
+ y: this._ref.y()
13119
+ });
13120
+ this._ref.setAttr("wcsRadiusX", this._worldTransformer.screenToWorld(radiusX));
13121
+ const radiusY = absoluteTransform.point({
13122
+ x: this._ref.x(),
13123
+ y: this._ref.y() + this._ref.radiusY()
13124
+ });
13125
+ this._ref.setAttr("wcsRadiusY", this._worldTransformer.screenToWorld(radiusY));
13126
+ }));
12807
13127
  this._ref.id(this._ref._id.toString());
12808
13128
  }
12809
13129
  getPosition() {
@@ -12814,18 +13134,30 @@
12814
13134
  x: x,
12815
13135
  y: y
12816
13136
  });
13137
+ this._ref.setAttr("wcsPosition", this._worldTransformer.screenToWorld({
13138
+ x: x,
13139
+ y: y
13140
+ }));
12817
13141
  }
12818
13142
  getRadiusX() {
12819
13143
  return this._ref.radiusX();
12820
13144
  }
12821
13145
  setRadiusX(r) {
12822
13146
  this._ref.radiusX(r);
13147
+ this._ref.setAttr("wcsRadiusX", this._worldTransformer.screenToWorld({
13148
+ x: this._ref.x() + r,
13149
+ y: this._ref.y()
13150
+ }));
12823
13151
  }
12824
13152
  getRadiusY() {
12825
13153
  return this._ref.radiusY();
12826
13154
  }
12827
13155
  setRadiusY(r) {
12828
13156
  this._ref.radiusY(r);
13157
+ this._ref.setAttr("wcsRadiusY", this._worldTransformer.screenToWorld({
13158
+ x: this._ref.x(),
13159
+ y: this._ref.y() + r
13160
+ }));
12829
13161
  }
12830
13162
  getLineWidth() {
12831
13163
  return this._ref.strokeWidth();
@@ -12867,13 +13199,43 @@
12867
13199
  this._ref.destroy();
12868
13200
  this._ref = null;
12869
13201
  }
13202
+ updateScreenCoordinates() {
13203
+ let screenPosition = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsPosition"));
13204
+ let radiusX = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsRadiusX"));
13205
+ let radiusY = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsRadiusY"));
13206
+ let invert = this._ref.getStage().getAbsoluteTransform().copy();
13207
+ invert = invert.invert();
13208
+ const position = invert.point({
13209
+ x: screenPosition.x,
13210
+ y: screenPosition.y
13211
+ });
13212
+ this._ref.position({
13213
+ x: position.x,
13214
+ y: position.y
13215
+ });
13216
+ this._ref.radius({
13217
+ x: Math.abs(invert.point(radiusX).x - position.x),
13218
+ y: Math.abs(invert.point(radiusY).y - position.y)
13219
+ });
13220
+ }
12870
13221
  }
12871
13222
 
12872
13223
  class KonvaArrow {
12873
- constructor(params, ref = null) {
13224
+ constructor(params, ref = null, worldTransformer = new WorldTransform) {
12874
13225
  var _a, _b;
13226
+ this._worldTransformer = worldTransformer;
12875
13227
  if (ref) {
12876
13228
  this._ref = ref;
13229
+ const wcsStart = this._ref.getAttr("wcsStart");
13230
+ const wcsEnd = this._ref.getAttr("wcsEnd");
13231
+ if (!wcsStart) this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
13232
+ x: ref.points()[0],
13233
+ y: ref.points()[1]
13234
+ }));
13235
+ if (!wcsEnd) this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
13236
+ x: ref.points()[2],
13237
+ y: ref.points()[3]
13238
+ }));
12877
13239
  return;
12878
13240
  }
12879
13241
  if (!params) params = {};
@@ -12896,9 +13258,43 @@
12896
13258
  draggable: true,
12897
13259
  strokeScaleEnabled: false
12898
13260
  });
12899
- this._ref.on("transform", (e => {
13261
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
13262
+ x: params.start.x,
13263
+ y: params.start.y
13264
+ }));
13265
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
13266
+ x: params.end.x,
13267
+ y: params.end.y
13268
+ }));
13269
+ this._ref.on("transformend", (e => {
12900
13270
  const attrs = e.target.attrs;
12901
13271
  if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
13272
+ const points = this._ref.points();
13273
+ const absoluteTransform = this._ref.getAbsoluteTransform();
13274
+ const transformStart = absoluteTransform.point({
13275
+ x: points[0],
13276
+ y: points[1]
13277
+ });
13278
+ const transformEnd = absoluteTransform.point({
13279
+ x: points[2],
13280
+ y: points[3]
13281
+ });
13282
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(transformStart));
13283
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld(transformEnd));
13284
+ }));
13285
+ this._ref.on("dragend", (e => {
13286
+ const points = this._ref.points();
13287
+ const absoluteTransform = e.target.getAbsoluteTransform();
13288
+ const transformStart = absoluteTransform.point({
13289
+ x: points[0],
13290
+ y: points[1]
13291
+ });
13292
+ const transformEnd = absoluteTransform.point({
13293
+ x: points[2],
13294
+ y: points[3]
13295
+ });
13296
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(transformStart));
13297
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld(transformEnd));
12902
13298
  }));
12903
13299
  this._ref.id(this._ref._id.toString());
12904
13300
  }
@@ -12949,6 +13345,14 @@
12949
13345
  }
12950
13346
  setPoints(points) {
12951
13347
  if (points.length === 2) {
13348
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
13349
+ x: points[0].x,
13350
+ y: points[0].y
13351
+ }));
13352
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
13353
+ x: points[1].x,
13354
+ y: points[1].y
13355
+ }));
12952
13356
  this._ref.points([ points[0].x, points[0].y, points[1].x, points[1].y ]);
12953
13357
  }
12954
13358
  }
@@ -12962,6 +13366,10 @@
12962
13366
  setStartPoint(x, y) {
12963
13367
  const points = this._ref.points();
12964
13368
  this._ref.points([ x, y, points[2], points[3] ]);
13369
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
13370
+ x: x,
13371
+ y: y
13372
+ }));
12965
13373
  }
12966
13374
  getEndPoint() {
12967
13375
  const points = this._ref.points();
@@ -12973,16 +13381,36 @@
12973
13381
  setEndPoint(x, y) {
12974
13382
  const points = this._ref.points();
12975
13383
  this._ref.points([ points[0], points[1], x, y ]);
13384
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
13385
+ x: x,
13386
+ y: y
13387
+ }));
13388
+ }
13389
+ updateScreenCoordinates() {
13390
+ let screenStartPoint = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
13391
+ let screenEndPoint = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));
13392
+ let invert = this._ref.getAbsoluteTransform().copy();
13393
+ invert = invert.invert();
13394
+ const startPoint = invert.point({
13395
+ x: screenStartPoint.x,
13396
+ y: screenStartPoint.y
13397
+ });
13398
+ const endPoint = invert.point({
13399
+ x: screenEndPoint.x,
13400
+ y: screenEndPoint.y
13401
+ });
13402
+ this._ref.points([ startPoint.x, startPoint.y, endPoint.x, endPoint.y ]);
12976
13403
  }
12977
13404
  }
12978
13405
 
12979
13406
  class KonvaImage {
12980
- constructor(params, ref = null) {
13407
+ constructor(params, ref = null, worldTransformer = new WorldTransform) {
12981
13408
  var _a, _b;
12982
13409
  this._ratio = 1;
12983
13410
  this.EPSILON = 1e-5;
12984
13411
  this.BASE64_HEADER_START = "data:image/";
12985
13412
  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=";
13413
+ this._worldTransformer = worldTransformer;
12986
13414
  if (ref) {
12987
13415
  if (!ref.src || !ref.src.startsWith(this.BASE64_HEADER_START)) ref.src = this.BASE64_NOT_FOUND;
12988
13416
  if (ref.height() <= this.EPSILON) ref.height(32);
@@ -12990,6 +13418,24 @@
12990
13418
  this._ref = ref;
12991
13419
  this._canvasImage = ref.image();
12992
13420
  this._ratio = this._ref.height() <= this.EPSILON || this._ref.width() <= this.EPSILON ? 1 : this._ref.height() / this._ref.width();
13421
+ const wcsStart = this._ref.getAttr("wcsStart");
13422
+ const wcsEnd = this._ref.getAttr("wcsEnd");
13423
+ if (!wcsStart) {
13424
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
13425
+ x: ref.x(),
13426
+ y: ref.y()
13427
+ }));
13428
+ }
13429
+ if (!wcsEnd) {
13430
+ const rightBottomPoint = {
13431
+ x: ref.x() + ref.width(),
13432
+ y: ref.y() + ref.height()
13433
+ };
13434
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
13435
+ x: rightBottomPoint.x,
13436
+ y: rightBottomPoint.y
13437
+ }));
13438
+ }
12993
13439
  return;
12994
13440
  }
12995
13441
  if (!params) params = {};
@@ -12998,6 +13444,10 @@
12998
13444
  y: 0
12999
13445
  };
13000
13446
  if (!params.src || !params.src.startsWith(this.BASE64_HEADER_START)) params.src = this.BASE64_NOT_FOUND;
13447
+ if (params.position2) {
13448
+ params.width = params.position2.x - params.position.x;
13449
+ params.height = params.position2.y - params.position.y;
13450
+ }
13001
13451
  this._canvasImage = new Image;
13002
13452
  this._canvasImage.onload = () => {
13003
13453
  this._ref.image(this._canvasImage);
@@ -13015,6 +13465,11 @@
13015
13465
  this._ref.width(params.maxHeight / this._ratio);
13016
13466
  this._ref.height(params.maxHeight);
13017
13467
  }
13468
+ const wcsEnd = this._worldTransformer.screenToWorld({
13469
+ x: params.position.x + this._ref.width(),
13470
+ y: params.position.y + this._ref.height()
13471
+ });
13472
+ this._ref.setAttr("wcsEnd", wcsEnd);
13018
13473
  }
13019
13474
  }
13020
13475
  };
@@ -13031,6 +13486,10 @@
13031
13486
  height: (_b = params.height) !== null && _b !== undefined ? _b : 0,
13032
13487
  draggable: true
13033
13488
  });
13489
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
13490
+ x: params.position.x,
13491
+ y: params.position.y
13492
+ }));
13034
13493
  this._ref.on("transform", (e => {
13035
13494
  const attrs = e.target.attrs;
13036
13495
  if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
@@ -13061,6 +13520,30 @@
13061
13520
  y: 1
13062
13521
  });
13063
13522
  }));
13523
+ this._ref.on("transformend", (e => {
13524
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
13525
+ const position = absoluteTransform.point({
13526
+ x: this._ref.x(),
13527
+ y: this._ref.y()
13528
+ });
13529
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
13530
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
13531
+ x: position.x + this._ref.width(),
13532
+ y: position.y + this._ref.height()
13533
+ }));
13534
+ }));
13535
+ this._ref.on("dragend", (e => {
13536
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
13537
+ const position = absoluteTransform.point({
13538
+ x: this._ref.x(),
13539
+ y: this._ref.y()
13540
+ });
13541
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
13542
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
13543
+ x: position.x + this._ref.width(),
13544
+ y: position.y + this._ref.height()
13545
+ }));
13546
+ }));
13064
13547
  this._ref.id(this._ref._id.toString());
13065
13548
  }
13066
13549
  getSrc() {
@@ -13075,6 +13558,12 @@
13075
13558
  setWidth(w) {
13076
13559
  this._ref.width(w);
13077
13560
  this._ref.height(w * this._ratio);
13561
+ const rightLowerPoint = {
13562
+ x: this._ref.x() + w,
13563
+ y: this._ref.y() + this._ref.height()
13564
+ };
13565
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
13566
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
13078
13567
  }
13079
13568
  getHeight() {
13080
13569
  return this._ref.height();
@@ -13082,6 +13571,12 @@
13082
13571
  setHeight(h) {
13083
13572
  this._ref.height(h);
13084
13573
  this._ref.width(h / this._ratio);
13574
+ const rightLowerPoint = {
13575
+ x: this._ref.x() + this._ref.width(),
13576
+ y: this._ref.y() + h
13577
+ };
13578
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
13579
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
13085
13580
  }
13086
13581
  ref() {
13087
13582
  return this._ref;
@@ -13119,14 +13614,57 @@
13119
13614
  x: x,
13120
13615
  y: y
13121
13616
  });
13617
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
13618
+ x: x,
13619
+ y: y
13620
+ }));
13621
+ const rightLowerPoint = {
13622
+ x: x + this._ref.width(),
13623
+ y: y + this._ref.y()
13624
+ };
13625
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
13626
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
13627
+ }
13628
+ updateScreenCoordinates() {
13629
+ let screenPositionStart = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
13630
+ let screenPositionEnd = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));
13631
+ let invert = this._ref.getStage().getAbsoluteTransform().copy();
13632
+ invert = invert.invert();
13633
+ const positionStart = invert.point(screenPositionStart);
13634
+ const positionEnd = invert.point(screenPositionEnd);
13635
+ this._ref.position({
13636
+ x: positionStart.x,
13637
+ y: positionStart.y
13638
+ });
13639
+ this._ref.width(Math.abs(positionEnd.x - positionStart.x));
13640
+ this._ref.height(Math.abs(positionEnd.y - positionStart.y));
13122
13641
  }
13123
13642
  }
13124
13643
 
13125
13644
  class KonvaCloud {
13126
- constructor(params, ref = null) {
13645
+ constructor(params, ref = null, worldTransformer = new WorldTransform) {
13127
13646
  var _a, _b, _c, _d;
13647
+ this._worldTransformer = worldTransformer;
13128
13648
  if (ref) {
13129
13649
  this._ref = ref;
13650
+ const wcsStart = this._ref.getAttr("wcsStart");
13651
+ const wcsEnd = this._ref.getAttr("wcsEnd");
13652
+ if (!wcsStart) {
13653
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
13654
+ x: ref.x(),
13655
+ y: ref.y()
13656
+ }));
13657
+ }
13658
+ if (!wcsEnd) {
13659
+ const rightBottomPoint = {
13660
+ x: ref.x() + ref.width(),
13661
+ y: ref.y() + ref.height()
13662
+ };
13663
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
13664
+ x: rightBottomPoint.x,
13665
+ y: rightBottomPoint.y
13666
+ }));
13667
+ }
13130
13668
  return;
13131
13669
  }
13132
13670
  if (!params) params = {};
@@ -13134,7 +13672,25 @@
13134
13672
  x: 0,
13135
13673
  y: 0
13136
13674
  };
13137
- const arcRadius = 16;
13675
+ if (params.position2) {
13676
+ params.width = params.position2.x - params.position.x;
13677
+ params.height = params.position2.y - params.position.y;
13678
+ } else {
13679
+ if (!params.width || !params.height) {
13680
+ params.position2 = {
13681
+ x: 200,
13682
+ y: 200
13683
+ };
13684
+ params.width = 200;
13685
+ params.height = 200;
13686
+ } else {
13687
+ params.position2 = {
13688
+ x: params.position.x + params.width,
13689
+ y: params.position.y + params.height
13690
+ };
13691
+ }
13692
+ }
13693
+ const ARC_RADIUS = 16;
13138
13694
  this._ref = new Konva.Shape({
13139
13695
  x: params.position.x,
13140
13696
  y: params.position.y,
@@ -13193,9 +13749,9 @@
13193
13749
  const counterClockwise = pX > midPoint.x && pY > midPoint.y;
13194
13750
  for (let iArc = 0; iArc < arcCount; iArc++) {
13195
13751
  if (counterClockwise) {
13196
- context.arc(pX, pY, arcRadius, endAngle, startAngle);
13752
+ context.arc(pX, pY, ARC_RADIUS, endAngle, startAngle);
13197
13753
  } else {
13198
- context.arc(pX, pY, arcRadius, startAngle, endAngle);
13754
+ context.arc(pX, pY, ARC_RADIUS, startAngle, endAngle);
13199
13755
  }
13200
13756
  pX += dx / arcCount;
13201
13757
  pY += dy / arcCount;
@@ -13206,9 +13762,16 @@
13206
13762
  }
13207
13763
  });
13208
13764
  this._ref.className = "Cloud";
13765
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
13766
+ x: params.position.x,
13767
+ y: params.position.y
13768
+ }));
13769
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
13770
+ x: params.position2.x,
13771
+ y: params.position2.y
13772
+ }));
13209
13773
  this._ref.on("transform", (e => {
13210
13774
  const attrs = e.target.attrs;
13211
- if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
13212
13775
  const scaleByX = Math.abs(attrs.scaleX - 1) > 1e-5;
13213
13776
  const scaleByY = Math.abs(attrs.scaleY - 1) > 1e-5;
13214
13777
  let newWidth = this._ref.width();
@@ -13230,11 +13793,37 @@
13230
13793
  y: 1
13231
13794
  });
13232
13795
  }));
13796
+ this._ref.on("transformend", (e => {
13797
+ const attrs = e.target.attrs;
13798
+ if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
13799
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
13800
+ const position = absoluteTransform.point({
13801
+ x: this._ref.x(),
13802
+ y: this._ref.y()
13803
+ });
13804
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
13805
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
13806
+ x: position.x + this._ref.width(),
13807
+ y: position.y + this._ref.height()
13808
+ }));
13809
+ }));
13810
+ this._ref.on("dragend", (e => {
13811
+ const absoluteTransform = this._ref.getStage().getAbsoluteTransform();
13812
+ const position = absoluteTransform.point({
13813
+ x: this._ref.x(),
13814
+ y: this._ref.y()
13815
+ });
13816
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld(position));
13817
+ this._ref.setAttr("wcsEnd", this._worldTransformer.screenToWorld({
13818
+ x: position.x + this._ref.width(),
13819
+ y: position.y + this._ref.height()
13820
+ }));
13821
+ }));
13233
13822
  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
13823
+ x: 0 - ARC_RADIUS,
13824
+ y: 0 - ARC_RADIUS,
13825
+ width: this._ref.width() + 2 * ARC_RADIUS,
13826
+ height: this._ref.height() + 2 * ARC_RADIUS
13238
13827
  });
13239
13828
  this._ref.id(this._ref._id.toString());
13240
13829
  }
@@ -13280,18 +13869,40 @@
13280
13869
  x: x,
13281
13870
  y: y
13282
13871
  });
13872
+ this._ref.setAttr("wcsStart", this._worldTransformer.screenToWorld({
13873
+ x: x,
13874
+ y: y
13875
+ }));
13876
+ const rightLowerPoint = {
13877
+ x: x + this._ref.width(),
13878
+ y: y + this._ref.y()
13879
+ };
13880
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
13881
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
13283
13882
  }
13284
13883
  getWidth() {
13285
13884
  return this._ref.width();
13286
13885
  }
13287
13886
  setWidth(w) {
13288
13887
  this._ref.width(w);
13888
+ const rightLowerPoint = {
13889
+ x: this._ref.x() + w,
13890
+ y: this._ref.y() + this._ref.height()
13891
+ };
13892
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
13893
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
13289
13894
  }
13290
13895
  getHeigth() {
13291
13896
  return this._ref.height();
13292
13897
  }
13293
13898
  setHeight(h) {
13294
13899
  this._ref.height(h);
13900
+ const rightLowerPoint = {
13901
+ x: this._ref.x() + this._ref.width(),
13902
+ y: this._ref.y() + h
13903
+ };
13904
+ const wcsRightLowerPoint = this._worldTransformer.screenToWorld(rightLowerPoint);
13905
+ this._ref.setAttr("wcsEnd", wcsRightLowerPoint);
13295
13906
  }
13296
13907
  getLineWidth() {
13297
13908
  return this._ref.strokeWidth();
@@ -13299,6 +13910,20 @@
13299
13910
  setLineWidth(size) {
13300
13911
  this._ref.strokeWidth(size);
13301
13912
  }
13913
+ updateScreenCoordinates() {
13914
+ let screenPositionStart = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsStart"));
13915
+ let screenPositionEnd = this._worldTransformer.worldToScreen(this._ref.getAttr("wcsEnd"));
13916
+ let invert = this._ref.getStage().getAbsoluteTransform().copy();
13917
+ invert = invert.invert();
13918
+ const positionStart = invert.point(screenPositionStart);
13919
+ const positionEnd = invert.point(screenPositionEnd);
13920
+ this._ref.position({
13921
+ x: positionStart.x,
13922
+ y: positionStart.y
13923
+ });
13924
+ this._ref.width(Math.abs(positionEnd.x - positionStart.x));
13925
+ this._ref.height(Math.abs(positionEnd.y - positionStart.y));
13926
+ }
13302
13927
  }
13303
13928
 
13304
13929
  const MarkupMode2Konva = {
@@ -13308,37 +13933,49 @@
13308
13933
  },
13309
13934
  Line: {
13310
13935
  name: "Line",
13311
- initializer: (ref, params = null) => new KonvaLine(params, ref)
13936
+ initializer: (ref, params = null, ...attr) => new KonvaLine(params, ref, ...attr)
13312
13937
  },
13313
13938
  Text: {
13314
13939
  name: "Text",
13315
- initializer: (ref, params = null) => new KonvaText(params, ref)
13940
+ initializer: (ref, params = null, ...attr) => new KonvaText(params, ref, ...attr)
13316
13941
  },
13317
13942
  Rectangle: {
13318
13943
  name: "Rect",
13319
- initializer: (ref, params = null) => new KonvaRectangle(params, ref)
13944
+ initializer: (ref, params = null, ...attr) => new KonvaRectangle(params, ref, ...attr)
13320
13945
  },
13321
13946
  Ellipse: {
13322
13947
  name: "Ellipse",
13323
- initializer: (ref, params = null) => new KonvaEllipse(params, ref)
13948
+ initializer: (ref, params = null, ...attr) => new KonvaEllipse(params, ref, ...attr)
13324
13949
  },
13325
13950
  Arrow: {
13326
13951
  name: "Arrow",
13327
- initializer: (ref, params = null) => new KonvaArrow(params, ref)
13952
+ initializer: (ref, params = null, ...attr) => new KonvaArrow(params, ref, ...attr)
13328
13953
  },
13329
13954
  Image: {
13330
13955
  name: "Image",
13331
- initializer: (ref, params = null) => new KonvaImage(params, ref)
13956
+ initializer: (ref, params = null, ...attr) => new KonvaImage(params, ref, ...attr)
13332
13957
  },
13333
13958
  Cloud: {
13334
13959
  name: "Cloud",
13335
- initializer: (ref, params = null) => new KonvaCloud(params, ref)
13960
+ initializer: (ref, params = null, ...attr) => new KonvaCloud(params, ref, ...attr)
13336
13961
  }
13337
13962
  };
13338
13963
 
13964
+ function debounce(func, wait) {
13965
+ let timeout = null;
13966
+ return (...args) => {
13967
+ if (timeout) {
13968
+ clearTimeout(timeout);
13969
+ }
13970
+ timeout = setTimeout((() => {
13971
+ timeout = null;
13972
+ func(...args);
13973
+ }), wait);
13974
+ };
13975
+ }
13976
+
13339
13977
  class KonvaMarkup {
13340
13978
  constructor() {
13341
- this._containerEvents = [];
13342
13979
  this._markupIsActive = false;
13343
13980
  this._markupColor = new MarkupColor(255, 0, 0);
13344
13981
  this.lineWidth = 4;
@@ -13357,25 +13994,29 @@
13357
13994
  if (!this._konvaStage) return;
13358
13995
  this._konvaStage.width(width);
13359
13996
  this._konvaStage.height(height);
13997
+ this.getObjects().forEach((markupObject => {
13998
+ markupObject.updateScreenCoordinates();
13999
+ }));
14000
+ };
14001
+ this.resizeViewer = event => {
14002
+ const {width: width, height: height} = event;
14003
+ if (!width || !height) return;
14004
+ if (!this._konvaStage) return;
14005
+ this._konvaStage.width(width);
14006
+ this._konvaStage.height(height);
14007
+ this.getObjects().forEach((markupObject => {
14008
+ markupObject.updateScreenCoordinates();
14009
+ }));
13360
14010
  };
13361
14011
  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);
14012
+ this.getObjects().forEach((markupObject => {
14013
+ markupObject.updateScreenCoordinates();
14014
+ }));
13367
14015
  };
13368
14016
  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);
14017
+ this.getObjects().forEach((markupObject => {
14018
+ markupObject.updateScreenCoordinates();
14019
+ }));
13379
14020
  };
13380
14021
  this.redirectToViewer = event => {
13381
14022
  if (this._viewer) this._viewer.emit(event);
@@ -13392,7 +14033,6 @@
13392
14033
  this._viewer = viewer;
13393
14034
  this._worldTransformer = worldTransformer !== null && worldTransformer !== undefined ? worldTransformer : new WorldTransform;
13394
14035
  this._container = container;
13395
- this._containerEvents = containerEvents !== null && containerEvents !== undefined ? containerEvents : [];
13396
14036
  this._markupContainer = document.createElement("div");
13397
14037
  this._markupContainer.id = "markup-container";
13398
14038
  this._markupContainer.style.position = "absolute";
@@ -13402,8 +14042,7 @@
13402
14042
  this._markupContainer.style.pointerEvents = "none";
13403
14043
  const parentDiv = this._container.parentElement;
13404
14044
  parentDiv.appendChild(this._markupContainer);
13405
- this._resizeObserver = new ResizeObserver(this.resizeContainer);
13406
- this._resizeObserver.observe(parentDiv);
14045
+ if (viewer) this._viewer.addEventListener("resize", this.resizeViewer); else this._resizeObserver = new ResizeObserver(debounce(this.resizeContainer, 100));
13407
14046
  this._markupColor.setColor(255, 0, 0);
13408
14047
  this.initializeKonva();
13409
14048
  if (this._viewer) {
@@ -13498,11 +14137,14 @@
13498
14137
  }));
13499
14138
  (_d = viewpoint.rectangles) === null || _d === undefined ? undefined : _d.forEach((rect => {
13500
14139
  const screenPoint = this._worldTransformer.worldToScreen(rect.position);
13501
- this.addRectangle(screenPoint, rect.width, rect.height, rect.line_width, rect.color, rect.id);
14140
+ const screenPoint2 = rect.position2 ? this._worldTransformer.worldToScreen(rect.position2) : null;
14141
+ this.addRectangle(screenPoint, screenPoint2, rect.width, rect.height, rect.line_width, rect.color, rect.id);
13502
14142
  }));
13503
14143
  (_e = viewpoint.ellipses) === null || _e === undefined ? undefined : _e.forEach((ellipse => {
13504
14144
  const screenPoint = this._worldTransformer.worldToScreen(ellipse.position);
13505
- this.addEllipse(screenPoint, ellipse.radius, ellipse.line_width, ellipse.color, ellipse.id);
14145
+ const screenPoint2 = ellipse.position2 ? this._worldTransformer.worldToScreen(ellipse.position2) : null;
14146
+ const screenPoint3 = ellipse.position3 ? this._worldTransformer.worldToScreen(ellipse.position3) : null;
14147
+ this.addEllipse(screenPoint, screenPoint2, screenPoint3, ellipse.radius, ellipse.line_width, ellipse.color, ellipse.id);
13506
14148
  }));
13507
14149
  (_f = viewpoint.arrows) === null || _f === undefined ? undefined : _f.forEach((arrow => {
13508
14150
  const startPoint = this._worldTransformer.worldToScreen(arrow.start);
@@ -13511,11 +14153,13 @@
13511
14153
  }));
13512
14154
  (_g = viewpoint.clouds) === null || _g === undefined ? undefined : _g.forEach((cloud => {
13513
14155
  const screenPoint = this._worldTransformer.worldToScreen(cloud.position);
13514
- this.addCloud(screenPoint, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
14156
+ const screenPoint2 = cloud.position2 ? this._worldTransformer.worldToScreen(cloud.position2) : null;
14157
+ this.addCloud(screenPoint, screenPoint2, cloud.width, cloud.height, cloud.line_width, cloud.color, cloud.id);
13515
14158
  }));
13516
14159
  (_h = viewpoint.images) === null || _h === undefined ? undefined : _h.forEach((image => {
13517
14160
  const screenPoint = this._worldTransformer.worldToScreen(image.position);
13518
- this.addImage(screenPoint, image.src, image.width, image.height, image.id);
14161
+ const screenPoint2 = image.position2 ? this._worldTransformer.worldToScreen(image.position2) : null;
14162
+ this.addImage(screenPoint, screenPoint2, image.src, image.width, image.height, image.id);
13519
14163
  }));
13520
14164
  }
13521
14165
  getViewpoint(viewpoint) {
@@ -13552,7 +14196,7 @@
13552
14196
  createObject(type, params) {
13553
14197
  const konvaShape = MarkupMode2Konva[type];
13554
14198
  if (!konvaShape || !konvaShape.initializer) throw new Error(`Markup CreateObject - unsupported markup type ${type}`);
13555
- const object = konvaShape.initializer(null, params);
14199
+ const object = konvaShape.initializer(null, params, this._worldTransformer);
13556
14200
  this.addObject(object);
13557
14201
  return object;
13558
14202
  }
@@ -13560,7 +14204,7 @@
13560
14204
  const objects = [];
13561
14205
  Object.keys(MarkupMode2Konva).forEach((type => {
13562
14206
  const konvaShape = MarkupMode2Konva[type];
13563
- this.konvaLayerFind(type).forEach((ref => objects.push(konvaShape.initializer(ref))));
14207
+ this.konvaLayerFind(type).forEach((ref => objects.push(konvaShape.initializer(ref, null, this._worldTransformer))));
13564
14208
  }));
13565
14209
  return objects;
13566
14210
  }
@@ -13569,7 +14213,7 @@
13569
14213
  return this._konvaTransformer.nodes().map((ref => {
13570
14214
  const name = ref.className;
13571
14215
  const konvaShape = Object.values(MarkupMode2Konva).find((shape => shape.name === name));
13572
- return konvaShape ? konvaShape.initializer(ref) : null;
14216
+ return konvaShape ? konvaShape.initializer(ref, null, this._worldTransformer) : null;
13573
14217
  })).filter((x => x));
13574
14218
  }
13575
14219
  selectObjects(objects) {
@@ -13645,12 +14289,12 @@
13645
14289
  this.addRectangle({
13646
14290
  x: startX,
13647
14291
  y: startY
13648
- }, dX, dY);
14292
+ }, null, dX, dY);
13649
14293
  } else if (this._markupMode === "Ellipse") {
13650
14294
  this.addEllipse({
13651
14295
  x: startX,
13652
14296
  y: startY
13653
- }, {
14297
+ }, null, null, {
13654
14298
  x: dX / 2,
13655
14299
  y: dY / 2
13656
14300
  });
@@ -13666,7 +14310,7 @@
13666
14310
  this.addCloud({
13667
14311
  x: startX,
13668
14312
  y: startY
13669
- }, Math.max(100, dX), Math.max(100, dY));
14313
+ }, null, Math.max(100, dX), Math.max(100, dY));
13670
14314
  }
13671
14315
  }
13672
14316
  }
@@ -13705,7 +14349,7 @@
13705
14349
  } else lastObj = this.addRectangle({
13706
14350
  x: startX,
13707
14351
  y: startY
13708
- }, dX, dY);
14352
+ }, null, dX, dY);
13709
14353
  } else if (this._markupMode === "Ellipse") {
13710
14354
  if (lastObj) {
13711
14355
  lastObj.setPosition(startX, startY);
@@ -13714,7 +14358,7 @@
13714
14358
  } else lastObj = this.addEllipse({
13715
14359
  x: startX,
13716
14360
  y: startY
13717
- }, {
14361
+ }, null, null, {
13718
14362
  x: dX,
13719
14363
  y: dY
13720
14364
  });
@@ -13726,7 +14370,7 @@
13726
14370
  } else lastObj = this.addCloud({
13727
14371
  x: startX,
13728
14372
  y: startY
13729
- }, dX, dY);
14373
+ }, null, dX, dY);
13730
14374
  }
13731
14375
  }));
13732
14376
  stage.on("click tap", (e => {
@@ -13741,7 +14385,7 @@
13741
14385
  if (this._imageInputRef && this._imageInputRef.value) this.addImage({
13742
14386
  x: this._imageInputPos.x,
13743
14387
  y: this._imageInputPos.y
13744
- }, this._imageInputRef.value, 0, 0, this._imageInputRef.value); else if (transformer.nodes().length === 0) {
14388
+ }, null, this._imageInputRef.value, 0, 0, this._imageInputRef.value); else if (transformer.nodes().length === 0) {
13745
14389
  const pos = this.getRelativePointerPosition(stage);
13746
14390
  this.createImageInput(pos);
13747
14391
  }
@@ -13762,7 +14406,7 @@
13762
14406
  }
13763
14407
  if (this._markupMode === "Image" || this._markupMode === "SelectMarkup") {
13764
14408
  if (e.target.className === "Image" && transformer.nodes().length === 1 && transformer.nodes()[0] === e.target) {
13765
- if (this._imageInputRef && this._imageInputRef.value) this.addImage(this._imageInputPos, this._imageInputRef.value, 0, 0); else this.createImageInput({
14409
+ if (this._imageInputRef && this._imageInputRef.value) this.addImage(this._imageInputPos, null, this._imageInputRef.value, 0, 0); else this.createImageInput({
13766
14410
  x: e.target.attrs.x,
13767
14411
  y: e.target.attrs.y
13768
14412
  });
@@ -13818,22 +14462,12 @@
13818
14462
  getMarkupLines() {
13819
14463
  const lines = [];
13820
14464
  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);
14465
+ const wcsPoints = ref.getAttr("wcsPoints");
14466
+ if (!wcsPoints) return;
14467
+ const konvaLine = new KonvaLine(null, ref, this._worldTransformer);
13834
14468
  const line = {
13835
14469
  id: konvaLine.id(),
13836
- points: worldPoints,
14470
+ points: wcsPoints,
13837
14471
  color: konvaLine.getColor() || "#ff0000",
13838
14472
  type: konvaLine.getLineType() || this.lineType,
13839
14473
  width: konvaLine.getLineWidth() || this.lineWidth
@@ -13847,17 +14481,12 @@
13847
14481
  this.konvaLayerFind("Text").forEach((ref => {
13848
14482
  const textSize = .02;
13849
14483
  const textScale = this._worldTransformer.getScale();
13850
- const position = ref.position();
14484
+ const wcsPosition = ref.getAttr("wcsStart");
13851
14485
  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);
14486
+ const shape = new KonvaText(null, ref, this._worldTransformer);
13858
14487
  const text = {
13859
14488
  id: shape.id(),
13860
- position: worldPoint,
14489
+ position: wcsPosition,
13861
14490
  text: shape.getText(),
13862
14491
  text_size: textSize * textScale.y,
13863
14492
  angle: shape.getRotation(),
@@ -13871,20 +14500,17 @@
13871
14500
  getMarkupRectangles() {
13872
14501
  const rectangles = [];
13873
14502
  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);
14503
+ const wcsStart = ref.getAttr("wcsStart");
14504
+ const wcsEnd = ref.getAttr("wcsEnd");
14505
+ const screenStart = this._worldTransformer.worldToScreen(wcsStart);
14506
+ const screenEnd = this._worldTransformer.worldToScreen(wcsEnd);
14507
+ const shape = new KonvaRectangle(null, ref, this._worldTransformer);
13883
14508
  const rectangle = {
13884
14509
  id: shape.id(),
13885
- position: worldPoint,
13886
- width: shape.getWidth() * scale,
13887
- height: shape.getHeigth() * scale,
14510
+ position: wcsStart,
14511
+ position2: wcsEnd,
14512
+ width: Math.abs(screenStart.x - screenEnd.x),
14513
+ height: Math.abs(screenStart.y - screenEnd.y),
13888
14514
  line_width: shape.getLineWidth(),
13889
14515
  color: shape.getColor()
13890
14516
  };
@@ -13895,18 +14521,17 @@
13895
14521
  getMarkupEllipses() {
13896
14522
  const ellipses = [];
13897
14523
  this.konvaLayerFind("Ellipse").forEach((ref => {
13898
- const position = ref.position();
14524
+ const wcsPosition = ref.getAttr("wcsPosition");
14525
+ const wcsPosition2 = ref.getAttr("wcsRadiusX");
14526
+ const wcsPosition3 = ref.getAttr("wcsRadiusY");
13899
14527
  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
14528
  const scale = stageAbsoluteTransform.getMatrix()[0];
13906
- const shape = new KonvaEllipse(null, ref);
14529
+ const shape = new KonvaEllipse(null, ref, this._worldTransformer);
13907
14530
  const ellipse = {
13908
14531
  id: shape.id(),
13909
- position: worldPoint,
14532
+ position: wcsPosition,
14533
+ position2: wcsPosition2,
14534
+ position3: wcsPosition3,
13910
14535
  radius: {
13911
14536
  x: ref.getRadiusX() * scale,
13912
14537
  y: ref.getRadiusY() * scale
@@ -13921,22 +14546,13 @@
13921
14546
  getMarkupArrows() {
13922
14547
  const arrows = [];
13923
14548
  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);
14549
+ const wcsStart = ref.getAttr("wcsStart");
14550
+ const wcsEnd = ref.getAttr("wcsEnd");
14551
+ const shape = new KonvaArrow(null, ref, this._worldTransformer);
13936
14552
  const arrow = {
13937
14553
  id: shape.id(),
13938
- start: worldStartPoint,
13939
- end: worldEndPoint,
14554
+ start: wcsStart,
14555
+ end: wcsEnd,
13940
14556
  color: shape.getColor()
13941
14557
  };
13942
14558
  arrows.push(arrow);
@@ -13946,18 +14562,15 @@
13946
14562
  getMarkupImages() {
13947
14563
  const images = [];
13948
14564
  this.konvaLayerFind("Image").forEach((ref => {
13949
- const position = ref.position();
14565
+ const wcsStart = ref.getAttr("wcsStart");
14566
+ const wcsEnd = ref.getAttr("wcsEnd");
13950
14567
  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
14568
  const scale = stageAbsoluteTransform.getMatrix()[0];
13957
- const shape = new KonvaImage(null, ref);
14569
+ const shape = new KonvaImage(null, ref, this._worldTransformer);
13958
14570
  const image = {
13959
14571
  id: shape.id(),
13960
- position: worldPoint,
14572
+ position: wcsStart,
14573
+ position2: wcsEnd,
13961
14574
  src: shape.getSrc(),
13962
14575
  width: shape.getWidth() * scale,
13963
14576
  height: shape.getHeight() * scale
@@ -13969,20 +14582,17 @@
13969
14582
  getMarkupClouds() {
13970
14583
  const clouds = [];
13971
14584
  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);
14585
+ const wcsStart = ref.getAttr("wcsStart");
14586
+ const wcsEnd = ref.getAttr("wcsEnd");
14587
+ const screenStart = this._worldTransformer.worldToScreen(wcsStart);
14588
+ const screenEnd = this._worldTransformer.worldToScreen(wcsEnd);
14589
+ const shape = new KonvaCloud(null, ref, this._worldTransformer);
13981
14590
  const cloud = {
13982
14591
  id: shape.id(),
13983
- position: worldPoint,
13984
- width: shape.getWidth() * scale,
13985
- height: shape.getHeigth() * scale,
14592
+ position: wcsStart,
14593
+ position2: wcsEnd,
14594
+ width: Math.abs(screenStart.x - screenEnd.x),
14595
+ height: Math.abs(screenStart.y - screenEnd.y),
13986
14596
  line_width: shape.getLineWidth(),
13987
14597
  color: shape.getColor()
13988
14598
  };
@@ -14019,7 +14629,7 @@
14019
14629
  width: width || this.lineWidth,
14020
14630
  color: color || this._markupColor.asHex(),
14021
14631
  id: id
14022
- });
14632
+ }, null, this._worldTransformer);
14023
14633
  this.addObject(konvaLine);
14024
14634
  return konvaLine;
14025
14635
  }
@@ -14085,7 +14695,7 @@
14085
14695
  this.addImage({
14086
14696
  x: this._imageInputPos.x,
14087
14697
  y: this._imageInputPos.y
14088
- }, base64.toString(), 0, 0);
14698
+ }, null, base64.toString(), 0, 0);
14089
14699
  };
14090
14700
  this._imageInputRef.oncancel = event => {
14091
14701
  this.removeImageInput();
@@ -14126,32 +14736,35 @@
14126
14736
  fontSize: fontSize || this.fontSize,
14127
14737
  color: color || this._markupColor.asHex(),
14128
14738
  id: id
14129
- });
14739
+ }, null, this._worldTransformer);
14130
14740
  this.addObject(konvaText);
14131
14741
  return konvaText;
14132
14742
  }
14133
- addRectangle(position, width, height, lineWidth, color, id) {
14743
+ addRectangle(position, position2, width, height, lineWidth, color, id) {
14134
14744
  if (!position) return;
14135
14745
  const konvaRectangle = new KonvaRectangle({
14136
14746
  position: position,
14747
+ position2: position2,
14137
14748
  width: width,
14138
14749
  height: height,
14139
14750
  lineWidth: lineWidth || this.lineWidth,
14140
14751
  color: color || this._markupColor.asHex(),
14141
14752
  id: id
14142
- });
14753
+ }, null, this._worldTransformer);
14143
14754
  this.addObject(konvaRectangle);
14144
14755
  return konvaRectangle;
14145
14756
  }
14146
- addEllipse(position, radius, lineWidth, color, id) {
14757
+ addEllipse(position, position2, position3, radius, lineWidth, color, id) {
14147
14758
  if (!position) return;
14148
14759
  const konvaEllipse = new KonvaEllipse({
14149
14760
  position: position,
14761
+ position2: position2,
14762
+ position3: position3,
14150
14763
  radius: radius,
14151
14764
  lineWidth: lineWidth,
14152
14765
  color: color || this._markupColor.asHex(),
14153
14766
  id: id
14154
- });
14767
+ }, null, this._worldTransformer);
14155
14768
  this.addObject(konvaEllipse);
14156
14769
  return konvaEllipse;
14157
14770
  }
@@ -14162,24 +14775,25 @@
14162
14775
  end: end,
14163
14776
  color: color || this._markupColor.asHex(),
14164
14777
  id: id
14165
- });
14778
+ }, null, this._worldTransformer);
14166
14779
  this.addObject(konvaArrow);
14167
14780
  return konvaArrow;
14168
14781
  }
14169
- addCloud(position, width, height, lineWidth, color, id) {
14782
+ addCloud(position, position2, width, height, lineWidth, color, id) {
14170
14783
  if (!position || !width || !height) return;
14171
14784
  const konvaCloud = new KonvaCloud({
14172
14785
  position: position,
14786
+ position2: position2,
14173
14787
  width: width,
14174
14788
  height: height,
14175
14789
  color: color || this._markupColor.asHex(),
14176
14790
  lineWidth: lineWidth || this.lineWidth,
14177
14791
  id: id
14178
- });
14792
+ }, null, this._worldTransformer);
14179
14793
  this.addObject(konvaCloud);
14180
14794
  return konvaCloud;
14181
14795
  }
14182
- addImage(position, src, width, height, id) {
14796
+ addImage(position, position2, src, width, height, id) {
14183
14797
  var _a;
14184
14798
  if (!position || !src) return;
14185
14799
  (_a = this.getSelectedObjects().at(0)) === null || _a === undefined ? undefined : _a.delete();
@@ -14187,13 +14801,14 @@
14187
14801
  this.removeImageInput();
14188
14802
  const konvaImage = new KonvaImage({
14189
14803
  position: position,
14804
+ position2: position2,
14190
14805
  src: src,
14191
14806
  width: width,
14192
14807
  height: height,
14193
14808
  maxWidth: this._konvaStage.width() - position.x,
14194
14809
  maxHeight: this._konvaStage.height() - position.y,
14195
14810
  id: id
14196
- });
14811
+ }, null, this._worldTransformer);
14197
14812
  this.addObject(konvaImage);
14198
14813
  return konvaImage;
14199
14814
  }
@@ -57514,7 +58129,7 @@ void main() {
57514
58129
  // acknowledge and accept the above terms.
57515
58130
  ///////////////////////////////////////////////////////////////////////////////
57516
58131
  /**
57517
- * A commands registry. Use this registry to register custom commands.
58132
+ * Viewer commands registry. Use this registry to register custom commands.
57518
58133
  *
57519
58134
  * To implement custom command:
57520
58135
  *
@@ -57588,6 +58203,45 @@ void main() {
57588
58203
  commands.registerCommandAlias("ne", "k3DViewNE");
57589
58204
  commands.registerCommandAlias("nw", "k3DViewNW");
57590
58205
 
58206
+ ///////////////////////////////////////////////////////////////////////////////
58207
+ // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance").
58208
+ // All rights reserved.
58209
+ //
58210
+ // This software and its documentation and related materials are owned by
58211
+ // the Alliance. The software may only be incorporated into application
58212
+ // programs owned by members of the Alliance, subject to a signed
58213
+ // Membership Agreement and Supplemental Software License Agreement with the
58214
+ // Alliance. The structure and organization of this software are the valuable
58215
+ // trade secrets of the Alliance and its suppliers. The software is also
58216
+ // protected by copyright law and international treaty provisions. Application
58217
+ // programs incorporating this software must include the following statement
58218
+ // with their copyright notices:
58219
+ //
58220
+ // This application incorporates Open Design Alliance software pursuant to a
58221
+ // license agreement with Open Design Alliance.
58222
+ // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance.
58223
+ // All rights reserved.
58224
+ //
58225
+ // By use of this software, its documentation or related materials, you
58226
+ // acknowledge and accept the above terms.
58227
+ ///////////////////////////////////////////////////////////////////////////////
58228
+ class BackgroundComponent {
58229
+ constructor(viewer) {
58230
+ this.syncOptions = () => {
58231
+ this.backgroundColor.setHex(0xffffff);
58232
+ };
58233
+ this.viewer = viewer;
58234
+ this.backgroundColor = new Color(0xffffff);
58235
+ this.viewer.renderer.setClearColor(this.backgroundColor);
58236
+ this.viewer.scene.background = this.backgroundColor;
58237
+ this.viewer.addEventListener("optionschange", this.syncOptions);
58238
+ }
58239
+ dispose() {
58240
+ this.viewer.removeEventListener("optionschange", this.syncOptions);
58241
+ this.viewer.scene.background = undefined;
58242
+ }
58243
+ }
58244
+
57591
58245
  /**
57592
58246
  * https://github.com/google/model-viewer/blob/master/packages/model-viewer/src/three-components/EnvironmentScene.ts
57593
58247
  */
@@ -57744,25 +58398,16 @@ void main() {
57744
58398
  // By use of this software, its documentation or related materials, you
57745
58399
  // acknowledge and accept the above terms.
57746
58400
  ///////////////////////////////////////////////////////////////////////////////
57747
- class BackgroundComponent {
58401
+ class RoomEnvironmentComponent {
57748
58402
  constructor(viewer) {
57749
- this.syncOptions = () => {
57750
- this.backgroundColor.setHex(0xffffff);
57751
- };
57752
58403
  this.viewer = viewer;
57753
- this.backgroundColor = new Color(0xffffff);
57754
58404
  const environment = new RoomEnvironment();
57755
58405
  const pmremGenerator = new PMREMGenerator(this.viewer.renderer);
57756
- this.viewer.renderer.setClearColor(this.backgroundColor);
57757
- this.viewer.scene.background = this.backgroundColor;
57758
58406
  this.viewer.scene.environment = pmremGenerator.fromScene(environment).texture;
57759
- this.viewer.addEventListener("optionschange", this.syncOptions);
57760
58407
  environment.dispose();
57761
58408
  }
57762
58409
  dispose() {
57763
- this.viewer.removeEventListener("optionschange", this.syncOptions);
57764
58410
  this.viewer.scene.environment = undefined;
57765
- this.viewer.scene.background = undefined;
57766
58411
  }
57767
58412
  }
57768
58413
 
@@ -57791,9 +58436,11 @@ void main() {
57791
58436
  class CameraComponent {
57792
58437
  constructor(viewer) {
57793
58438
  this.geometryEnd = () => {
58439
+ const extentsCenter = this.viewer.extents.getCenter(new Vector3());
57794
58440
  const extentsSize = this.viewer.extents.getBoundingSphere(new Sphere()).radius * 2;
57795
58441
  const rendererSize = this.viewer.renderer.getSize(new Vector2());
57796
58442
  const aspect = rendererSize.x / rendererSize.y;
58443
+ // TODO: do not change the camera and target after opening the second model in "append" mode
57797
58444
  let sceneCamera;
57798
58445
  this.viewer.scene.traverse((object) => {
57799
58446
  if (object.isCamera)
@@ -57821,6 +58468,7 @@ void main() {
57821
58468
  camera.far = extentsSize * 100;
57822
58469
  camera.updateProjectionMatrix();
57823
58470
  }
58471
+ this.viewer.target.copy(extentsCenter);
57824
58472
  if (!sceneCamera) {
57825
58473
  this.viewer.executeCommand("setDefaultViewPosition");
57826
58474
  }
@@ -57861,7 +58509,6 @@ void main() {
57861
58509
  const extents = new Box3();
57862
58510
  this.viewer.scene.traverseVisible((object) => !object.children.length && extents.expandByObject(object));
57863
58511
  this.viewer.extents.copy(extents);
57864
- this.viewer.target.copy(extents.getCenter(new Vector3()));
57865
58512
  };
57866
58513
  this.viewer = viewer;
57867
58514
  this.viewer.addEventListener("databasechunk", this.syncExtents);
@@ -58166,6 +58813,7 @@ void main() {
58166
58813
  components.registerComponent("ExtentsComponent", (viewer) => new ExtentsComponent(viewer));
58167
58814
  components.registerComponent("CameraComponent", (viewer) => new CameraComponent(viewer));
58168
58815
  components.registerComponent("BackgroundComponent", (viewer) => new BackgroundComponent(viewer));
58816
+ components.registerComponent("RoomEnvironmentComponent", (viewer) => new RoomEnvironmentComponent(viewer));
58169
58817
  // components.registerComponent("LightComponent", (viewer) => new LightComponent(viewer));
58170
58818
  components.registerComponent("ResizeCanvasComponent", (viewer) => new ResizeCanvasComponent(viewer));
58171
58819
  components.registerComponent("RenderLoopComponent", (viewer) => new RenderLoopComponent(viewer));