@leafer-ui/worker 1.0.0-rc.4 → 1.0.0-rc.6
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/dist/worker.esm.js +185 -146
- package/dist/worker.esm.min.js +1 -1
- package/dist/worker.js +568 -388
- package/dist/worker.min.js +1 -1
- package/dist/worker.module.js +569 -388
- package/dist/worker.module.min.js +1 -1
- package/package.json +6 -6
package/dist/worker.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LeafList, DataHelper, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, BoundsHelper, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, Platform, AnimateEvent, ResizeEvent, Creator, LeaferCanvasBase, canvasPatch, LeaferImage, InteractionBase, FileHelper, MatrixHelper, ImageEvent, PointHelper, MathHelper, TaskProcessor } from '@leafer/core';
|
|
2
2
|
export * from '@leafer/core';
|
|
3
3
|
export { LeaferImage } from '@leafer/core';
|
|
4
|
-
import { ColorConvert as ColorConvert$1, Paint, Effect, TextConvert as TextConvert$1, Export as Export$1 } from '@leafer-ui/core';
|
|
4
|
+
import { ColorConvert as ColorConvert$1, ImageManager as ImageManager$1, Paint, Effect, TextConvert as TextConvert$1, Export as Export$1 } from '@leafer-ui/core';
|
|
5
5
|
export * from '@leafer-ui/core';
|
|
6
6
|
|
|
7
7
|
class Watcher {
|
|
@@ -105,7 +105,7 @@ function updateMatrix(updateList, levelList) {
|
|
|
105
105
|
let layout;
|
|
106
106
|
updateList.list.forEach(leaf => {
|
|
107
107
|
layout = leaf.__layout;
|
|
108
|
-
if (levelList.without(leaf) && !layout.
|
|
108
|
+
if (levelList.without(leaf) && !layout.proxyZoom) {
|
|
109
109
|
if (layout.matrixChanged) {
|
|
110
110
|
updateAllWorldMatrix$1(leaf);
|
|
111
111
|
levelList.push(leaf);
|
|
@@ -424,8 +424,7 @@ class Renderer {
|
|
|
424
424
|
const { canvas, updateBlocks: list } = this;
|
|
425
425
|
if (!list)
|
|
426
426
|
return debug.warn('PartRender: need update attr');
|
|
427
|
-
|
|
428
|
-
this.mergeBlocks();
|
|
427
|
+
this.mergeBlocks();
|
|
429
428
|
list.forEach(block => { if (canvas.bounds.hit(block) && !block.isEmpty())
|
|
430
429
|
this.clipRender(block); });
|
|
431
430
|
}
|
|
@@ -444,7 +443,7 @@ class Renderer {
|
|
|
444
443
|
canvas.clearWorld(bounds, true);
|
|
445
444
|
canvas.clipWorld(bounds, true);
|
|
446
445
|
}
|
|
447
|
-
this.__render(bounds, realBounds);
|
|
446
|
+
this.__render(bounds, includes, realBounds);
|
|
448
447
|
canvas.restore();
|
|
449
448
|
Run.end(t);
|
|
450
449
|
}
|
|
@@ -453,12 +452,12 @@ class Renderer {
|
|
|
453
452
|
const { canvas } = this;
|
|
454
453
|
canvas.save();
|
|
455
454
|
canvas.clear();
|
|
456
|
-
this.__render(canvas.bounds);
|
|
455
|
+
this.__render(canvas.bounds, true);
|
|
457
456
|
canvas.restore();
|
|
458
457
|
Run.end(t);
|
|
459
458
|
}
|
|
460
|
-
__render(bounds, realBounds) {
|
|
461
|
-
const options =
|
|
459
|
+
__render(bounds, includes, realBounds) {
|
|
460
|
+
const options = bounds.includes(this.target.__world) ? { includes } : { bounds, includes };
|
|
462
461
|
if (this.needFill)
|
|
463
462
|
this.canvas.fillWorld(bounds, this.config.fill);
|
|
464
463
|
if (Debug.showRepaint)
|
|
@@ -559,7 +558,7 @@ class Renderer {
|
|
|
559
558
|
}
|
|
560
559
|
|
|
561
560
|
const { hitRadiusPoint } = BoundsHelper;
|
|
562
|
-
class
|
|
561
|
+
class Pather {
|
|
563
562
|
constructor(target, selector) {
|
|
564
563
|
this.target = target;
|
|
565
564
|
this.selector = selector;
|
|
@@ -679,117 +678,108 @@ class FindPath {
|
|
|
679
678
|
class Selector {
|
|
680
679
|
constructor(target, userConfig) {
|
|
681
680
|
this.config = {};
|
|
682
|
-
this.
|
|
683
|
-
this.
|
|
684
|
-
this.
|
|
685
|
-
|
|
681
|
+
this.innerIdMap = {};
|
|
682
|
+
this.idMap = {};
|
|
683
|
+
this.methods = {
|
|
684
|
+
id: (leaf, name) => leaf.id === name ? this.idMap[name] = leaf : 0,
|
|
685
|
+
innerId: (leaf, innerId) => leaf.innerId === innerId ? this.innerIdMap[innerId] = leaf : 0,
|
|
686
|
+
className: (leaf, name) => leaf.className === name ? 1 : 0,
|
|
687
|
+
tag: (leaf, name) => leaf.__tag === name ? 1 : 0
|
|
688
|
+
};
|
|
686
689
|
this.target = target;
|
|
687
690
|
if (userConfig)
|
|
688
691
|
this.config = DataHelper.default(userConfig, this.config);
|
|
689
|
-
this.
|
|
692
|
+
this.pather = new Pather(target, this);
|
|
690
693
|
this.__listenEvents();
|
|
691
694
|
}
|
|
692
695
|
getByPoint(hitPoint, hitRadius, options) {
|
|
693
696
|
if (Platform.name === 'node')
|
|
694
697
|
this.target.emit(LayoutEvent.CHECK_UPDATE);
|
|
695
|
-
return this.
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
698
|
+
return this.pather.getByPoint(hitPoint, hitRadius, options);
|
|
699
|
+
}
|
|
700
|
+
getBy(condition, branch, one, options) {
|
|
701
|
+
switch (typeof condition) {
|
|
702
|
+
case 'number':
|
|
703
|
+
const leaf = this.getByInnerId(condition, branch);
|
|
704
|
+
return one ? leaf : (leaf ? [leaf] : []);
|
|
705
|
+
case 'string':
|
|
706
|
+
switch (condition[0]) {
|
|
707
|
+
case '#':
|
|
708
|
+
const leaf = this.getById(condition.substring(1), branch);
|
|
709
|
+
return one ? leaf : (leaf ? [leaf] : []);
|
|
710
|
+
case '.':
|
|
711
|
+
return this.getByMethod(this.methods.className, branch, one, condition.substring(1));
|
|
712
|
+
default:
|
|
713
|
+
return this.getByMethod(this.methods.tag, branch, one, condition);
|
|
714
|
+
}
|
|
715
|
+
case 'function':
|
|
716
|
+
return this.getByMethod(condition, branch, one, options);
|
|
709
717
|
}
|
|
710
718
|
}
|
|
711
|
-
getByInnerId(
|
|
712
|
-
|
|
719
|
+
getByInnerId(innerId, branch) {
|
|
720
|
+
const cache = this.innerIdMap[innerId];
|
|
713
721
|
if (cache)
|
|
714
722
|
return cache;
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
let find;
|
|
718
|
-
this.loopFind(branch, (leaf) => {
|
|
719
|
-
if (leaf.innerId === name) {
|
|
720
|
-
find = leaf;
|
|
721
|
-
this.innerIdList[name] = find;
|
|
722
|
-
return true;
|
|
723
|
-
}
|
|
724
|
-
else {
|
|
725
|
-
return false;
|
|
726
|
-
}
|
|
727
|
-
});
|
|
728
|
-
return find;
|
|
723
|
+
this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId);
|
|
724
|
+
return this.findLeaf;
|
|
729
725
|
}
|
|
730
|
-
getById(
|
|
731
|
-
|
|
732
|
-
if (cache)
|
|
726
|
+
getById(id, branch) {
|
|
727
|
+
const cache = this.idMap[id];
|
|
728
|
+
if (cache && LeafHelper.hasParent(cache, branch || this.target))
|
|
733
729
|
return cache;
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
let find;
|
|
737
|
-
this.loopFind(branch, (leaf) => {
|
|
738
|
-
if (leaf.id === name) {
|
|
739
|
-
find = leaf;
|
|
740
|
-
this.idList[name] = find;
|
|
741
|
-
return true;
|
|
742
|
-
}
|
|
743
|
-
else {
|
|
744
|
-
return false;
|
|
745
|
-
}
|
|
746
|
-
});
|
|
747
|
-
return find;
|
|
748
|
-
}
|
|
749
|
-
getByClassName(name, branch) {
|
|
750
|
-
if (!branch)
|
|
751
|
-
branch = this.target;
|
|
752
|
-
let find = [];
|
|
753
|
-
this.loopFind(branch, (leaf) => {
|
|
754
|
-
if (leaf.className === name)
|
|
755
|
-
find.push(leaf);
|
|
756
|
-
return false;
|
|
757
|
-
});
|
|
758
|
-
return find;
|
|
759
|
-
}
|
|
760
|
-
getByTagName(name, branch) {
|
|
761
|
-
if (!branch)
|
|
762
|
-
branch = this.target;
|
|
763
|
-
let find = [];
|
|
764
|
-
this.loopFind(branch, (leaf) => {
|
|
765
|
-
if (leaf.__tag === name)
|
|
766
|
-
find.push(leaf);
|
|
767
|
-
return false;
|
|
768
|
-
});
|
|
769
|
-
return find;
|
|
730
|
+
this.eachFind(this.toChildren(branch), this.methods.id, null, id);
|
|
731
|
+
return this.findLeaf;
|
|
770
732
|
}
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
733
|
+
getByClassName(className, branch) {
|
|
734
|
+
return this.getByMethod(this.methods.className, branch, false, className);
|
|
735
|
+
}
|
|
736
|
+
getByTag(tag, branch) {
|
|
737
|
+
return this.getByMethod(this.methods.tag, branch, false, tag);
|
|
738
|
+
}
|
|
739
|
+
getByMethod(method, branch, one, options) {
|
|
740
|
+
const list = one ? null : [];
|
|
741
|
+
this.eachFind(this.toChildren(branch), method, list, options);
|
|
742
|
+
return list || this.findLeaf;
|
|
743
|
+
}
|
|
744
|
+
eachFind(children, method, list, options) {
|
|
745
|
+
let child;
|
|
775
746
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
776
|
-
|
|
777
|
-
if (
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
747
|
+
child = children[i];
|
|
748
|
+
if (method(child, options)) {
|
|
749
|
+
if (list) {
|
|
750
|
+
list.push(child);
|
|
751
|
+
}
|
|
752
|
+
else {
|
|
753
|
+
this.findLeaf = child;
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
if (child.isBranch)
|
|
758
|
+
this.eachFind(child.children, method, list, options);
|
|
781
759
|
}
|
|
782
760
|
}
|
|
761
|
+
toChildren(branch) {
|
|
762
|
+
this.findLeaf = null;
|
|
763
|
+
return [branch || this.target];
|
|
764
|
+
}
|
|
783
765
|
__onRemoveChild(event) {
|
|
784
|
-
const
|
|
785
|
-
if (this.
|
|
786
|
-
this.
|
|
787
|
-
if (this.
|
|
788
|
-
this.
|
|
766
|
+
const { id, innerId } = event.child;
|
|
767
|
+
if (this.idMap[id])
|
|
768
|
+
delete this.idMap[id];
|
|
769
|
+
if (this.innerIdMap[innerId])
|
|
770
|
+
delete this.innerIdMap[innerId];
|
|
771
|
+
}
|
|
772
|
+
__checkIdChange(event) {
|
|
773
|
+
if (event.attrName === 'id') {
|
|
774
|
+
const id = event.oldValue;
|
|
775
|
+
if (this.idMap[id])
|
|
776
|
+
delete this.idMap[id];
|
|
777
|
+
}
|
|
789
778
|
}
|
|
790
779
|
__listenEvents() {
|
|
791
780
|
this.__eventIds = [
|
|
792
|
-
this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this)
|
|
781
|
+
this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this),
|
|
782
|
+
this.target.on_(PropertyEvent.CHANGE, this.__checkIdChange, this)
|
|
793
783
|
];
|
|
794
784
|
}
|
|
795
785
|
__removeListenEvents() {
|
|
@@ -799,11 +789,10 @@ class Selector {
|
|
|
799
789
|
destroy() {
|
|
800
790
|
if (this.__eventIds.length) {
|
|
801
791
|
this.__removeListenEvents();
|
|
802
|
-
this.
|
|
803
|
-
this.
|
|
804
|
-
this.
|
|
805
|
-
this.
|
|
806
|
-
this.tagNameList = {};
|
|
792
|
+
this.pather.destroy();
|
|
793
|
+
this.findLeaf = null;
|
|
794
|
+
this.innerIdMap = {};
|
|
795
|
+
this.idMap = {};
|
|
807
796
|
}
|
|
808
797
|
}
|
|
809
798
|
}
|
|
@@ -1183,10 +1172,14 @@ function checkImage(ui, canvas, paint, allowPaint) {
|
|
|
1183
1172
|
createPattern(ui, paint, canvas.pixelRatio);
|
|
1184
1173
|
}
|
|
1185
1174
|
else {
|
|
1186
|
-
|
|
1187
|
-
|
|
1175
|
+
if (!paint.patternTask) {
|
|
1176
|
+
paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function* () {
|
|
1177
|
+
paint.patternTask = null;
|
|
1178
|
+
if (canvas.bounds.hit(ui.__world))
|
|
1179
|
+
createPattern(ui, paint, canvas.pixelRatio);
|
|
1188
1180
|
ui.forceUpdate('surface');
|
|
1189
|
-
|
|
1181
|
+
}), 300);
|
|
1182
|
+
}
|
|
1190
1183
|
}
|
|
1191
1184
|
return false;
|
|
1192
1185
|
}
|
|
@@ -1550,17 +1543,30 @@ function conicGradient(paint, box) {
|
|
|
1550
1543
|
let recycleMap;
|
|
1551
1544
|
function compute(attrName, ui) {
|
|
1552
1545
|
const value = [];
|
|
1546
|
+
const data = ui.__;
|
|
1553
1547
|
let item;
|
|
1554
|
-
let paints =
|
|
1548
|
+
let paints = data.__input[attrName];
|
|
1555
1549
|
if (!(paints instanceof Array))
|
|
1556
1550
|
paints = [paints];
|
|
1557
|
-
recycleMap = recycleImage(attrName,
|
|
1551
|
+
recycleMap = recycleImage(attrName, data);
|
|
1558
1552
|
for (let i = 0, len = paints.length; i < len; i++) {
|
|
1559
1553
|
item = getLeafPaint(attrName, paints[i], ui);
|
|
1560
1554
|
if (item)
|
|
1561
1555
|
value.push(item);
|
|
1562
1556
|
}
|
|
1563
|
-
|
|
1557
|
+
data['_' + attrName] = value.length ? value : undefined;
|
|
1558
|
+
let isPixel;
|
|
1559
|
+
if (paints.length === 1) {
|
|
1560
|
+
const paint = paints[0];
|
|
1561
|
+
if (paint.type === 'image')
|
|
1562
|
+
isPixel = ImageManager$1.isPixel(paint);
|
|
1563
|
+
}
|
|
1564
|
+
if (attrName === 'fill') {
|
|
1565
|
+
data.__pixelFill = isPixel;
|
|
1566
|
+
}
|
|
1567
|
+
else {
|
|
1568
|
+
data.__pixelStroke = isPixel;
|
|
1569
|
+
}
|
|
1564
1570
|
}
|
|
1565
1571
|
function getLeafPaint(attrName, paint, ui) {
|
|
1566
1572
|
if (typeof paint !== 'object' || paint.visible === false || paint.opacity === 0)
|
|
@@ -1835,6 +1841,8 @@ function createRows(drawData, content, style) {
|
|
|
1835
1841
|
const { width, height } = bounds;
|
|
1836
1842
|
const charMode = width || height || __letterSpacing || (textCase !== 'none');
|
|
1837
1843
|
if (charMode) {
|
|
1844
|
+
const wrap = style.textWrap !== 'none';
|
|
1845
|
+
const breakAll = style.textWrap === 'break';
|
|
1838
1846
|
paraStart = true;
|
|
1839
1847
|
lastCharType = null;
|
|
1840
1848
|
startCharSize = charWidth = charSize = wordWidth = rowWidth = 0;
|
|
@@ -1861,16 +1869,23 @@ function createRows(drawData, content, style) {
|
|
|
1861
1869
|
langBreak = (charType === Single && (lastCharType === Single || lastCharType === Letter)) || (lastCharType === Single && charType !== After);
|
|
1862
1870
|
afterBreak = ((charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After));
|
|
1863
1871
|
realWidth = paraStart && paraIndent ? width - paraIndent : width;
|
|
1864
|
-
if (width && rowWidth + wordWidth + charWidth > realWidth) {
|
|
1865
|
-
if (
|
|
1866
|
-
afterBreak = charType === Letter && lastCharType == After;
|
|
1867
|
-
if (langBreak || afterBreak || charType === Break || charType === Before || charType === Single || (wordWidth + charWidth > realWidth)) {
|
|
1872
|
+
if (wrap && (width && rowWidth + wordWidth + charWidth > realWidth)) {
|
|
1873
|
+
if (breakAll) {
|
|
1868
1874
|
if (wordWidth)
|
|
1869
1875
|
addWord();
|
|
1870
1876
|
addRow();
|
|
1871
1877
|
}
|
|
1872
1878
|
else {
|
|
1873
|
-
|
|
1879
|
+
if (!afterBreak)
|
|
1880
|
+
afterBreak = charType === Letter && lastCharType == After;
|
|
1881
|
+
if (langBreak || afterBreak || charType === Break || charType === Before || charType === Single || (wordWidth + charWidth > realWidth)) {
|
|
1882
|
+
if (wordWidth)
|
|
1883
|
+
addWord();
|
|
1884
|
+
addRow();
|
|
1885
|
+
}
|
|
1886
|
+
else {
|
|
1887
|
+
addRow();
|
|
1888
|
+
}
|
|
1874
1889
|
}
|
|
1875
1890
|
}
|
|
1876
1891
|
if (char === ' ' && paraStart !== true && (rowWidth + wordWidth) === 0) ;
|
|
@@ -1940,7 +1955,7 @@ function addRow() {
|
|
|
1940
1955
|
|
|
1941
1956
|
const CharMode = 0;
|
|
1942
1957
|
const WordMode = 1;
|
|
1943
|
-
const
|
|
1958
|
+
const TextMode = 2;
|
|
1944
1959
|
function layoutChar(drawData, style, width, _height) {
|
|
1945
1960
|
const { rows } = drawData;
|
|
1946
1961
|
const { textAlign, paraIndent, letterSpacing } = style;
|
|
@@ -1949,15 +1964,12 @@ function layoutChar(drawData, style, width, _height) {
|
|
|
1949
1964
|
if (row.words) {
|
|
1950
1965
|
indentWidth = paraIndent && row.paraStart ? paraIndent : 0;
|
|
1951
1966
|
addWordWidth = (width && textAlign === 'justify' && row.words.length > 1) ? (width - row.width - indentWidth) / (row.words.length - 1) : 0;
|
|
1952
|
-
mode = (letterSpacing || row.isOverflow) ? CharMode : (addWordWidth > 0.01 ? WordMode :
|
|
1953
|
-
if (
|
|
1954
|
-
row.
|
|
1967
|
+
mode = (letterSpacing || row.isOverflow) ? CharMode : (addWordWidth > 0.01 ? WordMode : TextMode);
|
|
1968
|
+
if (row.isOverflow && !letterSpacing)
|
|
1969
|
+
row.textMode = true;
|
|
1970
|
+
if (mode === TextMode) {
|
|
1955
1971
|
row.x += indentWidth;
|
|
1956
|
-
row
|
|
1957
|
-
word.data.forEach(char => {
|
|
1958
|
-
row.text += char.char;
|
|
1959
|
-
});
|
|
1960
|
-
});
|
|
1972
|
+
toTextChar$1(row);
|
|
1961
1973
|
}
|
|
1962
1974
|
else {
|
|
1963
1975
|
row.x += indentWidth;
|
|
@@ -1983,6 +1995,14 @@ function layoutChar(drawData, style, width, _height) {
|
|
|
1983
1995
|
}
|
|
1984
1996
|
});
|
|
1985
1997
|
}
|
|
1998
|
+
function toTextChar$1(row) {
|
|
1999
|
+
row.text = '';
|
|
2000
|
+
row.words.forEach(word => {
|
|
2001
|
+
word.data.forEach(char => {
|
|
2002
|
+
row.text += char.char;
|
|
2003
|
+
});
|
|
2004
|
+
});
|
|
2005
|
+
}
|
|
1986
2006
|
function toWordChar(data, charX, wordChar) {
|
|
1987
2007
|
data.forEach(char => {
|
|
1988
2008
|
wordChar.char += char.char;
|
|
@@ -2003,10 +2023,10 @@ function toChar(data, charX, rowData) {
|
|
|
2003
2023
|
|
|
2004
2024
|
function layoutText(drawData, style) {
|
|
2005
2025
|
const { rows, bounds } = drawData;
|
|
2006
|
-
const { __lineHeight, __baseLine, __letterSpacing, textAlign, verticalAlign, paraSpacing
|
|
2026
|
+
const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing } = style;
|
|
2007
2027
|
let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
|
|
2008
2028
|
let starY = __baseLine;
|
|
2009
|
-
if (
|
|
2029
|
+
if (__clipText && realHeight > height) {
|
|
2010
2030
|
realHeight = Math.max(height, __lineHeight);
|
|
2011
2031
|
drawData.overflow = rows.length;
|
|
2012
2032
|
}
|
|
@@ -2055,39 +2075,58 @@ function layoutText(drawData, style) {
|
|
|
2055
2075
|
bounds.x = rowX;
|
|
2056
2076
|
if (rowWidth > bounds.width)
|
|
2057
2077
|
bounds.width = rowWidth;
|
|
2078
|
+
if (__clipText && width && width < rowWidth) {
|
|
2079
|
+
row.isOverflow = true;
|
|
2080
|
+
if (!drawData.overflow)
|
|
2081
|
+
drawData.overflow = rows.length;
|
|
2082
|
+
}
|
|
2058
2083
|
}
|
|
2059
2084
|
bounds.y = y;
|
|
2060
2085
|
bounds.height = realHeight;
|
|
2061
2086
|
}
|
|
2062
2087
|
|
|
2063
|
-
function clipText(drawData,
|
|
2088
|
+
function clipText(drawData, style) {
|
|
2064
2089
|
const { rows, overflow } = drawData;
|
|
2090
|
+
let { textOverflow } = style;
|
|
2065
2091
|
rows.splice(overflow);
|
|
2066
2092
|
if (textOverflow !== 'hide') {
|
|
2067
2093
|
if (textOverflow === 'ellipsis')
|
|
2068
2094
|
textOverflow = '...';
|
|
2095
|
+
let char, charRight;
|
|
2069
2096
|
const ellipsisWidth = Platform.canvas.measureText(textOverflow).width;
|
|
2070
|
-
const
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2097
|
+
const right = style.x + style.width - ellipsisWidth;
|
|
2098
|
+
const list = style.textWrap === 'none' ? rows : [rows[overflow - 1]];
|
|
2099
|
+
list.forEach(row => {
|
|
2100
|
+
if (row.isOverflow && row.data) {
|
|
2101
|
+
let end = row.data.length - 1;
|
|
2102
|
+
for (let i = end; i > -1; i--) {
|
|
2103
|
+
char = row.data[i];
|
|
2104
|
+
charRight = char.x + char.width;
|
|
2105
|
+
if (i === end && charRight < right) {
|
|
2106
|
+
break;
|
|
2107
|
+
}
|
|
2108
|
+
else if (charRight < right && char.char !== ' ') {
|
|
2109
|
+
row.data.splice(i + 1);
|
|
2110
|
+
row.width -= char.width;
|
|
2111
|
+
break;
|
|
2112
|
+
}
|
|
2113
|
+
row.width -= char.width;
|
|
2114
|
+
}
|
|
2115
|
+
row.width += ellipsisWidth;
|
|
2116
|
+
row.data.push({ char: textOverflow, x: charRight });
|
|
2117
|
+
if (row.textMode)
|
|
2118
|
+
toTextChar(row);
|
|
2084
2119
|
}
|
|
2085
|
-
|
|
2086
|
-
}
|
|
2087
|
-
row.width += ellipsisWidth;
|
|
2088
|
-
row.data.push({ char: textOverflow, x: charRight });
|
|
2120
|
+
});
|
|
2089
2121
|
}
|
|
2090
2122
|
}
|
|
2123
|
+
function toTextChar(row) {
|
|
2124
|
+
row.text = '';
|
|
2125
|
+
row.data.forEach(char => {
|
|
2126
|
+
row.text += char.char;
|
|
2127
|
+
});
|
|
2128
|
+
row.data = null;
|
|
2129
|
+
}
|
|
2091
2130
|
|
|
2092
2131
|
function decorationText(drawData, style) {
|
|
2093
2132
|
const { fontSize } = style;
|
|
@@ -2108,7 +2147,7 @@ const TextConvert = {
|
|
|
2108
2147
|
let x = 0, y = 0;
|
|
2109
2148
|
let width = style.__getInput('width') || 0;
|
|
2110
2149
|
let height = style.__getInput('height') || 0;
|
|
2111
|
-
const { textDecoration,
|
|
2150
|
+
const { textDecoration, __font, padding } = style;
|
|
2112
2151
|
if (padding) {
|
|
2113
2152
|
const [top, right, bottom, left] = MathHelper.fourNumber(padding);
|
|
2114
2153
|
if (width) {
|
|
@@ -2130,7 +2169,7 @@ const TextConvert = {
|
|
|
2130
2169
|
layoutText(drawData, style);
|
|
2131
2170
|
layoutChar(drawData, style, width);
|
|
2132
2171
|
if (drawData.overflow)
|
|
2133
|
-
clipText(drawData,
|
|
2172
|
+
clipText(drawData, style);
|
|
2134
2173
|
if (textDecoration !== 'none')
|
|
2135
2174
|
decorationText(drawData, style);
|
|
2136
2175
|
return drawData;
|