leafer-draw 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.
package/dist/web.js CHANGED
@@ -51,6 +51,8 @@ var LeaferUI = (function (exports) {
51
51
  const { round, pow: pow$1, PI: PI$4 } = Math;
52
52
  const MathHelper = {
53
53
  within(value, min, max) {
54
+ if (typeof min === 'object')
55
+ max = min.max, min = min.min;
54
56
  if (min !== undefined && value < min)
55
57
  value = min;
56
58
  if (max !== undefined && value > max)
@@ -112,6 +114,19 @@ var LeaferUI = (function (exports) {
112
114
  const a = maxLength ? pow$1(10, maxLength) : 1000000000000;
113
115
  num = round(num * a) / a;
114
116
  return num === -0 ? 0 : num;
117
+ },
118
+ getScaleData(scale, size, originSize, scaleData) {
119
+ if (!scaleData)
120
+ scaleData = {};
121
+ if (size) {
122
+ scaleData.scaleX = (typeof size === 'number' ? size : size.width) / originSize.width;
123
+ scaleData.scaleY = (typeof size === 'number' ? size : size.height) / originSize.height;
124
+ }
125
+ else if (scale) {
126
+ scaleData.scaleX = typeof scale === 'number' ? scale : scale.x;
127
+ scaleData.scaleY = typeof scale === 'number' ? scale : scale.y;
128
+ }
129
+ return scaleData;
115
130
  }
116
131
  };
117
132
  const OneRadian = PI$4 / 180;
@@ -153,10 +168,10 @@ var LeaferUI = (function (exports) {
153
168
  t.e += x;
154
169
  t.f += y;
155
170
  },
156
- translateInner(t, x, y, isMoveOrigin) {
171
+ translateInner(t, x, y, hasOrigin) {
157
172
  t.e += t.a * x + t.c * y;
158
173
  t.f += t.b * x + t.d * y;
159
- if (isMoveOrigin)
174
+ if (hasOrigin)
160
175
  t.e -= x, t.f -= y;
161
176
  },
162
177
  scale(t, scaleX, scaleY = scaleX) {
@@ -315,7 +330,7 @@ var LeaferUI = (function (exports) {
315
330
  to.y -= (f * a - e * b) * s;
316
331
  }
317
332
  },
318
- setLayout(t, layout, origin, bcChanged) {
333
+ setLayout(t, layout, origin, around, bcChanged) {
319
334
  const { x, y, scaleX, scaleY } = layout;
320
335
  if (bcChanged === undefined)
321
336
  bcChanged = layout.rotation || layout.skewX || layout.skewY;
@@ -347,10 +362,10 @@ var LeaferUI = (function (exports) {
347
362
  }
348
363
  t.e = x;
349
364
  t.f = y;
350
- if (origin)
351
- M$6.translateInner(t, -origin.x, -origin.y, true);
365
+ if (origin = origin || around)
366
+ M$6.translateInner(t, -origin.x, -origin.y, !around);
352
367
  },
353
- getLayout(t, origin, firstSkewY) {
368
+ getLayout(t, origin, around, firstSkewY) {
354
369
  const { a, b, c, d, e, f } = t;
355
370
  let x = e, y = f, scaleX, scaleY, rotation, skewX, skewY;
356
371
  if (b || c) {
@@ -379,9 +394,11 @@ var LeaferUI = (function (exports) {
379
394
  scaleY = d;
380
395
  rotation = skewX = skewY = 0;
381
396
  }
382
- if (origin) {
397
+ if (origin = around || origin) {
383
398
  x += origin.x * a + origin.y * c;
384
399
  y += origin.x * b + origin.y * d;
400
+ if (!around)
401
+ x -= origin.x, y -= origin.y;
385
402
  }
386
403
  return { x, y, scaleX, scaleY, rotation, skewX, skewY };
387
404
  },
@@ -408,7 +425,7 @@ var LeaferUI = (function (exports) {
408
425
  };
409
426
  const M$6 = MatrixHelper;
410
427
 
411
- const { toInnerPoint: toInnerPoint$2, toOuterPoint: toOuterPoint$2 } = MatrixHelper;
428
+ const { toInnerPoint: toInnerPoint$2, toOuterPoint: toOuterPoint$3 } = MatrixHelper;
412
429
  const { sin: sin$4, cos: cos$4, abs: abs$4, sqrt: sqrt$2, atan2: atan2$2, min: min$1, PI: PI$3 } = Math;
413
430
  const PointHelper = {
414
431
  defaultPoint: getPointData(),
@@ -464,7 +481,7 @@ var LeaferUI = (function (exports) {
464
481
  tempToOuterOf(t, matrix) {
465
482
  const { tempPoint: temp } = P$5;
466
483
  copy$a(temp, t);
467
- toOuterPoint$2(matrix, temp, temp);
484
+ toOuterPoint$3(matrix, temp, temp);
468
485
  return temp;
469
486
  },
470
487
  tempToInnerRadiusPointOf(t, matrix) {
@@ -483,7 +500,7 @@ var LeaferUI = (function (exports) {
483
500
  toInnerPoint$2(matrix, t, to);
484
501
  },
485
502
  toOuterOf(t, matrix, to) {
486
- toOuterPoint$2(matrix, t, to);
503
+ toOuterPoint$3(matrix, t, to);
487
504
  },
488
505
  getCenter(t, to) {
489
506
  return { x: t.x + (to.x - t.x) / 2, y: t.y + (to.y - t.y) / 2 };
@@ -709,12 +726,12 @@ var LeaferUI = (function (exports) {
709
726
  toInnerPoint(outer, to, distance) {
710
727
  MatrixHelper.toInnerPoint(this, outer, to, distance);
711
728
  }
712
- setLayout(data, origin) {
713
- MatrixHelper.setLayout(this, data, origin);
729
+ setLayout(data, origin, around) {
730
+ MatrixHelper.setLayout(this, data, origin, around);
714
731
  return this;
715
732
  }
716
- getLayout(origin, firstSkewY) {
717
- return MatrixHelper.getLayout(this, origin, firstSkewY);
733
+ getLayout(origin, around, firstSkewY) {
734
+ return MatrixHelper.getLayout(this, origin, around, firstSkewY);
718
735
  }
719
736
  withScale(scaleX, scaleY) {
720
737
  return MatrixHelper.withScale(this, scaleX, scaleY);
@@ -763,7 +780,7 @@ var LeaferUI = (function (exports) {
763
780
  const { addPoint: addPoint$4 } = TwoPointBoundsHelper;
764
781
 
765
782
  const { tempPointBounds: tempPointBounds$1, setPoint: setPoint$3, addPoint: addPoint$3, toBounds: toBounds$4 } = TwoPointBoundsHelper;
766
- const { toOuterPoint: toOuterPoint$1 } = MatrixHelper;
783
+ const { toOuterPoint: toOuterPoint$2 } = MatrixHelper;
767
784
  const { float, fourNumber } = MathHelper;
768
785
  const { floor, ceil: ceil$2 } = Math;
769
786
  let right$1, bottom$1, boundsRight, boundsBottom;
@@ -783,17 +800,24 @@ var LeaferUI = (function (exports) {
783
800
  t.width = bounds.width;
784
801
  t.height = bounds.height;
785
802
  },
786
- copyAndSpread(t, bounds, spread, isShrink) {
803
+ copyAndSpread(t, bounds, spread, isShrink, side) {
804
+ const { x, y, width, height } = bounds;
787
805
  if (spread instanceof Array) {
788
806
  const four = fourNumber(spread);
789
807
  isShrink
790
- ? B.set(t, bounds.x + four[3], bounds.y + four[0], bounds.width - four[1] - four[3], bounds.height - four[2] - four[0])
791
- : B.set(t, bounds.x - four[3], bounds.y - four[0], bounds.width + four[1] + four[3], bounds.height + four[2] + four[0]);
808
+ ? B.set(t, x + four[3], y + four[0], width - four[1] - four[3], height - four[2] - four[0])
809
+ : B.set(t, x - four[3], y - four[0], width + four[1] + four[3], height + four[2] + four[0]);
792
810
  }
793
811
  else {
794
812
  if (isShrink)
795
813
  spread = -spread;
796
- B.set(t, bounds.x - spread, bounds.y - spread, bounds.width + spread * 2, bounds.height + spread * 2);
814
+ B.set(t, x - spread, y - spread, width + spread * 2, height + spread * 2);
815
+ }
816
+ if (side) {
817
+ if (side === 'width')
818
+ t.y = y, t.height = height;
819
+ else
820
+ t.x = x, t.width = width;
797
821
  }
798
822
  },
799
823
  minX(t) { return t.width > 0 ? t.x : t.x + t.width; },
@@ -870,16 +894,16 @@ var LeaferUI = (function (exports) {
870
894
  else {
871
895
  point.x = t.x;
872
896
  point.y = t.y;
873
- toOuterPoint$1(matrix, point, toPoint$5);
897
+ toOuterPoint$2(matrix, point, toPoint$5);
874
898
  setPoint$3(tempPointBounds$1, toPoint$5.x, toPoint$5.y);
875
899
  point.x = t.x + t.width;
876
- toOuterPoint$1(matrix, point, toPoint$5);
900
+ toOuterPoint$2(matrix, point, toPoint$5);
877
901
  addPoint$3(tempPointBounds$1, toPoint$5.x, toPoint$5.y);
878
902
  point.y = t.y + t.height;
879
- toOuterPoint$1(matrix, point, toPoint$5);
903
+ toOuterPoint$2(matrix, point, toPoint$5);
880
904
  addPoint$3(tempPointBounds$1, toPoint$5.x, toPoint$5.y);
881
905
  point.x = t.x;
882
- toOuterPoint$1(matrix, point, toPoint$5);
906
+ toOuterPoint$2(matrix, point, toPoint$5);
883
907
  addPoint$3(tempPointBounds$1, toPoint$5.x, toPoint$5.y);
884
908
  toBounds$4(tempPointBounds$1, to);
885
909
  }
@@ -893,16 +917,16 @@ var LeaferUI = (function (exports) {
893
917
  const scale = Math.min(baseScale, Math.min(t.width / put.width, t.height / put.height));
894
918
  return new Matrix(scale, 0, 0, scale, -put.x * scale, -put.y * scale);
895
919
  },
896
- getSpread(t, spread) {
920
+ getSpread(t, spread, side) {
897
921
  const n = {};
898
- B.copyAndSpread(n, t, spread);
922
+ B.copyAndSpread(n, t, spread, false, side);
899
923
  return n;
900
924
  },
901
- spread(t, spread) {
902
- B.copyAndSpread(t, t, spread);
925
+ spread(t, spread, side) {
926
+ B.copyAndSpread(t, t, spread, false, side);
903
927
  },
904
- shrink(t, shrink) {
905
- B.copyAndSpread(t, t, shrink, true);
928
+ shrink(t, shrink, side) {
929
+ B.copyAndSpread(t, t, shrink, true, side);
906
930
  },
907
931
  ceil(t) {
908
932
  const { x, y } = t;
@@ -1085,12 +1109,12 @@ var LeaferUI = (function (exports) {
1085
1109
  getFitMatrix(put, baseScale) {
1086
1110
  return BoundsHelper.getFitMatrix(this, put, baseScale);
1087
1111
  }
1088
- spread(fourNumber) {
1089
- BoundsHelper.spread(this, fourNumber);
1112
+ spread(fourNumber, side) {
1113
+ BoundsHelper.spread(this, fourNumber, side);
1090
1114
  return this;
1091
1115
  }
1092
- shrink(fourNumber) {
1093
- BoundsHelper.shrink(this, fourNumber);
1116
+ shrink(fourNumber, side) {
1117
+ BoundsHelper.shrink(this, fourNumber, side);
1094
1118
  return this;
1095
1119
  }
1096
1120
  ceil() {
@@ -2002,7 +2026,7 @@ var LeaferUI = (function (exports) {
2002
2026
  DataHelper.copyAttrs(this.size, size, canvasSizeAttrs);
2003
2027
  this.size.pixelRatio || (this.size.pixelRatio = 1);
2004
2028
  this.bounds = new Bounds(0, 0, this.width, this.height);
2005
- if (!this.unreal) {
2029
+ if (this.context && !this.unreal) {
2006
2030
  this.updateViewSize();
2007
2031
  this.smooth = this.config.smooth;
2008
2032
  }
@@ -2175,7 +2199,7 @@ var LeaferUI = (function (exports) {
2175
2199
  this.manager ? this.manager.recycle(this) : this.destroy();
2176
2200
  }
2177
2201
  }
2178
- updateRender() { }
2202
+ updateRender(_bounds) { }
2179
2203
  unrealCanvas() { }
2180
2204
  destroy() {
2181
2205
  this.manager = this.view = this.parentView = null;
@@ -2907,60 +2931,75 @@ var LeaferUI = (function (exports) {
2907
2931
  }
2908
2932
  beginPath() {
2909
2933
  beginPath(this.__path);
2934
+ this.paint();
2910
2935
  return this;
2911
2936
  }
2912
2937
  moveTo(x, y) {
2913
2938
  moveTo$4(this.__path, x, y);
2939
+ this.paint();
2914
2940
  return this;
2915
2941
  }
2916
2942
  lineTo(x, y) {
2917
2943
  lineTo$3(this.__path, x, y);
2944
+ this.paint();
2918
2945
  return this;
2919
2946
  }
2920
2947
  bezierCurveTo(x1, y1, x2, y2, x, y) {
2921
2948
  bezierCurveTo(this.__path, x1, y1, x2, y2, x, y);
2949
+ this.paint();
2922
2950
  return this;
2923
2951
  }
2924
2952
  quadraticCurveTo(x1, y1, x, y) {
2925
2953
  quadraticCurveTo(this.__path, x1, y1, x, y);
2954
+ this.paint();
2926
2955
  return this;
2927
2956
  }
2928
2957
  closePath() {
2929
2958
  closePath$3(this.__path);
2959
+ this.paint();
2930
2960
  return this;
2931
2961
  }
2932
2962
  rect(x, y, width, height) {
2933
2963
  rect$1(this.__path, x, y, width, height);
2964
+ this.paint();
2934
2965
  return this;
2935
2966
  }
2936
2967
  roundRect(x, y, width, height, cornerRadius) {
2937
2968
  roundRect$1(this.__path, x, y, width, height, cornerRadius);
2969
+ this.paint();
2938
2970
  return this;
2939
2971
  }
2940
2972
  ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise) {
2941
2973
  ellipse$2(this.__path, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise);
2974
+ this.paint();
2942
2975
  return this;
2943
2976
  }
2944
2977
  arc(x, y, radius, startAngle, endAngle, anticlockwise) {
2945
2978
  arc$1(this.__path, x, y, radius, startAngle, endAngle, anticlockwise);
2979
+ this.paint();
2946
2980
  return this;
2947
2981
  }
2948
2982
  arcTo(x1, y1, x2, y2, radius) {
2949
2983
  arcTo$2(this.__path, x1, y1, x2, y2, radius);
2984
+ this.paint();
2950
2985
  return this;
2951
2986
  }
2952
2987
  drawEllipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise) {
2953
2988
  drawEllipse(this.__path, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise);
2989
+ this.paint();
2954
2990
  return this;
2955
2991
  }
2956
2992
  drawArc(x, y, radius, startAngle, endAngle, anticlockwise) {
2957
2993
  drawArc(this.__path, x, y, radius, startAngle, endAngle, anticlockwise);
2994
+ this.paint();
2958
2995
  return this;
2959
2996
  }
2960
2997
  drawPoints(points, curve, close) {
2961
2998
  drawPoints$2(this.__path, points, curve, close);
2999
+ this.paint();
2962
3000
  return this;
2963
3001
  }
3002
+ paint() { }
2964
3003
  }
2965
3004
 
2966
3005
  const { M: M$2, L: L$3, C: C$2, Q: Q$1, Z: Z$2, N: N$1, D: D$1, X: X$1, G: G$1, F: F$2, O: O$1, P: P$1, U: U$1 } = PathCommandMap;
@@ -3982,7 +4021,7 @@ var LeaferUI = (function (exports) {
3982
4021
  };
3983
4022
  }
3984
4023
 
3985
- const { copy: copy$6, toInnerPoint: toInnerPoint$1, scaleOfOuter: scaleOfOuter$2, rotateOfOuter: rotateOfOuter$2, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
4024
+ const { copy: copy$6, toInnerPoint: toInnerPoint$1, toOuterPoint: toOuterPoint$1, scaleOfOuter: scaleOfOuter$2, rotateOfOuter: rotateOfOuter$2, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
3986
4025
  const matrix = {};
3987
4026
  const LeafHelper = {
3988
4027
  updateAllMatrix(leaf, checkAutoLayout, waitAutoLayout) {
@@ -4047,10 +4086,9 @@ var LeaferUI = (function (exports) {
4047
4086
  }
4048
4087
  return true;
4049
4088
  },
4050
- moveWorld(t, x, y = 0) {
4089
+ moveWorld(t, x, y = 0, isInnerPoint) {
4051
4090
  const local = typeof x === 'object' ? Object.assign({}, x) : { x, y };
4052
- if (t.parent)
4053
- toInnerPoint$1(t.parent.worldTransform, local, local, true);
4091
+ isInnerPoint ? toOuterPoint$1(t.localTransform, local, local, true) : (t.parent && toInnerPoint$1(t.parent.worldTransform, local, local, true));
4054
4092
  L.moveLocal(t, local.x, local.y);
4055
4093
  },
4056
4094
  moveLocal(t, x, y = 0) {
@@ -4069,8 +4107,13 @@ var LeaferUI = (function (exports) {
4069
4107
  zoomOfLocal(t, origin, scaleX, scaleY = scaleX, resize) {
4070
4108
  copy$6(matrix, t.__localMatrix);
4071
4109
  scaleOfOuter$2(matrix, origin, scaleX, scaleY);
4072
- moveByMatrix(t, matrix);
4073
- t.scaleResize(scaleX, scaleY, resize !== true);
4110
+ if (t.origin || t.around) {
4111
+ L.setTransform(t, matrix, resize);
4112
+ }
4113
+ else {
4114
+ moveByMatrix(t, matrix);
4115
+ t.scaleResize(scaleX, scaleY, resize !== true);
4116
+ }
4074
4117
  },
4075
4118
  rotateOfWorld(t, origin, angle) {
4076
4119
  L.rotateOfLocal(t, getTempLocal(t, origin), angle);
@@ -4078,8 +4121,13 @@ var LeaferUI = (function (exports) {
4078
4121
  rotateOfLocal(t, origin, angle) {
4079
4122
  copy$6(matrix, t.__localMatrix);
4080
4123
  rotateOfOuter$2(matrix, origin, angle);
4081
- moveByMatrix(t, matrix);
4082
- t.rotation = MathHelper.formatRotation(t.rotation + angle);
4124
+ if (t.origin || t.around) {
4125
+ L.setTransform(t, matrix);
4126
+ }
4127
+ else {
4128
+ moveByMatrix(t, matrix);
4129
+ t.rotation = MathHelper.formatRotation(t.rotation + angle);
4130
+ }
4083
4131
  },
4084
4132
  skewOfWorld(t, origin, skewX, skewY, resize) {
4085
4133
  L.skewOfLocal(t, getTempLocal(t, origin), skewX, skewY, resize);
@@ -4102,7 +4150,7 @@ var LeaferUI = (function (exports) {
4102
4150
  L.setTransform(t, matrix, resize);
4103
4151
  },
4104
4152
  setTransform(t, transform, resize) {
4105
- const layout = getLayout(transform);
4153
+ const layout = getLayout(transform, t.origin && L.getInnerOrigin(t, t.origin), t.around && L.getInnerOrigin(t, t.around));
4106
4154
  if (resize) {
4107
4155
  const scaleX = layout.scaleX / t.scaleX;
4108
4156
  const scaleY = layout.scaleY / t.scaleY;
@@ -4115,13 +4163,19 @@ var LeaferUI = (function (exports) {
4115
4163
  t.set(layout);
4116
4164
  }
4117
4165
  },
4166
+ getFlipTransform(t, axis) {
4167
+ const m = getMatrixData();
4168
+ const sign = axis === 'x' ? 1 : -1;
4169
+ scaleOfOuter$2(m, L.getLocalOrigin(t, 'center'), -1 * sign, 1 * sign);
4170
+ return m;
4171
+ },
4118
4172
  getLocalOrigin(t, origin) {
4119
4173
  return PointHelper.tempToOuterOf(L.getInnerOrigin(t, origin), t.localTransform);
4120
4174
  },
4121
4175
  getInnerOrigin(t, origin) {
4122
- if (typeof origin === 'string')
4123
- AroundHelper.toPoint(origin, t.boxBounds, origin = {});
4124
- return origin;
4176
+ const innerOrigin = {};
4177
+ AroundHelper.toPoint(origin, t.boxBounds, innerOrigin);
4178
+ return innerOrigin;
4125
4179
  },
4126
4180
  getRelativeWorld(t, relative, temp) {
4127
4181
  copy$6(matrix, t.worldTransform);
@@ -4548,7 +4602,10 @@ var LeaferUI = (function (exports) {
4548
4602
  on(type, listener, options) {
4549
4603
  let capture, once;
4550
4604
  if (options) {
4551
- if (typeof options === 'boolean') {
4605
+ if (options === 'once') {
4606
+ once = true;
4607
+ }
4608
+ else if (typeof options === 'boolean') {
4552
4609
  capture = options;
4553
4610
  }
4554
4611
  else {
@@ -4579,7 +4636,7 @@ var LeaferUI = (function (exports) {
4579
4636
  if (listener) {
4580
4637
  let capture;
4581
4638
  if (options)
4582
- capture = typeof options === 'boolean' ? options : options.capture;
4639
+ capture = typeof options === 'boolean' ? options : (options === 'once' ? false : options.capture);
4583
4640
  let events, index;
4584
4641
  const map = __getListenerMap(this, capture);
4585
4642
  typeList.forEach(type => {
@@ -4881,7 +4938,7 @@ var LeaferUI = (function (exports) {
4881
4938
  const layout = this.__layout, local = this.__local, data = this.__;
4882
4939
  if (layout.affectScaleOrRotation) {
4883
4940
  if (layout.scaleChanged || layout.rotationChanged) {
4884
- setLayout(local, data, null, layout.affectRotation);
4941
+ setLayout(local, data, null, null, layout.affectRotation);
4885
4942
  layout.scaleChanged = layout.rotationChanged = false;
4886
4943
  }
4887
4944
  }
@@ -4889,7 +4946,7 @@ var LeaferUI = (function (exports) {
4889
4946
  local.f = data.y + data.offsetY;
4890
4947
  if (data.around || data.origin) {
4891
4948
  toPoint$3(data.around || data.origin, layout.boxBounds, tempPoint$1);
4892
- translateInner(local, -tempPoint$1.x, -tempPoint$1.y, data.origin);
4949
+ translateInner(local, -tempPoint$1.x, -tempPoint$1.y, !data.around);
4893
4950
  }
4894
4951
  }
4895
4952
  this.__layout.matrixChanged = false;
@@ -4898,7 +4955,7 @@ var LeaferUI = (function (exports) {
4898
4955
 
4899
4956
  const { updateMatrix: updateMatrix$1, updateAllMatrix: updateAllMatrix$2 } = LeafHelper;
4900
4957
  const { updateBounds: updateBounds$1 } = BranchHelper;
4901
- const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$1, copy: copy$4 } = BoundsHelper;
4958
+ const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$2, copy: copy$4 } = BoundsHelper;
4902
4959
  const { toBounds: toBounds$2 } = PathBounds;
4903
4960
  const LeafBounds = {
4904
4961
  __updateWorldBounds() {
@@ -4999,7 +5056,7 @@ var LeaferUI = (function (exports) {
4999
5056
  updateAllMatrix$2(this);
5000
5057
  updateBounds$1(this, this);
5001
5058
  if (this.__.__autoSide)
5002
- this.__updateBoxBounds();
5059
+ this.__updateBoxBounds(true);
5003
5060
  }
5004
5061
  else {
5005
5062
  updateAllMatrix$2(this);
@@ -5017,11 +5074,11 @@ var LeaferUI = (function (exports) {
5017
5074
  },
5018
5075
  __updateStrokeBounds() {
5019
5076
  const layout = this.__layout;
5020
- copyAndSpread$1(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
5077
+ copyAndSpread$2(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
5021
5078
  },
5022
5079
  __updateRenderBounds() {
5023
5080
  const layout = this.__layout;
5024
- layout.renderSpread > 0 ? copyAndSpread$1(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$4(layout.renderBounds, layout.strokeBounds);
5081
+ layout.renderSpread > 0 ? copyAndSpread$2(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$4(layout.renderBounds, layout.strokeBounds);
5025
5082
  }
5026
5083
  };
5027
5084
 
@@ -5118,7 +5175,7 @@ var LeaferUI = (function (exports) {
5118
5175
  const { toInnerPoint, toOuterPoint, multiplyParent } = MatrixHelper;
5119
5176
  const { toOuterOf } = BoundsHelper;
5120
5177
  const { copy: copy$3 } = PointHelper;
5121
- const { moveLocal, zoomOfLocal, rotateOfLocal, skewOfLocal, moveWorld, zoomOfWorld, rotateOfWorld, skewOfWorld, transform, transformWorld, setTransform, getLocalOrigin, getRelativeWorld, drop } = LeafHelper;
5178
+ const { moveLocal, zoomOfLocal, rotateOfLocal, skewOfLocal, moveWorld, zoomOfWorld, rotateOfWorld, skewOfWorld, transform, transformWorld, setTransform, getFlipTransform, getLocalOrigin, getRelativeWorld, drop } = LeafHelper;
5122
5179
  exports.Leaf = class Leaf {
5123
5180
  get tag() { return this.__tag; }
5124
5181
  set tag(_value) { }
@@ -5144,6 +5201,8 @@ var LeaferUI = (function (exports) {
5144
5201
  get __ignoreHitWorld() { return (this.__hasMask || this.__hasEraser) && this.__.hitChildren; }
5145
5202
  get __inLazyBounds() { const { leafer } = this; return leafer && leafer.created && leafer.lazyBounds.hit(this.__world); }
5146
5203
  get pathInputed() { return this.__.__pathInputed; }
5204
+ set event(map) { let event; for (let key in map)
5205
+ event = map[key], event instanceof Array ? this.on(key, event[0], event[1]) : this.on(key, event); }
5147
5206
  constructor(data) {
5148
5207
  this.innerId = create(LEAF);
5149
5208
  this.reset(data);
@@ -5379,6 +5438,9 @@ var LeaferUI = (function (exports) {
5379
5438
  move(x, y) {
5380
5439
  moveLocal(this, x, y);
5381
5440
  }
5441
+ moveInner(x, y) {
5442
+ moveWorld(this, x, y, true);
5443
+ }
5382
5444
  scaleOf(origin, scaleX, scaleY, resize) {
5383
5445
  zoomOfLocal(this, getLocalOrigin(this, origin), scaleX, scaleY, resize);
5384
5446
  }
@@ -5403,6 +5465,9 @@ var LeaferUI = (function (exports) {
5403
5465
  skewOfWorld(worldOrigin, skewX, skewY, resize) {
5404
5466
  skewOfWorld(this, worldOrigin, skewX, skewY, resize);
5405
5467
  }
5468
+ flip(axis) {
5469
+ transform(this, getFlipTransform(this, axis));
5470
+ }
5406
5471
  scaleResize(scaleX, scaleY = scaleX, _noResize) {
5407
5472
  this.scaleX *= scaleX;
5408
5473
  this.scaleY *= scaleY;
@@ -5760,7 +5825,7 @@ var LeaferUI = (function (exports) {
5760
5825
  }
5761
5826
  }
5762
5827
 
5763
- const version = "1.0.0-rc.30";
5828
+ const version = "1.0.1";
5764
5829
  const inviteCode = {};
5765
5830
 
5766
5831
  const debug$5 = Debug.get('LeaferCanvas');
@@ -5784,7 +5849,8 @@ var LeaferUI = (function (exports) {
5784
5849
  }
5785
5850
  }
5786
5851
  init() {
5787
- const { view } = this.config;
5852
+ const { config } = this;
5853
+ const view = config.view || config.canvas;
5788
5854
  view ? this.__createViewFrom(view) : this.__createView();
5789
5855
  const { style } = this.view;
5790
5856
  style.display || (style.display = 'block');
@@ -5799,7 +5865,7 @@ var LeaferUI = (function (exports) {
5799
5865
  }
5800
5866
  this.__createContext();
5801
5867
  if (!this.autoLayout)
5802
- this.resize(this.config);
5868
+ this.resize(config);
5803
5869
  }
5804
5870
  set backgroundColor(color) { this.view.style.backgroundColor = color; }
5805
5871
  get backgroundColor() { return this.view.style.backgroundColor; }
@@ -5855,26 +5921,37 @@ var LeaferUI = (function (exports) {
5855
5921
  this.clientBounds = this.view.getBoundingClientRect();
5856
5922
  }
5857
5923
  startAutoLayout(autoBounds, listener) {
5858
- this.autoBounds = autoBounds;
5859
5924
  this.resizeListener = listener;
5860
- try {
5861
- this.resizeObserver = new ResizeObserver((entries) => {
5862
- this.updateClientBounds();
5863
- for (const entry of entries)
5864
- this.checkAutoBounds(entry.contentRect);
5865
- });
5866
- const parent = this.parentView;
5867
- if (parent) {
5868
- this.resizeObserver.observe(parent);
5869
- this.checkAutoBounds(parent.getBoundingClientRect());
5925
+ if (autoBounds) {
5926
+ this.autoBounds = autoBounds;
5927
+ try {
5928
+ this.resizeObserver = new ResizeObserver((entries) => {
5929
+ this.updateClientBounds();
5930
+ for (const entry of entries)
5931
+ this.checkAutoBounds(entry.contentRect);
5932
+ });
5933
+ const parent = this.parentView;
5934
+ if (parent) {
5935
+ this.resizeObserver.observe(parent);
5936
+ this.checkAutoBounds(parent.getBoundingClientRect());
5937
+ }
5938
+ else {
5939
+ this.checkAutoBounds(this.view);
5940
+ debug$5.warn('no parent');
5941
+ }
5870
5942
  }
5871
- else {
5872
- this.checkAutoBounds(this.view);
5873
- debug$5.warn('no parent');
5943
+ catch (_a) {
5944
+ this.imitateResizeObserver();
5874
5945
  }
5875
5946
  }
5876
- catch (_a) {
5877
- this.imitateResizeObserver();
5947
+ else {
5948
+ window.addEventListener('resize', () => {
5949
+ const pixelRatio = Platform.devicePixelRatio;
5950
+ if (this.pixelRatio !== pixelRatio) {
5951
+ const { width, height } = this;
5952
+ this.emitResize({ width, height, pixelRatio });
5953
+ }
5954
+ });
5878
5955
  }
5879
5956
  }
5880
5957
  imitateResizeObserver() {
@@ -5887,17 +5964,12 @@ var LeaferUI = (function (exports) {
5887
5964
  checkAutoBounds(parentSize) {
5888
5965
  const view = this.view;
5889
5966
  const { x, y, width, height } = this.autoBounds.getBoundsFrom(parentSize);
5890
- if (width !== this.width || height !== this.height) {
5967
+ const size = { width, height, pixelRatio: Platform.devicePixelRatio };
5968
+ if (!this.isSameSize(size)) {
5891
5969
  const { style } = view;
5892
- const { pixelRatio } = this;
5893
5970
  style.marginLeft = x + 'px';
5894
5971
  style.marginTop = y + 'px';
5895
- const size = { width, height, pixelRatio };
5896
- const oldSize = {};
5897
- DataHelper.copyAttrs(oldSize, this, canvasSizeAttrs);
5898
- this.resize(size);
5899
- if (this.width !== undefined)
5900
- this.resizeListener(new ResizeEvent(size, oldSize));
5972
+ this.emitResize(size);
5901
5973
  }
5902
5974
  }
5903
5975
  stopAutoLayout() {
@@ -5908,6 +5980,13 @@ var LeaferUI = (function (exports) {
5908
5980
  this.resizeObserver = null;
5909
5981
  }
5910
5982
  }
5983
+ emitResize(size) {
5984
+ const oldSize = {};
5985
+ DataHelper.copyAttrs(oldSize, this, canvasSizeAttrs);
5986
+ this.resize(size);
5987
+ if (this.width !== undefined)
5988
+ this.resizeListener(new ResizeEvent(size, oldSize));
5989
+ }
5911
5990
  unrealCanvas() {
5912
5991
  if (!this.unreal && this.parentView) {
5913
5992
  const view = this.view;
@@ -5988,7 +6067,7 @@ var LeaferUI = (function (exports) {
5988
6067
  Platform.name = 'web';
5989
6068
  Platform.isMobile = 'ontouchstart' in window;
5990
6069
  Platform.requestRender = function (render) { window.requestAnimationFrame(render); };
5991
- Platform.devicePixelRatio = Math.max(1, devicePixelRatio);
6070
+ defineKey(Platform, 'devicePixelRatio', { get() { return Math.max(1, devicePixelRatio); } });
5992
6071
  const { userAgent } = navigator;
5993
6072
  if (userAgent.indexOf("Firefox") > -1) {
5994
6073
  Platform.conicGradientRotate90 = true;
@@ -6485,14 +6564,14 @@ var LeaferUI = (function (exports) {
6485
6564
  if (Debug.showRepaint)
6486
6565
  this.canvas.strokeWorld(bounds, 'red');
6487
6566
  this.target.__render(this.canvas, options);
6488
- this.renderBounds = realBounds || bounds;
6567
+ this.renderBounds = realBounds = realBounds || bounds;
6489
6568
  this.renderOptions = options;
6490
- this.totalBounds.isEmpty() ? this.totalBounds = this.renderBounds : this.totalBounds.add(this.renderBounds);
6569
+ this.totalBounds.isEmpty() ? this.totalBounds = realBounds : this.totalBounds.add(realBounds);
6491
6570
  if (Debug.showHitView)
6492
6571
  this.renderHitView(options);
6493
6572
  if (Debug.showBoundsView)
6494
6573
  this.renderBoundsView(options);
6495
- this.canvas.updateRender();
6574
+ this.canvas.updateRender(realBounds);
6496
6575
  }
6497
6576
  renderHitView(_options) { }
6498
6577
  renderBoundsView(_options) { }
@@ -6801,6 +6880,11 @@ var LeaferUI = (function (exports) {
6801
6880
  }
6802
6881
 
6803
6882
  class LeaferData extends GroupData {
6883
+ __getInputData() {
6884
+ const data = super.__getInputData();
6885
+ canvasSizeAttrs.forEach(key => delete data[key]);
6886
+ return data;
6887
+ }
6804
6888
  }
6805
6889
 
6806
6890
  class FrameData extends BoxData {
@@ -6878,6 +6962,11 @@ var LeaferUI = (function (exports) {
6878
6962
  }
6879
6963
 
6880
6964
  class CanvasData extends RectData {
6965
+ __getInputData() {
6966
+ const data = super.__getInputData();
6967
+ data.url = this.__leaf.canvas.toDataURL('image/png');
6968
+ return data;
6969
+ }
6881
6970
  }
6882
6971
 
6883
6972
  const UIBounds = {
@@ -7543,7 +7632,7 @@ var LeaferUI = (function (exports) {
7543
7632
  this.__controllers.push(this.renderer = Creator.renderer(this, canvas, config), this.watcher = Creator.watcher(this, config), this.layouter = Creator.layouter(this, config));
7544
7633
  if (this.isApp)
7545
7634
  this.__setApp();
7546
- this.__checkAutoLayout(config);
7635
+ this.__checkAutoLayout(config, parentApp);
7547
7636
  this.view = canvas.view;
7548
7637
  if (parentApp) {
7549
7638
  this.__bindApp(parentApp);
@@ -7644,9 +7733,10 @@ var LeaferUI = (function (exports) {
7644
7733
  this.leafer = leafer;
7645
7734
  this.__level = 1;
7646
7735
  }
7647
- __checkAutoLayout(config) {
7648
- if (!config.width || !config.height) {
7649
- this.autoLayout = new AutoBounds(config);
7736
+ __checkAutoLayout(config, parentApp) {
7737
+ if (!parentApp) {
7738
+ if (!config.width || !config.height)
7739
+ this.autoLayout = new AutoBounds(config);
7650
7740
  this.canvas.startAutoLayout(this.autoLayout, this.__onResize.bind(this));
7651
7741
  }
7652
7742
  }
@@ -7781,12 +7871,21 @@ var LeaferUI = (function (exports) {
7781
7871
  list.push(item);
7782
7872
  }
7783
7873
  }
7784
- zoom(_zoomType, _padding, _fixedScale) { return undefined; }
7874
+ zoom(_zoomType, _padding, _fixedScale) {
7875
+ return debug$1.error('need @leafer-in/view');
7876
+ }
7785
7877
  getValidMove(moveX, moveY) { return { x: moveX, y: moveY }; }
7786
7878
  getValidScale(changeScale) { return changeScale; }
7787
7879
  getWorldPointByClient(clientPoint, updateClient) {
7788
7880
  return this.interaction && this.interaction.getLocal(clientPoint, updateClient);
7789
7881
  }
7882
+ getPagePointByClient(clientPoint, updateClient) {
7883
+ return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient));
7884
+ }
7885
+ updateClientBounds() {
7886
+ this.canvas && this.canvas.updateClientBounds();
7887
+ }
7888
+ receiveEvent(_event) { }
7790
7889
  __checkUpdateLayout() {
7791
7890
  this.__layout.update();
7792
7891
  }
@@ -7870,7 +7969,7 @@ var LeaferUI = (function (exports) {
7870
7969
  const rect = exports.Rect.prototype;
7871
7970
  const group = exports.Group.prototype;
7872
7971
  const childrenRenderBounds = {};
7873
- const { copy: copy$2, add, includes: includes$1 } = BoundsHelper;
7972
+ const { copy: copy$2, add, includes: includes$1, copyAndSpread: copyAndSpread$1 } = BoundsHelper;
7874
7973
  exports.Box = class Box extends exports.Group {
7875
7974
  get __tag() { return 'Box'; }
7876
7975
  get isBranchLeaf() { return true; }
@@ -7884,20 +7983,23 @@ var LeaferUI = (function (exports) {
7884
7983
  return this.__updateRectRenderSpread() || -1;
7885
7984
  }
7886
7985
  __updateRectBoxBounds() { }
7887
- __updateBoxBounds() {
7986
+ __updateBoxBounds(secondLayout) {
7888
7987
  const data = this.__;
7889
7988
  if (this.children.length) {
7890
7989
  if (data.__autoSide) {
7891
7990
  if (this.leafer && this.leafer.ready)
7892
7991
  this.leafer.layouter.addExtra(this);
7893
7992
  super.__updateBoxBounds();
7993
+ const { boxBounds } = this.__layout;
7894
7994
  if (!data.__autoSize) {
7895
- const b = this.__layout.boxBounds;
7896
- if (!data.__autoWidth)
7897
- b.height += b.y, b.width = data.width, b.x = b.y = 0;
7898
- if (!data.__autoHeight)
7899
- b.width += b.x, b.height = data.height, b.y = b.x = 0;
7995
+ if (data.__autoWidth)
7996
+ boxBounds.width += boxBounds.x, boxBounds.height = data.height, boxBounds.y = boxBounds.x = 0;
7997
+ else
7998
+ boxBounds.height += boxBounds.y, boxBounds.width = data.width, boxBounds.x = boxBounds.y = 0;
7900
7999
  }
8000
+ if (secondLayout && data.flow && data.padding)
8001
+ copyAndSpread$1(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'));
8002
+ this.__updateNaturalSize();
7901
8003
  }
7902
8004
  else {
7903
8005
  this.__updateRectBoxBounds();
@@ -7917,13 +8019,13 @@ var LeaferUI = (function (exports) {
7917
8019
  super.__updateRenderBounds();
7918
8020
  copy$2(childrenRenderBounds, renderBounds);
7919
8021
  this.__updateRectRenderBounds();
7920
- isOverflow = !includes$1(renderBounds, childrenRenderBounds) || undefined;
8022
+ isOverflow = !includes$1(renderBounds, childrenRenderBounds) || !this.pathInputed || !this.__.cornerRadius;
7921
8023
  }
7922
8024
  else {
7923
8025
  this.__updateRectRenderBounds();
7924
8026
  }
7925
8027
  this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
7926
- if (isOverflow && !(this.__.__drawAfterFill = this.__.overflow === 'hide'))
8028
+ if (!(this.__.__drawAfterFill = this.__.overflow === 'hide') && isOverflow)
7927
8029
  add(renderBounds, childrenRenderBounds);
7928
8030
  }
7929
8031
  __updateRectRenderBounds() { }
@@ -8257,14 +8359,26 @@ var LeaferUI = (function (exports) {
8257
8359
  exports.Image = __decorate([
8258
8360
  registerUI()
8259
8361
  ], exports.Image);
8362
+ const MyImage = exports.Image;
8260
8363
 
8261
8364
  exports.Canvas = class Canvas extends exports.Rect {
8262
8365
  get __tag() { return 'Canvas'; }
8366
+ get ready() { return !this.url; }
8263
8367
  constructor(data) {
8264
8368
  super(data);
8265
8369
  this.canvas = Creator.canvas(this.__);
8266
8370
  this.context = this.canvas.context;
8267
8371
  this.__.__isCanvas = this.__.__drawAfterFill = true;
8372
+ if (data && data.url)
8373
+ this.drawImage(data.url);
8374
+ }
8375
+ drawImage(url) {
8376
+ new LeaferImage({ url }).load((image) => {
8377
+ this.context.drawImage(image.view, 0, 0);
8378
+ this.url = undefined;
8379
+ this.paint();
8380
+ this.emitEvent(new ImageEvent(ImageEvent.LOADED, { image }));
8381
+ });
8268
8382
  }
8269
8383
  draw(ui, offset, scale, rotation) {
8270
8384
  ui.__layout.update();
@@ -8308,8 +8422,7 @@ var LeaferUI = (function (exports) {
8308
8422
  destroy() {
8309
8423
  if (this.canvas) {
8310
8424
  this.canvas.destroy();
8311
- this.canvas = null;
8312
- this.context = null;
8425
+ this.canvas = this.context = null;
8313
8426
  }
8314
8427
  super.destroy();
8315
8428
  }
@@ -8324,7 +8437,7 @@ var LeaferUI = (function (exports) {
8324
8437
  resizeType(100)
8325
8438
  ], exports.Canvas.prototype, "height", void 0);
8326
8439
  __decorate([
8327
- resizeType(Platform.devicePixelRatio)
8440
+ resizeType(1)
8328
8441
  ], exports.Canvas.prototype, "pixelRatio", void 0);
8329
8442
  __decorate([
8330
8443
  resizeType(true)
@@ -8348,13 +8461,13 @@ var LeaferUI = (function (exports) {
8348
8461
  super(data);
8349
8462
  }
8350
8463
  __drawHitPath(canvas) {
8351
- const { __lineHeight, __baseLine, __textDrawData: data } = this.__;
8464
+ const { __lineHeight, fontSize, __baseLine, __textDrawData: data } = this.__;
8352
8465
  canvas.beginPath();
8353
8466
  if (this.__.__letterSpacing < 0) {
8354
8467
  this.__drawPathByData(canvas);
8355
8468
  }
8356
8469
  else {
8357
- data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight));
8470
+ data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight));
8358
8471
  }
8359
8472
  }
8360
8473
  __drawPathByData(drawer, _data) {
@@ -8547,7 +8660,8 @@ var LeaferUI = (function (exports) {
8547
8660
  drawPoints(_points, _curve, _close) { return this; }
8548
8661
  clearPath() { return this; }
8549
8662
  paint() {
8550
- this.pathElement.forceUpdate('path');
8663
+ if (!this.pathElement.__layout.boxChanged)
8664
+ this.pathElement.forceUpdate('path');
8551
8665
  }
8552
8666
  };
8553
8667
  __decorate([
@@ -8557,7 +8671,7 @@ var LeaferUI = (function (exports) {
8557
8671
  penPathType()
8558
8672
  ], exports.Pen.prototype, "path", void 0);
8559
8673
  exports.Pen = __decorate([
8560
- useModule(PathCreator, ['set', 'beginPath', 'path']),
8674
+ useModule(PathCreator, ['set', 'beginPath', 'path', 'paint']),
8561
8675
  registerUI()
8562
8676
  ], exports.Pen);
8563
8677
  function penPathType() {
@@ -8919,10 +9033,13 @@ var LeaferUI = (function (exports) {
8919
9033
  const { get: get$2, translate } = MatrixHelper;
8920
9034
  const tempBox = new Bounds();
8921
9035
  const tempPoint = {};
9036
+ const tempScaleData = {};
8922
9037
  function createData(leafPaint, image, paint, box) {
8923
- const { blendMode } = paint;
9038
+ const { blendMode, sync } = paint;
8924
9039
  if (blendMode)
8925
9040
  leafPaint.blendMode = blendMode;
9041
+ if (sync)
9042
+ leafPaint.sync = sync;
8926
9043
  leafPaint.data = getPatternData(paint, box, image);
8927
9044
  }
8928
9045
  function getPatternData(paint, box, image) {
@@ -8942,13 +9059,10 @@ var LeaferUI = (function (exports) {
8942
9059
  x += (box.width - width * scaleX) / 2, y += (box.height - height * scaleY) / 2;
8943
9060
  }
8944
9061
  }
8945
- else if (size) {
8946
- scaleX = (typeof size === 'number' ? size : size.width) / width;
8947
- scaleY = (typeof size === 'number' ? size : size.height) / height;
8948
- }
8949
- else if (scale) {
8950
- scaleX = typeof scale === 'number' ? scale : scale.x;
8951
- scaleY = typeof scale === 'number' ? scale : scale.y;
9062
+ else if (scale || size) {
9063
+ MathHelper.getScaleData(scale, size, image, tempScaleData);
9064
+ scaleX = tempScaleData.scaleX;
9065
+ scaleY = tempScaleData.scaleY;
8952
9066
  }
8953
9067
  if (align) {
8954
9068
  const imageBounds = { x, y, width: swapWidth, height: swapHeight };
@@ -9153,7 +9267,7 @@ var LeaferUI = (function (exports) {
9153
9267
  const { abs } = Math;
9154
9268
  function checkImage(ui, canvas, paint, allowPaint) {
9155
9269
  const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
9156
- if (!paint.data || paint.patternId === scaleX + '-' + scaleY) {
9270
+ if (!paint.data || (paint.patternId === scaleX + '-' + scaleY && !Export.running)) {
9157
9271
  return false;
9158
9272
  }
9159
9273
  else {
@@ -9187,7 +9301,7 @@ var LeaferUI = (function (exports) {
9187
9301
  return true;
9188
9302
  }
9189
9303
  else {
9190
- if (!paint.style || Export.running) {
9304
+ if (!paint.style || paint.sync || Export.running) {
9191
9305
  createPattern(ui, paint, canvas.pixelRatio);
9192
9306
  }
9193
9307
  else {
@@ -10057,6 +10171,7 @@ var LeaferUI = (function (exports) {
10057
10171
  export(leaf, filename, options) {
10058
10172
  this.running = true;
10059
10173
  const fileType = FileHelper.fileType(filename);
10174
+ const isDownload = filename.includes('.');
10060
10175
  options = FileHelper.getExportOptions(options);
10061
10176
  return addTask((success) => new Promise((resolve) => {
10062
10177
  const over = (result) => {
@@ -10066,19 +10181,13 @@ var LeaferUI = (function (exports) {
10066
10181
  };
10067
10182
  const { toURL } = Platform;
10068
10183
  const { download } = Platform.origin;
10069
- if (filename === 'json') {
10070
- return over({ data: leaf.toJSON(options.json) });
10071
- }
10072
- else if (fileType === 'json') {
10073
- download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
10074
- return over({ data: true });
10075
- }
10076
- if (filename === 'svg') {
10077
- return over({ data: leaf.toSVG() });
10184
+ if (fileType === 'json') {
10185
+ isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
10186
+ return over({ data: isDownload ? true : leaf.toJSON(options.json) });
10078
10187
  }
10079
- else if (fileType === 'svg') {
10080
- download(toURL(leaf.toSVG(), 'svg'), filename);
10081
- return over({ data: true });
10188
+ if (fileType === 'svg') {
10189
+ isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
10190
+ return over({ data: isDownload ? true : leaf.toSVG() });
10082
10191
  }
10083
10192
  const { leafer } = leaf;
10084
10193
  if (leafer) {
@@ -10087,14 +10196,8 @@ var LeaferUI = (function (exports) {
10087
10196
  let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
10088
10197
  const { worldTransform, isLeafer, isFrame } = leaf;
10089
10198
  const { slice, trim, onCanvas } = options;
10090
- let scale = options.scale || 1;
10091
- let pixelRatio = options.pixelRatio || 1;
10092
10199
  const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
10093
10200
  const contextSettings = options.contextSettings || leafer.config.contextSettings;
10094
- if (leaf.isApp) {
10095
- scale *= pixelRatio;
10096
- pixelRatio = leaf.app.pixelRatio;
10097
- }
10098
10201
  const screenshot = options.screenshot || leaf.isApp;
10099
10202
  const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
10100
10203
  const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
@@ -10128,10 +10231,21 @@ var LeaferUI = (function (exports) {
10128
10231
  }
10129
10232
  renderBounds = leaf.getBounds('render', relative);
10130
10233
  }
10131
- const { x, y, width, height } = new Bounds(renderBounds).scale(scale);
10234
+ const scaleData = { scaleX: 1, scaleY: 1 };
10235
+ MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
10236
+ let pixelRatio = options.pixelRatio || 1;
10237
+ if (leaf.isApp) {
10238
+ scaleData.scaleX *= pixelRatio;
10239
+ scaleData.scaleY *= pixelRatio;
10240
+ pixelRatio = leaf.app.pixelRatio;
10241
+ }
10242
+ const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
10243
+ const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
10132
10244
  let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
10133
- const renderOptions = { matrix: matrix.scale(1 / scale).invert().translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) };
10245
+ let sliceLeaf;
10134
10246
  if (slice) {
10247
+ sliceLeaf = leaf;
10248
+ sliceLeaf.__worldOpacity = 0;
10135
10249
  leaf = leafer;
10136
10250
  renderOptions.bounds = canvas.bounds;
10137
10251
  }
@@ -10146,6 +10260,8 @@ var LeaferUI = (function (exports) {
10146
10260
  leaf.__render(canvas, renderOptions);
10147
10261
  }
10148
10262
  canvas.restore();
10263
+ if (sliceLeaf)
10264
+ sliceLeaf.__updateWorldOpacity();
10149
10265
  if (trim) {
10150
10266
  trimBounds = getTrimBounds(canvas);
10151
10267
  const old = canvas, { width, height } = trimBounds;
@@ -10282,6 +10398,7 @@ var LeaferUI = (function (exports) {
10282
10398
  exports.MathHelper = MathHelper;
10283
10399
  exports.Matrix = Matrix;
10284
10400
  exports.MatrixHelper = MatrixHelper;
10401
+ exports.MyImage = MyImage;
10285
10402
  exports.NeedConvertToCanvasCommandMap = NeedConvertToCanvasCommandMap;
10286
10403
  exports.OneRadian = OneRadian;
10287
10404
  exports.PI2 = PI2;