@inweb/viewer-core 26.10.5 → 26.11.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.
@@ -19,7 +19,7 @@ export interface AnimateEvent {
19
19
  time: DOMHighResTimeStamp;
20
20
  }
21
21
  /**
22
- * Event that fires when model loading has been canceled.
22
+ * Event that fires when file loading has been canceled.
23
23
  *
24
24
  * @event
25
25
  */
@@ -207,7 +207,7 @@ export interface GeometryChunkEvent {
207
207
  buffer?: Uint8Array | ArrayBuffer;
208
208
  }
209
209
  /**
210
- * Event that fires after model has been successfully loaded.
210
+ * Event that fires after file has been successfully loaded.
211
211
  *
212
212
  * @event
213
213
  */
@@ -261,7 +261,7 @@ export interface GeometryErrorEvent {
261
261
  buffer?: Uint8Array | ArrayBuffer;
262
262
  }
263
263
  /**
264
- * Event that measures the progress of the model loading.
264
+ * Event that measures the progress of the file loading.
265
265
  *
266
266
  * @event
267
267
  */
@@ -290,7 +290,7 @@ export interface GeometryProgressEvent {
290
290
  buffer?: Uint8Array | ArrayBuffer;
291
291
  }
292
292
  /**
293
- * Event that fires before the model loads.
293
+ * Event that fires before the file loads.
294
294
  *
295
295
  * @event
296
296
  */
@@ -373,7 +373,7 @@ export interface IsolateEvent {
373
373
  type: "isolate";
374
374
  }
375
375
  /**
376
- * Event that fires before model open.
376
+ * Event that fires before file open.
377
377
  *
378
378
  * @event
379
379
  */
@@ -383,13 +383,13 @@ export interface OpenEvent {
383
383
  */
384
384
  type: "open";
385
385
  /**
386
- * File to load.
386
+ * File opening mode.
387
387
  */
388
- file: File | Assembly | Model | string | globalThis.File | ArrayBuffer;
388
+ mode: string;
389
389
  /**
390
- * Model from file to load. Only defined when loading a file from the Open Cloud Server.
390
+ * File to load.
391
391
  */
392
- model?: Model;
392
+ file: File | Assembly | Model | string | globalThis.File | ArrayBuffer;
393
393
  /**
394
394
  * Deprecated since `26.4`. Use {@link file} instead.
395
395
  *
@@ -487,9 +487,29 @@ export interface SelectEvent {
487
487
  /**
488
488
  * Selection set (viewer dependent).
489
489
  */
490
- data: any;
490
+ data?: any;
491
491
  /**
492
- * Handles of selected entities.
492
+ * Handles of selected objects.
493
+ */
494
+ handles: string[];
495
+ }
496
+ /**
497
+ * Event that fires after viewer selection changes. Uses model prefix to avoid handle collisions in
498
+ * assemblies (multi-model scenes).
499
+ *
500
+ * @event
501
+ */
502
+ export interface Select2Event {
503
+ /**
504
+ * Event type.
505
+ */
506
+ type: "select2";
507
+ /**
508
+ * Selection set (viewer dependent).
509
+ */
510
+ data?: any;
511
+ /**
512
+ * Handles of selected objects with model prefix in format "model:handle".
493
513
  */
494
514
  handles: string[];
495
515
  }
@@ -683,7 +703,7 @@ export interface ViewerEventMap {
683
703
  */
684
704
  animate: AnimateEvent;
685
705
  /**
686
- * Event that fires when model loading has been canceled.
706
+ * Event that fires when file loading has been canceled.
687
707
  */
688
708
  cancel: CancelEvent;
689
709
  /**
@@ -735,7 +755,7 @@ export interface ViewerEventMap {
735
755
  */
736
756
  geometrychunk: GeometryChunkEvent;
737
757
  /**
738
- * Event that fires after model has been successfully loaded.
758
+ * Event that fires after file has been successfully loaded.
739
759
  */
740
760
  geometryend: GeometryEndEvent;
741
761
  /**
@@ -743,11 +763,11 @@ export interface ViewerEventMap {
743
763
  */
744
764
  geometryerror: GeometryErrorEvent;
745
765
  /**
746
- * Event that measures the progress of the model loading.
766
+ * Event that measures the progress of the file loading.
747
767
  */
748
768
  geometryprogress: GeometryProgressEvent;
749
769
  /**
750
- * Event that fires before the model opens.
770
+ * Event that fires before the file opens.
751
771
  */
752
772
  geometrystart: GeometryStartEvent;
753
773
  /**
@@ -767,7 +787,7 @@ export interface ViewerEventMap {
767
787
  */
768
788
  isolate: IsolateEvent;
769
789
  /**
770
- * Event that fires before model opens.
790
+ * Event that fires before file opens.
771
791
  */
772
792
  open: OpenEvent;
773
793
  /**
@@ -790,6 +810,10 @@ export interface ViewerEventMap {
790
810
  * Event that fires when the selection changes.
791
811
  */
792
812
  select: SelectEvent;
813
+ /**
814
+ * Event that fires when the selection changes.
815
+ */
816
+ select2: Select2Event;
793
817
  /**
794
818
  * Event that fires after selected objects becomes visible.
795
819
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/viewer-core",
3
- "version": "26.10.5",
3
+ "version": "26.11.0",
4
4
  "description": "3D CAD and BIM data Viewer core",
5
5
  "homepage": "https://cloud.opendesign.com/docs/index.html",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -26,7 +26,7 @@
26
26
  "test": "karma start karma.conf.js"
27
27
  },
28
28
  "dependencies": {
29
- "@inweb/client": "~26.10.5",
30
- "@inweb/eventemitter2": "~26.10.5"
29
+ "@inweb/client": "~26.11.0",
30
+ "@inweb/eventemitter2": "~26.11.0"
31
31
  }
32
32
  }
@@ -28,12 +28,13 @@ import { IViewer } from "../viewer/IViewer";
28
28
  */
29
29
  export interface ICommandService {
30
30
  /**
31
- * Executes the command denoted by the given command ID.
31
+ * Executes the command denoted by the given command ID. If the command is not found, tries to set
32
+ * active dragger with the specified name.
32
33
  *
33
- * @param id - ID of the command to execute.
34
+ * @param id - Command ID or dragger name.
34
35
  * @param args - Parameters passed to the command handler function.
35
- * @returns Returns the result of the command handler function. Returns `undefined` when the command
36
- * doesn't exists.
36
+ * @returns Returns the result of the command handler function or new active dragger instance. Returns
37
+ * `undefined` if neither the command nor the dragger exists.
37
38
  */
38
39
  executeCommand(id: string, ...args: any[]): any;
39
40
  }
package/src/index.ts CHANGED
@@ -32,6 +32,7 @@ export * from "./components/IComponents";
32
32
  export * from "./loaders/ILoader";
33
33
  export * from "./loaders/Loader";
34
34
  export * from "./loaders/Loaders";
35
+ export * from "./models/IModel";
35
36
  export * from "./options/IOptions";
36
37
  export * from "./options/Options";
37
38
  export * from "./options/OptionsEvents";
@@ -28,7 +28,7 @@ import type { IViewer } from "../viewer/IViewer";
28
28
  * Defines the file source to load into the viewer:
29
29
  *
30
30
  * - `File`, `Assembly` or `Model` instance from the Open Cloud Server
31
- * - File `URL` string
31
+ * - `URL` string
32
32
  * - {@link https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs | Data URL} string
33
33
  * - {@link https://developer.mozilla.org/docs/Web/API/File | Web API File} object
34
34
  * - {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer | ArrayBuffer}
@@ -43,4 +43,13 @@ export class Loader implements ILoader {
43
43
  cancel(): void {
44
44
  this.abortController.abort();
45
45
  }
46
+
47
+ extractFileName(file: FileSource): string {
48
+ const regex = /[^/\\?#:]+(?=\?|#|$)/;
49
+
50
+ if (typeof file === "string") return (file.match(regex) || [])[0];
51
+ else if (file instanceof globalThis.File) return (file.name.match(regex) || [])[0];
52
+
53
+ return undefined;
54
+ }
46
55
  }
@@ -0,0 +1,44 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance").
3
+ // All rights reserved.
4
+ //
5
+ // This software and its documentation and related materials are owned by
6
+ // the Alliance. The software may only be incorporated into application
7
+ // programs owned by members of the Alliance, subject to a signed
8
+ // Membership Agreement and Supplemental Software License Agreement with the
9
+ // Alliance. The structure and organization of this software are the valuable
10
+ // trade secrets of the Alliance and its suppliers. The software is also
11
+ // protected by copyright law and international treaty provisions. Application
12
+ // programs incorporating this software must include the following statement
13
+ // with their copyright notices:
14
+ //
15
+ // This application incorporates Open Design Alliance software pursuant to a
16
+ // license agreement with Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance.
18
+ // All rights reserved.
19
+ //
20
+ // By use of this software, its documentation or related materials, you
21
+ // acknowledge and accept the above terms.
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+
24
+ /**
25
+ * Model interface.
26
+ */
27
+ export interface IModel {
28
+ /**
29
+ * Unique model ID, used as a model prefix when selecting objects in assemblies (multi-model scenes).
30
+ * Can be:
31
+ *
32
+ * - `file ID` - when loading a file from Open Cloud Server.
33
+ * - `assembly ID` - when loading an assembly from Open Cloud Server.
34
+ * - `model ID` - when loading a model of the file/assembly from Open Cloud Server.
35
+ * - `file name` - when loading from local File or URL.
36
+ * - `user defined` - when loading from ArrayBuffer or Data URL.
37
+ */
38
+ id: string;
39
+
40
+ /**
41
+ * Disposes the model and releases allocated resources.
42
+ */
43
+ dispose(): void;
44
+ }
@@ -212,14 +212,45 @@ export interface IOptions {
212
212
  geometryType?: string;
213
213
 
214
214
  /**
215
- * Ruler unit.
215
+ * Unit of measurement for the ruler tool (distance measurements).
216
216
  *
217
- * Available values: Default, Millimeters, Centimeters, Meters, Feet, Inches, Yards, Kilometers, Miles,
218
- * Micrometers, MicroInches
217
+ * When set to `Default`, the ruler uses the file's native units. Otherwise, distances are
218
+ * automatically converted to the specified unit.
219
+ *
220
+ * Available values:
221
+ *
222
+ * - `Default` - Use file's native units (recommended)
223
+ * - `Millimeters` - Metric: 0.001 m
224
+ * - `Centimeters` - Metric: 0.01 m
225
+ * - `Meters` - Metric: 1 m (base unit)
226
+ * - `Kilometers` - Metric: 1000 m
227
+ * - `Micrometers` - Metric: 0.000001 m
228
+ * - `Inches` - Imperial: 0.0254 m
229
+ * - `Feet` - Imperial: 0.3048 m
230
+ * - `Yards` - Imperial: 0.9144 m
231
+ * - `Miles` - Imperial: 1609.344 m
232
+ * - `Mils` - Imperial: 0.0000254 m
233
+ * - `MicroInches` - Imperial: 0.0000000254 m
219
234
  *
220
235
  * @defaultValue "Default"
221
236
  */
222
- rulerUnit: string;
237
+ rulerUnit?: string;
238
+
239
+ /**
240
+ * Number of decimal places to display in ruler measurements.
241
+ *
242
+ * Controls the precision of distance values shown by the ruler tool. Higher values provide more
243
+ * precision but may clutter the display with unnecessary digits.
244
+ *
245
+ * Available values:
246
+ *
247
+ * - `Default` - Use file's native units precision, if supported, otherwise use 2 digits.
248
+ * - `Auto` - Automatically choose precision based on distance value.
249
+ * - `0`...`10` - Use specified number of decimal places (range 0-10, inclusive).
250
+ *
251
+ * @defaultValue 2
252
+ */
253
+ rulerPrecision?: any;
223
254
 
224
255
  /**
225
256
  * Camera projection mode:
@@ -267,6 +298,7 @@ export function defaultOptions(): IOptions {
267
298
  enableGestures: true,
268
299
  geometryType: "vsfx",
269
300
  rulerUnit: "Default",
301
+ rulerPrecision: 2,
270
302
  cameraMode: "perspective",
271
303
  };
272
304
  }
@@ -343,6 +343,15 @@ export class Options implements IOptions {
343
343
  this.change();
344
344
  }
345
345
 
346
+ get rulerPrecision(): any {
347
+ return this._data.rulerPrecision;
348
+ }
349
+
350
+ set rulerPrecision(value: any) {
351
+ this._data.rulerPrecision = value;
352
+ this.change();
353
+ }
354
+
346
355
  get cameraMode(): CameraMode {
347
356
  return this._data.cameraMode || "perspective";
348
357
  }
@@ -27,7 +27,8 @@ import { ICommandService } from "../commands/ICommands";
27
27
  import { IOptions } from "../options/IOptions";
28
28
  import { IDragger } from "../draggers/IDraggers";
29
29
  import { IComponent } from "../components/IComponents";
30
- import { FileSource } from "../loaders/ILoader";
30
+ import { FileSource, ILoader } from "../loaders/ILoader";
31
+ import { IModel } from "../models/IModel";
31
32
  import { IViewpoint } from "./IViewpoint";
32
33
 
33
34
  /**
@@ -78,6 +79,16 @@ export interface IViewer extends IEventEmitter, ICommandService {
78
79
  */
79
80
  canvasEvents: string[];
80
81
 
82
+ /**
83
+ * List of active loaders used to load models into the viewer.
84
+ */
85
+ loaders: ILoader[];
86
+
87
+ /**
88
+ * List of models loaded into the viewer.
89
+ */
90
+ models: IModel[];
91
+
81
92
  /**
82
93
  * List of names of available draggers.
83
94
  *
@@ -169,14 +180,16 @@ export interface IViewer extends IEventEmitter, ICommandService {
169
180
  * thrown.
170
181
  *
171
182
  * For URLs, the file extension is used to determine the file format. For a `ArrayBuffer` and `Data
172
- * URL`, a file format must be specified using `params.format` parameter (see below). If no appropriate
173
- * loader is found for the specified format, an exception will be thrown.
183
+ * URL`, a file format must be specified using `params.format` parameter. If no appropriate loader is
184
+ * found for the specified format, an exception will be thrown.
174
185
  *
175
186
  * If there was an active dragger before opening the file, it will be deactivated. After opening the
176
187
  * file, you must manually activate the required dragger.
177
188
  *
178
189
  * Fires:
179
190
  *
191
+ * - {@link CancelEvent | cancel}
192
+ * - {@link ClearEvent | clear}
180
193
  * - {@link OpenEvent | open}
181
194
  * - {@link GeometryStartEvent | geometrystart}
182
195
  * - {@link GeometryProgressEvent | geometryprogress}
@@ -185,23 +198,26 @@ export interface IViewer extends IEventEmitter, ICommandService {
185
198
  * - {@link GeometryEndEvent | geometryend}
186
199
  * - {@link GeometryErrorEvent | geometryerror}
187
200
  *
188
- * @param file - File to load. Can be one of:
201
+ * @param file - File to load. Can be:
189
202
  *
190
203
  * - `File`, `Assembly` or `Model` instance from the Open Cloud Server
191
- * - File `URL` string
204
+ * - `URL` string
192
205
  * - {@link https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs | Data URL} string
193
206
  * - {@link https://developer.mozilla.org/docs/Web/API/File | Web API File} object
194
207
  * - {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer | ArrayBuffer}
195
208
  * object
196
209
  *
197
210
  * @param params - Loading parameters.
198
- * @param params.format - File format string. Required when loading a file as `ArrayBuffer` or `Data *
199
- * URL`.
200
- * @param params.mode - File opening mode. Viewer specific. Can be one of:
211
+ * @param params.format - File format. Required when loading a file as `ArrayBuffer` or `Data URL`.
212
+ * @param params.mode - File opening mode. Can be one of:
201
213
  *
202
- * - `open` - Unloads an open file and opens a new one. This is default mode.
203
- * - `append` - Appends a file to an already open file. This mode is not supported for all formats.
214
+ * - `file` - Single file mode. Unloads an open file and opens a new one. This is default mode.
215
+ * - `assembly` - Assembly mode. Appends a file to an already open file (). This mode is not supported
216
+ * for all viewers.
204
217
  *
218
+ * @param params.modelId - Unique model ID in the assembly (multi-model scene). Used as a model prefix
219
+ * when selecting objects (see {@link getSelected2}). Must not contain the ":" (colon). Required when
220
+ * loading a file as `ArrayBuffer` or `Data URL`.
205
221
  * @param params.requestHeader - The
206
222
  * {@link https://developer.mozilla.org/docs/Glossary/Request_header | request header} used in HTTP
207
223
  * request.
@@ -215,6 +231,7 @@ export interface IViewer extends IEventEmitter, ICommandService {
215
231
  params: {
216
232
  format?: string;
217
233
  mode?: string;
234
+ modelId?: string;
218
235
  requestHeader?: HeadersInit;
219
236
  withCredentials?: boolean;
220
237
  }
@@ -259,21 +276,45 @@ export interface IViewer extends IEventEmitter, ICommandService {
259
276
  clearSlices(): void;
260
277
 
261
278
  /**
262
- * Returns a list of original handles for the selected objects.
279
+ * Returns a list of original handles for the selected objects. To avoid handle collisions in
280
+ * assemblies (multi-model scenes), use {@link getSelected2} instead.
281
+ *
282
+ * @returns The list of original object handles.
263
283
  */
264
284
  getSelected(): string[];
265
285
 
266
286
  /**
267
- * Selects the objects by original handles.
287
+ * Returns a list of original handles for the selected objects in assemblies (multi-model scenes).
288
+ *
289
+ * @returns The list of original object handles with model prefix in format "model:handle".
290
+ */
291
+ getSelected2(): string[];
292
+
293
+ /**
294
+ * Selects the objects by original handles. To avoid handle collisions in assemblies (multi-model
295
+ * scenes), use {@link setSelected2} instead.
268
296
  *
269
297
  * Fires:
270
298
  *
271
299
  * - {@link SelectEvent | select}
300
+ * - {@link Select2Event | select2}
272
301
  *
273
302
  * @param handles - The list of original handles.
274
303
  */
275
304
  setSelected(handles?: string[]): void;
276
305
 
306
+ /**
307
+ * Selects the objects by original handles in assemblies (multi-model scenes).
308
+ *
309
+ * Fires:
310
+ *
311
+ * - {@link SelectEvent | select}
312
+ * - {@link Select2Event | select2}
313
+ *
314
+ * @param handles - The list of original handles with model prefix in format "model:handle".
315
+ */
316
+ setSelected2(handles?: string[]): void;
317
+
277
318
  /**
278
319
  * Unselects all objects.
279
320
  *
@@ -358,6 +399,8 @@ export interface IViewer extends IEventEmitter, ICommandService {
358
399
 
359
400
  /**
360
401
  * Returns the component reference, or `null` if there is no component with the specified name.
402
+ *
403
+ * @param name - Component name. Can be one of the {@link components} list.
361
404
  */
362
405
  getComponent(name: string): IComponent | null;
363
406
 
@@ -45,7 +45,7 @@ export interface AnimateEvent {
45
45
  }
46
46
 
47
47
  /**
48
- * Event that fires when model loading has been canceled.
48
+ * Event that fires when file loading has been canceled.
49
49
  *
50
50
  * @event
51
51
  */
@@ -254,7 +254,7 @@ export interface GeometryChunkEvent {
254
254
  }
255
255
 
256
256
  /**
257
- * Event that fires after model has been successfully loaded.
257
+ * Event that fires after file has been successfully loaded.
258
258
  *
259
259
  * @event
260
260
  */
@@ -317,7 +317,7 @@ export interface GeometryErrorEvent {
317
317
  }
318
318
 
319
319
  /**
320
- * Event that measures the progress of the model loading.
320
+ * Event that measures the progress of the file loading.
321
321
  *
322
322
  * @event
323
323
  */
@@ -351,7 +351,7 @@ export interface GeometryProgressEvent {
351
351
  }
352
352
 
353
353
  /**
354
- * Event that fires before the model loads.
354
+ * Event that fires before the file loads.
355
355
  *
356
356
  * @event
357
357
  */
@@ -445,7 +445,7 @@ export interface IsolateEvent {
445
445
  }
446
446
 
447
447
  /**
448
- * Event that fires before model open.
448
+ * Event that fires before file open.
449
449
  *
450
450
  * @event
451
451
  */
@@ -456,14 +456,14 @@ export interface OpenEvent {
456
456
  type: "open";
457
457
 
458
458
  /**
459
- * File to load.
459
+ * File opening mode.
460
460
  */
461
- file: File | Assembly | Model | string | globalThis.File | ArrayBuffer;
461
+ mode: string;
462
462
 
463
463
  /**
464
- * Model from file to load. Only defined when loading a file from the Open Cloud Server.
464
+ * File to load.
465
465
  */
466
- model?: Model;
466
+ file: File | Assembly | Model | string | globalThis.File | ArrayBuffer;
467
467
 
468
468
  /**
469
469
  * Deprecated since `26.4`. Use {@link file} instead.
@@ -576,10 +576,33 @@ export interface SelectEvent {
576
576
  /**
577
577
  * Selection set (viewer dependent).
578
578
  */
579
- data: any;
579
+ data?: any;
580
580
 
581
581
  /**
582
- * Handles of selected entities.
582
+ * Handles of selected objects.
583
+ */
584
+ handles: string[];
585
+ }
586
+
587
+ /**
588
+ * Event that fires after viewer selection changes. Uses model prefix to avoid handle collisions in
589
+ * assemblies (multi-model scenes).
590
+ *
591
+ * @event
592
+ */
593
+ export interface Select2Event {
594
+ /**
595
+ * Event type.
596
+ */
597
+ type: "select2";
598
+
599
+ /**
600
+ * Selection set (viewer dependent).
601
+ */
602
+ data?: any;
603
+
604
+ /**
605
+ * Handles of selected objects with model prefix in format "model:handle".
583
606
  */
584
607
  handles: string[];
585
608
  }
@@ -798,7 +821,7 @@ export interface ViewerEventMap {
798
821
  animate: AnimateEvent;
799
822
 
800
823
  /**
801
- * Event that fires when model loading has been canceled.
824
+ * Event that fires when file loading has been canceled.
802
825
  */
803
826
  cancel: CancelEvent;
804
827
 
@@ -863,7 +886,7 @@ export interface ViewerEventMap {
863
886
  geometrychunk: GeometryChunkEvent;
864
887
 
865
888
  /**
866
- * Event that fires after model has been successfully loaded.
889
+ * Event that fires after file has been successfully loaded.
867
890
  */
868
891
  geometryend: GeometryEndEvent;
869
892
 
@@ -873,12 +896,12 @@ export interface ViewerEventMap {
873
896
  geometryerror: GeometryErrorEvent;
874
897
 
875
898
  /**
876
- * Event that measures the progress of the model loading.
899
+ * Event that measures the progress of the file loading.
877
900
  */
878
901
  geometryprogress: GeometryProgressEvent;
879
902
 
880
903
  /**
881
- * Event that fires before the model opens.
904
+ * Event that fires before the file opens.
882
905
  */
883
906
  geometrystart: GeometryStartEvent;
884
907
 
@@ -903,7 +926,7 @@ export interface ViewerEventMap {
903
926
  isolate: IsolateEvent;
904
927
 
905
928
  /**
906
- * Event that fires before model opens.
929
+ * Event that fires before file opens.
907
930
  */
908
931
  open: OpenEvent;
909
932
 
@@ -932,6 +955,11 @@ export interface ViewerEventMap {
932
955
  */
933
956
  select: SelectEvent;
934
957
 
958
+ /**
959
+ * Event that fires when the selection changes.
960
+ */
961
+ select2: Select2Event;
962
+
935
963
  /**
936
964
  * Event that fires after selected objects becomes visible.
937
965
  */