@leafer-ui/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$b(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$2(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$7, toInnerPoint: toInnerPoint$1, scaleOfOuter: scaleOfOuter$2, rotateOfOuter: rotateOfOuter$2, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
4021
+ const { copy: copy$7, toInnerPoint: toInnerPoint$1, toOuterPoint: toOuterPoint$1, scaleOfOuter: scaleOfOuter$2, rotateOfOuter: rotateOfOuter$2, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
3987
4022
  const matrix$1 = {};
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$5 } = BoundsHelper;
4955
+ const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$2, copy: copy$5 } = 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$5(layout.renderBounds, layout.strokeBounds);
5078
+ layout.renderSpread > 0 ? copyAndSpread$2(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$5(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
  }
@@ -6938,6 +6975,11 @@ class BoxData extends GroupData {
6938
6975
  }
6939
6976
 
6940
6977
  class LeaferData extends GroupData {
6978
+ __getInputData() {
6979
+ const data = super.__getInputData();
6980
+ canvasSizeAttrs.forEach(key => delete data[key]);
6981
+ return data;
6982
+ }
6941
6983
  }
6942
6984
 
6943
6985
  class FrameData extends BoxData {
@@ -7015,6 +7057,11 @@ class ImageData extends RectData {
7015
7057
  }
7016
7058
 
7017
7059
  class CanvasData extends RectData {
7060
+ __getInputData() {
7061
+ const data = super.__getInputData();
7062
+ data.url = this.__leaf.canvas.toDataURL('image/png');
7063
+ return data;
7064
+ }
7018
7065
  }
7019
7066
 
7020
7067
  const UIBounds = {
@@ -7927,6 +7974,13 @@ let Leafer = Leafer_1 = class Leafer extends Group {
7927
7974
  getWorldPointByClient(clientPoint, updateClient) {
7928
7975
  return this.interaction && this.interaction.getLocal(clientPoint, updateClient);
7929
7976
  }
7977
+ getPagePointByClient(clientPoint, updateClient) {
7978
+ return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient));
7979
+ }
7980
+ updateClientBounds() {
7981
+ this.canvas && this.canvas.updateClientBounds();
7982
+ }
7983
+ receiveEvent(_event) { }
7930
7984
  __checkUpdateLayout() {
7931
7985
  this.__layout.update();
7932
7986
  }
@@ -8010,7 +8064,7 @@ Rect = __decorate([
8010
8064
  const rect$1 = Rect.prototype;
8011
8065
  const group$1 = Group.prototype;
8012
8066
  const childrenRenderBounds = {};
8013
- const { copy: copy$3, add, includes: includes$1 } = BoundsHelper;
8067
+ const { copy: copy$3, add, includes: includes$1, copyAndSpread: copyAndSpread$1 } = BoundsHelper;
8014
8068
  let Box = class Box extends Group {
8015
8069
  get __tag() { return 'Box'; }
8016
8070
  get isBranchLeaf() { return true; }
@@ -8024,20 +8078,23 @@ let Box = class Box extends Group {
8024
8078
  return this.__updateRectRenderSpread() || -1;
8025
8079
  }
8026
8080
  __updateRectBoxBounds() { }
8027
- __updateBoxBounds() {
8081
+ __updateBoxBounds(secondLayout) {
8028
8082
  const data = this.__;
8029
8083
  if (this.children.length) {
8030
8084
  if (data.__autoSide) {
8031
8085
  if (this.leafer && this.leafer.ready)
8032
8086
  this.leafer.layouter.addExtra(this);
8033
8087
  super.__updateBoxBounds();
8088
+ const { boxBounds } = this.__layout;
8034
8089
  if (!data.__autoSize) {
8035
- const b = this.__layout.boxBounds;
8036
- if (!data.__autoWidth)
8037
- b.height += b.y, b.width = data.width, b.x = b.y = 0;
8038
- if (!data.__autoHeight)
8039
- b.width += b.x, b.height = data.height, b.y = b.x = 0;
8090
+ if (data.__autoWidth)
8091
+ boxBounds.width += boxBounds.x, boxBounds.height = data.height, boxBounds.y = boxBounds.x = 0;
8092
+ else
8093
+ boxBounds.height += boxBounds.y, boxBounds.width = data.width, boxBounds.x = boxBounds.y = 0;
8040
8094
  }
8095
+ if (secondLayout && data.flow && data.padding)
8096
+ copyAndSpread$1(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'));
8097
+ this.__updateNaturalSize();
8041
8098
  }
8042
8099
  else {
8043
8100
  this.__updateRectBoxBounds();
@@ -8057,13 +8114,13 @@ let Box = class Box extends Group {
8057
8114
  super.__updateRenderBounds();
8058
8115
  copy$3(childrenRenderBounds, renderBounds);
8059
8116
  this.__updateRectRenderBounds();
8060
- isOverflow = !includes$1(renderBounds, childrenRenderBounds) || undefined;
8117
+ isOverflow = !includes$1(renderBounds, childrenRenderBounds) || !this.pathInputed || !this.__.cornerRadius;
8061
8118
  }
8062
8119
  else {
8063
8120
  this.__updateRectRenderBounds();
8064
8121
  }
8065
8122
  this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
8066
- if (isOverflow && !(this.__.__drawAfterFill = this.__.overflow === 'hide'))
8123
+ if (!(this.__.__drawAfterFill = this.__.overflow === 'hide') && isOverflow)
8067
8124
  add(renderBounds, childrenRenderBounds);
8068
8125
  }
8069
8126
  __updateRectRenderBounds() { }
@@ -8397,14 +8454,26 @@ __decorate([
8397
8454
  Image = __decorate([
8398
8455
  registerUI()
8399
8456
  ], Image);
8457
+ const MyImage = Image;
8400
8458
 
8401
8459
  let Canvas = class Canvas extends Rect {
8402
8460
  get __tag() { return 'Canvas'; }
8461
+ get ready() { return !this.url; }
8403
8462
  constructor(data) {
8404
8463
  super(data);
8405
8464
  this.canvas = Creator.canvas(this.__);
8406
8465
  this.context = this.canvas.context;
8407
8466
  this.__.__isCanvas = this.__.__drawAfterFill = true;
8467
+ if (data && data.url)
8468
+ this.drawImage(data.url);
8469
+ }
8470
+ drawImage(url) {
8471
+ new LeaferImage({ url }).load((image) => {
8472
+ this.context.drawImage(image.view, 0, 0);
8473
+ this.url = undefined;
8474
+ this.paint();
8475
+ this.emitEvent(new ImageEvent(ImageEvent.LOADED, { image }));
8476
+ });
8408
8477
  }
8409
8478
  draw(ui, offset, scale, rotation) {
8410
8479
  ui.__layout.update();
@@ -8463,7 +8532,7 @@ __decorate([
8463
8532
  resizeType(100)
8464
8533
  ], Canvas.prototype, "height", void 0);
8465
8534
  __decorate([
8466
- resizeType(Platform.devicePixelRatio)
8535
+ resizeType(1)
8467
8536
  ], Canvas.prototype, "pixelRatio", void 0);
8468
8537
  __decorate([
8469
8538
  resizeType(true)
@@ -8487,13 +8556,13 @@ let Text = class Text extends UI {
8487
8556
  super(data);
8488
8557
  }
8489
8558
  __drawHitPath(canvas) {
8490
- const { __lineHeight, __baseLine, __textDrawData: data } = this.__;
8559
+ const { __lineHeight, fontSize, __baseLine, __textDrawData: data } = this.__;
8491
8560
  canvas.beginPath();
8492
8561
  if (this.__.__letterSpacing < 0) {
8493
8562
  this.__drawPathByData(canvas);
8494
8563
  }
8495
8564
  else {
8496
- data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight));
8565
+ data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight));
8497
8566
  }
8498
8567
  }
8499
8568
  __drawPathByData(drawer, _data) {
@@ -8686,7 +8755,8 @@ let Pen = class Pen extends Group {
8686
8755
  drawPoints(_points, _curve, _close) { return this; }
8687
8756
  clearPath() { return this; }
8688
8757
  paint() {
8689
- this.pathElement.forceUpdate('path');
8758
+ if (!this.pathElement.__layout.boxChanged)
8759
+ this.pathElement.forceUpdate('path');
8690
8760
  }
8691
8761
  };
8692
8762
  __decorate([
@@ -8696,7 +8766,7 @@ __decorate([
8696
8766
  penPathType()
8697
8767
  ], Pen.prototype, "path", void 0);
8698
8768
  Pen = __decorate([
8699
- useModule(PathCreator, ['set', 'beginPath', 'path']),
8769
+ useModule(PathCreator, ['set', 'beginPath', 'path', 'paint']),
8700
8770
  registerUI()
8701
8771
  ], Pen);
8702
8772
  function penPathType() {
@@ -8919,6 +8989,7 @@ PointerEvent.MENU_TAP = 'pointer.menu_tap';
8919
8989
  PointerEvent = __decorate([
8920
8990
  registerUIEvent()
8921
8991
  ], PointerEvent);
8992
+ const MyPointerEvent = PointerEvent;
8922
8993
 
8923
8994
  const move = {};
8924
8995
  let DragEvent = class DragEvent extends PointerEvent {
@@ -9018,6 +9089,7 @@ DragEvent.LEAVE = 'drag.leave';
9018
9089
  DragEvent = __decorate([
9019
9090
  registerUIEvent()
9020
9091
  ], DragEvent);
9092
+ const MyDragEvent = DragEvent;
9021
9093
 
9022
9094
  let DropEvent = class DropEvent extends PointerEvent {
9023
9095
  static setList(data) {
@@ -9099,36 +9171,32 @@ function addInteractionWindow(leafer) {
9099
9171
 
9100
9172
  function document(leafer) {
9101
9173
  addInteractionWindow(leafer);
9102
- leafer.config.move.scroll = 'limit';
9103
- leafer.config.zoom.min = 1;
9174
+ const { move, zoom } = leafer.config;
9175
+ move.scroll = 'limit';
9176
+ zoom.min = 1;
9177
+ }
9178
+
9179
+ function block(leafer) {
9180
+ const { config } = leafer;
9181
+ (config.wheel || (config.wheel = {})).preventDefault = false;
9182
+ (config.touch || (config.touch = {})).preventDefault = 'auto';
9104
9183
  }
9105
9184
 
9106
9185
  const debug$2 = Debug.get('LeaferTypeCreator');
9107
9186
  const LeaferTypeCreator = {
9108
9187
  list: {},
9109
9188
  register(name, fn) {
9110
- if (list[name]) {
9111
- debug$2.repeat(name);
9112
- }
9113
- else {
9114
- list[name] = fn;
9115
- }
9189
+ list[name] ? debug$2.repeat(name) : list[name] = fn;
9116
9190
  },
9117
9191
  run(name, leafer) {
9118
9192
  const fn = list[name];
9119
- if (fn) {
9120
- fn(leafer);
9121
- }
9122
- else {
9123
- debug$2.error('no', name);
9124
- }
9193
+ fn && fn(leafer);
9125
9194
  }
9126
9195
  };
9127
9196
  const { list, register } = LeaferTypeCreator;
9128
- register('draw', () => { });
9129
- register('custom', () => { });
9130
9197
  register('design', addInteractionWindow);
9131
9198
  register('document', document);
9199
+ register('block', block);
9132
9200
 
9133
9201
  const leafer = Leafer.prototype;
9134
9202
  leafer.initType = function (type) {
@@ -9317,7 +9385,13 @@ const InteractionHelper = {
9317
9385
  find.add(list[i]);
9318
9386
  }
9319
9387
  return find;
9320
- }
9388
+ },
9389
+ pathCanDrag(path) {
9390
+ return path && path.list.some(item => item.draggable || item.editable || (!item.isLeafer && item.hasEvent(DragEvent.DRAG)));
9391
+ },
9392
+ pathHasOutside(path) {
9393
+ return path && path.list.some(item => item.isOutside);
9394
+ },
9321
9395
  };
9322
9396
  const I = InteractionHelper;
9323
9397
 
@@ -9627,15 +9701,18 @@ const config = {
9627
9701
  swipeDistance: 20,
9628
9702
  preventDefaultMenu: true
9629
9703
  },
9704
+ touch: {
9705
+ preventDefault: true
9706
+ },
9630
9707
  cursor: true,
9631
9708
  keyEvent: true
9632
9709
  };
9633
9710
 
9634
- const { pathHasEventType, getMoveEventData, getZoomEventData, getRotateEventData } = InteractionHelper;
9711
+ const { pathHasEventType, getMoveEventData, getZoomEventData, getRotateEventData, pathCanDrag, pathHasOutside } = InteractionHelper;
9635
9712
  class InteractionBase {
9636
9713
  get dragging() { return this.dragger.dragging; }
9637
9714
  get transforming() { return this.transformer.transforming; }
9638
- get moveMode() { return this.config.move.drag || this.isHoldSpaceKey || this.isHoldMiddleKey || (this.isHoldRightKey && this.dragger.moving) || this.isDragEmpty; }
9715
+ get moveMode() { return this.config.move.drag === true || this.isHoldSpaceKey || this.isHoldMiddleKey || (this.isHoldRightKey && this.dragger.moving) || this.isDragEmpty; }
9639
9716
  get canHover() { return this.config.pointer.hover && !this.config.mobile; }
9640
9717
  get isDragEmpty() { return this.config.move.dragEmpty && this.isRootPath(this.hoverData) && (!this.downData || this.isRootPath(this.downData)); }
9641
9718
  get isMobileDragEmpty() { return this.config.move.dragEmpty && !this.canHover && this.downData && this.isTreePath(this.downData); }
@@ -9644,7 +9721,7 @@ class InteractionBase {
9644
9721
  get isHoldSpaceKey() { return this.config.move.holdSpaceKey && Keyboard.isHoldSpaceKey(); }
9645
9722
  get hitRadius() { return this.config.pointer.hitRadius; }
9646
9723
  constructor(target, canvas, selector, userConfig) {
9647
- this.config = config;
9724
+ this.config = DataHelper.clone(config);
9648
9725
  this.tapCount = 0;
9649
9726
  this.downKeyMap = {};
9650
9727
  this.target = target;
@@ -9896,11 +9973,11 @@ class InteractionBase {
9896
9973
  return app.editor && (!data.path.has(app.editor) && data.path.has(app.tree) && !data.target.syncEventer);
9897
9974
  }
9898
9975
  checkPath(data, useDefaultPath) {
9899
- if (useDefaultPath || this.canMove(data))
9976
+ if (useDefaultPath || (this.moveMode && !pathHasOutside(data.path)))
9900
9977
  data.path = this.defaultPath;
9901
9978
  }
9902
9979
  canMove(data) {
9903
- return this.moveMode && data && data.path.list.every(item => !item.isOutside);
9980
+ return data && (this.moveMode || (this.config.move.drag === 'auto' && !pathCanDrag(data.path))) && !pathHasOutside(data.path);
9904
9981
  }
9905
9982
  isDrag(leaf) {
9906
9983
  return this.dragger.getList().has(leaf);
@@ -10595,10 +10672,13 @@ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, al
10595
10672
  const { get: get$2, translate } = MatrixHelper;
10596
10673
  const tempBox = new Bounds();
10597
10674
  const tempPoint = {};
10675
+ const tempScaleData = {};
10598
10676
  function createData(leafPaint, image, paint, box) {
10599
- const { blendMode } = paint;
10677
+ const { blendMode, sync } = paint;
10600
10678
  if (blendMode)
10601
10679
  leafPaint.blendMode = blendMode;
10680
+ if (sync)
10681
+ leafPaint.sync = sync;
10602
10682
  leafPaint.data = getPatternData(paint, box, image);
10603
10683
  }
10604
10684
  function getPatternData(paint, box, image) {
@@ -10618,13 +10698,10 @@ function getPatternData(paint, box, image) {
10618
10698
  x += (box.width - width * scaleX) / 2, y += (box.height - height * scaleY) / 2;
10619
10699
  }
10620
10700
  }
10621
- else if (size) {
10622
- scaleX = (typeof size === 'number' ? size : size.width) / width;
10623
- scaleY = (typeof size === 'number' ? size : size.height) / height;
10624
- }
10625
- else if (scale) {
10626
- scaleX = typeof scale === 'number' ? scale : scale.x;
10627
- scaleY = typeof scale === 'number' ? scale : scale.y;
10701
+ else if (scale || size) {
10702
+ MathHelper.getScaleData(scale, size, image, tempScaleData);
10703
+ scaleX = tempScaleData.scaleX;
10704
+ scaleY = tempScaleData.scaleY;
10628
10705
  }
10629
10706
  if (align) {
10630
10707
  const imageBounds = { x, y, width: swapWidth, height: swapHeight };
@@ -10863,7 +10940,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
10863
10940
  return true;
10864
10941
  }
10865
10942
  else {
10866
- if (!paint.style || Export.running) {
10943
+ if (!paint.style || paint.sync || Export.running) {
10867
10944
  createPattern(ui, paint, canvas.pixelRatio);
10868
10945
  }
10869
10946
  else {
@@ -11733,6 +11810,7 @@ const ExportModule = {
11733
11810
  export(leaf, filename, options) {
11734
11811
  this.running = true;
11735
11812
  const fileType = FileHelper.fileType(filename);
11813
+ const isDownload = filename.includes('.');
11736
11814
  options = FileHelper.getExportOptions(options);
11737
11815
  return addTask((success) => new Promise((resolve) => {
11738
11816
  const over = (result) => {
@@ -11742,19 +11820,13 @@ const ExportModule = {
11742
11820
  };
11743
11821
  const { toURL } = Platform;
11744
11822
  const { download } = Platform.origin;
11745
- if (filename === 'json') {
11746
- return over({ data: leaf.toJSON(options.json) });
11823
+ if (fileType === 'json') {
11824
+ isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
11825
+ return over({ data: isDownload ? true : leaf.toJSON(options.json) });
11747
11826
  }
11748
- else if (fileType === 'json') {
11749
- download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
11750
- return over({ data: true });
11751
- }
11752
- if (filename === 'svg') {
11753
- return over({ data: leaf.toSVG() });
11754
- }
11755
- else if (fileType === 'svg') {
11756
- download(toURL(leaf.toSVG(), 'svg'), filename);
11757
- return over({ data: true });
11827
+ if (fileType === 'svg') {
11828
+ isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
11829
+ return over({ data: isDownload ? true : leaf.toSVG() });
11758
11830
  }
11759
11831
  const { leafer } = leaf;
11760
11832
  if (leafer) {
@@ -11763,14 +11835,8 @@ const ExportModule = {
11763
11835
  let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
11764
11836
  const { worldTransform, isLeafer, isFrame } = leaf;
11765
11837
  const { slice, trim, onCanvas } = options;
11766
- let scale = options.scale || 1;
11767
- let pixelRatio = options.pixelRatio || 1;
11768
11838
  const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
11769
11839
  const contextSettings = options.contextSettings || leafer.config.contextSettings;
11770
- if (leaf.isApp) {
11771
- scale *= pixelRatio;
11772
- pixelRatio = leaf.app.pixelRatio;
11773
- }
11774
11840
  const screenshot = options.screenshot || leaf.isApp;
11775
11841
  const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
11776
11842
  const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
@@ -11804,9 +11870,17 @@ const ExportModule = {
11804
11870
  }
11805
11871
  renderBounds = leaf.getBounds('render', relative);
11806
11872
  }
11807
- const { x, y, width, height } = new Bounds(renderBounds).scale(scale);
11873
+ const scaleData = { scaleX: 1, scaleY: 1 };
11874
+ MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
11875
+ let pixelRatio = options.pixelRatio || 1;
11876
+ if (leaf.isApp) {
11877
+ scaleData.scaleX *= pixelRatio;
11878
+ scaleData.scaleY *= pixelRatio;
11879
+ pixelRatio = leaf.app.pixelRatio;
11880
+ }
11881
+ const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
11882
+ const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
11808
11883
  let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
11809
- const renderOptions = { matrix: matrix.scale(1 / scale).invert().translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) };
11810
11884
  let sliceLeaf;
11811
11885
  if (slice) {
11812
11886
  sliceLeaf = leaf;
@@ -11916,4 +11990,4 @@ Object.assign(Creator, {
11916
11990
  });
11917
11991
  useCanvas();
11918
11992
 
11919
- export { AlignHelper, AnimateEvent, Answer, App, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, Cursor, DataHelper, Debug, Direction4, Direction9, DragEvent, DropEvent, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Export, FileHelper, Frame, FrameData, Group, GroupData, HitCanvasManager, Image, ImageData, ImageEvent, ImageManager, IncrementId, InteractionBase, InteractionHelper, KeyEvent, Keyboard, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, LeaferTypeCreator, Line, LineData, MathHelper, Matrix, MatrixHelper, MoveEvent, MultiTouchHelper, 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, PointerButton, PointerEvent, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, RotateEvent, Run, Selector, Star, StarData, State, StringNumberMap, SwipeEvent, TaskItem, TaskProcessor, Text, TextConvert, TextData, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIEvent, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, ZoomEvent, addInteractionWindow, affectRenderBoundsType, affectStrokeBoundsType, arrowType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, effectType, emptyData, eraserType, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, inviteCode, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, 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 };
11993
+ export { AlignHelper, AnimateEvent, Answer, App, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert, Creator, Cursor, DataHelper, Debug, Direction4, Direction9, DragEvent, DropEvent, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Export, FileHelper, Frame, FrameData, Group, GroupData, HitCanvasManager, Image, ImageData, ImageEvent, ImageManager, IncrementId, InteractionBase, InteractionHelper, KeyEvent, Keyboard, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, LeaferTypeCreator, Line, LineData, MathHelper, Matrix, MatrixHelper, MoveEvent, MultiTouchHelper, MyDragEvent, MyImage, MyPointerEvent, 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, PointerButton, PointerEvent, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, RotateEvent, Run, Selector, Star, StarData, State, StringNumberMap, SwipeEvent, TaskItem, TaskProcessor, Text, TextConvert, TextData, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIEvent, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, ZoomEvent, addInteractionWindow, affectRenderBoundsType, affectStrokeBoundsType, arrowType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, doBoundsType, doStrokeType, effectType, emptyData, eraserType, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, inviteCode, layoutProcessor, maskType, naturalBoundsType, opacityType, pathInputType, pathType, pen, positionType, 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 };