@leafer-draw/worker 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$5 = 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$5.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
  class LeaferCanvas extends LeaferCanvasBase {
5922
5965
  get allowBackgroundColor() { return true; }
@@ -6385,6 +6428,7 @@ class Renderer {
6385
6428
  this.totalBounds = new Bounds();
6386
6429
  debug$3.log(target.innerName, '--->');
6387
6430
  try {
6431
+ target.app.emit(RenderEvent.CHILD_START, target);
6388
6432
  this.emitRender(RenderEvent.START);
6389
6433
  this.renderOnce(callback);
6390
6434
  this.emitRender(RenderEvent.END, this.totalBounds);
@@ -6624,6 +6668,13 @@ function zoomLayerType() {
6624
6668
 
6625
6669
  const TextConvert = {};
6626
6670
  const ColorConvert = {};
6671
+ const UnitConvert = {
6672
+ number(value, percentRefer) {
6673
+ if (typeof value === 'object')
6674
+ return value.type === 'percent' ? value.value * percentRefer : value.value;
6675
+ return value;
6676
+ }
6677
+ };
6627
6678
  const PathArrow = {};
6628
6679
  const Paint = {};
6629
6680
  const PaintImage = {};
@@ -6644,7 +6695,7 @@ const Transition = {
6644
6695
  }
6645
6696
  };
6646
6697
 
6647
- const { parse } = PathConvert;
6698
+ const { parse, objectToCanvasData } = PathConvert;
6648
6699
  const emptyPaint = {};
6649
6700
  const debug$2 = Debug.get('UIData');
6650
6701
  class UIData extends LeafData {
@@ -6658,10 +6709,11 @@ class UIData extends LeafData {
6658
6709
  scaleX = -scaleX;
6659
6710
  return scaleX > 1 ? strokeWidth / scaleX : strokeWidth;
6660
6711
  }
6661
- else {
6712
+ else
6662
6713
  return strokeWidth;
6663
- }
6664
6714
  }
6715
+ get __hasStroke() { return this.stroke && this.strokeWidth; }
6716
+ get __clipAfterFill() { return (this.cornerRadius || this.__pathInputed); }
6665
6717
  get __autoWidth() { return !this._width; }
6666
6718
  get __autoHeight() { return !this._height; }
6667
6719
  get __autoSide() { return !this._width || !this._height; }
@@ -6678,9 +6730,8 @@ class UIData extends LeafData {
6678
6730
  this.__leaf.scaleX *= -1;
6679
6731
  debug$2.warn('width < 0, instead -scaleX ', this);
6680
6732
  }
6681
- else {
6733
+ else
6682
6734
  this._width = value;
6683
- }
6684
6735
  }
6685
6736
  setHeight(value) {
6686
6737
  if (value < 0) {
@@ -6688,9 +6739,8 @@ class UIData extends LeafData {
6688
6739
  this.__leaf.scaleY *= -1;
6689
6740
  debug$2.warn('height < 0, instead -scaleY', this);
6690
6741
  }
6691
- else {
6742
+ else
6692
6743
  this._height = value;
6693
- }
6694
6744
  }
6695
6745
  setFill(value) {
6696
6746
  if (this.__naturalWidth)
@@ -6731,9 +6781,10 @@ class UIData extends LeafData {
6731
6781
  }
6732
6782
  }
6733
6783
  setPath(value) {
6734
- if (typeof value === 'string') {
6784
+ const isString = typeof value === 'string';
6785
+ if (isString || (value && typeof value[0] === 'object')) {
6735
6786
  this.__setInput('path', value);
6736
- this._path = parse(value);
6787
+ this._path = isString ? parse(value) : objectToCanvasData(value);
6737
6788
  }
6738
6789
  else {
6739
6790
  if (this.__input)
@@ -6748,12 +6799,8 @@ class UIData extends LeafData {
6748
6799
  value = value.filter((item) => item.visible !== false);
6749
6800
  this._shadow = value.length ? value : null;
6750
6801
  }
6751
- else if (value) {
6752
- this._shadow = value.visible === false ? null : [value];
6753
- }
6754
- else {
6755
- this._shadow = null;
6756
- }
6802
+ else
6803
+ this._shadow = value && value.visible !== false ? [value] : null;
6757
6804
  }
6758
6805
  setInnerShadow(value) {
6759
6806
  this.__setInput('innerShadow', value);
@@ -6762,12 +6809,8 @@ class UIData extends LeafData {
6762
6809
  value = value.filter((item) => item.visible !== false);
6763
6810
  this._innerShadow = value.length ? value : null;
6764
6811
  }
6765
- else if (value) {
6766
- this._innerShadow = value.visible === false ? null : [value];
6767
- }
6768
- else {
6769
- this._innerShadow = null;
6770
- }
6812
+ else
6813
+ this._innerShadow = value && value.visible !== false ? [value] : null;
6771
6814
  }
6772
6815
  __computePaint() {
6773
6816
  const { fill, stroke } = this.__input;
@@ -6778,24 +6821,19 @@ class UIData extends LeafData {
6778
6821
  this.__needComputePaint = false;
6779
6822
  }
6780
6823
  }
6781
- const UnitConvert = {
6782
- number(value, percentRefer) {
6783
- if (typeof value === 'object')
6784
- return value.type === 'percent' ? value.value * percentRefer : value.value;
6785
- return value;
6786
- }
6787
- };
6788
6824
 
6789
6825
  class GroupData extends UIData {
6790
6826
  }
6791
6827
 
6792
6828
  class BoxData extends GroupData {
6793
6829
  get __boxStroke() { return !this.__pathInputed; }
6830
+ get __drawAfterFill() { return this.overflow === 'hide' && this.__clipAfterFill && this.__leaf.children.length; }
6831
+ get __clipAfterFill() { return this.__leaf.isOverflow || super.__clipAfterFill; }
6794
6832
  }
6795
6833
 
6796
6834
  class LeaferData extends GroupData {
6797
- __getInputData() {
6798
- const data = super.__getInputData();
6835
+ __getInputData(names, options) {
6836
+ const data = super.__getInputData(names, options);
6799
6837
  canvasSizeAttrs.forEach(key => delete data[key]);
6800
6838
  return data;
6801
6839
  }
@@ -6822,6 +6860,7 @@ class StarData extends UIData {
6822
6860
  }
6823
6861
 
6824
6862
  class PathData extends UIData {
6863
+ get __pathInputed() { return 2; }
6825
6864
  }
6826
6865
 
6827
6866
  class PenData extends GroupData {
@@ -6868,16 +6907,18 @@ class ImageData extends RectData {
6868
6907
  delete data.fill;
6869
6908
  return data;
6870
6909
  }
6871
- __getInputData() {
6872
- const data = super.__getInputData();
6910
+ __getInputData(names, options) {
6911
+ const data = super.__getInputData(names, options);
6873
6912
  delete data.fill;
6874
6913
  return data;
6875
6914
  }
6876
6915
  }
6877
6916
 
6878
6917
  class CanvasData extends RectData {
6879
- __getInputData() {
6880
- const data = super.__getInputData();
6918
+ get __isCanvas() { return true; }
6919
+ get __drawAfterFill() { return true; }
6920
+ __getInputData(names, options) {
6921
+ const data = super.__getInputData(names, options);
6881
6922
  data.url = this.__leaf.canvas.toDataURL('image/png');
6882
6923
  return data;
6883
6924
  }
@@ -6904,16 +6945,12 @@ const UIBounds = {
6904
6945
  let width = 0;
6905
6946
  const { shadow, innerShadow, blur, backgroundBlur } = this.__;
6906
6947
  if (shadow)
6907
- shadow.forEach(item => {
6908
- width = Math.max(width, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread > 0 ? item.spread : 0) + item.blur * 1.5);
6909
- });
6948
+ 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));
6910
6949
  if (blur)
6911
6950
  width = Math.max(width, blur);
6912
6951
  let shapeWidth = width = Math.ceil(width);
6913
6952
  if (innerShadow)
6914
- innerShadow.forEach(item => {
6915
- shapeWidth = Math.max(shapeWidth, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread < 0 ? -item.spread : 0) + item.blur * 1.5);
6916
- });
6953
+ 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));
6917
6954
  if (backgroundBlur)
6918
6955
  shapeWidth = Math.max(shapeWidth, backgroundBlur);
6919
6956
  this.__layout.renderShapeSpread = shapeWidth;
@@ -6995,6 +7032,16 @@ const UIRender = {
6995
7032
  if (stroke && !ignoreStroke)
6996
7033
  this.__.__pixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
6997
7034
  }
7035
+ },
7036
+ __drawAfterFill(canvas, options) {
7037
+ if (this.__.__clipAfterFill) {
7038
+ canvas.save();
7039
+ this.windingRule ? canvas.clip(this.windingRule) : canvas.clip();
7040
+ this.__drawContent(canvas, options);
7041
+ canvas.restore();
7042
+ }
7043
+ else
7044
+ this.__drawContent(canvas, options);
6998
7045
  }
6999
7046
  };
7000
7047
  function drawFast(ui, canvas, options) {
@@ -7061,8 +7108,8 @@ let UI = UI_1 = class UI extends Leaf {
7061
7108
  return pen;
7062
7109
  }
7063
7110
  get editConfig() { return undefined; }
7064
- get editOuter() { return this.__.__isLinePath ? 'LineEditTool' : 'EditTool'; }
7065
- get editInner() { return 'PathEditor'; }
7111
+ get editOuter() { return ''; }
7112
+ get editInner() { return ''; }
7066
7113
  constructor(data) {
7067
7114
  super(data);
7068
7115
  }
@@ -7073,9 +7120,8 @@ let UI = UI_1 = class UI extends Leaf {
7073
7120
  Object.assign(this, data);
7074
7121
  this.lockNormalStyle = false;
7075
7122
  }
7076
- else {
7123
+ else
7077
7124
  Object.assign(this, data);
7078
- }
7079
7125
  }
7080
7126
  get(name) {
7081
7127
  return typeof name === 'string' ? this.__.__getInput(name) : this.__.__getInputData(name);
@@ -7121,12 +7167,7 @@ let UI = UI_1 = class UI extends Leaf {
7121
7167
  this.__drawPathByData(canvas, this.__.path);
7122
7168
  }
7123
7169
  __drawPathByData(drawer, data) {
7124
- if (data) {
7125
- PathDrawer.drawPathByData(drawer, data);
7126
- }
7127
- else {
7128
- this.__drawPathByBox(drawer);
7129
- }
7170
+ data ? PathDrawer.drawPathByData(drawer, data) : this.__drawPathByBox(drawer);
7130
7171
  }
7131
7172
  __drawPathByBox(drawer) {
7132
7173
  const { x, y, width, height } = this.__layout.boxBounds;
@@ -7134,9 +7175,8 @@ let UI = UI_1 = class UI extends Leaf {
7134
7175
  const { cornerRadius } = this.__;
7135
7176
  drawer.roundRect(x, y, width, height, typeof cornerRadius === 'number' ? [cornerRadius] : cornerRadius);
7136
7177
  }
7137
- else {
7178
+ else
7138
7179
  drawer.rect(x, y, width, height);
7139
- }
7140
7180
  }
7141
7181
  animate(_keyframe, _options, _type, _isTemp) {
7142
7182
  return needPlugin('animate');
@@ -7383,23 +7423,13 @@ let Group = class Group extends UI {
7383
7423
  if (data.children) {
7384
7424
  const { children } = data;
7385
7425
  delete data.children;
7386
- if (!this.children) {
7387
- this.__setBranch();
7388
- }
7389
- else {
7390
- this.clear();
7391
- }
7426
+ this.children ? this.clear() : this.__setBranch();
7392
7427
  super.set(data, isTemp);
7393
- let child;
7394
- children.forEach(childData => {
7395
- child = childData.__ ? childData : UICreator.get(childData.tag, childData);
7396
- this.add(child);
7397
- });
7428
+ children.forEach(child => this.add(child));
7398
7429
  data.children = children;
7399
7430
  }
7400
- else {
7431
+ else
7401
7432
  super.set(data, isTemp);
7402
- }
7403
7433
  }
7404
7434
  toJSON(options) {
7405
7435
  const data = super.toJSON(options);
@@ -7819,10 +7849,9 @@ Rect = __decorate([
7819
7849
  registerUI()
7820
7850
  ], Rect);
7821
7851
 
7822
- const rect = Rect.prototype;
7823
- const group = Group.prototype;
7852
+ const { copy: copy$2, add, includes: includes$1 } = BoundsHelper;
7853
+ const rect = Rect.prototype, group = Group.prototype;
7824
7854
  const childrenRenderBounds = {};
7825
- const { copy: copy$2, add, includes: includes$1, copyAndSpread: copyAndSpread$1 } = BoundsHelper;
7826
7855
  let Box = class Box extends Group {
7827
7856
  get __tag() { return 'Box'; }
7828
7857
  get isBranchLeaf() { return true; }
@@ -7832,37 +7861,31 @@ let Box = class Box extends Group {
7832
7861
  }
7833
7862
  __updateStrokeSpread() { return 0; }
7834
7863
  __updateRectRenderSpread() { return 0; }
7835
- __updateRenderSpread() {
7836
- return this.__updateRectRenderSpread() || -1;
7837
- }
7864
+ __updateRenderSpread() { return this.__updateRectRenderSpread() || -1; }
7838
7865
  __updateRectBoxBounds() { }
7839
- __updateBoxBounds(secondLayout) {
7866
+ __updateBoxBounds(_secondLayout) {
7840
7867
  const data = this.__;
7841
7868
  if (this.children.length) {
7842
7869
  if (data.__autoSide) {
7843
- if (this.leafer && this.leafer.ready)
7844
- this.leafer.layouter.addExtra(this);
7845
7870
  super.__updateBoxBounds();
7846
7871
  const { boxBounds } = this.__layout;
7847
7872
  if (!data.__autoSize) {
7848
- if (data.__autoWidth)
7849
- boxBounds.width += boxBounds.x, boxBounds.height = data.height, boxBounds.y = boxBounds.x = 0;
7850
- else
7851
- boxBounds.height += boxBounds.y, boxBounds.width = data.width, boxBounds.x = boxBounds.y = 0;
7873
+ if (data.__autoWidth) {
7874
+ boxBounds.width += boxBounds.x, boxBounds.x = 0;
7875
+ boxBounds.height = data.height, boxBounds.y = 0;
7876
+ }
7877
+ else {
7878
+ boxBounds.height += boxBounds.y, boxBounds.y = 0;
7879
+ boxBounds.width = data.width, boxBounds.x = 0;
7880
+ }
7852
7881
  }
7853
- if (secondLayout && data.flow && data.padding)
7854
- copyAndSpread$1(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'));
7855
7882
  this.__updateNaturalSize();
7856
7883
  }
7857
- else {
7884
+ else
7858
7885
  this.__updateRectBoxBounds();
7859
- }
7860
- if (data.flow)
7861
- this.__updateContentBounds();
7862
7886
  }
7863
- else {
7887
+ else
7864
7888
  this.__updateRectBoxBounds();
7865
- }
7866
7889
  }
7867
7890
  __updateStrokeBounds() { }
7868
7891
  __updateRenderBounds() {
@@ -7872,14 +7895,13 @@ let Box = class Box extends Group {
7872
7895
  super.__updateRenderBounds();
7873
7896
  copy$2(childrenRenderBounds, renderBounds);
7874
7897
  this.__updateRectRenderBounds();
7875
- isOverflow = !includes$1(renderBounds, childrenRenderBounds) || !this.pathInputed || !this.__.cornerRadius;
7898
+ isOverflow = !includes$1(renderBounds, childrenRenderBounds);
7899
+ if (isOverflow && this.__.overflow !== 'hide')
7900
+ add(renderBounds, childrenRenderBounds);
7876
7901
  }
7877
- else {
7902
+ else
7878
7903
  this.__updateRectRenderBounds();
7879
- }
7880
- this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
7881
- if (!(this.__.__drawAfterFill = this.__.overflow === 'hide') && isOverflow)
7882
- add(renderBounds, childrenRenderBounds);
7904
+ !this.isOverflow !== !isOverflow && (this.isOverflow = isOverflow);
7883
7905
  }
7884
7906
  __updateRectRenderBounds() { }
7885
7907
  __updateRectChange() { }
@@ -7899,20 +7921,9 @@ let Box = class Box extends Group {
7899
7921
  this.__renderGroup(canvas, options);
7900
7922
  }
7901
7923
  }
7902
- __drawAfterFill(canvas, options) {
7903
- const { length } = this.children;
7904
- if (this.isOverflow) {
7905
- canvas.save();
7906
- canvas.clip();
7907
- if (length)
7908
- this.__renderGroup(canvas, options);
7909
- canvas.restore();
7910
- }
7911
- else {
7912
- if (length)
7913
- this.__renderGroup(canvas, options);
7914
- }
7915
- if (this.__.stroke && length) {
7924
+ __drawContent(canvas, options) {
7925
+ this.__renderGroup(canvas, options);
7926
+ if (this.__.__hasStroke) {
7916
7927
  canvas.setWorld(this.__nowWorld);
7917
7928
  this.__drawRenderPath(canvas);
7918
7929
  }
@@ -7924,6 +7935,9 @@ __decorate([
7924
7935
  __decorate([
7925
7936
  dataType(false)
7926
7937
  ], Box.prototype, "resizeChildren", void 0);
7938
+ __decorate([
7939
+ dataType(false)
7940
+ ], Box.prototype, "textBox", void 0);
7927
7941
  __decorate([
7928
7942
  affectRenderBoundsType('show')
7929
7943
  ], Box.prototype, "overflow", void 0);
@@ -8073,17 +8087,15 @@ let Line = class Line extends UI {
8073
8087
  if (data.__useArrow)
8074
8088
  PathArrow.addArrows(this, false);
8075
8089
  }
8076
- else {
8090
+ else
8077
8091
  super.__updateRenderPath();
8078
- }
8079
8092
  }
8080
8093
  __updateBoxBounds() {
8081
8094
  if (this.points) {
8082
8095
  toBounds$1(this.__.__pathForRender, this.__layout.boxBounds);
8083
8096
  }
8084
- else {
8097
+ else
8085
8098
  super.__updateBoxBounds();
8086
- }
8087
8099
  }
8088
8100
  };
8089
8101
  __decorate([
@@ -8221,7 +8233,6 @@ let Canvas = class Canvas extends Rect {
8221
8233
  super(data);
8222
8234
  this.canvas = Creator.canvas(this.__);
8223
8235
  this.context = this.canvas.context;
8224
- this.__.__isCanvas = this.__.__drawAfterFill = true;
8225
8236
  if (data && data.url)
8226
8237
  this.drawImage(data.url);
8227
8238
  }
@@ -8234,8 +8245,7 @@ let Canvas = class Canvas extends Rect {
8234
8245
  });
8235
8246
  }
8236
8247
  draw(ui, offset, scale, rotation) {
8237
- ui.__layout.update();
8238
- const matrix = new Matrix(ui.__world).invert();
8248
+ const matrix = new Matrix(ui.worldTransform).invert();
8239
8249
  const m = new Matrix();
8240
8250
  if (offset)
8241
8251
  m.translate(offset.x, offset.y);
@@ -8250,17 +8260,9 @@ let Canvas = class Canvas extends Rect {
8250
8260
  paint() {
8251
8261
  this.forceRender();
8252
8262
  }
8253
- __drawAfterFill(canvas, _options) {
8254
- const { width, height, cornerRadius } = this.__, { view } = this.canvas;
8255
- if (cornerRadius || this.pathInputed) {
8256
- canvas.save();
8257
- canvas.clip();
8258
- canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8259
- canvas.restore();
8260
- }
8261
- else {
8262
- canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8263
- }
8263
+ __drawContent(canvas, _options) {
8264
+ const { width, height } = this.__, { view } = this.canvas;
8265
+ canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8264
8266
  }
8265
8267
  __updateSize() {
8266
8268
  const { canvas } = this;
@@ -8304,7 +8306,6 @@ Canvas = __decorate([
8304
8306
  const { copyAndSpread, includes, isSame: isSame$1, spread, setList } = BoundsHelper;
8305
8307
  let Text = class Text extends UI {
8306
8308
  get __tag() { return 'Text'; }
8307
- get editInner() { return 'TextEditor'; }
8308
8309
  get textDrawData() {
8309
8310
  this.__layout.update();
8310
8311
  return this.__.__textDrawData;
@@ -8453,6 +8454,9 @@ __decorate([
8453
8454
  __decorate([
8454
8455
  boundsType('top')
8455
8456
  ], Text.prototype, "verticalAlign", void 0);
8457
+ __decorate([
8458
+ boundsType(true)
8459
+ ], Text.prototype, "autoSizeAlign", void 0);
8456
8460
  __decorate([
8457
8461
  boundsType('normal')
8458
8462
  ], Text.prototype, "textWrap", void 0);
@@ -8467,7 +8471,6 @@ let Path = class Path extends UI {
8467
8471
  get __tag() { return 'Path'; }
8468
8472
  constructor(data) {
8469
8473
  super(data);
8470
- this.__.__pathInputed = 2;
8471
8474
  }
8472
8475
  };
8473
8476
  __decorate([
@@ -8994,9 +8997,10 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
8994
8997
  onLoadError(ui, event, image.error);
8995
8998
  }
8996
8999
  else {
8997
- ignoreRender(ui, true);
8998
- if (firstUse)
9000
+ if (firstUse) {
9001
+ ignoreRender(ui, true);
8999
9002
  onLoad(ui, event);
9003
+ }
9000
9004
  leafPaint.loadId = image.load(() => {
9001
9005
  ignoreRender(ui, false);
9002
9006
  if (!ui.destroyed) {
@@ -9144,7 +9148,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
9144
9148
  }
9145
9149
  if (allowPaint) {
9146
9150
  canvas.save();
9147
- canvas.clip();
9151
+ ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
9148
9152
  if (paint.blendMode)
9149
9153
  canvas.blendMode = paint.blendMode;
9150
9154
  if (data.opacity)
@@ -9608,11 +9612,12 @@ const { trimRight } = TextRowHelper;
9608
9612
  const { Letter, Single, Before, After, Symbol, Break } = CharType;
9609
9613
  let word, row, wordWidth, rowWidth, realWidth;
9610
9614
  let char, charWidth, startCharSize, charSize, charType, lastCharType, langBreak, afterBreak, paraStart;
9611
- let textDrawData, rows = [], bounds;
9615
+ let textDrawData, rows = [], bounds, findMaxWidth;
9612
9616
  function createRows(drawData, content, style) {
9613
9617
  textDrawData = drawData;
9614
9618
  rows = drawData.rows;
9615
9619
  bounds = drawData.bounds;
9620
+ findMaxWidth = !bounds.width && !style.autoSizeAlign;
9616
9621
  const { __letterSpacing, paraIndent, textCase } = style;
9617
9622
  const { canvas } = Platform;
9618
9623
  const { width, height } = bounds;
@@ -9697,7 +9702,10 @@ function createRows(drawData, content, style) {
9697
9702
  else {
9698
9703
  content.split('\n').forEach(content => {
9699
9704
  textDrawData.paraNumber++;
9700
- rows.push({ x: paraIndent || 0, text: content, width: canvas.measureText(content).width, paraStart: true });
9705
+ rowWidth = canvas.measureText(content).width;
9706
+ rows.push({ x: paraIndent || 0, text: content, width: rowWidth, paraStart: true });
9707
+ if (findMaxWidth)
9708
+ setMaxWidth();
9701
9709
  });
9702
9710
  }
9703
9711
  }
@@ -9728,10 +9736,16 @@ function addRow() {
9728
9736
  row.width = rowWidth;
9729
9737
  if (bounds.width)
9730
9738
  trimRight(row);
9739
+ else if (findMaxWidth)
9740
+ setMaxWidth();
9731
9741
  rows.push(row);
9732
9742
  row = { words: [] };
9733
9743
  rowWidth = 0;
9734
9744
  }
9745
+ function setMaxWidth() {
9746
+ if (rowWidth > (textDrawData.maxWidth || 0))
9747
+ textDrawData.maxWidth = rowWidth;
9748
+ }
9735
9749
 
9736
9750
  const CharMode = 0;
9737
9751
  const WordMode = 1;
@@ -9803,34 +9817,32 @@ function toChar(data, charX, rowData, isOverflow) {
9803
9817
 
9804
9818
  function layoutText(drawData, style) {
9805
9819
  const { rows, bounds } = drawData;
9806
- const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing } = style;
9820
+ const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
9807
9821
  let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
9808
9822
  let starY = __baseLine;
9809
9823
  if (__clipText && realHeight > height) {
9810
9824
  realHeight = Math.max(height, __lineHeight);
9811
9825
  drawData.overflow = rows.length;
9812
9826
  }
9813
- else {
9827
+ else if (height || autoSizeAlign) {
9814
9828
  switch (verticalAlign) {
9815
9829
  case 'middle':
9816
9830
  y += (height - realHeight) / 2;
9817
9831
  break;
9818
- case 'bottom':
9819
- y += (height - realHeight);
9832
+ case 'bottom': y += (height - realHeight);
9820
9833
  }
9821
9834
  }
9822
9835
  starY += y;
9823
- let row, rowX, rowWidth;
9836
+ let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
9824
9837
  for (let i = 0, len = rows.length; i < len; i++) {
9825
9838
  row = rows[i];
9826
9839
  row.x = x;
9827
9840
  if (row.width < width || (row.width > width && !__clipText)) {
9828
9841
  switch (textAlign) {
9829
9842
  case 'center':
9830
- row.x += (width - row.width) / 2;
9843
+ row.x += (layoutWidth - row.width) / 2;
9831
9844
  break;
9832
- case 'right':
9833
- row.x += width - row.width;
9845
+ case 'right': row.x += layoutWidth - row.width;
9834
9846
  }
9835
9847
  }
9836
9848
  if (row.paraStart && paraSpacing && i > 0)
@@ -9935,14 +9947,14 @@ function getDrawData(content, style) {
9935
9947
  let height = style.__getInput('height') || 0;
9936
9948
  const { textDecoration, __font, __padding: padding } = style;
9937
9949
  if (padding) {
9938
- if (width) {
9950
+ if (width)
9951
+ x = padding[left], width -= (padding[right] + padding[left]);
9952
+ else if (!style.autoSizeAlign)
9939
9953
  x = padding[left];
9940
- width -= (padding[right] + padding[left]);
9941
- }
9942
- if (height) {
9954
+ if (height)
9955
+ y = padding[top], height -= (padding[top] + padding[bottom]);
9956
+ else if (!style.autoSizeAlign)
9943
9957
  y = padding[top];
9944
- height -= (padding[top] + padding[bottom]);
9945
- }
9946
9958
  }
9947
9959
  const drawData = {
9948
9960
  bounds: { x, y, width, height },
@@ -9962,22 +9974,20 @@ function getDrawData(content, style) {
9962
9974
  return drawData;
9963
9975
  }
9964
9976
  function padAutoText(padding, drawData, style, width, height) {
9965
- if (!width) {
9977
+ if (!width && style.autoSizeAlign) {
9966
9978
  switch (style.textAlign) {
9967
9979
  case 'left':
9968
9980
  offsetText(drawData, 'x', padding[left]);
9969
9981
  break;
9970
- case 'right':
9971
- offsetText(drawData, 'x', -padding[right]);
9982
+ case 'right': offsetText(drawData, 'x', -padding[right]);
9972
9983
  }
9973
9984
  }
9974
- if (!height) {
9985
+ if (!height && style.autoSizeAlign) {
9975
9986
  switch (style.verticalAlign) {
9976
9987
  case 'top':
9977
9988
  offsetText(drawData, 'y', padding[top]);
9978
9989
  break;
9979
- case 'bottom':
9980
- offsetText(drawData, 'y', -padding[bottom]);
9990
+ case 'bottom': offsetText(drawData, 'y', -padding[bottom]);
9981
9991
  }
9982
9992
  }
9983
9993
  }