@flowgram.ai/free-lines-plugin 0.3.5 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.js +125 -323
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +8 -59
- package/dist/index.d.ts +8 -59
- package/dist/index.js +137 -335
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -38,7 +38,6 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
38
38
|
// src/index.ts
|
|
39
39
|
var src_exports = {};
|
|
40
40
|
__export(src_exports, {
|
|
41
|
-
BezierControlType: () => BezierControlType,
|
|
42
41
|
LINE_OFFSET: () => LINE_OFFSET,
|
|
43
42
|
LINE_PADDING: () => LINE_PADDING,
|
|
44
43
|
LinesLayer: () => WorkflowLinesLayer,
|
|
@@ -46,12 +45,9 @@ __export(src_exports, {
|
|
|
46
45
|
WorkflowBezierLineContribution: () => WorkflowBezierLineContribution,
|
|
47
46
|
WorkflowFoldLineContribution: () => WorkflowFoldLineContribution,
|
|
48
47
|
WorkflowLinesLayer: () => WorkflowLinesLayer,
|
|
49
|
-
WorkflowManhattanLineContribution: () => WorkflowManhattanLineContribution,
|
|
50
48
|
WorkflowPortRender: () => WorkflowPortRender,
|
|
51
49
|
WorkflowStraightLineContribution: () => WorkflowStraightLineContribution,
|
|
52
|
-
createFreeLinesPlugin: () => createFreeLinesPlugin
|
|
53
|
-
getBezierHorizontalControlPoints: () => getBezierHorizontalControlPoints,
|
|
54
|
-
getBezierVerticalControlPoints: () => getBezierVerticalControlPoints
|
|
50
|
+
createFreeLinesPlugin: () => createFreeLinesPlugin
|
|
55
51
|
});
|
|
56
52
|
module.exports = __toCommonJS(src_exports);
|
|
57
53
|
|
|
@@ -304,7 +300,7 @@ var LINE_OFFSET = 6;
|
|
|
304
300
|
var LINE_PADDING = 12;
|
|
305
301
|
|
|
306
302
|
// src/create-free-lines-plugin.ts
|
|
307
|
-
var
|
|
303
|
+
var import_free_layout_core10 = require("@flowgram.ai/free-layout-core");
|
|
308
304
|
var import_core3 = require("@flowgram.ai/core");
|
|
309
305
|
|
|
310
306
|
// src/layer/workflow-lines-layer.tsx
|
|
@@ -378,7 +374,7 @@ function ArrowRenderer({
|
|
|
378
374
|
var PADDING = 12;
|
|
379
375
|
var LineSVG = (props) => {
|
|
380
376
|
const { line, color, selected, children, strokePrefix, rendererRegistry } = props;
|
|
381
|
-
const { position, reverse,
|
|
377
|
+
const { position, reverse, hideArrow, vertical } = line;
|
|
382
378
|
const renderData = line.getData(import_free_layout_core3.WorkflowLineRenderData);
|
|
383
379
|
const { bounds, path: bezierPath } = renderData;
|
|
384
380
|
const toRelative = (p) => ({
|
|
@@ -387,9 +383,9 @@ var LineSVG = (props) => {
|
|
|
387
383
|
});
|
|
388
384
|
const fromPos = toRelative(position.from);
|
|
389
385
|
const toPos = toRelative(position.to);
|
|
390
|
-
const arrowToPos =
|
|
391
|
-
const arrowFromPos =
|
|
392
|
-
const strokeWidth = selected ? STROKE_WIDTH_SLECTED : STROKE_WIDTH;
|
|
386
|
+
const arrowToPos = position.to.location === "top" ? { x: toPos.x, y: toPos.y - import_free_layout_core2.POINT_RADIUS } : { x: toPos.x - import_free_layout_core2.POINT_RADIUS, y: toPos.y };
|
|
387
|
+
const arrowFromPos = position.from.location === "bottom" ? { x: fromPos.x, y: fromPos.y + import_free_layout_core2.POINT_RADIUS + LINE_OFFSET } : { x: fromPos.x + import_free_layout_core2.POINT_RADIUS + LINE_OFFSET, y: fromPos.y };
|
|
388
|
+
const strokeWidth = selected ? line.uiState.strokeWidthSelected ?? STROKE_WIDTH_SLECTED : line.uiState.strokeWidth ?? STROKE_WIDTH;
|
|
393
389
|
const strokeID = strokePrefix ? `${strokePrefix}-${line.id}` : line.id;
|
|
394
390
|
const CustomArrowRenderer = rendererRegistry?.tryToGetRendererComponent("arrow-renderer")?.renderer;
|
|
395
391
|
const ArrowComponent = CustomArrowRenderer || ArrowRenderer;
|
|
@@ -400,10 +396,10 @@ var LineSVG = (props) => {
|
|
|
400
396
|
fill: "none",
|
|
401
397
|
stroke: `url(#${strokeID})`,
|
|
402
398
|
strokeWidth,
|
|
399
|
+
style: line.uiState.style,
|
|
403
400
|
className: (0, import_clsx2.default)(
|
|
404
401
|
line.className,
|
|
405
|
-
|
|
406
|
-
!line.className && (line.processing || line.flowing ? "dashed-line flowing-line" : "")
|
|
402
|
+
line.processing || line.flowing ? "dashed-line flowing-line" : ""
|
|
407
403
|
)
|
|
408
404
|
}
|
|
409
405
|
);
|
|
@@ -592,143 +588,70 @@ WorkflowLinesLayer = __decorateClass([
|
|
|
592
588
|
(0, import_inversify.injectable)()
|
|
593
589
|
], WorkflowLinesLayer);
|
|
594
590
|
|
|
595
|
-
// src/contributions/bezier/
|
|
591
|
+
// src/contributions/bezier/index.ts
|
|
592
|
+
var import_bezier_js = require("bezier-js");
|
|
596
593
|
var import_utils2 = require("@flowgram.ai/utils");
|
|
597
|
-
var
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
})(BezierControlType || {});
|
|
604
|
-
var CONTROL_MAX = 300;
|
|
605
|
-
function getBezierHorizontalControlPoints(fromPos, toPos) {
|
|
606
|
-
const rect = import_utils2.Rectangle.createRectangleWithTwoPoints(fromPos, toPos);
|
|
607
|
-
let type;
|
|
608
|
-
if (fromPos.x <= toPos.x) {
|
|
609
|
-
type = fromPos.y <= toPos.y ? 1 /* RIGHT_BOTTOM */ : 0 /* RIGHT_TOP */;
|
|
610
|
-
} else {
|
|
611
|
-
type = fromPos.y <= toPos.y ? 3 /* LEFT_BOTTOM */ : 2 /* LEFT_TOP */;
|
|
612
|
-
}
|
|
613
|
-
let controls;
|
|
614
|
-
switch (type) {
|
|
615
|
-
case 0 /* RIGHT_TOP */:
|
|
616
|
-
controls = [
|
|
617
|
-
{
|
|
618
|
-
x: rect.rightBottom.x - rect.width / 2,
|
|
619
|
-
y: rect.rightBottom.y
|
|
620
|
-
},
|
|
621
|
-
{
|
|
622
|
-
x: rect.leftTop.x + rect.width / 2,
|
|
623
|
-
y: rect.leftTop.y
|
|
624
|
-
}
|
|
625
|
-
];
|
|
626
|
-
break;
|
|
627
|
-
case 1 /* RIGHT_BOTTOM */:
|
|
628
|
-
controls = [
|
|
629
|
-
{
|
|
630
|
-
x: rect.rightTop.x - rect.width / 2,
|
|
631
|
-
y: rect.rightTop.y
|
|
632
|
-
},
|
|
633
|
-
{
|
|
634
|
-
x: rect.leftBottom.x + rect.width / 2,
|
|
635
|
-
y: rect.leftBottom.y
|
|
636
|
-
}
|
|
637
|
-
];
|
|
638
|
-
break;
|
|
639
|
-
case 2 /* LEFT_TOP */:
|
|
640
|
-
controls = [
|
|
641
|
-
{
|
|
642
|
-
x: rect.rightBottom.x + Math.min(rect.width, CONTROL_MAX),
|
|
643
|
-
y: rect.rightBottom.y
|
|
644
|
-
},
|
|
645
|
-
{
|
|
646
|
-
x: rect.leftTop.x - Math.min(rect.width, CONTROL_MAX),
|
|
647
|
-
y: rect.leftTop.y
|
|
648
|
-
}
|
|
649
|
-
];
|
|
650
|
-
break;
|
|
651
|
-
case 3 /* LEFT_BOTTOM */:
|
|
652
|
-
controls = [
|
|
653
|
-
{
|
|
654
|
-
x: rect.rightTop.x + Math.min(rect.width, CONTROL_MAX),
|
|
655
|
-
y: rect.rightTop.y
|
|
656
|
-
},
|
|
657
|
-
{
|
|
658
|
-
x: rect.leftBottom.x - Math.min(rect.width, CONTROL_MAX),
|
|
659
|
-
y: rect.leftBottom.y
|
|
660
|
-
}
|
|
661
|
-
];
|
|
594
|
+
var import_free_layout_core5 = require("@flowgram.ai/free-layout-core");
|
|
595
|
+
|
|
596
|
+
// src/contributions/bezier/bezier-controls.ts
|
|
597
|
+
function getControlOffset(distance, curvature) {
|
|
598
|
+
if (distance >= 0) {
|
|
599
|
+
return 0.5 * distance;
|
|
662
600
|
}
|
|
663
|
-
return
|
|
601
|
+
return curvature * 25 * Math.sqrt(-distance);
|
|
664
602
|
}
|
|
665
|
-
function
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
x: rect.leftBottom.x,
|
|
695
|
-
y: rect.leftBottom.y - rect.height / 2
|
|
696
|
-
}
|
|
697
|
-
];
|
|
698
|
-
break;
|
|
699
|
-
case 0 /* RIGHT_TOP */:
|
|
700
|
-
controls = [
|
|
701
|
-
{
|
|
702
|
-
x: rect.leftBottom.x,
|
|
703
|
-
y: rect.leftBottom.y + Math.min(rect.height, CONTROL_MAX)
|
|
704
|
-
},
|
|
705
|
-
{
|
|
706
|
-
x: rect.rightTop.x,
|
|
707
|
-
y: rect.rightTop.y - Math.min(rect.height, CONTROL_MAX)
|
|
708
|
-
}
|
|
709
|
-
];
|
|
710
|
-
break;
|
|
711
|
-
case 2 /* LEFT_TOP */:
|
|
712
|
-
controls = [
|
|
713
|
-
{
|
|
714
|
-
x: rect.rightBottom.x,
|
|
715
|
-
y: rect.rightBottom.y + Math.min(rect.height, CONTROL_MAX)
|
|
716
|
-
},
|
|
717
|
-
{
|
|
718
|
-
x: rect.leftTop.x,
|
|
719
|
-
y: rect.leftTop.y - Math.min(rect.height, CONTROL_MAX)
|
|
720
|
-
}
|
|
721
|
-
];
|
|
722
|
-
break;
|
|
603
|
+
function getControlWithCurvature({
|
|
604
|
+
location,
|
|
605
|
+
x1,
|
|
606
|
+
y1,
|
|
607
|
+
x2,
|
|
608
|
+
y2,
|
|
609
|
+
curvature
|
|
610
|
+
}) {
|
|
611
|
+
switch (location) {
|
|
612
|
+
case "left":
|
|
613
|
+
return {
|
|
614
|
+
x: x1 - getControlOffset(x1 - x2, curvature),
|
|
615
|
+
y: y1
|
|
616
|
+
};
|
|
617
|
+
case "right":
|
|
618
|
+
return {
|
|
619
|
+
x: x1 + getControlOffset(x2 - x1, curvature),
|
|
620
|
+
y: y1
|
|
621
|
+
};
|
|
622
|
+
case "top":
|
|
623
|
+
return {
|
|
624
|
+
x: x1,
|
|
625
|
+
y: y1 - getControlOffset(y1 - y2, curvature)
|
|
626
|
+
};
|
|
627
|
+
case "bottom":
|
|
628
|
+
return {
|
|
629
|
+
x: x1,
|
|
630
|
+
y: y1 + getControlOffset(y2 - y1, curvature)
|
|
631
|
+
};
|
|
723
632
|
}
|
|
724
|
-
|
|
633
|
+
}
|
|
634
|
+
function getBezierControlPoints(fromPos, toPos, curvature = 0.25) {
|
|
635
|
+
const fromControl = getControlWithCurvature({
|
|
636
|
+
location: fromPos.location,
|
|
637
|
+
x1: fromPos.x,
|
|
638
|
+
y1: fromPos.y,
|
|
639
|
+
x2: toPos.x,
|
|
640
|
+
y2: toPos.y,
|
|
641
|
+
curvature
|
|
642
|
+
});
|
|
643
|
+
const toControl = getControlWithCurvature({
|
|
644
|
+
location: toPos.location,
|
|
645
|
+
x1: toPos.x,
|
|
646
|
+
y1: toPos.y,
|
|
647
|
+
x2: fromPos.x,
|
|
648
|
+
y2: fromPos.y,
|
|
649
|
+
curvature
|
|
650
|
+
});
|
|
651
|
+
return [fromControl, toControl];
|
|
725
652
|
}
|
|
726
653
|
|
|
727
654
|
// src/contributions/bezier/index.ts
|
|
728
|
-
var import_bezier_js = require("bezier-js");
|
|
729
|
-
var import_utils3 = require("@flowgram.ai/utils");
|
|
730
|
-
var import_free_layout_core5 = require("@flowgram.ai/free-layout-core");
|
|
731
|
-
var import_free_layout_core6 = require("@flowgram.ai/free-layout-core");
|
|
732
655
|
var WorkflowBezierLineContribution = class {
|
|
733
656
|
constructor(entity) {
|
|
734
657
|
this.entity = entity;
|
|
@@ -740,11 +663,11 @@ var WorkflowBezierLineContribution = class {
|
|
|
740
663
|
if (!this.data) {
|
|
741
664
|
return Number.MAX_SAFE_INTEGER;
|
|
742
665
|
}
|
|
743
|
-
return
|
|
666
|
+
return import_utils2.Point.getDistance(pos, this.data.bezier.project(pos));
|
|
744
667
|
}
|
|
745
668
|
get bounds() {
|
|
746
669
|
if (!this.data) {
|
|
747
|
-
return new
|
|
670
|
+
return new import_utils2.Rectangle();
|
|
748
671
|
}
|
|
749
672
|
return this.data.bbox;
|
|
750
673
|
}
|
|
@@ -752,10 +675,10 @@ var WorkflowBezierLineContribution = class {
|
|
|
752
675
|
this.data = this.calcBezier(params.fromPos, params.toPos);
|
|
753
676
|
}
|
|
754
677
|
calcBezier(fromPos, toPos) {
|
|
755
|
-
const controls =
|
|
678
|
+
const controls = getBezierControlPoints(fromPos, toPos, this.entity.uiState.curvature);
|
|
756
679
|
const bezier = new import_bezier_js.Bezier([fromPos, ...controls, toPos]);
|
|
757
680
|
const bbox = bezier.bbox();
|
|
758
|
-
const bboxBounds = new
|
|
681
|
+
const bboxBounds = new import_utils2.Rectangle(
|
|
759
682
|
bbox.x.min,
|
|
760
683
|
bbox.y.min,
|
|
761
684
|
bbox.x.max - bbox.x.min,
|
|
@@ -781,28 +704,22 @@ var WorkflowBezierLineContribution = class {
|
|
|
781
704
|
const fromPos = toRelative(params.fromPos);
|
|
782
705
|
const toPos = toRelative(params.toPos);
|
|
783
706
|
const controls = params.controls.map((c) => toRelative(c));
|
|
784
|
-
const
|
|
785
|
-
const
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
return `M${fromPos.x} ${fromPos.y + import_free_layout_core5.POINT_RADIUS} ${curveType} ${controlPoints}, ${renderToPos.x} ${renderToPos.y}`;
|
|
790
|
-
}
|
|
791
|
-
return `M${fromPos.x + import_free_layout_core5.POINT_RADIUS} ${fromPos.y} ${curveType} ${controlPoints}, ${renderToPos.x} ${renderToPos.y}`;
|
|
792
|
-
};
|
|
793
|
-
const path = getPathData();
|
|
794
|
-
return path;
|
|
707
|
+
const shrink = this.entity.uiState.shrink;
|
|
708
|
+
const renderFromPos = params.fromPos.location === "bottom" ? { x: fromPos.x, y: fromPos.y + shrink } : { x: fromPos.x + shrink, y: fromPos.y };
|
|
709
|
+
const renderToPos = params.toPos.location === "top" ? { x: toPos.x, y: toPos.y - shrink } : { x: toPos.x - shrink, y: toPos.y };
|
|
710
|
+
const controlPoints = controls.map((s) => `${s.x} ${s.y}`).join(",");
|
|
711
|
+
return `M${renderFromPos.x} ${renderFromPos.y} C ${controlPoints}, ${renderToPos.x} ${renderToPos.y}`;
|
|
795
712
|
}
|
|
796
713
|
};
|
|
797
|
-
WorkflowBezierLineContribution.type =
|
|
714
|
+
WorkflowBezierLineContribution.type = import_free_layout_core5.LineType.BEZIER;
|
|
798
715
|
|
|
799
716
|
// src/contributions/fold/index.ts
|
|
800
|
-
var
|
|
717
|
+
var import_utils4 = require("@flowgram.ai/utils");
|
|
718
|
+
var import_free_layout_core6 = require("@flowgram.ai/free-layout-core");
|
|
801
719
|
var import_free_layout_core7 = require("@flowgram.ai/free-layout-core");
|
|
802
|
-
var import_free_layout_core8 = require("@flowgram.ai/free-layout-core");
|
|
803
720
|
|
|
804
721
|
// src/contributions/fold/fold-line.ts
|
|
805
|
-
var
|
|
722
|
+
var import_utils3 = require("@flowgram.ai/utils");
|
|
806
723
|
var getPointToSegmentDistance = (point, segStart, segEnd) => {
|
|
807
724
|
const { x: px, y: py } = point;
|
|
808
725
|
const { x: x1, y: y1 } = segStart;
|
|
@@ -841,23 +758,38 @@ var FoldLine;
|
|
|
841
758
|
const centerY = target.y < source.y ? target.y + yOffset : target.y - yOffset;
|
|
842
759
|
return [centerX, centerY];
|
|
843
760
|
}
|
|
844
|
-
const getDirection = ({ source, target }) =>
|
|
761
|
+
const getDirection = ({ source, target }) => {
|
|
762
|
+
if (source.location === "left" || source.location === "right") {
|
|
763
|
+
return source.x < target.x ? { x: 1, y: 0 } : { x: -1, y: 0 };
|
|
764
|
+
}
|
|
765
|
+
return source.y < target.y ? { x: 0, y: 1 } : { x: 0, y: -1 };
|
|
766
|
+
};
|
|
767
|
+
const handleDirections = {
|
|
768
|
+
left: { x: -1, y: 0 },
|
|
769
|
+
right: { x: 1, y: 0 },
|
|
770
|
+
top: { x: 0, y: -1 },
|
|
771
|
+
bottom: { x: 0, y: 1 }
|
|
772
|
+
};
|
|
845
773
|
function getPoints({
|
|
846
774
|
source,
|
|
847
|
-
target
|
|
848
|
-
vertical = false
|
|
775
|
+
target
|
|
849
776
|
}) {
|
|
850
|
-
const sourceDir =
|
|
851
|
-
const targetDir =
|
|
777
|
+
const sourceDir = handleDirections[source.location];
|
|
778
|
+
const targetDir = handleDirections[target.location];
|
|
852
779
|
const sourceGapped = {
|
|
853
780
|
x: source.x + sourceDir.x * OFFSET,
|
|
854
|
-
y: source.y + sourceDir.y * OFFSET
|
|
781
|
+
y: source.y + sourceDir.y * OFFSET,
|
|
782
|
+
location: source.location
|
|
855
783
|
};
|
|
856
784
|
const targetGapped = {
|
|
857
785
|
x: target.x + targetDir.x * OFFSET,
|
|
858
|
-
y: target.y + targetDir.y * OFFSET
|
|
786
|
+
y: target.y + targetDir.y * OFFSET,
|
|
787
|
+
location: target.location
|
|
859
788
|
};
|
|
860
|
-
const dir =
|
|
789
|
+
const dir = getDirection({
|
|
790
|
+
source: sourceGapped,
|
|
791
|
+
target: targetGapped
|
|
792
|
+
});
|
|
861
793
|
const dirAccessor = dir.x !== 0 ? "x" : "y";
|
|
862
794
|
const currDir = dir[dirAccessor];
|
|
863
795
|
let points = [];
|
|
@@ -928,8 +860,8 @@ var FoldLine;
|
|
|
928
860
|
FoldLine2.getPoints = getPoints;
|
|
929
861
|
function getBend(a, b, c) {
|
|
930
862
|
const bendSize = Math.min(
|
|
931
|
-
|
|
932
|
-
|
|
863
|
+
import_utils3.Point.getDistance(a, b) / 2,
|
|
864
|
+
import_utils3.Point.getDistance(b, c) / 2,
|
|
933
865
|
EDGE_RADIUS
|
|
934
866
|
);
|
|
935
867
|
const { x, y } = b;
|
|
@@ -966,7 +898,7 @@ var FoldLine;
|
|
|
966
898
|
const right = Math.max(...xList);
|
|
967
899
|
const top = Math.min(...yList);
|
|
968
900
|
const bottom = Math.max(...yList);
|
|
969
|
-
return
|
|
901
|
+
return import_utils3.Rectangle.createRectangleWithTwoPoints(
|
|
970
902
|
{
|
|
971
903
|
x: left,
|
|
972
904
|
y: top
|
|
@@ -983,7 +915,7 @@ var FoldLine;
|
|
|
983
915
|
return Infinity;
|
|
984
916
|
}
|
|
985
917
|
if (points.length === 1) {
|
|
986
|
-
return
|
|
918
|
+
return import_utils3.Point.getDistance(points[0], pos);
|
|
987
919
|
}
|
|
988
920
|
const lines = [];
|
|
989
921
|
for (let i = 0; i < points.length - 1; i++) {
|
|
@@ -1013,31 +945,31 @@ var WorkflowFoldLineContribution = class {
|
|
|
1013
945
|
}
|
|
1014
946
|
get bounds() {
|
|
1015
947
|
if (!this.data) {
|
|
1016
|
-
return new
|
|
948
|
+
return new import_utils4.Rectangle();
|
|
1017
949
|
}
|
|
1018
950
|
return this.data.bbox;
|
|
1019
951
|
}
|
|
1020
952
|
update(params) {
|
|
1021
953
|
const { fromPos, toPos } = params;
|
|
1022
|
-
const { vertical } = this.entity;
|
|
1023
954
|
const sourceOffset = {
|
|
1024
|
-
x:
|
|
1025
|
-
y:
|
|
955
|
+
x: fromPos.location === "bottom" ? 0 : import_free_layout_core6.POINT_RADIUS,
|
|
956
|
+
y: fromPos.location === "bottom" ? import_free_layout_core6.POINT_RADIUS : 0
|
|
1026
957
|
};
|
|
1027
958
|
const targetOffset = {
|
|
1028
|
-
x:
|
|
1029
|
-
y:
|
|
959
|
+
x: toPos.location === "top" ? 0 : -import_free_layout_core6.POINT_RADIUS,
|
|
960
|
+
y: toPos.location === "top" ? -import_free_layout_core6.POINT_RADIUS : 0
|
|
1030
961
|
};
|
|
1031
962
|
const points = FoldLine.getPoints({
|
|
1032
963
|
source: {
|
|
1033
964
|
x: fromPos.x + sourceOffset.x,
|
|
1034
|
-
y: fromPos.y + sourceOffset.y
|
|
965
|
+
y: fromPos.y + sourceOffset.y,
|
|
966
|
+
location: fromPos.location
|
|
1035
967
|
},
|
|
1036
968
|
target: {
|
|
1037
969
|
x: toPos.x + targetOffset.x,
|
|
1038
|
-
y: toPos.y + targetOffset.y
|
|
1039
|
-
|
|
1040
|
-
|
|
970
|
+
y: toPos.y + targetOffset.y,
|
|
971
|
+
location: toPos.location
|
|
972
|
+
}
|
|
1041
973
|
});
|
|
1042
974
|
const bbox = FoldLine.getBounds(points);
|
|
1043
975
|
const adjustedPoints = points.map((p) => ({
|
|
@@ -1052,11 +984,11 @@ var WorkflowFoldLineContribution = class {
|
|
|
1052
984
|
};
|
|
1053
985
|
}
|
|
1054
986
|
};
|
|
1055
|
-
WorkflowFoldLineContribution.type =
|
|
987
|
+
WorkflowFoldLineContribution.type = import_free_layout_core7.LineType.LINE_CHART;
|
|
1056
988
|
|
|
1057
989
|
// src/contributions/straight/index.ts
|
|
1058
|
-
var
|
|
1059
|
-
var
|
|
990
|
+
var import_utils5 = require("@flowgram.ai/utils");
|
|
991
|
+
var import_free_layout_core8 = require("@flowgram.ai/free-layout-core");
|
|
1060
992
|
|
|
1061
993
|
// src/contributions/straight/point-on-line.ts
|
|
1062
994
|
function projectPointOnLine(point, lineStart, lineEnd) {
|
|
@@ -1089,24 +1021,23 @@ var WorkflowStraightLineContribution = class {
|
|
|
1089
1021
|
return Number.MAX_SAFE_INTEGER;
|
|
1090
1022
|
}
|
|
1091
1023
|
const [start, end] = this.data.points;
|
|
1092
|
-
return
|
|
1024
|
+
return import_utils5.Point.getDistance(pos, projectPointOnLine(pos, start, end));
|
|
1093
1025
|
}
|
|
1094
1026
|
get bounds() {
|
|
1095
1027
|
if (!this.data) {
|
|
1096
|
-
return new
|
|
1028
|
+
return new import_utils5.Rectangle();
|
|
1097
1029
|
}
|
|
1098
1030
|
return this.data.bbox;
|
|
1099
1031
|
}
|
|
1100
1032
|
update(params) {
|
|
1101
1033
|
const { fromPos, toPos } = params;
|
|
1102
|
-
const { vertical } = this.entity;
|
|
1103
1034
|
const sourceOffset = {
|
|
1104
|
-
x:
|
|
1105
|
-
y:
|
|
1035
|
+
x: fromPos.location === "bottom" ? 0 : import_free_layout_core8.POINT_RADIUS,
|
|
1036
|
+
y: fromPos.location === "bottom" ? import_free_layout_core8.POINT_RADIUS : 0
|
|
1106
1037
|
};
|
|
1107
1038
|
const targetOffset = {
|
|
1108
|
-
x:
|
|
1109
|
-
y:
|
|
1039
|
+
x: toPos.location === "top" ? 0 : -import_free_layout_core8.POINT_RADIUS,
|
|
1040
|
+
y: toPos.location === "top" ? -import_free_layout_core8.POINT_RADIUS : 0
|
|
1110
1041
|
};
|
|
1111
1042
|
const points = [
|
|
1112
1043
|
{
|
|
@@ -1118,7 +1049,7 @@ var WorkflowStraightLineContribution = class {
|
|
|
1118
1049
|
y: toPos.y + targetOffset.y
|
|
1119
1050
|
}
|
|
1120
1051
|
];
|
|
1121
|
-
const bbox =
|
|
1052
|
+
const bbox = import_utils5.Rectangle.createRectangleWithTwoPoints(points[0], points[1]);
|
|
1122
1053
|
const adjustedPoints = points.map((p) => ({
|
|
1123
1054
|
x: p.x - bbox.x + LINE_PADDING,
|
|
1124
1055
|
y: p.y - bbox.y + LINE_PADDING
|
|
@@ -1134,8 +1065,8 @@ var WorkflowStraightLineContribution = class {
|
|
|
1134
1065
|
WorkflowStraightLineContribution.type = "WorkflowStraightLineContribution";
|
|
1135
1066
|
|
|
1136
1067
|
// src/contributions/arc/index.ts
|
|
1137
|
-
var
|
|
1138
|
-
var
|
|
1068
|
+
var import_utils6 = require("@flowgram.ai/utils");
|
|
1069
|
+
var import_free_layout_core9 = require("@flowgram.ai/free-layout-core");
|
|
1139
1070
|
var WorkflowArkLineContribution = class {
|
|
1140
1071
|
constructor(entity) {
|
|
1141
1072
|
this.entity = entity;
|
|
@@ -1157,13 +1088,13 @@ var WorkflowArkLineContribution = class {
|
|
|
1157
1088
|
x: (fromPos.x + toPos.x) / 2,
|
|
1158
1089
|
y: (fromPos.y + toPos.y) / 2
|
|
1159
1090
|
};
|
|
1160
|
-
const radius =
|
|
1161
|
-
const distanceToCenter =
|
|
1091
|
+
const radius = import_utils6.Point.getDistance(fromPos, center);
|
|
1092
|
+
const distanceToCenter = import_utils6.Point.getDistance(pos, center);
|
|
1162
1093
|
return Math.abs(distanceToCenter - radius);
|
|
1163
1094
|
}
|
|
1164
1095
|
get bounds() {
|
|
1165
1096
|
if (!this.data) {
|
|
1166
|
-
return new
|
|
1097
|
+
return new import_utils6.Rectangle();
|
|
1167
1098
|
}
|
|
1168
1099
|
return this.data.bbox;
|
|
1169
1100
|
}
|
|
@@ -1171,12 +1102,12 @@ var WorkflowArkLineContribution = class {
|
|
|
1171
1102
|
const { fromPos, toPos } = params;
|
|
1172
1103
|
const { vertical } = this.entity;
|
|
1173
1104
|
const sourceOffset = {
|
|
1174
|
-
x: vertical ? 0 :
|
|
1175
|
-
y: vertical ?
|
|
1105
|
+
x: vertical ? 0 : import_free_layout_core9.POINT_RADIUS,
|
|
1106
|
+
y: vertical ? import_free_layout_core9.POINT_RADIUS : 0
|
|
1176
1107
|
};
|
|
1177
1108
|
const targetOffset = {
|
|
1178
|
-
x: vertical ? 0 : -
|
|
1179
|
-
y: vertical ? -
|
|
1109
|
+
x: vertical ? 0 : -import_free_layout_core9.POINT_RADIUS,
|
|
1110
|
+
y: vertical ? -import_free_layout_core9.POINT_RADIUS : 0
|
|
1180
1111
|
};
|
|
1181
1112
|
const start = {
|
|
1182
1113
|
x: fromPos.x + sourceOffset.x,
|
|
@@ -1201,7 +1132,7 @@ var WorkflowArkLineContribution = class {
|
|
|
1201
1132
|
const radius = Math.sqrt(dx * dx + dy * dy) / 2;
|
|
1202
1133
|
const centerX = (start.x + end.x) / 2;
|
|
1203
1134
|
const centerY = (start.y + end.y) / 2;
|
|
1204
|
-
return new
|
|
1135
|
+
return new import_utils6.Rectangle(centerX - radius, centerY - radius, radius * 2, radius * 2);
|
|
1205
1136
|
}
|
|
1206
1137
|
getArcPath(start, end, bbox) {
|
|
1207
1138
|
const dx = end.x - start.x;
|
|
@@ -1220,131 +1151,6 @@ var WorkflowArkLineContribution = class {
|
|
|
1220
1151
|
};
|
|
1221
1152
|
WorkflowArkLineContribution.type = "WorkflowArkLineContribution";
|
|
1222
1153
|
|
|
1223
|
-
// src/contributions/manhattan/index.ts
|
|
1224
|
-
var import_utils8 = require("@flowgram.ai/utils");
|
|
1225
|
-
var import_free_layout_core11 = require("@flowgram.ai/free-layout-core");
|
|
1226
|
-
var WorkflowManhattanLineContribution = class {
|
|
1227
|
-
constructor(entity) {
|
|
1228
|
-
this.entity = entity;
|
|
1229
|
-
}
|
|
1230
|
-
get path() {
|
|
1231
|
-
return this.data?.path ?? "";
|
|
1232
|
-
}
|
|
1233
|
-
calcDistance(pos) {
|
|
1234
|
-
if (!this.data) {
|
|
1235
|
-
return Number.MAX_SAFE_INTEGER;
|
|
1236
|
-
}
|
|
1237
|
-
return Math.min(
|
|
1238
|
-
...this.data.points.slice(1).map((point, index) => {
|
|
1239
|
-
const prevPoint = this.data.points[index];
|
|
1240
|
-
return this.getDistanceToLineSegment(pos, prevPoint, point);
|
|
1241
|
-
})
|
|
1242
|
-
);
|
|
1243
|
-
}
|
|
1244
|
-
getDistanceToLineSegment(point, start, end) {
|
|
1245
|
-
const dx = end.x - start.x;
|
|
1246
|
-
const dy = end.y - start.y;
|
|
1247
|
-
if (dx === 0 && dy === 0) {
|
|
1248
|
-
return import_utils8.Point.getDistance(point, start);
|
|
1249
|
-
}
|
|
1250
|
-
const t = ((point.x - start.x) * dx + (point.y - start.y) * dy) / (dx * dx + dy * dy);
|
|
1251
|
-
if (t < 0) return import_utils8.Point.getDistance(point, start);
|
|
1252
|
-
if (t > 1) return import_utils8.Point.getDistance(point, end);
|
|
1253
|
-
const projectionPoint = {
|
|
1254
|
-
x: start.x + t * dx,
|
|
1255
|
-
y: start.y + t * dy
|
|
1256
|
-
};
|
|
1257
|
-
return import_utils8.Point.getDistance(point, projectionPoint);
|
|
1258
|
-
}
|
|
1259
|
-
get bounds() {
|
|
1260
|
-
if (!this.data) {
|
|
1261
|
-
return new import_utils8.Rectangle();
|
|
1262
|
-
}
|
|
1263
|
-
return this.data.bbox;
|
|
1264
|
-
}
|
|
1265
|
-
update(params) {
|
|
1266
|
-
const { fromPos, toPos } = params;
|
|
1267
|
-
const { vertical } = this.entity;
|
|
1268
|
-
const sourceOffset = {
|
|
1269
|
-
x: vertical ? 0 : import_free_layout_core11.POINT_RADIUS,
|
|
1270
|
-
y: vertical ? import_free_layout_core11.POINT_RADIUS : 0
|
|
1271
|
-
};
|
|
1272
|
-
const targetOffset = {
|
|
1273
|
-
x: vertical ? 0 : -import_free_layout_core11.POINT_RADIUS,
|
|
1274
|
-
y: vertical ? -import_free_layout_core11.POINT_RADIUS : 0
|
|
1275
|
-
};
|
|
1276
|
-
const points = this.getManhattanPoints({
|
|
1277
|
-
source: {
|
|
1278
|
-
x: fromPos.x + sourceOffset.x,
|
|
1279
|
-
y: fromPos.y + sourceOffset.y
|
|
1280
|
-
},
|
|
1281
|
-
target: {
|
|
1282
|
-
x: toPos.x + targetOffset.x,
|
|
1283
|
-
y: toPos.y + targetOffset.y
|
|
1284
|
-
},
|
|
1285
|
-
vertical
|
|
1286
|
-
});
|
|
1287
|
-
const bbox = import_utils8.Rectangle.createRectangleWithTwoPoints(
|
|
1288
|
-
points.reduce(
|
|
1289
|
-
(min, p) => ({
|
|
1290
|
-
x: Math.min(min.x, p.x),
|
|
1291
|
-
y: Math.min(min.y, p.y)
|
|
1292
|
-
}),
|
|
1293
|
-
points[0]
|
|
1294
|
-
),
|
|
1295
|
-
points.reduce(
|
|
1296
|
-
(max, p) => ({
|
|
1297
|
-
x: Math.max(max.x, p.x),
|
|
1298
|
-
y: Math.max(max.y, p.y)
|
|
1299
|
-
}),
|
|
1300
|
-
points[0]
|
|
1301
|
-
)
|
|
1302
|
-
);
|
|
1303
|
-
const adjustedPoints = points.map((p) => ({
|
|
1304
|
-
x: p.x - bbox.x + LINE_PADDING,
|
|
1305
|
-
y: p.y - bbox.y + LINE_PADDING
|
|
1306
|
-
}));
|
|
1307
|
-
const path = this.getPathFromPoints(adjustedPoints);
|
|
1308
|
-
this.data = {
|
|
1309
|
-
points,
|
|
1310
|
-
path,
|
|
1311
|
-
bbox
|
|
1312
|
-
};
|
|
1313
|
-
}
|
|
1314
|
-
getManhattanPoints(params) {
|
|
1315
|
-
const { source, target, vertical } = params;
|
|
1316
|
-
const points = [source];
|
|
1317
|
-
if (vertical) {
|
|
1318
|
-
if (source.y !== target.y) {
|
|
1319
|
-
points.push({ x: source.x, y: target.y });
|
|
1320
|
-
}
|
|
1321
|
-
if (source.x !== target.x) {
|
|
1322
|
-
points.push({ x: target.x, y: target.y });
|
|
1323
|
-
}
|
|
1324
|
-
} else {
|
|
1325
|
-
if (source.x !== target.x) {
|
|
1326
|
-
points.push({ x: target.x, y: source.y });
|
|
1327
|
-
}
|
|
1328
|
-
if (source.y !== target.y) {
|
|
1329
|
-
points.push({ x: target.x, y: target.y });
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
|
-
if (points[points.length - 1] !== target) {
|
|
1333
|
-
points.push(target);
|
|
1334
|
-
}
|
|
1335
|
-
return points;
|
|
1336
|
-
}
|
|
1337
|
-
getPathFromPoints(points) {
|
|
1338
|
-
return points.reduce((path, point, index) => {
|
|
1339
|
-
if (index === 0) {
|
|
1340
|
-
return `M ${point.x} ${point.y}`;
|
|
1341
|
-
}
|
|
1342
|
-
return `${path} L ${point.x} ${point.y}`;
|
|
1343
|
-
}, "");
|
|
1344
|
-
}
|
|
1345
|
-
};
|
|
1346
|
-
WorkflowManhattanLineContribution.type = "WorkflowManhattanLineContribution";
|
|
1347
|
-
|
|
1348
1154
|
// src/create-free-lines-plugin.ts
|
|
1349
1155
|
var createFreeLinesPlugin = (0, import_core3.definePluginCreator)({
|
|
1350
1156
|
singleton: true,
|
|
@@ -1354,7 +1160,7 @@ var createFreeLinesPlugin = (0, import_core3.definePluginCreator)({
|
|
|
1354
1160
|
});
|
|
1355
1161
|
},
|
|
1356
1162
|
onReady: (ctx, opts) => {
|
|
1357
|
-
const linesManager = ctx.container.get(
|
|
1163
|
+
const linesManager = ctx.container.get(import_free_layout_core10.WorkflowLinesManager);
|
|
1358
1164
|
linesManager.registerContribution(WorkflowBezierLineContribution).registerContribution(WorkflowFoldLineContribution);
|
|
1359
1165
|
if (opts.contributions) {
|
|
1360
1166
|
opts.contributions.forEach((contribution) => {
|
|
@@ -1368,7 +1174,6 @@ var createFreeLinesPlugin = (0, import_core3.definePluginCreator)({
|
|
|
1368
1174
|
});
|
|
1369
1175
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1370
1176
|
0 && (module.exports = {
|
|
1371
|
-
BezierControlType,
|
|
1372
1177
|
LINE_OFFSET,
|
|
1373
1178
|
LINE_PADDING,
|
|
1374
1179
|
LinesLayer,
|
|
@@ -1376,11 +1181,8 @@ var createFreeLinesPlugin = (0, import_core3.definePluginCreator)({
|
|
|
1376
1181
|
WorkflowBezierLineContribution,
|
|
1377
1182
|
WorkflowFoldLineContribution,
|
|
1378
1183
|
WorkflowLinesLayer,
|
|
1379
|
-
WorkflowManhattanLineContribution,
|
|
1380
1184
|
WorkflowPortRender,
|
|
1381
1185
|
WorkflowStraightLineContribution,
|
|
1382
|
-
createFreeLinesPlugin
|
|
1383
|
-
getBezierHorizontalControlPoints,
|
|
1384
|
-
getBezierVerticalControlPoints
|
|
1186
|
+
createFreeLinesPlugin
|
|
1385
1187
|
});
|
|
1386
1188
|
//# sourceMappingURL=index.js.map
|