leafer-draw 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$5(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$6 = 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$6.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$4 } = BoundsHelper;
5006
+ const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$1, copy: copy$4 } = 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$4(layout.renderBounds, layout.strokeBounds);
5131
+ layout.renderSpread > 0 ? copyAndSpread$1(layout.renderBounds, layout.boxBounds, layout.renderSpread) : copy$4(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
  const debug$5 = Debug.get('LeaferCanvas');
5920
5930
  class LeaferCanvas extends LeaferCanvasBase {
@@ -6556,6 +6566,7 @@ class Renderer {
6556
6566
  this.totalBounds = new Bounds();
6557
6567
  debug$3.log(target.innerName, '--->');
6558
6568
  try {
6569
+ target.app.emit(RenderEvent.CHILD_START, target);
6559
6570
  this.emitRender(RenderEvent.START);
6560
6571
  this.renderOnce(callback);
6561
6572
  this.emitRender(RenderEvent.END, this.totalBounds);
@@ -7292,12 +7303,7 @@ let UI = UI_1 = class UI extends Leaf {
7292
7303
  this.__drawPathByData(canvas, this.__.path);
7293
7304
  }
7294
7305
  __drawPathByData(drawer, data) {
7295
- if (data) {
7296
- PathDrawer.drawPathByData(drawer, data);
7297
- }
7298
- else {
7299
- this.__drawPathByBox(drawer);
7300
- }
7306
+ data ? PathDrawer.drawPathByData(drawer, data) : this.__drawPathByBox(drawer);
7301
7307
  }
7302
7308
  __drawPathByBox(drawer) {
7303
7309
  const { x, y, width, height } = this.__layout.boxBounds;
@@ -7305,9 +7311,8 @@ let UI = UI_1 = class UI extends Leaf {
7305
7311
  const { cornerRadius } = this.__;
7306
7312
  drawer.roundRect(x, y, width, height, typeof cornerRadius === 'number' ? [cornerRadius] : cornerRadius);
7307
7313
  }
7308
- else {
7314
+ else
7309
7315
  drawer.rect(x, y, width, height);
7310
- }
7311
7316
  }
7312
7317
  animate(_keyframe, _options, _type, _isTemp) {
7313
7318
  return needPlugin('animate');
@@ -7316,10 +7321,10 @@ let UI = UI_1 = class UI extends Leaf {
7316
7321
  export(filename, options) {
7317
7322
  return Export.export(this, filename, options);
7318
7323
  }
7319
- clone(newData) {
7324
+ clone(data) {
7320
7325
  const json = this.toJSON();
7321
- if (newData)
7322
- Object.assign(json, newData);
7326
+ if (data)
7327
+ Object.assign(json, data);
7323
7328
  return UI_1.one(json);
7324
7329
  }
7325
7330
  static one(data, x, y, width, height) {
@@ -7990,10 +7995,9 @@ Rect = __decorate([
7990
7995
  registerUI()
7991
7996
  ], Rect);
7992
7997
 
7993
- const rect = Rect.prototype;
7994
- const group = Group.prototype;
7998
+ const { copy: copy$2, add, includes: includes$1 } = BoundsHelper;
7999
+ const rect = Rect.prototype, group = Group.prototype;
7995
8000
  const childrenRenderBounds = {};
7996
- const { copy: copy$2, add, includes: includes$1, copyAndSpread: copyAndSpread$1 } = BoundsHelper;
7997
8001
  let Box = class Box extends Group {
7998
8002
  get __tag() { return 'Box'; }
7999
8003
  get isBranchLeaf() { return true; }
@@ -8007,29 +8011,27 @@ let Box = class Box extends Group {
8007
8011
  return this.__updateRectRenderSpread() || -1;
8008
8012
  }
8009
8013
  __updateRectBoxBounds() { }
8010
- __updateBoxBounds(secondLayout) {
8014
+ __updateBoxBounds(_secondLayout) {
8011
8015
  const data = this.__;
8012
8016
  if (this.children.length) {
8013
8017
  if (data.__autoSide) {
8014
- if (this.leafer && this.leafer.ready)
8015
- this.leafer.layouter.addExtra(this);
8016
8018
  super.__updateBoxBounds();
8017
8019
  const { boxBounds } = this.__layout;
8018
8020
  if (!data.__autoSize) {
8019
- if (data.__autoWidth)
8020
- boxBounds.width += boxBounds.x, boxBounds.height = data.height, boxBounds.y = boxBounds.x = 0;
8021
- else
8022
- boxBounds.height += boxBounds.y, boxBounds.width = data.width, boxBounds.x = boxBounds.y = 0;
8021
+ if (data.__autoWidth) {
8022
+ boxBounds.width += boxBounds.x, boxBounds.x = 0;
8023
+ boxBounds.height = data.height, boxBounds.y = 0;
8024
+ }
8025
+ else {
8026
+ boxBounds.height += boxBounds.y, boxBounds.y = 0;
8027
+ boxBounds.width = data.width, boxBounds.x = 0;
8028
+ }
8023
8029
  }
8024
- if (secondLayout && data.flow && data.padding)
8025
- copyAndSpread$1(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'));
8026
8030
  this.__updateNaturalSize();
8027
8031
  }
8028
8032
  else {
8029
8033
  this.__updateRectBoxBounds();
8030
8034
  }
8031
- if (data.flow)
8032
- this.__updateContentBounds();
8033
8035
  }
8034
8036
  else {
8035
8037
  this.__updateRectBoxBounds();
@@ -8095,6 +8097,9 @@ __decorate([
8095
8097
  __decorate([
8096
8098
  dataType(false)
8097
8099
  ], Box.prototype, "resizeChildren", void 0);
8100
+ __decorate([
8101
+ dataType(false)
8102
+ ], Box.prototype, "textBox", void 0);
8098
8103
  __decorate([
8099
8104
  affectRenderBoundsType('show')
8100
8105
  ], Box.prototype, "overflow", void 0);
@@ -8624,6 +8629,9 @@ __decorate([
8624
8629
  __decorate([
8625
8630
  boundsType('top')
8626
8631
  ], Text.prototype, "verticalAlign", void 0);
8632
+ __decorate([
8633
+ boundsType(true)
8634
+ ], Text.prototype, "autoSizeAlign", void 0);
8627
8635
  __decorate([
8628
8636
  boundsType('normal')
8629
8637
  ], Text.prototype, "textWrap", void 0);
@@ -9165,9 +9173,10 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
9165
9173
  onLoadError(ui, event, image.error);
9166
9174
  }
9167
9175
  else {
9168
- ignoreRender(ui, true);
9169
- if (firstUse)
9176
+ if (firstUse) {
9177
+ ignoreRender(ui, true);
9170
9178
  onLoad(ui, event);
9179
+ }
9171
9180
  leafPaint.loadId = image.load(() => {
9172
9181
  ignoreRender(ui, false);
9173
9182
  if (!ui.destroyed) {
@@ -9779,11 +9788,12 @@ const { trimRight } = TextRowHelper;
9779
9788
  const { Letter, Single, Before, After, Symbol, Break } = CharType;
9780
9789
  let word, row, wordWidth, rowWidth, realWidth;
9781
9790
  let char, charWidth, startCharSize, charSize, charType, lastCharType, langBreak, afterBreak, paraStart;
9782
- let textDrawData, rows = [], bounds;
9791
+ let textDrawData, rows = [], bounds, findMaxWidth;
9783
9792
  function createRows(drawData, content, style) {
9784
9793
  textDrawData = drawData;
9785
9794
  rows = drawData.rows;
9786
9795
  bounds = drawData.bounds;
9796
+ findMaxWidth = !bounds.width && !style.autoSizeAlign;
9787
9797
  const { __letterSpacing, paraIndent, textCase } = style;
9788
9798
  const { canvas } = Platform;
9789
9799
  const { width, height } = bounds;
@@ -9868,7 +9878,10 @@ function createRows(drawData, content, style) {
9868
9878
  else {
9869
9879
  content.split('\n').forEach(content => {
9870
9880
  textDrawData.paraNumber++;
9871
- rows.push({ x: paraIndent || 0, text: content, width: canvas.measureText(content).width, paraStart: true });
9881
+ rowWidth = canvas.measureText(content).width;
9882
+ rows.push({ x: paraIndent || 0, text: content, width: rowWidth, paraStart: true });
9883
+ if (findMaxWidth)
9884
+ setMaxWidth();
9872
9885
  });
9873
9886
  }
9874
9887
  }
@@ -9899,10 +9912,16 @@ function addRow() {
9899
9912
  row.width = rowWidth;
9900
9913
  if (bounds.width)
9901
9914
  trimRight(row);
9915
+ else if (findMaxWidth)
9916
+ setMaxWidth();
9902
9917
  rows.push(row);
9903
9918
  row = { words: [] };
9904
9919
  rowWidth = 0;
9905
9920
  }
9921
+ function setMaxWidth() {
9922
+ if (rowWidth > (textDrawData.maxWidth || 0))
9923
+ textDrawData.maxWidth = rowWidth;
9924
+ }
9906
9925
 
9907
9926
  const CharMode = 0;
9908
9927
  const WordMode = 1;
@@ -9974,34 +9993,32 @@ function toChar(data, charX, rowData, isOverflow) {
9974
9993
 
9975
9994
  function layoutText(drawData, style) {
9976
9995
  const { rows, bounds } = drawData;
9977
- const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing } = style;
9996
+ const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
9978
9997
  let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
9979
9998
  let starY = __baseLine;
9980
9999
  if (__clipText && realHeight > height) {
9981
10000
  realHeight = Math.max(height, __lineHeight);
9982
10001
  drawData.overflow = rows.length;
9983
10002
  }
9984
- else {
10003
+ else if (height || autoSizeAlign) {
9985
10004
  switch (verticalAlign) {
9986
10005
  case 'middle':
9987
10006
  y += (height - realHeight) / 2;
9988
10007
  break;
9989
- case 'bottom':
9990
- y += (height - realHeight);
10008
+ case 'bottom': y += (height - realHeight);
9991
10009
  }
9992
10010
  }
9993
10011
  starY += y;
9994
- let row, rowX, rowWidth;
10012
+ let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
9995
10013
  for (let i = 0, len = rows.length; i < len; i++) {
9996
10014
  row = rows[i];
9997
10015
  row.x = x;
9998
10016
  if (row.width < width || (row.width > width && !__clipText)) {
9999
10017
  switch (textAlign) {
10000
10018
  case 'center':
10001
- row.x += (width - row.width) / 2;
10019
+ row.x += (layoutWidth - row.width) / 2;
10002
10020
  break;
10003
- case 'right':
10004
- row.x += width - row.width;
10021
+ case 'right': row.x += layoutWidth - row.width;
10005
10022
  }
10006
10023
  }
10007
10024
  if (row.paraStart && paraSpacing && i > 0)
@@ -10106,14 +10123,14 @@ function getDrawData(content, style) {
10106
10123
  let height = style.__getInput('height') || 0;
10107
10124
  const { textDecoration, __font, __padding: padding } = style;
10108
10125
  if (padding) {
10109
- if (width) {
10126
+ if (width)
10127
+ x = padding[left], width -= (padding[right] + padding[left]);
10128
+ else if (!style.autoSizeAlign)
10110
10129
  x = padding[left];
10111
- width -= (padding[right] + padding[left]);
10112
- }
10113
- if (height) {
10130
+ if (height)
10131
+ y = padding[top], height -= (padding[top] + padding[bottom]);
10132
+ else if (!style.autoSizeAlign)
10114
10133
  y = padding[top];
10115
- height -= (padding[top] + padding[bottom]);
10116
- }
10117
10134
  }
10118
10135
  const drawData = {
10119
10136
  bounds: { x, y, width, height },
@@ -10133,22 +10150,20 @@ function getDrawData(content, style) {
10133
10150
  return drawData;
10134
10151
  }
10135
10152
  function padAutoText(padding, drawData, style, width, height) {
10136
- if (!width) {
10153
+ if (!width && style.autoSizeAlign) {
10137
10154
  switch (style.textAlign) {
10138
10155
  case 'left':
10139
10156
  offsetText(drawData, 'x', padding[left]);
10140
10157
  break;
10141
- case 'right':
10142
- offsetText(drawData, 'x', -padding[right]);
10158
+ case 'right': offsetText(drawData, 'x', -padding[right]);
10143
10159
  }
10144
10160
  }
10145
- if (!height) {
10161
+ if (!height && style.autoSizeAlign) {
10146
10162
  switch (style.verticalAlign) {
10147
10163
  case 'top':
10148
10164
  offsetText(drawData, 'y', padding[top]);
10149
10165
  break;
10150
- case 'bottom':
10151
- offsetText(drawData, 'y', -padding[bottom]);
10166
+ case 'bottom': offsetText(drawData, 'y', -padding[bottom]);
10152
10167
  }
10153
10168
  }
10154
10169
  }