3dviewer-sdk 1.1.5 → 1.1.6

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.d.mts CHANGED
@@ -23,6 +23,7 @@ declare enum ViewerMessageType {
23
23
  WALK_THROUGH = "viewer-walk-through",
24
24
  ZOOM_WINDOW = "viewer-zoom-window",
25
25
  ZOOM_FIT = "viewer-zoom-fit",
26
+ DISPLAY_SET_BACKGROUND = "viewer-display-set-background",
26
27
  TOOLBAR_CONFIG = "viewer-toolbar-config",
27
28
  TOOLBAR_USE = "viewer-toolbar-use",
28
29
  PANEL_OPEN = "viewer-panel-open",
@@ -59,6 +60,19 @@ type NodeSelectionChangePayload = {
59
60
  nodeIds: string[];
60
61
  timestamp: number;
61
62
  };
63
+ type ViewerRgbColor = {
64
+ r: number;
65
+ g: number;
66
+ b: number;
67
+ };
68
+ type ViewerRgbaColor = ViewerRgbColor & {
69
+ a: number;
70
+ };
71
+ type ViewerBackgroundColorInput = ViewerRgbColor | ViewerRgbaColor | string;
72
+ type ViewerBackgroundPayload = {
73
+ top: ViewerRgbColor;
74
+ bottom?: ViewerRgbColor;
75
+ };
62
76
  type CameraZoomPayload = {
63
77
  requestId?: string;
64
78
  percent: number;
@@ -289,6 +303,22 @@ declare class CameraModule {
289
303
  private postCameraGetZoom;
290
304
  }
291
305
 
306
+ type BackgroundOptionsInput = {
307
+ top: ViewerBackgroundColorInput;
308
+ bottom?: ViewerBackgroundColorInput;
309
+ };
310
+ type InitialBackground = ViewerBackgroundColorInput | BackgroundOptionsInput;
311
+
312
+ type SetBackgroundOptions = BackgroundOptionsInput;
313
+ declare class DisplayModule {
314
+ private viewer;
315
+ constructor(viewer: Viewer3D);
316
+ setBackgroundColor(color: ViewerBackgroundColorInput): void;
317
+ setBackgroundGradient(top: ViewerBackgroundColorInput, bottom: ViewerBackgroundColorInput): void;
318
+ setBackground(options: SetBackgroundOptions): void;
319
+ private postBackground;
320
+ }
321
+
292
322
  declare class InteractionModule {
293
323
  private viewer;
294
324
  on: {
@@ -647,6 +677,7 @@ type Viewer3DOptions = {
647
677
  uploadPath?: string;
648
678
  file?: File;
649
679
  initialToolbar?: InitialToolbarUse;
680
+ initialBackground?: InitialBackground;
650
681
  ui?: {
651
682
  loadingIndicator?: boolean;
652
683
  };
@@ -666,6 +697,7 @@ declare class Viewer3D {
666
697
  private loadingState;
667
698
  private emitter;
668
699
  camera: CameraModule;
700
+ display: DisplayModule;
669
701
  interaction: InteractionModule;
670
702
  node: NodeModule;
671
703
  files: FilesModule;
@@ -691,6 +723,7 @@ declare class Viewer3D {
691
723
  private ensureInit;
692
724
  private withInitialOptions;
693
725
  private normalizeInitialToolbar;
726
+ private normalizeInitialBackground;
694
727
  _on<K extends SdkEventKey>(event: K, cb: (payload: SdkEventPayload<K>) => void): () => void;
695
728
  _off<K extends SdkEventKey>(event: K, cb: (payload: SdkEventPayload<K>) => void): void;
696
729
  _emit<K extends SdkEventKey>(event: K, payload: SdkEventPayload<K>): void;
@@ -702,4 +735,4 @@ declare class Viewer3D {
702
735
  private handleMessage;
703
736
  }
704
737
 
705
- export { type CameraZoomPayload, type ConvertOptions, type ConvertV2Options, type CreatePipelineOptions, type FileInfoCheckInput, type FileInfoCheckPayloadItem, type FilesConfig, type InitialToolbarUse, type LanguageCode, type LoadStage, type LoadStatePayload, type MarkupAction, type MarkupListItem, type MarkupOperationResultPayload, type ObjectPropertiesGetOptions, type ObjectPropertiesResult, type PreparedViewerData, Viewer3D, type Viewer3DOptions, type ViewerLoadingChangePayload, type ViewerLoadingPhase, type ViewerReadyPayload };
738
+ export { type CameraZoomPayload, type ConvertOptions, type ConvertV2Options, type CreatePipelineOptions, type FileInfoCheckInput, type FileInfoCheckPayloadItem, type FilesConfig, type InitialBackground, type InitialToolbarUse, type LanguageCode, type LoadStage, type LoadStatePayload, type MarkupAction, type MarkupListItem, type MarkupOperationResultPayload, type ObjectPropertiesGetOptions, type ObjectPropertiesResult, type PreparedViewerData, type SetBackgroundOptions, Viewer3D, type Viewer3DOptions, type ViewerBackgroundColorInput, type ViewerBackgroundPayload, type ViewerLoadingChangePayload, type ViewerLoadingPhase, type ViewerReadyPayload, type ViewerRgbColor, type ViewerRgbaColor };
package/dist/index.d.ts CHANGED
@@ -23,6 +23,7 @@ declare enum ViewerMessageType {
23
23
  WALK_THROUGH = "viewer-walk-through",
24
24
  ZOOM_WINDOW = "viewer-zoom-window",
25
25
  ZOOM_FIT = "viewer-zoom-fit",
26
+ DISPLAY_SET_BACKGROUND = "viewer-display-set-background",
26
27
  TOOLBAR_CONFIG = "viewer-toolbar-config",
27
28
  TOOLBAR_USE = "viewer-toolbar-use",
28
29
  PANEL_OPEN = "viewer-panel-open",
@@ -59,6 +60,19 @@ type NodeSelectionChangePayload = {
59
60
  nodeIds: string[];
60
61
  timestamp: number;
61
62
  };
63
+ type ViewerRgbColor = {
64
+ r: number;
65
+ g: number;
66
+ b: number;
67
+ };
68
+ type ViewerRgbaColor = ViewerRgbColor & {
69
+ a: number;
70
+ };
71
+ type ViewerBackgroundColorInput = ViewerRgbColor | ViewerRgbaColor | string;
72
+ type ViewerBackgroundPayload = {
73
+ top: ViewerRgbColor;
74
+ bottom?: ViewerRgbColor;
75
+ };
62
76
  type CameraZoomPayload = {
63
77
  requestId?: string;
64
78
  percent: number;
@@ -289,6 +303,22 @@ declare class CameraModule {
289
303
  private postCameraGetZoom;
290
304
  }
291
305
 
306
+ type BackgroundOptionsInput = {
307
+ top: ViewerBackgroundColorInput;
308
+ bottom?: ViewerBackgroundColorInput;
309
+ };
310
+ type InitialBackground = ViewerBackgroundColorInput | BackgroundOptionsInput;
311
+
312
+ type SetBackgroundOptions = BackgroundOptionsInput;
313
+ declare class DisplayModule {
314
+ private viewer;
315
+ constructor(viewer: Viewer3D);
316
+ setBackgroundColor(color: ViewerBackgroundColorInput): void;
317
+ setBackgroundGradient(top: ViewerBackgroundColorInput, bottom: ViewerBackgroundColorInput): void;
318
+ setBackground(options: SetBackgroundOptions): void;
319
+ private postBackground;
320
+ }
321
+
292
322
  declare class InteractionModule {
293
323
  private viewer;
294
324
  on: {
@@ -647,6 +677,7 @@ type Viewer3DOptions = {
647
677
  uploadPath?: string;
648
678
  file?: File;
649
679
  initialToolbar?: InitialToolbarUse;
680
+ initialBackground?: InitialBackground;
650
681
  ui?: {
651
682
  loadingIndicator?: boolean;
652
683
  };
@@ -666,6 +697,7 @@ declare class Viewer3D {
666
697
  private loadingState;
667
698
  private emitter;
668
699
  camera: CameraModule;
700
+ display: DisplayModule;
669
701
  interaction: InteractionModule;
670
702
  node: NodeModule;
671
703
  files: FilesModule;
@@ -691,6 +723,7 @@ declare class Viewer3D {
691
723
  private ensureInit;
692
724
  private withInitialOptions;
693
725
  private normalizeInitialToolbar;
726
+ private normalizeInitialBackground;
694
727
  _on<K extends SdkEventKey>(event: K, cb: (payload: SdkEventPayload<K>) => void): () => void;
695
728
  _off<K extends SdkEventKey>(event: K, cb: (payload: SdkEventPayload<K>) => void): void;
696
729
  _emit<K extends SdkEventKey>(event: K, payload: SdkEventPayload<K>): void;
@@ -702,4 +735,4 @@ declare class Viewer3D {
702
735
  private handleMessage;
703
736
  }
704
737
 
705
- export { type CameraZoomPayload, type ConvertOptions, type ConvertV2Options, type CreatePipelineOptions, type FileInfoCheckInput, type FileInfoCheckPayloadItem, type FilesConfig, type InitialToolbarUse, type LanguageCode, type LoadStage, type LoadStatePayload, type MarkupAction, type MarkupListItem, type MarkupOperationResultPayload, type ObjectPropertiesGetOptions, type ObjectPropertiesResult, type PreparedViewerData, Viewer3D, type Viewer3DOptions, type ViewerLoadingChangePayload, type ViewerLoadingPhase, type ViewerReadyPayload };
738
+ export { type CameraZoomPayload, type ConvertOptions, type ConvertV2Options, type CreatePipelineOptions, type FileInfoCheckInput, type FileInfoCheckPayloadItem, type FilesConfig, type InitialBackground, type InitialToolbarUse, type LanguageCode, type LoadStage, type LoadStatePayload, type MarkupAction, type MarkupListItem, type MarkupOperationResultPayload, type ObjectPropertiesGetOptions, type ObjectPropertiesResult, type PreparedViewerData, type SetBackgroundOptions, Viewer3D, type Viewer3DOptions, type ViewerBackgroundColorInput, type ViewerBackgroundPayload, type ViewerLoadingChangePayload, type ViewerLoadingPhase, type ViewerReadyPayload, type ViewerRgbColor, type ViewerRgbaColor };
package/dist/index.js CHANGED
@@ -99,6 +99,105 @@ var CameraModule = class {
99
99
  }
100
100
  };
101
101
 
102
+ // src/modules/display.shared.ts
103
+ function isBackgroundOptionsInput(value) {
104
+ return typeof value === "object" && value !== null && "top" in value;
105
+ }
106
+ function clampColorChannel(value) {
107
+ if (!Number.isFinite(value)) return 0;
108
+ return Math.min(255, Math.max(0, Math.round(value)));
109
+ }
110
+ function normalizeHexColor(color) {
111
+ const normalized = color.trim();
112
+ const match = normalized.match(/^#?([a-f\d]{3}|[a-f\d]{6})$/i);
113
+ if (!match) {
114
+ throw new Error(
115
+ `Invalid background color "${color}". Use #RGB, #RRGGBB, rgb(...), rgba(...), or { r, g, b }.`
116
+ );
117
+ }
118
+ const hex = match[1].length === 3 ? match[1].split("").map((char) => `${char}${char}`).join("") : match[1];
119
+ return {
120
+ r: Number.parseInt(hex.slice(0, 2), 16),
121
+ g: Number.parseInt(hex.slice(2, 4), 16),
122
+ b: Number.parseInt(hex.slice(4, 6), 16)
123
+ };
124
+ }
125
+ function normalizeFunctionalRgbColor(color) {
126
+ const normalized = color.trim();
127
+ const match = normalized.match(/^rgba?\(\s*([^)]+)\s*\)$/i);
128
+ if (!match) return null;
129
+ const values = match[1].split(",").map((value) => value.trim()).filter((value) => value !== "");
130
+ if (values.length !== 3 && values.length !== 4) {
131
+ throw new Error(
132
+ `Invalid background color "${color}". rgb()/rgba() requires 3 RGB channels and optional alpha.`
133
+ );
134
+ }
135
+ const [r, g, b] = values;
136
+ return {
137
+ r: clampColorChannel(Number(r)),
138
+ g: clampColorChannel(Number(g)),
139
+ b: clampColorChannel(Number(b))
140
+ };
141
+ }
142
+ function normalizeBackgroundColor(color) {
143
+ var _a;
144
+ if (typeof color === "string") {
145
+ return (_a = normalizeFunctionalRgbColor(color)) != null ? _a : normalizeHexColor(color);
146
+ }
147
+ return {
148
+ r: clampColorChannel(color.r),
149
+ g: clampColorChannel(color.g),
150
+ b: clampColorChannel(color.b)
151
+ };
152
+ }
153
+ function normalizeBackgroundOptions(options) {
154
+ return {
155
+ top: normalizeBackgroundColor(options.top),
156
+ bottom: options.bottom === void 0 ? void 0 : normalizeBackgroundColor(options.bottom)
157
+ };
158
+ }
159
+ function normalizeInitialBackground(background) {
160
+ if (isBackgroundOptionsInput(background)) {
161
+ return normalizeBackgroundOptions(background);
162
+ }
163
+ const solidColor = normalizeBackgroundColor(
164
+ background
165
+ );
166
+ return {
167
+ top: solidColor,
168
+ bottom: solidColor
169
+ };
170
+ }
171
+
172
+ // src/modules/display.module.ts
173
+ var DisplayModule = class {
174
+ constructor(viewer) {
175
+ this.viewer = viewer;
176
+ }
177
+ setBackgroundColor(color) {
178
+ const normalizedColor = normalizeBackgroundColor(color);
179
+ this.postBackground({
180
+ top: normalizedColor,
181
+ bottom: normalizedColor
182
+ });
183
+ }
184
+ setBackgroundGradient(top, bottom) {
185
+ this.postBackground({
186
+ top: normalizeBackgroundColor(top),
187
+ bottom: normalizeBackgroundColor(bottom)
188
+ });
189
+ }
190
+ setBackground(options) {
191
+ this.postBackground(normalizeBackgroundOptions(options));
192
+ }
193
+ postBackground(payload) {
194
+ this.viewer.postToViewer(
195
+ "viewer-display-set-background" /* DISPLAY_SET_BACKGROUND */,
196
+ payload
197
+ );
198
+ }
199
+ };
200
+
102
201
  // src/modules/interaction.module.ts
103
202
  var InteractionModule = class {
104
203
  constructor(viewer) {
@@ -1662,6 +1761,7 @@ var Viewer3D = class {
1662
1761
  }
1663
1762
  };
1664
1763
  this.camera = new CameraModule(this);
1764
+ this.display = new DisplayModule(this);
1665
1765
  this.interaction = new InteractionModule(this);
1666
1766
  this.node = new NodeModule(this);
1667
1767
  this.files = new FilesModule(this);
@@ -1789,6 +1889,13 @@ var Viewer3D = class {
1789
1889
  if (((_a = this.options.ui) == null ? void 0 : _a.loadingIndicator) === false) {
1790
1890
  parsedUrl.searchParams.set("loadingIndicator", "false");
1791
1891
  }
1892
+ const initialBackground = this.normalizeInitialBackground();
1893
+ if (initialBackground) {
1894
+ parsedUrl.searchParams.set(
1895
+ "initialBackground",
1896
+ JSON.stringify(initialBackground)
1897
+ );
1898
+ }
1792
1899
  return parsedUrl.toString();
1793
1900
  } catch {
1794
1901
  return url;
@@ -1821,6 +1928,11 @@ var Viewer3D = class {
1821
1928
  {}
1822
1929
  );
1823
1930
  }
1931
+ normalizeInitialBackground() {
1932
+ const initialBackground = this.options.initialBackground;
1933
+ if (!initialBackground) return null;
1934
+ return normalizeInitialBackground(initialBackground);
1935
+ }
1824
1936
  // ===== typed internal events used by modules =====
1825
1937
  _on(event, cb) {
1826
1938
  return this.emitter.on(event, cb);
package/dist/index.mjs CHANGED
@@ -73,6 +73,105 @@ var CameraModule = class {
73
73
  }
74
74
  };
75
75
 
76
+ // src/modules/display.shared.ts
77
+ function isBackgroundOptionsInput(value) {
78
+ return typeof value === "object" && value !== null && "top" in value;
79
+ }
80
+ function clampColorChannel(value) {
81
+ if (!Number.isFinite(value)) return 0;
82
+ return Math.min(255, Math.max(0, Math.round(value)));
83
+ }
84
+ function normalizeHexColor(color) {
85
+ const normalized = color.trim();
86
+ const match = normalized.match(/^#?([a-f\d]{3}|[a-f\d]{6})$/i);
87
+ if (!match) {
88
+ throw new Error(
89
+ `Invalid background color "${color}". Use #RGB, #RRGGBB, rgb(...), rgba(...), or { r, g, b }.`
90
+ );
91
+ }
92
+ const hex = match[1].length === 3 ? match[1].split("").map((char) => `${char}${char}`).join("") : match[1];
93
+ return {
94
+ r: Number.parseInt(hex.slice(0, 2), 16),
95
+ g: Number.parseInt(hex.slice(2, 4), 16),
96
+ b: Number.parseInt(hex.slice(4, 6), 16)
97
+ };
98
+ }
99
+ function normalizeFunctionalRgbColor(color) {
100
+ const normalized = color.trim();
101
+ const match = normalized.match(/^rgba?\(\s*([^)]+)\s*\)$/i);
102
+ if (!match) return null;
103
+ const values = match[1].split(",").map((value) => value.trim()).filter((value) => value !== "");
104
+ if (values.length !== 3 && values.length !== 4) {
105
+ throw new Error(
106
+ `Invalid background color "${color}". rgb()/rgba() requires 3 RGB channels and optional alpha.`
107
+ );
108
+ }
109
+ const [r, g, b] = values;
110
+ return {
111
+ r: clampColorChannel(Number(r)),
112
+ g: clampColorChannel(Number(g)),
113
+ b: clampColorChannel(Number(b))
114
+ };
115
+ }
116
+ function normalizeBackgroundColor(color) {
117
+ var _a;
118
+ if (typeof color === "string") {
119
+ return (_a = normalizeFunctionalRgbColor(color)) != null ? _a : normalizeHexColor(color);
120
+ }
121
+ return {
122
+ r: clampColorChannel(color.r),
123
+ g: clampColorChannel(color.g),
124
+ b: clampColorChannel(color.b)
125
+ };
126
+ }
127
+ function normalizeBackgroundOptions(options) {
128
+ return {
129
+ top: normalizeBackgroundColor(options.top),
130
+ bottom: options.bottom === void 0 ? void 0 : normalizeBackgroundColor(options.bottom)
131
+ };
132
+ }
133
+ function normalizeInitialBackground(background) {
134
+ if (isBackgroundOptionsInput(background)) {
135
+ return normalizeBackgroundOptions(background);
136
+ }
137
+ const solidColor = normalizeBackgroundColor(
138
+ background
139
+ );
140
+ return {
141
+ top: solidColor,
142
+ bottom: solidColor
143
+ };
144
+ }
145
+
146
+ // src/modules/display.module.ts
147
+ var DisplayModule = class {
148
+ constructor(viewer) {
149
+ this.viewer = viewer;
150
+ }
151
+ setBackgroundColor(color) {
152
+ const normalizedColor = normalizeBackgroundColor(color);
153
+ this.postBackground({
154
+ top: normalizedColor,
155
+ bottom: normalizedColor
156
+ });
157
+ }
158
+ setBackgroundGradient(top, bottom) {
159
+ this.postBackground({
160
+ top: normalizeBackgroundColor(top),
161
+ bottom: normalizeBackgroundColor(bottom)
162
+ });
163
+ }
164
+ setBackground(options) {
165
+ this.postBackground(normalizeBackgroundOptions(options));
166
+ }
167
+ postBackground(payload) {
168
+ this.viewer.postToViewer(
169
+ "viewer-display-set-background" /* DISPLAY_SET_BACKGROUND */,
170
+ payload
171
+ );
172
+ }
173
+ };
174
+
76
175
  // src/modules/interaction.module.ts
77
176
  var InteractionModule = class {
78
177
  constructor(viewer) {
@@ -1636,6 +1735,7 @@ var Viewer3D = class {
1636
1735
  }
1637
1736
  };
1638
1737
  this.camera = new CameraModule(this);
1738
+ this.display = new DisplayModule(this);
1639
1739
  this.interaction = new InteractionModule(this);
1640
1740
  this.node = new NodeModule(this);
1641
1741
  this.files = new FilesModule(this);
@@ -1763,6 +1863,13 @@ var Viewer3D = class {
1763
1863
  if (((_a = this.options.ui) == null ? void 0 : _a.loadingIndicator) === false) {
1764
1864
  parsedUrl.searchParams.set("loadingIndicator", "false");
1765
1865
  }
1866
+ const initialBackground = this.normalizeInitialBackground();
1867
+ if (initialBackground) {
1868
+ parsedUrl.searchParams.set(
1869
+ "initialBackground",
1870
+ JSON.stringify(initialBackground)
1871
+ );
1872
+ }
1766
1873
  return parsedUrl.toString();
1767
1874
  } catch {
1768
1875
  return url;
@@ -1795,6 +1902,11 @@ var Viewer3D = class {
1795
1902
  {}
1796
1903
  );
1797
1904
  }
1905
+ normalizeInitialBackground() {
1906
+ const initialBackground = this.options.initialBackground;
1907
+ if (!initialBackground) return null;
1908
+ return normalizeInitialBackground(initialBackground);
1909
+ }
1798
1910
  // ===== typed internal events used by modules =====
1799
1911
  _on(event, cb) {
1800
1912
  return this.emitter.on(event, cb);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "3dviewer-sdk",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [