leafer-draw 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
  }
@@ -6840,6 +6877,11 @@ class BoxData extends GroupData {
6840
6877
  }
6841
6878
 
6842
6879
  class LeaferData extends GroupData {
6880
+ __getInputData() {
6881
+ const data = super.__getInputData();
6882
+ canvasSizeAttrs.forEach(key => delete data[key]);
6883
+ return data;
6884
+ }
6843
6885
  }
6844
6886
 
6845
6887
  class FrameData extends BoxData {
@@ -6917,6 +6959,11 @@ class ImageData extends RectData {
6917
6959
  }
6918
6960
 
6919
6961
  class CanvasData extends RectData {
6962
+ __getInputData() {
6963
+ const data = super.__getInputData();
6964
+ data.url = this.__leaf.canvas.toDataURL('image/png');
6965
+ return data;
6966
+ }
6920
6967
  }
6921
6968
 
6922
6969
  const UIBounds = {
@@ -7829,6 +7876,13 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7829
7876
  getWorldPointByClient(clientPoint, updateClient) {
7830
7877
  return this.interaction && this.interaction.getLocal(clientPoint, updateClient);
7831
7878
  }
7879
+ getPagePointByClient(clientPoint, updateClient) {
7880
+ return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient));
7881
+ }
7882
+ updateClientBounds() {
7883
+ this.canvas && this.canvas.updateClientBounds();
7884
+ }
7885
+ receiveEvent(_event) { }
7832
7886
  __checkUpdateLayout() {
7833
7887
  this.__layout.update();
7834
7888
  }
@@ -7912,7 +7966,7 @@ Rect = __decorate([
7912
7966
  const rect = Rect.prototype;
7913
7967
  const group = Group.prototype;
7914
7968
  const childrenRenderBounds = {};
7915
- const { copy: copy$2, add, includes: includes$1 } = BoundsHelper;
7969
+ const { copy: copy$2, add, includes: includes$1, copyAndSpread: copyAndSpread$1 } = BoundsHelper;
7916
7970
  let Box = class Box extends Group {
7917
7971
  get __tag() { return 'Box'; }
7918
7972
  get isBranchLeaf() { return true; }
@@ -7926,20 +7980,23 @@ let Box = class Box extends Group {
7926
7980
  return this.__updateRectRenderSpread() || -1;
7927
7981
  }
7928
7982
  __updateRectBoxBounds() { }
7929
- __updateBoxBounds() {
7983
+ __updateBoxBounds(secondLayout) {
7930
7984
  const data = this.__;
7931
7985
  if (this.children.length) {
7932
7986
  if (data.__autoSide) {
7933
7987
  if (this.leafer && this.leafer.ready)
7934
7988
  this.leafer.layouter.addExtra(this);
7935
7989
  super.__updateBoxBounds();
7990
+ const { boxBounds } = this.__layout;
7936
7991
  if (!data.__autoSize) {
7937
- const b = this.__layout.boxBounds;
7938
- if (!data.__autoWidth)
7939
- b.height += b.y, b.width = data.width, b.x = b.y = 0;
7940
- if (!data.__autoHeight)
7941
- b.width += b.x, b.height = data.height, b.y = b.x = 0;
7992
+ if (data.__autoWidth)
7993
+ boxBounds.width += boxBounds.x, boxBounds.height = data.height, boxBounds.y = boxBounds.x = 0;
7994
+ else
7995
+ boxBounds.height += boxBounds.y, boxBounds.width = data.width, boxBounds.x = boxBounds.y = 0;
7942
7996
  }
7997
+ if (secondLayout && data.flow && data.padding)
7998
+ copyAndSpread$1(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'));
7999
+ this.__updateNaturalSize();
7943
8000
  }
7944
8001
  else {
7945
8002
  this.__updateRectBoxBounds();
@@ -7959,13 +8016,13 @@ let Box = class Box extends Group {
7959
8016
  super.__updateRenderBounds();
7960
8017
  copy$2(childrenRenderBounds, renderBounds);
7961
8018
  this.__updateRectRenderBounds();
7962
- isOverflow = !includes$1(renderBounds, childrenRenderBounds) || undefined;
8019
+ isOverflow = !includes$1(renderBounds, childrenRenderBounds) || !this.pathInputed || !this.__.cornerRadius;
7963
8020
  }
7964
8021
  else {
7965
8022
  this.__updateRectRenderBounds();
7966
8023
  }
7967
8024
  this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
7968
- if (isOverflow && !(this.__.__drawAfterFill = this.__.overflow === 'hide'))
8025
+ if (!(this.__.__drawAfterFill = this.__.overflow === 'hide') && isOverflow)
7969
8026
  add(renderBounds, childrenRenderBounds);
7970
8027
  }
7971
8028
  __updateRectRenderBounds() { }
@@ -8299,14 +8356,26 @@ __decorate([
8299
8356
  Image$1 = __decorate([
8300
8357
  registerUI()
8301
8358
  ], Image$1);
8359
+ const MyImage = Image$1;
8302
8360
 
8303
8361
  let Canvas = class Canvas extends Rect {
8304
8362
  get __tag() { return 'Canvas'; }
8363
+ get ready() { return !this.url; }
8305
8364
  constructor(data) {
8306
8365
  super(data);
8307
8366
  this.canvas = Creator.canvas(this.__);
8308
8367
  this.context = this.canvas.context;
8309
8368
  this.__.__isCanvas = this.__.__drawAfterFill = true;
8369
+ if (data && data.url)
8370
+ this.drawImage(data.url);
8371
+ }
8372
+ drawImage(url) {
8373
+ new LeaferImage({ url }).load((image) => {
8374
+ this.context.drawImage(image.view, 0, 0);
8375
+ this.url = undefined;
8376
+ this.paint();
8377
+ this.emitEvent(new ImageEvent(ImageEvent.LOADED, { image }));
8378
+ });
8310
8379
  }
8311
8380
  draw(ui, offset, scale, rotation) {
8312
8381
  ui.__layout.update();
@@ -8365,7 +8434,7 @@ __decorate([
8365
8434
  resizeType(100)
8366
8435
  ], Canvas.prototype, "height", void 0);
8367
8436
  __decorate([
8368
- resizeType(Platform.devicePixelRatio)
8437
+ resizeType(1)
8369
8438
  ], Canvas.prototype, "pixelRatio", void 0);
8370
8439
  __decorate([
8371
8440
  resizeType(true)
@@ -8389,13 +8458,13 @@ let Text = class Text extends UI {
8389
8458
  super(data);
8390
8459
  }
8391
8460
  __drawHitPath(canvas) {
8392
- const { __lineHeight, __baseLine, __textDrawData: data } = this.__;
8461
+ const { __lineHeight, fontSize, __baseLine, __textDrawData: data } = this.__;
8393
8462
  canvas.beginPath();
8394
8463
  if (this.__.__letterSpacing < 0) {
8395
8464
  this.__drawPathByData(canvas);
8396
8465
  }
8397
8466
  else {
8398
- data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight));
8467
+ data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight));
8399
8468
  }
8400
8469
  }
8401
8470
  __drawPathByData(drawer, _data) {
@@ -8588,7 +8657,8 @@ let Pen = class Pen extends Group {
8588
8657
  drawPoints(_points, _curve, _close) { return this; }
8589
8658
  clearPath() { return this; }
8590
8659
  paint() {
8591
- this.pathElement.forceUpdate('path');
8660
+ if (!this.pathElement.__layout.boxChanged)
8661
+ this.pathElement.forceUpdate('path');
8592
8662
  }
8593
8663
  };
8594
8664
  __decorate([
@@ -8598,7 +8668,7 @@ __decorate([
8598
8668
  penPathType()
8599
8669
  ], Pen.prototype, "path", void 0);
8600
8670
  Pen = __decorate([
8601
- useModule(PathCreator, ['set', 'beginPath', 'path']),
8671
+ useModule(PathCreator, ['set', 'beginPath', 'path', 'paint']),
8602
8672
  registerUI()
8603
8673
  ], Pen);
8604
8674
  function penPathType() {
@@ -8960,10 +9030,13 @@ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, al
8960
9030
  const { get: get$2, translate } = MatrixHelper;
8961
9031
  const tempBox = new Bounds();
8962
9032
  const tempPoint = {};
9033
+ const tempScaleData = {};
8963
9034
  function createData(leafPaint, image, paint, box) {
8964
- const { blendMode } = paint;
9035
+ const { blendMode, sync } = paint;
8965
9036
  if (blendMode)
8966
9037
  leafPaint.blendMode = blendMode;
9038
+ if (sync)
9039
+ leafPaint.sync = sync;
8967
9040
  leafPaint.data = getPatternData(paint, box, image);
8968
9041
  }
8969
9042
  function getPatternData(paint, box, image) {
@@ -8983,13 +9056,10 @@ function getPatternData(paint, box, image) {
8983
9056
  x += (box.width - width * scaleX) / 2, y += (box.height - height * scaleY) / 2;
8984
9057
  }
8985
9058
  }
8986
- else if (size) {
8987
- scaleX = (typeof size === 'number' ? size : size.width) / width;
8988
- scaleY = (typeof size === 'number' ? size : size.height) / height;
8989
- }
8990
- else if (scale) {
8991
- scaleX = typeof scale === 'number' ? scale : scale.x;
8992
- scaleY = typeof scale === 'number' ? scale : scale.y;
9059
+ else if (scale || size) {
9060
+ MathHelper.getScaleData(scale, size, image, tempScaleData);
9061
+ scaleX = tempScaleData.scaleX;
9062
+ scaleY = tempScaleData.scaleY;
8993
9063
  }
8994
9064
  if (align) {
8995
9065
  const imageBounds = { x, y, width: swapWidth, height: swapHeight };
@@ -9228,7 +9298,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
9228
9298
  return true;
9229
9299
  }
9230
9300
  else {
9231
- if (!paint.style || Export.running) {
9301
+ if (!paint.style || paint.sync || Export.running) {
9232
9302
  createPattern(ui, paint, canvas.pixelRatio);
9233
9303
  }
9234
9304
  else {
@@ -10098,6 +10168,7 @@ const ExportModule = {
10098
10168
  export(leaf, filename, options) {
10099
10169
  this.running = true;
10100
10170
  const fileType = FileHelper.fileType(filename);
10171
+ const isDownload = filename.includes('.');
10101
10172
  options = FileHelper.getExportOptions(options);
10102
10173
  return addTask((success) => new Promise((resolve) => {
10103
10174
  const over = (result) => {
@@ -10107,19 +10178,13 @@ const ExportModule = {
10107
10178
  };
10108
10179
  const { toURL } = Platform;
10109
10180
  const { download } = Platform.origin;
10110
- if (filename === 'json') {
10111
- return over({ data: leaf.toJSON(options.json) });
10112
- }
10113
- else if (fileType === 'json') {
10114
- download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
10115
- return over({ data: true });
10116
- }
10117
- if (filename === 'svg') {
10118
- return over({ data: leaf.toSVG() });
10181
+ if (fileType === 'json') {
10182
+ isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
10183
+ return over({ data: isDownload ? true : leaf.toJSON(options.json) });
10119
10184
  }
10120
- else if (fileType === 'svg') {
10121
- download(toURL(leaf.toSVG(), 'svg'), filename);
10122
- return over({ data: true });
10185
+ if (fileType === 'svg') {
10186
+ isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
10187
+ return over({ data: isDownload ? true : leaf.toSVG() });
10123
10188
  }
10124
10189
  const { leafer } = leaf;
10125
10190
  if (leafer) {
@@ -10128,14 +10193,8 @@ const ExportModule = {
10128
10193
  let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
10129
10194
  const { worldTransform, isLeafer, isFrame } = leaf;
10130
10195
  const { slice, trim, onCanvas } = options;
10131
- let scale = options.scale || 1;
10132
- let pixelRatio = options.pixelRatio || 1;
10133
10196
  const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
10134
10197
  const contextSettings = options.contextSettings || leafer.config.contextSettings;
10135
- if (leaf.isApp) {
10136
- scale *= pixelRatio;
10137
- pixelRatio = leaf.app.pixelRatio;
10138
- }
10139
10198
  const screenshot = options.screenshot || leaf.isApp;
10140
10199
  const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
10141
10200
  const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
@@ -10169,9 +10228,17 @@ const ExportModule = {
10169
10228
  }
10170
10229
  renderBounds = leaf.getBounds('render', relative);
10171
10230
  }
10172
- const { x, y, width, height } = new Bounds(renderBounds).scale(scale);
10231
+ const scaleData = { scaleX: 1, scaleY: 1 };
10232
+ MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
10233
+ let pixelRatio = options.pixelRatio || 1;
10234
+ if (leaf.isApp) {
10235
+ scaleData.scaleX *= pixelRatio;
10236
+ scaleData.scaleY *= pixelRatio;
10237
+ pixelRatio = leaf.app.pixelRatio;
10238
+ }
10239
+ const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
10240
+ const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
10173
10241
  let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
10174
- const renderOptions = { matrix: matrix.scale(1 / scale).invert().translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) };
10175
10242
  let sliceLeaf;
10176
10243
  if (slice) {
10177
10244
  sliceLeaf = leaf;
@@ -10276,4 +10343,4 @@ Object.assign(Export, ExportModule);
10276
10343
 
10277
10344
  useCanvas();
10278
10345
 
10279
- 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$1 as 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 };
10346
+ 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$1 as 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 };