@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.
package/dist/worker.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$5 = 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$5.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
  class LeaferCanvas extends LeaferCanvasBase {
5925
5968
  get allowBackgroundColor() { return true; }
@@ -6388,6 +6431,7 @@ var LeaferUI = (function (exports) {
6388
6431
  this.totalBounds = new Bounds();
6389
6432
  debug$3.log(target.innerName, '--->');
6390
6433
  try {
6434
+ target.app.emit(RenderEvent.CHILD_START, target);
6391
6435
  this.emitRender(RenderEvent.START);
6392
6436
  this.renderOnce(callback);
6393
6437
  this.emitRender(RenderEvent.END, this.totalBounds);
@@ -6627,6 +6671,13 @@ var LeaferUI = (function (exports) {
6627
6671
 
6628
6672
  const TextConvert = {};
6629
6673
  const ColorConvert = {};
6674
+ const UnitConvert = {
6675
+ number(value, percentRefer) {
6676
+ if (typeof value === 'object')
6677
+ return value.type === 'percent' ? value.value * percentRefer : value.value;
6678
+ return value;
6679
+ }
6680
+ };
6630
6681
  const PathArrow = {};
6631
6682
  const Paint = {};
6632
6683
  const PaintImage = {};
@@ -6647,7 +6698,7 @@ var LeaferUI = (function (exports) {
6647
6698
  }
6648
6699
  };
6649
6700
 
6650
- const { parse } = PathConvert;
6701
+ const { parse, objectToCanvasData } = PathConvert;
6651
6702
  const emptyPaint = {};
6652
6703
  const debug$2 = Debug.get('UIData');
6653
6704
  class UIData extends LeafData {
@@ -6661,10 +6712,11 @@ var LeaferUI = (function (exports) {
6661
6712
  scaleX = -scaleX;
6662
6713
  return scaleX > 1 ? strokeWidth / scaleX : strokeWidth;
6663
6714
  }
6664
- else {
6715
+ else
6665
6716
  return strokeWidth;
6666
- }
6667
6717
  }
6718
+ get __hasStroke() { return this.stroke && this.strokeWidth; }
6719
+ get __clipAfterFill() { return (this.cornerRadius || this.__pathInputed); }
6668
6720
  get __autoWidth() { return !this._width; }
6669
6721
  get __autoHeight() { return !this._height; }
6670
6722
  get __autoSide() { return !this._width || !this._height; }
@@ -6681,9 +6733,8 @@ var LeaferUI = (function (exports) {
6681
6733
  this.__leaf.scaleX *= -1;
6682
6734
  debug$2.warn('width < 0, instead -scaleX ', this);
6683
6735
  }
6684
- else {
6736
+ else
6685
6737
  this._width = value;
6686
- }
6687
6738
  }
6688
6739
  setHeight(value) {
6689
6740
  if (value < 0) {
@@ -6691,9 +6742,8 @@ var LeaferUI = (function (exports) {
6691
6742
  this.__leaf.scaleY *= -1;
6692
6743
  debug$2.warn('height < 0, instead -scaleY', this);
6693
6744
  }
6694
- else {
6745
+ else
6695
6746
  this._height = value;
6696
- }
6697
6747
  }
6698
6748
  setFill(value) {
6699
6749
  if (this.__naturalWidth)
@@ -6734,9 +6784,10 @@ var LeaferUI = (function (exports) {
6734
6784
  }
6735
6785
  }
6736
6786
  setPath(value) {
6737
- if (typeof value === 'string') {
6787
+ const isString = typeof value === 'string';
6788
+ if (isString || (value && typeof value[0] === 'object')) {
6738
6789
  this.__setInput('path', value);
6739
- this._path = parse(value);
6790
+ this._path = isString ? parse(value) : objectToCanvasData(value);
6740
6791
  }
6741
6792
  else {
6742
6793
  if (this.__input)
@@ -6751,12 +6802,8 @@ var LeaferUI = (function (exports) {
6751
6802
  value = value.filter((item) => item.visible !== false);
6752
6803
  this._shadow = value.length ? value : null;
6753
6804
  }
6754
- else if (value) {
6755
- this._shadow = value.visible === false ? null : [value];
6756
- }
6757
- else {
6758
- this._shadow = null;
6759
- }
6805
+ else
6806
+ this._shadow = value && value.visible !== false ? [value] : null;
6760
6807
  }
6761
6808
  setInnerShadow(value) {
6762
6809
  this.__setInput('innerShadow', value);
@@ -6765,12 +6812,8 @@ var LeaferUI = (function (exports) {
6765
6812
  value = value.filter((item) => item.visible !== false);
6766
6813
  this._innerShadow = value.length ? value : null;
6767
6814
  }
6768
- else if (value) {
6769
- this._innerShadow = value.visible === false ? null : [value];
6770
- }
6771
- else {
6772
- this._innerShadow = null;
6773
- }
6815
+ else
6816
+ this._innerShadow = value && value.visible !== false ? [value] : null;
6774
6817
  }
6775
6818
  __computePaint() {
6776
6819
  const { fill, stroke } = this.__input;
@@ -6781,24 +6824,19 @@ var LeaferUI = (function (exports) {
6781
6824
  this.__needComputePaint = false;
6782
6825
  }
6783
6826
  }
6784
- const UnitConvert = {
6785
- number(value, percentRefer) {
6786
- if (typeof value === 'object')
6787
- return value.type === 'percent' ? value.value * percentRefer : value.value;
6788
- return value;
6789
- }
6790
- };
6791
6827
 
6792
6828
  class GroupData extends UIData {
6793
6829
  }
6794
6830
 
6795
6831
  class BoxData extends GroupData {
6796
6832
  get __boxStroke() { return !this.__pathInputed; }
6833
+ get __drawAfterFill() { return this.overflow === 'hide' && this.__clipAfterFill && this.__leaf.children.length; }
6834
+ get __clipAfterFill() { return this.__leaf.isOverflow || super.__clipAfterFill; }
6797
6835
  }
6798
6836
 
6799
6837
  class LeaferData extends GroupData {
6800
- __getInputData() {
6801
- const data = super.__getInputData();
6838
+ __getInputData(names, options) {
6839
+ const data = super.__getInputData(names, options);
6802
6840
  canvasSizeAttrs.forEach(key => delete data[key]);
6803
6841
  return data;
6804
6842
  }
@@ -6825,6 +6863,7 @@ var LeaferUI = (function (exports) {
6825
6863
  }
6826
6864
 
6827
6865
  class PathData extends UIData {
6866
+ get __pathInputed() { return 2; }
6828
6867
  }
6829
6868
 
6830
6869
  class PenData extends GroupData {
@@ -6871,16 +6910,18 @@ var LeaferUI = (function (exports) {
6871
6910
  delete data.fill;
6872
6911
  return data;
6873
6912
  }
6874
- __getInputData() {
6875
- const data = super.__getInputData();
6913
+ __getInputData(names, options) {
6914
+ const data = super.__getInputData(names, options);
6876
6915
  delete data.fill;
6877
6916
  return data;
6878
6917
  }
6879
6918
  }
6880
6919
 
6881
6920
  class CanvasData extends RectData {
6882
- __getInputData() {
6883
- const data = super.__getInputData();
6921
+ get __isCanvas() { return true; }
6922
+ get __drawAfterFill() { return true; }
6923
+ __getInputData(names, options) {
6924
+ const data = super.__getInputData(names, options);
6884
6925
  data.url = this.__leaf.canvas.toDataURL('image/png');
6885
6926
  return data;
6886
6927
  }
@@ -6907,16 +6948,12 @@ var LeaferUI = (function (exports) {
6907
6948
  let width = 0;
6908
6949
  const { shadow, innerShadow, blur, backgroundBlur } = this.__;
6909
6950
  if (shadow)
6910
- shadow.forEach(item => {
6911
- width = Math.max(width, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread > 0 ? item.spread : 0) + item.blur * 1.5);
6912
- });
6951
+ 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));
6913
6952
  if (blur)
6914
6953
  width = Math.max(width, blur);
6915
6954
  let shapeWidth = width = Math.ceil(width);
6916
6955
  if (innerShadow)
6917
- innerShadow.forEach(item => {
6918
- shapeWidth = Math.max(shapeWidth, Math.max(Math.abs(item.y), Math.abs(item.x)) + (item.spread < 0 ? -item.spread : 0) + item.blur * 1.5);
6919
- });
6956
+ 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));
6920
6957
  if (backgroundBlur)
6921
6958
  shapeWidth = Math.max(shapeWidth, backgroundBlur);
6922
6959
  this.__layout.renderShapeSpread = shapeWidth;
@@ -6998,6 +7035,16 @@ var LeaferUI = (function (exports) {
6998
7035
  if (stroke && !ignoreStroke)
6999
7036
  this.__.__pixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke('#000000', this, canvas);
7000
7037
  }
7038
+ },
7039
+ __drawAfterFill(canvas, options) {
7040
+ if (this.__.__clipAfterFill) {
7041
+ canvas.save();
7042
+ this.windingRule ? canvas.clip(this.windingRule) : canvas.clip();
7043
+ this.__drawContent(canvas, options);
7044
+ canvas.restore();
7045
+ }
7046
+ else
7047
+ this.__drawContent(canvas, options);
7001
7048
  }
7002
7049
  };
7003
7050
  function drawFast(ui, canvas, options) {
@@ -7064,8 +7111,8 @@ var LeaferUI = (function (exports) {
7064
7111
  return pen;
7065
7112
  }
7066
7113
  get editConfig() { return undefined; }
7067
- get editOuter() { return this.__.__isLinePath ? 'LineEditTool' : 'EditTool'; }
7068
- get editInner() { return 'PathEditor'; }
7114
+ get editOuter() { return ''; }
7115
+ get editInner() { return ''; }
7069
7116
  constructor(data) {
7070
7117
  super(data);
7071
7118
  }
@@ -7076,9 +7123,8 @@ var LeaferUI = (function (exports) {
7076
7123
  Object.assign(this, data);
7077
7124
  this.lockNormalStyle = false;
7078
7125
  }
7079
- else {
7126
+ else
7080
7127
  Object.assign(this, data);
7081
- }
7082
7128
  }
7083
7129
  get(name) {
7084
7130
  return typeof name === 'string' ? this.__.__getInput(name) : this.__.__getInputData(name);
@@ -7124,12 +7170,7 @@ var LeaferUI = (function (exports) {
7124
7170
  this.__drawPathByData(canvas, this.__.path);
7125
7171
  }
7126
7172
  __drawPathByData(drawer, data) {
7127
- if (data) {
7128
- PathDrawer.drawPathByData(drawer, data);
7129
- }
7130
- else {
7131
- this.__drawPathByBox(drawer);
7132
- }
7173
+ data ? PathDrawer.drawPathByData(drawer, data) : this.__drawPathByBox(drawer);
7133
7174
  }
7134
7175
  __drawPathByBox(drawer) {
7135
7176
  const { x, y, width, height } = this.__layout.boxBounds;
@@ -7137,9 +7178,8 @@ var LeaferUI = (function (exports) {
7137
7178
  const { cornerRadius } = this.__;
7138
7179
  drawer.roundRect(x, y, width, height, typeof cornerRadius === 'number' ? [cornerRadius] : cornerRadius);
7139
7180
  }
7140
- else {
7181
+ else
7141
7182
  drawer.rect(x, y, width, height);
7142
- }
7143
7183
  }
7144
7184
  animate(_keyframe, _options, _type, _isTemp) {
7145
7185
  return needPlugin('animate');
@@ -7386,23 +7426,13 @@ var LeaferUI = (function (exports) {
7386
7426
  if (data.children) {
7387
7427
  const { children } = data;
7388
7428
  delete data.children;
7389
- if (!this.children) {
7390
- this.__setBranch();
7391
- }
7392
- else {
7393
- this.clear();
7394
- }
7429
+ this.children ? this.clear() : this.__setBranch();
7395
7430
  super.set(data, isTemp);
7396
- let child;
7397
- children.forEach(childData => {
7398
- child = childData.__ ? childData : UICreator.get(childData.tag, childData);
7399
- this.add(child);
7400
- });
7431
+ children.forEach(child => this.add(child));
7401
7432
  data.children = children;
7402
7433
  }
7403
- else {
7434
+ else
7404
7435
  super.set(data, isTemp);
7405
- }
7406
7436
  }
7407
7437
  toJSON(options) {
7408
7438
  const data = super.toJSON(options);
@@ -7822,10 +7852,9 @@ var LeaferUI = (function (exports) {
7822
7852
  registerUI()
7823
7853
  ], exports.Rect);
7824
7854
 
7825
- const rect = exports.Rect.prototype;
7826
- const group = exports.Group.prototype;
7855
+ const { copy: copy$2, add, includes: includes$1 } = BoundsHelper;
7856
+ const rect = exports.Rect.prototype, group = exports.Group.prototype;
7827
7857
  const childrenRenderBounds = {};
7828
- const { copy: copy$2, add, includes: includes$1, copyAndSpread: copyAndSpread$1 } = BoundsHelper;
7829
7858
  exports.Box = class Box extends exports.Group {
7830
7859
  get __tag() { return 'Box'; }
7831
7860
  get isBranchLeaf() { return true; }
@@ -7835,37 +7864,31 @@ var LeaferUI = (function (exports) {
7835
7864
  }
7836
7865
  __updateStrokeSpread() { return 0; }
7837
7866
  __updateRectRenderSpread() { return 0; }
7838
- __updateRenderSpread() {
7839
- return this.__updateRectRenderSpread() || -1;
7840
- }
7867
+ __updateRenderSpread() { return this.__updateRectRenderSpread() || -1; }
7841
7868
  __updateRectBoxBounds() { }
7842
- __updateBoxBounds(secondLayout) {
7869
+ __updateBoxBounds(_secondLayout) {
7843
7870
  const data = this.__;
7844
7871
  if (this.children.length) {
7845
7872
  if (data.__autoSide) {
7846
- if (this.leafer && this.leafer.ready)
7847
- this.leafer.layouter.addExtra(this);
7848
7873
  super.__updateBoxBounds();
7849
7874
  const { boxBounds } = this.__layout;
7850
7875
  if (!data.__autoSize) {
7851
- if (data.__autoWidth)
7852
- boxBounds.width += boxBounds.x, boxBounds.height = data.height, boxBounds.y = boxBounds.x = 0;
7853
- else
7854
- boxBounds.height += boxBounds.y, boxBounds.width = data.width, boxBounds.x = boxBounds.y = 0;
7876
+ if (data.__autoWidth) {
7877
+ boxBounds.width += boxBounds.x, boxBounds.x = 0;
7878
+ boxBounds.height = data.height, boxBounds.y = 0;
7879
+ }
7880
+ else {
7881
+ boxBounds.height += boxBounds.y, boxBounds.y = 0;
7882
+ boxBounds.width = data.width, boxBounds.x = 0;
7883
+ }
7855
7884
  }
7856
- if (secondLayout && data.flow && data.padding)
7857
- copyAndSpread$1(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'));
7858
7885
  this.__updateNaturalSize();
7859
7886
  }
7860
- else {
7887
+ else
7861
7888
  this.__updateRectBoxBounds();
7862
- }
7863
- if (data.flow)
7864
- this.__updateContentBounds();
7865
7889
  }
7866
- else {
7890
+ else
7867
7891
  this.__updateRectBoxBounds();
7868
- }
7869
7892
  }
7870
7893
  __updateStrokeBounds() { }
7871
7894
  __updateRenderBounds() {
@@ -7875,14 +7898,13 @@ var LeaferUI = (function (exports) {
7875
7898
  super.__updateRenderBounds();
7876
7899
  copy$2(childrenRenderBounds, renderBounds);
7877
7900
  this.__updateRectRenderBounds();
7878
- isOverflow = !includes$1(renderBounds, childrenRenderBounds) || !this.pathInputed || !this.__.cornerRadius;
7901
+ isOverflow = !includes$1(renderBounds, childrenRenderBounds);
7902
+ if (isOverflow && this.__.overflow !== 'hide')
7903
+ add(renderBounds, childrenRenderBounds);
7879
7904
  }
7880
- else {
7905
+ else
7881
7906
  this.__updateRectRenderBounds();
7882
- }
7883
- this.isOverflow !== isOverflow && (this.isOverflow = isOverflow);
7884
- if (!(this.__.__drawAfterFill = this.__.overflow === 'hide') && isOverflow)
7885
- add(renderBounds, childrenRenderBounds);
7907
+ !this.isOverflow !== !isOverflow && (this.isOverflow = isOverflow);
7886
7908
  }
7887
7909
  __updateRectRenderBounds() { }
7888
7910
  __updateRectChange() { }
@@ -7902,20 +7924,9 @@ var LeaferUI = (function (exports) {
7902
7924
  this.__renderGroup(canvas, options);
7903
7925
  }
7904
7926
  }
7905
- __drawAfterFill(canvas, options) {
7906
- const { length } = this.children;
7907
- if (this.isOverflow) {
7908
- canvas.save();
7909
- canvas.clip();
7910
- if (length)
7911
- this.__renderGroup(canvas, options);
7912
- canvas.restore();
7913
- }
7914
- else {
7915
- if (length)
7916
- this.__renderGroup(canvas, options);
7917
- }
7918
- if (this.__.stroke && length) {
7927
+ __drawContent(canvas, options) {
7928
+ this.__renderGroup(canvas, options);
7929
+ if (this.__.__hasStroke) {
7919
7930
  canvas.setWorld(this.__nowWorld);
7920
7931
  this.__drawRenderPath(canvas);
7921
7932
  }
@@ -7927,6 +7938,9 @@ var LeaferUI = (function (exports) {
7927
7938
  __decorate([
7928
7939
  dataType(false)
7929
7940
  ], exports.Box.prototype, "resizeChildren", void 0);
7941
+ __decorate([
7942
+ dataType(false)
7943
+ ], exports.Box.prototype, "textBox", void 0);
7930
7944
  __decorate([
7931
7945
  affectRenderBoundsType('show')
7932
7946
  ], exports.Box.prototype, "overflow", void 0);
@@ -8076,17 +8090,15 @@ var LeaferUI = (function (exports) {
8076
8090
  if (data.__useArrow)
8077
8091
  PathArrow.addArrows(this, false);
8078
8092
  }
8079
- else {
8093
+ else
8080
8094
  super.__updateRenderPath();
8081
- }
8082
8095
  }
8083
8096
  __updateBoxBounds() {
8084
8097
  if (this.points) {
8085
8098
  toBounds$1(this.__.__pathForRender, this.__layout.boxBounds);
8086
8099
  }
8087
- else {
8100
+ else
8088
8101
  super.__updateBoxBounds();
8089
- }
8090
8102
  }
8091
8103
  };
8092
8104
  __decorate([
@@ -8224,7 +8236,6 @@ var LeaferUI = (function (exports) {
8224
8236
  super(data);
8225
8237
  this.canvas = Creator.canvas(this.__);
8226
8238
  this.context = this.canvas.context;
8227
- this.__.__isCanvas = this.__.__drawAfterFill = true;
8228
8239
  if (data && data.url)
8229
8240
  this.drawImage(data.url);
8230
8241
  }
@@ -8237,8 +8248,7 @@ var LeaferUI = (function (exports) {
8237
8248
  });
8238
8249
  }
8239
8250
  draw(ui, offset, scale, rotation) {
8240
- ui.__layout.update();
8241
- const matrix = new Matrix(ui.__world).invert();
8251
+ const matrix = new Matrix(ui.worldTransform).invert();
8242
8252
  const m = new Matrix();
8243
8253
  if (offset)
8244
8254
  m.translate(offset.x, offset.y);
@@ -8253,17 +8263,9 @@ var LeaferUI = (function (exports) {
8253
8263
  paint() {
8254
8264
  this.forceRender();
8255
8265
  }
8256
- __drawAfterFill(canvas, _options) {
8257
- const { width, height, cornerRadius } = this.__, { view } = this.canvas;
8258
- if (cornerRadius || this.pathInputed) {
8259
- canvas.save();
8260
- canvas.clip();
8261
- canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8262
- canvas.restore();
8263
- }
8264
- else {
8265
- canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8266
- }
8266
+ __drawContent(canvas, _options) {
8267
+ const { width, height } = this.__, { view } = this.canvas;
8268
+ canvas.drawImage(view, 0, 0, view.width, view.height, 0, 0, width, height);
8267
8269
  }
8268
8270
  __updateSize() {
8269
8271
  const { canvas } = this;
@@ -8307,7 +8309,6 @@ var LeaferUI = (function (exports) {
8307
8309
  const { copyAndSpread, includes, isSame: isSame$1, spread, setList } = BoundsHelper;
8308
8310
  exports.Text = class Text extends exports.UI {
8309
8311
  get __tag() { return 'Text'; }
8310
- get editInner() { return 'TextEditor'; }
8311
8312
  get textDrawData() {
8312
8313
  this.__layout.update();
8313
8314
  return this.__.__textDrawData;
@@ -8456,6 +8457,9 @@ var LeaferUI = (function (exports) {
8456
8457
  __decorate([
8457
8458
  boundsType('top')
8458
8459
  ], exports.Text.prototype, "verticalAlign", void 0);
8460
+ __decorate([
8461
+ boundsType(true)
8462
+ ], exports.Text.prototype, "autoSizeAlign", void 0);
8459
8463
  __decorate([
8460
8464
  boundsType('normal')
8461
8465
  ], exports.Text.prototype, "textWrap", void 0);
@@ -8470,7 +8474,6 @@ var LeaferUI = (function (exports) {
8470
8474
  get __tag() { return 'Path'; }
8471
8475
  constructor(data) {
8472
8476
  super(data);
8473
- this.__.__pathInputed = 2;
8474
8477
  }
8475
8478
  };
8476
8479
  __decorate([
@@ -8997,9 +9000,10 @@ var LeaferUI = (function (exports) {
8997
9000
  onLoadError(ui, event, image.error);
8998
9001
  }
8999
9002
  else {
9000
- ignoreRender(ui, true);
9001
- if (firstUse)
9003
+ if (firstUse) {
9004
+ ignoreRender(ui, true);
9002
9005
  onLoad(ui, event);
9006
+ }
9003
9007
  leafPaint.loadId = image.load(() => {
9004
9008
  ignoreRender(ui, false);
9005
9009
  if (!ui.destroyed) {
@@ -9147,7 +9151,7 @@ var LeaferUI = (function (exports) {
9147
9151
  }
9148
9152
  if (allowPaint) {
9149
9153
  canvas.save();
9150
- canvas.clip();
9154
+ ui.windingRule ? canvas.clip(ui.windingRule) : canvas.clip();
9151
9155
  if (paint.blendMode)
9152
9156
  canvas.blendMode = paint.blendMode;
9153
9157
  if (data.opacity)
@@ -9611,11 +9615,12 @@ var LeaferUI = (function (exports) {
9611
9615
  const { Letter, Single, Before, After, Symbol, Break } = CharType;
9612
9616
  let word, row, wordWidth, rowWidth, realWidth;
9613
9617
  let char, charWidth, startCharSize, charSize, charType, lastCharType, langBreak, afterBreak, paraStart;
9614
- let textDrawData, rows = [], bounds;
9618
+ let textDrawData, rows = [], bounds, findMaxWidth;
9615
9619
  function createRows(drawData, content, style) {
9616
9620
  textDrawData = drawData;
9617
9621
  rows = drawData.rows;
9618
9622
  bounds = drawData.bounds;
9623
+ findMaxWidth = !bounds.width && !style.autoSizeAlign;
9619
9624
  const { __letterSpacing, paraIndent, textCase } = style;
9620
9625
  const { canvas } = Platform;
9621
9626
  const { width, height } = bounds;
@@ -9700,7 +9705,10 @@ var LeaferUI = (function (exports) {
9700
9705
  else {
9701
9706
  content.split('\n').forEach(content => {
9702
9707
  textDrawData.paraNumber++;
9703
- rows.push({ x: paraIndent || 0, text: content, width: canvas.measureText(content).width, paraStart: true });
9708
+ rowWidth = canvas.measureText(content).width;
9709
+ rows.push({ x: paraIndent || 0, text: content, width: rowWidth, paraStart: true });
9710
+ if (findMaxWidth)
9711
+ setMaxWidth();
9704
9712
  });
9705
9713
  }
9706
9714
  }
@@ -9731,10 +9739,16 @@ var LeaferUI = (function (exports) {
9731
9739
  row.width = rowWidth;
9732
9740
  if (bounds.width)
9733
9741
  trimRight(row);
9742
+ else if (findMaxWidth)
9743
+ setMaxWidth();
9734
9744
  rows.push(row);
9735
9745
  row = { words: [] };
9736
9746
  rowWidth = 0;
9737
9747
  }
9748
+ function setMaxWidth() {
9749
+ if (rowWidth > (textDrawData.maxWidth || 0))
9750
+ textDrawData.maxWidth = rowWidth;
9751
+ }
9738
9752
 
9739
9753
  const CharMode = 0;
9740
9754
  const WordMode = 1;
@@ -9806,34 +9820,32 @@ var LeaferUI = (function (exports) {
9806
9820
 
9807
9821
  function layoutText(drawData, style) {
9808
9822
  const { rows, bounds } = drawData;
9809
- const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing } = style;
9823
+ const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
9810
9824
  let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
9811
9825
  let starY = __baseLine;
9812
9826
  if (__clipText && realHeight > height) {
9813
9827
  realHeight = Math.max(height, __lineHeight);
9814
9828
  drawData.overflow = rows.length;
9815
9829
  }
9816
- else {
9830
+ else if (height || autoSizeAlign) {
9817
9831
  switch (verticalAlign) {
9818
9832
  case 'middle':
9819
9833
  y += (height - realHeight) / 2;
9820
9834
  break;
9821
- case 'bottom':
9822
- y += (height - realHeight);
9835
+ case 'bottom': y += (height - realHeight);
9823
9836
  }
9824
9837
  }
9825
9838
  starY += y;
9826
- let row, rowX, rowWidth;
9839
+ let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
9827
9840
  for (let i = 0, len = rows.length; i < len; i++) {
9828
9841
  row = rows[i];
9829
9842
  row.x = x;
9830
9843
  if (row.width < width || (row.width > width && !__clipText)) {
9831
9844
  switch (textAlign) {
9832
9845
  case 'center':
9833
- row.x += (width - row.width) / 2;
9846
+ row.x += (layoutWidth - row.width) / 2;
9834
9847
  break;
9835
- case 'right':
9836
- row.x += width - row.width;
9848
+ case 'right': row.x += layoutWidth - row.width;
9837
9849
  }
9838
9850
  }
9839
9851
  if (row.paraStart && paraSpacing && i > 0)
@@ -9938,14 +9950,14 @@ var LeaferUI = (function (exports) {
9938
9950
  let height = style.__getInput('height') || 0;
9939
9951
  const { textDecoration, __font, __padding: padding } = style;
9940
9952
  if (padding) {
9941
- if (width) {
9953
+ if (width)
9954
+ x = padding[left], width -= (padding[right] + padding[left]);
9955
+ else if (!style.autoSizeAlign)
9942
9956
  x = padding[left];
9943
- width -= (padding[right] + padding[left]);
9944
- }
9945
- if (height) {
9957
+ if (height)
9958
+ y = padding[top], height -= (padding[top] + padding[bottom]);
9959
+ else if (!style.autoSizeAlign)
9946
9960
  y = padding[top];
9947
- height -= (padding[top] + padding[bottom]);
9948
- }
9949
9961
  }
9950
9962
  const drawData = {
9951
9963
  bounds: { x, y, width, height },
@@ -9965,22 +9977,20 @@ var LeaferUI = (function (exports) {
9965
9977
  return drawData;
9966
9978
  }
9967
9979
  function padAutoText(padding, drawData, style, width, height) {
9968
- if (!width) {
9980
+ if (!width && style.autoSizeAlign) {
9969
9981
  switch (style.textAlign) {
9970
9982
  case 'left':
9971
9983
  offsetText(drawData, 'x', padding[left]);
9972
9984
  break;
9973
- case 'right':
9974
- offsetText(drawData, 'x', -padding[right]);
9985
+ case 'right': offsetText(drawData, 'x', -padding[right]);
9975
9986
  }
9976
9987
  }
9977
- if (!height) {
9988
+ if (!height && style.autoSizeAlign) {
9978
9989
  switch (style.verticalAlign) {
9979
9990
  case 'top':
9980
9991
  offsetText(drawData, 'y', padding[top]);
9981
9992
  break;
9982
- case 'bottom':
9983
- offsetText(drawData, 'y', -padding[bottom]);
9993
+ case 'bottom': offsetText(drawData, 'y', -padding[bottom]);
9984
9994
  }
9985
9995
  }
9986
9996
  }