@flowgram.ai/free-layout-core 0.4.3 → 0.4.5

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.
@@ -2,6 +2,7 @@
2
2
  var LineType = /* @__PURE__ */ ((LineType2) => {
3
3
  LineType2[LineType2["BEZIER"] = 0] = "BEZIER";
4
4
  LineType2[LineType2["LINE_CHART"] = 1] = "LINE_CHART";
5
+ LineType2[LineType2["STRAIGHT"] = 2] = "STRAIGHT";
5
6
  return LineType2;
6
7
  })(LineType || {});
7
8
  var LineColors = /* @__PURE__ */ ((LineColors2) => {
@@ -19,4 +20,4 @@ export {
19
20
  LineType,
20
21
  LineColors
21
22
  };
22
- //# sourceMappingURL=chunk-E7ZUQ7LV.js.map
23
+ //# sourceMappingURL=chunk-5BT3ZR4D.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/typings/workflow-line.ts"],"sourcesContent":["/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport type { Rectangle, IPoint } from '@flowgram.ai/utils';\n\nimport { type WorkflowLineEntity } from '../entities';\n\nexport enum LineType {\n BEZIER, // 贝塞尔曲线\n LINE_CHART, // 折叠线\n STRAIGHT, // 直线\n}\n\nexport type LineRenderType = LineType | string;\n\nexport type LinePointLocation = 'left' | 'top' | 'right' | 'bottom';\n\nexport interface LinePoint {\n x: number;\n y: number;\n location: LinePointLocation;\n}\n\nexport interface LinePosition {\n from: LinePoint;\n to: LinePoint;\n}\n\nexport interface LineColor {\n hidden: string;\n default: string;\n drawing: string;\n hovered: string;\n selected: string;\n error: string;\n flowing: string;\n}\n\nexport enum LineColors {\n HIDDEN = 'var(--g-workflow-line-color-hidden,transparent)', // 隐藏线条\n DEFUALT = 'var(--g-workflow-line-color-default,#4d53e8)',\n DRAWING = 'var(--g-workflow-line-color-drawing, #5DD6E3)', // '#b5bbf8', // '#9197F1',\n HOVER = 'var(--g-workflow-line-color-hover,#37d0ff)',\n SELECTED = 'var(--g-workflow-line-color-selected,#37d0ff)',\n ERROR = 'var(--g-workflow-line-color-error,red)',\n FLOWING = 'var(--g-workflow-line-color-flowing,#4d53e8)', // 流动线条,默认使用主题色\n}\n\nexport interface LineCenterPoint {\n x: number;\n y: number;\n labelX: number; // Relative to where the line begins\n labelY: number; // Relative to where the line begins\n}\n\nexport interface WorkflowLineRenderContribution {\n entity: WorkflowLineEntity;\n path: string;\n center?: LineCenterPoint;\n bounds: Rectangle;\n update: (params: { fromPos: LinePoint; toPos: LinePoint }) => void;\n calcDistance: (pos: IPoint) => number;\n}\n\nexport type WorkflowLineRenderContributionFactory = (new (\n entity: WorkflowLineEntity\n) => WorkflowLineRenderContribution) & {\n type: LineRenderType;\n};\n"],"mappings":";AASO,IAAK,WAAL,kBAAKA,cAAL;AACL,EAAAA,oBAAA;AACA,EAAAA,oBAAA;AACA,EAAAA,oBAAA;AAHU,SAAAA;AAAA,GAAA;AA+BL,IAAK,aAAL,kBAAKC,gBAAL;AACL,EAAAA,YAAA,YAAS;AACT,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,WAAQ;AACR,EAAAA,YAAA,cAAW;AACX,EAAAA,YAAA,WAAQ;AACR,EAAAA,YAAA,aAAU;AAPA,SAAAA;AAAA,GAAA;","names":["LineType","LineColors"]}
package/dist/esm/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  import {
12
12
  LineColors,
13
13
  LineType
14
- } from "./chunk-E7ZUQ7LV.js";
14
+ } from "./chunk-5BT3ZR4D.js";
15
15
  import "./chunk-DDJTYHXN.js";
16
16
  import {
17
17
  WorkflowOperationBaseService
@@ -100,6 +100,16 @@ var buildGroupJSON = (json) => {
100
100
  };
101
101
  };
102
102
 
103
+ // src/utils/get-line-center.ts
104
+ function getLineCenter(from, to, bbox, linePadding) {
105
+ return {
106
+ x: bbox.center.x,
107
+ y: bbox.center.y,
108
+ labelX: bbox.center.x - bbox.x + linePadding,
109
+ labelY: bbox.center.y - bbox.y + linePadding
110
+ };
111
+ }
112
+
103
113
  // src/utils/nanoid.ts
104
114
  import { nanoid as nanoidOrigin } from "nanoid";
105
115
  function nanoid(n) {
@@ -611,6 +621,9 @@ var _WorkflowNodeLinesData = class _WorkflowNodeLinesData extends EntityData2 {
611
621
  get allLines() {
612
622
  return this.data.inputLines.concat(this.data.outputLines);
613
623
  }
624
+ get availableLines() {
625
+ return this.allLines.filter((line) => !line.isDrawing && !line.isHidden);
626
+ }
614
627
  /**
615
628
  * 输入节点
616
629
  */
@@ -752,6 +765,12 @@ var WorkflowLineRenderData = class extends EntityData3 {
752
765
  get lineType() {
753
766
  return this.entity.renderType ?? this.entity.linesManager.lineType;
754
767
  }
768
+ /**
769
+ * 获取 center 位置
770
+ */
771
+ get center() {
772
+ return this.currentLine?.center || { x: 0, y: 0, labelX: 0, labelY: 0 };
773
+ }
755
774
  /**
756
775
  * 更新版本
757
776
  * WARNING: 这个方法,必须在 requestAnimationFrame / useLayoutEffect 中调用,否则会引起浏览器强制重排
@@ -1013,6 +1032,9 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
1013
1032
  get bounds() {
1014
1033
  return this.getData(WorkflowLineRenderData).bounds;
1015
1034
  }
1035
+ get center() {
1036
+ return this.getData(WorkflowLineRenderData).center;
1037
+ }
1016
1038
  /**
1017
1039
  * 获取点和线最接近的距离
1018
1040
  */
@@ -3598,81 +3620,6 @@ var WorkflowDocumentContainerModule = new ContainerModule(
3598
3620
  bind(WorkflowDocumentProvider).toDynamicValue((ctx) => () => ctx.container.get(WorkflowDocument)).inSingletonScope();
3599
3621
  }
3600
3622
  );
3601
-
3602
- // src/utils/simple-line.ts
3603
- import { Point, Rectangle as Rectangle9 } from "@flowgram.ai/utils";
3604
- var LINE_PADDING = 12;
3605
- var WorkflowSimpleLineContribution = class {
3606
- constructor(entity) {
3607
- this.entity = entity;
3608
- }
3609
- get path() {
3610
- return this.data?.path ?? "";
3611
- }
3612
- calcDistance(pos) {
3613
- if (!this.data) {
3614
- return Number.MAX_SAFE_INTEGER;
3615
- }
3616
- const [start, end] = this.data.points;
3617
- return Point.getDistance(pos, this.projectPointOnLine(pos, start, end));
3618
- }
3619
- get bounds() {
3620
- if (!this.data) {
3621
- return new Rectangle9();
3622
- }
3623
- return this.data.bbox;
3624
- }
3625
- update(params) {
3626
- const { fromPos, toPos } = params;
3627
- const { vertical } = this.entity;
3628
- const sourceOffset = {
3629
- x: vertical ? 0 : POINT_RADIUS,
3630
- y: vertical ? POINT_RADIUS : 0
3631
- };
3632
- const targetOffset = {
3633
- x: vertical ? 0 : -POINT_RADIUS,
3634
- y: vertical ? -POINT_RADIUS : 0
3635
- };
3636
- const points = [
3637
- {
3638
- x: fromPos.x + sourceOffset.x,
3639
- y: fromPos.y + sourceOffset.y
3640
- },
3641
- {
3642
- x: toPos.x + targetOffset.x,
3643
- y: toPos.y + targetOffset.y
3644
- }
3645
- ];
3646
- const bbox = Rectangle9.createRectangleWithTwoPoints(points[0], points[1]);
3647
- const adjustedPoints = points.map((p) => ({
3648
- x: p.x - bbox.x + LINE_PADDING,
3649
- y: p.y - bbox.y + LINE_PADDING
3650
- }));
3651
- const path = `M ${adjustedPoints[0].x} ${adjustedPoints[0].y} L ${adjustedPoints[1].x} ${adjustedPoints[1].y}`;
3652
- this.data = {
3653
- points,
3654
- path,
3655
- bbox
3656
- };
3657
- }
3658
- projectPointOnLine(point, lineStart, lineEnd) {
3659
- const dx = lineEnd.x - lineStart.x;
3660
- const dy = lineEnd.y - lineStart.y;
3661
- if (dx === 0) {
3662
- return { x: lineStart.x, y: point.y };
3663
- }
3664
- if (dy === 0) {
3665
- return { x: point.x, y: lineStart.y };
3666
- }
3667
- const t = ((point.x - lineStart.x) * dx + (point.y - lineStart.y) * dy) / (dx * dx + dy * dy);
3668
- const clampedT = Math.max(0, Math.min(1, t));
3669
- return {
3670
- x: lineStart.x + clampedT * dx,
3671
- y: lineStart.y + clampedT * dy
3672
- };
3673
- }
3674
- };
3675
- WorkflowSimpleLineContribution.type = "WorkflowSimpleLineContribution";
3676
3623
  export {
3677
3624
  EditorCursorState,
3678
3625
  InteractiveType,
@@ -3703,7 +3650,6 @@ export {
3703
3650
  WorkflowPortEntity,
3704
3651
  WorkflowResetLayoutService,
3705
3652
  WorkflowSelectService,
3706
- WorkflowSimpleLineContribution,
3707
3653
  bindConfigEntity,
3708
3654
  buildGroupJSON,
3709
3655
  compose,
@@ -3712,6 +3658,7 @@ export {
3712
3658
  domReactToBounds,
3713
3659
  fitView,
3714
3660
  getAntiOverlapPosition,
3661
+ getLineCenter,
3715
3662
  getPortEntityId,
3716
3663
  nanoid,
3717
3664
  useConfigEntity,