@leafer-ui/miniapp 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.
@@ -1,7 +1,7 @@
1
- import { LeafList, DataHelper, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, BoundsHelper, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, Platform, AnimateEvent, ResizeEvent, Creator, LeaferCanvasBase, canvasPatch, canvasSizeAttrs, InteractionHelper, InteractionBase, LeaferImage, FileHelper, MatrixHelper, ImageEvent, PointHelper, MathHelper, TaskProcessor } from '@leafer/core';
1
+ import { LeafList, DataHelper, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, Bounds, LeafBoundsHelper, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, Platform, AnimateEvent, ResizeEvent, BoundsHelper, Creator, LeaferCanvasBase, canvasPatch, canvasSizeAttrs, InteractionHelper, InteractionBase, LeaferImage, FileHelper, MatrixHelper, ImageEvent, PointHelper, MathHelper, TaskProcessor } from '@leafer/core';
2
2
  export * from '@leafer/core';
3
3
  export { LeaferImage } from '@leafer/core';
4
- import { ColorConvert as ColorConvert$1, ImageManager as ImageManager$1, Paint, Effect, TextConvert as TextConvert$1, Export as Export$1, Platform as Platform$1 } from '@leafer-ui/core';
4
+ import { ColorConvert as ColorConvert$1, ImageManager as ImageManager$1, Paint, Effect, TextConvert as TextConvert$1, Export as Export$2, Platform as Platform$1 } 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.push(item); });
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.push(event.target);
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.push(event.parent);
58
+ this.__updatedList.add(event.parent);
59
59
  }
60
60
  this.update();
61
61
  }
62
62
  __pushChild(child) {
63
- this.__updatedList.push(child);
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 { updateAllWorldMatrix: updateAllWorldMatrix$1, updateAllWorldOpacity } = LeafHelper;
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
- updateAllWorldMatrix$1(leaf);
111
- levelList.push(leaf);
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.push(leaf);
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 itemList, branch;
126
+ let list, branch, children;
127
127
  boundsList.sort(true);
128
128
  boundsList.levels.forEach(level => {
129
- itemList = boundsList.levelMap[level];
130
- for (let i = 0, len = itemList.length; i < len; i++) {
131
- branch = itemList[i];
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
- for (let j = 0, jLen = branch.children.length; j < jLen; j++) {
134
- if (!branch.children[j].isBranch) {
135
- branch.children[j].__updateWorldBounds();
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.__updateWorldBounds();
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 { setByListWithHandle } = BoundsHelper;
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
- setByListWithHandle(this.beforeBounds, this.updatedList.list, worldBounds);
164
+ this.beforeBounds.setListWithFn(this.updatedList.list, worldBounds);
164
165
  }
165
166
  setAfter() {
166
- setByListWithHandle(this.afterBounds, this.updatedList.list, worldBounds);
167
- this.updatedBounds.setByList([this.beforeBounds, this.afterBounds]);
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.pushList(data.updatedList.list);
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 { updateAllWorldMatrix, updateAllChange } = LeafHelper;
181
- const { pushAllBranchStack, updateWorldBoundsByBranchStack } = BranchHelper;
187
+ const { updateAllMatrix, updateAllChange } = LeafHelper;
182
188
  const debug$1 = 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 => { item.setBefore(); });
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
- updateAllWorldMatrix(target);
295
+ updateAllMatrix(target, true);
287
296
  if (target.isBranch) {
288
- const branchStack = [target];
289
- pushAllBranchStack(target, branchStack);
290
- updateWorldBoundsByBranchStack(branchStack);
297
+ BranchHelper.updateBounds(target);
291
298
  }
292
299
  else {
293
- target.__updateWorldBounds();
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().copy(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.setByList(list);
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.warn(leaf.innerName, ': empty');
537
+ debug.tip(leaf.innerName, ': empty');
527
538
  empty = (!leaf.isBranch || leaf.isBranchLeaf);
528
539
  }
529
540
  return empty;
@@ -557,8 +568,16 @@ 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
- class FindPath {
580
+ class Pather {
562
581
  constructor(target, selector) {
563
582
  this.target = target;
564
583
  this.selector = selector;
@@ -601,10 +620,10 @@ class FindPath {
601
620
  getPath(leaf) {
602
621
  const path = new LeafList();
603
622
  while (leaf) {
604
- path.push(leaf);
623
+ path.add(leaf);
605
624
  leaf = leaf.parent;
606
625
  }
607
- path.push(this.target);
626
+ path.add(this.target);
608
627
  return path;
609
628
  }
610
629
  getHitablePath(leaf) {
@@ -614,7 +633,7 @@ class FindPath {
614
633
  item = path.list[i];
615
634
  if (!item.__.hittable)
616
635
  break;
617
- hittablePath.unshift(item);
636
+ hittablePath.addAt(item, 0);
618
637
  if (!item.__.hitChildren)
619
638
  break;
620
639
  }
@@ -633,7 +652,7 @@ class FindPath {
633
652
  leaf = path.list[j];
634
653
  if (nextPath && nextPath.has(leaf))
635
654
  break;
636
- throughPath.push(leaf);
655
+ throughPath.add(leaf);
637
656
  }
638
657
  }
639
658
  return throughPath;
@@ -675,120 +694,113 @@ class FindPath {
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
- this.innerIdList = {};
682
- this.idList = {};
683
- this.classNameList = {};
684
- this.tagNameList = {};
701
+ this.innerIdMap = {};
702
+ this.idMap = {};
703
+ this.methods = {
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,
706
+ className: (leaf, name) => leaf.className === name ? 1 : 0,
707
+ tag: (leaf, name) => leaf.__tag === name ? 1 : 0
708
+ };
685
709
  this.target = target;
686
710
  if (userConfig)
687
711
  this.config = DataHelper.default(userConfig, this.config);
688
- this.findPath = new FindPath(target, this);
712
+ this.pather = new Pather(target, this);
689
713
  this.__listenEvents();
690
714
  }
715
+ getBy(condition, branch, one, options) {
716
+ switch (typeof condition) {
717
+ case 'number':
718
+ const leaf = this.getByInnerId(condition, branch);
719
+ return one ? leaf : (leaf ? [leaf] : []);
720
+ case 'string':
721
+ switch (condition[0]) {
722
+ case '#':
723
+ const leaf = this.getById(condition.substring(1), branch);
724
+ return one ? leaf : (leaf ? [leaf] : []);
725
+ case '.':
726
+ return this.getByMethod(this.methods.className, branch, one, condition.substring(1));
727
+ default:
728
+ return this.getByMethod(this.methods.tag, branch, one, condition);
729
+ }
730
+ case 'function':
731
+ return this.getByMethod(condition, branch, one, options);
732
+ }
733
+ }
691
734
  getByPoint(hitPoint, hitRadius, options) {
692
735
  if (Platform.name === 'node')
693
736
  this.target.emit(LayoutEvent.CHECK_UPDATE);
694
- return this.findPath.getByPoint(hitPoint, hitRadius, options);
737
+ return this.pather.getByPoint(hitPoint, hitRadius, options);
695
738
  }
696
- find(name, branch) {
697
- if (typeof name === 'number') {
698
- return this.getByInnerId(name, branch);
699
- }
700
- else if (name.startsWith('#')) {
701
- return this.getById(name.substring(1), branch);
702
- }
703
- else if (name.startsWith('.')) {
704
- return this.getByClassName(name.substring(1), branch);
705
- }
706
- else {
707
- return this.getByTagName(name, branch);
708
- }
709
- }
710
- getByInnerId(name, branch) {
711
- let cache = this.innerIdList[name];
739
+ getByInnerId(innerId, branch) {
740
+ const cache = this.innerIdMap[innerId];
712
741
  if (cache)
713
742
  return cache;
714
- if (!branch)
715
- branch = this.target;
716
- let find;
717
- this.loopFind(branch, (leaf) => {
718
- if (leaf.innerId === name) {
719
- find = leaf;
720
- this.innerIdList[name] = find;
721
- return true;
722
- }
723
- else {
724
- return false;
725
- }
726
- });
727
- return find;
743
+ this.eachFind(this.toChildren(branch), this.methods.innerId, null, innerId);
744
+ return this.findLeaf;
728
745
  }
729
- getById(name, branch) {
730
- let cache = this.idList[name];
731
- if (cache)
746
+ getById(id, branch) {
747
+ const cache = this.idMap[id];
748
+ if (cache && LeafHelper.hasParent(cache, branch || this.target))
732
749
  return cache;
733
- if (!branch)
734
- branch = this.target;
735
- let find;
736
- this.loopFind(branch, (leaf) => {
737
- if (leaf.id === name) {
738
- find = leaf;
739
- this.idList[name] = find;
740
- return true;
741
- }
742
- else {
743
- return false;
744
- }
745
- });
746
- return find;
747
- }
748
- getByClassName(name, branch) {
749
- if (!branch)
750
- branch = this.target;
751
- let find = [];
752
- this.loopFind(branch, (leaf) => {
753
- if (leaf.className === name)
754
- find.push(leaf);
755
- return false;
756
- });
757
- return find;
758
- }
759
- getByTagName(name, branch) {
760
- if (!branch)
761
- branch = this.target;
762
- let find = [];
763
- this.loopFind(branch, (leaf) => {
764
- if (leaf.__tag === name)
765
- find.push(leaf);
766
- return false;
767
- });
768
- return find;
750
+ this.eachFind(this.toChildren(branch), this.methods.id, null, id);
751
+ return this.findLeaf;
769
752
  }
770
- loopFind(branch, find) {
771
- if (find(branch))
772
- return;
773
- const { children } = branch;
753
+ getByClassName(className, branch) {
754
+ return this.getByMethod(this.methods.className, branch, false, className);
755
+ }
756
+ getByTag(tag, branch) {
757
+ return this.getByMethod(this.methods.tag, branch, false, tag);
758
+ }
759
+ getByMethod(method, branch, one, options) {
760
+ const list = one ? null : [];
761
+ this.eachFind(this.toChildren(branch), method, list, options);
762
+ return list || this.findLeaf;
763
+ }
764
+ eachFind(children, method, list, options) {
765
+ let child, result;
774
766
  for (let i = 0, len = children.length; i < len; i++) {
775
- branch = children[i];
776
- if (find(branch))
777
- return;
778
- if (branch.isBranch)
779
- this.loopFind(branch, find);
767
+ child = children[i];
768
+ result = method(child, options);
769
+ if (result === Yes || result === YesAndSkip) {
770
+ if (list) {
771
+ list.push(child);
772
+ }
773
+ else {
774
+ this.findLeaf = child;
775
+ return;
776
+ }
777
+ }
778
+ if (child.isBranch && result < NoAndSkip)
779
+ this.eachFind(child.children, method, list, options);
780
780
  }
781
781
  }
782
+ toChildren(branch) {
783
+ this.findLeaf = null;
784
+ return [branch || this.target];
785
+ }
782
786
  __onRemoveChild(event) {
783
- const target = event.target;
784
- if (this.idList[target.id])
785
- this.idList[target.id] = null;
786
- if (this.innerIdList[target.id])
787
- this.innerIdList[target.innerId] = null;
787
+ const { id, innerId } = event.child;
788
+ if (this.idMap[id])
789
+ delete this.idMap[id];
790
+ if (this.innerIdMap[innerId])
791
+ delete this.innerIdMap[innerId];
792
+ }
793
+ __checkIdChange(event) {
794
+ if (event.attrName === 'id') {
795
+ const id = event.oldValue;
796
+ if (this.idMap[id])
797
+ delete this.idMap[id];
798
+ }
788
799
  }
789
800
  __listenEvents() {
790
801
  this.__eventIds = [
791
- this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this)
802
+ this.target.on_(ChildEvent.REMOVE, this.__onRemoveChild, this),
803
+ this.target.on_(PropertyEvent.CHANGE, this.__checkIdChange, this)
792
804
  ];
793
805
  }
794
806
  __removeListenEvents() {
@@ -798,11 +810,10 @@ class Selector {
798
810
  destroy() {
799
811
  if (this.__eventIds.length) {
800
812
  this.__removeListenEvents();
801
- this.findPath.destroy();
802
- this.innerIdList = {};
803
- this.idList = {};
804
- this.classNameList = {};
805
- this.tagNameList = {};
813
+ this.pather.destroy();
814
+ this.findLeaf = null;
815
+ this.innerIdMap = {};
816
+ this.idMap = {};
806
817
  }
807
818
  }
808
819
  }
@@ -1129,9 +1140,8 @@ function useCanvas(_canvasType, app) {
1129
1140
  Platform.name = 'miniapp';
1130
1141
  Platform.requestRender = function (render) { Platform.canvas.view.requestAnimationFrame(render); };
1131
1142
  Platform.devicePixelRatio = wx.getSystemInfoSync().pixelRatio;
1132
- Platform.realtimeLayout = true;
1133
1143
 
1134
- const { get: get$4, rotateOfOuter: rotateOfOuter$2, translate: translate$1, scaleOfOuter: scaleOfOuter$2, scale: scaleHelper$1, rotate } = MatrixHelper;
1144
+ const { get: get$4, rotateOfOuter: rotateOfOuter$2, translate: translate$1, scaleOfOuter: scaleOfOuter$2, scale: scaleHelper, rotate } = MatrixHelper;
1135
1145
  function fillOrFitMode(data, mode, box, width, height, rotation) {
1136
1146
  const transform = get$4();
1137
1147
  const swap = rotation && rotation !== 180;
@@ -1141,7 +1151,7 @@ function fillOrFitMode(data, mode, box, width, height, rotation) {
1141
1151
  const x = box.x + (box.width - width * scale) / 2;
1142
1152
  const y = box.y + (box.height - height * scale) / 2;
1143
1153
  translate$1(transform, x, y);
1144
- scaleHelper$1(transform, scale);
1154
+ scaleHelper(transform, scale);
1145
1155
  if (rotation)
1146
1156
  rotateOfOuter$2(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
1147
1157
  data.scaleX = data.scaleY = scale;
@@ -1153,7 +1163,7 @@ function clipMode(data, box, offset, scale, rotation) {
1153
1163
  if (offset)
1154
1164
  translate$1(transform, offset.x, offset.y);
1155
1165
  if (scale) {
1156
- typeof scale === 'number' ? scaleHelper$1(transform, scale) : scaleHelper$1(transform, scale.x, scale.y);
1166
+ typeof scale === 'number' ? scaleHelper(transform, scale) : scaleHelper(transform, scale.x, scale.y);
1157
1167
  data.scaleX = transform.a;
1158
1168
  data.scaleY = transform.d;
1159
1169
  }
@@ -1266,6 +1276,10 @@ function hasNaturalSize(ui, attrName, image) {
1266
1276
  d.__naturalWidth = image.width;
1267
1277
  d.__naturalHeight = image.height;
1268
1278
  if (!d.__getInput('width') || !d.__getInput('height')) {
1279
+ if (ui.__proxyData) {
1280
+ ui.setProxyAttr('width', ui.__.width);
1281
+ ui.setProxyAttr('height', ui.__.height);
1282
+ }
1269
1283
  ui.forceUpdate('width');
1270
1284
  return false;
1271
1285
  }
@@ -1309,22 +1323,21 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
1309
1323
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1310
1324
  };
1311
1325
 
1312
- const { get: get$2, scale: scaleHelper, copy: copy$1 } = MatrixHelper;
1326
+ const Export$1 = {};
1327
+
1328
+ const { get: get$2, scale, copy: copy$1 } = MatrixHelper;
1313
1329
  function createPattern(ui, paint, pixelRatio) {
1314
1330
  let { scaleX, scaleY } = ui.__world;
1315
1331
  const id = scaleX + '-' + scaleY;
1316
1332
  if (paint.patternId !== id && !ui.destroyed) {
1317
- paint.patternId = id;
1318
1333
  scaleX = Math.abs(scaleX);
1319
1334
  scaleY = Math.abs(scaleY);
1320
1335
  const { image, data } = paint;
1321
- const maxWidth = image.isSVG ? 4096 : Math.min(image.width, 4096);
1322
- const maxHeight = image.isSVG ? 4096 : Math.min(image.height, 4096);
1323
- let scale, matrix, { width, height, scaleX: sx, scaleY: sy, opacity, transform, mode } = data;
1336
+ let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, opacity, transform, mode } = data;
1324
1337
  if (sx) {
1325
- matrix = get$2();
1326
- copy$1(matrix, transform);
1327
- scaleHelper(matrix, 1 / sx, 1 / sy);
1338
+ imageMatrix = get$2();
1339
+ copy$1(imageMatrix, transform);
1340
+ scale(imageMatrix, 1 / sx, 1 / sy);
1328
1341
  scaleX *= sx;
1329
1342
  scaleY *= sy;
1330
1343
  }
@@ -1332,38 +1345,49 @@ function createPattern(ui, paint, pixelRatio) {
1332
1345
  scaleY *= pixelRatio;
1333
1346
  width *= scaleX;
1334
1347
  height *= scaleY;
1335
- if (width > maxWidth || height > maxHeight) {
1336
- scale = Math.max(width / maxWidth, height / maxHeight);
1348
+ const size = width * height;
1349
+ if (paint.data.mode !== 'repeat') {
1350
+ if (size > Platform.image.maxCacheSize)
1351
+ return false;
1352
+ }
1353
+ let maxSize = Platform.image.maxPatternSize;
1354
+ if (!image.isSVG) {
1355
+ const imageSize = image.width * image.height;
1356
+ if (maxSize > imageSize)
1357
+ maxSize = imageSize;
1337
1358
  }
1338
- if (scale) {
1339
- scaleX /= scale;
1340
- scaleY /= scale;
1341
- width /= scale;
1342
- height /= scale;
1359
+ if (size > maxSize)
1360
+ imageScale = Math.sqrt(size / maxSize);
1361
+ if (imageScale) {
1362
+ scaleX /= imageScale;
1363
+ scaleY /= imageScale;
1364
+ width /= imageScale;
1365
+ height /= imageScale;
1343
1366
  }
1344
1367
  if (sx) {
1345
1368
  scaleX /= sx;
1346
1369
  scaleY /= sy;
1347
1370
  }
1348
1371
  if (transform || scaleX !== 1 || scaleY !== 1) {
1349
- if (!matrix) {
1350
- matrix = get$2();
1372
+ if (!imageMatrix) {
1373
+ imageMatrix = get$2();
1351
1374
  if (transform)
1352
- copy$1(matrix, transform);
1375
+ copy$1(imageMatrix, transform);
1353
1376
  }
1354
- scaleHelper(matrix, 1 / scaleX, 1 / scaleY);
1377
+ scale(imageMatrix, 1 / scaleX, 1 / scaleY);
1355
1378
  }
1356
- const style = Platform.canvas.createPattern(image.getCanvas(width < 1 ? 1 : width, height < 1 ? 1 : height, opacity), mode === 'repeat' ? 'repeat' : (Platform.origin.noRepeat || 'no-repeat'));
1379
+ const pattern = Platform.canvas.createPattern(image.getCanvas(width < 1 ? 1 : width, height < 1 ? 1 : height, opacity), mode === 'repeat' ? 'repeat' : (Platform.origin.noRepeat || 'no-repeat'));
1357
1380
  try {
1358
1381
  if (paint.transform)
1359
1382
  paint.transform = null;
1360
- if (matrix)
1361
- style.setTransform ? style.setTransform(matrix) : paint.transform = matrix;
1383
+ if (imageMatrix)
1384
+ pattern.setTransform ? pattern.setTransform(imageMatrix) : paint.transform = imageMatrix;
1362
1385
  }
1363
1386
  catch (_a) {
1364
- paint.transform = matrix;
1387
+ paint.transform = imageMatrix;
1365
1388
  }
1366
- paint.style = style;
1389
+ paint.style = pattern;
1390
+ paint.patternId = id;
1367
1391
  return true;
1368
1392
  }
1369
1393
  else {
@@ -1371,18 +1395,24 @@ function createPattern(ui, paint, pixelRatio) {
1371
1395
  }
1372
1396
  }
1373
1397
 
1398
+ const { abs } = Math;
1374
1399
  function checkImage(ui, canvas, paint, allowPaint) {
1375
1400
  const { scaleX, scaleY } = ui.__world;
1376
1401
  if (!paint.data || paint.patternId === scaleX + '-' + scaleY) {
1377
1402
  return false;
1378
1403
  }
1379
1404
  else {
1405
+ const { data } = paint;
1380
1406
  if (allowPaint) {
1381
- if (paint.image.isSVG && paint.data.mode !== 'repeat') {
1382
- let { width, height } = paint.data;
1383
- width *= scaleX * canvas.pixelRatio;
1384
- height *= scaleY * canvas.pixelRatio;
1385
- allowPaint = width > 4096 || height > 4096;
1407
+ if (data.mode !== 'repeat') {
1408
+ let { width, height } = data;
1409
+ width *= abs(scaleX) * canvas.pixelRatio;
1410
+ height *= abs(scaleY) * canvas.pixelRatio;
1411
+ if (data.scaleX) {
1412
+ width *= data.scaleX;
1413
+ height *= data.scaleY;
1414
+ }
1415
+ allowPaint = width * height > Platform.image.maxCacheSize;
1386
1416
  }
1387
1417
  else {
1388
1418
  allowPaint = false;
@@ -1391,7 +1421,6 @@ function checkImage(ui, canvas, paint, allowPaint) {
1391
1421
  if (allowPaint) {
1392
1422
  canvas.save();
1393
1423
  canvas.clip();
1394
- const { data } = paint;
1395
1424
  if (paint.blendMode)
1396
1425
  canvas.blendMode = paint.blendMode;
1397
1426
  if (data.opacity)
@@ -1403,15 +1432,16 @@ function checkImage(ui, canvas, paint, allowPaint) {
1403
1432
  return true;
1404
1433
  }
1405
1434
  else {
1406
- if (!paint.style) {
1435
+ if (!paint.style || Export$1.running) {
1407
1436
  createPattern(ui, paint, canvas.pixelRatio);
1408
1437
  }
1409
1438
  else {
1410
1439
  if (!paint.patternTask) {
1411
1440
  paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function* () {
1412
1441
  paint.patternTask = null;
1413
- if (canvas.bounds.hit(ui.__world) && createPattern(ui, paint, canvas.pixelRatio))
1414
- ui.forceUpdate('surface');
1442
+ if (canvas.bounds.hit(ui.__world))
1443
+ createPattern(ui, paint, canvas.pixelRatio);
1444
+ ui.forceUpdate('surface');
1415
1445
  }), 300);
1416
1446
  }
1417
1447
  }
@@ -1421,7 +1451,7 @@ function checkImage(ui, canvas, paint, allowPaint) {
1421
1451
  }
1422
1452
 
1423
1453
  function recycleImage(attrName, data) {
1424
- const paints = (attrName === 'fill' ? data._fill : data._stroke);
1454
+ const paints = data['_' + attrName];
1425
1455
  if (paints instanceof Array) {
1426
1456
  let image, recycleMap, input, url;
1427
1457
  for (let i = 0, len = paints.length; i < len; i++) {
@@ -1525,7 +1555,7 @@ function drawAlignStroke(align, stroke, isStrokes, ui, canvas, renderOptions) {
1525
1555
  out.blendMode = align === 'outside' ? 'destination-out' : 'destination-in';
1526
1556
  fillText(ui, out);
1527
1557
  out.blendMode = 'normal';
1528
- if (ui.__hasMirror || renderOptions.matrix) {
1558
+ if (ui.__worldFlipped || renderOptions.matrix) {
1529
1559
  canvas.copyWorldByReset(out);
1530
1560
  }
1531
1561
  else {
@@ -1598,7 +1628,7 @@ function stroke(stroke, ui, canvas, renderOptions) {
1598
1628
  out.stroke();
1599
1629
  options.windingRule ? out.clip(options.windingRule) : out.clip();
1600
1630
  out.clearWorld(ui.__layout.renderBounds);
1601
- if (ui.__hasMirror || renderOptions.matrix) {
1631
+ if (ui.__worldFlipped || renderOptions.matrix) {
1602
1632
  canvas.copyWorldByReset(out);
1603
1633
  }
1604
1634
  else {
@@ -1638,7 +1668,7 @@ function strokes(strokes, ui, canvas, renderOptions) {
1638
1668
  drawStrokesStyle(strokes, false, ui, out);
1639
1669
  options.windingRule ? out.clip(options.windingRule) : out.clip();
1640
1670
  out.clearWorld(renderBounds);
1641
- if (ui.__hasMirror || renderOptions.matrix) {
1671
+ if (ui.__worldFlipped || renderOptions.matrix) {
1642
1672
  canvas.copyWorldByReset(out);
1643
1673
  }
1644
1674
  else {
@@ -1862,7 +1892,7 @@ function shadow(ui, current, shape, renderOptions) {
1862
1892
  }
1863
1893
  worldCanvas ? other.copyWorld(worldCanvas, __world, __world, 'destination-out') : other.copyWorld(shape.canvas, shapeBounds, bounds, 'destination-out');
1864
1894
  }
1865
- if (ui.__hasMirror || renderOptions.matrix) {
1895
+ if (ui.__worldFlipped || renderOptions.matrix) {
1866
1896
  current.copyWorldByReset(other, copyBounds, __world, item.blendMode);
1867
1897
  }
1868
1898
  else {
@@ -1926,7 +1956,7 @@ function innerShadow(ui, current, shape, renderOptions) {
1926
1956
  copyBounds = bounds;
1927
1957
  }
1928
1958
  other.fillWorld(copyBounds, item.color, 'source-in');
1929
- if (ui.__hasMirror || renderOptions.matrix) {
1959
+ if (ui.__worldFlipped || renderOptions.matrix) {
1930
1960
  current.copyWorldByReset(other, copyBounds, __world, item.blendMode);
1931
1961
  }
1932
1962
  else {
@@ -2075,6 +2105,8 @@ function createRows(drawData, content, style) {
2075
2105
  const { width, height } = bounds;
2076
2106
  const charMode = width || height || __letterSpacing || (textCase !== 'none');
2077
2107
  if (charMode) {
2108
+ const wrap = style.textWrap !== 'none';
2109
+ const breakAll = style.textWrap === 'break';
2078
2110
  paraStart = true;
2079
2111
  lastCharType = null;
2080
2112
  startCharSize = charWidth = charSize = wordWidth = rowWidth = 0;
@@ -2101,16 +2133,23 @@ function createRows(drawData, content, style) {
2101
2133
  langBreak = (charType === Single && (lastCharType === Single || lastCharType === Letter)) || (lastCharType === Single && charType !== After);
2102
2134
  afterBreak = ((charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After));
2103
2135
  realWidth = paraStart && paraIndent ? width - paraIndent : width;
2104
- if (width && rowWidth + wordWidth + charWidth > realWidth) {
2105
- if (!afterBreak)
2106
- afterBreak = charType === Letter && lastCharType == After;
2107
- if (langBreak || afterBreak || charType === Break || charType === Before || charType === Single || (wordWidth + charWidth > realWidth)) {
2136
+ if (wrap && (width && rowWidth + wordWidth + charWidth > realWidth)) {
2137
+ if (breakAll) {
2108
2138
  if (wordWidth)
2109
2139
  addWord();
2110
2140
  addRow();
2111
2141
  }
2112
2142
  else {
2113
- addRow();
2143
+ if (!afterBreak)
2144
+ afterBreak = charType === Letter && lastCharType == After;
2145
+ if (langBreak || afterBreak || charType === Break || charType === Before || charType === Single || (wordWidth + charWidth > realWidth)) {
2146
+ if (wordWidth)
2147
+ addWord();
2148
+ addRow();
2149
+ }
2150
+ else {
2151
+ addRow();
2152
+ }
2114
2153
  }
2115
2154
  }
2116
2155
  if (char === ' ' && paraStart !== true && (rowWidth + wordWidth) === 0) ;
@@ -2180,7 +2219,7 @@ function addRow() {
2180
2219
 
2181
2220
  const CharMode = 0;
2182
2221
  const WordMode = 1;
2183
- const RowMode = 2;
2222
+ const TextMode = 2;
2184
2223
  function layoutChar(drawData, style, width, _height) {
2185
2224
  const { rows } = drawData;
2186
2225
  const { textAlign, paraIndent, letterSpacing } = style;
@@ -2189,15 +2228,12 @@ function layoutChar(drawData, style, width, _height) {
2189
2228
  if (row.words) {
2190
2229
  indentWidth = paraIndent && row.paraStart ? paraIndent : 0;
2191
2230
  addWordWidth = (width && textAlign === 'justify' && row.words.length > 1) ? (width - row.width - indentWidth) / (row.words.length - 1) : 0;
2192
- mode = (letterSpacing || row.isOverflow) ? CharMode : (addWordWidth > 0.01 ? WordMode : RowMode);
2193
- if (mode === RowMode) {
2194
- row.text = '';
2231
+ mode = (letterSpacing || row.isOverflow) ? CharMode : (addWordWidth > 0.01 ? WordMode : TextMode);
2232
+ if (row.isOverflow && !letterSpacing)
2233
+ row.textMode = true;
2234
+ if (mode === TextMode) {
2195
2235
  row.x += indentWidth;
2196
- row.words.forEach(word => {
2197
- word.data.forEach(char => {
2198
- row.text += char.char;
2199
- });
2200
- });
2236
+ toTextChar$1(row);
2201
2237
  }
2202
2238
  else {
2203
2239
  row.x += indentWidth;
@@ -2223,6 +2259,14 @@ function layoutChar(drawData, style, width, _height) {
2223
2259
  }
2224
2260
  });
2225
2261
  }
2262
+ function toTextChar$1(row) {
2263
+ row.text = '';
2264
+ row.words.forEach(word => {
2265
+ word.data.forEach(char => {
2266
+ row.text += char.char;
2267
+ });
2268
+ });
2269
+ }
2226
2270
  function toWordChar(data, charX, wordChar) {
2227
2271
  data.forEach(char => {
2228
2272
  wordChar.char += char.char;
@@ -2243,10 +2287,10 @@ function toChar(data, charX, rowData) {
2243
2287
 
2244
2288
  function layoutText(drawData, style) {
2245
2289
  const { rows, bounds } = drawData;
2246
- const { __lineHeight, __baseLine, __letterSpacing, textAlign, verticalAlign, paraSpacing, textOverflow } = style;
2290
+ const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing } = style;
2247
2291
  let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
2248
2292
  let starY = __baseLine;
2249
- if (textOverflow !== 'show' && realHeight > height) {
2293
+ if (__clipText && realHeight > height) {
2250
2294
  realHeight = Math.max(height, __lineHeight);
2251
2295
  drawData.overflow = rows.length;
2252
2296
  }
@@ -2295,39 +2339,58 @@ function layoutText(drawData, style) {
2295
2339
  bounds.x = rowX;
2296
2340
  if (rowWidth > bounds.width)
2297
2341
  bounds.width = rowWidth;
2342
+ if (__clipText && width && width < rowWidth) {
2343
+ row.isOverflow = true;
2344
+ if (!drawData.overflow)
2345
+ drawData.overflow = rows.length;
2346
+ }
2298
2347
  }
2299
2348
  bounds.y = y;
2300
2349
  bounds.height = realHeight;
2301
2350
  }
2302
2351
 
2303
- function clipText(drawData, textOverflow) {
2352
+ function clipText(drawData, style) {
2304
2353
  const { rows, overflow } = drawData;
2354
+ let { textOverflow } = style;
2305
2355
  rows.splice(overflow);
2306
2356
  if (textOverflow !== 'hide') {
2307
2357
  if (textOverflow === 'ellipsis')
2308
2358
  textOverflow = '...';
2359
+ let char, charRight;
2309
2360
  const ellipsisWidth = Platform.canvas.measureText(textOverflow).width;
2310
- const row = rows[overflow - 1];
2311
- let char, end = row.data.length - 1, charRight;
2312
- const { x, width } = drawData.bounds;
2313
- const right = x + width - ellipsisWidth;
2314
- for (let i = end; i > -1; i--) {
2315
- char = row.data[i];
2316
- charRight = char.x + char.width;
2317
- if (i === end && charRight < right) {
2318
- break;
2319
- }
2320
- else if (charRight < right && char.char !== ' ') {
2321
- row.data.splice(i + 1);
2322
- row.width -= char.width;
2323
- break;
2361
+ const right = style.x + style.width - ellipsisWidth;
2362
+ const list = style.textWrap === 'none' ? rows : [rows[overflow - 1]];
2363
+ list.forEach(row => {
2364
+ if (row.isOverflow && row.data) {
2365
+ let end = row.data.length - 1;
2366
+ for (let i = end; i > -1; i--) {
2367
+ char = row.data[i];
2368
+ charRight = char.x + char.width;
2369
+ if (i === end && charRight < right) {
2370
+ break;
2371
+ }
2372
+ else if (charRight < right && char.char !== ' ') {
2373
+ row.data.splice(i + 1);
2374
+ row.width -= char.width;
2375
+ break;
2376
+ }
2377
+ row.width -= char.width;
2378
+ }
2379
+ row.width += ellipsisWidth;
2380
+ row.data.push({ char: textOverflow, x: charRight });
2381
+ if (row.textMode)
2382
+ toTextChar(row);
2324
2383
  }
2325
- row.width -= char.width;
2326
- }
2327
- row.width += ellipsisWidth;
2328
- row.data.push({ char: textOverflow, x: charRight });
2384
+ });
2329
2385
  }
2330
2386
  }
2387
+ function toTextChar(row) {
2388
+ row.text = '';
2389
+ row.data.forEach(char => {
2390
+ row.text += char.char;
2391
+ });
2392
+ row.data = null;
2393
+ }
2331
2394
 
2332
2395
  function decorationText(drawData, style) {
2333
2396
  const { fontSize } = style;
@@ -2348,7 +2411,7 @@ const TextConvert = {
2348
2411
  let x = 0, y = 0;
2349
2412
  let width = style.__getInput('width') || 0;
2350
2413
  let height = style.__getInput('height') || 0;
2351
- const { textDecoration, textOverflow, __font, padding } = style;
2414
+ const { textDecoration, __font, padding } = style;
2352
2415
  if (padding) {
2353
2416
  const [top, right, bottom, left] = MathHelper.fourNumber(padding);
2354
2417
  if (width) {
@@ -2370,7 +2433,7 @@ const TextConvert = {
2370
2433
  layoutText(drawData, style);
2371
2434
  layoutChar(drawData, style, width);
2372
2435
  if (drawData.overflow)
2373
- clipText(drawData, textOverflow);
2436
+ clipText(drawData, style);
2374
2437
  if (textDecoration !== 'none')
2375
2438
  decorationText(drawData, style);
2376
2439
  return drawData;
@@ -2391,6 +2454,7 @@ const ColorConvert = {
2391
2454
 
2392
2455
  const Export = {
2393
2456
  export(leaf, filename, options) {
2457
+ Export.running = true;
2394
2458
  return addTask((success) => new Promise((resolve) => {
2395
2459
  const { leafer } = leaf;
2396
2460
  if (leafer) {
@@ -2428,6 +2492,7 @@ const Export = {
2428
2492
  }
2429
2493
  success({ data });
2430
2494
  resolve();
2495
+ Export.running = false;
2431
2496
  if (unreal)
2432
2497
  canvas.recycle();
2433
2498
  }));
@@ -2435,6 +2500,7 @@ const Export = {
2435
2500
  else {
2436
2501
  success({ data: false });
2437
2502
  resolve();
2503
+ Export.running = false;
2438
2504
  }
2439
2505
  }));
2440
2506
  }
@@ -2452,7 +2518,7 @@ Object.assign(Paint, UIPaint);
2452
2518
  Object.assign(Effect, UIEffect);
2453
2519
  Object.assign(TextConvert$1, TextConvert);
2454
2520
  Object.assign(ColorConvert$1, ColorConvert);
2455
- Object.assign(Export$1, Export);
2521
+ Object.assign(Export$2, Export);
2456
2522
 
2457
2523
  try {
2458
2524
  useCanvas('wx', wx);