@logicflow/extension 1.1.12 → 1.1.15

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.
@@ -4,37 +4,27 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Snapshot = void 0;
7
- var Snapshot = {
8
- pluginName: 'snapshot',
9
- install: function (lf) {
7
+ var Snapshot = /** @class */ (function () {
8
+ function Snapshot(_a) {
10
9
  var _this = this;
10
+ var lf = _a.lf;
11
11
  this.lf = lf;
12
+ this.customCssRules = '';
13
+ this.useGlobalRules = true;
12
14
  /* 下载快照 */
13
15
  lf.getSnapshot = function (fileName, backgroundColor) {
14
- _this.offsetX = Number.MAX_SAFE_INTEGER;
15
- _this.offsetY = Number.MAX_SAFE_INTEGER;
16
- _this.fileName = fileName || "logic-flow." + Date.now() + ".png";
17
- var svgRootElement = _this.getSvgRootElement(lf);
18
- _this.downloadSvg(svgRootElement, _this.fileName, backgroundColor);
16
+ _this.getSnapshot(fileName, backgroundColor);
19
17
  };
20
18
  /* 获取Blob对象,用户图片上传 */
21
- lf.getSnapshotBlob = function (backgroundColor) {
22
- _this.offsetX = Number.MAX_SAFE_INTEGER;
23
- _this.offsetY = Number.MAX_SAFE_INTEGER;
24
- var svgRootElement = _this.getSvgRootElement(lf);
25
- return _this.getBlob(svgRootElement, backgroundColor);
26
- };
19
+ lf.getSnapshotBlob = function (backgroundColor) { return _this.getSnapshotBlob(backgroundColor); };
27
20
  /* 获取Base64对象,用户图片上传 */
28
- lf.getSnapshotBase64 = function (backgroundColor) {
29
- _this.offsetX = Number.MAX_SAFE_INTEGER;
30
- _this.offsetY = Number.MAX_SAFE_INTEGER;
31
- var svgRootElement = _this.getSvgRootElement(lf);
32
- return _this.getBase64(svgRootElement, backgroundColor);
33
- };
34
- },
21
+ lf.getSnapshotBase64 = function (backgroundColor) { return _this.getSnapshotBase64(backgroundColor); };
22
+ }
35
23
  /* 获取svgRoot对象 */
36
- getSvgRootElement: function (lf) {
24
+ Snapshot.prototype.getSvgRootElement = function (lf) {
37
25
  var _this = this;
26
+ this.offsetX = Number.MAX_SAFE_INTEGER;
27
+ this.offsetY = Number.MAX_SAFE_INTEGER;
38
28
  lf.graphModel.nodes.forEach(function (item) {
39
29
  var x = item.x, width = item.width, y = item.y, height = item.height;
40
30
  var offsetX = x - width / 2;
@@ -61,8 +51,8 @@ var Snapshot = {
61
51
  });
62
52
  var svgRootElement = lf.container.querySelector('.lf-canvas-overlay');
63
53
  return svgRootElement;
64
- },
65
- triggerDownload: function (imgURI) {
54
+ };
55
+ Snapshot.prototype.triggerDownload = function (imgURI) {
66
56
  var evt = new MouseEvent('click', {
67
57
  view: window,
68
58
  bubbles: false,
@@ -73,8 +63,8 @@ var Snapshot = {
73
63
  a.setAttribute('href', imgURI);
74
64
  a.setAttribute('target', '_blank');
75
65
  a.dispatchEvent(evt);
76
- },
77
- removeAnchor: function (element) {
66
+ };
67
+ Snapshot.prototype.removeAnchor = function (element) {
78
68
  var childNodes = element.childNodes;
79
69
  var childLength = element.childNodes && element.childNodes.length;
80
70
  for (var i = 0; i < childLength; i++) {
@@ -86,20 +76,22 @@ var Snapshot = {
86
76
  i--;
87
77
  }
88
78
  }
89
- },
79
+ };
90
80
  /* 下载图片 */
91
- downloadSvg: function (svg, fileName, backgroundColor) {
81
+ Snapshot.prototype.getSnapshot = function (fileName, backgroundColor) {
92
82
  var _this = this;
83
+ this.fileName = fileName || "logic-flow." + Date.now() + ".png";
84
+ var svg = this.getSvgRootElement(this.lf);
93
85
  this.getCanvasData(svg, backgroundColor).then(function (canvas) {
94
- var imgURI = canvas
95
- .toDataURL('image/png')
86
+ var imgURI = canvas.toDataURL('image/png')
96
87
  .replace('image/png', 'image/octet-stream');
97
- _this.triggerDownload(imgURI, fileName);
88
+ _this.triggerDownload(imgURI);
98
89
  });
99
- },
90
+ };
100
91
  /* 获取base64对象 */
101
- getBase64: function (svg, backgroundColor) {
92
+ Snapshot.prototype.getSnapshotBase64 = function (backgroundColor) {
102
93
  var _this = this;
94
+ var svg = this.getSvgRootElement(this.lf);
103
95
  return new Promise(function (resolve) {
104
96
  _this.getCanvasData(svg, backgroundColor).then(function (canvas) {
105
97
  var base64 = canvas.toDataURL('image/png');
@@ -107,10 +99,11 @@ var Snapshot = {
107
99
  resolve({ data: base64, width: canvas.width, height: canvas.height });
108
100
  });
109
101
  });
110
- },
102
+ };
111
103
  /* 获取Blob对象 */
112
- getBlob: function (svg, backgroundColor) {
104
+ Snapshot.prototype.getSnapshotBlob = function (backgroundColor) {
113
105
  var _this = this;
106
+ var svg = this.getSvgRootElement(this.lf);
114
107
  return new Promise(function (resolve) {
115
108
  _this.getCanvasData(svg, backgroundColor).then(function (canvas) {
116
109
  canvas.toBlob(function (blob) {
@@ -119,20 +112,25 @@ var Snapshot = {
119
112
  }, 'image/png');
120
113
  });
121
114
  });
122
- },
123
- getClassRules: function () {
115
+ };
116
+ Snapshot.prototype.getClassRules = function () {
124
117
  var rules = '';
125
- var styleSheets = document.styleSheets;
126
- for (var i = 0; i < styleSheets.length; i++) {
127
- var sheet = styleSheets[i];
128
- for (var j = 0; j < sheet.cssRules.length; j++) {
129
- rules += sheet.cssRules[j].cssText;
118
+ if (this.useGlobalRules) {
119
+ var styleSheets = document.styleSheets;
120
+ for (var i = 0; i < styleSheets.length; i++) {
121
+ var sheet = styleSheets[i];
122
+ for (var j = 0; j < sheet.cssRules.length; j++) {
123
+ rules += sheet.cssRules[j].cssText;
124
+ }
130
125
  }
131
126
  }
127
+ if (this.customCssRules) {
128
+ rules += this.customCssRules;
129
+ }
132
130
  return rules;
133
- },
131
+ };
134
132
  // 获取图片生成中中间产物canvas对象,用户转换为其他需要的格式
135
- getCanvasData: function (svg, backgroundColor) {
133
+ Snapshot.prototype.getCanvasData = function (svg, backgroundColor) {
136
134
  var _this = this;
137
135
  var copy = svg.cloneNode(true);
138
136
  var graph = copy.lastChild;
@@ -204,12 +202,15 @@ var Snapshot = {
204
202
  因为svg中存在dom存放在foreignObject元素中
205
203
  SVG图形转成img对象
206
204
  todo: 会导致一些清晰度问题这个需要再解决
205
+ fixme: XMLSerializer的中的css background url不会下载图片
207
206
  */
208
207
  var svg2Img = "data:image/svg+xml;charset=utf-8," + new XMLSerializer().serializeToString(copy);
209
208
  var imgSrc = svg2Img.replace(/\n/g, '').replace(/\t/g, '').replace(/#/g, '%23');
210
209
  img.src = imgSrc;
211
210
  });
212
- },
213
- };
211
+ };
212
+ Snapshot.pluginName = 'snapshot';
213
+ return Snapshot;
214
+ }());
214
215
  exports.Snapshot = Snapshot;
215
216
  exports.default = Snapshot;
@@ -10,17 +10,39 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __read = (this && this.__read) || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o), r, ar = [], e;
17
+ try {
18
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
+ }
20
+ catch (error) { e = { error: error }; }
21
+ finally {
22
+ try {
23
+ if (r && !r.done && (m = i["return"])) m.call(i);
24
+ }
25
+ finally { if (e) throw e.error; }
26
+ }
27
+ return ar;
28
+ };
13
29
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.TurboAdapter = exports.toLogicflowData = exports.toTurboData = void 0;
15
- var TurboType;
16
- (function (TurboType) {
17
- TurboType[TurboType["SEQUENCE_FLOW"] = 1] = "SEQUENCE_FLOW";
18
- TurboType[TurboType["START_EVENT"] = 2] = "START_EVENT";
19
- TurboType[TurboType["END_EVENT"] = 3] = "END_EVENT";
20
- TurboType[TurboType["USER_TASK"] = 4] = "USER_TASK";
30
+ exports.toLogicflowData = exports.toTurboData = void 0;
31
+ var TurboType = {
32
+ SEQUENCE_FLOW: 1,
33
+ START_EVENT: 2,
34
+ END_EVENT: 3,
35
+ USER_TASK: 4,
21
36
  // SERVICE_TASK = 5, 暂不支持
22
- TurboType[TurboType["EXCLUSIVE_GATEWAY"] = 6] = "EXCLUSIVE_GATEWAY";
23
- })(TurboType || (TurboType = {}));
37
+ EXCLUSIVE_GATEWAY: 6,
38
+ };
39
+ var TurboTypeMap = {
40
+ 1: 'bpmn:sequenceFlow',
41
+ 2: 'bpmn:startEvent',
42
+ 3: 'bpmn:endEvent',
43
+ 4: 'bpmn:userTask',
44
+ 6: 'bpmn:exclusiveGateway',
45
+ };
24
46
  // 转换Turbo识别的类型
25
47
  function getTurboType(type) {
26
48
  switch (type) {
@@ -50,11 +72,11 @@ function convertNodeToTurboElement(node) {
50
72
  type: getTurboType(node.type),
51
73
  properties: __assign(__assign({}, properties), { name: (text && text.value) || '', x: x,
52
74
  y: y,
53
- text: text, logicFlowType: type }),
75
+ text: text }),
54
76
  key: id,
55
77
  };
56
78
  }
57
- // 将LogicFlow中的Eedg数据转换为Turbo元素数据
79
+ // 将LogicFlow中的Edge数据转换为Turbo元素数据
58
80
  function convertEdgeToTurboElement(edge) {
59
81
  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;
60
82
  return {
@@ -62,10 +84,7 @@ function convertEdgeToTurboElement(edge) {
62
84
  outgoing: [targetNodeId],
63
85
  type: getTurboType(type),
64
86
  dockers: [],
65
- properties: __assign(__assign({}, properties), { name: (text && text.value) || '', text: text,
66
- startPoint: startPoint,
67
- endPoint: endPoint,
68
- pointsList: pointsList, logicFlowType: type }),
87
+ properties: __assign(__assign({}, properties), { name: (text && text.value) || '', text: text, startPoint: JSON.stringify(startPoint), endPoint: JSON.stringify(endPoint), pointsList: JSON.stringify(text) }),
69
88
  key: id,
70
89
  };
71
90
  }
@@ -91,23 +110,32 @@ function toTurboData(data) {
91
110
  return turboData;
92
111
  }
93
112
  exports.toTurboData = toTurboData;
94
- // 将Turbo元素数据转换为LogicFlow中的Eedg数据
113
+ // 将Turbo元素数据转换为LogicFlow中的Edge数据
95
114
  function convertFlowElementToEdge(element) {
96
- var incoming = element.incoming, outgoing = element.outgoing, properties = element.properties, key = element.key;
97
- var text = properties.text, startPoint = properties.startPoint, endPoint = properties.endPoint, pointsList = properties.pointsList, logicFlowType = properties.logicFlowType;
115
+ var incoming = element.incoming, outgoing = element.outgoing, properties = element.properties, key = element.key, type = element.type;
116
+ var text = properties.text, name = properties.name, startPoint = properties.startPoint, endPoint = properties.endPoint, pointsList = properties.pointsList;
98
117
  var edge = {
99
118
  id: key,
100
- type: logicFlowType,
119
+ type: TurboTypeMap[type],
101
120
  sourceNodeId: incoming[0],
102
121
  targetNodeId: outgoing[0],
103
- text: text,
104
- startPoint: startPoint,
105
- endPoint: endPoint,
106
- pointsList: pointsList,
122
+ text: text || name,
107
123
  properties: {},
108
124
  };
125
+ if (startPoint) {
126
+ // @ts-ignore
127
+ edge.startPoint = JSON.parse(startPoint);
128
+ }
129
+ if (endPoint) {
130
+ // @ts-ignore
131
+ edge.endPoint = JSON.parse(endPoint);
132
+ }
133
+ if (pointsList) {
134
+ // @ts-ignore
135
+ edge.endPoint = JSON.parse(pointsList);
136
+ }
109
137
  // 这种转换方式,在自定义属性中不能与excludeProperties中的属性重名,否则将在转换过程中丢失
110
- var excludeProperties = ['startPoint', 'endPoint', 'pointsList', 'text', 'logicFlowType'];
138
+ var excludeProperties = ['startPoint', 'endPoint', 'pointsList', 'text'];
111
139
  Object.keys(element.properties).forEach(function (property) {
112
140
  if (excludeProperties.indexOf(property) === -1) {
113
141
  edge.properties[property] = element.properties[property];
@@ -117,18 +145,23 @@ function convertFlowElementToEdge(element) {
117
145
  }
118
146
  // 将Turbo元素数据转换为LogicFlow中的Node数据
119
147
  function convertFlowElementToNode(element) {
120
- var properties = element.properties, key = element.key;
121
- var x = properties.x, y = properties.y, text = properties.text, logicFlowType = properties.logicFlowType;
148
+ var properties = element.properties, key = element.key, type = element.type, bounds = element.bounds;
149
+ var x = properties.x, y = properties.y;
150
+ if (x === undefined) {
151
+ var _a = __read(bounds, 2), _b = _a[0], x1 = _b.x, y1 = _b.y, _c = _a[1], x2 = _c.x, y2 = _c.y;
152
+ x = (x1 + x2) / 2;
153
+ y = (y1 + y2) / 2;
154
+ }
122
155
  var node = {
123
156
  id: key,
124
- type: logicFlowType,
157
+ type: TurboTypeMap[type],
125
158
  x: x,
126
159
  y: y,
127
- text: text,
160
+ text: properties.text,
128
161
  properties: {},
129
162
  };
130
163
  // 这种转换方式,在自定义属性中不能与excludeProperties中的属性重名,否则将在转换过程中丢失
131
- var excludeProperties = ['x', 'y', 'text', 'logicFlowType'];
164
+ var excludeProperties = ['x', 'y', 'text'];
132
165
  Object.keys(element.properties).forEach(function (property) {
133
166
  if (excludeProperties.indexOf(property) === -1) {
134
167
  node.properties[property] = element.properties[property];
@@ -156,26 +189,23 @@ function toLogicflowData(data) {
156
189
  return lfData;
157
190
  }
158
191
  exports.toLogicflowData = toLogicflowData;
159
- var TurboAdapter = {
160
- pluginName: 'turboAdapter',
161
- install: function (lf) {
192
+ var TurboAdapter = /** @class */ (function () {
193
+ function TurboAdapter(_a) {
194
+ var lf = _a.lf;
162
195
  lf.adapterIn = this.adapterIn;
163
196
  lf.adapterOut = this.adapterOut;
164
- },
165
- shapeConfigMap: new Map(),
166
- setCustomShape: function (key, val) {
167
- this.shapeConfigMap.set(key, val);
168
- },
169
- adapterOut: function (logicflowData) {
197
+ }
198
+ TurboAdapter.prototype.adapterOut = function (logicflowData) {
170
199
  if (logicflowData) {
171
200
  return toTurboData(logicflowData);
172
201
  }
173
- },
174
- adapterIn: function (turboData) {
202
+ };
203
+ TurboAdapter.prototype.adapterIn = function (turboData) {
175
204
  if (turboData) {
176
205
  return toLogicflowData(turboData);
177
206
  }
178
- },
179
- };
180
- exports.TurboAdapter = TurboAdapter;
207
+ };
208
+ TurboAdapter.pluginName = 'turboAdapter';
209
+ return TurboAdapter;
210
+ }());
181
211
  exports.default = TurboAdapter;
@@ -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, };
@@ -5,11 +5,11 @@ export declare function toLogicflowData(data: any): {
5
5
  nodes: any[];
6
6
  edges: any[];
7
7
  };
8
- declare const TurboAdapter: {
9
- pluginName: string;
10
- install(lf: any): void;
11
- shapeConfigMap: Map<any, any>;
12
- setCustomShape(key: any, val: any): void;
8
+ declare class TurboAdapter {
9
+ static pluginName: string;
10
+ constructor({ lf }: {
11
+ lf: any;
12
+ });
13
13
  adapterOut(logicflowData: any): {
14
14
  flowElementList: any[];
15
15
  };
@@ -17,6 +17,5 @@ declare const TurboAdapter: {
17
17
  nodes: any[];
18
18
  edges: any[];
19
19
  };
20
- };
21
- export { TurboAdapter };
20
+ }
22
21
  export default TurboAdapter;