@vope/utils 1.6.0-bate.7 → 1.6.0
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.js +3 -23
- package/dist/classnames.js +7 -27
- package/dist/compare/version.js +3 -23
- package/dist/compare/weak-equal.js +5 -25
- package/dist/convert/json.js +3 -23
- package/dist/convert/object.js +3 -23
- package/dist/convert/strings.js +3 -23
- package/dist/desens.js +7 -27
- package/dist/encoding.js +3 -23
- package/dist/index.cjs.js +1265 -0
- package/dist/index.js +72 -102
- package/dist/input-regex.js +3 -23
- package/dist/is/class.js +3 -23
- package/dist/is/empty.js +4 -24
- package/dist/is/key.js +3 -23
- package/dist/is/null.js +3 -23
- package/dist/load/image.js +3 -23
- package/dist/memory/basic.js +5 -25
- package/dist/memory/list.js +5 -25
- package/dist/memory/power.js +7 -27
- package/dist/memory/simple.js +5 -25
- package/dist/neo4j-anchors.js +6 -26
- package/dist/neo4j.js +12 -32
- package/dist/once.js +3 -23
- package/dist/parse/num.js +5 -25
- package/dist/power/decon.js +3 -23
- package/dist/rotate/angle.js +4 -24
- package/dist/rotate/rad.js +3 -23
- package/dist/serialize/url-params.js +8 -28
- package/dist/style/css.js +7 -27
- package/dist/subscriber.js +5 -25
- package/dist/table/flex.js +3 -23
- package/dist/union.js +3 -23
- package/dist/url/join.js +3 -23
- package/dist/url/params.js +5 -25
- package/dist/wait.js +3 -23
- package/package.json +8 -8
- package/sub_storage/{offline.mjs → offline.cjs.js} +59 -27
- package/sub_storage/offline.js +15 -45
- package/sub_storage/package.json +2 -2
- package/dist/clamp.mjs +0 -11
- package/dist/classnames.mjs +0 -17
- package/dist/compare/version.mjs +0 -15
- package/dist/compare/weak-equal.mjs +0 -33
- package/dist/convert/json.mjs +0 -7
- package/dist/convert/object.mjs +0 -7
- package/dist/convert/strings.mjs +0 -7
- package/dist/desens.mjs +0 -51
- package/dist/encoding.mjs +0 -56
- package/dist/index.mjs +0 -73
- package/dist/input-regex.mjs +0 -8
- package/dist/is/class.mjs +0 -22
- package/dist/is/empty.mjs +0 -5
- package/dist/is/key.mjs +0 -4
- package/dist/is/null.mjs +0 -4
- package/dist/load/image.mjs +0 -11
- package/dist/memory/basic.mjs +0 -167
- package/dist/memory/list.mjs +0 -12
- package/dist/memory/power.mjs +0 -13
- package/dist/memory/simple.mjs +0 -94
- package/dist/neo4j-anchors.mjs +0 -169
- package/dist/neo4j.mjs +0 -161
- package/dist/once.mjs +0 -8
- package/dist/parse/num.mjs +0 -31
- package/dist/power/decon.mjs +0 -22
- package/dist/rotate/angle.mjs +0 -5
- package/dist/rotate/rad.mjs +0 -11
- package/dist/serialize/url-params.mjs +0 -53
- package/dist/style/css.mjs +0 -25
- package/dist/subscriber.mjs +0 -64
- package/dist/table/flex.mjs +0 -96
- package/dist/union.mjs +0 -47
- package/dist/url/join.mjs +0 -9
- package/dist/url/params.mjs +0 -8
- package/dist/wait.mjs +0 -4
package/dist/memory/basic.mjs
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/memory/list.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/memory/power.mjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/memory/simple.mjs
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/neo4j-anchors.mjs
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { rotateRad } from "./rotate/rad";
|
|
2
|
-
class Neo4jAhchors {
|
|
3
|
-
constructor(neo4j, config) {
|
|
4
|
-
this.neo4j = neo4j;
|
|
5
|
-
this.config = Object.assign({}, config);
|
|
6
|
-
}
|
|
7
|
-
config;
|
|
8
|
-
#anchors = {};
|
|
9
|
-
getDir(start, end) {
|
|
10
|
-
const { neo4j } = this;
|
|
11
|
-
return neo4j.dirKey({
|
|
12
|
-
[neo4j.sourceField]: start,
|
|
13
|
-
[neo4j.targetField]: end
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* 设置多边间隔弧长
|
|
18
|
-
*/
|
|
19
|
-
setRaidx(value) {
|
|
20
|
-
this.config.radOffsetRaidx = value;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* 当图数据准备好后调用
|
|
24
|
-
*/
|
|
25
|
-
read() {
|
|
26
|
-
const { neo4j } = this;
|
|
27
|
-
const { nodeField, edgeField, sourceField, targetField } = neo4j;
|
|
28
|
-
const anchors = {};
|
|
29
|
-
neo4j.nodes.forEach((node) => {
|
|
30
|
-
const nodeId = node[nodeField];
|
|
31
|
-
let count = 0;
|
|
32
|
-
[
|
|
33
|
-
neo4j.sources.get(nodeId),
|
|
34
|
-
neo4j.targets.get(nodeId)
|
|
35
|
-
].forEach((list, i) => {
|
|
36
|
-
if (!list) return;
|
|
37
|
-
let diffCount = 0;
|
|
38
|
-
let sameCount = 0;
|
|
39
|
-
list.forEach((edge) => {
|
|
40
|
-
const edgeId = edge[edgeField];
|
|
41
|
-
if (edge[sourceField] !== edge[targetField]) {
|
|
42
|
-
const anchor = anchors[edgeId] || (anchors[edgeId] = {});
|
|
43
|
-
anchor[i ? "target" : "source"] = count + diffCount++;
|
|
44
|
-
} else if (edgeId in anchors === false) {
|
|
45
|
-
anchors[edgeId] = {
|
|
46
|
-
source: sameCount,
|
|
47
|
-
target: sameCount++
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
count += diffCount;
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
this.#anchors = anchors;
|
|
55
|
-
}
|
|
56
|
-
calcPoints(edge, index, total, type) {
|
|
57
|
-
const { neo4j, config: { getBox, radOffsetRaidx = 0.3125 } } = this;
|
|
58
|
-
const source = getBox(edge[neo4j.sourceField]);
|
|
59
|
-
const target = getBox(edge[neo4j.targetField]);
|
|
60
|
-
const rad = Math.atan2(
|
|
61
|
-
(source.centerY - target.centerY) * type,
|
|
62
|
-
(source.centerX - target.centerX) * type
|
|
63
|
-
);
|
|
64
|
-
let point = rotateRad([0.5, 0], rad);
|
|
65
|
-
if (total !== 1) {
|
|
66
|
-
point = rotateRad(point, radOffsetRaidx * (total / 2 - 0.5 - index));
|
|
67
|
-
}
|
|
68
|
-
const [x, y] = point;
|
|
69
|
-
return [x + 0.5, 0.5 - y];
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* 获取指定节点上出入边连接点的坐标
|
|
73
|
-
*/
|
|
74
|
-
getPoints(id) {
|
|
75
|
-
const { neo4j } = this;
|
|
76
|
-
const { dirs, edgeField, sourceField, targetField } = neo4j;
|
|
77
|
-
const anchors = this.#anchors;
|
|
78
|
-
const points = [];
|
|
79
|
-
const caches = {};
|
|
80
|
-
neo4j.sources.get(id)?.forEach((edge) => {
|
|
81
|
-
const source = edge[sourceField];
|
|
82
|
-
const target = edge[targetField];
|
|
83
|
-
const direct = this.getDir(source, target);
|
|
84
|
-
const invert = this.getDir(target, source);
|
|
85
|
-
if (direct in caches) return;
|
|
86
|
-
const directs = dirs.get(direct) || [];
|
|
87
|
-
const inverts = dirs.get(invert) || [];
|
|
88
|
-
const directsLength = directs.length;
|
|
89
|
-
const invertsLength = inverts.length;
|
|
90
|
-
const total = directsLength + invertsLength;
|
|
91
|
-
directs.forEach((data, index) => {
|
|
92
|
-
points[anchors[data[edgeField]].source] = this.calcPoints(data, directsLength - 1 - index, total, -1);
|
|
93
|
-
});
|
|
94
|
-
caches[direct] = direct;
|
|
95
|
-
});
|
|
96
|
-
neo4j.targets.get(id)?.forEach((edge) => {
|
|
97
|
-
const source = edge[sourceField];
|
|
98
|
-
const target = edge[targetField];
|
|
99
|
-
const direct = this.getDir(source, target);
|
|
100
|
-
const invert = this.getDir(target, source);
|
|
101
|
-
if (direct in caches) return;
|
|
102
|
-
const directs = neo4j.dirs.get(direct) || [];
|
|
103
|
-
const inverts = neo4j.dirs.get(invert) || [];
|
|
104
|
-
const directsLength = directs.length;
|
|
105
|
-
const invertsLength = inverts.length;
|
|
106
|
-
const total = directsLength + invertsLength;
|
|
107
|
-
directs.forEach((data, index) => {
|
|
108
|
-
points[anchors[data[edgeField]].target] = this.calcPoints(data, invertsLength + index, total, 1);
|
|
109
|
-
});
|
|
110
|
-
caches[direct] = direct;
|
|
111
|
-
});
|
|
112
|
-
return points;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* 查找边连接点的位置
|
|
116
|
-
*/
|
|
117
|
-
findAnchor(id) {
|
|
118
|
-
const anchor = this.#anchors[id];
|
|
119
|
-
if (!anchor) return null;
|
|
120
|
-
return {
|
|
121
|
-
source: anchor.source || 0,
|
|
122
|
-
target: anchor.target || 0
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* 获取指定边控制点距离两端点连线的距离(可理解为控制边的弯曲程度)
|
|
127
|
-
* @description 返回值是一个相对值,需要乘以一个基数值(基数值应为负值,如-30)
|
|
128
|
-
*/
|
|
129
|
-
getOffset(id) {
|
|
130
|
-
const { neo4j } = this;
|
|
131
|
-
const edge = neo4j.edges.get(id);
|
|
132
|
-
if (!edge) return -1;
|
|
133
|
-
const { dirs, edgeField, sourceField, targetField } = neo4j;
|
|
134
|
-
const source = edge[sourceField];
|
|
135
|
-
const target = edge[targetField];
|
|
136
|
-
const directs = dirs.get(this.getDir(source, target)) || [];
|
|
137
|
-
const inverts = dirs.get(this.getDir(target, source)) || [];
|
|
138
|
-
let count = 0;
|
|
139
|
-
let index = 0;
|
|
140
|
-
[directs, inverts].some((list) => {
|
|
141
|
-
const result = list.some((data, i) => {
|
|
142
|
-
if (data[edgeField] === id) {
|
|
143
|
-
index = i + count;
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
count += list.length;
|
|
148
|
-
return result;
|
|
149
|
-
});
|
|
150
|
-
const directsSize = directs.length;
|
|
151
|
-
const invertsSize = inverts.length;
|
|
152
|
-
const total = directsSize + invertsSize;
|
|
153
|
-
if (total === 1) return -1;
|
|
154
|
-
if (directsSize === 0 || invertsSize === 0) {
|
|
155
|
-
return total / 2 - index - 0.5;
|
|
156
|
-
} else {
|
|
157
|
-
return Math.abs(directsSize - invertsSize) * (directsSize >= invertsSize ? 1 : -1) / 2 - index - 0.5;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* 清理数据
|
|
162
|
-
*/
|
|
163
|
-
clear() {
|
|
164
|
-
this.#anchors = {};
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
export {
|
|
168
|
-
Neo4jAhchors as default
|
|
169
|
-
};
|
package/dist/neo4j.mjs
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { hash8strings } from "./convert/strings";
|
|
2
|
-
import { MemoryList } from "./memory/list";
|
|
3
|
-
import { MemorySimple } from "./memory/simple";
|
|
4
|
-
class Neo4j {
|
|
5
|
-
#nPrimaryKey;
|
|
6
|
-
#ePrimaryKey;
|
|
7
|
-
#sourceKey;
|
|
8
|
-
#targetKey;
|
|
9
|
-
#dirKey;
|
|
10
|
-
#nodes;
|
|
11
|
-
#edges;
|
|
12
|
-
#sources;
|
|
13
|
-
#targets;
|
|
14
|
-
#dirs;
|
|
15
|
-
get nodeField() {
|
|
16
|
-
return this.#nPrimaryKey;
|
|
17
|
-
}
|
|
18
|
-
get edgeField() {
|
|
19
|
-
return this.#ePrimaryKey;
|
|
20
|
-
}
|
|
21
|
-
get sourceField() {
|
|
22
|
-
return this.#sourceKey;
|
|
23
|
-
}
|
|
24
|
-
get targetField() {
|
|
25
|
-
return this.#targetKey;
|
|
26
|
-
}
|
|
27
|
-
get dirKey() {
|
|
28
|
-
return this.#dirKey;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* 点视图
|
|
32
|
-
*/
|
|
33
|
-
nodes;
|
|
34
|
-
/**
|
|
35
|
-
* 边视图
|
|
36
|
-
*/
|
|
37
|
-
edges;
|
|
38
|
-
/**
|
|
39
|
-
* (边)出点视图
|
|
40
|
-
*/
|
|
41
|
-
sources;
|
|
42
|
-
/**
|
|
43
|
-
* (边)入点视图
|
|
44
|
-
*/
|
|
45
|
-
targets;
|
|
46
|
-
/**
|
|
47
|
-
* (边)方向视图
|
|
48
|
-
*/
|
|
49
|
-
dirs;
|
|
50
|
-
constructor(nodeList, edgeList, {
|
|
51
|
-
nid,
|
|
52
|
-
eid,
|
|
53
|
-
sourceKey,
|
|
54
|
-
targetKey,
|
|
55
|
-
dir = (edge) => edge[sourceKey] + "|" + edge[targetKey]
|
|
56
|
-
}) {
|
|
57
|
-
shield(this, "nodes", this.#nodes = new MemorySimple(this.#nPrimaryKey = nid));
|
|
58
|
-
shield(this, "edges", this.#edges = new MemorySimple(this.#ePrimaryKey = eid));
|
|
59
|
-
shield(this, "sources", this.#sources = new MemoryList(this.#sourceKey = sourceKey));
|
|
60
|
-
shield(this, "targets", this.#targets = new MemoryList(this.#targetKey = targetKey));
|
|
61
|
-
shield(this, "dirs", this.#dirs = new MemoryList(this.#dirKey = dir));
|
|
62
|
-
nodeList.forEach((node) => this.node("add", node));
|
|
63
|
-
edgeList.forEach((edge) => this.edge("add", edge));
|
|
64
|
-
}
|
|
65
|
-
node(type, value) {
|
|
66
|
-
const nodes = this.#nodes;
|
|
67
|
-
if (type === "add") {
|
|
68
|
-
nodes.push(value);
|
|
69
|
-
} else if (type === "delete") {
|
|
70
|
-
const node = nodes.get(value);
|
|
71
|
-
if (!node) return [];
|
|
72
|
-
nodes.delete(node);
|
|
73
|
-
const id = node[this.#nPrimaryKey];
|
|
74
|
-
const sourceKey = this.#sourceKey;
|
|
75
|
-
const targetKey = this.#targetKey;
|
|
76
|
-
const edges = this.#edges;
|
|
77
|
-
const sources = this.#sources;
|
|
78
|
-
const targets = this.#targets;
|
|
79
|
-
const dirs = this.#dirs;
|
|
80
|
-
const list = [];
|
|
81
|
-
sources.get(id)?.reduce((_, edge) => {
|
|
82
|
-
edges.delete(edge);
|
|
83
|
-
targets.delete(edge);
|
|
84
|
-
edge[sourceKey] === edge[targetKey] || dirs.delete(edge);
|
|
85
|
-
list.push(edge);
|
|
86
|
-
return true;
|
|
87
|
-
}, false) && sources.deleteType(id);
|
|
88
|
-
targets.get(id)?.reduce((_, edge) => {
|
|
89
|
-
edges.delete(edge);
|
|
90
|
-
sources.delete(edge);
|
|
91
|
-
edge[sourceKey] === edge[targetKey] || dirs.delete(edge);
|
|
92
|
-
list.push(edge);
|
|
93
|
-
return true;
|
|
94
|
-
}, false) && targets.deleteType(id);
|
|
95
|
-
return list;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
edge(type, value) {
|
|
99
|
-
const sourceKey = this.#sourceKey;
|
|
100
|
-
const targetKey = this.#targetKey;
|
|
101
|
-
const edges = this.#edges;
|
|
102
|
-
const sources = this.#sources;
|
|
103
|
-
const targets = this.#targets;
|
|
104
|
-
const dirs = this.#dirs;
|
|
105
|
-
if (type === "add") {
|
|
106
|
-
const edge = value;
|
|
107
|
-
edges.push(edge);
|
|
108
|
-
sources.push(edge);
|
|
109
|
-
targets.push(edge);
|
|
110
|
-
edge[sourceKey] === edge[targetKey] || dirs.push(edge);
|
|
111
|
-
} else if (type === "delete") {
|
|
112
|
-
const edge = edges.get(value);
|
|
113
|
-
if (!edge) return false;
|
|
114
|
-
edges.delete(edge);
|
|
115
|
-
sources.delete(edge);
|
|
116
|
-
targets.delete(edge);
|
|
117
|
-
edge[sourceKey] === edge[targetKey] || dirs.delete(edge);
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* 清理图管理数据
|
|
123
|
-
*/
|
|
124
|
-
clear() {
|
|
125
|
-
this.#nodes.clear();
|
|
126
|
-
this.#edges.clear();
|
|
127
|
-
this.#sources.clear();
|
|
128
|
-
this.#targets.clear();
|
|
129
|
-
this.#dirs.clear();
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
const shield_keys = hash8strings([
|
|
133
|
-
"push",
|
|
134
|
-
"delete",
|
|
135
|
-
"deleteType",
|
|
136
|
-
"clear"
|
|
137
|
-
]);
|
|
138
|
-
const shield = (obj, key, origin) => {
|
|
139
|
-
const proxy = new Proxy({}, {
|
|
140
|
-
get(target, p) {
|
|
141
|
-
if (p in shield_keys) return;
|
|
142
|
-
const value = origin[p];
|
|
143
|
-
if (typeof value === "function") {
|
|
144
|
-
return function(...args) {
|
|
145
|
-
const result = origin[p](...args);
|
|
146
|
-
return result === origin ? proxy : result;
|
|
147
|
-
};
|
|
148
|
-
} else {
|
|
149
|
-
return value;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
Object.defineProperty(obj, key, {
|
|
154
|
-
get() {
|
|
155
|
-
return proxy;
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
};
|
|
159
|
-
export {
|
|
160
|
-
Neo4j as default
|
|
161
|
-
};
|
package/dist/once.mjs
DELETED
package/dist/parse/num.mjs
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { isNumber } from "lodash-es";
|
|
2
|
-
const pow = Math.floor(Math.log10(Number.MAX_SAFE_INTEGER));
|
|
3
|
-
const re_num = /^([-+]?)0*(\d+)(?:(n)|(?:\.(\d+))?(?:[Ee]([-+]?)(\d+))?)$/;
|
|
4
|
-
const parseNum = (num) => {
|
|
5
|
-
if (isNumber(num) || typeof num === "bigint") return num;
|
|
6
|
-
const match = num.match(re_num);
|
|
7
|
-
if (!match) return Number.NaN;
|
|
8
|
-
const [, valueSymbol, integer, bigint, decimal, powSymbol, powValue] = match;
|
|
9
|
-
if (bigint === "n") return BigInt(valueSymbol + integer);
|
|
10
|
-
const powSize = integer.length - 1 + (powValue ? powSymbol === "-" ? -powValue : +powValue : 0);
|
|
11
|
-
if (powSize < pow || powSize === pow && +integer.slice(0, -1) < Number.MAX_SAFE_INTEGER / 10) return +num;
|
|
12
|
-
try {
|
|
13
|
-
const bigValue = BigInt(integer.slice(0, powSize + 1).padEnd(powSize + 1, "0"));
|
|
14
|
-
let smallValue;
|
|
15
|
-
if (decimal && powValue && powSymbol !== "-") {
|
|
16
|
-
const powNum = +powValue;
|
|
17
|
-
const effectDecimal = decimal.slice(0, Math.min(pow, powNum));
|
|
18
|
-
const tinyValue = decimal.length > pow && powNum > pow ? BigInt(+decimal.slice(pow, powNum)) * BigInt(10 ** Math.max(powNum - decimal.length, 0)) : BigInt(0);
|
|
19
|
-
smallValue = BigInt(effectDecimal) * BigInt(10 ** (powNum - effectDecimal.length)) + tinyValue;
|
|
20
|
-
} else {
|
|
21
|
-
smallValue = BigInt(0);
|
|
22
|
-
}
|
|
23
|
-
const value = bigValue + smallValue;
|
|
24
|
-
return valueSymbol === "-" ? value * BigInt(-1) : value;
|
|
25
|
-
} catch {
|
|
26
|
-
return Number.NaN;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
export {
|
|
30
|
-
parseNum
|
|
31
|
-
};
|
package/dist/power/decon.mjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const ERROR_MESSAGE = {
|
|
2
|
-
INT: "\u53C2\u6570\u5FC5\u987B\u662F\u6574\u6570",
|
|
3
|
-
MIN: "\u591A\u4E2A2\u7684\u6B63\u6574\u6570\u5E42(\u4E24\u4E24\u4E0D\u76F8\u7B49)\u4E4B\u548C\u5FC5\u5B9A\u5927\u4E8E\u7B49\u4E8E1"
|
|
4
|
-
};
|
|
5
|
-
const deconPowersSum = (sum, sort) => {
|
|
6
|
-
if (sum < 1) {
|
|
7
|
-
throw new Error(ERROR_MESSAGE.MIN);
|
|
8
|
-
} else if (sum !== Math.floor(sum)) {
|
|
9
|
-
throw new Error(ERROR_MESSAGE.INT);
|
|
10
|
-
}
|
|
11
|
-
const list = [];
|
|
12
|
-
let cache = sum;
|
|
13
|
-
while (cache) {
|
|
14
|
-
const power = Math.log2(cache) ^ 0;
|
|
15
|
-
list.push(power);
|
|
16
|
-
cache -= Math.pow(2, power);
|
|
17
|
-
}
|
|
18
|
-
return sort === "asc" ? list.reverse() : list;
|
|
19
|
-
};
|
|
20
|
-
export {
|
|
21
|
-
deconPowersSum
|
|
22
|
-
};
|
package/dist/rotate/angle.mjs
DELETED
package/dist/rotate/rad.mjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const rotateRad = (from, rad, visit = [0, 0]) => {
|
|
2
|
-
const x = from[0] - visit[0];
|
|
3
|
-
const y = from[1] - visit[1];
|
|
4
|
-
return [
|
|
5
|
-
x * Math.cos(rad) + y * Math.sin(rad) + visit[0],
|
|
6
|
-
y * Math.cos(rad) - x * Math.sin(rad) + visit[1]
|
|
7
|
-
];
|
|
8
|
-
};
|
|
9
|
-
export {
|
|
10
|
-
rotateRad
|
|
11
|
-
};
|