@leafer-draw/worker 1.0.4 → 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.
@@ -4755,6 +4755,7 @@ class RenderEvent extends Event {
4755
4755
  }
4756
4756
  }
4757
4757
  RenderEvent.REQUEST = 'render.request';
4758
+ RenderEvent.CHILD_START = 'render.child_start';
4758
4759
  RenderEvent.START = 'render.start';
4759
4760
  RenderEvent.BEFORE = 'render.before';
4760
4761
  RenderEvent.RENDER = 'render';
@@ -4930,7 +4931,7 @@ const { isFinite } = Number;
4930
4931
  const debug$5 = Debug.get('setAttr');
4931
4932
  const LeafDataProxy = {
4932
4933
  __setAttr(name, newValue, checkFiniteNumber) {
4933
- if (this.leafer && this.leafer.created) {
4934
+ if (this.leaferIsCreated) {
4934
4935
  const oldValue = this.__.__getInput(name);
4935
4936
  if (checkFiniteNumber && !isFinite(newValue) && newValue !== undefined) {
4936
4937
  debug$5.warn(this.innerName, name, newValue);
@@ -5002,7 +5003,7 @@ const LeafMatrix = {
5002
5003
 
5003
5004
  const { updateMatrix: updateMatrix$1, updateAllMatrix: updateAllMatrix$2 } = LeafHelper;
5004
5005
  const { updateBounds: updateBounds$1 } = BranchHelper;
5005
- const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$2, copy: copy$4 } = BoundsHelper;
5006
+ const { toOuterOf: toOuterOf$1, copyAndSpread: copyAndSpread$1, copy: copy$4 } = BoundsHelper;
5006
5007
  const { toBounds: toBounds$2 } = PathBounds;
5007
5008
  const LeafBounds = {
5008
5009
  __updateWorldBounds() {
@@ -5085,7 +5086,7 @@ const LeafBounds = {
5085
5086
  const b = this.__layout.boxBounds;
5086
5087
  const data = this.__;
5087
5088
  if (data.__pathInputed) {
5088
- toBounds$2(data.__pathForRender, b);
5089
+ toBounds$2(data.path, b);
5089
5090
  }
5090
5091
  else {
5091
5092
  b.x = 0;
@@ -5097,7 +5098,7 @@ const LeafBounds = {
5097
5098
  __updateAutoLayout() {
5098
5099
  this.__layout.matrixChanged = true;
5099
5100
  if (this.isBranch) {
5100
- if (this.leafer && this.leafer.ready)
5101
+ if (this.leaferIsReady)
5101
5102
  this.leafer.layouter.addExtra(this);
5102
5103
  if (this.__.flow) {
5103
5104
  if (this.__layout.boxChanged)
@@ -5123,11 +5124,11 @@ const LeafBounds = {
5123
5124
  },
5124
5125
  __updateStrokeBounds() {
5125
5126
  const layout = this.__layout;
5126
- copyAndSpread$2(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
5127
+ copyAndSpread$1(layout.strokeBounds, layout.boxBounds, layout.strokeBoxSpread);
5127
5128
  },
5128
5129
  __updateRenderBounds() {
5129
5130
  const layout = this.__layout;
5130
- 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);
5131
5132
  }
5132
5133
  };
5133
5134
 
@@ -5232,6 +5233,8 @@ let Leaf = class Leaf {
5232
5233
  get innerName() { return this.__.name || this.tag + this.innerId; }
5233
5234
  get __DataProcessor() { return LeafData; }
5234
5235
  get __LayoutProcessor() { return LeafLayout; }
5236
+ get leaferIsCreated() { return this.leafer && this.leafer.created; }
5237
+ get leaferIsReady() { return this.leafer && this.leafer.ready; }
5235
5238
  get isLeafer() { return false; }
5236
5239
  get isBranch() { return false; }
5237
5240
  get isBranchLeaf() { return false; }
@@ -5673,6 +5676,7 @@ let Branch = class Branch extends Leaf {
5673
5676
  add(child, index) {
5674
5677
  if (child === this)
5675
5678
  return;
5679
+ child.__ || (child = UICreator.get(child.tag, child));
5676
5680
  if (child.parent)
5677
5681
  child.parent.remove(child);
5678
5682
  child.parent = this;
@@ -5695,10 +5699,14 @@ let Branch = class Branch extends Leaf {
5695
5699
  }
5696
5700
  remove(child, destroy) {
5697
5701
  if (child) {
5698
- if (child.animationOut)
5699
- 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
+ }
5700
5708
  else
5701
- this.__remove(child, destroy);
5709
+ this.find(child).forEach(item => this.remove(item, destroy));
5702
5710
  }
5703
5711
  else if (child === undefined) {
5704
5712
  super.remove(null, destroy);
@@ -5916,7 +5924,7 @@ class LeafLevelList {
5916
5924
  }
5917
5925
  }
5918
5926
 
5919
- const version = "1.0.4";
5927
+ const version = "1.0.5";
5920
5928
 
5921
5929
  class LeaferCanvas extends LeaferCanvasBase {
5922
5930
  get allowBackgroundColor() { return true; }
@@ -6385,6 +6393,7 @@ class Renderer {
6385
6393
  this.totalBounds = new Bounds();
6386
6394
  debug$3.log(target.innerName, '--->');
6387
6395
  try {
6396
+ target.app.emit(RenderEvent.CHILD_START, target);
6388
6397
  this.emitRender(RenderEvent.START);
6389
6398
  this.renderOnce(callback);
6390
6399
  this.emitRender(RenderEvent.END, this.totalBounds);
@@ -7121,12 +7130,7 @@ let UI = UI_1 = class UI extends Leaf {
7121
7130
  this.__drawPathByData(canvas, this.__.path);
7122
7131
  }
7123
7132
  __drawPathByData(drawer, data) {
7124
- if (data) {
7125
- PathDrawer.drawPathByData(drawer, data);
7126
- }
7127
- else {
7128
- this.__drawPathByBox(drawer);
7129
- }
7133
+ data ? PathDrawer.drawPathByData(drawer, data) : this.__drawPathByBox(drawer);
7130
7134
  }
7131
7135
  __drawPathByBox(drawer) {
7132
7136
  const { x, y, width, height } = this.__layout.boxBounds;
@@ -7134,9 +7138,8 @@ let UI = UI_1 = class UI extends Leaf {
7134
7138
  const { cornerRadius } = this.__;
7135
7139
  drawer.roundRect(x, y, width, height, typeof cornerRadius === 'number' ? [cornerRadius] : cornerRadius);
7136
7140
  }
7137
- else {
7141
+ else
7138
7142
  drawer.rect(x, y, width, height);
7139
- }
7140
7143
  }
7141
7144
  animate(_keyframe, _options, _type, _isTemp) {
7142
7145
  return needPlugin('animate');
@@ -7819,10 +7822,9 @@ Rect = __decorate([
7819
7822
  registerUI()
7820
7823
  ], Rect);
7821
7824
 
7822
- const rect = Rect.prototype;
7823
- const group = Group.prototype;
7825
+ const { copy: copy$2, add, includes: includes$1 } = BoundsHelper;
7826
+ const rect = Rect.prototype, group = Group.prototype;
7824
7827
  const childrenRenderBounds = {};
7825
- const { copy: copy$2, add, includes: includes$1, copyAndSpread: copyAndSpread$1 } = BoundsHelper;
7826
7828
  let Box = class Box extends Group {
7827
7829
  get __tag() { return 'Box'; }
7828
7830
  get isBranchLeaf() { return true; }
@@ -7836,29 +7838,27 @@ let Box = class Box extends Group {
7836
7838
  return this.__updateRectRenderSpread() || -1;
7837
7839
  }
7838
7840
  __updateRectBoxBounds() { }
7839
- __updateBoxBounds(secondLayout) {
7841
+ __updateBoxBounds(_secondLayout) {
7840
7842
  const data = this.__;
7841
7843
  if (this.children.length) {
7842
7844
  if (data.__autoSide) {
7843
- if (this.leafer && this.leafer.ready)
7844
- this.leafer.layouter.addExtra(this);
7845
7845
  super.__updateBoxBounds();
7846
7846
  const { boxBounds } = this.__layout;
7847
7847
  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;
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
+ }
7852
7856
  }
7853
- if (secondLayout && data.flow && data.padding)
7854
- copyAndSpread$1(boxBounds, boxBounds, data.padding, false, data.__autoSize ? null : (data.__autoWidth ? 'width' : 'height'));
7855
7857
  this.__updateNaturalSize();
7856
7858
  }
7857
7859
  else {
7858
7860
  this.__updateRectBoxBounds();
7859
7861
  }
7860
- if (data.flow)
7861
- this.__updateContentBounds();
7862
7862
  }
7863
7863
  else {
7864
7864
  this.__updateRectBoxBounds();
@@ -7924,6 +7924,9 @@ __decorate([
7924
7924
  __decorate([
7925
7925
  dataType(false)
7926
7926
  ], Box.prototype, "resizeChildren", void 0);
7927
+ __decorate([
7928
+ dataType(false)
7929
+ ], Box.prototype, "textBox", void 0);
7927
7930
  __decorate([
7928
7931
  affectRenderBoundsType('show')
7929
7932
  ], Box.prototype, "overflow", void 0);
@@ -8453,6 +8456,9 @@ __decorate([
8453
8456
  __decorate([
8454
8457
  boundsType('top')
8455
8458
  ], Text.prototype, "verticalAlign", void 0);
8459
+ __decorate([
8460
+ boundsType(true)
8461
+ ], Text.prototype, "autoSizeAlign", void 0);
8456
8462
  __decorate([
8457
8463
  boundsType('normal')
8458
8464
  ], Text.prototype, "textWrap", void 0);
@@ -8994,9 +9000,10 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
8994
9000
  onLoadError(ui, event, image.error);
8995
9001
  }
8996
9002
  else {
8997
- ignoreRender(ui, true);
8998
- if (firstUse)
9003
+ if (firstUse) {
9004
+ ignoreRender(ui, true);
8999
9005
  onLoad(ui, event);
9006
+ }
9000
9007
  leafPaint.loadId = image.load(() => {
9001
9008
  ignoreRender(ui, false);
9002
9009
  if (!ui.destroyed) {
@@ -9608,11 +9615,12 @@ const { trimRight } = TextRowHelper;
9608
9615
  const { Letter, Single, Before, After, Symbol, Break } = CharType;
9609
9616
  let word, row, wordWidth, rowWidth, realWidth;
9610
9617
  let char, charWidth, startCharSize, charSize, charType, lastCharType, langBreak, afterBreak, paraStart;
9611
- let textDrawData, rows = [], bounds;
9618
+ let textDrawData, rows = [], bounds, findMaxWidth;
9612
9619
  function createRows(drawData, content, style) {
9613
9620
  textDrawData = drawData;
9614
9621
  rows = drawData.rows;
9615
9622
  bounds = drawData.bounds;
9623
+ findMaxWidth = !bounds.width && !style.autoSizeAlign;
9616
9624
  const { __letterSpacing, paraIndent, textCase } = style;
9617
9625
  const { canvas } = Platform;
9618
9626
  const { width, height } = bounds;
@@ -9697,7 +9705,10 @@ function createRows(drawData, content, style) {
9697
9705
  else {
9698
9706
  content.split('\n').forEach(content => {
9699
9707
  textDrawData.paraNumber++;
9700
- 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();
9701
9712
  });
9702
9713
  }
9703
9714
  }
@@ -9728,10 +9739,16 @@ function addRow() {
9728
9739
  row.width = rowWidth;
9729
9740
  if (bounds.width)
9730
9741
  trimRight(row);
9742
+ else if (findMaxWidth)
9743
+ setMaxWidth();
9731
9744
  rows.push(row);
9732
9745
  row = { words: [] };
9733
9746
  rowWidth = 0;
9734
9747
  }
9748
+ function setMaxWidth() {
9749
+ if (rowWidth > (textDrawData.maxWidth || 0))
9750
+ textDrawData.maxWidth = rowWidth;
9751
+ }
9735
9752
 
9736
9753
  const CharMode = 0;
9737
9754
  const WordMode = 1;
@@ -9803,34 +9820,32 @@ function toChar(data, charX, rowData, isOverflow) {
9803
9820
 
9804
9821
  function layoutText(drawData, style) {
9805
9822
  const { rows, bounds } = drawData;
9806
- const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing } = style;
9823
+ const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
9807
9824
  let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
9808
9825
  let starY = __baseLine;
9809
9826
  if (__clipText && realHeight > height) {
9810
9827
  realHeight = Math.max(height, __lineHeight);
9811
9828
  drawData.overflow = rows.length;
9812
9829
  }
9813
- else {
9830
+ else if (height || autoSizeAlign) {
9814
9831
  switch (verticalAlign) {
9815
9832
  case 'middle':
9816
9833
  y += (height - realHeight) / 2;
9817
9834
  break;
9818
- case 'bottom':
9819
- y += (height - realHeight);
9835
+ case 'bottom': y += (height - realHeight);
9820
9836
  }
9821
9837
  }
9822
9838
  starY += y;
9823
- let row, rowX, rowWidth;
9839
+ let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
9824
9840
  for (let i = 0, len = rows.length; i < len; i++) {
9825
9841
  row = rows[i];
9826
9842
  row.x = x;
9827
9843
  if (row.width < width || (row.width > width && !__clipText)) {
9828
9844
  switch (textAlign) {
9829
9845
  case 'center':
9830
- row.x += (width - row.width) / 2;
9846
+ row.x += (layoutWidth - row.width) / 2;
9831
9847
  break;
9832
- case 'right':
9833
- row.x += width - row.width;
9848
+ case 'right': row.x += layoutWidth - row.width;
9834
9849
  }
9835
9850
  }
9836
9851
  if (row.paraStart && paraSpacing && i > 0)
@@ -9935,14 +9950,14 @@ function getDrawData(content, style) {
9935
9950
  let height = style.__getInput('height') || 0;
9936
9951
  const { textDecoration, __font, __padding: padding } = style;
9937
9952
  if (padding) {
9938
- if (width) {
9953
+ if (width)
9954
+ x = padding[left], width -= (padding[right] + padding[left]);
9955
+ else if (!style.autoSizeAlign)
9939
9956
  x = padding[left];
9940
- width -= (padding[right] + padding[left]);
9941
- }
9942
- if (height) {
9957
+ if (height)
9958
+ y = padding[top], height -= (padding[top] + padding[bottom]);
9959
+ else if (!style.autoSizeAlign)
9943
9960
  y = padding[top];
9944
- height -= (padding[top] + padding[bottom]);
9945
- }
9946
9961
  }
9947
9962
  const drawData = {
9948
9963
  bounds: { x, y, width, height },
@@ -9962,22 +9977,20 @@ function getDrawData(content, style) {
9962
9977
  return drawData;
9963
9978
  }
9964
9979
  function padAutoText(padding, drawData, style, width, height) {
9965
- if (!width) {
9980
+ if (!width && style.autoSizeAlign) {
9966
9981
  switch (style.textAlign) {
9967
9982
  case 'left':
9968
9983
  offsetText(drawData, 'x', padding[left]);
9969
9984
  break;
9970
- case 'right':
9971
- offsetText(drawData, 'x', -padding[right]);
9985
+ case 'right': offsetText(drawData, 'x', -padding[right]);
9972
9986
  }
9973
9987
  }
9974
- if (!height) {
9988
+ if (!height && style.autoSizeAlign) {
9975
9989
  switch (style.verticalAlign) {
9976
9990
  case 'top':
9977
9991
  offsetText(drawData, 'y', padding[top]);
9978
9992
  break;
9979
- case 'bottom':
9980
- offsetText(drawData, 'y', -padding[bottom]);
9993
+ case 'bottom': offsetText(drawData, 'y', -padding[bottom]);
9981
9994
  }
9982
9995
  }
9983
9996
  }