@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/index.js
CHANGED
|
@@ -38,20 +38,15 @@ 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,
|
|
45
|
-
WorkflowArkLineContribution: () => WorkflowArkLineContribution,
|
|
46
44
|
WorkflowBezierLineContribution: () => WorkflowBezierLineContribution,
|
|
47
45
|
WorkflowFoldLineContribution: () => WorkflowFoldLineContribution,
|
|
48
46
|
WorkflowLinesLayer: () => WorkflowLinesLayer,
|
|
49
|
-
WorkflowManhattanLineContribution: () => WorkflowManhattanLineContribution,
|
|
50
47
|
WorkflowPortRender: () => WorkflowPortRender,
|
|
51
48
|
WorkflowStraightLineContribution: () => WorkflowStraightLineContribution,
|
|
52
|
-
createFreeLinesPlugin: () => createFreeLinesPlugin
|
|
53
|
-
getBezierHorizontalControlPoints: () => getBezierHorizontalControlPoints,
|
|
54
|
-
getBezierVerticalControlPoints: () => getBezierVerticalControlPoints
|
|
49
|
+
createFreeLinesPlugin: () => createFreeLinesPlugin
|
|
55
50
|
});
|
|
56
51
|
module.exports = __toCommonJS(src_exports);
|
|
57
52
|
|
|
@@ -304,7 +299,7 @@ var LINE_OFFSET = 6;
|
|
|
304
299
|
var LINE_PADDING = 12;
|
|
305
300
|
|
|
306
301
|
// src/create-free-lines-plugin.ts
|
|
307
|
-
var
|
|
302
|
+
var import_free_layout_core8 = require("@flowgram.ai/free-layout-core");
|
|
308
303
|
var import_core3 = require("@flowgram.ai/core");
|
|
309
304
|
|
|
310
305
|
// src/layer/workflow-lines-layer.tsx
|
|
@@ -328,9 +323,7 @@ var import_free_layout_core3 = require("@flowgram.ai/free-layout-core");
|
|
|
328
323
|
|
|
329
324
|
// src/components/workflow-line-render/index.style.ts
|
|
330
325
|
var import_styled_components2 = __toESM(require("styled-components"));
|
|
331
|
-
var LineStyle = import_styled_components2.default.div
|
|
332
|
-
className: "gedit-flow-activity-edge"
|
|
333
|
-
})`
|
|
326
|
+
var LineStyle = import_styled_components2.default.div`
|
|
334
327
|
position: absolute;
|
|
335
328
|
|
|
336
329
|
@keyframes flowingDash {
|
|
@@ -378,18 +371,18 @@ function ArrowRenderer({
|
|
|
378
371
|
var PADDING = 12;
|
|
379
372
|
var LineSVG = (props) => {
|
|
380
373
|
const { line, color, selected, children, strokePrefix, rendererRegistry } = props;
|
|
381
|
-
const { position, reverse,
|
|
374
|
+
const { position, reverse, hideArrow, vertical } = line;
|
|
382
375
|
const renderData = line.getData(import_free_layout_core3.WorkflowLineRenderData);
|
|
383
376
|
const { bounds, path: bezierPath } = renderData;
|
|
384
|
-
const
|
|
377
|
+
const toRelative2 = (p) => ({
|
|
385
378
|
x: p.x - bounds.x + PADDING,
|
|
386
379
|
y: p.y - bounds.y + PADDING
|
|
387
380
|
});
|
|
388
|
-
const fromPos =
|
|
389
|
-
const toPos =
|
|
390
|
-
const arrowToPos =
|
|
391
|
-
const arrowFromPos =
|
|
392
|
-
const strokeWidth = selected ? STROKE_WIDTH_SLECTED : STROKE_WIDTH;
|
|
381
|
+
const fromPos = toRelative2(position.from);
|
|
382
|
+
const toPos = toRelative2(position.to);
|
|
383
|
+
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 };
|
|
384
|
+
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 };
|
|
385
|
+
const strokeWidth = selected ? line.uiState.strokeWidthSelected ?? STROKE_WIDTH_SLECTED : line.uiState.strokeWidth ?? STROKE_WIDTH;
|
|
393
386
|
const strokeID = strokePrefix ? `${strokePrefix}-${line.id}` : line.id;
|
|
394
387
|
const CustomArrowRenderer = rendererRegistry?.tryToGetRendererComponent("arrow-renderer")?.renderer;
|
|
395
388
|
const ArrowComponent = CustomArrowRenderer || ArrowRenderer;
|
|
@@ -400,17 +393,15 @@ var LineSVG = (props) => {
|
|
|
400
393
|
fill: "none",
|
|
401
394
|
stroke: `url(#${strokeID})`,
|
|
402
395
|
strokeWidth,
|
|
403
|
-
className:
|
|
404
|
-
line.className,
|
|
405
|
-
// 显示流动线条的条件:没有自定义线条class,并且线条处于流动或处理中
|
|
406
|
-
!line.className && (line.processing || line.flowing ? "dashed-line flowing-line" : "")
|
|
407
|
-
)
|
|
396
|
+
className: line.processing || line.flowing ? "dashed-line flowing-line" : ""
|
|
408
397
|
}
|
|
409
398
|
);
|
|
410
399
|
return /* @__PURE__ */ import_react4.default.createElement(
|
|
411
400
|
LineStyle,
|
|
412
401
|
{
|
|
402
|
+
className: (0, import_clsx2.default)("gedit-flow-activity-edge", line.className),
|
|
413
403
|
style: {
|
|
404
|
+
...line.uiState.style,
|
|
414
405
|
left: bounds.x - PADDING,
|
|
415
406
|
top: bounds.y - PADDING,
|
|
416
407
|
position: "absolute"
|
|
@@ -592,143 +583,90 @@ WorkflowLinesLayer = __decorateClass([
|
|
|
592
583
|
(0, import_inversify.injectable)()
|
|
593
584
|
], WorkflowLinesLayer);
|
|
594
585
|
|
|
595
|
-
// src/contributions/bezier/
|
|
586
|
+
// src/contributions/bezier/index.ts
|
|
587
|
+
var import_bezier_js = require("bezier-js");
|
|
596
588
|
var import_utils2 = require("@flowgram.ai/utils");
|
|
597
|
-
var
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
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
|
-
];
|
|
662
|
-
}
|
|
663
|
-
return controls;
|
|
589
|
+
var import_free_layout_core5 = require("@flowgram.ai/free-layout-core");
|
|
590
|
+
|
|
591
|
+
// src/contributions/utils.ts
|
|
592
|
+
function toRelative(p, bbox) {
|
|
593
|
+
return {
|
|
594
|
+
x: p.x - bbox.x + LINE_PADDING,
|
|
595
|
+
y: p.y - bbox.y + LINE_PADDING
|
|
596
|
+
};
|
|
664
597
|
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
598
|
+
|
|
599
|
+
// src/contributions/bezier/bezier-controls.ts
|
|
600
|
+
function getBezierEdgeCenter(fromPos, toPos, fromControl, toControl) {
|
|
601
|
+
const x = fromPos.x * 0.125 + fromControl.x * 0.375 + toControl.x * 0.375 + toPos.x * 0.125;
|
|
602
|
+
const y = fromPos.y * 0.125 + fromControl.y * 0.375 + toControl.y * 0.375 + toPos.y * 0.125;
|
|
603
|
+
return {
|
|
604
|
+
x,
|
|
605
|
+
y
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
function getControlOffset(distance, curvature) {
|
|
609
|
+
if (distance >= 0) {
|
|
610
|
+
return 0.5 * distance;
|
|
672
611
|
}
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
case
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
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;
|
|
612
|
+
return curvature * 25 * Math.sqrt(-distance);
|
|
613
|
+
}
|
|
614
|
+
function getControlWithCurvature({
|
|
615
|
+
location,
|
|
616
|
+
x1,
|
|
617
|
+
y1,
|
|
618
|
+
x2,
|
|
619
|
+
y2,
|
|
620
|
+
curvature
|
|
621
|
+
}) {
|
|
622
|
+
switch (location) {
|
|
623
|
+
case "left":
|
|
624
|
+
return {
|
|
625
|
+
x: x1 - getControlOffset(x1 - x2, curvature),
|
|
626
|
+
y: y1
|
|
627
|
+
};
|
|
628
|
+
case "right":
|
|
629
|
+
return {
|
|
630
|
+
x: x1 + getControlOffset(x2 - x1, curvature),
|
|
631
|
+
y: y1
|
|
632
|
+
};
|
|
633
|
+
case "top":
|
|
634
|
+
return {
|
|
635
|
+
x: x1,
|
|
636
|
+
y: y1 - getControlOffset(y1 - y2, curvature)
|
|
637
|
+
};
|
|
638
|
+
case "bottom":
|
|
639
|
+
return {
|
|
640
|
+
x: x1,
|
|
641
|
+
y: y1 + getControlOffset(y2 - y1, curvature)
|
|
642
|
+
};
|
|
723
643
|
}
|
|
724
|
-
|
|
644
|
+
}
|
|
645
|
+
function getBezierControlPoints(fromPos, toPos, curvature = 0.25) {
|
|
646
|
+
const fromControl = getControlWithCurvature({
|
|
647
|
+
location: fromPos.location,
|
|
648
|
+
x1: fromPos.x,
|
|
649
|
+
y1: fromPos.y,
|
|
650
|
+
x2: toPos.x,
|
|
651
|
+
y2: toPos.y,
|
|
652
|
+
curvature
|
|
653
|
+
});
|
|
654
|
+
const toControl = getControlWithCurvature({
|
|
655
|
+
location: toPos.location,
|
|
656
|
+
x1: toPos.x,
|
|
657
|
+
y1: toPos.y,
|
|
658
|
+
x2: fromPos.x,
|
|
659
|
+
y2: fromPos.y,
|
|
660
|
+
curvature
|
|
661
|
+
});
|
|
662
|
+
const center = getBezierEdgeCenter(fromPos, toPos, fromControl, toControl);
|
|
663
|
+
return {
|
|
664
|
+
controls: [fromControl, toControl],
|
|
665
|
+
center
|
|
666
|
+
};
|
|
725
667
|
}
|
|
726
668
|
|
|
727
669
|
// 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
670
|
var WorkflowBezierLineContribution = class {
|
|
733
671
|
constructor(entity) {
|
|
734
672
|
this.entity = entity;
|
|
@@ -740,27 +678,35 @@ var WorkflowBezierLineContribution = class {
|
|
|
740
678
|
if (!this.data) {
|
|
741
679
|
return Number.MAX_SAFE_INTEGER;
|
|
742
680
|
}
|
|
743
|
-
return
|
|
681
|
+
return import_utils2.Point.getDistance(pos, this.data.bezier.project(pos));
|
|
744
682
|
}
|
|
745
683
|
get bounds() {
|
|
746
684
|
if (!this.data) {
|
|
747
|
-
return
|
|
685
|
+
return import_utils2.Rectangle.EMPTY;
|
|
748
686
|
}
|
|
749
687
|
return this.data.bbox;
|
|
750
688
|
}
|
|
689
|
+
get center() {
|
|
690
|
+
return this.data?.center;
|
|
691
|
+
}
|
|
751
692
|
update(params) {
|
|
752
693
|
this.data = this.calcBezier(params.fromPos, params.toPos);
|
|
753
694
|
}
|
|
754
695
|
calcBezier(fromPos, toPos) {
|
|
755
|
-
const controls
|
|
696
|
+
const { controls, center } = getBezierControlPoints(
|
|
697
|
+
fromPos,
|
|
698
|
+
toPos,
|
|
699
|
+
this.entity.uiState.curvature
|
|
700
|
+
);
|
|
756
701
|
const bezier = new import_bezier_js.Bezier([fromPos, ...controls, toPos]);
|
|
757
702
|
const bbox = bezier.bbox();
|
|
758
|
-
const bboxBounds = new
|
|
703
|
+
const bboxBounds = new import_utils2.Rectangle(
|
|
759
704
|
bbox.x.min,
|
|
760
705
|
bbox.y.min,
|
|
761
706
|
bbox.x.max - bbox.x.min,
|
|
762
707
|
bbox.y.max - bbox.y.min
|
|
763
708
|
);
|
|
709
|
+
const centerPoint = toRelative(center, bboxBounds);
|
|
764
710
|
const path = this.getPath({ bbox: bboxBounds, fromPos, toPos, controls });
|
|
765
711
|
this.data = {
|
|
766
712
|
fromPos,
|
|
@@ -768,38 +714,32 @@ var WorkflowBezierLineContribution = class {
|
|
|
768
714
|
bezier,
|
|
769
715
|
bbox: bboxBounds,
|
|
770
716
|
controls,
|
|
771
|
-
path
|
|
717
|
+
path,
|
|
718
|
+
center: {
|
|
719
|
+
...center,
|
|
720
|
+
labelX: centerPoint.x,
|
|
721
|
+
labelY: centerPoint.y
|
|
722
|
+
}
|
|
772
723
|
};
|
|
773
724
|
return this.data;
|
|
774
725
|
}
|
|
775
726
|
getPath(params) {
|
|
776
727
|
const { bbox } = params;
|
|
777
|
-
const
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
const
|
|
782
|
-
const
|
|
783
|
-
const
|
|
784
|
-
|
|
785
|
-
const getPathData = () => {
|
|
786
|
-
const controlPoints = controls.map((s) => `${s.x} ${s.y}`).join(",");
|
|
787
|
-
const curveType = controls.length === 1 ? "S" : "C";
|
|
788
|
-
if (this.entity.vertical) {
|
|
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;
|
|
728
|
+
const fromPos = toRelative(params.fromPos, bbox);
|
|
729
|
+
const toPos = toRelative(params.toPos, bbox);
|
|
730
|
+
const controls = params.controls.map((c) => toRelative(c, bbox));
|
|
731
|
+
const shrink = this.entity.uiState.shrink;
|
|
732
|
+
const renderFromPos = params.fromPos.location === "bottom" ? { x: fromPos.x, y: fromPos.y + shrink } : { x: fromPos.x + shrink, y: fromPos.y };
|
|
733
|
+
const renderToPos = params.toPos.location === "top" ? { x: toPos.x, y: toPos.y - shrink } : { x: toPos.x - shrink, y: toPos.y };
|
|
734
|
+
const controlPoints = controls.map((s) => `${s.x} ${s.y}`).join(",");
|
|
735
|
+
return `M${renderFromPos.x} ${renderFromPos.y} C ${controlPoints}, ${renderToPos.x} ${renderToPos.y}`;
|
|
795
736
|
}
|
|
796
737
|
};
|
|
797
|
-
WorkflowBezierLineContribution.type =
|
|
738
|
+
WorkflowBezierLineContribution.type = import_free_layout_core5.LineType.BEZIER;
|
|
798
739
|
|
|
799
740
|
// src/contributions/fold/index.ts
|
|
800
741
|
var import_utils5 = require("@flowgram.ai/utils");
|
|
801
|
-
var
|
|
802
|
-
var import_free_layout_core8 = require("@flowgram.ai/free-layout-core");
|
|
742
|
+
var import_free_layout_core6 = require("@flowgram.ai/free-layout-core");
|
|
803
743
|
|
|
804
744
|
// src/contributions/fold/fold-line.ts
|
|
805
745
|
var import_utils4 = require("@flowgram.ai/utils");
|
|
@@ -841,23 +781,35 @@ var FoldLine;
|
|
|
841
781
|
const centerY = target.y < source.y ? target.y + yOffset : target.y - yOffset;
|
|
842
782
|
return [centerX, centerY];
|
|
843
783
|
}
|
|
844
|
-
const getDirection = ({ source, target }) =>
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
|
|
784
|
+
const getDirection = ({ source, target }) => {
|
|
785
|
+
if (source.location === "left" || source.location === "right") {
|
|
786
|
+
return source.x < target.x ? { x: 1, y: 0 } : { x: -1, y: 0 };
|
|
787
|
+
}
|
|
788
|
+
return source.y < target.y ? { x: 0, y: 1 } : { x: 0, y: -1 };
|
|
789
|
+
};
|
|
790
|
+
const handleDirections = {
|
|
791
|
+
left: { x: -1, y: 0 },
|
|
792
|
+
right: { x: 1, y: 0 },
|
|
793
|
+
top: { x: 0, y: -1 },
|
|
794
|
+
bottom: { x: 0, y: 1 }
|
|
795
|
+
};
|
|
796
|
+
function getPoints({ source, target }) {
|
|
797
|
+
const sourceDir = handleDirections[source.location];
|
|
798
|
+
const targetDir = handleDirections[target.location];
|
|
852
799
|
const sourceGapped = {
|
|
853
800
|
x: source.x + sourceDir.x * OFFSET,
|
|
854
|
-
y: source.y + sourceDir.y * OFFSET
|
|
801
|
+
y: source.y + sourceDir.y * OFFSET,
|
|
802
|
+
location: source.location
|
|
855
803
|
};
|
|
856
804
|
const targetGapped = {
|
|
857
805
|
x: target.x + targetDir.x * OFFSET,
|
|
858
|
-
y: target.y + targetDir.y * OFFSET
|
|
806
|
+
y: target.y + targetDir.y * OFFSET,
|
|
807
|
+
location: target.location
|
|
859
808
|
};
|
|
860
|
-
const dir =
|
|
809
|
+
const dir = getDirection({
|
|
810
|
+
source: sourceGapped,
|
|
811
|
+
target: targetGapped
|
|
812
|
+
});
|
|
861
813
|
const dirAccessor = dir.x !== 0 ? "x" : "y";
|
|
862
814
|
const currDir = dir[dirAccessor];
|
|
863
815
|
let points = [];
|
|
@@ -923,7 +875,13 @@ var FoldLine;
|
|
|
923
875
|
{ x: targetGapped.x, y: targetGapped.y },
|
|
924
876
|
target
|
|
925
877
|
];
|
|
926
|
-
return
|
|
878
|
+
return {
|
|
879
|
+
points: pathPoints,
|
|
880
|
+
center: {
|
|
881
|
+
x: centerX,
|
|
882
|
+
y: centerY
|
|
883
|
+
}
|
|
884
|
+
};
|
|
927
885
|
}
|
|
928
886
|
FoldLine2.getPoints = getPoints;
|
|
929
887
|
function getBend(a, b, c) {
|
|
@@ -1017,46 +975,54 @@ var WorkflowFoldLineContribution = class {
|
|
|
1017
975
|
}
|
|
1018
976
|
return this.data.bbox;
|
|
1019
977
|
}
|
|
978
|
+
get center() {
|
|
979
|
+
return this.data?.center;
|
|
980
|
+
}
|
|
1020
981
|
update(params) {
|
|
1021
982
|
const { fromPos, toPos } = params;
|
|
1022
|
-
const
|
|
983
|
+
const shrink = this.entity.uiState.shrink;
|
|
1023
984
|
const sourceOffset = {
|
|
1024
|
-
x:
|
|
1025
|
-
y:
|
|
985
|
+
x: fromPos.location === "bottom" ? 0 : shrink,
|
|
986
|
+
y: fromPos.location === "bottom" ? shrink : 0
|
|
1026
987
|
};
|
|
1027
988
|
const targetOffset = {
|
|
1028
|
-
x:
|
|
1029
|
-
y:
|
|
989
|
+
x: toPos.location === "top" ? 0 : -shrink,
|
|
990
|
+
y: toPos.location === "top" ? -shrink : 0
|
|
1030
991
|
};
|
|
1031
|
-
const points = FoldLine.getPoints({
|
|
992
|
+
const { points, center } = FoldLine.getPoints({
|
|
1032
993
|
source: {
|
|
1033
994
|
x: fromPos.x + sourceOffset.x,
|
|
1034
|
-
y: fromPos.y + sourceOffset.y
|
|
995
|
+
y: fromPos.y + sourceOffset.y,
|
|
996
|
+
location: fromPos.location
|
|
1035
997
|
},
|
|
1036
998
|
target: {
|
|
1037
999
|
x: toPos.x + targetOffset.x,
|
|
1038
|
-
y: toPos.y + targetOffset.y
|
|
1039
|
-
|
|
1040
|
-
|
|
1000
|
+
y: toPos.y + targetOffset.y,
|
|
1001
|
+
location: toPos.location
|
|
1002
|
+
}
|
|
1041
1003
|
});
|
|
1042
1004
|
const bbox = FoldLine.getBounds(points);
|
|
1043
|
-
const adjustedPoints = points.map((p) => (
|
|
1044
|
-
x: p.x - bbox.x + LINE_PADDING,
|
|
1045
|
-
y: p.y - bbox.y + LINE_PADDING
|
|
1046
|
-
}));
|
|
1005
|
+
const adjustedPoints = points.map((p) => toRelative(p, bbox));
|
|
1047
1006
|
const path = FoldLine.getSmoothStepPath(adjustedPoints);
|
|
1007
|
+
const relativeCenter = toRelative(center, bbox);
|
|
1048
1008
|
this.data = {
|
|
1049
1009
|
points,
|
|
1050
1010
|
path,
|
|
1051
|
-
bbox
|
|
1011
|
+
bbox,
|
|
1012
|
+
center: {
|
|
1013
|
+
x: center.x,
|
|
1014
|
+
y: center.y,
|
|
1015
|
+
labelX: relativeCenter.x,
|
|
1016
|
+
labelY: relativeCenter.y
|
|
1017
|
+
}
|
|
1052
1018
|
};
|
|
1053
1019
|
}
|
|
1054
1020
|
};
|
|
1055
|
-
WorkflowFoldLineContribution.type =
|
|
1021
|
+
WorkflowFoldLineContribution.type = import_free_layout_core6.LineType.LINE_CHART;
|
|
1056
1022
|
|
|
1057
1023
|
// src/contributions/straight/index.ts
|
|
1058
|
-
var
|
|
1059
|
-
var
|
|
1024
|
+
var import_utils7 = require("@flowgram.ai/utils");
|
|
1025
|
+
var import_free_layout_core7 = require("@flowgram.ai/free-layout-core");
|
|
1060
1026
|
|
|
1061
1027
|
// src/contributions/straight/point-on-line.ts
|
|
1062
1028
|
function projectPointOnLine(point, lineStart, lineEnd) {
|
|
@@ -1089,24 +1055,27 @@ var WorkflowStraightLineContribution = class {
|
|
|
1089
1055
|
return Number.MAX_SAFE_INTEGER;
|
|
1090
1056
|
}
|
|
1091
1057
|
const [start, end] = this.data.points;
|
|
1092
|
-
return
|
|
1058
|
+
return import_utils7.Point.getDistance(pos, projectPointOnLine(pos, start, end));
|
|
1093
1059
|
}
|
|
1094
1060
|
get bounds() {
|
|
1095
1061
|
if (!this.data) {
|
|
1096
|
-
return new
|
|
1062
|
+
return new import_utils7.Rectangle();
|
|
1097
1063
|
}
|
|
1098
1064
|
return this.data.bbox;
|
|
1099
1065
|
}
|
|
1066
|
+
get center() {
|
|
1067
|
+
return this.data?.center;
|
|
1068
|
+
}
|
|
1100
1069
|
update(params) {
|
|
1101
1070
|
const { fromPos, toPos } = params;
|
|
1102
|
-
const
|
|
1071
|
+
const shrink = this.entity.uiState.shrink;
|
|
1103
1072
|
const sourceOffset = {
|
|
1104
|
-
x:
|
|
1105
|
-
y:
|
|
1073
|
+
x: fromPos.location === "bottom" ? 0 : shrink,
|
|
1074
|
+
y: fromPos.location === "bottom" ? shrink : 0
|
|
1106
1075
|
};
|
|
1107
1076
|
const targetOffset = {
|
|
1108
|
-
x:
|
|
1109
|
-
y:
|
|
1077
|
+
x: toPos.location === "top" ? 0 : -shrink,
|
|
1078
|
+
y: toPos.location === "top" ? -shrink : 0
|
|
1110
1079
|
};
|
|
1111
1080
|
const points = [
|
|
1112
1081
|
{
|
|
@@ -1118,7 +1087,7 @@ var WorkflowStraightLineContribution = class {
|
|
|
1118
1087
|
y: toPos.y + targetOffset.y
|
|
1119
1088
|
}
|
|
1120
1089
|
];
|
|
1121
|
-
const bbox =
|
|
1090
|
+
const bbox = import_utils7.Rectangle.createRectangleWithTwoPoints(points[0], points[1]);
|
|
1122
1091
|
const adjustedPoints = points.map((p) => ({
|
|
1123
1092
|
x: p.x - bbox.x + LINE_PADDING,
|
|
1124
1093
|
y: p.y - bbox.y + LINE_PADDING
|
|
@@ -1127,223 +1096,12 @@ var WorkflowStraightLineContribution = class {
|
|
|
1127
1096
|
this.data = {
|
|
1128
1097
|
points,
|
|
1129
1098
|
path,
|
|
1130
|
-
bbox
|
|
1131
|
-
|
|
1132
|
-
}
|
|
1133
|
-
};
|
|
1134
|
-
WorkflowStraightLineContribution.type = "WorkflowStraightLineContribution";
|
|
1135
|
-
|
|
1136
|
-
// src/contributions/arc/index.ts
|
|
1137
|
-
var import_utils7 = require("@flowgram.ai/utils");
|
|
1138
|
-
var import_free_layout_core10 = require("@flowgram.ai/free-layout-core");
|
|
1139
|
-
var WorkflowArkLineContribution = class {
|
|
1140
|
-
constructor(entity) {
|
|
1141
|
-
this.entity = entity;
|
|
1142
|
-
}
|
|
1143
|
-
get path() {
|
|
1144
|
-
return this.data?.path ?? "";
|
|
1145
|
-
}
|
|
1146
|
-
calcDistance(pos) {
|
|
1147
|
-
if (!this.data) {
|
|
1148
|
-
return Number.MAX_SAFE_INTEGER;
|
|
1149
|
-
}
|
|
1150
|
-
const { fromPos, toPos, bbox } = this.data;
|
|
1151
|
-
if (!bbox.contains(pos.x, pos.y)) {
|
|
1152
|
-
const dx = Math.max(bbox.x - pos.x, 0, pos.x - (bbox.x + bbox.width));
|
|
1153
|
-
const dy = Math.max(bbox.y - pos.y, 0, pos.y - (bbox.y + bbox.height));
|
|
1154
|
-
return Math.sqrt(dx * dx + dy * dy);
|
|
1155
|
-
}
|
|
1156
|
-
const center = {
|
|
1157
|
-
x: (fromPos.x + toPos.x) / 2,
|
|
1158
|
-
y: (fromPos.y + toPos.y) / 2
|
|
1159
|
-
};
|
|
1160
|
-
const radius = import_utils7.Point.getDistance(fromPos, center);
|
|
1161
|
-
const distanceToCenter = import_utils7.Point.getDistance(pos, center);
|
|
1162
|
-
return Math.abs(distanceToCenter - radius);
|
|
1163
|
-
}
|
|
1164
|
-
get bounds() {
|
|
1165
|
-
if (!this.data) {
|
|
1166
|
-
return new import_utils7.Rectangle();
|
|
1167
|
-
}
|
|
1168
|
-
return this.data.bbox;
|
|
1169
|
-
}
|
|
1170
|
-
update(params) {
|
|
1171
|
-
const { fromPos, toPos } = params;
|
|
1172
|
-
const { vertical } = this.entity;
|
|
1173
|
-
const sourceOffset = {
|
|
1174
|
-
x: vertical ? 0 : import_free_layout_core10.POINT_RADIUS,
|
|
1175
|
-
y: vertical ? import_free_layout_core10.POINT_RADIUS : 0
|
|
1176
|
-
};
|
|
1177
|
-
const targetOffset = {
|
|
1178
|
-
x: vertical ? 0 : -import_free_layout_core10.POINT_RADIUS,
|
|
1179
|
-
y: vertical ? -import_free_layout_core10.POINT_RADIUS : 0
|
|
1180
|
-
};
|
|
1181
|
-
const start = {
|
|
1182
|
-
x: fromPos.x + sourceOffset.x,
|
|
1183
|
-
y: fromPos.y + sourceOffset.y
|
|
1184
|
-
};
|
|
1185
|
-
const end = {
|
|
1186
|
-
x: toPos.x + targetOffset.x,
|
|
1187
|
-
y: toPos.y + targetOffset.y
|
|
1188
|
-
};
|
|
1189
|
-
const bbox = this.calculateArcBBox(start, end);
|
|
1190
|
-
const path = this.getArcPath(start, end, bbox);
|
|
1191
|
-
this.data = {
|
|
1192
|
-
fromPos: start,
|
|
1193
|
-
toPos: end,
|
|
1194
|
-
path,
|
|
1195
|
-
bbox
|
|
1196
|
-
};
|
|
1197
|
-
}
|
|
1198
|
-
calculateArcBBox(start, end) {
|
|
1199
|
-
const dx = end.x - start.x;
|
|
1200
|
-
const dy = end.y - start.y;
|
|
1201
|
-
const radius = Math.sqrt(dx * dx + dy * dy) / 2;
|
|
1202
|
-
const centerX = (start.x + end.x) / 2;
|
|
1203
|
-
const centerY = (start.y + end.y) / 2;
|
|
1204
|
-
return new import_utils7.Rectangle(centerX - radius, centerY - radius, radius * 2, radius * 2);
|
|
1205
|
-
}
|
|
1206
|
-
getArcPath(start, end, bbox) {
|
|
1207
|
-
const dx = end.x - start.x;
|
|
1208
|
-
const dy = end.y - start.y;
|
|
1209
|
-
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
1210
|
-
const startRel = {
|
|
1211
|
-
x: start.x - bbox.x + LINE_PADDING,
|
|
1212
|
-
y: start.y - bbox.y + LINE_PADDING
|
|
1213
|
-
};
|
|
1214
|
-
const endRel = {
|
|
1215
|
-
x: end.x - bbox.x + LINE_PADDING,
|
|
1216
|
-
y: end.y - bbox.y + LINE_PADDING
|
|
1217
|
-
};
|
|
1218
|
-
return `M ${startRel.x} ${startRel.y} A ${distance / 2} ${distance / 2} 0 0 1 ${endRel.x} ${endRel.y}`;
|
|
1219
|
-
}
|
|
1220
|
-
};
|
|
1221
|
-
WorkflowArkLineContribution.type = "WorkflowArkLineContribution";
|
|
1222
|
-
|
|
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
|
|
1099
|
+
bbox,
|
|
1100
|
+
center: (0, import_free_layout_core7.getLineCenter)(fromPos, toPos, bbox, LINE_PADDING)
|
|
1312
1101
|
};
|
|
1313
1102
|
}
|
|
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
1103
|
};
|
|
1346
|
-
|
|
1104
|
+
WorkflowStraightLineContribution.type = import_free_layout_core7.LineType.STRAIGHT;
|
|
1347
1105
|
|
|
1348
1106
|
// src/create-free-lines-plugin.ts
|
|
1349
1107
|
var createFreeLinesPlugin = (0, import_core3.definePluginCreator)({
|
|
@@ -1354,8 +1112,8 @@ var createFreeLinesPlugin = (0, import_core3.definePluginCreator)({
|
|
|
1354
1112
|
});
|
|
1355
1113
|
},
|
|
1356
1114
|
onReady: (ctx, opts) => {
|
|
1357
|
-
const linesManager = ctx.container.get(
|
|
1358
|
-
linesManager.registerContribution(WorkflowBezierLineContribution).registerContribution(WorkflowFoldLineContribution);
|
|
1115
|
+
const linesManager = ctx.container.get(import_free_layout_core8.WorkflowLinesManager);
|
|
1116
|
+
linesManager.registerContribution(WorkflowBezierLineContribution).registerContribution(WorkflowFoldLineContribution).registerContribution(WorkflowStraightLineContribution);
|
|
1359
1117
|
if (opts.contributions) {
|
|
1360
1118
|
opts.contributions.forEach((contribution) => {
|
|
1361
1119
|
linesManager.registerContribution(contribution);
|
|
@@ -1368,19 +1126,14 @@ var createFreeLinesPlugin = (0, import_core3.definePluginCreator)({
|
|
|
1368
1126
|
});
|
|
1369
1127
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1370
1128
|
0 && (module.exports = {
|
|
1371
|
-
BezierControlType,
|
|
1372
1129
|
LINE_OFFSET,
|
|
1373
1130
|
LINE_PADDING,
|
|
1374
1131
|
LinesLayer,
|
|
1375
|
-
WorkflowArkLineContribution,
|
|
1376
1132
|
WorkflowBezierLineContribution,
|
|
1377
1133
|
WorkflowFoldLineContribution,
|
|
1378
1134
|
WorkflowLinesLayer,
|
|
1379
|
-
WorkflowManhattanLineContribution,
|
|
1380
1135
|
WorkflowPortRender,
|
|
1381
1136
|
WorkflowStraightLineContribution,
|
|
1382
|
-
createFreeLinesPlugin
|
|
1383
|
-
getBezierHorizontalControlPoints,
|
|
1384
|
-
getBezierVerticalControlPoints
|
|
1137
|
+
createFreeLinesPlugin
|
|
1385
1138
|
});
|
|
1386
1139
|
//# sourceMappingURL=index.js.map
|