@dtducas/wh-forge-viewer 1.0.5 → 1.0.7

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.esm.js CHANGED
@@ -184,542 +184,1672 @@ function _unsupportedIterableToArray(r, a) {
184
184
  }
185
185
  }
186
186
 
187
- function registerToolbarExtension(Autodesk) {
188
- function ToolbarExtension(viewer, options) {
189
- Autodesk.Viewing.Extension.call(this, viewer, options);
190
- this.viewer = viewer;
191
- this.subToolbar = null;
192
- this.paginationGroup = null;
193
- this.viewables = [];
194
- this.currentIndex = 0;
195
- this.docBrowserShouldBeOpen = false; // Track if doc browser should remain open
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
- }
187
+ /**
188
+ * Document Browser Configuration Constants
189
+ *
190
+ * @file document-browser.constants.ts
191
+ * @description Constants for Document Browser panel configuration and styling
192
+ */
193
+ const DOCUMENT_BROWSER_STYLES = {
194
+ top: '0',
195
+ left: 'unset',
196
+ right: '0px',
197
+ };
198
+
199
+ /**
200
+ * Event Names Constants
201
+ *
202
+ * @file events.constants.ts
203
+ * @description Constants for Autodesk Forge events and custom application events
204
+ */
205
+ const EVENT_NAMES = {
206
+ // Autodesk Forge Events
207
+ GEOMETRY_LOADED: 'Autodesk.Viewing.GEOMETRY_LOADED_EVENT',
208
+ MODEL_ADDED: 'Autodesk.Viewing.MODEL_ADDED_EVENT',
209
+ TOOLBAR_CREATED: 'Autodesk.Viewing.TOOLBAR_CREATED_EVENT',
210
+ // Custom Application Events
211
+ PAGE_CHANGED: 'page:changed',
212
+ VIEWABLES_SET: 'viewables:set',
213
+ DOC_BROWSER_OPENED: 'docBrowser:opened',
214
+ DOC_BROWSER_CLOSED: 'docBrowser:closed',
215
+ TOOLBAR_BUTTON_CLICKED: 'toolbar:button:clicked',
216
+ PAN_ACTIVATED: 'pan:activated',
217
+ DOWNLOAD_REQUESTED: 'download:requested',
218
+ };
219
+
220
+ /**
221
+ * Toolbar Configuration Constants
222
+ *
223
+ * @file toolbar.constants.ts
224
+ * @description Constants for custom toolbar buttons, groups, and refresh intervals
225
+ */
226
+ const DEFAULT_HIDDEN_TOOLBAR_GROUPS = [
227
+ 'settingsTools',
228
+ 'modelTools',
229
+ 'navTools',
230
+ ];
231
+ const CUSTOM_TOOLBAR_BUTTONS = {
232
+ PAN: {
233
+ id: 'custom-pan-btn',
234
+ icon: 'adsk-icon-pan',
235
+ tooltip: 'Pan',
236
+ },
237
+ DOC_BROWSER: {
238
+ id: 'custom-doc-browser-btn',
239
+ icon: 'adsk-icon-documentModels',
240
+ tooltip: 'Document Browser',
241
+ },
242
+ DOWNLOAD: {
243
+ id: 'custom-download-btn',
244
+ icon: 'adsk-icon-custom-download',
245
+ tooltip: 'Download File',
246
+ },
247
+ };
248
+ const PAGINATION_BUTTONS = {
249
+ PREV: {
250
+ id: 'prev-page-btn',
251
+ icon: 'adsk-icon-custom-prev',
252
+ tooltip: 'Previous Page',
253
+ },
254
+ NEXT: {
255
+ id: 'next-page-btn',
256
+ icon: 'adsk-icon-custom-next',
257
+ tooltip: 'Next Page',
258
+ },
259
+ LABEL: {
260
+ id: 'total-page-label',
261
+ tooltip: 'Page info',
262
+ },
263
+ };
264
+ const TOOLBAR_REFRESH_INTERVALS = {
265
+ HEALING_POLL: 8,
266
+ BUTTON_STATE_CHECK: 10,
267
+ DOM_SETTLE: 50,
268
+ GEOMETRY_SETTLE: 80,
269
+ EXTENSION_INIT: 150,
270
+ };
271
+ const TOOLBAR_CONTROL_GROUP_IDS = {
272
+ TOOLS: 'custom-tool-group',
273
+ PAGINATION: 'custom-pagination-group',
274
+ };
275
+
276
+ /**
277
+ * Autodesk Forge Viewer Configuration Constants
278
+ *
279
+ * @file viewer.constants.ts
280
+ * @description Constants for Forge Viewer initialization, CDN URLs, and file type mappings
281
+ */
282
+ const FORGE_VIEWER_VERSION = '7.*';
283
+ const FORGE_VIEWER_CDN = 'https://developer.api.autodesk.com/modelderivative/v2/viewers';
284
+ const FORGE_STYLE_URL = `${FORGE_VIEWER_CDN}/${FORGE_VIEWER_VERSION}/style.min.css`;
285
+ const FORGE_SCRIPT_URL = `${FORGE_VIEWER_CDN}/${FORGE_VIEWER_VERSION}/viewer3D.min.js`;
286
+ const SUPPORTED_FILE_EXTENSIONS = ['pdf', 'dwf', 'dwfx'];
287
+ const FILE_EXTENSION_TO_VIEWER_EXTENSION = {
288
+ pdf: 'Autodesk.PDF',
289
+ dwf: 'Autodesk.DWF',
290
+ dwfx: 'Autodesk.DWF',
291
+ };
292
+ const GEOMETRY_SEARCH_CRITERIA = {
293
+ VIEW_3D: { type: 'geometry', role: '3d', progress: 'complete' },
294
+ VIEW_2D: { type: 'geometry', role: '2d', progress: 'complete' },
295
+ };
296
+
297
+ /******************************************************************************
298
+ Copyright (c) Microsoft Corporation.
299
+
300
+ Permission to use, copy, modify, and/or distribute this software for any
301
+ purpose with or without fee is hereby granted.
302
+
303
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
304
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
305
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
306
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
307
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
308
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
309
+ PERFORMANCE OF THIS SOFTWARE.
310
+ ***************************************************************************** */
311
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
312
+
313
+
314
+ function __awaiter(thisArg, _arguments, P, generator) {
315
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
316
+ return new (P || (P = Promise))(function (resolve, reject) {
317
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
318
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
319
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
320
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
321
+ });
322
+ }
323
+
324
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
325
+ var e = new Error(message);
326
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
327
+ };
328
+
329
+ /**
330
+ * DOM Utility Functions
331
+ *
332
+ * @file dom.utils.ts
333
+ * @description Utilities for safe DOM manipulation and querying
334
+ */
335
+ /**
336
+ * Find element by text content
337
+ */
338
+ function findElementByText(selector, text) {
339
+ var _a;
340
+ const elements = Array.from(document.querySelectorAll(selector));
341
+ return (_a = elements.find((el) => { var _a; return (_a = el.textContent) === null || _a === void 0 ? void 0 : _a.includes(text); })) !== null && _a !== void 0 ? _a : null;
342
+ }
343
+ /**
344
+ * Find thumbnail tab element using multiple selectors
345
+ */
346
+ function findThumbnailTab() {
347
+ return (document.querySelector('.docking-panel-thumbnail-view') ||
348
+ document.querySelector('[data-i18n="Thumbnails"]') ||
349
+ findElementByText('.adsk-control-group .adsk-button', 'Thumbnails'));
350
+ }
351
+ /**
352
+ * Safely click an element
353
+ */
354
+ function clickElement(element) {
355
+ if (element && 'click' in element) {
356
+ element.click();
216
357
  }
217
- };
218
- ToolbarExtension.prototype.setViewables = function (viewables) {
219
- var _this = this;
220
- this.viewables = viewables;
221
- this.currentIndex = 0;
222
- // If multiple pages, document browser will be auto-opened
223
- if (viewables.length > 1) {
224
- this.docBrowserShouldBeOpen = true;
225
- }
226
- this.updatePaginationState();
227
- this.viewer.addEventListener(Autodesk.Viewing.MODEL_ADDED_EVENT, function (e) {
228
- _this.updateCurrentIndexFromModel();
229
- });
230
- };
231
- ToolbarExtension.prototype.updateCurrentIndexFromModel = function () {
232
- if (!this.viewer.model || this.viewables.length === 0) return;
233
- var currentNode = this.viewer.model.getDocumentNode();
234
- if (currentNode) {
235
- var currentGuid = currentNode.data.guid || currentNode.guid;
236
- var index = this.viewables.findIndex(function (v) {
237
- var vGuid = v.data && v.data.guid ? v.data.guid : v.guid;
238
- return vGuid === currentGuid;
239
- });
240
- if (index !== -1) {
241
- this.currentIndex = index;
242
- }
243
- this.updatePaginationState();
358
+ }
359
+ /**
360
+ * Apply multiple styles to an element
361
+ */
362
+ function applyStyles(element, styles) {
363
+ if (element) {
364
+ Object.assign(element.style, styles);
244
365
  }
245
- };
246
- ToolbarExtension.prototype.updatePaginationState = function () {
247
- if (!this.paginationGroup) return;
366
+ }
248
367
 
249
- // Hide pagination group if there's only 1 page or no pages
250
- if (this.viewables.length <= 1) {
251
- this.paginationGroup.setVisible(false);
252
- // Also hide the container via CSS to ensure it's completely hidden
253
- if (this.paginationGroup.container) {
254
- this.paginationGroup.container.style.display = 'none';
255
- }
256
- return;
368
+ /**
369
+ * File Utility Functions
370
+ *
371
+ * @file file.utils.ts
372
+ * @description Utilities for file handling and path operations
373
+ */
374
+ /**
375
+ * Extract filename from URL or path
376
+ */
377
+ function extractFilenameFromPath(path) {
378
+ try {
379
+ const urlPath = new URL(path).pathname;
380
+ const filename = urlPath.split('/').pop();
381
+ return decodeURIComponent(filename || 'document.pdf');
257
382
  }
258
-
259
- // Show pagination group for multi-page documents
260
- this.paginationGroup.setVisible(true);
261
- // Ensure container is visible
262
- if (this.paginationGroup.container) {
263
- this.paginationGroup.container.style.display = '';
264
- }
265
- var totalBtn = this.paginationGroup.getControl('total-page-label');
266
- if (totalBtn) {
267
- var current = this.viewables.length > 0 ? this.currentIndex + 1 : 0;
268
- var total = this.viewables.length;
269
- totalBtn.setToolTip("Page ".concat(current, " of ").concat(total));
270
- var domElem = totalBtn.container;
271
- if (domElem) {
272
- 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>");
273
- }
383
+ catch (_a) {
384
+ const parts = path.split('/');
385
+ return parts[parts.length - 1] || 'document.pdf';
274
386
  }
275
- };
276
- ToolbarExtension.prototype.loadCurrentViewable = function () {
277
- var _this2 = this;
278
- if (this.viewables.length > 0 && this.viewables[this.currentIndex]) {
279
- var viewer = this.viewer;
280
- var toolbar = viewer.toolbar;
281
- var self = this;
387
+ }
282
388
 
283
- // Store Document Browser panel state before loading new page
284
- var docBrowserExt = viewer.getExtension('Autodesk.DocumentBrowser');
285
- var isCurrentlyOpen = docBrowserExt && docBrowserExt.ui && docBrowserExt.ui.panel && docBrowserExt.ui.panel.isVisible();
389
+ class DownloadService {
390
+ /**
391
+ * Download a file from URL
392
+ *
393
+ * @param fileUrl - URL of file to download
394
+ *
395
+ * @example
396
+ * const downloadService = new DownloadService();
397
+ * await downloadService.downloadFile('https://example.com/document.pdf');
398
+ */
399
+ downloadFile(fileUrl) {
400
+ return __awaiter(this, void 0, void 0, function* () {
401
+ try {
402
+ const response = yield fetch(fileUrl);
403
+ if (!response.ok) {
404
+ throw new Error(`HTTP error! status: ${response.status}`);
405
+ }
406
+ const blob = yield response.blob();
407
+ const filename = extractFilenameFromPath(fileUrl);
408
+ // Create download link
409
+ const blobUrl = URL.createObjectURL(blob);
410
+ const anchor = document.createElement('a');
411
+ anchor.href = blobUrl;
412
+ anchor.download = filename;
413
+ anchor.style.display = 'none';
414
+ // Trigger download
415
+ document.body.appendChild(anchor);
416
+ anchor.click();
417
+ document.body.removeChild(anchor);
418
+ // Cleanup
419
+ URL.revokeObjectURL(blobUrl);
420
+ }
421
+ catch (error) {
422
+ throw error;
423
+ }
424
+ });
425
+ }
426
+ }
286
427
 
287
- // Update flag - if currently open or flag is already set, keep it open
288
- if (isCurrentlyOpen) {
289
- this.docBrowserShouldBeOpen = true;
290
- }
428
+ class EventBus {
429
+ constructor() {
430
+ this.listeners = new Map();
431
+ // Private constructor for singleton pattern
432
+ }
433
+ /**
434
+ * Get singleton instance of EventBus
435
+ *
436
+ * @example
437
+ * const eventBus = EventBus.getInstance();
438
+ * eventBus.on('myEvent', (data) => console.log(data));
439
+ */
440
+ static getInstance() {
441
+ if (!EventBus.instance) {
442
+ EventBus.instance = new EventBus();
443
+ }
444
+ return EventBus.instance;
445
+ }
446
+ /**
447
+ * Subscribe to an event
448
+ *
449
+ * @param eventName - Event name to listen for
450
+ * @param listener - Callback function to execute when event is emitted
451
+ *
452
+ * @example
453
+ * eventBus.on('page:changed', (data) => {
454
+ * console.log('Page changed to:', data.index);
455
+ * });
456
+ */
457
+ on(eventName, listener) {
458
+ if (!this.listeners.has(eventName)) {
459
+ this.listeners.set(eventName, new Set());
460
+ }
461
+ this.listeners.get(eventName).add(listener);
462
+ }
463
+ /**
464
+ * Unsubscribe from an event
465
+ *
466
+ * @param eventName - Event name to stop listening for
467
+ * @param listener - Callback function to remove
468
+ *
469
+ * @example
470
+ * const handler = (data) => console.log(data);
471
+ * eventBus.on('myEvent', handler);
472
+ * eventBus.off('myEvent', handler);
473
+ */
474
+ off(eventName, listener) {
475
+ const listeners = this.listeners.get(eventName);
476
+ if (listeners) {
477
+ listeners.delete(listener);
478
+ if (listeners.size === 0) {
479
+ this.listeners.delete(eventName);
480
+ }
481
+ }
482
+ }
483
+ /**
484
+ * Emit an event to all subscribers
485
+ *
486
+ * @param eventName - Event name to emit
487
+ * @param data - Data to pass to subscribers
488
+ *
489
+ * @example
490
+ * eventBus.emit('page:changed', { index: 5, viewable: {...} });
491
+ */
492
+ emit(eventName, data) {
493
+ const listeners = this.listeners.get(eventName);
494
+ if (listeners) {
495
+ listeners.forEach((listener) => {
496
+ try {
497
+ listener(data);
498
+ }
499
+ catch (error) {
500
+ // Silent error handling
501
+ }
502
+ });
503
+ }
504
+ }
505
+ /**
506
+ * Clear all listeners for an event (or all events if no eventName provided)
507
+ *
508
+ * @param eventName - Optional event name to clear. If not provided, clears all events
509
+ */
510
+ clear(eventName) {
511
+ if (eventName) {
512
+ this.listeners.delete(eventName);
513
+ }
514
+ else {
515
+ this.listeners.clear();
516
+ }
517
+ }
518
+ /**
519
+ * Get number of listeners for an event
520
+ *
521
+ * @param eventName - Event name to count listeners for
522
+ * @returns Number of listeners registered for the event
523
+ */
524
+ listenerCount(eventName) {
525
+ var _a, _b;
526
+ return (_b = (_a = this.listeners.get(eventName)) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0;
527
+ }
528
+ }
291
529
 
292
- // Add one-time listener for geometry loaded to restore states
293
- var _onGeometryLoaded = function onGeometryLoaded() {
294
- viewer.removeEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, _onGeometryLoaded);
295
- // Restore after geometry is fully loaded
296
- setTimeout(function () {
297
- self.restoreButtonStates(self.docBrowserShouldBeOpen);
298
- }, 200);
299
- };
300
- viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, _onGeometryLoaded);
301
- viewer.loadDocumentNode(viewer.model.getDocumentNode().getDocument(), this.viewables[this.currentIndex]).then(function () {
302
- var defaultGroups = ['settingsTools', 'modelTools', 'navTools'];
303
- defaultGroups.forEach(function (id) {
304
- var group = toolbar.getControl(id);
305
- if (group) group.setVisible(false);
530
+ class FileLoader {
531
+ constructor(viewer) {
532
+ this.viewer = viewer;
533
+ this.eventBus = EventBus.getInstance();
534
+ }
535
+ /**
536
+ * Load a file into the viewer
537
+ *
538
+ * @param filePath - Path or URL to the file
539
+ * @param fileExt - File extension (pdf, dwf, dwfx)
540
+ * @param callbacks - Optional success/error callbacks
541
+ *
542
+ * @example
543
+ * const fileLoader = new FileLoader(viewer);
544
+ * await fileLoader.loadFile('document.pdf', 'pdf', {
545
+ * onSuccess: (e) => console.log('Loaded successfully'),
546
+ * onError: (err) => console.error('Load failed', err)
547
+ * });
548
+ */
549
+ loadFile(filePath, fileExt, callbacks) {
550
+ return __awaiter(this, void 0, void 0, function* () {
551
+ const viewerExtension = FILE_EXTENSION_TO_VIEWER_EXTENSION[fileExt];
552
+ // Load appropriate viewer extension
553
+ yield this.viewer.loadExtension(viewerExtension);
554
+ // Determine loading method based on file type
555
+ if (fileExt === 'pdf') {
556
+ yield this.loadPDFFile(filePath, callbacks);
557
+ }
558
+ else {
559
+ yield this.loadDWFFile(filePath, callbacks);
560
+ }
306
561
  });
307
- var toolGroupExists = toolbar.getControl('custom-tool-group');
308
- var paginationGroupExists = toolbar.getControl('custom-pagination-group');
309
- if (!toolGroupExists && _this2.subToolbar) {
310
- toolbar.addControl(_this2.subToolbar);
311
- }
312
- if (!paginationGroupExists && _this2.paginationGroup) {
313
- toolbar.addControl(_this2.paginationGroup);
314
- }
315
- if (_this2.subToolbar) _this2.subToolbar.setVisible(true);
316
- if (_this2.paginationGroup) _this2.paginationGroup.setVisible(true);
317
- toolbar.setVisible(true);
318
- _this2.updatePaginationState();
319
-
320
- // Also restore immediately (may work for cached pages)
321
- _this2.restoreButtonStates(_this2.docBrowserShouldBeOpen);
322
- })["catch"](function (err) {
323
- return console.error('Error loading viewable:', err);
324
- });
325
562
  }
326
- };
327
- ToolbarExtension.prototype.restoreButtonStates = function (shouldOpenDocBrowser) {
328
- var viewer = this.viewer;
329
- var toolbar = viewer.toolbar;
330
- if (!toolbar) return;
331
- var self = this;
563
+ /**
564
+ * Load PDF file directly
565
+ */
566
+ loadPDFFile(filePath, callbacks) {
567
+ return __awaiter(this, void 0, void 0, function* () {
568
+ const handleLoadSuccess = this.createLoadSuccessHandler(callbacks === null || callbacks === void 0 ? void 0 : callbacks.onSuccess);
569
+ this.viewer.loadModel(filePath, {}, handleLoadSuccess);
570
+ });
571
+ }
572
+ /**
573
+ * Load DWF/DWFX file via blob
574
+ * Extracted from ViewerForgePDF.jsx lines 125-136
575
+ */
576
+ loadDWFFile(filePath, callbacks) {
577
+ return __awaiter(this, void 0, void 0, function* () {
578
+ return new Promise((resolve, reject) => {
579
+ const xhr = new XMLHttpRequest();
580
+ xhr.open('GET', filePath, true);
581
+ xhr.responseType = 'blob';
582
+ xhr.onload = () => {
583
+ var _a;
584
+ if (xhr.status === 200) {
585
+ const blob = xhr.response;
586
+ const blobUrl = window.URL.createObjectURL(blob);
587
+ const handleLoadSuccess = this.createLoadSuccessHandler(callbacks === null || callbacks === void 0 ? void 0 : callbacks.onSuccess);
588
+ this.viewer.loadModel(blobUrl + '#.dwf', {}, handleLoadSuccess);
589
+ resolve();
590
+ }
591
+ else {
592
+ const error = new Error(`Failed to load DWF file: HTTP ${xhr.status}`);
593
+ (_a = callbacks === null || callbacks === void 0 ? void 0 : callbacks.onError) === null || _a === void 0 ? void 0 : _a.call(callbacks, error);
594
+ reject(error);
595
+ }
596
+ };
597
+ xhr.onerror = () => {
598
+ var _a;
599
+ const error = new Error('Network error loading DWF file');
600
+ (_a = callbacks === null || callbacks === void 0 ? void 0 : callbacks.onError) === null || _a === void 0 ? void 0 : _a.call(callbacks, error);
601
+ reject(error);
602
+ };
603
+ xhr.send();
604
+ });
605
+ });
606
+ }
607
+ /**
608
+ * Create load success handler that extracts viewables
609
+ * Extracted from ViewerForgePDF.jsx lines 44-56
610
+ */
611
+ createLoadSuccessHandler(userCallback) {
612
+ return (event) => {
613
+ try {
614
+ // Enable reverse zoom
615
+ this.viewer.setReverseZoomDirection(true);
616
+ // Extract viewables
617
+ const viewables = this.extractViewables(event);
618
+ // Emit event with viewables
619
+ this.eventBus.emit(EVENT_NAMES.VIEWABLES_SET, { viewables });
620
+ // Show toolbar
621
+ if (this.viewer.toolbar) {
622
+ this.viewer.toolbar.setVisible(true);
623
+ }
624
+ // Call user callback if provided
625
+ userCallback === null || userCallback === void 0 ? void 0 : userCallback(event);
626
+ }
627
+ catch (error) {
628
+ // Silent error handling
629
+ }
630
+ };
631
+ }
632
+ /**
633
+ * Extract viewables from document
634
+ * Extracted from ViewerForgePDF.jsx lines 47-56
635
+ */
636
+ extractViewables(event) {
637
+ const root = event.getDocumentNode().getRootNode();
638
+ const view3d = root.search(GEOMETRY_SEARCH_CRITERIA.VIEW_3D, true);
639
+ const view2d = root.search(GEOMETRY_SEARCH_CRITERIA.VIEW_2D, true);
640
+ return view3d.concat(view2d);
641
+ }
642
+ }
332
643
 
333
- // Restore Document Browser state
334
- var openDocBrowser = /*#__PURE__*/function () {
335
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
336
- var docBrowserExt, _t;
337
- return _regenerator().w(function (_context) {
338
- while (1) switch (_context.p = _context.n) {
339
- case 0:
340
- if (shouldOpenDocBrowser) {
341
- _context.n = 1;
342
- break;
343
- }
344
- return _context.a(2);
345
- case 1:
346
- docBrowserExt = viewer.getExtension('Autodesk.DocumentBrowser'); // If extension is null, it was unloaded - we need to reload it
347
- if (docBrowserExt) {
348
- _context.n = 5;
349
- break;
350
- }
351
- _context.p = 2;
352
- _context.n = 3;
353
- return viewer.loadExtension('Autodesk.DocumentBrowser');
354
- case 3:
355
- docBrowserExt = _context.v;
356
- // After loading, we need to wait for the extension to fully initialize
357
- // and then open the panel
358
- setTimeout(function () {
359
- if (docBrowserExt && docBrowserExt.ui) {
360
- docBrowserExt.ui.togglePanel();
361
- setTimeout(function () {
362
- self.applyDocBrowserStyling();
363
- self.checkButtonState();
364
- }, 150);
644
+ class DocumentBrowserManager {
645
+ constructor(viewer, config, eventBus) {
646
+ this.shouldRemainOpen = false;
647
+ this.viewer = viewer;
648
+ this.config = config || {
649
+ autoOpen: true,
650
+ persistState: true,
651
+ defaultTab: 'thumbnails',
652
+ };
653
+ // Use provided EventBus instance or fallback to singleton
654
+ this.eventBus = eventBus || EventBus.getInstance();
655
+ }
656
+ autoOpenIfMultiPage(isMultiPage) {
657
+ return __awaiter(this, void 0, void 0, function* () {
658
+ // Auto-open Document Browser for both single and multi-page documents
659
+ if (!this.config.autoOpen) {
660
+ return;
661
+ }
662
+ setTimeout(() => {
663
+ const originalDocBtn = document.getElementById('toolbar-documentModels');
664
+ if (originalDocBtn && !originalDocBtn.classList.contains('active')) {
665
+ originalDocBtn.click();
666
+ this.shouldRemainOpen = true;
667
+ setTimeout(() => {
668
+ this.applyCustomStyling();
669
+ this.switchToThumbnailTab();
670
+ }, TOOLBAR_REFRESH_INTERVALS.EXTENSION_INIT);
671
+ this.eventBus.emit(EVENT_NAMES.DOC_BROWSER_OPENED);
365
672
  }
366
- }, 200);
367
- return _context.a(2);
368
- case 4:
369
- _context.p = 4;
370
- _t = _context.v;
371
- console.error('[ToolbarExt] Failed to reload DocumentBrowser:', _t);
372
- return _context.a(2);
373
- case 5:
374
- if (docBrowserExt.ui) {
375
- _context.n = 6;
376
- break;
377
- }
378
- return _context.a(2);
379
- case 6:
380
- if (!docBrowserExt.ui.panel) {
381
- _context.n = 8;
382
- break;
383
- }
384
- if (!docBrowserExt.ui.panel.isVisible()) {
385
- _context.n = 7;
386
- break;
387
- }
388
- self.applyDocBrowserStyling();
389
- self.checkButtonState();
390
- return _context.a(2);
391
- case 7:
392
- // Use setVisible(true) directly on the panel
393
- docBrowserExt.ui.panel.setVisible(true);
394
- setTimeout(function () {
395
- self.applyDocBrowserStyling();
396
- self.checkButtonState();
397
- }, 100);
398
- return _context.a(2);
399
- case 8:
400
- // If panel doesn't exist yet, use togglePanel to create it
401
- if (typeof docBrowserExt.ui.togglePanel === 'function') {
402
- docBrowserExt.ui.togglePanel();
403
- setTimeout(function () {
404
- self.applyDocBrowserStyling();
405
- self.checkButtonState();
406
- }, 150);
407
- }
408
- case 9:
409
- return _context.a(2);
410
- }
411
- }, _callee, null, [[2, 4]]);
412
- }));
413
- return function openDocBrowser() {
414
- return _ref.apply(this, arguments);
415
- };
416
- }();
673
+ else if (originalDocBtn &&
674
+ originalDocBtn.classList.contains('active')) {
675
+ this.shouldRemainOpen = true;
676
+ }
677
+ }, TOOLBAR_REFRESH_INTERVALS.GEOMETRY_SETTLE);
678
+ });
679
+ }
680
+ openPanel() {
681
+ return __awaiter(this, void 0, void 0, function* () {
682
+ var _a, _b, _c;
683
+ let ext = this.viewer.getExtension('Autodesk.DocumentBrowser');
684
+ if (!ext) {
685
+ try {
686
+ yield this.viewer.loadExtension('Autodesk.DocumentBrowser');
687
+ ext = this.viewer.getExtension('Autodesk.DocumentBrowser');
688
+ }
689
+ catch (e) {
690
+ return;
691
+ }
692
+ }
693
+ // Check if already open
694
+ if ((_b = (_a = ext === null || ext === void 0 ? void 0 : ext.ui) === null || _a === void 0 ? void 0 : _a.panel) === null || _b === void 0 ? void 0 : _b.isVisible()) {
695
+ this.shouldRemainOpen = true;
696
+ this.applyCustomStyling();
697
+ this.switchToThumbnailTab();
698
+ return;
699
+ }
700
+ // Try to use original button first for proper initialization
701
+ const originalDocBtn = document.getElementById('toolbar-documentModels');
702
+ if (originalDocBtn) {
703
+ originalDocBtn.click();
704
+ this.shouldRemainOpen = true;
705
+ setTimeout(() => {
706
+ this.applyCustomStyling();
707
+ this.switchToThumbnailTab();
708
+ this.eventBus.emit(EVENT_NAMES.DOC_BROWSER_OPENED);
709
+ }, TOOLBAR_REFRESH_INTERVALS.EXTENSION_INIT);
710
+ }
711
+ else {
712
+ if ((_c = ext === null || ext === void 0 ? void 0 : ext.ui) === null || _c === void 0 ? void 0 : _c.panel) {
713
+ ext.ui.panel.setVisible(true);
714
+ this.shouldRemainOpen = true;
715
+ setTimeout(() => {
716
+ this.applyCustomStyling();
717
+ this.switchToThumbnailTab();
718
+ this.eventBus.emit(EVENT_NAMES.DOC_BROWSER_OPENED);
719
+ }, TOOLBAR_REFRESH_INTERVALS.EXTENSION_INIT);
720
+ }
721
+ }
722
+ });
723
+ }
724
+ closePanel() {
725
+ return __awaiter(this, void 0, void 0, function* () {
726
+ var _a, _b, _c;
727
+ const ext = this.viewer.getExtension('Autodesk.DocumentBrowser');
728
+ if (!((_b = (_a = ext === null || ext === void 0 ? void 0 : ext.ui) === null || _a === void 0 ? void 0 : _a.panel) === null || _b === void 0 ? void 0 : _b.isVisible())) {
729
+ this.shouldRemainOpen = false;
730
+ return;
731
+ }
732
+ const originalDocBtn = document.getElementById('toolbar-documentModels');
733
+ if (originalDocBtn && originalDocBtn.classList.contains('active')) {
734
+ originalDocBtn.click();
735
+ this.shouldRemainOpen = false;
736
+ this.eventBus.emit(EVENT_NAMES.DOC_BROWSER_CLOSED);
737
+ }
738
+ else {
739
+ if ((_c = ext === null || ext === void 0 ? void 0 : ext.ui) === null || _c === void 0 ? void 0 : _c.panel) {
740
+ ext.ui.panel.setVisible(false);
741
+ this.shouldRemainOpen = false;
742
+ this.eventBus.emit(EVENT_NAMES.DOC_BROWSER_CLOSED);
743
+ }
744
+ }
745
+ });
746
+ }
747
+ togglePanel() {
748
+ return __awaiter(this, void 0, void 0, function* () {
749
+ const isCurrentlyOpen = this.isOpen();
750
+ if (isCurrentlyOpen) {
751
+ yield this.closePanel();
752
+ }
753
+ else {
754
+ yield this.openPanel();
755
+ }
756
+ });
757
+ }
758
+ isOpen() {
759
+ var _a, _b, _c;
760
+ const ext = this.viewer.getExtension('Autodesk.DocumentBrowser');
761
+ return (_c = (_b = (_a = ext === null || ext === void 0 ? void 0 : ext.ui) === null || _a === void 0 ? void 0 : _a.panel) === null || _b === void 0 ? void 0 : _b.isVisible()) !== null && _c !== void 0 ? _c : false;
762
+ }
763
+ applyCustomStyling() {
764
+ setTimeout(() => {
765
+ var _a, _b;
766
+ const ext = this.viewer.getExtension('Autodesk.DocumentBrowser');
767
+ if ((_b = (_a = ext === null || ext === void 0 ? void 0 : ext.ui) === null || _a === void 0 ? void 0 : _a.panel) === null || _b === void 0 ? void 0 : _b.container) {
768
+ applyStyles(ext.ui.panel.container, DOCUMENT_BROWSER_STYLES);
769
+ // Adjust panel height based on number of thumbnails
770
+ this.adjustPanelHeight();
771
+ }
772
+ }, TOOLBAR_REFRESH_INTERVALS.DOM_SETTLE);
773
+ }
774
+ /**
775
+ * Adjust Document Browser panel height based on content
776
+ */
777
+ adjustPanelHeight() {
778
+ setTimeout(() => {
779
+ var _a, _b;
780
+ const ext = this.viewer.getExtension('Autodesk.DocumentBrowser');
781
+ if (!((_b = (_a = ext === null || ext === void 0 ? void 0 : ext.ui) === null || _a === void 0 ? void 0 : _a.panel) === null || _b === void 0 ? void 0 : _b.container)) {
782
+ return;
783
+ }
784
+ const panel = ext.ui.panel;
785
+ const scrollContainer = panel.container.querySelector('.docking-panel-scroll');
786
+ if (!scrollContainer) {
787
+ return;
788
+ }
789
+ // Count thumbnails
790
+ const thumbnails = scrollContainer.querySelectorAll('.viewer-ext-docbrowser-thumbnail');
791
+ const thumbnailCount = thumbnails.length;
792
+ if (thumbnailCount === 0) {
793
+ return;
794
+ }
795
+ // Get thumbnail dimensions (typically 200x200 + label)
796
+ const firstThumbnail = thumbnails[0];
797
+ const thumbnailHeight = (firstThumbnail === null || firstThumbnail === void 0 ? void 0 : firstThumbnail.offsetHeight) || 220; // Default 220 if can't get
798
+ // Calculate optimal height
799
+ // For 1 thumbnail: just the thumbnail height + some padding
800
+ // For multiple: use a reasonable max height
801
+ const headerHeight = 110; // Panel header + tabs
802
+ const padding = 40; // Extra padding for aesthetics
803
+ let optimalHeight;
804
+ if (thumbnailCount === 1) {
805
+ // Single thumbnail: compact size
806
+ optimalHeight = thumbnailHeight + headerHeight + padding;
807
+ }
808
+ else {
809
+ // Multiple thumbnails: calculate based on count but cap at viewport height
810
+ const maxViewportHeight = window.innerHeight * 0.8; // Max 80% of viewport
811
+ const calculatedHeight = Math.min(thumbnailCount * thumbnailHeight + headerHeight + padding, maxViewportHeight);
812
+ optimalHeight = calculatedHeight;
813
+ }
814
+ // Apply the height
815
+ panel.container.style.height = `${optimalHeight}px`;
816
+ // Update scroll container height
817
+ const scrollHeight = optimalHeight - headerHeight;
818
+ scrollContainer.style.height = `${scrollHeight}px`;
819
+ }, TOOLBAR_REFRESH_INTERVALS.DOM_SETTLE + 50);
820
+ }
821
+ switchToThumbnailTab() {
822
+ return __awaiter(this, void 0, void 0, function* () {
823
+ if (this.config.defaultTab !== 'thumbnails')
824
+ return;
825
+ setTimeout(() => {
826
+ const thumbnailTab = findThumbnailTab();
827
+ if (thumbnailTab && !thumbnailTab.classList.contains('active')) {
828
+ clickElement(thumbnailTab);
829
+ }
830
+ }, TOOLBAR_REFRESH_INTERVALS.DOM_SETTLE);
831
+ });
832
+ }
833
+ restoreState() {
834
+ return __awaiter(this, void 0, void 0, function* () {
835
+ var _a, _b, _c;
836
+ if (!this.config.persistState || !this.shouldRemainOpen) {
837
+ return;
838
+ }
839
+ const ext = this.viewer.getExtension('Autodesk.DocumentBrowser');
840
+ const isCurrentlyOpen = (_c = (_b = (_a = ext === null || ext === void 0 ? void 0 : ext.ui) === null || _a === void 0 ? void 0 : _a.panel) === null || _b === void 0 ? void 0 : _b.isVisible()) !== null && _c !== void 0 ? _c : false;
841
+ if (isCurrentlyOpen) {
842
+ this.applyCustomStyling();
843
+ this.switchToThumbnailTab();
844
+ // Emit event MULTIPLE times to ensure button state syncs
845
+ this.eventBus.emit(EVENT_NAMES.DOC_BROWSER_OPENED);
846
+ setTimeout(() => this.eventBus.emit(EVENT_NAMES.DOC_BROWSER_OPENED), 50);
847
+ setTimeout(() => this.eventBus.emit(EVENT_NAMES.DOC_BROWSER_OPENED), 100);
848
+ setTimeout(() => this.eventBus.emit(EVENT_NAMES.DOC_BROWSER_OPENED), 150);
849
+ }
850
+ else {
851
+ yield this.openPanel();
852
+ }
853
+ });
854
+ }
855
+ setShouldRemainOpen(value) {
856
+ this.shouldRemainOpen = value;
857
+ }
858
+ getShouldRemainOpen() {
859
+ return this.shouldRemainOpen;
860
+ }
861
+ }
417
862
 
418
- // Restore Pan tool active state
419
- var restorePanTool = function restorePanTool() {
420
- self.activatePanTool();
421
- };
863
+ /**
864
+ * PaginationManager
865
+ *
866
+ * @file PaginationManager.ts
867
+ * @description Manages page navigation for multi-page documents
868
+ * Extracted from ToolbarExtension.js lines 34-148
869
+ */
870
+ class PaginationManager {
871
+ constructor(viewer, Autodesk, config, eventBus) {
872
+ this.currentIndex = 0;
873
+ this.viewables = [];
874
+ this.paginationGroup = null;
875
+ this.docBrowserShouldBeOpen = false;
876
+ this.viewer = viewer;
877
+ this.Autodesk = Autodesk;
878
+ this.config = config || {};
879
+ // Use provided EventBus instance or fallback to singleton
880
+ this.eventBus = eventBus || EventBus.getInstance();
881
+ this.modelAddedHandler = this.updateCurrentIndexFromModel.bind(this);
882
+ // Add MODEL_ADDED_EVENT listener immediately in constructor
883
+ // This ensures it's always listening for page changes
884
+ this.viewer.addEventListener(this.Autodesk.Viewing.MODEL_ADDED_EVENT, this.modelAddedHandler);
885
+ }
886
+ /**
887
+ * Set callback for page changes (alternative to EventBus)
888
+ */
889
+ setPageChangeCallback(callback) {
890
+ this.onPageChangeCallback = callback;
891
+ }
892
+ setViewables(viewables) {
893
+ this.viewables = viewables;
894
+ this.currentIndex = 0;
895
+ if (viewables.length > 1) {
896
+ this.docBrowserShouldBeOpen = true;
897
+ }
898
+ this.updatePaginationState();
899
+ // Remove existing listener to avoid duplicates
900
+ if (this.modelAddedHandler) {
901
+ this.viewer.removeEventListener(this.Autodesk.Viewing.MODEL_ADDED_EVENT, this.modelAddedHandler);
902
+ }
903
+ // Add MODEL_ADDED_EVENT listener
904
+ this.viewer.addEventListener(this.Autodesk.Viewing.MODEL_ADDED_EVENT, this.modelAddedHandler);
905
+ }
906
+ nextPage() {
907
+ if (this.viewables.length > 0) {
908
+ this.currentIndex = (this.currentIndex + 1) % this.viewables.length;
909
+ this.loadCurrentViewable();
910
+ }
911
+ }
912
+ previousPage() {
913
+ if (this.viewables.length > 0) {
914
+ this.currentIndex =
915
+ (this.currentIndex - 1 + this.viewables.length) % this.viewables.length;
916
+ this.loadCurrentViewable();
917
+ }
918
+ }
919
+ goToPage(index) {
920
+ if (index >= 0 && index < this.viewables.length) {
921
+ this.currentIndex = index;
922
+ this.loadCurrentViewable();
923
+ }
924
+ }
925
+ getCurrentPage() {
926
+ return this.currentIndex;
927
+ }
928
+ getTotalPages() {
929
+ return this.viewables.length;
930
+ }
931
+ isMultiPage() {
932
+ return this.viewables.length > 1;
933
+ }
934
+ getViewables() {
935
+ return this.viewables;
936
+ }
937
+ updateCurrentIndexFromModel() {
938
+ var _a, _b, _c, _d, _e, _f, _g;
939
+ if (!this.viewer.model || this.viewables.length === 0) {
940
+ return;
941
+ }
942
+ const currentNode = this.viewer.model.getDocumentNode();
943
+ if (currentNode) {
944
+ const currentGuid = ((_a = currentNode.data) === null || _a === void 0 ? void 0 : _a.guid) || currentNode.guid;
945
+ const index = this.viewables.findIndex((v) => {
946
+ var _a;
947
+ const vGuid = ((_a = v.data) === null || _a === void 0 ? void 0 : _a.guid) || v.guid;
948
+ return vGuid === currentGuid;
949
+ });
950
+ if (index !== -1 && index !== this.currentIndex) {
951
+ // Page changed via Document Browser panel
952
+ this.currentIndex = index;
953
+ // Check if Document Browser is currently open
954
+ const docBrowserExt = this.viewer.getExtension('Autodesk.DocumentBrowser');
955
+ const isCurrentlyOpen = (_d = (_c = (_b = docBrowserExt === null || docBrowserExt === void 0 ? void 0 : docBrowserExt.ui) === null || _b === void 0 ? void 0 : _b.panel) === null || _c === void 0 ? void 0 : _c.isVisible()) !== null && _d !== void 0 ? _d : false;
956
+ if (isCurrentlyOpen) {
957
+ this.docBrowserShouldBeOpen = true;
958
+ }
959
+ // Emit page changed event to trigger button state sync and toolbar refresh
960
+ const pageData = {
961
+ index: this.currentIndex,
962
+ viewable: this.viewables[this.currentIndex],
963
+ shouldRestoreDocBrowser: this.docBrowserShouldBeOpen,
964
+ fromDocBrowser: true,
965
+ };
966
+ // Use callback first (direct communication)
967
+ if (this.onPageChangeCallback) {
968
+ this.onPageChangeCallback(pageData);
969
+ }
970
+ // Also emit via EventBus as fallback
971
+ this.eventBus.emit(EVENT_NAMES.PAGE_CHANGED, pageData);
972
+ // Update pagination state multiple times to ensure it sticks
973
+ const updateTimes = [10, 50, 100, 150, 200, 250, 300, 350, 400, 500];
974
+ updateTimes.forEach((delay) => {
975
+ setTimeout(() => {
976
+ this.updatePaginationState();
977
+ }, delay);
978
+ });
979
+ }
980
+ else if (index !== -1) {
981
+ // Same page - but user might have clicked thumbnail while panel is open
982
+ const docBrowserExt = this.viewer.getExtension('Autodesk.DocumentBrowser');
983
+ const isCurrentlyOpen = (_g = (_f = (_e = docBrowserExt === null || docBrowserExt === void 0 ? void 0 : docBrowserExt.ui) === null || _e === void 0 ? void 0 : _e.panel) === null || _f === void 0 ? void 0 : _f.isVisible()) !== null && _g !== void 0 ? _g : false;
984
+ if (isCurrentlyOpen && !this.docBrowserShouldBeOpen) {
985
+ this.docBrowserShouldBeOpen = true;
986
+ // Emit a "refresh" event to ensure button state is synced
987
+ const pageData = {
988
+ index: this.currentIndex,
989
+ viewable: this.viewables[this.currentIndex],
990
+ shouldRestoreDocBrowser: true,
991
+ fromDocBrowser: true,
992
+ refresh: true,
993
+ };
994
+ if (this.onPageChangeCallback) {
995
+ this.onPageChangeCallback(pageData);
996
+ }
997
+ this.eventBus.emit(EVENT_NAMES.PAGE_CHANGED, pageData);
998
+ }
999
+ // Always update pagination state
1000
+ this.updatePaginationState();
1001
+ }
1002
+ }
1003
+ }
1004
+ updatePaginationState() {
1005
+ // IMPORTANT: First sync currentIndex with actual loaded model
1006
+ this.syncCurrentIndexFromModel();
1007
+ if (!this.paginationGroup) {
1008
+ return;
1009
+ }
1010
+ if (this.viewables.length <= 1) {
1011
+ this.paginationGroup.setVisible(false);
1012
+ if (this.paginationGroup.container) {
1013
+ this.paginationGroup.container.style.display = 'none';
1014
+ }
1015
+ return;
1016
+ }
1017
+ this.paginationGroup.setVisible(true);
1018
+ if (this.paginationGroup.container) {
1019
+ this.paginationGroup.container.style.display = '';
1020
+ }
1021
+ const totalBtn = this.paginationGroup.getControl(PAGINATION_BUTTONS.LABEL.id);
1022
+ if (totalBtn) {
1023
+ const current = this.viewables.length > 0 ? this.currentIndex + 1 : 0;
1024
+ const total = this.viewables.length;
1025
+ totalBtn.setToolTip(`Page ${current} of ${total}`);
1026
+ const domElem = totalBtn.container;
1027
+ if (domElem) {
1028
+ const newContent = `<div style="display: flex; align-items: center; justify-content: center; height: 100%; padding: 0 10px; color: white; font-size: 14px; white-space: nowrap;">${current} / ${total}</div>`;
1029
+ domElem.innerHTML = newContent;
1030
+ // Use requestAnimationFrame to ensure DOM update
1031
+ requestAnimationFrame(() => {
1032
+ domElem.innerHTML = newContent;
1033
+ });
1034
+ // Also try direct text update as fallback
1035
+ setTimeout(() => {
1036
+ if (domElem.innerHTML !== newContent) {
1037
+ domElem.innerHTML = newContent;
1038
+ }
1039
+ }, 20);
1040
+ }
1041
+ }
1042
+ else {
1043
+ // Try to get the control again in case it was just created
1044
+ setTimeout(() => {
1045
+ const totalBtnRetry = this.paginationGroup.getControl(PAGINATION_BUTTONS.LABEL.id);
1046
+ if (totalBtnRetry) {
1047
+ const current = this.viewables.length > 0 ? this.currentIndex + 1 : 0;
1048
+ const total = this.viewables.length;
1049
+ totalBtnRetry.setToolTip(`Page ${current} of ${total}`);
1050
+ const domElem = totalBtnRetry.container;
1051
+ if (domElem) {
1052
+ 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;">${current} / ${total}</div>`;
1053
+ }
1054
+ }
1055
+ }, 50);
1056
+ }
1057
+ }
1058
+ /**
1059
+ * Sync currentIndex with the actual loaded model (without emitting events)
1060
+ * This is used to ensure pagination display shows correct page number
1061
+ */
1062
+ syncCurrentIndexFromModel() {
1063
+ var _a;
1064
+ if (!this.viewer.model || this.viewables.length === 0) {
1065
+ return;
1066
+ }
1067
+ const currentNode = this.viewer.model.getDocumentNode();
1068
+ if (currentNode) {
1069
+ const currentGuid = ((_a = currentNode.data) === null || _a === void 0 ? void 0 : _a.guid) || currentNode.guid;
1070
+ const index = this.viewables.findIndex((v) => {
1071
+ var _a;
1072
+ const vGuid = ((_a = v.data) === null || _a === void 0 ? void 0 : _a.guid) || v.guid;
1073
+ return vGuid === currentGuid;
1074
+ });
1075
+ if (index !== -1 && index !== this.currentIndex) {
1076
+ this.currentIndex = index;
1077
+ }
1078
+ }
1079
+ }
1080
+ /**
1081
+ * Update thumbnail selection in Document Browser panel
1082
+ * This ensures the correct thumbnail is highlighted after navigation
1083
+ */
1084
+ updateThumbnailSelection(targetViewable) {
1085
+ var _a;
1086
+ try {
1087
+ const targetGuid = ((_a = targetViewable.data) === null || _a === void 0 ? void 0 : _a.guid) || targetViewable.guid;
1088
+ // Find all thumbnails
1089
+ const thumbnails = document.querySelectorAll('.viewer-ext-docbrowser-thumbnail');
1090
+ let selectedThumbnail = null;
1091
+ thumbnails.forEach((thumbnail) => {
1092
+ const bubbleGuid = thumbnail.getAttribute('bubble-guid');
1093
+ if (bubbleGuid === targetGuid) {
1094
+ thumbnail.classList.add('viewer-ext-docbrowser-thumbnail-selected');
1095
+ selectedThumbnail = thumbnail;
1096
+ }
1097
+ else {
1098
+ thumbnail.classList.remove('viewer-ext-docbrowser-thumbnail-selected');
1099
+ }
1100
+ });
1101
+ // CRITICAL: Scroll to selected thumbnail
1102
+ if (selectedThumbnail) {
1103
+ this.scrollToThumbnail(selectedThumbnail);
1104
+ }
1105
+ }
1106
+ catch (error) {
1107
+ // Silent error handling
1108
+ }
1109
+ }
1110
+ /**
1111
+ * Scroll the Document Browser panel to show the selected thumbnail
1112
+ */
1113
+ scrollToThumbnail(thumbnail) {
1114
+ try {
1115
+ // Find the scroll container
1116
+ const scrollContainer = document.querySelector('.docking-panel-scroll');
1117
+ if (!scrollContainer) {
1118
+ return;
1119
+ }
1120
+ // Get thumbnail position relative to container
1121
+ const thumbnailRect = thumbnail.getBoundingClientRect();
1122
+ const containerRect = scrollContainer.getBoundingClientRect();
1123
+ // Calculate scroll position to center the thumbnail in the viewport
1124
+ const thumbnailTop = thumbnailRect.top - containerRect.top + scrollContainer.scrollTop;
1125
+ const containerHeight = scrollContainer.clientHeight;
1126
+ const thumbnailHeight = thumbnailRect.height;
1127
+ const targetScrollTop = thumbnailTop - containerHeight / 2 + thumbnailHeight / 2;
1128
+ // Smooth scroll to target position
1129
+ scrollContainer.scrollTo({
1130
+ top: targetScrollTop,
1131
+ behavior: 'smooth',
1132
+ });
1133
+ }
1134
+ catch (error) {
1135
+ // Silent error handling
1136
+ }
1137
+ }
1138
+ /**
1139
+ * Try to use DocumentBrowser API to change page without refreshing panel
1140
+ * Returns true if successful, false otherwise
1141
+ */
1142
+ tryUseDocBrowserAPI(targetIndex) {
1143
+ var _a, _b, _c;
1144
+ const docBrowserExt = this.viewer.getExtension('Autodesk.DocumentBrowser');
1145
+ const isOpen = (_c = (_b = (_a = docBrowserExt === null || docBrowserExt === void 0 ? void 0 : docBrowserExt.ui) === null || _a === void 0 ? void 0 : _a.panel) === null || _b === void 0 ? void 0 : _b.isVisible()) !== null && _c !== void 0 ? _c : false;
1146
+ if (!isOpen || targetIndex < 0 || targetIndex >= this.viewables.length) {
1147
+ return false;
1148
+ }
1149
+ try {
1150
+ const targetViewable = this.viewables[targetIndex];
1151
+ if (!targetViewable) {
1152
+ return false;
1153
+ }
1154
+ // Try _changeModelFn (internal method used by DocumentBrowser)
1155
+ if (docBrowserExt.ui &&
1156
+ typeof docBrowserExt.ui._changeModelFn === 'function') {
1157
+ docBrowserExt.ui._changeModelFn(targetViewable);
1158
+ // Update thumbnail selection after model change
1159
+ setTimeout(() => {
1160
+ this.updateThumbnailSelection(targetViewable);
1161
+ }, 100);
1162
+ return true;
1163
+ }
1164
+ // Fallback: Try _changeModel
1165
+ if (docBrowserExt.ui &&
1166
+ typeof docBrowserExt.ui._changeModel === 'function') {
1167
+ docBrowserExt.ui._changeModel(targetViewable);
1168
+ return true;
1169
+ }
1170
+ // Fallback: Try setCurrentViewable
1171
+ if (docBrowserExt &&
1172
+ typeof docBrowserExt.setCurrentViewable === 'function') {
1173
+ docBrowserExt.setCurrentViewable(targetViewable);
1174
+ return true;
1175
+ }
1176
+ return false;
1177
+ }
1178
+ catch (error) {
1179
+ return false;
1180
+ }
1181
+ }
1182
+ loadCurrentViewable() {
1183
+ var _a, _b, _c, _d, _e;
1184
+ if (this.viewables.length === 0 || !this.viewables[this.currentIndex]) {
1185
+ return;
1186
+ }
1187
+ const viewer = this.viewer;
1188
+ // Check current Document Browser state before loading new page
1189
+ const docBrowserExt = viewer.getExtension('Autodesk.DocumentBrowser');
1190
+ const isCurrentlyOpen = (_c = (_b = (_a = docBrowserExt === null || docBrowserExt === void 0 ? void 0 : docBrowserExt.ui) === null || _a === void 0 ? void 0 : _a.panel) === null || _b === void 0 ? void 0 : _b.isVisible()) !== null && _c !== void 0 ? _c : false;
1191
+ if (isCurrentlyOpen) {
1192
+ this.docBrowserShouldBeOpen = true;
1193
+ }
1194
+ // OPTIMIZATION: If Document Browser is open, try to use its API to navigate
1195
+ // This prevents the panel from being refreshed (same behavior as manual thumbnail click)
1196
+ if (isCurrentlyOpen) {
1197
+ const apiSuccess = this.tryUseDocBrowserAPI(this.currentIndex);
1198
+ if (apiSuccess) {
1199
+ // Update pagination state after a short delay
1200
+ setTimeout(() => {
1201
+ this.updatePaginationState();
1202
+ }, 100);
1203
+ return;
1204
+ }
1205
+ }
1206
+ // FALLBACK: Use traditional loadDocumentNode if Document Browser is closed
1207
+ const onGeometryLoaded = () => {
1208
+ viewer.removeEventListener(this.Autodesk.Viewing.GEOMETRY_LOADED_EVENT, onGeometryLoaded);
1209
+ setTimeout(() => {
1210
+ const pageData = {
1211
+ index: this.currentIndex,
1212
+ viewable: this.viewables[this.currentIndex],
1213
+ shouldRestoreDocBrowser: this.docBrowserShouldBeOpen,
1214
+ fromPagination: true,
1215
+ };
1216
+ if (this.onPageChangeCallback) {
1217
+ this.onPageChangeCallback(pageData);
1218
+ }
1219
+ this.eventBus.emit(EVENT_NAMES.PAGE_CHANGED, pageData);
1220
+ this.updatePaginationState();
1221
+ }, TOOLBAR_REFRESH_INTERVALS.GEOMETRY_SETTLE);
1222
+ };
1223
+ viewer.addEventListener(this.Autodesk.Viewing.GEOMETRY_LOADED_EVENT, onGeometryLoaded);
1224
+ viewer
1225
+ .loadDocumentNode(viewer.model.getDocumentNode().getDocument(), this.viewables[this.currentIndex])
1226
+ .then(() => {
1227
+ const pageData = {
1228
+ index: this.currentIndex,
1229
+ viewable: this.viewables[this.currentIndex],
1230
+ shouldRestoreDocBrowser: this.docBrowserShouldBeOpen,
1231
+ immediate: true,
1232
+ fromPagination: true,
1233
+ };
1234
+ if (this.onPageChangeCallback) {
1235
+ this.onPageChangeCallback(pageData);
1236
+ }
1237
+ this.eventBus.emit(EVENT_NAMES.PAGE_CHANGED, pageData);
1238
+ this.updatePaginationState();
1239
+ })
1240
+ .catch((err) => {
1241
+ // Silent error handling
1242
+ });
1243
+ (_e = (_d = this.config).onPageChange) === null || _e === void 0 ? void 0 : _e.call(_d, this.currentIndex);
1244
+ }
1245
+ createPaginationGroup(toolbar) {
1246
+ this.paginationGroup = new this.Autodesk.Viewing.UI.ControlGroup(TOOLBAR_CONTROL_GROUP_IDS.PAGINATION);
1247
+ toolbar.addControl(this.paginationGroup);
1248
+ const prevBtn = new this.Autodesk.Viewing.UI.Button(PAGINATION_BUTTONS.PREV.id);
1249
+ prevBtn.setIcon(PAGINATION_BUTTONS.PREV.icon);
1250
+ prevBtn.addClass('custom-prev-btn');
1251
+ prevBtn.setToolTip(PAGINATION_BUTTONS.PREV.tooltip);
1252
+ prevBtn.onClick = () => this.previousPage();
1253
+ this.paginationGroup.addControl(prevBtn);
1254
+ const labelBtn = new this.Autodesk.Viewing.UI.Button(PAGINATION_BUTTONS.LABEL.id);
1255
+ labelBtn.setToolTip(PAGINATION_BUTTONS.LABEL.tooltip);
1256
+ this.paginationGroup.addControl(labelBtn);
1257
+ const nextBtn = new this.Autodesk.Viewing.UI.Button(PAGINATION_BUTTONS.NEXT.id);
1258
+ nextBtn.setIcon(PAGINATION_BUTTONS.NEXT.icon);
1259
+ nextBtn.addClass('custom-next-btn');
1260
+ nextBtn.setToolTip(PAGINATION_BUTTONS.NEXT.tooltip);
1261
+ nextBtn.onClick = () => this.nextPage();
1262
+ this.paginationGroup.addControl(nextBtn);
1263
+ // Immediately update pagination state after creating group
1264
+ setTimeout(() => {
1265
+ this.updatePaginationState();
1266
+ }, 10);
1267
+ }
1268
+ getPaginationGroup() {
1269
+ return this.paginationGroup;
1270
+ }
1271
+ setPaginationGroup(group) {
1272
+ this.paginationGroup = group;
1273
+ }
1274
+ cleanup() {
1275
+ if (this.modelAddedHandler) {
1276
+ this.viewer.removeEventListener(this.Autodesk.Viewing.MODEL_ADDED_EVENT, this.modelAddedHandler);
1277
+ }
1278
+ if (this.viewer.toolbar && this.paginationGroup) {
1279
+ this.viewer.toolbar.removeControl(this.paginationGroup);
1280
+ this.paginationGroup = null;
1281
+ }
1282
+ }
1283
+ }
422
1284
 
423
- // Call restore at multiple intervals to ensure it works
424
- // Use longer delays since geometry needs to fully load
425
- setTimeout(openDocBrowser, 300);
426
- setTimeout(openDocBrowser, 600);
427
- setTimeout(openDocBrowser, 1000);
428
- setTimeout(restorePanTool, 100);
429
- setTimeout(restorePanTool, 300);
430
- };
431
- ToolbarExtension.prototype.applyDocBrowserStyling = function () {
432
- var viewer = this.viewer;
433
- var ext = viewer.getExtension('Autodesk.DocumentBrowser');
434
- if (ext && ext.ui && ext.ui.panel && ext.ui.panel.container) {
435
- ext.ui.panel.container.style.top = '0';
436
- ext.ui.panel.container.style.left = 'unset';
437
- ext.ui.panel.container.style.right = '0px';
438
- ext.ui.panel.container.style.width = '200px';
439
- ext.ui.panel.container.style.height = '80%';
1285
+ /**
1286
+ * ToolbarManager
1287
+ *
1288
+ * @file ToolbarManager.ts
1289
+ * @description Manages custom toolbar creation and button state
1290
+ * Extracted from ToolbarExtension.js lines 256-479
1291
+ */
1292
+ class ToolbarManager {
1293
+ constructor(viewer, Autodesk, config) {
1294
+ this.subToolbar = null;
1295
+ this.viewer = viewer;
1296
+ this.Autodesk = Autodesk;
1297
+ this.config = config;
1298
+ this.eventBus = EventBus.getInstance();
1299
+ }
1300
+ createToolbar(isMultiPage = false) {
1301
+ const toolbar = this.viewer.toolbar;
1302
+ if (!toolbar)
1303
+ return;
1304
+ this.subToolbar = new this.Autodesk.Viewing.UI.ControlGroup(TOOLBAR_CONTROL_GROUP_IDS.TOOLS);
1305
+ const panBtn = this.createPanButton();
1306
+ const docBtn = this.createDocBrowserButton();
1307
+ const dlBtn = this.createDownloadButton();
1308
+ this.subToolbar.addControl(panBtn);
1309
+ this.subToolbar.addControl(docBtn);
1310
+ this.subToolbar.addControl(dlBtn);
1311
+ toolbar.addControl(this.subToolbar);
1312
+ }
1313
+ createPanButton() {
1314
+ const btn = new this.Autodesk.Viewing.UI.Button(CUSTOM_TOOLBAR_BUTTONS.PAN.id);
1315
+ btn.setIcon(CUSTOM_TOOLBAR_BUTTONS.PAN.icon);
1316
+ btn.addClass('custom-pan-btn');
1317
+ btn.setToolTip(CUSTOM_TOOLBAR_BUTTONS.PAN.tooltip);
1318
+ btn.onClick = () => {
1319
+ var _a, _b;
1320
+ (_b = (_a = this.config).onPanClick) === null || _b === void 0 ? void 0 : _b.call(_a);
1321
+ this.activatePanButton();
1322
+ };
1323
+ return btn;
1324
+ }
1325
+ createDocBrowserButton() {
1326
+ const btn = new this.Autodesk.Viewing.UI.Button(CUSTOM_TOOLBAR_BUTTONS.DOC_BROWSER.id);
1327
+ btn.setIcon(CUSTOM_TOOLBAR_BUTTONS.DOC_BROWSER.icon);
1328
+ btn.addClass('custom-doc-browser-btn');
1329
+ btn.setToolTip(CUSTOM_TOOLBAR_BUTTONS.DOC_BROWSER.tooltip);
1330
+ btn.onClick = () => {
1331
+ var _a, _b;
1332
+ (_b = (_a = this.config).onDocBrowserClick) === null || _b === void 0 ? void 0 : _b.call(_a);
1333
+ this.eventBus.emit(EVENT_NAMES.TOOLBAR_BUTTON_CLICKED, {
1334
+ buttonId: CUSTOM_TOOLBAR_BUTTONS.DOC_BROWSER.id,
1335
+ });
1336
+ };
1337
+ return btn;
1338
+ }
1339
+ createDownloadButton() {
1340
+ const btn = new this.Autodesk.Viewing.UI.Button(CUSTOM_TOOLBAR_BUTTONS.DOWNLOAD.id);
1341
+ btn.setIcon(CUSTOM_TOOLBAR_BUTTONS.DOWNLOAD.icon);
1342
+ btn.addClass('custom-download-btn');
1343
+ btn.setToolTip(CUSTOM_TOOLBAR_BUTTONS.DOWNLOAD.tooltip);
1344
+ btn.onClick = () => {
1345
+ var _a, _b;
1346
+ (_b = (_a = this.config).onDownloadClick) === null || _b === void 0 ? void 0 : _b.call(_a);
1347
+ this.eventBus.emit(EVENT_NAMES.DOWNLOAD_REQUESTED, {
1348
+ filePath: this.config.filePath,
1349
+ });
1350
+ };
1351
+ return btn;
1352
+ }
1353
+ updateButtonState(buttonId, isActive) {
1354
+ if (!this.subToolbar)
1355
+ return;
1356
+ const btn = this.subToolbar.getControl(buttonId);
1357
+ if (btn) {
1358
+ const newState = isActive
1359
+ ? this.Autodesk.Viewing.UI.Button.State.ACTIVE
1360
+ : this.Autodesk.Viewing.UI.Button.State.INACTIVE;
1361
+ btn.setState(newState);
1362
+ }
1363
+ }
1364
+ activatePanButton() {
1365
+ try {
1366
+ this.viewer.setActiveNavigationTool('pan');
1367
+ // Note: Removed EVENT_NAMES.PAN_ACTIVATED emit as no listeners were registered
1368
+ // If you need this event, add a listener first
1369
+ }
1370
+ catch (e) {
1371
+ const originalPanBtn = document.getElementById('toolbar-panTool');
1372
+ if (originalPanBtn) {
1373
+ originalPanBtn.click();
1374
+ }
1375
+ }
1376
+ this.updateButtonState(CUSTOM_TOOLBAR_BUTTONS.PAN.id, true);
1377
+ const customPanBtn = document.querySelector('.custom-pan-btn');
1378
+ if (customPanBtn) {
1379
+ customPanBtn.classList.add('active');
1380
+ customPanBtn.classList.remove('inactive');
1381
+ }
1382
+ }
1383
+ hideDefaultGroups() {
1384
+ const toolbar = this.viewer.toolbar;
1385
+ if (!toolbar)
1386
+ return;
1387
+ DEFAULT_HIDDEN_TOOLBAR_GROUPS.forEach((id) => {
1388
+ const group = toolbar.getControl(id);
1389
+ if (group) {
1390
+ group.setVisible(false);
1391
+ }
1392
+ });
1393
+ }
1394
+ getToolbar() {
1395
+ return this.subToolbar;
440
1396
  }
1397
+ cleanup() {
1398
+ if (this.viewer.toolbar && this.subToolbar) {
1399
+ this.viewer.toolbar.removeControl(this.subToolbar);
1400
+ this.subToolbar = null;
1401
+ }
1402
+ }
1403
+ }
441
1404
 
442
- // Switch to Thumbnail tab
443
- this.switchToThumbnailTab();
444
- };
445
- ToolbarExtension.prototype.switchToThumbnailTab = function () {
446
- // Try multiple selectors to find the thumbnail tab button
447
- var thumbnailTab = document.querySelector('.docking-panel-thumbnail-view') || document.querySelector('[data-i18n="Thumbnails"]') || Array.from(document.querySelectorAll('.adsk-control-group .adsk-button')).find(function (btn) {
448
- return btn.textContent.includes('Thumbnails') || btn.title.includes('Thumbnails');
1405
+ // CRITICAL: Global state to persist across extension unload/reload cycles
1406
+ // This is necessary because Forge Viewer unloads extensions when navigating via thumbnails
1407
+ var GLOBAL_STATE = {
1408
+ viewables: null,
1409
+ docBrowserShouldBeOpen: false,
1410
+ currentIndex: 0
1411
+ };
1412
+ function registerToolbarExtension(Autodesk) {
1413
+ function ToolbarExtension(viewer, options) {
1414
+ var _this = this;
1415
+ Autodesk.Viewing.Extension.call(this, viewer, options);
1416
+ this.viewer = viewer;
1417
+ this.Autodesk = Autodesk;
1418
+ this.options = options;
1419
+ // Initialize EventBus
1420
+ this.eventBus = EventBus.getInstance();
1421
+ // Initialize Managers (Dependency Injection)
1422
+ // CRITICAL: Pass EventBus instance to ensure all managers use the same instance
1423
+ this.paginationManager = new PaginationManager(viewer, Autodesk, {}, this.eventBus);
1424
+ // Register page change callback (direct communication instead of EventBus)
1425
+ this.paginationManager.setPageChangeCallback(function (data) {
1426
+ _this.onPageChanged(data);
449
1427
  });
450
- if (thumbnailTab && !thumbnailTab.classList.contains('active')) {
451
- thumbnailTab.click();
1428
+ this.toolbarManager = new ToolbarManager(viewer, Autodesk, {
1429
+ Autodesk: Autodesk,
1430
+ filePath: options.filePath,
1431
+ onPanClick: function onPanClick() {
1432
+ return _this.handlePanClick();
1433
+ },
1434
+ onDocBrowserClick: function onDocBrowserClick() {
1435
+ return _this.handleDocBrowserClick();
1436
+ },
1437
+ onDownloadClick: function onDownloadClick() {
1438
+ return _this.handleDownloadClick();
1439
+ }
1440
+ });
1441
+ this.docBrowserManager = new DocumentBrowserManager(viewer, {
1442
+ autoOpen: true,
1443
+ persistState: true,
1444
+ defaultTab: 'thumbnails'
1445
+ }, this.eventBus);
1446
+ // Initialize Services
1447
+ this.downloadService = new DownloadService();
1448
+ // Toolbar healing interval
1449
+ this._toolbarInterval = null;
1450
+ this._buttonStateInterval = null;
1451
+ // Store viewables temporarily if toolbar not ready yet
1452
+ this._pendingViewables = null;
1453
+ this._toolbarReady = false;
1454
+ // Track if page change is in progress
1455
+ this._isPageChanging = false;
1456
+ // Bind event handlers
1457
+ this.onToolbarCreatedHandler = this.onToolbarCreated.bind(this);
1458
+ this.onGeometryLoadedHandler = this.onGeometryLoaded.bind(this);
1459
+ this.onPageChangedHandler = this.onPageChanged.bind(this);
1460
+ this.onViewablesSetHandler = this.onViewablesSet.bind(this);
1461
+ }
1462
+ ToolbarExtension.prototype = Object.create(Autodesk.Viewing.Extension.prototype);
1463
+ ToolbarExtension.prototype.constructor = ToolbarExtension;
1464
+ ToolbarExtension.prototype.load = function () {
1465
+ var _this2 = this;
1466
+ this.viewer.addEventListener(Autodesk.Viewing.TOOLBAR_CREATED_EVENT, this.onToolbarCreatedHandler);
1467
+ this.viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, this.onGeometryLoadedHandler);
1468
+ // Subscribe to EventBus events
1469
+ this.eventBus.on(EVENT_NAMES.PAGE_CHANGED, this.onPageChangedHandler);
1470
+ this.eventBus.on(EVENT_NAMES.VIEWABLES_SET, this.onViewablesSetHandler);
1471
+ // Subscribe to Document Browser open/close events
1472
+ this.eventBus.on(EVENT_NAMES.DOC_BROWSER_OPENED, function () {
1473
+ GLOBAL_STATE.docBrowserShouldBeOpen = true;
1474
+ setTimeout(function () {
1475
+ return _this2.syncDocBrowserButtonState();
1476
+ }, TOOLBAR_REFRESH_INTERVALS.DOM_SETTLE);
1477
+ });
1478
+ this.eventBus.on(EVENT_NAMES.DOC_BROWSER_CLOSED, function () {
1479
+ GLOBAL_STATE.docBrowserShouldBeOpen = false;
1480
+ setTimeout(function () {
1481
+ return _this2.syncDocBrowserButtonState();
1482
+ }, TOOLBAR_REFRESH_INTERVALS.DOM_SETTLE);
1483
+ });
1484
+ // CRITICAL: Restore state from GLOBAL_STATE if available
1485
+ // This handles the case where extension was unloaded and reloaded (e.g., thumbnail navigation)
1486
+ if (GLOBAL_STATE.viewables && GLOBAL_STATE.viewables.length > 0) {
1487
+ // Restore viewables to pagination manager
1488
+ this._pendingViewables = GLOBAL_STATE.viewables;
1489
+ // Restore Document Browser state
1490
+ if (GLOBAL_STATE.docBrowserShouldBeOpen) {
1491
+ this.docBrowserManager.setShouldRemainOpen(true);
1492
+ // CRITICAL: Sync button state immediately and repeatedly after load
1493
+ // This ensures button is active when extension reloads after using _changeModelFn
1494
+ var syncTimes = [50, 100, 150, 200, 300, 400, 500];
1495
+ syncTimes.forEach(function (delay) {
1496
+ setTimeout(function () {
1497
+ _this2.syncDocBrowserButtonState();
1498
+ }, delay);
1499
+ });
1500
+ }
452
1501
  }
1502
+ return true;
453
1503
  };
454
- ToolbarExtension.prototype.activatePanTool = function () {
455
- var viewer = this.viewer;
456
- var toolbar = viewer.toolbar;
457
- if (!toolbar) return;
458
-
459
- // Activate pan tool using viewer API
460
- try {
461
- viewer.setActiveNavigationTool('pan');
462
- } catch (e) {
463
- // Fallback: click the original pan button
464
- var originalPanBtn = document.getElementById('toolbar-panTool');
465
- if (originalPanBtn) {
466
- originalPanBtn.click();
467
- }
1504
+ ToolbarExtension.prototype.unload = function () {
1505
+ // CRITICAL: Save state to GLOBAL_STATE before unloading
1506
+ // This allows state to persist across unload/reload cycles (e.g., thumbnail navigation)
1507
+ var totalPages = this.paginationManager.getTotalPages();
1508
+ if (totalPages > 0) {
1509
+ GLOBAL_STATE.viewables = this.paginationManager.getViewables();
1510
+ GLOBAL_STATE.currentIndex = this.paginationManager.getCurrentPage();
1511
+ GLOBAL_STATE.docBrowserShouldBeOpen = this.docBrowserManager.getShouldRemainOpen();
468
1512
  }
469
-
470
- // Update custom pan button visual state
471
- var toolGroup = toolbar.getControl('custom-tool-group');
472
- if (toolGroup) {
473
- var panBtn = toolGroup.getControl('custom-pan-btn');
474
- if (panBtn) {
475
- panBtn.setState(Autodesk.Viewing.UI.Button.State.ACTIVE);
476
- if (panBtn.container) {
477
- panBtn.container.classList.add('active');
478
- panBtn.container.classList.remove('inactive');
479
- }
480
- }
1513
+ // Cleanup event listeners
1514
+ this.viewer.removeEventListener(Autodesk.Viewing.TOOLBAR_CREATED_EVENT, this.onToolbarCreatedHandler);
1515
+ this.viewer.removeEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, this.onGeometryLoadedHandler);
1516
+ // Unsubscribe from EventBus
1517
+ this.eventBus.off(EVENT_NAMES.PAGE_CHANGED, this.onPageChangedHandler);
1518
+ this.eventBus.off(EVENT_NAMES.VIEWABLES_SET, this.onViewablesSetHandler);
1519
+ // Cleanup intervals
1520
+ if (this._toolbarInterval) {
1521
+ clearInterval(this._toolbarInterval);
1522
+ this._toolbarInterval = null;
481
1523
  }
1524
+ return true;
482
1525
  };
483
- ToolbarExtension.prototype.onToolbarCreated = function (toolbar) {
1526
+ /**
1527
+ * Called when toolbar is created
1528
+ * Delegates to managers for setup
1529
+ */
1530
+ ToolbarExtension.prototype.onToolbarCreated = function () {
484
1531
  var _this3 = this;
1532
+ // Initial toolbar setup
485
1533
  this.refreshToolbar();
1534
+ // Add listener for geometry loaded to refresh toolbar
486
1535
  this.viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, function () {
487
1536
  setTimeout(function () {
488
1537
  _this3.refreshToolbar();
489
- _this3.updateCurrentIndexFromModel();
490
- }, 100);
1538
+ }, TOOLBAR_REFRESH_INTERVALS.GEOMETRY_SETTLE);
491
1539
  });
1540
+ // Add listener for toolbar created event
492
1541
  this.viewer.addEventListener(Autodesk.Viewing.TOOLBAR_CREATED_EVENT, function () {
493
1542
  setTimeout(function () {
494
1543
  _this3.refreshToolbar();
495
- }, 10);
1544
+ }, TOOLBAR_REFRESH_INTERVALS.BUTTON_STATE_CHECK);
496
1545
  });
497
- if (this._toolbarInterval) clearInterval(this._toolbarInterval);
498
- this._toolbarInterval = setInterval(function () {
499
- if (_this3.viewer && _this3.viewer.toolbar) {
500
- var toolGroup = _this3.viewer.toolbar.getControl('custom-tool-group');
501
- var pagGroup = _this3.viewer.toolbar.getControl('custom-pagination-group');
502
- if (!toolGroup || !pagGroup) {
503
- _this3.refreshToolbar();
504
- }
505
- _this3.checkButtonState();
506
- }
507
- }, 200);
508
- };
509
- ToolbarExtension.prototype.checkButtonState = function () {
510
- var viewer = this.viewer;
511
- if (!viewer.toolbar) return;
512
- var toolGroup = viewer.toolbar.getControl('custom-tool-group');
513
- if (!toolGroup) return;
514
-
515
- // Check Document Browser button state
516
- var docBtn = toolGroup.getControl('custom-doc-browser-btn');
517
- if (docBtn) {
518
- var ext = viewer.getExtension('Autodesk.DocumentBrowser');
519
- var isVisible = ext && ext.ui && ext.ui.panel && ext.ui.panel.isVisible();
520
- var newState = isVisible ? Autodesk.Viewing.UI.Button.State.ACTIVE : Autodesk.Viewing.UI.Button.State.INACTIVE;
521
- if (docBtn.getState() !== newState) {
522
- docBtn.setState(newState);
523
- }
524
-
525
- // Force CSS class update to ensure visual state is correct
526
- if (docBtn.container) {
527
- if (isVisible) {
528
- docBtn.container.classList.add('active');
529
- docBtn.container.classList.remove('inactive');
530
- } else {
531
- docBtn.container.classList.remove('active');
532
- docBtn.container.classList.add('inactive');
533
- }
534
- }
535
- }
536
-
537
- // Check Pan button state - ensure it stays active
538
- var panBtn = toolGroup.getControl('custom-pan-btn');
539
- if (panBtn) {
540
- // Check if pan tool is the active tool
541
- var activeTool = viewer.getActiveNavigationTool();
542
- var isPanActive = activeTool === 'pan';
543
- if (isPanActive) {
544
- panBtn.setState(Autodesk.Viewing.UI.Button.State.ACTIVE);
545
- if (panBtn.container) {
546
- panBtn.container.classList.add('active');
547
- panBtn.container.classList.remove('inactive');
548
- }
549
- }
550
- }
551
- };
552
- var originalUnload = ToolbarExtension.prototype.unload;
553
- ToolbarExtension.prototype.unload = function () {
554
- if (this._toolbarInterval) {
555
- clearInterval(this._toolbarInterval);
556
- this._toolbarInterval = null;
557
- }
558
- return originalUnload.call(this);
1546
+ // Start toolbar healing mechanism (also handles button state sync)
1547
+ this.startToolbarHealing();
559
1548
  };
1549
+ /**
1550
+ * Refresh toolbar - recreate if needed
1551
+ * This is the core method that handles toolbar persistence
1552
+ */
560
1553
  ToolbarExtension.prototype.refreshToolbar = function () {
561
- var viewer = this.viewer;
562
- var toolbar = viewer.toolbar;
1554
+ var _this4 = this;
1555
+ var toolbar = this.viewer.toolbar;
563
1556
  if (!toolbar) return;
564
- var defaultGroups = ['settingsTools', 'modelTools', 'navTools'];
565
- defaultGroups.forEach(function (id) {
566
- var group = toolbar.getControl(id);
567
- if (group) {
568
- group.setVisible(false);
569
- if (group.container) {
570
- group.container.style.display = 'none';
571
- }
572
- }
573
- });
1557
+ // Hide default groups
1558
+ this.toolbarManager.hideDefaultGroups();
1559
+ // Check and recreate tool group if needed
574
1560
  var toolGroup = toolbar.getControl('custom-tool-group');
575
- var pagGroup = toolbar.getControl('custom-pagination-group');
576
1561
  if (!toolGroup) {
577
- if (this.subToolbar) {
578
- this.subToolbar = null;
579
- }
580
- this.createToolGroup(toolbar);
1562
+ this.toolbarManager.createToolbar();
581
1563
  } else {
582
1564
  toolGroup.setVisible(true);
583
- this.subToolbar = toolGroup;
584
1565
  }
1566
+ // Check and recreate pagination group if needed
1567
+ var pagGroup = toolbar.getControl('custom-pagination-group');
585
1568
  if (!pagGroup) {
586
- if (this.paginationGroup) {
587
- this.paginationGroup = null;
588
- }
589
- this.createPaginationGroup(toolbar);
1569
+ this.paginationManager.createPaginationGroup(toolbar);
590
1570
  } else {
591
- // Don't force visibility here - let updatePaginationState handle it
592
- this.paginationGroup = pagGroup;
1571
+ // Ensure pagination manager has correct reference to existing group
1572
+ this.paginationManager.setPaginationGroup(pagGroup);
1573
+ pagGroup.setVisible(true);
1574
+ }
1575
+ // Mark toolbar as ready
1576
+ this._toolbarReady = true;
1577
+ // Process pending viewables if any
1578
+ if (this._pendingViewables) {
1579
+ this.paginationManager.setViewables(this._pendingViewables);
1580
+ // Auto-open Document Browser for all documents (single or multi-page)
1581
+ var isMultiPage = this._pendingViewables.length > 1;
1582
+ this.docBrowserManager.autoOpenIfMultiPage(isMultiPage);
1583
+ this._pendingViewables = null;
593
1584
  }
1585
+ // Show toolbar
594
1586
  toolbar.setVisible(true);
595
- this.updatePaginationState();
1587
+ // ALWAYS update pagination state after toolbar refresh
1588
+ // Use multiple timeouts to ensure it sticks
1589
+ var updateTimes = [10, 30, 50, 100];
1590
+ updateTimes.forEach(function (delay) {
1591
+ setTimeout(function () {
1592
+ _this4.paginationManager.updatePaginationState();
1593
+ }, delay);
1594
+ });
1595
+ // CRITICAL: Sync Document Browser button state after toolbar refresh
1596
+ // This ensures button is active if panel is open (especially after reload)
1597
+ var syncTimes = [50, 100, 150, 200];
1598
+ syncTimes.forEach(function (delay) {
1599
+ setTimeout(function () {
1600
+ var isOpen = _this4.docBrowserManager.isOpen();
1601
+ if (isOpen) {
1602
+ _this4.syncDocBrowserButtonState();
1603
+ }
1604
+ }, delay);
1605
+ });
1606
+ // Activate pan tool
1607
+ this.toolbarManager.activatePanButton();
596
1608
  };
597
- ToolbarExtension.prototype.createToolGroup = function (toolbar) {
598
- var _this4 = this;
599
- var viewer = this.viewer;
600
- this.subToolbar = new Autodesk.Viewing.UI.ControlGroup('custom-tool-group');
601
- toolbar.addControl(this.subToolbar);
602
- var panBtn = new Autodesk.Viewing.UI.Button('custom-pan-btn');
603
- panBtn.setIcon('adsk-icon-pan');
604
- panBtn.setToolTip('Pan');
605
- panBtn.onClick = function () {
606
- var originalPanBtn = document.getElementById('toolbar-panTool');
607
- if (originalPanBtn) {
608
- originalPanBtn.click();
609
- }
610
-
611
- // Set this button to active state
612
- if (panBtn.container) {
613
- panBtn.container.classList.add('active');
614
- panBtn.container.classList.remove('inactive');
1609
+ /**
1610
+ * Called when geometry is loaded
1611
+ * Restores button states
1612
+ */
1613
+ ToolbarExtension.prototype.onGeometryLoaded = function () {
1614
+ var _this5 = this;
1615
+ setTimeout(function () {
1616
+ _this5.toolbarManager.activatePanButton();
1617
+ _this5.paginationManager.updatePaginationState();
1618
+ }, TOOLBAR_REFRESH_INTERVALS.GEOMETRY_SETTLE);
1619
+ };
1620
+ /**
1621
+ * Called when page changes
1622
+ * Restores Document Browser and toolbar states
1623
+ */
1624
+ ToolbarExtension.prototype.onPageChanged = function (data) {
1625
+ var _this6 = this;
1626
+ if (!data || data.test) {
1627
+ return;
1628
+ }
1629
+ // Mark that page change is in progress to prevent premature pagination updates
1630
+ this._isPageChanging = true;
1631
+ // CRITICAL FIX: If page changed from Document Browser (thumbnails), sync button state IMMEDIATELY
1632
+ // This ensures the button is active when user navigates via thumbnails
1633
+ if (data.fromDocBrowser) {
1634
+ // Sync button state right away (before any other operations)
1635
+ this.syncDocBrowserButtonState();
1636
+ // Force recreate pagination group to ensure display updates
1637
+ var toolbar = this.viewer.toolbar;
1638
+ if (toolbar) {
1639
+ var pagGroup = toolbar.getControl('custom-pagination-group');
1640
+ if (pagGroup) {
1641
+ toolbar.removeControl(pagGroup);
1642
+ this.paginationManager.setPaginationGroup(null);
1643
+ }
615
1644
  }
616
- panBtn.setState(Autodesk.Viewing.UI.Button.State.ACTIVE);
617
- };
618
- this.subToolbar.addControl(panBtn);
619
- var docBrowserBtn = new Autodesk.Viewing.UI.Button('custom-doc-browser-btn');
620
- docBrowserBtn.setIcon('adsk-icon-documentModels');
621
- docBrowserBtn.setToolTip('Document Browser');
622
- var self = this;
623
- docBrowserBtn.onClick = function () {
624
- var ext = viewer.getExtension('Autodesk.DocumentBrowser');
625
- if (ext && ext.ui) {
626
- ext.ui.togglePanel();
627
- // Update flag based on new state
1645
+ }
1646
+ // Refresh toolbar to ensure both tool and pagination groups are restored
1647
+ this.refreshToolbar();
1648
+ // Restore Document Browser panel if needed
1649
+ if (data.shouldRestoreDocBrowser) {
1650
+ this.docBrowserManager.restoreState();
1651
+ // Force sync button state multiple times after restore
1652
+ var syncDelays = data.fromDocBrowser ? [10, 30, 50, 80, 100, 150, 200, 250, 300] : [50, 100, 150, 200, 250, 300];
1653
+ syncDelays.forEach(function (delay) {
628
1654
  setTimeout(function () {
629
- self.docBrowserShouldBeOpen = ext.ui.panel && ext.ui.panel.isVisible();
630
- }, 50);
1655
+ _this6.syncDocBrowserButtonState();
1656
+ }, delay);
1657
+ });
1658
+ }
1659
+ // Sync Document Browser button state and update pagination display at multiple intervals
1660
+ var syncIntervals = data.fromDocBrowser ? [10, 30, 50, 80, 100, 150, 200, 250, 300] : [50, 100, 150, 200, 250, 300];
1661
+ syncIntervals.forEach(function (delay, index) {
1662
+ setTimeout(function () {
1663
+ _this6.syncDocBrowserButtonState();
1664
+ _this6.paginationManager.updatePaginationState();
1665
+ if (index === 0) {
1666
+ _this6._isPageChanging = false;
1667
+ }
1668
+ }, delay);
1669
+ });
1670
+ // Additional pagination updates at various intervals to handle race conditions
1671
+ var updateIntervals = data.fromDocBrowser ? [60, 100, 120, 150, 180, 200, 250, 300, 350, 400, 500] : [100, 150, 200, 300];
1672
+ updateIntervals.forEach(function (delay) {
1673
+ setTimeout(function () {
1674
+ _this6.paginationManager.updatePaginationState();
1675
+ }, delay);
1676
+ });
1677
+ };
1678
+ /**
1679
+ * Called when viewables are set (from FileLoader)
1680
+ * Sets viewables to pagination manager and auto-opens Document Browser
1681
+ */
1682
+ ToolbarExtension.prototype.onViewablesSet = function (data) {
1683
+ if (data && data.viewables) {
1684
+ // CRITICAL: Save viewables to GLOBAL_STATE for persistence across unload/reload
1685
+ GLOBAL_STATE.viewables = data.viewables;
1686
+ // Check if toolbar is ready
1687
+ if (this._toolbarReady) {
1688
+ // Toolbar ready - set viewables immediately
1689
+ this.paginationManager.setViewables(data.viewables);
1690
+ // Auto-open Document Browser for all documents
1691
+ var isMultiPage = data.viewables.length > 1;
1692
+ GLOBAL_STATE.docBrowserShouldBeOpen = true;
1693
+ this.docBrowserManager.autoOpenIfMultiPage(isMultiPage);
1694
+ } else {
1695
+ // Toolbar not ready yet - store viewables for later
1696
+ this._pendingViewables = data.viewables;
631
1697
  }
632
- };
633
- this.subToolbar.addControl(docBrowserBtn);
634
- var downloadBtn = new Autodesk.Viewing.UI.Button('custom-download-btn');
635
- downloadBtn.setIcon('adsk-icon-custom-download');
636
- downloadBtn.setToolTip('Download File');
637
- downloadBtn.onClick = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
638
- var fileUrl, response, blob, urlPath, filename, blobUrl, anchor, _t2;
639
- return _regenerator().w(function (_context2) {
640
- while (1) switch (_context2.p = _context2.n) {
641
- case 0:
642
- if (!(_this4.options && _this4.options.filePath)) {
643
- _context2.n = 7;
644
- break;
645
- }
646
- _context2.p = 1;
647
- fileUrl = _this4.options.filePath;
648
- _context2.n = 2;
649
- return fetch(fileUrl);
650
- case 2:
651
- response = _context2.v;
652
- if (response.ok) {
653
- _context2.n = 3;
654
- break;
655
- }
656
- throw new Error("HTTP error! status: ".concat(response.status));
657
- case 3:
658
- _context2.n = 4;
659
- return response.blob();
660
- case 4:
661
- blob = _context2.v;
662
- urlPath = new URL(fileUrl).pathname;
663
- filename = decodeURIComponent(urlPath.split('/').pop()) || 'document.pdf';
664
- blobUrl = URL.createObjectURL(blob);
665
- anchor = document.createElement('a');
666
- anchor.href = blobUrl;
667
- anchor.download = filename;
668
- anchor.style.display = 'none';
669
- document.body.appendChild(anchor);
670
- anchor.click();
671
- document.body.removeChild(anchor);
672
- URL.revokeObjectURL(blobUrl);
673
- _context2.n = 6;
674
- break;
675
- case 5:
676
- _context2.p = 5;
677
- _t2 = _context2.v;
678
- console.error('Download error:', _t2);
679
- alert('Unable to download file: ' + _t2.message);
680
- case 6:
681
- _context2.n = 8;
682
- break;
683
- case 7:
684
- console.warn('FilePath not available in extension options');
685
- alert('File path not available for download');
686
- case 8:
687
- return _context2.a(2);
688
- }
689
- }, _callee2, null, [[1, 5]]);
690
- }));
691
- this.subToolbar.addControl(downloadBtn);
1698
+ }
692
1699
  };
693
- ToolbarExtension.prototype.createPaginationGroup = function (toolbar) {
694
- var _this5 = this;
695
- this.paginationGroup = new Autodesk.Viewing.UI.ControlGroup('custom-pagination-group');
696
- toolbar.addControl(this.paginationGroup);
697
- var prevBtn = new Autodesk.Viewing.UI.Button('prev-page-btn');
698
- prevBtn.setIcon('adsk-icon-custom-prev');
699
- prevBtn.addClass('custom-prev-btn');
700
- prevBtn.setToolTip('Previous Page');
701
- prevBtn.onClick = function () {
702
- if (_this5.viewables.length > 0) {
703
- _this5.currentIndex = (_this5.currentIndex - 1 + _this5.viewables.length) % _this5.viewables.length;
704
- _this5.loadCurrentViewable();
1700
+ /**
1701
+ * Start toolbar healing mechanism
1702
+ * Polls every 8ms to check if toolbar needs recreation
1703
+ */
1704
+ ToolbarExtension.prototype.startToolbarHealing = function () {
1705
+ var _this7 = this;
1706
+ if (this._toolbarInterval) {
1707
+ clearInterval(this._toolbarInterval);
1708
+ }
1709
+ // Store last known Document Browser state to detect changes
1710
+ this._lastDocBrowserState = null;
1711
+ this._healingCounter = 0;
1712
+ this._toolbarInterval = setInterval(function () {
1713
+ if (_this7.viewer && _this7.viewer.toolbar) {
1714
+ _this7._healingCounter++;
1715
+ var toolbar = _this7.viewer.toolbar;
1716
+ var toolGroup = toolbar.getControl('custom-tool-group');
1717
+ var pagGroup = toolbar.getControl('custom-pagination-group');
1718
+ // Refresh toolbar if either group is missing
1719
+ if (!toolGroup || !pagGroup) {
1720
+ _this7.refreshToolbar();
1721
+ }
1722
+ // Check if Document Browser panel state changed
1723
+ var currentDocBrowserState = _this7.docBrowserManager.isOpen();
1724
+ if (_this7._lastDocBrowserState !== null && _this7._lastDocBrowserState !== currentDocBrowserState) {
1725
+ // Update shouldRemainOpen flag based on current state
1726
+ if (currentDocBrowserState) {
1727
+ _this7.docBrowserManager.setShouldRemainOpen(true);
1728
+ }
1729
+ // Sync button state immediately when state changes
1730
+ _this7.syncDocBrowserButtonState();
1731
+ }
1732
+ _this7._lastDocBrowserState = currentDocBrowserState;
1733
+ // CRITICAL: Sync button state periodically (every ~50ms = every 6 healing cycles)
1734
+ // This catches thumbnail navigation where panel stays open but button might lose active state
1735
+ if (_this7._healingCounter % 6 === 0) {
1736
+ _this7.syncDocBrowserButtonState();
1737
+ }
1738
+ // ADDITIONAL: If panel is currently open, ensure button is always active
1739
+ // This is the ultimate fallback to handle thumbnail navigation
1740
+ if (currentDocBrowserState && _this7._healingCounter % 3 === 0) {
1741
+ // Check button state and force sync if needed (every ~24ms = every 3 healing cycles)
1742
+ var _toolGroup = toolbar.getControl('custom-tool-group');
1743
+ if (_toolGroup) {
1744
+ var docBtn = _toolGroup.getControl('custom-doc-browser-btn');
1745
+ if (docBtn) {
1746
+ var currentBtnState = docBtn.getState();
1747
+ var ACTIVE_STATE = _this7.Autodesk.Viewing.UI.Button.State.ACTIVE;
1748
+ // If panel is open but button is not active, force sync
1749
+ if (currentBtnState !== ACTIVE_STATE) {
1750
+ _this7.syncDocBrowserButtonState();
1751
+ }
1752
+ }
1753
+ }
1754
+ }
705
1755
  }
706
- };
707
- this.paginationGroup.addControl(prevBtn);
708
- var labelBtn = new Autodesk.Viewing.UI.Button('total-page-label');
709
- labelBtn.setToolTip('Page info');
710
- this.paginationGroup.addControl(labelBtn);
711
- var nextBtn = new Autodesk.Viewing.UI.Button('next-page-btn');
712
- nextBtn.setIcon('adsk-icon-custom-next');
713
- nextBtn.addClass('custom-next-btn');
714
- nextBtn.setToolTip('Next Page');
715
- nextBtn.onClick = function () {
716
- if (_this5.viewables.length > 0) {
717
- _this5.currentIndex = (_this5.currentIndex + 1) % _this5.viewables.length;
718
- _this5.loadCurrentViewable();
1756
+ }, TOOLBAR_REFRESH_INTERVALS.HEALING_POLL);
1757
+ };
1758
+ /**
1759
+ * Start button state synchronization
1760
+ * Polls to keep custom button states in sync with actual states
1761
+ */
1762
+ ToolbarExtension.prototype.startButtonStateSync = function () {
1763
+ var _this8 = this;
1764
+ if (this._buttonStateInterval) {
1765
+ clearInterval(this._buttonStateInterval);
1766
+ }
1767
+ this._buttonStateInterval = setInterval(function () {
1768
+ _this8.syncDocBrowserButtonState();
1769
+ }, TOOLBAR_REFRESH_INTERVALS.BUTTON_STATE_CHECK);
1770
+ };
1771
+ /**
1772
+ * Set Document Browser button active state
1773
+ */
1774
+ ToolbarExtension.prototype.setDocBrowserButtonActive = function (isActive) {
1775
+ var toolbar = this.viewer.toolbar;
1776
+ if (!toolbar) return;
1777
+ var toolGroup = toolbar.getControl('custom-tool-group');
1778
+ if (!toolGroup) return;
1779
+ var docBtn = toolGroup.getControl(CUSTOM_TOOLBAR_BUTTONS.DOC_BROWSER.id);
1780
+ if (!docBtn) return;
1781
+ var newState = isActive ? Autodesk.Viewing.UI.Button.State.ACTIVE : Autodesk.Viewing.UI.Button.State.INACTIVE;
1782
+ docBtn.setState(newState);
1783
+ };
1784
+ /**
1785
+ * Sync Document Browser button state with panel visibility
1786
+ */
1787
+ ToolbarExtension.prototype.syncDocBrowserButtonState = function () {
1788
+ var toolbar = this.viewer.toolbar;
1789
+ if (!toolbar) return;
1790
+ var toolGroup = toolbar.getControl('custom-tool-group');
1791
+ if (!toolGroup) return;
1792
+ var docBtn = toolGroup.getControl(CUSTOM_TOOLBAR_BUTTONS.DOC_BROWSER.id);
1793
+ if (!docBtn) return;
1794
+ var isOpen = this.docBrowserManager.isOpen();
1795
+ var ACTIVE_STATE = Autodesk.Viewing.UI.Button.State.ACTIVE;
1796
+ var INACTIVE_STATE = Autodesk.Viewing.UI.Button.State.INACTIVE;
1797
+ var expectedState = isOpen ? ACTIVE_STATE : INACTIVE_STATE;
1798
+ // Set button state via API
1799
+ docBtn.setState(expectedState);
1800
+ // Also update DOM class directly to ensure visual state
1801
+ var btnElement = docBtn.container;
1802
+ if (btnElement) {
1803
+ if (isOpen) {
1804
+ btnElement.classList.add('active');
1805
+ btnElement.classList.remove('inactive');
1806
+ } else {
1807
+ btnElement.classList.remove('active');
1808
+ btnElement.classList.add('inactive');
719
1809
  }
720
- };
721
- this.paginationGroup.addControl(nextBtn);
1810
+ }
1811
+ };
1812
+ /**
1813
+ * Handle Pan button click
1814
+ */
1815
+ ToolbarExtension.prototype.handlePanClick = function () {
1816
+ this.toolbarManager.activatePanButton();
722
1817
  };
1818
+ /**
1819
+ * Handle Document Browser button click
1820
+ */
1821
+ ToolbarExtension.prototype.handleDocBrowserClick = function () {
1822
+ var _this9 = this;
1823
+ this.docBrowserManager.togglePanel();
1824
+ // Sync button state with new panel state at multiple intervals
1825
+ [50, 100, 150, 200].forEach(function (delay) {
1826
+ setTimeout(function () {
1827
+ _this9.syncDocBrowserButtonState();
1828
+ }, delay);
1829
+ });
1830
+ };
1831
+ /**
1832
+ * Handle Download button click
1833
+ */
1834
+ ToolbarExtension.prototype.handleDownloadClick = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
1835
+ return _regenerator().w(function (_context) {
1836
+ while (1) switch (_context.p = _context.n) {
1837
+ case 0:
1838
+ _context.p = 0;
1839
+ _context.n = 1;
1840
+ return this.downloadService.downloadFile(this.options.filePath);
1841
+ case 1:
1842
+ _context.n = 3;
1843
+ break;
1844
+ case 2:
1845
+ _context.p = 2;
1846
+ _context.v;
1847
+ case 3:
1848
+ return _context.a(2);
1849
+ }
1850
+ }, _callee, this, [[0, 2]]);
1851
+ }));
1852
+ // Register extension
723
1853
  Autodesk.Viewing.theExtensionManager.registerExtension('ToolbarExtension', ToolbarExtension);
724
1854
  }
725
1855
 
@@ -812,156 +1942,110 @@ function styleInject(css, ref) {
812
1942
  }
813
1943
  }
814
1944
 
815
- 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;\n position: relative !important;\n margin: 0 !important;\n padding: 0 !important;\n transform: none !important;\n left: auto !important;\n}\n\n/* Document Browser Panel Styling */\n.docking-panel.document-browser-panel,\n.adsk-viewing-viewer .docking-panel.document-browser-panel {\n min-height: 400px !important;\n height: 80% !important;\n max-height: 80vh !important;\n}\n\n/* Ensure thumbnail container has proper height */\n.docking-panel.document-browser-panel .docking-panel-container-solid-color-a,\n.document-browser-panel .treeview,\n.document-browser-panel .thumbnails-container {\n height: calc(100% - 50px) !important;\n min-height: 350px !important;\n overflow-y: auto !important;\n}\n\n/* Thumbnail cards styling */\n.document-browser-panel .thumbnail-item,\n.document-browser-panel .thumbnail {\n display: flex !important;\n visibility: visible !important;\n}\n\n/* Ensure thumbnail images are visible */\n.document-browser-panel .thumbnail img,\n.document-browser-panel .thumbnail-item img {\n display: block !important;\n visibility: visible !important;\n max-width: 100% !important;\n height: auto !important;\n}\n";
1945
+ 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;\n position: relative !important;\n margin: 0 !important;\n padding: 0 !important;\n transform: none !important;\n left: auto !important;\n}\n";
816
1946
  styleInject(css_248z$1);
817
1947
 
818
- 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,\\\n<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\">\\\n<path fill=\"%23FFFFFF\" d=\"M9.293 0H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V4.707A1 1 0 0 0 13.707 4L10 .293A1 1 0 0 0 9.293 0M9.5 3.5v-2l3 3h-2a1 1 0 0 1-1-1m-1 4v3.793l1.146-1.147a.5.5 0 0 1 .708.708l-2 2a.5.5 0 0 1-.708 0l-2-2a.5.5 0 0 1 .708-.708L7.5 11.293V7.5a.5.5 0 0 1 1 0\"/>\\\n</svg>');\n background-repeat: no-repeat;\n background-position: center;\n background-size: 16px 16px;\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,\\\n<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\">\\\n<path fill=\"%23FFFFFF\" d=\"M16 14a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2zm-4.5-6.5H5.707l2.147-2.146a.5.5 0 1 0-.708-.708l-3 3a.5.5 0 0 0 0 .708l3 3a.5.5 0 0 0 .708-.708L5.707 8.5H11.5a.5.5 0 0 0 0-1\"/>\\\n</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,\\\n<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\">\\\n<path fill=\"%23FFFFFF\" d=\"M0 14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2a2 2 0 0 0-2 2zm4.5-6.5h5.793L8.146 5.354a.5.5 0 1 1 .708-.708l3 3a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708-.708L10.293 8.5H4.5a.5.5 0 0 1 0-1\"/>\\\n</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\n/* Comment icon - custom SVG (Smiley) */\n.adsk-icon-custom-comment::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 24 24\" fill=\"none\" stroke=\"%23FFFFFF\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><circle cx=\"12\" cy=\"12\" r=\"10\"></circle><path d=\"M8 14s1.5 2 4 2 4-2 4-2\"></path><line x1=\"9\" y1=\"9\" x2=\"9.01\" y2=\"9\"></line><line x1=\"15\" y1=\"9\" x2=\"15.01\" y2=\"9\"></line></svg>');\n background-repeat: no-repeat;\n background-position: center;\n background-size: contain;\n}\n\n/* Save icon - custom SVG */\n.adsk-icon-custom-save::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 24 24\" fill=\"none\" stroke=\"%23FFFFFF\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z\"></path><polyline points=\"17 21 17 13 7 13 7 21\"></polyline><polyline points=\"7 3 7 8 15 8\"></polyline></svg>');\n background-repeat: no-repeat;\n background-position: center;\n background-size: contain;\n}\n";
1948
+ var css_248z = "/* Custom icon styles for toolbar using SVG */\n/* Download icon - custom SVG (white, thicker stroke) */\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,\\\n<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"%23ffffff\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">\\\n <path d=\"M4.75 17.25a.75.75 0 0 1 .75.75v2.25c0 .138.112.25.25.25h12.5a.25.25 0 0 0 .25-.25V18a.75.75 0 0 1 1.5 0v2.25A1.75 1.75 0 0 1 18.25 22H5.75A1.75 1.75 0 0 1 4 20.25V18a.75.75 0 0 1 .75-.75Z\"/>\\\n <path d=\"M5.22 9.97a.749.749 0 0 1 1.06 0l4.97 4.969V2.75a.75.75 0 0 1 1.5 0v12.189l4.97-4.969a.749.749 0 1 1 1.06 1.06l-6.25 6.25a.749.749 0 0 1-1.06 0l-6.25-6.25a.749.749 0 0 1 0-1.06Z\"/>\\\n</svg>');\n background-repeat: no-repeat;\n background-position: center;\n background-size: 16px 16px;\n}\n/* Previous page icon - custom SVG (white, filled) */\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,\\\n<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 1024 1024\">\\\n<g transform=\"translate(512 512) scale(1.2) translate(-512 -512)\">\\\n<path fill=\"%23FFFFFF\" d=\"M685.248 104.704a64 64 0 010 90.496L368.448 512l316.8 316.8a64 64 0 01-90.496 90.496L232.704 557.248a64 64 0 010-90.496l362.048-362.048a64 64 0 0190.496 0z\"/>\\\n</g>\\\n</svg>');\n background-repeat: no-repeat;\n background-position: center;\n background-size: 16px 16px;\n}\n/* Next page icon - custom SVG (white, filled) */\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,\\\n<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 1024 1024\">\\\n<g transform=\"translate(512 512) scale(1.2) translate(-512 -512)\">\\\n<path fill=\"%23FFFFFF\" d=\"M338.752 104.704a64 64 0 000 90.496l316.8 316.8-316.8 316.8a64 64 0 0090.496 90.496l362.048-362.048a64 64 0 000-90.496L429.248 104.704a64 64 0 00-90.496 0z\"/>\\\n</g>\\\n</svg>');\n background-repeat: no-repeat;\n background-position: center;\n background-size: 16px 16px;\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.adsk-icon-caret-right::before {\n content: ']';\n font-family: 'adsk-viewing';\n}\n/* Comment icon - custom SVG (Smiley) */\n.adsk-icon-custom-comment::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 24 24\" fill=\"none\" stroke=\"%23FFFFFF\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><circle cx=\"12\" cy=\"12\" r=\"10\"></circle><path d=\"M8 14s1.5 2 4 2 4-2 4-2\"></path><line x1=\"9\" y1=\"9\" x2=\"9.01\" y2=\"9\"></line><line x1=\"15\" y1=\"9\" x2=\"15.01\" y2=\"9\"></line></svg>');\n background-repeat: no-repeat;\n background-position: center;\n background-size: contain;\n}\n/* Save icon - custom SVG */\n.adsk-icon-custom-save::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 24 24\" fill=\"none\" stroke=\"%23FFFFFF\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path d=\"M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z\"></path><polyline points=\"17 21 17 13 7 13 7 21\"></polyline><polyline points=\"7 3 7 8 15 8\"></polyline></svg>');\n background-repeat: no-repeat;\n background-position: center;\n background-size: contain;\n}\n";
819
1949
  styleInject(css_248z);
820
1950
 
821
1951
  var ViewerForgePDF = function ViewerForgePDF(_ref) {
822
1952
  var filePath = _ref.filePath,
823
1953
  fileExt = _ref.fileExt,
824
1954
  setViewer = _ref.setViewer;
825
- useCss('https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/style.min.css');
826
- var status = useScript('https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/viewer3D.min.js');
1955
+ // Load Forge Viewer CSS and JS from CDN
1956
+ useCss(FORGE_STYLE_URL);
1957
+ var status = useScript(FORGE_SCRIPT_URL);
827
1958
  useEffect(function () {
828
- if (status === 'ready' && window.Autodesk) {
829
- var Autodesk = window.Autodesk;
830
- if (!fileExt) {
831
- message.warning('You need to provide file extension');
832
- return;
833
- }
834
- var validExts = ['pdf', 'dwf', 'dwfx'];
835
- if (!validExts.includes(fileExt.toLowerCase())) {
836
- message.warning('Only support pdf, dwf, dwfx format');
837
- return;
838
- }
839
- Autodesk.Viewing.Initializer({
840
- env: 'Local'
841
- }, /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
842
- var viewerDiv, viewer, isDWF, handleLoadSuccess, xhr;
843
- return _regenerator().w(function (_context) {
844
- while (1) switch (_context.n) {
1959
+ if (status !== 'ready' || !window.Autodesk || !filePath || !fileExt) return;
1960
+ var initializeViewer = /*#__PURE__*/function () {
1961
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
1962
+ var Autodesk;
1963
+ return _regenerator().w(function (_context2) {
1964
+ while (1) switch (_context2.p = _context2.n) {
845
1965
  case 0:
846
- registerToolbarExtension(Autodesk);
847
- viewerDiv = document.getElementById('forgeViewerPDF');
848
- viewerDiv.innerHTML = '';
849
- viewer = new Autodesk.Viewing.GuiViewer3D(viewerDiv);
850
- viewer.start();
851
- viewer.loadExtension('Autodesk.DocumentBrowser');
852
- viewer.loadExtension('Autodesk.Viewing.MarkupsCore');
853
- viewer.loadExtension('Autodesk.Viewing.MarkupsGui');
854
- viewer.loadExtension('ToolbarExtension', {
855
- filePath: filePath
856
- });
857
- viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, function (e) {
858
- e.target.loadExtension('Autodesk.Viewing.MarkupsCore');
859
- e.target.loadExtension('Autodesk.Viewing.MarkupsGui');
860
- });
861
- isDWF = fileExt.toLowerCase() === 'pdf' ? 'Autodesk.PDF' : 'Autodesk.DWF';
862
- _context.n = 1;
863
- return viewer.loadExtension(isDWF);
1966
+ _context2.p = 0;
1967
+ Autodesk = window.Autodesk; // Validate file extension
1968
+ if (SUPPORTED_FILE_EXTENSIONS.includes(fileExt.toLowerCase())) {
1969
+ _context2.n = 1;
1970
+ break;
1971
+ }
1972
+ message.warning('Only support pdf, dwf, dwfx format');
1973
+ return _context2.a(2);
864
1974
  case 1:
865
- handleLoadSuccess = function handleLoadSuccess(e) {
866
- try {
867
- viewer.setReverseZoomDirection(true);
868
- var root = e.getDocumentNode().getRootNode();
869
- var view3d = root.search({
870
- type: 'geometry',
871
- role: '3d',
872
- progress: 'complete'
873
- }, true);
874
- var view2d = root.search({
875
- type: 'geometry',
876
- role: '2d',
877
- progress: 'complete'
878
- }, true);
879
- var viewables = view3d.concat(view2d);
880
- var toolbarExt = viewer.getExtension('ToolbarExtension');
881
- if (toolbarExt && typeof toolbarExt.setViewables === 'function') {
882
- toolbarExt.setViewables(viewables);
883
- }
884
- if (viewer.toolbar) {
885
- viewer.toolbar.setVisible(true);
886
- }
887
- if (viewables.length > 1) {
888
- // Auto-open Document Browser by clicking the original button
889
- setTimeout(function () {
890
- var originalDocBtn = document.getElementById('toolbar-documentModels');
891
- if (originalDocBtn && !originalDocBtn.classList.contains('active')) {
892
- originalDocBtn.click();
893
- }
894
-
895
- // Apply custom styling to the panel
896
- var documentBrowser = viewer.getExtension('Autodesk.DocumentBrowser');
897
- if (documentBrowser && documentBrowser.ui && documentBrowser.ui.panel) {
898
- documentBrowser.ui.panel.container.style.top = '0';
899
- documentBrowser.ui.panel.container.style.left = 'unset';
900
- documentBrowser.ui.panel.container.style.right = '0px';
901
- documentBrowser.ui.panel.container.style.width = '200px';
902
- documentBrowser.ui.panel.container.style.height = '80%';
903
- documentBrowser.ui.panel.container.style.minHeight = '400px';
1975
+ // Initialize Forge Viewer
1976
+ Autodesk.Viewing.Initializer({
1977
+ env: 'Local'
1978
+ }, /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
1979
+ var viewerDiv, viewer, fileLoader;
1980
+ return _regenerator().w(function (_context) {
1981
+ while (1) switch (_context.n) {
1982
+ case 0:
1983
+ // Register custom toolbar extension
1984
+ registerToolbarExtension(Autodesk);
1985
+ // Create viewer instance
1986
+ viewerDiv = document.getElementById('forgeViewerPDF');
1987
+ if (viewerDiv) {
1988
+ _context.n = 1;
1989
+ break;
904
1990
  }
905
-
906
- // Switch to Thumbnail tab after a short delay
907
- setTimeout(function () {
908
- // Try multiple selectors to find the thumbnail tab button
909
- var thumbnailTab = document.querySelector('.docking-panel-thumbnail-view') || document.querySelector('[data-i18n="Thumbnails"]') || Array.from(document.querySelectorAll('.adsk-control-group .adsk-button')).find(function (btn) {
910
- return btn.textContent.includes('Thumbnails') || btn.title.includes('Thumbnails');
911
- });
912
- if (thumbnailTab && !thumbnailTab.classList.contains('active')) {
913
- thumbnailTab.click();
1991
+ return _context.a(2);
1992
+ case 1:
1993
+ viewerDiv.innerHTML = '';
1994
+ viewer = new Autodesk.Viewing.GuiViewer3D(viewerDiv);
1995
+ viewer.start();
1996
+ // Load required extensions
1997
+ _context.n = 2;
1998
+ return viewer.loadExtension('Autodesk.DocumentBrowser');
1999
+ case 2:
2000
+ _context.n = 3;
2001
+ return viewer.loadExtension('Autodesk.Viewing.MarkupsCore');
2002
+ case 3:
2003
+ _context.n = 4;
2004
+ return viewer.loadExtension('Autodesk.Viewing.MarkupsGui');
2005
+ case 4:
2006
+ _context.n = 5;
2007
+ return viewer.loadExtension('ToolbarExtension', {
2008
+ filePath: filePath
2009
+ });
2010
+ case 5:
2011
+ // Initialize FileLoader service
2012
+ fileLoader = new FileLoader(viewer); // Note: ToolbarExtension now subscribes to VIEWABLES_SET directly
2013
+ // No need to forward events here - prevents infinite recursion
2014
+ // Load the document using FileLoader service
2015
+ _context.n = 6;
2016
+ return fileLoader.loadFile(filePath, fileExt.toLowerCase(), {
2017
+ onSuccess: function onSuccess() {
2018
+ // Pass viewer instance to parent component
2019
+ if (setViewer) {
2020
+ setViewer(viewer);
2021
+ }
2022
+ },
2023
+ onError: function onError(error) {
2024
+ message.error('Failed to load document');
914
2025
  }
915
- }, 200);
916
- }, 500);
917
- }
918
-
919
- // Ensure Custom Pan tool is active by default
920
- setTimeout(function () {
921
- var customPanBtn = document.getElementById('custom-pan-btn');
922
- if (customPanBtn) {
923
- customPanBtn.click();
924
- // Double check visual state
925
- if (!customPanBtn.classList.contains('active')) {
926
- customPanBtn.classList.add('active');
927
- customPanBtn.classList.remove('inactive');
928
- }
929
- } else {
930
- var _viewer$toolbar;
931
- // Fallback if custom button not found immediately, try accessing via viewer toolbar
932
- var toolGroup = (_viewer$toolbar = viewer.toolbar) === null || _viewer$toolbar === void 0 ? void 0 : _viewer$toolbar.getControl('custom-tool-group');
933
- var panBtnConf = toolGroup === null || toolGroup === void 0 ? void 0 : toolGroup.getControl('custom-pan-btn');
934
- if (panBtnConf) {
935
- panBtnConf.setState(1); // ACTIVE
936
- }
937
- }
938
- }, 600);
939
- if (setViewer) setViewer(viewer);
940
- } catch (err) {
941
- console.error('Error in handleLoadSuccess:', err);
942
- }
943
- };
944
- if (isDWF === 'Autodesk.DWF') {
945
- xhr = new XMLHttpRequest();
946
- xhr.open('GET', filePath, true);
947
- xhr.responseType = 'blob';
948
- xhr.onload = function () {
949
- if (this.status === 200) {
950
- var myBlob = this.response;
951
- var url1 = window.URL.createObjectURL(myBlob);
952
- viewer.loadModel(url1 + '#.dwf', {}, handleLoadSuccess);
2026
+ });
2027
+ case 6:
2028
+ return _context.a(2);
953
2029
  }
954
- };
955
- xhr.send();
956
- } else {
957
- viewer.loadModel(filePath, {}, handleLoadSuccess);
958
- }
2030
+ }, _callee);
2031
+ })));
2032
+ _context2.n = 3;
2033
+ break;
959
2034
  case 2:
960
- return _context.a(2);
2035
+ _context2.p = 2;
2036
+ _context2.v;
2037
+ message.error('Failed to initialize viewer');
2038
+ case 3:
2039
+ return _context2.a(2);
961
2040
  }
962
- }, _callee);
963
- })));
964
- }
2041
+ }, _callee2, null, [[0, 2]]);
2042
+ }));
2043
+ return function initializeViewer() {
2044
+ return _ref2.apply(this, arguments);
2045
+ };
2046
+ }();
2047
+ initializeViewer();
2048
+ // No cleanup needed - ToolbarExtension handles its own subscriptions
965
2049
  // eslint-disable-next-line react-hooks/exhaustive-deps
966
2050
  }, [status, filePath, fileExt]);
967
2051
  return /*#__PURE__*/jsx("div", {