silkio-flowchart 0.0.0-stage → 0.1.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/LICENSE +15 -0
- package/README.md +38 -3
- package/dist/FlowEdge.d.ts +45 -0
- package/dist/FlowEdge.js +390 -0
- package/dist/Shape.d.ts +48 -0
- package/dist/Shape.js +118 -0
- package/dist/ai-protocol.d.ts +146 -0
- package/dist/ai-protocol.js +578 -0
- package/dist/ai-report.d.ts +3 -0
- package/dist/ai-report.js +83 -0
- package/dist/ai.d.ts +6 -0
- package/dist/ai.js +7 -0
- package/dist/auto-layout.d.ts +15 -0
- package/dist/auto-layout.js +248 -0
- package/dist/commands.d.ts +106 -0
- package/dist/commands.js +264 -0
- package/dist/data.d.ts +24 -0
- package/dist/data.js +1 -0
- package/dist/edge-router.d.ts +24 -0
- package/dist/edge-router.js +22 -0
- package/dist/editing.d.ts +32 -0
- package/dist/editing.js +148 -0
- package/dist/flow-layout-capability.d.ts +7 -0
- package/dist/flow-layout-capability.js +2 -0
- package/dist/flowchart.d.ts +115 -0
- package/dist/flowchart.js +1425 -0
- package/dist/geometry.d.ts +98 -0
- package/dist/geometry.js +310 -0
- package/dist/history-codec.d.ts +47 -0
- package/dist/history-codec.js +410 -0
- package/dist/hover.d.ts +22 -0
- package/dist/hover.js +96 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +18 -0
- package/dist/interactions.d.ts +51 -0
- package/dist/interactions.js +636 -0
- package/dist/model.d.ts +58 -0
- package/dist/model.js +233 -0
- package/dist/overlay.d.ts +60 -0
- package/dist/overlay.js +242 -0
- package/dist/quick-create.d.ts +12 -0
- package/dist/quick-create.js +29 -0
- package/dist/selection.d.ts +8 -0
- package/dist/selection.js +31 -0
- package/dist/session.d.ts +68 -0
- package/dist/session.js +4 -0
- package/dist/shape-registry.d.ts +17 -0
- package/dist/shape-registry.js +36 -0
- package/dist/shapes.d.ts +56 -0
- package/dist/shapes.js +291 -0
- package/dist/snap-capability.d.ts +23 -0
- package/dist/snap-capability.js +32 -0
- package/dist/snap.d.ts +34 -0
- package/dist/snap.js +370 -0
- package/package.json +32 -3
package/dist/snap.js
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
// 吸附引擎(纯函数):节点/组合拖拽时的对齐吸附与等间距吸附。
|
|
2
|
+
// 输入拖拽目标 bounds、候选参考形状与容差,输出吸附位移与绘制用参考线——
|
|
3
|
+
// 不依赖画布、App 或交互状态,可独立测试。
|
|
4
|
+
// 释放容差倍数:处于吸附态的轴用 snapTol 的该倍数做匹配(迟滞区间),
|
|
5
|
+
// 进入吸附用原阈值、退出需越过更大的阈值,边界抖动不会导致吸附反复进出
|
|
6
|
+
const RELEASE_FACTOR = 2;
|
|
7
|
+
// 间隙聚类取众数:簇内相邻差值 <= tol,出现次数 >= 2 时取簇均值,否则 NaN
|
|
8
|
+
function modeGap(gaps, tol) {
|
|
9
|
+
if (gaps.length < 2)
|
|
10
|
+
return NaN;
|
|
11
|
+
const s = [...gaps].sort((a, b) => a - b);
|
|
12
|
+
let best = NaN;
|
|
13
|
+
let bestN = 1;
|
|
14
|
+
let i = 0;
|
|
15
|
+
while (i < s.length) {
|
|
16
|
+
let j = i;
|
|
17
|
+
while (j + 1 < s.length && s[j + 1] - s[j] <= tol)
|
|
18
|
+
j++;
|
|
19
|
+
if (j - i + 1 > bestN) {
|
|
20
|
+
bestN = j - i + 1;
|
|
21
|
+
best = (s[i] + s[j]) / 2;
|
|
22
|
+
}
|
|
23
|
+
i = j + 1;
|
|
24
|
+
}
|
|
25
|
+
return bestN >= 2 ? best : NaN;
|
|
26
|
+
}
|
|
27
|
+
// 单侧吸附的目标间距:当前间隙接近众数时锁定众数,否则复现既有间距 g
|
|
28
|
+
function targetGap(cur, g, mode, tol) {
|
|
29
|
+
return !Number.isNaN(mode) && Math.abs(cur - mode) <= tol ? mode : g;
|
|
30
|
+
}
|
|
31
|
+
// 等间距吸附(主流画板做法):
|
|
32
|
+
// 1. 轴线投影过滤——仅与拖拽节点在另一轴上重叠(含少量容差)的节点参与计算,
|
|
33
|
+
// 远处行/列夹杂的零碎间距不进入间距池;
|
|
34
|
+
// 2. 高频间距锁定——投影带内相邻节点的间隙聚类取众数(至少出现 2 次),
|
|
35
|
+
// 接近众数时直接磁吸到该间距,孤立、不规则的间距不产生吸附力;
|
|
36
|
+
// 3. 两侧邻居间隙相等时平分差值;仅一侧有邻居时复现既有间距。
|
|
37
|
+
// 直接修改载体 b 的坐标;返回绘制用测量线段,以及两轴是否发生了吸附
|
|
38
|
+
function applySpacingSnap(b, candidates, tol) {
|
|
39
|
+
const out = [];
|
|
40
|
+
let snappedX = false;
|
|
41
|
+
let snappedY = false;
|
|
42
|
+
{
|
|
43
|
+
// 水平投影带:与拖拽节点垂直方向重叠(含容差)的节点
|
|
44
|
+
const band = candidates.filter((o) => o.y < b.y + b.height + tol && o.y + o.height > b.y - tol);
|
|
45
|
+
const midY = b.y + b.height / 2;
|
|
46
|
+
let L = null;
|
|
47
|
+
let R = null;
|
|
48
|
+
for (const o of band) {
|
|
49
|
+
if (o.x + o.width <= b.x && (!L || o.x + o.width > L.x + L.width))
|
|
50
|
+
L = o;
|
|
51
|
+
if (o.x >= b.x + b.width && (!R || o.x < R.x))
|
|
52
|
+
R = o;
|
|
53
|
+
}
|
|
54
|
+
// 高频间距样本:带内每个节点与其最近右邻的间隙
|
|
55
|
+
const gapsX = [];
|
|
56
|
+
for (const o of band) {
|
|
57
|
+
let nr = null;
|
|
58
|
+
for (const p of band) {
|
|
59
|
+
if (p === o || p.x < o.x + o.width)
|
|
60
|
+
continue;
|
|
61
|
+
if (!nr || p.x < nr.x)
|
|
62
|
+
nr = p;
|
|
63
|
+
}
|
|
64
|
+
if (nr) {
|
|
65
|
+
const g = nr.x - (o.x + o.width);
|
|
66
|
+
if (g > 0)
|
|
67
|
+
gapsX.push(g);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const modeX = modeGap(gapsX, tol);
|
|
71
|
+
const gL = L ? b.x - (L.x + L.width) : Infinity;
|
|
72
|
+
const gR = R ? R.x - (b.x + b.width) : Infinity;
|
|
73
|
+
if (L && R && gL > 0 && gR > 0) {
|
|
74
|
+
if (Math.abs(gL - gR) <= tol) {
|
|
75
|
+
b.x -= (gL - gR) / 2; // 平分差值,两侧间隙相等
|
|
76
|
+
snappedX = true;
|
|
77
|
+
}
|
|
78
|
+
else if (!Number.isNaN(modeX) && Math.abs(gL - modeX) <= tol && Math.abs(gR - modeX) <= tol) {
|
|
79
|
+
b.x = L.x + L.width + modeX; // 两侧都接近高频间距,磁吸过去
|
|
80
|
+
snappedX = true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else if (L && !R && gL > 0) {
|
|
84
|
+
// 仅左侧有邻居:优先吸附到高频间距,否则复现 L 与其左邻 LL
|
|
85
|
+
// (投影带内最近)的既有间距
|
|
86
|
+
let LL = null;
|
|
87
|
+
for (const o of band) {
|
|
88
|
+
if (o === L)
|
|
89
|
+
continue;
|
|
90
|
+
if (o.x + o.width <= L.x && (!LL || o.x + o.width > LL.x + LL.width))
|
|
91
|
+
LL = o;
|
|
92
|
+
}
|
|
93
|
+
if (LL) {
|
|
94
|
+
const g = L.x - (LL.x + LL.width);
|
|
95
|
+
const target = targetGap(gL, g, modeX, tol);
|
|
96
|
+
if (target > 0 && Math.abs(gL - target) <= tol) {
|
|
97
|
+
b.x = L.x + L.width + target;
|
|
98
|
+
snappedX = true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else if (R && !L && gR > 0) {
|
|
103
|
+
// 仅右侧有邻居:优先吸附到高频间距,否则复现 R 与其右邻 RR
|
|
104
|
+
// (投影带内最近)的既有间距
|
|
105
|
+
let RR = null;
|
|
106
|
+
for (const o of band) {
|
|
107
|
+
if (o === R)
|
|
108
|
+
continue;
|
|
109
|
+
if (o.x >= R.x + R.width && (!RR || o.x < RR.x))
|
|
110
|
+
RR = o;
|
|
111
|
+
}
|
|
112
|
+
if (RR) {
|
|
113
|
+
const g = RR.x - (R.x + R.width);
|
|
114
|
+
const target = targetGap(gR, g, modeX, tol);
|
|
115
|
+
if (target > 0 && Math.abs(gR - target) <= tol) {
|
|
116
|
+
b.x = R.x - target - b.width;
|
|
117
|
+
snappedX = true;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// 吸附平移后重算,两侧间隙相等时输出测量线段
|
|
122
|
+
if (L && R) {
|
|
123
|
+
const a = b.x - (L.x + L.width);
|
|
124
|
+
const c = R.x - (b.x + b.width);
|
|
125
|
+
if (a > 0 && Math.abs(a - c) <= tol) {
|
|
126
|
+
out.push({ x1: L.x + L.width, y1: midY, x2: b.x, y2: midY, value: a });
|
|
127
|
+
out.push({ x1: b.x + b.width, y1: midY, x2: R.x, y2: midY, value: c });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else if (L) {
|
|
131
|
+
// 外侧等间距:把 L 左侧的既有间距一并画出
|
|
132
|
+
let LL = null;
|
|
133
|
+
for (const o of band) {
|
|
134
|
+
if (o === L)
|
|
135
|
+
continue;
|
|
136
|
+
if (o.x + o.width <= L.x && (!LL || o.x + o.width > LL.x + LL.width))
|
|
137
|
+
LL = o;
|
|
138
|
+
}
|
|
139
|
+
if (LL) {
|
|
140
|
+
const g = L.x - (LL.x + LL.width);
|
|
141
|
+
const a = b.x - (L.x + L.width);
|
|
142
|
+
if (g > 0 && a > 0 && (Math.abs(a - g) <= tol || Math.abs(a - modeX) <= tol)) {
|
|
143
|
+
out.push({ x1: LL.x + LL.width, y1: L.y + L.height / 2, x2: L.x, y2: L.y + L.height / 2, value: g });
|
|
144
|
+
out.push({ x1: L.x + L.width, y1: midY, x2: b.x, y2: midY, value: a });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else if (R) {
|
|
149
|
+
// 外侧等间距(拖拽节点在左):把 R 右侧的既有间距一并画出
|
|
150
|
+
let RR = null;
|
|
151
|
+
for (const o of band) {
|
|
152
|
+
if (o === R)
|
|
153
|
+
continue;
|
|
154
|
+
if (o.x >= R.x + R.width && (!RR || o.x < RR.x))
|
|
155
|
+
RR = o;
|
|
156
|
+
}
|
|
157
|
+
if (RR) {
|
|
158
|
+
const g = RR.x - (R.x + R.width);
|
|
159
|
+
const a = R.x - (b.x + b.width);
|
|
160
|
+
if (g > 0 && a > 0 && (Math.abs(a - g) <= tol || Math.abs(a - modeX) <= tol)) {
|
|
161
|
+
out.push({ x1: b.x + b.width, y1: midY, x2: R.x, y2: midY, value: a });
|
|
162
|
+
out.push({ x1: R.x + R.width, y1: R.y + R.height / 2, x2: RR.x, y2: R.y + R.height / 2, value: g });
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
{
|
|
168
|
+
// 垂直投影带:与拖拽节点水平方向重叠(含容差)的节点,逻辑与水平对称
|
|
169
|
+
const band = candidates.filter((o) => o.x < b.x + b.width + tol && o.x + o.width > b.x - tol);
|
|
170
|
+
const midX = b.x + b.width / 2;
|
|
171
|
+
let T = null;
|
|
172
|
+
let B = null;
|
|
173
|
+
for (const o of band) {
|
|
174
|
+
if (o.y + o.height <= b.y && (!T || o.y + o.height > T.y + T.height))
|
|
175
|
+
T = o;
|
|
176
|
+
if (o.y >= b.y + b.height && (!B || o.y < B.y))
|
|
177
|
+
B = o;
|
|
178
|
+
}
|
|
179
|
+
// 高频间距样本:带内每个节点与其最近下邻的间隙
|
|
180
|
+
const gapsY = [];
|
|
181
|
+
for (const o of band) {
|
|
182
|
+
let nb = null;
|
|
183
|
+
for (const p of band) {
|
|
184
|
+
if (p === o || p.y < o.y + o.height)
|
|
185
|
+
continue;
|
|
186
|
+
if (!nb || p.y < nb.y)
|
|
187
|
+
nb = p;
|
|
188
|
+
}
|
|
189
|
+
if (nb) {
|
|
190
|
+
const g = nb.y - (o.y + o.height);
|
|
191
|
+
if (g > 0)
|
|
192
|
+
gapsY.push(g);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const modeY = modeGap(gapsY, tol);
|
|
196
|
+
const gT = T ? b.y - (T.y + T.height) : Infinity;
|
|
197
|
+
const gB = B ? B.y - (b.y + b.height) : Infinity;
|
|
198
|
+
if (T && B && gT > 0 && gB > 0) {
|
|
199
|
+
if (Math.abs(gT - gB) <= tol) {
|
|
200
|
+
b.y -= (gT - gB) / 2;
|
|
201
|
+
snappedY = true;
|
|
202
|
+
}
|
|
203
|
+
else if (!Number.isNaN(modeY) && Math.abs(gT - modeY) <= tol && Math.abs(gB - modeY) <= tol) {
|
|
204
|
+
b.y = T.y + T.height + modeY;
|
|
205
|
+
snappedY = true;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
else if (T && !B && gT > 0) {
|
|
209
|
+
let TT = null;
|
|
210
|
+
for (const o of band) {
|
|
211
|
+
if (o === T)
|
|
212
|
+
continue;
|
|
213
|
+
if (o.y + o.height <= T.y && (!TT || o.y + o.height > TT.y + TT.height))
|
|
214
|
+
TT = o;
|
|
215
|
+
}
|
|
216
|
+
if (TT) {
|
|
217
|
+
const g = T.y - (TT.y + TT.height);
|
|
218
|
+
const target = targetGap(gT, g, modeY, tol);
|
|
219
|
+
if (target > 0 && Math.abs(gT - target) <= tol) {
|
|
220
|
+
b.y = T.y + T.height + target;
|
|
221
|
+
snappedY = true;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
else if (B && !T && gB > 0) {
|
|
226
|
+
let BB = null;
|
|
227
|
+
for (const o of band) {
|
|
228
|
+
if (o === B)
|
|
229
|
+
continue;
|
|
230
|
+
if (o.y >= B.y + B.height && (!BB || o.y < BB.y))
|
|
231
|
+
BB = o;
|
|
232
|
+
}
|
|
233
|
+
if (BB) {
|
|
234
|
+
const g = BB.y - (B.y + B.height);
|
|
235
|
+
const target = targetGap(gB, g, modeY, tol);
|
|
236
|
+
if (target > 0 && Math.abs(gB - target) <= tol) {
|
|
237
|
+
b.y = B.y - target - b.height;
|
|
238
|
+
snappedY = true;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (T && B) {
|
|
243
|
+
const a = b.y - (T.y + T.height);
|
|
244
|
+
const c = B.y - (b.y + b.height);
|
|
245
|
+
if (a > 0 && Math.abs(a - c) <= tol) {
|
|
246
|
+
out.push({ x1: midX, y1: T.y + T.height, x2: midX, y2: b.y, value: a });
|
|
247
|
+
out.push({ x1: midX, y1: b.y + b.height, x2: midX, y2: B.y, value: c });
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
else if (T) {
|
|
251
|
+
let TT = null;
|
|
252
|
+
for (const o of band) {
|
|
253
|
+
if (o === T)
|
|
254
|
+
continue;
|
|
255
|
+
if (o.y + o.height <= T.y && (!TT || o.y + o.height > TT.y + TT.height))
|
|
256
|
+
TT = o;
|
|
257
|
+
}
|
|
258
|
+
if (TT) {
|
|
259
|
+
const g = T.y - (TT.y + TT.height);
|
|
260
|
+
const a = b.y - (T.y + T.height);
|
|
261
|
+
if (g > 0 && a > 0 && (Math.abs(a - g) <= tol || Math.abs(a - modeY) <= tol)) {
|
|
262
|
+
out.push({ x1: T.x + T.width / 2, y1: TT.y + TT.height, x2: T.x + T.width / 2, y2: T.y, value: g });
|
|
263
|
+
out.push({ x1: midX, y1: T.y + T.height, x2: midX, y2: b.y, value: a });
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
else if (B) {
|
|
268
|
+
// 外侧等间距(拖拽节点在上):把 B 下方的既有间距一并画出
|
|
269
|
+
let BB = null;
|
|
270
|
+
for (const o of band) {
|
|
271
|
+
if (o === B)
|
|
272
|
+
continue;
|
|
273
|
+
if (o.y >= B.y + B.height && (!BB || o.y < BB.y))
|
|
274
|
+
BB = o;
|
|
275
|
+
}
|
|
276
|
+
if (BB) {
|
|
277
|
+
const g = BB.y - (B.y + B.height);
|
|
278
|
+
const a = B.y - (b.y + b.height);
|
|
279
|
+
if (g > 0 && a > 0 && (Math.abs(a - g) <= tol || Math.abs(a - modeY) <= tol)) {
|
|
280
|
+
out.push({ x1: midX, y1: b.y + b.height, x2: midX, y2: B.y, value: a });
|
|
281
|
+
out.push({ x1: B.x + B.width / 2, y1: B.y + B.height, x2: B.x + B.width / 2, y2: BB.y, value: g });
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return { guides: out, snappedX, snappedY };
|
|
287
|
+
}
|
|
288
|
+
// 拖拽吸附总入口:对 bounds 载体(单形状,或多选组合的并集框)做吸附——
|
|
289
|
+
// 等间距吸附优先——某轴发生等间距吸附后该轴不再做对齐吸附,
|
|
290
|
+
// 避免两类吸附点相邻时(如间距 40px 恰与中线对齐差 1px)来回切换产生抖动;
|
|
291
|
+
// 对齐吸附仅同类型基准配对——左对左、中对中、右对右(上/中/下同理),取各类
|
|
292
|
+
// 最小差值做吸附平移;吸附后仅在实际吸附的轴上收集精确对齐的基准做参考线
|
|
293
|
+
//(等宽节点上下对齐时中线随之对齐,跳过中线参考线);opts.prev 提供迟滞——
|
|
294
|
+
// 上一帧已吸附的轴用加倍的释放容差维持吸附,边界抖动不闪烁。
|
|
295
|
+
// 不修改传入的 box,返回位移与参考线,由调用方应用
|
|
296
|
+
export function computeSnap(box, candidates, opts) {
|
|
297
|
+
const tol = opts.snapTol;
|
|
298
|
+
// 迟滞:上一帧已吸附的轴放宽到释放容差,未吸附的轴用进入阈值
|
|
299
|
+
const tolX = opts.prev?.x ? tol * RELEASE_FACTOR : tol;
|
|
300
|
+
const tolY = opts.prev?.y ? tol * RELEASE_FACTOR : tol;
|
|
301
|
+
const b = { ...box };
|
|
302
|
+
// 等间距吸附优先;该轴已吸附时跳过对齐吸附
|
|
303
|
+
const spacing = applySpacingSnap(b, candidates, opts.spacingTol);
|
|
304
|
+
const skipX = spacing.snappedX;
|
|
305
|
+
const skipY = spacing.snappedY;
|
|
306
|
+
const xs = () => [b.x, b.x + b.width / 2, b.x + b.width];
|
|
307
|
+
const ys = () => [b.y, b.y + b.height / 2, b.y + b.height];
|
|
308
|
+
let bestX = null;
|
|
309
|
+
let bestY = null;
|
|
310
|
+
for (const other of candidates) {
|
|
311
|
+
const oxs = [other.x, other.x + other.width / 2, other.x + other.width];
|
|
312
|
+
const oys = [other.y, other.y + other.height / 2, other.y + other.height];
|
|
313
|
+
for (let i = 0; i < 3; i++) {
|
|
314
|
+
if (!skipX) {
|
|
315
|
+
const d = Math.abs(oxs[i] - xs()[i]);
|
|
316
|
+
if (d <= tolX && (!bestX || d < bestX.d))
|
|
317
|
+
bestX = { d, shift: oxs[i] - xs()[i] };
|
|
318
|
+
}
|
|
319
|
+
if (!skipY) {
|
|
320
|
+
const d2 = Math.abs(oys[i] - ys()[i]);
|
|
321
|
+
if (d2 <= tolY && (!bestY || d2 < bestY.d))
|
|
322
|
+
bestY = { d: d2, shift: oys[i] - ys()[i] };
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
if (bestX)
|
|
327
|
+
b.x += bestX.shift;
|
|
328
|
+
if (bestY)
|
|
329
|
+
b.y += bestY.shift;
|
|
330
|
+
// 吸附后收集参考线:仅在实际发生对齐吸附的轴上收集,且只收录精确对齐的
|
|
331
|
+
// 基准(吸附平移后差值为浮点零,EPS 过滤舍入误差)——阈值内"接近对齐"的
|
|
332
|
+
// 基线不再画线,避免相差几像素也显示对齐、参考线随鼠标移动忽隐忽现;
|
|
333
|
+
// 等间距吸附的轴由测量线段表达,不重复画对齐线
|
|
334
|
+
const EPS = 1e-6;
|
|
335
|
+
const v = new Set();
|
|
336
|
+
const h = new Set();
|
|
337
|
+
if (bestX) {
|
|
338
|
+
for (const other of candidates) {
|
|
339
|
+
const oxs = [other.x, other.x + other.width / 2, other.x + other.width];
|
|
340
|
+
for (let i = 0; i < 3; i++) {
|
|
341
|
+
if (Math.abs(oxs[i] - xs()[i]) <= EPS)
|
|
342
|
+
v.add(oxs[i]);
|
|
343
|
+
}
|
|
344
|
+
// 左右两边都已精确对齐时宽度必然相等、中线随之对齐,跳过中线参考线
|
|
345
|
+
if (Math.abs(oxs[0] - xs()[0]) <= EPS && Math.abs(oxs[2] - xs()[2]) <= EPS)
|
|
346
|
+
v.delete(oxs[1]);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
if (bestY) {
|
|
350
|
+
for (const other of candidates) {
|
|
351
|
+
const oys = [other.y, other.y + other.height / 2, other.y + other.height];
|
|
352
|
+
for (let i = 0; i < 3; i++) {
|
|
353
|
+
if (Math.abs(oys[i] - ys()[i]) <= EPS)
|
|
354
|
+
h.add(oys[i]);
|
|
355
|
+
}
|
|
356
|
+
// 上下两边都已精确对齐时高度必然相等、中线随之对齐,跳过中线参考线
|
|
357
|
+
if (Math.abs(oys[0] - ys()[0]) <= EPS && Math.abs(oys[2] - ys()[2]) <= EPS)
|
|
358
|
+
h.delete(oys[1]);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return {
|
|
362
|
+
dx: b.x - box.x,
|
|
363
|
+
dy: b.y - box.y,
|
|
364
|
+
snappedX: !skipX && bestX !== null,
|
|
365
|
+
snappedY: !skipY && bestY !== null,
|
|
366
|
+
guides: v.size || h.size || spacing.guides.length
|
|
367
|
+
? { v: [...v], h: [...h], spacing: spacing.guides }
|
|
368
|
+
: null,
|
|
369
|
+
};
|
|
370
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "silkio-flowchart",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@silkor/core": "^0.1.0",
|
|
15
|
+
"@silkor/preset": "^0.1.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@changesets/changelog-github": "^1.0.1",
|
|
19
|
+
"@changesets/cli": "^3.0.3",
|
|
20
|
+
"typescript": "~6.0.2",
|
|
21
|
+
"vitest": "^3.0.0"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"license": "ISC",
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc -p tsconfig.json",
|
|
29
|
+
"dev": "tsc -p tsconfig.json --watch",
|
|
30
|
+
"test": "vitest run",
|
|
31
|
+
"check:deps": "node scripts/check-deps.mjs",
|
|
32
|
+
"changeset": "changeset",
|
|
33
|
+
"version-packages": "changeset version"
|
|
34
|
+
}
|
|
6
35
|
}
|