@meta2d/core 1.0.33 → 1.0.35
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.
- package/package.json +1 -1
- package/src/canvas/canvas.d.ts +9 -1
- package/src/canvas/canvas.js +413 -131
- package/src/canvas/canvas.js.map +1 -1
- package/src/canvas/canvasTemplate.js +45 -14
- package/src/canvas/canvasTemplate.js.map +1 -1
- package/src/core.d.ts +5 -1
- package/src/core.js +144 -67
- package/src/core.js.map +1 -1
- package/src/diagrams/iframe.js +22 -7
- package/src/diagrams/iframe.js.map +1 -1
- package/src/event/event.d.ts +1 -1
- package/src/event/event.js.map +1 -1
- package/src/options.d.ts +6 -0
- package/src/options.js +6 -0
- package/src/options.js.map +1 -1
- package/src/pen/model.d.ts +12 -0
- package/src/pen/model.js +4 -0
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.d.ts +3 -2
- package/src/pen/render.js +97 -27
- package/src/pen/render.js.map +1 -1
- package/src/store/store.d.ts +12 -1
- package/src/store/store.js +2 -0
- package/src/store/store.js.map +1 -1
package/src/canvas/canvas.js
CHANGED
|
@@ -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, } 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, } 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';
|
|
@@ -298,11 +298,15 @@ var Canvas = /** @class */ (function () {
|
|
|
298
298
|
}
|
|
299
299
|
}
|
|
300
300
|
else {
|
|
301
|
+
var offset = 0.2;
|
|
302
|
+
if (e.deltaY.toString().indexOf('.') !== -1) {
|
|
303
|
+
offset = 0.01;
|
|
304
|
+
}
|
|
301
305
|
if (e.deltaY > 0) {
|
|
302
|
-
scaleOff = -
|
|
306
|
+
scaleOff = -offset;
|
|
303
307
|
}
|
|
304
308
|
else {
|
|
305
|
-
scaleOff =
|
|
309
|
+
scaleOff = offset;
|
|
306
310
|
}
|
|
307
311
|
}
|
|
308
312
|
var x = e.offsetX, y = e.offsetY;
|
|
@@ -538,6 +542,9 @@ var Canvas = /** @class */ (function () {
|
|
|
538
542
|
case 'v':
|
|
539
543
|
case 'V':
|
|
540
544
|
if (!e.ctrlKey && !e.metaKey) {
|
|
545
|
+
if (_this.pencil) {
|
|
546
|
+
_this.stopPencil();
|
|
547
|
+
}
|
|
541
548
|
if (_this.drawingLineName) {
|
|
542
549
|
_this.finishDrawline();
|
|
543
550
|
_this.drawingLineName = '';
|
|
@@ -552,7 +559,16 @@ var Canvas = /** @class */ (function () {
|
|
|
552
559
|
break;
|
|
553
560
|
case 'b':
|
|
554
561
|
case 'B':
|
|
555
|
-
_this.
|
|
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
|
+
}
|
|
556
572
|
break;
|
|
557
573
|
case 'y':
|
|
558
574
|
case 'Y':
|
|
@@ -1048,7 +1064,7 @@ var Canvas = /** @class */ (function () {
|
|
|
1048
1064
|
else {
|
|
1049
1065
|
switch (_this.hoverType) {
|
|
1050
1066
|
case HoverType.None:
|
|
1051
|
-
_this.store.data.rule &&
|
|
1067
|
+
(_this.store.data.rule || _this.store.options.rule) &&
|
|
1052
1068
|
!_this.store.options.disableRuleLine &&
|
|
1053
1069
|
_this.addRuleLine(e);
|
|
1054
1070
|
if (_this.store.options.resizeMode) {
|
|
@@ -1374,6 +1390,7 @@ var Canvas = /** @class */ (function () {
|
|
|
1374
1390
|
_this.store.emitter.emit('contextmenu', {
|
|
1375
1391
|
e: e,
|
|
1376
1392
|
clientRect: _this.clientRect,
|
|
1393
|
+
pen: _this.store.hover,
|
|
1377
1394
|
});
|
|
1378
1395
|
}
|
|
1379
1396
|
_this.mouseRight = MouseRight.None;
|
|
@@ -2514,7 +2531,12 @@ var Canvas = /** @class */ (function () {
|
|
|
2514
2531
|
if (tem < 0) {
|
|
2515
2532
|
tem = 0;
|
|
2516
2533
|
}
|
|
2517
|
-
|
|
2534
|
+
var height = pen.fontSize * scale < 12 ? tem * font_scale : tem * scale * font_scale;
|
|
2535
|
+
if (height < pen.fontSize * pen.lineHeight * scale) {
|
|
2536
|
+
height = pen.fontSize * pen.lineHeight * scale;
|
|
2537
|
+
style += "top:-" + height / 2 + "px;";
|
|
2538
|
+
}
|
|
2539
|
+
style += "height:" + height + "px;";
|
|
2518
2540
|
}
|
|
2519
2541
|
var _textWidth = null;
|
|
2520
2542
|
if (pen.textWidth) {
|
|
@@ -2971,12 +2993,15 @@ var Canvas = /** @class */ (function () {
|
|
|
2971
2993
|
});
|
|
2972
2994
|
};
|
|
2973
2995
|
Canvas.prototype.dropPens = function (pens, e) {
|
|
2996
|
+
var _a;
|
|
2974
2997
|
return __awaiter(this, void 0, void 0, function () {
|
|
2975
|
-
var pens_2, pens_2_1, pen, pens_3, pens_3_1, pen, pens_4, pens_4_1, pen, width, height, rect_1, flag,
|
|
2976
|
-
var e_7,
|
|
2977
|
-
|
|
2978
|
-
|
|
2998
|
+
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;
|
|
2999
|
+
var e_7, _b, e_8, _c, e_9, _d, e_10, _e, e_11, _f;
|
|
3000
|
+
var _this = this;
|
|
3001
|
+
return __generator(this, function (_g) {
|
|
3002
|
+
switch (_g.label) {
|
|
2979
3003
|
case 0:
|
|
3004
|
+
this.randomIdObj = {};
|
|
2980
3005
|
try {
|
|
2981
3006
|
for (pens_2 = __values(pens), pens_2_1 = pens_2.next(); !pens_2_1.done; pens_2_1 = pens_2.next()) {
|
|
2982
3007
|
pen = pens_2_1.value;
|
|
@@ -2987,13 +3012,38 @@ var Canvas = /** @class */ (function () {
|
|
|
2987
3012
|
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
2988
3013
|
finally {
|
|
2989
3014
|
try {
|
|
2990
|
-
if (pens_2_1 && !pens_2_1.done && (
|
|
3015
|
+
if (pens_2_1 && !pens_2_1.done && (_b = pens_2.return)) _b.call(pens_2);
|
|
2991
3016
|
}
|
|
2992
3017
|
finally { if (e_7) throw e_7.error; }
|
|
2993
3018
|
}
|
|
3019
|
+
if (Object.keys(this.randomIdObj).length !== 0) {
|
|
3020
|
+
try {
|
|
3021
|
+
for (pens_3 = __values(pens), pens_3_1 = pens_3.next(); !pens_3_1.done; pens_3_1 = pens_3.next()) {
|
|
3022
|
+
pen = pens_3_1.value;
|
|
3023
|
+
if (pen.type) {
|
|
3024
|
+
pen.anchors[0].connectTo = this.randomIdObj[pen.anchors[0].connectTo];
|
|
3025
|
+
pen.anchors[pen.anchors.length - 1].connectTo =
|
|
3026
|
+
this.randomIdObj[pen.anchors[pen.anchors.length - 1].connectTo];
|
|
3027
|
+
}
|
|
3028
|
+
else {
|
|
3029
|
+
(_a = pen.connectedLines) === null || _a === void 0 ? void 0 : _a.forEach(function (item) {
|
|
3030
|
+
item.lineAnchor = _this.randomIdObj[item.lineAnchor];
|
|
3031
|
+
item.lineId = _this.randomIdObj[item.lineId];
|
|
3032
|
+
});
|
|
3033
|
+
}
|
|
3034
|
+
}
|
|
3035
|
+
}
|
|
3036
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
3037
|
+
finally {
|
|
3038
|
+
try {
|
|
3039
|
+
if (pens_3_1 && !pens_3_1.done && (_c = pens_3.return)) _c.call(pens_3);
|
|
3040
|
+
}
|
|
3041
|
+
finally { if (e_8) throw e_8.error; }
|
|
3042
|
+
}
|
|
3043
|
+
}
|
|
2994
3044
|
try {
|
|
2995
|
-
for (
|
|
2996
|
-
pen =
|
|
3045
|
+
for (pens_4 = __values(pens), pens_4_1 = pens_4.next(); !pens_4_1.done; pens_4_1 = pens_4.next()) {
|
|
3046
|
+
pen = pens_4_1.value;
|
|
2997
3047
|
// TODO: randomCombineId 会更改 id, 此处应该不存在空 id
|
|
2998
3048
|
if (!pen.id) {
|
|
2999
3049
|
pen.id = s8();
|
|
@@ -3002,12 +3052,12 @@ var Canvas = /** @class */ (function () {
|
|
|
3002
3052
|
this.store.pens[pen.id] = pen;
|
|
3003
3053
|
}
|
|
3004
3054
|
}
|
|
3005
|
-
catch (
|
|
3055
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
3006
3056
|
finally {
|
|
3007
3057
|
try {
|
|
3008
|
-
if (
|
|
3058
|
+
if (pens_4_1 && !pens_4_1.done && (_d = pens_4.return)) _d.call(pens_4);
|
|
3009
3059
|
}
|
|
3010
|
-
finally { if (
|
|
3060
|
+
finally { if (e_9) throw e_9.error; }
|
|
3011
3061
|
}
|
|
3012
3062
|
try {
|
|
3013
3063
|
// // 计算区域
|
|
@@ -3015,8 +3065,8 @@ var Canvas = /** @class */ (function () {
|
|
|
3015
3065
|
// // 组合节点才需要提前计算
|
|
3016
3066
|
// Array.isArray(pen.children) && pen.children.length > 0 && this.updatePenRect(pen);
|
|
3017
3067
|
// }
|
|
3018
|
-
for (
|
|
3019
|
-
pen =
|
|
3068
|
+
for (pens_5 = __values(pens), pens_5_1 = pens_5.next(); !pens_5_1.done; pens_5_1 = pens_5.next()) {
|
|
3069
|
+
pen = pens_5_1.value;
|
|
3020
3070
|
if (!pen.parentId) {
|
|
3021
3071
|
pen.width *= this.store.data.scale;
|
|
3022
3072
|
pen.height *= this.store.data.scale;
|
|
@@ -3029,12 +3079,12 @@ var Canvas = /** @class */ (function () {
|
|
|
3029
3079
|
}
|
|
3030
3080
|
}
|
|
3031
3081
|
}
|
|
3032
|
-
catch (
|
|
3082
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
3033
3083
|
finally {
|
|
3034
3084
|
try {
|
|
3035
|
-
if (
|
|
3085
|
+
if (pens_5_1 && !pens_5_1.done && (_e = pens_5.return)) _e.call(pens_5);
|
|
3036
3086
|
}
|
|
3037
|
-
finally { if (
|
|
3087
|
+
finally { if (e_10) throw e_10.error; }
|
|
3038
3088
|
}
|
|
3039
3089
|
width = this.store.data.width || this.store.options.width;
|
|
3040
3090
|
height = this.store.data.height || this.store.options.height;
|
|
@@ -3047,8 +3097,8 @@ var Canvas = /** @class */ (function () {
|
|
|
3047
3097
|
};
|
|
3048
3098
|
flag = true;
|
|
3049
3099
|
try {
|
|
3050
|
-
for (
|
|
3051
|
-
pen =
|
|
3100
|
+
for (pens_6 = __values(pens), pens_6_1 = pens_6.next(); !pens_6_1.done; pens_6_1 = pens_6.next()) {
|
|
3101
|
+
pen = pens_6_1.value;
|
|
3052
3102
|
if (!pen.parentId) {
|
|
3053
3103
|
points = [
|
|
3054
3104
|
{ x: pen.x, y: pen.y },
|
|
@@ -3083,12 +3133,12 @@ var Canvas = /** @class */ (function () {
|
|
|
3083
3133
|
}
|
|
3084
3134
|
}
|
|
3085
3135
|
}
|
|
3086
|
-
catch (
|
|
3136
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
3087
3137
|
finally {
|
|
3088
3138
|
try {
|
|
3089
|
-
if (
|
|
3139
|
+
if (pens_6_1 && !pens_6_1.done && (_f = pens_6.return)) _f.call(pens_6);
|
|
3090
3140
|
}
|
|
3091
|
-
finally { if (
|
|
3141
|
+
finally { if (e_11) throw e_11.error; }
|
|
3092
3142
|
}
|
|
3093
3143
|
if (flag) {
|
|
3094
3144
|
console.info('画笔在大屏范围外');
|
|
@@ -3097,7 +3147,7 @@ var Canvas = /** @class */ (function () {
|
|
|
3097
3147
|
}
|
|
3098
3148
|
return [4 /*yield*/, this.addPens(pens, true)];
|
|
3099
3149
|
case 1:
|
|
3100
|
-
|
|
3150
|
+
_g.sent();
|
|
3101
3151
|
this.active(pens.filter(function (pen) { return !pen.parentId; }));
|
|
3102
3152
|
this.render();
|
|
3103
3153
|
this.externalElements.focus(); // 聚焦
|
|
@@ -3107,8 +3157,35 @@ var Canvas = /** @class */ (function () {
|
|
|
3107
3157
|
});
|
|
3108
3158
|
};
|
|
3109
3159
|
Canvas.prototype.randomCombineId = function (pen, pens, parentId) {
|
|
3110
|
-
var
|
|
3160
|
+
var e_12, _a;
|
|
3161
|
+
var beforeIds = null;
|
|
3162
|
+
if (pen.type) {
|
|
3163
|
+
if (pen.anchors[0].connectTo ||
|
|
3164
|
+
pen.anchors[pen.anchors.length - 1].connectTo) {
|
|
3165
|
+
beforeIds = [
|
|
3166
|
+
pen.id,
|
|
3167
|
+
pen.anchors[0].id,
|
|
3168
|
+
pen.anchors[pen.anchors.length - 1].id,
|
|
3169
|
+
];
|
|
3170
|
+
}
|
|
3171
|
+
}
|
|
3172
|
+
else {
|
|
3173
|
+
if (pen.connectedLines && pen.connectedLines.length) {
|
|
3174
|
+
beforeIds = [pen.id];
|
|
3175
|
+
}
|
|
3176
|
+
}
|
|
3111
3177
|
randomId(pen);
|
|
3178
|
+
if (beforeIds) {
|
|
3179
|
+
if (beforeIds.length === 1) {
|
|
3180
|
+
this.randomIdObj[beforeIds[0]] = pen.id;
|
|
3181
|
+
}
|
|
3182
|
+
else {
|
|
3183
|
+
this.randomIdObj[beforeIds[0]] = pen.id;
|
|
3184
|
+
this.randomIdObj[beforeIds[1]] = pen.anchors[0].id;
|
|
3185
|
+
this.randomIdObj[beforeIds[2]] = pen.anchors[pen.anchors.length - 1].id;
|
|
3186
|
+
}
|
|
3187
|
+
}
|
|
3188
|
+
//处理链接关系
|
|
3112
3189
|
pen.parentId = parentId;
|
|
3113
3190
|
var newChildren = [];
|
|
3114
3191
|
if (Array.isArray(pen.children)) {
|
|
@@ -3124,12 +3201,12 @@ var Canvas = /** @class */ (function () {
|
|
|
3124
3201
|
_loop_4(childId);
|
|
3125
3202
|
}
|
|
3126
3203
|
}
|
|
3127
|
-
catch (
|
|
3204
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
3128
3205
|
finally {
|
|
3129
3206
|
try {
|
|
3130
3207
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3131
3208
|
}
|
|
3132
|
-
finally { if (
|
|
3209
|
+
finally { if (e_12) throw e_12.error; }
|
|
3133
3210
|
}
|
|
3134
3211
|
}
|
|
3135
3212
|
pen.children = newChildren;
|
|
@@ -3137,8 +3214,8 @@ var Canvas = /** @class */ (function () {
|
|
|
3137
3214
|
};
|
|
3138
3215
|
Canvas.prototype.addPens = function (pens, history) {
|
|
3139
3216
|
return __awaiter(this, void 0, void 0, function () {
|
|
3140
|
-
var _a, list,
|
|
3141
|
-
var
|
|
3217
|
+
var _a, list, pens_7, pens_7_1, pen;
|
|
3218
|
+
var e_13, _b;
|
|
3142
3219
|
return __generator(this, function (_c) {
|
|
3143
3220
|
switch (_c.label) {
|
|
3144
3221
|
case 0:
|
|
@@ -3154,8 +3231,8 @@ var Canvas = /** @class */ (function () {
|
|
|
3154
3231
|
}
|
|
3155
3232
|
list = [];
|
|
3156
3233
|
try {
|
|
3157
|
-
for (
|
|
3158
|
-
pen =
|
|
3234
|
+
for (pens_7 = __values(pens), pens_7_1 = pens_7.next(); !pens_7_1.done; pens_7_1 = pens_7.next()) {
|
|
3235
|
+
pen = pens_7_1.value;
|
|
3159
3236
|
if (this.beforeAddPen && this.beforeAddPen(pen) != true) {
|
|
3160
3237
|
continue;
|
|
3161
3238
|
}
|
|
@@ -3163,12 +3240,12 @@ var Canvas = /** @class */ (function () {
|
|
|
3163
3240
|
list.push(pen);
|
|
3164
3241
|
}
|
|
3165
3242
|
}
|
|
3166
|
-
catch (
|
|
3243
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
3167
3244
|
finally {
|
|
3168
3245
|
try {
|
|
3169
|
-
if (
|
|
3246
|
+
if (pens_7_1 && !pens_7_1.done && (_b = pens_7.return)) _b.call(pens_7);
|
|
3170
3247
|
}
|
|
3171
|
-
finally { if (
|
|
3248
|
+
finally { if (e_13) throw e_13.error; }
|
|
3172
3249
|
}
|
|
3173
3250
|
this.render();
|
|
3174
3251
|
this.store.emitter.emit('add', list);
|
|
@@ -3235,7 +3312,7 @@ var Canvas = /** @class */ (function () {
|
|
|
3235
3312
|
};
|
|
3236
3313
|
};
|
|
3237
3314
|
Canvas.prototype.addRuleLine = function (e) {
|
|
3238
|
-
var _a = this.store.data, offsetX = _a.x, offsetY = _a.y;
|
|
3315
|
+
var _a = this.store.data, offsetX = _a.x, offsetY = _a.y, scale = _a.scale, origin = _a.origin;
|
|
3239
3316
|
// 靠近左上角的 x ,y
|
|
3240
3317
|
var x = e.x + offsetX;
|
|
3241
3318
|
var y = e.y + offsetY;
|
|
@@ -3250,12 +3327,24 @@ var Canvas = /** @class */ (function () {
|
|
|
3250
3327
|
lineX = -offsetX;
|
|
3251
3328
|
width = this.width;
|
|
3252
3329
|
otherPX = 1;
|
|
3330
|
+
if (!e.ctrlKey) {
|
|
3331
|
+
//找最近的标尺线
|
|
3332
|
+
lineY =
|
|
3333
|
+
Math.round((lineY - origin.y) / (scale * 10)) * (scale * 10) +
|
|
3334
|
+
origin.y;
|
|
3335
|
+
}
|
|
3253
3336
|
}
|
|
3254
3337
|
else if (y < x && y < 20) {
|
|
3255
3338
|
// 绘制一条垂直线
|
|
3256
3339
|
lineY = -offsetY;
|
|
3257
3340
|
height = this.height;
|
|
3258
3341
|
otherPY = 1;
|
|
3342
|
+
if (!e.ctrlKey) {
|
|
3343
|
+
//找最近的标尺线
|
|
3344
|
+
lineX =
|
|
3345
|
+
Math.round((lineX - origin.x) / (scale * 10)) * (scale * 10) +
|
|
3346
|
+
origin.x;
|
|
3347
|
+
}
|
|
3259
3348
|
}
|
|
3260
3349
|
else {
|
|
3261
3350
|
return;
|
|
@@ -3283,6 +3372,37 @@ var Canvas = /** @class */ (function () {
|
|
|
3283
3372
|
],
|
|
3284
3373
|
});
|
|
3285
3374
|
};
|
|
3375
|
+
/**
|
|
3376
|
+
* @description 调整pen的坐标,让pen按照网格自动对齐
|
|
3377
|
+
* @author Joseph Ho
|
|
3378
|
+
* @date 14/11/2023
|
|
3379
|
+
* @memberof Canvas
|
|
3380
|
+
*/
|
|
3381
|
+
Canvas.prototype.alignPenToGrid = function (pen) {
|
|
3382
|
+
var _a;
|
|
3383
|
+
var autoAlignGrid = this.store.options.autoAlignGrid && this.store.data.grid;
|
|
3384
|
+
if (autoAlignGrid) {
|
|
3385
|
+
var gridSize = this.store.data.gridSize || this.store.options.gridSize;
|
|
3386
|
+
var _b = this.store.data, origin_2 = _b.origin, scale = _b.scale;
|
|
3387
|
+
var x = pen.x, y = pen.y;
|
|
3388
|
+
var obj = { x: x, y: y };
|
|
3389
|
+
var rect = this.getPenRect(pen);
|
|
3390
|
+
// 算出偏移了多少个网格
|
|
3391
|
+
var m = parseInt((rect.x / gridSize).toFixed());
|
|
3392
|
+
var n = parseInt((rect.y / gridSize).toFixed());
|
|
3393
|
+
console.log(m, n);
|
|
3394
|
+
var x1 = m * gridSize;
|
|
3395
|
+
var y1 = n * gridSize;
|
|
3396
|
+
// 算出最终的偏移坐标
|
|
3397
|
+
obj.x = origin_2.x + x1 * scale;
|
|
3398
|
+
obj.y = origin_2.y + y1 * scale;
|
|
3399
|
+
Object.assign(pen, obj);
|
|
3400
|
+
(_a = pen.onMove) === null || _a === void 0 ? void 0 : _a.call(pen, pen);
|
|
3401
|
+
this.updatePenRect(pen);
|
|
3402
|
+
this.calcActiveRect();
|
|
3403
|
+
this.getSizeCPs();
|
|
3404
|
+
}
|
|
3405
|
+
};
|
|
3286
3406
|
/**
|
|
3287
3407
|
* 拖拽结束,数据更新到 active.pens
|
|
3288
3408
|
*/
|
|
@@ -3291,13 +3411,26 @@ var Canvas = /** @class */ (function () {
|
|
|
3291
3411
|
// 鼠标松手才更新,此处是更新前的值
|
|
3292
3412
|
var initPens = deepClone(this.store.active, true);
|
|
3293
3413
|
// const pens = deepClone(this.store.active, true);
|
|
3414
|
+
var gridSize = this.store.data.gridSize || this.store.options.gridSize;
|
|
3415
|
+
var _a = this.store.data, origin = _a.origin, scale = _a.scale;
|
|
3416
|
+
var autoAlignGrid = this.store.options.autoAlignGrid && this.store.data.grid;
|
|
3294
3417
|
this.store.active.forEach(function (pen, i) {
|
|
3295
3418
|
var _a;
|
|
3296
3419
|
var _b = _this.movingPens[i], x = _b.x, y = _b.y;
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3420
|
+
var obj = { x: x, y: y };
|
|
3421
|
+
// 根据是否开启了自动网格对齐,来修正坐标
|
|
3422
|
+
if (autoAlignGrid) {
|
|
3423
|
+
var rect = _this.getPenRect(_this.movingPens[i]);
|
|
3424
|
+
// 算出偏移了多少个网格
|
|
3425
|
+
var m = parseInt((rect.x / gridSize).toFixed());
|
|
3426
|
+
var n = parseInt((rect.y / gridSize).toFixed());
|
|
3427
|
+
var x1 = m * gridSize;
|
|
3428
|
+
var y1 = n * gridSize;
|
|
3429
|
+
// 算出最终的偏移坐标
|
|
3430
|
+
obj.x = origin.x + x1 * scale;
|
|
3431
|
+
obj.y = origin.y + y1 * scale;
|
|
3432
|
+
}
|
|
3433
|
+
Object.assign(pen, obj);
|
|
3301
3434
|
(_a = pen.onMove) === null || _a === void 0 ? void 0 : _a.call(pen, pen);
|
|
3302
3435
|
_this.updatePenRect(pen);
|
|
3303
3436
|
_this.updateLines(pen);
|
|
@@ -3326,7 +3459,7 @@ var Canvas = /** @class */ (function () {
|
|
|
3326
3459
|
// 避免选中图元的出错情况,this.dock为undefined
|
|
3327
3460
|
if (!this.dock)
|
|
3328
3461
|
return;
|
|
3329
|
-
var
|
|
3462
|
+
var _b = this.dock, xDock = _b.xDock, yDock = _b.yDock;
|
|
3330
3463
|
var dockPen;
|
|
3331
3464
|
if (xDock) {
|
|
3332
3465
|
dockPen = this.store.pens[xDock.penId];
|
|
@@ -3369,6 +3502,11 @@ var Canvas = /** @class */ (function () {
|
|
|
3369
3502
|
}
|
|
3370
3503
|
}
|
|
3371
3504
|
}
|
|
3505
|
+
// 如果开启自动网格对齐,则需要重算activeRect和sizeCPs
|
|
3506
|
+
if (autoAlignGrid) {
|
|
3507
|
+
this.calcActiveRect();
|
|
3508
|
+
this.getSizeCPs();
|
|
3509
|
+
}
|
|
3372
3510
|
// 此处是更新后的值
|
|
3373
3511
|
this.pushHistory({
|
|
3374
3512
|
type: EditType.Update,
|
|
@@ -3444,7 +3582,7 @@ var Canvas = /** @class */ (function () {
|
|
|
3444
3582
|
this.patchFlags = true;
|
|
3445
3583
|
};
|
|
3446
3584
|
Canvas.prototype.active = function (pens, emit) {
|
|
3447
|
-
var
|
|
3585
|
+
var e_14, _a, _b;
|
|
3448
3586
|
if (emit === void 0) { emit = true; }
|
|
3449
3587
|
if (this.store.active) {
|
|
3450
3588
|
emit && this.store.emitter.emit('inactive', this.store.active);
|
|
@@ -3456,12 +3594,12 @@ var Canvas = /** @class */ (function () {
|
|
|
3456
3594
|
setChildrenActive(pen, false);
|
|
3457
3595
|
}
|
|
3458
3596
|
}
|
|
3459
|
-
catch (
|
|
3597
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
3460
3598
|
finally {
|
|
3461
3599
|
try {
|
|
3462
3600
|
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
3463
3601
|
}
|
|
3464
|
-
finally { if (
|
|
3602
|
+
finally { if (e_14) throw e_14.error; }
|
|
3465
3603
|
}
|
|
3466
3604
|
}
|
|
3467
3605
|
this.store.active = [];
|
|
@@ -3648,7 +3786,7 @@ var Canvas = /** @class */ (function () {
|
|
|
3648
3786
|
return HoverType.None;
|
|
3649
3787
|
};
|
|
3650
3788
|
Canvas.prototype.resize = function (w, h) {
|
|
3651
|
-
var
|
|
3789
|
+
var e_15, _a;
|
|
3652
3790
|
w = w || this.parentElement.clientWidth;
|
|
3653
3791
|
h = h || this.parentElement.clientHeight;
|
|
3654
3792
|
this.width = w;
|
|
@@ -3690,12 +3828,12 @@ var Canvas = /** @class */ (function () {
|
|
|
3690
3828
|
calcInView(pen);
|
|
3691
3829
|
}
|
|
3692
3830
|
}
|
|
3693
|
-
catch (
|
|
3831
|
+
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
3694
3832
|
finally {
|
|
3695
3833
|
try {
|
|
3696
3834
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3697
3835
|
}
|
|
3698
|
-
finally { if (
|
|
3836
|
+
finally { if (e_15) throw e_15.error; }
|
|
3699
3837
|
}
|
|
3700
3838
|
};
|
|
3701
3839
|
Canvas.prototype.clearCanvas = function () {
|
|
@@ -3763,7 +3901,7 @@ var Canvas = /** @class */ (function () {
|
|
|
3763
3901
|
this.store.histories.splice(this.store.historyIndex + 1, this.store.histories.length - this.store.historyIndex - 1);
|
|
3764
3902
|
}
|
|
3765
3903
|
(_a = action.pens) === null || _a === void 0 ? void 0 : _a.forEach(function (pen) {
|
|
3766
|
-
var
|
|
3904
|
+
var e_16, _a;
|
|
3767
3905
|
var found;
|
|
3768
3906
|
if (action.initPens) {
|
|
3769
3907
|
try {
|
|
@@ -3774,12 +3912,12 @@ var Canvas = /** @class */ (function () {
|
|
|
3774
3912
|
}
|
|
3775
3913
|
}
|
|
3776
3914
|
}
|
|
3777
|
-
catch (
|
|
3915
|
+
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
3778
3916
|
finally {
|
|
3779
3917
|
try {
|
|
3780
3918
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3781
3919
|
}
|
|
3782
|
-
finally { if (
|
|
3920
|
+
finally { if (e_16) throw e_16.error; }
|
|
3783
3921
|
}
|
|
3784
3922
|
}
|
|
3785
3923
|
if (found) {
|
|
@@ -3837,11 +3975,11 @@ var Canvas = /** @class */ (function () {
|
|
|
3837
3975
|
var _this = this;
|
|
3838
3976
|
var before = this.store.histories[this.store.historyIndex];
|
|
3839
3977
|
if (before && before.type === EditType.Add) {
|
|
3840
|
-
var
|
|
3978
|
+
var pens_8 = [];
|
|
3841
3979
|
before.pens.forEach(function (pen) {
|
|
3842
|
-
|
|
3980
|
+
pens_8.push(_this.store.pens[pen.id]);
|
|
3843
3981
|
});
|
|
3844
|
-
this.active(
|
|
3982
|
+
this.active(pens_8);
|
|
3845
3983
|
}
|
|
3846
3984
|
};
|
|
3847
3985
|
Canvas.prototype.doEditAction = function (action, undo) {
|
|
@@ -3877,6 +4015,11 @@ var Canvas = /** @class */ (function () {
|
|
|
3877
4015
|
var i = _this.store.data.pens.findIndex(function (item) { return item.id === pen.id; });
|
|
3878
4016
|
if (i > -1) {
|
|
3879
4017
|
pen.calculative = _this.store.data.pens[i].calculative;
|
|
4018
|
+
if (_this.store.data.pens[i].type && _this.store.data.pens[i].lastConnected) {
|
|
4019
|
+
for (var key in _this.store.data.pens[i].lastConnected) {
|
|
4020
|
+
_this.store.pens[key].connectedLines = _this.store.data.pens[i].lastConnected[key];
|
|
4021
|
+
}
|
|
4022
|
+
}
|
|
3880
4023
|
_this.store.data.pens[i] = pen;
|
|
3881
4024
|
_this.store.pens[pen.id] = pen;
|
|
3882
4025
|
for (var k in pen) {
|
|
@@ -3901,18 +4044,25 @@ var Canvas = /** @class */ (function () {
|
|
|
3901
4044
|
});
|
|
3902
4045
|
break;
|
|
3903
4046
|
case EditType.Delete:
|
|
3904
|
-
action.pens.forEach(function (aPen) {
|
|
3905
|
-
var _a;
|
|
4047
|
+
action.pens.reverse().forEach(function (aPen) {
|
|
4048
|
+
var _a, _b;
|
|
3906
4049
|
var pen = deepClone(aPen, true);
|
|
3907
4050
|
if (!pen.calculative) {
|
|
3908
4051
|
pen.calculative = {};
|
|
3909
4052
|
}
|
|
3910
|
-
_this.store.data.pens.splice((_a = pen.calculative) === null || _a === void 0 ? void 0 : _a.layer
|
|
4053
|
+
_this.store.data.pens.splice(((_a = pen.calculative) === null || _a === void 0 ? void 0 : _a.layer) !== -1
|
|
4054
|
+
? (_b = pen.calculative) === null || _b === void 0 ? void 0 : _b.layer
|
|
4055
|
+
: _this.store.data.pens.length, 0, pen);
|
|
3911
4056
|
// 先放进去,pens 可能是子节点在前,而父节点在后
|
|
3912
4057
|
_this.store.pens[pen.id] = pen;
|
|
4058
|
+
if (pen.type && pen.lastConnected) {
|
|
4059
|
+
for (var key in pen.lastConnected) {
|
|
4060
|
+
_this.store.pens[key].connectedLines = pen.lastConnected[key];
|
|
4061
|
+
}
|
|
4062
|
+
}
|
|
3913
4063
|
pen.calculative.canvas = _this;
|
|
3914
4064
|
});
|
|
3915
|
-
action.pens.forEach(function (aPen) {
|
|
4065
|
+
action.pens.reverse().forEach(function (aPen) {
|
|
3916
4066
|
var pen = _this.store.pens[aPen.id];
|
|
3917
4067
|
var rect = _this.getPenRect(pen, action.origin, action.scale);
|
|
3918
4068
|
_this.setPenRect(pen, rect, false);
|
|
@@ -4000,6 +4150,7 @@ var Canvas = /** @class */ (function () {
|
|
|
4000
4150
|
}
|
|
4001
4151
|
!pen.rotate && (pen.rotate = 0);
|
|
4002
4152
|
this.loadImage(pen);
|
|
4153
|
+
this.parent.penNetwork(pen);
|
|
4003
4154
|
};
|
|
4004
4155
|
Canvas.prototype.drawline = function (mouse) {
|
|
4005
4156
|
var _a;
|
|
@@ -4503,7 +4654,7 @@ var Canvas = /** @class */ (function () {
|
|
|
4503
4654
|
this.onMovePens();
|
|
4504
4655
|
};
|
|
4505
4656
|
Canvas.prototype.onMovePens = function () {
|
|
4506
|
-
var
|
|
4657
|
+
var e_17, _a;
|
|
4507
4658
|
var _b;
|
|
4508
4659
|
var map = this.parent.map;
|
|
4509
4660
|
if (map && map.isShow) {
|
|
@@ -4528,12 +4679,12 @@ var Canvas = /** @class */ (function () {
|
|
|
4528
4679
|
}
|
|
4529
4680
|
}
|
|
4530
4681
|
}
|
|
4531
|
-
catch (
|
|
4682
|
+
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
4532
4683
|
finally {
|
|
4533
4684
|
try {
|
|
4534
4685
|
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
4535
4686
|
}
|
|
4536
|
-
finally { if (
|
|
4687
|
+
finally { if (e_17) throw e_17.error; }
|
|
4537
4688
|
}
|
|
4538
4689
|
};
|
|
4539
4690
|
/**
|
|
@@ -4631,7 +4782,7 @@ var Canvas = /** @class */ (function () {
|
|
|
4631
4782
|
this.calcActiveRect();
|
|
4632
4783
|
};
|
|
4633
4784
|
Canvas.prototype.rotatePens = function (e) {
|
|
4634
|
-
var
|
|
4785
|
+
var e_18, _a;
|
|
4635
4786
|
var _this = this;
|
|
4636
4787
|
if (!this.initPens) {
|
|
4637
4788
|
this.initPens = deepClone(this.getAllByPens(this.store.active));
|
|
@@ -4658,12 +4809,12 @@ var Canvas = /** @class */ (function () {
|
|
|
4658
4809
|
this.updateLines(pen);
|
|
4659
4810
|
}
|
|
4660
4811
|
}
|
|
4661
|
-
catch (
|
|
4812
|
+
catch (e_18_1) { e_18 = { error: e_18_1 }; }
|
|
4662
4813
|
finally {
|
|
4663
4814
|
try {
|
|
4664
4815
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
4665
4816
|
}
|
|
4666
|
-
finally { if (
|
|
4817
|
+
finally { if (e_18) throw e_18.error; }
|
|
4667
4818
|
}
|
|
4668
4819
|
this.lastRotate = this.activeRect.rotate;
|
|
4669
4820
|
this.getSizeCPs();
|
|
@@ -5400,7 +5551,7 @@ var Canvas = /** @class */ (function () {
|
|
|
5400
5551
|
this.initLineRect(line);
|
|
5401
5552
|
};
|
|
5402
5553
|
Canvas.prototype.restoreNodeAnimate = function (pen) {
|
|
5403
|
-
var _a;
|
|
5554
|
+
var _a, _b;
|
|
5404
5555
|
if (pen.calculative.initRect) {
|
|
5405
5556
|
if (pen.keepAnimateState) {
|
|
5406
5557
|
for (var k in pen) {
|
|
@@ -5457,10 +5608,14 @@ var Canvas = /** @class */ (function () {
|
|
|
5457
5608
|
pen.calculative.worldRect = pen.calculative.initRect;
|
|
5458
5609
|
}
|
|
5459
5610
|
this.updatePenRect(pen, { worldRectIsReady: true });
|
|
5611
|
+
this.updateLines(pen);
|
|
5460
5612
|
if (pen.calculative.text !== pen.text) {
|
|
5461
5613
|
pen.calculative.text = pen.text;
|
|
5462
5614
|
calcTextLines(pen);
|
|
5463
5615
|
}
|
|
5616
|
+
if ((_b = this.store.active) === null || _b === void 0 ? void 0 : _b.length) {
|
|
5617
|
+
this.calcActiveRect();
|
|
5618
|
+
}
|
|
5464
5619
|
pen.calculative.initRect = undefined;
|
|
5465
5620
|
}
|
|
5466
5621
|
};
|
|
@@ -5547,6 +5702,9 @@ var Canvas = /** @class */ (function () {
|
|
|
5547
5702
|
}
|
|
5548
5703
|
_this.store.path2dMap.set(line, globalStore.path2dDraws[line.name](line));
|
|
5549
5704
|
_this.patchFlagsLines.add(line);
|
|
5705
|
+
if (line.calculative.gradientSmooth) {
|
|
5706
|
+
line.calculative.gradientAnimatePath = getGradientAnimatePath(line);
|
|
5707
|
+
}
|
|
5550
5708
|
change && getLineLength(line);
|
|
5551
5709
|
});
|
|
5552
5710
|
};
|
|
@@ -5634,7 +5792,7 @@ var Canvas = /** @class */ (function () {
|
|
|
5634
5792
|
return;
|
|
5635
5793
|
}
|
|
5636
5794
|
pens.forEach(function (pen) {
|
|
5637
|
-
var _a, _b, _c;
|
|
5795
|
+
var _a, _b, _c, _d, _e;
|
|
5638
5796
|
if (pen.calculative.pause) {
|
|
5639
5797
|
var d = Date.now() - pen.calculative.pause;
|
|
5640
5798
|
pen.calculative.pause = undefined;
|
|
@@ -5647,11 +5805,40 @@ var Canvas = /** @class */ (function () {
|
|
|
5647
5805
|
(_a = pen.calculative.media) === null || _a === void 0 ? void 0 : _a.play();
|
|
5648
5806
|
(_b = pen.onStartVideo) === null || _b === void 0 ? void 0 : _b.call(pen, pen);
|
|
5649
5807
|
}
|
|
5650
|
-
else if (pen.type ||
|
|
5808
|
+
else if (pen.type ||
|
|
5809
|
+
((_c = pen.frames) === null || _c === void 0 ? void 0 : _c.length) ||
|
|
5810
|
+
(pen.animations && pen.animations.length)) {
|
|
5651
5811
|
//存储动画初始状态
|
|
5652
5812
|
if (!pen.type) {
|
|
5813
|
+
if (!pen.frames && pen.animations && pen.animations.length) {
|
|
5814
|
+
//无活动动画
|
|
5815
|
+
var autoIndex = (_d = pen.animations) === null || _d === void 0 ? void 0 : _d.findIndex(function (i) { return i.autoPlay; });
|
|
5816
|
+
var index = autoIndex === -1 ? 0 : autoIndex;
|
|
5817
|
+
var animate = deepClone(pen.animations[index]);
|
|
5818
|
+
delete animate.name;
|
|
5819
|
+
animate.currentAnimation = index;
|
|
5820
|
+
if (!pen.type && animate.frames) {
|
|
5821
|
+
animate.showDuration = _this.parent.calcAnimateDuration(animate);
|
|
5822
|
+
}
|
|
5823
|
+
_this.parent.setValue(__assign({ id: pen.id }, animate), {
|
|
5824
|
+
doEvent: false,
|
|
5825
|
+
history: false,
|
|
5826
|
+
});
|
|
5827
|
+
}
|
|
5653
5828
|
_this.store.animateMap.set(pen, _this.getFrameProps(pen));
|
|
5654
5829
|
}
|
|
5830
|
+
else {
|
|
5831
|
+
if ((_e = pen.animations) === null || _e === void 0 ? void 0 : _e.length) {
|
|
5832
|
+
//默认执行line的第一个动画
|
|
5833
|
+
var animate = deepClone(pen.animations[0]);
|
|
5834
|
+
delete animate.name;
|
|
5835
|
+
animate.currentAnimation = 0;
|
|
5836
|
+
_this.parent.setValue(__assign({ id: pen.id }, animate), {
|
|
5837
|
+
doEvent: false,
|
|
5838
|
+
history: false,
|
|
5839
|
+
});
|
|
5840
|
+
}
|
|
5841
|
+
}
|
|
5655
5842
|
_this.store.animates.add(pen);
|
|
5656
5843
|
}
|
|
5657
5844
|
}
|
|
@@ -5677,7 +5864,7 @@ var Canvas = /** @class */ (function () {
|
|
|
5677
5864
|
return;
|
|
5678
5865
|
}
|
|
5679
5866
|
requestAnimationFrame(function () {
|
|
5680
|
-
var
|
|
5867
|
+
var e_19, _a;
|
|
5681
5868
|
var now = Date.now();
|
|
5682
5869
|
if (now - _this.lastAnimateRender < _this.store.options.animateInterval) {
|
|
5683
5870
|
if (_this.store.animates.size > 0) {
|
|
@@ -5762,12 +5949,12 @@ var Canvas = /** @class */ (function () {
|
|
|
5762
5949
|
_loop_5(pen);
|
|
5763
5950
|
}
|
|
5764
5951
|
}
|
|
5765
|
-
catch (
|
|
5952
|
+
catch (e_19_1) { e_19 = { error: e_19_1 }; }
|
|
5766
5953
|
finally {
|
|
5767
5954
|
try {
|
|
5768
5955
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
5769
5956
|
}
|
|
5770
|
-
finally { if (
|
|
5957
|
+
finally { if (e_19) throw e_19.error; }
|
|
5771
5958
|
}
|
|
5772
5959
|
if (active) {
|
|
5773
5960
|
_this.calcActiveRect();
|
|
@@ -5854,7 +6041,7 @@ var Canvas = /** @class */ (function () {
|
|
|
5854
6041
|
var _a;
|
|
5855
6042
|
return __awaiter(this, void 0, void 0, function () {
|
|
5856
6043
|
var clipboardText, clipboard, _b, _c, offset, pos, curPage, rootPens, rootPens_1, rootPens_1_1, pen;
|
|
5857
|
-
var
|
|
6044
|
+
var e_20, _d;
|
|
5858
6045
|
return __generator(this, function (_e) {
|
|
5859
6046
|
switch (_e.label) {
|
|
5860
6047
|
case 0:
|
|
@@ -5927,12 +6114,12 @@ var Canvas = /** @class */ (function () {
|
|
|
5927
6114
|
this.pastePen(pen, undefined);
|
|
5928
6115
|
}
|
|
5929
6116
|
}
|
|
5930
|
-
catch (
|
|
6117
|
+
catch (e_20_1) { e_20 = { error: e_20_1 }; }
|
|
5931
6118
|
finally {
|
|
5932
6119
|
try {
|
|
5933
6120
|
if (rootPens_1_1 && !rootPens_1_1.done && (_d = rootPens_1.return)) _d.call(rootPens_1);
|
|
5934
6121
|
}
|
|
5935
|
-
finally { if (
|
|
6122
|
+
finally { if (e_20) throw e_20.error; }
|
|
5936
6123
|
}
|
|
5937
6124
|
sessionStorage.setItem('page', clipboard.page);
|
|
5938
6125
|
this.active(rootPens);
|
|
@@ -5950,20 +6137,20 @@ var Canvas = /** @class */ (function () {
|
|
|
5950
6137
|
* @param pens 不包含子节点
|
|
5951
6138
|
*/
|
|
5952
6139
|
Canvas.prototype.getAllByPens = function (pens) {
|
|
5953
|
-
var
|
|
6140
|
+
var e_21, _a;
|
|
5954
6141
|
var retPens = [];
|
|
5955
6142
|
try {
|
|
5956
|
-
for (var
|
|
5957
|
-
var pen =
|
|
6143
|
+
for (var pens_9 = __values(pens), pens_9_1 = pens_9.next(); !pens_9_1.done; pens_9_1 = pens_9.next()) {
|
|
6144
|
+
var pen = pens_9_1.value;
|
|
5958
6145
|
retPens.push.apply(retPens, __spreadArray([], __read(deepClone(getAllChildren(pen, this.store), true)), false));
|
|
5959
6146
|
}
|
|
5960
6147
|
}
|
|
5961
|
-
catch (
|
|
6148
|
+
catch (e_21_1) { e_21 = { error: e_21_1 }; }
|
|
5962
6149
|
finally {
|
|
5963
6150
|
try {
|
|
5964
|
-
if (
|
|
6151
|
+
if (pens_9_1 && !pens_9_1.done && (_a = pens_9.return)) _a.call(pens_9);
|
|
5965
6152
|
}
|
|
5966
|
-
finally { if (
|
|
6153
|
+
finally { if (e_21) throw e_21.error; }
|
|
5967
6154
|
}
|
|
5968
6155
|
return retPens.concat(pens);
|
|
5969
6156
|
};
|
|
@@ -6006,7 +6193,7 @@ var Canvas = /** @class */ (function () {
|
|
|
6006
6193
|
* @param pastePens 此处复制的全部 pens (包含子节点)
|
|
6007
6194
|
*/
|
|
6008
6195
|
Canvas.prototype.changeNodeConnectedLine = function (oldId, line, pastePens) {
|
|
6009
|
-
var
|
|
6196
|
+
var e_22, _a;
|
|
6010
6197
|
var _b;
|
|
6011
6198
|
var from = line.anchors[0];
|
|
6012
6199
|
var to = line.anchors[line.anchors.length - 1];
|
|
@@ -6042,12 +6229,12 @@ var Canvas = /** @class */ (function () {
|
|
|
6042
6229
|
_loop_7(anchor);
|
|
6043
6230
|
}
|
|
6044
6231
|
}
|
|
6045
|
-
catch (
|
|
6232
|
+
catch (e_22_1) { e_22 = { error: e_22_1 }; }
|
|
6046
6233
|
finally {
|
|
6047
6234
|
try {
|
|
6048
6235
|
if (anchors_1_1 && !anchors_1_1.done && (_a = anchors_1.return)) _a.call(anchors_1);
|
|
6049
6236
|
}
|
|
6050
|
-
finally { if (
|
|
6237
|
+
finally { if (e_22) throw e_22.error; }
|
|
6051
6238
|
}
|
|
6052
6239
|
};
|
|
6053
6240
|
Canvas.prototype.delete = function (pens, canDelLocked, history) {
|
|
@@ -6079,7 +6266,7 @@ var Canvas = /** @class */ (function () {
|
|
|
6079
6266
|
return [2 /*return*/];
|
|
6080
6267
|
}
|
|
6081
6268
|
deletePens = [];
|
|
6082
|
-
this._del(pens, deletePens);
|
|
6269
|
+
this._del(pens, deletePens, canDelLocked);
|
|
6083
6270
|
this.initImageCanvas(deletePens);
|
|
6084
6271
|
this.initTemplateCanvas(deletePens);
|
|
6085
6272
|
this.inactive();
|
|
@@ -6095,15 +6282,17 @@ var Canvas = /** @class */ (function () {
|
|
|
6095
6282
|
});
|
|
6096
6283
|
});
|
|
6097
6284
|
};
|
|
6098
|
-
Canvas.prototype._del = function (pens, delPens) {
|
|
6285
|
+
Canvas.prototype._del = function (pens, delPens, canDelLocked) {
|
|
6099
6286
|
var _this = this;
|
|
6100
6287
|
if (!pens) {
|
|
6101
6288
|
return;
|
|
6102
6289
|
}
|
|
6103
6290
|
pens.forEach(function (pen) {
|
|
6291
|
+
if (pen.type) {
|
|
6292
|
+
pen.lastConnected = {};
|
|
6293
|
+
}
|
|
6104
6294
|
if (!pen.parentId) {
|
|
6105
|
-
if (pen.locked) {
|
|
6106
|
-
// TODO: canDelLocked 是 true , locked 仍然删不掉
|
|
6295
|
+
if (!canDelLocked && pen.locked) {
|
|
6107
6296
|
return;
|
|
6108
6297
|
}
|
|
6109
6298
|
else {
|
|
@@ -6269,9 +6458,60 @@ var Canvas = /** @class */ (function () {
|
|
|
6269
6458
|
sheet.insertRule('.meta2d-input ul li{padding: 5px 12px;line-height: 22px;white-space: nowrap;cursor: pointer;}');
|
|
6270
6459
|
sheet.insertRule('.meta2d-input ul li:hover{background: #eeeeee;}');
|
|
6271
6460
|
sheet.insertRule(".input-div::-webkit-scrollbar {display:none}");
|
|
6461
|
+
sheet.insertRule(".input-div{scrollbar-width: none;}");
|
|
6272
6462
|
sheet.insertRule('.meta2d-input .input-div{resize:none;border:none;outline:none;background:transparent;flex-grow:1;height:100%;width: 100%;left:0;top:0;display:flex;text-align: center;justify-content: center;flex-direction: column;}');
|
|
6273
6463
|
sheet.insertRule(".input-div div{}");
|
|
6274
6464
|
}
|
|
6465
|
+
this.inputDiv.onfocus = function (e) {
|
|
6466
|
+
if (navigator.userAgent.includes('Firefox')) {
|
|
6467
|
+
if (!e.target.innerText) {
|
|
6468
|
+
var left = _this.inputDiv.offsetWidth / 2;
|
|
6469
|
+
var inputDivStyle = window.getComputedStyle(_this.inputDiv, null);
|
|
6470
|
+
if (inputDivStyle.textAlign !== 'center') {
|
|
6471
|
+
left = 0;
|
|
6472
|
+
}
|
|
6473
|
+
_this.inputDiv.innerHTML = "<br style=\"margin-left:" + left + "px;margin-top:4px;\" />";
|
|
6474
|
+
}
|
|
6475
|
+
}
|
|
6476
|
+
else {
|
|
6477
|
+
//无文本时,光标确保居中
|
|
6478
|
+
if (!e.target.innerText) {
|
|
6479
|
+
var inputDivStyle = window.getComputedStyle(_this.inputDiv, null);
|
|
6480
|
+
if (inputDivStyle.justifyContent === 'center') {
|
|
6481
|
+
_this.inputDiv.style.paddingTop = " " + (_this.inputDiv.offsetHeight / 2 -
|
|
6482
|
+
parseFloat(inputDivStyle.lineHeight) / 2) + "px";
|
|
6483
|
+
}
|
|
6484
|
+
}
|
|
6485
|
+
else {
|
|
6486
|
+
_this.inputDiv.style.paddingTop = '';
|
|
6487
|
+
}
|
|
6488
|
+
}
|
|
6489
|
+
};
|
|
6490
|
+
this.inputDiv.oninput = function (e) {
|
|
6491
|
+
// //无文本时,光标确保居中
|
|
6492
|
+
if (navigator.userAgent.includes('Firefox')) {
|
|
6493
|
+
if (!e.target.innerText.trim()) {
|
|
6494
|
+
var left = _this.inputDiv.offsetWidth / 2;
|
|
6495
|
+
var inputDivStyle = window.getComputedStyle(_this.inputDiv, null);
|
|
6496
|
+
if (inputDivStyle.textAlign !== 'center') {
|
|
6497
|
+
left = 0;
|
|
6498
|
+
}
|
|
6499
|
+
_this.inputDiv.innerHTML = "<br style=\"margin-left:" + left + "px;margin-top:4px;\" />";
|
|
6500
|
+
}
|
|
6501
|
+
}
|
|
6502
|
+
else {
|
|
6503
|
+
if (!e.target.innerText) {
|
|
6504
|
+
var inputDivStyle = window.getComputedStyle(_this.inputDiv, null);
|
|
6505
|
+
if (inputDivStyle.justifyContent === 'center') {
|
|
6506
|
+
_this.inputDiv.style.paddingTop = " " + (_this.inputDiv.offsetHeight / 2 -
|
|
6507
|
+
parseFloat(inputDivStyle.lineHeight) / 2) + "px";
|
|
6508
|
+
}
|
|
6509
|
+
}
|
|
6510
|
+
else {
|
|
6511
|
+
_this.inputDiv.style.paddingTop = '';
|
|
6512
|
+
}
|
|
6513
|
+
}
|
|
6514
|
+
};
|
|
6275
6515
|
this.inputDiv.onclick = function (e) {
|
|
6276
6516
|
e.stopPropagation();
|
|
6277
6517
|
var pen = _this.store.pens[_this.inputDiv.dataset.penId];
|
|
@@ -6403,37 +6643,45 @@ var Canvas = /** @class */ (function () {
|
|
|
6403
6643
|
var oldRotate = undefined;
|
|
6404
6644
|
var willRenderImage = false; // 是否需要重新渲染图片
|
|
6405
6645
|
for (var k in data) {
|
|
6406
|
-
|
|
6407
|
-
|
|
6408
|
-
|
|
6409
|
-
|
|
6410
|
-
|
|
6411
|
-
|
|
6412
|
-
|
|
6413
|
-
|
|
6414
|
-
|
|
6415
|
-
|
|
6416
|
-
|
|
6417
|
-
|
|
6418
|
-
|
|
6419
|
-
|
|
6420
|
-
|
|
6421
|
-
|
|
6422
|
-
|
|
6423
|
-
|
|
6424
|
-
|
|
6425
|
-
|
|
6426
|
-
|
|
6427
|
-
|
|
6428
|
-
|
|
6429
|
-
|
|
6430
|
-
|
|
6431
|
-
|
|
6646
|
+
// 单属性
|
|
6647
|
+
if (k.indexOf('.') === -1) {
|
|
6648
|
+
if (k === 'rotate') {
|
|
6649
|
+
oldRotate = pen.calculative.rotate || 0;
|
|
6650
|
+
}
|
|
6651
|
+
else if (k === 'isBottom') {
|
|
6652
|
+
containIsBottom = true;
|
|
6653
|
+
}
|
|
6654
|
+
else if (k === 'image') {
|
|
6655
|
+
willRenderImage = true;
|
|
6656
|
+
}
|
|
6657
|
+
if (typeof pen[k] !== 'object' || k === 'lineDash') {
|
|
6658
|
+
pen.calculative[k] = data[k];
|
|
6659
|
+
}
|
|
6660
|
+
if (needCalcTextRectProps.includes(k)) {
|
|
6661
|
+
willCalcTextRect = true;
|
|
6662
|
+
}
|
|
6663
|
+
if (['name', 'borderRadius'].includes(k)) {
|
|
6664
|
+
willUpdatePath = true;
|
|
6665
|
+
}
|
|
6666
|
+
if (needSetPenProps.includes(k)) {
|
|
6667
|
+
willSetPenRect = true;
|
|
6668
|
+
}
|
|
6669
|
+
if (needPatchFlagsPenRectProps.includes(k)) {
|
|
6670
|
+
willPatchFlagsPenRect = true;
|
|
6671
|
+
}
|
|
6672
|
+
if (needCalcIconRectProps.includes(k)) {
|
|
6673
|
+
willCalcIconRect = true;
|
|
6674
|
+
}
|
|
6432
6675
|
}
|
|
6433
|
-
|
|
6676
|
+
else {
|
|
6677
|
+
// 复合属性,如abc.def.ghi
|
|
6434
6678
|
delete pen[k];
|
|
6435
6679
|
setter(pen, k, data[k]);
|
|
6436
6680
|
}
|
|
6681
|
+
// anchors 或者 anchors.x都去执行
|
|
6682
|
+
if (k.split('.')[0] === 'anchors') {
|
|
6683
|
+
calcWorldAnchors(pen);
|
|
6684
|
+
}
|
|
6437
6685
|
}
|
|
6438
6686
|
this.setCalculativeByScale(pen); // 该方法计算量并不大,所以每次修改都计算一次
|
|
6439
6687
|
if (isChangedName) {
|
|
@@ -6450,6 +6698,11 @@ var Canvas = /** @class */ (function () {
|
|
|
6450
6698
|
};
|
|
6451
6699
|
this.setPenRect(pen, rect, false);
|
|
6452
6700
|
this.updateLines(pen, true);
|
|
6701
|
+
if (this.store.active &&
|
|
6702
|
+
this.store.active.length &&
|
|
6703
|
+
pen.id === this.store.active[0].id) {
|
|
6704
|
+
this.calcActiveRect();
|
|
6705
|
+
}
|
|
6453
6706
|
}
|
|
6454
6707
|
else if (willPatchFlagsPenRect) {
|
|
6455
6708
|
this.updatePenRect(pen);
|
|
@@ -6532,9 +6785,9 @@ var Canvas = /** @class */ (function () {
|
|
|
6532
6785
|
Object.assign(pen, rect);
|
|
6533
6786
|
}
|
|
6534
6787
|
else {
|
|
6535
|
-
var _a = this.store.data,
|
|
6536
|
-
pen.x =
|
|
6537
|
-
pen.y =
|
|
6788
|
+
var _a = this.store.data, origin_3 = _a.origin, scale = _a.scale;
|
|
6789
|
+
pen.x = origin_3.x + rect.x * scale;
|
|
6790
|
+
pen.y = origin_3.y + rect.y * scale;
|
|
6538
6791
|
pen.width = rect.width * scale;
|
|
6539
6792
|
pen.height = rect.height * scale;
|
|
6540
6793
|
}
|
|
@@ -6565,7 +6818,7 @@ var Canvas = /** @class */ (function () {
|
|
|
6565
6818
|
};
|
|
6566
6819
|
};
|
|
6567
6820
|
Canvas.prototype.toPng = function (padding, callback, containBkImg, maxWidth) {
|
|
6568
|
-
var
|
|
6821
|
+
var e_23, _a;
|
|
6569
6822
|
if (padding === void 0) { padding = 2; }
|
|
6570
6823
|
if (containBkImg === void 0) { containBkImg = false; }
|
|
6571
6824
|
var rect = getRect(this.store.data.pens);
|
|
@@ -6595,6 +6848,20 @@ var Canvas = /** @class */ (function () {
|
|
|
6595
6848
|
isRight = rect.x === 0;
|
|
6596
6849
|
isBottom = rect.y === 0;
|
|
6597
6850
|
}
|
|
6851
|
+
var width = this.store.data.width || this.store.options.width;
|
|
6852
|
+
var height = this.store.data.height || this.store.options.height;
|
|
6853
|
+
//大屏
|
|
6854
|
+
var isV = false;
|
|
6855
|
+
if (width && height && !this.store.data.component) {
|
|
6856
|
+
isV = true;
|
|
6857
|
+
}
|
|
6858
|
+
if (isV) {
|
|
6859
|
+
rect.x = this.store.data.origin.x;
|
|
6860
|
+
rect.y = this.store.data.origin.y;
|
|
6861
|
+
rect.width = width * this.store.data.scale;
|
|
6862
|
+
rect.height = height * this.store.data.scale;
|
|
6863
|
+
}
|
|
6864
|
+
var vRect = deepClone(rect);
|
|
6598
6865
|
// 有背景图,也添加 padding
|
|
6599
6866
|
var p = formatPadding(padding);
|
|
6600
6867
|
rect.x -= p[3] * _scale;
|
|
@@ -6629,25 +6896,40 @@ var Canvas = /** @class */ (function () {
|
|
|
6629
6896
|
// }
|
|
6630
6897
|
ctx.textBaseline = 'middle'; // 默认垂直居中
|
|
6631
6898
|
ctx.scale(scale, scale);
|
|
6632
|
-
if (isDrawBkImg) {
|
|
6633
|
-
var x = rect.x < 0 ? -rect.x : 0;
|
|
6634
|
-
var y = rect.y < 0 ? -rect.y : 0;
|
|
6635
|
-
ctx.drawImage(this.store.bkImg, x, y, this.canvasRect.width, this.canvasRect.height);
|
|
6636
|
-
}
|
|
6637
6899
|
var background = this.store.data.background || this.store.options.background;
|
|
6638
6900
|
if (background) {
|
|
6639
6901
|
// 绘制背景颜色
|
|
6640
6902
|
ctx.save();
|
|
6641
6903
|
ctx.fillStyle = background;
|
|
6642
|
-
|
|
6904
|
+
if (isV) {
|
|
6905
|
+
ctx.fillRect(0, 0, vRect.width + (p[1] + p[3]) * _scale, vRect.height + (p[0] + p[2]) * _scale);
|
|
6906
|
+
}
|
|
6907
|
+
else {
|
|
6908
|
+
ctx.fillRect(0, 0, oldRect.width + (p[3] + p[1]) * _scale, oldRect.height + (p[0] + p[2]) * _scale);
|
|
6909
|
+
}
|
|
6643
6910
|
ctx.restore();
|
|
6644
6911
|
}
|
|
6912
|
+
if (isDrawBkImg) {
|
|
6913
|
+
if (isV) {
|
|
6914
|
+
ctx.drawImage(this.store.bkImg, p[3] * _scale || 0, p[0] * _scale || 0, vRect.width, vRect.height);
|
|
6915
|
+
}
|
|
6916
|
+
else {
|
|
6917
|
+
var x = rect.x < 0 ? -rect.x : 0;
|
|
6918
|
+
var y = rect.y < 0 ? -rect.y : 0;
|
|
6919
|
+
ctx.drawImage(this.store.bkImg, x, y, this.canvasRect.width, this.canvasRect.height);
|
|
6920
|
+
}
|
|
6921
|
+
}
|
|
6645
6922
|
if (!isDrawBkImg) {
|
|
6646
6923
|
ctx.translate(-rect.x, -rect.y);
|
|
6647
6924
|
}
|
|
6648
6925
|
else {
|
|
6649
6926
|
// 平移画布,画笔的 worldRect 不变化
|
|
6650
|
-
|
|
6927
|
+
if (isV) {
|
|
6928
|
+
ctx.translate(-oldRect.x + p[3] * _scale || 0, -oldRect.y + p[0] * _scale || 0);
|
|
6929
|
+
}
|
|
6930
|
+
else {
|
|
6931
|
+
ctx.translate((isRight ? storeData.x : -oldRect.x) + p[3] * _scale || 0, (isBottom ? storeData.y : -oldRect.y) + p[0] * _scale || 0);
|
|
6932
|
+
}
|
|
6651
6933
|
}
|
|
6652
6934
|
try {
|
|
6653
6935
|
for (var _b = __values(this.store.data.pens), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -6663,17 +6945,17 @@ var Canvas = /** @class */ (function () {
|
|
|
6663
6945
|
renderPenRaw(ctx, pen);
|
|
6664
6946
|
}
|
|
6665
6947
|
else {
|
|
6666
|
-
renderPen(ctx, pen);
|
|
6948
|
+
renderPen(ctx, pen, true);
|
|
6667
6949
|
}
|
|
6668
6950
|
pen.calculative.active = active;
|
|
6669
6951
|
}
|
|
6670
6952
|
}
|
|
6671
|
-
catch (
|
|
6953
|
+
catch (e_23_1) { e_23 = { error: e_23_1 }; }
|
|
6672
6954
|
finally {
|
|
6673
6955
|
try {
|
|
6674
6956
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
6675
6957
|
}
|
|
6676
|
-
finally { if (
|
|
6958
|
+
finally { if (e_23) throw e_23.error; }
|
|
6677
6959
|
}
|
|
6678
6960
|
if (callback) {
|
|
6679
6961
|
canvas.toBlob(callback);
|
|
@@ -6682,7 +6964,7 @@ var Canvas = /** @class */ (function () {
|
|
|
6682
6964
|
return canvas.toDataURL();
|
|
6683
6965
|
};
|
|
6684
6966
|
Canvas.prototype.activeToPng = function (padding) {
|
|
6685
|
-
var
|
|
6967
|
+
var e_24, _a;
|
|
6686
6968
|
if (padding === void 0) { padding = 2; }
|
|
6687
6969
|
var allPens = this.getAllByPens(this.store.active);
|
|
6688
6970
|
var ids = allPens.map(function (pen) { return pen.id; });
|
|
@@ -6732,12 +7014,12 @@ var Canvas = /** @class */ (function () {
|
|
|
6732
7014
|
}
|
|
6733
7015
|
}
|
|
6734
7016
|
}
|
|
6735
|
-
catch (
|
|
7017
|
+
catch (e_24_1) { e_24 = { error: e_24_1 }; }
|
|
6736
7018
|
finally {
|
|
6737
7019
|
try {
|
|
6738
7020
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
6739
7021
|
}
|
|
6740
|
-
finally { if (
|
|
7022
|
+
finally { if (e_24) throw e_24.error; }
|
|
6741
7023
|
}
|
|
6742
7024
|
return canvas.toDataURL();
|
|
6743
7025
|
};
|