@meta2d/core 1.0.38 → 1.0.39

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.38",
3
+ "version": "1.0.39",
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",
@@ -81,6 +81,12 @@ export declare class Canvas {
81
81
  maxZindex: number;
82
82
  canMoveLine: boolean;
83
83
  randomIdObj: object;
84
+ keyOptions?: {
85
+ shiftKey?: boolean;
86
+ altKey?: boolean;
87
+ ctrlKey?: boolean;
88
+ metaKey?: boolean;
89
+ };
84
90
  /**
85
91
  * @deprecated 改用 beforeAddPens
86
92
  */
@@ -82,7 +82,7 @@ var __values = (this && this.__values) || function(o) {
82
82
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
83
83
  };
84
84
  import { KeydownType } from '../options';
85
- import { addLineAnchor, calcIconRect, calcTextRect, calcWorldAnchors, calcWorldRects, LockState, nearestAnchor, PenType, pushPenAnchor, removePenAnchor, renderPen, scalePen, translateLine, deleteTempAnchor, connectLine, disconnectLine, getAnchor, calcAnchorDock, calcMoveDock, calcTextLines, setNodeAnimate, setLineAnimate, calcPenRect, setChildrenActive, getParent, setHover, randomId, getPensLock, getToAnchor, getFromAnchor, calcPadding, getPensDisableRotate, getPensDisableResize, needCalcTextRectProps, calcResizeDock, needPatchFlagsPenRectProps, needCalcIconRectProps, isDomShapes, renderPenRaw, needSetPenProps, getAllChildren, calcInView, isShowChild, getTextColor, getGlobalColor, clearLifeCycle, rotatePen, calcTextAutoWidth, getGradientAnimatePath, CanvasLayer, ctxFlip, ctxRotate, setGlobalAlpha, drawImage, } from '../pen';
85
+ import { addLineAnchor, calcIconRect, calcTextRect, calcWorldAnchors, calcWorldRects, LockState, nearestAnchor, PenType, pushPenAnchor, removePenAnchor, renderPen, scalePen, translateLine, deleteTempAnchor, connectLine, disconnectLine, getAnchor, calcAnchorDock, calcMoveDock, calcTextLines, setNodeAnimate, setLineAnimate, calcPenRect, setChildrenActive, getParent, setHover, randomId, getPensLock, getToAnchor, getFromAnchor, calcPadding, getPensDisableRotate, getPensDisableResize, needCalcTextRectProps, calcResizeDock, needPatchFlagsPenRectProps, needCalcIconRectProps, isDomShapes, renderPenRaw, needSetPenProps, getAllChildren, calcInView, isShowChild, getTextColor, getGlobalColor, clearLifeCycle, rotatePen, calcTextAutoWidth, getGradientAnimatePath, CanvasLayer, ctxFlip, ctxRotate, setGlobalAlpha, drawImage, setElemPosition, } 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';
@@ -333,6 +333,13 @@ var Canvas = /** @class */ (function () {
333
333
  if (_this.store.options.unavailableKeys.includes(e.key)) {
334
334
  return;
335
335
  }
336
+ if (!_this.keyOptions) {
337
+ _this.keyOptions = {};
338
+ }
339
+ _this.keyOptions.altKey = e.altKey;
340
+ _this.keyOptions.shiftKey = e.shiftKey;
341
+ _this.keyOptions.ctrlKey = e.ctrlKey;
342
+ _this.keyOptions.metaKey = e.metaKey;
336
343
  var x = 10;
337
344
  var y = 10;
338
345
  var vRect = null;
@@ -427,6 +434,13 @@ var Canvas = /** @class */ (function () {
427
434
  x = -10;
428
435
  }
429
436
  x = x * _this.store.data.scale;
437
+ if (_this.store.activeAnchor &&
438
+ _this.store.active &&
439
+ _this.store.active.length === 1 &&
440
+ _this.store.active[0].type) {
441
+ _this.moveLineAnchor({ x: _this.store.activeAnchor.x + x, y: _this.store.activeAnchor.y }, {});
442
+ break;
443
+ }
430
444
  if (vRect && _this.activeRect.x + x < vRect.x) {
431
445
  x = vRect.x - _this.activeRect.x;
432
446
  }
@@ -448,6 +462,13 @@ var Canvas = /** @class */ (function () {
448
462
  if (vRect && _this.activeRect.y + y < vRect.y) {
449
463
  y = vRect.y - _this.activeRect.y;
450
464
  }
465
+ if (_this.store.activeAnchor &&
466
+ _this.store.active &&
467
+ _this.store.active.length === 1 &&
468
+ _this.store.active[0].type) {
469
+ _this.moveLineAnchor({ x: _this.store.activeAnchor.x, y: _this.store.activeAnchor.y + y }, {});
470
+ break;
471
+ }
451
472
  _this.translatePens(_this.store.active, 0, y);
452
473
  break;
453
474
  case 'ArrowRight':
@@ -463,6 +484,13 @@ var Canvas = /** @class */ (function () {
463
484
  x = 10;
464
485
  }
465
486
  x = x * _this.store.data.scale;
487
+ if (_this.store.activeAnchor &&
488
+ _this.store.active &&
489
+ _this.store.active.length === 1 &&
490
+ _this.store.active[0].type) {
491
+ _this.moveLineAnchor({ x: _this.store.activeAnchor.x + x, y: _this.store.activeAnchor.y }, {});
492
+ break;
493
+ }
466
494
  if (vRect &&
467
495
  _this.activeRect.x + _this.activeRect.width + x > vRect.x + vRect.width) {
468
496
  x =
@@ -491,6 +519,13 @@ var Canvas = /** @class */ (function () {
491
519
  vRect.height -
492
520
  (_this.activeRect.y + _this.activeRect.height);
493
521
  }
522
+ if (_this.store.activeAnchor &&
523
+ _this.store.active &&
524
+ _this.store.active.length === 1 &&
525
+ _this.store.active[0].type) {
526
+ _this.moveLineAnchor({ x: _this.store.activeAnchor.x, y: _this.store.activeAnchor.y + y }, {});
527
+ break;
528
+ }
494
529
  _this.translatePens(_this.store.active, 0, y);
495
530
  break;
496
531
  case 'd':
@@ -541,6 +576,7 @@ var Canvas = /** @class */ (function () {
541
576
  _this.cut();
542
577
  }
543
578
  break;
579
+ case '√': //MAC OPTION + V
544
580
  case 'v':
545
581
  case 'V':
546
582
  if (!e.ctrlKey && !e.metaKey) {
@@ -555,7 +591,9 @@ var Canvas = /** @class */ (function () {
555
591
  _this.drawingLineName = _this.store.options.drawingLineName;
556
592
  }
557
593
  }
558
- if ((e.ctrlKey || e.metaKey) && _this.store.options.disableClipboard) {
594
+ if ((e.ctrlKey || e.metaKey) && (_this.store.options.disableClipboard ||
595
+ (!_this.store.options.disableClipboard && e.altKey)) //alt按下,paste事件无效
596
+ ) {
559
597
  _this.paste();
560
598
  }
561
599
  break;
@@ -657,6 +695,22 @@ var Canvas = /** @class */ (function () {
657
695
  case 'L':
658
696
  _this.canMoveLine = true;
659
697
  break;
698
+ case '[':
699
+ //下一层
700
+ _this.parent.down();
701
+ break;
702
+ case ']':
703
+ //上一层
704
+ _this.parent.up();
705
+ break;
706
+ case '{':
707
+ // 置底
708
+ _this.parent.bottom();
709
+ break;
710
+ case '}':
711
+ //置顶
712
+ _this.parent.top();
713
+ break;
660
714
  }
661
715
  _this.render(false);
662
716
  };
@@ -1241,7 +1295,7 @@ var Canvas = /** @class */ (function () {
1241
1295
  var pt = { x: e.x, y: e.y };
1242
1296
  // Move line anchor
1243
1297
  if (_this.hoverType === HoverType.LineAnchor) {
1244
- if ((_this.store.active[0].lineName === 'line' || _this.dockInAnchor(e)) &&
1298
+ if ((_this.dockInAnchor(e) || _this.store.active[0].lineName === 'line') &&
1245
1299
  !_this.store.options.disableDock &&
1246
1300
  !_this.store.options.disableLineDock) {
1247
1301
  _this.clearDock();
@@ -2335,8 +2389,16 @@ var Canvas = /** @class */ (function () {
2335
2389
  pen.x -= initRect.center.x - _this.store.clipboard.pos.x;
2336
2390
  pen.y -= initRect.center.y - _this.store.clipboard.pos.y;
2337
2391
  }
2338
- pen.x += _this.store.clipboard.offset * _this.store.data.scale;
2339
- pen.y += _this.store.clipboard.offset * _this.store.data.scale;
2392
+ if (_this.keyOptions && _this.keyOptions.altKey && (_this.keyOptions.ctrlKey || _this.keyOptions.metaKey)) {
2393
+ pen.x = -_this.store.data.x + _this.width / 2 - pen.width / 2;
2394
+ pen.y = -_this.store.data.y + _this.height / 2 - pen.height / 2;
2395
+ }
2396
+ else if (_this.keyOptions && _this.keyOptions.shiftKey && (_this.keyOptions.ctrlKey || _this.keyOptions.metaKey)) {
2397
+ }
2398
+ else {
2399
+ pen.x += _this.store.clipboard.offset * _this.store.data.scale;
2400
+ pen.y += _this.store.clipboard.offset * _this.store.data.scale;
2401
+ }
2340
2402
  }
2341
2403
  _this.makePen(pen);
2342
2404
  var newChildren = [];
@@ -2360,6 +2422,7 @@ var Canvas = /** @class */ (function () {
2360
2422
  }
2361
2423
  }
2362
2424
  pen.children = newChildren;
2425
+ calcInView(pen, true);
2363
2426
  return pen;
2364
2427
  };
2365
2428
  this.ondblclick = function (e) {
@@ -4297,6 +4360,8 @@ var Canvas = /** @class */ (function () {
4297
4360
  calcPadding(pen, rect);
4298
4361
  calcTextRect(pen);
4299
4362
  calcInView(pen);
4363
+ pen.calculative &&
4364
+ (pen.calculative.gradientAnimatePath = undefined);
4300
4365
  this.store.path2dMap.set(pen, globalStore.path2dDraws[pen.name](pen));
4301
4366
  if (pen.calculative.worldAnchors) {
4302
4367
  pen.anchors = pen.calculative.worldAnchors.map(function (pt) {
@@ -5325,6 +5390,10 @@ var Canvas = /** @class */ (function () {
5325
5390
  this.render();
5326
5391
  this.store.active[0].calculative &&
5327
5392
  (this.store.active[0].calculative.gradientAnimatePath = undefined);
5393
+ this.store.emitter.emit('moveLineAnchor', {
5394
+ pen: this.store.active[0],
5395
+ anchor: this.store.activeAnchor,
5396
+ });
5328
5397
  if (this.timer) {
5329
5398
  clearTimeout(this.timer);
5330
5399
  }
@@ -6025,6 +6094,9 @@ var Canvas = /** @class */ (function () {
6025
6094
  if (pen.calculative[k] === undefined) {
6026
6095
  continue;
6027
6096
  }
6097
+ if (k === 'length') {
6098
+ continue;
6099
+ }
6028
6100
  if (typeof pen[k] !== 'object' || k === 'lineDash') {
6029
6101
  if (k === 'lineWidth') {
6030
6102
  pen[k] =
@@ -6894,6 +6966,10 @@ var Canvas = /** @class */ (function () {
6894
6966
  pen.canvasLayer === CanvasLayer.CanvasTemplate) {
6895
6967
  this.initTemplateCanvas([pen]);
6896
6968
  }
6969
+ if (data.zIndex !== undefined) {
6970
+ pen.calculative.singleton.div &&
6971
+ setElemPosition(pen, pen.calculative.singleton.div);
6972
+ }
6897
6973
  };
6898
6974
  /**
6899
6975
  * 执行 pen ,以及 pen 的子孙节点的 onResize 生命周期函数