3dviewer-sdk 1.0.17 → 1.0.18

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
@@ -1,6 +1,8 @@
1
1
  declare enum ViewerMessageType {
2
2
  LANGUAGE_CHANGE = "viewer-language-change",
3
3
  ZOOM = "viewer-zoom",
4
+ CAMERA_GET_ZOOM = "viewer-camera-get-zoom",
5
+ CAMERA_ZOOM = "viewer-camera-zoom",
4
6
  DRAW_MODE = "viewer-draw-mode",
5
7
  EXPLODE = "viewer-explode",
6
8
  MARKUP_ACTION = "viewer-markup-action",
@@ -50,6 +52,12 @@ declare enum ViewerMessageType {
50
52
  PAN_CHANGE = "viewer-pan-change"
51
53
  }
52
54
  type LanguageCode = "en" | "vn";
55
+ type CameraZoomPayload = {
56
+ requestId?: string;
57
+ percent: number;
58
+ zoomFactor: number;
59
+ timestamp: number;
60
+ };
53
61
  type ToolbarUseTarget = "all" | "left" | "center" | "right";
54
62
  type MarkupAction = "line" | "arrow" | "circle" | "ellipse" | "rectangle" | "polygon" | "polyline" | "textbox" | "note" | "callout" | "cloud" | "freehand";
55
63
  type MarkupOperationResultPayload = {
@@ -123,6 +131,7 @@ type ViewerEventMap = {
123
131
  "camera:home": {
124
132
  timestamp: number;
125
133
  };
134
+ "camera:zoom": CameraZoomPayload;
126
135
  "node:select": {
127
136
  nodeId: string;
128
137
  timestamp: number;
@@ -237,17 +246,23 @@ type SdkEventMap = ViewerEventMap & FilesEventMap;
237
246
  type SdkEventKey = keyof SdkEventMap;
238
247
  type SdkEventPayload<K extends SdkEventKey> = SdkEventMap[K];
239
248
 
249
+ type GetZoomOptions = {
250
+ timeoutMs?: number;
251
+ };
240
252
  declare class CameraModule {
241
253
  private viewer;
242
254
  on: {
243
255
  home: (cb: (payload: {
244
256
  timestamp: number;
245
257
  }) => void) => () => void;
258
+ zoom: (cb: (payload: CameraZoomPayload) => void) => () => void;
246
259
  };
247
260
  constructor(viewer: Viewer3D);
248
261
  zoomIn(percent: number): void;
249
262
  zoomOut(percent: number): void;
250
263
  home(): void;
264
+ getZoom(options?: GetZoomOptions): Promise<CameraZoomPayload>;
265
+ private postCameraGetZoom;
251
266
  }
252
267
 
253
268
  declare class InteractionModule {
@@ -601,4 +616,4 @@ declare class Viewer3D {
601
616
  private handleMessage;
602
617
  }
603
618
 
604
- export { type ConvertOptions, type ConvertV2Options, type FileInfoCheckInput, type FileInfoCheckPayloadItem, type FilesConfig, type InitialToolbarUse, type LanguageCode, type LoadStage, type LoadStatePayload, type MarkupAction, type MarkupListItem, type MarkupOperationResultPayload, type PreparedViewerData, Viewer3D };
619
+ export { type CameraZoomPayload, type ConvertOptions, type ConvertV2Options, type FileInfoCheckInput, type FileInfoCheckPayloadItem, type FilesConfig, type InitialToolbarUse, type LanguageCode, type LoadStage, type LoadStatePayload, type MarkupAction, type MarkupListItem, type MarkupOperationResultPayload, type PreparedViewerData, Viewer3D };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  declare enum ViewerMessageType {
2
2
  LANGUAGE_CHANGE = "viewer-language-change",
3
3
  ZOOM = "viewer-zoom",
4
+ CAMERA_GET_ZOOM = "viewer-camera-get-zoom",
5
+ CAMERA_ZOOM = "viewer-camera-zoom",
4
6
  DRAW_MODE = "viewer-draw-mode",
5
7
  EXPLODE = "viewer-explode",
6
8
  MARKUP_ACTION = "viewer-markup-action",
@@ -50,6 +52,12 @@ declare enum ViewerMessageType {
50
52
  PAN_CHANGE = "viewer-pan-change"
51
53
  }
52
54
  type LanguageCode = "en" | "vn";
55
+ type CameraZoomPayload = {
56
+ requestId?: string;
57
+ percent: number;
58
+ zoomFactor: number;
59
+ timestamp: number;
60
+ };
53
61
  type ToolbarUseTarget = "all" | "left" | "center" | "right";
54
62
  type MarkupAction = "line" | "arrow" | "circle" | "ellipse" | "rectangle" | "polygon" | "polyline" | "textbox" | "note" | "callout" | "cloud" | "freehand";
55
63
  type MarkupOperationResultPayload = {
@@ -123,6 +131,7 @@ type ViewerEventMap = {
123
131
  "camera:home": {
124
132
  timestamp: number;
125
133
  };
134
+ "camera:zoom": CameraZoomPayload;
126
135
  "node:select": {
127
136
  nodeId: string;
128
137
  timestamp: number;
@@ -237,17 +246,23 @@ type SdkEventMap = ViewerEventMap & FilesEventMap;
237
246
  type SdkEventKey = keyof SdkEventMap;
238
247
  type SdkEventPayload<K extends SdkEventKey> = SdkEventMap[K];
239
248
 
249
+ type GetZoomOptions = {
250
+ timeoutMs?: number;
251
+ };
240
252
  declare class CameraModule {
241
253
  private viewer;
242
254
  on: {
243
255
  home: (cb: (payload: {
244
256
  timestamp: number;
245
257
  }) => void) => () => void;
258
+ zoom: (cb: (payload: CameraZoomPayload) => void) => () => void;
246
259
  };
247
260
  constructor(viewer: Viewer3D);
248
261
  zoomIn(percent: number): void;
249
262
  zoomOut(percent: number): void;
250
263
  home(): void;
264
+ getZoom(options?: GetZoomOptions): Promise<CameraZoomPayload>;
265
+ private postCameraGetZoom;
251
266
  }
252
267
 
253
268
  declare class InteractionModule {
@@ -601,4 +616,4 @@ declare class Viewer3D {
601
616
  private handleMessage;
602
617
  }
603
618
 
604
- export { type ConvertOptions, type ConvertV2Options, type FileInfoCheckInput, type FileInfoCheckPayloadItem, type FilesConfig, type InitialToolbarUse, type LanguageCode, type LoadStage, type LoadStatePayload, type MarkupAction, type MarkupListItem, type MarkupOperationResultPayload, type PreparedViewerData, Viewer3D };
619
+ export { type CameraZoomPayload, type ConvertOptions, type ConvertV2Options, type FileInfoCheckInput, type FileInfoCheckPayloadItem, type FilesConfig, type InitialToolbarUse, type LanguageCode, type LoadStage, type LoadStatePayload, type MarkupAction, type MarkupListItem, type MarkupOperationResultPayload, type PreparedViewerData, Viewer3D };
package/dist/index.js CHANGED
@@ -54,11 +54,18 @@ var Emitter = class {
54
54
  };
55
55
 
56
56
  // src/modules/camera.module.ts
57
+ function createRequestId(prefix) {
58
+ return `${prefix}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
59
+ }
60
+ function resolveTimeoutMs(timeoutMs) {
61
+ return Math.max(1e3, timeoutMs != null ? timeoutMs : 1e4);
62
+ }
57
63
  var CameraModule = class {
58
64
  constructor(viewer) {
59
65
  this.viewer = viewer;
60
66
  this.on = {
61
- home: (cb) => this.viewer._on("camera:home", cb)
67
+ home: (cb) => this.viewer._on("camera:home", cb),
68
+ zoom: (cb) => this.viewer._on("camera:zoom", cb)
62
69
  };
63
70
  }
64
71
  zoomIn(percent) {
@@ -70,6 +77,26 @@ var CameraModule = class {
70
77
  home() {
71
78
  this.viewer.postToViewer("viewer-home" /* HOME */, {});
72
79
  }
80
+ getZoom(options) {
81
+ const requestId = createRequestId("camera_zoom");
82
+ const timeoutMs = resolveTimeoutMs(options == null ? void 0 : options.timeoutMs);
83
+ return new Promise((resolve, reject) => {
84
+ const timer = setTimeout(() => {
85
+ off();
86
+ reject(new Error("Timeout while getting camera zoom state from viewer"));
87
+ }, timeoutMs);
88
+ const off = this.viewer._on("camera:zoom", (payload) => {
89
+ if (payload.requestId !== requestId) return;
90
+ clearTimeout(timer);
91
+ off();
92
+ resolve(payload);
93
+ });
94
+ this.postCameraGetZoom({ requestId });
95
+ });
96
+ }
97
+ postCameraGetZoom(payload) {
98
+ this.viewer.postToViewer("viewer-camera-get-zoom" /* CAMERA_GET_ZOOM */, payload);
99
+ }
73
100
  };
74
101
 
75
102
  // src/modules/interaction.module.ts
@@ -588,7 +615,7 @@ var FilesModule = class {
588
615
  };
589
616
 
590
617
  // src/modules/toolbar.module.ts
591
- function createRequestId(prefix) {
618
+ function createRequestId2(prefix) {
592
619
  return `${prefix}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
593
620
  }
594
621
  var ALL_3D_TOOLBAR_OPERATORS = [
@@ -746,7 +773,7 @@ var ToolbarModule = class {
746
773
  }
747
774
  getSheets(options) {
748
775
  var _a;
749
- const requestId = createRequestId("sheets");
776
+ const requestId = createRequestId2("sheets");
750
777
  const timeoutMs = Math.max(1e3, (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : 1e4);
751
778
  return new Promise((resolve, reject) => {
752
779
  const timer = setTimeout(() => {
@@ -764,7 +791,7 @@ var ToolbarModule = class {
764
791
  }
765
792
  getObjectProperties(options) {
766
793
  var _a;
767
- const requestId = createRequestId("object_properties");
794
+ const requestId = createRequestId2("object_properties");
768
795
  const timeoutMs = Math.max(1e3, (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : 1e4);
769
796
  return new Promise((resolve, reject) => {
770
797
  const timer = setTimeout(() => {
@@ -782,7 +809,7 @@ var ToolbarModule = class {
782
809
  }
783
810
  getLinkedObjects(options) {
784
811
  var _a;
785
- const requestId = createRequestId("linked_objects");
812
+ const requestId = createRequestId2("linked_objects");
786
813
  const timeoutMs = Math.max(1e3, (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : 1e4);
787
814
  return new Promise((resolve, reject) => {
788
815
  const timer = setTimeout(() => {
@@ -800,7 +827,7 @@ var ToolbarModule = class {
800
827
  }
801
828
  getStatesObjects(options) {
802
829
  var _a;
803
- const requestId = createRequestId("states_objects");
830
+ const requestId = createRequestId2("states_objects");
804
831
  const timeoutMs = Math.max(1e3, (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : 1e4);
805
832
  return new Promise((resolve, reject) => {
806
833
  const timer = setTimeout(() => {
@@ -888,7 +915,7 @@ var ToolbarModule = class {
888
915
  };
889
916
 
890
917
  // src/modules/model-tree.module.ts
891
- function createRequestId2(prefix) {
918
+ function createRequestId3(prefix) {
892
919
  return `${prefix}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
893
920
  }
894
921
  function buildTree(nodes, rootNodeIds) {
@@ -936,7 +963,7 @@ var ModelTreeModule = class {
936
963
  });
937
964
  }
938
965
  getNodeIds(options) {
939
- const requestId = createRequestId2("tree");
966
+ const requestId = createRequestId3("tree");
940
967
  const timeoutMs = this.resolveTimeoutMs(options);
941
968
  return new Promise((resolve, reject) => {
942
969
  const timer = setTimeout(() => {
@@ -962,7 +989,7 @@ var ModelTreeModule = class {
962
989
  return this.requestNodes(options).then((response) => buildTree(response.nodes, response.rootNodeIds));
963
990
  }
964
991
  requestNodes(options) {
965
- const requestId = createRequestId2("tree_nodes");
992
+ const requestId = createRequestId3("tree_nodes");
966
993
  const timeoutMs = this.resolveTimeoutMs(options);
967
994
  return new Promise((resolve, reject) => {
968
995
  const timer = setTimeout(() => {
@@ -1004,7 +1031,7 @@ var ModelTreeModule = class {
1004
1031
  };
1005
1032
 
1006
1033
  // src/modules/markup.module.ts
1007
- function createRequestId3(prefix) {
1034
+ function createRequestId4(prefix) {
1008
1035
  return `${prefix}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
1009
1036
  }
1010
1037
  var MarkupModule = class {
@@ -1058,7 +1085,7 @@ var MarkupModule = class {
1058
1085
  }
1059
1086
  getList(options) {
1060
1087
  var _a;
1061
- const requestId = createRequestId3("markup-list");
1088
+ const requestId = createRequestId4("markup-list");
1062
1089
  const timeoutMs = Math.max(1e3, (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : 1e4);
1063
1090
  return new Promise((resolve, reject) => {
1064
1091
  const timer = setTimeout(() => {
@@ -1076,7 +1103,7 @@ var MarkupModule = class {
1076
1103
  }
1077
1104
  runRequest(prefix, messageType, eventName, options) {
1078
1105
  var _a;
1079
- const requestId = createRequestId3(prefix);
1106
+ const requestId = createRequestId4(prefix);
1080
1107
  const timeoutMs = Math.max(1e3, (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : 1e4);
1081
1108
  return new Promise((resolve, reject) => {
1082
1109
  const timer = setTimeout(() => {
@@ -1132,6 +1159,17 @@ var Viewer3D = class {
1132
1159
  case "viewer-home-click" /* HOME_CLICK */:
1133
1160
  this._emit("camera:home", { timestamp: Date.now() });
1134
1161
  break;
1162
+ case "viewer-camera-zoom" /* CAMERA_ZOOM */: {
1163
+ const payload = data.payload;
1164
+ if (!payload) break;
1165
+ this._emit("camera:zoom", {
1166
+ requestId: payload.requestId ? String(payload.requestId) : void 0,
1167
+ percent: Number(payload.percent) || 0,
1168
+ zoomFactor: Number(payload.zoomFactor) || 1,
1169
+ timestamp: Number(payload.timestamp) || Date.now()
1170
+ });
1171
+ break;
1172
+ }
1135
1173
  case "viewer-node-select" /* NODE_SELECT */:
1136
1174
  this._emit("node:select", { nodeId: String((_b = (_a = data.payload) == null ? void 0 : _a.nodeId) != null ? _b : ""), timestamp: Date.now() });
1137
1175
  break;
package/dist/index.mjs CHANGED
@@ -28,11 +28,18 @@ var Emitter = class {
28
28
  };
29
29
 
30
30
  // src/modules/camera.module.ts
31
+ function createRequestId(prefix) {
32
+ return `${prefix}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
33
+ }
34
+ function resolveTimeoutMs(timeoutMs) {
35
+ return Math.max(1e3, timeoutMs != null ? timeoutMs : 1e4);
36
+ }
31
37
  var CameraModule = class {
32
38
  constructor(viewer) {
33
39
  this.viewer = viewer;
34
40
  this.on = {
35
- home: (cb) => this.viewer._on("camera:home", cb)
41
+ home: (cb) => this.viewer._on("camera:home", cb),
42
+ zoom: (cb) => this.viewer._on("camera:zoom", cb)
36
43
  };
37
44
  }
38
45
  zoomIn(percent) {
@@ -44,6 +51,26 @@ var CameraModule = class {
44
51
  home() {
45
52
  this.viewer.postToViewer("viewer-home" /* HOME */, {});
46
53
  }
54
+ getZoom(options) {
55
+ const requestId = createRequestId("camera_zoom");
56
+ const timeoutMs = resolveTimeoutMs(options == null ? void 0 : options.timeoutMs);
57
+ return new Promise((resolve, reject) => {
58
+ const timer = setTimeout(() => {
59
+ off();
60
+ reject(new Error("Timeout while getting camera zoom state from viewer"));
61
+ }, timeoutMs);
62
+ const off = this.viewer._on("camera:zoom", (payload) => {
63
+ if (payload.requestId !== requestId) return;
64
+ clearTimeout(timer);
65
+ off();
66
+ resolve(payload);
67
+ });
68
+ this.postCameraGetZoom({ requestId });
69
+ });
70
+ }
71
+ postCameraGetZoom(payload) {
72
+ this.viewer.postToViewer("viewer-camera-get-zoom" /* CAMERA_GET_ZOOM */, payload);
73
+ }
47
74
  };
48
75
 
49
76
  // src/modules/interaction.module.ts
@@ -562,7 +589,7 @@ var FilesModule = class {
562
589
  };
563
590
 
564
591
  // src/modules/toolbar.module.ts
565
- function createRequestId(prefix) {
592
+ function createRequestId2(prefix) {
566
593
  return `${prefix}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
567
594
  }
568
595
  var ALL_3D_TOOLBAR_OPERATORS = [
@@ -720,7 +747,7 @@ var ToolbarModule = class {
720
747
  }
721
748
  getSheets(options) {
722
749
  var _a;
723
- const requestId = createRequestId("sheets");
750
+ const requestId = createRequestId2("sheets");
724
751
  const timeoutMs = Math.max(1e3, (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : 1e4);
725
752
  return new Promise((resolve, reject) => {
726
753
  const timer = setTimeout(() => {
@@ -738,7 +765,7 @@ var ToolbarModule = class {
738
765
  }
739
766
  getObjectProperties(options) {
740
767
  var _a;
741
- const requestId = createRequestId("object_properties");
768
+ const requestId = createRequestId2("object_properties");
742
769
  const timeoutMs = Math.max(1e3, (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : 1e4);
743
770
  return new Promise((resolve, reject) => {
744
771
  const timer = setTimeout(() => {
@@ -756,7 +783,7 @@ var ToolbarModule = class {
756
783
  }
757
784
  getLinkedObjects(options) {
758
785
  var _a;
759
- const requestId = createRequestId("linked_objects");
786
+ const requestId = createRequestId2("linked_objects");
760
787
  const timeoutMs = Math.max(1e3, (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : 1e4);
761
788
  return new Promise((resolve, reject) => {
762
789
  const timer = setTimeout(() => {
@@ -774,7 +801,7 @@ var ToolbarModule = class {
774
801
  }
775
802
  getStatesObjects(options) {
776
803
  var _a;
777
- const requestId = createRequestId("states_objects");
804
+ const requestId = createRequestId2("states_objects");
778
805
  const timeoutMs = Math.max(1e3, (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : 1e4);
779
806
  return new Promise((resolve, reject) => {
780
807
  const timer = setTimeout(() => {
@@ -862,7 +889,7 @@ var ToolbarModule = class {
862
889
  };
863
890
 
864
891
  // src/modules/model-tree.module.ts
865
- function createRequestId2(prefix) {
892
+ function createRequestId3(prefix) {
866
893
  return `${prefix}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
867
894
  }
868
895
  function buildTree(nodes, rootNodeIds) {
@@ -910,7 +937,7 @@ var ModelTreeModule = class {
910
937
  });
911
938
  }
912
939
  getNodeIds(options) {
913
- const requestId = createRequestId2("tree");
940
+ const requestId = createRequestId3("tree");
914
941
  const timeoutMs = this.resolveTimeoutMs(options);
915
942
  return new Promise((resolve, reject) => {
916
943
  const timer = setTimeout(() => {
@@ -936,7 +963,7 @@ var ModelTreeModule = class {
936
963
  return this.requestNodes(options).then((response) => buildTree(response.nodes, response.rootNodeIds));
937
964
  }
938
965
  requestNodes(options) {
939
- const requestId = createRequestId2("tree_nodes");
966
+ const requestId = createRequestId3("tree_nodes");
940
967
  const timeoutMs = this.resolveTimeoutMs(options);
941
968
  return new Promise((resolve, reject) => {
942
969
  const timer = setTimeout(() => {
@@ -978,7 +1005,7 @@ var ModelTreeModule = class {
978
1005
  };
979
1006
 
980
1007
  // src/modules/markup.module.ts
981
- function createRequestId3(prefix) {
1008
+ function createRequestId4(prefix) {
982
1009
  return `${prefix}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
983
1010
  }
984
1011
  var MarkupModule = class {
@@ -1032,7 +1059,7 @@ var MarkupModule = class {
1032
1059
  }
1033
1060
  getList(options) {
1034
1061
  var _a;
1035
- const requestId = createRequestId3("markup-list");
1062
+ const requestId = createRequestId4("markup-list");
1036
1063
  const timeoutMs = Math.max(1e3, (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : 1e4);
1037
1064
  return new Promise((resolve, reject) => {
1038
1065
  const timer = setTimeout(() => {
@@ -1050,7 +1077,7 @@ var MarkupModule = class {
1050
1077
  }
1051
1078
  runRequest(prefix, messageType, eventName, options) {
1052
1079
  var _a;
1053
- const requestId = createRequestId3(prefix);
1080
+ const requestId = createRequestId4(prefix);
1054
1081
  const timeoutMs = Math.max(1e3, (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : 1e4);
1055
1082
  return new Promise((resolve, reject) => {
1056
1083
  const timer = setTimeout(() => {
@@ -1106,6 +1133,17 @@ var Viewer3D = class {
1106
1133
  case "viewer-home-click" /* HOME_CLICK */:
1107
1134
  this._emit("camera:home", { timestamp: Date.now() });
1108
1135
  break;
1136
+ case "viewer-camera-zoom" /* CAMERA_ZOOM */: {
1137
+ const payload = data.payload;
1138
+ if (!payload) break;
1139
+ this._emit("camera:zoom", {
1140
+ requestId: payload.requestId ? String(payload.requestId) : void 0,
1141
+ percent: Number(payload.percent) || 0,
1142
+ zoomFactor: Number(payload.zoomFactor) || 1,
1143
+ timestamp: Number(payload.timestamp) || Date.now()
1144
+ });
1145
+ break;
1146
+ }
1109
1147
  case "viewer-node-select" /* NODE_SELECT */:
1110
1148
  this._emit("node:select", { nodeId: String((_b = (_a = data.payload) == null ? void 0 : _a.nodeId) != null ? _b : ""), timestamp: Date.now() });
1111
1149
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "3dviewer-sdk",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [