@inweb/viewer-visualize 25.5.4 → 25.6.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.
@@ -3060,6 +3060,7 @@
3060
3060
  */
3061
3061
  var MarkupMode;
3062
3062
  (function (MarkupMode) {
3063
+ MarkupMode["SelectMarkup"] = "SelectMarkup";
3063
3064
  MarkupMode["Line"] = "Line";
3064
3065
  MarkupMode["Text"] = "Text";
3065
3066
  MarkupMode["Rectangle"] = "Rectangle";
@@ -14590,8 +14591,8 @@
14590
14591
  });
14591
14592
  this._ref.on("transform", (e) => {
14592
14593
  const attrs = e.target.attrs;
14593
- if (attrs.rotation !== this.getRotation())
14594
- this.setRotation(attrs.rotation);
14594
+ if (attrs.rotation !== this._ref.rotation())
14595
+ this._ref.rotation(attrs.rotation);
14595
14596
  });
14596
14597
  this._ref.id(this._ref._id.toString());
14597
14598
  }
@@ -14692,14 +14693,25 @@
14692
14693
  this._ref.width(this._ref.getTextWidth());
14693
14694
  this._ref.on("transform", (e) => {
14694
14695
  const attrs = e.target.attrs;
14695
- if (attrs.rotation !== this.getRotation())
14696
- this.setRotation(attrs.rotation);
14697
- const newWidth = this._ref.width() * attrs.scaleX;
14698
- const newHeight = this._ref.height() * attrs.scaleY;
14699
- if (Math.abs(attrs.scaleX - 1) > 10e-6) {
14696
+ if (attrs.rotation !== this._ref.rotation())
14697
+ this._ref.rotation(attrs.rotation);
14698
+ const scaleByX = Math.abs(attrs.scaleX - 1) > 10e-6;
14699
+ const scaleByY = Math.abs(attrs.scaleY - 1) > 10e-6;
14700
+ let newWidth = this._ref.width();
14701
+ if (scaleByX)
14702
+ newWidth *= attrs.scaleX;
14703
+ let newHeight = this._ref.height();
14704
+ if (scaleByY)
14705
+ newHeight *= attrs.scaleY;
14706
+ const minWidth = 50;
14707
+ if (newWidth < minWidth)
14708
+ newWidth = minWidth;
14709
+ if (newHeight < Math.round(this.getFontSize()))
14710
+ newHeight = Math.round(this.getFontSize());
14711
+ if (scaleByX) {
14700
14712
  this._ref.width(newWidth);
14701
14713
  }
14702
- if (Math.abs(attrs.scaleY - 1) > 10e-6) {
14714
+ if (scaleByY) {
14703
14715
  this._ref.height(newHeight);
14704
14716
  }
14705
14717
  this._ref.scale({ x: 1, y: 1 });
@@ -14784,15 +14796,27 @@
14784
14796
  });
14785
14797
  this._ref.on("transform", (e) => {
14786
14798
  const attrs = e.target.attrs;
14787
- if (attrs.rotation !== this.getRotation())
14788
- this.setRotation(attrs.rotation);
14789
- const newWidth = this._ref.width() * attrs.scaleX;
14790
- const newHeight = this._ref.height() * attrs.scaleY;
14791
- if (Math.abs(attrs.scaleX - 1) > 10e-6) {
14792
- this.setWidth(newWidth);
14799
+ if (attrs.rotation !== this._ref.rotation())
14800
+ this._ref.rotation(attrs.rotation);
14801
+ const scaleByX = Math.abs(attrs.scaleX - 1) > 10e-6;
14802
+ const scaleByY = Math.abs(attrs.scaleY - 1) > 10e-6;
14803
+ let newWidth = this._ref.width();
14804
+ if (scaleByX)
14805
+ newWidth *= attrs.scaleX;
14806
+ let newHeight = this._ref.height();
14807
+ if (scaleByY)
14808
+ newHeight *= attrs.scaleY;
14809
+ const minWidth = 50;
14810
+ const minHeight = 50;
14811
+ if (newWidth < minWidth)
14812
+ newWidth = minWidth;
14813
+ if (newHeight < minHeight)
14814
+ newHeight = minHeight;
14815
+ if (scaleByX) {
14816
+ this._ref.width(newWidth);
14793
14817
  }
14794
- if (Math.abs(attrs.scaleY - 1) > 10e-6) {
14795
- this.setHeight(newHeight);
14818
+ if (scaleByY) {
14819
+ this._ref.height(newHeight);
14796
14820
  }
14797
14821
  this._ref.scale({ x: 1, y: 1 });
14798
14822
  });
@@ -14882,15 +14906,32 @@
14882
14906
  });
14883
14907
  this._ref.on("transform", (e) => {
14884
14908
  const attrs = e.target.attrs;
14885
- if (attrs.rotation !== this.getRotation())
14886
- this.setRotation(attrs.rotation);
14887
- const newRadiusX = this._ref.radiusX() * attrs.scaleX;
14888
- const newRadiusY = this._ref.radiusY() * attrs.scaleY;
14889
- if (Math.abs(attrs.scaleX - 1) > 10e-6) {
14890
- this.setRadiusX(newRadiusX);
14909
+ if (attrs.rotation !== this._ref.rotation())
14910
+ this._ref.rotation(attrs.rotation);
14911
+ const scaleByX = Math.abs(attrs.scaleX - 1) > 10e-6;
14912
+ const scaleByY = Math.abs(attrs.scaleY - 1) > 10e-6;
14913
+ let newRadiusX = this._ref.radiusX();
14914
+ if (scaleByX)
14915
+ newRadiusX *= attrs.scaleX;
14916
+ let newRadiusY = this._ref.radiusY();
14917
+ if (scaleByY)
14918
+ newRadiusY *= attrs.scaleY;
14919
+ const minRadiusX = 25;
14920
+ const minRadiusY = 25;
14921
+ if (newRadiusX < minRadiusX)
14922
+ newRadiusX = minRadiusX;
14923
+ if (newRadiusY < minRadiusY)
14924
+ newRadiusY = minRadiusY;
14925
+ if (e.evt.ctrlKey || e.evt.shiftKey) {
14926
+ if (scaleByX) {
14927
+ this._ref.radius({ x: newRadiusX, y: newRadiusX });
14928
+ }
14929
+ else {
14930
+ this._ref.radius({ x: newRadiusY, y: newRadiusY });
14931
+ }
14891
14932
  }
14892
- if (Math.abs(attrs.scaleY - 1) > 10e-6) {
14893
- this.setRadiusY(newRadiusY);
14933
+ else {
14934
+ this._ref.radius({ x: newRadiusX, y: newRadiusY });
14894
14935
  }
14895
14936
  this._ref.scale({ x: 1, y: 1 });
14896
14937
  });
@@ -14979,8 +15020,8 @@
14979
15020
  });
14980
15021
  this._ref.on("transform", (e) => {
14981
15022
  const attrs = e.target.attrs;
14982
- if (attrs.rotation !== this.getRotation())
14983
- this.setRotation(attrs.rotation);
15023
+ if (attrs.rotation !== this._ref.rotation())
15024
+ this._ref.rotation(attrs.rotation);
14984
15025
  });
14985
15026
  this._ref.id(this._ref._id.toString());
14986
15027
  }
@@ -15082,15 +15123,33 @@
15082
15123
  this._canvasImage.src = params.src;
15083
15124
  this._ref.on("transform", (e) => {
15084
15125
  const attrs = e.target.attrs;
15085
- if (attrs.rotation !== this.getRotation())
15086
- this.setRotation(attrs.rotation);
15087
- const newWidth = this._ref.width() * attrs.scaleX;
15088
- const newHeight = this._ref.height() * attrs.scaleY;
15089
- if (Math.abs(attrs.scaleX - 1) > 10e-6) {
15090
- this.setWidth(newWidth);
15126
+ if (attrs.rotation !== this._ref.rotation())
15127
+ this._ref.rotation(attrs.rotation);
15128
+ const scaleByX = Math.abs(attrs.scaleX - 1) > 10e-6;
15129
+ const scaleByY = Math.abs(attrs.scaleY - 1) > 10e-6;
15130
+ let newWidth = this._ref.width();
15131
+ if (scaleByX)
15132
+ newWidth *= attrs.scaleX;
15133
+ let newHeight = this._ref.height();
15134
+ if (scaleByY)
15135
+ newHeight *= attrs.scaleY;
15136
+ if (e.evt.ctrlKey || e.evt.shiftKey) {
15137
+ if (scaleByX) {
15138
+ this._ref.width(newWidth);
15139
+ this._ref.height(newWidth * this._ratio);
15140
+ }
15141
+ else {
15142
+ this._ref.width(newHeight / this._ratio);
15143
+ this._ref.height(newHeight);
15144
+ }
15091
15145
  }
15092
- if (Math.abs(attrs.scaleY - 1) > 10e-6) {
15093
- this.setHeight(newHeight);
15146
+ else {
15147
+ if (scaleByX) {
15148
+ this._ref.width(newWidth);
15149
+ }
15150
+ if (scaleByY) {
15151
+ this._ref.height(newHeight);
15152
+ }
15094
15153
  }
15095
15154
  this._ref.scale({ x: 1, y: 1 });
15096
15155
  });
@@ -15223,21 +15282,27 @@
15223
15282
  this._ref.className = "Cloud";
15224
15283
  this._ref.on("transform", (e) => {
15225
15284
  const attrs = e.target.attrs;
15226
- if (attrs.rotation !== this.getRotation())
15227
- this.setRotation(attrs.rotation);
15228
- const newWidth = this._ref.width() * attrs.scaleX;
15229
- const newHeight = this._ref.height() * attrs.scaleY;
15285
+ if (attrs.rotation !== this._ref.rotation())
15286
+ this._ref.rotation(attrs.rotation);
15287
+ const scaleByX = Math.abs(attrs.scaleX - 1) > 10e-6;
15288
+ const scaleByY = Math.abs(attrs.scaleY - 1) > 10e-6;
15289
+ let newWidth = this._ref.width();
15290
+ if (scaleByX)
15291
+ newWidth *= attrs.scaleX;
15292
+ let newHeight = this._ref.height();
15293
+ if (scaleByY)
15294
+ newHeight *= attrs.scaleY;
15230
15295
  const minWidth = 100;
15231
15296
  const minHeight = 100;
15232
- if (newWidth < minWidth || newHeight < minHeight) {
15233
- this._ref.scale({ x: 1, y: 1 });
15234
- return;
15235
- }
15236
- if (Math.abs(attrs.scaleX - 1) > 10e-6) {
15237
- this.setWidth(newWidth);
15297
+ if (newWidth < minWidth)
15298
+ newWidth = minWidth;
15299
+ if (newHeight < minHeight)
15300
+ newHeight = minHeight;
15301
+ if (scaleByX) {
15302
+ this._ref.width(newWidth);
15238
15303
  }
15239
- if (Math.abs(attrs.scaleY - 1) > 10e-6) {
15240
- this.setHeight(newHeight);
15304
+ if (scaleByY) {
15305
+ this._ref.height(newHeight);
15241
15306
  }
15242
15307
  this._ref.scale({ x: 1, y: 1 });
15243
15308
  });
@@ -15314,6 +15379,13 @@
15314
15379
  ///////////////////////////////////////////////////////////////////////////////
15315
15380
  // move to separate class and create factory with enum?
15316
15381
  const MarkupMode2Konva = new Map([
15382
+ [
15383
+ MarkupMode.SelectMarkup,
15384
+ {
15385
+ name: "SelectMarkup",
15386
+ initializer: () => { },
15387
+ },
15388
+ ],
15317
15389
  [
15318
15390
  MarkupMode.Line,
15319
15391
  {
@@ -15384,6 +15456,8 @@
15384
15456
  this._zIndex = 1;
15385
15457
  this._markupContainerName = "markupContainer";
15386
15458
  this.lineWidth = 4;
15459
+ this.lineType = "solid";
15460
+ this.fontSize = 34;
15387
15461
  this.changeActiveDragger = (event) => {
15388
15462
  const draggerName = event.data;
15389
15463
  this._markupContainer.className = this._canvasOriginal.className
@@ -15477,8 +15551,9 @@
15477
15551
  const hex = new MarkupColor(r, g, b).HexColor;
15478
15552
  Object.values(MarkupMode).forEach((mode) => {
15479
15553
  this.konvaLayerFind(mode).forEach((x) => {
15480
- const konvaObj = MarkupMode2Konva.get(mode).initializer(x);
15481
- if (konvaObj.setColor)
15554
+ var _a;
15555
+ const konvaObj = (_a = MarkupMode2Konva.get(mode)) === null || _a === void 0 ? void 0 : _a.initializer(x);
15556
+ if (konvaObj && konvaObj.setColor)
15482
15557
  konvaObj.setColor(hex);
15483
15558
  });
15484
15559
  });
@@ -15679,6 +15754,7 @@
15679
15754
  const konvaShapes = this._konvaLayer.find(konvaShape.name).filter((x) => x.parent instanceof Konva.Layer);
15680
15755
  return konvaShapes;
15681
15756
  }
15757
+ return [];
15682
15758
  }
15683
15759
  initializeKonva() {
15684
15760
  // first we need Konva core things: stage and layer
@@ -15693,6 +15769,8 @@
15693
15769
  this._konvaLayer = layer;
15694
15770
  const transformer = new Konva.Transformer({
15695
15771
  shouldOverdrawWholeArea: false,
15772
+ keepRatio: false,
15773
+ flipEnabled: false,
15696
15774
  });
15697
15775
  this._konvaTransformer = transformer;
15698
15776
  layer.add(transformer);
@@ -15823,7 +15901,7 @@
15823
15901
  transformer.nodes([]);
15824
15902
  return;
15825
15903
  }
15826
- if (this._markupMode === MarkupMode.Text) {
15904
+ if (this._markupMode === MarkupMode.Text || this._markupMode === MarkupMode.SelectMarkup) {
15827
15905
  if (e.target.className === "Text" && transformer.nodes().length === 1 && transformer.nodes()[0] === e.target) {
15828
15906
  if (this._textInputRef && this._textInputRef.value)
15829
15907
  this.addText(this._textInputRef.value, this._textInputPos, this._textInputAngle);
@@ -15835,7 +15913,7 @@
15835
15913
  this.removeTextInput();
15836
15914
  }
15837
15915
  }
15838
- if (this._markupMode === MarkupMode.Image) {
15916
+ if (this._markupMode === MarkupMode.Image || this._markupMode === MarkupMode.SelectMarkup) {
15839
15917
  if (e.target.className === "Image" && transformer.nodes().length === 1 && transformer.nodes()[0] === e.target) {
15840
15918
  if (this._imageInputRef && this._imageInputRef.value)
15841
15919
  this.addImage(this._imageInputPos, this._imageInputRef.value, 0, 0);
@@ -15923,9 +16001,9 @@
15923
16001
  lines.push({
15924
16002
  id: konvaLine.id(),
15925
16003
  points: worldPoints.map((p) => this.getPoint3dFromArray(p)),
15926
- color: konvaLine.getColor() || "ff0000",
15927
- type: konvaLine.getLineType() || "solid",
15928
- width: konvaLine.getLineWidth() || 3,
16004
+ color: konvaLine.getColor() || "#ff0000",
16005
+ type: konvaLine.getLineType() || this.lineType,
16006
+ width: konvaLine.getLineWidth() || this.lineWidth,
15929
16007
  });
15930
16008
  });
15931
16009
  return lines;
@@ -16115,7 +16193,7 @@
16115
16193
  }
16116
16194
  const konvaLine = new KonvaLine({
16117
16195
  points,
16118
- type: type || "solid",
16196
+ type: type || this.lineType,
16119
16197
  width: width || this.lineWidth,
16120
16198
  color: color || this._markupColor.HexColor,
16121
16199
  id,
@@ -16222,7 +16300,7 @@
16222
16300
  position: { x: position.x, y: position.y },
16223
16301
  text: specifiedText,
16224
16302
  rotation: angle,
16225
- fontSize,
16303
+ fontSize: fontSize || this.fontSize,
16226
16304
  color: color || this._markupColor.HexColor,
16227
16305
  id,
16228
16306
  });
@@ -16444,7 +16522,8 @@
16444
16522
  class VisualizeMarkup {
16445
16523
  constructor() {
16446
16524
  this._markupColor = { r: 255, g: 0, b: 0 };
16447
- this.lineWidth = 0;
16525
+ this.lineWidth = 4;
16526
+ this.fontSize = 34;
16448
16527
  }
16449
16528
  initialize(viewer, canvas, canvasEvents) {
16450
16529
  this._viewer = viewer;