@inweb/viewer-visualize 25.9.0 → 25.9.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.
@@ -12701,6 +12701,29 @@
12701
12701
  var libExports = lib$1.exports;
12702
12702
  var Konva = /*@__PURE__*/getDefaultExportFromCjs(libExports);
12703
12703
 
12704
+ class WorldTransform {
12705
+ screenToWorld(position) {
12706
+ return {
12707
+ x: position.x,
12708
+ y: position.y,
12709
+ z: 0
12710
+ };
12711
+ }
12712
+ worldToScreen(position) {
12713
+ return {
12714
+ x: position.x,
12715
+ y: position.y
12716
+ };
12717
+ }
12718
+ getScale() {
12719
+ return {
12720
+ x: 1,
12721
+ y: 1,
12722
+ z: 1
12723
+ };
12724
+ }
12725
+ }
12726
+
12704
12727
  class MarkupColor {
12705
12728
  constructor(r, g, b) {
12706
12729
  this.setColor(r, g, b);
@@ -12730,29 +12753,6 @@
12730
12753
  }
12731
12754
  }
12732
12755
 
12733
- class WorldTransform {
12734
- screenToWorld(position) {
12735
- return {
12736
- x: position.x,
12737
- y: position.y,
12738
- z: 0
12739
- };
12740
- }
12741
- worldToScreen(position) {
12742
- return {
12743
- x: position.x,
12744
- y: position.y
12745
- };
12746
- }
12747
- getScale() {
12748
- return {
12749
- x: 1,
12750
- y: 1,
12751
- z: 1
12752
- };
12753
- }
12754
- }
12755
-
12756
12756
  const LineTypeSpecs = new Map([ [ "solid", [] ], [ "dot", [ 30, 30, .001, 30 ] ], [ "dash", [ 30, 30 ] ] ]);
12757
12757
 
12758
12758
  class KonvaLine {
@@ -13705,16 +13705,45 @@
13705
13705
  this._konvaStage.height(height);
13706
13706
  };
13707
13707
  this.pan = event => {
13708
- const dX = event.dX / window.devicePixelRatio;
13709
- const dY = event.dY / window.devicePixelRatio;
13710
- this.getObjects().forEach((obj => obj.ref().move({
13711
- x: dX,
13712
- y: dY
13713
- })));
13708
+ const pointer = this._konvaStage.getPointerPosition();
13709
+ const pointTo = {
13710
+ x: (pointer.x - this._konvaStage.x()) / this._konvaStage.scaleX(),
13711
+ y: (pointer.y - this._konvaStage.y()) / this._konvaStage.scaleX()
13712
+ };
13713
+ const newPos = {
13714
+ x: pointer.x - pointTo.x * this._konvaStage.scale().x + event.dX,
13715
+ y: pointer.y - pointTo.y * this._konvaStage.scale().x + event.dY
13716
+ };
13717
+ this._konvaStage.position(newPos);
13718
+ };
13719
+ this.zoomAt = event => {
13720
+ const oldScale = this._konvaStage.scaleX();
13721
+ const pointer = this._konvaStage.getPointerPosition();
13722
+ const mousePointTo = {
13723
+ x: (pointer.x - this._konvaStage.x()) / oldScale,
13724
+ y: (pointer.y - this._konvaStage.y()) / oldScale
13725
+ };
13726
+ let direction = event.data > 0 ? 1 : -1;
13727
+ const newScale = direction > 0 ? oldScale * event.data : oldScale / event.data;
13728
+ this._konvaStage.scale({
13729
+ x: newScale,
13730
+ y: newScale
13731
+ });
13732
+ const newPos = {
13733
+ x: pointer.x - mousePointTo.x * newScale,
13734
+ y: pointer.y - mousePointTo.y * newScale
13735
+ };
13736
+ this._konvaStage.position(newPos);
13714
13737
  };
13715
13738
  this.redirectToViewer = event => {
13716
13739
  if (this._viewer) this._viewer.emit(event);
13717
13740
  };
13741
+ this.getRelativePointPosition = (point, node) => {
13742
+ const transform = node.getAbsoluteTransform().copy();
13743
+ transform.invert();
13744
+ return transform.point(point);
13745
+ };
13746
+ this.getRelativePointerPosition = node => this.getRelativePointPosition(node.getStage().getPointerPosition(), node);
13718
13747
  }
13719
13748
  initialize(container, containerEvents, viewer, worldTransformer) {
13720
13749
  if (!Konva) throw new Error('Markup error: Konva is not initialized. Forgot to add <script src="https://unpkg.com/konva@9/konva.min.js"><\/script> to your page?');
@@ -13738,11 +13767,13 @@
13738
13767
  this._containerEvents.forEach((x => this._markupContainer.addEventListener(x, this.redirectToViewer)));
13739
13768
  this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
13740
13769
  this._viewer.addEventListener("pan", this.pan);
13770
+ this._viewer.addEventListener("zoomat", this.zoomAt);
13741
13771
  }
13742
13772
  }
13743
13773
  dispose() {
13744
13774
  var _a, _b;
13745
13775
  if (this._viewer) {
13776
+ this._viewer.removeEventListener("zoomat", this.zoomAt);
13746
13777
  this._viewer.removeEventListener("pan", this.pan);
13747
13778
  this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
13748
13779
  this._containerEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
@@ -13789,6 +13820,14 @@
13789
13820
  this.clearSelected();
13790
13821
  this.removeTextInput();
13791
13822
  this.removeImageInput();
13823
+ this._konvaStage.scale({
13824
+ x: 1,
13825
+ y: 1
13826
+ });
13827
+ this._konvaStage.position({
13828
+ x: 0,
13829
+ y: 0
13830
+ });
13792
13831
  const markupColor = ((_a = viewpoint.custom_fields) === null || _a === void 0 ? void 0 : _a.markup_color) || {
13793
13832
  r: 255,
13794
13833
  g: 0,
@@ -13935,7 +13974,7 @@
13935
13974
  transformer.nodes([]);
13936
13975
  return;
13937
13976
  }
13938
- const pos = stage.getPointerPosition();
13977
+ const pos = this.getRelativePointerPosition(stage);
13939
13978
  mouseDownPos = pos;
13940
13979
  isPaint = [ "Arrow", "Cloud", "Ellipse", "Line", "Rectangle" ].some((m => m === this._markupMode));
13941
13980
  if (this._markupMode === "Line") {
@@ -13945,7 +13984,7 @@
13945
13984
  stage.on("mouseup touchend", (e => {
13946
13985
  if (!this._markupIsActive) return;
13947
13986
  if (isPaint) {
13948
- const pos = stage.getPointerPosition();
13987
+ const pos = this.getRelativePointerPosition(stage);
13949
13988
  const defParams = mouseDownPos && pos.x === mouseDownPos.x && pos.y === mouseDownPos.y;
13950
13989
  const startX = defParams ? mouseDownPos.x : Math.min(mouseDownPos.x, pos.x);
13951
13990
  const startY = defParams ? mouseDownPos.y : Math.min(mouseDownPos.y, pos.y);
@@ -13989,7 +14028,7 @@
13989
14028
  if (!isPaint) {
13990
14029
  return;
13991
14030
  }
13992
- const pos = stage.getPointerPosition();
14031
+ const pos = this.getRelativePointerPosition(stage);
13993
14032
  const defParams = mouseDownPos && pos.x === mouseDownPos.x && pos.y === mouseDownPos.y;
13994
14033
  const startX = defParams ? mouseDownPos.x : Math.min(mouseDownPos.x, pos.x);
13995
14034
  const startY = defParams ? mouseDownPos.y : Math.min(mouseDownPos.y, pos.y);
@@ -14045,7 +14084,7 @@
14045
14084
  if (e.target === stage) {
14046
14085
  if (this._markupMode === "Text") {
14047
14086
  if (this._textInputRef && this._textInputRef.value) this.addText(this._textInputRef.value, this._textInputPos, this._textInputAngle); else if (transformer.nodes().length === 0) {
14048
- const pos = stage.getPointerPosition();
14087
+ const pos = this.getRelativePointerPosition(stage);
14049
14088
  this.createTextInput(pos, e.evt.pageX, e.evt.pageY, 0, null);
14050
14089
  }
14051
14090
  } else if (this._markupMode === "Image") {
@@ -14053,7 +14092,7 @@
14053
14092
  x: this._imageInputPos.x,
14054
14093
  y: this._imageInputPos.y
14055
14094
  }, this._imageInputRef.value, 0, 0, this._imageInputRef.value); else if (transformer.nodes().length === 0) {
14056
- const pos = stage.getPointerPosition();
14095
+ const pos = this.getRelativePointerPosition(stage);
14057
14096
  this.createImageInput(pos);
14058
14097
  }
14059
14098
  }
@@ -14158,11 +14197,13 @@
14158
14197
  this.konvaLayerFind("Text").forEach((ref => {
14159
14198
  const textSize = .02;
14160
14199
  const textScale = this._worldTransformer.getScale();
14161
- const position = {
14162
- x: ref.x(),
14163
- y: ref.y()
14164
- };
14165
- const worldPoint = this._worldTransformer.screenToWorld(position);
14200
+ const position = ref.position();
14201
+ const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
14202
+ const atPoint = stageAbsoluteTransform.point({
14203
+ x: position.x,
14204
+ y: position.y
14205
+ });
14206
+ const worldPoint = this._worldTransformer.screenToWorld(atPoint);
14166
14207
  const shape = new KonvaText(null, ref);
14167
14208
  const text = {
14168
14209
  id: shape.id(),
@@ -14171,7 +14212,7 @@
14171
14212
  text_size: textSize * textScale.y,
14172
14213
  angle: shape.getRotation(),
14173
14214
  color: shape.getColor(),
14174
- font_size: shape.getFontSize()
14215
+ font_size: shape.getFontSize() * stageAbsoluteTransform.getMatrix()[0]
14175
14216
  };
14176
14217
  texts.push(text);
14177
14218
  }));
@@ -14181,13 +14222,19 @@
14181
14222
  const rectangles = [];
14182
14223
  this.konvaLayerFind("Rectangle").forEach((ref => {
14183
14224
  const position = ref.position();
14184
- const worldPoint = this._worldTransformer.screenToWorld(position);
14225
+ const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
14226
+ const atPoint = stageAbsoluteTransform.point({
14227
+ x: position.x,
14228
+ y: position.y
14229
+ });
14230
+ const worldPoint = this._worldTransformer.screenToWorld(atPoint);
14231
+ const scale = stageAbsoluteTransform.getMatrix()[0];
14185
14232
  const shape = new KonvaRectangle(null, ref);
14186
14233
  const rectangle = {
14187
14234
  id: shape.id(),
14188
14235
  position: worldPoint,
14189
- width: shape.getWidth(),
14190
- height: shape.getHeigth(),
14236
+ width: shape.getWidth() * scale,
14237
+ height: shape.getHeigth() * scale,
14191
14238
  line_width: shape.getLineWidth(),
14192
14239
  color: shape.getColor()
14193
14240
  };
@@ -14199,14 +14246,20 @@
14199
14246
  const ellipses = [];
14200
14247
  this.konvaLayerFind("Ellipse").forEach((ref => {
14201
14248
  const position = ref.position();
14202
- const worldPoint = this._worldTransformer.screenToWorld(position);
14249
+ const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
14250
+ const atPoint = stageAbsoluteTransform.point({
14251
+ x: position.x,
14252
+ y: position.y
14253
+ });
14254
+ const worldPoint = this._worldTransformer.screenToWorld(atPoint);
14255
+ const scale = stageAbsoluteTransform.getMatrix()[0];
14203
14256
  const shape = new KonvaEllipse(null, ref);
14204
14257
  const ellipse = {
14205
14258
  id: shape.id(),
14206
14259
  position: worldPoint,
14207
14260
  radius: {
14208
- x: ref.getRadiusX(),
14209
- y: ref.getRadiusY()
14261
+ x: ref.getRadiusX() * scale,
14262
+ y: ref.getRadiusY() * scale
14210
14263
  },
14211
14264
  line_width: shape.getLineWidth(),
14212
14265
  color: shape.getColor()
@@ -14244,14 +14297,20 @@
14244
14297
  const images = [];
14245
14298
  this.konvaLayerFind("Image").forEach((ref => {
14246
14299
  const position = ref.position();
14247
- const worldPoint = this._worldTransformer.screenToWorld(position);
14300
+ const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
14301
+ const atPoint = stageAbsoluteTransform.point({
14302
+ x: position.x,
14303
+ y: position.y
14304
+ });
14305
+ const worldPoint = this._worldTransformer.screenToWorld(atPoint);
14306
+ const scale = stageAbsoluteTransform.getMatrix()[0];
14248
14307
  const shape = new KonvaImage(null, ref);
14249
14308
  const image = {
14250
14309
  id: shape.id(),
14251
14310
  position: worldPoint,
14252
14311
  src: shape.getSrc(),
14253
- width: shape.getWidth(),
14254
- height: shape.getHeight()
14312
+ width: shape.getWidth() * scale,
14313
+ height: shape.getHeight() * scale
14255
14314
  };
14256
14315
  images.push(image);
14257
14316
  }));
@@ -14261,13 +14320,19 @@
14261
14320
  const clouds = [];
14262
14321
  this.konvaLayerFind("Cloud").forEach((ref => {
14263
14322
  const position = ref.position();
14264
- const worldPoint = this._worldTransformer.screenToWorld(position);
14323
+ const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
14324
+ const atPoint = stageAbsoluteTransform.point({
14325
+ x: position.x,
14326
+ y: position.y
14327
+ });
14328
+ const worldPoint = this._worldTransformer.screenToWorld(atPoint);
14329
+ const scale = stageAbsoluteTransform.getMatrix()[0];
14265
14330
  const shape = new KonvaCloud(null, ref);
14266
14331
  const cloud = {
14267
14332
  id: shape.id(),
14268
14333
  position: worldPoint,
14269
- width: shape.getWidth(),
14270
- height: shape.getHeigth(),
14334
+ width: shape.getWidth() * scale,
14335
+ height: shape.getHeigth() * scale,
14271
14336
  line_width: shape.getLineWidth(),
14272
14337
  color: shape.getColor()
14273
14338
  };
@@ -15978,7 +16043,7 @@
15978
16043
  this.beginInteractivity();
15979
16044
  }
15980
16045
  drag(x, y, dltX, dltY) {
15981
- if (this.press && Math.abs(dltY) <= 10e-6) {
16046
+ if (this.press && Math.abs(dltY) >= 10e-6) {
15982
16047
  const ZOOM_SPEED = 0.025;
15983
16048
  const zoomFactor = dltY > 0 ? 1 + ZOOM_SPEED : 1 - ZOOM_SPEED;
15984
16049
  this._zoomAction.action(this.pressX, this.pressY, zoomFactor);