@inweb/viewer-core 25.3.13

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.
@@ -0,0 +1,599 @@
1
+ import { Assembly, File, Model } from "@inweb/client";
2
+ /**
3
+ * A {@link Viewer} event that fires when model loading has been canceled.
4
+ *
5
+ * @event
6
+ */
7
+ export interface CancelEvent {
8
+ /**
9
+ * Event type.
10
+ */
11
+ type: "cancel";
12
+ }
13
+ /**
14
+ * A {@link Viewer} event that fires when the active dragger has been changed.
15
+ *
16
+ * @event
17
+ */
18
+ export interface ChangeActiveDraggerEvent {
19
+ /**
20
+ * Event type.
21
+ */
22
+ type: "changeactivedragger";
23
+ /**
24
+ * Dragger name.
25
+ */
26
+ data: string;
27
+ }
28
+ /**
29
+ * A {@link Viewer} event that fires when the markup color has been changed.
30
+ *
31
+ * @event
32
+ */
33
+ export interface ChangeMarkupColorEvent {
34
+ /**
35
+ * Event type.
36
+ */
37
+ type: "changemarkupcolor";
38
+ /**
39
+ * New color.
40
+ */
41
+ data: {
42
+ r: number;
43
+ g: number;
44
+ b: number;
45
+ };
46
+ }
47
+ /**
48
+ * A {@link Viewer} event that fires when the viewer has been cleared.
49
+ *
50
+ * @event
51
+ */
52
+ export interface ClearEvent {
53
+ /**
54
+ * Event type.
55
+ */
56
+ type: "clear";
57
+ }
58
+ /**
59
+ * A {@link Viewer} event that fires after viewer executes the command.
60
+ *
61
+ * @event
62
+ */
63
+ export interface CommandEvent {
64
+ /**
65
+ * Event type.
66
+ */
67
+ type: "command";
68
+ /**
69
+ * Command name.
70
+ */
71
+ data: string;
72
+ /**
73
+ * Command arguments.
74
+ */
75
+ args: any[];
76
+ }
77
+ /**
78
+ * A {@link Viewer} event that fires when the model scene description file has been loaded.
79
+ *
80
+ * @event
81
+ */
82
+ export interface DatabaseChunkEvent {
83
+ /**
84
+ * Event type.
85
+ */
86
+ type: "databasechunk";
87
+ /**
88
+ * Scene description file.
89
+ */
90
+ data?: Uint8Array;
91
+ /**
92
+ * Model instance to open.
93
+ */
94
+ model?: Model;
95
+ /**
96
+ * Buffer to open.
97
+ */
98
+ buffer?: Uint8Array | ArrayBuffer;
99
+ }
100
+ /**
101
+ * A {@link Viewer} event that fires before viewer resources has been released.
102
+ *
103
+ * @event
104
+ */
105
+ export interface DisposeEvent {
106
+ /**
107
+ * Event type.
108
+ */
109
+ type: "dispose";
110
+ }
111
+ /**
112
+ * A {@link Viewer} event that fires when the model geometry data chunk has been loaded. Note
113
+ * that small files are loaded in one chunk, and `geometrychunk` event does not fire, only the
114
+ * `databasechink` event fires.
115
+ *
116
+ * @event
117
+ */
118
+ export interface GeometryChunkEvent {
119
+ /**
120
+ * Event type.
121
+ */
122
+ type: "geometrychunk";
123
+ /**
124
+ * Geometry data chunk.
125
+ */
126
+ data: Uint8Array;
127
+ /**
128
+ * Model instance to open.
129
+ */
130
+ model?: Model;
131
+ /**
132
+ * Buffer to open.
133
+ */
134
+ buffer?: Uint8Array | ArrayBuffer;
135
+ }
136
+ /**
137
+ * A {@link Viewer} event that fires after model has been successfully loaded.
138
+ *
139
+ * @event
140
+ */
141
+ export interface GeometryEndEvent {
142
+ /**
143
+ * Event type.
144
+ */
145
+ type: "geometryend";
146
+ /**
147
+ * Model instance to open.
148
+ */
149
+ model?: Model;
150
+ /**
151
+ * Buffer to open.
152
+ */
153
+ buffer?: Uint8Array | ArrayBuffer;
154
+ /**
155
+ * Loaded data (viewer depended).
156
+ */
157
+ data?: any;
158
+ }
159
+ /**
160
+ * A {@link Viewer} event that fires when the model fails to load.
161
+ *
162
+ * @event
163
+ */
164
+ export interface GeometryErrorEvent {
165
+ /**
166
+ * Event type.
167
+ */
168
+ type: "geometryerror";
169
+ /**
170
+ * Thrown exception.
171
+ */
172
+ data: Error;
173
+ /**
174
+ * Model instance to open.
175
+ */
176
+ model?: Model;
177
+ /**
178
+ * Buffer to open.
179
+ */
180
+ buffer?: Uint8Array | ArrayBuffer;
181
+ }
182
+ /**
183
+ * A {@link Viewer} event measuring progress of the model loading process.
184
+ *
185
+ * @event
186
+ */
187
+ export interface GeometryProgressEvent {
188
+ /**
189
+ * Event type.
190
+ */
191
+ type: "geometryprogress";
192
+ /**
193
+ * The non-rounded progress value from 0 to 1. To get a percentage (%), multiply the `data` by 100.
194
+ */
195
+ data: number;
196
+ /**
197
+ * Model instance to open.
198
+ */
199
+ model?: Model;
200
+ /**
201
+ * Buffer to open.
202
+ */
203
+ buffer?: Uint8Array | ArrayBuffer;
204
+ }
205
+ /**
206
+ * A {@link Viewer} event that fires before the model loads.
207
+ *
208
+ * @event
209
+ */
210
+ export interface GeometryStartEvent {
211
+ /**
212
+ * Event type.
213
+ */
214
+ type: "geometrystart";
215
+ /**
216
+ * Model instance to open.
217
+ */
218
+ model?: Model;
219
+ /**
220
+ * Buffer to open.
221
+ */
222
+ buffer?: Uint8Array | ArrayBuffer;
223
+ }
224
+ /**
225
+ * A {@link Viewer} event that fires before model opens.
226
+ *
227
+ * @event
228
+ */
229
+ export interface OpenEvent {
230
+ /**
231
+ * Event type.
232
+ */
233
+ type: "open";
234
+ /**
235
+ * File instance to open.
236
+ */
237
+ file?: File | Assembly | Model;
238
+ model?: File | Assembly | Model;
239
+ /**
240
+ * Buffer to open.
241
+ */
242
+ buffer?: Uint8Array | ArrayBuffer;
243
+ }
244
+ /**
245
+ * A {@link Viewer} event that fires when rendering occurs.
246
+ *
247
+ * @event
248
+ */
249
+ export interface RenderEvent {
250
+ /**
251
+ * Event type.
252
+ */
253
+ type: "render";
254
+ time: DOMHighResTimeStamp;
255
+ deltaTime: DOMHighResTimeStamp;
256
+ }
257
+ /**
258
+ * A {@link Viewer} event that fires when resize occurs.
259
+ *
260
+ * @event
261
+ */
262
+ export interface ResizeEvent {
263
+ /**
264
+ * Event type.
265
+ */
266
+ type: "resize";
267
+ /**
268
+ * New width.
269
+ */
270
+ width: number;
271
+ /**
272
+ * New height.
273
+ */
274
+ height: number;
275
+ }
276
+ /**
277
+ * A {@link Viewer} event that fires when the selection changes.
278
+ *
279
+ * @event
280
+ */
281
+ export interface SelectEvent {
282
+ /**
283
+ * Event type.
284
+ */
285
+ type: "select";
286
+ /**
287
+ * Selection set.
288
+ */
289
+ data: any;
290
+ /**
291
+ * Handles of selected entities.
292
+ */
293
+ handles: string[];
294
+ }
295
+ /**
296
+ * A {@link Viewer} event that fires when an update occurs.
297
+ *
298
+ * @event
299
+ */
300
+ export interface UpdateEvent {
301
+ /**
302
+ * Event type.
303
+ */
304
+ type: "update";
305
+ /**
306
+ * `true` to force the update, otherwise the update is delayed until the next animation frame.
307
+ */
308
+ data: boolean;
309
+ }
310
+ /**
311
+ * A {@link Viewer} event measuring progress of loading a `VisualizeJS` library.
312
+ *
313
+ * @event
314
+ */
315
+ export interface VisualizeProgressEvent {
316
+ /**
317
+ * Event type.
318
+ */
319
+ type: "visualizeprogress";
320
+ /**
321
+ * A 64-bit unsigned integer value indicating the amount of work already performed by the
322
+ * underlying process. The ratio of work done can be calculated by dividing total by the
323
+ * value of this property.
324
+ */
325
+ loaded: number;
326
+ /**
327
+ * A 64-bit unsigned integer representing the total amount of work that the underlying
328
+ * process is in the progress of performing.
329
+ */
330
+ total: number;
331
+ }
332
+ /**
333
+ * A {@link Viewer} event that fires when walk speed changing.
334
+ *
335
+ * @event
336
+ */
337
+ export interface WalkSpeedChangeEvent {
338
+ /**
339
+ * Event type.
340
+ */
341
+ type: "walkspeedchange";
342
+ /**
343
+ * Multiplier
344
+ */
345
+ data: number;
346
+ }
347
+ /**
348
+ * A {@link Viewer} event that fires when walk started.
349
+ *
350
+ * @event
351
+ */
352
+ export interface WalkStartEvent {
353
+ /**
354
+ * Event type.
355
+ */
356
+ type: "walkstart";
357
+ }
358
+ /**
359
+ * A {@link Viewer} pan to event.
360
+ *
361
+ * @event
362
+ */
363
+ export interface PanEvent {
364
+ /**
365
+ * Event type.
366
+ */
367
+ type: "pan";
368
+ /**
369
+ * X coordinate.
370
+ */
371
+ x: number;
372
+ /**
373
+ * Y coordinate.
374
+ */
375
+ y: number;
376
+ /**
377
+ * delta X coordinate.
378
+ */
379
+ dX: number;
380
+ /**
381
+ * delta Y coordinate.
382
+ */
383
+ dY: number;
384
+ }
385
+ /**
386
+ * A {@link Viewer} zoom event.
387
+ *
388
+ * @event
389
+ */
390
+ export interface ZoomEvent {
391
+ /**
392
+ * Event type.
393
+ */
394
+ type: "zoom";
395
+ /**
396
+ * New view parameters.
397
+ */
398
+ data?: any;
399
+ }
400
+ /**
401
+ * A {@link Viewer} zoom at event.
402
+ *
403
+ * @event
404
+ */
405
+ export interface ZoomAtEvent {
406
+ /**
407
+ * Event type.
408
+ */
409
+ type: "zoomat";
410
+ /**
411
+ * Zoom factor
412
+ */
413
+ data: number;
414
+ }
415
+ /**
416
+ * A {@link Viewer} zoom to entity event.
417
+ *
418
+ * @event
419
+ */
420
+ export interface ZoomToEntityEvent {
421
+ /**
422
+ * Event type.
423
+ */
424
+ type: "zoomtoentity";
425
+ /**
426
+ * Entity
427
+ */
428
+ data: any;
429
+ }
430
+ /**
431
+ * Viewer Events
432
+ */
433
+ export interface ViewerEventMap {
434
+ /**
435
+ * A {@link Viewer} event that fires when model loading has been canceled.
436
+ */
437
+ cancel: CancelEvent;
438
+ /**
439
+ * A {@link Viewer} event that fires when the active dragger has been changed.
440
+ */
441
+ changeactivedragger: ChangeActiveDraggerEvent;
442
+ /**
443
+ * A {@link Viewer} event that fires when the markup color has been changed.
444
+ */
445
+ changemarkupcolor: ChangeMarkupColorEvent;
446
+ /**
447
+ * A {@link Viewer} event that fires when the viewer has been cleared.
448
+ */
449
+ clear: ClearEvent;
450
+ /**
451
+ * A {@link Viewer} event that fires after viewer executes the command.
452
+ */
453
+ command: CommandEvent;
454
+ /**
455
+ * A {@link Viewer} event that fires when the model scene description file has been loaded.
456
+ */
457
+ databasechunk: DatabaseChunkEvent;
458
+ /**
459
+ * A {@link Viewer} event that fires before viewer resources has been released.
460
+ */
461
+ dispose: DisposeEvent;
462
+ /**
463
+ * A {@link Viewer} event that fires when the model geometry data chunk has been loaded.
464
+ */
465
+ geometrychunk: GeometryChunkEvent;
466
+ /**
467
+ * A {@link Viewer} event that fires after model has been successfully loaded.
468
+ */
469
+ geometryend: GeometryEndEvent;
470
+ /**
471
+ * A {@link Viewer} event that fires when the model fails to open.
472
+ */
473
+ geometryerror: GeometryErrorEvent;
474
+ /**
475
+ * A {@link Viewer} event measuring progress of the model loading process.
476
+ */
477
+ geometryprogress: GeometryProgressEvent;
478
+ /**
479
+ * A {@link Viewer} event that fires before the model opens.
480
+ */
481
+ geometrystart: GeometryStartEvent;
482
+ /**
483
+ * A {@link Viewer} event that fires before model opens.
484
+ */
485
+ open: OpenEvent;
486
+ /**
487
+ * A {@link Viewer} event that fires when an rendering occurs.
488
+ */
489
+ render: RenderEvent;
490
+ /**
491
+ * A {@link Viewer} event that fires when resize occurs.
492
+ */
493
+ resize: ResizeEvent;
494
+ /**
495
+ * A {@link Viewer} event that fires when the selection changes.
496
+ */
497
+ select: SelectEvent;
498
+ /**
499
+ * A {@link Viewer} event that fires when an update occurs.
500
+ */
501
+ update: UpdateEvent;
502
+ /**
503
+ * A {@link Viewer} event measuring progress of loading a `VisualizeJS` library.
504
+ */
505
+ visualizeprogress: VisualizeProgressEvent;
506
+ /**
507
+ * A {@link Viewer} event that fires when walk speed changing.
508
+ */
509
+ walkspeedchange: WalkSpeedChangeEvent;
510
+ /**
511
+ * A {@link Viewer} event that fires when walk started.
512
+ */
513
+ walkstart: WalkStartEvent;
514
+ /**
515
+ * A {@link Viewer} pan event.
516
+ */
517
+ pan: PanEvent;
518
+ /**
519
+ * A {@link Viewer} zoom event.
520
+ */
521
+ zoom: ZoomEvent;
522
+ /**
523
+ * A {@link Viewer} zoom at event.
524
+ */
525
+ zoomat: ZoomAtEvent;
526
+ /**
527
+ * A {@link Viewer} zoom to entity event.
528
+ */
529
+ zoomtoentity: ZoomToEntityEvent;
530
+ /**
531
+ * {@link Viewer} event that fires when the user attempts to open a context menu.
532
+ */
533
+ contextmenu: PointerEvent;
534
+ /**
535
+ * {@link Viewer} event that fires on mouse click.
536
+ */
537
+ click: MouseEvent;
538
+ /**
539
+ * A {@link Viewer} event that fires on mouse double click.
540
+ */
541
+ dblclick: MouseEvent;
542
+ /**
543
+ * A {@link Viewer} event that fires on mouse button is down.
544
+ */
545
+ mousedown: MouseEvent;
546
+ /**
547
+ * A {@link Viewer} event that fires on mouse leave.
548
+ */
549
+ mouseleave: MouseEvent;
550
+ /**
551
+ * A {@link Viewer} event that fires on mouse move.
552
+ */
553
+ mousemove: MouseEvent;
554
+ /**
555
+ * A {@link Viewer} event that fires on mouse button is up.
556
+ */
557
+ mouseup: MouseEvent;
558
+ /**
559
+ * A {@link Viewer} event is fired when the browser determines that there are unlikely to be
560
+ * any more pointer events.
561
+ */
562
+ pointercancel: PointerEvent;
563
+ /**
564
+ * A {@link Viewer} event that fires on mouse button is down.
565
+ */
566
+ pointerdown: PointerEvent;
567
+ /**
568
+ * A {@link Viewer} event that fires on mouse leave.
569
+ */
570
+ pointerleave: PointerEvent;
571
+ /**
572
+ * A {@link Viewer} event that fires on mouse move.
573
+ */
574
+ pointermove: PointerEvent;
575
+ /**
576
+ * A {@link Viewer} event that fires on mouse button is up.
577
+ */
578
+ pointerup: PointerEvent;
579
+ /**
580
+ * A {@link Viewer} event that fires touch is canceled.
581
+ */
582
+ touchcancel: TouchEvent;
583
+ /**
584
+ * A {@link Viewer} event that fires touch is ended.
585
+ */
586
+ touchend: TouchEvent;
587
+ /**
588
+ * A {@link Viewer} event that fires touch is moving.
589
+ */
590
+ touchmove: TouchEvent;
591
+ /**
592
+ * A {@link Viewer} event that fires when touch is started.
593
+ */
594
+ touchstart: TouchEvent;
595
+ /**
596
+ * A {@link Viewer} event that fires when mouse wheel is moving.
597
+ */
598
+ wheel: MouseEvent;
599
+ }
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@inweb/viewer-core",
3
+ "version": "25.3.13",
4
+ "description": "3D CAD and BIM data Viewer core for the inWEB Open Cloud platform.",
5
+ "homepage": "https://cloud.opendesign.com/docs/index.html",
6
+ "license": "SEE LICENSE IN LICENSE",
7
+ "author": "Open Design Alliance",
8
+ "keywords": [
9
+ "opendesign",
10
+ "opencloud",
11
+ "inweb",
12
+ "viewer",
13
+ "core"
14
+ ],
15
+ "sideEffects": false,
16
+ "main": "dist/viewer-core.js",
17
+ "module": "dist/viewer-core.module.js",
18
+ "types": "lib/index.d.ts",
19
+ "files": [
20
+ "dist",
21
+ "lib/**/*.d.ts",
22
+ "src"
23
+ ],
24
+ "scripts": {
25
+ "build": "rollup -c rollup.config.js",
26
+ "test": "karma start karma.conf.js"
27
+ },
28
+ "devDependencies": {
29
+ "@inweb/eventemitter2": "^25.3.12"
30
+ },
31
+ "peerDependencies": {
32
+ "@inweb/eventemitter2": "^25.3.12"
33
+ }
34
+ }
@@ -0,0 +1,84 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2023, 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-2021 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
+ import { IViewer } from "../viewer/IViewer";
25
+ import { ICommand, ICommandHandler, ICommandDescription, ICommandsMap, ICommands } from "./ICommands";
26
+
27
+ class Commands implements ICommands {
28
+ private readonly _commands = new Map<string, ICommand>();
29
+
30
+ registerCommand(id: string, handler: ICommandHandler, description?: ICommandDescription, thisArg?: any): void {
31
+ this._commands.set(id, { id, handler, thisArg, description });
32
+ }
33
+
34
+ registerCommandAlias(id: string, alias: string): void {
35
+ this.registerCommand(alias, (viewer: IViewer, ...args) => this.executeCommand(id, viewer, ...args));
36
+ }
37
+
38
+ getCommand(id: string): ICommand | undefined {
39
+ return this._commands.get(id);
40
+ }
41
+
42
+ getCommands(): ICommandsMap {
43
+ const map = new Map<string, ICommand>();
44
+ this._commands.forEach((value, key) => map.set(key, value));
45
+ return map;
46
+ }
47
+
48
+ executeCommand(id: string, viewer: IViewer, ...args: any[]): any {
49
+ const command = this._commands.get(id);
50
+ if (!command) {
51
+ if (viewer) {
52
+ const isDraggerCommand = viewer.draggers.includes(id);
53
+ if (isDraggerCommand) return viewer.setActiveDragger(id);
54
+ }
55
+
56
+ console.warn(`Command '${id}' not found`);
57
+ return undefined;
58
+ }
59
+
60
+ const { handler, thisArg } = command;
61
+ const result = handler.apply(thisArg, [viewer, ...args]);
62
+
63
+ viewer?.emit({ type: "command", data: id, args });
64
+
65
+ return result;
66
+ }
67
+ }
68
+
69
+ const _commands = new Map<string, Commands>();
70
+
71
+ function commands(viewerType = ""): ICommands {
72
+ let result = _commands.get(viewerType);
73
+ if (!result) {
74
+ result = new Commands();
75
+ _commands.set(viewerType, result);
76
+ }
77
+ return result;
78
+ }
79
+
80
+ commands("").registerCommand("noop", () => {});
81
+ commands("VisualizeJS").registerCommand("noop", () => {});
82
+ commands("ThreeJS").registerCommand("noop", () => {});
83
+
84
+ export { commands };