@thatopen/components 2.4.0-alpha.31 → 2.4.0-alpha.32

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.
package/dist/index.mjs CHANGED
@@ -3858,6 +3858,97 @@ class DataMap extends Map {
3858
3858
  }
3859
3859
  class ComponentWithUI extends Component {
3860
3860
  }
3861
+ class ControlsUtils {
3862
+ static isEntry(item) {
3863
+ const types = /* @__PURE__ */ new Set([
3864
+ "Boolean",
3865
+ "Color",
3866
+ "Text",
3867
+ "Number",
3868
+ "Select",
3869
+ "Vector3",
3870
+ "TextSet",
3871
+ "None"
3872
+ ]);
3873
+ return types.has(item.type);
3874
+ }
3875
+ static copySchema(schema, copy = {}) {
3876
+ for (const name in schema) {
3877
+ const entry = schema[name];
3878
+ if (this.isEntry(entry)) {
3879
+ copy[name] = this.copyEntry(entry);
3880
+ } else {
3881
+ copy[name] = {};
3882
+ this.copySchema(entry, copy[name]);
3883
+ }
3884
+ }
3885
+ return copy;
3886
+ }
3887
+ static copyEntry(controlEntry) {
3888
+ if (controlEntry.type === "Boolean") {
3889
+ const entry = controlEntry;
3890
+ return {
3891
+ type: entry.type,
3892
+ value: entry.value
3893
+ };
3894
+ }
3895
+ if (controlEntry.type === "Color") {
3896
+ const entry = controlEntry;
3897
+ return {
3898
+ type: entry.type,
3899
+ value: entry.value.clone()
3900
+ };
3901
+ }
3902
+ if (controlEntry.type === "Text") {
3903
+ const entry = controlEntry;
3904
+ return {
3905
+ type: entry.type,
3906
+ value: entry.value
3907
+ };
3908
+ }
3909
+ if (controlEntry.type === "Number") {
3910
+ const entry = controlEntry;
3911
+ return {
3912
+ type: entry.type,
3913
+ value: entry.value,
3914
+ min: entry.min,
3915
+ max: entry.max,
3916
+ interpolable: entry.interpolable
3917
+ };
3918
+ }
3919
+ if (controlEntry.type === "Select") {
3920
+ const entry = controlEntry;
3921
+ return {
3922
+ type: entry.type,
3923
+ value: entry.value,
3924
+ multiple: entry.multiple,
3925
+ options: new Set(entry.options)
3926
+ };
3927
+ }
3928
+ if (controlEntry.type === "Vector3") {
3929
+ const entry = controlEntry;
3930
+ return {
3931
+ type: entry.type,
3932
+ value: entry.value.clone()
3933
+ };
3934
+ }
3935
+ if (controlEntry.type === "TextSet") {
3936
+ const entry = controlEntry;
3937
+ return {
3938
+ type: entry.type,
3939
+ value: new Set(entry.value)
3940
+ };
3941
+ }
3942
+ if (controlEntry.type === "None") {
3943
+ const entry = controlEntry;
3944
+ return {
3945
+ type: entry.type,
3946
+ value: entry.value
3947
+ };
3948
+ }
3949
+ throw new Error("Invalid entry!");
3950
+ }
3951
+ }
3861
3952
  class EventManager {
3862
3953
  constructor() {
3863
3954
  /**
@@ -5533,12 +5624,7 @@ class Configurator {
5533
5624
  configManager.list.set(this.uuid, this);
5534
5625
  }
5535
5626
  get controls() {
5536
- const copy = {};
5537
- for (const name in this._config) {
5538
- const entry = this._config[name];
5539
- copy[name] = this.copyEntry(entry);
5540
- }
5541
- return copy;
5627
+ return ControlsUtils.copySchema(this._config);
5542
5628
  }
5543
5629
  set(data) {
5544
5630
  for (const name in data) {
@@ -5548,111 +5634,59 @@ class Configurator {
5548
5634
  }
5549
5635
  }
5550
5636
  }
5551
- export() {
5552
- const serializedData = {};
5553
- for (const id in this._config) {
5554
- const control = this._config[id];
5555
- if (control.type === "Color") {
5556
- const { r, g, b } = control.value;
5557
- serializedData[id] = { ...control, value: { r, g, b } };
5558
- } else if (control.type === "Vector3") {
5559
- const { x, y, z } = control.value;
5560
- serializedData[id] = { ...control, value: { x, y, z } };
5561
- } else if (control.type === "TextSet") {
5562
- const value = Array.from(control.value);
5563
- serializedData[id] = { ...control, value };
5564
- } else if (control.type === "Select") {
5565
- const options = Array.from(control.options);
5566
- serializedData[id] = { ...control, options };
5567
- } else {
5568
- serializedData[id] = { ...control };
5569
- }
5570
- }
5571
- return serializedData;
5572
- }
5573
- import(serializedData) {
5574
- const imported = {};
5575
- for (const id in serializedData) {
5576
- const control = serializedData[id];
5577
- if (control.type === "Color") {
5578
- const { r, g, b } = control.value;
5579
- imported[id] = { ...control, value: new THREE$1.Color(r, g, b) };
5580
- } else if (control.type === "Vector3") {
5581
- const { x, y, z } = control.value;
5582
- imported[id] = { ...control, value: new THREE$1.Vector3(x, y, z) };
5583
- } else if (control.type === "TextSet") {
5584
- imported[id] = { ...control, value: new Set(control.value) };
5585
- } else if (control.type === "Select") {
5586
- imported[id] = { ...control, options: new Set(control.options) };
5637
+ export(controls = this._config, exported = {}) {
5638
+ for (const id in controls) {
5639
+ const control = controls[id];
5640
+ const isControl = ControlsUtils.isEntry(control);
5641
+ if (isControl) {
5642
+ if (control.type === "Color") {
5643
+ const { r, g, b } = control.value;
5644
+ exported[id] = { ...control, value: { r, g, b } };
5645
+ } else if (control.type === "Vector3") {
5646
+ const { x, y, z } = control.value;
5647
+ exported[id] = { ...control, value: { x, y, z } };
5648
+ } else if (control.type === "TextSet") {
5649
+ const value = Array.from(control.value);
5650
+ exported[id] = { ...control, value };
5651
+ } else if (control.type === "Select") {
5652
+ const options = Array.from(control.options);
5653
+ exported[id] = { ...control, options };
5654
+ } else {
5655
+ exported[id] = { ...control };
5656
+ }
5587
5657
  } else {
5588
- imported[id] = { ...control };
5658
+ exported[id] = {};
5659
+ this.export(control, exported[id]);
5589
5660
  }
5590
5661
  }
5591
- this.set(imported);
5662
+ return exported;
5592
5663
  }
5593
- copyEntry(controlEntry) {
5594
- if (controlEntry.type === "Boolean") {
5595
- const entry = controlEntry;
5596
- return {
5597
- type: entry.type,
5598
- value: entry.value
5599
- };
5600
- }
5601
- if (controlEntry.type === "Color") {
5602
- const entry = controlEntry;
5603
- return {
5604
- type: entry.type,
5605
- value: entry.value.clone()
5606
- };
5607
- }
5608
- if (controlEntry.type === "Text") {
5609
- const entry = controlEntry;
5610
- return {
5611
- type: entry.type,
5612
- value: entry.value
5613
- };
5614
- }
5615
- if (controlEntry.type === "Number") {
5616
- const entry = controlEntry;
5617
- return {
5618
- type: entry.type,
5619
- value: entry.value,
5620
- min: entry.min,
5621
- max: entry.max,
5622
- interpolable: entry.interpolable
5623
- };
5624
- }
5625
- if (controlEntry.type === "Select") {
5626
- const entry = controlEntry;
5627
- return {
5628
- type: entry.type,
5629
- value: entry.value,
5630
- multiple: entry.multiple,
5631
- options: new Set(entry.options)
5632
- };
5633
- }
5634
- if (controlEntry.type === "Vector3") {
5635
- const entry = controlEntry;
5636
- return {
5637
- type: entry.type,
5638
- value: entry.value.clone()
5639
- };
5640
- }
5641
- if (controlEntry.type === "TextSet") {
5642
- const entry = controlEntry;
5643
- return {
5644
- type: entry.type,
5645
- value: new Set(entry.value)
5646
- };
5664
+ import(exported, imported = {}, first = true) {
5665
+ for (const id in exported) {
5666
+ const control = exported[id];
5667
+ const isControl = ControlsUtils.isEntry(control);
5668
+ if (isControl) {
5669
+ if (control.type === "Color") {
5670
+ const { r, g, b } = control.value;
5671
+ imported[id] = { ...control, value: new THREE$1.Color(r, g, b) };
5672
+ } else if (control.type === "Vector3") {
5673
+ const { x, y, z } = control.value;
5674
+ imported[id] = { ...control, value: new THREE$1.Vector3(x, y, z) };
5675
+ } else if (control.type === "TextSet") {
5676
+ imported[id] = { ...control, value: new Set(control.value) };
5677
+ } else if (control.type === "Select") {
5678
+ imported[id] = { ...control, options: new Set(control.options) };
5679
+ } else {
5680
+ imported[id] = { ...control };
5681
+ }
5682
+ } else {
5683
+ imported[id] = {};
5684
+ this.import(control, imported[id], false);
5685
+ }
5647
5686
  }
5648
- if (controlEntry.type === "None") {
5649
- const entry = controlEntry;
5650
- return {
5651
- type: entry.type,
5652
- value: entry.value
5653
- };
5687
+ if (first) {
5688
+ this.set(imported);
5654
5689
  }
5655
- throw new Error("Invalid entry!");
5656
5690
  }
5657
5691
  }
5658
5692
  const _ConfigManager = class _ConfigManager extends Component {
@@ -27637,6 +27671,7 @@ export {
27637
27671
  Components,
27638
27672
  ConfigManager,
27639
27673
  Configurator,
27674
+ ControlsUtils,
27640
27675
  CullerRenderer,
27641
27676
  Cullers,
27642
27677
  DataMap,