@inweb/viewer-core 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.
@@ -21,14 +21,14 @@
21
21
  // acknowledge and accept the above terms.
22
22
  ///////////////////////////////////////////////////////////////////////////////
23
23
 
24
- import { EventEmitter2 } from "@inweb/eventemitter2";
24
+ import { IEventEmitter } from "@inweb/eventemitter2";
25
25
  import { CameraMode, defaultOptions, IOptions, RGB } from "./IOptions";
26
26
 
27
27
  export class Options implements IOptions {
28
- protected _emitter?: EventEmitter2;
28
+ protected _emitter?: IEventEmitter;
29
29
  protected _data: IOptions;
30
30
 
31
- constructor(emitter?: EventEmitter2) {
31
+ constructor(emitter?: IEventEmitter) {
32
32
  this._emitter = emitter;
33
33
  this._data = defaultOptions();
34
34
  this.loadFromStorage();
@@ -73,15 +73,23 @@ export class Options implements IOptions {
73
73
  * @param fields - Name of fields to be reset. Specify `undefined` to reset all.
74
74
  */
75
75
  resetToDefaults(fields?: string[]): void {
76
+ const defaults = Options.defaults();
76
77
  if (fields !== undefined) {
77
- const defaults = Options.defaults();
78
- const resetData = fields.reduce((acc, field) => {
79
- acc[field] = defaults[field];
80
- return acc;
81
- }, {});
82
- this.data = { ...this.data, ...resetData };
78
+ const resetData: Partial<IOptions> = {};
79
+ for (const field of fields) {
80
+ if (field in defaults) resetData[field] = defaults[field];
81
+ }
82
+ this.data = resetData;
83
83
  } else {
84
- this.data = { ...this.data, ...Options.defaults() };
84
+ this.data = defaults;
85
+ }
86
+ }
87
+
88
+ setProperty<K extends keyof IOptions>(key: K, value = Options.defaults()[key]): void {
89
+ // for object-valued fields any new literal counts as a change
90
+ if (this._data[key] !== value) {
91
+ this._data[key] = value;
92
+ this.change();
85
93
  }
86
94
  }
87
95
 
@@ -89,8 +97,14 @@ export class Options implements IOptions {
89
97
  return this._data;
90
98
  }
91
99
 
92
- set data(value: IOptions) {
93
- this._data = { ...Options.defaults(), ...this._data, ...value };
100
+ set data(value: Partial<IOptions>) {
101
+ const defaults = Options.defaults();
102
+ const merged: IOptions = { ...defaults, ...this._data, ...value };
103
+ // replace undefined to default value for known properties
104
+ for (const key of Object.keys(defaults)) {
105
+ if (merged[key] === undefined) merged[key] = defaults[key];
106
+ }
107
+ this._data = merged;
94
108
  // partial mode first
95
109
  if (this._data.enablePartialMode) {
96
110
  this._data.enableStreamingMode = true;
@@ -111,8 +125,7 @@ export class Options implements IOptions {
111
125
  }
112
126
 
113
127
  set showWCS(value: boolean) {
114
- this._data.showWCS = value;
115
- this.change();
128
+ this.setProperty("showWCS", value);
116
129
  }
117
130
 
118
131
  get cameraAnimation(): boolean {
@@ -120,8 +133,7 @@ export class Options implements IOptions {
120
133
  }
121
134
 
122
135
  set cameraAnimation(value: boolean) {
123
- this._data.cameraAnimation = value;
124
- this.change();
136
+ this.setProperty("cameraAnimation", value);
125
137
  }
126
138
 
127
139
  get antialiasing(): boolean | string {
@@ -129,8 +141,7 @@ export class Options implements IOptions {
129
141
  }
130
142
 
131
143
  set antialiasing(value: boolean | string) {
132
- this._data.antialiasing = value;
133
- this.change();
144
+ this.setProperty("antialiasing", value);
134
145
  }
135
146
 
136
147
  get groundShadow(): boolean {
@@ -138,8 +149,7 @@ export class Options implements IOptions {
138
149
  }
139
150
 
140
151
  set groundShadow(value: boolean) {
141
- this._data.groundShadow = value;
142
- this.change();
152
+ this.setProperty("groundShadow", value);
143
153
  }
144
154
 
145
155
  get shadows(): boolean {
@@ -147,8 +157,7 @@ export class Options implements IOptions {
147
157
  }
148
158
 
149
159
  set shadows(value: boolean) {
150
- this._data.shadows = value;
151
- this.change();
160
+ this.setProperty("shadows", value);
152
161
  }
153
162
 
154
163
  get cameraAxisXSpeed(): number {
@@ -156,8 +165,7 @@ export class Options implements IOptions {
156
165
  }
157
166
 
158
167
  set cameraAxisXSpeed(value: number) {
159
- this._data.cameraAxisXSpeed = value;
160
- this.change();
168
+ this.setProperty("cameraAxisXSpeed", value);
161
169
  }
162
170
 
163
171
  get cameraAxisYSpeed(): number {
@@ -165,8 +173,7 @@ export class Options implements IOptions {
165
173
  }
166
174
 
167
175
  set cameraAxisYSpeed(value: number) {
168
- this.cameraAxisYSpeed = value;
169
- this.change();
176
+ this.setProperty("cameraAxisYSpeed", value);
170
177
  }
171
178
 
172
179
  get ambientOcclusion(): boolean {
@@ -174,8 +181,7 @@ export class Options implements IOptions {
174
181
  }
175
182
 
176
183
  set ambientOcclusion(value: boolean) {
177
- this._data.ambientOcclusion = value;
178
- this.change();
184
+ this.setProperty("ambientOcclusion", value);
179
185
  }
180
186
 
181
187
  get enableStreamingMode(): boolean {
@@ -183,9 +189,10 @@ export class Options implements IOptions {
183
189
  }
184
190
 
185
191
  set enableStreamingMode(value: boolean) {
186
- this._data.enableStreamingMode = value;
187
- if (!value) this._data.enablePartialMode = false;
188
- this.change();
192
+ this.setProperty("enableStreamingMode", value);
193
+ if (!value) {
194
+ this.setProperty("enablePartialMode", false);
195
+ }
189
196
  }
190
197
 
191
198
  get enablePartialMode(): boolean {
@@ -193,12 +200,11 @@ export class Options implements IOptions {
193
200
  }
194
201
 
195
202
  set enablePartialMode(value: boolean) {
196
- this._data.enablePartialMode = value;
203
+ this.setProperty("enablePartialMode", value);
197
204
  if (value) {
198
- this._data.enableStreamingMode = true;
199
- this._data.sceneGraph = false;
205
+ this.setProperty("enableStreamingMode", true);
206
+ this.setProperty("sceneGraph", false);
200
207
  }
201
- this.change();
202
208
  }
203
209
 
204
210
  get memoryLimit(): number {
@@ -206,8 +212,7 @@ export class Options implements IOptions {
206
212
  }
207
213
 
208
214
  set memoryLimit(value: number) {
209
- this._data.memoryLimit = value;
210
- this.change();
215
+ this.setProperty("memoryLimit", value);
211
216
  }
212
217
 
213
218
  get cuttingPlaneFillColor(): RGB {
@@ -225,12 +230,11 @@ export class Options implements IOptions {
225
230
  console.warn(
226
231
  "Options.cuttingPlaneFillColor has been deprecated since 27.5 and will be removed in a future release, use sectionFillColor instead"
227
232
  );
228
- this._data.sectionFillColor = {
233
+ this.setProperty("sectionFillColor", {
229
234
  r: value.red,
230
235
  g: value.green,
231
236
  b: value.blue,
232
- };
233
- this.change();
237
+ });
234
238
  }
235
239
 
236
240
  get enableSectionFill(): boolean {
@@ -238,17 +242,15 @@ export class Options implements IOptions {
238
242
  }
239
243
 
240
244
  set enableSectionFill(value: boolean) {
241
- this._data.enableSectionFill = value;
242
- this.change();
245
+ this.setProperty("enableSectionFill", value);
243
246
  }
244
247
 
245
- get sectionFillColor() {
248
+ get sectionFillColor(): { r: number; g: number; b: number } {
246
249
  return this._data.sectionFillColor;
247
250
  }
248
251
 
249
- set sectionFillColor(value) {
250
- this._data.sectionFillColor = value;
251
- this.change();
252
+ set sectionFillColor(value: { r: number; g: number; b: number }) {
253
+ this.setProperty("sectionFillColor", value);
252
254
  }
253
255
 
254
256
  get sectionUseObjectColor(): boolean {
@@ -256,8 +258,7 @@ export class Options implements IOptions {
256
258
  }
257
259
 
258
260
  set sectionUseObjectColor(value: boolean) {
259
- this._data.sectionUseObjectColor = value;
260
- this.change();
261
+ this.setProperty("sectionUseObjectColor", value);
261
262
  }
262
263
 
263
264
  get enableSectionHatch(): boolean {
@@ -265,17 +266,15 @@ export class Options implements IOptions {
265
266
  }
266
267
 
267
268
  set enableSectionHatch(value: boolean) {
268
- this._data.enableSectionHatch = value;
269
- this.change();
269
+ this.setProperty("enableSectionHatch", value);
270
270
  }
271
271
 
272
- get sectionHatchColor() {
272
+ get sectionHatchColor(): { r: number; g: number; b: number } {
273
273
  return this._data.sectionHatchColor;
274
274
  }
275
275
 
276
- set sectionHatchColor(value) {
277
- this._data.sectionHatchColor = value;
278
- this.change();
276
+ set sectionHatchColor(value: { r: number; g: number; b: number }) {
277
+ this.setProperty("sectionHatchColor", value);
279
278
  }
280
279
 
281
280
  get sectionHatchScale(): number {
@@ -283,8 +282,7 @@ export class Options implements IOptions {
283
282
  }
284
283
 
285
284
  set sectionHatchScale(value: number) {
286
- this._data.sectionHatchScale = value;
287
- this.change();
285
+ this.setProperty("sectionHatchScale", value);
288
286
  }
289
287
 
290
288
  get enableSectionOutline(): boolean {
@@ -292,17 +290,15 @@ export class Options implements IOptions {
292
290
  }
293
291
 
294
292
  set enableSectionOutline(value: boolean) {
295
- this._data.enableSectionOutline = value;
296
- this.change();
293
+ this.setProperty("enableSectionOutline", value);
297
294
  }
298
295
 
299
- get sectionOutlineColor() {
296
+ get sectionOutlineColor(): { r: number; g: number; b: number } {
300
297
  return this._data.sectionOutlineColor;
301
298
  }
302
299
 
303
- set sectionOutlineColor(value) {
304
- this._data.sectionOutlineColor = value;
305
- this.change();
300
+ set sectionOutlineColor(value: { r: number; g: number; b: number }) {
301
+ this.setProperty("sectionOutlineColor", value);
306
302
  }
307
303
 
308
304
  get sectionOutlineWidth(): number {
@@ -310,126 +306,114 @@ export class Options implements IOptions {
310
306
  }
311
307
 
312
308
  set sectionOutlineWidth(value: number) {
313
- this._data.sectionOutlineWidth = value;
314
- this.change();
309
+ this.setProperty("sectionOutlineWidth", value);
315
310
  }
316
311
 
317
- get edgesColor() {
312
+ get edgesColor(): { r: number; g: number; b: number } {
318
313
  return this._data.edgesColor;
319
314
  }
320
315
 
321
- set edgesColor(value) {
322
- this._data.edgesColor = value;
323
- this.change();
316
+ set edgesColor(value: { r: number; g: number; b: number }) {
317
+ this.setProperty("edgesColor", value);
324
318
  }
325
319
 
326
- get facesColor() {
320
+ get facesColor(): { r: number; g: number; b: number } {
327
321
  return this._data.facesColor;
328
322
  }
329
323
 
330
- set facesColor(value) {
331
- this._data.facesColor = value;
332
- this.change();
324
+ set facesColor(value: { r: number; g: number; b: number }) {
325
+ this.setProperty("facesColor", value);
333
326
  }
334
327
 
335
- get edgesVisibility() {
328
+ get edgesVisibility(): boolean {
336
329
  return this._data.edgesVisibility;
337
330
  }
338
331
 
339
- set edgesVisibility(value) {
340
- this._data.edgesVisibility = value;
341
- this.change();
332
+ set edgesVisibility(value: boolean) {
333
+ this.setProperty("edgesVisibility", value);
342
334
  }
343
335
 
344
- get edgesOverlap() {
336
+ get edgesOverlap(): boolean {
345
337
  return this._data.edgesOverlap;
346
338
  }
347
339
 
348
- set edgesOverlap(value) {
349
- this._data.edgesOverlap = value;
350
- this.change();
340
+ set edgesOverlap(value: boolean) {
341
+ this.setProperty("edgesOverlap", value);
351
342
  }
352
343
 
353
- get facesOverlap() {
344
+ get facesOverlap(): boolean {
354
345
  return this._data.facesOverlap;
355
346
  }
356
347
 
357
- set facesOverlap(value) {
358
- this._data.facesOverlap = value;
359
- this.change();
348
+ set facesOverlap(value: boolean) {
349
+ this.setProperty("facesOverlap", value);
360
350
  }
361
351
 
362
- get facesTransparancy() {
352
+ get facesTransparancy(): number {
363
353
  return this._data.facesTransparancy;
364
354
  }
365
355
 
366
- set facesTransparancy(value) {
367
- this._data.facesTransparancy = value;
368
- this.change();
356
+ set facesTransparancy(value: number) {
357
+ this.setProperty("facesTransparancy", value);
369
358
  }
370
359
 
371
- get enableCustomHighlight() {
360
+ get enableCustomHighlight(): boolean {
372
361
  return this._data.enableCustomHighlight;
373
362
  }
374
363
 
375
- set enableCustomHighlight(value) {
376
- this._data.enableCustomHighlight = value;
377
- this.change();
364
+ set enableCustomHighlight(value: boolean) {
365
+ this.setProperty("enableCustomHighlight", value);
378
366
  }
379
367
 
380
- get sceneGraph() {
368
+ get sceneGraph(): boolean {
381
369
  return this._data.sceneGraph;
382
370
  }
383
371
 
384
- set sceneGraph(value) {
385
- this._data.sceneGraph = value;
386
- if (value) this._data.enablePartialMode = false;
387
- this.change();
372
+ set sceneGraph(value: boolean) {
373
+ this.setProperty("sceneGraph", value);
374
+ if (value) {
375
+ this.setProperty("enablePartialMode", false);
376
+ }
388
377
  }
389
378
 
390
- get edgeModel() {
379
+ get edgeModel(): boolean {
391
380
  return Boolean(this._data.edgeModel);
392
381
  }
393
382
 
394
- set edgeModel(value) {
395
- this._data.edgeModel = Boolean(value);
396
- this.change();
383
+ set edgeModel(value: boolean) {
384
+ this.setProperty("edgeModel", value);
397
385
  }
398
386
 
399
- get reverseZoomWheel() {
387
+ get reverseZoomWheel(): boolean {
400
388
  return this._data.reverseZoomWheel;
401
389
  }
402
390
 
403
391
  set reverseZoomWheel(value: boolean) {
404
- this._data.reverseZoomWheel = !!value;
405
- this.change();
392
+ this.setProperty("reverseZoomWheel", value);
406
393
  }
407
394
 
408
- get enableZoomWheel() {
395
+ get enableZoomWheel(): boolean {
409
396
  return this._data.enableZoomWheel;
410
397
  }
411
398
 
412
399
  set enableZoomWheel(value: boolean) {
413
- this._data.enableZoomWheel = !!value;
414
- this.change();
400
+ this.setProperty("enableZoomWheel", value);
415
401
  }
416
402
 
417
- get enableGestures() {
403
+ get enableGestures(): boolean {
418
404
  return this._data.enableGestures;
419
405
  }
420
406
 
421
407
  set enableGestures(value: boolean) {
422
- this._data.enableGestures = !!value;
423
- this.change();
408
+ this.setProperty("enableGestures", value);
424
409
  }
425
410
 
426
- get geometryType() {
411
+ get geometryType(): string {
427
412
  return this._data.geometryType;
428
413
  }
429
414
 
430
415
  set geometryType(value: string) {
431
- this._data.geometryType = value;
432
- this.change();
416
+ this.setProperty("geometryType", value);
433
417
  }
434
418
 
435
419
  get rulerUnit(): string {
@@ -437,17 +421,15 @@ export class Options implements IOptions {
437
421
  }
438
422
 
439
423
  set rulerUnit(value: string) {
440
- this._data.rulerUnit = value;
441
- this.change();
424
+ this.setProperty("rulerUnit", value);
442
425
  }
443
426
 
444
- get rulerPrecision(): any {
427
+ get rulerPrecision(): "Default" | "Auto" | number {
445
428
  return this._data.rulerPrecision;
446
429
  }
447
430
 
448
- set rulerPrecision(value: any) {
449
- this._data.rulerPrecision = value;
450
- this.change();
431
+ set rulerPrecision(value: "Default" | "Auto" | number) {
432
+ this.setProperty("rulerPrecision", value);
451
433
  }
452
434
 
453
435
  get cameraMode(): CameraMode {
@@ -455,7 +437,22 @@ export class Options implements IOptions {
455
437
  }
456
438
 
457
439
  set cameraMode(value: CameraMode) {
458
- this._data.cameraMode = value;
459
- this.change();
440
+ this.setProperty("cameraMode", value);
441
+ }
442
+
443
+ get snapshotMimeType(): string {
444
+ return this._data.snapshotMimeType;
445
+ }
446
+
447
+ set snapshotMimeType(value: string) {
448
+ this.setProperty("snapshotMimeType", value);
449
+ }
450
+
451
+ get snapshotQuality(): number {
452
+ return this._data.snapshotQuality;
453
+ }
454
+
455
+ set snapshotQuality(value: number) {
456
+ this.setProperty("snapshotQuality", value);
460
457
  }
461
458
  }