@leafer/miniapp 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 false; }
@@ -7220,6 +7275,11 @@ function zoomLayerType() {
7220
7275
  });
7221
7276
  };
7222
7277
  }
7278
+ function createAttr(defaultValue) {
7279
+ return (target, key) => {
7280
+ defineKey(target, key, createDescriptor(key, defaultValue));
7281
+ };
7282
+ }
7223
7283
 
7224
7284
  function hasTransparent$3(color) {
7225
7285
  if (!color || color.length === 7 || color.length === 4)
@@ -7277,26 +7337,9 @@ const emptyPaint = {};
7277
7337
  const debug$5 = Debug.get('UIData');
7278
7338
  class UIData extends LeafData {
7279
7339
  get scale() { const { scaleX, scaleY } = this; return scaleX !== scaleY ? { x: scaleX, y: scaleY } : scaleX; }
7280
- get __strokeWidth() {
7281
- const { strokeWidth, strokeWidthFixed } = this;
7282
- if (strokeWidthFixed) {
7283
- const ui = this.__leaf;
7284
- let { scaleX } = ui.__nowWorld || ui.__world;
7285
- if (scaleX < 0)
7286
- scaleX = -scaleX;
7287
- return scaleX > 1 ? strokeWidth / scaleX : strokeWidth;
7288
- }
7289
- else
7290
- return strokeWidth;
7291
- }
7292
- get __hasStroke() { return this.stroke && this.strokeWidth; }
7293
- get __hasHalf() { const t = this; return (t.stroke && t.strokeAlign === 'center' && t.strokeWidth % 2) || undefined; }
7294
- get __hasMultiPaint() {
7295
- const t = this;
7296
- if ((t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect)
7297
- return true;
7298
- return t.fill && this.__hasStroke;
7299
- }
7340
+ get __strokeWidth() { return this.__getRealStrokeWidth(); }
7341
+ get __maxStrokeWidth() { const t = this; return t.__hasMultiStrokeStyle ? Math.max(t.__hasMultiStrokeStyle, t.strokeWidth) : t.strokeWidth; }
7342
+ get __hasMultiPaint() { const t = this; return (t.fill && this.__useStroke) || (t.__isFills && t.fill.length > 1) || (t.__isStrokes && t.stroke.length > 1) || t.__useEffect; }
7300
7343
  get __clipAfterFill() { const t = this; return (t.cornerRadius || t.innerShadow || t.__pathInputed); }
7301
7344
  get __hasSurface() { const t = this; return (t.fill || t.stroke); }
7302
7345
  get __autoWidth() { return !this._width; }
@@ -7378,6 +7421,21 @@ class UIData extends LeafData {
7378
7421
  Paint.compute('stroke', this.__leaf);
7379
7422
  this.__needComputePaint = undefined;
7380
7423
  }
7424
+ __getRealStrokeWidth(childStyle) {
7425
+ let { strokeWidth, strokeWidthFixed } = this;
7426
+ if (childStyle) {
7427
+ if (childStyle.strokeWidth)
7428
+ strokeWidth = childStyle.strokeWidth;
7429
+ if (childStyle.strokeWidthFixed !== undefined)
7430
+ strokeWidthFixed = childStyle.strokeWidthFixed;
7431
+ }
7432
+ if (strokeWidthFixed) {
7433
+ const scale = this.__leaf.getClampRenderScale();
7434
+ return scale > 1 ? strokeWidth / scale : strokeWidth;
7435
+ }
7436
+ else
7437
+ return strokeWidth;
7438
+ }
7381
7439
  __setPaint(attrName, value) {
7382
7440
  this.__setInput(attrName, value);
7383
7441
  const layout = this.__leaf.__layout;
@@ -7402,6 +7460,7 @@ class UIData extends LeafData {
7402
7460
  }
7403
7461
  else {
7404
7462
  stintSet$2(this, '__isAlphaPixelStroke', undefined);
7463
+ stintSet$2(this, '__hasMultiStrokeStyle', undefined);
7405
7464
  this._stroke = this.__isStrokes = undefined;
7406
7465
  }
7407
7466
  }
@@ -7423,8 +7482,8 @@ class GroupData extends UIData {
7423
7482
 
7424
7483
  class BoxData extends GroupData {
7425
7484
  get __boxStroke() { return !this.__pathInputed; }
7426
- get __drawAfterFill() { const t = this; return (t.overflow === 'hide' && (t.__clipAfterFill || t.innerShadow) && t.__leaf.children.length); }
7427
- get __clipAfterFill() { return this.__leaf.isOverflow || super.__clipAfterFill; }
7485
+ get __drawAfterFill() { const t = this; return t.__single || t.__clipAfterFill; }
7486
+ get __clipAfterFill() { const t = this; return t.overflow === 'hide' && t.__leaf.children.length && (t.__leaf.isOverflow || super.__clipAfterFill); }
7428
7487
  }
7429
7488
 
7430
7489
  class LeaferData extends GroupData {
@@ -7544,7 +7603,7 @@ class CanvasData extends RectData {
7544
7603
  const UIBounds = {
7545
7604
  __updateStrokeSpread() {
7546
7605
  let width = 0, boxWidth = 0;
7547
- const data = this.__, { strokeAlign, strokeWidth } = data, box = this.__box;
7606
+ const data = this.__, { strokeAlign, __maxStrokeWidth: strokeWidth } = data, box = this.__box;
7548
7607
  if ((data.stroke || data.hitStroke === 'all') && strokeWidth && strokeAlign !== 'inside') {
7549
7608
  boxWidth = width = strokeAlign === 'center' ? strokeWidth / 2 : strokeWidth;
7550
7609
  if (!data.__boxStroke) {
@@ -7564,13 +7623,15 @@ const UIBounds = {
7564
7623
  },
7565
7624
  __updateRenderSpread() {
7566
7625
  let width = 0;
7567
- const { shadow, innerShadow, blur, backgroundBlur, filter } = this.__;
7626
+ const { shadow, innerShadow, blur, backgroundBlur, filter, renderSpread } = this.__;
7568
7627
  if (shadow)
7569
7628
  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));
7570
7629
  if (blur)
7571
7630
  width = Math.max(width, blur);
7572
7631
  if (filter)
7573
7632
  width += Filter.getSpread(filter);
7633
+ if (renderSpread)
7634
+ width += renderSpread;
7574
7635
  let shapeWidth = width = Math.ceil(width);
7575
7636
  if (innerShadow)
7576
7637
  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));
@@ -7586,15 +7647,18 @@ const { stintSet: stintSet$1 } = DataHelper;
7586
7647
  const UIRender = {
7587
7648
  __updateChange() {
7588
7649
  const data = this.__;
7650
+ if (data.__useStroke) {
7651
+ const useStroke = data.__useStroke = !!(data.stroke && data.strokeWidth);
7652
+ stintSet$1(this.__world, 'half', useStroke && data.strokeAlign === 'center' && data.strokeWidth % 2);
7653
+ stintSet$1(data, '__fillAfterStroke', useStroke && data.strokeAlign === 'outside' && data.fill && !data.__isTransparentFill);
7654
+ }
7589
7655
  if (data.__useEffect) {
7590
7656
  const { shadow, fill, stroke } = data, otherEffect = data.innerShadow || data.blur || data.backgroundBlur || data.filter;
7591
- 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')));
7657
+ 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')));
7592
7658
  data.__useEffect = !!(shadow || otherEffect);
7593
7659
  }
7594
- stintSet$1(this.__world, 'half', data.__hasHalf);
7595
- stintSet$1(data, '__fillAfterStroke', data.stroke && data.strokeAlign === 'outside' && data.fill && !data.__isTransparentFill);
7596
7660
  data.__checkSingle();
7597
- stintSet$1(data, '__complex', data.__isFills || data.__isStrokes || data.cornerRadius || data.__useEffect);
7661
+ stintSet$1(data, '__complex', (data.__isFills || data.__isStrokes || data.cornerRadius || data.__useEffect));
7598
7662
  },
7599
7663
  __drawFast(canvas, options) {
7600
7664
  drawFast(this, canvas, options);
@@ -7652,18 +7716,15 @@ const UIRender = {
7652
7716
  this.__drawFast(canvas, options);
7653
7717
  }
7654
7718
  },
7655
- __renderShape(canvas, options, ignoreFill, ignoreStroke) {
7656
- if (this.__worldOpacity) {
7657
- canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
7658
- const { fill, stroke } = this.__;
7659
- this.__drawRenderPath(canvas);
7660
- if (fill && !ignoreFill)
7661
- this.__.__isAlphaPixelFill ? Paint.fills(fill, this, canvas) : Paint.fill('#000000', this, canvas);
7662
- if (this.__.__isCanvas)
7663
- this.__drawAfterFill(canvas, options);
7664
- if (stroke && !ignoreStroke)
7665
- this.__.__isAlphaPixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
7666
- }
7719
+ __drawShape(canvas, options) {
7720
+ this.__drawRenderPath(canvas);
7721
+ const data = this.__, { fill, stroke } = data;
7722
+ if (fill && !options.ignoreFill)
7723
+ data.__isAlphaPixelFill ? Paint.fills(fill, this, canvas) : Paint.fill('#000000', this, canvas);
7724
+ if (data.__isCanvas)
7725
+ this.__drawAfterFill(canvas, options);
7726
+ if (stroke && !options.ignoreStroke)
7727
+ data.__isAlphaPixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
7667
7728
  },
7668
7729
  __drawAfterFill(canvas, options) {
7669
7730
  if (this.__.__clipAfterFill) {
@@ -7700,17 +7761,17 @@ const RectRender = {
7700
7761
  if (__drawAfterFill)
7701
7762
  this.__drawAfterFill(canvas, options);
7702
7763
  if (stroke) {
7703
- const { strokeAlign, __strokeWidth } = this.__;
7704
- if (!__strokeWidth)
7764
+ const { strokeAlign, __strokeWidth: strokeWidth } = this.__;
7765
+ if (!strokeWidth)
7705
7766
  return;
7706
- canvas.setStroke(stroke, __strokeWidth, this.__);
7707
- const half = __strokeWidth / 2;
7767
+ canvas.setStroke(stroke, strokeWidth, this.__);
7768
+ const half = strokeWidth / 2;
7708
7769
  switch (strokeAlign) {
7709
7770
  case 'center':
7710
7771
  canvas.strokeRect(0, 0, width, height);
7711
7772
  break;
7712
7773
  case 'inside':
7713
- width -= __strokeWidth, height -= __strokeWidth;
7774
+ width -= strokeWidth, height -= strokeWidth;
7714
7775
  if (width < 0 || height < 0) {
7715
7776
  canvas.save();
7716
7777
  this.__clip(canvas, options);
@@ -7721,7 +7782,7 @@ const RectRender = {
7721
7782
  canvas.strokeRect(x + half, y + half, width, height);
7722
7783
  break;
7723
7784
  case 'outside':
7724
- canvas.strokeRect(x - half, y - half, width + __strokeWidth, height + __strokeWidth);
7785
+ canvas.strokeRect(x - half, y - half, width + strokeWidth, height + strokeWidth);
7725
7786
  break;
7726
7787
  }
7727
7788
  }
@@ -7734,6 +7795,8 @@ let UI = UI_1 = class UI extends Leaf {
7734
7795
  get isFrame() { return false; }
7735
7796
  set scale(value) { MathHelper.assignScale(this, value); }
7736
7797
  get scale() { return this.__.scale; }
7798
+ get isAutoWidth() { const t = this.__; return t.__autoWidth || t.autoWidth; }
7799
+ get isAutoHeight() { const t = this.__; return t.__autoHeight || t.autoHeight; }
7737
7800
  get pen() {
7738
7801
  const { path } = this.__;
7739
7802
  pen.set(this.path = path || []);
@@ -7788,12 +7851,14 @@ let UI = UI_1 = class UI extends Leaf {
7788
7851
  }
7789
7852
  }
7790
7853
  __updateRenderPath() {
7791
- if (this.__.path) {
7792
- const data = this.__;
7854
+ const data = this.__;
7855
+ if (data.path) {
7793
7856
  data.__pathForRender = data.cornerRadius ? PathCorner.smooth(data.path, data.cornerRadius, data.cornerSmoothing) : data.path;
7794
7857
  if (data.__useArrow)
7795
7858
  PathArrow.addArrows(this, !data.cornerRadius);
7796
7859
  }
7860
+ else
7861
+ data.__pathForRender && (data.__pathForRender = undefined);
7797
7862
  }
7798
7863
  __drawRenderPath(canvas) {
7799
7864
  canvas.beginPath();
@@ -7946,6 +8011,9 @@ __decorate([
7946
8011
  __decorate([
7947
8012
  naturalBoundsType(1)
7948
8013
  ], UI.prototype, "pixelRatio", void 0);
8014
+ __decorate([
8015
+ affectRenderBoundsType(0)
8016
+ ], UI.prototype, "renderSpread", void 0);
7949
8017
  __decorate([
7950
8018
  pathInputType()
7951
8019
  ], UI.prototype, "path", void 0);
@@ -8004,13 +8072,13 @@ __decorate([
8004
8072
  surfaceType()
8005
8073
  ], UI.prototype, "fill", void 0);
8006
8074
  __decorate([
8007
- strokeType()
8075
+ strokeType(undefined, true)
8008
8076
  ], UI.prototype, "stroke", void 0);
8009
8077
  __decorate([
8010
8078
  strokeType('inside')
8011
8079
  ], UI.prototype, "strokeAlign", void 0);
8012
8080
  __decorate([
8013
- strokeType(1)
8081
+ strokeType(1, true)
8014
8082
  ], UI.prototype, "strokeWidth", void 0);
8015
8083
  __decorate([
8016
8084
  strokeType(false)
@@ -8102,7 +8170,8 @@ let Group = class Group extends UI {
8102
8170
  }
8103
8171
  toJSON(options) {
8104
8172
  const data = super.toJSON(options);
8105
- data.children = this.children.map(child => child.toJSON(options));
8173
+ if (!this.childlessJSON)
8174
+ data.children = this.children.map(child => child.toJSON(options));
8106
8175
  return data;
8107
8176
  }
8108
8177
  pick(_hitPoint, _options) { return undefined; }
@@ -8437,7 +8506,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
8437
8506
  list.push(item);
8438
8507
  this.requestRender();
8439
8508
  }
8440
- zoom(_zoomType, _padding, _fixedScale, _transition) {
8509
+ zoom(_zoomType, _optionsOrPadding, _scroll, _transition) {
8441
8510
  return Plugin.need('view');
8442
8511
  }
8443
8512
  getValidMove(moveX, moveY) { return { x: moveX, y: moveY }; }
@@ -8482,7 +8551,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
8482
8551
  Leafer_1.list.remove(this);
8483
8552
  try {
8484
8553
  this.stop();
8485
- this.emitEvent(new LeaferEvent(LeaferEvent.END, this));
8554
+ this.emitLeafer(LeaferEvent.END);
8486
8555
  this.__removeListenEvents();
8487
8556
  this.__controllers.forEach(item => !(this.parent && item === this.interaction) && item.destroy());
8488
8557
  this.__controllers.length = 0;
@@ -8549,8 +8618,8 @@ let Box = class Box extends Group {
8549
8618
  __updateRenderSpread() { return this.__updateRectRenderSpread() || -1; }
8550
8619
  __updateRectBoxBounds() { }
8551
8620
  __updateBoxBounds(_secondLayout) {
8552
- const data = this.__;
8553
8621
  if (this.children.length && !this.pathInputed) {
8622
+ const data = this.__;
8554
8623
  if (data.__autoSide) {
8555
8624
  if (data.__hasSurface)
8556
8625
  this.__extraUpdate();
@@ -8577,20 +8646,26 @@ let Box = class Box extends Group {
8577
8646
  __updateStrokeBounds() { }
8578
8647
  __updateRenderBounds() {
8579
8648
  let isOverflow;
8580
- const { renderBounds } = this.__layout;
8581
8649
  if (this.children.length) {
8650
+ const data = this.__, { renderBounds, boxBounds } = this.__layout;
8582
8651
  super.__updateRenderBounds();
8583
8652
  copy$6(childrenRenderBounds, renderBounds);
8584
8653
  this.__updateRectRenderBounds();
8585
- isOverflow = !includes$1(renderBounds, childrenRenderBounds);
8586
- if (isOverflow && this.__.overflow !== 'hide')
8654
+ if (data.scrollY || data.scrollX) {
8655
+ childrenRenderBounds.x += data.scrollX;
8656
+ childrenRenderBounds.y += data.scrollY;
8657
+ }
8658
+ isOverflow = !includes$1(boxBounds, childrenRenderBounds);
8659
+ if (isOverflow && data.overflow !== 'hide')
8587
8660
  add(renderBounds, childrenRenderBounds);
8588
8661
  }
8589
8662
  else
8590
8663
  this.__updateRectRenderBounds();
8591
8664
  DataHelper.stintSet(this, 'isOverflow', isOverflow);
8665
+ this.__updateScrollBar();
8592
8666
  }
8593
8667
  __updateRectRenderBounds() { }
8668
+ __updateScrollBar() { }
8594
8669
  __updateRectChange() { }
8595
8670
  __updateChange() {
8596
8671
  super.__updateChange();
@@ -8607,10 +8682,12 @@ let Box = class Box extends Group {
8607
8682
  if (this.children.length)
8608
8683
  this.__renderGroup(canvas, options);
8609
8684
  }
8685
+ if (this.scrollBar)
8686
+ this.scrollBar.__render(canvas, options);
8610
8687
  }
8611
8688
  __drawContent(canvas, options) {
8612
8689
  this.__renderGroup(canvas, options);
8613
- if (this.__.__hasStroke) {
8690
+ if (this.__.__useStroke || this.__.__useEffect) {
8614
8691
  canvas.setWorld(this.__nowWorld);
8615
8692
  this.__drawRenderPath(canvas);
8616
8693
  }
@@ -8830,8 +8907,8 @@ let Polygon = class Polygon extends UI {
8830
8907
  for (let i = 1; i < sides; i++) {
8831
8908
  lineTo$1(path, rx + rx * sin$2((i * 2 * PI$2) / sides), ry - ry * cos$2((i * 2 * PI$2) / sides));
8832
8909
  }
8910
+ closePath$1(path);
8833
8911
  }
8834
- closePath$1(path);
8835
8912
  }
8836
8913
  __updateRenderPath() { }
8837
8914
  __updateBoxBounds() { }
@@ -9069,6 +9146,11 @@ let Text = class Text extends UI {
9069
9146
  return;
9070
9147
  super.__draw(canvas, options, originCanvas);
9071
9148
  }
9149
+ __drawShape(canvas, options) {
9150
+ if (options.shape)
9151
+ this.__box && this.__box.__drawShape(canvas, options);
9152
+ super.__drawShape(canvas, options);
9153
+ }
9072
9154
  destroy() {
9073
9155
  if (this.boxStyle)
9074
9156
  this.boxStyle = null;
@@ -9890,6 +9972,7 @@ const config$1 = {
9890
9972
  delta: { x: 80 / 4, y: 8.0 },
9891
9973
  },
9892
9974
  pointer: {
9975
+ type: 'pointer',
9893
9976
  snap: true,
9894
9977
  hitRadius: 5,
9895
9978
  tapTime: 120,
@@ -10407,18 +10490,20 @@ leaf$1.__hitWorld = function (point) {
10407
10490
  }
10408
10491
  return this.__hit(inner);
10409
10492
  };
10410
- leaf$1.__hitFill = function (inner) { var _a; return (_a = this.__hitCanvas) === null || _a === void 0 ? void 0 : _a.hitFill(inner, this.__.windingRule); };
10411
- leaf$1.__hitStroke = function (inner, strokeWidth) { var _a; return (_a = this.__hitCanvas) === null || _a === void 0 ? void 0 : _a.hitStroke(inner, strokeWidth); };
10412
- 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); };
10413
- leaf$1.__drawHitPath = function (canvas) { if (canvas)
10414
- this.__drawRenderPath(canvas); };
10493
+ leaf$1.__hitFill = function (inner) { const h = this.__hitCanvas; return h && h.hitFill(inner, this.__.windingRule); };
10494
+ leaf$1.__hitStroke = function (inner, strokeWidth) { const h = this.__hitCanvas; return h && h.hitStroke(inner, strokeWidth); };
10495
+ leaf$1.__hitPixel = function (inner) { const h = this.__hitCanvas; return h && h.hitPixel(inner, this.__layout.renderBounds, h.hitScale); };
10496
+ leaf$1.__drawHitPath = function (canvas) { canvas && this.__drawRenderPath(canvas); };
10415
10497
 
10416
10498
  const matrix$2 = new Matrix();
10417
10499
  const ui$5 = UI.prototype;
10418
10500
  ui$5.__updateHitCanvas = function () {
10419
10501
  if (this.__box)
10420
10502
  this.__box.__updateHitCanvas();
10421
- const data = this.__, { hitCanvasManager } = this.leafer || this.parent.leafer;
10503
+ const leafer = this.leafer || (this.parent && this.parent.leafer);
10504
+ if (!leafer)
10505
+ return;
10506
+ const data = this.__, { hitCanvasManager } = leafer;
10422
10507
  const isHitPixelFill = (data.__isAlphaPixelFill || data.__isCanvas) && data.hitFill === 'pixel';
10423
10508
  const isHitPixelStroke = data.__isAlphaPixelStroke && data.hitStroke === 'pixel';
10424
10509
  const isHitPixel = isHitPixelFill || isHitPixelStroke;
@@ -10433,7 +10518,7 @@ ui$5.__updateHitCanvas = function () {
10433
10518
  h.resize({ width, height, pixelRatio: 1 });
10434
10519
  h.clear();
10435
10520
  ImageManager.patternLocked = true;
10436
- this.__renderShape(h, { matrix: matrix$2.setWith(this.__world).scaleWith(1 / scale).invertWith().translate(-x, -y) }, !isHitPixelFill, !isHitPixelStroke);
10521
+ this.__renderShape(h, { matrix: matrix$2.setWith(this.__world).scaleWith(1 / scale).invertWith().translate(-x, -y), ignoreFill: !isHitPixelFill, ignoreStroke: !isHitPixelStroke });
10437
10522
  ImageManager.patternLocked = false;
10438
10523
  h.resetTransform();
10439
10524
  data.__isHitPixel = true;
@@ -10454,7 +10539,7 @@ ui$5.__hit = function (inner) {
10454
10539
  const needHitFillPath = ((data.fill || data.__isCanvas) && (hitFill === 'path' || (hitFill === 'pixel' && !(data.__isAlphaPixelFill || data.__isCanvas)))) || hitFill === 'all';
10455
10540
  if (needHitFillPath && this.__hitFill(inner))
10456
10541
  return true;
10457
- const { hitStroke, __strokeWidth } = data;
10542
+ const { hitStroke, __maxStrokeWidth: strokeWidth } = data;
10458
10543
  const needHitStrokePath = (data.stroke && (hitStroke === 'path' || (hitStroke === 'pixel' && !data.__isAlphaPixelStroke))) || hitStroke === 'all';
10459
10544
  if (!needHitFillPath && !needHitStrokePath)
10460
10545
  return false;
@@ -10463,16 +10548,16 @@ ui$5.__hit = function (inner) {
10463
10548
  if (needHitStrokePath) {
10464
10549
  switch (data.strokeAlign) {
10465
10550
  case 'inside':
10466
- hitWidth += __strokeWidth * 2;
10551
+ hitWidth += strokeWidth * 2;
10467
10552
  if (!needHitFillPath && this.__hitFill(inner) && this.__hitStroke(inner, hitWidth))
10468
10553
  return true;
10469
10554
  hitWidth = radiusWidth;
10470
10555
  break;
10471
10556
  case 'center':
10472
- hitWidth += __strokeWidth;
10557
+ hitWidth += strokeWidth;
10473
10558
  break;
10474
10559
  case 'outside':
10475
- hitWidth += __strokeWidth * 2;
10560
+ hitWidth += strokeWidth * 2;
10476
10561
  if (!needHitFillPath) {
10477
10562
  if (!this.__hitFill(inner) && this.__hitStroke(inner, hitWidth))
10478
10563
  return true;
@@ -10677,9 +10762,14 @@ function fills(fills, ui, canvas) {
10677
10762
  }
10678
10763
  }
10679
10764
  canvas.fillStyle = item.style;
10680
- if (item.transform) {
10765
+ if (item.transform || item.scaleFixed) {
10681
10766
  canvas.save();
10682
- canvas.transform(item.transform);
10767
+ if (item.transform)
10768
+ canvas.transform(item.transform);
10769
+ if (item.scaleFixed) {
10770
+ const { scaleX, scaleY } = ui.getRenderScaleData(true);
10771
+ canvas.scale(1 / scaleX, 1 / scaleY);
10772
+ }
10683
10773
  if (item.blendMode)
10684
10774
  canvas.blendMode = item.blendMode;
10685
10775
  fillPathOrText(ui, canvas);
@@ -10715,8 +10805,13 @@ function strokeText(stroke, ui, canvas) {
10715
10805
  }
10716
10806
  function drawCenter$1(stroke, strokeWidthScale, ui, canvas) {
10717
10807
  const data = ui.__;
10718
- canvas.setStroke(!data.__isStrokes && stroke, data.strokeWidth * strokeWidthScale, data);
10719
- data.__isStrokes ? drawStrokesStyle(stroke, true, ui, canvas) : drawTextStroke(ui, canvas);
10808
+ if (typeof stroke === 'object') {
10809
+ drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas);
10810
+ }
10811
+ else {
10812
+ canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
10813
+ drawTextStroke(ui, canvas);
10814
+ }
10720
10815
  }
10721
10816
  function drawAlign(stroke, align, ui, canvas) {
10722
10817
  const out = canvas.getSameCanvas(true, true);
@@ -10725,15 +10820,9 @@ function drawAlign(stroke, align, ui, canvas) {
10725
10820
  out.blendMode = align === 'outside' ? 'destination-out' : 'destination-in';
10726
10821
  fillText(ui, out);
10727
10822
  out.blendMode = 'normal';
10728
- copyWorld(canvas, out, ui);
10823
+ LeafHelper.copyCanvasByWorld(ui, canvas, out);
10729
10824
  out.recycle(ui.__nowWorld);
10730
10825
  }
10731
- function copyWorld(canvas, out, ui) {
10732
- if (ui.__worldFlipped || Platform.fullImageShadow)
10733
- canvas.copyWorldByReset(out, ui.__nowWorld);
10734
- else
10735
- canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds);
10736
- }
10737
10826
  function drawTextStroke(ui, canvas) {
10738
10827
  let row, data = ui.__.__textDrawData;
10739
10828
  const { rows, decorationY } = data;
@@ -10749,14 +10838,21 @@ function drawTextStroke(ui, canvas) {
10749
10838
  rows.forEach(row => decorationY.forEach(value => canvas.strokeRect(row.x, row.y + value, row.width, decorationHeight)));
10750
10839
  }
10751
10840
  }
10752
- function drawStrokesStyle(strokes, isText, ui, canvas) {
10841
+ function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas) {
10753
10842
  let item;
10843
+ const data = ui.__, { __hasMultiStrokeStyle } = data;
10844
+ __hasMultiStrokeStyle || canvas.setStroke(undefined, data.__strokeWidth * strokeWidthScale, data);
10754
10845
  for (let i = 0, len = strokes.length; i < len; i++) {
10755
10846
  item = strokes[i];
10756
10847
  if (item.image && PaintImage.checkImage(ui, canvas, item, false))
10757
10848
  continue;
10758
10849
  if (item.style) {
10759
- canvas.strokeStyle = item.style;
10850
+ if (__hasMultiStrokeStyle) {
10851
+ const { strokeStyle } = item;
10852
+ strokeStyle ? canvas.setStroke(item.style, data.__getRealStrokeWidth(strokeStyle) * strokeWidthScale, data, strokeStyle) : canvas.setStroke(item.style, data.__strokeWidth * strokeWidthScale, data);
10853
+ }
10854
+ else
10855
+ canvas.strokeStyle = item.style;
10760
10856
  if (item.blendMode) {
10761
10857
  canvas.saveBlendMode(item.blendMode);
10762
10858
  isText ? drawTextStroke(ui, canvas) : canvas.stroke();
@@ -10795,8 +10891,13 @@ function strokes(strokes, ui, canvas) {
10795
10891
  }
10796
10892
  function drawCenter(stroke, strokeWidthScale, ui, canvas) {
10797
10893
  const data = ui.__;
10798
- canvas.setStroke(!data.__isStrokes && stroke, data.__strokeWidth * strokeWidthScale, data);
10799
- data.__isStrokes ? drawStrokesStyle(stroke, false, ui, canvas) : canvas.stroke();
10894
+ if (typeof stroke === 'object') {
10895
+ drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas);
10896
+ }
10897
+ else {
10898
+ canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
10899
+ canvas.stroke();
10900
+ }
10800
10901
  if (data.__useArrow)
10801
10902
  Paint.strokeArrow(stroke, ui, canvas);
10802
10903
  }
@@ -10818,7 +10919,7 @@ function drawOutside(stroke, ui, canvas) {
10818
10919
  drawCenter(stroke, 2, ui, out);
10819
10920
  out.clipUI(data);
10820
10921
  out.clearWorld(renderBounds);
10821
- copyWorld(canvas, out, ui);
10922
+ LeafHelper.copyCanvasByWorld(ui, canvas, out);
10822
10923
  out.recycle(ui.__nowWorld);
10823
10924
  }
10824
10925
  }
@@ -10873,8 +10974,16 @@ function compute(attrName, ui) {
10873
10974
  if (!(paints instanceof Array))
10874
10975
  paints = [paints];
10875
10976
  recycleMap = PaintImage.recycleImage(attrName, data);
10977
+ let maxChildStrokeWidth;
10876
10978
  for (let i = 0, len = paints.length, item; i < len; i++) {
10877
- (item = getLeafPaint(attrName, paints[i], ui)) && leafPaints.push(item);
10979
+ if (item = getLeafPaint(attrName, paints[i], ui)) {
10980
+ leafPaints.push(item);
10981
+ if (item.strokeStyle) {
10982
+ maxChildStrokeWidth || (maxChildStrokeWidth = 1);
10983
+ if (item.strokeStyle.strokeWidth)
10984
+ maxChildStrokeWidth = Math.max(maxChildStrokeWidth, item.strokeStyle.strokeWidth);
10985
+ }
10986
+ }
10878
10987
  }
10879
10988
  data['_' + attrName] = leafPaints.length ? leafPaints : undefined;
10880
10989
  if (leafPaints.length) {
@@ -10891,6 +11000,7 @@ function compute(attrName, ui) {
10891
11000
  else {
10892
11001
  stintSet(data, '__isAlphaPixelStroke', isAlphaPixel);
10893
11002
  stintSet(data, '__isTransparentStroke', isTransparent);
11003
+ stintSet(data, '__hasMultiStrokeStyle', maxChildStrokeWidth);
10894
11004
  }
10895
11005
  }
10896
11006
  function getLeafPaint(attrName, paint, ui) {
@@ -10922,6 +11032,11 @@ function getLeafPaint(attrName, paint, ui) {
10922
11032
  if (data) {
10923
11033
  if (typeof data.style === 'string' && hasTransparent$1(data.style))
10924
11034
  data.isTransparent = true;
11035
+ if (paint.style) {
11036
+ if (paint.style.strokeWidth === 0)
11037
+ return undefined;
11038
+ data.strokeStyle = paint.style;
11039
+ }
10925
11040
  if (paint.blendMode)
10926
11041
  data.blendMode = paint.blendMode;
10927
11042
  }
@@ -10941,8 +11056,8 @@ const PaintModule = {
10941
11056
  shape
10942
11057
  };
10943
11058
 
10944
- let origin$1 = {};
10945
- const { get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, scale: scaleHelper, rotate: rotate$2 } = MatrixHelper;
11059
+ let origin$1 = {}, tempMatrix = getMatrixData();
11060
+ const { get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, multiplyParent, scale: scaleHelper, rotate: rotate$2, skew: skewHelper } = MatrixHelper;
10946
11061
  function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
10947
11062
  const transform = get$3();
10948
11063
  translate$1(transform, box.x + x, box.y + y);
@@ -10951,13 +11066,19 @@ function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
10951
11066
  rotateOfOuter$1(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
10952
11067
  data.transform = transform;
10953
11068
  }
10954
- function clipMode(data, box, x, y, scaleX, scaleY, rotation) {
11069
+ function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipSize) {
10955
11070
  const transform = get$3();
10956
- translate$1(transform, box.x + x, box.y + y);
10957
- if (scaleX)
10958
- scaleHelper(transform, scaleX, scaleY);
10959
11071
  if (rotation)
10960
11072
  rotate$2(transform, rotation);
11073
+ if (skew)
11074
+ skewHelper(transform, skew.x, skew.y);
11075
+ if (scaleX)
11076
+ scaleHelper(transform, scaleX, scaleY);
11077
+ translate$1(transform, box.x + x, box.y + y);
11078
+ if (clipSize) {
11079
+ tempMatrix.a = box.width / clipSize.width, tempMatrix.d = box.height / clipSize.height;
11080
+ multiplyParent(transform, tempMatrix);
11081
+ }
10961
11082
  data.transform = transform;
10962
11083
  }
10963
11084
  function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align) {
@@ -10994,11 +11115,15 @@ const tempBox = new Bounds();
10994
11115
  const tempScaleData = {};
10995
11116
  const tempImage = {};
10996
11117
  function createData(leafPaint, image, paint, box) {
10997
- const { changeful, sync } = paint;
11118
+ const { changeful, sync, editing, scaleFixed } = paint;
10998
11119
  if (changeful)
10999
11120
  leafPaint.changeful = changeful;
11000
11121
  if (sync)
11001
11122
  leafPaint.sync = sync;
11123
+ if (editing)
11124
+ leafPaint.editing = editing;
11125
+ if (scaleFixed)
11126
+ leafPaint.scaleFixed = scaleFixed;
11002
11127
  leafPaint.data = getPatternData(paint, box, image);
11003
11128
  }
11004
11129
  function getPatternData(paint, box, image) {
@@ -11007,7 +11132,7 @@ function getPatternData(paint, box, image) {
11007
11132
  if (paint.mode === 'strench')
11008
11133
  paint.mode = 'stretch';
11009
11134
  let { width, height } = image;
11010
- const { opacity, mode, align, offset, scale, size, rotation, repeat, filters } = paint;
11135
+ const { opacity, mode, align, offset, scale, size, rotation, skew, clipSize, repeat, filters } = paint;
11011
11136
  const sameBox = box.width === width && box.height === height;
11012
11137
  const data = { mode };
11013
11138
  const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
@@ -11041,8 +11166,8 @@ function getPatternData(paint, box, image) {
11041
11166
  break;
11042
11167
  case 'normal':
11043
11168
  case 'clip':
11044
- if (tempImage.x || tempImage.y || scaleX || rotation)
11045
- clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
11169
+ if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew)
11170
+ clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, paint.clipSize);
11046
11171
  break;
11047
11172
  case 'repeat':
11048
11173
  if (!sameBox || scaleX || rotation)
@@ -11119,11 +11244,11 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
11119
11244
  }
11120
11245
  onLoadSuccess(ui, event);
11121
11246
  }
11122
- leafPaint.loadId = null;
11247
+ leafPaint.loadId = undefined;
11123
11248
  }, (error) => {
11124
11249
  ignoreRender(ui, false);
11125
11250
  onLoadError(ui, event, error);
11126
- leafPaint.loadId = null;
11251
+ leafPaint.loadId = undefined;
11127
11252
  });
11128
11253
  if (ui.placeholderColor) {
11129
11254
  if (!ui.placeholderDelay)
@@ -11179,16 +11304,16 @@ function ignoreRender(ui, value) {
11179
11304
  }
11180
11305
 
11181
11306
  const { get: get$1, scale: scale$2, copy: copy$4 } = MatrixHelper;
11182
- const { ceil: ceil$1, abs: abs$4 } = Math;
11307
+ const { ceil: ceil$1, abs: abs$3 } = Math;
11183
11308
  function createPattern(ui, paint, pixelRatio) {
11184
- let { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
11309
+ let { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
11185
11310
  const id = scaleX + '-' + scaleY + '-' + pixelRatio;
11186
11311
  if (paint.patternId !== id && !ui.destroyed) {
11187
- scaleX = abs$4(scaleX);
11188
- scaleY = abs$4(scaleY);
11189
11312
  const { image, data } = paint;
11190
11313
  let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, transform, repeat } = data;
11191
11314
  if (sx) {
11315
+ sx = abs$3(sx);
11316
+ sy = abs$3(sy);
11192
11317
  imageMatrix = get$1();
11193
11318
  copy$4(imageMatrix, transform);
11194
11319
  scale$2(imageMatrix, 1 / sx, 1 / sy);
@@ -11241,9 +11366,8 @@ function createPattern(ui, paint, pixelRatio) {
11241
11366
  }
11242
11367
  }
11243
11368
 
11244
- const { abs: abs$3 } = Math;
11245
11369
  function checkImage(ui, canvas, paint, allowDraw) {
11246
- const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
11370
+ const { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
11247
11371
  const { pixelRatio } = canvas, { data } = paint;
11248
11372
  if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
11249
11373
  return false;
@@ -11256,8 +11380,8 @@ function checkImage(ui, canvas, paint, allowDraw) {
11256
11380
  else {
11257
11381
  if (!(paint.changeful || ResizeEvent.isResizing(ui) || Export.running)) {
11258
11382
  let { width, height } = data;
11259
- width *= abs$3(scaleX) * pixelRatio;
11260
- height *= abs$3(scaleY) * pixelRatio;
11383
+ width *= scaleX * pixelRatio;
11384
+ height *= scaleY * pixelRatio;
11261
11385
  if (data.scaleX) {
11262
11386
  width *= data.scaleX;
11263
11387
  height *= data.scaleY;
@@ -11267,6 +11391,10 @@ function checkImage(ui, canvas, paint, allowDraw) {
11267
11391
  }
11268
11392
  }
11269
11393
  if (allowDraw) {
11394
+ if (ui.__.__isFastShadow) {
11395
+ canvas.fillStyle = paint.style || '#000';
11396
+ canvas.fill();
11397
+ }
11270
11398
  drawImage(ui, canvas, paint, data);
11271
11399
  return true;
11272
11400
  }
@@ -11455,10 +11583,7 @@ function shadow$1(ui, current, shape) {
11455
11583
  }
11456
11584
  worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, 'destination-out') : other.copyWorld(shape.canvas, shapeBounds, bounds, 'destination-out');
11457
11585
  }
11458
- if (ui.__worldFlipped)
11459
- current.copyWorldByReset(other, copyBounds, nowWorld, item.blendMode);
11460
- else
11461
- current.copyWorldToInner(other, copyBounds, __layout.renderBounds, item.blendMode);
11586
+ LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
11462
11587
  if (end && index < end)
11463
11588
  other.clearWorld(copyBounds, true);
11464
11589
  });
@@ -11517,10 +11642,7 @@ function innerShadow(ui, current, shape) {
11517
11642
  copyBounds = bounds;
11518
11643
  }
11519
11644
  other.fillWorld(copyBounds, ColorConvert.string(item.color), 'source-in');
11520
- if (ui.__worldFlipped)
11521
- current.copyWorldByReset(other, copyBounds, nowWorld, item.blendMode);
11522
- else
11523
- current.copyWorldToInner(other, copyBounds, __layout.renderBounds, item.blendMode);
11645
+ LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
11524
11646
  if (end && index < end)
11525
11647
  other.clearWorld(copyBounds, true);
11526
11648
  });
@@ -11576,12 +11698,11 @@ Group.prototype.__renderMask = function (canvas, options) {
11576
11698
  contentCanvas = getCanvas(canvas);
11577
11699
  child.__render(maskCanvas, options);
11578
11700
  }
11579
- if (!(mask === 'clipping' || mask === 'clipping-path'))
11580
- continue;
11581
- }
11582
- if (excludeRenderBounds(child, options))
11701
+ if (mask === 'clipping' || mask === 'clipping-path')
11702
+ excludeRenderBounds(child, options) || child.__render(canvas, options);
11583
11703
  continue;
11584
- child.__render(contentCanvas || canvas, options);
11704
+ }
11705
+ excludeRenderBounds(child, options) || child.__render(contentCanvas || canvas, options);
11585
11706
  }
11586
11707
  maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
11587
11708
  };
@@ -12189,41 +12310,10 @@ class EditorEvent extends Event {
12189
12310
  }
12190
12311
  EditorEvent.BEFORE_SELECT = 'editor.before_select';
12191
12312
  EditorEvent.SELECT = 'editor.select';
12313
+ EditorEvent.AFTER_SELECT = 'editor.after_select';
12192
12314
  EditorEvent.BEFORE_HOVER = 'editor.before_hover';
12193
12315
  EditorEvent.HOVER = 'editor.hover';
12194
12316
 
12195
- class EditorMoveEvent extends EditorEvent {
12196
- constructor(type, data) {
12197
- super(type, data);
12198
- }
12199
- }
12200
- EditorMoveEvent.BEFORE_MOVE = 'editor.before_move';
12201
- EditorMoveEvent.MOVE = 'editor.move';
12202
-
12203
- class EditorScaleEvent extends EditorEvent {
12204
- constructor(type, data) {
12205
- super(type, data);
12206
- }
12207
- }
12208
- EditorScaleEvent.BEFORE_SCALE = 'editor.before_scale';
12209
- EditorScaleEvent.SCALE = 'editor.scale';
12210
-
12211
- class EditorRotateEvent extends EditorEvent {
12212
- constructor(type, data) {
12213
- super(type, data);
12214
- }
12215
- }
12216
- EditorRotateEvent.BEFORE_ROTATE = 'editor.before_rotate';
12217
- EditorRotateEvent.ROTATE = 'editor.rotate';
12218
-
12219
- class EditorSkewEvent extends EditorEvent {
12220
- constructor(type, data) {
12221
- super(type, data);
12222
- }
12223
- }
12224
- EditorSkewEvent.BEFORE_SKEW = 'editor.before_skew';
12225
- EditorSkewEvent.SKEW = 'editor.skew';
12226
-
12227
12317
  function targetAttr(fn) {
12228
12318
  return (target, key) => {
12229
12319
  const privateKey = '_' + key;
@@ -12237,6 +12327,8 @@ function targetAttr(fn) {
12237
12327
  if (isSelect) {
12238
12328
  if (value instanceof Array && value.length > 1 && value[0].locked)
12239
12329
  value.splice(0, 1);
12330
+ if (this.single)
12331
+ this.element.syncEventer = null;
12240
12332
  const { beforeSelect } = this.config;
12241
12333
  if (beforeSelect) {
12242
12334
  const check = beforeSelect({ target: value });
@@ -12260,9 +12352,11 @@ function mergeConfigAttr() {
12260
12352
  return (target, key) => {
12261
12353
  defineKey(target, key, {
12262
12354
  get() {
12263
- const { config, element, dragPoint } = this, mergeConfig = Object.assign({}, config);
12355
+ const { config, element, dragPoint, editBox } = this, mergeConfig = Object.assign({}, config);
12264
12356
  if (element && element.editConfig)
12265
12357
  Object.assign(mergeConfig, element.editConfig);
12358
+ if (editBox.config)
12359
+ Object.assign(mergeConfig, editBox.config);
12266
12360
  if (dragPoint) {
12267
12361
  if (dragPoint.editConfig)
12268
12362
  Object.assign(mergeConfig, dragPoint.editConfig);
@@ -12294,14 +12388,17 @@ class Stroker extends UI {
12294
12388
  this.strokeAlign = 'center';
12295
12389
  }
12296
12390
  setTarget(target, style) {
12297
- this.set(style);
12391
+ if (style)
12392
+ this.set(style);
12298
12393
  this.target = target;
12299
12394
  this.update();
12300
12395
  }
12301
- update() {
12396
+ update(style) {
12302
12397
  const { list } = this;
12303
12398
  if (list.length) {
12304
12399
  setListWithFn(bounds$2, list, worldBounds);
12400
+ if (style)
12401
+ this.set(style);
12305
12402
  this.set(bounds$2);
12306
12403
  this.visible = true;
12307
12404
  }
@@ -12444,15 +12541,14 @@ class EditSelect extends Group {
12444
12541
  }
12445
12542
  onSelect() {
12446
12543
  if (this.running) {
12447
- const { mergeConfig, list } = this.editor;
12448
- const { stroke, strokeWidth, selectedStyle } = mergeConfig;
12449
- this.targetStroker.setTarget(list, Object.assign({ stroke, strokeWidth: Math.max(1, strokeWidth / 2) }, (selectedStyle || {})));
12544
+ this.targetStroker.setTarget(this.editor.list);
12450
12545
  this.hoverStroker.target = null;
12451
12546
  }
12452
12547
  }
12453
12548
  update() {
12454
12549
  this.hoverStroker.update();
12455
- this.targetStroker.update();
12550
+ const { stroke, strokeWidth, selectedStyle } = this.editor.mergedConfig;
12551
+ this.targetStroker.update(Object.assign({ stroke, strokeWidth: strokeWidth && Math.max(1, strokeWidth / 2) }, (selectedStyle || {})));
12456
12552
  }
12457
12553
  onPointerMove(e) {
12458
12554
  const { app, editor } = this;
@@ -12634,16 +12730,16 @@ const { topLeft: topLeft$1, top: top$1, topRight: topRight$1, right: right$2, bo
12634
12730
  const { toPoint } = AroundHelper;
12635
12731
  const { within: within$2 } = MathHelper;
12636
12732
  const EditDataHelper = {
12637
- getScaleData(element, startBounds, direction, totalMove, lockRatio, around, flipable, scaleMode) {
12733
+ getScaleData(target, startBounds, direction, totalMove, lockRatio, around, flipable, scaleMode) {
12638
12734
  let align, origin = {}, scaleX = 1, scaleY = 1;
12639
- const { boxBounds, widthRange, heightRange, dragBounds, worldBoxBounds } = element;
12735
+ const { boxBounds, widthRange, heightRange, dragBounds, worldBoxBounds } = target;
12640
12736
  const { width, height } = startBounds;
12641
12737
  if (around) {
12642
12738
  totalMove.x *= 2;
12643
12739
  totalMove.y *= 2;
12644
12740
  }
12645
- const originChangedScaleX = element.scaleX / startBounds.scaleX;
12646
- const originChangedScaleY = element.scaleY / startBounds.scaleY;
12741
+ const originChangedScaleX = target.scaleX / startBounds.scaleX;
12742
+ const originChangedScaleY = target.scaleY / startBounds.scaleY;
12647
12743
  const signX = originChangedScaleX < 0 ? -1 : 1;
12648
12744
  const signY = originChangedScaleY < 0 ? -1 : 1;
12649
12745
  const changedScaleX = scaleMode ? originChangedScaleX : signX * boxBounds.width / width;
@@ -12719,7 +12815,7 @@ const EditDataHelper = {
12719
12815
  if (useScaleY)
12720
12816
  scaleY /= changedScaleY;
12721
12817
  if (!flipable) {
12722
- const { worldTransform } = element;
12818
+ const { worldTransform } = target;
12723
12819
  if (scaleX < 0)
12724
12820
  scaleX = 1 / boxBounds.width / worldTransform.scaleX;
12725
12821
  if (scaleY < 0)
@@ -12727,24 +12823,26 @@ const EditDataHelper = {
12727
12823
  }
12728
12824
  toPoint(around || align, boxBounds, origin, true);
12729
12825
  if (dragBounds) {
12730
- const allowBounds = dragBounds === 'parent' ? element.parent.boxBounds : dragBounds;
12731
- const localBounds = new Bounds(element.__localBoxBounds);
12732
- localBounds.scaleOf(element.getLocalPointByInner(origin), scaleX, scaleY);
12733
- if (!BoundsHelper.includes(allowBounds, localBounds)) {
12734
- const realBounds = localBounds.getIntersect(allowBounds);
12735
- const fitScaleX = realBounds.width / localBounds.width, fitScaleY = realBounds.height / localBounds.height;
12736
- if (useScaleX)
12737
- scaleX *= fitScaleX;
12738
- if (useScaleY)
12739
- scaleY *= fitScaleY;
12826
+ const allowBounds = dragBounds === 'parent' ? target.parent.boxBounds : dragBounds;
12827
+ const childBounds = new Bounds(target.__localBoxBounds);
12828
+ if (BoundsHelper.includes(new Bounds(allowBounds).spread(0.1), childBounds)) {
12829
+ childBounds.scaleOf(target.getLocalPointByInner(origin), scaleX, scaleY);
12830
+ if (!BoundsHelper.includes(allowBounds, childBounds)) {
12831
+ const realBounds = childBounds.getIntersect(allowBounds);
12832
+ const fitScaleX = realBounds.width / childBounds.width, fitScaleY = realBounds.height / childBounds.height;
12833
+ if (useScaleX)
12834
+ scaleX *= fitScaleX;
12835
+ if (useScaleY)
12836
+ scaleY *= fitScaleY;
12837
+ }
12740
12838
  }
12741
12839
  }
12742
12840
  if (useScaleX && widthRange) {
12743
- const nowWidth = boxBounds.width * element.scaleX;
12841
+ const nowWidth = boxBounds.width * target.scaleX;
12744
12842
  scaleX = within$2(nowWidth * scaleX, widthRange) / nowWidth;
12745
12843
  }
12746
12844
  if (useScaleY && heightRange) {
12747
- const nowHeight = boxBounds.height * element.scaleY;
12845
+ const nowHeight = boxBounds.height * target.scaleY;
12748
12846
  scaleY = within$2(nowHeight * scaleY, heightRange) / nowHeight;
12749
12847
  }
12750
12848
  if (useScaleX && Math.abs(scaleX * worldBoxBounds.width) < 1)
@@ -12755,7 +12853,7 @@ const EditDataHelper = {
12755
12853
  scaleY = scaleX = Math.min(scaleX, scaleY);
12756
12854
  return { origin, scaleX, scaleY, direction, lockRatio, around };
12757
12855
  },
12758
- getRotateData(bounds, direction, current, last, around) {
12856
+ getRotateData(target, direction, current, last, around) {
12759
12857
  let align, origin = {};
12760
12858
  switch (direction) {
12761
12859
  case topLeft$1:
@@ -12773,8 +12871,8 @@ const EditDataHelper = {
12773
12871
  default:
12774
12872
  align = 'center';
12775
12873
  }
12776
- toPoint(around || align, bounds, origin, true);
12777
- return { origin, rotation: PointHelper.getRotation(last, origin, current) };
12874
+ toPoint(around || align, target.boxBounds, origin, true);
12875
+ return { origin, rotation: PointHelper.getRotation(last, target.getWorldPointByBox(origin), current) };
12778
12876
  },
12779
12877
  getSkewData(bounds, direction, move, around) {
12780
12878
  let align, origin = {}, skewX = 0, skewY = 0;
@@ -12871,9 +12969,9 @@ const EditDataHelper = {
12871
12969
  };
12872
12970
 
12873
12971
  const cacheCursors = {};
12874
- function updateCursor(editor, e) {
12875
- const { editBox } = editor, point = editBox.enterPoint;
12876
- if (!point || !editor.editing || !editBox.visible)
12972
+ function updatePointCursor(editBox, e) {
12973
+ const { enterPoint: point, dragging, skewing, resizing, flippedX, flippedY } = editBox;
12974
+ if (!point || !editBox.editor.editing || !editBox.canUse)
12877
12975
  return;
12878
12976
  if (point.name === 'circle')
12879
12977
  return;
@@ -12883,13 +12981,14 @@ function updateCursor(editor, e) {
12883
12981
  return;
12884
12982
  }
12885
12983
  let { rotation } = editBox;
12886
- const { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editor.mergeConfig;
12887
- const { pointType } = point, { flippedX, flippedY } = editBox;
12984
+ const { pointType } = point, { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editBox.mergeConfig;
12888
12985
  let showResize = pointType.includes('resize');
12889
12986
  if (showResize && rotateable && (e.metaKey || e.ctrlKey || !resizeable))
12890
12987
  showResize = false;
12891
12988
  const showSkew = skewable && !showResize && (point.name === 'resize-line' || pointType === 'skew');
12892
- const cursor = showSkew ? skewCursor : (showResize ? resizeCursor : rotateCursor);
12989
+ const cursor = dragging
12990
+ ? (skewing ? skewCursor : (resizing ? resizeCursor : rotateCursor))
12991
+ : (showSkew ? skewCursor : (showResize ? resizeCursor : rotateCursor));
12893
12992
  rotation += (EditDataHelper.getFlipDirection(point.direction, flippedX, flippedY) + 1) * 45;
12894
12993
  rotation = Math.round(MathHelper.formatRotation(rotation, true) / 2) * 2;
12895
12994
  const { url, x, y } = cursor;
@@ -12901,9 +13000,10 @@ function updateCursor(editor, e) {
12901
13000
  cacheCursors[key] = point.cursor = { url: toDataURL(url, rotation), x, y };
12902
13001
  }
12903
13002
  }
12904
- function updateMoveCursor(editor) {
12905
- const { moveCursor, moveable } = editor.mergeConfig;
12906
- editor.editBox.rect.cursor = moveable ? moveCursor : undefined;
13003
+ function updateMoveCursor(editBox) {
13004
+ const { moveCursor, moveable } = editBox.mergeConfig;
13005
+ if (editBox.canUse)
13006
+ editBox.rect.cursor = moveable ? moveCursor : undefined;
12907
13007
  }
12908
13008
  function toDataURL(svg, rotation) {
12909
13009
  return '"data:image/svg+xml,' + encodeURIComponent(svg.replace('{{rotation}}', rotation.toString())) + '"';
@@ -12918,10 +13018,26 @@ class EditPoint extends Box {
12918
13018
 
12919
13019
  const fourDirection = ['top', 'right', 'bottom', 'left'], editConfig = undefined;
12920
13020
  class EditBox extends Group {
13021
+ get mergeConfig() {
13022
+ const { config } = this, { mergeConfig, editBox } = this.editor;
13023
+ return this.mergedConfig = config && (editBox !== this) ? Object.assign(Object.assign({}, mergeConfig), config) : mergeConfig;
13024
+ }
13025
+ get target() { return this._target || this.editor.element; }
13026
+ set target(target) { this._target = target; }
13027
+ get single() { return !!this._target || this.editor.single; }
13028
+ get transformTool() { return this._transformTool || this.editor; }
13029
+ set transformTool(tool) { this._transformTool = tool; }
12921
13030
  get flipped() { return this.flippedX || this.flippedY; }
12922
13031
  get flippedX() { return this.scaleX < 0; }
12923
13032
  get flippedY() { return this.scaleY < 0; }
12924
13033
  get flippedOne() { return this.scaleX * this.scaleY < 0; }
13034
+ get canUse() { return (this.visible && this.view.visible); }
13035
+ get canGesture() {
13036
+ if (!this.canUse)
13037
+ return false;
13038
+ const { moveable, resizeable, rotateable } = this.mergeConfig;
13039
+ return typeof moveable === 'string' || typeof resizeable === 'string' || typeof rotateable === 'string';
13040
+ }
12925
13041
  constructor(editor) {
12926
13042
  super();
12927
13043
  this.view = new Group();
@@ -12960,8 +13076,7 @@ class EditBox extends Group {
12960
13076
  this.add(view);
12961
13077
  }
12962
13078
  load() {
12963
- const { mergeConfig, element, single } = this.editor;
12964
- const { rect, circle, resizePoints } = this;
13079
+ const { target, mergeConfig, single, rect, circle, resizePoints } = this;
12965
13080
  const { stroke, strokeWidth } = mergeConfig;
12966
13081
  const pointsStyle = this.getPointsStyle();
12967
13082
  const middlePointsStyle = this.getMiddlePointsStyle();
@@ -12969,24 +13084,38 @@ class EditBox extends Group {
12969
13084
  for (let i = 0; i < 8; i++) {
12970
13085
  resizeP = resizePoints[i];
12971
13086
  resizeP.set(this.getPointStyle((i % 2) ? middlePointsStyle[((i - 1) / 2) % middlePointsStyle.length] : pointsStyle[(i / 2) % pointsStyle.length]));
12972
- if (!(i % 2))
12973
- resizeP.rotation = (i / 2) * 90;
13087
+ resizeP.rotation = ((i - (i % 2 ? 1 : 0)) / 2) * 90;
12974
13088
  }
12975
13089
  circle.set(this.getPointStyle(mergeConfig.circle || mergeConfig.rotatePoint || pointsStyle[0]));
12976
13090
  rect.set(Object.assign({ stroke, strokeWidth, editConfig }, (mergeConfig.rect || {})));
12977
- rect.hittable = !single;
12978
- rect.syncEventer = single && this.editor;
12979
- if (single) {
12980
- element.syncEventer = rect;
12981
- this.app.interaction.bottomList = [{ target: rect, proxy: element }];
12982
- }
12983
- }
12984
- update(bounds) {
12985
- const { rect, circle, buttons, resizePoints, rotatePoints, resizeLines, editor } = this;
12986
- const { mergeConfig, element, multiple, editMask } = editor;
12987
- const { middlePoint, resizeable, rotateable, hideOnSmall, editBox, mask } = mergeConfig;
12988
- this.visible = !element.locked;
13091
+ const syncEventer = single && this.transformTool.editTool;
13092
+ rect.hittable = !syncEventer;
13093
+ rect.syncEventer = syncEventer && this.editor;
13094
+ if (syncEventer) {
13095
+ target.syncEventer = rect;
13096
+ this.app.interaction.bottomList = [{ target: rect, proxy: target }];
13097
+ }
13098
+ updateMoveCursor(this);
13099
+ }
13100
+ update() {
13101
+ const { editor } = this;
13102
+ const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = this.target.getLayoutBounds('box', editor, true);
13103
+ this.set({ x, y, scaleX, scaleY, rotation, skewX, skewY });
13104
+ this.updateBounds({ x: 0, y: 0, width, height });
13105
+ }
13106
+ unload() {
13107
+ this.visible = false;
13108
+ if (this.app)
13109
+ this.rect.syncEventer = this.app.interaction.bottomList = null;
13110
+ }
13111
+ updateBounds(bounds) {
13112
+ const { editMask } = this.editor;
13113
+ const { mergeConfig, single, rect, circle, buttons, resizePoints, rotatePoints, resizeLines } = this;
13114
+ const { middlePoint, resizeable, rotateable, hideOnSmall, editBox, mask, spread } = mergeConfig;
13115
+ this.visible = !this.target.locked;
12989
13116
  editMask.visible = mask ? true : 0;
13117
+ if (spread)
13118
+ BoundsHelper.spread(bounds, spread);
12990
13119
  if (this.view.worldOpacity) {
12991
13120
  const { width, height } = bounds;
12992
13121
  const smallSize = typeof hideOnSmall === 'number' ? hideOnSmall : 10;
@@ -13011,7 +13140,6 @@ class EditBox extends Group {
13011
13140
  }
13012
13141
  else {
13013
13142
  resizeL.height = height;
13014
- resizeP.rotation = 90;
13015
13143
  if (hideOnSmall && resizeP.width * 2 > height)
13016
13144
  resizeP.visible = false;
13017
13145
  }
@@ -13019,25 +13147,25 @@ class EditBox extends Group {
13019
13147
  }
13020
13148
  circle.visible = showPoints && rotateable && !!(mergeConfig.circle || mergeConfig.rotatePoint);
13021
13149
  if (circle.visible)
13022
- this.layoutCircle(mergeConfig);
13150
+ this.layoutCircle();
13023
13151
  if (rect.path)
13024
13152
  rect.path = null;
13025
- rect.set(Object.assign(Object.assign({}, bounds), { visible: multiple ? true : editBox }));
13153
+ rect.set(Object.assign(Object.assign({}, bounds), { visible: single ? editBox : true }));
13026
13154
  buttons.visible = showPoints && buttons.children.length > 0 || 0;
13027
13155
  if (buttons.visible)
13028
- this.layoutButtons(mergeConfig);
13156
+ this.layoutButtons();
13029
13157
  }
13030
13158
  else
13031
13159
  rect.set(bounds);
13032
13160
  }
13033
- layoutCircle(config) {
13034
- const { circleDirection, circleMargin, buttonsMargin, buttonsDirection, middlePoint } = config;
13161
+ layoutCircle() {
13162
+ const { circleDirection, circleMargin, buttonsMargin, buttonsDirection, middlePoint } = this.mergedConfig;
13035
13163
  const direction = fourDirection.indexOf(circleDirection || ((this.buttons.children.length && buttonsDirection === 'bottom') ? 'top' : 'bottom'));
13036
13164
  this.setButtonPosition(this.circle, direction, circleMargin || buttonsMargin, !!middlePoint);
13037
13165
  }
13038
- layoutButtons(config) {
13166
+ layoutButtons() {
13039
13167
  const { buttons } = this;
13040
- const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = config;
13168
+ const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = this.mergedConfig;
13041
13169
  const { flippedX, flippedY } = this;
13042
13170
  let index = fourDirection.indexOf(buttonsDirection);
13043
13171
  if ((index % 2 && flippedX) || ((index + 1) % 2 && flippedY)) {
@@ -13066,49 +13194,51 @@ class EditBox extends Group {
13066
13194
  buttons.y = point.y + margin;
13067
13195
  }
13068
13196
  }
13069
- unload() {
13070
- this.visible = false;
13071
- }
13072
13197
  getPointStyle(userStyle) {
13073
- const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.editor.mergeConfig;
13198
+ const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.mergedConfig;
13074
13199
  const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius, offsetX: 0, offsetY: 0, editConfig };
13075
13200
  return userStyle ? Object.assign(defaultStyle, userStyle) : defaultStyle;
13076
13201
  }
13077
13202
  getPointsStyle() {
13078
- const { point } = this.editor.mergeConfig;
13203
+ const { point } = this.mergedConfig;
13079
13204
  return point instanceof Array ? point : [point];
13080
13205
  }
13081
13206
  getMiddlePointsStyle() {
13082
- const { middlePoint } = this.editor.mergeConfig;
13207
+ const { middlePoint } = this.mergedConfig;
13083
13208
  return middlePoint instanceof Array ? middlePoint : (middlePoint ? [middlePoint] : this.getPointsStyle());
13084
13209
  }
13085
- onSelect(e) {
13086
- if (e.oldList.length === 1) {
13087
- e.oldList[0].syncEventer = null;
13088
- if (this.app)
13089
- this.app.interaction.bottomList = null;
13090
- }
13091
- }
13092
13210
  onDragStart(e) {
13093
13211
  this.dragging = true;
13094
13212
  const point = this.dragPoint = e.current, { pointType } = point;
13095
- const { editor, dragStartData } = this, { element } = editor;
13213
+ const { editor, dragStartData } = this, { target } = this, { moveable, resizeable, rotateable, skewable, hideOnMove } = this.mergeConfig;
13096
13214
  if (point.name === 'rect') {
13097
- this.moving = true;
13098
- editor.opacity = editor.mergeConfig.hideOnMove ? 0 : 1;
13215
+ moveable && (this.moving = true);
13216
+ editor.opacity = hideOnMove ? 0 : 1;
13217
+ }
13218
+ else {
13219
+ if (pointType.includes('rotate') || e.metaKey || e.ctrlKey || !resizeable) {
13220
+ rotateable && (this.rotating = true);
13221
+ if (pointType === 'resize-rotate')
13222
+ resizeable && (this.resizing = true);
13223
+ else if (point.name === 'resize-line')
13224
+ skewable && (this.skewing = true), this.rotating = false;
13225
+ }
13226
+ else if (pointType === 'resize')
13227
+ resizeable && (this.resizing = true);
13228
+ if (pointType === 'skew')
13229
+ skewable && (this.skewing = true);
13099
13230
  }
13100
13231
  dragStartData.x = e.x;
13101
13232
  dragStartData.y = e.y;
13102
- dragStartData.point = { x: element.x, y: element.y };
13103
- dragStartData.bounds = Object.assign({}, element.getLayoutBounds('box', 'local'));
13104
- dragStartData.rotation = element.rotation;
13233
+ dragStartData.point = { x: target.x, y: target.y };
13234
+ dragStartData.bounds = Object.assign({}, target.getLayoutBounds('box', 'local'));
13235
+ dragStartData.rotation = target.rotation;
13105
13236
  if (pointType && pointType.includes('resize'))
13106
13237
  ResizeEvent.resizingKeys = editor.leafList.keys;
13107
13238
  }
13108
13239
  onDragEnd(e) {
13109
- this.dragging = false;
13110
13240
  this.dragPoint = null;
13111
- this.moving = false;
13241
+ this.resetDoing();
13112
13242
  const { name, pointType } = e.current;
13113
13243
  if (name === 'rect')
13114
13244
  this.editor.opacity = 1;
@@ -13116,22 +13246,61 @@ class EditBox extends Group {
13116
13246
  ResizeEvent.resizingKeys = null;
13117
13247
  }
13118
13248
  onDrag(e) {
13119
- const { editor } = this;
13120
- const { pointType } = this.enterPoint = e.current;
13121
- if (pointType.includes('rotate') || e.metaKey || e.ctrlKey || !editor.mergeConfig.resizeable) {
13122
- editor.onRotate(e);
13123
- if (pointType === 'resize-rotate')
13124
- editor.onScale(e);
13125
- }
13126
- else if (pointType === 'resize')
13127
- editor.onScale(e);
13128
- if (pointType === 'skew')
13129
- editor.onSkew(e);
13130
- updateCursor(editor, e);
13249
+ const { transformTool, moving, resizing, rotating, skewing } = this;
13250
+ if (moving) {
13251
+ transformTool.onMove(e);
13252
+ updateMoveCursor(this);
13253
+ }
13254
+ else if (resizing || rotating || skewing) {
13255
+ const point = e.current;
13256
+ if (point.pointType)
13257
+ this.enterPoint = point;
13258
+ if (rotating)
13259
+ transformTool.onRotate(e);
13260
+ if (resizing)
13261
+ transformTool.onScale(e);
13262
+ if (skewing)
13263
+ transformTool.onSkew(e);
13264
+ updatePointCursor(this, e);
13265
+ }
13266
+ }
13267
+ resetDoing() {
13268
+ if (this.canUse)
13269
+ this.dragging = this.gesturing = this.moving = this.resizing = this.rotating = this.skewing = false;
13270
+ }
13271
+ onMove(e) {
13272
+ if (this.canGesture && e.moveType !== 'drag') {
13273
+ e.stop();
13274
+ if (typeof this.mergeConfig.moveable === 'string') {
13275
+ this.gesturing = this.moving = true;
13276
+ this.transformTool.onMove(e);
13277
+ }
13278
+ }
13279
+ }
13280
+ onScale(e) {
13281
+ if (this.canGesture) {
13282
+ e.stop();
13283
+ if (typeof this.mergeConfig.resizeable === 'string') {
13284
+ this.gesturing = this.resizing = true;
13285
+ this.transformTool.onScale(e);
13286
+ }
13287
+ }
13288
+ }
13289
+ onRotate(e) {
13290
+ if (this.canGesture) {
13291
+ e.stop();
13292
+ if (typeof this.mergeConfig.rotateable === 'string') {
13293
+ this.gesturing = this.rotating = true;
13294
+ this.transformTool.onRotate(e);
13295
+ }
13296
+ }
13297
+ }
13298
+ onKey(e) {
13299
+ updatePointCursor(this, e);
13131
13300
  }
13132
13301
  onArrow(e) {
13133
- const { editor } = this;
13134
- if (editor.editing && editor.mergeConfig.keyEvent) {
13302
+ const { editor, transformTool } = this;
13303
+ if (this.canUse && editor.editing && this.mergeConfig.keyEvent) {
13135
13304
  let x = 0, y = 0;
13136
13305
  const distance = e.shiftKey ? 10 : 1;
13137
13306
  switch (e.code) {
@@ -13148,31 +13317,32 @@ class EditBox extends Group {
13148
13317
  x = distance;
13149
13318
  }
13150
13319
  if (x || y)
13151
- editor.move(x, y);
13320
+ transformTool.move(x, y);
13152
13321
  }
13153
13322
  }
13154
13323
  onDoubleTap(e) {
13155
- if (this.editor.mergeConfig.openInner === 'double')
13324
+ const { openInner, preventEditInner } = this.mergeConfig;
13325
+ if (openInner === 'double' && !preventEditInner)
13156
13326
  this.openInner(e);
13157
13327
  }
13158
13328
  onLongPress(e) {
13159
- if (this.editor.mergeConfig.openInner === 'long')
13329
+ const { openInner, preventEditInner } = this.mergeConfig;
13330
+ if (openInner === 'long' && preventEditInner)
13160
13331
  this.openInner(e);
13161
13332
  }
13162
13333
  openInner(e) {
13163
- const { editor } = this;
13164
- if (editor.single) {
13165
- const { element } = editor;
13166
- if (element.locked)
13334
+ const { editor, target } = this;
13335
+ if (this.single) {
13336
+ if (target.locked)
13167
13337
  return;
13168
- if (element.isBranch && !element.editInner) {
13169
- if (element.textBox) {
13170
- const { children } = element;
13338
+ if (target.isBranch && !target.editInner) {
13339
+ if (target.textBox) {
13340
+ const { children } = target;
13171
13341
  const find = children.find(item => item.editable && item instanceof Text) || children.find(item => item instanceof Text);
13172
13342
  if (find)
13173
13343
  return editor.openInnerEditor(find);
13174
13344
  }
13175
- editor.openGroup(element);
13345
+ editor.openGroup(target);
13176
13346
  editor.target = editor.selector.findDeepOne(e);
13177
13347
  }
13178
13348
  else {
@@ -13181,7 +13351,6 @@ class EditBox extends Group {
13181
13351
  }
13182
13352
  }
13183
13353
  listenPointEvents(point, type, direction) {
13184
- const { editor } = this;
13185
13354
  point.direction = direction;
13186
13355
  point.pointType = type;
13187
13356
  const events = [
@@ -13191,19 +13360,31 @@ class EditBox extends Group {
13191
13360
  [PointerEvent.LEAVE, () => { this.enterPoint = null; }],
13192
13361
  ];
13193
13362
  if (point.name !== 'circle')
13194
- events.push([PointerEvent.ENTER, (e) => { this.enterPoint = point, updateCursor(editor, e); }]);
13363
+ events.push([PointerEvent.ENTER, (e) => { this.enterPoint = point, updatePointCursor(this, e); }]);
13195
13364
  this.__eventIds.push(point.on_(events));
13196
13365
  }
13197
13366
  __listenEvents() {
13198
- const { rect, editor } = this;
13199
- this.__eventIds.push(editor.on_(EditorEvent.SELECT, this.onSelect, this), rect.on_([
13367
+ const { rect, editor, __eventIds: events } = this;
13368
+ events.push(rect.on_([
13200
13369
  [DragEvent.START, this.onDragStart, this],
13201
- [DragEvent.DRAG, editor.onMove, editor],
13370
+ [DragEvent.DRAG, this.onDrag, this],
13202
13371
  [DragEvent.END, this.onDragEnd, this],
13203
- [PointerEvent.ENTER, () => updateMoveCursor(editor)],
13372
+ [PointerEvent.ENTER, () => updateMoveCursor(this)],
13204
13373
  [PointerEvent.DOUBLE_TAP, this.onDoubleTap, this],
13205
13374
  [PointerEvent.LONG_PRESS, this.onLongPress, this]
13206
13375
  ]));
13376
+ this.waitLeafer(() => {
13377
+ events.push(editor.app.on_([
13378
+ [[KeyEvent.HOLD, KeyEvent.UP], this.onKey, this],
13379
+ [KeyEvent.DOWN, this.onArrow, this],
13380
+ [MoveEvent.BEFORE_MOVE, this.onMove, this, true],
13381
+ [ZoomEvent.BEFORE_ZOOM, this.onScale, this, true],
13382
+ [RotateEvent.BEFORE_ROTATE, this.onRotate, this, true],
13383
+ [MoveEvent.END, this.resetDoing, this],
13384
+ [ZoomEvent.END, this.resetDoing, this],
13385
+ [RotateEvent.END, this.resetDoing, this],
13386
+ ]));
13387
+ });
13207
13388
  }
13208
13389
  __removeListenEvents() {
13209
13390
  this.off_(this.__eventIds);
@@ -13234,11 +13415,12 @@ class EditMask extends UI {
13234
13415
  if (options.bounds && !options.bounds.hit(editor.editBox.rect.__world, options.matrix))
13235
13416
  return;
13236
13417
  canvas.saveBlendMode('destination-out');
13418
+ options = Object.assign(Object.assign({}, options), { shape: true });
13237
13419
  editor.list.forEach(item => {
13238
- item.__renderShape(canvas, options);
13239
- const { __box, parent } = item;
13240
- if ((item = __box) || ((item = parent) && parent.textBox))
13241
- item.__renderShape(canvas, options);
13420
+ item.__render(canvas, options);
13421
+ const { parent } = item;
13422
+ if (parent && parent.textBox)
13423
+ parent.__renderShape(canvas, options);
13242
13424
  });
13243
13425
  canvas.restoreBlendMode();
13244
13426
  }
@@ -13333,7 +13515,7 @@ const config = {
13333
13515
  const bounds$1 = new Bounds();
13334
13516
  function simulate(editor) {
13335
13517
  const { simulateTarget, list } = editor;
13336
- const { zoomLayer } = list[0].leafer.zoomLayer;
13518
+ const { zoomLayer } = list[0].leafer;
13337
13519
  simulateTarget.safeChange(() => {
13338
13520
  bounds$1.setListWithFn(list, (leaf) => leaf.getBounds('box', 'page'));
13339
13521
  if (bounds$1.width === 0)
@@ -13355,15 +13537,15 @@ function onTarget(editor, oldValue) {
13355
13537
  else {
13356
13538
  editor.simulateTarget.remove();
13357
13539
  editor.leafList.reset();
13358
- editor.closeInnerEditor();
13359
13540
  }
13360
- editor.emitEvent(new EditorEvent(EditorEvent.SELECT, { editor, value: target, oldValue }));
13541
+ editor.closeInnerEditor(true);
13542
+ editor.unloadEditTool();
13543
+ const data = { editor, value: target, oldValue };
13544
+ editor.emitEvent(new EditorEvent(EditorEvent.SELECT, data));
13361
13545
  editor.checkOpenedGroups();
13362
13546
  if (editor.editing) {
13363
13547
  editor.waitLeafer(() => {
13364
- updateMoveCursor(editor);
13365
13548
  editor.updateEditTool();
13366
- editor.update();
13367
13549
  editor.listenTargetEvents();
13368
13550
  });
13369
13551
  }
@@ -13371,6 +13553,7 @@ function onTarget(editor, oldValue) {
13371
13553
  editor.updateEditTool();
13372
13554
  editor.removeTargetEvents();
13373
13555
  }
13556
+ editor.emitEvent(new EditorEvent(EditorEvent.AFTER_SELECT, data));
13374
13557
  }
13375
13558
  function onHover(editor, oldValue) {
13376
13559
  editor.emitEvent(new EditorEvent(EditorEvent.HOVER, { editor, value: editor.hoverTarget, oldValue }));
@@ -13542,98 +13725,44 @@ class SimulateElement extends Rect {
13542
13725
  }
13543
13726
  }
13544
13727
 
13545
- class Editor extends Group {
13546
- get list() { return this.leafList.list; }
13547
- get dragHoverExclude() { return [this.editBox.rect]; }
13548
- get editing() { return !!this.list.length; }
13549
- get groupOpening() { return !!this.openedGroupList.length; }
13550
- get multiple() { return this.list.length > 1; }
13551
- get single() { return this.list.length === 1; }
13552
- get dragging() { return this.editBox.dragging; }
13553
- get moving() { return this.editBox.moving; }
13554
- get dragPoint() { return this.editBox.dragPoint; }
13555
- get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
13556
- get buttons() { return this.editBox.buttons; }
13557
- constructor(userConfig, data) {
13558
- super(data);
13559
- this.leafList = new LeafList();
13560
- this.openedGroupList = new LeafList();
13561
- this.simulateTarget = new SimulateElement(this);
13562
- this.editBox = new EditBox(this);
13563
- this.editToolList = {};
13564
- this.selector = new EditSelect(this);
13565
- this.editMask = new EditMask(this);
13566
- this.targetEventIds = [];
13567
- let mergedConfig = DataHelper.clone(config);
13568
- if (userConfig)
13569
- mergedConfig = DataHelper.default(userConfig, mergedConfig);
13570
- this.mergedConfig = this.config = mergedConfig;
13571
- this.addMany(this.editMask, this.selector, this.editBox);
13572
- if (!Plugin.has('resize'))
13573
- this.config.editSize = 'scale';
13574
- }
13575
- select(target) {
13576
- this.target = target;
13577
- }
13578
- cancel() {
13579
- this.target = null;
13580
- }
13581
- hasItem(item) {
13582
- return this.leafList.has(item);
13583
- }
13584
- addItem(item) {
13585
- if (!this.hasItem(item) && !item.locked)
13586
- this.leafList.add(item), this.target = this.leafList.list;
13587
- }
13588
- removeItem(item) {
13589
- if (this.hasItem(item))
13590
- this.leafList.remove(item), this.target = this.leafList.list;
13591
- }
13592
- shiftItem(item) {
13593
- this.hasItem(item) ? this.removeItem(item) : this.addItem(item);
13594
- }
13595
- update() {
13596
- if (this.editing) {
13597
- if (!this.element.parent)
13598
- return this.cancel();
13599
- if (this.innerEditing)
13600
- this.innerEditor.update();
13601
- this.editTool.update();
13602
- this.selector.update();
13603
- }
13728
+ class EditorMoveEvent extends EditorEvent {
13729
+ constructor(type, data) {
13730
+ super(type, data);
13604
13731
  }
13605
- updateEditBox() {
13606
- if (this.multiple)
13607
- simulate(this);
13608
- this.update();
13732
+ }
13733
+ EditorMoveEvent.BEFORE_MOVE = 'editor.before_move';
13734
+ EditorMoveEvent.MOVE = 'editor.move';
13735
+
13736
+ class EditorScaleEvent extends EditorEvent {
13737
+ constructor(type, data) {
13738
+ super(type, data);
13609
13739
  }
13610
- updateEditTool() {
13611
- const tool = this.editTool;
13612
- if (tool) {
13613
- this.editBox.unload();
13614
- tool.unload();
13615
- this.editTool = null;
13616
- }
13617
- if (this.editing) {
13618
- const tag = this.single ? this.list[0].editOuter : 'EditTool';
13619
- this.editTool = this.editToolList[tag] = this.editToolList[tag] || EditToolCreator.get(tag, this);
13620
- this.editBox.load();
13621
- this.editTool.load();
13622
- }
13740
+ }
13741
+ EditorScaleEvent.BEFORE_SCALE = 'editor.before_scale';
13742
+ EditorScaleEvent.SCALE = 'editor.scale';
13743
+
13744
+ class EditorRotateEvent extends EditorEvent {
13745
+ constructor(type, data) {
13746
+ super(type, data);
13623
13747
  }
13624
- getEditSize(_ui) {
13625
- return this.mergeConfig.editSize;
13748
+ }
13749
+ EditorRotateEvent.BEFORE_ROTATE = 'editor.before_rotate';
13750
+ EditorRotateEvent.ROTATE = 'editor.rotate';
13751
+
13752
+ class EditorSkewEvent extends EditorEvent {
13753
+ constructor(type, data) {
13754
+ super(type, data);
13626
13755
  }
13756
+ }
13757
+ EditorSkewEvent.BEFORE_SKEW = 'editor.before_skew';
13758
+ EditorSkewEvent.SKEW = 'editor.skew';
13759
+
13760
+ class TransformTool {
13627
13761
  onMove(e) {
13762
+ const { target, dragStartData } = this.editBox;
13628
13763
  if (e instanceof MoveEvent) {
13629
- if (e.moveType !== 'drag') {
13630
- const { moveable, resizeable } = this.mergeConfig;
13631
- const move = e.getLocalMove(this.element);
13632
- if (moveable === 'move')
13633
- e.stop(), this.move(move.x, move.y);
13634
- else if (resizeable === 'zoom')
13635
- e.stop();
13636
- }
13764
+ const move = e.getLocalMove(target);
13765
+ this.move(move.x, move.y);
13637
13766
  }
13638
13767
  else {
13639
13768
  const total = { x: e.totalX, y: e.totalY };
@@ -13643,22 +13772,21 @@ class Editor extends Group {
13643
13772
  else
13644
13773
  total.x = 0;
13645
13774
  }
13646
- this.move(DragEvent.getValidMove(this.element, this.editBox.dragStartData.point, total));
13775
+ this.move(DragEvent.getValidMove(target, dragStartData.point, total));
13647
13776
  }
13648
13777
  }
13649
13778
  onScale(e) {
13650
- const { element } = this;
13651
- let { around, lockRatio, resizeable, flipable, editSize } = this.mergeConfig;
13779
+ const { target, mergeConfig, single, dragStartData } = this.editBox;
13780
+ let { around, lockRatio, flipable, editSize } = mergeConfig;
13652
13781
  if (e instanceof ZoomEvent) {
13653
- if (resizeable === 'zoom')
13654
- e.stop(), this.scaleOf(element.getBoxPoint(e), e.scale, e.scale);
13782
+ this.scaleOf(target.getBoxPoint(e), e.scale, e.scale);
13655
13783
  }
13656
13784
  else {
13657
13785
  const { direction } = e.current;
13658
- if (e.shiftKey || element.lockRatio)
13786
+ if (e.shiftKey || target.lockRatio)
13659
13787
  lockRatio = true;
13660
- const data = EditDataHelper.getScaleData(element, this.editBox.dragStartData.bounds, direction, e.getInnerTotal(element), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, this.multiple || editSize === 'scale');
13661
- if (this.editTool.onScaleWithDrag) {
13788
+ const data = EditDataHelper.getScaleData(target, dragStartData.bounds, direction, e.getInnerTotal(target), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, !single || editSize === 'scale');
13789
+ if (this.editTool && this.editTool.onScaleWithDrag) {
13662
13790
  data.drag = e;
13663
13791
  this.scaleWithDrag(data);
13664
13792
  }
@@ -13668,38 +13796,28 @@ class Editor extends Group {
13668
13796
  }
13669
13797
  }
13670
13798
  onRotate(e) {
13671
- const { skewable, rotateable, around, rotateGap } = this.mergeConfig;
13672
- const { direction, name } = e.current;
13673
- if (skewable && name === 'resize-line')
13674
- return this.onSkew(e);
13675
- const { element } = this, { dragStartData } = this.editBox;
13799
+ const { target, mergeConfig, dragStartData } = this.editBox;
13800
+ const { around, rotateAround, rotateGap } = mergeConfig;
13801
+ const { direction } = e.current;
13676
13802
  let origin, rotation;
13677
13803
  if (e instanceof RotateEvent) {
13678
- if (rotateable === 'rotate')
13679
- e.stop(), rotation = e.rotation, origin = element.getBoxPoint(e);
13680
- else
13681
- return;
13682
- if (element.scaleX * element.scaleY < 0)
13683
- rotation = -rotation;
13804
+ rotation = e.rotation;
13805
+ origin = rotateAround ? AroundHelper.getPoint(rotateAround, target.boxBounds) : target.getBoxPoint(e);
13684
13806
  }
13685
13807
  else {
13686
- const data = EditDataHelper.getRotateData(element.boxBounds, direction, e.getBoxPoint(element), element.getBoxPoint(dragStartData), e.shiftKey ? null : (element.around || element.origin || around || 'center'));
13687
- rotation = data.rotation;
13808
+ const data = EditDataHelper.getRotateData(target, direction, e, dragStartData, e.shiftKey ? null : (rotateAround || target.around || target.origin || around || 'center'));
13809
+ rotation = dragStartData.rotation + data.rotation - target.rotation;
13688
13810
  origin = data.origin;
13689
13811
  }
13690
- if (element.scaleX * element.scaleY < 0)
13691
- rotation = -rotation;
13692
- if (e instanceof DragEvent)
13693
- rotation = dragStartData.rotation + rotation - element.rotation;
13694
- rotation = MathHelper.float(MathHelper.getGapRotation(rotation, rotateGap, element.rotation), 2);
13812
+ rotation = MathHelper.float(MathHelper.getGapRotation(rotation, rotateGap, target.rotation), 2);
13695
13813
  if (!rotation)
13696
13814
  return;
13697
13815
  this.rotateOf(origin, rotation);
13698
13816
  }
13699
13817
  onSkew(e) {
13700
- const { element } = this;
13701
- const { around } = this.mergeConfig;
13702
- const { origin, skewX, skewY } = EditDataHelper.getSkewData(element.boxBounds, e.current.direction, e.getInnerMove(element), EditDataHelper.getAround(around, e.altKey));
13818
+ const { target, mergeConfig } = this.editBox;
13819
+ const { around } = mergeConfig;
13820
+ const { origin, skewX, skewY } = EditDataHelper.getSkewData(target.boxBounds, e.current.direction, e.getInnerMove(target), EditDataHelper.getAround(around, e.altKey));
13703
13821
  if (!skewX && !skewY)
13704
13822
  return;
13705
13823
  this.skewOf(origin, skewX, skewY);
@@ -13709,7 +13827,8 @@ class Editor extends Group {
13709
13827
  return;
13710
13828
  if (typeof x === 'object')
13711
13829
  y = x.y, x = x.x;
13712
- const { element: target } = this, { beforeMove } = this.mergeConfig;
13830
+ const { target, mergeConfig, single, editor } = this.editBox;
13831
+ const { beforeMove } = mergeConfig;
13713
13832
  if (beforeMove) {
13714
13833
  const check = beforeMove({ target, x, y });
13715
13834
  if (typeof check === 'object')
@@ -13718,25 +13837,26 @@ class Editor extends Group {
13718
13837
  return;
13719
13838
  }
13720
13839
  const world = target.getWorldPointByLocal({ x, y }, null, true);
13721
- if (this.multiple)
13840
+ if (!single)
13722
13841
  target.safeChange(() => target.move(x, y));
13723
- const data = { target, editor: this, moveX: world.x, moveY: world.y };
13842
+ const data = { target, editor, moveX: world.x, moveY: world.y };
13724
13843
  this.emitEvent(new EditorMoveEvent(EditorMoveEvent.BEFORE_MOVE, data));
13725
13844
  const event = new EditorMoveEvent(EditorMoveEvent.MOVE, data);
13726
- this.editTool.onMove(event);
13845
+ this.doMove(event);
13727
13846
  this.emitEvent(event);
13728
13847
  }
13729
13848
  scaleWithDrag(data) {
13730
13849
  if (!this.checkTransform('resizeable'))
13731
13850
  return;
13732
- const { element: target } = this, { beforeScale } = this.mergeConfig;
13851
+ const { target, mergeConfig, editor } = this.editBox;
13852
+ const { beforeScale } = mergeConfig;
13733
13853
  if (beforeScale) {
13734
13854
  const { origin, scaleX, scaleY, drag } = data;
13735
13855
  const check = beforeScale({ target, drag, origin, scaleX, scaleY });
13736
13856
  if (check === false)
13737
13857
  return;
13738
13858
  }
13739
- data = Object.assign(Object.assign({}, data), { target, editor: this, worldOrigin: target.getWorldPoint(data.origin) });
13859
+ data = Object.assign(Object.assign({}, data), { target, editor, worldOrigin: target.getWorldPoint(data.origin) });
13740
13860
  this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
13741
13861
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
13742
13862
  this.editTool.onScaleWithDrag(event);
@@ -13745,7 +13865,8 @@ class Editor extends Group {
13745
13865
  scaleOf(origin, scaleX, scaleY = scaleX, _resize) {
13746
13866
  if (!this.checkTransform('resizeable'))
13747
13867
  return;
13748
- const { element: target } = this, { beforeScale } = this.mergeConfig;
13868
+ const { target, mergeConfig, single, editor } = this.editBox;
13869
+ const { beforeScale } = mergeConfig;
13749
13870
  if (beforeScale) {
13750
13871
  const check = beforeScale({ target, origin, scaleX, scaleY });
13751
13872
  if (typeof check === 'object')
@@ -13754,29 +13875,30 @@ class Editor extends Group {
13754
13875
  return;
13755
13876
  }
13756
13877
  const worldOrigin = this.getWorldOrigin(origin);
13757
- const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.scaleOf(origin, scaleX, scaleY)));
13758
- const data = { target, editor: this, worldOrigin, scaleX, scaleY, transform };
13878
+ const transform = !single && this.getChangedTransform(() => target.safeChange(() => target.scaleOf(origin, scaleX, scaleY)));
13879
+ const data = { target, editor, worldOrigin, scaleX, scaleY, transform };
13759
13880
  this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
13760
13881
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
13761
- this.editTool.onScale(event);
13882
+ this.doScale(event);
13762
13883
  this.emitEvent(event);
13763
13884
  }
13764
13885
  flip(axis) {
13765
13886
  if (!this.checkTransform('resizeable'))
13766
13887
  return;
13767
- const { element } = this;
13888
+ const { target, single, editor } = this.editBox;
13768
13889
  const worldOrigin = this.getWorldOrigin('center');
13769
- const transform = this.multiple ? this.getChangedTransform(() => element.safeChange(() => element.flip(axis))) : new Matrix(LeafHelper.getFlipTransform(element, axis));
13770
- const data = { target: element, editor: this, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform };
13890
+ const transform = !single ? this.getChangedTransform(() => target.safeChange(() => target.flip(axis))) : new Matrix(LeafHelper.getFlipTransform(target, axis));
13891
+ const data = { target, editor, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform };
13771
13892
  this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
13772
13893
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
13773
- this.editTool.onScale(event);
13894
+ this.doScale(event);
13774
13895
  this.emitEvent(event);
13775
13896
  }
13776
13897
  rotateOf(origin, rotation) {
13777
13898
  if (!this.checkTransform('rotateable'))
13778
13899
  return;
13779
- const { element: target } = this, { beforeRotate } = this.mergeConfig;
13900
+ const { target, mergeConfig, single, editor } = this.editBox;
13901
+ const { beforeRotate } = mergeConfig;
13780
13902
  if (beforeRotate) {
13781
13903
  const check = beforeRotate({ target, origin, rotation });
13782
13904
  if (typeof check === 'number')
@@ -13785,17 +13907,18 @@ class Editor extends Group {
13785
13907
  return;
13786
13908
  }
13787
13909
  const worldOrigin = this.getWorldOrigin(origin);
13788
- const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.rotateOf(origin, rotation)));
13789
- const data = { target, editor: this, worldOrigin, rotation, transform };
13910
+ const transform = !single && this.getChangedTransform(() => target.safeChange(() => target.rotateOf(origin, rotation)));
13911
+ const data = { target, editor, worldOrigin, rotation, transform };
13790
13912
  this.emitEvent(new EditorRotateEvent(EditorRotateEvent.BEFORE_ROTATE, data));
13791
13913
  const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, data);
13792
- this.editTool.onRotate(event);
13914
+ this.doRotate(event);
13793
13915
  this.emitEvent(event);
13794
13916
  }
13795
13917
  skewOf(origin, skewX, skewY = 0, _resize) {
13796
13918
  if (!this.checkTransform('skewable'))
13797
13919
  return;
13798
- const { element: target } = this, { beforeSkew } = this.mergeConfig;
13920
+ const { target, mergeConfig, single, editor } = this.editBox;
13921
+ const { beforeSkew } = mergeConfig;
13799
13922
  if (beforeSkew) {
13800
13923
  const check = beforeSkew({ target, origin, skewX, skewY });
13801
13924
  if (typeof check === 'object')
@@ -13804,25 +13927,149 @@ class Editor extends Group {
13804
13927
  return;
13805
13928
  }
13806
13929
  const worldOrigin = this.getWorldOrigin(origin);
13807
- const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.skewOf(origin, skewX, skewY)));
13808
- const data = { target, editor: this, worldOrigin, skewX, skewY, transform };
13930
+ const transform = !single && this.getChangedTransform(() => target.safeChange(() => target.skewOf(origin, skewX, skewY)));
13931
+ const data = { target, editor, worldOrigin, skewX, skewY, transform };
13809
13932
  this.emitEvent(new EditorSkewEvent(EditorSkewEvent.BEFORE_SKEW, data));
13810
13933
  const event = new EditorSkewEvent(EditorSkewEvent.SKEW, data);
13811
- this.editTool.onSkew(event);
13934
+ this.doSkew(event);
13812
13935
  this.emitEvent(event);
13813
13936
  }
13814
- checkTransform(type) { return this.element && !this.element.locked && this.mergeConfig[type]; }
13937
+ doMove(event) {
13938
+ this.editTool.onMove(event);
13939
+ }
13940
+ doScale(event) {
13941
+ this.editTool.onScale(event);
13942
+ }
13943
+ doRotate(event) {
13944
+ this.editTool.onRotate(event);
13945
+ }
13946
+ doSkew(event) {
13947
+ this.editTool.onSkew(event);
13948
+ }
13949
+ checkTransform(type) {
13950
+ const { target, mergeConfig } = this.editBox;
13951
+ return target && !target.locked && mergeConfig[type];
13952
+ }
13815
13953
  getWorldOrigin(origin) {
13816
- return this.element.getWorldPoint(LeafHelper.getInnerOrigin(this.element, origin));
13954
+ const { target } = this.editBox;
13955
+ return target.getWorldPoint(LeafHelper.getInnerOrigin(target, origin));
13817
13956
  }
13818
13957
  getChangedTransform(func) {
13819
- const { element } = this;
13820
- if (this.multiple && !element.canChange)
13821
- return element.changedTransform;
13822
- const oldMatrix = new Matrix(element.worldTransform);
13958
+ const { target, single } = this.editBox;
13959
+ if (!single && !target.canChange)
13960
+ return target.changedTransform;
13961
+ const oldMatrix = new Matrix(target.worldTransform);
13823
13962
  func();
13824
- return new Matrix(element.worldTransform).divide(oldMatrix);
13963
+ return new Matrix(target.worldTransform).divide(oldMatrix);
13964
+ }
13965
+ emitEvent(event, capture) {
13966
+ this.editBox.editor.emitEvent(event, capture);
13967
+ }
13968
+ }
13969
+
13970
+ let Editor = class Editor extends Group {
13971
+ get list() { return this.leafList.list; }
13972
+ get dragHoverExclude() { return [this.editBox.rect]; }
13973
+ get editing() { return !!this.list.length; }
13974
+ get groupOpening() { return !!this.openedGroupList.length; }
13975
+ get multiple() { return this.list.length > 1; }
13976
+ get single() { return this.list.length === 1; }
13977
+ get dragPoint() { return this.editBox.dragPoint; }
13978
+ get dragging() { return this.editBox.dragging; }
13979
+ get gesturing() { return this.editBox.gesturing; }
13980
+ get moving() { return this.editBox.moving; }
13981
+ get resizing() { return this.editBox.resizing; }
13982
+ get rotating() { return this.editBox.rotating; }
13983
+ get skewing() { return this.editBox.skewing; }
13984
+ get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
13985
+ get buttons() { return this.editBox.buttons; }
13986
+ constructor(userConfig, data) {
13987
+ super(data);
13988
+ this.leafList = new LeafList();
13989
+ this.openedGroupList = new LeafList();
13990
+ this.simulateTarget = new SimulateElement(this);
13991
+ this.editBox = new EditBox(this);
13992
+ this.editToolList = {};
13993
+ this.selector = new EditSelect(this);
13994
+ this.editMask = new EditMask(this);
13995
+ this.targetEventIds = [];
13996
+ let mergedConfig = DataHelper.clone(config);
13997
+ if (userConfig)
13998
+ mergedConfig = DataHelper.default(userConfig, mergedConfig);
13999
+ this.mergedConfig = this.config = mergedConfig;
14000
+ this.addMany(this.editMask, this.selector, this.editBox);
14001
+ if (!Plugin.has('resize'))
14002
+ this.config.editSize = 'scale';
14003
+ }
14004
+ select(target) {
14005
+ this.target = target;
14006
+ }
14007
+ cancel() {
14008
+ this.target = null;
14009
+ }
14010
+ hasItem(item) {
14011
+ return this.leafList.has(item);
14012
+ }
14013
+ addItem(item) {
14014
+ if (!this.hasItem(item) && !item.locked)
14015
+ this.leafList.add(item), this.target = this.leafList.list;
14016
+ }
14017
+ removeItem(item) {
14018
+ if (this.hasItem(item))
14019
+ this.leafList.remove(item), this.target = this.leafList.list;
14020
+ }
14021
+ shiftItem(item) {
14022
+ this.hasItem(item) ? this.removeItem(item) : this.addItem(item);
14023
+ }
14024
+ update() {
14025
+ if (this.editing) {
14026
+ if (!this.element.parent)
14027
+ return this.cancel();
14028
+ if (this.innerEditing)
14029
+ this.innerEditor.update();
14030
+ this.editTool.update();
14031
+ this.selector.update();
14032
+ }
14033
+ }
14034
+ updateEditBox() {
14035
+ if (this.multiple)
14036
+ simulate(this);
14037
+ this.update();
14038
+ }
14039
+ updateEditTool() {
14040
+ this.unloadEditTool();
14041
+ if (this.editing) {
14042
+ const name = this.element.editOuter || 'EditTool';
14043
+ const tool = this.editTool = this.editToolList[name] = this.editToolList[name] || EditToolCreator.get(name, this);
14044
+ this.editBox.load();
14045
+ tool.load();
14046
+ this.update();
14047
+ }
14048
+ }
14049
+ unloadEditTool() {
14050
+ let tool = this.editTool;
14051
+ if (tool) {
14052
+ this.editBox.unload();
14053
+ tool.unload();
14054
+ this.editTool = null;
14055
+ }
14056
+ }
14057
+ getEditSize(_ui) {
14058
+ return this.mergeConfig.editSize;
13825
14059
  }
14060
+ onMove(_e) { }
14061
+ onScale(_e) { }
14062
+ onRotate(_e) { }
14063
+ onSkew(_e) { }
14064
+ move(_x, _y = 0) { }
14065
+ scaleWithDrag(_data) { }
14066
+ scaleOf(_origin, scaleX, _scaleY = scaleX, _resize) { }
14067
+ flip(_axis) { }
14068
+ rotateOf(_origin, _rotation) { }
14069
+ skewOf(_origin, _skewX, _skewY = 0, _resize) { }
14070
+ checkTransform(_type) { return undefined; }
14071
+ getWorldOrigin(_origin) { return undefined; }
14072
+ getChangedTransform(_func) { return undefined; }
13826
14073
  group(userGroup) {
13827
14074
  if (this.multiple) {
13828
14075
  this.emitGroupEvent(EditorGroupEvent.BEFORE_GROUP);
@@ -13879,16 +14126,21 @@ class Editor extends Group {
13879
14126
  if (group)
13880
14127
  group.emitEvent(event);
13881
14128
  }
13882
- openInnerEditor(target, select) {
14129
+ openInnerEditor(target, nameOrSelect, select) {
14130
+ let name;
14131
+ if (typeof nameOrSelect === 'string')
14132
+ name = nameOrSelect;
14133
+ else if (!select)
14134
+ select = nameOrSelect;
13883
14135
  if (target && select)
13884
14136
  this.target = target;
13885
14137
  if (this.single) {
13886
14138
  const editTarget = target || this.element;
13887
- const tag = editTarget.editInner;
13888
- if (tag && EditToolCreator.list[tag]) {
14139
+ name || (name = editTarget.editInner);
14140
+ if (name && EditToolCreator.list[name]) {
13889
14141
  this.editTool.unload();
13890
14142
  this.innerEditing = true;
13891
- this.innerEditor = this.editToolList[tag] || EditToolCreator.get(tag, this);
14143
+ this.innerEditor = this.editToolList[name] = this.editToolList[name] || EditToolCreator.get(name, this);
13892
14144
  this.innerEditor.editTarget = editTarget;
13893
14145
  this.emitInnerEvent(InnerEditorEvent.BEFORE_OPEN);
13894
14146
  this.innerEditor.load();
@@ -13896,13 +14148,14 @@ class Editor extends Group {
13896
14148
  }
13897
14149
  }
13898
14150
  }
13899
- closeInnerEditor() {
14151
+ closeInnerEditor(onlyInnerEditor) {
13900
14152
  if (this.innerEditing) {
13901
14153
  this.innerEditing = false;
13902
14154
  this.emitInnerEvent(InnerEditorEvent.BEFORE_CLOSE);
13903
14155
  this.innerEditor.unload();
13904
14156
  this.emitInnerEvent(InnerEditorEvent.CLOSE);
13905
- this.editTool.load();
14157
+ if (!onlyInnerEditor)
14158
+ this.updateEditTool();
13906
14159
  this.innerEditor = null;
13907
14160
  }
13908
14161
  }
@@ -13940,22 +14193,12 @@ class Editor extends Group {
13940
14193
  if (this.targetChanged)
13941
14194
  this.update();
13942
14195
  }
13943
- onKey(e) {
13944
- updateCursor(this, e);
13945
- }
13946
14196
  listenTargetEvents() {
13947
14197
  if (!this.targetEventIds.length) {
13948
- const { app, leafer, editBox, editMask } = this;
14198
+ const { app, leafer, editMask } = this;
13949
14199
  this.targetEventIds = [
13950
14200
  leafer.on_(RenderEvent.START, this.onRenderStart, this),
13951
- app.on_([
13952
- [RenderEvent.CHILD_START, this.onAppRenderStart, this],
13953
- [MoveEvent.BEFORE_MOVE, this.onMove, this, true],
13954
- [ZoomEvent.BEFORE_ZOOM, this.onScale, this, true],
13955
- [RotateEvent.BEFORE_ROTATE, this.onRotate, this, true],
13956
- [[KeyEvent.HOLD, KeyEvent.UP], this.onKey, this],
13957
- [KeyEvent.DOWN, editBox.onArrow, editBox]
13958
- ])
14201
+ app.on_(RenderEvent.CHILD_START, this.onAppRenderStart, this)
13959
14202
  ];
13960
14203
  if (editMask.visible)
13961
14204
  editMask.forceRender();
@@ -13979,7 +14222,7 @@ class Editor extends Group {
13979
14222
  super.destroy();
13980
14223
  }
13981
14224
  }
13982
- }
14225
+ };
13983
14226
  __decorate([
13984
14227
  mergeConfigAttr()
13985
14228
  ], Editor.prototype, "mergeConfig", void 0);
@@ -13989,14 +14232,19 @@ __decorate([
13989
14232
  __decorate([
13990
14233
  targetAttr(onTarget)
13991
14234
  ], Editor.prototype, "target", void 0);
14235
+ Editor = __decorate([
14236
+ useModule(TransformTool, ['editBox', 'editTool', 'emitEvent'])
14237
+ ], Editor);
13992
14238
 
13993
14239
  class InnerEditor {
13994
14240
  static registerInnerEditor() {
13995
14241
  EditToolCreator.register(this);
13996
14242
  }
13997
14243
  get tag() { return 'InnerEditor'; }
14244
+ get mode() { return 'focus'; }
13998
14245
  get editBox() { return this.editor.editBox; }
13999
14246
  constructor(editor) {
14247
+ this.eventIds = [];
14000
14248
  this.editor = editor;
14001
14249
  this.create();
14002
14250
  }
@@ -14009,7 +14257,7 @@ class InnerEditor {
14009
14257
  load() {
14010
14258
  const { editor } = this;
14011
14259
  if (editor) {
14012
- if (editor.app)
14260
+ if (editor.app && this.mode === 'focus')
14013
14261
  editor.selector.hittable = editor.app.tree.hitChildren = false;
14014
14262
  this.onLoad();
14015
14263
  }
@@ -14020,7 +14268,7 @@ class InnerEditor {
14020
14268
  unload() {
14021
14269
  const { editor } = this;
14022
14270
  if (editor) {
14023
- if (editor.app)
14271
+ if (editor.app && this.mode === 'focus')
14024
14272
  editor.selector.hittable = editor.app.tree.hitChildren = true;
14025
14273
  this.onUnload();
14026
14274
  }
@@ -14094,10 +14342,7 @@ let EditTool = class EditTool extends InnerEditor {
14094
14342
  this.onLoad();
14095
14343
  }
14096
14344
  update() {
14097
- const { editor, editBox } = this;
14098
- const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = editor.element.getLayoutBounds('box', editor, true);
14099
- editBox.set({ x, y, scaleX, scaleY, rotation, skewX, skewY });
14100
- editBox.update({ x: 0, y: 0, width, height });
14345
+ this.editBox.update();
14101
14346
  this.onUpdate();
14102
14347
  }
14103
14348
  unload() {
@@ -14441,7 +14686,7 @@ Creator.editor = function (options, app) {
14441
14686
  };
14442
14687
  Box.addAttr('textBox', false, dataType);
14443
14688
  UI.addAttr('editConfig', undefined, dataType);
14444
- UI.addAttr('editOuter', (ui) => ui.__.__isLinePath ? 'LineEditTool' : 'EditTool', dataType);
14689
+ UI.addAttr('editOuter', (ui) => { ui.updateLayout(); return ui.__.__isLinePath ? 'LineEditTool' : 'EditTool'; }, dataType);
14445
14690
  UI.addAttr('editInner', 'PathEditor', dataType);
14446
14691
  Group.addAttr('editInner', '', dataType);
14447
14692
  Text.addAttr('editInner', 'TextEditor', dataType);
@@ -14838,8 +15083,16 @@ function getFixBounds(bounds, scaleBounds) {
14838
15083
  }
14839
15084
 
14840
15085
  Plugin.add('view');
14841
- Leafer.prototype.zoom = function (zoomType, padding, fixed, transition) {
15086
+ Leafer.prototype.zoom = function (zoomType, optionsOrPadding, scroll, transition) {
14842
15087
  this.killAnimate();
15088
+ let padding;
15089
+ if (typeof optionsOrPadding === 'object' && !(optionsOrPadding instanceof Array)) {
15090
+ padding = optionsOrPadding.padding;
15091
+ scroll = optionsOrPadding.scroll;
15092
+ transition = optionsOrPadding.transition;
15093
+ }
15094
+ else
15095
+ padding = optionsOrPadding;
14843
15096
  const { zoomLayer } = this;
14844
15097
  const limitBounds = this.canvas.bounds.clone().shrink(padding !== undefined ? padding : 30), bounds = new Bounds();
14845
15098
  const center = { x: limitBounds.x + limitBounds.width / 2, y: limitBounds.y + limitBounds.height / 2 };
@@ -14886,7 +15139,7 @@ Leafer.prototype.zoom = function (zoomType, padding, fixed, transition) {
14886
15139
  }
14887
15140
  const { width, height } = bounds;
14888
15141
  let moveX = limitBounds.x - bounds.x, moveY = limitBounds.y - bounds.y;
14889
- if (fixed) {
15142
+ if (scroll) {
14890
15143
  moveX += Math.max((limitBounds.width - width) / 2, 0);
14891
15144
  moveY += Math.max((limitBounds.height - height) / 2, 0);
14892
15145
  }
@@ -14899,6 +15152,10 @@ Leafer.prototype.zoom = function (zoomType, padding, fixed, transition) {
14899
15152
  data.scaleX *= changeScale;
14900
15153
  data.scaleY *= changeScale;
14901
15154
  }
15155
+ if (scroll === 'x')
15156
+ moveY = 0;
15157
+ else if (scroll === 'y')
15158
+ moveX = 0;
14902
15159
  PointHelper.move(data, moveX, moveY);
14903
15160
  bounds.move(moveX, moveY);
14904
15161
  zoomLayer.set(data, transition);
@@ -15790,9 +16047,8 @@ box.__updateContentBounds = function () {
15790
16047
  }
15791
16048
  };
15792
16049
  box.__updateBoxBounds = function (secondLayout) {
15793
- const data = this.__;
15794
16050
  if (this.children.length && !this.pathInputed) {
15795
- const { flow } = data;
16051
+ const data = this.__, { flow } = data;
15796
16052
  if (data.__autoSide) {
15797
16053
  if (data.__hasSurface)
15798
16054
  this.__extraUpdate();
@@ -16024,6 +16280,11 @@ let Animate = class Animate extends Eventer {
16024
16280
  this.play();
16025
16281
  }, 0);
16026
16282
  }
16283
+ emitType(type) {
16284
+ this.emit(type, this);
16285
+ if (this.parent)
16286
+ this.parent.onChildEvent(type, this);
16287
+ }
16027
16288
  play() {
16028
16289
  if (this.destroyed)
16029
16290
  return;
@@ -16032,20 +16293,20 @@ let Animate = class Animate extends Eventer {
16032
16293
  this.clearTimer(), this.start();
16033
16294
  else if (!this.timer)
16034
16295
  this.requestAnimate();
16035
- this.emit(AnimateEvent.PLAY, this);
16296
+ this.emitType(AnimateEvent.PLAY);
16036
16297
  }
16037
16298
  pause() {
16038
16299
  if (this.destroyed)
16039
16300
  return;
16040
16301
  this.running = false;
16041
16302
  this.clearTimer();
16042
- this.emit(AnimateEvent.PAUSE, this);
16303
+ this.emitType(AnimateEvent.PAUSE);
16043
16304
  }
16044
16305
  stop() {
16045
16306
  if (this.destroyed)
16046
16307
  return;
16047
16308
  this.complete();
16048
- this.emit(AnimateEvent.STOP, this);
16309
+ this.emitType(AnimateEvent.STOP);
16049
16310
  }
16050
16311
  seek(time) {
16051
16312
  if (this.destroyed)
@@ -16059,7 +16320,7 @@ let Animate = class Animate extends Eventer {
16059
16320
  this.time = time;
16060
16321
  this.animate(0, true);
16061
16322
  this.clearTimer(() => this.requestAnimate());
16062
- this.emit(AnimateEvent.SEEK, this);
16323
+ this.emitType(AnimateEvent.SEEK);
16063
16324
  }
16064
16325
  kill(complete = true, killStyle) {
16065
16326
  this.killStyle = killStyle;
@@ -16126,7 +16387,7 @@ let Animate = class Animate extends Eventer {
16126
16387
  if (totalTime)
16127
16388
  this.changeDuration(totalTime);
16128
16389
  }
16129
- this.emit(AnimateEvent.CREATED, this);
16390
+ this.emitType(AnimateEvent.CREATED);
16130
16391
  }
16131
16392
  changeDuration(duration) {
16132
16393
  const { config } = this;
@@ -16246,7 +16507,7 @@ let Animate = class Animate extends Eventer {
16246
16507
  key in killStyle || (style[key] = endingStyle[key]);
16247
16508
  this.setStyle(style);
16248
16509
  this.clearTimer();
16249
- this.emit(AnimateEvent.COMPLETED, this);
16510
+ this.emitType(AnimateEvent.COMPLETED);
16250
16511
  }
16251
16512
  setFrom() {
16252
16513
  this.nowIndex = 0;
@@ -16290,7 +16551,7 @@ let Animate = class Animate extends Eventer {
16290
16551
  Transition.setBetweenStyle(betweenStyle, fromStyle, toStyle, style, t, target, attrsMap);
16291
16552
  this.setStyle(betweenStyle);
16292
16553
  }
16293
- this.emit(AnimateEvent.UPDATE, this);
16554
+ this.emitType(AnimateEvent.UPDATE);
16294
16555
  }
16295
16556
  setStyle(style) {
16296
16557
  const { target } = this;
@@ -16334,7 +16595,7 @@ let Animate = class Animate extends Eventer {
16334
16595
  this.stop();
16335
16596
  else
16336
16597
  this.pause();
16337
- this.target = this.config = this.frames = this.fromStyle = this.toStyle = this.style = this.killStyle = null;
16598
+ this.target = this.parent = this.config = this.frames = this.fromStyle = this.toStyle = this.style = this.killStyle = null;
16338
16599
  this.destroyed = true;
16339
16600
  }
16340
16601
  }
@@ -16400,6 +16661,7 @@ let AnimateList = class AnimateList extends Animate {
16400
16661
  });
16401
16662
  this.list = animation.map(item => {
16402
16663
  const animate = item.target ? item : new Animate(this.target, item, isTemp);
16664
+ animate.parent = this;
16403
16665
  Object.assign(this.fromStyle, animate.fromStyle);
16404
16666
  Object.assign(this.toStyle, animate.toStyle);
16405
16667
  Object.assign(this._endingStyle, animate.endingStyle);
@@ -16408,20 +16670,34 @@ let AnimateList = class AnimateList extends Animate {
16408
16670
  }
16409
16671
  play() {
16410
16672
  this.each(item => item.play());
16673
+ this.emitType(AnimateEvent.PLAY);
16411
16674
  }
16412
16675
  pause() {
16413
16676
  this.each(item => item.pause());
16677
+ this.emitType(AnimateEvent.PAUSE);
16414
16678
  }
16415
16679
  stop() {
16416
16680
  this.each(item => item.stop());
16681
+ this.emitType(AnimateEvent.STOP);
16417
16682
  }
16418
16683
  seek(time) {
16419
16684
  this.each(item => item.seek(time));
16685
+ this.emitType(AnimateEvent.SEEK);
16420
16686
  }
16421
16687
  kill(complete, killStyle) {
16422
16688
  this.each(item => item.kill(complete, killStyle));
16423
16689
  this.destroy();
16424
16690
  }
16691
+ onChildEvent(type, _animate) {
16692
+ switch (type) {
16693
+ case AnimateEvent.COMPLETED:
16694
+ if (this.completed)
16695
+ this.emitType(type);
16696
+ break;
16697
+ case AnimateEvent.UPDATE:
16698
+ this.emitType(type);
16699
+ }
16700
+ }
16425
16701
  each(func) {
16426
16702
  this.list.forEach(func);
16427
16703
  }
@@ -17880,123 +18156,131 @@ function getTrimBounds(canvas) {
17880
18156
  index++;
17881
18157
  }
17882
18158
  const bounds = new Bounds();
17883
- toBounds(pointBounds, bounds);
17884
- return bounds.scale(1 / canvas.pixelRatio).ceil();
18159
+ if (pointBounds) {
18160
+ toBounds(pointBounds, bounds);
18161
+ bounds.scale(1 / canvas.pixelRatio).ceil();
18162
+ }
18163
+ return bounds;
17885
18164
  }
17886
18165
 
17887
18166
  const ExportModule = {
17888
18167
  syncExport(leaf, filename, options) {
17889
- this.running = true;
18168
+ Export.running = true;
17890
18169
  let result;
17891
- const fileType = FileHelper.fileType(filename);
17892
- const isDownload = filename.includes('.');
17893
- options = FileHelper.getExportOptions(options);
17894
- const { toURL } = Platform;
17895
- const { download } = Platform.origin;
17896
- if (fileType === 'json') {
17897
- isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
17898
- result = { data: isDownload ? true : leaf.toJSON(options.json) };
17899
- }
17900
- else if (fileType === 'svg') {
17901
- isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
17902
- result = { data: isDownload ? true : leaf.toSVG() };
17903
- }
17904
- else {
17905
- let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
17906
- const { worldTransform, isLeafer, leafer, isFrame } = leaf;
17907
- const { slice, clip, trim, screenshot, padding, onCanvas } = options;
17908
- const smooth = options.smooth === undefined ? (leafer ? leafer.config.smooth : true) : options.smooth;
17909
- const contextSettings = options.contextSettings || (leafer ? leafer.config.contextSettings : undefined);
17910
- const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
17911
- const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
17912
- if (screenshot) {
17913
- renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
18170
+ try {
18171
+ const fileType = FileHelper.fileType(filename);
18172
+ const isDownload = filename.includes('.');
18173
+ options = FileHelper.getExportOptions(options);
18174
+ const { toURL } = Platform;
18175
+ const { download } = Platform.origin;
18176
+ if (fileType === 'json') {
18177
+ isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
18178
+ result = { data: isDownload ? true : leaf.toJSON(options.json) };
18179
+ }
18180
+ else if (fileType === 'svg') {
18181
+ isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
18182
+ result = { data: isDownload ? true : leaf.toSVG() };
17914
18183
  }
17915
18184
  else {
17916
- let relative = options.relative || (isLeafer ? 'inner' : 'local');
17917
- scaleX = worldTransform.scaleX;
17918
- scaleY = worldTransform.scaleY;
17919
- switch (relative) {
17920
- case 'inner':
17921
- matrix.set(worldTransform);
17922
- break;
17923
- case 'local':
17924
- matrix.set(worldTransform).divide(leaf.localTransform);
17925
- scaleX /= leaf.scaleX;
17926
- scaleY /= leaf.scaleY;
17927
- break;
17928
- case 'world':
17929
- scaleX = 1;
17930
- scaleY = 1;
17931
- break;
17932
- case 'page':
17933
- relative = leafer || leaf;
17934
- default:
17935
- matrix.set(worldTransform).divide(leaf.getTransform(relative));
17936
- const l = relative.worldTransform;
17937
- scaleX /= scaleX / l.scaleX;
17938
- scaleY /= scaleY / l.scaleY;
18185
+ let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
18186
+ const { worldTransform, isLeafer, leafer, isFrame } = leaf;
18187
+ const { slice, clip, trim, screenshot, padding, onCanvas } = options;
18188
+ const smooth = options.smooth === undefined ? (leafer ? leafer.config.smooth : true) : options.smooth;
18189
+ const contextSettings = options.contextSettings || (leafer ? leafer.config.contextSettings : undefined);
18190
+ const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
18191
+ const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
18192
+ if (screenshot) {
18193
+ renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
17939
18194
  }
17940
- renderBounds = leaf.getBounds('render', relative);
17941
- }
17942
- const scaleData = { scaleX: 1, scaleY: 1 };
17943
- MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
17944
- let pixelRatio = options.pixelRatio || 1;
17945
- let { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
17946
- if (clip)
17947
- x += clip.x, y += clip.y, width = clip.width, height = clip.height;
17948
- 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) };
17949
- let canvas = Creator.canvas({ width: Math.floor(width), height: Math.floor(height), pixelRatio, smooth, contextSettings });
17950
- let sliceLeaf;
17951
- if (slice) {
17952
- sliceLeaf = leaf;
17953
- sliceLeaf.__worldOpacity = 0;
17954
- leaf = leafer || leaf;
17955
- renderOptions.bounds = canvas.bounds;
17956
- }
17957
- canvas.save();
17958
- if (isFrame && fill !== undefined) {
17959
- const oldFill = leaf.get('fill');
17960
- leaf.fill = '';
17961
- leaf.__render(canvas, renderOptions);
17962
- leaf.fill = oldFill;
17963
- }
17964
- else {
17965
- leaf.__render(canvas, renderOptions);
17966
- }
17967
- canvas.restore();
17968
- if (sliceLeaf)
17969
- sliceLeaf.__updateWorldOpacity();
17970
- if (trim) {
17971
- trimBounds = getTrimBounds(canvas);
17972
- const old = canvas, { width, height } = trimBounds;
17973
- const config = { x: 0, y: 0, width, height, pixelRatio };
17974
- canvas = Creator.canvas(config);
17975
- canvas.copyWorld(old, trimBounds, config);
18195
+ else {
18196
+ let relative = options.relative || (isLeafer ? 'inner' : 'local');
18197
+ scaleX = worldTransform.scaleX;
18198
+ scaleY = worldTransform.scaleY;
18199
+ switch (relative) {
18200
+ case 'inner':
18201
+ matrix.set(worldTransform);
18202
+ break;
18203
+ case 'local':
18204
+ matrix.set(worldTransform).divide(leaf.localTransform);
18205
+ scaleX /= leaf.scaleX;
18206
+ scaleY /= leaf.scaleY;
18207
+ break;
18208
+ case 'world':
18209
+ scaleX = 1;
18210
+ scaleY = 1;
18211
+ break;
18212
+ case 'page':
18213
+ relative = leafer || leaf;
18214
+ default:
18215
+ matrix.set(worldTransform).divide(leaf.getTransform(relative));
18216
+ const l = relative.worldTransform;
18217
+ scaleX /= scaleX / l.scaleX;
18218
+ scaleY /= scaleY / l.scaleY;
18219
+ }
18220
+ renderBounds = leaf.getBounds('render', relative);
18221
+ }
18222
+ const scaleData = { scaleX: 1, scaleY: 1 };
18223
+ MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
18224
+ let pixelRatio = options.pixelRatio || 1;
18225
+ let { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
18226
+ if (clip)
18227
+ x += clip.x, y += clip.y, width = clip.width, height = clip.height;
18228
+ 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) };
18229
+ let canvas = Creator.canvas({ width: Math.floor(width), height: Math.floor(height), pixelRatio, smooth, contextSettings });
18230
+ let sliceLeaf;
18231
+ if (slice) {
18232
+ sliceLeaf = leaf;
18233
+ sliceLeaf.__worldOpacity = 0;
18234
+ leaf = leafer || leaf;
18235
+ renderOptions.bounds = canvas.bounds;
18236
+ }
18237
+ canvas.save();
18238
+ if (isFrame && fill !== undefined) {
18239
+ const oldFill = leaf.get('fill');
18240
+ leaf.fill = '';
18241
+ leaf.__render(canvas, renderOptions);
18242
+ leaf.fill = oldFill;
18243
+ }
18244
+ else {
18245
+ leaf.__render(canvas, renderOptions);
18246
+ }
18247
+ canvas.restore();
18248
+ if (sliceLeaf)
18249
+ sliceLeaf.__updateWorldOpacity();
18250
+ if (trim) {
18251
+ trimBounds = getTrimBounds(canvas);
18252
+ const old = canvas, { width, height } = trimBounds;
18253
+ const config = { x: 0, y: 0, width, height, pixelRatio };
18254
+ canvas = Creator.canvas(config);
18255
+ canvas.copyWorld(old, trimBounds, config);
18256
+ }
18257
+ if (padding) {
18258
+ const [top, right, bottom, left] = MathHelper.fourNumber(padding);
18259
+ const old = canvas, { width, height } = old;
18260
+ canvas = Creator.canvas({ width: width + left + right, height: height + top + bottom, pixelRatio });
18261
+ canvas.copyWorld(old, old.bounds, { x: left, y: top, width, height });
18262
+ }
18263
+ if (needFill)
18264
+ canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
18265
+ if (onCanvas)
18266
+ onCanvas(canvas);
18267
+ const data = filename === 'canvas' ? canvas : canvas.export(filename, options);
18268
+ result = { data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds };
17976
18269
  }
17977
- if (padding) {
17978
- const [top, right, bottom, left] = MathHelper.fourNumber(padding);
17979
- const old = canvas, { width, height } = old;
17980
- canvas = Creator.canvas({ width: width + left + right, height: height + top + bottom, pixelRatio });
17981
- canvas.copyWorld(old, old.bounds, { x: left, y: top, width, height });
17982
- }
17983
- if (needFill)
17984
- canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
17985
- if (onCanvas)
17986
- onCanvas(canvas);
17987
- const data = filename === 'canvas' ? canvas : canvas.export(filename, options);
17988
- result = { data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds };
17989
18270
  }
17990
- this.running = false;
18271
+ catch (error) {
18272
+ result = { data: '', error };
18273
+ }
18274
+ Export.running = false;
17991
18275
  return result;
17992
18276
  },
17993
18277
  export(leaf, filename, options) {
17994
- this.running = true;
18278
+ Export.running = true;
17995
18279
  return addTask((success) => new Promise((resolve) => {
17996
18280
  const getResult = () => __awaiter(this, void 0, void 0, function* () {
17997
18281
  if (!Resource.isComplete)
17998
18282
  return Platform.requestRender(getResult);
17999
- const result = ExportModule.syncExport(leaf, filename, options);
18283
+ const result = Export.syncExport(leaf, filename, options);
18000
18284
  if (result.data instanceof Promise)
18001
18285
  result.data = yield result.data;
18002
18286
  success(result);
@@ -18096,4 +18380,4 @@ Object.assign(Filter, {
18096
18380
  }
18097
18381
  });
18098
18382
 
18099
- export { AlignHelper, Animate, AnimateEasing, AnimateEvent, AnimateList, Answer, App, AroundHelper, Arrow, ArrowData, AutoBounds, BezierHelper, Bounds, BoundsEvent, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, Cursor, DataHelper, Debug, Direction4, Direction9, DragEvent, Dragger, DropEvent, EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorGroupEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Eventer, Export, FileHelper, Filter, Finder, Flow, Frame, FrameData, Group, GroupData, HighBezierHelper, HighCurveHelper, HitCanvasManager, Image, ImageData, ImageEvent, ImageManager, IncrementId, InnerEditor, InnerEditorEvent, Interaction, InteractionBase, InteractionHelper, KeyEvent, Keyboard, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, LeaferTypeCreator, Line, LineData, LineEditTool, MathHelper, Matrix, MatrixHelper, MoveEvent, MultiTouchHelper, MyDragEvent, MyImage, MyPointerEvent, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, PaintGradient, PaintImage, Path, PathArrow, PathArrowModule, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathMatrixHelper, PathNumberCommandLengthMap, PathNumberCommandMap, PathScaler, Pen, PenData, Picker, Platform, Plugin, Point, PointHelper, PointerButton, PointerEvent, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, Resource, Robot, RobotData, RotateEvent, Run, ScrollBar, SelectArea, Selector, Star, StarData, State, StringNumberMap, Stroker, SwipeEvent, TaskItem, TaskProcessor, Text, TextConvert, TextData, Transformer, Transition, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIEvent, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, WheelEventHelper, ZoomEvent, addViewport, addViewportConfig, affectRenderBoundsType, affectStrokeBoundsType, arrowType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, effectType, emptyData, eraserType, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, isEmptyData, isNull, layoutProcessor, maskType, motionPathType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, registerEditTool, registerInnerEditor, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleResize, scaleResizeFontSize, scaleResizeGroup, scaleResizePath, scaleResizePoints, scaleType, sortType, stateStyleType, stateType, strokeType, surfaceType, tempBounds$1 as tempBounds, tempMatrix, tempPoint$3 as tempPoint, useCanvas, useModule, version, visibleType, zoomLayerType };
18383
+ export { AlignHelper, Animate, AnimateEasing, AnimateEvent, AnimateList, Answer, App, AroundHelper, Arrow, ArrowData, AutoBounds, BezierHelper, Bounds, BoundsEvent, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, Cursor, DataHelper, Debug, Direction4, Direction9, DragEvent, Dragger, DropEvent, EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorGroupEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Eventer, Export, FileHelper, Filter, Finder, Flow, Frame, FrameData, Group, GroupData, HighBezierHelper, HighCurveHelper, HitCanvasManager, Image, ImageData, ImageEvent, ImageManager, IncrementId, InnerEditor, InnerEditorEvent, Interaction, InteractionBase, InteractionHelper, KeyEvent, Keyboard, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, LeaferTypeCreator, Line, LineData, LineEditTool, MathHelper, Matrix, MatrixHelper, MoveEvent, MultiTouchHelper, MyDragEvent, MyImage, MyPointerEvent, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, PaintGradient, PaintImage, Path, PathArrow, PathArrowModule, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathMatrixHelper, PathNumberCommandLengthMap, PathNumberCommandMap, PathScaler, Pen, PenData, Picker, Platform, Plugin, Point, PointHelper, PointerButton, PointerEvent, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, Resource, Robot, RobotData, RotateEvent, Run, ScrollBar, SelectArea, Selector, Star, StarData, State, StringNumberMap, Stroker, SwipeEvent, TaskItem, TaskProcessor, Text, TextConvert, TextData, TransformTool, Transformer, Transition, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIEvent, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, WheelEventHelper, ZoomEvent, addViewport, addViewportConfig, affectRenderBoundsType, affectStrokeBoundsType, arrowType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, 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 };