leafer-draw 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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$a(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$1(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$6, toInnerPoint: toInnerPoint$1, scaleOfOuter: scaleOfOuter$2, rotateOfOuter: rotateOfOuter$2, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
4024
+ const { copy: copy$6, toInnerPoint: toInnerPoint$1, toOuterPoint: toOuterPoint$1, scaleOfOuter: scaleOfOuter$2, rotateOfOuter: rotateOfOuter$2, skewOfOuter, multiplyParent: multiplyParent$2, divideParent, getLayout } = MatrixHelper;
3990
4025
  const matrix = {};
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$4 } = BoundsHelper;
4958
+ const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$2, copy: copy$4 } = 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$4(layout.renderBounds, layout.strokeBounds);
5081
+ layout.renderSpread > 0 ? copyAndSpread$2(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$4(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
  }
@@ -6843,6 +6880,11 @@ var LeaferUI = (function (exports) {
6843
6880
  }
6844
6881
 
6845
6882
  class LeaferData extends GroupData {
6883
+ __getInputData() {
6884
+ const data = super.__getInputData();
6885
+ canvasSizeAttrs.forEach(key => delete data[key]);
6886
+ return data;
6887
+ }
6846
6888
  }
6847
6889
 
6848
6890
  class FrameData extends BoxData {
@@ -6920,6 +6962,11 @@ var LeaferUI = (function (exports) {
6920
6962
  }
6921
6963
 
6922
6964
  class CanvasData extends RectData {
6965
+ __getInputData() {
6966
+ const data = super.__getInputData();
6967
+ data.url = this.__leaf.canvas.toDataURL('image/png');
6968
+ return data;
6969
+ }
6923
6970
  }
6924
6971
 
6925
6972
  const UIBounds = {
@@ -7832,6 +7879,13 @@ var LeaferUI = (function (exports) {
7832
7879
  getWorldPointByClient(clientPoint, updateClient) {
7833
7880
  return this.interaction && this.interaction.getLocal(clientPoint, updateClient);
7834
7881
  }
7882
+ getPagePointByClient(clientPoint, updateClient) {
7883
+ return this.getPagePoint(this.getWorldPointByClient(clientPoint, updateClient));
7884
+ }
7885
+ updateClientBounds() {
7886
+ this.canvas && this.canvas.updateClientBounds();
7887
+ }
7888
+ receiveEvent(_event) { }
7835
7889
  __checkUpdateLayout() {
7836
7890
  this.__layout.update();
7837
7891
  }
@@ -7915,7 +7969,7 @@ var LeaferUI = (function (exports) {
7915
7969
  const rect = exports.Rect.prototype;
7916
7970
  const group = exports.Group.prototype;
7917
7971
  const childrenRenderBounds = {};
7918
- const { copy: copy$2, add, includes: includes$1 } = BoundsHelper;
7972
+ const { copy: copy$2, add, includes: includes$1, copyAndSpread: copyAndSpread$1 } = BoundsHelper;
7919
7973
  exports.Box = class Box extends exports.Group {
7920
7974
  get __tag() { return 'Box'; }
7921
7975
  get isBranchLeaf() { return true; }
@@ -7929,20 +7983,23 @@ var LeaferUI = (function (exports) {
7929
7983
  return this.__updateRectRenderSpread() || -1;
7930
7984
  }
7931
7985
  __updateRectBoxBounds() { }
7932
- __updateBoxBounds() {
7986
+ __updateBoxBounds(secondLayout) {
7933
7987
  const data = this.__;
7934
7988
  if (this.children.length) {
7935
7989
  if (data.__autoSide) {
7936
7990
  if (this.leafer && this.leafer.ready)
7937
7991
  this.leafer.layouter.addExtra(this);
7938
7992
  super.__updateBoxBounds();
7993
+ const { boxBounds } = this.__layout;
7939
7994
  if (!data.__autoSize) {
7940
- const b = this.__layout.boxBounds;
7941
- if (!data.__autoWidth)
7942
- b.height += b.y, b.width = data.width, b.x = b.y = 0;
7943
- if (!data.__autoHeight)
7944
- b.width += b.x, b.height = data.height, b.y = b.x = 0;
7995
+ if (data.__autoWidth)
7996
+ boxBounds.width += boxBounds.x, boxBounds.height = data.height, boxBounds.y = boxBounds.x = 0;
7997
+ else
7998
+ boxBounds.height += boxBounds.y, boxBounds.width = data.width, boxBounds.x = boxBounds.y = 0;
7945
7999
  }
8000
+ if (secondLayout && data.flow && data.padding)
8001
+ copyAndSpread$1(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'));
8002
+ this.__updateNaturalSize();
7946
8003
  }
7947
8004
  else {
7948
8005
  this.__updateRectBoxBounds();
@@ -7962,13 +8019,13 @@ var LeaferUI = (function (exports) {
7962
8019
  super.__updateRenderBounds();
7963
8020
  copy$2(childrenRenderBounds, renderBounds);
7964
8021
  this.__updateRectRenderBounds();
7965
- isOverflow = !includes$1(renderBounds, childrenRenderBounds) || undefined;
8022
+ isOverflow = !includes$1(renderBounds, childrenRenderBounds) || !this.pathInputed || !this.__.cornerRadius;
7966
8023
  }
7967
8024
  else {
7968
8025
  this.__updateRectRenderBounds();
7969
8026
  }
7970
8027
  this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
7971
- if (isOverflow && !(this.__.__drawAfterFill = this.__.overflow === 'hide'))
8028
+ if (!(this.__.__drawAfterFill = this.__.overflow === 'hide') && isOverflow)
7972
8029
  add(renderBounds, childrenRenderBounds);
7973
8030
  }
7974
8031
  __updateRectRenderBounds() { }
@@ -8302,14 +8359,26 @@ var LeaferUI = (function (exports) {
8302
8359
  exports.Image = __decorate([
8303
8360
  registerUI()
8304
8361
  ], exports.Image);
8362
+ const MyImage = exports.Image;
8305
8363
 
8306
8364
  exports.Canvas = class Canvas extends exports.Rect {
8307
8365
  get __tag() { return 'Canvas'; }
8366
+ get ready() { return !this.url; }
8308
8367
  constructor(data) {
8309
8368
  super(data);
8310
8369
  this.canvas = Creator.canvas(this.__);
8311
8370
  this.context = this.canvas.context;
8312
8371
  this.__.__isCanvas = this.__.__drawAfterFill = true;
8372
+ if (data && data.url)
8373
+ this.drawImage(data.url);
8374
+ }
8375
+ drawImage(url) {
8376
+ new LeaferImage({ url }).load((image) => {
8377
+ this.context.drawImage(image.view, 0, 0);
8378
+ this.url = undefined;
8379
+ this.paint();
8380
+ this.emitEvent(new ImageEvent(ImageEvent.LOADED, { image }));
8381
+ });
8313
8382
  }
8314
8383
  draw(ui, offset, scale, rotation) {
8315
8384
  ui.__layout.update();
@@ -8368,7 +8437,7 @@ var LeaferUI = (function (exports) {
8368
8437
  resizeType(100)
8369
8438
  ], exports.Canvas.prototype, "height", void 0);
8370
8439
  __decorate([
8371
- resizeType(Platform.devicePixelRatio)
8440
+ resizeType(1)
8372
8441
  ], exports.Canvas.prototype, "pixelRatio", void 0);
8373
8442
  __decorate([
8374
8443
  resizeType(true)
@@ -8392,13 +8461,13 @@ var LeaferUI = (function (exports) {
8392
8461
  super(data);
8393
8462
  }
8394
8463
  __drawHitPath(canvas) {
8395
- const { __lineHeight, __baseLine, __textDrawData: data } = this.__;
8464
+ const { __lineHeight, fontSize, __baseLine, __textDrawData: data } = this.__;
8396
8465
  canvas.beginPath();
8397
8466
  if (this.__.__letterSpacing < 0) {
8398
8467
  this.__drawPathByData(canvas);
8399
8468
  }
8400
8469
  else {
8401
- data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight));
8470
+ data.rows.forEach(row => canvas.rect(row.x, row.y - __baseLine, row.width, __lineHeight < fontSize ? fontSize : __lineHeight));
8402
8471
  }
8403
8472
  }
8404
8473
  __drawPathByData(drawer, _data) {
@@ -8591,7 +8660,8 @@ var LeaferUI = (function (exports) {
8591
8660
  drawPoints(_points, _curve, _close) { return this; }
8592
8661
  clearPath() { return this; }
8593
8662
  paint() {
8594
- this.pathElement.forceUpdate('path');
8663
+ if (!this.pathElement.__layout.boxChanged)
8664
+ this.pathElement.forceUpdate('path');
8595
8665
  }
8596
8666
  };
8597
8667
  __decorate([
@@ -8601,7 +8671,7 @@ var LeaferUI = (function (exports) {
8601
8671
  penPathType()
8602
8672
  ], exports.Pen.prototype, "path", void 0);
8603
8673
  exports.Pen = __decorate([
8604
- useModule(PathCreator, ['set', 'beginPath', 'path']),
8674
+ useModule(PathCreator, ['set', 'beginPath', 'path', 'paint']),
8605
8675
  registerUI()
8606
8676
  ], exports.Pen);
8607
8677
  function penPathType() {
@@ -8963,10 +9033,13 @@ var LeaferUI = (function (exports) {
8963
9033
  const { get: get$2, translate } = MatrixHelper;
8964
9034
  const tempBox = new Bounds();
8965
9035
  const tempPoint = {};
9036
+ const tempScaleData = {};
8966
9037
  function createData(leafPaint, image, paint, box) {
8967
- const { blendMode } = paint;
9038
+ const { blendMode, sync } = paint;
8968
9039
  if (blendMode)
8969
9040
  leafPaint.blendMode = blendMode;
9041
+ if (sync)
9042
+ leafPaint.sync = sync;
8970
9043
  leafPaint.data = getPatternData(paint, box, image);
8971
9044
  }
8972
9045
  function getPatternData(paint, box, image) {
@@ -8986,13 +9059,10 @@ var LeaferUI = (function (exports) {
8986
9059
  x += (box.width - width * scaleX) / 2, y += (box.height - height * scaleY) / 2;
8987
9060
  }
8988
9061
  }
8989
- else if (size) {
8990
- scaleX = (typeof size === 'number' ? size : size.width) / width;
8991
- scaleY = (typeof size === 'number' ? size : size.height) / height;
8992
- }
8993
- else if (scale) {
8994
- scaleX = typeof scale === 'number' ? scale : scale.x;
8995
- scaleY = typeof scale === 'number' ? scale : scale.y;
9062
+ else if (scale || size) {
9063
+ MathHelper.getScaleData(scale, size, image, tempScaleData);
9064
+ scaleX = tempScaleData.scaleX;
9065
+ scaleY = tempScaleData.scaleY;
8996
9066
  }
8997
9067
  if (align) {
8998
9068
  const imageBounds = { x, y, width: swapWidth, height: swapHeight };
@@ -9231,7 +9301,7 @@ var LeaferUI = (function (exports) {
9231
9301
  return true;
9232
9302
  }
9233
9303
  else {
9234
- if (!paint.style || Export.running) {
9304
+ if (!paint.style || paint.sync || Export.running) {
9235
9305
  createPattern(ui, paint, canvas.pixelRatio);
9236
9306
  }
9237
9307
  else {
@@ -10101,6 +10171,7 @@ var LeaferUI = (function (exports) {
10101
10171
  export(leaf, filename, options) {
10102
10172
  this.running = true;
10103
10173
  const fileType = FileHelper.fileType(filename);
10174
+ const isDownload = filename.includes('.');
10104
10175
  options = FileHelper.getExportOptions(options);
10105
10176
  return addTask((success) => new Promise((resolve) => {
10106
10177
  const over = (result) => {
@@ -10110,19 +10181,13 @@ var LeaferUI = (function (exports) {
10110
10181
  };
10111
10182
  const { toURL } = Platform;
10112
10183
  const { download } = Platform.origin;
10113
- if (filename === 'json') {
10114
- return over({ data: leaf.toJSON(options.json) });
10115
- }
10116
- else if (fileType === 'json') {
10117
- download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
10118
- return over({ data: true });
10119
- }
10120
- if (filename === 'svg') {
10121
- return over({ data: leaf.toSVG() });
10184
+ if (fileType === 'json') {
10185
+ isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
10186
+ return over({ data: isDownload ? true : leaf.toJSON(options.json) });
10122
10187
  }
10123
- else if (fileType === 'svg') {
10124
- download(toURL(leaf.toSVG(), 'svg'), filename);
10125
- return over({ data: true });
10188
+ if (fileType === 'svg') {
10189
+ isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
10190
+ return over({ data: isDownload ? true : leaf.toSVG() });
10126
10191
  }
10127
10192
  const { leafer } = leaf;
10128
10193
  if (leafer) {
@@ -10131,14 +10196,8 @@ var LeaferUI = (function (exports) {
10131
10196
  let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
10132
10197
  const { worldTransform, isLeafer, isFrame } = leaf;
10133
10198
  const { slice, trim, onCanvas } = options;
10134
- let scale = options.scale || 1;
10135
- let pixelRatio = options.pixelRatio || 1;
10136
10199
  const smooth = options.smooth === undefined ? leafer.config.smooth : options.smooth;
10137
10200
  const contextSettings = options.contextSettings || leafer.config.contextSettings;
10138
- if (leaf.isApp) {
10139
- scale *= pixelRatio;
10140
- pixelRatio = leaf.app.pixelRatio;
10141
- }
10142
10201
  const screenshot = options.screenshot || leaf.isApp;
10143
10202
  const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
10144
10203
  const needFill = FileHelper.isOpaqueImage(filename) || fill, matrix = new Matrix();
@@ -10172,9 +10231,17 @@ var LeaferUI = (function (exports) {
10172
10231
  }
10173
10232
  renderBounds = leaf.getBounds('render', relative);
10174
10233
  }
10175
- const { x, y, width, height } = new Bounds(renderBounds).scale(scale);
10234
+ const scaleData = { scaleX: 1, scaleY: 1 };
10235
+ MathHelper.getScaleData(options.scale, options.size, renderBounds, scaleData);
10236
+ let pixelRatio = options.pixelRatio || 1;
10237
+ if (leaf.isApp) {
10238
+ scaleData.scaleX *= pixelRatio;
10239
+ scaleData.scaleY *= pixelRatio;
10240
+ pixelRatio = leaf.app.pixelRatio;
10241
+ }
10242
+ const { x, y, width, height } = new Bounds(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
10243
+ const renderOptions = { matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
10176
10244
  let canvas = Creator.canvas({ width: Math.round(width), height: Math.round(height), pixelRatio, smooth, contextSettings });
10177
- const renderOptions = { matrix: matrix.scale(1 / scale).invert().translate(-x, -y).withScale(1 / scaleX * scale, 1 / scaleY * scale) };
10178
10245
  let sliceLeaf;
10179
10246
  if (slice) {
10180
10247
  sliceLeaf = leaf;
@@ -10331,6 +10398,7 @@ var LeaferUI = (function (exports) {
10331
10398
  exports.MathHelper = MathHelper;
10332
10399
  exports.Matrix = Matrix;
10333
10400
  exports.MatrixHelper = MatrixHelper;
10401
+ exports.MyImage = MyImage;
10334
10402
  exports.NeedConvertToCanvasCommandMap = NeedConvertToCanvasCommandMap;
10335
10403
  exports.OneRadian = OneRadian;
10336
10404
  exports.PI2 = PI2;
@@ -0,0 +1 @@
1
+ "use strict";var t=require("@leafer/core"),e=require("@leafer-ui/draw");const n=t.Debug.get("LeaferCanvas");class i extends t.LeaferCanvasBase{set zIndex(t){const{style:e}=this.view;e.zIndex=t,this.setAbsolute(this.view)}set childIndex(t){const{view:e,parentView:n}=this;if(e&&n){const i=n.children[t];i?(this.setAbsolute(i),n.insertBefore(e,i)):n.appendChild(i)}}init(){const{config:e}=this,n=e.view||e.canvas;n?this.__createViewFrom(n):this.__createView();const{style:i}=this.view;if(i.display||(i.display="block"),this.parentView=this.view.parentElement,this.parentView){const t=this.parentView.style;t.webkitUserSelect=t.userSelect="none"}t.Platform.syncDomFont&&!this.parentView&&(i.display="none",document.body.appendChild(this.view)),this.__createContext(),this.autoLayout||this.resize(e)}set backgroundColor(t){this.view.style.backgroundColor=t}get backgroundColor(){return this.view.style.backgroundColor}set hittable(t){this.view.style.pointerEvents=t?"auto":"none"}get hittable(){return"none"!==this.view.style.pointerEvents}__createView(){this.view=document.createElement("canvas")}__createViewFrom(t){let e="string"==typeof t?document.getElementById(t):t;if(e)if(e instanceof HTMLCanvasElement)this.view=e;else{let t=e;if(e===window||e===document){const e=document.createElement("div"),{style:n}=e;n.position="absolute",n.top=n.bottom=n.left=n.right="0px",document.body.appendChild(e),t=e}this.__createView();const n=this.view;t.hasChildNodes()&&(this.setAbsolute(n),t.style.position||(t.style.position="relative")),t.appendChild(n)}else n.error(`no id: ${t}`),this.__createView()}setAbsolute(t){const{style:e}=t;e.position="absolute",e.top=e.left="0px"}updateViewSize(){const{width:t,height:e,pixelRatio:n}=this,{style:i}=this.view;i.width=t+"px",i.height=e+"px",this.view.width=Math.ceil(t*n),this.view.height=Math.ceil(e*n)}updateClientBounds(){this.clientBounds=this.view.getBoundingClientRect()}startAutoLayout(e,i){if(this.resizeListener=i,e){this.autoBounds=e;try{this.resizeObserver=new ResizeObserver((t=>{this.updateClientBounds();for(const e of t)this.checkAutoBounds(e.contentRect)}));const t=this.parentView;t?(this.resizeObserver.observe(t),this.checkAutoBounds(t.getBoundingClientRect())):(this.checkAutoBounds(this.view),n.warn("no parent"))}catch(t){this.imitateResizeObserver()}}else window.addEventListener("resize",(()=>{const e=t.Platform.devicePixelRatio;if(this.pixelRatio!==e){const{width:t,height:n}=this;this.emitResize({width:t,height:n,pixelRatio:e})}}))}imitateResizeObserver(){this.autoLayout&&(this.parentView&&this.checkAutoBounds(this.parentView.getBoundingClientRect()),t.Platform.requestRender(this.imitateResizeObserver.bind(this)))}checkAutoBounds(e){const n=this.view,{x:i,y:s,width:o,height:a}=this.autoBounds.getBoundsFrom(e),r={width:o,height:a,pixelRatio:t.Platform.devicePixelRatio};if(!this.isSameSize(r)){const{style:t}=n;t.marginLeft=i+"px",t.marginTop=s+"px",this.emitResize(r)}}stopAutoLayout(){this.autoLayout=!1,this.resizeListener=null,this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null)}emitResize(e){const n={};t.DataHelper.copyAttrs(n,this,t.canvasSizeAttrs),this.resize(e),void 0!==this.width&&this.resizeListener(new t.ResizeEvent(e,n))}unrealCanvas(){if(!this.unreal&&this.parentView){const t=this.view;t&&t.remove(),this.view=this.parentView,this.unreal=!0}}destroy(){if(this.view){if(this.stopAutoLayout(),!this.unreal){const t=this.view;t.parentElement&&t.remove()}super.destroy()}}}t.canvasPatch(CanvasRenderingContext2D.prototype),t.canvasPatch(Path2D.prototype);const{mineType:s,fileType:o}=t.FileHelper;function a(e,n){t.Platform.origin={createCanvas(t,e){const n=document.createElement("canvas");return n.width=t,n.height=e,n},canvasToDataURL:(t,e,n)=>t.toDataURL(s(e),n),canvasToBolb:(t,e,n)=>new Promise((i=>t.toBlob(i,s(e),n))),canvasSaveAs:(e,n,i)=>{const a=e.toDataURL(s(o(n)),i);return t.Platform.origin.download(a,n)},download:(t,e)=>new Promise((n=>{let i=document.createElement("a");i.href=t,i.download=e,document.body.appendChild(i),i.click(),document.body.removeChild(i),n()})),loadImage:e=>new Promise(((n,i)=>{const s=new Image,{crossOrigin:o}=t.Platform.image;o&&(s.setAttribute("crossOrigin",o),s.crossOrigin=o),s.onload=()=>{n(s)},s.onerror=t=>{i(t)},s.src=t.Platform.image.getRealURL(e)}))},t.Platform.event={stopDefault(t){t.preventDefault()},stopNow(t){t.stopImmediatePropagation()},stop(t){t.stopPropagation()}},t.Platform.canvas=t.Creator.canvas(),t.Platform.conicGradientSupport=!!t.Platform.canvas.context.createConicGradient}Object.assign(t.Creator,{canvas:(t,e)=>new i(t,e),image:e=>new t.LeaferImage(e)}),t.Platform.name="web",t.Platform.isMobile="ontouchstart"in window,t.Platform.requestRender=function(t){window.requestAnimationFrame(t)},t.defineKey(t.Platform,"devicePixelRatio",{get:()=>Math.max(1,devicePixelRatio)});const{userAgent:r}=navigator;r.indexOf("Firefox")>-1?(t.Platform.conicGradientRotate90=!0,t.Platform.intWheelDeltaY=!0,t.Platform.syncDomFont=!0):r.indexOf("Safari")>-1&&-1===r.indexOf("Chrome")&&(t.Platform.fullImageShadow=!0),r.indexOf("Windows")>-1?(t.Platform.os="Windows",t.Platform.intWheelDeltaY=!0):r.indexOf("Mac")>-1?t.Platform.os="Mac":r.indexOf("Linux")>-1&&(t.Platform.os="Linux");class l{get childrenChanged(){return this.hasAdd||this.hasRemove||this.hasVisible}get updatedList(){if(this.hasRemove){const e=new t.LeafList;return this.__updatedList.list.forEach((t=>{t.leafer&&e.add(t)})),e}return this.__updatedList}constructor(e,n){this.totalTimes=0,this.config={},this.__updatedList=new t.LeafList,this.target=e,n&&(this.config=t.DataHelper.default(n,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}update(){this.changed=!0,this.running&&this.target.emit(t.RenderEvent.REQUEST)}__onAttrChange(t){this.__updatedList.add(t.target),this.update()}__onChildEvent(e){e.type===t.ChildEvent.ADD?(this.hasAdd=!0,this.__pushChild(e.child)):(this.hasRemove=!0,this.__updatedList.add(e.parent)),this.update()}__pushChild(t){this.__updatedList.add(t),t.isBranch&&this.__loopChildren(t)}__loopChildren(t){const{children:e}=t;for(let t=0,n=e.length;t<n;t++)this.__pushChild(e[t])}__onRquestData(){this.target.emitEvent(new t.WatchEvent(t.WatchEvent.DATA,{updatedList:this.updatedList})),this.__updatedList=new t.LeafList,this.totalTimes++,this.changed=!1,this.hasVisible=!1,this.hasRemove=!1,this.hasAdd=!1}__listenEvents(){const{target:e}=this;this.__eventIds=[e.on_(t.PropertyEvent.CHANGE,this.__onAttrChange,this),e.on_([t.ChildEvent.ADD,t.ChildEvent.REMOVE],this.__onChildEvent,this),e.on_(t.WatchEvent.REQUEST,this.__onRquestData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=null,this.__updatedList=null)}}const{updateAllMatrix:d,updateBounds:c,updateAllWorldOpacity:h}=t.LeafHelper,{pushAllChildBranch:u,pushAllParent:f}=t.BranchHelper;const{worldBounds:p}=t.LeafBoundsHelper,g={x:0,y:0,width:1e5,height:1e5};class _{constructor(e){this.updatedBounds=new t.Bounds,this.beforeBounds=new t.Bounds,this.afterBounds=new t.Bounds,e instanceof Array&&(e=new t.LeafList(e)),this.updatedList=e}setBefore(){this.beforeBounds.setListWithFn(this.updatedList.list,p)}setAfter(){const{list:t}=this.updatedList;t.some((t=>t.noBounds))?this.afterBounds.set(g):this.afterBounds.setListWithFn(t,p),this.updatedBounds.setList([this.beforeBounds,this.afterBounds])}merge(t){this.updatedList.addList(t.updatedList.list),this.beforeBounds.add(t.beforeBounds),this.afterBounds.add(t.afterBounds),this.updatedBounds.add(t.updatedBounds)}destroy(){this.updatedList=null}}const{updateAllMatrix:w,updateAllChange:m}=t.LeafHelper,v=t.Debug.get("Layouter");class y{constructor(e,n){this.totalTimes=0,this.config={},this.__levelList=new t.LeafLevelList,this.target=e,n&&(this.config=t.DataHelper.default(n,this.config)),this.__listenEvents()}start(){this.disabled||(this.running=!0)}stop(){this.running=!1}disable(){this.stop(),this.__removeListenEvents(),this.disabled=!0}layout(){if(!this.running)return;const{target:e}=this;this.times=0;try{e.emit(t.LayoutEvent.START),this.layoutOnce(),e.emitEvent(new t.LayoutEvent(t.LayoutEvent.END,this.layoutedBlocks,this.times))}catch(t){v.error(t)}this.layoutedBlocks=null}layoutAgain(){this.layouting?this.waitAgain=!0:this.layoutOnce()}layoutOnce(){return this.layouting?v.warn("layouting"):this.times>3?v.warn("layout max times"):(this.times++,this.totalTimes++,this.layouting=!0,this.target.emit(t.WatchEvent.REQUEST),this.totalTimes>1?this.partLayout():this.fullLayout(),this.layouting=!1,void(this.waitAgain&&(this.waitAgain=!1,this.layoutOnce())))}partLayout(){var e;if(!(null===(e=this.__updatedList)||void 0===e?void 0:e.length))return;const n=t.Run.start("PartLayout"),{target:i,__updatedList:s}=this,{BEFORE:o,LAYOUT:a,AFTER:r}=t.LayoutEvent,l=this.getBlocks(s);l.forEach((t=>t.setBefore())),i.emitEvent(new t.LayoutEvent(o,l,this.times)),this.extraBlock=null,s.sort(),function(t,e){let n;t.list.forEach((t=>{n=t.__layout,e.without(t)&&!n.proxyZoom&&(n.matrixChanged?(d(t,!0),e.add(t),t.isBranch&&u(t,e),f(t,e)):n.boundsChanged&&(e.add(t),t.isBranch&&(t.__tempNumber=0),f(t,e)))}))}(s,this.__levelList),function(t){let e,n,i;t.sort(!0),t.levels.forEach((s=>{e=t.levelMap[s];for(let t=0,s=e.length;t<s;t++){if(n=e[t],n.isBranch&&n.__tempNumber){i=n.children;for(let t=0,e=i.length;t<e;t++)i[t].isBranch||c(i[t])}c(n)}}))}(this.__levelList),function(t){t.list.forEach((t=>{t.__layout.opacityChanged&&h(t),t.__updateChange()}))}(s),this.extraBlock&&l.push(this.extraBlock),l.forEach((t=>t.setAfter())),i.emitEvent(new t.LayoutEvent(a,l,this.times)),i.emitEvent(new t.LayoutEvent(r,l,this.times)),this.addBlocks(l),this.__levelList.reset(),this.__updatedList=null,t.Run.end(n)}fullLayout(){const e=t.Run.start("FullLayout"),{target:n}=this,{BEFORE:i,LAYOUT:s,AFTER:o}=t.LayoutEvent,a=this.getBlocks(new t.LeafList(n));n.emitEvent(new t.LayoutEvent(i,a,this.times)),y.fullLayout(n),a.forEach((t=>{t.setAfter()})),n.emitEvent(new t.LayoutEvent(s,a,this.times)),n.emitEvent(new t.LayoutEvent(o,a,this.times)),this.addBlocks(a),t.Run.end(e)}static fullLayout(e){w(e,!0),e.isBranch?t.BranchHelper.updateBounds(e):t.LeafHelper.updateBounds(e),m(e)}addExtra(t){if(!this.__updatedList.has(t)){const{updatedList:e,beforeBounds:n}=this.extraBlock||(this.extraBlock=new _([]));e.length?n.add(t.__world):n.set(t.__world),e.add(t)}}createBlock(t){return new _(t)}getBlocks(t){return[this.createBlock(t)]}addBlocks(t){this.layoutedBlocks?this.layoutedBlocks.push(...t):this.layoutedBlocks=t}__onReceiveWatchData(t){this.__updatedList=t.data.updatedList}__listenEvents(){const{target:e}=this;this.__eventIds=[e.on_(t.LayoutEvent.REQUEST,this.layout,this),e.on_(t.LayoutEvent.AGAIN,this.layoutAgain,this),e.on_(t.WatchEvent.DATA,this.__onReceiveWatchData,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.config=null)}}const x=t.Debug.get("Renderer");class b{get needFill(){return!(this.canvas.allowBackgroundColor||!this.config.fill)}constructor(e,n,i){this.FPS=60,this.totalTimes=0,this.times=0,this.config={usePartRender:!0,maxFPS:60},this.target=e,this.canvas=n,i&&(this.config=t.DataHelper.default(i,this.config)),this.__listenEvents(),this.__requestRender()}start(){this.running=!0}stop(){this.running=!1}update(){this.changed=!0}requestLayout(){this.target.emit(t.LayoutEvent.REQUEST)}render(e){if(!this.running||!this.canvas.view)return void(this.changed=!0);const{target:n}=this;this.times=0,this.totalBounds=new t.Bounds,x.log(n.innerName,"---\x3e");try{this.emitRender(t.RenderEvent.START),this.renderOnce(e),this.emitRender(t.RenderEvent.END,this.totalBounds),t.ImageManager.clearRecycled()}catch(t){this.rendering=!1,x.error(t)}x.log("-------------|")}renderAgain(){this.rendering?this.waitAgain=!0:this.renderOnce()}renderOnce(e){if(this.rendering)return x.warn("rendering");if(this.times>3)return x.warn("render max times");if(this.times++,this.totalTimes++,this.rendering=!0,this.changed=!1,this.renderBounds=new t.Bounds,this.renderOptions={},e)this.emitRender(t.RenderEvent.BEFORE),e();else{if(this.requestLayout(),this.ignore)return void(this.ignore=this.rendering=!1);this.emitRender(t.RenderEvent.BEFORE),this.config.usePartRender&&this.totalTimes>1?this.partRender():this.fullRender()}this.emitRender(t.RenderEvent.RENDER,this.renderBounds,this.renderOptions),this.emitRender(t.RenderEvent.AFTER,this.renderBounds,this.renderOptions),this.updateBlocks=null,this.rendering=!1,this.waitAgain&&(this.waitAgain=!1,this.renderOnce())}partRender(){const{canvas:t,updateBlocks:e}=this;if(!e)return x.warn("PartRender: need update attr");this.mergeBlocks(),e.forEach((e=>{t.bounds.hit(e)&&!e.isEmpty()&&this.clipRender(e)}))}clipRender(e){const n=t.Run.start("PartRender"),{canvas:i}=this,s=e.getIntersect(i.bounds),o=e.includes(this.target.__world),a=new t.Bounds(s);i.save(),o&&!t.Debug.showRepaint?i.clear():(s.spread(10+1/this.canvas.pixelRatio).ceil(),i.clearWorld(s,!0),i.clipWorld(s,!0)),this.__render(s,o,a),i.restore(),t.Run.end(n)}fullRender(){const e=t.Run.start("FullRender"),{canvas:n}=this;n.save(),n.clear(),this.__render(n.bounds,!0),n.restore(),t.Run.end(e)}__render(e,n,i){const s=e.includes(this.target.__world)?{includes:n}:{bounds:e,includes:n};this.needFill&&this.canvas.fillWorld(e,this.config.fill),t.Debug.showRepaint&&this.canvas.strokeWorld(e,"red"),this.target.__render(this.canvas,s),this.renderBounds=i=i||e,this.renderOptions=s,this.totalBounds.isEmpty()?this.totalBounds=i:this.totalBounds.add(i),t.Debug.showHitView&&this.renderHitView(s),t.Debug.showBoundsView&&this.renderBoundsView(s),this.canvas.updateRender(i)}renderHitView(t){}renderBoundsView(t){}addBlock(t){this.updateBlocks||(this.updateBlocks=[]),this.updateBlocks.push(t)}mergeBlocks(){const{updateBlocks:e}=this;if(e){const n=new t.Bounds;n.setList(e),e.length=0,e.push(n)}}__requestRender(){const e=Date.now();t.Platform.requestRender((()=>{this.FPS=Math.min(60,Math.ceil(1e3/(Date.now()-e))),this.running&&(this.target.emit(t.AnimateEvent.FRAME),this.changed&&this.canvas.view&&this.render(),this.target.emit(t.RenderEvent.NEXT)),this.target&&this.__requestRender()}))}__onResize(e){if(!this.canvas.unreal){if(e.bigger||!e.samePixelRatio){const{width:n,height:i}=e.old;if(!new t.Bounds(0,0,n,i).includes(this.target.__world)||this.needFill||!e.samePixelRatio)return this.addBlock(this.canvas.bounds),void this.target.forceUpdate("surface")}this.addBlock(new t.Bounds(0,0,1,1)),this.changed=!0}}__onLayoutEnd(t){t.data&&t.data.map((t=>{let e;t.updatedList&&t.updatedList.list.some((t=>(e=!t.__world.width||!t.__world.height,e&&(t.isLeafer||x.tip(t.innerName,": empty"),e=!t.isBranch||t.isBranchLeaf),e))),this.addBlock(e?this.canvas.bounds:t.updatedBounds)}))}emitRender(e,n,i){this.target.emitEvent(new t.RenderEvent(e,this.times,n,i))}__listenEvents(){const{target:e}=this;this.__eventIds=[e.on_(t.RenderEvent.REQUEST,this.update,this),e.on_(t.LayoutEvent.END,this.__onLayoutEnd,this),e.on_(t.RenderEvent.AGAIN,this.renderAgain,this),e.on_(t.ResizeEvent.RESIZE,this.__onResize,this)]}__removeListenEvents(){this.target.off_(this.__eventIds)}destroy(){this.target&&(this.stop(),this.__removeListenEvents(),this.target=this.canvas=this.config=null)}}function B(t,e){let n;const{rows:i,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=i.length;t<a;t++)n=i[t],n.text?e.fillText(n.text,n.x,n.y):n.data&&n.data.forEach((t=>{e.fillText(t.char,t.x,n.y)})),s&&e.fillRect(n.x,n.y+s,n.width,o)}function E(t,e,n){const{strokeAlign:i}=e.__,s="string"!=typeof t;switch(i){case"center":n.setStroke(s?void 0:t,e.__.strokeWidth,e.__),s?k(t,!0,e,n):L(e,n);break;case"inside":R("inside",t,s,e,n);break;case"outside":R("outside",t,s,e,n)}}function R(t,e,n,i,s){const{__strokeWidth:o,__font:a}=i.__,r=s.getSameCanvas(!0,!0);r.setStroke(n?void 0:e,2*o,i.__),r.font=a,n?k(e,!0,i,r):L(i,r),r.blendMode="outside"===t?"destination-out":"destination-in",B(i,r),r.blendMode="normal",i.__worldFlipped?s.copyWorldByReset(r,i.__nowWorld):s.copyWorldToInner(r,i.__nowWorld,i.__layout.renderBounds),r.recycle(i.__nowWorld)}function L(t,e){let n;const{rows:i,decorationY:s,decorationHeight:o}=t.__.__textDrawData;for(let t=0,a=i.length;t<a;t++)n=i[t],n.text?e.strokeText(n.text,n.x,n.y):n.data&&n.data.forEach((t=>{e.strokeText(t.char,t.x,n.y)})),s&&e.strokeRect(n.x,n.y+s,n.width,o)}function k(t,n,i,s){let o;for(let a=0,r=t.length;a<r;a++)o=t[a],o.image&&e.PaintImage.checkImage(i,s,o,!1)||o.style&&(s.strokeStyle=o.style,o.blendMode?(s.saveBlendMode(o.blendMode),n?L(i,s):s.stroke(),s.restoreBlendMode()):n?L(i,s):s.stroke())}Object.assign(t.Creator,{watcher:(t,e)=>new l(t,e),layouter:(t,e)=>new y(t,e),renderer:(t,e,n)=>new b(t,e,n),selector:(t,e)=>{},interaction:(t,e,n,i)=>{}}),t.Platform.layout=y.fullLayout;const{getSpread:P,getOuterOf:S,getByMove:C,getIntersectData:O}=t.BoundsHelper;let A;function W(t,n,i){if("object"!=typeof n||!1===n.visible||0===n.opacity)return;const{boxBounds:s}=i.__layout;switch(n.type){case"solid":let{type:o,blendMode:a,color:r,opacity:l}=n;return{type:o,blendMode:a,style:e.ColorConvert.string(r,l)};case"image":return e.PaintImage.image(i,t,n,s,!A||!A[n.url]);case"linear":return e.PaintGradient.linearGradient(n,s);case"radial":return e.PaintGradient.radialGradient(n,s);case"angular":return e.PaintGradient.conicGradient(n,s);default:return void 0!==n.r?{type:"solid",style:e.ColorConvert.string(n)}:void 0}}const M={compute:function(t,n){const i=n.__,s=[];let o,a=i.__input[t];a instanceof Array||(a=[a]),A=e.PaintImage.recycleImage(t,i);for(let e,i=0,o=a.length;i<o;i++)e=W(t,a[i],n),e&&s.push(e);i["_"+t]=s.length?s:void 0,s.length&&s[0].image&&(o=s[0].image.hasOpacityPixel),"fill"===t?i.__pixelFill=o:i.__pixelStroke=o},fill:function(t,e,n){n.fillStyle=t,e.__.__font?B(e,n):e.__.windingRule?n.fill(e.__.windingRule):n.fill()},fills:function(t,n,i){let s;const{windingRule:o,__font:a}=n.__;for(let r=0,l=t.length;r<l;r++)s=t[r],s.image&&e.PaintImage.checkImage(n,i,s,!a)||s.style&&(i.fillStyle=s.style,s.transform?(i.save(),i.transform(s.transform),s.blendMode&&(i.blendMode=s.blendMode),a?B(n,i):o?i.fill(o):i.fill(),i.restore()):s.blendMode?(i.saveBlendMode(s.blendMode),a?B(n,i):o?i.fill(o):i.fill(),i.restoreBlendMode()):a?B(n,i):o?i.fill(o):i.fill())},fillText:B,stroke:function(t,e,n){const i=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=i;if(s)if(a)E(t,e,n);else switch(o){case"center":n.setStroke(t,s,i),n.stroke();break;case"inside":n.save(),n.setStroke(t,2*s,i),i.windingRule?n.clip(i.windingRule):n.clip(),n.stroke(),n.restore();break;case"outside":const o=n.getSameCanvas(!0,!0);o.setStroke(t,2*s,i),e.__drawRenderPath(o),o.stroke(),i.windingRule?o.clip(i.windingRule):o.clip(),o.clearWorld(e.__layout.renderBounds),e.__worldFlipped?n.copyWorldByReset(o,e.__nowWorld):n.copyWorldToInner(o,e.__nowWorld,e.__layout.renderBounds),o.recycle(e.__nowWorld)}},strokes:function(t,e,n){const i=e.__,{__strokeWidth:s,strokeAlign:o,__font:a}=i;if(s)if(a)E(t,e,n);else switch(o){case"center":n.setStroke(void 0,s,i),k(t,!1,e,n);break;case"inside":n.save(),n.setStroke(void 0,2*s,i),i.windingRule?n.clip(i.windingRule):n.clip(),k(t,!1,e,n),n.restore();break;case"outside":const{renderBounds:o}=e.__layout,a=n.getSameCanvas(!0,!0);e.__drawRenderPath(a),a.setStroke(void 0,2*s,i),k(t,!1,e,a),i.windingRule?a.clip(i.windingRule):a.clip(),a.clearWorld(o),e.__worldFlipped?n.copyWorldByReset(a,e.__nowWorld):n.copyWorldToInner(a,e.__nowWorld,o),a.recycle(e.__nowWorld)}},strokeText:E,drawTextStroke:L,shape:function(t,e,n){const i=e.getSameCanvas(),s=t.__nowWorld;let o,a,r,l,{scaleX:d,scaleY:c}=s;if(d<0&&(d=-d),c<0&&(c=-c),e.bounds.includes(s))l=i,o=r=s;else{const{renderShapeSpread:i}=t.__layout,h=O(i?P(e.bounds,d===c?i*d:[i*c,i*d]):e.bounds,s);a=e.bounds.getFitMatrix(h);let{a:u,d:f}=a;if(a.a<1&&(l=e.getSameCanvas(),t.__renderShape(l,n),d*=u,c*=f),r=S(s,a),o=C(r,-a.e,-a.f),n.matrix){const{matrix:t}=n;a.multiply(t),u*=t.scaleX,f*=t.scaleY}n=Object.assign(Object.assign({},n),{matrix:a.withScale(u,f)})}return t.__renderShape(i,n),{canvas:i,matrix:a,bounds:o,worldCanvas:l,shapeBounds:r,scaleX:d,scaleY:c}}};let T={};const{get:D,rotateOfOuter:I,translate:F,scaleOfOuter:H,scale:z,rotate:V}=t.MatrixHelper;function Y(t,e,n,i,s,o,a){const r=D();F(r,e.x+n,e.y+i),z(r,s,o),a&&I(r,{x:e.x+e.width/2,y:e.y+e.height/2},a),t.transform=r}function G(t,e,n,i,s,o,a){const r=D();F(r,e.x+n,e.y+i),s&&z(r,s,o),a&&V(r,a),t.transform=r}function j(t,e,n,i,s,o,a,r,l,d){const c=D();if(l)if("center"===d)I(c,{x:n/2,y:i/2},l);else switch(V(c,l),l){case 90:F(c,i,0);break;case 180:F(c,n,i);break;case 270:F(c,0,n)}T.x=e.x+s,T.y=e.y+o,F(c,T.x,T.y),a&&H(c,T,a,r),t.transform=c}const{get:U,translate:X}=t.MatrixHelper,N=new t.Bounds,q={},Q={};function J(t,e,n,i){const{blendMode:s,sync:o}=n;s&&(t.blendMode=s),o&&(t.sync=o),t.data=Z(n,i,e)}function Z(e,n,i){let{width:s,height:o}=i;e.padding&&(n=N.set(n).shrink(e.padding));const{opacity:a,mode:r,align:l,offset:d,scale:c,size:h,rotation:u,repeat:f}=e,p=n.width===s&&n.height===o,g={mode:r},_="center"!==l&&(u||0)%180==90,w=_?o:s,m=_?s:o;let v,y,x=0,b=0;if(r&&"cover"!==r&&"fit"!==r)(c||h)&&(t.MathHelper.getScaleData(c,h,i,Q),v=Q.scaleX,y=Q.scaleY);else if(!p||u){const t=n.width/w,e=n.height/m;v=y="fit"===r?Math.min(t,e):Math.max(t,e),x+=(n.width-s*v)/2,b+=(n.height-o*y)/2}if(l){const e={x:x,y:b,width:w,height:m};v&&(e.width*=v,e.height*=y),t.AlignHelper.toPoint(l,e,n,q,!0),x+=q.x,b+=q.y}switch(d&&(x+=d.x,b+=d.y),r){case"strench":p||(s=n.width,o=n.height);break;case"normal":case"clip":(x||b||v||u)&&G(g,n,x,b,v,y,u);break;case"repeat":(!p||v||u)&&j(g,n,s,o,x,b,v,y,u,l),f||(g.repeat="repeat");break;default:v&&Y(g,n,x,b,v,y,u)}return g.transform||(n.x||n.y)&&(g.transform=U(),X(g.transform,n.x,n.y)),v&&"strench"!==r&&(g.scaleX=v,g.scaleY=y),g.width=s,g.height=o,a&&(g.opacity=a),f&&(g.repeat="string"==typeof f?"x"===f?"repeat-x":"repeat-y":"repeat"),g}let $,K=new t.Bounds;const{isSame:tt}=t.BoundsHelper;function et(t,e,n,i,s,o){if("fill"===e&&!t.__.__naturalWidth){const e=t.__;if(e.__naturalWidth=i.width/e.pixelRatio,e.__naturalHeight=i.height/e.pixelRatio,e.__autoSide)return t.forceUpdate("width"),t.__proxyData&&(t.setProxyAttr("width",e.width),t.setProxyAttr("height",e.height)),!1}return s.data||J(s,i,n,o),!0}function nt(e,n){ot(e,t.ImageEvent.LOAD,n)}function it(e,n){ot(e,t.ImageEvent.LOADED,n)}function st(e,n,i){n.error=i,e.forceUpdate("surface"),ot(e,t.ImageEvent.ERROR,n)}function ot(e,n,i){e.hasEvent(n)&&e.emitEvent(new t.ImageEvent(n,i))}function at(t,e){const{leafer:n}=t;n&&n.viewReady&&(n.renderer.ignore=e)}const{get:rt,scale:lt,copy:dt}=t.MatrixHelper,{ceil:ct,abs:ht}=Math;function ut(e,n,i){let{scaleX:s,scaleY:o}=t.ImageManager.patternLocked?e.__world:e.__nowWorld;const a=s+"-"+o;if(n.patternId===a||e.destroyed)return!1;{s=ht(s),o=ht(o);const{image:e,data:r}=n;let l,d,{width:c,height:h,scaleX:u,scaleY:f,opacity:p,transform:g,repeat:_}=r;u&&(d=rt(),dt(d,g),lt(d,1/u,1/f),s*=u,o*=f),s*=i,o*=i,c*=s,h*=o;const w=c*h;if(!_&&w>t.Platform.image.maxCacheSize)return!1;let m=t.Platform.image.maxPatternSize;if(!e.isSVG){const t=e.width*e.height;m>t&&(m=t)}w>m&&(l=Math.sqrt(w/m)),l&&(s/=l,o/=l,c/=l,h/=l),u&&(s/=u,o/=f),(g||1!==s||1!==o)&&(d||(d=rt(),g&&dt(d,g)),lt(d,1/s,1/o));const v=e.getCanvas(ct(c)||1,ct(h)||1,p),y=e.getPattern(v,_||t.Platform.origin.noRepeat||"no-repeat",d,n);return n.style=y,n.patternId=a,!0}}function ft(t,e,n,i){return new(n||(n=Promise))((function(s,o){function a(t){try{l(i.next(t))}catch(t){o(t)}}function r(t){try{l(i.throw(t))}catch(t){o(t)}}function l(t){var e;t.done?s(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,r)}l((i=i.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const{abs:pt}=Math;const gt={image:function(e,n,i,s,o){let a,r;const l=t.ImageManager.get(i);return $&&i===$.paint&&tt(s,$.boxBounds)?a=$.leafPaint:(a={type:i.type,image:l},$=l.use>1?{leafPaint:a,paint:i,boxBounds:K.set(s)}:null),(o||l.loading)&&(r={image:l,attrName:n,attrValue:i}),l.ready?(et(e,n,i,l,a,s),o&&(nt(e,r),it(e,r))):l.error?o&&st(e,r,l.error):(at(e,!0),o&&nt(e,r),a.loadId=l.load((()=>{at(e,!1),e.destroyed||(et(e,n,i,l,a,s)&&(l.hasOpacityPixel&&(e.__layout.hitCanvasChanged=!0),e.forceUpdate("surface")),it(e,r)),a.loadId=null}),(t=>{at(e,!1),st(e,r,t),a.loadId=null}))),a},checkImage:function(n,i,s,o){const{scaleX:a,scaleY:r}=t.ImageManager.patternLocked?n.__world:n.__nowWorld;if(!s.data||s.patternId===a+"-"+r&&!e.Export.running)return!1;{const{data:l}=s;if(o)if(l.repeat)o=!1;else{let{width:n,height:s}=l;n*=pt(a)*i.pixelRatio,s*=pt(r)*i.pixelRatio,l.scaleX&&(n*=l.scaleX,s*=l.scaleY),o=n*s>t.Platform.image.maxCacheSize||e.Export.running}return o?(i.save(),i.clip(),s.blendMode&&(i.blendMode=s.blendMode),l.opacity&&(i.opacity*=l.opacity),l.transform&&i.transform(l.transform),i.drawImage(s.image.view,0,0,l.width,l.height),i.restore(),!0):(!s.style||s.sync||e.Export.running?ut(n,s,i.pixelRatio):s.patternTask||(s.patternTask=t.ImageManager.patternTasker.add((()=>ft(this,void 0,void 0,(function*(){s.patternTask=null,i.bounds.hit(n.__nowWorld)&&ut(n,s,i.pixelRatio),n.forceUpdate("surface")}))),300)),!1)}},createPattern:ut,recycleImage:function(e,n){const i=n["_"+e];if(i instanceof Array){let s,o,a,r;for(let l=0,d=i.length;l<d;l++)s=i[l].image,r=s&&s.url,r&&(o||(o={}),o[r]=!0,t.ImageManager.recycle(s),s.loading&&(a||(a=n.__input&&n.__input[e]||[],a instanceof Array||(a=[a])),s.unload(i[l].loadId,!a.some((t=>t.url===r)))));return o}return null},createData:J,getPatternData:Z,fillOrFitMode:Y,clipMode:G,repeatMode:j},{toPoint:_t}=t.AroundHelper,wt={},mt={};function vt(t,n,i){let s;for(let o=0,a=n.length;o<a;o++)s=n[o],"string"==typeof s?t.addColorStop(o/(a-1),e.ColorConvert.string(s,i)):t.addColorStop(s.offset,e.ColorConvert.string(s.color,i))}const{getAngle:yt,getDistance:xt}=t.PointHelper,{get:bt,rotateOfOuter:Bt,scaleOfOuter:Et}=t.MatrixHelper,{toPoint:Rt}=t.AroundHelper,Lt={},kt={};function Pt(t,e,n,i,s){let o;const{width:a,height:r}=t;if(a!==r||i){const t=yt(e,n);o=bt(),s?(Et(o,e,a/r*(i||1),1),Bt(o,e,t+90)):(Et(o,e,1,a/r*(i||1)),Bt(o,e,t))}return o}const{getDistance:St}=t.PointHelper,{toPoint:Ct}=t.AroundHelper,Ot={},At={};const Wt={linearGradient:function(e,n){let{from:i,to:s,type:o,blendMode:a,opacity:r}=e;_t(i||"top",n,wt),_t(s||"bottom",n,mt);const l=t.Platform.canvas.createLinearGradient(wt.x,wt.y,mt.x,mt.y);vt(l,e.stops,r);const d={type:o,style:l};return a&&(d.blendMode=a),d},radialGradient:function(e,n){let{from:i,to:s,type:o,opacity:a,blendMode:r,stretch:l}=e;Rt(i||"center",n,Lt),Rt(s||"bottom",n,kt);const d=t.Platform.canvas.createRadialGradient(Lt.x,Lt.y,0,Lt.x,Lt.y,xt(Lt,kt));vt(d,e.stops,a);const c={type:o,style:d},h=Pt(n,Lt,kt,l,!0);return h&&(c.transform=h),r&&(c.blendMode=r),c},conicGradient:function(e,n){let{from:i,to:s,type:o,opacity:a,blendMode:r,stretch:l}=e;Ct(i||"center",n,Ot),Ct(s||"bottom",n,At);const d=t.Platform.conicGradientSupport?t.Platform.canvas.createConicGradient(0,Ot.x,Ot.y):t.Platform.canvas.createRadialGradient(Ot.x,Ot.y,0,Ot.x,Ot.y,St(Ot,At));vt(d,e.stops,a);const c={type:o,style:d},h=Pt(n,Ot,At,l||1,t.Platform.conicGradientRotate90);return h&&(c.transform=h),r&&(c.blendMode=r),c},getTransform:Pt},{copy:Mt,toOffsetOutBounds:Tt}=t.BoundsHelper,Dt={},It={};function Ft(e,n,i,s){const{bounds:o,shapeBounds:a}=s;if(t.Platform.fullImageShadow){if(Mt(Dt,e.bounds),Dt.x+=n.x-a.x,Dt.y+=n.y-a.y,i){const{matrix:t}=s;Dt.x-=(o.x+(t?t.e:0)+o.width/2)*(i-1),Dt.y-=(o.y+(t?t.f:0)+o.height/2)*(i-1),Dt.width*=i,Dt.height*=i}e.copyWorld(s.canvas,e.bounds,Dt)}else i&&(Mt(Dt,n),Dt.x-=n.width/2*(i-1),Dt.y-=n.height/2*(i-1),Dt.width*=i,Dt.height*=i),e.copyWorld(s.canvas,a,i?Dt:n)}const{toOffsetOutBounds:Ht}=t.BoundsHelper,zt={};const Vt={shadow:function(t,e,n){let i,s;const{__nowWorld:o,__layout:a}=t,{shadow:r}=t.__,{worldCanvas:l,bounds:d,shapeBounds:c,scaleX:h,scaleY:u}=n,f=e.getSameCanvas(),p=r.length-1;Tt(d,It),r.forEach(((r,g)=>{f.setWorldShadow(It.offsetX+r.x*h,It.offsetY+r.y*u,r.blur*h,r.color),s=r.spread?1+2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Ft(f,It,s,n),i=d,r.box&&(f.restore(),f.save(),l&&(f.copyWorld(f,d,o,"copy"),i=o),l?f.copyWorld(l,o,o,"destination-out"):f.copyWorld(n.canvas,c,d,"destination-out")),t.__worldFlipped?e.copyWorldByReset(f,i,o,r.blendMode):e.copyWorldToInner(f,i,a.renderBounds,r.blendMode),p&&g<p&&f.clearWorld(i,!0)})),f.recycle(i)},innerShadow:function(t,e,n){let i,s;const{__nowWorld:o,__layout:a}=t,{innerShadow:r}=t.__,{worldCanvas:l,bounds:d,shapeBounds:c,scaleX:h,scaleY:u}=n,f=e.getSameCanvas(),p=r.length-1;Ht(d,zt),r.forEach(((r,g)=>{f.save(),f.setWorldShadow(zt.offsetX+r.x*h,zt.offsetY+r.y*u,r.blur*h),s=r.spread?1-2*r.spread/(a.boxBounds.width+2*(a.strokeBoxSpread||0)):0,Ft(f,zt,s,n),f.restore(),l?(f.copyWorld(f,d,o,"copy"),f.copyWorld(l,o,o,"source-out"),i=o):(f.copyWorld(n.canvas,c,d,"source-out"),i=d),f.fillWorld(i,r.color,"source-in"),t.__worldFlipped?e.copyWorldByReset(f,i,o,r.blendMode):e.copyWorldToInner(f,i,a.renderBounds,r.blendMode),p&&g<p&&f.clearWorld(i,!0)})),f.recycle(i)},blur:function(t,e,n){const{blur:i}=t.__;n.setWorldBlur(i*t.__nowWorld.a),n.copyWorldToInner(e,t.__nowWorld,t.__layout.renderBounds),n.filter="none"},backgroundBlur:function(t,e,n){}},{excludeRenderBounds:Yt}=t.LeafBoundsHelper;function Gt(t,e,n,i,s,o){switch(e){case"alpha":!function(t,e,n,i){const s=t.__nowWorld;n.resetTransform(),n.opacity=1,n.useMask(i,s),i.recycle(s),Ut(t,e,n,1)}(t,n,i,s);break;case"opacity-path":Ut(t,n,i,o);break;case"path":n.restore()}}function jt(t){return t.getSameCanvas(!1,!0)}function Ut(t,e,n,i){const s=t.__nowWorld;e.resetTransform(),e.opacity=i,e.copyWorld(n,s),n.recycle(s)}e.Group.prototype.__renderMask=function(t,e){let n,i,s,o,a;const{children:r}=this;for(let l=0,d=r.length;l<d;l++)n=r[l],n.__.mask&&(a&&(Gt(this,a,t,s,i,o),i=s=null),"path"===n.__.mask?(n.opacity<1?(a="opacity-path",o=n.opacity,s||(s=jt(t))):(a="path",t.save()),n.__clip(s||t,e)):(a="alpha",i||(i=jt(t)),s||(s=jt(t)),n.__render(i,e)),"clipping"!==n.__.mask)||Yt(n,e)||n.__render(s||t,e);Gt(this,a,t,s,i,o)};const Xt=">)]}%!?,.:;'\"》)」〉』〗】〕}┐>’”!?,、。:;‰",Nt=Xt+"_#~&*+\\=|≮≯≈≠=…",qt=new RegExp([[19968,40959],[13312,19903],[131072,173791],[173824,177983],[177984,178207],[178208,183983],[183984,191471],[196608,201551],[201552,205743],[11904,12031],[12032,12255],[12272,12287],[12288,12351],[12736,12783],[12800,13055],[13056,13311],[63744,64255],[65072,65103],[127488,127743],[194560,195103]].map((([t,e])=>`[\\u${t.toString(16)}-\\u${e.toString(16)}]`)).join("|"));function Qt(t){const e={};return t.split("").forEach((t=>e[t]=!0)),e}const Jt=Qt("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"),Zt=Qt("{[(<'\"《(「〈『〖【〔{┌<‘“=¥¥$€££¢¢"),$t=Qt(Xt),Kt=Qt(Nt),te=Qt("- —/~|┆·");var ee;!function(t){t[t.Letter=0]="Letter",t[t.Single=1]="Single",t[t.Before=2]="Before",t[t.After=3]="After",t[t.Symbol=4]="Symbol",t[t.Break=5]="Break"}(ee||(ee={}));const{Letter:ne,Single:ie,Before:se,After:oe,Symbol:ae,Break:re}=ee;function le(t){return Jt[t]?ne:te[t]?re:Zt[t]?se:$t[t]?oe:Kt[t]?ae:qt.test(t)?ie:ne}const de={trimRight(t){const{words:e}=t;let n,i=0,s=e.length;for(let o=s-1;o>-1&&(n=e[o].data[0]," "===n.char);o--)i++,t.width-=n.width;i&&e.splice(s-i,i)}};function ce(t,e,n){switch(e){case"title":return n?t.toUpperCase():t;case"upper":return t.toUpperCase();case"lower":return t.toLowerCase();default:return t}}const{trimRight:he}=de,{Letter:ue,Single:fe,Before:pe,After:ge,Symbol:_e,Break:we}=ee;let me,ve,ye,xe,be,Be,Ee,Re,Le,ke,Pe,Se,Ce,Oe,Ae,We,Me=[];function Te(t,e){Le&&!Re&&(Re=Le),me.data.push({char:t,width:e}),ye+=e}function De(){xe+=ye,me.width=ye,ve.words.push(me),me={data:[]},ye=0}function Ie(){Oe&&(Ae.paraNumber++,ve.paraStart=!0,Oe=!1),Le&&(ve.startCharSize=Re,ve.endCharSize=Le,Re=0),ve.width=xe,We.width&&he(ve),Me.push(ve),ve={words:[]},xe=0}const Fe=0,He=1,ze=2;const{top:Ve,right:Ye,bottom:Ge,left:je}=t.Direction4;function Ue(t,e,n){const{bounds:i,rows:s}=t;i[e]+=n;for(let t=0;t<s.length;t++)s[t][e]+=n}const Xe={getDrawData:function(e,n){"string"!=typeof e&&(e=String(e));let i=0,s=0,o=n.__getInput("width")||0,a=n.__getInput("height")||0;const{textDecoration:r,__font:l,__padding:d}=n;d&&(o&&(i=d[je],o-=d[Ye]+d[je]),a&&(s=d[Ve],a-=d[Ve]+d[Ge]));const c={bounds:{x:i,y:s,width:o,height:a},rows:[],paraNumber:0,font:t.Platform.canvas.font=l};return function(e,n,i){Ae=e,Me=e.rows,We=e.bounds;const{__letterSpacing:s,paraIndent:o,textCase:a}=i,{canvas:r}=t.Platform,{width:l,height:d}=We;if(l||d||s||"none"!==a){const t="none"!==i.textWrap,e="break"===i.textWrap;Oe=!0,Pe=null,Re=Ee=Le=ye=xe=0,me={data:[]},ve={words:[]};for(let i=0,d=n.length;i<d;i++)Be=n[i],"\n"===Be?(ye&&De(),ve.paraEnd=!0,Ie(),Oe=!0):(ke=le(Be),ke===ue&&"none"!==a&&(Be=ce(Be,a,!ye)),Ee=r.measureText(Be).width,s&&(s<0&&(Le=Ee),Ee+=s),Se=ke===fe&&(Pe===fe||Pe===ue)||Pe===fe&&ke!==ge,Ce=!(ke!==pe&&ke!==fe||Pe!==_e&&Pe!==ge),be=Oe&&o?l-o:l,t&&l&&xe+ye+Ee>be&&(e?(ye&&De(),xe&&Ie()):(Ce||(Ce=ke===ue&&Pe==ge),Se||Ce||ke===we||ke===pe||ke===fe||ye+Ee>be?(ye&&De(),xe&&Ie()):xe&&Ie()))," "===Be&&!0!==Oe&&xe+ye===0||(ke===we?(" "===Be&&ye&&De(),Te(Be,Ee),De()):Se||Ce?(ye&&De(),Te(Be,Ee)):Te(Be,Ee)),Pe=ke);ye&&De(),xe&&Ie(),Me.length>0&&(Me[Me.length-1].paraEnd=!0)}else n.split("\n").forEach((t=>{Ae.paraNumber++,Me.push({x:o||0,text:t,width:r.measureText(t).width,paraStart:!0})}))}(c,e,n),d&&function(t,e,n,i,s){if(!i)switch(n.textAlign){case"left":Ue(e,"x",t[je]);break;case"right":Ue(e,"x",-t[Ye])}if(!s)switch(n.verticalAlign){case"top":Ue(e,"y",t[Ve]);break;case"bottom":Ue(e,"y",-t[Ge])}}(d,c,n,o,a),function(t,e){const{rows:n,bounds:i}=t,{__lineHeight:s,__baseLine:o,__letterSpacing:a,__clipText:r,textAlign:l,verticalAlign:d,paraSpacing:c}=e;let h,u,f,{x:p,y:g,width:_,height:w}=i,m=s*n.length+(c?c*(t.paraNumber-1):0),v=o;if(r&&m>w)m=Math.max(w,s),t.overflow=n.length;else switch(d){case"middle":g+=(w-m)/2;break;case"bottom":g+=w-m}v+=g;for(let o=0,d=n.length;o<d;o++){if(h=n[o],h.x=p,h.width<_||h.width>_&&!r)switch(l){case"center":h.x+=(_-h.width)/2;break;case"right":h.x+=_-h.width}h.paraStart&&c&&o>0&&(v+=c),h.y=v,v+=s,t.overflow>o&&v>m&&(h.isOverflow=!0,t.overflow=o+1),u=h.x,f=h.width,a<0&&(h.width<0?(f=-h.width+e.fontSize+a,u-=f,f+=e.fontSize):f-=a),u<i.x&&(i.x=u),f>i.width&&(i.width=f),r&&_&&_<f&&(h.isOverflow=!0,t.overflow||(t.overflow=n.length))}i.y=g,i.height=m}(c,n),function(t,e,n,i){const{rows:s}=t,{textAlign:o,paraIndent:a,letterSpacing:r}=e;let l,d,c,h,u;s.forEach((t=>{t.words&&(c=a&&t.paraStart?a:0,d=n&&"justify"===o&&t.words.length>1?(n-t.width-c)/(t.words.length-1):0,h=r||t.isOverflow?Fe:d>.01?He:ze,t.isOverflow&&!r&&(t.textMode=!0),h===ze?(t.x+=c,function(t){t.text="",t.words.forEach((e=>{e.data.forEach((e=>{t.text+=e.char}))}))}(t)):(t.x+=c,l=t.x,t.data=[],t.words.forEach((e=>{h===He?(u={char:"",x:l},l=function(t,e,n){return t.forEach((t=>{n.char+=t.char,e+=t.width})),e}(e.data,l,u),(t.isOverflow||" "!==u.char)&&t.data.push(u)):l=function(t,e,n,i){return t.forEach((t=>{(i||" "!==t.char)&&(t.x=e,n.push(t)),e+=t.width})),e}(e.data,l,t.data,t.isOverflow),!t.paraEnd&&d&&(l+=d,t.width+=d)}))),t.words=null)}))}(c,n,o),c.overflow&&function(e,n,i,s){if(!s)return;const{rows:o,overflow:a}=e;let{textOverflow:r}=n;if(o.splice(a),r&&"show"!==r){let e,l;"hide"===r?r="":"ellipsis"===r&&(r="...");const d=r?t.Platform.canvas.measureText(r).width:0,c=i+s-d;("none"===n.textWrap?o:[o[a-1]]).forEach((t=>{if(t.isOverflow&&t.data){let n=t.data.length-1;for(let i=n;i>-1&&(e=t.data[i],l=e.x+e.width,!(i===n&&l<c));i--){if(l<c&&" "!==e.char){t.data.splice(i+1),t.width-=e.width;break}t.width-=e.width}t.width+=d,t.data.push({char:r,x:l}),t.textMode&&function(t){t.text="",t.data.forEach((e=>{t.text+=e.char})),t.data=null}(t)}}))}}(c,n,i,o),"none"!==r&&function(t,e){const{fontSize:n}=e;switch(t.decorationHeight=n/11,e.textDecoration){case"under":t.decorationY=.15*n;break;case"delete":t.decorationY=.35*-n}}(c,n),c}};const Ne={string:function(t,e){if("string"==typeof t)return t;let n=void 0===t.a?1:t.a;e&&(n*=e);const i=t.r+","+t.g+","+t.b;return 1===n?"rgb("+i+")":"rgba("+i+","+n+")"}},{setPoint:qe,addPoint:Qe,toBounds:Je}=t.TwoPointBoundsHelper;const Ze={export(e,n,i){this.running=!0;const s=t.FileHelper.fileType(n),o=n.includes(".");return i=t.FileHelper.getExportOptions(i),function(e){$e||($e=new t.TaskProcessor);return new Promise((t=>{$e.add((()=>ft(this,void 0,void 0,(function*(){return yield e(t)}))),{parallel:!1})}))}((a=>new Promise((r=>{const l=t=>{a(t),r(),this.running=!1},{toURL:d}=t.Platform,{download:c}=t.Platform.origin;if("json"===s)return o&&c(d(JSON.stringify(e.toJSON(i.json)),"text"),n),l({data:!!o||e.toJSON(i.json)});if("svg"===s)return o&&c(d(e.toSVG(),"svg"),n),l({data:!!o||e.toSVG()});const{leafer:h}=e;h?(Ke(e),h.waitViewCompleted((()=>ft(this,void 0,void 0,(function*(){let s,o,a=1,r=1;const{worldTransform:d,isLeafer:c,isFrame:u}=e,{slice:f,trim:p,onCanvas:g}=i,_=void 0===i.smooth?h.config.smooth:i.smooth,w=i.contextSettings||h.config.contextSettings,m=i.screenshot||e.isApp,v=c&&m&&void 0===i.fill?e.fill:i.fill,y=t.FileHelper.isOpaqueImage(n)||v,x=new t.Matrix;if(m)s=!0===m?c?h.canvas.bounds:e.worldRenderBounds:m;else{let t=i.relative||(c?"inner":"local");switch(a=d.scaleX,r=d.scaleY,t){case"inner":x.set(d);break;case"local":x.set(d).divide(e.localTransform),a/=e.scaleX,r/=e.scaleY;break;case"world":a=1,r=1;break;case"page":t=e.leafer;default:x.set(d).divide(e.getTransform(t));const n=t.worldTransform;a/=a/n.scaleX,r/=r/n.scaleY}s=e.getBounds("render",t)}const b={scaleX:1,scaleY:1};t.MathHelper.getScaleData(i.scale,i.size,s,b);let B=i.pixelRatio||1;e.isApp&&(b.scaleX*=B,b.scaleY*=B,B=e.app.pixelRatio);const{x:E,y:R,width:L,height:k}=new t.Bounds(s).scale(b.scaleX,b.scaleY),P={matrix:x.scale(1/b.scaleX,1/b.scaleY).invert().translate(-E,-R).withScale(1/a*b.scaleX,1/r*b.scaleY)};let S,C=t.Creator.canvas({width:Math.round(L),height:Math.round(k),pixelRatio:B,smooth:_,contextSettings:w});if(f&&(S=e,S.__worldOpacity=0,e=h,P.bounds=C.bounds),C.save(),u&&void 0!==v){const t=e.get("fill");e.fill="",e.__render(C,P),e.fill=t}else e.__render(C,P);if(C.restore(),S&&S.__updateWorldOpacity(),p){o=function(e){const{width:n,height:i}=e.view,{data:s}=e.context.getImageData(0,0,n,i);let o,a,r,l=0;for(let t=0;t<s.length;t+=4)0!==s[t+3]&&(o=l%n,a=(l-o)/n,r?Qe(r,o,a):qe(r={},o,a)),l++;const d=new t.Bounds;return Je(r,d),d.scale(1/e.pixelRatio).ceil()}(C);const e=C,{width:n,height:i}=o,s={x:0,y:0,width:n,height:i,pixelRatio:B};C=t.Creator.canvas(s),C.copyWorld(e,o,s)}y&&C.fillWorld(C.bounds,v||"#FFFFFF","destination-over"),g&&g(C);const O="canvas"===n?C:yield C.export(n,i);l({data:O,width:C.pixelWidth,height:C.pixelHeight,renderBounds:s,trimBounds:o})}))))):l({data:!1})}))))}};let $e;function Ke(t){t.__.__needComputePaint&&t.__.__computePaint(),t.isBranch&&t.children.forEach((t=>Ke(t)))}const tn=t.LeaferCanvasBase.prototype,en=t.Debug.get("@leafer-ui/export");tn.export=function(e,n){const{quality:i,blob:s}=t.FileHelper.getExportOptions(n);return e.includes(".")?this.saveAs(e,i):s?this.toBlob(e,i):this.toDataURL(e,i)},tn.toBlob=function(e,n){return new Promise((i=>{t.Platform.origin.canvasToBolb(this.view,e,n).then((t=>{i(t)})).catch((t=>{en.error(t),i(null)}))}))},tn.toDataURL=function(e,n){return t.Platform.origin.canvasToDataURL(this.view,e,n)},tn.saveAs=function(e,n){return new Promise((i=>{t.Platform.origin.canvasSaveAs(this.view,e,n).then((()=>{i(!0)})).catch((t=>{en.error(t),i(!1)}))}))},Object.assign(e.TextConvert,Xe),Object.assign(e.ColorConvert,Ne),Object.assign(e.Paint,M),Object.assign(e.PaintImage,gt),Object.assign(e.PaintGradient,Wt),Object.assign(e.Effect,Vt),Object.assign(e.Export,Ze),a(),Object.defineProperty(exports,"LeaferImage",{enumerable:!0,get:function(){return t.LeaferImage}}),exports.Layouter=y,exports.LeaferCanvas=i,exports.Renderer=b,exports.Watcher=l,exports.useCanvas=a,Object.keys(t).forEach((function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return t[e]}})})),Object.keys(e).forEach((function(t){"default"===t||Object.prototype.hasOwnProperty.call(exports,t)||Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})}));