@maqiuyao/dxf-viewer 0.2.21 → 0.2.23

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.
@@ -14251,15 +14251,18 @@ const Nn = new p.Vector3();
14251
14251
  class Ot extends ci {
14252
14252
  /**
14253
14253
  * @param id
14254
- * @param boxes 需要绘制云线框的包围盒集合
14254
+ * @param boxes 需要绘制边框的包围盒集合
14255
14255
  * @param lineColor 边框颜色 rgba 数组(0~1),默认红色
14256
14256
  * @param fillColor 区域半透明填充色 rgba 数组(0~1),默认与边框同色、低透明度
14257
+ * @param useCloudBorder 边框样式,默认 false 普通圆角矩形边框;传 true 为云线(修订云线)花边
14257
14258
  */
14258
- constructor(e, i, s = [1, 0, 0, 1], n) {
14259
+ constructor(e, i, s = [1, 0, 0, 1], n, r = !1) {
14259
14260
  super(e);
14260
14261
  g(this, "boxes");
14261
14262
  g(this, "lineSegments");
14262
- this.lineSegments = [], this.boxes = Ot.expandBoxesWithGap(i), this.lineColor = s, this.fillColor = n ?? [s[0], s[1], s[2], 0.12], this.lineWidth = 2, this.calculateCloudLineSegments(this.boxes);
14263
+ /** 边框样式:true 云线(修订云线花边),false 普通圆角矩形边框 */
14264
+ g(this, "useCloudBorder");
14265
+ this.lineSegments = [], this.useCloudBorder = r, this.boxes = Ot.expandBoxesWithGap(i), this.lineColor = s, this.fillColor = n ?? [s[0], s[1], s[2], 0.12], this.lineWidth = 2, r && this.calculateCloudLineSegments(this.boxes);
14263
14266
  }
14264
14267
  /**
14265
14268
  * 按包围盒尺寸比例向外扩张,使云线框与变动内容之间留出间隙,避免框线压住文字/图形。
@@ -14284,14 +14287,22 @@ class Ot extends ci {
14284
14287
  }
14285
14288
  draw(e, i) {
14286
14289
  e.save(), e.lineWidth = this.lineWidth, e.strokeStyle = gs.rgba2Color(this.lineColor), e.fillStyle = gs.rgba2Color(this.fillColor);
14287
- for (let s = 0; s < this.lineSegments.length; s++) {
14290
+ for (let s = 0; s < (this.useCloudBorder ? this.lineSegments.length : this.boxes.length); s++) {
14288
14291
  const n = this.boxes[s];
14289
- n && this.fillRect(e, i, n);
14290
- const r = this.lineSegments[s];
14291
- this.drawBox(e, i, r);
14292
+ if (n && this.fillRect(e, i, n), this.useCloudBorder) {
14293
+ const r = this.lineSegments[s];
14294
+ this.drawBox(e, i, r);
14295
+ } else
14296
+ this.drawRoundedRect(e, i, n);
14292
14297
  }
14293
14298
  e.restore();
14294
14299
  }
14300
+ /** 普通圆角矩形边框:屏幕空间绘制,圆角半径固定像素(不随缩放变化) */
14301
+ drawRoundedRect(e, i, s) {
14302
+ if (!s) return;
14303
+ const n = this.transToScreenCoord(new p.Vector3(s.min.x, s.min.y), i), r = this.transToScreenCoord(new p.Vector3(s.max.x, s.min.y), i), a = this.transToScreenCoord(new p.Vector3(s.max.x, s.max.y), i), o = this.transToScreenCoord(new p.Vector3(s.min.x, s.max.y), i), l = Math.hypot(r.x - n.x, r.y - n.y), h = Math.hypot(o.x - n.x, o.y - n.y), d = Math.max(0, Math.min(8, l / 2, h / 2));
14304
+ e.beginPath(), e.moveTo(n.x + d, n.y), e.arcTo(r.x, r.y, a.x, a.y, d), e.arcTo(a.x, a.y, o.x, o.y, d), e.arcTo(o.x, o.y, n.x, n.y, d), e.arcTo(n.x, n.y, r.x, r.y, d), e.closePath(), e.stroke();
14305
+ }
14295
14306
  fillRect(e, i, s) {
14296
14307
  const n = [new p.Vector3(s.min.x, s.min.y), new p.Vector3(s.max.x, s.min.y), new p.Vector3(s.max.x, s.max.y), new p.Vector3(s.min.x, s.max.y)];
14297
14308
  e.beginPath();
@@ -20485,9 +20496,10 @@ const Ge = new p.Vector3(1, 0, 0), Xn = new p.Vector3(0, 1, 0), bi = new p.Vecto
20485
20496
  */
20486
20497
  g(this, "entityThreejsCache");
20487
20498
  /**
20488
- * 顶级实体 handle → 实体索引,用于 ATTRIB 查找所属 INSERT(父实体)。
20499
+ * 顶级实体 handle → { 实体, 在 entities 数组中的下标 },用于 ATTRIB 查找所属 INSERT(父实体)。
20489
20500
  * 此前为逐 ATTRIB 线性扫描全部实体(O(n²),大图纸上万 ATTRIB 时耗时数十秒),
20490
- * 改为首次使用时构建一次索引、O(1) 查找。
20501
+ * 改为首次使用时构建一次索引、O(1) 查找;下标用于 owner 链不指向 INSERT 时
20502
+ * 沿实体流向前回溯最近 INSERT(标准 DXF:INSERT(66=1) 后紧跟其 ATTRIB 组)。
20491
20503
  */
20492
20504
  g(this, "entitiesByHandleIndex");
20493
20505
  /**
@@ -21019,15 +21031,29 @@ const Ge = new p.Vector3(1, 0, 0), Xn = new p.Vector3(0, 1, 0), bi = new p.Vecto
21019
21031
  else if (e.type === "DIMENSION") o = this.loadDimension(e, i);
21020
21032
  else if (e.type !== "REGION") if (e.type === "ATTDEF") o = this.loadAttDef(e, i, s);
21021
21033
  else if (e.type === "ATTRIB") {
21022
- if (!s && e.ownerHandle) {
21034
+ if (!s) {
21023
21035
  if (!this.entitiesByHandleIndex || this.entitiesByHandleIndexData !== i) {
21024
21036
  this.entitiesByHandleIndexData = i, this.entitiesByHandleIndex = /* @__PURE__ */ new Map();
21025
21037
  for (let m = 0; m < i.entities.length; m++) {
21026
21038
  const b = i.entities[m];
21027
- b.handle && this.entitiesByHandleIndex.set(b.handle, b);
21039
+ b.handle && this.entitiesByHandleIndex.set(b.handle, { entity: b, index: m });
21028
21040
  }
21029
21041
  }
21030
- s = this.entitiesByHandleIndex.get(e.ownerHandle);
21042
+ if (e.ownerHandle) {
21043
+ const m = this.entitiesByHandleIndex.get(e.ownerHandle);
21044
+ m?.entity.type === "INSERT" && (s = m.entity);
21045
+ }
21046
+ if (!s) {
21047
+ const m = e.handle ? this.entitiesByHandleIndex.get(e.handle) : void 0;
21048
+ if (m)
21049
+ for (let b = m.index - 1; b >= 0; b--) {
21050
+ const y = i.entities[b];
21051
+ if (y.type === "INSERT") {
21052
+ s = y;
21053
+ break;
21054
+ }
21055
+ }
21056
+ }
21031
21057
  }
21032
21058
  o = this.loadAttrib(e, i, s);
21033
21059
  } else e.type === "HATCH" ? o = this.loadHatch(e, i, s) : e.type === "VIEWPORT" ? o = this.loadViewport(e, i, s) : e.type === "LEADER" ? o = this.loadLeader(e, i, s) : e.type === "MULTILEADER" ? o = this.loadMLeader(e, i, s) : e.type === "OLE2FRAME" ? o = this.loadOle2frame(e, i) : e.type === "ACAD_TABLE" && (o = this.loadTable(e, i));
@@ -32490,12 +32516,15 @@ class no {
32490
32516
  }
32491
32517
  /**
32492
32518
  * 定位到一条搜索结果:切换到其所在布局、缩放至包围盒,并在叠加层高亮。
32519
+ * @param zoomScale 视野缩放比例:定位后的视野约为文字包围盒对角线的 zoomScale 倍,
32520
+ * 数值越大可视区域越大、文字占比越小(不要光看字);默认 8,
32521
+ * 传 2 约等于旧版视野(文字占满视野)。
32493
32522
  */
32494
- focus(t) {
32523
+ focus(t, e = 8) {
32495
32524
  if (!t) return;
32496
32525
  this.viewer.activateLayout(t.layoutName), this.highlight(t);
32497
- const e = t.box.clone();
32498
- this.viewer.zoomToBBox(e.expandByScalar(Math.max(e.getSize(pu).length() * 0.5, 1)));
32526
+ const i = t.box.clone(), s = i.getSize(pu).length(), n = Math.max(s * e, s + 2);
32527
+ this.viewer.zoomToBBox(i.expandByScalar((n - s) / 2));
32499
32528
  }
32500
32529
  /**
32501
32530
  * 在叠加层用云线框高亮指定结果(替换上一个高亮)。
@@ -34135,9 +34164,17 @@ class $o extends Pr {
34135
34164
  /**
34136
34165
  * @description {en} Zooms to a text search result and highlights it with a cloud border.
34137
34166
  * @description {zh} 定位到一条文本搜索结果并高亮(云线框)。
34167
+ * @param zoomScale 视野缩放比例:定位后的视野约为文字包围盒对角线的 zoomScale 倍,
34168
+ * 数值越大可视区域越大、文字占比越小;默认 8,传 2 约等于旧版视野。
34169
+ * @example
34170
+ * ```typescript
34171
+ * const results = viewer.searchText("道岔");
34172
+ * results.length > 0 && viewer.focusText(results[0]); // 默认视野(可视区域较大)
34173
+ * results.length > 0 && viewer.focusText(results[0], 4); // 更贴近文字
34174
+ * ```
34138
34175
  */
34139
- focusText(e) {
34140
- !this.textSearchHelper && (this.textSearchHelper = new no(this)), this.textSearchHelper.focus(e);
34176
+ focusText(e, i) {
34177
+ !this.textSearchHelper && (this.textSearchHelper = new no(this)), this.textSearchHelper.focus(e, i);
34141
34178
  }
34142
34179
  /**
34143
34180
  * @description {en} Clears the highlight of text search results.
@@ -6,13 +6,16 @@ import * as THREE from "three";
6
6
  export declare class CompareDrawable extends Drawable {
7
7
  boxes: THREE.Box3[];
8
8
  lineSegments: THREE.Vector3[][];
9
+ /** 边框样式:true 云线(修订云线花边),false 普通圆角矩形边框 */
10
+ private useCloudBorder;
9
11
  /**
10
12
  * @param id
11
- * @param boxes 需要绘制云线框的包围盒集合
13
+ * @param boxes 需要绘制边框的包围盒集合
12
14
  * @param lineColor 边框颜色 rgba 数组(0~1),默认红色
13
15
  * @param fillColor 区域半透明填充色 rgba 数组(0~1),默认与边框同色、低透明度
16
+ * @param useCloudBorder 边框样式,默认 false 普通圆角矩形边框;传 true 为云线(修订云线)花边
14
17
  */
15
- constructor(id: string, boxes: THREE.Box3[], lineColor?: number[], fillColor?: number[]);
18
+ constructor(id: string, boxes: THREE.Box3[], lineColor?: number[], fillColor?: number[], useCloudBorder?: boolean);
16
19
  /**
17
20
  * 按包围盒尺寸比例向外扩张,使云线框与变动内容之间留出间隙,避免框线压住文字/图形。
18
21
  * 间隙取盒最长边的 12%(退化盒给最小值兜底)。
@@ -20,6 +23,8 @@ export declare class CompareDrawable extends Drawable {
20
23
  private static expandBoxesWithGap;
21
24
  private calculateCloudLineSegments;
22
25
  draw(ctx: CanvasRenderingContext2D, camera: THREE.Camera): void;
26
+ /** 普通圆角矩形边框:屏幕空间绘制,圆角半径固定像素(不随缩放变化) */
27
+ private drawRoundedRect;
23
28
  private fillRect;
24
29
  private drawBox;
25
30
  static getControlPointByTwoPoints(p1: THREE.Vector2, p2: THREE.Vector2): THREE.Vector2;
@@ -295,9 +295,10 @@ export declare class DxfLoader extends THREE.Loader {
295
295
  */
296
296
  private entityThreejsCache?;
297
297
  /**
298
- * 顶级实体 handle → 实体索引,用于 ATTRIB 查找所属 INSERT(父实体)。
298
+ * 顶级实体 handle → { 实体, 在 entities 数组中的下标 },用于 ATTRIB 查找所属 INSERT(父实体)。
299
299
  * 此前为逐 ATTRIB 线性扫描全部实体(O(n²),大图纸上万 ATTRIB 时耗时数十秒),
300
- * 改为首次使用时构建一次索引、O(1) 查找。
300
+ * 改为首次使用时构建一次索引、O(1) 查找;下标用于 owner 链不指向 INSERT 时
301
+ * 沿实体流向前回溯最近 INSERT(标准 DXF:INSERT(66=1) 后紧跟其 ATTRIB 组)。
301
302
  */
302
303
  private entitiesByHandleIndex?;
303
304
  /**
@@ -68,8 +68,11 @@ export declare class TextSearchHelper {
68
68
  }): TextSearchResult[];
69
69
  /**
70
70
  * 定位到一条搜索结果:切换到其所在布局、缩放至包围盒,并在叠加层高亮。
71
+ * @param zoomScale 视野缩放比例:定位后的视野约为文字包围盒对角线的 zoomScale 倍,
72
+ * 数值越大可视区域越大、文字占比越小(不要光看字);默认 8,
73
+ * 传 2 约等于旧版视野(文字占满视野)。
71
74
  */
72
- focus(result: TextSearchResult): void;
75
+ focus(result: TextSearchResult, zoomScale?: number): void;
73
76
  /**
74
77
  * 在叠加层用云线框高亮指定结果(替换上一个高亮)。
75
78
  */
@@ -442,8 +442,16 @@ export declare class Viewer2d extends BaseViewer {
442
442
  /**
443
443
  * @description {en} Zooms to a text search result and highlights it with a cloud border.
444
444
  * @description {zh} 定位到一条文本搜索结果并高亮(云线框)。
445
+ * @param zoomScale 视野缩放比例:定位后的视野约为文字包围盒对角线的 zoomScale 倍,
446
+ * 数值越大可视区域越大、文字占比越小;默认 8,传 2 约等于旧版视野。
447
+ * @example
448
+ * ```typescript
449
+ * const results = viewer.searchText("道岔");
450
+ * results.length > 0 && viewer.focusText(results[0]); // 默认视野(可视区域较大)
451
+ * results.length > 0 && viewer.focusText(results[0], 4); // 更贴近文字
452
+ * ```
445
453
  */
446
- focusText(result: TextSearchResult): void;
454
+ focusText(result: TextSearchResult, zoomScale?: number): void;
447
455
  /**
448
456
  * @description {en} Clears the highlight of text search results.
449
457
  * @description {zh} 清除文本搜索结果的高亮。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maqiuyao/dxf-viewer",
3
- "version": "0.2.21",
3
+ "version": "0.2.23",
4
4
  "description": "基于 three.js 的 DXF 图纸 2D/3D 查看与对比库(Viewer2d / DxfCompareHelper)",
5
5
  "type": "module",
6
6
  "main": "./dist/dxf-viewer.cjs",