@logicflow/extension 2.1.9 → 2.1.10

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.
@@ -41,6 +41,9 @@ var __read = (this && this.__read) || function (o, n) {
41
41
  return ar;
42
42
  };
43
43
  import { PolylineEdge, PolylineEdgeModel, h } from '@logicflow/core';
44
+ // 方向组合到圆弧象限的映射。
45
+ // key 由进入方向(dir1)和离开方向(dir2)拼接,例如 'tr' 表示从上(t)到右(r)的拐角。
46
+ // 通过该映射确定在拐点处应该绘制的圆弧象限,用于计算中间控制点。
44
47
  var directionMap = {
45
48
  tr: 'tl',
46
49
  lb: 'tl',
@@ -51,13 +54,17 @@ var directionMap = {
51
54
  bl: 'br',
52
55
  rt: 'br',
53
56
  };
57
+ // 过滤折线中的共线中间点,减少不必要的顶点
54
58
  function pointFilter(points) {
59
+ // 原地修改传入的数组
55
60
  var all = points;
61
+ // 从第二个点开始,检查三点是否共线
56
62
  var i = 1;
57
63
  while (i < all.length - 1) {
58
64
  var _a = __read(all[i - 1], 2), x = _a[0], y = _a[1];
59
65
  var _b = __read(all[i], 2), x1 = _b[0], y1 = _b[1];
60
66
  var _c = __read(all[i + 1], 2), x2 = _c[0], y2 = _c[1];
67
+ // 如果三点在同一条水平或垂直直线上,删除中间点
61
68
  if ((x === x1 && x1 === x2) || (y === y1 && y1 === y2)) {
62
69
  all.splice(i, 1);
63
70
  }
@@ -65,6 +72,7 @@ function pointFilter(points) {
65
72
  i++;
66
73
  }
67
74
  }
75
+ // 返回精简后的点集
68
76
  return all;
69
77
  }
70
78
  function getMidPoints(cur, key, orientation, radius) {
@@ -121,18 +129,22 @@ function getMidPoints(cur, key, orientation, radius) {
121
129
  }
122
130
  function getPartialPath(prev, cur, next, radius) {
123
131
  var _a;
132
+ // 定义误差容错变量
133
+ var tolerance = 1;
124
134
  var dir1 = '';
125
135
  var dir2 = '';
126
- if (prev[0] === cur[0]) {
136
+ if (Math.abs(prev[0] - cur[0]) <= tolerance) {
137
+ // 垂直方向
127
138
  dir1 = prev[1] > cur[1] ? 't' : 'b';
128
139
  }
129
- else if (prev[1] === cur[1]) {
140
+ else if (Math.abs(prev[1] - cur[1]) <= tolerance) {
141
+ // 水平方向
130
142
  dir1 = prev[0] > cur[0] ? 'l' : 'r';
131
143
  }
132
- if (cur[0] === next[0]) {
144
+ if (Math.abs(cur[0] - next[0]) <= tolerance) {
133
145
  dir2 = cur[1] > next[1] ? 't' : 'b';
134
146
  }
135
- else if (cur[1] === next[1]) {
147
+ else if (Math.abs(cur[1] - next[1]) <= tolerance) {
136
148
  dir2 = cur[0] > next[0] ? 'l' : 'r';
137
149
  }
138
150
  var r = Math.min(Math.hypot(cur[0] - prev[0], cur[1] - prev[1]) / 2, Math.hypot(next[0] - cur[0], next[1] - cur[1]) / 2, radius) || (1 / 5) * radius;
@@ -372,7 +372,7 @@ var Snapshot = /** @class */ (function () {
372
372
  */
373
373
  Snapshot.prototype.getCanvasData = function (svg, toImageOptions) {
374
374
  return __awaiter(this, void 0, void 0, function () {
375
- var width, height, backgroundColor, _a, padding, copy, dpr, base, bbox, layoutCanvas, layout, offsetX, offsetY, graphModel, transformModel, SCALE_X, SCALE_Y, TRANSLATE_X, TRANSLATE_Y, safetyFactor, actualWidth, actualHeight, bboxWidth, bboxHeight, canvas, safetyMargin, _b, maxCanvasDimension, otherMaxCanvasDimension, MAX_CANVAS_DIMENSION, OTHER_MAX_CANVAS_DIMENSION, targetWidth, targetHeight, scaleWidth, scaleHeight, ctx, img, style, foreignObject;
375
+ var width, height, backgroundColor, _a, padding, copy, dpr, base, bbox, layoutCanvas, layout, offsetX, offsetY, graphModel, transformModel, SCALE_X, SCALE_Y, TRANSLATE_X, TRANSLATE_Y, safetyFactor, actualWidth, actualHeight, factorWidth, factorHeight, bboxWidth, bboxHeight, canvas, safetyMargin, _b, maxCanvasDimension, otherMaxCanvasDimension, MAX_CANVAS_DIMENSION, OTHER_MAX_CANVAS_DIMENSION, targetWidth, targetHeight, scaleWidth, scaleHeight, ctx, img, style, foreignObject;
376
376
  return __generator(this, function (_c) {
377
377
  switch (_c.label) {
378
378
  case 0:
@@ -404,22 +404,24 @@ var Snapshot = /** @class */ (function () {
404
404
  graphModel = this.lf.graphModel;
405
405
  transformModel = graphModel.transformModel;
406
406
  SCALE_X = transformModel.SCALE_X, SCALE_Y = transformModel.SCALE_Y, TRANSLATE_X = transformModel.TRANSLATE_X, TRANSLATE_Y = transformModel.TRANSLATE_Y;
407
- safetyFactor = toImageOptions.safetyFactor || 1.1 // 安全系数,增加10%的空间
407
+ safetyFactor = toImageOptions.safetyFactor || 1 // 安全系数,增加10%的空间
408
408
  ;
409
- actualWidth = (bbox.width / SCALE_X) * safetyFactor;
410
- actualHeight = (bbox.height / SCALE_Y) * safetyFactor;
411
- bboxWidth = Math.ceil(actualWidth);
412
- bboxHeight = Math.ceil(actualHeight);
409
+ actualWidth = bbox.width / SCALE_X;
410
+ actualHeight = bbox.height / SCALE_Y;
411
+ factorWidth = actualWidth * (safetyFactor - 1);
412
+ factorHeight = actualHeight * (safetyFactor - 1);
413
+ bboxWidth = Math.ceil(actualWidth + factorWidth);
414
+ bboxHeight = Math.ceil(actualHeight + factorHeight);
413
415
  canvas = document.createElement('canvas');
414
416
  canvas.style.width = "".concat(bboxWidth, "px");
415
417
  canvas.style.height = "".concat(bboxHeight, "px");
416
- safetyMargin = toImageOptions.safetyMargin || 40 // 额外的安全边距
418
+ safetyMargin = toImageOptions.safetyMargin || 0 // 额外的安全边距
417
419
  ;
418
420
  _b = this.getCanvasDimensionsByBrowser(), maxCanvasDimension = _b.maxCanvasDimension, otherMaxCanvasDimension = _b.otherMaxCanvasDimension;
419
421
  MAX_CANVAS_DIMENSION = maxCanvasDimension;
420
422
  OTHER_MAX_CANVAS_DIMENSION = otherMaxCanvasDimension;
421
- targetWidth = bboxWidth * dpr + padding * 2 + safetyMargin;
422
- targetHeight = bboxHeight * dpr + padding * 2 + safetyMargin;
423
+ targetWidth = bboxWidth * dpr;
424
+ targetHeight = bboxHeight * dpr;
423
425
  scaleWidth = 1 //宽 缩放
424
426
  ;
425
427
  scaleHeight = 1 //高 缩放
@@ -452,9 +454,12 @@ var Snapshot = /** @class */ (function () {
452
454
  // 对这个矩阵进行缩放,否则会导致截断
453
455
  ;
454
456
  copy.lastChild.style.transform =
455
- "matrix(".concat(scaleWidth, ", 0, 0, ").concat(scaleHeight, ", ").concat((-offsetX + TRANSLATE_X) * (1 / SCALE_X) * scaleWidth + padding / dpr, ", ").concat((-offsetY + TRANSLATE_Y) * (1 / SCALE_Y) * scaleHeight + padding / dpr, ")");
456
- canvas.width = targetWidth;
457
- canvas.height = targetHeight;
457
+ "matrix(".concat(scaleWidth, ", 0, 0, ").concat(scaleHeight, ", ").concat((-offsetX + TRANSLATE_X) * (1 / SCALE_X) * scaleWidth +
458
+ padding +
459
+ factorWidth / 2 +
460
+ safetyMargin, ", ").concat((-offsetY + TRANSLATE_Y) * (1 / SCALE_Y) * scaleHeight + padding + factorHeight / 2 + safetyMargin, ")");
461
+ canvas.width = targetWidth + (padding + safetyMargin) * 2 * dpr;
462
+ canvas.height = targetHeight + (padding + safetyMargin) * 2 * dpr;
458
463
  ctx = canvas.getContext('2d');
459
464
  if (ctx) {
460
465
  // 清空canvas
@@ -704,9 +709,7 @@ var Snapshot = /** @class */ (function () {
704
709
  var _this = this;
705
710
  return __generator(this, function (_a) {
706
711
  switch (_a.label) {
707
- case 0:
708
- console.log('getSnapshotBase64---------------', backgroundColor, fileType, toImageOptions);
709
- return [4 /*yield*/, this.withExportPreparation(function () { return _this._getSnapshotBase64(backgroundColor, fileType, toImageOptions); }, toImageOptions)];
712
+ case 0: return [4 /*yield*/, this.withExportPreparation(function () { return _this._getSnapshotBase64(backgroundColor, fileType, toImageOptions); }, toImageOptions)];
710
713
  case 1: return [2 /*return*/, _a.sent()];
711
714
  }
712
715
  });
@@ -44,6 +44,9 @@ var __read = (this && this.__read) || function (o, n) {
44
44
  Object.defineProperty(exports, "__esModule", { value: true });
45
45
  exports.getCurvedEdgePath = exports.CurvedEdgeModel = exports.CurvedEdge = void 0;
46
46
  var core_1 = require("@logicflow/core");
47
+ // 方向组合到圆弧象限的映射。
48
+ // key 由进入方向(dir1)和离开方向(dir2)拼接,例如 'tr' 表示从上(t)到右(r)的拐角。
49
+ // 通过该映射确定在拐点处应该绘制的圆弧象限,用于计算中间控制点。
47
50
  var directionMap = {
48
51
  tr: 'tl',
49
52
  lb: 'tl',
@@ -54,13 +57,17 @@ var directionMap = {
54
57
  bl: 'br',
55
58
  rt: 'br',
56
59
  };
60
+ // 过滤折线中的共线中间点,减少不必要的顶点
57
61
  function pointFilter(points) {
62
+ // 原地修改传入的数组
58
63
  var all = points;
64
+ // 从第二个点开始,检查三点是否共线
59
65
  var i = 1;
60
66
  while (i < all.length - 1) {
61
67
  var _a = __read(all[i - 1], 2), x = _a[0], y = _a[1];
62
68
  var _b = __read(all[i], 2), x1 = _b[0], y1 = _b[1];
63
69
  var _c = __read(all[i + 1], 2), x2 = _c[0], y2 = _c[1];
70
+ // 如果三点在同一条水平或垂直直线上,删除中间点
64
71
  if ((x === x1 && x1 === x2) || (y === y1 && y1 === y2)) {
65
72
  all.splice(i, 1);
66
73
  }
@@ -68,6 +75,7 @@ function pointFilter(points) {
68
75
  i++;
69
76
  }
70
77
  }
78
+ // 返回精简后的点集
71
79
  return all;
72
80
  }
73
81
  function getMidPoints(cur, key, orientation, radius) {
@@ -124,18 +132,22 @@ function getMidPoints(cur, key, orientation, radius) {
124
132
  }
125
133
  function getPartialPath(prev, cur, next, radius) {
126
134
  var _a;
135
+ // 定义误差容错变量
136
+ var tolerance = 1;
127
137
  var dir1 = '';
128
138
  var dir2 = '';
129
- if (prev[0] === cur[0]) {
139
+ if (Math.abs(prev[0] - cur[0]) <= tolerance) {
140
+ // 垂直方向
130
141
  dir1 = prev[1] > cur[1] ? 't' : 'b';
131
142
  }
132
- else if (prev[1] === cur[1]) {
143
+ else if (Math.abs(prev[1] - cur[1]) <= tolerance) {
144
+ // 水平方向
133
145
  dir1 = prev[0] > cur[0] ? 'l' : 'r';
134
146
  }
135
- if (cur[0] === next[0]) {
147
+ if (Math.abs(cur[0] - next[0]) <= tolerance) {
136
148
  dir2 = cur[1] > next[1] ? 't' : 'b';
137
149
  }
138
- else if (cur[1] === next[1]) {
150
+ else if (Math.abs(cur[1] - next[1]) <= tolerance) {
139
151
  dir2 = cur[0] > next[0] ? 'l' : 'r';
140
152
  }
141
153
  var r = Math.min(Math.hypot(cur[0] - prev[0], cur[1] - prev[1]) / 2, Math.hypot(next[0] - cur[0], next[1] - cur[1]) / 2, radius) || (1 / 5) * radius;
@@ -375,7 +375,7 @@ var Snapshot = /** @class */ (function () {
375
375
  */
376
376
  Snapshot.prototype.getCanvasData = function (svg, toImageOptions) {
377
377
  return __awaiter(this, void 0, void 0, function () {
378
- var width, height, backgroundColor, _a, padding, copy, dpr, base, bbox, layoutCanvas, layout, offsetX, offsetY, graphModel, transformModel, SCALE_X, SCALE_Y, TRANSLATE_X, TRANSLATE_Y, safetyFactor, actualWidth, actualHeight, bboxWidth, bboxHeight, canvas, safetyMargin, _b, maxCanvasDimension, otherMaxCanvasDimension, MAX_CANVAS_DIMENSION, OTHER_MAX_CANVAS_DIMENSION, targetWidth, targetHeight, scaleWidth, scaleHeight, ctx, img, style, foreignObject;
378
+ var width, height, backgroundColor, _a, padding, copy, dpr, base, bbox, layoutCanvas, layout, offsetX, offsetY, graphModel, transformModel, SCALE_X, SCALE_Y, TRANSLATE_X, TRANSLATE_Y, safetyFactor, actualWidth, actualHeight, factorWidth, factorHeight, bboxWidth, bboxHeight, canvas, safetyMargin, _b, maxCanvasDimension, otherMaxCanvasDimension, MAX_CANVAS_DIMENSION, OTHER_MAX_CANVAS_DIMENSION, targetWidth, targetHeight, scaleWidth, scaleHeight, ctx, img, style, foreignObject;
379
379
  return __generator(this, function (_c) {
380
380
  switch (_c.label) {
381
381
  case 0:
@@ -407,22 +407,24 @@ var Snapshot = /** @class */ (function () {
407
407
  graphModel = this.lf.graphModel;
408
408
  transformModel = graphModel.transformModel;
409
409
  SCALE_X = transformModel.SCALE_X, SCALE_Y = transformModel.SCALE_Y, TRANSLATE_X = transformModel.TRANSLATE_X, TRANSLATE_Y = transformModel.TRANSLATE_Y;
410
- safetyFactor = toImageOptions.safetyFactor || 1.1 // 安全系数,增加10%的空间
410
+ safetyFactor = toImageOptions.safetyFactor || 1 // 安全系数,增加10%的空间
411
411
  ;
412
- actualWidth = (bbox.width / SCALE_X) * safetyFactor;
413
- actualHeight = (bbox.height / SCALE_Y) * safetyFactor;
414
- bboxWidth = Math.ceil(actualWidth);
415
- bboxHeight = Math.ceil(actualHeight);
412
+ actualWidth = bbox.width / SCALE_X;
413
+ actualHeight = bbox.height / SCALE_Y;
414
+ factorWidth = actualWidth * (safetyFactor - 1);
415
+ factorHeight = actualHeight * (safetyFactor - 1);
416
+ bboxWidth = Math.ceil(actualWidth + factorWidth);
417
+ bboxHeight = Math.ceil(actualHeight + factorHeight);
416
418
  canvas = document.createElement('canvas');
417
419
  canvas.style.width = "".concat(bboxWidth, "px");
418
420
  canvas.style.height = "".concat(bboxHeight, "px");
419
- safetyMargin = toImageOptions.safetyMargin || 40 // 额外的安全边距
421
+ safetyMargin = toImageOptions.safetyMargin || 0 // 额外的安全边距
420
422
  ;
421
423
  _b = this.getCanvasDimensionsByBrowser(), maxCanvasDimension = _b.maxCanvasDimension, otherMaxCanvasDimension = _b.otherMaxCanvasDimension;
422
424
  MAX_CANVAS_DIMENSION = maxCanvasDimension;
423
425
  OTHER_MAX_CANVAS_DIMENSION = otherMaxCanvasDimension;
424
- targetWidth = bboxWidth * dpr + padding * 2 + safetyMargin;
425
- targetHeight = bboxHeight * dpr + padding * 2 + safetyMargin;
426
+ targetWidth = bboxWidth * dpr;
427
+ targetHeight = bboxHeight * dpr;
426
428
  scaleWidth = 1 //宽 缩放
427
429
  ;
428
430
  scaleHeight = 1 //高 缩放
@@ -455,9 +457,12 @@ var Snapshot = /** @class */ (function () {
455
457
  // 对这个矩阵进行缩放,否则会导致截断
456
458
  ;
457
459
  copy.lastChild.style.transform =
458
- "matrix(".concat(scaleWidth, ", 0, 0, ").concat(scaleHeight, ", ").concat((-offsetX + TRANSLATE_X) * (1 / SCALE_X) * scaleWidth + padding / dpr, ", ").concat((-offsetY + TRANSLATE_Y) * (1 / SCALE_Y) * scaleHeight + padding / dpr, ")");
459
- canvas.width = targetWidth;
460
- canvas.height = targetHeight;
460
+ "matrix(".concat(scaleWidth, ", 0, 0, ").concat(scaleHeight, ", ").concat((-offsetX + TRANSLATE_X) * (1 / SCALE_X) * scaleWidth +
461
+ padding +
462
+ factorWidth / 2 +
463
+ safetyMargin, ", ").concat((-offsetY + TRANSLATE_Y) * (1 / SCALE_Y) * scaleHeight + padding + factorHeight / 2 + safetyMargin, ")");
464
+ canvas.width = targetWidth + (padding + safetyMargin) * 2 * dpr;
465
+ canvas.height = targetHeight + (padding + safetyMargin) * 2 * dpr;
461
466
  ctx = canvas.getContext('2d');
462
467
  if (ctx) {
463
468
  // 清空canvas
@@ -707,9 +712,7 @@ var Snapshot = /** @class */ (function () {
707
712
  var _this = this;
708
713
  return __generator(this, function (_a) {
709
714
  switch (_a.label) {
710
- case 0:
711
- console.log('getSnapshotBase64---------------', backgroundColor, fileType, toImageOptions);
712
- return [4 /*yield*/, this.withExportPreparation(function () { return _this._getSnapshotBase64(backgroundColor, fileType, toImageOptions); }, toImageOptions)];
715
+ case 0: return [4 /*yield*/, this.withExportPreparation(function () { return _this._getSnapshotBase64(backgroundColor, fileType, toImageOptions); }, toImageOptions)];
713
716
  case 1: return [2 /*return*/, _a.sent()];
714
717
  }
715
718
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logicflow/extension",
3
- "version": "2.1.9",
3
+ "version": "2.1.10",
4
4
  "description": "LogicFlow Extensions",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -20,8 +20,8 @@
20
20
  "author": "Logicflow-Team",
21
21
  "license": "Apache-2.0",
22
22
  "peerDependencies": {
23
- "@logicflow/core": "2.1.7",
24
- "@logicflow/vue-node-registry": "1.1.8"
23
+ "@logicflow/vue-node-registry": "1.1.9",
24
+ "@logicflow/core": "2.1.8"
25
25
  },
26
26
  "dependencies": {
27
27
  "@antv/hierarchy": "^0.6.11",
@@ -32,8 +32,8 @@
32
32
  "preact": "^10.17.1",
33
33
  "rangy": "^1.3.1",
34
34
  "vanilla-picker": "^2.12.3",
35
- "@logicflow/core": "2.1.7",
36
- "@logicflow/vue-node-registry": "1.1.8"
35
+ "@logicflow/core": "2.1.8",
36
+ "@logicflow/vue-node-registry": "1.1.9"
37
37
  },
38
38
  "devDependencies": {
39
39
  "less": "^4.1.1",
@@ -1,9 +1,14 @@
1
1
  import { PolylineEdge, PolylineEdgeModel, h, LogicFlow } from '@logicflow/core'
2
2
  import PointTuple = LogicFlow.PointTuple
3
3
 
4
+ // 方向类型:t=上(top), b=下(bottom), l=左(left), r=右(right),'' 表示未确定
4
5
  type DirectionType = 't' | 'b' | 'l' | 'r' | ''
6
+ // 圆弧所在象限:tl=左上,tr=右上,bl=左下,br=右下,'-' 表示不需要圆弧
5
7
  type ArcQuadrantType = 'tl' | 'tr' | 'bl' | 'br' | '-'
6
8
 
9
+ // 方向组合到圆弧象限的映射。
10
+ // key 由进入方向(dir1)和离开方向(dir2)拼接,例如 'tr' 表示从上(t)到右(r)的拐角。
11
+ // 通过该映射确定在拐点处应该绘制的圆弧象限,用于计算中间控制点。
7
12
  const directionMap: {
8
13
  [key: string]: ArcQuadrantType
9
14
  } = {
@@ -17,19 +22,24 @@ const directionMap: {
17
22
  rt: 'br',
18
23
  }
19
24
 
25
+ // 过滤折线中的共线中间点,减少不必要的顶点
20
26
  function pointFilter(points: number[][]) {
27
+ // 原地修改传入的数组
21
28
  const all = points
29
+ // 从第二个点开始,检查三点是否共线
22
30
  let i = 1
23
31
  while (i < all.length - 1) {
24
32
  const [x, y] = all[i - 1]
25
33
  const [x1, y1] = all[i]
26
34
  const [x2, y2] = all[i + 1]
35
+ // 如果三点在同一条水平或垂直直线上,删除中间点
27
36
  if ((x === x1 && x1 === x2) || (y === y1 && y1 === y2)) {
28
37
  all.splice(i, 1)
29
38
  } else {
30
39
  i++
31
40
  }
32
41
  }
42
+ // 返回精简后的点集
33
43
  return all
34
44
  }
35
45
 
@@ -93,18 +103,23 @@ function getPartialPath(
93
103
  next: PointTuple,
94
104
  radius: number,
95
105
  ): string {
106
+ // 定义误差容错变量
107
+ const tolerance = 1
108
+
96
109
  let dir1: DirectionType = ''
97
110
  let dir2: DirectionType = ''
98
111
 
99
- if (prev[0] === cur[0]) {
112
+ if (Math.abs(prev[0] - cur[0]) <= tolerance) {
113
+ // 垂直方向
100
114
  dir1 = prev[1] > cur[1] ? 't' : 'b'
101
- } else if (prev[1] === cur[1]) {
115
+ } else if (Math.abs(prev[1] - cur[1]) <= tolerance) {
116
+ // 水平方向
102
117
  dir1 = prev[0] > cur[0] ? 'l' : 'r'
103
118
  }
104
119
 
105
- if (cur[0] === next[0]) {
120
+ if (Math.abs(cur[0] - next[0]) <= tolerance) {
106
121
  dir2 = cur[1] > next[1] ? 't' : 'b'
107
- } else if (cur[1] === next[1]) {
122
+ } else if (Math.abs(cur[1] - next[1]) <= tolerance) {
108
123
  dir2 = cur[0] > next[0] ? 'l' : 'r'
109
124
  }
110
125
 
@@ -389,20 +389,22 @@ export class Snapshot {
389
389
  // 计算实际宽高,考虑缩放因素
390
390
  // 在宽画布情况下,getBoundingClientRect可能无法获取到所有元素的边界
391
391
  // 因此我们添加一个安全系数来确保能够容纳所有元素
392
- const safetyFactor = toImageOptions.safetyFactor || 1.1 // 安全系数,增加10%的空间
393
- const actualWidth = (bbox.width / SCALE_X) * safetyFactor
394
- const actualHeight = (bbox.height / SCALE_Y) * safetyFactor
392
+ const safetyFactor = toImageOptions.safetyFactor || 1 // 安全系数,增加10%的空间
393
+ const actualWidth = bbox.width / SCALE_X
394
+ const actualHeight = bbox.height / SCALE_Y
395
+ const factorWidth = actualWidth * (safetyFactor - 1)
396
+ const factorHeight = actualHeight * (safetyFactor - 1)
395
397
 
396
398
  // 包含所有元素的最小宽高,确保足够大以容纳所有元素
397
- const bboxWidth = Math.ceil(actualWidth)
398
- const bboxHeight = Math.ceil(actualHeight)
399
+ const bboxWidth = Math.ceil(actualWidth + factorWidth)
400
+ const bboxHeight = Math.ceil(actualHeight + factorHeight)
399
401
  const canvas = document.createElement('canvas')
400
402
  canvas.style.width = `${bboxWidth}px`
401
403
  canvas.style.height = `${bboxHeight}px`
402
404
 
403
405
  // 宽高值 默认加padding 40,保证图形不会紧贴着下载图片
404
406
  // 为宽画布添加额外的安全边距,确保不会裁剪
405
- const safetyMargin = toImageOptions.safetyMargin || 40 // 额外的安全边距
407
+ const safetyMargin = toImageOptions.safetyMargin || 0 // 额外的安全边距
406
408
 
407
409
  // 获取当前浏览器类型,不同浏览器对canvas的限制不同
408
410
  const { maxCanvasDimension, otherMaxCanvasDimension } =
@@ -410,8 +412,8 @@ export class Snapshot {
410
412
  const MAX_CANVAS_DIMENSION = maxCanvasDimension
411
413
  const OTHER_MAX_CANVAS_DIMENSION = otherMaxCanvasDimension
412
414
 
413
- let targetWidth = bboxWidth * dpr + padding * 2 + safetyMargin
414
- let targetHeight = bboxHeight * dpr + padding * 2 + safetyMargin
415
+ let targetWidth = bboxWidth * dpr
416
+ let targetHeight = bboxHeight * dpr
415
417
  let scaleWidth = 1 //宽 缩放
416
418
  let scaleHeight = 1 //高 缩放
417
419
  // 对宽和高分别进行缩放,如chrome,矩形单边最大宽度不超过65535,如宽超过65535,那么高不能超过4096,否则像素会超,也会显示不出。
@@ -448,12 +450,13 @@ export class Snapshot {
448
450
  // 对这个矩阵进行缩放,否则会导致截断
449
451
  ;(copy.lastChild as SVGElement).style.transform =
450
452
  `matrix(${scaleWidth}, 0, 0, ${scaleHeight}, ${
451
- (-offsetX + TRANSLATE_X) * (1 / SCALE_X) * scaleWidth + padding / dpr
452
- }, ${
453
- (-offsetY + TRANSLATE_Y) * (1 / SCALE_Y) * scaleHeight + padding / dpr
454
- })`
455
- canvas.width = targetWidth
456
- canvas.height = targetHeight
453
+ (-offsetX + TRANSLATE_X) * (1 / SCALE_X) * scaleWidth +
454
+ padding +
455
+ factorWidth / 2 +
456
+ safetyMargin
457
+ }, ${(-offsetY + TRANSLATE_Y) * (1 / SCALE_Y) * scaleHeight + padding + factorHeight / 2 + safetyMargin})`
458
+ canvas.width = targetWidth + (padding + safetyMargin) * 2 * dpr
459
+ canvas.height = targetHeight + (padding + safetyMargin) * 2 * dpr
457
460
  const ctx = canvas.getContext('2d')
458
461
  if (ctx) {
459
462
  // 清空canvas
@@ -678,12 +681,6 @@ export class Snapshot {
678
681
  fileType?: string,
679
682
  toImageOptions?: ToImageOptions,
680
683
  ): Promise<SnapshotResponse> {
681
- console.log(
682
- 'getSnapshotBase64---------------',
683
- backgroundColor,
684
- fileType,
685
- toImageOptions,
686
- )
687
684
  return await this.withExportPreparation(
688
685
  () => this._getSnapshotBase64(backgroundColor, fileType, toImageOptions),
689
686
  toImageOptions,