@inweb/viewer-visualize 25.8.20 → 25.8.22

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/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Viewer.visualize
2
2
 
3
- `Viewer.visualize` is JavaScript library implementating 3D viewer powered by [VisualizeJS](https://cloud.opendesign.com/docs/index.html#/visualizejs) for in-browser visualization of 3D CAD and BIM data files.
3
+ `Viewer.visualize` is JavaScript library implementating 3D viewer powered by [VisualizeJS](https://cloud.opendesign.com/docs/index.html#/visualizejs) for in-browser visualization of CAD and BIM data files.
4
4
 
5
- With `Viewer.visualize` you can:
5
+ Core capabilities:
6
6
 
7
7
  - Visualize files stored on the [Open Cloud Server](https://cloud.opendesign.com/docs/index.html#/opencloud_server), on the web, or on your local computer.
8
8
  - Add user interaction with scenes.
@@ -11,8 +11,6 @@ With `Viewer.visualize` you can:
11
11
 
12
12
  This library is a part of [CDE SDK](https://www.opendesign.com/products/cde) by [Open Design Alliance](https://opendesign.com).
13
13
 
14
- > `Viewer.visualize` uses `VSFX` file format as internal geometry data format. `VSFX` is a [Visualize SDK](https://cloud.opendesign.com/docs/index.html#/visualizejs) file format with support for streaming and partial viewing.
15
-
16
14
  ## Installation
17
15
 
18
16
  ### CDN or static hosting
@@ -12208,24 +12208,24 @@
12208
12208
  var Konva = /*@__PURE__*/getDefaultExportFromCjs(libExports);
12209
12209
 
12210
12210
  class MarkupColor {
12211
- get HexColor() {
12212
- return "#" + this._hex;
12211
+ constructor(r, g, b) {
12212
+ this.setColor(r, g, b);
12213
12213
  }
12214
- get RGB() {
12214
+ asHex() {
12215
+ return "#" + this.HEX;
12216
+ }
12217
+ asRGB() {
12215
12218
  return {
12216
12219
  r: this.R,
12217
12220
  g: this.G,
12218
12221
  b: this.B
12219
12222
  };
12220
12223
  }
12221
- constructor(r, g, b) {
12222
- this.setColor(r, g, b);
12223
- }
12224
12224
  setColor(r, g, b) {
12225
12225
  this.R = r;
12226
12226
  this.G = g;
12227
12227
  this.B = b;
12228
- this._hex = this.rgbToHex(r, g, b);
12228
+ this.HEX = this.rgbToHex(r, g, b);
12229
12229
  }
12230
12230
  rgbToHex(r, g, b) {
12231
12231
  const valueToHex = c => {
@@ -13190,7 +13190,7 @@
13190
13190
 
13191
13191
  class KonvaMarkup {
13192
13192
  constructor() {
13193
- this._pointerEvents = [];
13193
+ this._containerEvents = [];
13194
13194
  this._markupIsActive = false;
13195
13195
  this._markupColor = new MarkupColor(255, 0, 0);
13196
13196
  this.lineWidth = 4;
@@ -13222,12 +13222,12 @@
13222
13222
  if (this._viewer) this._viewer.emit(event);
13223
13223
  };
13224
13224
  }
13225
- initialize(container, pointerEvents, viewer, worldTransformer) {
13225
+ initialize(container, containerEvents, viewer, worldTransformer) {
13226
13226
  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?');
13227
13227
  this._viewer = viewer;
13228
13228
  this._worldTransformer = worldTransformer !== null && worldTransformer !== void 0 ? worldTransformer : new WorldTransform;
13229
13229
  this._container = container;
13230
- this._pointerEvents = pointerEvents !== null && pointerEvents !== void 0 ? pointerEvents : [];
13230
+ this._containerEvents = containerEvents !== null && containerEvents !== void 0 ? containerEvents : [];
13231
13231
  this._markupContainer = document.createElement("div");
13232
13232
  this._markupContainer.id = "markup-container";
13233
13233
  this._markupContainer.style.position = "absolute";
@@ -13241,7 +13241,7 @@
13241
13241
  this._markupColor.setColor(255, 0, 0);
13242
13242
  this.initializeKonva();
13243
13243
  if (this._viewer) {
13244
- this._pointerEvents.forEach((x => this._markupContainer.addEventListener(x, this.redirectToViewer)));
13244
+ this._containerEvents.forEach((x => this._markupContainer.addEventListener(x, this.redirectToViewer)));
13245
13245
  this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
13246
13246
  this._viewer.addEventListener("pan", this.pan);
13247
13247
  }
@@ -13251,7 +13251,7 @@
13251
13251
  if (this._viewer) {
13252
13252
  this._viewer.removeEventListener("pan", this.pan);
13253
13253
  this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
13254
- this._pointerEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
13254
+ this._containerEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
13255
13255
  }
13256
13256
  this.destroyKonva();
13257
13257
  (_a = this._resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
@@ -13271,20 +13271,20 @@
13271
13271
  this.getObjects().forEach((obj => obj.delete()));
13272
13272
  }
13273
13273
  getMarkupColor() {
13274
- return this._markupColor.RGB;
13274
+ return this._markupColor.asRGB();
13275
13275
  }
13276
13276
  setMarkupColor(r, g, b) {
13277
13277
  this._markupColor.setColor(r, g, b);
13278
13278
  }
13279
13279
  colorizeAllMarkup(r, g, b) {
13280
- const hexColor = new MarkupColor(r, g, b).HexColor;
13280
+ const hexColor = new MarkupColor(r, g, b).asHex();
13281
13281
  this.getObjects().filter((obj => {
13282
13282
  var _a;
13283
13283
  return (_a = obj.setColor) === null || _a === void 0 ? void 0 : _a.call(obj, hexColor);
13284
13284
  }));
13285
13285
  }
13286
13286
  colorizeSelectedMarkups(r, g, b) {
13287
- const hexColor = new MarkupColor(r, g, b).HexColor;
13287
+ const hexColor = new MarkupColor(r, g, b).asHex();
13288
13288
  this.getSelectedObjects().filter((obj => {
13289
13289
  var _a;
13290
13290
  return (_a = obj.setColor) === null || _a === void 0 ? void 0 : _a.call(obj, hexColor);
@@ -13808,7 +13808,7 @@
13808
13808
  points: points,
13809
13809
  type: type || this.lineType,
13810
13810
  width: width || this.lineWidth,
13811
- color: color || this._markupColor.HexColor,
13811
+ color: color || this._markupColor.asHex(),
13812
13812
  id: id
13813
13813
  });
13814
13814
  this.addObject(konvaLine);
@@ -13825,7 +13825,7 @@
13825
13825
  this._textInputRef.style.top = inputY + "px";
13826
13826
  this._textInputRef.style.left = inputX + "px";
13827
13827
  this._textInputRef.style.fontSize = `${this.fontSize}px`;
13828
- this._textInputRef.style.color = `${this._markupColor.HexColor}`;
13828
+ this._textInputRef.style.color = `${this._markupColor.asHex()}`;
13829
13829
  this._textInputRef.style.fontFamily = "Calibri";
13830
13830
  this._textInputRef.onkeydown = event => {
13831
13831
  if (event.key === "Enter" && !event.shiftKey) {
@@ -13915,7 +13915,7 @@
13915
13915
  text: text,
13916
13916
  rotation: angle,
13917
13917
  fontSize: fontSize || this.fontSize,
13918
- color: color || this._markupColor.HexColor,
13918
+ color: color || this._markupColor.asHex(),
13919
13919
  id: id
13920
13920
  });
13921
13921
  this.addObject(konvaText);
@@ -13928,7 +13928,7 @@
13928
13928
  width: width,
13929
13929
  height: height,
13930
13930
  lineWidth: lineWidth || this.lineWidth,
13931
- color: color || this._markupColor.HexColor,
13931
+ color: color || this._markupColor.asHex(),
13932
13932
  id: id
13933
13933
  });
13934
13934
  this.addObject(konvaRectangle);
@@ -13940,7 +13940,7 @@
13940
13940
  position: position,
13941
13941
  radius: radius,
13942
13942
  lineWidth: lineWidth,
13943
- color: color || this._markupColor.HexColor,
13943
+ color: color || this._markupColor.asHex(),
13944
13944
  id: id
13945
13945
  });
13946
13946
  this.addObject(konvaEllipse);
@@ -13951,7 +13951,7 @@
13951
13951
  const konvaArrow = new KonvaArrow({
13952
13952
  start: start,
13953
13953
  end: end,
13954
- color: color || this._markupColor.HexColor,
13954
+ color: color || this._markupColor.asHex(),
13955
13955
  id: id
13956
13956
  });
13957
13957
  this.addObject(konvaArrow);
@@ -13963,7 +13963,7 @@
13963
13963
  position: position,
13964
13964
  width: width,
13965
13965
  height: height,
13966
- color: color || this._markupColor.HexColor,
13966
+ color: color || this._markupColor.asHex(),
13967
13967
  lineWidth: lineWidth || this.lineWidth,
13968
13968
  id: id
13969
13969
  });
@@ -16467,7 +16467,7 @@
16467
16467
  this.lineWidth = 4;
16468
16468
  this.fontSize = 34;
16469
16469
  }
16470
- initialize(canvas, canvasEvents, viewer, worldTransformer) {
16470
+ initialize(container, containerEvents, viewer, worldTransformer) {
16471
16471
  this._viewer = viewer;
16472
16472
  this._viewer.registerDragger("Line", OdaLineDragger);
16473
16473
  this._viewer.registerDragger("Text", OdaTextDragger);
@@ -16660,9 +16660,9 @@
16660
16660
  */
16661
16661
  class Viewer extends EventEmitter2 {
16662
16662
  /**
16663
- * @param client - The `Client` instance that provides access to a Open Cloud Server. Do not
16664
- * specify `Client` if you need a standalone viewer instance to view `VSFX` files from the
16665
- * web or from local computer.
16663
+ * @param client - The `Client` instance that is used to load model reference files from the
16664
+ * Open Cloud Server. Do not specify `Client` if you need a standalone viewer instance to
16665
+ * view `VSFX` files from the web or from local computer.
16666
16666
  * @param params - An object containing viewer configuration parameters.
16667
16667
  * @param params.visualizeJsUrl - `VisualizeJS` library URL. Set this URL to use your own
16668
16668
  * library instance, or specify `undefined` or blank to use the default URL defined by
@@ -16854,6 +16854,8 @@
16854
16854
  if (!this.visualizeJs)
16855
16855
  return this;
16856
16856
  const { clientWidth, clientHeight } = this.canvas;
16857
+ if (!clientWidth || !clientHeight)
16858
+ return this; // <- invisible viewer, or viewer with parent removed
16857
16859
  this.canvas.width = clientWidth * window.devicePixelRatio;
16858
16860
  this.canvas.height = clientHeight * window.devicePixelRatio;
16859
16861
  const visViewer = this.visualizeJs.getViewer();
@@ -17332,9 +17334,12 @@
17332
17334
  this.update();
17333
17335
  }
17334
17336
  /**
17335
- * Loads a model/file/assembly into the viewer.
17337
+ * Loads a file from Open Cloud Server into the viewer.
17338
+ *
17339
+ * The file geometry data on the server must be converted to `VSFX` format.
17336
17340
  *
17337
- * This method requires a {@link Client} instance to work. For standalone viewer instance use
17341
+ * This method requires a `Client` instance to be specified when creating the viewer to load
17342
+ * model reference files from the Open Cloud Server. For a standalone viewer instance use
17338
17343
  * {@link openVsfFile | openVsfFile()} or {@link openVsfxFile | openVsfxFile()}.
17339
17344
  *
17340
17345
  * Fires:
@@ -17347,9 +17352,9 @@
17347
17352
  * - {@link GeometryEndEvent | geometryend}
17348
17353
  * - {@link GeometryErrorEvent | geometryerror}
17349
17354
  *
17350
- * @param file - File or Assembly or Model instance to load. If a `File` instance with
17351
- * multiple models is specified, the default model will be loaded. If there is no default
17352
- * model, first availiable model will be loaded.
17355
+ * @param file - File, assembly or specific model to load. If a `File` instance with multiple
17356
+ * models is specified, the default model will be loaded. If there is no default model,
17357
+ * first availiable model will be loaded.
17353
17358
  */
17354
17359
  async open(file) {
17355
17360
  if (!this.visualizeJs)
@@ -17502,9 +17507,9 @@
17502
17507
  *
17503
17508
  * - {@link ChangeMarkupColorEvent | changemarkupcolor}
17504
17509
  *
17505
- * @param r - `Red` part of color.
17506
- * @param g - `Green` part of color.
17507
- * @param b - `Blue` part of color.
17510
+ * @param r - The `red` component of the color, as a number between 0 and 255.
17511
+ * @param g - The `green` component of the color, as a number between 0 and 255.
17512
+ * @param b - The `blue` component of the color, as a number between 0 and 255.
17508
17513
  */
17509
17514
  setMarkupColor(r = 255, g = 0, b = 0) {
17510
17515
  this._markup.setMarkupColor(r, g, b);
@@ -17514,15 +17519,15 @@
17514
17519
  /**
17515
17520
  * Colors all markup objects with the specified color.
17516
17521
  *
17517
- * @param r - `Red` part of color.
17518
- * @param g - `Green` part of color.
17519
- * @param b - `Blue` part of color.
17522
+ * @param r - The `red` component of the color, as a number between 0 and 255.
17523
+ * @param g - The `green` component of the color, as a number between 0 and 255.
17524
+ * @param b - The `blue` component of the color, as a number between 0 and 255.
17520
17525
  */
17521
17526
  colorizeAllMarkup(r = 255, g = 0, b = 0) {
17522
17527
  this._markup.colorizeAllMarkup(r, g, b);
17523
17528
  }
17524
17529
  /**
17525
- * Colors selected markup objects with the specified color.
17530
+ * Colors the selected markup objects with the specified color.
17526
17531
  *
17527
17532
  * @param r - `Red` part of color.
17528
17533
  * @param g - `Green` part of color.
@@ -17552,7 +17557,8 @@
17552
17557
  /**
17553
17558
  * Sets the viewer state to the specified viewpoint.
17554
17559
  *
17555
- * To get a list of available model viewpoints, use the `File.getViewpoints()`.
17560
+ * To get a list of available viewpoints from the server for a specific file, use the
17561
+ * `File.getViewpoints()`.
17556
17562
  *
17557
17563
  * @param viewpoint - Viewpoint data.
17558
17564
  */
@@ -17564,7 +17570,7 @@
17564
17570
  /**
17565
17571
  * Saves the viewer state at the viewpoint.
17566
17572
  *
17567
- * To save a viewpoint to a model on the server, use the `File.saveViewpoint()`.
17573
+ * To save a viewpoint to the server for a specific file, use the `File.saveViewpoint()`.
17568
17574
  */
17569
17575
  createViewpoint() {
17570
17576
  const vp = this._markup.getViewpoint();