@mlightcad/cad-simple-viewer 1.7.6-preview.0 → 1.7.6

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.
Files changed (65) hide show
  1. package/dist/cad-simple-viewer.js +6060 -5654
  2. package/dist/cad-simple-viewer.umd.cjs +74 -74
  3. package/lib/app/AcApDocManager.d.ts.map +1 -1
  4. package/lib/app/AcApDocManager.js +11 -6
  5. package/lib/app/AcApDocManager.js.map +1 -1
  6. package/lib/editor/input/AcEdOsnapCenterMarks.d.ts +15 -2
  7. package/lib/editor/input/AcEdOsnapCenterMarks.d.ts.map +1 -1
  8. package/lib/editor/input/AcEdOsnapCenterMarks.js +63 -13
  9. package/lib/editor/input/AcEdOsnapCenterMarks.js.map +1 -1
  10. package/lib/editor/input/AcEdOsnapResolver.d.ts +14 -0
  11. package/lib/editor/input/AcEdOsnapResolver.d.ts.map +1 -1
  12. package/lib/editor/input/AcEdOsnapResolver.js +246 -32
  13. package/lib/editor/input/AcEdOsnapResolver.js.map +1 -1
  14. package/lib/editor/input/AcEdSelectionFilter.d.ts +6 -0
  15. package/lib/editor/input/AcEdSelectionFilter.d.ts.map +1 -1
  16. package/lib/editor/input/AcEdSelectionFilter.js +19 -2
  17. package/lib/editor/input/AcEdSelectionFilter.js.map +1 -1
  18. package/lib/editor/input/AcEditor.d.ts +6 -0
  19. package/lib/editor/input/AcEditor.d.ts.map +1 -1
  20. package/lib/editor/input/AcEditor.js +9 -0
  21. package/lib/editor/input/AcEditor.js.map +1 -1
  22. package/lib/editor/input/ui/AcEdCommandLine.d.ts +12 -0
  23. package/lib/editor/input/ui/AcEdCommandLine.d.ts.map +1 -1
  24. package/lib/editor/input/ui/AcEdCommandLine.js +54 -16
  25. package/lib/editor/input/ui/AcEdCommandLine.js.map +1 -1
  26. package/lib/editor/input/ui/AcEdInputManager.d.ts +15 -0
  27. package/lib/editor/input/ui/AcEdInputManager.d.ts.map +1 -1
  28. package/lib/editor/input/ui/AcEdInputManager.js +41 -10
  29. package/lib/editor/input/ui/AcEdInputManager.js.map +1 -1
  30. package/lib/editor/view/AcEdBaseView.d.ts +34 -0
  31. package/lib/editor/view/AcEdBaseView.d.ts.map +1 -1
  32. package/lib/editor/view/AcEdBaseView.js +35 -44
  33. package/lib/editor/view/AcEdBaseView.js.map +1 -1
  34. package/lib/editor/view/AcEdSpatialQueryResult.d.ts +7 -0
  35. package/lib/editor/view/AcEdSpatialQueryResult.d.ts.map +1 -1
  36. package/lib/editor/view/AcEdSpatialQueryResult.js.map +1 -1
  37. package/lib/find/findText.d.ts.map +1 -1
  38. package/lib/find/findText.js +49 -15
  39. package/lib/find/findText.js.map +1 -1
  40. package/lib/i18n/ar/jig.d.ts +2 -0
  41. package/lib/i18n/ar/jig.d.ts.map +1 -1
  42. package/lib/i18n/ar/jig.js +1 -1
  43. package/lib/i18n/ar/jig.js.map +1 -1
  44. package/lib/i18n/cs/jig.d.ts +2 -0
  45. package/lib/i18n/cs/jig.d.ts.map +1 -1
  46. package/lib/i18n/cs/jig.js +2 -0
  47. package/lib/i18n/cs/jig.js.map +1 -1
  48. package/lib/i18n/en/jig.d.ts +2 -0
  49. package/lib/i18n/en/jig.d.ts.map +1 -1
  50. package/lib/i18n/en/jig.js +2 -0
  51. package/lib/i18n/en/jig.js.map +1 -1
  52. package/lib/i18n/tr/jig.d.ts +2 -0
  53. package/lib/i18n/tr/jig.d.ts.map +1 -1
  54. package/lib/i18n/tr/jig.js +2 -0
  55. package/lib/i18n/tr/jig.js.map +1 -1
  56. package/lib/i18n/zh/jig.d.ts +2 -0
  57. package/lib/i18n/zh/jig.d.ts.map +1 -1
  58. package/lib/i18n/zh/jig.js +2 -0
  59. package/lib/i18n/zh/jig.js.map +1 -1
  60. package/lib/view/AcTrView2d.d.ts +43 -2
  61. package/lib/view/AcTrView2d.d.ts.map +1 -1
  62. package/lib/view/AcTrView2d.js +231 -76
  63. package/lib/view/AcTrView2d.js.map +1 -1
  64. package/package.json +5 -5
  65. package/src/find/findText.ts +43 -14
@@ -180,6 +180,11 @@ var AcTrView2d = /** @class */ (function (_super) {
180
180
  var container = (_a = mergedOptions.container) !== null && _a !== void 0 ? _a : document.createElement('div');
181
181
  mergedOptions.container = container;
182
182
  container.style.overflow = 'hidden';
183
+ // Allow focusing the container after canvas clicks so document-level
184
+ // shortcuts stay scoped to this viewer without stealing host-page focus.
185
+ if (!container.hasAttribute('tabindex')) {
186
+ container.tabIndex = -1;
187
+ }
183
188
  var renderer = new THREE.WebGLRenderer({
184
189
  antialias: true,
185
190
  alpha: true
@@ -359,6 +364,12 @@ var AcTrView2d = /** @class */ (function (_super) {
359
364
  * ENTITY parse and linework convert; glyph jobs await this before draw.
360
365
  */
361
366
  _this._textStyleFontPreloadPromise = null;
367
+ /**
368
+ * Aborts canvas / document DOM listeners registered on this view.
369
+ * Custom singleton listeners are removed explicitly in {@link dispose}.
370
+ */
371
+ _this._viewDomAbort = new AbortController();
372
+ _this._viewDisposed = false;
362
373
  /** Transient reading mode forces black linework on a white canvas. */
363
374
  _this._readingMode = new AcApReadingModeState({
364
375
  getCurrentBackgroundColor: function () { return _this._renderer.currentBackgroundColor; },
@@ -442,16 +453,27 @@ var AcTrView2d = /** @class */ (function (_super) {
442
453
  };
443
454
  _this._disposeCanvasTouchCallout = disposeCanvasTouchCallout;
444
455
  var onProgressiveInput = function () { return _this.noteProgressiveUserInput(); };
445
- renderer.domElement.addEventListener('pointerdown', onProgressiveInput, {
456
+ // Pointer and wheel both claim shortcut focus so undo/erase still work
457
+ // after zooming without a prior click, without stealing focus from host
458
+ // inputs/textareas/contenteditable fields.
459
+ var onCanvasPointerDown = function () {
460
+ onProgressiveInput();
461
+ _this.focusViewerForShortcuts();
462
+ };
463
+ var onCanvasWheel = function () {
464
+ onProgressiveInput();
465
+ _this.focusViewerForShortcuts();
466
+ };
467
+ renderer.domElement.addEventListener('pointerdown', onCanvasPointerDown, {
446
468
  capture: true
447
469
  });
448
- renderer.domElement.addEventListener('wheel', onProgressiveInput, {
470
+ renderer.domElement.addEventListener('wheel', onCanvasWheel, {
449
471
  capture: true,
450
472
  passive: true
451
473
  });
452
474
  _this._disposeProgressiveInputWatch = function () {
453
- renderer.domElement.removeEventListener('pointerdown', onProgressiveInput, { capture: true });
454
- renderer.domElement.removeEventListener('wheel', onProgressiveInput, {
475
+ renderer.domElement.removeEventListener('pointerdown', onCanvasPointerDown, { capture: true });
476
+ renderer.domElement.removeEventListener('wheel', onCanvasWheel, {
455
477
  capture: true
456
478
  });
457
479
  };
@@ -468,27 +490,32 @@ var AcTrView2d = /** @class */ (function (_super) {
468
490
  setAcTrDrawOrderZAllocator(function () { return _this._renderer.allocateDrawOrderZ(); });
469
491
  var fontMapping = AcApSettingManager.instance.fontMapping;
470
492
  _this._renderer.setFontMapping(fontMapping);
471
- _this._renderer.events.fontNotFound.addEventListener(function (args) {
493
+ _this._onFontNotFound = function (args) {
472
494
  var _a;
473
495
  eventBus.emit('font-not-found', {
474
496
  fontName: args.fontName,
475
497
  count: (_a = args.count) !== null && _a !== void 0 ? _a : 0
476
498
  });
477
- });
478
- _this._renderer.events.fontLoaded.addEventListener(function (args) {
499
+ };
500
+ _this._onFontLoaded = function (args) {
479
501
  // Lazy load success clears FontManager.missedFonts; refresh status-bar state.
480
502
  eventBus.emit('missed-data-changed', {});
481
503
  // On-demand faces (e.g. style `malgun`) may finish after the first glyph
482
504
  // bake. Rebuild text so Hangul is not left as permanent '?'.
483
505
  _this.scheduleGlyphRedrawAfterFontLoad(args === null || args === void 0 ? void 0 : args.fontName);
484
- });
506
+ };
507
+ _this._renderer.events.fontNotFound.addEventListener(_this._onFontNotFound);
508
+ _this._renderer.events.fontLoaded.addEventListener(_this._onFontLoaded);
485
509
  _this._scene = _this.createScene();
486
510
  _this._layerAppearance = new AcTrLayerAppearanceController(_this._scene, _this._renderer);
487
511
  _this._inheritedLayerMaterialMapper = new AcTrInheritedLayerMaterialMapper(function (layerName) { return _this._layerAppearance.getEffectiveLayerTraits(layerName); }, _this._renderer);
488
512
  // Initialize background color through setter to keep renderer/cursor in sync.
489
513
  _this.backgroundColor =
490
514
  (_b = mergedOptions.background) !== null && _b !== void 0 ? _b : ACGI_MODEL_SPACE_BACKGROUND;
491
- _this._stats = _this.createStats(AcApSettingManager.instance.isShowStats && _this.isActiveManagedView());
515
+ // During main-view construction the manager singleton is not published yet,
516
+ // so treat a missing manager as "this is the primary canvas".
517
+ _this._stats = _this.createStats(AcApSettingManager.instance.isShowStats &&
518
+ (AcApDocManager.tryGetInstance() == null || _this.isActiveManagedView()));
492
519
  // Layout background sysvars drive the canvas clear colour and ACI-7
493
520
  // inversion (`MODELBKCOLOR` for model space, `PAPERBKCOLOR` for the
494
521
  // active layout). `COLORTHEME` only affects UI chrome — see
@@ -496,23 +523,28 @@ var AcTrView2d = /** @class */ (function (_super) {
496
523
  var sysVarManager = AcDbSysVarManager.instance();
497
524
  var modelBkVar = AcDbSystemVariables.MODELBKCOLOR.toLowerCase();
498
525
  var paperBkVar = AcDbSystemVariables.PAPERBKCOLOR.toLowerCase();
499
- sysVarManager.events.sysVarChanged.addEventListener(function (args) {
526
+ _this._onSysVarChanged = function (args) {
500
527
  var nameLower = args.name.toLowerCase();
501
528
  if (nameLower === modelBkVar || nameLower === paperBkVar) {
502
- var isModelSpace = _this.isModelSpaceLayout(args.database);
529
+ var database = args.database;
530
+ if (!database)
531
+ return;
532
+ var isModelSpace = _this.isModelSpaceLayout(database);
503
533
  var applies = (nameLower === modelBkVar && isModelSpace) ||
504
534
  (nameLower === paperBkVar && !isModelSpace);
505
535
  if (!applies) {
506
536
  return;
507
537
  }
508
- _this.applyCanvasBackground(readLayoutBackgroundColor(args.database, isModelSpace));
538
+ _this.applyCanvasBackground(readLayoutBackgroundColor(database, isModelSpace));
509
539
  }
510
- });
511
- AcApSettingManager.instance.events.modified.addEventListener(function (args) {
540
+ };
541
+ sysVarManager.events.sysVarChanged.addEventListener(_this._onSysVarChanged);
542
+ _this._onSettingsModified = function (args) {
512
543
  if (args.key == 'isShowStats') {
513
544
  _this.toggleStatsVisibility(_this._stats, args.value);
514
545
  }
515
- });
546
+ };
547
+ AcApSettingManager.instance.events.modified.addEventListener(_this._onSettingsModified);
516
548
  var selectionStartWcs = null;
517
549
  var selectionStartCanvas = null;
518
550
  var selectionPreviewEl = null;
@@ -618,6 +650,7 @@ var AcTrView2d = /** @class */ (function (_super) {
618
650
  selectionStartWcs = null;
619
651
  selectionStartCanvas = null;
620
652
  };
653
+ var viewDomSignal = _this._viewDomAbort.signal;
621
654
  _this.canvas.addEventListener('mousedown', function (e) {
622
655
  if (e.button !== 0)
623
656
  return;
@@ -627,7 +660,7 @@ var AcTrView2d = /** @class */ (function (_super) {
627
660
  return;
628
661
  }
629
662
  beginSelectionPreview(e.clientX, e.clientY);
630
- });
663
+ }, { signal: viewDomSignal });
631
664
  _this.canvas.addEventListener('mousemove', function (e) {
632
665
  if (!selectionStartWcs || !selectionPreviewEl || !selectionStartCanvas) {
633
666
  return;
@@ -636,7 +669,7 @@ var AcTrView2d = /** @class */ (function (_super) {
636
669
  return;
637
670
  }
638
671
  updateSelectionPreview(e.clientX, e.clientY, _this.getPointerSelectionAction(e));
639
- });
672
+ }, { signal: viewDomSignal });
640
673
  _this.canvas.addEventListener('mouseup', function (e) {
641
674
  if (_this._gripManager.isDragging) {
642
675
  resetSelectionDrag();
@@ -653,8 +686,8 @@ var AcTrView2d = /** @class */ (function (_super) {
653
686
  });
654
687
  var action = _this.getPointerSelectionAction(e);
655
688
  finishSelection(e.clientX, e.clientY, action, _this.isSelectionClick(selectionStartCanvas, endCanvas));
656
- });
657
- acedAttachMobileBoxGesture({
689
+ }, { signal: viewDomSignal });
690
+ _this._disposeMobileBoxGesture = acedAttachMobileBoxGesture({
658
691
  element: _this.canvas,
659
692
  shouldStart: function () { return canHandleMobileBoxGesture(); },
660
693
  setNavigationEnabled: function (enabled) {
@@ -693,16 +726,19 @@ var AcTrView2d = /** @class */ (function (_super) {
693
726
  return;
694
727
  }
695
728
  void _this.openPickedEntityEditor(e);
696
- });
729
+ }, { signal: viewDomSignal });
697
730
  // When using OrbitControls in THREE.js, it attaches its own event listeners to the DOM elements,
698
731
  // such as the canvas or the entire document. This can interfere with other event listeners you
699
- // add, including the keydown event.
732
+ // add, including the keydown event. Scope to this view's container so host-page shortcuts
733
+ // (and post-destroy key presses) are not captured.
700
734
  document.addEventListener('keydown', function (e) {
701
735
  if (!_this.isActiveManagedView())
702
736
  return;
737
+ if (!_this.isShortcutEventInsideViewer(e))
738
+ return;
703
739
  _this._keyHandler.handleKeyDown(e);
704
- });
705
- acdbHostApplicationServices().layoutManager.events.layoutSwitched.addEventListener(function (args) {
740
+ }, { signal: viewDomSignal });
741
+ _this._onLayoutSwitched = function (args) {
706
742
  var _a, _b;
707
743
  if (!_this.isActiveManagedView())
708
744
  return;
@@ -742,7 +778,8 @@ var AcTrView2d = /** @class */ (function (_super) {
742
778
  if (isFirstVisit) {
743
779
  _this.applyInitialZoom(btrId, args.layout);
744
780
  }
745
- });
781
+ };
782
+ acdbHostApplicationServices().layoutManager.events.layoutSwitched.addEventListener(_this._onLayoutSwitched);
746
783
  _this._css2dRenderer = new CSS2DRenderer();
747
784
  _this._css2dRenderer.setSize(_this.width, _this.height);
748
785
  _this._css2dRenderer.domElement.style.position = 'absolute';
@@ -841,12 +878,14 @@ var AcTrView2d = /** @class */ (function (_super) {
841
878
  // This method is called after camera and render are created.
842
879
  // Children class can override this method to add its own logic
843
880
  this.setCursor(AcEdCorsorType.Crosshair);
844
- this.editor.events.commandWillStart.addEventListener(function () {
881
+ this._onCommandWillStartHitTest = function () {
845
882
  _this.htmlTransientManager.setHitTestEnabled(false);
846
- });
847
- this.editor.events.commandEnded.addEventListener(function () {
883
+ };
884
+ this._onCommandEndedHitTest = function () {
848
885
  _this.htmlTransientManager.setHitTestEnabled(true);
849
- });
886
+ };
887
+ this.editor.events.commandWillStart.addEventListener(this._onCommandWillStartHitTest);
888
+ this.editor.events.commandEnded.addEventListener(this._onCommandEndedHitTest);
850
889
  };
851
890
  Object.defineProperty(AcTrView2d.prototype, "mode", {
852
891
  /**
@@ -2191,6 +2230,37 @@ var AcTrView2d = /** @class */ (function (_super) {
2191
2230
  var sortedResults = sortPickResults(results, point);
2192
2231
  return pickOneOnly ? sortedResults.slice(0, 1) : sortedResults;
2193
2232
  };
2233
+ /**
2234
+ * @inheritdoc
2235
+ */
2236
+ AcTrView2d.prototype.getViewportCoordinateMapper = function (viewportId) {
2237
+ var e_7, _a;
2238
+ var _b, _c;
2239
+ var vpView;
2240
+ try {
2241
+ for (var _d = __values((_c = (_b = this.activeLayoutView) === null || _b === void 0 ? void 0 : _b.viewportViews) !== null && _c !== void 0 ? _c : []), _e = _d.next(); !_e.done; _e = _d.next()) {
2242
+ var candidate = _e.value;
2243
+ if (candidate.viewport.id === viewportId) {
2244
+ vpView = candidate;
2245
+ break;
2246
+ }
2247
+ }
2248
+ }
2249
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
2250
+ finally {
2251
+ try {
2252
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
2253
+ }
2254
+ finally { if (e_7) throw e_7.error; }
2255
+ }
2256
+ if (!vpView)
2257
+ return undefined;
2258
+ return {
2259
+ paperToModel: function (point) { return vpView.paperPointToModel(point); },
2260
+ modelToPaper: function (point) { return vpView.modelPointToPaper(point); },
2261
+ containsPaperPoint: function (point) { return vpView.containsPaperPoint(point); }
2262
+ };
2263
+ };
2194
2264
  /**
2195
2265
  * Resolves hits against the model-space layout for each viewport the
2196
2266
  * click drills through. Appends the matches into `results` (caller
@@ -2208,7 +2278,7 @@ var AcTrView2d = /** @class */ (function (_super) {
2208
2278
  * paper-space pick.
2209
2279
  */
2210
2280
  AcTrView2d.prototype.pickThroughViewports = function (paperPoint, paperBox, viewports, results) {
2211
- var e_7, _a;
2281
+ var e_8, _a;
2212
2282
  var modelLayout = this._scene.modelSpaceLayout;
2213
2283
  if (!modelLayout)
2214
2284
  return;
@@ -2233,7 +2303,7 @@ var AcTrView2d = /** @class */ (function (_super) {
2233
2303
  if (!isEffectiveSpatialQueryHit(item))
2234
2304
  return;
2235
2305
  if (modelLayout.isIntersectWith(item.id, vpRaycaster)) {
2236
- results.push(item);
2306
+ results.push(__assign(__assign({}, item), { viewportId: vpView.viewport.id }));
2237
2307
  }
2238
2308
  });
2239
2309
  };
@@ -2243,12 +2313,12 @@ var AcTrView2d = /** @class */ (function (_super) {
2243
2313
  _loop_1(vpView);
2244
2314
  }
2245
2315
  }
2246
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
2316
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
2247
2317
  finally {
2248
2318
  try {
2249
2319
  if (viewports_1_1 && !viewports_1_1.done && (_a = viewports_1.return)) _a.call(viewports_1);
2250
2320
  }
2251
- finally { if (e_7) throw e_7.error; }
2321
+ finally { if (e_8) throw e_8.error; }
2252
2322
  }
2253
2323
  };
2254
2324
  /**
@@ -2281,7 +2351,7 @@ var AcTrView2d = /** @class */ (function (_super) {
2281
2351
  * that interior also selects those polylines and can stall highlight work.
2282
2352
  */
2283
2353
  AcTrView2d.prototype.refineCrossingSelectionHits = function (box, results) {
2284
- var e_8, _a;
2354
+ var e_9, _a;
2285
2355
  var _b;
2286
2356
  var database = (_b = AcApDocManager.instance.curDocument) === null || _b === void 0 ? void 0 : _b.database;
2287
2357
  if (!database) {
@@ -2306,12 +2376,12 @@ var AcTrView2d = /** @class */ (function (_super) {
2306
2376
  }
2307
2377
  }
2308
2378
  }
2309
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
2379
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
2310
2380
  finally {
2311
2381
  try {
2312
2382
  if (results_1_1 && !results_1_1.done && (_a = results_1.return)) _a.call(results_1);
2313
2383
  }
2314
- finally { if (e_8) throw e_8.error; }
2384
+ finally { if (e_9) throw e_9.error; }
2315
2385
  }
2316
2386
  return ids;
2317
2387
  };
@@ -2327,7 +2397,7 @@ var AcTrView2d = /** @class */ (function (_super) {
2327
2397
  * @inheritdoc
2328
2398
  */
2329
2399
  AcTrView2d.prototype.updateLayer = function (layer, changes) {
2330
- var e_9, _a;
2400
+ var e_10, _a;
2331
2401
  var touchedObjectIds = this._scene.updateLayer(this.toLayerInfo(layer)).touchedObjectIds;
2332
2402
  if (this._layerAppearance.layerStyleMayHaveChanged(changes)) {
2333
2403
  this._layerAppearance.syncFromLiveRecord(layer);
@@ -2349,12 +2419,12 @@ var AcTrView2d = /** @class */ (function (_super) {
2349
2419
  this.applySessionHiddenObjectState(objectId);
2350
2420
  }
2351
2421
  }
2352
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
2422
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
2353
2423
  finally {
2354
2424
  try {
2355
2425
  if (touchedObjectIds_1_1 && !touchedObjectIds_1_1.done && (_a = touchedObjectIds_1.return)) _a.call(touchedObjectIds_1);
2356
2426
  }
2357
- finally { if (e_9) throw e_9.error; }
2427
+ finally { if (e_10) throw e_10.error; }
2358
2428
  }
2359
2429
  this._isDirty = true;
2360
2430
  };
@@ -2628,7 +2698,7 @@ var AcTrView2d = /** @class */ (function (_super) {
2628
2698
  * drawable entity that must be rebuilt (for example ATTRIB → INSERT).
2629
2699
  */
2630
2700
  AcTrView2d.prototype.resolveSceneUpdateEntities = function (entities) {
2631
- var e_10, _a;
2701
+ var e_11, _a;
2632
2702
  var _b;
2633
2703
  var db = (_b = AcApDocManager.instance.curDocument) === null || _b === void 0 ? void 0 : _b.database;
2634
2704
  var resolved = [];
@@ -2650,12 +2720,12 @@ var AcTrView2d = /** @class */ (function (_super) {
2650
2720
  resolved.push(target);
2651
2721
  }
2652
2722
  }
2653
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
2723
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
2654
2724
  finally {
2655
2725
  try {
2656
2726
  if (entities_1_1 && !entities_1_1.done && (_a = entities_1.return)) _a.call(entities_1);
2657
2727
  }
2658
- finally { if (e_10) throw e_10.error; }
2728
+ finally { if (e_11) throw e_11.error; }
2659
2729
  }
2660
2730
  return resolved;
2661
2731
  };
@@ -2788,9 +2858,13 @@ var AcTrView2d = /** @class */ (function (_super) {
2788
2858
  waiter.start();
2789
2859
  };
2790
2860
  /**
2791
- * @inheritdoc
2861
+ * Invalidates in-flight progressive convert and empties convert / deferred
2862
+ * queues without tearing down the renderer or DOM.
2863
+ *
2864
+ * Call before {@link AcApDocManager.destroy} tears down documents so
2865
+ * in-flight commits do not keep reading the manager singleton.
2792
2866
  */
2793
- AcTrView2d.prototype.clear = function () {
2867
+ AcTrView2d.prototype.abortConversion = function () {
2794
2868
  // Invalidate any in-flight progressive convert so it neither paints into
2795
2869
  // the cleared scene nor double-decrements the processing counter.
2796
2870
  this._convertEpoch++;
@@ -2803,6 +2877,12 @@ var AcTrView2d = /** @class */ (function (_super) {
2803
2877
  this.cancelOpenLineworkFrame();
2804
2878
  this.resetDeferredGeometryQueue();
2805
2879
  this._entityProcessingIdleAt = 0;
2880
+ };
2881
+ /**
2882
+ * @inheritdoc
2883
+ */
2884
+ AcTrView2d.prototype.clear = function () {
2885
+ this.abortConversion();
2806
2886
  this._scene.clear();
2807
2887
  this._renderer.resetDrawOrderZ();
2808
2888
  this._isDirty = true;
@@ -2919,12 +2999,44 @@ var AcTrView2d = /** @class */ (function (_super) {
2919
2999
  /**
2920
3000
  * True when this view is the document manager's live canvas.
2921
3001
  * Satellite/preview views must ignore global shortcuts and layout switches.
3002
+ * Returns false when no manager exists so post-destroy key handlers do not
3003
+ * reach {@link AcApDocManager.instance}.
2922
3004
  */
2923
3005
  AcTrView2d.prototype.isActiveManagedView = function () {
2924
3006
  var _a;
2925
3007
  var singleton = AcApDocManager;
2926
3008
  var current = (_a = singleton._instance) === null || _a === void 0 ? void 0 : _a.curView;
2927
- return current == null || current === this;
3009
+ return current != null && current === this;
3010
+ };
3011
+ /**
3012
+ * Moves keyboard focus into the viewer container after canvas interaction so
3013
+ * document-level shortcuts stay scoped to this view.
3014
+ *
3015
+ * Skips host editable fields so wheel-over-canvas does not interrupt typing.
3016
+ */
3017
+ AcTrView2d.prototype.focusViewerForShortcuts = function () {
3018
+ var active = document.activeElement;
3019
+ if (active instanceof Node && this.container.contains(active)) {
3020
+ return;
3021
+ }
3022
+ if (active instanceof HTMLElement &&
3023
+ (active.tagName === 'INPUT' ||
3024
+ active.tagName === 'TEXTAREA' ||
3025
+ active.isContentEditable)) {
3026
+ return;
3027
+ }
3028
+ this.container.focus({ preventScroll: true });
3029
+ };
3030
+ /**
3031
+ * True when the key event originated from (or is focused within) this view.
3032
+ */
3033
+ AcTrView2d.prototype.isShortcutEventInsideViewer = function (e) {
3034
+ var target = e.target;
3035
+ if (target instanceof Node && this.container.contains(target)) {
3036
+ return true;
3037
+ }
3038
+ var active = document.activeElement;
3039
+ return active instanceof Node && this.container.contains(active);
2928
3040
  };
2929
3041
  /**
2930
3042
  * Drains the convert queue on a single serial worker so ENTITY flush chunks
@@ -3223,20 +3335,63 @@ var AcTrView2d = /** @class */ (function (_super) {
3223
3335
  }
3224
3336
  };
3225
3337
  /**
3226
- * Releases canvas DOM listeners and stops the animation loop.
3338
+ * Releases canvas DOM, WebGL context, convert work, and listeners.
3227
3339
  *
3228
3340
  * Call when this view will no longer be used (manager destroy / split
3229
3341
  * view teardown). Safe to call more than once.
3230
3342
  */
3231
3343
  AcTrView2d.prototype.dispose = function () {
3232
- var _a, _b;
3344
+ var _a, _b, _c;
3345
+ if (this._viewDisposed)
3346
+ return;
3347
+ this._viewDisposed = true;
3348
+ // Stop convert before tearing down documents/singletons that commit paths read.
3349
+ this.abortConversion();
3233
3350
  (_a = this._disposeCanvasTouchCallout) === null || _a === void 0 ? void 0 : _a.call(this);
3234
3351
  this._disposeCanvasTouchCallout = undefined;
3235
3352
  (_b = this._disposeProgressiveInputWatch) === null || _b === void 0 ? void 0 : _b.call(this);
3236
3353
  this._disposeProgressiveInputWatch = undefined;
3354
+ (_c = this._disposeMobileBoxGesture) === null || _c === void 0 ? void 0 : _c.call(this);
3355
+ this._disposeMobileBoxGesture = undefined;
3356
+ this._viewDomAbort.abort();
3357
+ if (this._onFontNotFound) {
3358
+ this._renderer.events.fontNotFound.removeEventListener(this._onFontNotFound);
3359
+ }
3360
+ if (this._onFontLoaded) {
3361
+ this._renderer.events.fontLoaded.removeEventListener(this._onFontLoaded);
3362
+ }
3363
+ if (this._onSysVarChanged) {
3364
+ AcDbSysVarManager.instance().events.sysVarChanged.removeEventListener(this._onSysVarChanged);
3365
+ }
3366
+ if (this._onSettingsModified) {
3367
+ AcApSettingManager.instance.events.modified.removeEventListener(this._onSettingsModified);
3368
+ }
3369
+ if (this._onLayoutSwitched) {
3370
+ acdbHostApplicationServices().layoutManager.events.layoutSwitched.removeEventListener(this._onLayoutSwitched);
3371
+ }
3372
+ if (this._onCommandWillStartHitTest) {
3373
+ this.editor.events.commandWillStart.removeEventListener(this._onCommandWillStartHitTest);
3374
+ }
3375
+ if (this._onCommandEndedHitTest) {
3376
+ this.editor.events.commandEnded.removeEventListener(this._onCommandEndedHitTest);
3377
+ }
3378
+ this._gripManager.dispose();
3237
3379
  this.clearFontLoadedRedrawTimer();
3238
3380
  this.cancelOpenLineworkFrame();
3239
3381
  this.stopAnimationLoop();
3382
+ this.selectionSet.clear();
3383
+ this.htmlTransientManager.dispose();
3384
+ this._scene.clear();
3385
+ this._renderer.dispose();
3386
+ AcDbRenderingCache.instance.clear();
3387
+ var webgl = this._renderer.internalRenderer;
3388
+ webgl.dispose();
3389
+ webgl.forceContextLoss();
3390
+ this.canvas.remove();
3391
+ this._css2dRenderer.domElement.remove();
3392
+ this._stats.dom.remove();
3393
+ // Editor / command line / ResizeObserver (after canvas/CSS2D removed).
3394
+ _super.prototype.dispose.call(this);
3240
3395
  };
3241
3396
  /**
3242
3397
  * @inheritdoc
@@ -3338,7 +3493,7 @@ var AcTrView2d = /** @class */ (function (_super) {
3338
3493
  * @param layoutBtrId Input the block table record id of the layout
3339
3494
  */
3340
3495
  AcTrView2d.prototype.loadLayoutEntitiesIfNeeded = function (layoutBtrId) {
3341
- var e_11, _a;
3496
+ var e_12, _a;
3342
3497
  var _this = this;
3343
3498
  try {
3344
3499
  var db = AcApDocManager.instance.curDocument.database;
@@ -3402,12 +3557,12 @@ var AcTrView2d = /** @class */ (function (_super) {
3402
3557
  entities_2.push(entity);
3403
3558
  }
3404
3559
  }
3405
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
3560
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
3406
3561
  finally {
3407
3562
  try {
3408
3563
  if (iterator_1_1 && !iterator_1_1.done && (_a = iterator_1.return)) _a.call(iterator_1);
3409
3564
  }
3410
- finally { if (e_11) throw e_11.error; }
3565
+ finally { if (e_12) throw e_12.error; }
3411
3566
  }
3412
3567
  if (entities_2.length === 0) {
3413
3568
  // Empty layout (e.g. a freshly-created paper space tab). Mark as
@@ -3731,8 +3886,8 @@ var AcTrView2d = /** @class */ (function (_super) {
3731
3886
  */
3732
3887
  AcTrView2d.prototype.redrawGlyphEntitiesAfterFontLoad = function (epoch, fontName) {
3733
3888
  return __awaiter(this, void 0, void 0, function () {
3734
- var redrawEpoch, glyphs, _a, _b, layout, glyphs_1, glyphs_1_1, glyph, e_12_1, defaults, normalized_1, msSinceIdle, db;
3735
- var e_13, _c, e_12, _d;
3889
+ var redrawEpoch, glyphs, _a, _b, layout, glyphs_1, glyphs_1_1, glyph, e_13_1, defaults, normalized_1, msSinceIdle, db;
3890
+ var e_14, _c, e_13, _d;
3736
3891
  var _e, _f;
3737
3892
  return __generator(this, function (_g) {
3738
3893
  switch (_g.label) {
@@ -3754,12 +3909,12 @@ var AcTrView2d = /** @class */ (function (_super) {
3754
3909
  });
3755
3910
  }
3756
3911
  }
3757
- catch (e_13_1) { e_13 = { error: e_13_1 }; }
3912
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
3758
3913
  finally {
3759
3914
  try {
3760
3915
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
3761
3916
  }
3762
- finally { if (e_13) throw e_13.error; }
3917
+ finally { if (e_14) throw e_14.error; }
3763
3918
  }
3764
3919
  _g.label = 1;
3765
3920
  case 1:
@@ -3782,14 +3937,14 @@ var AcTrView2d = /** @class */ (function (_super) {
3782
3937
  return [3 /*break*/, 2];
3783
3938
  case 5: return [3 /*break*/, 8];
3784
3939
  case 6:
3785
- e_12_1 = _g.sent();
3786
- e_12 = { error: e_12_1 };
3940
+ e_13_1 = _g.sent();
3941
+ e_13 = { error: e_13_1 };
3787
3942
  return [3 /*break*/, 8];
3788
3943
  case 7:
3789
3944
  try {
3790
3945
  if (glyphs_1_1 && !glyphs_1_1.done && (_d = glyphs_1.return)) _d.call(glyphs_1);
3791
3946
  }
3792
- finally { if (e_12) throw e_12.error; }
3947
+ finally { if (e_13) throw e_13.error; }
3793
3948
  return [7 /*endfinally*/];
3794
3949
  case 8:
3795
3950
  if (glyphs.length > 0) {
@@ -3840,7 +3995,7 @@ var AcTrView2d = /** @class */ (function (_super) {
3840
3995
  });
3841
3996
  };
3842
3997
  AcTrView2d.prototype.groupHasPendingGlyphGeometry = function (group) {
3843
- var e_14, _a;
3998
+ var e_15, _a;
3844
3999
  try {
3845
4000
  // Prefer O(block-def shells). A full THREE.traverse over a mega-block
3846
4001
  // (100k+ flattened mesh leaves) was dominating scene-convert wall time.
@@ -3851,12 +4006,12 @@ var AcTrView2d = /** @class */ (function (_super) {
3851
4006
  }
3852
4007
  }
3853
4008
  }
3854
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
4009
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
3855
4010
  finally {
3856
4011
  try {
3857
4012
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3858
4013
  }
3859
- finally { if (e_14) throw e_14.error; }
4014
+ finally { if (e_15) throw e_15.error; }
3860
4015
  }
3861
4016
  return AcTrView2d.directChildrenHavePendingGlyphs(group);
3862
4017
  };
@@ -3867,7 +4022,7 @@ var AcTrView2d = /** @class */ (function (_super) {
3867
4022
  * a whole-floor INSERT is O(glyph shells), not O(all drawable leaves).
3868
4023
  */
3869
4024
  AcTrView2d.directChildrenHavePendingGlyphs = function (root) {
3870
- var e_15, _a;
4025
+ var e_16, _a;
3871
4026
  var children = root.children;
3872
4027
  for (var i = 0; i < children.length; i++) {
3873
4028
  var child = children[i];
@@ -3879,7 +4034,7 @@ var AcTrView2d = /** @class */ (function (_super) {
3879
4034
  }
3880
4035
  if (child instanceof AcTrGroup) {
3881
4036
  try {
3882
- for (var _b = (e_15 = void 0, __values(child.getSourceEntities())), _c = _b.next(); !_c.done; _c = _b.next()) {
4037
+ for (var _b = (e_16 = void 0, __values(child.getSourceEntities())), _c = _b.next(); !_c.done; _c = _b.next()) {
3883
4038
  var entity = _c.value;
3884
4039
  if (entity instanceof AcTrGlyphEntity &&
3885
4040
  !entity.hasDrawableGeometry()) {
@@ -3887,12 +4042,12 @@ var AcTrView2d = /** @class */ (function (_super) {
3887
4042
  }
3888
4043
  }
3889
4044
  }
3890
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
4045
+ catch (e_16_1) { e_16 = { error: e_16_1 }; }
3891
4046
  finally {
3892
4047
  try {
3893
4048
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3894
4049
  }
3895
- finally { if (e_15) throw e_15.error; }
4050
+ finally { if (e_16) throw e_16.error; }
3896
4051
  }
3897
4052
  if (AcTrView2d.directChildrenHavePendingGlyphs(child)) {
3898
4053
  return true;
@@ -4050,7 +4205,7 @@ var AcTrView2d = /** @class */ (function (_super) {
4050
4205
  * paper layouts.
4051
4206
  */
4052
4207
  AcTrView2d.prototype.ensureViewportViews = function (blockTableRecord, layoutView) {
4053
- var e_16, _a;
4208
+ var e_17, _a;
4054
4209
  var iterator = blockTableRecord.newIterator();
4055
4210
  try {
4056
4211
  for (var iterator_2 = __values(iterator), iterator_2_1 = iterator_2.next(); !iterator_2_1.done; iterator_2_1 = iterator_2.next()) {
@@ -4063,12 +4218,12 @@ var AcTrView2d = /** @class */ (function (_super) {
4063
4218
  layoutView.addViewport(viewportView);
4064
4219
  }
4065
4220
  }
4066
- catch (e_16_1) { e_16 = { error: e_16_1 }; }
4221
+ catch (e_17_1) { e_17 = { error: e_17_1 }; }
4067
4222
  finally {
4068
4223
  try {
4069
4224
  if (iterator_2_1 && !iterator_2_1.done && (_a = iterator_2.return)) _a.call(iterator_2);
4070
4225
  }
4071
- finally { if (e_16) throw e_16.error; }
4226
+ finally { if (e_17) throw e_17.error; }
4072
4227
  }
4073
4228
  };
4074
4229
  /**
@@ -4077,7 +4232,7 @@ var AcTrView2d = /** @class */ (function (_super) {
4077
4232
  * {@link AcDbViewport.frozenLayerIds} but omit them from `toGiViewport()`.
4078
4233
  */
4079
4234
  AcTrView2d.prototype.toGiViewportWithFrozenLayers = function (entity) {
4080
- var e_17, _a;
4235
+ var e_18, _a;
4081
4236
  var _b;
4082
4237
  var gi = entity.toGiViewport();
4083
4238
  if (gi.frozenLayers && gi.frozenLayers.length > 0) {
@@ -4097,12 +4252,12 @@ var AcTrView2d = /** @class */ (function (_super) {
4097
4252
  names.push(layer.name);
4098
4253
  }
4099
4254
  }
4100
- catch (e_17_1) { e_17 = { error: e_17_1 }; }
4255
+ catch (e_18_1) { e_18 = { error: e_18_1 }; }
4101
4256
  finally {
4102
4257
  try {
4103
4258
  if (ids_1_1 && !ids_1_1.done && (_a = ids_1.return)) _a.call(ids_1);
4104
4259
  }
4105
- finally { if (e_17) throw e_17.error; }
4260
+ finally { if (e_18) throw e_18.error; }
4106
4261
  }
4107
4262
  }
4108
4263
  gi.frozenLayerIds = __spreadArray([], __read(ids), false);
@@ -4422,8 +4577,8 @@ var AcTrView2d = /** @class */ (function (_super) {
4422
4577
  };
4423
4578
  AcTrView2d.prototype.handleGroup = function (group_1, progressive_1) {
4424
4579
  return __awaiter(this, arguments, void 0, function (group, progressive, epoch, convertGen) {
4425
- var t0, objectId, children, objectsGroupByLayer_2, children_1, children_1_1, child, renderContext, groupObjectId, groupLayerName, lazyChildren, groupChildBoxes, aggregateSpatialBbox, registeredChildIndex, yieldToEventLoop, lastGroupYieldAt, _loop_5, this_4, objectsGroupByLayer_1, objectsGroupByLayer_1_1, _a, layerName, objects, e_18_1;
4426
- var e_19, _b, e_18, _c;
4580
+ var t0, objectId, children, objectsGroupByLayer_2, children_1, children_1_1, child, renderContext, groupObjectId, groupLayerName, lazyChildren, groupChildBoxes, aggregateSpatialBbox, registeredChildIndex, yieldToEventLoop, lastGroupYieldAt, _loop_5, this_4, objectsGroupByLayer_1, objectsGroupByLayer_1_1, _a, layerName, objects, e_19_1;
4581
+ var e_20, _b, e_19, _c;
4427
4582
  var _this = this;
4428
4583
  var _d, _e;
4429
4584
  if (epoch === void 0) { epoch = this._convertEpoch; }
@@ -4478,12 +4633,12 @@ var AcTrView2d = /** @class */ (function (_super) {
4478
4633
  child.parent = null;
4479
4634
  }
4480
4635
  }
4481
- catch (e_19_1) { e_19 = { error: e_19_1 }; }
4636
+ catch (e_20_1) { e_20 = { error: e_20_1 }; }
4482
4637
  finally {
4483
4638
  try {
4484
4639
  if (children_1_1 && !children_1_1.done && (_b = children_1.return)) _b.call(children_1);
4485
4640
  }
4486
- finally { if (e_19) throw e_19.error; }
4641
+ finally { if (e_20) throw e_20.error; }
4487
4642
  }
4488
4643
  renderContext = group.renderContext;
4489
4644
  groupObjectId = group.objectId;
@@ -4598,14 +4753,14 @@ var AcTrView2d = /** @class */ (function (_super) {
4598
4753
  return [3 /*break*/, 4];
4599
4754
  case 7: return [3 /*break*/, 10];
4600
4755
  case 8:
4601
- e_18_1 = _f.sent();
4602
- e_18 = { error: e_18_1 };
4756
+ e_19_1 = _f.sent();
4757
+ e_19 = { error: e_19_1 };
4603
4758
  return [3 /*break*/, 10];
4604
4759
  case 9:
4605
4760
  try {
4606
4761
  if (objectsGroupByLayer_1_1 && !objectsGroupByLayer_1_1.done && (_c = objectsGroupByLayer_1.return)) _c.call(objectsGroupByLayer_1);
4607
4762
  }
4608
- finally { if (e_18) throw e_18.error; }
4763
+ finally { if (e_19) throw e_19.error; }
4609
4764
  return [7 /*endfinally*/];
4610
4765
  case 10:
4611
4766
  group.dispose();