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