@inweb/viewer-visualize 25.8.19 → 25.8.21

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
+ }
12214
+ asHex() {
12215
+ return "#" + this.HEX;
12213
12216
  }
12214
- get RGB() {
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 => {
@@ -12268,7 +12268,14 @@
12268
12268
  this._ref = ref;
12269
12269
  return;
12270
12270
  }
12271
- if (!params || !params.points) return;
12271
+ if (!params) params = {};
12272
+ if (!params.points) params.points = [ {
12273
+ x: 50,
12274
+ y: 50
12275
+ }, {
12276
+ x: 100,
12277
+ y: 100
12278
+ } ];
12272
12279
  const konvaPoints = [];
12273
12280
  params.points.forEach((point => konvaPoints.push(point.x, point.y)));
12274
12281
  this._ref = new Konva.Line({
@@ -12370,7 +12377,12 @@
12370
12377
  this._ref = ref;
12371
12378
  return;
12372
12379
  }
12373
- if (!params || !params.position || !params.text) return;
12380
+ if (!params) params = {};
12381
+ if (!params.position) params.position = {
12382
+ x: 100,
12383
+ y: 100
12384
+ };
12385
+ if (!params.text) params.text = "default";
12374
12386
  this._ref = new Konva.Text({
12375
12387
  x: params.position.x,
12376
12388
  y: params.position.y,
@@ -12472,7 +12484,11 @@
12472
12484
  this._ref = ref;
12473
12485
  return;
12474
12486
  }
12475
- if (!params || !params.position) return;
12487
+ if (!params) params = {};
12488
+ if (!params.position) params.position = {
12489
+ x: 100,
12490
+ y: 100
12491
+ };
12476
12492
  this._ref = new Konva.Rect({
12477
12493
  stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
12478
12494
  strokeWidth: (_b = params.lineWidth) !== null && _b !== void 0 ? _b : 4,
@@ -12582,7 +12598,15 @@
12582
12598
  this._ref = ref;
12583
12599
  return;
12584
12600
  }
12585
- if (!params || !params.position || !params.radius) return;
12601
+ if (!params) params = {};
12602
+ if (!params.position) params.position = {
12603
+ x: 100,
12604
+ y: 100
12605
+ };
12606
+ if (!params.radius) params.radius = {
12607
+ x: 25,
12608
+ y: 25
12609
+ };
12586
12610
  this._ref = new Konva.Ellipse({
12587
12611
  stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
12588
12612
  strokeWidth: (_b = params.lineWidth) !== null && _b !== void 0 ? _b : 4,
@@ -12704,7 +12728,15 @@
12704
12728
  this._ref = ref;
12705
12729
  return;
12706
12730
  }
12707
- if (!params || !params.start || !params.end) return;
12731
+ if (!params) params = {};
12732
+ if (!params.start) params.start = {
12733
+ x: 50,
12734
+ y: 50
12735
+ };
12736
+ if (!params.end) params.end = {
12737
+ x: 100,
12738
+ y: 100
12739
+ };
12708
12740
  this._ref = new Konva.Arrow({
12709
12741
  stroke: (_a = params.color) !== null && _a !== void 0 ? _a : "#ff0000",
12710
12742
  fill: (_b = params.color) !== null && _b !== void 0 ? _b : "#ff0000",
@@ -12801,22 +12833,24 @@
12801
12833
  var _a, _b;
12802
12834
  this._ratio = 1;
12803
12835
  this.EPSILON = 1e-5;
12836
+ this.BASE64_NOT_FOUND = "data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAAADsAAAA7AF5KHG9AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAmhJREFUWIXtlr9rVEEQxz+H8RQUJIdeIopYm0vkCg0GBBtbG1NF7Kxt7dR/IGIw/uhTaBNLERURg2kCEUyCYCPi70b0InjGS57FzOZN3r19d+9HJIVfWO52dma/s7Mz8xa2KAaBCWAR+AkECWOmSOIdwC1gtQOpHc+NfQ8wClQ8+1d0vcdH/lQ3bSIRGAZ2pTjAqNovANXIWlXlAXA2zvi2Ln4AjqYgtagYEutENSLvjRoOImFv5iB32Ae8UrLXwFBk3h9ndF0VJnKSO9gTu3yKu5Z1LKnS8YIcABgw5Ks692JZFXcXRJ46Aq6kikCnHNi/mQ50WwVtfaIoBzL3gRk2drSscJ2wrc4VvUoe2wn/41/iBfoVLRnBGnDSY3AAKacy8AmYR+o7K1zCl6wgrgpOAc/MuhvfgMuk+1JGHQgSBcAloKXy78AjYBppJk5/noTulseBMZ23iD/piHFkEdgTQzKk+5wHjmHC3cmBg0BD5xcSTrFXyQPgIWFtDwMvab+2N8DpbhyY1v/3E8gdDgNfVX9SCVZ0/gW4B0wB71S2BpxLcuCM/jaQSHSDEeAX4VMuAG4gTzyHbcAVXXO6GxxwIX+vvxe7JHcYQ07nHqklj96UIW/YhSWzMKcep8VVtf8B1Dw6h4DfhB+sdbgn2R+gnoEc5NR3dZ+3QJ9H74HqXLPCGlJyTfI9y3YCs0owq3OLOpKkLeBI1HhSDT/mdKIPiUCARMTlQx34TMLjtww8IczmO8AJ/N/2JNSQXAiQ671JePePge0+wzJSQq4FFzlaenIvucUAkiQLhC/mLGNZ9xgn5s63BP4CCk0QDtm4BhoAAAAASUVORK5CYII=";
12837
+ this.BASE64_HEADER_START = "data:image/";
12804
12838
  if (ref) {
12839
+ if (!ref.src || !ref.src.startsWith(this.BASE64_HEADER_START)) ref.src = this.BASE64_NOT_FOUND;
12840
+ if (ref.height() <= this.EPSILON) ref.height(32);
12841
+ if (ref.width() <= this.EPSILON) ref.width(32);
12805
12842
  this._ref = ref;
12806
12843
  this._canvasImage = ref.image();
12807
12844
  this._ratio = this._ref.height() <= this.EPSILON || this._ref.width() <= this.EPSILON ? 1 : this._ref.height() / this._ref.width();
12808
12845
  return;
12809
12846
  }
12810
- if (!params || !params.position || !params.src) return;
12847
+ if (!params) params = {};
12848
+ if (!params.position) params.position = {
12849
+ x: 50,
12850
+ y: 50
12851
+ };
12852
+ if (!params.src || !params.src.startsWith(this.BASE64_HEADER_START)) params.src = this.BASE64_NOT_FOUND;
12811
12853
  this._canvasImage = new Image;
12812
- this._ref = new Konva.Image({
12813
- x: params.position.x,
12814
- y: params.position.y,
12815
- image: this._canvasImage,
12816
- width: (_a = params.width) !== null && _a !== void 0 ? _a : 0,
12817
- height: (_b = params.height) !== null && _b !== void 0 ? _b : 0,
12818
- draggable: true
12819
- });
12820
12854
  this._canvasImage.onload = () => {
12821
12855
  this._ref.image(this._canvasImage);
12822
12856
  if (this._ref.height() <= this.EPSILON) this._ref.height(this._canvasImage.height);
@@ -12836,7 +12870,19 @@
12836
12870
  }
12837
12871
  }
12838
12872
  };
12873
+ this._canvasImage.onerror = () => {
12874
+ this._canvasImage.onerror = function() {};
12875
+ this._canvasImage.src = this.BASE64_NOT_FOUND;
12876
+ };
12839
12877
  this._canvasImage.src = params.src;
12878
+ this._ref = new Konva.Image({
12879
+ x: params.position.x,
12880
+ y: params.position.y,
12881
+ image: this._canvasImage,
12882
+ width: (_a = params.width) !== null && _a !== void 0 ? _a : 0,
12883
+ height: (_b = params.height) !== null && _b !== void 0 ? _b : 0,
12884
+ draggable: true
12885
+ });
12840
12886
  this._ref.on("transform", (e => {
12841
12887
  const attrs = e.target.attrs;
12842
12888
  if (attrs.rotation !== this._ref.rotation()) this._ref.rotation(attrs.rotation);
@@ -12935,7 +12981,11 @@
12935
12981
  this._ref = ref;
12936
12982
  return;
12937
12983
  }
12938
- if (!params || !params.position) return;
12984
+ if (!params) params = {};
12985
+ if (!params.position) params.position = {
12986
+ x: 100,
12987
+ y: 100
12988
+ };
12939
12989
  const arcRadius = 16;
12940
12990
  this._ref = new Konva.Shape({
12941
12991
  x: params.position.x,
@@ -13140,7 +13190,7 @@
13140
13190
 
13141
13191
  class KonvaMarkup {
13142
13192
  constructor() {
13143
- this._pointerEvents = [];
13193
+ this._containerEvents = [];
13144
13194
  this._markupIsActive = false;
13145
13195
  this._markupColor = new MarkupColor(255, 0, 0);
13146
13196
  this.lineWidth = 4;
@@ -13172,12 +13222,12 @@
13172
13222
  if (this._viewer) this._viewer.emit(event);
13173
13223
  };
13174
13224
  }
13175
- initialize(container, pointerEvents, viewer, worldTransformer) {
13225
+ initialize(container, containerEvents, viewer, worldTransformer) {
13176
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?');
13177
13227
  this._viewer = viewer;
13178
13228
  this._worldTransformer = worldTransformer !== null && worldTransformer !== void 0 ? worldTransformer : new WorldTransform;
13179
13229
  this._container = container;
13180
- this._pointerEvents = pointerEvents !== null && pointerEvents !== void 0 ? pointerEvents : [];
13230
+ this._containerEvents = containerEvents !== null && containerEvents !== void 0 ? containerEvents : [];
13181
13231
  this._markupContainer = document.createElement("div");
13182
13232
  this._markupContainer.id = "markup-container";
13183
13233
  this._markupContainer.style.position = "absolute";
@@ -13191,7 +13241,7 @@
13191
13241
  this._markupColor.setColor(255, 0, 0);
13192
13242
  this.initializeKonva();
13193
13243
  if (this._viewer) {
13194
- this._pointerEvents.forEach((x => this._markupContainer.addEventListener(x, this.redirectToViewer)));
13244
+ this._containerEvents.forEach((x => this._markupContainer.addEventListener(x, this.redirectToViewer)));
13195
13245
  this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
13196
13246
  this._viewer.addEventListener("pan", this.pan);
13197
13247
  }
@@ -13201,7 +13251,7 @@
13201
13251
  if (this._viewer) {
13202
13252
  this._viewer.removeEventListener("pan", this.pan);
13203
13253
  this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
13204
- this._pointerEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
13254
+ this._containerEvents.forEach((x => this._markupContainer.removeEventListener(x, this.redirectToViewer)));
13205
13255
  }
13206
13256
  this.destroyKonva();
13207
13257
  (_a = this._resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
@@ -13221,20 +13271,20 @@
13221
13271
  this.getObjects().forEach((obj => obj.delete()));
13222
13272
  }
13223
13273
  getMarkupColor() {
13224
- return this._markupColor.RGB;
13274
+ return this._markupColor.asRGB();
13225
13275
  }
13226
13276
  setMarkupColor(r, g, b) {
13227
13277
  this._markupColor.setColor(r, g, b);
13228
13278
  }
13229
13279
  colorizeAllMarkup(r, g, b) {
13230
- const hexColor = new MarkupColor(r, g, b).HexColor;
13280
+ const hexColor = new MarkupColor(r, g, b).asHex();
13231
13281
  this.getObjects().filter((obj => {
13232
13282
  var _a;
13233
13283
  return (_a = obj.setColor) === null || _a === void 0 ? void 0 : _a.call(obj, hexColor);
13234
13284
  }));
13235
13285
  }
13236
13286
  colorizeSelectedMarkups(r, g, b) {
13237
- const hexColor = new MarkupColor(r, g, b).HexColor;
13287
+ const hexColor = new MarkupColor(r, g, b).asHex();
13238
13288
  this.getSelectedObjects().filter((obj => {
13239
13289
  var _a;
13240
13290
  return (_a = obj.setColor) === null || _a === void 0 ? void 0 : _a.call(obj, hexColor);
@@ -13758,7 +13808,7 @@
13758
13808
  points: points,
13759
13809
  type: type || this.lineType,
13760
13810
  width: width || this.lineWidth,
13761
- color: color || this._markupColor.HexColor,
13811
+ color: color || this._markupColor.asHex(),
13762
13812
  id: id
13763
13813
  });
13764
13814
  this.addObject(konvaLine);
@@ -13775,7 +13825,7 @@
13775
13825
  this._textInputRef.style.top = inputY + "px";
13776
13826
  this._textInputRef.style.left = inputX + "px";
13777
13827
  this._textInputRef.style.fontSize = `${this.fontSize}px`;
13778
- this._textInputRef.style.color = `${this._markupColor.HexColor}`;
13828
+ this._textInputRef.style.color = `${this._markupColor.asHex()}`;
13779
13829
  this._textInputRef.style.fontFamily = "Calibri";
13780
13830
  this._textInputRef.onkeydown = event => {
13781
13831
  if (event.key === "Enter" && !event.shiftKey) {
@@ -13865,7 +13915,7 @@
13865
13915
  text: text,
13866
13916
  rotation: angle,
13867
13917
  fontSize: fontSize || this.fontSize,
13868
- color: color || this._markupColor.HexColor,
13918
+ color: color || this._markupColor.asHex(),
13869
13919
  id: id
13870
13920
  });
13871
13921
  this.addObject(konvaText);
@@ -13878,7 +13928,7 @@
13878
13928
  width: width,
13879
13929
  height: height,
13880
13930
  lineWidth: lineWidth || this.lineWidth,
13881
- color: color || this._markupColor.HexColor,
13931
+ color: color || this._markupColor.asHex(),
13882
13932
  id: id
13883
13933
  });
13884
13934
  this.addObject(konvaRectangle);
@@ -13890,7 +13940,7 @@
13890
13940
  position: position,
13891
13941
  radius: radius,
13892
13942
  lineWidth: lineWidth,
13893
- color: color || this._markupColor.HexColor,
13943
+ color: color || this._markupColor.asHex(),
13894
13944
  id: id
13895
13945
  });
13896
13946
  this.addObject(konvaEllipse);
@@ -13901,7 +13951,7 @@
13901
13951
  const konvaArrow = new KonvaArrow({
13902
13952
  start: start,
13903
13953
  end: end,
13904
- color: color || this._markupColor.HexColor,
13954
+ color: color || this._markupColor.asHex(),
13905
13955
  id: id
13906
13956
  });
13907
13957
  this.addObject(konvaArrow);
@@ -13913,7 +13963,7 @@
13913
13963
  position: position,
13914
13964
  width: width,
13915
13965
  height: height,
13916
- color: color || this._markupColor.HexColor,
13966
+ color: color || this._markupColor.asHex(),
13917
13967
  lineWidth: lineWidth || this.lineWidth,
13918
13968
  id: id
13919
13969
  });
@@ -16417,7 +16467,7 @@
16417
16467
  this.lineWidth = 4;
16418
16468
  this.fontSize = 34;
16419
16469
  }
16420
- initialize(canvas, canvasEvents, viewer, worldTransformer) {
16470
+ initialize(container, containerEvents, viewer, worldTransformer) {
16421
16471
  this._viewer = viewer;
16422
16472
  this._viewer.registerDragger("Line", OdaLineDragger);
16423
16473
  this._viewer.registerDragger("Text", OdaTextDragger);
@@ -16610,9 +16660,9 @@
16610
16660
  */
16611
16661
  class Viewer extends EventEmitter2 {
16612
16662
  /**
16613
- * @param client - The `Client` instance that provides access to a Open Cloud Server. Do not
16614
- * specify `Client` if you need a standalone viewer instance to view `VSFX` files from the
16615
- * 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.
16616
16666
  * @param params - An object containing viewer configuration parameters.
16617
16667
  * @param params.visualizeJsUrl - `VisualizeJS` library URL. Set this URL to use your own
16618
16668
  * library instance, or specify `undefined` or blank to use the default URL defined by
@@ -17282,9 +17332,12 @@
17282
17332
  this.update();
17283
17333
  }
17284
17334
  /**
17285
- * Loads a model/file/assembly into the viewer.
17335
+ * Loads a file from Open Cloud Server into the viewer.
17286
17336
  *
17287
- * This method requires a {@link Client} instance to work. For standalone viewer instance use
17337
+ * The file geometry data on the server must be converted to `VSFX` format.
17338
+ *
17339
+ * This method requires a `Client` instance to be specified when creating the viewer to load
17340
+ * model reference files from the Open Cloud Server. For a standalone viewer instance use
17288
17341
  * {@link openVsfFile | openVsfFile()} or {@link openVsfxFile | openVsfxFile()}.
17289
17342
  *
17290
17343
  * Fires:
@@ -17297,9 +17350,9 @@
17297
17350
  * - {@link GeometryEndEvent | geometryend}
17298
17351
  * - {@link GeometryErrorEvent | geometryerror}
17299
17352
  *
17300
- * @param file - File or Assembly or Model instance to load. If a `File` instance with
17301
- * multiple models is specified, the default model will be loaded. If there is no default
17302
- * model, first availiable model will be loaded.
17353
+ * @param file - File, assembly or specific model to load. If a `File` instance with multiple
17354
+ * models is specified, the default model will be loaded. If there is no default model,
17355
+ * first availiable model will be loaded.
17303
17356
  */
17304
17357
  async open(file) {
17305
17358
  if (!this.visualizeJs)
@@ -17452,9 +17505,9 @@
17452
17505
  *
17453
17506
  * - {@link ChangeMarkupColorEvent | changemarkupcolor}
17454
17507
  *
17455
- * @param r - `Red` part of color.
17456
- * @param g - `Green` part of color.
17457
- * @param b - `Blue` part of color.
17508
+ * @param r - The `red` component of the color, as a number between 0 and 255.
17509
+ * @param g - The `green` component of the color, as a number between 0 and 255.
17510
+ * @param b - The `blue` component of the color, as a number between 0 and 255.
17458
17511
  */
17459
17512
  setMarkupColor(r = 255, g = 0, b = 0) {
17460
17513
  this._markup.setMarkupColor(r, g, b);
@@ -17464,15 +17517,15 @@
17464
17517
  /**
17465
17518
  * Colors all markup objects with the specified color.
17466
17519
  *
17467
- * @param r - `Red` part of color.
17468
- * @param g - `Green` part of color.
17469
- * @param b - `Blue` part of color.
17520
+ * @param r - The `red` component of the color, as a number between 0 and 255.
17521
+ * @param g - The `green` component of the color, as a number between 0 and 255.
17522
+ * @param b - The `blue` component of the color, as a number between 0 and 255.
17470
17523
  */
17471
17524
  colorizeAllMarkup(r = 255, g = 0, b = 0) {
17472
17525
  this._markup.colorizeAllMarkup(r, g, b);
17473
17526
  }
17474
17527
  /**
17475
- * Colors selected markup objects with the specified color.
17528
+ * Colors the selected markup objects with the specified color.
17476
17529
  *
17477
17530
  * @param r - `Red` part of color.
17478
17531
  * @param g - `Green` part of color.
@@ -17502,7 +17555,8 @@
17502
17555
  /**
17503
17556
  * Sets the viewer state to the specified viewpoint.
17504
17557
  *
17505
- * To get a list of available model viewpoints, use the `File.getViewpoints()`.
17558
+ * To get a list of available viewpoints from the server for a specific file, use the
17559
+ * `File.getViewpoints()`.
17506
17560
  *
17507
17561
  * @param viewpoint - Viewpoint data.
17508
17562
  */
@@ -17514,7 +17568,7 @@
17514
17568
  /**
17515
17569
  * Saves the viewer state at the viewpoint.
17516
17570
  *
17517
- * To save a viewpoint to a model on the server, use the `File.saveViewpoint()`.
17571
+ * To save a viewpoint to the server for a specific file, use the `File.saveViewpoint()`.
17518
17572
  */
17519
17573
  createViewpoint() {
17520
17574
  const vp = this._markup.getViewpoint();