@leafer-draw/miniapp 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
  }
@@ -5827,6 +5864,8 @@ class LeaferCanvas extends LeaferCanvasBase {
5827
5864
  const size = { width: width || view.width, height: height || view.height, pixelRatio };
5828
5865
  this.resize(size);
5829
5866
  if (this.context) {
5867
+ if (this.viewSelect)
5868
+ Platform.renderCanvas = this;
5830
5869
  if (this.context.roundRect) {
5831
5870
  this.roundRect = function (x, y, width, height, radius) {
5832
5871
  this.context.roundRect(x, y, width, height, typeof radius === 'number' ? [radius] : radius);
@@ -5894,119 +5933,120 @@ Object.assign(Creator, {
5894
5933
  image: (options) => new LeaferImage(options)
5895
5934
  });
5896
5935
  function useCanvas(_canvasType, app) {
5897
- if (!Platform.origin) {
5898
- Platform.origin = {
5899
- createCanvas: (width, height, _format) => app.createOffscreenCanvas({ type: '2d', width, height }),
5900
- canvasToDataURL: (canvas, type, quality) => canvas.toDataURL(mineType(type), quality),
5901
- canvasToBolb: (canvas, type, quality) => canvas.toBuffer(type, { quality }),
5902
- canvasSaveAs: (canvas, filePath, quality) => {
5903
- let data = canvas.toDataURL(mineType(fileType(filePath)), quality);
5904
- data = data.substring(data.indexOf('64,') + 3);
5905
- return Platform.origin.download(data, filePath);
5906
- },
5907
- download(data, filePath) {
5908
- return new Promise((resolve, reject) => {
5909
- let toAlbum;
5910
- if (!filePath.includes('/')) {
5911
- filePath = `${app.env.USER_DATA_PATH}/` + filePath;
5912
- toAlbum = true;
5913
- }
5914
- const fs = app.getFileSystemManager();
5915
- fs.writeFile({
5916
- filePath,
5917
- data,
5918
- encoding: 'base64',
5919
- success() {
5920
- if (toAlbum) {
5921
- Platform.miniapp.saveToAlbum(filePath).then(() => {
5922
- fs.unlink({ filePath });
5923
- resolve();
5924
- });
5925
- }
5926
- else {
5936
+ Platform.origin = {
5937
+ createCanvas: (width, height, _format) => app.createOffscreenCanvas({ type: '2d', width, height }),
5938
+ canvasToDataURL: (canvas, type, quality) => canvas.toDataURL(mineType(type), quality),
5939
+ canvasToBolb: (canvas, type, quality) => canvas.toBuffer(type, { quality }),
5940
+ canvasSaveAs: (canvas, filePath, quality) => {
5941
+ let data = canvas.toDataURL(mineType(fileType(filePath)), quality);
5942
+ data = data.substring(data.indexOf('64,') + 3);
5943
+ return Platform.origin.download(data, filePath);
5944
+ },
5945
+ download(data, filePath) {
5946
+ return new Promise((resolve, reject) => {
5947
+ let toAlbum;
5948
+ if (!filePath.includes('/')) {
5949
+ filePath = `${app.env.USER_DATA_PATH}/` + filePath;
5950
+ toAlbum = true;
5951
+ }
5952
+ const fs = app.getFileSystemManager();
5953
+ fs.writeFile({
5954
+ filePath,
5955
+ data,
5956
+ encoding: 'base64',
5957
+ success() {
5958
+ if (toAlbum) {
5959
+ Platform.miniapp.saveToAlbum(filePath).then(() => {
5960
+ fs.unlink({ filePath });
5927
5961
  resolve();
5928
- }
5929
- },
5930
- fail(error) {
5931
- reject(error);
5962
+ });
5932
5963
  }
5933
- });
5934
- });
5935
- },
5936
- loadImage(src) {
5937
- return new Promise((resolve, reject) => {
5938
- const img = Platform.canvas.view.createImage();
5939
- img.onload = () => { resolve(img); };
5940
- img.onerror = (error) => { reject(error); };
5941
- img.src = Platform.image.getRealURL(src);
5964
+ else {
5965
+ resolve();
5966
+ }
5967
+ },
5968
+ fail(error) {
5969
+ reject(error);
5970
+ }
5942
5971
  });
5943
- },
5944
- noRepeat: 'repeat-x'
5945
- };
5946
- Platform.miniapp = {
5947
- select(name) {
5948
- return app.createSelectorQuery().select(name);
5949
- },
5950
- getBounds(select) {
5951
- return new Promise((resolve) => {
5952
- select.boundingClientRect().exec((res) => {
5953
- const rect = res[1];
5954
- resolve({ x: rect.top, y: rect.left, width: rect.width, height: rect.height });
5955
- });
5972
+ });
5973
+ },
5974
+ loadImage(src) {
5975
+ return new Promise((resolve, reject) => {
5976
+ const img = Platform.canvas.view.createImage();
5977
+ img.onload = () => { resolve(img); };
5978
+ img.onerror = (error) => { reject(error); };
5979
+ img.src = Platform.image.getRealURL(src);
5980
+ });
5981
+ },
5982
+ noRepeat: 'repeat-x'
5983
+ };
5984
+ Platform.miniapp = {
5985
+ select(name) {
5986
+ return app.createSelectorQuery().select(name);
5987
+ },
5988
+ getBounds(select) {
5989
+ return new Promise((resolve) => {
5990
+ select.boundingClientRect().exec((res) => {
5991
+ const rect = res[1];
5992
+ resolve({ x: rect.top, y: rect.left, width: rect.width, height: rect.height });
5956
5993
  });
5957
- },
5958
- getSizeView(select) {
5959
- return new Promise((resolve) => {
5960
- select.fields({ node: true, size: true }).exec((res) => {
5961
- const data = res[0];
5962
- resolve({ view: data.node, width: data.width, height: data.height });
5963
- });
5994
+ });
5995
+ },
5996
+ getSizeView(select) {
5997
+ return new Promise((resolve) => {
5998
+ select.fields({ node: true, size: true }).exec((res) => {
5999
+ const data = res[0];
6000
+ resolve({ view: data.node, width: data.width, height: data.height });
5964
6001
  });
5965
- },
5966
- saveToAlbum(path) {
5967
- return new Promise((resolve) => {
5968
- app.getSetting({
5969
- success: (res) => {
5970
- if (res.authSetting['scope.writePhotosAlbum']) {
5971
- app.saveImageToPhotosAlbum({
5972
- filePath: path,
5973
- success() { resolve(true); }
5974
- });
5975
- }
5976
- else {
5977
- app.authorize({
5978
- scope: 'scope.writePhotosAlbum',
5979
- success: () => {
5980
- app.saveImageToPhotosAlbum({
5981
- filePath: path,
5982
- success() { resolve(true); }
5983
- });
5984
- },
5985
- fail: () => { }
5986
- });
5987
- }
6002
+ });
6003
+ },
6004
+ saveToAlbum(path) {
6005
+ return new Promise((resolve) => {
6006
+ app.getSetting({
6007
+ success: (res) => {
6008
+ if (res.authSetting['scope.writePhotosAlbum']) {
6009
+ app.saveImageToPhotosAlbum({
6010
+ filePath: path,
6011
+ success() { resolve(true); }
6012
+ });
5988
6013
  }
5989
- });
6014
+ else {
6015
+ app.authorize({
6016
+ scope: 'scope.writePhotosAlbum',
6017
+ success: () => {
6018
+ app.saveImageToPhotosAlbum({
6019
+ filePath: path,
6020
+ success() { resolve(true); }
6021
+ });
6022
+ },
6023
+ fail: () => { }
6024
+ });
6025
+ }
6026
+ }
5990
6027
  });
5991
- },
5992
- onWindowResize(fun) {
5993
- app.onWindowResize(fun);
5994
- },
5995
- offWindowResize(fun) {
5996
- app.offWindowResize(fun);
5997
- }
5998
- };
5999
- Platform.event = {
6000
- stopDefault(_origin) { },
6001
- stopNow(_origin) { },
6002
- stop(_origin) { }
6003
- };
6004
- Platform.canvas = Creator.canvas();
6005
- Platform.conicGradientSupport = !!Platform.canvas.context.createConicGradient;
6006
- }
6028
+ });
6029
+ },
6030
+ onWindowResize(fun) {
6031
+ app.onWindowResize(fun);
6032
+ },
6033
+ offWindowResize(fun) {
6034
+ app.offWindowResize(fun);
6035
+ }
6036
+ };
6037
+ Platform.event = {
6038
+ stopDefault(_origin) { },
6039
+ stopNow(_origin) { },
6040
+ stop(_origin) { }
6041
+ };
6042
+ Platform.canvas = Creator.canvas();
6043
+ Platform.conicGradientSupport = !!Platform.canvas.context.createConicGradient;
6007
6044
  }
6008
6045
  Platform.name = 'miniapp';
6009
- Platform.requestRender = function (render) { Platform.canvas.view.requestAnimationFrame(render); };
6046
+ Platform.requestRender = function (render) {
6047
+ const { view } = (Platform.renderCanvas || Platform.canvas);
6048
+ view.requestAnimationFrame ? view.requestAnimationFrame(render) : setTimeout(render, 16);
6049
+ };
6010
6050
  defineKey(Platform, 'devicePixelRatio', { get() { return Math.max(1, wx.getSystemInfoSync().pixelRatio); } });
6011
6051
 
6012
6052
  class Watcher {
@@ -6801,6 +6841,11 @@ class BoxData extends GroupData {
6801
6841
  }
6802
6842
 
6803
6843
  class LeaferData extends GroupData {
6844
+ __getInputData() {
6845
+ const data = super.__getInputData();
6846
+ canvasSizeAttrs.forEach(key => delete data[key]);
6847
+ return data;
6848
+ }
6804
6849
  }
6805
6850
 
6806
6851
  class FrameData extends BoxData {
@@ -6878,6 +6923,11 @@ class ImageData extends RectData {
6878
6923
  }
6879
6924
 
6880
6925
  class CanvasData extends RectData {
6926
+ __getInputData() {
6927
+ const data = super.__getInputData();
6928
+ data.url = this.__leaf.canvas.toDataURL('image/png');
6929
+ return data;
6930
+ }
6881
6931
  }
6882
6932
 
6883
6933
  const UIBounds = {
@@ -7790,6 +7840,13 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7790
7840
  getWorldPointByClient(clientPoint, updateClient) {
7791
7841
  return this.interaction && this.interaction.getLocal(clientPoint, updateClient);
7792
7842
  }
7843
+ getPagePointByClient(clientPoint, updateClient) {
7844
+ return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient));
7845
+ }
7846
+ updateClientBounds() {
7847
+ this.canvas && this.canvas.updateClientBounds();
7848
+ }
7849
+ receiveEvent(_event) { }
7793
7850
  __checkUpdateLayout() {
7794
7851
  this.__layout.update();
7795
7852
  }
@@ -7873,7 +7930,7 @@ Rect = __decorate([
7873
7930
  const rect = Rect.prototype;
7874
7931
  const group = Group.prototype;
7875
7932
  const childrenRenderBounds = {};
7876
- const { copy: copy$2, add, includes: includes$1 } = BoundsHelper;
7933
+ const { copy: copy$2, add, includes: includes$1, copyAndSpread: copyAndSpread$1 } = BoundsHelper;
7877
7934
  let Box = class Box extends Group {
7878
7935
  get __tag() { return 'Box'; }
7879
7936
  get isBranchLeaf() { return true; }
@@ -7887,20 +7944,23 @@ let Box = class Box extends Group {
7887
7944
  return this.__updateRectRenderSpread() || -1;
7888
7945
  }
7889
7946
  __updateRectBoxBounds() { }
7890
- __updateBoxBounds() {
7947
+ __updateBoxBounds(secondLayout) {
7891
7948
  const data = this.__;
7892
7949
  if (this.children.length) {
7893
7950
  if (data.__autoSide) {
7894
7951
  if (this.leafer && this.leafer.ready)
7895
7952
  this.leafer.layouter.addExtra(this);
7896
7953
  super.__updateBoxBounds();
7954
+ const { boxBounds } = this.__layout;
7897
7955
  if (!data.__autoSize) {
7898
- const b = this.__layout.boxBounds;
7899
- if (!data.__autoWidth)
7900
- b.height += b.y, b.width = data.width, b.x = b.y = 0;
7901
- if (!data.__autoHeight)
7902
- b.width += b.x, b.height = data.height, b.y = b.x = 0;
7956
+ if (data.__autoWidth)
7957
+ boxBounds.width += boxBounds.x, boxBounds.height = data.height, boxBounds.y = boxBounds.x = 0;
7958
+ else
7959
+ boxBounds.height += boxBounds.y, boxBounds.width = data.width, boxBounds.x = boxBounds.y = 0;
7903
7960
  }
7961
+ if (secondLayout && data.flow && data.padding)
7962
+ copyAndSpread$1(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'));
7963
+ this.__updateNaturalSize();
7904
7964
  }
7905
7965
  else {
7906
7966
  this.__updateRectBoxBounds();
@@ -7920,13 +7980,13 @@ let Box = class Box extends Group {
7920
7980
  super.__updateRenderBounds();
7921
7981
  copy$2(childrenRenderBounds, renderBounds);
7922
7982
  this.__updateRectRenderBounds();
7923
- isOverflow = !includes$1(renderBounds, childrenRenderBounds) || undefined;
7983
+ isOverflow = !includes$1(renderBounds, childrenRenderBounds) || !this.pathInputed || !this.__.cornerRadius;
7924
7984
  }
7925
7985
  else {
7926
7986
  this.__updateRectRenderBounds();
7927
7987
  }
7928
7988
  this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
7929
- if (isOverflow && !(this.__.__drawAfterFill = this.__.overflow === 'hide'))
7989
+ if (!(this.__.__drawAfterFill = this.__.overflow === 'hide') && isOverflow)
7930
7990
  add(renderBounds, childrenRenderBounds);
7931
7991
  }
7932
7992
  __updateRectRenderBounds() { }
@@ -8260,14 +8320,26 @@ __decorate([
8260
8320
  Image = __decorate([
8261
8321
  registerUI()
8262
8322
  ], Image);
8323
+ const MyImage = Image;
8263
8324
 
8264
8325
  let Canvas = class Canvas extends Rect {
8265
8326
  get __tag() { return 'Canvas'; }
8327
+ get ready() { return !this.url; }
8266
8328
  constructor(data) {
8267
8329
  super(data);
8268
8330
  this.canvas = Creator.canvas(this.__);
8269
8331
  this.context = this.canvas.context;
8270
8332
  this.__.__isCanvas = this.__.__drawAfterFill = true;
8333
+ if (data && data.url)
8334
+ this.drawImage(data.url);
8335
+ }
8336
+ drawImage(url) {
8337
+ new LeaferImage({ url }).load((image) => {
8338
+ this.context.drawImage(image.view, 0, 0);
8339
+ this.url = undefined;
8340
+ this.paint();
8341
+ this.emitEvent(new ImageEvent(ImageEvent.LOADED, { image }));
8342
+ });
8271
8343
  }
8272
8344
  draw(ui, offset, scale, rotation) {
8273
8345
  ui.__layout.update();
@@ -8326,7 +8398,7 @@ __decorate([
8326
8398
  resizeType(100)
8327
8399
  ], Canvas.prototype, "height", void 0);
8328
8400
  __decorate([
8329
- resizeType(Platform.devicePixelRatio)
8401
+ resizeType(1)
8330
8402
  ], Canvas.prototype, "pixelRatio", void 0);
8331
8403
  __decorate([
8332
8404
  resizeType(true)
@@ -8350,13 +8422,13 @@ let Text = class Text extends UI {
8350
8422
  super(data);
8351
8423
  }
8352
8424
  __drawHitPath(canvas) {
8353
- const { __lineHeight, __baseLine, __textDrawData: data } = this.__;
8425
+ const { __lineHeight, fontSize, __baseLine, __textDrawData: data } = this.__;
8354
8426
  canvas.beginPath();
8355
8427
  if (this.__.__letterSpacing < 0) {
8356
8428
  this.__drawPathByData(canvas);
8357
8429
  }
8358
8430
  else {
8359
- data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight));
8431
+ data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight));
8360
8432
  }
8361
8433
  }
8362
8434
  __drawPathByData(drawer, _data) {
@@ -8549,7 +8621,8 @@ let Pen = class Pen extends Group {
8549
8621
  drawPoints(_points, _curve, _close) { return this; }
8550
8622
  clearPath() { return this; }
8551
8623
  paint() {
8552
- this.pathElement.forceUpdate('path');
8624
+ if (!this.pathElement.__layout.boxChanged)
8625
+ this.pathElement.forceUpdate('path');
8553
8626
  }
8554
8627
  };
8555
8628
  __decorate([
@@ -8559,7 +8632,7 @@ __decorate([
8559
8632
  penPathType()
8560
8633
  ], Pen.prototype, "path", void 0);
8561
8634
  Pen = __decorate([
8562
- useModule(PathCreator, ['set', 'beginPath', 'path']),
8635
+ useModule(PathCreator, ['set', 'beginPath', 'path', 'paint']),
8563
8636
  registerUI()
8564
8637
  ], Pen);
8565
8638
  function penPathType() {
@@ -8921,10 +8994,13 @@ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, al
8921
8994
  const { get: get$2, translate } = MatrixHelper;
8922
8995
  const tempBox = new Bounds();
8923
8996
  const tempPoint = {};
8997
+ const tempScaleData = {};
8924
8998
  function createData(leafPaint, image, paint, box) {
8925
- const { blendMode } = paint;
8999
+ const { blendMode, sync } = paint;
8926
9000
  if (blendMode)
8927
9001
  leafPaint.blendMode = blendMode;
9002
+ if (sync)
9003
+ leafPaint.sync = sync;
8928
9004
  leafPaint.data = getPatternData(paint, box, image);
8929
9005
  }
8930
9006
  function getPatternData(paint, box, image) {
@@ -8944,13 +9020,10 @@ function getPatternData(paint, box, image) {
8944
9020
  x += (box.width - width * scaleX) / 2, y += (box.height - height * scaleY) / 2;
8945
9021
  }
8946
9022
  }
8947
- else if (size) {
8948
- scaleX = (typeof size === 'number' ? size : size.width) / width;
8949
- scaleY = (typeof size === 'number' ? size : size.height) / height;
8950
- }
8951
- else if (scale) {
8952
- scaleX = typeof scale === 'number' ? scale : scale.x;
8953
- scaleY = typeof scale === 'number' ? scale : scale.y;
9023
+ else if (scale || size) {
9024
+ MathHelper.getScaleData(scale, size, image, tempScaleData);
9025
+ scaleX = tempScaleData.scaleX;
9026
+ scaleY = tempScaleData.scaleY;
8954
9027
  }
8955
9028
  if (align) {
8956
9029
  const imageBounds = { x, y, width: swapWidth, height: swapHeight };
@@ -9189,7 +9262,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
9189
9262
  return true;
9190
9263
  }
9191
9264
  else {
9192
- if (!paint.style || Export.running) {
9265
+ if (!paint.style || paint.sync || Export.running) {
9193
9266
  createPattern(ui, paint, canvas.pixelRatio);
9194
9267
  }
9195
9268
  else {
@@ -10059,6 +10132,7 @@ const ExportModule = {
10059
10132
  export(leaf, filename, options) {
10060
10133
  this.running = true;
10061
10134
  const fileType = FileHelper.fileType(filename);
10135
+ const isDownload = filename.includes('.');
10062
10136
  options = FileHelper.getExportOptions(options);
10063
10137
  return addTask((success) => new Promise((resolve) => {
10064
10138
  const over = (result) => {
@@ -10068,19 +10142,13 @@ const ExportModule = {
10068
10142
  };
10069
10143
  const { toURL } = Platform;
10070
10144
  const { download } = Platform.origin;
10071
- if (filename === 'json') {
10072
- return over({ data: leaf.toJSON(options.json) });
10073
- }
10074
- else if (fileType === 'json') {
10075
- download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
10076
- return over({ data: true });
10077
- }
10078
- if (filename === 'svg') {
10079
- return over({ data: leaf.toSVG() });
10145
+ if (fileType === 'json') {
10146
+ isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
10147
+ return over({ data: isDownload ? true : leaf.toJSON(options.json) });
10080
10148
  }
10081
- else if (fileType === 'svg') {
10082
- download(toURL(leaf.toSVG(), 'svg'), filename);
10083
- return over({ data: true });
10149
+ if (fileType === 'svg') {
10150
+ isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
10151
+ return over({ data: isDownload ? true : leaf.toSVG() });
10084
10152
  }
10085
10153
  const { leafer } = leaf;
10086
10154
  if (leafer) {
@@ -10089,14 +10157,8 @@ const ExportModule = {
10089
10157
  let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
10090
10158
  const { worldTransform, isLeafer, isFrame } = leaf;
10091
10159
  const { slice, trim, onCanvas } = options;
10092
- let scale = options.scale || 1;
10093
- let pixelRatio = options.pixelRatio || 1;
10094
10160
  const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
10095
10161
  const contextSettings = options.contextSettings || leafer.config.contextSettings;
10096
- if (leaf.isApp) {
10097
- scale *= pixelRatio;
10098
- pixelRatio = leaf.app.pixelRatio;
10099
- }
10100
10162
  const screenshot = options.screenshot || leaf.isApp;
10101
10163
  const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
10102
10164
  const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
@@ -10130,9 +10192,17 @@ const ExportModule = {
10130
10192
  }
10131
10193
  renderBounds = leaf.getBounds('render', relative);
10132
10194
  }
10133
- const { x, y, width, height } = new Bounds(renderBounds).scale(scale);
10195
+ const scaleData = { scaleX: 1, scaleY: 1 };
10196
+ MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
10197
+ let pixelRatio = options.pixelRatio || 1;
10198
+ if (leaf.isApp) {
10199
+ scaleData.scaleX *= pixelRatio;
10200
+ scaleData.scaleY *= pixelRatio;
10201
+ pixelRatio = leaf.app.pixelRatio;
10202
+ }
10203
+ const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
10204
+ const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
10134
10205
  let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
10135
- const renderOptions = { matrix: matrix.scale(1 / scale).invert().translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) };
10136
10206
  let sliceLeaf;
10137
10207
  if (slice) {
10138
10208
  sliceLeaf = leaf;
@@ -10236,8 +10306,9 @@ Object.assign(Effect, EffectModule);
10236
10306
  Object.assign(Export, ExportModule);
10237
10307
 
10238
10308
  try {
10239
- useCanvas('wx', wx);
10309
+ if (wx)
10310
+ useCanvas('miniapp', wx);
10240
10311
  }
10241
10312
  catch (_a) { }
10242
10313
 
10243
- 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 };
10314
+ 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 };