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.
package/dist/web.js CHANGED
@@ -114,6 +114,19 @@ var LeaferUI = (function (exports) {
114
114
  const a = maxLength ? pow$1(10, maxLength) : 1000000000000;
115
115
  num = round(num * a) / a;
116
116
  return num === -0 ? 0 : num;
117
+ },
118
+ getScaleData(scale, size, originSize, scaleData) {
119
+ if (!scaleData)
120
+ scaleData = {};
121
+ if (size) {
122
+ scaleData.scaleX = (typeof size === 'number' ? size : size.width) / originSize.width;
123
+ scaleData.scaleY = (typeof size === 'number' ? size : size.height) / originSize.height;
124
+ }
125
+ else if (scale) {
126
+ scaleData.scaleX = typeof scale === 'number' ? scale : scale.x;
127
+ scaleData.scaleY = typeof scale === 'number' ? scale : scale.y;
128
+ }
129
+ return scaleData;
117
130
  }
118
131
  };
119
132
  const OneRadian = PI$4 / 180;
@@ -412,7 +425,7 @@ var LeaferUI = (function (exports) {
412
425
  };
413
426
  const M$6 = MatrixHelper;
414
427
 
415
- const { toInnerPoint: toInnerPoint$2, toOuterPoint: toOuterPoint$2 } = MatrixHelper;
428
+ const { toInnerPoint: toInnerPoint$2, toOuterPoint: toOuterPoint$3 } = MatrixHelper;
416
429
  const { sin: sin$4, cos: cos$4, abs: abs$4, sqrt: sqrt$2, atan2: atan2$2, min: min$1, PI: PI$3 } = Math;
417
430
  const PointHelper = {
418
431
  defaultPoint: getPointData(),
@@ -468,7 +481,7 @@ var LeaferUI = (function (exports) {
468
481
  tempToOuterOf(t, matrix) {
469
482
  const { tempPoint: temp } = P$5;
470
483
  copy$b(temp, t);
471
- toOuterPoint$2(matrix, temp, temp);
484
+ toOuterPoint$3(matrix, temp, temp);
472
485
  return temp;
473
486
  },
474
487
  tempToInnerRadiusPointOf(t, matrix) {
@@ -487,7 +500,7 @@ var LeaferUI = (function (exports) {
487
500
  toInnerPoint$2(matrix, t, to);
488
501
  },
489
502
  toOuterOf(t, matrix, to) {
490
- toOuterPoint$2(matrix, t, to);
503
+ toOuterPoint$3(matrix, t, to);
491
504
  },
492
505
  getCenter(t, to) {
493
506
  return { x: t.x + (to.x - t.x) / 2, y: t.y + (to.y - t.y) / 2 };
@@ -767,7 +780,7 @@ var LeaferUI = (function (exports) {
767
780
  const { addPoint: addPoint$4 } = TwoPointBoundsHelper;
768
781
 
769
782
  const { tempPointBounds: tempPointBounds$1, setPoint: setPoint$3, addPoint: addPoint$3, toBounds: toBounds$4 } = TwoPointBoundsHelper;
770
- const { toOuterPoint: toOuterPoint$1 } = MatrixHelper;
783
+ const { toOuterPoint: toOuterPoint$2 } = MatrixHelper;
771
784
  const { float, fourNumber } = MathHelper;
772
785
  const { floor, ceil: ceil$2 } = Math;
773
786
  let right$1, bottom$1, boundsRight, boundsBottom;
@@ -787,17 +800,24 @@ var LeaferUI = (function (exports) {
787
800
  t.width = bounds.width;
788
801
  t.height = bounds.height;
789
802
  },
790
- copyAndSpread(t, bounds, spread, isShrink) {
803
+ copyAndSpread(t, bounds, spread, isShrink, side) {
804
+ const { x, y, width, height } = bounds;
791
805
  if (spread instanceof Array) {
792
806
  const four = fourNumber(spread);
793
807
  isShrink
794
- ? B.set(t, bounds.x + four[3], bounds.y + four[0], bounds.width - four[1] - four[3], bounds.height - four[2] - four[0])
795
- : B.set(t, bounds.x - four[3], bounds.y - four[0], bounds.width + four[1] + four[3], bounds.height + four[2] + four[0]);
808
+ ? B.set(t, x + four[3], y + four[0], width - four[1] - four[3], height - four[2] - four[0])
809
+ : B.set(t, x - four[3], y - four[0], width + four[1] + four[3], height + four[2] + four[0]);
796
810
  }
797
811
  else {
798
812
  if (isShrink)
799
813
  spread = -spread;
800
- B.set(t, bounds.x - spread, bounds.y - spread, bounds.width + spread * 2, bounds.height + spread * 2);
814
+ B.set(t, x - spread, y - spread, width + spread * 2, height + spread * 2);
815
+ }
816
+ if (side) {
817
+ if (side === 'width')
818
+ t.y = y, t.height = height;
819
+ else
820
+ t.x = x, t.width = width;
801
821
  }
802
822
  },
803
823
  minX(t) { return t.width > 0 ? t.x : t.x + t.width; },
@@ -874,16 +894,16 @@ var LeaferUI = (function (exports) {
874
894
  else {
875
895
  point.x = t.x;
876
896
  point.y = t.y;
877
- toOuterPoint$1(matrix, point, toPoint$5);
897
+ toOuterPoint$2(matrix, point, toPoint$5);
878
898
  setPoint$3(tempPointBounds$1, toPoint$5.x, toPoint$5.y);
879
899
  point.x = t.x + t.width;
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.y = t.y + t.height;
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
  point.x = t.x;
886
- toOuterPoint$1(matrix, point, toPoint$5);
906
+ toOuterPoint$2(matrix, point, toPoint$5);
887
907
  addPoint$3(tempPointBounds$1, toPoint$5.x, toPoint$5.y);
888
908
  toBounds$4(tempPointBounds$1, to);
889
909
  }
@@ -897,16 +917,16 @@ var LeaferUI = (function (exports) {
897
917
  const scale = Math.min(baseScale, Math.min(t.width / put.width, t.height / put.height));
898
918
  return new Matrix(scale, 0, 0, scale, -put.x * scale, -put.y * scale);
899
919
  },
900
- getSpread(t, spread) {
920
+ getSpread(t, spread, side) {
901
921
  const n = {};
902
- B.copyAndSpread(n, t, spread);
922
+ B.copyAndSpread(n, t, spread, false, side);
903
923
  return n;
904
924
  },
905
- spread(t, spread) {
906
- B.copyAndSpread(t, t, spread);
925
+ spread(t, spread, side) {
926
+ B.copyAndSpread(t, t, spread, false, side);
907
927
  },
908
- shrink(t, shrink) {
909
- B.copyAndSpread(t, t, shrink, true);
928
+ shrink(t, shrink, side) {
929
+ B.copyAndSpread(t, t, shrink, true, side);
910
930
  },
911
931
  ceil(t) {
912
932
  const { x, y } = t;
@@ -1089,12 +1109,12 @@ var LeaferUI = (function (exports) {
1089
1109
  getFitMatrix(put, baseScale) {
1090
1110
  return BoundsHelper.getFitMatrix(this, put, baseScale);
1091
1111
  }
1092
- spread(fourNumber) {
1093
- BoundsHelper.spread(this, fourNumber);
1112
+ spread(fourNumber, side) {
1113
+ BoundsHelper.spread(this, fourNumber, side);
1094
1114
  return this;
1095
1115
  }
1096
- shrink(fourNumber) {
1097
- BoundsHelper.shrink(this, fourNumber);
1116
+ shrink(fourNumber, side) {
1117
+ BoundsHelper.shrink(this, fourNumber, side);
1098
1118
  return this;
1099
1119
  }
1100
1120
  ceil() {
@@ -2911,60 +2931,75 @@ var LeaferUI = (function (exports) {
2911
2931
  }
2912
2932
  beginPath() {
2913
2933
  beginPath(this.__path);
2934
+ this.paint();
2914
2935
  return this;
2915
2936
  }
2916
2937
  moveTo(x, y) {
2917
2938
  moveTo$4(this.__path, x, y);
2939
+ this.paint();
2918
2940
  return this;
2919
2941
  }
2920
2942
  lineTo(x, y) {
2921
2943
  lineTo$3(this.__path, x, y);
2944
+ this.paint();
2922
2945
  return this;
2923
2946
  }
2924
2947
  bezierCurveTo(x1, y1, x2, y2, x, y) {
2925
2948
  bezierCurveTo(this.__path, x1, y1, x2, y2, x, y);
2949
+ this.paint();
2926
2950
  return this;
2927
2951
  }
2928
2952
  quadraticCurveTo(x1, y1, x, y) {
2929
2953
  quadraticCurveTo(this.__path, x1, y1, x, y);
2954
+ this.paint();
2930
2955
  return this;
2931
2956
  }
2932
2957
  closePath() {
2933
2958
  closePath$3(this.__path);
2959
+ this.paint();
2934
2960
  return this;
2935
2961
  }
2936
2962
  rect(x, y, width, height) {
2937
2963
  rect$2(this.__path, x, y, width, height);
2964
+ this.paint();
2938
2965
  return this;
2939
2966
  }
2940
2967
  roundRect(x, y, width, height, cornerRadius) {
2941
2968
  roundRect$1(this.__path, x, y, width, height, cornerRadius);
2969
+ this.paint();
2942
2970
  return this;
2943
2971
  }
2944
2972
  ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise) {
2945
2973
  ellipse$2(this.__path, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise);
2974
+ this.paint();
2946
2975
  return this;
2947
2976
  }
2948
2977
  arc(x, y, radius, startAngle, endAngle, anticlockwise) {
2949
2978
  arc$1(this.__path, x, y, radius, startAngle, endAngle, anticlockwise);
2979
+ this.paint();
2950
2980
  return this;
2951
2981
  }
2952
2982
  arcTo(x1, y1, x2, y2, radius) {
2953
2983
  arcTo$2(this.__path, x1, y1, x2, y2, radius);
2984
+ this.paint();
2954
2985
  return this;
2955
2986
  }
2956
2987
  drawEllipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise) {
2957
2988
  drawEllipse(this.__path, x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise);
2989
+ this.paint();
2958
2990
  return this;
2959
2991
  }
2960
2992
  drawArc(x, y, radius, startAngle, endAngle, anticlockwise) {
2961
2993
  drawArc(this.__path, x, y, radius, startAngle, endAngle, anticlockwise);
2994
+ this.paint();
2962
2995
  return this;
2963
2996
  }
2964
2997
  drawPoints(points, curve, close) {
2965
2998
  drawPoints$2(this.__path, points, curve, close);
2999
+ this.paint();
2966
3000
  return this;
2967
3001
  }
3002
+ paint() { }
2968
3003
  }
2969
3004
 
2970
3005
  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;
@@ -3986,7 +4021,7 @@ var LeaferUI = (function (exports) {
3986
4021
  };
3987
4022
  }
3988
4023
 
3989
- const { copy: copy$7, toInnerPoint: toInnerPoint$1, scaleOfOuter: scaleOfOuter$2, rotateOfOuter: rotateOfOuter$2, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
4024
+ const { copy: copy$7, toInnerPoint: toInnerPoint$1, toOuterPoint: toOuterPoint$1, scaleOfOuter: scaleOfOuter$2, rotateOfOuter: rotateOfOuter$2, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
3990
4025
  const matrix$1 = {};
3991
4026
  const LeafHelper = {
3992
4027
  updateAllMatrix(leaf, checkAutoLayout, waitAutoLayout) {
@@ -4051,10 +4086,9 @@ var LeaferUI = (function (exports) {
4051
4086
  }
4052
4087
  return true;
4053
4088
  },
4054
- moveWorld(t, x, y = 0) {
4089
+ moveWorld(t, x, y = 0, isInnerPoint) {
4055
4090
  const local = typeof x === 'object' ? Object.assign({}, x) : { x, y };
4056
- if (t.parent)
4057
- toInnerPoint$1(t.parent.worldTransform, local, local, true);
4091
+ isInnerPoint ? toOuterPoint$1(t.localTransform, local, local, true) : (t.parent && toInnerPoint$1(t.parent.worldTransform, local, local, true));
4058
4092
  L.moveLocal(t, local.x, local.y);
4059
4093
  },
4060
4094
  moveLocal(t, x, y = 0) {
@@ -4921,7 +4955,7 @@ var LeaferUI = (function (exports) {
4921
4955
 
4922
4956
  const { updateMatrix: updateMatrix$1, updateAllMatrix: updateAllMatrix$2 } = LeafHelper;
4923
4957
  const { updateBounds: updateBounds$1 } = BranchHelper;
4924
- const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$1, copy: copy$5 } = BoundsHelper;
4958
+ const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$2, copy: copy$5 } = BoundsHelper;
4925
4959
  const { toBounds: toBounds$2 } = PathBounds;
4926
4960
  const LeafBounds = {
4927
4961
  __updateWorldBounds() {
@@ -5022,7 +5056,7 @@ var LeaferUI = (function (exports) {
5022
5056
  updateAllMatrix$2(this);
5023
5057
  updateBounds$1(this, this);
5024
5058
  if (this.__.__autoSide)
5025
- this.__updateBoxBounds();
5059
+ this.__updateBoxBounds(true);
5026
5060
  }
5027
5061
  else {
5028
5062
  updateAllMatrix$2(this);
@@ -5040,11 +5074,11 @@ var LeaferUI = (function (exports) {
5040
5074
  },
5041
5075
  __updateStrokeBounds() {
5042
5076
  const layout = this.__layout;
5043
- copyAndSpread$1(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
5077
+ copyAndSpread$2(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
5044
5078
  },
5045
5079
  __updateRenderBounds() {
5046
5080
  const layout = this.__layout;
5047
- layout.renderSpread > 0 ? copyAndSpread$1(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$5(layout.renderBounds, layout.strokeBounds);
5081
+ layout.renderSpread > 0 ? copyAndSpread$2(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$5(layout.renderBounds, layout.strokeBounds);
5048
5082
  }
5049
5083
  };
5050
5084
 
@@ -5404,6 +5438,9 @@ var LeaferUI = (function (exports) {
5404
5438
  move(x, y) {
5405
5439
  moveLocal(this, x, y);
5406
5440
  }
5441
+ moveInner(x, y) {
5442
+ moveWorld(this, x, y, true);
5443
+ }
5407
5444
  scaleOf(origin, scaleX, scaleY, resize) {
5408
5445
  zoomOfLocal(this, getLocalOrigin(this, origin), scaleX, scaleY, resize);
5409
5446
  }
@@ -7114,6 +7151,11 @@ var LeaferUI = (function (exports) {
7114
7151
  }
7115
7152
 
7116
7153
  class LeaferData extends GroupData {
7154
+ __getInputData() {
7155
+ const data = super.__getInputData();
7156
+ canvasSizeAttrs.forEach(key => delete data[key]);
7157
+ return data;
7158
+ }
7117
7159
  }
7118
7160
 
7119
7161
  class FrameData extends BoxData {
@@ -7191,6 +7233,11 @@ var LeaferUI = (function (exports) {
7191
7233
  }
7192
7234
 
7193
7235
  class CanvasData extends RectData {
7236
+ __getInputData() {
7237
+ const data = super.__getInputData();
7238
+ data.url = this.__leaf.canvas.toDataURL('image/png');
7239
+ return data;
7240
+ }
7194
7241
  }
7195
7242
 
7196
7243
  const UIBounds = {
@@ -8103,6 +8150,13 @@ var LeaferUI = (function (exports) {
8103
8150
  getWorldPointByClient(clientPoint, updateClient) {
8104
8151
  return this.interaction && this.interaction.getLocal(clientPoint, updateClient);
8105
8152
  }
8153
+ getPagePointByClient(clientPoint, updateClient) {
8154
+ return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient));
8155
+ }
8156
+ updateClientBounds() {
8157
+ this.canvas && this.canvas.updateClientBounds();
8158
+ }
8159
+ receiveEvent(_event) { }
8106
8160
  __checkUpdateLayout() {
8107
8161
  this.__layout.update();
8108
8162
  }
@@ -8186,7 +8240,7 @@ var LeaferUI = (function (exports) {
8186
8240
  const rect$1 = exports.Rect.prototype;
8187
8241
  const group$1 = exports.Group.prototype;
8188
8242
  const childrenRenderBounds = {};
8189
- const { copy: copy$3, add, includes: includes$1 } = BoundsHelper;
8243
+ const { copy: copy$3, add, includes: includes$1, copyAndSpread: copyAndSpread$1 } = BoundsHelper;
8190
8244
  exports.Box = class Box extends exports.Group {
8191
8245
  get __tag() { return 'Box'; }
8192
8246
  get isBranchLeaf() { return true; }
@@ -8200,20 +8254,23 @@ var LeaferUI = (function (exports) {
8200
8254
  return this.__updateRectRenderSpread() || -1;
8201
8255
  }
8202
8256
  __updateRectBoxBounds() { }
8203
- __updateBoxBounds() {
8257
+ __updateBoxBounds(secondLayout) {
8204
8258
  const data = this.__;
8205
8259
  if (this.children.length) {
8206
8260
  if (data.__autoSide) {
8207
8261
  if (this.leafer && this.leafer.ready)
8208
8262
  this.leafer.layouter.addExtra(this);
8209
8263
  super.__updateBoxBounds();
8264
+ const { boxBounds } = this.__layout;
8210
8265
  if (!data.__autoSize) {
8211
- const b = this.__layout.boxBounds;
8212
- if (!data.__autoWidth)
8213
- b.height += b.y, b.width = data.width, b.x = b.y = 0;
8214
- if (!data.__autoHeight)
8215
- b.width += b.x, b.height = data.height, b.y = b.x = 0;
8266
+ if (data.__autoWidth)
8267
+ boxBounds.width += boxBounds.x, boxBounds.height = data.height, boxBounds.y = boxBounds.x = 0;
8268
+ else
8269
+ boxBounds.height += boxBounds.y, boxBounds.width = data.width, boxBounds.x = boxBounds.y = 0;
8216
8270
  }
8271
+ if (secondLayout && data.flow && data.padding)
8272
+ copyAndSpread$1(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'));
8273
+ this.__updateNaturalSize();
8217
8274
  }
8218
8275
  else {
8219
8276
  this.__updateRectBoxBounds();
@@ -8233,13 +8290,13 @@ var LeaferUI = (function (exports) {
8233
8290
  super.__updateRenderBounds();
8234
8291
  copy$3(childrenRenderBounds, renderBounds);
8235
8292
  this.__updateRectRenderBounds();
8236
- isOverflow = !includes$1(renderBounds, childrenRenderBounds) || undefined;
8293
+ isOverflow = !includes$1(renderBounds, childrenRenderBounds) || !this.pathInputed || !this.__.cornerRadius;
8237
8294
  }
8238
8295
  else {
8239
8296
  this.__updateRectRenderBounds();
8240
8297
  }
8241
8298
  this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
8242
- if (isOverflow && !(this.__.__drawAfterFill = this.__.overflow === 'hide'))
8299
+ if (!(this.__.__drawAfterFill = this.__.overflow === 'hide') && isOverflow)
8243
8300
  add(renderBounds, childrenRenderBounds);
8244
8301
  }
8245
8302
  __updateRectRenderBounds() { }
@@ -8573,14 +8630,26 @@ var LeaferUI = (function (exports) {
8573
8630
  exports.Image = __decorate([
8574
8631
  registerUI()
8575
8632
  ], exports.Image);
8633
+ const MyImage = exports.Image;
8576
8634
 
8577
8635
  exports.Canvas = class Canvas extends exports.Rect {
8578
8636
  get __tag() { return 'Canvas'; }
8637
+ get ready() { return !this.url; }
8579
8638
  constructor(data) {
8580
8639
  super(data);
8581
8640
  this.canvas = Creator.canvas(this.__);
8582
8641
  this.context = this.canvas.context;
8583
8642
  this.__.__isCanvas = this.__.__drawAfterFill = true;
8643
+ if (data && data.url)
8644
+ this.drawImage(data.url);
8645
+ }
8646
+ drawImage(url) {
8647
+ new LeaferImage({ url }).load((image) => {
8648
+ this.context.drawImage(image.view, 0, 0);
8649
+ this.url = undefined;
8650
+ this.paint();
8651
+ this.emitEvent(new ImageEvent(ImageEvent.LOADED, { image }));
8652
+ });
8584
8653
  }
8585
8654
  draw(ui, offset, scale, rotation) {
8586
8655
  ui.__layout.update();
@@ -8639,7 +8708,7 @@ var LeaferUI = (function (exports) {
8639
8708
  resizeType(100)
8640
8709
  ], exports.Canvas.prototype, "height", void 0);
8641
8710
  __decorate([
8642
- resizeType(Platform.devicePixelRatio)
8711
+ resizeType(1)
8643
8712
  ], exports.Canvas.prototype, "pixelRatio", void 0);
8644
8713
  __decorate([
8645
8714
  resizeType(true)
@@ -8663,13 +8732,13 @@ var LeaferUI = (function (exports) {
8663
8732
  super(data);
8664
8733
  }
8665
8734
  __drawHitPath(canvas) {
8666
- const { __lineHeight, __baseLine, __textDrawData: data } = this.__;
8735
+ const { __lineHeight, fontSize, __baseLine, __textDrawData: data } = this.__;
8667
8736
  canvas.beginPath();
8668
8737
  if (this.__.__letterSpacing < 0) {
8669
8738
  this.__drawPathByData(canvas);
8670
8739
  }
8671
8740
  else {
8672
- data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight));
8741
+ data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight));
8673
8742
  }
8674
8743
  }
8675
8744
  __drawPathByData(drawer, _data) {
@@ -8862,7 +8931,8 @@ var LeaferUI = (function (exports) {
8862
8931
  drawPoints(_points, _curve, _close) { return this; }
8863
8932
  clearPath() { return this; }
8864
8933
  paint() {
8865
- this.pathElement.forceUpdate('path');
8934
+ if (!this.pathElement.__layout.boxChanged)
8935
+ this.pathElement.forceUpdate('path');
8866
8936
  }
8867
8937
  };
8868
8938
  __decorate([
@@ -8872,7 +8942,7 @@ var LeaferUI = (function (exports) {
8872
8942
  penPathType()
8873
8943
  ], exports.Pen.prototype, "path", void 0);
8874
8944
  exports.Pen = __decorate([
8875
- useModule(PathCreator, ['set', 'beginPath', 'path']),
8945
+ useModule(PathCreator, ['set', 'beginPath', 'path', 'paint']),
8876
8946
  registerUI()
8877
8947
  ], exports.Pen);
8878
8948
  function penPathType() {
@@ -9095,6 +9165,7 @@ var LeaferUI = (function (exports) {
9095
9165
  exports.PointerEvent = __decorate([
9096
9166
  registerUIEvent()
9097
9167
  ], exports.PointerEvent);
9168
+ const MyPointerEvent = exports.PointerEvent;
9098
9169
 
9099
9170
  const move = {};
9100
9171
  exports.DragEvent = class DragEvent extends exports.PointerEvent {
@@ -9194,6 +9265,7 @@ var LeaferUI = (function (exports) {
9194
9265
  exports.DragEvent = __decorate([
9195
9266
  registerUIEvent()
9196
9267
  ], exports.DragEvent);
9268
+ const MyDragEvent = exports.DragEvent;
9197
9269
 
9198
9270
  exports.DropEvent = class DropEvent extends exports.PointerEvent {
9199
9271
  static setList(data) {
@@ -9275,36 +9347,32 @@ var LeaferUI = (function (exports) {
9275
9347
 
9276
9348
  function document$1(leafer) {
9277
9349
  addInteractionWindow(leafer);
9278
- leafer.config.move.scroll = 'limit';
9279
- leafer.config.zoom.min = 1;
9350
+ const { move, zoom } = leafer.config;
9351
+ move.scroll = 'limit';
9352
+ zoom.min = 1;
9353
+ }
9354
+
9355
+ function block(leafer) {
9356
+ const { config } = leafer;
9357
+ (config.wheel || (config.wheel = {})).preventDefault = false;
9358
+ (config.touch || (config.touch = {})).preventDefault = 'auto';
9280
9359
  }
9281
9360
 
9282
9361
  const debug$2 = Debug.get('LeaferTypeCreator');
9283
9362
  const LeaferTypeCreator = {
9284
9363
  list: {},
9285
9364
  register(name, fn) {
9286
- if (list[name]) {
9287
- debug$2.repeat(name);
9288
- }
9289
- else {
9290
- list[name] = fn;
9291
- }
9365
+ list[name] ? debug$2.repeat(name) : list[name] = fn;
9292
9366
  },
9293
9367
  run(name, leafer) {
9294
9368
  const fn = list[name];
9295
- if (fn) {
9296
- fn(leafer);
9297
- }
9298
- else {
9299
- debug$2.error('no', name);
9300
- }
9369
+ fn && fn(leafer);
9301
9370
  }
9302
9371
  };
9303
9372
  const { list, register } = LeaferTypeCreator;
9304
- register('draw', () => { });
9305
- register('custom', () => { });
9306
9373
  register('design', addInteractionWindow);
9307
9374
  register('document', document$1);
9375
+ register('block', block);
9308
9376
 
9309
9377
  const leafer = exports.Leafer.prototype;
9310
9378
  leafer.initType = function (type) {
@@ -9493,7 +9561,13 @@ var LeaferUI = (function (exports) {
9493
9561
  find.add(list[i]);
9494
9562
  }
9495
9563
  return find;
9496
- }
9564
+ },
9565
+ pathCanDrag(path) {
9566
+ return path && path.list.some(item => item.draggable || item.editable || (!item.isLeafer && item.hasEvent(exports.DragEvent.DRAG)));
9567
+ },
9568
+ pathHasOutside(path) {
9569
+ return path && path.list.some(item => item.isOutside);
9570
+ },
9497
9571
  };
9498
9572
  const I = InteractionHelper;
9499
9573
 
@@ -9803,15 +9877,18 @@ var LeaferUI = (function (exports) {
9803
9877
  swipeDistance: 20,
9804
9878
  preventDefaultMenu: true
9805
9879
  },
9880
+ touch: {
9881
+ preventDefault: true
9882
+ },
9806
9883
  cursor: true,
9807
9884
  keyEvent: true
9808
9885
  };
9809
9886
 
9810
- const { pathHasEventType, getMoveEventData: getMoveEventData$1, getZoomEventData: getZoomEventData$1, getRotateEventData: getRotateEventData$1 } = InteractionHelper;
9887
+ const { pathHasEventType, getMoveEventData: getMoveEventData$1, getZoomEventData: getZoomEventData$1, getRotateEventData: getRotateEventData$1, pathCanDrag: pathCanDrag$1, pathHasOutside } = InteractionHelper;
9811
9888
  class InteractionBase {
9812
9889
  get dragging() { return this.dragger.dragging; }
9813
9890
  get transforming() { return this.transformer.transforming; }
9814
- get moveMode() { return this.config.move.drag || this.isHoldSpaceKey || this.isHoldMiddleKey || (this.isHoldRightKey && this.dragger.moving) || this.isDragEmpty; }
9891
+ get moveMode() { return this.config.move.drag === true || this.isHoldSpaceKey || this.isHoldMiddleKey || (this.isHoldRightKey && this.dragger.moving) || this.isDragEmpty; }
9815
9892
  get canHover() { return this.config.pointer.hover && !this.config.mobile; }
9816
9893
  get isDragEmpty() { return this.config.move.dragEmpty && this.isRootPath(this.hoverData) && (!this.downData || this.isRootPath(this.downData)); }
9817
9894
  get isMobileDragEmpty() { return this.config.move.dragEmpty && !this.canHover && this.downData && this.isTreePath(this.downData); }
@@ -9820,7 +9897,7 @@ var LeaferUI = (function (exports) {
9820
9897
  get isHoldSpaceKey() { return this.config.move.holdSpaceKey && Keyboard.isHoldSpaceKey(); }
9821
9898
  get hitRadius() { return this.config.pointer.hitRadius; }
9822
9899
  constructor(target, canvas, selector, userConfig) {
9823
- this.config = config;
9900
+ this.config = DataHelper.clone(config);
9824
9901
  this.tapCount = 0;
9825
9902
  this.downKeyMap = {};
9826
9903
  this.target = target;
@@ -10072,11 +10149,11 @@ var LeaferUI = (function (exports) {
10072
10149
  return app.editor && (!data.path.has(app.editor) && data.path.has(app.tree) && !data.target.syncEventer);
10073
10150
  }
10074
10151
  checkPath(data, useDefaultPath) {
10075
- if (useDefaultPath || this.canMove(data))
10152
+ if (useDefaultPath || (this.moveMode && !pathHasOutside(data.path)))
10076
10153
  data.path = this.defaultPath;
10077
10154
  }
10078
10155
  canMove(data) {
10079
- return this.moveMode && data && data.path.list.every(item => !item.isOutside);
10156
+ return data && (this.moveMode || (this.config.move.drag === 'auto' && !pathCanDrag$1(data.path))) && !pathHasOutside(data.path);
10080
10157
  }
10081
10158
  isDrag(leaf) {
10082
10159
  return this.dragger.getList().has(leaf);
@@ -10494,7 +10571,7 @@ var LeaferUI = (function (exports) {
10494
10571
  }
10495
10572
  };
10496
10573
 
10497
- const { getMoveEventData, getZoomEventData, getRotateEventData } = InteractionHelper;
10574
+ const { getMoveEventData, getZoomEventData, getRotateEventData, pathCanDrag } = InteractionHelper;
10498
10575
  class Interaction extends InteractionBase {
10499
10576
  __listenEvents() {
10500
10577
  super.__listenEvents();
@@ -10627,7 +10704,11 @@ var LeaferUI = (function (exports) {
10627
10704
  this.pointerCancel();
10628
10705
  }
10629
10706
  onTouchStart(e) {
10630
- e.preventDefault();
10707
+ const touch = PointerEventHelper.getTouch(e);
10708
+ const local = this.getLocal(touch, true);
10709
+ const { preventDefault } = this.config.touch;
10710
+ if (preventDefault === true || (preventDefault === 'auto' && pathCanDrag(this.findPath(local))))
10711
+ e.preventDefault();
10631
10712
  this.multiTouchStart(e);
10632
10713
  if (this.usePointer)
10633
10714
  return;
@@ -10636,8 +10717,7 @@ var LeaferUI = (function (exports) {
10636
10717
  this.touchTimer = 0;
10637
10718
  }
10638
10719
  this.useTouch = true;
10639
- const touch = PointerEventHelper.getTouch(e);
10640
- this.pointerDown(PointerEventHelper.convertTouch(e, this.getLocal(touch, true)));
10720
+ this.pointerDown(PointerEventHelper.convertTouch(e, local));
10641
10721
  }
10642
10722
  onTouchMove(e) {
10643
10723
  this.multiTouchMove(e);
@@ -11120,10 +11200,13 @@ var LeaferUI = (function (exports) {
11120
11200
  const { get: get$2, translate } = MatrixHelper;
11121
11201
  const tempBox = new Bounds();
11122
11202
  const tempPoint = {};
11203
+ const tempScaleData = {};
11123
11204
  function createData(leafPaint, image, paint, box) {
11124
- const { blendMode } = paint;
11205
+ const { blendMode, sync } = paint;
11125
11206
  if (blendMode)
11126
11207
  leafPaint.blendMode = blendMode;
11208
+ if (sync)
11209
+ leafPaint.sync = sync;
11127
11210
  leafPaint.data = getPatternData(paint, box, image);
11128
11211
  }
11129
11212
  function getPatternData(paint, box, image) {
@@ -11143,13 +11226,10 @@ var LeaferUI = (function (exports) {
11143
11226
  x += (box.width - width * scaleX) / 2, y += (box.height - height * scaleY) / 2;
11144
11227
  }
11145
11228
  }
11146
- else if (size) {
11147
- scaleX = (typeof size === 'number' ? size : size.width) / width;
11148
- scaleY = (typeof size === 'number' ? size : size.height) / height;
11149
- }
11150
- else if (scale) {
11151
- scaleX = typeof scale === 'number' ? scale : scale.x;
11152
- scaleY = typeof scale === 'number' ? scale : scale.y;
11229
+ else if (scale || size) {
11230
+ MathHelper.getScaleData(scale, size, image, tempScaleData);
11231
+ scaleX = tempScaleData.scaleX;
11232
+ scaleY = tempScaleData.scaleY;
11153
11233
  }
11154
11234
  if (align) {
11155
11235
  const imageBounds = { x, y, width: swapWidth, height: swapHeight };
@@ -11388,7 +11468,7 @@ var LeaferUI = (function (exports) {
11388
11468
  return true;
11389
11469
  }
11390
11470
  else {
11391
- if (!paint.style || Export.running) {
11471
+ if (!paint.style || paint.sync || Export.running) {
11392
11472
  createPattern(ui, paint, canvas.pixelRatio);
11393
11473
  }
11394
11474
  else {
@@ -12258,6 +12338,7 @@ var LeaferUI = (function (exports) {
12258
12338
  export(leaf, filename, options) {
12259
12339
  this.running = true;
12260
12340
  const fileType = FileHelper.fileType(filename);
12341
+ const isDownload = filename.includes('.');
12261
12342
  options = FileHelper.getExportOptions(options);
12262
12343
  return addTask((success) => new Promise((resolve) => {
12263
12344
  const over = (result) => {
@@ -12267,19 +12348,13 @@ var LeaferUI = (function (exports) {
12267
12348
  };
12268
12349
  const { toURL } = Platform;
12269
12350
  const { download } = Platform.origin;
12270
- if (filename === 'json') {
12271
- return over({ data: leaf.toJSON(options.json) });
12272
- }
12273
- else if (fileType === 'json') {
12274
- download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
12275
- return over({ data: true });
12351
+ if (fileType === 'json') {
12352
+ isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
12353
+ return over({ data: isDownload ? true : leaf.toJSON(options.json) });
12276
12354
  }
12277
- if (filename === 'svg') {
12278
- return over({ data: leaf.toSVG() });
12279
- }
12280
- else if (fileType === 'svg') {
12281
- download(toURL(leaf.toSVG(), 'svg'), filename);
12282
- return over({ data: true });
12355
+ if (fileType === 'svg') {
12356
+ isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
12357
+ return over({ data: isDownload ? true : leaf.toSVG() });
12283
12358
  }
12284
12359
  const { leafer } = leaf;
12285
12360
  if (leafer) {
@@ -12288,14 +12363,8 @@ var LeaferUI = (function (exports) {
12288
12363
  let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
12289
12364
  const { worldTransform, isLeafer, isFrame } = leaf;
12290
12365
  const { slice, trim, onCanvas } = options;
12291
- let scale = options.scale || 1;
12292
- let pixelRatio = options.pixelRatio || 1;
12293
12366
  const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
12294
12367
  const contextSettings = options.contextSettings || leafer.config.contextSettings;
12295
- if (leaf.isApp) {
12296
- scale *= pixelRatio;
12297
- pixelRatio = leaf.app.pixelRatio;
12298
- }
12299
12368
  const screenshot = options.screenshot || leaf.isApp;
12300
12369
  const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
12301
12370
  const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
@@ -12329,9 +12398,17 @@ var LeaferUI = (function (exports) {
12329
12398
  }
12330
12399
  renderBounds = leaf.getBounds('render', relative);
12331
12400
  }
12332
- const { x, y, width, height } = new Bounds(renderBounds).scale(scale);
12401
+ const scaleData = { scaleX: 1, scaleY: 1 };
12402
+ MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
12403
+ let pixelRatio = options.pixelRatio || 1;
12404
+ if (leaf.isApp) {
12405
+ scaleData.scaleX *= pixelRatio;
12406
+ scaleData.scaleY *= pixelRatio;
12407
+ pixelRatio = leaf.app.pixelRatio;
12408
+ }
12409
+ const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
12410
+ const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
12333
12411
  let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
12334
- const renderOptions = { matrix: matrix.scale(1 / scale).invert().translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) };
12335
12412
  let sliceLeaf;
12336
12413
  if (slice) {
12337
12414
  sliceLeaf = leaf;
@@ -12501,6 +12578,9 @@ var LeaferUI = (function (exports) {
12501
12578
  exports.Matrix = Matrix;
12502
12579
  exports.MatrixHelper = MatrixHelper;
12503
12580
  exports.MultiTouchHelper = MultiTouchHelper;
12581
+ exports.MyDragEvent = MyDragEvent;
12582
+ exports.MyImage = MyImage;
12583
+ exports.MyPointerEvent = MyPointerEvent;
12504
12584
  exports.NeedConvertToCanvasCommandMap = NeedConvertToCanvasCommandMap;
12505
12585
  exports.OneRadian = OneRadian;
12506
12586
  exports.PI2 = PI2;