@unicom-cloud/utils 0.1.12 → 0.1.14
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/filesize/src/constants.js +22 -22
- package/filesize/src/filesize.js +32 -33
- package/package.json +1 -1
- package/snapdom/src/api/preCache.js +23 -23
- package/snapdom/src/api/snapdom.js +67 -63
- package/snapdom/src/core/cache.js +19 -8
- package/snapdom/src/core/capture.js +46 -45
- package/snapdom/src/core/clone.js +94 -31
- package/snapdom/src/core/prepare.js +35 -38
- package/snapdom/src/modules/background.js +29 -20
- package/snapdom/src/modules/fonts.js +93 -101
- package/snapdom/src/modules/pseudo.js +70 -75
- package/snapdom/src/modules/styles.js +22 -22
- package/snapdom/src/utils/cssTools.js +41 -41
- package/snapdom/src/utils/helpers.js +143 -146
- package/tree/index.js +1 -1
- package/tree/search/index.js +90 -0
- package/tree.js +1 -1
- package/types/filesize/src/constants.d.ts +12 -12
- package/types/filesize/src/filesize.d.ts +63 -22
- package/types/snapdom/src/core/cache.d.ts +17 -11
- package/types/snapdom/src/core/capture.d.ts +4 -0
- package/types/snapdom/src/core/clone.d.ts +4 -5
- package/types/snapdom/src/core/prepare.d.ts +8 -1
- package/types/snapdom/src/modules/background.d.ts +1 -2
- package/types/snapdom/src/modules/pseudo.d.ts +1 -3
- package/types/snapdom/src/modules/styles.d.ts +1 -1
- package/types/snapdom/src/utils/cssTools.d.ts +1 -2
- package/types/tree/index.d.ts +1 -1
- package/types/tree/search/index.d.ts +80 -0
- package/types/ui-color/index.d.ts +28 -3
- package/ui-color/index.js +70 -63
- package/uiColor.js +19 -18
- package/tree/searchTree.js +0 -54
- package/types/tree/searchTree.d.ts +0 -20
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @param {Element} element - Element to clone
|
|
5
5
|
* @param {boolean} [compress=false] - Whether to compress style keys
|
|
6
|
+
* @param {boolean} [embedFonts=false] - Whether to embed custom fonts
|
|
7
|
+
* @param {Object} [options={}] - Capture options
|
|
8
|
+
* @param {string[]} [options.exclude] - CSS selectors for elements to exclude
|
|
9
|
+
* @param {Function} [options.filter] - Custom filter function
|
|
6
10
|
* @returns {Promise<Object>} Object containing the clone, generated CSS, and style cache
|
|
7
11
|
*/
|
|
8
|
-
export function prepareClone(element: Element, compress?: boolean, embedFonts?: boolean,
|
|
12
|
+
export function prepareClone(element: Element, compress?: boolean, embedFonts?: boolean, options?: {
|
|
13
|
+
exclude?: string[] | undefined;
|
|
14
|
+
filter?: Function | undefined;
|
|
15
|
+
}): Promise<Object>;
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @param {Element} source - Original element
|
|
5
5
|
* @param {Element} clone - Cloned element
|
|
6
|
-
* @param {WeakMap} styleCache - Cache of computed styles
|
|
7
6
|
* @param {Object} [options={}] - Options for image processing
|
|
8
7
|
* @returns {Promise<void>} Promise that resolves when all background images are processed
|
|
9
8
|
*/
|
|
10
|
-
export function inlineBackgroundImages(source: Element, clone: Element,
|
|
9
|
+
export function inlineBackgroundImages(source: Element, clone: Element, options?: Object): Promise<void>;
|
|
@@ -3,10 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @param {Element} source - Original element
|
|
5
5
|
* @param {Element} clone - Cloned element
|
|
6
|
-
* @param {Map} styleMap - Map to store element-to-style-key mappings
|
|
7
|
-
* @param {WeakMap} styleCache - Cache of computed styles
|
|
8
6
|
* @param {boolean} compress - Whether to compress style keys
|
|
9
7
|
* @param {boolean} embedFonts - Whether to embed icon fonts as images
|
|
10
8
|
* @returns {Promise} Promise that resolves when all pseudo-elements are processed
|
|
11
9
|
*/
|
|
12
|
-
export function inlinePseudoElements(source: Element, clone: Element,
|
|
10
|
+
export function inlinePseudoElements(source: Element, clone: Element, compress: boolean, embedFonts: boolean | undefined, useProxy: any): Promise<any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export function inlineAllStyles(source: any, clone: any,
|
|
1
|
+
export function inlineAllStyles(source: any, clone: any, compress: any): void;
|
|
@@ -32,7 +32,6 @@ export function generateDedupedBaseCSS(usedTagNames: string[]): string;
|
|
|
32
32
|
/**
|
|
33
33
|
* Generates CSS classes from a style map.
|
|
34
34
|
*
|
|
35
|
-
* @param {Map} styleMap - Map of elements to style keys
|
|
36
35
|
* @returns {Map} Map of style keys to class names
|
|
37
36
|
*/
|
|
38
|
-
export function generateCSSClasses(
|
|
37
|
+
export function generateCSSClasses(): Map<any, any>;
|
package/types/tree/index.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export function getLabelFromDictionaryByValue(a: any, value: any, 保底?: boole
|
|
|
6
6
|
export function getChildWithParentBy(root: any, key: any, value: any, childrenKey?: string): null | undefined;
|
|
7
7
|
export function getItemBy2(root: any, key: any, value: any, childrenKey?: string): any;
|
|
8
8
|
export default getItemBy;
|
|
9
|
-
export { default as searchTree } from "./
|
|
9
|
+
export { default as searchTree } from "./search";
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 基础原始类型定义(string/number/boolean/symbol/null/undefined)
|
|
3
|
+
*/
|
|
4
|
+
type Primitive = string | number | boolean | symbol | null | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* 条件值类型,可以是:
|
|
7
|
+
* 1. 原始值(Primitive)
|
|
8
|
+
* 2. 判断函数(接收节点值返回boolean)
|
|
9
|
+
* 3. 正则表达式
|
|
10
|
+
* @template T 节点值的泛型类型
|
|
11
|
+
*/
|
|
12
|
+
type ConditionValue<T = unknown> = Primitive | ((value: T) => boolean) | RegExp;
|
|
13
|
+
/**
|
|
14
|
+
* 树搜索配置选项接口
|
|
15
|
+
*/
|
|
16
|
+
interface SearchOptions {
|
|
17
|
+
/**
|
|
18
|
+
* 遍历策略:广度优先(BFS)或深度优先(DFS)
|
|
19
|
+
* @default 'BFS'
|
|
20
|
+
*/
|
|
21
|
+
strategy?: 'BFS' | 'DFS';
|
|
22
|
+
/**
|
|
23
|
+
* 子节点字段名
|
|
24
|
+
* @default 'children'
|
|
25
|
+
*/
|
|
26
|
+
childrenKey?: string;
|
|
27
|
+
/**
|
|
28
|
+
* 是否启用严格模式比较(===)
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
31
|
+
strict?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* 是否启用字符串模糊匹配
|
|
34
|
+
* @default false
|
|
35
|
+
*/
|
|
36
|
+
fuzzyMatch?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* 是否返回所有匹配结果(否则返回第一个匹配)
|
|
39
|
+
* @default false
|
|
40
|
+
*/
|
|
41
|
+
returnAllMatches?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* 字符串匹配是否区分大小写
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
46
|
+
caseSensitive?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* 多条件匹配模式:AND(所有条件需满足)或OR(任一条件满足)
|
|
49
|
+
* @default 'AND'
|
|
50
|
+
*/
|
|
51
|
+
matchMode?: 'AND' | 'OR';
|
|
52
|
+
/**
|
|
53
|
+
* 字符串匹配是否允许空字符
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
56
|
+
allowEmptyString?: boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 树节点接口定义
|
|
60
|
+
*/
|
|
61
|
+
interface TreeNode {
|
|
62
|
+
/**
|
|
63
|
+
* 动态属性(任意键值对)
|
|
64
|
+
*/
|
|
65
|
+
[key: string]: unknown;
|
|
66
|
+
/**
|
|
67
|
+
* 子节点数组(可选)
|
|
68
|
+
*/
|
|
69
|
+
children?: TreeNode[];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 高级树搜索函数
|
|
73
|
+
* @param treeData 要搜索的树数据(必须是数组)
|
|
74
|
+
* @param searchCondition 搜索条件对象(键值对)
|
|
75
|
+
* @param options 搜索配置选项
|
|
76
|
+
* @returns 返回匹配的节点或节点数组(根据returnAllMatches决定)
|
|
77
|
+
* @throws 当参数不符合要求时抛出TypeError或Error
|
|
78
|
+
*/
|
|
79
|
+
declare function searchTree(treeData: TreeNode[], searchCondition: Record<string, ConditionValue>, options?: SearchOptions): TreeNode | TreeNode[] | null;
|
|
80
|
+
export default searchTree;
|
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
export namespace PRIMARY_COLOR_KEY_MAPPING {
|
|
2
|
+
namespace primary {
|
|
3
|
+
let label: string;
|
|
4
|
+
let key: string;
|
|
5
|
+
}
|
|
6
|
+
namespace success {
|
|
7
|
+
let label_1: string;
|
|
8
|
+
export { label_1 as label };
|
|
9
|
+
let key_1: string;
|
|
10
|
+
export { key_1 as key };
|
|
11
|
+
}
|
|
12
|
+
namespace warning {
|
|
13
|
+
let label_2: string;
|
|
14
|
+
export { label_2 as label };
|
|
15
|
+
let key_2: string;
|
|
16
|
+
export { key_2 as key };
|
|
17
|
+
}
|
|
18
|
+
namespace danger {
|
|
19
|
+
let label_3: string;
|
|
20
|
+
export { label_3 as label };
|
|
21
|
+
let key_3: string;
|
|
22
|
+
export { key_3 as key };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
1
25
|
export { default as compareColorByRange } from "./compareColorByRange";
|
|
2
26
|
export namespace blue {
|
|
3
27
|
namespace name {
|
|
@@ -59,11 +83,12 @@ export namespace gray {
|
|
|
59
83
|
export { value_3 as value };
|
|
60
84
|
}
|
|
61
85
|
export namespace grayPresets {
|
|
62
|
-
|
|
86
|
+
let key_4: string;
|
|
87
|
+
export { key_4 as key };
|
|
63
88
|
import name_4 = gray.name;
|
|
64
89
|
export { name_4 as name };
|
|
65
|
-
import
|
|
66
|
-
export { primary };
|
|
90
|
+
import primary_1 = gray.value;
|
|
91
|
+
export { primary_1 as primary };
|
|
67
92
|
export let light: TinyColor[];
|
|
68
93
|
export let dark: TinyColor[];
|
|
69
94
|
}
|
package/ui-color/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { TinyColor as e } from "../tinycolor/src/index.js";
|
|
2
2
|
import { default as Q } from "./compareColorByRange.js";
|
|
3
|
-
const c = 10,
|
|
3
|
+
const c = 10, f = {
|
|
4
4
|
name: { zh: "浪漫红", en: "red" },
|
|
5
5
|
value: "#F53F3F"
|
|
6
|
-
},
|
|
6
|
+
}, B = {
|
|
7
7
|
name: { zh: "晚秋红", en: "orangered" },
|
|
8
8
|
value: "#FF702E"
|
|
9
|
-
},
|
|
9
|
+
}, D = {
|
|
10
10
|
name: { zh: "活力橙", en: "orange" },
|
|
11
11
|
value: "#FFA500"
|
|
12
12
|
}, C = {
|
|
@@ -21,42 +21,42 @@ const c = 10, A = {
|
|
|
21
21
|
}, M = {
|
|
22
22
|
name: { zh: "仙野绿", en: "green" },
|
|
23
23
|
value: "#00B82B"
|
|
24
|
-
},
|
|
24
|
+
}, P = {
|
|
25
25
|
name: { zh: "碧涛青", en: "cyan" },
|
|
26
26
|
value: "#0BD0D0"
|
|
27
|
-
},
|
|
27
|
+
}, x = {
|
|
28
28
|
name: { zh: "海蔚蓝", en: "blue" },
|
|
29
29
|
value: "#2E8FFF"
|
|
30
|
-
},
|
|
30
|
+
}, R = {
|
|
31
31
|
name: { zh: "主题色(极致蓝)", en: "primary" },
|
|
32
32
|
value: "#1A5EFF"
|
|
33
|
-
},
|
|
33
|
+
}, G = {
|
|
34
34
|
name: { zh: "暗夜紫", en: "purple" },
|
|
35
35
|
value: "#7126D9"
|
|
36
|
-
},
|
|
36
|
+
}, L = {
|
|
37
37
|
name: { zh: "青春紫", en: "pinkpurple" },
|
|
38
38
|
value: "#D91AD9"
|
|
39
|
-
},
|
|
39
|
+
}, H = {
|
|
40
40
|
name: { zh: "品红", en: "magenta" },
|
|
41
41
|
value: "#FF299F"
|
|
42
42
|
}, s = {
|
|
43
43
|
name: { zh: "中性灰", en: "gray" },
|
|
44
44
|
value: "#6B6C6D"
|
|
45
|
-
},
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
}, I = [
|
|
46
|
+
f,
|
|
47
|
+
B,
|
|
48
|
+
D,
|
|
49
49
|
C,
|
|
50
50
|
b,
|
|
51
51
|
_,
|
|
52
52
|
M,
|
|
53
|
+
P,
|
|
53
54
|
x,
|
|
55
|
+
R,
|
|
54
56
|
G,
|
|
55
|
-
H,
|
|
56
57
|
L,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
], R = {
|
|
58
|
+
H
|
|
59
|
+
], N = {
|
|
60
60
|
key: s.name?.en ?? s.name?.zh ?? s.name,
|
|
61
61
|
name: s.name,
|
|
62
62
|
primary: s.value,
|
|
@@ -84,72 +84,79 @@ const c = 10, A = {
|
|
|
84
84
|
new e("#E4E6E8"),
|
|
85
85
|
new e("#E8EBEE")
|
|
86
86
|
]
|
|
87
|
-
},
|
|
88
|
-
const
|
|
87
|
+
}, S = I.map((n, l, h) => {
|
|
88
|
+
const t = n.name, a = t?.en ?? t?.zh ?? t, r = n.value;
|
|
89
89
|
return {
|
|
90
90
|
key: a,
|
|
91
|
-
name:
|
|
92
|
-
primary:
|
|
93
|
-
light:
|
|
94
|
-
dark:
|
|
91
|
+
name: t,
|
|
92
|
+
primary: r,
|
|
93
|
+
light: T({ color: r, length: c }),
|
|
94
|
+
dark: Y({ color: r, length: c })
|
|
95
95
|
};
|
|
96
|
-
}).concat([
|
|
97
|
-
function
|
|
98
|
-
const { length: l, color:
|
|
99
|
-
let u = new e(
|
|
100
|
-
const w = u.toHsv(),
|
|
101
|
-
let
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
let
|
|
105
|
-
return
|
|
106
|
-
h:
|
|
107
|
-
s:
|
|
108
|
-
v
|
|
96
|
+
}).concat([N]);
|
|
97
|
+
function z(n = {}) {
|
|
98
|
+
const { length: l, color: h, level: t } = n, a = (l ?? c) / 2 + 1, r = t ?? a;
|
|
99
|
+
let u = new e(h);
|
|
100
|
+
const w = u.toHsv(), F = w.h, o = w.s, m = w.v, y = F === 0 && o === 0, E = r < a, g = Math.abs(a - r), A = 1, p = 0.1;
|
|
101
|
+
let i = o;
|
|
102
|
+
i > p && (E ? i = o - (o - p) / (a - 1) * g : i = o + (A - o) / (a - 1) * g), y && (i = o);
|
|
103
|
+
const d = y ? 0.97 : 1, k = 0.1;
|
|
104
|
+
let v = m;
|
|
105
|
+
return v > k && (E ? v = m + (d - m) / (a - 1) * g : v = m - (m - k) / (a - 1) * g), u = new e({
|
|
106
|
+
h: F,
|
|
107
|
+
s: i,
|
|
108
|
+
v
|
|
109
109
|
}), n.dark && (u = u.darken(n.amount ?? 10)), u;
|
|
110
110
|
}
|
|
111
|
-
function
|
|
112
|
-
return
|
|
111
|
+
function O(n = {}) {
|
|
112
|
+
return z({ ...n, dark: !0 });
|
|
113
113
|
}
|
|
114
|
-
function
|
|
114
|
+
function T(n = {}) {
|
|
115
115
|
const { length: l } = n;
|
|
116
|
-
return Array.from(new Array(l ?? c), (
|
|
117
|
-
const
|
|
118
|
-
return
|
|
116
|
+
return Array.from(new Array(l ?? c), (t, a) => {
|
|
117
|
+
const r = a + 1;
|
|
118
|
+
return z({ ...n, level: r });
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
|
-
function
|
|
121
|
+
function Y(n = {}) {
|
|
122
122
|
const { length: l } = n;
|
|
123
|
-
return Array.from(new Array(l ?? c), (
|
|
124
|
-
const
|
|
125
|
-
return
|
|
123
|
+
return Array.from(new Array(l ?? c), (t, a) => {
|
|
124
|
+
const r = a + 1;
|
|
125
|
+
return O({
|
|
126
126
|
...n,
|
|
127
|
-
level: c -
|
|
127
|
+
level: c - r + 1
|
|
128
128
|
});
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
|
+
const j = {
|
|
132
|
+
primary: { label: "主色", key: "primary" },
|
|
133
|
+
success: { label: "成功色", key: "green" },
|
|
134
|
+
warning: { label: "警示色", key: "orange" },
|
|
135
|
+
danger: { label: "错误色", key: "red" }
|
|
136
|
+
};
|
|
131
137
|
export {
|
|
132
138
|
c as LENGTH,
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
139
|
+
j as PRIMARY_COLOR_KEY_MAPPING,
|
|
140
|
+
x as blue,
|
|
141
|
+
S as colorPresets,
|
|
142
|
+
I as colors,
|
|
136
143
|
Q as compareColorByRange,
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
144
|
+
P as cyan,
|
|
145
|
+
T as generate,
|
|
146
|
+
Y as generateDark,
|
|
140
147
|
C as gold,
|
|
141
148
|
s as gray,
|
|
142
|
-
|
|
149
|
+
N as grayPresets,
|
|
143
150
|
M as green,
|
|
144
151
|
_ as lime,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
H as magenta,
|
|
153
|
+
D as orange,
|
|
154
|
+
B as orangered,
|
|
155
|
+
z as palette,
|
|
156
|
+
O as paletteDark,
|
|
157
|
+
L as pinkpurple,
|
|
158
|
+
R as primary,
|
|
159
|
+
G as purple,
|
|
160
|
+
f as red,
|
|
154
161
|
b as yellow
|
|
155
162
|
};
|
package/uiColor.js
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
1
|
import "./tinycolor/src/index.js";
|
|
2
2
|
import { default as o } from "./ui-color/compareColorByRange.js";
|
|
3
|
-
import { LENGTH as t,
|
|
3
|
+
import { LENGTH as t, PRIMARY_COLOR_KEY_MAPPING as p, blue as g, colorPresets as n, colors as m, cyan as s, generate as y, generateDark as P, gold as c, gray as d, grayPresets as i, green as u, lime as R, magenta as f, orange as k, orangered as _, palette as x, paletteDark as A, pinkpurple as C, primary as D, purple as E, red as G, yellow as I } from "./ui-color/index.js";
|
|
4
4
|
export {
|
|
5
5
|
t as LENGTH,
|
|
6
|
-
p as
|
|
7
|
-
g as
|
|
8
|
-
n as
|
|
6
|
+
p as PRIMARY_COLOR_KEY_MAPPING,
|
|
7
|
+
g as blue,
|
|
8
|
+
n as colorPresets,
|
|
9
|
+
m as colors,
|
|
9
10
|
o as compareColorByRange,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
s as cyan,
|
|
12
|
+
y as generate,
|
|
13
|
+
P as generateDark,
|
|
13
14
|
c as gold,
|
|
14
15
|
d as gray,
|
|
15
16
|
i as grayPresets,
|
|
16
17
|
u as green,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
R as lime,
|
|
19
|
+
f as magenta,
|
|
20
|
+
k as orange,
|
|
21
|
+
_ as orangered,
|
|
22
|
+
x as palette,
|
|
23
|
+
A as paletteDark,
|
|
24
|
+
C as pinkpurple,
|
|
25
|
+
D as primary,
|
|
26
|
+
E as purple,
|
|
27
|
+
G as red,
|
|
28
|
+
I as yellow
|
|
28
29
|
};
|
package/tree/searchTree.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
function p(o, i, a = {}) {
|
|
2
|
-
const {
|
|
3
|
-
strategy: f = "BFS",
|
|
4
|
-
childrenKey: c = "children",
|
|
5
|
-
strict: u = !1
|
|
6
|
-
} = a;
|
|
7
|
-
if (!Array.isArray(o))
|
|
8
|
-
throw new TypeError("treeData must be an array");
|
|
9
|
-
if (typeof i != "object" || i === null)
|
|
10
|
-
throw new TypeError("searchCondition must be an object");
|
|
11
|
-
const t = [...o], l = (e) => {
|
|
12
|
-
for (const r in i) {
|
|
13
|
-
if (!Object.prototype.hasOwnProperty.call(e, r))
|
|
14
|
-
return !1;
|
|
15
|
-
const n = i[r], s = e[r];
|
|
16
|
-
if (u) {
|
|
17
|
-
if (s !== n)
|
|
18
|
-
return !1;
|
|
19
|
-
} else if (n instanceof RegExp) {
|
|
20
|
-
if (typeof s != "string" || !n.test(s))
|
|
21
|
-
return !1;
|
|
22
|
-
} else if (typeof n == "function") {
|
|
23
|
-
if (!n(s))
|
|
24
|
-
return !1;
|
|
25
|
-
} else if (s != n)
|
|
26
|
-
return !1;
|
|
27
|
-
}
|
|
28
|
-
return !0;
|
|
29
|
-
};
|
|
30
|
-
if (f === "BFS")
|
|
31
|
-
for (; t.length > 0; ) {
|
|
32
|
-
const e = t.shift();
|
|
33
|
-
if (!e) continue;
|
|
34
|
-
if (l(e))
|
|
35
|
-
return e;
|
|
36
|
-
const r = e[c];
|
|
37
|
-
Array.isArray(r) && t.push(...r);
|
|
38
|
-
}
|
|
39
|
-
else if (f === "DFS")
|
|
40
|
-
for (; t.length > 0; ) {
|
|
41
|
-
const e = t.pop();
|
|
42
|
-
if (!e) continue;
|
|
43
|
-
if (l(e))
|
|
44
|
-
return e;
|
|
45
|
-
const r = e[c];
|
|
46
|
-
Array.isArray(r) && t.push(...r.slice().reverse());
|
|
47
|
-
}
|
|
48
|
-
else
|
|
49
|
-
throw new Error('Invalid strategy. Use "BFS" or "DFS"');
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
export {
|
|
53
|
-
p as default
|
|
54
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
type Primitive = string | number | boolean | symbol | null | undefined;
|
|
2
|
-
type ConditionValue<T = unknown> = Primitive | ((value: T) => boolean) | RegExp;
|
|
3
|
-
interface SearchOptions {
|
|
4
|
-
strategy?: 'BFS' | 'DFS';
|
|
5
|
-
childrenKey?: string;
|
|
6
|
-
strict?: boolean;
|
|
7
|
-
}
|
|
8
|
-
interface TreeNode {
|
|
9
|
-
[key: string]: unknown;
|
|
10
|
-
children?: TreeNode[];
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* 非递归树搜索算法
|
|
14
|
-
* @param {TreeNode[]} treeData - 树数据
|
|
15
|
-
* @param {Record<string, ConditionValue>} searchCondition - 搜索条件对象
|
|
16
|
-
* @param {SearchOptions} [options={}] - 配置选项
|
|
17
|
-
* @returns {TreeNode | null} 找到的节点或null
|
|
18
|
-
*/
|
|
19
|
-
declare function searchTree(treeData: TreeNode[], searchCondition: Record<string, ConditionValue>, options?: SearchOptions): TreeNode | null;
|
|
20
|
-
export default searchTree;
|