@flowgram.ai/free-lines-plugin 0.1.0-alpha.13 → 0.1.0-alpha.14

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/esm/index.js CHANGED
@@ -295,9 +295,7 @@ import { WorkflowLineRenderData } from "@flowgram.ai/free-layout-core";
295
295
 
296
296
  // src/components/workflow-line-render/index.style.ts
297
297
  import styled2 from "styled-components";
298
- var LineStyle = styled2.div.attrs({
299
- className: "gedit-flow-activity-edge"
300
- })`
298
+ var LineStyle = styled2.div`
301
299
  position: absolute;
302
300
 
303
301
  @keyframes flowingDash {
@@ -348,12 +346,12 @@ var LineSVG = (props) => {
348
346
  const { position, reverse, hideArrow, vertical } = line;
349
347
  const renderData = line.getData(WorkflowLineRenderData);
350
348
  const { bounds, path: bezierPath } = renderData;
351
- const toRelative = (p) => ({
349
+ const toRelative2 = (p) => ({
352
350
  x: p.x - bounds.x + PADDING,
353
351
  y: p.y - bounds.y + PADDING
354
352
  });
355
- const fromPos = toRelative(position.from);
356
- const toPos = toRelative(position.to);
353
+ const fromPos = toRelative2(position.from);
354
+ const toPos = toRelative2(position.to);
357
355
  const arrowToPos = position.to.location === "top" ? { x: toPos.x, y: toPos.y - POINT_RADIUS } : { x: toPos.x - POINT_RADIUS, y: toPos.y };
358
356
  const arrowFromPos = position.from.location === "bottom" ? { x: fromPos.x, y: fromPos.y + POINT_RADIUS + LINE_OFFSET } : { x: fromPos.x + POINT_RADIUS + LINE_OFFSET, y: fromPos.y };
359
357
  const strokeWidth = selected ? line.uiState.strokeWidthSelected ?? STROKE_WIDTH_SLECTED : line.uiState.strokeWidth ?? STROKE_WIDTH;
@@ -367,17 +365,15 @@ var LineSVG = (props) => {
367
365
  fill: "none",
368
366
  stroke: `url(#${strokeID})`,
369
367
  strokeWidth,
370
- style: line.uiState.style,
371
- className: clsx(
372
- line.className,
373
- line.processing || line.flowing ? "dashed-line flowing-line" : ""
374
- )
368
+ className: line.processing || line.flowing ? "dashed-line flowing-line" : ""
375
369
  }
376
370
  );
377
371
  return /* @__PURE__ */ React4.createElement(
378
372
  LineStyle,
379
373
  {
374
+ className: clsx("gedit-flow-activity-edge", line.className),
380
375
  style: {
376
+ ...line.uiState.style,
381
377
  left: bounds.x - PADDING,
382
378
  top: bounds.y - PADDING,
383
379
  position: "absolute"
@@ -564,7 +560,23 @@ import { Bezier } from "bezier-js";
564
560
  import { Point, Rectangle } from "@flowgram.ai/utils";
565
561
  import { LineType } from "@flowgram.ai/free-layout-core";
566
562
 
563
+ // src/contributions/utils.ts
564
+ function toRelative(p, bbox) {
565
+ return {
566
+ x: p.x - bbox.x + LINE_PADDING,
567
+ y: p.y - bbox.y + LINE_PADDING
568
+ };
569
+ }
570
+
567
571
  // src/contributions/bezier/bezier-controls.ts
572
+ function getBezierEdgeCenter(fromPos, toPos, fromControl, toControl) {
573
+ const x = fromPos.x * 0.125 + fromControl.x * 0.375 + toControl.x * 0.375 + toPos.x * 0.125;
574
+ const y = fromPos.y * 0.125 + fromControl.y * 0.375 + toControl.y * 0.375 + toPos.y * 0.125;
575
+ return {
576
+ x,
577
+ y
578
+ };
579
+ }
568
580
  function getControlOffset(distance, curvature) {
569
581
  if (distance >= 0) {
570
582
  return 0.5 * distance;
@@ -619,7 +631,11 @@ function getBezierControlPoints(fromPos, toPos, curvature = 0.25) {
619
631
  y2: fromPos.y,
620
632
  curvature
621
633
  });
622
- return [fromControl, toControl];
634
+ const center = getBezierEdgeCenter(fromPos, toPos, fromControl, toControl);
635
+ return {
636
+ controls: [fromControl, toControl],
637
+ center
638
+ };
623
639
  }
624
640
 
625
641
  // src/contributions/bezier/index.ts
@@ -638,15 +654,22 @@ var WorkflowBezierLineContribution = class {
638
654
  }
639
655
  get bounds() {
640
656
  if (!this.data) {
641
- return new Rectangle();
657
+ return Rectangle.EMPTY;
642
658
  }
643
659
  return this.data.bbox;
644
660
  }
661
+ get center() {
662
+ return this.data?.center;
663
+ }
645
664
  update(params) {
646
665
  this.data = this.calcBezier(params.fromPos, params.toPos);
647
666
  }
648
667
  calcBezier(fromPos, toPos) {
649
- const controls = getBezierControlPoints(fromPos, toPos, this.entity.uiState.curvature);
668
+ const { controls, center } = getBezierControlPoints(
669
+ fromPos,
670
+ toPos,
671
+ this.entity.uiState.curvature
672
+ );
650
673
  const bezier = new Bezier([fromPos, ...controls, toPos]);
651
674
  const bbox = bezier.bbox();
652
675
  const bboxBounds = new Rectangle(
@@ -655,6 +678,7 @@ var WorkflowBezierLineContribution = class {
655
678
  bbox.x.max - bbox.x.min,
656
679
  bbox.y.max - bbox.y.min
657
680
  );
681
+ const centerPoint = toRelative(center, bboxBounds);
658
682
  const path = this.getPath({ bbox: bboxBounds, fromPos, toPos, controls });
659
683
  this.data = {
660
684
  fromPos,
@@ -662,19 +686,20 @@ var WorkflowBezierLineContribution = class {
662
686
  bezier,
663
687
  bbox: bboxBounds,
664
688
  controls,
665
- path
689
+ path,
690
+ center: {
691
+ ...center,
692
+ labelX: centerPoint.x,
693
+ labelY: centerPoint.y
694
+ }
666
695
  };
667
696
  return this.data;
668
697
  }
669
698
  getPath(params) {
670
699
  const { bbox } = params;
671
- const toRelative = (p) => ({
672
- x: p.x - bbox.x + LINE_PADDING,
673
- y: p.y - bbox.y + LINE_PADDING
674
- });
675
- const fromPos = toRelative(params.fromPos);
676
- const toPos = toRelative(params.toPos);
677
- const controls = params.controls.map((c) => toRelative(c));
700
+ const fromPos = toRelative(params.fromPos, bbox);
701
+ const toPos = toRelative(params.toPos, bbox);
702
+ const controls = params.controls.map((c) => toRelative(c, bbox));
678
703
  const shrink = this.entity.uiState.shrink;
679
704
  const renderFromPos = params.fromPos.location === "bottom" ? { x: fromPos.x, y: fromPos.y + shrink } : { x: fromPos.x + shrink, y: fromPos.y };
680
705
  const renderToPos = params.toPos.location === "top" ? { x: toPos.x, y: toPos.y - shrink } : { x: toPos.x - shrink, y: toPos.y };
@@ -686,9 +711,6 @@ WorkflowBezierLineContribution.type = LineType.BEZIER;
686
711
 
687
712
  // src/contributions/fold/index.ts
688
713
  import { Rectangle as Rectangle3 } from "@flowgram.ai/utils";
689
- import {
690
- POINT_RADIUS as POINT_RADIUS2
691
- } from "@flowgram.ai/free-layout-core";
692
714
  import { LineType as LineType2 } from "@flowgram.ai/free-layout-core";
693
715
 
694
716
  // src/contributions/fold/fold-line.ts
@@ -743,10 +765,7 @@ var FoldLine;
743
765
  top: { x: 0, y: -1 },
744
766
  bottom: { x: 0, y: 1 }
745
767
  };
746
- function getPoints({
747
- source,
748
- target
749
- }) {
768
+ function getPoints({ source, target }) {
750
769
  const sourceDir = handleDirections[source.location];
751
770
  const targetDir = handleDirections[target.location];
752
771
  const sourceGapped = {
@@ -828,7 +847,13 @@ var FoldLine;
828
847
  { x: targetGapped.x, y: targetGapped.y },
829
848
  target
830
849
  ];
831
- return pathPoints;
850
+ return {
851
+ points: pathPoints,
852
+ center: {
853
+ x: centerX,
854
+ y: centerY
855
+ }
856
+ };
832
857
  }
833
858
  FoldLine2.getPoints = getPoints;
834
859
  function getBend(a, b, c) {
@@ -922,17 +947,21 @@ var WorkflowFoldLineContribution = class {
922
947
  }
923
948
  return this.data.bbox;
924
949
  }
950
+ get center() {
951
+ return this.data?.center;
952
+ }
925
953
  update(params) {
926
954
  const { fromPos, toPos } = params;
955
+ const shrink = this.entity.uiState.shrink;
927
956
  const sourceOffset = {
928
- x: fromPos.location === "bottom" ? 0 : POINT_RADIUS2,
929
- y: fromPos.location === "bottom" ? POINT_RADIUS2 : 0
957
+ x: fromPos.location === "bottom" ? 0 : shrink,
958
+ y: fromPos.location === "bottom" ? shrink : 0
930
959
  };
931
960
  const targetOffset = {
932
- x: toPos.location === "top" ? 0 : -POINT_RADIUS2,
933
- y: toPos.location === "top" ? -POINT_RADIUS2 : 0
961
+ x: toPos.location === "top" ? 0 : -shrink,
962
+ y: toPos.location === "top" ? -shrink : 0
934
963
  };
935
- const points = FoldLine.getPoints({
964
+ const { points, center } = FoldLine.getPoints({
936
965
  source: {
937
966
  x: fromPos.x + sourceOffset.x,
938
967
  y: fromPos.y + sourceOffset.y,
@@ -945,15 +974,19 @@ var WorkflowFoldLineContribution = class {
945
974
  }
946
975
  });
947
976
  const bbox = FoldLine.getBounds(points);
948
- const adjustedPoints = points.map((p) => ({
949
- x: p.x - bbox.x + LINE_PADDING,
950
- y: p.y - bbox.y + LINE_PADDING
951
- }));
977
+ const adjustedPoints = points.map((p) => toRelative(p, bbox));
952
978
  const path = FoldLine.getSmoothStepPath(adjustedPoints);
979
+ const relativeCenter = toRelative(center, bbox);
953
980
  this.data = {
954
981
  points,
955
982
  path,
956
- bbox
983
+ bbox,
984
+ center: {
985
+ x: center.x,
986
+ y: center.y,
987
+ labelX: relativeCenter.x,
988
+ labelY: relativeCenter.y
989
+ }
957
990
  };
958
991
  }
959
992
  };
@@ -962,7 +995,8 @@ WorkflowFoldLineContribution.type = LineType2.LINE_CHART;
962
995
  // src/contributions/straight/index.ts
963
996
  import { Point as Point3, Rectangle as Rectangle4 } from "@flowgram.ai/utils";
964
997
  import {
965
- POINT_RADIUS as POINT_RADIUS3
998
+ getLineCenter,
999
+ LineType as LineType3
966
1000
  } from "@flowgram.ai/free-layout-core";
967
1001
 
968
1002
  // src/contributions/straight/point-on-line.ts
@@ -1004,15 +1038,19 @@ var WorkflowStraightLineContribution = class {
1004
1038
  }
1005
1039
  return this.data.bbox;
1006
1040
  }
1041
+ get center() {
1042
+ return this.data?.center;
1043
+ }
1007
1044
  update(params) {
1008
1045
  const { fromPos, toPos } = params;
1046
+ const shrink = this.entity.uiState.shrink;
1009
1047
  const sourceOffset = {
1010
- x: fromPos.location === "bottom" ? 0 : POINT_RADIUS3,
1011
- y: fromPos.location === "bottom" ? POINT_RADIUS3 : 0
1048
+ x: fromPos.location === "bottom" ? 0 : shrink,
1049
+ y: fromPos.location === "bottom" ? shrink : 0
1012
1050
  };
1013
1051
  const targetOffset = {
1014
- x: toPos.location === "top" ? 0 : -POINT_RADIUS3,
1015
- y: toPos.location === "top" ? -POINT_RADIUS3 : 0
1052
+ x: toPos.location === "top" ? 0 : -shrink,
1053
+ y: toPos.location === "top" ? -shrink : 0
1016
1054
  };
1017
1055
  const points = [
1018
1056
  {
@@ -1033,100 +1071,12 @@ var WorkflowStraightLineContribution = class {
1033
1071
  this.data = {
1034
1072
  points,
1035
1073
  path,
1036
- bbox
1037
- };
1038
- }
1039
- };
1040
- WorkflowStraightLineContribution.type = "WorkflowStraightLineContribution";
1041
-
1042
- // src/contributions/arc/index.ts
1043
- import { Point as Point4, Rectangle as Rectangle5 } from "@flowgram.ai/utils";
1044
- import {
1045
- POINT_RADIUS as POINT_RADIUS4
1046
- } from "@flowgram.ai/free-layout-core";
1047
- var WorkflowArkLineContribution = class {
1048
- constructor(entity) {
1049
- this.entity = entity;
1050
- }
1051
- get path() {
1052
- return this.data?.path ?? "";
1053
- }
1054
- calcDistance(pos) {
1055
- if (!this.data) {
1056
- return Number.MAX_SAFE_INTEGER;
1057
- }
1058
- const { fromPos, toPos, bbox } = this.data;
1059
- if (!bbox.contains(pos.x, pos.y)) {
1060
- const dx = Math.max(bbox.x - pos.x, 0, pos.x - (bbox.x + bbox.width));
1061
- const dy = Math.max(bbox.y - pos.y, 0, pos.y - (bbox.y + bbox.height));
1062
- return Math.sqrt(dx * dx + dy * dy);
1063
- }
1064
- const center = {
1065
- x: (fromPos.x + toPos.x) / 2,
1066
- y: (fromPos.y + toPos.y) / 2
1067
- };
1068
- const radius = Point4.getDistance(fromPos, center);
1069
- const distanceToCenter = Point4.getDistance(pos, center);
1070
- return Math.abs(distanceToCenter - radius);
1071
- }
1072
- get bounds() {
1073
- if (!this.data) {
1074
- return new Rectangle5();
1075
- }
1076
- return this.data.bbox;
1077
- }
1078
- update(params) {
1079
- const { fromPos, toPos } = params;
1080
- const { vertical } = this.entity;
1081
- const sourceOffset = {
1082
- x: vertical ? 0 : POINT_RADIUS4,
1083
- y: vertical ? POINT_RADIUS4 : 0
1084
- };
1085
- const targetOffset = {
1086
- x: vertical ? 0 : -POINT_RADIUS4,
1087
- y: vertical ? -POINT_RADIUS4 : 0
1088
- };
1089
- const start = {
1090
- x: fromPos.x + sourceOffset.x,
1091
- y: fromPos.y + sourceOffset.y
1092
- };
1093
- const end = {
1094
- x: toPos.x + targetOffset.x,
1095
- y: toPos.y + targetOffset.y
1096
- };
1097
- const bbox = this.calculateArcBBox(start, end);
1098
- const path = this.getArcPath(start, end, bbox);
1099
- this.data = {
1100
- fromPos: start,
1101
- toPos: end,
1102
- path,
1103
- bbox
1104
- };
1105
- }
1106
- calculateArcBBox(start, end) {
1107
- const dx = end.x - start.x;
1108
- const dy = end.y - start.y;
1109
- const radius = Math.sqrt(dx * dx + dy * dy) / 2;
1110
- const centerX = (start.x + end.x) / 2;
1111
- const centerY = (start.y + end.y) / 2;
1112
- return new Rectangle5(centerX - radius, centerY - radius, radius * 2, radius * 2);
1113
- }
1114
- getArcPath(start, end, bbox) {
1115
- const dx = end.x - start.x;
1116
- const dy = end.y - start.y;
1117
- const distance = Math.sqrt(dx * dx + dy * dy);
1118
- const startRel = {
1119
- x: start.x - bbox.x + LINE_PADDING,
1120
- y: start.y - bbox.y + LINE_PADDING
1121
- };
1122
- const endRel = {
1123
- x: end.x - bbox.x + LINE_PADDING,
1124
- y: end.y - bbox.y + LINE_PADDING
1074
+ bbox,
1075
+ center: getLineCenter(fromPos, toPos, bbox, LINE_PADDING)
1125
1076
  };
1126
- return `M ${startRel.x} ${startRel.y} A ${distance / 2} ${distance / 2} 0 0 1 ${endRel.x} ${endRel.y}`;
1127
1077
  }
1128
1078
  };
1129
- WorkflowArkLineContribution.type = "WorkflowArkLineContribution";
1079
+ WorkflowStraightLineContribution.type = LineType3.STRAIGHT;
1130
1080
 
1131
1081
  // src/create-free-lines-plugin.ts
1132
1082
  var createFreeLinesPlugin = definePluginCreator({
@@ -1138,7 +1088,7 @@ var createFreeLinesPlugin = definePluginCreator({
1138
1088
  },
1139
1089
  onReady: (ctx, opts) => {
1140
1090
  const linesManager = ctx.container.get(WorkflowLinesManager2);
1141
- linesManager.registerContribution(WorkflowBezierLineContribution).registerContribution(WorkflowFoldLineContribution);
1091
+ linesManager.registerContribution(WorkflowBezierLineContribution).registerContribution(WorkflowFoldLineContribution).registerContribution(WorkflowStraightLineContribution);
1142
1092
  if (opts.contributions) {
1143
1093
  opts.contributions.forEach((contribution) => {
1144
1094
  linesManager.registerContribution(contribution);
@@ -1153,7 +1103,6 @@ export {
1153
1103
  LINE_OFFSET,
1154
1104
  LINE_PADDING,
1155
1105
  WorkflowLinesLayer as LinesLayer,
1156
- WorkflowArkLineContribution,
1157
1106
  WorkflowBezierLineContribution,
1158
1107
  WorkflowFoldLineContribution,
1159
1108
  WorkflowLinesLayer,