@vope/utils 1.6.0-bate.2 → 1.6.0-bate.3
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/clamp.d.ts +4 -0
- package/dist/clamp.mjs +11 -0
- package/dist/classnames.d.ts +7 -0
- package/dist/classnames.mjs +17 -0
- package/dist/compare/version.d.ts +5 -0
- package/dist/compare/version.mjs +15 -0
- package/dist/compare/weak-equal.d.ts +4 -0
- package/dist/compare/weak-equal.mjs +33 -0
- package/dist/convert/json.d.ts +12 -0
- package/dist/convert/json.mjs +7 -0
- package/dist/convert/object.d.ts +12 -0
- package/dist/convert/object.mjs +7 -0
- package/dist/convert/strings.d.ts +6 -0
- package/dist/convert/strings.mjs +7 -0
- package/dist/desens.d.ts +40 -0
- package/dist/desens.mjs +51 -0
- package/dist/encoding.d.ts +9 -0
- package/dist/encoding.mjs +56 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +1361 -0
- package/dist/index.mjs +73 -0
- package/dist/input-regex.d.ts +12 -0
- package/dist/input-regex.mjs +8 -0
- package/dist/is/class.d.ts +4 -0
- package/dist/is/class.mjs +22 -0
- package/dist/is/empty.d.ts +4 -0
- package/dist/is/empty.mjs +5 -0
- package/dist/is/key.d.ts +4 -0
- package/dist/is/key.mjs +4 -0
- package/dist/is/null.d.ts +4 -0
- package/dist/is/null.mjs +4 -0
- package/dist/load/image.d.ts +5 -0
- package/dist/load/image.mjs +11 -0
- package/dist/memory/basic.d.ts +79 -0
- package/dist/memory/basic.mjs +167 -0
- package/dist/memory/list.d.ts +8 -0
- package/dist/memory/list.mjs +12 -0
- package/dist/memory/power.d.ts +8 -0
- package/dist/memory/power.mjs +13 -0
- package/dist/memory/simple.d.ts +60 -0
- package/dist/memory/simple.mjs +94 -0
- package/dist/neo4j-anchors.d.ts +50 -0
- package/dist/neo4j-anchors.mjs +169 -0
- package/dist/neo4j.d.ts +82 -0
- package/dist/neo4j.mjs +161 -0
- package/dist/once.d.ts +6 -0
- package/dist/once.mjs +8 -0
- package/dist/parse/num.d.ts +8 -0
- package/dist/parse/num.mjs +31 -0
- package/dist/power/decon.d.ts +9 -0
- package/dist/power/decon.mjs +22 -0
- package/dist/rotate/angle.d.ts +8 -0
- package/dist/rotate/angle.mjs +5 -0
- package/dist/rotate/rad.d.ts +8 -0
- package/dist/rotate/rad.mjs +11 -0
- package/dist/serialize/url-params.d.ts +43 -0
- package/dist/serialize/url-params.mjs +53 -0
- package/dist/storage/offline.d.ts +51 -0
- package/dist/style/css.d.ts +9 -0
- package/dist/style/css.mjs +25 -0
- package/dist/subscriber.d.ts +11 -0
- package/dist/subscriber.mjs +64 -0
- package/dist/table/flex.d.ts +43 -0
- package/dist/table/flex.mjs +96 -0
- package/dist/union.d.ts +34 -0
- package/dist/union.mjs +47 -0
- package/dist/url/join.d.ts +4 -0
- package/dist/url/join.mjs +9 -0
- package/dist/url/params.d.ts +8 -0
- package/dist/url/params.mjs +8 -0
- package/dist/wait.d.ts +4 -0
- package/dist/wait.mjs +4 -0
- package/package.json +3 -4
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { clamp } from "./clamp";
|
|
2
|
+
import { classnames } from "./classnames";
|
|
3
|
+
import { compareVersion } from "./compare/version";
|
|
4
|
+
import { deepWeakEqual } from "./compare/weak-equal";
|
|
5
|
+
import { hash8json } from "./convert/json";
|
|
6
|
+
import { hash8object } from "./convert/object";
|
|
7
|
+
import { hash8strings } from "./convert/strings";
|
|
8
|
+
import { desensEncrypt, desensDecrypt, desensReplace } from "./desens";
|
|
9
|
+
import { getEncoding } from "./encoding";
|
|
10
|
+
import { inputRegex } from "./input-regex";
|
|
11
|
+
import { isClass } from "./is/class";
|
|
12
|
+
import { isEmpty } from "./is/empty";
|
|
13
|
+
import { isKey } from "./is/key";
|
|
14
|
+
import { isNull } from "./is/null";
|
|
15
|
+
import { loadImage } from "./load/image";
|
|
16
|
+
import { MemoryBasic } from "./memory/basic";
|
|
17
|
+
import { MemoryList } from "./memory/list";
|
|
18
|
+
import { MemoryPower } from "./memory/power";
|
|
19
|
+
import { MemorySimple } from "./memory/simple";
|
|
20
|
+
import { default as default2 } from "./neo4j-anchors";
|
|
21
|
+
import { default as default3 } from "./neo4j";
|
|
22
|
+
import { once } from "./once";
|
|
23
|
+
import { parseNum } from "./parse/num";
|
|
24
|
+
import { deconPowersSum } from "./power/decon";
|
|
25
|
+
import { rotateAngle } from "./rotate/angle";
|
|
26
|
+
import { rotateRad } from "./rotate/rad";
|
|
27
|
+
import { cubeURLParams, flatURLParams } from "./serialize/url-params";
|
|
28
|
+
import { css } from "./style/css";
|
|
29
|
+
import { default as default4 } from "./subscriber";
|
|
30
|
+
import { FlexTable } from "./table/flex";
|
|
31
|
+
import { Union } from "./union";
|
|
32
|
+
import { joinPaths } from "./url/join";
|
|
33
|
+
import { connectURLParams } from "./url/params";
|
|
34
|
+
import { wait } from "./wait";
|
|
35
|
+
export {
|
|
36
|
+
FlexTable,
|
|
37
|
+
MemoryBasic,
|
|
38
|
+
MemoryList,
|
|
39
|
+
MemoryPower,
|
|
40
|
+
MemorySimple,
|
|
41
|
+
default3 as Neo4j,
|
|
42
|
+
default2 as Neo4jAhchors,
|
|
43
|
+
default4 as Subscriber,
|
|
44
|
+
Union,
|
|
45
|
+
clamp,
|
|
46
|
+
classnames,
|
|
47
|
+
compareVersion,
|
|
48
|
+
connectURLParams,
|
|
49
|
+
css,
|
|
50
|
+
cubeURLParams,
|
|
51
|
+
deconPowersSum,
|
|
52
|
+
deepWeakEqual,
|
|
53
|
+
desensDecrypt,
|
|
54
|
+
desensEncrypt,
|
|
55
|
+
desensReplace,
|
|
56
|
+
flatURLParams,
|
|
57
|
+
getEncoding,
|
|
58
|
+
hash8json,
|
|
59
|
+
hash8object,
|
|
60
|
+
hash8strings,
|
|
61
|
+
inputRegex,
|
|
62
|
+
isClass,
|
|
63
|
+
isEmpty,
|
|
64
|
+
isKey,
|
|
65
|
+
isNull,
|
|
66
|
+
joinPaths,
|
|
67
|
+
loadImage,
|
|
68
|
+
once,
|
|
69
|
+
parseNum,
|
|
70
|
+
rotateAngle,
|
|
71
|
+
rotateRad,
|
|
72
|
+
wait
|
|
73
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 处理输入文本中的特殊字符,用于转换正则表达式
|
|
3
|
+
* @param text
|
|
4
|
+
* @param flags 表示输出正则表达式
|
|
5
|
+
*/
|
|
6
|
+
export declare function inputRegex(text: string, flags?: string): RegExp;
|
|
7
|
+
/**
|
|
8
|
+
* 处理输入文本中的特殊字符,用于转换正则表达式
|
|
9
|
+
* @param text
|
|
10
|
+
* @param flags 表示输出字符串,该字符串将作为正则表达式的一部分
|
|
11
|
+
*/
|
|
12
|
+
export declare function inputRegex(text: string, flags: false): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const RE_REGEX = /[$()*+.[?\\^{|]/g;
|
|
2
|
+
const RE_STRING = /[$()*+.[?\\^{|-]/g;
|
|
3
|
+
function inputRegex(text, flags) {
|
|
4
|
+
return flags === false ? text.replace(RE_STRING, ($0) => "\\" + $0) : new RegExp(text.replace(RE_REGEX, ($0) => "\\" + $0), flags);
|
|
5
|
+
}
|
|
6
|
+
export {
|
|
7
|
+
inputRegex
|
|
8
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const re_anonymous = /^function\s+\(|^function\s+anonymous\(/;
|
|
2
|
+
const re_function = /^function\s+[A-Z]/;
|
|
3
|
+
const re_this = /\b\(this\b|\bthis[\.\[]\b/;
|
|
4
|
+
const re_check = /classCallCheck\(this/;
|
|
5
|
+
const re_default = /^function\sdefault_\d+\s*\(/;
|
|
6
|
+
const isClass = (value, strict = true) => {
|
|
7
|
+
if (typeof value !== "function") return false;
|
|
8
|
+
const proto = value.prototype;
|
|
9
|
+
if (!proto || proto.constructor !== value) return false;
|
|
10
|
+
const str = value.toString();
|
|
11
|
+
if (str.slice(0, 5) === "class" || Object.getOwnPropertyNames(proto).length >= 2) return true;
|
|
12
|
+
if (re_anonymous.test(str)) return false;
|
|
13
|
+
if (strict && re_function.test(str)) return true;
|
|
14
|
+
if (re_this.test(str)) {
|
|
15
|
+
if (!strict || re_check.test(str)) return true;
|
|
16
|
+
return re_default.test(str);
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
isClass
|
|
22
|
+
};
|
package/dist/is/key.d.ts
ADDED
package/dist/is/key.mjs
ADDED
package/dist/is/null.mjs
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type Memory } from './type';
|
|
2
|
+
interface Config<Reactor> {
|
|
3
|
+
/**
|
|
4
|
+
* 定义数据如何挂载到存储中
|
|
5
|
+
* @param index 当前存入数据对应的角标
|
|
6
|
+
* @param reactor 当前存入数据对应存储单元
|
|
7
|
+
*/
|
|
8
|
+
mount(index: number, reactor?: Reactor): Reactor;
|
|
9
|
+
/**
|
|
10
|
+
* 定义存储单元和存储关系
|
|
11
|
+
* @param reactor 存储单元
|
|
12
|
+
*/
|
|
13
|
+
reflex(reactor: Reactor): number[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 分类存储(通过继承,可用于拓展存储方式)
|
|
17
|
+
*/
|
|
18
|
+
export declare class MemoryBasic<T, Reactor, Type extends Memory.Type> {
|
|
19
|
+
#private;
|
|
20
|
+
protected key: Memory.Pitch<T, Type>;
|
|
21
|
+
protected list: T[];
|
|
22
|
+
protected memorys: Map<Type, Reactor>;
|
|
23
|
+
/**
|
|
24
|
+
* 返回存储长度
|
|
25
|
+
*/
|
|
26
|
+
get size(): number;
|
|
27
|
+
/**
|
|
28
|
+
* @param key 用于对数据进行分类的key
|
|
29
|
+
* @param config
|
|
30
|
+
*/
|
|
31
|
+
constructor(key: Memory.Pitch<T, Type>, config: Config<Reactor>);
|
|
32
|
+
protected getType(data: T): Type;
|
|
33
|
+
push(...list: T[]): this;
|
|
34
|
+
/**
|
|
35
|
+
* 返回位于指定索引处的项
|
|
36
|
+
*/
|
|
37
|
+
at(index: number): T | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* 遍历所有存储数据(按入栈顺序)
|
|
40
|
+
*/
|
|
41
|
+
forEach(callback: (data: T, index: number) => void): this;
|
|
42
|
+
/**
|
|
43
|
+
* 遍历所有存储类型
|
|
44
|
+
*/
|
|
45
|
+
forType(callback: (data: T[], type: Type) => void): this;
|
|
46
|
+
/**
|
|
47
|
+
* some(按入栈顺序)
|
|
48
|
+
*/
|
|
49
|
+
some(callback: (data: T, index: number) => boolean): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* map(按入栈顺序)
|
|
52
|
+
*/
|
|
53
|
+
map<V>(callback: (data: T, index: number) => V): V[];
|
|
54
|
+
/**
|
|
55
|
+
* reduce(按入栈顺序)
|
|
56
|
+
*/
|
|
57
|
+
reduce<V>(callback: (previousValue: V, currentValue: T, currentIndex: number) => V, initialValue: V): V;
|
|
58
|
+
/**
|
|
59
|
+
* 判断存储是否包含指定类型
|
|
60
|
+
*/
|
|
61
|
+
includes(type: Type): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* 获取指定类型存储数据
|
|
64
|
+
*/
|
|
65
|
+
get(type: Type): T[] | null;
|
|
66
|
+
/**
|
|
67
|
+
* 删除指定存储数据
|
|
68
|
+
*/
|
|
69
|
+
delete(data: T): this;
|
|
70
|
+
/**
|
|
71
|
+
* 删除指定类型存储数据
|
|
72
|
+
*/
|
|
73
|
+
deleteType(type: Type): this;
|
|
74
|
+
/**
|
|
75
|
+
* 清理存储
|
|
76
|
+
*/
|
|
77
|
+
clear(): void;
|
|
78
|
+
}
|
|
79
|
+
export {};
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { hash8strings } from "../convert/strings";
|
|
2
|
+
class MemoryBasic {
|
|
3
|
+
/**
|
|
4
|
+
* @param key 用于对数据进行分类的key
|
|
5
|
+
* @param config
|
|
6
|
+
*/
|
|
7
|
+
constructor(key, config) {
|
|
8
|
+
this.key = key;
|
|
9
|
+
this.#mount = config.mount;
|
|
10
|
+
this.#reflex = config.reflex;
|
|
11
|
+
}
|
|
12
|
+
#mount;
|
|
13
|
+
#reflex;
|
|
14
|
+
list = [];
|
|
15
|
+
memorys = /* @__PURE__ */ new Map();
|
|
16
|
+
/**
|
|
17
|
+
* 返回存储长度
|
|
18
|
+
*/
|
|
19
|
+
get size() {
|
|
20
|
+
return this.list.length;
|
|
21
|
+
}
|
|
22
|
+
getType(data) {
|
|
23
|
+
const { key } = this;
|
|
24
|
+
return typeof key === "function" ? key(data) : data[key];
|
|
25
|
+
}
|
|
26
|
+
push(...list) {
|
|
27
|
+
const { memorys } = this;
|
|
28
|
+
list.forEach((data) => {
|
|
29
|
+
const type = this.getType(data);
|
|
30
|
+
const memory = memorys.get(type);
|
|
31
|
+
const index = this.list.push(data) - 1;
|
|
32
|
+
const result = this.#mount(index, memory);
|
|
33
|
+
memory === result || memorys.set(type, result);
|
|
34
|
+
});
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 返回位于指定索引处的项
|
|
39
|
+
*/
|
|
40
|
+
at(index) {
|
|
41
|
+
const { list } = this;
|
|
42
|
+
if (index < 0) {
|
|
43
|
+
index += list.length;
|
|
44
|
+
}
|
|
45
|
+
return this.list.at(index);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 遍历所有存储数据(按入栈顺序)
|
|
49
|
+
*/
|
|
50
|
+
forEach(callback) {
|
|
51
|
+
this.list.forEach(callback);
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 遍历所有存储类型
|
|
56
|
+
*/
|
|
57
|
+
forType(callback) {
|
|
58
|
+
const { memorys, list } = this;
|
|
59
|
+
for (const [type, memory] of memorys) {
|
|
60
|
+
const caches = this.#reflex(memory).map((index) => list[index]);
|
|
61
|
+
callback(caches, type);
|
|
62
|
+
}
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* some(按入栈顺序)
|
|
67
|
+
*/
|
|
68
|
+
some(callback) {
|
|
69
|
+
return this.list.some(callback);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* map(按入栈顺序)
|
|
73
|
+
*/
|
|
74
|
+
map(callback) {
|
|
75
|
+
return this.list.map(callback);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* reduce(按入栈顺序)
|
|
79
|
+
*/
|
|
80
|
+
reduce(callback, initialValue) {
|
|
81
|
+
return this.list.reduce(callback, initialValue);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 判断存储是否包含指定类型
|
|
85
|
+
*/
|
|
86
|
+
includes(type) {
|
|
87
|
+
return this.memorys.has(type);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 获取指定类型存储数据
|
|
91
|
+
*/
|
|
92
|
+
get(type) {
|
|
93
|
+
const memory = this.memorys.get(type);
|
|
94
|
+
return memory === void 0 ? null : this.#reflex(memory).map((count) => this.list[count]);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 删除指定存储数据
|
|
98
|
+
*/
|
|
99
|
+
delete(data) {
|
|
100
|
+
const { memorys, list } = this;
|
|
101
|
+
let index = -1;
|
|
102
|
+
if (!list.some((value, i) => {
|
|
103
|
+
if (data === value) {
|
|
104
|
+
index = i;
|
|
105
|
+
list.splice(index, 1);
|
|
106
|
+
const type = this.getType(value);
|
|
107
|
+
const memory = this.#reflex(memorys.get(type));
|
|
108
|
+
if (memory.length === 1) {
|
|
109
|
+
memorys.delete(type);
|
|
110
|
+
} else {
|
|
111
|
+
memory.some((count, j) => {
|
|
112
|
+
if (count === i) {
|
|
113
|
+
memory.splice(j, 1);
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
})) return this;
|
|
121
|
+
for (const [type, target] of memorys) {
|
|
122
|
+
const memory = this.#reflex(target);
|
|
123
|
+
memory.forEach((value, i) => {
|
|
124
|
+
if (value >= index) {
|
|
125
|
+
memory[i] = value - 1;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
if (memory !== target) {
|
|
129
|
+
let reactor;
|
|
130
|
+
memory.forEach((count) => {
|
|
131
|
+
reactor = this.#mount(count, reactor);
|
|
132
|
+
});
|
|
133
|
+
memorys.set(type, reactor);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* 删除指定类型存储数据
|
|
140
|
+
*/
|
|
141
|
+
deleteType(type) {
|
|
142
|
+
const { memorys, list } = this;
|
|
143
|
+
if (!memorys.has(type)) return this;
|
|
144
|
+
const local = hash8strings(this.#reflex(memorys.get(type)));
|
|
145
|
+
const Memory = this.constructor;
|
|
146
|
+
const imitator = new Memory(this.key, {
|
|
147
|
+
mount: this.#mount,
|
|
148
|
+
reflex: this.#reflex
|
|
149
|
+
});
|
|
150
|
+
list.forEach((data, index) => {
|
|
151
|
+
index in local || imitator.push(data);
|
|
152
|
+
});
|
|
153
|
+
this.list = imitator.list;
|
|
154
|
+
this.memorys = imitator.memorys;
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* 清理存储
|
|
159
|
+
*/
|
|
160
|
+
clear() {
|
|
161
|
+
this.list = [];
|
|
162
|
+
this.memorys.clear();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
export {
|
|
166
|
+
MemoryBasic
|
|
167
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MemoryBasic } from './basic';
|
|
2
|
+
import { type Memory } from './type';
|
|
3
|
+
/**
|
|
4
|
+
* 分类存储(基于普通的键值存储)
|
|
5
|
+
*/
|
|
6
|
+
export declare class MemoryList<T, Type extends Memory.Type = Memory.Type> extends MemoryBasic<T, number[], Type> {
|
|
7
|
+
constructor(key: Memory.Pitch<T, Type>);
|
|
8
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MemoryBasic } from "./basic";
|
|
2
|
+
class MemoryList extends MemoryBasic {
|
|
3
|
+
constructor(key) {
|
|
4
|
+
super(key, {
|
|
5
|
+
mount: (index, reactor) => reactor ? (reactor.push(index), reactor) : [index],
|
|
6
|
+
reflex: (reactor) => reactor
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
MemoryList
|
|
12
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MemoryBasic } from './basic';
|
|
2
|
+
import { type Memory } from './type';
|
|
3
|
+
/**
|
|
4
|
+
* 分类存储(基于2的n次幂之和构建唯一键进行存储)
|
|
5
|
+
*/
|
|
6
|
+
export declare class MemoryPower<T, Type extends Memory.Type = Memory.Type> extends MemoryBasic<T, number, Type> {
|
|
7
|
+
constructor(key: Memory.Pitch<T, Type>);
|
|
8
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { deconPowersSum } from "../power/decon";
|
|
2
|
+
import { MemoryBasic } from "./basic";
|
|
3
|
+
class MemoryPower extends MemoryBasic {
|
|
4
|
+
constructor(key) {
|
|
5
|
+
super(key, {
|
|
6
|
+
mount: (index, reactor) => (reactor || 0) + 2 ** index,
|
|
7
|
+
reflex: (reactor) => deconPowersSum(reactor, "asc")
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
MemoryPower
|
|
13
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Assign } from '@vope/types';
|
|
2
|
+
import { MemoryBasic } from './basic';
|
|
3
|
+
import { type Memory } from './type';
|
|
4
|
+
type Transform<T, V> = {
|
|
5
|
+
[P in keyof T]: T[P] extends (...args: any) => any ? (...args: Parameters<T[P]>) => ReturnType<T[P]> extends T ? V : ReturnType<T[P]> : T[P];
|
|
6
|
+
};
|
|
7
|
+
type Basic<T, V, Type extends Memory.Type> = Assign<Transform<Omit<MemoryBasic<T, V, Type>, 'forType'>, MemorySimple<T, Type>>, {
|
|
8
|
+
get(type: Type): T | null;
|
|
9
|
+
at(index: number): T | undefined;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* 简易存储(不分类)
|
|
13
|
+
*/
|
|
14
|
+
export declare class MemorySimple<T, Type extends Memory.Type> implements Basic<T, number, Type> {
|
|
15
|
+
#private;
|
|
16
|
+
get size(): number;
|
|
17
|
+
constructor(key: Memory.Pitch<T, Type>);
|
|
18
|
+
/**
|
|
19
|
+
* 返回位于指定索引处的项
|
|
20
|
+
*/
|
|
21
|
+
at(index: number): T | undefined;
|
|
22
|
+
push(...list: T[]): this;
|
|
23
|
+
/**
|
|
24
|
+
* 获取指定类型存储数据
|
|
25
|
+
*/
|
|
26
|
+
get(type: Type): T | null;
|
|
27
|
+
/**
|
|
28
|
+
* 遍历所有存储数据(按入栈顺序)
|
|
29
|
+
*/
|
|
30
|
+
forEach(callback: (data: T, index: number) => void): this;
|
|
31
|
+
/**
|
|
32
|
+
* some(按入栈顺序)
|
|
33
|
+
*/
|
|
34
|
+
some(callback: (data: T, index: number) => boolean): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* map(按入栈顺序)
|
|
37
|
+
*/
|
|
38
|
+
map<V>(callback: (data: T, index: number) => V): V[];
|
|
39
|
+
/**
|
|
40
|
+
* reduce(按入栈顺序)
|
|
41
|
+
*/
|
|
42
|
+
reduce<V>(callback: (previousValue: V, currentValue: T, currentIndex: number) => V, initialValue: V): V;
|
|
43
|
+
/**
|
|
44
|
+
* 判断是否包含指定类型
|
|
45
|
+
*/
|
|
46
|
+
includes(type: Type): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* 删除指定存储数据
|
|
49
|
+
*/
|
|
50
|
+
delete(data: T): this;
|
|
51
|
+
/**
|
|
52
|
+
* 删除指定类型存储数据
|
|
53
|
+
*/
|
|
54
|
+
deleteType(type: Type): this;
|
|
55
|
+
/**
|
|
56
|
+
* 清理存储
|
|
57
|
+
*/
|
|
58
|
+
clear(): void;
|
|
59
|
+
}
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { MemoryBasic } from "./basic";
|
|
2
|
+
class MemorySimple {
|
|
3
|
+
#memory;
|
|
4
|
+
#key;
|
|
5
|
+
get size() {
|
|
6
|
+
return this.#memory.size;
|
|
7
|
+
}
|
|
8
|
+
constructor(key) {
|
|
9
|
+
this.#key = key;
|
|
10
|
+
this.#memory = new MemoryBasic(key, {
|
|
11
|
+
mount: (index) => index,
|
|
12
|
+
reflex: (reactor) => [reactor]
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
#getType(data) {
|
|
16
|
+
const key = this.#key;
|
|
17
|
+
return typeof key === "function" ? key(data) : data[key];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 返回位于指定索引处的项
|
|
21
|
+
*/
|
|
22
|
+
at(index) {
|
|
23
|
+
return this.#memory.at(index);
|
|
24
|
+
}
|
|
25
|
+
push(...list) {
|
|
26
|
+
const memory = this.#memory;
|
|
27
|
+
list.forEach((data) => {
|
|
28
|
+
memory.includes(this.#getType(data)) || memory.push(data);
|
|
29
|
+
});
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 获取指定类型存储数据
|
|
34
|
+
*/
|
|
35
|
+
get(type) {
|
|
36
|
+
const value = this.#memory.get(type);
|
|
37
|
+
if (value === null) return value;
|
|
38
|
+
return value.length ? value[0] : null;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 遍历所有存储数据(按入栈顺序)
|
|
42
|
+
*/
|
|
43
|
+
forEach(callback) {
|
|
44
|
+
this.#memory.forEach(callback);
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* some(按入栈顺序)
|
|
49
|
+
*/
|
|
50
|
+
some(callback) {
|
|
51
|
+
return this.#memory.some(callback);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* map(按入栈顺序)
|
|
55
|
+
*/
|
|
56
|
+
map(callback) {
|
|
57
|
+
return this.#memory.map(callback);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* reduce(按入栈顺序)
|
|
61
|
+
*/
|
|
62
|
+
reduce(callback, initialValue) {
|
|
63
|
+
return this.#memory.reduce(callback, initialValue);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* 判断是否包含指定类型
|
|
67
|
+
*/
|
|
68
|
+
includes(type) {
|
|
69
|
+
return this.#memory.includes(type);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 删除指定存储数据
|
|
73
|
+
*/
|
|
74
|
+
delete(data) {
|
|
75
|
+
this.#memory.delete(data);
|
|
76
|
+
return this;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 删除指定类型存储数据
|
|
80
|
+
*/
|
|
81
|
+
deleteType(type) {
|
|
82
|
+
this.#memory.deleteType(type);
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 清理存储
|
|
87
|
+
*/
|
|
88
|
+
clear() {
|
|
89
|
+
this.#memory.clear();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export {
|
|
93
|
+
MemorySimple
|
|
94
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import Neo4j from './neo4j';
|
|
2
|
+
interface IBox {
|
|
3
|
+
centerX: number;
|
|
4
|
+
centerY: number;
|
|
5
|
+
}
|
|
6
|
+
interface Config {
|
|
7
|
+
/** 多边之间的间隔弧长 */
|
|
8
|
+
radOffsetRaidx?: number;
|
|
9
|
+
getBox(id: string): IBox;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 图布局之二阶贝塞尔曲线边锚点管理
|
|
13
|
+
*/
|
|
14
|
+
export default class Neo4jAhchors<INode extends object, IEdge extends object> {
|
|
15
|
+
#private;
|
|
16
|
+
protected neo4j: Neo4j<INode, IEdge>;
|
|
17
|
+
protected config: Config;
|
|
18
|
+
constructor(neo4j: Neo4j<INode, IEdge>, config: Config);
|
|
19
|
+
protected getDir(start: string, end: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* 设置多边间隔弧长
|
|
22
|
+
*/
|
|
23
|
+
setRaidx(value: number): void;
|
|
24
|
+
/**
|
|
25
|
+
* 当图数据准备好后调用
|
|
26
|
+
*/
|
|
27
|
+
read(): void;
|
|
28
|
+
protected calcPoints(edge: IEdge, index: number, total: number, type: 1 | -1): number[];
|
|
29
|
+
/**
|
|
30
|
+
* 获取指定节点上出入边连接点的坐标
|
|
31
|
+
*/
|
|
32
|
+
getPoints(id: string): number[][];
|
|
33
|
+
/**
|
|
34
|
+
* 查找边连接点的位置
|
|
35
|
+
*/
|
|
36
|
+
findAnchor(id: string): {
|
|
37
|
+
source: number;
|
|
38
|
+
target: number;
|
|
39
|
+
} | null;
|
|
40
|
+
/**
|
|
41
|
+
* 获取指定边控制点距离两端点连线的距离(可理解为控制边的弯曲程度)
|
|
42
|
+
* @description 返回值是一个相对值,需要乘以一个基数值(基数值应为负值,如-30)
|
|
43
|
+
*/
|
|
44
|
+
getOffset(id: string): number;
|
|
45
|
+
/**
|
|
46
|
+
* 清理数据
|
|
47
|
+
*/
|
|
48
|
+
clear(): void;
|
|
49
|
+
}
|
|
50
|
+
export {};
|