@leafer-ui/miniapp 1.0.0-rc.7 → 1.0.0-rc.9

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.
@@ -101,14 +101,14 @@ const PI_2 = PI$4 / 2;
101
101
  const { sin: sin$5, cos: cos$5, acos, sqrt: sqrt$3 } = Math;
102
102
  const { float } = MathHelper;
103
103
  const tempPoint$2 = {};
104
- function get$5() {
104
+ function get$6() {
105
105
  return { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 };
106
106
  }
107
107
  function getWorld() {
108
- return Object.assign(Object.assign({}, get$5()), { x: 0, y: 0, width: 0, height: 0, scaleX: 1, scaleY: 1, rotation: 0, skewX: 0, skewY: 0 });
108
+ return Object.assign(Object.assign({}, get$6()), { x: 0, y: 0, width: 0, height: 0, scaleX: 1, scaleY: 1, rotation: 0, skewX: 0, skewY: 0 });
109
109
  }
110
110
  const MatrixHelper = {
111
- defaultMatrix: get$5(),
111
+ defaultMatrix: get$6(),
112
112
  defaultWorld: getWorld(),
113
113
  tempMatrix: {},
114
114
  set(t, a = 1, b = 0, c = 0, d = 1, e = 0, f = 0) {
@@ -119,7 +119,7 @@ const MatrixHelper = {
119
119
  t.e = e;
120
120
  t.f = f;
121
121
  },
122
- get: get$5,
122
+ get: get$6,
123
123
  getWorld,
124
124
  copy(t, matrix) {
125
125
  t.a = matrix.a;
@@ -682,7 +682,7 @@ const { addPoint: addPoint$3 } = TwoPointBoundsHelper;
682
682
 
683
683
  const { tempPointBounds: tempPointBounds$1, setPoint: setPoint$2, addPoint: addPoint$2, toBounds: toBounds$3 } = TwoPointBoundsHelper;
684
684
  const { toOuterPoint: toOuterPoint$1 } = MatrixHelper;
685
- let right, bottom, boundsRight, boundsBottom;
685
+ let right$1, bottom$1, boundsRight, boundsBottom;
686
686
  const point = {};
687
687
  const toPoint$1 = {};
688
688
  const BoundsHelper = {
@@ -825,16 +825,16 @@ const BoundsHelper = {
825
825
  }
826
826
  },
827
827
  add(t, bounds) {
828
- right = t.x + t.width;
829
- bottom = t.y + t.height;
828
+ right$1 = t.x + t.width;
829
+ bottom$1 = t.y + t.height;
830
830
  boundsRight = bounds.x + bounds.width;
831
831
  boundsBottom = bounds.y + bounds.height;
832
- right = right > boundsRight ? right : boundsRight;
833
- bottom = bottom > boundsBottom ? bottom : boundsBottom;
832
+ right$1 = right$1 > boundsRight ? right$1 : boundsRight;
833
+ bottom$1 = bottom$1 > boundsBottom ? bottom$1 : boundsBottom;
834
834
  t.x = t.x < bounds.x ? t.x : bounds.x;
835
835
  t.y = t.y < bounds.y ? t.y : bounds.y;
836
- t.width = right - t.x;
837
- t.height = bottom - t.y;
836
+ t.width = right$1 - t.x;
837
+ t.height = bottom$1 - t.y;
838
838
  },
839
839
  addList(t, list) {
840
840
  B.setListWithFn(t, list, undefined, true);
@@ -900,16 +900,16 @@ const BoundsHelper = {
900
900
  if (otherMatrix)
901
901
  other = B.tempToOuterOf(other, otherMatrix);
902
902
  let { x, y, width, height } = other;
903
- right = x + width;
904
- bottom = y + height;
903
+ right$1 = x + width;
904
+ bottom$1 = y + height;
905
905
  boundsRight = t.x + t.width;
906
906
  boundsBottom = t.y + t.height;
907
907
  x = x > t.x ? x : t.x;
908
908
  y = y > t.y ? y : t.y;
909
- right = right < boundsRight ? right : boundsRight;
910
- bottom = bottom < boundsBottom ? bottom : boundsBottom;
911
- width = right - x;
912
- height = bottom - y;
909
+ right$1 = right$1 < boundsRight ? right$1 : boundsRight;
910
+ bottom$1 = bottom$1 < boundsBottom ? bottom$1 : boundsBottom;
911
+ width = right$1 - x;
912
+ height = bottom$1 - y;
913
913
  return { x, y, width, height };
914
914
  },
915
915
  intersect(t, other, otherMatrix) {
@@ -1053,25 +1053,55 @@ class AutoBounds {
1053
1053
  }
1054
1054
  }
1055
1055
 
1056
- const center = { x: 0.5, y: 0.5 };
1056
+ var Direction4;
1057
+ (function (Direction4) {
1058
+ Direction4[Direction4["top"] = 0] = "top";
1059
+ Direction4[Direction4["right"] = 1] = "right";
1060
+ Direction4[Direction4["bottom"] = 2] = "bottom";
1061
+ Direction4[Direction4["left"] = 3] = "left";
1062
+ })(Direction4 || (Direction4 = {}));
1063
+ var Direction9;
1064
+ (function (Direction9) {
1065
+ Direction9[Direction9["topLeft"] = 0] = "topLeft";
1066
+ Direction9[Direction9["top"] = 1] = "top";
1067
+ Direction9[Direction9["topRight"] = 2] = "topRight";
1068
+ Direction9[Direction9["right"] = 3] = "right";
1069
+ Direction9[Direction9["bottomRight"] = 4] = "bottomRight";
1070
+ Direction9[Direction9["bottom"] = 5] = "bottom";
1071
+ Direction9[Direction9["bottomLeft"] = 6] = "bottomLeft";
1072
+ Direction9[Direction9["left"] = 7] = "left";
1073
+ Direction9[Direction9["center"] = 8] = "center";
1074
+ })(Direction9 || (Direction9 = {}));
1075
+
1076
+ const directionData = [
1077
+ { x: 0, y: 0 },
1078
+ { x: 0.5, y: 0 },
1079
+ { x: 1, y: 0 },
1080
+ { x: 1, y: 0.5 },
1081
+ { x: 1, y: 1 },
1082
+ { x: 0.5, y: 1 },
1083
+ { x: 0, y: 1 },
1084
+ { x: 0, y: 0.5 },
1085
+ { x: 0.5, y: 0.5 }
1086
+ ];
1057
1087
  const AroundHelper = {
1058
- center,
1088
+ directionData,
1059
1089
  tempPoint: {},
1090
+ get: get$5,
1060
1091
  toPoint(around, bounds, to, onlySize) {
1061
1092
  to || (to = {});
1062
- switch (around) {
1063
- case 'center':
1064
- around = center;
1065
- break;
1066
- }
1067
- to.x = around.x * bounds.width;
1068
- to.y = around.y * bounds.height;
1093
+ const point = get$5(around);
1094
+ to.x = point.x * bounds.width;
1095
+ to.y = point.y * bounds.height;
1069
1096
  if (!onlySize) {
1070
1097
  to.x += bounds.x;
1071
1098
  to.y += bounds.y;
1072
1099
  }
1073
1100
  }
1074
1101
  };
1102
+ function get$5(around) {
1103
+ return typeof around === 'string' ? directionData[Direction9[around]] : around;
1104
+ }
1075
1105
 
1076
1106
  const StringNumberMap = {
1077
1107
  '0': 1,
@@ -3086,7 +3116,6 @@ const PathScaler = {
3086
3116
  break;
3087
3117
  case G$1:
3088
3118
  scalePoints(data, scaleX, scaleY, i, 2);
3089
- console.log('G');
3090
3119
  i += 9;
3091
3120
  break;
3092
3121
  case F$1:
@@ -3801,7 +3830,7 @@ LayoutEvent.CHECK_UPDATE = 'layout.check_update';
3801
3830
  LayoutEvent.REQUEST = 'layout.request';
3802
3831
  LayoutEvent.START = 'layout.start';
3803
3832
  LayoutEvent.BEFORE = 'layout.before';
3804
- LayoutEvent.LAYOUT = 'layout.layout';
3833
+ LayoutEvent.LAYOUT = 'layout';
3805
3834
  LayoutEvent.AFTER = 'layout.after';
3806
3835
  LayoutEvent.AGAIN = 'layout.again';
3807
3836
  LayoutEvent.END = 'layout.end';
@@ -4450,13 +4479,10 @@ const LeafHelper = {
4450
4479
  }
4451
4480
  },
4452
4481
  worldHittable(t) {
4453
- if (!t.__.hittable)
4454
- return false;
4455
- let { parent } = t;
4456
- while (parent) {
4457
- if (!parent.__.hittable || !parent.__.hitChildren)
4482
+ while (t) {
4483
+ if (!t.__.hittable)
4458
4484
  return false;
4459
- parent = parent.parent;
4485
+ t = t.parent;
4460
4486
  }
4461
4487
  return true;
4462
4488
  },
@@ -5909,7 +5935,7 @@ const LeafRender = {
5909
5935
  canvas.setWorld(this.__world, options.matrix);
5910
5936
  canvas.opacity = this.__worldOpacity;
5911
5937
  if (this.__.__single) {
5912
- const tempCanvas = canvas.getSameCanvas(true);
5938
+ const tempCanvas = canvas.getSameCanvas(true, true);
5913
5939
  this.__draw(tempCanvas, options);
5914
5940
  const blendMode = this.__.isEraser ? 'destination-out' : this.__.blendMode;
5915
5941
  if (this.__worldFlipped || options.matrix) {
@@ -5986,7 +6012,7 @@ const BranchRender = {
5986
6012
  if (this.__worldOpacity) {
5987
6013
  if (this.__.__single) {
5988
6014
  canvas.resetTransform();
5989
- const tempCanvas = canvas.getSameCanvas();
6015
+ const tempCanvas = canvas.getSameCanvas(false, true);
5990
6016
  this.__renderBranch(tempCanvas, options);
5991
6017
  canvas.opacity = this.__worldOpacity;
5992
6018
  const blendMode = this.__.isEraser ? 'destination-out' : this.__.blendMode;
@@ -7814,6 +7840,9 @@ class FrameData extends BoxData {
7814
7840
  class LineData extends UIData {
7815
7841
  }
7816
7842
 
7843
+ class ArrowData extends LineData {
7844
+ }
7845
+
7817
7846
  class RectData extends UIData {
7818
7847
  get __boxStroke() { return true; }
7819
7848
  }
@@ -7872,6 +7901,25 @@ class TextData extends UIData {
7872
7901
  }
7873
7902
 
7874
7903
  class ImageData extends RectData {
7904
+ setUrl(value) {
7905
+ this.__setImageFill(value);
7906
+ this._url = value;
7907
+ }
7908
+ __setImageFill(value) {
7909
+ if (this.__leaf.image)
7910
+ this.__leaf.image = null;
7911
+ this.fill = value ? { type: 'image', mode: 'strench', url: value } : undefined;
7912
+ }
7913
+ __getData() {
7914
+ const data = super.__getData();
7915
+ delete data.fill;
7916
+ return data;
7917
+ }
7918
+ __getInputData() {
7919
+ const data = super.__getInputData();
7920
+ delete data.fill;
7921
+ return data;
7922
+ }
7875
7923
  }
7876
7924
 
7877
7925
  class CanvasData extends RectData {
@@ -8118,14 +8166,15 @@ let UI = UI_1 = class UI extends Leaf {
8118
8166
  findOne(condition, options) {
8119
8167
  return this.leafer ? this.leafer.selector.getBy(condition, this, true, options) : null;
8120
8168
  }
8121
- getPath(curve) {
8122
- const { path } = this.__;
8169
+ getPath(curve, pathForRender) {
8170
+ this.__layout.update();
8171
+ let path = pathForRender ? this.__.__pathForRender : this.__.path;
8123
8172
  if (!path)
8124
- return [];
8173
+ this.__drawPathByBox(new PathCreator(path = []));
8125
8174
  return curve ? PathConvert.toCanvasData(path, true) : path;
8126
8175
  }
8127
- getPathString(curve) {
8128
- return PathConvert.stringify(this.getPath(curve));
8176
+ getPathString(curve, pathForRender) {
8177
+ return PathConvert.stringify(this.getPath(curve, pathForRender));
8129
8178
  }
8130
8179
  __onUpdateSize() {
8131
8180
  if (this.__.__input) {
@@ -8297,6 +8346,12 @@ __decorate([
8297
8346
  __decorate([
8298
8347
  strokeType(10)
8299
8348
  ], UI.prototype, "miterLimit", void 0);
8349
+ __decorate([
8350
+ strokeType('none')
8351
+ ], UI.prototype, "startArrow", void 0);
8352
+ __decorate([
8353
+ strokeType('none')
8354
+ ], UI.prototype, "endArrow", void 0);
8300
8355
  __decorate([
8301
8356
  pathType(0)
8302
8357
  ], UI.prototype, "cornerRadius", void 0);
@@ -8793,26 +8848,10 @@ let Image = class Image extends Rect {
8793
8848
  get ready() { return this.image ? this.image.ready : false; }
8794
8849
  constructor(data) {
8795
8850
  super(data);
8796
- }
8797
- __updateBoxBounds() {
8798
- let update;
8799
- const { url } = this;
8800
- const fill = this.fill;
8801
- if (fill) {
8802
- if (fill.url !== url)
8803
- update = true;
8804
- }
8805
- else {
8806
- if (url)
8807
- update = true;
8808
- }
8809
- if (update) {
8810
- if (this.image)
8811
- this.image = null;
8812
- this.fill = url ? { type: 'image', mode: 'strench', url } : undefined;
8813
- this.once(ImageEvent.LOADED, (e) => this.image = e.image);
8814
- }
8815
- super.__updateBoxBounds();
8851
+ this.on(ImageEvent.LOADED, (e) => {
8852
+ if (e.attrName === 'fill' && e.attrValue.url === this.url)
8853
+ this.image = e.image;
8854
+ });
8816
8855
  }
8817
8856
  destroy() {
8818
8857
  this.image = null;
@@ -8942,11 +8981,12 @@ let Text = class Text extends UI {
8942
8981
  __updateBoxBounds() {
8943
8982
  const data = this.__;
8944
8983
  const layout = this.__layout;
8945
- const { lineHeight, letterSpacing, fontFamily, fontSize, fontWeight, italic, textCase, textOverflow } = data;
8984
+ const { lineHeight, letterSpacing, fontFamily, fontSize, fontWeight, italic, textCase, textOverflow, padding } = data;
8946
8985
  const autoWidth = data.__autoWidth;
8947
8986
  const autoHeight = data.__autoHeight;
8948
8987
  data.__lineHeight = UnitConvert.number(lineHeight, fontSize);
8949
8988
  data.__letterSpacing = UnitConvert.number(letterSpacing, fontSize);
8989
+ data.__padding = padding ? MathHelper.fourNumber(padding) : undefined;
8950
8990
  data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * 0.7) / 2;
8951
8991
  data.__font = `${italic ? 'italic ' : ''}${textCase === 'small-caps' ? 'small-caps ' : ''}${fontWeight !== 'normal' ? fontWeight + ' ' : ''}${fontSize}px ${fontFamily}`;
8952
8992
  data.__clipText = textOverflow !== 'show' && !data.__autoBounds;
@@ -8960,9 +9000,8 @@ let Text = class Text extends UI {
8960
9000
  b.y = autoHeight ? bounds.y : 0;
8961
9001
  b.width = autoWidth ? bounds.width : data.width;
8962
9002
  b.height = autoHeight ? bounds.height : data.height;
8963
- const { padding } = data;
8964
9003
  if (padding) {
8965
- const [top, right, bottom, left] = MathHelper.fourNumber(padding);
9004
+ const [top, right, bottom, left] = data.__padding;
8966
9005
  if (autoWidth) {
8967
9006
  b.x -= left;
8968
9007
  b.width += (right + left);
@@ -9147,6 +9186,7 @@ let Leafer = class Leafer extends Group {
9147
9186
  get __tag() { return 'Leafer'; }
9148
9187
  get isApp() { return false; }
9149
9188
  get app() { return this.parent || this; }
9189
+ get imageReady() { return this.viewReady && ImageManager.isComplete; }
9150
9190
  get layoutLocked() { return !this.layouter.running; }
9151
9191
  get cursorPoint() { return (this.interaction && this.interaction.hoverData) || { x: this.width / 2, y: this.height / 2 }; }
9152
9192
  constructor(userConfig, data) {
@@ -9349,23 +9389,26 @@ let Leafer = class Leafer extends Group {
9349
9389
  this.emitLeafer(LeaferEvent.VIEW_READY);
9350
9390
  WaitHelper.run(this.__viewReadyWait);
9351
9391
  }
9352
- __onRenderEnd(_e) {
9353
- if (!this.viewReady)
9354
- this.__onViewReady();
9355
- const completed = this.__checkViewCompleted();
9356
- if (completed)
9357
- this.__onViewCompleted();
9358
- this.viewCompleted = completed;
9359
- WaitHelper.run(this.__nextRenderWait);
9360
- }
9361
- __checkViewCompleted() {
9362
- return this.viewReady && !this.watcher.changed && ImageManager.isComplete;
9363
- }
9364
- __onViewCompleted() {
9365
- if (!this.viewCompleted) {
9366
- this.emitLeafer(LeaferEvent.VIEW_COMPLETED);
9367
- WaitHelper.run(this.__viewCompletedWait);
9368
- }
9392
+ __onAnimateFrame() {
9393
+ if (this.viewReady) {
9394
+ if (this.__nextRenderWait.length)
9395
+ WaitHelper.run(this.__nextRenderWait);
9396
+ const { imageReady } = this;
9397
+ if (imageReady && !this.viewCompleted)
9398
+ this.__checkViewCompleted();
9399
+ if (!imageReady)
9400
+ this.viewCompleted = false;
9401
+ }
9402
+ }
9403
+ __checkViewCompleted(emit = true) {
9404
+ this.nextRender(() => {
9405
+ if (this.imageReady) {
9406
+ if (emit)
9407
+ this.emitLeafer(LeaferEvent.VIEW_COMPLETED);
9408
+ WaitHelper.run(this.__viewCompletedWait);
9409
+ this.viewCompleted = true;
9410
+ }
9411
+ });
9369
9412
  }
9370
9413
  __onWatchData() {
9371
9414
  if (this.watcher.childrenChanged && this.interaction) {
@@ -9379,22 +9422,17 @@ let Leafer = class Leafer extends Group {
9379
9422
  this.viewReady ? item() : this.__viewReadyWait.push(item);
9380
9423
  }
9381
9424
  waitViewCompleted(item) {
9425
+ this.__viewCompletedWait.push(item);
9382
9426
  if (this.viewCompleted) {
9383
- item();
9427
+ this.__checkViewCompleted(false);
9384
9428
  }
9385
9429
  else {
9386
- this.__viewCompletedWait.push(item);
9387
9430
  if (!this.running)
9388
9431
  this.start();
9389
9432
  }
9390
9433
  }
9391
9434
  nextRender(item) {
9392
- if (this.watcher && !this.watcher.changed) {
9393
- item();
9394
- }
9395
- else {
9396
- this.__nextRenderWait.push(item);
9397
- }
9435
+ this.__nextRenderWait.push(item);
9398
9436
  }
9399
9437
  __checkUpdateLayout() {
9400
9438
  this.__layout.update();
@@ -9407,7 +9445,8 @@ let Leafer = class Leafer extends Group {
9407
9445
  this.once(LeaferEvent.START, () => Run.end(runId));
9408
9446
  this.once(LayoutEvent.END, () => this.__onReady());
9409
9447
  this.once(RenderEvent.START, () => this.__onCreated());
9410
- this.__eventIds.push(this.on_(WatchEvent.DATA, this.__onWatchData, this), this.on_(RenderEvent.END, this.__onRenderEnd, this), this.on_(LayoutEvent.CHECK_UPDATE, this.__checkUpdateLayout, this));
9448
+ this.once(RenderEvent.END, () => this.__onViewReady());
9449
+ this.__eventIds.push(this.on_(WatchEvent.DATA, this.__onWatchData, this), this.on_(AnimateEvent.FRAME, this.__onAnimateFrame, this), this.on_(LayoutEvent.CHECK_UPDATE, this.__checkUpdateLayout, this));
9411
9450
  }
9412
9451
  __removeListenEvents() {
9413
9452
  this.off_(this.__eventIds);
@@ -9534,9 +9573,6 @@ let App = class App extends Leafer {
9534
9573
  if (this.children.every(child => child.viewReady))
9535
9574
  super.__onViewReady();
9536
9575
  }
9537
- __checkViewCompleted() {
9538
- return this.children.every(item => item.viewCompleted);
9539
- }
9540
9576
  __onChildRenderEnd(e) {
9541
9577
  this.renderer.addBlock(e.renderBounds);
9542
9578
  if (this.viewReady)
@@ -9566,7 +9602,7 @@ let App = class App extends Leafer {
9566
9602
  __listenChildEvents(leafer) {
9567
9603
  leafer.once(LayoutEvent.END, () => this.__onReady());
9568
9604
  leafer.once(RenderEvent.START, () => this.__onCreated());
9569
- leafer.once(RenderEvent.END, (e) => this.__onRenderEnd(e));
9605
+ leafer.once(RenderEvent.END, () => this.__onViewReady());
9570
9606
  if (this.realCanvas)
9571
9607
  this.__eventIds.push(leafer.on_(RenderEvent.END, this.__onChildRenderEnd, this));
9572
9608
  }
@@ -9575,6 +9611,7 @@ App = __decorate([
9575
9611
  registerUI()
9576
9612
  ], App);
9577
9613
 
9614
+ let origin = {};
9578
9615
  const { get: get$4, rotateOfOuter: rotateOfOuter$2, translate: translate$1, scaleOfOuter: scaleOfOuter$2, scale: scaleHelper, rotate } = MatrixHelper;
9579
9616
  function fillOrFitMode(data, mode, box, width, height, rotation) {
9580
9617
  const transform = get$4();
@@ -9591,13 +9628,13 @@ function fillOrFitMode(data, mode, box, width, height, rotation) {
9591
9628
  data.scaleX = data.scaleY = scale;
9592
9629
  data.transform = transform;
9593
9630
  }
9594
- function clipMode(data, box, offset, scale, rotation) {
9631
+ function clipMode(data, box, x, y, scaleX, scaleY, rotation) {
9595
9632
  const transform = get$4();
9596
9633
  translate$1(transform, box.x, box.y);
9597
- if (offset)
9598
- translate$1(transform, offset.x, offset.y);
9599
- if (scale) {
9600
- typeof scale === 'number' ? scaleHelper(transform, scale) : scaleHelper(transform, scale.x, scale.y);
9634
+ if (x || y)
9635
+ translate$1(transform, x, y);
9636
+ if (scaleX) {
9637
+ scaleHelper(transform, scaleX, scaleY);
9601
9638
  data.scaleX = transform.a;
9602
9639
  data.scaleY = transform.d;
9603
9640
  }
@@ -9605,7 +9642,7 @@ function clipMode(data, box, offset, scale, rotation) {
9605
9642
  rotate(transform, rotation);
9606
9643
  data.transform = transform;
9607
9644
  }
9608
- function repeatMode(data, box, width, height, scale, rotation) {
9645
+ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation) {
9609
9646
  const transform = get$4();
9610
9647
  if (rotation) {
9611
9648
  rotate(transform, rotation);
@@ -9621,10 +9658,15 @@ function repeatMode(data, box, width, height, scale, rotation) {
9621
9658
  break;
9622
9659
  }
9623
9660
  }
9624
- translate$1(transform, box.x, box.y);
9625
- if (scale) {
9626
- scaleOfOuter$2(transform, box, scale);
9627
- data.scaleX = data.scaleY = scale;
9661
+ origin.x = box.x;
9662
+ origin.y = box.y;
9663
+ if (x || y)
9664
+ origin.x += x, origin.y += y;
9665
+ translate$1(transform, origin.x, origin.y);
9666
+ if (scaleX) {
9667
+ scaleOfOuter$2(transform, origin, scaleX, scaleY);
9668
+ data.scaleX = scaleX;
9669
+ data.scaleY = scaleY;
9628
9670
  }
9629
9671
  data.transform = transform;
9630
9672
  }
@@ -9632,11 +9674,22 @@ function repeatMode(data, box, width, height, scale, rotation) {
9632
9674
  const { get: get$3, translate } = MatrixHelper;
9633
9675
  function createData(leafPaint, image, paint, box) {
9634
9676
  let { width, height } = image;
9635
- const { opacity, mode, offset, scale, rotation, blendMode } = paint;
9677
+ const { opacity, mode, offset, scale, size, rotation, blendMode, repeat } = paint;
9636
9678
  const sameBox = box.width === width && box.height === height;
9637
9679
  if (blendMode)
9638
9680
  leafPaint.blendMode = blendMode;
9639
9681
  const data = leafPaint.data = { mode };
9682
+ let x, y, scaleX, scaleY;
9683
+ if (offset)
9684
+ x = offset.x, y = offset.y;
9685
+ if (size) {
9686
+ scaleX = (typeof size === 'number' ? size : size.width) / width;
9687
+ scaleY = (typeof size === 'number' ? size : size.height) / height;
9688
+ }
9689
+ else if (scale) {
9690
+ scaleX = typeof scale === 'number' ? scale : scale.x;
9691
+ scaleY = typeof scale === 'number' ? scale : scale.y;
9692
+ }
9640
9693
  switch (mode) {
9641
9694
  case 'strench':
9642
9695
  if (!sameBox)
@@ -9647,12 +9700,14 @@ function createData(leafPaint, image, paint, box) {
9647
9700
  }
9648
9701
  break;
9649
9702
  case 'clip':
9650
- if (offset || scale || rotation)
9651
- clipMode(data, box, offset, scale, rotation);
9703
+ if (offset || scaleX || rotation)
9704
+ clipMode(data, box, x, y, scaleX, scaleY, rotation);
9652
9705
  break;
9653
9706
  case 'repeat':
9654
- if (!sameBox || scale || rotation)
9655
- repeatMode(data, box, width, height, scale, rotation);
9707
+ if (!sameBox || scaleX || rotation)
9708
+ repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation);
9709
+ if (!repeat)
9710
+ data.repeat = 'repeat';
9656
9711
  break;
9657
9712
  case 'fit':
9658
9713
  case 'cover':
@@ -9664,6 +9719,8 @@ function createData(leafPaint, image, paint, box) {
9664
9719
  data.height = height;
9665
9720
  if (opacity)
9666
9721
  data.opacity = opacity;
9722
+ if (repeat)
9723
+ data.repeat = typeof repeat === 'string' ? (repeat === 'x' ? 'repeat-x' : 'repeat-y') : 'repeat';
9667
9724
  }
9668
9725
 
9669
9726
  function image(ui, attrName, attrValue, box, firstUse) {
@@ -9710,11 +9767,11 @@ function hasNaturalSize(ui, attrName, image) {
9710
9767
  d.__naturalWidth = image.width;
9711
9768
  d.__naturalHeight = image.height;
9712
9769
  if (!d.__getInput('width') || !d.__getInput('height')) {
9770
+ ui.forceUpdate('width');
9713
9771
  if (ui.__proxyData) {
9714
9772
  ui.setProxyAttr('width', ui.__.width);
9715
9773
  ui.setProxyAttr('height', ui.__.height);
9716
9774
  }
9717
- ui.forceUpdate('width');
9718
9775
  return false;
9719
9776
  }
9720
9777
  }
@@ -9733,7 +9790,7 @@ function createPattern(ui, paint, pixelRatio) {
9733
9790
  scaleX = Math.abs(scaleX);
9734
9791
  scaleY = Math.abs(scaleY);
9735
9792
  const { image, data } = paint;
9736
- let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, opacity, transform, mode } = data;
9793
+ let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, opacity, transform, repeat } = data;
9737
9794
  if (sx) {
9738
9795
  imageMatrix = get$2();
9739
9796
  copy$1(imageMatrix, transform);
@@ -9746,7 +9803,7 @@ function createPattern(ui, paint, pixelRatio) {
9746
9803
  width *= scaleX;
9747
9804
  height *= scaleY;
9748
9805
  const size = width * height;
9749
- if (paint.data.mode !== 'repeat') {
9806
+ if (!repeat) {
9750
9807
  if (size > Platform.image.maxCacheSize)
9751
9808
  return false;
9752
9809
  }
@@ -9776,7 +9833,7 @@ function createPattern(ui, paint, pixelRatio) {
9776
9833
  }
9777
9834
  scale(imageMatrix, 1 / scaleX, 1 / scaleY);
9778
9835
  }
9779
- const pattern = Platform.canvas.createPattern(image.getCanvas(width < 1 ? 1 : width, height < 1 ? 1 : height, opacity), mode === 'repeat' ? 'repeat' : (Platform.origin.noRepeat || 'no-repeat'));
9836
+ const pattern = Platform.canvas.createPattern(image.getCanvas(width < 1 ? 1 : width, height < 1 ? 1 : height, opacity), repeat || (Platform.origin.noRepeat || 'no-repeat'));
9780
9837
  try {
9781
9838
  if (paint.transform)
9782
9839
  paint.transform = null;
@@ -9804,7 +9861,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
9804
9861
  else {
9805
9862
  const { data } = paint;
9806
9863
  if (allowPaint) {
9807
- if (data.mode !== 'repeat') {
9864
+ if (!data.repeat) {
9808
9865
  let { width, height } = data;
9809
9866
  width *= abs(scaleX) * canvas.pixelRatio;
9810
9867
  height *= abs(scaleY) * canvas.pixelRatio;
@@ -10804,6 +10861,7 @@ function decorationText(drawData, style) {
10804
10861
  }
10805
10862
  }
10806
10863
 
10864
+ const { top, right, bottom, left } = Direction4;
10807
10865
  const TextConvert = {
10808
10866
  getDrawData(content, style) {
10809
10867
  if (typeof content !== 'string')
@@ -10811,16 +10869,15 @@ const TextConvert = {
10811
10869
  let x = 0, y = 0;
10812
10870
  let width = style.__getInput('width') || 0;
10813
10871
  let height = style.__getInput('height') || 0;
10814
- const { textDecoration, __font, padding } = style;
10872
+ const { textDecoration, __font, __padding: padding } = style;
10815
10873
  if (padding) {
10816
- const [top, right, bottom, left] = MathHelper.fourNumber(padding);
10817
10874
  if (width) {
10818
- x = left;
10819
- width -= (right + left);
10875
+ x = padding[left];
10876
+ width -= (padding[right] + padding[left]);
10820
10877
  }
10821
10878
  if (height) {
10822
- y = top;
10823
- height -= (top + bottom);
10879
+ y = padding[top];
10880
+ height -= (padding[top] + padding[bottom]);
10824
10881
  }
10825
10882
  }
10826
10883
  const drawData = {
@@ -10830,6 +10887,8 @@ const TextConvert = {
10830
10887
  font: Platform.canvas.font = __font
10831
10888
  };
10832
10889
  createRows(drawData, content, style);
10890
+ if (padding)
10891
+ padAutoText(padding, drawData, style, width, height);
10833
10892
  layoutText(drawData, style);
10834
10893
  layoutChar(drawData, style, width);
10835
10894
  if (drawData.overflow)
@@ -10839,6 +10898,32 @@ const TextConvert = {
10839
10898
  return drawData;
10840
10899
  }
10841
10900
  };
10901
+ function padAutoText(padding, drawData, style, width, height) {
10902
+ if (!width) {
10903
+ switch (style.textAlign) {
10904
+ case 'left':
10905
+ offsetText(drawData, 'x', padding[left]);
10906
+ break;
10907
+ case 'right':
10908
+ offsetText(drawData, 'x', -padding[right]);
10909
+ }
10910
+ }
10911
+ if (!height) {
10912
+ switch (style.verticalAlign) {
10913
+ case 'top':
10914
+ offsetText(drawData, 'y', padding[top]);
10915
+ break;
10916
+ case 'bottom':
10917
+ offsetText(drawData, 'y', -padding[bottom]);
10918
+ }
10919
+ }
10920
+ }
10921
+ function offsetText(drawData, attrName, value) {
10922
+ const { bounds, rows } = drawData;
10923
+ bounds[attrName] += value;
10924
+ for (let i = 0; i < rows.length; i++)
10925
+ rows[i][attrName] += value;
10926
+ }
10842
10927
 
10843
10928
  const ColorConvert = {
10844
10929
  string(color, opacity) {
@@ -10955,4 +11040,4 @@ LeaferCanvas.prototype.updateViewSize = function () {
10955
11040
  }
10956
11041
  };
10957
11042
 
10958
- export { Animate, AnimateEvent, App, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert$1 as ColorConvert, Creator, Cursor, DataHelper, Debug, DragEvent, DropEvent, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Export$1 as Export, FileHelper, Frame, FrameData, Group, GroupData, HitCanvasManager, Image, ImageData, ImageEvent, ImageManager, IncrementId, Interaction, InteractionBase, InteractionHelper, KeyEvent, Keyboard, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafHit, LeafLayout, LeafLevelList, LeafList, LeafMask, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, LeaferTypeCreator, Line, LineData, MathHelper, Matrix, MatrixHelper, MoveEvent, MultiTouchHelper, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, Path, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, PathScaler, Pen, PenData, Platform, PluginManager, Point, PointHelper, PointerButton, PointerEvent, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, RotateEvent, Run, Selector, Star, StarData, StringNumberMap, SwipeEvent, TaskItem, TaskProcessor, Text, TextConvert$1 as TextConvert, TextData, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIEvent, UIHit, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, ZoomEvent, affectRenderBoundsType, affectStrokeBoundsType, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, cursorType, dataProcessor, dataType, defineDataProcessor, defineKey, defineLeafAttr, effectType, eraserType, getDescriptor, hitType, layoutProcessor, maskType, opacityType, pathType, positionType, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, useCanvas, useModule, usePlugin };
11043
+ export { Animate, AnimateEvent, App, AroundHelper, ArrowData, AutoBounds, BezierHelper, Bounds, BoundsHelper, Box, BoxData, Branch, BranchHelper, BranchRender, Canvas, CanvasData, CanvasManager, ChildEvent, ColorConvert$1 as ColorConvert, Creator, Cursor, DataHelper, Debug, Direction4, Direction9, DragEvent, DropEvent, Effect, Ellipse, EllipseData, EllipseHelper, Event, EventCreator, Export$1 as Export, FileHelper, Frame, FrameData, Group, GroupData, HitCanvasManager, Image, ImageData, ImageEvent, ImageManager, IncrementId, Interaction, InteractionBase, InteractionHelper, KeyEvent, Keyboard, LayoutEvent, Layouter, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafHit, LeafLayout, LeafLevelList, LeafList, LeafMask, LeafMatrix, LeafRender, Leafer, LeaferCanvas, LeaferCanvasBase, LeaferData, LeaferEvent, LeaferImage, LeaferTypeCreator, Line, LineData, MathHelper, Matrix, MatrixHelper, MoveEvent, MultiTouchHelper, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, Paint, Path, PathBounds, PathCommandDataHelper, PathCommandMap, PathConvert, PathCorner, PathCreator, PathData, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, PathScaler, Pen, PenData, Platform, PluginManager, Point, PointHelper, PointerButton, PointerEvent, Polygon, PolygonData, PropertyEvent, Rect, RectData, RectHelper, RectRender, RenderEvent, Renderer, ResizeEvent, RotateEvent, Run, Selector, Star, StarData, StringNumberMap, SwipeEvent, TaskItem, TaskProcessor, Text, TextConvert$1 as TextConvert, TextData, TwoPointBoundsHelper, UI, UIBounds, UICreator, UIData, UIEvent, UIHit, UIRender, UnitConvert, WaitHelper, WatchEvent, Watcher, ZoomEvent, affectRenderBoundsType, affectStrokeBoundsType, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, cursorType, dataProcessor, dataType, defineDataProcessor, defineKey, defineLeafAttr, effectType, eraserType, getDescriptor, hitType, layoutProcessor, maskType, opacityType, pathType, positionType, registerUI, registerUIEvent, resizeType, rewrite, rewriteAble, rotationType, scaleType, sortType, strokeType, surfaceType, useCanvas, useModule, usePlugin };