@leafer-ui/miniapp 1.8.0 → 1.9.1

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