@meta2d/core 1.0.33 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meta2d/core",
3
- "version": "1.0.33",
3
+ "version": "1.0.34",
4
4
  "description": "@meta2d/core: Powerful, Beautiful, Simple, Open - Web-Based 2D At Its Best .",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -343,7 +343,7 @@ export declare class Canvas {
343
343
  */
344
344
  rotatePen(pen: Pen, angle: number, rect: Rect): void;
345
345
  nextAnimate(pen: Pen): void;
346
- getFrameProps(pen: any): {};
346
+ getFrameProps(pen: Pen): {};
347
347
  animate(): void;
348
348
  get clipboardName(): string;
349
349
  copy(pens?: Pen[], emit?: boolean): Promise<void>;
@@ -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 = -0.05;
306
+ scaleOff = -offset;
303
307
  }
304
308
  else {
305
- scaleOff = 0.05;
309
+ scaleOff = offset;
306
310
  }
307
311
  }
308
312
  var x = e.offsetX, y = e.offsetY;
@@ -1374,6 +1378,7 @@ var Canvas = /** @class */ (function () {
1374
1378
  _this.store.emitter.emit('contextmenu', {
1375
1379
  e: e,
1376
1380
  clientRect: _this.clientRect,
1381
+ pen: _this.store.hover,
1377
1382
  });
1378
1383
  }
1379
1384
  _this.mouseRight = MouseRight.None;
@@ -2514,7 +2519,12 @@ var Canvas = /** @class */ (function () {
2514
2519
  if (tem < 0) {
2515
2520
  tem = 0;
2516
2521
  }
2517
- 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;";
2518
2528
  }
2519
2529
  var _textWidth = null;
2520
2530
  if (pen.textWidth) {
@@ -3902,12 +3912,14 @@ var Canvas = /** @class */ (function () {
3902
3912
  break;
3903
3913
  case EditType.Delete:
3904
3914
  action.pens.forEach(function (aPen) {
3905
- var _a;
3915
+ var _a, _b;
3906
3916
  var pen = deepClone(aPen, true);
3907
3917
  if (!pen.calculative) {
3908
3918
  pen.calculative = {};
3909
3919
  }
3910
- _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);
3911
3923
  // 先放进去,pens 可能是子节点在前,而父节点在后
3912
3924
  _this.store.pens[pen.id] = pen;
3913
3925
  pen.calculative.canvas = _this;
@@ -4000,6 +4012,7 @@ var Canvas = /** @class */ (function () {
4000
4012
  }
4001
4013
  !pen.rotate && (pen.rotate = 0);
4002
4014
  this.loadImage(pen);
4015
+ this.parent.penNetwork(pen);
4003
4016
  };
4004
4017
  Canvas.prototype.drawline = function (mouse) {
4005
4018
  var _a;
@@ -5547,6 +5560,9 @@ var Canvas = /** @class */ (function () {
5547
5560
  }
5548
5561
  _this.store.path2dMap.set(line, globalStore.path2dDraws[line.name](line));
5549
5562
  _this.patchFlagsLines.add(line);
5563
+ if (line.calculative.gradientSmooth) {
5564
+ line.calculative.gradientAnimatePath = getGradientAnimatePath(line);
5565
+ }
5550
5566
  change && getLineLength(line);
5551
5567
  });
5552
5568
  };
@@ -5634,7 +5650,7 @@ var Canvas = /** @class */ (function () {
5634
5650
  return;
5635
5651
  }
5636
5652
  pens.forEach(function (pen) {
5637
- var _a, _b, _c;
5653
+ var _a, _b, _c, _d;
5638
5654
  if (pen.calculative.pause) {
5639
5655
  var d = Date.now() - pen.calculative.pause;
5640
5656
  pen.calculative.pause = undefined;
@@ -5647,9 +5663,26 @@ var Canvas = /** @class */ (function () {
5647
5663
  (_a = pen.calculative.media) === null || _a === void 0 ? void 0 : _a.play();
5648
5664
  (_b = pen.onStartVideo) === null || _b === void 0 ? void 0 : _b.call(pen, pen);
5649
5665
  }
5650
- 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)) {
5651
5669
  //存储动画初始状态
5652
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
+ }
5653
5686
  _this.store.animateMap.set(pen, _this.getFrameProps(pen));
5654
5687
  }
5655
5688
  _this.store.animates.add(pen);
@@ -6079,7 +6112,7 @@ var Canvas = /** @class */ (function () {
6079
6112
  return [2 /*return*/];
6080
6113
  }
6081
6114
  deletePens = [];
6082
- this._del(pens, deletePens);
6115
+ this._del(pens, deletePens, canDelLocked);
6083
6116
  this.initImageCanvas(deletePens);
6084
6117
  this.initTemplateCanvas(deletePens);
6085
6118
  this.inactive();
@@ -6095,15 +6128,14 @@ var Canvas = /** @class */ (function () {
6095
6128
  });
6096
6129
  });
6097
6130
  };
6098
- Canvas.prototype._del = function (pens, delPens) {
6131
+ Canvas.prototype._del = function (pens, delPens, canDelLocked) {
6099
6132
  var _this = this;
6100
6133
  if (!pens) {
6101
6134
  return;
6102
6135
  }
6103
6136
  pens.forEach(function (pen) {
6104
6137
  if (!pen.parentId) {
6105
- if (pen.locked) {
6106
- // TODO: canDelLocked 是 true , locked 仍然删不掉
6138
+ if (!canDelLocked && pen.locked) {
6107
6139
  return;
6108
6140
  }
6109
6141
  else {
@@ -6269,9 +6301,60 @@ var Canvas = /** @class */ (function () {
6269
6301
  sheet.insertRule('.meta2d-input ul li{padding: 5px 12px;line-height: 22px;white-space: nowrap;cursor: pointer;}');
6270
6302
  sheet.insertRule('.meta2d-input ul li:hover{background: #eeeeee;}');
6271
6303
  sheet.insertRule(".input-div::-webkit-scrollbar {display:none}");
6304
+ sheet.insertRule(".input-div{scrollbar-width: none;}");
6272
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;}');
6273
6306
  sheet.insertRule(".input-div div{}");
6274
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
+ };
6275
6358
  this.inputDiv.onclick = function (e) {
6276
6359
  e.stopPropagation();
6277
6360
  var pen = _this.store.pens[_this.inputDiv.dataset.penId];
@@ -6403,37 +6486,45 @@ var Canvas = /** @class */ (function () {
6403
6486
  var oldRotate = undefined;
6404
6487
  var willRenderImage = false; // 是否需要重新渲染图片
6405
6488
  for (var k in data) {
6406
- if (k === 'rotate') {
6407
- oldRotate = pen.calculative.rotate || 0;
6408
- }
6409
- if (typeof pen[k] !== 'object' || k === 'lineDash') {
6410
- pen.calculative[k] = data[k];
6411
- }
6412
- if (needCalcTextRectProps.includes(k)) {
6413
- willCalcTextRect = true;
6414
- }
6415
- if (['name', 'borderRadius'].includes(k)) {
6416
- willUpdatePath = true;
6417
- }
6418
- if (needSetPenProps.includes(k)) {
6419
- willSetPenRect = true;
6420
- }
6421
- if (needPatchFlagsPenRectProps.includes(k)) {
6422
- willPatchFlagsPenRect = true;
6423
- }
6424
- if (needCalcIconRectProps.includes(k)) {
6425
- willCalcIconRect = true;
6426
- }
6427
- if (k === 'isBottom') {
6428
- containIsBottom = true;
6429
- }
6430
- if (k === 'image') {
6431
- 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
+ }
6432
6518
  }
6433
- if (k.indexOf('.') !== -1) {
6519
+ else {
6520
+ // 复合属性,如abc.def.ghi
6434
6521
  delete pen[k];
6435
6522
  setter(pen, k, data[k]);
6436
6523
  }
6524
+ // anchors 或者 anchors.x都去执行
6525
+ if (k.split('.')[0] === 'anchors') {
6526
+ calcWorldAnchors(pen);
6527
+ }
6437
6528
  }
6438
6529
  this.setCalculativeByScale(pen); // 该方法计算量并不大,所以每次修改都计算一次
6439
6530
  if (isChangedName) {
@@ -6450,6 +6541,11 @@ var Canvas = /** @class */ (function () {
6450
6541
  };
6451
6542
  this.setPenRect(pen, rect, false);
6452
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
+ }
6453
6549
  }
6454
6550
  else if (willPatchFlagsPenRect) {
6455
6551
  this.updatePenRect(pen);
@@ -6595,6 +6691,16 @@ var Canvas = /** @class */ (function () {
6595
6691
  isRight = rect.x === 0;
6596
6692
  isBottom = rect.y === 0;
6597
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);
6598
6704
  // 有背景图,也添加 padding
6599
6705
  var p = formatPadding(padding);
6600
6706
  rect.x -= p[3] * _scale;
@@ -6629,25 +6735,40 @@ var Canvas = /** @class */ (function () {
6629
6735
  // }
6630
6736
  ctx.textBaseline = 'middle'; // 默认垂直居中
6631
6737
  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
6738
  var background = this.store.data.background || this.store.options.background;
6638
6739
  if (background) {
6639
6740
  // 绘制背景颜色
6640
6741
  ctx.save();
6641
6742
  ctx.fillStyle = background;
6642
- ctx.fillRect(0, 0, oldRect.width + (p[3] + p[1]) * _scale, oldRect.height + (p[0] + p[2]) * _scale);
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
+ }
6643
6749
  ctx.restore();
6644
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
+ }
6645
6761
  if (!isDrawBkImg) {
6646
6762
  ctx.translate(-rect.x, -rect.y);
6647
6763
  }
6648
6764
  else {
6649
6765
  // 平移画布,画笔的 worldRect 不变化
6650
- 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
+ }
6651
6772
  }
6652
6773
  try {
6653
6774
  for (var _b = __values(this.store.data.pens), _c = _b.next(); !_c.done; _c = _b.next()) {