@inweb/viewer-visualize 25.3.19 → 25.3.20

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.
@@ -680,27 +680,24 @@
680
680
 
681
681
  class EventEmitter2 {
682
682
  constructor() {
683
- this._listeners = undefined;
683
+ this._listeners = {};
684
684
  }
685
685
  addEventListener(type, listener) {
686
- if (this._listeners === undefined) this._listeners = {};
687
686
  if (this._listeners[type] === undefined) this._listeners[type] = [];
688
687
  this._listeners[type].push(listener);
689
688
  return this;
690
689
  }
691
690
  removeEventListener(type, listener) {
692
- if (this._listeners === undefined) return this;
693
691
  if (this._listeners[type] === undefined) return this;
694
692
  const listeners = this._listeners[type].filter((x => x !== listener));
695
- this._listeners[type] = listeners.length === 0 ? undefined : listeners;
693
+ if (listeners.length !== 0) this._listeners[type] = listeners; else delete this._listeners[type];
696
694
  return this;
697
695
  }
698
696
  removeAllListeners(type) {
699
- if (type) this._listeners[type] = undefined; else this._listeners = undefined;
697
+ if (type) delete this._listeners[type]; else this._listeners = {};
700
698
  return this;
701
699
  }
702
700
  emitEvent(event) {
703
- if (this._listeners === undefined) return false;
704
701
  if (this._listeners[event.type] === undefined) return false;
705
702
  const invoke = this._listeners[event.type].slice();
706
703
  invoke.forEach((listener => listener.call(this, event)));
@@ -2709,20 +2706,18 @@
2709
2706
  const visLib = this.viewer.visLib();
2710
2707
  const visViewer = visLib.getViewer();
2711
2708
  const abortController = new AbortController();
2712
- const listFileForDownload = [this.model.database, ...this.model.geometry];
2713
- const chunksProgress = listFileForDownload.map(() => 0);
2714
- const calcProgress = (index, progress) => {
2715
- chunksProgress[index] = progress;
2716
- const fileProgress = chunksProgress.reduce((acc, progress) => (acc += progress)) / (chunksProgress.length || 1);
2717
- this.viewer.emitEvent({ type: "geometryprogress", data: fileProgress, model: this.model });
2718
- };
2709
+ const filesToDownload = [this.model.database, ...this.model.geometry];
2719
2710
  this.viewer._abortController = abortController;
2711
+ console.time("File load time");
2720
2712
  try {
2721
2713
  this.viewer.emitEvent({ type: "geometrystart", model: this.model });
2722
- for (let i = 0; i < listFileForDownload.length; i++) {
2723
- const chunk = listFileForDownload[i];
2724
- const progressCb = (progress) => calcProgress(i, progress);
2725
- const arrayBuffer = await this.model.downloadResource(chunk, progressCb, abortController.signal);
2714
+ for (let i = 0; i < filesToDownload.length; i++) {
2715
+ const dataId = filesToDownload[i];
2716
+ const chunkLoadHandler = (progress) => {
2717
+ const data = (i + progress) / filesToDownload.length;
2718
+ this.viewer.emitEvent({ type: "geometryprogress", data, model: this.model });
2719
+ };
2720
+ const arrayBuffer = await this.model.downloadResource(dataId, chunkLoadHandler, abortController.signal);
2726
2721
  if (abortController.signal.aborted) {
2727
2722
  await Promise.reject(new Error(`Open model aborted ${this.model.name}`));
2728
2723
  }
@@ -2740,6 +2735,44 @@
2740
2735
  this.viewer.emitEvent({ type: "geometrychunk", data, model: this.model });
2741
2736
  }
2742
2737
  }
2738
+ console.timeEnd("File load time");
2739
+ this.viewer.emitEvent({ type: "geometryend", model: this.model });
2740
+ }
2741
+ catch (error) {
2742
+ this.viewer.emitEvent({ type: "geometryerror", data: error, model: this.model });
2743
+ throw error;
2744
+ }
2745
+ }
2746
+ }
2747
+
2748
+ ///////////////////////////////////////////////////////////////////////////////
2749
+ class VsfXLoader extends BaseLoader {
2750
+ async load() {
2751
+ if (!this.viewer.visualizeJs)
2752
+ return;
2753
+ const visLib = this.viewer.visLib();
2754
+ const visViewer = visLib.getViewer();
2755
+ const abortController = new AbortController();
2756
+ this.viewer._abortController = abortController;
2757
+ const chunkLoadHandler = (progress) => {
2758
+ this.viewer.emitEvent({ type: "geometryprogress", data: progress, model: this.model });
2759
+ };
2760
+ console.time("File load time");
2761
+ try {
2762
+ this.viewer.emitEvent({ type: "geometrystart", model: this.model });
2763
+ const arrayBuffer = await this.model.downloadResource(this.model.database, chunkLoadHandler, abortController.signal);
2764
+ if (abortController.signal.aborted) {
2765
+ await Promise.reject(new Error(`Open model aborted ${this.model.name}`));
2766
+ }
2767
+ const data = new Uint8Array(arrayBuffer);
2768
+ if (this.viewer.visualizeJs) {
2769
+ visViewer.parseVsfx(data);
2770
+ this.viewer.syncOpenCloudVisualStyle(false);
2771
+ this.viewer.syncOptions();
2772
+ this.viewer.resize();
2773
+ }
2774
+ console.timeEnd("File load time");
2775
+ this.viewer.emitEvent({ type: "databasechunk", data, model: this.model });
2743
2776
  this.viewer.emitEvent({ type: "geometryend", model: this.model });
2744
2777
  }
2745
2778
  catch (error) {
@@ -2759,6 +2792,7 @@
2759
2792
  })(UpdateType || (UpdateType = {}));
2760
2793
  class UpdaterController {
2761
2794
  constructor() {
2795
+ this.lastUpdate = 0;
2762
2796
  this.delayUpdateTime = START_UPDATE_TIME;
2763
2797
  }
2764
2798
  initialize(viewer) {
@@ -2869,7 +2903,7 @@
2869
2903
  const abortCtrl = new AbortController();
2870
2904
  abortControllerForRequestMap.set(requestId, abortCtrl);
2871
2905
  try {
2872
- await this.model.downloadResourceRange(dataId, ranges, requestId, chunkLoadHandler, abortCtrl.signal);
2906
+ await this.model.downloadResourceRange(dataId, requestId, ranges, chunkLoadHandler, abortCtrl.signal);
2873
2907
  }
2874
2908
  catch (error) {
2875
2909
  this.viewer.emitEvent({ type: "geometryerror", data: error, model: this.model });
@@ -2982,43 +3016,6 @@
2982
3016
  }
2983
3017
  }
2984
3018
 
2985
- ///////////////////////////////////////////////////////////////////////////////
2986
- class VsfXLoader extends BaseLoader {
2987
- async load() {
2988
- if (!this.viewer.visualizeJs)
2989
- return;
2990
- const visLib = this.viewer.visLib();
2991
- const visViewer = visLib.getViewer();
2992
- const abortController = new AbortController();
2993
- this.viewer._abortController = abortController;
2994
- const chunkLoadHandler = (progress) => {
2995
- this.viewer.emitEvent({ type: "geometryprogress", data: progress, model: this.model });
2996
- };
2997
- console.time("File load time");
2998
- try {
2999
- this.viewer.emitEvent({ type: "geometrystart", model: this.model });
3000
- const arrayBuffer = await this.model.downloadResource(this.model.database, chunkLoadHandler, abortController.signal);
3001
- if (abortController.signal.aborted) {
3002
- await Promise.reject(new Error(`Open model aborted ${this.model.name}`));
3003
- }
3004
- const data = new Uint8Array(arrayBuffer);
3005
- if (this.viewer.visualizeJs) {
3006
- visViewer.parseVsfx(data);
3007
- this.viewer.syncOpenCloudVisualStyle(false);
3008
- this.viewer.syncOptions();
3009
- this.viewer.resize();
3010
- }
3011
- console.timeEnd("File load time");
3012
- this.viewer.emitEvent({ type: "databasechunk", data, model: this.model });
3013
- this.viewer.emitEvent({ type: "geometryend", model: this.model });
3014
- }
3015
- catch (error) {
3016
- this.viewer.emitEvent({ type: "geometryerror", data: error, model: this.model });
3017
- throw error;
3018
- }
3019
- }
3020
- }
3021
-
3022
3019
  ///////////////////////////////////////////////////////////////////////////////
3023
3020
  class LoaderFactory {
3024
3021
  create(viewer, model, options) {
@@ -16401,15 +16398,17 @@
16401
16398
  * the auto-update is disabled, you need to update the `VisualizeJS` viewer and the active
16402
16399
  * dragger manually using the `update` event. Default is `true`.
16403
16400
  */
16404
- constructor(client, params = {
16405
- markupType: MarkupType.Konva,
16406
- }) {
16401
+ constructor(client, params = {}) {
16407
16402
  var _a, _b;
16408
16403
  super();
16404
+ this._visualizeJsUrl = "";
16405
+ this.frameId = 0;
16409
16406
  this.configure(params);
16410
16407
  this._options = new Options(this);
16411
16408
  this.client = client;
16412
16409
  this._activeDragger = null;
16410
+ this._zoomWheelDragger = null;
16411
+ this._gestureManager = null;
16413
16412
  this._renderTime = 0;
16414
16413
  this.markup = MarkupFactory.createMarkup((_a = params.markupType) !== null && _a !== void 0 ? _a : MarkupType.Konva);
16415
16414
  this.draggerFactory = new Map();
@@ -16586,7 +16585,7 @@
16586
16585
  * @param force - If `true` updates the viewer immidietly. Otherwise updates on next
16587
16586
  * animation frame. Default is `false`.
16588
16587
  */
16589
- update(force) {
16588
+ update(force = false) {
16590
16589
  var _a, _b;
16591
16590
  if (this._enableAutoUpdate) {
16592
16591
  if (force) {
@@ -16961,6 +16960,8 @@
16961
16960
  var _a;
16962
16961
  if (!this.visualizeJs)
16963
16962
  return this;
16963
+ if (!this.client)
16964
+ return this;
16964
16965
  const abortController = new AbortController();
16965
16966
  (_a = this._abortControllerForReferences) === null || _a === void 0 ? void 0 : _a.abort();
16966
16967
  this._abortControllerForReferences = abortController;
@@ -17024,7 +17025,7 @@
17024
17025
  this.cancel();
17025
17026
  this.clear();
17026
17027
  this.emitEvent({ type: "open", file, model: file });
17027
- let model;
17028
+ let model = undefined;
17028
17029
  if (file) {
17029
17030
  const models = (await file.getModels()) || [];
17030
17031
  model = models.find((model) => model.default) || models[0];