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