@dtducas/wh-forge-viewer 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/LICENSE +21 -0
- package/README.md +103 -0
- package/dist/index.esm.js +646 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +648 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,648 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var antd = require('antd');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
|
|
6
|
+
function _arrayLikeToArray(r, a) {
|
|
7
|
+
(null == a || a > r.length) && (a = r.length);
|
|
8
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
9
|
+
return n;
|
|
10
|
+
}
|
|
11
|
+
function _arrayWithHoles(r) {
|
|
12
|
+
if (Array.isArray(r)) return r;
|
|
13
|
+
}
|
|
14
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
15
|
+
try {
|
|
16
|
+
var i = n[a](c),
|
|
17
|
+
u = i.value;
|
|
18
|
+
} catch (n) {
|
|
19
|
+
return void e(n);
|
|
20
|
+
}
|
|
21
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
22
|
+
}
|
|
23
|
+
function _asyncToGenerator(n) {
|
|
24
|
+
return function () {
|
|
25
|
+
var t = this,
|
|
26
|
+
e = arguments;
|
|
27
|
+
return new Promise(function (r, o) {
|
|
28
|
+
var a = n.apply(t, e);
|
|
29
|
+
function _next(n) {
|
|
30
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
31
|
+
}
|
|
32
|
+
function _throw(n) {
|
|
33
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
34
|
+
}
|
|
35
|
+
_next(void 0);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function _iterableToArrayLimit(r, l) {
|
|
40
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
41
|
+
if (null != t) {
|
|
42
|
+
var e,
|
|
43
|
+
n,
|
|
44
|
+
i,
|
|
45
|
+
u,
|
|
46
|
+
a = [],
|
|
47
|
+
f = !0,
|
|
48
|
+
o = !1;
|
|
49
|
+
try {
|
|
50
|
+
if (i = (t = t.call(r)).next, 0 === l) {
|
|
51
|
+
if (Object(t) !== t) return;
|
|
52
|
+
f = !1;
|
|
53
|
+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
54
|
+
} catch (r) {
|
|
55
|
+
o = !0, n = r;
|
|
56
|
+
} finally {
|
|
57
|
+
try {
|
|
58
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
59
|
+
} finally {
|
|
60
|
+
if (o) throw n;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return a;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function _nonIterableRest() {
|
|
67
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
68
|
+
}
|
|
69
|
+
function _regenerator() {
|
|
70
|
+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
71
|
+
var e,
|
|
72
|
+
t,
|
|
73
|
+
r = "function" == typeof Symbol ? Symbol : {},
|
|
74
|
+
n = r.iterator || "@@iterator",
|
|
75
|
+
o = r.toStringTag || "@@toStringTag";
|
|
76
|
+
function i(r, n, o, i) {
|
|
77
|
+
var c = n && n.prototype instanceof Generator ? n : Generator,
|
|
78
|
+
u = Object.create(c.prototype);
|
|
79
|
+
return _regeneratorDefine(u, "_invoke", function (r, n, o) {
|
|
80
|
+
var i,
|
|
81
|
+
c,
|
|
82
|
+
u,
|
|
83
|
+
f = 0,
|
|
84
|
+
p = o || [],
|
|
85
|
+
y = !1,
|
|
86
|
+
G = {
|
|
87
|
+
p: 0,
|
|
88
|
+
n: 0,
|
|
89
|
+
v: e,
|
|
90
|
+
a: d,
|
|
91
|
+
f: d.bind(e, 4),
|
|
92
|
+
d: function (t, r) {
|
|
93
|
+
return i = t, c = 0, u = e, G.n = r, a;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
function d(r, n) {
|
|
97
|
+
for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
|
|
98
|
+
var o,
|
|
99
|
+
i = p[t],
|
|
100
|
+
d = G.p,
|
|
101
|
+
l = i[2];
|
|
102
|
+
r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
|
|
103
|
+
}
|
|
104
|
+
if (o || r > 1) return a;
|
|
105
|
+
throw y = !0, n;
|
|
106
|
+
}
|
|
107
|
+
return function (o, p, l) {
|
|
108
|
+
if (f > 1) throw TypeError("Generator is already running");
|
|
109
|
+
for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
|
|
110
|
+
i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
|
|
111
|
+
try {
|
|
112
|
+
if (f = 2, i) {
|
|
113
|
+
if (c || (o = "next"), t = i[o]) {
|
|
114
|
+
if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
|
|
115
|
+
if (!t.done) return t;
|
|
116
|
+
u = t.value, c < 2 && (c = 0);
|
|
117
|
+
} else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
|
|
118
|
+
i = e;
|
|
119
|
+
} else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
|
|
120
|
+
} catch (t) {
|
|
121
|
+
i = e, c = 1, u = t;
|
|
122
|
+
} finally {
|
|
123
|
+
f = 1;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
value: t,
|
|
128
|
+
done: y
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
}(r, o, i), !0), u;
|
|
132
|
+
}
|
|
133
|
+
var a = {};
|
|
134
|
+
function Generator() {}
|
|
135
|
+
function GeneratorFunction() {}
|
|
136
|
+
function GeneratorFunctionPrototype() {}
|
|
137
|
+
t = Object.getPrototypeOf;
|
|
138
|
+
var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
|
|
139
|
+
return this;
|
|
140
|
+
}), t),
|
|
141
|
+
u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
|
|
142
|
+
function f(e) {
|
|
143
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
|
|
144
|
+
}
|
|
145
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
|
|
146
|
+
return this;
|
|
147
|
+
}), _regeneratorDefine(u, "toString", function () {
|
|
148
|
+
return "[object Generator]";
|
|
149
|
+
}), (_regenerator = function () {
|
|
150
|
+
return {
|
|
151
|
+
w: i,
|
|
152
|
+
m: f
|
|
153
|
+
};
|
|
154
|
+
})();
|
|
155
|
+
}
|
|
156
|
+
function _regeneratorDefine(e, r, n, t) {
|
|
157
|
+
var i = Object.defineProperty;
|
|
158
|
+
try {
|
|
159
|
+
i({}, "", {});
|
|
160
|
+
} catch (e) {
|
|
161
|
+
i = 0;
|
|
162
|
+
}
|
|
163
|
+
_regeneratorDefine = function (e, r, n, t) {
|
|
164
|
+
function o(r, n) {
|
|
165
|
+
_regeneratorDefine(e, r, function (e) {
|
|
166
|
+
return this._invoke(r, n, e);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
r ? i ? i(e, r, {
|
|
170
|
+
value: n,
|
|
171
|
+
enumerable: !t,
|
|
172
|
+
configurable: !t,
|
|
173
|
+
writable: !t
|
|
174
|
+
}) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
|
|
175
|
+
}, _regeneratorDefine(e, r, n, t);
|
|
176
|
+
}
|
|
177
|
+
function _slicedToArray(r, e) {
|
|
178
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
179
|
+
}
|
|
180
|
+
function _unsupportedIterableToArray(r, a) {
|
|
181
|
+
if (r) {
|
|
182
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
183
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
184
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function registerToolbarExtension(Autodesk) {
|
|
189
|
+
function ToolbarExtension(viewer, options) {
|
|
190
|
+
Autodesk.Viewing.Extension.call(this, viewer, options);
|
|
191
|
+
this.viewer = viewer;
|
|
192
|
+
this.subToolbar = null;
|
|
193
|
+
this.paginationGroup = null;
|
|
194
|
+
this.viewables = [];
|
|
195
|
+
this.currentIndex = 0;
|
|
196
|
+
}
|
|
197
|
+
ToolbarExtension.prototype = Object.create(Autodesk.Viewing.Extension.prototype);
|
|
198
|
+
ToolbarExtension.prototype.constructor = ToolbarExtension;
|
|
199
|
+
ToolbarExtension.prototype.load = function () {
|
|
200
|
+
return true;
|
|
201
|
+
};
|
|
202
|
+
ToolbarExtension.prototype.unload = function () {
|
|
203
|
+
this.cleanupToolbar();
|
|
204
|
+
return true;
|
|
205
|
+
};
|
|
206
|
+
ToolbarExtension.prototype.cleanupToolbar = function () {
|
|
207
|
+
if (this.viewer.toolbar) {
|
|
208
|
+
if (this.subToolbar) {
|
|
209
|
+
this.viewer.toolbar.removeControl(this.subToolbar);
|
|
210
|
+
this.subToolbar = null;
|
|
211
|
+
}
|
|
212
|
+
if (this.paginationGroup) {
|
|
213
|
+
this.viewer.toolbar.removeControl(this.paginationGroup);
|
|
214
|
+
this.paginationGroup = null;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
ToolbarExtension.prototype.setViewables = function (viewables) {
|
|
219
|
+
var _this = this;
|
|
220
|
+
this.viewables = viewables;
|
|
221
|
+
this.currentIndex = 0;
|
|
222
|
+
this.updatePaginationState();
|
|
223
|
+
this.viewer.addEventListener(Autodesk.Viewing.MODEL_ADDED_EVENT, function (e) {
|
|
224
|
+
_this.updateCurrentIndexFromModel();
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
ToolbarExtension.prototype.updateCurrentIndexFromModel = function () {
|
|
228
|
+
if (!this.viewer.model || this.viewables.length === 0) return;
|
|
229
|
+
var currentNode = this.viewer.model.getDocumentNode();
|
|
230
|
+
if (currentNode) {
|
|
231
|
+
var currentGuid = currentNode.data.guid || currentNode.guid;
|
|
232
|
+
console.log('Checking Page Index. Current Node GUID:', currentGuid);
|
|
233
|
+
var index = this.viewables.findIndex(function (v) {
|
|
234
|
+
var vGuid = v.data && v.data.guid ? v.data.guid : v.guid;
|
|
235
|
+
return vGuid === currentGuid;
|
|
236
|
+
});
|
|
237
|
+
console.log('Found index:', index, 'Current stored index:', this.currentIndex);
|
|
238
|
+
if (index !== -1) {
|
|
239
|
+
this.currentIndex = index;
|
|
240
|
+
}
|
|
241
|
+
this.updatePaginationState();
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
ToolbarExtension.prototype.updatePaginationState = function () {
|
|
245
|
+
if (!this.paginationGroup) return;
|
|
246
|
+
var totalBtn = this.paginationGroup.getControl('total-page-label');
|
|
247
|
+
if (totalBtn) {
|
|
248
|
+
var current = this.viewables.length > 0 ? this.currentIndex + 1 : 0;
|
|
249
|
+
var total = this.viewables.length;
|
|
250
|
+
totalBtn.setToolTip("Page ".concat(current, " of ").concat(total));
|
|
251
|
+
var domElem = totalBtn.container;
|
|
252
|
+
if (domElem) {
|
|
253
|
+
domElem.innerHTML = "<div style=\"display: flex; align-items: center; justify-content: center; height: 100%; padding: 0 10px; color: white; font-size: 14px; white-space: nowrap;\">".concat(current, " / ").concat(total, "</div>");
|
|
254
|
+
}
|
|
255
|
+
console.log("Pagination updated: Page ".concat(current, " of ").concat(total));
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
ToolbarExtension.prototype.loadCurrentViewable = function () {
|
|
259
|
+
var _this2 = this;
|
|
260
|
+
if (this.viewables.length > 0 && this.viewables[this.currentIndex]) {
|
|
261
|
+
var viewer = this.viewer;
|
|
262
|
+
var toolbar = viewer.toolbar;
|
|
263
|
+
viewer.loadDocumentNode(viewer.model.getDocumentNode().getDocument(), this.viewables[this.currentIndex]).then(function () {
|
|
264
|
+
console.log('Model loaded, re-applying toolbar customization');
|
|
265
|
+
var defaultGroups = ['settingsTools', 'modelTools', 'navTools'];
|
|
266
|
+
defaultGroups.forEach(function (id) {
|
|
267
|
+
var group = toolbar.getControl(id);
|
|
268
|
+
if (group) group.setVisible(false);
|
|
269
|
+
});
|
|
270
|
+
var toolGroupExists = toolbar.getControl('custom-tool-group');
|
|
271
|
+
var paginationGroupExists = toolbar.getControl('custom-pagination-group');
|
|
272
|
+
if (!toolGroupExists && _this2.subToolbar) {
|
|
273
|
+
toolbar.addControl(_this2.subToolbar);
|
|
274
|
+
}
|
|
275
|
+
if (!paginationGroupExists && _this2.paginationGroup) {
|
|
276
|
+
toolbar.addControl(_this2.paginationGroup);
|
|
277
|
+
}
|
|
278
|
+
if (_this2.subToolbar) _this2.subToolbar.setVisible(true);
|
|
279
|
+
if (_this2.paginationGroup) _this2.paginationGroup.setVisible(true);
|
|
280
|
+
toolbar.setVisible(true);
|
|
281
|
+
_this2.updatePaginationState();
|
|
282
|
+
})["catch"](function (err) {
|
|
283
|
+
return console.error('Error loading viewable:', err);
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
ToolbarExtension.prototype.onToolbarCreated = function (toolbar) {
|
|
288
|
+
var _this3 = this;
|
|
289
|
+
this.refreshToolbar();
|
|
290
|
+
this.viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, function () {
|
|
291
|
+
setTimeout(function () {
|
|
292
|
+
console.log('GEOMETRY_LOADED Event - Refreshing Toolbar');
|
|
293
|
+
_this3.refreshToolbar();
|
|
294
|
+
_this3.updateCurrentIndexFromModel();
|
|
295
|
+
}, 100);
|
|
296
|
+
});
|
|
297
|
+
this.viewer.addEventListener(Autodesk.Viewing.TOOLBAR_CREATED_EVENT, function () {
|
|
298
|
+
setTimeout(function () {
|
|
299
|
+
console.log('TOOLBAR_CREATED Event - Refreshing Toolbar');
|
|
300
|
+
_this3.refreshToolbar();
|
|
301
|
+
}, 10);
|
|
302
|
+
});
|
|
303
|
+
if (this._toolbarInterval) clearInterval(this._toolbarInterval);
|
|
304
|
+
this._toolbarInterval = setInterval(function () {
|
|
305
|
+
if (_this3.viewer && _this3.viewer.toolbar) {
|
|
306
|
+
var toolGroup = _this3.viewer.toolbar.getControl('custom-tool-group');
|
|
307
|
+
var pagGroup = _this3.viewer.toolbar.getControl('custom-pagination-group');
|
|
308
|
+
if (!toolGroup || !pagGroup) {
|
|
309
|
+
console.log('Polling found missing toolbar groups - restoring...');
|
|
310
|
+
_this3.refreshToolbar();
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}, 200);
|
|
314
|
+
};
|
|
315
|
+
var originalUnload = ToolbarExtension.prototype.unload;
|
|
316
|
+
ToolbarExtension.prototype.unload = function () {
|
|
317
|
+
if (this._toolbarInterval) {
|
|
318
|
+
clearInterval(this._toolbarInterval);
|
|
319
|
+
this._toolbarInterval = null;
|
|
320
|
+
}
|
|
321
|
+
return originalUnload.call(this);
|
|
322
|
+
};
|
|
323
|
+
ToolbarExtension.prototype.refreshToolbar = function () {
|
|
324
|
+
var viewer = this.viewer;
|
|
325
|
+
var toolbar = viewer.toolbar;
|
|
326
|
+
if (!toolbar) return;
|
|
327
|
+
var defaultGroups = ['settingsTools', 'modelTools', 'navTools'];
|
|
328
|
+
defaultGroups.forEach(function (id) {
|
|
329
|
+
var group = toolbar.getControl(id);
|
|
330
|
+
if (group) {
|
|
331
|
+
group.setVisible(false);
|
|
332
|
+
if (group.container) {
|
|
333
|
+
group.container.style.display = 'none';
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
var toolGroup = toolbar.getControl('custom-tool-group');
|
|
338
|
+
var pagGroup = toolbar.getControl('custom-pagination-group');
|
|
339
|
+
if (!toolGroup) {
|
|
340
|
+
console.log('Custom Tool Group missing, recreating...');
|
|
341
|
+
if (this.subToolbar) {
|
|
342
|
+
this.subToolbar = null;
|
|
343
|
+
}
|
|
344
|
+
this.createToolGroup(toolbar);
|
|
345
|
+
} else {
|
|
346
|
+
toolGroup.setVisible(true);
|
|
347
|
+
this.subToolbar = toolGroup;
|
|
348
|
+
}
|
|
349
|
+
if (!pagGroup) {
|
|
350
|
+
console.log('Custom Pagination Group missing, recreating...');
|
|
351
|
+
if (this.paginationGroup) {
|
|
352
|
+
this.paginationGroup = null;
|
|
353
|
+
}
|
|
354
|
+
this.createPaginationGroup(toolbar);
|
|
355
|
+
} else {
|
|
356
|
+
pagGroup.setVisible(true);
|
|
357
|
+
this.paginationGroup = pagGroup;
|
|
358
|
+
}
|
|
359
|
+
toolbar.setVisible(true);
|
|
360
|
+
this.updatePaginationState();
|
|
361
|
+
};
|
|
362
|
+
ToolbarExtension.prototype.createToolGroup = function (toolbar) {
|
|
363
|
+
var _this4 = this;
|
|
364
|
+
var viewer = this.viewer;
|
|
365
|
+
this.subToolbar = new Autodesk.Viewing.UI.ControlGroup('custom-tool-group');
|
|
366
|
+
toolbar.addControl(this.subToolbar);
|
|
367
|
+
var panBtn = new Autodesk.Viewing.UI.Button('custom-pan-btn');
|
|
368
|
+
panBtn.setIcon('adsk-icon-pan');
|
|
369
|
+
panBtn.setToolTip('Pan');
|
|
370
|
+
panBtn.onClick = function () {
|
|
371
|
+
return viewer.setTool('pan');
|
|
372
|
+
};
|
|
373
|
+
this.subToolbar.addControl(panBtn);
|
|
374
|
+
var docBrowserBtn = new Autodesk.Viewing.UI.Button('custom-doc-browser-btn');
|
|
375
|
+
docBrowserBtn.setIcon('adsk-icon-documentModels');
|
|
376
|
+
docBrowserBtn.setToolTip('Document Browser');
|
|
377
|
+
docBrowserBtn.onClick = function () {
|
|
378
|
+
var ext = viewer.getExtension('Autodesk.DocumentBrowser');
|
|
379
|
+
if (ext && ext.ui) ext.ui.togglePanel();
|
|
380
|
+
};
|
|
381
|
+
this.subToolbar.addControl(docBrowserBtn);
|
|
382
|
+
var downloadBtn = new Autodesk.Viewing.UI.Button('custom-download-btn');
|
|
383
|
+
downloadBtn.setIcon('adsk-icon-custom-download');
|
|
384
|
+
downloadBtn.setToolTip('Download File');
|
|
385
|
+
downloadBtn.onClick = function () {
|
|
386
|
+
if (_this4.options && _this4.options.filePath) {
|
|
387
|
+
var a = document.createElement('a');
|
|
388
|
+
a.href = _this4.options.filePath;
|
|
389
|
+
a.download = '';
|
|
390
|
+
document.body.appendChild(a);
|
|
391
|
+
a.click();
|
|
392
|
+
document.body.removeChild(a);
|
|
393
|
+
} else {
|
|
394
|
+
console.warn('FilePath not available in extension options');
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
this.subToolbar.addControl(downloadBtn);
|
|
398
|
+
};
|
|
399
|
+
ToolbarExtension.prototype.createPaginationGroup = function (toolbar) {
|
|
400
|
+
var _this5 = this;
|
|
401
|
+
this.paginationGroup = new Autodesk.Viewing.UI.ControlGroup('custom-pagination-group');
|
|
402
|
+
toolbar.addControl(this.paginationGroup);
|
|
403
|
+
var prevBtn = new Autodesk.Viewing.UI.Button('prev-page-btn');
|
|
404
|
+
prevBtn.setIcon('adsk-icon-custom-prev');
|
|
405
|
+
prevBtn.addClass('custom-prev-btn');
|
|
406
|
+
prevBtn.setToolTip('Previous Page');
|
|
407
|
+
prevBtn.onClick = function () {
|
|
408
|
+
if (_this5.viewables.length > 0) {
|
|
409
|
+
_this5.currentIndex = (_this5.currentIndex - 1 + _this5.viewables.length) % _this5.viewables.length;
|
|
410
|
+
_this5.loadCurrentViewable();
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
this.paginationGroup.addControl(prevBtn);
|
|
414
|
+
var labelBtn = new Autodesk.Viewing.UI.Button('total-page-label');
|
|
415
|
+
labelBtn.setToolTip('Page info');
|
|
416
|
+
this.paginationGroup.addControl(labelBtn);
|
|
417
|
+
var nextBtn = new Autodesk.Viewing.UI.Button('next-page-btn');
|
|
418
|
+
nextBtn.setIcon('adsk-icon-custom-next');
|
|
419
|
+
nextBtn.addClass('custom-next-btn');
|
|
420
|
+
nextBtn.setToolTip('Next Page');
|
|
421
|
+
nextBtn.onClick = function () {
|
|
422
|
+
if (_this5.viewables.length > 0) {
|
|
423
|
+
_this5.currentIndex = (_this5.currentIndex + 1) % _this5.viewables.length;
|
|
424
|
+
_this5.loadCurrentViewable();
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
this.paginationGroup.addControl(nextBtn);
|
|
428
|
+
};
|
|
429
|
+
Autodesk.Viewing.theExtensionManager.registerExtension('ToolbarExtension', ToolbarExtension);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
var useCss = function useCss(href) {
|
|
433
|
+
react.useEffect(function () {
|
|
434
|
+
if (!href) return;
|
|
435
|
+
var link = document.createElement('link');
|
|
436
|
+
link.href = href;
|
|
437
|
+
link.rel = 'stylesheet';
|
|
438
|
+
document.head.appendChild(link);
|
|
439
|
+
return function () {
|
|
440
|
+
document.head.removeChild(link);
|
|
441
|
+
};
|
|
442
|
+
}, [href]);
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
var scriptCache = new Set();
|
|
446
|
+
var useScript = function useScript(src) {
|
|
447
|
+
var _useState = react.useState(src ? 'loading' : 'idle'),
|
|
448
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
449
|
+
status = _useState2[0],
|
|
450
|
+
setStatus = _useState2[1];
|
|
451
|
+
react.useEffect(function () {
|
|
452
|
+
if (!src) {
|
|
453
|
+
setStatus('idle');
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (scriptCache.has(src)) {
|
|
457
|
+
setStatus('ready');
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
var script = document.querySelector("script[src=\"".concat(src, "\"]"));
|
|
461
|
+
if (!script) {
|
|
462
|
+
script = document.createElement('script');
|
|
463
|
+
script.src = src;
|
|
464
|
+
script.async = true;
|
|
465
|
+
script.setAttribute('data-status', 'loading');
|
|
466
|
+
document.body.appendChild(script);
|
|
467
|
+
var setAttributeFromEvent = function setAttributeFromEvent(event) {
|
|
468
|
+
var _script;
|
|
469
|
+
var attribute = event.type === 'load' ? 'ready' : 'error';
|
|
470
|
+
(_script = script) === null || _script === void 0 || _script.setAttribute('data-status', attribute);
|
|
471
|
+
if (attribute === 'ready') scriptCache.add(src);
|
|
472
|
+
setStatus(attribute);
|
|
473
|
+
};
|
|
474
|
+
script.addEventListener('load', setAttributeFromEvent);
|
|
475
|
+
script.addEventListener('error', setAttributeFromEvent);
|
|
476
|
+
} else {
|
|
477
|
+
setStatus(script.getAttribute('data-status'));
|
|
478
|
+
}
|
|
479
|
+
var setStateFromEvent = function setStateFromEvent(event) {
|
|
480
|
+
setStatus(event.type === 'load' ? 'ready' : 'error');
|
|
481
|
+
};
|
|
482
|
+
script.addEventListener('load', setStateFromEvent);
|
|
483
|
+
script.addEventListener('error', setStateFromEvent);
|
|
484
|
+
return function () {
|
|
485
|
+
if (script) {
|
|
486
|
+
script.removeEventListener('load', setStateFromEvent);
|
|
487
|
+
script.removeEventListener('error', setStateFromEvent);
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
}, [src]);
|
|
491
|
+
return status;
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
function styleInject(css, ref) {
|
|
495
|
+
if ( ref === void 0 ) ref = {};
|
|
496
|
+
var insertAt = ref.insertAt;
|
|
497
|
+
|
|
498
|
+
if (!css || typeof document === 'undefined') { return; }
|
|
499
|
+
|
|
500
|
+
var head = document.head || document.getElementsByTagName('head')[0];
|
|
501
|
+
var style = document.createElement('style');
|
|
502
|
+
style.type = 'text/css';
|
|
503
|
+
|
|
504
|
+
if (insertAt === 'top') {
|
|
505
|
+
if (head.firstChild) {
|
|
506
|
+
head.insertBefore(style, head.firstChild);
|
|
507
|
+
} else {
|
|
508
|
+
head.appendChild(style);
|
|
509
|
+
}
|
|
510
|
+
} else {
|
|
511
|
+
head.appendChild(style);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
if (style.styleSheet) {
|
|
515
|
+
style.styleSheet.cssText = css;
|
|
516
|
+
} else {
|
|
517
|
+
style.appendChild(document.createTextNode(css));
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
var css_248z$1 = "#navTools,\n#modelTools,\n#settingsTools,\n#measureTools {\n display: none !important;\n visibility: hidden !important;\n}\n#guiviewer3d-toolbar {\n display: flex !important;\n align-items: center !important;\n justify-content: center !important;\n gap: 20px;\n position: fixed !important;\n bottom: 10px !important;\n left: 50% !important;\n transform: translateX(-50%) !important;\n width: auto !important;\n border-radius: 4px !important;\n padding: 8px 12px !important;\n}\n#custom-tool-group {\n display: flex !important;\n margin: 0 !important;\n padding: 0 !important;\n}\n#custom-pagination-group {\n display: flex !important;\n position: relative !important;\n margin: 0 !important;\n padding: 0 !important;\n transform: none !important;\n left: auto !important;\n}\n";
|
|
522
|
+
styleInject(css_248z$1);
|
|
523
|
+
|
|
524
|
+
var css_248z = "/* Custom icon styles for toolbar using SVG */\n\n/* Download icon - custom SVG */\n.adsk-icon-custom-download::before {\n content: '';\n display: inline-block;\n width: 24px;\n height: 24px;\n background-image: url('data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M17 9.00195C19.175 9.01406 20.3529 9.11051 21.1213 9.8789C22 10.7576 22 12.1718 22 15.0002V16.0002C22 18.8286 22 20.2429 21.1213 21.1215C20.2426 22.0002 18.8284 22.0002 16 22.0002H8C5.17157 22.0002 3.75736 22.0002 2.87868 21.1215C2 20.2429 2 18.8286 2 16.0002L2 15.0002C2 12.1718 2 10.7576 2.87868 9.87889C3.64706 9.11051 4.82497 9.01406 7 9.00195\" stroke=\"%23FFFFFF\" stroke-width=\"1.5\" stroke-linecap=\"round\"/><path d=\"M12 2L12 15M12 15L9 11.5M12 15L15 11.5\" stroke=\"%23FFFFFF\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/></svg>');\n background-repeat: no-repeat;\n background-position: center;\n background-size: contain;\n}\n\n/* Previous page icon - Font Awesome chevron left */\n.adsk-icon-custom-prev::before {\n content: '';\n display: inline-block;\n width: 24px;\n height: 24px;\n background-image: url('data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 640 640\"><path fill=\"%23FFFFFF\" d=\"M201.4 297.4C188.9 309.9 188.9 330.2 201.4 342.7L361.4 502.7C373.9 515.2 394.2 515.2 406.7 502.7C419.2 490.2 419.2 469.9 406.7 457.4L269.3 320L406.6 182.6C419.1 170.1 419.1 149.8 406.6 137.3C394.1 124.8 373.8 124.8 361.3 137.3L201.3 297.3z\"/></svg>');\n background-repeat: no-repeat;\n background-position: center;\n background-size: 16px 16px;\n}\n\n/* Next page icon - Font Awesome chevron right */\n.adsk-icon-custom-next::before {\n content: '';\n display: inline-block;\n width: 24px;\n height: 24px;\n background-image: url('data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 640 640\"><path fill=\"%23FFFFFF\" d=\"M439.1 297.4C451.6 309.9 451.6 330.2 439.1 342.7L279.1 502.7C266.6 515.2 246.3 515.2 233.8 502.7C221.3 490.2 221.3 469.9 233.8 457.4L371.2 320L233.9 182.6C221.4 170.1 221.4 149.8 233.9 137.3C246.4 124.8 266.7 124.8 279.2 137.3L439.2 297.3z\"/></svg>');\n background-repeat: no-repeat;\n background-position: center;\n background-size: 16px 16px;\n}\n\n/* Fallback for adsk-icon-caret-left and adsk-icon-caret-right if not defined */\n.adsk-icon-caret-left::before {\n content: '[';\n font-family: 'adsk-viewing';\n}\n\n.adsk-icon-caret-right::before {\n content: ']';\n font-family: 'adsk-viewing';\n}\n";
|
|
525
|
+
styleInject(css_248z);
|
|
526
|
+
|
|
527
|
+
var ViewerForgePDF = function ViewerForgePDF(_ref) {
|
|
528
|
+
var filePath = _ref.filePath,
|
|
529
|
+
fileExt = _ref.fileExt,
|
|
530
|
+
setViewer = _ref.setViewer;
|
|
531
|
+
useCss('https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/style.min.css');
|
|
532
|
+
var status = useScript('https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/viewer3D.min.js');
|
|
533
|
+
react.useEffect(function () {
|
|
534
|
+
if (status === 'ready' && window.Autodesk) {
|
|
535
|
+
var Autodesk = window.Autodesk;
|
|
536
|
+
if (!fileExt) {
|
|
537
|
+
antd.message.warning('You need to provide file extension');
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
var validExts = ['pdf', 'dwf', 'dwfx'];
|
|
541
|
+
if (!validExts.includes(fileExt.toLowerCase())) {
|
|
542
|
+
antd.message.warning('Only support pdf, dwf, dwfx format');
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
Autodesk.Viewing.Initializer({
|
|
546
|
+
env: 'Local'
|
|
547
|
+
}, /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
548
|
+
var viewerDiv, viewer, isDWF, handleLoadSuccess, xhr;
|
|
549
|
+
return _regenerator().w(function (_context) {
|
|
550
|
+
while (1) switch (_context.n) {
|
|
551
|
+
case 0:
|
|
552
|
+
registerToolbarExtension(Autodesk);
|
|
553
|
+
viewerDiv = document.getElementById('forgeViewerPDF');
|
|
554
|
+
viewerDiv.innerHTML = '';
|
|
555
|
+
viewer = new Autodesk.Viewing.GuiViewer3D(viewerDiv);
|
|
556
|
+
viewer.start();
|
|
557
|
+
viewer.loadExtension('Autodesk.DocumentBrowser');
|
|
558
|
+
viewer.loadExtension('Autodesk.Viewing.MarkupsCore');
|
|
559
|
+
viewer.loadExtension('Autodesk.Viewing.MarkupsGui');
|
|
560
|
+
viewer.loadExtension('ToolbarExtension', {
|
|
561
|
+
filePath: filePath
|
|
562
|
+
});
|
|
563
|
+
viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, function (e) {
|
|
564
|
+
e.target.loadExtension('Autodesk.Viewing.MarkupsCore');
|
|
565
|
+
e.target.loadExtension('Autodesk.Viewing.MarkupsGui');
|
|
566
|
+
});
|
|
567
|
+
isDWF = fileExt.toLowerCase() === 'pdf' ? 'Autodesk.PDF' : 'Autodesk.DWF';
|
|
568
|
+
_context.n = 1;
|
|
569
|
+
return viewer.loadExtension(isDWF);
|
|
570
|
+
case 1:
|
|
571
|
+
handleLoadSuccess = function handleLoadSuccess(e) {
|
|
572
|
+
try {
|
|
573
|
+
viewer.setReverseZoomDirection(true);
|
|
574
|
+
var root = e.getDocumentNode().getRootNode();
|
|
575
|
+
var view3d = root.search({
|
|
576
|
+
type: 'geometry',
|
|
577
|
+
role: '3d',
|
|
578
|
+
progress: 'complete'
|
|
579
|
+
}, true);
|
|
580
|
+
var view2d = root.search({
|
|
581
|
+
type: 'geometry',
|
|
582
|
+
role: '2d',
|
|
583
|
+
progress: 'complete'
|
|
584
|
+
}, true);
|
|
585
|
+
var viewables = view3d.concat(view2d);
|
|
586
|
+
var toolbarExt = viewer.getExtension('ToolbarExtension');
|
|
587
|
+
if (toolbarExt && typeof toolbarExt.setViewables === 'function') {
|
|
588
|
+
toolbarExt.setViewables(viewables);
|
|
589
|
+
}
|
|
590
|
+
if (viewer.toolbar) {
|
|
591
|
+
viewer.toolbar.setVisible(true);
|
|
592
|
+
console.log('Toolbar forced visible');
|
|
593
|
+
}
|
|
594
|
+
if (viewables.length > 1) {
|
|
595
|
+
var documentBrowser = viewer.getExtension('Autodesk.DocumentBrowser');
|
|
596
|
+
if (documentBrowser) {
|
|
597
|
+
if (documentBrowser.ui.panel) {
|
|
598
|
+
documentBrowser.ui.panel.container.style.top = 0;
|
|
599
|
+
documentBrowser.ui.panel.container.style.left = 'unset';
|
|
600
|
+
documentBrowser.ui.panel.container.style.right = '0px';
|
|
601
|
+
documentBrowser.ui.panel.container.style.width = '200px';
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
if (setViewer) setViewer(viewer);
|
|
606
|
+
} catch (err) {
|
|
607
|
+
console.error('Error in handleLoadSuccess:', err);
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
if (isDWF === 'Autodesk.DWF') {
|
|
611
|
+
xhr = new XMLHttpRequest();
|
|
612
|
+
xhr.open('GET', filePath, true);
|
|
613
|
+
xhr.responseType = 'blob';
|
|
614
|
+
xhr.onload = function () {
|
|
615
|
+
if (this.status === 200) {
|
|
616
|
+
var myBlob = this.response;
|
|
617
|
+
var url1 = window.URL.createObjectURL(myBlob);
|
|
618
|
+
viewer.loadModel(url1 + '#.dwf', {}, handleLoadSuccess);
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
xhr.send();
|
|
622
|
+
} else {
|
|
623
|
+
viewer.loadModel(filePath, {}, handleLoadSuccess);
|
|
624
|
+
}
|
|
625
|
+
case 2:
|
|
626
|
+
return _context.a(2);
|
|
627
|
+
}
|
|
628
|
+
}, _callee);
|
|
629
|
+
})));
|
|
630
|
+
}
|
|
631
|
+
}, [status, filePath, fileExt, setViewer]);
|
|
632
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
633
|
+
style: {
|
|
634
|
+
position: 'relative',
|
|
635
|
+
width: '100%',
|
|
636
|
+
height: '100%'
|
|
637
|
+
}
|
|
638
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
639
|
+
id: "forgeViewerPDF",
|
|
640
|
+
style: {
|
|
641
|
+
width: '100%',
|
|
642
|
+
height: '100%'
|
|
643
|
+
}
|
|
644
|
+
}));
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
exports.ViewerForgePDF = ViewerForgePDF;
|
|
648
|
+
//# sourceMappingURL=index.js.map
|