@leafer-draw/worker 1.0.1 → 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.
@@ -111,6 +111,19 @@ const MathHelper = {
111
111
  const a = maxLength ? pow$1(10, maxLength) : 1000000000000;
112
112
  num = round(num * a) / a;
113
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;
114
127
  }
115
128
  };
116
129
  const OneRadian = PI$4 / 180;
@@ -409,7 +422,7 @@ const MatrixHelper = {
409
422
  };
410
423
  const M$6 = MatrixHelper;
411
424
 
412
- const { toInnerPoint: toInnerPoint$2, toOuterPoint: toOuterPoint$2 } = MatrixHelper;
425
+ const { toInnerPoint: toInnerPoint$2, toOuterPoint: toOuterPoint$3 } = MatrixHelper;
413
426
  const { sin: sin$4, cos: cos$4, abs: abs$4, sqrt: sqrt$2, atan2: atan2$2, min: min$1, PI: PI$3 } = Math;
414
427
  const PointHelper = {
415
428
  defaultPoint: getPointData(),
@@ -465,7 +478,7 @@ const PointHelper = {
465
478
  tempToOuterOf(t, matrix) {
466
479
  const { tempPoint: temp } = P$5;
467
480
  copy$a(temp, t);
468
- toOuterPoint$2(matrix, temp, temp);
481
+ toOuterPoint$3(matrix, temp, temp);
469
482
  return temp;
470
483
  },
471
484
  tempToInnerRadiusPointOf(t, matrix) {
@@ -484,7 +497,7 @@ const PointHelper = {
484
497
  toInnerPoint$2(matrix, t, to);
485
498
  },
486
499
  toOuterOf(t, matrix, to) {
487
- toOuterPoint$2(matrix, t, to);
500
+ toOuterPoint$3(matrix, t, to);
488
501
  },
489
502
  getCenter(t, to) {
490
503
  return { x: t.x + (to.x - t.x) / 2, y: t.y + (to.y - t.y) / 2 };
@@ -764,7 +777,7 @@ const TwoPointBoundsHelper = {
764
777
  const { addPoint: addPoint$4 } = TwoPointBoundsHelper;
765
778
 
766
779
  const { tempPointBounds: tempPointBounds$1, setPoint: setPoint$3, addPoint: addPoint$3, toBounds: toBounds$4 } = TwoPointBoundsHelper;
767
- const { toOuterPoint: toOuterPoint$1 } = MatrixHelper;
780
+ const { toOuterPoint: toOuterPoint$2 } = MatrixHelper;
768
781
  const { float, fourNumber } = MathHelper;
769
782
  const { floor, ceil: ceil$2 } = Math;
770
783
  let right$1, bottom$1, boundsRight, boundsBottom;
@@ -784,17 +797,24 @@ const BoundsHelper = {
784
797
  t.width = bounds.width;
785
798
  t.height = bounds.height;
786
799
  },
787
- copyAndSpread(t, bounds, spread, isShrink) {
800
+ copyAndSpread(t, bounds, spread, isShrink, side) {
801
+ const { x, y, width, height } = bounds;
788
802
  if (spread instanceof Array) {
789
803
  const four = fourNumber(spread);
790
804
  isShrink
791
- ? B.set(t, bounds.x + four[3], bounds.y + four[0], bounds.width - four[1] - four[3], bounds.height - four[2] - four[0])
792
- : 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]);
793
807
  }
794
808
  else {
795
809
  if (isShrink)
796
810
  spread = -spread;
797
- 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;
798
818
  }
799
819
  },
800
820
  minX(t) { return t.width > 0 ? t.x : t.x + t.width; },
@@ -871,16 +891,16 @@ const BoundsHelper = {
871
891
  else {
872
892
  point.x = t.x;
873
893
  point.y = t.y;
874
- toOuterPoint$1(matrix, point, toPoint$5);
894
+ toOuterPoint$2(matrix, point, toPoint$5);
875
895
  setPoint$3(tempPointBounds$1, toPoint$5.x, toPoint$5.y);
876
896
  point.x = t.x + t.width;
877
- toOuterPoint$1(matrix, point, toPoint$5);
897
+ toOuterPoint$2(matrix, point, toPoint$5);
878
898
  addPoint$3(tempPointBounds$1, toPoint$5.x, toPoint$5.y);
879
899
  point.y = t.y + t.height;
880
- toOuterPoint$1(matrix, point, toPoint$5);
900
+ toOuterPoint$2(matrix, point, toPoint$5);
881
901
  addPoint$3(tempPointBounds$1, toPoint$5.x, toPoint$5.y);
882
902
  point.x = t.x;
883
- toOuterPoint$1(matrix, point, toPoint$5);
903
+ toOuterPoint$2(matrix, point, toPoint$5);
884
904
  addPoint$3(tempPointBounds$1, toPoint$5.x, toPoint$5.y);
885
905
  toBounds$4(tempPointBounds$1, to);
886
906
  }
@@ -894,16 +914,16 @@ const BoundsHelper = {
894
914
  const scale = Math.min(baseScale, Math.min(t.width / put.width, t.height / put.height));
895
915
  return new Matrix(scale, 0, 0, scale, -put.x * scale, -put.y * scale);
896
916
  },
897
- getSpread(t, spread) {
917
+ getSpread(t, spread, side) {
898
918
  const n = {};
899
- B.copyAndSpread(n, t, spread);
919
+ B.copyAndSpread(n, t, spread, false, side);
900
920
  return n;
901
921
  },
902
- spread(t, spread) {
903
- B.copyAndSpread(t, t, spread);
922
+ spread(t, spread, side) {
923
+ B.copyAndSpread(t, t, spread, false, side);
904
924
  },
905
- shrink(t, shrink) {
906
- B.copyAndSpread(t, t, shrink, true);
925
+ shrink(t, shrink, side) {
926
+ B.copyAndSpread(t, t, shrink, true, side);
907
927
  },
908
928
  ceil(t) {
909
929
  const { x, y } = t;
@@ -1086,12 +1106,12 @@ class Bounds {
1086
1106
  getFitMatrix(put, baseScale) {
1087
1107
  return BoundsHelper.getFitMatrix(this, put, baseScale);
1088
1108
  }
1089
- spread(fourNumber) {
1090
- BoundsHelper.spread(this, fourNumber);
1109
+ spread(fourNumber, side) {
1110
+ BoundsHelper.spread(this, fourNumber, side);
1091
1111
  return this;
1092
1112
  }
1093
- shrink(fourNumber) {
1094
- BoundsHelper.shrink(this, fourNumber);
1113
+ shrink(fourNumber, side) {
1114
+ BoundsHelper.shrink(this, fourNumber, side);
1095
1115
  return this;
1096
1116
  }
1097
1117
  ceil() {
@@ -2908,60 +2928,75 @@ class PathCreator {
2908
2928
  }
2909
2929
  beginPath() {
2910
2930
  beginPath(this.__path);
2931
+ this.paint();
2911
2932
  return this;
2912
2933
  }
2913
2934
  moveTo(x, y) {
2914
2935
  moveTo$4(this.__path, x, y);
2936
+ this.paint();
2915
2937
  return this;
2916
2938
  }
2917
2939
  lineTo(x, y) {
2918
2940
  lineTo$3(this.__path, x, y);
2941
+ this.paint();
2919
2942
  return this;
2920
2943
  }
2921
2944
  bezierCurveTo(x1, y1, x2, y2, x, y) {
2922
2945
  bezierCurveTo(this.__path, x1, y1, x2, y2, x, y);
2946
+ this.paint();
2923
2947
  return this;
2924
2948
  }
2925
2949
  quadraticCurveTo(x1, y1, x, y) {
2926
2950
  quadraticCurveTo(this.__path, x1, y1, x, y);
2951
+ this.paint();
2927
2952
  return this;
2928
2953
  }
2929
2954
  closePath() {
2930
2955
  closePath$3(this.__path);
2956
+ this.paint();
2931
2957
  return this;
2932
2958
  }
2933
2959
  rect(x, y, width, height) {
2934
2960
  rect$1(this.__path, x, y, width, height);
2961
+ this.paint();
2935
2962
  return this;
2936
2963
  }
2937
2964
  roundRect(x, y, width, height, cornerRadius) {
2938
2965
  roundRect$1(this.__path, x, y, width, height, cornerRadius);
2966
+ this.paint();
2939
2967
  return this;
2940
2968
  }
2941
2969
  ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise) {
2942
2970
  ellipse$2(this.__path, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise);
2971
+ this.paint();
2943
2972
  return this;
2944
2973
  }
2945
2974
  arc(x, y, radius, startAngle, endAngle, anticlockwise) {
2946
2975
  arc$1(this.__path, x, y, radius, startAngle, endAngle, anticlockwise);
2976
+ this.paint();
2947
2977
  return this;
2948
2978
  }
2949
2979
  arcTo(x1, y1, x2, y2, radius) {
2950
2980
  arcTo$2(this.__path, x1, y1, x2, y2, radius);
2981
+ this.paint();
2951
2982
  return this;
2952
2983
  }
2953
2984
  drawEllipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise) {
2954
2985
  drawEllipse(this.__path, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise);
2986
+ this.paint();
2955
2987
  return this;
2956
2988
  }
2957
2989
  drawArc(x, y, radius, startAngle, endAngle, anticlockwise) {
2958
2990
  drawArc(this.__path, x, y, radius, startAngle, endAngle, anticlockwise);
2991
+ this.paint();
2959
2992
  return this;
2960
2993
  }
2961
2994
  drawPoints(points, curve, close) {
2962
2995
  drawPoints$2(this.__path, points, curve, close);
2996
+ this.paint();
2963
2997
  return this;
2964
2998
  }
2999
+ paint() { }
2965
3000
  }
2966
3001
 
2967
3002
  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;
@@ -3983,7 +4018,7 @@ function registerUIEvent() {
3983
4018
  };
3984
4019
  }
3985
4020
 
3986
- const { copy: copy$6, toInnerPoint: toInnerPoint$1, scaleOfOuter: scaleOfOuter$2, rotateOfOuter: rotateOfOuter$2, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
4021
+ const { copy: copy$6, toInnerPoint: toInnerPoint$1, toOuterPoint: toOuterPoint$1, scaleOfOuter: scaleOfOuter$2, rotateOfOuter: rotateOfOuter$2, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
3987
4022
  const matrix = {};
3988
4023
  const LeafHelper = {
3989
4024
  updateAllMatrix(leaf, checkAutoLayout, waitAutoLayout) {
@@ -4048,10 +4083,9 @@ const LeafHelper = {
4048
4083
  }
4049
4084
  return true;
4050
4085
  },
4051
- moveWorld(t, x, y = 0) {
4086
+ moveWorld(t, x, y = 0, isInnerPoint) {
4052
4087
  const local = typeof x === 'object' ? Object.assign({}, x) : { x, y };
4053
- if (t.parent)
4054
- 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));
4055
4089
  L.moveLocal(t, local.x, local.y);
4056
4090
  },
4057
4091
  moveLocal(t, x, y = 0) {
@@ -4918,7 +4952,7 @@ const LeafMatrix = {
4918
4952
 
4919
4953
  const { updateMatrix: updateMatrix$1, updateAllMatrix: updateAllMatrix$2 } = LeafHelper;
4920
4954
  const { updateBounds: updateBounds$1 } = BranchHelper;
4921
- const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$1, copy: copy$4 } = BoundsHelper;
4955
+ const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$2, copy: copy$4 } = BoundsHelper;
4922
4956
  const { toBounds: toBounds$2 } = PathBounds;
4923
4957
  const LeafBounds = {
4924
4958
  __updateWorldBounds() {
@@ -5019,7 +5053,7 @@ const LeafBounds = {
5019
5053
  updateAllMatrix$2(this);
5020
5054
  updateBounds$1(this, this);
5021
5055
  if (this.__.__autoSide)
5022
- this.__updateBoxBounds();
5056
+ this.__updateBoxBounds(true);
5023
5057
  }
5024
5058
  else {
5025
5059
  updateAllMatrix$2(this);
@@ -5037,11 +5071,11 @@ const LeafBounds = {
5037
5071
  },
5038
5072
  __updateStrokeBounds() {
5039
5073
  const layout = this.__layout;
5040
- copyAndSpread$1(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
5074
+ copyAndSpread$2(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
5041
5075
  },
5042
5076
  __updateRenderBounds() {
5043
5077
  const layout = this.__layout;
5044
- layout.renderSpread > 0 ? copyAndSpread$1(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$4(layout.renderBounds, layout.strokeBounds);
5078
+ layout.renderSpread > 0 ? copyAndSpread$2(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$4(layout.renderBounds, layout.strokeBounds);
5045
5079
  }
5046
5080
  };
5047
5081
 
@@ -5401,6 +5435,9 @@ let Leaf = class Leaf {
5401
5435
  move(x, y) {
5402
5436
  moveLocal(this, x, y);
5403
5437
  }
5438
+ moveInner(x, y) {
5439
+ moveWorld(this, x, y, true);
5440
+ }
5404
5441
  scaleOf(origin, scaleX, scaleY, resize) {
5405
5442
  zoomOfLocal(this, getLocalOrigin(this, origin), scaleX, scaleY, resize);
5406
5443
  }
@@ -6667,6 +6704,11 @@ class BoxData extends GroupData {
6667
6704
  }
6668
6705
 
6669
6706
  class LeaferData extends GroupData {
6707
+ __getInputData() {
6708
+ const data = super.__getInputData();
6709
+ canvasSizeAttrs.forEach(key => delete data[key]);
6710
+ return data;
6711
+ }
6670
6712
  }
6671
6713
 
6672
6714
  class FrameData extends BoxData {
@@ -6744,6 +6786,11 @@ class ImageData extends RectData {
6744
6786
  }
6745
6787
 
6746
6788
  class CanvasData extends RectData {
6789
+ __getInputData() {
6790
+ const data = super.__getInputData();
6791
+ data.url = this.__leaf.canvas.toDataURL('image/png');
6792
+ return data;
6793
+ }
6747
6794
  }
6748
6795
 
6749
6796
  const UIBounds = {
@@ -7656,6 +7703,13 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7656
7703
  getWorldPointByClient(clientPoint, updateClient) {
7657
7704
  return this.interaction && this.interaction.getLocal(clientPoint, updateClient);
7658
7705
  }
7706
+ getPagePointByClient(clientPoint, updateClient) {
7707
+ return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient));
7708
+ }
7709
+ updateClientBounds() {
7710
+ this.canvas && this.canvas.updateClientBounds();
7711
+ }
7712
+ receiveEvent(_event) { }
7659
7713
  __checkUpdateLayout() {
7660
7714
  this.__layout.update();
7661
7715
  }
@@ -7739,7 +7793,7 @@ Rect = __decorate([
7739
7793
  const rect = Rect.prototype;
7740
7794
  const group = Group.prototype;
7741
7795
  const childrenRenderBounds = {};
7742
- const { copy: copy$2, add, includes: includes$1 } = BoundsHelper;
7796
+ const { copy: copy$2, add, includes: includes$1, copyAndSpread: copyAndSpread$1 } = BoundsHelper;
7743
7797
  let Box = class Box extends Group {
7744
7798
  get __tag() { return 'Box'; }
7745
7799
  get isBranchLeaf() { return true; }
@@ -7753,20 +7807,23 @@ let Box = class Box extends Group {
7753
7807
  return this.__updateRectRenderSpread() || -1;
7754
7808
  }
7755
7809
  __updateRectBoxBounds() { }
7756
- __updateBoxBounds() {
7810
+ __updateBoxBounds(secondLayout) {
7757
7811
  const data = this.__;
7758
7812
  if (this.children.length) {
7759
7813
  if (data.__autoSide) {
7760
7814
  if (this.leafer && this.leafer.ready)
7761
7815
  this.leafer.layouter.addExtra(this);
7762
7816
  super.__updateBoxBounds();
7817
+ const { boxBounds } = this.__layout;
7763
7818
  if (!data.__autoSize) {
7764
- const b = this.__layout.boxBounds;
7765
- if (!data.__autoWidth)
7766
- b.height += b.y, b.width = data.width, b.x = b.y = 0;
7767
- if (!data.__autoHeight)
7768
- b.width += b.x, b.height = data.height, b.y = b.x = 0;
7819
+ if (data.__autoWidth)
7820
+ boxBounds.width += boxBounds.x, boxBounds.height = data.height, boxBounds.y = boxBounds.x = 0;
7821
+ else
7822
+ boxBounds.height += boxBounds.y, boxBounds.width = data.width, boxBounds.x = boxBounds.y = 0;
7769
7823
  }
7824
+ if (secondLayout && data.flow && data.padding)
7825
+ copyAndSpread$1(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'));
7826
+ this.__updateNaturalSize();
7770
7827
  }
7771
7828
  else {
7772
7829
  this.__updateRectBoxBounds();
@@ -7786,13 +7843,13 @@ let Box = class Box extends Group {
7786
7843
  super.__updateRenderBounds();
7787
7844
  copy$2(childrenRenderBounds, renderBounds);
7788
7845
  this.__updateRectRenderBounds();
7789
- isOverflow = !includes$1(renderBounds, childrenRenderBounds) || undefined;
7846
+ isOverflow = !includes$1(renderBounds, childrenRenderBounds) || !this.pathInputed || !this.__.cornerRadius;
7790
7847
  }
7791
7848
  else {
7792
7849
  this.__updateRectRenderBounds();
7793
7850
  }
7794
7851
  this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
7795
- if (isOverflow && !(this.__.__drawAfterFill = this.__.overflow === 'hide'))
7852
+ if (!(this.__.__drawAfterFill = this.__.overflow === 'hide') && isOverflow)
7796
7853
  add(renderBounds, childrenRenderBounds);
7797
7854
  }
7798
7855
  __updateRectRenderBounds() { }
@@ -8126,14 +8183,26 @@ __decorate([
8126
8183
  Image = __decorate([
8127
8184
  registerUI()
8128
8185
  ], Image);
8186
+ const MyImage = Image;
8129
8187
 
8130
8188
  let Canvas = class Canvas extends Rect {
8131
8189
  get __tag() { return 'Canvas'; }
8190
+ get ready() { return !this.url; }
8132
8191
  constructor(data) {
8133
8192
  super(data);
8134
8193
  this.canvas = Creator.canvas(this.__);
8135
8194
  this.context = this.canvas.context;
8136
8195
  this.__.__isCanvas = this.__.__drawAfterFill = true;
8196
+ if (data && data.url)
8197
+ this.drawImage(data.url);
8198
+ }
8199
+ drawImage(url) {
8200
+ new LeaferImage({ url }).load((image) => {
8201
+ this.context.drawImage(image.view, 0, 0);
8202
+ this.url = undefined;
8203
+ this.paint();
8204
+ this.emitEvent(new ImageEvent(ImageEvent.LOADED, { image }));
8205
+ });
8137
8206
  }
8138
8207
  draw(ui, offset, scale, rotation) {
8139
8208
  ui.__layout.update();
@@ -8192,7 +8261,7 @@ __decorate([
8192
8261
  resizeType(100)
8193
8262
  ], Canvas.prototype, "height", void 0);
8194
8263
  __decorate([
8195
- resizeType(Platform.devicePixelRatio)
8264
+ resizeType(1)
8196
8265
  ], Canvas.prototype, "pixelRatio", void 0);
8197
8266
  __decorate([
8198
8267
  resizeType(true)
@@ -8216,13 +8285,13 @@ let Text = class Text extends UI {
8216
8285
  super(data);
8217
8286
  }
8218
8287
  __drawHitPath(canvas) {
8219
- const { __lineHeight, __baseLine, __textDrawData: data } = this.__;
8288
+ const { __lineHeight, fontSize, __baseLine, __textDrawData: data } = this.__;
8220
8289
  canvas.beginPath();
8221
8290
  if (this.__.__letterSpacing < 0) {
8222
8291
  this.__drawPathByData(canvas);
8223
8292
  }
8224
8293
  else {
8225
- data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight));
8294
+ data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight));
8226
8295
  }
8227
8296
  }
8228
8297
  __drawPathByData(drawer, _data) {
@@ -8415,7 +8484,8 @@ let Pen = class Pen extends Group {
8415
8484
  drawPoints(_points, _curve, _close) { return this; }
8416
8485
  clearPath() { return this; }
8417
8486
  paint() {
8418
- this.pathElement.forceUpdate('path');
8487
+ if (!this.pathElement.__layout.boxChanged)
8488
+ this.pathElement.forceUpdate('path');
8419
8489
  }
8420
8490
  };
8421
8491
  __decorate([
@@ -8425,7 +8495,7 @@ __decorate([
8425
8495
  penPathType()
8426
8496
  ], Pen.prototype, "path", void 0);
8427
8497
  Pen = __decorate([
8428
- useModule(PathCreator, ['set', 'beginPath', 'path']),
8498
+ useModule(PathCreator, ['set', 'beginPath', 'path', 'paint']),
8429
8499
  registerUI()
8430
8500
  ], Pen);
8431
8501
  function penPathType() {
@@ -8787,10 +8857,13 @@ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, al
8787
8857
  const { get: get$2, translate } = MatrixHelper;
8788
8858
  const tempBox = new Bounds();
8789
8859
  const tempPoint = {};
8860
+ const tempScaleData = {};
8790
8861
  function createData(leafPaint, image, paint, box) {
8791
- const { blendMode } = paint;
8862
+ const { blendMode, sync } = paint;
8792
8863
  if (blendMode)
8793
8864
  leafPaint.blendMode = blendMode;
8865
+ if (sync)
8866
+ leafPaint.sync = sync;
8794
8867
  leafPaint.data = getPatternData(paint, box, image);
8795
8868
  }
8796
8869
  function getPatternData(paint, box, image) {
@@ -8810,13 +8883,10 @@ function getPatternData(paint, box, image) {
8810
8883
  x += (box.width - width * scaleX) / 2, y += (box.height - height * scaleY) / 2;
8811
8884
  }
8812
8885
  }
8813
- else if (size) {
8814
- scaleX = (typeof size === 'number' ? size : size.width) / width;
8815
- scaleY = (typeof size === 'number' ? size : size.height) / height;
8816
- }
8817
- else if (scale) {
8818
- scaleX = typeof scale === 'number' ? scale : scale.x;
8819
- scaleY = typeof scale === 'number' ? scale : scale.y;
8886
+ else if (scale || size) {
8887
+ MathHelper.getScaleData(scale, size, image, tempScaleData);
8888
+ scaleX = tempScaleData.scaleX;
8889
+ scaleY = tempScaleData.scaleY;
8820
8890
  }
8821
8891
  if (align) {
8822
8892
  const imageBounds = { x, y, width: swapWidth, height: swapHeight };
@@ -9055,7 +9125,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
9055
9125
  return true;
9056
9126
  }
9057
9127
  else {
9058
- if (!paint.style || Export.running) {
9128
+ if (!paint.style || paint.sync || Export.running) {
9059
9129
  createPattern(ui, paint, canvas.pixelRatio);
9060
9130
  }
9061
9131
  else {
@@ -9925,6 +9995,7 @@ const ExportModule = {
9925
9995
  export(leaf, filename, options) {
9926
9996
  this.running = true;
9927
9997
  const fileType = FileHelper.fileType(filename);
9998
+ const isDownload = filename.includes('.');
9928
9999
  options = FileHelper.getExportOptions(options);
9929
10000
  return addTask((success) => new Promise((resolve) => {
9930
10001
  const over = (result) => {
@@ -9934,19 +10005,13 @@ const ExportModule = {
9934
10005
  };
9935
10006
  const { toURL } = Platform;
9936
10007
  const { download } = Platform.origin;
9937
- if (filename === 'json') {
9938
- return over({ data: leaf.toJSON(options.json) });
10008
+ if (fileType === 'json') {
10009
+ isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
10010
+ return over({ data: isDownload ? true : leaf.toJSON(options.json) });
9939
10011
  }
9940
- else if (fileType === 'json') {
9941
- download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
9942
- return over({ data: true });
9943
- }
9944
- if (filename === 'svg') {
9945
- return over({ data: leaf.toSVG() });
9946
- }
9947
- else if (fileType === 'svg') {
9948
- download(toURL(leaf.toSVG(), 'svg'), filename);
9949
- return over({ data: true });
10012
+ if (fileType === 'svg') {
10013
+ isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
10014
+ return over({ data: isDownload ? true : leaf.toSVG() });
9950
10015
  }
9951
10016
  const { leafer } = leaf;
9952
10017
  if (leafer) {
@@ -9955,14 +10020,8 @@ const ExportModule = {
9955
10020
  let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
9956
10021
  const { worldTransform, isLeafer, isFrame } = leaf;
9957
10022
  const { slice, trim, onCanvas } = options;
9958
- let scale = options.scale || 1;
9959
- let pixelRatio = options.pixelRatio || 1;
9960
10023
  const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
9961
10024
  const contextSettings = options.contextSettings || leafer.config.contextSettings;
9962
- if (leaf.isApp) {
9963
- scale *= pixelRatio;
9964
- pixelRatio = leaf.app.pixelRatio;
9965
- }
9966
10025
  const screenshot = options.screenshot || leaf.isApp;
9967
10026
  const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
9968
10027
  const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
@@ -9996,9 +10055,17 @@ const ExportModule = {
9996
10055
  }
9997
10056
  renderBounds = leaf.getBounds('render', relative);
9998
10057
  }
9999
- const { x, y, width, height } = new Bounds(renderBounds).scale(scale);
10058
+ const scaleData = { scaleX: 1, scaleY: 1 };
10059
+ MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
10060
+ let pixelRatio = options.pixelRatio || 1;
10061
+ if (leaf.isApp) {
10062
+ scaleData.scaleX *= pixelRatio;
10063
+ scaleData.scaleY *= pixelRatio;
10064
+ pixelRatio = leaf.app.pixelRatio;
10065
+ }
10066
+ const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
10067
+ const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
10000
10068
  let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
10001
- const renderOptions = { matrix: matrix.scale(1 / scale).invert().translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) };
10002
10069
  let sliceLeaf;
10003
10070
  if (slice) {
10004
10071
  sliceLeaf = leaf;
@@ -10103,4 +10170,4 @@ Object.assign(Export, ExportModule);
10103
10170
 
10104
10171
  useCanvas();
10105
10172
 
10106
- export { AlignHelper, AnimateEvent, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, DataHelper, Debug, Direction4, Direction9, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Export, FileHelper, Frame, FrameData, Group, GroupData, Image, ImageData, ImageEvent, ImageManager, IncrementId, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, Line, LineData, MathHelper, Matrix, MatrixHelper, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, PaintGradient, PaintImage, Path, PathArrow, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Pen, PenData, Platform, Point, PointHelper, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, Run, Star, StarData, State, StringNumberMap, TaskItem, TaskProcessor, Text, TextConvert, TextData, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, 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, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleType, sortType, stateType, strokeType, surfaceType, tempBounds$1 as tempBounds, tempMatrix, tempPoint$3 as tempPoint, useCanvas, useModule, version, visibleType, zoomLayerType };
10173
+ export { AlignHelper, AnimateEvent, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, DataHelper, Debug, Direction4, Direction9, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Export, FileHelper, Frame, FrameData, Group, GroupData, Image, ImageData, ImageEvent, ImageManager, IncrementId, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, Line, LineData, MathHelper, Matrix, MatrixHelper, MyImage, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, PaintGradient, PaintImage, Path, PathArrow, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Pen, PenData, Platform, Point, PointHelper, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, Run, Star, StarData, State, StringNumberMap, TaskItem, TaskProcessor, Text, TextConvert, TextData, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, 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, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleType, sortType, stateType, strokeType, surfaceType, tempBounds$1 as tempBounds, tempMatrix, tempPoint$3 as tempPoint, useCanvas, useModule, version, visibleType, zoomLayerType };