@logicflow/extension 1.2.6 → 1.2.7

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.
@@ -1,24 +1,25 @@
1
1
  // @ts-nocheck
2
- // ========================================================================
3
- // XML.ObjTree -- XML source code from/to JavaScript object like E4X
4
- // ========================================================================
2
+ // ========================================================================
3
+ // XML.ObjTree -- XML source code from/to JavaScript object like E4X
4
+ // ========================================================================
5
5
  var XML = function () { };
6
- // constructor
6
+ // constructor
7
7
  XML.ObjTree = function () {
8
+ // @ts-ignore
8
9
  return this;
9
10
  };
10
- // class variables
11
- XML.ObjTree.VERSION = "0.23";
12
- // object prototype
11
+ // class variables
12
+ XML.ObjTree.VERSION = '0.23';
13
+ // object prototype
13
14
  XML.ObjTree.prototype.xmlDecl = '<?xml version="1.0" encoding="UTF-8" ?>\n';
14
15
  XML.ObjTree.prototype.attr_prefix = '-';
15
- // method: parseXML( xmlsource )
16
+ // method: parseXML( xmlsource )
16
17
  XML.ObjTree.prototype.parseXML = function (xml) {
17
18
  var root;
18
19
  if (window.DOMParser) {
19
20
  var xmldom = new DOMParser();
20
- // xmldom.async = false; // DOMParser is always sync-mode
21
- var dom = xmldom.parseFromString(xml, "application/xml");
21
+ // xmldom.async = false; // DOMParser is always sync-mode
22
+ var dom = xmldom.parseFromString(xml, 'application/xml');
22
23
  if (!dom)
23
24
  return;
24
25
  root = dom.documentElement;
@@ -33,24 +34,24 @@ XML.ObjTree.prototype.parseXML = function (xml) {
33
34
  return;
34
35
  return this.parseDOM(root);
35
36
  };
36
- // method: parseHTTP( url, options, callback )
37
+ // method: parseHTTP( url, options, callback )
37
38
  XML.ObjTree.prototype.parseHTTP = function (url, options, callback) {
38
39
  var myOpt = {};
39
40
  for (var key in options) {
40
- myOpt[key] = options[key]; // copy object
41
+ myOpt[key] = options[key]; // copy object
41
42
  }
42
43
  if (!myOpt.method) {
43
- if (typeof (myOpt.postBody) == "undefined" &&
44
- typeof (myOpt.postbody) == "undefined" &&
45
- typeof (myOpt.parameters) == "undefined") {
46
- myOpt.method = "get";
44
+ if (typeof myOpt.postBody == 'undefined' &&
45
+ typeof myOpt.postbody == 'undefined' &&
46
+ typeof myOpt.parameters == 'undefined') {
47
+ myOpt.method = 'get';
47
48
  }
48
49
  else {
49
- myOpt.method = "post";
50
+ myOpt.method = 'post';
50
51
  }
51
52
  }
52
53
  if (callback) {
53
- myOpt.asynchronous = true; // async-mode
54
+ myOpt.asynchronous = true; // async-mode
54
55
  var __this = this;
55
56
  var __func = callback;
56
57
  var __save = myOpt.onComplete;
@@ -65,16 +66,16 @@ XML.ObjTree.prototype.parseHTTP = function (url, options, callback) {
65
66
  };
66
67
  }
67
68
  else {
68
- myOpt.asynchronous = false; // sync-mode
69
+ myOpt.asynchronous = false; // sync-mode
69
70
  }
70
71
  var trans;
71
- if (typeof (HTTP) != "undefined" && HTTP.Request) {
72
+ if (typeof HTTP != 'undefined' && HTTP.Request) {
72
73
  myOpt.uri = url;
73
74
  var req = new HTTP.Request(myOpt);
74
75
  if (req)
75
76
  trans = req.transport;
76
77
  }
77
- else if (typeof (Ajax) != "undefined" && Ajax.Request) {
78
+ else if (typeof Ajax != 'undefined' && Ajax.Request) {
78
79
  var req = new Ajax.Request(url, myOpt);
79
80
  if (req)
80
81
  trans = req.transport;
@@ -94,23 +95,24 @@ XML.ObjTree.prototype.parseDOM = function (root) {
94
95
  this.__force_array[this.force_array[i]] = 1;
95
96
  }
96
97
  }
97
- var json = this.parseElement(root); // parse root node
98
+ var json = this.parseElement(root); // parse root node
98
99
  if (this.__force_array[root.nodeName]) {
99
100
  json = [json];
100
101
  }
101
- if (root.nodeType != 11) { // DOCUMENT_FRAGMENT_NODE
102
+ if (root.nodeType != 11) {
103
+ // DOCUMENT_FRAGMENT_NODE
102
104
  var tmp = {};
103
- tmp[root.nodeName] = json; // root nodeName
105
+ tmp[root.nodeName] = json; // root nodeName
104
106
  json = tmp;
105
107
  }
106
- return json["LogicFlow"];
108
+ return json;
107
109
  };
108
- // method: parseElement( element )
110
+ // method: parseElement( element )
109
111
  /**
110
112
  * @reference node type reference https://www.w3schools.com/xml/dom_nodetype.asp
111
113
  */
112
114
  XML.ObjTree.prototype.parseElement = function (elem) {
113
- // PROCESSING_INSTRUCTION_NODE
115
+ // PROCESSING_INSTRUCTION_NODE
114
116
  if (elem.nodeType == 7) {
115
117
  return;
116
118
  }
@@ -118,7 +120,7 @@ XML.ObjTree.prototype.parseElement = function (elem) {
118
120
  if (elem.nodeType == 3 || elem.nodeType == 4 || elem.nodeType == 8) {
119
121
  var bool = elem.nodeValue.match(/[^\x00-\x20]/);
120
122
  if (bool == null)
121
- return; // ignore white spaces
123
+ return; // ignore white spaces
122
124
  return elem.nodeValue;
123
125
  }
124
126
  var retVal = null;
@@ -127,7 +129,7 @@ XML.ObjTree.prototype.parseElement = function (elem) {
127
129
  retVal = {};
128
130
  for (var i = 0; i < elem.attributes.length; i++) {
129
131
  var key = elem.attributes[i].nodeName;
130
- if (typeof key != "string")
132
+ if (typeof key != 'string')
131
133
  continue;
132
134
  var val = elem.attributes[i].nodeValue;
133
135
  try {
@@ -139,17 +141,17 @@ XML.ObjTree.prototype.parseElement = function (elem) {
139
141
  if (!val)
140
142
  continue;
141
143
  key = this.attr_prefix + key;
142
- if (typeof cnt[key] == "undefined")
144
+ if (typeof cnt[key] == 'undefined')
143
145
  cnt[key] = 0;
144
146
  cnt[key]++;
145
147
  this.addNode(retVal, key, cnt[key], val);
146
148
  }
147
149
  }
148
- // parse child nodes (recursive)
150
+ // parse child nodes (recursive)
149
151
  if (elem.childNodes && elem.childNodes.length) {
150
152
  var textOnly = true;
151
153
  if (retVal)
152
- textOnly = false; // some attributes exists
154
+ textOnly = false; // some attributes exists
153
155
  for (var i = 0; i < elem.childNodes.length && textOnly; i++) {
154
156
  var nType = elem.childNodes[i].nodeType;
155
157
  if (nType == 3 || nType == 4 || nType == 8)
@@ -158,7 +160,7 @@ XML.ObjTree.prototype.parseElement = function (elem) {
158
160
  }
159
161
  if (textOnly) {
160
162
  if (!retVal)
161
- retVal = "";
163
+ retVal = '';
162
164
  for (var i = 0; i < elem.childNodes.length; i++) {
163
165
  retVal += elem.childNodes[i].nodeValue;
164
166
  }
@@ -168,12 +170,12 @@ XML.ObjTree.prototype.parseElement = function (elem) {
168
170
  retVal = {};
169
171
  for (var i = 0; i < elem.childNodes.length; i++) {
170
172
  var key = elem.childNodes[i].nodeName;
171
- if (typeof (key) != "string")
173
+ if (typeof key != 'string')
172
174
  continue;
173
175
  var val = this.parseElement(elem.childNodes[i]);
174
176
  if (!val)
175
177
  continue;
176
- if (typeof (cnt[key]) == "undefined")
178
+ if (typeof cnt[key] == 'undefined')
177
179
  cnt[key] = 0;
178
180
  cnt[key]++;
179
181
  this.addNode(retVal, key, cnt[key], val);
@@ -182,35 +184,38 @@ XML.ObjTree.prototype.parseElement = function (elem) {
182
184
  }
183
185
  else {
184
186
  // @see issue https://github.com/didi/LogicFlow/issues/1068
185
- // if retVal is null, that means the elem doesn't have any attributes and children,
187
+ // if retVal is null, that means the elem doesn't have any attributes and children,
186
188
  // the elem would be like: <a /> or <a></a>, so set retVal to empty object {}
187
189
  retVal === null && (retVal = {});
188
190
  }
189
191
  return retVal;
190
192
  };
191
- // method: addNode( hash, key, count, value )
193
+ // method: addNode( hash, key, count, value )
192
194
  XML.ObjTree.prototype.addNode = function (hash, key, counts, val) {
193
195
  if (this.__force_array[key]) {
194
196
  if (counts == 1)
195
197
  hash[key] = [];
196
- hash[key][hash[key].length] = val; // push
198
+ hash[key][hash[key].length] = val; // push
197
199
  }
198
- else if (counts == 1) { // 1st sibling
200
+ else if (counts == 1) {
201
+ // 1st sibling
199
202
  hash[key] = val;
200
203
  }
201
- else if (counts == 2) { // 2nd sibling
204
+ else if (counts == 2) {
205
+ // 2nd sibling
202
206
  hash[key] = [hash[key], val];
203
207
  }
204
- else { // 3rd sibling and more
208
+ else {
209
+ // 3rd sibling and more
205
210
  hash[key][hash[key].length] = val;
206
211
  }
207
212
  };
208
- // method: writeXML( tree )
213
+ // method: writeXML( tree )
209
214
  XML.ObjTree.prototype.writeXML = function (tree) {
210
215
  var xml = this.hash_to_xml(null, tree);
211
216
  return this.xmlDecl + xml;
212
217
  };
213
- // method: hash_to_xml( tagName, tree )
218
+ // method: hash_to_xml( tagName, tree )
214
219
  XML.ObjTree.prototype.hash_to_xml = function (name, tree) {
215
220
  var elem = [];
216
221
  var attr = [];
@@ -219,13 +224,13 @@ XML.ObjTree.prototype.hash_to_xml = function (name, tree) {
219
224
  continue;
220
225
  var val = tree[key];
221
226
  if (key.charAt(0) != this.attr_prefix) {
222
- if (typeof (val) == "undefined" || val == null) {
223
- elem[elem.length] = "<" + key + " />";
227
+ if (typeof val == 'undefined' || val == null) {
228
+ elem[elem.length] = '<' + key + ' />';
224
229
  }
225
- else if (typeof (val) == "object" && val.constructor == Array) {
230
+ else if (typeof val == 'object' && val.constructor == Array) {
226
231
  elem[elem.length] = this.array_to_xml(key, val);
227
232
  }
228
- else if (typeof (val) == "object") {
233
+ else if (typeof val == 'object') {
229
234
  elem[elem.length] = this.hash_to_xml(key, val);
230
235
  }
231
236
  else {
@@ -233,59 +238,64 @@ XML.ObjTree.prototype.hash_to_xml = function (name, tree) {
233
238
  }
234
239
  }
235
240
  else {
236
- attr[attr.length] = " " + (key.substring(1)) + '="' + (this.xml_escape(val)) + '"';
241
+ attr[attr.length] =
242
+ ' ' + key.substring(1) + '="' + this.xml_escape(val) + '"';
237
243
  }
238
244
  }
239
- var jattr = attr.join("");
240
- var jelem = elem.join("");
241
- if (typeof (name) == "undefined" || name == null) {
242
- // no tag
245
+ var jattr = attr.join('');
246
+ var jelem = elem.join('');
247
+ if (typeof name == 'undefined' || name == null) {
248
+ // no tag
243
249
  }
244
250
  else if (elem.length > 0) {
245
251
  if (jelem.match(/\n/)) {
246
- jelem = "<" + name + jattr + ">\n" + jelem + "</" + name + ">\n";
252
+ jelem = '<' + name + jattr + '>\n' + jelem + '</' + name + '>\n';
247
253
  }
248
254
  else {
249
- jelem = "<" + name + jattr + ">" + jelem + "</" + name + ">\n";
255
+ jelem = '<' + name + jattr + '>' + jelem + '</' + name + '>\n';
250
256
  }
251
257
  }
252
258
  else {
253
- jelem = "<" + name + jattr + " />\n";
259
+ jelem = '<' + name + jattr + ' />\n';
254
260
  }
255
261
  return jelem;
256
262
  };
257
- // method: array_to_xml( tagName, array )
263
+ // method: array_to_xml( tagName, array )
258
264
  XML.ObjTree.prototype.array_to_xml = function (name, array) {
259
265
  var out = [];
260
266
  for (var i = 0; i < array.length; i++) {
261
267
  var val = array[i];
262
- if (typeof (val) == "undefined" || val == null) {
263
- out[out.length] = "<" + name + " />";
268
+ if (typeof val == 'undefined' || val == null) {
269
+ out[out.length] = '<' + name + ' />';
264
270
  }
265
- else if (typeof (val) == "object" && val.constructor == Array) {
271
+ else if (typeof val == 'object' && val.constructor == Array) {
266
272
  out[out.length] = this.array_to_xml(name, val);
267
273
  }
268
- else if (typeof (val) == "object") {
274
+ else if (typeof val == 'object') {
269
275
  out[out.length] = this.hash_to_xml(name, val);
270
276
  }
271
277
  else {
272
278
  out[out.length] = this.scalar_to_xml(name, val);
273
279
  }
274
280
  }
275
- return out.join("");
281
+ return out.join('');
276
282
  };
277
- // method: scalar_to_xml( tagName, text )
283
+ // method: scalar_to_xml( tagName, text )
278
284
  XML.ObjTree.prototype.scalar_to_xml = function (name, text) {
279
- if (name == "#text") {
285
+ if (name == '#text') {
280
286
  return this.xml_escape(text);
281
287
  }
282
288
  else {
283
- return "<" + name + ">" + this.xml_escape(text) + "</" + name + ">\n";
289
+ return '<' + name + '>' + this.xml_escape(text) + '</' + name + '>\n';
284
290
  }
285
291
  };
286
- // method: xml_escape( text )
292
+ // method: xml_escape( text )
287
293
  XML.ObjTree.prototype.xml_escape = function (text) {
288
- return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
294
+ return text
295
+ .replace(/&/g, '&')
296
+ .replace(/</g, '<')
297
+ .replace(/>/g, '>')
298
+ .replace(/"/g, '"');
289
299
  };
290
300
  /*
291
301
  // ========================================================================
@@ -536,4 +546,4 @@ which I will do instead of keeping this documentation like it is.
536
546
  var lfXml2Json = function (xmlData) {
537
547
  return new XML.ObjTree().parseXML(xmlData);
538
548
  };
539
- export { lfXml2Json, };
549
+ export { lfXml2Json };
@@ -181,8 +181,6 @@ var MiniMap = /** @class */ (function () {
181
181
  miniMapWrap.style.width = this.width + 4 + "px";
182
182
  miniMapWrap.style.height = this.height + "px";
183
183
  this.lfMap = new this.LogicFlow({
184
- width: this.lf.graphModel.width,
185
- height: (this.lf.graphModel.width * this.height) / this.width,
186
184
  container: miniMapWrap,
187
185
  isSilentMode: true,
188
186
  stopZoomGraph: true,
@@ -22,4 +22,4 @@ declare class Snapshot {
22
22
  getCanvasData(svg: SVGGraphicsElement, backgroundColor: string): Promise<unknown>;
23
23
  }
24
24
  export default Snapshot;
25
- export { Snapshot, };
25
+ export { Snapshot };
@@ -1,3 +1,5 @@
1
+ /* eslint-disable operator-linebreak */
2
+ /* eslint-disable implicit-arrow-linebreak */
1
3
  /**
2
4
  * 快照插件,生成视图
3
5
  */
@@ -13,39 +15,16 @@ var Snapshot = /** @class */ (function () {
13
15
  _this.getSnapshot(fileName, backgroundColor);
14
16
  };
15
17
  /* 获取Blob对象,用户图片上传 */
16
- lf.getSnapshotBlob = function (backgroundColor) { return _this.getSnapshotBlob(backgroundColor); };
18
+ lf.getSnapshotBlob = function (backgroundColor) {
19
+ return _this.getSnapshotBlob(backgroundColor);
20
+ };
17
21
  /* 获取Base64对象,用户图片上传 */
18
- lf.getSnapshotBase64 = function (backgroundColor) { return _this.getSnapshotBase64(backgroundColor); };
22
+ lf.getSnapshotBase64 = function (backgroundColor) {
23
+ return _this.getSnapshotBase64(backgroundColor);
24
+ };
19
25
  }
20
26
  /* 获取svgRoot对象 */
21
27
  Snapshot.prototype.getSvgRootElement = function (lf) {
22
- var _this = this;
23
- this.offsetX = Number.MAX_SAFE_INTEGER;
24
- this.offsetY = Number.MAX_SAFE_INTEGER;
25
- lf.graphModel.nodes.forEach(function (item) {
26
- var x = item.x, width = item.width, y = item.y, height = item.height;
27
- var offsetX = x - width / 2;
28
- var offsetY = y - height / 2;
29
- if (offsetX < _this.offsetX) {
30
- _this.offsetX = offsetX - 5;
31
- }
32
- if (offsetY < _this.offsetY) {
33
- _this.offsetY = offsetY - 5;
34
- }
35
- });
36
- lf.graphModel.edges.forEach(function (edge) {
37
- if (edge.pointsList) {
38
- edge.pointsList.forEach(function (point) {
39
- var x = point.x, y = point.y;
40
- if (x < _this.offsetX) {
41
- _this.offsetX = x - 5;
42
- }
43
- if (y < _this.offsetY) {
44
- _this.offsetY = y - 5;
45
- }
46
- });
47
- }
48
- });
49
28
  var svgRootElement = lf.container.querySelector('.lf-canvas-overlay');
50
29
  return svgRootElement;
51
30
  };
@@ -80,7 +59,8 @@ var Snapshot = /** @class */ (function () {
80
59
  this.fileName = fileName || "logic-flow." + Date.now() + ".png";
81
60
  var svg = this.getSvgRootElement(this.lf);
82
61
  this.getCanvasData(svg, backgroundColor).then(function (canvas) {
83
- var imgURI = canvas.toDataURL('image/png')
62
+ var imgURI = canvas
63
+ .toDataURL('image/png')
84
64
  .replace('image/png', 'image/octet-stream');
85
65
  _this.triggerDownload(imgURI);
86
66
  });
@@ -145,15 +125,14 @@ var Snapshot = /** @class */ (function () {
145
125
  else {
146
126
  // 删除锚点
147
127
  var lfBase = graph.childNodes[i];
148
- lfBase && lfBase.childNodes.forEach(function (item) {
149
- var element = item;
150
- _this.removeAnchor(element.firstChild);
151
- });
128
+ lfBase &&
129
+ lfBase.childNodes.forEach(function (item) {
130
+ var element = item;
131
+ _this.removeAnchor(element.firstChild);
132
+ });
152
133
  }
153
134
  }
154
135
  }
155
- // offset值加10,保证图形不会紧贴着下载图片的左边和上边
156
- copy.lastChild.style.transform = "matrix(1, 0, 0, 1, " + (-this.offsetX + 10) + ", " + (-this.offsetY + 10) + ")";
157
136
  var dpr = window.devicePixelRatio || 1;
158
137
  var canvas = document.createElement('canvas');
159
138
  /*
@@ -163,9 +142,16 @@ var Snapshot = /** @class */ (function () {
163
142
  */
164
143
  var base = this.lf.graphModel.rootEl.querySelector('.lf-base');
165
144
  var bbox = base.getBoundingClientRect();
145
+ var layout = document
146
+ .querySelector('.lf-canvas-overlay')
147
+ .getBoundingClientRect();
148
+ var offsetX = bbox.x - layout.x;
149
+ var offsetY = bbox.y - layout.y;
166
150
  var graphModel = this.lf.graphModel;
167
151
  var transformModel = graphModel.transformModel;
168
- var SCALE_X = transformModel.SCALE_X, SCALE_Y = transformModel.SCALE_Y;
152
+ var SCALE_X = transformModel.SCALE_X, SCALE_Y = transformModel.SCALE_Y, TRANSLATE_X = transformModel.TRANSLATE_X, TRANSLATE_Y = transformModel.TRANSLATE_Y;
153
+ // offset值加10,保证图形不会紧贴着下载图片的左边和上边
154
+ copy.lastChild.style.transform = "matrix(1, 0, 0, 1, " + (-offsetX + 10 + TRANSLATE_X) + ", " + (-offsetY + 10 + TRANSLATE_Y) + ")";
169
155
  var bboxWidth = Math.ceil(bbox.width / SCALE_X);
170
156
  var bboxHeight = Math.ceil(bbox.height / SCALE_Y);
171
157
  // width,height 值加40,保证图形不会紧贴着下载图片的右边和下边
@@ -221,7 +207,10 @@ var Snapshot = /** @class */ (function () {
221
207
  fixme: XMLSerializer的中的css background url不会下载图片
222
208
  */
223
209
  var svg2Img = "data:image/svg+xml;charset=utf-8," + new XMLSerializer().serializeToString(copy);
224
- var imgSrc = svg2Img.replace(/\n/g, '').replace(/\t/g, '').replace(/#/g, '%23');
210
+ var imgSrc = svg2Img
211
+ .replace(/\n/g, '')
212
+ .replace(/\t/g, '')
213
+ .replace(/#/g, '%23');
225
214
  img.src = imgSrc;
226
215
  });
227
216
  };
@@ -229,4 +218,4 @@ var Snapshot = /** @class */ (function () {
229
218
  return Snapshot;
230
219
  }());
231
220
  export default Snapshot;
232
- export { Snapshot, };
221
+ export { Snapshot };