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