@leafer-in/linker 2.3.2 → 2.3.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/linker.cjs +444 -49
- package/dist/linker.esm.js +445 -50
- package/dist/linker.esm.min.js +1 -1
- package/dist/linker.esm.min.js.map +1 -1
- package/dist/linker.js +420 -49
- package/dist/linker.min.cjs +1 -1
- package/dist/linker.min.cjs.map +1 -1
- package/dist/linker.min.js +1 -1
- package/dist/linker.min.js.map +1 -1
- package/package.json +1 -1
- package/src/Linker.ts +72 -57
- package/src/helper/drawPolyline.ts +456 -0
- package/types/index.d.ts +2 -1
package/dist/linker.js
CHANGED
|
@@ -16,7 +16,7 @@ this.LeaferIN.linker = function(exports, draw, core) {
|
|
|
16
16
|
return this.path || this.__pathInputed;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
const {directionData: directionData} = draw.AroundHelper;
|
|
19
|
+
const {directionData: directionData$1} = draw.AroundHelper;
|
|
20
20
|
const directionNames = [ "top-left", "top", "top-right", "right", "bottom-right", "bottom", "bottom-left", "left", "center" ];
|
|
21
21
|
const LinkerHelper = {
|
|
22
22
|
getCtrlPoint(linker, node, point, direction, ctrl, offsetAngle) {
|
|
@@ -129,8 +129,8 @@ this.LeaferIN.linker = function(exports, draw, core) {
|
|
|
129
129
|
const {width: width, height: height} = bounds;
|
|
130
130
|
const hitRadiusX = width / 4;
|
|
131
131
|
const hitRadiusY = height / 4;
|
|
132
|
-
for (let i = 0; i < directionData.length; i++) {
|
|
133
|
-
const unit = directionData[i];
|
|
132
|
+
for (let i = 0; i < directionData$1.length; i++) {
|
|
133
|
+
const unit = directionData$1[i];
|
|
134
134
|
const px = unit.x * width;
|
|
135
135
|
const py = unit.y * height;
|
|
136
136
|
const dx = boxPoint.x - px;
|
|
@@ -172,7 +172,363 @@ this.LeaferIN.linker = function(exports, draw, core) {
|
|
|
172
172
|
}
|
|
173
173
|
}));
|
|
174
174
|
}
|
|
175
|
-
const {
|
|
175
|
+
const {directionData: directionData} = draw.AroundHelper;
|
|
176
|
+
const {moveTo: moveTo$1, lineTo: lineTo$1} = draw.PathCommandDataHelper;
|
|
177
|
+
const POLYLINE_X = 0, POLYLINE_Y = 1;
|
|
178
|
+
const POLYLINE_EPSILON = .001;
|
|
179
|
+
const POLYLINE_MIN_SEGMENT = 4;
|
|
180
|
+
const POLYLINE_TURN_WEIGHT = 1.5;
|
|
181
|
+
function getPolylineDirectionIndex(direction) {
|
|
182
|
+
switch (direction) {
|
|
183
|
+
case "top-left":
|
|
184
|
+
return 0;
|
|
185
|
+
|
|
186
|
+
case "top":
|
|
187
|
+
return 1;
|
|
188
|
+
|
|
189
|
+
case "top-right":
|
|
190
|
+
return 2;
|
|
191
|
+
|
|
192
|
+
case "right":
|
|
193
|
+
return 3;
|
|
194
|
+
|
|
195
|
+
case "bottom-right":
|
|
196
|
+
return 4;
|
|
197
|
+
|
|
198
|
+
case "bottom":
|
|
199
|
+
return 5;
|
|
200
|
+
|
|
201
|
+
case "bottom-left":
|
|
202
|
+
return 6;
|
|
203
|
+
|
|
204
|
+
case "left":
|
|
205
|
+
return 7;
|
|
206
|
+
|
|
207
|
+
default:
|
|
208
|
+
return 8;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function getPolylinePorts(direction, point, target, bounds, targetBounds, ports) {
|
|
212
|
+
const data = directionData[getPolylineDirectionIndex(direction)];
|
|
213
|
+
const dx = Math.sign(data.x - .5), dy = Math.sign(data.y - .5);
|
|
214
|
+
const cx = bounds ? bounds.x + bounds.width / 2 : point.x;
|
|
215
|
+
const cy = bounds ? bounds.y + bounds.height / 2 : point.y;
|
|
216
|
+
const tx = targetBounds ? targetBounds.x + targetBounds.width / 2 : target.x;
|
|
217
|
+
const ty = targetBounds ? targetBounds.y + targetBounds.height / 2 : target.y;
|
|
218
|
+
const deltaX = tx - cx, deltaY = ty - cy;
|
|
219
|
+
const xSign = dx || (deltaX >= 0 ? 1 : -1);
|
|
220
|
+
const ySign = dy || (deltaY >= 0 ? 1 : -1);
|
|
221
|
+
const xPort = POLYLINE_X * 2 + (xSign > 0 ? 1 : 0);
|
|
222
|
+
const yPort = POLYLINE_Y * 2 + (ySign > 0 ? 1 : 0);
|
|
223
|
+
if (dx && !dy) {
|
|
224
|
+
ports[0] = xPort;
|
|
225
|
+
return 1;
|
|
226
|
+
}
|
|
227
|
+
if (dy && !dx) {
|
|
228
|
+
ports[0] = yPort;
|
|
229
|
+
return 1;
|
|
230
|
+
}
|
|
231
|
+
if (Math.abs(deltaX) >= Math.abs(deltaY)) {
|
|
232
|
+
ports[0] = xPort;
|
|
233
|
+
ports[1] = yPort;
|
|
234
|
+
} else {
|
|
235
|
+
ports[0] = yPort;
|
|
236
|
+
ports[1] = xPort;
|
|
237
|
+
}
|
|
238
|
+
return 2;
|
|
239
|
+
}
|
|
240
|
+
function getPolylineExit(point, bounds, port, clearance, result) {
|
|
241
|
+
const axis = port >> 1, sign = port & 1 ? 1 : -1;
|
|
242
|
+
if (axis === POLYLINE_X) {
|
|
243
|
+
const boundary = bounds ? sign > 0 ? bounds.x + bounds.width : bounds.x : point.x;
|
|
244
|
+
result[0] = boundary + sign * clearance;
|
|
245
|
+
result[1] = point.y;
|
|
246
|
+
} else {
|
|
247
|
+
const boundary = bounds ? sign > 0 ? bounds.y + bounds.height : bounds.y : point.y;
|
|
248
|
+
result[0] = point.x;
|
|
249
|
+
result[1] = boundary + sign * clearance;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function isPolylinePointBlocked(x, y, bounds, clearance) {
|
|
253
|
+
if (!bounds) return false;
|
|
254
|
+
const left = bounds.x - clearance, right = bounds.x + bounds.width + clearance;
|
|
255
|
+
const top = bounds.y - clearance, bottom = bounds.y + bounds.height + clearance;
|
|
256
|
+
return x > left + POLYLINE_EPSILON && x < right - POLYLINE_EPSILON && y > top + POLYLINE_EPSILON && y < bottom - POLYLINE_EPSILON;
|
|
257
|
+
}
|
|
258
|
+
function isPolylineSegmentBlocked(x1, y1, x2, y2, bounds, clearance) {
|
|
259
|
+
if (!bounds) return false;
|
|
260
|
+
const left = bounds.x - clearance, right = bounds.x + bounds.width + clearance;
|
|
261
|
+
const top = bounds.y - clearance, bottom = bounds.y + bounds.height + clearance;
|
|
262
|
+
if (Math.abs(y1 - y2) <= POLYLINE_EPSILON) {
|
|
263
|
+
return y1 > top + POLYLINE_EPSILON && y1 < bottom - POLYLINE_EPSILON && Math.max(Math.min(x1, x2), left + POLYLINE_EPSILON) < Math.min(Math.max(x1, x2), right - POLYLINE_EPSILON);
|
|
264
|
+
}
|
|
265
|
+
if (Math.abs(x1 - x2) <= POLYLINE_EPSILON) {
|
|
266
|
+
return x1 > left + POLYLINE_EPSILON && x1 < right - POLYLINE_EPSILON && Math.max(Math.min(y1, y2), top + POLYLINE_EPSILON) < Math.min(Math.max(y1, y2), bottom - POLYLINE_EPSILON);
|
|
267
|
+
}
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
270
|
+
function addPolylineBoundsCoordinates(xs, ys, bounds, clearance, margin) {
|
|
271
|
+
if (!bounds) return;
|
|
272
|
+
const left = bounds.x - clearance, right = bounds.x + bounds.width + clearance;
|
|
273
|
+
const top = bounds.y - clearance, bottom = bounds.y + bounds.height + clearance;
|
|
274
|
+
xs.push(left, right, left - margin, right + margin);
|
|
275
|
+
ys.push(top, bottom, top - margin, bottom + margin);
|
|
276
|
+
}
|
|
277
|
+
function sortPolylineCoordinates(values) {
|
|
278
|
+
values.sort((a, b) => a - b);
|
|
279
|
+
let write = 0;
|
|
280
|
+
for (let i = 0; i < values.length; i++) {
|
|
281
|
+
if (!write || Math.abs(values[i] - values[write - 1]) > POLYLINE_EPSILON) values[write++] = values[i];
|
|
282
|
+
}
|
|
283
|
+
values.length = write;
|
|
284
|
+
}
|
|
285
|
+
function getPolylineCoordinateIndex(values, value) {
|
|
286
|
+
for (let i = 0; i < values.length; i++) {
|
|
287
|
+
if (Math.abs(values[i] - value) <= POLYLINE_EPSILON) return i;
|
|
288
|
+
}
|
|
289
|
+
return -1;
|
|
290
|
+
}
|
|
291
|
+
function getPolylineMidpointAxis(startPort, endPort, sx, sy, ex, ey) {
|
|
292
|
+
const startAxis = startPort >> 1, endAxis = endPort >> 1;
|
|
293
|
+
const startSign = startPort & 1 ? 1 : -1, endSign = endPort & 1 ? 1 : -1;
|
|
294
|
+
if (startAxis === endAxis && startSign === -endSign) return startAxis;
|
|
295
|
+
return Math.abs(ex - sx) >= Math.abs(ey - sy) ? POLYLINE_X : POLYLINE_Y;
|
|
296
|
+
}
|
|
297
|
+
function getPolylineMidpointRoute(result, startPoint, endPoint, sx, sy, ex, ey, midpointAxis, startBounds, endBounds, clearance) {
|
|
298
|
+
const midpointX = (sx + ex) / 2, midpointY = (sy + ey) / 2;
|
|
299
|
+
result.length = 0;
|
|
300
|
+
result.push(startPoint.x, startPoint.y, sx, sy);
|
|
301
|
+
if (midpointAxis === POLYLINE_X) {
|
|
302
|
+
result.push(midpointX, sy, midpointX, ey);
|
|
303
|
+
} else {
|
|
304
|
+
result.push(sx, midpointY, ex, midpointY);
|
|
305
|
+
}
|
|
306
|
+
result.push(ex, ey, endPoint.x, endPoint.y);
|
|
307
|
+
for (let i = 4; i < result.length - 2; i += 2) {
|
|
308
|
+
const x1 = result[i - 2], y1 = result[i - 1];
|
|
309
|
+
const x2 = result[i], y2 = result[i + 1];
|
|
310
|
+
if (isPolylineSegmentBlocked(x1, y1, x2, y2, startBounds, clearance) || isPolylineSegmentBlocked(x1, y1, x2, y2, endBounds, clearance)) return Infinity;
|
|
311
|
+
}
|
|
312
|
+
return getPolylineScore(result, clearance);
|
|
313
|
+
}
|
|
314
|
+
function getPolylineRoute(result, startPoint, endPoint, startPort, endPort, startBounds, endBounds, clearance) {
|
|
315
|
+
const startExit = [], endExit = [];
|
|
316
|
+
getPolylineExit(startPoint, startBounds, startPort, clearance, startExit);
|
|
317
|
+
getPolylineExit(endPoint, endBounds, endPort, clearance, endExit);
|
|
318
|
+
const sx = startExit[0], sy = startExit[1], ex = endExit[0], ey = endExit[1];
|
|
319
|
+
const startAxis = startPort >> 1, endAxis = endPort >> 1;
|
|
320
|
+
const startSign = startPort & 1 ? 1 : -1, endSign = endPort & 1 ? 1 : -1;
|
|
321
|
+
const startStub = Math.abs(sx - startPoint.x) + Math.abs(sy - startPoint.y);
|
|
322
|
+
const endStub = Math.abs(ex - endPoint.x) + Math.abs(ey - endPoint.y);
|
|
323
|
+
if (isPolylineSegmentBlocked(startPoint.x, startPoint.y, sx, sy, endBounds, clearance) || isPolylineSegmentBlocked(endPoint.x, endPoint.y, ex, ey, startBounds, clearance)) return Infinity;
|
|
324
|
+
const midpointAxis = getPolylineMidpointAxis(startPort, endPort, sx, sy, ex, ey);
|
|
325
|
+
const midpointScore = getPolylineMidpointRoute(result, startPoint, endPoint, sx, sy, ex, ey, midpointAxis, startBounds, endBounds, clearance);
|
|
326
|
+
if (midpointScore < Infinity) return midpointScore;
|
|
327
|
+
const margin = Math.max(clearance, POLYLINE_MIN_SEGMENT) * 2;
|
|
328
|
+
const xs = [ sx, ex, (sx + ex) / 2 ], ys = [ sy, ey, (sy + ey) / 2 ];
|
|
329
|
+
addPolylineBoundsCoordinates(xs, ys, startBounds, clearance, margin);
|
|
330
|
+
addPolylineBoundsCoordinates(xs, ys, endBounds, clearance, margin);
|
|
331
|
+
let minX = Math.min(...xs), maxX = Math.max(...xs);
|
|
332
|
+
let minY = Math.min(...ys), maxY = Math.max(...ys);
|
|
333
|
+
xs.push(minX - margin * 2, maxX + margin * 2);
|
|
334
|
+
ys.push(minY - margin * 2, maxY + margin * 2);
|
|
335
|
+
sortPolylineCoordinates(xs);
|
|
336
|
+
sortPolylineCoordinates(ys);
|
|
337
|
+
const nx = xs.length, ny = ys.length;
|
|
338
|
+
const startXIndex = getPolylineCoordinateIndex(xs, sx), startYIndex = getPolylineCoordinateIndex(ys, sy);
|
|
339
|
+
const endXIndex = getPolylineCoordinateIndex(xs, ex), endYIndex = getPolylineCoordinateIndex(ys, ey);
|
|
340
|
+
if (startXIndex < 0 || startYIndex < 0 || endXIndex < 0 || endYIndex < 0) return Infinity;
|
|
341
|
+
const startNode = startYIndex * nx + startXIndex, endNode = endYIndex * nx + endXIndex;
|
|
342
|
+
const total = nx * ny * 3;
|
|
343
|
+
const distance = new Float64Array(total), previous = new Int32Array(total), visited = new Uint8Array(total);
|
|
344
|
+
distance.fill(Infinity);
|
|
345
|
+
previous.fill(-1);
|
|
346
|
+
const startState = startNode * 3;
|
|
347
|
+
distance[startState] = 0;
|
|
348
|
+
const turnCost = Math.max(POLYLINE_MIN_SEGMENT, clearance * POLYLINE_TURN_WEIGHT);
|
|
349
|
+
let currentState = -1, currentNode = -1, currentAxis = 0;
|
|
350
|
+
let currentX = 0, currentY = 0, currentDistance = 0;
|
|
351
|
+
const relax = (nextXIndex, nextYIndex, axis, sign) => {
|
|
352
|
+
const nextX = xs[nextXIndex], nextY = ys[nextYIndex];
|
|
353
|
+
const nextNode = nextYIndex * nx + nextXIndex;
|
|
354
|
+
if (isPolylinePointBlocked(nextX, nextY, startBounds, clearance) || isPolylinePointBlocked(nextX, nextY, endBounds, clearance)) return;
|
|
355
|
+
if (isPolylineSegmentBlocked(currentX, currentY, nextX, nextY, startBounds, clearance) || isPolylineSegmentBlocked(currentX, currentY, nextX, nextY, endBounds, clearance)) return;
|
|
356
|
+
if (currentState === startState) {
|
|
357
|
+
if (axis === startAxis + 1) {
|
|
358
|
+
if (sign !== startSign) return;
|
|
359
|
+
} else if (startStub <= POLYLINE_EPSILON) return;
|
|
360
|
+
}
|
|
361
|
+
if (nextNode === endNode) {
|
|
362
|
+
if (axis === endAxis + 1) {
|
|
363
|
+
if (sign !== -endSign) return;
|
|
364
|
+
} else if (endStub <= POLYLINE_EPSILON) return;
|
|
365
|
+
}
|
|
366
|
+
const nextState = nextNode * 3 + axis;
|
|
367
|
+
if (visited[nextState]) return;
|
|
368
|
+
const segmentLength = Math.abs(nextX - currentX) + Math.abs(nextY - currentY);
|
|
369
|
+
let cost = currentDistance + segmentLength;
|
|
370
|
+
if (currentAxis && currentAxis !== axis) {
|
|
371
|
+
cost += turnCost;
|
|
372
|
+
const turnCoordinate = currentAxis === POLYLINE_X + 1 ? currentX : currentY;
|
|
373
|
+
const preferredCoordinate = midpointAxis === POLYLINE_X ? (sx + ex) / 2 : (sy + ey) / 2;
|
|
374
|
+
if (Math.abs(turnCoordinate - preferredCoordinate) > POLYLINE_EPSILON) cost += turnCost * 2;
|
|
375
|
+
}
|
|
376
|
+
if (cost < distance[nextState]) {
|
|
377
|
+
distance[nextState] = cost;
|
|
378
|
+
previous[nextState] = currentState;
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
let bestState = -1;
|
|
382
|
+
for (let iteration = 0; iteration < total; iteration++) {
|
|
383
|
+
let minDistance = Infinity, state = -1;
|
|
384
|
+
for (let i = 0; i < total; i++) {
|
|
385
|
+
if (!visited[i] && distance[i] < minDistance) {
|
|
386
|
+
minDistance = distance[i];
|
|
387
|
+
state = i;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
if (state < 0) break;
|
|
391
|
+
currentState = state;
|
|
392
|
+
currentNode = Math.floor(state / 3);
|
|
393
|
+
currentAxis = state % 3;
|
|
394
|
+
currentDistance = minDistance;
|
|
395
|
+
visited[state] = 1;
|
|
396
|
+
if (currentNode === endNode) {
|
|
397
|
+
bestState = state;
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
const xIndex = currentNode % nx, yIndex = Math.floor(currentNode / nx);
|
|
401
|
+
currentX = xs[xIndex];
|
|
402
|
+
currentY = ys[yIndex];
|
|
403
|
+
if (xIndex > 0) relax(xIndex - 1, yIndex, POLYLINE_X + 1, -1);
|
|
404
|
+
if (xIndex < nx - 1) relax(xIndex + 1, yIndex, POLYLINE_X + 1, 1);
|
|
405
|
+
if (yIndex > 0) relax(xIndex, yIndex - 1, POLYLINE_Y + 1, -1);
|
|
406
|
+
if (yIndex < ny - 1) relax(xIndex, yIndex + 1, POLYLINE_Y + 1, 1);
|
|
407
|
+
}
|
|
408
|
+
if (bestState < 0) return Infinity;
|
|
409
|
+
const reverse = [];
|
|
410
|
+
let state = bestState;
|
|
411
|
+
while (state >= 0) {
|
|
412
|
+
const node = Math.floor(state / 3);
|
|
413
|
+
reverse.push(xs[node % nx], ys[Math.floor(node / nx)]);
|
|
414
|
+
if (state === startState) break;
|
|
415
|
+
state = previous[state];
|
|
416
|
+
}
|
|
417
|
+
if (state !== startState) return Infinity;
|
|
418
|
+
result.length = 0;
|
|
419
|
+
result.push(startPoint.x, startPoint.y, sx, sy);
|
|
420
|
+
for (let i = reverse.length - 4; i >= 0; i -= 2) result.push(reverse[i], reverse[i + 1]);
|
|
421
|
+
result.push(endPoint.x, endPoint.y);
|
|
422
|
+
return distance[bestState] + startStub + endStub;
|
|
423
|
+
}
|
|
424
|
+
function appendPolylinePoint(points, x, y) {
|
|
425
|
+
const length = points.length;
|
|
426
|
+
if (length >= 2 && Math.abs(points[length - 2] - x) <= POLYLINE_EPSILON && Math.abs(points[length - 1] - y) <= POLYLINE_EPSILON) return;
|
|
427
|
+
points.push(x, y);
|
|
428
|
+
}
|
|
429
|
+
function appendPolylineOrthogonal(points, x1, y1, x2, y2, firstAxis = POLYLINE_X) {
|
|
430
|
+
if (Math.abs(x1 - x2) > POLYLINE_EPSILON && Math.abs(y1 - y2) > POLYLINE_EPSILON) {
|
|
431
|
+
if (firstAxis === POLYLINE_X) {
|
|
432
|
+
const midX = (x1 + x2) / 2;
|
|
433
|
+
appendPolylinePoint(points, midX, y1);
|
|
434
|
+
appendPolylinePoint(points, midX, y2);
|
|
435
|
+
} else {
|
|
436
|
+
const midY = (y1 + y2) / 2;
|
|
437
|
+
appendPolylinePoint(points, x1, midY);
|
|
438
|
+
appendPolylinePoint(points, x2, midY);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
appendPolylinePoint(points, x2, y2);
|
|
442
|
+
}
|
|
443
|
+
function getPolylineEditPath(result, startPoint, endPoint, startPort, endPort, startBounds, endBounds, points, clearance) {
|
|
444
|
+
if (points.length % 2) return Infinity;
|
|
445
|
+
for (let i = 0; i < points.length; i++) if (!Number.isFinite(points[i])) return Infinity;
|
|
446
|
+
const startExit = [], endExit = [];
|
|
447
|
+
getPolylineExit(startPoint, startBounds, startPort, clearance, startExit);
|
|
448
|
+
getPolylineExit(endPoint, endBounds, endPort, clearance, endExit);
|
|
449
|
+
const sx = startExit[0], sy = startExit[1], ex = endExit[0], ey = endExit[1];
|
|
450
|
+
if (isPolylineSegmentBlocked(startPoint.x, startPoint.y, sx, sy, endBounds, clearance) || isPolylineSegmentBlocked(endPoint.x, endPoint.y, ex, ey, startBounds, clearance)) return Infinity;
|
|
451
|
+
result.length = 0;
|
|
452
|
+
appendPolylinePoint(result, startPoint.x, startPoint.y);
|
|
453
|
+
appendPolylinePoint(result, sx, sy);
|
|
454
|
+
let x = sx, y = sy;
|
|
455
|
+
for (let i = 0; i < points.length; i += 2) {
|
|
456
|
+
const nx = points[i], ny = points[i + 1];
|
|
457
|
+
appendPolylineOrthogonal(result, x, y, nx, ny, i === 0 && clearance === 0 ? startPort >> 1 : POLYLINE_X);
|
|
458
|
+
x = nx;
|
|
459
|
+
y = ny;
|
|
460
|
+
}
|
|
461
|
+
const endAxis = endPort >> 1;
|
|
462
|
+
if (Math.abs(x - ex) > POLYLINE_EPSILON && Math.abs(y - ey) > POLYLINE_EPSILON) {
|
|
463
|
+
if (endAxis === POLYLINE_X) appendPolylinePoint(result, x, ey); else appendPolylinePoint(result, ex, y);
|
|
464
|
+
}
|
|
465
|
+
appendPolylinePoint(result, ex, ey);
|
|
466
|
+
appendPolylinePoint(result, endPoint.x, endPoint.y);
|
|
467
|
+
return getPolylineScore(result, clearance);
|
|
468
|
+
}
|
|
469
|
+
function getPolylineScore(points, clearance) {
|
|
470
|
+
let length = 0, turns = 0, previousAxis = -1;
|
|
471
|
+
for (let i = 2; i < points.length; i += 2) {
|
|
472
|
+
const dx = points[i] - points[i - 2], dy = points[i + 1] - points[i - 1];
|
|
473
|
+
if (Math.abs(dx) <= POLYLINE_EPSILON && Math.abs(dy) <= POLYLINE_EPSILON) continue;
|
|
474
|
+
const axis = Math.abs(dx) > POLYLINE_EPSILON ? POLYLINE_X : POLYLINE_Y;
|
|
475
|
+
length += Math.abs(dx) + Math.abs(dy);
|
|
476
|
+
if (previousAxis !== -1 && previousAxis !== axis) turns++;
|
|
477
|
+
previousAxis = axis;
|
|
478
|
+
}
|
|
479
|
+
return length + turns * Math.max(clearance, POLYLINE_MIN_SEGMENT) * POLYLINE_TURN_WEIGHT;
|
|
480
|
+
}
|
|
481
|
+
function simplifyPolyline(points) {
|
|
482
|
+
let write = 2;
|
|
483
|
+
for (let read = 2; read < points.length; read += 2) {
|
|
484
|
+
const x = points[read], y = points[read + 1];
|
|
485
|
+
const px = points[write - 2], py = points[write - 1];
|
|
486
|
+
if (Math.abs(x - px) <= POLYLINE_EPSILON && Math.abs(y - py) <= POLYLINE_EPSILON) continue;
|
|
487
|
+
if (write >= 4) {
|
|
488
|
+
const ax = points[write - 4], ay = points[write - 3];
|
|
489
|
+
const horizontal = Math.abs(ay - py) <= POLYLINE_EPSILON && Math.abs(py - y) <= POLYLINE_EPSILON && (px - ax) * (x - px) >= 0;
|
|
490
|
+
const vertical = Math.abs(ax - px) <= POLYLINE_EPSILON && Math.abs(px - x) <= POLYLINE_EPSILON && (py - ay) * (y - py) >= 0;
|
|
491
|
+
if (horizontal || vertical) {
|
|
492
|
+
points[write - 2] = x;
|
|
493
|
+
points[write - 1] = y;
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
points[write++] = x;
|
|
498
|
+
points[write++] = y;
|
|
499
|
+
}
|
|
500
|
+
points.length = write;
|
|
501
|
+
}
|
|
502
|
+
function drawPolyline(path, startPoint, endPoint, startDirection, endDirection, startBounds, endBounds, clearance = 8, points) {
|
|
503
|
+
if (!Number.isFinite(startPoint.x) || !Number.isFinite(startPoint.y) || !Number.isFinite(endPoint.x) || !Number.isFinite(endPoint.y)) return false;
|
|
504
|
+
if (startBounds && (!Number.isFinite(startBounds.x) || !Number.isFinite(startBounds.y) || !Number.isFinite(startBounds.width) || !Number.isFinite(startBounds.height) || startBounds.width < 0 || startBounds.height < 0)) return false;
|
|
505
|
+
if (endBounds && (!Number.isFinite(endBounds.x) || !Number.isFinite(endBounds.y) || !Number.isFinite(endBounds.width) || !Number.isFinite(endBounds.height) || endBounds.width < 0 || endBounds.height < 0)) return false;
|
|
506
|
+
clearance = Number.isFinite(clearance) ? Math.max(0, clearance) : 8;
|
|
507
|
+
const startPorts = [], endPorts = [];
|
|
508
|
+
const startCount = getPolylinePorts(startDirection, startPoint, endPoint, startBounds, endBounds, startPorts);
|
|
509
|
+
const endCount = getPolylinePorts(endDirection, endPoint, startPoint, endBounds, startBounds, endPorts);
|
|
510
|
+
const candidate = [], best = [];
|
|
511
|
+
let bestScore = Infinity;
|
|
512
|
+
for (let pass = 0; pass < 2 && bestScore === Infinity; pass++) {
|
|
513
|
+
const currentClearance = pass === 0 ? clearance : 0;
|
|
514
|
+
for (let i = 0; i < startCount; i++) {
|
|
515
|
+
for (let j = 0; j < endCount; j++) {
|
|
516
|
+
const score = points !== undefined ? getPolylineEditPath(candidate, startPoint, endPoint, startPorts[i], endPorts[j], startBounds, endBounds, points, currentClearance) : getPolylineRoute(candidate, startPoint, endPoint, startPorts[i], endPorts[j], startBounds, endBounds, currentClearance);
|
|
517
|
+
if (score < bestScore) {
|
|
518
|
+
bestScore = score;
|
|
519
|
+
best.length = 0;
|
|
520
|
+
for (let k = 0; k < candidate.length; k++) best.push(candidate[k]);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
if (!best.length) return false;
|
|
526
|
+
if (points === undefined) simplifyPolyline(best);
|
|
527
|
+
moveTo$1(path, best[0], best[1]);
|
|
528
|
+
for (let i = 2; i < best.length; i += 2) lineTo$1(path, best[i], best[i + 1]);
|
|
529
|
+
return true;
|
|
530
|
+
}
|
|
531
|
+
const {moveTo: moveTo, lineTo: lineTo, bezierCurveTo: bezierCurveTo, drawPoints: drawPoints$1} = draw.PathCommandDataHelper;
|
|
176
532
|
const {isEmpty: isEmpty, getPoint: getPoint} = draw.BoundsHelper;
|
|
177
533
|
const {getDistance: getDistance} = draw.PointHelper;
|
|
178
534
|
const {getCtrlPoint: getCtrlPoint, getDirectionForFromPoint: getDirectionForFromPoint, isOppositeDirection: isOppositeDirection} = LinkerHelper;
|
|
@@ -260,7 +616,7 @@ this.LeaferIN.linker = function(exports, draw, core) {
|
|
|
260
616
|
}
|
|
261
617
|
}
|
|
262
618
|
updateLinkerPoint(type) {
|
|
263
|
-
const {startPoint: startPoint, endPoint: endPoint} = this;
|
|
619
|
+
const {startPoint: startPoint, endPoint: endPoint, lineType: lineType} = this;
|
|
264
620
|
const nowPoint = type === "end" ? endPoint : startPoint;
|
|
265
621
|
if (nowPoint) {
|
|
266
622
|
const data = {};
|
|
@@ -285,6 +641,7 @@ this.LeaferIN.linker = function(exports, draw, core) {
|
|
|
285
641
|
if (isEmpty(boxBounds)) draw.LeafHelper.updateBounds(ui);
|
|
286
642
|
p = getPoint(boxBounds, point, true);
|
|
287
643
|
ui.getWorldPointByBox(p, this, false, true);
|
|
644
|
+
if (lineType === "polyline") data.bounds = ui.getBounds("box", this.parent);
|
|
288
645
|
}
|
|
289
646
|
} else {
|
|
290
647
|
if (draw.isObject(point)) p = point;
|
|
@@ -310,56 +667,69 @@ this.LeaferIN.linker = function(exports, draw, core) {
|
|
|
310
667
|
}
|
|
311
668
|
const startPoint = startData.point, endPoint = endData.point;
|
|
312
669
|
const startDirection = startData.direction, endDirection = endData.direction;
|
|
313
|
-
const half = {
|
|
314
|
-
x: abs((startPoint.x - endPoint.x) / 2),
|
|
315
|
-
y: abs((startPoint.y - endPoint.y) / 2)
|
|
316
|
-
};
|
|
317
670
|
const arrowWidth = this.__.strokeWidth * 8;
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
671
|
+
switch (data.lineType) {
|
|
672
|
+
case "straight":
|
|
673
|
+
moveTo(path, startPoint.x, startPoint.y);
|
|
674
|
+
lineTo(path, endPoint.x, endPoint.y);
|
|
675
|
+
break;
|
|
676
|
+
|
|
677
|
+
case "polyline":
|
|
678
|
+
drawPolyline(path, startPoint, endPoint, startDirection, endDirection, startData.bounds, endData.bounds, arrowWidth, hasPoints && draw.PointHelper.toNumberPoints(data.points));
|
|
679
|
+
break;
|
|
680
|
+
|
|
681
|
+
case "curve":
|
|
682
|
+
default:
|
|
683
|
+
const half = {
|
|
684
|
+
x: abs((startPoint.x - endPoint.x) / 2),
|
|
685
|
+
y: abs((startPoint.y - endPoint.y) / 2)
|
|
686
|
+
};
|
|
687
|
+
let minCtrl;
|
|
688
|
+
if (this.__.__useArrow) {
|
|
689
|
+
const ratio = min(getDistance(startPoint, endPoint) / (arrowWidth * 25), 1);
|
|
690
|
+
minCtrl = max(arrowWidth * ratio * 12, arrowWidth * 3);
|
|
691
|
+
} else {
|
|
327
692
|
minCtrl = arrowWidth * 2;
|
|
328
693
|
}
|
|
329
|
-
}
|
|
330
|
-
half.x = max(minCtrl, half.x);
|
|
331
|
-
half.y = max(minCtrl, half.y);
|
|
332
|
-
if (hasPoints) {
|
|
333
|
-
minCtrl *= .6;
|
|
334
|
-
const points = draw.PointHelper.toNumberPoints(data.points);
|
|
335
|
-
drawPoints$1(path, [ startPoint.x, startPoint.y, ...points, endPoint.x, endPoint.y ], data.curve, false, data);
|
|
336
|
-
if (startDirection) {
|
|
337
|
-
const handleX = path[4];
|
|
338
|
-
const handleY = path[5];
|
|
339
|
-
half.x = max(minCtrl, abs(handleX - startPoint.x));
|
|
340
|
-
half.y = max(minCtrl, abs(handleY - startPoint.y));
|
|
341
|
-
const startCtrlPoint = getCtrlPoint(this, startNode, startPoint, startDirection, half);
|
|
342
|
-
path[4] = startCtrlPoint.x;
|
|
343
|
-
path[5] = startCtrlPoint.y;
|
|
344
|
-
}
|
|
345
|
-
const len = path.length;
|
|
346
694
|
if (endDirection) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
695
|
+
if (isOppositeDirection(startDirection, endDirection) && startDirection === getDirectionForFromPoint(startPoint, endPoint)) {
|
|
696
|
+
minCtrl = arrowWidth * 2;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
half.x = max(minCtrl, half.x);
|
|
700
|
+
half.y = max(minCtrl, half.y);
|
|
701
|
+
if (hasPoints) {
|
|
702
|
+
minCtrl *= .6;
|
|
703
|
+
const points = draw.PointHelper.toNumberPoints(data.points);
|
|
704
|
+
drawPoints$1(path, [ startPoint.x, startPoint.y, ...points, endPoint.x, endPoint.y ], data.curve, false, data);
|
|
705
|
+
if (startDirection) {
|
|
706
|
+
const handleX = path[4];
|
|
707
|
+
const handleY = path[5];
|
|
708
|
+
half.x = max(minCtrl, abs(handleX - startPoint.x));
|
|
709
|
+
half.y = max(minCtrl, abs(handleY - startPoint.y));
|
|
710
|
+
const startCtrlPoint = getCtrlPoint(this, startNode, startPoint, startDirection, half);
|
|
711
|
+
path[4] = startCtrlPoint.x;
|
|
712
|
+
path[5] = startCtrlPoint.y;
|
|
713
|
+
}
|
|
714
|
+
const len = path.length;
|
|
715
|
+
if (endDirection) {
|
|
716
|
+
const handleX = path[len - 4];
|
|
717
|
+
const handleY = path[len - 3];
|
|
718
|
+
half.x = max(minCtrl, abs(handleX - endPoint.x));
|
|
719
|
+
half.y = max(minCtrl, abs(handleY - endPoint.y));
|
|
720
|
+
const endCtrlPoint = getCtrlPoint(this, endNode, endPoint, endDirection, half);
|
|
721
|
+
path[len - 4] = endCtrlPoint.x;
|
|
722
|
+
path[len - 3] = endCtrlPoint.y;
|
|
723
|
+
} else {
|
|
724
|
+
path[len - 4] = endPoint.x;
|
|
725
|
+
path[len - 3] = endPoint.y;
|
|
726
|
+
}
|
|
354
727
|
} else {
|
|
355
|
-
|
|
356
|
-
|
|
728
|
+
const startCtrlPoint = startDirection ? getCtrlPoint(this, startNode, startPoint, startDirection, half) : startPoint;
|
|
729
|
+
const endCtrlPoint = endDirection ? getCtrlPoint(this, endNode, endPoint, endDirection, half) : endPoint;
|
|
730
|
+
moveTo(path, startPoint.x, startPoint.y);
|
|
731
|
+
bezierCurveTo(path, startCtrlPoint.x, startCtrlPoint.y, endCtrlPoint.x, endCtrlPoint.y, endPoint.x, endPoint.y);
|
|
357
732
|
}
|
|
358
|
-
} else {
|
|
359
|
-
const startCtrlPoint = startDirection ? getCtrlPoint(this, startNode, startPoint, startDirection, half) : startPoint;
|
|
360
|
-
const endCtrlPoint = endDirection ? getCtrlPoint(this, endNode, endPoint, endDirection, half) : endPoint;
|
|
361
|
-
moveTo(path, startPoint.x, startPoint.y);
|
|
362
|
-
bezierCurveTo(path, startCtrlPoint.x, startCtrlPoint.y, endCtrlPoint.x, endCtrlPoint.y, endPoint.x, endPoint.y);
|
|
363
733
|
}
|
|
364
734
|
}
|
|
365
735
|
createStartPoint(worldPoint, node, options) {
|
|
@@ -427,6 +797,7 @@ this.LeaferIN.linker = function(exports, draw, core) {
|
|
|
427
797
|
}
|
|
428
798
|
};
|
|
429
799
|
__decorate([ draw.dataProcessor(LinkerData) ], exports.Linker.prototype, "__", void 0);
|
|
800
|
+
__decorate([ draw.boundsType("curve") ], exports.Linker.prototype, "lineType", void 0);
|
|
430
801
|
__decorate([ linkerPointType() ], exports.Linker.prototype, "startPoint", void 0);
|
|
431
802
|
__decorate([ linkerPointType() ], exports.Linker.prototype, "endPoint", void 0);
|
|
432
803
|
__decorate([ draw.pathType({
|
package/dist/linker.min.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var t=require("@leafer-ui/draw"),e=require("@leafer-ui/core");function n(t,e,n,o){var i,r=arguments.length,s=r<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,o);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(s=(r<3?i(s):r>3?i(e,n,s):i(e,n))||s);return r>3&&s&&Object.defineProperty(e,n,s),s}"function"==typeof SuppressedError&&SuppressedError;class o extends t.LineData{get __usePathBox(){return this.path||this.__pathInputed}}const{directionData:i}=t.AroundHelper,r=["top-left","top","top-right","right","bottom-right","bottom","bottom-left","left","center"],s={getCtrlPoint(t,e,n,o,i,r){let s;switch(e&&(n=e.getBoxPoint(n,t)),o){case"left":case"top-left":case"bottom-left":s={x:n.x-i.x,y:n.y};break;case"top":s={x:n.x,y:n.y-i.y};break;case"right":case"top-right":case"bottom-right":s={x:n.x+i.x,y:n.y};break;case"bottom":s={x:n.x,y:n.y+i.y};break;default:s={x:n.x,y:n.y}}return r&&(r=r/180*Math.PI,s={x:(s.x-n.x)*Math.cos(r)-(s.y-n.y)*Math.sin(r)+n.x,y:(s.x-n.x)*Math.sin(r)+(s.y-n.y)*Math.cos(r)+n.y}),e&&e.getWorldPointByBox(s,t,void 0,!0),s},isOppositeDirection(t,e){switch(t){case"left":return"right"==e;case"top":return"bottom"==e;case"right":return"left"==e;case"bottom":return"top"==e;case"center":return"center"==e;default:return!1}},getDirectionForFromPoint(t,e){const n=t.x-e.x,o=t.y-e.y;let i,r=180*Math.atan2(o,n)/Math.PI;return r<0&&(r=360+r),i=r>315||r<45?"left":r>45&&r<135?"top":r>135&&r<225?"right":"bottom",i},getRotateDirection(e,n,o=8){let i=t.Direction9[e];return i=(i+Math.round(n/(360/o)))%o,i<0&&(i+=o),r[i]},getDirection:function(e,n,o){const{width:i,height:r}=n,s=t.BoundsHelper.getPoint(n,"center",!0),a=e.x-s.x,d=e.y-s.y;if(!o&&Math.abs(a)<i/4&&Math.abs(d)<r/4)return"center";const h=Math.abs(a)*r,c=Math.abs(d)*i;if(h>c)return a>0?"right":"left";return d>0?"bottom":"top"},getPointDirection:function(t,e,n){const{width:o,height:s}=e,a=o/4,d=s/4;for(let e=0;e<i.length;e++){const h=i[e],c=h.x*o,p=h.y*s,u=t.x-c,l=t.y-p;if(Math.abs(u)<=a&&Math.abs(l)<=d){if(!n)return r[e];if("center"!==r[e])return r[e]}}return},autoRotatePoint(e,n,o){const{rotation:i,scaleX:r,scaleY:s}=o,a=r*s<0;(i||a)&&t.PointHelper.rotate(e,a?-i:i,n)}};function a(e){return t.decorateLeafAttr(e,e=>t.attr({set(n){if(this.__setAttr(e,n)){const e=this.__layout;e.linkerChanged||(t.doBoundsType(this),t.doStrokeType(this),e.linkerChanged=!0)}}}))}const{moveTo:d,bezierCurveTo:h,drawPoints:c}=t.PathCommandDataHelper,{isEmpty:p,getPoint:u}=t.BoundsHelper,{getDistance:l}=t.PointHelper,{getCtrlPoint:f,getDirectionForFromPoint:x,isOppositeDirection:y}=s,{max:g,min:P,abs:k}=Math;exports.Linker=class extends t.Line{get __tag(){return"Linker"}constructor(t){super(t),this.onStartNodeChange=this.onStartNodeChange.bind(this),this.onEndNodeChange=this.onEndNodeChange.bind(this)}__updatePath(){const t=this.__layout,{startNode:e,endNode:n}=this;t.linkerChanged&&(this.updateLinkerNode("start"),this.updateLinkerNode("end"),this.updateLinkerPoint("start"),this.updateLinkerPoint("end"),e!==this.startNode&&this.listenLinkerNode(this.startNode,e,"start"),n!==this.endNode&&this.listenLinkerNode(this.endNode,n,"end"),t.linkerChanged=!1),this.updateLinkerPath()}listenLinkerNode(e,n,o){if(n){n.off(t.BoundsEvent.WORLD,"end"===o?this.onEndNodeChange:this.onStartNodeChange);const e="end"===o?n.endLinker:n.startLinker;if(e){const t=e.indexOf(this);t>-1&&e.splice(t,1)}}if(e){e.on(t.BoundsEvent.WORLD,"end"===o?this.onEndNodeChange:this.onStartNodeChange);("end"===o?e.endLinker||(e.endLinker=[]):e.startLinker||(e.startLinker=[])).push(this)}}onStartNodeChange(){this.onLinkerNodeChange("start")}onEndNodeChange(){this.onLinkerNodeChange("end")}onLinkerNodeChange(e){if(this.leaferIsCreated){const{layouter:t,zoomLayer:e}=this.leafer;if(t.__updatedList.has(e))return;t.addExtra(this,!0)}const{startData:n,endData:o}=this;"start"==e?(this.updateLinkerPoint("start"),o&&o.auto&&this.updateLinkerPoint("end")):(n&&n.auto&&this.updateLinkerPoint("start"),this.updateLinkerPoint("end")),this.__layout.boxChange(),t.LeafHelper.updateBounds(this)}updateLinkerNode(e){const{startPoint:n,endPoint:o}=this,i="end"===e?o:n;if(i){const{id:n}=i,o=n&&(t.isString(n)?this.app.findId(n):n);"end"===e?this.endNode=o:this.startNode=o}}getLinkerNodeCenter(e){const{startPoint:n,endPoint:o,startNode:i,endNode:r,startData:s,endData:a}=this,d="end"===e?r:i,h="end"===e?a||o:s||n;if(d){const{worldRenderBounds:e}=d;return p(e)&&t.LeafHelper.updateBounds(d),u(d.worldRenderBounds,"center")}return h&&t.isObject(h.point)&&this.getWorldPointByLocal(h.point)}updateLinkerPoint(e){const{startPoint:n,endPoint:o}=this,i="end"===e?o:n;if(i){const n={},{id:o,offset:r}=i;let{direction:s,point:a}=i;if("center"===s||!s&&o&&!a){const t=this.getLinkerNodeCenter("start"),o=this.getLinkerNodeCenter("end"),i="end"===e?o:t,r="end"===e?t:o;i&&r&&(s=x(i,r)),n.auto=!0}!s&&t.isString(a)&&(s=a),n.direction=s;const d="end"===e?this.endNode:this.startNode;let h;if(d){if(a||(a=s),a){const{boxBounds:e}=d;p(e)&&t.LeafHelper.updateBounds(d),h=u(e,a,!0),d.getWorldPointByBox(h,this,!1,!0)}}else t.isObject(a)&&(h=a);if(h&&r){const e=Object.assign({},r);r.x||(e.x=0),r.y||(e.y=0),d&&d.getWorldPoint(e,this,!0,!0),t.PointHelper.move(h,e)}n.point=h,"end"===e?this.endData=h&&n:this.startData=h&&n}}updateLinkerPath(){const e=this.__,n=e.path=[],o=e.points&&e.points.length,{startData:i,endData:r,startNode:s,endNode:a}=this;if(!i||!r)return;const p=i.point,u=r.point,L=i.direction,b=r.direction,N={x:k((p.x-u.x)/2),y:k((p.y-u.y)/2)},C=8*this.__.strokeWidth;let M;if(this.__.__useArrow){const t=P(l(p,u)/(25*C),1);M=g(C*t*12,3*C)}else M=2*C;if(b&&y(L,b)&&L===x(p,u)&&(M=2*C),N.x=g(M,N.x),N.y=g(M,N.y),o){M*=.6;const o=t.PointHelper.toNumberPoints(e.points);if(c(n,[p.x,p.y,...o,u.x,u.y],e.curve,!1,e),L){const t=n[4],e=n[5];N.x=g(M,k(t-p.x)),N.y=g(M,k(e-p.y));const o=f(this,s,p,L,N);n[4]=o.x,n[5]=o.y}const i=n.length;if(b){const t=n[i-4],e=n[i-3];N.x=g(M,k(t-u.x)),N.y=g(M,k(e-u.y));const o=f(this,a,u,b,N);n[i-4]=o.x,n[i-3]=o.y}else n[i-4]=u.x,n[i-3]=u.y}else{const t=L?f(this,s,p,L,N):p,e=b?f(this,a,u,b,N):u;d(n,p.x,p.y),h(n,t.x,t.y,e.x,e.y,u.x,u.y)}}createStartPoint(t,e,n){const o=this.createLinkerPoint(t,e,n);return this.startPoint=o,o}createEndPoint(t,e,n){const o=this.createLinkerPoint(t,e,n);return this.endPoint=o,o}createLinkerPoint(e,n,o){const i={};if(n&&n.id){const r=n.getBoxPoint(e),{boxBounds:a}=n,d=o&&o.mode,h="edge"===d||!d,c="four"===d,p="free"===d;if(!("auto"===d))if(c)i.point=s.getDirection(r,a,c);else if(i.direction=s.getDirection(r,a,h),i.point=s.getPointDirection(r,a,h)||i.direction,i.point===i.direction&&delete i.direction,p||h){const e=t.BoundsHelper.getPoint(a,i.point),n=r.x-e.x,s=r.y-e.y,d=o&&o.snapRadius||10;if(Math.abs(n)>d||Math.abs(s)>d){const t=i.offset={x:Math.abs(n)>d?n:0,y:Math.abs(s)>d?s:0};if(h&&(t.x||t.y))switch(i.direction||i.point){case"top":case"bottom":t.y=0;break;case"right":case"left":t.x=0;break;default:t.x>t.y?t.y=0:t.x=0}}}i.id=n.id}else i.point=this.getLocalPoint(e);return i}},n([t.dataProcessor(o)],exports.Linker.prototype,"__",void 0),n([a()],exports.Linker.prototype,"startPoint",void 0),n([a()],exports.Linker.prototype,"endPoint",void 0),n([t.pathType({type:"C",value:.5})],exports.Linker.prototype,"curve",void 0),exports.Linker=n([t.registerUI()],exports.Linker);const{toNumberPoints:L}=e.PointHelper,{M:b,L:N,C:C,Z:M}=e.PathCommandMap;t.Plugin.add("linker"),t.registerPointsCurve("C",function(t,e,n,o){const i=L(e),r=i.length>>1;if(r<2)return;if(t.push(b,i[0],i[1]),!n||r<3){for(let e=1;e<r;e++)t.push(N,i[2*e],i[2*e+1]);return void(o&&t.push(M))}let s=!0===n?.5:n;s<0?s=0:s>1&&(s=1);const a=o?r:r-1;let d=i[0],h=i[1];{const t=i[2]-i[0],e=i[3]-i[1],n=Math.sqrt(t*t+e*e);n&&(d=i[0]+t/n*n*s,h=i[1]+e/n*n*s)}for(let e=0;e<a;e++){const n=e+1===r?0:e+1,o=i[2*n],a=i[2*n+1],c=0===n?r-1:n-1,p=n+1===r?0:n+1;let u=i[2*c]-o,l=i[2*c+1]-a,f=i[2*p]-o,x=i[2*p+1]-a;const y=Math.sqrt(u*u+l*l),g=Math.sqrt(f*f+x*x);let P=o,k=a,L=o,b=a;if(y||g){let t=0,e=0;y&&(t+=u/y,e+=l/y),g&&(t+=f/g,e+=x/g);let n=Math.sqrt(t*t+e*e);n||(g?(t=f/g,e=x/g):(t=u/y,e=l/y),n=1),t/=n,e/=n;let i=-e,r=t;g&&i*f+r*x<0&&(i=-i,r=-r);let d=0;y&&g&&(d=(u*f+l*x)/(y*g),d>1?d=1:d<-1&&(d=-1));let h=Math.sqrt(Math.sqrt(Math.max(0,1-d*d)));h<.15&&(h=.15);let c=y*s*h,p=g*s*h;const N=.5*Math.min(y||g,g||y);c>N&&(c=N),p>N&&(p=N),P=o-i*c,k=a-r*c,L=o+i*p,b=a+r*p}t.push(C,d,h,P,k,o,a),d=L,h=b}o&&t.push(M)}),exports.LinkerData=o;
|
|
1
|
+
"use strict";var t=require("@leafer-ui/draw"),e=require("@leafer-ui/core");function n(t,e,n,i){var o,r=arguments.length,s=r<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,i);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(r<3?o(s):r>3?o(e,n,s):o(e,n))||s);return r>3&&s&&Object.defineProperty(e,n,s),s}"function"==typeof SuppressedError&&SuppressedError;class i extends t.LineData{get __usePathBox(){return this.path||this.__pathInputed}}const{directionData:o}=t.AroundHelper,r=["top-left","top","top-right","right","bottom-right","bottom","bottom-left","left","center"],s={getCtrlPoint(t,e,n,i,o,r){let s;switch(e&&(n=e.getBoxPoint(n,t)),i){case"left":case"top-left":case"bottom-left":s={x:n.x-o.x,y:n.y};break;case"top":s={x:n.x,y:n.y-o.y};break;case"right":case"top-right":case"bottom-right":s={x:n.x+o.x,y:n.y};break;case"bottom":s={x:n.x,y:n.y+o.y};break;default:s={x:n.x,y:n.y}}return r&&(r=r/180*Math.PI,s={x:(s.x-n.x)*Math.cos(r)-(s.y-n.y)*Math.sin(r)+n.x,y:(s.x-n.x)*Math.sin(r)+(s.y-n.y)*Math.cos(r)+n.y}),e&&e.getWorldPointByBox(s,t,void 0,!0),s},isOppositeDirection(t,e){switch(t){case"left":return"right"==e;case"top":return"bottom"==e;case"right":return"left"==e;case"bottom":return"top"==e;case"center":return"center"==e;default:return!1}},getDirectionForFromPoint(t,e){const n=t.x-e.x,i=t.y-e.y;let o,r=180*Math.atan2(i,n)/Math.PI;return r<0&&(r=360+r),o=r>315||r<45?"left":r>45&&r<135?"top":r>135&&r<225?"right":"bottom",o},getRotateDirection(e,n,i=8){let o=t.Direction9[e];return o=(o+Math.round(n/(360/i)))%i,o<0&&(o+=i),r[o]},getDirection:function(e,n,i){const{width:o,height:r}=n,s=t.BoundsHelper.getPoint(n,"center",!0),a=e.x-s.x,h=e.y-s.y;if(!i&&Math.abs(a)<o/4&&Math.abs(h)<r/4)return"center";const c=Math.abs(a)*r,u=Math.abs(h)*o;if(c>u)return a>0?"right":"left";return h>0?"bottom":"top"},getPointDirection:function(t,e,n){const{width:i,height:s}=e,a=i/4,h=s/4;for(let e=0;e<o.length;e++){const c=o[e],u=c.x*i,d=c.y*s,l=t.x-u,f=t.y-d;if(Math.abs(l)<=a&&Math.abs(f)<=h){if(!n)return r[e];if("center"!==r[e])return r[e]}}return},autoRotatePoint(e,n,i){const{rotation:o,scaleX:r,scaleY:s}=i,a=r*s<0;(o||a)&&t.PointHelper.rotate(e,a?-o:o,n)}};function a(e){return t.decorateLeafAttr(e,e=>t.attr({set(n){if(this.__setAttr(e,n)){const e=this.__layout;e.linkerChanged||(t.doBoundsType(this),t.doStrokeType(this),e.linkerChanged=!0)}}}))}const{directionData:h}=t.AroundHelper,{moveTo:c,lineTo:u}=t.PathCommandDataHelper,d=.001;function l(t,e,n,i,o,r){const s=h[function(t){switch(t){case"top-left":return 0;case"top":return 1;case"top-right":return 2;case"right":return 3;case"bottom-right":return 4;case"bottom":return 5;case"bottom-left":return 6;case"left":return 7;default:return 8}}(t)],a=Math.sign(s.x-.5),c=Math.sign(s.y-.5),u=i?i.x+i.width/2:e.x,d=i?i.y+i.height/2:e.y,l=(o?o.x+o.width/2:n.x)-u,f=(o?o.y+o.height/2:n.y)-d,p=0+((a||(l>=0?1:-1))>0?1:0),x=2+((c||(f>=0?1:-1))>0?1:0);return a&&!c?(r[0]=p,1):c&&!a?(r[0]=x,1):(Math.abs(l)>=Math.abs(f)?(r[0]=p,r[1]=x):(r[0]=x,r[1]=p),2)}function f(t,e,n,i,o){const r=1&n?1:-1;if(0===n>>1){const n=e?r>0?e.x+e.width:e.x:t.x;o[0]=n+r*i,o[1]=t.y}else{const n=e?r>0?e.y+e.height:e.y:t.y;o[0]=t.x,o[1]=n+r*i}}function p(t,e,n,i){if(!n)return!1;const o=n.x-i,r=n.x+n.width+i,s=n.y-i,a=n.y+n.height+i;return t>o+d&&t<r-d&&e>s+d&&e<a-d}function x(t,e,n,i,o,r){if(!o)return!1;const s=o.x-r,a=o.x+o.width+r,h=o.y-r,c=o.y+o.height+r;return Math.abs(e-i)<=d?e>h+d&&e<c-d&&Math.max(Math.min(t,n),s+d)<Math.min(Math.max(t,n),a-d):!(Math.abs(t-n)<=d)||t>s+d&&t<a-d&&Math.max(Math.min(e,i),h+d)<Math.min(Math.max(e,i),c-d)}function y(t,e,n,i,o){if(!n)return;const r=n.x-i,s=n.x+n.width+i,a=n.y-i,h=n.y+n.height+i;t.push(r,s,r-o,s+o),e.push(a,h,a-o,h+o)}function g(t){t.sort((t,e)=>t-e);let e=0;for(let n=0;n<t.length;n++)(!e||Math.abs(t[n]-t[e-1])>d)&&(t[e++]=t[n]);t.length=e}function b(t,e){for(let n=0;n<t.length;n++)if(Math.abs(t[n]-e)<=d)return n;return-1}function M(t,e,n,i,o,r,s,a){const h=[],c=[];f(e,r,i,a,h),f(n,s,o,a,c);const u=h[0],l=h[1],M=c[0],m=c[1],P=i>>1,k=o>>1,N=1&i?1:-1,C=1&o?1:-1,D=Math.abs(u-e.x)+Math.abs(l-e.y),_=Math.abs(M-n.x)+Math.abs(m-n.y);if(x(e.x,e.y,u,l,s,a)||x(n.x,n.y,M,m,r,a))return 1/0;const w=function(t,e,n,i,o,r){const s=t>>1;return s===e>>1&&(1&t?1:-1)==-(1&e?1:-1)?s:Math.abs(o-n)>=Math.abs(r-i)?0:1}(i,o,u,l,M,m),v=function(t,e,n,i,o,r,s,a,h,c,u){const d=(i+r)/2,l=(o+s)/2;t.length=0,t.push(e.x,e.y,i,o),0===a?t.push(d,o,d,s):t.push(i,l,r,l),t.push(r,s,n.x,n.y);for(let e=4;e<t.length-2;e+=2){const n=t[e-2],i=t[e-1],o=t[e],r=t[e+1];if(x(n,i,o,r,h,u)||x(n,i,o,r,c,u))return 1/0}return L(t,u)}(t,e,n,u,l,M,m,w,r,s,a);if(v<1/0)return v;const B=2*Math.max(a,4),F=[u,M,(u+M)/2],H=[l,m,(l+m)/2];y(F,H,r,a,B),y(F,H,s,a,B);let E=Math.min(...F),T=Math.max(...F),O=Math.min(...H),S=Math.max(...H);F.push(E-2*B,T+2*B),H.push(O-2*B,S+2*B),g(F),g(H);const R=F.length,q=H.length,A=b(F,u),I=b(H,l),W=b(F,M),j=b(H,m);if(A<0||I<0||W<0||j<0)return 1/0;const z=I*R+A,U=j*R+W,X=R*q*3,Y=new Float64Array(X),Z=new Int32Array(X),G=new Uint8Array(X);Y.fill(1/0),Z.fill(-1);const J=3*z;Y[J]=0;const K=Math.max(4,1.5*a);let Q=-1,V=-1,$=0,tt=0,et=0,nt=0;const it=(t,e,n,i)=>{const o=F[t],h=H[e],c=e*R+t;if(p(o,h,r,a)||p(o,h,s,a))return;if(x(tt,et,o,h,r,a)||x(tt,et,o,h,s,a))return;if(Q===J)if(n===P+1){if(i!==N)return}else if(D<=d)return;if(c===U)if(n===k+1){if(i!==-C)return}else if(_<=d)return;const f=3*c+n;if(G[f])return;const y=Math.abs(o-tt)+Math.abs(h-et);let g=nt+y;if($&&$!==n){g+=K;const t=1===$?tt:et,e=0===w?(u+M)/2:(l+m)/2;Math.abs(t-e)>d&&(g+=2*K)}g<Y[f]&&(Y[f]=g,Z[f]=Q)};let ot=-1;for(let t=0;t<X;t++){let t=1/0,e=-1;for(let n=0;n<X;n++)!G[n]&&Y[n]<t&&(t=Y[n],e=n);if(e<0)break;if(Q=e,V=Math.floor(e/3),$=e%3,nt=t,G[e]=1,V===U){ot=e;break}const n=V%R,i=Math.floor(V/R);tt=F[n],et=H[i],n>0&&it(n-1,i,1,-1),n<R-1&&it(n+1,i,1,1),i>0&&it(n,i-1,2,-1),i<q-1&&it(n,i+1,2,1)}if(ot<0)return 1/0;const rt=[];let st=ot;for(;st>=0;){const t=Math.floor(st/3);if(rt.push(F[t%R],H[Math.floor(t/R)]),st===J)break;st=Z[st]}if(st!==J)return 1/0;t.length=0,t.push(e.x,e.y,u,l);for(let e=rt.length-4;e>=0;e-=2)t.push(rt[e],rt[e+1]);return t.push(n.x,n.y),Y[ot]+D+_}function m(t,e,n){const i=t.length;i>=2&&Math.abs(t[i-2]-e)<=d&&Math.abs(t[i-1]-n)<=d||t.push(e,n)}function P(t,e,n,i,o,r=0){if(Math.abs(e-i)>d&&Math.abs(n-o)>d)if(0===r){const r=(e+i)/2;m(t,r,n),m(t,r,o)}else{const r=(n+o)/2;m(t,e,r),m(t,i,r)}m(t,i,o)}function k(t,e,n,i,o,r,s,a,h){if(a.length%2)return 1/0;for(let t=0;t<a.length;t++)if(!Number.isFinite(a[t]))return 1/0;const c=[],u=[];f(e,r,i,h,c),f(n,s,o,h,u);const l=c[0],p=c[1],y=u[0],g=u[1];if(x(e.x,e.y,l,p,s,h)||x(n.x,n.y,y,g,r,h))return 1/0;t.length=0,m(t,e.x,e.y),m(t,l,p);let b=l,M=p;for(let e=0;e<a.length;e+=2){const n=a[e],o=a[e+1];P(t,b,M,n,o,0===e&&0===h?i>>1:0),b=n,M=o}const k=o>>1;return Math.abs(b-y)>d&&Math.abs(M-g)>d&&(0===k?m(t,b,g):m(t,y,M)),m(t,y,g),m(t,n.x,n.y),L(t,h)}function L(t,e){let n=0,i=0,o=-1;for(let e=2;e<t.length;e+=2){const r=t[e]-t[e-2],s=t[e+1]-t[e-1];if(Math.abs(r)<=d&&Math.abs(s)<=d)continue;const a=Math.abs(r)>d?0:1;n+=Math.abs(r)+Math.abs(s),-1!==o&&o!==a&&i++,o=a}return n+i*Math.max(e,4)*1.5}function N(t,e,n,i,o,r,s,a=8,h){if(!(Number.isFinite(e.x)&&Number.isFinite(e.y)&&Number.isFinite(n.x)&&Number.isFinite(n.y)))return!1;if(r&&(!Number.isFinite(r.x)||!Number.isFinite(r.y)||!Number.isFinite(r.width)||!Number.isFinite(r.height)||r.width<0||r.height<0))return!1;if(s&&(!Number.isFinite(s.x)||!Number.isFinite(s.y)||!Number.isFinite(s.width)||!Number.isFinite(s.height)||s.width<0||s.height<0))return!1;a=Number.isFinite(a)?Math.max(0,a):8;const f=[],p=[],x=l(i,e,n,r,s,f),y=l(o,n,e,s,r,p),g=[],b=[];let m=1/0;for(let t=0;t<2&&m===1/0;t++){const i=0===t?a:0;for(let t=0;t<x;t++)for(let o=0;o<y;o++){const a=void 0!==h?k(g,e,n,f[t],p[o],r,s,h,i):M(g,e,n,f[t],p[o],r,s,i);if(a<m){m=a,b.length=0;for(let t=0;t<g.length;t++)b.push(g[t])}}}if(!b.length)return!1;void 0===h&&function(t){let e=2;for(let n=2;n<t.length;n+=2){const i=t[n],o=t[n+1],r=t[e-2],s=t[e-1];if(!(Math.abs(i-r)<=d&&Math.abs(o-s)<=d)){if(e>=4){const n=t[e-4],a=t[e-3],h=Math.abs(a-s)<=d&&Math.abs(s-o)<=d&&(r-n)*(i-r)>=0,c=Math.abs(n-r)<=d&&Math.abs(r-i)<=d&&(s-a)*(o-s)>=0;if(h||c){t[e-2]=i,t[e-1]=o;continue}}t[e++]=i,t[e++]=o}}t.length=e}(b),c(t,b[0],b[1]);for(let e=2;e<b.length;e+=2)u(t,b[e],b[e+1]);return!0}const{moveTo:C,lineTo:D,bezierCurveTo:_,drawPoints:w}=t.PathCommandDataHelper,{isEmpty:v,getPoint:B}=t.BoundsHelper,{getDistance:F}=t.PointHelper,{getCtrlPoint:H,getDirectionForFromPoint:E,isOppositeDirection:T}=s,{max:O,min:S,abs:R}=Math;exports.Linker=class extends t.Line{get __tag(){return"Linker"}constructor(t){super(t),this.onStartNodeChange=this.onStartNodeChange.bind(this),this.onEndNodeChange=this.onEndNodeChange.bind(this)}__updatePath(){const t=this.__layout,{startNode:e,endNode:n}=this;t.linkerChanged&&(this.updateLinkerNode("start"),this.updateLinkerNode("end"),this.updateLinkerPoint("start"),this.updateLinkerPoint("end"),e!==this.startNode&&this.listenLinkerNode(this.startNode,e,"start"),n!==this.endNode&&this.listenLinkerNode(this.endNode,n,"end"),t.linkerChanged=!1),this.updateLinkerPath()}listenLinkerNode(e,n,i){if(n){n.off(t.BoundsEvent.WORLD,"end"===i?this.onEndNodeChange:this.onStartNodeChange);const e="end"===i?n.endLinker:n.startLinker;if(e){const t=e.indexOf(this);t>-1&&e.splice(t,1)}}if(e){e.on(t.BoundsEvent.WORLD,"end"===i?this.onEndNodeChange:this.onStartNodeChange);("end"===i?e.endLinker||(e.endLinker=[]):e.startLinker||(e.startLinker=[])).push(this)}}onStartNodeChange(){this.onLinkerNodeChange("start")}onEndNodeChange(){this.onLinkerNodeChange("end")}onLinkerNodeChange(e){if(this.leaferIsCreated){const{layouter:t,zoomLayer:e}=this.leafer;if(t.__updatedList.has(e))return;t.addExtra(this,!0)}const{startData:n,endData:i}=this;"start"==e?(this.updateLinkerPoint("start"),i&&i.auto&&this.updateLinkerPoint("end")):(n&&n.auto&&this.updateLinkerPoint("start"),this.updateLinkerPoint("end")),this.__layout.boxChange(),t.LeafHelper.updateBounds(this)}updateLinkerNode(e){const{startPoint:n,endPoint:i}=this,o="end"===e?i:n;if(o){const{id:n}=o,i=n&&(t.isString(n)?this.app.findId(n):n);"end"===e?this.endNode=i:this.startNode=i}}getLinkerNodeCenter(e){const{startPoint:n,endPoint:i,startNode:o,endNode:r,startData:s,endData:a}=this,h="end"===e?r:o,c="end"===e?a||i:s||n;if(h){const{worldRenderBounds:e}=h;return v(e)&&t.LeafHelper.updateBounds(h),B(h.worldRenderBounds,"center")}return c&&t.isObject(c.point)&&this.getWorldPointByLocal(c.point)}updateLinkerPoint(e){const{startPoint:n,endPoint:i,lineType:o}=this,r="end"===e?i:n;if(r){const n={},{id:i,offset:s}=r;let{direction:a,point:h}=r;if("center"===a||!a&&i&&!h){const t=this.getLinkerNodeCenter("start"),i=this.getLinkerNodeCenter("end"),o="end"===e?i:t,r="end"===e?t:i;o&&r&&(a=E(o,r)),n.auto=!0}!a&&t.isString(h)&&(a=h),n.direction=a;const c="end"===e?this.endNode:this.startNode;let u;if(c){if(h||(h=a),h){const{boxBounds:e}=c;v(e)&&t.LeafHelper.updateBounds(c),u=B(e,h,!0),c.getWorldPointByBox(u,this,!1,!0),"polyline"===o&&(n.bounds=c.getBounds("box",this.parent))}}else t.isObject(h)&&(u=h);if(u&&s){const e=Object.assign({},s);s.x||(e.x=0),s.y||(e.y=0),c&&c.getWorldPoint(e,this,!0,!0),t.PointHelper.move(u,e)}n.point=u,"end"===e?this.endData=u&&n:this.startData=u&&n}}updateLinkerPath(){const e=this.__,n=e.path=[],i=e.points&&e.points.length,{startData:o,endData:r,startNode:s,endNode:a}=this;if(!o||!r)return;const h=o.point,c=r.point,u=o.direction,d=r.direction,l=8*this.__.strokeWidth;switch(e.lineType){case"straight":C(n,h.x,h.y),D(n,c.x,c.y);break;case"polyline":N(n,h,c,u,d,o.bounds,r.bounds,l,i&&t.PointHelper.toNumberPoints(e.points));break;default:const f={x:R((h.x-c.x)/2),y:R((h.y-c.y)/2)};let p;if(this.__.__useArrow){const t=S(F(h,c)/(25*l),1);p=O(l*t*12,3*l)}else p=2*l;if(d&&T(u,d)&&u===E(h,c)&&(p=2*l),f.x=O(p,f.x),f.y=O(p,f.y),i){p*=.6;const i=t.PointHelper.toNumberPoints(e.points);if(w(n,[h.x,h.y,...i,c.x,c.y],e.curve,!1,e),u){const t=n[4],e=n[5];f.x=O(p,R(t-h.x)),f.y=O(p,R(e-h.y));const i=H(this,s,h,u,f);n[4]=i.x,n[5]=i.y}const o=n.length;if(d){const t=n[o-4],e=n[o-3];f.x=O(p,R(t-c.x)),f.y=O(p,R(e-c.y));const i=H(this,a,c,d,f);n[o-4]=i.x,n[o-3]=i.y}else n[o-4]=c.x,n[o-3]=c.y}else{const t=u?H(this,s,h,u,f):h,e=d?H(this,a,c,d,f):c;C(n,h.x,h.y),_(n,t.x,t.y,e.x,e.y,c.x,c.y)}}}createStartPoint(t,e,n){const i=this.createLinkerPoint(t,e,n);return this.startPoint=i,i}createEndPoint(t,e,n){const i=this.createLinkerPoint(t,e,n);return this.endPoint=i,i}createLinkerPoint(e,n,i){const o={};if(n&&n.id){const r=n.getBoxPoint(e),{boxBounds:a}=n,h=i&&i.mode,c="edge"===h||!h,u="four"===h,d="free"===h;if(!("auto"===h))if(u)o.point=s.getDirection(r,a,u);else if(o.direction=s.getDirection(r,a,c),o.point=s.getPointDirection(r,a,c)||o.direction,o.point===o.direction&&delete o.direction,d||c){const e=t.BoundsHelper.getPoint(a,o.point),n=r.x-e.x,s=r.y-e.y,h=i&&i.snapRadius||10;if(Math.abs(n)>h||Math.abs(s)>h){const t=o.offset={x:Math.abs(n)>h?n:0,y:Math.abs(s)>h?s:0};if(c&&(t.x||t.y))switch(o.direction||o.point){case"top":case"bottom":t.y=0;break;case"right":case"left":t.x=0;break;default:t.x>t.y?t.y=0:t.x=0}}}o.id=n.id}else o.point=this.getLocalPoint(e);return o}},n([t.dataProcessor(i)],exports.Linker.prototype,"__",void 0),n([t.boundsType("curve")],exports.Linker.prototype,"lineType",void 0),n([a()],exports.Linker.prototype,"startPoint",void 0),n([a()],exports.Linker.prototype,"endPoint",void 0),n([t.pathType({type:"C",value:.5})],exports.Linker.prototype,"curve",void 0),exports.Linker=n([t.registerUI()],exports.Linker);const{toNumberPoints:q}=e.PointHelper,{M:A,L:I,C:W,Z:j}=e.PathCommandMap;t.Plugin.add("linker"),t.registerPointsCurve("C",function(t,e,n,i){const o=q(e),r=o.length>>1;if(r<2)return;if(t.push(A,o[0],o[1]),!n||r<3){for(let e=1;e<r;e++)t.push(I,o[2*e],o[2*e+1]);return void(i&&t.push(j))}let s=!0===n?.5:n;s<0?s=0:s>1&&(s=1);const a=i?r:r-1;let h=o[0],c=o[1];{const t=o[2]-o[0],e=o[3]-o[1],n=Math.sqrt(t*t+e*e);n&&(h=o[0]+t/n*n*s,c=o[1]+e/n*n*s)}for(let e=0;e<a;e++){const n=e+1===r?0:e+1,i=o[2*n],a=o[2*n+1],u=0===n?r-1:n-1,d=n+1===r?0:n+1;let l=o[2*u]-i,f=o[2*u+1]-a,p=o[2*d]-i,x=o[2*d+1]-a;const y=Math.sqrt(l*l+f*f),g=Math.sqrt(p*p+x*x);let b=i,M=a,m=i,P=a;if(y||g){let t=0,e=0;y&&(t+=l/y,e+=f/y),g&&(t+=p/g,e+=x/g);let n=Math.sqrt(t*t+e*e);n||(g?(t=p/g,e=x/g):(t=l/y,e=f/y),n=1),t/=n,e/=n;let o=-e,r=t;g&&o*p+r*x<0&&(o=-o,r=-r);let h=0;y&&g&&(h=(l*p+f*x)/(y*g),h>1?h=1:h<-1&&(h=-1));let c=Math.sqrt(Math.sqrt(Math.max(0,1-h*h)));c<.15&&(c=.15);let u=y*s*c,d=g*s*c;const k=.5*Math.min(y||g,g||y);u>k&&(u=k),d>k&&(d=k),b=i-o*u,M=a-r*u,m=i+o*d,P=a+r*d}t.push(W,h,c,b,M,i,a),h=m,c=P}i&&t.push(j)}),exports.LinkerData=i;
|
|
2
2
|
//# sourceMappingURL=linker.min.cjs.map
|