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