@leafer-ui/node 1.7.0 → 1.9.0

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