@inweb/markup 25.9.0 → 25.9.2

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.
package/dist/markup.js CHANGED
@@ -11466,6 +11466,40 @@
11466
11466
  var libExports = lib$1.exports;
11467
11467
  var Konva = /*@__PURE__*/getDefaultExportFromCjs(libExports);
11468
11468
 
11469
+ ///////////////////////////////////////////////////////////////////////////////
11470
+ // Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
11471
+ // All rights reserved.
11472
+ //
11473
+ // This software and its documentation and related materials are owned by
11474
+ // the Alliance. The software may only be incorporated into application
11475
+ // programs owned by members of the Alliance, subject to a signed
11476
+ // Membership Agreement and Supplemental Software License Agreement with the
11477
+ // Alliance. The structure and organization of this software are the valuable
11478
+ // trade secrets of the Alliance and its suppliers. The software is also
11479
+ // protected by copyright law and international treaty provisions. Application
11480
+ // programs incorporating this software must include the following statement
11481
+ // with their copyright notices:
11482
+ //
11483
+ // This application incorporates Open Design Alliance software pursuant to a
11484
+ // license agreement with Open Design Alliance.
11485
+ // Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
11486
+ // All rights reserved.
11487
+ //
11488
+ // By use of this software, its documentation or related materials, you
11489
+ // acknowledge and accept the above terms.
11490
+ ///////////////////////////////////////////////////////////////////////////////
11491
+ class WorldTransform {
11492
+ screenToWorld(position) {
11493
+ return { x: position.x, y: position.y, z: 0 };
11494
+ }
11495
+ worldToScreen(position) {
11496
+ return { x: position.x, y: position.y };
11497
+ }
11498
+ getScale() {
11499
+ return { x: 1, y: 1, z: 1 };
11500
+ }
11501
+ }
11502
+
11469
11503
  ///////////////////////////////////////////////////////////////////////////////
11470
11504
  // Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
11471
11505
  // All rights reserved.
@@ -11537,40 +11571,6 @@
11537
11571
  }
11538
11572
  }
11539
11573
 
11540
- ///////////////////////////////////////////////////////////////////////////////
11541
- // Copyright (C) 2002-2024, Open Design Alliance (the "Alliance").
11542
- // All rights reserved.
11543
- //
11544
- // This software and its documentation and related materials are owned by
11545
- // the Alliance. The software may only be incorporated into application
11546
- // programs owned by members of the Alliance, subject to a signed
11547
- // Membership Agreement and Supplemental Software License Agreement with the
11548
- // Alliance. The structure and organization of this software are the valuable
11549
- // trade secrets of the Alliance and its suppliers. The software is also
11550
- // protected by copyright law and international treaty provisions. Application
11551
- // programs incorporating this software must include the following statement
11552
- // with their copyright notices:
11553
- //
11554
- // This application incorporates Open Design Alliance software pursuant to a
11555
- // license agreement with Open Design Alliance.
11556
- // Open Design Alliance Copyright (C) 2002-2024 by Open Design Alliance.
11557
- // All rights reserved.
11558
- //
11559
- // By use of this software, its documentation or related materials, you
11560
- // acknowledge and accept the above terms.
11561
- ///////////////////////////////////////////////////////////////////////////////
11562
- class WorldTransform {
11563
- screenToWorld(position) {
11564
- return { x: position.x, y: position.y, z: 0 };
11565
- }
11566
- worldToScreen(position) {
11567
- return { x: position.x, y: position.y };
11568
- }
11569
- getScale() {
11570
- return { x: 1, y: 1, z: 1 };
11571
- }
11572
- }
11573
-
11574
11574
  const LineTypeSpecs = new Map([
11575
11575
  ["solid", []],
11576
11576
  ["dot", [30, 30, 0.001, 30]],
@@ -12554,14 +12554,50 @@
12554
12554
  this._konvaStage.height(height);
12555
12555
  };
12556
12556
  this.pan = (event) => {
12557
- const dX = event.dX / window.devicePixelRatio;
12558
- const dY = event.dY / window.devicePixelRatio;
12559
- this.getObjects().forEach((obj) => obj.ref().move({ x: dX, y: dY }));
12557
+ const pointer = this._konvaStage.getPointerPosition();
12558
+ const pointTo = {
12559
+ x: (pointer.x - this._konvaStage.x()) / this._konvaStage.scaleX(),
12560
+ y: (pointer.y - this._konvaStage.y()) / this._konvaStage.scaleX(),
12561
+ };
12562
+ const newPos = {
12563
+ x: pointer.x - pointTo.x * this._konvaStage.scale().x + event.dX,
12564
+ y: pointer.y - pointTo.y * this._konvaStage.scale().x + event.dY,
12565
+ };
12566
+ this._konvaStage.position(newPos);
12567
+ };
12568
+ this.zoomAt = (event) => {
12569
+ const oldScale = this._konvaStage.scaleX();
12570
+ const pointer = this._konvaStage.getPointerPosition();
12571
+ const mousePointTo = {
12572
+ x: (pointer.x - this._konvaStage.x()) / oldScale,
12573
+ y: (pointer.y - this._konvaStage.y()) / oldScale,
12574
+ };
12575
+ // how to scale? Zoom in? Or zoom out?
12576
+ let direction = event.data > 0 ? 1 : -1;
12577
+ const newScale = direction > 0 ? oldScale * event.data : oldScale / event.data;
12578
+ this._konvaStage.scale({ x: newScale, y: newScale });
12579
+ const newPos = {
12580
+ x: pointer.x - mousePointTo.x * newScale,
12581
+ y: pointer.y - mousePointTo.y * newScale,
12582
+ };
12583
+ this._konvaStage.position(newPos);
12560
12584
  };
12561
12585
  this.redirectToViewer = (event) => {
12562
12586
  if (this._viewer)
12563
12587
  this._viewer.emit(event);
12564
12588
  };
12589
+ this.getRelativePointPosition = (point, node) => {
12590
+ // the function will return pointer position relative to the passed node
12591
+ const transform = node.getAbsoluteTransform().copy();
12592
+ // to detect relative position we need to invert transform
12593
+ transform.invert();
12594
+ // get pointer (say mouse or touch) position
12595
+ // now we find relative point
12596
+ return transform.point(point);
12597
+ };
12598
+ this.getRelativePointerPosition = (node) => {
12599
+ return this.getRelativePointPosition(node.getStage().getPointerPosition(), node);
12600
+ };
12565
12601
  }
12566
12602
  initialize(container, containerEvents, viewer, worldTransformer) {
12567
12603
  if (!Konva)
@@ -12587,11 +12623,13 @@
12587
12623
  this._containerEvents.forEach((x) => this._markupContainer.addEventListener(x, this.redirectToViewer));
12588
12624
  this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
12589
12625
  this._viewer.addEventListener("pan", this.pan);
12626
+ this._viewer.addEventListener("zoomat", this.zoomAt);
12590
12627
  }
12591
12628
  }
12592
12629
  dispose() {
12593
12630
  var _a, _b;
12594
12631
  if (this._viewer) {
12632
+ this._viewer.removeEventListener("zoomat", this.zoomAt);
12595
12633
  this._viewer.removeEventListener("pan", this.pan);
12596
12634
  this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
12597
12635
  this._containerEvents.forEach((x) => this._markupContainer.removeEventListener(x, this.redirectToViewer));
@@ -12632,6 +12670,8 @@
12632
12670
  this.clearSelected();
12633
12671
  this.removeTextInput();
12634
12672
  this.removeImageInput();
12673
+ this._konvaStage.scale({ x: 1, y: 1 });
12674
+ this._konvaStage.position({ x: 0, y: 0 });
12635
12675
  const markupColor = ((_a = viewpoint.custom_fields) === null || _a === void 0 ? void 0 : _a.markup_color) || { r: 255, g: 0, b: 0 };
12636
12676
  this.setMarkupColor(markupColor.r, markupColor.g, markupColor.b);
12637
12677
  (_b = viewpoint.lines) === null || _b === void 0 ? void 0 : _b.forEach((line) => {
@@ -12792,7 +12832,7 @@
12792
12832
  transformer.nodes([]);
12793
12833
  return;
12794
12834
  }
12795
- const pos = stage.getPointerPosition();
12835
+ const pos = this.getRelativePointerPosition(stage);
12796
12836
  mouseDownPos = pos;
12797
12837
  isPaint = ["Arrow", "Cloud", "Ellipse", "Line", "Rectangle"].some((m) => m === this._markupMode);
12798
12838
  if (this._markupMode === "Line") {
@@ -12804,7 +12844,7 @@
12804
12844
  if (!this._markupIsActive)
12805
12845
  return;
12806
12846
  if (isPaint) {
12807
- const pos = stage.getPointerPosition();
12847
+ const pos = this.getRelativePointerPosition(stage);
12808
12848
  const defParams = mouseDownPos && pos.x === mouseDownPos.x && pos.y === mouseDownPos.y;
12809
12849
  const startX = defParams ? mouseDownPos.x : Math.min(mouseDownPos.x, pos.x);
12810
12850
  const startY = defParams ? mouseDownPos.y : Math.min(mouseDownPos.y, pos.y);
@@ -12836,7 +12876,7 @@
12836
12876
  }
12837
12877
  // prevent scrolling on touch devices
12838
12878
  //e.evt.preventDefault();
12839
- const pos = stage.getPointerPosition();
12879
+ const pos = this.getRelativePointerPosition(stage);
12840
12880
  const defParams = mouseDownPos && pos.x === mouseDownPos.x && pos.y === mouseDownPos.y;
12841
12881
  const startX = defParams ? mouseDownPos.x : Math.min(mouseDownPos.x, pos.x);
12842
12882
  const startY = defParams ? mouseDownPos.y : Math.min(mouseDownPos.y, pos.y);
@@ -12889,7 +12929,7 @@
12889
12929
  if (this._textInputRef && this._textInputRef.value)
12890
12930
  this.addText(this._textInputRef.value, this._textInputPos, this._textInputAngle);
12891
12931
  else if (transformer.nodes().length === 0) {
12892
- const pos = stage.getPointerPosition();
12932
+ const pos = this.getRelativePointerPosition(stage);
12893
12933
  this.createTextInput(pos, e.evt.pageX, e.evt.pageY, 0, null);
12894
12934
  }
12895
12935
  }
@@ -12897,7 +12937,7 @@
12897
12937
  if (this._imageInputRef && this._imageInputRef.value)
12898
12938
  this.addImage({ x: this._imageInputPos.x, y: this._imageInputPos.y }, this._imageInputRef.value, 0, 0, this._imageInputRef.value);
12899
12939
  else if (transformer.nodes().length === 0) {
12900
- const pos = stage.getPointerPosition();
12940
+ const pos = this.getRelativePointerPosition(stage);
12901
12941
  this.createImageInput(pos);
12902
12942
  }
12903
12943
  }
@@ -13022,11 +13062,10 @@
13022
13062
  this.konvaLayerFind("Text").forEach((ref) => {
13023
13063
  const textSize = 0.02;
13024
13064
  const textScale = this._worldTransformer.getScale();
13025
- const position = {
13026
- x: ref.x(),
13027
- y: ref.y(),
13028
- };
13029
- const worldPoint = this._worldTransformer.screenToWorld(position);
13065
+ const position = ref.position();
13066
+ const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
13067
+ const atPoint = stageAbsoluteTransform.point({ x: position.x, y: position.y });
13068
+ const worldPoint = this._worldTransformer.screenToWorld(atPoint);
13030
13069
  const shape = new KonvaText(null, ref);
13031
13070
  const text = {
13032
13071
  id: shape.id(),
@@ -13035,7 +13074,7 @@
13035
13074
  text_size: textSize * textScale.y,
13036
13075
  angle: shape.getRotation(),
13037
13076
  color: shape.getColor(),
13038
- font_size: shape.getFontSize(),
13077
+ font_size: shape.getFontSize() * stageAbsoluteTransform.getMatrix()[0],
13039
13078
  };
13040
13079
  texts.push(text);
13041
13080
  });
@@ -13045,13 +13084,16 @@
13045
13084
  const rectangles = [];
13046
13085
  this.konvaLayerFind("Rectangle").forEach((ref) => {
13047
13086
  const position = ref.position();
13048
- const worldPoint = this._worldTransformer.screenToWorld(position);
13087
+ const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
13088
+ const atPoint = stageAbsoluteTransform.point({ x: position.x, y: position.y });
13089
+ const worldPoint = this._worldTransformer.screenToWorld(atPoint);
13090
+ const scale = stageAbsoluteTransform.getMatrix()[0];
13049
13091
  const shape = new KonvaRectangle(null, ref);
13050
13092
  const rectangle = {
13051
13093
  id: shape.id(),
13052
13094
  position: worldPoint,
13053
- width: shape.getWidth(),
13054
- height: shape.getHeigth(),
13095
+ width: shape.getWidth() * scale,
13096
+ height: shape.getHeigth() * scale,
13055
13097
  line_width: shape.getLineWidth(),
13056
13098
  color: shape.getColor(),
13057
13099
  };
@@ -13063,12 +13105,18 @@
13063
13105
  const ellipses = [];
13064
13106
  this.konvaLayerFind("Ellipse").forEach((ref) => {
13065
13107
  const position = ref.position();
13066
- const worldPoint = this._worldTransformer.screenToWorld(position);
13108
+ const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
13109
+ const atPoint = stageAbsoluteTransform.point({ x: position.x, y: position.y });
13110
+ const worldPoint = this._worldTransformer.screenToWorld(atPoint);
13111
+ const scale = stageAbsoluteTransform.getMatrix()[0];
13067
13112
  const shape = new KonvaEllipse(null, ref);
13068
13113
  const ellipse = {
13069
13114
  id: shape.id(),
13070
13115
  position: worldPoint,
13071
- radius: { x: ref.getRadiusX(), y: ref.getRadiusY() },
13116
+ radius: {
13117
+ x: ref.getRadiusX() * scale,
13118
+ y: ref.getRadiusY() * scale,
13119
+ },
13072
13120
  line_width: shape.getLineWidth(),
13073
13121
  color: shape.getColor(),
13074
13122
  };
@@ -13106,14 +13154,17 @@
13106
13154
  const images = [];
13107
13155
  this.konvaLayerFind("Image").forEach((ref) => {
13108
13156
  const position = ref.position();
13109
- const worldPoint = this._worldTransformer.screenToWorld(position);
13157
+ const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
13158
+ const atPoint = stageAbsoluteTransform.point({ x: position.x, y: position.y });
13159
+ const worldPoint = this._worldTransformer.screenToWorld(atPoint);
13160
+ const scale = stageAbsoluteTransform.getMatrix()[0];
13110
13161
  const shape = new KonvaImage(null, ref);
13111
13162
  const image = {
13112
13163
  id: shape.id(),
13113
13164
  position: worldPoint,
13114
13165
  src: shape.getSrc(),
13115
- width: shape.getWidth(),
13116
- height: shape.getHeight(),
13166
+ width: shape.getWidth() * scale,
13167
+ height: shape.getHeight() * scale,
13117
13168
  };
13118
13169
  images.push(image);
13119
13170
  });
@@ -13123,13 +13174,16 @@
13123
13174
  const clouds = [];
13124
13175
  this.konvaLayerFind("Cloud").forEach((ref) => {
13125
13176
  const position = ref.position();
13126
- const worldPoint = this._worldTransformer.screenToWorld(position);
13177
+ const stageAbsoluteTransform = this._konvaStage.getAbsoluteTransform();
13178
+ const atPoint = stageAbsoluteTransform.point({ x: position.x, y: position.y });
13179
+ const worldPoint = this._worldTransformer.screenToWorld(atPoint);
13180
+ const scale = stageAbsoluteTransform.getMatrix()[0];
13127
13181
  const shape = new KonvaCloud(null, ref);
13128
13182
  const cloud = {
13129
13183
  id: shape.id(),
13130
13184
  position: worldPoint,
13131
- width: shape.getWidth(),
13132
- height: shape.getHeigth(),
13185
+ width: shape.getWidth() * scale,
13186
+ height: shape.getHeigth() * scale,
13133
13187
  line_width: shape.getLineWidth(),
13134
13188
  color: shape.getColor(),
13135
13189
  };