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.
@@ -552,6 +552,12 @@ const PointHelper = {
552
552
  to.y = t.y + sin$4(r) * distance;
553
553
  return to;
554
554
  },
555
+ toNumberPoints(originPoints) {
556
+ let points = originPoints;
557
+ if (typeof originPoints[0] === 'object')
558
+ points = [], originPoints.forEach(p => points.push(p.x, p.y));
559
+ return points;
560
+ },
555
561
  reset(t) {
556
562
  P$5.reset(t);
557
563
  }
@@ -1542,7 +1548,10 @@ const { assign } = DataHelper;
1542
1548
 
1543
1549
  class LeafData {
1544
1550
  get __useNaturalRatio() { return true; }
1545
- get __isLinePath() { return this.path && this.path.length === 6; }
1551
+ get __isLinePath() {
1552
+ const { path } = this;
1553
+ return path && path.length === 6 && path[0] === 1;
1554
+ }
1546
1555
  get __blendMode() {
1547
1556
  if (this.eraser && this.eraser !== 'path')
1548
1557
  return 'destination-out';
@@ -2305,11 +2314,12 @@ const RectHelper = {
2305
2314
 
2306
2315
  const { sin: sin$3, cos: cos$3, atan2: atan2$1, ceil: ceil$1, abs: abs$3, PI: PI$2, sqrt: sqrt$1, pow } = Math;
2307
2316
  const { setPoint: setPoint$2, addPoint: addPoint$2 } = TwoPointBoundsHelper;
2308
- const { set } = PointHelper;
2317
+ const { set, toNumberPoints } = PointHelper;
2309
2318
  const { M: M$5, L: L$6, C: C$5, Q: Q$4, Z: Z$5 } = PathCommandMap;
2310
2319
  const tempPoint$2 = {};
2311
2320
  const BezierHelper = {
2312
- points(data, points, curve, close) {
2321
+ points(data, originPoints, curve, close) {
2322
+ let points = toNumberPoints(originPoints);
2313
2323
  data.push(M$5, points[0], points[1]);
2314
2324
  if (curve && points.length > 5) {
2315
2325
  let aX, aY, bX, bY, cX, cY, c1X, c1Y, c2X, c2Y;
@@ -2818,6 +2828,27 @@ const PathConvert = {
2818
2828
  }
2819
2829
  return data;
2820
2830
  },
2831
+ objectToCanvasData(list) {
2832
+ const data = [];
2833
+ list.forEach(item => {
2834
+ switch (item.name) {
2835
+ case 'M':
2836
+ data.push(M$4, item.x, item.y);
2837
+ break;
2838
+ case 'L':
2839
+ data.push(L$5, item.x, item.y);
2840
+ break;
2841
+ case 'C':
2842
+ data.push(C$4, item.x1, item.y1, item.x2, item.y2, item.x, item.y);
2843
+ break;
2844
+ case 'Q':
2845
+ data.push(Q$3, item.x1, item.y1, item.x, item.y);
2846
+ break;
2847
+ case 'Z': data.push(Z$4);
2848
+ }
2849
+ });
2850
+ return data;
2851
+ },
2821
2852
  copyData(data, old, index, count) {
2822
2853
  for (let i = index, end = index + count; i < end; i++) {
2823
2854
  data.push(old[i]);
@@ -4755,6 +4786,7 @@ class RenderEvent extends Event {
4755
4786
  }
4756
4787
  }
4757
4788
  RenderEvent.REQUEST = 'render.request';
4789
+ RenderEvent.CHILD_START = 'render.child_start';
4758
4790
  RenderEvent.START = 'render.start';
4759
4791
  RenderEvent.BEFORE = 'render.before';
4760
4792
  RenderEvent.RENDER = 'render';
@@ -4930,7 +4962,7 @@ const { isFinite } = Number;
4930
4962
  const debug$6 = Debug.get('setAttr');
4931
4963
  const LeafDataProxy = {
4932
4964
  __setAttr(name, newValue, checkFiniteNumber) {
4933
- if (this.leafer && this.leafer.created) {
4965
+ if (this.leaferIsCreated) {
4934
4966
  const oldValue = this.__.__getInput(name);
4935
4967
  if (checkFiniteNumber && !isFinite(newValue) && newValue !== undefined) {
4936
4968
  debug$6.warn(this.innerName, name, newValue);
@@ -5002,7 +5034,7 @@ const LeafMatrix = {
5002
5034
 
5003
5035
  const { updateMatrix: updateMatrix$1, updateAllMatrix: updateAllMatrix$2 } = LeafHelper;
5004
5036
  const { updateBounds: updateBounds$1 } = BranchHelper;
5005
- const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$2, copy: copy$4 } = BoundsHelper;
5037
+ const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$1, copy: copy$4 } = BoundsHelper;
5006
5038
  const { toBounds: toBounds$2 } = PathBounds;
5007
5039
  const LeafBounds = {
5008
5040
  __updateWorldBounds() {
@@ -5085,7 +5117,7 @@ const LeafBounds = {
5085
5117
  const b = this.__layout.boxBounds;
5086
5118
  const data = this.__;
5087
5119
  if (data.__pathInputed) {
5088
- toBounds$2(data.__pathForRender, b);
5120
+ toBounds$2(data.path, b);
5089
5121
  }
5090
5122
  else {
5091
5123
  b.x = 0;
@@ -5097,7 +5129,7 @@ const LeafBounds = {
5097
5129
  __updateAutoLayout() {
5098
5130
  this.__layout.matrixChanged = true;
5099
5131
  if (this.isBranch) {
5100
- if (this.leafer && this.leafer.ready)
5132
+ if (this.leaferIsReady)
5101
5133
  this.leafer.layouter.addExtra(this);
5102
5134
  if (this.__.flow) {
5103
5135
  if (this.__layout.boxChanged)
@@ -5123,11 +5155,11 @@ const LeafBounds = {
5123
5155
  },
5124
5156
  __updateStrokeBounds() {
5125
5157
  const layout = this.__layout;
5126
- copyAndSpread$2(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
5158
+ copyAndSpread$1(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
5127
5159
  },
5128
5160
  __updateRenderBounds() {
5129
5161
  const layout = this.__layout;
5130
- layout.renderSpread > 0 ? copyAndSpread$2(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$4(layout.renderBounds, layout.strokeBounds);
5162
+ layout.renderSpread > 0 ? copyAndSpread$1(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$4(layout.renderBounds, layout.strokeBounds);
5131
5163
  }
5132
5164
  };
5133
5165
 
@@ -5158,7 +5190,7 @@ const LeafRender = {
5158
5190
  if (this.__worldOpacity) {
5159
5191
  canvas.setWorld(this.__nowWorld = this.__getNowWorld(options));
5160
5192
  this.__drawRenderPath(canvas);
5161
- this.__.windingRule ? canvas.clip(this.__.windingRule) : canvas.clip();
5193
+ this.windingRule ? canvas.clip(this.windingRule) : canvas.clip();
5162
5194
  }
5163
5195
  },
5164
5196
  __updateWorldOpacity() {
@@ -5232,6 +5264,8 @@ let Leaf = class Leaf {
5232
5264
  get innerName() { return this.__.name || this.tag + this.innerId; }
5233
5265
  get __DataProcessor() { return LeafData; }
5234
5266
  get __LayoutProcessor() { return LeafLayout; }
5267
+ get leaferIsCreated() { return this.leafer && this.leafer.created; }
5268
+ get leaferIsReady() { return this.leafer && this.leafer.ready; }
5235
5269
  get isLeafer() { return false; }
5236
5270
  get isBranch() { return false; }
5237
5271
  get isBranchLeaf() { return false; }
@@ -5673,10 +5707,17 @@ let Branch = class Branch extends Leaf {
5673
5707
  add(child, index) {
5674
5708
  if (child === this)
5675
5709
  return;
5710
+ const noIndex = index === undefined;
5711
+ if (!child.__) {
5712
+ if (child instanceof Array)
5713
+ return child.forEach(item => { this.add(item, index); noIndex || index++; });
5714
+ else
5715
+ child = UICreator.get(child.tag, child);
5716
+ }
5676
5717
  if (child.parent)
5677
5718
  child.parent.remove(child);
5678
5719
  child.parent = this;
5679
- index === undefined ? this.children.push(child) : this.children.splice(index, 0, child);
5720
+ noIndex ? this.children.push(child) : this.children.splice(index, 0, child);
5680
5721
  if (child.isBranch)
5681
5722
  this.__.__childBranchNumber = (this.__.__childBranchNumber || 0) + 1;
5682
5723
  child.__layout.boxChanged || child.__layout.boxChange();
@@ -5690,15 +5731,17 @@ let Branch = class Branch extends Leaf {
5690
5731
  }
5691
5732
  this.__layout.affectChildrenSort && this.__layout.childrenSortChange();
5692
5733
  }
5693
- addMany(...children) {
5694
- children.forEach(child => this.add(child));
5695
- }
5734
+ addMany(...children) { this.add(children); }
5696
5735
  remove(child, destroy) {
5697
5736
  if (child) {
5698
- if (child.animationOut)
5699
- child.__runAnimation('out', () => this.__remove(child, destroy));
5737
+ if (child.__) {
5738
+ if (child.animationOut)
5739
+ child.__runAnimation('out', () => this.__remove(child, destroy));
5740
+ else
5741
+ this.__remove(child, destroy);
5742
+ }
5700
5743
  else
5701
- this.__remove(child, destroy);
5744
+ this.find(child).forEach(item => this.remove(item, destroy));
5702
5745
  }
5703
5746
  else if (child === undefined) {
5704
5747
  super.remove(null, destroy);
@@ -5916,7 +5959,7 @@ class LeafLevelList {
5916
5959
  }
5917
5960
  }
5918
5961
 
5919
- const version = "1.0.4";
5962
+ const version = "1.0.6";
5920
5963
 
5921
5964
  const debug$5 = Debug.get('LeaferCanvas');
5922
5965
  class LeaferCanvas extends LeaferCanvasBase {
@@ -6074,7 +6117,7 @@ class LeaferCanvas extends LeaferCanvasBase {
6074
6117
  const oldSize = {};
6075
6118
  DataHelper.copyAttrs(oldSize, this, canvasSizeAttrs);
6076
6119
  this.resize(size);
6077
- if (this.width !== undefined)
6120
+ if (this.resizeListener && this.width !== undefined)
6078
6121
  this.resizeListener(new ResizeEvent(size, oldSize));
6079
6122
  }
6080
6123
  unrealCanvas() {
@@ -6558,6 +6601,7 @@ class Renderer {
6558
6601
  this.totalBounds = new Bounds();
6559
6602
  debug$3.log(target.innerName, '--->');
6560
6603
  try {
6604
+ target.app.emit(RenderEvent.CHILD_START, target);
6561
6605
  this.emitRender(RenderEvent.START);
6562
6606
  this.renderOnce(callback);
6563
6607
  this.emitRender(RenderEvent.END, this.totalBounds);
@@ -6797,6 +6841,13 @@ function zoomLayerType() {
6797
6841
 
6798
6842
  const TextConvert = {};
6799
6843
  const ColorConvert = {};
6844
+ const UnitConvert = {
6845
+ number(value, percentRefer) {
6846
+ if (typeof value === 'object')
6847
+ return value.type === 'percent' ? value.value * percentRefer : value.value;
6848
+ return value;
6849
+ }
6850
+ };
6800
6851
  const PathArrow = {};
6801
6852
  const Paint = {};
6802
6853
  const PaintImage = {};
@@ -6817,7 +6868,7 @@ const Transition = {
6817
6868
  }
6818
6869
  };
6819
6870
 
6820
- const { parse } = PathConvert;
6871
+ const { parse, objectToCanvasData } = PathConvert;
6821
6872
  const emptyPaint = {};
6822
6873
  const debug$2 = Debug.get('UIData');
6823
6874
  class UIData extends LeafData {
@@ -6831,10 +6882,11 @@ class UIData extends LeafData {
6831
6882
  scaleX = -scaleX;
6832
6883
  return scaleX > 1 ? strokeWidth / scaleX : strokeWidth;
6833
6884
  }
6834
- else {
6885
+ else
6835
6886
  return strokeWidth;
6836
- }
6837
6887
  }
6888
+ get __hasStroke() { return this.stroke && this.strokeWidth; }
6889
+ get __clipAfterFill() { return (this.cornerRadius || this.__pathInputed); }
6838
6890
  get __autoWidth() { return !this._width; }
6839
6891
  get __autoHeight() { return !this._height; }
6840
6892
  get __autoSide() { return !this._width || !this._height; }
@@ -6851,9 +6903,8 @@ class UIData extends LeafData {
6851
6903
  this.__leaf.scaleX *= -1;
6852
6904
  debug$2.warn('width < 0, instead -scaleX ', this);
6853
6905
  }
6854
- else {
6906
+ else
6855
6907
  this._width = value;
6856
- }
6857
6908
  }
6858
6909
  setHeight(value) {
6859
6910
  if (value < 0) {
@@ -6861,9 +6912,8 @@ class UIData extends LeafData {
6861
6912
  this.__leaf.scaleY *= -1;
6862
6913
  debug$2.warn('height < 0, instead -scaleY', this);
6863
6914
  }
6864
- else {
6915
+ else
6865
6916
  this._height = value;
6866
- }
6867
6917
  }
6868
6918
  setFill(value) {
6869
6919
  if (this.__naturalWidth)
@@ -6904,9 +6954,10 @@ class UIData extends LeafData {
6904
6954
  }
6905
6955
  }
6906
6956
  setPath(value) {
6907
- if (typeof value === 'string') {
6957
+ const isString = typeof value === 'string';
6958
+ if (isString || (value && typeof value[0] === 'object')) {
6908
6959
  this.__setInput('path', value);
6909
- this._path = parse(value);
6960
+ this._path = isString ? parse(value) : objectToCanvasData(value);
6910
6961
  }
6911
6962
  else {
6912
6963
  if (this.__input)
@@ -6921,12 +6972,8 @@ class UIData extends LeafData {
6921
6972
  value = value.filter((item) => item.visible !== false);
6922
6973
  this._shadow = value.length ? value : null;
6923
6974
  }
6924
- else if (value) {
6925
- this._shadow = value.visible === false ? null : [value];
6926
- }
6927
- else {
6928
- this._shadow = null;
6929
- }
6975
+ else
6976
+ this._shadow = value && value.visible !== false ? [value] : null;
6930
6977
  }
6931
6978
  setInnerShadow(value) {
6932
6979
  this.__setInput('innerShadow', value);
@@ -6935,12 +6982,8 @@ class UIData extends LeafData {
6935
6982
  value = value.filter((item) => item.visible !== false);
6936
6983
  this._innerShadow = value.length ? value : null;
6937
6984
  }
6938
- else if (value) {
6939
- this._innerShadow = value.visible === false ? null : [value];
6940
- }
6941
- else {
6942
- this._innerShadow = null;
6943
- }
6985
+ else
6986
+ this._innerShadow = value && value.visible !== false ? [value] : null;
6944
6987
  }
6945
6988
  __computePaint() {
6946
6989
  const { fill, stroke } = this.__input;
@@ -6951,24 +6994,19 @@ class UIData extends LeafData {
6951
6994
  this.__needComputePaint = false;
6952
6995
  }
6953
6996
  }
6954
- const UnitConvert = {
6955
- number(value, percentRefer) {
6956
- if (typeof value === 'object')
6957
- return value.type === 'percent' ? value.value * percentRefer : value.value;
6958
- return value;
6959
- }
6960
- };
6961
6997
 
6962
6998
  class GroupData extends UIData {
6963
6999
  }
6964
7000
 
6965
7001
  class BoxData extends GroupData {
6966
7002
  get __boxStroke() { return !this.__pathInputed; }
7003
+ get __drawAfterFill() { return this.overflow === 'hide' && this.__clipAfterFill && this.__leaf.children.length; }
7004
+ get __clipAfterFill() { return this.__leaf.isOverflow || super.__clipAfterFill; }
6967
7005
  }
6968
7006
 
6969
7007
  class LeaferData extends GroupData {
6970
- __getInputData() {
6971
- const data = super.__getInputData();
7008
+ __getInputData(names, options) {
7009
+ const data = super.__getInputData(names, options);
6972
7010
  canvasSizeAttrs.forEach(key => delete data[key]);
6973
7011
  return data;
6974
7012
  }
@@ -6995,6 +7033,7 @@ class StarData extends UIData {
6995
7033
  }
6996
7034
 
6997
7035
  class PathData extends UIData {
7036
+ get __pathInputed() { return 2; }
6998
7037
  }
6999
7038
 
7000
7039
  class PenData extends GroupData {
@@ -7041,16 +7080,18 @@ class ImageData extends RectData {
7041
7080
  delete data.fill;
7042
7081
  return data;
7043
7082
  }
7044
- __getInputData() {
7045
- const data = super.__getInputData();
7083
+ __getInputData(names, options) {
7084
+ const data = super.__getInputData(names, options);
7046
7085
  delete data.fill;
7047
7086
  return data;
7048
7087
  }
7049
7088
  }
7050
7089
 
7051
7090
  class CanvasData extends RectData {
7052
- __getInputData() {
7053
- const data = super.__getInputData();
7091
+ get __isCanvas() { return true; }
7092
+ get __drawAfterFill() { return true; }
7093
+ __getInputData(names, options) {
7094
+ const data = super.__getInputData(names, options);
7054
7095
  data.url = this.__leaf.canvas.toDataURL('image/png');
7055
7096
  return data;
7056
7097
  }
@@ -7077,16 +7118,12 @@ const UIBounds = {
7077
7118
  let width = 0;
7078
7119
  const { shadow, innerShadow, blur, backgroundBlur } = this.__;
7079
7120
  if (shadow)
7080
- shadow.forEach(item => {
7081
- width = Math.max(width, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread > 0 ? item.spread : 0) + item.blur * 1.5);
7082
- });
7121
+ 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));
7083
7122
  if (blur)
7084
7123
  width = Math.max(width, blur);
7085
7124
  let shapeWidth = width = Math.ceil(width);
7086
7125
  if (innerShadow)
7087
- innerShadow.forEach(item => {
7088
- shapeWidth = Math.max(shapeWidth, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread < 0 ? -item.spread : 0) + item.blur * 1.5);
7089
- });
7126
+ 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));
7090
7127
  if (backgroundBlur)
7091
7128
  shapeWidth = Math.max(shapeWidth, backgroundBlur);
7092
7129
  this.__layout.renderShapeSpread = shapeWidth;
@@ -7168,6 +7205,16 @@ const UIRender = {
7168
7205
  if (stroke && !ignoreStroke)
7169
7206
  this.__.__pixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
7170
7207
  }
7208
+ },
7209
+ __drawAfterFill(canvas, options) {
7210
+ if (this.__.__clipAfterFill) {
7211
+ canvas.save();
7212
+ this.windingRule ? canvas.clip(this.windingRule) : canvas.clip();
7213
+ this.__drawContent(canvas, options);
7214
+ canvas.restore();
7215
+ }
7216
+ else
7217
+ this.__drawContent(canvas, options);
7171
7218
  }
7172
7219
  };
7173
7220
  function drawFast(ui, canvas, options) {
@@ -7234,8 +7281,8 @@ let UI = UI_1 = class UI extends Leaf {
7234
7281
  return pen;
7235
7282
  }
7236
7283
  get editConfig() { return undefined; }
7237
- get editOuter() { return this.__.__isLinePath ? 'LineEditTool' : 'EditTool'; }
7238
- get editInner() { return 'PathEditor'; }
7284
+ get editOuter() { return ''; }
7285
+ get editInner() { return ''; }
7239
7286
  constructor(data) {
7240
7287
  super(data);
7241
7288
  }
@@ -7246,9 +7293,8 @@ let UI = UI_1 = class UI extends Leaf {
7246
7293
  Object.assign(this, data);
7247
7294
  this.lockNormalStyle = false;
7248
7295
  }
7249
- else {
7296
+ else
7250
7297
  Object.assign(this, data);
7251
- }
7252
7298
  }
7253
7299
  get(name) {
7254
7300
  return typeof name === 'string' ? this.__.__getInput(name) : this.__.__getInputData(name);
@@ -7294,12 +7340,7 @@ let UI = UI_1 = class UI extends Leaf {
7294
7340
  this.__drawPathByData(canvas, this.__.path);
7295
7341
  }
7296
7342
  __drawPathByData(drawer, data) {
7297
- if (data) {
7298
- PathDrawer.drawPathByData(drawer, data);
7299
- }
7300
- else {
7301
- this.__drawPathByBox(drawer);
7302
- }
7343
+ data ? PathDrawer.drawPathByData(drawer, data) : this.__drawPathByBox(drawer);
7303
7344
  }
7304
7345
  __drawPathByBox(drawer) {
7305
7346
  const { x, y, width, height } = this.__layout.boxBounds;
@@ -7307,9 +7348,8 @@ let UI = UI_1 = class UI extends Leaf {
7307
7348
  const { cornerRadius } = this.__;
7308
7349
  drawer.roundRect(x, y, width, height, typeof cornerRadius === 'number' ? [cornerRadius] : cornerRadius);
7309
7350
  }
7310
- else {
7351
+ else
7311
7352
  drawer.rect(x, y, width, height);
7312
- }
7313
7353
  }
7314
7354
  animate(_keyframe, _options, _type, _isTemp) {
7315
7355
  return needPlugin('animate');
@@ -7556,23 +7596,13 @@ let Group = class Group extends UI {
7556
7596
  if (data.children) {
7557
7597
  const { children } = data;
7558
7598
  delete data.children;
7559
- if (!this.children) {
7560
- this.__setBranch();
7561
- }
7562
- else {
7563
- this.clear();
7564
- }
7599
+ this.children ? this.clear() : this.__setBranch();
7565
7600
  super.set(data, isTemp);
7566
- let child;
7567
- children.forEach(childData => {
7568
- child = childData.__ ? childData : UICreator.get(childData.tag, childData);
7569
- this.add(child);
7570
- });
7601
+ children.forEach(child => this.add(child));
7571
7602
  data.children = children;
7572
7603
  }
7573
- else {
7604
+ else
7574
7605
  super.set(data, isTemp);
7575
- }
7576
7606
  }
7577
7607
  toJSON(options) {
7578
7608
  const data = super.toJSON(options);
@@ -7992,10 +8022,9 @@ Rect = __decorate([
7992
8022
  registerUI()
7993
8023
  ], Rect);
7994
8024
 
7995
- const rect = Rect.prototype;
7996
- const group = Group.prototype;
8025
+ const { copy: copy$2, add, includes: includes$1 } = BoundsHelper;
8026
+ const rect = Rect.prototype, group = Group.prototype;
7997
8027
  const childrenRenderBounds = {};
7998
- const { copy: copy$2, add, includes: includes$1, copyAndSpread: copyAndSpread$1 } = BoundsHelper;
7999
8028
  let Box = class Box extends Group {
8000
8029
  get __tag() { return 'Box'; }
8001
8030
  get isBranchLeaf() { return true; }
@@ -8005,37 +8034,31 @@ let Box = class Box extends Group {
8005
8034
  }
8006
8035
  __updateStrokeSpread() { return 0; }
8007
8036
  __updateRectRenderSpread() { return 0; }
8008
- __updateRenderSpread() {
8009
- return this.__updateRectRenderSpread() || -1;
8010
- }
8037
+ __updateRenderSpread() { return this.__updateRectRenderSpread() || -1; }
8011
8038
  __updateRectBoxBounds() { }
8012
- __updateBoxBounds(secondLayout) {
8039
+ __updateBoxBounds(_secondLayout) {
8013
8040
  const data = this.__;
8014
8041
  if (this.children.length) {
8015
8042
  if (data.__autoSide) {
8016
- if (this.leafer && this.leafer.ready)
8017
- this.leafer.layouter.addExtra(this);
8018
8043
  super.__updateBoxBounds();
8019
8044
  const { boxBounds } = this.__layout;
8020
8045
  if (!data.__autoSize) {
8021
- if (data.__autoWidth)
8022
- boxBounds.width += boxBounds.x, boxBounds.height = data.height, boxBounds.y = boxBounds.x = 0;
8023
- else
8024
- boxBounds.height += boxBounds.y, boxBounds.width = data.width, boxBounds.x = boxBounds.y = 0;
8046
+ if (data.__autoWidth) {
8047
+ boxBounds.width += boxBounds.x, boxBounds.x = 0;
8048
+ boxBounds.height = data.height, boxBounds.y = 0;
8049
+ }
8050
+ else {
8051
+ boxBounds.height += boxBounds.y, boxBounds.y = 0;
8052
+ boxBounds.width = data.width, boxBounds.x = 0;
8053
+ }
8025
8054
  }
8026
- if (secondLayout && data.flow && data.padding)
8027
- copyAndSpread$1(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'));
8028
8055
  this.__updateNaturalSize();
8029
8056
  }
8030
- else {
8057
+ else
8031
8058
  this.__updateRectBoxBounds();
8032
- }
8033
- if (data.flow)
8034
- this.__updateContentBounds();
8035
8059
  }
8036
- else {
8060
+ else
8037
8061
  this.__updateRectBoxBounds();
8038
- }
8039
8062
  }
8040
8063
  __updateStrokeBounds() { }
8041
8064
  __updateRenderBounds() {
@@ -8045,14 +8068,13 @@ let Box = class Box extends Group {
8045
8068
  super.__updateRenderBounds();
8046
8069
  copy$2(childrenRenderBounds, renderBounds);
8047
8070
  this.__updateRectRenderBounds();
8048
- isOverflow = !includes$1(renderBounds, childrenRenderBounds) || !this.pathInputed || !this.__.cornerRadius;
8071
+ isOverflow = !includes$1(renderBounds, childrenRenderBounds);
8072
+ if (isOverflow && this.__.overflow !== 'hide')
8073
+ add(renderBounds, childrenRenderBounds);
8049
8074
  }
8050
- else {
8075
+ else
8051
8076
  this.__updateRectRenderBounds();
8052
- }
8053
- this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
8054
- if (!(this.__.__drawAfterFill = this.__.overflow === 'hide') && isOverflow)
8055
- add(renderBounds, childrenRenderBounds);
8077
+ !this.isOverflow !== !isOverflow && (this.isOverflow = isOverflow);
8056
8078
  }
8057
8079
  __updateRectRenderBounds() { }
8058
8080
  __updateRectChange() { }
@@ -8072,20 +8094,9 @@ let Box = class Box extends Group {
8072
8094
  this.__renderGroup(canvas, options);
8073
8095
  }
8074
8096
  }
8075
- __drawAfterFill(canvas, options) {
8076
- const { length } = this.children;
8077
- if (this.isOverflow) {
8078
- canvas.save();
8079
- canvas.clip();
8080
- if (length)
8081
- this.__renderGroup(canvas, options);
8082
- canvas.restore();
8083
- }
8084
- else {
8085
- if (length)
8086
- this.__renderGroup(canvas, options);
8087
- }
8088
- if (this.__.stroke && length) {
8097
+ __drawContent(canvas, options) {
8098
+ this.__renderGroup(canvas, options);
8099
+ if (this.__.__hasStroke) {
8089
8100
  canvas.setWorld(this.__nowWorld);
8090
8101
  this.__drawRenderPath(canvas);
8091
8102
  }
@@ -8097,6 +8108,9 @@ __decorate([
8097
8108
  __decorate([
8098
8109
  dataType(false)
8099
8110
  ], Box.prototype, "resizeChildren", void 0);
8111
+ __decorate([
8112
+ dataType(false)
8113
+ ], Box.prototype, "textBox", void 0);
8100
8114
  __decorate([
8101
8115
  affectRenderBoundsType('show')
8102
8116
  ], Box.prototype, "overflow", void 0);
@@ -8246,17 +8260,15 @@ let Line = class Line extends UI {
8246
8260
  if (data.__useArrow)
8247
8261
  PathArrow.addArrows(this, false);
8248
8262
  }
8249
- else {
8263
+ else
8250
8264
  super.__updateRenderPath();
8251
- }
8252
8265
  }
8253
8266
  __updateBoxBounds() {
8254
8267
  if (this.points) {
8255
8268
  toBounds$1(this.__.__pathForRender, this.__layout.boxBounds);
8256
8269
  }
8257
- else {
8270
+ else
8258
8271
  super.__updateBoxBounds();
8259
- }
8260
8272
  }
8261
8273
  };
8262
8274
  __decorate([
@@ -8394,7 +8406,6 @@ let Canvas = class Canvas extends Rect {
8394
8406
  super(data);
8395
8407
  this.canvas = Creator.canvas(this.__);
8396
8408
  this.context = this.canvas.context;
8397
- this.__.__isCanvas = this.__.__drawAfterFill = true;
8398
8409
  if (data && data.url)
8399
8410
  this.drawImage(data.url);
8400
8411
  }
@@ -8407,8 +8418,7 @@ let Canvas = class Canvas extends Rect {
8407
8418
  });
8408
8419
  }
8409
8420
  draw(ui, offset, scale, rotation) {
8410
- ui.__layout.update();
8411
- const matrix = new Matrix(ui.__world).invert();
8421
+ const matrix = new Matrix(ui.worldTransform).invert();
8412
8422
  const m = new Matrix();
8413
8423
  if (offset)
8414
8424
  m.translate(offset.x, offset.y);
@@ -8423,17 +8433,9 @@ let Canvas = class Canvas extends Rect {
8423
8433
  paint() {
8424
8434
  this.forceRender();
8425
8435
  }
8426
- __drawAfterFill(canvas, _options) {
8427
- const { width, height, cornerRadius } = this.__, { view } = this.canvas;
8428
- if (cornerRadius || this.pathInputed) {
8429
- canvas.save();
8430
- canvas.clip();
8431
- canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8432
- canvas.restore();
8433
- }
8434
- else {
8435
- canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8436
- }
8436
+ __drawContent(canvas, _options) {
8437
+ const { width, height } = this.__, { view } = this.canvas;
8438
+ canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8437
8439
  }
8438
8440
  __updateSize() {
8439
8441
  const { canvas } = this;
@@ -8477,7 +8479,6 @@ Canvas = __decorate([
8477
8479
  const { copyAndSpread, includes, isSame: isSame$1, spread, setList } = BoundsHelper;
8478
8480
  let Text = class Text extends UI {
8479
8481
  get __tag() { return 'Text'; }
8480
- get editInner() { return 'TextEditor'; }
8481
8482
  get textDrawData() {
8482
8483
  this.__layout.update();
8483
8484
  return this.__.__textDrawData;
@@ -8626,6 +8627,9 @@ __decorate([
8626
8627
  __decorate([
8627
8628
  boundsType('top')
8628
8629
  ], Text.prototype, "verticalAlign", void 0);
8630
+ __decorate([
8631
+ boundsType(true)
8632
+ ], Text.prototype, "autoSizeAlign", void 0);
8629
8633
  __decorate([
8630
8634
  boundsType('normal')
8631
8635
  ], Text.prototype, "textWrap", void 0);
@@ -8640,7 +8644,6 @@ let Path = class Path extends UI {
8640
8644
  get __tag() { return 'Path'; }
8641
8645
  constructor(data) {
8642
8646
  super(data);
8643
- this.__.__pathInputed = 2;
8644
8647
  }
8645
8648
  };
8646
8649
  __decorate([
@@ -9167,9 +9170,10 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
9167
9170
  onLoadError(ui, event, image.error);
9168
9171
  }
9169
9172
  else {
9170
- ignoreRender(ui, true);
9171
- if (firstUse)
9173
+ if (firstUse) {
9174
+ ignoreRender(ui, true);
9172
9175
  onLoad(ui, event);
9176
+ }
9173
9177
  leafPaint.loadId = image.load(() => {
9174
9178
  ignoreRender(ui, false);
9175
9179
  if (!ui.destroyed) {
@@ -9317,7 +9321,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
9317
9321
  }
9318
9322
  if (allowPaint) {
9319
9323
  canvas.save();
9320
- canvas.clip();
9324
+ ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
9321
9325
  if (paint.blendMode)
9322
9326
  canvas.blendMode = paint.blendMode;
9323
9327
  if (data.opacity)
@@ -9781,11 +9785,12 @@ const { trimRight } = TextRowHelper;
9781
9785
  const { Letter, Single, Before, After, Symbol, Break } = CharType;
9782
9786
  let word, row, wordWidth, rowWidth, realWidth;
9783
9787
  let char, charWidth, startCharSize, charSize, charType, lastCharType, langBreak, afterBreak, paraStart;
9784
- let textDrawData, rows = [], bounds;
9788
+ let textDrawData, rows = [], bounds, findMaxWidth;
9785
9789
  function createRows(drawData, content, style) {
9786
9790
  textDrawData = drawData;
9787
9791
  rows = drawData.rows;
9788
9792
  bounds = drawData.bounds;
9793
+ findMaxWidth = !bounds.width && !style.autoSizeAlign;
9789
9794
  const { __letterSpacing, paraIndent, textCase } = style;
9790
9795
  const { canvas } = Platform;
9791
9796
  const { width, height } = bounds;
@@ -9870,7 +9875,10 @@ function createRows(drawData, content, style) {
9870
9875
  else {
9871
9876
  content.split('\n').forEach(content => {
9872
9877
  textDrawData.paraNumber++;
9873
- rows.push({ x: paraIndent || 0, text: content, width: canvas.measureText(content).width, paraStart: true });
9878
+ rowWidth = canvas.measureText(content).width;
9879
+ rows.push({ x: paraIndent || 0, text: content, width: rowWidth, paraStart: true });
9880
+ if (findMaxWidth)
9881
+ setMaxWidth();
9874
9882
  });
9875
9883
  }
9876
9884
  }
@@ -9901,10 +9909,16 @@ function addRow() {
9901
9909
  row.width = rowWidth;
9902
9910
  if (bounds.width)
9903
9911
  trimRight(row);
9912
+ else if (findMaxWidth)
9913
+ setMaxWidth();
9904
9914
  rows.push(row);
9905
9915
  row = { words: [] };
9906
9916
  rowWidth = 0;
9907
9917
  }
9918
+ function setMaxWidth() {
9919
+ if (rowWidth > (textDrawData.maxWidth || 0))
9920
+ textDrawData.maxWidth = rowWidth;
9921
+ }
9908
9922
 
9909
9923
  const CharMode = 0;
9910
9924
  const WordMode = 1;
@@ -9976,34 +9990,32 @@ function toChar(data, charX, rowData, isOverflow) {
9976
9990
 
9977
9991
  function layoutText(drawData, style) {
9978
9992
  const { rows, bounds } = drawData;
9979
- const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing } = style;
9993
+ const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
9980
9994
  let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
9981
9995
  let starY = __baseLine;
9982
9996
  if (__clipText && realHeight > height) {
9983
9997
  realHeight = Math.max(height, __lineHeight);
9984
9998
  drawData.overflow = rows.length;
9985
9999
  }
9986
- else {
10000
+ else if (height || autoSizeAlign) {
9987
10001
  switch (verticalAlign) {
9988
10002
  case 'middle':
9989
10003
  y += (height - realHeight) / 2;
9990
10004
  break;
9991
- case 'bottom':
9992
- y += (height - realHeight);
10005
+ case 'bottom': y += (height - realHeight);
9993
10006
  }
9994
10007
  }
9995
10008
  starY += y;
9996
- let row, rowX, rowWidth;
10009
+ let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
9997
10010
  for (let i = 0, len = rows.length; i < len; i++) {
9998
10011
  row = rows[i];
9999
10012
  row.x = x;
10000
10013
  if (row.width < width || (row.width > width && !__clipText)) {
10001
10014
  switch (textAlign) {
10002
10015
  case 'center':
10003
- row.x += (width - row.width) / 2;
10016
+ row.x += (layoutWidth - row.width) / 2;
10004
10017
  break;
10005
- case 'right':
10006
- row.x += width - row.width;
10018
+ case 'right': row.x += layoutWidth - row.width;
10007
10019
  }
10008
10020
  }
10009
10021
  if (row.paraStart && paraSpacing && i > 0)
@@ -10108,14 +10120,14 @@ function getDrawData(content, style) {
10108
10120
  let height = style.__getInput('height') || 0;
10109
10121
  const { textDecoration, __font, __padding: padding } = style;
10110
10122
  if (padding) {
10111
- if (width) {
10123
+ if (width)
10124
+ x = padding[left], width -= (padding[right] + padding[left]);
10125
+ else if (!style.autoSizeAlign)
10112
10126
  x = padding[left];
10113
- width -= (padding[right] + padding[left]);
10114
- }
10115
- if (height) {
10127
+ if (height)
10128
+ y = padding[top], height -= (padding[top] + padding[bottom]);
10129
+ else if (!style.autoSizeAlign)
10116
10130
  y = padding[top];
10117
- height -= (padding[top] + padding[bottom]);
10118
- }
10119
10131
  }
10120
10132
  const drawData = {
10121
10133
  bounds: { x, y, width, height },
@@ -10135,22 +10147,20 @@ function getDrawData(content, style) {
10135
10147
  return drawData;
10136
10148
  }
10137
10149
  function padAutoText(padding, drawData, style, width, height) {
10138
- if (!width) {
10150
+ if (!width && style.autoSizeAlign) {
10139
10151
  switch (style.textAlign) {
10140
10152
  case 'left':
10141
10153
  offsetText(drawData, 'x', padding[left]);
10142
10154
  break;
10143
- case 'right':
10144
- offsetText(drawData, 'x', -padding[right]);
10155
+ case 'right': offsetText(drawData, 'x', -padding[right]);
10145
10156
  }
10146
10157
  }
10147
- if (!height) {
10158
+ if (!height && style.autoSizeAlign) {
10148
10159
  switch (style.verticalAlign) {
10149
10160
  case 'top':
10150
10161
  offsetText(drawData, 'y', padding[top]);
10151
10162
  break;
10152
- case 'bottom':
10153
- offsetText(drawData, 'y', -padding[bottom]);
10163
+ case 'bottom': offsetText(drawData, 'y', -padding[bottom]);
10154
10164
  }
10155
10165
  }
10156
10166
  }