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