@leafer-draw/node 1.8.0 → 1.9.0

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