3dviewer-sdk 1.0.12 → 1.0.14

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.js CHANGED
@@ -145,8 +145,10 @@ var NodeModule = class {
145
145
  };
146
146
 
147
147
  // src/modules/files.module.ts
148
- var DEFAULT_API_BASE_URL = "https://dev.3dviewer.anybim.vn";
148
+ var DEFAULT_API_BASE_URL = "https://dev.3dviewer.anybim.vn/service/conversion";
149
149
  var DEFAULT_VIEWER_ORIGIN = "http://localhost:3000";
150
+ var SDK_VIEWER_PATH = "/mainviewer-sdk";
151
+ var LEGACY_VIEWER_PATH = "/mainviewer";
150
152
  var FilesModule = class {
151
153
  constructor(viewer) {
152
154
  this.viewer = viewer;
@@ -296,12 +298,7 @@ var FilesModule = class {
296
298
  const raw = this.config.baseUrl || this.viewer.getOptions().baseUrl || DEFAULT_API_BASE_URL;
297
299
  return this.normalizeBaseUrl(raw);
298
300
  }
299
- // Resolve conversion API base URL with legacy baseUrl fallback.
300
- resolveConversionBaseUrl() {
301
- const raw = this.config.conversionBaseUrl || this.viewer.getOptions().conversionBaseUrl;
302
- return (raw == null ? void 0 : raw.trim()) ? this.normalizeBaseUrl(raw) : this.resolveBaseUrl();
303
- }
304
- // Resolve viewer route path (e.g. /mainviewer).
301
+ // Resolve viewer route path for all SDK flows.
305
302
  resolveViewerPath() {
306
303
  const configuredPath = this.config.viewerPath || this.viewer.getOptions().viewerPath;
307
304
  if (!configuredPath) {
@@ -309,36 +306,41 @@ var FilesModule = class {
309
306
  if (viewerUrl) {
310
307
  try {
311
308
  const pathname = new URL(viewerUrl, window.location.href).pathname;
312
- if (pathname && pathname !== "/") return pathname;
309
+ if (pathname && pathname !== "/") return this.normalizeSdkViewerPath(pathname);
313
310
  } catch {
314
311
  }
315
312
  }
316
313
  }
317
- const p = (configuredPath || "/mainviewer").trim();
318
- if (!p) return "/mainviewer";
319
- return p.startsWith("/") ? p : `/${p}`;
314
+ return this.normalizeSdkViewerPath(configuredPath || SDK_VIEWER_PATH);
315
+ }
316
+ normalizeSdkViewerPath(path) {
317
+ const p = path.trim();
318
+ if (!p || p === LEGACY_VIEWER_PATH) return SDK_VIEWER_PATH;
319
+ const normalized = p.startsWith("/") ? p : `/${p}`;
320
+ return normalized === LEGACY_VIEWER_PATH ? SDK_VIEWER_PATH : normalized;
320
321
  }
321
322
  // Viewer host used to open iframe after conversion completes.
322
323
  resolveViewerOrigin() {
323
- const configuredBaseUrl = this.config.baseUrl || this.viewer.getOptions().baseUrl;
324
- if (configuredBaseUrl) {
324
+ const viewerUrl = this.viewer.getOptions().url;
325
+ if (viewerUrl) {
325
326
  try {
326
- return this.normalizeBaseUrl(new URL(configuredBaseUrl, window.location.href).origin);
327
+ return this.normalizeBaseUrl(new URL(viewerUrl, window.location.href).origin);
327
328
  } catch {
328
329
  }
329
330
  }
330
- const viewerUrl = this.viewer.getOptions().url;
331
- if (viewerUrl) {
331
+ const configuredBaseUrl = this.config.baseUrl || this.viewer.getOptions().baseUrl;
332
+ if (configuredBaseUrl) {
332
333
  try {
333
- return this.normalizeBaseUrl(new URL(viewerUrl, window.location.href).origin);
334
+ return this.normalizeBaseUrl(new URL(configuredBaseUrl, window.location.href).origin);
334
335
  } catch {
335
336
  }
336
337
  }
337
338
  return this.normalizeBaseUrl(DEFAULT_VIEWER_ORIGIN);
338
339
  }
339
- // Use the configured conversion API root as-is.
340
+ // Resolve conversion service root from configured API base URL.
341
+ // Do not auto-append path segments (e.g. "/service/conversion").
340
342
  resolveHostConversion() {
341
- return this.resolveConversionBaseUrl();
343
+ return this.resolveBaseUrl();
342
344
  }
343
345
  // Resolve upload path sent to conversion APIs.
344
346
  getUploadPath() {
@@ -456,6 +458,8 @@ var FilesModule = class {
456
458
  originalFilePath: options.originalFilePath,
457
459
  convertOptions,
458
460
  downloadUrl: options.downloadUrl,
461
+ workflowId: options.workflowId,
462
+ taskId: options.taskId,
459
463
  baseFileId: options.baseFileId,
460
464
  baseMajorRev: (_a = options.baseMajorRev) != null ? _a : 0,
461
465
  baseMinorRev: (_b = options.baseMinorRev) != null ? _b : 0
@@ -490,11 +494,11 @@ var FilesModule = class {
490
494
  }
491
495
  // Submit conversion request to the newer downloadUrl-based endpoint.
492
496
  async cacheFileV2(options) {
497
+ var _a;
493
498
  const hostConversion = await this.resolveHostConversion();
494
499
  const params = new URLSearchParams();
495
- if (typeof options.overwrite === "boolean") {
496
- params.set("overwrite", String(options.overwrite));
497
- }
500
+ params.set("overwrite", String((_a = options.overwrite) != null ? _a : true));
501
+ params.set("ignore_line_weight", "1");
498
502
  if (options.project) {
499
503
  params.set("project", options.project);
500
504
  }
@@ -587,8 +591,8 @@ var FilesModule = class {
587
591
  };
588
592
 
589
593
  // src/modules/toolbar.module.ts
590
- function createRequestId() {
591
- return `sheets_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
594
+ function createRequestId(prefix) {
595
+ return `${prefix}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
592
596
  }
593
597
  var ALL_3D_TOOLBAR_OPERATORS = [
594
598
  "home",
@@ -674,90 +678,78 @@ var ToolbarModule = class {
674
678
  enableAllPdf() {
675
679
  this.clearDisabledPdf();
676
680
  }
677
- hideToolbar() {
678
- this.setToolbarVisible(false);
681
+ useToolbar(target = "all") {
682
+ this.postToolbarUse({ target });
679
683
  }
680
- showToolbar() {
681
- this.setToolbarVisible(true);
684
+ useLeftToolbar() {
685
+ this.useToolbar("left");
682
686
  }
683
- setToolbarVisible(visible, target = "all") {
684
- this.postToolbarVisibility({ visible, target });
687
+ useCenterToolbar() {
688
+ this.useToolbar("center");
685
689
  }
686
- hideLeftToolbar() {
687
- this.setToolbarVisible(false, "left");
690
+ useRightToolbar() {
691
+ this.useToolbar("right");
688
692
  }
689
- showLeftToolbar() {
690
- this.setToolbarVisible(true, "left");
691
- }
692
- hideCenterToolbar() {
693
- this.setToolbarVisible(false, "center");
694
- }
695
- showCenterToolbar() {
696
- this.setToolbarVisible(true, "center");
697
- }
698
- hideRightToolbar() {
699
- this.setToolbarVisible(false, "right");
700
- }
701
- showRightToolbar() {
702
- this.setToolbarVisible(true, "right");
693
+ usePanel(panel, format) {
694
+ this.postPanelOpen({ panel, format });
703
695
  }
704
696
  openClippingPlanes() {
705
- this.postPanelOpen({ panel: "clipping-commands", format: "3d" });
697
+ this.usePanel("clipping-commands", "3d");
706
698
  }
707
699
  closeClippingPlanes() {
708
700
  this.postPanelClose({ panel: "clipping-commands", format: "3d" });
709
701
  }
710
702
  openSetting() {
711
- this.postPanelOpen({ panel: "setting" });
703
+ this.usePanel("setting");
712
704
  }
713
705
  closeSetting() {
714
706
  this.postPanelClose({ panel: "setting" });
715
707
  }
716
708
  openSetting3D() {
717
- this.postPanelOpen({ panel: "setting", format: "3d" });
709
+ this.usePanel("setting", "3d");
718
710
  }
719
711
  closeSetting3D() {
720
712
  this.postPanelClose({ panel: "setting", format: "3d" });
721
713
  }
722
714
  openSettingPdf() {
723
- this.postPanelOpen({ panel: "setting", format: "pdf" });
715
+ this.usePanel("setting", "pdf");
724
716
  }
725
717
  closeSettingPdf() {
726
718
  this.postPanelClose({ panel: "setting", format: "pdf" });
727
719
  }
728
720
  openStatesObjects() {
729
- this.postPanelOpen({ panel: "statesObjects", format: "3d" });
721
+ this.usePanel("statesObjects", "3d");
730
722
  }
731
723
  closeStatesObjects() {
732
724
  this.postPanelClose({ panel: "statesObjects", format: "3d" });
733
725
  }
734
726
  openLinkedObjects() {
735
- this.postPanelOpen({ panel: "linkedObjects", format: "3d" });
727
+ this.usePanel("linkedObjects", "3d");
736
728
  }
737
729
  closeLinkedObjects() {
738
730
  this.postPanelClose({ panel: "linkedObjects", format: "3d" });
739
731
  }
740
732
  openModelTree() {
741
- this.postPanelOpen({ panel: "model-tree", format: "3d" });
733
+ this.usePanel("model-tree", "3d");
742
734
  }
743
735
  closeModelTree() {
744
736
  this.postPanelClose({ panel: "model-tree", format: "3d" });
745
737
  }
746
738
  openObjectProperties() {
747
- this.postPanelOpen({ panel: "object-properties", format: "3d" });
739
+ this.usePanel("object-properties", "3d");
748
740
  }
749
741
  closeObjectProperties() {
750
742
  this.postPanelClose({ panel: "object-properties", format: "3d" });
751
743
  }
752
744
  openSheets() {
753
- this.postPanelOpen({ panel: "sheets", format: "3d" });
745
+ this.usePanel("sheets", "3d");
754
746
  }
755
747
  closeSheets() {
756
748
  this.postPanelClose({ panel: "sheets", format: "3d" });
757
749
  }
758
750
  getSheets(options) {
759
751
  var _a;
760
- const requestId = createRequestId();
752
+ const requestId = createRequestId("sheets");
761
753
  const timeoutMs = Math.max(1e3, (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : 1e4);
762
754
  return new Promise((resolve, reject) => {
763
755
  const timer = setTimeout(() => {
@@ -773,6 +765,60 @@ var ToolbarModule = class {
773
765
  this.postSheetsGetList({ requestId });
774
766
  });
775
767
  }
768
+ getObjectProperties(options) {
769
+ var _a;
770
+ const requestId = createRequestId("object_properties");
771
+ const timeoutMs = Math.max(1e3, (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : 1e4);
772
+ return new Promise((resolve, reject) => {
773
+ const timer = setTimeout(() => {
774
+ off();
775
+ reject(new Error("Timeout while getting object properties list from viewer"));
776
+ }, timeoutMs);
777
+ const off = this.viewer._on("object-properties:list", (payload) => {
778
+ if (payload.requestId !== requestId) return;
779
+ clearTimeout(timer);
780
+ off();
781
+ resolve(payload.properties);
782
+ });
783
+ this.postObjectPropertiesGetList({ requestId });
784
+ });
785
+ }
786
+ getLinkedObjects(options) {
787
+ var _a;
788
+ const requestId = createRequestId("linked_objects");
789
+ const timeoutMs = Math.max(1e3, (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : 1e4);
790
+ return new Promise((resolve, reject) => {
791
+ const timer = setTimeout(() => {
792
+ off();
793
+ reject(new Error("Timeout while getting linked objects list from viewer"));
794
+ }, timeoutMs);
795
+ const off = this.viewer._on("linked-objects:list", (payload) => {
796
+ if (payload.requestId !== requestId) return;
797
+ clearTimeout(timer);
798
+ off();
799
+ resolve(payload.linkedObjects);
800
+ });
801
+ this.postLinkedObjectsGetList({ requestId });
802
+ });
803
+ }
804
+ getStatesObjects(options) {
805
+ var _a;
806
+ const requestId = createRequestId("states_objects");
807
+ const timeoutMs = Math.max(1e3, (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : 1e4);
808
+ return new Promise((resolve, reject) => {
809
+ const timer = setTimeout(() => {
810
+ off();
811
+ reject(new Error("Timeout while getting states objects list from viewer"));
812
+ }, timeoutMs);
813
+ const off = this.viewer._on("states-objects:list", (payload) => {
814
+ if (payload.requestId !== requestId) return;
815
+ clearTimeout(timer);
816
+ off();
817
+ resolve(payload.statesObjects);
818
+ });
819
+ this.postStatesObjectsGetList({ requestId });
820
+ });
821
+ }
776
822
  applySheet(sheetId) {
777
823
  this.postSheetsApply({ sheetId });
778
824
  }
@@ -815,8 +861,8 @@ var ToolbarModule = class {
815
861
  postConfig(payload) {
816
862
  this.viewer.postToViewer("viewer-toolbar-config" /* TOOLBAR_CONFIG */, payload);
817
863
  }
818
- postToolbarVisibility(payload) {
819
- this.viewer.postToViewer("viewer-toolbar-visibility" /* TOOLBAR_VISIBILITY */, payload);
864
+ postToolbarUse(payload) {
865
+ this.viewer.postToViewer("viewer-toolbar-use" /* TOOLBAR_USE */, payload);
820
866
  }
821
867
  postPanelOpen(payload) {
822
868
  this.viewer.postToViewer("viewer-panel-open" /* PANEL_OPEN */, payload);
@@ -833,6 +879,15 @@ var ToolbarModule = class {
833
879
  postSheetsApply(payload) {
834
880
  this.viewer.postToViewer("viewer-sheets-apply" /* SHEETS_APPLY */, payload);
835
881
  }
882
+ postObjectPropertiesGetList(payload) {
883
+ this.viewer.postToViewer("viewer-object-properties-get-list" /* OBJECT_PROPERTIES_GET_LIST */, payload);
884
+ }
885
+ postLinkedObjectsGetList(payload) {
886
+ this.viewer.postToViewer("viewer-linked-objects-get-list" /* LINKED_OBJECTS_GET_LIST */, payload);
887
+ }
888
+ postStatesObjectsGetList(payload) {
889
+ this.viewer.postToViewer("viewer-states-objects-get-list" /* STATES_OBJECTS_GET_LIST */, payload);
890
+ }
836
891
  };
837
892
 
838
893
  // src/modules/model-tree.module.ts
@@ -989,6 +1044,8 @@ var LanguageModule = class {
989
1044
  };
990
1045
 
991
1046
  // src/viewer.ts
1047
+ var SDK_VIEWER_PATH2 = "/mainviewer-sdk";
1048
+ var LEGACY_VIEWER_PATH2 = "/mainviewer";
992
1049
  var Viewer3D = class {
993
1050
  constructor(options) {
994
1051
  this.options = options;
@@ -1093,6 +1150,54 @@ var Viewer3D = class {
1093
1150
  });
1094
1151
  break;
1095
1152
  }
1153
+ case "viewer-object-properties-list" /* OBJECT_PROPERTIES_LIST */: {
1154
+ const payload = data.payload;
1155
+ if (!payload || !payload.requestId || !Array.isArray(payload.properties)) break;
1156
+ this._emit("object-properties:list", {
1157
+ requestId: String(payload.requestId),
1158
+ properties: payload.properties.filter((item) => item && typeof item === "object").map((item) => ({ ...item })),
1159
+ timestamp: Number(payload.timestamp) || Date.now()
1160
+ });
1161
+ break;
1162
+ }
1163
+ case "viewer-linked-objects-list" /* LINKED_OBJECTS_LIST */: {
1164
+ const payload = data.payload;
1165
+ if (!payload || !payload.requestId || !Array.isArray(payload.linkedObjects)) break;
1166
+ this._emit("linked-objects:list", {
1167
+ requestId: String(payload.requestId),
1168
+ linkedObjects: payload.linkedObjects.filter((item) => item && typeof item === "object").map((item) => ({ ...item })),
1169
+ timestamp: Number(payload.timestamp) || Date.now()
1170
+ });
1171
+ break;
1172
+ }
1173
+ case "viewer-states-objects-list" /* STATES_OBJECTS_LIST */: {
1174
+ const payload = data.payload;
1175
+ if (!payload || !payload.requestId || !Array.isArray(payload.statesObjects)) break;
1176
+ this._emit("states-objects:list", {
1177
+ requestId: String(payload.requestId),
1178
+ statesObjects: payload.statesObjects.map((item) => {
1179
+ var _a2, _b2, _c2, _d2, _e, _f, _g;
1180
+ return {
1181
+ id: String((_a2 = item.id) != null ? _a2 : ""),
1182
+ name: String((_b2 = item.name) != null ? _b2 : ""),
1183
+ char: String((_c2 = item.char) != null ? _c2 : ""),
1184
+ object: Array.isArray(item.object) ? item.object.map((objectItem) => {
1185
+ var _a3;
1186
+ return {
1187
+ name: String((_a3 = objectItem == null ? void 0 : objectItem.name) != null ? _a3 : ""),
1188
+ id: Number(objectItem == null ? void 0 : objectItem.id) || 0
1189
+ };
1190
+ }) : [],
1191
+ states: {
1192
+ color: String((_e = (_d2 = item.states) == null ? void 0 : _d2.color) != null ? _e : ""),
1193
+ type: String((_g = (_f = item.states) == null ? void 0 : _f.type) != null ? _g : "")
1194
+ }
1195
+ };
1196
+ }),
1197
+ timestamp: Number(payload.timestamp) || Date.now()
1198
+ });
1199
+ break;
1200
+ }
1096
1201
  case "viewer-markup-list" /* MARKUP_LIST */: {
1097
1202
  const payload = data.payload;
1098
1203
  if (!payload || !payload.requestId || !Array.isArray(payload.markups)) break;
@@ -1212,18 +1317,39 @@ var Viewer3D = class {
1212
1317
  if (!this.initialized) throw new Error("Call viewer.init() before using viewer");
1213
1318
  }
1214
1319
  withInitialOptions(url) {
1215
- if (!this.options.initialToolbarVisibility) return url;
1216
1320
  try {
1217
1321
  const parsedUrl = new URL(url, window.location.href);
1218
- parsedUrl.searchParams.set(
1219
- "toolbarVisibility",
1220
- JSON.stringify(this.options.initialToolbarVisibility)
1221
- );
1322
+ if (parsedUrl.pathname === LEGACY_VIEWER_PATH2) {
1323
+ parsedUrl.pathname = SDK_VIEWER_PATH2;
1324
+ }
1325
+ const initialToolbar = this.normalizeInitialToolbar();
1326
+ if (initialToolbar) {
1327
+ parsedUrl.searchParams.set("useToolbar", JSON.stringify(initialToolbar));
1328
+ }
1222
1329
  return parsedUrl.toString();
1223
1330
  } catch {
1224
1331
  return url;
1225
1332
  }
1226
1333
  }
1334
+ normalizeInitialToolbar() {
1335
+ const initialToolbar = this.options.initialToolbar;
1336
+ if (!initialToolbar) return null;
1337
+ if (typeof initialToolbar === "string") {
1338
+ return { [initialToolbar]: true };
1339
+ }
1340
+ if (Array.isArray(initialToolbar)) {
1341
+ return initialToolbar.reduce((result, target) => {
1342
+ result[target] = true;
1343
+ return result;
1344
+ }, {});
1345
+ }
1346
+ const entries = Object.entries(initialToolbar).filter(([, enabled]) => enabled === true);
1347
+ if (entries.length === 0) return null;
1348
+ return entries.reduce((result, [target]) => {
1349
+ result[target] = true;
1350
+ return result;
1351
+ }, {});
1352
+ }
1227
1353
  // ===== typed internal events used by modules =====
1228
1354
  _on(event, cb) {
1229
1355
  return this.emitter.on(event, cb);