@zhongguo168a/yxeditor-common 0.0.78 → 0.0.80

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.d.ts CHANGED
@@ -454,10 +454,18 @@ declare class TreeNode<T = any> {
454
454
  */
455
455
  walkRemove(f: (node: TreeNode) => boolean): void;
456
456
  private _walkRemove;
457
+ flat(): TreeNode[];
458
+ /**
459
+ * 广度优先遍历(BFS):从当前节点开始,逐层遍历子树
460
+ * @param f - 节点处理函数,返回 false 表示停止遍历
461
+ * @param inChild - 决定是否将子节点加入队列:若提供,调用 inChild(node),返回 true 才加入其子节点
462
+ */
463
+ walkBFS(f: (node: TreeNode) => boolean, inChild?: (node: TreeNode) => boolean): boolean;
457
464
  /**
458
465
  * 如果返回true则继续,包含当前节点
466
+ * 深度优先遍历(DFS)
459
467
  * @param f
460
- * @param inChild
468
+ * @param inChild 如果返回true,则继续遍历, 否则不进入节点的子节点
461
469
  */
462
470
  walk(f: (node: TreeNode) => boolean, inChild?: (node: TreeNode) => boolean): void;
463
471
  private _walk;
@@ -1796,7 +1804,7 @@ declare namespace formatutil {
1796
1804
  function format数字使用逗号(val: number | string, N?: number): string;
1797
1805
  }
1798
1806
 
1799
- declare enum GeometryDirection {
1807
+ declare const enum GeometryDirection {
1800
1808
  East = 0,
1801
1809
  SouthEast = 1,
1802
1810
  South = 2,
@@ -1804,9 +1812,18 @@ declare enum GeometryDirection {
1804
1812
  West = 4,
1805
1813
  NorthWest = 5,
1806
1814
  North = 6,
1807
- NorthEast = 7
1815
+ NorthEast = 7,
1816
+ Any = -1
1817
+ }
1818
+ declare const enum DirectionMode {
1819
+ 任意 = 0,
1820
+ 二方向 = 1,
1821
+ 四方向 = 2,
1822
+ 斜四方向 = 3,
1823
+ 八方向 = 4
1808
1824
  }
1809
1825
  declare class GeometryUtil {
1826
+ getDirection(mode: DirectionMode, 角度: number): GeometryDirection;
1810
1827
  /**
1811
1828
  * mode,8表示八方向,2表示二方向(左右),4表示4方向
1812
1829
  * @param dot
package/dist/index.esm.js CHANGED
@@ -2036,10 +2036,53 @@ class TreeNode {
2036
2036
  }
2037
2037
  return true;
2038
2038
  }
2039
+ flat() {
2040
+ let result = [];
2041
+ this.walkBFS((node) => {
2042
+ result.push(node);
2043
+ return true;
2044
+ });
2045
+ return result;
2046
+ }
2047
+ /**
2048
+ * 广度优先遍历(BFS):从当前节点开始,逐层遍历子树
2049
+ * @param f - 节点处理函数,返回 false 表示停止遍历
2050
+ * @param inChild - 决定是否将子节点加入队列:若提供,调用 inChild(node),返回 true 才加入其子节点
2051
+ */
2052
+ walkBFS(f, inChild) {
2053
+ var _a;
2054
+ const queue = [this]; // 初始化队列
2055
+ while (queue.length > 0) {
2056
+ const node = queue.shift(); // 取出队首节点
2057
+ try {
2058
+ // 1. 处理当前节点
2059
+ if (!f(node)) {
2060
+ return false; // 停止遍历
2061
+ }
2062
+ }
2063
+ catch (e) {
2064
+ console.warn('walkBFS error:', e);
2065
+ return false;
2066
+ }
2067
+ // 2. 决定是否展开子节点
2068
+ const shouldEnqueueChildren = inChild ? inChild(node) : true;
2069
+ if (!shouldEnqueueChildren || node.isLeaf) {
2070
+ continue;
2071
+ }
2072
+ // 3. 将子节点加入队列(从左到右)
2073
+ if ((_a = node.children) === null || _a === void 0 ? void 0 : _a.length) {
2074
+ for (const child of node.children) {
2075
+ queue.push(child);
2076
+ }
2077
+ }
2078
+ }
2079
+ return true; // 遍历完成
2080
+ }
2039
2081
  /**
2040
2082
  * 如果返回true则继续,包含当前节点
2083
+ * 深度优先遍历(DFS)
2041
2084
  * @param f
2042
- * @param inChild
2085
+ * @param inChild 如果返回true,则继续遍历, 否则不进入节点的子节点
2043
2086
  */
2044
2087
  walk(f, inChild) {
2045
2088
  this._walk(f, inChild);
@@ -5434,8 +5477,34 @@ var GeometryDirection;
5434
5477
  GeometryDirection[GeometryDirection["NorthWest"] = 5] = "NorthWest";
5435
5478
  GeometryDirection[GeometryDirection["North"] = 6] = "North";
5436
5479
  GeometryDirection[GeometryDirection["NorthEast"] = 7] = "NorthEast";
5480
+ GeometryDirection[GeometryDirection["Any"] = -1] = "Any";
5437
5481
  })(GeometryDirection || (GeometryDirection = {}));
5482
+ var DirectionMode;
5483
+ (function (DirectionMode) {
5484
+ DirectionMode[DirectionMode["\u4EFB\u610F"] = 0] = "\u4EFB\u610F";
5485
+ DirectionMode[DirectionMode["\u4E8C\u65B9\u5411"] = 1] = "\u4E8C\u65B9\u5411";
5486
+ DirectionMode[DirectionMode["\u56DB\u65B9\u5411"] = 2] = "\u56DB\u65B9\u5411";
5487
+ DirectionMode[DirectionMode["\u659C\u56DB\u65B9\u5411"] = 3] = "\u659C\u56DB\u65B9\u5411";
5488
+ DirectionMode[DirectionMode["\u516B\u65B9\u5411"] = 4] = "\u516B\u65B9\u5411";
5489
+ })(DirectionMode || (DirectionMode = {}));
5438
5490
  class GeometryUtil {
5491
+ getDirection(mode, 角度) {
5492
+ let direction = 0;
5493
+ switch (mode) {
5494
+ case DirectionMode.任意:
5495
+ direction = GeometryDirection.Any;
5496
+ break;
5497
+ case DirectionMode.二方向:
5498
+ direction = geoutil.angleToDirection(角度, 2);
5499
+ break;
5500
+ case DirectionMode.四方向:
5501
+ direction = geoutil.angleToDirection(角度, 4);
5502
+ break;
5503
+ case DirectionMode.斜四方向:
5504
+ break;
5505
+ }
5506
+ return direction;
5507
+ }
5439
5508
  /**
5440
5509
  * mode,8表示八方向,2表示二方向(左右),4表示4方向
5441
5510
  * @param dot