@leafer/worker 1.6.7 → 1.8.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$6, sqrt: sqrt$4, atan2: atan2$2, min: min$1, round: round$5 } = Math;
440
440
  const PointHelper = {
441
441
  defaultPoint: getPointData(),
442
442
  tempPoint: {},
@@ -531,8 +531,8 @@ const PointHelper = {
531
531
  return getDistanceFrom(t.x, t.y, point.x, point.y);
532
532
  },
533
533
  getDistanceFrom(x1, y1, x2, y2) {
534
- const x = abs$7(x2 - x1);
535
- const y = abs$7(y2 - y1);
534
+ const x = abs$6(x2 - x1);
535
+ const y = abs$6(y2 - y1);
536
536
  return sqrt$4(x * x + y * y);
537
537
  },
538
538
  getMinDistanceFrom(x1, y1, x2, y2, x3, y3) {
@@ -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);
@@ -762,7 +763,7 @@ class Matrix {
762
763
  MatrixHelper.reset(this);
763
764
  }
764
765
  }
765
- const tempMatrix = new Matrix();
766
+ const tempMatrix$1 = new Matrix();
766
767
 
767
768
  const TwoPointBoundsHelper = {
768
769
  tempPointBounds: {},
@@ -859,6 +860,12 @@ const AroundHelper = {
859
860
  }
860
861
  if (!onlyBoxSize)
861
862
  to.x += box.x, to.y += box.y;
863
+ },
864
+ getPoint(around, box, to) {
865
+ if (!to)
866
+ to = {};
867
+ AroundHelper.toPoint(around, box, to, true);
868
+ return to;
862
869
  }
863
870
  };
864
871
  function get$4(around) {
@@ -1787,10 +1794,13 @@ function contextAttr(realName) {
1787
1794
  return (target, key) => {
1788
1795
  if (!realName)
1789
1796
  realName = key;
1790
- Object.defineProperty(target, key, {
1797
+ const property = {
1791
1798
  get() { return this.context[realName]; },
1792
1799
  set(value) { this.context[realName] = value; }
1793
- });
1800
+ };
1801
+ if (key === 'strokeCap')
1802
+ property.set = function (value) { this.context[realName] = value === 'none' ? 'butt' : value; };
1803
+ Object.defineProperty(target, key, property);
1794
1804
  };
1795
1805
  }
1796
1806
  const contextMethodNameList = [];
@@ -2066,15 +2076,15 @@ __decorate([
2066
2076
  contextMethod()
2067
2077
  ], Canvas$1.prototype, "strokeText", null);
2068
2078
 
2069
- const { copy: copy$c, multiplyParent: multiplyParent$3 } = MatrixHelper, { round: round$4 } = Math;
2079
+ const { copy: copy$c, multiplyParent: multiplyParent$4 } = MatrixHelper, { round: round$4 } = Math;
2070
2080
  const minSize = { width: 1, height: 1, pixelRatio: 1 };
2071
2081
  const canvasSizeAttrs = ['width', 'height', 'pixelRatio'];
2072
2082
  class LeaferCanvasBase extends Canvas$1 {
2073
2083
  get width() { return this.size.width; }
2074
2084
  get height() { return this.size.height; }
2075
2085
  get pixelRatio() { return this.size.pixelRatio; }
2076
- get pixelWidth() { return this.width * this.pixelRatio; }
2077
- get pixelHeight() { return this.height * this.pixelRatio; }
2086
+ get pixelWidth() { return this.width * this.pixelRatio || 0; }
2087
+ get pixelHeight() { return this.height * this.pixelRatio || 0; }
2078
2088
  get pixelSnap() { return this.config.pixelSnap; }
2079
2089
  set pixelSnap(value) { this.config.pixelSnap = value; }
2080
2090
  get allowBackgroundColor() { return this.view && this.parentView; }
@@ -2139,7 +2149,7 @@ class LeaferCanvasBase extends Canvas$1 {
2139
2149
  setWorld(matrix, parentMatrix) {
2140
2150
  const { pixelRatio, pixelSnap } = this, w = this.worldTransform;
2141
2151
  if (parentMatrix)
2142
- multiplyParent$3(matrix, parentMatrix, w);
2152
+ multiplyParent$4(matrix, parentMatrix, w);
2143
2153
  w.a = matrix.a * pixelRatio;
2144
2154
  w.b = matrix.b * pixelRatio;
2145
2155
  w.c = matrix.c * pixelRatio;
@@ -2161,20 +2171,33 @@ class LeaferCanvasBase extends Canvas$1 {
2161
2171
  if (w)
2162
2172
  this.setTransform(w.a, w.b, w.c, w.d, w.e, w.f);
2163
2173
  }
2164
- setStroke(color, strokeWidth, options) {
2174
+ setStroke(color, strokeWidth, options, childOptions) {
2165
2175
  if (strokeWidth)
2166
2176
  this.strokeWidth = strokeWidth;
2167
2177
  if (color)
2168
2178
  this.strokeStyle = color;
2169
2179
  if (options)
2170
- this.setStrokeOptions(options);
2171
- }
2172
- setStrokeOptions(options) {
2173
- this.strokeCap = options.strokeCap === 'none' ? 'butt' : options.strokeCap;
2174
- this.strokeJoin = options.strokeJoin;
2175
- this.dashPattern = options.dashPattern;
2176
- this.dashOffset = options.dashOffset;
2177
- this.miterLimit = options.miterLimit;
2180
+ this.setStrokeOptions(options, childOptions);
2181
+ }
2182
+ setStrokeOptions(options, childOptions) {
2183
+ let { strokeCap, strokeJoin, dashPattern, dashOffset, miterLimit } = options;
2184
+ if (childOptions) {
2185
+ if (childOptions.strokeCap)
2186
+ strokeCap = childOptions.strokeCap;
2187
+ if (childOptions.strokeJoin)
2188
+ strokeJoin = childOptions.strokeJoin;
2189
+ if (childOptions.dashPattern !== undefined)
2190
+ dashPattern = childOptions.dashPattern;
2191
+ if (childOptions.dashOffset !== undefined)
2192
+ dashOffset = childOptions.dashOffset;
2193
+ if (childOptions.miterLimit)
2194
+ miterLimit = childOptions.miterLimit;
2195
+ }
2196
+ this.strokeCap = strokeCap;
2197
+ this.strokeJoin = strokeJoin;
2198
+ this.dashPattern = dashPattern;
2199
+ this.dashOffset = dashOffset;
2200
+ this.miterLimit = miterLimit;
2178
2201
  }
2179
2202
  saveBlendMode(blendMode) {
2180
2203
  this.savedBlendMode = this.blendMode;
@@ -2408,7 +2431,7 @@ const RectHelper = {
2408
2431
  }
2409
2432
  };
2410
2433
 
2411
- const { sin: sin$4, cos: cos$4, atan2: atan2$1, ceil: ceil$2, abs: abs$6, PI: PI$3, sqrt: sqrt$3, pow: pow$1 } = Math;
2434
+ const { sin: sin$4, cos: cos$4, atan2: atan2$1, ceil: ceil$2, abs: abs$5, PI: PI$3, sqrt: sqrt$3, pow: pow$1 } = Math;
2412
2435
  const { setPoint: setPoint$4, addPoint: addPoint$2 } = TwoPointBoundsHelper;
2413
2436
  const { set, toNumberPoints: toNumberPoints$1 } = PointHelper;
2414
2437
  const { M: M$9, L: L$a, C: C$8, Q: Q$7, Z: Z$8 } = PathCommandMap;
@@ -2483,7 +2506,7 @@ const BezierHelper = {
2483
2506
  let totalRadian = endRadian - startRadian;
2484
2507
  if (totalRadian < 0)
2485
2508
  totalRadian += PI2;
2486
- if (totalRadian === PI$3 || (abs$6(BAx + BAy) < 1.e-12) || (abs$6(CBx + CBy) < 1.e-12)) {
2509
+ if (totalRadian === PI$3 || (abs$5(BAx + BAy) < 1.e-12) || (abs$5(CBx + CBy) < 1.e-12)) {
2487
2510
  if (data)
2488
2511
  data.push(L$a, x1, y1);
2489
2512
  if (setPointBounds) {
@@ -2525,7 +2548,7 @@ const BezierHelper = {
2525
2548
  totalRadian -= PI2;
2526
2549
  if (anticlockwise)
2527
2550
  totalRadian -= PI2;
2528
- const parts = ceil$2(abs$6(totalRadian / PI_2));
2551
+ const parts = ceil$2(abs$5(totalRadian / PI_2));
2529
2552
  const partRadian = totalRadian / parts;
2530
2553
  const partRadian4Sin = sin$4(partRadian / 4);
2531
2554
  const control = 8 / 3 * partRadian4Sin * partRadian4Sin / sin$4(partRadian / 2);
@@ -2970,7 +2993,7 @@ const { current, pushData, copyData } = PathConvert;
2970
2993
 
2971
2994
  const { M: M$7, L: L$8, C: C$6, Q: Q$5, Z: Z$6, N: N$4, D: D$4, X: X$4, G: G$4, F: F$5, O: O$5, P: P$4, U: U$4 } = PathCommandMap;
2972
2995
  const { getMinDistanceFrom, getRadianFrom } = PointHelper;
2973
- const { tan, min, abs: abs$5 } = Math;
2996
+ const { tan, min, abs: abs$4 } = Math;
2974
2997
  const startPoint = {};
2975
2998
  const PathCommandDataHelper = {
2976
2999
  beginPath(data) {
@@ -3033,7 +3056,7 @@ const PathCommandDataHelper = {
3033
3056
  arcTo(data, x1, y1, x2, y2, radius, lastX, lastY) {
3034
3057
  if (lastX !== undefined) {
3035
3058
  const d = getMinDistanceFrom(lastX, lastY, x1, y1, x2, y2);
3036
- radius = min(radius, min(d / 2, d / 2 * abs$5(tan(getRadianFrom(lastX, lastY, x1, y1, x2, y2) / 2))));
3059
+ radius = min(radius, min(d / 2, d / 2 * abs$4(tan(getRadianFrom(lastX, lastY, x1, y1, x2, y2) / 2))));
3037
3060
  }
3038
3061
  data.push(U$4, x1, y1, x2, y2, radius);
3039
3062
  },
@@ -3339,7 +3362,7 @@ const { getCenterX, getCenterY } = PointHelper;
3339
3362
  const { arcTo } = PathCommandDataHelper;
3340
3363
  const PathCorner = {
3341
3364
  smooth(data, cornerRadius, _cornerSmoothing) {
3342
- let command, commandLen;
3365
+ let command, lastCommand, commandLen;
3343
3366
  let i = 0, x = 0, y = 0, startX = 0, startY = 0, secondX = 0, secondY = 0, lastX = 0, lastY = 0;
3344
3367
  const len = data.length;
3345
3368
  const smooth = [];
@@ -3377,8 +3400,10 @@ const PathCorner = {
3377
3400
  lastY = y;
3378
3401
  break;
3379
3402
  case Z$3:
3380
- arcTo(smooth, startX, startY, secondX, secondY, cornerRadius, lastX, lastY);
3381
- smooth.push(Z$3);
3403
+ if (lastCommand !== Z$3) {
3404
+ arcTo(smooth, startX, startY, secondX, secondY, cornerRadius, lastX, lastY);
3405
+ smooth.push(Z$3);
3406
+ }
3382
3407
  i += 1;
3383
3408
  break;
3384
3409
  default:
@@ -3387,6 +3412,7 @@ const PathCorner = {
3387
3412
  smooth.push(data[i + j]);
3388
3413
  i += commandLen;
3389
3414
  }
3415
+ lastCommand = command;
3390
3416
  }
3391
3417
  if (command !== Z$3) {
3392
3418
  smooth[1] = startX;
@@ -3883,12 +3909,12 @@ class LeaferImage {
3883
3909
  try {
3884
3910
  if (transform && pattern.setTransform) {
3885
3911
  pattern.setTransform(transform);
3886
- transform = null;
3912
+ transform = undefined;
3887
3913
  }
3888
3914
  }
3889
3915
  catch (_a) { }
3890
3916
  if (paint)
3891
- paint.transform = transform;
3917
+ DataHelper.stintSet(paint, 'transform', transform);
3892
3918
  return pattern;
3893
3919
  }
3894
3920
  destroy() {
@@ -3906,6 +3932,13 @@ function defineKey(target, key, descriptor, noConfigurable) {
3906
3932
  function getDescriptor(object, name) {
3907
3933
  return Object.getOwnPropertyDescriptor(object, name);
3908
3934
  }
3935
+ function createDescriptor(key, defaultValue) {
3936
+ const privateKey = '_' + key;
3937
+ return {
3938
+ get() { const v = this[privateKey]; return v === undefined ? defaultValue : v; },
3939
+ set(value) { this[privateKey] = value; }
3940
+ };
3941
+ }
3909
3942
  function getNames(object) {
3910
3943
  return Object.getOwnPropertyNames(object);
3911
3944
  }
@@ -3993,10 +4026,14 @@ function pathInputType(defaultValue) {
3993
4026
  }));
3994
4027
  }
3995
4028
  const pathType = boundsType;
3996
- function affectStrokeBoundsType(defaultValue) {
4029
+ function affectStrokeBoundsType(defaultValue, useStroke) {
3997
4030
  return decorateLeafAttr(defaultValue, (key) => attr({
3998
4031
  set(value) {
3999
- this.__setAttr(key, value) && doStrokeType(this);
4032
+ if (this.__setAttr(key, value)) {
4033
+ doStrokeType(this);
4034
+ if (useStroke)
4035
+ this.__.__useStroke = true;
4036
+ }
4000
4037
  }
4001
4038
  }));
4002
4039
  }
@@ -4134,15 +4171,7 @@ function defineDataProcessor(target, key, defaultValue) {
4134
4171
  const data = target.__DataProcessor.prototype;
4135
4172
  const computedKey = '_' + key;
4136
4173
  const setMethodName = getSetMethodName(key);
4137
- const property = {
4138
- get() {
4139
- const v = this[computedKey];
4140
- return v === undefined ? defaultValue : v;
4141
- },
4142
- set(value) {
4143
- this[computedKey] = value;
4144
- }
4145
- };
4174
+ const property = createDescriptor(key, defaultValue);
4146
4175
  if (defaultValue === undefined) {
4147
4176
  property.get = function () { return this[computedKey]; };
4148
4177
  }
@@ -4257,7 +4286,7 @@ function registerUIEvent() {
4257
4286
  };
4258
4287
  }
4259
4288
 
4260
- const { copy: copy$a, toInnerPoint: toInnerPoint$1, toOuterPoint: toOuterPoint$1, scaleOfOuter: scaleOfOuter$2, rotateOfOuter: rotateOfOuter$2, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
4289
+ const { copy: copy$a, toInnerPoint: toInnerPoint$1, toOuterPoint: toOuterPoint$1, scaleOfOuter: scaleOfOuter$2, rotateOfOuter: rotateOfOuter$2, skewOfOuter, multiplyParent: multiplyParent$3, divideParent, getLayout } = MatrixHelper;
4261
4290
  const matrix$3 = {}, { round: round$3 } = Math;
4262
4291
  const LeafHelper = {
4263
4292
  updateAllMatrix(leaf, checkAutoLayout, waitAutoLayout) {
@@ -4329,6 +4358,14 @@ const LeafHelper = {
4329
4358
  }
4330
4359
  return true;
4331
4360
  },
4361
+ copyCanvasByWorld(leaf, currentCanvas, fromCanvas, fromWorld, blendMode, onlyResetTransform) {
4362
+ if (!fromWorld)
4363
+ fromWorld = leaf.__nowWorld;
4364
+ if (leaf.__worldFlipped || Platform.fullImageShadow)
4365
+ currentCanvas.copyWorldByReset(fromCanvas, fromWorld, leaf.__nowWorld, blendMode, onlyResetTransform);
4366
+ else
4367
+ currentCanvas.copyWorldToInner(fromCanvas, fromWorld, leaf.__layout.renderBounds, blendMode);
4368
+ },
4332
4369
  moveWorld(t, x, y = 0, isInnerPoint, transition) {
4333
4370
  const local = typeof x === 'object' ? Object.assign({}, x) : { x, y };
4334
4371
  isInnerPoint ? toOuterPoint$1(t.localTransform, local, local, true) : (t.parent && toInnerPoint$1(t.parent.worldTransform, local, local, true));
@@ -4388,14 +4425,14 @@ const LeafHelper = {
4388
4425
  },
4389
4426
  transformWorld(t, transform, resize, transition) {
4390
4427
  copy$a(matrix$3, t.worldTransform);
4391
- multiplyParent$2(matrix$3, transform);
4428
+ multiplyParent$3(matrix$3, transform);
4392
4429
  if (t.parent)
4393
4430
  divideParent(matrix$3, t.parent.worldTransform);
4394
4431
  L$4.setTransform(t, matrix$3, resize, transition);
4395
4432
  },
4396
4433
  transform(t, transform, resize, transition) {
4397
4434
  copy$a(matrix$3, t.localTransform);
4398
- multiplyParent$2(matrix$3, transform);
4435
+ multiplyParent$3(matrix$3, transform);
4399
4436
  L$4.setTransform(t, matrix$3, resize, transition);
4400
4437
  },
4401
4438
  setTransform(t, transform, resize, transition) {
@@ -5257,17 +5294,18 @@ const LeafDataProxy = {
5257
5294
  }
5258
5295
  };
5259
5296
 
5260
- const { setLayout, multiplyParent: multiplyParent$1, translateInner, defaultWorld } = MatrixHelper;
5297
+ const { setLayout, multiplyParent: multiplyParent$2, translateInner, defaultWorld } = MatrixHelper;
5261
5298
  const { toPoint: toPoint$4, tempPoint: tempPoint$1 } = AroundHelper;
5262
5299
  const LeafMatrix = {
5263
5300
  __updateWorldMatrix() {
5264
- multiplyParent$1(this.__local || this.__layout, this.parent ? this.parent.__world : defaultWorld, this.__world, !!this.__layout.affectScaleOrRotation, this.__, this.parent && this.parent.__);
5301
+ const { parent, __layout } = this;
5302
+ multiplyParent$2(this.__local || __layout, parent ? parent.__world : defaultWorld, this.__world, !!__layout.affectScaleOrRotation, this.__, parent && (parent.scrollY || parent.scrollX) && parent.__);
5265
5303
  },
5266
5304
  __updateLocalMatrix() {
5267
5305
  if (this.__local) {
5268
5306
  const layout = this.__layout, local = this.__local, data = this.__;
5269
5307
  if (layout.affectScaleOrRotation) {
5270
- if ((layout.scaleChanged && (layout.resized = 'scale')) || layout.rotationChanged) {
5308
+ if ((layout.scaleChanged && (layout.resized || (layout.resized = 'scale'))) || layout.rotationChanged) {
5271
5309
  setLayout(local, data, null, null, layout.affectRotation);
5272
5310
  layout.scaleChanged = layout.rotationChanged = undefined;
5273
5311
  }
@@ -5422,6 +5460,8 @@ const LeafBounds = {
5422
5460
 
5423
5461
  const LeafRender = {
5424
5462
  __render(canvas, options) {
5463
+ if (options.shape)
5464
+ return this.__renderShape(canvas, options);
5425
5465
  if (this.__worldOpacity) {
5426
5466
  const data = this.__;
5427
5467
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
@@ -5431,12 +5471,7 @@ const LeafRender = {
5431
5471
  return this.__renderEraser(canvas, options);
5432
5472
  const tempCanvas = canvas.getSameCanvas(true, true);
5433
5473
  this.__draw(tempCanvas, options, canvas);
5434
- if (this.__worldFlipped) {
5435
- canvas.copyWorldByReset(tempCanvas, this.__nowWorld, null, data.__blendMode, true);
5436
- }
5437
- else {
5438
- canvas.copyWorldToInner(tempCanvas, this.__nowWorld, this.__layout.renderBounds, data.__blendMode);
5439
- }
5474
+ LeafHelper.copyCanvasByWorld(this, canvas, tempCanvas, this.__nowWorld, data.__blendMode, true);
5440
5475
  tempCanvas.recycle(this.__nowWorld);
5441
5476
  }
5442
5477
  else {
@@ -5446,6 +5481,12 @@ const LeafRender = {
5446
5481
  Debug.drawBounds(this, canvas, options);
5447
5482
  }
5448
5483
  },
5484
+ __renderShape(canvas, options) {
5485
+ if (this.__worldOpacity) {
5486
+ canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
5487
+ this.__drawShape(canvas, options);
5488
+ }
5489
+ },
5449
5490
  __clip(canvas, options) {
5450
5491
  if (this.__worldOpacity) {
5451
5492
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
@@ -5478,7 +5519,7 @@ const BranchRender = {
5478
5519
  options.dimOpacity = data.dim === true ? 0.2 : data.dim;
5479
5520
  else if (data.dimskip)
5480
5521
  options.dimOpacity && (options.dimOpacity = 0);
5481
- if (data.__single) {
5522
+ if (data.__single && !this.isBranchLeaf) {
5482
5523
  if (data.eraser === 'path')
5483
5524
  return this.__renderEraser(canvas, options);
5484
5525
  const tempCanvas = canvas.getSameCanvas(false, true);
@@ -5500,9 +5541,7 @@ const BranchRender = {
5500
5541
  else {
5501
5542
  const { children } = this;
5502
5543
  for (let i = 0, len = children.length; i < len; i++) {
5503
- if (excludeRenderBounds$1(children[i], options))
5504
- continue;
5505
- children[i].__render(canvas, options);
5544
+ excludeRenderBounds$1(children[i], options) || children[i].__render(canvas, options);
5506
5545
  }
5507
5546
  }
5508
5547
  },
@@ -5510,16 +5549,15 @@ const BranchRender = {
5510
5549
  if (this.__worldOpacity) {
5511
5550
  const { children } = this;
5512
5551
  for (let i = 0, len = children.length; i < len; i++) {
5513
- if (excludeRenderBounds$1(children[i], options))
5514
- continue;
5515
- children[i].__clip(canvas, options);
5552
+ excludeRenderBounds$1(children[i], options) || children[i].__clip(canvas, options);
5516
5553
  }
5517
5554
  }
5518
5555
  }
5519
5556
  };
5520
5557
 
5558
+ const tempScaleData$1 = {};
5521
5559
  const { LEAF, create } = IncrementId;
5522
- const { toInnerPoint, toOuterPoint, multiplyParent } = MatrixHelper;
5560
+ const { toInnerPoint, toOuterPoint, multiplyParent: multiplyParent$1 } = MatrixHelper;
5523
5561
  const { toOuterOf } = BoundsHelper;
5524
5562
  const { copy: copy$7, move: move$5 } = PointHelper;
5525
5563
  const { moveLocal, zoomOfLocal, rotateOfLocal, skewOfLocal, moveWorld, zoomOfWorld, rotateOfWorld, skewOfWorld, transform, transformWorld, setTransform, getFlipTransform, getLocalOrigin, getRelativeWorld, drop } = LeafHelper;
@@ -5701,7 +5739,7 @@ let Leaf = class Leaf {
5701
5739
  if (!this.__cameraWorld)
5702
5740
  this.__cameraWorld = {};
5703
5741
  const cameraWorld = this.__cameraWorld, world = this.__world;
5704
- multiplyParent(world, options.matrix, cameraWorld, undefined, world);
5742
+ multiplyParent$1(world, options.matrix, cameraWorld, undefined, world);
5705
5743
  toOuterOf(this.__layout.renderBounds, cameraWorld, cameraWorld);
5706
5744
  cameraWorld.half !== world.half && (cameraWorld.half = world.half);
5707
5745
  return cameraWorld;
@@ -5710,6 +5748,22 @@ let Leaf = class Leaf {
5710
5748
  return this.__world;
5711
5749
  }
5712
5750
  }
5751
+ getClampRenderScale() {
5752
+ let { scaleX } = this.__nowWorld || this.__world;
5753
+ if (scaleX < 0)
5754
+ scaleX = -scaleX;
5755
+ return scaleX > 1 ? scaleX : 1;
5756
+ }
5757
+ getRenderScaleData(abs, scaleFixed) {
5758
+ const { scaleX, scaleY } = ImageManager.patternLocked ? this.__world : this.__nowWorld;
5759
+ if (scaleFixed)
5760
+ tempScaleData$1.scaleX = tempScaleData$1.scaleY = 1;
5761
+ else if (abs)
5762
+ tempScaleData$1.scaleX = scaleX < 0 ? -scaleX : scaleX, tempScaleData$1.scaleY = scaleY < 0 ? -scaleY : scaleY;
5763
+ else
5764
+ tempScaleData$1.scaleX = scaleX, tempScaleData$1.scaleY = scaleY;
5765
+ return tempScaleData$1;
5766
+ }
5713
5767
  getTransform(relative) {
5714
5768
  return this.__layout.getTransform(relative || 'local');
5715
5769
  }
@@ -5865,7 +5919,8 @@ let Leaf = class Leaf {
5865
5919
  __drawFast(_canvas, _options) { }
5866
5920
  __draw(_canvas, _options, _originCanvas) { }
5867
5921
  __clip(_canvas, _options) { }
5868
- __renderShape(_canvas, _options, _ignoreFill, _ignoreStroke) { }
5922
+ __renderShape(_canvas, _options) { }
5923
+ __drawShape(_canvas, _options) { }
5869
5924
  __updateWorldOpacity() { }
5870
5925
  __updateChange() { }
5871
5926
  __drawPath(_canvas) { }
@@ -6233,7 +6288,7 @@ class LeafLevelList {
6233
6288
  }
6234
6289
  }
6235
6290
 
6236
- const version = "1.6.7";
6291
+ const version = "1.8.0";
6237
6292
 
6238
6293
  class LeaferCanvas extends LeaferCanvasBase {
6239
6294
  get allowBackgroundColor() { return true; }
@@ -7081,6 +7136,11 @@ function zoomLayerType() {
7081
7136
  });
7082
7137
  };
7083
7138
  }
7139
+ function createAttr(defaultValue) {
7140
+ return (target, key) => {
7141
+ defineKey(target, key, createDescriptor(key, defaultValue));
7142
+ };
7143
+ }
7084
7144
 
7085
7145
  function hasTransparent$3(color) {
7086
7146
  if (!color || color.length === 7 || color.length === 4)
@@ -7138,26 +7198,9 @@ const emptyPaint = {};
7138
7198
  const debug$5 = Debug.get('UIData');
7139
7199
  class UIData extends LeafData {
7140
7200
  get scale() { const { scaleX, scaleY } = this; return scaleX !== scaleY ? { x: scaleX, y: scaleY } : scaleX; }
7141
- get __strokeWidth() {
7142
- const { strokeWidth, strokeWidthFixed } = this;
7143
- if (strokeWidthFixed) {
7144
- const ui = this.__leaf;
7145
- let { scaleX } = ui.__nowWorld || ui.__world;
7146
- if (scaleX < 0)
7147
- scaleX = -scaleX;
7148
- return scaleX > 1 ? strokeWidth / scaleX : strokeWidth;
7149
- }
7150
- else
7151
- return strokeWidth;
7152
- }
7153
- get __hasStroke() { return this.stroke && this.strokeWidth; }
7154
- get __hasHalf() { const t = this; return (t.stroke && t.strokeAlign === 'center' && t.strokeWidth % 2) || undefined; }
7155
- get __hasMultiPaint() {
7156
- const t = this;
7157
- if ((t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect)
7158
- return true;
7159
- return t.fill && this.__hasStroke;
7160
- }
7201
+ get __strokeWidth() { return this.__getRealStrokeWidth(); }
7202
+ get __maxStrokeWidth() { const t = this; return t.__hasMultiStrokeStyle ? Math.max(t.__hasMultiStrokeStyle, t.strokeWidth) : t.strokeWidth; }
7203
+ get __hasMultiPaint() { const t = this; return (t.fill && this.__useStroke) || (t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect; }
7161
7204
  get __clipAfterFill() { const t = this; return (t.cornerRadius || t.innerShadow || t.__pathInputed); }
7162
7205
  get __hasSurface() { const t = this; return (t.fill || t.stroke); }
7163
7206
  get __autoWidth() { return !this._width; }
@@ -7239,6 +7282,21 @@ class UIData extends LeafData {
7239
7282
  Paint.compute('stroke', this.__leaf);
7240
7283
  this.__needComputePaint = undefined;
7241
7284
  }
7285
+ __getRealStrokeWidth(childStyle) {
7286
+ let { strokeWidth, strokeWidthFixed } = this;
7287
+ if (childStyle) {
7288
+ if (childStyle.strokeWidth)
7289
+ strokeWidth = childStyle.strokeWidth;
7290
+ if (childStyle.strokeWidthFixed !== undefined)
7291
+ strokeWidthFixed = childStyle.strokeWidthFixed;
7292
+ }
7293
+ if (strokeWidthFixed) {
7294
+ const scale = this.__leaf.getClampRenderScale();
7295
+ return scale > 1 ? strokeWidth / scale : strokeWidth;
7296
+ }
7297
+ else
7298
+ return strokeWidth;
7299
+ }
7242
7300
  __setPaint(attrName, value) {
7243
7301
  this.__setInput(attrName, value);
7244
7302
  const layout = this.__leaf.__layout;
@@ -7263,6 +7321,7 @@ class UIData extends LeafData {
7263
7321
  }
7264
7322
  else {
7265
7323
  stintSet$2(this, '__isAlphaPixelStroke', undefined);
7324
+ stintSet$2(this, '__hasMultiStrokeStyle', undefined);
7266
7325
  this._stroke = this.__isStrokes = undefined;
7267
7326
  }
7268
7327
  }
@@ -7284,8 +7343,8 @@ class GroupData extends UIData {
7284
7343
 
7285
7344
  class BoxData extends GroupData {
7286
7345
  get __boxStroke() { return !this.__pathInputed; }
7287
- get __drawAfterFill() { const t = this; return (t.overflow === 'hide' && (t.__clipAfterFill || t.innerShadow) && t.__leaf.children.length); }
7288
- get __clipAfterFill() { return this.__leaf.isOverflow || super.__clipAfterFill; }
7346
+ get __drawAfterFill() { const t = this; return t.__single || t.__clipAfterFill; }
7347
+ get __clipAfterFill() { const t = this; return t.overflow === 'hide' && t.__leaf.children.length && (t.__leaf.isOverflow || super.__clipAfterFill); }
7289
7348
  }
7290
7349
 
7291
7350
  class LeaferData extends GroupData {
@@ -7405,7 +7464,7 @@ class CanvasData extends RectData {
7405
7464
  const UIBounds = {
7406
7465
  __updateStrokeSpread() {
7407
7466
  let width = 0, boxWidth = 0;
7408
- const data = this.__, { strokeAlign, strokeWidth } = data, box = this.__box;
7467
+ const data = this.__, { strokeAlign, __maxStrokeWidth: strokeWidth } = data, box = this.__box;
7409
7468
  if ((data.stroke || data.hitStroke === 'all') && strokeWidth && strokeAlign !== 'inside') {
7410
7469
  boxWidth = width = strokeAlign === 'center' ? strokeWidth / 2 : strokeWidth;
7411
7470
  if (!data.__boxStroke) {
@@ -7425,13 +7484,15 @@ const UIBounds = {
7425
7484
  },
7426
7485
  __updateRenderSpread() {
7427
7486
  let width = 0;
7428
- const { shadow, innerShadow, blur, backgroundBlur, filter } = this.__;
7487
+ const { shadow, innerShadow, blur, backgroundBlur, filter, renderSpread } = this.__;
7429
7488
  if (shadow)
7430
7489
  shadow.forEach(item => width = Math.max(width, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread > 0 ? item.spread : 0) + item.blur * 1.5));
7431
7490
  if (blur)
7432
7491
  width = Math.max(width, blur);
7433
7492
  if (filter)
7434
7493
  width += Filter.getSpread(filter);
7494
+ if (renderSpread)
7495
+ width += renderSpread;
7435
7496
  let shapeWidth = width = Math.ceil(width);
7436
7497
  if (innerShadow)
7437
7498
  innerShadow.forEach(item => shapeWidth = Math.max(shapeWidth, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread < 0 ? -item.spread : 0) + item.blur * 1.5));
@@ -7447,15 +7508,18 @@ const { stintSet: stintSet$1 } = DataHelper;
7447
7508
  const UIRender = {
7448
7509
  __updateChange() {
7449
7510
  const data = this.__;
7511
+ if (data.__useStroke) {
7512
+ const useStroke = data.__useStroke = !!(data.stroke && data.strokeWidth);
7513
+ stintSet$1(this.__world, 'half', useStroke && data.strokeAlign === 'center' && data.strokeWidth % 2);
7514
+ stintSet$1(data, '__fillAfterStroke', useStroke && data.strokeAlign === 'outside' && data.fill && !data.__isTransparentFill);
7515
+ }
7450
7516
  if (data.__useEffect) {
7451
7517
  const { shadow, fill, stroke } = data, otherEffect = data.innerShadow || data.blur || data.backgroundBlur || data.filter;
7452
- 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')));
7518
+ stintSet$1(data, '__isFastShadow', shadow && !otherEffect && shadow.length < 2 && !shadow[0].spread && fill && !data.__isTransparentFill && !(fill instanceof Array && fill.length > 1) && (this.useFastShadow || !stroke || (stroke && data.strokeAlign === 'inside')));
7453
7519
  data.__useEffect = !!(shadow || otherEffect);
7454
7520
  }
7455
- stintSet$1(this.__world, 'half', data.__hasHalf);
7456
- stintSet$1(data, '__fillAfterStroke', data.stroke && data.strokeAlign === 'outside' && data.fill && !data.__isTransparentFill);
7457
7521
  data.__checkSingle();
7458
- stintSet$1(data, '__complex', data.__isFills || data.__isStrokes || data.cornerRadius || data.__useEffect);
7522
+ stintSet$1(data, '__complex', (data.__isFills || data.__isStrokes || data.cornerRadius || data.__useEffect));
7459
7523
  },
7460
7524
  __drawFast(canvas, options) {
7461
7525
  drawFast(this, canvas, options);
@@ -7513,18 +7577,15 @@ const UIRender = {
7513
7577
  this.__drawFast(canvas, options);
7514
7578
  }
7515
7579
  },
7516
- __renderShape(canvas, options, ignoreFill, ignoreStroke) {
7517
- if (this.__worldOpacity) {
7518
- canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
7519
- const { fill, stroke } = this.__;
7520
- this.__drawRenderPath(canvas);
7521
- if (fill && !ignoreFill)
7522
- this.__.__isAlphaPixelFill ? Paint.fills(fill, this, canvas) : Paint.fill('#000000', this, canvas);
7523
- if (this.__.__isCanvas)
7524
- this.__drawAfterFill(canvas, options);
7525
- if (stroke && !ignoreStroke)
7526
- this.__.__isAlphaPixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
7527
- }
7580
+ __drawShape(canvas, options) {
7581
+ this.__drawRenderPath(canvas);
7582
+ const data = this.__, { fill, stroke } = data;
7583
+ if (fill && !options.ignoreFill)
7584
+ data.__isAlphaPixelFill ? Paint.fills(fill, this, canvas) : Paint.fill('#000000', this, canvas);
7585
+ if (data.__isCanvas)
7586
+ this.__drawAfterFill(canvas, options);
7587
+ if (stroke && !options.ignoreStroke)
7588
+ data.__isAlphaPixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
7528
7589
  },
7529
7590
  __drawAfterFill(canvas, options) {
7530
7591
  if (this.__.__clipAfterFill) {
@@ -7561,17 +7622,17 @@ const RectRender = {
7561
7622
  if (__drawAfterFill)
7562
7623
  this.__drawAfterFill(canvas, options);
7563
7624
  if (stroke) {
7564
- const { strokeAlign, __strokeWidth } = this.__;
7565
- if (!__strokeWidth)
7625
+ const { strokeAlign, __strokeWidth: strokeWidth } = this.__;
7626
+ if (!strokeWidth)
7566
7627
  return;
7567
- canvas.setStroke(stroke, __strokeWidth, this.__);
7568
- const half = __strokeWidth / 2;
7628
+ canvas.setStroke(stroke, strokeWidth, this.__);
7629
+ const half = strokeWidth / 2;
7569
7630
  switch (strokeAlign) {
7570
7631
  case 'center':
7571
7632
  canvas.strokeRect(0, 0, width, height);
7572
7633
  break;
7573
7634
  case 'inside':
7574
- width -= __strokeWidth, height -= __strokeWidth;
7635
+ width -= strokeWidth, height -= strokeWidth;
7575
7636
  if (width < 0 || height < 0) {
7576
7637
  canvas.save();
7577
7638
  this.__clip(canvas, options);
@@ -7582,7 +7643,7 @@ const RectRender = {
7582
7643
  canvas.strokeRect(x + half, y + half, width, height);
7583
7644
  break;
7584
7645
  case 'outside':
7585
- canvas.strokeRect(x - half, y - half, width + __strokeWidth, height + __strokeWidth);
7646
+ canvas.strokeRect(x - half, y - half, width + strokeWidth, height + strokeWidth);
7586
7647
  break;
7587
7648
  }
7588
7649
  }
@@ -7595,6 +7656,8 @@ let UI = UI_1 = class UI extends Leaf {
7595
7656
  get isFrame() { return false; }
7596
7657
  set scale(value) { MathHelper.assignScale(this, value); }
7597
7658
  get scale() { return this.__.scale; }
7659
+ get isAutoWidth() { const t = this.__; return t.__autoWidth || t.autoWidth; }
7660
+ get isAutoHeight() { const t = this.__; return t.__autoHeight || t.autoHeight; }
7598
7661
  get pen() {
7599
7662
  const { path } = this.__;
7600
7663
  pen.set(this.path = path || []);
@@ -7649,12 +7712,14 @@ let UI = UI_1 = class UI extends Leaf {
7649
7712
  }
7650
7713
  }
7651
7714
  __updateRenderPath() {
7652
- if (this.__.path) {
7653
- const data = this.__;
7715
+ const data = this.__;
7716
+ if (data.path) {
7654
7717
  data.__pathForRender = data.cornerRadius ? PathCorner.smooth(data.path, data.cornerRadius, data.cornerSmoothing) : data.path;
7655
7718
  if (data.__useArrow)
7656
7719
  PathArrow.addArrows(this, !data.cornerRadius);
7657
7720
  }
7721
+ else
7722
+ data.__pathForRender && (data.__pathForRender = undefined);
7658
7723
  }
7659
7724
  __drawRenderPath(canvas) {
7660
7725
  canvas.beginPath();
@@ -7807,6 +7872,9 @@ __decorate([
7807
7872
  __decorate([
7808
7873
  naturalBoundsType(1)
7809
7874
  ], UI.prototype, "pixelRatio", void 0);
7875
+ __decorate([
7876
+ affectRenderBoundsType(0)
7877
+ ], UI.prototype, "renderSpread", void 0);
7810
7878
  __decorate([
7811
7879
  pathInputType()
7812
7880
  ], UI.prototype, "path", void 0);
@@ -7865,13 +7933,13 @@ __decorate([
7865
7933
  surfaceType()
7866
7934
  ], UI.prototype, "fill", void 0);
7867
7935
  __decorate([
7868
- strokeType()
7936
+ strokeType(undefined, true)
7869
7937
  ], UI.prototype, "stroke", void 0);
7870
7938
  __decorate([
7871
7939
  strokeType('inside')
7872
7940
  ], UI.prototype, "strokeAlign", void 0);
7873
7941
  __decorate([
7874
- strokeType(1)
7942
+ strokeType(1, true)
7875
7943
  ], UI.prototype, "strokeWidth", void 0);
7876
7944
  __decorate([
7877
7945
  strokeType(false)
@@ -7963,7 +8031,8 @@ let Group = class Group extends UI {
7963
8031
  }
7964
8032
  toJSON(options) {
7965
8033
  const data = super.toJSON(options);
7966
- data.children = this.children.map(child => child.toJSON(options));
8034
+ if (!this.childlessJSON)
8035
+ data.children = this.children.map(child => child.toJSON(options));
7967
8036
  return data;
7968
8037
  }
7969
8038
  pick(_hitPoint, _options) { return undefined; }
@@ -8298,7 +8367,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
8298
8367
  list.push(item);
8299
8368
  this.requestRender();
8300
8369
  }
8301
- zoom(_zoomType, _padding, _fixedScale, _transition) {
8370
+ zoom(_zoomType, _optionsOrPadding, _scroll, _transition) {
8302
8371
  return Plugin.need('view');
8303
8372
  }
8304
8373
  getValidMove(moveX, moveY) { return { x: moveX, y: moveY }; }
@@ -8343,7 +8412,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
8343
8412
  Leafer_1.list.remove(this);
8344
8413
  try {
8345
8414
  this.stop();
8346
- this.emitEvent(new LeaferEvent(LeaferEvent.END, this));
8415
+ this.emitLeafer(LeaferEvent.END);
8347
8416
  this.__removeListenEvents();
8348
8417
  this.__controllers.forEach(item => !(this.parent && item === this.interaction) && item.destroy());
8349
8418
  this.__controllers.length = 0;
@@ -8410,8 +8479,8 @@ let Box = class Box extends Group {
8410
8479
  __updateRenderSpread() { return this.__updateRectRenderSpread() || -1; }
8411
8480
  __updateRectBoxBounds() { }
8412
8481
  __updateBoxBounds(_secondLayout) {
8413
- const data = this.__;
8414
8482
  if (this.children.length && !this.pathInputed) {
8483
+ const data = this.__;
8415
8484
  if (data.__autoSide) {
8416
8485
  if (data.__hasSurface)
8417
8486
  this.__extraUpdate();
@@ -8438,20 +8507,26 @@ let Box = class Box extends Group {
8438
8507
  __updateStrokeBounds() { }
8439
8508
  __updateRenderBounds() {
8440
8509
  let isOverflow;
8441
- const { renderBounds } = this.__layout;
8442
8510
  if (this.children.length) {
8511
+ const data = this.__, { renderBounds, boxBounds } = this.__layout;
8443
8512
  super.__updateRenderBounds();
8444
8513
  copy$6(childrenRenderBounds, renderBounds);
8445
8514
  this.__updateRectRenderBounds();
8446
- isOverflow = !includes$1(renderBounds, childrenRenderBounds);
8447
- if (isOverflow && this.__.overflow !== 'hide')
8515
+ if (data.scrollY || data.scrollX) {
8516
+ childrenRenderBounds.x += data.scrollX;
8517
+ childrenRenderBounds.y += data.scrollY;
8518
+ }
8519
+ isOverflow = !includes$1(boxBounds, childrenRenderBounds);
8520
+ if (isOverflow && data.overflow !== 'hide')
8448
8521
  add(renderBounds, childrenRenderBounds);
8449
8522
  }
8450
8523
  else
8451
8524
  this.__updateRectRenderBounds();
8452
8525
  DataHelper.stintSet(this, 'isOverflow', isOverflow);
8526
+ this.__updateScrollBar();
8453
8527
  }
8454
8528
  __updateRectRenderBounds() { }
8529
+ __updateScrollBar() { }
8455
8530
  __updateRectChange() { }
8456
8531
  __updateChange() {
8457
8532
  super.__updateChange();
@@ -8468,10 +8543,12 @@ let Box = class Box extends Group {
8468
8543
  if (this.children.length)
8469
8544
  this.__renderGroup(canvas, options);
8470
8545
  }
8546
+ if (this.scrollBar)
8547
+ this.scrollBar.__render(canvas, options);
8471
8548
  }
8472
8549
  __drawContent(canvas, options) {
8473
8550
  this.__renderGroup(canvas, options);
8474
- if (this.__.__hasStroke) {
8551
+ if (this.__.__useStroke || this.__.__useEffect) {
8475
8552
  canvas.setWorld(this.__nowWorld);
8476
8553
  this.__drawRenderPath(canvas);
8477
8554
  }
@@ -8691,8 +8768,8 @@ let Polygon = class Polygon extends UI {
8691
8768
  for (let i = 1; i < sides; i++) {
8692
8769
  lineTo$1(path, rx + rx * sin$2((i * 2 * PI$2) / sides), ry - ry * cos$2((i * 2 * PI$2) / sides));
8693
8770
  }
8771
+ closePath$1(path);
8694
8772
  }
8695
- closePath$1(path);
8696
8773
  }
8697
8774
  __updateRenderPath() { }
8698
8775
  __updateBoxBounds() { }
@@ -8930,6 +9007,11 @@ let Text = class Text extends UI {
8930
9007
  return;
8931
9008
  super.__draw(canvas, options, originCanvas);
8932
9009
  }
9010
+ __drawShape(canvas, options) {
9011
+ if (options.shape)
9012
+ this.__box && this.__box.__drawShape(canvas, options);
9013
+ super.__drawShape(canvas, options);
9014
+ }
8933
9015
  destroy() {
8934
9016
  if (this.boxStyle)
8935
9017
  this.boxStyle = null;
@@ -9751,6 +9833,7 @@ const config$1 = {
9751
9833
  delta: { x: 80 / 4, y: 8.0 },
9752
9834
  },
9753
9835
  pointer: {
9836
+ type: 'pointer',
9754
9837
  snap: true,
9755
9838
  hitRadius: 5,
9756
9839
  tapTime: 120,
@@ -10268,18 +10351,20 @@ leaf$1.__hitWorld = function (point) {
10268
10351
  }
10269
10352
  return this.__hit(inner);
10270
10353
  };
10271
- leaf$1.__hitFill = function (inner) { var _a; return (_a = this.__hitCanvas) === null || _a === void 0 ? void 0 : _a.hitFill(inner, this.__.windingRule); };
10272
- leaf$1.__hitStroke = function (inner, strokeWidth) { var _a; return (_a = this.__hitCanvas) === null || _a === void 0 ? void 0 : _a.hitStroke(inner, strokeWidth); };
10273
- leaf$1.__hitPixel = function (inner) { var _a; return (_a = this.__hitCanvas) === null || _a === void 0 ? void 0 : _a.hitPixel(inner, this.__layout.renderBounds, this.__hitCanvas.hitScale); };
10274
- leaf$1.__drawHitPath = function (canvas) { if (canvas)
10275
- this.__drawRenderPath(canvas); };
10354
+ leaf$1.__hitFill = function (inner) { const h = this.__hitCanvas; return h && h.hitFill(inner, this.__.windingRule); };
10355
+ leaf$1.__hitStroke = function (inner, strokeWidth) { const h = this.__hitCanvas; return h && h.hitStroke(inner, strokeWidth); };
10356
+ leaf$1.__hitPixel = function (inner) { const h = this.__hitCanvas; return h && h.hitPixel(inner, this.__layout.renderBounds, h.hitScale); };
10357
+ leaf$1.__drawHitPath = function (canvas) { canvas && this.__drawRenderPath(canvas); };
10276
10358
 
10277
10359
  const matrix$2 = new Matrix();
10278
10360
  const ui$5 = UI.prototype;
10279
10361
  ui$5.__updateHitCanvas = function () {
10280
10362
  if (this.__box)
10281
10363
  this.__box.__updateHitCanvas();
10282
- const data = this.__, { hitCanvasManager } = this.leafer || this.parent.leafer;
10364
+ const leafer = this.leafer || (this.parent && this.parent.leafer);
10365
+ if (!leafer)
10366
+ return;
10367
+ const data = this.__, { hitCanvasManager } = leafer;
10283
10368
  const isHitPixelFill = (data.__isAlphaPixelFill || data.__isCanvas) && data.hitFill === 'pixel';
10284
10369
  const isHitPixelStroke = data.__isAlphaPixelStroke && data.hitStroke === 'pixel';
10285
10370
  const isHitPixel = isHitPixelFill || isHitPixelStroke;
@@ -10294,7 +10379,7 @@ ui$5.__updateHitCanvas = function () {
10294
10379
  h.resize({ width, height, pixelRatio: 1 });
10295
10380
  h.clear();
10296
10381
  ImageManager.patternLocked = true;
10297
- this.__renderShape(h, { matrix: matrix$2.setWith(this.__world).scaleWith(1 / scale).invertWith().translate(-x, -y) }, !isHitPixelFill, !isHitPixelStroke);
10382
+ this.__renderShape(h, { matrix: matrix$2.setWith(this.__world).scaleWith(1 / scale).invertWith().translate(-x, -y), ignoreFill: !isHitPixelFill, ignoreStroke: !isHitPixelStroke });
10298
10383
  ImageManager.patternLocked = false;
10299
10384
  h.resetTransform();
10300
10385
  data.__isHitPixel = true;
@@ -10315,7 +10400,7 @@ ui$5.__hit = function (inner) {
10315
10400
  const needHitFillPath = ((data.fill || data.__isCanvas) && (hitFill === 'path' || (hitFill === 'pixel' && !(data.__isAlphaPixelFill || data.__isCanvas)))) || hitFill === 'all';
10316
10401
  if (needHitFillPath && this.__hitFill(inner))
10317
10402
  return true;
10318
- const { hitStroke, __strokeWidth } = data;
10403
+ const { hitStroke, __maxStrokeWidth: strokeWidth } = data;
10319
10404
  const needHitStrokePath = (data.stroke && (hitStroke === 'path' || (hitStroke === 'pixel' && !data.__isAlphaPixelStroke))) || hitStroke === 'all';
10320
10405
  if (!needHitFillPath && !needHitStrokePath)
10321
10406
  return false;
@@ -10324,16 +10409,16 @@ ui$5.__hit = function (inner) {
10324
10409
  if (needHitStrokePath) {
10325
10410
  switch (data.strokeAlign) {
10326
10411
  case 'inside':
10327
- hitWidth += __strokeWidth * 2;
10412
+ hitWidth += strokeWidth * 2;
10328
10413
  if (!needHitFillPath && this.__hitFill(inner) && this.__hitStroke(inner, hitWidth))
10329
10414
  return true;
10330
10415
  hitWidth = radiusWidth;
10331
10416
  break;
10332
10417
  case 'center':
10333
- hitWidth += __strokeWidth;
10418
+ hitWidth += strokeWidth;
10334
10419
  break;
10335
10420
  case 'outside':
10336
- hitWidth += __strokeWidth * 2;
10421
+ hitWidth += strokeWidth * 2;
10337
10422
  if (!needHitFillPath) {
10338
10423
  if (!this.__hitFill(inner) && this.__hitStroke(inner, hitWidth))
10339
10424
  return true;
@@ -10433,9 +10518,14 @@ function fills(fills, ui, canvas) {
10433
10518
  }
10434
10519
  }
10435
10520
  canvas.fillStyle = item.style;
10436
- if (item.transform) {
10521
+ if (item.transform || item.scaleFixed) {
10437
10522
  canvas.save();
10438
- canvas.transform(item.transform);
10523
+ if (item.transform)
10524
+ canvas.transform(item.transform);
10525
+ if (item.scaleFixed) {
10526
+ const { scaleX, scaleY } = ui.getRenderScaleData(true);
10527
+ canvas.scale(1 / scaleX, 1 / scaleY);
10528
+ }
10439
10529
  if (item.blendMode)
10440
10530
  canvas.blendMode = item.blendMode;
10441
10531
  fillPathOrText(ui, canvas);
@@ -10471,8 +10561,13 @@ function strokeText(stroke, ui, canvas) {
10471
10561
  }
10472
10562
  function drawCenter$1(stroke, strokeWidthScale, ui, canvas) {
10473
10563
  const data = ui.__;
10474
- canvas.setStroke(!data.__isStrokes && stroke, data.strokeWidth * strokeWidthScale, data);
10475
- data.__isStrokes ? drawStrokesStyle(stroke, true, ui, canvas) : drawTextStroke(ui, canvas);
10564
+ if (typeof stroke === 'object') {
10565
+ drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas);
10566
+ }
10567
+ else {
10568
+ canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
10569
+ drawTextStroke(ui, canvas);
10570
+ }
10476
10571
  }
10477
10572
  function drawAlign(stroke, align, ui, canvas) {
10478
10573
  const out = canvas.getSameCanvas(true, true);
@@ -10481,15 +10576,9 @@ function drawAlign(stroke, align, ui, canvas) {
10481
10576
  out.blendMode = align === 'outside' ? 'destination-out' : 'destination-in';
10482
10577
  fillText(ui, out);
10483
10578
  out.blendMode = 'normal';
10484
- copyWorld(canvas, out, ui);
10579
+ LeafHelper.copyCanvasByWorld(ui, canvas, out);
10485
10580
  out.recycle(ui.__nowWorld);
10486
10581
  }
10487
- function copyWorld(canvas, out, ui) {
10488
- if (ui.__worldFlipped || Platform.fullImageShadow)
10489
- canvas.copyWorldByReset(out, ui.__nowWorld);
10490
- else
10491
- canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds);
10492
- }
10493
10582
  function drawTextStroke(ui, canvas) {
10494
10583
  let row, data = ui.__.__textDrawData;
10495
10584
  const { rows, decorationY } = data;
@@ -10505,14 +10594,21 @@ function drawTextStroke(ui, canvas) {
10505
10594
  rows.forEach(row => decorationY.forEach(value => canvas.strokeRect(row.x, row.y + value, row.width, decorationHeight)));
10506
10595
  }
10507
10596
  }
10508
- function drawStrokesStyle(strokes, isText, ui, canvas) {
10597
+ function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas) {
10509
10598
  let item;
10599
+ const data = ui.__, { __hasMultiStrokeStyle } = data;
10600
+ __hasMultiStrokeStyle || canvas.setStroke(undefined, data.__strokeWidth * strokeWidthScale, data);
10510
10601
  for (let i = 0, len = strokes.length; i < len; i++) {
10511
10602
  item = strokes[i];
10512
10603
  if (item.image && PaintImage.checkImage(ui, canvas, item, false))
10513
10604
  continue;
10514
10605
  if (item.style) {
10515
- canvas.strokeStyle = item.style;
10606
+ if (__hasMultiStrokeStyle) {
10607
+ const { strokeStyle } = item;
10608
+ strokeStyle ? canvas.setStroke(item.style, data.__getRealStrokeWidth(strokeStyle) * strokeWidthScale, data, strokeStyle) : canvas.setStroke(item.style, data.__strokeWidth * strokeWidthScale, data);
10609
+ }
10610
+ else
10611
+ canvas.strokeStyle = item.style;
10516
10612
  if (item.blendMode) {
10517
10613
  canvas.saveBlendMode(item.blendMode);
10518
10614
  isText ? drawTextStroke(ui, canvas) : canvas.stroke();
@@ -10551,8 +10647,13 @@ function strokes(strokes, ui, canvas) {
10551
10647
  }
10552
10648
  function drawCenter(stroke, strokeWidthScale, ui, canvas) {
10553
10649
  const data = ui.__;
10554
- canvas.setStroke(!data.__isStrokes && stroke, data.__strokeWidth * strokeWidthScale, data);
10555
- data.__isStrokes ? drawStrokesStyle(stroke, false, ui, canvas) : canvas.stroke();
10650
+ if (typeof stroke === 'object') {
10651
+ drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas);
10652
+ }
10653
+ else {
10654
+ canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
10655
+ canvas.stroke();
10656
+ }
10556
10657
  if (data.__useArrow)
10557
10658
  Paint.strokeArrow(stroke, ui, canvas);
10558
10659
  }
@@ -10574,7 +10675,7 @@ function drawOutside(stroke, ui, canvas) {
10574
10675
  drawCenter(stroke, 2, ui, out);
10575
10676
  out.clipUI(data);
10576
10677
  out.clearWorld(renderBounds);
10577
- copyWorld(canvas, out, ui);
10678
+ LeafHelper.copyCanvasByWorld(ui, canvas, out);
10578
10679
  out.recycle(ui.__nowWorld);
10579
10680
  }
10580
10681
  }
@@ -10629,8 +10730,16 @@ function compute(attrName, ui) {
10629
10730
  if (!(paints instanceof Array))
10630
10731
  paints = [paints];
10631
10732
  recycleMap = PaintImage.recycleImage(attrName, data);
10733
+ let maxChildStrokeWidth;
10632
10734
  for (let i = 0, len = paints.length, item; i < len; i++) {
10633
- (item = getLeafPaint(attrName, paints[i], ui)) && leafPaints.push(item);
10735
+ if (item = getLeafPaint(attrName, paints[i], ui)) {
10736
+ leafPaints.push(item);
10737
+ if (item.strokeStyle) {
10738
+ maxChildStrokeWidth || (maxChildStrokeWidth = 1);
10739
+ if (item.strokeStyle.strokeWidth)
10740
+ maxChildStrokeWidth = Math.max(maxChildStrokeWidth, item.strokeStyle.strokeWidth);
10741
+ }
10742
+ }
10634
10743
  }
10635
10744
  data['_' + attrName] = leafPaints.length ? leafPaints : undefined;
10636
10745
  if (leafPaints.length) {
@@ -10647,6 +10756,7 @@ function compute(attrName, ui) {
10647
10756
  else {
10648
10757
  stintSet(data, '__isAlphaPixelStroke', isAlphaPixel);
10649
10758
  stintSet(data, '__isTransparentStroke', isTransparent);
10759
+ stintSet(data, '__hasMultiStrokeStyle', maxChildStrokeWidth);
10650
10760
  }
10651
10761
  }
10652
10762
  function getLeafPaint(attrName, paint, ui) {
@@ -10678,6 +10788,11 @@ function getLeafPaint(attrName, paint, ui) {
10678
10788
  if (data) {
10679
10789
  if (typeof data.style === 'string' && hasTransparent$1(data.style))
10680
10790
  data.isTransparent = true;
10791
+ if (paint.style) {
10792
+ if (paint.style.strokeWidth === 0)
10793
+ return undefined;
10794
+ data.strokeStyle = paint.style;
10795
+ }
10681
10796
  if (paint.blendMode)
10682
10797
  data.blendMode = paint.blendMode;
10683
10798
  }
@@ -10697,8 +10812,8 @@ const PaintModule = {
10697
10812
  shape
10698
10813
  };
10699
10814
 
10700
- let origin$1 = {};
10701
- const { get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, scale: scaleHelper, rotate: rotate$2 } = MatrixHelper;
10815
+ let origin$1 = {}, tempMatrix = getMatrixData();
10816
+ const { get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, multiplyParent, scale: scaleHelper, rotate: rotate$2, skew: skewHelper } = MatrixHelper;
10702
10817
  function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
10703
10818
  const transform = get$3();
10704
10819
  translate$1(transform, box.x + x, box.y + y);
@@ -10707,13 +10822,19 @@ function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
10707
10822
  rotateOfOuter$1(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
10708
10823
  data.transform = transform;
10709
10824
  }
10710
- function clipMode(data, box, x, y, scaleX, scaleY, rotation) {
10825
+ function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipSize) {
10711
10826
  const transform = get$3();
10712
- translate$1(transform, box.x + x, box.y + y);
10713
- if (scaleX)
10714
- scaleHelper(transform, scaleX, scaleY);
10715
10827
  if (rotation)
10716
10828
  rotate$2(transform, rotation);
10829
+ if (skew)
10830
+ skewHelper(transform, skew.x, skew.y);
10831
+ if (scaleX)
10832
+ scaleHelper(transform, scaleX, scaleY);
10833
+ translate$1(transform, box.x + x, box.y + y);
10834
+ if (clipSize) {
10835
+ tempMatrix.a = box.width / clipSize.width, tempMatrix.d = box.height / clipSize.height;
10836
+ multiplyParent(transform, tempMatrix);
10837
+ }
10717
10838
  data.transform = transform;
10718
10839
  }
10719
10840
  function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align) {
@@ -10750,11 +10871,15 @@ const tempBox = new Bounds();
10750
10871
  const tempScaleData = {};
10751
10872
  const tempImage = {};
10752
10873
  function createData(leafPaint, image, paint, box) {
10753
- const { changeful, sync } = paint;
10874
+ const { changeful, sync, editing, scaleFixed } = paint;
10754
10875
  if (changeful)
10755
10876
  leafPaint.changeful = changeful;
10756
10877
  if (sync)
10757
10878
  leafPaint.sync = sync;
10879
+ if (editing)
10880
+ leafPaint.editing = editing;
10881
+ if (scaleFixed)
10882
+ leafPaint.scaleFixed = scaleFixed;
10758
10883
  leafPaint.data = getPatternData(paint, box, image);
10759
10884
  }
10760
10885
  function getPatternData(paint, box, image) {
@@ -10763,7 +10888,7 @@ function getPatternData(paint, box, image) {
10763
10888
  if (paint.mode === 'strench')
10764
10889
  paint.mode = 'stretch';
10765
10890
  let { width, height } = image;
10766
- const { opacity, mode, align, offset, scale, size, rotation, repeat, filters } = paint;
10891
+ const { opacity, mode, align, offset, scale, size, rotation, skew, clipSize, repeat, filters } = paint;
10767
10892
  const sameBox = box.width === width && box.height === height;
10768
10893
  const data = { mode };
10769
10894
  const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
@@ -10797,8 +10922,8 @@ function getPatternData(paint, box, image) {
10797
10922
  break;
10798
10923
  case 'normal':
10799
10924
  case 'clip':
10800
- if (tempImage.x || tempImage.y || scaleX || rotation)
10801
- clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
10925
+ if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew)
10926
+ clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, paint.clipSize);
10802
10927
  break;
10803
10928
  case 'repeat':
10804
10929
  if (!sameBox || scaleX || rotation)
@@ -10875,11 +11000,11 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
10875
11000
  }
10876
11001
  onLoadSuccess(ui, event);
10877
11002
  }
10878
- leafPaint.loadId = null;
11003
+ leafPaint.loadId = undefined;
10879
11004
  }, (error) => {
10880
11005
  ignoreRender(ui, false);
10881
11006
  onLoadError(ui, event, error);
10882
- leafPaint.loadId = null;
11007
+ leafPaint.loadId = undefined;
10883
11008
  });
10884
11009
  if (ui.placeholderColor) {
10885
11010
  if (!ui.placeholderDelay)
@@ -10935,16 +11060,16 @@ function ignoreRender(ui, value) {
10935
11060
  }
10936
11061
 
10937
11062
  const { get: get$1, scale: scale$2, copy: copy$4 } = MatrixHelper;
10938
- const { ceil: ceil$1, abs: abs$4 } = Math;
11063
+ const { ceil: ceil$1, abs: abs$3 } = Math;
10939
11064
  function createPattern(ui, paint, pixelRatio) {
10940
- let { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
11065
+ let { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
10941
11066
  const id = scaleX + '-' + scaleY + '-' + pixelRatio;
10942
11067
  if (paint.patternId !== id && !ui.destroyed) {
10943
- scaleX = abs$4(scaleX);
10944
- scaleY = abs$4(scaleY);
10945
11068
  const { image, data } = paint;
10946
11069
  let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, transform, repeat } = data;
10947
11070
  if (sx) {
11071
+ sx = abs$3(sx);
11072
+ sy = abs$3(sy);
10948
11073
  imageMatrix = get$1();
10949
11074
  copy$4(imageMatrix, transform);
10950
11075
  scale$2(imageMatrix, 1 / sx, 1 / sy);
@@ -10997,9 +11122,8 @@ function createPattern(ui, paint, pixelRatio) {
10997
11122
  }
10998
11123
  }
10999
11124
 
11000
- const { abs: abs$3 } = Math;
11001
11125
  function checkImage(ui, canvas, paint, allowDraw) {
11002
- const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
11126
+ const { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
11003
11127
  const { pixelRatio } = canvas, { data } = paint;
11004
11128
  if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
11005
11129
  return false;
@@ -11012,8 +11136,8 @@ function checkImage(ui, canvas, paint, allowDraw) {
11012
11136
  else {
11013
11137
  if (!(paint.changeful || ResizeEvent.isResizing(ui) || Export.running)) {
11014
11138
  let { width, height } = data;
11015
- width *= abs$3(scaleX) * pixelRatio;
11016
- height *= abs$3(scaleY) * pixelRatio;
11139
+ width *= scaleX * pixelRatio;
11140
+ height *= scaleY * pixelRatio;
11017
11141
  if (data.scaleX) {
11018
11142
  width *= data.scaleX;
11019
11143
  height *= data.scaleY;
@@ -11023,6 +11147,10 @@ function checkImage(ui, canvas, paint, allowDraw) {
11023
11147
  }
11024
11148
  }
11025
11149
  if (allowDraw) {
11150
+ if (ui.__.__isFastShadow) {
11151
+ canvas.fillStyle = paint.style || '#000';
11152
+ canvas.fill();
11153
+ }
11026
11154
  drawImage(ui, canvas, paint, data);
11027
11155
  return true;
11028
11156
  }
@@ -11211,10 +11339,7 @@ function shadow$1(ui, current, shape) {
11211
11339
  }
11212
11340
  worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, 'destination-out') : other.copyWorld(shape.canvas, shapeBounds, bounds, 'destination-out');
11213
11341
  }
11214
- if (ui.__worldFlipped)
11215
- current.copyWorldByReset(other, copyBounds, nowWorld, item.blendMode);
11216
- else
11217
- current.copyWorldToInner(other, copyBounds, __layout.renderBounds, item.blendMode);
11342
+ LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
11218
11343
  if (end && index < end)
11219
11344
  other.clearWorld(copyBounds, true);
11220
11345
  });
@@ -11273,10 +11398,7 @@ function innerShadow(ui, current, shape) {
11273
11398
  copyBounds = bounds;
11274
11399
  }
11275
11400
  other.fillWorld(copyBounds, ColorConvert.string(item.color), 'source-in');
11276
- if (ui.__worldFlipped)
11277
- current.copyWorldByReset(other, copyBounds, nowWorld, item.blendMode);
11278
- else
11279
- current.copyWorldToInner(other, copyBounds, __layout.renderBounds, item.blendMode);
11401
+ LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
11280
11402
  if (end && index < end)
11281
11403
  other.clearWorld(copyBounds, true);
11282
11404
  });
@@ -11332,12 +11454,11 @@ Group.prototype.__renderMask = function (canvas, options) {
11332
11454
  contentCanvas = getCanvas(canvas);
11333
11455
  child.__render(maskCanvas, options);
11334
11456
  }
11335
- if (!(mask === 'clipping' || mask === 'clipping-path'))
11336
- continue;
11337
- }
11338
- if (excludeRenderBounds(child, options))
11457
+ if (mask === 'clipping' || mask === 'clipping-path')
11458
+ excludeRenderBounds(child, options) || child.__render(canvas, options);
11339
11459
  continue;
11340
- child.__render(contentCanvas || canvas, options);
11460
+ }
11461
+ excludeRenderBounds(child, options) || child.__render(contentCanvas || canvas, options);
11341
11462
  }
11342
11463
  maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
11343
11464
  };
@@ -11938,41 +12059,10 @@ class EditorEvent extends Event {
11938
12059
  }
11939
12060
  EditorEvent.BEFORE_SELECT = 'editor.before_select';
11940
12061
  EditorEvent.SELECT = 'editor.select';
12062
+ EditorEvent.AFTER_SELECT = 'editor.after_select';
11941
12063
  EditorEvent.BEFORE_HOVER = 'editor.before_hover';
11942
12064
  EditorEvent.HOVER = 'editor.hover';
11943
12065
 
11944
- class EditorMoveEvent extends EditorEvent {
11945
- constructor(type, data) {
11946
- super(type, data);
11947
- }
11948
- }
11949
- EditorMoveEvent.BEFORE_MOVE = 'editor.before_move';
11950
- EditorMoveEvent.MOVE = 'editor.move';
11951
-
11952
- class EditorScaleEvent extends EditorEvent {
11953
- constructor(type, data) {
11954
- super(type, data);
11955
- }
11956
- }
11957
- EditorScaleEvent.BEFORE_SCALE = 'editor.before_scale';
11958
- EditorScaleEvent.SCALE = 'editor.scale';
11959
-
11960
- class EditorRotateEvent extends EditorEvent {
11961
- constructor(type, data) {
11962
- super(type, data);
11963
- }
11964
- }
11965
- EditorRotateEvent.BEFORE_ROTATE = 'editor.before_rotate';
11966
- EditorRotateEvent.ROTATE = 'editor.rotate';
11967
-
11968
- class EditorSkewEvent extends EditorEvent {
11969
- constructor(type, data) {
11970
- super(type, data);
11971
- }
11972
- }
11973
- EditorSkewEvent.BEFORE_SKEW = 'editor.before_skew';
11974
- EditorSkewEvent.SKEW = 'editor.skew';
11975
-
11976
12066
  function targetAttr(fn) {
11977
12067
  return (target, key) => {
11978
12068
  const privateKey = '_' + key;
@@ -11986,6 +12076,8 @@ function targetAttr(fn) {
11986
12076
  if (isSelect) {
11987
12077
  if (value instanceof Array && value.length > 1 && value[0].locked)
11988
12078
  value.splice(0, 1);
12079
+ if (this.single)
12080
+ this.element.syncEventer = null;
11989
12081
  const { beforeSelect } = this.config;
11990
12082
  if (beforeSelect) {
11991
12083
  const check = beforeSelect({ target: value });
@@ -12009,9 +12101,11 @@ function mergeConfigAttr() {
12009
12101
  return (target, key) => {
12010
12102
  defineKey(target, key, {
12011
12103
  get() {
12012
- const { config, element, dragPoint } = this, mergeConfig = Object.assign({}, config);
12104
+ const { config, element, dragPoint, editBox } = this, mergeConfig = Object.assign({}, config);
12013
12105
  if (element && element.editConfig)
12014
12106
  Object.assign(mergeConfig, element.editConfig);
12107
+ if (editBox.config)
12108
+ Object.assign(mergeConfig, editBox.config);
12015
12109
  if (dragPoint) {
12016
12110
  if (dragPoint.editConfig)
12017
12111
  Object.assign(mergeConfig, dragPoint.editConfig);
@@ -12043,14 +12137,17 @@ class Stroker extends UI {
12043
12137
  this.strokeAlign = 'center';
12044
12138
  }
12045
12139
  setTarget(target, style) {
12046
- this.set(style);
12140
+ if (style)
12141
+ this.set(style);
12047
12142
  this.target = target;
12048
12143
  this.update();
12049
12144
  }
12050
- update() {
12145
+ update(style) {
12051
12146
  const { list } = this;
12052
12147
  if (list.length) {
12053
12148
  setListWithFn(bounds$2, list, worldBounds);
12149
+ if (style)
12150
+ this.set(style);
12054
12151
  this.set(bounds$2);
12055
12152
  this.visible = true;
12056
12153
  }
@@ -12193,15 +12290,14 @@ class EditSelect extends Group {
12193
12290
  }
12194
12291
  onSelect() {
12195
12292
  if (this.running) {
12196
- const { mergeConfig, list } = this.editor;
12197
- const { stroke, strokeWidth, selectedStyle } = mergeConfig;
12198
- this.targetStroker.setTarget(list, Object.assign({ stroke, strokeWidth: Math.max(1, strokeWidth / 2) }, (selectedStyle || {})));
12293
+ this.targetStroker.setTarget(this.editor.list);
12199
12294
  this.hoverStroker.target = null;
12200
12295
  }
12201
12296
  }
12202
12297
  update() {
12203
12298
  this.hoverStroker.update();
12204
- this.targetStroker.update();
12299
+ const { stroke, strokeWidth, selectedStyle } = this.editor.mergedConfig;
12300
+ this.targetStroker.update(Object.assign({ stroke, strokeWidth: strokeWidth && Math.max(1, strokeWidth / 2) }, (selectedStyle || {})));
12205
12301
  }
12206
12302
  onPointerMove(e) {
12207
12303
  const { app, editor } = this;
@@ -12383,16 +12479,16 @@ const { topLeft: topLeft$1, top: top$1, topRight: topRight$1, right: right$2, bo
12383
12479
  const { toPoint } = AroundHelper;
12384
12480
  const { within: within$2 } = MathHelper;
12385
12481
  const EditDataHelper = {
12386
- getScaleData(element, startBounds, direction, totalMove, lockRatio, around, flipable, scaleMode) {
12482
+ getScaleData(target, startBounds, direction, totalMove, lockRatio, around, flipable, scaleMode) {
12387
12483
  let align, origin = {}, scaleX = 1, scaleY = 1;
12388
- const { boxBounds, widthRange, heightRange, dragBounds, worldBoxBounds } = element;
12484
+ const { boxBounds, widthRange, heightRange, dragBounds, worldBoxBounds } = target;
12389
12485
  const { width, height } = startBounds;
12390
12486
  if (around) {
12391
12487
  totalMove.x *= 2;
12392
12488
  totalMove.y *= 2;
12393
12489
  }
12394
- const originChangedScaleX = element.scaleX / startBounds.scaleX;
12395
- const originChangedScaleY = element.scaleY / startBounds.scaleY;
12490
+ const originChangedScaleX = target.scaleX / startBounds.scaleX;
12491
+ const originChangedScaleY = target.scaleY / startBounds.scaleY;
12396
12492
  const signX = originChangedScaleX < 0 ? -1 : 1;
12397
12493
  const signY = originChangedScaleY < 0 ? -1 : 1;
12398
12494
  const changedScaleX = scaleMode ? originChangedScaleX : signX * boxBounds.width / width;
@@ -12468,7 +12564,7 @@ const EditDataHelper = {
12468
12564
  if (useScaleY)
12469
12565
  scaleY /= changedScaleY;
12470
12566
  if (!flipable) {
12471
- const { worldTransform } = element;
12567
+ const { worldTransform } = target;
12472
12568
  if (scaleX < 0)
12473
12569
  scaleX = 1 / boxBounds.width / worldTransform.scaleX;
12474
12570
  if (scaleY < 0)
@@ -12476,24 +12572,26 @@ const EditDataHelper = {
12476
12572
  }
12477
12573
  toPoint(around || align, boxBounds, origin, true);
12478
12574
  if (dragBounds) {
12479
- const allowBounds = dragBounds === 'parent' ? element.parent.boxBounds : dragBounds;
12480
- const localBounds = new Bounds(element.__localBoxBounds);
12481
- localBounds.scaleOf(element.getLocalPointByInner(origin), scaleX, scaleY);
12482
- if (!BoundsHelper.includes(allowBounds, localBounds)) {
12483
- const realBounds = localBounds.getIntersect(allowBounds);
12484
- const fitScaleX = realBounds.width / localBounds.width, fitScaleY = realBounds.height / localBounds.height;
12485
- if (useScaleX)
12486
- scaleX *= fitScaleX;
12487
- if (useScaleY)
12488
- scaleY *= fitScaleY;
12575
+ const allowBounds = dragBounds === 'parent' ? target.parent.boxBounds : dragBounds;
12576
+ const childBounds = new Bounds(target.__localBoxBounds);
12577
+ if (BoundsHelper.includes(new Bounds(allowBounds).spread(0.1), childBounds)) {
12578
+ childBounds.scaleOf(target.getLocalPointByInner(origin), scaleX, scaleY);
12579
+ if (!BoundsHelper.includes(allowBounds, childBounds)) {
12580
+ const realBounds = childBounds.getIntersect(allowBounds);
12581
+ const fitScaleX = realBounds.width / childBounds.width, fitScaleY = realBounds.height / childBounds.height;
12582
+ if (useScaleX)
12583
+ scaleX *= fitScaleX;
12584
+ if (useScaleY)
12585
+ scaleY *= fitScaleY;
12586
+ }
12489
12587
  }
12490
12588
  }
12491
12589
  if (useScaleX && widthRange) {
12492
- const nowWidth = boxBounds.width * element.scaleX;
12590
+ const nowWidth = boxBounds.width * target.scaleX;
12493
12591
  scaleX = within$2(nowWidth * scaleX, widthRange) / nowWidth;
12494
12592
  }
12495
12593
  if (useScaleY && heightRange) {
12496
- const nowHeight = boxBounds.height * element.scaleY;
12594
+ const nowHeight = boxBounds.height * target.scaleY;
12497
12595
  scaleY = within$2(nowHeight * scaleY, heightRange) / nowHeight;
12498
12596
  }
12499
12597
  if (useScaleX && Math.abs(scaleX * worldBoxBounds.width) < 1)
@@ -12504,7 +12602,7 @@ const EditDataHelper = {
12504
12602
  scaleY = scaleX = Math.min(scaleX, scaleY);
12505
12603
  return { origin, scaleX, scaleY, direction, lockRatio, around };
12506
12604
  },
12507
- getRotateData(bounds, direction, current, last, around) {
12605
+ getRotateData(target, direction, current, last, around) {
12508
12606
  let align, origin = {};
12509
12607
  switch (direction) {
12510
12608
  case topLeft$1:
@@ -12522,8 +12620,8 @@ const EditDataHelper = {
12522
12620
  default:
12523
12621
  align = 'center';
12524
12622
  }
12525
- toPoint(around || align, bounds, origin, true);
12526
- return { origin, rotation: PointHelper.getRotation(last, origin, current) };
12623
+ toPoint(around || align, target.boxBounds, origin, true);
12624
+ return { origin, rotation: PointHelper.getRotation(last, target.getWorldPointByBox(origin), current) };
12527
12625
  },
12528
12626
  getSkewData(bounds, direction, move, around) {
12529
12627
  let align, origin = {}, skewX = 0, skewY = 0;
@@ -12620,9 +12718,9 @@ const EditDataHelper = {
12620
12718
  };
12621
12719
 
12622
12720
  const cacheCursors = {};
12623
- function updateCursor(editor, e) {
12624
- const { editBox } = editor, point = editBox.enterPoint;
12625
- if (!point || !editor.editing || !editBox.visible)
12721
+ function updatePointCursor(editBox, e) {
12722
+ const { enterPoint: point, dragging, skewing, resizing, flippedX, flippedY } = editBox;
12723
+ if (!point || !editBox.editor.editing || !editBox.canUse)
12626
12724
  return;
12627
12725
  if (point.name === 'circle')
12628
12726
  return;
@@ -12632,13 +12730,14 @@ function updateCursor(editor, e) {
12632
12730
  return;
12633
12731
  }
12634
12732
  let { rotation } = editBox;
12635
- const { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editor.mergeConfig;
12636
- const { pointType } = point, { flippedX, flippedY } = editBox;
12733
+ const { pointType } = point, { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editBox.mergeConfig;
12637
12734
  let showResize = pointType.includes('resize');
12638
12735
  if (showResize && rotateable && (e.metaKey || e.ctrlKey || !resizeable))
12639
12736
  showResize = false;
12640
12737
  const showSkew = skewable && !showResize && (point.name === 'resize-line' || pointType === 'skew');
12641
- const cursor = showSkew ? skewCursor : (showResize ? resizeCursor : rotateCursor);
12738
+ const cursor = dragging
12739
+ ? (skewing ? skewCursor : (resizing ? resizeCursor : rotateCursor))
12740
+ : (showSkew ? skewCursor : (showResize ? resizeCursor : rotateCursor));
12642
12741
  rotation += (EditDataHelper.getFlipDirection(point.direction, flippedX, flippedY) + 1) * 45;
12643
12742
  rotation = Math.round(MathHelper.formatRotation(rotation, true) / 2) * 2;
12644
12743
  const { url, x, y } = cursor;
@@ -12650,9 +12749,10 @@ function updateCursor(editor, e) {
12650
12749
  cacheCursors[key] = point.cursor = { url: toDataURL(url, rotation), x, y };
12651
12750
  }
12652
12751
  }
12653
- function updateMoveCursor(editor) {
12654
- const { moveCursor, moveable } = editor.mergeConfig;
12655
- editor.editBox.rect.cursor = moveable ? moveCursor : undefined;
12752
+ function updateMoveCursor(editBox) {
12753
+ const { moveCursor, moveable } = editBox.mergeConfig;
12754
+ if (editBox.canUse)
12755
+ editBox.rect.cursor = moveable ? moveCursor : undefined;
12656
12756
  }
12657
12757
  function toDataURL(svg, rotation) {
12658
12758
  return '"data:image/svg+xml,' + encodeURIComponent(svg.replace('{{rotation}}', rotation.toString())) + '"';
@@ -12667,10 +12767,26 @@ class EditPoint extends Box {
12667
12767
 
12668
12768
  const fourDirection = ['top', 'right', 'bottom', 'left'], editConfig = undefined;
12669
12769
  class EditBox extends Group {
12770
+ get mergeConfig() {
12771
+ const { config } = this, { mergeConfig, editBox } = this.editor;
12772
+ return this.mergedConfig = config && (editBox !== this) ? Object.assign(Object.assign({}, mergeConfig), config) : mergeConfig;
12773
+ }
12774
+ get target() { return this._target || this.editor.element; }
12775
+ set target(target) { this._target = target; }
12776
+ get single() { return !!this._target || this.editor.single; }
12777
+ get transformTool() { return this._transformTool || this.editor; }
12778
+ set transformTool(tool) { this._transformTool = tool; }
12670
12779
  get flipped() { return this.flippedX || this.flippedY; }
12671
12780
  get flippedX() { return this.scaleX < 0; }
12672
12781
  get flippedY() { return this.scaleY < 0; }
12673
12782
  get flippedOne() { return this.scaleX * this.scaleY < 0; }
12783
+ get canUse() { return (this.visible && this.view.visible); }
12784
+ get canGesture() {
12785
+ if (!this.canUse)
12786
+ return false;
12787
+ const { moveable, resizeable, rotateable } = this.mergeConfig;
12788
+ return typeof moveable === 'string' || typeof resizeable === 'string' || typeof rotateable === 'string';
12789
+ }
12674
12790
  constructor(editor) {
12675
12791
  super();
12676
12792
  this.view = new Group();
@@ -12709,8 +12825,7 @@ class EditBox extends Group {
12709
12825
  this.add(view);
12710
12826
  }
12711
12827
  load() {
12712
- const { mergeConfig, element, single } = this.editor;
12713
- const { rect, circle, resizePoints } = this;
12828
+ const { target, mergeConfig, single, rect, circle, resizePoints } = this;
12714
12829
  const { stroke, strokeWidth } = mergeConfig;
12715
12830
  const pointsStyle = this.getPointsStyle();
12716
12831
  const middlePointsStyle = this.getMiddlePointsStyle();
@@ -12718,24 +12833,38 @@ class EditBox extends Group {
12718
12833
  for (let i = 0; i < 8; i++) {
12719
12834
  resizeP = resizePoints[i];
12720
12835
  resizeP.set(this.getPointStyle((i % 2) ? middlePointsStyle[((i - 1) / 2) % middlePointsStyle.length] : pointsStyle[(i / 2) % pointsStyle.length]));
12721
- if (!(i % 2))
12722
- resizeP.rotation = (i / 2) * 90;
12836
+ resizeP.rotation = ((i - (i % 2 ? 1 : 0)) / 2) * 90;
12723
12837
  }
12724
12838
  circle.set(this.getPointStyle(mergeConfig.circle || mergeConfig.rotatePoint || pointsStyle[0]));
12725
12839
  rect.set(Object.assign({ stroke, strokeWidth, editConfig }, (mergeConfig.rect || {})));
12726
- rect.hittable = !single;
12727
- rect.syncEventer = single && this.editor;
12728
- if (single) {
12729
- element.syncEventer = rect;
12730
- this.app.interaction.bottomList = [{ target: rect, proxy: element }];
12731
- }
12732
- }
12733
- update(bounds) {
12734
- const { rect, circle, buttons, resizePoints, rotatePoints, resizeLines, editor } = this;
12735
- const { mergeConfig, element, multiple, editMask } = editor;
12736
- const { middlePoint, resizeable, rotateable, hideOnSmall, editBox, mask } = mergeConfig;
12737
- this.visible = !element.locked;
12840
+ const syncEventer = single && this.transformTool.editTool;
12841
+ rect.hittable = !syncEventer;
12842
+ rect.syncEventer = syncEventer && this.editor;
12843
+ if (syncEventer) {
12844
+ target.syncEventer = rect;
12845
+ this.app.interaction.bottomList = [{ target: rect, proxy: target }];
12846
+ }
12847
+ updateMoveCursor(this);
12848
+ }
12849
+ update() {
12850
+ const { editor } = this;
12851
+ const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = this.target.getLayoutBounds('box', editor, true);
12852
+ this.set({ x, y, scaleX, scaleY, rotation, skewX, skewY });
12853
+ this.updateBounds({ x: 0, y: 0, width, height });
12854
+ }
12855
+ unload() {
12856
+ this.visible = false;
12857
+ if (this.app)
12858
+ this.rect.syncEventer = this.app.interaction.bottomList = null;
12859
+ }
12860
+ updateBounds(bounds) {
12861
+ const { editMask } = this.editor;
12862
+ const { mergeConfig, single, rect, circle, buttons, resizePoints, rotatePoints, resizeLines } = this;
12863
+ const { middlePoint, resizeable, rotateable, hideOnSmall, editBox, mask, spread } = mergeConfig;
12864
+ this.visible = !this.target.locked;
12738
12865
  editMask.visible = mask ? true : 0;
12866
+ if (spread)
12867
+ BoundsHelper.spread(bounds, spread);
12739
12868
  if (this.view.worldOpacity) {
12740
12869
  const { width, height } = bounds;
12741
12870
  const smallSize = typeof hideOnSmall === 'number' ? hideOnSmall : 10;
@@ -12760,7 +12889,6 @@ class EditBox extends Group {
12760
12889
  }
12761
12890
  else {
12762
12891
  resizeL.height = height;
12763
- resizeP.rotation = 90;
12764
12892
  if (hideOnSmall && resizeP.width * 2 > height)
12765
12893
  resizeP.visible = false;
12766
12894
  }
@@ -12768,25 +12896,25 @@ class EditBox extends Group {
12768
12896
  }
12769
12897
  circle.visible = showPoints && rotateable && !!(mergeConfig.circle || mergeConfig.rotatePoint);
12770
12898
  if (circle.visible)
12771
- this.layoutCircle(mergeConfig);
12899
+ this.layoutCircle();
12772
12900
  if (rect.path)
12773
12901
  rect.path = null;
12774
- rect.set(Object.assign(Object.assign({}, bounds), { visible: multiple ? true : editBox }));
12902
+ rect.set(Object.assign(Object.assign({}, bounds), { visible: single ? editBox : true }));
12775
12903
  buttons.visible = showPoints && buttons.children.length > 0 || 0;
12776
12904
  if (buttons.visible)
12777
- this.layoutButtons(mergeConfig);
12905
+ this.layoutButtons();
12778
12906
  }
12779
12907
  else
12780
12908
  rect.set(bounds);
12781
12909
  }
12782
- layoutCircle(config) {
12783
- const { circleDirection, circleMargin, buttonsMargin, buttonsDirection, middlePoint } = config;
12910
+ layoutCircle() {
12911
+ const { circleDirection, circleMargin, buttonsMargin, buttonsDirection, middlePoint } = this.mergedConfig;
12784
12912
  const direction = fourDirection.indexOf(circleDirection || ((this.buttons.children.length && buttonsDirection === 'bottom') ? 'top' : 'bottom'));
12785
12913
  this.setButtonPosition(this.circle, direction, circleMargin || buttonsMargin, !!middlePoint);
12786
12914
  }
12787
- layoutButtons(config) {
12915
+ layoutButtons() {
12788
12916
  const { buttons } = this;
12789
- const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = config;
12917
+ const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = this.mergedConfig;
12790
12918
  const { flippedX, flippedY } = this;
12791
12919
  let index = fourDirection.indexOf(buttonsDirection);
12792
12920
  if ((index % 2 && flippedX) || ((index + 1) % 2 && flippedY)) {
@@ -12815,49 +12943,51 @@ class EditBox extends Group {
12815
12943
  buttons.y = point.y + margin;
12816
12944
  }
12817
12945
  }
12818
- unload() {
12819
- this.visible = false;
12820
- }
12821
12946
  getPointStyle(userStyle) {
12822
- const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.editor.mergeConfig;
12947
+ const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.mergedConfig;
12823
12948
  const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius, offsetX: 0, offsetY: 0, editConfig };
12824
12949
  return userStyle ? Object.assign(defaultStyle, userStyle) : defaultStyle;
12825
12950
  }
12826
12951
  getPointsStyle() {
12827
- const { point } = this.editor.mergeConfig;
12952
+ const { point } = this.mergedConfig;
12828
12953
  return point instanceof Array ? point : [point];
12829
12954
  }
12830
12955
  getMiddlePointsStyle() {
12831
- const { middlePoint } = this.editor.mergeConfig;
12956
+ const { middlePoint } = this.mergedConfig;
12832
12957
  return middlePoint instanceof Array ? middlePoint : (middlePoint ? [middlePoint] : this.getPointsStyle());
12833
12958
  }
12834
- onSelect(e) {
12835
- if (e.oldList.length === 1) {
12836
- e.oldList[0].syncEventer = null;
12837
- if (this.app)
12838
- this.app.interaction.bottomList = null;
12839
- }
12840
- }
12841
12959
  onDragStart(e) {
12842
12960
  this.dragging = true;
12843
12961
  const point = this.dragPoint = e.current, { pointType } = point;
12844
- const { editor, dragStartData } = this, { element } = editor;
12962
+ const { editor, dragStartData } = this, { target } = this, { moveable, resizeable, rotateable, skewable, hideOnMove } = this.mergeConfig;
12845
12963
  if (point.name === 'rect') {
12846
- this.moving = true;
12847
- editor.opacity = editor.mergeConfig.hideOnMove ? 0 : 1;
12964
+ moveable && (this.moving = true);
12965
+ editor.opacity = hideOnMove ? 0 : 1;
12966
+ }
12967
+ else {
12968
+ if (pointType.includes('rotate') || e.metaKey || e.ctrlKey || !resizeable) {
12969
+ rotateable && (this.rotating = true);
12970
+ if (pointType === 'resize-rotate')
12971
+ resizeable && (this.resizing = true);
12972
+ else if (point.name === 'resize-line')
12973
+ skewable && (this.skewing = true), this.rotating = false;
12974
+ }
12975
+ else if (pointType === 'resize')
12976
+ resizeable && (this.resizing = true);
12977
+ if (pointType === 'skew')
12978
+ skewable && (this.skewing = true);
12848
12979
  }
12849
12980
  dragStartData.x = e.x;
12850
12981
  dragStartData.y = e.y;
12851
- dragStartData.point = { x: element.x, y: element.y };
12852
- dragStartData.bounds = Object.assign({}, element.getLayoutBounds('box', 'local'));
12853
- dragStartData.rotation = element.rotation;
12982
+ dragStartData.point = { x: target.x, y: target.y };
12983
+ dragStartData.bounds = Object.assign({}, target.getLayoutBounds('box', 'local'));
12984
+ dragStartData.rotation = target.rotation;
12854
12985
  if (pointType && pointType.includes('resize'))
12855
12986
  ResizeEvent.resizingKeys = editor.leafList.keys;
12856
12987
  }
12857
12988
  onDragEnd(e) {
12858
- this.dragging = false;
12859
12989
  this.dragPoint = null;
12860
- this.moving = false;
12990
+ this.resetDoing();
12861
12991
  const { name, pointType } = e.current;
12862
12992
  if (name === 'rect')
12863
12993
  this.editor.opacity = 1;
@@ -12865,22 +12995,61 @@ class EditBox extends Group {
12865
12995
  ResizeEvent.resizingKeys = null;
12866
12996
  }
12867
12997
  onDrag(e) {
12868
- const { editor } = this;
12869
- const { pointType } = this.enterPoint = e.current;
12870
- if (pointType.includes('rotate') || e.metaKey || e.ctrlKey || !editor.mergeConfig.resizeable) {
12871
- editor.onRotate(e);
12872
- if (pointType === 'resize-rotate')
12873
- editor.onScale(e);
12874
- }
12875
- else if (pointType === 'resize')
12876
- editor.onScale(e);
12877
- if (pointType === 'skew')
12878
- editor.onSkew(e);
12879
- updateCursor(editor, e);
12998
+ const { transformTool, moving, resizing, rotating, skewing } = this;
12999
+ if (moving) {
13000
+ transformTool.onMove(e);
13001
+ updateMoveCursor(this);
13002
+ }
13003
+ else if (resizing || rotating || skewing) {
13004
+ const point = e.current;
13005
+ if (point.pointType)
13006
+ this.enterPoint = point;
13007
+ if (rotating)
13008
+ transformTool.onRotate(e);
13009
+ if (resizing)
13010
+ transformTool.onScale(e);
13011
+ if (skewing)
13012
+ transformTool.onSkew(e);
13013
+ updatePointCursor(this, e);
13014
+ }
13015
+ }
13016
+ resetDoing() {
13017
+ if (this.canUse)
13018
+ this.dragging = this.gesturing = this.moving = this.resizing = this.rotating = this.skewing = false;
13019
+ }
13020
+ onMove(e) {
13021
+ if (this.canGesture && e.moveType !== 'drag') {
13022
+ e.stop();
13023
+ if (typeof this.mergeConfig.moveable === 'string') {
13024
+ this.gesturing = this.moving = true;
13025
+ this.transformTool.onMove(e);
13026
+ }
13027
+ }
13028
+ }
13029
+ onScale(e) {
13030
+ if (this.canGesture) {
13031
+ e.stop();
13032
+ if (typeof this.mergeConfig.resizeable === 'string') {
13033
+ this.gesturing = this.resizing = true;
13034
+ this.transformTool.onScale(e);
13035
+ }
13036
+ }
13037
+ }
13038
+ onRotate(e) {
13039
+ if (this.canGesture) {
13040
+ e.stop();
13041
+ if (typeof this.mergeConfig.rotateable === 'string') {
13042
+ this.gesturing = this.rotating = true;
13043
+ this.transformTool.onRotate(e);
13044
+ }
13045
+ }
13046
+ }
13047
+ onKey(e) {
13048
+ updatePointCursor(this, e);
12880
13049
  }
12881
13050
  onArrow(e) {
12882
- const { editor } = this;
12883
- if (editor.editing && editor.mergeConfig.keyEvent) {
13051
+ const { editor, transformTool } = this;
13052
+ if (this.canUse && editor.editing && this.mergeConfig.keyEvent) {
12884
13053
  let x = 0, y = 0;
12885
13054
  const distance = e.shiftKey ? 10 : 1;
12886
13055
  switch (e.code) {
@@ -12897,31 +13066,32 @@ class EditBox extends Group {
12897
13066
  x = distance;
12898
13067
  }
12899
13068
  if (x || y)
12900
- editor.move(x, y);
13069
+ transformTool.move(x, y);
12901
13070
  }
12902
13071
  }
12903
13072
  onDoubleTap(e) {
12904
- if (this.editor.mergeConfig.openInner === 'double')
13073
+ const { openInner, preventEditInner } = this.mergeConfig;
13074
+ if (openInner === 'double' && !preventEditInner)
12905
13075
  this.openInner(e);
12906
13076
  }
12907
13077
  onLongPress(e) {
12908
- if (this.editor.mergeConfig.openInner === 'long')
13078
+ const { openInner, preventEditInner } = this.mergeConfig;
13079
+ if (openInner === 'long' && preventEditInner)
12909
13080
  this.openInner(e);
12910
13081
  }
12911
13082
  openInner(e) {
12912
- const { editor } = this;
12913
- if (editor.single) {
12914
- const { element } = editor;
12915
- if (element.locked)
13083
+ const { editor, target } = this;
13084
+ if (this.single) {
13085
+ if (target.locked)
12916
13086
  return;
12917
- if (element.isBranch && !element.editInner) {
12918
- if (element.textBox) {
12919
- const { children } = element;
13087
+ if (target.isBranch && !target.editInner) {
13088
+ if (target.textBox) {
13089
+ const { children } = target;
12920
13090
  const find = children.find(item => item.editable && item instanceof Text) || children.find(item => item instanceof Text);
12921
13091
  if (find)
12922
13092
  return editor.openInnerEditor(find);
12923
13093
  }
12924
- editor.openGroup(element);
13094
+ editor.openGroup(target);
12925
13095
  editor.target = editor.selector.findDeepOne(e);
12926
13096
  }
12927
13097
  else {
@@ -12930,7 +13100,6 @@ class EditBox extends Group {
12930
13100
  }
12931
13101
  }
12932
13102
  listenPointEvents(point, type, direction) {
12933
- const { editor } = this;
12934
13103
  point.direction = direction;
12935
13104
  point.pointType = type;
12936
13105
  const events = [
@@ -12940,19 +13109,31 @@ class EditBox extends Group {
12940
13109
  [PointerEvent.LEAVE, () => { this.enterPoint = null; }],
12941
13110
  ];
12942
13111
  if (point.name !== 'circle')
12943
- events.push([PointerEvent.ENTER, (e) => { this.enterPoint = point, updateCursor(editor, e); }]);
13112
+ events.push([PointerEvent.ENTER, (e) => { this.enterPoint = point, updatePointCursor(this, e); }]);
12944
13113
  this.__eventIds.push(point.on_(events));
12945
13114
  }
12946
13115
  __listenEvents() {
12947
- const { rect, editor } = this;
12948
- this.__eventIds.push(editor.on_(EditorEvent.SELECT, this.onSelect, this), rect.on_([
13116
+ const { rect, editor, __eventIds: events } = this;
13117
+ events.push(rect.on_([
12949
13118
  [DragEvent.START, this.onDragStart, this],
12950
- [DragEvent.DRAG, editor.onMove, editor],
13119
+ [DragEvent.DRAG, this.onDrag, this],
12951
13120
  [DragEvent.END, this.onDragEnd, this],
12952
- [PointerEvent.ENTER, () => updateMoveCursor(editor)],
13121
+ [PointerEvent.ENTER, () => updateMoveCursor(this)],
12953
13122
  [PointerEvent.DOUBLE_TAP, this.onDoubleTap, this],
12954
13123
  [PointerEvent.LONG_PRESS, this.onLongPress, this]
12955
13124
  ]));
13125
+ this.waitLeafer(() => {
13126
+ events.push(editor.app.on_([
13127
+ [[KeyEvent.HOLD, KeyEvent.UP], this.onKey, this],
13128
+ [KeyEvent.DOWN, this.onArrow, this],
13129
+ [MoveEvent.BEFORE_MOVE, this.onMove, this, true],
13130
+ [ZoomEvent.BEFORE_ZOOM, this.onScale, this, true],
13131
+ [RotateEvent.BEFORE_ROTATE, this.onRotate, this, true],
13132
+ [MoveEvent.END, this.resetDoing, this],
13133
+ [ZoomEvent.END, this.resetDoing, this],
13134
+ [RotateEvent.END, this.resetDoing, this],
13135
+ ]));
13136
+ });
12956
13137
  }
12957
13138
  __removeListenEvents() {
12958
13139
  this.off_(this.__eventIds);
@@ -12983,11 +13164,12 @@ class EditMask extends UI {
12983
13164
  if (options.bounds && !options.bounds.hit(editor.editBox.rect.__world, options.matrix))
12984
13165
  return;
12985
13166
  canvas.saveBlendMode('destination-out');
13167
+ options = Object.assign(Object.assign({}, options), { shape: true });
12986
13168
  editor.list.forEach(item => {
12987
- item.__renderShape(canvas, options);
12988
- const { __box, parent } = item;
12989
- if ((item = __box) || ((item = parent) && parent.textBox))
12990
- item.__renderShape(canvas, options);
13169
+ item.__render(canvas, options);
13170
+ const { parent } = item;
13171
+ if (parent && parent.textBox)
13172
+ parent.__renderShape(canvas, options);
12991
13173
  });
12992
13174
  canvas.restoreBlendMode();
12993
13175
  }
@@ -13082,7 +13264,7 @@ const config = {
13082
13264
  const bounds$1 = new Bounds();
13083
13265
  function simulate(editor) {
13084
13266
  const { simulateTarget, list } = editor;
13085
- const { zoomLayer } = list[0].leafer.zoomLayer;
13267
+ const { zoomLayer } = list[0].leafer;
13086
13268
  simulateTarget.safeChange(() => {
13087
13269
  bounds$1.setListWithFn(list, (leaf) => leaf.getBounds('box', 'page'));
13088
13270
  if (bounds$1.width === 0)
@@ -13104,15 +13286,15 @@ function onTarget(editor, oldValue) {
13104
13286
  else {
13105
13287
  editor.simulateTarget.remove();
13106
13288
  editor.leafList.reset();
13107
- editor.closeInnerEditor();
13108
13289
  }
13109
- editor.emitEvent(new EditorEvent(EditorEvent.SELECT, { editor, value: target, oldValue }));
13290
+ editor.closeInnerEditor(true);
13291
+ editor.unloadEditTool();
13292
+ const data = { editor, value: target, oldValue };
13293
+ editor.emitEvent(new EditorEvent(EditorEvent.SELECT, data));
13110
13294
  editor.checkOpenedGroups();
13111
13295
  if (editor.editing) {
13112
13296
  editor.waitLeafer(() => {
13113
- updateMoveCursor(editor);
13114
13297
  editor.updateEditTool();
13115
- editor.update();
13116
13298
  editor.listenTargetEvents();
13117
13299
  });
13118
13300
  }
@@ -13120,6 +13302,7 @@ function onTarget(editor, oldValue) {
13120
13302
  editor.updateEditTool();
13121
13303
  editor.removeTargetEvents();
13122
13304
  }
13305
+ editor.emitEvent(new EditorEvent(EditorEvent.AFTER_SELECT, data));
13123
13306
  }
13124
13307
  function onHover(editor, oldValue) {
13125
13308
  editor.emitEvent(new EditorEvent(EditorEvent.HOVER, { editor, value: editor.hoverTarget, oldValue }));
@@ -13291,98 +13474,44 @@ class SimulateElement extends Rect {
13291
13474
  }
13292
13475
  }
13293
13476
 
13294
- class Editor extends Group {
13295
- get list() { return this.leafList.list; }
13296
- get dragHoverExclude() { return [this.editBox.rect]; }
13297
- get editing() { return !!this.list.length; }
13298
- get groupOpening() { return !!this.openedGroupList.length; }
13299
- get multiple() { return this.list.length > 1; }
13300
- get single() { return this.list.length === 1; }
13301
- get dragging() { return this.editBox.dragging; }
13302
- get moving() { return this.editBox.moving; }
13303
- get dragPoint() { return this.editBox.dragPoint; }
13304
- get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
13305
- get buttons() { return this.editBox.buttons; }
13306
- constructor(userConfig, data) {
13307
- super(data);
13308
- this.leafList = new LeafList();
13309
- this.openedGroupList = new LeafList();
13310
- this.simulateTarget = new SimulateElement(this);
13311
- this.editBox = new EditBox(this);
13312
- this.editToolList = {};
13313
- this.selector = new EditSelect(this);
13314
- this.editMask = new EditMask(this);
13315
- this.targetEventIds = [];
13316
- let mergedConfig = DataHelper.clone(config);
13317
- if (userConfig)
13318
- mergedConfig = DataHelper.default(userConfig, mergedConfig);
13319
- this.mergedConfig = this.config = mergedConfig;
13320
- this.addMany(this.editMask, this.selector, this.editBox);
13321
- if (!Plugin.has('resize'))
13322
- this.config.editSize = 'scale';
13323
- }
13324
- select(target) {
13325
- this.target = target;
13326
- }
13327
- cancel() {
13328
- this.target = null;
13329
- }
13330
- hasItem(item) {
13331
- return this.leafList.has(item);
13332
- }
13333
- addItem(item) {
13334
- if (!this.hasItem(item) && !item.locked)
13335
- this.leafList.add(item), this.target = this.leafList.list;
13336
- }
13337
- removeItem(item) {
13338
- if (this.hasItem(item))
13339
- this.leafList.remove(item), this.target = this.leafList.list;
13340
- }
13341
- shiftItem(item) {
13342
- this.hasItem(item) ? this.removeItem(item) : this.addItem(item);
13343
- }
13344
- update() {
13345
- if (this.editing) {
13346
- if (!this.element.parent)
13347
- return this.cancel();
13348
- if (this.innerEditing)
13349
- this.innerEditor.update();
13350
- this.editTool.update();
13351
- this.selector.update();
13352
- }
13477
+ class EditorMoveEvent extends EditorEvent {
13478
+ constructor(type, data) {
13479
+ super(type, data);
13353
13480
  }
13354
- updateEditBox() {
13355
- if (this.multiple)
13356
- simulate(this);
13357
- this.update();
13481
+ }
13482
+ EditorMoveEvent.BEFORE_MOVE = 'editor.before_move';
13483
+ EditorMoveEvent.MOVE = 'editor.move';
13484
+
13485
+ class EditorScaleEvent extends EditorEvent {
13486
+ constructor(type, data) {
13487
+ super(type, data);
13358
13488
  }
13359
- updateEditTool() {
13360
- const tool = this.editTool;
13361
- if (tool) {
13362
- this.editBox.unload();
13363
- tool.unload();
13364
- this.editTool = null;
13365
- }
13366
- if (this.editing) {
13367
- const tag = this.single ? this.list[0].editOuter : 'EditTool';
13368
- this.editTool = this.editToolList[tag] = this.editToolList[tag] || EditToolCreator.get(tag, this);
13369
- this.editBox.load();
13370
- this.editTool.load();
13371
- }
13489
+ }
13490
+ EditorScaleEvent.BEFORE_SCALE = 'editor.before_scale';
13491
+ EditorScaleEvent.SCALE = 'editor.scale';
13492
+
13493
+ class EditorRotateEvent extends EditorEvent {
13494
+ constructor(type, data) {
13495
+ super(type, data);
13372
13496
  }
13373
- getEditSize(_ui) {
13374
- return this.mergeConfig.editSize;
13497
+ }
13498
+ EditorRotateEvent.BEFORE_ROTATE = 'editor.before_rotate';
13499
+ EditorRotateEvent.ROTATE = 'editor.rotate';
13500
+
13501
+ class EditorSkewEvent extends EditorEvent {
13502
+ constructor(type, data) {
13503
+ super(type, data);
13375
13504
  }
13505
+ }
13506
+ EditorSkewEvent.BEFORE_SKEW = 'editor.before_skew';
13507
+ EditorSkewEvent.SKEW = 'editor.skew';
13508
+
13509
+ class TransformTool {
13376
13510
  onMove(e) {
13511
+ const { target, dragStartData } = this.editBox;
13377
13512
  if (e instanceof MoveEvent) {
13378
- if (e.moveType !== 'drag') {
13379
- const { moveable, resizeable } = this.mergeConfig;
13380
- const move = e.getLocalMove(this.element);
13381
- if (moveable === 'move')
13382
- e.stop(), this.move(move.x, move.y);
13383
- else if (resizeable === 'zoom')
13384
- e.stop();
13385
- }
13513
+ const move = e.getLocalMove(target);
13514
+ this.move(move.x, move.y);
13386
13515
  }
13387
13516
  else {
13388
13517
  const total = { x: e.totalX, y: e.totalY };
@@ -13392,22 +13521,21 @@ class Editor extends Group {
13392
13521
  else
13393
13522
  total.x = 0;
13394
13523
  }
13395
- this.move(DragEvent.getValidMove(this.element, this.editBox.dragStartData.point, total));
13524
+ this.move(DragEvent.getValidMove(target, dragStartData.point, total));
13396
13525
  }
13397
13526
  }
13398
13527
  onScale(e) {
13399
- const { element } = this;
13400
- let { around, lockRatio, resizeable, flipable, editSize } = this.mergeConfig;
13528
+ const { target, mergeConfig, single, dragStartData } = this.editBox;
13529
+ let { around, lockRatio, flipable, editSize } = mergeConfig;
13401
13530
  if (e instanceof ZoomEvent) {
13402
- if (resizeable === 'zoom')
13403
- e.stop(), this.scaleOf(element.getBoxPoint(e), e.scale, e.scale);
13531
+ this.scaleOf(target.getBoxPoint(e), e.scale, e.scale);
13404
13532
  }
13405
13533
  else {
13406
13534
  const { direction } = e.current;
13407
- if (e.shiftKey || element.lockRatio)
13535
+ if (e.shiftKey || target.lockRatio)
13408
13536
  lockRatio = true;
13409
- const data = EditDataHelper.getScaleData(element, this.editBox.dragStartData.bounds, direction, e.getInnerTotal(element), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, this.multiple || editSize === 'scale');
13410
- if (this.editTool.onScaleWithDrag) {
13537
+ const data = EditDataHelper.getScaleData(target, dragStartData.bounds, direction, e.getInnerTotal(target), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, !single || editSize === 'scale');
13538
+ if (this.editTool && this.editTool.onScaleWithDrag) {
13411
13539
  data.drag = e;
13412
13540
  this.scaleWithDrag(data);
13413
13541
  }
@@ -13417,38 +13545,28 @@ class Editor extends Group {
13417
13545
  }
13418
13546
  }
13419
13547
  onRotate(e) {
13420
- const { skewable, rotateable, around, rotateGap } = this.mergeConfig;
13421
- const { direction, name } = e.current;
13422
- if (skewable && name === 'resize-line')
13423
- return this.onSkew(e);
13424
- const { element } = this, { dragStartData } = this.editBox;
13548
+ const { target, mergeConfig, dragStartData } = this.editBox;
13549
+ const { around, rotateAround, rotateGap } = mergeConfig;
13550
+ const { direction } = e.current;
13425
13551
  let origin, rotation;
13426
13552
  if (e instanceof RotateEvent) {
13427
- if (rotateable === 'rotate')
13428
- e.stop(), rotation = e.rotation, origin = element.getBoxPoint(e);
13429
- else
13430
- return;
13431
- if (element.scaleX * element.scaleY < 0)
13432
- rotation = -rotation;
13553
+ rotation = e.rotation;
13554
+ origin = rotateAround ? AroundHelper.getPoint(rotateAround, target.boxBounds) : target.getBoxPoint(e);
13433
13555
  }
13434
13556
  else {
13435
- const data = EditDataHelper.getRotateData(element.boxBounds, direction, e.getBoxPoint(element), element.getBoxPoint(dragStartData), e.shiftKey ? null : (element.around || element.origin || around || 'center'));
13436
- rotation = data.rotation;
13557
+ const data = EditDataHelper.getRotateData(target, direction, e, dragStartData, e.shiftKey ? null : (rotateAround || target.around || target.origin || around || 'center'));
13558
+ rotation = dragStartData.rotation + data.rotation - target.rotation;
13437
13559
  origin = data.origin;
13438
13560
  }
13439
- if (element.scaleX * element.scaleY < 0)
13440
- rotation = -rotation;
13441
- if (e instanceof DragEvent)
13442
- rotation = dragStartData.rotation + rotation - element.rotation;
13443
- rotation = MathHelper.float(MathHelper.getGapRotation(rotation, rotateGap, element.rotation), 2);
13561
+ rotation = MathHelper.float(MathHelper.getGapRotation(rotation, rotateGap, target.rotation), 2);
13444
13562
  if (!rotation)
13445
13563
  return;
13446
13564
  this.rotateOf(origin, rotation);
13447
13565
  }
13448
13566
  onSkew(e) {
13449
- const { element } = this;
13450
- const { around } = this.mergeConfig;
13451
- const { origin, skewX, skewY } = EditDataHelper.getSkewData(element.boxBounds, e.current.direction, e.getInnerMove(element), EditDataHelper.getAround(around, e.altKey));
13567
+ const { target, mergeConfig } = this.editBox;
13568
+ const { around } = mergeConfig;
13569
+ const { origin, skewX, skewY } = EditDataHelper.getSkewData(target.boxBounds, e.current.direction, e.getInnerMove(target), EditDataHelper.getAround(around, e.altKey));
13452
13570
  if (!skewX && !skewY)
13453
13571
  return;
13454
13572
  this.skewOf(origin, skewX, skewY);
@@ -13458,7 +13576,8 @@ class Editor extends Group {
13458
13576
  return;
13459
13577
  if (typeof x === 'object')
13460
13578
  y = x.y, x = x.x;
13461
- const { element: target } = this, { beforeMove } = this.mergeConfig;
13579
+ const { target, mergeConfig, single, editor } = this.editBox;
13580
+ const { beforeMove } = mergeConfig;
13462
13581
  if (beforeMove) {
13463
13582
  const check = beforeMove({ target, x, y });
13464
13583
  if (typeof check === 'object')
@@ -13467,25 +13586,26 @@ class Editor extends Group {
13467
13586
  return;
13468
13587
  }
13469
13588
  const world = target.getWorldPointByLocal({ x, y }, null, true);
13470
- if (this.multiple)
13589
+ if (!single)
13471
13590
  target.safeChange(() => target.move(x, y));
13472
- const data = { target, editor: this, moveX: world.x, moveY: world.y };
13591
+ const data = { target, editor, moveX: world.x, moveY: world.y };
13473
13592
  this.emitEvent(new EditorMoveEvent(EditorMoveEvent.BEFORE_MOVE, data));
13474
13593
  const event = new EditorMoveEvent(EditorMoveEvent.MOVE, data);
13475
- this.editTool.onMove(event);
13594
+ this.doMove(event);
13476
13595
  this.emitEvent(event);
13477
13596
  }
13478
13597
  scaleWithDrag(data) {
13479
13598
  if (!this.checkTransform('resizeable'))
13480
13599
  return;
13481
- const { element: target } = this, { beforeScale } = this.mergeConfig;
13600
+ const { target, mergeConfig, editor } = this.editBox;
13601
+ const { beforeScale } = mergeConfig;
13482
13602
  if (beforeScale) {
13483
13603
  const { origin, scaleX, scaleY, drag } = data;
13484
13604
  const check = beforeScale({ target, drag, origin, scaleX, scaleY });
13485
13605
  if (check === false)
13486
13606
  return;
13487
13607
  }
13488
- data = Object.assign(Object.assign({}, data), { target, editor: this, worldOrigin: target.getWorldPoint(data.origin) });
13608
+ data = Object.assign(Object.assign({}, data), { target, editor, worldOrigin: target.getWorldPoint(data.origin) });
13489
13609
  this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
13490
13610
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
13491
13611
  this.editTool.onScaleWithDrag(event);
@@ -13494,7 +13614,8 @@ class Editor extends Group {
13494
13614
  scaleOf(origin, scaleX, scaleY = scaleX, _resize) {
13495
13615
  if (!this.checkTransform('resizeable'))
13496
13616
  return;
13497
- const { element: target } = this, { beforeScale } = this.mergeConfig;
13617
+ const { target, mergeConfig, single, editor } = this.editBox;
13618
+ const { beforeScale } = mergeConfig;
13498
13619
  if (beforeScale) {
13499
13620
  const check = beforeScale({ target, origin, scaleX, scaleY });
13500
13621
  if (typeof check === 'object')
@@ -13503,29 +13624,30 @@ class Editor extends Group {
13503
13624
  return;
13504
13625
  }
13505
13626
  const worldOrigin = this.getWorldOrigin(origin);
13506
- const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.scaleOf(origin, scaleX, scaleY)));
13507
- const data = { target, editor: this, worldOrigin, scaleX, scaleY, transform };
13627
+ const transform = !single && this.getChangedTransform(() => target.safeChange(() => target.scaleOf(origin, scaleX, scaleY)));
13628
+ const data = { target, editor, worldOrigin, scaleX, scaleY, transform };
13508
13629
  this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
13509
13630
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
13510
- this.editTool.onScale(event);
13631
+ this.doScale(event);
13511
13632
  this.emitEvent(event);
13512
13633
  }
13513
13634
  flip(axis) {
13514
13635
  if (!this.checkTransform('resizeable'))
13515
13636
  return;
13516
- const { element } = this;
13637
+ const { target, single, editor } = this.editBox;
13517
13638
  const worldOrigin = this.getWorldOrigin('center');
13518
- const transform = this.multiple ? this.getChangedTransform(() => element.safeChange(() => element.flip(axis))) : new Matrix(LeafHelper.getFlipTransform(element, axis));
13519
- const data = { target: element, editor: this, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform };
13639
+ const transform = !single ? this.getChangedTransform(() => target.safeChange(() => target.flip(axis))) : new Matrix(LeafHelper.getFlipTransform(target, axis));
13640
+ const data = { target, editor, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform };
13520
13641
  this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
13521
13642
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
13522
- this.editTool.onScale(event);
13643
+ this.doScale(event);
13523
13644
  this.emitEvent(event);
13524
13645
  }
13525
13646
  rotateOf(origin, rotation) {
13526
13647
  if (!this.checkTransform('rotateable'))
13527
13648
  return;
13528
- const { element: target } = this, { beforeRotate } = this.mergeConfig;
13649
+ const { target, mergeConfig, single, editor } = this.editBox;
13650
+ const { beforeRotate } = mergeConfig;
13529
13651
  if (beforeRotate) {
13530
13652
  const check = beforeRotate({ target, origin, rotation });
13531
13653
  if (typeof check === 'number')
@@ -13534,17 +13656,18 @@ class Editor extends Group {
13534
13656
  return;
13535
13657
  }
13536
13658
  const worldOrigin = this.getWorldOrigin(origin);
13537
- const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.rotateOf(origin, rotation)));
13538
- const data = { target, editor: this, worldOrigin, rotation, transform };
13659
+ const transform = !single && this.getChangedTransform(() => target.safeChange(() => target.rotateOf(origin, rotation)));
13660
+ const data = { target, editor, worldOrigin, rotation, transform };
13539
13661
  this.emitEvent(new EditorRotateEvent(EditorRotateEvent.BEFORE_ROTATE, data));
13540
13662
  const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, data);
13541
- this.editTool.onRotate(event);
13663
+ this.doRotate(event);
13542
13664
  this.emitEvent(event);
13543
13665
  }
13544
13666
  skewOf(origin, skewX, skewY = 0, _resize) {
13545
13667
  if (!this.checkTransform('skewable'))
13546
13668
  return;
13547
- const { element: target } = this, { beforeSkew } = this.mergeConfig;
13669
+ const { target, mergeConfig, single, editor } = this.editBox;
13670
+ const { beforeSkew } = mergeConfig;
13548
13671
  if (beforeSkew) {
13549
13672
  const check = beforeSkew({ target, origin, skewX, skewY });
13550
13673
  if (typeof check === 'object')
@@ -13553,25 +13676,149 @@ class Editor extends Group {
13553
13676
  return;
13554
13677
  }
13555
13678
  const worldOrigin = this.getWorldOrigin(origin);
13556
- const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.skewOf(origin, skewX, skewY)));
13557
- const data = { target, editor: this, worldOrigin, skewX, skewY, transform };
13679
+ const transform = !single && this.getChangedTransform(() => target.safeChange(() => target.skewOf(origin, skewX, skewY)));
13680
+ const data = { target, editor, worldOrigin, skewX, skewY, transform };
13558
13681
  this.emitEvent(new EditorSkewEvent(EditorSkewEvent.BEFORE_SKEW, data));
13559
13682
  const event = new EditorSkewEvent(EditorSkewEvent.SKEW, data);
13560
- this.editTool.onSkew(event);
13683
+ this.doSkew(event);
13561
13684
  this.emitEvent(event);
13562
13685
  }
13563
- checkTransform(type) { return this.element && !this.element.locked && this.mergeConfig[type]; }
13686
+ doMove(event) {
13687
+ this.editTool.onMove(event);
13688
+ }
13689
+ doScale(event) {
13690
+ this.editTool.onScale(event);
13691
+ }
13692
+ doRotate(event) {
13693
+ this.editTool.onRotate(event);
13694
+ }
13695
+ doSkew(event) {
13696
+ this.editTool.onSkew(event);
13697
+ }
13698
+ checkTransform(type) {
13699
+ const { target, mergeConfig } = this.editBox;
13700
+ return target && !target.locked && mergeConfig[type];
13701
+ }
13564
13702
  getWorldOrigin(origin) {
13565
- return this.element.getWorldPoint(LeafHelper.getInnerOrigin(this.element, origin));
13703
+ const { target } = this.editBox;
13704
+ return target.getWorldPoint(LeafHelper.getInnerOrigin(target, origin));
13566
13705
  }
13567
13706
  getChangedTransform(func) {
13568
- const { element } = this;
13569
- if (this.multiple && !element.canChange)
13570
- return element.changedTransform;
13571
- const oldMatrix = new Matrix(element.worldTransform);
13707
+ const { target, single } = this.editBox;
13708
+ if (!single && !target.canChange)
13709
+ return target.changedTransform;
13710
+ const oldMatrix = new Matrix(target.worldTransform);
13572
13711
  func();
13573
- return new Matrix(element.worldTransform).divide(oldMatrix);
13712
+ return new Matrix(target.worldTransform).divide(oldMatrix);
13713
+ }
13714
+ emitEvent(event, capture) {
13715
+ this.editBox.editor.emitEvent(event, capture);
13716
+ }
13717
+ }
13718
+
13719
+ let Editor = class Editor extends Group {
13720
+ get list() { return this.leafList.list; }
13721
+ get dragHoverExclude() { return [this.editBox.rect]; }
13722
+ get editing() { return !!this.list.length; }
13723
+ get groupOpening() { return !!this.openedGroupList.length; }
13724
+ get multiple() { return this.list.length > 1; }
13725
+ get single() { return this.list.length === 1; }
13726
+ get dragPoint() { return this.editBox.dragPoint; }
13727
+ get dragging() { return this.editBox.dragging; }
13728
+ get gesturing() { return this.editBox.gesturing; }
13729
+ get moving() { return this.editBox.moving; }
13730
+ get resizing() { return this.editBox.resizing; }
13731
+ get rotating() { return this.editBox.rotating; }
13732
+ get skewing() { return this.editBox.skewing; }
13733
+ get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
13734
+ get buttons() { return this.editBox.buttons; }
13735
+ constructor(userConfig, data) {
13736
+ super(data);
13737
+ this.leafList = new LeafList();
13738
+ this.openedGroupList = new LeafList();
13739
+ this.simulateTarget = new SimulateElement(this);
13740
+ this.editBox = new EditBox(this);
13741
+ this.editToolList = {};
13742
+ this.selector = new EditSelect(this);
13743
+ this.editMask = new EditMask(this);
13744
+ this.targetEventIds = [];
13745
+ let mergedConfig = DataHelper.clone(config);
13746
+ if (userConfig)
13747
+ mergedConfig = DataHelper.default(userConfig, mergedConfig);
13748
+ this.mergedConfig = this.config = mergedConfig;
13749
+ this.addMany(this.editMask, this.selector, this.editBox);
13750
+ if (!Plugin.has('resize'))
13751
+ this.config.editSize = 'scale';
13574
13752
  }
13753
+ select(target) {
13754
+ this.target = target;
13755
+ }
13756
+ cancel() {
13757
+ this.target = null;
13758
+ }
13759
+ hasItem(item) {
13760
+ return this.leafList.has(item);
13761
+ }
13762
+ addItem(item) {
13763
+ if (!this.hasItem(item) && !item.locked)
13764
+ this.leafList.add(item), this.target = this.leafList.list;
13765
+ }
13766
+ removeItem(item) {
13767
+ if (this.hasItem(item))
13768
+ this.leafList.remove(item), this.target = this.leafList.list;
13769
+ }
13770
+ shiftItem(item) {
13771
+ this.hasItem(item) ? this.removeItem(item) : this.addItem(item);
13772
+ }
13773
+ update() {
13774
+ if (this.editing) {
13775
+ if (!this.element.parent)
13776
+ return this.cancel();
13777
+ if (this.innerEditing)
13778
+ this.innerEditor.update();
13779
+ this.editTool.update();
13780
+ this.selector.update();
13781
+ }
13782
+ }
13783
+ updateEditBox() {
13784
+ if (this.multiple)
13785
+ simulate(this);
13786
+ this.update();
13787
+ }
13788
+ updateEditTool() {
13789
+ this.unloadEditTool();
13790
+ if (this.editing) {
13791
+ const name = this.element.editOuter || 'EditTool';
13792
+ const tool = this.editTool = this.editToolList[name] = this.editToolList[name] || EditToolCreator.get(name, this);
13793
+ this.editBox.load();
13794
+ tool.load();
13795
+ this.update();
13796
+ }
13797
+ }
13798
+ unloadEditTool() {
13799
+ let tool = this.editTool;
13800
+ if (tool) {
13801
+ this.editBox.unload();
13802
+ tool.unload();
13803
+ this.editTool = null;
13804
+ }
13805
+ }
13806
+ getEditSize(_ui) {
13807
+ return this.mergeConfig.editSize;
13808
+ }
13809
+ onMove(_e) { }
13810
+ onScale(_e) { }
13811
+ onRotate(_e) { }
13812
+ onSkew(_e) { }
13813
+ move(_x, _y = 0) { }
13814
+ scaleWithDrag(_data) { }
13815
+ scaleOf(_origin, scaleX, _scaleY = scaleX, _resize) { }
13816
+ flip(_axis) { }
13817
+ rotateOf(_origin, _rotation) { }
13818
+ skewOf(_origin, _skewX, _skewY = 0, _resize) { }
13819
+ checkTransform(_type) { return undefined; }
13820
+ getWorldOrigin(_origin) { return undefined; }
13821
+ getChangedTransform(_func) { return undefined; }
13575
13822
  group(userGroup) {
13576
13823
  if (this.multiple) {
13577
13824
  this.emitGroupEvent(EditorGroupEvent.BEFORE_GROUP);
@@ -13628,16 +13875,21 @@ class Editor extends Group {
13628
13875
  if (group)
13629
13876
  group.emitEvent(event);
13630
13877
  }
13631
- openInnerEditor(target, select) {
13878
+ openInnerEditor(target, nameOrSelect, select) {
13879
+ let name;
13880
+ if (typeof nameOrSelect === 'string')
13881
+ name = nameOrSelect;
13882
+ else if (!select)
13883
+ select = nameOrSelect;
13632
13884
  if (target && select)
13633
13885
  this.target = target;
13634
13886
  if (this.single) {
13635
13887
  const editTarget = target || this.element;
13636
- const tag = editTarget.editInner;
13637
- if (tag && EditToolCreator.list[tag]) {
13888
+ name || (name = editTarget.editInner);
13889
+ if (name && EditToolCreator.list[name]) {
13638
13890
  this.editTool.unload();
13639
13891
  this.innerEditing = true;
13640
- this.innerEditor = this.editToolList[tag] || EditToolCreator.get(tag, this);
13892
+ this.innerEditor = this.editToolList[name] = this.editToolList[name] || EditToolCreator.get(name, this);
13641
13893
  this.innerEditor.editTarget = editTarget;
13642
13894
  this.emitInnerEvent(InnerEditorEvent.BEFORE_OPEN);
13643
13895
  this.innerEditor.load();
@@ -13645,13 +13897,14 @@ class Editor extends Group {
13645
13897
  }
13646
13898
  }
13647
13899
  }
13648
- closeInnerEditor() {
13900
+ closeInnerEditor(onlyInnerEditor) {
13649
13901
  if (this.innerEditing) {
13650
13902
  this.innerEditing = false;
13651
13903
  this.emitInnerEvent(InnerEditorEvent.BEFORE_CLOSE);
13652
13904
  this.innerEditor.unload();
13653
13905
  this.emitInnerEvent(InnerEditorEvent.CLOSE);
13654
- this.editTool.load();
13906
+ if (!onlyInnerEditor)
13907
+ this.updateEditTool();
13655
13908
  this.innerEditor = null;
13656
13909
  }
13657
13910
  }
@@ -13689,22 +13942,12 @@ class Editor extends Group {
13689
13942
  if (this.targetChanged)
13690
13943
  this.update();
13691
13944
  }
13692
- onKey(e) {
13693
- updateCursor(this, e);
13694
- }
13695
13945
  listenTargetEvents() {
13696
13946
  if (!this.targetEventIds.length) {
13697
- const { app, leafer, editBox, editMask } = this;
13947
+ const { app, leafer, editMask } = this;
13698
13948
  this.targetEventIds = [
13699
13949
  leafer.on_(RenderEvent.START, this.onRenderStart, this),
13700
- app.on_([
13701
- [RenderEvent.CHILD_START, this.onAppRenderStart, this],
13702
- [MoveEvent.BEFORE_MOVE, this.onMove, this, true],
13703
- [ZoomEvent.BEFORE_ZOOM, this.onScale, this, true],
13704
- [RotateEvent.BEFORE_ROTATE, this.onRotate, this, true],
13705
- [[KeyEvent.HOLD, KeyEvent.UP], this.onKey, this],
13706
- [KeyEvent.DOWN, editBox.onArrow, editBox]
13707
- ])
13950
+ app.on_(RenderEvent.CHILD_START, this.onAppRenderStart, this)
13708
13951
  ];
13709
13952
  if (editMask.visible)
13710
13953
  editMask.forceRender();
@@ -13728,7 +13971,7 @@ class Editor extends Group {
13728
13971
  super.destroy();
13729
13972
  }
13730
13973
  }
13731
- }
13974
+ };
13732
13975
  __decorate([
13733
13976
  mergeConfigAttr()
13734
13977
  ], Editor.prototype, "mergeConfig", void 0);
@@ -13738,14 +13981,19 @@ __decorate([
13738
13981
  __decorate([
13739
13982
  targetAttr(onTarget)
13740
13983
  ], Editor.prototype, "target", void 0);
13984
+ Editor = __decorate([
13985
+ useModule(TransformTool, ['editBox', 'editTool', 'emitEvent'])
13986
+ ], Editor);
13741
13987
 
13742
13988
  class InnerEditor {
13743
13989
  static registerInnerEditor() {
13744
13990
  EditToolCreator.register(this);
13745
13991
  }
13746
13992
  get tag() { return 'InnerEditor'; }
13993
+ get mode() { return 'focus'; }
13747
13994
  get editBox() { return this.editor.editBox; }
13748
13995
  constructor(editor) {
13996
+ this.eventIds = [];
13749
13997
  this.editor = editor;
13750
13998
  this.create();
13751
13999
  }
@@ -13758,7 +14006,7 @@ class InnerEditor {
13758
14006
  load() {
13759
14007
  const { editor } = this;
13760
14008
  if (editor) {
13761
- if (editor.app)
14009
+ if (editor.app && this.mode === 'focus')
13762
14010
  editor.selector.hittable = editor.app.tree.hitChildren = false;
13763
14011
  this.onLoad();
13764
14012
  }
@@ -13769,7 +14017,7 @@ class InnerEditor {
13769
14017
  unload() {
13770
14018
  const { editor } = this;
13771
14019
  if (editor) {
13772
- if (editor.app)
14020
+ if (editor.app && this.mode === 'focus')
13773
14021
  editor.selector.hittable = editor.app.tree.hitChildren = true;
13774
14022
  this.onUnload();
13775
14023
  }
@@ -13843,10 +14091,7 @@ let EditTool = class EditTool extends InnerEditor {
13843
14091
  this.onLoad();
13844
14092
  }
13845
14093
  update() {
13846
- const { editor, editBox } = this;
13847
- const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = editor.element.getLayoutBounds('box', editor, true);
13848
- editBox.set({ x, y, scaleX, scaleY, rotation, skewX, skewY });
13849
- editBox.update({ x: 0, y: 0, width, height });
14094
+ this.editBox.update();
13850
14095
  this.onUpdate();
13851
14096
  }
13852
14097
  unload() {
@@ -14190,7 +14435,7 @@ Creator.editor = function (options, app) {
14190
14435
  };
14191
14436
  Box.addAttr('textBox', false, dataType);
14192
14437
  UI.addAttr('editConfig', undefined, dataType);
14193
- UI.addAttr('editOuter', (ui) => ui.__.__isLinePath ? 'LineEditTool' : 'EditTool', dataType);
14438
+ UI.addAttr('editOuter', (ui) => { ui.updateLayout(); return ui.__.__isLinePath ? 'LineEditTool' : 'EditTool'; }, dataType);
14194
14439
  UI.addAttr('editInner', 'PathEditor', dataType);
14195
14440
  Group.addAttr('editInner', '', dataType);
14196
14441
  Text.addAttr('editInner', 'TextEditor', dataType);
@@ -14315,10 +14560,12 @@ let TextEditor = class TextEditor extends InnerEditor {
14315
14560
  ];
14316
14561
  this.onFocus = this.onFocus.bind(this);
14317
14562
  this.onInput = this.onInput.bind(this);
14563
+ this.onPaste = this.onPaste.bind(this);
14318
14564
  this.onUpdate = this.onUpdate.bind(this);
14319
14565
  this.onKeydown = this.onKeydown.bind(this);
14320
14566
  div.addEventListener("focus", this.onFocus);
14321
14567
  div.addEventListener("input", this.onInput);
14568
+ div.addEventListener("paste", this.onPaste);
14322
14569
  window.addEventListener('keydown', this.onKeydown);
14323
14570
  window.addEventListener('scroll', this.onUpdate);
14324
14571
  const selection = window.getSelection();
@@ -14348,15 +14595,43 @@ let TextEditor = class TextEditor extends InnerEditor {
14348
14595
  if (e.key === 'Enter') {
14349
14596
  e.preventDefault();
14350
14597
  const br = document.createElement('br');
14598
+ const zwsp = document.createTextNode('\u200B');
14351
14599
  const selection = window.getSelection();
14352
14600
  const range = selection.getRangeAt(0);
14353
14601
  range.deleteContents();
14602
+ range.insertNode(zwsp);
14354
14603
  range.insertNode(br);
14355
14604
  range.setStartAfter(br);
14356
14605
  range.setEndAfter(br);
14357
14606
  this.onInput();
14358
14607
  }
14359
14608
  }
14609
+ onPaste(event) {
14610
+ if (this.isHTMLText)
14611
+ return;
14612
+ event.preventDefault();
14613
+ const clipboardData = event.clipboardData;
14614
+ if (!clipboardData)
14615
+ return;
14616
+ let text = clipboardData.getData('text/plain').replace(/\r\n?/g, '\n');
14617
+ const selection = window.getSelection();
14618
+ if (!selection || !selection.rangeCount)
14619
+ return;
14620
+ const range = selection.getRangeAt(0);
14621
+ range.deleteContents();
14622
+ const lines = text.split('\n');
14623
+ const fragment = document.createDocumentFragment();
14624
+ lines.forEach((line, index) => {
14625
+ if (index > 0)
14626
+ fragment.appendChild(document.createElement('br'));
14627
+ fragment.appendChild(document.createTextNode(line));
14628
+ });
14629
+ range.insertNode(fragment);
14630
+ range.collapse(false);
14631
+ selection.removeAllRanges();
14632
+ selection.addRange(range);
14633
+ this.onInput();
14634
+ }
14360
14635
  onUpdate() {
14361
14636
  const { editTarget: text } = this;
14362
14637
  let textScale = 1;
@@ -14415,6 +14690,7 @@ let TextEditor = class TextEditor extends InnerEditor {
14415
14690
  editor.off_(this.eventIds);
14416
14691
  dom.removeEventListener("focus", this.onFocus);
14417
14692
  dom.removeEventListener("input", this.onInput);
14693
+ dom.removeEventListener("paste", this.onPaste);
14418
14694
  window.removeEventListener('keydown', this.onKeydown);
14419
14695
  window.removeEventListener('scroll', this.onUpdate);
14420
14696
  dom.remove();
@@ -14817,8 +15093,16 @@ function getFixBounds(bounds, scaleBounds) {
14817
15093
  }
14818
15094
 
14819
15095
  Plugin.add('view');
14820
- Leafer.prototype.zoom = function (zoomType, padding, fixed, transition) {
15096
+ Leafer.prototype.zoom = function (zoomType, optionsOrPadding, scroll, transition) {
14821
15097
  this.killAnimate();
15098
+ let padding;
15099
+ if (typeof optionsOrPadding === 'object' && !(optionsOrPadding instanceof Array)) {
15100
+ padding = optionsOrPadding.padding;
15101
+ scroll = optionsOrPadding.scroll;
15102
+ transition = optionsOrPadding.transition;
15103
+ }
15104
+ else
15105
+ padding = optionsOrPadding;
14822
15106
  const { zoomLayer } = this;
14823
15107
  const limitBounds = this.canvas.bounds.clone().shrink(padding !== undefined ? padding : 30), bounds = new Bounds();
14824
15108
  const center = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 };
@@ -14865,7 +15149,7 @@ Leafer.prototype.zoom = function (zoomType, padding, fixed, transition) {
14865
15149
  }
14866
15150
  const { width, height } = bounds;
14867
15151
  let moveX = limitBounds.x - bounds.x, moveY = limitBounds.y - bounds.y;
14868
- if (fixed) {
15152
+ if (scroll) {
14869
15153
  moveX += Math.max((limitBounds.width - width) / 2, 0);
14870
15154
  moveY += Math.max((limitBounds.height - height) / 2, 0);
14871
15155
  }
@@ -14878,6 +15162,10 @@ Leafer.prototype.zoom = function (zoomType, padding, fixed, transition) {
14878
15162
  data.scaleX *= changeScale;
14879
15163
  data.scaleY *= changeScale;
14880
15164
  }
15165
+ if (scroll === 'x')
15166
+ moveY = 0;
15167
+ else if (scroll === 'y')
15168
+ moveX = 0;
14881
15169
  PointHelper.move(data, moveX, moveY);
14882
15170
  bounds.move(moveX, moveY);
14883
15171
  zoomLayer.set(data, transition);
@@ -15043,6 +15331,11 @@ let HTMLText = class HTMLText extends Image {
15043
15331
  }
15044
15332
  super.__updateBoxBounds();
15045
15333
  }
15334
+ __draw(canvas, options, originCanvas) {
15335
+ if (this.textEditing && !options.exporting)
15336
+ return;
15337
+ super.__draw(canvas, options, originCanvas);
15338
+ }
15046
15339
  };
15047
15340
  __decorate([
15048
15341
  dataProcessor(HTMLTextData)
@@ -15053,6 +15346,9 @@ __decorate([
15053
15346
  __decorate([
15054
15347
  dataType('TextEditor')
15055
15348
  ], HTMLText.prototype, "editInner", void 0);
15349
+ __decorate([
15350
+ surfaceType(false)
15351
+ ], HTMLText.prototype, "textEditing", void 0);
15056
15352
  HTMLText = __decorate([
15057
15353
  registerUI()
15058
15354
  ], HTMLText);
@@ -15831,9 +16127,8 @@ box.__updateContentBounds = function () {
15831
16127
  }
15832
16128
  };
15833
16129
  box.__updateBoxBounds = function (secondLayout) {
15834
- const data = this.__;
15835
16130
  if (this.children.length && !this.pathInputed) {
15836
- const { flow } = data;
16131
+ const data = this.__, { flow } = data;
15837
16132
  if (data.__autoSide) {
15838
16133
  if (data.__hasSurface)
15839
16134
  this.__extraUpdate();
@@ -16065,6 +16360,11 @@ let Animate = class Animate extends Eventer {
16065
16360
  this.play();
16066
16361
  }, 0);
16067
16362
  }
16363
+ emitType(type) {
16364
+ this.emit(type, this);
16365
+ if (this.parent)
16366
+ this.parent.onChildEvent(type, this);
16367
+ }
16068
16368
  play() {
16069
16369
  if (this.destroyed)
16070
16370
  return;
@@ -16073,20 +16373,20 @@ let Animate = class Animate extends Eventer {
16073
16373
  this.clearTimer(), this.start();
16074
16374
  else if (!this.timer)
16075
16375
  this.requestAnimate();
16076
- this.emit(AnimateEvent.PLAY, this);
16376
+ this.emitType(AnimateEvent.PLAY);
16077
16377
  }
16078
16378
  pause() {
16079
16379
  if (this.destroyed)
16080
16380
  return;
16081
16381
  this.running = false;
16082
16382
  this.clearTimer();
16083
- this.emit(AnimateEvent.PAUSE, this);
16383
+ this.emitType(AnimateEvent.PAUSE);
16084
16384
  }
16085
16385
  stop() {
16086
16386
  if (this.destroyed)
16087
16387
  return;
16088
16388
  this.complete();
16089
- this.emit(AnimateEvent.STOP, this);
16389
+ this.emitType(AnimateEvent.STOP);
16090
16390
  }
16091
16391
  seek(time) {
16092
16392
  if (this.destroyed)
@@ -16100,7 +16400,7 @@ let Animate = class Animate extends Eventer {
16100
16400
  this.time = time;
16101
16401
  this.animate(0, true);
16102
16402
  this.clearTimer(() => this.requestAnimate());
16103
- this.emit(AnimateEvent.SEEK, this);
16403
+ this.emitType(AnimateEvent.SEEK);
16104
16404
  }
16105
16405
  kill(complete = true, killStyle) {
16106
16406
  this.killStyle = killStyle;
@@ -16167,7 +16467,7 @@ let Animate = class Animate extends Eventer {
16167
16467
  if (totalTime)
16168
16468
  this.changeDuration(totalTime);
16169
16469
  }
16170
- this.emit(AnimateEvent.CREATED, this);
16470
+ this.emitType(AnimateEvent.CREATED);
16171
16471
  }
16172
16472
  changeDuration(duration) {
16173
16473
  const { config } = this;
@@ -16287,7 +16587,7 @@ let Animate = class Animate extends Eventer {
16287
16587
  key in killStyle || (style[key] = endingStyle[key]);
16288
16588
  this.setStyle(style);
16289
16589
  this.clearTimer();
16290
- this.emit(AnimateEvent.COMPLETED, this);
16590
+ this.emitType(AnimateEvent.COMPLETED);
16291
16591
  }
16292
16592
  setFrom() {
16293
16593
  this.nowIndex = 0;
@@ -16331,7 +16631,7 @@ let Animate = class Animate extends Eventer {
16331
16631
  Transition.setBetweenStyle(betweenStyle, fromStyle, toStyle, style, t, target, attrsMap);
16332
16632
  this.setStyle(betweenStyle);
16333
16633
  }
16334
- this.emit(AnimateEvent.UPDATE, this);
16634
+ this.emitType(AnimateEvent.UPDATE);
16335
16635
  }
16336
16636
  setStyle(style) {
16337
16637
  const { target } = this;
@@ -16375,7 +16675,7 @@ let Animate = class Animate extends Eventer {
16375
16675
  this.stop();
16376
16676
  else
16377
16677
  this.pause();
16378
- this.target = this.config = this.frames = this.fromStyle = this.toStyle = this.style = this.killStyle = null;
16678
+ this.target = this.parent = this.config = this.frames = this.fromStyle = this.toStyle = this.style = this.killStyle = null;
16379
16679
  this.destroyed = true;
16380
16680
  }
16381
16681
  }
@@ -16441,6 +16741,7 @@ let AnimateList = class AnimateList extends Animate {
16441
16741
  });
16442
16742
  this.list = animation.map(item => {
16443
16743
  const animate = item.target ? item : new Animate(this.target, item, isTemp);
16744
+ animate.parent = this;
16444
16745
  Object.assign(this.fromStyle, animate.fromStyle);
16445
16746
  Object.assign(this.toStyle, animate.toStyle);
16446
16747
  Object.assign(this._endingStyle, animate.endingStyle);
@@ -16449,20 +16750,34 @@ let AnimateList = class AnimateList extends Animate {
16449
16750
  }
16450
16751
  play() {
16451
16752
  this.each(item => item.play());
16753
+ this.emitType(AnimateEvent.PLAY);
16452
16754
  }
16453
16755
  pause() {
16454
16756
  this.each(item => item.pause());
16757
+ this.emitType(AnimateEvent.PAUSE);
16455
16758
  }
16456
16759
  stop() {
16457
16760
  this.each(item => item.stop());
16761
+ this.emitType(AnimateEvent.STOP);
16458
16762
  }
16459
16763
  seek(time) {
16460
16764
  this.each(item => item.seek(time));
16765
+ this.emitType(AnimateEvent.SEEK);
16461
16766
  }
16462
16767
  kill(complete, killStyle) {
16463
16768
  this.each(item => item.kill(complete, killStyle));
16464
16769
  this.destroy();
16465
16770
  }
16771
+ onChildEvent(type, _animate) {
16772
+ switch (type) {
16773
+ case AnimateEvent.COMPLETED:
16774
+ if (this.completed)
16775
+ this.emitType(type);
16776
+ break;
16777
+ case AnimateEvent.UPDATE:
16778
+ this.emitType(type);
16779
+ }
16780
+ }
16466
16781
  each(func) {
16467
16782
  this.list.forEach(func);
16468
16783
  }
@@ -17921,123 +18236,131 @@ function getTrimBounds(canvas) {
17921
18236
  index++;
17922
18237
  }
17923
18238
  const bounds = new Bounds();
17924
- toBounds(pointBounds, bounds);
17925
- return bounds.scale(1 / canvas.pixelRatio).ceil();
18239
+ if (pointBounds) {
18240
+ toBounds(pointBounds, bounds);
18241
+ bounds.scale(1 / canvas.pixelRatio).ceil();
18242
+ }
18243
+ return bounds;
17926
18244
  }
17927
18245
 
17928
18246
  const ExportModule = {
17929
18247
  syncExport(leaf, filename, options) {
17930
- this.running = true;
18248
+ Export.running = true;
17931
18249
  let result;
17932
- const fileType = FileHelper.fileType(filename);
17933
- const isDownload = filename.includes('.');
17934
- options = FileHelper.getExportOptions(options);
17935
- const { toURL } = Platform;
17936
- const { download } = Platform.origin;
17937
- if (fileType === 'json') {
17938
- isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
17939
- result = { data: isDownload ? true : leaf.toJSON(options.json) };
17940
- }
17941
- else if (fileType === 'svg') {
17942
- isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
17943
- result = { data: isDownload ? true : leaf.toSVG() };
17944
- }
17945
- else {
17946
- let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
17947
- const { worldTransform, isLeafer, leafer, isFrame } = leaf;
17948
- const { slice, clip, trim, screenshot, padding, onCanvas } = options;
17949
- const smooth = options.smooth === undefined ? (leafer ? leafer.config.smooth : true) : options.smooth;
17950
- const contextSettings = options.contextSettings || (leafer ? leafer.config.contextSettings : undefined);
17951
- const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
17952
- const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
17953
- if (screenshot) {
17954
- renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
18250
+ try {
18251
+ const fileType = FileHelper.fileType(filename);
18252
+ const isDownload = filename.includes('.');
18253
+ options = FileHelper.getExportOptions(options);
18254
+ const { toURL } = Platform;
18255
+ const { download } = Platform.origin;
18256
+ if (fileType === 'json') {
18257
+ isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
18258
+ result = { data: isDownload ? true : leaf.toJSON(options.json) };
18259
+ }
18260
+ else if (fileType === 'svg') {
18261
+ isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
18262
+ result = { data: isDownload ? true : leaf.toSVG() };
17955
18263
  }
17956
18264
  else {
17957
- let relative = options.relative || (isLeafer ? 'inner' : 'local');
17958
- scaleX = worldTransform.scaleX;
17959
- scaleY = worldTransform.scaleY;
17960
- switch (relative) {
17961
- case 'inner':
17962
- matrix.set(worldTransform);
17963
- break;
17964
- case 'local':
17965
- matrix.set(worldTransform).divide(leaf.localTransform);
17966
- scaleX /= leaf.scaleX;
17967
- scaleY /= leaf.scaleY;
17968
- break;
17969
- case 'world':
17970
- scaleX = 1;
17971
- scaleY = 1;
17972
- break;
17973
- case 'page':
17974
- relative = leafer || leaf;
17975
- default:
17976
- matrix.set(worldTransform).divide(leaf.getTransform(relative));
17977
- const l = relative.worldTransform;
17978
- scaleX /= scaleX / l.scaleX;
17979
- scaleY /= scaleY / l.scaleY;
18265
+ let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
18266
+ const { worldTransform, isLeafer, leafer, isFrame } = leaf;
18267
+ const { slice, clip, trim, screenshot, padding, onCanvas } = options;
18268
+ const smooth = options.smooth === undefined ? (leafer ? leafer.config.smooth : true) : options.smooth;
18269
+ const contextSettings = options.contextSettings || (leafer ? leafer.config.contextSettings : undefined);
18270
+ const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
18271
+ const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
18272
+ if (screenshot) {
18273
+ renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
17980
18274
  }
17981
- renderBounds = leaf.getBounds('render', relative);
17982
- }
17983
- const scaleData = { scaleX: 1, scaleY: 1 };
17984
- MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
17985
- let pixelRatio = options.pixelRatio || 1;
17986
- let { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
17987
- if (clip)
17988
- x += clip.x, y += clip.y, width = clip.width, height = clip.height;
17989
- const renderOptions = { exporting: true, matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
17990
- let canvas = Creator.canvas({ width: Math.floor(width), height: Math.floor(height), pixelRatio, smooth, contextSettings });
17991
- let sliceLeaf;
17992
- if (slice) {
17993
- sliceLeaf = leaf;
17994
- sliceLeaf.__worldOpacity = 0;
17995
- leaf = leafer || leaf;
17996
- renderOptions.bounds = canvas.bounds;
17997
- }
17998
- canvas.save();
17999
- if (isFrame && fill !== undefined) {
18000
- const oldFill = leaf.get('fill');
18001
- leaf.fill = '';
18002
- leaf.__render(canvas, renderOptions);
18003
- leaf.fill = oldFill;
18004
- }
18005
- else {
18006
- leaf.__render(canvas, renderOptions);
18007
- }
18008
- canvas.restore();
18009
- if (sliceLeaf)
18010
- sliceLeaf.__updateWorldOpacity();
18011
- if (trim) {
18012
- trimBounds = getTrimBounds(canvas);
18013
- const old = canvas, { width, height } = trimBounds;
18014
- const config = { x: 0, y: 0, width, height, pixelRatio };
18015
- canvas = Creator.canvas(config);
18016
- canvas.copyWorld(old, trimBounds, config);
18275
+ else {
18276
+ let relative = options.relative || (isLeafer ? 'inner' : 'local');
18277
+ scaleX = worldTransform.scaleX;
18278
+ scaleY = worldTransform.scaleY;
18279
+ switch (relative) {
18280
+ case 'inner':
18281
+ matrix.set(worldTransform);
18282
+ break;
18283
+ case 'local':
18284
+ matrix.set(worldTransform).divide(leaf.localTransform);
18285
+ scaleX /= leaf.scaleX;
18286
+ scaleY /= leaf.scaleY;
18287
+ break;
18288
+ case 'world':
18289
+ scaleX = 1;
18290
+ scaleY = 1;
18291
+ break;
18292
+ case 'page':
18293
+ relative = leafer || leaf;
18294
+ default:
18295
+ matrix.set(worldTransform).divide(leaf.getTransform(relative));
18296
+ const l = relative.worldTransform;
18297
+ scaleX /= scaleX / l.scaleX;
18298
+ scaleY /= scaleY / l.scaleY;
18299
+ }
18300
+ renderBounds = leaf.getBounds('render', relative);
18301
+ }
18302
+ const scaleData = { scaleX: 1, scaleY: 1 };
18303
+ MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
18304
+ let pixelRatio = options.pixelRatio || 1;
18305
+ let { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
18306
+ if (clip)
18307
+ x += clip.x, y += clip.y, width = clip.width, height = clip.height;
18308
+ const renderOptions = { exporting: true, matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
18309
+ let canvas = Creator.canvas({ width: Math.floor(width), height: Math.floor(height), pixelRatio, smooth, contextSettings });
18310
+ let sliceLeaf;
18311
+ if (slice) {
18312
+ sliceLeaf = leaf;
18313
+ sliceLeaf.__worldOpacity = 0;
18314
+ leaf = leafer || leaf;
18315
+ renderOptions.bounds = canvas.bounds;
18316
+ }
18317
+ canvas.save();
18318
+ if (isFrame && fill !== undefined) {
18319
+ const oldFill = leaf.get('fill');
18320
+ leaf.fill = '';
18321
+ leaf.__render(canvas, renderOptions);
18322
+ leaf.fill = oldFill;
18323
+ }
18324
+ else {
18325
+ leaf.__render(canvas, renderOptions);
18326
+ }
18327
+ canvas.restore();
18328
+ if (sliceLeaf)
18329
+ sliceLeaf.__updateWorldOpacity();
18330
+ if (trim) {
18331
+ trimBounds = getTrimBounds(canvas);
18332
+ const old = canvas, { width, height } = trimBounds;
18333
+ const config = { x: 0, y: 0, width, height, pixelRatio };
18334
+ canvas = Creator.canvas(config);
18335
+ canvas.copyWorld(old, trimBounds, config);
18336
+ }
18337
+ if (padding) {
18338
+ const [top, right, bottom, left] = MathHelper.fourNumber(padding);
18339
+ const old = canvas, { width, height } = old;
18340
+ canvas = Creator.canvas({ width: width + left + right, height: height + top + bottom, pixelRatio });
18341
+ canvas.copyWorld(old, old.bounds, { x: left, y: top, width, height });
18342
+ }
18343
+ if (needFill)
18344
+ canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
18345
+ if (onCanvas)
18346
+ onCanvas(canvas);
18347
+ const data = filename === 'canvas' ? canvas : canvas.export(filename, options);
18348
+ result = { data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds };
18017
18349
  }
18018
- if (padding) {
18019
- const [top, right, bottom, left] = MathHelper.fourNumber(padding);
18020
- const old = canvas, { width, height } = old;
18021
- canvas = Creator.canvas({ width: width + left + right, height: height + top + bottom, pixelRatio });
18022
- canvas.copyWorld(old, old.bounds, { x: left, y: top, width, height });
18023
- }
18024
- if (needFill)
18025
- canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
18026
- if (onCanvas)
18027
- onCanvas(canvas);
18028
- const data = filename === 'canvas' ? canvas : canvas.export(filename, options);
18029
- result = { data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds };
18030
18350
  }
18031
- this.running = false;
18351
+ catch (error) {
18352
+ result = { data: '', error };
18353
+ }
18354
+ Export.running = false;
18032
18355
  return result;
18033
18356
  },
18034
18357
  export(leaf, filename, options) {
18035
- this.running = true;
18358
+ Export.running = true;
18036
18359
  return addTask((success) => new Promise((resolve) => {
18037
18360
  const getResult = () => __awaiter(this, void 0, void 0, function* () {
18038
18361
  if (!Resource.isComplete)
18039
18362
  return Platform.requestRender(getResult);
18040
- const result = ExportModule.syncExport(leaf, filename, options);
18363
+ const result = Export.syncExport(leaf, filename, options);
18041
18364
  if (result.data instanceof Promise)
18042
18365
  result.data = yield result.data;
18043
18366
  success(result);
@@ -18137,4 +18460,4 @@ Object.assign(Filter, {
18137
18460
  }
18138
18461
  });
18139
18462
 
18140
- 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, HTMLText, HTMLTextData, HighBezierHelper, HighCurveHelper, HitCanvasManager, Image, ImageData, ImageEvent, ImageManager, IncrementId, InnerEditor, InnerEditorEvent, 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, TextEditor, 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 };
18463
+ 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, HTMLText, HTMLTextData, HighBezierHelper, HighCurveHelper, HitCanvasManager, Image, ImageData, ImageEvent, ImageManager, IncrementId, InnerEditor, InnerEditorEvent, 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, TextEditor, 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, createAttr, createDescriptor, 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$1 as tempMatrix, tempPoint$3 as tempPoint, useCanvas, useModule, version, visibleType, zoomLayerType };