leafer-ui 1.8.0 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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,27 @@ 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
- 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;
1524
- if (current.bounds.includes(nowWorld)) {
1545
+ const nowWorld = ui.__nowWorld, currentBounds = current.bounds;
1546
+ let bounds, matrix, fitMatrix, shapeBounds, worldCanvas;
1547
+ let {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true);
1548
+ if (currentBounds.includes(nowWorld)) {
1525
1549
  worldCanvas = canvas;
1526
1550
  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);
1531
- fitMatrix = current.bounds.getFitMatrix(worldClipBounds);
1532
- let { a: fitScaleX, d: fitScaleY } = fitMatrix;
1551
+ } else {
1552
+ const {renderShapeSpread: spread} = ui.__layout;
1553
+ let worldClipBounds;
1554
+ if (Platform.fullImageShadow) {
1555
+ worldClipBounds = nowWorld;
1556
+ } else {
1557
+ const spreadBounds = spread ? getSpread(currentBounds, scaleX === scaleY ? spread * scaleX : [ spread * scaleY, spread * scaleX ]) : currentBounds;
1558
+ worldClipBounds = getIntersectData(spreadBounds, nowWorld);
1559
+ }
1560
+ fitMatrix = currentBounds.getFitMatrix(worldClipBounds);
1561
+ let {a: fitScaleX, d: fitScaleY} = fitMatrix;
1533
1562
  if (fitMatrix.a < 1) {
1534
1563
  worldCanvas = current.getSameCanvas();
1535
1564
  ui.__renderShape(worldCanvas, options);
@@ -1538,28 +1567,39 @@ function shape(ui, current, options) {
1538
1567
  }
1539
1568
  shapeBounds = getOuterOf(nowWorld, fitMatrix);
1540
1569
  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) });
1570
+ const userMatrix = options.matrix;
1571
+ if (userMatrix) {
1572
+ matrix = new Matrix(fitMatrix);
1573
+ matrix.multiply(userMatrix);
1574
+ fitScaleX *= userMatrix.scaleX;
1575
+ fitScaleY *= userMatrix.scaleY;
1576
+ } else matrix = fitMatrix;
1577
+ matrix.withScale(fitScaleX, fitScaleY);
1578
+ options = Object.assign(Object.assign({}, options), {
1579
+ matrix: matrix
1580
+ });
1548
1581
  }
1549
1582
  ui.__renderShape(canvas, options);
1550
1583
  return {
1551
- canvas, matrix: fitMatrix, bounds,
1552
- worldCanvas, shapeBounds, scaleX, scaleY
1584
+ canvas: canvas,
1585
+ matrix: matrix,
1586
+ fitMatrix: fitMatrix,
1587
+ bounds: bounds,
1588
+ worldCanvas: worldCanvas,
1589
+ shapeBounds: shapeBounds,
1590
+ scaleX: scaleX,
1591
+ scaleY: scaleY
1553
1592
  };
1554
1593
  }
1555
1594
 
1556
1595
  let recycleMap;
1557
- const { stintSet } = DataHelper, { hasTransparent: hasTransparent$1 } = ColorConvert;
1596
+
1597
+ const {stintSet: stintSet} = DataHelper, {hasTransparent: hasTransparent$1} = ColorConvert;
1598
+
1558
1599
  function compute(attrName, ui) {
1559
1600
  const data = ui.__, leafPaints = [];
1560
1601
  let paints = data.__input[attrName], isAlphaPixel, isTransparent;
1561
- if (!(paints instanceof Array))
1562
- paints = [paints];
1602
+ if (!isArray(paints)) paints = [ paints ];
1563
1603
  recycleMap = PaintImage.recycleImage(attrName, data);
1564
1604
  let maxChildStrokeWidth;
1565
1605
  for (let i = 0, len = paints.length, item; i < len; i++) {
@@ -1567,206 +1607,222 @@ function compute(attrName, ui) {
1567
1607
  leafPaints.push(item);
1568
1608
  if (item.strokeStyle) {
1569
1609
  maxChildStrokeWidth || (maxChildStrokeWidth = 1);
1570
- if (item.strokeStyle.strokeWidth)
1571
- maxChildStrokeWidth = Math.max(maxChildStrokeWidth, item.strokeStyle.strokeWidth);
1610
+ if (item.strokeStyle.strokeWidth) maxChildStrokeWidth = Math.max(maxChildStrokeWidth, item.strokeStyle.strokeWidth);
1572
1611
  }
1573
1612
  }
1574
1613
  }
1575
- data['_' + attrName] = leafPaints.length ? leafPaints : undefined;
1614
+ data["_" + attrName] = leafPaints.length ? leafPaints : undefined;
1576
1615
  if (leafPaints.length) {
1577
1616
  if (leafPaints.every(item => item.isTransparent)) {
1578
- if (leafPaints.some(item => item.image))
1579
- isAlphaPixel = true;
1617
+ if (leafPaints.some(item => item.image)) isAlphaPixel = true;
1580
1618
  isTransparent = true;
1581
1619
  }
1582
1620
  }
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);
1621
+ if (attrName === "fill") {
1622
+ stintSet(data, "__isAlphaPixelFill", isAlphaPixel);
1623
+ stintSet(data, "__isTransparentFill", isTransparent);
1624
+ } else {
1625
+ stintSet(data, "__isAlphaPixelStroke", isAlphaPixel);
1626
+ stintSet(data, "__isTransparentStroke", isTransparent);
1627
+ stintSet(data, "__hasMultiStrokeStyle", maxChildStrokeWidth);
1591
1628
  }
1592
1629
  }
1630
+
1593
1631
  function getLeafPaint(attrName, paint, ui) {
1594
- if (typeof paint !== 'object' || paint.visible === false || paint.opacity === 0)
1595
- return undefined;
1632
+ if (!isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
1596
1633
  let data;
1597
- const { boxBounds } = ui.__layout;
1634
+ const {boxBounds: boxBounds} = ui.__layout;
1598
1635
  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) };
1636
+ case "image":
1637
+ data = PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
1638
+ break;
1639
+
1640
+ case "linear":
1641
+ data = PaintGradient.linearGradient(paint, boxBounds);
1642
+ break;
1643
+
1644
+ case "radial":
1645
+ data = PaintGradient.radialGradient(paint, boxBounds);
1646
+ break;
1647
+
1648
+ case "angular":
1649
+ data = PaintGradient.conicGradient(paint, boxBounds);
1650
+ break;
1651
+
1652
+ case "solid":
1653
+ const {type: type, color: color, opacity: opacity} = paint;
1654
+ data = {
1655
+ type: type,
1656
+ style: ColorConvert.string(color, opacity)
1657
+ };
1658
+ break;
1659
+
1660
+ default:
1661
+ if (!isUndefined(paint.r)) data = {
1662
+ type: "solid",
1663
+ style: ColorConvert.string(paint)
1664
+ };
1618
1665
  }
1619
1666
  if (data) {
1620
- if (typeof data.style === 'string' && hasTransparent$1(data.style))
1621
- data.isTransparent = true;
1667
+ if (isString(data.style) && hasTransparent$1(data.style)) data.isTransparent = true;
1622
1668
  if (paint.style) {
1623
- if (paint.style.strokeWidth === 0)
1624
- return undefined;
1669
+ if (paint.style.strokeWidth === 0) return undefined;
1625
1670
  data.strokeStyle = paint.style;
1626
1671
  }
1627
- if (paint.blendMode)
1628
- data.blendMode = paint.blendMode;
1672
+ if (paint.editing) data.editing = paint.editing;
1673
+ if (paint.blendMode) data.blendMode = paint.blendMode;
1629
1674
  }
1630
1675
  return data;
1631
1676
  }
1632
1677
 
1633
1678
  const PaintModule = {
1634
- compute,
1635
- fill,
1636
- fills,
1637
- fillPathOrText,
1638
- fillText,
1639
- stroke,
1640
- strokes,
1641
- strokeText,
1642
- drawTextStroke,
1643
- shape
1679
+ compute: compute,
1680
+ fill: fill,
1681
+ fills: fills,
1682
+ fillPathOrText: fillPathOrText,
1683
+ fillText: fillText,
1684
+ stroke: stroke,
1685
+ strokes: strokes,
1686
+ strokeText: strokeText,
1687
+ drawTextStroke: drawTextStroke,
1688
+ shape: shape
1644
1689
  };
1645
1690
 
1646
1691
  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;
1692
+
1693
+ const {get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, multiplyParent: multiplyParent, scale: scaleHelper, rotate: rotate, skew: skewHelper} = MatrixHelper;
1694
+
1648
1695
  function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
1649
1696
  const transform = get$3();
1650
1697
  translate$1(transform, box.x + x, box.y + y);
1651
1698
  scaleHelper(transform, scaleX, scaleY);
1652
- if (rotation)
1653
- rotateOfOuter$1(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
1699
+ if (rotation) rotateOfOuter$1(transform, {
1700
+ x: box.x + box.width / 2,
1701
+ y: box.y + box.height / 2
1702
+ }, rotation);
1654
1703
  data.transform = transform;
1655
1704
  }
1705
+
1656
1706
  function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipSize) {
1657
1707
  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);
1708
+ layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
1665
1709
  if (clipSize) {
1666
1710
  tempMatrix.a = box.width / clipSize.width, tempMatrix.d = box.height / clipSize.height;
1667
1711
  multiplyParent(transform, tempMatrix);
1668
1712
  }
1669
1713
  data.transform = transform;
1670
1714
  }
1671
- function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align) {
1715
+
1716
+ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, skew, align, freeTransform) {
1672
1717
  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:
1718
+ if (freeTransform) {
1719
+ layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
1720
+ } else {
1721
+ if (rotation) {
1722
+ if (align === "center") {
1723
+ rotateOfOuter$1(transform, {
1724
+ x: width / 2,
1725
+ y: height / 2
1726
+ }, rotation);
1727
+ } else {
1728
+ rotate(transform, rotation);
1729
+ switch (rotation) {
1730
+ case 90:
1681
1731
  translate$1(transform, height, 0);
1682
1732
  break;
1683
- case 180:
1733
+
1734
+ case 180:
1684
1735
  translate$1(transform, width, height);
1685
1736
  break;
1686
- case 270:
1737
+
1738
+ case 270:
1687
1739
  translate$1(transform, 0, width);
1688
1740
  break;
1741
+ }
1689
1742
  }
1690
1743
  }
1744
+ origin.x = box.x + x;
1745
+ origin.y = box.y + y;
1746
+ translate$1(transform, origin.x, origin.y);
1747
+ if (scaleX) scaleOfOuter$1(transform, origin, scaleX, scaleY);
1691
1748
  }
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
1749
  data.transform = transform;
1698
1750
  }
1699
1751
 
1700
- const { get: get$2, translate } = MatrixHelper;
1701
- const tempBox = new Bounds();
1752
+ function layout(transform, box, x, y, scaleX, scaleY, rotation, skew) {
1753
+ if (rotation) rotate(transform, rotation);
1754
+ if (skew) skewHelper(transform, skew.x, skew.y);
1755
+ if (scaleX) scaleHelper(transform, scaleX, scaleY);
1756
+ translate$1(transform, box.x + x, box.y + y);
1757
+ }
1758
+
1759
+ const {get: get$2, translate: translate} = MatrixHelper;
1760
+
1761
+ const tempBox = new Bounds;
1762
+
1702
1763
  const tempScaleData = {};
1764
+
1703
1765
  const tempImage = {};
1766
+
1704
1767
  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;
1768
+ const {changeful: changeful, sync: sync, scaleFixed: scaleFixed} = paint;
1769
+ if (changeful) leafPaint.changeful = changeful;
1770
+ if (sync) leafPaint.sync = sync;
1771
+ if (scaleFixed) leafPaint.scaleFixed = scaleFixed;
1714
1772
  leafPaint.data = getPatternData(paint, box, image);
1715
1773
  }
1774
+
1716
1775
  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;
1776
+ if (paint.padding) box = tempBox.set(box).shrink(paint.padding);
1777
+ if (paint.mode === "strench") paint.mode = "stretch";
1778
+ let {width: width, height: height} = image;
1779
+ 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
1780
  const sameBox = box.width === width && box.height === height;
1724
- const data = { mode };
1725
- const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
1781
+ const data = {
1782
+ mode: mode
1783
+ };
1784
+ const swapSize = align !== "center" && (rotation || 0) % 180 === 90;
1726
1785
  BoundsHelper.set(tempImage, 0, 0, swapSize ? height : width, swapSize ? width : height);
1727
1786
  let scaleX, scaleY;
1728
- if (!mode || mode === 'cover' || mode === 'fit') {
1787
+ if (!mode || mode === "cover" || mode === "fit") {
1729
1788
  if (!sameBox || rotation) {
1730
- scaleX = scaleY = BoundsHelper.getFitScale(box, tempImage, mode !== 'fit');
1789
+ scaleX = scaleY = BoundsHelper.getFitScale(box, tempImage, mode !== "fit");
1731
1790
  BoundsHelper.put(box, image, align, scaleX, false, tempImage);
1732
1791
  BoundsHelper.scale(tempImage, scaleX, scaleY, true);
1733
1792
  }
1734
- }
1735
- else {
1793
+ } else {
1736
1794
  if (scale || size) {
1737
1795
  MathHelper.getScaleData(scale, size, image, tempScaleData);
1738
1796
  scaleX = tempScaleData.scaleX;
1739
1797
  scaleY = tempScaleData.scaleY;
1740
1798
  }
1741
- if (align) {
1742
- if (scaleX)
1743
- BoundsHelper.scale(tempImage, scaleX, scaleY, true);
1744
- AlignHelper.toPoint(align, tempImage, box, tempImage, true, true);
1799
+ if (align || gap || repeat) {
1800
+ if (scaleX) BoundsHelper.scale(tempImage, scaleX, scaleY, true);
1801
+ if (align) AlignHelper.toPoint(align, tempImage, box, tempImage, true, true);
1745
1802
  }
1746
1803
  }
1747
- if (offset)
1748
- PointHelper.move(tempImage, offset);
1804
+ if (offset) PointHelper.move(tempImage, offset);
1749
1805
  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);
1806
+ case "stretch":
1807
+ if (!sameBox) width = box.width, height = box.height;
1808
+ break;
1809
+
1810
+ case "normal":
1811
+ case "clip":
1812
+ if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew) clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, paint.clipSize);
1813
+ break;
1814
+
1815
+ case "repeat":
1816
+ if (!sameBox || scaleX || rotation || skew) repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform);
1817
+ if (!repeat) data.repeat = "repeat";
1818
+ const count = isObject(repeat);
1819
+ if (gap || count) data.gap = getGapData(gap, count && repeat, tempImage.width, tempImage.height, box);
1820
+ break;
1821
+
1822
+ case "fit":
1823
+ case "cover":
1824
+ default:
1825
+ if (scaleX) fillOrFitMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
1770
1826
  }
1771
1827
  if (!data.transform) {
1772
1828
  if (box.x || box.y) {
@@ -1774,49 +1830,69 @@ function getPatternData(paint, box, image) {
1774
1830
  translate(data.transform, box.x, box.y);
1775
1831
  }
1776
1832
  }
1777
- if (scaleX && mode !== 'stretch') {
1833
+ if (scaleX && mode !== "stretch") {
1778
1834
  data.scaleX = scaleX;
1779
1835
  data.scaleY = scaleY;
1780
1836
  }
1781
1837
  data.width = width;
1782
1838
  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';
1839
+ if (opacity) data.opacity = opacity;
1840
+ if (filters) data.filters = filters;
1841
+ if (repeat) data.repeat = isString(repeat) ? repeat === "x" ? "repeat-x" : "repeat-y" : "repeat";
1789
1842
  return data;
1790
1843
  }
1791
1844
 
1792
- let cache, box = new Bounds();
1793
- const { isSame } = BoundsHelper;
1845
+ function getGapData(gap, repeat, width, height, box) {
1846
+ let xGap, yGap;
1847
+ if (isObject(gap)) xGap = gap.x, yGap = gap.y; else xGap = yGap = gap;
1848
+ return {
1849
+ x: getGapValue(xGap, width, box.width, repeat && repeat.x),
1850
+ y: getGapValue(yGap, height, box.height, repeat && repeat.y)
1851
+ };
1852
+ }
1853
+
1854
+ function getGapValue(gap, size, totalSize, rows) {
1855
+ const auto = isString(gap) || rows;
1856
+ const remain = rows ? totalSize - rows * size : totalSize % size;
1857
+ const value = auto ? remain / ((rows || Math.floor(totalSize / size)) - 1) : gap;
1858
+ return gap === "auto" ? value < 0 ? 0 : value : value;
1859
+ }
1860
+
1861
+ let cache, box = new Bounds;
1862
+
1863
+ const {isSame: isSame} = BoundsHelper;
1864
+
1794
1865
  function image(ui, attrName, paint, boxBounds, firstUse) {
1795
1866
  let leafPaint, event;
1796
1867
  const image = ImageManager.get(paint);
1797
1868
  if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
1798
1869
  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 };
1870
+ } else {
1871
+ leafPaint = {
1872
+ type: paint.type,
1873
+ image: image
1874
+ };
1875
+ if (image.hasAlphaPixel) leafPaint.isTransparent = true;
1876
+ cache = image.use > 1 ? {
1877
+ leafPaint: leafPaint,
1878
+ paint: paint,
1879
+ boxBounds: box.set(boxBounds)
1880
+ } : null;
1881
+ }
1882
+ if (firstUse || image.loading) event = {
1883
+ image: image,
1884
+ attrName: attrName,
1885
+ attrValue: paint
1886
+ };
1808
1887
  if (image.ready) {
1809
1888
  checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds);
1810
1889
  if (firstUse) {
1811
1890
  onLoad(ui, event);
1812
1891
  onLoadSuccess(ui, event);
1813
1892
  }
1814
- }
1815
- else if (image.error) {
1816
- if (firstUse)
1817
- onLoadError(ui, event, image.error);
1818
- }
1819
- else {
1893
+ } else if (image.error) {
1894
+ if (firstUse) onLoadError(ui, event, image.error);
1895
+ } else {
1820
1896
  if (firstUse) {
1821
1897
  ignoreRender(ui, true);
1822
1898
  onLoad(ui, event);
@@ -1825,79 +1901,84 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
1825
1901
  ignoreRender(ui, false);
1826
1902
  if (!ui.destroyed) {
1827
1903
  if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds)) {
1828
- if (image.hasAlphaPixel)
1829
- ui.__layout.hitCanvasChanged = true;
1830
- ui.forceUpdate('surface');
1904
+ if (image.hasAlphaPixel) ui.__layout.hitCanvasChanged = true;
1905
+ ui.forceUpdate("surface");
1831
1906
  }
1832
1907
  onLoadSuccess(ui, event);
1833
1908
  }
1834
1909
  leafPaint.loadId = undefined;
1835
- }, (error) => {
1910
+ }, error => {
1836
1911
  ignoreRender(ui, false);
1837
1912
  onLoadError(ui, event, error);
1838
1913
  leafPaint.loadId = undefined;
1839
1914
  });
1840
1915
  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);
1916
+ if (!ui.placeholderDelay) image.isPlacehold = true; else setTimeout(() => {
1917
+ if (!image.ready) {
1918
+ image.isPlacehold = true;
1919
+ ui.forceUpdate("surface");
1920
+ }
1921
+ }, ui.placeholderDelay);
1850
1922
  }
1851
1923
  }
1852
1924
  return leafPaint;
1853
1925
  }
1926
+
1854
1927
  function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
1855
- if (attrName === 'fill' && !ui.__.__naturalWidth) {
1928
+ if (attrName === "fill" && !ui.__.__naturalWidth) {
1856
1929
  const data = ui.__;
1857
1930
  data.__naturalWidth = image.width / data.pixelRatio;
1858
1931
  data.__naturalHeight = image.height / data.pixelRatio;
1859
1932
  if (data.__autoSide) {
1860
- ui.forceUpdate('width');
1933
+ ui.forceUpdate("width");
1861
1934
  if (ui.__proxyData) {
1862
- ui.setProxyAttr('width', data.width);
1863
- ui.setProxyAttr('height', data.height);
1935
+ ui.setProxyAttr("width", data.width);
1936
+ ui.setProxyAttr("height", data.height);
1864
1937
  }
1865
1938
  return false;
1866
1939
  }
1867
1940
  }
1868
- if (!leafPaint.data)
1869
- createData(leafPaint, image, paint, boxBounds);
1941
+ if (!leafPaint.data) createData(leafPaint, image, paint, boxBounds);
1870
1942
  return true;
1871
1943
  }
1944
+
1872
1945
  function onLoad(ui, event) {
1873
1946
  emit(ui, ImageEvent.LOAD, event);
1874
1947
  }
1948
+
1875
1949
  function onLoadSuccess(ui, event) {
1876
1950
  emit(ui, ImageEvent.LOADED, event);
1877
1951
  }
1952
+
1878
1953
  function onLoadError(ui, event, error) {
1879
1954
  event.error = error;
1880
- ui.forceUpdate('surface');
1955
+ ui.forceUpdate("surface");
1881
1956
  emit(ui, ImageEvent.ERROR, event);
1882
1957
  }
1958
+
1883
1959
  function emit(ui, type, data) {
1884
- if (ui.hasEvent(type))
1885
- ui.emitEvent(new ImageEvent(type, data));
1960
+ if (ui.hasEvent(type)) ui.emitEvent(new ImageEvent(type, data));
1886
1961
  }
1962
+
1887
1963
  function ignoreRender(ui, value) {
1888
- const { leafer } = ui;
1889
- if (leafer && leafer.viewReady)
1890
- leafer.renderer.ignore = value;
1964
+ const {leafer: leafer} = ui;
1965
+ if (leafer && leafer.viewReady) leafer.renderer.ignore = value;
1891
1966
  }
1892
1967
 
1893
- const { get: get$1, scale, copy: copy$1 } = MatrixHelper;
1894
- const { ceil, abs } = Math;
1968
+ const {get: get$1, scale: scale, copy: copy$1} = MatrixHelper;
1969
+
1970
+ const {floor: floor, max: max, abs: abs} = Math;
1971
+
1895
1972
  function createPattern(ui, paint, pixelRatio) {
1896
- let { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed);
1897
- const id = scaleX + '-' + scaleY + '-' + pixelRatio;
1973
+ let {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
1974
+ const id = scaleX + "-" + scaleY + "-" + pixelRatio;
1898
1975
  if (paint.patternId !== id && !ui.destroyed) {
1899
- const { image, data } = paint;
1900
- let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, transform, repeat } = data;
1976
+ const {image: image, data: data} = paint;
1977
+ let imageScale, imageMatrix, {width: width, height: height, scaleX: sx, scaleY: sy, transform: transform, repeat: repeat, gap: gap} = data;
1978
+ scaleX *= pixelRatio;
1979
+ scaleY *= pixelRatio;
1980
+ const xGap = gap && gap.x * scaleX;
1981
+ const yGap = gap && gap.y * scaleY;
1901
1982
  if (sx) {
1902
1983
  sx = abs(sx);
1903
1984
  sy = abs(sy);
@@ -1907,23 +1988,18 @@ function createPattern(ui, paint, pixelRatio) {
1907
1988
  scaleX *= sx;
1908
1989
  scaleY *= sy;
1909
1990
  }
1910
- scaleX *= pixelRatio;
1911
- scaleY *= pixelRatio;
1912
1991
  width *= scaleX;
1913
1992
  height *= scaleY;
1914
1993
  const size = width * height;
1915
1994
  if (!repeat) {
1916
- if (size > Platform.image.maxCacheSize)
1917
- return false;
1995
+ if (size > Platform.image.maxCacheSize) return false;
1918
1996
  }
1919
1997
  let maxSize = Platform.image.maxPatternSize;
1920
1998
  if (!image.isSVG) {
1921
1999
  const imageSize = image.width * image.height;
1922
- if (maxSize > imageSize)
1923
- maxSize = imageSize;
2000
+ if (maxSize > imageSize) maxSize = imageSize;
1924
2001
  }
1925
- if (size > maxSize)
1926
- imageScale = Math.sqrt(size / maxSize);
2002
+ if (size > maxSize) imageScale = Math.sqrt(size / maxSize);
1927
2003
  if (imageScale) {
1928
2004
  scaleX /= imageScale;
1929
2005
  scaleY /= imageScale;
@@ -1937,97 +2013,95 @@ function createPattern(ui, paint, pixelRatio) {
1937
2013
  if (transform || scaleX !== 1 || scaleY !== 1) {
1938
2014
  if (!imageMatrix) {
1939
2015
  imageMatrix = get$1();
1940
- if (transform)
1941
- copy$1(imageMatrix, transform);
2016
+ if (transform) copy$1(imageMatrix, transform);
1942
2017
  }
1943
2018
  scale(imageMatrix, 1 / scaleX, 1 / scaleY);
1944
2019
  }
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);
2020
+ if (imageMatrix) {
2021
+ const canvasWidth = width + (xGap || 0), canvasHeight = height + (yGap || 0);
2022
+ scale(imageMatrix, canvasWidth / max(floor(canvasWidth), 1), canvasHeight / max(floor(canvasHeight), 1));
2023
+ }
2024
+ const canvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap);
2025
+ const pattern = image.getPattern(canvas, repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
1947
2026
  paint.style = pattern;
1948
2027
  paint.patternId = id;
1949
2028
  return true;
1950
- }
1951
- else {
2029
+ } else {
1952
2030
  return false;
1953
2031
  }
1954
2032
  }
1955
2033
 
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;
2034
+ function __awaiter(thisArg, _arguments, P, generator) {
2035
+ function adopt(value) {
2036
+ return value instanceof P ? value : new P(function(resolve) {
2037
+ resolve(value);
2038
+ });
2039
+ }
2040
+ return new (P || (P = Promise))(function(resolve, reject) {
2041
+ function fulfilled(value) {
2042
+ try {
2043
+ step(generator.next(value));
2044
+ } catch (e) {
2045
+ reject(e);
2046
+ }
2047
+ }
2048
+ function rejected(value) {
2049
+ try {
2050
+ step(generator["throw"](value));
2051
+ } catch (e) {
2052
+ reject(e);
2053
+ }
2054
+ }
2055
+ function step(result) {
2056
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
2057
+ }
2058
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
2059
+ });
2060
+ }
2061
+
2062
+ typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
2063
+ var e = new Error(message);
2064
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1986
2065
  };
1987
2066
 
1988
2067
  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)) {
2068
+ const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
2069
+ const {pixelRatio: pixelRatio} = canvas, {data: data} = paint;
2070
+ if (!data || paint.patternId === scaleX + "-" + scaleY + "-" + pixelRatio && !Export.running) {
1992
2071
  return false;
1993
- }
1994
- else {
2072
+ } else {
1995
2073
  if (allowDraw) {
1996
2074
  if (data.repeat) {
1997
2075
  allowDraw = false;
1998
- }
1999
- else {
2000
- if (!(paint.changeful || ResizeEvent.isResizing(ui) || Export.running)) {
2001
- let { width, height } = data;
2076
+ } else {
2077
+ if (!(paint.changeful || Platform.name === "miniapp" && ResizeEvent.isResizing(ui) || Export.running)) {
2078
+ let {width: width, height: height} = data;
2002
2079
  width *= scaleX * pixelRatio;
2003
2080
  height *= scaleY * pixelRatio;
2004
2081
  if (data.scaleX) {
2005
2082
  width *= data.scaleX;
2006
2083
  height *= data.scaleY;
2007
2084
  }
2008
- allowDraw = (width * height > Platform.image.maxCacheSize);
2085
+ allowDraw = width * height > Platform.image.maxCacheSize;
2009
2086
  }
2010
2087
  }
2011
2088
  }
2012
2089
  if (allowDraw) {
2013
2090
  if (ui.__.__isFastShadow) {
2014
- canvas.fillStyle = paint.style || '#000';
2091
+ canvas.fillStyle = paint.style || "#000";
2015
2092
  canvas.fill();
2016
2093
  }
2017
2094
  drawImage(ui, canvas, paint, data);
2018
2095
  return true;
2019
- }
2020
- else {
2096
+ } else {
2021
2097
  if (!paint.style || paint.sync || Export.running) {
2022
2098
  createPattern(ui, paint, pixelRatio);
2023
- }
2024
- else {
2099
+ } else {
2025
2100
  if (!paint.patternTask) {
2026
- paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function* () {
2101
+ paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function*() {
2027
2102
  paint.patternTask = null;
2028
- if (canvas.bounds.hit(ui.__nowWorld))
2029
- createPattern(ui, paint, pixelRatio);
2030
- ui.forceUpdate('surface');
2103
+ if (canvas.bounds.hit(ui.__nowWorld)) createPattern(ui, paint, pixelRatio);
2104
+ ui.forceUpdate("surface");
2031
2105
  }), 300);
2032
2106
  }
2033
2107
  }
@@ -2035,39 +2109,35 @@ function checkImage(ui, canvas, paint, allowDraw) {
2035
2109
  }
2036
2110
  }
2037
2111
  }
2112
+
2038
2113
  function drawImage(ui, canvas, paint, data) {
2039
2114
  canvas.save();
2040
2115
  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);
2116
+ if (paint.blendMode) canvas.blendMode = paint.blendMode;
2117
+ if (data.opacity) canvas.opacity *= data.opacity;
2118
+ if (data.transform) canvas.transform(data.transform);
2047
2119
  canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
2048
2120
  canvas.restore();
2049
2121
  }
2050
2122
 
2051
2123
  function recycleImage(attrName, data) {
2052
- const paints = data['_' + attrName];
2053
- if (paints instanceof Array) {
2124
+ const paints = data["_" + attrName];
2125
+ if (isArray(paints)) {
2054
2126
  let paint, image, recycleMap, input, url;
2055
2127
  for (let i = 0, len = paints.length; i < len; i++) {
2056
2128
  paint = paints[i];
2057
2129
  image = paint.image;
2058
2130
  url = image && image.url;
2059
2131
  if (url) {
2060
- if (!recycleMap)
2061
- recycleMap = {};
2132
+ if (!recycleMap) recycleMap = {};
2062
2133
  recycleMap[url] = true;
2063
2134
  ImageManager.recycle(image);
2064
2135
  if (image.loading) {
2065
2136
  if (!input) {
2066
- input = (data.__input && data.__input[attrName]) || [];
2067
- if (!(input instanceof Array))
2068
- input = [input];
2137
+ input = data.__input && data.__input[attrName] || [];
2138
+ if (!isArray(input)) input = [ input ];
2069
2139
  }
2070
- image.unload(paints[i].loadId, !input.some((item) => item.url === url));
2140
+ image.unload(paints[i].loadId, !input.some(item => item.url === url));
2071
2141
  }
2072
2142
  }
2073
2143
  }
@@ -2077,75 +2147,85 @@ function recycleImage(attrName, data) {
2077
2147
  }
2078
2148
 
2079
2149
  const PaintImageModule = {
2080
- image,
2081
- checkImage,
2082
- createPattern,
2083
- recycleImage,
2084
- createData,
2085
- getPatternData,
2086
- fillOrFitMode,
2087
- clipMode,
2088
- repeatMode
2150
+ image: image,
2151
+ checkImage: checkImage,
2152
+ createPattern: createPattern,
2153
+ recycleImage: recycleImage,
2154
+ createData: createData,
2155
+ getPatternData: getPatternData,
2156
+ fillOrFitMode: fillOrFitMode,
2157
+ clipMode: clipMode,
2158
+ repeatMode: repeatMode
2089
2159
  };
2090
2160
 
2091
- const { toPoint: toPoint$2 } = AroundHelper, { hasTransparent } = ColorConvert;
2161
+ const {toPoint: toPoint$2} = AroundHelper, {hasTransparent: hasTransparent} = ColorConvert;
2162
+
2092
2163
  const realFrom$2 = {};
2164
+
2093
2165
  const realTo$2 = {};
2166
+
2094
2167
  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);
2168
+ let {from: from, to: to, type: type, opacity: opacity} = paint;
2169
+ toPoint$2(from || "top", box, realFrom$2);
2170
+ toPoint$2(to || "bottom", box, realTo$2);
2098
2171
  const style = Platform.canvas.createLinearGradient(realFrom$2.x, realFrom$2.y, realTo$2.x, realTo$2.y);
2099
- const data = { type, style };
2172
+ const data = {
2173
+ type: type,
2174
+ style: style
2175
+ };
2100
2176
  applyStops(data, style, paint.stops, opacity);
2101
2177
  return data;
2102
2178
  }
2179
+
2103
2180
  function applyStops(data, gradient, stops, opacity) {
2104
2181
  if (stops) {
2105
2182
  let stop, color, offset, isTransparent;
2106
2183
  for (let i = 0, len = stops.length; i < len; i++) {
2107
2184
  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);
2185
+ if (isString(stop)) offset = i / (len - 1), color = ColorConvert.string(stop, opacity); else offset = stop.offset,
2186
+ color = ColorConvert.string(stop.color, opacity);
2112
2187
  gradient.addColorStop(offset, color);
2113
- if (!isTransparent && hasTransparent(color))
2114
- isTransparent = true;
2188
+ if (!isTransparent && hasTransparent(color)) isTransparent = true;
2115
2189
  }
2116
- if (isTransparent)
2117
- data.isTransparent = true;
2190
+ if (isTransparent) data.isTransparent = true;
2118
2191
  }
2119
2192
  }
2120
2193
 
2121
- const { getAngle, getDistance: getDistance$1 } = PointHelper;
2122
- const { get, rotateOfOuter, scaleOfOuter } = MatrixHelper;
2123
- const { toPoint: toPoint$1 } = AroundHelper;
2194
+ const {getAngle: getAngle, getDistance: getDistance$1} = PointHelper;
2195
+
2196
+ const {get: get, rotateOfOuter: rotateOfOuter, scaleOfOuter: scaleOfOuter} = MatrixHelper;
2197
+
2198
+ const {toPoint: toPoint$1} = AroundHelper;
2199
+
2124
2200
  const realFrom$1 = {};
2201
+
2125
2202
  const realTo$1 = {};
2203
+
2126
2204
  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);
2205
+ let {from: from, to: to, type: type, opacity: opacity, stretch: stretch} = paint;
2206
+ toPoint$1(from || "center", box, realFrom$1);
2207
+ toPoint$1(to || "bottom", box, realTo$1);
2130
2208
  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 };
2209
+ const data = {
2210
+ type: type,
2211
+ style: style
2212
+ };
2132
2213
  applyStops(data, style, paint.stops, opacity);
2133
2214
  const transform = getTransform(box, realFrom$1, realTo$1, stretch, true);
2134
- if (transform)
2135
- data.transform = transform;
2215
+ if (transform) data.transform = transform;
2136
2216
  return data;
2137
2217
  }
2218
+
2138
2219
  function getTransform(box, from, to, stretch, rotate90) {
2139
2220
  let transform;
2140
- const { width, height } = box;
2221
+ const {width: width, height: height} = box;
2141
2222
  if (width !== height || stretch) {
2142
2223
  const angle = getAngle(from, to);
2143
2224
  transform = get();
2144
2225
  if (rotate90) {
2145
2226
  scaleOfOuter(transform, from, width / height * (stretch || 1), 1);
2146
2227
  rotateOfOuter(transform, from, angle + 90);
2147
- }
2148
- else {
2228
+ } else {
2149
2229
  scaleOfOuter(transform, from, 1, width / height * (stretch || 1));
2150
2230
  rotateOfOuter(transform, from, angle);
2151
2231
  }
@@ -2153,81 +2233,94 @@ function getTransform(box, from, to, stretch, rotate90) {
2153
2233
  return transform;
2154
2234
  }
2155
2235
 
2156
- const { getDistance } = PointHelper;
2157
- const { toPoint } = AroundHelper;
2236
+ const {getDistance: getDistance} = PointHelper;
2237
+
2238
+ const {toPoint: toPoint} = AroundHelper;
2239
+
2158
2240
  const realFrom = {};
2241
+
2159
2242
  const realTo = {};
2243
+
2160
2244
  function conicGradient(paint, box) {
2161
- let { from, to, type, opacity, stretch } = paint;
2162
- toPoint(from || 'center', box, realFrom);
2163
- toPoint(to || 'bottom', box, realTo);
2245
+ let {from: from, to: to, type: type, opacity: opacity, stretch: stretch} = paint;
2246
+ toPoint(from || "center", box, realFrom);
2247
+ toPoint(to || "bottom", box, realTo);
2164
2248
  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 };
2249
+ const data = {
2250
+ type: type,
2251
+ style: style
2252
+ };
2166
2253
  applyStops(data, style, paint.stops, opacity);
2167
2254
  const transform = getTransform(box, realFrom, realTo, stretch || 1, Platform.conicGradientRotate90);
2168
- if (transform)
2169
- data.transform = transform;
2255
+ if (transform) data.transform = transform;
2170
2256
  return data;
2171
2257
  }
2172
2258
 
2173
2259
  const PaintGradientModule = {
2174
- linearGradient,
2175
- radialGradient,
2176
- conicGradient,
2177
- getTransform
2260
+ linearGradient: linearGradient,
2261
+ radialGradient: radialGradient,
2262
+ conicGradient: conicGradient,
2263
+ getTransform: getTransform
2178
2264
  };
2179
2265
 
2180
- const { copy, toOffsetOutBounds: toOffsetOutBounds$1 } = BoundsHelper;
2266
+ const {copy: copy, toOffsetOutBounds: toOffsetOutBounds$1} = BoundsHelper;
2267
+
2181
2268
  const tempBounds = {};
2269
+
2182
2270
  const offsetOutBounds$1 = {};
2271
+
2183
2272
  function shadow(ui, current, shape) {
2184
2273
  let copyBounds, spreadScale;
2185
- const { __nowWorld: nowWorld, __layout } = ui;
2186
- const { shadow } = ui.__;
2187
- const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
2274
+ const {__nowWorld: nowWorld, __layout: __layout} = ui;
2275
+ const {shadow: shadow} = ui.__;
2276
+ const {worldCanvas: worldCanvas, bounds: bounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
2188
2277
  const other = current.getSameCanvas();
2189
2278
  const end = shadow.length - 1;
2190
2279
  toOffsetOutBounds$1(bounds, offsetOutBounds$1);
2191
2280
  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;
2281
+ let otherScale = 1;
2282
+ if (item.scaleFixed) {
2283
+ const sx = Math.abs(nowWorld.scaleX);
2284
+ if (sx > 1) otherScale = 1 / sx;
2285
+ }
2286
+ other.setWorldShadow(offsetOutBounds$1.offsetX + item.x * scaleX * otherScale, offsetOutBounds$1.offsetY + item.y * scaleY * otherScale, item.blur * scaleX * otherScale, ColorConvert.string(item.color));
2287
+ spreadScale = item.spread ? 1 + item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) * otherScale : 0;
2194
2288
  drawWorldShadow(other, offsetOutBounds$1, spreadScale, shape);
2195
2289
  copyBounds = bounds;
2196
2290
  if (item.box) {
2197
2291
  other.restore();
2198
2292
  other.save();
2199
2293
  if (worldCanvas) {
2200
- other.copyWorld(other, bounds, nowWorld, 'copy');
2294
+ other.copyWorld(other, bounds, nowWorld, "copy");
2201
2295
  copyBounds = nowWorld;
2202
2296
  }
2203
- worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, 'destination-out') : other.copyWorld(shape.canvas, shapeBounds, bounds, 'destination-out');
2297
+ worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, "destination-out") : other.copyWorld(shape.canvas, shapeBounds, bounds, "destination-out");
2204
2298
  }
2205
2299
  LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
2206
- if (end && index < end)
2207
- other.clearWorld(copyBounds, true);
2300
+ if (end && index < end) other.clearWorld(copyBounds, true);
2208
2301
  });
2209
2302
  other.recycle(copyBounds);
2210
2303
  }
2304
+
2211
2305
  function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
2212
- const { bounds, shapeBounds } = shape;
2306
+ const {bounds: bounds, shapeBounds: shapeBounds} = shape;
2213
2307
  if (Platform.fullImageShadow) {
2214
2308
  copy(tempBounds, canvas.bounds);
2215
- tempBounds.x += (outBounds.x - shapeBounds.x);
2216
- tempBounds.y += (outBounds.y - shapeBounds.y);
2309
+ tempBounds.x += outBounds.x - shapeBounds.x;
2310
+ tempBounds.y += outBounds.y - shapeBounds.y;
2217
2311
  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);
2312
+ const {fitMatrix: fitMatrix} = shape;
2313
+ tempBounds.x -= (bounds.x + (fitMatrix ? fitMatrix.e : 0) + bounds.width / 2) * (spreadScale - 1);
2314
+ tempBounds.y -= (bounds.y + (fitMatrix ? fitMatrix.f : 0) + bounds.height / 2) * (spreadScale - 1);
2221
2315
  tempBounds.width *= spreadScale;
2222
2316
  tempBounds.height *= spreadScale;
2223
2317
  }
2224
2318
  canvas.copyWorld(shape.canvas, canvas.bounds, tempBounds);
2225
- }
2226
- else {
2319
+ } else {
2227
2320
  if (spreadScale) {
2228
2321
  copy(tempBounds, outBounds);
2229
- tempBounds.x -= (outBounds.width / 2) * (spreadScale - 1);
2230
- tempBounds.y -= (outBounds.height / 2) * (spreadScale - 1);
2322
+ tempBounds.x -= outBounds.width / 2 * (spreadScale - 1);
2323
+ tempBounds.y -= outBounds.height / 2 * (spreadScale - 1);
2231
2324
  tempBounds.width *= spreadScale;
2232
2325
  tempBounds.height *= spreadScale;
2233
2326
  }
@@ -2235,174 +2328,184 @@ function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
2235
2328
  }
2236
2329
  }
2237
2330
 
2238
- const { toOffsetOutBounds } = BoundsHelper;
2331
+ const {toOffsetOutBounds: toOffsetOutBounds} = BoundsHelper;
2332
+
2239
2333
  const offsetOutBounds = {};
2334
+
2240
2335
  function innerShadow(ui, current, shape) {
2241
2336
  let copyBounds, spreadScale;
2242
- const { __nowWorld: nowWorld, __layout } = ui;
2243
- const { innerShadow } = ui.__;
2244
- const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
2337
+ const {__nowWorld: nowWorld, __layout: __layout} = ui;
2338
+ const {innerShadow: innerShadow} = ui.__;
2339
+ const {worldCanvas: worldCanvas, bounds: bounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
2245
2340
  const other = current.getSameCanvas();
2246
2341
  const end = innerShadow.length - 1;
2247
2342
  toOffsetOutBounds(bounds, offsetOutBounds);
2248
2343
  innerShadow.forEach((item, index) => {
2344
+ let otherScale = 1;
2345
+ if (item.scaleFixed) {
2346
+ const sx = Math.abs(nowWorld.scaleX);
2347
+ if (sx > 1) otherScale = 1 / sx;
2348
+ }
2249
2349
  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;
2350
+ other.setWorldShadow(offsetOutBounds.offsetX + item.x * scaleX * otherScale, offsetOutBounds.offsetY + item.y * scaleY * otherScale, item.blur * scaleX * otherScale);
2351
+ spreadScale = item.spread ? 1 - item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) * otherScale : 0;
2252
2352
  drawWorldShadow(other, offsetOutBounds, spreadScale, shape);
2253
2353
  other.restore();
2254
2354
  if (worldCanvas) {
2255
- other.copyWorld(other, bounds, nowWorld, 'copy');
2256
- other.copyWorld(worldCanvas, nowWorld, nowWorld, 'source-out');
2355
+ other.copyWorld(other, bounds, nowWorld, "copy");
2356
+ other.copyWorld(worldCanvas, nowWorld, nowWorld, "source-out");
2257
2357
  copyBounds = nowWorld;
2258
- }
2259
- else {
2260
- other.copyWorld(shape.canvas, shapeBounds, bounds, 'source-out');
2358
+ } else {
2359
+ other.copyWorld(shape.canvas, shapeBounds, bounds, "source-out");
2261
2360
  copyBounds = bounds;
2262
2361
  }
2263
- other.fillWorld(copyBounds, ColorConvert.string(item.color), 'source-in');
2362
+ other.fillWorld(copyBounds, ColorConvert.string(item.color), "source-in");
2264
2363
  LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
2265
- if (end && index < end)
2266
- other.clearWorld(copyBounds, true);
2364
+ if (end && index < end) other.clearWorld(copyBounds, true);
2267
2365
  });
2268
2366
  other.recycle(copyBounds);
2269
2367
  }
2270
2368
 
2271
2369
  function blur(ui, current, origin) {
2272
- const { blur } = ui.__;
2370
+ const {blur: blur} = ui.__;
2273
2371
  origin.setWorldBlur(blur * ui.__nowWorld.a);
2274
2372
  origin.copyWorldToInner(current, ui.__nowWorld, ui.__layout.renderBounds);
2275
- origin.filter = 'none';
2373
+ origin.filter = "none";
2276
2374
  }
2277
2375
 
2278
- function backgroundBlur(_ui, _current, _shape) {
2279
- }
2376
+ function backgroundBlur(_ui, _current, _shape) {}
2280
2377
 
2281
2378
  const EffectModule = {
2282
- shadow,
2283
- innerShadow,
2284
- blur,
2285
- backgroundBlur
2379
+ shadow: shadow,
2380
+ innerShadow: innerShadow,
2381
+ blur: blur,
2382
+ backgroundBlur: backgroundBlur
2286
2383
  };
2287
2384
 
2288
- const { excludeRenderBounds } = LeafBoundsHelper;
2289
- Group.prototype.__renderMask = function (canvas, options) {
2385
+ const {excludeRenderBounds: excludeRenderBounds} = LeafBoundsHelper;
2386
+
2387
+ let usedGrayscaleAlpha;
2388
+
2389
+ Group.prototype.__renderMask = function(canvas, options) {
2290
2390
  let child, maskCanvas, contentCanvas, maskOpacity, currentMask, mask;
2291
- const { children } = this;
2391
+ const {children: children} = this;
2292
2392
  for (let i = 0, len = children.length; i < len; i++) {
2293
2393
  child = children[i], mask = child.__.mask;
2294
2394
  if (mask) {
2295
2395
  if (currentMask) {
2296
- maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
2396
+ maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
2297
2397
  maskCanvas = contentCanvas = null;
2298
2398
  }
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';
2399
+ maskOpacity = child.__.opacity;
2400
+ usedGrayscaleAlpha = false;
2401
+ if (mask === "path" || mask === "clipping-path") {
2402
+ if (maskOpacity < 1) {
2403
+ currentMask = "opacity-path";
2404
+ if (!contentCanvas) contentCanvas = getCanvas(canvas);
2405
+ } else {
2406
+ currentMask = "path";
2308
2407
  canvas.save();
2309
2408
  }
2310
2409
  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);
2410
+ } else {
2411
+ currentMask = mask === "grayscale" ? "grayscale" : "alpha";
2412
+ if (!maskCanvas) maskCanvas = getCanvas(canvas);
2413
+ if (!contentCanvas) contentCanvas = getCanvas(canvas);
2318
2414
  child.__render(maskCanvas, options);
2319
2415
  }
2320
- if (mask === 'clipping' || mask === 'clipping-path')
2321
- excludeRenderBounds(child, options) || child.__render(canvas, options);
2416
+ if (mask === "clipping" || mask === "clipping-path") excludeRenderBounds(child, options) || child.__render(canvas, options);
2322
2417
  continue;
2323
2418
  }
2419
+ const childBlendMode = maskOpacity === 1 && child.__.__blendMode;
2420
+ if (childBlendMode) maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, false);
2324
2421
  excludeRenderBounds(child, options) || child.__render(contentCanvas || canvas, options);
2422
+ if (childBlendMode) maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, childBlendMode, false);
2325
2423
  }
2326
- maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
2424
+ maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
2327
2425
  };
2328
- function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity) {
2426
+
2427
+ function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity, blendMode, recycle) {
2329
2428
  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();
2429
+ case "grayscale":
2430
+ if (!usedGrayscaleAlpha) usedGrayscaleAlpha = true, maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
2431
+
2432
+ case "alpha":
2433
+ usePixelMask(leaf, canvas, contentCanvas, maskCanvas, blendMode, recycle);
2434
+ break;
2435
+
2436
+ case "opacity-path":
2437
+ copyContent(leaf, canvas, contentCanvas, maskOpacity, blendMode, recycle);
2438
+ break;
2439
+
2440
+ case "path":
2441
+ if (recycle) canvas.restore();
2340
2442
  }
2341
2443
  }
2444
+
2342
2445
  function getCanvas(canvas) {
2343
2446
  return canvas.getSameCanvas(false, true);
2344
2447
  }
2345
- function usePixelMask(leaf, canvas, content, mask) {
2448
+
2449
+ function usePixelMask(leaf, canvas, content, mask, blendMode, recycle) {
2346
2450
  const realBounds = leaf.__nowWorld;
2347
2451
  content.resetTransform();
2348
2452
  content.opacity = 1;
2349
2453
  content.useMask(mask, realBounds);
2350
- mask.recycle(realBounds);
2351
- copyContent(leaf, canvas, content, 1);
2454
+ if (recycle) mask.recycle(realBounds);
2455
+ copyContent(leaf, canvas, content, 1, blendMode, recycle);
2352
2456
  }
2353
- function copyContent(leaf, canvas, content, maskOpacity) {
2457
+
2458
+ function copyContent(leaf, canvas, content, maskOpacity, blendMode, recycle) {
2354
2459
  const realBounds = leaf.__nowWorld;
2355
2460
  canvas.resetTransform();
2356
2461
  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('|'));
2462
+ canvas.copyWorld(content, realBounds, undefined, blendMode);
2463
+ recycle ? content.recycle(realBounds) : content.clearWorld(realBounds, true);
2464
+ }
2465
+
2466
+ const money = "¥¥$€££¢¢";
2467
+
2468
+ const letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
2469
+
2470
+ const langBefore = "《(「〈『〖【〔{┌<‘“=" + money;
2471
+
2472
+ const langAfter = "》)」〉』〗】〕}┐>’”!?,、。:;‰";
2473
+
2474
+ const langSymbol = "≮≯≈≠=…";
2475
+
2476
+ const langBreak$1 = "—/~|┆·";
2477
+
2478
+ const beforeChar = "{[(<'\"" + langBefore;
2479
+
2480
+ const afterChar = ">)]}%!?,.:;'\"" + langAfter;
2481
+
2482
+ const symbolChar = afterChar + "_#~&*+\\=|" + langSymbol;
2483
+
2484
+ const breakChar = "- " + langBreak$1;
2485
+
2486
+ 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 ] ];
2487
+
2488
+ const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u${start.toString(16)}-\\u${end.toString(16)}]`).join("|"));
2489
+
2394
2490
  function mapChar(str) {
2395
2491
  const map = {};
2396
- str.split('').forEach(char => map[char] = true);
2492
+ str.split("").forEach(char => map[char] = true);
2397
2493
  return map;
2398
2494
  }
2495
+
2399
2496
  const letterMap = mapChar(letter);
2497
+
2400
2498
  const beforeMap = mapChar(beforeChar);
2499
+
2401
2500
  const afterMap = mapChar(afterChar);
2501
+
2402
2502
  const symbolMap = mapChar(symbolChar);
2503
+
2403
2504
  const breakMap = mapChar(breakChar);
2505
+
2404
2506
  var CharType;
2405
- (function (CharType) {
2507
+
2508
+ (function(CharType) {
2406
2509
  CharType[CharType["Letter"] = 0] = "Letter";
2407
2510
  CharType[CharType["Single"] = 1] = "Single";
2408
2511
  CharType[CharType["Before"] = 2] = "Before";
@@ -2410,179 +2513,175 @@ var CharType;
2410
2513
  CharType[CharType["Symbol"] = 4] = "Symbol";
2411
2514
  CharType[CharType["Break"] = 5] = "Break";
2412
2515
  })(CharType || (CharType = {}));
2413
- const { Letter: Letter$1, Single: Single$1, Before: Before$1, After: After$1, Symbol: Symbol$1, Break: Break$1 } = CharType;
2516
+
2517
+ const {Letter: Letter$1, Single: Single$1, Before: Before$1, After: After$1, Symbol: Symbol$1, Break: Break$1} = CharType;
2518
+
2414
2519
  function getCharType(char) {
2415
2520
  if (letterMap[char]) {
2416
2521
  return Letter$1;
2417
- }
2418
- else if (breakMap[char]) {
2522
+ } else if (breakMap[char]) {
2419
2523
  return Break$1;
2420
- }
2421
- else if (beforeMap[char]) {
2524
+ } else if (beforeMap[char]) {
2422
2525
  return Before$1;
2423
- }
2424
- else if (afterMap[char]) {
2526
+ } else if (afterMap[char]) {
2425
2527
  return After$1;
2426
- }
2427
- else if (symbolMap[char]) {
2528
+ } else if (symbolMap[char]) {
2428
2529
  return Symbol$1;
2429
- }
2430
- else if (cjkReg.test(char)) {
2530
+ } else if (cjkReg.test(char)) {
2431
2531
  return Single$1;
2432
- }
2433
- else {
2532
+ } else {
2434
2533
  return Letter$1;
2435
2534
  }
2436
2535
  }
2437
2536
 
2438
2537
  const TextRowHelper = {
2439
2538
  trimRight(row) {
2440
- const { words } = row;
2539
+ const {words: words} = row;
2441
2540
  let trimRight = 0, len = words.length, char;
2442
2541
  for (let i = len - 1; i > -1; i--) {
2443
2542
  char = words[i].data[0];
2444
- if (char.char === ' ') {
2543
+ if (char.char === " ") {
2445
2544
  trimRight++;
2446
2545
  row.width -= char.width;
2447
- }
2448
- else {
2546
+ } else {
2449
2547
  break;
2450
2548
  }
2451
2549
  }
2452
- if (trimRight)
2453
- words.splice(len - trimRight, trimRight);
2550
+ if (trimRight) words.splice(len - trimRight, trimRight);
2454
2551
  }
2455
2552
  };
2456
2553
 
2457
2554
  function getTextCase(char, textCase, firstChar) {
2458
2555
  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;
2556
+ case "title":
2557
+ return firstChar ? char.toUpperCase() : char;
2558
+
2559
+ case "upper":
2560
+ return char.toUpperCase();
2561
+
2562
+ case "lower":
2563
+ return char.toLowerCase();
2564
+
2565
+ default:
2566
+ return char;
2467
2567
  }
2468
2568
  }
2469
2569
 
2470
- const { trimRight } = TextRowHelper;
2471
- const { Letter, Single, Before, After, Symbol, Break } = CharType;
2570
+ const {trimRight: trimRight} = TextRowHelper;
2571
+
2572
+ const {Letter: Letter, Single: Single, Before: Before, After: After, Symbol: Symbol, Break: Break} = CharType;
2573
+
2472
2574
  let word, row, wordWidth, rowWidth, realWidth;
2575
+
2473
2576
  let char, charWidth, startCharSize, charSize, charType, lastCharType, langBreak, afterBreak, paraStart;
2577
+
2474
2578
  let textDrawData, rows = [], bounds, findMaxWidth;
2579
+
2475
2580
  function createRows(drawData, content, style) {
2476
2581
  textDrawData = drawData;
2477
2582
  rows = drawData.rows;
2478
2583
  bounds = drawData.bounds;
2479
2584
  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');
2585
+ const {__letterSpacing: __letterSpacing, paraIndent: paraIndent, textCase: textCase} = style;
2586
+ const {canvas: canvas} = Platform;
2587
+ const {width: width, height: height} = bounds;
2588
+ const charMode = width || height || __letterSpacing || textCase !== "none";
2484
2589
  if (charMode) {
2485
- const wrap = style.textWrap !== 'none';
2486
- const breakAll = style.textWrap === 'break';
2590
+ const wrap = style.textWrap !== "none";
2591
+ const breakAll = style.textWrap === "break";
2487
2592
  paraStart = true;
2488
2593
  lastCharType = null;
2489
2594
  startCharSize = charWidth = charSize = wordWidth = rowWidth = 0;
2490
- word = { data: [] }, row = { words: [] };
2491
- if (__letterSpacing)
2492
- content = [...content];
2595
+ word = {
2596
+ data: []
2597
+ }, row = {
2598
+ words: []
2599
+ };
2600
+ if (__letterSpacing) content = [ ...content ];
2493
2601
  for (let i = 0, len = content.length; i < len; i++) {
2494
2602
  char = content[i];
2495
- if (char === '\n') {
2496
- if (wordWidth)
2497
- addWord();
2603
+ if (char === "\n") {
2604
+ if (wordWidth) addWord();
2498
2605
  row.paraEnd = true;
2499
2606
  addRow();
2500
2607
  paraStart = true;
2501
- }
2502
- else {
2608
+ } else {
2503
2609
  charType = getCharType(char);
2504
- if (charType === Letter && textCase !== 'none')
2505
- char = getTextCase(char, textCase, !wordWidth);
2610
+ if (charType === Letter && textCase !== "none") char = getTextCase(char, textCase, !wordWidth);
2506
2611
  charWidth = canvas.measureText(char).width;
2507
2612
  if (__letterSpacing) {
2508
- if (__letterSpacing < 0)
2509
- charSize = charWidth;
2613
+ if (__letterSpacing < 0) charSize = charWidth;
2510
2614
  charWidth += __letterSpacing;
2511
2615
  }
2512
- langBreak = (charType === Single && (lastCharType === Single || lastCharType === Letter)) || (lastCharType === Single && charType !== After);
2513
- afterBreak = ((charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After));
2616
+ langBreak = charType === Single && (lastCharType === Single || lastCharType === Letter) || lastCharType === Single && charType !== After;
2617
+ afterBreak = (charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After);
2514
2618
  realWidth = paraStart && paraIndent ? width - paraIndent : width;
2515
2619
  if (wrap && (width && rowWidth + wordWidth + charWidth > realWidth)) {
2516
2620
  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();
2621
+ if (wordWidth) addWord();
2622
+ if (rowWidth) addRow();
2623
+ } else {
2624
+ if (!afterBreak) afterBreak = charType === Letter && lastCharType == After;
2625
+ if (langBreak || afterBreak || charType === Break || charType === Before || charType === Single || wordWidth + charWidth > realWidth) {
2626
+ if (wordWidth) addWord();
2627
+ if (rowWidth) addRow();
2628
+ } else {
2629
+ if (rowWidth) addRow();
2534
2630
  }
2535
2631
  }
2536
2632
  }
2537
- if (char === ' ' && paraStart !== true && (rowWidth + wordWidth) === 0) ;
2538
- else {
2633
+ if (char === " " && paraStart !== true && rowWidth + wordWidth === 0) ; else {
2539
2634
  if (charType === Break) {
2540
- if (char === ' ' && wordWidth)
2541
- addWord();
2635
+ if (char === " " && wordWidth) addWord();
2542
2636
  addChar(char, charWidth);
2543
2637
  addWord();
2544
- }
2545
- else if (langBreak || afterBreak) {
2546
- if (wordWidth)
2547
- addWord();
2638
+ } else if (langBreak || afterBreak) {
2639
+ if (wordWidth) addWord();
2548
2640
  addChar(char, charWidth);
2549
- }
2550
- else {
2641
+ } else {
2551
2642
  addChar(char, charWidth);
2552
2643
  }
2553
2644
  }
2554
2645
  lastCharType = charType;
2555
2646
  }
2556
2647
  }
2557
- if (wordWidth)
2558
- addWord();
2559
- if (rowWidth)
2560
- addRow();
2648
+ if (wordWidth) addWord();
2649
+ if (rowWidth) addRow();
2561
2650
  rows.length > 0 && (rows[rows.length - 1].paraEnd = true);
2562
- }
2563
- else {
2564
- content.split('\n').forEach(content => {
2651
+ } else {
2652
+ content.split("\n").forEach(content => {
2565
2653
  textDrawData.paraNumber++;
2566
2654
  rowWidth = canvas.measureText(content).width;
2567
- rows.push({ x: paraIndent || 0, text: content, width: rowWidth, paraStart: true });
2568
- if (findMaxWidth)
2569
- setMaxWidth();
2655
+ rows.push({
2656
+ x: paraIndent || 0,
2657
+ text: content,
2658
+ width: rowWidth,
2659
+ paraStart: true
2660
+ });
2661
+ if (findMaxWidth) setMaxWidth();
2570
2662
  });
2571
2663
  }
2572
2664
  }
2665
+
2573
2666
  function addChar(char, width) {
2574
- if (charSize && !startCharSize)
2575
- startCharSize = charSize;
2576
- word.data.push({ char, width });
2667
+ if (charSize && !startCharSize) startCharSize = charSize;
2668
+ word.data.push({
2669
+ char: char,
2670
+ width: width
2671
+ });
2577
2672
  wordWidth += width;
2578
2673
  }
2674
+
2579
2675
  function addWord() {
2580
2676
  rowWidth += wordWidth;
2581
2677
  word.width = wordWidth;
2582
2678
  row.words.push(word);
2583
- word = { data: [] };
2679
+ word = {
2680
+ data: []
2681
+ };
2584
2682
  wordWidth = 0;
2585
2683
  }
2684
+
2586
2685
  function addRow() {
2587
2686
  if (paraStart) {
2588
2687
  textDrawData.paraNumber++;
@@ -2595,52 +2694,53 @@ function addRow() {
2595
2694
  startCharSize = 0;
2596
2695
  }
2597
2696
  row.width = rowWidth;
2598
- if (bounds.width)
2599
- trimRight(row);
2600
- else if (findMaxWidth)
2601
- setMaxWidth();
2697
+ if (bounds.width) trimRight(row); else if (findMaxWidth) setMaxWidth();
2602
2698
  rows.push(row);
2603
- row = { words: [] };
2699
+ row = {
2700
+ words: []
2701
+ };
2604
2702
  rowWidth = 0;
2605
2703
  }
2704
+
2606
2705
  function setMaxWidth() {
2607
- if (rowWidth > (textDrawData.maxWidth || 0))
2608
- textDrawData.maxWidth = rowWidth;
2706
+ if (rowWidth > (textDrawData.maxWidth || 0)) textDrawData.maxWidth = rowWidth;
2609
2707
  }
2610
2708
 
2611
2709
  const CharMode = 0;
2710
+
2612
2711
  const WordMode = 1;
2712
+
2613
2713
  const TextMode = 2;
2714
+
2614
2715
  function layoutChar(drawData, style, width, _height) {
2615
- const { rows } = drawData;
2616
- const { textAlign, paraIndent, letterSpacing } = style;
2716
+ const {rows: rows} = drawData;
2717
+ const {textAlign: textAlign, paraIndent: paraIndent, letterSpacing: letterSpacing} = style;
2617
2718
  let charX, addWordWidth, indentWidth, mode, wordChar, wordsLength;
2618
2719
  rows.forEach(row => {
2619
2720
  if (row.words) {
2620
2721
  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;
2722
+ addWordWidth = width && (textAlign === "justify" || textAlign === "both") && wordsLength > 1 ? (width - row.width - indentWidth) / (wordsLength - 1) : 0;
2723
+ mode = letterSpacing || row.isOverflow ? CharMode : addWordWidth > .01 ? WordMode : TextMode;
2724
+ if (row.isOverflow && !letterSpacing) row.textMode = true;
2625
2725
  if (mode === TextMode) {
2626
2726
  row.x += indentWidth;
2627
2727
  toTextChar$1(row);
2628
- }
2629
- else {
2728
+ } else {
2630
2729
  row.x += indentWidth;
2631
2730
  charX = row.x;
2632
2731
  row.data = [];
2633
2732
  row.words.forEach((word, index) => {
2634
2733
  if (mode === WordMode) {
2635
- wordChar = { char: '', x: charX };
2734
+ wordChar = {
2735
+ char: "",
2736
+ x: charX
2737
+ };
2636
2738
  charX = toWordChar(word.data, charX, wordChar);
2637
- if (row.isOverflow || wordChar.char !== ' ')
2638
- row.data.push(wordChar);
2639
- }
2640
- else {
2739
+ if (row.isOverflow || wordChar.char !== " ") row.data.push(wordChar);
2740
+ } else {
2641
2741
  charX = toChar(word.data, charX, row.data, row.isOverflow);
2642
2742
  }
2643
- if (addWordWidth && (!row.paraEnd || textAlign === 'both') && (index !== wordsLength - 1)) {
2743
+ if (addWordWidth && (!row.paraEnd || textAlign === "both") && index !== wordsLength - 1) {
2644
2744
  charX += addWordWidth;
2645
2745
  row.width += addWordWidth;
2646
2746
  }
@@ -2650,14 +2750,16 @@ function layoutChar(drawData, style, width, _height) {
2650
2750
  }
2651
2751
  });
2652
2752
  }
2753
+
2653
2754
  function toTextChar$1(row) {
2654
- row.text = '';
2755
+ row.text = "";
2655
2756
  row.words.forEach(word => {
2656
2757
  word.data.forEach(char => {
2657
2758
  row.text += char.char;
2658
2759
  });
2659
2760
  });
2660
2761
  }
2762
+
2661
2763
  function toWordChar(data, charX, wordChar) {
2662
2764
  data.forEach(char => {
2663
2765
  wordChar.char += char.char;
@@ -2665,9 +2767,10 @@ function toWordChar(data, charX, wordChar) {
2665
2767
  });
2666
2768
  return charX;
2667
2769
  }
2770
+
2668
2771
  function toChar(data, charX, rowData, isOverflow) {
2669
2772
  data.forEach(char => {
2670
- if (isOverflow || char.char !== ' ') {
2773
+ if (isOverflow || char.char !== " ") {
2671
2774
  char.x = charX;
2672
2775
  rowData.push(char);
2673
2776
  }
@@ -2677,38 +2780,39 @@ function toChar(data, charX, rowData, isOverflow) {
2677
2780
  }
2678
2781
 
2679
2782
  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);
2783
+ const {rows: rows, bounds: bounds} = drawData, countRows = rows.length;
2784
+ const {__lineHeight: __lineHeight, __baseLine: __baseLine, __letterSpacing: __letterSpacing, __clipText: __clipText, textAlign: textAlign, verticalAlign: verticalAlign, paraSpacing: paraSpacing, autoSizeAlign: autoSizeAlign} = style;
2785
+ let {x: x, y: y, width: width, height: height} = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
2683
2786
  let starY = __baseLine;
2684
2787
  if (__clipText && realHeight > height) {
2685
2788
  realHeight = Math.max(height, __lineHeight);
2686
- if (countRows > 1)
2687
- drawData.overflow = countRows;
2688
- }
2689
- else if (height || autoSizeAlign) {
2789
+ if (countRows > 1) drawData.overflow = countRows;
2790
+ } else if (height || autoSizeAlign) {
2690
2791
  switch (verticalAlign) {
2691
- case 'middle':
2692
- y += (height - realHeight) / 2;
2693
- break;
2694
- case 'bottom': y += (height - realHeight);
2792
+ case "middle":
2793
+ y += (height - realHeight) / 2;
2794
+ break;
2795
+
2796
+ case "bottom":
2797
+ y += height - realHeight;
2695
2798
  }
2696
2799
  }
2697
2800
  starY += y;
2698
- let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
2801
+ let row, rowX, rowWidth, layoutWidth = width || autoSizeAlign ? width : drawData.maxWidth;
2699
2802
  for (let i = 0, len = countRows; i < len; i++) {
2700
2803
  row = rows[i];
2701
2804
  row.x = x;
2702
- if (row.width < width || (row.width > width && !__clipText)) {
2805
+ if (row.width < width || row.width > width && !__clipText) {
2703
2806
  switch (textAlign) {
2704
- case 'center':
2705
- row.x += (layoutWidth - row.width) / 2;
2706
- break;
2707
- case 'right': row.x += layoutWidth - row.width;
2807
+ case "center":
2808
+ row.x += (layoutWidth - row.width) / 2;
2809
+ break;
2810
+
2811
+ case "right":
2812
+ row.x += layoutWidth - row.width;
2708
2813
  }
2709
2814
  }
2710
- if (row.paraStart && paraSpacing && i > 0)
2711
- starY += paraSpacing;
2815
+ if (row.paraStart && paraSpacing && i > 0) starY += paraSpacing;
2712
2816
  row.y = starY;
2713
2817
  starY += __lineHeight;
2714
2818
  if (drawData.overflow > i && starY > realHeight) {
@@ -2722,19 +2826,15 @@ function layoutText(drawData, style) {
2722
2826
  rowWidth = -row.width + style.fontSize + __letterSpacing;
2723
2827
  rowX -= rowWidth;
2724
2828
  rowWidth += style.fontSize;
2725
- }
2726
- else {
2829
+ } else {
2727
2830
  rowWidth -= __letterSpacing;
2728
2831
  }
2729
2832
  }
2730
- if (rowX < bounds.x)
2731
- bounds.x = rowX;
2732
- if (rowWidth > bounds.width)
2733
- bounds.width = rowWidth;
2833
+ if (rowX < bounds.x) bounds.x = rowX;
2834
+ if (rowWidth > bounds.width) bounds.width = rowWidth;
2734
2835
  if (__clipText && width && width < rowWidth) {
2735
2836
  row.isOverflow = true;
2736
- if (!drawData.overflow)
2737
- drawData.overflow = rows.length;
2837
+ if (!drawData.overflow) drawData.overflow = rows.length;
2738
2838
  }
2739
2839
  }
2740
2840
  bounds.y = y;
@@ -2742,20 +2842,16 @@ function layoutText(drawData, style) {
2742
2842
  }
2743
2843
 
2744
2844
  function clipText(drawData, style, x, width) {
2745
- if (!width)
2746
- return;
2747
- const { rows, overflow } = drawData;
2748
- let { textOverflow } = style;
2845
+ if (!width) return;
2846
+ const {rows: rows, overflow: overflow} = drawData;
2847
+ let {textOverflow: textOverflow} = style;
2749
2848
  rows.splice(overflow);
2750
- if (textOverflow && textOverflow !== 'show') {
2751
- if (textOverflow === 'hide')
2752
- textOverflow = '';
2753
- else if (textOverflow === 'ellipsis')
2754
- textOverflow = '...';
2849
+ if (textOverflow && textOverflow !== "show") {
2850
+ if (textOverflow === "hide") textOverflow = ""; else if (textOverflow === "ellipsis") textOverflow = "...";
2755
2851
  let char, charRight;
2756
2852
  const ellipsisWidth = textOverflow ? Platform.canvas.measureText(textOverflow).width : 0;
2757
2853
  const right = x + width - ellipsisWidth;
2758
- const list = style.textWrap === 'none' ? rows : [rows[overflow - 1]];
2854
+ const list = style.textWrap === "none" ? rows : [ rows[overflow - 1] ];
2759
2855
  list.forEach(row => {
2760
2856
  if (row.isOverflow && row.data) {
2761
2857
  let end = row.data.length - 1;
@@ -2764,8 +2860,7 @@ function clipText(drawData, style, x, width) {
2764
2860
  charRight = char.x + char.width;
2765
2861
  if (i === end && charRight < right) {
2766
2862
  break;
2767
- }
2768
- else if ((charRight < right && char.char !== ' ') || !i) {
2863
+ } else if (charRight < right && char.char !== " " || !i) {
2769
2864
  row.data.splice(i + 1);
2770
2865
  row.width -= char.width;
2771
2866
  break;
@@ -2773,15 +2868,18 @@ function clipText(drawData, style, x, width) {
2773
2868
  row.width -= char.width;
2774
2869
  }
2775
2870
  row.width += ellipsisWidth;
2776
- row.data.push({ char: textOverflow, x: charRight });
2777
- if (row.textMode)
2778
- toTextChar(row);
2871
+ row.data.push({
2872
+ char: textOverflow,
2873
+ x: charRight
2874
+ });
2875
+ if (row.textMode) toTextChar(row);
2779
2876
  }
2780
2877
  });
2781
2878
  }
2782
2879
  }
2880
+
2783
2881
  function toTextChar(row) {
2784
- row.text = '';
2882
+ row.text = "";
2785
2883
  row.data.forEach(char => {
2786
2884
  row.text += char.char;
2787
2885
  });
@@ -2790,122 +2888,124 @@ function toTextChar(row) {
2790
2888
 
2791
2889
  function decorationText(drawData, style) {
2792
2890
  let type;
2793
- const { fontSize, textDecoration } = style;
2891
+ const {fontSize: fontSize, textDecoration: textDecoration} = style;
2794
2892
  drawData.decorationHeight = fontSize / 11;
2795
- if (typeof textDecoration === 'object') {
2893
+ if (isObject(textDecoration)) {
2796
2894
  type = textDecoration.type;
2797
- if (textDecoration.color)
2798
- drawData.decorationColor = ColorConvert.string(textDecoration.color);
2799
- }
2800
- else
2801
- type = textDecoration;
2895
+ if (textDecoration.color) drawData.decorationColor = ColorConvert.string(textDecoration.color);
2896
+ } else type = textDecoration;
2802
2897
  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];
2898
+ case "under":
2899
+ drawData.decorationY = [ fontSize * .15 ];
2900
+ break;
2901
+
2902
+ case "delete":
2903
+ drawData.decorationY = [ -fontSize * .35 ];
2904
+ break;
2905
+
2906
+ case "under-delete":
2907
+ drawData.decorationY = [ fontSize * .15, -fontSize * .35 ];
2811
2908
  }
2812
2909
  }
2813
2910
 
2814
- const { top, right, bottom, left } = Direction4;
2911
+ const {top: top, right: right, bottom: bottom, left: left} = Direction4;
2912
+
2815
2913
  function getDrawData(content, style) {
2816
- if (typeof content !== 'string')
2817
- content = String(content);
2914
+ if (!isString(content)) content = String(content);
2818
2915
  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;
2916
+ let width = style.__getInput("width") || 0;
2917
+ let height = style.__getInput("height") || 0;
2918
+ const {textDecoration: textDecoration, __font: __font, __padding: padding} = style;
2822
2919
  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];
2920
+ if (width) x = padding[left], width -= padding[right] + padding[left]; else if (!style.autoSizeAlign) x = padding[left];
2921
+ if (height) y = padding[top], height -= padding[top] + padding[bottom]; else if (!style.autoSizeAlign) y = padding[top];
2831
2922
  }
2832
2923
  const drawData = {
2833
- bounds: { x, y, width, height },
2924
+ bounds: {
2925
+ x: x,
2926
+ y: y,
2927
+ width: width,
2928
+ height: height
2929
+ },
2834
2930
  rows: [],
2835
2931
  paraNumber: 0,
2836
2932
  font: Platform.canvas.font = __font
2837
2933
  };
2838
2934
  createRows(drawData, content, style);
2839
- if (padding)
2840
- padAutoText(padding, drawData, style, width, height);
2935
+ if (padding) padAutoText(padding, drawData, style, width, height);
2841
2936
  layoutText(drawData, style);
2842
2937
  layoutChar(drawData, style, width);
2843
- if (drawData.overflow)
2844
- clipText(drawData, style, x, width);
2845
- if (textDecoration !== 'none')
2846
- decorationText(drawData, style);
2938
+ if (drawData.overflow) clipText(drawData, style, x, width);
2939
+ if (textDecoration !== "none") decorationText(drawData, style);
2847
2940
  return drawData;
2848
2941
  }
2942
+
2849
2943
  function padAutoText(padding, drawData, style, width, height) {
2850
2944
  if (!width && style.autoSizeAlign) {
2851
2945
  switch (style.textAlign) {
2852
- case 'left':
2853
- offsetText(drawData, 'x', padding[left]);
2854
- break;
2855
- case 'right': offsetText(drawData, 'x', -padding[right]);
2946
+ case "left":
2947
+ offsetText(drawData, "x", padding[left]);
2948
+ break;
2949
+
2950
+ case "right":
2951
+ offsetText(drawData, "x", -padding[right]);
2856
2952
  }
2857
2953
  }
2858
2954
  if (!height && style.autoSizeAlign) {
2859
2955
  switch (style.verticalAlign) {
2860
- case 'top':
2861
- offsetText(drawData, 'y', padding[top]);
2862
- break;
2863
- case 'bottom': offsetText(drawData, 'y', -padding[bottom]);
2956
+ case "top":
2957
+ offsetText(drawData, "y", padding[top]);
2958
+ break;
2959
+
2960
+ case "bottom":
2961
+ offsetText(drawData, "y", -padding[bottom]);
2864
2962
  }
2865
2963
  }
2866
2964
  }
2965
+
2867
2966
  function offsetText(drawData, attrName, value) {
2868
- const { bounds, rows } = drawData;
2967
+ const {bounds: bounds, rows: rows} = drawData;
2869
2968
  bounds[attrName] += value;
2870
- for (let i = 0; i < rows.length; i++)
2871
- rows[i][attrName] += value;
2969
+ for (let i = 0; i < rows.length; i++) rows[i][attrName] += value;
2872
2970
  }
2873
2971
 
2874
2972
  const TextConvertModule = {
2875
- getDrawData
2973
+ getDrawData: getDrawData
2876
2974
  };
2877
2975
 
2878
2976
  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;
2977
+ const doOpacity = isNumber(opacity) && opacity < 1;
2978
+ if (isString(color)) {
2979
+ if (doOpacity && ColorConvert.object) color = ColorConvert.object(color); else return color;
2885
2980
  }
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 + ')';
2981
+ let a = isUndefined(color.a) ? 1 : color.a;
2982
+ if (doOpacity) a *= opacity;
2983
+ const rgb = color.r + "," + color.g + "," + color.b;
2984
+ return a === 1 ? "rgb(" + rgb + ")" : "rgba(" + rgb + "," + a + ")";
2891
2985
  }
2892
2986
 
2893
2987
  const ColorConvertModule = {
2894
- string
2988
+ string: string
2895
2989
  };
2896
2990
 
2897
2991
  Object.assign(TextConvert, TextConvertModule);
2992
+
2898
2993
  Object.assign(ColorConvert, ColorConvertModule);
2994
+
2899
2995
  Object.assign(Paint, PaintModule);
2996
+
2900
2997
  Object.assign(PaintImage, PaintImageModule);
2998
+
2901
2999
  Object.assign(PaintGradient, PaintGradientModule);
3000
+
2902
3001
  Object.assign(Effect, EffectModule);
2903
3002
 
2904
3003
  Object.assign(Creator, {
2905
3004
  interaction: (target, canvas, selector, options) => new Interaction(target, canvas, selector, options),
2906
3005
  hitCanvas: (options, manager) => new LeaferCanvas(options, manager),
2907
- hitCanvasManager: () => new HitCanvasManager()
3006
+ hitCanvasManager: () => new HitCanvasManager
2908
3007
  });
3008
+
2909
3009
  useCanvas();
2910
3010
 
2911
3011
  export { Interaction, Layouter, LeaferCanvas, Picker, Renderer, Selector, Watcher, useCanvas };