3dviewer-sdk 1.0.16 → 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.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;
@@ -0,0 +1,13 @@
1
+ import { Viewer3D } from "../viewer";
2
+ export declare class CameraModule {
3
+ private viewer;
4
+ on: {
5
+ home: (cb: (payload: {
6
+ timestamp: number;
7
+ }) => void) => () => void;
8
+ };
9
+ constructor(viewer: Viewer3D);
10
+ zoomIn(percent: number): void;
11
+ zoomOut(percent: number): void;
12
+ home(): void;
13
+ }
@@ -0,0 +1,18 @@
1
+ import { ViewerMessageType } from "../contracts/messages";
2
+ export class CameraModule {
3
+ constructor(viewer) {
4
+ this.viewer = viewer;
5
+ this.on = {
6
+ home: (cb) => this.viewer._on("camera:home", cb),
7
+ };
8
+ }
9
+ zoomIn(percent) {
10
+ this.viewer.postToViewer(ViewerMessageType.ZOOM, { action: "in", percent });
11
+ }
12
+ zoomOut(percent) {
13
+ this.viewer.postToViewer(ViewerMessageType.ZOOM, { action: "out", percent });
14
+ }
15
+ home() {
16
+ this.viewer.postToViewer(ViewerMessageType.HOME, {});
17
+ }
18
+ }
@@ -0,0 +1,112 @@
1
+ import type { LoadStatePayload, PreparedViewerData } from "../contracts/events";
2
+ import { Viewer3D } from "../viewer";
3
+ export declare type FilesConfig = {
4
+ baseUrl?: string;
5
+ viewerPath?: string;
6
+ uploadPath?: string;
7
+ };
8
+ export declare type ConvertOptions = {
9
+ downloadUrl?: string;
10
+ };
11
+ export declare type ConvertV2Options = {
12
+ filename: string;
13
+ originalFilePath: string;
14
+ downloadUrl: string;
15
+ baseFileId: string;
16
+ baseMajorRev?: number;
17
+ baseMinorRev?: number;
18
+ overwrite?: boolean;
19
+ project?: string;
20
+ convertOptions?: Partial<StreamConvertOptions>;
21
+ };
22
+ export declare type FileInfoCheckInput = string | string[];
23
+ export declare type FileInfoCheckPayloadItem = {
24
+ baseFileId: string;
25
+ };
26
+ declare type StreamConvertOptions = {
27
+ convert3DModel: number;
28
+ convert2DSheet: number;
29
+ extractProperties: number;
30
+ childModels: number;
31
+ };
32
+ export declare class FilesModule {
33
+ private viewer;
34
+ on: {
35
+ state: (cb: (payload: LoadStatePayload) => void) => () => void;
36
+ uploadStart: (cb: (payload: {
37
+ fileName: string;
38
+ }) => void) => () => void;
39
+ uploadSuccess: (cb: (payload: {
40
+ fileName: string;
41
+ baseFileId: string;
42
+ }) => void) => () => void;
43
+ uploadError: (cb: (payload: {
44
+ fileName: string;
45
+ error: string;
46
+ }) => void) => () => void;
47
+ conversionStart: (cb: (payload: {
48
+ fileName: string;
49
+ }) => void) => () => void;
50
+ conversionSuccess: (cb: (payload: PreparedViewerData) => void) => () => void;
51
+ conversionError: (cb: (payload: {
52
+ fileName: string;
53
+ error: string;
54
+ }) => void) => () => void;
55
+ renderStart: (cb: (payload: {
56
+ url: string;
57
+ }) => void) => () => void;
58
+ renderSuccess: (cb: (payload: {
59
+ url: string;
60
+ }) => void) => () => void;
61
+ renderError: (cb: (payload: {
62
+ url?: string;
63
+ error: string;
64
+ }) => void) => () => void;
65
+ loadSuccess: (cb: (payload: PreparedViewerData) => void) => () => void;
66
+ loadError: (cb: (payload: {
67
+ error: string;
68
+ }) => void) => () => void;
69
+ };
70
+ private config;
71
+ private operationStartTime;
72
+ private state;
73
+ private lastUploadSession;
74
+ constructor(viewer: Viewer3D);
75
+ setConfig(next: FilesConfig): void;
76
+ getState(): LoadStatePayload;
77
+ upload(file?: File): Promise<{
78
+ fileName: string;
79
+ baseFileId: string;
80
+ }>;
81
+ convert(file?: File, options?: ConvertOptions): Promise<PreparedViewerData>;
82
+ prepare(file?: File, options?: ConvertOptions): Promise<PreparedViewerData>;
83
+ convertV2(options: ConvertV2Options): Promise<PreparedViewerData>;
84
+ checkFileInfo(baseFileIds: FileInfoCheckInput): Promise<unknown>;
85
+ open(input: PreparedViewerData | {
86
+ url: string;
87
+ }): void;
88
+ render(file?: File, options?: ConvertOptions): Promise<PreparedViewerData>;
89
+ private resolveFile;
90
+ private normalizeBaseUrl;
91
+ private resolveBaseUrl;
92
+ private resolveViewerPath;
93
+ private resolveViewerOrigin;
94
+ private resolveHostConversion;
95
+ private getUploadPath;
96
+ private fileSignature;
97
+ private createBaseFileId;
98
+ private createUploadSession;
99
+ private getUploadSessionForFile;
100
+ private uploadInternal;
101
+ private buildCachePayload;
102
+ private buildConvertV2Payload;
103
+ private buildFileInfoPayload;
104
+ private cacheFile;
105
+ private cacheFileV2;
106
+ private convertInternal;
107
+ private convertV2Internal;
108
+ private updateState;
109
+ private withOperation;
110
+ private toErrorMessage;
111
+ }
112
+ export {};