3dviewer-sdk 1.0.10 → 1.0.12

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
@@ -270,6 +270,11 @@ var FilesModule = class {
270
270
  const raw = this.config.baseUrl || this.viewer.getOptions().baseUrl || DEFAULT_API_BASE_URL;
271
271
  return this.normalizeBaseUrl(raw);
272
272
  }
273
+ // Resolve conversion API base URL with legacy baseUrl fallback.
274
+ resolveConversionBaseUrl() {
275
+ const raw = this.config.conversionBaseUrl || this.viewer.getOptions().conversionBaseUrl;
276
+ return (raw == null ? void 0 : raw.trim()) ? this.normalizeBaseUrl(raw) : this.resolveBaseUrl();
277
+ }
273
278
  // Resolve viewer route path (e.g. /mainviewer).
274
279
  resolveViewerPath() {
275
280
  const configuredPath = this.config.viewerPath || this.viewer.getOptions().viewerPath;
@@ -289,6 +294,13 @@ var FilesModule = class {
289
294
  }
290
295
  // Viewer host used to open iframe after conversion completes.
291
296
  resolveViewerOrigin() {
297
+ const configuredBaseUrl = this.config.baseUrl || this.viewer.getOptions().baseUrl;
298
+ if (configuredBaseUrl) {
299
+ try {
300
+ return this.normalizeBaseUrl(new URL(configuredBaseUrl, window.location.href).origin);
301
+ } catch {
302
+ }
303
+ }
292
304
  const viewerUrl = this.viewer.getOptions().url;
293
305
  if (viewerUrl) {
294
306
  try {
@@ -298,10 +310,9 @@ var FilesModule = class {
298
310
  }
299
311
  return this.normalizeBaseUrl(DEFAULT_VIEWER_ORIGIN);
300
312
  }
301
- // Build conversion service root from API base URL.
313
+ // Use the configured conversion API root as-is.
302
314
  resolveHostConversion() {
303
- const baseUrl = this.resolveBaseUrl();
304
- return baseUrl.endsWith("/service/conversion") ? baseUrl : `${baseUrl}/service/conversion`;
315
+ return this.resolveConversionBaseUrl();
305
316
  }
306
317
  // Resolve upload path sent to conversion APIs.
307
318
  getUploadPath() {
@@ -1139,7 +1150,7 @@ var Viewer3D = class {
1139
1150
  if (this.iframeEl) return;
1140
1151
  if (!this.options.url) return this.files.render(file);
1141
1152
  const iframe = document.createElement("iframe");
1142
- iframe.src = this.options.url;
1153
+ iframe.src = this.withInitialOptions(this.options.url);
1143
1154
  iframe.style.border = "none";
1144
1155
  iframe.style.width = this.options.width || "100%";
1145
1156
  iframe.style.height = this.options.height || "100%";
@@ -1152,11 +1163,12 @@ var Viewer3D = class {
1152
1163
  open(url) {
1153
1164
  this.ensureInit();
1154
1165
  this.options.url = url;
1166
+ const finalUrl = this.withInitialOptions(url);
1155
1167
  if (!this.iframeEl) {
1156
1168
  this.render();
1157
1169
  return;
1158
1170
  }
1159
- this.iframeEl.src = url;
1171
+ this.iframeEl.src = finalUrl;
1160
1172
  }
1161
1173
  destroy() {
1162
1174
  window.removeEventListener("message", this.handleMessage);
@@ -1173,6 +1185,19 @@ var Viewer3D = class {
1173
1185
  ensureInit() {
1174
1186
  if (!this.initialized) throw new Error("Call viewer.init() before using viewer");
1175
1187
  }
1188
+ withInitialOptions(url) {
1189
+ if (!this.options.initialToolbarVisibility) return url;
1190
+ try {
1191
+ const parsedUrl = new URL(url, window.location.href);
1192
+ parsedUrl.searchParams.set(
1193
+ "toolbarVisibility",
1194
+ JSON.stringify(this.options.initialToolbarVisibility)
1195
+ );
1196
+ return parsedUrl.toString();
1197
+ } catch {
1198
+ return url;
1199
+ }
1200
+ }
1176
1201
  // ===== typed internal events used by modules =====
1177
1202
  _on(event, cb) {
1178
1203
  return this.emitter.on(event, cb);
package/dist/viewer.d.ts CHANGED
@@ -7,7 +7,8 @@ import { ToolbarModule } from "./modules/toolbar.module";
7
7
  import { ModelTreeModule } from "./modules/model-tree.module";
8
8
  import { MarkupModule } from "./modules/markup.module";
9
9
  import { LanguageModule } from "./modules/language.module";
10
- import { ViewerMessageType } from "./contracts/messages";
10
+ import { ViewerMessageType, type ToolbarVisibilityTarget } from "./contracts/messages";
11
+ export declare type InitialToolbarVisibility = Partial<Record<ToolbarVisibilityTarget, boolean>>;
11
12
  export declare type Viewer3DOptions = {
12
13
  container: HTMLElement | string;
13
14
  url?: string;
@@ -15,6 +16,7 @@ export declare type Viewer3DOptions = {
15
16
  viewerPath?: string;
16
17
  uploadPath?: string;
17
18
  file?: File;
19
+ initialToolbarVisibility?: InitialToolbarVisibility;
18
20
  width?: string;
19
21
  height?: string;
20
22
  sandbox?: string;
@@ -43,6 +45,7 @@ export declare class Viewer3D {
43
45
  open(url: string): void;
44
46
  destroy(): void;
45
47
  private ensureInit;
48
+ private withInitialOptions;
46
49
  _on<K extends SdkEventKey>(event: K, cb: (payload: SdkEventPayload<K>) => void): () => void;
47
50
  _off<K extends SdkEventKey>(event: K, cb: (payload: SdkEventPayload<K>) => void): void;
48
51
  _emit<K extends SdkEventKey>(event: K, payload: SdkEventPayload<K>): void;
package/dist/viewer.js CHANGED
@@ -211,7 +211,7 @@ export class Viewer3D {
211
211
  if (!this.options.url)
212
212
  return this.files.render(file);
213
213
  const iframe = document.createElement("iframe");
214
- iframe.src = this.options.url;
214
+ iframe.src = this.withInitialOptions(this.options.url);
215
215
  iframe.style.border = "none";
216
216
  iframe.style.width = this.options.width || "100%";
217
217
  iframe.style.height = this.options.height || "100%";
@@ -225,11 +225,12 @@ export class Viewer3D {
225
225
  open(url) {
226
226
  this.ensureInit();
227
227
  this.options.url = url;
228
+ const finalUrl = this.withInitialOptions(url);
228
229
  if (!this.iframeEl) {
229
230
  this.render();
230
231
  return;
231
232
  }
232
- this.iframeEl.src = url;
233
+ this.iframeEl.src = finalUrl;
233
234
  }
234
235
  destroy() {
235
236
  // remove listener using the same function reference
@@ -251,6 +252,18 @@ export class Viewer3D {
251
252
  if (!this.initialized)
252
253
  throw new Error("Call viewer.init() before using viewer");
253
254
  }
255
+ withInitialOptions(url) {
256
+ if (!this.options.initialToolbarVisibility)
257
+ return url;
258
+ try {
259
+ const parsedUrl = new URL(url, window.location.href);
260
+ parsedUrl.searchParams.set("toolbarVisibility", JSON.stringify(this.options.initialToolbarVisibility));
261
+ return parsedUrl.toString();
262
+ }
263
+ catch {
264
+ return url;
265
+ }
266
+ }
254
267
  // ===== typed internal events used by modules =====
255
268
  _on(event, cb) {
256
269
  return this.emitter.on(event, cb);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "3dviewer-sdk",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [