@logicflow/extension 1.1.12 → 1.2.0-alpha.1

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 (70) hide show
  1. package/cjs/NodeResize/Control/Control.js +8 -8
  2. package/cjs/NodeResize/Control/Util.js +11 -11
  3. package/cjs/bpmn-adapter/index.js +124 -76
  4. package/cjs/bpmn-adapter/json2xml.js +5 -2
  5. package/cjs/bpmn-adapter/xml2json.js +38 -284
  6. package/cjs/components/context-menu/index.js +2 -2
  7. package/cjs/components/menu/index.js +23 -23
  8. package/cjs/components/mini-map/index.js +2 -2
  9. package/cjs/components/selection-select/index.js +5 -5
  10. package/cjs/insert-node-in-polyline/edge.js +4 -4
  11. package/cjs/insert-node-in-polyline/index.js +1 -1
  12. package/cjs/materials/group/GroupNode.js +2 -2
  13. package/cjs/materials/group/index.js +3 -3
  14. package/cjs/tools/auto-layout/index.js +9 -9
  15. package/cjs/tools/snapshot/index.js +47 -46
  16. package/cjs/turbo-adapter/index.js +2 -2
  17. package/es/NodeResize/Control/Control.d.ts +1 -1
  18. package/es/NodeResize/Control/Control.js +9 -9
  19. package/es/NodeResize/Control/Util.d.ts +3 -3
  20. package/es/NodeResize/Control/Util.js +7 -7
  21. package/es/bpmn-adapter/index.d.ts +41 -33
  22. package/es/bpmn-adapter/index.js +124 -76
  23. package/es/bpmn-adapter/json2xml.js +5 -2
  24. package/es/bpmn-adapter/xml2json.js +38 -284
  25. package/es/components/context-menu/index.js +2 -2
  26. package/es/components/menu/index.js +23 -23
  27. package/es/components/mini-map/index.js +2 -2
  28. package/es/components/selection-select/index.d.ts +1 -1
  29. package/es/components/selection-select/index.js +5 -5
  30. package/es/insert-node-in-polyline/edge.d.ts +3 -3
  31. package/es/insert-node-in-polyline/edge.js +3 -3
  32. package/es/insert-node-in-polyline/index.js +2 -2
  33. package/es/materials/group/GroupNode.d.ts +1 -1
  34. package/es/materials/group/GroupNode.js +2 -2
  35. package/es/materials/group/index.d.ts +1 -1
  36. package/es/materials/group/index.js +3 -3
  37. package/es/tools/auto-layout/index.d.ts +2 -2
  38. package/es/tools/auto-layout/index.js +9 -9
  39. package/es/tools/snapshot/index.d.ts +15 -7
  40. package/es/tools/snapshot/index.js +47 -46
  41. package/es/turbo-adapter/index.js +2 -2
  42. package/lib/AutoLayout.js +1 -1
  43. package/lib/BpmnAdapter.js +1 -1
  44. package/lib/BpmnElement.js +1 -1
  45. package/lib/ContextMenu.js +1 -1
  46. package/lib/Control.js +1 -1
  47. package/lib/CurvedEdge.js +1 -1
  48. package/lib/DndPanel.js +1 -1
  49. package/lib/FlowPath.js +1 -1
  50. package/lib/Group.js +1 -1
  51. package/lib/InsertNodeInPolyline.js +1 -1
  52. package/lib/Menu.js +1 -1
  53. package/lib/MiniMap.js +1 -1
  54. package/lib/NodeResize.js +1 -1
  55. package/lib/RectLabelNode.js +1 -1
  56. package/lib/SelectionSelect.js +1 -1
  57. package/lib/Snapshot.js +1 -1
  58. package/lib/TurboAdapter.js +1 -1
  59. package/lib/lfJson2Xml.js +1 -1
  60. package/lib/lfXml2Json.js +1 -1
  61. package/package.json +2 -2
  62. package/types/NodeResize/Control/Control.d.ts +1 -1
  63. package/types/NodeResize/Control/Util.d.ts +3 -3
  64. package/types/bpmn-adapter/index.d.ts +41 -33
  65. package/types/components/selection-select/index.d.ts +1 -1
  66. package/types/insert-node-in-polyline/edge.d.ts +3 -3
  67. package/types/materials/group/GroupNode.d.ts +1 -1
  68. package/types/materials/group/index.d.ts +1 -1
  69. package/types/tools/auto-layout/index.d.ts +2 -2
  70. package/types/tools/snapshot/index.d.ts +15 -7
@@ -174,8 +174,8 @@ var ContextMenu = /** @class */ (function () {
174
174
  var leftTopY = y - node.y / 2 - 20;
175
175
  var rightBottomX = node.x + nodeModel.width + NEXT_X_DISTANCE;
176
176
  var rightBottomY = y + node.y / 2 + 20;
177
- var exsitElements = this.lf.getAreaElement([leftTopX, leftTopY], [rightBottomX, rightBottomY]);
178
- if (exsitElements.length) {
177
+ var existElements = this.lf.getAreaElement([leftTopX, leftTopY], [rightBottomX, rightBottomY]);
178
+ if (existElements.length) {
179
179
  y = y + NEXT_Y_DISTANCE;
180
180
  this.addNode(node, y);
181
181
  return;
@@ -18,10 +18,10 @@ var __spread = (this && this.__spread) || function () {
18
18
  for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
19
19
  return ar;
20
20
  };
21
- var DefalutNodeMenuKey = 'lf:defaultNodeMenu';
22
- var DefalutEdgeMenuKey = 'lf:defaultEdgeMenu';
23
- var DefalutGraphMenuKey = 'lf:defaultGraphMenu';
24
- var DefalutSelectionMenuKey = 'lf:defaultSelectionMenu';
21
+ var DefaultNodeMenuKey = 'lf:defaultNodeMenu';
22
+ var DefaultEdgeMenuKey = 'lf:defaultEdgeMenu';
23
+ var DefaultGraphMenuKey = 'lf:defaultGraphMenu';
24
+ var DefaultSelectionMenuKey = 'lf:defaultSelectionMenu';
25
25
  var Menu = /** @class */ (function () {
26
26
  function Menu(_a) {
27
27
  var _this = this;
@@ -45,7 +45,7 @@ var Menu = /** @class */ (function () {
45
45
  */
46
46
  Menu.prototype.init = function () {
47
47
  var _this = this;
48
- var defalutNodeMenu = [
48
+ var defaultNodeMenu = [
49
49
  {
50
50
  text: '删除',
51
51
  callback: function (node) {
@@ -65,7 +65,7 @@ var Menu = /** @class */ (function () {
65
65
  },
66
66
  },
67
67
  ];
68
- this.menuTypeMap.set(DefalutNodeMenuKey, defalutNodeMenu);
68
+ this.menuTypeMap.set(DefaultNodeMenuKey, defaultNodeMenu);
69
69
  var defaultEdgeMenu = [
70
70
  {
71
71
  text: '删除',
@@ -80,9 +80,9 @@ var Menu = /** @class */ (function () {
80
80
  },
81
81
  },
82
82
  ];
83
- this.menuTypeMap.set(DefalutEdgeMenuKey, defaultEdgeMenu);
84
- this.menuTypeMap.set(DefalutGraphMenuKey, []);
85
- var DefalutSelectionMenu = [
83
+ this.menuTypeMap.set(DefaultEdgeMenuKey, defaultEdgeMenu);
84
+ this.menuTypeMap.set(DefaultGraphMenuKey, []);
85
+ var DefaultSelectionMenu = [
86
86
  {
87
87
  text: '删除',
88
88
  callback: function (elements) {
@@ -92,7 +92,7 @@ var Menu = /** @class */ (function () {
92
92
  },
93
93
  },
94
94
  ];
95
- this.menuTypeMap.set(DefalutSelectionMenuKey, DefalutSelectionMenu);
95
+ this.menuTypeMap.set(DefaultSelectionMenuKey, DefaultSelectionMenu);
96
96
  };
97
97
  Menu.prototype.render = function (lf, container) {
98
98
  var _this = this;
@@ -139,7 +139,7 @@ var Menu = /** @class */ (function () {
139
139
  menuList = typeMenus;
140
140
  }
141
141
  else { // 最后取全局默认
142
- menuList = _this.menuTypeMap.get(DefalutNodeMenuKey);
142
+ menuList = _this.menuTypeMap.get(DefaultNodeMenuKey);
143
143
  }
144
144
  _this.__currentData = data;
145
145
  _this.showMenu(x, y, menuList);
@@ -159,20 +159,20 @@ var Menu = /** @class */ (function () {
159
159
  menuList = typeMenus;
160
160
  }
161
161
  else { // 最后取全局默认
162
- menuList = _this.menuTypeMap.get(DefalutEdgeMenuKey);
162
+ menuList = _this.menuTypeMap.get(DefaultEdgeMenuKey);
163
163
  }
164
164
  _this.__currentData = data;
165
165
  _this.showMenu(x, y, menuList);
166
166
  });
167
167
  this.lf.on('blank:contextmenu', function (_a) {
168
168
  var position = _a.position;
169
- var menuList = _this.menuTypeMap.get(DefalutGraphMenuKey);
169
+ var menuList = _this.menuTypeMap.get(DefaultGraphMenuKey);
170
170
  var _b = position.domOverlayPosition, x = _b.x, y = _b.y;
171
171
  _this.showMenu(x, y, menuList);
172
172
  });
173
173
  this.lf.on('selection:contextmenu', function (_a) {
174
174
  var data = _a.data, position = _a.position;
175
- var menuList = _this.menuTypeMap.get(DefalutSelectionMenuKey);
175
+ var menuList = _this.menuTypeMap.get(DefaultSelectionMenuKey);
176
176
  var _b = position.domOverlayPosition, x = _b.x, y = _b.y;
177
177
  _this.__currentData = data;
178
178
  _this.showMenu(x, y, menuList);
@@ -253,13 +253,13 @@ var Menu = /** @class */ (function () {
253
253
  }
254
254
  // node
255
255
  config.nodeMenu !== undefined
256
- && this.menuTypeMap.set(DefalutNodeMenuKey, config.nodeMenu ? config.nodeMenu : []);
256
+ && this.menuTypeMap.set(DefaultNodeMenuKey, config.nodeMenu ? config.nodeMenu : []);
257
257
  // edge
258
258
  config.edgeMenu !== undefined
259
- && this.menuTypeMap.set(DefalutEdgeMenuKey, config.edgeMenu ? config.edgeMenu : []);
259
+ && this.menuTypeMap.set(DefaultEdgeMenuKey, config.edgeMenu ? config.edgeMenu : []);
260
260
  // graph
261
261
  config.graphMenu !== undefined
262
- && this.menuTypeMap.set(DefalutGraphMenuKey, config.graphMenu ? config.graphMenu : []);
262
+ && this.menuTypeMap.set(DefaultGraphMenuKey, config.graphMenu ? config.graphMenu : []);
263
263
  };
264
264
  // 在默认菜单后面追加菜单项
265
265
  Menu.prototype.addMenuConfig = function (config) {
@@ -268,16 +268,16 @@ var Menu = /** @class */ (function () {
268
268
  }
269
269
  // 追加项时,只支持数组类型,对false不做操作
270
270
  if (Array.isArray(config.nodeMenu)) {
271
- var menuList = this.menuTypeMap.get(DefalutNodeMenuKey);
272
- this.menuTypeMap.set(DefalutNodeMenuKey, menuList.concat(config.nodeMenu));
271
+ var menuList = this.menuTypeMap.get(DefaultNodeMenuKey);
272
+ this.menuTypeMap.set(DefaultNodeMenuKey, menuList.concat(config.nodeMenu));
273
273
  }
274
274
  if (Array.isArray(config.edgeMenu)) {
275
- var menuList = this.menuTypeMap.get(DefalutEdgeMenuKey);
276
- this.menuTypeMap.set(DefalutEdgeMenuKey, menuList.concat(config.edgeMenu));
275
+ var menuList = this.menuTypeMap.get(DefaultEdgeMenuKey);
276
+ this.menuTypeMap.set(DefaultEdgeMenuKey, menuList.concat(config.edgeMenu));
277
277
  }
278
278
  if (Array.isArray(config.graphMenu)) {
279
- var menuList = this.menuTypeMap.get(DefalutGraphMenuKey);
280
- this.menuTypeMap.set(DefalutGraphMenuKey, menuList.concat(config.graphMenu));
279
+ var menuList = this.menuTypeMap.get(DefaultGraphMenuKey);
280
+ this.menuTypeMap.set(DefaultGraphMenuKey, menuList.concat(config.graphMenu));
281
281
  }
282
282
  };
283
283
  /**
@@ -167,11 +167,11 @@ var MiniMap = /** @class */ (function () {
167
167
  nodes.forEach(function (_a) {
168
168
  var x = _a.x, y = _a.y, _b = _a.width, width = _b === void 0 ? 200 : _b, _c = _a.height, height = _c === void 0 ? 200 : _c;
169
169
  var nodeLeft = x - width / 2;
170
- var noderight = x + width / 2;
170
+ var nodeRight = x + width / 2;
171
171
  var nodeTop = y - height / 2;
172
172
  var nodeBottom = y + height / 2;
173
173
  left = nodeLeft < left ? nodeLeft : left;
174
- right = noderight > right ? noderight : right;
174
+ right = nodeRight > right ? nodeRight : right;
175
175
  top = nodeTop < top ? nodeTop : top;
176
176
  bottom = nodeBottom > bottom ? nodeBottom : bottom;
177
177
  });
@@ -12,7 +12,7 @@ declare class SelectionSelect {
12
12
  y: number;
13
13
  };
14
14
  __disabled: boolean;
15
- isDefalutStopMoveGraph: boolean;
15
+ isDefaultStopMoveGraph: boolean;
16
16
  isWholeNode: boolean;
17
17
  isWholeEdge: boolean;
18
18
  static pluginName: string;
@@ -3,7 +3,7 @@ var SelectionSelect = /** @class */ (function () {
3
3
  var _this = this;
4
4
  var lf = _a.lf;
5
5
  this.__disabled = false;
6
- this.isDefalutStopMoveGraph = false;
6
+ this.isDefaultStopMoveGraph = false;
7
7
  this.isWholeNode = true;
8
8
  this.isWholeEdge = true;
9
9
  this.__draw = function (ev) {
@@ -47,9 +47,9 @@ var SelectionSelect = /** @class */ (function () {
47
47
  _this.lf.emit('selection:selected', elements);
48
48
  };
49
49
  this.lf = lf;
50
- // 初始化isDefalutStopMoveGraph取值
50
+ // 初始化isDefaultStopMoveGraph取值
51
51
  var stopMoveGraph = lf.getEditConfig().stopMoveGraph;
52
- this.isDefalutStopMoveGraph = stopMoveGraph;
52
+ this.isDefaultStopMoveGraph = stopMoveGraph;
53
53
  lf.openSelectionSelect = function () {
54
54
  _this.openSelectionSelect();
55
55
  };
@@ -97,7 +97,7 @@ var SelectionSelect = /** @class */ (function () {
97
97
  SelectionSelect.prototype.openSelectionSelect = function () {
98
98
  var stopMoveGraph = this.lf.getEditConfig().stopMoveGraph;
99
99
  if (!stopMoveGraph) {
100
- this.isDefalutStopMoveGraph = false;
100
+ this.isDefaultStopMoveGraph = false;
101
101
  this.lf.updateEditConfig({
102
102
  stopMoveGraph: true,
103
103
  });
@@ -108,7 +108,7 @@ var SelectionSelect = /** @class */ (function () {
108
108
  * 关闭选区
109
109
  */
110
110
  SelectionSelect.prototype.closeSelectionSelect = function () {
111
- if (!this.isDefalutStopMoveGraph) {
111
+ if (!this.isDefaultStopMoveGraph) {
112
112
  this.lf.updateEditConfig({
113
113
  stopMoveGraph: false,
114
114
  });
@@ -1,6 +1,6 @@
1
1
  import { Point, PolylineEdgeModel, BaseNodeModel } from '@logicflow/core';
2
2
  export declare const isInSegment: (point: any, start: any, end: any) => boolean;
3
- export declare const corssPointInSegement: (node: BaseNodeModel, start: Point, end: Point) => {
3
+ export declare const crossPointInSegment: (node: BaseNodeModel, start: Point, end: Point) => {
4
4
  startCrossPoint: {
5
5
  x: number;
6
6
  y: number;
@@ -10,12 +10,12 @@ export declare const corssPointInSegement: (node: BaseNodeModel, start: Point, e
10
10
  y: number;
11
11
  };
12
12
  };
13
- interface SegementCross {
13
+ interface SegmentCross {
14
14
  crossIndex: number;
15
15
  crossPoints: {
16
16
  startCrossPoint: Point;
17
17
  endCrossPoint: Point;
18
18
  };
19
19
  }
20
- export declare const isNodeInSegement: (node: BaseNodeModel, polyline: PolylineEdgeModel) => SegementCross;
20
+ export declare const isNodeInSegment: (node: BaseNodeModel, polyline: PolylineEdgeModel) => SegmentCross;
21
21
  export {};
@@ -42,7 +42,7 @@ var segmentDirection = function (start, end) {
42
42
  return direction;
43
43
  };
44
44
  // 节点是够在线段内,求出节点与线段的交点
45
- export var corssPointInSegement = function (node, start, end) {
45
+ export var crossPointInSegment = function (node, start, end) {
46
46
  var bBox = getNodeBBox(node);
47
47
  var direction = segmentDirection(start, end);
48
48
  var maxX = Math.max(start.x, end.x);
@@ -83,12 +83,12 @@ export var corssPointInSegement = function (node, start, end) {
83
83
  };
84
84
  // 节点是否在线段内
85
85
  // eslint-disable-next-line max-len
86
- export var isNodeInSegement = function (node, polyline) {
86
+ export var isNodeInSegment = function (node, polyline) {
87
87
  var x = node.x, y = node.y;
88
88
  var pointsList = polyline.pointsList;
89
89
  for (var i = 0; i < pointsList.length - 1; i++) {
90
90
  if (isInSegment({ x: x, y: y }, pointsList[i], pointsList[i + 1])) {
91
- var bBoxCross = corssPointInSegement(node, pointsList[i], pointsList[i + 1]);
91
+ var bBoxCross = crossPointInSegment(node, pointsList[i], pointsList[i + 1]);
92
92
  if (bBoxCross) {
93
93
  return {
94
94
  crossIndex: i + 1,
@@ -18,7 +18,7 @@ var __spread = (this && this.__spread) || function () {
18
18
  for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
19
19
  return ar;
20
20
  };
21
- import { isNodeInSegement } from './edge';
21
+ import { isNodeInSegment } from './edge';
22
22
  var InsertNodeInPolyline = /** @class */ (function () {
23
23
  function InsertNodeInPolyline(_a) {
24
24
  var lf = _a.lf;
@@ -59,7 +59,7 @@ var InsertNodeInPolyline = /** @class */ (function () {
59
59
  var nodeModel = this._lf.getNodeModelById(nodeData.id);
60
60
  for (var i = 0; i < edges.length; i++) {
61
61
  // eslint-disable-next-line max-len
62
- var _a = isNodeInSegement(nodeModel, edges[i]), crossIndex = _a.crossIndex, crossPoints = _a.crossPoints;
62
+ var _a = isNodeInSegment(nodeModel, edges[i]), crossIndex = _a.crossIndex, crossPoints = _a.crossPoints;
63
63
  if (crossIndex >= 0) {
64
64
  var _b = edges[i], sourceNodeId = _b.sourceNodeId, targetNodeId = _b.targetNodeId, id = _b.id, type = _b.type, pointsList = _b.pointsList;
65
65
  this._lf.addEdge({
@@ -101,7 +101,7 @@ declare class GroupNodeModel extends RectResize.model {
101
101
  }
102
102
  declare class GroupNode extends RectResize.view {
103
103
  getControlGroup(): h.JSX.Element;
104
- getAddedableShape(): import("preact").VNode<any>;
104
+ getAddAbleShape(): import("preact").VNode<any>;
105
105
  getFoldIcon(): import("preact").VNode<any>;
106
106
  getResizeShape(): import("preact").VNode<any>;
107
107
  }
@@ -293,7 +293,7 @@ var GroupNode = /** @class */ (function (_super) {
293
293
  var _a = this.props.model, resizable = _a.resizable, properties = _a.properties;
294
294
  return resizable && !properties.isFolded ? _super.prototype.getControlGroup.call(this) : null;
295
295
  };
296
- GroupNode.prototype.getAddedableShape = function () {
296
+ GroupNode.prototype.getAddAbleShape = function () {
297
297
  var _a = this.props.model, width = _a.width, height = _a.height, x = _a.x, y = _a.y, radius = _a.radius, properties = _a.properties;
298
298
  if (!properties.groupAddable)
299
299
  return null;
@@ -339,7 +339,7 @@ var GroupNode = /** @class */ (function (_super) {
339
339
  };
340
340
  GroupNode.prototype.getResizeShape = function () {
341
341
  return h('g', {}, [
342
- this.getAddedableShape(),
342
+ this.getAddAbleShape(),
343
343
  _super.prototype.getResizeShape.call(this),
344
344
  this.getFoldIcon(),
345
345
  ]);
@@ -17,7 +17,7 @@ declare class Group {
17
17
  lf: any;
18
18
  });
19
19
  graphRendered: (data: any) => void;
20
- appendNodeToGrop: ({ data }: {
20
+ appendNodeToGroup: ({ data }: {
21
21
  data: any;
22
22
  }) => void;
23
23
  deleteGroupChild: ({ data }: {
@@ -36,7 +36,7 @@ var Group = /** @class */ (function () {
36
36
  });
37
37
  }
38
38
  };
39
- this.appendNodeToGrop = function (_a) {
39
+ this.appendNodeToGroup = function (_a) {
40
40
  var data = _a.data;
41
41
  // 如果这个节点之前已经在group中了,则将其从之前的group中移除
42
42
  var preGroupId = _this.nodeGroupMap.get(data.id);
@@ -110,9 +110,9 @@ var Group = /** @class */ (function () {
110
110
  return true;
111
111
  });
112
112
  lf.graphModel.group = this;
113
- lf.on('node:add', this.appendNodeToGrop);
113
+ lf.on('node:add', this.appendNodeToGroup);
114
114
  lf.on('node:delete', this.deleteGroupChild);
115
- lf.on('node:drop', this.appendNodeToGrop);
115
+ lf.on('node:drop', this.appendNodeToGroup);
116
116
  lf.on('node:dnd-drag', this.setActiveGroup);
117
117
  lf.on('node:drag', this.setActiveGroup);
118
118
  lf.on('graph:rendered', this.graphRendered);
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * 自动布局插件
3
- * 依赖flowpath插件
3
+ * 依赖flow-path插件
4
4
  * 未完善
5
5
  */
6
6
  import LogicFlow from '@logicflow/core';
@@ -26,7 +26,7 @@ declare class AutoLayout {
26
26
  * source一定在target左边。
27
27
  * 1. 如果source和target在同一x, y坐标内容。
28
28
  * 2. 如果source在target左上方。
29
- * 3. 如果souce在target左下方。
29
+ * 3. 如果source在target左下方。
30
30
  */
31
31
  private getRelativePosition;
32
32
  /**
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * 自动布局插件
3
- * 依赖flowpath插件
3
+ * 依赖flow-path插件
4
4
  * 未完善
5
5
  */
6
6
  var __assign = (this && this.__assign) || function () {
@@ -138,7 +138,7 @@ var AutoLayout = /** @class */ (function () {
138
138
  var target = this.newNodeMap.get(targetNodeId);
139
139
  var _a = this.getShape(sourceNodeId), width = _a.width, height = _a.height;
140
140
  var _b = this.getShape(targetNodeId), targetWidth = _b.width, targetHeight = _b.height;
141
- var postionType = this.getRelativePosition(source, target);
141
+ var positionType = this.getRelativePosition(source, target);
142
142
  var startPoint = {
143
143
  x: source.x,
144
144
  y: source.y,
@@ -147,7 +147,7 @@ var AutoLayout = /** @class */ (function () {
147
147
  x: target.x,
148
148
  y: target.y,
149
149
  };
150
- switch (postionType) {
150
+ switch (positionType) {
151
151
  case POSITION_TYPE.LEFT:
152
152
  startPoint.x = source.x + width / 2;
153
153
  endPoint.x = target.x - targetWidth / 2;
@@ -173,22 +173,22 @@ var AutoLayout = /** @class */ (function () {
173
173
  * source一定在target左边。
174
174
  * 1. 如果source和target在同一x, y坐标内容。
175
175
  * 2. 如果source在target左上方。
176
- * 3. 如果souce在target左下方。
176
+ * 3. 如果source在target左下方。
177
177
  */
178
178
  AutoLayout.prototype.getRelativePosition = function (source, target) {
179
179
  var y = source.y;
180
180
  var y1 = target.y;
181
- var postionType;
181
+ var positionType;
182
182
  if (y < y1) {
183
- postionType = -1;
183
+ positionType = -1;
184
184
  }
185
185
  else if (y === y1) {
186
- postionType = 0;
186
+ positionType = 0;
187
187
  }
188
188
  else {
189
- postionType = 1;
189
+ positionType = 1;
190
190
  }
191
- return postionType;
191
+ return positionType;
192
192
  };
193
193
  /**
194
194
  * 获取边节点图形的宽高。
@@ -1,17 +1,25 @@
1
1
  /**
2
2
  * 快照插件,生成视图
3
3
  */
4
- declare const Snapshot: {
5
- pluginName: string;
6
- install(lf: any): void;
4
+ declare class Snapshot {
5
+ static pluginName: string;
6
+ lf: any;
7
+ offsetX: number;
8
+ offsetY: number;
9
+ fileName: string;
10
+ customCssRules: string;
11
+ useGlobalRules: boolean;
12
+ constructor({ lf }: {
13
+ lf: any;
14
+ });
7
15
  getSvgRootElement(lf: any): any;
8
16
  triggerDownload(imgURI: string): void;
9
17
  removeAnchor(element: any): void;
10
- downloadSvg(svg: SVGGraphicsElement, fileName: string, backgroundColor: string): void;
11
- getBase64(svg: SVGGraphicsElement, backgroundColor: string): Promise<unknown>;
12
- getBlob(svg: SVGGraphicsElement, backgroundColor: string): Promise<unknown>;
18
+ getSnapshot(fileName: string, backgroundColor: string): void;
19
+ getSnapshotBase64(backgroundColor: string): Promise<unknown>;
20
+ getSnapshotBlob(backgroundColor: string): Promise<unknown>;
13
21
  getClassRules(): string;
14
22
  getCanvasData(svg: SVGGraphicsElement, backgroundColor: string): Promise<unknown>;
15
- };
23
+ }
16
24
  export default Snapshot;
17
25
  export { Snapshot, };
@@ -1,37 +1,27 @@
1
1
  /**
2
2
  * 快照插件,生成视图
3
3
  */
4
- var Snapshot = {
5
- pluginName: 'snapshot',
6
- install: function (lf) {
4
+ var Snapshot = /** @class */ (function () {
5
+ function Snapshot(_a) {
7
6
  var _this = this;
7
+ var lf = _a.lf;
8
8
  this.lf = lf;
9
+ this.customCssRules = '';
10
+ this.useGlobalRules = true;
9
11
  /* 下载快照 */
10
12
  lf.getSnapshot = function (fileName, backgroundColor) {
11
- _this.offsetX = Number.MAX_SAFE_INTEGER;
12
- _this.offsetY = Number.MAX_SAFE_INTEGER;
13
- _this.fileName = fileName || "logic-flow." + Date.now() + ".png";
14
- var svgRootElement = _this.getSvgRootElement(lf);
15
- _this.downloadSvg(svgRootElement, _this.fileName, backgroundColor);
13
+ _this.getSnapshot(fileName, backgroundColor);
16
14
  };
17
15
  /* 获取Blob对象,用户图片上传 */
18
- lf.getSnapshotBlob = function (backgroundColor) {
19
- _this.offsetX = Number.MAX_SAFE_INTEGER;
20
- _this.offsetY = Number.MAX_SAFE_INTEGER;
21
- var svgRootElement = _this.getSvgRootElement(lf);
22
- return _this.getBlob(svgRootElement, backgroundColor);
23
- };
16
+ lf.getSnapshotBlob = function (backgroundColor) { return _this.getSnapshotBlob(backgroundColor); };
24
17
  /* 获取Base64对象,用户图片上传 */
25
- lf.getSnapshotBase64 = function (backgroundColor) {
26
- _this.offsetX = Number.MAX_SAFE_INTEGER;
27
- _this.offsetY = Number.MAX_SAFE_INTEGER;
28
- var svgRootElement = _this.getSvgRootElement(lf);
29
- return _this.getBase64(svgRootElement, backgroundColor);
30
- };
31
- },
18
+ lf.getSnapshotBase64 = function (backgroundColor) { return _this.getSnapshotBase64(backgroundColor); };
19
+ }
32
20
  /* 获取svgRoot对象 */
33
- getSvgRootElement: function (lf) {
21
+ Snapshot.prototype.getSvgRootElement = function (lf) {
34
22
  var _this = this;
23
+ this.offsetX = Number.MAX_SAFE_INTEGER;
24
+ this.offsetY = Number.MAX_SAFE_INTEGER;
35
25
  lf.graphModel.nodes.forEach(function (item) {
36
26
  var x = item.x, width = item.width, y = item.y, height = item.height;
37
27
  var offsetX = x - width / 2;
@@ -58,8 +48,8 @@ var Snapshot = {
58
48
  });
59
49
  var svgRootElement = lf.container.querySelector('.lf-canvas-overlay');
60
50
  return svgRootElement;
61
- },
62
- triggerDownload: function (imgURI) {
51
+ };
52
+ Snapshot.prototype.triggerDownload = function (imgURI) {
63
53
  var evt = new MouseEvent('click', {
64
54
  view: window,
65
55
  bubbles: false,
@@ -70,8 +60,8 @@ var Snapshot = {
70
60
  a.setAttribute('href', imgURI);
71
61
  a.setAttribute('target', '_blank');
72
62
  a.dispatchEvent(evt);
73
- },
74
- removeAnchor: function (element) {
63
+ };
64
+ Snapshot.prototype.removeAnchor = function (element) {
75
65
  var childNodes = element.childNodes;
76
66
  var childLength = element.childNodes && element.childNodes.length;
77
67
  for (var i = 0; i < childLength; i++) {
@@ -83,20 +73,22 @@ var Snapshot = {
83
73
  i--;
84
74
  }
85
75
  }
86
- },
76
+ };
87
77
  /* 下载图片 */
88
- downloadSvg: function (svg, fileName, backgroundColor) {
78
+ Snapshot.prototype.getSnapshot = function (fileName, backgroundColor) {
89
79
  var _this = this;
80
+ this.fileName = fileName || "logic-flow." + Date.now() + ".png";
81
+ var svg = this.getSvgRootElement(this.lf);
90
82
  this.getCanvasData(svg, backgroundColor).then(function (canvas) {
91
- var imgURI = canvas
92
- .toDataURL('image/png')
83
+ var imgURI = canvas.toDataURL('image/png')
93
84
  .replace('image/png', 'image/octet-stream');
94
- _this.triggerDownload(imgURI, fileName);
85
+ _this.triggerDownload(imgURI);
95
86
  });
96
- },
87
+ };
97
88
  /* 获取base64对象 */
98
- getBase64: function (svg, backgroundColor) {
89
+ Snapshot.prototype.getSnapshotBase64 = function (backgroundColor) {
99
90
  var _this = this;
91
+ var svg = this.getSvgRootElement(this.lf);
100
92
  return new Promise(function (resolve) {
101
93
  _this.getCanvasData(svg, backgroundColor).then(function (canvas) {
102
94
  var base64 = canvas.toDataURL('image/png');
@@ -104,10 +96,11 @@ var Snapshot = {
104
96
  resolve({ data: base64, width: canvas.width, height: canvas.height });
105
97
  });
106
98
  });
107
- },
99
+ };
108
100
  /* 获取Blob对象 */
109
- getBlob: function (svg, backgroundColor) {
101
+ Snapshot.prototype.getSnapshotBlob = function (backgroundColor) {
110
102
  var _this = this;
103
+ var svg = this.getSvgRootElement(this.lf);
111
104
  return new Promise(function (resolve) {
112
105
  _this.getCanvasData(svg, backgroundColor).then(function (canvas) {
113
106
  canvas.toBlob(function (blob) {
@@ -116,20 +109,25 @@ var Snapshot = {
116
109
  }, 'image/png');
117
110
  });
118
111
  });
119
- },
120
- getClassRules: function () {
112
+ };
113
+ Snapshot.prototype.getClassRules = function () {
121
114
  var rules = '';
122
- var styleSheets = document.styleSheets;
123
- for (var i = 0; i < styleSheets.length; i++) {
124
- var sheet = styleSheets[i];
125
- for (var j = 0; j < sheet.cssRules.length; j++) {
126
- rules += sheet.cssRules[j].cssText;
115
+ if (this.useGlobalRules) {
116
+ var styleSheets = document.styleSheets;
117
+ for (var i = 0; i < styleSheets.length; i++) {
118
+ var sheet = styleSheets[i];
119
+ for (var j = 0; j < sheet.cssRules.length; j++) {
120
+ rules += sheet.cssRules[j].cssText;
121
+ }
127
122
  }
128
123
  }
124
+ if (this.customCssRules) {
125
+ rules += this.customCssRules;
126
+ }
129
127
  return rules;
130
- },
128
+ };
131
129
  // 获取图片生成中中间产物canvas对象,用户转换为其他需要的格式
132
- getCanvasData: function (svg, backgroundColor) {
130
+ Snapshot.prototype.getCanvasData = function (svg, backgroundColor) {
133
131
  var _this = this;
134
132
  var copy = svg.cloneNode(true);
135
133
  var graph = copy.lastChild;
@@ -201,12 +199,15 @@ var Snapshot = {
201
199
  因为svg中存在dom存放在foreignObject元素中
202
200
  SVG图形转成img对象
203
201
  todo: 会导致一些清晰度问题这个需要再解决
202
+ fixme: XMLSerializer的中的css background url不会下载图片
204
203
  */
205
204
  var svg2Img = "data:image/svg+xml;charset=utf-8," + new XMLSerializer().serializeToString(copy);
206
205
  var imgSrc = svg2Img.replace(/\n/g, '').replace(/\t/g, '').replace(/#/g, '%23');
207
206
  img.src = imgSrc;
208
207
  });
209
- },
210
- };
208
+ };
209
+ Snapshot.pluginName = 'snapshot';
210
+ return Snapshot;
211
+ }());
211
212
  export default Snapshot;
212
213
  export { Snapshot, };
@@ -51,7 +51,7 @@ function convertNodeToTurboElement(node) {
51
51
  key: id,
52
52
  };
53
53
  }
54
- // 将LogicFlow中的Eedg数据转换为Turbo元素数据
54
+ // 将LogicFlow中的Edge数据转换为Turbo元素数据
55
55
  function convertEdgeToTurboElement(edge) {
56
56
  var id = edge.id, type = edge.type, sourceNodeId = edge.sourceNodeId, targetNodeId = edge.targetNodeId, startPoint = edge.startPoint, endPoint = edge.endPoint, pointsList = edge.pointsList, _a = edge.text, text = _a === void 0 ? '' : _a, properties = edge.properties;
57
57
  return {
@@ -87,7 +87,7 @@ export function toTurboData(data) {
87
87
  });
88
88
  return turboData;
89
89
  }
90
- // 将Turbo元素数据转换为LogicFlow中的Eedg数据
90
+ // 将Turbo元素数据转换为LogicFlow中的Edge数据
91
91
  function convertFlowElementToEdge(element) {
92
92
  var incoming = element.incoming, outgoing = element.outgoing, properties = element.properties, key = element.key;
93
93
  var text = properties.text, startPoint = properties.startPoint, endPoint = properties.endPoint, pointsList = properties.pointsList, logicFlowType = properties.logicFlowType;