leafer-ui 1.0.0-rc.6 → 1.0.0-rc.8
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 +1 -1
- package/dist/web.esm.js +178 -103
- package/dist/web.esm.min.js +1 -1
- package/dist/web.js +1746 -1122
- package/dist/web.min.js +1 -1
- package/dist/web.module.js +1728 -1120
- package/dist/web.module.min.js +1 -1
- package/package.json +4 -4
package/dist/web.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { LeafList, DataHelper, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper,
|
|
1
|
+
import { LeafList, DataHelper, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, Platform, AnimateEvent, ResizeEvent, BoundsHelper, Creator, LeaferCanvasBase, Cursor, canvasSizeAttrs, canvasPatch, InteractionHelper, MathHelper, InteractionBase, LeaferImage, FileHelper, MatrixHelper, ImageEvent, PointHelper, Direction4, TaskProcessor } from '@leafer/core';
|
|
2
2
|
export * from '@leafer/core';
|
|
3
3
|
export { LeaferImage } from '@leafer/core';
|
|
4
|
-
import { ColorConvert as ColorConvert$1, ImageManager as ImageManager$1, Paint, Effect, TextConvert as TextConvert$1, Export as Export$
|
|
4
|
+
import { ColorConvert as ColorConvert$1, ImageManager as ImageManager$1, Paint, Effect, TextConvert as TextConvert$1, Export as Export$2 } from '@leafer-ui/core';
|
|
5
5
|
export * from '@leafer-ui/core';
|
|
6
6
|
|
|
7
7
|
class Watcher {
|
|
@@ -10,7 +10,7 @@ class Watcher {
|
|
|
10
10
|
if (this.hasRemove) {
|
|
11
11
|
const updatedList = new LeafList();
|
|
12
12
|
this.__updatedList.list.forEach(item => { if (item.leafer)
|
|
13
|
-
updatedList.
|
|
13
|
+
updatedList.add(item); });
|
|
14
14
|
return updatedList;
|
|
15
15
|
}
|
|
16
16
|
else {
|
|
@@ -45,7 +45,7 @@ class Watcher {
|
|
|
45
45
|
this.target.emit(RenderEvent.REQUEST);
|
|
46
46
|
}
|
|
47
47
|
__onAttrChange(event) {
|
|
48
|
-
this.__updatedList.
|
|
48
|
+
this.__updatedList.add(event.target);
|
|
49
49
|
this.update();
|
|
50
50
|
}
|
|
51
51
|
__onChildEvent(event) {
|
|
@@ -55,12 +55,12 @@ class Watcher {
|
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
57
57
|
this.hasRemove = true;
|
|
58
|
-
this.__updatedList.
|
|
58
|
+
this.__updatedList.add(event.parent);
|
|
59
59
|
}
|
|
60
60
|
this.update();
|
|
61
61
|
}
|
|
62
62
|
__pushChild(child) {
|
|
63
|
-
this.__updatedList.
|
|
63
|
+
this.__updatedList.add(child);
|
|
64
64
|
if (child.isBranch)
|
|
65
65
|
this.__loopChildren(child);
|
|
66
66
|
}
|
|
@@ -99,7 +99,7 @@ class Watcher {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
const {
|
|
102
|
+
const { updateAllMatrix: updateAllMatrix$1, updateBounds: updateOneBounds, updateAllWorldOpacity } = LeafHelper;
|
|
103
103
|
const { pushAllChildBranch, pushAllParent } = BranchHelper;
|
|
104
104
|
function updateMatrix(updateList, levelList) {
|
|
105
105
|
let layout;
|
|
@@ -107,14 +107,14 @@ function updateMatrix(updateList, levelList) {
|
|
|
107
107
|
layout = leaf.__layout;
|
|
108
108
|
if (levelList.without(leaf) && !layout.proxyZoom) {
|
|
109
109
|
if (layout.matrixChanged) {
|
|
110
|
-
|
|
111
|
-
levelList.
|
|
110
|
+
updateAllMatrix$1(leaf, true);
|
|
111
|
+
levelList.add(leaf);
|
|
112
112
|
if (leaf.isBranch)
|
|
113
113
|
pushAllChildBranch(leaf, levelList);
|
|
114
114
|
pushAllParent(leaf, levelList);
|
|
115
115
|
}
|
|
116
116
|
else if (layout.boundsChanged) {
|
|
117
|
-
levelList.
|
|
117
|
+
levelList.add(leaf);
|
|
118
118
|
if (leaf.isBranch)
|
|
119
119
|
leaf.__tempNumber = 0;
|
|
120
120
|
pushAllParent(leaf, levelList);
|
|
@@ -123,20 +123,21 @@ function updateMatrix(updateList, levelList) {
|
|
|
123
123
|
});
|
|
124
124
|
}
|
|
125
125
|
function updateBounds(boundsList) {
|
|
126
|
-
let
|
|
126
|
+
let list, branch, children;
|
|
127
127
|
boundsList.sort(true);
|
|
128
128
|
boundsList.levels.forEach(level => {
|
|
129
|
-
|
|
130
|
-
for (let i = 0, len =
|
|
131
|
-
branch =
|
|
129
|
+
list = boundsList.levelMap[level];
|
|
130
|
+
for (let i = 0, len = list.length; i < len; i++) {
|
|
131
|
+
branch = list[i];
|
|
132
132
|
if (branch.isBranch && branch.__tempNumber) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
children = branch.children;
|
|
134
|
+
for (let j = 0, jLen = children.length; j < jLen; j++) {
|
|
135
|
+
if (!children[j].isBranch) {
|
|
136
|
+
updateOneBounds(children[j]);
|
|
136
137
|
}
|
|
137
138
|
}
|
|
138
139
|
}
|
|
139
|
-
branch
|
|
140
|
+
updateOneBounds(branch);
|
|
140
141
|
}
|
|
141
142
|
});
|
|
142
143
|
}
|
|
@@ -149,7 +150,7 @@ function updateChange(updateList) {
|
|
|
149
150
|
}
|
|
150
151
|
|
|
151
152
|
const { worldBounds } = LeafBoundsHelper;
|
|
152
|
-
const {
|
|
153
|
+
const bigBounds = { x: 0, y: 0, width: 100000, height: 100000 };
|
|
153
154
|
class LayoutBlockData {
|
|
154
155
|
constructor(list) {
|
|
155
156
|
this.updatedBounds = new Bounds();
|
|
@@ -160,14 +161,20 @@ class LayoutBlockData {
|
|
|
160
161
|
this.updatedList = list;
|
|
161
162
|
}
|
|
162
163
|
setBefore() {
|
|
163
|
-
|
|
164
|
+
this.beforeBounds.setListWithFn(this.updatedList.list, worldBounds);
|
|
164
165
|
}
|
|
165
166
|
setAfter() {
|
|
166
|
-
|
|
167
|
-
|
|
167
|
+
const { list } = this.updatedList;
|
|
168
|
+
if (list.some(leaf => leaf.noBounds)) {
|
|
169
|
+
this.afterBounds.set(bigBounds);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
this.afterBounds.setListWithFn(list, worldBounds);
|
|
173
|
+
}
|
|
174
|
+
this.updatedBounds.setList([this.beforeBounds, this.afterBounds]);
|
|
168
175
|
}
|
|
169
176
|
merge(data) {
|
|
170
|
-
this.updatedList.
|
|
177
|
+
this.updatedList.addList(data.updatedList.list);
|
|
171
178
|
this.beforeBounds.add(data.beforeBounds);
|
|
172
179
|
this.afterBounds.add(data.afterBounds);
|
|
173
180
|
this.updatedBounds.add(data.updatedBounds);
|
|
@@ -177,8 +184,7 @@ class LayoutBlockData {
|
|
|
177
184
|
}
|
|
178
185
|
}
|
|
179
186
|
|
|
180
|
-
const {
|
|
181
|
-
const { pushAllBranchStack, updateWorldBoundsByBranchStack } = BranchHelper;
|
|
187
|
+
const { updateAllMatrix, updateAllChange } = LeafHelper;
|
|
182
188
|
const debug$2 = Debug.get('Layouter');
|
|
183
189
|
class Layouter {
|
|
184
190
|
constructor(target, userConfig) {
|
|
@@ -255,12 +261,15 @@ class Layouter {
|
|
|
255
261
|
const { target, __updatedList: updateList } = this;
|
|
256
262
|
const { BEFORE, LAYOUT, AFTER } = LayoutEvent;
|
|
257
263
|
const blocks = this.getBlocks(updateList);
|
|
258
|
-
blocks.forEach(item =>
|
|
264
|
+
blocks.forEach(item => item.setBefore());
|
|
259
265
|
target.emitEvent(new LayoutEvent(BEFORE, blocks, this.times));
|
|
266
|
+
this.extraBlock = null;
|
|
260
267
|
updateList.sort();
|
|
261
268
|
updateMatrix(updateList, this.__levelList);
|
|
262
269
|
updateBounds(this.__levelList);
|
|
263
270
|
updateChange(updateList);
|
|
271
|
+
if (this.extraBlock)
|
|
272
|
+
blocks.push(this.extraBlock);
|
|
264
273
|
blocks.forEach(item => item.setAfter());
|
|
265
274
|
target.emitEvent(new LayoutEvent(LAYOUT, blocks, this.times));
|
|
266
275
|
target.emitEvent(new LayoutEvent(AFTER, blocks, this.times));
|
|
@@ -283,17 +292,20 @@ class Layouter {
|
|
|
283
292
|
Run.end(t);
|
|
284
293
|
}
|
|
285
294
|
static fullLayout(target) {
|
|
286
|
-
|
|
295
|
+
updateAllMatrix(target, true);
|
|
287
296
|
if (target.isBranch) {
|
|
288
|
-
|
|
289
|
-
pushAllBranchStack(target, branchStack);
|
|
290
|
-
updateWorldBoundsByBranchStack(branchStack);
|
|
297
|
+
BranchHelper.updateBounds(target);
|
|
291
298
|
}
|
|
292
299
|
else {
|
|
293
|
-
|
|
300
|
+
LeafHelper.updateBounds(target);
|
|
294
301
|
}
|
|
295
302
|
updateAllChange(target);
|
|
296
303
|
}
|
|
304
|
+
addExtra(leaf) {
|
|
305
|
+
const block = this.extraBlock || (this.extraBlock = new LayoutBlockData([]));
|
|
306
|
+
block.updatedList.add(leaf);
|
|
307
|
+
block.beforeBounds.add(leaf.__world);
|
|
308
|
+
}
|
|
297
309
|
createBlock(data) {
|
|
298
310
|
return new LayoutBlockData(data);
|
|
299
311
|
}
|
|
@@ -321,8 +333,7 @@ class Layouter {
|
|
|
321
333
|
if (this.target) {
|
|
322
334
|
this.stop();
|
|
323
335
|
this.__removeListenEvents();
|
|
324
|
-
this.target = null;
|
|
325
|
-
this.config = null;
|
|
336
|
+
this.target = this.config = null;
|
|
326
337
|
}
|
|
327
338
|
}
|
|
328
339
|
}
|
|
@@ -433,7 +444,7 @@ class Renderer {
|
|
|
433
444
|
const { canvas } = this;
|
|
434
445
|
const bounds = block.getIntersect(canvas.bounds);
|
|
435
446
|
const includes = block.includes(this.target.__world);
|
|
436
|
-
const realBounds = new Bounds(
|
|
447
|
+
const realBounds = new Bounds(bounds);
|
|
437
448
|
canvas.save();
|
|
438
449
|
if (includes && !Debug.showRepaint) {
|
|
439
450
|
canvas.clear();
|
|
@@ -483,7 +494,7 @@ class Renderer {
|
|
|
483
494
|
const { updateBlocks: list } = this;
|
|
484
495
|
if (list) {
|
|
485
496
|
const bounds = new Bounds();
|
|
486
|
-
bounds.
|
|
497
|
+
bounds.setList(list);
|
|
487
498
|
list.length = 0;
|
|
488
499
|
list.push(bounds);
|
|
489
500
|
}
|
|
@@ -523,7 +534,7 @@ class Renderer {
|
|
|
523
534
|
empty = (!leaf.__world.width || !leaf.__world.height);
|
|
524
535
|
if (empty) {
|
|
525
536
|
if (!leaf.isLeafer)
|
|
526
|
-
debug$1.
|
|
537
|
+
debug$1.tip(leaf.innerName, ': empty');
|
|
527
538
|
empty = (!leaf.isBranch || leaf.isBranchLeaf);
|
|
528
539
|
}
|
|
529
540
|
return empty;
|
|
@@ -557,6 +568,14 @@ class Renderer {
|
|
|
557
568
|
}
|
|
558
569
|
}
|
|
559
570
|
|
|
571
|
+
var AnswerType;
|
|
572
|
+
(function (AnswerType) {
|
|
573
|
+
AnswerType[AnswerType["No"] = 0] = "No";
|
|
574
|
+
AnswerType[AnswerType["Yes"] = 1] = "Yes";
|
|
575
|
+
AnswerType[AnswerType["NoAndSkip"] = 2] = "NoAndSkip";
|
|
576
|
+
AnswerType[AnswerType["YesAndSkip"] = 3] = "YesAndSkip";
|
|
577
|
+
})(AnswerType || (AnswerType = {}));
|
|
578
|
+
|
|
560
579
|
const { hitRadiusPoint } = BoundsHelper;
|
|
561
580
|
class Pather {
|
|
562
581
|
constructor(target, selector) {
|
|
@@ -601,10 +620,10 @@ class Pather {
|
|
|
601
620
|
getPath(leaf) {
|
|
602
621
|
const path = new LeafList();
|
|
603
622
|
while (leaf) {
|
|
604
|
-
path.
|
|
623
|
+
path.add(leaf);
|
|
605
624
|
leaf = leaf.parent;
|
|
606
625
|
}
|
|
607
|
-
path.
|
|
626
|
+
path.add(this.target);
|
|
608
627
|
return path;
|
|
609
628
|
}
|
|
610
629
|
getHitablePath(leaf) {
|
|
@@ -614,7 +633,7 @@ class Pather {
|
|
|
614
633
|
item = path.list[i];
|
|
615
634
|
if (!item.__.hittable)
|
|
616
635
|
break;
|
|
617
|
-
hittablePath.
|
|
636
|
+
hittablePath.addAt(item, 0);
|
|
618
637
|
if (!item.__.hitChildren)
|
|
619
638
|
break;
|
|
620
639
|
}
|
|
@@ -633,7 +652,7 @@ class Pather {
|
|
|
633
652
|
leaf = path.list[j];
|
|
634
653
|
if (nextPath && nextPath.has(leaf))
|
|
635
654
|
break;
|
|
636
|
-
throughPath.
|
|
655
|
+
throughPath.add(leaf);
|
|
637
656
|
}
|
|
638
657
|
}
|
|
639
658
|
return throughPath;
|
|
@@ -675,14 +694,15 @@ class Pather {
|
|
|
675
694
|
}
|
|
676
695
|
}
|
|
677
696
|
|
|
697
|
+
const { Yes, NoAndSkip, YesAndSkip } = AnswerType;
|
|
678
698
|
class Selector {
|
|
679
699
|
constructor(target, userConfig) {
|
|
680
700
|
this.config = {};
|
|
681
701
|
this.innerIdMap = {};
|
|
682
702
|
this.idMap = {};
|
|
683
703
|
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,
|
|
704
|
+
id: (leaf, name) => leaf.id === name ? (this.idMap[name] = leaf, 1) : 0,
|
|
705
|
+
innerId: (leaf, innerId) => leaf.innerId === innerId ? (this.innerIdMap[innerId] = leaf, 1) : 0,
|
|
686
706
|
className: (leaf, name) => leaf.className === name ? 1 : 0,
|
|
687
707
|
tag: (leaf, name) => leaf.__tag === name ? 1 : 0
|
|
688
708
|
};
|
|
@@ -692,11 +712,6 @@ class Selector {
|
|
|
692
712
|
this.pather = new Pather(target, this);
|
|
693
713
|
this.__listenEvents();
|
|
694
714
|
}
|
|
695
|
-
getByPoint(hitPoint, hitRadius, options) {
|
|
696
|
-
if (Platform.name === 'node')
|
|
697
|
-
this.target.emit(LayoutEvent.CHECK_UPDATE);
|
|
698
|
-
return this.pather.getByPoint(hitPoint, hitRadius, options);
|
|
699
|
-
}
|
|
700
715
|
getBy(condition, branch, one, options) {
|
|
701
716
|
switch (typeof condition) {
|
|
702
717
|
case 'number':
|
|
@@ -716,6 +731,11 @@ class Selector {
|
|
|
716
731
|
return this.getByMethod(condition, branch, one, options);
|
|
717
732
|
}
|
|
718
733
|
}
|
|
734
|
+
getByPoint(hitPoint, hitRadius, options) {
|
|
735
|
+
if (Platform.name === 'node')
|
|
736
|
+
this.target.emit(LayoutEvent.CHECK_UPDATE);
|
|
737
|
+
return this.pather.getByPoint(hitPoint, hitRadius, options);
|
|
738
|
+
}
|
|
719
739
|
getByInnerId(innerId, branch) {
|
|
720
740
|
const cache = this.innerIdMap[innerId];
|
|
721
741
|
if (cache)
|
|
@@ -742,10 +762,11 @@ class Selector {
|
|
|
742
762
|
return list || this.findLeaf;
|
|
743
763
|
}
|
|
744
764
|
eachFind(children, method, list, options) {
|
|
745
|
-
let child;
|
|
765
|
+
let child, result;
|
|
746
766
|
for (let i = 0, len = children.length; i < len; i++) {
|
|
747
767
|
child = children[i];
|
|
748
|
-
|
|
768
|
+
result = method(child, options);
|
|
769
|
+
if (result === Yes || result === YesAndSkip) {
|
|
749
770
|
if (list) {
|
|
750
771
|
list.push(child);
|
|
751
772
|
}
|
|
@@ -754,7 +775,7 @@ class Selector {
|
|
|
754
775
|
return;
|
|
755
776
|
}
|
|
756
777
|
}
|
|
757
|
-
if (child.isBranch)
|
|
778
|
+
if (child.isBranch && result < NoAndSkip)
|
|
758
779
|
this.eachFind(child.children, method, list, options);
|
|
759
780
|
}
|
|
760
781
|
}
|
|
@@ -812,6 +833,7 @@ class LeaferCanvas extends LeaferCanvasBase {
|
|
|
812
833
|
view ? this.__createViewFrom(view) : this.__createView();
|
|
813
834
|
const { style } = this.view;
|
|
814
835
|
style.display || (style.display = 'block');
|
|
836
|
+
style.userSelect = 'none';
|
|
815
837
|
this.parentView = this.view.parentElement;
|
|
816
838
|
if (Platform.syncDomFont && !this.parentView) {
|
|
817
839
|
this.view.style.display = 'none';
|
|
@@ -1325,8 +1347,8 @@ function useCanvas(_canvasType, _power) {
|
|
|
1325
1347
|
img.crossOrigin = 'anonymous';
|
|
1326
1348
|
img.onload = () => { resolve(img); };
|
|
1327
1349
|
img.onerror = (e) => { reject(e); };
|
|
1328
|
-
if (!src.startsWith('data:') && Platform.
|
|
1329
|
-
src += (src.includes("?") ? "&" : "?") + Platform.
|
|
1350
|
+
if (!src.startsWith('data:') && Platform.image.suffix)
|
|
1351
|
+
src += (src.includes("?") ? "&" : "?") + Platform.image.suffix;
|
|
1330
1352
|
img.src = src;
|
|
1331
1353
|
});
|
|
1332
1354
|
}
|
|
@@ -1342,8 +1364,7 @@ function useCanvas(_canvasType, _power) {
|
|
|
1342
1364
|
Platform.name = 'web';
|
|
1343
1365
|
Platform.isMobile = 'ontouchstart' in window;
|
|
1344
1366
|
Platform.requestRender = function (render) { window.requestAnimationFrame(render); };
|
|
1345
|
-
Platform.devicePixelRatio = devicePixelRatio;
|
|
1346
|
-
Platform.realtimeLayout = true;
|
|
1367
|
+
Platform.devicePixelRatio = Math.max(1, devicePixelRatio);
|
|
1347
1368
|
const { userAgent } = navigator;
|
|
1348
1369
|
if (userAgent.indexOf("Firefox") > -1) {
|
|
1349
1370
|
Platform.conicGradientRotate90 = true;
|
|
@@ -1364,7 +1385,7 @@ else if (userAgent.indexOf('Linux') > -1) {
|
|
|
1364
1385
|
Platform.os = 'Linux';
|
|
1365
1386
|
}
|
|
1366
1387
|
|
|
1367
|
-
const { get: get$4, rotateOfOuter: rotateOfOuter$2, translate: translate$1, scaleOfOuter: scaleOfOuter$2, scale: scaleHelper
|
|
1388
|
+
const { get: get$4, rotateOfOuter: rotateOfOuter$2, translate: translate$1, scaleOfOuter: scaleOfOuter$2, scale: scaleHelper, rotate } = MatrixHelper;
|
|
1368
1389
|
function fillOrFitMode(data, mode, box, width, height, rotation) {
|
|
1369
1390
|
const transform = get$4();
|
|
1370
1391
|
const swap = rotation && rotation !== 180;
|
|
@@ -1374,7 +1395,7 @@ function fillOrFitMode(data, mode, box, width, height, rotation) {
|
|
|
1374
1395
|
const x = box.x + (box.width - width * scale) / 2;
|
|
1375
1396
|
const y = box.y + (box.height - height * scale) / 2;
|
|
1376
1397
|
translate$1(transform, x, y);
|
|
1377
|
-
scaleHelper
|
|
1398
|
+
scaleHelper(transform, scale);
|
|
1378
1399
|
if (rotation)
|
|
1379
1400
|
rotateOfOuter$2(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
|
|
1380
1401
|
data.scaleX = data.scaleY = scale;
|
|
@@ -1386,7 +1407,7 @@ function clipMode(data, box, offset, scale, rotation) {
|
|
|
1386
1407
|
if (offset)
|
|
1387
1408
|
translate$1(transform, offset.x, offset.y);
|
|
1388
1409
|
if (scale) {
|
|
1389
|
-
typeof scale === 'number' ? scaleHelper
|
|
1410
|
+
typeof scale === 'number' ? scaleHelper(transform, scale) : scaleHelper(transform, scale.x, scale.y);
|
|
1390
1411
|
data.scaleX = transform.a;
|
|
1391
1412
|
data.scaleY = transform.d;
|
|
1392
1413
|
}
|
|
@@ -1421,7 +1442,7 @@ function repeatMode(data, box, width, height, scale, rotation) {
|
|
|
1421
1442
|
const { get: get$3, translate } = MatrixHelper;
|
|
1422
1443
|
function createData(leafPaint, image, paint, box) {
|
|
1423
1444
|
let { width, height } = image;
|
|
1424
|
-
const { opacity, mode, offset, scale, rotation, blendMode } = paint;
|
|
1445
|
+
const { opacity, mode, offset, scale, rotation, blendMode, repeat } = paint;
|
|
1425
1446
|
const sameBox = box.width === width && box.height === height;
|
|
1426
1447
|
if (blendMode)
|
|
1427
1448
|
leafPaint.blendMode = blendMode;
|
|
@@ -1442,6 +1463,8 @@ function createData(leafPaint, image, paint, box) {
|
|
|
1442
1463
|
case 'repeat':
|
|
1443
1464
|
if (!sameBox || scale || rotation)
|
|
1444
1465
|
repeatMode(data, box, width, height, scale, rotation);
|
|
1466
|
+
if (!repeat)
|
|
1467
|
+
data.repeat = 'repeat';
|
|
1445
1468
|
break;
|
|
1446
1469
|
case 'fit':
|
|
1447
1470
|
case 'cover':
|
|
@@ -1453,6 +1476,8 @@ function createData(leafPaint, image, paint, box) {
|
|
|
1453
1476
|
data.height = height;
|
|
1454
1477
|
if (opacity)
|
|
1455
1478
|
data.opacity = opacity;
|
|
1479
|
+
if (repeat)
|
|
1480
|
+
data.repeat = typeof repeat === 'string' ? (repeat === 'x' ? 'repeat-x' : 'repeat-y') : 'repeat';
|
|
1456
1481
|
}
|
|
1457
1482
|
|
|
1458
1483
|
function image(ui, attrName, attrValue, box, firstUse) {
|
|
@@ -1500,6 +1525,10 @@ function hasNaturalSize(ui, attrName, image) {
|
|
|
1500
1525
|
d.__naturalHeight = image.height;
|
|
1501
1526
|
if (!d.__getInput('width') || !d.__getInput('height')) {
|
|
1502
1527
|
ui.forceUpdate('width');
|
|
1528
|
+
if (ui.__proxyData) {
|
|
1529
|
+
ui.setProxyAttr('width', ui.__.width);
|
|
1530
|
+
ui.setProxyAttr('height', ui.__.height);
|
|
1531
|
+
}
|
|
1503
1532
|
return false;
|
|
1504
1533
|
}
|
|
1505
1534
|
}
|
|
@@ -1542,22 +1571,21 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
1542
1571
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
1543
1572
|
};
|
|
1544
1573
|
|
|
1545
|
-
const
|
|
1574
|
+
const Export$1 = {};
|
|
1575
|
+
|
|
1576
|
+
const { get: get$2, scale, copy: copy$1 } = MatrixHelper;
|
|
1546
1577
|
function createPattern(ui, paint, pixelRatio) {
|
|
1547
1578
|
let { scaleX, scaleY } = ui.__world;
|
|
1548
1579
|
const id = scaleX + '-' + scaleY;
|
|
1549
1580
|
if (paint.patternId !== id && !ui.destroyed) {
|
|
1550
|
-
paint.patternId = id;
|
|
1551
1581
|
scaleX = Math.abs(scaleX);
|
|
1552
1582
|
scaleY = Math.abs(scaleY);
|
|
1553
1583
|
const { image, data } = paint;
|
|
1554
|
-
|
|
1555
|
-
const maxHeight = image.isSVG ? 4096 : Math.min(image.height, 4096);
|
|
1556
|
-
let scale, matrix, { width, height, scaleX: sx, scaleY: sy, opacity, transform, mode } = data;
|
|
1584
|
+
let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, opacity, transform, repeat } = data;
|
|
1557
1585
|
if (sx) {
|
|
1558
|
-
|
|
1559
|
-
copy$1(
|
|
1560
|
-
|
|
1586
|
+
imageMatrix = get$2();
|
|
1587
|
+
copy$1(imageMatrix, transform);
|
|
1588
|
+
scale(imageMatrix, 1 / sx, 1 / sy);
|
|
1561
1589
|
scaleX *= sx;
|
|
1562
1590
|
scaleY *= sy;
|
|
1563
1591
|
}
|
|
@@ -1565,38 +1593,49 @@ function createPattern(ui, paint, pixelRatio) {
|
|
|
1565
1593
|
scaleY *= pixelRatio;
|
|
1566
1594
|
width *= scaleX;
|
|
1567
1595
|
height *= scaleY;
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1596
|
+
const size = width * height;
|
|
1597
|
+
if (!repeat) {
|
|
1598
|
+
if (size > Platform.image.maxCacheSize)
|
|
1599
|
+
return false;
|
|
1600
|
+
}
|
|
1601
|
+
let maxSize = Platform.image.maxPatternSize;
|
|
1602
|
+
if (!image.isSVG) {
|
|
1603
|
+
const imageSize = image.width * image.height;
|
|
1604
|
+
if (maxSize > imageSize)
|
|
1605
|
+
maxSize = imageSize;
|
|
1606
|
+
}
|
|
1607
|
+
if (size > maxSize)
|
|
1608
|
+
imageScale = Math.sqrt(size / maxSize);
|
|
1609
|
+
if (imageScale) {
|
|
1610
|
+
scaleX /= imageScale;
|
|
1611
|
+
scaleY /= imageScale;
|
|
1612
|
+
width /= imageScale;
|
|
1613
|
+
height /= imageScale;
|
|
1576
1614
|
}
|
|
1577
1615
|
if (sx) {
|
|
1578
1616
|
scaleX /= sx;
|
|
1579
1617
|
scaleY /= sy;
|
|
1580
1618
|
}
|
|
1581
1619
|
if (transform || scaleX !== 1 || scaleY !== 1) {
|
|
1582
|
-
if (!
|
|
1583
|
-
|
|
1620
|
+
if (!imageMatrix) {
|
|
1621
|
+
imageMatrix = get$2();
|
|
1584
1622
|
if (transform)
|
|
1585
|
-
copy$1(
|
|
1623
|
+
copy$1(imageMatrix, transform);
|
|
1586
1624
|
}
|
|
1587
|
-
|
|
1625
|
+
scale(imageMatrix, 1 / scaleX, 1 / scaleY);
|
|
1588
1626
|
}
|
|
1589
|
-
const
|
|
1627
|
+
const pattern = Platform.canvas.createPattern(image.getCanvas(width < 1 ? 1 : width, height < 1 ? 1 : height, opacity), repeat || (Platform.origin.noRepeat || 'no-repeat'));
|
|
1590
1628
|
try {
|
|
1591
1629
|
if (paint.transform)
|
|
1592
1630
|
paint.transform = null;
|
|
1593
|
-
if (
|
|
1594
|
-
|
|
1631
|
+
if (imageMatrix)
|
|
1632
|
+
pattern.setTransform ? pattern.setTransform(imageMatrix) : paint.transform = imageMatrix;
|
|
1595
1633
|
}
|
|
1596
1634
|
catch (_a) {
|
|
1597
|
-
paint.transform =
|
|
1635
|
+
paint.transform = imageMatrix;
|
|
1598
1636
|
}
|
|
1599
|
-
paint.style =
|
|
1637
|
+
paint.style = pattern;
|
|
1638
|
+
paint.patternId = id;
|
|
1600
1639
|
return true;
|
|
1601
1640
|
}
|
|
1602
1641
|
else {
|
|
@@ -1604,18 +1643,24 @@ function createPattern(ui, paint, pixelRatio) {
|
|
|
1604
1643
|
}
|
|
1605
1644
|
}
|
|
1606
1645
|
|
|
1646
|
+
const { abs } = Math;
|
|
1607
1647
|
function checkImage(ui, canvas, paint, allowPaint) {
|
|
1608
1648
|
const { scaleX, scaleY } = ui.__world;
|
|
1609
1649
|
if (!paint.data || paint.patternId === scaleX + '-' + scaleY) {
|
|
1610
1650
|
return false;
|
|
1611
1651
|
}
|
|
1612
1652
|
else {
|
|
1653
|
+
const { data } = paint;
|
|
1613
1654
|
if (allowPaint) {
|
|
1614
|
-
if (
|
|
1615
|
-
let { width, height } =
|
|
1616
|
-
width *= scaleX * canvas.pixelRatio;
|
|
1617
|
-
height *= scaleY * canvas.pixelRatio;
|
|
1618
|
-
|
|
1655
|
+
if (!data.repeat) {
|
|
1656
|
+
let { width, height } = data;
|
|
1657
|
+
width *= abs(scaleX) * canvas.pixelRatio;
|
|
1658
|
+
height *= abs(scaleY) * canvas.pixelRatio;
|
|
1659
|
+
if (data.scaleX) {
|
|
1660
|
+
width *= data.scaleX;
|
|
1661
|
+
height *= data.scaleY;
|
|
1662
|
+
}
|
|
1663
|
+
allowPaint = width * height > Platform.image.maxCacheSize;
|
|
1619
1664
|
}
|
|
1620
1665
|
else {
|
|
1621
1666
|
allowPaint = false;
|
|
@@ -1624,7 +1669,6 @@ function checkImage(ui, canvas, paint, allowPaint) {
|
|
|
1624
1669
|
if (allowPaint) {
|
|
1625
1670
|
canvas.save();
|
|
1626
1671
|
canvas.clip();
|
|
1627
|
-
const { data } = paint;
|
|
1628
1672
|
if (paint.blendMode)
|
|
1629
1673
|
canvas.blendMode = paint.blendMode;
|
|
1630
1674
|
if (data.opacity)
|
|
@@ -1636,7 +1680,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
|
|
|
1636
1680
|
return true;
|
|
1637
1681
|
}
|
|
1638
1682
|
else {
|
|
1639
|
-
if (!paint.style) {
|
|
1683
|
+
if (!paint.style || Export$1.running) {
|
|
1640
1684
|
createPattern(ui, paint, canvas.pixelRatio);
|
|
1641
1685
|
}
|
|
1642
1686
|
else {
|
|
@@ -1655,7 +1699,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
|
|
|
1655
1699
|
}
|
|
1656
1700
|
|
|
1657
1701
|
function recycleImage(attrName, data) {
|
|
1658
|
-
const paints =
|
|
1702
|
+
const paints = data['_' + attrName];
|
|
1659
1703
|
if (paints instanceof Array) {
|
|
1660
1704
|
let image, recycleMap, input, url;
|
|
1661
1705
|
for (let i = 0, len = paints.length; i < len; i++) {
|
|
@@ -1759,7 +1803,7 @@ function drawAlignStroke(align, stroke, isStrokes, ui, canvas, renderOptions) {
|
|
|
1759
1803
|
out.blendMode = align === 'outside' ? 'destination-out' : 'destination-in';
|
|
1760
1804
|
fillText(ui, out);
|
|
1761
1805
|
out.blendMode = 'normal';
|
|
1762
|
-
if (ui.
|
|
1806
|
+
if (ui.__worldFlipped || renderOptions.matrix) {
|
|
1763
1807
|
canvas.copyWorldByReset(out);
|
|
1764
1808
|
}
|
|
1765
1809
|
else {
|
|
@@ -1832,7 +1876,7 @@ function stroke(stroke, ui, canvas, renderOptions) {
|
|
|
1832
1876
|
out.stroke();
|
|
1833
1877
|
options.windingRule ? out.clip(options.windingRule) : out.clip();
|
|
1834
1878
|
out.clearWorld(ui.__layout.renderBounds);
|
|
1835
|
-
if (ui.
|
|
1879
|
+
if (ui.__worldFlipped || renderOptions.matrix) {
|
|
1836
1880
|
canvas.copyWorldByReset(out);
|
|
1837
1881
|
}
|
|
1838
1882
|
else {
|
|
@@ -1872,7 +1916,7 @@ function strokes(strokes, ui, canvas, renderOptions) {
|
|
|
1872
1916
|
drawStrokesStyle(strokes, false, ui, out);
|
|
1873
1917
|
options.windingRule ? out.clip(options.windingRule) : out.clip();
|
|
1874
1918
|
out.clearWorld(renderBounds);
|
|
1875
|
-
if (ui.
|
|
1919
|
+
if (ui.__worldFlipped || renderOptions.matrix) {
|
|
1876
1920
|
canvas.copyWorldByReset(out);
|
|
1877
1921
|
}
|
|
1878
1922
|
else {
|
|
@@ -2096,7 +2140,7 @@ function shadow(ui, current, shape, renderOptions) {
|
|
|
2096
2140
|
}
|
|
2097
2141
|
worldCanvas ? other.copyWorld(worldCanvas, __world, __world, 'destination-out') : other.copyWorld(shape.canvas, shapeBounds, bounds, 'destination-out');
|
|
2098
2142
|
}
|
|
2099
|
-
if (ui.
|
|
2143
|
+
if (ui.__worldFlipped || renderOptions.matrix) {
|
|
2100
2144
|
current.copyWorldByReset(other, copyBounds, __world, item.blendMode);
|
|
2101
2145
|
}
|
|
2102
2146
|
else {
|
|
@@ -2160,7 +2204,7 @@ function innerShadow(ui, current, shape, renderOptions) {
|
|
|
2160
2204
|
copyBounds = bounds;
|
|
2161
2205
|
}
|
|
2162
2206
|
other.fillWorld(copyBounds, item.color, 'source-in');
|
|
2163
|
-
if (ui.
|
|
2207
|
+
if (ui.__worldFlipped || renderOptions.matrix) {
|
|
2164
2208
|
current.copyWorldByReset(other, copyBounds, __world, item.blendMode);
|
|
2165
2209
|
}
|
|
2166
2210
|
else {
|
|
@@ -2608,6 +2652,7 @@ function decorationText(drawData, style) {
|
|
|
2608
2652
|
}
|
|
2609
2653
|
}
|
|
2610
2654
|
|
|
2655
|
+
const { top, right, bottom, left } = Direction4;
|
|
2611
2656
|
const TextConvert = {
|
|
2612
2657
|
getDrawData(content, style) {
|
|
2613
2658
|
if (typeof content !== 'string')
|
|
@@ -2615,16 +2660,15 @@ const TextConvert = {
|
|
|
2615
2660
|
let x = 0, y = 0;
|
|
2616
2661
|
let width = style.__getInput('width') || 0;
|
|
2617
2662
|
let height = style.__getInput('height') || 0;
|
|
2618
|
-
const { textDecoration, __font, padding } = style;
|
|
2663
|
+
const { textDecoration, __font, __padding: padding } = style;
|
|
2619
2664
|
if (padding) {
|
|
2620
|
-
const [top, right, bottom, left] = MathHelper.fourNumber(padding);
|
|
2621
2665
|
if (width) {
|
|
2622
|
-
x = left;
|
|
2623
|
-
width -= (right + left);
|
|
2666
|
+
x = padding[left];
|
|
2667
|
+
width -= (padding[right] + padding[left]);
|
|
2624
2668
|
}
|
|
2625
2669
|
if (height) {
|
|
2626
|
-
y = top;
|
|
2627
|
-
height -= (top + bottom);
|
|
2670
|
+
y = padding[top];
|
|
2671
|
+
height -= (padding[top] + padding[bottom]);
|
|
2628
2672
|
}
|
|
2629
2673
|
}
|
|
2630
2674
|
const drawData = {
|
|
@@ -2634,6 +2678,8 @@ const TextConvert = {
|
|
|
2634
2678
|
font: Platform.canvas.font = __font
|
|
2635
2679
|
};
|
|
2636
2680
|
createRows(drawData, content, style);
|
|
2681
|
+
if (padding)
|
|
2682
|
+
padAutoText(padding, drawData, style, width, height);
|
|
2637
2683
|
layoutText(drawData, style);
|
|
2638
2684
|
layoutChar(drawData, style, width);
|
|
2639
2685
|
if (drawData.overflow)
|
|
@@ -2643,6 +2689,32 @@ const TextConvert = {
|
|
|
2643
2689
|
return drawData;
|
|
2644
2690
|
}
|
|
2645
2691
|
};
|
|
2692
|
+
function padAutoText(padding, drawData, style, width, height) {
|
|
2693
|
+
if (!width) {
|
|
2694
|
+
switch (style.textAlign) {
|
|
2695
|
+
case 'left':
|
|
2696
|
+
offsetText(drawData, 'x', padding[left]);
|
|
2697
|
+
break;
|
|
2698
|
+
case 'right':
|
|
2699
|
+
offsetText(drawData, 'x', -padding[right]);
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
if (!height) {
|
|
2703
|
+
switch (style.verticalAlign) {
|
|
2704
|
+
case 'top':
|
|
2705
|
+
offsetText(drawData, 'y', padding[top]);
|
|
2706
|
+
break;
|
|
2707
|
+
case 'bottom':
|
|
2708
|
+
offsetText(drawData, 'y', -padding[bottom]);
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
2712
|
+
function offsetText(drawData, attrName, value) {
|
|
2713
|
+
const { bounds, rows } = drawData;
|
|
2714
|
+
bounds[attrName] += value;
|
|
2715
|
+
for (let i = 0; i < rows.length; i++)
|
|
2716
|
+
rows[i][attrName] += value;
|
|
2717
|
+
}
|
|
2646
2718
|
|
|
2647
2719
|
const ColorConvert = {
|
|
2648
2720
|
string(color, opacity) {
|
|
@@ -2658,6 +2730,7 @@ const ColorConvert = {
|
|
|
2658
2730
|
|
|
2659
2731
|
const Export = {
|
|
2660
2732
|
export(leaf, filename, options) {
|
|
2733
|
+
Export.running = true;
|
|
2661
2734
|
return addTask((success) => new Promise((resolve) => {
|
|
2662
2735
|
const { leafer } = leaf;
|
|
2663
2736
|
if (leafer) {
|
|
@@ -2695,6 +2768,7 @@ const Export = {
|
|
|
2695
2768
|
}
|
|
2696
2769
|
success({ data });
|
|
2697
2770
|
resolve();
|
|
2771
|
+
Export.running = false;
|
|
2698
2772
|
if (unreal)
|
|
2699
2773
|
canvas.recycle();
|
|
2700
2774
|
}));
|
|
@@ -2702,6 +2776,7 @@ const Export = {
|
|
|
2702
2776
|
else {
|
|
2703
2777
|
success({ data: false });
|
|
2704
2778
|
resolve();
|
|
2779
|
+
Export.running = false;
|
|
2705
2780
|
}
|
|
2706
2781
|
}));
|
|
2707
2782
|
}
|
|
@@ -2719,7 +2794,7 @@ Object.assign(Paint, UIPaint);
|
|
|
2719
2794
|
Object.assign(Effect, UIEffect);
|
|
2720
2795
|
Object.assign(TextConvert$1, TextConvert);
|
|
2721
2796
|
Object.assign(ColorConvert$1, ColorConvert);
|
|
2722
|
-
Object.assign(Export$
|
|
2797
|
+
Object.assign(Export$2, Export);
|
|
2723
2798
|
|
|
2724
2799
|
useCanvas();
|
|
2725
2800
|
|