@inweb/viewer-three 27.6.0 → 27.6.1

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.
@@ -263,21 +263,44 @@
263
263
  snapshotQuality: 0.25,
264
264
  };
265
265
  }
266
+ function isColorRGB(value) {
267
+ return (typeof value === "object" &&
268
+ value !== null &&
269
+ typeof value.r === "number" &&
270
+ typeof value.g === "number" &&
271
+ typeof value.b === "number");
272
+ }
273
+ function isLegacyRGB(value) {
274
+ return (typeof value === "object" &&
275
+ value !== null &&
276
+ typeof value.red === "number" &&
277
+ typeof value.green === "number" &&
278
+ typeof value.blue === "number");
279
+ }
266
280
  class Options {
267
281
  constructor(emitter) {
282
+ this._updateCount = 0;
268
283
  this._emitter = emitter;
269
- this._data = defaultOptions();
284
+ this._data = Options.defaults();
285
+ this._defaults = Options.defaults();
270
286
  this.loadFromStorage();
271
287
  }
272
288
  static defaults() {
273
289
  return defaultOptions();
274
290
  }
275
291
  change() {
276
- if (this._emitter !== undefined) {
292
+ if (this._emitter !== undefined && this._updateCount === 0) {
277
293
  this.saveToStorage();
278
294
  this._emitter.emit({ type: "optionschange", data: this });
279
295
  }
280
296
  }
297
+ beginUpdate() {
298
+ this._updateCount++;
299
+ }
300
+ endUpdate() {
301
+ this._updateCount--;
302
+ this.change();
303
+ }
281
304
  saveToStorage() {
282
305
  if (typeof window !== "undefined")
283
306
  try {
@@ -291,18 +314,15 @@
291
314
  if (typeof window !== "undefined")
292
315
  try {
293
316
  const item = localStorage.getItem("od-client-settings");
294
- if (item) {
295
- const data = JSON.parse(item);
296
- this.data = { ...data };
297
- }
317
+ if (item)
318
+ this.data = JSON.parse(item);
298
319
  }
299
320
  catch (error) {
300
321
  console.error("Cannot load client settings.", error);
301
322
  }
302
323
  }
303
- resetToDefaults(fields) {
304
- const defaults = Options.defaults();
305
- if (fields !== undefined) {
324
+ resetToDefaults(fields, defaults = this._defaults) {
325
+ if (Array.isArray(fields)) {
306
326
  const resetData = {};
307
327
  for (const field of fields) {
308
328
  if (field in defaults)
@@ -314,34 +334,41 @@
314
334
  this.data = defaults;
315
335
  }
316
336
  }
317
- setProperty(key, value = Options.defaults()[key]) {
337
+ setProperty(key, value = this._defaults[key], accept = this.isValidValue(key, value)) {
338
+ if (!accept) {
339
+ console.warn(`Options.${key}: Invalid value`, value);
340
+ return;
341
+ }
318
342
  if (this._data[key] !== value) {
319
343
  this._data[key] = value;
320
344
  this.change();
321
345
  }
322
346
  }
347
+ isValidValue(key, value) {
348
+ return typeof value === typeof this._defaults[key];
349
+ }
323
350
  get data() {
324
351
  return this._data;
325
352
  }
326
353
  set data(value) {
327
- const defaults = Options.defaults();
328
- const merged = { ...defaults, ...this._data, ...value };
329
- for (const key of Object.keys(defaults)) {
330
- if (merged[key] === undefined)
331
- merged[key] = defaults[key];
332
- }
333
- this._data = merged;
334
- if (this._data.enablePartialMode) {
335
- this._data.enableStreamingMode = true;
336
- this._data.sceneGraph = false;
337
- }
338
- if (!value.sectionFillColor && value.cuttingPlaneFillColor)
339
- this._data.sectionFillColor = {
340
- r: value.cuttingPlaneFillColor.red,
341
- g: value.cuttingPlaneFillColor.green,
342
- b: value.cuttingPlaneFillColor.blue,
343
- };
344
- this.change();
354
+ this.beginUpdate();
355
+ try {
356
+ for (const key of Object.keys(value)) {
357
+ if (key in this._defaults)
358
+ this[key] = value[key];
359
+ else
360
+ this._data[key] = value[key];
361
+ }
362
+ if ("enablePartialMode" in value) {
363
+ this.enablePartialMode = value.enablePartialMode;
364
+ }
365
+ if ("sectionFillColor" in value) {
366
+ this.sectionFillColor = value.sectionFillColor;
367
+ }
368
+ }
369
+ finally {
370
+ this.endUpdate();
371
+ }
345
372
  }
346
373
  get showWCS() {
347
374
  return this._data.showWCS;
@@ -359,7 +386,7 @@
359
386
  return this._data.antialiasing;
360
387
  }
361
388
  set antialiasing(value) {
362
- this.setProperty("antialiasing", value);
389
+ this.setProperty("antialiasing", value, typeof value === "boolean" || typeof value === "string");
363
390
  }
364
391
  get groundShadow() {
365
392
  return this._data.groundShadow;
@@ -396,19 +423,15 @@
396
423
  }
397
424
  set enableStreamingMode(value) {
398
425
  this.setProperty("enableStreamingMode", value);
399
- if (!value) {
400
- this.setProperty("enablePartialMode", false);
401
- }
426
+ this.setProperty("enablePartialMode", this.enablePartialMode && this.enableStreamingMode);
402
427
  }
403
428
  get enablePartialMode() {
404
429
  return this._data.enablePartialMode;
405
430
  }
406
431
  set enablePartialMode(value) {
407
432
  this.setProperty("enablePartialMode", value);
408
- if (value) {
409
- this.setProperty("enableStreamingMode", true);
410
- this.setProperty("sceneGraph", false);
411
- }
433
+ this.setProperty("enableStreamingMode", this.enableStreamingMode || this.enablePartialMode);
434
+ this.setProperty("sceneGraph", this.sceneGraph && !this.enablePartialMode);
412
435
  }
413
436
  get memoryLimit() {
414
437
  return this._data.memoryLimit;
@@ -417,20 +440,18 @@
417
440
  this.setProperty("memoryLimit", value);
418
441
  }
419
442
  get cuttingPlaneFillColor() {
420
- console.warn("Options.cuttingPlaneFillColor has been deprecated since 27.5 and will be removed in a future release, use sectionFillColor instead");
421
- return {
422
- red: this._data.sectionFillColor.r,
423
- green: this._data.sectionFillColor.g,
424
- blue: this._data.sectionFillColor.b,
425
- };
443
+ return this._data.cuttingPlaneFillColor;
426
444
  }
427
445
  set cuttingPlaneFillColor(value) {
428
- console.warn("Options.cuttingPlaneFillColor has been deprecated since 27.5 and will be removed in a future release, use sectionFillColor instead");
446
+ if (this._updateCount === 0) {
447
+ console.warn("Options.cuttingPlaneFillColor has been deprecated since 27.5 and will be removed in a future release, use sectionFillColor instead");
448
+ }
449
+ this.setProperty("cuttingPlaneFillColor", value, isLegacyRGB(value));
429
450
  this.setProperty("sectionFillColor", {
430
- r: value.red,
431
- g: value.green,
432
- b: value.blue,
433
- });
451
+ r: this._data.cuttingPlaneFillColor.red,
452
+ g: this._data.cuttingPlaneFillColor.green,
453
+ b: this._data.cuttingPlaneFillColor.blue,
454
+ }, true);
434
455
  }
435
456
  get enableSectionFill() {
436
457
  return this._data.enableSectionFill;
@@ -442,7 +463,12 @@
442
463
  return this._data.sectionFillColor;
443
464
  }
444
465
  set sectionFillColor(value) {
445
- this.setProperty("sectionFillColor", value);
466
+ this.setProperty("sectionFillColor", value, isColorRGB(value));
467
+ this.setProperty("cuttingPlaneFillColor", {
468
+ red: this._data.sectionFillColor.r,
469
+ green: this._data.sectionFillColor.g,
470
+ blue: this._data.sectionFillColor.b,
471
+ }, true);
446
472
  }
447
473
  get sectionUseObjectColor() {
448
474
  return this._data.sectionUseObjectColor;
@@ -460,7 +486,7 @@
460
486
  return this._data.sectionHatchColor;
461
487
  }
462
488
  set sectionHatchColor(value) {
463
- this.setProperty("sectionHatchColor", value);
489
+ this.setProperty("sectionHatchColor", value, isColorRGB(value));
464
490
  }
465
491
  get sectionHatchScale() {
466
492
  return this._data.sectionHatchScale;
@@ -478,7 +504,7 @@
478
504
  return this._data.sectionOutlineColor;
479
505
  }
480
506
  set sectionOutlineColor(value) {
481
- this.setProperty("sectionOutlineColor", value);
507
+ this.setProperty("sectionOutlineColor", value, isColorRGB(value));
482
508
  }
483
509
  get sectionOutlineWidth() {
484
510
  return this._data.sectionOutlineWidth;
@@ -490,13 +516,13 @@
490
516
  return this._data.edgesColor;
491
517
  }
492
518
  set edgesColor(value) {
493
- this.setProperty("edgesColor", value);
519
+ this.setProperty("edgesColor", value, isColorRGB(value));
494
520
  }
495
521
  get facesColor() {
496
522
  return this._data.facesColor;
497
523
  }
498
524
  set facesColor(value) {
499
- this.setProperty("facesColor", value);
525
+ this.setProperty("facesColor", value, isColorRGB(value));
500
526
  }
501
527
  get edgesVisibility() {
502
528
  return this._data.edgesVisibility;
@@ -533,9 +559,7 @@
533
559
  }
534
560
  set sceneGraph(value) {
535
561
  this.setProperty("sceneGraph", value);
536
- if (value) {
537
- this.setProperty("enablePartialMode", false);
538
- }
562
+ this.setProperty("enablePartialMode", this.enablePartialMode && !this.sceneGraph);
539
563
  }
540
564
  get edgeModel() {
541
565
  return Boolean(this._data.edgeModel);
@@ -577,13 +601,13 @@
577
601
  return this._data.rulerPrecision;
578
602
  }
579
603
  set rulerPrecision(value) {
580
- this.setProperty("rulerPrecision", value);
604
+ this.setProperty("rulerPrecision", value, typeof value === "number" || value === "Default" || value === "Auto");
581
605
  }
582
606
  get cameraMode() {
583
- return this._data.cameraMode || "perspective";
607
+ return this._data.cameraMode;
584
608
  }
585
609
  set cameraMode(value) {
586
- this.setProperty("cameraMode", value);
610
+ this.setProperty("cameraMode", value, value === "perspective" || value === "orthographic");
587
611
  }
588
612
  get snapshotMimeType() {
589
613
  return this._data.snapshotMimeType;