@leafer/miniapp 1.6.7 → 1.7.0

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.
@@ -43,7 +43,7 @@ const IncrementId = {
43
43
  };
44
44
  const I$2 = IncrementId;
45
45
 
46
- const { round: round$6, pow: pow$2, PI: PI$5 } = Math;
46
+ const { round: round$6, pow: pow$2, PI: PI$4 } = Math;
47
47
  const MathHelper = {
48
48
  within(value, min, max) {
49
49
  if (typeof min === 'object')
@@ -139,9 +139,9 @@ const MathHelper = {
139
139
  function randInt(num) {
140
140
  return Math.round(Math.random() * num);
141
141
  }
142
- const OneRadian = PI$5 / 180;
143
- const PI2 = PI$5 * 2;
144
- const PI_2 = PI$5 / 2;
142
+ const OneRadian = PI$4 / 180;
143
+ const PI2 = PI$4 * 2;
144
+ const PI_2 = PI$4 / 2;
145
145
  function getPointData() { return { x: 0, y: 0 }; }
146
146
  function getBoundsData() { return { x: 0, y: 0, width: 0, height: 0 }; }
147
147
  function getMatrixData() { return { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }; }
@@ -436,7 +436,7 @@ const MatrixHelper = {
436
436
  const M$a = MatrixHelper;
437
437
 
438
438
  const { toInnerPoint: toInnerPoint$2, toOuterPoint: toOuterPoint$3 } = MatrixHelper;
439
- const { sin: sin$5, cos: cos$5, abs: abs$7, sqrt: sqrt$4, atan2: atan2$2, min: min$1, round: round$5, PI: PI$4 } = Math;
439
+ const { sin: sin$5, cos: cos$5, abs: abs$7, sqrt: sqrt$4, atan2: atan2$2, min: min$1, round: round$5 } = Math;
440
440
  const PointHelper = {
441
441
  defaultPoint: getPointData(),
442
442
  tempPoint: {},
@@ -549,10 +549,11 @@ const PointHelper = {
549
549
  getRadianFrom(fromX, fromY, originX, originY, toX, toY, toOriginX, toOriginY) {
550
550
  if (toOriginX === undefined)
551
551
  toOriginX = originX, toOriginY = originY;
552
- let fromAngle = atan2$2(fromY - originY, fromX - originX);
553
- let toAngle = atan2$2(toY - toOriginY, toX - toOriginX);
554
- const radian = toAngle - fromAngle;
555
- return radian < -PI$4 ? radian + PI2 : radian;
552
+ const a = fromX - originX;
553
+ const b = fromY - originY;
554
+ const c = toX - toOriginX;
555
+ const d = toY - toOriginY;
556
+ return Math.atan2(a * d - b * c, a * c + b * d);
556
557
  },
557
558
  getAtan2(t, to) {
558
559
  return atan2$2(to.y - t.y, to.x - t.x);
@@ -3339,7 +3340,7 @@ const { getCenterX, getCenterY } = PointHelper;
3339
3340
  const { arcTo } = PathCommandDataHelper;
3340
3341
  const PathCorner = {
3341
3342
  smooth(data, cornerRadius, _cornerSmoothing) {
3342
- let command, commandLen;
3343
+ let command, lastCommand, commandLen;
3343
3344
  let i = 0, x = 0, y = 0, startX = 0, startY = 0, secondX = 0, secondY = 0, lastX = 0, lastY = 0;
3344
3345
  const len = data.length;
3345
3346
  const smooth = [];
@@ -3377,8 +3378,10 @@ const PathCorner = {
3377
3378
  lastY = y;
3378
3379
  break;
3379
3380
  case Z$3:
3380
- arcTo(smooth, startX, startY, secondX, secondY, cornerRadius, lastX, lastY);
3381
- smooth.push(Z$3);
3381
+ if (lastCommand !== Z$3) {
3382
+ arcTo(smooth, startX, startY, secondX, secondY, cornerRadius, lastX, lastY);
3383
+ smooth.push(Z$3);
3384
+ }
3382
3385
  i += 1;
3383
3386
  break;
3384
3387
  default:
@@ -3387,6 +3390,7 @@ const PathCorner = {
3387
3390
  smooth.push(data[i + j]);
3388
3391
  i += commandLen;
3389
3392
  }
3393
+ lastCommand = command;
3390
3394
  }
3391
3395
  if (command !== Z$3) {
3392
3396
  smooth[1] = startX;
@@ -3883,12 +3887,12 @@ class LeaferImage {
3883
3887
  try {
3884
3888
  if (transform && pattern.setTransform) {
3885
3889
  pattern.setTransform(transform);
3886
- transform = null;
3890
+ transform = undefined;
3887
3891
  }
3888
3892
  }
3889
3893
  catch (_a) { }
3890
3894
  if (paint)
3891
- paint.transform = transform;
3895
+ DataHelper.stintSet(paint, 'transform', transform);
3892
3896
  return pattern;
3893
3897
  }
3894
3898
  destroy() {
@@ -3993,10 +3997,14 @@ function pathInputType(defaultValue) {
3993
3997
  }));
3994
3998
  }
3995
3999
  const pathType = boundsType;
3996
- function affectStrokeBoundsType(defaultValue) {
4000
+ function affectStrokeBoundsType(defaultValue, useStroke) {
3997
4001
  return decorateLeafAttr(defaultValue, (key) => attr({
3998
4002
  set(value) {
3999
- this.__setAttr(key, value) && doStrokeType(this);
4003
+ if (this.__setAttr(key, value)) {
4004
+ doStrokeType(this);
4005
+ if (useStroke)
4006
+ this.__.__useStroke = true;
4007
+ }
4000
4008
  }
4001
4009
  }));
4002
4010
  }
@@ -5422,6 +5430,8 @@ const LeafBounds = {
5422
5430
 
5423
5431
  const LeafRender = {
5424
5432
  __render(canvas, options) {
5433
+ if (options.shape)
5434
+ return this.__renderShape(canvas, options);
5425
5435
  if (this.__worldOpacity) {
5426
5436
  const data = this.__;
5427
5437
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
@@ -5431,12 +5441,10 @@ const LeafRender = {
5431
5441
  return this.__renderEraser(canvas, options);
5432
5442
  const tempCanvas = canvas.getSameCanvas(true, true);
5433
5443
  this.__draw(tempCanvas, options, canvas);
5434
- if (this.__worldFlipped) {
5444
+ if (this.__worldFlipped)
5435
5445
  canvas.copyWorldByReset(tempCanvas, this.__nowWorld, null, data.__blendMode, true);
5436
- }
5437
- else {
5446
+ else
5438
5447
  canvas.copyWorldToInner(tempCanvas, this.__nowWorld, this.__layout.renderBounds, data.__blendMode);
5439
- }
5440
5448
  tempCanvas.recycle(this.__nowWorld);
5441
5449
  }
5442
5450
  else {
@@ -5446,6 +5454,12 @@ const LeafRender = {
5446
5454
  Debug.drawBounds(this, canvas, options);
5447
5455
  }
5448
5456
  },
5457
+ __renderShape(canvas, options) {
5458
+ if (this.__worldOpacity) {
5459
+ canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
5460
+ this.__drawShape(canvas, options);
5461
+ }
5462
+ },
5449
5463
  __clip(canvas, options) {
5450
5464
  if (this.__worldOpacity) {
5451
5465
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
@@ -5865,7 +5879,8 @@ let Leaf = class Leaf {
5865
5879
  __drawFast(_canvas, _options) { }
5866
5880
  __draw(_canvas, _options, _originCanvas) { }
5867
5881
  __clip(_canvas, _options) { }
5868
- __renderShape(_canvas, _options, _ignoreFill, _ignoreStroke) { }
5882
+ __renderShape(_canvas, _options) { }
5883
+ __drawShape(_canvas, _options) { }
5869
5884
  __updateWorldOpacity() { }
5870
5885
  __updateChange() { }
5871
5886
  __drawPath(_canvas) { }
@@ -6233,7 +6248,7 @@ class LeafLevelList {
6233
6248
  }
6234
6249
  }
6235
6250
 
6236
- const version = "1.6.7";
6251
+ const version = "1.7.0";
6237
6252
 
6238
6253
  class LeaferCanvas extends LeaferCanvasBase {
6239
6254
  get allowBackgroundColor() { return false; }
@@ -7289,13 +7304,9 @@ class UIData extends LeafData {
7289
7304
  else
7290
7305
  return strokeWidth;
7291
7306
  }
7292
- get __hasStroke() { return this.stroke && this.strokeWidth; }
7293
- get __hasHalf() { const t = this; return (t.stroke && t.strokeAlign === 'center' && t.strokeWidth % 2) || undefined; }
7294
7307
  get __hasMultiPaint() {
7295
7308
  const t = this;
7296
- if ((t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect)
7297
- return true;
7298
- return t.fill && this.__hasStroke;
7309
+ return (t.fill && this.__useStroke) || (t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect;
7299
7310
  }
7300
7311
  get __clipAfterFill() { const t = this; return (t.cornerRadius || t.innerShadow || t.__pathInputed); }
7301
7312
  get __hasSurface() { const t = this; return (t.fill || t.stroke); }
@@ -7586,15 +7597,18 @@ const { stintSet: stintSet$1 } = DataHelper;
7586
7597
  const UIRender = {
7587
7598
  __updateChange() {
7588
7599
  const data = this.__;
7600
+ if (data.__useStroke) {
7601
+ const useStroke = data.__useStroke = !!(data.stroke && data.strokeWidth);
7602
+ stintSet$1(this.__world, 'half', useStroke && data.strokeAlign === 'center' && data.strokeWidth % 2);
7603
+ stintSet$1(data, '__fillAfterStroke', useStroke && data.strokeAlign === 'outside' && data.fill && !data.__isTransparentFill);
7604
+ }
7589
7605
  if (data.__useEffect) {
7590
7606
  const { shadow, fill, stroke } = data, otherEffect = data.innerShadow || data.blur || data.backgroundBlur || data.filter;
7591
7607
  stintSet$1(data, '__isFastShadow', shadow && !otherEffect && shadow.length < 2 && !shadow[0].spread && !(shadow[0].box && data.__isTransparentFill) && fill && !(fill instanceof Array && fill.length > 1) && (this.useFastShadow || !stroke || (stroke && data.strokeAlign === 'inside')));
7592
7608
  data.__useEffect = !!(shadow || otherEffect);
7593
7609
  }
7594
- stintSet$1(this.__world, 'half', data.__hasHalf);
7595
- stintSet$1(data, '__fillAfterStroke', data.stroke && data.strokeAlign === 'outside' && data.fill && !data.__isTransparentFill);
7596
7610
  data.__checkSingle();
7597
- stintSet$1(data, '__complex', data.__isFills || data.__isStrokes || data.cornerRadius || data.__useEffect);
7611
+ stintSet$1(data, '__complex', (data.__isFills || data.__isStrokes || data.cornerRadius || data.__useEffect));
7598
7612
  },
7599
7613
  __drawFast(canvas, options) {
7600
7614
  drawFast(this, canvas, options);
@@ -7652,18 +7666,15 @@ const UIRender = {
7652
7666
  this.__drawFast(canvas, options);
7653
7667
  }
7654
7668
  },
7655
- __renderShape(canvas, options, ignoreFill, ignoreStroke) {
7656
- if (this.__worldOpacity) {
7657
- canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
7658
- const { fill, stroke } = this.__;
7659
- this.__drawRenderPath(canvas);
7660
- if (fill && !ignoreFill)
7661
- this.__.__isAlphaPixelFill ? Paint.fills(fill, this, canvas) : Paint.fill('#000000', this, canvas);
7662
- if (this.__.__isCanvas)
7663
- this.__drawAfterFill(canvas, options);
7664
- if (stroke && !ignoreStroke)
7665
- this.__.__isAlphaPixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
7666
- }
7669
+ __drawShape(canvas, options) {
7670
+ this.__drawRenderPath(canvas);
7671
+ const data = this.__, { fill, stroke } = data;
7672
+ if (fill && !options.ignoreFill)
7673
+ data.__isAlphaPixelFill ? Paint.fills(fill, this, canvas) : Paint.fill('#000000', this, canvas);
7674
+ if (data.__isCanvas)
7675
+ this.__drawAfterFill(canvas, options);
7676
+ if (stroke && !options.ignoreStroke)
7677
+ data.__isAlphaPixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
7667
7678
  },
7668
7679
  __drawAfterFill(canvas, options) {
7669
7680
  if (this.__.__clipAfterFill) {
@@ -7788,12 +7799,14 @@ let UI = UI_1 = class UI extends Leaf {
7788
7799
  }
7789
7800
  }
7790
7801
  __updateRenderPath() {
7791
- if (this.__.path) {
7792
- const data = this.__;
7802
+ const data = this.__;
7803
+ if (data.path) {
7793
7804
  data.__pathForRender = data.cornerRadius ? PathCorner.smooth(data.path, data.cornerRadius, data.cornerSmoothing) : data.path;
7794
7805
  if (data.__useArrow)
7795
7806
  PathArrow.addArrows(this, !data.cornerRadius);
7796
7807
  }
7808
+ else
7809
+ data.__pathForRender && (data.__pathForRender = undefined);
7797
7810
  }
7798
7811
  __drawRenderPath(canvas) {
7799
7812
  canvas.beginPath();
@@ -8004,13 +8017,13 @@ __decorate([
8004
8017
  surfaceType()
8005
8018
  ], UI.prototype, "fill", void 0);
8006
8019
  __decorate([
8007
- strokeType()
8020
+ strokeType(undefined, true)
8008
8021
  ], UI.prototype, "stroke", void 0);
8009
8022
  __decorate([
8010
8023
  strokeType('inside')
8011
8024
  ], UI.prototype, "strokeAlign", void 0);
8012
8025
  __decorate([
8013
- strokeType(1)
8026
+ strokeType(1, true)
8014
8027
  ], UI.prototype, "strokeWidth", void 0);
8015
8028
  __decorate([
8016
8029
  strokeType(false)
@@ -8437,7 +8450,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
8437
8450
  list.push(item);
8438
8451
  this.requestRender();
8439
8452
  }
8440
- zoom(_zoomType, _padding, _fixedScale, _transition) {
8453
+ zoom(_zoomType, _optionsOrPadding, _scroll, _transition) {
8441
8454
  return Plugin.need('view');
8442
8455
  }
8443
8456
  getValidMove(moveX, moveY) { return { x: moveX, y: moveY }; }
@@ -8482,7 +8495,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
8482
8495
  Leafer_1.list.remove(this);
8483
8496
  try {
8484
8497
  this.stop();
8485
- this.emitEvent(new LeaferEvent(LeaferEvent.END, this));
8498
+ this.emitLeafer(LeaferEvent.END);
8486
8499
  this.__removeListenEvents();
8487
8500
  this.__controllers.forEach(item => !(this.parent && item === this.interaction) && item.destroy());
8488
8501
  this.__controllers.length = 0;
@@ -8610,7 +8623,7 @@ let Box = class Box extends Group {
8610
8623
  }
8611
8624
  __drawContent(canvas, options) {
8612
8625
  this.__renderGroup(canvas, options);
8613
- if (this.__.__hasStroke) {
8626
+ if (this.__.__useStroke) {
8614
8627
  canvas.setWorld(this.__nowWorld);
8615
8628
  this.__drawRenderPath(canvas);
8616
8629
  }
@@ -8830,8 +8843,8 @@ let Polygon = class Polygon extends UI {
8830
8843
  for (let i = 1; i < sides; i++) {
8831
8844
  lineTo$1(path, rx + rx * sin$2((i * 2 * PI$2) / sides), ry - ry * cos$2((i * 2 * PI$2) / sides));
8832
8845
  }
8846
+ closePath$1(path);
8833
8847
  }
8834
- closePath$1(path);
8835
8848
  }
8836
8849
  __updateRenderPath() { }
8837
8850
  __updateBoxBounds() { }
@@ -9069,6 +9082,11 @@ let Text = class Text extends UI {
9069
9082
  return;
9070
9083
  super.__draw(canvas, options, originCanvas);
9071
9084
  }
9085
+ __drawShape(canvas, options) {
9086
+ if (options.shape)
9087
+ this.__box && this.__box.__drawShape(canvas, options);
9088
+ super.__drawShape(canvas, options);
9089
+ }
9072
9090
  destroy() {
9073
9091
  if (this.boxStyle)
9074
9092
  this.boxStyle = null;
@@ -9890,6 +9908,7 @@ const config$1 = {
9890
9908
  delta: { x: 80 / 4, y: 8.0 },
9891
9909
  },
9892
9910
  pointer: {
9911
+ type: 'pointer',
9893
9912
  snap: true,
9894
9913
  hitRadius: 5,
9895
9914
  tapTime: 120,
@@ -10433,7 +10452,7 @@ ui$5.__updateHitCanvas = function () {
10433
10452
  h.resize({ width, height, pixelRatio: 1 });
10434
10453
  h.clear();
10435
10454
  ImageManager.patternLocked = true;
10436
- this.__renderShape(h, { matrix: matrix$2.setWith(this.__world).scaleWith(1 / scale).invertWith().translate(-x, -y) }, !isHitPixelFill, !isHitPixelStroke);
10455
+ this.__renderShape(h, { matrix: matrix$2.setWith(this.__world).scaleWith(1 / scale).invertWith().translate(-x, -y), ignoreFill: !isHitPixelFill, ignoreStroke: !isHitPixelStroke });
10437
10456
  ImageManager.patternLocked = false;
10438
10457
  h.resetTransform();
10439
10458
  data.__isHitPixel = true;
@@ -10942,7 +10961,7 @@ const PaintModule = {
10942
10961
  };
10943
10962
 
10944
10963
  let origin$1 = {};
10945
- const { get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, scale: scaleHelper, rotate: rotate$2 } = MatrixHelper;
10964
+ const { get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, scale: scaleHelper, rotate: rotate$2, skew: skewHelper } = MatrixHelper;
10946
10965
  function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
10947
10966
  const transform = get$3();
10948
10967
  translate$1(transform, box.x + x, box.y + y);
@@ -10951,13 +10970,15 @@ function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
10951
10970
  rotateOfOuter$1(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
10952
10971
  data.transform = transform;
10953
10972
  }
10954
- function clipMode(data, box, x, y, scaleX, scaleY, rotation) {
10973
+ function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew) {
10955
10974
  const transform = get$3();
10956
- translate$1(transform, box.x + x, box.y + y);
10957
- if (scaleX)
10958
- scaleHelper(transform, scaleX, scaleY);
10959
10975
  if (rotation)
10960
10976
  rotate$2(transform, rotation);
10977
+ if (skew)
10978
+ skewHelper(transform, skew.x, skew.y);
10979
+ if (scaleX)
10980
+ scaleHelper(transform, scaleX, scaleY);
10981
+ translate$1(transform, box.x + x, box.y + y);
10961
10982
  data.transform = transform;
10962
10983
  }
10963
10984
  function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align) {
@@ -10994,11 +11015,13 @@ const tempBox = new Bounds();
10994
11015
  const tempScaleData = {};
10995
11016
  const tempImage = {};
10996
11017
  function createData(leafPaint, image, paint, box) {
10997
- const { changeful, sync } = paint;
11018
+ const { changeful, sync, editing } = paint;
10998
11019
  if (changeful)
10999
11020
  leafPaint.changeful = changeful;
11000
11021
  if (sync)
11001
11022
  leafPaint.sync = sync;
11023
+ if (editing)
11024
+ leafPaint.editing = editing;
11002
11025
  leafPaint.data = getPatternData(paint, box, image);
11003
11026
  }
11004
11027
  function getPatternData(paint, box, image) {
@@ -11007,7 +11030,7 @@ function getPatternData(paint, box, image) {
11007
11030
  if (paint.mode === 'strench')
11008
11031
  paint.mode = 'stretch';
11009
11032
  let { width, height } = image;
11010
- const { opacity, mode, align, offset, scale, size, rotation, repeat, filters } = paint;
11033
+ const { opacity, mode, align, offset, scale, size, rotation, skew, repeat, filters } = paint;
11011
11034
  const sameBox = box.width === width && box.height === height;
11012
11035
  const data = { mode };
11013
11036
  const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
@@ -11041,8 +11064,8 @@ function getPatternData(paint, box, image) {
11041
11064
  break;
11042
11065
  case 'normal':
11043
11066
  case 'clip':
11044
- if (tempImage.x || tempImage.y || scaleX || rotation)
11045
- clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
11067
+ if (tempImage.x || tempImage.y || scaleX || rotation || skew)
11068
+ clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew);
11046
11069
  break;
11047
11070
  case 'repeat':
11048
11071
  if (!sameBox || scaleX || rotation)
@@ -11119,11 +11142,11 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
11119
11142
  }
11120
11143
  onLoadSuccess(ui, event);
11121
11144
  }
11122
- leafPaint.loadId = null;
11145
+ leafPaint.loadId = undefined;
11123
11146
  }, (error) => {
11124
11147
  ignoreRender(ui, false);
11125
11148
  onLoadError(ui, event, error);
11126
- leafPaint.loadId = null;
11149
+ leafPaint.loadId = undefined;
11127
11150
  });
11128
11151
  if (ui.placeholderColor) {
11129
11152
  if (!ui.placeholderDelay)
@@ -11189,6 +11212,8 @@ function createPattern(ui, paint, pixelRatio) {
11189
11212
  const { image, data } = paint;
11190
11213
  let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, transform, repeat } = data;
11191
11214
  if (sx) {
11215
+ sx = abs$4(sx);
11216
+ sy = abs$4(sy);
11192
11217
  imageMatrix = get$1();
11193
11218
  copy$4(imageMatrix, transform);
11194
11219
  scale$2(imageMatrix, 1 / sx, 1 / sy);
@@ -12189,41 +12214,10 @@ class EditorEvent extends Event {
12189
12214
  }
12190
12215
  EditorEvent.BEFORE_SELECT = 'editor.before_select';
12191
12216
  EditorEvent.SELECT = 'editor.select';
12217
+ EditorEvent.AFTER_SELECT = 'editor.after_select';
12192
12218
  EditorEvent.BEFORE_HOVER = 'editor.before_hover';
12193
12219
  EditorEvent.HOVER = 'editor.hover';
12194
12220
 
12195
- class EditorMoveEvent extends EditorEvent {
12196
- constructor(type, data) {
12197
- super(type, data);
12198
- }
12199
- }
12200
- EditorMoveEvent.BEFORE_MOVE = 'editor.before_move';
12201
- EditorMoveEvent.MOVE = 'editor.move';
12202
-
12203
- class EditorScaleEvent extends EditorEvent {
12204
- constructor(type, data) {
12205
- super(type, data);
12206
- }
12207
- }
12208
- EditorScaleEvent.BEFORE_SCALE = 'editor.before_scale';
12209
- EditorScaleEvent.SCALE = 'editor.scale';
12210
-
12211
- class EditorRotateEvent extends EditorEvent {
12212
- constructor(type, data) {
12213
- super(type, data);
12214
- }
12215
- }
12216
- EditorRotateEvent.BEFORE_ROTATE = 'editor.before_rotate';
12217
- EditorRotateEvent.ROTATE = 'editor.rotate';
12218
-
12219
- class EditorSkewEvent extends EditorEvent {
12220
- constructor(type, data) {
12221
- super(type, data);
12222
- }
12223
- }
12224
- EditorSkewEvent.BEFORE_SKEW = 'editor.before_skew';
12225
- EditorSkewEvent.SKEW = 'editor.skew';
12226
-
12227
12221
  function targetAttr(fn) {
12228
12222
  return (target, key) => {
12229
12223
  const privateKey = '_' + key;
@@ -12634,16 +12628,16 @@ const { topLeft: topLeft$1, top: top$1, topRight: topRight$1, right: right$2, bo
12634
12628
  const { toPoint } = AroundHelper;
12635
12629
  const { within: within$2 } = MathHelper;
12636
12630
  const EditDataHelper = {
12637
- getScaleData(element, startBounds, direction, totalMove, lockRatio, around, flipable, scaleMode) {
12631
+ getScaleData(target, startBounds, direction, totalMove, lockRatio, around, flipable, scaleMode) {
12638
12632
  let align, origin = {}, scaleX = 1, scaleY = 1;
12639
- const { boxBounds, widthRange, heightRange, dragBounds, worldBoxBounds } = element;
12633
+ const { boxBounds, widthRange, heightRange, dragBounds, worldBoxBounds } = target;
12640
12634
  const { width, height } = startBounds;
12641
12635
  if (around) {
12642
12636
  totalMove.x *= 2;
12643
12637
  totalMove.y *= 2;
12644
12638
  }
12645
- const originChangedScaleX = element.scaleX / startBounds.scaleX;
12646
- const originChangedScaleY = element.scaleY / startBounds.scaleY;
12639
+ const originChangedScaleX = target.scaleX / startBounds.scaleX;
12640
+ const originChangedScaleY = target.scaleY / startBounds.scaleY;
12647
12641
  const signX = originChangedScaleX < 0 ? -1 : 1;
12648
12642
  const signY = originChangedScaleY < 0 ? -1 : 1;
12649
12643
  const changedScaleX = scaleMode ? originChangedScaleX : signX * boxBounds.width / width;
@@ -12719,7 +12713,7 @@ const EditDataHelper = {
12719
12713
  if (useScaleY)
12720
12714
  scaleY /= changedScaleY;
12721
12715
  if (!flipable) {
12722
- const { worldTransform } = element;
12716
+ const { worldTransform } = target;
12723
12717
  if (scaleX < 0)
12724
12718
  scaleX = 1 / boxBounds.width / worldTransform.scaleX;
12725
12719
  if (scaleY < 0)
@@ -12727,9 +12721,9 @@ const EditDataHelper = {
12727
12721
  }
12728
12722
  toPoint(around || align, boxBounds, origin, true);
12729
12723
  if (dragBounds) {
12730
- const allowBounds = dragBounds === 'parent' ? element.parent.boxBounds : dragBounds;
12731
- const localBounds = new Bounds(element.__localBoxBounds);
12732
- localBounds.scaleOf(element.getLocalPointByInner(origin), scaleX, scaleY);
12724
+ const allowBounds = dragBounds === 'parent' ? target.parent.boxBounds : dragBounds;
12725
+ const localBounds = new Bounds(target.__localBoxBounds);
12726
+ localBounds.scaleOf(target.getLocalPointByInner(origin), scaleX, scaleY);
12733
12727
  if (!BoundsHelper.includes(allowBounds, localBounds)) {
12734
12728
  const realBounds = localBounds.getIntersect(allowBounds);
12735
12729
  const fitScaleX = realBounds.width / localBounds.width, fitScaleY = realBounds.height / localBounds.height;
@@ -12740,11 +12734,11 @@ const EditDataHelper = {
12740
12734
  }
12741
12735
  }
12742
12736
  if (useScaleX && widthRange) {
12743
- const nowWidth = boxBounds.width * element.scaleX;
12737
+ const nowWidth = boxBounds.width * target.scaleX;
12744
12738
  scaleX = within$2(nowWidth * scaleX, widthRange) / nowWidth;
12745
12739
  }
12746
12740
  if (useScaleY && heightRange) {
12747
- const nowHeight = boxBounds.height * element.scaleY;
12741
+ const nowHeight = boxBounds.height * target.scaleY;
12748
12742
  scaleY = within$2(nowHeight * scaleY, heightRange) / nowHeight;
12749
12743
  }
12750
12744
  if (useScaleX && Math.abs(scaleX * worldBoxBounds.width) < 1)
@@ -12755,7 +12749,7 @@ const EditDataHelper = {
12755
12749
  scaleY = scaleX = Math.min(scaleX, scaleY);
12756
12750
  return { origin, scaleX, scaleY, direction, lockRatio, around };
12757
12751
  },
12758
- getRotateData(bounds, direction, current, last, around) {
12752
+ getRotateData(target, direction, current, last, around) {
12759
12753
  let align, origin = {};
12760
12754
  switch (direction) {
12761
12755
  case topLeft$1:
@@ -12773,8 +12767,8 @@ const EditDataHelper = {
12773
12767
  default:
12774
12768
  align = 'center';
12775
12769
  }
12776
- toPoint(around || align, bounds, origin, true);
12777
- return { origin, rotation: PointHelper.getRotation(last, origin, current) };
12770
+ toPoint(around || align, target.boxBounds, origin, true);
12771
+ return { origin, rotation: PointHelper.getRotation(last, target.getWorldPointByBox(origin), current) };
12778
12772
  },
12779
12773
  getSkewData(bounds, direction, move, around) {
12780
12774
  let align, origin = {}, skewX = 0, skewY = 0;
@@ -12871,9 +12865,9 @@ const EditDataHelper = {
12871
12865
  };
12872
12866
 
12873
12867
  const cacheCursors = {};
12874
- function updateCursor(editor, e) {
12875
- const { editBox } = editor, point = editBox.enterPoint;
12876
- if (!point || !editor.editing || !editBox.visible)
12868
+ function updateCursor(editBox, e) {
12869
+ const { enterPoint: point } = editBox;
12870
+ if (!point || !editBox.editor.editing || !editBox.visible)
12877
12871
  return;
12878
12872
  if (point.name === 'circle')
12879
12873
  return;
@@ -12882,9 +12876,8 @@ function updateCursor(editor, e) {
12882
12876
  point.cursor = 'pointer';
12883
12877
  return;
12884
12878
  }
12885
- let { rotation } = editBox;
12886
- const { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editor.mergeConfig;
12887
- const { pointType } = point, { flippedX, flippedY } = editBox;
12879
+ let { rotation, flippedX, flippedY } = editBox;
12880
+ const { pointType } = point, { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editBox.mergeConfig;
12888
12881
  let showResize = pointType.includes('resize');
12889
12882
  if (showResize && rotateable && (e.metaKey || e.ctrlKey || !resizeable))
12890
12883
  showResize = false;
@@ -12901,9 +12894,9 @@ function updateCursor(editor, e) {
12901
12894
  cacheCursors[key] = point.cursor = { url: toDataURL(url, rotation), x, y };
12902
12895
  }
12903
12896
  }
12904
- function updateMoveCursor(editor) {
12905
- const { moveCursor, moveable } = editor.mergeConfig;
12906
- editor.editBox.rect.cursor = moveable ? moveCursor : undefined;
12897
+ function updateMoveCursor(editBox) {
12898
+ const { moveCursor, moveable } = editBox.mergeConfig;
12899
+ editBox.rect.cursor = moveable ? moveCursor : undefined;
12907
12900
  }
12908
12901
  function toDataURL(svg, rotation) {
12909
12902
  return '"data:image/svg+xml,' + encodeURIComponent(svg.replace('{{rotation}}', rotation.toString())) + '"';
@@ -12918,6 +12911,15 @@ class EditPoint extends Box {
12918
12911
 
12919
12912
  const fourDirection = ['top', 'right', 'bottom', 'left'], editConfig = undefined;
12920
12913
  class EditBox extends Group {
12914
+ get mergeConfig() {
12915
+ const { config } = this, { mergeConfig } = this.editor;
12916
+ return this.mergedConfig = config ? Object.assign(Object.assign({}, mergeConfig), config) : mergeConfig;
12917
+ }
12918
+ get target() { return this._target || this.editor.element; }
12919
+ set target(target) { this._target = target; }
12920
+ get single() { return !!this._target || this.editor.single; }
12921
+ get transformTool() { return this._transformTool || this.editor; }
12922
+ set transformTool(tool) { this._transformTool = tool; }
12921
12923
  get flipped() { return this.flippedX || this.flippedY; }
12922
12924
  get flippedX() { return this.scaleX < 0; }
12923
12925
  get flippedY() { return this.scaleY < 0; }
@@ -12960,8 +12962,7 @@ class EditBox extends Group {
12960
12962
  this.add(view);
12961
12963
  }
12962
12964
  load() {
12963
- const { mergeConfig, element, single } = this.editor;
12964
- const { rect, circle, resizePoints } = this;
12965
+ const { target, mergeConfig, single, rect, circle, resizePoints } = this;
12965
12966
  const { stroke, strokeWidth } = mergeConfig;
12966
12967
  const pointsStyle = this.getPointsStyle();
12967
12968
  const middlePointsStyle = this.getMiddlePointsStyle();
@@ -12974,18 +12975,26 @@ class EditBox extends Group {
12974
12975
  }
12975
12976
  circle.set(this.getPointStyle(mergeConfig.circle || mergeConfig.rotatePoint || pointsStyle[0]));
12976
12977
  rect.set(Object.assign({ stroke, strokeWidth, editConfig }, (mergeConfig.rect || {})));
12977
- rect.hittable = !single;
12978
- rect.syncEventer = single && this.editor;
12979
- if (single) {
12980
- element.syncEventer = rect;
12981
- this.app.interaction.bottomList = [{ target: rect, proxy: element }];
12978
+ const syncEventer = single && this.transformTool.editTool;
12979
+ rect.hittable = !syncEventer;
12980
+ rect.syncEventer = syncEventer && this.editor;
12981
+ if (syncEventer) {
12982
+ target.syncEventer = rect;
12983
+ this.app.interaction.bottomList = [{ target: rect, proxy: target }];
12982
12984
  }
12985
+ updateMoveCursor(this);
12983
12986
  }
12984
- update(bounds) {
12985
- const { rect, circle, buttons, resizePoints, rotatePoints, resizeLines, editor } = this;
12986
- const { mergeConfig, element, multiple, editMask } = editor;
12987
+ update() {
12988
+ const { editor } = this;
12989
+ const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = this.target.getLayoutBounds('box', editor, true);
12990
+ this.set({ x, y, scaleX, scaleY, rotation, skewX, skewY });
12991
+ this.updateBounds({ x: 0, y: 0, width, height });
12992
+ }
12993
+ updateBounds(bounds) {
12994
+ const { editMask } = this.editor;
12995
+ const { mergeConfig, single, rect, circle, buttons, resizePoints, rotatePoints, resizeLines } = this;
12987
12996
  const { middlePoint, resizeable, rotateable, hideOnSmall, editBox, mask } = mergeConfig;
12988
- this.visible = !element.locked;
12997
+ this.visible = !this.target.locked;
12989
12998
  editMask.visible = mask ? true : 0;
12990
12999
  if (this.view.worldOpacity) {
12991
13000
  const { width, height } = bounds;
@@ -13019,25 +13028,25 @@ class EditBox extends Group {
13019
13028
  }
13020
13029
  circle.visible = showPoints && rotateable && !!(mergeConfig.circle || mergeConfig.rotatePoint);
13021
13030
  if (circle.visible)
13022
- this.layoutCircle(mergeConfig);
13031
+ this.layoutCircle();
13023
13032
  if (rect.path)
13024
13033
  rect.path = null;
13025
- rect.set(Object.assign(Object.assign({}, bounds), { visible: multiple ? true : editBox }));
13034
+ rect.set(Object.assign(Object.assign({}, bounds), { visible: single ? editBox : true }));
13026
13035
  buttons.visible = showPoints && buttons.children.length > 0 || 0;
13027
13036
  if (buttons.visible)
13028
- this.layoutButtons(mergeConfig);
13037
+ this.layoutButtons();
13029
13038
  }
13030
13039
  else
13031
13040
  rect.set(bounds);
13032
13041
  }
13033
- layoutCircle(config) {
13034
- const { circleDirection, circleMargin, buttonsMargin, buttonsDirection, middlePoint } = config;
13042
+ layoutCircle() {
13043
+ const { circleDirection, circleMargin, buttonsMargin, buttonsDirection, middlePoint } = this.mergedConfig;
13035
13044
  const direction = fourDirection.indexOf(circleDirection || ((this.buttons.children.length && buttonsDirection === 'bottom') ? 'top' : 'bottom'));
13036
13045
  this.setButtonPosition(this.circle, direction, circleMargin || buttonsMargin, !!middlePoint);
13037
13046
  }
13038
- layoutButtons(config) {
13047
+ layoutButtons() {
13039
13048
  const { buttons } = this;
13040
- const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = config;
13049
+ const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = this.mergedConfig;
13041
13050
  const { flippedX, flippedY } = this;
13042
13051
  let index = fourDirection.indexOf(buttonsDirection);
13043
13052
  if ((index % 2 && flippedX) || ((index + 1) % 2 && flippedY)) {
@@ -13070,16 +13079,16 @@ class EditBox extends Group {
13070
13079
  this.visible = false;
13071
13080
  }
13072
13081
  getPointStyle(userStyle) {
13073
- const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.editor.mergeConfig;
13082
+ const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.mergedConfig;
13074
13083
  const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius, offsetX: 0, offsetY: 0, editConfig };
13075
13084
  return userStyle ? Object.assign(defaultStyle, userStyle) : defaultStyle;
13076
13085
  }
13077
13086
  getPointsStyle() {
13078
- const { point } = this.editor.mergeConfig;
13087
+ const { point } = this.mergedConfig;
13079
13088
  return point instanceof Array ? point : [point];
13080
13089
  }
13081
13090
  getMiddlePointsStyle() {
13082
- const { middlePoint } = this.editor.mergeConfig;
13091
+ const { middlePoint } = this.mergedConfig;
13083
13092
  return middlePoint instanceof Array ? middlePoint : (middlePoint ? [middlePoint] : this.getPointsStyle());
13084
13093
  }
13085
13094
  onSelect(e) {
@@ -13092,16 +13101,16 @@ class EditBox extends Group {
13092
13101
  onDragStart(e) {
13093
13102
  this.dragging = true;
13094
13103
  const point = this.dragPoint = e.current, { pointType } = point;
13095
- const { editor, dragStartData } = this, { element } = editor;
13104
+ const { editor, dragStartData } = this, { target } = this;
13096
13105
  if (point.name === 'rect') {
13097
13106
  this.moving = true;
13098
- editor.opacity = editor.mergeConfig.hideOnMove ? 0 : 1;
13107
+ editor.opacity = this.mergeConfig.hideOnMove ? 0 : 1;
13099
13108
  }
13100
13109
  dragStartData.x = e.x;
13101
13110
  dragStartData.y = e.y;
13102
- dragStartData.point = { x: element.x, y: element.y };
13103
- dragStartData.bounds = Object.assign({}, element.getLayoutBounds('box', 'local'));
13104
- dragStartData.rotation = element.rotation;
13111
+ dragStartData.point = { x: target.x, y: target.y };
13112
+ dragStartData.bounds = Object.assign({}, target.getLayoutBounds('box', 'local'));
13113
+ dragStartData.rotation = target.rotation;
13105
13114
  if (pointType && pointType.includes('resize'))
13106
13115
  ResizeEvent.resizingKeys = editor.leafList.keys;
13107
13116
  }
@@ -13116,22 +13125,31 @@ class EditBox extends Group {
13116
13125
  ResizeEvent.resizingKeys = null;
13117
13126
  }
13118
13127
  onDrag(e) {
13119
- const { editor } = this;
13120
- const { pointType } = this.enterPoint = e.current;
13121
- if (pointType.includes('rotate') || e.metaKey || e.ctrlKey || !editor.mergeConfig.resizeable) {
13122
- editor.onRotate(e);
13123
- if (pointType === 'resize-rotate')
13124
- editor.onScale(e);
13125
- }
13126
- else if (pointType === 'resize')
13127
- editor.onScale(e);
13128
- if (pointType === 'skew')
13129
- editor.onSkew(e);
13130
- updateCursor(editor, e);
13128
+ const { transformTool } = this, point = e.current;
13129
+ if (point.name === 'rect') {
13130
+ transformTool.onMove(e);
13131
+ updateMoveCursor(this);
13132
+ }
13133
+ else {
13134
+ const { pointType } = this.enterPoint = point;
13135
+ if (pointType.includes('rotate') || e.metaKey || e.ctrlKey || !this.mergeConfig.resizeable) {
13136
+ transformTool.onRotate(e);
13137
+ if (pointType === 'resize-rotate')
13138
+ transformTool.onScale(e);
13139
+ }
13140
+ else if (pointType === 'resize')
13141
+ transformTool.onScale(e);
13142
+ if (pointType === 'skew')
13143
+ transformTool.onSkew(e);
13144
+ updateCursor(this, e);
13145
+ }
13146
+ }
13147
+ onKey(e) {
13148
+ updateCursor(this, e);
13131
13149
  }
13132
13150
  onArrow(e) {
13133
13151
  const { editor } = this;
13134
- if (editor.editing && editor.mergeConfig.keyEvent) {
13152
+ if (editor.editing && this.mergeConfig.keyEvent) {
13135
13153
  let x = 0, y = 0;
13136
13154
  const distance = e.shiftKey ? 10 : 1;
13137
13155
  switch (e.code) {
@@ -13152,27 +13170,28 @@ class EditBox extends Group {
13152
13170
  }
13153
13171
  }
13154
13172
  onDoubleTap(e) {
13155
- if (this.editor.mergeConfig.openInner === 'double')
13173
+ const { openInner, preventEditInner } = this.mergeConfig;
13174
+ if (openInner === 'double' && !preventEditInner)
13156
13175
  this.openInner(e);
13157
13176
  }
13158
13177
  onLongPress(e) {
13159
- if (this.editor.mergeConfig.openInner === 'long')
13178
+ const { openInner, preventEditInner } = this.mergeConfig;
13179
+ if (openInner === 'long' && preventEditInner)
13160
13180
  this.openInner(e);
13161
13181
  }
13162
13182
  openInner(e) {
13163
- const { editor } = this;
13164
- if (editor.single) {
13165
- const { element } = editor;
13166
- if (element.locked)
13183
+ const { editor, target } = this;
13184
+ if (this.single) {
13185
+ if (target.locked)
13167
13186
  return;
13168
- if (element.isBranch && !element.editInner) {
13169
- if (element.textBox) {
13170
- const { children } = element;
13187
+ if (target.isBranch && !target.editInner) {
13188
+ if (target.textBox) {
13189
+ const { children } = target;
13171
13190
  const find = children.find(item => item.editable && item instanceof Text) || children.find(item => item instanceof Text);
13172
13191
  if (find)
13173
13192
  return editor.openInnerEditor(find);
13174
13193
  }
13175
- editor.openGroup(element);
13194
+ editor.openGroup(target);
13176
13195
  editor.target = editor.selector.findDeepOne(e);
13177
13196
  }
13178
13197
  else {
@@ -13181,7 +13200,6 @@ class EditBox extends Group {
13181
13200
  }
13182
13201
  }
13183
13202
  listenPointEvents(point, type, direction) {
13184
- const { editor } = this;
13185
13203
  point.direction = direction;
13186
13204
  point.pointType = type;
13187
13205
  const events = [
@@ -13191,19 +13209,25 @@ class EditBox extends Group {
13191
13209
  [PointerEvent.LEAVE, () => { this.enterPoint = null; }],
13192
13210
  ];
13193
13211
  if (point.name !== 'circle')
13194
- events.push([PointerEvent.ENTER, (e) => { this.enterPoint = point, updateCursor(editor, e); }]);
13212
+ events.push([PointerEvent.ENTER, (e) => { this.enterPoint = point, updateCursor(this, e); }]);
13195
13213
  this.__eventIds.push(point.on_(events));
13196
13214
  }
13197
13215
  __listenEvents() {
13198
- const { rect, editor } = this;
13199
- this.__eventIds.push(editor.on_(EditorEvent.SELECT, this.onSelect, this), rect.on_([
13216
+ const { rect, editor, __eventIds: events } = this;
13217
+ events.push(editor.on_(EditorEvent.SELECT, this.onSelect, this), rect.on_([
13200
13218
  [DragEvent.START, this.onDragStart, this],
13201
- [DragEvent.DRAG, editor.onMove, editor],
13219
+ [DragEvent.DRAG, this.onDrag, this],
13202
13220
  [DragEvent.END, this.onDragEnd, this],
13203
- [PointerEvent.ENTER, () => updateMoveCursor(editor)],
13221
+ [PointerEvent.ENTER, () => updateMoveCursor(this)],
13204
13222
  [PointerEvent.DOUBLE_TAP, this.onDoubleTap, this],
13205
13223
  [PointerEvent.LONG_PRESS, this.onLongPress, this]
13206
13224
  ]));
13225
+ this.waitLeafer(() => {
13226
+ events.push(editor.app.on_([
13227
+ [[KeyEvent.HOLD, KeyEvent.UP], this.onKey, this],
13228
+ [KeyEvent.DOWN, this.onArrow, this]
13229
+ ]));
13230
+ });
13207
13231
  }
13208
13232
  __removeListenEvents() {
13209
13233
  this.off_(this.__eventIds);
@@ -13234,11 +13258,12 @@ class EditMask extends UI {
13234
13258
  if (options.bounds && !options.bounds.hit(editor.editBox.rect.__world, options.matrix))
13235
13259
  return;
13236
13260
  canvas.saveBlendMode('destination-out');
13261
+ options = Object.assign(Object.assign({}, options), { shape: true });
13237
13262
  editor.list.forEach(item => {
13238
- item.__renderShape(canvas, options);
13239
- const { __box, parent } = item;
13240
- if ((item = __box) || ((item = parent) && parent.textBox))
13241
- item.__renderShape(canvas, options);
13263
+ item.__render(canvas, options);
13264
+ const { parent } = item;
13265
+ if (parent && parent.textBox)
13266
+ parent.__renderShape(canvas, options);
13242
13267
  });
13243
13268
  canvas.restoreBlendMode();
13244
13269
  }
@@ -13333,7 +13358,7 @@ const config = {
13333
13358
  const bounds$1 = new Bounds();
13334
13359
  function simulate(editor) {
13335
13360
  const { simulateTarget, list } = editor;
13336
- const { zoomLayer } = list[0].leafer.zoomLayer;
13361
+ const { zoomLayer } = list[0].leafer;
13337
13362
  simulateTarget.safeChange(() => {
13338
13363
  bounds$1.setListWithFn(list, (leaf) => leaf.getBounds('box', 'page'));
13339
13364
  if (bounds$1.width === 0)
@@ -13355,15 +13380,14 @@ function onTarget(editor, oldValue) {
13355
13380
  else {
13356
13381
  editor.simulateTarget.remove();
13357
13382
  editor.leafList.reset();
13358
- editor.closeInnerEditor();
13359
13383
  }
13360
- editor.emitEvent(new EditorEvent(EditorEvent.SELECT, { editor, value: target, oldValue }));
13384
+ editor.closeInnerEditor();
13385
+ const data = { editor, value: target, oldValue };
13386
+ editor.emitEvent(new EditorEvent(EditorEvent.SELECT, data));
13361
13387
  editor.checkOpenedGroups();
13362
13388
  if (editor.editing) {
13363
13389
  editor.waitLeafer(() => {
13364
- updateMoveCursor(editor);
13365
13390
  editor.updateEditTool();
13366
- editor.update();
13367
13391
  editor.listenTargetEvents();
13368
13392
  });
13369
13393
  }
@@ -13371,6 +13395,7 @@ function onTarget(editor, oldValue) {
13371
13395
  editor.updateEditTool();
13372
13396
  editor.removeTargetEvents();
13373
13397
  }
13398
+ editor.emitEvent(new EditorEvent(EditorEvent.AFTER_SELECT, data));
13374
13399
  }
13375
13400
  function onHover(editor, oldValue) {
13376
13401
  editor.emitEvent(new EditorEvent(EditorEvent.HOVER, { editor, value: editor.hoverTarget, oldValue }));
@@ -13542,93 +13567,45 @@ class SimulateElement extends Rect {
13542
13567
  }
13543
13568
  }
13544
13569
 
13545
- class Editor extends Group {
13546
- get list() { return this.leafList.list; }
13547
- get dragHoverExclude() { return [this.editBox.rect]; }
13548
- get editing() { return !!this.list.length; }
13549
- get groupOpening() { return !!this.openedGroupList.length; }
13550
- get multiple() { return this.list.length > 1; }
13551
- get single() { return this.list.length === 1; }
13552
- get dragging() { return this.editBox.dragging; }
13553
- get moving() { return this.editBox.moving; }
13554
- get dragPoint() { return this.editBox.dragPoint; }
13555
- get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
13556
- get buttons() { return this.editBox.buttons; }
13557
- constructor(userConfig, data) {
13558
- super(data);
13559
- this.leafList = new LeafList();
13560
- this.openedGroupList = new LeafList();
13561
- this.simulateTarget = new SimulateElement(this);
13562
- this.editBox = new EditBox(this);
13563
- this.editToolList = {};
13564
- this.selector = new EditSelect(this);
13565
- this.editMask = new EditMask(this);
13566
- this.targetEventIds = [];
13567
- let mergedConfig = DataHelper.clone(config);
13568
- if (userConfig)
13569
- mergedConfig = DataHelper.default(userConfig, mergedConfig);
13570
- this.mergedConfig = this.config = mergedConfig;
13571
- this.addMany(this.editMask, this.selector, this.editBox);
13572
- if (!Plugin.has('resize'))
13573
- this.config.editSize = 'scale';
13574
- }
13575
- select(target) {
13576
- this.target = target;
13577
- }
13578
- cancel() {
13579
- this.target = null;
13580
- }
13581
- hasItem(item) {
13582
- return this.leafList.has(item);
13583
- }
13584
- addItem(item) {
13585
- if (!this.hasItem(item) && !item.locked)
13586
- this.leafList.add(item), this.target = this.leafList.list;
13587
- }
13588
- removeItem(item) {
13589
- if (this.hasItem(item))
13590
- this.leafList.remove(item), this.target = this.leafList.list;
13591
- }
13592
- shiftItem(item) {
13593
- this.hasItem(item) ? this.removeItem(item) : this.addItem(item);
13594
- }
13595
- update() {
13596
- if (this.editing) {
13597
- if (!this.element.parent)
13598
- return this.cancel();
13599
- if (this.innerEditing)
13600
- this.innerEditor.update();
13601
- this.editTool.update();
13602
- this.selector.update();
13603
- }
13570
+ class EditorMoveEvent extends EditorEvent {
13571
+ constructor(type, data) {
13572
+ super(type, data);
13604
13573
  }
13605
- updateEditBox() {
13606
- if (this.multiple)
13607
- simulate(this);
13608
- this.update();
13574
+ }
13575
+ EditorMoveEvent.BEFORE_MOVE = 'editor.before_move';
13576
+ EditorMoveEvent.MOVE = 'editor.move';
13577
+
13578
+ class EditorScaleEvent extends EditorEvent {
13579
+ constructor(type, data) {
13580
+ super(type, data);
13609
13581
  }
13610
- updateEditTool() {
13611
- const tool = this.editTool;
13612
- if (tool) {
13613
- this.editBox.unload();
13614
- tool.unload();
13615
- this.editTool = null;
13616
- }
13617
- if (this.editing) {
13618
- const tag = this.single ? this.list[0].editOuter : 'EditTool';
13619
- this.editTool = this.editToolList[tag] = this.editToolList[tag] || EditToolCreator.get(tag, this);
13620
- this.editBox.load();
13621
- this.editTool.load();
13622
- }
13582
+ }
13583
+ EditorScaleEvent.BEFORE_SCALE = 'editor.before_scale';
13584
+ EditorScaleEvent.SCALE = 'editor.scale';
13585
+
13586
+ class EditorRotateEvent extends EditorEvent {
13587
+ constructor(type, data) {
13588
+ super(type, data);
13623
13589
  }
13624
- getEditSize(_ui) {
13625
- return this.mergeConfig.editSize;
13590
+ }
13591
+ EditorRotateEvent.BEFORE_ROTATE = 'editor.before_rotate';
13592
+ EditorRotateEvent.ROTATE = 'editor.rotate';
13593
+
13594
+ class EditorSkewEvent extends EditorEvent {
13595
+ constructor(type, data) {
13596
+ super(type, data);
13626
13597
  }
13598
+ }
13599
+ EditorSkewEvent.BEFORE_SKEW = 'editor.before_skew';
13600
+ EditorSkewEvent.SKEW = 'editor.skew';
13601
+
13602
+ class TransformTool {
13627
13603
  onMove(e) {
13604
+ const { target, mergeConfig, dragStartData } = this.editBox;
13628
13605
  if (e instanceof MoveEvent) {
13629
13606
  if (e.moveType !== 'drag') {
13630
- const { moveable, resizeable } = this.mergeConfig;
13631
- const move = e.getLocalMove(this.element);
13607
+ const { moveable, resizeable } = mergeConfig;
13608
+ const move = e.getLocalMove(target);
13632
13609
  if (moveable === 'move')
13633
13610
  e.stop(), this.move(move.x, move.y);
13634
13611
  else if (resizeable === 'zoom')
@@ -13643,22 +13620,22 @@ class Editor extends Group {
13643
13620
  else
13644
13621
  total.x = 0;
13645
13622
  }
13646
- this.move(DragEvent.getValidMove(this.element, this.editBox.dragStartData.point, total));
13623
+ this.move(DragEvent.getValidMove(target, dragStartData.point, total));
13647
13624
  }
13648
13625
  }
13649
13626
  onScale(e) {
13650
- const { element } = this;
13651
- let { around, lockRatio, resizeable, flipable, editSize } = this.mergeConfig;
13627
+ const { target, mergeConfig, single, dragStartData } = this.editBox;
13628
+ let { around, lockRatio, resizeable, flipable, editSize } = mergeConfig;
13652
13629
  if (e instanceof ZoomEvent) {
13653
13630
  if (resizeable === 'zoom')
13654
- e.stop(), this.scaleOf(element.getBoxPoint(e), e.scale, e.scale);
13631
+ e.stop(), this.scaleOf(target.getBoxPoint(e), e.scale, e.scale);
13655
13632
  }
13656
13633
  else {
13657
13634
  const { direction } = e.current;
13658
- if (e.shiftKey || element.lockRatio)
13635
+ if (e.shiftKey || target.lockRatio)
13659
13636
  lockRatio = true;
13660
- const data = EditDataHelper.getScaleData(element, this.editBox.dragStartData.bounds, direction, e.getInnerTotal(element), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, this.multiple || editSize === 'scale');
13661
- if (this.editTool.onScaleWithDrag) {
13637
+ const data = EditDataHelper.getScaleData(target, dragStartData.bounds, direction, e.getInnerTotal(target), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, !single || editSize === 'scale');
13638
+ if (this.editTool && this.editTool.onScaleWithDrag) {
13662
13639
  data.drag = e;
13663
13640
  this.scaleWithDrag(data);
13664
13641
  }
@@ -13668,38 +13645,38 @@ class Editor extends Group {
13668
13645
  }
13669
13646
  }
13670
13647
  onRotate(e) {
13671
- const { skewable, rotateable, around, rotateGap } = this.mergeConfig;
13648
+ const { target, mergeConfig, dragStartData } = this.editBox;
13649
+ const { skewable, rotateable, around, rotateGap } = mergeConfig;
13672
13650
  const { direction, name } = e.current;
13673
13651
  if (skewable && name === 'resize-line')
13674
13652
  return this.onSkew(e);
13675
- const { element } = this, { dragStartData } = this.editBox;
13676
13653
  let origin, rotation;
13677
13654
  if (e instanceof RotateEvent) {
13678
13655
  if (rotateable === 'rotate')
13679
- e.stop(), rotation = e.rotation, origin = element.getBoxPoint(e);
13656
+ e.stop(), rotation = e.rotation, origin = target.getBoxPoint(e);
13680
13657
  else
13681
13658
  return;
13682
- if (element.scaleX * element.scaleY < 0)
13659
+ if (target.scaleX * target.scaleY < 0)
13683
13660
  rotation = -rotation;
13684
13661
  }
13685
13662
  else {
13686
- const data = EditDataHelper.getRotateData(element.boxBounds, direction, e.getBoxPoint(element), element.getBoxPoint(dragStartData), e.shiftKey ? null : (element.around || element.origin || around || 'center'));
13663
+ const data = EditDataHelper.getRotateData(target, direction, e, dragStartData, e.shiftKey ? null : (target.around || target.origin || around || 'center'));
13687
13664
  rotation = data.rotation;
13688
13665
  origin = data.origin;
13689
13666
  }
13690
- if (element.scaleX * element.scaleY < 0)
13667
+ if (target.scaleX * target.scaleY < 0)
13691
13668
  rotation = -rotation;
13692
13669
  if (e instanceof DragEvent)
13693
- rotation = dragStartData.rotation + rotation - element.rotation;
13694
- rotation = MathHelper.float(MathHelper.getGapRotation(rotation, rotateGap, element.rotation), 2);
13670
+ rotation = dragStartData.rotation + rotation - target.rotation;
13671
+ rotation = MathHelper.float(MathHelper.getGapRotation(rotation, rotateGap, target.rotation), 2);
13695
13672
  if (!rotation)
13696
13673
  return;
13697
13674
  this.rotateOf(origin, rotation);
13698
13675
  }
13699
13676
  onSkew(e) {
13700
- const { element } = this;
13701
- const { around } = this.mergeConfig;
13702
- const { origin, skewX, skewY } = EditDataHelper.getSkewData(element.boxBounds, e.current.direction, e.getInnerMove(element), EditDataHelper.getAround(around, e.altKey));
13677
+ const { target, mergeConfig } = this.editBox;
13678
+ const { around } = mergeConfig;
13679
+ const { origin, skewX, skewY } = EditDataHelper.getSkewData(target.boxBounds, e.current.direction, e.getInnerMove(target), EditDataHelper.getAround(around, e.altKey));
13703
13680
  if (!skewX && !skewY)
13704
13681
  return;
13705
13682
  this.skewOf(origin, skewX, skewY);
@@ -13709,7 +13686,8 @@ class Editor extends Group {
13709
13686
  return;
13710
13687
  if (typeof x === 'object')
13711
13688
  y = x.y, x = x.x;
13712
- const { element: target } = this, { beforeMove } = this.mergeConfig;
13689
+ const { target, mergeConfig, single, editor } = this.editBox;
13690
+ const { beforeMove } = mergeConfig;
13713
13691
  if (beforeMove) {
13714
13692
  const check = beforeMove({ target, x, y });
13715
13693
  if (typeof check === 'object')
@@ -13718,25 +13696,26 @@ class Editor extends Group {
13718
13696
  return;
13719
13697
  }
13720
13698
  const world = target.getWorldPointByLocal({ x, y }, null, true);
13721
- if (this.multiple)
13699
+ if (!single)
13722
13700
  target.safeChange(() => target.move(x, y));
13723
- const data = { target, editor: this, moveX: world.x, moveY: world.y };
13701
+ const data = { target, editor, moveX: world.x, moveY: world.y };
13724
13702
  this.emitEvent(new EditorMoveEvent(EditorMoveEvent.BEFORE_MOVE, data));
13725
13703
  const event = new EditorMoveEvent(EditorMoveEvent.MOVE, data);
13726
- this.editTool.onMove(event);
13704
+ this.doMove(event);
13727
13705
  this.emitEvent(event);
13728
13706
  }
13729
13707
  scaleWithDrag(data) {
13730
13708
  if (!this.checkTransform('resizeable'))
13731
13709
  return;
13732
- const { element: target } = this, { beforeScale } = this.mergeConfig;
13710
+ const { target, mergeConfig, editor } = this.editBox;
13711
+ const { beforeScale } = mergeConfig;
13733
13712
  if (beforeScale) {
13734
13713
  const { origin, scaleX, scaleY, drag } = data;
13735
13714
  const check = beforeScale({ target, drag, origin, scaleX, scaleY });
13736
13715
  if (check === false)
13737
13716
  return;
13738
13717
  }
13739
- data = Object.assign(Object.assign({}, data), { target, editor: this, worldOrigin: target.getWorldPoint(data.origin) });
13718
+ data = Object.assign(Object.assign({}, data), { target, editor, worldOrigin: target.getWorldPoint(data.origin) });
13740
13719
  this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
13741
13720
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
13742
13721
  this.editTool.onScaleWithDrag(event);
@@ -13745,7 +13724,8 @@ class Editor extends Group {
13745
13724
  scaleOf(origin, scaleX, scaleY = scaleX, _resize) {
13746
13725
  if (!this.checkTransform('resizeable'))
13747
13726
  return;
13748
- const { element: target } = this, { beforeScale } = this.mergeConfig;
13727
+ const { target, mergeConfig, single, editor } = this.editBox;
13728
+ const { beforeScale } = mergeConfig;
13749
13729
  if (beforeScale) {
13750
13730
  const check = beforeScale({ target, origin, scaleX, scaleY });
13751
13731
  if (typeof check === 'object')
@@ -13754,29 +13734,30 @@ class Editor extends Group {
13754
13734
  return;
13755
13735
  }
13756
13736
  const worldOrigin = this.getWorldOrigin(origin);
13757
- const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.scaleOf(origin, scaleX, scaleY)));
13758
- const data = { target, editor: this, worldOrigin, scaleX, scaleY, transform };
13737
+ const transform = !single && this.getChangedTransform(() => target.safeChange(() => target.scaleOf(origin, scaleX, scaleY)));
13738
+ const data = { target, editor, worldOrigin, scaleX, scaleY, transform };
13759
13739
  this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
13760
13740
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
13761
- this.editTool.onScale(event);
13741
+ this.doScale(event);
13762
13742
  this.emitEvent(event);
13763
13743
  }
13764
13744
  flip(axis) {
13765
13745
  if (!this.checkTransform('resizeable'))
13766
13746
  return;
13767
- const { element } = this;
13747
+ const { target, single, editor } = this.editBox;
13768
13748
  const worldOrigin = this.getWorldOrigin('center');
13769
- const transform = this.multiple ? this.getChangedTransform(() => element.safeChange(() => element.flip(axis))) : new Matrix(LeafHelper.getFlipTransform(element, axis));
13770
- const data = { target: element, editor: this, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform };
13749
+ const transform = !single ? this.getChangedTransform(() => target.safeChange(() => target.flip(axis))) : new Matrix(LeafHelper.getFlipTransform(target, axis));
13750
+ const data = { target, editor, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform };
13771
13751
  this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
13772
13752
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
13773
- this.editTool.onScale(event);
13753
+ this.doScale(event);
13774
13754
  this.emitEvent(event);
13775
13755
  }
13776
13756
  rotateOf(origin, rotation) {
13777
13757
  if (!this.checkTransform('rotateable'))
13778
13758
  return;
13779
- const { element: target } = this, { beforeRotate } = this.mergeConfig;
13759
+ const { target, mergeConfig, single, editor } = this.editBox;
13760
+ const { beforeRotate } = mergeConfig;
13780
13761
  if (beforeRotate) {
13781
13762
  const check = beforeRotate({ target, origin, rotation });
13782
13763
  if (typeof check === 'number')
@@ -13785,17 +13766,18 @@ class Editor extends Group {
13785
13766
  return;
13786
13767
  }
13787
13768
  const worldOrigin = this.getWorldOrigin(origin);
13788
- const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.rotateOf(origin, rotation)));
13789
- const data = { target, editor: this, worldOrigin, rotation, transform };
13769
+ const transform = !single && this.getChangedTransform(() => target.safeChange(() => target.rotateOf(origin, rotation)));
13770
+ const data = { target, editor, worldOrigin, rotation, transform };
13790
13771
  this.emitEvent(new EditorRotateEvent(EditorRotateEvent.BEFORE_ROTATE, data));
13791
13772
  const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, data);
13792
- this.editTool.onRotate(event);
13773
+ this.doRotate(event);
13793
13774
  this.emitEvent(event);
13794
13775
  }
13795
13776
  skewOf(origin, skewX, skewY = 0, _resize) {
13796
13777
  if (!this.checkTransform('skewable'))
13797
13778
  return;
13798
- const { element: target } = this, { beforeSkew } = this.mergeConfig;
13779
+ const { target, mergeConfig, single, editor } = this.editBox;
13780
+ const { beforeSkew } = mergeConfig;
13799
13781
  if (beforeSkew) {
13800
13782
  const check = beforeSkew({ target, origin, skewX, skewY });
13801
13783
  if (typeof check === 'object')
@@ -13804,25 +13786,142 @@ class Editor extends Group {
13804
13786
  return;
13805
13787
  }
13806
13788
  const worldOrigin = this.getWorldOrigin(origin);
13807
- const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.skewOf(origin, skewX, skewY)));
13808
- const data = { target, editor: this, worldOrigin, skewX, skewY, transform };
13789
+ const transform = !single && this.getChangedTransform(() => target.safeChange(() => target.skewOf(origin, skewX, skewY)));
13790
+ const data = { target, editor, worldOrigin, skewX, skewY, transform };
13809
13791
  this.emitEvent(new EditorSkewEvent(EditorSkewEvent.BEFORE_SKEW, data));
13810
13792
  const event = new EditorSkewEvent(EditorSkewEvent.SKEW, data);
13811
- this.editTool.onSkew(event);
13793
+ this.doSkew(event);
13812
13794
  this.emitEvent(event);
13813
13795
  }
13814
- checkTransform(type) { return this.element && !this.element.locked && this.mergeConfig[type]; }
13796
+ doMove(event) {
13797
+ this.editTool.onMove(event);
13798
+ }
13799
+ doScale(event) {
13800
+ this.editTool.onScale(event);
13801
+ }
13802
+ doRotate(event) {
13803
+ this.editTool.onRotate(event);
13804
+ }
13805
+ doSkew(event) {
13806
+ this.editTool.onSkew(event);
13807
+ }
13808
+ checkTransform(type) {
13809
+ const { target, mergeConfig } = this.editBox;
13810
+ return target && !target.locked && mergeConfig[type];
13811
+ }
13815
13812
  getWorldOrigin(origin) {
13816
- return this.element.getWorldPoint(LeafHelper.getInnerOrigin(this.element, origin));
13813
+ const { target } = this.editBox;
13814
+ return target.getWorldPoint(LeafHelper.getInnerOrigin(target, origin));
13817
13815
  }
13818
13816
  getChangedTransform(func) {
13819
- const { element } = this;
13820
- if (this.multiple && !element.canChange)
13821
- return element.changedTransform;
13822
- const oldMatrix = new Matrix(element.worldTransform);
13817
+ const { target, single } = this.editBox;
13818
+ if (!single && !target.canChange)
13819
+ return target.changedTransform;
13820
+ const oldMatrix = new Matrix(target.worldTransform);
13823
13821
  func();
13824
- return new Matrix(element.worldTransform).divide(oldMatrix);
13822
+ return new Matrix(target.worldTransform).divide(oldMatrix);
13825
13823
  }
13824
+ emitEvent(event, capture) {
13825
+ this.editBox.editor.emitEvent(event, capture);
13826
+ }
13827
+ }
13828
+
13829
+ let Editor = class Editor extends Group {
13830
+ get list() { return this.leafList.list; }
13831
+ get dragHoverExclude() { return [this.editBox.rect]; }
13832
+ get editing() { return !!this.list.length; }
13833
+ get groupOpening() { return !!this.openedGroupList.length; }
13834
+ get multiple() { return this.list.length > 1; }
13835
+ get single() { return this.list.length === 1; }
13836
+ get dragging() { return this.editBox.dragging; }
13837
+ get moving() { return this.editBox.moving; }
13838
+ get dragPoint() { return this.editBox.dragPoint; }
13839
+ get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
13840
+ get buttons() { return this.editBox.buttons; }
13841
+ constructor(userConfig, data) {
13842
+ super(data);
13843
+ this.leafList = new LeafList();
13844
+ this.openedGroupList = new LeafList();
13845
+ this.simulateTarget = new SimulateElement(this);
13846
+ this.editBox = new EditBox(this);
13847
+ this.editToolList = {};
13848
+ this.selector = new EditSelect(this);
13849
+ this.editMask = new EditMask(this);
13850
+ this.targetEventIds = [];
13851
+ let mergedConfig = DataHelper.clone(config);
13852
+ if (userConfig)
13853
+ mergedConfig = DataHelper.default(userConfig, mergedConfig);
13854
+ this.mergedConfig = this.config = mergedConfig;
13855
+ this.addMany(this.editMask, this.selector, this.editBox);
13856
+ if (!Plugin.has('resize'))
13857
+ this.config.editSize = 'scale';
13858
+ }
13859
+ select(target) {
13860
+ this.target = target;
13861
+ }
13862
+ cancel() {
13863
+ this.target = null;
13864
+ }
13865
+ hasItem(item) {
13866
+ return this.leafList.has(item);
13867
+ }
13868
+ addItem(item) {
13869
+ if (!this.hasItem(item) && !item.locked)
13870
+ this.leafList.add(item), this.target = this.leafList.list;
13871
+ }
13872
+ removeItem(item) {
13873
+ if (this.hasItem(item))
13874
+ this.leafList.remove(item), this.target = this.leafList.list;
13875
+ }
13876
+ shiftItem(item) {
13877
+ this.hasItem(item) ? this.removeItem(item) : this.addItem(item);
13878
+ }
13879
+ update() {
13880
+ if (this.editing) {
13881
+ if (!this.element.parent)
13882
+ return this.cancel();
13883
+ if (this.innerEditing)
13884
+ this.innerEditor.update();
13885
+ this.editTool.update();
13886
+ this.selector.update();
13887
+ }
13888
+ }
13889
+ updateEditBox() {
13890
+ if (this.multiple)
13891
+ simulate(this);
13892
+ this.update();
13893
+ }
13894
+ updateEditTool() {
13895
+ let tool = this.editTool;
13896
+ if (tool) {
13897
+ this.editBox.unload();
13898
+ tool.unload();
13899
+ this.editTool = null;
13900
+ }
13901
+ if (this.editing) {
13902
+ const tag = this.element.editOuter || 'EditTool';
13903
+ tool = this.editTool = this.editToolList[tag] = this.editToolList[tag] || EditToolCreator.get(tag, this);
13904
+ this.editBox.load();
13905
+ tool.load();
13906
+ this.update();
13907
+ }
13908
+ }
13909
+ getEditSize(_ui) {
13910
+ return this.mergeConfig.editSize;
13911
+ }
13912
+ onMove(_e) { }
13913
+ onScale(_e) { }
13914
+ onRotate(_e) { }
13915
+ onSkew(_e) { }
13916
+ move(_x, _y = 0) { }
13917
+ scaleWithDrag(_data) { }
13918
+ scaleOf(_origin, scaleX, _scaleY = scaleX, _resize) { }
13919
+ flip(_axis) { }
13920
+ rotateOf(_origin, _rotation) { }
13921
+ skewOf(_origin, _skewX, _skewY = 0, _resize) { }
13922
+ checkTransform(_type) { return undefined; }
13923
+ getWorldOrigin(_origin) { return undefined; }
13924
+ getChangedTransform(_func) { return undefined; }
13826
13925
  group(userGroup) {
13827
13926
  if (this.multiple) {
13828
13927
  this.emitGroupEvent(EditorGroupEvent.BEFORE_GROUP);
@@ -13940,12 +14039,9 @@ class Editor extends Group {
13940
14039
  if (this.targetChanged)
13941
14040
  this.update();
13942
14041
  }
13943
- onKey(e) {
13944
- updateCursor(this, e);
13945
- }
13946
14042
  listenTargetEvents() {
13947
14043
  if (!this.targetEventIds.length) {
13948
- const { app, leafer, editBox, editMask } = this;
14044
+ const { app, leafer, editMask } = this;
13949
14045
  this.targetEventIds = [
13950
14046
  leafer.on_(RenderEvent.START, this.onRenderStart, this),
13951
14047
  app.on_([
@@ -13953,8 +14049,6 @@ class Editor extends Group {
13953
14049
  [MoveEvent.BEFORE_MOVE, this.onMove, this, true],
13954
14050
  [ZoomEvent.BEFORE_ZOOM, this.onScale, this, true],
13955
14051
  [RotateEvent.BEFORE_ROTATE, this.onRotate, this, true],
13956
- [[KeyEvent.HOLD, KeyEvent.UP], this.onKey, this],
13957
- [KeyEvent.DOWN, editBox.onArrow, editBox]
13958
14052
  ])
13959
14053
  ];
13960
14054
  if (editMask.visible)
@@ -13979,7 +14073,7 @@ class Editor extends Group {
13979
14073
  super.destroy();
13980
14074
  }
13981
14075
  }
13982
- }
14076
+ };
13983
14077
  __decorate([
13984
14078
  mergeConfigAttr()
13985
14079
  ], Editor.prototype, "mergeConfig", void 0);
@@ -13989,14 +14083,19 @@ __decorate([
13989
14083
  __decorate([
13990
14084
  targetAttr(onTarget)
13991
14085
  ], Editor.prototype, "target", void 0);
14086
+ Editor = __decorate([
14087
+ useModule(TransformTool, ['editBox', 'editTool', 'emitEvent'])
14088
+ ], Editor);
13992
14089
 
13993
14090
  class InnerEditor {
13994
14091
  static registerInnerEditor() {
13995
14092
  EditToolCreator.register(this);
13996
14093
  }
13997
14094
  get tag() { return 'InnerEditor'; }
14095
+ get mode() { return 'focus'; }
13998
14096
  get editBox() { return this.editor.editBox; }
13999
14097
  constructor(editor) {
14098
+ this.eventIds = [];
14000
14099
  this.editor = editor;
14001
14100
  this.create();
14002
14101
  }
@@ -14009,7 +14108,7 @@ class InnerEditor {
14009
14108
  load() {
14010
14109
  const { editor } = this;
14011
14110
  if (editor) {
14012
- if (editor.app)
14111
+ if (editor.app && this.mode === 'focus')
14013
14112
  editor.selector.hittable = editor.app.tree.hitChildren = false;
14014
14113
  this.onLoad();
14015
14114
  }
@@ -14020,7 +14119,7 @@ class InnerEditor {
14020
14119
  unload() {
14021
14120
  const { editor } = this;
14022
14121
  if (editor) {
14023
- if (editor.app)
14122
+ if (editor.app && this.mode === 'focus')
14024
14123
  editor.selector.hittable = editor.app.tree.hitChildren = true;
14025
14124
  this.onUnload();
14026
14125
  }
@@ -14094,10 +14193,7 @@ let EditTool = class EditTool extends InnerEditor {
14094
14193
  this.onLoad();
14095
14194
  }
14096
14195
  update() {
14097
- const { editor, editBox } = this;
14098
- const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = editor.element.getLayoutBounds('box', editor, true);
14099
- editBox.set({ x, y, scaleX, scaleY, rotation, skewX, skewY });
14100
- editBox.update({ x: 0, y: 0, width, height });
14196
+ this.editBox.update();
14101
14197
  this.onUpdate();
14102
14198
  }
14103
14199
  unload() {
@@ -14838,8 +14934,16 @@ function getFixBounds(bounds, scaleBounds) {
14838
14934
  }
14839
14935
 
14840
14936
  Plugin.add('view');
14841
- Leafer.prototype.zoom = function (zoomType, padding, fixed, transition) {
14937
+ Leafer.prototype.zoom = function (zoomType, optionsOrPadding, scroll, transition) {
14842
14938
  this.killAnimate();
14939
+ let padding;
14940
+ if (typeof optionsOrPadding === 'object' && !(optionsOrPadding instanceof Array)) {
14941
+ padding = optionsOrPadding.padding;
14942
+ scroll = optionsOrPadding.scroll;
14943
+ transition = optionsOrPadding.transition;
14944
+ }
14945
+ else
14946
+ padding = optionsOrPadding;
14843
14947
  const { zoomLayer } = this;
14844
14948
  const limitBounds = this.canvas.bounds.clone().shrink(padding !== undefined ? padding : 30), bounds = new Bounds();
14845
14949
  const center = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 };
@@ -14886,7 +14990,7 @@ Leafer.prototype.zoom = function (zoomType, padding, fixed, transition) {
14886
14990
  }
14887
14991
  const { width, height } = bounds;
14888
14992
  let moveX = limitBounds.x - bounds.x, moveY = limitBounds.y - bounds.y;
14889
- if (fixed) {
14993
+ if (scroll) {
14890
14994
  moveX += Math.max((limitBounds.width - width) / 2, 0);
14891
14995
  moveY += Math.max((limitBounds.height - height) / 2, 0);
14892
14996
  }
@@ -14899,6 +15003,10 @@ Leafer.prototype.zoom = function (zoomType, padding, fixed, transition) {
14899
15003
  data.scaleX *= changeScale;
14900
15004
  data.scaleY *= changeScale;
14901
15005
  }
15006
+ if (scroll === 'x')
15007
+ moveY = 0;
15008
+ else if (scroll === 'y')
15009
+ moveX = 0;
14902
15010
  PointHelper.move(data, moveX, moveY);
14903
15011
  bounds.move(moveX, moveY);
14904
15012
  zoomLayer.set(data, transition);
@@ -18096,4 +18204,4 @@ Object.assign(Filter, {
18096
18204
  }
18097
18205
  });
18098
18206
 
18099
- export { AlignHelper, Animate, AnimateEasing, AnimateEvent, AnimateList, Answer, App, AroundHelper, Arrow, ArrowData, AutoBounds, BezierHelper, Bounds, BoundsEvent, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, Cursor, DataHelper, Debug, Direction4, Direction9, DragEvent, Dragger, DropEvent, EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorGroupEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Eventer, Export, FileHelper, Filter, Finder, Flow, Frame, FrameData, Group, GroupData, HighBezierHelper, HighCurveHelper, HitCanvasManager, Image, ImageData, ImageEvent, ImageManager, IncrementId, InnerEditor, InnerEditorEvent, Interaction, InteractionBase, InteractionHelper, KeyEvent, Keyboard, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, LeaferTypeCreator, Line, LineData, LineEditTool, MathHelper, Matrix, MatrixHelper, MoveEvent, MultiTouchHelper, MyDragEvent, MyImage, MyPointerEvent, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, PaintGradient, PaintImage, Path, PathArrow, PathArrowModule, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathMatrixHelper, PathNumberCommandLengthMap, PathNumberCommandMap, PathScaler, Pen, PenData, Picker, Platform, Plugin, Point, PointHelper, PointerButton, PointerEvent, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, Resource, Robot, RobotData, RotateEvent, Run, ScrollBar, SelectArea, Selector, Star, StarData, State, StringNumberMap, Stroker, SwipeEvent, TaskItem, TaskProcessor, Text, TextConvert, TextData, Transformer, Transition, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIEvent, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, WheelEventHelper, ZoomEvent, addViewport, addViewportConfig, affectRenderBoundsType, affectStrokeBoundsType, arrowType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, effectType, emptyData, eraserType, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, isEmptyData, isNull, layoutProcessor, maskType, motionPathType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, registerEditTool, registerInnerEditor, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleResize, scaleResizeFontSize, scaleResizeGroup, scaleResizePath, scaleResizePoints, scaleType, sortType, stateStyleType, stateType, strokeType, surfaceType, tempBounds$1 as tempBounds, tempMatrix, tempPoint$3 as tempPoint, useCanvas, useModule, version, visibleType, zoomLayerType };
18207
+ export { AlignHelper, Animate, AnimateEasing, AnimateEvent, AnimateList, Answer, App, AroundHelper, Arrow, ArrowData, AutoBounds, BezierHelper, Bounds, BoundsEvent, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, Cursor, DataHelper, Debug, Direction4, Direction9, DragEvent, Dragger, DropEvent, EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorGroupEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Eventer, Export, FileHelper, Filter, Finder, Flow, Frame, FrameData, Group, GroupData, HighBezierHelper, HighCurveHelper, HitCanvasManager, Image, ImageData, ImageEvent, ImageManager, IncrementId, InnerEditor, InnerEditorEvent, Interaction, InteractionBase, InteractionHelper, KeyEvent, Keyboard, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, LeaferTypeCreator, Line, LineData, LineEditTool, MathHelper, Matrix, MatrixHelper, MoveEvent, MultiTouchHelper, MyDragEvent, MyImage, MyPointerEvent, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, PaintGradient, PaintImage, Path, PathArrow, PathArrowModule, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathMatrixHelper, PathNumberCommandLengthMap, PathNumberCommandMap, PathScaler, Pen, PenData, Picker, Platform, Plugin, Point, PointHelper, PointerButton, PointerEvent, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, Resource, Robot, RobotData, RotateEvent, Run, ScrollBar, SelectArea, Selector, Star, StarData, State, StringNumberMap, Stroker, SwipeEvent, TaskItem, TaskProcessor, Text, TextConvert, TextData, TransformTool, Transformer, Transition, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIEvent, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, WheelEventHelper, ZoomEvent, addViewport, addViewportConfig, affectRenderBoundsType, affectStrokeBoundsType, arrowType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, effectType, emptyData, eraserType, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, isEmptyData, isNull, layoutProcessor, maskType, motionPathType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, registerEditTool, registerInnerEditor, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleResize, scaleResizeFontSize, scaleResizeGroup, scaleResizePath, scaleResizePoints, scaleType, sortType, stateStyleType, stateType, strokeType, surfaceType, tempBounds$1 as tempBounds, tempMatrix, tempPoint$3 as tempPoint, useCanvas, useModule, version, visibleType, zoomLayerType };