@inweb/viewer-visualize 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.
@@ -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);
@@ -17488,7 +17553,7 @@
17488
17553
  return this;
17489
17554
  }
17490
17555
  /**
17491
- * Loads the `VisualizeJS` module and initialize it with the specified canvas. Call
17556
+ * Loads the `VisualizeJS` module and initializes it with the specified canvas. Call
17492
17557
  * {@link dispose | dispose()} to release allocated resources.
17493
17558
  *
17494
17559
  * Fires:
@@ -17543,8 +17608,8 @@
17543
17608
  return this;
17544
17609
  }
17545
17610
  /**
17546
- * Releases all resources allocated by this viewer instance. Call this method before release
17547
- * the `Viewer` instance.
17611
+ * Unloads an open file, clears the canvas and markups, and releases resources allocated by
17612
+ * this viewer instance. Call this method before release the `Viewer` instance.
17548
17613
  */
17549
17614
  dispose() {
17550
17615
  this.cancel();
@@ -17842,7 +17907,9 @@
17842
17907
  return this;
17843
17908
  }
17844
17909
  /**
17845
- * List of names of registered draggers. By default, the following draggers are registered:
17910
+ * List of names of registered draggers.
17911
+ *
17912
+ * The following draggers are registered by default:
17846
17913
  *
17847
17914
  * - `Line`
17848
17915
  * - `Text`
@@ -17857,14 +17924,16 @@
17857
17924
  * - `CuttingPlaneZAxis`
17858
17925
  * - `Walk`
17859
17926
  *
17860
- * @readonly
17927
+ * To register your own command use the {@link registerDragger | registerDragger()}.
17861
17928
  */
17862
17929
  get draggers() {
17863
17930
  return [...this.draggerFactory.keys()];
17864
17931
  }
17865
17932
  /**
17866
- * Registers a dragger for the viewer. Dragger is an object that received mouse/keyboard
17867
- * events and does something to the viewer.
17933
+ * Registers a dragger for the viewer.
17934
+ *
17935
+ * Dragger is an object that received mouse/keyboard events and does something to the viewer.
17936
+ * For a quick tutorial on how to create your own dragger, see {@link Dragger}.
17868
17937
  *
17869
17938
  * @param name - Dragger name.
17870
17939
  * @param dragger - Dragger class.
@@ -17873,7 +17942,7 @@
17873
17942
  this.draggerFactory.set(name, dragger);
17874
17943
  }
17875
17944
  /**
17876
- * Returns active dragger instance or `null` if there is no active dragger.
17945
+ * Returns the active dragger instance, or `null` if there is no active dragger.
17877
17946
  */
17878
17947
  activeDragger() {
17879
17948
  return this._activeDragger;
@@ -17886,7 +17955,8 @@
17886
17955
  * - {@link ChangeActiveDraggerEvent | changeactivedragger}
17887
17956
  *
17888
17957
  * @param name - Dragger name. Can be one of the {@link draggers} list.
17889
- * @returns Returns active dragger instance or `null` if there is no dragger with the given name.
17958
+ * @returns Returns the new active dragger instance or `null` if there is no dragger with the
17959
+ * given name.
17890
17960
  */
17891
17961
  setActiveDragger(name) {
17892
17962
  var _a;
@@ -17976,7 +18046,7 @@
17976
18046
  this.update();
17977
18047
  }
17978
18048
  /**
17979
- * Returns `true` if current model is 3D model.
18049
+ * Returns `true` if current opened model is 3D model.
17980
18050
  */
17981
18051
  is3D() {
17982
18052
  if (!this.visualizeJs)
@@ -18212,7 +18282,7 @@
18212
18282
  return this;
18213
18283
  }
18214
18284
  /**
18215
- * Cancels asynchronous model loading started by {@link open | open()}.
18285
+ * Cancels asynchronous file loading started by {@link open | open()}.
18216
18286
  */
18217
18287
  cancel() {
18218
18288
  var _a, _b, _c;
@@ -18226,7 +18296,7 @@
18226
18296
  return this;
18227
18297
  }
18228
18298
  /**
18229
- * Unloads the model and clears the viewer and markups.
18299
+ * Unloads an open file and clears the canvas and markups.
18230
18300
  */
18231
18301
  clear() {
18232
18302
  if (!this.visualizeJs)
@@ -18381,11 +18451,42 @@
18381
18451
  }
18382
18452
  }
18383
18453
  /**
18384
- * Executes the command denoted by the given command identifier.
18454
+ * Executes the command denoted by the given command. If the command is not found, tries to
18455
+ * set active dragger with the specified name.
18456
+ *
18457
+ * The following commands are registered by default:
18458
+ *
18459
+ * - `applyModelTransform`
18460
+ * - `autoTransformAllModelsToCentralPoint`
18461
+ * - `clearMarkup`
18462
+ * - `clearSlices`
18463
+ * - `createPreview`
18464
+ * - `explode`
18465
+ * - `getDefaultViewPositions`
18466
+ * - `getModels`
18467
+ * - `getSelected`
18468
+ * - `hideSelected`
18469
+ * - `isolateSelected`
18470
+ * - `regenerateAll`
18471
+ * - `resetView`
18472
+ * - `selectModel`
18473
+ * - `setActiveDragger`
18474
+ * - `setDefaultViewPosition`
18475
+ * - `setMarkupColor`
18476
+ * - `setSelected`
18477
+ * - `showAll`
18478
+ * - `unselect`
18479
+ * - `zoomToExtents`
18480
+ * - `zoomToObjects`
18481
+ * - `zoomToSelected`
18482
+ *
18483
+ * To register your own command use the {@link ICommands.registerCommand | registerCommand()}
18484
+ * method of the {@link commands} manager.
18385
18485
  *
18386
- * @param id - Identifier of the command to execute.
18387
- * @param args - Parameters passed to the command function.
18388
- * @returns A returned value of the given command. Returns `undefined` when the command doesn't exists.
18486
+ * @param id - Command ID or dragger name.
18487
+ * @param args - Parameters passed to the command handler function.
18488
+ * @returns Returns the result of the command handler function or new active dragger
18489
+ * instance. Returns `undefined` if neither the command nor the dragger exists.
18389
18490
  */
18390
18491
  executeCommand(id, ...args) {
18391
18492
  return commands("VisualizeJS").executeCommand(id, this, ...args);