@flowgram.ai/free-lines-plugin 0.1.0-alpha.12 → 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 +188 -437
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +15 -87
- package/dist/index.d.ts +15 -87
- package/dist/index.js +191 -438
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
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
|
|
299
|
-
className: "gedit-flow-activity-edge"
|
|
300
|
-
})`
|
|
298
|
+
var LineStyle = styled2.div`
|
|
301
299
|
position: absolute;
|
|
302
300
|
|
|
303
301
|
@keyframes flowingDash {
|
|
@@ -345,18 +343,18 @@ function ArrowRenderer({
|
|
|
345
343
|
var PADDING = 12;
|
|
346
344
|
var LineSVG = (props) => {
|
|
347
345
|
const { line, color, selected, children, strokePrefix, rendererRegistry } = props;
|
|
348
|
-
const { position, reverse,
|
|
346
|
+
const { position, reverse, hideArrow, vertical } = line;
|
|
349
347
|
const renderData = line.getData(WorkflowLineRenderData);
|
|
350
348
|
const { bounds, path: bezierPath } = renderData;
|
|
351
|
-
const
|
|
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 =
|
|
356
|
-
const toPos =
|
|
357
|
-
const arrowToPos =
|
|
358
|
-
const arrowFromPos =
|
|
359
|
-
const strokeWidth = selected ? STROKE_WIDTH_SLECTED : STROKE_WIDTH;
|
|
353
|
+
const fromPos = toRelative2(position.from);
|
|
354
|
+
const toPos = toRelative2(position.to);
|
|
355
|
+
const arrowToPos = position.to.location === "top" ? { x: toPos.x, y: toPos.y - POINT_RADIUS } : { x: toPos.x - POINT_RADIUS, y: toPos.y };
|
|
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 };
|
|
357
|
+
const strokeWidth = selected ? line.uiState.strokeWidthSelected ?? STROKE_WIDTH_SLECTED : line.uiState.strokeWidth ?? STROKE_WIDTH;
|
|
360
358
|
const strokeID = strokePrefix ? `${strokePrefix}-${line.id}` : line.id;
|
|
361
359
|
const CustomArrowRenderer = rendererRegistry?.tryToGetRendererComponent("arrow-renderer")?.renderer;
|
|
362
360
|
const ArrowComponent = CustomArrowRenderer || ArrowRenderer;
|
|
@@ -367,17 +365,15 @@ var LineSVG = (props) => {
|
|
|
367
365
|
fill: "none",
|
|
368
366
|
stroke: `url(#${strokeID})`,
|
|
369
367
|
strokeWidth,
|
|
370
|
-
className:
|
|
371
|
-
line.className,
|
|
372
|
-
// 显示流动线条的条件:没有自定义线条class,并且线条处于流动或处理中
|
|
373
|
-
!line.className && (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"
|
|
@@ -559,145 +555,90 @@ WorkflowLinesLayer = __decorateClass([
|
|
|
559
555
|
injectable()
|
|
560
556
|
], WorkflowLinesLayer);
|
|
561
557
|
|
|
558
|
+
// src/contributions/bezier/index.ts
|
|
559
|
+
import { Bezier } from "bezier-js";
|
|
560
|
+
import { Point, Rectangle } from "@flowgram.ai/utils";
|
|
561
|
+
import { LineType } from "@flowgram.ai/free-layout-core";
|
|
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
|
+
|
|
562
571
|
// src/contributions/bezier/bezier-controls.ts
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
})(BezierControlType || {});
|
|
571
|
-
var CONTROL_MAX = 300;
|
|
572
|
-
function getBezierHorizontalControlPoints(fromPos, toPos) {
|
|
573
|
-
const rect = Rectangle.createRectangleWithTwoPoints(fromPos, toPos);
|
|
574
|
-
let type;
|
|
575
|
-
if (fromPos.x <= toPos.x) {
|
|
576
|
-
type = fromPos.y <= toPos.y ? 1 /* RIGHT_BOTTOM */ : 0 /* RIGHT_TOP */;
|
|
577
|
-
} else {
|
|
578
|
-
type = fromPos.y <= toPos.y ? 3 /* LEFT_BOTTOM */ : 2 /* LEFT_TOP */;
|
|
579
|
-
}
|
|
580
|
-
let controls;
|
|
581
|
-
switch (type) {
|
|
582
|
-
case 0 /* RIGHT_TOP */:
|
|
583
|
-
controls = [
|
|
584
|
-
{
|
|
585
|
-
x: rect.rightBottom.x - rect.width / 2,
|
|
586
|
-
y: rect.rightBottom.y
|
|
587
|
-
},
|
|
588
|
-
{
|
|
589
|
-
x: rect.leftTop.x + rect.width / 2,
|
|
590
|
-
y: rect.leftTop.y
|
|
591
|
-
}
|
|
592
|
-
];
|
|
593
|
-
break;
|
|
594
|
-
case 1 /* RIGHT_BOTTOM */:
|
|
595
|
-
controls = [
|
|
596
|
-
{
|
|
597
|
-
x: rect.rightTop.x - rect.width / 2,
|
|
598
|
-
y: rect.rightTop.y
|
|
599
|
-
},
|
|
600
|
-
{
|
|
601
|
-
x: rect.leftBottom.x + rect.width / 2,
|
|
602
|
-
y: rect.leftBottom.y
|
|
603
|
-
}
|
|
604
|
-
];
|
|
605
|
-
break;
|
|
606
|
-
case 2 /* LEFT_TOP */:
|
|
607
|
-
controls = [
|
|
608
|
-
{
|
|
609
|
-
x: rect.rightBottom.x + Math.min(rect.width, CONTROL_MAX),
|
|
610
|
-
y: rect.rightBottom.y
|
|
611
|
-
},
|
|
612
|
-
{
|
|
613
|
-
x: rect.leftTop.x - Math.min(rect.width, CONTROL_MAX),
|
|
614
|
-
y: rect.leftTop.y
|
|
615
|
-
}
|
|
616
|
-
];
|
|
617
|
-
break;
|
|
618
|
-
case 3 /* LEFT_BOTTOM */:
|
|
619
|
-
controls = [
|
|
620
|
-
{
|
|
621
|
-
x: rect.rightTop.x + Math.min(rect.width, CONTROL_MAX),
|
|
622
|
-
y: rect.rightTop.y
|
|
623
|
-
},
|
|
624
|
-
{
|
|
625
|
-
x: rect.leftBottom.x - Math.min(rect.width, CONTROL_MAX),
|
|
626
|
-
y: rect.leftBottom.y
|
|
627
|
-
}
|
|
628
|
-
];
|
|
629
|
-
}
|
|
630
|
-
return controls;
|
|
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
|
+
};
|
|
631
579
|
}
|
|
632
|
-
function
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
if (fromPos.y <= toPos.y) {
|
|
636
|
-
type = fromPos.x <= toPos.x ? 1 /* RIGHT_BOTTOM */ : 3 /* LEFT_BOTTOM */;
|
|
637
|
-
} else {
|
|
638
|
-
type = fromPos.x <= toPos.x ? 0 /* RIGHT_TOP */ : 2 /* LEFT_TOP */;
|
|
580
|
+
function getControlOffset(distance, curvature) {
|
|
581
|
+
if (distance >= 0) {
|
|
582
|
+
return 0.5 * distance;
|
|
639
583
|
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
case
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
},
|
|
672
|
-
{
|
|
673
|
-
x: rect.rightTop.x,
|
|
674
|
-
y: rect.rightTop.y - Math.min(rect.height, CONTROL_MAX)
|
|
675
|
-
}
|
|
676
|
-
];
|
|
677
|
-
break;
|
|
678
|
-
case 2 /* LEFT_TOP */:
|
|
679
|
-
controls = [
|
|
680
|
-
{
|
|
681
|
-
x: rect.rightBottom.x,
|
|
682
|
-
y: rect.rightBottom.y + Math.min(rect.height, CONTROL_MAX)
|
|
683
|
-
},
|
|
684
|
-
{
|
|
685
|
-
x: rect.leftTop.x,
|
|
686
|
-
y: rect.leftTop.y - Math.min(rect.height, CONTROL_MAX)
|
|
687
|
-
}
|
|
688
|
-
];
|
|
689
|
-
break;
|
|
584
|
+
return curvature * 25 * Math.sqrt(-distance);
|
|
585
|
+
}
|
|
586
|
+
function getControlWithCurvature({
|
|
587
|
+
location,
|
|
588
|
+
x1,
|
|
589
|
+
y1,
|
|
590
|
+
x2,
|
|
591
|
+
y2,
|
|
592
|
+
curvature
|
|
593
|
+
}) {
|
|
594
|
+
switch (location) {
|
|
595
|
+
case "left":
|
|
596
|
+
return {
|
|
597
|
+
x: x1 - getControlOffset(x1 - x2, curvature),
|
|
598
|
+
y: y1
|
|
599
|
+
};
|
|
600
|
+
case "right":
|
|
601
|
+
return {
|
|
602
|
+
x: x1 + getControlOffset(x2 - x1, curvature),
|
|
603
|
+
y: y1
|
|
604
|
+
};
|
|
605
|
+
case "top":
|
|
606
|
+
return {
|
|
607
|
+
x: x1,
|
|
608
|
+
y: y1 - getControlOffset(y1 - y2, curvature)
|
|
609
|
+
};
|
|
610
|
+
case "bottom":
|
|
611
|
+
return {
|
|
612
|
+
x: x1,
|
|
613
|
+
y: y1 + getControlOffset(y2 - y1, curvature)
|
|
614
|
+
};
|
|
690
615
|
}
|
|
691
|
-
|
|
616
|
+
}
|
|
617
|
+
function getBezierControlPoints(fromPos, toPos, curvature = 0.25) {
|
|
618
|
+
const fromControl = getControlWithCurvature({
|
|
619
|
+
location: fromPos.location,
|
|
620
|
+
x1: fromPos.x,
|
|
621
|
+
y1: fromPos.y,
|
|
622
|
+
x2: toPos.x,
|
|
623
|
+
y2: toPos.y,
|
|
624
|
+
curvature
|
|
625
|
+
});
|
|
626
|
+
const toControl = getControlWithCurvature({
|
|
627
|
+
location: toPos.location,
|
|
628
|
+
x1: toPos.x,
|
|
629
|
+
y1: toPos.y,
|
|
630
|
+
x2: fromPos.x,
|
|
631
|
+
y2: fromPos.y,
|
|
632
|
+
curvature
|
|
633
|
+
});
|
|
634
|
+
const center = getBezierEdgeCenter(fromPos, toPos, fromControl, toControl);
|
|
635
|
+
return {
|
|
636
|
+
controls: [fromControl, toControl],
|
|
637
|
+
center
|
|
638
|
+
};
|
|
692
639
|
}
|
|
693
640
|
|
|
694
641
|
// src/contributions/bezier/index.ts
|
|
695
|
-
import { Bezier } from "bezier-js";
|
|
696
|
-
import { Point, Rectangle as Rectangle2 } from "@flowgram.ai/utils";
|
|
697
|
-
import {
|
|
698
|
-
POINT_RADIUS as POINT_RADIUS2
|
|
699
|
-
} from "@flowgram.ai/free-layout-core";
|
|
700
|
-
import { LineType } from "@flowgram.ai/free-layout-core";
|
|
701
642
|
var WorkflowBezierLineContribution = class {
|
|
702
643
|
constructor(entity) {
|
|
703
644
|
this.entity = entity;
|
|
@@ -713,23 +654,31 @@ var WorkflowBezierLineContribution = class {
|
|
|
713
654
|
}
|
|
714
655
|
get bounds() {
|
|
715
656
|
if (!this.data) {
|
|
716
|
-
return
|
|
657
|
+
return Rectangle.EMPTY;
|
|
717
658
|
}
|
|
718
659
|
return this.data.bbox;
|
|
719
660
|
}
|
|
661
|
+
get center() {
|
|
662
|
+
return this.data?.center;
|
|
663
|
+
}
|
|
720
664
|
update(params) {
|
|
721
665
|
this.data = this.calcBezier(params.fromPos, params.toPos);
|
|
722
666
|
}
|
|
723
667
|
calcBezier(fromPos, toPos) {
|
|
724
|
-
const controls
|
|
668
|
+
const { controls, center } = getBezierControlPoints(
|
|
669
|
+
fromPos,
|
|
670
|
+
toPos,
|
|
671
|
+
this.entity.uiState.curvature
|
|
672
|
+
);
|
|
725
673
|
const bezier = new Bezier([fromPos, ...controls, toPos]);
|
|
726
674
|
const bbox = bezier.bbox();
|
|
727
|
-
const bboxBounds = new
|
|
675
|
+
const bboxBounds = new Rectangle(
|
|
728
676
|
bbox.x.min,
|
|
729
677
|
bbox.y.min,
|
|
730
678
|
bbox.x.max - bbox.x.min,
|
|
731
679
|
bbox.y.max - bbox.y.min
|
|
732
680
|
);
|
|
681
|
+
const centerPoint = toRelative(center, bboxBounds);
|
|
733
682
|
const path = this.getPath({ bbox: bboxBounds, fromPos, toPos, controls });
|
|
734
683
|
this.data = {
|
|
735
684
|
fromPos,
|
|
@@ -737,43 +686,35 @@ var WorkflowBezierLineContribution = class {
|
|
|
737
686
|
bezier,
|
|
738
687
|
bbox: bboxBounds,
|
|
739
688
|
controls,
|
|
740
|
-
path
|
|
689
|
+
path,
|
|
690
|
+
center: {
|
|
691
|
+
...center,
|
|
692
|
+
labelX: centerPoint.x,
|
|
693
|
+
labelY: centerPoint.y
|
|
694
|
+
}
|
|
741
695
|
};
|
|
742
696
|
return this.data;
|
|
743
697
|
}
|
|
744
698
|
getPath(params) {
|
|
745
699
|
const { bbox } = params;
|
|
746
|
-
const
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
const
|
|
751
|
-
const
|
|
752
|
-
const
|
|
753
|
-
|
|
754
|
-
const getPathData = () => {
|
|
755
|
-
const controlPoints = controls.map((s) => `${s.x} ${s.y}`).join(",");
|
|
756
|
-
const curveType = controls.length === 1 ? "S" : "C";
|
|
757
|
-
if (this.entity.vertical) {
|
|
758
|
-
return `M${fromPos.x} ${fromPos.y + POINT_RADIUS2} ${curveType} ${controlPoints}, ${renderToPos.x} ${renderToPos.y}`;
|
|
759
|
-
}
|
|
760
|
-
return `M${fromPos.x + POINT_RADIUS2} ${fromPos.y} ${curveType} ${controlPoints}, ${renderToPos.x} ${renderToPos.y}`;
|
|
761
|
-
};
|
|
762
|
-
const path = getPathData();
|
|
763
|
-
return path;
|
|
700
|
+
const fromPos = toRelative(params.fromPos, bbox);
|
|
701
|
+
const toPos = toRelative(params.toPos, bbox);
|
|
702
|
+
const controls = params.controls.map((c) => toRelative(c, bbox));
|
|
703
|
+
const shrink = this.entity.uiState.shrink;
|
|
704
|
+
const renderFromPos = params.fromPos.location === "bottom" ? { x: fromPos.x, y: fromPos.y + shrink } : { x: fromPos.x + shrink, y: fromPos.y };
|
|
705
|
+
const renderToPos = params.toPos.location === "top" ? { x: toPos.x, y: toPos.y - shrink } : { x: toPos.x - shrink, y: toPos.y };
|
|
706
|
+
const controlPoints = controls.map((s) => `${s.x} ${s.y}`).join(",");
|
|
707
|
+
return `M${renderFromPos.x} ${renderFromPos.y} C ${controlPoints}, ${renderToPos.x} ${renderToPos.y}`;
|
|
764
708
|
}
|
|
765
709
|
};
|
|
766
710
|
WorkflowBezierLineContribution.type = LineType.BEZIER;
|
|
767
711
|
|
|
768
712
|
// src/contributions/fold/index.ts
|
|
769
|
-
import { Rectangle as
|
|
770
|
-
import {
|
|
771
|
-
POINT_RADIUS as POINT_RADIUS3
|
|
772
|
-
} from "@flowgram.ai/free-layout-core";
|
|
713
|
+
import { Rectangle as Rectangle3 } from "@flowgram.ai/utils";
|
|
773
714
|
import { LineType as LineType2 } from "@flowgram.ai/free-layout-core";
|
|
774
715
|
|
|
775
716
|
// src/contributions/fold/fold-line.ts
|
|
776
|
-
import { Point as Point2, Rectangle as
|
|
717
|
+
import { Point as Point2, Rectangle as Rectangle2 } from "@flowgram.ai/utils";
|
|
777
718
|
var getPointToSegmentDistance = (point, segStart, segEnd) => {
|
|
778
719
|
const { x: px, y: py } = point;
|
|
779
720
|
const { x: x1, y: y1 } = segStart;
|
|
@@ -812,23 +753,35 @@ var FoldLine;
|
|
|
812
753
|
const centerY = target.y < source.y ? target.y + yOffset : target.y - yOffset;
|
|
813
754
|
return [centerX, centerY];
|
|
814
755
|
}
|
|
815
|
-
const getDirection = ({ source, target }) =>
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
|
|
756
|
+
const getDirection = ({ source, target }) => {
|
|
757
|
+
if (source.location === "left" || source.location === "right") {
|
|
758
|
+
return source.x < target.x ? { x: 1, y: 0 } : { x: -1, y: 0 };
|
|
759
|
+
}
|
|
760
|
+
return source.y < target.y ? { x: 0, y: 1 } : { x: 0, y: -1 };
|
|
761
|
+
};
|
|
762
|
+
const handleDirections = {
|
|
763
|
+
left: { x: -1, y: 0 },
|
|
764
|
+
right: { x: 1, y: 0 },
|
|
765
|
+
top: { x: 0, y: -1 },
|
|
766
|
+
bottom: { x: 0, y: 1 }
|
|
767
|
+
};
|
|
768
|
+
function getPoints({ source, target }) {
|
|
769
|
+
const sourceDir = handleDirections[source.location];
|
|
770
|
+
const targetDir = handleDirections[target.location];
|
|
823
771
|
const sourceGapped = {
|
|
824
772
|
x: source.x + sourceDir.x * OFFSET,
|
|
825
|
-
y: source.y + sourceDir.y * OFFSET
|
|
773
|
+
y: source.y + sourceDir.y * OFFSET,
|
|
774
|
+
location: source.location
|
|
826
775
|
};
|
|
827
776
|
const targetGapped = {
|
|
828
777
|
x: target.x + targetDir.x * OFFSET,
|
|
829
|
-
y: target.y + targetDir.y * OFFSET
|
|
778
|
+
y: target.y + targetDir.y * OFFSET,
|
|
779
|
+
location: target.location
|
|
830
780
|
};
|
|
831
|
-
const dir =
|
|
781
|
+
const dir = getDirection({
|
|
782
|
+
source: sourceGapped,
|
|
783
|
+
target: targetGapped
|
|
784
|
+
});
|
|
832
785
|
const dirAccessor = dir.x !== 0 ? "x" : "y";
|
|
833
786
|
const currDir = dir[dirAccessor];
|
|
834
787
|
let points = [];
|
|
@@ -894,7 +847,13 @@ var FoldLine;
|
|
|
894
847
|
{ x: targetGapped.x, y: targetGapped.y },
|
|
895
848
|
target
|
|
896
849
|
];
|
|
897
|
-
return
|
|
850
|
+
return {
|
|
851
|
+
points: pathPoints,
|
|
852
|
+
center: {
|
|
853
|
+
x: centerX,
|
|
854
|
+
y: centerY
|
|
855
|
+
}
|
|
856
|
+
};
|
|
898
857
|
}
|
|
899
858
|
FoldLine2.getPoints = getPoints;
|
|
900
859
|
function getBend(a, b, c) {
|
|
@@ -937,7 +896,7 @@ var FoldLine;
|
|
|
937
896
|
const right = Math.max(...xList);
|
|
938
897
|
const top = Math.min(...yList);
|
|
939
898
|
const bottom = Math.max(...yList);
|
|
940
|
-
return
|
|
899
|
+
return Rectangle2.createRectangleWithTwoPoints(
|
|
941
900
|
{
|
|
942
901
|
x: left,
|
|
943
902
|
y: top
|
|
@@ -984,51 +943,60 @@ var WorkflowFoldLineContribution = class {
|
|
|
984
943
|
}
|
|
985
944
|
get bounds() {
|
|
986
945
|
if (!this.data) {
|
|
987
|
-
return new
|
|
946
|
+
return new Rectangle3();
|
|
988
947
|
}
|
|
989
948
|
return this.data.bbox;
|
|
990
949
|
}
|
|
950
|
+
get center() {
|
|
951
|
+
return this.data?.center;
|
|
952
|
+
}
|
|
991
953
|
update(params) {
|
|
992
954
|
const { fromPos, toPos } = params;
|
|
993
|
-
const
|
|
955
|
+
const shrink = this.entity.uiState.shrink;
|
|
994
956
|
const sourceOffset = {
|
|
995
|
-
x:
|
|
996
|
-
y:
|
|
957
|
+
x: fromPos.location === "bottom" ? 0 : shrink,
|
|
958
|
+
y: fromPos.location === "bottom" ? shrink : 0
|
|
997
959
|
};
|
|
998
960
|
const targetOffset = {
|
|
999
|
-
x:
|
|
1000
|
-
y:
|
|
961
|
+
x: toPos.location === "top" ? 0 : -shrink,
|
|
962
|
+
y: toPos.location === "top" ? -shrink : 0
|
|
1001
963
|
};
|
|
1002
|
-
const points = FoldLine.getPoints({
|
|
964
|
+
const { points, center } = FoldLine.getPoints({
|
|
1003
965
|
source: {
|
|
1004
966
|
x: fromPos.x + sourceOffset.x,
|
|
1005
|
-
y: fromPos.y + sourceOffset.y
|
|
967
|
+
y: fromPos.y + sourceOffset.y,
|
|
968
|
+
location: fromPos.location
|
|
1006
969
|
},
|
|
1007
970
|
target: {
|
|
1008
971
|
x: toPos.x + targetOffset.x,
|
|
1009
|
-
y: toPos.y + targetOffset.y
|
|
1010
|
-
|
|
1011
|
-
|
|
972
|
+
y: toPos.y + targetOffset.y,
|
|
973
|
+
location: toPos.location
|
|
974
|
+
}
|
|
1012
975
|
});
|
|
1013
976
|
const bbox = FoldLine.getBounds(points);
|
|
1014
|
-
const adjustedPoints = points.map((p) => (
|
|
1015
|
-
x: p.x - bbox.x + LINE_PADDING,
|
|
1016
|
-
y: p.y - bbox.y + LINE_PADDING
|
|
1017
|
-
}));
|
|
977
|
+
const adjustedPoints = points.map((p) => toRelative(p, bbox));
|
|
1018
978
|
const path = FoldLine.getSmoothStepPath(adjustedPoints);
|
|
979
|
+
const relativeCenter = toRelative(center, bbox);
|
|
1019
980
|
this.data = {
|
|
1020
981
|
points,
|
|
1021
982
|
path,
|
|
1022
|
-
bbox
|
|
983
|
+
bbox,
|
|
984
|
+
center: {
|
|
985
|
+
x: center.x,
|
|
986
|
+
y: center.y,
|
|
987
|
+
labelX: relativeCenter.x,
|
|
988
|
+
labelY: relativeCenter.y
|
|
989
|
+
}
|
|
1023
990
|
};
|
|
1024
991
|
}
|
|
1025
992
|
};
|
|
1026
993
|
WorkflowFoldLineContribution.type = LineType2.LINE_CHART;
|
|
1027
994
|
|
|
1028
995
|
// src/contributions/straight/index.ts
|
|
1029
|
-
import { Point as Point3, Rectangle as
|
|
996
|
+
import { Point as Point3, Rectangle as Rectangle4 } from "@flowgram.ai/utils";
|
|
1030
997
|
import {
|
|
1031
|
-
|
|
998
|
+
getLineCenter,
|
|
999
|
+
LineType as LineType3
|
|
1032
1000
|
} from "@flowgram.ai/free-layout-core";
|
|
1033
1001
|
|
|
1034
1002
|
// src/contributions/straight/point-on-line.ts
|
|
@@ -1066,20 +1034,23 @@ var WorkflowStraightLineContribution = class {
|
|
|
1066
1034
|
}
|
|
1067
1035
|
get bounds() {
|
|
1068
1036
|
if (!this.data) {
|
|
1069
|
-
return new
|
|
1037
|
+
return new Rectangle4();
|
|
1070
1038
|
}
|
|
1071
1039
|
return this.data.bbox;
|
|
1072
1040
|
}
|
|
1041
|
+
get center() {
|
|
1042
|
+
return this.data?.center;
|
|
1043
|
+
}
|
|
1073
1044
|
update(params) {
|
|
1074
1045
|
const { fromPos, toPos } = params;
|
|
1075
|
-
const
|
|
1046
|
+
const shrink = this.entity.uiState.shrink;
|
|
1076
1047
|
const sourceOffset = {
|
|
1077
|
-
x:
|
|
1078
|
-
y:
|
|
1048
|
+
x: fromPos.location === "bottom" ? 0 : shrink,
|
|
1049
|
+
y: fromPos.location === "bottom" ? shrink : 0
|
|
1079
1050
|
};
|
|
1080
1051
|
const targetOffset = {
|
|
1081
|
-
x:
|
|
1082
|
-
y:
|
|
1052
|
+
x: toPos.location === "top" ? 0 : -shrink,
|
|
1053
|
+
y: toPos.location === "top" ? -shrink : 0
|
|
1083
1054
|
};
|
|
1084
1055
|
const points = [
|
|
1085
1056
|
{
|
|
@@ -1091,7 +1062,7 @@ var WorkflowStraightLineContribution = class {
|
|
|
1091
1062
|
y: toPos.y + targetOffset.y
|
|
1092
1063
|
}
|
|
1093
1064
|
];
|
|
1094
|
-
const bbox =
|
|
1065
|
+
const bbox = Rectangle4.createRectangleWithTwoPoints(points[0], points[1]);
|
|
1095
1066
|
const adjustedPoints = points.map((p) => ({
|
|
1096
1067
|
x: p.x - bbox.x + LINE_PADDING,
|
|
1097
1068
|
y: p.y - bbox.y + LINE_PADDING
|
|
@@ -1100,227 +1071,12 @@ var WorkflowStraightLineContribution = class {
|
|
|
1100
1071
|
this.data = {
|
|
1101
1072
|
points,
|
|
1102
1073
|
path,
|
|
1103
|
-
bbox
|
|
1104
|
-
|
|
1105
|
-
}
|
|
1106
|
-
};
|
|
1107
|
-
WorkflowStraightLineContribution.type = "WorkflowStraightLineContribution";
|
|
1108
|
-
|
|
1109
|
-
// src/contributions/arc/index.ts
|
|
1110
|
-
import { Point as Point4, Rectangle as Rectangle6 } from "@flowgram.ai/utils";
|
|
1111
|
-
import {
|
|
1112
|
-
POINT_RADIUS as POINT_RADIUS5
|
|
1113
|
-
} from "@flowgram.ai/free-layout-core";
|
|
1114
|
-
var WorkflowArkLineContribution = class {
|
|
1115
|
-
constructor(entity) {
|
|
1116
|
-
this.entity = entity;
|
|
1117
|
-
}
|
|
1118
|
-
get path() {
|
|
1119
|
-
return this.data?.path ?? "";
|
|
1120
|
-
}
|
|
1121
|
-
calcDistance(pos) {
|
|
1122
|
-
if (!this.data) {
|
|
1123
|
-
return Number.MAX_SAFE_INTEGER;
|
|
1124
|
-
}
|
|
1125
|
-
const { fromPos, toPos, bbox } = this.data;
|
|
1126
|
-
if (!bbox.contains(pos.x, pos.y)) {
|
|
1127
|
-
const dx = Math.max(bbox.x - pos.x, 0, pos.x - (bbox.x + bbox.width));
|
|
1128
|
-
const dy = Math.max(bbox.y - pos.y, 0, pos.y - (bbox.y + bbox.height));
|
|
1129
|
-
return Math.sqrt(dx * dx + dy * dy);
|
|
1130
|
-
}
|
|
1131
|
-
const center = {
|
|
1132
|
-
x: (fromPos.x + toPos.x) / 2,
|
|
1133
|
-
y: (fromPos.y + toPos.y) / 2
|
|
1074
|
+
bbox,
|
|
1075
|
+
center: getLineCenter(fromPos, toPos, bbox, LINE_PADDING)
|
|
1134
1076
|
};
|
|
1135
|
-
const radius = Point4.getDistance(fromPos, center);
|
|
1136
|
-
const distanceToCenter = Point4.getDistance(pos, center);
|
|
1137
|
-
return Math.abs(distanceToCenter - radius);
|
|
1138
|
-
}
|
|
1139
|
-
get bounds() {
|
|
1140
|
-
if (!this.data) {
|
|
1141
|
-
return new Rectangle6();
|
|
1142
|
-
}
|
|
1143
|
-
return this.data.bbox;
|
|
1144
|
-
}
|
|
1145
|
-
update(params) {
|
|
1146
|
-
const { fromPos, toPos } = params;
|
|
1147
|
-
const { vertical } = this.entity;
|
|
1148
|
-
const sourceOffset = {
|
|
1149
|
-
x: vertical ? 0 : POINT_RADIUS5,
|
|
1150
|
-
y: vertical ? POINT_RADIUS5 : 0
|
|
1151
|
-
};
|
|
1152
|
-
const targetOffset = {
|
|
1153
|
-
x: vertical ? 0 : -POINT_RADIUS5,
|
|
1154
|
-
y: vertical ? -POINT_RADIUS5 : 0
|
|
1155
|
-
};
|
|
1156
|
-
const start = {
|
|
1157
|
-
x: fromPos.x + sourceOffset.x,
|
|
1158
|
-
y: fromPos.y + sourceOffset.y
|
|
1159
|
-
};
|
|
1160
|
-
const end = {
|
|
1161
|
-
x: toPos.x + targetOffset.x,
|
|
1162
|
-
y: toPos.y + targetOffset.y
|
|
1163
|
-
};
|
|
1164
|
-
const bbox = this.calculateArcBBox(start, end);
|
|
1165
|
-
const path = this.getArcPath(start, end, bbox);
|
|
1166
|
-
this.data = {
|
|
1167
|
-
fromPos: start,
|
|
1168
|
-
toPos: end,
|
|
1169
|
-
path,
|
|
1170
|
-
bbox
|
|
1171
|
-
};
|
|
1172
|
-
}
|
|
1173
|
-
calculateArcBBox(start, end) {
|
|
1174
|
-
const dx = end.x - start.x;
|
|
1175
|
-
const dy = end.y - start.y;
|
|
1176
|
-
const radius = Math.sqrt(dx * dx + dy * dy) / 2;
|
|
1177
|
-
const centerX = (start.x + end.x) / 2;
|
|
1178
|
-
const centerY = (start.y + end.y) / 2;
|
|
1179
|
-
return new Rectangle6(centerX - radius, centerY - radius, radius * 2, radius * 2);
|
|
1180
|
-
}
|
|
1181
|
-
getArcPath(start, end, bbox) {
|
|
1182
|
-
const dx = end.x - start.x;
|
|
1183
|
-
const dy = end.y - start.y;
|
|
1184
|
-
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
1185
|
-
const startRel = {
|
|
1186
|
-
x: start.x - bbox.x + LINE_PADDING,
|
|
1187
|
-
y: start.y - bbox.y + LINE_PADDING
|
|
1188
|
-
};
|
|
1189
|
-
const endRel = {
|
|
1190
|
-
x: end.x - bbox.x + LINE_PADDING,
|
|
1191
|
-
y: end.y - bbox.y + LINE_PADDING
|
|
1192
|
-
};
|
|
1193
|
-
return `M ${startRel.x} ${startRel.y} A ${distance / 2} ${distance / 2} 0 0 1 ${endRel.x} ${endRel.y}`;
|
|
1194
|
-
}
|
|
1195
|
-
};
|
|
1196
|
-
WorkflowArkLineContribution.type = "WorkflowArkLineContribution";
|
|
1197
|
-
|
|
1198
|
-
// src/contributions/manhattan/index.ts
|
|
1199
|
-
import { Point as Point5, Rectangle as Rectangle7 } from "@flowgram.ai/utils";
|
|
1200
|
-
import {
|
|
1201
|
-
POINT_RADIUS as POINT_RADIUS6
|
|
1202
|
-
} from "@flowgram.ai/free-layout-core";
|
|
1203
|
-
var WorkflowManhattanLineContribution = class {
|
|
1204
|
-
constructor(entity) {
|
|
1205
|
-
this.entity = entity;
|
|
1206
|
-
}
|
|
1207
|
-
get path() {
|
|
1208
|
-
return this.data?.path ?? "";
|
|
1209
|
-
}
|
|
1210
|
-
calcDistance(pos) {
|
|
1211
|
-
if (!this.data) {
|
|
1212
|
-
return Number.MAX_SAFE_INTEGER;
|
|
1213
|
-
}
|
|
1214
|
-
return Math.min(
|
|
1215
|
-
...this.data.points.slice(1).map((point, index) => {
|
|
1216
|
-
const prevPoint = this.data.points[index];
|
|
1217
|
-
return this.getDistanceToLineSegment(pos, prevPoint, point);
|
|
1218
|
-
})
|
|
1219
|
-
);
|
|
1220
|
-
}
|
|
1221
|
-
getDistanceToLineSegment(point, start, end) {
|
|
1222
|
-
const dx = end.x - start.x;
|
|
1223
|
-
const dy = end.y - start.y;
|
|
1224
|
-
if (dx === 0 && dy === 0) {
|
|
1225
|
-
return Point5.getDistance(point, start);
|
|
1226
|
-
}
|
|
1227
|
-
const t = ((point.x - start.x) * dx + (point.y - start.y) * dy) / (dx * dx + dy * dy);
|
|
1228
|
-
if (t < 0) return Point5.getDistance(point, start);
|
|
1229
|
-
if (t > 1) return Point5.getDistance(point, end);
|
|
1230
|
-
const projectionPoint = {
|
|
1231
|
-
x: start.x + t * dx,
|
|
1232
|
-
y: start.y + t * dy
|
|
1233
|
-
};
|
|
1234
|
-
return Point5.getDistance(point, projectionPoint);
|
|
1235
|
-
}
|
|
1236
|
-
get bounds() {
|
|
1237
|
-
if (!this.data) {
|
|
1238
|
-
return new Rectangle7();
|
|
1239
|
-
}
|
|
1240
|
-
return this.data.bbox;
|
|
1241
|
-
}
|
|
1242
|
-
update(params) {
|
|
1243
|
-
const { fromPos, toPos } = params;
|
|
1244
|
-
const { vertical } = this.entity;
|
|
1245
|
-
const sourceOffset = {
|
|
1246
|
-
x: vertical ? 0 : POINT_RADIUS6,
|
|
1247
|
-
y: vertical ? POINT_RADIUS6 : 0
|
|
1248
|
-
};
|
|
1249
|
-
const targetOffset = {
|
|
1250
|
-
x: vertical ? 0 : -POINT_RADIUS6,
|
|
1251
|
-
y: vertical ? -POINT_RADIUS6 : 0
|
|
1252
|
-
};
|
|
1253
|
-
const points = this.getManhattanPoints({
|
|
1254
|
-
source: {
|
|
1255
|
-
x: fromPos.x + sourceOffset.x,
|
|
1256
|
-
y: fromPos.y + sourceOffset.y
|
|
1257
|
-
},
|
|
1258
|
-
target: {
|
|
1259
|
-
x: toPos.x + targetOffset.x,
|
|
1260
|
-
y: toPos.y + targetOffset.y
|
|
1261
|
-
},
|
|
1262
|
-
vertical
|
|
1263
|
-
});
|
|
1264
|
-
const bbox = Rectangle7.createRectangleWithTwoPoints(
|
|
1265
|
-
points.reduce(
|
|
1266
|
-
(min, p) => ({
|
|
1267
|
-
x: Math.min(min.x, p.x),
|
|
1268
|
-
y: Math.min(min.y, p.y)
|
|
1269
|
-
}),
|
|
1270
|
-
points[0]
|
|
1271
|
-
),
|
|
1272
|
-
points.reduce(
|
|
1273
|
-
(max, p) => ({
|
|
1274
|
-
x: Math.max(max.x, p.x),
|
|
1275
|
-
y: Math.max(max.y, p.y)
|
|
1276
|
-
}),
|
|
1277
|
-
points[0]
|
|
1278
|
-
)
|
|
1279
|
-
);
|
|
1280
|
-
const adjustedPoints = points.map((p) => ({
|
|
1281
|
-
x: p.x - bbox.x + LINE_PADDING,
|
|
1282
|
-
y: p.y - bbox.y + LINE_PADDING
|
|
1283
|
-
}));
|
|
1284
|
-
const path = this.getPathFromPoints(adjustedPoints);
|
|
1285
|
-
this.data = {
|
|
1286
|
-
points,
|
|
1287
|
-
path,
|
|
1288
|
-
bbox
|
|
1289
|
-
};
|
|
1290
|
-
}
|
|
1291
|
-
getManhattanPoints(params) {
|
|
1292
|
-
const { source, target, vertical } = params;
|
|
1293
|
-
const points = [source];
|
|
1294
|
-
if (vertical) {
|
|
1295
|
-
if (source.y !== target.y) {
|
|
1296
|
-
points.push({ x: source.x, y: target.y });
|
|
1297
|
-
}
|
|
1298
|
-
if (source.x !== target.x) {
|
|
1299
|
-
points.push({ x: target.x, y: target.y });
|
|
1300
|
-
}
|
|
1301
|
-
} else {
|
|
1302
|
-
if (source.x !== target.x) {
|
|
1303
|
-
points.push({ x: target.x, y: source.y });
|
|
1304
|
-
}
|
|
1305
|
-
if (source.y !== target.y) {
|
|
1306
|
-
points.push({ x: target.x, y: target.y });
|
|
1307
|
-
}
|
|
1308
|
-
}
|
|
1309
|
-
if (points[points.length - 1] !== target) {
|
|
1310
|
-
points.push(target);
|
|
1311
|
-
}
|
|
1312
|
-
return points;
|
|
1313
|
-
}
|
|
1314
|
-
getPathFromPoints(points) {
|
|
1315
|
-
return points.reduce((path, point, index) => {
|
|
1316
|
-
if (index === 0) {
|
|
1317
|
-
return `M ${point.x} ${point.y}`;
|
|
1318
|
-
}
|
|
1319
|
-
return `${path} L ${point.x} ${point.y}`;
|
|
1320
|
-
}, "");
|
|
1321
1077
|
}
|
|
1322
1078
|
};
|
|
1323
|
-
|
|
1079
|
+
WorkflowStraightLineContribution.type = LineType3.STRAIGHT;
|
|
1324
1080
|
|
|
1325
1081
|
// src/create-free-lines-plugin.ts
|
|
1326
1082
|
var createFreeLinesPlugin = definePluginCreator({
|
|
@@ -1332,7 +1088,7 @@ var createFreeLinesPlugin = definePluginCreator({
|
|
|
1332
1088
|
},
|
|
1333
1089
|
onReady: (ctx, opts) => {
|
|
1334
1090
|
const linesManager = ctx.container.get(WorkflowLinesManager2);
|
|
1335
|
-
linesManager.registerContribution(WorkflowBezierLineContribution).registerContribution(WorkflowFoldLineContribution);
|
|
1091
|
+
linesManager.registerContribution(WorkflowBezierLineContribution).registerContribution(WorkflowFoldLineContribution).registerContribution(WorkflowStraightLineContribution);
|
|
1336
1092
|
if (opts.contributions) {
|
|
1337
1093
|
opts.contributions.forEach((contribution) => {
|
|
1338
1094
|
linesManager.registerContribution(contribution);
|
|
@@ -1344,19 +1100,14 @@ var createFreeLinesPlugin = definePluginCreator({
|
|
|
1344
1100
|
}
|
|
1345
1101
|
});
|
|
1346
1102
|
export {
|
|
1347
|
-
BezierControlType,
|
|
1348
1103
|
LINE_OFFSET,
|
|
1349
1104
|
LINE_PADDING,
|
|
1350
1105
|
WorkflowLinesLayer as LinesLayer,
|
|
1351
|
-
WorkflowArkLineContribution,
|
|
1352
1106
|
WorkflowBezierLineContribution,
|
|
1353
1107
|
WorkflowFoldLineContribution,
|
|
1354
1108
|
WorkflowLinesLayer,
|
|
1355
|
-
WorkflowManhattanLineContribution,
|
|
1356
1109
|
WorkflowPortRender,
|
|
1357
1110
|
WorkflowStraightLineContribution,
|
|
1358
|
-
createFreeLinesPlugin
|
|
1359
|
-
getBezierHorizontalControlPoints,
|
|
1360
|
-
getBezierVerticalControlPoints
|
|
1111
|
+
createFreeLinesPlugin
|
|
1361
1112
|
};
|
|
1362
1113
|
//# sourceMappingURL=index.js.map
|