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