leafer-draw 1.0.4 → 1.0.6

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
@@ -555,6 +555,12 @@ var LeaferUI = (function (exports) {
555
555
  to.y = t.y + sin$4(r) * distance;
556
556
  return to;
557
557
  },
558
+ toNumberPoints(originPoints) {
559
+ let points = originPoints;
560
+ if (typeof originPoints[0] === 'object')
561
+ points = [], originPoints.forEach(p => points.push(p.x, p.y));
562
+ return points;
563
+ },
558
564
  reset(t) {
559
565
  P$5.reset(t);
560
566
  }
@@ -1545,7 +1551,10 @@ var LeaferUI = (function (exports) {
1545
1551
 
1546
1552
  class LeafData {
1547
1553
  get __useNaturalRatio() { return true; }
1548
- get __isLinePath() { return this.path && this.path.length === 6; }
1554
+ get __isLinePath() {
1555
+ const { path } = this;
1556
+ return path && path.length === 6 && path[0] === 1;
1557
+ }
1549
1558
  get __blendMode() {
1550
1559
  if (this.eraser && this.eraser !== 'path')
1551
1560
  return 'destination-out';
@@ -2308,11 +2317,12 @@ var LeaferUI = (function (exports) {
2308
2317
 
2309
2318
  const { sin: sin$3, cos: cos$3, atan2: atan2$1, ceil: ceil$1, abs: abs$3, PI: PI$2, sqrt: sqrt$1, pow } = Math;
2310
2319
  const { setPoint: setPoint$2, addPoint: addPoint$2 } = TwoPointBoundsHelper;
2311
- const { set } = PointHelper;
2320
+ const { set, toNumberPoints } = PointHelper;
2312
2321
  const { M: M$5, L: L$6, C: C$5, Q: Q$4, Z: Z$5 } = PathCommandMap;
2313
2322
  const tempPoint$2 = {};
2314
2323
  const BezierHelper = {
2315
- points(data, points, curve, close) {
2324
+ points(data, originPoints, curve, close) {
2325
+ let points = toNumberPoints(originPoints);
2316
2326
  data.push(M$5, points[0], points[1]);
2317
2327
  if (curve && points.length > 5) {
2318
2328
  let aX, aY, bX, bY, cX, cY, c1X, c1Y, c2X, c2Y;
@@ -2821,6 +2831,27 @@ var LeaferUI = (function (exports) {
2821
2831
  }
2822
2832
  return data;
2823
2833
  },
2834
+ objectToCanvasData(list) {
2835
+ const data = [];
2836
+ list.forEach(item => {
2837
+ switch (item.name) {
2838
+ case 'M':
2839
+ data.push(M$4, item.x, item.y);
2840
+ break;
2841
+ case 'L':
2842
+ data.push(L$5, item.x, item.y);
2843
+ break;
2844
+ case 'C':
2845
+ data.push(C$4, item.x1, item.y1, item.x2, item.y2, item.x, item.y);
2846
+ break;
2847
+ case 'Q':
2848
+ data.push(Q$3, item.x1, item.y1, item.x, item.y);
2849
+ break;
2850
+ case 'Z': data.push(Z$4);
2851
+ }
2852
+ });
2853
+ return data;
2854
+ },
2824
2855
  copyData(data, old, index, count) {
2825
2856
  for (let i = index, end = index + count; i < end; i++) {
2826
2857
  data.push(old[i]);
@@ -4758,6 +4789,7 @@ var LeaferUI = (function (exports) {
4758
4789
  }
4759
4790
  }
4760
4791
  RenderEvent.REQUEST = 'render.request';
4792
+ RenderEvent.CHILD_START = 'render.child_start';
4761
4793
  RenderEvent.START = 'render.start';
4762
4794
  RenderEvent.BEFORE = 'render.before';
4763
4795
  RenderEvent.RENDER = 'render';
@@ -4933,7 +4965,7 @@ var LeaferUI = (function (exports) {
4933
4965
  const debug$6 = Debug.get('setAttr');
4934
4966
  const LeafDataProxy = {
4935
4967
  __setAttr(name, newValue, checkFiniteNumber) {
4936
- if (this.leafer && this.leafer.created) {
4968
+ if (this.leaferIsCreated) {
4937
4969
  const oldValue = this.__.__getInput(name);
4938
4970
  if (checkFiniteNumber && !isFinite(newValue) && newValue !== undefined) {
4939
4971
  debug$6.warn(this.innerName, name, newValue);
@@ -5005,7 +5037,7 @@ var LeaferUI = (function (exports) {
5005
5037
 
5006
5038
  const { updateMatrix: updateMatrix$1, updateAllMatrix: updateAllMatrix$2 } = LeafHelper;
5007
5039
  const { updateBounds: updateBounds$1 } = BranchHelper;
5008
- const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$2, copy: copy$4 } = BoundsHelper;
5040
+ const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$1, copy: copy$4 } = BoundsHelper;
5009
5041
  const { toBounds: toBounds$2 } = PathBounds;
5010
5042
  const LeafBounds = {
5011
5043
  __updateWorldBounds() {
@@ -5088,7 +5120,7 @@ var LeaferUI = (function (exports) {
5088
5120
  const b = this.__layout.boxBounds;
5089
5121
  const data = this.__;
5090
5122
  if (data.__pathInputed) {
5091
- toBounds$2(data.__pathForRender, b);
5123
+ toBounds$2(data.path, b);
5092
5124
  }
5093
5125
  else {
5094
5126
  b.x = 0;
@@ -5100,7 +5132,7 @@ var LeaferUI = (function (exports) {
5100
5132
  __updateAutoLayout() {
5101
5133
  this.__layout.matrixChanged = true;
5102
5134
  if (this.isBranch) {
5103
- if (this.leafer && this.leafer.ready)
5135
+ if (this.leaferIsReady)
5104
5136
  this.leafer.layouter.addExtra(this);
5105
5137
  if (this.__.flow) {
5106
5138
  if (this.__layout.boxChanged)
@@ -5126,11 +5158,11 @@ var LeaferUI = (function (exports) {
5126
5158
  },
5127
5159
  __updateStrokeBounds() {
5128
5160
  const layout = this.__layout;
5129
- copyAndSpread$2(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
5161
+ copyAndSpread$1(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
5130
5162
  },
5131
5163
  __updateRenderBounds() {
5132
5164
  const layout = this.__layout;
5133
- layout.renderSpread > 0 ? copyAndSpread$2(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$4(layout.renderBounds, layout.strokeBounds);
5165
+ layout.renderSpread > 0 ? copyAndSpread$1(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$4(layout.renderBounds, layout.strokeBounds);
5134
5166
  }
5135
5167
  };
5136
5168
 
@@ -5161,7 +5193,7 @@ var LeaferUI = (function (exports) {
5161
5193
  if (this.__worldOpacity) {
5162
5194
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
5163
5195
  this.__drawRenderPath(canvas);
5164
- this.__.windingRule ? canvas.clip(this.__.windingRule) : canvas.clip();
5196
+ this.windingRule ? canvas.clip(this.windingRule) : canvas.clip();
5165
5197
  }
5166
5198
  },
5167
5199
  __updateWorldOpacity() {
@@ -5235,6 +5267,8 @@ var LeaferUI = (function (exports) {
5235
5267
  get innerName() { return this.__.name || this.tag + this.innerId; }
5236
5268
  get __DataProcessor() { return LeafData; }
5237
5269
  get __LayoutProcessor() { return LeafLayout; }
5270
+ get leaferIsCreated() { return this.leafer && this.leafer.created; }
5271
+ get leaferIsReady() { return this.leafer && this.leafer.ready; }
5238
5272
  get isLeafer() { return false; }
5239
5273
  get isBranch() { return false; }
5240
5274
  get isBranchLeaf() { return false; }
@@ -5676,10 +5710,17 @@ var LeaferUI = (function (exports) {
5676
5710
  add(child, index) {
5677
5711
  if (child === this)
5678
5712
  return;
5713
+ const noIndex = index === undefined;
5714
+ if (!child.__) {
5715
+ if (child instanceof Array)
5716
+ return child.forEach(item => { this.add(item, index); noIndex || index++; });
5717
+ else
5718
+ child = UICreator.get(child.tag, child);
5719
+ }
5679
5720
  if (child.parent)
5680
5721
  child.parent.remove(child);
5681
5722
  child.parent = this;
5682
- index === undefined ? this.children.push(child) : this.children.splice(index, 0, child);
5723
+ noIndex ? this.children.push(child) : this.children.splice(index, 0, child);
5683
5724
  if (child.isBranch)
5684
5725
  this.__.__childBranchNumber = (this.__.__childBranchNumber || 0) + 1;
5685
5726
  child.__layout.boxChanged || child.__layout.boxChange();
@@ -5693,15 +5734,17 @@ var LeaferUI = (function (exports) {
5693
5734
  }
5694
5735
  this.__layout.affectChildrenSort && this.__layout.childrenSortChange();
5695
5736
  }
5696
- addMany(...children) {
5697
- children.forEach(child => this.add(child));
5698
- }
5737
+ addMany(...children) { this.add(children); }
5699
5738
  remove(child, destroy) {
5700
5739
  if (child) {
5701
- if (child.animationOut)
5702
- child.__runAnimation('out', () => this.__remove(child, destroy));
5740
+ if (child.__) {
5741
+ if (child.animationOut)
5742
+ child.__runAnimation('out', () => this.__remove(child, destroy));
5743
+ else
5744
+ this.__remove(child, destroy);
5745
+ }
5703
5746
  else
5704
- this.__remove(child, destroy);
5747
+ this.find(child).forEach(item => this.remove(item, destroy));
5705
5748
  }
5706
5749
  else if (child === undefined) {
5707
5750
  super.remove(null, destroy);
@@ -5919,7 +5962,7 @@ var LeaferUI = (function (exports) {
5919
5962
  }
5920
5963
  }
5921
5964
 
5922
- const version = "1.0.4";
5965
+ const version = "1.0.6";
5923
5966
 
5924
5967
  const debug$5 = Debug.get('LeaferCanvas');
5925
5968
  class LeaferCanvas extends LeaferCanvasBase {
@@ -6077,7 +6120,7 @@ var LeaferUI = (function (exports) {
6077
6120
  const oldSize = {};
6078
6121
  DataHelper.copyAttrs(oldSize, this, canvasSizeAttrs);
6079
6122
  this.resize(size);
6080
- if (this.width !== undefined)
6123
+ if (this.resizeListener && this.width !== undefined)
6081
6124
  this.resizeListener(new ResizeEvent(size, oldSize));
6082
6125
  }
6083
6126
  unrealCanvas() {
@@ -6561,6 +6604,7 @@ var LeaferUI = (function (exports) {
6561
6604
  this.totalBounds = new Bounds();
6562
6605
  debug$3.log(target.innerName, '--->');
6563
6606
  try {
6607
+ target.app.emit(RenderEvent.CHILD_START, target);
6564
6608
  this.emitRender(RenderEvent.START);
6565
6609
  this.renderOnce(callback);
6566
6610
  this.emitRender(RenderEvent.END, this.totalBounds);
@@ -6800,6 +6844,13 @@ var LeaferUI = (function (exports) {
6800
6844
 
6801
6845
  const TextConvert = {};
6802
6846
  const ColorConvert = {};
6847
+ const UnitConvert = {
6848
+ number(value, percentRefer) {
6849
+ if (typeof value === 'object')
6850
+ return value.type === 'percent' ? value.value * percentRefer : value.value;
6851
+ return value;
6852
+ }
6853
+ };
6803
6854
  const PathArrow = {};
6804
6855
  const Paint = {};
6805
6856
  const PaintImage = {};
@@ -6820,7 +6871,7 @@ var LeaferUI = (function (exports) {
6820
6871
  }
6821
6872
  };
6822
6873
 
6823
- const { parse } = PathConvert;
6874
+ const { parse, objectToCanvasData } = PathConvert;
6824
6875
  const emptyPaint = {};
6825
6876
  const debug$2 = Debug.get('UIData');
6826
6877
  class UIData extends LeafData {
@@ -6834,10 +6885,11 @@ var LeaferUI = (function (exports) {
6834
6885
  scaleX = -scaleX;
6835
6886
  return scaleX > 1 ? strokeWidth / scaleX : strokeWidth;
6836
6887
  }
6837
- else {
6888
+ else
6838
6889
  return strokeWidth;
6839
- }
6840
6890
  }
6891
+ get __hasStroke() { return this.stroke && this.strokeWidth; }
6892
+ get __clipAfterFill() { return (this.cornerRadius || this.__pathInputed); }
6841
6893
  get __autoWidth() { return !this._width; }
6842
6894
  get __autoHeight() { return !this._height; }
6843
6895
  get __autoSide() { return !this._width || !this._height; }
@@ -6854,9 +6906,8 @@ var LeaferUI = (function (exports) {
6854
6906
  this.__leaf.scaleX *= -1;
6855
6907
  debug$2.warn('width < 0, instead -scaleX ', this);
6856
6908
  }
6857
- else {
6909
+ else
6858
6910
  this._width = value;
6859
- }
6860
6911
  }
6861
6912
  setHeight(value) {
6862
6913
  if (value < 0) {
@@ -6864,9 +6915,8 @@ var LeaferUI = (function (exports) {
6864
6915
  this.__leaf.scaleY *= -1;
6865
6916
  debug$2.warn('height < 0, instead -scaleY', this);
6866
6917
  }
6867
- else {
6918
+ else
6868
6919
  this._height = value;
6869
- }
6870
6920
  }
6871
6921
  setFill(value) {
6872
6922
  if (this.__naturalWidth)
@@ -6907,9 +6957,10 @@ var LeaferUI = (function (exports) {
6907
6957
  }
6908
6958
  }
6909
6959
  setPath(value) {
6910
- if (typeof value === 'string') {
6960
+ const isString = typeof value === 'string';
6961
+ if (isString || (value && typeof value[0] === 'object')) {
6911
6962
  this.__setInput('path', value);
6912
- this._path = parse(value);
6963
+ this._path = isString ? parse(value) : objectToCanvasData(value);
6913
6964
  }
6914
6965
  else {
6915
6966
  if (this.__input)
@@ -6924,12 +6975,8 @@ var LeaferUI = (function (exports) {
6924
6975
  value = value.filter((item) => item.visible !== false);
6925
6976
  this._shadow = value.length ? value : null;
6926
6977
  }
6927
- else if (value) {
6928
- this._shadow = value.visible === false ? null : [value];
6929
- }
6930
- else {
6931
- this._shadow = null;
6932
- }
6978
+ else
6979
+ this._shadow = value && value.visible !== false ? [value] : null;
6933
6980
  }
6934
6981
  setInnerShadow(value) {
6935
6982
  this.__setInput('innerShadow', value);
@@ -6938,12 +6985,8 @@ var LeaferUI = (function (exports) {
6938
6985
  value = value.filter((item) => item.visible !== false);
6939
6986
  this._innerShadow = value.length ? value : null;
6940
6987
  }
6941
- else if (value) {
6942
- this._innerShadow = value.visible === false ? null : [value];
6943
- }
6944
- else {
6945
- this._innerShadow = null;
6946
- }
6988
+ else
6989
+ this._innerShadow = value && value.visible !== false ? [value] : null;
6947
6990
  }
6948
6991
  __computePaint() {
6949
6992
  const { fill, stroke } = this.__input;
@@ -6954,24 +6997,19 @@ var LeaferUI = (function (exports) {
6954
6997
  this.__needComputePaint = false;
6955
6998
  }
6956
6999
  }
6957
- const UnitConvert = {
6958
- number(value, percentRefer) {
6959
- if (typeof value === 'object')
6960
- return value.type === 'percent' ? value.value * percentRefer : value.value;
6961
- return value;
6962
- }
6963
- };
6964
7000
 
6965
7001
  class GroupData extends UIData {
6966
7002
  }
6967
7003
 
6968
7004
  class BoxData extends GroupData {
6969
7005
  get __boxStroke() { return !this.__pathInputed; }
7006
+ get __drawAfterFill() { return this.overflow === 'hide' && this.__clipAfterFill && this.__leaf.children.length; }
7007
+ get __clipAfterFill() { return this.__leaf.isOverflow || super.__clipAfterFill; }
6970
7008
  }
6971
7009
 
6972
7010
  class LeaferData extends GroupData {
6973
- __getInputData() {
6974
- const data = super.__getInputData();
7011
+ __getInputData(names, options) {
7012
+ const data = super.__getInputData(names, options);
6975
7013
  canvasSizeAttrs.forEach(key => delete data[key]);
6976
7014
  return data;
6977
7015
  }
@@ -6998,6 +7036,7 @@ var LeaferUI = (function (exports) {
6998
7036
  }
6999
7037
 
7000
7038
  class PathData extends UIData {
7039
+ get __pathInputed() { return 2; }
7001
7040
  }
7002
7041
 
7003
7042
  class PenData extends GroupData {
@@ -7044,16 +7083,18 @@ var LeaferUI = (function (exports) {
7044
7083
  delete data.fill;
7045
7084
  return data;
7046
7085
  }
7047
- __getInputData() {
7048
- const data = super.__getInputData();
7086
+ __getInputData(names, options) {
7087
+ const data = super.__getInputData(names, options);
7049
7088
  delete data.fill;
7050
7089
  return data;
7051
7090
  }
7052
7091
  }
7053
7092
 
7054
7093
  class CanvasData extends RectData {
7055
- __getInputData() {
7056
- const data = super.__getInputData();
7094
+ get __isCanvas() { return true; }
7095
+ get __drawAfterFill() { return true; }
7096
+ __getInputData(names, options) {
7097
+ const data = super.__getInputData(names, options);
7057
7098
  data.url = this.__leaf.canvas.toDataURL('image/png');
7058
7099
  return data;
7059
7100
  }
@@ -7080,16 +7121,12 @@ var LeaferUI = (function (exports) {
7080
7121
  let width = 0;
7081
7122
  const { shadow, innerShadow, blur, backgroundBlur } = this.__;
7082
7123
  if (shadow)
7083
- shadow.forEach(item => {
7084
- width = Math.max(width, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread > 0 ? item.spread : 0) + item.blur * 1.5);
7085
- });
7124
+ shadow.forEach(item => width = Math.max(width, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread > 0 ? item.spread : 0) + item.blur * 1.5));
7086
7125
  if (blur)
7087
7126
  width = Math.max(width, blur);
7088
7127
  let shapeWidth = width = Math.ceil(width);
7089
7128
  if (innerShadow)
7090
- innerShadow.forEach(item => {
7091
- shapeWidth = Math.max(shapeWidth, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread < 0 ? -item.spread : 0) + item.blur * 1.5);
7092
- });
7129
+ innerShadow.forEach(item => shapeWidth = Math.max(shapeWidth, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread < 0 ? -item.spread : 0) + item.blur * 1.5));
7093
7130
  if (backgroundBlur)
7094
7131
  shapeWidth = Math.max(shapeWidth, backgroundBlur);
7095
7132
  this.__layout.renderShapeSpread = shapeWidth;
@@ -7171,6 +7208,16 @@ var LeaferUI = (function (exports) {
7171
7208
  if (stroke && !ignoreStroke)
7172
7209
  this.__.__pixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
7173
7210
  }
7211
+ },
7212
+ __drawAfterFill(canvas, options) {
7213
+ if (this.__.__clipAfterFill) {
7214
+ canvas.save();
7215
+ this.windingRule ? canvas.clip(this.windingRule) : canvas.clip();
7216
+ this.__drawContent(canvas, options);
7217
+ canvas.restore();
7218
+ }
7219
+ else
7220
+ this.__drawContent(canvas, options);
7174
7221
  }
7175
7222
  };
7176
7223
  function drawFast(ui, canvas, options) {
@@ -7237,8 +7284,8 @@ var LeaferUI = (function (exports) {
7237
7284
  return pen;
7238
7285
  }
7239
7286
  get editConfig() { return undefined; }
7240
- get editOuter() { return this.__.__isLinePath ? 'LineEditTool' : 'EditTool'; }
7241
- get editInner() { return 'PathEditor'; }
7287
+ get editOuter() { return ''; }
7288
+ get editInner() { return ''; }
7242
7289
  constructor(data) {
7243
7290
  super(data);
7244
7291
  }
@@ -7249,9 +7296,8 @@ var LeaferUI = (function (exports) {
7249
7296
  Object.assign(this, data);
7250
7297
  this.lockNormalStyle = false;
7251
7298
  }
7252
- else {
7299
+ else
7253
7300
  Object.assign(this, data);
7254
- }
7255
7301
  }
7256
7302
  get(name) {
7257
7303
  return typeof name === 'string' ? this.__.__getInput(name) : this.__.__getInputData(name);
@@ -7297,12 +7343,7 @@ var LeaferUI = (function (exports) {
7297
7343
  this.__drawPathByData(canvas, this.__.path);
7298
7344
  }
7299
7345
  __drawPathByData(drawer, data) {
7300
- if (data) {
7301
- PathDrawer.drawPathByData(drawer, data);
7302
- }
7303
- else {
7304
- this.__drawPathByBox(drawer);
7305
- }
7346
+ data ? PathDrawer.drawPathByData(drawer, data) : this.__drawPathByBox(drawer);
7306
7347
  }
7307
7348
  __drawPathByBox(drawer) {
7308
7349
  const { x, y, width, height } = this.__layout.boxBounds;
@@ -7310,9 +7351,8 @@ var LeaferUI = (function (exports) {
7310
7351
  const { cornerRadius } = this.__;
7311
7352
  drawer.roundRect(x, y, width, height, typeof cornerRadius === 'number' ? [cornerRadius] : cornerRadius);
7312
7353
  }
7313
- else {
7354
+ else
7314
7355
  drawer.rect(x, y, width, height);
7315
- }
7316
7356
  }
7317
7357
  animate(_keyframe, _options, _type, _isTemp) {
7318
7358
  return needPlugin('animate');
@@ -7559,23 +7599,13 @@ var LeaferUI = (function (exports) {
7559
7599
  if (data.children) {
7560
7600
  const { children } = data;
7561
7601
  delete data.children;
7562
- if (!this.children) {
7563
- this.__setBranch();
7564
- }
7565
- else {
7566
- this.clear();
7567
- }
7602
+ this.children ? this.clear() : this.__setBranch();
7568
7603
  super.set(data, isTemp);
7569
- let child;
7570
- children.forEach(childData => {
7571
- child = childData.__ ? childData : UICreator.get(childData.tag, childData);
7572
- this.add(child);
7573
- });
7604
+ children.forEach(child => this.add(child));
7574
7605
  data.children = children;
7575
7606
  }
7576
- else {
7607
+ else
7577
7608
  super.set(data, isTemp);
7578
- }
7579
7609
  }
7580
7610
  toJSON(options) {
7581
7611
  const data = super.toJSON(options);
@@ -7995,10 +8025,9 @@ var LeaferUI = (function (exports) {
7995
8025
  registerUI()
7996
8026
  ], exports.Rect);
7997
8027
 
7998
- const rect = exports.Rect.prototype;
7999
- const group = exports.Group.prototype;
8028
+ const { copy: copy$2, add, includes: includes$1 } = BoundsHelper;
8029
+ const rect = exports.Rect.prototype, group = exports.Group.prototype;
8000
8030
  const childrenRenderBounds = {};
8001
- const { copy: copy$2, add, includes: includes$1, copyAndSpread: copyAndSpread$1 } = BoundsHelper;
8002
8031
  exports.Box = class Box extends exports.Group {
8003
8032
  get __tag() { return 'Box'; }
8004
8033
  get isBranchLeaf() { return true; }
@@ -8008,37 +8037,31 @@ var LeaferUI = (function (exports) {
8008
8037
  }
8009
8038
  __updateStrokeSpread() { return 0; }
8010
8039
  __updateRectRenderSpread() { return 0; }
8011
- __updateRenderSpread() {
8012
- return this.__updateRectRenderSpread() || -1;
8013
- }
8040
+ __updateRenderSpread() { return this.__updateRectRenderSpread() || -1; }
8014
8041
  __updateRectBoxBounds() { }
8015
- __updateBoxBounds(secondLayout) {
8042
+ __updateBoxBounds(_secondLayout) {
8016
8043
  const data = this.__;
8017
8044
  if (this.children.length) {
8018
8045
  if (data.__autoSide) {
8019
- if (this.leafer && this.leafer.ready)
8020
- this.leafer.layouter.addExtra(this);
8021
8046
  super.__updateBoxBounds();
8022
8047
  const { boxBounds } = this.__layout;
8023
8048
  if (!data.__autoSize) {
8024
- if (data.__autoWidth)
8025
- boxBounds.width += boxBounds.x, boxBounds.height = data.height, boxBounds.y = boxBounds.x = 0;
8026
- else
8027
- boxBounds.height += boxBounds.y, boxBounds.width = data.width, boxBounds.x = boxBounds.y = 0;
8049
+ if (data.__autoWidth) {
8050
+ boxBounds.width += boxBounds.x, boxBounds.x = 0;
8051
+ boxBounds.height = data.height, boxBounds.y = 0;
8052
+ }
8053
+ else {
8054
+ boxBounds.height += boxBounds.y, boxBounds.y = 0;
8055
+ boxBounds.width = data.width, boxBounds.x = 0;
8056
+ }
8028
8057
  }
8029
- if (secondLayout && data.flow && data.padding)
8030
- copyAndSpread$1(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'));
8031
8058
  this.__updateNaturalSize();
8032
8059
  }
8033
- else {
8060
+ else
8034
8061
  this.__updateRectBoxBounds();
8035
- }
8036
- if (data.flow)
8037
- this.__updateContentBounds();
8038
8062
  }
8039
- else {
8063
+ else
8040
8064
  this.__updateRectBoxBounds();
8041
- }
8042
8065
  }
8043
8066
  __updateStrokeBounds() { }
8044
8067
  __updateRenderBounds() {
@@ -8048,14 +8071,13 @@ var LeaferUI = (function (exports) {
8048
8071
  super.__updateRenderBounds();
8049
8072
  copy$2(childrenRenderBounds, renderBounds);
8050
8073
  this.__updateRectRenderBounds();
8051
- isOverflow = !includes$1(renderBounds, childrenRenderBounds) || !this.pathInputed || !this.__.cornerRadius;
8074
+ isOverflow = !includes$1(renderBounds, childrenRenderBounds);
8075
+ if (isOverflow && this.__.overflow !== 'hide')
8076
+ add(renderBounds, childrenRenderBounds);
8052
8077
  }
8053
- else {
8078
+ else
8054
8079
  this.__updateRectRenderBounds();
8055
- }
8056
- this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
8057
- if (!(this.__.__drawAfterFill = this.__.overflow === 'hide') && isOverflow)
8058
- add(renderBounds, childrenRenderBounds);
8080
+ !this.isOverflow !== !isOverflow && (this.isOverflow = isOverflow);
8059
8081
  }
8060
8082
  __updateRectRenderBounds() { }
8061
8083
  __updateRectChange() { }
@@ -8075,20 +8097,9 @@ var LeaferUI = (function (exports) {
8075
8097
  this.__renderGroup(canvas, options);
8076
8098
  }
8077
8099
  }
8078
- __drawAfterFill(canvas, options) {
8079
- const { length } = this.children;
8080
- if (this.isOverflow) {
8081
- canvas.save();
8082
- canvas.clip();
8083
- if (length)
8084
- this.__renderGroup(canvas, options);
8085
- canvas.restore();
8086
- }
8087
- else {
8088
- if (length)
8089
- this.__renderGroup(canvas, options);
8090
- }
8091
- if (this.__.stroke && length) {
8100
+ __drawContent(canvas, options) {
8101
+ this.__renderGroup(canvas, options);
8102
+ if (this.__.__hasStroke) {
8092
8103
  canvas.setWorld(this.__nowWorld);
8093
8104
  this.__drawRenderPath(canvas);
8094
8105
  }
@@ -8100,6 +8111,9 @@ var LeaferUI = (function (exports) {
8100
8111
  __decorate([
8101
8112
  dataType(false)
8102
8113
  ], exports.Box.prototype, "resizeChildren", void 0);
8114
+ __decorate([
8115
+ dataType(false)
8116
+ ], exports.Box.prototype, "textBox", void 0);
8103
8117
  __decorate([
8104
8118
  affectRenderBoundsType('show')
8105
8119
  ], exports.Box.prototype, "overflow", void 0);
@@ -8249,17 +8263,15 @@ var LeaferUI = (function (exports) {
8249
8263
  if (data.__useArrow)
8250
8264
  PathArrow.addArrows(this, false);
8251
8265
  }
8252
- else {
8266
+ else
8253
8267
  super.__updateRenderPath();
8254
- }
8255
8268
  }
8256
8269
  __updateBoxBounds() {
8257
8270
  if (this.points) {
8258
8271
  toBounds$1(this.__.__pathForRender, this.__layout.boxBounds);
8259
8272
  }
8260
- else {
8273
+ else
8261
8274
  super.__updateBoxBounds();
8262
- }
8263
8275
  }
8264
8276
  };
8265
8277
  __decorate([
@@ -8397,7 +8409,6 @@ var LeaferUI = (function (exports) {
8397
8409
  super(data);
8398
8410
  this.canvas = Creator.canvas(this.__);
8399
8411
  this.context = this.canvas.context;
8400
- this.__.__isCanvas = this.__.__drawAfterFill = true;
8401
8412
  if (data && data.url)
8402
8413
  this.drawImage(data.url);
8403
8414
  }
@@ -8410,8 +8421,7 @@ var LeaferUI = (function (exports) {
8410
8421
  });
8411
8422
  }
8412
8423
  draw(ui, offset, scale, rotation) {
8413
- ui.__layout.update();
8414
- const matrix = new Matrix(ui.__world).invert();
8424
+ const matrix = new Matrix(ui.worldTransform).invert();
8415
8425
  const m = new Matrix();
8416
8426
  if (offset)
8417
8427
  m.translate(offset.x, offset.y);
@@ -8426,17 +8436,9 @@ var LeaferUI = (function (exports) {
8426
8436
  paint() {
8427
8437
  this.forceRender();
8428
8438
  }
8429
- __drawAfterFill(canvas, _options) {
8430
- const { width, height, cornerRadius } = this.__, { view } = this.canvas;
8431
- if (cornerRadius || this.pathInputed) {
8432
- canvas.save();
8433
- canvas.clip();
8434
- canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8435
- canvas.restore();
8436
- }
8437
- else {
8438
- canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8439
- }
8439
+ __drawContent(canvas, _options) {
8440
+ const { width, height } = this.__, { view } = this.canvas;
8441
+ canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8440
8442
  }
8441
8443
  __updateSize() {
8442
8444
  const { canvas } = this;
@@ -8480,7 +8482,6 @@ var LeaferUI = (function (exports) {
8480
8482
  const { copyAndSpread, includes, isSame: isSame$1, spread, setList } = BoundsHelper;
8481
8483
  exports.Text = class Text extends exports.UI {
8482
8484
  get __tag() { return 'Text'; }
8483
- get editInner() { return 'TextEditor'; }
8484
8485
  get textDrawData() {
8485
8486
  this.__layout.update();
8486
8487
  return this.__.__textDrawData;
@@ -8629,6 +8630,9 @@ var LeaferUI = (function (exports) {
8629
8630
  __decorate([
8630
8631
  boundsType('top')
8631
8632
  ], exports.Text.prototype, "verticalAlign", void 0);
8633
+ __decorate([
8634
+ boundsType(true)
8635
+ ], exports.Text.prototype, "autoSizeAlign", void 0);
8632
8636
  __decorate([
8633
8637
  boundsType('normal')
8634
8638
  ], exports.Text.prototype, "textWrap", void 0);
@@ -8643,7 +8647,6 @@ var LeaferUI = (function (exports) {
8643
8647
  get __tag() { return 'Path'; }
8644
8648
  constructor(data) {
8645
8649
  super(data);
8646
- this.__.__pathInputed = 2;
8647
8650
  }
8648
8651
  };
8649
8652
  __decorate([
@@ -9170,9 +9173,10 @@ var LeaferUI = (function (exports) {
9170
9173
  onLoadError(ui, event, image.error);
9171
9174
  }
9172
9175
  else {
9173
- ignoreRender(ui, true);
9174
- if (firstUse)
9176
+ if (firstUse) {
9177
+ ignoreRender(ui, true);
9175
9178
  onLoad(ui, event);
9179
+ }
9176
9180
  leafPaint.loadId = image.load(() => {
9177
9181
  ignoreRender(ui, false);
9178
9182
  if (!ui.destroyed) {
@@ -9320,7 +9324,7 @@ var LeaferUI = (function (exports) {
9320
9324
  }
9321
9325
  if (allowPaint) {
9322
9326
  canvas.save();
9323
- canvas.clip();
9327
+ ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
9324
9328
  if (paint.blendMode)
9325
9329
  canvas.blendMode = paint.blendMode;
9326
9330
  if (data.opacity)
@@ -9784,11 +9788,12 @@ var LeaferUI = (function (exports) {
9784
9788
  const { Letter, Single, Before, After, Symbol, Break } = CharType;
9785
9789
  let word, row, wordWidth, rowWidth, realWidth;
9786
9790
  let char, charWidth, startCharSize, charSize, charType, lastCharType, langBreak, afterBreak, paraStart;
9787
- let textDrawData, rows = [], bounds;
9791
+ let textDrawData, rows = [], bounds, findMaxWidth;
9788
9792
  function createRows(drawData, content, style) {
9789
9793
  textDrawData = drawData;
9790
9794
  rows = drawData.rows;
9791
9795
  bounds = drawData.bounds;
9796
+ findMaxWidth = !bounds.width && !style.autoSizeAlign;
9792
9797
  const { __letterSpacing, paraIndent, textCase } = style;
9793
9798
  const { canvas } = Platform;
9794
9799
  const { width, height } = bounds;
@@ -9873,7 +9878,10 @@ var LeaferUI = (function (exports) {
9873
9878
  else {
9874
9879
  content.split('\n').forEach(content => {
9875
9880
  textDrawData.paraNumber++;
9876
- rows.push({ x: paraIndent || 0, text: content, width: canvas.measureText(content).width, paraStart: true });
9881
+ rowWidth = canvas.measureText(content).width;
9882
+ rows.push({ x: paraIndent || 0, text: content, width: rowWidth, paraStart: true });
9883
+ if (findMaxWidth)
9884
+ setMaxWidth();
9877
9885
  });
9878
9886
  }
9879
9887
  }
@@ -9904,10 +9912,16 @@ var LeaferUI = (function (exports) {
9904
9912
  row.width = rowWidth;
9905
9913
  if (bounds.width)
9906
9914
  trimRight(row);
9915
+ else if (findMaxWidth)
9916
+ setMaxWidth();
9907
9917
  rows.push(row);
9908
9918
  row = { words: [] };
9909
9919
  rowWidth = 0;
9910
9920
  }
9921
+ function setMaxWidth() {
9922
+ if (rowWidth > (textDrawData.maxWidth || 0))
9923
+ textDrawData.maxWidth = rowWidth;
9924
+ }
9911
9925
 
9912
9926
  const CharMode = 0;
9913
9927
  const WordMode = 1;
@@ -9979,34 +9993,32 @@ var LeaferUI = (function (exports) {
9979
9993
 
9980
9994
  function layoutText(drawData, style) {
9981
9995
  const { rows, bounds } = drawData;
9982
- const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing } = style;
9996
+ const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
9983
9997
  let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
9984
9998
  let starY = __baseLine;
9985
9999
  if (__clipText && realHeight > height) {
9986
10000
  realHeight = Math.max(height, __lineHeight);
9987
10001
  drawData.overflow = rows.length;
9988
10002
  }
9989
- else {
10003
+ else if (height || autoSizeAlign) {
9990
10004
  switch (verticalAlign) {
9991
10005
  case 'middle':
9992
10006
  y += (height - realHeight) / 2;
9993
10007
  break;
9994
- case 'bottom':
9995
- y += (height - realHeight);
10008
+ case 'bottom': y += (height - realHeight);
9996
10009
  }
9997
10010
  }
9998
10011
  starY += y;
9999
- let row, rowX, rowWidth;
10012
+ let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
10000
10013
  for (let i = 0, len = rows.length; i < len; i++) {
10001
10014
  row = rows[i];
10002
10015
  row.x = x;
10003
10016
  if (row.width < width || (row.width > width && !__clipText)) {
10004
10017
  switch (textAlign) {
10005
10018
  case 'center':
10006
- row.x += (width - row.width) / 2;
10019
+ row.x += (layoutWidth - row.width) / 2;
10007
10020
  break;
10008
- case 'right':
10009
- row.x += width - row.width;
10021
+ case 'right': row.x += layoutWidth - row.width;
10010
10022
  }
10011
10023
  }
10012
10024
  if (row.paraStart && paraSpacing && i > 0)
@@ -10111,14 +10123,14 @@ var LeaferUI = (function (exports) {
10111
10123
  let height = style.__getInput('height') || 0;
10112
10124
  const { textDecoration, __font, __padding: padding } = style;
10113
10125
  if (padding) {
10114
- if (width) {
10126
+ if (width)
10127
+ x = padding[left], width -= (padding[right] + padding[left]);
10128
+ else if (!style.autoSizeAlign)
10115
10129
  x = padding[left];
10116
- width -= (padding[right] + padding[left]);
10117
- }
10118
- if (height) {
10130
+ if (height)
10131
+ y = padding[top], height -= (padding[top] + padding[bottom]);
10132
+ else if (!style.autoSizeAlign)
10119
10133
  y = padding[top];
10120
- height -= (padding[top] + padding[bottom]);
10121
- }
10122
10134
  }
10123
10135
  const drawData = {
10124
10136
  bounds: { x, y, width, height },
@@ -10138,22 +10150,20 @@ var LeaferUI = (function (exports) {
10138
10150
  return drawData;
10139
10151
  }
10140
10152
  function padAutoText(padding, drawData, style, width, height) {
10141
- if (!width) {
10153
+ if (!width && style.autoSizeAlign) {
10142
10154
  switch (style.textAlign) {
10143
10155
  case 'left':
10144
10156
  offsetText(drawData, 'x', padding[left]);
10145
10157
  break;
10146
- case 'right':
10147
- offsetText(drawData, 'x', -padding[right]);
10158
+ case 'right': offsetText(drawData, 'x', -padding[right]);
10148
10159
  }
10149
10160
  }
10150
- if (!height) {
10161
+ if (!height && style.autoSizeAlign) {
10151
10162
  switch (style.verticalAlign) {
10152
10163
  case 'top':
10153
10164
  offsetText(drawData, 'y', padding[top]);
10154
10165
  break;
10155
- case 'bottom':
10156
- offsetText(drawData, 'y', -padding[bottom]);
10166
+ case 'bottom': offsetText(drawData, 'y', -padding[bottom]);
10157
10167
  }
10158
10168
  }
10159
10169
  }