@leafer-ui/worker 1.0.3 → 1.0.5

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.
@@ -4483,15 +4483,16 @@ class LeafLayout {
4483
4483
  }
4484
4484
  getLayoutBounds(type, relative = 'world', unscale) {
4485
4485
  const { leaf } = this;
4486
- let point, matrix, bounds = this.getInnerBounds(type);
4486
+ let point, matrix, layoutBounds, bounds = this.getInnerBounds(type);
4487
4487
  switch (relative) {
4488
4488
  case 'world':
4489
4489
  point = leaf.getWorldPoint(bounds);
4490
4490
  matrix = leaf.__world;
4491
4491
  break;
4492
4492
  case 'local':
4493
+ const { scaleX, scaleY, rotation, skewX, skewY } = leaf.__;
4494
+ layoutBounds = { scaleX, scaleY, rotation, skewX, skewY };
4493
4495
  point = leaf.getLocalPointByInner(bounds);
4494
- matrix = leaf.__localMatrix;
4495
4496
  break;
4496
4497
  case 'inner':
4497
4498
  point = bounds;
@@ -4503,7 +4504,8 @@ class LeafLayout {
4503
4504
  point = leaf.getWorldPoint(bounds, relative);
4504
4505
  matrix = getRelativeWorld$1(leaf, relative, true);
4505
4506
  }
4506
- const layoutBounds = MatrixHelper.getLayout(matrix);
4507
+ if (!layoutBounds)
4508
+ layoutBounds = MatrixHelper.getLayout(matrix);
4507
4509
  copy$6(layoutBounds, bounds);
4508
4510
  PointHelper.copy(layoutBounds, point);
4509
4511
  if (unscale) {
@@ -4753,6 +4755,7 @@ class RenderEvent extends Event {
4753
4755
  }
4754
4756
  }
4755
4757
  RenderEvent.REQUEST = 'render.request';
4758
+ RenderEvent.CHILD_START = 'render.child_start';
4756
4759
  RenderEvent.START = 'render.start';
4757
4760
  RenderEvent.BEFORE = 'render.before';
4758
4761
  RenderEvent.RENDER = 'render';
@@ -4928,7 +4931,7 @@ const { isFinite } = Number;
4928
4931
  const debug$7 = Debug.get('setAttr');
4929
4932
  const LeafDataProxy = {
4930
4933
  __setAttr(name, newValue, checkFiniteNumber) {
4931
- if (this.leafer && this.leafer.created) {
4934
+ if (this.leaferIsCreated) {
4932
4935
  const oldValue = this.__.__getInput(name);
4933
4936
  if (checkFiniteNumber && !isFinite(newValue) && newValue !== undefined) {
4934
4937
  debug$7.warn(this.innerName, name, newValue);
@@ -5000,7 +5003,7 @@ const LeafMatrix = {
5000
5003
 
5001
5004
  const { updateMatrix: updateMatrix$1, updateAllMatrix: updateAllMatrix$2 } = LeafHelper;
5002
5005
  const { updateBounds: updateBounds$1 } = BranchHelper;
5003
- const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$2, copy: copy$5 } = BoundsHelper;
5006
+ const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$1, copy: copy$5 } = BoundsHelper;
5004
5007
  const { toBounds: toBounds$2 } = PathBounds;
5005
5008
  const LeafBounds = {
5006
5009
  __updateWorldBounds() {
@@ -5083,7 +5086,7 @@ const LeafBounds = {
5083
5086
  const b = this.__layout.boxBounds;
5084
5087
  const data = this.__;
5085
5088
  if (data.__pathInputed) {
5086
- toBounds$2(data.__pathForRender, b);
5089
+ toBounds$2(data.path, b);
5087
5090
  }
5088
5091
  else {
5089
5092
  b.x = 0;
@@ -5095,7 +5098,7 @@ const LeafBounds = {
5095
5098
  __updateAutoLayout() {
5096
5099
  this.__layout.matrixChanged = true;
5097
5100
  if (this.isBranch) {
5098
- if (this.leafer && this.leafer.ready)
5101
+ if (this.leaferIsReady)
5099
5102
  this.leafer.layouter.addExtra(this);
5100
5103
  if (this.__.flow) {
5101
5104
  if (this.__layout.boxChanged)
@@ -5121,11 +5124,11 @@ const LeafBounds = {
5121
5124
  },
5122
5125
  __updateStrokeBounds() {
5123
5126
  const layout = this.__layout;
5124
- copyAndSpread$2(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
5127
+ copyAndSpread$1(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
5125
5128
  },
5126
5129
  __updateRenderBounds() {
5127
5130
  const layout = this.__layout;
5128
- layout.renderSpread > 0 ? copyAndSpread$2(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$5(layout.renderBounds, layout.strokeBounds);
5131
+ layout.renderSpread > 0 ? copyAndSpread$1(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$5(layout.renderBounds, layout.strokeBounds);
5129
5132
  }
5130
5133
  };
5131
5134
 
@@ -5230,6 +5233,8 @@ let Leaf = class Leaf {
5230
5233
  get innerName() { return this.__.name || this.tag + this.innerId; }
5231
5234
  get __DataProcessor() { return LeafData; }
5232
5235
  get __LayoutProcessor() { return LeafLayout; }
5236
+ get leaferIsCreated() { return this.leafer && this.leafer.created; }
5237
+ get leaferIsReady() { return this.leafer && this.leafer.ready; }
5233
5238
  get isLeafer() { return false; }
5234
5239
  get isBranch() { return false; }
5235
5240
  get isBranchLeaf() { return false; }
@@ -5671,6 +5676,7 @@ let Branch = class Branch extends Leaf {
5671
5676
  add(child, index) {
5672
5677
  if (child === this)
5673
5678
  return;
5679
+ child.__ || (child = UICreator.get(child.tag, child));
5674
5680
  if (child.parent)
5675
5681
  child.parent.remove(child);
5676
5682
  child.parent = this;
@@ -5693,10 +5699,14 @@ let Branch = class Branch extends Leaf {
5693
5699
  }
5694
5700
  remove(child, destroy) {
5695
5701
  if (child) {
5696
- if (child.animationOut)
5697
- child.__runAnimation('out', () => this.__remove(child, destroy));
5702
+ if (child.__) {
5703
+ if (child.animationOut)
5704
+ child.__runAnimation('out', () => this.__remove(child, destroy));
5705
+ else
5706
+ this.__remove(child, destroy);
5707
+ }
5698
5708
  else
5699
- this.__remove(child, destroy);
5709
+ this.find(child).forEach(item => this.remove(item, destroy));
5700
5710
  }
5701
5711
  else if (child === undefined) {
5702
5712
  super.remove(null, destroy);
@@ -5914,7 +5924,7 @@ class LeafLevelList {
5914
5924
  }
5915
5925
  }
5916
5926
 
5917
- const version = "1.0.3";
5927
+ const version = "1.0.5";
5918
5928
 
5919
5929
  class LeaferCanvas extends LeaferCanvasBase {
5920
5930
  get allowBackgroundColor() { return true; }
@@ -6383,6 +6393,7 @@ class Renderer {
6383
6393
  this.totalBounds = new Bounds();
6384
6394
  debug$5.log(target.innerName, '--->');
6385
6395
  try {
6396
+ target.app.emit(RenderEvent.CHILD_START, target);
6386
6397
  this.emitRender(RenderEvent.START);
6387
6398
  this.renderOnce(callback);
6388
6399
  this.emitRender(RenderEvent.END, this.totalBounds);
@@ -6680,7 +6691,7 @@ class Picker {
6680
6691
  if (child.isBranch) {
6681
6692
  if (hit || child.__ignoreHitWorld) {
6682
6693
  this.eachFind(child.children, child.__onlyHitMask);
6683
- if (child.isBranchLeaf && !this.findList.length)
6694
+ if (child.isBranchLeaf)
6684
6695
  this.hitChild(child, point);
6685
6696
  }
6686
6697
  }
@@ -7390,12 +7401,7 @@ let UI = UI_1 = class UI extends Leaf {
7390
7401
  this.__drawPathByData(canvas, this.__.path);
7391
7402
  }
7392
7403
  __drawPathByData(drawer, data) {
7393
- if (data) {
7394
- PathDrawer.drawPathByData(drawer, data);
7395
- }
7396
- else {
7397
- this.__drawPathByBox(drawer);
7398
- }
7404
+ data ? PathDrawer.drawPathByData(drawer, data) : this.__drawPathByBox(drawer);
7399
7405
  }
7400
7406
  __drawPathByBox(drawer) {
7401
7407
  const { x, y, width, height } = this.__layout.boxBounds;
@@ -7403,9 +7409,8 @@ let UI = UI_1 = class UI extends Leaf {
7403
7409
  const { cornerRadius } = this.__;
7404
7410
  drawer.roundRect(x, y, width, height, typeof cornerRadius === 'number' ? [cornerRadius] : cornerRadius);
7405
7411
  }
7406
- else {
7412
+ else
7407
7413
  drawer.rect(x, y, width, height);
7408
- }
7409
7414
  }
7410
7415
  animate(_keyframe, _options, _type, _isTemp) {
7411
7416
  return needPlugin('animate');
@@ -7414,10 +7419,10 @@ let UI = UI_1 = class UI extends Leaf {
7414
7419
  export(filename, options) {
7415
7420
  return Export.export(this, filename, options);
7416
7421
  }
7417
- clone(newData) {
7422
+ clone(data) {
7418
7423
  const json = this.toJSON();
7419
- if (newData)
7420
- Object.assign(json, newData);
7424
+ if (data)
7425
+ Object.assign(json, data);
7421
7426
  return UI_1.one(json);
7422
7427
  }
7423
7428
  static one(data, x, y, width, height) {
@@ -8088,10 +8093,9 @@ Rect = __decorate([
8088
8093
  registerUI()
8089
8094
  ], Rect);
8090
8095
 
8091
- const rect$1 = Rect.prototype;
8092
- const group$1 = Group.prototype;
8096
+ const { copy: copy$3, add, includes: includes$1 } = BoundsHelper;
8097
+ const rect$1 = Rect.prototype, group$1 = Group.prototype;
8093
8098
  const childrenRenderBounds = {};
8094
- const { copy: copy$3, add, includes: includes$1, copyAndSpread: copyAndSpread$1 } = BoundsHelper;
8095
8099
  let Box = class Box extends Group {
8096
8100
  get __tag() { return 'Box'; }
8097
8101
  get isBranchLeaf() { return true; }
@@ -8105,29 +8109,27 @@ let Box = class Box extends Group {
8105
8109
  return this.__updateRectRenderSpread() || -1;
8106
8110
  }
8107
8111
  __updateRectBoxBounds() { }
8108
- __updateBoxBounds(secondLayout) {
8112
+ __updateBoxBounds(_secondLayout) {
8109
8113
  const data = this.__;
8110
8114
  if (this.children.length) {
8111
8115
  if (data.__autoSide) {
8112
- if (this.leafer && this.leafer.ready)
8113
- this.leafer.layouter.addExtra(this);
8114
8116
  super.__updateBoxBounds();
8115
8117
  const { boxBounds } = this.__layout;
8116
8118
  if (!data.__autoSize) {
8117
- if (data.__autoWidth)
8118
- boxBounds.width += boxBounds.x, boxBounds.height = data.height, boxBounds.y = boxBounds.x = 0;
8119
- else
8120
- boxBounds.height += boxBounds.y, boxBounds.width = data.width, boxBounds.x = boxBounds.y = 0;
8119
+ if (data.__autoWidth) {
8120
+ boxBounds.width += boxBounds.x, boxBounds.x = 0;
8121
+ boxBounds.height = data.height, boxBounds.y = 0;
8122
+ }
8123
+ else {
8124
+ boxBounds.height += boxBounds.y, boxBounds.y = 0;
8125
+ boxBounds.width = data.width, boxBounds.x = 0;
8126
+ }
8121
8127
  }
8122
- if (secondLayout && data.flow && data.padding)
8123
- copyAndSpread$1(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'));
8124
8128
  this.__updateNaturalSize();
8125
8129
  }
8126
8130
  else {
8127
8131
  this.__updateRectBoxBounds();
8128
8132
  }
8129
- if (data.flow)
8130
- this.__updateContentBounds();
8131
8133
  }
8132
8134
  else {
8133
8135
  this.__updateRectBoxBounds();
@@ -8193,6 +8195,9 @@ __decorate([
8193
8195
  __decorate([
8194
8196
  dataType(false)
8195
8197
  ], Box.prototype, "resizeChildren", void 0);
8198
+ __decorate([
8199
+ dataType(false)
8200
+ ], Box.prototype, "textBox", void 0);
8196
8201
  __decorate([
8197
8202
  affectRenderBoundsType('show')
8198
8203
  ], Box.prototype, "overflow", void 0);
@@ -8722,6 +8727,9 @@ __decorate([
8722
8727
  __decorate([
8723
8728
  boundsType('top')
8724
8729
  ], Text.prototype, "verticalAlign", void 0);
8730
+ __decorate([
8731
+ boundsType(true)
8732
+ ], Text.prototype, "autoSizeAlign", void 0);
8725
8733
  __decorate([
8726
8734
  boundsType('normal')
8727
8735
  ], Text.prototype, "textWrap", void 0);
@@ -9442,9 +9450,10 @@ class Dragger {
9442
9450
  this.dragData = getDragEventData(data, data, data);
9443
9451
  this.canAnimate = this.canDragOut = true;
9444
9452
  }
9445
- getList() {
9453
+ getList(realDraggable, hover) {
9446
9454
  const { proxy } = this.interaction.selector;
9447
- return this.dragging && (!proxy || !proxy.list.length) ? (DragEvent.list || this.dragableList || emptyList) : emptyList;
9455
+ const hasProxyList = proxy && proxy.list.length, dragList = DragEvent.list || this.draggableList || emptyList;
9456
+ return this.dragging && (hasProxyList ? (realDraggable ? emptyList : new LeafList(hover ? [...proxy.list, ...proxy.dragHoverExclude] : proxy.list)) : dragList);
9448
9457
  }
9449
9458
  checkDrag(data, canDrag) {
9450
9459
  const { interaction } = this;
@@ -9469,8 +9478,8 @@ class Dragger {
9469
9478
  this.dragging = canDrag && PointerButton.left(data);
9470
9479
  if (this.dragging) {
9471
9480
  this.interaction.emit(DragEvent.START, this.dragData);
9472
- this.getDragableList(this.dragData.path);
9473
- this.setDragStartPoints(this.realDragableList = this.getList());
9481
+ this.getDraggableList(this.dragData.path);
9482
+ this.setDragStartPoints(this.realDraggableList = this.getList(true));
9474
9483
  }
9475
9484
  }
9476
9485
  }
@@ -9478,12 +9487,12 @@ class Dragger {
9478
9487
  this.dragStartPoints = {};
9479
9488
  list.forEach(leaf => this.dragStartPoints[leaf.innerId] = { x: leaf.x, y: leaf.y });
9480
9489
  }
9481
- getDragableList(path) {
9490
+ getDraggableList(path) {
9482
9491
  let leaf;
9483
9492
  for (let i = 0, len = path.length; i < len; i++) {
9484
9493
  leaf = path.list[i];
9485
- if ((leaf.__.draggable || leaf.__.editable) && leaf.__.hitSelf && !leaf.__.locked) {
9486
- this.dragableList = new LeafList(leaf);
9494
+ if ((leaf.draggable || leaf.editable) && leaf.hitSelf && !leaf.locked) {
9495
+ this.draggableList = new LeafList(leaf);
9487
9496
  break;
9488
9497
  }
9489
9498
  }
@@ -9508,7 +9517,7 @@ class Dragger {
9508
9517
  }
9509
9518
  dragReal() {
9510
9519
  const { running } = this.interaction;
9511
- const list = this.realDragableList;
9520
+ const list = this.realDraggableList;
9512
9521
  if (list.length && running) {
9513
9522
  const { totalX, totalY } = this.dragData;
9514
9523
  list.forEach(leaf => leaf.draggable && leaf.move(DragEvent.getValidMove(leaf, this.dragStartPoints[leaf.innerId], { x: totalX, y: totalY })));
@@ -9597,7 +9606,7 @@ class Dragger {
9597
9606
  this.interaction.emit(DragEvent.LEAVE, data, dragEnterPath);
9598
9607
  }
9599
9608
  dragReset() {
9600
- DragEvent.list = DragEvent.data = this.dragableList = this.dragData = this.downData = this.dragOverPath = this.dragEnterPath = null;
9609
+ DragEvent.list = DragEvent.data = this.draggableList = this.dragData = this.downData = this.dragOverPath = this.dragEnterPath = null;
9601
9610
  }
9602
9611
  checkDragOut(data) {
9603
9612
  const { interaction } = this;
@@ -9738,6 +9747,7 @@ const config = {
9738
9747
  touch: {
9739
9748
  preventDefault: true
9740
9749
  },
9750
+ multiTouch: {},
9741
9751
  cursor: true,
9742
9752
  keyEvent: true
9743
9753
  };
@@ -9864,6 +9874,8 @@ class InteractionBase {
9864
9874
  this.pointerUp(data);
9865
9875
  }
9866
9876
  multiTouch(data, list) {
9877
+ if (this.config.multiTouch.disabled)
9878
+ return;
9867
9879
  const { move, angle, scale, center } = MultiTouchHelper.getData(list);
9868
9880
  this.rotate(getRotateEventData(center, angle, data));
9869
9881
  this.zoom(getZoomEventData(center, scale, data));
@@ -10053,7 +10065,7 @@ class InteractionBase {
10053
10065
  data = this.hoverData;
10054
10066
  if (!data)
10055
10067
  return;
10056
- this.findPath(data, { exclude: this.dragger.getList(), name: PointerEvent.MOVE });
10068
+ this.findPath(data, { exclude: this.dragger.getList(false, true), name: PointerEvent.MOVE });
10057
10069
  this.hoverData = data;
10058
10070
  }
10059
10071
  updateCursor(data) {
@@ -10075,7 +10087,7 @@ class InteractionBase {
10075
10087
  const { path } = data;
10076
10088
  for (let i = 0, len = path.length; i < len; i++) {
10077
10089
  leaf = path.list[i];
10078
- cursor = leaf.syncEventer ? leaf.syncEventer.cursor : leaf.cursor;
10090
+ cursor = (leaf.syncEventer && leaf.syncEventer.cursor) || leaf.cursor;
10079
10091
  if (cursor)
10080
10092
  break;
10081
10093
  }
@@ -10257,7 +10269,7 @@ ui$2.__updateHitCanvas = function () {
10257
10269
  if (isHitPixel) {
10258
10270
  const { renderBounds } = this.__layout;
10259
10271
  const size = Platform.image.hitCanvasSize;
10260
- const scale = h.hitScale = tempBounds$1.set(0, 0, size, size).getFitMatrix(renderBounds, 0.5).a;
10272
+ const scale = h.hitScale = tempBounds$1.set(0, 0, size, size).getFitMatrix(renderBounds).a;
10261
10273
  const { x, y, width, height } = tempBounds$1.set(renderBounds).scale(scale);
10262
10274
  h.resize({ width, height, pixelRatio: 1 });
10263
10275
  h.clear();
@@ -10313,15 +10325,14 @@ ui$2.__hit = function (inner) {
10313
10325
  return hitWidth ? this.__hitStroke(inner, hitWidth) : false;
10314
10326
  };
10315
10327
 
10316
- const ui$1 = new UI();
10317
- const rect = Rect.prototype;
10318
- rect.__updateHitCanvas = function () {
10328
+ const ui$1 = UI.prototype, rect = Rect.prototype, box$1 = Box.prototype;
10329
+ rect.__updateHitCanvas = box$1.__updateHitCanvas = function () {
10319
10330
  if (this.stroke || this.cornerRadius || ((this.fill || this.__.__isCanvas) && this.hitFill === 'pixel') || this.hitStroke === 'all')
10320
10331
  ui$1.__updateHitCanvas.call(this);
10321
10332
  else if (this.__hitCanvas)
10322
10333
  this.__hitCanvas = null;
10323
10334
  };
10324
- rect.__hitFill = function (inner) {
10335
+ rect.__hitFill = box$1.__hitFill = function (inner) {
10325
10336
  return this.__hitCanvas ? ui$1.__hitFill.call(this, inner) : BoundsHelper.hitRadiusPoint(this.__layout.boxBounds, inner);
10326
10337
  };
10327
10338
 
@@ -10820,9 +10831,10 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
10820
10831
  onLoadError(ui, event, image.error);
10821
10832
  }
10822
10833
  else {
10823
- ignoreRender(ui, true);
10824
- if (firstUse)
10834
+ if (firstUse) {
10835
+ ignoreRender(ui, true);
10825
10836
  onLoad(ui, event);
10837
+ }
10826
10838
  leafPaint.loadId = image.load(() => {
10827
10839
  ignoreRender(ui, false);
10828
10840
  if (!ui.destroyed) {
@@ -11434,11 +11446,12 @@ const { trimRight } = TextRowHelper;
11434
11446
  const { Letter, Single, Before, After, Symbol, Break } = CharType;
11435
11447
  let word, row, wordWidth, rowWidth, realWidth;
11436
11448
  let char, charWidth, startCharSize, charSize, charType, lastCharType, langBreak, afterBreak, paraStart;
11437
- let textDrawData, rows = [], bounds;
11449
+ let textDrawData, rows = [], bounds, findMaxWidth;
11438
11450
  function createRows(drawData, content, style) {
11439
11451
  textDrawData = drawData;
11440
11452
  rows = drawData.rows;
11441
11453
  bounds = drawData.bounds;
11454
+ findMaxWidth = !bounds.width && !style.autoSizeAlign;
11442
11455
  const { __letterSpacing, paraIndent, textCase } = style;
11443
11456
  const { canvas } = Platform;
11444
11457
  const { width, height } = bounds;
@@ -11523,7 +11536,10 @@ function createRows(drawData, content, style) {
11523
11536
  else {
11524
11537
  content.split('\n').forEach(content => {
11525
11538
  textDrawData.paraNumber++;
11526
- rows.push({ x: paraIndent || 0, text: content, width: canvas.measureText(content).width, paraStart: true });
11539
+ rowWidth = canvas.measureText(content).width;
11540
+ rows.push({ x: paraIndent || 0, text: content, width: rowWidth, paraStart: true });
11541
+ if (findMaxWidth)
11542
+ setMaxWidth();
11527
11543
  });
11528
11544
  }
11529
11545
  }
@@ -11554,10 +11570,16 @@ function addRow() {
11554
11570
  row.width = rowWidth;
11555
11571
  if (bounds.width)
11556
11572
  trimRight(row);
11573
+ else if (findMaxWidth)
11574
+ setMaxWidth();
11557
11575
  rows.push(row);
11558
11576
  row = { words: [] };
11559
11577
  rowWidth = 0;
11560
11578
  }
11579
+ function setMaxWidth() {
11580
+ if (rowWidth > (textDrawData.maxWidth || 0))
11581
+ textDrawData.maxWidth = rowWidth;
11582
+ }
11561
11583
 
11562
11584
  const CharMode = 0;
11563
11585
  const WordMode = 1;
@@ -11629,34 +11651,32 @@ function toChar(data, charX, rowData, isOverflow) {
11629
11651
 
11630
11652
  function layoutText(drawData, style) {
11631
11653
  const { rows, bounds } = drawData;
11632
- const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing } = style;
11654
+ const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
11633
11655
  let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
11634
11656
  let starY = __baseLine;
11635
11657
  if (__clipText && realHeight > height) {
11636
11658
  realHeight = Math.max(height, __lineHeight);
11637
11659
  drawData.overflow = rows.length;
11638
11660
  }
11639
- else {
11661
+ else if (height || autoSizeAlign) {
11640
11662
  switch (verticalAlign) {
11641
11663
  case 'middle':
11642
11664
  y += (height - realHeight) / 2;
11643
11665
  break;
11644
- case 'bottom':
11645
- y += (height - realHeight);
11666
+ case 'bottom': y += (height - realHeight);
11646
11667
  }
11647
11668
  }
11648
11669
  starY += y;
11649
- let row, rowX, rowWidth;
11670
+ let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
11650
11671
  for (let i = 0, len = rows.length; i < len; i++) {
11651
11672
  row = rows[i];
11652
11673
  row.x = x;
11653
11674
  if (row.width < width || (row.width > width && !__clipText)) {
11654
11675
  switch (textAlign) {
11655
11676
  case 'center':
11656
- row.x += (width - row.width) / 2;
11677
+ row.x += (layoutWidth - row.width) / 2;
11657
11678
  break;
11658
- case 'right':
11659
- row.x += width - row.width;
11679
+ case 'right': row.x += layoutWidth - row.width;
11660
11680
  }
11661
11681
  }
11662
11682
  if (row.paraStart && paraSpacing && i > 0)
@@ -11761,14 +11781,14 @@ function getDrawData(content, style) {
11761
11781
  let height = style.__getInput('height') || 0;
11762
11782
  const { textDecoration, __font, __padding: padding } = style;
11763
11783
  if (padding) {
11764
- if (width) {
11784
+ if (width)
11785
+ x = padding[left], width -= (padding[right] + padding[left]);
11786
+ else if (!style.autoSizeAlign)
11765
11787
  x = padding[left];
11766
- width -= (padding[right] + padding[left]);
11767
- }
11768
- if (height) {
11788
+ if (height)
11789
+ y = padding[top], height -= (padding[top] + padding[bottom]);
11790
+ else if (!style.autoSizeAlign)
11769
11791
  y = padding[top];
11770
- height -= (padding[top] + padding[bottom]);
11771
- }
11772
11792
  }
11773
11793
  const drawData = {
11774
11794
  bounds: { x, y, width, height },
@@ -11788,22 +11808,20 @@ function getDrawData(content, style) {
11788
11808
  return drawData;
11789
11809
  }
11790
11810
  function padAutoText(padding, drawData, style, width, height) {
11791
- if (!width) {
11811
+ if (!width && style.autoSizeAlign) {
11792
11812
  switch (style.textAlign) {
11793
11813
  case 'left':
11794
11814
  offsetText(drawData, 'x', padding[left]);
11795
11815
  break;
11796
- case 'right':
11797
- offsetText(drawData, 'x', -padding[right]);
11816
+ case 'right': offsetText(drawData, 'x', -padding[right]);
11798
11817
  }
11799
11818
  }
11800
- if (!height) {
11819
+ if (!height && style.autoSizeAlign) {
11801
11820
  switch (style.verticalAlign) {
11802
11821
  case 'top':
11803
11822
  offsetText(drawData, 'y', padding[top]);
11804
11823
  break;
11805
- case 'bottom':
11806
- offsetText(drawData, 'y', -padding[bottom]);
11824
+ case 'bottom': offsetText(drawData, 'y', -padding[bottom]);
11807
11825
  }
11808
11826
  }
11809
11827
  }