@leafer-ui/node 1.7.0 → 1.9.0

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.esm.js CHANGED
@@ -1,45 +1,54 @@
1
- import { LeaferCanvasBase, Platform, canvasPatch, FileHelper, Creator, LeaferImage, defineKey, LeafList, DataHelper, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, LeafBoundsHelper, Bounds, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, ResizeEvent, BoundsHelper, Plugin, MatrixHelper, MathHelper, AlignHelper, PointHelper, ImageEvent, AroundHelper, Direction4 } from '@leafer/core';
2
- export * from '@leafer/core';
3
- export { LeaferImage } from '@leafer/core';
4
- import { writeFileSync } from 'fs';
5
- import { HitCanvasManager, InteractionBase } from '@leafer-ui/core';
6
- export * from '@leafer-ui/core';
7
- import { PaintImage, Paint, ColorConvert, PaintGradient, Export, Group, TextConvert, Effect, TwoPointBoundsHelper, Bounds as Bounds$1, FileHelper as FileHelper$1, Platform as Platform$1, Matrix, MathHelper as MathHelper$1, Creator as Creator$1, TaskProcessor, Resource, LeaferCanvasBase as LeaferCanvasBase$1, Debug as Debug$1, Plugin as Plugin$1, UI } from '@leafer-ui/draw';
8
-
9
- /******************************************************************************
10
- Copyright (c) Microsoft Corporation.
11
-
12
- Permission to use, copy, modify, and/or distribute this software for any
13
- purpose with or without fee is hereby granted.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
16
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
17
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
18
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
19
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21
- PERFORMANCE OF THIS SOFTWARE.
22
- ***************************************************************************** */
23
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
24
-
25
-
26
- function __awaiter(thisArg, _arguments, P, generator) {
27
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28
- return new (P || (P = Promise))(function (resolve, reject) {
29
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
- step((generator = generator.apply(thisArg, _arguments || [])).next());
33
- });
34
- }
35
-
36
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
37
- var e = new Error(message);
38
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1
+ import { LeaferCanvasBase, Platform, canvasPatch, FileHelper, Creator, LeaferImage, defineKey, LeafList, DataHelper, RenderEvent, ChildEvent, WatchEvent, PropertyEvent, LeafHelper, BranchHelper, LeafBoundsHelper, Bounds, isArray, Debug, LeafLevelList, LayoutEvent, Run, ImageManager, ResizeEvent, BoundsHelper, Plugin, isObject, Matrix, isUndefined, isString, getMatrixData, MatrixHelper, MathHelper, AlignHelper, PointHelper, ImageEvent, AroundHelper, Direction4, isNumber } from "@leafer/core";
2
+
3
+ export * from "@leafer/core";
4
+
5
+ export { LeaferImage } from "@leafer/core";
6
+
7
+ import { writeFileSync } from "fs";
8
+
9
+ import { HitCanvasManager, InteractionBase } from "@leafer-ui/core";
10
+
11
+ export * from "@leafer-ui/core";
12
+
13
+ import { PaintImage, Paint, ColorConvert, PaintGradient, Export, Group, TextConvert, Effect, TwoPointBoundsHelper, Bounds as Bounds$1, FileHelper as FileHelper$1, Platform as Platform$1, isUndefined as isUndefined$1, Matrix as Matrix$1, MathHelper as MathHelper$1, Creator as Creator$1, TaskProcessor, Resource, LeaferCanvasBase as LeaferCanvasBase$1, Debug as Debug$1, Plugin as Plugin$1, UI } from "@leafer-ui/draw";
14
+
15
+ function __awaiter(thisArg, _arguments, P, generator) {
16
+ function adopt(value) {
17
+ return value instanceof P ? value : new P(function(resolve) {
18
+ resolve(value);
19
+ });
20
+ }
21
+ return new (P || (P = Promise))(function(resolve, reject) {
22
+ function fulfilled(value) {
23
+ try {
24
+ step(generator.next(value));
25
+ } catch (e) {
26
+ reject(e);
27
+ }
28
+ }
29
+ function rejected(value) {
30
+ try {
31
+ step(generator["throw"](value));
32
+ } catch (e) {
33
+ reject(e);
34
+ }
35
+ }
36
+ function step(result) {
37
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
38
+ }
39
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
40
+ });
41
+ }
42
+
43
+ typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
44
+ var e = new Error(message);
45
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
39
46
  };
40
47
 
41
48
  class LeaferCanvas extends LeaferCanvasBase {
42
- get allowBackgroundColor() { return true; }
49
+ get allowBackgroundColor() {
50
+ return true;
51
+ }
43
52
  init() {
44
53
  this.__createView();
45
54
  this.__createContext();
@@ -53,84 +62,114 @@ class LeaferCanvas extends LeaferCanvasBase {
53
62
  this.view = Platform.origin.createCanvas(1, 1);
54
63
  }
55
64
  updateViewSize() {
56
- const { width, height, pixelRatio } = this;
65
+ const {width: width, height: height, pixelRatio: pixelRatio} = this;
57
66
  this.view.width = Math.ceil(width * pixelRatio);
58
67
  this.view.height = Math.ceil(height * pixelRatio);
59
68
  this.clientBounds = this.bounds;
60
69
  }
61
70
  }
62
71
 
63
- const { mineType, fileType } = FileHelper;
72
+ const {mineType: mineType, fileType: fileType} = FileHelper;
73
+
64
74
  Object.assign(Creator, {
65
75
  canvas: (options, manager) => new LeaferCanvas(options, manager),
66
- image: (options) => new LeaferImage(options)
76
+ image: options => new LeaferImage(options)
67
77
  });
78
+
68
79
  function useCanvas(canvasType, power) {
69
80
  Platform.canvasType = canvasType;
70
81
  if (!Platform.origin) {
71
- if (canvasType === 'skia') {
72
- const { Canvas, loadImage } = power;
82
+ if (canvasType === "skia") {
83
+ const {Canvas: Canvas, loadImage: loadImage} = power;
73
84
  Platform.origin = {
74
85
  createCanvas: (width, height, format) => new Canvas(width, height, format),
75
- canvasToDataURL: (canvas, type, quality) => canvas.toDataURLSync(type, { quality }),
76
- canvasToBolb: (canvas, type, quality) => canvas.toBuffer(type, { quality }),
77
- canvasSaveAs: (canvas, filename, quality) => canvas.saveAs(filename, { quality }),
78
- download(_url, _filename) { return undefined; },
79
- loadImage(src) { return loadImage(Platform.image.getRealURL(src)); }
86
+ canvasToDataURL: (canvas, type, quality) => canvas.toDataURLSync(type, {
87
+ quality: quality
88
+ }),
89
+ canvasToBolb: (canvas, type, quality) => canvas.toBuffer(type, {
90
+ quality: quality
91
+ }),
92
+ canvasSaveAs: (canvas, filename, quality) => canvas.saveAs(filename, {
93
+ quality: quality
94
+ }),
95
+ download(_url, _filename) {
96
+ return undefined;
97
+ },
98
+ loadImage(src) {
99
+ return loadImage(Platform.image.getRealURL(src));
100
+ }
80
101
  };
81
102
  Platform.roundRectPatch = true;
82
- }
83
- else if (canvasType === 'napi') {
84
- const { Canvas, loadImage } = power;
103
+ } else if (canvasType === "napi") {
104
+ const {Canvas: Canvas, loadImage: loadImage} = power;
85
105
  Platform.origin = {
86
106
  createCanvas: (width, height, format) => new Canvas(width, height, format),
87
107
  canvasToDataURL: (canvas, type, quality) => canvas.toDataURL(mineType(type), quality),
88
- canvasToBolb: (canvas, type, quality) => __awaiter(this, void 0, void 0, function* () { return canvas.toBuffer(mineType(type), quality); }),
89
- canvasSaveAs: (canvas, filename, quality) => __awaiter(this, void 0, void 0, function* () { return writeFileSync(filename, canvas.toBuffer(mineType(fileType(filename)), quality)); }),
90
- download(_url, _filename) { return undefined; },
91
- loadImage(src) { return loadImage(Platform.image.getRealURL(src)); }
108
+ canvasToBolb: (canvas, type, quality) => __awaiter(this, void 0, void 0, function*() {
109
+ return canvas.toBuffer(mineType(type), quality);
110
+ }),
111
+ canvasSaveAs: (canvas, filename, quality) => __awaiter(this, void 0, void 0, function*() {
112
+ return writeFileSync(filename, canvas.toBuffer(mineType(fileType(filename)), quality));
113
+ }),
114
+ download(_url, _filename) {
115
+ return undefined;
116
+ },
117
+ loadImage(src) {
118
+ return loadImage(Platform.image.getRealURL(src));
119
+ }
92
120
  };
93
121
  }
94
122
  Platform.ellipseToCurve = true;
95
123
  Platform.event = {
96
- stopDefault(_origin) { },
97
- stopNow(_origin) { },
98
- stop(_origin) { }
124
+ stopDefault(_origin) {},
125
+ stopNow(_origin) {},
126
+ stop(_origin) {}
99
127
  };
100
128
  Platform.canvas = Creator.canvas();
101
129
  }
102
130
  }
103
- Platform.name = 'node';
131
+
132
+ Platform.name = "node";
133
+
104
134
  Platform.backgrounder = true;
105
- Platform.requestRender = function (render) { setTimeout(render, 16); };
106
- defineKey(Platform, 'devicePixelRatio', { get() { return 1; } });
135
+
136
+ Platform.requestRender = function(render) {
137
+ setTimeout(render, 16);
138
+ };
139
+
140
+ defineKey(Platform, "devicePixelRatio", {
141
+ get() {
142
+ return 1;
143
+ }
144
+ });
145
+
107
146
  Platform.conicGradientSupport = true;
108
147
 
109
148
  class Watcher {
110
- get childrenChanged() { return this.hasAdd || this.hasRemove || this.hasVisible; }
149
+ get childrenChanged() {
150
+ return this.hasAdd || this.hasRemove || this.hasVisible;
151
+ }
111
152
  get updatedList() {
112
153
  if (this.hasRemove) {
113
- const updatedList = new LeafList();
114
- this.__updatedList.list.forEach(item => { if (item.leafer)
115
- updatedList.add(item); });
154
+ const updatedList = new LeafList;
155
+ this.__updatedList.list.forEach(item => {
156
+ if (item.leafer) updatedList.add(item);
157
+ });
116
158
  return updatedList;
117
- }
118
- else {
159
+ } else {
119
160
  return this.__updatedList;
120
161
  }
121
162
  }
122
163
  constructor(target, userConfig) {
123
164
  this.totalTimes = 0;
124
165
  this.config = {};
125
- this.__updatedList = new LeafList();
166
+ this.__updatedList = new LeafList;
126
167
  this.target = target;
127
- if (userConfig)
128
- this.config = DataHelper.default(userConfig, this.config);
168
+ if (userConfig) this.config = DataHelper.default(userConfig, this.config);
129
169
  this.__listenEvents();
130
170
  }
131
171
  start() {
132
- if (this.disabled)
133
- return;
172
+ if (this.disabled) return;
134
173
  this.running = true;
135
174
  }
136
175
  stop() {
@@ -143,8 +182,7 @@ class Watcher {
143
182
  }
144
183
  update() {
145
184
  this.changed = true;
146
- if (this.running)
147
- this.target.emit(RenderEvent.REQUEST);
185
+ if (this.running) this.target.emit(RenderEvent.REQUEST);
148
186
  }
149
187
  __onAttrChange(event) {
150
188
  this.__updatedList.add(event.target);
@@ -154,8 +192,7 @@ class Watcher {
154
192
  if (event.type === ChildEvent.ADD) {
155
193
  this.hasAdd = true;
156
194
  this.__pushChild(event.child);
157
- }
158
- else {
195
+ } else {
159
196
  this.hasRemove = true;
160
197
  this.__updatedList.add(event.parent);
161
198
  }
@@ -163,28 +200,22 @@ class Watcher {
163
200
  }
164
201
  __pushChild(child) {
165
202
  this.__updatedList.add(child);
166
- if (child.isBranch)
167
- this.__loopChildren(child);
203
+ if (child.isBranch) this.__loopChildren(child);
168
204
  }
169
205
  __loopChildren(parent) {
170
- const { children } = parent;
171
- for (let i = 0, len = children.length; i < len; i++)
172
- this.__pushChild(children[i]);
206
+ const {children: children} = parent;
207
+ for (let i = 0, len = children.length; i < len; i++) this.__pushChild(children[i]);
173
208
  }
174
209
  __onRquestData() {
175
- this.target.emitEvent(new WatchEvent(WatchEvent.DATA, { updatedList: this.updatedList }));
176
- this.__updatedList = new LeafList();
210
+ this.target.emitEvent(new WatchEvent(WatchEvent.DATA, {
211
+ updatedList: this.updatedList
212
+ }));
213
+ this.__updatedList = new LeafList;
177
214
  this.totalTimes++;
178
215
  this.changed = this.hasVisible = this.hasRemove = this.hasAdd = false;
179
216
  }
180
217
  __listenEvents() {
181
- this.__eventIds = [
182
- this.target.on_([
183
- [PropertyEvent.CHANGE, this.__onAttrChange, this],
184
- [[ChildEvent.ADD, ChildEvent.REMOVE], this.__onChildEvent, this],
185
- [WatchEvent.REQUEST, this.__onRquestData, this]
186
- ])
187
- ];
218
+ this.__eventIds = [ this.target.on_([ [ PropertyEvent.CHANGE, this.__onAttrChange, this ], [ [ ChildEvent.ADD, ChildEvent.REMOVE ], this.__onChildEvent, this ], [ WatchEvent.REQUEST, this.__onRquestData, this ] ]) ];
188
219
  }
189
220
  __removeListenEvents() {
190
221
  this.target.off_(this.__eventIds);
@@ -198,8 +229,10 @@ class Watcher {
198
229
  }
199
230
  }
200
231
 
201
- const { updateAllMatrix: updateAllMatrix$1, updateBounds: updateOneBounds, updateChange: updateOneChange } = LeafHelper;
202
- const { pushAllChildBranch, pushAllParent } = BranchHelper;
232
+ const {updateAllMatrix: updateAllMatrix$1, updateBounds: updateOneBounds, updateChange: updateOneChange} = LeafHelper;
233
+
234
+ const {pushAllChildBranch: pushAllChildBranch, pushAllParent: pushAllParent} = BranchHelper;
235
+
203
236
  function updateMatrix(updateList, levelList) {
204
237
  let layout;
205
238
  updateList.list.forEach(leaf => {
@@ -208,19 +241,17 @@ function updateMatrix(updateList, levelList) {
208
241
  if (layout.matrixChanged) {
209
242
  updateAllMatrix$1(leaf, true);
210
243
  levelList.add(leaf);
211
- if (leaf.isBranch)
212
- pushAllChildBranch(leaf, levelList);
244
+ if (leaf.isBranch) pushAllChildBranch(leaf, levelList);
213
245
  pushAllParent(leaf, levelList);
214
- }
215
- else if (layout.boundsChanged) {
246
+ } else if (layout.boundsChanged) {
216
247
  levelList.add(leaf);
217
- if (leaf.isBranch)
218
- leaf.__tempNumber = 0;
248
+ if (leaf.isBranch) leaf.__tempNumber = 0;
219
249
  pushAllParent(leaf, levelList);
220
250
  }
221
251
  }
222
252
  });
223
253
  }
254
+
224
255
  function updateBounds(boundsList) {
225
256
  let list, branch, children;
226
257
  boundsList.sort(true);
@@ -240,18 +271,19 @@ function updateBounds(boundsList) {
240
271
  }
241
272
  });
242
273
  }
274
+
243
275
  function updateChange(updateList) {
244
276
  updateList.list.forEach(updateOneChange);
245
277
  }
246
278
 
247
- const { worldBounds } = LeafBoundsHelper;
279
+ const {worldBounds: worldBounds} = LeafBoundsHelper;
280
+
248
281
  class LayoutBlockData {
249
282
  constructor(list) {
250
- this.updatedBounds = new Bounds();
251
- this.beforeBounds = new Bounds();
252
- this.afterBounds = new Bounds();
253
- if (list instanceof Array)
254
- list = new LeafList(list);
283
+ this.updatedBounds = new Bounds;
284
+ this.beforeBounds = new Bounds;
285
+ this.afterBounds = new Bounds;
286
+ if (isArray(list)) list = new LeafList(list);
255
287
  this.updatedList = list;
256
288
  }
257
289
  setBefore() {
@@ -259,7 +291,7 @@ class LayoutBlockData {
259
291
  }
260
292
  setAfter() {
261
293
  this.afterBounds.setListWithFn(this.updatedList.list, worldBounds);
262
- this.updatedBounds.setList([this.beforeBounds, this.afterBounds]);
294
+ this.updatedBounds.setList([ this.beforeBounds, this.afterBounds ]);
263
295
  }
264
296
  merge(data) {
265
297
  this.updatedList.addList(data.updatedList.list);
@@ -272,21 +304,21 @@ class LayoutBlockData {
272
304
  }
273
305
  }
274
306
 
275
- const { updateAllMatrix, updateAllChange } = LeafHelper;
276
- const debug$2 = Debug.get('Layouter');
307
+ const {updateAllMatrix: updateAllMatrix, updateAllChange: updateAllChange} = LeafHelper;
308
+
309
+ const debug$2 = Debug.get("Layouter");
310
+
277
311
  class Layouter {
278
312
  constructor(target, userConfig) {
279
313
  this.totalTimes = 0;
280
314
  this.config = {};
281
- this.__levelList = new LeafLevelList();
315
+ this.__levelList = new LeafLevelList;
282
316
  this.target = target;
283
- if (userConfig)
284
- this.config = DataHelper.default(userConfig, this.config);
317
+ if (userConfig) this.config = DataHelper.default(userConfig, this.config);
285
318
  this.__listenEvents();
286
319
  }
287
320
  start() {
288
- if (this.disabled)
289
- return;
321
+ if (this.disabled) return;
290
322
  this.running = true;
291
323
  }
292
324
  stop() {
@@ -298,16 +330,14 @@ class Layouter {
298
330
  this.disabled = true;
299
331
  }
300
332
  layout() {
301
- if (this.layouting || !this.running)
302
- return;
303
- const { target } = this;
333
+ if (this.layouting || !this.running) return;
334
+ const {target: target} = this;
304
335
  this.times = 0;
305
336
  try {
306
337
  target.emit(LayoutEvent.START);
307
338
  this.layoutOnce();
308
339
  target.emitEvent(new LayoutEvent(LayoutEvent.END, this.layoutedBlocks, this.times));
309
- }
310
- catch (e) {
340
+ } catch (e) {
311
341
  debug$2.error(e);
312
342
  }
313
343
  this.layoutedBlocks = null;
@@ -315,24 +345,20 @@ class Layouter {
315
345
  layoutAgain() {
316
346
  if (this.layouting) {
317
347
  this.waitAgain = true;
318
- }
319
- else {
348
+ } else {
320
349
  this.layoutOnce();
321
350
  }
322
351
  }
323
352
  layoutOnce() {
324
- if (this.layouting)
325
- return debug$2.warn('layouting');
326
- if (this.times > 3)
327
- return debug$2.warn('layout max times');
353
+ if (this.layouting) return debug$2.warn("layouting");
354
+ if (this.times > 3) return debug$2.warn("layout max times");
328
355
  this.times++;
329
356
  this.totalTimes++;
330
357
  this.layouting = true;
331
358
  this.target.emit(WatchEvent.REQUEST);
332
359
  if (this.totalTimes > 1) {
333
360
  this.partLayout();
334
- }
335
- else {
361
+ } else {
336
362
  this.fullLayout();
337
363
  }
338
364
  this.layouting = false;
@@ -343,11 +369,10 @@ class Layouter {
343
369
  }
344
370
  partLayout() {
345
371
  var _a;
346
- if (!((_a = this.__updatedList) === null || _a === void 0 ? void 0 : _a.length))
347
- return;
348
- const t = Run.start('PartLayout');
349
- const { target, __updatedList: updateList } = this;
350
- const { BEFORE, LAYOUT, AFTER } = LayoutEvent;
372
+ if (!((_a = this.__updatedList) === null || _a === void 0 ? void 0 : _a.length)) return;
373
+ const t = Run.start("PartLayout");
374
+ const {target: target, __updatedList: updateList} = this;
375
+ const {BEFORE: BEFORE, LAYOUT: LAYOUT, AFTER: AFTER} = LayoutEvent;
351
376
  const blocks = this.getBlocks(updateList);
352
377
  blocks.forEach(item => item.setBefore());
353
378
  target.emitEvent(new LayoutEvent(BEFORE, blocks, this.times));
@@ -356,8 +381,7 @@ class Layouter {
356
381
  updateMatrix(updateList, this.__levelList);
357
382
  updateBounds(this.__levelList);
358
383
  updateChange(updateList);
359
- if (this.extraBlock)
360
- blocks.push(this.extraBlock);
384
+ if (this.extraBlock) blocks.push(this.extraBlock);
361
385
  blocks.forEach(item => item.setAfter());
362
386
  target.emitEvent(new LayoutEvent(LAYOUT, blocks, this.times));
363
387
  target.emitEvent(new LayoutEvent(AFTER, blocks, this.times));
@@ -367,13 +391,15 @@ class Layouter {
367
391
  Run.end(t);
368
392
  }
369
393
  fullLayout() {
370
- const t = Run.start('FullLayout');
371
- const { target } = this;
372
- const { BEFORE, LAYOUT, AFTER } = LayoutEvent;
394
+ const t = Run.start("FullLayout");
395
+ const {target: target} = this;
396
+ const {BEFORE: BEFORE, LAYOUT: LAYOUT, AFTER: AFTER} = LayoutEvent;
373
397
  const blocks = this.getBlocks(new LeafList(target));
374
398
  target.emitEvent(new LayoutEvent(BEFORE, blocks, this.times));
375
399
  Layouter.fullLayout(target);
376
- blocks.forEach(item => { item.setAfter(); });
400
+ blocks.forEach(item => {
401
+ item.setAfter();
402
+ });
377
403
  target.emitEvent(new LayoutEvent(LAYOUT, blocks, this.times));
378
404
  target.emitEvent(new LayoutEvent(AFTER, blocks, this.times));
379
405
  this.addBlocks(blocks);
@@ -381,15 +407,12 @@ class Layouter {
381
407
  }
382
408
  static fullLayout(target) {
383
409
  updateAllMatrix(target, true);
384
- if (target.isBranch)
385
- BranchHelper.updateBounds(target);
386
- else
387
- LeafHelper.updateBounds(target);
410
+ if (target.isBranch) BranchHelper.updateBounds(target); else LeafHelper.updateBounds(target);
388
411
  updateAllChange(target);
389
412
  }
390
413
  addExtra(leaf) {
391
414
  if (!this.__updatedList.has(leaf)) {
392
- const { updatedList, beforeBounds } = this.extraBlock || (this.extraBlock = new LayoutBlockData([]));
415
+ const {updatedList: updatedList, beforeBounds: beforeBounds} = this.extraBlock || (this.extraBlock = new LayoutBlockData([]));
393
416
  updatedList.length ? beforeBounds.add(leaf.__world) : beforeBounds.set(leaf.__world);
394
417
  updatedList.add(leaf);
395
418
  }
@@ -398,7 +421,7 @@ class Layouter {
398
421
  return new LayoutBlockData(data);
399
422
  }
400
423
  getBlocks(list) {
401
- return [this.createBlock(list)];
424
+ return [ this.createBlock(list) ];
402
425
  }
403
426
  addBlocks(current) {
404
427
  this.layoutedBlocks ? this.layoutedBlocks.push(...current) : this.layoutedBlocks = current;
@@ -407,13 +430,7 @@ class Layouter {
407
430
  this.__updatedList = event.data.updatedList;
408
431
  }
409
432
  __listenEvents() {
410
- this.__eventIds = [
411
- this.target.on_([
412
- [LayoutEvent.REQUEST, this.layout, this],
413
- [LayoutEvent.AGAIN, this.layoutAgain, this],
414
- [WatchEvent.DATA, this.__onReceiveWatchData, this]
415
- ])
416
- ];
433
+ this.__eventIds = [ this.target.on_([ [ LayoutEvent.REQUEST, this.layout, this ], [ LayoutEvent.AGAIN, this.layoutAgain, this ], [ WatchEvent.DATA, this.__onReceiveWatchData, this ] ]) ];
417
434
  }
418
435
  __removeListenEvents() {
419
436
  this.target.off_(this.__eventIds);
@@ -427,9 +444,12 @@ class Layouter {
427
444
  }
428
445
  }
429
446
 
430
- const debug$1 = Debug.get('Renderer');
447
+ const debug$1 = Debug.get("Renderer");
448
+
431
449
  class Renderer {
432
- get needFill() { return !!(!this.canvas.allowBackgroundColor && this.config.fill); }
450
+ get needFill() {
451
+ return !!(!this.canvas.allowBackgroundColor && this.config.fill);
452
+ }
433
453
  constructor(target, canvas, userConfig) {
434
454
  this.FPS = 60;
435
455
  this.totalTimes = 0;
@@ -440,8 +460,7 @@ class Renderer {
440
460
  };
441
461
  this.target = target;
442
462
  this.canvas = canvas;
443
- if (userConfig)
444
- this.config = DataHelper.default(userConfig, this.config);
463
+ if (userConfig) this.config = DataHelper.default(userConfig, this.config);
445
464
  this.__listenEvents();
446
465
  }
447
466
  start() {
@@ -452,8 +471,7 @@ class Renderer {
452
471
  this.running = false;
453
472
  }
454
473
  update(change = true) {
455
- if (!this.changed)
456
- this.changed = change;
474
+ if (!this.changed) this.changed = change;
457
475
  this.__requestRender();
458
476
  }
459
477
  requestLayout() {
@@ -461,7 +479,7 @@ class Renderer {
461
479
  }
462
480
  checkRender() {
463
481
  if (this.running) {
464
- const { target } = this;
482
+ const {target: target} = this;
465
483
  if (target.isApp) {
466
484
  target.emit(RenderEvent.CHILD_START, target);
467
485
  target.children.forEach(leafer => {
@@ -470,54 +488,47 @@ class Renderer {
470
488
  });
471
489
  target.emit(RenderEvent.CHILD_END, target);
472
490
  }
473
- if (this.changed && this.canvas.view)
474
- this.render();
491
+ if (this.changed && this.canvas.view) this.render();
475
492
  this.target.emit(RenderEvent.NEXT);
476
493
  }
477
494
  }
478
495
  render(callback) {
479
- if (!(this.running && this.canvas.view))
480
- return this.update();
481
- const { target } = this;
496
+ if (!(this.running && this.canvas.view)) return this.update();
497
+ const {target: target} = this;
482
498
  this.times = 0;
483
- this.totalBounds = new Bounds();
484
- debug$1.log(target.innerName, '--->');
499
+ this.totalBounds = new Bounds;
500
+ debug$1.log(target.innerName, "---\x3e");
485
501
  try {
486
502
  this.emitRender(RenderEvent.START);
487
503
  this.renderOnce(callback);
488
504
  this.emitRender(RenderEvent.END, this.totalBounds);
489
505
  ImageManager.clearRecycled();
490
- }
491
- catch (e) {
506
+ } catch (e) {
492
507
  this.rendering = false;
493
508
  debug$1.error(e);
494
509
  }
495
- debug$1.log('-------------|');
510
+ debug$1.log("-------------|");
496
511
  }
497
512
  renderAgain() {
498
513
  if (this.rendering) {
499
514
  this.waitAgain = true;
500
- }
501
- else {
515
+ } else {
502
516
  this.renderOnce();
503
517
  }
504
518
  }
505
519
  renderOnce(callback) {
506
- if (this.rendering)
507
- return debug$1.warn('rendering');
508
- if (this.times > 3)
509
- return debug$1.warn('render max times');
520
+ if (this.rendering) return debug$1.warn("rendering");
521
+ if (this.times > 3) return debug$1.warn("render max times");
510
522
  this.times++;
511
523
  this.totalTimes++;
512
524
  this.rendering = true;
513
525
  this.changed = false;
514
- this.renderBounds = new Bounds();
526
+ this.renderBounds = new Bounds;
515
527
  this.renderOptions = {};
516
528
  if (callback) {
517
529
  this.emitRender(RenderEvent.BEFORE);
518
530
  callback();
519
- }
520
- else {
531
+ } else {
521
532
  this.requestLayout();
522
533
  if (this.ignore) {
523
534
  this.ignore = this.rendering = false;
@@ -526,8 +537,7 @@ class Renderer {
526
537
  this.emitRender(RenderEvent.BEFORE);
527
538
  if (this.config.usePartRender && this.totalTimes > 1) {
528
539
  this.partRender();
529
- }
530
- else {
540
+ } else {
531
541
  this.fullRender();
532
542
  }
533
543
  }
@@ -541,16 +551,16 @@ class Renderer {
541
551
  }
542
552
  }
543
553
  partRender() {
544
- const { canvas, updateBlocks: list } = this;
545
- if (!list)
546
- return;
554
+ const {canvas: canvas, updateBlocks: list} = this;
555
+ if (!list) return;
547
556
  this.mergeBlocks();
548
- list.forEach(block => { if (canvas.bounds.hit(block) && !block.isEmpty())
549
- this.clipRender(block); });
557
+ list.forEach(block => {
558
+ if (canvas.bounds.hit(block) && !block.isEmpty()) this.clipRender(block);
559
+ });
550
560
  }
551
561
  clipRender(block) {
552
- const t = Run.start('PartRender');
553
- const { canvas } = this, bounds = block.getIntersect(canvas.bounds), realBounds = new Bounds(bounds);
562
+ const t = Run.start("PartRender");
563
+ const {canvas: canvas} = this, bounds = block.getIntersect(canvas.bounds), realBounds = new Bounds(bounds);
554
564
  canvas.save();
555
565
  bounds.spread(Renderer.clipSpread).ceil();
556
566
  canvas.clearWorld(bounds, true);
@@ -560,8 +570,8 @@ class Renderer {
560
570
  Run.end(t);
561
571
  }
562
572
  fullRender() {
563
- const t = Run.start('FullRender');
564
- const { canvas } = this;
573
+ const t = Run.start("FullRender");
574
+ const {canvas: canvas} = this;
565
575
  canvas.save();
566
576
  canvas.clear();
567
577
  this.__render(canvas.bounds);
@@ -569,11 +579,14 @@ class Renderer {
569
579
  Run.end(t);
570
580
  }
571
581
  __render(bounds, realBounds) {
572
- const { canvas } = this, includes = bounds.includes(this.target.__world), options = includes ? { includes } : { bounds, includes };
573
- if (this.needFill)
574
- canvas.fillWorld(bounds, this.config.fill);
575
- if (Debug.showRepaint)
576
- Debug.drawRepaint(canvas, bounds);
582
+ const {canvas: canvas} = this, includes = bounds.includes(this.target.__world), options = includes ? {
583
+ includes: includes
584
+ } : {
585
+ bounds: bounds,
586
+ includes: includes
587
+ };
588
+ if (this.needFill) canvas.fillWorld(bounds, this.config.fill);
589
+ if (Debug.showRepaint) Debug.drawRepaint(canvas, bounds);
577
590
  this.target.__render(canvas, options);
578
591
  this.renderBounds = realBounds = realBounds || bounds;
579
592
  this.renderOptions = options;
@@ -581,14 +594,13 @@ class Renderer {
581
594
  canvas.updateRender(realBounds);
582
595
  }
583
596
  addBlock(block) {
584
- if (!this.updateBlocks)
585
- this.updateBlocks = [];
597
+ if (!this.updateBlocks) this.updateBlocks = [];
586
598
  this.updateBlocks.push(block);
587
599
  }
588
600
  mergeBlocks() {
589
- const { updateBlocks: list } = this;
601
+ const {updateBlocks: list} = this;
590
602
  if (list) {
591
- const bounds = new Bounds();
603
+ const bounds = new Bounds;
592
604
  bounds.setList(list);
593
605
  list.length = 0;
594
606
  list.push(bounds);
@@ -596,26 +608,23 @@ class Renderer {
596
608
  }
597
609
  __requestRender() {
598
610
  const target = this.target;
599
- if (this.requestTime || !target)
600
- return;
601
- if (target.parentApp)
602
- return target.parentApp.requestRender(false);
611
+ if (this.requestTime || !target) return;
612
+ if (target.parentApp) return target.parentApp.requestRender(false);
603
613
  const requestTime = this.requestTime = Date.now();
604
614
  Platform.requestRender(() => {
605
- this.FPS = Math.min(60, Math.ceil(1000 / (Date.now() - requestTime)));
615
+ this.FPS = Math.min(60, Math.ceil(1e3 / (Date.now() - requestTime)));
606
616
  this.requestTime = 0;
607
617
  this.checkRender();
608
618
  });
609
619
  }
610
620
  __onResize(e) {
611
- if (this.canvas.unreal)
612
- return;
621
+ if (this.canvas.unreal) return;
613
622
  if (e.bigger || !e.samePixelRatio) {
614
- const { width, height } = e.old;
623
+ const {width: width, height: height} = e.old;
615
624
  const bounds = new Bounds(0, 0, width, height);
616
625
  if (!bounds.includes(this.target.__world) || this.needFill || !e.samePixelRatio) {
617
626
  this.addBlock(this.canvas.bounds);
618
- this.target.forceUpdate('surface');
627
+ this.target.forceUpdate("surface");
619
628
  return;
620
629
  }
621
630
  }
@@ -623,34 +632,24 @@ class Renderer {
623
632
  this.update();
624
633
  }
625
634
  __onLayoutEnd(event) {
626
- if (event.data)
627
- event.data.map(item => {
628
- let empty;
629
- if (item.updatedList)
630
- item.updatedList.list.some(leaf => {
631
- empty = (!leaf.__world.width || !leaf.__world.height);
632
- if (empty) {
633
- if (!leaf.isLeafer)
634
- debug$1.tip(leaf.innerName, ': empty');
635
- empty = (!leaf.isBranch || leaf.isBranchLeaf);
636
- }
637
- return empty;
638
- });
639
- this.addBlock(empty ? this.canvas.bounds : item.updatedBounds);
635
+ if (event.data) event.data.map(item => {
636
+ let empty;
637
+ if (item.updatedList) item.updatedList.list.some(leaf => {
638
+ empty = !leaf.__world.width || !leaf.__world.height;
639
+ if (empty) {
640
+ if (!leaf.isLeafer) debug$1.tip(leaf.innerName, ": empty");
641
+ empty = !leaf.isBranch || leaf.isBranchLeaf;
642
+ }
643
+ return empty;
640
644
  });
645
+ this.addBlock(empty ? this.canvas.bounds : item.updatedBounds);
646
+ });
641
647
  }
642
648
  emitRender(type, bounds, options) {
643
649
  this.target.emitEvent(new RenderEvent(type, this.times, bounds, options));
644
650
  }
645
651
  __listenEvents() {
646
- this.__eventIds = [
647
- this.target.on_([
648
- [RenderEvent.REQUEST, this.update, this],
649
- [LayoutEvent.END, this.__onLayoutEnd, this],
650
- [RenderEvent.AGAIN, this.renderAgain, this],
651
- [ResizeEvent.RESIZE, this.__onResize, this]
652
- ])
653
- ];
652
+ this.__eventIds = [ this.target.on_([ [ RenderEvent.REQUEST, this.update, this ], [ LayoutEvent.END, this.__onLayoutEnd, this ], [ RenderEvent.AGAIN, this.renderAgain, this ], [ ResizeEvent.RESIZE, this.__onResize, this ] ]) ];
654
653
  }
655
654
  __removeListenEvents() {
656
655
  this.target.off_(this.__eventIds);
@@ -663,82 +662,104 @@ class Renderer {
663
662
  }
664
663
  }
665
664
  }
665
+
666
666
  Renderer.clipSpread = 10;
667
667
 
668
- const { hitRadiusPoint } = BoundsHelper;
668
+ const {hitRadiusPoint: hitRadiusPoint} = BoundsHelper;
669
+
669
670
  class Picker {
670
671
  constructor(target, selector) {
671
672
  this.target = target;
672
673
  this.selector = selector;
673
674
  }
674
675
  getByPoint(hitPoint, hitRadius, options) {
675
- if (!hitRadius)
676
- hitRadius = 0;
677
- if (!options)
678
- options = {};
676
+ if (!hitRadius) hitRadius = 0;
677
+ if (!options) options = {};
679
678
  const through = options.through || false;
680
679
  const ignoreHittable = options.ignoreHittable || false;
681
680
  const target = options.target || this.target;
682
681
  this.exclude = options.exclude || null;
683
- this.point = { x: hitPoint.x, y: hitPoint.y, radiusX: hitRadius, radiusY: hitRadius };
682
+ this.point = {
683
+ x: hitPoint.x,
684
+ y: hitPoint.y,
685
+ radiusX: hitRadius,
686
+ radiusY: hitRadius
687
+ };
684
688
  this.findList = new LeafList(options.findList);
685
- if (!options.findList)
686
- this.hitBranch(target);
687
- const { list } = this.findList;
689
+ if (!options.findList) this.hitBranch(target.isBranchLeaf ? {
690
+ children: [ target ]
691
+ } : target);
692
+ const {list: list} = this.findList;
688
693
  const leaf = this.getBestMatchLeaf(list, options.bottomList, ignoreHittable);
689
694
  const path = ignoreHittable ? this.getPath(leaf) : this.getHitablePath(leaf);
690
695
  this.clear();
691
- return through ? { path, target: leaf, throughPath: list.length ? this.getThroughPath(list) : path } : { path, target: leaf };
696
+ return through ? {
697
+ path: path,
698
+ target: leaf,
699
+ throughPath: list.length ? this.getThroughPath(list) : path
700
+ } : {
701
+ path: path,
702
+ target: leaf
703
+ };
704
+ }
705
+ hitPoint(hitPoint, hitRadius, options) {
706
+ return !!this.getByPoint(hitPoint, hitRadius, options).target;
692
707
  }
693
708
  getBestMatchLeaf(list, bottomList, ignoreHittable) {
709
+ const findList = this.findList = new LeafList;
694
710
  if (list.length) {
695
711
  let find;
696
- this.findList = new LeafList();
697
- const { x, y } = this.point;
698
- const point = { x, y, radiusX: 0, radiusY: 0 };
712
+ const {x: x, y: y} = this.point;
713
+ const point = {
714
+ x: x,
715
+ y: y,
716
+ radiusX: 0,
717
+ radiusY: 0
718
+ };
699
719
  for (let i = 0, len = list.length; i < len; i++) {
700
720
  find = list[i];
701
721
  if (ignoreHittable || LeafHelper.worldHittable(find)) {
702
722
  this.hitChild(find, point);
703
- if (this.findList.length)
704
- return this.findList.list[0];
723
+ if (findList.length) {
724
+ if (find.isBranchLeaf && list.some(item => item !== find && LeafHelper.hasParent(item, find))) {
725
+ findList.reset();
726
+ break;
727
+ }
728
+ return findList.list[0];
729
+ }
705
730
  }
706
731
  }
707
732
  }
708
733
  if (bottomList) {
709
734
  for (let i = 0, len = bottomList.length; i < len; i++) {
710
735
  this.hitChild(bottomList[i].target, this.point, bottomList[i].proxy);
711
- if (this.findList.length)
712
- return this.findList.list[0];
736
+ if (findList.length) return findList.list[0];
713
737
  }
714
738
  }
715
- return list[0];
739
+ return ignoreHittable ? list[0] : list.find(item => LeafHelper.worldHittable(item));
716
740
  }
717
741
  getPath(leaf) {
718
- const path = new LeafList();
742
+ const path = new LeafList;
719
743
  while (leaf) {
720
744
  path.add(leaf);
721
745
  leaf = leaf.parent;
722
746
  }
723
- if (this.target)
724
- path.add(this.target);
747
+ if (this.target) path.add(this.target);
725
748
  return path;
726
749
  }
727
750
  getHitablePath(leaf) {
728
751
  const path = this.getPath(leaf && leaf.hittable ? leaf : null);
729
- let item, hittablePath = new LeafList();
752
+ let item, hittablePath = new LeafList;
730
753
  for (let i = path.list.length - 1; i > -1; i--) {
731
754
  item = path.list[i];
732
- if (!item.__.hittable)
733
- break;
755
+ if (!item.__.hittable) break;
734
756
  hittablePath.addAt(item, 0);
735
- if (!item.__.hitChildren)
736
- break;
757
+ if (!item.__.hitChildren) break;
737
758
  }
738
759
  return hittablePath;
739
760
  }
740
761
  getThroughPath(list) {
741
- const throughPath = new LeafList();
762
+ const throughPath = new LeafList;
742
763
  const pathList = [];
743
764
  for (let i = list.length - 1; i > -1; i--) {
744
765
  pathList.push(this.getPath(list[i]));
@@ -748,8 +769,7 @@ class Picker {
748
769
  path = pathList[i], nextPath = pathList[i + 1];
749
770
  for (let j = 0, jLen = path.length; j < jLen; j++) {
750
771
  leaf = path.list[j];
751
- if (nextPath && nextPath.has(leaf))
752
- break;
772
+ if (nextPath && nextPath.has(leaf)) break;
753
773
  throughPath.add(leaf);
754
774
  }
755
775
  }
@@ -760,32 +780,37 @@ class Picker {
760
780
  }
761
781
  eachFind(children, hitMask) {
762
782
  let child, hit;
763
- const { point } = this, len = children.length;
783
+ const {point: point} = this, len = children.length;
764
784
  for (let i = len - 1; i > -1; i--) {
765
785
  child = children[i];
766
- if (!child.__.visible || (hitMask && !child.__.mask))
767
- continue;
786
+ if (!child.__.visible || hitMask && !child.__.mask) continue;
768
787
  hit = child.__.hitRadius ? true : hitRadiusPoint(child.__world, point);
769
788
  if (child.isBranch) {
770
789
  if (hit || child.__ignoreHitWorld) {
771
790
  this.eachFind(child.children, child.__onlyHitMask);
772
- if (child.isBranchLeaf)
773
- this.hitChild(child, point);
791
+ if (child.isBranchLeaf) this.hitChild(child, point);
774
792
  }
775
- }
776
- else {
777
- if (hit)
778
- this.hitChild(child, point);
793
+ } else {
794
+ if (hit) this.hitChild(child, point);
779
795
  }
780
796
  }
781
797
  }
782
798
  hitChild(child, point, proxy) {
783
- if (this.exclude && this.exclude.has(child))
784
- return;
799
+ if (this.exclude && this.exclude.has(child)) return;
785
800
  if (child.__hitWorld(point)) {
786
- const { parent } = child;
787
- if (parent && parent.__hasMask && !child.__.mask && !parent.children.some(item => item.__.mask && item.__hitWorld(point)))
788
- return;
801
+ const {parent: parent} = child;
802
+ if (parent && parent.__hasMask && !child.__.mask) {
803
+ let findMasks = [], item;
804
+ const {children: children} = parent;
805
+ for (let i = 0, len = children.length; i < len; i++) {
806
+ item = children[i];
807
+ if (item.__.mask) findMasks.push(item);
808
+ if (item === child) {
809
+ if (findMasks && !findMasks.every(value => value.__hitWorld(point))) return;
810
+ break;
811
+ }
812
+ }
813
+ }
789
814
  this.findList.add(proxy || child);
790
815
  }
791
816
  }
@@ -802,24 +827,24 @@ class Picker {
802
827
  class Selector {
803
828
  constructor(target, userConfig) {
804
829
  this.config = {};
805
- if (userConfig)
806
- this.config = DataHelper.default(userConfig, this.config);
830
+ if (userConfig) this.config = DataHelper.default(userConfig, this.config);
807
831
  this.picker = new Picker(this.target = target, this);
808
832
  this.finder = Creator.finder && Creator.finder();
809
833
  }
810
834
  getByPoint(hitPoint, hitRadius, options) {
811
- const { target, picker } = this;
812
- if (Platform.backgrounder)
813
- target && target.updateLayout();
835
+ const {target: target, picker: picker} = this;
836
+ if (Platform.backgrounder) target && target.updateLayout();
814
837
  return picker.getByPoint(hitPoint, hitRadius, options);
815
838
  }
839
+ hitPoint(hitPoint, hitRadius, options) {
840
+ return this.picker.hitPoint(hitPoint, hitRadius, options);
841
+ }
816
842
  getBy(condition, branch, one, options) {
817
- return this.finder ? this.finder.getBy(condition, branch, one, options) : Plugin.need('find');
843
+ return this.finder ? this.finder.getBy(condition, branch, one, options) : Plugin.need("find");
818
844
  }
819
845
  destroy() {
820
846
  this.picker.destroy();
821
- if (this.finder)
822
- this.finder.destroy();
847
+ if (this.finder) this.finder.destroy();
823
848
  }
824
849
  }
825
850
 
@@ -829,24 +854,22 @@ Object.assign(Creator, {
829
854
  renderer: (target, canvas, options) => new Renderer(target, canvas, options),
830
855
  selector: (target, options) => new Selector(target, options)
831
856
  });
857
+
832
858
  Platform.layout = Layouter.fullLayout;
833
859
 
834
860
  function fillText(ui, canvas) {
835
- const data = ui.__, { rows, decorationY } = data.__textDrawData;
836
- if (data.__isPlacehold && data.placeholderColor)
837
- canvas.fillStyle = data.placeholderColor;
861
+ const data = ui.__, {rows: rows, decorationY: decorationY} = data.__textDrawData;
862
+ if (data.__isPlacehold && data.placeholderColor) canvas.fillStyle = data.placeholderColor;
838
863
  let row;
839
864
  for (let i = 0, len = rows.length; i < len; i++) {
840
865
  row = rows[i];
841
- if (row.text)
842
- canvas.fillText(row.text, row.x, row.y);
843
- else if (row.data)
844
- row.data.forEach(charData => { canvas.fillText(charData.char, charData.x, row.y); });
866
+ if (row.text) canvas.fillText(row.text, row.x, row.y); else if (row.data) row.data.forEach(charData => {
867
+ canvas.fillText(charData.char, charData.x, row.y);
868
+ });
845
869
  }
846
870
  if (decorationY) {
847
- const { decorationColor, decorationHeight } = data.__textDrawData;
848
- if (decorationColor)
849
- canvas.fillStyle = decorationColor;
871
+ const {decorationColor: decorationColor, decorationHeight: decorationHeight} = data.__textDrawData;
872
+ if (decorationColor) canvas.fillStyle = decorationColor;
850
873
  rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
851
874
  }
852
875
  }
@@ -855,106 +878,112 @@ function fill(fill, ui, canvas) {
855
878
  canvas.fillStyle = fill;
856
879
  fillPathOrText(ui, canvas);
857
880
  }
881
+
858
882
  function fills(fills, ui, canvas) {
859
883
  let item;
860
884
  for (let i = 0, len = fills.length; i < len; i++) {
861
885
  item = fills[i];
862
886
  if (item.image) {
863
- if (PaintImage.checkImage(ui, canvas, item, !ui.__.__font))
864
- continue;
887
+ if (PaintImage.checkImage(ui, canvas, item, !ui.__.__font)) continue;
865
888
  if (!item.style) {
866
- if (!i && item.image.isPlacehold)
867
- ui.drawImagePlaceholder(canvas, item.image);
889
+ if (!i && item.image.isPlacehold) ui.drawImagePlaceholder(canvas, item.image);
868
890
  continue;
869
891
  }
870
892
  }
871
893
  canvas.fillStyle = item.style;
872
- if (item.transform) {
894
+ if (item.transform || item.scaleFixed) {
873
895
  canvas.save();
874
- canvas.transform(item.transform);
875
- if (item.blendMode)
876
- canvas.blendMode = item.blendMode;
896
+ if (item.transform) canvas.transform(item.transform);
897
+ if (item.scaleFixed) {
898
+ const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true);
899
+ if (item.scaleFixed === true || item.scaleFixed === "zoom-in" && scaleX > 1 && scaleY > 1) canvas.scale(1 / scaleX, 1 / scaleY);
900
+ }
901
+ if (item.blendMode) canvas.blendMode = item.blendMode;
877
902
  fillPathOrText(ui, canvas);
878
903
  canvas.restore();
879
- }
880
- else {
904
+ } else {
881
905
  if (item.blendMode) {
882
906
  canvas.saveBlendMode(item.blendMode);
883
907
  fillPathOrText(ui, canvas);
884
908
  canvas.restoreBlendMode();
885
- }
886
- else
887
- fillPathOrText(ui, canvas);
909
+ } else fillPathOrText(ui, canvas);
888
910
  }
889
911
  }
890
912
  }
913
+
891
914
  function fillPathOrText(ui, canvas) {
892
- ui.__.__font ? fillText(ui, canvas) : (ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill());
915
+ ui.__.__font ? fillText(ui, canvas) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
893
916
  }
894
917
 
895
918
  function strokeText(stroke, ui, canvas) {
896
919
  switch (ui.__.strokeAlign) {
897
- case 'center':
898
- drawCenter$1(stroke, 1, ui, canvas);
899
- break;
900
- case 'inside':
901
- drawAlign(stroke, 'inside', ui, canvas);
902
- break;
903
- case 'outside':
904
- ui.__.__fillAfterStroke ? drawCenter$1(stroke, 2, ui, canvas) : drawAlign(stroke, 'outside', ui, canvas);
905
- break;
920
+ case "center":
921
+ drawCenter$1(stroke, 1, ui, canvas);
922
+ break;
923
+
924
+ case "inside":
925
+ drawAlign(stroke, "inside", ui, canvas);
926
+ break;
927
+
928
+ case "outside":
929
+ ui.__.__fillAfterStroke ? drawCenter$1(stroke, 2, ui, canvas) : drawAlign(stroke, "outside", ui, canvas);
930
+ break;
906
931
  }
907
932
  }
933
+
908
934
  function drawCenter$1(stroke, strokeWidthScale, ui, canvas) {
909
935
  const data = ui.__;
910
- canvas.setStroke(!data.__isStrokes && stroke, data.strokeWidth * strokeWidthScale, data);
911
- data.__isStrokes ? drawStrokesStyle(stroke, true, ui, canvas) : drawTextStroke(ui, canvas);
936
+ if (isObject(stroke)) {
937
+ drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas);
938
+ } else {
939
+ canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
940
+ drawTextStroke(ui, canvas);
941
+ }
912
942
  }
943
+
913
944
  function drawAlign(stroke, align, ui, canvas) {
914
945
  const out = canvas.getSameCanvas(true, true);
915
946
  out.font = ui.__.__font;
916
947
  drawCenter$1(stroke, 2, ui, out);
917
- out.blendMode = align === 'outside' ? 'destination-out' : 'destination-in';
948
+ out.blendMode = align === "outside" ? "destination-out" : "destination-in";
918
949
  fillText(ui, out);
919
- out.blendMode = 'normal';
920
- copyWorld(canvas, out, ui);
950
+ out.blendMode = "normal";
951
+ LeafHelper.copyCanvasByWorld(ui, canvas, out);
921
952
  out.recycle(ui.__nowWorld);
922
953
  }
923
- function copyWorld(canvas, out, ui) {
924
- if (ui.__worldFlipped || Platform.fullImageShadow)
925
- canvas.copyWorldByReset(out, ui.__nowWorld);
926
- else
927
- canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds);
928
- }
954
+
929
955
  function drawTextStroke(ui, canvas) {
930
956
  let row, data = ui.__.__textDrawData;
931
- const { rows, decorationY } = data;
957
+ const {rows: rows, decorationY: decorationY} = data;
932
958
  for (let i = 0, len = rows.length; i < len; i++) {
933
959
  row = rows[i];
934
- if (row.text)
935
- canvas.strokeText(row.text, row.x, row.y);
936
- else if (row.data)
937
- row.data.forEach(charData => { canvas.strokeText(charData.char, charData.x, row.y); });
960
+ if (row.text) canvas.strokeText(row.text, row.x, row.y); else if (row.data) row.data.forEach(charData => {
961
+ canvas.strokeText(charData.char, charData.x, row.y);
962
+ });
938
963
  }
939
964
  if (decorationY) {
940
- const { decorationHeight } = data;
965
+ const {decorationHeight: decorationHeight} = data;
941
966
  rows.forEach(row => decorationY.forEach(value => canvas.strokeRect(row.x, row.y + value, row.width, decorationHeight)));
942
967
  }
943
968
  }
944
- function drawStrokesStyle(strokes, isText, ui, canvas) {
969
+
970
+ function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas) {
945
971
  let item;
972
+ const data = ui.__, {__hasMultiStrokeStyle: __hasMultiStrokeStyle} = data;
973
+ __hasMultiStrokeStyle || canvas.setStroke(undefined, data.__strokeWidth * strokeWidthScale, data);
946
974
  for (let i = 0, len = strokes.length; i < len; i++) {
947
975
  item = strokes[i];
948
- if (item.image && PaintImage.checkImage(ui, canvas, item, false))
949
- continue;
976
+ if (item.image && PaintImage.checkImage(ui, canvas, item, false)) continue;
950
977
  if (item.style) {
951
- canvas.strokeStyle = item.style;
978
+ if (__hasMultiStrokeStyle) {
979
+ const {strokeStyle: strokeStyle} = item;
980
+ strokeStyle ? canvas.setStroke(item.style, data.__getRealStrokeWidth(strokeStyle) * strokeWidthScale, data, strokeStyle) : canvas.setStroke(item.style, data.__strokeWidth * strokeWidthScale, data);
981
+ } else canvas.strokeStyle = item.style;
952
982
  if (item.blendMode) {
953
983
  canvas.saveBlendMode(item.blendMode);
954
984
  isText ? drawTextStroke(ui, canvas) : canvas.stroke();
955
985
  canvas.restoreBlendMode();
956
- }
957
- else {
986
+ } else {
958
987
  isText ? drawTextStroke(ui, canvas) : canvas.stroke();
959
988
  }
960
989
  }
@@ -963,77 +992,81 @@ function drawStrokesStyle(strokes, isText, ui, canvas) {
963
992
 
964
993
  function stroke(stroke, ui, canvas) {
965
994
  const data = ui.__;
966
- if (!data.__strokeWidth)
967
- return;
995
+ if (!data.__strokeWidth) return;
968
996
  if (data.__font) {
969
997
  strokeText(stroke, ui, canvas);
970
- }
971
- else {
998
+ } else {
972
999
  switch (data.strokeAlign) {
973
- case 'center':
974
- drawCenter(stroke, 1, ui, canvas);
975
- break;
976
- case 'inside':
977
- drawInside(stroke, ui, canvas);
978
- break;
979
- case 'outside':
980
- drawOutside(stroke, ui, canvas);
981
- break;
1000
+ case "center":
1001
+ drawCenter(stroke, 1, ui, canvas);
1002
+ break;
1003
+
1004
+ case "inside":
1005
+ drawInside(stroke, ui, canvas);
1006
+ break;
1007
+
1008
+ case "outside":
1009
+ drawOutside(stroke, ui, canvas);
1010
+ break;
982
1011
  }
983
1012
  }
984
1013
  }
1014
+
985
1015
  function strokes(strokes, ui, canvas) {
986
1016
  stroke(strokes, ui, canvas);
987
1017
  }
1018
+
988
1019
  function drawCenter(stroke, strokeWidthScale, ui, canvas) {
989
1020
  const data = ui.__;
990
- canvas.setStroke(!data.__isStrokes && stroke, data.__strokeWidth * strokeWidthScale, data);
991
- data.__isStrokes ? drawStrokesStyle(stroke, false, ui, canvas) : canvas.stroke();
992
- if (data.__useArrow)
993
- Paint.strokeArrow(stroke, ui, canvas);
1021
+ if (isObject(stroke)) {
1022
+ drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas);
1023
+ } else {
1024
+ canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
1025
+ canvas.stroke();
1026
+ }
1027
+ if (data.__useArrow) Paint.strokeArrow(stroke, ui, canvas);
994
1028
  }
1029
+
995
1030
  function drawInside(stroke, ui, canvas) {
996
1031
  canvas.save();
997
1032
  canvas.clipUI(ui);
998
1033
  drawCenter(stroke, 2, ui, canvas);
999
1034
  canvas.restore();
1000
1035
  }
1036
+
1001
1037
  function drawOutside(stroke, ui, canvas) {
1002
1038
  const data = ui.__;
1003
1039
  if (data.__fillAfterStroke) {
1004
1040
  drawCenter(stroke, 2, ui, canvas);
1005
- }
1006
- else {
1007
- const { renderBounds } = ui.__layout;
1041
+ } else {
1042
+ const {renderBounds: renderBounds} = ui.__layout;
1008
1043
  const out = canvas.getSameCanvas(true, true);
1009
1044
  ui.__drawRenderPath(out);
1010
1045
  drawCenter(stroke, 2, ui, out);
1011
1046
  out.clipUI(data);
1012
1047
  out.clearWorld(renderBounds);
1013
- copyWorld(canvas, out, ui);
1048
+ LeafHelper.copyCanvasByWorld(ui, canvas, out);
1014
1049
  out.recycle(ui.__nowWorld);
1015
1050
  }
1016
1051
  }
1017
1052
 
1018
- const { getSpread, getOuterOf, getByMove, getIntersectData } = BoundsHelper;
1053
+ const {getSpread: getSpread, getOuterOf: getOuterOf, getByMove: getByMove, getIntersectData: getIntersectData} = BoundsHelper;
1054
+
1019
1055
  function shape(ui, current, options) {
1020
1056
  const canvas = current.getSameCanvas();
1021
1057
  const nowWorld = ui.__nowWorld;
1022
- let bounds, fitMatrix, shapeBounds, worldCanvas;
1023
- let { scaleX, scaleY } = nowWorld;
1024
- if (scaleX < 0)
1025
- scaleX = -scaleX;
1026
- if (scaleY < 0)
1027
- scaleY = -scaleY;
1058
+ let bounds, matrix, fitMatrix, shapeBounds, worldCanvas;
1059
+ let {scaleX: scaleX, scaleY: scaleY} = nowWorld;
1060
+ if (scaleX < 0) scaleX = -scaleX;
1061
+ if (scaleY < 0) scaleY = -scaleY;
1028
1062
  if (current.bounds.includes(nowWorld)) {
1029
1063
  worldCanvas = canvas;
1030
1064
  bounds = shapeBounds = nowWorld;
1031
- }
1032
- else {
1033
- const { renderShapeSpread: spread } = ui.__layout;
1034
- const worldClipBounds = getIntersectData(spread ? getSpread(current.bounds, scaleX === scaleY ? spread * scaleX : [spread * scaleY, spread * scaleX]) : current.bounds, nowWorld);
1065
+ } else {
1066
+ const {renderShapeSpread: spread} = ui.__layout;
1067
+ const worldClipBounds = getIntersectData(spread ? getSpread(current.bounds, scaleX === scaleY ? spread * scaleX : [ spread * scaleY, spread * scaleX ]) : current.bounds, nowWorld);
1035
1068
  fitMatrix = current.bounds.getFitMatrix(worldClipBounds);
1036
- let { a: fitScaleX, d: fitScaleY } = fitMatrix;
1069
+ let {a: fitScaleX, d: fitScaleY} = fitMatrix;
1037
1070
  if (fitMatrix.a < 1) {
1038
1071
  worldCanvas = current.getSameCanvas();
1039
1072
  ui.__renderShape(worldCanvas, options);
@@ -1042,215 +1075,262 @@ function shape(ui, current, options) {
1042
1075
  }
1043
1076
  shapeBounds = getOuterOf(nowWorld, fitMatrix);
1044
1077
  bounds = getByMove(shapeBounds, -fitMatrix.e, -fitMatrix.f);
1045
- if (options.matrix) {
1046
- const { matrix } = options;
1047
- fitMatrix.multiply(matrix);
1048
- fitScaleX *= matrix.scaleX;
1049
- fitScaleY *= matrix.scaleY;
1050
- }
1051
- options = Object.assign(Object.assign({}, options), { matrix: fitMatrix.withScale(fitScaleX, fitScaleY) });
1078
+ const userMatrix = options.matrix;
1079
+ if (userMatrix) {
1080
+ matrix = new Matrix(fitMatrix);
1081
+ matrix.multiply(userMatrix);
1082
+ fitScaleX *= userMatrix.scaleX;
1083
+ fitScaleY *= userMatrix.scaleY;
1084
+ } else matrix = fitMatrix;
1085
+ matrix.withScale(fitScaleX, fitScaleY);
1086
+ options = Object.assign(Object.assign({}, options), {
1087
+ matrix: matrix
1088
+ });
1052
1089
  }
1053
1090
  ui.__renderShape(canvas, options);
1054
1091
  return {
1055
- canvas, matrix: fitMatrix, bounds,
1056
- worldCanvas, shapeBounds, scaleX, scaleY
1092
+ canvas: canvas,
1093
+ matrix: matrix,
1094
+ fitMatrix: fitMatrix,
1095
+ bounds: bounds,
1096
+ worldCanvas: worldCanvas,
1097
+ shapeBounds: shapeBounds,
1098
+ scaleX: scaleX,
1099
+ scaleY: scaleY
1057
1100
  };
1058
1101
  }
1059
1102
 
1060
1103
  let recycleMap;
1061
- const { stintSet } = DataHelper, { hasTransparent: hasTransparent$1 } = ColorConvert;
1104
+
1105
+ const {stintSet: stintSet} = DataHelper, {hasTransparent: hasTransparent$1} = ColorConvert;
1106
+
1062
1107
  function compute(attrName, ui) {
1063
1108
  const data = ui.__, leafPaints = [];
1064
1109
  let paints = data.__input[attrName], isAlphaPixel, isTransparent;
1065
- if (!(paints instanceof Array))
1066
- paints = [paints];
1110
+ if (!isArray(paints)) paints = [ paints ];
1067
1111
  recycleMap = PaintImage.recycleImage(attrName, data);
1112
+ let maxChildStrokeWidth;
1068
1113
  for (let i = 0, len = paints.length, item; i < len; i++) {
1069
- (item = getLeafPaint(attrName, paints[i], ui)) && leafPaints.push(item);
1114
+ if (item = getLeafPaint(attrName, paints[i], ui)) {
1115
+ leafPaints.push(item);
1116
+ if (item.strokeStyle) {
1117
+ maxChildStrokeWidth || (maxChildStrokeWidth = 1);
1118
+ if (item.strokeStyle.strokeWidth) maxChildStrokeWidth = Math.max(maxChildStrokeWidth, item.strokeStyle.strokeWidth);
1119
+ }
1120
+ }
1070
1121
  }
1071
- data['_' + attrName] = leafPaints.length ? leafPaints : undefined;
1122
+ data["_" + attrName] = leafPaints.length ? leafPaints : undefined;
1072
1123
  if (leafPaints.length) {
1073
1124
  if (leafPaints.every(item => item.isTransparent)) {
1074
- if (leafPaints.some(item => item.image))
1075
- isAlphaPixel = true;
1125
+ if (leafPaints.some(item => item.image)) isAlphaPixel = true;
1076
1126
  isTransparent = true;
1077
1127
  }
1078
1128
  }
1079
- if (attrName === 'fill') {
1080
- stintSet(data, '__isAlphaPixelFill', isAlphaPixel);
1081
- stintSet(data, '__isTransparentFill', isTransparent);
1082
- }
1083
- else {
1084
- stintSet(data, '__isAlphaPixelStroke', isAlphaPixel);
1085
- stintSet(data, '__isTransparentStroke', isTransparent);
1129
+ if (attrName === "fill") {
1130
+ stintSet(data, "__isAlphaPixelFill", isAlphaPixel);
1131
+ stintSet(data, "__isTransparentFill", isTransparent);
1132
+ } else {
1133
+ stintSet(data, "__isAlphaPixelStroke", isAlphaPixel);
1134
+ stintSet(data, "__isTransparentStroke", isTransparent);
1135
+ stintSet(data, "__hasMultiStrokeStyle", maxChildStrokeWidth);
1086
1136
  }
1087
1137
  }
1138
+
1088
1139
  function getLeafPaint(attrName, paint, ui) {
1089
- if (typeof paint !== 'object' || paint.visible === false || paint.opacity === 0)
1090
- return undefined;
1140
+ if (!isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
1091
1141
  let data;
1092
- const { boxBounds } = ui.__layout;
1142
+ const {boxBounds: boxBounds} = ui.__layout;
1093
1143
  switch (paint.type) {
1094
- case 'image':
1095
- data = PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
1096
- break;
1097
- case 'linear':
1098
- data = PaintGradient.linearGradient(paint, boxBounds);
1099
- break;
1100
- case 'radial':
1101
- data = PaintGradient.radialGradient(paint, boxBounds);
1102
- break;
1103
- case 'angular':
1104
- data = PaintGradient.conicGradient(paint, boxBounds);
1105
- break;
1106
- case 'solid':
1107
- const { type, color, opacity } = paint;
1108
- data = { type, style: ColorConvert.string(color, opacity) };
1109
- break;
1110
- default:
1111
- if (paint.r !== undefined)
1112
- data = { type: 'solid', style: ColorConvert.string(paint) };
1144
+ case "image":
1145
+ data = PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
1146
+ break;
1147
+
1148
+ case "linear":
1149
+ data = PaintGradient.linearGradient(paint, boxBounds);
1150
+ break;
1151
+
1152
+ case "radial":
1153
+ data = PaintGradient.radialGradient(paint, boxBounds);
1154
+ break;
1155
+
1156
+ case "angular":
1157
+ data = PaintGradient.conicGradient(paint, boxBounds);
1158
+ break;
1159
+
1160
+ case "solid":
1161
+ const {type: type, color: color, opacity: opacity} = paint;
1162
+ data = {
1163
+ type: type,
1164
+ style: ColorConvert.string(color, opacity)
1165
+ };
1166
+ break;
1167
+
1168
+ default:
1169
+ if (!isUndefined(paint.r)) data = {
1170
+ type: "solid",
1171
+ style: ColorConvert.string(paint)
1172
+ };
1113
1173
  }
1114
1174
  if (data) {
1115
- if (typeof data.style === 'string' && hasTransparent$1(data.style))
1116
- data.isTransparent = true;
1117
- if (paint.blendMode)
1118
- data.blendMode = paint.blendMode;
1175
+ if (isString(data.style) && hasTransparent$1(data.style)) data.isTransparent = true;
1176
+ if (paint.style) {
1177
+ if (paint.style.strokeWidth === 0) return undefined;
1178
+ data.strokeStyle = paint.style;
1179
+ }
1180
+ if (paint.editing) data.editing = paint.editing;
1181
+ if (paint.blendMode) data.blendMode = paint.blendMode;
1119
1182
  }
1120
1183
  return data;
1121
1184
  }
1122
1185
 
1123
1186
  const PaintModule = {
1124
- compute,
1125
- fill,
1126
- fills,
1127
- fillPathOrText,
1128
- fillText,
1129
- stroke,
1130
- strokes,
1131
- strokeText,
1132
- drawTextStroke,
1133
- shape
1187
+ compute: compute,
1188
+ fill: fill,
1189
+ fills: fills,
1190
+ fillPathOrText: fillPathOrText,
1191
+ fillText: fillText,
1192
+ stroke: stroke,
1193
+ strokes: strokes,
1194
+ strokeText: strokeText,
1195
+ drawTextStroke: drawTextStroke,
1196
+ shape: shape
1134
1197
  };
1135
1198
 
1136
- let origin = {};
1137
- const { get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, scale: scaleHelper, rotate, skew: skewHelper } = MatrixHelper;
1199
+ let origin = {}, tempMatrix = getMatrixData();
1200
+
1201
+ const {get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, multiplyParent: multiplyParent, scale: scaleHelper, rotate: rotate, skew: skewHelper} = MatrixHelper;
1202
+
1138
1203
  function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
1139
1204
  const transform = get$3();
1140
1205
  translate$1(transform, box.x + x, box.y + y);
1141
1206
  scaleHelper(transform, scaleX, scaleY);
1142
- if (rotation)
1143
- rotateOfOuter$1(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
1207
+ if (rotation) rotateOfOuter$1(transform, {
1208
+ x: box.x + box.width / 2,
1209
+ y: box.y + box.height / 2
1210
+ }, rotation);
1144
1211
  data.transform = transform;
1145
1212
  }
1146
- function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew) {
1213
+
1214
+ function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipSize) {
1147
1215
  const transform = get$3();
1148
- if (rotation)
1149
- rotate(transform, rotation);
1150
- if (skew)
1151
- skewHelper(transform, skew.x, skew.y);
1152
- if (scaleX)
1153
- scaleHelper(transform, scaleX, scaleY);
1154
- translate$1(transform, box.x + x, box.y + y);
1216
+ layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
1217
+ if (clipSize) {
1218
+ tempMatrix.a = box.width / clipSize.width, tempMatrix.d = box.height / clipSize.height;
1219
+ multiplyParent(transform, tempMatrix);
1220
+ }
1155
1221
  data.transform = transform;
1156
1222
  }
1157
- function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align) {
1223
+
1224
+ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, skew, align, freeTransform) {
1158
1225
  const transform = get$3();
1159
- if (rotation) {
1160
- if (align === 'center') {
1161
- rotateOfOuter$1(transform, { x: width / 2, y: height / 2 }, rotation);
1162
- }
1163
- else {
1164
- rotate(transform, rotation);
1165
- switch (rotation) {
1166
- case 90:
1226
+ if (freeTransform) {
1227
+ layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
1228
+ } else {
1229
+ if (rotation) {
1230
+ if (align === "center") {
1231
+ rotateOfOuter$1(transform, {
1232
+ x: width / 2,
1233
+ y: height / 2
1234
+ }, rotation);
1235
+ } else {
1236
+ rotate(transform, rotation);
1237
+ switch (rotation) {
1238
+ case 90:
1167
1239
  translate$1(transform, height, 0);
1168
1240
  break;
1169
- case 180:
1241
+
1242
+ case 180:
1170
1243
  translate$1(transform, width, height);
1171
1244
  break;
1172
- case 270:
1245
+
1246
+ case 270:
1173
1247
  translate$1(transform, 0, width);
1174
1248
  break;
1249
+ }
1175
1250
  }
1176
1251
  }
1252
+ origin.x = box.x + x;
1253
+ origin.y = box.y + y;
1254
+ translate$1(transform, origin.x, origin.y);
1255
+ if (scaleX) scaleOfOuter$1(transform, origin, scaleX, scaleY);
1177
1256
  }
1178
- origin.x = box.x + x;
1179
- origin.y = box.y + y;
1180
- translate$1(transform, origin.x, origin.y);
1181
- if (scaleX)
1182
- scaleOfOuter$1(transform, origin, scaleX, scaleY);
1183
1257
  data.transform = transform;
1184
1258
  }
1185
1259
 
1186
- const { get: get$2, translate } = MatrixHelper;
1187
- const tempBox = new Bounds();
1260
+ function layout(transform, box, x, y, scaleX, scaleY, rotation, skew) {
1261
+ if (rotation) rotate(transform, rotation);
1262
+ if (skew) skewHelper(transform, skew.x, skew.y);
1263
+ if (scaleX) scaleHelper(transform, scaleX, scaleY);
1264
+ translate$1(transform, box.x + x, box.y + y);
1265
+ }
1266
+
1267
+ const {get: get$2, translate: translate} = MatrixHelper;
1268
+
1269
+ const tempBox = new Bounds;
1270
+
1188
1271
  const tempScaleData = {};
1272
+
1189
1273
  const tempImage = {};
1274
+
1190
1275
  function createData(leafPaint, image, paint, box) {
1191
- const { changeful, sync, editing } = paint;
1192
- if (changeful)
1193
- leafPaint.changeful = changeful;
1194
- if (sync)
1195
- leafPaint.sync = sync;
1196
- if (editing)
1197
- leafPaint.editing = editing;
1276
+ const {changeful: changeful, sync: sync, scaleFixed: scaleFixed} = paint;
1277
+ if (changeful) leafPaint.changeful = changeful;
1278
+ if (sync) leafPaint.sync = sync;
1279
+ if (scaleFixed) leafPaint.scaleFixed = scaleFixed;
1198
1280
  leafPaint.data = getPatternData(paint, box, image);
1199
1281
  }
1282
+
1200
1283
  function getPatternData(paint, box, image) {
1201
- if (paint.padding)
1202
- box = tempBox.set(box).shrink(paint.padding);
1203
- if (paint.mode === 'strench')
1204
- paint.mode = 'stretch';
1205
- let { width, height } = image;
1206
- const { opacity, mode, align, offset, scale, size, rotation, skew, repeat, filters } = paint;
1284
+ if (paint.padding) box = tempBox.set(box).shrink(paint.padding);
1285
+ if (paint.mode === "strench") paint.mode = "stretch";
1286
+ let {width: width, height: height} = image;
1287
+ const {opacity: opacity, mode: mode, align: align, offset: offset, scale: scale, size: size, rotation: rotation, skew: skew, clipSize: clipSize, repeat: repeat, gap: gap, filters: filters} = paint;
1207
1288
  const sameBox = box.width === width && box.height === height;
1208
- const data = { mode };
1209
- const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
1289
+ const data = {
1290
+ mode: mode
1291
+ };
1292
+ const swapSize = align !== "center" && (rotation || 0) % 180 === 90;
1210
1293
  BoundsHelper.set(tempImage, 0, 0, swapSize ? height : width, swapSize ? width : height);
1211
1294
  let scaleX, scaleY;
1212
- if (!mode || mode === 'cover' || mode === 'fit') {
1295
+ if (!mode || mode === "cover" || mode === "fit") {
1213
1296
  if (!sameBox || rotation) {
1214
- scaleX = scaleY = BoundsHelper.getFitScale(box, tempImage, mode !== 'fit');
1297
+ scaleX = scaleY = BoundsHelper.getFitScale(box, tempImage, mode !== "fit");
1215
1298
  BoundsHelper.put(box, image, align, scaleX, false, tempImage);
1216
1299
  BoundsHelper.scale(tempImage, scaleX, scaleY, true);
1217
1300
  }
1218
- }
1219
- else {
1301
+ } else {
1220
1302
  if (scale || size) {
1221
1303
  MathHelper.getScaleData(scale, size, image, tempScaleData);
1222
1304
  scaleX = tempScaleData.scaleX;
1223
1305
  scaleY = tempScaleData.scaleY;
1224
1306
  }
1225
- if (align) {
1226
- if (scaleX)
1227
- BoundsHelper.scale(tempImage, scaleX, scaleY, true);
1228
- AlignHelper.toPoint(align, tempImage, box, tempImage, true, true);
1307
+ if (align || gap || repeat) {
1308
+ if (scaleX) BoundsHelper.scale(tempImage, scaleX, scaleY, true);
1309
+ if (align) AlignHelper.toPoint(align, tempImage, box, tempImage, true, true);
1229
1310
  }
1230
1311
  }
1231
- if (offset)
1232
- PointHelper.move(tempImage, offset);
1312
+ if (offset) PointHelper.move(tempImage, offset);
1233
1313
  switch (mode) {
1234
- case 'stretch':
1235
- if (!sameBox)
1236
- width = box.width, height = box.height;
1237
- break;
1238
- case 'normal':
1239
- case 'clip':
1240
- if (tempImage.x || tempImage.y || scaleX || rotation || skew)
1241
- clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew);
1242
- break;
1243
- case 'repeat':
1244
- if (!sameBox || scaleX || rotation)
1245
- repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, align);
1246
- if (!repeat)
1247
- data.repeat = 'repeat';
1248
- break;
1249
- case 'fit':
1250
- case 'cover':
1251
- default:
1252
- if (scaleX)
1253
- fillOrFitMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
1314
+ case "stretch":
1315
+ if (!sameBox) width = box.width, height = box.height;
1316
+ break;
1317
+
1318
+ case "normal":
1319
+ case "clip":
1320
+ if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew) clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, paint.clipSize);
1321
+ break;
1322
+
1323
+ case "repeat":
1324
+ if (!sameBox || scaleX || rotation || skew) repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform);
1325
+ if (!repeat) data.repeat = "repeat";
1326
+ const count = isObject(repeat);
1327
+ if (gap || count) data.gap = getGapData(gap, count && repeat, tempImage.width, tempImage.height, box);
1328
+ break;
1329
+
1330
+ case "fit":
1331
+ case "cover":
1332
+ default:
1333
+ if (scaleX) fillOrFitMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
1254
1334
  }
1255
1335
  if (!data.transform) {
1256
1336
  if (box.x || box.y) {
@@ -1258,49 +1338,69 @@ function getPatternData(paint, box, image) {
1258
1338
  translate(data.transform, box.x, box.y);
1259
1339
  }
1260
1340
  }
1261
- if (scaleX && mode !== 'stretch') {
1341
+ if (scaleX && mode !== "stretch") {
1262
1342
  data.scaleX = scaleX;
1263
1343
  data.scaleY = scaleY;
1264
1344
  }
1265
1345
  data.width = width;
1266
1346
  data.height = height;
1267
- if (opacity)
1268
- data.opacity = opacity;
1269
- if (filters)
1270
- data.filters = filters;
1271
- if (repeat)
1272
- data.repeat = typeof repeat === 'string' ? (repeat === 'x' ? 'repeat-x' : 'repeat-y') : 'repeat';
1347
+ if (opacity) data.opacity = opacity;
1348
+ if (filters) data.filters = filters;
1349
+ if (repeat) data.repeat = isString(repeat) ? repeat === "x" ? "repeat-x" : "repeat-y" : "repeat";
1273
1350
  return data;
1274
1351
  }
1275
1352
 
1276
- let cache, box = new Bounds();
1277
- const { isSame } = BoundsHelper;
1353
+ function getGapData(gap, repeat, width, height, box) {
1354
+ let xGap, yGap;
1355
+ if (isObject(gap)) xGap = gap.x, yGap = gap.y; else xGap = yGap = gap;
1356
+ return {
1357
+ x: getGapValue(xGap, width, box.width, repeat && repeat.x),
1358
+ y: getGapValue(yGap, height, box.height, repeat && repeat.y)
1359
+ };
1360
+ }
1361
+
1362
+ function getGapValue(gap, size, totalSize, rows) {
1363
+ const auto = isString(gap) || rows;
1364
+ const remain = rows ? totalSize - rows * size : totalSize % size;
1365
+ const value = auto ? remain / ((rows || Math.floor(totalSize / size)) - 1) : gap;
1366
+ return gap === "auto" ? value < 0 ? 0 : value : value;
1367
+ }
1368
+
1369
+ let cache, box = new Bounds;
1370
+
1371
+ const {isSame: isSame} = BoundsHelper;
1372
+
1278
1373
  function image(ui, attrName, paint, boxBounds, firstUse) {
1279
1374
  let leafPaint, event;
1280
1375
  const image = ImageManager.get(paint);
1281
1376
  if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
1282
1377
  leafPaint = cache.leafPaint;
1283
- }
1284
- else {
1285
- leafPaint = { type: paint.type, image };
1286
- if (image.hasAlphaPixel)
1287
- leafPaint.isTransparent = true;
1288
- cache = image.use > 1 ? { leafPaint, paint, boxBounds: box.set(boxBounds) } : null;
1289
- }
1290
- if (firstUse || image.loading)
1291
- event = { image, attrName, attrValue: paint };
1378
+ } else {
1379
+ leafPaint = {
1380
+ type: paint.type,
1381
+ image: image
1382
+ };
1383
+ if (image.hasAlphaPixel) leafPaint.isTransparent = true;
1384
+ cache = image.use > 1 ? {
1385
+ leafPaint: leafPaint,
1386
+ paint: paint,
1387
+ boxBounds: box.set(boxBounds)
1388
+ } : null;
1389
+ }
1390
+ if (firstUse || image.loading) event = {
1391
+ image: image,
1392
+ attrName: attrName,
1393
+ attrValue: paint
1394
+ };
1292
1395
  if (image.ready) {
1293
1396
  checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds);
1294
1397
  if (firstUse) {
1295
1398
  onLoad(ui, event);
1296
1399
  onLoadSuccess(ui, event);
1297
1400
  }
1298
- }
1299
- else if (image.error) {
1300
- if (firstUse)
1301
- onLoadError(ui, event, image.error);
1302
- }
1303
- else {
1401
+ } else if (image.error) {
1402
+ if (firstUse) onLoadError(ui, event, image.error);
1403
+ } else {
1304
1404
  if (firstUse) {
1305
1405
  ignoreRender(ui, true);
1306
1406
  onLoad(ui, event);
@@ -1309,107 +1409,105 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
1309
1409
  ignoreRender(ui, false);
1310
1410
  if (!ui.destroyed) {
1311
1411
  if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds)) {
1312
- if (image.hasAlphaPixel)
1313
- ui.__layout.hitCanvasChanged = true;
1314
- ui.forceUpdate('surface');
1412
+ if (image.hasAlphaPixel) ui.__layout.hitCanvasChanged = true;
1413
+ ui.forceUpdate("surface");
1315
1414
  }
1316
1415
  onLoadSuccess(ui, event);
1317
1416
  }
1318
1417
  leafPaint.loadId = undefined;
1319
- }, (error) => {
1418
+ }, error => {
1320
1419
  ignoreRender(ui, false);
1321
1420
  onLoadError(ui, event, error);
1322
1421
  leafPaint.loadId = undefined;
1323
1422
  });
1324
1423
  if (ui.placeholderColor) {
1325
- if (!ui.placeholderDelay)
1326
- image.isPlacehold = true;
1327
- else
1328
- setTimeout(() => {
1329
- if (!image.ready) {
1330
- image.isPlacehold = true;
1331
- ui.forceUpdate('surface');
1332
- }
1333
- }, ui.placeholderDelay);
1424
+ if (!ui.placeholderDelay) image.isPlacehold = true; else setTimeout(() => {
1425
+ if (!image.ready) {
1426
+ image.isPlacehold = true;
1427
+ ui.forceUpdate("surface");
1428
+ }
1429
+ }, ui.placeholderDelay);
1334
1430
  }
1335
1431
  }
1336
1432
  return leafPaint;
1337
1433
  }
1434
+
1338
1435
  function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
1339
- if (attrName === 'fill' && !ui.__.__naturalWidth) {
1436
+ if (attrName === "fill" && !ui.__.__naturalWidth) {
1340
1437
  const data = ui.__;
1341
1438
  data.__naturalWidth = image.width / data.pixelRatio;
1342
1439
  data.__naturalHeight = image.height / data.pixelRatio;
1343
1440
  if (data.__autoSide) {
1344
- ui.forceUpdate('width');
1441
+ ui.forceUpdate("width");
1345
1442
  if (ui.__proxyData) {
1346
- ui.setProxyAttr('width', data.width);
1347
- ui.setProxyAttr('height', data.height);
1443
+ ui.setProxyAttr("width", data.width);
1444
+ ui.setProxyAttr("height", data.height);
1348
1445
  }
1349
1446
  return false;
1350
1447
  }
1351
1448
  }
1352
- if (!leafPaint.data)
1353
- createData(leafPaint, image, paint, boxBounds);
1449
+ if (!leafPaint.data) createData(leafPaint, image, paint, boxBounds);
1354
1450
  return true;
1355
1451
  }
1452
+
1356
1453
  function onLoad(ui, event) {
1357
1454
  emit(ui, ImageEvent.LOAD, event);
1358
1455
  }
1456
+
1359
1457
  function onLoadSuccess(ui, event) {
1360
1458
  emit(ui, ImageEvent.LOADED, event);
1361
1459
  }
1460
+
1362
1461
  function onLoadError(ui, event, error) {
1363
1462
  event.error = error;
1364
- ui.forceUpdate('surface');
1463
+ ui.forceUpdate("surface");
1365
1464
  emit(ui, ImageEvent.ERROR, event);
1366
1465
  }
1466
+
1367
1467
  function emit(ui, type, data) {
1368
- if (ui.hasEvent(type))
1369
- ui.emitEvent(new ImageEvent(type, data));
1468
+ if (ui.hasEvent(type)) ui.emitEvent(new ImageEvent(type, data));
1370
1469
  }
1470
+
1371
1471
  function ignoreRender(ui, value) {
1372
- const { leafer } = ui;
1373
- if (leafer && leafer.viewReady)
1374
- leafer.renderer.ignore = value;
1472
+ const {leafer: leafer} = ui;
1473
+ if (leafer && leafer.viewReady) leafer.renderer.ignore = value;
1375
1474
  }
1376
1475
 
1377
- const { get: get$1, scale, copy: copy$1 } = MatrixHelper;
1378
- const { ceil, abs: abs$1 } = Math;
1476
+ const {get: get$1, scale: scale, copy: copy$1} = MatrixHelper;
1477
+
1478
+ const {floor: floor, max: max, abs: abs} = Math;
1479
+
1379
1480
  function createPattern(ui, paint, pixelRatio) {
1380
- let { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1381
- const id = scaleX + '-' + scaleY + '-' + pixelRatio;
1481
+ let {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
1482
+ const id = scaleX + "-" + scaleY + "-" + pixelRatio;
1382
1483
  if (paint.patternId !== id && !ui.destroyed) {
1383
- scaleX = abs$1(scaleX);
1384
- scaleY = abs$1(scaleY);
1385
- const { image, data } = paint;
1386
- let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, transform, repeat } = data;
1484
+ const {image: image, data: data} = paint;
1485
+ let imageScale, imageMatrix, {width: width, height: height, scaleX: sx, scaleY: sy, transform: transform, repeat: repeat, gap: gap} = data;
1486
+ scaleX *= pixelRatio;
1487
+ scaleY *= pixelRatio;
1488
+ const xGap = gap && gap.x * scaleX;
1489
+ const yGap = gap && gap.y * scaleY;
1387
1490
  if (sx) {
1388
- sx = abs$1(sx);
1389
- sy = abs$1(sy);
1491
+ sx = abs(sx);
1492
+ sy = abs(sy);
1390
1493
  imageMatrix = get$1();
1391
1494
  copy$1(imageMatrix, transform);
1392
1495
  scale(imageMatrix, 1 / sx, 1 / sy);
1393
1496
  scaleX *= sx;
1394
1497
  scaleY *= sy;
1395
1498
  }
1396
- scaleX *= pixelRatio;
1397
- scaleY *= pixelRatio;
1398
1499
  width *= scaleX;
1399
1500
  height *= scaleY;
1400
1501
  const size = width * height;
1401
1502
  if (!repeat) {
1402
- if (size > Platform.image.maxCacheSize)
1403
- return false;
1503
+ if (size > Platform.image.maxCacheSize) return false;
1404
1504
  }
1405
1505
  let maxSize = Platform.image.maxPatternSize;
1406
1506
  if (!image.isSVG) {
1407
1507
  const imageSize = image.width * image.height;
1408
- if (maxSize > imageSize)
1409
- maxSize = imageSize;
1508
+ if (maxSize > imageSize) maxSize = imageSize;
1410
1509
  }
1411
- if (size > maxSize)
1412
- imageScale = Math.sqrt(size / maxSize);
1510
+ if (size > maxSize) imageScale = Math.sqrt(size / maxSize);
1413
1511
  if (imageScale) {
1414
1512
  scaleX /= imageScale;
1415
1513
  scaleY /= imageScale;
@@ -1423,62 +1521,62 @@ function createPattern(ui, paint, pixelRatio) {
1423
1521
  if (transform || scaleX !== 1 || scaleY !== 1) {
1424
1522
  if (!imageMatrix) {
1425
1523
  imageMatrix = get$1();
1426
- if (transform)
1427
- copy$1(imageMatrix, transform);
1524
+ if (transform) copy$1(imageMatrix, transform);
1428
1525
  }
1429
1526
  scale(imageMatrix, 1 / scaleX, 1 / scaleY);
1430
1527
  }
1431
- const canvas = image.getCanvas(ceil(width) || 1, ceil(height) || 1, data.opacity, data.filters);
1432
- const pattern = image.getPattern(canvas, repeat || (Platform.origin.noRepeat || 'no-repeat'), imageMatrix, paint);
1528
+ if (imageMatrix) {
1529
+ const canvasWidth = width + (xGap || 0), canvasHeight = height + (yGap || 0);
1530
+ scale(imageMatrix, canvasWidth / max(floor(canvasWidth), 1), canvasHeight / max(floor(canvasHeight), 1));
1531
+ }
1532
+ const canvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap);
1533
+ const pattern = image.getPattern(canvas, repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
1433
1534
  paint.style = pattern;
1434
1535
  paint.patternId = id;
1435
1536
  return true;
1436
- }
1437
- else {
1537
+ } else {
1438
1538
  return false;
1439
1539
  }
1440
1540
  }
1441
1541
 
1442
- const { abs } = Math;
1443
1542
  function checkImage(ui, canvas, paint, allowDraw) {
1444
- const { scaleX, scaleY } = ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1445
- const { pixelRatio } = canvas, { data } = paint;
1446
- if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
1543
+ const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
1544
+ const {pixelRatio: pixelRatio} = canvas, {data: data} = paint;
1545
+ if (!data || paint.patternId === scaleX + "-" + scaleY + "-" + pixelRatio && !Export.running) {
1447
1546
  return false;
1448
- }
1449
- else {
1547
+ } else {
1450
1548
  if (allowDraw) {
1451
1549
  if (data.repeat) {
1452
1550
  allowDraw = false;
1453
- }
1454
- else {
1455
- if (!(paint.changeful || ResizeEvent.isResizing(ui) || Export.running)) {
1456
- let { width, height } = data;
1457
- width *= abs(scaleX) * pixelRatio;
1458
- height *= abs(scaleY) * pixelRatio;
1551
+ } else {
1552
+ if (!(paint.changeful || Platform.name === "miniapp" && ResizeEvent.isResizing(ui) || Export.running)) {
1553
+ let {width: width, height: height} = data;
1554
+ width *= scaleX * pixelRatio;
1555
+ height *= scaleY * pixelRatio;
1459
1556
  if (data.scaleX) {
1460
1557
  width *= data.scaleX;
1461
1558
  height *= data.scaleY;
1462
1559
  }
1463
- allowDraw = (width * height > Platform.image.maxCacheSize);
1560
+ allowDraw = width * height > Platform.image.maxCacheSize;
1464
1561
  }
1465
1562
  }
1466
1563
  }
1467
1564
  if (allowDraw) {
1565
+ if (ui.__.__isFastShadow) {
1566
+ canvas.fillStyle = paint.style || "#000";
1567
+ canvas.fill();
1568
+ }
1468
1569
  drawImage(ui, canvas, paint, data);
1469
1570
  return true;
1470
- }
1471
- else {
1571
+ } else {
1472
1572
  if (!paint.style || paint.sync || Export.running) {
1473
1573
  createPattern(ui, paint, pixelRatio);
1474
- }
1475
- else {
1574
+ } else {
1476
1575
  if (!paint.patternTask) {
1477
- paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function* () {
1576
+ paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function*() {
1478
1577
  paint.patternTask = null;
1479
- if (canvas.bounds.hit(ui.__nowWorld))
1480
- createPattern(ui, paint, pixelRatio);
1481
- ui.forceUpdate('surface');
1578
+ if (canvas.bounds.hit(ui.__nowWorld)) createPattern(ui, paint, pixelRatio);
1579
+ ui.forceUpdate("surface");
1482
1580
  }), 300);
1483
1581
  }
1484
1582
  }
@@ -1486,39 +1584,35 @@ function checkImage(ui, canvas, paint, allowDraw) {
1486
1584
  }
1487
1585
  }
1488
1586
  }
1587
+
1489
1588
  function drawImage(ui, canvas, paint, data) {
1490
1589
  canvas.save();
1491
1590
  canvas.clipUI(ui);
1492
- if (paint.blendMode)
1493
- canvas.blendMode = paint.blendMode;
1494
- if (data.opacity)
1495
- canvas.opacity *= data.opacity;
1496
- if (data.transform)
1497
- canvas.transform(data.transform);
1591
+ if (paint.blendMode) canvas.blendMode = paint.blendMode;
1592
+ if (data.opacity) canvas.opacity *= data.opacity;
1593
+ if (data.transform) canvas.transform(data.transform);
1498
1594
  canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1499
1595
  canvas.restore();
1500
1596
  }
1501
1597
 
1502
1598
  function recycleImage(attrName, data) {
1503
- const paints = data['_' + attrName];
1504
- if (paints instanceof Array) {
1599
+ const paints = data["_" + attrName];
1600
+ if (isArray(paints)) {
1505
1601
  let paint, image, recycleMap, input, url;
1506
1602
  for (let i = 0, len = paints.length; i < len; i++) {
1507
1603
  paint = paints[i];
1508
1604
  image = paint.image;
1509
1605
  url = image && image.url;
1510
1606
  if (url) {
1511
- if (!recycleMap)
1512
- recycleMap = {};
1607
+ if (!recycleMap) recycleMap = {};
1513
1608
  recycleMap[url] = true;
1514
1609
  ImageManager.recycle(image);
1515
1610
  if (image.loading) {
1516
1611
  if (!input) {
1517
- input = (data.__input && data.__input[attrName]) || [];
1518
- if (!(input instanceof Array))
1519
- input = [input];
1612
+ input = data.__input && data.__input[attrName] || [];
1613
+ if (!isArray(input)) input = [ input ];
1520
1614
  }
1521
- image.unload(paints[i].loadId, !input.some((item) => item.url === url));
1615
+ image.unload(paints[i].loadId, !input.some(item => item.url === url));
1522
1616
  }
1523
1617
  }
1524
1618
  }
@@ -1528,75 +1622,85 @@ function recycleImage(attrName, data) {
1528
1622
  }
1529
1623
 
1530
1624
  const PaintImageModule = {
1531
- image,
1532
- checkImage,
1533
- createPattern,
1534
- recycleImage,
1535
- createData,
1536
- getPatternData,
1537
- fillOrFitMode,
1538
- clipMode,
1539
- repeatMode
1625
+ image: image,
1626
+ checkImage: checkImage,
1627
+ createPattern: createPattern,
1628
+ recycleImage: recycleImage,
1629
+ createData: createData,
1630
+ getPatternData: getPatternData,
1631
+ fillOrFitMode: fillOrFitMode,
1632
+ clipMode: clipMode,
1633
+ repeatMode: repeatMode
1540
1634
  };
1541
1635
 
1542
- const { toPoint: toPoint$2 } = AroundHelper, { hasTransparent } = ColorConvert;
1636
+ const {toPoint: toPoint$2} = AroundHelper, {hasTransparent: hasTransparent} = ColorConvert;
1637
+
1543
1638
  const realFrom$2 = {};
1639
+
1544
1640
  const realTo$2 = {};
1641
+
1545
1642
  function linearGradient(paint, box) {
1546
- let { from, to, type, opacity } = paint;
1547
- toPoint$2(from || 'top', box, realFrom$2);
1548
- toPoint$2(to || 'bottom', box, realTo$2);
1643
+ let {from: from, to: to, type: type, opacity: opacity} = paint;
1644
+ toPoint$2(from || "top", box, realFrom$2);
1645
+ toPoint$2(to || "bottom", box, realTo$2);
1549
1646
  const style = Platform.canvas.createLinearGradient(realFrom$2.x, realFrom$2.y, realTo$2.x, realTo$2.y);
1550
- const data = { type, style };
1647
+ const data = {
1648
+ type: type,
1649
+ style: style
1650
+ };
1551
1651
  applyStops(data, style, paint.stops, opacity);
1552
1652
  return data;
1553
1653
  }
1654
+
1554
1655
  function applyStops(data, gradient, stops, opacity) {
1555
1656
  if (stops) {
1556
1657
  let stop, color, offset, isTransparent;
1557
1658
  for (let i = 0, len = stops.length; i < len; i++) {
1558
1659
  stop = stops[i];
1559
- if (typeof stop === 'string')
1560
- offset = i / (len - 1), color = ColorConvert.string(stop, opacity);
1561
- else
1562
- offset = stop.offset, color = ColorConvert.string(stop.color, opacity);
1660
+ if (isString(stop)) offset = i / (len - 1), color = ColorConvert.string(stop, opacity); else offset = stop.offset,
1661
+ color = ColorConvert.string(stop.color, opacity);
1563
1662
  gradient.addColorStop(offset, color);
1564
- if (!isTransparent && hasTransparent(color))
1565
- isTransparent = true;
1663
+ if (!isTransparent && hasTransparent(color)) isTransparent = true;
1566
1664
  }
1567
- if (isTransparent)
1568
- data.isTransparent = true;
1665
+ if (isTransparent) data.isTransparent = true;
1569
1666
  }
1570
1667
  }
1571
1668
 
1572
- const { getAngle, getDistance: getDistance$1 } = PointHelper;
1573
- const { get, rotateOfOuter, scaleOfOuter } = MatrixHelper;
1574
- const { toPoint: toPoint$1 } = AroundHelper;
1669
+ const {getAngle: getAngle, getDistance: getDistance$1} = PointHelper;
1670
+
1671
+ const {get: get, rotateOfOuter: rotateOfOuter, scaleOfOuter: scaleOfOuter} = MatrixHelper;
1672
+
1673
+ const {toPoint: toPoint$1} = AroundHelper;
1674
+
1575
1675
  const realFrom$1 = {};
1676
+
1576
1677
  const realTo$1 = {};
1678
+
1577
1679
  function radialGradient(paint, box) {
1578
- let { from, to, type, opacity, stretch } = paint;
1579
- toPoint$1(from || 'center', box, realFrom$1);
1580
- toPoint$1(to || 'bottom', box, realTo$1);
1680
+ let {from: from, to: to, type: type, opacity: opacity, stretch: stretch} = paint;
1681
+ toPoint$1(from || "center", box, realFrom$1);
1682
+ toPoint$1(to || "bottom", box, realTo$1);
1581
1683
  const style = Platform.canvas.createRadialGradient(realFrom$1.x, realFrom$1.y, 0, realFrom$1.x, realFrom$1.y, getDistance$1(realFrom$1, realTo$1));
1582
- const data = { type, style };
1684
+ const data = {
1685
+ type: type,
1686
+ style: style
1687
+ };
1583
1688
  applyStops(data, style, paint.stops, opacity);
1584
1689
  const transform = getTransform(box, realFrom$1, realTo$1, stretch, true);
1585
- if (transform)
1586
- data.transform = transform;
1690
+ if (transform) data.transform = transform;
1587
1691
  return data;
1588
1692
  }
1693
+
1589
1694
  function getTransform(box, from, to, stretch, rotate90) {
1590
1695
  let transform;
1591
- const { width, height } = box;
1696
+ const {width: width, height: height} = box;
1592
1697
  if (width !== height || stretch) {
1593
1698
  const angle = getAngle(from, to);
1594
1699
  transform = get();
1595
1700
  if (rotate90) {
1596
1701
  scaleOfOuter(transform, from, width / height * (stretch || 1), 1);
1597
1702
  rotateOfOuter(transform, from, angle + 90);
1598
- }
1599
- else {
1703
+ } else {
1600
1704
  scaleOfOuter(transform, from, 1, width / height * (stretch || 1));
1601
1705
  rotateOfOuter(transform, from, angle);
1602
1706
  }
@@ -1604,84 +1708,94 @@ function getTransform(box, from, to, stretch, rotate90) {
1604
1708
  return transform;
1605
1709
  }
1606
1710
 
1607
- const { getDistance } = PointHelper;
1608
- const { toPoint } = AroundHelper;
1711
+ const {getDistance: getDistance} = PointHelper;
1712
+
1713
+ const {toPoint: toPoint} = AroundHelper;
1714
+
1609
1715
  const realFrom = {};
1716
+
1610
1717
  const realTo = {};
1718
+
1611
1719
  function conicGradient(paint, box) {
1612
- let { from, to, type, opacity, stretch } = paint;
1613
- toPoint(from || 'center', box, realFrom);
1614
- toPoint(to || 'bottom', box, realTo);
1720
+ let {from: from, to: to, type: type, opacity: opacity, stretch: stretch} = paint;
1721
+ toPoint(from || "center", box, realFrom);
1722
+ toPoint(to || "bottom", box, realTo);
1615
1723
  const style = Platform.conicGradientSupport ? Platform.canvas.createConicGradient(0, realFrom.x, realFrom.y) : Platform.canvas.createRadialGradient(realFrom.x, realFrom.y, 0, realFrom.x, realFrom.y, getDistance(realFrom, realTo));
1616
- const data = { type, style };
1724
+ const data = {
1725
+ type: type,
1726
+ style: style
1727
+ };
1617
1728
  applyStops(data, style, paint.stops, opacity);
1618
1729
  const transform = getTransform(box, realFrom, realTo, stretch || 1, Platform.conicGradientRotate90);
1619
- if (transform)
1620
- data.transform = transform;
1730
+ if (transform) data.transform = transform;
1621
1731
  return data;
1622
1732
  }
1623
1733
 
1624
1734
  const PaintGradientModule = {
1625
- linearGradient,
1626
- radialGradient,
1627
- conicGradient,
1628
- getTransform
1735
+ linearGradient: linearGradient,
1736
+ radialGradient: radialGradient,
1737
+ conicGradient: conicGradient,
1738
+ getTransform: getTransform
1629
1739
  };
1630
1740
 
1631
- const { copy, toOffsetOutBounds: toOffsetOutBounds$1 } = BoundsHelper;
1741
+ const {copy: copy, toOffsetOutBounds: toOffsetOutBounds$1} = BoundsHelper;
1742
+
1632
1743
  const tempBounds = {};
1744
+
1633
1745
  const offsetOutBounds$1 = {};
1746
+
1634
1747
  function shadow(ui, current, shape) {
1635
1748
  let copyBounds, spreadScale;
1636
- const { __nowWorld: nowWorld, __layout } = ui;
1637
- const { shadow } = ui.__;
1638
- const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
1749
+ const {__nowWorld: nowWorld, __layout: __layout} = ui;
1750
+ const {shadow: shadow} = ui.__;
1751
+ const {worldCanvas: worldCanvas, bounds: bounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
1639
1752
  const other = current.getSameCanvas();
1640
1753
  const end = shadow.length - 1;
1641
1754
  toOffsetOutBounds$1(bounds, offsetOutBounds$1);
1642
1755
  shadow.forEach((item, index) => {
1643
- other.setWorldShadow((offsetOutBounds$1.offsetX + item.x * scaleX), (offsetOutBounds$1.offsetY + item.y * scaleY), item.blur * scaleX, ColorConvert.string(item.color));
1644
- spreadScale = item.spread ? 1 + item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) : 0;
1756
+ let otherScale = 1;
1757
+ if (item.scaleFixed) {
1758
+ const sx = Math.abs(nowWorld.scaleX);
1759
+ if (sx > 1) otherScale = 1 / sx;
1760
+ }
1761
+ other.setWorldShadow(offsetOutBounds$1.offsetX + item.x * scaleX * otherScale, offsetOutBounds$1.offsetY + item.y * scaleY * otherScale, item.blur * scaleX * otherScale, ColorConvert.string(item.color));
1762
+ spreadScale = item.spread ? 1 + item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) * otherScale : 0;
1645
1763
  drawWorldShadow(other, offsetOutBounds$1, spreadScale, shape);
1646
1764
  copyBounds = bounds;
1647
1765
  if (item.box) {
1648
1766
  other.restore();
1649
1767
  other.save();
1650
1768
  if (worldCanvas) {
1651
- other.copyWorld(other, bounds, nowWorld, 'copy');
1769
+ other.copyWorld(other, bounds, nowWorld, "copy");
1652
1770
  copyBounds = nowWorld;
1653
1771
  }
1654
- worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, 'destination-out') : other.copyWorld(shape.canvas, shapeBounds, bounds, 'destination-out');
1655
- }
1656
- if (ui.__worldFlipped)
1657
- current.copyWorldByReset(other, copyBounds, nowWorld, item.blendMode);
1658
- else
1659
- current.copyWorldToInner(other, copyBounds, __layout.renderBounds, item.blendMode);
1660
- if (end && index < end)
1661
- other.clearWorld(copyBounds, true);
1772
+ worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, "destination-out") : other.copyWorld(shape.canvas, shapeBounds, bounds, "destination-out");
1773
+ }
1774
+ LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
1775
+ if (end && index < end) other.clearWorld(copyBounds, true);
1662
1776
  });
1663
1777
  other.recycle(copyBounds);
1664
1778
  }
1779
+
1665
1780
  function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
1666
- const { bounds, shapeBounds } = shape;
1781
+ const {bounds: bounds, shapeBounds: shapeBounds} = shape;
1667
1782
  if (Platform.fullImageShadow) {
1668
1783
  copy(tempBounds, canvas.bounds);
1669
- tempBounds.x += (outBounds.x - shapeBounds.x);
1670
- tempBounds.y += (outBounds.y - shapeBounds.y);
1784
+ tempBounds.x += outBounds.x - shapeBounds.x;
1785
+ tempBounds.y += outBounds.y - shapeBounds.y;
1671
1786
  if (spreadScale) {
1672
- const { matrix } = shape;
1673
- tempBounds.x -= (bounds.x + (matrix ? matrix.e : 0) + bounds.width / 2) * (spreadScale - 1);
1674
- tempBounds.y -= (bounds.y + (matrix ? matrix.f : 0) + bounds.height / 2) * (spreadScale - 1);
1787
+ const {fitMatrix: fitMatrix} = shape;
1788
+ tempBounds.x -= (bounds.x + (fitMatrix ? fitMatrix.e : 0) + bounds.width / 2) * (spreadScale - 1);
1789
+ tempBounds.y -= (bounds.y + (fitMatrix ? fitMatrix.f : 0) + bounds.height / 2) * (spreadScale - 1);
1675
1790
  tempBounds.width *= spreadScale;
1676
1791
  tempBounds.height *= spreadScale;
1677
1792
  }
1678
1793
  canvas.copyWorld(shape.canvas, canvas.bounds, tempBounds);
1679
- }
1680
- else {
1794
+ } else {
1681
1795
  if (spreadScale) {
1682
1796
  copy(tempBounds, outBounds);
1683
- tempBounds.x -= (outBounds.width / 2) * (spreadScale - 1);
1684
- tempBounds.y -= (outBounds.height / 2) * (spreadScale - 1);
1797
+ tempBounds.x -= outBounds.width / 2 * (spreadScale - 1);
1798
+ tempBounds.y -= outBounds.height / 2 * (spreadScale - 1);
1685
1799
  tempBounds.width *= spreadScale;
1686
1800
  tempBounds.height *= spreadScale;
1687
1801
  }
@@ -1689,178 +1803,184 @@ function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
1689
1803
  }
1690
1804
  }
1691
1805
 
1692
- const { toOffsetOutBounds } = BoundsHelper;
1806
+ const {toOffsetOutBounds: toOffsetOutBounds} = BoundsHelper;
1807
+
1693
1808
  const offsetOutBounds = {};
1809
+
1694
1810
  function innerShadow(ui, current, shape) {
1695
1811
  let copyBounds, spreadScale;
1696
- const { __nowWorld: nowWorld, __layout } = ui;
1697
- const { innerShadow } = ui.__;
1698
- const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
1812
+ const {__nowWorld: nowWorld, __layout: __layout} = ui;
1813
+ const {innerShadow: innerShadow} = ui.__;
1814
+ const {worldCanvas: worldCanvas, bounds: bounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
1699
1815
  const other = current.getSameCanvas();
1700
1816
  const end = innerShadow.length - 1;
1701
1817
  toOffsetOutBounds(bounds, offsetOutBounds);
1702
1818
  innerShadow.forEach((item, index) => {
1819
+ let otherScale = 1;
1820
+ if (item.scaleFixed) {
1821
+ const sx = Math.abs(nowWorld.scaleX);
1822
+ if (sx > 1) otherScale = 1 / sx;
1823
+ }
1703
1824
  other.save();
1704
- other.setWorldShadow((offsetOutBounds.offsetX + item.x * scaleX), (offsetOutBounds.offsetY + item.y * scaleY), item.blur * scaleX);
1705
- spreadScale = item.spread ? 1 - item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) : 0;
1825
+ other.setWorldShadow(offsetOutBounds.offsetX + item.x * scaleX * otherScale, offsetOutBounds.offsetY + item.y * scaleY * otherScale, item.blur * scaleX * otherScale);
1826
+ spreadScale = item.spread ? 1 - item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) * otherScale : 0;
1706
1827
  drawWorldShadow(other, offsetOutBounds, spreadScale, shape);
1707
1828
  other.restore();
1708
1829
  if (worldCanvas) {
1709
- other.copyWorld(other, bounds, nowWorld, 'copy');
1710
- other.copyWorld(worldCanvas, nowWorld, nowWorld, 'source-out');
1830
+ other.copyWorld(other, bounds, nowWorld, "copy");
1831
+ other.copyWorld(worldCanvas, nowWorld, nowWorld, "source-out");
1711
1832
  copyBounds = nowWorld;
1712
- }
1713
- else {
1714
- other.copyWorld(shape.canvas, shapeBounds, bounds, 'source-out');
1833
+ } else {
1834
+ other.copyWorld(shape.canvas, shapeBounds, bounds, "source-out");
1715
1835
  copyBounds = bounds;
1716
1836
  }
1717
- other.fillWorld(copyBounds, ColorConvert.string(item.color), 'source-in');
1718
- if (ui.__worldFlipped)
1719
- current.copyWorldByReset(other, copyBounds, nowWorld, item.blendMode);
1720
- else
1721
- current.copyWorldToInner(other, copyBounds, __layout.renderBounds, item.blendMode);
1722
- if (end && index < end)
1723
- other.clearWorld(copyBounds, true);
1837
+ other.fillWorld(copyBounds, ColorConvert.string(item.color), "source-in");
1838
+ LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
1839
+ if (end && index < end) other.clearWorld(copyBounds, true);
1724
1840
  });
1725
1841
  other.recycle(copyBounds);
1726
1842
  }
1727
1843
 
1728
1844
  function blur(ui, current, origin) {
1729
- const { blur } = ui.__;
1845
+ const {blur: blur} = ui.__;
1730
1846
  origin.setWorldBlur(blur * ui.__nowWorld.a);
1731
1847
  origin.copyWorldToInner(current, ui.__nowWorld, ui.__layout.renderBounds);
1732
- origin.filter = 'none';
1848
+ origin.filter = "none";
1733
1849
  }
1734
1850
 
1735
- function backgroundBlur(_ui, _current, _shape) {
1736
- }
1851
+ function backgroundBlur(_ui, _current, _shape) {}
1737
1852
 
1738
1853
  const EffectModule = {
1739
- shadow,
1740
- innerShadow,
1741
- blur,
1742
- backgroundBlur
1854
+ shadow: shadow,
1855
+ innerShadow: innerShadow,
1856
+ blur: blur,
1857
+ backgroundBlur: backgroundBlur
1743
1858
  };
1744
1859
 
1745
- const { excludeRenderBounds } = LeafBoundsHelper;
1746
- Group.prototype.__renderMask = function (canvas, options) {
1860
+ const {excludeRenderBounds: excludeRenderBounds} = LeafBoundsHelper;
1861
+
1862
+ let usedGrayscaleAlpha;
1863
+
1864
+ Group.prototype.__renderMask = function(canvas, options) {
1747
1865
  let child, maskCanvas, contentCanvas, maskOpacity, currentMask, mask;
1748
- const { children } = this;
1866
+ const {children: children} = this;
1749
1867
  for (let i = 0, len = children.length; i < len; i++) {
1750
1868
  child = children[i], mask = child.__.mask;
1751
1869
  if (mask) {
1752
1870
  if (currentMask) {
1753
- maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
1871
+ maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
1754
1872
  maskCanvas = contentCanvas = null;
1755
1873
  }
1756
- if (mask === 'path' || mask === 'clipping-path') {
1757
- if (child.opacity < 1) {
1758
- currentMask = 'opacity-path';
1759
- maskOpacity = child.opacity;
1760
- if (!contentCanvas)
1761
- contentCanvas = getCanvas(canvas);
1762
- }
1763
- else {
1764
- currentMask = 'path';
1874
+ maskOpacity = child.__.opacity;
1875
+ usedGrayscaleAlpha = false;
1876
+ if (mask === "path" || mask === "clipping-path") {
1877
+ if (maskOpacity < 1) {
1878
+ currentMask = "opacity-path";
1879
+ if (!contentCanvas) contentCanvas = getCanvas(canvas);
1880
+ } else {
1881
+ currentMask = "path";
1765
1882
  canvas.save();
1766
1883
  }
1767
1884
  child.__clip(contentCanvas || canvas, options);
1768
- }
1769
- else {
1770
- currentMask = mask === 'grayscale' ? 'grayscale' : 'alpha';
1771
- if (!maskCanvas)
1772
- maskCanvas = getCanvas(canvas);
1773
- if (!contentCanvas)
1774
- contentCanvas = getCanvas(canvas);
1885
+ } else {
1886
+ currentMask = mask === "grayscale" ? "grayscale" : "alpha";
1887
+ if (!maskCanvas) maskCanvas = getCanvas(canvas);
1888
+ if (!contentCanvas) contentCanvas = getCanvas(canvas);
1775
1889
  child.__render(maskCanvas, options);
1776
1890
  }
1777
- if (!(mask === 'clipping' || mask === 'clipping-path'))
1778
- continue;
1779
- }
1780
- if (excludeRenderBounds(child, options))
1891
+ if (mask === "clipping" || mask === "clipping-path") excludeRenderBounds(child, options) || child.__render(canvas, options);
1781
1892
  continue;
1782
- child.__render(contentCanvas || canvas, options);
1893
+ }
1894
+ const childBlendMode = maskOpacity === 1 && child.__.__blendMode;
1895
+ if (childBlendMode) maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, false);
1896
+ excludeRenderBounds(child, options) || child.__render(contentCanvas || canvas, options);
1897
+ if (childBlendMode) maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, childBlendMode, false);
1783
1898
  }
1784
- maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
1899
+ maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
1785
1900
  };
1786
- function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity) {
1901
+
1902
+ function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity, blendMode, recycle) {
1787
1903
  switch (maskMode) {
1788
- case 'grayscale':
1789
- maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
1790
- case 'alpha':
1791
- usePixelMask(leaf, canvas, contentCanvas, maskCanvas);
1792
- break;
1793
- case 'opacity-path':
1794
- copyContent(leaf, canvas, contentCanvas, maskOpacity);
1795
- break;
1796
- case 'path':
1797
- canvas.restore();
1904
+ case "grayscale":
1905
+ if (!usedGrayscaleAlpha) usedGrayscaleAlpha = true, maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
1906
+
1907
+ case "alpha":
1908
+ usePixelMask(leaf, canvas, contentCanvas, maskCanvas, blendMode, recycle);
1909
+ break;
1910
+
1911
+ case "opacity-path":
1912
+ copyContent(leaf, canvas, contentCanvas, maskOpacity, blendMode, recycle);
1913
+ break;
1914
+
1915
+ case "path":
1916
+ if (recycle) canvas.restore();
1798
1917
  }
1799
1918
  }
1919
+
1800
1920
  function getCanvas(canvas) {
1801
1921
  return canvas.getSameCanvas(false, true);
1802
1922
  }
1803
- function usePixelMask(leaf, canvas, content, mask) {
1923
+
1924
+ function usePixelMask(leaf, canvas, content, mask, blendMode, recycle) {
1804
1925
  const realBounds = leaf.__nowWorld;
1805
1926
  content.resetTransform();
1806
1927
  content.opacity = 1;
1807
1928
  content.useMask(mask, realBounds);
1808
- mask.recycle(realBounds);
1809
- copyContent(leaf, canvas, content, 1);
1929
+ if (recycle) mask.recycle(realBounds);
1930
+ copyContent(leaf, canvas, content, 1, blendMode, recycle);
1810
1931
  }
1811
- function copyContent(leaf, canvas, content, maskOpacity) {
1932
+
1933
+ function copyContent(leaf, canvas, content, maskOpacity, blendMode, recycle) {
1812
1934
  const realBounds = leaf.__nowWorld;
1813
1935
  canvas.resetTransform();
1814
1936
  canvas.opacity = maskOpacity;
1815
- canvas.copyWorld(content, realBounds);
1816
- content.recycle(realBounds);
1817
- }
1818
-
1819
- const money = '¥¥$€££¢¢';
1820
- const letter = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
1821
- const langBefore = '《(「〈『〖【〔{┌<‘“=' + money;
1822
- const langAfter = '》)」〉』〗】〕}┐>’”!?,、。:;‰';
1823
- const langSymbol = '≮≯≈≠=…';
1824
- const langBreak$1 = '—/~|┆·';
1825
- const beforeChar = '{[(<\'"' + langBefore;
1826
- const afterChar = '>)]}%!?,.:;\'"' + langAfter;
1827
- const symbolChar = afterChar + '_#~&*+\\=|' + langSymbol;
1828
- const breakChar = '- ' + langBreak$1;
1829
- const cjkRangeList = [
1830
- [0x4E00, 0x9FFF],
1831
- [0x3400, 0x4DBF],
1832
- [0x20000, 0x2A6DF],
1833
- [0x2A700, 0x2B73F],
1834
- [0x2B740, 0x2B81F],
1835
- [0x2B820, 0x2CEAF],
1836
- [0x2CEB0, 0x2EBEF],
1837
- [0x30000, 0x3134F],
1838
- [0x31350, 0x323AF],
1839
- [0x2E80, 0x2EFF],
1840
- [0x2F00, 0x2FDF],
1841
- [0x2FF0, 0x2FFF],
1842
- [0x3000, 0x303F],
1843
- [0x31C0, 0x31EF],
1844
- [0x3200, 0x32FF],
1845
- [0x3300, 0x33FF],
1846
- [0xF900, 0xFAFF],
1847
- [0xFE30, 0xFE4F],
1848
- [0x1F200, 0x1F2FF],
1849
- [0x2F800, 0x2FA1F],
1850
- ];
1851
- const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u${start.toString(16)}-\\u${end.toString(16)}]`).join('|'));
1937
+ canvas.copyWorld(content, realBounds, undefined, blendMode);
1938
+ recycle ? content.recycle(realBounds) : content.clearWorld(realBounds, true);
1939
+ }
1940
+
1941
+ const money = "¥¥$€££¢¢";
1942
+
1943
+ const letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
1944
+
1945
+ const langBefore = "《(「〈『〖【〔{┌<‘“=" + money;
1946
+
1947
+ const langAfter = "》)」〉』〗】〕}┐>’”!?,、。:;‰";
1948
+
1949
+ const langSymbol = "≮≯≈≠=…";
1950
+
1951
+ const langBreak$1 = "—/~|┆·";
1952
+
1953
+ const beforeChar = "{[(<'\"" + langBefore;
1954
+
1955
+ const afterChar = ">)]}%!?,.:;'\"" + langAfter;
1956
+
1957
+ const symbolChar = afterChar + "_#~&*+\\=|" + langSymbol;
1958
+
1959
+ const breakChar = "- " + langBreak$1;
1960
+
1961
+ const cjkRangeList = [ [ 19968, 40959 ], [ 13312, 19903 ], [ 131072, 173791 ], [ 173824, 177983 ], [ 177984, 178207 ], [ 178208, 183983 ], [ 183984, 191471 ], [ 196608, 201551 ], [ 201552, 205743 ], [ 11904, 12031 ], [ 12032, 12255 ], [ 12272, 12287 ], [ 12288, 12351 ], [ 12736, 12783 ], [ 12800, 13055 ], [ 13056, 13311 ], [ 63744, 64255 ], [ 65072, 65103 ], [ 127488, 127743 ], [ 194560, 195103 ] ];
1962
+
1963
+ const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u${start.toString(16)}-\\u${end.toString(16)}]`).join("|"));
1964
+
1852
1965
  function mapChar(str) {
1853
1966
  const map = {};
1854
- str.split('').forEach(char => map[char] = true);
1967
+ str.split("").forEach(char => map[char] = true);
1855
1968
  return map;
1856
1969
  }
1970
+
1857
1971
  const letterMap = mapChar(letter);
1972
+
1858
1973
  const beforeMap = mapChar(beforeChar);
1974
+
1859
1975
  const afterMap = mapChar(afterChar);
1976
+
1860
1977
  const symbolMap = mapChar(symbolChar);
1978
+
1861
1979
  const breakMap = mapChar(breakChar);
1980
+
1862
1981
  var CharType;
1863
- (function (CharType) {
1982
+
1983
+ (function(CharType) {
1864
1984
  CharType[CharType["Letter"] = 0] = "Letter";
1865
1985
  CharType[CharType["Single"] = 1] = "Single";
1866
1986
  CharType[CharType["Before"] = 2] = "Before";
@@ -1868,179 +1988,175 @@ var CharType;
1868
1988
  CharType[CharType["Symbol"] = 4] = "Symbol";
1869
1989
  CharType[CharType["Break"] = 5] = "Break";
1870
1990
  })(CharType || (CharType = {}));
1871
- const { Letter: Letter$1, Single: Single$1, Before: Before$1, After: After$1, Symbol: Symbol$1, Break: Break$1 } = CharType;
1991
+
1992
+ const {Letter: Letter$1, Single: Single$1, Before: Before$1, After: After$1, Symbol: Symbol$1, Break: Break$1} = CharType;
1993
+
1872
1994
  function getCharType(char) {
1873
1995
  if (letterMap[char]) {
1874
1996
  return Letter$1;
1875
- }
1876
- else if (breakMap[char]) {
1997
+ } else if (breakMap[char]) {
1877
1998
  return Break$1;
1878
- }
1879
- else if (beforeMap[char]) {
1999
+ } else if (beforeMap[char]) {
1880
2000
  return Before$1;
1881
- }
1882
- else if (afterMap[char]) {
2001
+ } else if (afterMap[char]) {
1883
2002
  return After$1;
1884
- }
1885
- else if (symbolMap[char]) {
2003
+ } else if (symbolMap[char]) {
1886
2004
  return Symbol$1;
1887
- }
1888
- else if (cjkReg.test(char)) {
2005
+ } else if (cjkReg.test(char)) {
1889
2006
  return Single$1;
1890
- }
1891
- else {
2007
+ } else {
1892
2008
  return Letter$1;
1893
2009
  }
1894
2010
  }
1895
2011
 
1896
2012
  const TextRowHelper = {
1897
2013
  trimRight(row) {
1898
- const { words } = row;
2014
+ const {words: words} = row;
1899
2015
  let trimRight = 0, len = words.length, char;
1900
2016
  for (let i = len - 1; i > -1; i--) {
1901
2017
  char = words[i].data[0];
1902
- if (char.char === ' ') {
2018
+ if (char.char === " ") {
1903
2019
  trimRight++;
1904
2020
  row.width -= char.width;
1905
- }
1906
- else {
2021
+ } else {
1907
2022
  break;
1908
2023
  }
1909
2024
  }
1910
- if (trimRight)
1911
- words.splice(len - trimRight, trimRight);
2025
+ if (trimRight) words.splice(len - trimRight, trimRight);
1912
2026
  }
1913
2027
  };
1914
2028
 
1915
2029
  function getTextCase(char, textCase, firstChar) {
1916
2030
  switch (textCase) {
1917
- case 'title':
1918
- return firstChar ? char.toUpperCase() : char;
1919
- case 'upper':
1920
- return char.toUpperCase();
1921
- case 'lower':
1922
- return char.toLowerCase();
1923
- default:
1924
- return char;
2031
+ case "title":
2032
+ return firstChar ? char.toUpperCase() : char;
2033
+
2034
+ case "upper":
2035
+ return char.toUpperCase();
2036
+
2037
+ case "lower":
2038
+ return char.toLowerCase();
2039
+
2040
+ default:
2041
+ return char;
1925
2042
  }
1926
2043
  }
1927
2044
 
1928
- const { trimRight } = TextRowHelper;
1929
- const { Letter, Single, Before, After, Symbol, Break } = CharType;
2045
+ const {trimRight: trimRight} = TextRowHelper;
2046
+
2047
+ const {Letter: Letter, Single: Single, Before: Before, After: After, Symbol: Symbol, Break: Break} = CharType;
2048
+
1930
2049
  let word, row, wordWidth, rowWidth, realWidth;
2050
+
1931
2051
  let char, charWidth, startCharSize, charSize, charType, lastCharType, langBreak, afterBreak, paraStart;
2052
+
1932
2053
  let textDrawData, rows = [], bounds, findMaxWidth;
2054
+
1933
2055
  function createRows(drawData, content, style) {
1934
2056
  textDrawData = drawData;
1935
2057
  rows = drawData.rows;
1936
2058
  bounds = drawData.bounds;
1937
2059
  findMaxWidth = !bounds.width && !style.autoSizeAlign;
1938
- const { __letterSpacing, paraIndent, textCase } = style;
1939
- const { canvas } = Platform;
1940
- const { width, height } = bounds;
1941
- const charMode = width || height || __letterSpacing || (textCase !== 'none');
2060
+ const {__letterSpacing: __letterSpacing, paraIndent: paraIndent, textCase: textCase} = style;
2061
+ const {canvas: canvas} = Platform;
2062
+ const {width: width, height: height} = bounds;
2063
+ const charMode = width || height || __letterSpacing || textCase !== "none";
1942
2064
  if (charMode) {
1943
- const wrap = style.textWrap !== 'none';
1944
- const breakAll = style.textWrap === 'break';
2065
+ const wrap = style.textWrap !== "none";
2066
+ const breakAll = style.textWrap === "break";
1945
2067
  paraStart = true;
1946
2068
  lastCharType = null;
1947
2069
  startCharSize = charWidth = charSize = wordWidth = rowWidth = 0;
1948
- word = { data: [] }, row = { words: [] };
1949
- if (__letterSpacing)
1950
- content = [...content];
2070
+ word = {
2071
+ data: []
2072
+ }, row = {
2073
+ words: []
2074
+ };
2075
+ if (__letterSpacing) content = [ ...content ];
1951
2076
  for (let i = 0, len = content.length; i < len; i++) {
1952
2077
  char = content[i];
1953
- if (char === '\n') {
1954
- if (wordWidth)
1955
- addWord();
2078
+ if (char === "\n") {
2079
+ if (wordWidth) addWord();
1956
2080
  row.paraEnd = true;
1957
2081
  addRow();
1958
2082
  paraStart = true;
1959
- }
1960
- else {
2083
+ } else {
1961
2084
  charType = getCharType(char);
1962
- if (charType === Letter && textCase !== 'none')
1963
- char = getTextCase(char, textCase, !wordWidth);
2085
+ if (charType === Letter && textCase !== "none") char = getTextCase(char, textCase, !wordWidth);
1964
2086
  charWidth = canvas.measureText(char).width;
1965
2087
  if (__letterSpacing) {
1966
- if (__letterSpacing < 0)
1967
- charSize = charWidth;
2088
+ if (__letterSpacing < 0) charSize = charWidth;
1968
2089
  charWidth += __letterSpacing;
1969
2090
  }
1970
- langBreak = (charType === Single && (lastCharType === Single || lastCharType === Letter)) || (lastCharType === Single && charType !== After);
1971
- afterBreak = ((charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After));
2091
+ langBreak = charType === Single && (lastCharType === Single || lastCharType === Letter) || lastCharType === Single && charType !== After;
2092
+ afterBreak = (charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After);
1972
2093
  realWidth = paraStart && paraIndent ? width - paraIndent : width;
1973
2094
  if (wrap && (width && rowWidth + wordWidth + charWidth > realWidth)) {
1974
2095
  if (breakAll) {
1975
- if (wordWidth)
1976
- addWord();
1977
- if (rowWidth)
1978
- addRow();
1979
- }
1980
- else {
1981
- if (!afterBreak)
1982
- afterBreak = charType === Letter && lastCharType == After;
1983
- if (langBreak || afterBreak || charType === Break || charType === Before || charType === Single || (wordWidth + charWidth > realWidth)) {
1984
- if (wordWidth)
1985
- addWord();
1986
- if (rowWidth)
1987
- addRow();
1988
- }
1989
- else {
1990
- if (rowWidth)
1991
- addRow();
2096
+ if (wordWidth) addWord();
2097
+ if (rowWidth) addRow();
2098
+ } else {
2099
+ if (!afterBreak) afterBreak = charType === Letter && lastCharType == After;
2100
+ if (langBreak || afterBreak || charType === Break || charType === Before || charType === Single || wordWidth + charWidth > realWidth) {
2101
+ if (wordWidth) addWord();
2102
+ if (rowWidth) addRow();
2103
+ } else {
2104
+ if (rowWidth) addRow();
1992
2105
  }
1993
2106
  }
1994
2107
  }
1995
- if (char === ' ' && paraStart !== true && (rowWidth + wordWidth) === 0) ;
1996
- else {
2108
+ if (char === " " && paraStart !== true && rowWidth + wordWidth === 0) ; else {
1997
2109
  if (charType === Break) {
1998
- if (char === ' ' && wordWidth)
1999
- addWord();
2110
+ if (char === " " && wordWidth) addWord();
2000
2111
  addChar(char, charWidth);
2001
2112
  addWord();
2002
- }
2003
- else if (langBreak || afterBreak) {
2004
- if (wordWidth)
2005
- addWord();
2113
+ } else if (langBreak || afterBreak) {
2114
+ if (wordWidth) addWord();
2006
2115
  addChar(char, charWidth);
2007
- }
2008
- else {
2116
+ } else {
2009
2117
  addChar(char, charWidth);
2010
2118
  }
2011
2119
  }
2012
2120
  lastCharType = charType;
2013
2121
  }
2014
2122
  }
2015
- if (wordWidth)
2016
- addWord();
2017
- if (rowWidth)
2018
- addRow();
2123
+ if (wordWidth) addWord();
2124
+ if (rowWidth) addRow();
2019
2125
  rows.length > 0 && (rows[rows.length - 1].paraEnd = true);
2020
- }
2021
- else {
2022
- content.split('\n').forEach(content => {
2126
+ } else {
2127
+ content.split("\n").forEach(content => {
2023
2128
  textDrawData.paraNumber++;
2024
2129
  rowWidth = canvas.measureText(content).width;
2025
- rows.push({ x: paraIndent || 0, text: content, width: rowWidth, paraStart: true });
2026
- if (findMaxWidth)
2027
- setMaxWidth();
2130
+ rows.push({
2131
+ x: paraIndent || 0,
2132
+ text: content,
2133
+ width: rowWidth,
2134
+ paraStart: true
2135
+ });
2136
+ if (findMaxWidth) setMaxWidth();
2028
2137
  });
2029
2138
  }
2030
2139
  }
2140
+
2031
2141
  function addChar(char, width) {
2032
- if (charSize && !startCharSize)
2033
- startCharSize = charSize;
2034
- word.data.push({ char, width });
2142
+ if (charSize && !startCharSize) startCharSize = charSize;
2143
+ word.data.push({
2144
+ char: char,
2145
+ width: width
2146
+ });
2035
2147
  wordWidth += width;
2036
2148
  }
2149
+
2037
2150
  function addWord() {
2038
2151
  rowWidth += wordWidth;
2039
2152
  word.width = wordWidth;
2040
2153
  row.words.push(word);
2041
- word = { data: [] };
2154
+ word = {
2155
+ data: []
2156
+ };
2042
2157
  wordWidth = 0;
2043
2158
  }
2159
+
2044
2160
  function addRow() {
2045
2161
  if (paraStart) {
2046
2162
  textDrawData.paraNumber++;
@@ -2053,52 +2169,53 @@ function addRow() {
2053
2169
  startCharSize = 0;
2054
2170
  }
2055
2171
  row.width = rowWidth;
2056
- if (bounds.width)
2057
- trimRight(row);
2058
- else if (findMaxWidth)
2059
- setMaxWidth();
2172
+ if (bounds.width) trimRight(row); else if (findMaxWidth) setMaxWidth();
2060
2173
  rows.push(row);
2061
- row = { words: [] };
2174
+ row = {
2175
+ words: []
2176
+ };
2062
2177
  rowWidth = 0;
2063
2178
  }
2179
+
2064
2180
  function setMaxWidth() {
2065
- if (rowWidth > (textDrawData.maxWidth || 0))
2066
- textDrawData.maxWidth = rowWidth;
2181
+ if (rowWidth > (textDrawData.maxWidth || 0)) textDrawData.maxWidth = rowWidth;
2067
2182
  }
2068
2183
 
2069
2184
  const CharMode = 0;
2185
+
2070
2186
  const WordMode = 1;
2187
+
2071
2188
  const TextMode = 2;
2189
+
2072
2190
  function layoutChar(drawData, style, width, _height) {
2073
- const { rows } = drawData;
2074
- const { textAlign, paraIndent, letterSpacing } = style;
2191
+ const {rows: rows} = drawData;
2192
+ const {textAlign: textAlign, paraIndent: paraIndent, letterSpacing: letterSpacing} = style;
2075
2193
  let charX, addWordWidth, indentWidth, mode, wordChar, wordsLength;
2076
2194
  rows.forEach(row => {
2077
2195
  if (row.words) {
2078
2196
  indentWidth = paraIndent && row.paraStart ? paraIndent : 0, wordsLength = row.words.length;
2079
- addWordWidth = (width && (textAlign === 'justify' || textAlign === 'both') && wordsLength > 1) ? (width - row.width - indentWidth) / (wordsLength - 1) : 0;
2080
- mode = (letterSpacing || row.isOverflow) ? CharMode : (addWordWidth > 0.01 ? WordMode : TextMode);
2081
- if (row.isOverflow && !letterSpacing)
2082
- row.textMode = true;
2197
+ addWordWidth = width && (textAlign === "justify" || textAlign === "both") && wordsLength > 1 ? (width - row.width - indentWidth) / (wordsLength - 1) : 0;
2198
+ mode = letterSpacing || row.isOverflow ? CharMode : addWordWidth > .01 ? WordMode : TextMode;
2199
+ if (row.isOverflow && !letterSpacing) row.textMode = true;
2083
2200
  if (mode === TextMode) {
2084
2201
  row.x += indentWidth;
2085
2202
  toTextChar$1(row);
2086
- }
2087
- else {
2203
+ } else {
2088
2204
  row.x += indentWidth;
2089
2205
  charX = row.x;
2090
2206
  row.data = [];
2091
2207
  row.words.forEach((word, index) => {
2092
2208
  if (mode === WordMode) {
2093
- wordChar = { char: '', x: charX };
2209
+ wordChar = {
2210
+ char: "",
2211
+ x: charX
2212
+ };
2094
2213
  charX = toWordChar(word.data, charX, wordChar);
2095
- if (row.isOverflow || wordChar.char !== ' ')
2096
- row.data.push(wordChar);
2097
- }
2098
- else {
2214
+ if (row.isOverflow || wordChar.char !== " ") row.data.push(wordChar);
2215
+ } else {
2099
2216
  charX = toChar(word.data, charX, row.data, row.isOverflow);
2100
2217
  }
2101
- if (addWordWidth && (!row.paraEnd || textAlign === 'both') && (index !== wordsLength - 1)) {
2218
+ if (addWordWidth && (!row.paraEnd || textAlign === "both") && index !== wordsLength - 1) {
2102
2219
  charX += addWordWidth;
2103
2220
  row.width += addWordWidth;
2104
2221
  }
@@ -2108,14 +2225,16 @@ function layoutChar(drawData, style, width, _height) {
2108
2225
  }
2109
2226
  });
2110
2227
  }
2228
+
2111
2229
  function toTextChar$1(row) {
2112
- row.text = '';
2230
+ row.text = "";
2113
2231
  row.words.forEach(word => {
2114
2232
  word.data.forEach(char => {
2115
2233
  row.text += char.char;
2116
2234
  });
2117
2235
  });
2118
2236
  }
2237
+
2119
2238
  function toWordChar(data, charX, wordChar) {
2120
2239
  data.forEach(char => {
2121
2240
  wordChar.char += char.char;
@@ -2123,9 +2242,10 @@ function toWordChar(data, charX, wordChar) {
2123
2242
  });
2124
2243
  return charX;
2125
2244
  }
2245
+
2126
2246
  function toChar(data, charX, rowData, isOverflow) {
2127
2247
  data.forEach(char => {
2128
- if (isOverflow || char.char !== ' ') {
2248
+ if (isOverflow || char.char !== " ") {
2129
2249
  char.x = charX;
2130
2250
  rowData.push(char);
2131
2251
  }
@@ -2135,38 +2255,39 @@ function toChar(data, charX, rowData, isOverflow) {
2135
2255
  }
2136
2256
 
2137
2257
  function layoutText(drawData, style) {
2138
- const { rows, bounds } = drawData, countRows = rows.length;
2139
- const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
2140
- let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
2258
+ const {rows: rows, bounds: bounds} = drawData, countRows = rows.length;
2259
+ const {__lineHeight: __lineHeight, __baseLine: __baseLine, __letterSpacing: __letterSpacing, __clipText: __clipText, textAlign: textAlign, verticalAlign: verticalAlign, paraSpacing: paraSpacing, autoSizeAlign: autoSizeAlign} = style;
2260
+ let {x: x, y: y, width: width, height: height} = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
2141
2261
  let starY = __baseLine;
2142
2262
  if (__clipText && realHeight > height) {
2143
2263
  realHeight = Math.max(height, __lineHeight);
2144
- if (countRows > 1)
2145
- drawData.overflow = countRows;
2146
- }
2147
- else if (height || autoSizeAlign) {
2264
+ if (countRows > 1) drawData.overflow = countRows;
2265
+ } else if (height || autoSizeAlign) {
2148
2266
  switch (verticalAlign) {
2149
- case 'middle':
2150
- y += (height - realHeight) / 2;
2151
- break;
2152
- case 'bottom': y += (height - realHeight);
2267
+ case "middle":
2268
+ y += (height - realHeight) / 2;
2269
+ break;
2270
+
2271
+ case "bottom":
2272
+ y += height - realHeight;
2153
2273
  }
2154
2274
  }
2155
2275
  starY += y;
2156
- let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
2276
+ let row, rowX, rowWidth, layoutWidth = width || autoSizeAlign ? width : drawData.maxWidth;
2157
2277
  for (let i = 0, len = countRows; i < len; i++) {
2158
2278
  row = rows[i];
2159
2279
  row.x = x;
2160
- if (row.width < width || (row.width > width && !__clipText)) {
2280
+ if (row.width < width || row.width > width && !__clipText) {
2161
2281
  switch (textAlign) {
2162
- case 'center':
2163
- row.x += (layoutWidth - row.width) / 2;
2164
- break;
2165
- case 'right': row.x += layoutWidth - row.width;
2282
+ case "center":
2283
+ row.x += (layoutWidth - row.width) / 2;
2284
+ break;
2285
+
2286
+ case "right":
2287
+ row.x += layoutWidth - row.width;
2166
2288
  }
2167
2289
  }
2168
- if (row.paraStart && paraSpacing && i > 0)
2169
- starY += paraSpacing;
2290
+ if (row.paraStart && paraSpacing && i > 0) starY += paraSpacing;
2170
2291
  row.y = starY;
2171
2292
  starY += __lineHeight;
2172
2293
  if (drawData.overflow > i && starY > realHeight) {
@@ -2180,19 +2301,15 @@ function layoutText(drawData, style) {
2180
2301
  rowWidth = -row.width + style.fontSize + __letterSpacing;
2181
2302
  rowX -= rowWidth;
2182
2303
  rowWidth += style.fontSize;
2183
- }
2184
- else {
2304
+ } else {
2185
2305
  rowWidth -= __letterSpacing;
2186
2306
  }
2187
2307
  }
2188
- if (rowX < bounds.x)
2189
- bounds.x = rowX;
2190
- if (rowWidth > bounds.width)
2191
- bounds.width = rowWidth;
2308
+ if (rowX < bounds.x) bounds.x = rowX;
2309
+ if (rowWidth > bounds.width) bounds.width = rowWidth;
2192
2310
  if (__clipText && width && width < rowWidth) {
2193
2311
  row.isOverflow = true;
2194
- if (!drawData.overflow)
2195
- drawData.overflow = rows.length;
2312
+ if (!drawData.overflow) drawData.overflow = rows.length;
2196
2313
  }
2197
2314
  }
2198
2315
  bounds.y = y;
@@ -2200,20 +2317,16 @@ function layoutText(drawData, style) {
2200
2317
  }
2201
2318
 
2202
2319
  function clipText(drawData, style, x, width) {
2203
- if (!width)
2204
- return;
2205
- const { rows, overflow } = drawData;
2206
- let { textOverflow } = style;
2320
+ if (!width) return;
2321
+ const {rows: rows, overflow: overflow} = drawData;
2322
+ let {textOverflow: textOverflow} = style;
2207
2323
  rows.splice(overflow);
2208
- if (textOverflow && textOverflow !== 'show') {
2209
- if (textOverflow === 'hide')
2210
- textOverflow = '';
2211
- else if (textOverflow === 'ellipsis')
2212
- textOverflow = '...';
2324
+ if (textOverflow && textOverflow !== "show") {
2325
+ if (textOverflow === "hide") textOverflow = ""; else if (textOverflow === "ellipsis") textOverflow = "...";
2213
2326
  let char, charRight;
2214
2327
  const ellipsisWidth = textOverflow ? Platform.canvas.measureText(textOverflow).width : 0;
2215
2328
  const right = x + width - ellipsisWidth;
2216
- const list = style.textWrap === 'none' ? rows : [rows[overflow - 1]];
2329
+ const list = style.textWrap === "none" ? rows : [ rows[overflow - 1] ];
2217
2330
  list.forEach(row => {
2218
2331
  if (row.isOverflow && row.data) {
2219
2332
  let end = row.data.length - 1;
@@ -2222,8 +2335,7 @@ function clipText(drawData, style, x, width) {
2222
2335
  charRight = char.x + char.width;
2223
2336
  if (i === end && charRight < right) {
2224
2337
  break;
2225
- }
2226
- else if ((charRight < right && char.char !== ' ') || !i) {
2338
+ } else if (charRight < right && char.char !== " " || !i) {
2227
2339
  row.data.splice(i + 1);
2228
2340
  row.width -= char.width;
2229
2341
  break;
@@ -2231,15 +2343,18 @@ function clipText(drawData, style, x, width) {
2231
2343
  row.width -= char.width;
2232
2344
  }
2233
2345
  row.width += ellipsisWidth;
2234
- row.data.push({ char: textOverflow, x: charRight });
2235
- if (row.textMode)
2236
- toTextChar(row);
2346
+ row.data.push({
2347
+ char: textOverflow,
2348
+ x: charRight
2349
+ });
2350
+ if (row.textMode) toTextChar(row);
2237
2351
  }
2238
2352
  });
2239
2353
  }
2240
2354
  }
2355
+
2241
2356
  function toTextChar(row) {
2242
- row.text = '';
2357
+ row.text = "";
2243
2358
  row.data.forEach(char => {
2244
2359
  row.text += char.char;
2245
2360
  });
@@ -2248,121 +2363,123 @@ function toTextChar(row) {
2248
2363
 
2249
2364
  function decorationText(drawData, style) {
2250
2365
  let type;
2251
- const { fontSize, textDecoration } = style;
2366
+ const {fontSize: fontSize, textDecoration: textDecoration} = style;
2252
2367
  drawData.decorationHeight = fontSize / 11;
2253
- if (typeof textDecoration === 'object') {
2368
+ if (isObject(textDecoration)) {
2254
2369
  type = textDecoration.type;
2255
- if (textDecoration.color)
2256
- drawData.decorationColor = ColorConvert.string(textDecoration.color);
2257
- }
2258
- else
2259
- type = textDecoration;
2370
+ if (textDecoration.color) drawData.decorationColor = ColorConvert.string(textDecoration.color);
2371
+ } else type = textDecoration;
2260
2372
  switch (type) {
2261
- case 'under':
2262
- drawData.decorationY = [fontSize * 0.15];
2263
- break;
2264
- case 'delete':
2265
- drawData.decorationY = [-fontSize * 0.35];
2266
- break;
2267
- case 'under-delete':
2268
- drawData.decorationY = [fontSize * 0.15, -fontSize * 0.35];
2373
+ case "under":
2374
+ drawData.decorationY = [ fontSize * .15 ];
2375
+ break;
2376
+
2377
+ case "delete":
2378
+ drawData.decorationY = [ -fontSize * .35 ];
2379
+ break;
2380
+
2381
+ case "under-delete":
2382
+ drawData.decorationY = [ fontSize * .15, -fontSize * .35 ];
2269
2383
  }
2270
2384
  }
2271
2385
 
2272
- const { top, right, bottom, left } = Direction4;
2386
+ const {top: top, right: right, bottom: bottom, left: left} = Direction4;
2387
+
2273
2388
  function getDrawData(content, style) {
2274
- if (typeof content !== 'string')
2275
- content = String(content);
2389
+ if (!isString(content)) content = String(content);
2276
2390
  let x = 0, y = 0;
2277
- let width = style.__getInput('width') || 0;
2278
- let height = style.__getInput('height') || 0;
2279
- const { textDecoration, __font, __padding: padding } = style;
2391
+ let width = style.__getInput("width") || 0;
2392
+ let height = style.__getInput("height") || 0;
2393
+ const {textDecoration: textDecoration, __font: __font, __padding: padding} = style;
2280
2394
  if (padding) {
2281
- if (width)
2282
- x = padding[left], width -= (padding[right] + padding[left]);
2283
- else if (!style.autoSizeAlign)
2284
- x = padding[left];
2285
- if (height)
2286
- y = padding[top], height -= (padding[top] + padding[bottom]);
2287
- else if (!style.autoSizeAlign)
2288
- y = padding[top];
2395
+ if (width) x = padding[left], width -= padding[right] + padding[left]; else if (!style.autoSizeAlign) x = padding[left];
2396
+ if (height) y = padding[top], height -= padding[top] + padding[bottom]; else if (!style.autoSizeAlign) y = padding[top];
2289
2397
  }
2290
2398
  const drawData = {
2291
- bounds: { x, y, width, height },
2399
+ bounds: {
2400
+ x: x,
2401
+ y: y,
2402
+ width: width,
2403
+ height: height
2404
+ },
2292
2405
  rows: [],
2293
2406
  paraNumber: 0,
2294
2407
  font: Platform.canvas.font = __font
2295
2408
  };
2296
2409
  createRows(drawData, content, style);
2297
- if (padding)
2298
- padAutoText(padding, drawData, style, width, height);
2410
+ if (padding) padAutoText(padding, drawData, style, width, height);
2299
2411
  layoutText(drawData, style);
2300
2412
  layoutChar(drawData, style, width);
2301
- if (drawData.overflow)
2302
- clipText(drawData, style, x, width);
2303
- if (textDecoration !== 'none')
2304
- decorationText(drawData, style);
2413
+ if (drawData.overflow) clipText(drawData, style, x, width);
2414
+ if (textDecoration !== "none") decorationText(drawData, style);
2305
2415
  return drawData;
2306
2416
  }
2417
+
2307
2418
  function padAutoText(padding, drawData, style, width, height) {
2308
2419
  if (!width && style.autoSizeAlign) {
2309
2420
  switch (style.textAlign) {
2310
- case 'left':
2311
- offsetText(drawData, 'x', padding[left]);
2312
- break;
2313
- case 'right': offsetText(drawData, 'x', -padding[right]);
2421
+ case "left":
2422
+ offsetText(drawData, "x", padding[left]);
2423
+ break;
2424
+
2425
+ case "right":
2426
+ offsetText(drawData, "x", -padding[right]);
2314
2427
  }
2315
2428
  }
2316
2429
  if (!height && style.autoSizeAlign) {
2317
2430
  switch (style.verticalAlign) {
2318
- case 'top':
2319
- offsetText(drawData, 'y', padding[top]);
2320
- break;
2321
- case 'bottom': offsetText(drawData, 'y', -padding[bottom]);
2431
+ case "top":
2432
+ offsetText(drawData, "y", padding[top]);
2433
+ break;
2434
+
2435
+ case "bottom":
2436
+ offsetText(drawData, "y", -padding[bottom]);
2322
2437
  }
2323
2438
  }
2324
2439
  }
2440
+
2325
2441
  function offsetText(drawData, attrName, value) {
2326
- const { bounds, rows } = drawData;
2442
+ const {bounds: bounds, rows: rows} = drawData;
2327
2443
  bounds[attrName] += value;
2328
- for (let i = 0; i < rows.length; i++)
2329
- rows[i][attrName] += value;
2444
+ for (let i = 0; i < rows.length; i++) rows[i][attrName] += value;
2330
2445
  }
2331
2446
 
2332
2447
  const TextConvertModule = {
2333
- getDrawData
2448
+ getDrawData: getDrawData
2334
2449
  };
2335
2450
 
2336
2451
  function string(color, opacity) {
2337
- const doOpacity = typeof opacity === 'number' && opacity !== 1;
2338
- if (typeof color === 'string') {
2339
- if (doOpacity && ColorConvert.object)
2340
- color = ColorConvert.object(color);
2341
- else
2342
- return color;
2452
+ const doOpacity = isNumber(opacity) && opacity < 1;
2453
+ if (isString(color)) {
2454
+ if (doOpacity && ColorConvert.object) color = ColorConvert.object(color); else return color;
2343
2455
  }
2344
- let a = color.a === undefined ? 1 : color.a;
2345
- if (doOpacity)
2346
- a *= opacity;
2347
- const rgb = color.r + ',' + color.g + ',' + color.b;
2348
- return a === 1 ? 'rgb(' + rgb + ')' : 'rgba(' + rgb + ',' + a + ')';
2456
+ let a = isUndefined(color.a) ? 1 : color.a;
2457
+ if (doOpacity) a *= opacity;
2458
+ const rgb = color.r + "," + color.g + "," + color.b;
2459
+ return a === 1 ? "rgb(" + rgb + ")" : "rgba(" + rgb + "," + a + ")";
2349
2460
  }
2350
2461
 
2351
2462
  const ColorConvertModule = {
2352
- string
2463
+ string: string
2353
2464
  };
2354
2465
 
2355
2466
  Object.assign(TextConvert, TextConvertModule);
2467
+
2356
2468
  Object.assign(ColorConvert, ColorConvertModule);
2469
+
2357
2470
  Object.assign(Paint, PaintModule);
2471
+
2358
2472
  Object.assign(PaintImage, PaintImageModule);
2473
+
2359
2474
  Object.assign(PaintGradient, PaintGradientModule);
2475
+
2360
2476
  Object.assign(Effect, EffectModule);
2361
2477
 
2362
- const { setPoint, addPoint, toBounds } = TwoPointBoundsHelper;
2478
+ const {setPoint: setPoint, addPoint: addPoint, toBounds: toBounds} = TwoPointBoundsHelper;
2479
+
2363
2480
  function getTrimBounds(canvas) {
2364
- const { width, height } = canvas.view;
2365
- const { data } = canvas.context.getImageData(0, 0, width, height);
2481
+ const {width: width, height: height} = canvas.view;
2482
+ const {data: data} = canvas.context.getImageData(0, 0, width, height);
2366
2483
  let x, y, pointBounds, index = 0;
2367
2484
  for (let i = 0; i < data.length; i += 4) {
2368
2485
  if (data[i + 3] !== 0) {
@@ -2372,202 +2489,249 @@ function getTrimBounds(canvas) {
2372
2489
  }
2373
2490
  index++;
2374
2491
  }
2375
- const bounds = new Bounds$1();
2376
- toBounds(pointBounds, bounds);
2377
- return bounds.scale(1 / canvas.pixelRatio).ceil();
2492
+ const bounds = new Bounds$1;
2493
+ if (pointBounds) {
2494
+ toBounds(pointBounds, bounds);
2495
+ bounds.scale(1 / canvas.pixelRatio).ceil();
2496
+ }
2497
+ return bounds;
2378
2498
  }
2379
2499
 
2380
2500
  const ExportModule = {
2381
2501
  syncExport(leaf, filename, options) {
2382
- this.running = true;
2502
+ Export.running = true;
2383
2503
  let result;
2384
- const fileType = FileHelper$1.fileType(filename);
2385
- const isDownload = filename.includes('.');
2386
- options = FileHelper$1.getExportOptions(options);
2387
- const { toURL } = Platform$1;
2388
- const { download } = Platform$1.origin;
2389
- if (fileType === 'json') {
2390
- isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
2391
- result = { data: isDownload ? true : leaf.toJSON(options.json) };
2392
- }
2393
- else if (fileType === 'svg') {
2394
- isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
2395
- result = { data: isDownload ? true : leaf.toSVG() };
2396
- }
2397
- else {
2398
- let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
2399
- const { worldTransform, isLeafer, leafer, isFrame } = leaf;
2400
- const { slice, clip, trim, screenshot, padding, onCanvas } = options;
2401
- const smooth = options.smooth === undefined ? (leafer ? leafer.config.smooth : true) : options.smooth;
2402
- const contextSettings = options.contextSettings || (leafer ? leafer.config.contextSettings : undefined);
2403
- const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
2404
- const needFill = FileHelper$1.isOpaqueImage(filename) || fill, matrix = new Matrix();
2405
- if (screenshot) {
2406
- renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
2407
- }
2408
- else {
2409
- let relative = options.relative || (isLeafer ? 'inner' : 'local');
2410
- scaleX = worldTransform.scaleX;
2411
- scaleY = worldTransform.scaleY;
2412
- switch (relative) {
2413
- case 'inner':
2504
+ try {
2505
+ const fileType = FileHelper$1.fileType(filename);
2506
+ const isDownload = filename.includes(".");
2507
+ options = FileHelper$1.getExportOptions(options);
2508
+ const {toURL: toURL} = Platform$1;
2509
+ const {download: download} = Platform$1.origin;
2510
+ if (fileType === "json") {
2511
+ isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), "text"), filename);
2512
+ result = {
2513
+ data: isDownload ? true : leaf.toJSON(options.json)
2514
+ };
2515
+ } else if (fileType === "svg") {
2516
+ isDownload && download(toURL(leaf.toSVG(), "svg"), filename);
2517
+ result = {
2518
+ data: isDownload ? true : leaf.toSVG()
2519
+ };
2520
+ } else {
2521
+ let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
2522
+ const {worldTransform: worldTransform, isLeafer: isLeafer, leafer: leafer, isFrame: isFrame} = leaf;
2523
+ const {slice: slice, clip: clip, trim: trim, screenshot: screenshot, padding: padding, onCanvas: onCanvas} = options;
2524
+ const smooth = isUndefined$1(options.smooth) ? leafer ? leafer.config.smooth : true : options.smooth;
2525
+ const contextSettings = options.contextSettings || (leafer ? leafer.config.contextSettings : undefined);
2526
+ const fill = isLeafer && screenshot ? isUndefined$1(options.fill) ? leaf.fill : options.fill : options.fill;
2527
+ const needFill = FileHelper$1.isOpaqueImage(filename) || fill, matrix = new Matrix$1;
2528
+ if (screenshot) {
2529
+ renderBounds = screenshot === true ? isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds : screenshot;
2530
+ } else {
2531
+ let relative = options.relative || (isLeafer ? "inner" : "local");
2532
+ scaleX = worldTransform.scaleX;
2533
+ scaleY = worldTransform.scaleY;
2534
+ switch (relative) {
2535
+ case "inner":
2414
2536
  matrix.set(worldTransform);
2415
2537
  break;
2416
- case 'local':
2538
+
2539
+ case "local":
2417
2540
  matrix.set(worldTransform).divide(leaf.localTransform);
2418
2541
  scaleX /= leaf.scaleX;
2419
2542
  scaleY /= leaf.scaleY;
2420
2543
  break;
2421
- case 'world':
2544
+
2545
+ case "world":
2422
2546
  scaleX = 1;
2423
2547
  scaleY = 1;
2424
2548
  break;
2425
- case 'page':
2549
+
2550
+ case "page":
2426
2551
  relative = leafer || leaf;
2427
- default:
2552
+
2553
+ default:
2428
2554
  matrix.set(worldTransform).divide(leaf.getTransform(relative));
2429
2555
  const l = relative.worldTransform;
2430
2556
  scaleX /= scaleX / l.scaleX;
2431
2557
  scaleY /= scaleY / l.scaleY;
2558
+ }
2559
+ renderBounds = leaf.getBounds("render", relative);
2432
2560
  }
2433
- renderBounds = leaf.getBounds('render', relative);
2434
- }
2435
- const scaleData = { scaleX: 1, scaleY: 1 };
2436
- MathHelper$1.getScaleData(options.scale, options.size, renderBounds, scaleData);
2437
- let pixelRatio = options.pixelRatio || 1;
2438
- let { x, y, width, height } = new Bounds$1(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
2439
- if (clip)
2440
- x += clip.x, y += clip.y, width = clip.width, height = clip.height;
2441
- const renderOptions = { exporting: true, matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY) };
2442
- let canvas = Creator$1.canvas({ width: Math.floor(width), height: Math.floor(height), pixelRatio, smooth, contextSettings });
2443
- let sliceLeaf;
2444
- if (slice) {
2445
- sliceLeaf = leaf;
2446
- sliceLeaf.__worldOpacity = 0;
2447
- leaf = leafer || leaf;
2448
- renderOptions.bounds = canvas.bounds;
2449
- }
2450
- canvas.save();
2451
- if (isFrame && fill !== undefined) {
2452
- const oldFill = leaf.get('fill');
2453
- leaf.fill = '';
2454
- leaf.__render(canvas, renderOptions);
2455
- leaf.fill = oldFill;
2456
- }
2457
- else {
2458
- leaf.__render(canvas, renderOptions);
2459
- }
2460
- canvas.restore();
2461
- if (sliceLeaf)
2462
- sliceLeaf.__updateWorldOpacity();
2463
- if (trim) {
2464
- trimBounds = getTrimBounds(canvas);
2465
- const old = canvas, { width, height } = trimBounds;
2466
- const config = { x: 0, y: 0, width, height, pixelRatio };
2467
- canvas = Creator$1.canvas(config);
2468
- canvas.copyWorld(old, trimBounds, config);
2469
- }
2470
- if (padding) {
2471
- const [top, right, bottom, left] = MathHelper$1.fourNumber(padding);
2472
- const old = canvas, { width, height } = old;
2473
- canvas = Creator$1.canvas({ width: width + left + right, height: height + top + bottom, pixelRatio });
2474
- canvas.copyWorld(old, old.bounds, { x: left, y: top, width, height });
2561
+ const scaleData = {
2562
+ scaleX: 1,
2563
+ scaleY: 1
2564
+ };
2565
+ MathHelper$1.getScaleData(options.scale, options.size, renderBounds, scaleData);
2566
+ let pixelRatio = options.pixelRatio || 1;
2567
+ let {x: x, y: y, width: width, height: height} = new Bounds$1(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
2568
+ if (clip) x += clip.x, y += clip.y, width = clip.width, height = clip.height;
2569
+ const renderOptions = {
2570
+ exporting: true,
2571
+ matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY)
2572
+ };
2573
+ let canvas = Creator$1.canvas({
2574
+ width: Math.floor(width),
2575
+ height: Math.floor(height),
2576
+ pixelRatio: pixelRatio,
2577
+ smooth: smooth,
2578
+ contextSettings: contextSettings
2579
+ });
2580
+ let sliceLeaf;
2581
+ if (slice) {
2582
+ sliceLeaf = leaf;
2583
+ sliceLeaf.__worldOpacity = 0;
2584
+ leaf = leafer || leaf;
2585
+ renderOptions.bounds = canvas.bounds;
2586
+ }
2587
+ canvas.save();
2588
+ if (isFrame && !isUndefined$1(fill)) {
2589
+ const oldFill = leaf.get("fill");
2590
+ leaf.fill = "";
2591
+ leaf.__render(canvas, renderOptions);
2592
+ leaf.fill = oldFill;
2593
+ } else {
2594
+ leaf.__render(canvas, renderOptions);
2595
+ }
2596
+ canvas.restore();
2597
+ if (sliceLeaf) sliceLeaf.__updateWorldOpacity();
2598
+ if (trim) {
2599
+ trimBounds = getTrimBounds(canvas);
2600
+ const old = canvas, {width: width, height: height} = trimBounds;
2601
+ const config = {
2602
+ x: 0,
2603
+ y: 0,
2604
+ width: width,
2605
+ height: height,
2606
+ pixelRatio: pixelRatio
2607
+ };
2608
+ canvas = Creator$1.canvas(config);
2609
+ canvas.copyWorld(old, trimBounds, config);
2610
+ old.destroy();
2611
+ }
2612
+ if (padding) {
2613
+ const [top, right, bottom, left] = MathHelper$1.fourNumber(padding);
2614
+ const old = canvas, {width: width, height: height} = old;
2615
+ canvas = Creator$1.canvas({
2616
+ width: width + left + right,
2617
+ height: height + top + bottom,
2618
+ pixelRatio: pixelRatio
2619
+ });
2620
+ canvas.copyWorld(old, old.bounds, {
2621
+ x: left,
2622
+ y: top,
2623
+ width: width,
2624
+ height: height
2625
+ });
2626
+ old.destroy();
2627
+ }
2628
+ if (needFill) canvas.fillWorld(canvas.bounds, fill || "#FFFFFF", "destination-over");
2629
+ if (onCanvas) onCanvas(canvas);
2630
+ const data = filename === "canvas" ? canvas : canvas.export(filename, options);
2631
+ result = {
2632
+ data: data,
2633
+ width: canvas.pixelWidth,
2634
+ height: canvas.pixelHeight,
2635
+ renderBounds: renderBounds,
2636
+ trimBounds: trimBounds
2637
+ };
2475
2638
  }
2476
- if (needFill)
2477
- canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
2478
- if (onCanvas)
2479
- onCanvas(canvas);
2480
- const data = filename === 'canvas' ? canvas : canvas.export(filename, options);
2481
- result = { data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds };
2639
+ } catch (error) {
2640
+ result = {
2641
+ data: "",
2642
+ error: error
2643
+ };
2482
2644
  }
2483
- this.running = false;
2645
+ Export.running = false;
2484
2646
  return result;
2485
2647
  },
2486
2648
  export(leaf, filename, options) {
2487
- this.running = true;
2488
- return addTask((success) => new Promise((resolve) => {
2489
- const getResult = () => __awaiter(this, void 0, void 0, function* () {
2490
- if (!Resource.isComplete)
2491
- return Platform$1.requestRender(getResult);
2492
- const result = ExportModule.syncExport(leaf, filename, options);
2493
- if (result.data instanceof Promise)
2494
- result.data = yield result.data;
2649
+ Export.running = true;
2650
+ return addTask(success => new Promise(resolve => {
2651
+ const getResult = () => __awaiter(this, void 0, void 0, function*() {
2652
+ if (!Resource.isComplete) return Platform$1.requestRender(getResult);
2653
+ const result = Export.syncExport(leaf, filename, options);
2654
+ if (result.data instanceof Promise) result.data = yield result.data;
2495
2655
  success(result);
2496
2656
  resolve();
2497
2657
  });
2498
2658
  leaf.updateLayout();
2499
2659
  checkLazy(leaf);
2500
- const { leafer } = leaf;
2501
- if (leafer)
2502
- leafer.waitViewCompleted(getResult);
2503
- else
2504
- getResult();
2660
+ const {leafer: leafer} = leaf;
2661
+ if (leafer) leafer.waitViewCompleted(getResult); else getResult();
2505
2662
  }));
2506
2663
  }
2507
2664
  };
2665
+
2508
2666
  let tasker;
2667
+
2509
2668
  function addTask(task) {
2510
- if (!tasker)
2511
- tasker = new TaskProcessor();
2512
- return new Promise((resolve) => {
2513
- tasker.add(() => __awaiter(this, void 0, void 0, function* () { return yield task(resolve); }), { parallel: false });
2669
+ if (!tasker) tasker = new TaskProcessor;
2670
+ return new Promise(resolve => {
2671
+ tasker.add(() => __awaiter(this, void 0, void 0, function*() {
2672
+ return yield task(resolve);
2673
+ }), {
2674
+ parallel: false
2675
+ });
2514
2676
  });
2515
2677
  }
2678
+
2516
2679
  function checkLazy(leaf) {
2517
- if (leaf.__.__needComputePaint)
2518
- leaf.__.__computePaint();
2519
- if (leaf.isBranch)
2520
- leaf.children.forEach(child => checkLazy(child));
2680
+ if (leaf.__.__needComputePaint) leaf.__.__computePaint();
2681
+ if (leaf.isBranch) leaf.children.forEach(child => checkLazy(child));
2521
2682
  }
2522
2683
 
2523
2684
  const canvas = LeaferCanvasBase$1.prototype;
2524
- const debug = Debug$1.get('@leafer-in/export');
2525
- canvas.export = function (filename, options) {
2526
- const { quality, blob } = FileHelper$1.getExportOptions(options);
2527
- if (filename.includes('.'))
2528
- return this.saveAs(filename, quality);
2529
- else if (blob)
2530
- return this.toBlob(filename, quality);
2531
- else
2532
- return this.toDataURL(filename, quality);
2685
+
2686
+ const debug = Debug$1.get("@leafer-in/export");
2687
+
2688
+ canvas.export = function(filename, options) {
2689
+ const {quality: quality, blob: blob} = FileHelper$1.getExportOptions(options);
2690
+ if (filename.includes(".")) return this.saveAs(filename, quality); else if (blob) return this.toBlob(filename, quality); else return this.toDataURL(filename, quality);
2533
2691
  };
2534
- canvas.toBlob = function (type, quality) {
2535
- return new Promise((resolve) => {
2536
- Platform$1.origin.canvasToBolb(this.view, type, quality).then((blob) => {
2692
+
2693
+ canvas.toBlob = function(type, quality) {
2694
+ return new Promise(resolve => {
2695
+ Platform$1.origin.canvasToBolb(this.view, type, quality).then(blob => {
2537
2696
  resolve(blob);
2538
- }).catch((e) => {
2697
+ }).catch(e => {
2539
2698
  debug.error(e);
2540
2699
  resolve(null);
2541
2700
  });
2542
2701
  });
2543
2702
  };
2544
- canvas.toDataURL = function (type, quality) {
2703
+
2704
+ canvas.toDataURL = function(type, quality) {
2545
2705
  return Platform$1.origin.canvasToDataURL(this.view, type, quality);
2546
2706
  };
2547
- canvas.saveAs = function (filename, quality) {
2548
- return new Promise((resolve) => {
2707
+
2708
+ canvas.saveAs = function(filename, quality) {
2709
+ return new Promise(resolve => {
2549
2710
  Platform$1.origin.canvasSaveAs(this.view, filename, quality).then(() => {
2550
2711
  resolve(true);
2551
- }).catch((e) => {
2712
+ }).catch(e => {
2552
2713
  debug.error(e);
2553
2714
  resolve(false);
2554
2715
  });
2555
2716
  });
2556
2717
  };
2557
2718
 
2558
- Plugin$1.add('export');
2719
+ Plugin$1.add("export");
2720
+
2559
2721
  Object.assign(Export, ExportModule);
2560
- UI.prototype.export = function (filename, options) {
2722
+
2723
+ UI.prototype.export = function(filename, options) {
2561
2724
  return Export.export(this, filename, options);
2562
2725
  };
2563
- UI.prototype.syncExport = function (filename, options) {
2726
+
2727
+ UI.prototype.syncExport = function(filename, options) {
2564
2728
  return Export.syncExport(this, filename, options);
2565
2729
  };
2566
2730
 
2567
2731
  Object.assign(Creator, {
2568
- interaction: (target, canvas, selector, options) => { return new InteractionBase(target, canvas, selector, options); },
2732
+ interaction: (target, canvas, selector, options) => new InteractionBase(target, canvas, selector, options),
2569
2733
  hitCanvas: (options, manager) => new LeaferCanvas(options, manager),
2570
- hitCanvasManager: () => new HitCanvasManager()
2734
+ hitCanvasManager: () => new HitCanvasManager
2571
2735
  });
2572
2736
 
2573
2737
  export { Layouter, LeaferCanvas, Picker, Renderer, Selector, Watcher, useCanvas };