@inweb/viewer-visualize 27.5.0 → 27.6.0

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.
@@ -3,7 +3,6 @@ import { OdBaseDragger } from "./Common/OdBaseDragger";
3
3
  export declare const MARKUP_ENTITY_LINE = "$MarkupTempEntity_Line";
4
4
  export declare class OdaLineDragger extends OdBaseDragger {
5
5
  protected entity: any;
6
- protected points: any[];
7
6
  protected drawPoints: any[];
8
7
  constructor(subject: Viewer);
9
8
  dispose(): void;
@@ -9,7 +9,7 @@ export declare class VisualizeMarkup implements IMarkup {
9
9
  b: number;
10
10
  };
11
11
  lineWidth: number;
12
- lineType: "solid";
12
+ lineType: string;
13
13
  fontSize: number;
14
14
  initialize(container: HTMLElement, containerEvents: string[], viewer?: IEventEmitter, worldTransformer?: IWorldTransform): void;
15
15
  dispose(): void;
@@ -232,7 +232,7 @@ export declare class Viewer extends EventEmitter2<ViewerEventMap & CanvasEventMa
232
232
  activeDragger(): IDragger | null;
233
233
  setActiveDragger(name?: string): IDragger | null;
234
234
  resetActiveDragger(): void;
235
- getComponent(name: string): IComponent;
235
+ getComponent(name: string): IComponent | null;
236
236
  drawViewpoint(viewpoint: IViewpoint): void;
237
237
  createViewpoint(): IViewpoint;
238
238
  getSnapshot(type?: string, quality?: number): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/viewer-visualize",
3
- "version": "27.5.0",
3
+ "version": "27.6.0",
4
4
  "description": "JavaScript library for rendering CAD and BIM files in a browser using VisualizeJS",
5
5
  "homepage": "https://cloud.opendesign.com/docs/index.html",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -29,10 +29,10 @@
29
29
  "docs": "typedoc"
30
30
  },
31
31
  "dependencies": {
32
- "@inweb/client": "~27.5.0",
33
- "@inweb/eventemitter2": "~27.5.0",
34
- "@inweb/markup": "~27.5.0",
35
- "@inweb/viewer-core": "~27.5.0"
32
+ "@inweb/client": "~27.6.0",
33
+ "@inweb/eventemitter2": "~27.6.0",
34
+ "@inweb/markup": "~27.6.0",
35
+ "@inweb/viewer-core": "~27.6.0"
36
36
  },
37
37
  "visualizeJS": "https://public-fhemb7e3embacwec.z02.azurefd.net/libs/visualizejs/master/Visualize.js"
38
38
  }
@@ -24,7 +24,7 @@
24
24
  import { Viewer } from "../Viewer";
25
25
 
26
26
  export function setSelected2(viewer: Viewer, handles2: string[] = []): void {
27
- const handles = [];
27
+ const handles: string[] = [];
28
28
 
29
29
  handles2.forEach((handle) => {
30
30
  if (!handle.includes(":")) {
@@ -36,7 +36,6 @@ export class CanvasRemoveComponent implements IComponent {
36
36
 
37
37
  dispose() {
38
38
  this.mutationObserver.disconnect();
39
- this.mutationObserver = undefined;
40
39
  }
41
40
 
42
41
  cleanupViewer = (mutations: MutationRecord[]) => {
@@ -34,6 +34,5 @@ export class GestureManagerComponent implements IComponent {
34
34
 
35
35
  dispose() {
36
36
  this.gestureManager.dispose();
37
- this.gestureManager = undefined;
38
37
  }
39
38
  }
@@ -35,6 +35,5 @@ export class ZoomWheelComponent implements IComponent {
35
35
 
36
36
  dispose() {
37
37
  this.zoomWheelDragger.dispose();
38
- this.zoomWheelDragger = undefined;
39
38
  }
40
39
  }
@@ -37,7 +37,7 @@ export class OdBaseDragger extends OdaGeAction {
37
37
  protected isDragging: boolean;
38
38
  protected press: boolean;
39
39
 
40
- public name: string;
40
+ public name = "";
41
41
 
42
42
  constructor(subject: Viewer) {
43
43
  super(subject.visualizeJs);
@@ -45,6 +45,8 @@ export class OdBaseDragger extends OdaGeAction {
45
45
  this.needInputText = false;
46
46
  this.mouseDownPosition = { x: 0, y: 0 };
47
47
  this.autoSelect = false;
48
+ this.isDragging = false;
49
+ this.press = false;
48
50
 
49
51
  this.pointerdown = this.pointerdown.bind(this);
50
52
  this.pointerup = this.pointerup.bind(this);
@@ -142,8 +142,8 @@ export function getDataForDrawLineWithFixed(p1: Point2d, p2: Point2d, width: num
142
142
  checkSegmentsIntersect(p1, p2, pLB, pRB, intersects);
143
143
  checkSegmentsIntersect(p1, p2, pRB, pRU, intersects);
144
144
 
145
- let fixedP1: Point2d = null;
146
- let fixedP2: Point2d = null;
145
+ let fixedP1: Point2d | null = null;
146
+ let fixedP2: Point2d | null = null;
147
147
 
148
148
  if (intersects.length === 0) {
149
149
  fixedP1 = p1;
@@ -27,24 +27,23 @@ export const MARKUP_ENTITY_LINE = "$MarkupTempEntity_Line";
27
27
 
28
28
  export class OdaLineDragger extends OdBaseDragger {
29
29
  protected entity: any;
30
- protected points: any[];
31
30
  protected drawPoints: any[];
32
31
 
33
32
  constructor(subject: Viewer) {
34
33
  super(subject);
35
34
  this.press = false;
35
+ this.drawPoints = [];
36
36
  }
37
37
 
38
38
  override dispose(): void {
39
39
  super.dispose();
40
40
  this.end();
41
- this.points = null;
42
- this.drawPoints = null;
41
+ this.drawPoints.length = 0;
43
42
  }
44
43
 
45
44
  override start(x: number, y: number): void {
46
45
  const point = this.getViewer().screenToWorld(x, y);
47
- this.drawPoints = [point[0], point[1], point[2]];
46
+ this.drawPoints.push(point[0], point[1], point[2]);
48
47
  }
49
48
 
50
49
  override drag(x: number, y: number): void {
@@ -58,7 +57,7 @@ export class OdaLineDragger extends OdBaseDragger {
58
57
  override end(): void {
59
58
  if (this.entity) {
60
59
  this.entity.delete();
61
- this.drawPoints = null;
60
+ this.drawPoints.length = 0;
62
61
  this.entity = null;
63
62
  }
64
63
  }
@@ -24,12 +24,11 @@
24
24
  export class FileLoader {
25
25
  private requestHeader: HeadersInit;
26
26
  private withCredentials: boolean;
27
- private abortSignal: AbortSignal;
27
+ private abortSignal: AbortSignal | undefined;
28
28
 
29
29
  constructor() {
30
30
  this.requestHeader = {};
31
31
  this.withCredentials = false;
32
- this.abortSignal = undefined;
33
32
  }
34
33
 
35
34
  setRequestHeader(requestHeader: HeadersInit) {
@@ -56,13 +55,16 @@ export class FileLoader {
56
55
  .then((response) => {
57
56
  if (!response.ok) throw new Error(`Failed to fetch "${response.url}", status ${response.status}`);
58
57
 
58
+ const body = response.body;
59
+ if (!body) return response;
60
+
59
61
  const contentLength = response.headers.get("X-File-Size") || response.headers.get("Content-Length");
60
62
  const total = parseInt(contentLength || "", 10) || 0;
61
63
  const lengthComputable = total > 0;
62
64
 
63
65
  const stream = new ReadableStream({
64
66
  async start(controller) {
65
- const reader = response.body.getReader();
67
+ const reader = body.getReader();
66
68
  let loaded = 0;
67
69
  try {
68
70
  while (true) {
@@ -91,7 +93,7 @@ export class FileLoader {
91
93
  const reader = new FileReader();
92
94
  reader.onload = () => resolve(reader.result as any);
93
95
  reader.onerror = () => reject(reader.error);
94
- reader.onprogress = onProgress;
96
+ reader.onprogress = onProgress || null;
95
97
  reader.readAsArrayBuffer(new Blob([file]));
96
98
  });
97
99
  }
@@ -34,7 +34,7 @@ export class VSFFileLoader extends Loader {
34
34
  this.viewer = viewer;
35
35
  }
36
36
 
37
- override isSupport(file: any, format?: string): boolean {
37
+ override isSupport(file: any, format = ""): boolean {
38
38
  return (
39
39
  (typeof file === "string" || file instanceof globalThis.File || file instanceof ArrayBuffer) &&
40
40
  /vsf$/i.test(format)
@@ -52,6 +52,8 @@ export class VSFXCloudPartialLoader extends Loader {
52
52
  override async load(model: any): Promise<this> {
53
53
  if (!this.viewer.visualizeJs) return this;
54
54
 
55
+ type Range = { requestId: number; begin: number; end: number };
56
+
55
57
  const visViewer = this.viewer.visViewer();
56
58
  visViewer.memoryLimit = this.viewer.options.memoryLimit;
57
59
 
@@ -94,7 +96,7 @@ export class VSFXCloudPartialLoader extends Loader {
94
96
  }
95
97
  };
96
98
 
97
- const downloadResourceRange = async (dataId: string, requestId: number, ranges: any) => {
99
+ const downloadResourceRange = async (dataId: string, requestId: number, ranges: Range[]) => {
98
100
  const abortCtrl = new AbortController();
99
101
  this.abortControllerForRequestMap.set(requestId, abortCtrl);
100
102
  try {
@@ -107,8 +109,8 @@ export class VSFXCloudPartialLoader extends Loader {
107
109
  }
108
110
  };
109
111
 
110
- const requestRecordsToRanges = (requestId: number, records: any): any => {
111
- const ranges = [];
112
+ const requestRecordsToRanges = (requestId: number, records: any): Range[] => {
113
+ const ranges: Range[] = [];
112
114
  for (let i = 0; i < records.size(); i++) {
113
115
  const record = records.get(i);
114
116
  ranges.push({
@@ -151,7 +153,7 @@ export class VSFXCloudPartialLoader extends Loader {
151
153
  const dataId = `${model.fileId}${model.file.type}`;
152
154
  const ranges = requestRecordsToRanges(requestId, records);
153
155
 
154
- let pendingRanges = [];
156
+ let pendingRanges: Range[] = [];
155
157
  let requestNumber = 0;
156
158
  const pendingRequest = pendingRequestsMap.get(dataId);
157
159
  if (pendingRequest) {
@@ -34,7 +34,7 @@ export class VSFXFileLoader extends Loader {
34
34
  this.viewer = viewer;
35
35
  }
36
36
 
37
- override isSupport(file: any, format?: string): boolean {
37
+ override isSupport(file: any, format = ""): boolean {
38
38
  return (
39
39
  (typeof file === "string" || file instanceof globalThis.File || file instanceof ArrayBuffer) &&
40
40
  /vsfx$/i.test(format)
@@ -33,7 +33,7 @@ export class VisualizeMarkup implements IMarkup {
33
33
  protected _markupColor = { r: 255, g: 0, b: 0 };
34
34
 
35
35
  public lineWidth = 4;
36
- public lineType: "solid";
36
+ public lineType = "solid";
37
37
  public fontSize = 34;
38
38
 
39
39
  initialize(
@@ -26,7 +26,7 @@ import { IModelImpl } from "./IModelImpl";
26
26
  // Basic model implementation.
27
27
 
28
28
  export class ModelImpl implements IModelImpl {
29
- public id: string;
29
+ public id = "";
30
30
 
31
31
  dispose(): void {}
32
32
  }
@@ -127,6 +127,7 @@ export class Viewer
127
127
  this.canvasEvents = CANVAS_EVENTS.slice();
128
128
  this.canvaseventlistener = (event: Event) => this.emit(event);
129
129
 
130
+ this._visualizeTimestamp = 0;
130
131
  this._activeDragger = null;
131
132
  this._components = [];
132
133
 
@@ -274,7 +275,8 @@ export class Viewer
274
275
  this._markup.initialize(this.canvas, this.canvasEvents, this, this);
275
276
 
276
277
  for (const name of components.getComponents().keys()) {
277
- this._components.push(components.createComponent(name, this));
278
+ const component = components.createComponent(name, this);
279
+ if (component) this._components.push(component);
278
280
  }
279
281
 
280
282
  this.syncOptions();
@@ -300,10 +302,7 @@ export class Viewer
300
302
  this._components.forEach((component: IComponent) => component.dispose());
301
303
  this._components.length = 0;
302
304
 
303
- if (this._markup) {
304
- this._markup.dispose();
305
- this._markup = undefined;
306
- }
305
+ this._markup.dispose();
307
306
 
308
307
  if (this.canvas) {
309
308
  this.canvasEvents.forEach((x) => this.canvas.removeEventListener(x, this.canvaseventlistener));
@@ -313,7 +312,7 @@ export class Viewer
313
312
  if (this._viewer) this._viewer.clear();
314
313
 
315
314
  this._visualizeJs = undefined;
316
- this._visualizeTimestamp = undefined;
315
+ this._visualizeTimestamp = 0;
317
316
  this._viewer = undefined;
318
317
 
319
318
  return this;
@@ -884,8 +883,8 @@ export class Viewer
884
883
 
885
884
  setActiveDragger(name = ""): IDragger | null {
886
885
  if (!this._activeDragger || this._activeDragger.name !== name) {
887
- const oldDragger = this._activeDragger;
888
- let newDragger = null;
886
+ const oldDragger: IDragger | null = this._activeDragger;
887
+ let newDragger: IDragger | null = null;
889
888
 
890
889
  if (this._activeDragger) {
891
890
  this._activeDragger.dispose();
@@ -915,8 +914,8 @@ export class Viewer
915
914
  }
916
915
  }
917
916
 
918
- getComponent(name: string): IComponent {
919
- return this._components.find((component) => component.name === name);
917
+ getComponent(name: string): IComponent | null {
918
+ return this._components.find((component) => component.name === name) || null;
920
919
  }
921
920
 
922
921
  drawViewpoint(viewpoint: IViewpoint): void {
@@ -929,7 +928,7 @@ export class Viewer
929
928
  return [point3d.x, point3d.y, point3d.z];
930
929
  };
931
930
 
932
- const setOrthogonalCamera = (orthogonal_camera: IOrthogonalCamera) => {
931
+ const setOrthogonalCamera = (orthogonal_camera?: IOrthogonalCamera) => {
933
932
  if (orthogonal_camera) {
934
933
  activeView.setView(
935
934
  getPoint3dAsArray(orthogonal_camera.view_point),
@@ -945,7 +944,7 @@ export class Viewer
945
944
  }
946
945
  };
947
946
 
948
- const setPerspectiveCamera = (perspective_camera: IPerspectiveCamera) => {
947
+ const setPerspectiveCamera = (perspective_camera?: IPerspectiveCamera) => {
949
948
  if (perspective_camera) {
950
949
  // ===================== AI-CODE-START ======================
951
950
  // Source: Claude Sonnet 4.5
@@ -984,7 +983,7 @@ export class Viewer
984
983
  }
985
984
  };
986
985
 
987
- const setClippingPlanes = (clipping_planes: IClippingPlane[]) => {
986
+ const setClippingPlanes = (clipping_planes?: IClippingPlane[]) => {
988
987
  if (clipping_planes) {
989
988
  for (const clipping_plane of clipping_planes) {
990
989
  const cuttingPlane = new (this.visLib().OdTvPlane)();
@@ -1035,7 +1034,7 @@ export class Viewer
1035
1034
  return { x: array[0], y: array[1], z: array[2] };
1036
1035
  };
1037
1036
 
1038
- const getOrthogonalCamera = (): IOrthogonalCamera => {
1037
+ const getOrthogonalCamera = (): IOrthogonalCamera | undefined => {
1039
1038
  if (!activeView.perspective)
1040
1039
  return {
1041
1040
  view_point: getPoint3dFromArray(activeView.viewPosition),
@@ -1048,7 +1047,7 @@ export class Viewer
1048
1047
  else return undefined;
1049
1048
  };
1050
1049
 
1051
- const getPerspectiveCamera = (): IPerspectiveCamera => {
1050
+ const getPerspectiveCamera = (): IPerspectiveCamera | undefined => {
1052
1051
  if (activeView.perspective) {
1053
1052
  // ===================== AI-CODE-START ======================
1054
1053
  // Source: Claude Sonnet 4.5
@@ -1080,7 +1079,7 @@ export class Viewer
1080
1079
  };
1081
1080
 
1082
1081
  const getClippingPlanes = (): IClippingPlane[] => {
1083
- const clipping_planes = [];
1082
+ const clipping_planes: IClippingPlane[] = [];
1084
1083
  for (let i = 0; i < activeView.numCuttingPlanes(); i++) {
1085
1084
  const cuttingPlane = activeView.getCuttingPlane(i);
1086
1085
 
@@ -30,7 +30,7 @@ export function loadScript(url: string, params: LoadParams = {}): Promise<HTMLSc
30
30
  const script = document.createElement("script");
31
31
  script.src = url;
32
32
  script.async = true;
33
- script.crossOrigin = params.crossOrigin;
33
+ script.crossOrigin = params.crossOrigin || null;
34
34
  script.onload = () => resolve(script);
35
35
  script.onerror = () => {
36
36
  script.remove();