@meta2d/core 1.0.32 → 1.0.34

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, } 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';
@@ -265,12 +265,15 @@ var Canvas = /** @class */ (function () {
265
265
  if (_this.store.data.locked === LockState.DisableMoveScale)
266
266
  return;
267
267
  // e.ctrlKey: false - 平移; true - 缩放。老windows触摸板不支持
268
- if (!e.ctrlKey && Math.abs(e.wheelDelta) < 100) {
268
+ if (!e.ctrlKey &&
269
+ Math.abs(e.wheelDelta) < 100 &&
270
+ e.deltaY.toString().indexOf('.') === -1) {
269
271
  if (_this.store.options.scroll && !e.metaKey && _this.scroll) {
270
272
  _this.scroll.wheel(e.deltaY < 0);
271
273
  return;
272
274
  }
273
- _this.translate(-e.deltaX, -e.deltaY);
275
+ var scale = _this.store.data.scale || 1;
276
+ _this.translate(-e.deltaX / scale, -e.deltaY / scale);
274
277
  return;
275
278
  }
276
279
  if (Math.abs(e.wheelDelta) > 100) {
@@ -295,11 +298,15 @@ var Canvas = /** @class */ (function () {
295
298
  }
296
299
  }
297
300
  else {
301
+ var offset = 0.2;
302
+ if (e.deltaY.toString().indexOf('.') !== -1) {
303
+ offset = 0.01;
304
+ }
298
305
  if (e.deltaY > 0) {
299
- scaleOff = -0.2;
306
+ scaleOff = -offset;
300
307
  }
301
308
  else {
302
- scaleOff = 0.2;
309
+ scaleOff = offset;
303
310
  }
304
311
  }
305
312
  var x = e.offsetX, y = e.offsetY;
@@ -326,6 +333,19 @@ var Canvas = /** @class */ (function () {
326
333
  }
327
334
  var x = 10;
328
335
  var y = 10;
336
+ var vRect = null;
337
+ if (_this.store.options.strictScope) {
338
+ var width = _this.store.data.width || _this.store.options.width;
339
+ var height = _this.store.data.height || _this.store.options.height;
340
+ if (width && height) {
341
+ vRect = {
342
+ x: _this.store.data.origin.x,
343
+ y: _this.store.data.origin.y,
344
+ width: width * _this.store.data.scale,
345
+ height: height * _this.store.data.scale,
346
+ };
347
+ }
348
+ }
329
349
  switch (e.key) {
330
350
  case ' ':
331
351
  _this.hotkeyType = HotkeyType.Translate;
@@ -350,7 +370,9 @@ var Canvas = /** @class */ (function () {
350
370
  }
351
371
  else if (!_this.hotkeyType) {
352
372
  _this.patchFlags = true;
353
- _this.hotkeyType = HotkeyType.Resize;
373
+ if (!_this.store.options.resizeMode) {
374
+ _this.hotkeyType = HotkeyType.Resize;
375
+ }
354
376
  }
355
377
  break;
356
378
  case 'Alt':
@@ -403,6 +425,9 @@ var Canvas = /** @class */ (function () {
403
425
  x = -10;
404
426
  }
405
427
  x = x * _this.store.data.scale;
428
+ if (vRect && _this.activeRect.x + x < vRect.x) {
429
+ x = vRect.x - _this.activeRect.x;
430
+ }
406
431
  _this.translatePens(_this.store.active, x, 0);
407
432
  break;
408
433
  case 'ArrowUp':
@@ -418,6 +443,9 @@ var Canvas = /** @class */ (function () {
418
443
  y = -10;
419
444
  }
420
445
  y = y * _this.store.data.scale;
446
+ if (vRect && _this.activeRect.y + y < vRect.y) {
447
+ y = vRect.y - _this.activeRect.y;
448
+ }
421
449
  _this.translatePens(_this.store.active, 0, y);
422
450
  break;
423
451
  case 'ArrowRight':
@@ -433,6 +461,11 @@ var Canvas = /** @class */ (function () {
433
461
  x = 10;
434
462
  }
435
463
  x = x * _this.store.data.scale;
464
+ if (vRect &&
465
+ _this.activeRect.x + _this.activeRect.width + x > vRect.x + vRect.width) {
466
+ x =
467
+ vRect.x + vRect.width - (_this.activeRect.x + _this.activeRect.width);
468
+ }
436
469
  _this.translatePens(_this.store.active, x, 0);
437
470
  break;
438
471
  case 'ArrowDown':
@@ -448,6 +481,14 @@ var Canvas = /** @class */ (function () {
448
481
  y = 10;
449
482
  }
450
483
  y = y * _this.store.data.scale;
484
+ if (vRect &&
485
+ _this.activeRect.y + _this.activeRect.height + y >
486
+ vRect.y + vRect.height) {
487
+ y =
488
+ vRect.y +
489
+ vRect.height -
490
+ (_this.activeRect.y + _this.activeRect.height);
491
+ }
451
492
  _this.translatePens(_this.store.active, 0, y);
452
493
  break;
453
494
  case 'd':
@@ -1014,6 +1055,9 @@ var Canvas = /** @class */ (function () {
1014
1055
  _this.store.data.rule &&
1015
1056
  !_this.store.options.disableRuleLine &&
1016
1057
  _this.addRuleLine(e);
1058
+ if (_this.store.options.resizeMode) {
1059
+ _this.hotkeyType = HotkeyType.None;
1060
+ }
1017
1061
  _this.inactive();
1018
1062
  break;
1019
1063
  case HoverType.Node:
@@ -1038,6 +1082,9 @@ var Canvas = /** @class */ (function () {
1038
1082
  else {
1039
1083
  if (!pen.calculative.active) {
1040
1084
  _this.active([pen]);
1085
+ if (_this.store.options.resizeMode) {
1086
+ _this.hotkeyType = HotkeyType.Resize;
1087
+ }
1041
1088
  }
1042
1089
  }
1043
1090
  _this.calcActiveRect();
@@ -1331,6 +1378,7 @@ var Canvas = /** @class */ (function () {
1331
1378
  _this.store.emitter.emit('contextmenu', {
1332
1379
  e: e,
1333
1380
  clientRect: _this.clientRect,
1381
+ pen: _this.store.hover,
1334
1382
  });
1335
1383
  }
1336
1384
  _this.mouseRight = MouseRight.None;
@@ -2471,7 +2519,12 @@ var Canvas = /** @class */ (function () {
2471
2519
  if (tem < 0) {
2472
2520
  tem = 0;
2473
2521
  }
2474
- style += "height:" + (pen.fontSize * scale < 12 ? tem * font_scale : tem * scale * font_scale) + "px;";
2522
+ var height = pen.fontSize * scale < 12 ? tem * font_scale : tem * scale * font_scale;
2523
+ if (height < pen.fontSize * pen.lineHeight * scale) {
2524
+ height = pen.fontSize * pen.lineHeight * scale;
2525
+ style += "top:-" + height / 2 + "px;";
2526
+ }
2527
+ style += "height:" + height + "px;";
2475
2528
  }
2476
2529
  var _textWidth = null;
2477
2530
  if (pen.textWidth) {
@@ -3020,6 +3073,21 @@ var Canvas = /** @class */ (function () {
3020
3073
  pen.height === rect_1.height) ||
3021
3074
  points.some(function (point) { return pointInRect(point, rect_1); })) {
3022
3075
  flag = false;
3076
+ //严格范围模式下对齐大屏边界
3077
+ if (this.store.options.strictScope) {
3078
+ if (pen.x < rect_1.x) {
3079
+ pen.x = rect_1.x;
3080
+ }
3081
+ if (pen.y < rect_1.y) {
3082
+ pen.y = rect_1.y;
3083
+ }
3084
+ if (pen.x + pen.width > rect_1.x + rect_1.width) {
3085
+ pen.x = rect_1.x + rect_1.width - pen.width;
3086
+ }
3087
+ if (pen.y + pen.height > rect_1.y + rect_1.height) {
3088
+ pen.y = rect_1.y + rect_1.height - pen.height;
3089
+ }
3090
+ }
3023
3091
  break;
3024
3092
  }
3025
3093
  }
@@ -3844,12 +3912,14 @@ var Canvas = /** @class */ (function () {
3844
3912
  break;
3845
3913
  case EditType.Delete:
3846
3914
  action.pens.forEach(function (aPen) {
3847
- var _a;
3915
+ var _a, _b;
3848
3916
  var pen = deepClone(aPen, true);
3849
3917
  if (!pen.calculative) {
3850
3918
  pen.calculative = {};
3851
3919
  }
3852
- _this.store.data.pens.splice((_a = pen.calculative) === null || _a === void 0 ? void 0 : _a.layer, 0, pen);
3920
+ _this.store.data.pens.splice(((_a = pen.calculative) === null || _a === void 0 ? void 0 : _a.layer) !== -1
3921
+ ? (_b = pen.calculative) === null || _b === void 0 ? void 0 : _b.layer
3922
+ : _this.store.data.pens.length, 0, pen);
3853
3923
  // 先放进去,pens 可能是子节点在前,而父节点在后
3854
3924
  _this.store.pens[pen.id] = pen;
3855
3925
  pen.calculative.canvas = _this;
@@ -3942,6 +4012,7 @@ var Canvas = /** @class */ (function () {
3942
4012
  }
3943
4013
  !pen.rotate && (pen.rotate = 0);
3944
4014
  this.loadImage(pen);
4015
+ this.parent.penNetwork(pen);
3945
4016
  };
3946
4017
  Canvas.prototype.drawline = function (mouse) {
3947
4018
  var _a;
@@ -4391,6 +4462,43 @@ var Canvas = /** @class */ (function () {
4391
4462
  this.store.data.y += y * this.store.data.scale;
4392
4463
  this.store.data.x = Math.round(this.store.data.x);
4393
4464
  this.store.data.y = Math.round(this.store.data.y);
4465
+ if (this.store.options.padding) {
4466
+ var p = formatPadding(this.store.options.padding);
4467
+ var width = this.store.data.width || this.store.options.width;
4468
+ var height = this.store.data.height || this.store.options.height;
4469
+ if (this.width < (width + p[1] + p[3]) * this.store.data.scale) {
4470
+ if (this.store.data.x + this.store.data.origin.x >
4471
+ p[3] * this.store.data.scale) {
4472
+ this.store.data.x =
4473
+ p[3] * this.store.data.scale - this.store.data.origin.x;
4474
+ }
4475
+ if (this.store.data.x +
4476
+ this.store.data.origin.x +
4477
+ width * this.store.data.scale <
4478
+ this.width - p[1] * this.store.data.scale) {
4479
+ this.store.data.x =
4480
+ this.width -
4481
+ p[1] * this.store.data.scale -
4482
+ (this.store.data.origin.x + width * this.store.data.scale);
4483
+ }
4484
+ }
4485
+ if (this.height < (height + p[0] + p[2]) * this.store.data.scale) {
4486
+ if (this.store.data.y + this.store.data.origin.y >
4487
+ p[0] * this.store.data.scale) {
4488
+ this.store.data.y =
4489
+ p[0] * this.store.data.scale - this.store.data.origin.y;
4490
+ }
4491
+ if (this.store.data.y +
4492
+ this.store.data.origin.y +
4493
+ height * this.store.data.scale <
4494
+ this.height - p[2] * this.store.data.scale) {
4495
+ this.store.data.y =
4496
+ this.height -
4497
+ p[2] * this.store.data.scale -
4498
+ (this.store.data.origin.y + height * this.store.data.scale);
4499
+ }
4500
+ }
4501
+ }
4394
4502
  setTimeout(function () {
4395
4503
  _this.canvasTemplate.init();
4396
4504
  _this.canvasImage.init();
@@ -4638,6 +4746,48 @@ var Canvas = /** @class */ (function () {
4638
4746
  }
4639
4747
  this.activeRect.ratio = this.initPens[0].ratio;
4640
4748
  resizeRect(this.activeRect, offsetX, offsetY, this.resizeIndex);
4749
+ //大屏区域
4750
+ if (this.store.options.strictScope) {
4751
+ var width = this.store.data.width || this.store.options.width;
4752
+ var height = this.store.data.height || this.store.options.height;
4753
+ if (width && height) {
4754
+ var vRect = {
4755
+ x: this.store.data.origin.x,
4756
+ y: this.store.data.origin.y,
4757
+ width: width * this.store.data.scale,
4758
+ height: height * this.store.data.scale,
4759
+ };
4760
+ if (this.activeRect.x < vRect.x) {
4761
+ this.activeRect.width =
4762
+ this.activeRect.width - (vRect.x - this.activeRect.x);
4763
+ this.activeRect.x = vRect.x;
4764
+ }
4765
+ if (this.activeRect.y < vRect.y) {
4766
+ this.activeRect.height =
4767
+ this.activeRect.height - (vRect.y - this.activeRect.y);
4768
+ this.activeRect.y = vRect.y;
4769
+ }
4770
+ if (this.activeRect.x + this.activeRect.width > vRect.x + vRect.width) {
4771
+ this.activeRect.width =
4772
+ this.activeRect.width -
4773
+ (this.activeRect.x +
4774
+ this.activeRect.width -
4775
+ (vRect.x + vRect.width));
4776
+ this.activeRect.x = vRect.x + vRect.width - this.activeRect.width;
4777
+ this.activeRect.ex = this.activeRect.x + this.activeRect.width;
4778
+ }
4779
+ if (this.activeRect.y + this.activeRect.height >
4780
+ vRect.y + vRect.height) {
4781
+ this.activeRect.height =
4782
+ this.activeRect.height -
4783
+ (this.activeRect.y +
4784
+ this.activeRect.height -
4785
+ (vRect.y + vRect.height));
4786
+ this.activeRect.y = vRect.y + vRect.height - this.activeRect.height;
4787
+ this.activeRect.ey = this.activeRect.y + this.activeRect.height;
4788
+ }
4789
+ }
4790
+ }
4641
4791
  calcCenter(this.activeRect);
4642
4792
  var scaleX = this.activeRect.width / w;
4643
4793
  var scaleY = this.activeRect.height / h;
@@ -4706,11 +4856,40 @@ var Canvas = /** @class */ (function () {
4706
4856
  e.ctrlKey && (x = 0);
4707
4857
  var rect = deepClone(this.initActiveRect);
4708
4858
  translateRect(rect, x, y);
4859
+ var vFlag = false;
4860
+ if (this.store.options.strictScope) {
4861
+ var width = this.store.data.width || this.store.options.width;
4862
+ var height = this.store.data.height || this.store.options.height;
4863
+ if (width && height) {
4864
+ var vRect = {
4865
+ x: this.store.data.origin.x,
4866
+ y: this.store.data.origin.y,
4867
+ width: width * this.store.data.scale,
4868
+ height: height * this.store.data.scale,
4869
+ };
4870
+ if (rect.x < vRect.x) {
4871
+ rect.x = vRect.x;
4872
+ vFlag = true;
4873
+ }
4874
+ if (rect.y < vRect.y) {
4875
+ rect.y = vRect.y;
4876
+ vFlag = true;
4877
+ }
4878
+ if (rect.x + rect.width > vRect.x + vRect.width) {
4879
+ rect.x = vRect.x + vRect.width - rect.width;
4880
+ vFlag = true;
4881
+ }
4882
+ if (rect.y + rect.height > vRect.y + vRect.height) {
4883
+ rect.y = vRect.y + vRect.height - rect.height;
4884
+ vFlag = true;
4885
+ }
4886
+ }
4887
+ }
4709
4888
  var offset = {
4710
4889
  x: rect.x - this.activeRect.x,
4711
4890
  y: rect.y - this.activeRect.y,
4712
4891
  };
4713
- if (!this.store.options.disableDock) {
4892
+ if (!this.store.options.disableDock && !vFlag) {
4714
4893
  this.clearDock();
4715
4894
  var moveDock = this.customMoveDock || calcMoveDock;
4716
4895
  this.dock = moveDock(this.store, rect, this.movingPens, offset);
@@ -5381,6 +5560,9 @@ var Canvas = /** @class */ (function () {
5381
5560
  }
5382
5561
  _this.store.path2dMap.set(line, globalStore.path2dDraws[line.name](line));
5383
5562
  _this.patchFlagsLines.add(line);
5563
+ if (line.calculative.gradientSmooth) {
5564
+ line.calculative.gradientAnimatePath = getGradientAnimatePath(line);
5565
+ }
5384
5566
  change && getLineLength(line);
5385
5567
  });
5386
5568
  };
@@ -5468,7 +5650,7 @@ var Canvas = /** @class */ (function () {
5468
5650
  return;
5469
5651
  }
5470
5652
  pens.forEach(function (pen) {
5471
- var _a, _b, _c;
5653
+ var _a, _b, _c, _d;
5472
5654
  if (pen.calculative.pause) {
5473
5655
  var d = Date.now() - pen.calculative.pause;
5474
5656
  pen.calculative.pause = undefined;
@@ -5481,9 +5663,26 @@ var Canvas = /** @class */ (function () {
5481
5663
  (_a = pen.calculative.media) === null || _a === void 0 ? void 0 : _a.play();
5482
5664
  (_b = pen.onStartVideo) === null || _b === void 0 ? void 0 : _b.call(pen, pen);
5483
5665
  }
5484
- else if (pen.type || ((_c = pen.frames) === null || _c === void 0 ? void 0 : _c.length)) {
5666
+ else if (pen.type ||
5667
+ ((_c = pen.frames) === null || _c === void 0 ? void 0 : _c.length) ||
5668
+ (pen.animations && pen.animations.length)) {
5485
5669
  //存储动画初始状态
5486
5670
  if (!pen.type) {
5671
+ if (!pen.frames && pen.animations && pen.animations.length) {
5672
+ //无活动动画
5673
+ var autoIndex = (_d = pen.animations) === null || _d === void 0 ? void 0 : _d.findIndex(function (i) { return i.autoPlay; });
5674
+ var index = autoIndex === -1 ? 0 : autoIndex;
5675
+ var animate = deepClone(pen.animations[index]);
5676
+ delete animate.name;
5677
+ animate.currentAnimation = index;
5678
+ if (!pen.type && animate.frames) {
5679
+ animate.showDuration = _this.parent.calcAnimateDuration(animate);
5680
+ }
5681
+ _this.parent.setValue(__assign({ id: pen.id }, animate), {
5682
+ doEvent: false,
5683
+ history: false,
5684
+ });
5685
+ }
5487
5686
  _this.store.animateMap.set(pen, _this.getFrameProps(pen));
5488
5687
  }
5489
5688
  _this.store.animates.add(pen);
@@ -5913,7 +6112,7 @@ var Canvas = /** @class */ (function () {
5913
6112
  return [2 /*return*/];
5914
6113
  }
5915
6114
  deletePens = [];
5916
- this._del(pens, deletePens);
6115
+ this._del(pens, deletePens, canDelLocked);
5917
6116
  this.initImageCanvas(deletePens);
5918
6117
  this.initTemplateCanvas(deletePens);
5919
6118
  this.inactive();
@@ -5929,15 +6128,14 @@ var Canvas = /** @class */ (function () {
5929
6128
  });
5930
6129
  });
5931
6130
  };
5932
- Canvas.prototype._del = function (pens, delPens) {
6131
+ Canvas.prototype._del = function (pens, delPens, canDelLocked) {
5933
6132
  var _this = this;
5934
6133
  if (!pens) {
5935
6134
  return;
5936
6135
  }
5937
6136
  pens.forEach(function (pen) {
5938
6137
  if (!pen.parentId) {
5939
- if (pen.locked) {
5940
- // TODO: canDelLocked 是 true , locked 仍然删不掉
6138
+ if (!canDelLocked && pen.locked) {
5941
6139
  return;
5942
6140
  }
5943
6141
  else {
@@ -6103,9 +6301,60 @@ var Canvas = /** @class */ (function () {
6103
6301
  sheet.insertRule('.meta2d-input ul li{padding: 5px 12px;line-height: 22px;white-space: nowrap;cursor: pointer;}');
6104
6302
  sheet.insertRule('.meta2d-input ul li:hover{background: #eeeeee;}');
6105
6303
  sheet.insertRule(".input-div::-webkit-scrollbar {display:none}");
6304
+ sheet.insertRule(".input-div{scrollbar-width: none;}");
6106
6305
  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;}');
6107
6306
  sheet.insertRule(".input-div div{}");
6108
6307
  }
6308
+ this.inputDiv.onfocus = function (e) {
6309
+ if (navigator.userAgent.includes('Firefox')) {
6310
+ if (!e.target.innerText) {
6311
+ var left = _this.inputDiv.offsetWidth / 2;
6312
+ var inputDivStyle = window.getComputedStyle(_this.inputDiv, null);
6313
+ if (inputDivStyle.textAlign !== 'center') {
6314
+ left = 0;
6315
+ }
6316
+ _this.inputDiv.innerHTML = "<br style=\"margin-left:" + left + "px;margin-top:4px;\" />";
6317
+ }
6318
+ }
6319
+ else {
6320
+ //无文本时,光标确保居中
6321
+ if (!e.target.innerText) {
6322
+ var inputDivStyle = window.getComputedStyle(_this.inputDiv, null);
6323
+ if (inputDivStyle.justifyContent === 'center') {
6324
+ _this.inputDiv.style.paddingTop = " " + (_this.inputDiv.offsetHeight / 2 -
6325
+ parseFloat(inputDivStyle.lineHeight) / 2) + "px";
6326
+ }
6327
+ }
6328
+ else {
6329
+ _this.inputDiv.style.paddingTop = '';
6330
+ }
6331
+ }
6332
+ };
6333
+ this.inputDiv.oninput = function (e) {
6334
+ // //无文本时,光标确保居中
6335
+ if (navigator.userAgent.includes('Firefox')) {
6336
+ if (!e.target.innerText.trim()) {
6337
+ var left = _this.inputDiv.offsetWidth / 2;
6338
+ var inputDivStyle = window.getComputedStyle(_this.inputDiv, null);
6339
+ if (inputDivStyle.textAlign !== 'center') {
6340
+ left = 0;
6341
+ }
6342
+ _this.inputDiv.innerHTML = "<br style=\"margin-left:" + left + "px;margin-top:4px;\" />";
6343
+ }
6344
+ }
6345
+ else {
6346
+ if (!e.target.innerText) {
6347
+ var inputDivStyle = window.getComputedStyle(_this.inputDiv, null);
6348
+ if (inputDivStyle.justifyContent === 'center') {
6349
+ _this.inputDiv.style.paddingTop = " " + (_this.inputDiv.offsetHeight / 2 -
6350
+ parseFloat(inputDivStyle.lineHeight) / 2) + "px";
6351
+ }
6352
+ }
6353
+ else {
6354
+ _this.inputDiv.style.paddingTop = '';
6355
+ }
6356
+ }
6357
+ };
6109
6358
  this.inputDiv.onclick = function (e) {
6110
6359
  e.stopPropagation();
6111
6360
  var pen = _this.store.pens[_this.inputDiv.dataset.penId];
@@ -6237,37 +6486,45 @@ var Canvas = /** @class */ (function () {
6237
6486
  var oldRotate = undefined;
6238
6487
  var willRenderImage = false; // 是否需要重新渲染图片
6239
6488
  for (var k in data) {
6240
- if (k === 'rotate') {
6241
- oldRotate = pen.calculative.rotate || 0;
6242
- }
6243
- if (typeof pen[k] !== 'object' || k === 'lineDash') {
6244
- pen.calculative[k] = data[k];
6245
- }
6246
- if (needCalcTextRectProps.includes(k)) {
6247
- willCalcTextRect = true;
6248
- }
6249
- if (['name', 'borderRadius'].includes(k)) {
6250
- willUpdatePath = true;
6251
- }
6252
- if (needSetPenProps.includes(k)) {
6253
- willSetPenRect = true;
6254
- }
6255
- if (needPatchFlagsPenRectProps.includes(k)) {
6256
- willPatchFlagsPenRect = true;
6257
- }
6258
- if (needCalcIconRectProps.includes(k)) {
6259
- willCalcIconRect = true;
6260
- }
6261
- if (k === 'isBottom') {
6262
- containIsBottom = true;
6263
- }
6264
- if (k === 'image') {
6265
- willRenderImage = true;
6489
+ // 单属性
6490
+ if (k.indexOf('.') === -1) {
6491
+ if (k === 'rotate') {
6492
+ oldRotate = pen.calculative.rotate || 0;
6493
+ }
6494
+ else if (k === 'isBottom') {
6495
+ containIsBottom = true;
6496
+ }
6497
+ else if (k === 'image') {
6498
+ willRenderImage = true;
6499
+ }
6500
+ if (typeof pen[k] !== 'object' || k === 'lineDash') {
6501
+ pen.calculative[k] = data[k];
6502
+ }
6503
+ if (needCalcTextRectProps.includes(k)) {
6504
+ willCalcTextRect = true;
6505
+ }
6506
+ if (['name', 'borderRadius'].includes(k)) {
6507
+ willUpdatePath = true;
6508
+ }
6509
+ if (needSetPenProps.includes(k)) {
6510
+ willSetPenRect = true;
6511
+ }
6512
+ if (needPatchFlagsPenRectProps.includes(k)) {
6513
+ willPatchFlagsPenRect = true;
6514
+ }
6515
+ if (needCalcIconRectProps.includes(k)) {
6516
+ willCalcIconRect = true;
6517
+ }
6266
6518
  }
6267
- if (k.indexOf('.') !== -1) {
6519
+ else {
6520
+ // 复合属性,如abc.def.ghi
6268
6521
  delete pen[k];
6269
6522
  setter(pen, k, data[k]);
6270
6523
  }
6524
+ // anchors 或者 anchors.x都去执行
6525
+ if (k.split('.')[0] === 'anchors') {
6526
+ calcWorldAnchors(pen);
6527
+ }
6271
6528
  }
6272
6529
  this.setCalculativeByScale(pen); // 该方法计算量并不大,所以每次修改都计算一次
6273
6530
  if (isChangedName) {
@@ -6284,6 +6541,11 @@ var Canvas = /** @class */ (function () {
6284
6541
  };
6285
6542
  this.setPenRect(pen, rect, false);
6286
6543
  this.updateLines(pen, true);
6544
+ if (this.store.active &&
6545
+ this.store.active.length &&
6546
+ pen.id === this.store.active[0].id) {
6547
+ this.calcActiveRect();
6548
+ }
6287
6549
  }
6288
6550
  else if (willPatchFlagsPenRect) {
6289
6551
  this.updatePenRect(pen);
@@ -6398,11 +6660,12 @@ var Canvas = /** @class */ (function () {
6398
6660
  height: pen.height / scale,
6399
6661
  };
6400
6662
  };
6401
- Canvas.prototype.toPng = function (padding, callback, containBkImg) {
6663
+ Canvas.prototype.toPng = function (padding, callback, containBkImg, maxWidth) {
6402
6664
  var e_22, _a;
6403
6665
  if (padding === void 0) { padding = 2; }
6404
6666
  if (containBkImg === void 0) { containBkImg = false; }
6405
6667
  var rect = getRect(this.store.data.pens);
6668
+ var _scale = this.store.data.scale;
6406
6669
  if (!isFinite(rect.width)) {
6407
6670
  throw new Error('can not to png, because width is not finite');
6408
6671
  }
@@ -6428,12 +6691,28 @@ var Canvas = /** @class */ (function () {
6428
6691
  isRight = rect.x === 0;
6429
6692
  isBottom = rect.y === 0;
6430
6693
  }
6694
+ var width = this.store.data.width || this.store.options.width;
6695
+ var height = this.store.data.height || this.store.options.height;
6696
+ //大屏
6697
+ if (width && height) {
6698
+ rect.x = this.store.data.origin.x;
6699
+ rect.y = this.store.data.origin.y;
6700
+ rect.width = width * this.store.data.scale;
6701
+ rect.height = height * this.store.data.scale;
6702
+ }
6703
+ var vRect = deepClone(rect);
6431
6704
  // 有背景图,也添加 padding
6432
6705
  var p = formatPadding(padding);
6433
- rect.x -= p[3];
6434
- rect.y -= p[0];
6435
- rect.width += p[3] + p[1];
6436
- rect.height += p[0] + p[2];
6706
+ rect.x -= p[3] * _scale;
6707
+ rect.y -= p[0] * _scale;
6708
+ rect.width += (p[3] + p[1]) * _scale;
6709
+ rect.height += (p[0] + p[2]) * _scale;
6710
+ // 扩大图
6711
+ // const scale =
6712
+ // rect.width > rect.height ? longSide / rect.width : longSide / rect.height;
6713
+ var scale = (maxWidth || 1920) / rect.width;
6714
+ rect.width *= scale;
6715
+ rect.height *= scale;
6437
6716
  calcRightBottom(rect);
6438
6717
  var canvas = document.createElement('canvas');
6439
6718
  canvas.width = rect.width;
@@ -6447,26 +6726,49 @@ var Canvas = /** @class */ (function () {
6447
6726
  throw new Error('can not to png, because the size exceeds the browser limit');
6448
6727
  }
6449
6728
  var ctx = canvas.getContext('2d');
6729
+ // if (window.devicePixelRatio > 1) {
6730
+ // canvas.width *= window.devicePixelRatio;
6731
+ // canvas.height *= window.devicePixelRatio;
6732
+ // canvas.style.width = `${canvas.width / window.devicePixelRatio}`;
6733
+ // canvas.style.height = `${canvas.height / window.devicePixelRatio}`;
6734
+ // ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
6735
+ // }
6450
6736
  ctx.textBaseline = 'middle'; // 默认垂直居中
6451
- if (isDrawBkImg) {
6452
- var x = rect.x < 0 ? -rect.x : 0;
6453
- var y = rect.y < 0 ? -rect.y : 0;
6454
- ctx.drawImage(this.store.bkImg, x, y, this.canvasRect.width, this.canvasRect.height);
6455
- }
6737
+ ctx.scale(scale, scale);
6456
6738
  var background = this.store.data.background || this.store.options.background;
6457
6739
  if (background) {
6458
6740
  // 绘制背景颜色
6459
6741
  ctx.save();
6460
6742
  ctx.fillStyle = background;
6461
- ctx.fillRect(0, 0, canvas.width, canvas.height);
6743
+ if (width && height) {
6744
+ ctx.fillRect(0, 0, vRect.width + (p[1] + p[3]) * _scale, vRect.height + (p[0] + p[2]) * _scale);
6745
+ }
6746
+ else {
6747
+ ctx.fillRect(0, 0, oldRect.width + (p[3] + p[1]) * _scale, oldRect.height + (p[0] + p[2]) * _scale);
6748
+ }
6462
6749
  ctx.restore();
6463
6750
  }
6751
+ if (isDrawBkImg) {
6752
+ if (width && height) {
6753
+ ctx.drawImage(this.store.bkImg, p[3] * _scale || 0, p[0] * _scale || 0, vRect.width, vRect.height);
6754
+ }
6755
+ else {
6756
+ var x = rect.x < 0 ? -rect.x : 0;
6757
+ var y = rect.y < 0 ? -rect.y : 0;
6758
+ ctx.drawImage(this.store.bkImg, x, y, this.canvasRect.width, this.canvasRect.height);
6759
+ }
6760
+ }
6464
6761
  if (!isDrawBkImg) {
6465
6762
  ctx.translate(-rect.x, -rect.y);
6466
6763
  }
6467
6764
  else {
6468
6765
  // 平移画布,画笔的 worldRect 不变化
6469
- ctx.translate(isRight ? storeData.x : -oldRect.x, isBottom ? storeData.y : -oldRect.y);
6766
+ if (width && height) {
6767
+ ctx.translate(-oldRect.x + p[3] * _scale || 0, -oldRect.y + p[0] * _scale || 0);
6768
+ }
6769
+ else {
6770
+ ctx.translate((isRight ? storeData.x : -oldRect.x) + p[3] * _scale || 0, (isBottom ? storeData.y : -oldRect.y) + p[0] * _scale || 0);
6771
+ }
6470
6772
  }
6471
6773
  try {
6472
6774
  for (var _b = __values(this.store.data.pens), _c = _b.next(); !_c.done; _c = _b.next()) {