@leafer-in/linker 2.3.3 → 2.3.4

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.js CHANGED
@@ -208,7 +208,7 @@ this.LeaferIN.linker = function(exports, draw, core) {
208
208
  return 8;
209
209
  }
210
210
  }
211
- function getPolylinePorts(direction, point, target, bounds, targetBounds, ports) {
211
+ function getPolylinePorts(direction, point, target, bounds, targetBounds) {
212
212
  const data = directionData[getPolylineDirectionIndex(direction)];
213
213
  const dx = Math.sign(data.x - .5), dy = Math.sign(data.y - .5);
214
214
  const cx = bounds ? bounds.x + bounds.width / 2 : point.x;
@@ -216,38 +216,26 @@ this.LeaferIN.linker = function(exports, draw, core) {
216
216
  const tx = targetBounds ? targetBounds.x + targetBounds.width / 2 : target.x;
217
217
  const ty = targetBounds ? targetBounds.y + targetBounds.height / 2 : target.y;
218
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;
219
+ const xPort = (dx || (deltaX >= 0 ? 1 : -1)) > 0 ? 1 : 0;
220
+ const yPort = (dy || (deltaY >= 0 ? 1 : -1)) > 0 ? 3 : 2;
221
+ if (dx && !dy) return [ xPort ];
222
+ if (dy && !dx) return [ yPort ];
223
+ return Math.abs(deltaX) >= Math.abs(deltaY) ? [ xPort, yPort ] : [ yPort, xPort ];
239
224
  }
240
- function getPolylineExit(point, bounds, port, clearance, result) {
225
+ function getPolylineExit(point, bounds, port, clearance) {
241
226
  const axis = port >> 1, sign = port & 1 ? 1 : -1;
242
227
  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
- }
228
+ const x = bounds ? bounds.x + (sign > 0 ? bounds.width : 0) : point.x;
229
+ return {
230
+ x: x + sign * clearance,
231
+ y: point.y
232
+ };
233
+ }
234
+ const y = bounds ? bounds.y + (sign > 0 ? bounds.height : 0) : point.y;
235
+ return {
236
+ x: point.x,
237
+ y: y + sign * clearance
238
+ };
251
239
  }
252
240
  function isPolylinePointBlocked(x, y, bounds, clearance) {
253
241
  if (!bounds) return false;
@@ -294,44 +282,65 @@ this.LeaferIN.linker = function(exports, draw, core) {
294
282
  if (startAxis === endAxis && startSign === -endSign) return startAxis;
295
283
  return Math.abs(ex - sx) >= Math.abs(ey - sy) ? POLYLINE_X : POLYLINE_Y;
296
284
  }
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);
285
+ function isPolylinePortAligned(port, stub, dx, dy) {
286
+ const offset = port >> 1 === POLYLINE_X ? dx : dy;
287
+ const sign = port & 1 ? 1 : -1;
288
+ return Math.abs(offset) <= POLYLINE_EPSILON ? stub > POLYLINE_EPSILON : offset * sign > 0;
313
289
  }
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;
290
+ function isPolylineMidpointAligned(port, stub, dx, dy, axis) {
291
+ if (port === undefined) return true;
292
+ if (axis === POLYLINE_X && Math.abs(dx / 2) > POLYLINE_EPSILON) return isPolylinePortAligned(port, stub, dx, 0);
293
+ if (axis === POLYLINE_Y && Math.abs(dy / 2) > POLYLINE_EPSILON) return isPolylinePortAligned(port, stub, 0, dy);
294
+ if (Math.abs(dx) <= POLYLINE_EPSILON && Math.abs(dy) <= POLYLINE_EPSILON) return true;
295
+ return isPolylinePortAligned(port, stub, dx, dy);
296
+ }
297
+ function isPolylineApproachAligned(points, port) {
298
+ if (port === undefined) return true;
299
+ const last = points.length - 2, x = points[last], y = points[last + 1];
300
+ for (let i = last - 2; i >= 0; i -= 2) {
301
+ const dx = points[i] - x, dy = points[i + 1] - y;
302
+ if (Math.abs(dx) > POLYLINE_EPSILON || Math.abs(dy) > POLYLINE_EPSILON) return isPolylinePortAligned(port, 1, dx, dy);
303
+ }
304
+ return true;
305
+ }
306
+ function getPolylineRoute(result, startPoint, endPoint, startPort, endPort, startBounds, endBounds, clearance, strictPorts, approachPort) {
307
+ const startExit = getPolylineExit(startPoint, startBounds, startPort, clearance);
308
+ const endExit = endPort === undefined ? endPoint : getPolylineExit(endPoint, endBounds, endPort, clearance);
309
+ const {x: sx, y: sy} = startExit, {x: ex, y: ey} = endExit;
321
310
  const startStub = Math.abs(sx - startPoint.x) + Math.abs(sy - startPoint.y);
322
311
  const endStub = Math.abs(ex - endPoint.x) + Math.abs(ey - endPoint.y);
323
312
  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;
313
+ if (endPort === undefined && (isPolylinePointBlocked(ex, ey, startBounds, clearance) || isPolylinePointBlocked(ex, ey, endBounds, clearance))) return Infinity;
314
+ const axis = endPort === undefined ? startPort >> 1 : getPolylineMidpointAxis(startPort, endPort, sx, sy, ex, ey);
315
+ const dx = ex - sx, dy = ey - sy;
316
+ result.length = 0;
317
+ result.push(startPoint.x, startPoint.y, sx, sy);
318
+ if ((!strictPorts || isPolylineMidpointAligned(startPort, startStub, dx, dy, axis) && isPolylineMidpointAligned(endPort, endStub, -dx, -dy, axis)) && isPolylineMidpointAligned(approachPort, 1, -dx, -dy, axis)) {
319
+ const mx = (sx + ex) / 2, my = (sy + ey) / 2;
320
+ if (axis === POLYLINE_X) result.push(mx, sy, mx, ey); else result.push(sx, my, ex, my);
321
+ result.push(ex, ey, endPoint.x, endPoint.y);
322
+ for (let i = 4; i < result.length - 2; i += 2) {
323
+ if (isPolylineSegmentBlocked(result[i - 2], result[i - 1], result[i], result[i + 1], startBounds, clearance) || isPolylineSegmentBlocked(result[i - 2], result[i - 1], result[i], result[i + 1], endBounds, clearance)) {
324
+ result.length = 4;
325
+ break;
326
+ }
327
+ }
328
+ if (result.length > 4 && isPolylineApproachAligned(result, approachPort)) return getPolylineScore(result, clearance);
329
+ result.length = 4;
330
+ }
331
+ const score = findPolylineGridRoute(result, startExit, endExit, startPort, endPort, startBounds, endBounds, clearance, axis, startStub, endStub, strictPorts, approachPort);
332
+ if (score === Infinity) return score;
333
+ result.push(endPoint.x, endPoint.y);
334
+ return isPolylineApproachAligned(result, approachPort) ? score + startStub + endStub : Infinity;
335
+ }
336
+ function findPolylineGridRoute(result, startExit, endExit, startPort, endPort, startBounds, endBounds, clearance, midpointAxis, startStub, endStub, strictPorts, approachPort) {
337
+ const {x: sx, y: sy} = startExit, {x: ex, y: ey} = endExit;
327
338
  const margin = Math.max(clearance, POLYLINE_MIN_SEGMENT) * 2;
328
339
  const xs = [ sx, ex, (sx + ex) / 2 ], ys = [ sy, ey, (sy + ey) / 2 ];
329
340
  addPolylineBoundsCoordinates(xs, ys, startBounds, clearance, margin);
330
341
  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);
342
+ xs.push(Math.min(...xs) - margin * 2, Math.max(...xs) + margin * 2);
343
+ ys.push(Math.min(...ys) - margin * 2, Math.max(...ys) + margin * 2);
335
344
  sortPolylineCoordinates(xs);
336
345
  sortPolylineCoordinates(ys);
337
346
  const nx = xs.length, ny = ys.length;
@@ -345,53 +354,49 @@ this.LeaferIN.linker = function(exports, draw, core) {
345
354
  previous.fill(-1);
346
355
  const startState = startNode * 3;
347
356
  distance[startState] = 0;
357
+ const pending = [ startState ];
348
358
  const turnCost = Math.max(POLYLINE_MIN_SEGMENT, clearance * POLYLINE_TURN_WEIGHT);
359
+ const preferredCoordinate = midpointAxis === POLYLINE_X ? (sx + ex) / 2 : (sy + ey) / 2;
349
360
  let currentState = -1, currentNode = -1, currentAxis = 0;
350
361
  let currentX = 0, currentY = 0, currentDistance = 0;
351
- const relax = (nextXIndex, nextYIndex, axis, sign) => {
362
+ const relax = (nextXIndex, nextYIndex, axis) => {
352
363
  const nextX = xs[nextXIndex], nextY = ys[nextYIndex];
353
364
  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
- }
365
+ const dx = nextX - currentX, dy = nextY - currentY;
366
+ if (nextNode === startNode) return;
367
+ if (approachPort !== undefined && nextNode === endNode && !isPolylinePortAligned(approachPort, 1, -dx, -dy)) return;
368
+ if (strictPorts && (currentState === startState && !isPolylinePortAligned(startPort, startStub, dx, dy) || endPort !== undefined && nextNode === endNode && !isPolylinePortAligned(endPort, endStub, -dx, -dy))) return;
369
+ if (isPolylinePointBlocked(nextX, nextY, startBounds, clearance) || isPolylinePointBlocked(nextX, nextY, endBounds, clearance) || isPolylineSegmentBlocked(currentX, currentY, nextX, nextY, startBounds, clearance) || isPolylineSegmentBlocked(currentX, currentY, nextX, nextY, endBounds, clearance)) return;
366
370
  const nextState = nextNode * 3 + axis;
367
371
  if (visited[nextState]) return;
368
- const segmentLength = Math.abs(nextX - currentX) + Math.abs(nextY - currentY);
369
- let cost = currentDistance + segmentLength;
372
+ let cost = currentDistance + (Math.abs(dx) + Math.abs(dy));
370
373
  if (currentAxis && currentAxis !== axis) {
371
374
  cost += turnCost;
372
375
  const turnCoordinate = currentAxis === POLYLINE_X + 1 ? currentX : currentY;
373
- const preferredCoordinate = midpointAxis === POLYLINE_X ? (sx + ex) / 2 : (sy + ey) / 2;
374
376
  if (Math.abs(turnCoordinate - preferredCoordinate) > POLYLINE_EPSILON) cost += turnCost * 2;
375
377
  }
376
378
  if (cost < distance[nextState]) {
379
+ if (distance[nextState] === Infinity) pending.push(nextState);
377
380
  distance[nextState] = cost;
378
381
  previous[nextState] = currentState;
379
382
  }
380
383
  };
381
384
  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;
385
+ while (pending.length) {
386
+ let index = 0, state = pending[0];
387
+ for (let i = 1; i < pending.length; i++) {
388
+ const next = pending[i];
389
+ if (distance[next] < distance[state] || distance[next] === distance[state] && next < state) {
390
+ index = i;
391
+ state = next;
388
392
  }
389
393
  }
390
- if (state < 0) break;
394
+ pending[index] = pending[pending.length - 1];
395
+ pending.pop();
391
396
  currentState = state;
392
397
  currentNode = Math.floor(state / 3);
393
398
  currentAxis = state % 3;
394
- currentDistance = minDistance;
399
+ currentDistance = distance[state];
395
400
  visited[state] = 1;
396
401
  if (currentNode === endNode) {
397
402
  bestState = state;
@@ -400,10 +405,10 @@ this.LeaferIN.linker = function(exports, draw, core) {
400
405
  const xIndex = currentNode % nx, yIndex = Math.floor(currentNode / nx);
401
406
  currentX = xs[xIndex];
402
407
  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);
408
+ if (xIndex > 0) relax(xIndex - 1, yIndex, POLYLINE_X + 1);
409
+ if (xIndex < nx - 1) relax(xIndex + 1, yIndex, POLYLINE_X + 1);
410
+ if (yIndex > 0) relax(xIndex, yIndex - 1, POLYLINE_Y + 1);
411
+ if (yIndex < ny - 1) relax(xIndex, yIndex + 1, POLYLINE_Y + 1);
407
412
  }
408
413
  if (bestState < 0) return Infinity;
409
414
  const reverse = [];
@@ -415,56 +420,79 @@ this.LeaferIN.linker = function(exports, draw, core) {
415
420
  state = previous[state];
416
421
  }
417
422
  if (state !== startState) return Infinity;
418
- result.length = 0;
419
- result.push(startPoint.x, startPoint.y, sx, sy);
420
423
  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;
424
+ return distance[bestState];
423
425
  }
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);
426
+ function getPolylineFallback(start, end, port, startBounds, endBounds) {
427
+ const {x: sx, y: sy} = start, {x: ex, y: ey} = end;
428
+ if (sx === ex || sy === ey) return [ sx, sy, ex, ey ];
429
+ const horizontal = port >> 1 === POLYLINE_X;
430
+ const crosses = (x, y) => {
431
+ let count = 0;
432
+ if (isPolylineSegmentBlocked(sx, sy, x, y, startBounds, 0)) count++;
433
+ if (isPolylineSegmentBlocked(x, y, ex, ey, startBounds, 0)) count++;
434
+ if (isPolylineSegmentBlocked(sx, sy, x, y, endBounds, 0)) count++;
435
+ if (isPolylineSegmentBlocked(x, y, ex, ey, endBounds, 0)) count++;
436
+ return count;
437
+ };
438
+ const xy = crosses(ex, sy), yx = crosses(sx, ey);
439
+ return xy < yx || xy === yx && horizontal ? [ sx, sy, ex, sy, ex, ey ] : [ sx, sy, sx, ey, ex, ey ];
428
440
  }
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);
441
+ function getBestPolyline(startPoint, endPoint, startDirection, endDirection, startBounds, endBounds, clearance, approachPort) {
442
+ const startPorts = getPolylinePorts(startDirection, startPoint, endPoint, startBounds, endDirection === undefined ? undefined : endBounds);
443
+ const endPorts = endDirection === undefined ? [ undefined ] : getPolylinePorts(endDirection, endPoint, startPoint, endBounds, startBounds);
444
+ let candidate = [], best = [], bestScore = Infinity;
445
+ for (let pass = clearance ? 0 : 1; pass < 3 && !best.length; pass++) {
446
+ const gap = pass ? 0 : clearance;
447
+ for (let i = 0; i < startPorts.length; i++) {
448
+ for (let j = 0; j < endPorts.length; j++) {
449
+ const score = getPolylineRoute(candidate, startPoint, endPoint, startPorts[i], endPorts[j], startBounds, endBounds, gap, pass < 2, approachPort);
450
+ if (score < bestScore) {
451
+ bestScore = score;
452
+ const previous = best;
453
+ best = candidate;
454
+ candidate = previous;
455
+ }
456
+ }
439
457
  }
440
458
  }
441
- appendPolylinePoint(points, x2, y2);
459
+ if (!best.length) return getPolylineFallback(startPoint, endPoint, startPorts[0], startBounds, endBounds);
460
+ simplifyPolyline(best);
461
+ const last = best.length - 2;
462
+ if (best[last] !== endPoint.x || best[last + 1] !== endPoint.y) best.push(endPoint.x, endPoint.y);
463
+ return best;
442
464
  }
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);
465
+ function getPolylineEditSide(point, waypoint, direction, bounds, otherBounds, clearance, points, index, step) {
466
+ if (point.x === waypoint.x && point.y === waypoint.y) return [];
467
+ let approachPort;
468
+ for (let i = index + step; i >= 0 && i < points.length; i += step) {
469
+ const dx = points[i] - waypoint.x, dy = points[i + 1] - waypoint.y;
470
+ if (Math.abs(dx) <= POLYLINE_EPSILON && Math.abs(dy) <= POLYLINE_EPSILON) continue;
471
+ if (Math.abs(dy) <= POLYLINE_EPSILON) approachPort = dx > 0 ? 0 : 1; else if (Math.abs(dx) <= POLYLINE_EPSILON) approachPort = dy > 0 ? 2 : 3;
472
+ break;
473
+ }
474
+ const side = getBestPolyline(point, waypoint, direction, undefined, bounds, otherBounds, clearance, approachPort);
475
+ side.length -= 2;
476
+ return side;
477
+ }
478
+ function drawPolylineEditPath(path, startPoint, endPoint, startDirection, endDirection, startBounds, endBounds, clearance, points) {
479
+ const length = points.length, last = length - 2;
480
+ if (length % 2) return false;
481
+ for (let i = 0; i < length; i++) if (!Number.isFinite(points[i])) return false;
482
+ const start = getPolylineEditSide(startPoint, {
483
+ x: points[0],
484
+ y: points[1]
485
+ }, startDirection, startBounds, endBounds, clearance, points, 0, 2);
486
+ const end = getPolylineEditSide(endPoint, {
487
+ x: points[last],
488
+ y: points[last + 1]
489
+ }, endDirection, endBounds, startBounds, clearance, points, last, -2);
490
+ const first = start.length ? start : points;
491
+ moveTo$1(path, first[0], first[1]);
492
+ for (let i = 2; i < start.length; i += 2) lineTo$1(path, start[i], start[i + 1]);
493
+ for (let i = start.length ? 0 : 2; i < length; i += 2) lineTo$1(path, points[i], points[i + 1]);
494
+ for (let i = end.length - 2; i >= 0; i -= 2) lineTo$1(path, end[i], end[i + 1]);
495
+ return true;
468
496
  }
469
497
  function getPolylineScore(points, clearance) {
470
498
  let length = 0, turns = 0, previousAxis = -1;
@@ -504,26 +532,8 @@ this.LeaferIN.linker = function(exports, draw, core) {
504
532
  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
533
  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
534
  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);
535
+ if (points === null || points === void 0 ? void 0 : points.length) return drawPolylineEditPath(path, startPoint, endPoint, startDirection, endDirection, startBounds, endBounds, clearance, points);
536
+ const best = getBestPolyline(startPoint, endPoint, startDirection, endDirection, startBounds, endBounds, clearance);
527
537
  moveTo$1(path, best[0], best[1]);
528
538
  for (let i = 2; i < best.length; i += 2) lineTo$1(path, best[i], best[i + 1]);
529
539
  return true;
@@ -1,2 +1,2 @@
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;
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 u=Math.abs(a)*r,c=Math.abs(h)*o;if(u>c)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 u=o[e],c=u.x*i,d=u.y*s,l=t.x-c,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:u,lineTo:c}=t.PathCommandDataHelper,d=.001,l=1.5;function f(t,e,n,i,o){const r=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)],s=Math.sign(r.x-.5),a=Math.sign(r.y-.5),u=i?i.x+i.width/2:e.x,c=i?i.y+i.height/2:e.y,d=(o?o.x+o.width/2:n.x)-u,l=(o?o.y+o.height/2:n.y)-c,f=(s||(d>=0?1:-1))>0?1:0,p=(a||(l>=0?1:-1))>0?3:2;return s&&!a?[f]:a&&!s?[p]:Math.abs(d)>=Math.abs(l)?[f,p]:[p,f]}function p(t,e,n,i){const o=1&n?1:-1;if(0===n>>1){return{x:(e?e.x+(o>0?e.width:0):t.x)+o*i,y:t.y}}const r=e?e.y+(o>0?e.height:0):t.y;return{x:t.x,y:r+o*i}}function x(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 y(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,u=o.y+o.height+r;return Math.abs(e-i)<=d?e>h+d&&e<u-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),u-d)}function g(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 b(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 M(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){const o=t>>1?i:n,r=1&t?1:-1;return Math.abs(o)<=d?e>d:o*r>0}function P(t,e,n,i,o){return void 0===t||(0===o&&Math.abs(n/2)>d?m(t,e,n,0):1===o&&Math.abs(i/2)>d?m(t,e,0,i):Math.abs(n)<=d&&Math.abs(i)<=d||m(t,e,n,i))}function k(t,e){if(void 0===e)return!0;const n=t.length-2,i=t[n],o=t[n+1];for(let r=n-2;r>=0;r-=2){const n=t[r]-i,s=t[r+1]-o;if(Math.abs(n)>d||Math.abs(s)>d)return m(e,1,n,s)}return!0}function L(t,e,n,i,o,r,s,a,h,u){const c=p(e,r,i,a),f=void 0===o?n:p(n,s,o,a),{x:L,y:N}=c,{x:v,y:C}=f,D=Math.abs(L-e.x)+Math.abs(N-e.y),_=Math.abs(v-n.x)+Math.abs(C-n.y);if(y(e.x,e.y,L,N,s,a)||y(n.x,n.y,v,C,r,a))return 1/0;if(void 0===o&&(x(v,C,r,a)||x(v,C,s,a)))return 1/0;const w=void 0===o?i>>1: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,L,N,v,C),B=v-L,F=C-N;if(t.length=0,t.push(e.x,e.y,L,N),(!h||P(i,D,B,F,w)&&P(o,_,-B,-F,w))&&P(u,1,-B,-F,w)){const e=(L+v)/2,i=(N+C)/2;0===w?t.push(e,N,e,C):t.push(L,i,v,i),t.push(v,C,n.x,n.y);for(let e=4;e<t.length-2;e+=2)if(y(t[e-2],t[e-1],t[e],t[e+1],r,a)||y(t[e-2],t[e-1],t[e],t[e+1],s,a)){t.length=4;break}if(t.length>4&&k(t,u))return function(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}(t,a);t.length=4}const H=function(t,e,n,i,o,r,s,a,h,u,c,f,p){const{x:P,y:k}=e,{x:L,y:N}=n,v=2*Math.max(a,4),C=[P,L,(P+L)/2],D=[k,N,(k+N)/2];g(C,D,r,a,v),g(C,D,s,a,v),C.push(Math.min(...C)-2*v,Math.max(...C)+2*v),D.push(Math.min(...D)-2*v,Math.max(...D)+2*v),b(C),b(D);const _=C.length,w=D.length,B=M(C,P),F=M(D,k),H=M(C,L),E=M(D,N);if(B<0||F<0||H<0||E<0)return 1/0;const T=F*_+B,O=E*_+H,S=_*w*3,R=new Float64Array(S),q=new Int32Array(S),A=new Uint8Array(S);R.fill(1/0),q.fill(-1);const I=3*T;R[I]=0;const W=[I],j=Math.max(4,a*l),z=0===h?(P+L)/2:(k+N)/2;let U=-1,X=-1,Y=0,Z=0,G=0,J=0;const K=(t,e,n)=>{const h=C[t],l=D[e],g=e*_+t,b=h-Z,M=l-G;if(g===T)return;if(void 0!==p&&g===O&&!m(p,1,-b,-M))return;if(f&&(U===I&&!m(i,u,b,M)||void 0!==o&&g===O&&!m(o,c,-b,-M)))return;if(x(h,l,r,a)||x(h,l,s,a)||y(Z,G,h,l,r,a)||y(Z,G,h,l,s,a))return;const P=3*g+n;if(A[P])return;let k=J+(Math.abs(b)+Math.abs(M));if(Y&&Y!==n){k+=j;const t=1===Y?Z:G;Math.abs(t-z)>d&&(k+=2*j)}k<R[P]&&(R[P]===1/0&&W.push(P),R[P]=k,q[P]=U)};let Q=-1;for(;W.length;){let t=0,e=W[0];for(let n=1;n<W.length;n++){const i=W[n];(R[i]<R[e]||R[i]===R[e]&&i<e)&&(t=n,e=i)}if(W[t]=W[W.length-1],W.pop(),U=e,X=Math.floor(e/3),Y=e%3,J=R[e],A[e]=1,X===O){Q=e;break}const n=X%_,i=Math.floor(X/_);Z=C[n],G=D[i],n>0&&K(n-1,i,1),n<_-1&&K(n+1,i,1),i>0&&K(n,i-1,2),i<w-1&&K(n,i+1,2)}if(Q<0)return 1/0;const V=[];let $=Q;for(;$>=0;){const t=Math.floor($/3);if(V.push(C[t%_],D[Math.floor(t/_)]),$===I)break;$=q[$]}if($!==I)return 1/0;for(let e=V.length-4;e>=0;e-=2)t.push(V[e],V[e+1]);return R[Q]}(t,c,f,i,o,r,s,a,w,D,_,h,u);return H===1/0?H:(t.push(n.x,n.y),k(t,u)?H+D+_:1/0)}function N(t,e,n,i,o,r,s,a){const h=f(n,t,e,o,void 0===i?void 0:r),u=void 0===i?[void 0]:f(i,e,t,r,o);let c=[],l=[],p=1/0;for(let n=s?0:1;n<3&&!l.length;n++){const i=n?0:s;for(let s=0;s<h.length;s++)for(let d=0;d<u.length;d++){const f=L(c,t,e,h[s],u[d],o,r,i,n<2,a);if(f<p){p=f;const t=l;l=c,c=t}}}if(!l.length)return function(t,e,n,i,o){const{x:r,y:s}=t,{x:a,y:h}=e;if(r===a||s===h)return[r,s,a,h];const u=!(n>>1),c=(t,e)=>{let n=0;return y(r,s,t,e,i,0)&&n++,y(t,e,a,h,i,0)&&n++,y(r,s,t,e,o,0)&&n++,y(t,e,a,h,o,0)&&n++,n},d=c(a,s),l=c(r,h);return d<l||d===l&&u?[r,s,a,s,a,h]:[r,s,r,h,a,h]}(t,e,h[0],o,r);!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,u=Math.abs(n-r)<=d&&Math.abs(r-i)<=d&&(s-a)*(o-s)>=0;if(h||u){t[e-2]=i,t[e-1]=o;continue}}t[e++]=i,t[e++]=o}}t.length=e}(l);const x=l.length-2;return l[x]===e.x&&l[x+1]===e.y||l.push(e.x,e.y),l}function v(t,e,n,i,o,r,s,a,h){if(t.x===e.x&&t.y===e.y)return[];let u;for(let t=a+h;t>=0&&t<s.length;t+=h){const n=s[t]-e.x,i=s[t+1]-e.y;if(!(Math.abs(n)<=d&&Math.abs(i)<=d)){Math.abs(i)<=d?u=n>0?0:1:Math.abs(n)<=d&&(u=i>0?2:3);break}}const c=N(t,e,n,void 0,i,o,r,u);return c.length-=2,c}function C(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;if(a=Number.isFinite(a)?Math.max(0,a):8,null==h?void 0:h.length)return function(t,e,n,i,o,r,s,a,h){const d=h.length,l=d-2;if(d%2)return!1;for(let t=0;t<d;t++)if(!Number.isFinite(h[t]))return!1;const f=v(e,{x:h[0],y:h[1]},i,r,s,a,h,0,2),p=v(n,{x:h[l],y:h[l+1]},o,s,r,a,h,l,-2),x=f.length?f:h;u(t,x[0],x[1]);for(let e=2;e<f.length;e+=2)c(t,f[e],f[e+1]);for(let e=f.length?0:2;e<d;e+=2)c(t,h[e],h[e+1]);for(let e=p.length-2;e>=0;e-=2)c(t,p[e],p[e+1]);return!0}(t,e,n,i,o,r,s,a,h);const d=N(e,n,i,o,r,s,a);u(t,d[0],d[1]);for(let e=2;e<d.length;e+=2)c(t,d[e],d[e+1]);return!0}const{moveTo:D,lineTo:_,bezierCurveTo:w,drawPoints:B}=t.PathCommandDataHelper,{isEmpty:F,getPoint:H}=t.BoundsHelper,{getDistance:E}=t.PointHelper,{getCtrlPoint:T,getDirectionForFromPoint:O,isOppositeDirection:S}=s,{max:R,min:q,abs:A}=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,u="end"===e?a||i:s||n;if(h){const{worldRenderBounds:e}=h;return F(e)&&t.LeafHelper.updateBounds(h),H(h.worldRenderBounds,"center")}return u&&t.isObject(u.point)&&this.getWorldPointByLocal(u.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=O(o,r)),n.auto=!0}!a&&t.isString(h)&&(a=h),n.direction=a;const u="end"===e?this.endNode:this.startNode;let c;if(u){if(h||(h=a),h){const{boxBounds:e}=u;F(e)&&t.LeafHelper.updateBounds(u),c=H(e,h,!0),u.getWorldPointByBox(c,this,!1,!0),"polyline"===o&&(n.bounds=u.getBounds("box",this.parent))}}else t.isObject(h)&&(c=h);if(c&&s){const e=Object.assign({},s);s.x||(e.x=0),s.y||(e.y=0),u&&u.getWorldPoint(e,this,!0,!0),t.PointHelper.move(c,e)}n.point=c,"end"===e?this.endData=c&&n:this.startData=c&&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,u=r.point,c=o.direction,d=r.direction,l=8*this.__.strokeWidth;switch(e.lineType){case"straight":D(n,h.x,h.y),_(n,u.x,u.y);break;case"polyline":C(n,h,u,c,d,o.bounds,r.bounds,l,i&&t.PointHelper.toNumberPoints(e.points));break;default:const f={x:A((h.x-u.x)/2),y:A((h.y-u.y)/2)};let p;if(this.__.__useArrow){const t=q(E(h,u)/(25*l),1);p=R(l*t*12,3*l)}else p=2*l;if(d&&S(c,d)&&c===O(h,u)&&(p=2*l),f.x=R(p,f.x),f.y=R(p,f.y),i){p*=.6;const i=t.PointHelper.toNumberPoints(e.points);if(B(n,[h.x,h.y,...i,u.x,u.y],e.curve,!1,e),c){const t=n[4],e=n[5];f.x=R(p,A(t-h.x)),f.y=R(p,A(e-h.y));const i=T(this,s,h,c,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=R(p,A(t-u.x)),f.y=R(p,A(e-u.y));const i=T(this,a,u,d,f);n[o-4]=i.x,n[o-3]=i.y}else n[o-4]=u.x,n[o-3]=u.y}else{const t=c?T(this,s,h,c,f):h,e=d?T(this,a,u,d,f):u;D(n,h.x,h.y),w(n,t.x,t.y,e.x,e.y,u.x,u.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,u="edge"===h||!h,c="four"===h,d="free"===h;if(!("auto"===h))if(c)o.point=s.getDirection(r,a,c);else if(o.direction=s.getDirection(r,a,u),o.point=s.getPointDirection(r,a,u)||o.direction,o.point===o.direction&&delete o.direction,d||u){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(u&&(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:I}=e.PointHelper,{M:W,L:j,C:z,Z:U}=e.PathCommandMap;t.Plugin.add("linker"),t.registerPointsCurve("C",function(t,e,n,i){const o=I(e),r=o.length>>1;if(r<2)return;if(t.push(W,o[0],o[1]),!n||r<3){for(let e=1;e<r;e++)t.push(j,o[2*e],o[2*e+1]);return void(i&&t.push(U))}let s=!0===n?.5:n;s<0?s=0:s>1&&(s=1);const a=i?r:r-1;let h=o[0],u=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,u=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],c=0===n?r-1:n-1,d=n+1===r?0:n+1;let l=o[2*c]-i,f=o[2*c+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 u=Math.sqrt(Math.sqrt(Math.max(0,1-h*h)));u<.15&&(u=.15);let c=y*s*u,d=g*s*u;const k=.5*Math.min(y||g,g||y);c>k&&(c=k),d>k&&(d=k),b=i-o*c,M=a-r*c,m=i+o*d,P=a+r*d}t.push(z,h,u,b,M,i,a),h=m,u=P}i&&t.push(U)}),exports.LinkerData=i;
2
2
  //# sourceMappingURL=linker.min.cjs.map