leafer-ui 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
  }
@@ -7111,6 +7148,11 @@ class BoxData extends GroupData {
7111
7148
  }
7112
7149
 
7113
7150
  class LeaferData extends GroupData {
7151
+ __getInputData() {
7152
+ const data = super.__getInputData();
7153
+ canvasSizeAttrs.forEach(key => delete data[key]);
7154
+ return data;
7155
+ }
7114
7156
  }
7115
7157
 
7116
7158
  class FrameData extends BoxData {
@@ -7188,6 +7230,11 @@ class ImageData extends RectData {
7188
7230
  }
7189
7231
 
7190
7232
  class CanvasData extends RectData {
7233
+ __getInputData() {
7234
+ const data = super.__getInputData();
7235
+ data.url = this.__leaf.canvas.toDataURL('image/png');
7236
+ return data;
7237
+ }
7191
7238
  }
7192
7239
 
7193
7240
  const UIBounds = {
@@ -8100,6 +8147,13 @@ let Leafer = Leafer_1 = class Leafer extends Group {
8100
8147
  getWorldPointByClient(clientPoint, updateClient) {
8101
8148
  return this.interaction && this.interaction.getLocal(clientPoint, updateClient);
8102
8149
  }
8150
+ getPagePointByClient(clientPoint, updateClient) {
8151
+ return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient));
8152
+ }
8153
+ updateClientBounds() {
8154
+ this.canvas && this.canvas.updateClientBounds();
8155
+ }
8156
+ receiveEvent(_event) { }
8103
8157
  __checkUpdateLayout() {
8104
8158
  this.__layout.update();
8105
8159
  }
@@ -8183,7 +8237,7 @@ Rect = __decorate([
8183
8237
  const rect$1 = Rect.prototype;
8184
8238
  const group$1 = Group.prototype;
8185
8239
  const childrenRenderBounds = {};
8186
- const { copy: copy$3, add, includes: includes$1 } = BoundsHelper;
8240
+ const { copy: copy$3, add, includes: includes$1, copyAndSpread: copyAndSpread$1 } = BoundsHelper;
8187
8241
  let Box = class Box extends Group {
8188
8242
  get __tag() { return 'Box'; }
8189
8243
  get isBranchLeaf() { return true; }
@@ -8197,20 +8251,23 @@ let Box = class Box extends Group {
8197
8251
  return this.__updateRectRenderSpread() || -1;
8198
8252
  }
8199
8253
  __updateRectBoxBounds() { }
8200
- __updateBoxBounds() {
8254
+ __updateBoxBounds(secondLayout) {
8201
8255
  const data = this.__;
8202
8256
  if (this.children.length) {
8203
8257
  if (data.__autoSide) {
8204
8258
  if (this.leafer && this.leafer.ready)
8205
8259
  this.leafer.layouter.addExtra(this);
8206
8260
  super.__updateBoxBounds();
8261
+ const { boxBounds } = this.__layout;
8207
8262
  if (!data.__autoSize) {
8208
- const b = this.__layout.boxBounds;
8209
- if (!data.__autoWidth)
8210
- b.height += b.y, b.width = data.width, b.x = b.y = 0;
8211
- if (!data.__autoHeight)
8212
- b.width += b.x, b.height = data.height, b.y = b.x = 0;
8263
+ if (data.__autoWidth)
8264
+ boxBounds.width += boxBounds.x, boxBounds.height = data.height, boxBounds.y = boxBounds.x = 0;
8265
+ else
8266
+ boxBounds.height += boxBounds.y, boxBounds.width = data.width, boxBounds.x = boxBounds.y = 0;
8213
8267
  }
8268
+ if (secondLayout && data.flow && data.padding)
8269
+ copyAndSpread$1(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'));
8270
+ this.__updateNaturalSize();
8214
8271
  }
8215
8272
  else {
8216
8273
  this.__updateRectBoxBounds();
@@ -8230,13 +8287,13 @@ let Box = class Box extends Group {
8230
8287
  super.__updateRenderBounds();
8231
8288
  copy$3(childrenRenderBounds, renderBounds);
8232
8289
  this.__updateRectRenderBounds();
8233
- isOverflow = !includes$1(renderBounds, childrenRenderBounds) || undefined;
8290
+ isOverflow = !includes$1(renderBounds, childrenRenderBounds) || !this.pathInputed || !this.__.cornerRadius;
8234
8291
  }
8235
8292
  else {
8236
8293
  this.__updateRectRenderBounds();
8237
8294
  }
8238
8295
  this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
8239
- if (isOverflow && !(this.__.__drawAfterFill = this.__.overflow === 'hide'))
8296
+ if (!(this.__.__drawAfterFill = this.__.overflow === 'hide') && isOverflow)
8240
8297
  add(renderBounds, childrenRenderBounds);
8241
8298
  }
8242
8299
  __updateRectRenderBounds() { }
@@ -8570,14 +8627,26 @@ __decorate([
8570
8627
  Image$1 = __decorate([
8571
8628
  registerUI()
8572
8629
  ], Image$1);
8630
+ const MyImage = Image$1;
8573
8631
 
8574
8632
  let Canvas = class Canvas extends Rect {
8575
8633
  get __tag() { return 'Canvas'; }
8634
+ get ready() { return !this.url; }
8576
8635
  constructor(data) {
8577
8636
  super(data);
8578
8637
  this.canvas = Creator.canvas(this.__);
8579
8638
  this.context = this.canvas.context;
8580
8639
  this.__.__isCanvas = this.__.__drawAfterFill = true;
8640
+ if (data && data.url)
8641
+ this.drawImage(data.url);
8642
+ }
8643
+ drawImage(url) {
8644
+ new LeaferImage({ url }).load((image) => {
8645
+ this.context.drawImage(image.view, 0, 0);
8646
+ this.url = undefined;
8647
+ this.paint();
8648
+ this.emitEvent(new ImageEvent(ImageEvent.LOADED, { image }));
8649
+ });
8581
8650
  }
8582
8651
  draw(ui, offset, scale, rotation) {
8583
8652
  ui.__layout.update();
@@ -8636,7 +8705,7 @@ __decorate([
8636
8705
  resizeType(100)
8637
8706
  ], Canvas.prototype, "height", void 0);
8638
8707
  __decorate([
8639
- resizeType(Platform.devicePixelRatio)
8708
+ resizeType(1)
8640
8709
  ], Canvas.prototype, "pixelRatio", void 0);
8641
8710
  __decorate([
8642
8711
  resizeType(true)
@@ -8660,13 +8729,13 @@ let Text = class Text extends UI {
8660
8729
  super(data);
8661
8730
  }
8662
8731
  __drawHitPath(canvas) {
8663
- const { __lineHeight, __baseLine, __textDrawData: data } = this.__;
8732
+ const { __lineHeight, fontSize, __baseLine, __textDrawData: data } = this.__;
8664
8733
  canvas.beginPath();
8665
8734
  if (this.__.__letterSpacing < 0) {
8666
8735
  this.__drawPathByData(canvas);
8667
8736
  }
8668
8737
  else {
8669
- data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight));
8738
+ data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight));
8670
8739
  }
8671
8740
  }
8672
8741
  __drawPathByData(drawer, _data) {
@@ -8859,7 +8928,8 @@ let Pen = class Pen extends Group {
8859
8928
  drawPoints(_points, _curve, _close) { return this; }
8860
8929
  clearPath() { return this; }
8861
8930
  paint() {
8862
- this.pathElement.forceUpdate('path');
8931
+ if (!this.pathElement.__layout.boxChanged)
8932
+ this.pathElement.forceUpdate('path');
8863
8933
  }
8864
8934
  };
8865
8935
  __decorate([
@@ -8869,7 +8939,7 @@ __decorate([
8869
8939
  penPathType()
8870
8940
  ], Pen.prototype, "path", void 0);
8871
8941
  Pen = __decorate([
8872
- useModule(PathCreator, ['set', 'beginPath', 'path']),
8942
+ useModule(PathCreator, ['set', 'beginPath', 'path', 'paint']),
8873
8943
  registerUI()
8874
8944
  ], Pen);
8875
8945
  function penPathType() {
@@ -9092,6 +9162,7 @@ PointerEvent.MENU_TAP = 'pointer.menu_tap';
9092
9162
  PointerEvent = __decorate([
9093
9163
  registerUIEvent()
9094
9164
  ], PointerEvent);
9165
+ const MyPointerEvent = PointerEvent;
9095
9166
 
9096
9167
  const move = {};
9097
9168
  let DragEvent = class DragEvent extends PointerEvent {
@@ -9191,6 +9262,7 @@ DragEvent.LEAVE = 'drag.leave';
9191
9262
  DragEvent = __decorate([
9192
9263
  registerUIEvent()
9193
9264
  ], DragEvent);
9265
+ const MyDragEvent = DragEvent;
9194
9266
 
9195
9267
  let DropEvent = class DropEvent extends PointerEvent {
9196
9268
  static setList(data) {
@@ -9272,36 +9344,32 @@ function addInteractionWindow(leafer) {
9272
9344
 
9273
9345
  function document$1(leafer) {
9274
9346
  addInteractionWindow(leafer);
9275
- leafer.config.move.scroll = 'limit';
9276
- leafer.config.zoom.min = 1;
9347
+ const { move, zoom } = leafer.config;
9348
+ move.scroll = 'limit';
9349
+ zoom.min = 1;
9350
+ }
9351
+
9352
+ function block(leafer) {
9353
+ const { config } = leafer;
9354
+ (config.wheel || (config.wheel = {})).preventDefault = false;
9355
+ (config.touch || (config.touch = {})).preventDefault = 'auto';
9277
9356
  }
9278
9357
 
9279
9358
  const debug$2 = Debug.get('LeaferTypeCreator');
9280
9359
  const LeaferTypeCreator = {
9281
9360
  list: {},
9282
9361
  register(name, fn) {
9283
- if (list[name]) {
9284
- debug$2.repeat(name);
9285
- }
9286
- else {
9287
- list[name] = fn;
9288
- }
9362
+ list[name] ? debug$2.repeat(name) : list[name] = fn;
9289
9363
  },
9290
9364
  run(name, leafer) {
9291
9365
  const fn = list[name];
9292
- if (fn) {
9293
- fn(leafer);
9294
- }
9295
- else {
9296
- debug$2.error('no', name);
9297
- }
9366
+ fn && fn(leafer);
9298
9367
  }
9299
9368
  };
9300
9369
  const { list, register } = LeaferTypeCreator;
9301
- register('draw', () => { });
9302
- register('custom', () => { });
9303
9370
  register('design', addInteractionWindow);
9304
9371
  register('document', document$1);
9372
+ register('block', block);
9305
9373
 
9306
9374
  const leafer = Leafer.prototype;
9307
9375
  leafer.initType = function (type) {
@@ -9490,7 +9558,13 @@ const InteractionHelper = {
9490
9558
  find.add(list[i]);
9491
9559
  }
9492
9560
  return find;
9493
- }
9561
+ },
9562
+ pathCanDrag(path) {
9563
+ return path && path.list.some(item => item.draggable || item.editable || (!item.isLeafer && item.hasEvent(DragEvent.DRAG)));
9564
+ },
9565
+ pathHasOutside(path) {
9566
+ return path && path.list.some(item => item.isOutside);
9567
+ },
9494
9568
  };
9495
9569
  const I = InteractionHelper;
9496
9570
 
@@ -9800,15 +9874,18 @@ const config = {
9800
9874
  swipeDistance: 20,
9801
9875
  preventDefaultMenu: true
9802
9876
  },
9877
+ touch: {
9878
+ preventDefault: true
9879
+ },
9803
9880
  cursor: true,
9804
9881
  keyEvent: true
9805
9882
  };
9806
9883
 
9807
- const { pathHasEventType, getMoveEventData: getMoveEventData$1, getZoomEventData: getZoomEventData$1, getRotateEventData: getRotateEventData$1 } = InteractionHelper;
9884
+ const { pathHasEventType, getMoveEventData: getMoveEventData$1, getZoomEventData: getZoomEventData$1, getRotateEventData: getRotateEventData$1, pathCanDrag: pathCanDrag$1, pathHasOutside } = InteractionHelper;
9808
9885
  class InteractionBase {
9809
9886
  get dragging() { return this.dragger.dragging; }
9810
9887
  get transforming() { return this.transformer.transforming; }
9811
- get moveMode() { return this.config.move.drag || this.isHoldSpaceKey || this.isHoldMiddleKey || (this.isHoldRightKey && this.dragger.moving) || this.isDragEmpty; }
9888
+ get moveMode() { return this.config.move.drag === true || this.isHoldSpaceKey || this.isHoldMiddleKey || (this.isHoldRightKey && this.dragger.moving) || this.isDragEmpty; }
9812
9889
  get canHover() { return this.config.pointer.hover && !this.config.mobile; }
9813
9890
  get isDragEmpty() { return this.config.move.dragEmpty && this.isRootPath(this.hoverData) && (!this.downData || this.isRootPath(this.downData)); }
9814
9891
  get isMobileDragEmpty() { return this.config.move.dragEmpty && !this.canHover && this.downData && this.isTreePath(this.downData); }
@@ -9817,7 +9894,7 @@ class InteractionBase {
9817
9894
  get isHoldSpaceKey() { return this.config.move.holdSpaceKey && Keyboard.isHoldSpaceKey(); }
9818
9895
  get hitRadius() { return this.config.pointer.hitRadius; }
9819
9896
  constructor(target, canvas, selector, userConfig) {
9820
- this.config = config;
9897
+ this.config = DataHelper.clone(config);
9821
9898
  this.tapCount = 0;
9822
9899
  this.downKeyMap = {};
9823
9900
  this.target = target;
@@ -10069,11 +10146,11 @@ class InteractionBase {
10069
10146
  return app.editor && (!data.path.has(app.editor) && data.path.has(app.tree) && !data.target.syncEventer);
10070
10147
  }
10071
10148
  checkPath(data, useDefaultPath) {
10072
- if (useDefaultPath || this.canMove(data))
10149
+ if (useDefaultPath || (this.moveMode && !pathHasOutside(data.path)))
10073
10150
  data.path = this.defaultPath;
10074
10151
  }
10075
10152
  canMove(data) {
10076
- return this.moveMode && data && data.path.list.every(item => !item.isOutside);
10153
+ return data && (this.moveMode || (this.config.move.drag === 'auto' && !pathCanDrag$1(data.path))) && !pathHasOutside(data.path);
10077
10154
  }
10078
10155
  isDrag(leaf) {
10079
10156
  return this.dragger.getList().has(leaf);
@@ -10491,7 +10568,7 @@ const KeyEventHelper = {
10491
10568
  }
10492
10569
  };
10493
10570
 
10494
- const { getMoveEventData, getZoomEventData, getRotateEventData } = InteractionHelper;
10571
+ const { getMoveEventData, getZoomEventData, getRotateEventData, pathCanDrag } = InteractionHelper;
10495
10572
  class Interaction extends InteractionBase {
10496
10573
  __listenEvents() {
10497
10574
  super.__listenEvents();
@@ -10624,7 +10701,11 @@ class Interaction extends InteractionBase {
10624
10701
  this.pointerCancel();
10625
10702
  }
10626
10703
  onTouchStart(e) {
10627
- e.preventDefault();
10704
+ const touch = PointerEventHelper.getTouch(e);
10705
+ const local = this.getLocal(touch, true);
10706
+ const { preventDefault } = this.config.touch;
10707
+ if (preventDefault === true || (preventDefault === 'auto' && pathCanDrag(this.findPath(local))))
10708
+ e.preventDefault();
10628
10709
  this.multiTouchStart(e);
10629
10710
  if (this.usePointer)
10630
10711
  return;
@@ -10633,8 +10714,7 @@ class Interaction extends InteractionBase {
10633
10714
  this.touchTimer = 0;
10634
10715
  }
10635
10716
  this.useTouch = true;
10636
- const touch = PointerEventHelper.getTouch(e);
10637
- this.pointerDown(PointerEventHelper.convertTouch(e, this.getLocal(touch, true)));
10717
+ this.pointerDown(PointerEventHelper.convertTouch(e, local));
10638
10718
  }
10639
10719
  onTouchMove(e) {
10640
10720
  this.multiTouchMove(e);
@@ -11117,10 +11197,13 @@ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, al
11117
11197
  const { get: get$2, translate } = MatrixHelper;
11118
11198
  const tempBox = new Bounds();
11119
11199
  const tempPoint = {};
11200
+ const tempScaleData = {};
11120
11201
  function createData(leafPaint, image, paint, box) {
11121
- const { blendMode } = paint;
11202
+ const { blendMode, sync } = paint;
11122
11203
  if (blendMode)
11123
11204
  leafPaint.blendMode = blendMode;
11205
+ if (sync)
11206
+ leafPaint.sync = sync;
11124
11207
  leafPaint.data = getPatternData(paint, box, image);
11125
11208
  }
11126
11209
  function getPatternData(paint, box, image) {
@@ -11140,13 +11223,10 @@ function getPatternData(paint, box, image) {
11140
11223
  x += (box.width - width * scaleX) / 2, y += (box.height - height * scaleY) / 2;
11141
11224
  }
11142
11225
  }
11143
- else if (size) {
11144
- scaleX = (typeof size === 'number' ? size : size.width) / width;
11145
- scaleY = (typeof size === 'number' ? size : size.height) / height;
11146
- }
11147
- else if (scale) {
11148
- scaleX = typeof scale === 'number' ? scale : scale.x;
11149
- scaleY = typeof scale === 'number' ? scale : scale.y;
11226
+ else if (scale || size) {
11227
+ MathHelper.getScaleData(scale, size, image, tempScaleData);
11228
+ scaleX = tempScaleData.scaleX;
11229
+ scaleY = tempScaleData.scaleY;
11150
11230
  }
11151
11231
  if (align) {
11152
11232
  const imageBounds = { x, y, width: swapWidth, height: swapHeight };
@@ -11385,7 +11465,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
11385
11465
  return true;
11386
11466
  }
11387
11467
  else {
11388
- if (!paint.style || Export.running) {
11468
+ if (!paint.style || paint.sync || Export.running) {
11389
11469
  createPattern(ui, paint, canvas.pixelRatio);
11390
11470
  }
11391
11471
  else {
@@ -12255,6 +12335,7 @@ const ExportModule = {
12255
12335
  export(leaf, filename, options) {
12256
12336
  this.running = true;
12257
12337
  const fileType = FileHelper.fileType(filename);
12338
+ const isDownload = filename.includes('.');
12258
12339
  options = FileHelper.getExportOptions(options);
12259
12340
  return addTask((success) => new Promise((resolve) => {
12260
12341
  const over = (result) => {
@@ -12264,19 +12345,13 @@ const ExportModule = {
12264
12345
  };
12265
12346
  const { toURL } = Platform;
12266
12347
  const { download } = Platform.origin;
12267
- if (filename === 'json') {
12268
- return over({ data: leaf.toJSON(options.json) });
12269
- }
12270
- else if (fileType === 'json') {
12271
- download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
12272
- return over({ data: true });
12348
+ if (fileType === 'json') {
12349
+ isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
12350
+ return over({ data: isDownload ? true : leaf.toJSON(options.json) });
12273
12351
  }
12274
- if (filename === 'svg') {
12275
- return over({ data: leaf.toSVG() });
12276
- }
12277
- else if (fileType === 'svg') {
12278
- download(toURL(leaf.toSVG(), 'svg'), filename);
12279
- return over({ data: true });
12352
+ if (fileType === 'svg') {
12353
+ isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
12354
+ return over({ data: isDownload ? true : leaf.toSVG() });
12280
12355
  }
12281
12356
  const { leafer } = leaf;
12282
12357
  if (leafer) {
@@ -12285,14 +12360,8 @@ const ExportModule = {
12285
12360
  let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
12286
12361
  const { worldTransform, isLeafer, isFrame } = leaf;
12287
12362
  const { slice, trim, onCanvas } = options;
12288
- let scale = options.scale || 1;
12289
- let pixelRatio = options.pixelRatio || 1;
12290
12363
  const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
12291
12364
  const contextSettings = options.contextSettings || leafer.config.contextSettings;
12292
- if (leaf.isApp) {
12293
- scale *= pixelRatio;
12294
- pixelRatio = leaf.app.pixelRatio;
12295
- }
12296
12365
  const screenshot = options.screenshot || leaf.isApp;
12297
12366
  const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
12298
12367
  const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
@@ -12326,9 +12395,17 @@ const ExportModule = {
12326
12395
  }
12327
12396
  renderBounds = leaf.getBounds('render', relative);
12328
12397
  }
12329
- const { x, y, width, height } = new Bounds(renderBounds).scale(scale);
12398
+ const scaleData = { scaleX: 1, scaleY: 1 };
12399
+ MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
12400
+ let pixelRatio = options.pixelRatio || 1;
12401
+ if (leaf.isApp) {
12402
+ scaleData.scaleX *= pixelRatio;
12403
+ scaleData.scaleY *= pixelRatio;
12404
+ pixelRatio = leaf.app.pixelRatio;
12405
+ }
12406
+ const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
12407
+ const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
12330
12408
  let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
12331
- const renderOptions = { matrix: matrix.scale(1 / scale).invert().translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) };
12332
12409
  let sliceLeaf;
12333
12410
  if (slice) {
12334
12411
  sliceLeaf = leaf;
@@ -12438,4 +12515,4 @@ Object.assign(Creator, {
12438
12515
  });
12439
12516
  useCanvas();
12440
12517
 
12441
- 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$1 as Image, ImageData, ImageEvent, ImageManager, IncrementId, Interaction, 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 };
12518
+ 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$1 as Image, ImageData, ImageEvent, ImageManager, IncrementId, Interaction, 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 };