@mlightcad/cad-simple-viewer 1.7.2 → 1.7.4

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 (183) hide show
  1. package/dist/cad-simple-viewer.js +8285 -7371
  2. package/dist/cad-simple-viewer.umd.cjs +82 -82
  3. package/dist/mtext-renderer-worker.js +2434 -2363
  4. package/lib/app/AcApDocManager.d.ts +14 -0
  5. package/lib/app/AcApDocManager.d.ts.map +1 -1
  6. package/lib/app/AcApDocManager.js +46 -9
  7. package/lib/app/AcApDocManager.js.map +1 -1
  8. package/lib/app/AcApOpenDatabaseOptions.d.ts +7 -8
  9. package/lib/app/AcApOpenDatabaseOptions.d.ts.map +1 -1
  10. package/lib/command/AcApZoomCmd.d.ts +29 -0
  11. package/lib/command/AcApZoomCmd.d.ts.map +1 -1
  12. package/lib/command/AcApZoomCmd.js +83 -3
  13. package/lib/command/AcApZoomCmd.js.map +1 -1
  14. package/lib/command/convert/AcApConvertToRasterImageCmd.d.ts +4 -2
  15. package/lib/command/convert/AcApConvertToRasterImageCmd.d.ts.map +1 -1
  16. package/lib/command/convert/AcApConvertToRasterImageCmd.js +33 -17
  17. package/lib/command/convert/AcApConvertToRasterImageCmd.js.map +1 -1
  18. package/lib/command/markup/AcApMarkupCalloutCmd.d.ts.map +1 -1
  19. package/lib/command/markup/AcApMarkupCalloutCmd.js +8 -4
  20. package/lib/command/markup/AcApMarkupCalloutCmd.js.map +1 -1
  21. package/lib/command/markup/AcApMarkupShapeCallout.d.ts.map +1 -1
  22. package/lib/command/markup/AcApMarkupShapeCallout.js +8 -4
  23. package/lib/command/markup/AcApMarkupShapeCallout.js.map +1 -1
  24. package/lib/command/markup/AcApMarkupUtil.d.ts.map +1 -1
  25. package/lib/command/markup/AcApMarkupUtil.js +6 -4
  26. package/lib/command/markup/AcApMarkupUtil.js.map +1 -1
  27. package/lib/command/measure/AcApMeasureAngleArc.d.ts +9 -2
  28. package/lib/command/measure/AcApMeasureAngleArc.d.ts.map +1 -1
  29. package/lib/command/measure/AcApMeasureAngleArc.js +9 -2
  30. package/lib/command/measure/AcApMeasureAngleArc.js.map +1 -1
  31. package/lib/command/measure/AcApMeasureAngleCmd.d.ts.map +1 -1
  32. package/lib/command/measure/AcApMeasureAngleCmd.js +17 -4
  33. package/lib/command/measure/AcApMeasureAngleCmd.js.map +1 -1
  34. package/lib/command/measure/AcApMeasureArcCmd.d.ts.map +1 -1
  35. package/lib/command/measure/AcApMeasureArcCmd.js +12 -8
  36. package/lib/command/measure/AcApMeasureArcCmd.js.map +1 -1
  37. package/lib/command/measure/AcApMeasureAreaCmd.d.ts.map +1 -1
  38. package/lib/command/measure/AcApMeasureAreaCmd.js +17 -4
  39. package/lib/command/measure/AcApMeasureAreaCmd.js.map +1 -1
  40. package/lib/command/measure/AcApMeasureContinuousCmd.d.ts.map +1 -1
  41. package/lib/command/measure/AcApMeasureContinuousCmd.js +36 -6
  42. package/lib/command/measure/AcApMeasureContinuousCmd.js.map +1 -1
  43. package/lib/command/measure/AcApMeasureDistanceCmd.d.ts.map +1 -1
  44. package/lib/command/measure/AcApMeasureDistanceCmd.js +28 -8
  45. package/lib/command/measure/AcApMeasureDistanceCmd.js.map +1 -1
  46. package/lib/command/measure/AcApMeasurementStore.d.ts.map +1 -1
  47. package/lib/command/measure/AcApMeasurementStore.js +44 -28
  48. package/lib/command/measure/AcApMeasurementStore.js.map +1 -1
  49. package/lib/command/measure/entity/AcApMeasureAngleEntity.d.ts.map +1 -1
  50. package/lib/command/measure/entity/AcApMeasureAngleEntity.js +43 -7
  51. package/lib/command/measure/entity/AcApMeasureAngleEntity.js.map +1 -1
  52. package/lib/command/measure/entity/AcApMeasureArcEntity.d.ts.map +1 -1
  53. package/lib/command/measure/entity/AcApMeasureArcEntity.js +46 -8
  54. package/lib/command/measure/entity/AcApMeasureArcEntity.js.map +1 -1
  55. package/lib/command/measure/entity/AcApMeasureAreaEntity.d.ts.map +1 -1
  56. package/lib/command/measure/entity/AcApMeasureAreaEntity.js +43 -7
  57. package/lib/command/measure/entity/AcApMeasureAreaEntity.js.map +1 -1
  58. package/lib/command/measure/entity/AcApMeasureDistanceEntity.d.ts.map +1 -1
  59. package/lib/command/measure/entity/AcApMeasureDistanceEntity.js +56 -8
  60. package/lib/command/measure/entity/AcApMeasureDistanceEntity.js.map +1 -1
  61. package/lib/command/measure/entity/AcApMeasureEntity.d.ts +8 -0
  62. package/lib/command/measure/entity/AcApMeasureEntity.d.ts.map +1 -1
  63. package/lib/command/measure/entity/AcApMeasureEntity.js +16 -1
  64. package/lib/command/measure/entity/AcApMeasureEntity.js.map +1 -1
  65. package/lib/command/measure/entity/AcApMeasureEntityGrips.d.ts.map +1 -1
  66. package/lib/command/measure/entity/AcApMeasureEntityGrips.js +2 -1
  67. package/lib/command/measure/entity/AcApMeasureEntityGrips.js.map +1 -1
  68. package/lib/command/overlay/AcApHtmlLivePreview.d.ts +6 -0
  69. package/lib/command/overlay/AcApHtmlLivePreview.d.ts.map +1 -1
  70. package/lib/command/overlay/AcApHtmlLivePreview.js +9 -2
  71. package/lib/command/overlay/AcApHtmlLivePreview.js.map +1 -1
  72. package/lib/command/overlay/AcApOverlayDrawUtil.d.ts +5 -0
  73. package/lib/command/overlay/AcApOverlayDrawUtil.d.ts.map +1 -1
  74. package/lib/command/overlay/AcApOverlayDrawUtil.js +54 -23
  75. package/lib/command/overlay/AcApOverlayDrawUtil.js.map +1 -1
  76. package/lib/editor/global/AcEdConditionWaiter.d.ts +3 -0
  77. package/lib/editor/global/AcEdConditionWaiter.d.ts.map +1 -1
  78. package/lib/editor/global/AcEdConditionWaiter.js +9 -2
  79. package/lib/editor/global/AcEdConditionWaiter.js.map +1 -1
  80. package/lib/editor/view/AcEdBaseView.d.ts +22 -0
  81. package/lib/editor/view/AcEdBaseView.d.ts.map +1 -1
  82. package/lib/editor/view/AcEdBaseView.js.map +1 -1
  83. package/lib/i18n/ar/jig.d.ts +10 -0
  84. package/lib/i18n/ar/jig.d.ts.map +1 -1
  85. package/lib/i18n/ar/jig.js +10 -2
  86. package/lib/i18n/ar/jig.js.map +1 -1
  87. package/lib/i18n/ar/main.d.ts +2 -0
  88. package/lib/i18n/ar/main.d.ts.map +1 -1
  89. package/lib/i18n/ar/main.js +2 -0
  90. package/lib/i18n/ar/main.js.map +1 -1
  91. package/lib/i18n/cs/jig.d.ts +10 -0
  92. package/lib/i18n/cs/jig.d.ts.map +1 -1
  93. package/lib/i18n/cs/jig.js +13 -3
  94. package/lib/i18n/cs/jig.js.map +1 -1
  95. package/lib/i18n/cs/main.d.ts +2 -0
  96. package/lib/i18n/cs/main.d.ts.map +1 -1
  97. package/lib/i18n/cs/main.js +2 -0
  98. package/lib/i18n/cs/main.js.map +1 -1
  99. package/lib/i18n/en/jig.d.ts +10 -0
  100. package/lib/i18n/en/jig.d.ts.map +1 -1
  101. package/lib/i18n/en/jig.js +13 -3
  102. package/lib/i18n/en/jig.js.map +1 -1
  103. package/lib/i18n/en/main.d.ts +2 -0
  104. package/lib/i18n/en/main.d.ts.map +1 -1
  105. package/lib/i18n/en/main.js +2 -0
  106. package/lib/i18n/en/main.js.map +1 -1
  107. package/lib/i18n/tr/jig.d.ts +10 -0
  108. package/lib/i18n/tr/jig.d.ts.map +1 -1
  109. package/lib/i18n/tr/jig.js +13 -3
  110. package/lib/i18n/tr/jig.js.map +1 -1
  111. package/lib/i18n/tr/main.d.ts +2 -0
  112. package/lib/i18n/tr/main.d.ts.map +1 -1
  113. package/lib/i18n/tr/main.js +2 -0
  114. package/lib/i18n/tr/main.js.map +1 -1
  115. package/lib/i18n/zh/jig.d.ts +10 -0
  116. package/lib/i18n/zh/jig.d.ts.map +1 -1
  117. package/lib/i18n/zh/jig.js +13 -3
  118. package/lib/i18n/zh/jig.js.map +1 -1
  119. package/lib/i18n/zh/main.d.ts +2 -0
  120. package/lib/i18n/zh/main.d.ts.map +1 -1
  121. package/lib/i18n/zh/main.js +2 -0
  122. package/lib/i18n/zh/main.js.map +1 -1
  123. package/lib/spatialIndex/AcTrHierarchicalSpatialIndex.d.ts +11 -0
  124. package/lib/spatialIndex/AcTrHierarchicalSpatialIndex.d.ts.map +1 -1
  125. package/lib/spatialIndex/AcTrHierarchicalSpatialIndex.js +98 -3
  126. package/lib/spatialIndex/AcTrHierarchicalSpatialIndex.js.map +1 -1
  127. package/lib/ui/icons.d.ts +2 -0
  128. package/lib/ui/icons.d.ts.map +1 -1
  129. package/lib/ui/icons.js +2 -0
  130. package/lib/ui/icons.js.map +1 -1
  131. package/lib/util/AcApDrawingExtents.d.ts +29 -0
  132. package/lib/util/AcApDrawingExtents.d.ts.map +1 -0
  133. package/lib/util/AcApDrawingExtents.js +34 -0
  134. package/lib/util/AcApDrawingExtents.js.map +1 -0
  135. package/lib/util/AcApFontUtil.d.ts +18 -0
  136. package/lib/util/AcApFontUtil.d.ts.map +1 -1
  137. package/lib/util/AcApFontUtil.js +126 -0
  138. package/lib/util/AcApFontUtil.js.map +1 -1
  139. package/lib/util/AcApMeasureBadgeFont.d.ts +99 -0
  140. package/lib/util/AcApMeasureBadgeFont.d.ts.map +1 -0
  141. package/lib/util/AcApMeasureBadgeFont.js +207 -0
  142. package/lib/util/AcApMeasureBadgeFont.js.map +1 -0
  143. package/lib/util/AcApMeasurementUnits.d.ts.map +1 -1
  144. package/lib/util/AcApMeasurementUnits.js +41 -2
  145. package/lib/util/AcApMeasurementUnits.js.map +1 -1
  146. package/lib/util/index.d.ts +2 -0
  147. package/lib/util/index.d.ts.map +1 -1
  148. package/lib/util/index.js +2 -0
  149. package/lib/util/index.js.map +1 -1
  150. package/lib/view/AcTrExtentCluster.d.ts +40 -0
  151. package/lib/view/AcTrExtentCluster.d.ts.map +1 -0
  152. package/lib/view/AcTrExtentCluster.js +209 -0
  153. package/lib/view/AcTrExtentCluster.js.map +1 -0
  154. package/lib/view/AcTrIntelligentExtents.d.ts +30 -0
  155. package/lib/view/AcTrIntelligentExtents.d.ts.map +1 -0
  156. package/lib/view/AcTrIntelligentExtents.js +328 -0
  157. package/lib/view/AcTrIntelligentExtents.js.map +1 -0
  158. package/lib/view/AcTrLayer.d.ts +4 -0
  159. package/lib/view/AcTrLayer.d.ts.map +1 -1
  160. package/lib/view/AcTrLayer.js +6 -0
  161. package/lib/view/AcTrLayer.js.map +1 -1
  162. package/lib/view/AcTrLayout.d.ts +46 -1
  163. package/lib/view/AcTrLayout.d.ts.map +1 -1
  164. package/lib/view/AcTrLayout.js +132 -0
  165. package/lib/view/AcTrLayout.js.map +1 -1
  166. package/lib/view/AcTrScene.d.ts +4 -0
  167. package/lib/view/AcTrScene.d.ts.map +1 -1
  168. package/lib/view/AcTrScene.js +6 -0
  169. package/lib/view/AcTrScene.js.map +1 -1
  170. package/lib/view/AcTrView2d.d.ts +18 -4
  171. package/lib/view/AcTrView2d.d.ts.map +1 -1
  172. package/lib/view/AcTrView2d.js +202 -43
  173. package/lib/view/AcTrView2d.js.map +1 -1
  174. package/lib/view/AcTrWorkSlice.d.ts +23 -0
  175. package/lib/view/AcTrWorkSlice.d.ts.map +1 -0
  176. package/lib/view/AcTrWorkSlice.js +92 -0
  177. package/lib/view/AcTrWorkSlice.js.map +1 -0
  178. package/lib/view/index.d.ts +2 -0
  179. package/lib/view/index.d.ts.map +1 -1
  180. package/lib/view/index.js +2 -0
  181. package/lib/view/index.js.map +1 -1
  182. package/package.json +10 -10
  183. package/src/ui/icons.ts +5 -0
@@ -99,7 +99,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
99
99
  import { AcCmUiYieldGate, AcDbAttribute, AcDbBlockReference, acdbHostApplicationServices, AcDbMText, AcDbRasterImage, AcDbRay, AcDbSysVarManager, AcDbViewport, AcDbXline, AcGeBox2d, AcGePoint2d, acgiForegroundColorForBackground, log } from '@mlightcad/data-model';
100
100
  import { AcDbSystemVariables } from '@mlightcad/data-model';
101
101
  import { FontManager } from '@mlightcad/mtext-renderer';
102
- import { AcTrEntity, AcTrGlyphEntity, AcTrGroup, AcTrRenderer, AcTrViewportView, hasPendingComplexLineTypeGlyphs } from '@mlightcad/three-renderer';
102
+ import { AcTrEntity, AcTrGlyphEntity, AcTrGroup, AcTrMTextRenderer, AcTrRenderer, AcTrViewportView, hasPendingComplexLineTypeGlyphs, setAcTrDrawOrderZAllocator } from '@mlightcad/three-renderer';
103
103
  import { AcTrMatrixUtil } from '@mlightcad/three-renderer';
104
104
  import * as THREE from 'three';
105
105
  import Stats from 'three/examples/jsm/libs/stats.module';
@@ -122,6 +122,7 @@ import { shouldExtendBboxForDirectEntity, tryBuildDirectEntityMeta } from './AcT
122
122
  import { AcTrEntityDisplayController } from './AcTrEntityDisplayController';
123
123
  import { assertAcTrGroupWcsBboxesConsistent, unionGroupWcsChildBoxes } from './AcTrGroupWcsBboxAssert';
124
124
  import { AcTrInheritedLayerMaterialMapper } from './AcTrInheritedLayerMaterialMapper';
125
+ import { computeIntelligentExtentsAsync } from './AcTrIntelligentExtents';
125
126
  import { AcTrLayer } from './AcTrLayer';
126
127
  import { AcTrLayerAppearanceController } from './AcTrLayerAppearanceController';
127
128
  import { AcTrLayout } from './AcTrLayout';
@@ -130,6 +131,7 @@ import { AcTrLayoutViewManager } from './AcTrLayoutViewManager';
130
131
  import { sortPickResults } from './AcTrPickResultUtil';
131
132
  import { AcTrProgressiveOpenFitController } from './AcTrProgressiveOpenFitController';
132
133
  import { AcTrScene } from './AcTrScene';
134
+ import { AcTrWorkSlice } from './AcTrWorkSlice';
133
135
  import { shouldRegenDatabaseAfterFontLoad } from './fontLoadRegen';
134
136
  /**
135
137
  * Default view option values
@@ -384,6 +386,9 @@ var AcTrView2d = /** @class */ (function (_super) {
384
386
  renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
385
387
  renderer.setSize(_this.width, _this.height);
386
388
  _this._renderer = new AcTrRenderer(renderer);
389
+ // Shared across all layer batched groups so later entities (e.g. wipeouts)
390
+ // occlude earlier linework via depth, matching AutoCAD draw order.
391
+ setAcTrDrawOrderZAllocator(function () { return _this._renderer.allocateDrawOrderZ(); });
387
392
  var fontMapping = AcApSettingManager.instance.fontMapping;
388
393
  _this._renderer.setFontMapping(fontMapping);
389
394
  _this._renderer.events.fontNotFound.addEventListener(function (args) {
@@ -1041,6 +1046,9 @@ var AcTrView2d = /** @class */ (function (_super) {
1041
1046
  // Style-manager changeForeground only updates cache entries; batch
1042
1047
  // containers own private material clones and must be repainted too.
1043
1048
  this._scene.repaintForegroundMaterials(acgiForegroundColorForBackground(value));
1049
+ // Wipeouts track the canvas background (isBackgroundFill); repaint their
1050
+ // batch-owned clones the same way as ACI-7 foreground materials.
1051
+ this._scene.repaintBackgroundMaterials(value);
1044
1052
  this.resyncForegroundLayersForBackground();
1045
1053
  if (this._readingMode.isEnabled) {
1046
1054
  this._readingMode.noteLayoutBackground(value);
@@ -1560,7 +1568,7 @@ var AcTrView2d = /** @class */ (function (_super) {
1560
1568
  _this.endProgressiveOpenFit();
1561
1569
  return;
1562
1570
  }
1563
- _this._progressiveOpenFit.applyFinalFit(function () { return _this.resolveLayoutFitBox(); });
1571
+ _this._progressiveOpenFit.applyFinalFit(function () { return _this.getDrawingExtents(); });
1564
1572
  _this.endProgressiveOpenFit();
1565
1573
  var originalBtrId = layoutBtrId !== null && layoutBtrId !== void 0 ? layoutBtrId : _this.activeLayoutBtrId;
1566
1574
  if (originalBtrId) {
@@ -1586,6 +1594,94 @@ var AcTrView2d = /** @class */ (function (_super) {
1586
1594
  }
1587
1595
  return false;
1588
1596
  };
1597
+ /**
1598
+ * @inheritdoc
1599
+ */
1600
+ AcTrView2d.prototype.zoomToSmartExtents = function (timeout) {
1601
+ var _this = this;
1602
+ if (timeout === void 0) { timeout = 0; }
1603
+ return new Promise(function (resolve, reject) {
1604
+ var waiter = new AcEdConditionWaiter(function () { return !_this.isProcessingEntities; }, function () {
1605
+ void (function () { return __awaiter(_this, void 0, void 0, function () {
1606
+ var smart, error_2;
1607
+ var _this = this;
1608
+ return __generator(this, function (_a) {
1609
+ switch (_a.label) {
1610
+ case 0:
1611
+ _a.trys.push([0, 2, , 3]);
1612
+ return [4 /*yield*/, this.resolveSmartFitBox()];
1613
+ case 1:
1614
+ smart = _a.sent();
1615
+ if (smart) {
1616
+ this.zoomTo(smart);
1617
+ this._isDirty = true;
1618
+ this.endProgressiveOpenFit();
1619
+ resolve();
1620
+ return [2 /*return*/];
1621
+ }
1622
+ this._progressiveOpenFit.applyFinalFit(function () {
1623
+ return _this.getDrawingExtents();
1624
+ });
1625
+ this.endProgressiveOpenFit();
1626
+ resolve();
1627
+ return [3 /*break*/, 3];
1628
+ case 2:
1629
+ error_2 = _a.sent();
1630
+ // Always clear progressive-open framing so a failed smart fit
1631
+ // cannot leave the open-fit overlay/state stuck indefinitely.
1632
+ this.endProgressiveOpenFit();
1633
+ reject(error_2);
1634
+ return [3 /*break*/, 3];
1635
+ case 3: return [2 /*return*/];
1636
+ }
1637
+ });
1638
+ }); })();
1639
+ }, 300, timeout);
1640
+ waiter.start();
1641
+ });
1642
+ };
1643
+ /**
1644
+ * Resolves intelligent zoom extents from spatial-index entity boxes.
1645
+ * Reuses the layout cache until entity geometry extents are invalidated.
1646
+ * Collects and clusters cooperatively so the UI thread stays responsive.
1647
+ */
1648
+ AcTrView2d.prototype.resolveSmartFitBox = function () {
1649
+ return __awaiter(this, void 0, void 0, function () {
1650
+ var activeLayout, cached, generation, work, entries, smart;
1651
+ return __generator(this, function (_a) {
1652
+ switch (_a.label) {
1653
+ case 0:
1654
+ activeLayout = this._scene.activeLayout;
1655
+ if (!activeLayout)
1656
+ return [2 /*return*/, undefined];
1657
+ cached = activeLayout.cachedSmartExtents;
1658
+ if (cached) {
1659
+ return [2 /*return*/, cached];
1660
+ }
1661
+ generation = activeLayout.smartExtentsGeneration;
1662
+ work = new AcTrWorkSlice();
1663
+ return [4 /*yield*/, activeLayout.collectSpatialExtentBoxesAsync(work)];
1664
+ case 1:
1665
+ entries = _a.sent();
1666
+ return [4 /*yield*/, computeIntelligentExtentsAsync(entries, work)
1667
+ // Geometry changed while we yielded: discard this result (a newer cache
1668
+ // may already exist; otherwise the caller falls back to drawing extents).
1669
+ ];
1670
+ case 2:
1671
+ smart = _a.sent();
1672
+ // Geometry changed while we yielded: discard this result (a newer cache
1673
+ // may already exist; otherwise the caller falls back to drawing extents).
1674
+ if (activeLayout.smartExtentsGeneration !== generation) {
1675
+ return [2 /*return*/, activeLayout.cachedSmartExtents];
1676
+ }
1677
+ if (smart) {
1678
+ activeLayout.cachedSmartExtents = smart;
1679
+ }
1680
+ return [2 /*return*/, smart];
1681
+ }
1682
+ });
1683
+ });
1684
+ };
1589
1685
  /**
1590
1686
  * @inheritdoc
1591
1687
  */
@@ -1638,7 +1734,9 @@ var AcTrView2d = /** @class */ (function (_super) {
1638
1734
  return entity;
1639
1735
  return undefined;
1640
1736
  }
1641
- if (entity instanceof AcDbAttribute) {
1737
+ if (entity instanceof AcDbAttribute ||
1738
+ entity.type === 'Attrib' ||
1739
+ entity.type === 'Attribute') {
1642
1740
  var owner = AcApDocManager.instance.curDocument.database.tables.blockTable.getEntityById(entity.ownerId);
1643
1741
  if (owner instanceof AcDbBlockReference &&
1644
1742
  owner.attributeIterator().count > 0) {
@@ -2315,10 +2413,14 @@ var AcTrView2d = /** @class */ (function (_super) {
2315
2413
  this._externallyFramedLayouts.add(layoutBtrId);
2316
2414
  };
2317
2415
  /**
2318
- * Resolves the 2D box to frame for the active layout once entities are
2319
- * converted. Uses {@link AcTrScene.box}, which is derived from batch geometry.
2416
+ * Returns the 2D box of drawable geometry in the active layout.
2417
+ *
2418
+ * Uses {@link AcTrScene.box}, which is derived from batch geometry — not
2419
+ * database header `EXTMIN`/`EXTMAX`, which are often stale on real DWGs.
2420
+ *
2421
+ * @inheritdoc
2320
2422
  */
2321
- AcTrView2d.prototype.resolveLayoutFitBox = function () {
2423
+ AcTrView2d.prototype.getDrawingExtents = function () {
2322
2424
  var sceneBox = this._scene.box;
2323
2425
  if (sceneBox && !sceneBox.isEmpty()) {
2324
2426
  return AcTrGeometryUtil.threeBox3dToGeBox2d(sceneBox);
@@ -2346,7 +2448,7 @@ var AcTrView2d = /** @class */ (function (_super) {
2346
2448
  * populated. Many parsers leave this empty (we've seen `(0,0)-(0,0)`),
2347
2449
  * so it sits below the viewport-based heuristic.
2348
2450
  *
2349
- * 4. **`resolveLayoutFitBox`** (entity extents from batch geometry) —
2451
+ * 4. **`getDrawingExtents`** (entity extents from batch geometry) —
2350
2452
  * last-resort fallback for layouts with no viewports and no
2351
2453
  * sensible limits/extents (e.g. a freshly created empty paper).
2352
2454
  * Vulnerable to scale-mismatch outliers, but better than no zoom.
@@ -2392,7 +2494,7 @@ var AcTrView2d = /** @class */ (function (_super) {
2392
2494
  _this.zoomTo(new AcGeBox2d({ x: extents.min.x, y: extents.min.y }, { x: extents.max.x, y: extents.max.y }));
2393
2495
  }
2394
2496
  else {
2395
- var box = _this.resolveLayoutFitBox();
2497
+ var box = _this.getDrawingExtents();
2396
2498
  if (box) {
2397
2499
  _this.zoomTo(box);
2398
2500
  }
@@ -2418,6 +2520,7 @@ var AcTrView2d = /** @class */ (function (_super) {
2418
2520
  this.resetDeferredGeometryQueue();
2419
2521
  this._entityProcessingIdleAt = 0;
2420
2522
  this._scene.clear();
2523
+ this._renderer.resetDrawOrderZ();
2421
2524
  this._isDirty = true;
2422
2525
  this._missedImages.clear();
2423
2526
  this._initializedLayouts.clear();
@@ -2971,7 +3074,8 @@ var AcTrView2d = /** @class */ (function (_super) {
2971
3074
  * @param database - Database whose text style table has just been filled.
2972
3075
  */
2973
3076
  AcTrView2d.prototype.startTextStyleFontPreload = function (database) {
2974
- var _a;
3077
+ var e_12, _a;
3078
+ var _b;
2975
3079
  var epoch = this._convertEpoch;
2976
3080
  if (this._textStyleFontPreloadEpoch === epoch &&
2977
3081
  this._textStyleFontPreloadPromise) {
@@ -2980,19 +3084,65 @@ var AcTrView2d = /** @class */ (function (_super) {
2980
3084
  this._textStyleFontPreloadEpoch = epoch;
2981
3085
  var names = [];
2982
3086
  try {
2983
- names = (_a = database.tables.textStyleTable.fonts) !== null && _a !== void 0 ? _a : [];
2984
- }
2985
- catch (_b) {
2986
- this._textStyleFontPreloadPromise = Promise.resolve();
2987
- return;
3087
+ var table = database.tables.textStyleTable;
3088
+ names = __spreadArray([], __read(((_b = table.fonts) !== null && _b !== void 0 ? _b : [])), false);
3089
+ // `fonts` is DXF group 3/4 file names only. TrueType styles store the
3090
+ // face on `font` / `extendedFont` (仿宋, SimHei).
3091
+ if (table.newIterator) {
3092
+ try {
3093
+ for (var _c = __values(table.newIterator()), _d = _c.next(); !_d.done; _d = _c.next()) {
3094
+ var record = _d.value;
3095
+ var style = record.textStyle;
3096
+ if (style === null || style === void 0 ? void 0 : style.font)
3097
+ names.push(style.font);
3098
+ if (style === null || style === void 0 ? void 0 : style.bigFont)
3099
+ names.push(style.bigFont);
3100
+ if (style === null || style === void 0 ? void 0 : style.extendedFont)
3101
+ names.push(style.extendedFont);
3102
+ }
3103
+ }
3104
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
3105
+ finally {
3106
+ try {
3107
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
3108
+ }
3109
+ finally { if (e_12) throw e_12.error; }
3110
+ }
3111
+ }
2988
3112
  }
2989
- if (names.length === 0) {
3113
+ catch (_e) {
3114
+ names = [];
3115
+ }
3116
+ // Style fonts alone are not enough: awaitFontsBeforeDraw only *awaits*
3117
+ // content/style faces and kicks default/symbol fallbacks in the background.
3118
+ // Drawings with empty primary font files (font falls back to the STYLE name)
3119
+ // need those fallbacks loaded before the first glyph bake, otherwise Latin
3120
+ // (and often all) text is permanently baked as '?'.
3121
+ var fallbackFonts = FontManager.instance.getFontsToLoad();
3122
+ var preloadNames = __spreadArray([], __read(new Set(__spreadArray(__spreadArray([], __read(names), false), __read(fallbackFonts), false))), false);
3123
+ if (preloadNames.length === 0) {
2990
3124
  this._textStyleFontPreloadPromise = Promise.resolve();
2991
3125
  return;
2992
3126
  }
2993
- this._textStyleFontPreloadPromise = FontManager.instance
2994
- .requestFonts(names)
2995
- .then(function () { }, function () {
3127
+ var mtextRenderer = AcTrMTextRenderer.getInstance();
3128
+ // Same deadline as AcApDocManager.installFontFileLoadTimeout. Covers both
3129
+ // main-thread requestFonts and worker-pool loadFonts so a stalled CDN
3130
+ // cannot pin deferred glyph jobs / the open overlay indefinitely.
3131
+ var preloadTimeoutMs = 30000;
3132
+ var preload = Promise.all([
3133
+ FontManager.instance.requestFonts(preloadNames),
3134
+ // Worker isolates have their own FontManager; main-thread requestFonts
3135
+ // alone does not populate them before asyncRenderMText.
3136
+ mtextRenderer.loadFonts(fallbackFonts)
3137
+ ]);
3138
+ this._textStyleFontPreloadPromise = Promise.race([
3139
+ preload,
3140
+ new Promise(function (_, reject) {
3141
+ setTimeout(function () {
3142
+ reject(new Error("Text-style font preload timed out after ".concat(preloadTimeoutMs, "ms")));
3143
+ }, preloadTimeoutMs);
3144
+ })
3145
+ ]).then(function () { return undefined; }, function () {
2996
3146
  // Glyph draw still falls back via FontManager defaults / '?'.
2997
3147
  });
2998
3148
  };
@@ -3121,8 +3271,8 @@ var AcTrView2d = /** @class */ (function (_super) {
3121
3271
  */
3122
3272
  AcTrView2d.prototype.redrawGlyphEntitiesAfterFontLoad = function (epoch, fontName) {
3123
3273
  return __awaiter(this, void 0, void 0, function () {
3124
- var redrawEpoch, glyphs, _a, _b, layout, glyphs_1, glyphs_1_1, glyph, e_12_1, defaults, normalized_1, msSinceIdle, db;
3125
- var e_13, _c, e_12, _d;
3274
+ var redrawEpoch, glyphs, _a, _b, layout, glyphs_1, glyphs_1_1, glyph, e_13_1, defaults, normalized_1, msSinceIdle, db;
3275
+ var e_14, _c, e_13, _d;
3126
3276
  var _e, _f;
3127
3277
  return __generator(this, function (_g) {
3128
3278
  switch (_g.label) {
@@ -3144,12 +3294,12 @@ var AcTrView2d = /** @class */ (function (_super) {
3144
3294
  });
3145
3295
  }
3146
3296
  }
3147
- catch (e_13_1) { e_13 = { error: e_13_1 }; }
3297
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
3148
3298
  finally {
3149
3299
  try {
3150
3300
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
3151
3301
  }
3152
- finally { if (e_13) throw e_13.error; }
3302
+ finally { if (e_14) throw e_14.error; }
3153
3303
  }
3154
3304
  _g.label = 1;
3155
3305
  case 1:
@@ -3172,14 +3322,14 @@ var AcTrView2d = /** @class */ (function (_super) {
3172
3322
  return [3 /*break*/, 2];
3173
3323
  case 5: return [3 /*break*/, 8];
3174
3324
  case 6:
3175
- e_12_1 = _g.sent();
3176
- e_12 = { error: e_12_1 };
3325
+ e_13_1 = _g.sent();
3326
+ e_13 = { error: e_13_1 };
3177
3327
  return [3 /*break*/, 8];
3178
3328
  case 7:
3179
3329
  try {
3180
3330
  if (glyphs_1_1 && !glyphs_1_1.done && (_d = glyphs_1.return)) _d.call(glyphs_1);
3181
3331
  }
3182
- finally { if (e_12) throw e_12.error; }
3332
+ finally { if (e_13) throw e_13.error; }
3183
3333
  return [7 /*endfinally*/];
3184
3334
  case 8:
3185
3335
  if (glyphs.length > 0) {
@@ -3205,9 +3355,14 @@ var AcTrView2d = /** @class */ (function (_super) {
3205
3355
  redrawEpoch !== this._fontLoadedRedrawEpoch) {
3206
3356
  return [2 /*return*/];
3207
3357
  }
3208
- msSinceIdle = this._entityProcessingIdleAt > 0
3209
- ? performance.now() - this._entityProcessingIdleAt
3210
- : null;
3358
+ // Font load before the first convert idle (empty scene, ENTITY stream not
3359
+ // started yet). Glyph jobs await that font. regen() here replays the
3360
+ // in-flight database: measured as thousands of duplicate convert claims
3361
+ // and a ~1GB heap spike at the start of open.
3362
+ if (this._entityProcessingIdleAt <= 0) {
3363
+ return [2 /*return*/];
3364
+ }
3365
+ msSinceIdle = performance.now() - this._entityProcessingIdleAt;
3211
3366
  // Open-time text awaits its fonts, then this debounced callback runs.
3212
3367
  // Regen here only flashes the loading spinner again after
3213
3368
  // "Rendering drawing ..." has already hidden (progressive rendering on).
@@ -3344,7 +3499,7 @@ var AcTrView2d = /** @class */ (function (_super) {
3344
3499
  * paper layouts.
3345
3500
  */
3346
3501
  AcTrView2d.prototype.ensureViewportViews = function (blockTableRecord, layoutView) {
3347
- var e_14, _a;
3502
+ var e_15, _a;
3348
3503
  var iterator = blockTableRecord.newIterator();
3349
3504
  try {
3350
3505
  for (var iterator_2 = __values(iterator), iterator_2_1 = iterator_2.next(); !iterator_2_1.done; iterator_2_1 = iterator_2.next()) {
@@ -3357,12 +3512,12 @@ var AcTrView2d = /** @class */ (function (_super) {
3357
3512
  layoutView.addViewport(viewportView);
3358
3513
  }
3359
3514
  }
3360
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
3515
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
3361
3516
  finally {
3362
3517
  try {
3363
3518
  if (iterator_2_1 && !iterator_2_1.done && (_a = iterator_2.return)) _a.call(iterator_2);
3364
3519
  }
3365
- finally { if (e_14) throw e_14.error; }
3520
+ finally { if (e_15) throw e_15.error; }
3366
3521
  }
3367
3522
  };
3368
3523
  /**
@@ -3397,7 +3552,7 @@ var AcTrView2d = /** @class */ (function (_super) {
3397
3552
  return new Promise(function (resolve) { return setTimeout(resolve, 0); });
3398
3553
  };
3399
3554
  _loop_4 = function (i) {
3400
- var entity, shouldConvert, objectId_1, convertGen_1, directMeta, added, superseded, threeEntity_1, isMultiLayerGroup, deferGeometry, isExtendBbox_1, commitEntity, layoutView, viewportView, fileName, error_2, didYield;
3555
+ var entity, shouldConvert, objectId_1, convertGen_1, directMeta, added, superseded, threeEntity_1, isMultiLayerGroup, deferGeometry, isExtendBbox_1, commitEntity, layoutView, viewportView, fileName, error_3, didYield;
3401
3556
  return __generator(this, function (_e) {
3402
3557
  switch (_e.label) {
3403
3558
  case 0:
@@ -3458,7 +3613,7 @@ var AcTrView2d = /** @class */ (function (_super) {
3458
3613
  this_3.applySessionHiddenObjectState(entity.objectId);
3459
3614
  if (progressive) {
3460
3615
  this_3.markProgressiveDirty();
3461
- this_3._progressiveOpenFit.afterGeometryBatch(function () { return _this.resolveLayoutFitBox(); }, i);
3616
+ this_3._progressiveOpenFit.afterGeometryBatch(function () { return _this.getDrawingExtents(); }, i);
3462
3617
  }
3463
3618
  }
3464
3619
  }
@@ -3535,7 +3690,7 @@ var AcTrView2d = /** @class */ (function (_super) {
3535
3690
  threeEntity_1.dispose();
3536
3691
  if (progressive) {
3537
3692
  this.markProgressiveDirty();
3538
- this._progressiveOpenFit.afterGeometryBatch(function () { return _this.resolveLayoutFitBox(); }, i);
3693
+ this._progressiveOpenFit.afterGeometryBatch(function () { return _this.getDrawingExtents(); }, i);
3539
3694
  }
3540
3695
  return [2 /*return*/];
3541
3696
  }
@@ -3577,8 +3732,8 @@ var AcTrView2d = /** @class */ (function (_super) {
3577
3732
  }
3578
3733
  return [3 /*break*/, 11];
3579
3734
  case 9:
3580
- error_2 = _e.sent();
3581
- log.error("[AcTrView2d] Failed to convert entity ".concat(entity.objectId, " (").concat(entity.type, "):"), error_2);
3735
+ error_3 = _e.sent();
3736
+ log.error("[AcTrView2d] Failed to convert entity ".concat(entity.objectId, " (").concat(entity.type, "):"), error_3);
3582
3737
  return [3 /*break*/, 11];
3583
3738
  case 10:
3584
3739
  // Counter was reset in clear() when the epoch advanced; do not
@@ -3642,8 +3797,8 @@ var AcTrView2d = /** @class */ (function (_super) {
3642
3797
  };
3643
3798
  AcTrView2d.prototype.handleGroup = function (group_1, progressive_1) {
3644
3799
  return __awaiter(this, arguments, void 0, function (group, progressive, epoch, convertGen) {
3645
- var objectId, children, objectsGroupByLayer, children_1, children_1_1, child, renderContext, groupObjectId, groupLayerName, groupChildBoxes, aggregateSpatialBbox;
3646
- var e_15, _a;
3800
+ var objectId, children, objectsGroupByLayer, children_1, children_1_1, child, renderContext, groupObjectId, groupLayerName, groupChildBoxes, aggregateSpatialBbox, registeredChildIndex;
3801
+ var e_16, _a;
3647
3802
  var _this = this;
3648
3803
  var _b, _c;
3649
3804
  if (epoch === void 0) { epoch = this._convertEpoch; }
@@ -3693,12 +3848,12 @@ var AcTrView2d = /** @class */ (function (_super) {
3693
3848
  child.parent = null;
3694
3849
  }
3695
3850
  }
3696
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
3851
+ catch (e_16_1) { e_16 = { error: e_16_1 }; }
3697
3852
  finally {
3698
3853
  try {
3699
3854
  if (children_1_1 && !children_1_1.done && (_a = children_1.return)) _a.call(children_1);
3700
3855
  }
3701
- finally { if (e_15) throw e_15.error; }
3856
+ finally { if (e_16) throw e_16.error; }
3702
3857
  }
3703
3858
  renderContext = group.renderContext;
3704
3859
  groupObjectId = group.objectId;
@@ -3722,6 +3877,7 @@ var AcTrView2d = /** @class */ (function (_super) {
3722
3877
  if (groupChildBoxes.length > 0) {
3723
3878
  group.wcsBbox = aggregateSpatialBbox.clone();
3724
3879
  }
3880
+ registeredChildIndex = false;
3725
3881
  objectsGroupByLayer.forEach(function (objects, layerName) {
3726
3882
  // Nested layer-0 may already be resolved to an inner INSERT layer during
3727
3883
  // flatten. Remaining "0" buckets inherit this (outermost) INSERT layer.
@@ -3757,7 +3913,10 @@ var AcTrView2d = /** @class */ (function (_super) {
3757
3913
  entity.userData.insertLayerName = groupLayerName;
3758
3914
  entity.wcsBbox = aggregateSpatialBbox.clone();
3759
3915
  var entityUserData = entity.userData;
3760
- entityUserData.spatialIndexChildBoxes = groupChildBoxes;
3916
+ if (!registeredChildIndex && groupChildBoxes.length > 0) {
3917
+ entityUserData.spatialIndexChildBoxes = groupChildBoxes;
3918
+ registeredChildIndex = true;
3919
+ }
3761
3920
  // Important:
3762
3921
  // DO NOT USE spread operator when adding objects because it may be one very large array
3763
3922
  // and can result in maximum call stack size exceeded
@@ -3774,7 +3933,7 @@ var AcTrView2d = /** @class */ (function (_super) {
3774
3933
  if (progressive) {
3775
3934
  this.markProgressiveDirty();
3776
3935
  this._progressiveOpenFit.afterGeometryBatch(function () {
3777
- return _this.resolveLayoutFitBox();
3936
+ return _this.getDrawingExtents();
3778
3937
  });
3779
3938
  }
3780
3939
  return [2 /*return*/];
@@ -3807,7 +3966,7 @@ var AcTrView2d = /** @class */ (function (_super) {
3807
3966
  if (!this._openLineworkFramePending || this.isConvertingEntities) {
3808
3967
  return;
3809
3968
  }
3810
- var box = this.resolveLayoutFitBox();
3969
+ var box = this.getDrawingExtents();
3811
3970
  if (!box || box.isEmpty()) {
3812
3971
  this._openLineworkFramePending = false;
3813
3972
  return;