@logicflow/core 2.2.0-alpha.1 → 2.2.0-alpha.3

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 (119) hide show
  1. package/.turbo/turbo-build$colon$dev.log +2 -57
  2. package/.turbo/turbo-build.log +6 -6
  3. package/CHANGELOG.md +12 -0
  4. package/dist/index.css +3 -2
  5. package/dist/index.min.js +1 -1
  6. package/dist/index.min.js.map +1 -1
  7. package/es/LogicFlow.d.ts +9 -0
  8. package/es/constant/index.d.ts +1 -1
  9. package/es/constant/index.js +1 -1
  10. package/es/constant/theme.d.ts +136 -0
  11. package/es/constant/theme.js +680 -0
  12. package/es/index.css +3 -2
  13. package/es/model/GraphModel.d.ts +9 -2
  14. package/es/model/GraphModel.js +17 -6
  15. package/es/model/TransformModel.js +9 -9
  16. package/es/model/edge/BaseEdgeModel.js +7 -2
  17. package/es/model/edge/PolylineEdgeModel.d.ts +6 -0
  18. package/es/model/edge/PolylineEdgeModel.js +23 -1
  19. package/es/model/node/BaseNodeModel.d.ts +12 -1
  20. package/es/model/node/BaseNodeModel.js +6 -1
  21. package/es/model/node/HtmlNodeModel.d.ts +12 -0
  22. package/es/model/node/HtmlNodeModel.js +19 -0
  23. package/es/model/node/PolygonNodeModel.js +3 -3
  24. package/es/options.d.ts +1 -1
  25. package/es/style/index.css +3 -2
  26. package/es/style/index.less +3 -2
  27. package/es/style/raw.d.ts +1 -1
  28. package/es/style/raw.js +1 -1
  29. package/es/tool/MultipleSelectTool.js +6 -5
  30. package/es/util/edge.d.ts +1 -1
  31. package/es/util/edge.js +2 -2
  32. package/es/util/geometry.d.ts +8 -0
  33. package/es/util/geometry.js +79 -0
  34. package/es/util/theme.d.ts +2 -65
  35. package/es/util/theme.js +4 -281
  36. package/es/view/Control.d.ts +5 -0
  37. package/es/view/Control.js +44 -57
  38. package/es/view/edge/PolylineEdge.js +13 -2
  39. package/es/view/node/BaseNode.d.ts +1 -0
  40. package/es/view/node/BaseNode.js +14 -10
  41. package/es/view/node/HtmlNode.js +2 -4
  42. package/es/view/overlay/Grid.d.ts +12 -1
  43. package/es/view/overlay/Grid.js +85 -23
  44. package/es/view/overlay/OutlineOverlay.d.ts +1 -0
  45. package/es/view/overlay/OutlineOverlay.js +17 -16
  46. package/es/view/overlay/gridConfig.d.ts +46 -0
  47. package/es/view/overlay/gridConfig.js +99 -0
  48. package/es/view/shape/Polygon.d.ts +0 -7
  49. package/es/view/shape/Polygon.js +12 -43
  50. package/lib/LogicFlow.d.ts +9 -0
  51. package/lib/constant/index.d.ts +1 -1
  52. package/lib/constant/index.js +16 -2
  53. package/lib/constant/theme.d.ts +136 -0
  54. package/lib/constant/theme.js +683 -0
  55. package/lib/index.css +3 -2
  56. package/lib/model/GraphModel.d.ts +9 -2
  57. package/lib/model/GraphModel.js +18 -7
  58. package/lib/model/TransformModel.js +9 -9
  59. package/lib/model/edge/BaseEdgeModel.js +7 -2
  60. package/lib/model/edge/PolylineEdgeModel.d.ts +6 -0
  61. package/lib/model/edge/PolylineEdgeModel.js +23 -1
  62. package/lib/model/node/BaseNodeModel.d.ts +12 -1
  63. package/lib/model/node/BaseNodeModel.js +6 -1
  64. package/lib/model/node/HtmlNodeModel.d.ts +12 -0
  65. package/lib/model/node/HtmlNodeModel.js +19 -0
  66. package/lib/model/node/PolygonNodeModel.js +3 -3
  67. package/lib/options.d.ts +1 -1
  68. package/lib/style/index.css +3 -2
  69. package/lib/style/index.less +3 -2
  70. package/lib/style/raw.d.ts +1 -1
  71. package/lib/style/raw.js +1 -1
  72. package/lib/tool/MultipleSelectTool.js +6 -5
  73. package/lib/util/edge.d.ts +1 -1
  74. package/lib/util/edge.js +2 -2
  75. package/lib/util/geometry.d.ts +8 -0
  76. package/lib/util/geometry.js +81 -1
  77. package/lib/util/theme.d.ts +2 -65
  78. package/lib/util/theme.js +15 -292
  79. package/lib/view/Control.d.ts +5 -0
  80. package/lib/view/Control.js +44 -57
  81. package/lib/view/edge/PolylineEdge.js +13 -2
  82. package/lib/view/node/BaseNode.d.ts +1 -0
  83. package/lib/view/node/BaseNode.js +14 -10
  84. package/lib/view/node/HtmlNode.js +1 -3
  85. package/lib/view/overlay/Grid.d.ts +12 -1
  86. package/lib/view/overlay/Grid.js +83 -21
  87. package/lib/view/overlay/OutlineOverlay.d.ts +1 -0
  88. package/lib/view/overlay/OutlineOverlay.js +17 -16
  89. package/lib/view/overlay/gridConfig.d.ts +46 -0
  90. package/lib/view/overlay/gridConfig.js +104 -0
  91. package/lib/view/shape/Polygon.d.ts +0 -7
  92. package/lib/view/shape/Polygon.js +13 -45
  93. package/package.json +1 -1
  94. package/src/LogicFlow.tsx +10 -0
  95. package/src/constant/index.ts +2 -2
  96. package/src/constant/theme.ts +708 -0
  97. package/src/model/GraphModel.ts +19 -7
  98. package/src/model/TransformModel.ts +9 -9
  99. package/src/model/edge/BaseEdgeModel.ts +10 -2
  100. package/src/model/edge/PolylineEdgeModel.ts +26 -1
  101. package/src/model/node/BaseNodeModel.ts +9 -1
  102. package/src/model/node/HtmlNodeModel.ts +14 -0
  103. package/src/model/node/PolygonNodeModel.ts +2 -0
  104. package/src/options.ts +1 -1
  105. package/src/style/index.less +3 -2
  106. package/src/style/raw.ts +3 -2
  107. package/src/tool/MultipleSelectTool.tsx +6 -5
  108. package/src/util/edge.ts +2 -1
  109. package/src/util/geometry.ts +99 -0
  110. package/src/util/theme.ts +12 -303
  111. package/src/view/Control.tsx +61 -63
  112. package/src/view/edge/PolylineEdge.tsx +14 -2
  113. package/src/view/node/BaseNode.tsx +8 -3
  114. package/src/view/node/HtmlNode.tsx +27 -10
  115. package/src/view/overlay/Grid.tsx +187 -30
  116. package/src/view/overlay/OutlineOverlay.tsx +35 -47
  117. package/src/view/overlay/gridConfig.ts +103 -0
  118. package/src/view/shape/Polygon.tsx +12 -49
  119. package/stats.html +1 -1
@@ -20,12 +20,38 @@ 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
+ };
23
48
  Object.defineProperty(exports, "__esModule", { value: true });
24
49
  exports.Grid = void 0;
25
50
  var jsx_runtime_1 = require("preact/jsx-runtime");
26
51
  var compat_1 = require("preact/compat");
27
52
  var lodash_es_1 = require("lodash-es");
28
53
  var __1 = require("../..");
54
+ var gridConfig_1 = require("./gridConfig");
29
55
  var util_1 = require("../../util");
30
56
  var constant_1 = require("../../constant");
31
57
  var Grid = /** @class */ (function (_super) {
@@ -45,21 +71,64 @@ var Grid = /** @class */ (function (_super) {
45
71
  var opacity = visible ? 1 : 0;
46
72
  return ((0, jsx_runtime_1.jsxs)("g", { fill: color, opacity: opacity, children: [(0, jsx_runtime_1.jsx)("circle", { cx: 0, cy: 0, r: radius / 2 }), (0, jsx_runtime_1.jsx)("circle", { cx: 0, cy: size, r: radius / 2 }), (0, jsx_runtime_1.jsx)("circle", { cx: size, cy: 0, r: radius / 2 }), (0, jsx_runtime_1.jsx)("circle", { cx: size, cy: size, r: radius / 2 })] }));
47
73
  };
74
+ // 计算与 size 整除的虚线周期,使边长能被 (dash + gap) 完整分割
75
+ Grid.prototype.getDashArrayForSize = function (dashCfg) {
76
+ var _a;
77
+ // 若提供了直接可用的 pattern,则优先使用
78
+ var direct = (_a = dashCfg === null || dashCfg === void 0 ? void 0 : dashCfg.pattern) === null || _a === void 0 ? void 0 : _a.filter(function (n) { return typeof n === 'number' && n > 0; });
79
+ return (direct === null || direct === void 0 ? void 0 : direct.join(',')) || '2,1';
80
+ };
81
+ // 计算一个周期内的最大加粗索引(作为周期大小)
82
+ Grid.prototype.getPeriod = function (advanced) {
83
+ var list = Array.isArray(advanced === null || advanced === void 0 ? void 0 : advanced.boldIndices)
84
+ ? advanced.boldIndices.filter(function (n) { return typeof n === 'number' && n > 0; })
85
+ : [];
86
+ return list.length ? Math.max.apply(Math, __spreadArray([], __read(list), false)) : 0;
87
+ };
88
+ // 计算加粗线宽,优先使用自定义;否则根据周期与厚度估算
89
+ Grid.prototype.getBoldStrokeWidth = function (advanced, size, thickness, period) {
90
+ if (typeof (advanced === null || advanced === void 0 ? void 0 : advanced.customBoldWidth) === 'number')
91
+ return advanced.customBoldWidth;
92
+ var baseThickness = Math.max(1, thickness !== null && thickness !== void 0 ? thickness : 1);
93
+ var p = Math.max(1, period !== null && period !== void 0 ? period : this.getPeriod(advanced));
94
+ return Math.min(baseThickness, (size * p) / 2) / 2;
95
+ };
96
+ // 渲染 mesh 类型四条边的虚线,减少重复代码
97
+ Grid.prototype.renderMeshEdgeLines = function (size, color, strokeWidth, opacity, dash) {
98
+ var segments = [
99
+ { d: "M 0 0 H ".concat(size) },
100
+ { d: "M 0 ".concat(size, " H ").concat(size) },
101
+ { d: "M 0 0 V ".concat(size) },
102
+ { d: "M ".concat(size, " 0 V ").concat(size) },
103
+ ];
104
+ return ((0, jsx_runtime_1.jsx)("g", { opacity: opacity, fill: "transparent", children: segments.map(function (seg) { return ((0, jsx_runtime_1.jsx)("path", { d: seg.d, stroke: color, strokeWidth: strokeWidth / 2, strokeDasharray: dash, strokeLinecap: "butt", fill: "transparent" })); }) }));
105
+ };
48
106
  // 网格类型为交叉线
49
107
  // todo: 采用背景缩放的方式,实现更好的体验
50
108
  Grid.prototype.renderMesh = function () {
51
- var _a = this.gridOptions, config = _a.config, _b = _a.size, size = _b === void 0 ? 1 : _b, visible = _a.visible;
52
- var _c = config !== null && config !== void 0 ? config : {}, color = _c.color, _d = _c.thickness, thickness = _d === void 0 ? 1 : _d;
109
+ var _a, _b;
110
+ var _c = this.gridOptions, config = _c.config, _d = _c.size, size = _d === void 0 ? 1 : _d, visible = _c.visible, majorBold = _c.majorBold;
111
+ var advanced = (0, gridConfig_1.mergeMajorBoldConfig)(majorBold).config;
112
+ var baseOpacity = advanced.opacity;
113
+ var color = ((_a = config === null || config === void 0 ? void 0 : config.color) !== null && _a !== void 0 ? _a : '#D7DEEB');
114
+ var thickness = ((_b = config === null || config === void 0 ? void 0 : config.thickness) !== null && _b !== void 0 ? _b : 1);
53
115
  // 对于交叉线网格,线的宽度不能大于网格大小的一半
54
116
  var strokeWidth = Math.min(Math.max(1, thickness), size / 2);
55
- var d = "M 0 0 H ".concat(size, " V ").concat(size, " H 0 Z");
56
- var opacity = visible ? 1 : 0;
57
- return ((0, jsx_runtime_1.jsx)("path", { d: d, stroke: color, strokeWidth: strokeWidth / 2, opacity: opacity, fill: "transparent" }));
117
+ var opacity = visible ? baseOpacity : 0;
118
+ // 根据 size 自动计算合适的 dash/gap 周期,使 size 能被 (dash + gap) 整除
119
+ var dash = majorBold === false
120
+ ? undefined
121
+ : this.getDashArrayForSize(advanced.dashArrayConfig);
122
+ return this.renderMeshEdgeLines(size, color, strokeWidth, opacity, dash);
58
123
  };
59
124
  Grid.prototype.render = function () {
60
- var _a = this.props.graphModel, transformModel = _a.transformModel, grid = _a.grid;
125
+ var _this = this;
126
+ var _a, _b, _c;
127
+ var _d = this.props.graphModel, transformModel = _d.transformModel, grid = _d.grid;
61
128
  this.gridOptions = grid;
62
- var _b = this.gridOptions, type = _b.type, _c = _b.size, size = _c === void 0 ? 1 : _c;
129
+ var _e = this.gridOptions, type = _e.type, _f = _e.config, config = _f === void 0 ? {} : _f, _g = _e.size, size = _g === void 0 ? 1 : _g, majorBold = _e.majorBold;
130
+ var showMajorBold = majorBold !== false && !(0, lodash_es_1.isNil)(majorBold);
131
+ var advanced = (0, gridConfig_1.mergeMajorBoldConfig)(majorBold).config;
63
132
  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;
64
133
  var matrixString = [
65
134
  SCALE_X,
@@ -70,10 +139,12 @@ var Grid = /** @class */ (function (_super) {
70
139
  TRANSLATE_Y,
71
140
  ].join(',');
72
141
  var transform = "matrix(".concat(matrixString, ")");
73
- // const transitionStyle = {
74
- // transition: 'all 0.1s ease',
75
- // };
76
- return ((0, jsx_runtime_1.jsx)("div", { className: "lf-grid", children: (0, jsx_runtime_1.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", version: "1.1", width: "100%", height: "100%", children: [(0, jsx_runtime_1.jsx)("defs", { children: (0, jsx_runtime_1.jsxs)("pattern", { id: this.id, patternUnits: "userSpaceOnUse", patternTransform: transform, x: "0", y: "0", width: size, height: size, children: [type === 'dot' && this.renderDot(), type === 'mesh' && this.renderMesh()] }) }), (0, jsx_runtime_1.jsx)("rect", { width: "100%", height: "100%", fill: "url(#".concat(this.id, ")") })] }) }));
142
+ var radius = Math.min(Math.max(2, (_a = config.thickness) !== null && _a !== void 0 ? _a : 1), size / 4);
143
+ var opacity = showMajorBold ? advanced.opacity : 1;
144
+ return ((0, jsx_runtime_1.jsx)("div", { className: "lf-grid", children: (0, jsx_runtime_1.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", version: "1.1", width: "100%", height: "100%", children: [(0, jsx_runtime_1.jsxs)("defs", { children: [(0, jsx_runtime_1.jsxs)("pattern", { id: this.id, patternUnits: "userSpaceOnUse", patternTransform: transform, x: "0", y: "0", width: size, height: size, children: [type === 'dot' && this.renderDot(), type === 'mesh' && this.renderMesh()] }), type === 'dot' && advanced.boldIndices.length ? ((0, jsx_runtime_1.jsx)("pattern", { id: "".concat(this.id, "-dot-major"), patternUnits: "userSpaceOnUse", patternTransform: transform, x: "0", y: "0", width: size * this.getPeriod(advanced), height: size * this.getPeriod(advanced), children: (0, jsx_runtime_1.jsxs)("g", { fill: (_c = (_b = this.gridOptions.config) === null || _b === void 0 ? void 0 : _b.color) !== null && _c !== void 0 ? _c : '#D7DEEB', opacity: this.gridOptions.visible ? opacity : 0, children: [(0, jsx_runtime_1.jsx)("circle", { cx: 0, cy: 0, r: (radius * 1.5) / 2 }), (0, jsx_runtime_1.jsx)("circle", { cx: size * this.getPeriod(advanced), cy: 0, r: (radius * 1.5) / 2 }), (0, jsx_runtime_1.jsx)("circle", { cx: 0, cy: size * this.getPeriod(advanced), r: (radius * 1.5) / 2 }), (0, jsx_runtime_1.jsx)("circle", { cx: size * this.getPeriod(advanced), cy: size * this.getPeriod(advanced), r: (radius * 1.5) / 2 })] }) })) : null, type === 'mesh' && advanced.boldIndices.length ? ((0, jsx_runtime_1.jsx)("pattern", { id: "".concat(this.id, "-major"), patternUnits: "userSpaceOnUse", patternTransform: transform, x: "0", y: "0", width: size * this.getPeriod(advanced), height: size * this.getPeriod(advanced), children: advanced.boldIndices.map(function (i) {
145
+ var _a, _b, _c, _d, _e, _f;
146
+ return ((0, jsx_runtime_1.jsxs)("g", { children: [(0, jsx_runtime_1.jsx)("path", { d: "M ".concat(size * i, " 0 V ").concat(size * _this.getPeriod(advanced)), stroke: (_b = (_a = _this.gridOptions.config) === null || _a === void 0 ? void 0 : _a.color) !== null && _b !== void 0 ? _b : '#D7DEEB', strokeWidth: _this.getBoldStrokeWidth(advanced, size, ((_c = _this.gridOptions.config) !== null && _c !== void 0 ? _c : {}).thickness, _this.getPeriod(advanced)), opacity: _this.gridOptions.visible ? opacity : 0, fill: "transparent" }), (0, jsx_runtime_1.jsx)("path", { d: "M 0 ".concat(size * i, " H ").concat(size * _this.getPeriod(advanced)), stroke: (_e = (_d = _this.gridOptions.config) === null || _d === void 0 ? void 0 : _d.color) !== null && _e !== void 0 ? _e : '#D7DEEB', strokeWidth: _this.getBoldStrokeWidth(advanced, size, ((_f = _this.gridOptions.config) !== null && _f !== void 0 ? _f : {}).thickness, _this.getPeriod(advanced)), opacity: _this.gridOptions.visible ? opacity : 0, fill: "transparent" })] }));
147
+ }) })) : null] }), (0, jsx_runtime_1.jsx)("rect", { width: "100%", height: "100%", fill: "url(#".concat(this.id, ")") }), type === 'dot' && showMajorBold && advanced.boldIndices.length ? ((0, jsx_runtime_1.jsx)("rect", { width: "100%", height: "100%", fill: "url(#".concat(this.id, "-dot-major)") })) : null, type === 'mesh' && showMajorBold && advanced.boldIndices.length ? ((0, jsx_runtime_1.jsx)("rect", { width: "100%", height: "100%", fill: "url(#".concat(this.id, "-major)") })) : null] }) }));
77
148
  };
78
149
  Grid = __decorate([
79
150
  __1.observer
@@ -82,17 +153,8 @@ var Grid = /** @class */ (function (_super) {
82
153
  }(compat_1.Component));
83
154
  exports.Grid = Grid;
84
155
  (function (Grid) {
85
- Grid.defaultProps = {
86
- size: constant_1.DEFAULT_GRID_SIZE,
87
- visible: true,
88
- type: 'dot',
89
- config: {
90
- color: '#ababab',
91
- thickness: 1,
92
- },
93
- };
94
156
  function getGridOptions(options) {
95
- var defaultOptions = (0, lodash_es_1.cloneDeep)(Grid.defaultProps);
157
+ var defaultOptions = (0, lodash_es_1.cloneDeep)(constant_1.defaultGrid);
96
158
  if (typeof options === 'number') {
97
159
  return (0, lodash_es_1.assign)(defaultOptions, { size: options });
98
160
  }
@@ -4,6 +4,7 @@ type IProps = {
4
4
  graphModel: GraphModel;
5
5
  };
6
6
  export declare class OutlineOverlay extends Component<IProps> {
7
+ private renderRectOutline;
7
8
  getNodesOutline(): any;
8
9
  getEdgeOutline(): any;
9
10
  getLineOutline(line: LineEdgeModel): import("preact/compat").JSX.Element;
@@ -44,6 +44,12 @@ var OutlineOverlay = /** @class */ (function (_super) {
44
44
  function OutlineOverlay() {
45
45
  return _super !== null && _super.apply(this, arguments) || this;
46
46
  }
47
+ // 通用渲染函数:根据点集合与样式计算包围盒并返回矩形轮廓
48
+ OutlineOverlay.prototype.renderRectOutline = function (pointsList, style, className, defaultOffsets) {
49
+ var _a = (style || {}), _b = _a.widthOffset, widthOffset = _b === void 0 ? defaultOffsets.widthOffset : _b, _c = _a.heightOffset, heightOffset = _c === void 0 ? defaultOffsets.heightOffset : _c;
50
+ var _d = (0, util_1.getBBoxOfPoints)(pointsList, widthOffset, heightOffset), x = _d.x, y = _d.y, width = _d.width, height = _d.height;
51
+ return ((0, jsx_runtime_1.jsx)(shape_1.Rect, __assign({ className: className, x: x, y: y, width: width, height: height }, style)));
52
+ };
47
53
  // 节点outline
48
54
  OutlineOverlay.prototype.getNodesOutline = function () {
49
55
  var graphModel = this.props.graphModel;
@@ -65,11 +71,8 @@ var OutlineOverlay = /** @class */ (function (_super) {
65
71
  var hoverStyle = style_1.hover;
66
72
  attributes_1 = __assign(__assign({}, attributes_1), hoverStyle);
67
73
  }
68
- nodeOutline.push((0, jsx_runtime_1.jsx)(shape_1.Rect, __assign({ transform: element.transform, className: "lf-outline-node", x: x, y: y,
69
- // width: width + 10,
70
- // height: height + 10,
71
- width: width + 10,
72
- height: height + 10 }, attributes_1)));
74
+ nodeOutline.push((0, jsx_runtime_1.jsx)(shape_1.Rect, __assign({ transform: element.transform, className: "lf-outline-node", x: x, y: y, width: width + 4,
75
+ height: height + 4 }, attributes_1)));
73
76
  }
74
77
  }
75
78
  });
@@ -99,30 +102,28 @@ var OutlineOverlay = /** @class */ (function (_super) {
99
102
  // 直线outline
100
103
  OutlineOverlay.prototype.getLineOutline = function (line) {
101
104
  var startPoint = line.startPoint, endPoint = line.endPoint;
102
- var x = (startPoint.x + endPoint.x) / 2;
103
- var y = (startPoint.y + endPoint.y) / 2;
104
- var width = Math.abs(startPoint.x - endPoint.x) + 10;
105
- var height = Math.abs(startPoint.y - endPoint.y) + 10;
106
105
  var style = line.getOutlineStyle();
107
- return ((0, jsx_runtime_1.jsx)(shape_1.Rect, __assign({ className: "lf-outline-edge", x: x, y: y, width: width, height: height }, style)));
106
+ return this.renderRectOutline([startPoint, endPoint], style, 'lf-outline-edge', { widthOffset: 10, heightOffset: 10 });
108
107
  };
109
108
  // 折线outline
110
109
  OutlineOverlay.prototype.getPolylineOutline = function (polyline) {
111
110
  var points = polyline.points;
112
111
  var pointsList = (0, util_1.points2PointsList)(points);
113
- var bbox = (0, util_1.getBBoxOfPoints)(pointsList, 8);
114
- var x = bbox.x, y = bbox.y, width = bbox.width, height = bbox.height;
115
112
  var style = polyline.getOutlineStyle();
116
- return ((0, jsx_runtime_1.jsx)(shape_1.Rect, __assign({ className: "lf-outline", x: x, y: y, width: width, height: height }, style)));
113
+ return this.renderRectOutline(pointsList, style, 'lf-outline', {
114
+ widthOffset: 8,
115
+ heightOffset: 16,
116
+ });
117
117
  };
118
118
  // 曲线outline
119
119
  OutlineOverlay.prototype.getBezierOutline = function (bezier) {
120
120
  var path = bezier.path;
121
121
  var pointsList = (0, util_1.getBezierPoints)(path);
122
- var bbox = (0, util_1.getBBoxOfPoints)(pointsList, 8);
123
- var x = bbox.x, y = bbox.y, width = bbox.width, height = bbox.height;
124
122
  var style = bezier.getOutlineStyle();
125
- return ((0, jsx_runtime_1.jsx)(shape_1.Rect, __assign({ className: "lf-outline", x: x, y: y, width: width, height: height }, style)));
123
+ return this.renderRectOutline(pointsList, style, 'lf-outline', {
124
+ widthOffset: 8,
125
+ heightOffset: 16,
126
+ });
126
127
  };
127
128
  OutlineOverlay.prototype.render = function () {
128
129
  return ((0, jsx_runtime_1.jsxs)("g", { className: "lf-outline", children: [this.getNodesOutline(), this.getEdgeOutline()] }));
@@ -0,0 +1,46 @@
1
+ /**
2
+ * 网格高级 majorBold 配置。
3
+ *
4
+ * 示例(布尔值):
5
+ * - false:禁用特殊样式,opacity=1,无加粗,无虚线
6
+ * - true:启用默认值,opacity=0.75,每第 5 条线/点加粗/实线,
7
+ * 虚线图案通过 getDashArrayForSize(size) 计算
8
+ *
9
+ * 示例(对象):
10
+ * {
11
+ * opacity: 0.6,
12
+ * boldIndices: [4, 8],
13
+ * dashArrayConfig: { pattern: [4,2,4] },
14
+ * customBoldWidth: 2,
15
+ * }
16
+ */
17
+ export type MajorBoldConfig = {
18
+ /** 默认网格透明度 (0-1) */
19
+ opacity: number;
20
+ /** 一个周期内需要加粗/实线的索引列表 */
21
+ boldIndices: number[];
22
+ /** 虚线样式的计算配置 */
23
+ dashArrayConfig: {
24
+ /** 固定的虚线模式(可选) */
25
+ pattern: number[];
26
+ };
27
+ /** mesh 网格的自定义加粗线宽(可选) */
28
+ customBoldWidth?: number;
29
+ };
30
+ export declare const defaultGridConfig: MajorBoldConfig;
31
+ /**
32
+ * 校验并规范化 GridConfig。
33
+ * - 将 opacity 限制在 [0,1] 范围
34
+ * - boldIndices 过滤为正整数并去重
35
+ */
36
+ export declare function validateGridConfig(cfg: MajorBoldConfig): MajorBoldConfig;
37
+ /**
38
+ * 合并用户行为配置与默认值。
39
+ * - false → 关闭模式:opacity=1,bold=[],关闭虚线
40
+ * - true → 默认模式:采用 defaultGridConfig
41
+ * - object → 自定义模式:校验后使用用户配置
42
+ */
43
+ export declare function mergeMajorBoldConfig(input?: boolean | MajorBoldConfig): {
44
+ mode: 'disabled' | 'default' | 'custom';
45
+ config: MajorBoldConfig;
46
+ };
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __values = (this && this.__values) || function(o) {
14
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
15
+ if (m) return m.call(o);
16
+ if (o && typeof o.length === "number") return {
17
+ next: function () {
18
+ if (o && i >= o.length) o = void 0;
19
+ return { value: o && o[i++], done: !o };
20
+ }
21
+ };
22
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.mergeMajorBoldConfig = exports.validateGridConfig = exports.defaultGridConfig = void 0;
26
+ exports.defaultGridConfig = {
27
+ opacity: 1,
28
+ boldIndices: [5],
29
+ dashArrayConfig: {
30
+ pattern: [2, 1],
31
+ },
32
+ customBoldWidth: 2,
33
+ };
34
+ /**
35
+ * 校验并规范化 GridConfig。
36
+ * - 将 opacity 限制在 [0,1] 范围
37
+ * - boldIndices 过滤为正整数并去重
38
+ */
39
+ function validateGridConfig(cfg) {
40
+ var e_1, _a;
41
+ var _b, _c;
42
+ var opacity = Math.max(0, Math.min(1, (_b = cfg.opacity) !== null && _b !== void 0 ? _b : exports.defaultGridConfig.opacity));
43
+ var boldIndicesSet = new Set();
44
+ var boldRaw = Array.isArray(cfg.boldIndices)
45
+ ? cfg.boldIndices
46
+ : exports.defaultGridConfig.boldIndices;
47
+ try {
48
+ for (var boldRaw_1 = __values(boldRaw), boldRaw_1_1 = boldRaw_1.next(); !boldRaw_1_1.done; boldRaw_1_1 = boldRaw_1.next()) {
49
+ var n = boldRaw_1_1.value;
50
+ if (typeof n === 'number' && Number.isFinite(n) && n > 0) {
51
+ boldIndicesSet.add(Math.floor(n));
52
+ }
53
+ }
54
+ }
55
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
56
+ finally {
57
+ try {
58
+ if (boldRaw_1_1 && !boldRaw_1_1.done && (_a = boldRaw_1.return)) _a.call(boldRaw_1);
59
+ }
60
+ finally { if (e_1) throw e_1.error; }
61
+ }
62
+ var boldIndices = Array.from(boldIndicesSet);
63
+ var pattern = Array.isArray((_c = cfg.dashArrayConfig) === null || _c === void 0 ? void 0 : _c.pattern)
64
+ ? cfg.dashArrayConfig.pattern
65
+ : exports.defaultGridConfig.dashArrayConfig.pattern;
66
+ var dashArrayConfig = {
67
+ pattern: pattern,
68
+ };
69
+ var customBoldWidth = cfg.customBoldWidth;
70
+ return {
71
+ opacity: opacity,
72
+ boldIndices: boldIndices.length
73
+ ? boldIndices
74
+ : exports.defaultGridConfig.boldIndices,
75
+ dashArrayConfig: dashArrayConfig,
76
+ customBoldWidth: customBoldWidth,
77
+ };
78
+ }
79
+ exports.validateGridConfig = validateGridConfig;
80
+ /**
81
+ * 合并用户行为配置与默认值。
82
+ * - false → 关闭模式:opacity=1,bold=[],关闭虚线
83
+ * - true → 默认模式:采用 defaultGridConfig
84
+ * - object → 自定义模式:校验后使用用户配置
85
+ */
86
+ function mergeMajorBoldConfig(input) {
87
+ if (input === false) {
88
+ return {
89
+ mode: 'disabled',
90
+ config: {
91
+ opacity: 1,
92
+ boldIndices: [],
93
+ dashArrayConfig: {
94
+ pattern: [],
95
+ },
96
+ },
97
+ };
98
+ }
99
+ if (input === true || input == null) {
100
+ return { mode: 'default', config: __assign({}, exports.defaultGridConfig) };
101
+ }
102
+ return { mode: 'custom', config: validateGridConfig(input) };
103
+ }
104
+ exports.mergeMajorBoldConfig = mergeMajorBoldConfig;
@@ -7,12 +7,5 @@ export type IPolygonProps = {
7
7
  className?: string;
8
8
  radius?: number;
9
9
  };
10
- /**
11
- * 生成带圆角的多边形路径
12
- * @param points 多边形顶点坐标数组
13
- * @param radius 圆角半径
14
- * @returns SVG 路径字符串
15
- */
16
- export declare function createRoundedPolygonPath(points: any, radius: any): string;
17
10
  export declare function Polygon(props: IPolygonProps): h.JSX.Element;
18
11
  export default Polygon;
@@ -27,50 +27,10 @@ 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 = exports.createRoundedPolygonPath = void 0;
30
+ exports.Polygon = 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
+ var geometry_1 = require("../../util/geometry");
74
34
  function Polygon(props) {
75
35
  var _a = props.points, points = _a === void 0 ? [] : _a, className = props.className, radius = props.radius;
76
36
  var attrs = {
@@ -88,14 +48,22 @@ function Polygon(props) {
88
48
  }
89
49
  });
90
50
  if (className) {
91
- attrs.classNmae = "lf-basic-shape ".concat(className);
51
+ attrs.className = "lf-basic-shape ".concat(className);
92
52
  }
93
53
  else {
94
54
  attrs.className = 'lf-basic-shape';
95
55
  }
96
56
  if (radius) {
97
- var path = createRoundedPolygonPath(points, radius);
98
- attrs.d = path;
57
+ var pointList = points.map(function (point) { return ({ x: point[0], y: point[1] }); });
58
+ var rounded = (0, geometry_1.generateRoundedCorners)(pointList, radius, true);
59
+ var d = rounded.length
60
+ ? "M ".concat(rounded[0].x, " ").concat(rounded[0].y, " ").concat(rounded
61
+ .slice(1)
62
+ .map(function (p) { return "L ".concat(p.x, " ").concat(p.y); })
63
+ .join(' '), " Z")
64
+ : '';
65
+ attrs.d = d;
66
+ delete attrs.points;
99
67
  return (0, jsx_runtime_1.jsx)("path", __assign({}, attrs));
100
68
  }
101
69
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logicflow/core",
3
- "version": "2.2.0-alpha.1",
3
+ "version": "2.2.0-alpha.3",
4
4
  "description": "LogicFlow, help you quickly create flowcharts",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
package/src/LogicFlow.tsx CHANGED
@@ -1832,6 +1832,8 @@ export namespace LogicFlow {
1832
1832
 
1833
1833
  export type OutlineTheme = {
1834
1834
  hover?: CommonTheme
1835
+ widthOffset?: number
1836
+ heightOffset?: number
1835
1837
  } & CommonTheme &
1836
1838
  EdgeAnimation
1837
1839
 
@@ -1871,6 +1873,7 @@ export namespace LogicFlow {
1871
1873
  diamond: PolygonTheme // 菱形样式
1872
1874
  ellipse: EllipseTheme // 椭圆样式
1873
1875
  polygon: PolygonTheme // 多边形样式
1876
+ html: RectTheme // html 节点样式
1874
1877
 
1875
1878
  /**
1876
1879
  * 基础图形线相关主题
@@ -1897,6 +1900,10 @@ export namespace LogicFlow {
1897
1900
  rotateControl: CommonTheme // 节点旋转控制点样式
1898
1901
  resizeControl: CommonTheme // 节点旋转控制点样式
1899
1902
  resizeOutline: CommonTheme // 节点调整大小时的外框样式
1903
+ multiSelect?: {
1904
+ xPadding?: number
1905
+ yPadding?: number
1906
+ }
1900
1907
 
1901
1908
  /**
1902
1909
  * REMIND: 当开启了跳转边的起点和终点(adjustEdgeStartAndEnd:true)后
@@ -1905,12 +1912,15 @@ export namespace LogicFlow {
1905
1912
  */
1906
1913
  edgeAdjust: CircleTheme
1907
1914
  outline: OutlineTheme // 节点选择状态下外侧的选框样式
1915
+ edgeOutline: OutlineTheme // 边选择状态下外侧的选框样式
1908
1916
  edgeAnimation: EdgeAnimation // 边动画样式
1909
1917
 
1910
1918
  // 画布背景
1911
1919
  background?: boolean | Partial<LFOptions.BackgroundConfig>
1912
1920
  grid?: boolean | Partial<Grid.GridOptions>
1913
1921
  }
1922
+
1923
+ export type ThemeMode = 'default' | 'retro' | 'dark' | 'colorful'
1914
1924
  }
1915
1925
 
1916
1926
  // Render or Functions
@@ -1,8 +1,6 @@
1
1
  export const DEFAULT_VISIBLE_SPACE = 200
2
2
  export const ELEMENT_MAX_Z_INDEX = 9999
3
3
 
4
- export const DEFAULT_GRID_SIZE = 10
5
-
6
4
  export enum ElementState {
7
5
  DEFAULT = 1, // 默认显示
8
6
  TEXT_EDIT, // 此元素正在进行文本编辑
@@ -177,3 +175,5 @@ export enum TextMode {
177
175
  TEXT = 'text',
178
176
  LABEL = 'label',
179
177
  }
178
+
179
+ export * from './theme'