3dviewer-sdk 1.0.0 → 1.0.1
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 +415 -239
- package/dist/index.d.ts +415 -239
- package/dist/index.js +1051 -484
- package/dist/index.mjs +1024 -457
- package/package.json +16 -16
package/dist/index.mjs
CHANGED
|
@@ -1,457 +1,1024 @@
|
|
|
1
|
-
// src/core/emitter.ts
|
|
2
|
-
var Emitter = class {
|
|
3
|
-
constructor() {
|
|
4
|
-
this.listeners = {};
|
|
5
|
-
}
|
|
6
|
-
on(event, cb) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
this.
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
this.viewer
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
this.
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
this.viewer.
|
|
144
|
-
this.viewer.
|
|
145
|
-
|
|
146
|
-
this.viewer.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
return this.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
return this.
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
);
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
this.
|
|
374
|
-
this.
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
this.
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
1
|
+
// src/core/emitter.ts
|
|
2
|
+
var Emitter = class {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.listeners = {};
|
|
5
|
+
}
|
|
6
|
+
on(event, cb) {
|
|
7
|
+
if (!this.listeners[event]) {
|
|
8
|
+
this.listeners[event] = [];
|
|
9
|
+
}
|
|
10
|
+
const arr = this.listeners[event];
|
|
11
|
+
arr.push(cb);
|
|
12
|
+
return () => this.off(event, cb);
|
|
13
|
+
}
|
|
14
|
+
off(event, cb) {
|
|
15
|
+
const arr = this.listeners[event];
|
|
16
|
+
if (!arr) return;
|
|
17
|
+
const idx = arr.indexOf(cb);
|
|
18
|
+
if (idx >= 0) arr.splice(idx, 1);
|
|
19
|
+
if (arr.length === 0) delete this.listeners[event];
|
|
20
|
+
}
|
|
21
|
+
emit(event, payload) {
|
|
22
|
+
var _a;
|
|
23
|
+
(_a = this.listeners[event]) == null ? void 0 : _a.forEach((cb) => cb(payload));
|
|
24
|
+
}
|
|
25
|
+
clear() {
|
|
26
|
+
this.listeners = {};
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// src/modules/camera.module.ts
|
|
31
|
+
var CameraModule = class {
|
|
32
|
+
constructor(viewer) {
|
|
33
|
+
this.viewer = viewer;
|
|
34
|
+
this.on = {
|
|
35
|
+
home: (cb) => this.viewer._on("camera:home", cb)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
zoomIn(percent) {
|
|
39
|
+
this.viewer.postToViewer("viewer-zoom" /* ZOOM */, { action: "in", percent });
|
|
40
|
+
}
|
|
41
|
+
zoomOut(percent) {
|
|
42
|
+
this.viewer.postToViewer("viewer-zoom" /* ZOOM */, { action: "out", percent });
|
|
43
|
+
}
|
|
44
|
+
home() {
|
|
45
|
+
this.viewer.postToViewer("viewer-home" /* HOME */, {});
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// src/modules/interaction.module.ts
|
|
50
|
+
var InteractionModule = class {
|
|
51
|
+
constructor(viewer) {
|
|
52
|
+
this.viewer = viewer;
|
|
53
|
+
this.on = {
|
|
54
|
+
panChange: (cb) => this.viewer._on("interaction:pan-change", cb)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
enablePan() {
|
|
58
|
+
this.viewer.postToViewer("viewer-pan-toggle" /* PAN_TOGGLE */, { enabled: true });
|
|
59
|
+
}
|
|
60
|
+
disablePan() {
|
|
61
|
+
this.viewer.postToViewer("viewer-pan-toggle" /* PAN_TOGGLE */, { enabled: false });
|
|
62
|
+
}
|
|
63
|
+
select() {
|
|
64
|
+
this.viewer.postToViewer("viewer-select" /* SELECT */);
|
|
65
|
+
}
|
|
66
|
+
areaSelect() {
|
|
67
|
+
this.viewer.postToViewer("viewer-area-select" /* AREA_SELECT */);
|
|
68
|
+
}
|
|
69
|
+
orbit() {
|
|
70
|
+
this.viewer.postToViewer("viewer-orbit" /* ORBIT */);
|
|
71
|
+
}
|
|
72
|
+
rotateZ() {
|
|
73
|
+
this.viewer.postToViewer("viewer-rotate-z" /* ROTATE_Z */);
|
|
74
|
+
}
|
|
75
|
+
walkThrough() {
|
|
76
|
+
this.viewer.postToViewer("viewer-walk-through" /* WALK_THROUGH */);
|
|
77
|
+
}
|
|
78
|
+
zoomWindow() {
|
|
79
|
+
this.viewer.postToViewer("viewer-zoom-window" /* ZOOM_WINDOW */);
|
|
80
|
+
}
|
|
81
|
+
zoomFit() {
|
|
82
|
+
this.viewer.postToViewer("viewer-zoom-fit" /* ZOOM_FIT */);
|
|
83
|
+
}
|
|
84
|
+
drawModeShaded() {
|
|
85
|
+
this.setDrawMode("shaded");
|
|
86
|
+
}
|
|
87
|
+
drawModeWireframe() {
|
|
88
|
+
this.setDrawMode("wireframe");
|
|
89
|
+
}
|
|
90
|
+
drawModeHiddenLine() {
|
|
91
|
+
this.setDrawMode("hidden-line");
|
|
92
|
+
}
|
|
93
|
+
drawModeShadedWire() {
|
|
94
|
+
this.setDrawMode("shaded-wire");
|
|
95
|
+
}
|
|
96
|
+
drawModeXRay() {
|
|
97
|
+
this.setDrawMode("xray");
|
|
98
|
+
}
|
|
99
|
+
drawModeGhosting() {
|
|
100
|
+
this.setDrawMode("ghosting");
|
|
101
|
+
}
|
|
102
|
+
explode(magnitude) {
|
|
103
|
+
this.viewer.postToViewer("viewer-explode" /* EXPLODE */, { magnitude });
|
|
104
|
+
}
|
|
105
|
+
explodeOff() {
|
|
106
|
+
this.explode(0);
|
|
107
|
+
}
|
|
108
|
+
setDrawMode(mode) {
|
|
109
|
+
this.viewer.postToViewer("viewer-draw-mode" /* DRAW_MODE */, { mode });
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// src/modules/node.module.ts
|
|
114
|
+
var NodeModule = class {
|
|
115
|
+
constructor(viewer) {
|
|
116
|
+
this.viewer = viewer;
|
|
117
|
+
this.on = { select: (cb) => this.viewer._on("node:select", cb) };
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// src/modules/files.module.ts
|
|
122
|
+
var DEFAULT_API_BASE_URL = "https://dev.3dviewer.anybim.vn";
|
|
123
|
+
var DEFAULT_VIEWER_ORIGIN = "http://localhost:3000";
|
|
124
|
+
var FilesModule = class {
|
|
125
|
+
constructor(viewer) {
|
|
126
|
+
this.viewer = viewer;
|
|
127
|
+
this.config = {};
|
|
128
|
+
this.operationStartTime = 0;
|
|
129
|
+
this.state = {
|
|
130
|
+
isLoading: false,
|
|
131
|
+
stage: "idle"
|
|
132
|
+
};
|
|
133
|
+
this.lastUploadSession = null;
|
|
134
|
+
this.on = {
|
|
135
|
+
state: (cb) => this.viewer._on("files:state", cb),
|
|
136
|
+
uploadStart: (cb) => this.viewer._on("files:upload:start", cb),
|
|
137
|
+
uploadSuccess: (cb) => this.viewer._on("files:upload:success", cb),
|
|
138
|
+
uploadError: (cb) => this.viewer._on("files:upload:error", cb),
|
|
139
|
+
conversionStart: (cb) => this.viewer._on("files:conversion:start", cb),
|
|
140
|
+
conversionSuccess: (cb) => this.viewer._on("files:conversion:success", cb),
|
|
141
|
+
conversionError: (cb) => this.viewer._on("files:conversion:error", cb),
|
|
142
|
+
renderStart: (cb) => this.viewer._on("files:render:start", cb),
|
|
143
|
+
renderSuccess: (cb) => this.viewer._on("files:render:success", cb),
|
|
144
|
+
renderError: (cb) => this.viewer._on("files:render:error", cb),
|
|
145
|
+
loadSuccess: (cb) => this.viewer._on("files:load:success", cb),
|
|
146
|
+
loadError: (cb) => this.viewer._on("files:load:error", cb)
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
// Merge file-pipeline runtime config.
|
|
150
|
+
setConfig(next) {
|
|
151
|
+
this.config = { ...this.config, ...next };
|
|
152
|
+
}
|
|
153
|
+
// Return a snapshot of current loading state.
|
|
154
|
+
getState() {
|
|
155
|
+
return { ...this.state };
|
|
156
|
+
}
|
|
157
|
+
// ---------- public pipeline ----------
|
|
158
|
+
// Upload file to conversion server and keep generated baseFileId in session.
|
|
159
|
+
async upload(file) {
|
|
160
|
+
const target = this.resolveFile(file);
|
|
161
|
+
return this.withOperation({ stage: "uploading", message: "Uploading file..." }, async () => {
|
|
162
|
+
var _a;
|
|
163
|
+
this.viewer._emit("files:upload:start", { fileName: target.name });
|
|
164
|
+
await this.uploadInternal(target);
|
|
165
|
+
const baseFileId = ((_a = this.getUploadSessionForFile(target)) == null ? void 0 : _a.baseFileId) || "";
|
|
166
|
+
this.viewer._emit("files:upload:success", { fileName: target.name, baseFileId });
|
|
167
|
+
return { fileName: target.name, baseFileId };
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
// Trigger conversion flow and resolve final viewer metadata.
|
|
171
|
+
async convert(file) {
|
|
172
|
+
const target = this.resolveFile(file);
|
|
173
|
+
return this.withOperation({ stage: "converting", message: "Converting file..." }, async () => {
|
|
174
|
+
this.viewer._emit("files:conversion:start", { fileName: target.name });
|
|
175
|
+
try {
|
|
176
|
+
const prepared = await this.convertInternal(target);
|
|
177
|
+
this.viewer._emit("files:conversion:success", prepared);
|
|
178
|
+
return prepared;
|
|
179
|
+
} catch (e) {
|
|
180
|
+
this.viewer._emit("files:conversion:error", { fileName: target.name, error: this.toErrorMessage(e) });
|
|
181
|
+
throw e;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
// Convenience API: upload first, then convert in one call.
|
|
186
|
+
async prepare(file) {
|
|
187
|
+
const target = this.resolveFile(file);
|
|
188
|
+
return this.withOperation({ stage: "uploading", message: "Preparing file..." }, async () => {
|
|
189
|
+
await this.uploadInternal(target);
|
|
190
|
+
const prepared = await this.convertInternal(target);
|
|
191
|
+
return prepared;
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
// Open iframe with an already prepared viewer URL.
|
|
195
|
+
open(input) {
|
|
196
|
+
const url = input.url;
|
|
197
|
+
this.viewer._emit("files:render:start", { url });
|
|
198
|
+
try {
|
|
199
|
+
this.viewer.open(url);
|
|
200
|
+
this.viewer._emit("files:render:success", { url });
|
|
201
|
+
} catch (e) {
|
|
202
|
+
this.viewer._emit("files:render:error", { url, error: this.toErrorMessage(e) });
|
|
203
|
+
throw e;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// Full pipeline: upload + convert + open iframe.
|
|
207
|
+
async render(file) {
|
|
208
|
+
const target = this.resolveFile(file);
|
|
209
|
+
return this.withOperation({ stage: "uploading", message: "Uploading + converting + opening..." }, async () => {
|
|
210
|
+
await this.upload(target);
|
|
211
|
+
const prepared = await this.convert(target);
|
|
212
|
+
this.updateState({ stage: "rendering", message: "Opening viewer..." });
|
|
213
|
+
this.open(prepared);
|
|
214
|
+
this.viewer._emit("files:load:success", prepared);
|
|
215
|
+
return prepared;
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
// Resolve file argument, fallback to options.file, and persist it back.
|
|
219
|
+
resolveFile(file) {
|
|
220
|
+
const optFile = this.viewer.getOptions().file;
|
|
221
|
+
const target = file || optFile;
|
|
222
|
+
if (!target) throw new Error("No file provided. Pass a File or set options.file");
|
|
223
|
+
this.viewer.patchOptions({ file: target });
|
|
224
|
+
return target;
|
|
225
|
+
}
|
|
226
|
+
// Trim input URL and remove trailing slash.
|
|
227
|
+
normalizeBaseUrl(input) {
|
|
228
|
+
return input.trim().replace(/\/+$/, "");
|
|
229
|
+
}
|
|
230
|
+
// Resolve API base URL with default fallback.
|
|
231
|
+
resolveBaseUrl() {
|
|
232
|
+
const raw = this.config.baseUrl || this.viewer.getOptions().baseUrl || DEFAULT_API_BASE_URL;
|
|
233
|
+
return this.normalizeBaseUrl(raw);
|
|
234
|
+
}
|
|
235
|
+
// Resolve viewer route path (e.g. /mainviewer).
|
|
236
|
+
resolveViewerPath() {
|
|
237
|
+
const p = (this.config.viewerPath || this.viewer.getOptions().viewerPath || "/mainviewer").trim();
|
|
238
|
+
if (!p) return "/mainviewer";
|
|
239
|
+
return p.startsWith("/") ? p : `/${p}`;
|
|
240
|
+
}
|
|
241
|
+
// Viewer host used to open iframe after conversion completes.
|
|
242
|
+
resolveViewerOrigin() {
|
|
243
|
+
return this.normalizeBaseUrl(DEFAULT_VIEWER_ORIGIN);
|
|
244
|
+
}
|
|
245
|
+
// Build conversion service root from API base URL.
|
|
246
|
+
resolveHostConversion() {
|
|
247
|
+
const baseUrl = this.resolveBaseUrl();
|
|
248
|
+
return baseUrl.endsWith("/service/conversion") ? baseUrl : `${baseUrl}/service/conversion`;
|
|
249
|
+
}
|
|
250
|
+
// Resolve upload path sent to conversion APIs.
|
|
251
|
+
getUploadPath() {
|
|
252
|
+
return this.config.uploadPath || this.viewer.getOptions().uploadPath || ".";
|
|
253
|
+
}
|
|
254
|
+
// Build a stable in-memory signature to identify same file uploads.
|
|
255
|
+
fileSignature(file) {
|
|
256
|
+
return `${file.name}::${file.size}::${file.lastModified}`;
|
|
257
|
+
}
|
|
258
|
+
// Create a UUID-like baseFileId when caller does not provide one.
|
|
259
|
+
createBaseFileId() {
|
|
260
|
+
if (typeof crypto !== "undefined" && "randomUUID" in crypto) return crypto.randomUUID();
|
|
261
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
262
|
+
const r = Math.floor(Math.random() * 16);
|
|
263
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
264
|
+
return v.toString(16);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
// Create upload session metadata reused between upload and convert.
|
|
268
|
+
createUploadSession(file) {
|
|
269
|
+
return {
|
|
270
|
+
signature: this.fileSignature(file),
|
|
271
|
+
baseFileId: this.createBaseFileId(),
|
|
272
|
+
fileName: file.name,
|
|
273
|
+
uploadPath: this.getUploadPath()
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
// Return previous upload session for same file and upload path.
|
|
277
|
+
getUploadSessionForFile(file) {
|
|
278
|
+
if (!this.lastUploadSession) return null;
|
|
279
|
+
const sameFile = this.lastUploadSession.signature === this.fileSignature(file);
|
|
280
|
+
const samePath = this.lastUploadSession.uploadPath === this.getUploadPath();
|
|
281
|
+
return sameFile && samePath ? this.lastUploadSession : null;
|
|
282
|
+
}
|
|
283
|
+
// Call upload endpoint and persist upload session on success.
|
|
284
|
+
async uploadInternal(file) {
|
|
285
|
+
this.updateState({ stage: "uploading", message: "Uploading file..." });
|
|
286
|
+
try {
|
|
287
|
+
const existing = this.getUploadSessionForFile(file);
|
|
288
|
+
const session = existing || this.createUploadSession(file);
|
|
289
|
+
const hostConversion = this.resolveHostConversion();
|
|
290
|
+
const path = this.getUploadPath();
|
|
291
|
+
const url = `${hostConversion}/api/File/upload?path=${encodeURIComponent(path)}`;
|
|
292
|
+
const formData = new FormData();
|
|
293
|
+
formData.append("file", file, file.name);
|
|
294
|
+
const res = await fetch(url, { method: "POST", body: formData, headers: { Accept: "text/plain" } });
|
|
295
|
+
if (!res.ok) throw new Error(`Upload failed (${res.status} ${res.statusText})`);
|
|
296
|
+
this.lastUploadSession = session;
|
|
297
|
+
} catch (e) {
|
|
298
|
+
const msg = this.toErrorMessage(e);
|
|
299
|
+
this.viewer._emit("files:upload:error", { fileName: file.name, error: msg });
|
|
300
|
+
throw e;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
// Build StreamFile payload compatible with conversion service.
|
|
304
|
+
buildCachePayload(file, baseFileId) {
|
|
305
|
+
const createdDate = (/* @__PURE__ */ new Date()).toISOString();
|
|
306
|
+
return {
|
|
307
|
+
filename: file.name,
|
|
308
|
+
baseFileId,
|
|
309
|
+
baseMajorRev: 0,
|
|
310
|
+
baseMinorRev: 0,
|
|
311
|
+
isChecked: false,
|
|
312
|
+
status: { size: file.size },
|
|
313
|
+
child: [],
|
|
314
|
+
isDirectory: false,
|
|
315
|
+
createdDate,
|
|
316
|
+
cacheStatus: 0,
|
|
317
|
+
modelFileId: "",
|
|
318
|
+
id: "",
|
|
319
|
+
originalFilePath: this.getUploadPath(),
|
|
320
|
+
streamLocation: null,
|
|
321
|
+
converter: "Hoops",
|
|
322
|
+
originalSize: 0,
|
|
323
|
+
cacheSize: 0,
|
|
324
|
+
importTime: 0,
|
|
325
|
+
importAssemblyTreeTime: 0,
|
|
326
|
+
creator: {
|
|
327
|
+
id: "00000000-0000-0000-0000-000000000000",
|
|
328
|
+
name: "Anonymous"
|
|
329
|
+
},
|
|
330
|
+
originalFile: file.name,
|
|
331
|
+
multiStream: false,
|
|
332
|
+
isRootModel: 0,
|
|
333
|
+
extraConvertOutput: "",
|
|
334
|
+
cacheFilename: null,
|
|
335
|
+
errorMassage: null,
|
|
336
|
+
convertOptions: {
|
|
337
|
+
convert3DModel: 1,
|
|
338
|
+
convert2DSheet: 1,
|
|
339
|
+
extractProperties: 1,
|
|
340
|
+
childModels: 0
|
|
341
|
+
},
|
|
342
|
+
drawingConvertStatus: {
|
|
343
|
+
convert3DModel: 5,
|
|
344
|
+
convert2DSheet: 5,
|
|
345
|
+
extractProperties: 5
|
|
346
|
+
},
|
|
347
|
+
attemptedConvertTimes: 0
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
// Submit conversion/caching request and return service response.
|
|
351
|
+
async cacheFile(file, baseFileId) {
|
|
352
|
+
const hostConversion = await this.resolveHostConversion();
|
|
353
|
+
const url = `${hostConversion}/api/StreamFile?overwrite=true&ignore_line_weight=1`;
|
|
354
|
+
const payload = this.buildCachePayload(file, baseFileId);
|
|
355
|
+
const response = await fetch(url, {
|
|
356
|
+
method: "POST",
|
|
357
|
+
headers: {
|
|
358
|
+
"Content-Type": "application/json",
|
|
359
|
+
Accept: "application/json"
|
|
360
|
+
},
|
|
361
|
+
body: JSON.stringify(payload)
|
|
362
|
+
});
|
|
363
|
+
if (!response.ok) {
|
|
364
|
+
throw new Error(
|
|
365
|
+
`Cache/convert failed (${response.status} ${response.statusText})`
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
return await response.json();
|
|
369
|
+
}
|
|
370
|
+
// Convert file and generate final iframe URL with query string.
|
|
371
|
+
async convertInternal(file) {
|
|
372
|
+
var _a, _b, _c, _d;
|
|
373
|
+
this.updateState({ stage: "converting", message: "Converting file..." });
|
|
374
|
+
const uploadSession = this.getUploadSessionForFile(file) || this.createUploadSession(file);
|
|
375
|
+
const seedBaseFileId = uploadSession.baseFileId;
|
|
376
|
+
const cacheResult = await this.cacheFile(file, seedBaseFileId);
|
|
377
|
+
const baseFileId = (_a = cacheResult.baseFileId) != null ? _a : seedBaseFileId;
|
|
378
|
+
const baseMajorRev = (_b = cacheResult.baseMajorRev) != null ? _b : 0;
|
|
379
|
+
const baseMinorRev = (_c = cacheResult.baseMinorRev) != null ? _c : 0;
|
|
380
|
+
const fileName = cacheResult.filename || file.name;
|
|
381
|
+
const cacheListItem = { baseFileId, baseMajorRev, baseMinorRev, fileName };
|
|
382
|
+
if (cacheResult.cacheStatus !== 2) {
|
|
383
|
+
throw new Error(`Conversion not ready after first request (cacheStatus=${(_d = cacheResult.cacheStatus) != null ? _d : "unknown"})`);
|
|
384
|
+
}
|
|
385
|
+
const query = new URLSearchParams({ fileList: JSON.stringify([cacheListItem]) }).toString();
|
|
386
|
+
const viewerBase = this.resolveViewerOrigin();
|
|
387
|
+
const viewerPath = this.resolveViewerPath();
|
|
388
|
+
const url = `${viewerBase}${viewerPath}?${query}`;
|
|
389
|
+
return { baseFileId, baseMajorRev, baseMinorRev, fileName, query, url };
|
|
390
|
+
}
|
|
391
|
+
// Update internal loading state and emit state event.
|
|
392
|
+
updateState(next) {
|
|
393
|
+
const elapsedMs = this.operationStartTime > 0 ? Date.now() - this.operationStartTime : 0;
|
|
394
|
+
this.state = { ...this.state, ...next, elapsedMs };
|
|
395
|
+
this.viewer._emit("files:state", this.state);
|
|
396
|
+
}
|
|
397
|
+
// Shared wrapper to handle loading state lifecycle and top-level errors.
|
|
398
|
+
async withOperation(initial, run) {
|
|
399
|
+
this.operationStartTime = Date.now();
|
|
400
|
+
this.updateState({
|
|
401
|
+
isLoading: true,
|
|
402
|
+
stage: initial.stage,
|
|
403
|
+
message: initial.message
|
|
404
|
+
});
|
|
405
|
+
try {
|
|
406
|
+
const result = await run();
|
|
407
|
+
this.updateState({ isLoading: false, stage: "completed", message: "Completed" });
|
|
408
|
+
return result;
|
|
409
|
+
} catch (e) {
|
|
410
|
+
const msg = this.toErrorMessage(e);
|
|
411
|
+
this.updateState({ isLoading: false, stage: "error", message: msg });
|
|
412
|
+
this.viewer._emit("files:load:error", { error: msg });
|
|
413
|
+
throw e;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
// Normalize unknown error shape into displayable message.
|
|
417
|
+
toErrorMessage(e) {
|
|
418
|
+
return e instanceof Error ? e.message : String(e);
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
// src/modules/toolbar.module.ts
|
|
423
|
+
function createRequestId() {
|
|
424
|
+
return `sheets_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
|
|
425
|
+
}
|
|
426
|
+
var ALL_3D_TOOLBAR_OPERATORS = [
|
|
427
|
+
"home",
|
|
428
|
+
"select",
|
|
429
|
+
"areaSelect",
|
|
430
|
+
"pan",
|
|
431
|
+
"zoomIn",
|
|
432
|
+
"zoomOut",
|
|
433
|
+
"zoomWindow",
|
|
434
|
+
"zoomFit",
|
|
435
|
+
"orbit",
|
|
436
|
+
"rotateZ",
|
|
437
|
+
"walkThrough",
|
|
438
|
+
"drawMode-shaded",
|
|
439
|
+
"drawMode-wireframe",
|
|
440
|
+
"drawMode-shaded-wire",
|
|
441
|
+
"drawMode-hidden-line",
|
|
442
|
+
"drawMode-xray",
|
|
443
|
+
"drawMode-ghosting",
|
|
444
|
+
"cutting-plane",
|
|
445
|
+
"clipping-commands",
|
|
446
|
+
"explode",
|
|
447
|
+
"setting",
|
|
448
|
+
"propertyPanel",
|
|
449
|
+
"model-tree",
|
|
450
|
+
"linkedObjects",
|
|
451
|
+
"statesObjects",
|
|
452
|
+
"synchronized"
|
|
453
|
+
];
|
|
454
|
+
var ALL_PDF_TOOLBAR_OPERATORS = [
|
|
455
|
+
"home",
|
|
456
|
+
"select",
|
|
457
|
+
"pan",
|
|
458
|
+
"zoomIn",
|
|
459
|
+
"zoomOut",
|
|
460
|
+
"zoomWindow",
|
|
461
|
+
"zoomFit",
|
|
462
|
+
"rotateZ",
|
|
463
|
+
"save",
|
|
464
|
+
"setting",
|
|
465
|
+
"plan-mode",
|
|
466
|
+
"document-mode",
|
|
467
|
+
"first-page",
|
|
468
|
+
"previous-page",
|
|
469
|
+
"next-page",
|
|
470
|
+
"last-page",
|
|
471
|
+
"current-page"
|
|
472
|
+
];
|
|
473
|
+
var ToolbarModule = class {
|
|
474
|
+
constructor(viewer) {
|
|
475
|
+
this.viewer = viewer;
|
|
476
|
+
this.on = {
|
|
477
|
+
planMode: (cb) => this.viewer._on("toolbar:pdf-plan-mode", cb),
|
|
478
|
+
documentMode: (cb) => this.viewer._on("toolbar:pdf-document-mode", cb),
|
|
479
|
+
firstPage: (cb) => this.viewer._on("toolbar:pdf-first-page", cb),
|
|
480
|
+
previousPage: (cb) => this.viewer._on("toolbar:pdf-previous-page", cb),
|
|
481
|
+
nextPage: (cb) => this.viewer._on("toolbar:pdf-next-page", cb),
|
|
482
|
+
lastPage: (cb) => this.viewer._on("toolbar:pdf-last-page", cb),
|
|
483
|
+
currentPage: (cb) => this.viewer._on("toolbar:pdf-current-page", cb)
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
setDisabled3D(operators) {
|
|
487
|
+
this.postConfig({ format: "3d", mode: "set", operators });
|
|
488
|
+
}
|
|
489
|
+
setDisabledPdf(operators) {
|
|
490
|
+
this.postConfig({ format: "pdf", mode: "set", operators });
|
|
491
|
+
}
|
|
492
|
+
clearDisabled3D() {
|
|
493
|
+
this.postConfig({ format: "3d", mode: "clear" });
|
|
494
|
+
}
|
|
495
|
+
clearDisabledPdf() {
|
|
496
|
+
this.postConfig({ format: "pdf", mode: "clear" });
|
|
497
|
+
}
|
|
498
|
+
disableAll3D() {
|
|
499
|
+
this.setDisabled3D(ALL_3D_TOOLBAR_OPERATORS);
|
|
500
|
+
}
|
|
501
|
+
disableAllPdf() {
|
|
502
|
+
this.setDisabledPdf(ALL_PDF_TOOLBAR_OPERATORS);
|
|
503
|
+
}
|
|
504
|
+
enableAll3D() {
|
|
505
|
+
this.clearDisabled3D();
|
|
506
|
+
}
|
|
507
|
+
enableAllPdf() {
|
|
508
|
+
this.clearDisabledPdf();
|
|
509
|
+
}
|
|
510
|
+
openClippingPlanes() {
|
|
511
|
+
this.postPanelOpen({ panel: "clipping-commands", format: "3d" });
|
|
512
|
+
}
|
|
513
|
+
closeClippingPlanes() {
|
|
514
|
+
this.postPanelClose({ panel: "clipping-commands", format: "3d" });
|
|
515
|
+
}
|
|
516
|
+
openSetting() {
|
|
517
|
+
this.postPanelOpen({ panel: "setting" });
|
|
518
|
+
}
|
|
519
|
+
closeSetting() {
|
|
520
|
+
this.postPanelClose({ panel: "setting" });
|
|
521
|
+
}
|
|
522
|
+
openSetting3D() {
|
|
523
|
+
this.postPanelOpen({ panel: "setting", format: "3d" });
|
|
524
|
+
}
|
|
525
|
+
closeSetting3D() {
|
|
526
|
+
this.postPanelClose({ panel: "setting", format: "3d" });
|
|
527
|
+
}
|
|
528
|
+
openSettingPdf() {
|
|
529
|
+
this.postPanelOpen({ panel: "setting", format: "pdf" });
|
|
530
|
+
}
|
|
531
|
+
closeSettingPdf() {
|
|
532
|
+
this.postPanelClose({ panel: "setting", format: "pdf" });
|
|
533
|
+
}
|
|
534
|
+
openStatesObjects() {
|
|
535
|
+
this.postPanelOpen({ panel: "statesObjects", format: "3d" });
|
|
536
|
+
}
|
|
537
|
+
closeStatesObjects() {
|
|
538
|
+
this.postPanelClose({ panel: "statesObjects", format: "3d" });
|
|
539
|
+
}
|
|
540
|
+
openLinkedObjects() {
|
|
541
|
+
this.postPanelOpen({ panel: "linkedObjects", format: "3d" });
|
|
542
|
+
}
|
|
543
|
+
closeLinkedObjects() {
|
|
544
|
+
this.postPanelClose({ panel: "linkedObjects", format: "3d" });
|
|
545
|
+
}
|
|
546
|
+
openModelTree() {
|
|
547
|
+
this.postPanelOpen({ panel: "model-tree", format: "3d" });
|
|
548
|
+
}
|
|
549
|
+
closeModelTree() {
|
|
550
|
+
this.postPanelClose({ panel: "model-tree", format: "3d" });
|
|
551
|
+
}
|
|
552
|
+
openObjectProperties() {
|
|
553
|
+
this.postPanelOpen({ panel: "object-properties", format: "3d" });
|
|
554
|
+
}
|
|
555
|
+
closeObjectProperties() {
|
|
556
|
+
this.postPanelClose({ panel: "object-properties", format: "3d" });
|
|
557
|
+
}
|
|
558
|
+
openSheets() {
|
|
559
|
+
this.postPanelOpen({ panel: "sheets", format: "3d" });
|
|
560
|
+
}
|
|
561
|
+
closeSheets() {
|
|
562
|
+
this.postPanelClose({ panel: "sheets", format: "3d" });
|
|
563
|
+
}
|
|
564
|
+
getSheets(options) {
|
|
565
|
+
var _a;
|
|
566
|
+
const requestId = createRequestId();
|
|
567
|
+
const timeoutMs = Math.max(1e3, (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : 1e4);
|
|
568
|
+
return new Promise((resolve, reject) => {
|
|
569
|
+
const timer = setTimeout(() => {
|
|
570
|
+
off();
|
|
571
|
+
reject(new Error("Timeout while getting sheets list from viewer"));
|
|
572
|
+
}, timeoutMs);
|
|
573
|
+
const off = this.viewer._on("sheets:list", (payload) => {
|
|
574
|
+
if (payload.requestId !== requestId) return;
|
|
575
|
+
clearTimeout(timer);
|
|
576
|
+
off();
|
|
577
|
+
resolve(payload.sheets);
|
|
578
|
+
});
|
|
579
|
+
this.postSheetsGetList({ requestId });
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
applySheet(sheetId) {
|
|
583
|
+
this.postSheetsApply({ sheetId });
|
|
584
|
+
}
|
|
585
|
+
cuttingCloseSections() {
|
|
586
|
+
this.postCuttingAction({ action: "close" });
|
|
587
|
+
}
|
|
588
|
+
cuttingMultipleSides() {
|
|
589
|
+
this.postCuttingAction({ action: "multi" });
|
|
590
|
+
}
|
|
591
|
+
cuttingToggleSelection() {
|
|
592
|
+
this.postCuttingAction({ action: "toggle-section" });
|
|
593
|
+
}
|
|
594
|
+
cuttingTogglePlanes() {
|
|
595
|
+
this.postCuttingAction({ action: "toggle-plane" });
|
|
596
|
+
}
|
|
597
|
+
cuttingPlaneX() {
|
|
598
|
+
this.postCuttingAction({ action: "plane-x" });
|
|
599
|
+
}
|
|
600
|
+
cuttingPlaneY() {
|
|
601
|
+
this.postCuttingAction({ action: "plane-y" });
|
|
602
|
+
}
|
|
603
|
+
cuttingPlaneZ() {
|
|
604
|
+
this.postCuttingAction({ action: "plane-z" });
|
|
605
|
+
}
|
|
606
|
+
cuttingPlaneBox() {
|
|
607
|
+
this.postCuttingAction({ action: "plane-box" });
|
|
608
|
+
}
|
|
609
|
+
cuttingRotateBox() {
|
|
610
|
+
this.postCuttingAction({ action: "rotate-box" });
|
|
611
|
+
}
|
|
612
|
+
cuttingReversePlaneX() {
|
|
613
|
+
this.postCuttingAction({ action: "reverse-plane-x" });
|
|
614
|
+
}
|
|
615
|
+
cuttingReversePlaneY() {
|
|
616
|
+
this.postCuttingAction({ action: "reverse-plane-y" });
|
|
617
|
+
}
|
|
618
|
+
cuttingReversePlaneZ() {
|
|
619
|
+
this.postCuttingAction({ action: "reverse-plane-z" });
|
|
620
|
+
}
|
|
621
|
+
postConfig(payload) {
|
|
622
|
+
this.viewer.postToViewer("viewer-toolbar-config" /* TOOLBAR_CONFIG */, payload);
|
|
623
|
+
}
|
|
624
|
+
postPanelOpen(payload) {
|
|
625
|
+
this.viewer.postToViewer("viewer-panel-open" /* PANEL_OPEN */, payload);
|
|
626
|
+
}
|
|
627
|
+
postPanelClose(payload) {
|
|
628
|
+
this.viewer.postToViewer("viewer-panel-close" /* PANEL_CLOSE */, payload);
|
|
629
|
+
}
|
|
630
|
+
postCuttingAction(payload) {
|
|
631
|
+
this.viewer.postToViewer("viewer-cutting-plane-action" /* CUTTING_PLANE_ACTION */, payload);
|
|
632
|
+
}
|
|
633
|
+
postSheetsGetList(payload) {
|
|
634
|
+
this.viewer.postToViewer("viewer-sheets-get-list" /* SHEETS_GET_LIST */, payload);
|
|
635
|
+
}
|
|
636
|
+
postSheetsApply(payload) {
|
|
637
|
+
this.viewer.postToViewer("viewer-sheets-apply" /* SHEETS_APPLY */, payload);
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
|
|
641
|
+
// src/modules/model-tree.module.ts
|
|
642
|
+
function createRequestId2() {
|
|
643
|
+
return `tree_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
|
|
644
|
+
}
|
|
645
|
+
var ModelTreeModule = class {
|
|
646
|
+
constructor(viewer) {
|
|
647
|
+
this.viewer = viewer;
|
|
648
|
+
}
|
|
649
|
+
open() {
|
|
650
|
+
this.viewer.postToViewer("viewer-panel-open" /* PANEL_OPEN */, {
|
|
651
|
+
panel: "model-tree",
|
|
652
|
+
format: "3d"
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
selectNode(nodeId) {
|
|
656
|
+
this.viewer.postToViewer("viewer-tree-select-node" /* TREE_SELECT_NODE */, {
|
|
657
|
+
nodeId: String(nodeId)
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
getNodeIds(options) {
|
|
661
|
+
var _a;
|
|
662
|
+
const requestId = createRequestId2();
|
|
663
|
+
const timeoutMs = Math.max(1e3, (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : 1e4);
|
|
664
|
+
return new Promise((resolve, reject) => {
|
|
665
|
+
const timer = setTimeout(() => {
|
|
666
|
+
off();
|
|
667
|
+
reject(new Error("Timeout while getting node ids from viewer"));
|
|
668
|
+
}, timeoutMs);
|
|
669
|
+
const off = this.viewer._on("modelTree:node-ids", (payload) => {
|
|
670
|
+
if (payload.requestId !== requestId) return;
|
|
671
|
+
clearTimeout(timer);
|
|
672
|
+
off();
|
|
673
|
+
resolve(payload.nodeIds);
|
|
674
|
+
});
|
|
675
|
+
this.viewer.postToViewer("viewer-tree-get-node-ids" /* TREE_GET_NODE_IDS */, {
|
|
676
|
+
requestId,
|
|
677
|
+
onlyRealNodes: (options == null ? void 0 : options.onlyRealNodes) !== false
|
|
678
|
+
});
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
// src/modules/markup.module.ts
|
|
684
|
+
function createRequestId3(prefix) {
|
|
685
|
+
return `${prefix}_${Date.now()}_${Math.random().toString(36).slice(2, 10)}`;
|
|
686
|
+
}
|
|
687
|
+
var MarkupModule = class {
|
|
688
|
+
constructor(viewer) {
|
|
689
|
+
this.viewer = viewer;
|
|
690
|
+
}
|
|
691
|
+
action(action) {
|
|
692
|
+
this.viewer.postToViewer("viewer-markup-action" /* MARKUP_ACTION */, { action });
|
|
693
|
+
}
|
|
694
|
+
drawLine() {
|
|
695
|
+
this.action("line");
|
|
696
|
+
}
|
|
697
|
+
drawArrow() {
|
|
698
|
+
this.action("arrow");
|
|
699
|
+
}
|
|
700
|
+
drawCircle() {
|
|
701
|
+
this.action("circle");
|
|
702
|
+
}
|
|
703
|
+
drawEllipse() {
|
|
704
|
+
this.action("ellipse");
|
|
705
|
+
}
|
|
706
|
+
drawRectangle() {
|
|
707
|
+
this.action("rectangle");
|
|
708
|
+
}
|
|
709
|
+
drawPolygon() {
|
|
710
|
+
this.action("polygon");
|
|
711
|
+
}
|
|
712
|
+
drawPolyline() {
|
|
713
|
+
this.action("polyline");
|
|
714
|
+
}
|
|
715
|
+
drawTextBox() {
|
|
716
|
+
this.action("textbox");
|
|
717
|
+
}
|
|
718
|
+
drawNote() {
|
|
719
|
+
this.action("note");
|
|
720
|
+
}
|
|
721
|
+
drawCallout() {
|
|
722
|
+
this.action("callout");
|
|
723
|
+
}
|
|
724
|
+
drawCloud() {
|
|
725
|
+
this.action("cloud");
|
|
726
|
+
}
|
|
727
|
+
drawFreehand() {
|
|
728
|
+
this.action("freehand");
|
|
729
|
+
}
|
|
730
|
+
save(options) {
|
|
731
|
+
return this.runRequest("markup-save", "viewer-markup-save" /* MARKUP_SAVE */, "markup:save", options);
|
|
732
|
+
}
|
|
733
|
+
cancel(options) {
|
|
734
|
+
return this.runRequest("markup-cancel", "viewer-markup-cancel" /* MARKUP_CANCEL */, "markup:cancel", options);
|
|
735
|
+
}
|
|
736
|
+
getList(options) {
|
|
737
|
+
var _a;
|
|
738
|
+
const requestId = createRequestId3("markup-list");
|
|
739
|
+
const timeoutMs = Math.max(1e3, (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : 1e4);
|
|
740
|
+
return new Promise((resolve, reject) => {
|
|
741
|
+
const timer = setTimeout(() => {
|
|
742
|
+
off();
|
|
743
|
+
reject(new Error("Timeout while getting markup list from viewer"));
|
|
744
|
+
}, timeoutMs);
|
|
745
|
+
const off = this.viewer._on("markup:list", (payload) => {
|
|
746
|
+
if (payload.requestId !== requestId) return;
|
|
747
|
+
clearTimeout(timer);
|
|
748
|
+
off();
|
|
749
|
+
resolve(payload.markups);
|
|
750
|
+
});
|
|
751
|
+
this.viewer.postToViewer("viewer-markup-get-list" /* MARKUP_GET_LIST */, { requestId });
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
runRequest(prefix, messageType, eventName, options) {
|
|
755
|
+
var _a;
|
|
756
|
+
const requestId = createRequestId3(prefix);
|
|
757
|
+
const timeoutMs = Math.max(1e3, (_a = options == null ? void 0 : options.timeoutMs) != null ? _a : 1e4);
|
|
758
|
+
return new Promise((resolve, reject) => {
|
|
759
|
+
const timer = setTimeout(() => {
|
|
760
|
+
off();
|
|
761
|
+
reject(new Error(`Timeout while waiting for ${prefix} result from viewer`));
|
|
762
|
+
}, timeoutMs);
|
|
763
|
+
const off = this.viewer._on(eventName, (payload) => {
|
|
764
|
+
if (payload.requestId !== requestId) return;
|
|
765
|
+
clearTimeout(timer);
|
|
766
|
+
off();
|
|
767
|
+
if (payload.success) {
|
|
768
|
+
resolve();
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
reject(new Error(payload.error || `Viewer ${prefix} failed`));
|
|
772
|
+
});
|
|
773
|
+
this.viewer.postToViewer(messageType, { requestId });
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
// src/viewer.ts
|
|
779
|
+
var Viewer3D = class {
|
|
780
|
+
constructor(options) {
|
|
781
|
+
this.options = options;
|
|
782
|
+
this.containerEl = null;
|
|
783
|
+
this.iframeEl = null;
|
|
784
|
+
this.initialized = false;
|
|
785
|
+
this.emitter = new Emitter();
|
|
786
|
+
this.handleMessage = (event) => {
|
|
787
|
+
var _a, _b, _c, _d;
|
|
788
|
+
const data = event.data;
|
|
789
|
+
if (!data || typeof data !== "object") return;
|
|
790
|
+
switch (data.type) {
|
|
791
|
+
case "viewer-home-click" /* HOME_CLICK */:
|
|
792
|
+
this._emit("camera:home", { timestamp: Date.now() });
|
|
793
|
+
break;
|
|
794
|
+
case "viewer-node-select" /* NODE_SELECT */:
|
|
795
|
+
this._emit("node:select", { nodeId: String((_b = (_a = data.payload) == null ? void 0 : _a.nodeId) != null ? _b : ""), timestamp: Date.now() });
|
|
796
|
+
break;
|
|
797
|
+
case "viewer-pan-change" /* PAN_CHANGE */:
|
|
798
|
+
this._emit("interaction:pan-change", { enabled: Boolean((_c = data.payload) == null ? void 0 : _c.enabled) });
|
|
799
|
+
break;
|
|
800
|
+
case "viewer-pdf-plan-mode" /* PDF_PLAN_MODE */: {
|
|
801
|
+
const payload = data.payload;
|
|
802
|
+
this._emit("toolbar:pdf-plan-mode", {
|
|
803
|
+
mode: "plan",
|
|
804
|
+
timestamp: Number(payload == null ? void 0 : payload.timestamp) || Date.now()
|
|
805
|
+
});
|
|
806
|
+
break;
|
|
807
|
+
}
|
|
808
|
+
case "viewer-pdf-document-mode" /* PDF_DOCUMENT_MODE */: {
|
|
809
|
+
const payload = data.payload;
|
|
810
|
+
this._emit("toolbar:pdf-document-mode", {
|
|
811
|
+
mode: "document",
|
|
812
|
+
timestamp: Number(payload == null ? void 0 : payload.timestamp) || Date.now()
|
|
813
|
+
});
|
|
814
|
+
break;
|
|
815
|
+
}
|
|
816
|
+
case "viewer-pdf-first-page" /* PDF_FIRST_PAGE */: {
|
|
817
|
+
const payload = data.payload;
|
|
818
|
+
this._emit("toolbar:pdf-first-page", {
|
|
819
|
+
timestamp: Number(payload == null ? void 0 : payload.timestamp) || Date.now()
|
|
820
|
+
});
|
|
821
|
+
break;
|
|
822
|
+
}
|
|
823
|
+
case "viewer-pdf-previous-page" /* PDF_PREVIOUS_PAGE */: {
|
|
824
|
+
const payload = data.payload;
|
|
825
|
+
this._emit("toolbar:pdf-previous-page", {
|
|
826
|
+
timestamp: Number(payload == null ? void 0 : payload.timestamp) || Date.now()
|
|
827
|
+
});
|
|
828
|
+
break;
|
|
829
|
+
}
|
|
830
|
+
case "viewer-pdf-next-page" /* PDF_NEXT_PAGE */: {
|
|
831
|
+
const payload = data.payload;
|
|
832
|
+
this._emit("toolbar:pdf-next-page", {
|
|
833
|
+
timestamp: Number(payload == null ? void 0 : payload.timestamp) || Date.now()
|
|
834
|
+
});
|
|
835
|
+
break;
|
|
836
|
+
}
|
|
837
|
+
case "viewer-pdf-last-page" /* PDF_LAST_PAGE */: {
|
|
838
|
+
const payload = data.payload;
|
|
839
|
+
this._emit("toolbar:pdf-last-page", {
|
|
840
|
+
timestamp: Number(payload == null ? void 0 : payload.timestamp) || Date.now()
|
|
841
|
+
});
|
|
842
|
+
break;
|
|
843
|
+
}
|
|
844
|
+
case "viewer-pdf-current-page" /* PDF_CURRENT_PAGE */: {
|
|
845
|
+
const payload = data.payload;
|
|
846
|
+
if (!payload) break;
|
|
847
|
+
this._emit("toolbar:pdf-current-page", {
|
|
848
|
+
pageIndex: Number(payload.pageIndex) || 0,
|
|
849
|
+
pageNumber: Number(payload.pageNumber) || 1,
|
|
850
|
+
timestamp: Number(payload.timestamp) || Date.now()
|
|
851
|
+
});
|
|
852
|
+
break;
|
|
853
|
+
}
|
|
854
|
+
case "viewer-tree-node-ids" /* TREE_NODE_IDS */: {
|
|
855
|
+
const payload = data.payload;
|
|
856
|
+
if (!payload || !payload.requestId || !Array.isArray(payload.nodeIds)) break;
|
|
857
|
+
this._emit("modelTree:node-ids", {
|
|
858
|
+
requestId: String(payload.requestId),
|
|
859
|
+
nodeIds: payload.nodeIds.map(String),
|
|
860
|
+
timestamp: Number(payload.timestamp) || Date.now()
|
|
861
|
+
});
|
|
862
|
+
break;
|
|
863
|
+
}
|
|
864
|
+
case "viewer-sheets-list" /* SHEETS_LIST */: {
|
|
865
|
+
const payload = data.payload;
|
|
866
|
+
if (!payload || !payload.requestId || !Array.isArray(payload.sheets)) break;
|
|
867
|
+
this._emit("sheets:list", {
|
|
868
|
+
requestId: String(payload.requestId),
|
|
869
|
+
sheets: payload.sheets.map((sheet) => {
|
|
870
|
+
var _a2;
|
|
871
|
+
return {
|
|
872
|
+
id: sheet.id,
|
|
873
|
+
name: String((_a2 = sheet.name) != null ? _a2 : ""),
|
|
874
|
+
is3D: Boolean(sheet.is3D),
|
|
875
|
+
viewId: sheet.viewId ? String(sheet.viewId) : void 0
|
|
876
|
+
};
|
|
877
|
+
}),
|
|
878
|
+
activeSheetId: (_d = payload.activeSheetId) != null ? _d : null,
|
|
879
|
+
timestamp: Number(payload.timestamp) || Date.now()
|
|
880
|
+
});
|
|
881
|
+
break;
|
|
882
|
+
}
|
|
883
|
+
case "viewer-markup-list" /* MARKUP_LIST */: {
|
|
884
|
+
const payload = data.payload;
|
|
885
|
+
if (!payload || !payload.requestId || !Array.isArray(payload.markups)) break;
|
|
886
|
+
this._emit("markup:list", {
|
|
887
|
+
requestId: String(payload.requestId),
|
|
888
|
+
markups: payload.markups.map((markup) => {
|
|
889
|
+
var _a2, _b2;
|
|
890
|
+
return {
|
|
891
|
+
id: String(markup.id),
|
|
892
|
+
viewId: String(markup.viewId),
|
|
893
|
+
viewName: markup.viewName ? String(markup.viewName) : void 0,
|
|
894
|
+
title: String((_a2 = markup.title) != null ? _a2 : ""),
|
|
895
|
+
type: String((_b2 = markup.type) != null ? _b2 : ""),
|
|
896
|
+
shapeName: markup.shapeName ? String(markup.shapeName) : void 0,
|
|
897
|
+
createdDate: markup.createdDate ? String(markup.createdDate) : void 0,
|
|
898
|
+
modifiedDate: markup.modifiedDate ? String(markup.modifiedDate) : void 0,
|
|
899
|
+
createdBy: markup.createdBy ? String(markup.createdBy) : void 0,
|
|
900
|
+
lastModifiedBy: markup.lastModifiedBy ? String(markup.lastModifiedBy) : void 0
|
|
901
|
+
};
|
|
902
|
+
}),
|
|
903
|
+
timestamp: Number(payload.timestamp) || Date.now()
|
|
904
|
+
});
|
|
905
|
+
break;
|
|
906
|
+
}
|
|
907
|
+
case "viewer-markup-save-result" /* MARKUP_SAVE_RESULT */: {
|
|
908
|
+
const payload = data.payload;
|
|
909
|
+
if (!payload || !payload.requestId) break;
|
|
910
|
+
this._emit("markup:save", {
|
|
911
|
+
requestId: String(payload.requestId),
|
|
912
|
+
success: Boolean(payload.success),
|
|
913
|
+
error: payload.error ? String(payload.error) : void 0,
|
|
914
|
+
timestamp: Number(payload.timestamp) || Date.now()
|
|
915
|
+
});
|
|
916
|
+
break;
|
|
917
|
+
}
|
|
918
|
+
case "viewer-markup-cancel-result" /* MARKUP_CANCEL_RESULT */: {
|
|
919
|
+
const payload = data.payload;
|
|
920
|
+
if (!payload || !payload.requestId) break;
|
|
921
|
+
this._emit("markup:cancel", {
|
|
922
|
+
requestId: String(payload.requestId),
|
|
923
|
+
success: Boolean(payload.success),
|
|
924
|
+
error: payload.error ? String(payload.error) : void 0,
|
|
925
|
+
timestamp: Number(payload.timestamp) || Date.now()
|
|
926
|
+
});
|
|
927
|
+
break;
|
|
928
|
+
}
|
|
929
|
+
default:
|
|
930
|
+
break;
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
this.camera = new CameraModule(this);
|
|
934
|
+
this.interaction = new InteractionModule(this);
|
|
935
|
+
this.node = new NodeModule(this);
|
|
936
|
+
this.files = new FilesModule(this);
|
|
937
|
+
this.toolbar = new ToolbarModule(this);
|
|
938
|
+
this.modelTree = new ModelTreeModule(this);
|
|
939
|
+
this.markup = new MarkupModule(this);
|
|
940
|
+
}
|
|
941
|
+
// ===== options helpers =====
|
|
942
|
+
getOptions() {
|
|
943
|
+
return this.options;
|
|
944
|
+
}
|
|
945
|
+
patchOptions(next) {
|
|
946
|
+
this.options = { ...this.options, ...next };
|
|
947
|
+
}
|
|
948
|
+
getUrl() {
|
|
949
|
+
var _a;
|
|
950
|
+
return (_a = this.options.url) != null ? _a : null;
|
|
951
|
+
}
|
|
952
|
+
// ===== lifecycle =====
|
|
953
|
+
init() {
|
|
954
|
+
if (this.initialized) return;
|
|
955
|
+
this.containerEl = typeof this.options.container === "string" ? document.querySelector(this.options.container) : this.options.container;
|
|
956
|
+
if (!this.containerEl) throw new Error("Container element not found");
|
|
957
|
+
window.addEventListener("message", this.handleMessage);
|
|
958
|
+
this.initialized = true;
|
|
959
|
+
}
|
|
960
|
+
async render(file) {
|
|
961
|
+
this.ensureInit();
|
|
962
|
+
if (this.iframeEl) return;
|
|
963
|
+
if (!this.options.url) return this.files.render(file);
|
|
964
|
+
const iframe = document.createElement("iframe");
|
|
965
|
+
iframe.src = this.options.url;
|
|
966
|
+
iframe.style.border = "none";
|
|
967
|
+
iframe.style.width = this.options.width || "100%";
|
|
968
|
+
iframe.style.height = this.options.height || "100%";
|
|
969
|
+
iframe.width = this.options.width || "100%";
|
|
970
|
+
iframe.height = this.options.height || "100%";
|
|
971
|
+
if (this.options.sandbox) iframe.setAttribute("sandbox", this.options.sandbox);
|
|
972
|
+
this.containerEl.appendChild(iframe);
|
|
973
|
+
this.iframeEl = iframe;
|
|
974
|
+
}
|
|
975
|
+
open(url) {
|
|
976
|
+
this.ensureInit();
|
|
977
|
+
this.options.url = url;
|
|
978
|
+
if (!this.iframeEl) {
|
|
979
|
+
this.render();
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
this.iframeEl.src = url;
|
|
983
|
+
}
|
|
984
|
+
destroy() {
|
|
985
|
+
window.removeEventListener("message", this.handleMessage);
|
|
986
|
+
if (this.iframeEl && this.containerEl) {
|
|
987
|
+
try {
|
|
988
|
+
this.containerEl.removeChild(this.iframeEl);
|
|
989
|
+
} catch {
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
this.iframeEl = null;
|
|
993
|
+
this.containerEl = null;
|
|
994
|
+
this.initialized = false;
|
|
995
|
+
}
|
|
996
|
+
ensureInit() {
|
|
997
|
+
if (!this.initialized) throw new Error("Call viewer.init() before using viewer");
|
|
998
|
+
}
|
|
999
|
+
// ===== typed internal events used by modules =====
|
|
1000
|
+
_on(event, cb) {
|
|
1001
|
+
return this.emitter.on(event, cb);
|
|
1002
|
+
}
|
|
1003
|
+
_off(event, cb) {
|
|
1004
|
+
this.emitter.off(event, cb);
|
|
1005
|
+
}
|
|
1006
|
+
_emit(event, payload) {
|
|
1007
|
+
this.emitter.emit(event, payload);
|
|
1008
|
+
}
|
|
1009
|
+
// ===== postMessage bridge =====
|
|
1010
|
+
postToViewer(type, payload) {
|
|
1011
|
+
var _a;
|
|
1012
|
+
if (!((_a = this.iframeEl) == null ? void 0 : _a.contentWindow)) return;
|
|
1013
|
+
const message = {
|
|
1014
|
+
source: "HC_SDK" /* SDK */,
|
|
1015
|
+
type,
|
|
1016
|
+
payload
|
|
1017
|
+
};
|
|
1018
|
+
const targetOrigin = this.options.allowedOrigin || "*";
|
|
1019
|
+
this.iframeEl.contentWindow.postMessage(message, targetOrigin);
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
export {
|
|
1023
|
+
Viewer3D
|
|
1024
|
+
};
|