@meta2d/core 1.0.34 → 1.0.36

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.
@@ -82,7 +82,7 @@ var __values = (this && this.__values) || function(o) {
82
82
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
83
83
  };
84
84
  import { KeydownType } from '../options';
85
- import { addLineAnchor, calcIconRect, calcTextRect, calcWorldAnchors, calcWorldRects, LockState, nearestAnchor, PenType, pushPenAnchor, removePenAnchor, renderPen, scalePen, translateLine, deleteTempAnchor, connectLine, disconnectLine, getAnchor, calcAnchorDock, calcMoveDock, calcTextLines, setNodeAnimate, setLineAnimate, calcPenRect, setChildrenActive, getParent, setHover, randomId, getPensLock, getToAnchor, getFromAnchor, calcPadding, getPensDisableRotate, getPensDisableResize, needCalcTextRectProps, calcResizeDock, needPatchFlagsPenRectProps, needCalcIconRectProps, isDomShapes, renderPenRaw, needSetPenProps, getAllChildren, calcInView, isShowChild, getTextColor, getGlobalColor, clearLifeCycle, rotatePen, calcTextAutoWidth, getGradientAnimatePath, } from '../pen';
85
+ import { addLineAnchor, calcIconRect, calcTextRect, calcWorldAnchors, calcWorldRects, LockState, nearestAnchor, PenType, pushPenAnchor, removePenAnchor, renderPen, scalePen, translateLine, deleteTempAnchor, connectLine, disconnectLine, getAnchor, calcAnchorDock, calcMoveDock, calcTextLines, setNodeAnimate, setLineAnimate, calcPenRect, setChildrenActive, getParent, setHover, randomId, getPensLock, getToAnchor, getFromAnchor, calcPadding, getPensDisableRotate, getPensDisableResize, needCalcTextRectProps, calcResizeDock, needPatchFlagsPenRectProps, needCalcIconRectProps, isDomShapes, renderPenRaw, needSetPenProps, getAllChildren, calcInView, isShowChild, getTextColor, getGlobalColor, clearLifeCycle, rotatePen, calcTextAutoWidth, getGradientAnimatePath, CanvasLayer, ctxFlip, ctxRotate, setGlobalAlpha, drawImage, } from '../pen';
86
86
  import { calcRotate, distance, getDistance, hitPoint, PointType, PrevNextType, rotatePoint, samePoint, scalePoint, translatePoint, TwoWay, } from '../point';
87
87
  import { calcCenter, calcRightBottom, calcRelativePoint, getRect, getRectOfPoints, pointInRect, pointInSimpleRect, rectInRect, rectToPoints, resizeRect, translateRect, } from '../rect';
88
88
  import { EditType, globalStore, } from '../store';
@@ -542,6 +542,9 @@ var Canvas = /** @class */ (function () {
542
542
  case 'v':
543
543
  case 'V':
544
544
  if (!e.ctrlKey && !e.metaKey) {
545
+ if (_this.pencil) {
546
+ _this.stopPencil();
547
+ }
545
548
  if (_this.drawingLineName) {
546
549
  _this.finishDrawline();
547
550
  _this.drawingLineName = '';
@@ -556,7 +559,16 @@ var Canvas = /** @class */ (function () {
556
559
  break;
557
560
  case 'b':
558
561
  case 'B':
559
- _this.drawingPencil();
562
+ if (_this.drawingLineName) {
563
+ _this.finishDrawline();
564
+ _this.drawingLineName = '';
565
+ }
566
+ if (_this.pencil) {
567
+ _this.stopPencil();
568
+ }
569
+ else {
570
+ _this.drawingPencil();
571
+ }
560
572
  break;
561
573
  case 'y':
562
574
  case 'Y':
@@ -707,8 +719,8 @@ var Canvas = /** @class */ (function () {
707
719
  }
708
720
  _a.label = 3;
709
721
  case 3:
710
- if (obj && obj.draggable !== false) {
711
- obj = Array.isArray(obj) ? obj : [obj];
722
+ obj = Array.isArray(obj) ? obj : [obj];
723
+ if (obj[0] && obj[0].draggable !== false) {
712
724
  pt = { x: event.offsetX, y: event.offsetY };
713
725
  this.calibrateMouse(pt);
714
726
  this.dropPens(obj, pt);
@@ -1052,7 +1064,7 @@ var Canvas = /** @class */ (function () {
1052
1064
  else {
1053
1065
  switch (_this.hoverType) {
1054
1066
  case HoverType.None:
1055
- _this.store.data.rule &&
1067
+ (_this.store.data.rule || _this.store.options.rule) &&
1056
1068
  !_this.store.options.disableRuleLine &&
1057
1069
  _this.addRuleLine(e);
1058
1070
  if (_this.store.options.resizeMode) {
@@ -1227,7 +1239,7 @@ var Canvas = /** @class */ (function () {
1227
1239
  var pt = { x: e.x, y: e.y };
1228
1240
  // Move line anchor
1229
1241
  if (_this.hoverType === HoverType.LineAnchor) {
1230
- if (_this.dockInAnchor(e) &&
1242
+ if ((_this.store.active[0].lineName === 'line' || _this.dockInAnchor(e)) &&
1231
1243
  !_this.store.options.disableDock &&
1232
1244
  !_this.store.options.disableLineDock) {
1233
1245
  _this.clearDock();
@@ -2025,10 +2037,24 @@ var Canvas = /** @class */ (function () {
2025
2037
  if (!isFinite(pen.x)) {
2026
2038
  continue;
2027
2039
  }
2028
- if (pen.template) {
2040
+ // if (pen.template) {
2041
+ if (pen.canvasLayer === CanvasLayer.CanvasTemplate) {
2029
2042
  continue;
2030
2043
  }
2031
2044
  if (pen.calculative.inView) {
2045
+ if (pen.canvasLayer === CanvasLayer.CanvasMain &&
2046
+ pen.name !== 'gif' &&
2047
+ pen.image &&
2048
+ pen.calculative.img) {
2049
+ ctx.save();
2050
+ ctxFlip(ctx, pen);
2051
+ if (pen.calculative.rotate) {
2052
+ ctxRotate(ctx, pen);
2053
+ }
2054
+ setGlobalAlpha(ctx, pen);
2055
+ drawImage(ctx, pen);
2056
+ ctx.restore();
2057
+ }
2032
2058
  renderPen(ctx, pen);
2033
2059
  }
2034
2060
  }
@@ -2981,12 +3007,15 @@ var Canvas = /** @class */ (function () {
2981
3007
  });
2982
3008
  };
2983
3009
  Canvas.prototype.dropPens = function (pens, e) {
3010
+ var _a;
2984
3011
  return __awaiter(this, void 0, void 0, function () {
2985
- var pens_2, pens_2_1, pen, pens_3, pens_3_1, pen, pens_4, pens_4_1, pen, width, height, rect_1, flag, pens_5, pens_5_1, pen, points;
2986
- var e_7, _a, e_8, _b, e_9, _c, e_10, _d;
2987
- return __generator(this, function (_e) {
2988
- switch (_e.label) {
3012
+ var pens_2, pens_2_1, pen, pens_3, pens_3_1, pen, pens_4, pens_4_1, pen, pens_5, pens_5_1, pen, width, height, rect_1, flag, pens_6, pens_6_1, pen, points;
3013
+ var e_7, _b, e_8, _c, e_9, _d, e_10, _e, e_11, _f;
3014
+ var _this = this;
3015
+ return __generator(this, function (_g) {
3016
+ switch (_g.label) {
2989
3017
  case 0:
3018
+ this.randomIdObj = {};
2990
3019
  try {
2991
3020
  for (pens_2 = __values(pens), pens_2_1 = pens_2.next(); !pens_2_1.done; pens_2_1 = pens_2.next()) {
2992
3021
  pen = pens_2_1.value;
@@ -2997,13 +3026,38 @@ var Canvas = /** @class */ (function () {
2997
3026
  catch (e_7_1) { e_7 = { error: e_7_1 }; }
2998
3027
  finally {
2999
3028
  try {
3000
- if (pens_2_1 && !pens_2_1.done && (_a = pens_2.return)) _a.call(pens_2);
3029
+ if (pens_2_1 && !pens_2_1.done && (_b = pens_2.return)) _b.call(pens_2);
3001
3030
  }
3002
3031
  finally { if (e_7) throw e_7.error; }
3003
3032
  }
3033
+ if (Object.keys(this.randomIdObj).length !== 0) {
3034
+ try {
3035
+ for (pens_3 = __values(pens), pens_3_1 = pens_3.next(); !pens_3_1.done; pens_3_1 = pens_3.next()) {
3036
+ pen = pens_3_1.value;
3037
+ if (pen.type) {
3038
+ pen.anchors[0].connectTo = this.randomIdObj[pen.anchors[0].connectTo];
3039
+ pen.anchors[pen.anchors.length - 1].connectTo =
3040
+ this.randomIdObj[pen.anchors[pen.anchors.length - 1].connectTo];
3041
+ }
3042
+ else {
3043
+ (_a = pen.connectedLines) === null || _a === void 0 ? void 0 : _a.forEach(function (item) {
3044
+ item.lineAnchor = _this.randomIdObj[item.lineAnchor];
3045
+ item.lineId = _this.randomIdObj[item.lineId];
3046
+ });
3047
+ }
3048
+ }
3049
+ }
3050
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
3051
+ finally {
3052
+ try {
3053
+ if (pens_3_1 && !pens_3_1.done && (_c = pens_3.return)) _c.call(pens_3);
3054
+ }
3055
+ finally { if (e_8) throw e_8.error; }
3056
+ }
3057
+ }
3004
3058
  try {
3005
- for (pens_3 = __values(pens), pens_3_1 = pens_3.next(); !pens_3_1.done; pens_3_1 = pens_3.next()) {
3006
- pen = pens_3_1.value;
3059
+ for (pens_4 = __values(pens), pens_4_1 = pens_4.next(); !pens_4_1.done; pens_4_1 = pens_4.next()) {
3060
+ pen = pens_4_1.value;
3007
3061
  // TODO: randomCombineId 会更改 id, 此处应该不存在空 id
3008
3062
  if (!pen.id) {
3009
3063
  pen.id = s8();
@@ -3012,12 +3066,12 @@ var Canvas = /** @class */ (function () {
3012
3066
  this.store.pens[pen.id] = pen;
3013
3067
  }
3014
3068
  }
3015
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
3069
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
3016
3070
  finally {
3017
3071
  try {
3018
- if (pens_3_1 && !pens_3_1.done && (_b = pens_3.return)) _b.call(pens_3);
3072
+ if (pens_4_1 && !pens_4_1.done && (_d = pens_4.return)) _d.call(pens_4);
3019
3073
  }
3020
- finally { if (e_8) throw e_8.error; }
3074
+ finally { if (e_9) throw e_9.error; }
3021
3075
  }
3022
3076
  try {
3023
3077
  // // 计算区域
@@ -3025,8 +3079,8 @@ var Canvas = /** @class */ (function () {
3025
3079
  // // 组合节点才需要提前计算
3026
3080
  // Array.isArray(pen.children) && pen.children.length > 0 && this.updatePenRect(pen);
3027
3081
  // }
3028
- for (pens_4 = __values(pens), pens_4_1 = pens_4.next(); !pens_4_1.done; pens_4_1 = pens_4.next()) {
3029
- pen = pens_4_1.value;
3082
+ for (pens_5 = __values(pens), pens_5_1 = pens_5.next(); !pens_5_1.done; pens_5_1 = pens_5.next()) {
3083
+ pen = pens_5_1.value;
3030
3084
  if (!pen.parentId) {
3031
3085
  pen.width *= this.store.data.scale;
3032
3086
  pen.height *= this.store.data.scale;
@@ -3039,12 +3093,12 @@ var Canvas = /** @class */ (function () {
3039
3093
  }
3040
3094
  }
3041
3095
  }
3042
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
3096
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
3043
3097
  finally {
3044
3098
  try {
3045
- if (pens_4_1 && !pens_4_1.done && (_c = pens_4.return)) _c.call(pens_4);
3099
+ if (pens_5_1 && !pens_5_1.done && (_e = pens_5.return)) _e.call(pens_5);
3046
3100
  }
3047
- finally { if (e_9) throw e_9.error; }
3101
+ finally { if (e_10) throw e_10.error; }
3048
3102
  }
3049
3103
  width = this.store.data.width || this.store.options.width;
3050
3104
  height = this.store.data.height || this.store.options.height;
@@ -3057,8 +3111,8 @@ var Canvas = /** @class */ (function () {
3057
3111
  };
3058
3112
  flag = true;
3059
3113
  try {
3060
- for (pens_5 = __values(pens), pens_5_1 = pens_5.next(); !pens_5_1.done; pens_5_1 = pens_5.next()) {
3061
- pen = pens_5_1.value;
3114
+ for (pens_6 = __values(pens), pens_6_1 = pens_6.next(); !pens_6_1.done; pens_6_1 = pens_6.next()) {
3115
+ pen = pens_6_1.value;
3062
3116
  if (!pen.parentId) {
3063
3117
  points = [
3064
3118
  { x: pen.x, y: pen.y },
@@ -3093,12 +3147,12 @@ var Canvas = /** @class */ (function () {
3093
3147
  }
3094
3148
  }
3095
3149
  }
3096
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
3150
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
3097
3151
  finally {
3098
3152
  try {
3099
- if (pens_5_1 && !pens_5_1.done && (_d = pens_5.return)) _d.call(pens_5);
3153
+ if (pens_6_1 && !pens_6_1.done && (_f = pens_6.return)) _f.call(pens_6);
3100
3154
  }
3101
- finally { if (e_10) throw e_10.error; }
3155
+ finally { if (e_11) throw e_11.error; }
3102
3156
  }
3103
3157
  if (flag) {
3104
3158
  console.info('画笔在大屏范围外');
@@ -3107,7 +3161,7 @@ var Canvas = /** @class */ (function () {
3107
3161
  }
3108
3162
  return [4 /*yield*/, this.addPens(pens, true)];
3109
3163
  case 1:
3110
- _e.sent();
3164
+ _g.sent();
3111
3165
  this.active(pens.filter(function (pen) { return !pen.parentId; }));
3112
3166
  this.render();
3113
3167
  this.externalElements.focus(); // 聚焦
@@ -3117,8 +3171,35 @@ var Canvas = /** @class */ (function () {
3117
3171
  });
3118
3172
  };
3119
3173
  Canvas.prototype.randomCombineId = function (pen, pens, parentId) {
3120
- var e_11, _a;
3174
+ var e_12, _a;
3175
+ var beforeIds = null;
3176
+ if (pen.type) {
3177
+ if (pen.anchors[0].connectTo ||
3178
+ pen.anchors[pen.anchors.length - 1].connectTo) {
3179
+ beforeIds = [
3180
+ pen.id,
3181
+ pen.anchors[0].id,
3182
+ pen.anchors[pen.anchors.length - 1].id,
3183
+ ];
3184
+ }
3185
+ }
3186
+ else {
3187
+ if (pen.connectedLines && pen.connectedLines.length) {
3188
+ beforeIds = [pen.id];
3189
+ }
3190
+ }
3121
3191
  randomId(pen);
3192
+ if (beforeIds) {
3193
+ if (beforeIds.length === 1) {
3194
+ this.randomIdObj[beforeIds[0]] = pen.id;
3195
+ }
3196
+ else {
3197
+ this.randomIdObj[beforeIds[0]] = pen.id;
3198
+ this.randomIdObj[beforeIds[1]] = pen.anchors[0].id;
3199
+ this.randomIdObj[beforeIds[2]] = pen.anchors[pen.anchors.length - 1].id;
3200
+ }
3201
+ }
3202
+ //处理链接关系
3122
3203
  pen.parentId = parentId;
3123
3204
  var newChildren = [];
3124
3205
  if (Array.isArray(pen.children)) {
@@ -3134,12 +3215,12 @@ var Canvas = /** @class */ (function () {
3134
3215
  _loop_4(childId);
3135
3216
  }
3136
3217
  }
3137
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
3218
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
3138
3219
  finally {
3139
3220
  try {
3140
3221
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3141
3222
  }
3142
- finally { if (e_11) throw e_11.error; }
3223
+ finally { if (e_12) throw e_12.error; }
3143
3224
  }
3144
3225
  }
3145
3226
  pen.children = newChildren;
@@ -3147,8 +3228,8 @@ var Canvas = /** @class */ (function () {
3147
3228
  };
3148
3229
  Canvas.prototype.addPens = function (pens, history) {
3149
3230
  return __awaiter(this, void 0, void 0, function () {
3150
- var _a, list, pens_6, pens_6_1, pen;
3151
- var e_12, _b;
3231
+ var _a, list, pens_7, pens_7_1, pen;
3232
+ var e_13, _b;
3152
3233
  return __generator(this, function (_c) {
3153
3234
  switch (_c.label) {
3154
3235
  case 0:
@@ -3164,8 +3245,8 @@ var Canvas = /** @class */ (function () {
3164
3245
  }
3165
3246
  list = [];
3166
3247
  try {
3167
- for (pens_6 = __values(pens), pens_6_1 = pens_6.next(); !pens_6_1.done; pens_6_1 = pens_6.next()) {
3168
- pen = pens_6_1.value;
3248
+ for (pens_7 = __values(pens), pens_7_1 = pens_7.next(); !pens_7_1.done; pens_7_1 = pens_7.next()) {
3249
+ pen = pens_7_1.value;
3169
3250
  if (this.beforeAddPen && this.beforeAddPen(pen) != true) {
3170
3251
  continue;
3171
3252
  }
@@ -3173,12 +3254,12 @@ var Canvas = /** @class */ (function () {
3173
3254
  list.push(pen);
3174
3255
  }
3175
3256
  }
3176
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
3257
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
3177
3258
  finally {
3178
3259
  try {
3179
- if (pens_6_1 && !pens_6_1.done && (_b = pens_6.return)) _b.call(pens_6);
3260
+ if (pens_7_1 && !pens_7_1.done && (_b = pens_7.return)) _b.call(pens_7);
3180
3261
  }
3181
- finally { if (e_12) throw e_12.error; }
3262
+ finally { if (e_13) throw e_13.error; }
3182
3263
  }
3183
3264
  this.render();
3184
3265
  this.store.emitter.emit('add', list);
@@ -3245,7 +3326,7 @@ var Canvas = /** @class */ (function () {
3245
3326
  };
3246
3327
  };
3247
3328
  Canvas.prototype.addRuleLine = function (e) {
3248
- var _a = this.store.data, offsetX = _a.x, offsetY = _a.y;
3329
+ var _a = this.store.data, offsetX = _a.x, offsetY = _a.y, scale = _a.scale, origin = _a.origin;
3249
3330
  // 靠近左上角的 x ,y
3250
3331
  var x = e.x + offsetX;
3251
3332
  var y = e.y + offsetY;
@@ -3260,12 +3341,24 @@ var Canvas = /** @class */ (function () {
3260
3341
  lineX = -offsetX;
3261
3342
  width = this.width;
3262
3343
  otherPX = 1;
3344
+ if (!e.ctrlKey) {
3345
+ //找最近的标尺线
3346
+ lineY =
3347
+ Math.round((lineY - origin.y) / (scale * 10)) * (scale * 10) +
3348
+ origin.y;
3349
+ }
3263
3350
  }
3264
3351
  else if (y < x && y < 20) {
3265
3352
  // 绘制一条垂直线
3266
3353
  lineY = -offsetY;
3267
3354
  height = this.height;
3268
3355
  otherPY = 1;
3356
+ if (!e.ctrlKey) {
3357
+ //找最近的标尺线
3358
+ lineX =
3359
+ Math.round((lineX - origin.x) / (scale * 10)) * (scale * 10) +
3360
+ origin.x;
3361
+ }
3269
3362
  }
3270
3363
  else {
3271
3364
  return;
@@ -3293,6 +3386,37 @@ var Canvas = /** @class */ (function () {
3293
3386
  ],
3294
3387
  });
3295
3388
  };
3389
+ /**
3390
+ * @description 调整pen的坐标,让pen按照网格自动对齐
3391
+ * @author Joseph Ho
3392
+ * @date 14/11/2023
3393
+ * @memberof Canvas
3394
+ */
3395
+ Canvas.prototype.alignPenToGrid = function (pen) {
3396
+ var _a;
3397
+ var autoAlignGrid = this.store.options.autoAlignGrid && this.store.data.grid;
3398
+ // 如果开启了自动网格,并且不是连线,则使pen对齐网格
3399
+ if (autoAlignGrid && !pen.type) {
3400
+ var gridSize = this.store.data.gridSize || this.store.options.gridSize;
3401
+ var _b = this.store.data, origin_2 = _b.origin, scale = _b.scale;
3402
+ var x = pen.x, y = pen.y;
3403
+ var obj = { x: x, y: y };
3404
+ var rect = this.getPenRect(pen);
3405
+ // 算出偏移了多少个网格
3406
+ var m = parseInt((rect.x / gridSize).toFixed());
3407
+ var n = parseInt((rect.y / gridSize).toFixed());
3408
+ var x1 = m * gridSize;
3409
+ var y1 = n * gridSize;
3410
+ // 算出最终的偏移坐标
3411
+ obj.x = origin_2.x + x1 * scale;
3412
+ obj.y = origin_2.y + y1 * scale;
3413
+ Object.assign(pen, obj);
3414
+ (_a = pen.onMove) === null || _a === void 0 ? void 0 : _a.call(pen, pen);
3415
+ this.updatePenRect(pen);
3416
+ this.calcActiveRect();
3417
+ this.getSizeCPs();
3418
+ }
3419
+ };
3296
3420
  /**
3297
3421
  * 拖拽结束,数据更新到 active.pens
3298
3422
  */
@@ -3301,13 +3425,26 @@ var Canvas = /** @class */ (function () {
3301
3425
  // 鼠标松手才更新,此处是更新前的值
3302
3426
  var initPens = deepClone(this.store.active, true);
3303
3427
  // const pens = deepClone(this.store.active, true);
3428
+ var gridSize = this.store.data.gridSize || this.store.options.gridSize;
3429
+ var _a = this.store.data, origin = _a.origin, scale = _a.scale;
3430
+ var autoAlignGrid = this.store.options.autoAlignGrid && this.store.data.grid;
3304
3431
  this.store.active.forEach(function (pen, i) {
3305
3432
  var _a;
3306
3433
  var _b = _this.movingPens[i], x = _b.x, y = _b.y;
3307
- Object.assign(pen, {
3308
- x: x,
3309
- y: y,
3310
- });
3434
+ var obj = { x: x, y: y };
3435
+ // 根据是否开启了自动网格对齐,来修正坐标
3436
+ if (autoAlignGrid && !_this.movingPens[i].type) {
3437
+ var rect = _this.getPenRect(_this.movingPens[i]);
3438
+ // 算出偏移了多少个网格
3439
+ var m = parseInt((rect.x / gridSize).toFixed());
3440
+ var n = parseInt((rect.y / gridSize).toFixed());
3441
+ var x1 = m * gridSize;
3442
+ var y1 = n * gridSize;
3443
+ // 算出最终的偏移坐标
3444
+ obj.x = origin.x + x1 * scale;
3445
+ obj.y = origin.y + y1 * scale;
3446
+ }
3447
+ Object.assign(pen, obj);
3311
3448
  (_a = pen.onMove) === null || _a === void 0 ? void 0 : _a.call(pen, pen);
3312
3449
  _this.updatePenRect(pen);
3313
3450
  _this.updateLines(pen);
@@ -3336,7 +3473,7 @@ var Canvas = /** @class */ (function () {
3336
3473
  // 避免选中图元的出错情况,this.dock为undefined
3337
3474
  if (!this.dock)
3338
3475
  return;
3339
- var _a = this.dock, xDock = _a.xDock, yDock = _a.yDock;
3476
+ var _b = this.dock, xDock = _b.xDock, yDock = _b.yDock;
3340
3477
  var dockPen;
3341
3478
  if (xDock) {
3342
3479
  dockPen = this.store.pens[xDock.penId];
@@ -3379,6 +3516,11 @@ var Canvas = /** @class */ (function () {
3379
3516
  }
3380
3517
  }
3381
3518
  }
3519
+ // 如果开启自动网格对齐,则需要重算activeRect和sizeCPs
3520
+ if (autoAlignGrid) {
3521
+ this.calcActiveRect();
3522
+ this.getSizeCPs();
3523
+ }
3382
3524
  // 此处是更新后的值
3383
3525
  this.pushHistory({
3384
3526
  type: EditType.Update,
@@ -3421,14 +3563,34 @@ var Canvas = /** @class */ (function () {
3421
3563
  this.canvasImageBottom.init();
3422
3564
  };
3423
3565
  Canvas.prototype.initTemplateCanvas = function (pens) {
3424
- pens.some(function (pen) { return pen.template !== undefined; }) &&
3566
+ // pens.some((pen) => pen.template !== undefined) &&
3567
+ // this.canvasTemplate.init();
3568
+ pens.some(function (pen) { return pen.canvasLayer === CanvasLayer.CanvasTemplate; }) &&
3425
3569
  this.canvasTemplate.init();
3426
3570
  };
3427
3571
  Canvas.prototype.hasImage = function (pen, isBottom) {
3428
3572
  var _this = this;
3429
3573
  var _a;
3430
- if (pen.image && pen.name !== 'gif' && !pen.isBottom == !isBottom) {
3431
- return true;
3574
+ // if (pen.image && pen.name !== 'gif' && !pen.isBottom == !isBottom) {
3575
+ // return true;
3576
+ // }
3577
+ if (pen.image && pen.name !== 'gif') {
3578
+ if (isBottom) {
3579
+ if (pen.canvasLayer === CanvasLayer.CanvasImageBottom) {
3580
+ return true;
3581
+ }
3582
+ else {
3583
+ return false;
3584
+ }
3585
+ }
3586
+ else {
3587
+ if (pen.canvasLayer === CanvasLayer.CanvasImage) {
3588
+ return true;
3589
+ }
3590
+ else {
3591
+ return false;
3592
+ }
3593
+ }
3432
3594
  }
3433
3595
  return (_a = pen.children) === null || _a === void 0 ? void 0 : _a.some(function (childId) {
3434
3596
  var child = _this.store.pens[childId];
@@ -3454,7 +3616,7 @@ var Canvas = /** @class */ (function () {
3454
3616
  this.patchFlags = true;
3455
3617
  };
3456
3618
  Canvas.prototype.active = function (pens, emit) {
3457
- var e_13, _a, _b;
3619
+ var e_14, _a, _b;
3458
3620
  if (emit === void 0) { emit = true; }
3459
3621
  if (this.store.active) {
3460
3622
  emit && this.store.emitter.emit('inactive', this.store.active);
@@ -3466,12 +3628,12 @@ var Canvas = /** @class */ (function () {
3466
3628
  setChildrenActive(pen, false);
3467
3629
  }
3468
3630
  }
3469
- catch (e_13_1) { e_13 = { error: e_13_1 }; }
3631
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
3470
3632
  finally {
3471
3633
  try {
3472
3634
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
3473
3635
  }
3474
- finally { if (e_13) throw e_13.error; }
3636
+ finally { if (e_14) throw e_14.error; }
3475
3637
  }
3476
3638
  }
3477
3639
  this.store.active = [];
@@ -3658,7 +3820,7 @@ var Canvas = /** @class */ (function () {
3658
3820
  return HoverType.None;
3659
3821
  };
3660
3822
  Canvas.prototype.resize = function (w, h) {
3661
- var e_14, _a;
3823
+ var e_15, _a;
3662
3824
  w = w || this.parentElement.clientWidth;
3663
3825
  h = h || this.parentElement.clientHeight;
3664
3826
  this.width = w;
@@ -3700,12 +3862,12 @@ var Canvas = /** @class */ (function () {
3700
3862
  calcInView(pen);
3701
3863
  }
3702
3864
  }
3703
- catch (e_14_1) { e_14 = { error: e_14_1 }; }
3865
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
3704
3866
  finally {
3705
3867
  try {
3706
3868
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3707
3869
  }
3708
- finally { if (e_14) throw e_14.error; }
3870
+ finally { if (e_15) throw e_15.error; }
3709
3871
  }
3710
3872
  };
3711
3873
  Canvas.prototype.clearCanvas = function () {
@@ -3773,7 +3935,7 @@ var Canvas = /** @class */ (function () {
3773
3935
  this.store.histories.splice(this.store.historyIndex + 1, this.store.histories.length - this.store.historyIndex - 1);
3774
3936
  }
3775
3937
  (_a = action.pens) === null || _a === void 0 ? void 0 : _a.forEach(function (pen) {
3776
- var e_15, _a;
3938
+ var e_16, _a;
3777
3939
  var found;
3778
3940
  if (action.initPens) {
3779
3941
  try {
@@ -3784,12 +3946,12 @@ var Canvas = /** @class */ (function () {
3784
3946
  }
3785
3947
  }
3786
3948
  }
3787
- catch (e_15_1) { e_15 = { error: e_15_1 }; }
3949
+ catch (e_16_1) { e_16 = { error: e_16_1 }; }
3788
3950
  finally {
3789
3951
  try {
3790
3952
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3791
3953
  }
3792
- finally { if (e_15) throw e_15.error; }
3954
+ finally { if (e_16) throw e_16.error; }
3793
3955
  }
3794
3956
  }
3795
3957
  if (found) {
@@ -3847,11 +4009,11 @@ var Canvas = /** @class */ (function () {
3847
4009
  var _this = this;
3848
4010
  var before = this.store.histories[this.store.historyIndex];
3849
4011
  if (before && before.type === EditType.Add) {
3850
- var pens_7 = [];
4012
+ var pens_8 = [];
3851
4013
  before.pens.forEach(function (pen) {
3852
- pens_7.push(_this.store.pens[pen.id]);
4014
+ pens_8.push(_this.store.pens[pen.id]);
3853
4015
  });
3854
- this.active(pens_7);
4016
+ this.active(pens_8);
3855
4017
  }
3856
4018
  };
3857
4019
  Canvas.prototype.doEditAction = function (action, undo) {
@@ -3887,6 +4049,13 @@ var Canvas = /** @class */ (function () {
3887
4049
  var i = _this.store.data.pens.findIndex(function (item) { return item.id === pen.id; });
3888
4050
  if (i > -1) {
3889
4051
  pen.calculative = _this.store.data.pens[i].calculative;
4052
+ if (_this.store.data.pens[i].type &&
4053
+ _this.store.data.pens[i].lastConnected) {
4054
+ for (var key in _this.store.data.pens[i].lastConnected) {
4055
+ _this.store.pens[key].connectedLines =
4056
+ _this.store.data.pens[i].lastConnected[key];
4057
+ }
4058
+ }
3890
4059
  _this.store.data.pens[i] = pen;
3891
4060
  _this.store.pens[pen.id] = pen;
3892
4061
  for (var k in pen) {
@@ -3911,7 +4080,7 @@ var Canvas = /** @class */ (function () {
3911
4080
  });
3912
4081
  break;
3913
4082
  case EditType.Delete:
3914
- action.pens.forEach(function (aPen) {
4083
+ action.pens.reverse().forEach(function (aPen) {
3915
4084
  var _a, _b;
3916
4085
  var pen = deepClone(aPen, true);
3917
4086
  if (!pen.calculative) {
@@ -3922,9 +4091,14 @@ var Canvas = /** @class */ (function () {
3922
4091
  : _this.store.data.pens.length, 0, pen);
3923
4092
  // 先放进去,pens 可能是子节点在前,而父节点在后
3924
4093
  _this.store.pens[pen.id] = pen;
4094
+ if (pen.type && pen.lastConnected) {
4095
+ for (var key in pen.lastConnected) {
4096
+ _this.store.pens[key].connectedLines = pen.lastConnected[key];
4097
+ }
4098
+ }
3925
4099
  pen.calculative.canvas = _this;
3926
4100
  });
3927
- action.pens.forEach(function (aPen) {
4101
+ action.pens.reverse().forEach(function (aPen) {
3928
4102
  var pen = _this.store.pens[aPen.id];
3929
4103
  var rect = _this.getPenRect(pen, action.origin, action.scale);
3930
4104
  _this.setPenRect(pen, rect, false);
@@ -3958,7 +4132,8 @@ var Canvas = /** @class */ (function () {
3958
4132
  if (Math.abs(this.store.lastScale - this.store.data.scale) < 0.0001 &&
3959
4133
  this.store.sameTemplate &&
3960
4134
  this.store.templatePens[pen.id] &&
3961
- pen.template) {
4135
+ // pen.template
4136
+ pen.canvasLayer === CanvasLayer.CanvasTemplate) {
3962
4137
  pen = this.store.templatePens[pen.id];
3963
4138
  this.store.data.pens.push(pen);
3964
4139
  this.updatePenRect(pen);
@@ -3984,6 +4159,18 @@ var Canvas = /** @class */ (function () {
3984
4159
  if (!pen.lineHeight) {
3985
4160
  pen.lineHeight = lineHeight;
3986
4161
  }
4162
+ if (pen.image && pen.name !== 'gif' && pen.canvasLayer === undefined) {
4163
+ if (pen.isBottom) {
4164
+ pen.canvasLayer = CanvasLayer.CanvasImageBottom;
4165
+ }
4166
+ else {
4167
+ pen.canvasLayer = CanvasLayer.CanvasImage;
4168
+ }
4169
+ delete pen.isBottom;
4170
+ }
4171
+ if (pen.template) {
4172
+ pen.canvasLayer = CanvasLayer.CanvasTemplate;
4173
+ }
3987
4174
  pen.calculative = { canvas: this, singleton: (_a = pen.calculative) === null || _a === void 0 ? void 0 : _a.singleton };
3988
4175
  if (pen.video || pen.audio) {
3989
4176
  pen.calculative.onended = function (pen) {
@@ -4234,7 +4421,8 @@ var Canvas = /** @class */ (function () {
4234
4421
  pen.calculative.imgNaturalHeight = img.naturalHeight || pen.iconHeight;
4235
4422
  globalStore.htmlElements[pen.image] = img;
4236
4423
  _this.imageLoaded();
4237
- if (pen.template) {
4424
+ // if (pen.template) {
4425
+ if (pen.canvasLayer === CanvasLayer.CanvasTemplate) {
4238
4426
  _this.templateImageLoaded();
4239
4427
  }
4240
4428
  };
@@ -4254,7 +4442,8 @@ var Canvas = /** @class */ (function () {
4254
4442
  pen.calculative.imgNaturalHeight =
4255
4443
  img.naturalHeight || pen.iconHeight;
4256
4444
  this.imageLoaded(); // TODO: 重绘图片层 有延时器,可能卡顿
4257
- if (pen.template) {
4445
+ // if (pen.template) {
4446
+ if (pen.canvasLayer === CanvasLayer.CanvasTemplate) {
4258
4447
  this.templateImageLoaded();
4259
4448
  }
4260
4449
  }
@@ -4286,7 +4475,8 @@ var Canvas = /** @class */ (function () {
4286
4475
  img_1.naturalHeight || pen.iconHeight;
4287
4476
  globalStore.htmlElements[pen.image] = img_1;
4288
4477
  _this.imageLoaded();
4289
- if (pen.template) {
4478
+ // if (pen.template) {
4479
+ if (pen.canvasLayer === CanvasLayer.CanvasTemplate) {
4290
4480
  _this.templateImageLoaded();
4291
4481
  }
4292
4482
  };
@@ -4316,7 +4506,8 @@ var Canvas = /** @class */ (function () {
4316
4506
  pen.calculative.backgroundImg = img_2;
4317
4507
  globalStore.htmlElements[pen.backgroundImage] = img_2;
4318
4508
  _this.imageLoaded();
4319
- if (pen.template) {
4509
+ // if (pen.template) {
4510
+ if (pen.canvasLayer === CanvasLayer.CanvasTemplate) {
4320
4511
  _this.templateImageLoaded();
4321
4512
  }
4322
4513
  };
@@ -4345,7 +4536,10 @@ var Canvas = /** @class */ (function () {
4345
4536
  pen.calculative.strokeImg = img_3;
4346
4537
  globalStore.htmlElements[pen.strokeImage] = img_3;
4347
4538
  _this.imageLoaded();
4348
- if (pen.template && pen.name !== 'gif') {
4539
+ if (
4540
+ // pen.template
4541
+ pen.canvasLayer === CanvasLayer.CanvasTemplate &&
4542
+ pen.name !== 'gif') {
4349
4543
  _this.templateImageLoaded();
4350
4544
  }
4351
4545
  };
@@ -4516,7 +4710,7 @@ var Canvas = /** @class */ (function () {
4516
4710
  this.onMovePens();
4517
4711
  };
4518
4712
  Canvas.prototype.onMovePens = function () {
4519
- var e_16, _a;
4713
+ var e_17, _a;
4520
4714
  var _b;
4521
4715
  var map = this.parent.map;
4522
4716
  if (map && map.isShow) {
@@ -4541,12 +4735,12 @@ var Canvas = /** @class */ (function () {
4541
4735
  }
4542
4736
  }
4543
4737
  }
4544
- catch (e_16_1) { e_16 = { error: e_16_1 }; }
4738
+ catch (e_17_1) { e_17 = { error: e_17_1 }; }
4545
4739
  finally {
4546
4740
  try {
4547
4741
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
4548
4742
  }
4549
- finally { if (e_16) throw e_16.error; }
4743
+ finally { if (e_17) throw e_17.error; }
4550
4744
  }
4551
4745
  };
4552
4746
  /**
@@ -4644,7 +4838,7 @@ var Canvas = /** @class */ (function () {
4644
4838
  this.calcActiveRect();
4645
4839
  };
4646
4840
  Canvas.prototype.rotatePens = function (e) {
4647
- var e_17, _a;
4841
+ var e_18, _a;
4648
4842
  var _this = this;
4649
4843
  if (!this.initPens) {
4650
4844
  this.initPens = deepClone(this.getAllByPens(this.store.active));
@@ -4671,12 +4865,12 @@ var Canvas = /** @class */ (function () {
4671
4865
  this.updateLines(pen);
4672
4866
  }
4673
4867
  }
4674
- catch (e_17_1) { e_17 = { error: e_17_1 }; }
4868
+ catch (e_18_1) { e_18 = { error: e_18_1 }; }
4675
4869
  finally {
4676
4870
  try {
4677
4871
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
4678
4872
  }
4679
- finally { if (e_17) throw e_17.error; }
4873
+ finally { if (e_18) throw e_18.error; }
4680
4874
  }
4681
4875
  this.lastRotate = this.activeRect.rotate;
4682
4876
  this.getSizeCPs();
@@ -5413,7 +5607,7 @@ var Canvas = /** @class */ (function () {
5413
5607
  this.initLineRect(line);
5414
5608
  };
5415
5609
  Canvas.prototype.restoreNodeAnimate = function (pen) {
5416
- var _a;
5610
+ var _a, _b;
5417
5611
  if (pen.calculative.initRect) {
5418
5612
  if (pen.keepAnimateState) {
5419
5613
  for (var k in pen) {
@@ -5470,10 +5664,14 @@ var Canvas = /** @class */ (function () {
5470
5664
  pen.calculative.worldRect = pen.calculative.initRect;
5471
5665
  }
5472
5666
  this.updatePenRect(pen, { worldRectIsReady: true });
5667
+ this.updateLines(pen);
5473
5668
  if (pen.calculative.text !== pen.text) {
5474
5669
  pen.calculative.text = pen.text;
5475
5670
  calcTextLines(pen);
5476
5671
  }
5672
+ if ((_b = this.store.active) === null || _b === void 0 ? void 0 : _b.length) {
5673
+ this.calcActiveRect();
5674
+ }
5477
5675
  pen.calculative.initRect = undefined;
5478
5676
  }
5479
5677
  };
@@ -5650,7 +5848,7 @@ var Canvas = /** @class */ (function () {
5650
5848
  return;
5651
5849
  }
5652
5850
  pens.forEach(function (pen) {
5653
- var _a, _b, _c, _d;
5851
+ var _a, _b, _c, _d, _e;
5654
5852
  if (pen.calculative.pause) {
5655
5853
  var d = Date.now() - pen.calculative.pause;
5656
5854
  pen.calculative.pause = undefined;
@@ -5685,6 +5883,18 @@ var Canvas = /** @class */ (function () {
5685
5883
  }
5686
5884
  _this.store.animateMap.set(pen, _this.getFrameProps(pen));
5687
5885
  }
5886
+ else {
5887
+ if ((_e = pen.animations) === null || _e === void 0 ? void 0 : _e.length) {
5888
+ //默认执行line的第一个动画
5889
+ var animate = deepClone(pen.animations[0]);
5890
+ delete animate.name;
5891
+ animate.currentAnimation = 0;
5892
+ _this.parent.setValue(__assign({ id: pen.id }, animate), {
5893
+ doEvent: false,
5894
+ history: false,
5895
+ });
5896
+ }
5897
+ }
5688
5898
  _this.store.animates.add(pen);
5689
5899
  }
5690
5900
  }
@@ -5710,7 +5920,7 @@ var Canvas = /** @class */ (function () {
5710
5920
  return;
5711
5921
  }
5712
5922
  requestAnimationFrame(function () {
5713
- var e_18, _a;
5923
+ var e_19, _a;
5714
5924
  var now = Date.now();
5715
5925
  if (now - _this.lastAnimateRender < _this.store.options.animateInterval) {
5716
5926
  if (_this.store.animates.size > 0) {
@@ -5795,12 +6005,12 @@ var Canvas = /** @class */ (function () {
5795
6005
  _loop_5(pen);
5796
6006
  }
5797
6007
  }
5798
- catch (e_18_1) { e_18 = { error: e_18_1 }; }
6008
+ catch (e_19_1) { e_19 = { error: e_19_1 }; }
5799
6009
  finally {
5800
6010
  try {
5801
6011
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
5802
6012
  }
5803
- finally { if (e_18) throw e_18.error; }
6013
+ finally { if (e_19) throw e_19.error; }
5804
6014
  }
5805
6015
  if (active) {
5806
6016
  _this.calcActiveRect();
@@ -5887,7 +6097,7 @@ var Canvas = /** @class */ (function () {
5887
6097
  var _a;
5888
6098
  return __awaiter(this, void 0, void 0, function () {
5889
6099
  var clipboardText, clipboard, _b, _c, offset, pos, curPage, rootPens, rootPens_1, rootPens_1_1, pen;
5890
- var e_19, _d;
6100
+ var e_20, _d;
5891
6101
  return __generator(this, function (_e) {
5892
6102
  switch (_e.label) {
5893
6103
  case 0:
@@ -5960,12 +6170,12 @@ var Canvas = /** @class */ (function () {
5960
6170
  this.pastePen(pen, undefined);
5961
6171
  }
5962
6172
  }
5963
- catch (e_19_1) { e_19 = { error: e_19_1 }; }
6173
+ catch (e_20_1) { e_20 = { error: e_20_1 }; }
5964
6174
  finally {
5965
6175
  try {
5966
6176
  if (rootPens_1_1 && !rootPens_1_1.done && (_d = rootPens_1.return)) _d.call(rootPens_1);
5967
6177
  }
5968
- finally { if (e_19) throw e_19.error; }
6178
+ finally { if (e_20) throw e_20.error; }
5969
6179
  }
5970
6180
  sessionStorage.setItem('page', clipboard.page);
5971
6181
  this.active(rootPens);
@@ -5983,20 +6193,20 @@ var Canvas = /** @class */ (function () {
5983
6193
  * @param pens 不包含子节点
5984
6194
  */
5985
6195
  Canvas.prototype.getAllByPens = function (pens) {
5986
- var e_20, _a;
6196
+ var e_21, _a;
5987
6197
  var retPens = [];
5988
6198
  try {
5989
- for (var pens_8 = __values(pens), pens_8_1 = pens_8.next(); !pens_8_1.done; pens_8_1 = pens_8.next()) {
5990
- var pen = pens_8_1.value;
6199
+ for (var pens_9 = __values(pens), pens_9_1 = pens_9.next(); !pens_9_1.done; pens_9_1 = pens_9.next()) {
6200
+ var pen = pens_9_1.value;
5991
6201
  retPens.push.apply(retPens, __spreadArray([], __read(deepClone(getAllChildren(pen, this.store), true)), false));
5992
6202
  }
5993
6203
  }
5994
- catch (e_20_1) { e_20 = { error: e_20_1 }; }
6204
+ catch (e_21_1) { e_21 = { error: e_21_1 }; }
5995
6205
  finally {
5996
6206
  try {
5997
- if (pens_8_1 && !pens_8_1.done && (_a = pens_8.return)) _a.call(pens_8);
6207
+ if (pens_9_1 && !pens_9_1.done && (_a = pens_9.return)) _a.call(pens_9);
5998
6208
  }
5999
- finally { if (e_20) throw e_20.error; }
6209
+ finally { if (e_21) throw e_21.error; }
6000
6210
  }
6001
6211
  return retPens.concat(pens);
6002
6212
  };
@@ -6039,7 +6249,7 @@ var Canvas = /** @class */ (function () {
6039
6249
  * @param pastePens 此处复制的全部 pens (包含子节点)
6040
6250
  */
6041
6251
  Canvas.prototype.changeNodeConnectedLine = function (oldId, line, pastePens) {
6042
- var e_21, _a;
6252
+ var e_22, _a;
6043
6253
  var _b;
6044
6254
  var from = line.anchors[0];
6045
6255
  var to = line.anchors[line.anchors.length - 1];
@@ -6075,12 +6285,12 @@ var Canvas = /** @class */ (function () {
6075
6285
  _loop_7(anchor);
6076
6286
  }
6077
6287
  }
6078
- catch (e_21_1) { e_21 = { error: e_21_1 }; }
6288
+ catch (e_22_1) { e_22 = { error: e_22_1 }; }
6079
6289
  finally {
6080
6290
  try {
6081
6291
  if (anchors_1_1 && !anchors_1_1.done && (_a = anchors_1.return)) _a.call(anchors_1);
6082
6292
  }
6083
- finally { if (e_21) throw e_21.error; }
6293
+ finally { if (e_22) throw e_22.error; }
6084
6294
  }
6085
6295
  };
6086
6296
  Canvas.prototype.delete = function (pens, canDelLocked, history) {
@@ -6134,6 +6344,9 @@ var Canvas = /** @class */ (function () {
6134
6344
  return;
6135
6345
  }
6136
6346
  pens.forEach(function (pen) {
6347
+ if (pen.type) {
6348
+ pen.lastConnected = {};
6349
+ }
6137
6350
  if (!pen.parentId) {
6138
6351
  if (!canDelLocked && pen.locked) {
6139
6352
  return;
@@ -6491,7 +6704,7 @@ var Canvas = /** @class */ (function () {
6491
6704
  if (k === 'rotate') {
6492
6705
  oldRotate = pen.calculative.rotate || 0;
6493
6706
  }
6494
- else if (k === 'isBottom') {
6707
+ else if (k === 'canvasLayer' || k === 'isBottom') {
6495
6708
  containIsBottom = true;
6496
6709
  }
6497
6710
  else if (k === 'image') {
@@ -6595,17 +6808,30 @@ var Canvas = /** @class */ (function () {
6595
6808
  }
6596
6809
  else if (willRenderImage) {
6597
6810
  // 存在先有 image 后无 image 的情况
6598
- if (pen.isBottom) {
6811
+ // if (pen.isBottom) {
6812
+ // this.canvasImageBottom.init();
6813
+ // } else {
6814
+ // this.canvasImage.init();
6815
+ // }
6816
+ if (pen.canvasLayer === undefined) {
6817
+ pen.canvasLayer = CanvasLayer.CanvasImageBottom;
6818
+ pen.calculative.canvasLayer = CanvasLayer.CanvasImageBottom;
6819
+ }
6820
+ if (pen.canvasLayer === CanvasLayer.CanvasImageBottom) {
6599
6821
  this.canvasImageBottom.init();
6600
6822
  }
6601
- else {
6823
+ else if (pen.canvasLayer === CanvasLayer.CanvasImage) {
6602
6824
  this.canvasImage.init();
6603
6825
  }
6604
6826
  }
6605
6827
  else {
6606
6828
  this.initImageCanvas([pen]);
6607
6829
  }
6608
- if (data.template !== undefined || pen.template) {
6830
+ // if (data.template !== undefined || pen.template) {
6831
+ // this.initTemplateCanvas([pen]);
6832
+ // }
6833
+ if (data.canvasLayer !== undefined ||
6834
+ pen.canvasLayer === CanvasLayer.CanvasTemplate) {
6609
6835
  this.initTemplateCanvas([pen]);
6610
6836
  }
6611
6837
  };
@@ -6628,9 +6854,9 @@ var Canvas = /** @class */ (function () {
6628
6854
  Object.assign(pen, rect);
6629
6855
  }
6630
6856
  else {
6631
- var _a = this.store.data, origin_2 = _a.origin, scale = _a.scale;
6632
- pen.x = origin_2.x + rect.x * scale;
6633
- pen.y = origin_2.y + rect.y * scale;
6857
+ var _a = this.store.data, origin_3 = _a.origin, scale = _a.scale;
6858
+ pen.x = origin_3.x + rect.x * scale;
6859
+ pen.y = origin_3.y + rect.y * scale;
6634
6860
  pen.width = rect.width * scale;
6635
6861
  pen.height = rect.height * scale;
6636
6862
  }
@@ -6661,7 +6887,7 @@ var Canvas = /** @class */ (function () {
6661
6887
  };
6662
6888
  };
6663
6889
  Canvas.prototype.toPng = function (padding, callback, containBkImg, maxWidth) {
6664
- var e_22, _a;
6890
+ var e_23, _a;
6665
6891
  if (padding === void 0) { padding = 2; }
6666
6892
  if (containBkImg === void 0) { containBkImg = false; }
6667
6893
  var rect = getRect(this.store.data.pens);
@@ -6694,7 +6920,11 @@ var Canvas = /** @class */ (function () {
6694
6920
  var width = this.store.data.width || this.store.options.width;
6695
6921
  var height = this.store.data.height || this.store.options.height;
6696
6922
  //大屏
6697
- if (width && height) {
6923
+ var isV = false;
6924
+ if (width && height && !this.store.data.component) {
6925
+ isV = true;
6926
+ }
6927
+ if (isV) {
6698
6928
  rect.x = this.store.data.origin.x;
6699
6929
  rect.y = this.store.data.origin.y;
6700
6930
  rect.width = width * this.store.data.scale;
@@ -6740,7 +6970,7 @@ var Canvas = /** @class */ (function () {
6740
6970
  // 绘制背景颜色
6741
6971
  ctx.save();
6742
6972
  ctx.fillStyle = background;
6743
- if (width && height) {
6973
+ if (isV) {
6744
6974
  ctx.fillRect(0, 0, vRect.width + (p[1] + p[3]) * _scale, vRect.height + (p[0] + p[2]) * _scale);
6745
6975
  }
6746
6976
  else {
@@ -6749,7 +6979,7 @@ var Canvas = /** @class */ (function () {
6749
6979
  ctx.restore();
6750
6980
  }
6751
6981
  if (isDrawBkImg) {
6752
- if (width && height) {
6982
+ if (isV) {
6753
6983
  ctx.drawImage(this.store.bkImg, p[3] * _scale || 0, p[0] * _scale || 0, vRect.width, vRect.height);
6754
6984
  }
6755
6985
  else {
@@ -6763,7 +6993,7 @@ var Canvas = /** @class */ (function () {
6763
6993
  }
6764
6994
  else {
6765
6995
  // 平移画布,画笔的 worldRect 不变化
6766
- if (width && height) {
6996
+ if (isV) {
6767
6997
  ctx.translate(-oldRect.x + p[3] * _scale || 0, -oldRect.y + p[0] * _scale || 0);
6768
6998
  }
6769
6999
  else {
@@ -6784,17 +7014,17 @@ var Canvas = /** @class */ (function () {
6784
7014
  renderPenRaw(ctx, pen);
6785
7015
  }
6786
7016
  else {
6787
- renderPen(ctx, pen);
7017
+ renderPen(ctx, pen, true);
6788
7018
  }
6789
7019
  pen.calculative.active = active;
6790
7020
  }
6791
7021
  }
6792
- catch (e_22_1) { e_22 = { error: e_22_1 }; }
7022
+ catch (e_23_1) { e_23 = { error: e_23_1 }; }
6793
7023
  finally {
6794
7024
  try {
6795
7025
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
6796
7026
  }
6797
- finally { if (e_22) throw e_22.error; }
7027
+ finally { if (e_23) throw e_23.error; }
6798
7028
  }
6799
7029
  if (callback) {
6800
7030
  canvas.toBlob(callback);
@@ -6803,7 +7033,7 @@ var Canvas = /** @class */ (function () {
6803
7033
  return canvas.toDataURL();
6804
7034
  };
6805
7035
  Canvas.prototype.activeToPng = function (padding) {
6806
- var e_23, _a;
7036
+ var e_24, _a;
6807
7037
  if (padding === void 0) { padding = 2; }
6808
7038
  var allPens = this.getAllByPens(this.store.active);
6809
7039
  var ids = allPens.map(function (pen) { return pen.id; });
@@ -6853,12 +7083,12 @@ var Canvas = /** @class */ (function () {
6853
7083
  }
6854
7084
  }
6855
7085
  }
6856
- catch (e_23_1) { e_23 = { error: e_23_1 }; }
7086
+ catch (e_24_1) { e_24 = { error: e_24_1 }; }
6857
7087
  finally {
6858
7088
  try {
6859
7089
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
6860
7090
  }
6861
- finally { if (e_23) throw e_23.error; }
7091
+ finally { if (e_24) throw e_24.error; }
6862
7092
  }
6863
7093
  return canvas.toDataURL();
6864
7094
  };