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