@leafer-ui/node 1.0.0-rc.5 → 1.0.0-rc.7
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 +330 -247
- package/dist/node.esm.js +333 -250
- 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,15 +1,48 @@
|
|
|
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() {
|
|
9
42
|
if (this.hasRemove) {
|
|
10
43
|
const updatedList = new core.LeafList();
|
|
11
44
|
this.__updatedList.list.forEach(item => { if (item.leafer)
|
|
12
|
-
updatedList.
|
|
45
|
+
updatedList.add(item); });
|
|
13
46
|
return updatedList;
|
|
14
47
|
}
|
|
15
48
|
else {
|
|
@@ -44,7 +77,7 @@ class Watcher {
|
|
|
44
77
|
this.target.emit(core.RenderEvent.REQUEST);
|
|
45
78
|
}
|
|
46
79
|
__onAttrChange(event) {
|
|
47
|
-
this.__updatedList.
|
|
80
|
+
this.__updatedList.add(event.target);
|
|
48
81
|
this.update();
|
|
49
82
|
}
|
|
50
83
|
__onChildEvent(event) {
|
|
@@ -54,12 +87,12 @@ class Watcher {
|
|
|
54
87
|
}
|
|
55
88
|
else {
|
|
56
89
|
this.hasRemove = true;
|
|
57
|
-
this.__updatedList.
|
|
90
|
+
this.__updatedList.add(event.parent);
|
|
58
91
|
}
|
|
59
92
|
this.update();
|
|
60
93
|
}
|
|
61
94
|
__pushChild(child) {
|
|
62
|
-
this.__updatedList.
|
|
95
|
+
this.__updatedList.add(child);
|
|
63
96
|
if (child.isBranch)
|
|
64
97
|
this.__loopChildren(child);
|
|
65
98
|
}
|
|
@@ -98,7 +131,7 @@ class Watcher {
|
|
|
98
131
|
}
|
|
99
132
|
}
|
|
100
133
|
|
|
101
|
-
const {
|
|
134
|
+
const { updateAllMatrix: updateAllMatrix$1, updateBounds: updateOneBounds, updateAllWorldOpacity } = core.LeafHelper;
|
|
102
135
|
const { pushAllChildBranch, pushAllParent } = core.BranchHelper;
|
|
103
136
|
function updateMatrix(updateList, levelList) {
|
|
104
137
|
let layout;
|
|
@@ -106,14 +139,14 @@ function updateMatrix(updateList, levelList) {
|
|
|
106
139
|
layout = leaf.__layout;
|
|
107
140
|
if (levelList.without(leaf) && !layout.proxyZoom) {
|
|
108
141
|
if (layout.matrixChanged) {
|
|
109
|
-
|
|
110
|
-
levelList.
|
|
142
|
+
updateAllMatrix$1(leaf, true);
|
|
143
|
+
levelList.add(leaf);
|
|
111
144
|
if (leaf.isBranch)
|
|
112
145
|
pushAllChildBranch(leaf, levelList);
|
|
113
146
|
pushAllParent(leaf, levelList);
|
|
114
147
|
}
|
|
115
148
|
else if (layout.boundsChanged) {
|
|
116
|
-
levelList.
|
|
149
|
+
levelList.add(leaf);
|
|
117
150
|
if (leaf.isBranch)
|
|
118
151
|
leaf.__tempNumber = 0;
|
|
119
152
|
pushAllParent(leaf, levelList);
|
|
@@ -122,20 +155,21 @@ function updateMatrix(updateList, levelList) {
|
|
|
122
155
|
});
|
|
123
156
|
}
|
|
124
157
|
function updateBounds(boundsList) {
|
|
125
|
-
let
|
|
158
|
+
let list, branch, children;
|
|
126
159
|
boundsList.sort(true);
|
|
127
160
|
boundsList.levels.forEach(level => {
|
|
128
|
-
|
|
129
|
-
for (let i = 0, len =
|
|
130
|
-
branch =
|
|
161
|
+
list = boundsList.levelMap[level];
|
|
162
|
+
for (let i = 0, len = list.length; i < len; i++) {
|
|
163
|
+
branch = list[i];
|
|
131
164
|
if (branch.isBranch && branch.__tempNumber) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
165
|
+
children = branch.children;
|
|
166
|
+
for (let j = 0, jLen = children.length; j < jLen; j++) {
|
|
167
|
+
if (!children[j].isBranch) {
|
|
168
|
+
updateOneBounds(children[j]);
|
|
135
169
|
}
|
|
136
170
|
}
|
|
137
171
|
}
|
|
138
|
-
branch
|
|
172
|
+
updateOneBounds(branch);
|
|
139
173
|
}
|
|
140
174
|
});
|
|
141
175
|
}
|
|
@@ -148,7 +182,7 @@ function updateChange(updateList) {
|
|
|
148
182
|
}
|
|
149
183
|
|
|
150
184
|
const { worldBounds } = core.LeafBoundsHelper;
|
|
151
|
-
const {
|
|
185
|
+
const bigBounds = { x: 0, y: 0, width: 100000, height: 100000 };
|
|
152
186
|
class LayoutBlockData {
|
|
153
187
|
constructor(list) {
|
|
154
188
|
this.updatedBounds = new core.Bounds();
|
|
@@ -159,14 +193,20 @@ class LayoutBlockData {
|
|
|
159
193
|
this.updatedList = list;
|
|
160
194
|
}
|
|
161
195
|
setBefore() {
|
|
162
|
-
|
|
196
|
+
this.beforeBounds.setListWithFn(this.updatedList.list, worldBounds);
|
|
163
197
|
}
|
|
164
198
|
setAfter() {
|
|
165
|
-
|
|
166
|
-
|
|
199
|
+
const { list } = this.updatedList;
|
|
200
|
+
if (list.some(leaf => leaf.noBounds)) {
|
|
201
|
+
this.afterBounds.set(bigBounds);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
this.afterBounds.setListWithFn(list, worldBounds);
|
|
205
|
+
}
|
|
206
|
+
this.updatedBounds.setList([this.beforeBounds, this.afterBounds]);
|
|
167
207
|
}
|
|
168
208
|
merge(data) {
|
|
169
|
-
this.updatedList.
|
|
209
|
+
this.updatedList.addList(data.updatedList.list);
|
|
170
210
|
this.beforeBounds.add(data.beforeBounds);
|
|
171
211
|
this.afterBounds.add(data.afterBounds);
|
|
172
212
|
this.updatedBounds.add(data.updatedBounds);
|
|
@@ -176,8 +216,7 @@ class LayoutBlockData {
|
|
|
176
216
|
}
|
|
177
217
|
}
|
|
178
218
|
|
|
179
|
-
const {
|
|
180
|
-
const { pushAllBranchStack, updateWorldBoundsByBranchStack } = core.BranchHelper;
|
|
219
|
+
const { updateAllMatrix, updateAllChange } = core.LeafHelper;
|
|
181
220
|
const debug$1 = core.Debug.get('Layouter');
|
|
182
221
|
class Layouter {
|
|
183
222
|
constructor(target, userConfig) {
|
|
@@ -254,12 +293,15 @@ class Layouter {
|
|
|
254
293
|
const { target, __updatedList: updateList } = this;
|
|
255
294
|
const { BEFORE, LAYOUT, AFTER } = core.LayoutEvent;
|
|
256
295
|
const blocks = this.getBlocks(updateList);
|
|
257
|
-
blocks.forEach(item =>
|
|
296
|
+
blocks.forEach(item => item.setBefore());
|
|
258
297
|
target.emitEvent(new core.LayoutEvent(BEFORE, blocks, this.times));
|
|
298
|
+
this.extraBlock = null;
|
|
259
299
|
updateList.sort();
|
|
260
300
|
updateMatrix(updateList, this.__levelList);
|
|
261
301
|
updateBounds(this.__levelList);
|
|
262
302
|
updateChange(updateList);
|
|
303
|
+
if (this.extraBlock)
|
|
304
|
+
blocks.push(this.extraBlock);
|
|
263
305
|
blocks.forEach(item => item.setAfter());
|
|
264
306
|
target.emitEvent(new core.LayoutEvent(LAYOUT, blocks, this.times));
|
|
265
307
|
target.emitEvent(new core.LayoutEvent(AFTER, blocks, this.times));
|
|
@@ -282,17 +324,20 @@ class Layouter {
|
|
|
282
324
|
core.Run.end(t);
|
|
283
325
|
}
|
|
284
326
|
static fullLayout(target) {
|
|
285
|
-
|
|
327
|
+
updateAllMatrix(target, true);
|
|
286
328
|
if (target.isBranch) {
|
|
287
|
-
|
|
288
|
-
pushAllBranchStack(target, branchStack);
|
|
289
|
-
updateWorldBoundsByBranchStack(branchStack);
|
|
329
|
+
core.BranchHelper.updateBounds(target);
|
|
290
330
|
}
|
|
291
331
|
else {
|
|
292
|
-
|
|
332
|
+
core.LeafHelper.updateBounds(target);
|
|
293
333
|
}
|
|
294
334
|
updateAllChange(target);
|
|
295
335
|
}
|
|
336
|
+
addExtra(leaf) {
|
|
337
|
+
const block = this.extraBlock || (this.extraBlock = new LayoutBlockData([]));
|
|
338
|
+
block.updatedList.add(leaf);
|
|
339
|
+
block.beforeBounds.add(leaf.__world);
|
|
340
|
+
}
|
|
296
341
|
createBlock(data) {
|
|
297
342
|
return new LayoutBlockData(data);
|
|
298
343
|
}
|
|
@@ -320,8 +365,7 @@ class Layouter {
|
|
|
320
365
|
if (this.target) {
|
|
321
366
|
this.stop();
|
|
322
367
|
this.__removeListenEvents();
|
|
323
|
-
this.target = null;
|
|
324
|
-
this.config = null;
|
|
368
|
+
this.target = this.config = null;
|
|
325
369
|
}
|
|
326
370
|
}
|
|
327
371
|
}
|
|
@@ -432,7 +476,7 @@ class Renderer {
|
|
|
432
476
|
const { canvas } = this;
|
|
433
477
|
const bounds = block.getIntersect(canvas.bounds);
|
|
434
478
|
const includes = block.includes(this.target.__world);
|
|
435
|
-
const realBounds = new core.Bounds(
|
|
479
|
+
const realBounds = new core.Bounds(bounds);
|
|
436
480
|
canvas.save();
|
|
437
481
|
if (includes && !core.Debug.showRepaint) {
|
|
438
482
|
canvas.clear();
|
|
@@ -482,7 +526,7 @@ class Renderer {
|
|
|
482
526
|
const { updateBlocks: list } = this;
|
|
483
527
|
if (list) {
|
|
484
528
|
const bounds = new core.Bounds();
|
|
485
|
-
bounds.
|
|
529
|
+
bounds.setList(list);
|
|
486
530
|
list.length = 0;
|
|
487
531
|
list.push(bounds);
|
|
488
532
|
}
|
|
@@ -522,7 +566,7 @@ class Renderer {
|
|
|
522
566
|
empty = (!leaf.__world.width || !leaf.__world.height);
|
|
523
567
|
if (empty) {
|
|
524
568
|
if (!leaf.isLeafer)
|
|
525
|
-
debug.
|
|
569
|
+
debug.tip(leaf.innerName, ': empty');
|
|
526
570
|
empty = (!leaf.isBranch || leaf.isBranchLeaf);
|
|
527
571
|
}
|
|
528
572
|
return empty;
|
|
@@ -556,8 +600,16 @@ class Renderer {
|
|
|
556
600
|
}
|
|
557
601
|
}
|
|
558
602
|
|
|
603
|
+
var AnswerType;
|
|
604
|
+
(function (AnswerType) {
|
|
605
|
+
AnswerType[AnswerType["No"] = 0] = "No";
|
|
606
|
+
AnswerType[AnswerType["Yes"] = 1] = "Yes";
|
|
607
|
+
AnswerType[AnswerType["NoAndSkip"] = 2] = "NoAndSkip";
|
|
608
|
+
AnswerType[AnswerType["YesAndSkip"] = 3] = "YesAndSkip";
|
|
609
|
+
})(AnswerType || (AnswerType = {}));
|
|
610
|
+
|
|
559
611
|
const { hitRadiusPoint } = core.BoundsHelper;
|
|
560
|
-
class
|
|
612
|
+
class Pather {
|
|
561
613
|
constructor(target, selector) {
|
|
562
614
|
this.target = target;
|
|
563
615
|
this.selector = selector;
|
|
@@ -600,10 +652,10 @@ class FindPath {
|
|
|
600
652
|
getPath(leaf) {
|
|
601
653
|
const path = new core.LeafList();
|
|
602
654
|
while (leaf) {
|
|
603
|
-
path.
|
|
655
|
+
path.add(leaf);
|
|
604
656
|
leaf = leaf.parent;
|
|
605
657
|
}
|
|
606
|
-
path.
|
|
658
|
+
path.add(this.target);
|
|
607
659
|
return path;
|
|
608
660
|
}
|
|
609
661
|
getHitablePath(leaf) {
|
|
@@ -613,7 +665,7 @@ class FindPath {
|
|
|
613
665
|
item = path.list[i];
|
|
614
666
|
if (!item.__.hittable)
|
|
615
667
|
break;
|
|
616
|
-
hittablePath.
|
|
668
|
+
hittablePath.addAt(item, 0);
|
|
617
669
|
if (!item.__.hitChildren)
|
|
618
670
|
break;
|
|
619
671
|
}
|
|
@@ -632,7 +684,7 @@ class FindPath {
|
|
|
632
684
|
leaf = path.list[j];
|
|
633
685
|
if (nextPath && nextPath.has(leaf))
|
|
634
686
|
break;
|
|
635
|
-
throughPath.
|
|
687
|
+
throughPath.add(leaf);
|
|
636
688
|
}
|
|
637
689
|
}
|
|
638
690
|
return throughPath;
|
|
@@ -674,120 +726,113 @@ class FindPath {
|
|
|
674
726
|
}
|
|
675
727
|
}
|
|
676
728
|
|
|
729
|
+
const { Yes, NoAndSkip, YesAndSkip } = AnswerType;
|
|
677
730
|
class Selector {
|
|
678
731
|
constructor(target, userConfig) {
|
|
679
732
|
this.config = {};
|
|
680
|
-
this.
|
|
681
|
-
this.
|
|
682
|
-
this.
|
|
683
|
-
|
|
733
|
+
this.innerIdMap = {};
|
|
734
|
+
this.idMap = {};
|
|
735
|
+
this.methods = {
|
|
736
|
+
id: (leaf, name) => leaf.id === name ? (this.idMap[name] = leaf, 1) : 0,
|
|
737
|
+
innerId: (leaf, innerId) => leaf.innerId === innerId ? (this.innerIdMap[innerId] = leaf, 1) : 0,
|
|
738
|
+
className: (leaf, name) => leaf.className === name ? 1 : 0,
|
|
739
|
+
tag: (leaf, name) => leaf.__tag === name ? 1 : 0
|
|
740
|
+
};
|
|
684
741
|
this.target = target;
|
|
685
742
|
if (userConfig)
|
|
686
743
|
this.config = core.DataHelper.default(userConfig, this.config);
|
|
687
|
-
this.
|
|
744
|
+
this.pather = new Pather(target, this);
|
|
688
745
|
this.__listenEvents();
|
|
689
746
|
}
|
|
747
|
+
getBy(condition, branch, one, options) {
|
|
748
|
+
switch (typeof condition) {
|
|
749
|
+
case 'number':
|
|
750
|
+
const leaf = this.getByInnerId(condition, branch);
|
|
751
|
+
return one ? leaf : (leaf ? [leaf] : []);
|
|
752
|
+
case 'string':
|
|
753
|
+
switch (condition[0]) {
|
|
754
|
+
case '#':
|
|
755
|
+
const leaf = this.getById(condition.substring(1), branch);
|
|
756
|
+
return one ? leaf : (leaf ? [leaf] : []);
|
|
757
|
+
case '.':
|
|
758
|
+
return this.getByMethod(this.methods.className, branch, one, condition.substring(1));
|
|
759
|
+
default:
|
|
760
|
+
return this.getByMethod(this.methods.tag, branch, one, condition);
|
|
761
|
+
}
|
|
762
|
+
case 'function':
|
|
763
|
+
return this.getByMethod(condition, branch, one, options);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
690
766
|
getByPoint(hitPoint, hitRadius, options) {
|
|
691
767
|
if (core.Platform.name === 'node')
|
|
692
768
|
this.target.emit(core.LayoutEvent.CHECK_UPDATE);
|
|
693
|
-
return this.
|
|
694
|
-
}
|
|
695
|
-
find(name, branch) {
|
|
696
|
-
if (typeof name === 'number') {
|
|
697
|
-
return this.getByInnerId(name, branch);
|
|
698
|
-
}
|
|
699
|
-
else if (name.startsWith('#')) {
|
|
700
|
-
return this.getById(name.substring(1), branch);
|
|
701
|
-
}
|
|
702
|
-
else if (name.startsWith('.')) {
|
|
703
|
-
return this.getByClassName(name.substring(1), branch);
|
|
704
|
-
}
|
|
705
|
-
else {
|
|
706
|
-
return this.getByTagName(name, branch);
|
|
707
|
-
}
|
|
769
|
+
return this.pather.getByPoint(hitPoint, hitRadius, options);
|
|
708
770
|
}
|
|
709
|
-
getByInnerId(
|
|
710
|
-
|
|
771
|
+
getByInnerId(innerId, branch) {
|
|
772
|
+
const cache = this.innerIdMap[innerId];
|
|
711
773
|
if (cache)
|
|
712
774
|
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;
|
|
775
|
+
this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId);
|
|
776
|
+
return this.findLeaf;
|
|
727
777
|
}
|
|
728
|
-
getById(
|
|
729
|
-
|
|
730
|
-
if (cache)
|
|
778
|
+
getById(id, branch) {
|
|
779
|
+
const cache = this.idMap[id];
|
|
780
|
+
if (cache && core.LeafHelper.hasParent(cache, branch || this.target))
|
|
731
781
|
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;
|
|
782
|
+
this.eachFind(this.toChildren(branch), this.methods.id, null, id);
|
|
783
|
+
return this.findLeaf;
|
|
768
784
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
785
|
+
getByClassName(className, branch) {
|
|
786
|
+
return this.getByMethod(this.methods.className, branch, false, className);
|
|
787
|
+
}
|
|
788
|
+
getByTag(tag, branch) {
|
|
789
|
+
return this.getByMethod(this.methods.tag, branch, false, tag);
|
|
790
|
+
}
|
|
791
|
+
getByMethod(method, branch, one, options) {
|
|
792
|
+
const list = one ? null : [];
|
|
793
|
+
this.eachFind(this.toChildren(branch), method, list, options);
|
|
794
|
+
return list || this.findLeaf;
|
|
795
|
+
}
|
|
796
|
+
eachFind(children, method, list, options) {
|
|
797
|
+
let child, result;
|
|
773
798
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
799
|
+
child = children[i];
|
|
800
|
+
result = method(child, options);
|
|
801
|
+
if (result === Yes || result === YesAndSkip) {
|
|
802
|
+
if (list) {
|
|
803
|
+
list.push(child);
|
|
804
|
+
}
|
|
805
|
+
else {
|
|
806
|
+
this.findLeaf = child;
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
if (child.isBranch && result < NoAndSkip)
|
|
811
|
+
this.eachFind(child.children, method, list, options);
|
|
779
812
|
}
|
|
780
813
|
}
|
|
814
|
+
toChildren(branch) {
|
|
815
|
+
this.findLeaf = null;
|
|
816
|
+
return [branch || this.target];
|
|
817
|
+
}
|
|
781
818
|
__onRemoveChild(event) {
|
|
782
|
-
const
|
|
783
|
-
if (this.
|
|
784
|
-
this.
|
|
785
|
-
if (this.
|
|
786
|
-
this.
|
|
819
|
+
const { id, innerId } = event.child;
|
|
820
|
+
if (this.idMap[id])
|
|
821
|
+
delete this.idMap[id];
|
|
822
|
+
if (this.innerIdMap[innerId])
|
|
823
|
+
delete this.innerIdMap[innerId];
|
|
824
|
+
}
|
|
825
|
+
__checkIdChange(event) {
|
|
826
|
+
if (event.attrName === 'id') {
|
|
827
|
+
const id = event.oldValue;
|
|
828
|
+
if (this.idMap[id])
|
|
829
|
+
delete this.idMap[id];
|
|
830
|
+
}
|
|
787
831
|
}
|
|
788
832
|
__listenEvents() {
|
|
789
833
|
this.__eventIds = [
|
|
790
|
-
this.target.on_(core.ChildEvent.REMOVE, this.__onRemoveChild, this)
|
|
834
|
+
this.target.on_(core.ChildEvent.REMOVE, this.__onRemoveChild, this),
|
|
835
|
+
this.target.on_(core.PropertyEvent.CHANGE, this.__checkIdChange, this)
|
|
791
836
|
];
|
|
792
837
|
}
|
|
793
838
|
__removeListenEvents() {
|
|
@@ -797,11 +842,10 @@ class Selector {
|
|
|
797
842
|
destroy() {
|
|
798
843
|
if (this.__eventIds.length) {
|
|
799
844
|
this.__removeListenEvents();
|
|
800
|
-
this.
|
|
801
|
-
this.
|
|
802
|
-
this.
|
|
803
|
-
this.
|
|
804
|
-
this.tagNameList = {};
|
|
845
|
+
this.pather.destroy();
|
|
846
|
+
this.findLeaf = null;
|
|
847
|
+
this.innerIdMap = {};
|
|
848
|
+
this.idMap = {};
|
|
805
849
|
}
|
|
806
850
|
}
|
|
807
851
|
}
|
|
@@ -820,8 +864,10 @@ class LeaferCanvas extends core.LeaferCanvasBase {
|
|
|
820
864
|
this.__createView();
|
|
821
865
|
this.__createContext();
|
|
822
866
|
this.resize(this.config);
|
|
823
|
-
|
|
824
|
-
|
|
867
|
+
if (core.Platform.roundRectPatch) {
|
|
868
|
+
this.context.__proto__.roundRect = null;
|
|
869
|
+
core.canvasPatch(this.context.__proto__);
|
|
870
|
+
}
|
|
825
871
|
}
|
|
826
872
|
__createView() {
|
|
827
873
|
this.view = core.Platform.origin.createCanvas(1, 1);
|
|
@@ -834,6 +880,7 @@ class LeaferCanvas extends core.LeaferCanvasBase {
|
|
|
834
880
|
}
|
|
835
881
|
}
|
|
836
882
|
|
|
883
|
+
const { mineType, fileType } = core.FileHelper;
|
|
837
884
|
Object.assign(core.Creator, {
|
|
838
885
|
canvas: (options, manager) => new LeaferCanvas(options, manager),
|
|
839
886
|
image: (options) => new core.LeaferImage(options),
|
|
@@ -841,6 +888,7 @@ Object.assign(core.Creator, {
|
|
|
841
888
|
interaction: (target, canvas, selector, options) => { return new core.InteractionBase(target, canvas, selector, options); }
|
|
842
889
|
});
|
|
843
890
|
function useCanvas(canvasType, power) {
|
|
891
|
+
core.Platform.canvasType = canvasType;
|
|
844
892
|
if (!core.Platform.origin) {
|
|
845
893
|
if (canvasType === 'skia') {
|
|
846
894
|
const { Canvas, loadImage } = power;
|
|
@@ -851,7 +899,19 @@ function useCanvas(canvasType, power) {
|
|
|
851
899
|
canvasSaveAs: (canvas, filename, quality) => canvas.saveAs(filename, { quality }),
|
|
852
900
|
loadImage
|
|
853
901
|
};
|
|
902
|
+
core.Platform.roundRectPatch = true;
|
|
903
|
+
}
|
|
904
|
+
else if (canvasType === 'napi') {
|
|
905
|
+
const { Canvas, loadImage } = power;
|
|
906
|
+
core.Platform.origin = {
|
|
907
|
+
createCanvas: (width, height, format) => new Canvas(width, height, format),
|
|
908
|
+
canvasToDataURL: (canvas, type, quality) => canvas.toDataURL(mineType(type), quality),
|
|
909
|
+
canvasToBolb: (canvas, type, quality) => __awaiter(this, void 0, void 0, function* () { return canvas.toBuffer(mineType(type), quality); }),
|
|
910
|
+
canvasSaveAs: (canvas, filename, quality) => __awaiter(this, void 0, void 0, function* () { return fs.writeFileSync(filename, canvas.toBuffer(mineType(fileType(filename)), quality)); }),
|
|
911
|
+
loadImage
|
|
912
|
+
};
|
|
854
913
|
}
|
|
914
|
+
core.Platform.ellipseToCurve = true;
|
|
855
915
|
core.Platform.event = {
|
|
856
916
|
stopDefault(_origin) { },
|
|
857
917
|
stopNow(_origin) { },
|
|
@@ -864,9 +924,8 @@ core.Platform.name = 'node';
|
|
|
864
924
|
core.Platform.requestRender = function (render) { setTimeout(render); };
|
|
865
925
|
core.Platform.devicePixelRatio = 1;
|
|
866
926
|
core.Platform.conicGradientSupport = true;
|
|
867
|
-
core.Platform.realtimeLayout = true;
|
|
868
927
|
|
|
869
|
-
const { get: get$4, rotateOfOuter: rotateOfOuter$2, translate: translate$1, scaleOfOuter: scaleOfOuter$2, scale: scaleHelper
|
|
928
|
+
const { get: get$4, rotateOfOuter: rotateOfOuter$2, translate: translate$1, scaleOfOuter: scaleOfOuter$2, scale: scaleHelper, rotate } = core.MatrixHelper;
|
|
870
929
|
function fillOrFitMode(data, mode, box, width, height, rotation) {
|
|
871
930
|
const transform = get$4();
|
|
872
931
|
const swap = rotation && rotation !== 180;
|
|
@@ -876,7 +935,7 @@ function fillOrFitMode(data, mode, box, width, height, rotation) {
|
|
|
876
935
|
const x = box.x + (box.width - width * scale) / 2;
|
|
877
936
|
const y = box.y + (box.height - height * scale) / 2;
|
|
878
937
|
translate$1(transform, x, y);
|
|
879
|
-
scaleHelper
|
|
938
|
+
scaleHelper(transform, scale);
|
|
880
939
|
if (rotation)
|
|
881
940
|
rotateOfOuter$2(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
|
|
882
941
|
data.scaleX = data.scaleY = scale;
|
|
@@ -888,7 +947,7 @@ function clipMode(data, box, offset, scale, rotation) {
|
|
|
888
947
|
if (offset)
|
|
889
948
|
translate$1(transform, offset.x, offset.y);
|
|
890
949
|
if (scale) {
|
|
891
|
-
typeof scale === 'number' ? scaleHelper
|
|
950
|
+
typeof scale === 'number' ? scaleHelper(transform, scale) : scaleHelper(transform, scale.x, scale.y);
|
|
892
951
|
data.scaleX = transform.a;
|
|
893
952
|
data.scaleY = transform.d;
|
|
894
953
|
}
|
|
@@ -1001,6 +1060,10 @@ function hasNaturalSize(ui, attrName, image) {
|
|
|
1001
1060
|
d.__naturalWidth = image.width;
|
|
1002
1061
|
d.__naturalHeight = image.height;
|
|
1003
1062
|
if (!d.__getInput('width') || !d.__getInput('height')) {
|
|
1063
|
+
if (ui.__proxyData) {
|
|
1064
|
+
ui.setProxyAttr('width', ui.__.width);
|
|
1065
|
+
ui.setProxyAttr('height', ui.__.height);
|
|
1066
|
+
}
|
|
1004
1067
|
ui.forceUpdate('width');
|
|
1005
1068
|
return false;
|
|
1006
1069
|
}
|
|
@@ -1012,54 +1075,21 @@ function emit(type, data) {
|
|
|
1012
1075
|
data.target.emitEvent(new core.ImageEvent(type, data));
|
|
1013
1076
|
}
|
|
1014
1077
|
|
|
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
|
-
};
|
|
1078
|
+
const Export$1 = {};
|
|
1046
1079
|
|
|
1047
|
-
const { get: get$2, scale
|
|
1080
|
+
const { get: get$2, scale, copy: copy$1 } = core.MatrixHelper;
|
|
1048
1081
|
function createPattern(ui, paint, pixelRatio) {
|
|
1049
1082
|
let { scaleX, scaleY } = ui.__world;
|
|
1050
1083
|
const id = scaleX + '-' + scaleY;
|
|
1051
1084
|
if (paint.patternId !== id && !ui.destroyed) {
|
|
1052
|
-
paint.patternId = id;
|
|
1053
1085
|
scaleX = Math.abs(scaleX);
|
|
1054
1086
|
scaleY = Math.abs(scaleY);
|
|
1055
1087
|
const { image, data } = paint;
|
|
1056
|
-
|
|
1057
|
-
const maxHeight = image.isSVG ? 4096 : Math.min(image.height, 4096);
|
|
1058
|
-
let scale, matrix, { width, height, scaleX: sx, scaleY: sy, opacity, transform, mode } = data;
|
|
1088
|
+
let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, opacity, transform, mode } = data;
|
|
1059
1089
|
if (sx) {
|
|
1060
|
-
|
|
1061
|
-
copy$1(
|
|
1062
|
-
|
|
1090
|
+
imageMatrix = get$2();
|
|
1091
|
+
copy$1(imageMatrix, transform);
|
|
1092
|
+
scale(imageMatrix, 1 / sx, 1 / sy);
|
|
1063
1093
|
scaleX *= sx;
|
|
1064
1094
|
scaleY *= sy;
|
|
1065
1095
|
}
|
|
@@ -1067,38 +1097,49 @@ function createPattern(ui, paint, pixelRatio) {
|
|
|
1067
1097
|
scaleY *= pixelRatio;
|
|
1068
1098
|
width *= scaleX;
|
|
1069
1099
|
height *= scaleY;
|
|
1070
|
-
|
|
1071
|
-
|
|
1100
|
+
const size = width * height;
|
|
1101
|
+
if (paint.data.mode !== 'repeat') {
|
|
1102
|
+
if (size > core.Platform.image.maxCacheSize)
|
|
1103
|
+
return false;
|
|
1104
|
+
}
|
|
1105
|
+
let maxSize = core.Platform.image.maxPatternSize;
|
|
1106
|
+
if (!image.isSVG) {
|
|
1107
|
+
const imageSize = image.width * image.height;
|
|
1108
|
+
if (maxSize > imageSize)
|
|
1109
|
+
maxSize = imageSize;
|
|
1072
1110
|
}
|
|
1073
|
-
if (
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1111
|
+
if (size > maxSize)
|
|
1112
|
+
imageScale = Math.sqrt(size / maxSize);
|
|
1113
|
+
if (imageScale) {
|
|
1114
|
+
scaleX /= imageScale;
|
|
1115
|
+
scaleY /= imageScale;
|
|
1116
|
+
width /= imageScale;
|
|
1117
|
+
height /= imageScale;
|
|
1078
1118
|
}
|
|
1079
1119
|
if (sx) {
|
|
1080
1120
|
scaleX /= sx;
|
|
1081
1121
|
scaleY /= sy;
|
|
1082
1122
|
}
|
|
1083
1123
|
if (transform || scaleX !== 1 || scaleY !== 1) {
|
|
1084
|
-
if (!
|
|
1085
|
-
|
|
1124
|
+
if (!imageMatrix) {
|
|
1125
|
+
imageMatrix = get$2();
|
|
1086
1126
|
if (transform)
|
|
1087
|
-
copy$1(
|
|
1127
|
+
copy$1(imageMatrix, transform);
|
|
1088
1128
|
}
|
|
1089
|
-
|
|
1129
|
+
scale(imageMatrix, 1 / scaleX, 1 / scaleY);
|
|
1090
1130
|
}
|
|
1091
|
-
const
|
|
1131
|
+
const pattern = core.Platform.canvas.createPattern(image.getCanvas(width < 1 ? 1 : width, height < 1 ? 1 : height, opacity), mode === 'repeat' ? 'repeat' : (core.Platform.origin.noRepeat || 'no-repeat'));
|
|
1092
1132
|
try {
|
|
1093
1133
|
if (paint.transform)
|
|
1094
1134
|
paint.transform = null;
|
|
1095
|
-
if (
|
|
1096
|
-
|
|
1135
|
+
if (imageMatrix)
|
|
1136
|
+
pattern.setTransform ? pattern.setTransform(imageMatrix) : paint.transform = imageMatrix;
|
|
1097
1137
|
}
|
|
1098
1138
|
catch (_a) {
|
|
1099
|
-
paint.transform =
|
|
1139
|
+
paint.transform = imageMatrix;
|
|
1100
1140
|
}
|
|
1101
|
-
paint.style =
|
|
1141
|
+
paint.style = pattern;
|
|
1142
|
+
paint.patternId = id;
|
|
1102
1143
|
return true;
|
|
1103
1144
|
}
|
|
1104
1145
|
else {
|
|
@@ -1106,18 +1147,24 @@ function createPattern(ui, paint, pixelRatio) {
|
|
|
1106
1147
|
}
|
|
1107
1148
|
}
|
|
1108
1149
|
|
|
1150
|
+
const { abs } = Math;
|
|
1109
1151
|
function checkImage(ui, canvas, paint, allowPaint) {
|
|
1110
1152
|
const { scaleX, scaleY } = ui.__world;
|
|
1111
1153
|
if (!paint.data || paint.patternId === scaleX + '-' + scaleY) {
|
|
1112
1154
|
return false;
|
|
1113
1155
|
}
|
|
1114
1156
|
else {
|
|
1157
|
+
const { data } = paint;
|
|
1115
1158
|
if (allowPaint) {
|
|
1116
|
-
if (
|
|
1117
|
-
let { width, height } =
|
|
1118
|
-
width *= scaleX * canvas.pixelRatio;
|
|
1119
|
-
height *= scaleY * canvas.pixelRatio;
|
|
1120
|
-
|
|
1159
|
+
if (data.mode !== 'repeat') {
|
|
1160
|
+
let { width, height } = data;
|
|
1161
|
+
width *= abs(scaleX) * canvas.pixelRatio;
|
|
1162
|
+
height *= abs(scaleY) * canvas.pixelRatio;
|
|
1163
|
+
if (data.scaleX) {
|
|
1164
|
+
width *= data.scaleX;
|
|
1165
|
+
height *= data.scaleY;
|
|
1166
|
+
}
|
|
1167
|
+
allowPaint = width * height > core.Platform.image.maxCacheSize;
|
|
1121
1168
|
}
|
|
1122
1169
|
else {
|
|
1123
1170
|
allowPaint = false;
|
|
@@ -1126,7 +1173,6 @@ function checkImage(ui, canvas, paint, allowPaint) {
|
|
|
1126
1173
|
if (allowPaint) {
|
|
1127
1174
|
canvas.save();
|
|
1128
1175
|
canvas.clip();
|
|
1129
|
-
const { data } = paint;
|
|
1130
1176
|
if (paint.blendMode)
|
|
1131
1177
|
canvas.blendMode = paint.blendMode;
|
|
1132
1178
|
if (data.opacity)
|
|
@@ -1138,15 +1184,16 @@ function checkImage(ui, canvas, paint, allowPaint) {
|
|
|
1138
1184
|
return true;
|
|
1139
1185
|
}
|
|
1140
1186
|
else {
|
|
1141
|
-
if (!paint.style) {
|
|
1187
|
+
if (!paint.style || Export$1.running) {
|
|
1142
1188
|
createPattern(ui, paint, canvas.pixelRatio);
|
|
1143
1189
|
}
|
|
1144
1190
|
else {
|
|
1145
1191
|
if (!paint.patternTask) {
|
|
1146
1192
|
paint.patternTask = core.ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function* () {
|
|
1147
1193
|
paint.patternTask = null;
|
|
1148
|
-
if (canvas.bounds.hit(ui.__world)
|
|
1149
|
-
ui.
|
|
1194
|
+
if (canvas.bounds.hit(ui.__world))
|
|
1195
|
+
createPattern(ui, paint, canvas.pixelRatio);
|
|
1196
|
+
ui.forceUpdate('surface');
|
|
1150
1197
|
}), 300);
|
|
1151
1198
|
}
|
|
1152
1199
|
}
|
|
@@ -1156,7 +1203,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
|
|
|
1156
1203
|
}
|
|
1157
1204
|
|
|
1158
1205
|
function recycleImage(attrName, data) {
|
|
1159
|
-
const paints =
|
|
1206
|
+
const paints = data['_' + attrName];
|
|
1160
1207
|
if (paints instanceof Array) {
|
|
1161
1208
|
let image, recycleMap, input, url;
|
|
1162
1209
|
for (let i = 0, len = paints.length; i < len; i++) {
|
|
@@ -1260,7 +1307,7 @@ function drawAlignStroke(align, stroke, isStrokes, ui, canvas, renderOptions) {
|
|
|
1260
1307
|
out.blendMode = align === 'outside' ? 'destination-out' : 'destination-in';
|
|
1261
1308
|
fillText(ui, out);
|
|
1262
1309
|
out.blendMode = 'normal';
|
|
1263
|
-
if (ui.
|
|
1310
|
+
if (ui.__worldFlipped || renderOptions.matrix) {
|
|
1264
1311
|
canvas.copyWorldByReset(out);
|
|
1265
1312
|
}
|
|
1266
1313
|
else {
|
|
@@ -1333,7 +1380,7 @@ function stroke(stroke, ui, canvas, renderOptions) {
|
|
|
1333
1380
|
out.stroke();
|
|
1334
1381
|
options.windingRule ? out.clip(options.windingRule) : out.clip();
|
|
1335
1382
|
out.clearWorld(ui.__layout.renderBounds);
|
|
1336
|
-
if (ui.
|
|
1383
|
+
if (ui.__worldFlipped || renderOptions.matrix) {
|
|
1337
1384
|
canvas.copyWorldByReset(out);
|
|
1338
1385
|
}
|
|
1339
1386
|
else {
|
|
@@ -1373,7 +1420,7 @@ function strokes(strokes, ui, canvas, renderOptions) {
|
|
|
1373
1420
|
drawStrokesStyle(strokes, false, ui, out);
|
|
1374
1421
|
options.windingRule ? out.clip(options.windingRule) : out.clip();
|
|
1375
1422
|
out.clearWorld(renderBounds);
|
|
1376
|
-
if (ui.
|
|
1423
|
+
if (ui.__worldFlipped || renderOptions.matrix) {
|
|
1377
1424
|
canvas.copyWorldByReset(out);
|
|
1378
1425
|
}
|
|
1379
1426
|
else {
|
|
@@ -1597,7 +1644,7 @@ function shadow(ui, current, shape, renderOptions) {
|
|
|
1597
1644
|
}
|
|
1598
1645
|
worldCanvas ? other.copyWorld(worldCanvas, __world, __world, 'destination-out') : other.copyWorld(shape.canvas, shapeBounds, bounds, 'destination-out');
|
|
1599
1646
|
}
|
|
1600
|
-
if (ui.
|
|
1647
|
+
if (ui.__worldFlipped || renderOptions.matrix) {
|
|
1601
1648
|
current.copyWorldByReset(other, copyBounds, __world, item.blendMode);
|
|
1602
1649
|
}
|
|
1603
1650
|
else {
|
|
@@ -1661,7 +1708,7 @@ function innerShadow(ui, current, shape, renderOptions) {
|
|
|
1661
1708
|
copyBounds = bounds;
|
|
1662
1709
|
}
|
|
1663
1710
|
other.fillWorld(copyBounds, item.color, 'source-in');
|
|
1664
|
-
if (ui.
|
|
1711
|
+
if (ui.__worldFlipped || renderOptions.matrix) {
|
|
1665
1712
|
current.copyWorldByReset(other, copyBounds, __world, item.blendMode);
|
|
1666
1713
|
}
|
|
1667
1714
|
else {
|
|
@@ -1810,6 +1857,8 @@ function createRows(drawData, content, style) {
|
|
|
1810
1857
|
const { width, height } = bounds;
|
|
1811
1858
|
const charMode = width || height || __letterSpacing || (textCase !== 'none');
|
|
1812
1859
|
if (charMode) {
|
|
1860
|
+
const wrap = style.textWrap !== 'none';
|
|
1861
|
+
const breakAll = style.textWrap === 'break';
|
|
1813
1862
|
paraStart = true;
|
|
1814
1863
|
lastCharType = null;
|
|
1815
1864
|
startCharSize = charWidth = charSize = wordWidth = rowWidth = 0;
|
|
@@ -1836,16 +1885,23 @@ function createRows(drawData, content, style) {
|
|
|
1836
1885
|
langBreak = (charType === Single && (lastCharType === Single || lastCharType === Letter)) || (lastCharType === Single && charType !== After);
|
|
1837
1886
|
afterBreak = ((charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After));
|
|
1838
1887
|
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)) {
|
|
1888
|
+
if (wrap && (width && rowWidth + wordWidth + charWidth > realWidth)) {
|
|
1889
|
+
if (breakAll) {
|
|
1843
1890
|
if (wordWidth)
|
|
1844
1891
|
addWord();
|
|
1845
1892
|
addRow();
|
|
1846
1893
|
}
|
|
1847
1894
|
else {
|
|
1848
|
-
|
|
1895
|
+
if (!afterBreak)
|
|
1896
|
+
afterBreak = charType === Letter && lastCharType == After;
|
|
1897
|
+
if (langBreak || afterBreak || charType === Break || charType === Before || charType === Single || (wordWidth + charWidth > realWidth)) {
|
|
1898
|
+
if (wordWidth)
|
|
1899
|
+
addWord();
|
|
1900
|
+
addRow();
|
|
1901
|
+
}
|
|
1902
|
+
else {
|
|
1903
|
+
addRow();
|
|
1904
|
+
}
|
|
1849
1905
|
}
|
|
1850
1906
|
}
|
|
1851
1907
|
if (char === ' ' && paraStart !== true && (rowWidth + wordWidth) === 0) ;
|
|
@@ -1915,7 +1971,7 @@ function addRow() {
|
|
|
1915
1971
|
|
|
1916
1972
|
const CharMode = 0;
|
|
1917
1973
|
const WordMode = 1;
|
|
1918
|
-
const
|
|
1974
|
+
const TextMode = 2;
|
|
1919
1975
|
function layoutChar(drawData, style, width, _height) {
|
|
1920
1976
|
const { rows } = drawData;
|
|
1921
1977
|
const { textAlign, paraIndent, letterSpacing } = style;
|
|
@@ -1924,15 +1980,12 @@ function layoutChar(drawData, style, width, _height) {
|
|
|
1924
1980
|
if (row.words) {
|
|
1925
1981
|
indentWidth = paraIndent && row.paraStart ? paraIndent : 0;
|
|
1926
1982
|
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.
|
|
1983
|
+
mode = (letterSpacing || row.isOverflow) ? CharMode : (addWordWidth > 0.01 ? WordMode : TextMode);
|
|
1984
|
+
if (row.isOverflow && !letterSpacing)
|
|
1985
|
+
row.textMode = true;
|
|
1986
|
+
if (mode === TextMode) {
|
|
1930
1987
|
row.x += indentWidth;
|
|
1931
|
-
row
|
|
1932
|
-
word.data.forEach(char => {
|
|
1933
|
-
row.text += char.char;
|
|
1934
|
-
});
|
|
1935
|
-
});
|
|
1988
|
+
toTextChar$1(row);
|
|
1936
1989
|
}
|
|
1937
1990
|
else {
|
|
1938
1991
|
row.x += indentWidth;
|
|
@@ -1958,6 +2011,14 @@ function layoutChar(drawData, style, width, _height) {
|
|
|
1958
2011
|
}
|
|
1959
2012
|
});
|
|
1960
2013
|
}
|
|
2014
|
+
function toTextChar$1(row) {
|
|
2015
|
+
row.text = '';
|
|
2016
|
+
row.words.forEach(word => {
|
|
2017
|
+
word.data.forEach(char => {
|
|
2018
|
+
row.text += char.char;
|
|
2019
|
+
});
|
|
2020
|
+
});
|
|
2021
|
+
}
|
|
1961
2022
|
function toWordChar(data, charX, wordChar) {
|
|
1962
2023
|
data.forEach(char => {
|
|
1963
2024
|
wordChar.char += char.char;
|
|
@@ -1978,10 +2039,10 @@ function toChar(data, charX, rowData) {
|
|
|
1978
2039
|
|
|
1979
2040
|
function layoutText(drawData, style) {
|
|
1980
2041
|
const { rows, bounds } = drawData;
|
|
1981
|
-
const { __lineHeight, __baseLine, __letterSpacing, textAlign, verticalAlign, paraSpacing
|
|
2042
|
+
const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing } = style;
|
|
1982
2043
|
let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
|
|
1983
2044
|
let starY = __baseLine;
|
|
1984
|
-
if (
|
|
2045
|
+
if (__clipText && realHeight > height) {
|
|
1985
2046
|
realHeight = Math.max(height, __lineHeight);
|
|
1986
2047
|
drawData.overflow = rows.length;
|
|
1987
2048
|
}
|
|
@@ -2030,39 +2091,58 @@ function layoutText(drawData, style) {
|
|
|
2030
2091
|
bounds.x = rowX;
|
|
2031
2092
|
if (rowWidth > bounds.width)
|
|
2032
2093
|
bounds.width = rowWidth;
|
|
2094
|
+
if (__clipText && width && width < rowWidth) {
|
|
2095
|
+
row.isOverflow = true;
|
|
2096
|
+
if (!drawData.overflow)
|
|
2097
|
+
drawData.overflow = rows.length;
|
|
2098
|
+
}
|
|
2033
2099
|
}
|
|
2034
2100
|
bounds.y = y;
|
|
2035
2101
|
bounds.height = realHeight;
|
|
2036
2102
|
}
|
|
2037
2103
|
|
|
2038
|
-
function clipText(drawData,
|
|
2104
|
+
function clipText(drawData, style) {
|
|
2039
2105
|
const { rows, overflow } = drawData;
|
|
2106
|
+
let { textOverflow } = style;
|
|
2040
2107
|
rows.splice(overflow);
|
|
2041
2108
|
if (textOverflow !== 'hide') {
|
|
2042
2109
|
if (textOverflow === 'ellipsis')
|
|
2043
2110
|
textOverflow = '...';
|
|
2111
|
+
let char, charRight;
|
|
2044
2112
|
const ellipsisWidth = core.Platform.canvas.measureText(textOverflow).width;
|
|
2045
|
-
const
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2113
|
+
const right = style.x + style.width - ellipsisWidth;
|
|
2114
|
+
const list = style.textWrap === 'none' ? rows : [rows[overflow - 1]];
|
|
2115
|
+
list.forEach(row => {
|
|
2116
|
+
if (row.isOverflow && row.data) {
|
|
2117
|
+
let end = row.data.length - 1;
|
|
2118
|
+
for (let i = end; i > -1; i--) {
|
|
2119
|
+
char = row.data[i];
|
|
2120
|
+
charRight = char.x + char.width;
|
|
2121
|
+
if (i === end && charRight < right) {
|
|
2122
|
+
break;
|
|
2123
|
+
}
|
|
2124
|
+
else if (charRight < right && char.char !== ' ') {
|
|
2125
|
+
row.data.splice(i + 1);
|
|
2126
|
+
row.width -= char.width;
|
|
2127
|
+
break;
|
|
2128
|
+
}
|
|
2129
|
+
row.width -= char.width;
|
|
2130
|
+
}
|
|
2131
|
+
row.width += ellipsisWidth;
|
|
2132
|
+
row.data.push({ char: textOverflow, x: charRight });
|
|
2133
|
+
if (row.textMode)
|
|
2134
|
+
toTextChar(row);
|
|
2059
2135
|
}
|
|
2060
|
-
|
|
2061
|
-
}
|
|
2062
|
-
row.width += ellipsisWidth;
|
|
2063
|
-
row.data.push({ char: textOverflow, x: charRight });
|
|
2136
|
+
});
|
|
2064
2137
|
}
|
|
2065
2138
|
}
|
|
2139
|
+
function toTextChar(row) {
|
|
2140
|
+
row.text = '';
|
|
2141
|
+
row.data.forEach(char => {
|
|
2142
|
+
row.text += char.char;
|
|
2143
|
+
});
|
|
2144
|
+
row.data = null;
|
|
2145
|
+
}
|
|
2066
2146
|
|
|
2067
2147
|
function decorationText(drawData, style) {
|
|
2068
2148
|
const { fontSize } = style;
|
|
@@ -2083,7 +2163,7 @@ const TextConvert = {
|
|
|
2083
2163
|
let x = 0, y = 0;
|
|
2084
2164
|
let width = style.__getInput('width') || 0;
|
|
2085
2165
|
let height = style.__getInput('height') || 0;
|
|
2086
|
-
const { textDecoration,
|
|
2166
|
+
const { textDecoration, __font, padding } = style;
|
|
2087
2167
|
if (padding) {
|
|
2088
2168
|
const [top, right, bottom, left] = core.MathHelper.fourNumber(padding);
|
|
2089
2169
|
if (width) {
|
|
@@ -2105,7 +2185,7 @@ const TextConvert = {
|
|
|
2105
2185
|
layoutText(drawData, style);
|
|
2106
2186
|
layoutChar(drawData, style, width);
|
|
2107
2187
|
if (drawData.overflow)
|
|
2108
|
-
clipText(drawData,
|
|
2188
|
+
clipText(drawData, style);
|
|
2109
2189
|
if (textDecoration !== 'none')
|
|
2110
2190
|
decorationText(drawData, style);
|
|
2111
2191
|
return drawData;
|
|
@@ -2126,6 +2206,7 @@ const ColorConvert = {
|
|
|
2126
2206
|
|
|
2127
2207
|
const Export = {
|
|
2128
2208
|
export(leaf, filename, options) {
|
|
2209
|
+
Export.running = true;
|
|
2129
2210
|
return addTask((success) => new Promise((resolve) => {
|
|
2130
2211
|
const { leafer } = leaf;
|
|
2131
2212
|
if (leafer) {
|
|
@@ -2163,6 +2244,7 @@ const Export = {
|
|
|
2163
2244
|
}
|
|
2164
2245
|
success({ data });
|
|
2165
2246
|
resolve();
|
|
2247
|
+
Export.running = false;
|
|
2166
2248
|
if (unreal)
|
|
2167
2249
|
canvas.recycle();
|
|
2168
2250
|
}));
|
|
@@ -2170,6 +2252,7 @@ const Export = {
|
|
|
2170
2252
|
else {
|
|
2171
2253
|
success({ data: false });
|
|
2172
2254
|
resolve();
|
|
2255
|
+
Export.running = false;
|
|
2173
2256
|
}
|
|
2174
2257
|
}));
|
|
2175
2258
|
}
|