@leafer-draw/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$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$5 = 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$5.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
  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$3.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);
@@ -7119,12 +7130,7 @@ let UI = UI_1 = class UI extends Leaf {
7119
7130
  this.__drawPathByData(canvas, this.__.path);
7120
7131
  }
7121
7132
  __drawPathByData(drawer, data) {
7122
- if (data) {
7123
- PathDrawer.drawPathByData(drawer, data);
7124
- }
7125
- else {
7126
- this.__drawPathByBox(drawer);
7127
- }
7133
+ data ? PathDrawer.drawPathByData(drawer, data) : this.__drawPathByBox(drawer);
7128
7134
  }
7129
7135
  __drawPathByBox(drawer) {
7130
7136
  const { x, y, width, height } = this.__layout.boxBounds;
@@ -7132,9 +7138,8 @@ let UI = UI_1 = class UI extends Leaf {
7132
7138
  const { cornerRadius } = this.__;
7133
7139
  drawer.roundRect(x, y, width, height, typeof cornerRadius === 'number' ? [cornerRadius] : cornerRadius);
7134
7140
  }
7135
- else {
7141
+ else
7136
7142
  drawer.rect(x, y, width, height);
7137
- }
7138
7143
  }
7139
7144
  animate(_keyframe, _options, _type, _isTemp) {
7140
7145
  return needPlugin('animate');
@@ -7143,10 +7148,10 @@ let UI = UI_1 = class UI extends Leaf {
7143
7148
  export(filename, options) {
7144
7149
  return Export.export(this, filename, options);
7145
7150
  }
7146
- clone(newData) {
7151
+ clone(data) {
7147
7152
  const json = this.toJSON();
7148
- if (newData)
7149
- Object.assign(json, newData);
7153
+ if (data)
7154
+ Object.assign(json, data);
7150
7155
  return UI_1.one(json);
7151
7156
  }
7152
7157
  static one(data, x, y, width, height) {
@@ -7817,10 +7822,9 @@ Rect = __decorate([
7817
7822
  registerUI()
7818
7823
  ], Rect);
7819
7824
 
7820
- const rect = Rect.prototype;
7821
- const group = Group.prototype;
7825
+ const { copy: copy$2, add, includes: includes$1 } = BoundsHelper;
7826
+ const rect = Rect.prototype, group = Group.prototype;
7822
7827
  const childrenRenderBounds = {};
7823
- const { copy: copy$2, add, includes: includes$1, copyAndSpread: copyAndSpread$1 } = BoundsHelper;
7824
7828
  let Box = class Box extends Group {
7825
7829
  get __tag() { return 'Box'; }
7826
7830
  get isBranchLeaf() { return true; }
@@ -7834,29 +7838,27 @@ let Box = class Box extends Group {
7834
7838
  return this.__updateRectRenderSpread() || -1;
7835
7839
  }
7836
7840
  __updateRectBoxBounds() { }
7837
- __updateBoxBounds(secondLayout) {
7841
+ __updateBoxBounds(_secondLayout) {
7838
7842
  const data = this.__;
7839
7843
  if (this.children.length) {
7840
7844
  if (data.__autoSide) {
7841
- if (this.leafer && this.leafer.ready)
7842
- this.leafer.layouter.addExtra(this);
7843
7845
  super.__updateBoxBounds();
7844
7846
  const { boxBounds } = this.__layout;
7845
7847
  if (!data.__autoSize) {
7846
- if (data.__autoWidth)
7847
- boxBounds.width += boxBounds.x, boxBounds.height = data.height, boxBounds.y = boxBounds.x = 0;
7848
- else
7849
- boxBounds.height += boxBounds.y, boxBounds.width = data.width, boxBounds.x = boxBounds.y = 0;
7848
+ if (data.__autoWidth) {
7849
+ boxBounds.width += boxBounds.x, boxBounds.x = 0;
7850
+ boxBounds.height = data.height, boxBounds.y = 0;
7851
+ }
7852
+ else {
7853
+ boxBounds.height += boxBounds.y, boxBounds.y = 0;
7854
+ boxBounds.width = data.width, boxBounds.x = 0;
7855
+ }
7850
7856
  }
7851
- if (secondLayout && data.flow && data.padding)
7852
- copyAndSpread$1(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'));
7853
7857
  this.__updateNaturalSize();
7854
7858
  }
7855
7859
  else {
7856
7860
  this.__updateRectBoxBounds();
7857
7861
  }
7858
- if (data.flow)
7859
- this.__updateContentBounds();
7860
7862
  }
7861
7863
  else {
7862
7864
  this.__updateRectBoxBounds();
@@ -7922,6 +7924,9 @@ __decorate([
7922
7924
  __decorate([
7923
7925
  dataType(false)
7924
7926
  ], Box.prototype, "resizeChildren", void 0);
7927
+ __decorate([
7928
+ dataType(false)
7929
+ ], Box.prototype, "textBox", void 0);
7925
7930
  __decorate([
7926
7931
  affectRenderBoundsType('show')
7927
7932
  ], Box.prototype, "overflow", void 0);
@@ -8451,6 +8456,9 @@ __decorate([
8451
8456
  __decorate([
8452
8457
  boundsType('top')
8453
8458
  ], Text.prototype, "verticalAlign", void 0);
8459
+ __decorate([
8460
+ boundsType(true)
8461
+ ], Text.prototype, "autoSizeAlign", void 0);
8454
8462
  __decorate([
8455
8463
  boundsType('normal')
8456
8464
  ], Text.prototype, "textWrap", void 0);
@@ -8992,9 +9000,10 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
8992
9000
  onLoadError(ui, event, image.error);
8993
9001
  }
8994
9002
  else {
8995
- ignoreRender(ui, true);
8996
- if (firstUse)
9003
+ if (firstUse) {
9004
+ ignoreRender(ui, true);
8997
9005
  onLoad(ui, event);
9006
+ }
8998
9007
  leafPaint.loadId = image.load(() => {
8999
9008
  ignoreRender(ui, false);
9000
9009
  if (!ui.destroyed) {
@@ -9606,11 +9615,12 @@ const { trimRight } = TextRowHelper;
9606
9615
  const { Letter, Single, Before, After, Symbol, Break } = CharType;
9607
9616
  let word, row, wordWidth, rowWidth, realWidth;
9608
9617
  let char, charWidth, startCharSize, charSize, charType, lastCharType, langBreak, afterBreak, paraStart;
9609
- let textDrawData, rows = [], bounds;
9618
+ let textDrawData, rows = [], bounds, findMaxWidth;
9610
9619
  function createRows(drawData, content, style) {
9611
9620
  textDrawData = drawData;
9612
9621
  rows = drawData.rows;
9613
9622
  bounds = drawData.bounds;
9623
+ findMaxWidth = !bounds.width && !style.autoSizeAlign;
9614
9624
  const { __letterSpacing, paraIndent, textCase } = style;
9615
9625
  const { canvas } = Platform;
9616
9626
  const { width, height } = bounds;
@@ -9695,7 +9705,10 @@ function createRows(drawData, content, style) {
9695
9705
  else {
9696
9706
  content.split('\n').forEach(content => {
9697
9707
  textDrawData.paraNumber++;
9698
- 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();
9699
9712
  });
9700
9713
  }
9701
9714
  }
@@ -9726,10 +9739,16 @@ function addRow() {
9726
9739
  row.width = rowWidth;
9727
9740
  if (bounds.width)
9728
9741
  trimRight(row);
9742
+ else if (findMaxWidth)
9743
+ setMaxWidth();
9729
9744
  rows.push(row);
9730
9745
  row = { words: [] };
9731
9746
  rowWidth = 0;
9732
9747
  }
9748
+ function setMaxWidth() {
9749
+ if (rowWidth > (textDrawData.maxWidth || 0))
9750
+ textDrawData.maxWidth = rowWidth;
9751
+ }
9733
9752
 
9734
9753
  const CharMode = 0;
9735
9754
  const WordMode = 1;
@@ -9801,34 +9820,32 @@ function toChar(data, charX, rowData, isOverflow) {
9801
9820
 
9802
9821
  function layoutText(drawData, style) {
9803
9822
  const { rows, bounds } = drawData;
9804
- const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing } = style;
9823
+ const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
9805
9824
  let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
9806
9825
  let starY = __baseLine;
9807
9826
  if (__clipText && realHeight > height) {
9808
9827
  realHeight = Math.max(height, __lineHeight);
9809
9828
  drawData.overflow = rows.length;
9810
9829
  }
9811
- else {
9830
+ else if (height || autoSizeAlign) {
9812
9831
  switch (verticalAlign) {
9813
9832
  case 'middle':
9814
9833
  y += (height - realHeight) / 2;
9815
9834
  break;
9816
- case 'bottom':
9817
- y += (height - realHeight);
9835
+ case 'bottom': y += (height - realHeight);
9818
9836
  }
9819
9837
  }
9820
9838
  starY += y;
9821
- let row, rowX, rowWidth;
9839
+ let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
9822
9840
  for (let i = 0, len = rows.length; i < len; i++) {
9823
9841
  row = rows[i];
9824
9842
  row.x = x;
9825
9843
  if (row.width < width || (row.width > width && !__clipText)) {
9826
9844
  switch (textAlign) {
9827
9845
  case 'center':
9828
- row.x += (width - row.width) / 2;
9846
+ row.x += (layoutWidth - row.width) / 2;
9829
9847
  break;
9830
- case 'right':
9831
- row.x += width - row.width;
9848
+ case 'right': row.x += layoutWidth - row.width;
9832
9849
  }
9833
9850
  }
9834
9851
  if (row.paraStart && paraSpacing && i > 0)
@@ -9933,14 +9950,14 @@ function getDrawData(content, style) {
9933
9950
  let height = style.__getInput('height') || 0;
9934
9951
  const { textDecoration, __font, __padding: padding } = style;
9935
9952
  if (padding) {
9936
- if (width) {
9953
+ if (width)
9954
+ x = padding[left], width -= (padding[right] + padding[left]);
9955
+ else if (!style.autoSizeAlign)
9937
9956
  x = padding[left];
9938
- width -= (padding[right] + padding[left]);
9939
- }
9940
- if (height) {
9957
+ if (height)
9958
+ y = padding[top], height -= (padding[top] + padding[bottom]);
9959
+ else if (!style.autoSizeAlign)
9941
9960
  y = padding[top];
9942
- height -= (padding[top] + padding[bottom]);
9943
- }
9944
9961
  }
9945
9962
  const drawData = {
9946
9963
  bounds: { x, y, width, height },
@@ -9960,22 +9977,20 @@ function getDrawData(content, style) {
9960
9977
  return drawData;
9961
9978
  }
9962
9979
  function padAutoText(padding, drawData, style, width, height) {
9963
- if (!width) {
9980
+ if (!width && style.autoSizeAlign) {
9964
9981
  switch (style.textAlign) {
9965
9982
  case 'left':
9966
9983
  offsetText(drawData, 'x', padding[left]);
9967
9984
  break;
9968
- case 'right':
9969
- offsetText(drawData, 'x', -padding[right]);
9985
+ case 'right': offsetText(drawData, 'x', -padding[right]);
9970
9986
  }
9971
9987
  }
9972
- if (!height) {
9988
+ if (!height && style.autoSizeAlign) {
9973
9989
  switch (style.verticalAlign) {
9974
9990
  case 'top':
9975
9991
  offsetText(drawData, 'y', padding[top]);
9976
9992
  break;
9977
- case 'bottom':
9978
- offsetText(drawData, 'y', -padding[bottom]);
9993
+ case 'bottom': offsetText(drawData, 'y', -padding[bottom]);
9979
9994
  }
9980
9995
  }
9981
9996
  }