leafer-ui 1.8.0 → 1.9.0

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