@maqiuyao/dxf-viewer 0.2.33 → 0.2.34

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.
@@ -35047,49 +35047,91 @@ class pr {
35047
35047
  split(t) {
35048
35048
  if (this.detected || this.detectFrames(), this.frames.length === 0) return [];
35049
35049
  const e = new Set(
35050
- t ? t.filter((h) => h >= 0 && h < this.frames.length) : this.frames.map((h) => h.index)
35050
+ t ? t.filter((u) => u >= 0 && u < this.frames.length) : this.frames.map((u) => u.index)
35051
35051
  );
35052
35052
  if (e.size === 0) return [];
35053
35053
  this.report(10, "组装子 DXF");
35054
- const i = [], s = [];
35055
- let n = !1;
35056
- for (const h of this.sections) {
35057
- if (h.name === "ENTITIES") {
35058
- n = !0;
35054
+ const i = this.sections.find((u) => u.name === "HEADER"), s = [];
35055
+ if (i)
35056
+ for (let u = i.start; u <= i.end + 1 && u < this.lines.length; u++) s.push(this.lines[u]);
35057
+ const n = [], r = [];
35058
+ let a = !1;
35059
+ for (const u of this.sections) {
35060
+ if (u.name === "ENTITIES") {
35061
+ a = !0;
35059
35062
  continue;
35060
35063
  }
35061
- const d = n ? s : i;
35062
- for (let u = h.start; u <= h.end + 1 && u < this.lines.length; u++) d.push(this.lines[u]);
35063
- }
35064
- const r = i.join(`\r
35065
- `), a = s.length ? `\r
35066
- ${s.join(`\r
35067
- `)}` : "", o = /* @__PURE__ */ new Map();
35068
- for (const h of e) o.set(h, []);
35069
- for (let h = 0; h < this.entityBlocks.length; h++) {
35070
- const d = this.assignments[h];
35071
- if (d >= 0 && o.has(d)) {
35072
- const u = this.entityBlocks[h];
35073
- o.get(d).push(this.lines.slice(u.start, u.end).join(`\r
35064
+ if (u.name === "HEADER") continue;
35065
+ const f = a ? r : n;
35066
+ for (let m = u.start; m <= u.end + 1 && m < this.lines.length; m++) f.push(this.lines[m]);
35067
+ }
35068
+ const o = n.join(`\r
35069
+ `), l = r.length ? `\r
35070
+ ${r.join(`\r
35071
+ `)}` : "", h = /* @__PURE__ */ new Map();
35072
+ for (const u of e) h.set(u, []);
35073
+ for (let u = 0; u < this.entityBlocks.length; u++) {
35074
+ const f = this.assignments[u];
35075
+ if (f >= 0 && h.has(f)) {
35076
+ const m = this.entityBlocks[u];
35077
+ h.get(f).push(this.lines.slice(m.start, m.end).join(`\r
35074
35078
  `));
35075
35079
  }
35076
35080
  }
35077
- const l = [];
35078
- for (const h of e) {
35079
- const d = this.frames[h], u = o.get(h).join(`\r
35080
- `), f = `${r}\r
35081
+ const d = [];
35082
+ for (const u of e) {
35083
+ const f = this.frames[u], x = [i ? this.rewriteHeaderExtent(s, f.bbox).join(`\r
35084
+ `) : "", o].filter((w) => w.length > 0).join(`\r
35085
+ `), g = h.get(u).join(`\r
35086
+ `), M = `${x}\r
35081
35087
  0\r
35082
35088
  SECTION\r
35083
35089
  2\r
35084
35090
  ENTITIES\r
35085
- ${u}\r
35091
+ ${g}\r
35086
35092
  0\r
35087
- ENDSEC${a}\r
35093
+ ENDSEC${l}\r
35088
35094
  0\r
35089
35095
  EOF`;
35090
- l.push({ frame: d, text: this.stripReactors(f) });
35096
+ d.push({ frame: f, text: this.stripReactors(M) });
35091
35097
  }
35092
- return this.report(100, `已生成 ${l.length} 张子 DXF`), l;
35098
+ return this.report(100, `已生成 ${d.length} 张子 DXF`), d;
35099
+ }
35100
+ /**
35101
+ * 按图框范围重写 HEADER 的视图变量($EXTMIN/$EXTMAX/$VIEWCTR/$VIEWSIZE,外扩 2%)。
35102
+ * 否则所有子图沿用整图范围(可达数千单位),AutoCAD 打开子图时初始取景基于整图、
35103
+ * 内容缩成一小块;重写后打开即取景到本图框。
35104
+ */
35105
+ rewriteHeaderExtent(t, e) {
35106
+ const i = (e.maxX - e.minX) * 0.02, s = (e.maxY - e.minY) * 0.02, n = e.minX - i, r = e.maxX + i, a = e.minY - s, o = e.maxY + s, l = (n + r) / 2, h = (a + o) / 2, d = (o - a) * 1.1, u = (x) => String(Number(x.toFixed(6))), f = [];
35107
+ let m = "";
35108
+ for (let x = 0; x + 1 < t.length; x += 2) {
35109
+ const g = t[x].trim();
35110
+ if (g === "9") {
35111
+ m = t[x + 1].trim().toUpperCase(), f.push(t[x], t[x + 1]);
35112
+ continue;
35113
+ }
35114
+ if (m === "$EXTMIN" || m === "$EXTMAX" || m === "$VIEWCTR") {
35115
+ if (g === "10") {
35116
+ f.push(t[x], String(u(m === "$EXTMAX" ? r : m === "$EXTMIN" ? n : l)));
35117
+ continue;
35118
+ }
35119
+ if (g === "20") {
35120
+ f.push(t[x], String(u(m === "$EXTMAX" ? o : m === "$EXTMIN" ? a : h)));
35121
+ continue;
35122
+ }
35123
+ if (g === "30") {
35124
+ f.push(t[x], "0.0");
35125
+ continue;
35126
+ }
35127
+ }
35128
+ if (m === "$VIEWSIZE" && g === "40") {
35129
+ f.push(t[x], u(d));
35130
+ continue;
35131
+ }
35132
+ f.push(t[x], t[x + 1]);
35133
+ }
35134
+ return f;
35093
35135
  }
35094
35136
  /**
35095
35137
  * 删除所有 {ACAD_REACTORS ...} 与 {BLKREFS ...} 扩展块。
@@ -35173,7 +35215,10 @@ EOF`;
35173
35215
  for (; r + 1 < i; ) {
35174
35216
  if (r % 2 === 0 && e[r].trim() === "0") {
35175
35217
  const a = e[r + 1].trim();
35176
- if (r += 2, a === "SEQEND") break;
35218
+ if (r += 2, a === "SEQEND") {
35219
+ for (; r + 1 < i && !(r % 2 === 0 && e[r].trim() === "0"); ) r += 2;
35220
+ break;
35221
+ }
35177
35222
  continue;
35178
35223
  }
35179
35224
  r += 2;
@@ -35187,7 +35232,7 @@ EOF`;
35187
35232
  continue;
35188
35233
  }
35189
35234
  if (a === "SEQEND") {
35190
- r += 2;
35235
+ for (r += 2; r + 1 < i && !(r % 2 === 0 && e[r].trim() === "0"); ) r += 2;
35191
35236
  break;
35192
35237
  }
35193
35238
  break;
@@ -35502,7 +35547,8 @@ EOF`;
35502
35547
  }
35503
35548
  return h.map((d, u) => ({
35504
35549
  index: u,
35505
- name: d.name ?? `图框${u + 1}`,
35550
+ // 编号补零:文件按名称排序时保持数字序(图框02 排在图框10 前)
35551
+ name: d.name ?? `图框${String(u + 1).padStart(2, "0")}`,
35506
35552
  source: d.source,
35507
35553
  bbox: d.bbox,
35508
35554
  entityCount: 0
@@ -99,6 +99,12 @@ export declare class DxfSplitter {
99
99
  * @param frameIndices 要导出的图框序号数组;不传则导出全部图框。
100
100
  */
101
101
  split(frameIndices?: number[]): DxfSplitPiece[];
102
+ /**
103
+ * 按图框范围重写 HEADER 的视图变量($EXTMIN/$EXTMAX/$VIEWCTR/$VIEWSIZE,外扩 2%)。
104
+ * 否则所有子图沿用整图范围(可达数千单位),AutoCAD 打开子图时初始取景基于整图、
105
+ * 内容缩成一小块;重写后打开即取景到本图框。
106
+ */
107
+ private rewriteHeaderExtent;
102
108
  /**
103
109
  * 删除所有 {ACAD_REACTORS ...} 与 {BLKREFS ...} 扩展块。
104
110
  * 二者都指向可能已被分到其他子图的实体(331 反应器/块引用列表),
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@maqiuyao/dxf-viewer",
3
- "version": "0.2.33",
3
+ "version": "0.2.34",
4
4
  "description": "基于 three.js 的 DXF 图纸 2D/3D 查看与对比库(Viewer2d / DxfCompareHelper)",
5
5
  "type": "module",
6
+ "scripts": {
7
+ "prepublishOnly": "node ../scripts/check-bom.mjs"
8
+ },
6
9
  "main": "./dist/dxf-viewer.cjs",
7
10
  "module": "./dist/dxf-viewer.js",
8
11
  "types": "./dist/src/dxfViewer/lib.d.ts",