@leafer-ui/node 1.0.0-rc.5 → 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/node.cjs +209 -168
- package/dist/node.esm.js +210 -169
- package/dist/node.esm.min.js +1 -1
- package/dist/node.min.cjs +1 -1
- package/package.json +8 -7
package/dist/node.cjs
CHANGED
|
@@ -1,8 +1,41 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var core = require('@leafer/core');
|
|
4
|
+
var fs = require('fs');
|
|
4
5
|
var core$1 = require('@leafer-ui/core');
|
|
5
6
|
|
|
7
|
+
/******************************************************************************
|
|
8
|
+
Copyright (c) Microsoft Corporation.
|
|
9
|
+
|
|
10
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
+
purpose with or without fee is hereby granted.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
+
***************************************************************************** */
|
|
21
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
25
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
26
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
27
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
28
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
29
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
30
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
35
|
+
var e = new Error(message);
|
|
36
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
37
|
+
};
|
|
38
|
+
|
|
6
39
|
class Watcher {
|
|
7
40
|
get childrenChanged() { return this.hasAdd || this.hasRemove || this.hasVisible; }
|
|
8
41
|
get updatedList() {
|
|
@@ -557,7 +590,7 @@ class Renderer {
|
|
|
557
590
|
}
|
|
558
591
|
|
|
559
592
|
const { hitRadiusPoint } = core.BoundsHelper;
|
|
560
|
-
class
|
|
593
|
+
class Pather {
|
|
561
594
|
constructor(target, selector) {
|
|
562
595
|
this.target = target;
|
|
563
596
|
this.selector = selector;
|
|
@@ -677,117 +710,108 @@ class FindPath {
|
|
|
677
710
|
class Selector {
|
|
678
711
|
constructor(target, userConfig) {
|
|
679
712
|
this.config = {};
|
|
680
|
-
this.
|
|
681
|
-
this.
|
|
682
|
-
this.
|
|
683
|
-
|
|
713
|
+
this.innerIdMap = {};
|
|
714
|
+
this.idMap = {};
|
|
715
|
+
this.methods = {
|
|
716
|
+
id: (leaf, name) => leaf.id === name ? this.idMap[name] = leaf : 0,
|
|
717
|
+
innerId: (leaf, innerId) => leaf.innerId === innerId ? this.innerIdMap[innerId] = leaf : 0,
|
|
718
|
+
className: (leaf, name) => leaf.className === name ? 1 : 0,
|
|
719
|
+
tag: (leaf, name) => leaf.__tag === name ? 1 : 0
|
|
720
|
+
};
|
|
684
721
|
this.target = target;
|
|
685
722
|
if (userConfig)
|
|
686
723
|
this.config = core.DataHelper.default(userConfig, this.config);
|
|
687
|
-
this.
|
|
724
|
+
this.pather = new Pather(target, this);
|
|
688
725
|
this.__listenEvents();
|
|
689
726
|
}
|
|
690
727
|
getByPoint(hitPoint, hitRadius, options) {
|
|
691
728
|
if (core.Platform.name === 'node')
|
|
692
729
|
this.target.emit(core.LayoutEvent.CHECK_UPDATE);
|
|
693
|
-
return this.
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
730
|
+
return this.pather.getByPoint(hitPoint, hitRadius, options);
|
|
731
|
+
}
|
|
732
|
+
getBy(condition, branch, one, options) {
|
|
733
|
+
switch (typeof condition) {
|
|
734
|
+
case 'number':
|
|
735
|
+
const leaf = this.getByInnerId(condition, branch);
|
|
736
|
+
return one ? leaf : (leaf ? [leaf] : []);
|
|
737
|
+
case 'string':
|
|
738
|
+
switch (condition[0]) {
|
|
739
|
+
case '#':
|
|
740
|
+
const leaf = this.getById(condition.substring(1), branch);
|
|
741
|
+
return one ? leaf : (leaf ? [leaf] : []);
|
|
742
|
+
case '.':
|
|
743
|
+
return this.getByMethod(this.methods.className, branch, one, condition.substring(1));
|
|
744
|
+
default:
|
|
745
|
+
return this.getByMethod(this.methods.tag, branch, one, condition);
|
|
746
|
+
}
|
|
747
|
+
case 'function':
|
|
748
|
+
return this.getByMethod(condition, branch, one, options);
|
|
707
749
|
}
|
|
708
750
|
}
|
|
709
|
-
getByInnerId(
|
|
710
|
-
|
|
751
|
+
getByInnerId(innerId, branch) {
|
|
752
|
+
const cache = this.innerIdMap[innerId];
|
|
711
753
|
if (cache)
|
|
712
754
|
return cache;
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
let find;
|
|
716
|
-
this.loopFind(branch, (leaf) => {
|
|
717
|
-
if (leaf.innerId === name) {
|
|
718
|
-
find = leaf;
|
|
719
|
-
this.innerIdList[name] = find;
|
|
720
|
-
return true;
|
|
721
|
-
}
|
|
722
|
-
else {
|
|
723
|
-
return false;
|
|
724
|
-
}
|
|
725
|
-
});
|
|
726
|
-
return find;
|
|
755
|
+
this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId);
|
|
756
|
+
return this.findLeaf;
|
|
727
757
|
}
|
|
728
|
-
getById(
|
|
729
|
-
|
|
730
|
-
if (cache)
|
|
758
|
+
getById(id, branch) {
|
|
759
|
+
const cache = this.idMap[id];
|
|
760
|
+
if (cache && core.LeafHelper.hasParent(cache, branch || this.target))
|
|
731
761
|
return cache;
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
let find;
|
|
735
|
-
this.loopFind(branch, (leaf) => {
|
|
736
|
-
if (leaf.id === name) {
|
|
737
|
-
find = leaf;
|
|
738
|
-
this.idList[name] = find;
|
|
739
|
-
return true;
|
|
740
|
-
}
|
|
741
|
-
else {
|
|
742
|
-
return false;
|
|
743
|
-
}
|
|
744
|
-
});
|
|
745
|
-
return find;
|
|
746
|
-
}
|
|
747
|
-
getByClassName(name, branch) {
|
|
748
|
-
if (!branch)
|
|
749
|
-
branch = this.target;
|
|
750
|
-
let find = [];
|
|
751
|
-
this.loopFind(branch, (leaf) => {
|
|
752
|
-
if (leaf.className === name)
|
|
753
|
-
find.push(leaf);
|
|
754
|
-
return false;
|
|
755
|
-
});
|
|
756
|
-
return find;
|
|
757
|
-
}
|
|
758
|
-
getByTagName(name, branch) {
|
|
759
|
-
if (!branch)
|
|
760
|
-
branch = this.target;
|
|
761
|
-
let find = [];
|
|
762
|
-
this.loopFind(branch, (leaf) => {
|
|
763
|
-
if (leaf.__tag === name)
|
|
764
|
-
find.push(leaf);
|
|
765
|
-
return false;
|
|
766
|
-
});
|
|
767
|
-
return find;
|
|
762
|
+
this.eachFind(this.toChildren(branch), this.methods.id, null, id);
|
|
763
|
+
return this.findLeaf;
|
|
768
764
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
765
|
+
getByClassName(className, branch) {
|
|
766
|
+
return this.getByMethod(this.methods.className, branch, false, className);
|
|
767
|
+
}
|
|
768
|
+
getByTag(tag, branch) {
|
|
769
|
+
return this.getByMethod(this.methods.tag, branch, false, tag);
|
|
770
|
+
}
|
|
771
|
+
getByMethod(method, branch, one, options) {
|
|
772
|
+
const list = one ? null : [];
|
|
773
|
+
this.eachFind(this.toChildren(branch), method, list, options);
|
|
774
|
+
return list || this.findLeaf;
|
|
775
|
+
}
|
|
776
|
+
eachFind(children, method, list, options) {
|
|
777
|
+
let child;
|
|
773
778
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
774
|
-
|
|
775
|
-
if (
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
+
child = children[i];
|
|
780
|
+
if (method(child, options)) {
|
|
781
|
+
if (list) {
|
|
782
|
+
list.push(child);
|
|
783
|
+
}
|
|
784
|
+
else {
|
|
785
|
+
this.findLeaf = child;
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
if (child.isBranch)
|
|
790
|
+
this.eachFind(child.children, method, list, options);
|
|
779
791
|
}
|
|
780
792
|
}
|
|
793
|
+
toChildren(branch) {
|
|
794
|
+
this.findLeaf = null;
|
|
795
|
+
return [branch || this.target];
|
|
796
|
+
}
|
|
781
797
|
__onRemoveChild(event) {
|
|
782
|
-
const
|
|
783
|
-
if (this.
|
|
784
|
-
this.
|
|
785
|
-
if (this.
|
|
786
|
-
this.
|
|
798
|
+
const { id, innerId } = event.child;
|
|
799
|
+
if (this.idMap[id])
|
|
800
|
+
delete this.idMap[id];
|
|
801
|
+
if (this.innerIdMap[innerId])
|
|
802
|
+
delete this.innerIdMap[innerId];
|
|
803
|
+
}
|
|
804
|
+
__checkIdChange(event) {
|
|
805
|
+
if (event.attrName === 'id') {
|
|
806
|
+
const id = event.oldValue;
|
|
807
|
+
if (this.idMap[id])
|
|
808
|
+
delete this.idMap[id];
|
|
809
|
+
}
|
|
787
810
|
}
|
|
788
811
|
__listenEvents() {
|
|
789
812
|
this.__eventIds = [
|
|
790
|
-
this.target.on_(core.ChildEvent.REMOVE, this.__onRemoveChild, this)
|
|
813
|
+
this.target.on_(core.ChildEvent.REMOVE, this.__onRemoveChild, this),
|
|
814
|
+
this.target.on_(core.PropertyEvent.CHANGE, this.__checkIdChange, this)
|
|
791
815
|
];
|
|
792
816
|
}
|
|
793
817
|
__removeListenEvents() {
|
|
@@ -797,11 +821,10 @@ class Selector {
|
|
|
797
821
|
destroy() {
|
|
798
822
|
if (this.__eventIds.length) {
|
|
799
823
|
this.__removeListenEvents();
|
|
800
|
-
this.
|
|
801
|
-
this.
|
|
802
|
-
this.
|
|
803
|
-
this.
|
|
804
|
-
this.tagNameList = {};
|
|
824
|
+
this.pather.destroy();
|
|
825
|
+
this.findLeaf = null;
|
|
826
|
+
this.innerIdMap = {};
|
|
827
|
+
this.idMap = {};
|
|
805
828
|
}
|
|
806
829
|
}
|
|
807
830
|
}
|
|
@@ -820,8 +843,10 @@ class LeaferCanvas extends core.LeaferCanvasBase {
|
|
|
820
843
|
this.__createView();
|
|
821
844
|
this.__createContext();
|
|
822
845
|
this.resize(this.config);
|
|
823
|
-
|
|
824
|
-
|
|
846
|
+
if (core.Platform.roundRectPatch) {
|
|
847
|
+
this.context.__proto__.roundRect = null;
|
|
848
|
+
core.canvasPatch(this.context.__proto__);
|
|
849
|
+
}
|
|
825
850
|
}
|
|
826
851
|
__createView() {
|
|
827
852
|
this.view = core.Platform.origin.createCanvas(1, 1);
|
|
@@ -834,6 +859,7 @@ class LeaferCanvas extends core.LeaferCanvasBase {
|
|
|
834
859
|
}
|
|
835
860
|
}
|
|
836
861
|
|
|
862
|
+
const { mineType, fileType } = core.FileHelper;
|
|
837
863
|
Object.assign(core.Creator, {
|
|
838
864
|
canvas: (options, manager) => new LeaferCanvas(options, manager),
|
|
839
865
|
image: (options) => new core.LeaferImage(options),
|
|
@@ -841,6 +867,7 @@ Object.assign(core.Creator, {
|
|
|
841
867
|
interaction: (target, canvas, selector, options) => { return new core.InteractionBase(target, canvas, selector, options); }
|
|
842
868
|
});
|
|
843
869
|
function useCanvas(canvasType, power) {
|
|
870
|
+
core.Platform.canvasType = canvasType;
|
|
844
871
|
if (!core.Platform.origin) {
|
|
845
872
|
if (canvasType === 'skia') {
|
|
846
873
|
const { Canvas, loadImage } = power;
|
|
@@ -851,7 +878,19 @@ function useCanvas(canvasType, power) {
|
|
|
851
878
|
canvasSaveAs: (canvas, filename, quality) => canvas.saveAs(filename, { quality }),
|
|
852
879
|
loadImage
|
|
853
880
|
};
|
|
881
|
+
core.Platform.roundRectPatch = true;
|
|
882
|
+
}
|
|
883
|
+
else if (canvasType === 'napi') {
|
|
884
|
+
const { Canvas, loadImage } = power;
|
|
885
|
+
core.Platform.origin = {
|
|
886
|
+
createCanvas: (width, height, format) => new Canvas(width, height, format),
|
|
887
|
+
canvasToDataURL: (canvas, type, quality) => canvas.toDataURL(mineType(type), quality),
|
|
888
|
+
canvasToBolb: (canvas, type, quality) => __awaiter(this, void 0, void 0, function* () { return canvas.toBuffer(mineType(type), quality); }),
|
|
889
|
+
canvasSaveAs: (canvas, filename, quality) => __awaiter(this, void 0, void 0, function* () { return fs.writeFileSync(filename, canvas.toBuffer(mineType(fileType(filename)), quality)); }),
|
|
890
|
+
loadImage
|
|
891
|
+
};
|
|
854
892
|
}
|
|
893
|
+
core.Platform.ellipseToCurve = true;
|
|
855
894
|
core.Platform.event = {
|
|
856
895
|
stopDefault(_origin) { },
|
|
857
896
|
stopNow(_origin) { },
|
|
@@ -1012,38 +1051,6 @@ function emit(type, data) {
|
|
|
1012
1051
|
data.target.emitEvent(new core.ImageEvent(type, data));
|
|
1013
1052
|
}
|
|
1014
1053
|
|
|
1015
|
-
/******************************************************************************
|
|
1016
|
-
Copyright (c) Microsoft Corporation.
|
|
1017
|
-
|
|
1018
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
1019
|
-
purpose with or without fee is hereby granted.
|
|
1020
|
-
|
|
1021
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
1022
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
1023
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
1024
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
1025
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
1026
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
1027
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
1028
|
-
***************************************************************************** */
|
|
1029
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
1033
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
1034
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
1035
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
1036
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
1037
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
1038
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1039
|
-
});
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
1043
|
-
var e = new Error(message);
|
|
1044
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
1045
|
-
};
|
|
1046
|
-
|
|
1047
1054
|
const { get: get$2, scale: scaleHelper, copy: copy$1 } = core.MatrixHelper;
|
|
1048
1055
|
function createPattern(ui, paint, pixelRatio) {
|
|
1049
1056
|
let { scaleX, scaleY } = ui.__world;
|
|
@@ -1145,8 +1152,9 @@ function checkImage(ui, canvas, paint, allowPaint) {
|
|
|
1145
1152
|
if (!paint.patternTask) {
|
|
1146
1153
|
paint.patternTask = core.ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function* () {
|
|
1147
1154
|
paint.patternTask = null;
|
|
1148
|
-
if (canvas.bounds.hit(ui.__world)
|
|
1149
|
-
ui.
|
|
1155
|
+
if (canvas.bounds.hit(ui.__world))
|
|
1156
|
+
createPattern(ui, paint, canvas.pixelRatio);
|
|
1157
|
+
ui.forceUpdate('surface');
|
|
1150
1158
|
}), 300);
|
|
1151
1159
|
}
|
|
1152
1160
|
}
|
|
@@ -1810,6 +1818,8 @@ function createRows(drawData, content, style) {
|
|
|
1810
1818
|
const { width, height } = bounds;
|
|
1811
1819
|
const charMode = width || height || __letterSpacing || (textCase !== 'none');
|
|
1812
1820
|
if (charMode) {
|
|
1821
|
+
const wrap = style.textWrap !== 'none';
|
|
1822
|
+
const breakAll = style.textWrap === 'break';
|
|
1813
1823
|
paraStart = true;
|
|
1814
1824
|
lastCharType = null;
|
|
1815
1825
|
startCharSize = charWidth = charSize = wordWidth = rowWidth = 0;
|
|
@@ -1836,16 +1846,23 @@ function createRows(drawData, content, style) {
|
|
|
1836
1846
|
langBreak = (charType === Single && (lastCharType === Single || lastCharType === Letter)) || (lastCharType === Single && charType !== After);
|
|
1837
1847
|
afterBreak = ((charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After));
|
|
1838
1848
|
realWidth = paraStart && paraIndent ? width - paraIndent : width;
|
|
1839
|
-
if (width && rowWidth + wordWidth + charWidth > realWidth) {
|
|
1840
|
-
if (
|
|
1841
|
-
afterBreak = charType === Letter && lastCharType == After;
|
|
1842
|
-
if (langBreak || afterBreak || charType === Break || charType === Before || charType === Single || (wordWidth + charWidth > realWidth)) {
|
|
1849
|
+
if (wrap && (width && rowWidth + wordWidth + charWidth > realWidth)) {
|
|
1850
|
+
if (breakAll) {
|
|
1843
1851
|
if (wordWidth)
|
|
1844
1852
|
addWord();
|
|
1845
1853
|
addRow();
|
|
1846
1854
|
}
|
|
1847
1855
|
else {
|
|
1848
|
-
|
|
1856
|
+
if (!afterBreak)
|
|
1857
|
+
afterBreak = charType === Letter && lastCharType == After;
|
|
1858
|
+
if (langBreak || afterBreak || charType === Break || charType === Before || charType === Single || (wordWidth + charWidth > realWidth)) {
|
|
1859
|
+
if (wordWidth)
|
|
1860
|
+
addWord();
|
|
1861
|
+
addRow();
|
|
1862
|
+
}
|
|
1863
|
+
else {
|
|
1864
|
+
addRow();
|
|
1865
|
+
}
|
|
1849
1866
|
}
|
|
1850
1867
|
}
|
|
1851
1868
|
if (char === ' ' && paraStart !== true && (rowWidth + wordWidth) === 0) ;
|
|
@@ -1915,7 +1932,7 @@ function addRow() {
|
|
|
1915
1932
|
|
|
1916
1933
|
const CharMode = 0;
|
|
1917
1934
|
const WordMode = 1;
|
|
1918
|
-
const
|
|
1935
|
+
const TextMode = 2;
|
|
1919
1936
|
function layoutChar(drawData, style, width, _height) {
|
|
1920
1937
|
const { rows } = drawData;
|
|
1921
1938
|
const { textAlign, paraIndent, letterSpacing } = style;
|
|
@@ -1924,15 +1941,12 @@ function layoutChar(drawData, style, width, _height) {
|
|
|
1924
1941
|
if (row.words) {
|
|
1925
1942
|
indentWidth = paraIndent && row.paraStart ? paraIndent : 0;
|
|
1926
1943
|
addWordWidth = (width && textAlign === 'justify' && row.words.length > 1) ? (width - row.width - indentWidth) / (row.words.length - 1) : 0;
|
|
1927
|
-
mode = (letterSpacing || row.isOverflow) ? CharMode : (addWordWidth > 0.01 ? WordMode :
|
|
1928
|
-
if (
|
|
1929
|
-
row.
|
|
1944
|
+
mode = (letterSpacing || row.isOverflow) ? CharMode : (addWordWidth > 0.01 ? WordMode : TextMode);
|
|
1945
|
+
if (row.isOverflow && !letterSpacing)
|
|
1946
|
+
row.textMode = true;
|
|
1947
|
+
if (mode === TextMode) {
|
|
1930
1948
|
row.x += indentWidth;
|
|
1931
|
-
row
|
|
1932
|
-
word.data.forEach(char => {
|
|
1933
|
-
row.text += char.char;
|
|
1934
|
-
});
|
|
1935
|
-
});
|
|
1949
|
+
toTextChar$1(row);
|
|
1936
1950
|
}
|
|
1937
1951
|
else {
|
|
1938
1952
|
row.x += indentWidth;
|
|
@@ -1958,6 +1972,14 @@ function layoutChar(drawData, style, width, _height) {
|
|
|
1958
1972
|
}
|
|
1959
1973
|
});
|
|
1960
1974
|
}
|
|
1975
|
+
function toTextChar$1(row) {
|
|
1976
|
+
row.text = '';
|
|
1977
|
+
row.words.forEach(word => {
|
|
1978
|
+
word.data.forEach(char => {
|
|
1979
|
+
row.text += char.char;
|
|
1980
|
+
});
|
|
1981
|
+
});
|
|
1982
|
+
}
|
|
1961
1983
|
function toWordChar(data, charX, wordChar) {
|
|
1962
1984
|
data.forEach(char => {
|
|
1963
1985
|
wordChar.char += char.char;
|
|
@@ -1978,10 +2000,10 @@ function toChar(data, charX, rowData) {
|
|
|
1978
2000
|
|
|
1979
2001
|
function layoutText(drawData, style) {
|
|
1980
2002
|
const { rows, bounds } = drawData;
|
|
1981
|
-
const { __lineHeight, __baseLine, __letterSpacing, textAlign, verticalAlign, paraSpacing
|
|
2003
|
+
const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing } = style;
|
|
1982
2004
|
let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
|
|
1983
2005
|
let starY = __baseLine;
|
|
1984
|
-
if (
|
|
2006
|
+
if (__clipText && realHeight > height) {
|
|
1985
2007
|
realHeight = Math.max(height, __lineHeight);
|
|
1986
2008
|
drawData.overflow = rows.length;
|
|
1987
2009
|
}
|
|
@@ -2030,39 +2052,58 @@ function layoutText(drawData, style) {
|
|
|
2030
2052
|
bounds.x = rowX;
|
|
2031
2053
|
if (rowWidth > bounds.width)
|
|
2032
2054
|
bounds.width = rowWidth;
|
|
2055
|
+
if (__clipText && width && width < rowWidth) {
|
|
2056
|
+
row.isOverflow = true;
|
|
2057
|
+
if (!drawData.overflow)
|
|
2058
|
+
drawData.overflow = rows.length;
|
|
2059
|
+
}
|
|
2033
2060
|
}
|
|
2034
2061
|
bounds.y = y;
|
|
2035
2062
|
bounds.height = realHeight;
|
|
2036
2063
|
}
|
|
2037
2064
|
|
|
2038
|
-
function clipText(drawData,
|
|
2065
|
+
function clipText(drawData, style) {
|
|
2039
2066
|
const { rows, overflow } = drawData;
|
|
2067
|
+
let { textOverflow } = style;
|
|
2040
2068
|
rows.splice(overflow);
|
|
2041
2069
|
if (textOverflow !== 'hide') {
|
|
2042
2070
|
if (textOverflow === 'ellipsis')
|
|
2043
2071
|
textOverflow = '...';
|
|
2072
|
+
let char, charRight;
|
|
2044
2073
|
const ellipsisWidth = core.Platform.canvas.measureText(textOverflow).width;
|
|
2045
|
-
const
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2074
|
+
const right = style.x + style.width - ellipsisWidth;
|
|
2075
|
+
const list = style.textWrap === 'none' ? rows : [rows[overflow - 1]];
|
|
2076
|
+
list.forEach(row => {
|
|
2077
|
+
if (row.isOverflow && row.data) {
|
|
2078
|
+
let end = row.data.length - 1;
|
|
2079
|
+
for (let i = end; i > -1; i--) {
|
|
2080
|
+
char = row.data[i];
|
|
2081
|
+
charRight = char.x + char.width;
|
|
2082
|
+
if (i === end && charRight < right) {
|
|
2083
|
+
break;
|
|
2084
|
+
}
|
|
2085
|
+
else if (charRight < right && char.char !== ' ') {
|
|
2086
|
+
row.data.splice(i + 1);
|
|
2087
|
+
row.width -= char.width;
|
|
2088
|
+
break;
|
|
2089
|
+
}
|
|
2090
|
+
row.width -= char.width;
|
|
2091
|
+
}
|
|
2092
|
+
row.width += ellipsisWidth;
|
|
2093
|
+
row.data.push({ char: textOverflow, x: charRight });
|
|
2094
|
+
if (row.textMode)
|
|
2095
|
+
toTextChar(row);
|
|
2059
2096
|
}
|
|
2060
|
-
|
|
2061
|
-
}
|
|
2062
|
-
row.width += ellipsisWidth;
|
|
2063
|
-
row.data.push({ char: textOverflow, x: charRight });
|
|
2097
|
+
});
|
|
2064
2098
|
}
|
|
2065
2099
|
}
|
|
2100
|
+
function toTextChar(row) {
|
|
2101
|
+
row.text = '';
|
|
2102
|
+
row.data.forEach(char => {
|
|
2103
|
+
row.text += char.char;
|
|
2104
|
+
});
|
|
2105
|
+
row.data = null;
|
|
2106
|
+
}
|
|
2066
2107
|
|
|
2067
2108
|
function decorationText(drawData, style) {
|
|
2068
2109
|
const { fontSize } = style;
|
|
@@ -2083,7 +2124,7 @@ const TextConvert = {
|
|
|
2083
2124
|
let x = 0, y = 0;
|
|
2084
2125
|
let width = style.__getInput('width') || 0;
|
|
2085
2126
|
let height = style.__getInput('height') || 0;
|
|
2086
|
-
const { textDecoration,
|
|
2127
|
+
const { textDecoration, __font, padding } = style;
|
|
2087
2128
|
if (padding) {
|
|
2088
2129
|
const [top, right, bottom, left] = core.MathHelper.fourNumber(padding);
|
|
2089
2130
|
if (width) {
|
|
@@ -2105,7 +2146,7 @@ const TextConvert = {
|
|
|
2105
2146
|
layoutText(drawData, style);
|
|
2106
2147
|
layoutChar(drawData, style, width);
|
|
2107
2148
|
if (drawData.overflow)
|
|
2108
|
-
clipText(drawData,
|
|
2149
|
+
clipText(drawData, style);
|
|
2109
2150
|
if (textDecoration !== 'none')
|
|
2110
2151
|
decorationText(drawData, style);
|
|
2111
2152
|
return drawData;
|