@leafer-ui/node 1.8.0 → 1.9.1

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, getMatrixData, 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,117 +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
894
  if (item.transform || item.scaleFixed) {
873
895
  canvas.save();
874
- if (item.transform)
875
- canvas.transform(item.transform);
896
+ if (item.transform) canvas.transform(item.transform);
876
897
  if (item.scaleFixed) {
877
- const { scaleX, scaleY } = ui.getRenderScaleData(true);
878
- canvas.scale(1 / scaleX, 1 / scaleY);
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);
879
900
  }
880
- if (item.blendMode)
881
- canvas.blendMode = item.blendMode;
901
+ if (item.blendMode) canvas.blendMode = item.blendMode;
882
902
  fillPathOrText(ui, canvas);
883
903
  canvas.restore();
884
- }
885
- else {
904
+ } else {
886
905
  if (item.blendMode) {
887
906
  canvas.saveBlendMode(item.blendMode);
888
907
  fillPathOrText(ui, canvas);
889
908
  canvas.restoreBlendMode();
890
- }
891
- else
892
- fillPathOrText(ui, canvas);
909
+ } else fillPathOrText(ui, canvas);
893
910
  }
894
911
  }
895
912
  }
913
+
896
914
  function fillPathOrText(ui, canvas) {
897
- 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();
898
916
  }
899
917
 
900
918
  function strokeText(stroke, ui, canvas) {
901
919
  switch (ui.__.strokeAlign) {
902
- case 'center':
903
- drawCenter$1(stroke, 1, ui, canvas);
904
- break;
905
- case 'inside':
906
- drawAlign(stroke, 'inside', ui, canvas);
907
- break;
908
- case 'outside':
909
- ui.__.__fillAfterStroke ? drawCenter$1(stroke, 2, ui, canvas) : drawAlign(stroke, 'outside', ui, canvas);
910
- 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;
911
931
  }
912
932
  }
933
+
913
934
  function drawCenter$1(stroke, strokeWidthScale, ui, canvas) {
914
935
  const data = ui.__;
915
- if (typeof stroke === 'object') {
936
+ if (isObject(stroke)) {
916
937
  drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas);
917
- }
918
- else {
938
+ } else {
919
939
  canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
920
940
  drawTextStroke(ui, canvas);
921
941
  }
922
942
  }
943
+
923
944
  function drawAlign(stroke, align, ui, canvas) {
924
945
  const out = canvas.getSameCanvas(true, true);
925
946
  out.font = ui.__.__font;
926
947
  drawCenter$1(stroke, 2, ui, out);
927
- out.blendMode = align === 'outside' ? 'destination-out' : 'destination-in';
948
+ out.blendMode = align === "outside" ? "destination-out" : "destination-in";
928
949
  fillText(ui, out);
929
- out.blendMode = 'normal';
950
+ out.blendMode = "normal";
930
951
  LeafHelper.copyCanvasByWorld(ui, canvas, out);
931
952
  out.recycle(ui.__nowWorld);
932
953
  }
954
+
933
955
  function drawTextStroke(ui, canvas) {
934
956
  let row, data = ui.__.__textDrawData;
935
- const { rows, decorationY } = data;
957
+ const {rows: rows, decorationY: decorationY} = data;
936
958
  for (let i = 0, len = rows.length; i < len; i++) {
937
959
  row = rows[i];
938
- if (row.text)
939
- canvas.strokeText(row.text, row.x, row.y);
940
- else if (row.data)
941
- 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
+ });
942
963
  }
943
964
  if (decorationY) {
944
- const { decorationHeight } = data;
965
+ const {decorationHeight: decorationHeight} = data;
945
966
  rows.forEach(row => decorationY.forEach(value => canvas.strokeRect(row.x, row.y + value, row.width, decorationHeight)));
946
967
  }
947
968
  }
969
+
948
970
  function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas) {
949
971
  let item;
950
- const data = ui.__, { __hasMultiStrokeStyle } = data;
972
+ const data = ui.__, {__hasMultiStrokeStyle: __hasMultiStrokeStyle} = data;
951
973
  __hasMultiStrokeStyle || canvas.setStroke(undefined, data.__strokeWidth * strokeWidthScale, data);
952
974
  for (let i = 0, len = strokes.length; i < len; i++) {
953
975
  item = strokes[i];
954
- if (item.image && PaintImage.checkImage(ui, canvas, item, false))
955
- continue;
976
+ if (item.image && PaintImage.checkImage(ui, canvas, item, false)) continue;
956
977
  if (item.style) {
957
978
  if (__hasMultiStrokeStyle) {
958
- const { strokeStyle } = item;
979
+ const {strokeStyle: strokeStyle} = item;
959
980
  strokeStyle ? canvas.setStroke(item.style, data.__getRealStrokeWidth(strokeStyle) * strokeWidthScale, data, strokeStyle) : canvas.setStroke(item.style, data.__strokeWidth * strokeWidthScale, data);
960
- }
961
- else
962
- canvas.strokeStyle = item.style;
981
+ } else canvas.strokeStyle = item.style;
963
982
  if (item.blendMode) {
964
983
  canvas.saveBlendMode(item.blendMode);
965
984
  isText ? drawTextStroke(ui, canvas) : canvas.stroke();
966
985
  canvas.restoreBlendMode();
967
- }
968
- else {
986
+ } else {
969
987
  isText ? drawTextStroke(ui, canvas) : canvas.stroke();
970
988
  }
971
989
  }
@@ -974,53 +992,54 @@ function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas) {
974
992
 
975
993
  function stroke(stroke, ui, canvas) {
976
994
  const data = ui.__;
977
- if (!data.__strokeWidth)
978
- return;
995
+ if (!data.__strokeWidth) return;
979
996
  if (data.__font) {
980
997
  strokeText(stroke, ui, canvas);
981
- }
982
- else {
998
+ } else {
983
999
  switch (data.strokeAlign) {
984
- case 'center':
985
- drawCenter(stroke, 1, ui, canvas);
986
- break;
987
- case 'inside':
988
- drawInside(stroke, ui, canvas);
989
- break;
990
- case 'outside':
991
- drawOutside(stroke, ui, canvas);
992
- 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;
993
1011
  }
994
1012
  }
995
1013
  }
1014
+
996
1015
  function strokes(strokes, ui, canvas) {
997
1016
  stroke(strokes, ui, canvas);
998
1017
  }
1018
+
999
1019
  function drawCenter(stroke, strokeWidthScale, ui, canvas) {
1000
1020
  const data = ui.__;
1001
- if (typeof stroke === 'object') {
1021
+ if (isObject(stroke)) {
1002
1022
  drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas);
1003
- }
1004
- else {
1023
+ } else {
1005
1024
  canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
1006
1025
  canvas.stroke();
1007
1026
  }
1008
- if (data.__useArrow)
1009
- Paint.strokeArrow(stroke, ui, canvas);
1027
+ if (data.__useArrow) Paint.strokeArrow(stroke, ui, canvas);
1010
1028
  }
1029
+
1011
1030
  function drawInside(stroke, ui, canvas) {
1012
1031
  canvas.save();
1013
1032
  canvas.clipUI(ui);
1014
1033
  drawCenter(stroke, 2, ui, canvas);
1015
1034
  canvas.restore();
1016
1035
  }
1036
+
1017
1037
  function drawOutside(stroke, ui, canvas) {
1018
1038
  const data = ui.__;
1019
1039
  if (data.__fillAfterStroke) {
1020
1040
  drawCenter(stroke, 2, ui, canvas);
1021
- }
1022
- else {
1023
- const { renderBounds } = ui.__layout;
1041
+ } else {
1042
+ const {renderBounds: renderBounds} = ui.__layout;
1024
1043
  const out = canvas.getSameCanvas(true, true);
1025
1044
  ui.__drawRenderPath(out);
1026
1045
  drawCenter(stroke, 2, ui, out);
@@ -1031,25 +1050,27 @@ function drawOutside(stroke, ui, canvas) {
1031
1050
  }
1032
1051
  }
1033
1052
 
1034
- const { getSpread, getOuterOf, getByMove, getIntersectData } = BoundsHelper;
1053
+ const {getSpread: getSpread, getOuterOf: getOuterOf, getByMove: getByMove, getIntersectData: getIntersectData} = BoundsHelper;
1054
+
1035
1055
  function shape(ui, current, options) {
1036
1056
  const canvas = current.getSameCanvas();
1037
- const nowWorld = ui.__nowWorld;
1038
- let bounds, fitMatrix, shapeBounds, worldCanvas;
1039
- let { scaleX, scaleY } = nowWorld;
1040
- if (scaleX < 0)
1041
- scaleX = -scaleX;
1042
- if (scaleY < 0)
1043
- scaleY = -scaleY;
1044
- if (current.bounds.includes(nowWorld)) {
1057
+ const nowWorld = ui.__nowWorld, currentBounds = current.bounds;
1058
+ let bounds, matrix, fitMatrix, shapeBounds, worldCanvas;
1059
+ let {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true);
1060
+ if (currentBounds.includes(nowWorld)) {
1045
1061
  worldCanvas = canvas;
1046
1062
  bounds = shapeBounds = nowWorld;
1047
- }
1048
- else {
1049
- const { renderShapeSpread: spread } = ui.__layout;
1050
- const worldClipBounds = getIntersectData(spread ? getSpread(current.bounds, scaleX === scaleY ? spread * scaleX : [spread * scaleY, spread * scaleX]) : current.bounds, nowWorld);
1051
- fitMatrix = current.bounds.getFitMatrix(worldClipBounds);
1052
- let { a: fitScaleX, d: fitScaleY } = fitMatrix;
1063
+ } else {
1064
+ const {renderShapeSpread: spread} = ui.__layout;
1065
+ let worldClipBounds;
1066
+ if (Platform.fullImageShadow) {
1067
+ worldClipBounds = nowWorld;
1068
+ } else {
1069
+ const spreadBounds = spread ? getSpread(currentBounds, scaleX === scaleY ? spread * scaleX : [ spread * scaleY, spread * scaleX ]) : currentBounds;
1070
+ worldClipBounds = getIntersectData(spreadBounds, nowWorld);
1071
+ }
1072
+ fitMatrix = currentBounds.getFitMatrix(worldClipBounds);
1073
+ let {a: fitScaleX, d: fitScaleY} = fitMatrix;
1053
1074
  if (fitMatrix.a < 1) {
1054
1075
  worldCanvas = current.getSameCanvas();
1055
1076
  ui.__renderShape(worldCanvas, options);
@@ -1058,28 +1079,39 @@ function shape(ui, current, options) {
1058
1079
  }
1059
1080
  shapeBounds = getOuterOf(nowWorld, fitMatrix);
1060
1081
  bounds = getByMove(shapeBounds, -fitMatrix.e, -fitMatrix.f);
1061
- if (options.matrix) {
1062
- const { matrix } = options;
1063
- fitMatrix.multiply(matrix);
1064
- fitScaleX *= matrix.scaleX;
1065
- fitScaleY *= matrix.scaleY;
1066
- }
1067
- options = Object.assign(Object.assign({}, options), { matrix: fitMatrix.withScale(fitScaleX, fitScaleY) });
1082
+ const userMatrix = options.matrix;
1083
+ if (userMatrix) {
1084
+ matrix = new Matrix(fitMatrix);
1085
+ matrix.multiply(userMatrix);
1086
+ fitScaleX *= userMatrix.scaleX;
1087
+ fitScaleY *= userMatrix.scaleY;
1088
+ } else matrix = fitMatrix;
1089
+ matrix.withScale(fitScaleX, fitScaleY);
1090
+ options = Object.assign(Object.assign({}, options), {
1091
+ matrix: matrix
1092
+ });
1068
1093
  }
1069
1094
  ui.__renderShape(canvas, options);
1070
1095
  return {
1071
- canvas, matrix: fitMatrix, bounds,
1072
- worldCanvas, shapeBounds, scaleX, scaleY
1096
+ canvas: canvas,
1097
+ matrix: matrix,
1098
+ fitMatrix: fitMatrix,
1099
+ bounds: bounds,
1100
+ worldCanvas: worldCanvas,
1101
+ shapeBounds: shapeBounds,
1102
+ scaleX: scaleX,
1103
+ scaleY: scaleY
1073
1104
  };
1074
1105
  }
1075
1106
 
1076
1107
  let recycleMap;
1077
- const { stintSet } = DataHelper, { hasTransparent: hasTransparent$1 } = ColorConvert;
1108
+
1109
+ const {stintSet: stintSet} = DataHelper, {hasTransparent: hasTransparent$1} = ColorConvert;
1110
+
1078
1111
  function compute(attrName, ui) {
1079
1112
  const data = ui.__, leafPaints = [];
1080
1113
  let paints = data.__input[attrName], isAlphaPixel, isTransparent;
1081
- if (!(paints instanceof Array))
1082
- paints = [paints];
1114
+ if (!isArray(paints)) paints = [ paints ];
1083
1115
  recycleMap = PaintImage.recycleImage(attrName, data);
1084
1116
  let maxChildStrokeWidth;
1085
1117
  for (let i = 0, len = paints.length, item; i < len; i++) {
@@ -1087,206 +1119,222 @@ function compute(attrName, ui) {
1087
1119
  leafPaints.push(item);
1088
1120
  if (item.strokeStyle) {
1089
1121
  maxChildStrokeWidth || (maxChildStrokeWidth = 1);
1090
- if (item.strokeStyle.strokeWidth)
1091
- maxChildStrokeWidth = Math.max(maxChildStrokeWidth, item.strokeStyle.strokeWidth);
1122
+ if (item.strokeStyle.strokeWidth) maxChildStrokeWidth = Math.max(maxChildStrokeWidth, item.strokeStyle.strokeWidth);
1092
1123
  }
1093
1124
  }
1094
1125
  }
1095
- data['_' + attrName] = leafPaints.length ? leafPaints : undefined;
1126
+ data["_" + attrName] = leafPaints.length ? leafPaints : undefined;
1096
1127
  if (leafPaints.length) {
1097
1128
  if (leafPaints.every(item => item.isTransparent)) {
1098
- if (leafPaints.some(item => item.image))
1099
- isAlphaPixel = true;
1129
+ if (leafPaints.some(item => item.image)) isAlphaPixel = true;
1100
1130
  isTransparent = true;
1101
1131
  }
1102
1132
  }
1103
- if (attrName === 'fill') {
1104
- stintSet(data, '__isAlphaPixelFill', isAlphaPixel);
1105
- stintSet(data, '__isTransparentFill', isTransparent);
1106
- }
1107
- else {
1108
- stintSet(data, '__isAlphaPixelStroke', isAlphaPixel);
1109
- stintSet(data, '__isTransparentStroke', isTransparent);
1110
- stintSet(data, '__hasMultiStrokeStyle', maxChildStrokeWidth);
1133
+ if (attrName === "fill") {
1134
+ stintSet(data, "__isAlphaPixelFill", isAlphaPixel);
1135
+ stintSet(data, "__isTransparentFill", isTransparent);
1136
+ } else {
1137
+ stintSet(data, "__isAlphaPixelStroke", isAlphaPixel);
1138
+ stintSet(data, "__isTransparentStroke", isTransparent);
1139
+ stintSet(data, "__hasMultiStrokeStyle", maxChildStrokeWidth);
1111
1140
  }
1112
1141
  }
1142
+
1113
1143
  function getLeafPaint(attrName, paint, ui) {
1114
- if (typeof paint !== 'object' || paint.visible === false || paint.opacity === 0)
1115
- return undefined;
1144
+ if (!isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
1116
1145
  let data;
1117
- const { boxBounds } = ui.__layout;
1146
+ const {boxBounds: boxBounds} = ui.__layout;
1118
1147
  switch (paint.type) {
1119
- case 'image':
1120
- data = PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
1121
- break;
1122
- case 'linear':
1123
- data = PaintGradient.linearGradient(paint, boxBounds);
1124
- break;
1125
- case 'radial':
1126
- data = PaintGradient.radialGradient(paint, boxBounds);
1127
- break;
1128
- case 'angular':
1129
- data = PaintGradient.conicGradient(paint, boxBounds);
1130
- break;
1131
- case 'solid':
1132
- const { type, color, opacity } = paint;
1133
- data = { type, style: ColorConvert.string(color, opacity) };
1134
- break;
1135
- default:
1136
- if (paint.r !== undefined)
1137
- data = { type: 'solid', style: ColorConvert.string(paint) };
1148
+ case "image":
1149
+ data = PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
1150
+ break;
1151
+
1152
+ case "linear":
1153
+ data = PaintGradient.linearGradient(paint, boxBounds);
1154
+ break;
1155
+
1156
+ case "radial":
1157
+ data = PaintGradient.radialGradient(paint, boxBounds);
1158
+ break;
1159
+
1160
+ case "angular":
1161
+ data = PaintGradient.conicGradient(paint, boxBounds);
1162
+ break;
1163
+
1164
+ case "solid":
1165
+ const {type: type, color: color, opacity: opacity} = paint;
1166
+ data = {
1167
+ type: type,
1168
+ style: ColorConvert.string(color, opacity)
1169
+ };
1170
+ break;
1171
+
1172
+ default:
1173
+ if (!isUndefined(paint.r)) data = {
1174
+ type: "solid",
1175
+ style: ColorConvert.string(paint)
1176
+ };
1138
1177
  }
1139
1178
  if (data) {
1140
- if (typeof data.style === 'string' && hasTransparent$1(data.style))
1141
- data.isTransparent = true;
1179
+ if (isString(data.style) && hasTransparent$1(data.style)) data.isTransparent = true;
1142
1180
  if (paint.style) {
1143
- if (paint.style.strokeWidth === 0)
1144
- return undefined;
1181
+ if (paint.style.strokeWidth === 0) return undefined;
1145
1182
  data.strokeStyle = paint.style;
1146
1183
  }
1147
- if (paint.blendMode)
1148
- data.blendMode = paint.blendMode;
1184
+ if (paint.editing) data.editing = paint.editing;
1185
+ if (paint.blendMode) data.blendMode = paint.blendMode;
1149
1186
  }
1150
1187
  return data;
1151
1188
  }
1152
1189
 
1153
1190
  const PaintModule = {
1154
- compute,
1155
- fill,
1156
- fills,
1157
- fillPathOrText,
1158
- fillText,
1159
- stroke,
1160
- strokes,
1161
- strokeText,
1162
- drawTextStroke,
1163
- shape
1191
+ compute: compute,
1192
+ fill: fill,
1193
+ fills: fills,
1194
+ fillPathOrText: fillPathOrText,
1195
+ fillText: fillText,
1196
+ stroke: stroke,
1197
+ strokes: strokes,
1198
+ strokeText: strokeText,
1199
+ drawTextStroke: drawTextStroke,
1200
+ shape: shape
1164
1201
  };
1165
1202
 
1166
1203
  let origin = {}, tempMatrix = getMatrixData();
1167
- const { get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, multiplyParent, scale: scaleHelper, rotate, skew: skewHelper } = MatrixHelper;
1204
+
1205
+ const {get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, multiplyParent: multiplyParent, scale: scaleHelper, rotate: rotate, skew: skewHelper} = MatrixHelper;
1206
+
1168
1207
  function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
1169
1208
  const transform = get$3();
1170
1209
  translate$1(transform, box.x + x, box.y + y);
1171
1210
  scaleHelper(transform, scaleX, scaleY);
1172
- if (rotation)
1173
- rotateOfOuter$1(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
1211
+ if (rotation) rotateOfOuter$1(transform, {
1212
+ x: box.x + box.width / 2,
1213
+ y: box.y + box.height / 2
1214
+ }, rotation);
1174
1215
  data.transform = transform;
1175
1216
  }
1217
+
1176
1218
  function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipSize) {
1177
1219
  const transform = get$3();
1178
- if (rotation)
1179
- rotate(transform, rotation);
1180
- if (skew)
1181
- skewHelper(transform, skew.x, skew.y);
1182
- if (scaleX)
1183
- scaleHelper(transform, scaleX, scaleY);
1184
- translate$1(transform, box.x + x, box.y + y);
1220
+ layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
1185
1221
  if (clipSize) {
1186
1222
  tempMatrix.a = box.width / clipSize.width, tempMatrix.d = box.height / clipSize.height;
1187
1223
  multiplyParent(transform, tempMatrix);
1188
1224
  }
1189
1225
  data.transform = transform;
1190
1226
  }
1191
- function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align) {
1227
+
1228
+ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, skew, align, freeTransform) {
1192
1229
  const transform = get$3();
1193
- if (rotation) {
1194
- if (align === 'center') {
1195
- rotateOfOuter$1(transform, { x: width / 2, y: height / 2 }, rotation);
1196
- }
1197
- else {
1198
- rotate(transform, rotation);
1199
- switch (rotation) {
1200
- case 90:
1230
+ if (freeTransform) {
1231
+ layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
1232
+ } else {
1233
+ if (rotation) {
1234
+ if (align === "center") {
1235
+ rotateOfOuter$1(transform, {
1236
+ x: width / 2,
1237
+ y: height / 2
1238
+ }, rotation);
1239
+ } else {
1240
+ rotate(transform, rotation);
1241
+ switch (rotation) {
1242
+ case 90:
1201
1243
  translate$1(transform, height, 0);
1202
1244
  break;
1203
- case 180:
1245
+
1246
+ case 180:
1204
1247
  translate$1(transform, width, height);
1205
1248
  break;
1206
- case 270:
1249
+
1250
+ case 270:
1207
1251
  translate$1(transform, 0, width);
1208
1252
  break;
1253
+ }
1209
1254
  }
1210
1255
  }
1256
+ origin.x = box.x + x;
1257
+ origin.y = box.y + y;
1258
+ translate$1(transform, origin.x, origin.y);
1259
+ if (scaleX) scaleOfOuter$1(transform, origin, scaleX, scaleY);
1211
1260
  }
1212
- origin.x = box.x + x;
1213
- origin.y = box.y + y;
1214
- translate$1(transform, origin.x, origin.y);
1215
- if (scaleX)
1216
- scaleOfOuter$1(transform, origin, scaleX, scaleY);
1217
1261
  data.transform = transform;
1218
1262
  }
1219
1263
 
1220
- const { get: get$2, translate } = MatrixHelper;
1221
- const tempBox = new Bounds();
1264
+ function layout(transform, box, x, y, scaleX, scaleY, rotation, skew) {
1265
+ if (rotation) rotate(transform, rotation);
1266
+ if (skew) skewHelper(transform, skew.x, skew.y);
1267
+ if (scaleX) scaleHelper(transform, scaleX, scaleY);
1268
+ translate$1(transform, box.x + x, box.y + y);
1269
+ }
1270
+
1271
+ const {get: get$2, translate: translate} = MatrixHelper;
1272
+
1273
+ const tempBox = new Bounds;
1274
+
1222
1275
  const tempScaleData = {};
1276
+
1223
1277
  const tempImage = {};
1278
+
1224
1279
  function createData(leafPaint, image, paint, box) {
1225
- const { changeful, sync, editing, scaleFixed } = paint;
1226
- if (changeful)
1227
- leafPaint.changeful = changeful;
1228
- if (sync)
1229
- leafPaint.sync = sync;
1230
- if (editing)
1231
- leafPaint.editing = editing;
1232
- if (scaleFixed)
1233
- leafPaint.scaleFixed = scaleFixed;
1280
+ const {changeful: changeful, sync: sync, scaleFixed: scaleFixed} = paint;
1281
+ if (changeful) leafPaint.changeful = changeful;
1282
+ if (sync) leafPaint.sync = sync;
1283
+ if (scaleFixed) leafPaint.scaleFixed = scaleFixed;
1234
1284
  leafPaint.data = getPatternData(paint, box, image);
1235
1285
  }
1286
+
1236
1287
  function getPatternData(paint, box, image) {
1237
- if (paint.padding)
1238
- box = tempBox.set(box).shrink(paint.padding);
1239
- if (paint.mode === 'strench')
1240
- paint.mode = 'stretch';
1241
- let { width, height } = image;
1242
- const { opacity, mode, align, offset, scale, size, rotation, skew, clipSize, repeat, filters } = paint;
1288
+ if (paint.padding) box = tempBox.set(box).shrink(paint.padding);
1289
+ if (paint.mode === "strench") paint.mode = "stretch";
1290
+ let {width: width, height: height} = image;
1291
+ 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;
1243
1292
  const sameBox = box.width === width && box.height === height;
1244
- const data = { mode };
1245
- const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
1293
+ const data = {
1294
+ mode: mode
1295
+ };
1296
+ const swapSize = align !== "center" && (rotation || 0) % 180 === 90;
1246
1297
  BoundsHelper.set(tempImage, 0, 0, swapSize ? height : width, swapSize ? width : height);
1247
1298
  let scaleX, scaleY;
1248
- if (!mode || mode === 'cover' || mode === 'fit') {
1299
+ if (!mode || mode === "cover" || mode === "fit") {
1249
1300
  if (!sameBox || rotation) {
1250
- scaleX = scaleY = BoundsHelper.getFitScale(box, tempImage, mode !== 'fit');
1301
+ scaleX = scaleY = BoundsHelper.getFitScale(box, tempImage, mode !== "fit");
1251
1302
  BoundsHelper.put(box, image, align, scaleX, false, tempImage);
1252
1303
  BoundsHelper.scale(tempImage, scaleX, scaleY, true);
1253
1304
  }
1254
- }
1255
- else {
1305
+ } else {
1256
1306
  if (scale || size) {
1257
1307
  MathHelper.getScaleData(scale, size, image, tempScaleData);
1258
1308
  scaleX = tempScaleData.scaleX;
1259
1309
  scaleY = tempScaleData.scaleY;
1260
1310
  }
1261
- if (align) {
1262
- if (scaleX)
1263
- BoundsHelper.scale(tempImage, scaleX, scaleY, true);
1264
- AlignHelper.toPoint(align, tempImage, box, tempImage, true, true);
1311
+ if (align || gap || repeat) {
1312
+ if (scaleX) BoundsHelper.scale(tempImage, scaleX, scaleY, true);
1313
+ if (align) AlignHelper.toPoint(align, tempImage, box, tempImage, true, true);
1265
1314
  }
1266
1315
  }
1267
- if (offset)
1268
- PointHelper.move(tempImage, offset);
1316
+ if (offset) PointHelper.move(tempImage, offset);
1269
1317
  switch (mode) {
1270
- case 'stretch':
1271
- if (!sameBox)
1272
- width = box.width, height = box.height;
1273
- break;
1274
- case 'normal':
1275
- case 'clip':
1276
- if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew)
1277
- clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, paint.clipSize);
1278
- break;
1279
- case 'repeat':
1280
- if (!sameBox || scaleX || rotation)
1281
- repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, align);
1282
- if (!repeat)
1283
- data.repeat = 'repeat';
1284
- break;
1285
- case 'fit':
1286
- case 'cover':
1287
- default:
1288
- if (scaleX)
1289
- fillOrFitMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
1318
+ case "stretch":
1319
+ if (!sameBox) width = box.width, height = box.height;
1320
+ break;
1321
+
1322
+ case "normal":
1323
+ case "clip":
1324
+ if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew) clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, paint.clipSize);
1325
+ break;
1326
+
1327
+ case "repeat":
1328
+ if (!sameBox || scaleX || rotation || skew) repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform);
1329
+ if (!repeat) data.repeat = "repeat";
1330
+ const count = isObject(repeat);
1331
+ if (gap || count) data.gap = getGapData(gap, count && repeat, tempImage.width, tempImage.height, box);
1332
+ break;
1333
+
1334
+ case "fit":
1335
+ case "cover":
1336
+ default:
1337
+ if (scaleX) fillOrFitMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
1290
1338
  }
1291
1339
  if (!data.transform) {
1292
1340
  if (box.x || box.y) {
@@ -1294,49 +1342,69 @@ function getPatternData(paint, box, image) {
1294
1342
  translate(data.transform, box.x, box.y);
1295
1343
  }
1296
1344
  }
1297
- if (scaleX && mode !== 'stretch') {
1345
+ if (scaleX && mode !== "stretch") {
1298
1346
  data.scaleX = scaleX;
1299
1347
  data.scaleY = scaleY;
1300
1348
  }
1301
1349
  data.width = width;
1302
1350
  data.height = height;
1303
- if (opacity)
1304
- data.opacity = opacity;
1305
- if (filters)
1306
- data.filters = filters;
1307
- if (repeat)
1308
- data.repeat = typeof repeat === 'string' ? (repeat === 'x' ? 'repeat-x' : 'repeat-y') : 'repeat';
1351
+ if (opacity) data.opacity = opacity;
1352
+ if (filters) data.filters = filters;
1353
+ if (repeat) data.repeat = isString(repeat) ? repeat === "x" ? "repeat-x" : "repeat-y" : "repeat";
1309
1354
  return data;
1310
1355
  }
1311
1356
 
1312
- let cache, box = new Bounds();
1313
- const { isSame } = BoundsHelper;
1357
+ function getGapData(gap, repeat, width, height, box) {
1358
+ let xGap, yGap;
1359
+ if (isObject(gap)) xGap = gap.x, yGap = gap.y; else xGap = yGap = gap;
1360
+ return {
1361
+ x: getGapValue(xGap, width, box.width, repeat && repeat.x),
1362
+ y: getGapValue(yGap, height, box.height, repeat && repeat.y)
1363
+ };
1364
+ }
1365
+
1366
+ function getGapValue(gap, size, totalSize, rows) {
1367
+ const auto = isString(gap) || rows;
1368
+ const remain = rows ? totalSize - rows * size : totalSize % size;
1369
+ const value = auto ? remain / ((rows || Math.floor(totalSize / size)) - 1) : gap;
1370
+ return gap === "auto" ? value < 0 ? 0 : value : value;
1371
+ }
1372
+
1373
+ let cache, box = new Bounds;
1374
+
1375
+ const {isSame: isSame} = BoundsHelper;
1376
+
1314
1377
  function image(ui, attrName, paint, boxBounds, firstUse) {
1315
1378
  let leafPaint, event;
1316
1379
  const image = ImageManager.get(paint);
1317
1380
  if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
1318
1381
  leafPaint = cache.leafPaint;
1319
- }
1320
- else {
1321
- leafPaint = { type: paint.type, image };
1322
- if (image.hasAlphaPixel)
1323
- leafPaint.isTransparent = true;
1324
- cache = image.use > 1 ? { leafPaint, paint, boxBounds: box.set(boxBounds) } : null;
1325
- }
1326
- if (firstUse || image.loading)
1327
- event = { image, attrName, attrValue: paint };
1382
+ } else {
1383
+ leafPaint = {
1384
+ type: paint.type,
1385
+ image: image
1386
+ };
1387
+ if (image.hasAlphaPixel) leafPaint.isTransparent = true;
1388
+ cache = image.use > 1 ? {
1389
+ leafPaint: leafPaint,
1390
+ paint: paint,
1391
+ boxBounds: box.set(boxBounds)
1392
+ } : null;
1393
+ }
1394
+ if (firstUse || image.loading) event = {
1395
+ image: image,
1396
+ attrName: attrName,
1397
+ attrValue: paint
1398
+ };
1328
1399
  if (image.ready) {
1329
1400
  checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds);
1330
1401
  if (firstUse) {
1331
1402
  onLoad(ui, event);
1332
1403
  onLoadSuccess(ui, event);
1333
1404
  }
1334
- }
1335
- else if (image.error) {
1336
- if (firstUse)
1337
- onLoadError(ui, event, image.error);
1338
- }
1339
- else {
1405
+ } else if (image.error) {
1406
+ if (firstUse) onLoadError(ui, event, image.error);
1407
+ } else {
1340
1408
  if (firstUse) {
1341
1409
  ignoreRender(ui, true);
1342
1410
  onLoad(ui, event);
@@ -1345,79 +1413,84 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
1345
1413
  ignoreRender(ui, false);
1346
1414
  if (!ui.destroyed) {
1347
1415
  if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds)) {
1348
- if (image.hasAlphaPixel)
1349
- ui.__layout.hitCanvasChanged = true;
1350
- ui.forceUpdate('surface');
1416
+ if (image.hasAlphaPixel) ui.__layout.hitCanvasChanged = true;
1417
+ ui.forceUpdate("surface");
1351
1418
  }
1352
1419
  onLoadSuccess(ui, event);
1353
1420
  }
1354
1421
  leafPaint.loadId = undefined;
1355
- }, (error) => {
1422
+ }, error => {
1356
1423
  ignoreRender(ui, false);
1357
1424
  onLoadError(ui, event, error);
1358
1425
  leafPaint.loadId = undefined;
1359
1426
  });
1360
1427
  if (ui.placeholderColor) {
1361
- if (!ui.placeholderDelay)
1362
- image.isPlacehold = true;
1363
- else
1364
- setTimeout(() => {
1365
- if (!image.ready) {
1366
- image.isPlacehold = true;
1367
- ui.forceUpdate('surface');
1368
- }
1369
- }, ui.placeholderDelay);
1428
+ if (!ui.placeholderDelay) image.isPlacehold = true; else setTimeout(() => {
1429
+ if (!image.ready) {
1430
+ image.isPlacehold = true;
1431
+ ui.forceUpdate("surface");
1432
+ }
1433
+ }, ui.placeholderDelay);
1370
1434
  }
1371
1435
  }
1372
1436
  return leafPaint;
1373
1437
  }
1438
+
1374
1439
  function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
1375
- if (attrName === 'fill' && !ui.__.__naturalWidth) {
1440
+ if (attrName === "fill" && !ui.__.__naturalWidth) {
1376
1441
  const data = ui.__;
1377
1442
  data.__naturalWidth = image.width / data.pixelRatio;
1378
1443
  data.__naturalHeight = image.height / data.pixelRatio;
1379
1444
  if (data.__autoSide) {
1380
- ui.forceUpdate('width');
1445
+ ui.forceUpdate("width");
1381
1446
  if (ui.__proxyData) {
1382
- ui.setProxyAttr('width', data.width);
1383
- ui.setProxyAttr('height', data.height);
1447
+ ui.setProxyAttr("width", data.width);
1448
+ ui.setProxyAttr("height", data.height);
1384
1449
  }
1385
1450
  return false;
1386
1451
  }
1387
1452
  }
1388
- if (!leafPaint.data)
1389
- createData(leafPaint, image, paint, boxBounds);
1453
+ if (!leafPaint.data) createData(leafPaint, image, paint, boxBounds);
1390
1454
  return true;
1391
1455
  }
1456
+
1392
1457
  function onLoad(ui, event) {
1393
1458
  emit(ui, ImageEvent.LOAD, event);
1394
1459
  }
1460
+
1395
1461
  function onLoadSuccess(ui, event) {
1396
1462
  emit(ui, ImageEvent.LOADED, event);
1397
1463
  }
1464
+
1398
1465
  function onLoadError(ui, event, error) {
1399
1466
  event.error = error;
1400
- ui.forceUpdate('surface');
1467
+ ui.forceUpdate("surface");
1401
1468
  emit(ui, ImageEvent.ERROR, event);
1402
1469
  }
1470
+
1403
1471
  function emit(ui, type, data) {
1404
- if (ui.hasEvent(type))
1405
- ui.emitEvent(new ImageEvent(type, data));
1472
+ if (ui.hasEvent(type)) ui.emitEvent(new ImageEvent(type, data));
1406
1473
  }
1474
+
1407
1475
  function ignoreRender(ui, value) {
1408
- const { leafer } = ui;
1409
- if (leafer && leafer.viewReady)
1410
- leafer.renderer.ignore = value;
1476
+ const {leafer: leafer} = ui;
1477
+ if (leafer && leafer.viewReady) leafer.renderer.ignore = value;
1411
1478
  }
1412
1479
 
1413
- const { get: get$1, scale, copy: copy$1 } = MatrixHelper;
1414
- const { ceil, abs } = Math;
1480
+ const {get: get$1, scale: scale, copy: copy$1} = MatrixHelper;
1481
+
1482
+ const {floor: floor, max: max, abs: abs} = Math;
1483
+
1415
1484
  function createPattern(ui, paint, pixelRatio) {
1416
- let { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
1417
- const id = scaleX + '-' + scaleY + '-' + pixelRatio;
1485
+ let {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
1486
+ const id = scaleX + "-" + scaleY + "-" + pixelRatio;
1418
1487
  if (paint.patternId !== id && !ui.destroyed) {
1419
- const { image, data } = paint;
1420
- let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, transform, repeat } = data;
1488
+ const {image: image, data: data} = paint;
1489
+ let imageScale, imageMatrix, {width: width, height: height, scaleX: sx, scaleY: sy, transform: transform, repeat: repeat, gap: gap} = data;
1490
+ scaleX *= pixelRatio;
1491
+ scaleY *= pixelRatio;
1492
+ const xGap = gap && gap.x * scaleX;
1493
+ const yGap = gap && gap.y * scaleY;
1421
1494
  if (sx) {
1422
1495
  sx = abs(sx);
1423
1496
  sy = abs(sy);
@@ -1427,23 +1500,18 @@ function createPattern(ui, paint, pixelRatio) {
1427
1500
  scaleX *= sx;
1428
1501
  scaleY *= sy;
1429
1502
  }
1430
- scaleX *= pixelRatio;
1431
- scaleY *= pixelRatio;
1432
1503
  width *= scaleX;
1433
1504
  height *= scaleY;
1434
1505
  const size = width * height;
1435
1506
  if (!repeat) {
1436
- if (size > Platform.image.maxCacheSize)
1437
- return false;
1507
+ if (size > Platform.image.maxCacheSize) return false;
1438
1508
  }
1439
1509
  let maxSize = Platform.image.maxPatternSize;
1440
1510
  if (!image.isSVG) {
1441
1511
  const imageSize = image.width * image.height;
1442
- if (maxSize > imageSize)
1443
- maxSize = imageSize;
1512
+ if (maxSize > imageSize) maxSize = imageSize;
1444
1513
  }
1445
- if (size > maxSize)
1446
- imageScale = Math.sqrt(size / maxSize);
1514
+ if (size > maxSize) imageScale = Math.sqrt(size / maxSize);
1447
1515
  if (imageScale) {
1448
1516
  scaleX /= imageScale;
1449
1517
  scaleY /= imageScale;
@@ -1457,65 +1525,62 @@ function createPattern(ui, paint, pixelRatio) {
1457
1525
  if (transform || scaleX !== 1 || scaleY !== 1) {
1458
1526
  if (!imageMatrix) {
1459
1527
  imageMatrix = get$1();
1460
- if (transform)
1461
- copy$1(imageMatrix, transform);
1528
+ if (transform) copy$1(imageMatrix, transform);
1462
1529
  }
1463
1530
  scale(imageMatrix, 1 / scaleX, 1 / scaleY);
1464
1531
  }
1465
- const canvas = image.getCanvas(ceil(width) || 1, ceil(height) || 1, data.opacity, data.filters);
1466
- const pattern = image.getPattern(canvas, repeat || (Platform.origin.noRepeat || 'no-repeat'), imageMatrix, paint);
1532
+ if (imageMatrix) {
1533
+ const canvasWidth = width + (xGap || 0), canvasHeight = height + (yGap || 0);
1534
+ scale(imageMatrix, canvasWidth / max(floor(canvasWidth), 1), canvasHeight / max(floor(canvasHeight), 1));
1535
+ }
1536
+ const canvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap);
1537
+ const pattern = image.getPattern(canvas, repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
1467
1538
  paint.style = pattern;
1468
1539
  paint.patternId = id;
1469
1540
  return true;
1470
- }
1471
- else {
1541
+ } else {
1472
1542
  return false;
1473
1543
  }
1474
1544
  }
1475
1545
 
1476
1546
  function checkImage(ui, canvas, paint, allowDraw) {
1477
- const { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
1478
- const { pixelRatio } = canvas, { data } = paint;
1479
- if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !Export.running)) {
1547
+ const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
1548
+ const {pixelRatio: pixelRatio} = canvas, {data: data} = paint;
1549
+ if (!data || paint.patternId === scaleX + "-" + scaleY + "-" + pixelRatio && !Export.running) {
1480
1550
  return false;
1481
- }
1482
- else {
1551
+ } else {
1483
1552
  if (allowDraw) {
1484
1553
  if (data.repeat) {
1485
1554
  allowDraw = false;
1486
- }
1487
- else {
1488
- if (!(paint.changeful || ResizeEvent.isResizing(ui) || Export.running)) {
1489
- let { width, height } = data;
1555
+ } else {
1556
+ if (!(paint.changeful || Platform.name === "miniapp" && ResizeEvent.isResizing(ui) || Export.running)) {
1557
+ let {width: width, height: height} = data;
1490
1558
  width *= scaleX * pixelRatio;
1491
1559
  height *= scaleY * pixelRatio;
1492
1560
  if (data.scaleX) {
1493
1561
  width *= data.scaleX;
1494
1562
  height *= data.scaleY;
1495
1563
  }
1496
- allowDraw = (width * height > Platform.image.maxCacheSize);
1564
+ allowDraw = width * height > Platform.image.maxCacheSize;
1497
1565
  }
1498
1566
  }
1499
1567
  }
1500
1568
  if (allowDraw) {
1501
1569
  if (ui.__.__isFastShadow) {
1502
- canvas.fillStyle = paint.style || '#000';
1570
+ canvas.fillStyle = paint.style || "#000";
1503
1571
  canvas.fill();
1504
1572
  }
1505
1573
  drawImage(ui, canvas, paint, data);
1506
1574
  return true;
1507
- }
1508
- else {
1575
+ } else {
1509
1576
  if (!paint.style || paint.sync || Export.running) {
1510
1577
  createPattern(ui, paint, pixelRatio);
1511
- }
1512
- else {
1578
+ } else {
1513
1579
  if (!paint.patternTask) {
1514
- paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function* () {
1580
+ paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function*() {
1515
1581
  paint.patternTask = null;
1516
- if (canvas.bounds.hit(ui.__nowWorld))
1517
- createPattern(ui, paint, pixelRatio);
1518
- ui.forceUpdate('surface');
1582
+ if (canvas.bounds.hit(ui.__nowWorld)) createPattern(ui, paint, pixelRatio);
1583
+ ui.forceUpdate("surface");
1519
1584
  }), 300);
1520
1585
  }
1521
1586
  }
@@ -1523,39 +1588,35 @@ function checkImage(ui, canvas, paint, allowDraw) {
1523
1588
  }
1524
1589
  }
1525
1590
  }
1591
+
1526
1592
  function drawImage(ui, canvas, paint, data) {
1527
1593
  canvas.save();
1528
1594
  canvas.clipUI(ui);
1529
- if (paint.blendMode)
1530
- canvas.blendMode = paint.blendMode;
1531
- if (data.opacity)
1532
- canvas.opacity *= data.opacity;
1533
- if (data.transform)
1534
- canvas.transform(data.transform);
1595
+ if (paint.blendMode) canvas.blendMode = paint.blendMode;
1596
+ if (data.opacity) canvas.opacity *= data.opacity;
1597
+ if (data.transform) canvas.transform(data.transform);
1535
1598
  canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1536
1599
  canvas.restore();
1537
1600
  }
1538
1601
 
1539
1602
  function recycleImage(attrName, data) {
1540
- const paints = data['_' + attrName];
1541
- if (paints instanceof Array) {
1603
+ const paints = data["_" + attrName];
1604
+ if (isArray(paints)) {
1542
1605
  let paint, image, recycleMap, input, url;
1543
1606
  for (let i = 0, len = paints.length; i < len; i++) {
1544
1607
  paint = paints[i];
1545
1608
  image = paint.image;
1546
1609
  url = image && image.url;
1547
1610
  if (url) {
1548
- if (!recycleMap)
1549
- recycleMap = {};
1611
+ if (!recycleMap) recycleMap = {};
1550
1612
  recycleMap[url] = true;
1551
1613
  ImageManager.recycle(image);
1552
1614
  if (image.loading) {
1553
1615
  if (!input) {
1554
- input = (data.__input && data.__input[attrName]) || [];
1555
- if (!(input instanceof Array))
1556
- input = [input];
1616
+ input = data.__input && data.__input[attrName] || [];
1617
+ if (!isArray(input)) input = [ input ];
1557
1618
  }
1558
- image.unload(paints[i].loadId, !input.some((item) => item.url === url));
1619
+ image.unload(paints[i].loadId, !input.some(item => item.url === url));
1559
1620
  }
1560
1621
  }
1561
1622
  }
@@ -1565,75 +1626,85 @@ function recycleImage(attrName, data) {
1565
1626
  }
1566
1627
 
1567
1628
  const PaintImageModule = {
1568
- image,
1569
- checkImage,
1570
- createPattern,
1571
- recycleImage,
1572
- createData,
1573
- getPatternData,
1574
- fillOrFitMode,
1575
- clipMode,
1576
- repeatMode
1629
+ image: image,
1630
+ checkImage: checkImage,
1631
+ createPattern: createPattern,
1632
+ recycleImage: recycleImage,
1633
+ createData: createData,
1634
+ getPatternData: getPatternData,
1635
+ fillOrFitMode: fillOrFitMode,
1636
+ clipMode: clipMode,
1637
+ repeatMode: repeatMode
1577
1638
  };
1578
1639
 
1579
- const { toPoint: toPoint$2 } = AroundHelper, { hasTransparent } = ColorConvert;
1640
+ const {toPoint: toPoint$2} = AroundHelper, {hasTransparent: hasTransparent} = ColorConvert;
1641
+
1580
1642
  const realFrom$2 = {};
1643
+
1581
1644
  const realTo$2 = {};
1645
+
1582
1646
  function linearGradient(paint, box) {
1583
- let { from, to, type, opacity } = paint;
1584
- toPoint$2(from || 'top', box, realFrom$2);
1585
- toPoint$2(to || 'bottom', box, realTo$2);
1647
+ let {from: from, to: to, type: type, opacity: opacity} = paint;
1648
+ toPoint$2(from || "top", box, realFrom$2);
1649
+ toPoint$2(to || "bottom", box, realTo$2);
1586
1650
  const style = Platform.canvas.createLinearGradient(realFrom$2.x, realFrom$2.y, realTo$2.x, realTo$2.y);
1587
- const data = { type, style };
1651
+ const data = {
1652
+ type: type,
1653
+ style: style
1654
+ };
1588
1655
  applyStops(data, style, paint.stops, opacity);
1589
1656
  return data;
1590
1657
  }
1658
+
1591
1659
  function applyStops(data, gradient, stops, opacity) {
1592
1660
  if (stops) {
1593
1661
  let stop, color, offset, isTransparent;
1594
1662
  for (let i = 0, len = stops.length; i < len; i++) {
1595
1663
  stop = stops[i];
1596
- if (typeof stop === 'string')
1597
- offset = i / (len - 1), color = ColorConvert.string(stop, opacity);
1598
- else
1599
- offset = stop.offset, color = ColorConvert.string(stop.color, opacity);
1664
+ if (isString(stop)) offset = i / (len - 1), color = ColorConvert.string(stop, opacity); else offset = stop.offset,
1665
+ color = ColorConvert.string(stop.color, opacity);
1600
1666
  gradient.addColorStop(offset, color);
1601
- if (!isTransparent && hasTransparent(color))
1602
- isTransparent = true;
1667
+ if (!isTransparent && hasTransparent(color)) isTransparent = true;
1603
1668
  }
1604
- if (isTransparent)
1605
- data.isTransparent = true;
1669
+ if (isTransparent) data.isTransparent = true;
1606
1670
  }
1607
1671
  }
1608
1672
 
1609
- const { getAngle, getDistance: getDistance$1 } = PointHelper;
1610
- const { get, rotateOfOuter, scaleOfOuter } = MatrixHelper;
1611
- const { toPoint: toPoint$1 } = AroundHelper;
1673
+ const {getAngle: getAngle, getDistance: getDistance$1} = PointHelper;
1674
+
1675
+ const {get: get, rotateOfOuter: rotateOfOuter, scaleOfOuter: scaleOfOuter} = MatrixHelper;
1676
+
1677
+ const {toPoint: toPoint$1} = AroundHelper;
1678
+
1612
1679
  const realFrom$1 = {};
1680
+
1613
1681
  const realTo$1 = {};
1682
+
1614
1683
  function radialGradient(paint, box) {
1615
- let { from, to, type, opacity, stretch } = paint;
1616
- toPoint$1(from || 'center', box, realFrom$1);
1617
- toPoint$1(to || 'bottom', box, realTo$1);
1684
+ let {from: from, to: to, type: type, opacity: opacity, stretch: stretch} = paint;
1685
+ toPoint$1(from || "center", box, realFrom$1);
1686
+ toPoint$1(to || "bottom", box, realTo$1);
1618
1687
  const style = Platform.canvas.createRadialGradient(realFrom$1.x, realFrom$1.y, 0, realFrom$1.x, realFrom$1.y, getDistance$1(realFrom$1, realTo$1));
1619
- const data = { type, style };
1688
+ const data = {
1689
+ type: type,
1690
+ style: style
1691
+ };
1620
1692
  applyStops(data, style, paint.stops, opacity);
1621
1693
  const transform = getTransform(box, realFrom$1, realTo$1, stretch, true);
1622
- if (transform)
1623
- data.transform = transform;
1694
+ if (transform) data.transform = transform;
1624
1695
  return data;
1625
1696
  }
1697
+
1626
1698
  function getTransform(box, from, to, stretch, rotate90) {
1627
1699
  let transform;
1628
- const { width, height } = box;
1700
+ const {width: width, height: height} = box;
1629
1701
  if (width !== height || stretch) {
1630
1702
  const angle = getAngle(from, to);
1631
1703
  transform = get();
1632
1704
  if (rotate90) {
1633
1705
  scaleOfOuter(transform, from, width / height * (stretch || 1), 1);
1634
1706
  rotateOfOuter(transform, from, angle + 90);
1635
- }
1636
- else {
1707
+ } else {
1637
1708
  scaleOfOuter(transform, from, 1, width / height * (stretch || 1));
1638
1709
  rotateOfOuter(transform, from, angle);
1639
1710
  }
@@ -1641,81 +1712,94 @@ function getTransform(box, from, to, stretch, rotate90) {
1641
1712
  return transform;
1642
1713
  }
1643
1714
 
1644
- const { getDistance } = PointHelper;
1645
- const { toPoint } = AroundHelper;
1715
+ const {getDistance: getDistance} = PointHelper;
1716
+
1717
+ const {toPoint: toPoint} = AroundHelper;
1718
+
1646
1719
  const realFrom = {};
1720
+
1647
1721
  const realTo = {};
1722
+
1648
1723
  function conicGradient(paint, box) {
1649
- let { from, to, type, opacity, stretch } = paint;
1650
- toPoint(from || 'center', box, realFrom);
1651
- toPoint(to || 'bottom', box, realTo);
1724
+ let {from: from, to: to, type: type, opacity: opacity, stretch: stretch} = paint;
1725
+ toPoint(from || "center", box, realFrom);
1726
+ toPoint(to || "bottom", box, realTo);
1652
1727
  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));
1653
- const data = { type, style };
1728
+ const data = {
1729
+ type: type,
1730
+ style: style
1731
+ };
1654
1732
  applyStops(data, style, paint.stops, opacity);
1655
1733
  const transform = getTransform(box, realFrom, realTo, stretch || 1, Platform.conicGradientRotate90);
1656
- if (transform)
1657
- data.transform = transform;
1734
+ if (transform) data.transform = transform;
1658
1735
  return data;
1659
1736
  }
1660
1737
 
1661
1738
  const PaintGradientModule = {
1662
- linearGradient,
1663
- radialGradient,
1664
- conicGradient,
1665
- getTransform
1739
+ linearGradient: linearGradient,
1740
+ radialGradient: radialGradient,
1741
+ conicGradient: conicGradient,
1742
+ getTransform: getTransform
1666
1743
  };
1667
1744
 
1668
- const { copy, toOffsetOutBounds: toOffsetOutBounds$1 } = BoundsHelper;
1745
+ const {copy: copy, toOffsetOutBounds: toOffsetOutBounds$1} = BoundsHelper;
1746
+
1669
1747
  const tempBounds = {};
1748
+
1670
1749
  const offsetOutBounds$1 = {};
1750
+
1671
1751
  function shadow(ui, current, shape) {
1672
1752
  let copyBounds, spreadScale;
1673
- const { __nowWorld: nowWorld, __layout } = ui;
1674
- const { shadow } = ui.__;
1675
- const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
1753
+ const {__nowWorld: nowWorld, __layout: __layout} = ui;
1754
+ const {shadow: shadow} = ui.__;
1755
+ const {worldCanvas: worldCanvas, bounds: bounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
1676
1756
  const other = current.getSameCanvas();
1677
1757
  const end = shadow.length - 1;
1678
1758
  toOffsetOutBounds$1(bounds, offsetOutBounds$1);
1679
1759
  shadow.forEach((item, index) => {
1680
- other.setWorldShadow((offsetOutBounds$1.offsetX + item.x * scaleX), (offsetOutBounds$1.offsetY + item.y * scaleY), item.blur * scaleX, ColorConvert.string(item.color));
1681
- spreadScale = item.spread ? 1 + item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) : 0;
1760
+ let otherScale = 1;
1761
+ if (item.scaleFixed) {
1762
+ const sx = Math.abs(nowWorld.scaleX);
1763
+ if (sx > 1) otherScale = 1 / sx;
1764
+ }
1765
+ other.setWorldShadow(offsetOutBounds$1.offsetX + item.x * scaleX * otherScale, offsetOutBounds$1.offsetY + item.y * scaleY * otherScale, item.blur * scaleX * otherScale, ColorConvert.string(item.color));
1766
+ spreadScale = item.spread ? 1 + item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) * otherScale : 0;
1682
1767
  drawWorldShadow(other, offsetOutBounds$1, spreadScale, shape);
1683
1768
  copyBounds = bounds;
1684
1769
  if (item.box) {
1685
1770
  other.restore();
1686
1771
  other.save();
1687
1772
  if (worldCanvas) {
1688
- other.copyWorld(other, bounds, nowWorld, 'copy');
1773
+ other.copyWorld(other, bounds, nowWorld, "copy");
1689
1774
  copyBounds = nowWorld;
1690
1775
  }
1691
- worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, 'destination-out') : other.copyWorld(shape.canvas, shapeBounds, bounds, 'destination-out');
1776
+ worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, "destination-out") : other.copyWorld(shape.canvas, shapeBounds, bounds, "destination-out");
1692
1777
  }
1693
1778
  LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
1694
- if (end && index < end)
1695
- other.clearWorld(copyBounds, true);
1779
+ if (end && index < end) other.clearWorld(copyBounds, true);
1696
1780
  });
1697
1781
  other.recycle(copyBounds);
1698
1782
  }
1783
+
1699
1784
  function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
1700
- const { bounds, shapeBounds } = shape;
1785
+ const {bounds: bounds, shapeBounds: shapeBounds} = shape;
1701
1786
  if (Platform.fullImageShadow) {
1702
1787
  copy(tempBounds, canvas.bounds);
1703
- tempBounds.x += (outBounds.x - shapeBounds.x);
1704
- tempBounds.y += (outBounds.y - shapeBounds.y);
1788
+ tempBounds.x += outBounds.x - shapeBounds.x;
1789
+ tempBounds.y += outBounds.y - shapeBounds.y;
1705
1790
  if (spreadScale) {
1706
- const { matrix } = shape;
1707
- tempBounds.x -= (bounds.x + (matrix ? matrix.e : 0) + bounds.width / 2) * (spreadScale - 1);
1708
- tempBounds.y -= (bounds.y + (matrix ? matrix.f : 0) + bounds.height / 2) * (spreadScale - 1);
1791
+ const {fitMatrix: fitMatrix} = shape;
1792
+ tempBounds.x -= (bounds.x + (fitMatrix ? fitMatrix.e : 0) + bounds.width / 2) * (spreadScale - 1);
1793
+ tempBounds.y -= (bounds.y + (fitMatrix ? fitMatrix.f : 0) + bounds.height / 2) * (spreadScale - 1);
1709
1794
  tempBounds.width *= spreadScale;
1710
1795
  tempBounds.height *= spreadScale;
1711
1796
  }
1712
1797
  canvas.copyWorld(shape.canvas, canvas.bounds, tempBounds);
1713
- }
1714
- else {
1798
+ } else {
1715
1799
  if (spreadScale) {
1716
1800
  copy(tempBounds, outBounds);
1717
- tempBounds.x -= (outBounds.width / 2) * (spreadScale - 1);
1718
- tempBounds.y -= (outBounds.height / 2) * (spreadScale - 1);
1801
+ tempBounds.x -= outBounds.width / 2 * (spreadScale - 1);
1802
+ tempBounds.y -= outBounds.height / 2 * (spreadScale - 1);
1719
1803
  tempBounds.width *= spreadScale;
1720
1804
  tempBounds.height *= spreadScale;
1721
1805
  }
@@ -1723,174 +1807,184 @@ function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
1723
1807
  }
1724
1808
  }
1725
1809
 
1726
- const { toOffsetOutBounds } = BoundsHelper;
1810
+ const {toOffsetOutBounds: toOffsetOutBounds} = BoundsHelper;
1811
+
1727
1812
  const offsetOutBounds = {};
1813
+
1728
1814
  function innerShadow(ui, current, shape) {
1729
1815
  let copyBounds, spreadScale;
1730
- const { __nowWorld: nowWorld, __layout } = ui;
1731
- const { innerShadow } = ui.__;
1732
- const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
1816
+ const {__nowWorld: nowWorld, __layout: __layout} = ui;
1817
+ const {innerShadow: innerShadow} = ui.__;
1818
+ const {worldCanvas: worldCanvas, bounds: bounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
1733
1819
  const other = current.getSameCanvas();
1734
1820
  const end = innerShadow.length - 1;
1735
1821
  toOffsetOutBounds(bounds, offsetOutBounds);
1736
1822
  innerShadow.forEach((item, index) => {
1823
+ let otherScale = 1;
1824
+ if (item.scaleFixed) {
1825
+ const sx = Math.abs(nowWorld.scaleX);
1826
+ if (sx > 1) otherScale = 1 / sx;
1827
+ }
1737
1828
  other.save();
1738
- other.setWorldShadow((offsetOutBounds.offsetX + item.x * scaleX), (offsetOutBounds.offsetY + item.y * scaleY), item.blur * scaleX);
1739
- spreadScale = item.spread ? 1 - item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) : 0;
1829
+ other.setWorldShadow(offsetOutBounds.offsetX + item.x * scaleX * otherScale, offsetOutBounds.offsetY + item.y * scaleY * otherScale, item.blur * scaleX * otherScale);
1830
+ spreadScale = item.spread ? 1 - item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) * otherScale : 0;
1740
1831
  drawWorldShadow(other, offsetOutBounds, spreadScale, shape);
1741
1832
  other.restore();
1742
1833
  if (worldCanvas) {
1743
- other.copyWorld(other, bounds, nowWorld, 'copy');
1744
- other.copyWorld(worldCanvas, nowWorld, nowWorld, 'source-out');
1834
+ other.copyWorld(other, bounds, nowWorld, "copy");
1835
+ other.copyWorld(worldCanvas, nowWorld, nowWorld, "source-out");
1745
1836
  copyBounds = nowWorld;
1746
- }
1747
- else {
1748
- other.copyWorld(shape.canvas, shapeBounds, bounds, 'source-out');
1837
+ } else {
1838
+ other.copyWorld(shape.canvas, shapeBounds, bounds, "source-out");
1749
1839
  copyBounds = bounds;
1750
1840
  }
1751
- other.fillWorld(copyBounds, ColorConvert.string(item.color), 'source-in');
1841
+ other.fillWorld(copyBounds, ColorConvert.string(item.color), "source-in");
1752
1842
  LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
1753
- if (end && index < end)
1754
- other.clearWorld(copyBounds, true);
1843
+ if (end && index < end) other.clearWorld(copyBounds, true);
1755
1844
  });
1756
1845
  other.recycle(copyBounds);
1757
1846
  }
1758
1847
 
1759
1848
  function blur(ui, current, origin) {
1760
- const { blur } = ui.__;
1849
+ const {blur: blur} = ui.__;
1761
1850
  origin.setWorldBlur(blur * ui.__nowWorld.a);
1762
1851
  origin.copyWorldToInner(current, ui.__nowWorld, ui.__layout.renderBounds);
1763
- origin.filter = 'none';
1852
+ origin.filter = "none";
1764
1853
  }
1765
1854
 
1766
- function backgroundBlur(_ui, _current, _shape) {
1767
- }
1855
+ function backgroundBlur(_ui, _current, _shape) {}
1768
1856
 
1769
1857
  const EffectModule = {
1770
- shadow,
1771
- innerShadow,
1772
- blur,
1773
- backgroundBlur
1858
+ shadow: shadow,
1859
+ innerShadow: innerShadow,
1860
+ blur: blur,
1861
+ backgroundBlur: backgroundBlur
1774
1862
  };
1775
1863
 
1776
- const { excludeRenderBounds } = LeafBoundsHelper;
1777
- Group.prototype.__renderMask = function (canvas, options) {
1864
+ const {excludeRenderBounds: excludeRenderBounds} = LeafBoundsHelper;
1865
+
1866
+ let usedGrayscaleAlpha;
1867
+
1868
+ Group.prototype.__renderMask = function(canvas, options) {
1778
1869
  let child, maskCanvas, contentCanvas, maskOpacity, currentMask, mask;
1779
- const { children } = this;
1870
+ const {children: children} = this;
1780
1871
  for (let i = 0, len = children.length; i < len; i++) {
1781
1872
  child = children[i], mask = child.__.mask;
1782
1873
  if (mask) {
1783
1874
  if (currentMask) {
1784
- maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
1875
+ maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
1785
1876
  maskCanvas = contentCanvas = null;
1786
1877
  }
1787
- if (mask === 'path' || mask === 'clipping-path') {
1788
- if (child.opacity < 1) {
1789
- currentMask = 'opacity-path';
1790
- maskOpacity = child.opacity;
1791
- if (!contentCanvas)
1792
- contentCanvas = getCanvas(canvas);
1793
- }
1794
- else {
1795
- currentMask = 'path';
1878
+ maskOpacity = child.__.opacity;
1879
+ usedGrayscaleAlpha = false;
1880
+ if (mask === "path" || mask === "clipping-path") {
1881
+ if (maskOpacity < 1) {
1882
+ currentMask = "opacity-path";
1883
+ if (!contentCanvas) contentCanvas = getCanvas(canvas);
1884
+ } else {
1885
+ currentMask = "path";
1796
1886
  canvas.save();
1797
1887
  }
1798
1888
  child.__clip(contentCanvas || canvas, options);
1799
- }
1800
- else {
1801
- currentMask = mask === 'grayscale' ? 'grayscale' : 'alpha';
1802
- if (!maskCanvas)
1803
- maskCanvas = getCanvas(canvas);
1804
- if (!contentCanvas)
1805
- contentCanvas = getCanvas(canvas);
1889
+ } else {
1890
+ currentMask = mask === "grayscale" ? "grayscale" : "alpha";
1891
+ if (!maskCanvas) maskCanvas = getCanvas(canvas);
1892
+ if (!contentCanvas) contentCanvas = getCanvas(canvas);
1806
1893
  child.__render(maskCanvas, options);
1807
1894
  }
1808
- if (mask === 'clipping' || mask === 'clipping-path')
1809
- excludeRenderBounds(child, options) || child.__render(canvas, options);
1895
+ if (mask === "clipping" || mask === "clipping-path") excludeRenderBounds(child, options) || child.__render(canvas, options);
1810
1896
  continue;
1811
1897
  }
1898
+ const childBlendMode = maskOpacity === 1 && child.__.__blendMode;
1899
+ if (childBlendMode) maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, false);
1812
1900
  excludeRenderBounds(child, options) || child.__render(contentCanvas || canvas, options);
1901
+ if (childBlendMode) maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, childBlendMode, false);
1813
1902
  }
1814
- maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
1903
+ maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
1815
1904
  };
1816
- function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity) {
1905
+
1906
+ function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity, blendMode, recycle) {
1817
1907
  switch (maskMode) {
1818
- case 'grayscale':
1819
- maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
1820
- case 'alpha':
1821
- usePixelMask(leaf, canvas, contentCanvas, maskCanvas);
1822
- break;
1823
- case 'opacity-path':
1824
- copyContent(leaf, canvas, contentCanvas, maskOpacity);
1825
- break;
1826
- case 'path':
1827
- canvas.restore();
1908
+ case "grayscale":
1909
+ if (!usedGrayscaleAlpha) usedGrayscaleAlpha = true, maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
1910
+
1911
+ case "alpha":
1912
+ usePixelMask(leaf, canvas, contentCanvas, maskCanvas, blendMode, recycle);
1913
+ break;
1914
+
1915
+ case "opacity-path":
1916
+ copyContent(leaf, canvas, contentCanvas, maskOpacity, blendMode, recycle);
1917
+ break;
1918
+
1919
+ case "path":
1920
+ if (recycle) canvas.restore();
1828
1921
  }
1829
1922
  }
1923
+
1830
1924
  function getCanvas(canvas) {
1831
1925
  return canvas.getSameCanvas(false, true);
1832
1926
  }
1833
- function usePixelMask(leaf, canvas, content, mask) {
1927
+
1928
+ function usePixelMask(leaf, canvas, content, mask, blendMode, recycle) {
1834
1929
  const realBounds = leaf.__nowWorld;
1835
1930
  content.resetTransform();
1836
1931
  content.opacity = 1;
1837
1932
  content.useMask(mask, realBounds);
1838
- mask.recycle(realBounds);
1839
- copyContent(leaf, canvas, content, 1);
1933
+ if (recycle) mask.recycle(realBounds);
1934
+ copyContent(leaf, canvas, content, 1, blendMode, recycle);
1840
1935
  }
1841
- function copyContent(leaf, canvas, content, maskOpacity) {
1936
+
1937
+ function copyContent(leaf, canvas, content, maskOpacity, blendMode, recycle) {
1842
1938
  const realBounds = leaf.__nowWorld;
1843
1939
  canvas.resetTransform();
1844
1940
  canvas.opacity = maskOpacity;
1845
- canvas.copyWorld(content, realBounds);
1846
- content.recycle(realBounds);
1847
- }
1848
-
1849
- const money = '¥¥$€££¢¢';
1850
- const letter = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
1851
- const langBefore = '《(「〈『〖【〔{┌<‘“=' + money;
1852
- const langAfter = '》)」〉』〗】〕}┐>’”!?,、。:;‰';
1853
- const langSymbol = '≮≯≈≠=…';
1854
- const langBreak$1 = '—/~|┆·';
1855
- const beforeChar = '{[(<\'"' + langBefore;
1856
- const afterChar = '>)]}%!?,.:;\'"' + langAfter;
1857
- const symbolChar = afterChar + '_#~&*+\\=|' + langSymbol;
1858
- const breakChar = '- ' + langBreak$1;
1859
- const cjkRangeList = [
1860
- [0x4E00, 0x9FFF],
1861
- [0x3400, 0x4DBF],
1862
- [0x20000, 0x2A6DF],
1863
- [0x2A700, 0x2B73F],
1864
- [0x2B740, 0x2B81F],
1865
- [0x2B820, 0x2CEAF],
1866
- [0x2CEB0, 0x2EBEF],
1867
- [0x30000, 0x3134F],
1868
- [0x31350, 0x323AF],
1869
- [0x2E80, 0x2EFF],
1870
- [0x2F00, 0x2FDF],
1871
- [0x2FF0, 0x2FFF],
1872
- [0x3000, 0x303F],
1873
- [0x31C0, 0x31EF],
1874
- [0x3200, 0x32FF],
1875
- [0x3300, 0x33FF],
1876
- [0xF900, 0xFAFF],
1877
- [0xFE30, 0xFE4F],
1878
- [0x1F200, 0x1F2FF],
1879
- [0x2F800, 0x2FA1F],
1880
- ];
1881
- const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u${start.toString(16)}-\\u${end.toString(16)}]`).join('|'));
1941
+ canvas.copyWorld(content, realBounds, undefined, blendMode);
1942
+ recycle ? content.recycle(realBounds) : content.clearWorld(realBounds, true);
1943
+ }
1944
+
1945
+ const money = "¥¥$€££¢¢";
1946
+
1947
+ const letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
1948
+
1949
+ const langBefore = "《(「〈『〖【〔{┌<‘“=" + money;
1950
+
1951
+ const langAfter = "》)」〉』〗】〕}┐>’”!?,、。:;‰";
1952
+
1953
+ const langSymbol = "≮≯≈≠=…";
1954
+
1955
+ const langBreak$1 = "—/~|┆·";
1956
+
1957
+ const beforeChar = "{[(<'\"" + langBefore;
1958
+
1959
+ const afterChar = ">)]}%!?,.:;'\"" + langAfter;
1960
+
1961
+ const symbolChar = afterChar + "_#~&*+\\=|" + langSymbol;
1962
+
1963
+ const breakChar = "- " + langBreak$1;
1964
+
1965
+ 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 ] ];
1966
+
1967
+ const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u${start.toString(16)}-\\u${end.toString(16)}]`).join("|"));
1968
+
1882
1969
  function mapChar(str) {
1883
1970
  const map = {};
1884
- str.split('').forEach(char => map[char] = true);
1971
+ str.split("").forEach(char => map[char] = true);
1885
1972
  return map;
1886
1973
  }
1974
+
1887
1975
  const letterMap = mapChar(letter);
1976
+
1888
1977
  const beforeMap = mapChar(beforeChar);
1978
+
1889
1979
  const afterMap = mapChar(afterChar);
1980
+
1890
1981
  const symbolMap = mapChar(symbolChar);
1982
+
1891
1983
  const breakMap = mapChar(breakChar);
1984
+
1892
1985
  var CharType;
1893
- (function (CharType) {
1986
+
1987
+ (function(CharType) {
1894
1988
  CharType[CharType["Letter"] = 0] = "Letter";
1895
1989
  CharType[CharType["Single"] = 1] = "Single";
1896
1990
  CharType[CharType["Before"] = 2] = "Before";
@@ -1898,179 +1992,175 @@ var CharType;
1898
1992
  CharType[CharType["Symbol"] = 4] = "Symbol";
1899
1993
  CharType[CharType["Break"] = 5] = "Break";
1900
1994
  })(CharType || (CharType = {}));
1901
- const { Letter: Letter$1, Single: Single$1, Before: Before$1, After: After$1, Symbol: Symbol$1, Break: Break$1 } = CharType;
1995
+
1996
+ const {Letter: Letter$1, Single: Single$1, Before: Before$1, After: After$1, Symbol: Symbol$1, Break: Break$1} = CharType;
1997
+
1902
1998
  function getCharType(char) {
1903
1999
  if (letterMap[char]) {
1904
2000
  return Letter$1;
1905
- }
1906
- else if (breakMap[char]) {
2001
+ } else if (breakMap[char]) {
1907
2002
  return Break$1;
1908
- }
1909
- else if (beforeMap[char]) {
2003
+ } else if (beforeMap[char]) {
1910
2004
  return Before$1;
1911
- }
1912
- else if (afterMap[char]) {
2005
+ } else if (afterMap[char]) {
1913
2006
  return After$1;
1914
- }
1915
- else if (symbolMap[char]) {
2007
+ } else if (symbolMap[char]) {
1916
2008
  return Symbol$1;
1917
- }
1918
- else if (cjkReg.test(char)) {
2009
+ } else if (cjkReg.test(char)) {
1919
2010
  return Single$1;
1920
- }
1921
- else {
2011
+ } else {
1922
2012
  return Letter$1;
1923
2013
  }
1924
2014
  }
1925
2015
 
1926
2016
  const TextRowHelper = {
1927
2017
  trimRight(row) {
1928
- const { words } = row;
2018
+ const {words: words} = row;
1929
2019
  let trimRight = 0, len = words.length, char;
1930
2020
  for (let i = len - 1; i > -1; i--) {
1931
2021
  char = words[i].data[0];
1932
- if (char.char === ' ') {
2022
+ if (char.char === " ") {
1933
2023
  trimRight++;
1934
2024
  row.width -= char.width;
1935
- }
1936
- else {
2025
+ } else {
1937
2026
  break;
1938
2027
  }
1939
2028
  }
1940
- if (trimRight)
1941
- words.splice(len - trimRight, trimRight);
2029
+ if (trimRight) words.splice(len - trimRight, trimRight);
1942
2030
  }
1943
2031
  };
1944
2032
 
1945
2033
  function getTextCase(char, textCase, firstChar) {
1946
2034
  switch (textCase) {
1947
- case 'title':
1948
- return firstChar ? char.toUpperCase() : char;
1949
- case 'upper':
1950
- return char.toUpperCase();
1951
- case 'lower':
1952
- return char.toLowerCase();
1953
- default:
1954
- return char;
2035
+ case "title":
2036
+ return firstChar ? char.toUpperCase() : char;
2037
+
2038
+ case "upper":
2039
+ return char.toUpperCase();
2040
+
2041
+ case "lower":
2042
+ return char.toLowerCase();
2043
+
2044
+ default:
2045
+ return char;
1955
2046
  }
1956
2047
  }
1957
2048
 
1958
- const { trimRight } = TextRowHelper;
1959
- const { Letter, Single, Before, After, Symbol, Break } = CharType;
2049
+ const {trimRight: trimRight} = TextRowHelper;
2050
+
2051
+ const {Letter: Letter, Single: Single, Before: Before, After: After, Symbol: Symbol, Break: Break} = CharType;
2052
+
1960
2053
  let word, row, wordWidth, rowWidth, realWidth;
2054
+
1961
2055
  let char, charWidth, startCharSize, charSize, charType, lastCharType, langBreak, afterBreak, paraStart;
2056
+
1962
2057
  let textDrawData, rows = [], bounds, findMaxWidth;
2058
+
1963
2059
  function createRows(drawData, content, style) {
1964
2060
  textDrawData = drawData;
1965
2061
  rows = drawData.rows;
1966
2062
  bounds = drawData.bounds;
1967
2063
  findMaxWidth = !bounds.width && !style.autoSizeAlign;
1968
- const { __letterSpacing, paraIndent, textCase } = style;
1969
- const { canvas } = Platform;
1970
- const { width, height } = bounds;
1971
- const charMode = width || height || __letterSpacing || (textCase !== 'none');
2064
+ const {__letterSpacing: __letterSpacing, paraIndent: paraIndent, textCase: textCase} = style;
2065
+ const {canvas: canvas} = Platform;
2066
+ const {width: width, height: height} = bounds;
2067
+ const charMode = width || height || __letterSpacing || textCase !== "none";
1972
2068
  if (charMode) {
1973
- const wrap = style.textWrap !== 'none';
1974
- const breakAll = style.textWrap === 'break';
2069
+ const wrap = style.textWrap !== "none";
2070
+ const breakAll = style.textWrap === "break";
1975
2071
  paraStart = true;
1976
2072
  lastCharType = null;
1977
2073
  startCharSize = charWidth = charSize = wordWidth = rowWidth = 0;
1978
- word = { data: [] }, row = { words: [] };
1979
- if (__letterSpacing)
1980
- content = [...content];
2074
+ word = {
2075
+ data: []
2076
+ }, row = {
2077
+ words: []
2078
+ };
2079
+ if (__letterSpacing) content = [ ...content ];
1981
2080
  for (let i = 0, len = content.length; i < len; i++) {
1982
2081
  char = content[i];
1983
- if (char === '\n') {
1984
- if (wordWidth)
1985
- addWord();
2082
+ if (char === "\n") {
2083
+ if (wordWidth) addWord();
1986
2084
  row.paraEnd = true;
1987
2085
  addRow();
1988
2086
  paraStart = true;
1989
- }
1990
- else {
2087
+ } else {
1991
2088
  charType = getCharType(char);
1992
- if (charType === Letter && textCase !== 'none')
1993
- char = getTextCase(char, textCase, !wordWidth);
2089
+ if (charType === Letter && textCase !== "none") char = getTextCase(char, textCase, !wordWidth);
1994
2090
  charWidth = canvas.measureText(char).width;
1995
2091
  if (__letterSpacing) {
1996
- if (__letterSpacing < 0)
1997
- charSize = charWidth;
2092
+ if (__letterSpacing < 0) charSize = charWidth;
1998
2093
  charWidth += __letterSpacing;
1999
2094
  }
2000
- langBreak = (charType === Single && (lastCharType === Single || lastCharType === Letter)) || (lastCharType === Single && charType !== After);
2001
- afterBreak = ((charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After));
2095
+ langBreak = charType === Single && (lastCharType === Single || lastCharType === Letter) || lastCharType === Single && charType !== After;
2096
+ afterBreak = (charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After);
2002
2097
  realWidth = paraStart && paraIndent ? width - paraIndent : width;
2003
2098
  if (wrap && (width && rowWidth + wordWidth + charWidth > realWidth)) {
2004
2099
  if (breakAll) {
2005
- if (wordWidth)
2006
- addWord();
2007
- if (rowWidth)
2008
- addRow();
2009
- }
2010
- else {
2011
- if (!afterBreak)
2012
- afterBreak = charType === Letter && lastCharType == After;
2013
- if (langBreak || afterBreak || charType === Break || charType === Before || charType === Single || (wordWidth + charWidth > realWidth)) {
2014
- if (wordWidth)
2015
- addWord();
2016
- if (rowWidth)
2017
- addRow();
2018
- }
2019
- else {
2020
- if (rowWidth)
2021
- addRow();
2100
+ if (wordWidth) addWord();
2101
+ if (rowWidth) addRow();
2102
+ } else {
2103
+ if (!afterBreak) afterBreak = charType === Letter && lastCharType == After;
2104
+ if (langBreak || afterBreak || charType === Break || charType === Before || charType === Single || wordWidth + charWidth > realWidth) {
2105
+ if (wordWidth) addWord();
2106
+ if (rowWidth) addRow();
2107
+ } else {
2108
+ if (rowWidth) addRow();
2022
2109
  }
2023
2110
  }
2024
2111
  }
2025
- if (char === ' ' && paraStart !== true && (rowWidth + wordWidth) === 0) ;
2026
- else {
2112
+ if (char === " " && paraStart !== true && rowWidth + wordWidth === 0) ; else {
2027
2113
  if (charType === Break) {
2028
- if (char === ' ' && wordWidth)
2029
- addWord();
2114
+ if (char === " " && wordWidth) addWord();
2030
2115
  addChar(char, charWidth);
2031
2116
  addWord();
2032
- }
2033
- else if (langBreak || afterBreak) {
2034
- if (wordWidth)
2035
- addWord();
2117
+ } else if (langBreak || afterBreak) {
2118
+ if (wordWidth) addWord();
2036
2119
  addChar(char, charWidth);
2037
- }
2038
- else {
2120
+ } else {
2039
2121
  addChar(char, charWidth);
2040
2122
  }
2041
2123
  }
2042
2124
  lastCharType = charType;
2043
2125
  }
2044
2126
  }
2045
- if (wordWidth)
2046
- addWord();
2047
- if (rowWidth)
2048
- addRow();
2127
+ if (wordWidth) addWord();
2128
+ if (rowWidth) addRow();
2049
2129
  rows.length > 0 && (rows[rows.length - 1].paraEnd = true);
2050
- }
2051
- else {
2052
- content.split('\n').forEach(content => {
2130
+ } else {
2131
+ content.split("\n").forEach(content => {
2053
2132
  textDrawData.paraNumber++;
2054
2133
  rowWidth = canvas.measureText(content).width;
2055
- rows.push({ x: paraIndent || 0, text: content, width: rowWidth, paraStart: true });
2056
- if (findMaxWidth)
2057
- setMaxWidth();
2134
+ rows.push({
2135
+ x: paraIndent || 0,
2136
+ text: content,
2137
+ width: rowWidth,
2138
+ paraStart: true
2139
+ });
2140
+ if (findMaxWidth) setMaxWidth();
2058
2141
  });
2059
2142
  }
2060
2143
  }
2144
+
2061
2145
  function addChar(char, width) {
2062
- if (charSize && !startCharSize)
2063
- startCharSize = charSize;
2064
- word.data.push({ char, width });
2146
+ if (charSize && !startCharSize) startCharSize = charSize;
2147
+ word.data.push({
2148
+ char: char,
2149
+ width: width
2150
+ });
2065
2151
  wordWidth += width;
2066
2152
  }
2153
+
2067
2154
  function addWord() {
2068
2155
  rowWidth += wordWidth;
2069
2156
  word.width = wordWidth;
2070
2157
  row.words.push(word);
2071
- word = { data: [] };
2158
+ word = {
2159
+ data: []
2160
+ };
2072
2161
  wordWidth = 0;
2073
2162
  }
2163
+
2074
2164
  function addRow() {
2075
2165
  if (paraStart) {
2076
2166
  textDrawData.paraNumber++;
@@ -2083,52 +2173,53 @@ function addRow() {
2083
2173
  startCharSize = 0;
2084
2174
  }
2085
2175
  row.width = rowWidth;
2086
- if (bounds.width)
2087
- trimRight(row);
2088
- else if (findMaxWidth)
2089
- setMaxWidth();
2176
+ if (bounds.width) trimRight(row); else if (findMaxWidth) setMaxWidth();
2090
2177
  rows.push(row);
2091
- row = { words: [] };
2178
+ row = {
2179
+ words: []
2180
+ };
2092
2181
  rowWidth = 0;
2093
2182
  }
2183
+
2094
2184
  function setMaxWidth() {
2095
- if (rowWidth > (textDrawData.maxWidth || 0))
2096
- textDrawData.maxWidth = rowWidth;
2185
+ if (rowWidth > (textDrawData.maxWidth || 0)) textDrawData.maxWidth = rowWidth;
2097
2186
  }
2098
2187
 
2099
2188
  const CharMode = 0;
2189
+
2100
2190
  const WordMode = 1;
2191
+
2101
2192
  const TextMode = 2;
2193
+
2102
2194
  function layoutChar(drawData, style, width, _height) {
2103
- const { rows } = drawData;
2104
- const { textAlign, paraIndent, letterSpacing } = style;
2195
+ const {rows: rows} = drawData;
2196
+ const {textAlign: textAlign, paraIndent: paraIndent, letterSpacing: letterSpacing} = style;
2105
2197
  let charX, addWordWidth, indentWidth, mode, wordChar, wordsLength;
2106
2198
  rows.forEach(row => {
2107
2199
  if (row.words) {
2108
2200
  indentWidth = paraIndent && row.paraStart ? paraIndent : 0, wordsLength = row.words.length;
2109
- addWordWidth = (width && (textAlign === 'justify' || textAlign === 'both') && wordsLength > 1) ? (width - row.width - indentWidth) / (wordsLength - 1) : 0;
2110
- mode = (letterSpacing || row.isOverflow) ? CharMode : (addWordWidth > 0.01 ? WordMode : TextMode);
2111
- if (row.isOverflow && !letterSpacing)
2112
- row.textMode = true;
2201
+ addWordWidth = width && (textAlign === "justify" || textAlign === "both") && wordsLength > 1 ? (width - row.width - indentWidth) / (wordsLength - 1) : 0;
2202
+ mode = letterSpacing || row.isOverflow ? CharMode : addWordWidth > .01 ? WordMode : TextMode;
2203
+ if (row.isOverflow && !letterSpacing) row.textMode = true;
2113
2204
  if (mode === TextMode) {
2114
2205
  row.x += indentWidth;
2115
2206
  toTextChar$1(row);
2116
- }
2117
- else {
2207
+ } else {
2118
2208
  row.x += indentWidth;
2119
2209
  charX = row.x;
2120
2210
  row.data = [];
2121
2211
  row.words.forEach((word, index) => {
2122
2212
  if (mode === WordMode) {
2123
- wordChar = { char: '', x: charX };
2213
+ wordChar = {
2214
+ char: "",
2215
+ x: charX
2216
+ };
2124
2217
  charX = toWordChar(word.data, charX, wordChar);
2125
- if (row.isOverflow || wordChar.char !== ' ')
2126
- row.data.push(wordChar);
2127
- }
2128
- else {
2218
+ if (row.isOverflow || wordChar.char !== " ") row.data.push(wordChar);
2219
+ } else {
2129
2220
  charX = toChar(word.data, charX, row.data, row.isOverflow);
2130
2221
  }
2131
- if (addWordWidth && (!row.paraEnd || textAlign === 'both') && (index !== wordsLength - 1)) {
2222
+ if (addWordWidth && (!row.paraEnd || textAlign === "both") && index !== wordsLength - 1) {
2132
2223
  charX += addWordWidth;
2133
2224
  row.width += addWordWidth;
2134
2225
  }
@@ -2138,14 +2229,16 @@ function layoutChar(drawData, style, width, _height) {
2138
2229
  }
2139
2230
  });
2140
2231
  }
2232
+
2141
2233
  function toTextChar$1(row) {
2142
- row.text = '';
2234
+ row.text = "";
2143
2235
  row.words.forEach(word => {
2144
2236
  word.data.forEach(char => {
2145
2237
  row.text += char.char;
2146
2238
  });
2147
2239
  });
2148
2240
  }
2241
+
2149
2242
  function toWordChar(data, charX, wordChar) {
2150
2243
  data.forEach(char => {
2151
2244
  wordChar.char += char.char;
@@ -2153,9 +2246,10 @@ function toWordChar(data, charX, wordChar) {
2153
2246
  });
2154
2247
  return charX;
2155
2248
  }
2249
+
2156
2250
  function toChar(data, charX, rowData, isOverflow) {
2157
2251
  data.forEach(char => {
2158
- if (isOverflow || char.char !== ' ') {
2252
+ if (isOverflow || char.char !== " ") {
2159
2253
  char.x = charX;
2160
2254
  rowData.push(char);
2161
2255
  }
@@ -2165,38 +2259,39 @@ function toChar(data, charX, rowData, isOverflow) {
2165
2259
  }
2166
2260
 
2167
2261
  function layoutText(drawData, style) {
2168
- const { rows, bounds } = drawData, countRows = rows.length;
2169
- const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
2170
- let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
2262
+ const {rows: rows, bounds: bounds} = drawData, countRows = rows.length;
2263
+ const {__lineHeight: __lineHeight, __baseLine: __baseLine, __letterSpacing: __letterSpacing, __clipText: __clipText, textAlign: textAlign, verticalAlign: verticalAlign, paraSpacing: paraSpacing, autoSizeAlign: autoSizeAlign} = style;
2264
+ let {x: x, y: y, width: width, height: height} = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
2171
2265
  let starY = __baseLine;
2172
2266
  if (__clipText && realHeight > height) {
2173
2267
  realHeight = Math.max(height, __lineHeight);
2174
- if (countRows > 1)
2175
- drawData.overflow = countRows;
2176
- }
2177
- else if (height || autoSizeAlign) {
2268
+ if (countRows > 1) drawData.overflow = countRows;
2269
+ } else if (height || autoSizeAlign) {
2178
2270
  switch (verticalAlign) {
2179
- case 'middle':
2180
- y += (height - realHeight) / 2;
2181
- break;
2182
- case 'bottom': y += (height - realHeight);
2271
+ case "middle":
2272
+ y += (height - realHeight) / 2;
2273
+ break;
2274
+
2275
+ case "bottom":
2276
+ y += height - realHeight;
2183
2277
  }
2184
2278
  }
2185
2279
  starY += y;
2186
- let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
2280
+ let row, rowX, rowWidth, layoutWidth = width || autoSizeAlign ? width : drawData.maxWidth;
2187
2281
  for (let i = 0, len = countRows; i < len; i++) {
2188
2282
  row = rows[i];
2189
2283
  row.x = x;
2190
- if (row.width < width || (row.width > width && !__clipText)) {
2284
+ if (row.width < width || row.width > width && !__clipText) {
2191
2285
  switch (textAlign) {
2192
- case 'center':
2193
- row.x += (layoutWidth - row.width) / 2;
2194
- break;
2195
- case 'right': row.x += layoutWidth - row.width;
2286
+ case "center":
2287
+ row.x += (layoutWidth - row.width) / 2;
2288
+ break;
2289
+
2290
+ case "right":
2291
+ row.x += layoutWidth - row.width;
2196
2292
  }
2197
2293
  }
2198
- if (row.paraStart && paraSpacing && i > 0)
2199
- starY += paraSpacing;
2294
+ if (row.paraStart && paraSpacing && i > 0) starY += paraSpacing;
2200
2295
  row.y = starY;
2201
2296
  starY += __lineHeight;
2202
2297
  if (drawData.overflow > i && starY > realHeight) {
@@ -2210,19 +2305,15 @@ function layoutText(drawData, style) {
2210
2305
  rowWidth = -row.width + style.fontSize + __letterSpacing;
2211
2306
  rowX -= rowWidth;
2212
2307
  rowWidth += style.fontSize;
2213
- }
2214
- else {
2308
+ } else {
2215
2309
  rowWidth -= __letterSpacing;
2216
2310
  }
2217
2311
  }
2218
- if (rowX < bounds.x)
2219
- bounds.x = rowX;
2220
- if (rowWidth > bounds.width)
2221
- bounds.width = rowWidth;
2312
+ if (rowX < bounds.x) bounds.x = rowX;
2313
+ if (rowWidth > bounds.width) bounds.width = rowWidth;
2222
2314
  if (__clipText && width && width < rowWidth) {
2223
2315
  row.isOverflow = true;
2224
- if (!drawData.overflow)
2225
- drawData.overflow = rows.length;
2316
+ if (!drawData.overflow) drawData.overflow = rows.length;
2226
2317
  }
2227
2318
  }
2228
2319
  bounds.y = y;
@@ -2230,20 +2321,16 @@ function layoutText(drawData, style) {
2230
2321
  }
2231
2322
 
2232
2323
  function clipText(drawData, style, x, width) {
2233
- if (!width)
2234
- return;
2235
- const { rows, overflow } = drawData;
2236
- let { textOverflow } = style;
2324
+ if (!width) return;
2325
+ const {rows: rows, overflow: overflow} = drawData;
2326
+ let {textOverflow: textOverflow} = style;
2237
2327
  rows.splice(overflow);
2238
- if (textOverflow && textOverflow !== 'show') {
2239
- if (textOverflow === 'hide')
2240
- textOverflow = '';
2241
- else if (textOverflow === 'ellipsis')
2242
- textOverflow = '...';
2328
+ if (textOverflow && textOverflow !== "show") {
2329
+ if (textOverflow === "hide") textOverflow = ""; else if (textOverflow === "ellipsis") textOverflow = "...";
2243
2330
  let char, charRight;
2244
2331
  const ellipsisWidth = textOverflow ? Platform.canvas.measureText(textOverflow).width : 0;
2245
2332
  const right = x + width - ellipsisWidth;
2246
- const list = style.textWrap === 'none' ? rows : [rows[overflow - 1]];
2333
+ const list = style.textWrap === "none" ? rows : [ rows[overflow - 1] ];
2247
2334
  list.forEach(row => {
2248
2335
  if (row.isOverflow && row.data) {
2249
2336
  let end = row.data.length - 1;
@@ -2252,8 +2339,7 @@ function clipText(drawData, style, x, width) {
2252
2339
  charRight = char.x + char.width;
2253
2340
  if (i === end && charRight < right) {
2254
2341
  break;
2255
- }
2256
- else if ((charRight < right && char.char !== ' ') || !i) {
2342
+ } else if (charRight < right && char.char !== " " || !i) {
2257
2343
  row.data.splice(i + 1);
2258
2344
  row.width -= char.width;
2259
2345
  break;
@@ -2261,15 +2347,18 @@ function clipText(drawData, style, x, width) {
2261
2347
  row.width -= char.width;
2262
2348
  }
2263
2349
  row.width += ellipsisWidth;
2264
- row.data.push({ char: textOverflow, x: charRight });
2265
- if (row.textMode)
2266
- toTextChar(row);
2350
+ row.data.push({
2351
+ char: textOverflow,
2352
+ x: charRight
2353
+ });
2354
+ if (row.textMode) toTextChar(row);
2267
2355
  }
2268
2356
  });
2269
2357
  }
2270
2358
  }
2359
+
2271
2360
  function toTextChar(row) {
2272
- row.text = '';
2361
+ row.text = "";
2273
2362
  row.data.forEach(char => {
2274
2363
  row.text += char.char;
2275
2364
  });
@@ -2278,121 +2367,123 @@ function toTextChar(row) {
2278
2367
 
2279
2368
  function decorationText(drawData, style) {
2280
2369
  let type;
2281
- const { fontSize, textDecoration } = style;
2370
+ const {fontSize: fontSize, textDecoration: textDecoration} = style;
2282
2371
  drawData.decorationHeight = fontSize / 11;
2283
- if (typeof textDecoration === 'object') {
2372
+ if (isObject(textDecoration)) {
2284
2373
  type = textDecoration.type;
2285
- if (textDecoration.color)
2286
- drawData.decorationColor = ColorConvert.string(textDecoration.color);
2287
- }
2288
- else
2289
- type = textDecoration;
2374
+ if (textDecoration.color) drawData.decorationColor = ColorConvert.string(textDecoration.color);
2375
+ } else type = textDecoration;
2290
2376
  switch (type) {
2291
- case 'under':
2292
- drawData.decorationY = [fontSize * 0.15];
2293
- break;
2294
- case 'delete':
2295
- drawData.decorationY = [-fontSize * 0.35];
2296
- break;
2297
- case 'under-delete':
2298
- drawData.decorationY = [fontSize * 0.15, -fontSize * 0.35];
2377
+ case "under":
2378
+ drawData.decorationY = [ fontSize * .15 ];
2379
+ break;
2380
+
2381
+ case "delete":
2382
+ drawData.decorationY = [ -fontSize * .35 ];
2383
+ break;
2384
+
2385
+ case "under-delete":
2386
+ drawData.decorationY = [ fontSize * .15, -fontSize * .35 ];
2299
2387
  }
2300
2388
  }
2301
2389
 
2302
- const { top, right, bottom, left } = Direction4;
2390
+ const {top: top, right: right, bottom: bottom, left: left} = Direction4;
2391
+
2303
2392
  function getDrawData(content, style) {
2304
- if (typeof content !== 'string')
2305
- content = String(content);
2393
+ if (!isString(content)) content = String(content);
2306
2394
  let x = 0, y = 0;
2307
- let width = style.__getInput('width') || 0;
2308
- let height = style.__getInput('height') || 0;
2309
- const { textDecoration, __font, __padding: padding } = style;
2395
+ let width = style.__getInput("width") || 0;
2396
+ let height = style.__getInput("height") || 0;
2397
+ const {textDecoration: textDecoration, __font: __font, __padding: padding} = style;
2310
2398
  if (padding) {
2311
- if (width)
2312
- x = padding[left], width -= (padding[right] + padding[left]);
2313
- else if (!style.autoSizeAlign)
2314
- x = padding[left];
2315
- if (height)
2316
- y = padding[top], height -= (padding[top] + padding[bottom]);
2317
- else if (!style.autoSizeAlign)
2318
- y = padding[top];
2399
+ if (width) x = padding[left], width -= padding[right] + padding[left]; else if (!style.autoSizeAlign) x = padding[left];
2400
+ if (height) y = padding[top], height -= padding[top] + padding[bottom]; else if (!style.autoSizeAlign) y = padding[top];
2319
2401
  }
2320
2402
  const drawData = {
2321
- bounds: { x, y, width, height },
2403
+ bounds: {
2404
+ x: x,
2405
+ y: y,
2406
+ width: width,
2407
+ height: height
2408
+ },
2322
2409
  rows: [],
2323
2410
  paraNumber: 0,
2324
2411
  font: Platform.canvas.font = __font
2325
2412
  };
2326
2413
  createRows(drawData, content, style);
2327
- if (padding)
2328
- padAutoText(padding, drawData, style, width, height);
2414
+ if (padding) padAutoText(padding, drawData, style, width, height);
2329
2415
  layoutText(drawData, style);
2330
2416
  layoutChar(drawData, style, width);
2331
- if (drawData.overflow)
2332
- clipText(drawData, style, x, width);
2333
- if (textDecoration !== 'none')
2334
- decorationText(drawData, style);
2417
+ if (drawData.overflow) clipText(drawData, style, x, width);
2418
+ if (textDecoration !== "none") decorationText(drawData, style);
2335
2419
  return drawData;
2336
2420
  }
2421
+
2337
2422
  function padAutoText(padding, drawData, style, width, height) {
2338
2423
  if (!width && style.autoSizeAlign) {
2339
2424
  switch (style.textAlign) {
2340
- case 'left':
2341
- offsetText(drawData, 'x', padding[left]);
2342
- break;
2343
- case 'right': offsetText(drawData, 'x', -padding[right]);
2425
+ case "left":
2426
+ offsetText(drawData, "x", padding[left]);
2427
+ break;
2428
+
2429
+ case "right":
2430
+ offsetText(drawData, "x", -padding[right]);
2344
2431
  }
2345
2432
  }
2346
2433
  if (!height && style.autoSizeAlign) {
2347
2434
  switch (style.verticalAlign) {
2348
- case 'top':
2349
- offsetText(drawData, 'y', padding[top]);
2350
- break;
2351
- case 'bottom': offsetText(drawData, 'y', -padding[bottom]);
2435
+ case "top":
2436
+ offsetText(drawData, "y", padding[top]);
2437
+ break;
2438
+
2439
+ case "bottom":
2440
+ offsetText(drawData, "y", -padding[bottom]);
2352
2441
  }
2353
2442
  }
2354
2443
  }
2444
+
2355
2445
  function offsetText(drawData, attrName, value) {
2356
- const { bounds, rows } = drawData;
2446
+ const {bounds: bounds, rows: rows} = drawData;
2357
2447
  bounds[attrName] += value;
2358
- for (let i = 0; i < rows.length; i++)
2359
- rows[i][attrName] += value;
2448
+ for (let i = 0; i < rows.length; i++) rows[i][attrName] += value;
2360
2449
  }
2361
2450
 
2362
2451
  const TextConvertModule = {
2363
- getDrawData
2452
+ getDrawData: getDrawData
2364
2453
  };
2365
2454
 
2366
2455
  function string(color, opacity) {
2367
- const doOpacity = typeof opacity === 'number' && opacity !== 1;
2368
- if (typeof color === 'string') {
2369
- if (doOpacity && ColorConvert.object)
2370
- color = ColorConvert.object(color);
2371
- else
2372
- return color;
2456
+ const doOpacity = isNumber(opacity) && opacity < 1;
2457
+ if (isString(color)) {
2458
+ if (doOpacity && ColorConvert.object) color = ColorConvert.object(color); else return color;
2373
2459
  }
2374
- let a = color.a === undefined ? 1 : color.a;
2375
- if (doOpacity)
2376
- a *= opacity;
2377
- const rgb = color.r + ',' + color.g + ',' + color.b;
2378
- return a === 1 ? 'rgb(' + rgb + ')' : 'rgba(' + rgb + ',' + a + ')';
2460
+ let a = isUndefined(color.a) ? 1 : color.a;
2461
+ if (doOpacity) a *= opacity;
2462
+ const rgb = color.r + "," + color.g + "," + color.b;
2463
+ return a === 1 ? "rgb(" + rgb + ")" : "rgba(" + rgb + "," + a + ")";
2379
2464
  }
2380
2465
 
2381
2466
  const ColorConvertModule = {
2382
- string
2467
+ string: string
2383
2468
  };
2384
2469
 
2385
2470
  Object.assign(TextConvert, TextConvertModule);
2471
+
2386
2472
  Object.assign(ColorConvert, ColorConvertModule);
2473
+
2387
2474
  Object.assign(Paint, PaintModule);
2475
+
2388
2476
  Object.assign(PaintImage, PaintImageModule);
2477
+
2389
2478
  Object.assign(PaintGradient, PaintGradientModule);
2479
+
2390
2480
  Object.assign(Effect, EffectModule);
2391
2481
 
2392
- const { setPoint, addPoint, toBounds } = TwoPointBoundsHelper;
2482
+ const {setPoint: setPoint, addPoint: addPoint, toBounds: toBounds} = TwoPointBoundsHelper;
2483
+
2393
2484
  function getTrimBounds(canvas) {
2394
- const { width, height } = canvas.view;
2395
- const { data } = canvas.context.getImageData(0, 0, width, height);
2485
+ const {width: width, height: height} = canvas.view;
2486
+ const {data: data} = canvas.context.getImageData(0, 0, width, height);
2396
2487
  let x, y, pointBounds, index = 0;
2397
2488
  for (let i = 0; i < data.length; i += 4) {
2398
2489
  if (data[i + 3] !== 0) {
@@ -2402,7 +2493,7 @@ function getTrimBounds(canvas) {
2402
2493
  }
2403
2494
  index++;
2404
2495
  }
2405
- const bounds = new Bounds$1();
2496
+ const bounds = new Bounds$1;
2406
2497
  if (pointBounds) {
2407
2498
  toBounds(pointBounds, bounds);
2408
2499
  bounds.scale(1 / canvas.pixelRatio).ceil();
@@ -2416,64 +2507,80 @@ const ExportModule = {
2416
2507
  let result;
2417
2508
  try {
2418
2509
  const fileType = FileHelper$1.fileType(filename);
2419
- const isDownload = filename.includes('.');
2510
+ const isDownload = filename.includes(".");
2420
2511
  options = FileHelper$1.getExportOptions(options);
2421
- const { toURL } = Platform$1;
2422
- const { download } = Platform$1.origin;
2423
- if (fileType === 'json') {
2424
- isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), 'text'), filename);
2425
- result = { data: isDownload ? true : leaf.toJSON(options.json) };
2426
- }
2427
- else if (fileType === 'svg') {
2428
- isDownload && download(toURL(leaf.toSVG(), 'svg'), filename);
2429
- result = { data: isDownload ? true : leaf.toSVG() };
2430
- }
2431
- else {
2512
+ const {toURL: toURL} = Platform$1;
2513
+ const {download: download} = Platform$1.origin;
2514
+ if (fileType === "json") {
2515
+ isDownload && download(toURL(JSON.stringify(leaf.toJSON(options.json)), "text"), filename);
2516
+ result = {
2517
+ data: isDownload ? true : leaf.toJSON(options.json)
2518
+ };
2519
+ } else if (fileType === "svg") {
2520
+ isDownload && download(toURL(leaf.toSVG(), "svg"), filename);
2521
+ result = {
2522
+ data: isDownload ? true : leaf.toSVG()
2523
+ };
2524
+ } else {
2432
2525
  let renderBounds, trimBounds, scaleX = 1, scaleY = 1;
2433
- const { worldTransform, isLeafer, leafer, isFrame } = leaf;
2434
- const { slice, clip, trim, screenshot, padding, onCanvas } = options;
2435
- const smooth = options.smooth === undefined ? (leafer ? leafer.config.smooth : true) : options.smooth;
2526
+ const {worldTransform: worldTransform, isLeafer: isLeafer, leafer: leafer, isFrame: isFrame} = leaf;
2527
+ const {slice: slice, clip: clip, trim: trim, screenshot: screenshot, padding: padding, onCanvas: onCanvas} = options;
2528
+ const smooth = isUndefined$1(options.smooth) ? leafer ? leafer.config.smooth : true : options.smooth;
2436
2529
  const contextSettings = options.contextSettings || (leafer ? leafer.config.contextSettings : undefined);
2437
- const fill = (isLeafer && screenshot) ? (options.fill === undefined ? leaf.fill : options.fill) : options.fill;
2438
- const needFill = FileHelper$1.isOpaqueImage(filename) || fill, matrix = new Matrix();
2530
+ const fill = isLeafer && screenshot ? isUndefined$1(options.fill) ? leaf.fill : options.fill : options.fill;
2531
+ const needFill = FileHelper$1.isOpaqueImage(filename) || fill, matrix = new Matrix$1;
2439
2532
  if (screenshot) {
2440
- renderBounds = screenshot === true ? (isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds) : screenshot;
2441
- }
2442
- else {
2443
- let relative = options.relative || (isLeafer ? 'inner' : 'local');
2533
+ renderBounds = screenshot === true ? isLeafer ? leafer.canvas.bounds : leaf.worldRenderBounds : screenshot;
2534
+ } else {
2535
+ let relative = options.relative || (isLeafer ? "inner" : "local");
2444
2536
  scaleX = worldTransform.scaleX;
2445
2537
  scaleY = worldTransform.scaleY;
2446
2538
  switch (relative) {
2447
- case 'inner':
2448
- matrix.set(worldTransform);
2449
- break;
2450
- case 'local':
2451
- matrix.set(worldTransform).divide(leaf.localTransform);
2452
- scaleX /= leaf.scaleX;
2453
- scaleY /= leaf.scaleY;
2454
- break;
2455
- case 'world':
2456
- scaleX = 1;
2457
- scaleY = 1;
2458
- break;
2459
- case 'page':
2460
- relative = leafer || leaf;
2461
- default:
2462
- matrix.set(worldTransform).divide(leaf.getTransform(relative));
2463
- const l = relative.worldTransform;
2464
- scaleX /= scaleX / l.scaleX;
2465
- scaleY /= scaleY / l.scaleY;
2539
+ case "inner":
2540
+ matrix.set(worldTransform);
2541
+ break;
2542
+
2543
+ case "local":
2544
+ matrix.set(worldTransform).divide(leaf.localTransform);
2545
+ scaleX /= leaf.scaleX;
2546
+ scaleY /= leaf.scaleY;
2547
+ break;
2548
+
2549
+ case "world":
2550
+ scaleX = 1;
2551
+ scaleY = 1;
2552
+ break;
2553
+
2554
+ case "page":
2555
+ relative = leafer || leaf;
2556
+
2557
+ default:
2558
+ matrix.set(worldTransform).divide(leaf.getTransform(relative));
2559
+ const l = relative.worldTransform;
2560
+ scaleX /= scaleX / l.scaleX;
2561
+ scaleY /= scaleY / l.scaleY;
2466
2562
  }
2467
- renderBounds = leaf.getBounds('render', relative);
2563
+ renderBounds = leaf.getBounds("render", relative);
2468
2564
  }
2469
- const scaleData = { scaleX: 1, scaleY: 1 };
2565
+ const scaleData = {
2566
+ scaleX: 1,
2567
+ scaleY: 1
2568
+ };
2470
2569
  MathHelper$1.getScaleData(options.scale, options.size, renderBounds, scaleData);
2471
2570
  let pixelRatio = options.pixelRatio || 1;
2472
- let { x, y, width, height } = new Bounds$1(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
2473
- if (clip)
2474
- x += clip.x, y += clip.y, width = clip.width, height = clip.height;
2475
- 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) };
2476
- let canvas = Creator$1.canvas({ width: Math.floor(width), height: Math.floor(height), pixelRatio, smooth, contextSettings });
2571
+ let {x: x, y: y, width: width, height: height} = new Bounds$1(renderBounds).scale(scaleData.scaleX, scaleData.scaleY);
2572
+ if (clip) x += clip.x, y += clip.y, width = clip.width, height = clip.height;
2573
+ const renderOptions = {
2574
+ exporting: true,
2575
+ matrix: matrix.scale(1 / scaleData.scaleX, 1 / scaleData.scaleY).invert().translate(-x, -y).withScale(1 / scaleX * scaleData.scaleX, 1 / scaleY * scaleData.scaleY)
2576
+ };
2577
+ let canvas = Creator$1.canvas({
2578
+ width: Math.floor(width),
2579
+ height: Math.floor(height),
2580
+ pixelRatio: pixelRatio,
2581
+ smooth: smooth,
2582
+ contextSettings: contextSettings
2583
+ });
2477
2584
  let sliceLeaf;
2478
2585
  if (slice) {
2479
2586
  sliceLeaf = leaf;
@@ -2482,130 +2589,153 @@ const ExportModule = {
2482
2589
  renderOptions.bounds = canvas.bounds;
2483
2590
  }
2484
2591
  canvas.save();
2485
- if (isFrame && fill !== undefined) {
2486
- const oldFill = leaf.get('fill');
2487
- leaf.fill = '';
2592
+ if (isFrame && !isUndefined$1(fill)) {
2593
+ const oldFill = leaf.get("fill");
2594
+ leaf.fill = "";
2488
2595
  leaf.__render(canvas, renderOptions);
2489
2596
  leaf.fill = oldFill;
2490
- }
2491
- else {
2597
+ } else {
2492
2598
  leaf.__render(canvas, renderOptions);
2493
2599
  }
2494
2600
  canvas.restore();
2495
- if (sliceLeaf)
2496
- sliceLeaf.__updateWorldOpacity();
2601
+ if (sliceLeaf) sliceLeaf.__updateWorldOpacity();
2497
2602
  if (trim) {
2498
2603
  trimBounds = getTrimBounds(canvas);
2499
- const old = canvas, { width, height } = trimBounds;
2500
- const config = { x: 0, y: 0, width, height, pixelRatio };
2604
+ const old = canvas, {width: width, height: height} = trimBounds;
2605
+ const config = {
2606
+ x: 0,
2607
+ y: 0,
2608
+ width: width,
2609
+ height: height,
2610
+ pixelRatio: pixelRatio
2611
+ };
2501
2612
  canvas = Creator$1.canvas(config);
2502
2613
  canvas.copyWorld(old, trimBounds, config);
2614
+ old.destroy();
2503
2615
  }
2504
2616
  if (padding) {
2505
2617
  const [top, right, bottom, left] = MathHelper$1.fourNumber(padding);
2506
- const old = canvas, { width, height } = old;
2507
- canvas = Creator$1.canvas({ width: width + left + right, height: height + top + bottom, pixelRatio });
2508
- canvas.copyWorld(old, old.bounds, { x: left, y: top, width, height });
2618
+ const old = canvas, {width: width, height: height} = old;
2619
+ canvas = Creator$1.canvas({
2620
+ width: width + left + right,
2621
+ height: height + top + bottom,
2622
+ pixelRatio: pixelRatio
2623
+ });
2624
+ canvas.copyWorld(old, old.bounds, {
2625
+ x: left,
2626
+ y: top,
2627
+ width: width,
2628
+ height: height
2629
+ });
2630
+ old.destroy();
2509
2631
  }
2510
- if (needFill)
2511
- canvas.fillWorld(canvas.bounds, fill || '#FFFFFF', 'destination-over');
2512
- if (onCanvas)
2513
- onCanvas(canvas);
2514
- const data = filename === 'canvas' ? canvas : canvas.export(filename, options);
2515
- result = { data, width: canvas.pixelWidth, height: canvas.pixelHeight, renderBounds, trimBounds };
2632
+ if (needFill) canvas.fillWorld(canvas.bounds, fill || "#FFFFFF", "destination-over");
2633
+ if (onCanvas) onCanvas(canvas);
2634
+ const data = filename === "canvas" ? canvas : canvas.export(filename, options);
2635
+ result = {
2636
+ data: data,
2637
+ width: canvas.pixelWidth,
2638
+ height: canvas.pixelHeight,
2639
+ renderBounds: renderBounds,
2640
+ trimBounds: trimBounds
2641
+ };
2516
2642
  }
2517
- }
2518
- catch (error) {
2519
- result = { data: '', error };
2643
+ } catch (error) {
2644
+ result = {
2645
+ data: "",
2646
+ error: error
2647
+ };
2520
2648
  }
2521
2649
  Export.running = false;
2522
2650
  return result;
2523
2651
  },
2524
2652
  export(leaf, filename, options) {
2525
2653
  Export.running = true;
2526
- return addTask((success) => new Promise((resolve) => {
2527
- const getResult = () => __awaiter(this, void 0, void 0, function* () {
2528
- if (!Resource.isComplete)
2529
- return Platform$1.requestRender(getResult);
2654
+ return addTask(success => new Promise(resolve => {
2655
+ const getResult = () => __awaiter(this, void 0, void 0, function*() {
2656
+ if (!Resource.isComplete) return Platform$1.requestRender(getResult);
2530
2657
  const result = Export.syncExport(leaf, filename, options);
2531
- if (result.data instanceof Promise)
2532
- result.data = yield result.data;
2658
+ if (result.data instanceof Promise) result.data = yield result.data;
2533
2659
  success(result);
2534
2660
  resolve();
2535
2661
  });
2536
2662
  leaf.updateLayout();
2537
2663
  checkLazy(leaf);
2538
- const { leafer } = leaf;
2539
- if (leafer)
2540
- leafer.waitViewCompleted(getResult);
2541
- else
2542
- getResult();
2664
+ const {leafer: leafer} = leaf;
2665
+ if (leafer) leafer.waitViewCompleted(getResult); else getResult();
2543
2666
  }));
2544
2667
  }
2545
2668
  };
2669
+
2546
2670
  let tasker;
2671
+
2547
2672
  function addTask(task) {
2548
- if (!tasker)
2549
- tasker = new TaskProcessor();
2550
- return new Promise((resolve) => {
2551
- tasker.add(() => __awaiter(this, void 0, void 0, function* () { return yield task(resolve); }), { parallel: false });
2673
+ if (!tasker) tasker = new TaskProcessor;
2674
+ return new Promise(resolve => {
2675
+ tasker.add(() => __awaiter(this, void 0, void 0, function*() {
2676
+ return yield task(resolve);
2677
+ }), {
2678
+ parallel: false
2679
+ });
2552
2680
  });
2553
2681
  }
2682
+
2554
2683
  function checkLazy(leaf) {
2555
- if (leaf.__.__needComputePaint)
2556
- leaf.__.__computePaint();
2557
- if (leaf.isBranch)
2558
- leaf.children.forEach(child => checkLazy(child));
2684
+ if (leaf.__.__needComputePaint) leaf.__.__computePaint();
2685
+ if (leaf.isBranch) leaf.children.forEach(child => checkLazy(child));
2559
2686
  }
2560
2687
 
2561
2688
  const canvas = LeaferCanvasBase$1.prototype;
2562
- const debug = Debug$1.get('@leafer-in/export');
2563
- canvas.export = function (filename, options) {
2564
- const { quality, blob } = FileHelper$1.getExportOptions(options);
2565
- if (filename.includes('.'))
2566
- return this.saveAs(filename, quality);
2567
- else if (blob)
2568
- return this.toBlob(filename, quality);
2569
- else
2570
- return this.toDataURL(filename, quality);
2689
+
2690
+ const debug = Debug$1.get("@leafer-in/export");
2691
+
2692
+ canvas.export = function(filename, options) {
2693
+ const {quality: quality, blob: blob} = FileHelper$1.getExportOptions(options);
2694
+ if (filename.includes(".")) return this.saveAs(filename, quality); else if (blob) return this.toBlob(filename, quality); else return this.toDataURL(filename, quality);
2571
2695
  };
2572
- canvas.toBlob = function (type, quality) {
2573
- return new Promise((resolve) => {
2574
- Platform$1.origin.canvasToBolb(this.view, type, quality).then((blob) => {
2696
+
2697
+ canvas.toBlob = function(type, quality) {
2698
+ return new Promise(resolve => {
2699
+ Platform$1.origin.canvasToBolb(this.view, type, quality).then(blob => {
2575
2700
  resolve(blob);
2576
- }).catch((e) => {
2701
+ }).catch(e => {
2577
2702
  debug.error(e);
2578
2703
  resolve(null);
2579
2704
  });
2580
2705
  });
2581
2706
  };
2582
- canvas.toDataURL = function (type, quality) {
2707
+
2708
+ canvas.toDataURL = function(type, quality) {
2583
2709
  return Platform$1.origin.canvasToDataURL(this.view, type, quality);
2584
2710
  };
2585
- canvas.saveAs = function (filename, quality) {
2586
- return new Promise((resolve) => {
2711
+
2712
+ canvas.saveAs = function(filename, quality) {
2713
+ return new Promise(resolve => {
2587
2714
  Platform$1.origin.canvasSaveAs(this.view, filename, quality).then(() => {
2588
2715
  resolve(true);
2589
- }).catch((e) => {
2716
+ }).catch(e => {
2590
2717
  debug.error(e);
2591
2718
  resolve(false);
2592
2719
  });
2593
2720
  });
2594
2721
  };
2595
2722
 
2596
- Plugin$1.add('export');
2723
+ Plugin$1.add("export");
2724
+
2597
2725
  Object.assign(Export, ExportModule);
2598
- UI.prototype.export = function (filename, options) {
2726
+
2727
+ UI.prototype.export = function(filename, options) {
2599
2728
  return Export.export(this, filename, options);
2600
2729
  };
2601
- UI.prototype.syncExport = function (filename, options) {
2730
+
2731
+ UI.prototype.syncExport = function(filename, options) {
2602
2732
  return Export.syncExport(this, filename, options);
2603
2733
  };
2604
2734
 
2605
2735
  Object.assign(Creator, {
2606
- interaction: (target, canvas, selector, options) => { return new InteractionBase(target, canvas, selector, options); },
2736
+ interaction: (target, canvas, selector, options) => new InteractionBase(target, canvas, selector, options),
2607
2737
  hitCanvas: (options, manager) => new LeaferCanvas(options, manager),
2608
- hitCanvasManager: () => new HitCanvasManager()
2738
+ hitCanvasManager: () => new HitCanvasManager
2609
2739
  });
2610
2740
 
2611
2741
  export { Layouter, LeaferCanvas, Picker, Renderer, Selector, Watcher, useCanvas };