@logicflow/core 2.0.12 → 2.0.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.
Files changed (68) hide show
  1. package/.turbo/turbo-build$colon$dev.log +2 -2
  2. package/.turbo/turbo-build.log +7 -7
  3. package/CHANGELOG.md +12 -0
  4. package/__tests__/algorithm/index.test.ts +22 -17
  5. package/__tests__/algorithm/outline.test.ts +9 -9
  6. package/__tests__/event/event.test.ts +18 -18
  7. package/__tests__/history/history.test.ts +23 -23
  8. package/__tests__/logicflow.test.ts +236 -228
  9. package/__tests__/model/graphmodel.test.ts +51 -31
  10. package/__tests__/util/compatible.test.ts +5 -5
  11. package/__tests__/util/geometry.test.ts +10 -10
  12. package/__tests__/util/graph.test.ts +12 -12
  13. package/__tests__/util/matrix.test.ts +26 -26
  14. package/__tests__/util/node.test.ts +22 -22
  15. package/__tests__/util/sampling.test.ts +6 -10
  16. package/__tests__/util/vector.test.ts +36 -36
  17. package/__tests__/util/zIndex.test.ts +6 -6
  18. package/dist/index.min.js +1 -1
  19. package/dist/index.min.js.map +1 -1
  20. package/es/LogicFlow.d.ts +29 -4
  21. package/es/LogicFlow.js +35 -6
  22. package/es/model/GraphModel.d.ts +35 -1
  23. package/es/model/GraphModel.js +45 -5
  24. package/es/model/node/RectNodeModel.js +3 -0
  25. package/es/options.d.ts +1 -0
  26. package/es/util/theme.d.ts +67 -2
  27. package/es/util/theme.js +189 -2
  28. package/es/view/Graph.d.ts +0 -3
  29. package/es/view/Graph.js +3 -7
  30. package/es/view/edge/BaseEdge.d.ts +4 -0
  31. package/es/view/edge/BaseEdge.js +45 -3
  32. package/es/view/overlay/Grid.js +3 -2
  33. package/es/view/overlay/ToolOverlay.d.ts +1 -3
  34. package/es/view/overlay/ToolOverlay.js +2 -39
  35. package/es/view/shape/Polygon.d.ts +8 -0
  36. package/es/view/shape/Polygon.js +50 -3
  37. package/lib/LogicFlow.d.ts +29 -4
  38. package/lib/LogicFlow.js +34 -5
  39. package/lib/model/GraphModel.d.ts +35 -1
  40. package/lib/model/GraphModel.js +43 -3
  41. package/lib/model/node/RectNodeModel.js +3 -0
  42. package/lib/options.d.ts +1 -0
  43. package/lib/util/theme.d.ts +67 -2
  44. package/lib/util/theme.js +192 -2
  45. package/lib/view/Graph.d.ts +0 -3
  46. package/lib/view/Graph.js +2 -6
  47. package/lib/view/edge/BaseEdge.d.ts +4 -0
  48. package/lib/view/edge/BaseEdge.js +45 -3
  49. package/lib/view/overlay/Grid.js +3 -2
  50. package/lib/view/overlay/ToolOverlay.d.ts +1 -3
  51. package/lib/view/overlay/ToolOverlay.js +2 -39
  52. package/lib/view/shape/Polygon.d.ts +8 -0
  53. package/lib/view/shape/Polygon.js +52 -4
  54. package/package.json +1 -1
  55. package/src/LogicFlow.tsx +57 -7
  56. package/src/model/GraphModel.ts +56 -3
  57. package/src/model/edge/index.ts +4 -4
  58. package/src/model/index.ts +7 -7
  59. package/src/model/node/RectNodeModel.ts +2 -1
  60. package/src/model/node/index.ts +8 -8
  61. package/src/options.ts +1 -0
  62. package/src/util/theme.ts +198 -3
  63. package/src/view/Graph.tsx +3 -15
  64. package/src/view/edge/BaseEdge.tsx +96 -12
  65. package/src/view/overlay/Grid.tsx +2 -1
  66. package/src/view/overlay/ToolOverlay.tsx +2 -17
  67. package/src/view/shape/Polygon.tsx +56 -4
  68. package/stats.html +1 -1
@@ -1,4 +1,69 @@
1
1
  import LogicFlow from '../LogicFlow';
2
2
  export declare const defaultTheme: LogicFlow.Theme;
3
- export declare const setupTheme: (customTheme?: Partial<LogicFlow.Theme>) => LogicFlow.Theme;
4
- export declare const updateTheme: (customTheme?: Partial<LogicFlow.Theme>) => LogicFlow.Theme;
3
+ export declare const radiusMode: any;
4
+ export declare const darkMode: any;
5
+ export declare const colorfulMode: any;
6
+ export declare const themeModeMap: {
7
+ colorful: any;
8
+ dark: any;
9
+ radius: any;
10
+ default: LogicFlow.Theme;
11
+ };
12
+ export declare const darkBackground: {
13
+ background: string;
14
+ };
15
+ export declare const colorfulBackground: {
16
+ background: string;
17
+ };
18
+ export declare const defaultBackground: {
19
+ background: string;
20
+ };
21
+ export declare const backgroundModeMap: {
22
+ colorful: {
23
+ background: string;
24
+ };
25
+ dark: {
26
+ background: string;
27
+ };
28
+ radius: {
29
+ background: string;
30
+ };
31
+ default: {
32
+ background: string;
33
+ };
34
+ };
35
+ export declare const darkGrid: {
36
+ color: string;
37
+ thickness: number;
38
+ };
39
+ export declare const colorfulGrid: {
40
+ color: string;
41
+ thickness: number;
42
+ };
43
+ export declare const defaultGrid: {
44
+ color: string;
45
+ thickness: number;
46
+ };
47
+ export declare const gridModeMap: {
48
+ colorful: {
49
+ color: string;
50
+ thickness: number;
51
+ };
52
+ dark: {
53
+ color: string;
54
+ thickness: number;
55
+ };
56
+ radius: {
57
+ color: string;
58
+ thickness: number;
59
+ };
60
+ default: {
61
+ color: string;
62
+ thickness: number;
63
+ };
64
+ };
65
+ export declare const setupTheme: (customTheme?: Partial<LogicFlow.Theme>, themeMode?: 'radius' | 'dark' | 'colorful' | 'default' | string) => LogicFlow.Theme;
66
+ export declare const addThemeMode: (themeMode: string, style: Partial<LogicFlow.Theme>) => void;
67
+ export declare const removeThemeMode: (themeMode: string) => void;
68
+ export declare const clearThemeMode: () => void;
69
+ export declare const updateTheme: (customTheme?: Partial<LogicFlow.Theme>, themeMode?: 'radius' | 'dark' | 'colorful' | 'default' | string) => LogicFlow.Theme;
package/lib/util/theme.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateTheme = exports.setupTheme = exports.defaultTheme = void 0;
3
+ exports.updateTheme = exports.clearThemeMode = exports.removeThemeMode = exports.addThemeMode = exports.setupTheme = exports.gridModeMap = exports.defaultGrid = exports.colorfulGrid = exports.darkGrid = exports.backgroundModeMap = exports.defaultBackground = exports.colorfulBackground = exports.darkBackground = exports.themeModeMap = exports.colorfulMode = exports.darkMode = exports.radiusMode = exports.defaultTheme = void 0;
4
4
  var lodash_es_1 = require("lodash-es");
5
5
  exports.defaultTheme = {
6
6
  baseNode: {
@@ -119,9 +119,171 @@ exports.defaultTheme = {
119
119
  strokeDasharray: '3,3',
120
120
  },
121
121
  };
122
+ exports.radiusMode = {
123
+ rect: { radius: 8 },
124
+ diamond: { radius: 8 },
125
+ polygon: { radius: 8 },
126
+ polyline: { radius: 8 },
127
+ arrow: {
128
+ strokeLinecap: 'round',
129
+ strokeLinejoin: 'round',
130
+ offset: 10,
131
+ verticalLength: 5, // 箭头垂直于边的距离
132
+ },
133
+ snapline: {
134
+ strokeLinecap: 'round',
135
+ strokeLinejoin: 'round',
136
+ stroke: '#949494',
137
+ strokeWidth: 1,
138
+ },
139
+ outline: {
140
+ radius: 8,
141
+ fill: 'transparent',
142
+ stroke: '#949494',
143
+ strokeDasharray: '3,3',
144
+ hover: {
145
+ stroke: '#949494',
146
+ },
147
+ },
148
+ resizeOutline: {
149
+ radius: 8,
150
+ fill: 'none',
151
+ stroke: 'transparent', // 矩形默认不显示调整边框
152
+ strokeWidth: 1,
153
+ strokeDasharray: '3,3',
154
+ },
155
+ };
156
+ exports.darkMode = {
157
+ baseNode: {
158
+ fill: '#23272e',
159
+ stroke: '#fefeff',
160
+ },
161
+ baseEdge: {
162
+ stroke: '#fefeff',
163
+ },
164
+ rect: { radius: 8 },
165
+ diamond: { radius: 8 },
166
+ polygon: { radius: 8 },
167
+ polyline: { radius: 8 },
168
+ nodeText: {
169
+ color: '#fefeff',
170
+ overflowMode: 'default',
171
+ fontSize: 12,
172
+ lineHeight: 1.2,
173
+ },
174
+ arrow: {
175
+ strokeLinecap: 'round',
176
+ strokeLinejoin: 'round',
177
+ offset: 10,
178
+ verticalLength: 5, // 箭头垂直于边的距离
179
+ },
180
+ snapline: {
181
+ strokeLinecap: 'round',
182
+ strokeLinejoin: 'round',
183
+ stroke: '#949494',
184
+ strokeWidth: 1,
185
+ },
186
+ outline: {
187
+ radius: 8,
188
+ fill: 'transparent',
189
+ stroke: '#949494',
190
+ strokeDasharray: '3,3',
191
+ hover: {
192
+ stroke: '#949494',
193
+ },
194
+ },
195
+ resizeOutline: {
196
+ radius: 8,
197
+ fill: 'none',
198
+ stroke: 'transparent', // 矩形默认不显示调整边框
199
+ strokeWidth: 1,
200
+ strokeDasharray: '3,3',
201
+ },
202
+ };
203
+ exports.colorfulMode = {
204
+ rect: { fill: '#72CBFF', stroke: '#3ABDF9', radius: 8 },
205
+ circle: { fill: '#FFE075', stroke: '#F9CE3A', radius: 8 },
206
+ ellipse: { fill: '#FFA8A8', stroke: '#FF6B66', radius: 8 },
207
+ text: { fill: '#72CBFF', radius: 8 },
208
+ diamond: { fill: '#96F7AF', stroke: '#40EF7E', radius: 8 },
209
+ polygon: { fill: '#E0A8FF', stroke: '#C271FF', radius: 8 },
210
+ polyline: { radius: 8 },
211
+ arrow: {
212
+ strokeLinecap: 'round',
213
+ strokeLinejoin: 'round',
214
+ offset: 10,
215
+ verticalLength: 5, // 箭头垂直于边的距离
216
+ },
217
+ snapline: {
218
+ strokeLinecap: 'round',
219
+ strokeLinejoin: 'round',
220
+ stroke: '#949494',
221
+ strokeWidth: 1,
222
+ },
223
+ outline: {
224
+ radius: 8,
225
+ fill: 'transparent',
226
+ stroke: '#949494',
227
+ strokeDasharray: '3,3',
228
+ hover: {
229
+ stroke: '#949494',
230
+ },
231
+ },
232
+ resizeOutline: {
233
+ radius: 8,
234
+ fill: 'none',
235
+ stroke: 'transparent', // 矩形默认不显示调整边框
236
+ strokeWidth: 1,
237
+ strokeDasharray: '3,3',
238
+ },
239
+ };
240
+ exports.themeModeMap = {
241
+ colorful: exports.colorfulMode,
242
+ dark: exports.darkMode,
243
+ radius: exports.radiusMode,
244
+ default: exports.defaultTheme,
245
+ };
246
+ // 不同主题的背景色
247
+ exports.darkBackground = {
248
+ background: '#23272e',
249
+ };
250
+ exports.colorfulBackground = {
251
+ background: '#fefeff',
252
+ };
253
+ exports.defaultBackground = {
254
+ background: '#ffffff',
255
+ };
256
+ exports.backgroundModeMap = {
257
+ colorful: exports.colorfulBackground,
258
+ dark: exports.darkBackground,
259
+ radius: exports.defaultBackground,
260
+ default: exports.defaultBackground,
261
+ };
262
+ // 不同主题的网格样式
263
+ exports.darkGrid = {
264
+ color: '#66676a',
265
+ thickness: 1,
266
+ };
267
+ exports.colorfulGrid = {
268
+ color: '#dadada',
269
+ thickness: 1,
270
+ };
271
+ exports.defaultGrid = {
272
+ color: '#acacac',
273
+ thickness: 1,
274
+ };
275
+ exports.gridModeMap = {
276
+ colorful: exports.colorfulGrid,
277
+ dark: exports.darkGrid,
278
+ radius: exports.defaultGrid,
279
+ default: exports.defaultGrid,
280
+ };
122
281
  /* 主题(全局样式)相关工具方法 */
123
- var setupTheme = function (customTheme) {
282
+ var setupTheme = function (customTheme, themeMode) {
124
283
  var theme = (0, lodash_es_1.cloneDeep)(exports.defaultTheme);
284
+ if (themeMode) {
285
+ theme = (0, lodash_es_1.merge)(theme, exports.themeModeMap[themeMode]);
286
+ }
125
287
  if (customTheme) {
126
288
  /**
127
289
  * 为了不让默认样式被覆盖,使用 merge 方法
@@ -155,5 +317,33 @@ var setupTheme = function (customTheme) {
155
317
  return theme;
156
318
  };
157
319
  exports.setupTheme = setupTheme;
320
+ var addThemeMode = function (themeMode, style) {
321
+ if (exports.themeModeMap[themeMode]) {
322
+ console.warn("theme mode ".concat(themeMode, " already exists"));
323
+ return;
324
+ }
325
+ exports.themeModeMap[themeMode] = style;
326
+ exports.backgroundModeMap[themeMode] = style.background || exports.defaultBackground;
327
+ exports.gridModeMap[themeMode] = style.grid || exports.defaultGrid;
328
+ };
329
+ exports.addThemeMode = addThemeMode;
330
+ var removeThemeMode = function (themeMode) {
331
+ delete exports.themeModeMap[themeMode];
332
+ delete exports.backgroundModeMap[themeMode];
333
+ delete exports.gridModeMap[themeMode];
334
+ };
335
+ exports.removeThemeMode = removeThemeMode;
336
+ var clearThemeMode = function () {
337
+ var resetTheme = {
338
+ colorful: {},
339
+ dark: {},
340
+ radius: {},
341
+ default: {},
342
+ };
343
+ (0, lodash_es_1.assign)(exports.themeModeMap, resetTheme);
344
+ (0, lodash_es_1.assign)(exports.backgroundModeMap, resetTheme);
345
+ (0, lodash_es_1.assign)(exports.gridModeMap, resetTheme);
346
+ };
347
+ exports.clearThemeMode = clearThemeMode;
158
348
  /* 更新 theme 方法 */
159
349
  exports.updateTheme = exports.setupTheme;
@@ -1,5 +1,4 @@
1
1
  import { Component, ComponentType } from 'preact/compat';
2
- import { CanvasOverlay } from './overlay';
3
2
  import DnD from './behavior/dnd';
4
3
  import Tool from '../tool';
5
4
  import { Options as LFOptions } from '../options';
@@ -13,8 +12,6 @@ type IGraphProps = {
13
12
  graphModel: GraphModel;
14
13
  };
15
14
  declare class Graph extends Component<IGraphProps> {
16
- canvasOverlayRef: import("preact").RefObject<CanvasOverlay>;
17
- getCanvasOverlay: () => CanvasOverlay | null;
18
15
  private handleResize;
19
16
  private throttleResize;
20
17
  componentDidMount(): void;
package/lib/view/Graph.js CHANGED
@@ -56,10 +56,6 @@ var Graph = /** @class */ (function (_super) {
56
56
  __extends(Graph, _super);
57
57
  function Graph() {
58
58
  var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
59
- _this.canvasOverlayRef = (0, compat_1.createRef)();
60
- _this.getCanvasOverlay = function () {
61
- return _this.canvasOverlayRef.current;
62
- };
63
59
  _this.handleResize = function () {
64
60
  var _a = _this.props, graphModel = _a.graphModel, options = _a.options;
65
61
  var width = graphModel.width, height = graphModel.height, isContainerWidth = graphModel.isContainerWidth, isContainerHeight = graphModel.isContainerHeight;
@@ -116,9 +112,9 @@ var Graph = /** @class */ (function (_super) {
116
112
  }
117
113
  var fakeNode = graphModel.fakeNode, editConfigModel = graphModel.editConfigModel, background = graphModel.background;
118
114
  var adjustEdge = editConfigModel.adjustEdge;
119
- return ((0, jsx_runtime_1.jsxs)("div", { className: "lf-graph", "flow-id": graphModel.flowId, style: style, children: [(0, jsx_runtime_1.jsxs)(overlay_1.CanvasOverlay, { ref: this.canvasOverlayRef, graphModel: graphModel, dnd: dnd, children: [(0, jsx_runtime_1.jsx)("g", { className: "lf-base", children: (0, lodash_es_1.map)(graphModel.sortElements, function (nodeModel) {
115
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "lf-graph", "flow-id": graphModel.flowId, style: style, children: [(0, jsx_runtime_1.jsxs)(overlay_1.CanvasOverlay, { graphModel: graphModel, dnd: dnd, children: [(0, jsx_runtime_1.jsx)("g", { className: "lf-base", children: (0, lodash_es_1.map)(graphModel.sortElements, function (nodeModel) {
120
116
  return _this.getComponent(nodeModel, graphModel);
121
- }) }), fakeNode ? this.getComponent(fakeNode, graphModel) : ''] }), (0, jsx_runtime_1.jsxs)(overlay_1.ModificationOverlay, { graphModel: graphModel, children: [(0, jsx_runtime_1.jsx)(overlay_1.OutlineOverlay, { graphModel: graphModel }), adjustEdge ? (0, jsx_runtime_1.jsx)(overlay_1.BezierAdjustOverlay, { graphModel: graphModel }) : '', options.snapline !== false ? ((0, jsx_runtime_1.jsx)(overlay_1.SnaplineOverlay, { snaplineModel: snaplineModel })) : ('')] }), (0, jsx_runtime_1.jsx)(overlay_1.ToolOverlay, { graphModel: graphModel, tool: tool, getCanvasOverlay: this.getCanvasOverlay }), background && (0, jsx_runtime_1.jsx)(overlay_1.BackgroundOverlay, { background: background }), (0, jsx_runtime_1.jsx)(overlay_1.Grid, { graphModel: graphModel })] }));
117
+ }) }), fakeNode ? this.getComponent(fakeNode, graphModel) : ''] }), (0, jsx_runtime_1.jsxs)(overlay_1.ModificationOverlay, { graphModel: graphModel, children: [(0, jsx_runtime_1.jsx)(overlay_1.OutlineOverlay, { graphModel: graphModel }), adjustEdge ? (0, jsx_runtime_1.jsx)(overlay_1.BezierAdjustOverlay, { graphModel: graphModel }) : '', options.snapline !== false ? ((0, jsx_runtime_1.jsx)(overlay_1.SnaplineOverlay, { snaplineModel: snaplineModel })) : ('')] }), (0, jsx_runtime_1.jsx)(overlay_1.ToolOverlay, { graphModel: graphModel, tool: tool }), background && (0, jsx_runtime_1.jsx)(overlay_1.BackgroundOverlay, { background: background }), (0, jsx_runtime_1.jsx)(overlay_1.Grid, { graphModel: graphModel })] }));
122
118
  };
123
119
  Graph = __decorate([
124
120
  __1.observer
@@ -44,6 +44,10 @@ export declare abstract class BaseEdge<P extends IProps> extends Component<P, IE
44
44
  * 定义边的箭头,不支持重写。请使用getStartArrow和getEndArrow
45
45
  */
46
46
  private getArrow;
47
+ /**
48
+ * Private helper method to generate arrow path based on type and parameters
49
+ */
50
+ private getArrowPath;
47
51
  /**
48
52
  * @overridable 可重写,自定义边起点箭头形状。
49
53
  * @example
@@ -317,6 +317,31 @@ var BaseEdge = /** @class */ (function (_super) {
317
317
  }
318
318
  return ((0, jsx_runtime_1.jsx)("g", { children: (0, jsx_runtime_1.jsxs)("defs", { children: [(0, jsx_runtime_1.jsx)("marker", { id: "marker-start-".concat(id), refX: -refX, refY: refY, overflow: "visible", orient: "auto", markerUnits: "userSpaceOnUse", children: this.getStartArrow() }), (0, jsx_runtime_1.jsx)("marker", { id: "marker-end-".concat(id), refX: refX, refY: refY, overflow: "visible", orient: theta, markerUnits: "userSpaceOnUse", children: this.getEndArrow() })] }) }));
319
319
  };
320
+ /**
321
+ * Private helper method to generate arrow path based on type and parameters
322
+ */
323
+ BaseEdge.prototype.getArrowPath = function (arrowType, props) {
324
+ var stroke = props.stroke, _a = props.fill, fill = _a === void 0 ? stroke : _a, strokeWidth = props.strokeWidth, _b = props.offset, offset = _b === void 0 ? 10 : _b, verticalLength = props.verticalLength, strokeLinecap = props.strokeLinecap, strokeLinejoin = props.strokeLinejoin, transform = props.transform;
325
+ var arrowPath = '';
326
+ switch (arrowType) {
327
+ case 'solid':
328
+ arrowPath = "M".concat(-offset / 4, ",0 L").concat((3 * offset) / 4, ",").concat(verticalLength, " L").concat((3 * offset) / 4, ",-").concat(verticalLength, " Z");
329
+ break;
330
+ case 'hollow':
331
+ arrowPath = "M".concat(-offset / 4, ",0 L").concat((3 * offset) / 4, ",").concat(verticalLength, " L").concat(-offset / 4, ",0 L").concat((3 * offset) / 4, ",-").concat(verticalLength, " L").concat(-offset / 4, ",0 Z");
332
+ break;
333
+ case 'diamond':
334
+ arrowPath = "M".concat(-offset / 2, ",0 L0,").concat(verticalLength, " L").concat(offset / 2, ",0 L0,-").concat(verticalLength, " L").concat(-offset / 2, ",0 Z");
335
+ break;
336
+ case 'circle':
337
+ arrowPath = "M".concat(-offset / 2, ",0 A").concat(offset / 4, ",").concat(offset / 4, " 0 1,0 ").concat(offset / 2, ",0 A").concat(offset / 4, ",").concat(offset / 4, " 0 1,0 ").concat(-offset / 2, ",0 Z");
338
+ break;
339
+ default:
340
+ arrowPath = '';
341
+ break;
342
+ }
343
+ return ((0, jsx_runtime_1.jsx)("path", { d: arrowPath, stroke: stroke, fill: fill, strokeWidth: strokeWidth, strokeLinecap: strokeLinecap, strokeLinejoin: strokeLinejoin, transform: transform }));
344
+ };
320
345
  /**
321
346
  * @overridable 可重写,自定义边起点箭头形状。
322
347
  * @example
@@ -331,7 +356,16 @@ var BaseEdge = /** @class */ (function (_super) {
331
356
  * }
332
357
  */
333
358
  BaseEdge.prototype.getStartArrow = function () {
334
- return (0, jsx_runtime_1.jsx)("path", {});
359
+ var model = this.props.model;
360
+ var _a = model.getArrowStyle(), stroke = _a.stroke, strokeWidth = _a.strokeWidth, offset = _a.offset, verticalLength = _a.verticalLength, _b = _a.startArrowType, startArrowType = _b === void 0 ? 'solid' : _b, strokeLinecap = _a.strokeLinecap, strokeLinejoin = _a.strokeLinejoin;
361
+ return this.getArrowPath(startArrowType, {
362
+ stroke: stroke,
363
+ strokeWidth: strokeWidth,
364
+ offset: offset,
365
+ verticalLength: verticalLength,
366
+ strokeLinecap: strokeLinecap,
367
+ strokeLinejoin: strokeLinejoin,
368
+ });
335
369
  };
336
370
  /**
337
371
  * @overridable 可重写,自定义边终点箭头形状。
@@ -348,8 +382,16 @@ var BaseEdge = /** @class */ (function (_super) {
348
382
  */
349
383
  BaseEdge.prototype.getEndArrow = function () {
350
384
  var model = this.props.model;
351
- var _a = model.getArrowStyle(), stroke = _a.stroke, strokeWidth = _a.strokeWidth, offset = _a.offset, verticalLength = _a.verticalLength;
352
- return ((0, jsx_runtime_1.jsx)("path", { stroke: stroke, fill: stroke, strokeWidth: strokeWidth, transform: "rotate(180)", d: "M 0 0 L ".concat(offset, " -").concat(verticalLength, " L ").concat(offset, " ").concat(verticalLength, " Z") }));
385
+ var _a = model.getArrowStyle(), stroke = _a.stroke, strokeWidth = _a.strokeWidth, offset = _a.offset, verticalLength = _a.verticalLength, _b = _a.endArrowType, endArrowType = _b === void 0 ? 'solid' : _b, strokeLinecap = _a.strokeLinecap, strokeLinejoin = _a.strokeLinejoin;
386
+ return this.getArrowPath(endArrowType, {
387
+ stroke: stroke,
388
+ strokeWidth: strokeWidth,
389
+ offset: offset,
390
+ verticalLength: verticalLength,
391
+ strokeLinecap: strokeLinecap,
392
+ strokeLinejoin: strokeLinejoin,
393
+ transform: 'rotate(180)',
394
+ });
353
395
  };
354
396
  /**
355
397
  * @overridable 可重写,自定义调整边连接节点形状。在开启了adjustEdgeStartAndEnd的时候,会显示调整点。
@@ -57,8 +57,9 @@ var Grid = /** @class */ (function (_super) {
57
57
  return ((0, jsx_runtime_1.jsx)("path", { d: d, stroke: color, strokeWidth: strokeWidth / 2, opacity: opacity, fill: "transparent" }));
58
58
  };
59
59
  Grid.prototype.render = function () {
60
- var transformModel = this.props.graphModel.transformModel;
61
- var _a = this.gridOptions, type = _a.type, _b = _a.size, size = _b === void 0 ? 1 : _b;
60
+ var _a = this.props.graphModel, transformModel = _a.transformModel, grid = _a.grid;
61
+ this.gridOptions = grid;
62
+ var _b = this.gridOptions, type = _b.type, _c = _b.size, size = _c === void 0 ? 1 : _c;
62
63
  var SCALE_X = transformModel.SCALE_X, SKEW_Y = transformModel.SKEW_Y, SKEW_X = transformModel.SKEW_X, SCALE_Y = transformModel.SCALE_Y, TRANSLATE_X = transformModel.TRANSLATE_X, TRANSLATE_Y = transformModel.TRANSLATE_Y;
63
64
  var matrixString = [
64
65
  SCALE_X,
@@ -1,11 +1,10 @@
1
1
  import { createElement as h, Component } from 'preact/compat';
2
- import { CanvasOverlay, OutlineOverlay } from '.';
2
+ import { OutlineOverlay } from '.';
3
3
  import { GraphModel } from '../../model';
4
4
  import { Tool } from '../../tool';
5
5
  type IProps = {
6
6
  graphModel: GraphModel;
7
7
  tool: Tool;
8
- getCanvasOverlay: () => CanvasOverlay | null;
9
8
  };
10
9
  export declare class ToolOverlay extends Component<IProps> {
11
10
  componentDidMount(): void;
@@ -15,7 +14,6 @@ export declare class ToolOverlay extends Component<IProps> {
15
14
  */
16
15
  getTools(): import("preact").VNode<import("../..").IToolProps>[];
17
16
  triggerToolRender(): void;
18
- zoomHandler: (e: WheelEvent) => void;
19
17
  render(): h.JSX.Element;
20
18
  }
21
19
  export default OutlineOverlay;
@@ -20,31 +20,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
20
20
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
21
  return c > 3 && r && Object.defineProperty(target, key, r), r;
22
22
  };
23
- var __read = (this && this.__read) || function (o, n) {
24
- var m = typeof Symbol === "function" && o[Symbol.iterator];
25
- if (!m) return o;
26
- var i = m.call(o), r, ar = [], e;
27
- try {
28
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
29
- }
30
- catch (error) { e = { error: error }; }
31
- finally {
32
- try {
33
- if (r && !r.done && (m = i["return"])) m.call(i);
34
- }
35
- finally { if (e) throw e.error; }
36
- }
37
- return ar;
38
- };
39
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
40
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
41
- if (ar || !(i in from)) {
42
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
43
- ar[i] = from[i];
44
- }
45
- }
46
- return to.concat(ar || Array.prototype.slice.call(from));
47
- };
48
23
  Object.defineProperty(exports, "__esModule", { value: true });
49
24
  exports.ToolOverlay = void 0;
50
25
  var jsx_runtime_1 = require("preact/jsx-runtime");
@@ -54,13 +29,7 @@ var __1 = require("../..");
54
29
  var ToolOverlay = /** @class */ (function (_super) {
55
30
  __extends(ToolOverlay, _super);
56
31
  function ToolOverlay() {
57
- var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
58
- _this.zoomHandler = function (e) {
59
- var _a;
60
- // TODO 是否应该使用 dispatchEvent 来触发事件
61
- (_a = _this.props.getCanvasOverlay()) === null || _a === void 0 ? void 0 : _a.zoomHandler(e);
62
- };
63
- return _this;
32
+ return _super !== null && _super.apply(this, arguments) || this;
64
33
  }
65
34
  // 在react严格模式下,useEffect会执行两次,但是在LogicFlow内部,则只会触发一次componentDidMount和componentDidUpdate。
66
35
  // 其中第一次componentDidMount对应的graphModel为被丢弃的graphModel, 所以不应该生效。
@@ -98,13 +67,7 @@ var ToolOverlay = /** @class */ (function (_super) {
98
67
  };
99
68
  ToolOverlay.prototype.render = function () {
100
69
  var graphModel = this.props.graphModel;
101
- return ((0, jsx_runtime_1.jsx)("div", { className: "lf-tool-overlay", id: "ToolOverlay_".concat(graphModel.flowId),
102
- /*
103
- * 默认情况下该容器设置了 pointer-events: none,不会触发这些事件
104
- * 只会在容器取消 pointer-events: none 后触发,用于缩放、滚动画布等操作
105
- * 目前只在 selection-select 插件中使用。为了能在元素内部进行框选,在开启选区后会关闭事件透传。需要手动触发事件
106
- */
107
- onWheel: this.zoomHandler, children: this.getTools() }));
70
+ return ((0, jsx_runtime_1.jsx)("div", { className: "lf-tool-overlay", id: "ToolOverlay_".concat(graphModel.flowId), children: this.getTools() }));
108
71
  };
109
72
  ToolOverlay = __decorate([
110
73
  __1.observer
@@ -5,6 +5,14 @@ export type IPolygonProps = {
5
5
  x?: number;
6
6
  y?: number;
7
7
  className?: string;
8
+ radius?: number;
8
9
  };
10
+ /**
11
+ * 生成带圆角的多边形路径
12
+ * @param points 多边形顶点坐标数组
13
+ * @param radius 圆角半径
14
+ * @returns SVG 路径字符串
15
+ */
16
+ export declare function createRoundedPolygonPath(points: any, radius: any): string;
9
17
  export declare function Polygon(props: IPolygonProps): h.JSX.Element;
10
18
  export default Polygon;
@@ -27,11 +27,52 @@ var __read = (this && this.__read) || function (o, n) {
27
27
  return ar;
28
28
  };
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.Polygon = void 0;
30
+ exports.Polygon = exports.createRoundedPolygonPath = void 0;
31
31
  var jsx_runtime_1 = require("preact/jsx-runtime");
32
32
  var lodash_es_1 = require("lodash-es");
33
+ /**
34
+ * 生成带圆角的多边形路径
35
+ * @param points 多边形顶点坐标数组
36
+ * @param radius 圆角半径
37
+ * @returns SVG 路径字符串
38
+ */
39
+ function createRoundedPolygonPath(points, radius) {
40
+ var pointList = points.map(function (point) { return ({ x: point[0], y: point[1] }); });
41
+ var len = pointList.length;
42
+ if (len < 3)
43
+ return '';
44
+ var r = Math.abs(radius);
45
+ var path = '';
46
+ for (var i = 0; i < len; i++) {
47
+ var prev = pointList[(i - 1 + len) % len];
48
+ var curr = pointList[i];
49
+ var next = pointList[(i + 1) % len];
50
+ // 向量
51
+ var v1 = { x: curr.x - prev.x, y: curr.y - prev.y };
52
+ var v2 = { x: next.x - curr.x, y: next.y - curr.y };
53
+ // 单位向量
54
+ var len1 = Math.hypot(v1.x, v1.y);
55
+ var len2 = Math.hypot(v2.x, v2.y);
56
+ var u1 = { x: v1.x / len1, y: v1.y / len1 };
57
+ var u2 = { x: v2.x / len2, y: v2.y / len2 };
58
+ // 起点 = curr - u1 * r,终点 = curr + u2 * r
59
+ var start = { x: curr.x - u1.x * r, y: curr.y - u1.y * r };
60
+ var end = { x: curr.x + u2.x * r, y: curr.y + u2.y * r };
61
+ if (i === 0) {
62
+ path += "M ".concat(start.x, " ").concat(start.y, " ");
63
+ }
64
+ else {
65
+ path += "L ".concat(start.x, " ").concat(start.y, " ");
66
+ }
67
+ // Q 控制点是当前拐角点
68
+ path += "Q ".concat(curr.x, " ").concat(curr.y, " ").concat(end.x, " ").concat(end.y, " ");
69
+ }
70
+ path += 'Z';
71
+ return path;
72
+ }
73
+ exports.createRoundedPolygonPath = createRoundedPolygonPath;
33
74
  function Polygon(props) {
34
- var _a = props.points, points = _a === void 0 ? [] : _a, className = props.className;
75
+ var _a = props.points, points = _a === void 0 ? [] : _a, className = props.className, radius = props.radius;
35
76
  var attrs = {
36
77
  fill: 'transparent',
37
78
  fillOpacity: 1,
@@ -52,8 +93,15 @@ function Polygon(props) {
52
93
  else {
53
94
  attrs.className = 'lf-basic-shape';
54
95
  }
55
- attrs.points = points.map(function (point) { return point.join(','); }).join(' ');
56
- return (0, jsx_runtime_1.jsx)("polygon", __assign({}, attrs));
96
+ if (radius) {
97
+ var path = createRoundedPolygonPath(points, radius);
98
+ attrs.d = path;
99
+ return (0, jsx_runtime_1.jsx)("path", __assign({}, attrs));
100
+ }
101
+ else {
102
+ attrs.points = points.map(function (point) { return point.join(','); }).join(' ');
103
+ return (0, jsx_runtime_1.jsx)("polygon", __assign({}, attrs));
104
+ }
57
105
  }
58
106
  exports.Polygon = Polygon;
59
107
  exports.default = Polygon;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logicflow/core",
3
- "version": "2.0.12",
3
+ "version": "2.0.14",
4
4
  "description": "LogicFlow, help you quickly create flowcharts",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",