@leafer-editor/worker 1.0.0 → 1.0.2

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.
@@ -48,6 +48,8 @@ const I$2 = IncrementId;
48
48
  const { round, pow: pow$1, PI: PI$4 } = Math;
49
49
  const MathHelper = {
50
50
  within(value, min, max) {
51
+ if (typeof min === 'object')
52
+ max = min.max, min = min.min;
51
53
  if (min !== undefined && value < min)
52
54
  value = min;
53
55
  if (max !== undefined && value > max)
@@ -109,6 +111,19 @@ const MathHelper = {
109
111
  const a = maxLength ? pow$1(10, maxLength) : 1000000000000;
110
112
  num = round(num * a) / a;
111
113
  return num === -0 ? 0 : num;
114
+ },
115
+ getScaleData(scale, size, originSize, scaleData) {
116
+ if (!scaleData)
117
+ scaleData = {};
118
+ if (size) {
119
+ scaleData.scaleX = (typeof size === 'number' ? size : size.width) / originSize.width;
120
+ scaleData.scaleY = (typeof size === 'number' ? size : size.height) / originSize.height;
121
+ }
122
+ else if (scale) {
123
+ scaleData.scaleX = typeof scale === 'number' ? scale : scale.x;
124
+ scaleData.scaleY = typeof scale === 'number' ? scale : scale.y;
125
+ }
126
+ return scaleData;
112
127
  }
113
128
  };
114
129
  const OneRadian = PI$4 / 180;
@@ -150,10 +165,10 @@ const MatrixHelper = {
150
165
  t.e += x;
151
166
  t.f += y;
152
167
  },
153
- translateInner(t, x, y, isMoveOrigin) {
168
+ translateInner(t, x, y, hasOrigin) {
154
169
  t.e += t.a * x + t.c * y;
155
170
  t.f += t.b * x + t.d * y;
156
- if (isMoveOrigin)
171
+ if (hasOrigin)
157
172
  t.e -= x, t.f -= y;
158
173
  },
159
174
  scale(t, scaleX, scaleY = scaleX) {
@@ -312,7 +327,7 @@ const MatrixHelper = {
312
327
  to.y -= (f * a - e * b) * s;
313
328
  }
314
329
  },
315
- setLayout(t, layout, origin, bcChanged) {
330
+ setLayout(t, layout, origin, around, bcChanged) {
316
331
  const { x, y, scaleX, scaleY } = layout;
317
332
  if (bcChanged === undefined)
318
333
  bcChanged = layout.rotation || layout.skewX || layout.skewY;
@@ -344,10 +359,10 @@ const MatrixHelper = {
344
359
  }
345
360
  t.e = x;
346
361
  t.f = y;
347
- if (origin)
348
- M$9.translateInner(t, -origin.x, -origin.y, true);
362
+ if (origin = origin || around)
363
+ M$9.translateInner(t, -origin.x, -origin.y, !around);
349
364
  },
350
- getLayout(t, origin, firstSkewY) {
365
+ getLayout(t, origin, around, firstSkewY) {
351
366
  const { a, b, c, d, e, f } = t;
352
367
  let x = e, y = f, scaleX, scaleY, rotation, skewX, skewY;
353
368
  if (b || c) {
@@ -376,9 +391,11 @@ const MatrixHelper = {
376
391
  scaleY = d;
377
392
  rotation = skewX = skewY = 0;
378
393
  }
379
- if (origin) {
394
+ if (origin = around || origin) {
380
395
  x += origin.x * a + origin.y * c;
381
396
  y += origin.x * b + origin.y * d;
397
+ if (!around)
398
+ x -= origin.x, y -= origin.y;
382
399
  }
383
400
  return { x, y, scaleX, scaleY, rotation, skewX, skewY };
384
401
  },
@@ -405,7 +422,7 @@ const MatrixHelper = {
405
422
  };
406
423
  const M$9 = MatrixHelper;
407
424
 
408
- const { toInnerPoint: toInnerPoint$2, toOuterPoint: toOuterPoint$2 } = MatrixHelper;
425
+ const { toInnerPoint: toInnerPoint$2, toOuterPoint: toOuterPoint$3 } = MatrixHelper;
409
426
  const { sin: sin$4, cos: cos$4, abs: abs$5, sqrt: sqrt$2, atan2: atan2$2, min: min$1, PI: PI$3 } = Math;
410
427
  const PointHelper = {
411
428
  defaultPoint: getPointData(),
@@ -461,7 +478,7 @@ const PointHelper = {
461
478
  tempToOuterOf(t, matrix) {
462
479
  const { tempPoint: temp } = P$7;
463
480
  copy$e(temp, t);
464
- toOuterPoint$2(matrix, temp, temp);
481
+ toOuterPoint$3(matrix, temp, temp);
465
482
  return temp;
466
483
  },
467
484
  tempToInnerRadiusPointOf(t, matrix) {
@@ -480,7 +497,7 @@ const PointHelper = {
480
497
  toInnerPoint$2(matrix, t, to);
481
498
  },
482
499
  toOuterOf(t, matrix, to) {
483
- toOuterPoint$2(matrix, t, to);
500
+ toOuterPoint$3(matrix, t, to);
484
501
  },
485
502
  getCenter(t, to) {
486
503
  return { x: t.x + (to.x - t.x) / 2, y: t.y + (to.y - t.y) / 2 };
@@ -706,12 +723,12 @@ class Matrix {
706
723
  toInnerPoint(outer, to, distance) {
707
724
  MatrixHelper.toInnerPoint(this, outer, to, distance);
708
725
  }
709
- setLayout(data, origin) {
710
- MatrixHelper.setLayout(this, data, origin);
726
+ setLayout(data, origin, around) {
727
+ MatrixHelper.setLayout(this, data, origin, around);
711
728
  return this;
712
729
  }
713
- getLayout(origin, firstSkewY) {
714
- return MatrixHelper.getLayout(this, origin, firstSkewY);
730
+ getLayout(origin, around, firstSkewY) {
731
+ return MatrixHelper.getLayout(this, origin, around, firstSkewY);
715
732
  }
716
733
  withScale(scaleX, scaleY) {
717
734
  return MatrixHelper.withScale(this, scaleX, scaleY);
@@ -760,10 +777,10 @@ const TwoPointBoundsHelper = {
760
777
  const { addPoint: addPoint$4 } = TwoPointBoundsHelper;
761
778
 
762
779
  const { tempPointBounds: tempPointBounds$1, setPoint: setPoint$5, addPoint: addPoint$3, toBounds: toBounds$4 } = TwoPointBoundsHelper;
763
- const { toOuterPoint: toOuterPoint$1 } = MatrixHelper;
780
+ const { toOuterPoint: toOuterPoint$2 } = MatrixHelper;
764
781
  const { float, fourNumber } = MathHelper;
765
782
  const { floor, ceil: ceil$2 } = Math;
766
- let right$3, bottom$2, boundsRight, boundsBottom;
783
+ let right$4, bottom$3, boundsRight, boundsBottom;
767
784
  const point$1 = {};
768
785
  const toPoint$6 = {};
769
786
  const BoundsHelper = {
@@ -780,17 +797,24 @@ const BoundsHelper = {
780
797
  t.width = bounds.width;
781
798
  t.height = bounds.height;
782
799
  },
783
- copyAndSpread(t, bounds, spread, isShrink) {
800
+ copyAndSpread(t, bounds, spread, isShrink, side) {
801
+ const { x, y, width, height } = bounds;
784
802
  if (spread instanceof Array) {
785
803
  const four = fourNumber(spread);
786
804
  isShrink
787
- ? B.set(t, bounds.x + four[3], bounds.y + four[0], bounds.width - four[1] - four[3], bounds.height - four[2] - four[0])
788
- : B.set(t, bounds.x - four[3], bounds.y - four[0], bounds.width + four[1] + four[3], bounds.height + four[2] + four[0]);
805
+ ? B.set(t, x + four[3], y + four[0], width - four[1] - four[3], height - four[2] - four[0])
806
+ : B.set(t, x - four[3], y - four[0], width + four[1] + four[3], height + four[2] + four[0]);
789
807
  }
790
808
  else {
791
809
  if (isShrink)
792
810
  spread = -spread;
793
- B.set(t, bounds.x - spread, bounds.y - spread, bounds.width + spread * 2, bounds.height + spread * 2);
811
+ B.set(t, x - spread, y - spread, width + spread * 2, height + spread * 2);
812
+ }
813
+ if (side) {
814
+ if (side === 'width')
815
+ t.y = y, t.height = height;
816
+ else
817
+ t.x = x, t.width = width;
794
818
  }
795
819
  },
796
820
  minX(t) { return t.width > 0 ? t.x : t.x + t.width; },
@@ -867,16 +891,16 @@ const BoundsHelper = {
867
891
  else {
868
892
  point$1.x = t.x;
869
893
  point$1.y = t.y;
870
- toOuterPoint$1(matrix, point$1, toPoint$6);
894
+ toOuterPoint$2(matrix, point$1, toPoint$6);
871
895
  setPoint$5(tempPointBounds$1, toPoint$6.x, toPoint$6.y);
872
896
  point$1.x = t.x + t.width;
873
- toOuterPoint$1(matrix, point$1, toPoint$6);
897
+ toOuterPoint$2(matrix, point$1, toPoint$6);
874
898
  addPoint$3(tempPointBounds$1, toPoint$6.x, toPoint$6.y);
875
899
  point$1.y = t.y + t.height;
876
- toOuterPoint$1(matrix, point$1, toPoint$6);
900
+ toOuterPoint$2(matrix, point$1, toPoint$6);
877
901
  addPoint$3(tempPointBounds$1, toPoint$6.x, toPoint$6.y);
878
902
  point$1.x = t.x;
879
- toOuterPoint$1(matrix, point$1, toPoint$6);
903
+ toOuterPoint$2(matrix, point$1, toPoint$6);
880
904
  addPoint$3(tempPointBounds$1, toPoint$6.x, toPoint$6.y);
881
905
  toBounds$4(tempPointBounds$1, to);
882
906
  }
@@ -890,16 +914,16 @@ const BoundsHelper = {
890
914
  const scale = Math.min(baseScale, Math.min(t.width / put.width, t.height / put.height));
891
915
  return new Matrix(scale, 0, 0, scale, -put.x * scale, -put.y * scale);
892
916
  },
893
- getSpread(t, spread) {
917
+ getSpread(t, spread, side) {
894
918
  const n = {};
895
- B.copyAndSpread(n, t, spread);
919
+ B.copyAndSpread(n, t, spread, false, side);
896
920
  return n;
897
921
  },
898
- spread(t, spread) {
899
- B.copyAndSpread(t, t, spread);
922
+ spread(t, spread, side) {
923
+ B.copyAndSpread(t, t, spread, false, side);
900
924
  },
901
- shrink(t, shrink) {
902
- B.copyAndSpread(t, t, shrink, true);
925
+ shrink(t, shrink, side) {
926
+ B.copyAndSpread(t, t, shrink, true, side);
903
927
  },
904
928
  ceil(t) {
905
929
  const { x, y } = t;
@@ -925,20 +949,20 @@ const BoundsHelper = {
925
949
  t.height = float(t.height, maxLength);
926
950
  },
927
951
  add(t, bounds, isPoint) {
928
- right$3 = t.x + t.width;
929
- bottom$2 = t.y + t.height;
952
+ right$4 = t.x + t.width;
953
+ bottom$3 = t.y + t.height;
930
954
  boundsRight = bounds.x;
931
955
  boundsBottom = bounds.y;
932
956
  if (!isPoint) {
933
957
  boundsRight += bounds.width;
934
958
  boundsBottom += bounds.height;
935
959
  }
936
- right$3 = right$3 > boundsRight ? right$3 : boundsRight;
937
- bottom$2 = bottom$2 > boundsBottom ? bottom$2 : boundsBottom;
960
+ right$4 = right$4 > boundsRight ? right$4 : boundsRight;
961
+ bottom$3 = bottom$3 > boundsBottom ? bottom$3 : boundsBottom;
938
962
  t.x = t.x < bounds.x ? t.x : bounds.x;
939
963
  t.y = t.y < bounds.y ? t.y : bounds.y;
940
- t.width = right$3 - t.x;
941
- t.height = bottom$2 - t.y;
964
+ t.width = right$4 - t.x;
965
+ t.height = bottom$3 - t.y;
942
966
  },
943
967
  addList(t, list) {
944
968
  B.setListWithFn(t, list, undefined, true);
@@ -1012,16 +1036,16 @@ const BoundsHelper = {
1012
1036
  if (!B.hit(t, other))
1013
1037
  return getBoundsData();
1014
1038
  let { x, y, width, height } = other;
1015
- right$3 = x + width;
1016
- bottom$2 = y + height;
1039
+ right$4 = x + width;
1040
+ bottom$3 = y + height;
1017
1041
  boundsRight = t.x + t.width;
1018
1042
  boundsBottom = t.y + t.height;
1019
1043
  x = x > t.x ? x : t.x;
1020
1044
  y = y > t.y ? y : t.y;
1021
- right$3 = right$3 < boundsRight ? right$3 : boundsRight;
1022
- bottom$2 = bottom$2 < boundsBottom ? bottom$2 : boundsBottom;
1023
- width = right$3 - x;
1024
- height = bottom$2 - y;
1045
+ right$4 = right$4 < boundsRight ? right$4 : boundsRight;
1046
+ bottom$3 = bottom$3 < boundsBottom ? bottom$3 : boundsBottom;
1047
+ width = right$4 - x;
1048
+ height = bottom$3 - y;
1025
1049
  return { x, y, width, height };
1026
1050
  },
1027
1051
  intersect(t, other, otherMatrix) {
@@ -1082,12 +1106,12 @@ class Bounds {
1082
1106
  getFitMatrix(put, baseScale) {
1083
1107
  return BoundsHelper.getFitMatrix(this, put, baseScale);
1084
1108
  }
1085
- spread(fourNumber) {
1086
- BoundsHelper.spread(this, fourNumber);
1109
+ spread(fourNumber, side) {
1110
+ BoundsHelper.spread(this, fourNumber, side);
1087
1111
  return this;
1088
1112
  }
1089
- shrink(fourNumber) {
1090
- BoundsHelper.shrink(this, fourNumber);
1113
+ shrink(fourNumber, side) {
1114
+ BoundsHelper.shrink(this, fourNumber, side);
1091
1115
  return this;
1092
1116
  }
1093
1117
  ceil() {
@@ -1999,7 +2023,7 @@ class LeaferCanvasBase extends Canvas$1 {
1999
2023
  DataHelper.copyAttrs(this.size, size, canvasSizeAttrs);
2000
2024
  this.size.pixelRatio || (this.size.pixelRatio = 1);
2001
2025
  this.bounds = new Bounds(0, 0, this.width, this.height);
2002
- if (!this.unreal) {
2026
+ if (this.context && !this.unreal) {
2003
2027
  this.updateViewSize();
2004
2028
  this.smooth = this.config.smooth;
2005
2029
  }
@@ -2172,7 +2196,7 @@ class LeaferCanvasBase extends Canvas$1 {
2172
2196
  this.manager ? this.manager.recycle(this) : this.destroy();
2173
2197
  }
2174
2198
  }
2175
- updateRender() { }
2199
+ updateRender(_bounds) { }
2176
2200
  unrealCanvas() { }
2177
2201
  destroy() {
2178
2202
  this.manager = this.view = this.parentView = null;
@@ -2904,60 +2928,75 @@ class PathCreator {
2904
2928
  }
2905
2929
  beginPath() {
2906
2930
  beginPath(this.__path);
2931
+ this.paint();
2907
2932
  return this;
2908
2933
  }
2909
2934
  moveTo(x, y) {
2910
2935
  moveTo$4(this.__path, x, y);
2936
+ this.paint();
2911
2937
  return this;
2912
2938
  }
2913
2939
  lineTo(x, y) {
2914
2940
  lineTo$3(this.__path, x, y);
2941
+ this.paint();
2915
2942
  return this;
2916
2943
  }
2917
2944
  bezierCurveTo(x1, y1, x2, y2, x, y) {
2918
2945
  bezierCurveTo(this.__path, x1, y1, x2, y2, x, y);
2946
+ this.paint();
2919
2947
  return this;
2920
2948
  }
2921
2949
  quadraticCurveTo(x1, y1, x, y) {
2922
2950
  quadraticCurveTo(this.__path, x1, y1, x, y);
2951
+ this.paint();
2923
2952
  return this;
2924
2953
  }
2925
2954
  closePath() {
2926
2955
  closePath$3(this.__path);
2956
+ this.paint();
2927
2957
  return this;
2928
2958
  }
2929
2959
  rect(x, y, width, height) {
2930
2960
  rect$2(this.__path, x, y, width, height);
2961
+ this.paint();
2931
2962
  return this;
2932
2963
  }
2933
2964
  roundRect(x, y, width, height, cornerRadius) {
2934
2965
  roundRect$1(this.__path, x, y, width, height, cornerRadius);
2966
+ this.paint();
2935
2967
  return this;
2936
2968
  }
2937
2969
  ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise) {
2938
2970
  ellipse$2(this.__path, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise);
2971
+ this.paint();
2939
2972
  return this;
2940
2973
  }
2941
2974
  arc(x, y, radius, startAngle, endAngle, anticlockwise) {
2942
2975
  arc$1(this.__path, x, y, radius, startAngle, endAngle, anticlockwise);
2976
+ this.paint();
2943
2977
  return this;
2944
2978
  }
2945
2979
  arcTo(x1, y1, x2, y2, radius) {
2946
2980
  arcTo$2(this.__path, x1, y1, x2, y2, radius);
2981
+ this.paint();
2947
2982
  return this;
2948
2983
  }
2949
2984
  drawEllipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise) {
2950
2985
  drawEllipse(this.__path, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise);
2986
+ this.paint();
2951
2987
  return this;
2952
2988
  }
2953
2989
  drawArc(x, y, radius, startAngle, endAngle, anticlockwise) {
2954
2990
  drawArc(this.__path, x, y, radius, startAngle, endAngle, anticlockwise);
2991
+ this.paint();
2955
2992
  return this;
2956
2993
  }
2957
2994
  drawPoints(points, curve, close) {
2958
2995
  drawPoints$2(this.__path, points, curve, close);
2996
+ this.paint();
2959
2997
  return this;
2960
2998
  }
2999
+ paint() { }
2961
3000
  }
2962
3001
 
2963
3002
  const { M: M$5, L: L$6, C: C$5, Q: Q$4, Z: Z$4, N: N$3, D: D$3, X: X$3, G: G$3, F: F$4, O: O$4, P: P$3, U: U$3 } = PathCommandMap;
@@ -3979,7 +4018,7 @@ function registerUIEvent() {
3979
4018
  };
3980
4019
  }
3981
4020
 
3982
- const { copy: copy$a, toInnerPoint: toInnerPoint$1, scaleOfOuter: scaleOfOuter$2, rotateOfOuter: rotateOfOuter$2, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
4021
+ const { copy: copy$a, toInnerPoint: toInnerPoint$1, toOuterPoint: toOuterPoint$1, scaleOfOuter: scaleOfOuter$2, rotateOfOuter: rotateOfOuter$2, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
3983
4022
  const matrix$3 = {};
3984
4023
  const LeafHelper = {
3985
4024
  updateAllMatrix(leaf, checkAutoLayout, waitAutoLayout) {
@@ -4044,10 +4083,9 @@ const LeafHelper = {
4044
4083
  }
4045
4084
  return true;
4046
4085
  },
4047
- moveWorld(t, x, y = 0) {
4086
+ moveWorld(t, x, y = 0, isInnerPoint) {
4048
4087
  const local = typeof x === 'object' ? Object.assign({}, x) : { x, y };
4049
- if (t.parent)
4050
- toInnerPoint$1(t.parent.worldTransform, local, local, true);
4088
+ isInnerPoint ? toOuterPoint$1(t.localTransform, local, local, true) : (t.parent && toInnerPoint$1(t.parent.worldTransform, local, local, true));
4051
4089
  L$3.moveLocal(t, local.x, local.y);
4052
4090
  },
4053
4091
  moveLocal(t, x, y = 0) {
@@ -4066,8 +4104,13 @@ const LeafHelper = {
4066
4104
  zoomOfLocal(t, origin, scaleX, scaleY = scaleX, resize) {
4067
4105
  copy$a(matrix$3, t.__localMatrix);
4068
4106
  scaleOfOuter$2(matrix$3, origin, scaleX, scaleY);
4069
- moveByMatrix(t, matrix$3);
4070
- t.scaleResize(scaleX, scaleY, resize !== true);
4107
+ if (t.origin || t.around) {
4108
+ L$3.setTransform(t, matrix$3, resize);
4109
+ }
4110
+ else {
4111
+ moveByMatrix(t, matrix$3);
4112
+ t.scaleResize(scaleX, scaleY, resize !== true);
4113
+ }
4071
4114
  },
4072
4115
  rotateOfWorld(t, origin, angle) {
4073
4116
  L$3.rotateOfLocal(t, getTempLocal(t, origin), angle);
@@ -4075,8 +4118,13 @@ const LeafHelper = {
4075
4118
  rotateOfLocal(t, origin, angle) {
4076
4119
  copy$a(matrix$3, t.__localMatrix);
4077
4120
  rotateOfOuter$2(matrix$3, origin, angle);
4078
- moveByMatrix(t, matrix$3);
4079
- t.rotation = MathHelper.formatRotation(t.rotation + angle);
4121
+ if (t.origin || t.around) {
4122
+ L$3.setTransform(t, matrix$3);
4123
+ }
4124
+ else {
4125
+ moveByMatrix(t, matrix$3);
4126
+ t.rotation = MathHelper.formatRotation(t.rotation + angle);
4127
+ }
4080
4128
  },
4081
4129
  skewOfWorld(t, origin, skewX, skewY, resize) {
4082
4130
  L$3.skewOfLocal(t, getTempLocal(t, origin), skewX, skewY, resize);
@@ -4099,7 +4147,7 @@ const LeafHelper = {
4099
4147
  L$3.setTransform(t, matrix$3, resize);
4100
4148
  },
4101
4149
  setTransform(t, transform, resize) {
4102
- const layout = getLayout(transform);
4150
+ const layout = getLayout(transform, t.origin && L$3.getInnerOrigin(t, t.origin), t.around && L$3.getInnerOrigin(t, t.around));
4103
4151
  if (resize) {
4104
4152
  const scaleX = layout.scaleX / t.scaleX;
4105
4153
  const scaleY = layout.scaleY / t.scaleY;
@@ -4112,13 +4160,19 @@ const LeafHelper = {
4112
4160
  t.set(layout);
4113
4161
  }
4114
4162
  },
4163
+ getFlipTransform(t, axis) {
4164
+ const m = getMatrixData();
4165
+ const sign = axis === 'x' ? 1 : -1;
4166
+ scaleOfOuter$2(m, L$3.getLocalOrigin(t, 'center'), -1 * sign, 1 * sign);
4167
+ return m;
4168
+ },
4115
4169
  getLocalOrigin(t, origin) {
4116
4170
  return PointHelper.tempToOuterOf(L$3.getInnerOrigin(t, origin), t.localTransform);
4117
4171
  },
4118
4172
  getInnerOrigin(t, origin) {
4119
- if (typeof origin === 'string')
4120
- AroundHelper.toPoint(origin, t.boxBounds, origin = {});
4121
- return origin;
4173
+ const innerOrigin = {};
4174
+ AroundHelper.toPoint(origin, t.boxBounds, innerOrigin);
4175
+ return innerOrigin;
4122
4176
  },
4123
4177
  getRelativeWorld(t, relative, temp) {
4124
4178
  copy$a(matrix$3, t.worldTransform);
@@ -4545,7 +4599,10 @@ const LeafEventer = {
4545
4599
  on(type, listener, options) {
4546
4600
  let capture, once;
4547
4601
  if (options) {
4548
- if (typeof options === 'boolean') {
4602
+ if (options === 'once') {
4603
+ once = true;
4604
+ }
4605
+ else if (typeof options === 'boolean') {
4549
4606
  capture = options;
4550
4607
  }
4551
4608
  else {
@@ -4576,7 +4633,7 @@ const LeafEventer = {
4576
4633
  if (listener) {
4577
4634
  let capture;
4578
4635
  if (options)
4579
- capture = typeof options === 'boolean' ? options : options.capture;
4636
+ capture = typeof options === 'boolean' ? options : (options === 'once' ? false : options.capture);
4580
4637
  let events, index;
4581
4638
  const map = __getListenerMap(this, capture);
4582
4639
  typeList.forEach(type => {
@@ -4878,7 +4935,7 @@ const LeafMatrix = {
4878
4935
  const layout = this.__layout, local = this.__local, data = this.__;
4879
4936
  if (layout.affectScaleOrRotation) {
4880
4937
  if (layout.scaleChanged || layout.rotationChanged) {
4881
- setLayout(local, data, null, layout.affectRotation);
4938
+ setLayout(local, data, null, null, layout.affectRotation);
4882
4939
  layout.scaleChanged = layout.rotationChanged = false;
4883
4940
  }
4884
4941
  }
@@ -4886,7 +4943,7 @@ const LeafMatrix = {
4886
4943
  local.f = data.y + data.offsetY;
4887
4944
  if (data.around || data.origin) {
4888
4945
  toPoint$4(data.around || data.origin, layout.boxBounds, tempPoint$1);
4889
- translateInner(local, -tempPoint$1.x, -tempPoint$1.y, data.origin);
4946
+ translateInner(local, -tempPoint$1.x, -tempPoint$1.y, !data.around);
4890
4947
  }
4891
4948
  }
4892
4949
  this.__layout.matrixChanged = false;
@@ -4895,7 +4952,7 @@ const LeafMatrix = {
4895
4952
 
4896
4953
  const { updateMatrix: updateMatrix$1, updateAllMatrix: updateAllMatrix$2 } = LeafHelper;
4897
4954
  const { updateBounds: updateBounds$1 } = BranchHelper;
4898
- const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$1, copy: copy$8 } = BoundsHelper;
4955
+ const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$2, copy: copy$8 } = BoundsHelper;
4899
4956
  const { toBounds: toBounds$2 } = PathBounds;
4900
4957
  const LeafBounds = {
4901
4958
  __updateWorldBounds() {
@@ -4996,7 +5053,7 @@ const LeafBounds = {
4996
5053
  updateAllMatrix$2(this);
4997
5054
  updateBounds$1(this, this);
4998
5055
  if (this.__.__autoSide)
4999
- this.__updateBoxBounds();
5056
+ this.__updateBoxBounds(true);
5000
5057
  }
5001
5058
  else {
5002
5059
  updateAllMatrix$2(this);
@@ -5014,11 +5071,11 @@ const LeafBounds = {
5014
5071
  },
5015
5072
  __updateStrokeBounds() {
5016
5073
  const layout = this.__layout;
5017
- copyAndSpread$1(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
5074
+ copyAndSpread$2(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
5018
5075
  },
5019
5076
  __updateRenderBounds() {
5020
5077
  const layout = this.__layout;
5021
- layout.renderSpread > 0 ? copyAndSpread$1(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$8(layout.renderBounds, layout.strokeBounds);
5078
+ layout.renderSpread > 0 ? copyAndSpread$2(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$8(layout.renderBounds, layout.strokeBounds);
5022
5079
  }
5023
5080
  };
5024
5081
 
@@ -5115,7 +5172,7 @@ const { LEAF, create } = IncrementId;
5115
5172
  const { toInnerPoint, toOuterPoint, multiplyParent } = MatrixHelper;
5116
5173
  const { toOuterOf } = BoundsHelper;
5117
5174
  const { copy: copy$7 } = PointHelper;
5118
- const { moveLocal, zoomOfLocal, rotateOfLocal, skewOfLocal, moveWorld, zoomOfWorld, rotateOfWorld, skewOfWorld, transform, transformWorld, setTransform, getLocalOrigin, getRelativeWorld, drop } = LeafHelper;
5175
+ const { moveLocal, zoomOfLocal, rotateOfLocal, skewOfLocal, moveWorld, zoomOfWorld, rotateOfWorld, skewOfWorld, transform, transformWorld, setTransform, getFlipTransform, getLocalOrigin, getRelativeWorld, drop } = LeafHelper;
5119
5176
  let Leaf = class Leaf {
5120
5177
  get tag() { return this.__tag; }
5121
5178
  set tag(_value) { }
@@ -5141,6 +5198,8 @@ let Leaf = class Leaf {
5141
5198
  get __ignoreHitWorld() { return (this.__hasMask || this.__hasEraser) && this.__.hitChildren; }
5142
5199
  get __inLazyBounds() { const { leafer } = this; return leafer && leafer.created && leafer.lazyBounds.hit(this.__world); }
5143
5200
  get pathInputed() { return this.__.__pathInputed; }
5201
+ set event(map) { let event; for (let key in map)
5202
+ event = map[key], event instanceof Array ? this.on(key, event[0], event[1]) : this.on(key, event); }
5144
5203
  constructor(data) {
5145
5204
  this.innerId = create(LEAF);
5146
5205
  this.reset(data);
@@ -5376,6 +5435,9 @@ let Leaf = class Leaf {
5376
5435
  move(x, y) {
5377
5436
  moveLocal(this, x, y);
5378
5437
  }
5438
+ moveInner(x, y) {
5439
+ moveWorld(this, x, y, true);
5440
+ }
5379
5441
  scaleOf(origin, scaleX, scaleY, resize) {
5380
5442
  zoomOfLocal(this, getLocalOrigin(this, origin), scaleX, scaleY, resize);
5381
5443
  }
@@ -5400,6 +5462,9 @@ let Leaf = class Leaf {
5400
5462
  skewOfWorld(worldOrigin, skewX, skewY, resize) {
5401
5463
  skewOfWorld(this, worldOrigin, skewX, skewY, resize);
5402
5464
  }
5465
+ flip(axis) {
5466
+ transform(this, getFlipTransform(this, axis));
5467
+ }
5403
5468
  scaleResize(scaleX, scaleY = scaleX, _noResize) {
5404
5469
  this.scaleX *= scaleX;
5405
5470
  this.scaleY *= scaleY;
@@ -5757,7 +5822,7 @@ class LeafLevelList {
5757
5822
  }
5758
5823
  }
5759
5824
 
5760
- const version = "1.0.0-rc.30";
5825
+ const version = "1.0.1";
5761
5826
  const inviteCode = {};
5762
5827
 
5763
5828
  class LeaferCanvas extends LeaferCanvasBase {
@@ -5827,7 +5892,7 @@ function useCanvas(_canvasType, _power) {
5827
5892
  Platform.name = 'web';
5828
5893
  Platform.isWorker = true;
5829
5894
  Platform.requestRender = function (render) { requestAnimationFrame(render); };
5830
- Platform.devicePixelRatio = 1;
5895
+ defineKey(Platform, 'devicePixelRatio', { get() { return 1; } });
5831
5896
  const { userAgent } = navigator;
5832
5897
  if (userAgent.indexOf("Firefox") > -1) {
5833
5898
  Platform.conicGradientRotate90 = true;
@@ -6323,14 +6388,14 @@ class Renderer {
6323
6388
  if (Debug.showRepaint)
6324
6389
  this.canvas.strokeWorld(bounds, 'red');
6325
6390
  this.target.__render(this.canvas, options);
6326
- this.renderBounds = realBounds || bounds;
6391
+ this.renderBounds = realBounds = realBounds || bounds;
6327
6392
  this.renderOptions = options;
6328
- this.totalBounds.isEmpty() ? this.totalBounds = this.renderBounds : this.totalBounds.add(this.renderBounds);
6393
+ this.totalBounds.isEmpty() ? this.totalBounds = realBounds : this.totalBounds.add(realBounds);
6329
6394
  if (Debug.showHitView)
6330
6395
  this.renderHitView(options);
6331
6396
  if (Debug.showBoundsView)
6332
6397
  this.renderBoundsView(options);
6333
- this.canvas.updateRender();
6398
+ this.canvas.updateRender(realBounds);
6334
6399
  }
6335
6400
  renderHitView(_options) { }
6336
6401
  renderBoundsView(_options) { }
@@ -6910,6 +6975,11 @@ class BoxData extends GroupData {
6910
6975
  }
6911
6976
 
6912
6977
  class LeaferData extends GroupData {
6978
+ __getInputData() {
6979
+ const data = super.__getInputData();
6980
+ canvasSizeAttrs.forEach(key => delete data[key]);
6981
+ return data;
6982
+ }
6913
6983
  }
6914
6984
 
6915
6985
  class FrameData extends BoxData {
@@ -6987,6 +7057,11 @@ class ImageData extends RectData {
6987
7057
  }
6988
7058
 
6989
7059
  class CanvasData extends RectData {
7060
+ __getInputData() {
7061
+ const data = super.__getInputData();
7062
+ data.url = this.__leaf.canvas.toDataURL('image/png');
7063
+ return data;
7064
+ }
6990
7065
  }
6991
7066
 
6992
7067
  const UIBounds = {
@@ -7652,7 +7727,7 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7652
7727
  this.__controllers.push(this.renderer = Creator.renderer(this, canvas, config), this.watcher = Creator.watcher(this, config), this.layouter = Creator.layouter(this, config));
7653
7728
  if (this.isApp)
7654
7729
  this.__setApp();
7655
- this.__checkAutoLayout(config);
7730
+ this.__checkAutoLayout(config, parentApp);
7656
7731
  this.view = canvas.view;
7657
7732
  if (parentApp) {
7658
7733
  this.__bindApp(parentApp);
@@ -7753,9 +7828,10 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7753
7828
  this.leafer = leafer;
7754
7829
  this.__level = 1;
7755
7830
  }
7756
- __checkAutoLayout(config) {
7757
- if (!config.width || !config.height) {
7758
- this.autoLayout = new AutoBounds(config);
7831
+ __checkAutoLayout(config, parentApp) {
7832
+ if (!parentApp) {
7833
+ if (!config.width || !config.height)
7834
+ this.autoLayout = new AutoBounds(config);
7759
7835
  this.canvas.startAutoLayout(this.autoLayout, this.__onResize.bind(this));
7760
7836
  }
7761
7837
  }
@@ -7890,12 +7966,21 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7890
7966
  list.push(item);
7891
7967
  }
7892
7968
  }
7893
- zoom(_zoomType, _padding, _fixedScale) { return undefined; }
7969
+ zoom(_zoomType, _padding, _fixedScale) {
7970
+ return debug$4.error('need @leafer-in/view');
7971
+ }
7894
7972
  getValidMove(moveX, moveY) { return { x: moveX, y: moveY }; }
7895
7973
  getValidScale(changeScale) { return changeScale; }
7896
7974
  getWorldPointByClient(clientPoint, updateClient) {
7897
7975
  return this.interaction && this.interaction.getLocal(clientPoint, updateClient);
7898
7976
  }
7977
+ getPagePointByClient(clientPoint, updateClient) {
7978
+ return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient));
7979
+ }
7980
+ updateClientBounds() {
7981
+ this.canvas && this.canvas.updateClientBounds();
7982
+ }
7983
+ receiveEvent(_event) { }
7899
7984
  __checkUpdateLayout() {
7900
7985
  this.__layout.update();
7901
7986
  }
@@ -7979,7 +8064,7 @@ Rect = __decorate([
7979
8064
  const rect$1 = Rect.prototype;
7980
8065
  const group$1 = Group.prototype;
7981
8066
  const childrenRenderBounds = {};
7982
- const { copy: copy$6, add, includes: includes$1 } = BoundsHelper;
8067
+ const { copy: copy$6, add, includes: includes$1, copyAndSpread: copyAndSpread$1 } = BoundsHelper;
7983
8068
  let Box = class Box extends Group {
7984
8069
  get __tag() { return 'Box'; }
7985
8070
  get isBranchLeaf() { return true; }
@@ -7993,20 +8078,23 @@ let Box = class Box extends Group {
7993
8078
  return this.__updateRectRenderSpread() || -1;
7994
8079
  }
7995
8080
  __updateRectBoxBounds() { }
7996
- __updateBoxBounds() {
8081
+ __updateBoxBounds(secondLayout) {
7997
8082
  const data = this.__;
7998
8083
  if (this.children.length) {
7999
8084
  if (data.__autoSide) {
8000
8085
  if (this.leafer && this.leafer.ready)
8001
8086
  this.leafer.layouter.addExtra(this);
8002
8087
  super.__updateBoxBounds();
8088
+ const { boxBounds } = this.__layout;
8003
8089
  if (!data.__autoSize) {
8004
- const b = this.__layout.boxBounds;
8005
- if (!data.__autoWidth)
8006
- b.height += b.y, b.width = data.width, b.x = b.y = 0;
8007
- if (!data.__autoHeight)
8008
- b.width += b.x, b.height = data.height, b.y = b.x = 0;
8090
+ if (data.__autoWidth)
8091
+ boxBounds.width += boxBounds.x, boxBounds.height = data.height, boxBounds.y = boxBounds.x = 0;
8092
+ else
8093
+ boxBounds.height += boxBounds.y, boxBounds.width = data.width, boxBounds.x = boxBounds.y = 0;
8009
8094
  }
8095
+ if (secondLayout && data.flow && data.padding)
8096
+ copyAndSpread$1(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'));
8097
+ this.__updateNaturalSize();
8010
8098
  }
8011
8099
  else {
8012
8100
  this.__updateRectBoxBounds();
@@ -8026,13 +8114,13 @@ let Box = class Box extends Group {
8026
8114
  super.__updateRenderBounds();
8027
8115
  copy$6(childrenRenderBounds, renderBounds);
8028
8116
  this.__updateRectRenderBounds();
8029
- isOverflow = !includes$1(renderBounds, childrenRenderBounds) || undefined;
8117
+ isOverflow = !includes$1(renderBounds, childrenRenderBounds) || !this.pathInputed || !this.__.cornerRadius;
8030
8118
  }
8031
8119
  else {
8032
8120
  this.__updateRectRenderBounds();
8033
8121
  }
8034
8122
  this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
8035
- if (isOverflow && !(this.__.__drawAfterFill = this.__.overflow === 'hide'))
8123
+ if (!(this.__.__drawAfterFill = this.__.overflow === 'hide') && isOverflow)
8036
8124
  add(renderBounds, childrenRenderBounds);
8037
8125
  }
8038
8126
  __updateRectRenderBounds() { }
@@ -8366,14 +8454,26 @@ __decorate([
8366
8454
  Image = __decorate([
8367
8455
  registerUI()
8368
8456
  ], Image);
8457
+ const MyImage = Image;
8369
8458
 
8370
8459
  let Canvas = class Canvas extends Rect {
8371
8460
  get __tag() { return 'Canvas'; }
8461
+ get ready() { return !this.url; }
8372
8462
  constructor(data) {
8373
8463
  super(data);
8374
8464
  this.canvas = Creator.canvas(this.__);
8375
8465
  this.context = this.canvas.context;
8376
8466
  this.__.__isCanvas = this.__.__drawAfterFill = true;
8467
+ if (data && data.url)
8468
+ this.drawImage(data.url);
8469
+ }
8470
+ drawImage(url) {
8471
+ new LeaferImage({ url }).load((image) => {
8472
+ this.context.drawImage(image.view, 0, 0);
8473
+ this.url = undefined;
8474
+ this.paint();
8475
+ this.emitEvent(new ImageEvent(ImageEvent.LOADED, { image }));
8476
+ });
8377
8477
  }
8378
8478
  draw(ui, offset, scale, rotation) {
8379
8479
  ui.__layout.update();
@@ -8417,8 +8517,7 @@ let Canvas = class Canvas extends Rect {
8417
8517
  destroy() {
8418
8518
  if (this.canvas) {
8419
8519
  this.canvas.destroy();
8420
- this.canvas = null;
8421
- this.context = null;
8520
+ this.canvas = this.context = null;
8422
8521
  }
8423
8522
  super.destroy();
8424
8523
  }
@@ -8433,7 +8532,7 @@ __decorate([
8433
8532
  resizeType(100)
8434
8533
  ], Canvas.prototype, "height", void 0);
8435
8534
  __decorate([
8436
- resizeType(Platform.devicePixelRatio)
8535
+ resizeType(1)
8437
8536
  ], Canvas.prototype, "pixelRatio", void 0);
8438
8537
  __decorate([
8439
8538
  resizeType(true)
@@ -8457,13 +8556,13 @@ let Text = class Text extends UI {
8457
8556
  super(data);
8458
8557
  }
8459
8558
  __drawHitPath(canvas) {
8460
- const { __lineHeight, __baseLine, __textDrawData: data } = this.__;
8559
+ const { __lineHeight, fontSize, __baseLine, __textDrawData: data } = this.__;
8461
8560
  canvas.beginPath();
8462
8561
  if (this.__.__letterSpacing < 0) {
8463
8562
  this.__drawPathByData(canvas);
8464
8563
  }
8465
8564
  else {
8466
- data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight));
8565
+ data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight));
8467
8566
  }
8468
8567
  }
8469
8568
  __drawPathByData(drawer, _data) {
@@ -8656,7 +8755,8 @@ let Pen = class Pen extends Group {
8656
8755
  drawPoints(_points, _curve, _close) { return this; }
8657
8756
  clearPath() { return this; }
8658
8757
  paint() {
8659
- this.pathElement.forceUpdate('path');
8758
+ if (!this.pathElement.__layout.boxChanged)
8759
+ this.pathElement.forceUpdate('path');
8660
8760
  }
8661
8761
  };
8662
8762
  __decorate([
@@ -8666,7 +8766,7 @@ __decorate([
8666
8766
  penPathType()
8667
8767
  ], Pen.prototype, "path", void 0);
8668
8768
  Pen = __decorate([
8669
- useModule(PathCreator, ['set', 'beginPath', 'path']),
8769
+ useModule(PathCreator, ['set', 'beginPath', 'path', 'paint']),
8670
8770
  registerUI()
8671
8771
  ], Pen);
8672
8772
  function penPathType() {
@@ -8771,11 +8871,13 @@ let App = class App extends Leafer {
8771
8871
  this.renderer.update();
8772
8872
  }
8773
8873
  __render(canvas, options) {
8774
- if (options.matrix) {
8775
- const { a, b, c, d, e, f } = options.matrix;
8776
- canvas.setTransform(a, b, c, d, e, f);
8874
+ if (canvas.context) {
8875
+ if (options.matrix) {
8876
+ const { a, b, c, d, e, f } = options.matrix;
8877
+ canvas.setTransform(a, b, c, d, e, f);
8878
+ }
8879
+ this.children.forEach(leafer => canvas.copyWorld(leafer.canvas));
8777
8880
  }
8778
- this.children.forEach(leafer => canvas.copyWorld(leafer.canvas));
8779
8881
  }
8780
8882
  __onResize(event) {
8781
8883
  this.children.forEach(leafer => leafer.resize(event));
@@ -8887,6 +8989,7 @@ PointerEvent.MENU_TAP = 'pointer.menu_tap';
8887
8989
  PointerEvent = __decorate([
8888
8990
  registerUIEvent()
8889
8991
  ], PointerEvent);
8992
+ const MyPointerEvent = PointerEvent;
8890
8993
 
8891
8994
  const move$1 = {};
8892
8995
  let DragEvent = class DragEvent extends PointerEvent {
@@ -8986,6 +9089,7 @@ DragEvent.LEAVE = 'drag.leave';
8986
9089
  DragEvent = __decorate([
8987
9090
  registerUIEvent()
8988
9091
  ], DragEvent);
9092
+ const MyDragEvent = DragEvent;
8989
9093
 
8990
9094
  let DropEvent = class DropEvent extends PointerEvent {
8991
9095
  static setList(data) {
@@ -9067,36 +9171,32 @@ function addInteractionWindow(leafer) {
9067
9171
 
9068
9172
  function document$1(leafer) {
9069
9173
  addInteractionWindow(leafer);
9070
- leafer.config.move.scroll = 'limit';
9071
- leafer.config.zoom.min = 1;
9174
+ const { move, zoom } = leafer.config;
9175
+ move.scroll = 'limit';
9176
+ zoom.min = 1;
9177
+ }
9178
+
9179
+ function block(leafer) {
9180
+ const { config } = leafer;
9181
+ (config.wheel || (config.wheel = {})).preventDefault = false;
9182
+ (config.touch || (config.touch = {})).preventDefault = 'auto';
9072
9183
  }
9073
9184
 
9074
9185
  const debug$3 = Debug.get('LeaferTypeCreator');
9075
9186
  const LeaferTypeCreator = {
9076
9187
  list: {},
9077
9188
  register(name, fn) {
9078
- if (list$1[name]) {
9079
- debug$3.repeat(name);
9080
- }
9081
- else {
9082
- list$1[name] = fn;
9083
- }
9189
+ list$1[name] ? debug$3.repeat(name) : list$1[name] = fn;
9084
9190
  },
9085
9191
  run(name, leafer) {
9086
9192
  const fn = list$1[name];
9087
- if (fn) {
9088
- fn(leafer);
9089
- }
9090
- else {
9091
- debug$3.error('no', name);
9092
- }
9193
+ fn && fn(leafer);
9093
9194
  }
9094
9195
  };
9095
9196
  const { list: list$1, register } = LeaferTypeCreator;
9096
- register('draw', () => { });
9097
- register('custom', () => { });
9098
9197
  register('design', addInteractionWindow);
9099
9198
  register('document', document$1);
9199
+ register('block', block);
9100
9200
 
9101
9201
  const leafer = Leafer.prototype;
9102
9202
  leafer.initType = function (type) {
@@ -9142,11 +9242,14 @@ leafer.getValidScale = function (changeScale) {
9142
9242
  };
9143
9243
 
9144
9244
  class Transformer {
9245
+ get transforming() { return !!(this.moveData || this.zoomData || this.rotateData); }
9145
9246
  constructor(interaction) {
9146
9247
  this.interaction = interaction;
9147
9248
  }
9148
9249
  move(data) {
9149
9250
  const { interaction } = this;
9251
+ if (!data.moveType)
9252
+ data.moveType = 'move';
9150
9253
  if (!this.moveData) {
9151
9254
  const { path } = interaction.selector.getByPoint(data, interaction.hitRadius);
9152
9255
  data.path = path;
@@ -9282,7 +9385,13 @@ const InteractionHelper = {
9282
9385
  find.add(list[i]);
9283
9386
  }
9284
9387
  return find;
9285
- }
9388
+ },
9389
+ pathCanDrag(path) {
9390
+ return path && path.list.some(item => item.draggable || item.editable || (!item.isLeafer && item.hasEvent(DragEvent.DRAG)));
9391
+ },
9392
+ pathHasOutside(path) {
9393
+ return path && path.list.some(item => item.isOutside);
9394
+ },
9286
9395
  };
9287
9396
  const I = InteractionHelper;
9288
9397
 
@@ -9311,8 +9420,10 @@ class Dragger {
9311
9420
  return;
9312
9421
  }
9313
9422
  if (!this.moving && canDrag) {
9314
- if (this.moving = interaction.canMove(this.downData) || interaction.isHoldRightKey || interaction.isMobileDragEmpty)
9423
+ if (this.moving = interaction.canMove(this.downData) || interaction.isHoldRightKey || interaction.isMobileDragEmpty) {
9424
+ this.dragData.moveType = 'drag';
9315
9425
  interaction.emit(MoveEvent.START, this.dragData);
9426
+ }
9316
9427
  }
9317
9428
  if (!this.moving) {
9318
9429
  this.dragStart(data, canDrag);
@@ -9351,6 +9462,7 @@ class Dragger {
9351
9462
  this.dragData.throughPath = throughPath;
9352
9463
  this.dragData.path = path;
9353
9464
  if (this.moving) {
9465
+ this.dragData.moveType = 'drag';
9354
9466
  interaction.emit(MoveEvent.BEFORE_MOVE, this.dragData);
9355
9467
  interaction.emit(MoveEvent.MOVE, this.dragData);
9356
9468
  }
@@ -9417,6 +9529,7 @@ class Dragger {
9417
9529
  endDragData.path = path;
9418
9530
  if (this.moving) {
9419
9531
  this.moving = false;
9532
+ endDragData.moveType = 'drag';
9420
9533
  interaction.emit(MoveEvent.END, endDragData);
9421
9534
  }
9422
9535
  if (this.dragging) {
@@ -9475,7 +9588,7 @@ class Dragger {
9475
9588
  totalY += moveY;
9476
9589
  PointHelper.move(downData, moveX, moveY);
9477
9590
  PointHelper.move(this.dragData, moveX, moveY);
9478
- interaction.move(Object.assign(Object.assign({}, data), { moveX, moveY, totalX, totalY }));
9591
+ interaction.move(Object.assign(Object.assign({}, data), { moveX, moveY, totalX, totalY, moveType: 'drag' }));
9479
9592
  interaction.pointerMoveReal(data);
9480
9593
  }, 10);
9481
9594
  }
@@ -9588,22 +9701,27 @@ const config$1 = {
9588
9701
  swipeDistance: 20,
9589
9702
  preventDefaultMenu: true
9590
9703
  },
9704
+ touch: {
9705
+ preventDefault: true
9706
+ },
9591
9707
  cursor: true,
9592
9708
  keyEvent: true
9593
9709
  };
9594
9710
 
9595
- const { pathHasEventType, getMoveEventData, getZoomEventData, getRotateEventData } = InteractionHelper;
9711
+ const { pathHasEventType, getMoveEventData, getZoomEventData, getRotateEventData, pathCanDrag, pathHasOutside } = InteractionHelper;
9596
9712
  class InteractionBase {
9597
9713
  get dragging() { return this.dragger.dragging; }
9598
- get moveMode() { return this.config.move.drag || this.isHoldSpaceKey || this.isHoldMiddleKey || (this.isHoldRightKey && this.dragger.moving) || this.isDragEmpty; }
9714
+ get transforming() { return this.transformer.transforming; }
9715
+ get moveMode() { return this.config.move.drag === true || this.isHoldSpaceKey || this.isHoldMiddleKey || (this.isHoldRightKey && this.dragger.moving) || this.isDragEmpty; }
9716
+ get canHover() { return this.config.pointer.hover && !this.config.mobile; }
9599
9717
  get isDragEmpty() { return this.config.move.dragEmpty && this.isRootPath(this.hoverData) && (!this.downData || this.isRootPath(this.downData)); }
9600
- get isMobileDragEmpty() { return this.config.move.dragEmpty && !this.config.pointer.hover && this.downData && this.isTreePath(this.downData); }
9718
+ get isMobileDragEmpty() { return this.config.move.dragEmpty && !this.canHover && this.downData && this.isTreePath(this.downData); }
9601
9719
  get isHoldMiddleKey() { return this.config.move.holdMiddleKey && this.downData && PointerButton.middle(this.downData); }
9602
9720
  get isHoldRightKey() { return this.config.move.holdRightKey && this.downData && PointerButton.right(this.downData); }
9603
9721
  get isHoldSpaceKey() { return this.config.move.holdSpaceKey && Keyboard.isHoldSpaceKey(); }
9604
9722
  get hitRadius() { return this.config.pointer.hitRadius; }
9605
9723
  constructor(target, canvas, selector, userConfig) {
9606
- this.config = config$1;
9724
+ this.config = DataHelper.clone(config$1);
9607
9725
  this.tapCount = 0;
9608
9726
  this.downKeyMap = {};
9609
9727
  this.target = target;
@@ -9690,6 +9808,7 @@ class InteractionBase {
9690
9808
  if (!downData)
9691
9809
  return;
9692
9810
  PointerButton.defaultLeft(data);
9811
+ data.multiTouch = downData.multiTouch;
9693
9812
  this.findPath(data);
9694
9813
  const upData = Object.assign(Object.assign({}, data), { path: data.path.clone() });
9695
9814
  data.path.addList(downData.path.list);
@@ -9762,7 +9881,7 @@ class InteractionBase {
9762
9881
  this.updateCursor();
9763
9882
  }
9764
9883
  pointerHover(data) {
9765
- if (this.config.pointer.hover) {
9884
+ if (this.canHover) {
9766
9885
  this.pointerOverOrOut(data);
9767
9886
  this.pointerEnterOrLeave(data);
9768
9887
  }
@@ -9854,11 +9973,11 @@ class InteractionBase {
9854
9973
  return app.editor && (!data.path.has(app.editor) && data.path.has(app.tree) && !data.target.syncEventer);
9855
9974
  }
9856
9975
  checkPath(data, useDefaultPath) {
9857
- if (useDefaultPath || this.canMove(data))
9976
+ if (useDefaultPath || (this.moveMode && !pathHasOutside(data.path)))
9858
9977
  data.path = this.defaultPath;
9859
9978
  }
9860
9979
  canMove(data) {
9861
- return this.moveMode && data && data.path.list.every(item => !item.isOutside);
9980
+ return data && (this.moveMode || (this.config.move.drag === 'auto' && !pathCanDrag(data.path))) && !pathHasOutside(data.path);
9862
9981
  }
9863
9982
  isDrag(leaf) {
9864
9983
  return this.dragger.getList().has(leaf);
@@ -9899,7 +10018,7 @@ class InteractionBase {
9899
10018
  this.hoverData = data;
9900
10019
  }
9901
10020
  updateCursor(data) {
9902
- if (!this.config.cursor || !this.config.pointer.hover)
10021
+ if (!this.config.cursor || !this.canHover)
9903
10022
  return;
9904
10023
  if (!data) {
9905
10024
  this.updateHoverData();
@@ -10553,10 +10672,13 @@ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, al
10553
10672
  const { get: get$2, translate } = MatrixHelper;
10554
10673
  const tempBox = new Bounds();
10555
10674
  const tempPoint = {};
10675
+ const tempScaleData = {};
10556
10676
  function createData(leafPaint, image, paint, box) {
10557
- const { blendMode } = paint;
10677
+ const { blendMode, sync } = paint;
10558
10678
  if (blendMode)
10559
10679
  leafPaint.blendMode = blendMode;
10680
+ if (sync)
10681
+ leafPaint.sync = sync;
10560
10682
  leafPaint.data = getPatternData(paint, box, image);
10561
10683
  }
10562
10684
  function getPatternData(paint, box, image) {
@@ -10576,13 +10698,10 @@ function getPatternData(paint, box, image) {
10576
10698
  x += (box.width - width * scaleX) / 2, y += (box.height - height * scaleY) / 2;
10577
10699
  }
10578
10700
  }
10579
- else if (size) {
10580
- scaleX = (typeof size === 'number' ? size : size.width) / width;
10581
- scaleY = (typeof size === 'number' ? size : size.height) / height;
10582
- }
10583
- else if (scale) {
10584
- scaleX = typeof scale === 'number' ? scale : scale.x;
10585
- scaleY = typeof scale === 'number' ? scale : scale.y;
10701
+ else if (scale || size) {
10702
+ MathHelper.getScaleData(scale, size, image, tempScaleData);
10703
+ scaleX = tempScaleData.scaleX;
10704
+ scaleY = tempScaleData.scaleY;
10586
10705
  }
10587
10706
  if (align) {
10588
10707
  const imageBounds = { x, y, width: swapWidth, height: swapHeight };
@@ -10787,7 +10906,7 @@ function createPattern(ui, paint, pixelRatio) {
10787
10906
  const { abs: abs$1 } = Math;
10788
10907
  function checkImage(ui, canvas, paint, allowPaint) {
10789
10908
  const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
10790
- if (!paint.data || paint.patternId === scaleX + '-' + scaleY) {
10909
+ if (!paint.data || (paint.patternId === scaleX + '-' + scaleY && !Export.running)) {
10791
10910
  return false;
10792
10911
  }
10793
10912
  else {
@@ -10821,7 +10940,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
10821
10940
  return true;
10822
10941
  }
10823
10942
  else {
10824
- if (!paint.style || Export.running) {
10943
+ if (!paint.style || paint.sync || Export.running) {
10825
10944
  createPattern(ui, paint, canvas.pixelRatio);
10826
10945
  }
10827
10946
  else {
@@ -11589,7 +11708,7 @@ function decorationText(drawData, style) {
11589
11708
  }
11590
11709
  }
11591
11710
 
11592
- const { top: top$1, right: right$2, bottom: bottom$1, left: left$2 } = Direction4;
11711
+ const { top: top$2, right: right$3, bottom: bottom$2, left: left$3 } = Direction4;
11593
11712
  function getDrawData(content, style) {
11594
11713
  if (typeof content !== 'string')
11595
11714
  content = String(content);
@@ -11599,12 +11718,12 @@ function getDrawData(content, style) {
11599
11718
  const { textDecoration, __font, __padding: padding } = style;
11600
11719
  if (padding) {
11601
11720
  if (width) {
11602
- x = padding[left$2];
11603
- width -= (padding[right$2] + padding[left$2]);
11721
+ x = padding[left$3];
11722
+ width -= (padding[right$3] + padding[left$3]);
11604
11723
  }
11605
11724
  if (height) {
11606
- y = padding[top$1];
11607
- height -= (padding[top$1] + padding[bottom$1]);
11725
+ y = padding[top$2];
11726
+ height -= (padding[top$2] + padding[bottom$2]);
11608
11727
  }
11609
11728
  }
11610
11729
  const drawData = {
@@ -11628,19 +11747,19 @@ function padAutoText(padding, drawData, style, width, height) {
11628
11747
  if (!width) {
11629
11748
  switch (style.textAlign) {
11630
11749
  case 'left':
11631
- offsetText(drawData, 'x', padding[left$2]);
11750
+ offsetText(drawData, 'x', padding[left$3]);
11632
11751
  break;
11633
11752
  case 'right':
11634
- offsetText(drawData, 'x', -padding[right$2]);
11753
+ offsetText(drawData, 'x', -padding[right$3]);
11635
11754
  }
11636
11755
  }
11637
11756
  if (!height) {
11638
11757
  switch (style.verticalAlign) {
11639
11758
  case 'top':
11640
- offsetText(drawData, 'y', padding[top$1]);
11759
+ offsetText(drawData, 'y', padding[top$2]);
11641
11760
  break;
11642
11761
  case 'bottom':
11643
- offsetText(drawData, 'y', -padding[bottom$1]);
11762
+ offsetText(drawData, 'y', -padding[bottom$2]);
11644
11763
  }
11645
11764
  }
11646
11765
  }
@@ -11691,6 +11810,7 @@ const ExportModule = {
11691
11810
  export(leaf, filename, options) {
11692
11811
  this.running = true;
11693
11812
  const fileType = FileHelper.fileType(filename);
11813
+ const isDownload = filename.includes('.');
11694
11814
  options = FileHelper.getExportOptions(options);
11695
11815
  return addTask((success) => new Promise((resolve) => {
11696
11816
  const over = (result) => {
@@ -11700,19 +11820,13 @@ const ExportModule = {
11700
11820
  };
11701
11821
  const { toURL } = Platform;
11702
11822
  const { download } = Platform.origin;
11703
- if (filename === 'json') {
11704
- return over({ data: leaf.toJSON(options.json) });
11823
+ if (fileType === 'json') {
11824
+ isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
11825
+ return over({ data: isDownload ? true : leaf.toJSON(options.json) });
11705
11826
  }
11706
- else if (fileType === 'json') {
11707
- download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
11708
- return over({ data: true });
11709
- }
11710
- if (filename === 'svg') {
11711
- return over({ data: leaf.toSVG() });
11712
- }
11713
- else if (fileType === 'svg') {
11714
- download(toURL(leaf.toSVG(), 'svg'), filename);
11715
- return over({ data: true });
11827
+ if (fileType === 'svg') {
11828
+ isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
11829
+ return over({ data: isDownload ? true : leaf.toSVG() });
11716
11830
  }
11717
11831
  const { leafer } = leaf;
11718
11832
  if (leafer) {
@@ -11721,14 +11835,8 @@ const ExportModule = {
11721
11835
  let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
11722
11836
  const { worldTransform, isLeafer, isFrame } = leaf;
11723
11837
  const { slice, trim, onCanvas } = options;
11724
- let scale = options.scale || 1;
11725
- let pixelRatio = options.pixelRatio || 1;
11726
11838
  const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
11727
11839
  const contextSettings = options.contextSettings || leafer.config.contextSettings;
11728
- if (leaf.isApp) {
11729
- scale *= pixelRatio;
11730
- pixelRatio = leaf.app.pixelRatio;
11731
- }
11732
11840
  const screenshot = options.screenshot || leaf.isApp;
11733
11841
  const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
11734
11842
  const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
@@ -11762,10 +11870,21 @@ const ExportModule = {
11762
11870
  }
11763
11871
  renderBounds = leaf.getBounds('render', relative);
11764
11872
  }
11765
- const { x, y, width, height } = new Bounds(renderBounds).scale(scale);
11873
+ const scaleData = { scaleX: 1, scaleY: 1 };
11874
+ MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
11875
+ let pixelRatio = options.pixelRatio || 1;
11876
+ if (leaf.isApp) {
11877
+ scaleData.scaleX *= pixelRatio;
11878
+ scaleData.scaleY *= pixelRatio;
11879
+ pixelRatio = leaf.app.pixelRatio;
11880
+ }
11881
+ const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
11882
+ const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
11766
11883
  let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
11767
- const renderOptions = { matrix: matrix.scale(1 / scale).invert().translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) };
11884
+ let sliceLeaf;
11768
11885
  if (slice) {
11886
+ sliceLeaf = leaf;
11887
+ sliceLeaf.__worldOpacity = 0;
11769
11888
  leaf = leafer;
11770
11889
  renderOptions.bounds = canvas.bounds;
11771
11890
  }
@@ -11780,6 +11899,8 @@ const ExportModule = {
11780
11899
  leaf.__render(canvas, renderOptions);
11781
11900
  }
11782
11901
  canvas.restore();
11902
+ if (sliceLeaf)
11903
+ sliceLeaf.__updateWorldOpacity();
11783
11904
  if (trim) {
11784
11905
  trimBounds = getTrimBounds(canvas);
11785
11906
  const old = canvas, { width, height } = trimBounds;
@@ -11949,6 +12070,7 @@ const PathScaler = {
11949
12070
  const { scalePoints } = PathScaler;
11950
12071
 
11951
12072
  const matrix$1 = MatrixHelper.get();
12073
+ const { topLeft: topLeft$1, top: top$1, topRight: topRight$1, right: right$2, bottom: bottom$1, left: left$2 } = Direction9;
11952
12074
  function scaleResize(leaf, scaleX, scaleY) {
11953
12075
  if (leaf.pathInputed) {
11954
12076
  scaleResizePath(leaf, scaleX, scaleY);
@@ -11961,14 +12083,35 @@ function scaleResize(leaf, scaleX, scaleY) {
11961
12083
  }
11962
12084
  }
11963
12085
  function scaleResizeFontSize(leaf, scaleX, scaleY) {
11964
- const { width, height } = leaf.__localBoxBounds;
11965
- if (scaleX !== 1) {
11966
- leaf.fontSize *= scaleX;
11967
- leaf.y -= height * (scaleX - scaleY) / 2;
12086
+ const { app } = leaf;
12087
+ const editor = app && app.editor;
12088
+ if (editor.editing) {
12089
+ const layout = leaf.__layout;
12090
+ let { width, height } = layout.boxBounds;
12091
+ width *= (scaleY - scaleX) * (leaf.scaleX < 0 ? -1 : 1);
12092
+ height *= (scaleX - scaleY) * (leaf.scaleY < 0 ? -1 : 1);
12093
+ switch (editor.resizeDirection) {
12094
+ case top$1:
12095
+ case bottom$1:
12096
+ leaf.fontSize *= scaleY;
12097
+ layout.affectScaleOrRotation ? leaf.moveInner(-width / 2, 0) : leaf.x -= width / 2;
12098
+ break;
12099
+ case left$2:
12100
+ case right$2:
12101
+ leaf.fontSize *= scaleX;
12102
+ layout.affectScaleOrRotation ? leaf.moveInner(0, -height / 2) : leaf.y -= height / 2;
12103
+ break;
12104
+ case topLeft$1:
12105
+ case topRight$1:
12106
+ leaf.fontSize *= scaleX;
12107
+ layout.affectScaleOrRotation ? leaf.moveInner(0, -height) : leaf.y -= height;
12108
+ break;
12109
+ default:
12110
+ leaf.fontSize *= scaleX;
12111
+ }
11968
12112
  }
11969
- else if (scaleY !== 1) {
11970
- leaf.fontSize *= scaleY;
11971
- leaf.x -= width * (scaleY - scaleX) / 2;
12113
+ else {
12114
+ leaf.fontSize *= scaleX;
11972
12115
  }
11973
12116
  }
11974
12117
  function scaleResizePath(leaf, scaleX, scaleY) {
@@ -12272,7 +12415,7 @@ class EditSelect extends Group {
12272
12415
  }
12273
12416
  onPointerMove(e) {
12274
12417
  const { app, editor } = this;
12275
- if (this.running && !this.isMoveMode && app.config.pointer.hover && !app.interaction.dragging) {
12418
+ if (this.running && !this.isMoveMode && app.interaction.canHover && !app.interaction.dragging) {
12276
12419
  const find = this.findUI(e);
12277
12420
  editor.hoverTarget = editor.hasItem(find) ? null : find;
12278
12421
  }
@@ -12281,15 +12424,27 @@ class EditSelect extends Group {
12281
12424
  }
12282
12425
  }
12283
12426
  onBeforeDown(e) {
12427
+ if (e.multiTouch)
12428
+ return;
12284
12429
  const { select } = this.editor.mergeConfig;
12285
- if (select === 'press')
12286
- this.checkAndSelect(e);
12430
+ if (select === 'press') {
12431
+ if (this.app.config.mobile) {
12432
+ this.waitSelect = () => this.checkAndSelect(e);
12433
+ }
12434
+ else {
12435
+ this.checkAndSelect(e);
12436
+ }
12437
+ }
12287
12438
  }
12288
12439
  onTap(e) {
12440
+ if (e.multiTouch)
12441
+ return;
12289
12442
  const { editor } = this;
12290
12443
  const { select } = editor.mergeConfig;
12291
12444
  if (select === 'tap')
12292
12445
  this.checkAndSelect(e);
12446
+ else if (this.waitSelect)
12447
+ this.waitSelect();
12293
12448
  if (this.needRemoveItem) {
12294
12449
  editor.removeItem(this.needRemoveItem);
12295
12450
  }
@@ -12320,6 +12475,10 @@ class EditSelect extends Group {
12320
12475
  }
12321
12476
  }
12322
12477
  onDragStart(e) {
12478
+ if (e.multiTouch)
12479
+ return;
12480
+ if (this.waitSelect)
12481
+ this.waitSelect();
12323
12482
  if (this.allowDrag(e)) {
12324
12483
  const { editor } = this;
12325
12484
  const { stroke, area } = editor.mergeConfig;
@@ -12331,10 +12490,10 @@ class EditSelect extends Group {
12331
12490
  }
12332
12491
  }
12333
12492
  onDrag(e) {
12334
- if (this.editor.dragging) {
12335
- this.onDragEnd();
12493
+ if (e.multiTouch)
12336
12494
  return;
12337
- }
12495
+ if (this.editor.dragging)
12496
+ return this.onDragEnd(e);
12338
12497
  if (this.dragging) {
12339
12498
  const { editor } = this;
12340
12499
  const total = e.getInnerTotal(this);
@@ -12358,7 +12517,9 @@ class EditSelect extends Group {
12358
12517
  }
12359
12518
  }
12360
12519
  }
12361
- onDragEnd() {
12520
+ onDragEnd(e) {
12521
+ if (e.multiTouch)
12522
+ return;
12362
12523
  if (this.dragging)
12363
12524
  this.originList = null, this.selectArea.visible = false;
12364
12525
  }
@@ -12404,7 +12565,7 @@ class EditSelect extends Group {
12404
12565
  app.on_(PointerEvent.MOVE, this.onPointerMove, this),
12405
12566
  app.on_(PointerEvent.BEFORE_DOWN, this.onBeforeDown, this),
12406
12567
  app.on_(PointerEvent.TAP, this.onTap, this),
12407
- app.on_(DragEvent.START, this.onDragStart, this),
12568
+ app.on_(DragEvent.START, this.onDragStart, this, true),
12408
12569
  app.on_(DragEvent.DRAG, this.onDrag, this),
12409
12570
  app.on_(DragEvent.END, this.onDragEnd, this),
12410
12571
  app.on_(MoveEvent.MOVE, this.onAutoMove, this),
@@ -12427,22 +12588,32 @@ class EditSelect extends Group {
12427
12588
 
12428
12589
  const { topLeft, top, topRight, right: right$1, bottomRight, bottom, bottomLeft, left: left$1 } = Direction9;
12429
12590
  const { toPoint } = AroundHelper;
12591
+ const { within } = MathHelper;
12430
12592
  const EditDataHelper = {
12431
- getScaleData(bounds, direction, pointMove, lockRatio, around) {
12593
+ getScaleData(element, startBounds, direction, totalMove, lockRatio, around, flipable, scaleMode) {
12432
12594
  let align, origin = {}, scaleX = 1, scaleY = 1;
12433
- const { width, height } = bounds;
12595
+ const { boxBounds, widthRange, heightRange } = element;
12596
+ const { width, height } = startBounds;
12434
12597
  if (around) {
12435
- pointMove.x *= 2;
12436
- pointMove.y *= 2;
12437
- }
12438
- if (Math.abs(pointMove.x) === width)
12439
- pointMove.x += 0.1;
12440
- if (Math.abs(pointMove.y) === height)
12441
- pointMove.y += 0.1;
12442
- const topScale = (-pointMove.y + height) / height;
12443
- const rightScale = (pointMove.x + width) / width;
12444
- const bottomScale = (pointMove.y + height) / height;
12445
- const leftScale = (-pointMove.x + width) / width;
12598
+ totalMove.x *= 2;
12599
+ totalMove.y *= 2;
12600
+ }
12601
+ const originChangedScaleX = element.scaleX / startBounds.scaleX;
12602
+ const originChangedScaleY = element.scaleY / startBounds.scaleY;
12603
+ const signX = originChangedScaleX < 0 ? -1 : 1;
12604
+ const signY = originChangedScaleY < 0 ? -1 : 1;
12605
+ const changedScaleX = scaleMode ? originChangedScaleX : signX * boxBounds.width / width;
12606
+ const changedScaleY = scaleMode ? originChangedScaleY : signY * boxBounds.height / height;
12607
+ totalMove.x *= scaleMode ? originChangedScaleX : signX;
12608
+ totalMove.y *= scaleMode ? originChangedScaleY : signY;
12609
+ if (Math.abs(totalMove.x) === width)
12610
+ totalMove.x += 0.1;
12611
+ if (Math.abs(totalMove.y) === height)
12612
+ totalMove.y += 0.1;
12613
+ const topScale = (-totalMove.y + height) / height;
12614
+ const rightScale = (totalMove.x + width) / width;
12615
+ const bottomScale = (totalMove.y + height) / height;
12616
+ const leftScale = (-totalMove.x + width) / width;
12446
12617
  switch (direction) {
12447
12618
  case top:
12448
12619
  scaleY = topScale;
@@ -12483,12 +12654,41 @@ const EditDataHelper = {
12483
12654
  if (lockRatio) {
12484
12655
  const unlockSide = lockRatio === 'corner' && direction % 2;
12485
12656
  if (!unlockSide) {
12486
- const scale = Math.sqrt(Math.abs(scaleX * scaleY));
12657
+ let scale;
12658
+ switch (direction) {
12659
+ case top:
12660
+ case bottom:
12661
+ scale = scaleY;
12662
+ break;
12663
+ case left$1:
12664
+ case right$1:
12665
+ scale = scaleX;
12666
+ break;
12667
+ default:
12668
+ scale = Math.sqrt(Math.abs(scaleX * scaleY));
12669
+ }
12487
12670
  scaleX = scaleX < 0 ? -scale : scale;
12488
12671
  scaleY = scaleY < 0 ? -scale : scale;
12489
12672
  }
12490
12673
  }
12491
- toPoint(around || align, bounds, origin);
12674
+ scaleX /= changedScaleX;
12675
+ scaleY /= changedScaleY;
12676
+ if (!flipable) {
12677
+ const { worldTransform } = element;
12678
+ if (scaleX < 0)
12679
+ scaleX = 1 / boxBounds.width / worldTransform.scaleX;
12680
+ if (scaleY < 0)
12681
+ scaleY = 1 / boxBounds.height / worldTransform.scaleY;
12682
+ }
12683
+ if (widthRange) {
12684
+ const nowWidth = boxBounds.width * element.scaleX;
12685
+ scaleX = within(nowWidth * scaleX, widthRange) / nowWidth;
12686
+ }
12687
+ if (heightRange) {
12688
+ const nowHeight = boxBounds.height * element.scaleY;
12689
+ scaleY = within(nowHeight * scaleY, heightRange) / nowHeight;
12690
+ }
12691
+ toPoint(around || align, boxBounds, origin);
12492
12692
  return { origin, scaleX, scaleY, direction, lockRatio, around };
12493
12693
  },
12494
12694
  getRotateData(bounds, direction, current, last, around) {
@@ -12609,6 +12809,11 @@ function updateCursor(editor, e) {
12609
12809
  return;
12610
12810
  if (point.name === 'circle')
12611
12811
  return;
12812
+ if (point.pointType === 'button') {
12813
+ if (!point.cursor)
12814
+ point.cursor = 'pointer';
12815
+ return;
12816
+ }
12612
12817
  let { rotation } = editBox;
12613
12818
  const { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editor.mergeConfig;
12614
12819
  const { pointType } = point, { flippedX, flippedY } = editBox;
@@ -12677,9 +12882,8 @@ class EditBox extends Group {
12677
12882
  resizePoints.push(resizePoint);
12678
12883
  this.listenPointEvents(resizePoint, 'resize', i);
12679
12884
  }
12680
- buttons.add(circle);
12681
12885
  this.listenPointEvents(circle, 'rotate', 2);
12682
- view.addMany(...rotatePoints, rect, buttons, ...resizeLines, ...resizePoints);
12886
+ view.addMany(...rotatePoints, rect, circle, buttons, ...resizeLines, ...resizePoints);
12683
12887
  this.add(view);
12684
12888
  }
12685
12889
  load() {
@@ -12695,9 +12899,9 @@ class EditBox extends Group {
12695
12899
  if (!(i % 2))
12696
12900
  resizeP.rotation = (i / 2) * 90;
12697
12901
  }
12698
- circle.set(this.getPointStyle(mergeConfig.rotatePoint || pointsStyle[0]));
12902
+ circle.set(this.getPointStyle(mergeConfig.circle || mergeConfig.rotatePoint || pointsStyle[0]));
12699
12903
  rect.set(Object.assign({ stroke, strokeWidth }, (mergeConfig.rect || {})));
12700
- rect.hittable = !single && moveable;
12904
+ rect.hittable = !single && !!moveable;
12701
12905
  element.syncEventer = (single && moveable) ? rect : null;
12702
12906
  this.app.interaction.bottomList = (single && moveable) ? [{ target: rect, proxy: element }] : null;
12703
12907
  }
@@ -12706,7 +12910,7 @@ class EditBox extends Group {
12706
12910
  if (this.view.worldOpacity) {
12707
12911
  const { mergeConfig } = this.editor;
12708
12912
  const { width, height } = bounds;
12709
- const { rect, circle, resizePoints, rotatePoints, resizeLines } = this;
12913
+ const { rect, circle, buttons, resizePoints, rotatePoints, resizeLines } = this;
12710
12914
  const { middlePoint, resizeable, rotateable, hideOnSmall } = mergeConfig;
12711
12915
  const smallSize = typeof hideOnSmall === 'number' ? hideOnSmall : 10;
12712
12916
  const showPoints = !(hideOnSmall && width < smallSize && height < smallSize);
@@ -12736,19 +12940,25 @@ class EditBox extends Group {
12736
12940
  }
12737
12941
  }
12738
12942
  }
12739
- circle.visible = showPoints && rotateable && !!mergeConfig.rotatePoint;
12943
+ circle.visible = showPoints && rotateable && !!(mergeConfig.circle || mergeConfig.rotatePoint);
12944
+ if (circle.visible)
12945
+ this.layoutCircle(mergeConfig);
12740
12946
  if (rect.path)
12741
12947
  rect.path = null;
12742
12948
  rect.set(Object.assign(Object.assign({}, bounds), { visible: true }));
12743
- const buttonVisible = showPoints && (circle.visible || this.buttons.children.length > 1);
12744
- this.buttons.visible = buttonVisible;
12745
- if (buttonVisible)
12746
- this.layoutButtons();
12949
+ buttons.visible = showPoints && buttons.children.length > 0;
12950
+ if (buttons.visible)
12951
+ this.layoutButtons(mergeConfig);
12747
12952
  }
12748
12953
  }
12749
- layoutButtons() {
12750
- const { buttons, resizePoints } = this;
12751
- const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = this.editor.mergeConfig;
12954
+ layoutCircle(config) {
12955
+ const { circleDirection, circleMargin, buttonsMargin, buttonsDirection, middlePoint } = config;
12956
+ const direction = fourDirection.indexOf(circleDirection || ((this.buttons.children.length && buttonsDirection === 'bottom') ? 'top' : 'bottom'));
12957
+ this.setButtonPosition(this.circle, direction, circleMargin || buttonsMargin, !!middlePoint);
12958
+ }
12959
+ layoutButtons(config) {
12960
+ const { buttons } = this;
12961
+ const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = config;
12752
12962
  const { flippedX, flippedY } = this;
12753
12963
  let index = fourDirection.indexOf(buttonsDirection);
12754
12964
  if ((index % 2 && flippedX) || ((index + 1) % 2 && flippedY)) {
@@ -12756,11 +12966,18 @@ class EditBox extends Group {
12756
12966
  index = (index + 2) % 4;
12757
12967
  }
12758
12968
  const direction = buttonsFixed ? EditDataHelper.getRotateDirection(index, this.flippedOne ? this.rotation : -this.rotation, 4) : index;
12759
- const point = resizePoints[direction * 2 + 1];
12969
+ this.setButtonPosition(buttons, direction, buttonsMargin, !!middlePoint);
12970
+ if (buttonsFixed)
12971
+ buttons.rotation = (direction - index) * 90;
12972
+ buttons.scaleX = flippedX ? -1 : 1;
12973
+ buttons.scaleY = flippedY ? -1 : 1;
12974
+ }
12975
+ setButtonPosition(buttons, direction, buttonsMargin, useMiddlePoint) {
12976
+ const point = this.resizePoints[direction * 2 + 1];
12760
12977
  const useX = direction % 2;
12761
12978
  const sign = (!direction || direction === 3) ? -1 : 1;
12762
- const useWidth = index % 2;
12763
- const margin = (buttonsMargin + (useWidth ? ((middlePoint ? point.width : 0) + buttons.boxBounds.width) : ((middlePoint ? point.height : 0) + buttons.boxBounds.height)) / 2) * sign;
12979
+ const useWidth = direction % 2;
12980
+ const margin = (buttonsMargin + (useWidth ? ((useMiddlePoint ? point.width : 0) + buttons.boxBounds.width) : ((useMiddlePoint ? point.height : 0) + buttons.boxBounds.height)) / 2) * sign;
12764
12981
  if (useX) {
12765
12982
  buttons.x = point.x + margin;
12766
12983
  buttons.y = point.y;
@@ -12769,11 +12986,6 @@ class EditBox extends Group {
12769
12986
  buttons.x = point.x;
12770
12987
  buttons.y = point.y + margin;
12771
12988
  }
12772
- if (buttonsFixed) {
12773
- buttons.rotation = (direction - index) * 90;
12774
- buttons.scaleX = flippedX ? -1 : 1;
12775
- buttons.scaleY = flippedY ? -1 : 1;
12776
- }
12777
12989
  }
12778
12990
  unload() {
12779
12991
  this.visible = false;
@@ -12800,18 +13012,23 @@ class EditBox extends Group {
12800
13012
  }
12801
13013
  onDragStart(e) {
12802
13014
  this.dragging = true;
13015
+ const { editor } = this;
12803
13016
  if (e.current.name === 'rect') {
12804
- const { editor } = this;
12805
13017
  this.moving = true;
12806
13018
  editor.dragStartPoint = { x: editor.element.x, y: editor.element.y };
12807
13019
  editor.opacity = editor.mergeConfig.hideOnMove ? 0 : 1;
12808
13020
  }
13021
+ else if (e.current.pointType === 'resize') {
13022
+ editor.dragStartBounds = Object.assign({}, editor.element.getLayoutBounds('box', 'local'));
13023
+ editor.resizeDirection = e.current.direction;
13024
+ }
12809
13025
  }
12810
13026
  onDragEnd(e) {
12811
13027
  this.dragging = false;
12812
13028
  this.moving = false;
12813
13029
  if (e.current.name === 'rect')
12814
13030
  this.editor.opacity = 1;
13031
+ this.editor.resizeDirection = undefined;
12815
13032
  }
12816
13033
  onDrag(e) {
12817
13034
  const { editor } = this;
@@ -12820,7 +13037,7 @@ class EditBox extends Group {
12820
13037
  if (editor.mergeConfig.rotateable)
12821
13038
  editor.onRotate(e);
12822
13039
  }
12823
- else {
13040
+ else if (point.pointType === 'resize') {
12824
13041
  editor.onScale(e);
12825
13042
  }
12826
13043
  updateCursor(editor, e);
@@ -12884,8 +13101,6 @@ class EditBox extends Group {
12884
13101
  rect.on_(DragEvent.START, this.onDragStart, this),
12885
13102
  rect.on_(DragEvent.DRAG, editor.onMove, editor),
12886
13103
  rect.on_(DragEvent.END, this.onDragEnd, this),
12887
- rect.on_(ZoomEvent.BEFORE_ZOOM, editor.onScale, editor, true),
12888
- rect.on_(RotateEvent.BEFORE_ROTATE, editor.onRotate, editor, true),
12889
13104
  rect.on_(PointerEvent.ENTER, () => updateMoveCursor(editor)),
12890
13105
  rect.on_(PointerEvent.DOUBLE_TAP, this.onDoubleTap, this),
12891
13106
  rect.on_(PointerEvent.LONG_PRESS, this.onLongPress, this)
@@ -12915,7 +13130,7 @@ class EditMask extends UI {
12915
13130
  const { rect } = editor.editBox;
12916
13131
  const { width, height } = rect.__;
12917
13132
  canvas.resetTransform();
12918
- canvas.fillWorld(canvas.bounds, mask);
13133
+ canvas.fillWorld(canvas.bounds, mask === true ? 'rgba(0,0,0,0.8)' : mask);
12919
13134
  canvas.setWorld(rect.__world, options.matrix);
12920
13135
  canvas.clearRect(0, 0, width, height);
12921
13136
  }
@@ -13000,6 +13215,7 @@ const config = {
13000
13215
  boxSelect: true,
13001
13216
  moveable: true,
13002
13217
  resizeable: true,
13218
+ flipable: true,
13003
13219
  rotateable: true,
13004
13220
  skewable: true
13005
13221
  };
@@ -13157,7 +13373,7 @@ class Editor extends Group {
13157
13373
  get buttons() { return this.editBox.buttons; }
13158
13374
  constructor(userConfig, data) {
13159
13375
  super(data);
13160
- this.config = config;
13376
+ this.config = DataHelper.clone(config);
13161
13377
  this.leafList = new LeafList();
13162
13378
  this.openedGroupList = new LeafList();
13163
13379
  this.simulateTarget = new Rect({ visible: false });
@@ -13221,29 +13437,39 @@ class Editor extends Group {
13221
13437
  return this.mergeConfig.editSize;
13222
13438
  }
13223
13439
  onMove(e) {
13224
- const total = { x: e.totalX, y: e.totalY };
13225
- if (e.shiftKey) {
13226
- if (Math.abs(total.x) > Math.abs(total.y))
13227
- total.y = 0;
13228
- else
13229
- total.x = 0;
13440
+ if (e instanceof MoveEvent) {
13441
+ if (e.moveType !== 'drag') {
13442
+ const { moveable, resizeable } = this.mergeConfig;
13443
+ const move = e.getLocalMove(this.element);
13444
+ if (moveable === 'move')
13445
+ e.stop(), this.move(move.x, move.y);
13446
+ else if (resizeable === 'zoom')
13447
+ e.stop();
13448
+ }
13449
+ }
13450
+ else {
13451
+ const total = { x: e.totalX, y: e.totalY };
13452
+ if (e.shiftKey) {
13453
+ if (Math.abs(total.x) > Math.abs(total.y))
13454
+ total.y = 0;
13455
+ else
13456
+ total.x = 0;
13457
+ }
13458
+ this.move(DragEvent.getValidMove(this.element, this.dragStartPoint, total));
13230
13459
  }
13231
- this.move(DragEvent.getValidMove(this.element, this.dragStartPoint, total));
13232
13460
  }
13233
13461
  onScale(e) {
13234
13462
  const { element } = this;
13463
+ let { around, lockRatio, resizeable, flipable, editSize } = this.mergeConfig;
13235
13464
  if (e instanceof ZoomEvent) {
13236
- if (this.mergeConfig.resizeable === 'zoom') {
13237
- e.stop();
13238
- this.scaleOf(element.getInnerPoint(e), e.scale, e.scale);
13239
- }
13465
+ if (resizeable === 'zoom')
13466
+ e.stop(), this.scaleOf(element.getInnerPoint(e), e.scale, e.scale);
13240
13467
  }
13241
13468
  else {
13242
13469
  const { direction } = e.current;
13243
- let { around, lockRatio } = this.mergeConfig;
13244
13470
  if (e.shiftKey || element.lockRatio)
13245
13471
  lockRatio = true;
13246
- const data = EditDataHelper.getScaleData(element.boxBounds, direction, e.getInnerMove(element), lockRatio, EditDataHelper.getAround(around, e.altKey));
13472
+ const data = EditDataHelper.getScaleData(element, this.dragStartBounds, direction, e.getInnerTotal(element), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, this.multiple || editSize === 'scale');
13247
13473
  if (this.editTool.onScaleWithDrag) {
13248
13474
  data.drag = e;
13249
13475
  this.scaleWithDrag(data);
@@ -13254,23 +13480,21 @@ class Editor extends Group {
13254
13480
  }
13255
13481
  }
13256
13482
  onRotate(e) {
13257
- const { skewable, around, rotateGap } = this.mergeConfig;
13483
+ const { skewable, rotateable, around, rotateGap } = this.mergeConfig;
13258
13484
  const { direction, name } = e.current;
13259
13485
  if (skewable && name === 'resize-line')
13260
13486
  return this.onSkew(e);
13261
13487
  const { element } = this;
13262
13488
  let origin, rotation;
13263
13489
  if (e instanceof RotateEvent) {
13264
- if (this.mergeConfig.rotateable === 'rotate') {
13265
- e.stop();
13266
- rotation = e.rotation, origin = element.getInnerPoint(e);
13267
- }
13490
+ if (rotateable === 'rotate')
13491
+ e.stop(), rotation = e.rotation, origin = element.getInnerPoint(e);
13268
13492
  else
13269
13493
  return;
13270
13494
  }
13271
13495
  else {
13272
13496
  const last = { x: e.x - e.moveX, y: e.y - e.moveY };
13273
- const data = EditDataHelper.getRotateData(element.boxBounds, direction, e.getInner(element), element.getInnerPoint(last), e.shiftKey ? null : (around || 'center'));
13497
+ const data = EditDataHelper.getRotateData(element.boxBounds, direction, e.getInner(element), element.getInnerPoint(last), e.shiftKey ? null : (element.around || element.origin || around || 'center'));
13274
13498
  rotation = data.rotation;
13275
13499
  origin = data.origin;
13276
13500
  }
@@ -13304,8 +13528,7 @@ class Editor extends Group {
13304
13528
  if (!this.mergeConfig.resizeable || this.element.locked)
13305
13529
  return;
13306
13530
  const { element } = this;
13307
- const worldOrigin = element.getWorldPoint(data.origin);
13308
- const event = new EditorScaleEvent(EditorScaleEvent.SCALE, Object.assign(Object.assign({}, data), { target: element, editor: this, worldOrigin }));
13531
+ const event = new EditorScaleEvent(EditorScaleEvent.SCALE, Object.assign(Object.assign({}, data), { target: element, editor: this, worldOrigin: element.getWorldPoint(data.origin) }));
13309
13532
  this.editTool.onScaleWithDrag(event);
13310
13533
  this.emitEvent(event);
13311
13534
  }
@@ -13313,28 +13536,28 @@ class Editor extends Group {
13313
13536
  if (!this.mergeConfig.resizeable || this.element.locked)
13314
13537
  return;
13315
13538
  const { element } = this;
13316
- const worldOrigin = element.getWorldPoint(LeafHelper.getInnerOrigin(element, origin));
13317
- let transform;
13318
- if (this.multiple) {
13319
- const oldMatrix = new Matrix(element.worldTransform);
13320
- element.scaleOf(origin, scaleX, scaleY);
13321
- transform = new Matrix(element.worldTransform).divide(oldMatrix);
13322
- }
13539
+ const worldOrigin = this.getWorldOrigin(origin);
13540
+ const transform = this.multiple && this.getChangedTransform(() => element.scaleOf(origin, scaleX, scaleY));
13323
13541
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, { target: element, editor: this, worldOrigin, scaleX, scaleY, transform });
13324
13542
  this.editTool.onScale(event);
13325
13543
  this.emitEvent(event);
13326
13544
  }
13545
+ flip(axis) {
13546
+ if (this.element.locked)
13547
+ return;
13548
+ const { element } = this;
13549
+ const worldOrigin = this.getWorldOrigin('center');
13550
+ const transform = this.multiple ? this.getChangedTransform(() => element.flip(axis)) : new Matrix(LeafHelper.getFlipTransform(element, axis));
13551
+ const event = new EditorScaleEvent(EditorScaleEvent.SCALE, { target: element, editor: this, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform });
13552
+ this.editTool.onScale(event);
13553
+ this.emitEvent(event);
13554
+ }
13327
13555
  rotateOf(origin, rotation) {
13328
13556
  if (!this.mergeConfig.rotateable || this.element.locked)
13329
13557
  return;
13330
13558
  const { element } = this;
13331
- const worldOrigin = element.getWorldPoint(LeafHelper.getInnerOrigin(element, origin));
13332
- let transform;
13333
- if (this.multiple) {
13334
- const oldMatrix = new Matrix(element.worldTransform);
13335
- element.rotateOf(origin, rotation);
13336
- transform = new Matrix(element.worldTransform).divide(oldMatrix);
13337
- }
13559
+ const worldOrigin = this.getWorldOrigin(origin);
13560
+ const transform = this.multiple && this.getChangedTransform(() => element.rotateOf(origin, rotation));
13338
13561
  const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, { target: element, editor: this, worldOrigin, rotation, transform });
13339
13562
  this.editTool.onRotate(event);
13340
13563
  this.emitEvent(event);
@@ -13343,19 +13566,21 @@ class Editor extends Group {
13343
13566
  if (!this.mergeConfig.skewable || this.element.locked)
13344
13567
  return;
13345
13568
  const { element } = this;
13346
- const worldOrigin = element.getWorldPoint(LeafHelper.getInnerOrigin(element, origin));
13347
- let transform;
13348
- if (this.multiple) {
13349
- const oldMatrix = new Matrix(element.worldTransform);
13350
- element.skewOf(origin, skewX, skewY);
13351
- transform = new Matrix(element.worldTransform).divide(oldMatrix);
13352
- }
13353
- const event = new EditorSkewEvent(EditorSkewEvent.SKEW, {
13354
- target: element, editor: this, skewX, skewY, transform, worldOrigin
13355
- });
13569
+ const worldOrigin = this.getWorldOrigin(origin);
13570
+ const transform = this.multiple && this.getChangedTransform(() => element.skewOf(origin, skewX, skewY));
13571
+ const event = new EditorSkewEvent(EditorSkewEvent.SKEW, { target: element, editor: this, worldOrigin, skewX, skewY, transform });
13356
13572
  this.editTool.onSkew(event);
13357
13573
  this.emitEvent(event);
13358
13574
  }
13575
+ getWorldOrigin(origin) {
13576
+ return this.element.getWorldPoint(LeafHelper.getInnerOrigin(this.element, origin));
13577
+ }
13578
+ getChangedTransform(func) {
13579
+ const { element } = this;
13580
+ const oldMatrix = new Matrix(element.worldTransform);
13581
+ func();
13582
+ return new Matrix(element.worldTransform).divide(oldMatrix);
13583
+ }
13359
13584
  group(userGroup) {
13360
13585
  if (this.multiple) {
13361
13586
  this.target = EditorHelper.group(this.list, this.element, userGroup);
@@ -13466,6 +13691,9 @@ class Editor extends Group {
13466
13691
  if (!this.targetEventIds.length) {
13467
13692
  const { leafer } = this.list[0];
13468
13693
  this.targetEventIds = [
13694
+ this.app.on_(MoveEvent.BEFORE_MOVE, this.onMove, this, true),
13695
+ this.app.on_(ZoomEvent.BEFORE_ZOOM, this.onScale, this, true),
13696
+ this.app.on_(RotateEvent.BEFORE_ROTATE, this.onRotate, this, true),
13469
13697
  leafer.on_(RenderEvent.START, this.update, this),
13470
13698
  leafer.on_([KeyEvent.HOLD, KeyEvent.UP], (e) => { updateCursor(this, e); }),
13471
13699
  leafer.on_(KeyEvent.DOWN, this.editBox.onArrow, this.editBox)
@@ -14189,6 +14417,186 @@ function setPoint(data, point, startIndex) {
14189
14417
 
14190
14418
  Object.assign(PathArrow, PathArrowModule);
14191
14419
 
14420
+ const textCaseMap = {
14421
+ 'none': 'none',
14422
+ 'title': 'capitalize',
14423
+ 'upper': 'uppercase',
14424
+ 'lower': 'lowercase',
14425
+ 'small-caps': 'small-caps'
14426
+ };
14427
+ const verticalAlignMap = {
14428
+ 'top': 'flex-start',
14429
+ 'middle': 'center',
14430
+ 'bottom': 'flex-end'
14431
+ };
14432
+ function updateStyle(textDom, text, textScale) {
14433
+ const { style } = textDom;
14434
+ const { fill, padding, textWrap, textOverflow, textDecoration } = text;
14435
+ style.fontFamily = text.fontFamily;
14436
+ style.fontSize = text.fontSize * textScale + 'px';
14437
+ setFill(style, fill);
14438
+ style.fontStyle = text.italic ? 'italic' : 'normal';
14439
+ style.fontWeight = text.fontWeight;
14440
+ style.textDecoration = textDecoration === 'delete' ? 'line-through' : textDecoration;
14441
+ style.textTransform = textCaseMap[text.textCase];
14442
+ style.textAlign = text.textAlign;
14443
+ style.display = 'flex';
14444
+ style.flexDirection = 'column';
14445
+ style.justifyContent = verticalAlignMap[text.verticalAlign];
14446
+ style.lineHeight = (text.__.__lineHeight || 0) * textScale + 'px';
14447
+ style.letterSpacing = (text.__.__letterSpacing || 0) * textScale + 'px';
14448
+ if (textWrap === 'none') {
14449
+ style.whiteSpace = 'nowrap';
14450
+ }
14451
+ else if (textWrap === 'break') {
14452
+ style.wordBreak = 'break-all';
14453
+ }
14454
+ style.textIndent = (text.paraIndent || 0) * textScale + 'px';
14455
+ style.padding = padding instanceof Array ? padding.map(item => item * textScale + 'px').join(' ') : (padding || 0) * textScale + 'px';
14456
+ style.textOverflow = textOverflow === 'show' ? '' : (textOverflow === 'hide' ? 'clip' : textOverflow);
14457
+ }
14458
+ function setFill(style, fill) {
14459
+ let color = 'black';
14460
+ if (fill instanceof Array)
14461
+ fill = fill[0];
14462
+ if (typeof fill === 'object') {
14463
+ switch (fill.type) {
14464
+ case 'solid':
14465
+ color = ColorConvert.string(fill.color);
14466
+ break;
14467
+ case 'image':
14468
+ break;
14469
+ case 'linear':
14470
+ case 'radial':
14471
+ case 'angular':
14472
+ const stop = fill.stops[0];
14473
+ color = ColorConvert.string(typeof stop === 'string' ? stop : stop.color);
14474
+ break;
14475
+ default:
14476
+ if (fill.r !== undefined)
14477
+ color = ColorConvert.string(fill);
14478
+ }
14479
+ }
14480
+ else {
14481
+ color = fill;
14482
+ }
14483
+ style.color = color;
14484
+ }
14485
+
14486
+ let TextEditor = class TextEditor extends InnerEditor {
14487
+ constructor() {
14488
+ super(...arguments);
14489
+ this.config = {
14490
+ selectAll: true
14491
+ };
14492
+ this.eventIds = [];
14493
+ }
14494
+ get tag() { return 'TextEditor'; }
14495
+ onLoad() {
14496
+ const { editor } = this;
14497
+ const { config } = editor.app;
14498
+ const text = this.editTarget;
14499
+ text.visible = false;
14500
+ this.isHTMLText = !(text instanceof Text);
14501
+ this._keyEvent = config.keyEvent;
14502
+ config.keyEvent = false;
14503
+ const div = this.editDom = document.createElement('div');
14504
+ const { style } = div;
14505
+ div.contentEditable = 'true';
14506
+ style.position = 'fixed';
14507
+ style.transformOrigin = 'left top';
14508
+ style.boxSizing = 'border-box';
14509
+ if (this.isHTMLText) {
14510
+ div.innerHTML = text.text;
14511
+ this.textScale = 1;
14512
+ }
14513
+ else {
14514
+ div.innerText = text.text;
14515
+ const { scaleX, scaleY } = text.worldTransform;
14516
+ this.textScale = Math.max(Math.abs(scaleX), Math.abs(scaleY));
14517
+ const fontSize = text.fontSize * this.textScale;
14518
+ if (fontSize < 12)
14519
+ this.textScale *= 12 / fontSize;
14520
+ }
14521
+ const { view } = editor.app;
14522
+ (this.inBody = view instanceof HTMLCanvasElement) ? document.body.appendChild(div) : view.appendChild(div);
14523
+ this.eventIds = [
14524
+ editor.app.on_(PointerEvent.DOWN, (e) => {
14525
+ let { target } = e.origin, find;
14526
+ while (target) {
14527
+ if (target === div)
14528
+ find = true;
14529
+ target = target.parentElement;
14530
+ }
14531
+ if (!find)
14532
+ editor.closeInnerEditor();
14533
+ })
14534
+ ];
14535
+ this.onFocus = this.onFocus.bind(this);
14536
+ this.onInput = this.onInput.bind(this);
14537
+ this.onUpdate = this.onUpdate.bind(this);
14538
+ this.onEscape = this.onEscape.bind(this);
14539
+ div.addEventListener("focus", this.onFocus);
14540
+ div.addEventListener("input", this.onInput);
14541
+ window.addEventListener('keydown', this.onEscape);
14542
+ window.addEventListener('scroll', this.onUpdate);
14543
+ const selection = window.getSelection();
14544
+ const range = document.createRange();
14545
+ if (this.config.selectAll) {
14546
+ range.selectNodeContents(div);
14547
+ }
14548
+ else {
14549
+ const node = div.childNodes[0];
14550
+ range.setStartAfter(node);
14551
+ range.setEndAfter(node);
14552
+ range.collapse(true);
14553
+ }
14554
+ selection.removeAllRanges();
14555
+ selection.addRange(range);
14556
+ }
14557
+ onInput() {
14558
+ const { editDom } = this;
14559
+ this.editTarget.text = this.isHTMLText ? editDom.innerHTML : editDom.innerText.replace(/\n\n/, '\n');
14560
+ }
14561
+ onFocus() {
14562
+ this.editDom.style.outline = 'none';
14563
+ }
14564
+ onEscape(e) {
14565
+ if (e.code === 'Escape')
14566
+ this.editor.closeInnerEditor();
14567
+ }
14568
+ onUpdate() {
14569
+ const { editTarget: text, textScale } = this;
14570
+ const { style } = this.editDom;
14571
+ const { x, y } = this.inBody ? text.app.clientBounds : text.app.tree.clientBounds;
14572
+ const { a, b, c, d, e, f } = new Matrix(text.worldTransform).scale(1 / textScale);
14573
+ style.transform = `matrix(${a},${b},${c},${d},${e},${f})`;
14574
+ style.left = x - window.scrollX + 'px';
14575
+ style.top = y - window.scrollY + 'px';
14576
+ style.width = text.width * textScale + (text.__.__autoWidth ? 20 : 0) + 'px';
14577
+ style.height = text.height * textScale + (text.__.__autoHeight ? 20 : 0) + 'px';
14578
+ this.isHTMLText || updateStyle(this.editDom, text, this.textScale);
14579
+ }
14580
+ onUnload() {
14581
+ const { editTarget: text, editor, editDom: dom } = this;
14582
+ if (text) {
14583
+ this.onInput();
14584
+ text.visible = true;
14585
+ editor.app.config.keyEvent = this._keyEvent;
14586
+ editor.off_(this.eventIds);
14587
+ dom.removeEventListener("focus", this.onFocus);
14588
+ dom.removeEventListener("input", this.onInput);
14589
+ window.removeEventListener('keydown', this.onEscape);
14590
+ window.removeEventListener('scroll', this.onUpdate);
14591
+ dom.remove();
14592
+ this.editDom = this.eventIds = undefined;
14593
+ }
14594
+ }
14595
+ };
14596
+ TextEditor = __decorate([
14597
+ registerInnerEditor()
14598
+ ], TextEditor);
14599
+
14192
14600
  class HTMLTextData extends ImageData {
14193
14601
  setText(value) {
14194
14602
  this._text = value;
@@ -14198,11 +14606,13 @@ class HTMLTextData extends ImageData {
14198
14606
 
14199
14607
  let HTMLText = class HTMLText extends Image {
14200
14608
  get __tag() { return 'HTMLText'; }
14609
+ get editInner() { return 'TextEditor'; }
14201
14610
  constructor(data) {
14202
14611
  super(data);
14203
14612
  }
14204
14613
  __updateBoxBounds() {
14205
- if (this.__.__htmlChanged) {
14614
+ const data = this.__;
14615
+ if (data.__htmlChanged) {
14206
14616
  const div = document.createElement('div');
14207
14617
  const { style } = div;
14208
14618
  style.all = 'initial';
@@ -14211,9 +14621,9 @@ let HTMLText = class HTMLText extends Image {
14211
14621
  div.innerHTML = this.text;
14212
14622
  document.body.appendChild(div);
14213
14623
  const { width, height } = div.getBoundingClientRect();
14214
- const italicWidth = 10;
14215
- const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width + italicWidth}" height="${height}">
14216
- <foreignObject width="${width + italicWidth}" height="${height}">
14624
+ const realWidth = width + 10;
14625
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${realWidth}" height="${height}">
14626
+ <foreignObject width="${realWidth}" height="${height}">
14217
14627
  <style>
14218
14628
  * {
14219
14629
  margin: 0;
@@ -14226,8 +14636,10 @@ let HTMLText = class HTMLText extends Image {
14226
14636
  </body>
14227
14637
  </foreignObject>
14228
14638
  </svg>`;
14229
- this.__.__setImageFill('data:image/svg+xml,' + encodeURIComponent(svg));
14230
- this.__.__htmlChanged = false;
14639
+ data.__setImageFill('data:image/svg+xml,' + encodeURIComponent(svg));
14640
+ data.__naturalWidth = realWidth / data.pixelRatio;
14641
+ data.__naturalHeight = height / data.pixelRatio;
14642
+ data.__htmlChanged = false;
14231
14643
  div.remove();
14232
14644
  }
14233
14645
  super.__updateBoxBounds();
@@ -14243,4 +14655,4 @@ HTMLText = __decorate([
14243
14655
  registerUI()
14244
14656
  ], HTMLText);
14245
14657
 
14246
- export { AlignHelper, AnimateEvent, Answer, App, AroundHelper, Arrow, ArrowData, AutoBounds, BezierHelper, Bounds, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, Cursor, DataHelper, Debug, Direction4, Direction9, DragEvent, DropEvent, EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorGroupEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Export, FileHelper, Frame, FrameData, Group, GroupData, HTMLText, HTMLTextData, HitCanvasManager, Image, ImageData, ImageEvent, ImageManager, IncrementId, InnerEditor, InnerEditorEvent, InteractionBase, InteractionHelper, KeyEvent, Keyboard, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, LeaferTypeCreator, Line, LineData, LineEditTool, MathHelper, Matrix, MatrixHelper, MoveEvent, MultiTouchHelper, 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, Platform, Point, PointHelper, PointerButton, PointerEvent, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, RotateEvent, Run, ScrollBar, SelectArea, Selector, Star, StarData, State, StringNumberMap, Stroker, SwipeEvent, TaskItem, TaskProcessor, Text, TextConvert, TextData, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIEvent, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, ZoomEvent, addInteractionWindow, 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, inviteCode, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, registerEditTool, registerInnerEditor, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleResize, scaleResizeFontSize, scaleResizeGroup, scaleResizePath, scaleResizePoints, scaleType, sortType, stateType, strokeType, surfaceType, tempBounds$1 as tempBounds, tempMatrix, tempPoint$3 as tempPoint, useCanvas, useModule, version, visibleType, zoomLayerType };
14658
+ export { AlignHelper, AnimateEvent, Answer, App, AroundHelper, Arrow, ArrowData, AutoBounds, BezierHelper, Bounds, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, Cursor, DataHelper, Debug, Direction4, Direction9, DragEvent, DropEvent, EditBox, EditDataHelper, EditPoint, EditSelect, EditSelectHelper, EditTool, EditToolCreator, Editor, EditorEvent, EditorGroupEvent, EditorHelper, EditorMoveEvent, EditorRotateEvent, EditorScaleEvent, EditorSkewEvent, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Export, FileHelper, Frame, FrameData, Group, GroupData, HTMLText, HTMLTextData, HitCanvasManager, Image, ImageData, ImageEvent, ImageManager, IncrementId, InnerEditor, InnerEditorEvent, InteractionBase, InteractionHelper, KeyEvent, Keyboard, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, LeaferTypeCreator, Line, LineData, LineEditTool, MathHelper, Matrix, MatrixHelper, MoveEvent, MultiTouchHelper, MyDragEvent, MyImage, MyPointerEvent, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, PaintGradient, PaintImage, Path, PathArrow, PathArrowModule, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathMatrixHelper, PathNumberCommandLengthMap, PathNumberCommandMap, PathScaler, Pen, PenData, Platform, Point, PointHelper, PointerButton, PointerEvent, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, RotateEvent, Run, ScrollBar, SelectArea, Selector, Star, StarData, State, StringNumberMap, Stroker, SwipeEvent, TaskItem, TaskProcessor, Text, TextConvert, TextData, TextEditor, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIEvent, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, ZoomEvent, addInteractionWindow, 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, inviteCode, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, registerEditTool, registerInnerEditor, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleResize, scaleResizeFontSize, scaleResizeGroup, scaleResizePath, scaleResizePoints, scaleType, sortType, stateType, strokeType, surfaceType, tempBounds$1 as tempBounds, tempMatrix, tempPoint$3 as tempPoint, useCanvas, useModule, version, visibleType, zoomLayerType };