@inweb/viewer-core 27.6.0 → 27.6.2

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.
@@ -265,21 +265,44 @@ function defaultOptions() {
265
265
  };
266
266
  }
267
267
 
268
+ function isColorRGB(value) {
269
+ return (typeof value === "object" &&
270
+ value !== null &&
271
+ typeof value.r === "number" &&
272
+ typeof value.g === "number" &&
273
+ typeof value.b === "number");
274
+ }
275
+ function isLegacyRGB(value) {
276
+ return (typeof value === "object" &&
277
+ value !== null &&
278
+ typeof value.red === "number" &&
279
+ typeof value.green === "number" &&
280
+ typeof value.blue === "number");
281
+ }
268
282
  class Options {
269
283
  constructor(emitter) {
284
+ this._updateCount = 0;
270
285
  this._emitter = emitter;
271
- this._data = defaultOptions();
286
+ this._data = Options.defaults();
287
+ this._defaults = Options.defaults();
272
288
  this.loadFromStorage();
273
289
  }
274
290
  static defaults() {
275
291
  return defaultOptions();
276
292
  }
277
293
  change() {
278
- if (this._emitter !== undefined) {
294
+ if (this._emitter !== undefined && this._updateCount === 0) {
279
295
  this.saveToStorage();
280
296
  this._emitter.emit({ type: "optionschange", data: this });
281
297
  }
282
298
  }
299
+ beginUpdate() {
300
+ this._updateCount++;
301
+ }
302
+ endUpdate() {
303
+ this._updateCount--;
304
+ this.change();
305
+ }
283
306
  saveToStorage() {
284
307
  if (typeof window !== "undefined")
285
308
  try {
@@ -293,18 +316,15 @@ class Options {
293
316
  if (typeof window !== "undefined")
294
317
  try {
295
318
  const item = localStorage.getItem("od-client-settings");
296
- if (item) {
297
- const data = JSON.parse(item);
298
- this.data = { ...data };
299
- }
319
+ if (item)
320
+ this.data = JSON.parse(item);
300
321
  }
301
322
  catch (error) {
302
323
  console.error("Cannot load client settings.", error);
303
324
  }
304
325
  }
305
- resetToDefaults(fields) {
306
- const defaults = Options.defaults();
307
- if (fields !== undefined) {
326
+ resetToDefaults(fields, defaults = this._defaults) {
327
+ if (Array.isArray(fields)) {
308
328
  const resetData = {};
309
329
  for (const field of fields) {
310
330
  if (field in defaults)
@@ -316,34 +336,41 @@ class Options {
316
336
  this.data = defaults;
317
337
  }
318
338
  }
319
- setProperty(key, value = Options.defaults()[key]) {
339
+ setProperty(key, value = this._defaults[key], accept = this.isValidValue(key, value)) {
340
+ if (!accept) {
341
+ console.warn(`Options.${key}: Invalid value`, value);
342
+ return;
343
+ }
320
344
  if (this._data[key] !== value) {
321
345
  this._data[key] = value;
322
346
  this.change();
323
347
  }
324
348
  }
349
+ isValidValue(key, value) {
350
+ return typeof value === typeof this._defaults[key];
351
+ }
325
352
  get data() {
326
353
  return this._data;
327
354
  }
328
355
  set data(value) {
329
- const defaults = Options.defaults();
330
- const merged = { ...defaults, ...this._data, ...value };
331
- for (const key of Object.keys(defaults)) {
332
- if (merged[key] === undefined)
333
- merged[key] = defaults[key];
356
+ this.beginUpdate();
357
+ try {
358
+ for (const key of Object.keys(value)) {
359
+ if (key in this._defaults)
360
+ this[key] = value[key];
361
+ else
362
+ this._data[key] = value[key];
363
+ }
364
+ if ("enablePartialMode" in value) {
365
+ this.enablePartialMode = value.enablePartialMode;
366
+ }
367
+ if ("sectionFillColor" in value) {
368
+ this.sectionFillColor = value.sectionFillColor;
369
+ }
334
370
  }
335
- this._data = merged;
336
- if (this._data.enablePartialMode) {
337
- this._data.enableStreamingMode = true;
338
- this._data.sceneGraph = false;
371
+ finally {
372
+ this.endUpdate();
339
373
  }
340
- if (!value.sectionFillColor && value.cuttingPlaneFillColor)
341
- this._data.sectionFillColor = {
342
- r: value.cuttingPlaneFillColor.red,
343
- g: value.cuttingPlaneFillColor.green,
344
- b: value.cuttingPlaneFillColor.blue,
345
- };
346
- this.change();
347
374
  }
348
375
  get showWCS() {
349
376
  return this._data.showWCS;
@@ -361,7 +388,7 @@ class Options {
361
388
  return this._data.antialiasing;
362
389
  }
363
390
  set antialiasing(value) {
364
- this.setProperty("antialiasing", value);
391
+ this.setProperty("antialiasing", value, typeof value === "boolean" || typeof value === "string");
365
392
  }
366
393
  get groundShadow() {
367
394
  return this._data.groundShadow;
@@ -397,19 +424,27 @@ class Options {
397
424
  return this._data.enableStreamingMode;
398
425
  }
399
426
  set enableStreamingMode(value) {
400
- this.setProperty("enableStreamingMode", value);
401
- if (!value) {
402
- this.setProperty("enablePartialMode", false);
427
+ this.beginUpdate();
428
+ try {
429
+ this.setProperty("enableStreamingMode", value);
430
+ this.setProperty("enablePartialMode", this.enablePartialMode && this.enableStreamingMode);
431
+ }
432
+ finally {
433
+ this.endUpdate();
403
434
  }
404
435
  }
405
436
  get enablePartialMode() {
406
437
  return this._data.enablePartialMode;
407
438
  }
408
439
  set enablePartialMode(value) {
409
- this.setProperty("enablePartialMode", value);
410
- if (value) {
411
- this.setProperty("enableStreamingMode", true);
412
- this.setProperty("sceneGraph", false);
440
+ this.beginUpdate();
441
+ try {
442
+ this.setProperty("enablePartialMode", value);
443
+ this.setProperty("enableStreamingMode", this.enableStreamingMode || this.enablePartialMode);
444
+ this.setProperty("sceneGraph", this.sceneGraph && !this.enablePartialMode);
445
+ }
446
+ finally {
447
+ this.endUpdate();
413
448
  }
414
449
  }
415
450
  get memoryLimit() {
@@ -419,20 +454,24 @@ class Options {
419
454
  this.setProperty("memoryLimit", value);
420
455
  }
421
456
  get cuttingPlaneFillColor() {
422
- console.warn("Options.cuttingPlaneFillColor has been deprecated since 27.5 and will be removed in a future release, use sectionFillColor instead");
423
- return {
424
- red: this._data.sectionFillColor.r,
425
- green: this._data.sectionFillColor.g,
426
- blue: this._data.sectionFillColor.b,
427
- };
457
+ return this._data.cuttingPlaneFillColor;
428
458
  }
429
459
  set cuttingPlaneFillColor(value) {
430
- console.warn("Options.cuttingPlaneFillColor has been deprecated since 27.5 and will be removed in a future release, use sectionFillColor instead");
431
- this.setProperty("sectionFillColor", {
432
- r: value.red,
433
- g: value.green,
434
- b: value.blue,
435
- });
460
+ if (this._updateCount === 0) {
461
+ console.warn("Options.cuttingPlaneFillColor has been deprecated since 27.5 and will be removed in a future release, use sectionFillColor instead");
462
+ }
463
+ this.beginUpdate();
464
+ try {
465
+ this.setProperty("cuttingPlaneFillColor", value, isLegacyRGB(value));
466
+ this.setProperty("sectionFillColor", {
467
+ r: this._data.cuttingPlaneFillColor.red,
468
+ g: this._data.cuttingPlaneFillColor.green,
469
+ b: this._data.cuttingPlaneFillColor.blue,
470
+ });
471
+ }
472
+ finally {
473
+ this.endUpdate();
474
+ }
436
475
  }
437
476
  get enableSectionFill() {
438
477
  return this._data.enableSectionFill;
@@ -444,7 +483,18 @@ class Options {
444
483
  return this._data.sectionFillColor;
445
484
  }
446
485
  set sectionFillColor(value) {
447
- this.setProperty("sectionFillColor", value);
486
+ this.beginUpdate();
487
+ try {
488
+ this.setProperty("sectionFillColor", value, isColorRGB(value));
489
+ this.setProperty("cuttingPlaneFillColor", {
490
+ red: this._data.sectionFillColor.r,
491
+ green: this._data.sectionFillColor.g,
492
+ blue: this._data.sectionFillColor.b,
493
+ });
494
+ }
495
+ finally {
496
+ this.endUpdate();
497
+ }
448
498
  }
449
499
  get sectionUseObjectColor() {
450
500
  return this._data.sectionUseObjectColor;
@@ -462,7 +512,7 @@ class Options {
462
512
  return this._data.sectionHatchColor;
463
513
  }
464
514
  set sectionHatchColor(value) {
465
- this.setProperty("sectionHatchColor", value);
515
+ this.setProperty("sectionHatchColor", value, isColorRGB(value));
466
516
  }
467
517
  get sectionHatchScale() {
468
518
  return this._data.sectionHatchScale;
@@ -480,7 +530,7 @@ class Options {
480
530
  return this._data.sectionOutlineColor;
481
531
  }
482
532
  set sectionOutlineColor(value) {
483
- this.setProperty("sectionOutlineColor", value);
533
+ this.setProperty("sectionOutlineColor", value, isColorRGB(value));
484
534
  }
485
535
  get sectionOutlineWidth() {
486
536
  return this._data.sectionOutlineWidth;
@@ -492,13 +542,13 @@ class Options {
492
542
  return this._data.edgesColor;
493
543
  }
494
544
  set edgesColor(value) {
495
- this.setProperty("edgesColor", value);
545
+ this.setProperty("edgesColor", value, isColorRGB(value));
496
546
  }
497
547
  get facesColor() {
498
548
  return this._data.facesColor;
499
549
  }
500
550
  set facesColor(value) {
501
- this.setProperty("facesColor", value);
551
+ this.setProperty("facesColor", value, isColorRGB(value));
502
552
  }
503
553
  get edgesVisibility() {
504
554
  return this._data.edgesVisibility;
@@ -534,9 +584,13 @@ class Options {
534
584
  return this._data.sceneGraph;
535
585
  }
536
586
  set sceneGraph(value) {
537
- this.setProperty("sceneGraph", value);
538
- if (value) {
539
- this.setProperty("enablePartialMode", false);
587
+ this.beginUpdate();
588
+ try {
589
+ this.setProperty("sceneGraph", value);
590
+ this.setProperty("enablePartialMode", this.enablePartialMode && !this.sceneGraph);
591
+ }
592
+ finally {
593
+ this.endUpdate();
540
594
  }
541
595
  }
542
596
  get edgeModel() {
@@ -579,13 +633,13 @@ class Options {
579
633
  return this._data.rulerPrecision;
580
634
  }
581
635
  set rulerPrecision(value) {
582
- this.setProperty("rulerPrecision", value);
636
+ this.setProperty("rulerPrecision", value, typeof value === "number" || value === "Default" || value === "Auto");
583
637
  }
584
638
  get cameraMode() {
585
- return this._data.cameraMode || "perspective";
639
+ return this._data.cameraMode;
586
640
  }
587
641
  set cameraMode(value) {
588
- this.setProperty("cameraMode", value);
642
+ this.setProperty("cameraMode", value, value === "perspective" || value === "orthographic");
589
643
  }
590
644
  get snapshotMimeType() {
591
645
  return this._data.snapshotMimeType;