@html-graph/html-graph 8.18.0 → 8.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -623,7 +623,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
623
623
  removeNonexistentPort: (portId) => `Failed to remove port with ID ${JSON.stringify(portId)} because it does not exist`,
624
624
  accessNonexistentEdge: (edgeId) => `Failed to access edge with ID ${JSON.stringify(edgeId)} because it does not exist`,
625
625
  addEdgeWithExistingId: (edgeId) => `Failed to add edge with ID ${JSON.stringify(edgeId)} because an edge with this ID already exists`,
626
- addEdgeWithElementInUse: (edgeId, useEdgeId) => `Failed to add edge with ID ${JSON.stringify(edgeId)} because its SVG element is already attached to edge with ID ${JSON.stringify(useEdgeId)}`,
626
+ addEdgeWithElementInUse: (edgeId, useEdgeId) => `Failed to add edge with ID ${JSON.stringify(edgeId)} because its element is already attached to edge with ID ${JSON.stringify(useEdgeId)}`,
627
627
  addEdgeFromNonexistentPort: (edgeId, portId) => `Failed to add edge with ID ${JSON.stringify(edgeId)} from port with ID ${JSON.stringify(portId)} because the port does not exist`,
628
628
  addEdgeToNonexistentPort: (edgeId, portId) => `Failed to add edge with ID ${JSON.stringify(edgeId)} to port with ID ${JSON.stringify(portId)} because the port does not exist`,
629
629
  updateNonexistentEdge: (edgeId) => `Failed to update edge with ID ${JSON.stringify(edgeId)} because it does not exist`,
@@ -1475,48 +1475,52 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1475
1475
  return parts.join(" ");
1476
1476
  };
1477
1477
  const createLine$1 = (from, to) => {
1478
- const horizontalLineDir = to.x - from.x >= 0;
1478
+ const fromLine = from.linePoint;
1479
+ const toLine = to.linePoint;
1480
+ const horizontalLineDir = toLine.x - fromLine.x >= 0;
1479
1481
  const fromPortDir = from.dirX >= 0;
1480
1482
  const toPortDir = to.dirX >= 0;
1481
1483
  const isSameDirPorts = fromPortDir === toPortDir;
1482
1484
  if (isSameDirPorts) {
1483
1485
  const isSameDirLine = fromPortDir === horizontalLineDir;
1484
- const centerX = (from.x + to.x) / 2;
1485
- const centerY2 = (from.y + to.y) / 2;
1486
+ const centerX = (fromLine.x + toLine.x) / 2;
1487
+ const centerY2 = (fromLine.y + toLine.y) / 2;
1486
1488
  const midpoint = { x: centerX, y: centerY2 };
1487
1489
  if (isSameDirLine) {
1488
1490
  return {
1489
1491
  points: [
1490
- { x: from.x, y: from.y },
1491
- { x: midpoint.x, y: from.y },
1492
- { x: midpoint.x, y: to.y },
1493
- { x: to.x, y: to.y }
1492
+ from.arrowPoint,
1493
+ { x: midpoint.x, y: fromLine.y },
1494
+ { x: midpoint.x, y: toLine.y },
1495
+ to.arrowPoint
1494
1496
  ],
1495
1497
  midpoint
1496
1498
  };
1497
1499
  }
1498
1500
  return {
1499
1501
  points: [
1500
- { x: from.x, y: from.y },
1501
- { x: from.x, y: midpoint.y },
1502
- { x: to.x, y: midpoint.y },
1503
- { x: to.x, y: to.y }
1502
+ from.arrowPoint,
1503
+ fromLine,
1504
+ { x: fromLine.x, y: midpoint.y },
1505
+ { x: toLine.x, y: midpoint.y },
1506
+ toLine,
1507
+ to.arrowPoint
1504
1508
  ],
1505
1509
  midpoint
1506
1510
  };
1507
1511
  }
1508
1512
  const isSameSourceDir = fromPortDir === horizontalLineDir;
1509
- const centerY = (from.y + to.y) / 2;
1513
+ const centerY = (fromLine.y + toLine.y) / 2;
1510
1514
  if (isSameSourceDir) {
1511
- const joint2 = { x: to.x, y: from.y };
1515
+ const joint2 = { x: toLine.x, y: fromLine.y };
1512
1516
  return {
1513
- points: [{ x: from.x, y: from.y }, joint2, { x: to.x, y: to.y }],
1517
+ points: [from.arrowPoint, joint2, toLine, to.arrowPoint],
1514
1518
  midpoint: { x: joint2.x, y: centerY }
1515
1519
  };
1516
1520
  }
1517
- const joint = { x: from.x, y: to.y };
1521
+ const joint = { x: fromLine.x, y: toLine.y };
1518
1522
  return {
1519
- points: [{ x: from.x, y: from.y }, joint, { x: to.x, y: to.y }],
1523
+ points: [from.arrowPoint, fromLine, joint, to.arrowPoint],
1520
1524
  midpoint: { x: joint.x, y: centerY }
1521
1525
  };
1522
1526
  };
@@ -1540,14 +1544,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1540
1544
  fromDir,
1541
1545
  from
1542
1546
  ) : from;
1543
- const endArrow = hasTargetArrow ? createRotatedPoint(
1544
- {
1545
- x: to.x - arrowLength,
1546
- y: to.y
1547
- },
1548
- toDir,
1549
- to
1550
- ) : to;
1547
+ const endArrow = hasTargetArrow ? createRotatedPoint({ x: to.x - arrowLength, y: to.y }, toDir, to) : to;
1551
1548
  const gap = arrowLength + arrowOffset;
1552
1549
  const beginLine = createRotatedPoint(
1553
1550
  { x: from.x + gap, y: from.y },
@@ -1556,21 +1553,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1556
1553
  );
1557
1554
  const endLine = createRotatedPoint({ x: to.x - gap, y: to.y }, toDir, to);
1558
1555
  const line = createLine$1(
1559
- {
1560
- x: beginLine.x,
1561
- y: beginLine.y,
1562
- dirX: fromDir.x
1563
- },
1564
- {
1565
- x: endLine.x,
1566
- y: endLine.y,
1567
- dirX: toDir.x
1568
- }
1569
- );
1570
- this.path = createRoundedPath(
1571
- [beginArrow, ...line.points, endArrow],
1572
- roundness
1556
+ { arrowPoint: beginArrow, linePoint: beginLine, dirX: fromDir.x },
1557
+ { arrowPoint: endArrow, linePoint: endLine, dirX: toDir.x }
1573
1558
  );
1559
+ this.path = createRoundedPath(line.points, roundness);
1574
1560
  this.midpoint = line.midpoint;
1575
1561
  }
1576
1562
  }
@@ -1687,48 +1673,52 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1687
1673
  }
1688
1674
  }
1689
1675
  const createLine = (from, to) => {
1690
- const verticalLineDir = to.y - from.y >= 0;
1676
+ const fromLine = from.linePoint;
1677
+ const toLine = to.linePoint;
1678
+ const verticalLineDir = toLine.y - fromLine.y >= 0;
1691
1679
  const fromPortDir = from.dirY >= 0;
1692
1680
  const toPortDir = to.dirY >= 0;
1693
1681
  const isSameDirPorts = fromPortDir === toPortDir;
1694
1682
  if (isSameDirPorts) {
1695
1683
  const isSameDirLine = fromPortDir === verticalLineDir;
1696
- const centerX2 = (from.x + to.x) / 2;
1697
- const centerY = (from.y + to.y) / 2;
1684
+ const centerX2 = (fromLine.x + toLine.x) / 2;
1685
+ const centerY = (fromLine.y + toLine.y) / 2;
1698
1686
  const midpoint = { x: centerX2, y: centerY };
1699
1687
  if (isSameDirLine) {
1700
1688
  return {
1701
1689
  points: [
1702
- { x: from.x, y: from.y },
1703
- { x: from.x, y: midpoint.y },
1704
- { x: to.x, y: midpoint.y },
1705
- { x: to.x, y: to.y }
1690
+ from.arrowPoint,
1691
+ { x: fromLine.x, y: midpoint.y },
1692
+ { x: toLine.x, y: midpoint.y },
1693
+ to.arrowPoint
1706
1694
  ],
1707
1695
  midpoint
1708
1696
  };
1709
1697
  }
1710
1698
  return {
1711
1699
  points: [
1712
- { x: from.x, y: from.y },
1713
- { x: midpoint.x, y: from.y },
1714
- { x: midpoint.x, y: to.y },
1715
- { x: to.x, y: to.y }
1700
+ from.arrowPoint,
1701
+ fromLine,
1702
+ { x: midpoint.x, y: fromLine.y },
1703
+ { x: midpoint.x, y: toLine.y },
1704
+ toLine,
1705
+ to.arrowPoint
1716
1706
  ],
1717
1707
  midpoint
1718
1708
  };
1719
1709
  }
1720
1710
  const isSameSourceDir = fromPortDir === verticalLineDir;
1721
- const centerX = (from.x + to.x) / 2;
1711
+ const centerX = (fromLine.x + toLine.x) / 2;
1722
1712
  if (isSameSourceDir) {
1723
- const joint2 = { x: from.x, y: to.y };
1713
+ const joint2 = { x: fromLine.x, y: toLine.y };
1724
1714
  return {
1725
- points: [{ x: from.x, y: from.y }, joint2, { x: to.x, y: to.y }],
1715
+ points: [from.arrowPoint, joint2, toLine, to.arrowPoint],
1726
1716
  midpoint: { x: centerX, y: joint2.y }
1727
1717
  };
1728
1718
  }
1729
- const joint = { x: to.x, y: from.y };
1719
+ const joint = { x: toLine.x, y: fromLine.y };
1730
1720
  return {
1731
- points: [{ x: from.x, y: from.y }, joint, { x: to.x, y: to.y }],
1721
+ points: [from.arrowPoint, fromLine, joint, to.arrowPoint],
1732
1722
  midpoint: { x: centerX, y: joint.y }
1733
1723
  };
1734
1724
  };
@@ -1752,14 +1742,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1752
1742
  fromDir,
1753
1743
  from
1754
1744
  ) : from;
1755
- const endArrow = hasTargetArrow ? createRotatedPoint(
1756
- {
1757
- x: to.x - arrowLength,
1758
- y: to.y
1759
- },
1760
- toDir,
1761
- to
1762
- ) : to;
1745
+ const endArrow = hasTargetArrow ? createRotatedPoint({ x: to.x - arrowLength, y: to.y }, toDir, to) : to;
1763
1746
  const gap = arrowLength + arrowOffset;
1764
1747
  const beginLine = createRotatedPoint(
1765
1748
  { x: from.x + gap, y: from.y },
@@ -1768,21 +1751,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1768
1751
  );
1769
1752
  const endLine = createRotatedPoint({ x: to.x - gap, y: to.y }, toDir, to);
1770
1753
  const line = createLine(
1771
- {
1772
- x: beginLine.x,
1773
- y: beginLine.y,
1774
- dirY: fromDir.y
1775
- },
1776
- {
1777
- x: endLine.x,
1778
- y: endLine.y,
1779
- dirY: toDir.y
1780
- }
1781
- );
1782
- this.path = createRoundedPath(
1783
- [beginArrow, ...line.points, endArrow],
1784
- roundness
1754
+ { arrowPoint: beginArrow, linePoint: beginLine, dirY: fromDir.y },
1755
+ { arrowPoint: endArrow, linePoint: endLine, dirY: toDir.y }
1785
1756
  );
1757
+ this.path = createRoundedPath(line.points, roundness);
1786
1758
  this.midpoint = line.midpoint;
1787
1759
  }
1788
1760
  }
@@ -2297,6 +2269,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
2297
2269
  this.pathShape.render(params);
2298
2270
  }
2299
2271
  }
2272
+ const horizontalizeDirection = (direction) => {
2273
+ return Math.cos(direction) > 0 ? 0 : Math.PI;
2274
+ };
2300
2275
  class HorizontalEdgeShape {
2301
2276
  constructor(params) {
2302
2277
  __publicField(this, "svg");
@@ -2377,7 +2352,18 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
2377
2352
  this.onAfterRender = this.pathShape.onAfterRender;
2378
2353
  }
2379
2354
  render(params) {
2380
- this.pathShape.render(params);
2355
+ const { from, to, category } = params;
2356
+ this.pathShape.render({
2357
+ category,
2358
+ from: {
2359
+ ...from,
2360
+ direction: horizontalizeDirection(from.direction)
2361
+ },
2362
+ to: {
2363
+ ...to,
2364
+ direction: horizontalizeDirection(to.direction)
2365
+ }
2366
+ });
2381
2367
  }
2382
2368
  }
2383
2369
  class StraightEdgeShape {
@@ -2466,6 +2452,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
2466
2452
  this.pathShape.render(params);
2467
2453
  }
2468
2454
  }
2455
+ const pi2 = Math.PI / 2;
2456
+ const verticalizeDirection = (direction) => {
2457
+ return Math.sin(direction) > 0 ? pi2 : -pi2;
2458
+ };
2469
2459
  class VerticalEdgeShape {
2470
2460
  constructor(params) {
2471
2461
  __publicField(this, "svg");
@@ -2546,7 +2536,18 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
2546
2536
  this.onAfterRender = this.pathShape.onAfterRender;
2547
2537
  }
2548
2538
  render(params) {
2549
- this.pathShape.render(params);
2539
+ const { from, to, category } = params;
2540
+ this.pathShape.render({
2541
+ category,
2542
+ from: {
2543
+ ...from,
2544
+ direction: verticalizeDirection(from.direction)
2545
+ },
2546
+ to: {
2547
+ ...to,
2548
+ direction: verticalizeDirection(to.direction)
2549
+ }
2550
+ });
2550
2551
  }
2551
2552
  }
2552
2553
  class DirectEdgeShape {
@@ -2694,7 +2695,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
2694
2695
  // TODO: make private
2695
2696
  /**
2696
2697
  * @deprecated
2697
- * do use shape.svg instead
2698
+ * use shape.svg instead
2698
2699
  */
2699
2700
  __publicField(this, "handle", createEdgeGroup());
2700
2701
  __publicField(this, "onAfterRender");
@@ -3233,13 +3234,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
3233
3234
  start = timestamp;
3234
3235
  }
3235
3236
  const progress = Math.min((timestamp - start) / duration, 1);
3236
- if (progress <= 1) {
3237
- this.viewportStore.patchViewportMatrix({
3238
- scale: previousViewportMatrix.scale + progress * deltaMatrix.scale,
3239
- x: previousViewportMatrix.x + progress * deltaMatrix.x,
3240
- y: previousViewportMatrix.y + progress * deltaMatrix.y
3241
- });
3242
- }
3237
+ this.viewportStore.patchViewportMatrix({
3238
+ scale: previousViewportMatrix.scale + progress * deltaMatrix.scale,
3239
+ x: previousViewportMatrix.x + progress * deltaMatrix.x,
3240
+ y: previousViewportMatrix.y + progress * deltaMatrix.y
3241
+ });
3243
3242
  if (progress < 1) {
3244
3243
  this.win.requestAnimationFrame(step);
3245
3244
  }
@@ -3595,7 +3594,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
3595
3594
  to: params.isDirect ? targetPortId : params.staticPortId
3596
3595
  };
3597
3596
  };
3598
- class ClosestConnectablePortDraggingPortDirectionResolver {
3597
+ class NearestConnectablePortDraggingPortDirectionResolver {
3599
3598
  constructor(graph, connectionAllowedVerifier) {
3600
3599
  this.graph = graph;
3601
3600
  this.connectionAllowedVerifier = connectionAllowedVerifier;
@@ -4436,13 +4435,16 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4436
4435
  staticPortId,
4437
4436
  isDirect
4438
4437
  };
4438
+ const resolvedDirection = this.params.draggingPortDirectionResolver.resolve(
4439
+ {
4440
+ cursor,
4441
+ ...this.edgeInProgress
4442
+ }
4443
+ );
4439
4444
  const draggingParams = {
4440
4445
  overlayNodeId: OverlayId.DraggingNodeId,
4441
4446
  portCoords: cursorPoint,
4442
- portDirection: this.params.draggingPortDirectionResolver.resolve({
4443
- cursor,
4444
- ...this.edgeInProgress
4445
- }) ?? port.direction
4447
+ portDirection: resolvedDirection ?? port.direction
4446
4448
  };
4447
4449
  const [sourceParams, targetParams] = isDirect ? [staticParams, draggingParams] : [draggingParams, staticParams];
4448
4450
  this.overlayCanvas.addNode(createAddNodeOverlayRequest(sourceParams));
@@ -4596,14 +4598,16 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4596
4598
  portCoords: staticPoint,
4597
4599
  portDirection: staticPort.direction
4598
4600
  };
4599
- const direction = this.params.draggingPortDirectionResolver.resolve({
4600
- cursor,
4601
- ...this.edgeInProgress
4602
- });
4601
+ const resolvedDirection = this.params.draggingPortDirectionResolver.resolve(
4602
+ {
4603
+ cursor,
4604
+ ...this.edgeInProgress
4605
+ }
4606
+ );
4603
4607
  const draggingParams = {
4604
4608
  overlayNodeId: OverlayId.DraggingNodeId,
4605
4609
  portCoords: draggingPoint,
4606
- portDirection: direction ?? draggingPort.direction
4610
+ portDirection: resolvedDirection ?? draggingPort.direction
4607
4611
  };
4608
4612
  const [sourceParams, targetParams] = isDirect ? [staticParams, draggingParams] : [draggingParams, staticParams];
4609
4613
  this.overlayCanvas.addNode(createAddNodeOverlayRequest(sourceParams));
@@ -5050,7 +5054,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
5050
5054
  };
5051
5055
  const resolveDraggingPortDirectionResolver = (config, graph, connectionAllowedVerifier) => {
5052
5056
  if (config === "closest-connectable-port") {
5053
- return new ClosestConnectablePortDraggingPortDirectionResolver(
5057
+ return new NearestConnectablePortDraggingPortDirectionResolver(
5058
+ graph,
5059
+ connectionAllowedVerifier
5060
+ );
5061
+ }
5062
+ if (config === "nearest-connectable-port") {
5063
+ return new NearestConnectablePortDraggingPortDirectionResolver(
5054
5064
  graph,
5055
5065
  connectionAllowedVerifier
5056
5066
  );
@@ -6421,6 +6431,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
6421
6431
  nodeMass: (config == null ? void 0 : config.nodeMass) ?? forceDirectedDefaults.nodeMass,
6422
6432
  edgeEquilibriumLength: (config == null ? void 0 : config.edgeEquilibriumLength) ?? forceDirectedDefaults.edgeEquilibriumLength,
6423
6433
  edgeStiffness: (config == null ? void 0 : config.edgeStiffness) ?? forceDirectedDefaults.edgeStiffness,
6434
+ // TODO: rename no `minVelocity`
6424
6435
  convergenceVelocity: (config == null ? void 0 : config.convergenceVelocity) ?? forceDirectedDefaults.convergenceVelocity,
6425
6436
  maxForce: (config == null ? void 0 : config.maxForce) ?? forceDirectedDefaults.maxForce,
6426
6437
  nodeForceCoefficient: (config == null ? void 0 : config.nodeForceCoefficient) ?? forceDirectedDefaults.nodeForceCoefficient,
@@ -6450,6 +6461,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
6450
6461
  trigger: applyOn
6451
6462
  };
6452
6463
  }
6464
+ if (applyOn === "topologyChangeMicrotask") {
6465
+ return {
6466
+ type: "topologyChangeSchedule",
6467
+ schedule: microtaskScheduleFn
6468
+ };
6469
+ }
6453
6470
  if ((applyOn == null ? void 0 : applyOn.type) === "topologyChangeMacrotask") {
6454
6471
  return {
6455
6472
  type: "topologyChangeSchedule",
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@html-graph/html-graph",
3
3
  "author": "Dmitry Marov <d.marov94@gmail.com>",
4
4
  "private": false,
5
- "version": "8.18.0",
5
+ "version": "8.19.0",
6
6
  "type": "module",
7
7
  "main": "dist/html-graph.js",
8
8
  "types": "dist/html-graph.d.ts",