leafer-draw 1.7.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/web.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,106 +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
- if (item.transform) {
866
+ if (item.transform || item.scaleFixed) {
882
867
  canvas.save();
883
- canvas.transform(item.transform);
884
- if (item.blendMode)
885
- canvas.blendMode = item.blendMode;
868
+ if (item.transform) canvas.transform(item.transform);
869
+ if (item.scaleFixed) {
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);
872
+ }
873
+ if (item.blendMode) canvas.blendMode = item.blendMode;
886
874
  fillPathOrText(ui, canvas);
887
875
  canvas.restore();
888
- }
889
- else {
876
+ } else {
890
877
  if (item.blendMode) {
891
878
  canvas.saveBlendMode(item.blendMode);
892
879
  fillPathOrText(ui, canvas);
893
880
  canvas.restoreBlendMode();
894
- }
895
- else
896
- fillPathOrText(ui, canvas);
881
+ } else fillPathOrText(ui, canvas);
897
882
  }
898
883
  }
899
884
  }
885
+
900
886
  function fillPathOrText(ui, canvas) {
901
- 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();
902
888
  }
903
889
 
904
890
  function strokeText(stroke, ui, canvas) {
905
891
  switch (ui.__.strokeAlign) {
906
- case 'center':
907
- drawCenter$1(stroke, 1, ui, canvas);
908
- break;
909
- case 'inside':
910
- drawAlign(stroke, 'inside', ui, canvas);
911
- break;
912
- case 'outside':
913
- ui.__.__fillAfterStroke ? drawCenter$1(stroke, 2, ui, canvas) : drawAlign(stroke, 'outside', ui, canvas);
914
- 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;
915
903
  }
916
904
  }
905
+
917
906
  function drawCenter$1(stroke, strokeWidthScale, ui, canvas) {
918
907
  const data = ui.__;
919
- canvas.setStroke(!data.__isStrokes && stroke, data.strokeWidth * strokeWidthScale, data);
920
- data.__isStrokes ? drawStrokesStyle(stroke, true, ui, canvas) : drawTextStroke(ui, canvas);
908
+ if (core.isObject(stroke)) {
909
+ drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas);
910
+ } else {
911
+ canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
912
+ drawTextStroke(ui, canvas);
913
+ }
921
914
  }
915
+
922
916
  function drawAlign(stroke, align, ui, canvas) {
923
917
  const out = canvas.getSameCanvas(true, true);
924
918
  out.font = ui.__.__font;
925
919
  drawCenter$1(stroke, 2, ui, out);
926
- out.blendMode = align === 'outside' ? 'destination-out' : 'destination-in';
920
+ out.blendMode = align === "outside" ? "destination-out" : "destination-in";
927
921
  fillText(ui, out);
928
- out.blendMode = 'normal';
929
- copyWorld(canvas, out, ui);
922
+ out.blendMode = "normal";
923
+ core.LeafHelper.copyCanvasByWorld(ui, canvas, out);
930
924
  out.recycle(ui.__nowWorld);
931
925
  }
932
- function copyWorld(canvas, out, ui) {
933
- if (ui.__worldFlipped || core.Platform.fullImageShadow)
934
- canvas.copyWorldByReset(out, ui.__nowWorld);
935
- else
936
- canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds);
937
- }
926
+
938
927
  function drawTextStroke(ui, canvas) {
939
928
  let row, data = ui.__.__textDrawData;
940
- const { rows, decorationY } = data;
929
+ const {rows: rows, decorationY: decorationY} = data;
941
930
  for (let i = 0, len = rows.length; i < len; i++) {
942
931
  row = rows[i];
943
- if (row.text)
944
- canvas.strokeText(row.text, row.x, row.y);
945
- else if (row.data)
946
- 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
+ });
947
935
  }
948
936
  if (decorationY) {
949
- const { decorationHeight } = data;
937
+ const {decorationHeight: decorationHeight} = data;
950
938
  rows.forEach(row => decorationY.forEach(value => canvas.strokeRect(row.x, row.y + value, row.width, decorationHeight)));
951
939
  }
952
940
  }
953
- function drawStrokesStyle(strokes, isText, ui, canvas) {
941
+
942
+ function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas) {
954
943
  let item;
944
+ const data = ui.__, {__hasMultiStrokeStyle: __hasMultiStrokeStyle} = data;
945
+ __hasMultiStrokeStyle || canvas.setStroke(undefined, data.__strokeWidth * strokeWidthScale, data);
955
946
  for (let i = 0, len = strokes.length; i < len; i++) {
956
947
  item = strokes[i];
957
- if (item.image && draw.PaintImage.checkImage(ui, canvas, item, false))
958
- continue;
948
+ if (item.image && draw.PaintImage.checkImage(ui, canvas, item, false)) continue;
959
949
  if (item.style) {
960
- canvas.strokeStyle = item.style;
950
+ if (__hasMultiStrokeStyle) {
951
+ const {strokeStyle: strokeStyle} = item;
952
+ strokeStyle ? canvas.setStroke(item.style, data.__getRealStrokeWidth(strokeStyle) * strokeWidthScale, data, strokeStyle) : canvas.setStroke(item.style, data.__strokeWidth * strokeWidthScale, data);
953
+ } else canvas.strokeStyle = item.style;
961
954
  if (item.blendMode) {
962
955
  canvas.saveBlendMode(item.blendMode);
963
956
  isText ? drawTextStroke(ui, canvas) : canvas.stroke();
964
957
  canvas.restoreBlendMode();
965
- }
966
- else {
958
+ } else {
967
959
  isText ? drawTextStroke(ui, canvas) : canvas.stroke();
968
960
  }
969
961
  }
@@ -972,77 +964,81 @@ function drawStrokesStyle(strokes, isText, ui, canvas) {
972
964
 
973
965
  function stroke(stroke, ui, canvas) {
974
966
  const data = ui.__;
975
- if (!data.__strokeWidth)
976
- return;
967
+ if (!data.__strokeWidth) return;
977
968
  if (data.__font) {
978
969
  strokeText(stroke, ui, canvas);
979
- }
980
- else {
970
+ } else {
981
971
  switch (data.strokeAlign) {
982
- case 'center':
983
- drawCenter(stroke, 1, ui, canvas);
984
- break;
985
- case 'inside':
986
- drawInside(stroke, ui, canvas);
987
- break;
988
- case 'outside':
989
- drawOutside(stroke, ui, canvas);
990
- 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;
991
983
  }
992
984
  }
993
985
  }
986
+
994
987
  function strokes(strokes, ui, canvas) {
995
988
  stroke(strokes, ui, canvas);
996
989
  }
990
+
997
991
  function drawCenter(stroke, strokeWidthScale, ui, canvas) {
998
992
  const data = ui.__;
999
- canvas.setStroke(!data.__isStrokes && stroke, data.__strokeWidth * strokeWidthScale, data);
1000
- data.__isStrokes ? drawStrokesStyle(stroke, false, ui, canvas) : canvas.stroke();
1001
- if (data.__useArrow)
1002
- draw.Paint.strokeArrow(stroke, ui, canvas);
993
+ if (core.isObject(stroke)) {
994
+ drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas);
995
+ } else {
996
+ canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
997
+ canvas.stroke();
998
+ }
999
+ if (data.__useArrow) draw.Paint.strokeArrow(stroke, ui, canvas);
1003
1000
  }
1001
+
1004
1002
  function drawInside(stroke, ui, canvas) {
1005
1003
  canvas.save();
1006
1004
  canvas.clipUI(ui);
1007
1005
  drawCenter(stroke, 2, ui, canvas);
1008
1006
  canvas.restore();
1009
1007
  }
1008
+
1010
1009
  function drawOutside(stroke, ui, canvas) {
1011
1010
  const data = ui.__;
1012
1011
  if (data.__fillAfterStroke) {
1013
1012
  drawCenter(stroke, 2, ui, canvas);
1014
- }
1015
- else {
1016
- const { renderBounds } = ui.__layout;
1013
+ } else {
1014
+ const {renderBounds: renderBounds} = ui.__layout;
1017
1015
  const out = canvas.getSameCanvas(true, true);
1018
1016
  ui.__drawRenderPath(out);
1019
1017
  drawCenter(stroke, 2, ui, out);
1020
1018
  out.clipUI(data);
1021
1019
  out.clearWorld(renderBounds);
1022
- copyWorld(canvas, out, ui);
1020
+ core.LeafHelper.copyCanvasByWorld(ui, canvas, out);
1023
1021
  out.recycle(ui.__nowWorld);
1024
1022
  }
1025
1023
  }
1026
1024
 
1027
- const { getSpread, getOuterOf, getByMove, getIntersectData } = core.BoundsHelper;
1025
+ const {getSpread: getSpread, getOuterOf: getOuterOf, getByMove: getByMove, getIntersectData: getIntersectData} = core.BoundsHelper;
1026
+
1028
1027
  function shape(ui, current, options) {
1029
1028
  const canvas = current.getSameCanvas();
1030
1029
  const nowWorld = ui.__nowWorld;
1031
- let bounds, fitMatrix, shapeBounds, worldCanvas;
1032
- let { scaleX, scaleY } = nowWorld;
1033
- if (scaleX < 0)
1034
- scaleX = -scaleX;
1035
- if (scaleY < 0)
1036
- scaleY = -scaleY;
1030
+ let bounds, matrix, fitMatrix, shapeBounds, worldCanvas;
1031
+ let {scaleX: scaleX, scaleY: scaleY} = nowWorld;
1032
+ if (scaleX < 0) scaleX = -scaleX;
1033
+ if (scaleY < 0) scaleY = -scaleY;
1037
1034
  if (current.bounds.includes(nowWorld)) {
1038
1035
  worldCanvas = canvas;
1039
1036
  bounds = shapeBounds = nowWorld;
1040
- }
1041
- else {
1042
- const { renderShapeSpread: spread } = ui.__layout;
1043
- const worldClipBounds = getIntersectData(spread ? getSpread(current.bounds, scaleX === scaleY ? spread * scaleX : [spread * scaleY, spread * scaleX]) : current.bounds, nowWorld);
1037
+ } else {
1038
+ const {renderShapeSpread: spread} = ui.__layout;
1039
+ const worldClipBounds = getIntersectData(spread ? getSpread(current.bounds, scaleX === scaleY ? spread * scaleX : [ spread * scaleY, spread * scaleX ]) : current.bounds, nowWorld);
1044
1040
  fitMatrix = current.bounds.getFitMatrix(worldClipBounds);
1045
- let { a: fitScaleX, d: fitScaleY } = fitMatrix;
1041
+ let {a: fitScaleX, d: fitScaleY} = fitMatrix;
1046
1042
  if (fitMatrix.a < 1) {
1047
1043
  worldCanvas = current.getSameCanvas();
1048
1044
  ui.__renderShape(worldCanvas, options);
@@ -1051,215 +1047,262 @@ function shape(ui, current, options) {
1051
1047
  }
1052
1048
  shapeBounds = getOuterOf(nowWorld, fitMatrix);
1053
1049
  bounds = getByMove(shapeBounds, -fitMatrix.e, -fitMatrix.f);
1054
- if (options.matrix) {
1055
- const { matrix } = options;
1056
- fitMatrix.multiply(matrix);
1057
- fitScaleX *= matrix.scaleX;
1058
- fitScaleY *= matrix.scaleY;
1059
- }
1060
- options = Object.assign(Object.assign({}, options), { matrix: fitMatrix.withScale(fitScaleX, fitScaleY) });
1050
+ const userMatrix = options.matrix;
1051
+ if (userMatrix) {
1052
+ matrix = new core.Matrix(fitMatrix);
1053
+ matrix.multiply(userMatrix);
1054
+ fitScaleX *= userMatrix.scaleX;
1055
+ fitScaleY *= userMatrix.scaleY;
1056
+ } else matrix = fitMatrix;
1057
+ matrix.withScale(fitScaleX, fitScaleY);
1058
+ options = Object.assign(Object.assign({}, options), {
1059
+ matrix: matrix
1060
+ });
1061
1061
  }
1062
1062
  ui.__renderShape(canvas, options);
1063
1063
  return {
1064
- canvas, matrix: fitMatrix, bounds,
1065
- worldCanvas, shapeBounds, scaleX, scaleY
1064
+ canvas: canvas,
1065
+ matrix: matrix,
1066
+ fitMatrix: fitMatrix,
1067
+ bounds: bounds,
1068
+ worldCanvas: worldCanvas,
1069
+ shapeBounds: shapeBounds,
1070
+ scaleX: scaleX,
1071
+ scaleY: scaleY
1066
1072
  };
1067
1073
  }
1068
1074
 
1069
1075
  let recycleMap;
1070
- const { stintSet } = core.DataHelper, { hasTransparent: hasTransparent$1 } = draw.ColorConvert;
1076
+
1077
+ const {stintSet: stintSet} = core.DataHelper, {hasTransparent: hasTransparent$1} = draw.ColorConvert;
1078
+
1071
1079
  function compute(attrName, ui) {
1072
1080
  const data = ui.__, leafPaints = [];
1073
1081
  let paints = data.__input[attrName], isAlphaPixel, isTransparent;
1074
- if (!(paints instanceof Array))
1075
- paints = [paints];
1082
+ if (!core.isArray(paints)) paints = [ paints ];
1076
1083
  recycleMap = draw.PaintImage.recycleImage(attrName, data);
1084
+ let maxChildStrokeWidth;
1077
1085
  for (let i = 0, len = paints.length, item; i < len; i++) {
1078
- (item = getLeafPaint(attrName, paints[i], ui)) && leafPaints.push(item);
1086
+ if (item = getLeafPaint(attrName, paints[i], ui)) {
1087
+ leafPaints.push(item);
1088
+ if (item.strokeStyle) {
1089
+ maxChildStrokeWidth || (maxChildStrokeWidth = 1);
1090
+ if (item.strokeStyle.strokeWidth) maxChildStrokeWidth = Math.max(maxChildStrokeWidth, item.strokeStyle.strokeWidth);
1091
+ }
1092
+ }
1079
1093
  }
1080
- data['_' + attrName] = leafPaints.length ? leafPaints : undefined;
1094
+ data["_" + attrName] = leafPaints.length ? leafPaints : undefined;
1081
1095
  if (leafPaints.length) {
1082
1096
  if (leafPaints.every(item => item.isTransparent)) {
1083
- if (leafPaints.some(item => item.image))
1084
- isAlphaPixel = true;
1097
+ if (leafPaints.some(item => item.image)) isAlphaPixel = true;
1085
1098
  isTransparent = true;
1086
1099
  }
1087
1100
  }
1088
- if (attrName === 'fill') {
1089
- stintSet(data, '__isAlphaPixelFill', isAlphaPixel);
1090
- stintSet(data, '__isTransparentFill', isTransparent);
1091
- }
1092
- else {
1093
- stintSet(data, '__isAlphaPixelStroke', isAlphaPixel);
1094
- stintSet(data, '__isTransparentStroke', isTransparent);
1101
+ if (attrName === "fill") {
1102
+ stintSet(data, "__isAlphaPixelFill", isAlphaPixel);
1103
+ stintSet(data, "__isTransparentFill", isTransparent);
1104
+ } else {
1105
+ stintSet(data, "__isAlphaPixelStroke", isAlphaPixel);
1106
+ stintSet(data, "__isTransparentStroke", isTransparent);
1107
+ stintSet(data, "__hasMultiStrokeStyle", maxChildStrokeWidth);
1095
1108
  }
1096
1109
  }
1110
+
1097
1111
  function getLeafPaint(attrName, paint, ui) {
1098
- if (typeof paint !== 'object' || paint.visible === false || paint.opacity === 0)
1099
- return undefined;
1112
+ if (!core.isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
1100
1113
  let data;
1101
- const { boxBounds } = ui.__layout;
1114
+ const {boxBounds: boxBounds} = ui.__layout;
1102
1115
  switch (paint.type) {
1103
- case 'image':
1104
- data = draw.PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
1105
- break;
1106
- case 'linear':
1107
- data = draw.PaintGradient.linearGradient(paint, boxBounds);
1108
- break;
1109
- case 'radial':
1110
- data = draw.PaintGradient.radialGradient(paint, boxBounds);
1111
- break;
1112
- case 'angular':
1113
- data = draw.PaintGradient.conicGradient(paint, boxBounds);
1114
- break;
1115
- case 'solid':
1116
- const { type, color, opacity } = paint;
1117
- data = { type, style: draw.ColorConvert.string(color, opacity) };
1118
- break;
1119
- default:
1120
- if (paint.r !== undefined)
1121
- data = { type: 'solid', style: draw.ColorConvert.string(paint) };
1116
+ case "image":
1117
+ data = draw.PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
1118
+ break;
1119
+
1120
+ case "linear":
1121
+ data = draw.PaintGradient.linearGradient(paint, boxBounds);
1122
+ break;
1123
+
1124
+ case "radial":
1125
+ data = draw.PaintGradient.radialGradient(paint, boxBounds);
1126
+ break;
1127
+
1128
+ case "angular":
1129
+ data = draw.PaintGradient.conicGradient(paint, boxBounds);
1130
+ break;
1131
+
1132
+ case "solid":
1133
+ const {type: type, color: color, opacity: opacity} = paint;
1134
+ data = {
1135
+ type: type,
1136
+ style: draw.ColorConvert.string(color, opacity)
1137
+ };
1138
+ break;
1139
+
1140
+ default:
1141
+ if (!core.isUndefined(paint.r)) data = {
1142
+ type: "solid",
1143
+ style: draw.ColorConvert.string(paint)
1144
+ };
1122
1145
  }
1123
1146
  if (data) {
1124
- if (typeof data.style === 'string' && hasTransparent$1(data.style))
1125
- data.isTransparent = true;
1126
- if (paint.blendMode)
1127
- data.blendMode = paint.blendMode;
1147
+ if (core.isString(data.style) && hasTransparent$1(data.style)) data.isTransparent = true;
1148
+ if (paint.style) {
1149
+ if (paint.style.strokeWidth === 0) return undefined;
1150
+ data.strokeStyle = paint.style;
1151
+ }
1152
+ if (paint.editing) data.editing = paint.editing;
1153
+ if (paint.blendMode) data.blendMode = paint.blendMode;
1128
1154
  }
1129
1155
  return data;
1130
1156
  }
1131
1157
 
1132
1158
  const PaintModule = {
1133
- compute,
1134
- fill,
1135
- fills,
1136
- fillPathOrText,
1137
- fillText,
1138
- stroke,
1139
- strokes,
1140
- strokeText,
1141
- drawTextStroke,
1142
- shape
1159
+ compute: compute,
1160
+ fill: fill,
1161
+ fills: fills,
1162
+ fillPathOrText: fillPathOrText,
1163
+ fillText: fillText,
1164
+ stroke: stroke,
1165
+ strokes: strokes,
1166
+ strokeText: strokeText,
1167
+ drawTextStroke: drawTextStroke,
1168
+ shape: shape
1143
1169
  };
1144
1170
 
1145
- let origin = {};
1146
- const { get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, scale: scaleHelper, rotate, skew: skewHelper } = core.MatrixHelper;
1171
+ let origin = {}, tempMatrix = core.getMatrixData();
1172
+
1173
+ const {get: get$3, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, multiplyParent: multiplyParent, scale: scaleHelper, rotate: rotate, skew: skewHelper} = core.MatrixHelper;
1174
+
1147
1175
  function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
1148
1176
  const transform = get$3();
1149
1177
  translate$1(transform, box.x + x, box.y + y);
1150
1178
  scaleHelper(transform, scaleX, scaleY);
1151
- if (rotation)
1152
- rotateOfOuter$1(transform, { x: box.x + box.width / 2, y: box.y + box.height / 2 }, rotation);
1179
+ if (rotation) rotateOfOuter$1(transform, {
1180
+ x: box.x + box.width / 2,
1181
+ y: box.y + box.height / 2
1182
+ }, rotation);
1153
1183
  data.transform = transform;
1154
1184
  }
1155
- function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew) {
1185
+
1186
+ function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipSize) {
1156
1187
  const transform = get$3();
1157
- if (rotation)
1158
- rotate(transform, rotation);
1159
- if (skew)
1160
- skewHelper(transform, skew.x, skew.y);
1161
- if (scaleX)
1162
- scaleHelper(transform, scaleX, scaleY);
1163
- translate$1(transform, box.x + x, box.y + y);
1188
+ layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
1189
+ if (clipSize) {
1190
+ tempMatrix.a = box.width / clipSize.width, tempMatrix.d = box.height / clipSize.height;
1191
+ multiplyParent(transform, tempMatrix);
1192
+ }
1164
1193
  data.transform = transform;
1165
1194
  }
1166
- function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, align) {
1195
+
1196
+ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, skew, align, freeTransform) {
1167
1197
  const transform = get$3();
1168
- if (rotation) {
1169
- if (align === 'center') {
1170
- rotateOfOuter$1(transform, { x: width / 2, y: height / 2 }, rotation);
1171
- }
1172
- else {
1173
- rotate(transform, rotation);
1174
- switch (rotation) {
1175
- case 90:
1198
+ if (freeTransform) {
1199
+ layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
1200
+ } else {
1201
+ if (rotation) {
1202
+ if (align === "center") {
1203
+ rotateOfOuter$1(transform, {
1204
+ x: width / 2,
1205
+ y: height / 2
1206
+ }, rotation);
1207
+ } else {
1208
+ rotate(transform, rotation);
1209
+ switch (rotation) {
1210
+ case 90:
1176
1211
  translate$1(transform, height, 0);
1177
1212
  break;
1178
- case 180:
1213
+
1214
+ case 180:
1179
1215
  translate$1(transform, width, height);
1180
1216
  break;
1181
- case 270:
1217
+
1218
+ case 270:
1182
1219
  translate$1(transform, 0, width);
1183
1220
  break;
1221
+ }
1184
1222
  }
1185
1223
  }
1224
+ origin.x = box.x + x;
1225
+ origin.y = box.y + y;
1226
+ translate$1(transform, origin.x, origin.y);
1227
+ if (scaleX) scaleOfOuter$1(transform, origin, scaleX, scaleY);
1186
1228
  }
1187
- origin.x = box.x + x;
1188
- origin.y = box.y + y;
1189
- translate$1(transform, origin.x, origin.y);
1190
- if (scaleX)
1191
- scaleOfOuter$1(transform, origin, scaleX, scaleY);
1192
1229
  data.transform = transform;
1193
1230
  }
1194
1231
 
1195
- const { get: get$2, translate } = core.MatrixHelper;
1196
- const tempBox = new core.Bounds();
1232
+ function layout(transform, box, x, y, scaleX, scaleY, rotation, skew) {
1233
+ if (rotation) rotate(transform, rotation);
1234
+ if (skew) skewHelper(transform, skew.x, skew.y);
1235
+ if (scaleX) scaleHelper(transform, scaleX, scaleY);
1236
+ translate$1(transform, box.x + x, box.y + y);
1237
+ }
1238
+
1239
+ const {get: get$2, translate: translate} = core.MatrixHelper;
1240
+
1241
+ const tempBox = new core.Bounds;
1242
+
1197
1243
  const tempScaleData = {};
1244
+
1198
1245
  const tempImage = {};
1246
+
1199
1247
  function createData(leafPaint, image, paint, box) {
1200
- const { changeful, sync, editing } = paint;
1201
- if (changeful)
1202
- leafPaint.changeful = changeful;
1203
- if (sync)
1204
- leafPaint.sync = sync;
1205
- if (editing)
1206
- leafPaint.editing = editing;
1248
+ const {changeful: changeful, sync: sync, scaleFixed: scaleFixed} = paint;
1249
+ if (changeful) leafPaint.changeful = changeful;
1250
+ if (sync) leafPaint.sync = sync;
1251
+ if (scaleFixed) leafPaint.scaleFixed = scaleFixed;
1207
1252
  leafPaint.data = getPatternData(paint, box, image);
1208
1253
  }
1254
+
1209
1255
  function getPatternData(paint, box, image) {
1210
- if (paint.padding)
1211
- box = tempBox.set(box).shrink(paint.padding);
1212
- if (paint.mode === 'strench')
1213
- paint.mode = 'stretch';
1214
- let { width, height } = image;
1215
- const { opacity, mode, align, offset, scale, size, rotation, skew, repeat, filters } = paint;
1256
+ if (paint.padding) box = tempBox.set(box).shrink(paint.padding);
1257
+ if (paint.mode === "strench") paint.mode = "stretch";
1258
+ let {width: width, height: height} = image;
1259
+ 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;
1216
1260
  const sameBox = box.width === width && box.height === height;
1217
- const data = { mode };
1218
- const swapSize = align !== 'center' && (rotation || 0) % 180 === 90;
1261
+ const data = {
1262
+ mode: mode
1263
+ };
1264
+ const swapSize = align !== "center" && (rotation || 0) % 180 === 90;
1219
1265
  core.BoundsHelper.set(tempImage, 0, 0, swapSize ? height : width, swapSize ? width : height);
1220
1266
  let scaleX, scaleY;
1221
- if (!mode || mode === 'cover' || mode === 'fit') {
1267
+ if (!mode || mode === "cover" || mode === "fit") {
1222
1268
  if (!sameBox || rotation) {
1223
- scaleX = scaleY = core.BoundsHelper.getFitScale(box, tempImage, mode !== 'fit');
1269
+ scaleX = scaleY = core.BoundsHelper.getFitScale(box, tempImage, mode !== "fit");
1224
1270
  core.BoundsHelper.put(box, image, align, scaleX, false, tempImage);
1225
1271
  core.BoundsHelper.scale(tempImage, scaleX, scaleY, true);
1226
1272
  }
1227
- }
1228
- else {
1273
+ } else {
1229
1274
  if (scale || size) {
1230
1275
  core.MathHelper.getScaleData(scale, size, image, tempScaleData);
1231
1276
  scaleX = tempScaleData.scaleX;
1232
1277
  scaleY = tempScaleData.scaleY;
1233
1278
  }
1234
- if (align) {
1235
- if (scaleX)
1236
- core.BoundsHelper.scale(tempImage, scaleX, scaleY, true);
1237
- core.AlignHelper.toPoint(align, tempImage, box, tempImage, true, true);
1279
+ if (align || gap || repeat) {
1280
+ if (scaleX) core.BoundsHelper.scale(tempImage, scaleX, scaleY, true);
1281
+ if (align) core.AlignHelper.toPoint(align, tempImage, box, tempImage, true, true);
1238
1282
  }
1239
1283
  }
1240
- if (offset)
1241
- core.PointHelper.move(tempImage, offset);
1284
+ if (offset) core.PointHelper.move(tempImage, offset);
1242
1285
  switch (mode) {
1243
- case 'stretch':
1244
- if (!sameBox)
1245
- width = box.width, height = box.height;
1246
- break;
1247
- case 'normal':
1248
- case 'clip':
1249
- if (tempImage.x || tempImage.y || scaleX || rotation || skew)
1250
- clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew);
1251
- break;
1252
- case 'repeat':
1253
- if (!sameBox || scaleX || rotation)
1254
- repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, align);
1255
- if (!repeat)
1256
- data.repeat = 'repeat';
1257
- break;
1258
- case 'fit':
1259
- case 'cover':
1260
- default:
1261
- if (scaleX)
1262
- fillOrFitMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
1286
+ case "stretch":
1287
+ if (!sameBox) width = box.width, height = box.height;
1288
+ break;
1289
+
1290
+ case "normal":
1291
+ case "clip":
1292
+ if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew) clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, paint.clipSize);
1293
+ break;
1294
+
1295
+ case "repeat":
1296
+ if (!sameBox || scaleX || rotation || skew) repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform);
1297
+ if (!repeat) data.repeat = "repeat";
1298
+ const count = core.isObject(repeat);
1299
+ if (gap || count) data.gap = getGapData(gap, count && repeat, tempImage.width, tempImage.height, box);
1300
+ break;
1301
+
1302
+ case "fit":
1303
+ case "cover":
1304
+ default:
1305
+ if (scaleX) fillOrFitMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
1263
1306
  }
1264
1307
  if (!data.transform) {
1265
1308
  if (box.x || box.y) {
@@ -1267,49 +1310,69 @@ function getPatternData(paint, box, image) {
1267
1310
  translate(data.transform, box.x, box.y);
1268
1311
  }
1269
1312
  }
1270
- if (scaleX && mode !== 'stretch') {
1313
+ if (scaleX && mode !== "stretch") {
1271
1314
  data.scaleX = scaleX;
1272
1315
  data.scaleY = scaleY;
1273
1316
  }
1274
1317
  data.width = width;
1275
1318
  data.height = height;
1276
- if (opacity)
1277
- data.opacity = opacity;
1278
- if (filters)
1279
- data.filters = filters;
1280
- if (repeat)
1281
- data.repeat = typeof repeat === 'string' ? (repeat === 'x' ? 'repeat-x' : 'repeat-y') : 'repeat';
1319
+ if (opacity) data.opacity = opacity;
1320
+ if (filters) data.filters = filters;
1321
+ if (repeat) data.repeat = core.isString(repeat) ? repeat === "x" ? "repeat-x" : "repeat-y" : "repeat";
1282
1322
  return data;
1283
1323
  }
1284
1324
 
1285
- let cache, box = new core.Bounds();
1286
- const { isSame } = core.BoundsHelper;
1325
+ function getGapData(gap, repeat, width, height, box) {
1326
+ let xGap, yGap;
1327
+ if (core.isObject(gap)) xGap = gap.x, yGap = gap.y; else xGap = yGap = gap;
1328
+ return {
1329
+ x: getGapValue(xGap, width, box.width, repeat && repeat.x),
1330
+ y: getGapValue(yGap, height, box.height, repeat && repeat.y)
1331
+ };
1332
+ }
1333
+
1334
+ function getGapValue(gap, size, totalSize, rows) {
1335
+ const auto = core.isString(gap) || rows;
1336
+ const remain = rows ? totalSize - rows * size : totalSize % size;
1337
+ const value = auto ? remain / ((rows || Math.floor(totalSize / size)) - 1) : gap;
1338
+ return gap === "auto" ? value < 0 ? 0 : value : value;
1339
+ }
1340
+
1341
+ let cache, box = new core.Bounds;
1342
+
1343
+ const {isSame: isSame} = core.BoundsHelper;
1344
+
1287
1345
  function image(ui, attrName, paint, boxBounds, firstUse) {
1288
1346
  let leafPaint, event;
1289
1347
  const image = core.ImageManager.get(paint);
1290
1348
  if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
1291
1349
  leafPaint = cache.leafPaint;
1292
- }
1293
- else {
1294
- leafPaint = { type: paint.type, image };
1295
- if (image.hasAlphaPixel)
1296
- leafPaint.isTransparent = true;
1297
- cache = image.use > 1 ? { leafPaint, paint, boxBounds: box.set(boxBounds) } : null;
1298
- }
1299
- if (firstUse || image.loading)
1300
- event = { image, attrName, attrValue: paint };
1350
+ } else {
1351
+ leafPaint = {
1352
+ type: paint.type,
1353
+ image: image
1354
+ };
1355
+ if (image.hasAlphaPixel) leafPaint.isTransparent = true;
1356
+ cache = image.use > 1 ? {
1357
+ leafPaint: leafPaint,
1358
+ paint: paint,
1359
+ boxBounds: box.set(boxBounds)
1360
+ } : null;
1361
+ }
1362
+ if (firstUse || image.loading) event = {
1363
+ image: image,
1364
+ attrName: attrName,
1365
+ attrValue: paint
1366
+ };
1301
1367
  if (image.ready) {
1302
1368
  checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds);
1303
1369
  if (firstUse) {
1304
1370
  onLoad(ui, event);
1305
1371
  onLoadSuccess(ui, event);
1306
1372
  }
1307
- }
1308
- else if (image.error) {
1309
- if (firstUse)
1310
- onLoadError(ui, event, image.error);
1311
- }
1312
- else {
1373
+ } else if (image.error) {
1374
+ if (firstUse) onLoadError(ui, event, image.error);
1375
+ } else {
1313
1376
  if (firstUse) {
1314
1377
  ignoreRender(ui, true);
1315
1378
  onLoad(ui, event);
@@ -1318,107 +1381,105 @@ function image(ui, attrName, paint, boxBounds, firstUse) {
1318
1381
  ignoreRender(ui, false);
1319
1382
  if (!ui.destroyed) {
1320
1383
  if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds)) {
1321
- if (image.hasAlphaPixel)
1322
- ui.__layout.hitCanvasChanged = true;
1323
- ui.forceUpdate('surface');
1384
+ if (image.hasAlphaPixel) ui.__layout.hitCanvasChanged = true;
1385
+ ui.forceUpdate("surface");
1324
1386
  }
1325
1387
  onLoadSuccess(ui, event);
1326
1388
  }
1327
1389
  leafPaint.loadId = undefined;
1328
- }, (error) => {
1390
+ }, error => {
1329
1391
  ignoreRender(ui, false);
1330
1392
  onLoadError(ui, event, error);
1331
1393
  leafPaint.loadId = undefined;
1332
1394
  });
1333
1395
  if (ui.placeholderColor) {
1334
- if (!ui.placeholderDelay)
1335
- image.isPlacehold = true;
1336
- else
1337
- setTimeout(() => {
1338
- if (!image.ready) {
1339
- image.isPlacehold = true;
1340
- ui.forceUpdate('surface');
1341
- }
1342
- }, ui.placeholderDelay);
1396
+ if (!ui.placeholderDelay) image.isPlacehold = true; else setTimeout(() => {
1397
+ if (!image.ready) {
1398
+ image.isPlacehold = true;
1399
+ ui.forceUpdate("surface");
1400
+ }
1401
+ }, ui.placeholderDelay);
1343
1402
  }
1344
1403
  }
1345
1404
  return leafPaint;
1346
1405
  }
1406
+
1347
1407
  function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
1348
- if (attrName === 'fill' && !ui.__.__naturalWidth) {
1408
+ if (attrName === "fill" && !ui.__.__naturalWidth) {
1349
1409
  const data = ui.__;
1350
1410
  data.__naturalWidth = image.width / data.pixelRatio;
1351
1411
  data.__naturalHeight = image.height / data.pixelRatio;
1352
1412
  if (data.__autoSide) {
1353
- ui.forceUpdate('width');
1413
+ ui.forceUpdate("width");
1354
1414
  if (ui.__proxyData) {
1355
- ui.setProxyAttr('width', data.width);
1356
- ui.setProxyAttr('height', data.height);
1415
+ ui.setProxyAttr("width", data.width);
1416
+ ui.setProxyAttr("height", data.height);
1357
1417
  }
1358
1418
  return false;
1359
1419
  }
1360
1420
  }
1361
- if (!leafPaint.data)
1362
- createData(leafPaint, image, paint, boxBounds);
1421
+ if (!leafPaint.data) createData(leafPaint, image, paint, boxBounds);
1363
1422
  return true;
1364
1423
  }
1424
+
1365
1425
  function onLoad(ui, event) {
1366
1426
  emit(ui, core.ImageEvent.LOAD, event);
1367
1427
  }
1428
+
1368
1429
  function onLoadSuccess(ui, event) {
1369
1430
  emit(ui, core.ImageEvent.LOADED, event);
1370
1431
  }
1432
+
1371
1433
  function onLoadError(ui, event, error) {
1372
1434
  event.error = error;
1373
- ui.forceUpdate('surface');
1435
+ ui.forceUpdate("surface");
1374
1436
  emit(ui, core.ImageEvent.ERROR, event);
1375
1437
  }
1438
+
1376
1439
  function emit(ui, type, data) {
1377
- if (ui.hasEvent(type))
1378
- ui.emitEvent(new core.ImageEvent(type, data));
1440
+ if (ui.hasEvent(type)) ui.emitEvent(new core.ImageEvent(type, data));
1379
1441
  }
1442
+
1380
1443
  function ignoreRender(ui, value) {
1381
- const { leafer } = ui;
1382
- if (leafer && leafer.viewReady)
1383
- leafer.renderer.ignore = value;
1444
+ const {leafer: leafer} = ui;
1445
+ if (leafer && leafer.viewReady) leafer.renderer.ignore = value;
1384
1446
  }
1385
1447
 
1386
- const { get: get$1, scale, copy: copy$1 } = core.MatrixHelper;
1387
- const { ceil, abs: abs$1 } = Math;
1448
+ const {get: get$1, scale: scale, copy: copy$1} = core.MatrixHelper;
1449
+
1450
+ const {floor: floor, max: max, abs: abs} = Math;
1451
+
1388
1452
  function createPattern(ui, paint, pixelRatio) {
1389
- let { scaleX, scaleY } = core.ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1390
- const id = scaleX + '-' + scaleY + '-' + pixelRatio;
1453
+ let {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
1454
+ const id = scaleX + "-" + scaleY + "-" + pixelRatio;
1391
1455
  if (paint.patternId !== id && !ui.destroyed) {
1392
- scaleX = abs$1(scaleX);
1393
- scaleY = abs$1(scaleY);
1394
- const { image, data } = paint;
1395
- let imageScale, imageMatrix, { width, height, scaleX: sx, scaleY: sy, transform, repeat } = data;
1456
+ const {image: image, data: data} = paint;
1457
+ let imageScale, imageMatrix, {width: width, height: height, scaleX: sx, scaleY: sy, transform: transform, repeat: repeat, gap: gap} = data;
1458
+ scaleX *= pixelRatio;
1459
+ scaleY *= pixelRatio;
1460
+ const xGap = gap && gap.x * scaleX;
1461
+ const yGap = gap && gap.y * scaleY;
1396
1462
  if (sx) {
1397
- sx = abs$1(sx);
1398
- sy = abs$1(sy);
1463
+ sx = abs(sx);
1464
+ sy = abs(sy);
1399
1465
  imageMatrix = get$1();
1400
1466
  copy$1(imageMatrix, transform);
1401
1467
  scale(imageMatrix, 1 / sx, 1 / sy);
1402
1468
  scaleX *= sx;
1403
1469
  scaleY *= sy;
1404
1470
  }
1405
- scaleX *= pixelRatio;
1406
- scaleY *= pixelRatio;
1407
1471
  width *= scaleX;
1408
1472
  height *= scaleY;
1409
1473
  const size = width * height;
1410
1474
  if (!repeat) {
1411
- if (size > core.Platform.image.maxCacheSize)
1412
- return false;
1475
+ if (size > core.Platform.image.maxCacheSize) return false;
1413
1476
  }
1414
1477
  let maxSize = core.Platform.image.maxPatternSize;
1415
1478
  if (!image.isSVG) {
1416
1479
  const imageSize = image.width * image.height;
1417
- if (maxSize > imageSize)
1418
- maxSize = imageSize;
1480
+ if (maxSize > imageSize) maxSize = imageSize;
1419
1481
  }
1420
- if (size > maxSize)
1421
- imageScale = Math.sqrt(size / maxSize);
1482
+ if (size > maxSize) imageScale = Math.sqrt(size / maxSize);
1422
1483
  if (imageScale) {
1423
1484
  scaleX /= imageScale;
1424
1485
  scaleY /= imageScale;
@@ -1432,94 +1493,95 @@ function createPattern(ui, paint, pixelRatio) {
1432
1493
  if (transform || scaleX !== 1 || scaleY !== 1) {
1433
1494
  if (!imageMatrix) {
1434
1495
  imageMatrix = get$1();
1435
- if (transform)
1436
- copy$1(imageMatrix, transform);
1496
+ if (transform) copy$1(imageMatrix, transform);
1437
1497
  }
1438
1498
  scale(imageMatrix, 1 / scaleX, 1 / scaleY);
1439
1499
  }
1440
- const canvas = image.getCanvas(ceil(width) || 1, ceil(height) || 1, data.opacity, data.filters);
1441
- const pattern = image.getPattern(canvas, repeat || (core.Platform.origin.noRepeat || 'no-repeat'), imageMatrix, paint);
1500
+ if (imageMatrix) {
1501
+ const canvasWidth = width + (xGap || 0), canvasHeight = height + (yGap || 0);
1502
+ scale(imageMatrix, canvasWidth / max(floor(canvasWidth), 1), canvasHeight / max(floor(canvasHeight), 1));
1503
+ }
1504
+ const canvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap);
1505
+ const pattern = image.getPattern(canvas, repeat || (core.Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
1442
1506
  paint.style = pattern;
1443
1507
  paint.patternId = id;
1444
1508
  return true;
1445
- }
1446
- else {
1509
+ } else {
1447
1510
  return false;
1448
1511
  }
1449
1512
  }
1450
1513
 
1451
- /******************************************************************************
1452
- Copyright (c) Microsoft Corporation.
1453
-
1454
- Permission to use, copy, modify, and/or distribute this software for any
1455
- purpose with or without fee is hereby granted.
1456
-
1457
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1458
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1459
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1460
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1461
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1462
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1463
- PERFORMANCE OF THIS SOFTWARE.
1464
- ***************************************************************************** */
1465
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
1466
-
1467
-
1468
- function __awaiter(thisArg, _arguments, P, generator) {
1469
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1470
- return new (P || (P = Promise))(function (resolve, reject) {
1471
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
1472
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
1473
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1474
- step((generator = generator.apply(thisArg, _arguments || [])).next());
1475
- });
1476
- }
1477
-
1478
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1479
- var e = new Error(message);
1480
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1514
+ function __awaiter(thisArg, _arguments, P, generator) {
1515
+ function adopt(value) {
1516
+ return value instanceof P ? value : new P(function(resolve) {
1517
+ resolve(value);
1518
+ });
1519
+ }
1520
+ return new (P || (P = Promise))(function(resolve, reject) {
1521
+ function fulfilled(value) {
1522
+ try {
1523
+ step(generator.next(value));
1524
+ } catch (e) {
1525
+ reject(e);
1526
+ }
1527
+ }
1528
+ function rejected(value) {
1529
+ try {
1530
+ step(generator["throw"](value));
1531
+ } catch (e) {
1532
+ reject(e);
1533
+ }
1534
+ }
1535
+ function step(result) {
1536
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
1537
+ }
1538
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1539
+ });
1540
+ }
1541
+
1542
+ typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
1543
+ var e = new Error(message);
1544
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1481
1545
  };
1482
1546
 
1483
- const { abs } = Math;
1484
1547
  function checkImage(ui, canvas, paint, allowDraw) {
1485
- const { scaleX, scaleY } = core.ImageManager.patternLocked ? ui.__world : ui.__nowWorld;
1486
- const { pixelRatio } = canvas, { data } = paint;
1487
- if (!data || (paint.patternId === scaleX + '-' + scaleY + '-' + pixelRatio && !draw.Export.running)) {
1548
+ const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
1549
+ const {pixelRatio: pixelRatio} = canvas, {data: data} = paint;
1550
+ if (!data || paint.patternId === scaleX + "-" + scaleY + "-" + pixelRatio && !draw.Export.running) {
1488
1551
  return false;
1489
- }
1490
- else {
1552
+ } else {
1491
1553
  if (allowDraw) {
1492
1554
  if (data.repeat) {
1493
1555
  allowDraw = false;
1494
- }
1495
- else {
1496
- if (!(paint.changeful || core.ResizeEvent.isResizing(ui) || draw.Export.running)) {
1497
- let { width, height } = data;
1498
- width *= abs(scaleX) * pixelRatio;
1499
- height *= abs(scaleY) * pixelRatio;
1556
+ } else {
1557
+ if (!(paint.changeful || core.Platform.name === "miniapp" && core.ResizeEvent.isResizing(ui) || draw.Export.running)) {
1558
+ let {width: width, height: height} = data;
1559
+ width *= scaleX * pixelRatio;
1560
+ height *= scaleY * pixelRatio;
1500
1561
  if (data.scaleX) {
1501
1562
  width *= data.scaleX;
1502
1563
  height *= data.scaleY;
1503
1564
  }
1504
- allowDraw = (width * height > core.Platform.image.maxCacheSize);
1565
+ allowDraw = width * height > core.Platform.image.maxCacheSize;
1505
1566
  }
1506
1567
  }
1507
1568
  }
1508
1569
  if (allowDraw) {
1570
+ if (ui.__.__isFastShadow) {
1571
+ canvas.fillStyle = paint.style || "#000";
1572
+ canvas.fill();
1573
+ }
1509
1574
  drawImage(ui, canvas, paint, data);
1510
1575
  return true;
1511
- }
1512
- else {
1576
+ } else {
1513
1577
  if (!paint.style || paint.sync || draw.Export.running) {
1514
1578
  createPattern(ui, paint, pixelRatio);
1515
- }
1516
- else {
1579
+ } else {
1517
1580
  if (!paint.patternTask) {
1518
- paint.patternTask = core.ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function* () {
1581
+ paint.patternTask = core.ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function*() {
1519
1582
  paint.patternTask = null;
1520
- if (canvas.bounds.hit(ui.__nowWorld))
1521
- createPattern(ui, paint, pixelRatio);
1522
- ui.forceUpdate('surface');
1583
+ if (canvas.bounds.hit(ui.__nowWorld)) createPattern(ui, paint, pixelRatio);
1584
+ ui.forceUpdate("surface");
1523
1585
  }), 300);
1524
1586
  }
1525
1587
  }
@@ -1527,39 +1589,35 @@ function checkImage(ui, canvas, paint, allowDraw) {
1527
1589
  }
1528
1590
  }
1529
1591
  }
1592
+
1530
1593
  function drawImage(ui, canvas, paint, data) {
1531
1594
  canvas.save();
1532
1595
  canvas.clipUI(ui);
1533
- if (paint.blendMode)
1534
- canvas.blendMode = paint.blendMode;
1535
- if (data.opacity)
1536
- canvas.opacity *= data.opacity;
1537
- if (data.transform)
1538
- canvas.transform(data.transform);
1596
+ if (paint.blendMode) canvas.blendMode = paint.blendMode;
1597
+ if (data.opacity) canvas.opacity *= data.opacity;
1598
+ if (data.transform) canvas.transform(data.transform);
1539
1599
  canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
1540
1600
  canvas.restore();
1541
1601
  }
1542
1602
 
1543
1603
  function recycleImage(attrName, data) {
1544
- const paints = data['_' + attrName];
1545
- if (paints instanceof Array) {
1604
+ const paints = data["_" + attrName];
1605
+ if (core.isArray(paints)) {
1546
1606
  let paint, image, recycleMap, input, url;
1547
1607
  for (let i = 0, len = paints.length; i < len; i++) {
1548
1608
  paint = paints[i];
1549
1609
  image = paint.image;
1550
1610
  url = image && image.url;
1551
1611
  if (url) {
1552
- if (!recycleMap)
1553
- recycleMap = {};
1612
+ if (!recycleMap) recycleMap = {};
1554
1613
  recycleMap[url] = true;
1555
1614
  core.ImageManager.recycle(image);
1556
1615
  if (image.loading) {
1557
1616
  if (!input) {
1558
- input = (data.__input && data.__input[attrName]) || [];
1559
- if (!(input instanceof Array))
1560
- input = [input];
1617
+ input = data.__input && data.__input[attrName] || [];
1618
+ if (!core.isArray(input)) input = [ input ];
1561
1619
  }
1562
- image.unload(paints[i].loadId, !input.some((item) => item.url === url));
1620
+ image.unload(paints[i].loadId, !input.some(item => item.url === url));
1563
1621
  }
1564
1622
  }
1565
1623
  }
@@ -1569,75 +1627,85 @@ function recycleImage(attrName, data) {
1569
1627
  }
1570
1628
 
1571
1629
  const PaintImageModule = {
1572
- image,
1573
- checkImage,
1574
- createPattern,
1575
- recycleImage,
1576
- createData,
1577
- getPatternData,
1578
- fillOrFitMode,
1579
- clipMode,
1580
- repeatMode
1630
+ image: image,
1631
+ checkImage: checkImage,
1632
+ createPattern: createPattern,
1633
+ recycleImage: recycleImage,
1634
+ createData: createData,
1635
+ getPatternData: getPatternData,
1636
+ fillOrFitMode: fillOrFitMode,
1637
+ clipMode: clipMode,
1638
+ repeatMode: repeatMode
1581
1639
  };
1582
1640
 
1583
- const { toPoint: toPoint$2 } = core.AroundHelper, { hasTransparent } = draw.ColorConvert;
1641
+ const {toPoint: toPoint$2} = core.AroundHelper, {hasTransparent: hasTransparent} = draw.ColorConvert;
1642
+
1584
1643
  const realFrom$2 = {};
1644
+
1585
1645
  const realTo$2 = {};
1646
+
1586
1647
  function linearGradient(paint, box) {
1587
- let { from, to, type, opacity } = paint;
1588
- toPoint$2(from || 'top', box, realFrom$2);
1589
- toPoint$2(to || 'bottom', box, realTo$2);
1648
+ let {from: from, to: to, type: type, opacity: opacity} = paint;
1649
+ toPoint$2(from || "top", box, realFrom$2);
1650
+ toPoint$2(to || "bottom", box, realTo$2);
1590
1651
  const style = core.Platform.canvas.createLinearGradient(realFrom$2.x, realFrom$2.y, realTo$2.x, realTo$2.y);
1591
- const data = { type, style };
1652
+ const data = {
1653
+ type: type,
1654
+ style: style
1655
+ };
1592
1656
  applyStops(data, style, paint.stops, opacity);
1593
1657
  return data;
1594
1658
  }
1659
+
1595
1660
  function applyStops(data, gradient, stops, opacity) {
1596
1661
  if (stops) {
1597
1662
  let stop, color, offset, isTransparent;
1598
1663
  for (let i = 0, len = stops.length; i < len; i++) {
1599
1664
  stop = stops[i];
1600
- if (typeof stop === 'string')
1601
- offset = i / (len - 1), color = draw.ColorConvert.string(stop, opacity);
1602
- else
1603
- offset = stop.offset, color = draw.ColorConvert.string(stop.color, opacity);
1665
+ if (core.isString(stop)) offset = i / (len - 1), color = draw.ColorConvert.string(stop, opacity); else offset = stop.offset,
1666
+ color = draw.ColorConvert.string(stop.color, opacity);
1604
1667
  gradient.addColorStop(offset, color);
1605
- if (!isTransparent && hasTransparent(color))
1606
- isTransparent = true;
1668
+ if (!isTransparent && hasTransparent(color)) isTransparent = true;
1607
1669
  }
1608
- if (isTransparent)
1609
- data.isTransparent = true;
1670
+ if (isTransparent) data.isTransparent = true;
1610
1671
  }
1611
1672
  }
1612
1673
 
1613
- const { getAngle, getDistance: getDistance$1 } = core.PointHelper;
1614
- const { get, rotateOfOuter, scaleOfOuter } = core.MatrixHelper;
1615
- const { toPoint: toPoint$1 } = core.AroundHelper;
1674
+ const {getAngle: getAngle, getDistance: getDistance$1} = core.PointHelper;
1675
+
1676
+ const {get: get, rotateOfOuter: rotateOfOuter, scaleOfOuter: scaleOfOuter} = core.MatrixHelper;
1677
+
1678
+ const {toPoint: toPoint$1} = core.AroundHelper;
1679
+
1616
1680
  const realFrom$1 = {};
1681
+
1617
1682
  const realTo$1 = {};
1683
+
1618
1684
  function radialGradient(paint, box) {
1619
- let { from, to, type, opacity, stretch } = paint;
1620
- toPoint$1(from || 'center', box, realFrom$1);
1621
- toPoint$1(to || 'bottom', box, realTo$1);
1685
+ let {from: from, to: to, type: type, opacity: opacity, stretch: stretch} = paint;
1686
+ toPoint$1(from || "center", box, realFrom$1);
1687
+ toPoint$1(to || "bottom", box, realTo$1);
1622
1688
  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));
1623
- const data = { type, style };
1689
+ const data = {
1690
+ type: type,
1691
+ style: style
1692
+ };
1624
1693
  applyStops(data, style, paint.stops, opacity);
1625
1694
  const transform = getTransform(box, realFrom$1, realTo$1, stretch, true);
1626
- if (transform)
1627
- data.transform = transform;
1695
+ if (transform) data.transform = transform;
1628
1696
  return data;
1629
1697
  }
1698
+
1630
1699
  function getTransform(box, from, to, stretch, rotate90) {
1631
1700
  let transform;
1632
- const { width, height } = box;
1701
+ const {width: width, height: height} = box;
1633
1702
  if (width !== height || stretch) {
1634
1703
  const angle = getAngle(from, to);
1635
1704
  transform = get();
1636
1705
  if (rotate90) {
1637
1706
  scaleOfOuter(transform, from, width / height * (stretch || 1), 1);
1638
1707
  rotateOfOuter(transform, from, angle + 90);
1639
- }
1640
- else {
1708
+ } else {
1641
1709
  scaleOfOuter(transform, from, 1, width / height * (stretch || 1));
1642
1710
  rotateOfOuter(transform, from, angle);
1643
1711
  }
@@ -1645,84 +1713,94 @@ function getTransform(box, from, to, stretch, rotate90) {
1645
1713
  return transform;
1646
1714
  }
1647
1715
 
1648
- const { getDistance } = core.PointHelper;
1649
- const { toPoint } = core.AroundHelper;
1716
+ const {getDistance: getDistance} = core.PointHelper;
1717
+
1718
+ const {toPoint: toPoint} = core.AroundHelper;
1719
+
1650
1720
  const realFrom = {};
1721
+
1651
1722
  const realTo = {};
1723
+
1652
1724
  function conicGradient(paint, box) {
1653
- let { from, to, type, opacity, stretch } = paint;
1654
- toPoint(from || 'center', box, realFrom);
1655
- toPoint(to || 'bottom', box, realTo);
1725
+ let {from: from, to: to, type: type, opacity: opacity, stretch: stretch} = paint;
1726
+ toPoint(from || "center", box, realFrom);
1727
+ toPoint(to || "bottom", box, realTo);
1656
1728
  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));
1657
- const data = { type, style };
1729
+ const data = {
1730
+ type: type,
1731
+ style: style
1732
+ };
1658
1733
  applyStops(data, style, paint.stops, opacity);
1659
1734
  const transform = getTransform(box, realFrom, realTo, stretch || 1, core.Platform.conicGradientRotate90);
1660
- if (transform)
1661
- data.transform = transform;
1735
+ if (transform) data.transform = transform;
1662
1736
  return data;
1663
1737
  }
1664
1738
 
1665
1739
  const PaintGradientModule = {
1666
- linearGradient,
1667
- radialGradient,
1668
- conicGradient,
1669
- getTransform
1740
+ linearGradient: linearGradient,
1741
+ radialGradient: radialGradient,
1742
+ conicGradient: conicGradient,
1743
+ getTransform: getTransform
1670
1744
  };
1671
1745
 
1672
- const { copy, toOffsetOutBounds: toOffsetOutBounds$1 } = core.BoundsHelper;
1746
+ const {copy: copy, toOffsetOutBounds: toOffsetOutBounds$1} = core.BoundsHelper;
1747
+
1673
1748
  const tempBounds = {};
1749
+
1674
1750
  const offsetOutBounds$1 = {};
1751
+
1675
1752
  function shadow(ui, current, shape) {
1676
1753
  let copyBounds, spreadScale;
1677
- const { __nowWorld: nowWorld, __layout } = ui;
1678
- const { shadow } = ui.__;
1679
- const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
1754
+ const {__nowWorld: nowWorld, __layout: __layout} = ui;
1755
+ const {shadow: shadow} = ui.__;
1756
+ const {worldCanvas: worldCanvas, bounds: bounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
1680
1757
  const other = current.getSameCanvas();
1681
1758
  const end = shadow.length - 1;
1682
1759
  toOffsetOutBounds$1(bounds, offsetOutBounds$1);
1683
1760
  shadow.forEach((item, index) => {
1684
- other.setWorldShadow((offsetOutBounds$1.offsetX + item.x * scaleX), (offsetOutBounds$1.offsetY + item.y * scaleY), item.blur * scaleX, draw.ColorConvert.string(item.color));
1685
- spreadScale = item.spread ? 1 + item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) : 0;
1761
+ let otherScale = 1;
1762
+ if (item.scaleFixed) {
1763
+ const sx = Math.abs(nowWorld.scaleX);
1764
+ if (sx > 1) otherScale = 1 / sx;
1765
+ }
1766
+ 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));
1767
+ spreadScale = item.spread ? 1 + item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) * otherScale : 0;
1686
1768
  drawWorldShadow(other, offsetOutBounds$1, spreadScale, shape);
1687
1769
  copyBounds = bounds;
1688
1770
  if (item.box) {
1689
1771
  other.restore();
1690
1772
  other.save();
1691
1773
  if (worldCanvas) {
1692
- other.copyWorld(other, bounds, nowWorld, 'copy');
1774
+ other.copyWorld(other, bounds, nowWorld, "copy");
1693
1775
  copyBounds = nowWorld;
1694
1776
  }
1695
- worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, 'destination-out') : other.copyWorld(shape.canvas, shapeBounds, bounds, 'destination-out');
1696
- }
1697
- if (ui.__worldFlipped)
1698
- current.copyWorldByReset(other, copyBounds, nowWorld, item.blendMode);
1699
- else
1700
- current.copyWorldToInner(other, copyBounds, __layout.renderBounds, item.blendMode);
1701
- if (end && index < end)
1702
- other.clearWorld(copyBounds, true);
1777
+ worldCanvas ? other.copyWorld(worldCanvas, nowWorld, nowWorld, "destination-out") : other.copyWorld(shape.canvas, shapeBounds, bounds, "destination-out");
1778
+ }
1779
+ core.LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
1780
+ if (end && index < end) other.clearWorld(copyBounds, true);
1703
1781
  });
1704
1782
  other.recycle(copyBounds);
1705
1783
  }
1784
+
1706
1785
  function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
1707
- const { bounds, shapeBounds } = shape;
1786
+ const {bounds: bounds, shapeBounds: shapeBounds} = shape;
1708
1787
  if (core.Platform.fullImageShadow) {
1709
1788
  copy(tempBounds, canvas.bounds);
1710
- tempBounds.x += (outBounds.x - shapeBounds.x);
1711
- tempBounds.y += (outBounds.y - shapeBounds.y);
1789
+ tempBounds.x += outBounds.x - shapeBounds.x;
1790
+ tempBounds.y += outBounds.y - shapeBounds.y;
1712
1791
  if (spreadScale) {
1713
- const { matrix } = shape;
1714
- tempBounds.x -= (bounds.x + (matrix ? matrix.e : 0) + bounds.width / 2) * (spreadScale - 1);
1715
- tempBounds.y -= (bounds.y + (matrix ? matrix.f : 0) + bounds.height / 2) * (spreadScale - 1);
1792
+ const {fitMatrix: fitMatrix} = shape;
1793
+ tempBounds.x -= (bounds.x + (fitMatrix ? fitMatrix.e : 0) + bounds.width / 2) * (spreadScale - 1);
1794
+ tempBounds.y -= (bounds.y + (fitMatrix ? fitMatrix.f : 0) + bounds.height / 2) * (spreadScale - 1);
1716
1795
  tempBounds.width *= spreadScale;
1717
1796
  tempBounds.height *= spreadScale;
1718
1797
  }
1719
1798
  canvas.copyWorld(shape.canvas, canvas.bounds, tempBounds);
1720
- }
1721
- else {
1799
+ } else {
1722
1800
  if (spreadScale) {
1723
1801
  copy(tempBounds, outBounds);
1724
- tempBounds.x -= (outBounds.width / 2) * (spreadScale - 1);
1725
- tempBounds.y -= (outBounds.height / 2) * (spreadScale - 1);
1802
+ tempBounds.x -= outBounds.width / 2 * (spreadScale - 1);
1803
+ tempBounds.y -= outBounds.height / 2 * (spreadScale - 1);
1726
1804
  tempBounds.width *= spreadScale;
1727
1805
  tempBounds.height *= spreadScale;
1728
1806
  }
@@ -1730,178 +1808,184 @@ function drawWorldShadow(canvas, outBounds, spreadScale, shape) {
1730
1808
  }
1731
1809
  }
1732
1810
 
1733
- const { toOffsetOutBounds } = core.BoundsHelper;
1811
+ const {toOffsetOutBounds: toOffsetOutBounds} = core.BoundsHelper;
1812
+
1734
1813
  const offsetOutBounds = {};
1814
+
1735
1815
  function innerShadow(ui, current, shape) {
1736
1816
  let copyBounds, spreadScale;
1737
- const { __nowWorld: nowWorld, __layout } = ui;
1738
- const { innerShadow } = ui.__;
1739
- const { worldCanvas, bounds, shapeBounds, scaleX, scaleY } = shape;
1817
+ const {__nowWorld: nowWorld, __layout: __layout} = ui;
1818
+ const {innerShadow: innerShadow} = ui.__;
1819
+ const {worldCanvas: worldCanvas, bounds: bounds, shapeBounds: shapeBounds, scaleX: scaleX, scaleY: scaleY} = shape;
1740
1820
  const other = current.getSameCanvas();
1741
1821
  const end = innerShadow.length - 1;
1742
1822
  toOffsetOutBounds(bounds, offsetOutBounds);
1743
1823
  innerShadow.forEach((item, index) => {
1824
+ let otherScale = 1;
1825
+ if (item.scaleFixed) {
1826
+ const sx = Math.abs(nowWorld.scaleX);
1827
+ if (sx > 1) otherScale = 1 / sx;
1828
+ }
1744
1829
  other.save();
1745
- other.setWorldShadow((offsetOutBounds.offsetX + item.x * scaleX), (offsetOutBounds.offsetY + item.y * scaleY), item.blur * scaleX);
1746
- spreadScale = item.spread ? 1 - item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) : 0;
1830
+ other.setWorldShadow(offsetOutBounds.offsetX + item.x * scaleX * otherScale, offsetOutBounds.offsetY + item.y * scaleY * otherScale, item.blur * scaleX * otherScale);
1831
+ spreadScale = item.spread ? 1 - item.spread * 2 / (__layout.boxBounds.width + (__layout.strokeBoxSpread || 0) * 2) * otherScale : 0;
1747
1832
  drawWorldShadow(other, offsetOutBounds, spreadScale, shape);
1748
1833
  other.restore();
1749
1834
  if (worldCanvas) {
1750
- other.copyWorld(other, bounds, nowWorld, 'copy');
1751
- other.copyWorld(worldCanvas, nowWorld, nowWorld, 'source-out');
1835
+ other.copyWorld(other, bounds, nowWorld, "copy");
1836
+ other.copyWorld(worldCanvas, nowWorld, nowWorld, "source-out");
1752
1837
  copyBounds = nowWorld;
1753
- }
1754
- else {
1755
- other.copyWorld(shape.canvas, shapeBounds, bounds, 'source-out');
1838
+ } else {
1839
+ other.copyWorld(shape.canvas, shapeBounds, bounds, "source-out");
1756
1840
  copyBounds = bounds;
1757
1841
  }
1758
- other.fillWorld(copyBounds, draw.ColorConvert.string(item.color), 'source-in');
1759
- if (ui.__worldFlipped)
1760
- current.copyWorldByReset(other, copyBounds, nowWorld, item.blendMode);
1761
- else
1762
- current.copyWorldToInner(other, copyBounds, __layout.renderBounds, item.blendMode);
1763
- if (end && index < end)
1764
- other.clearWorld(copyBounds, true);
1842
+ other.fillWorld(copyBounds, draw.ColorConvert.string(item.color), "source-in");
1843
+ core.LeafHelper.copyCanvasByWorld(ui, current, other, copyBounds, item.blendMode);
1844
+ if (end && index < end) other.clearWorld(copyBounds, true);
1765
1845
  });
1766
1846
  other.recycle(copyBounds);
1767
1847
  }
1768
1848
 
1769
1849
  function blur(ui, current, origin) {
1770
- const { blur } = ui.__;
1850
+ const {blur: blur} = ui.__;
1771
1851
  origin.setWorldBlur(blur * ui.__nowWorld.a);
1772
1852
  origin.copyWorldToInner(current, ui.__nowWorld, ui.__layout.renderBounds);
1773
- origin.filter = 'none';
1853
+ origin.filter = "none";
1774
1854
  }
1775
1855
 
1776
- function backgroundBlur(_ui, _current, _shape) {
1777
- }
1856
+ function backgroundBlur(_ui, _current, _shape) {}
1778
1857
 
1779
1858
  const EffectModule = {
1780
- shadow,
1781
- innerShadow,
1782
- blur,
1783
- backgroundBlur
1859
+ shadow: shadow,
1860
+ innerShadow: innerShadow,
1861
+ blur: blur,
1862
+ backgroundBlur: backgroundBlur
1784
1863
  };
1785
1864
 
1786
- const { excludeRenderBounds } = core.LeafBoundsHelper;
1787
- draw.Group.prototype.__renderMask = function (canvas, options) {
1865
+ const {excludeRenderBounds: excludeRenderBounds} = core.LeafBoundsHelper;
1866
+
1867
+ let usedGrayscaleAlpha;
1868
+
1869
+ draw.Group.prototype.__renderMask = function(canvas, options) {
1788
1870
  let child, maskCanvas, contentCanvas, maskOpacity, currentMask, mask;
1789
- const { children } = this;
1871
+ const {children: children} = this;
1790
1872
  for (let i = 0, len = children.length; i < len; i++) {
1791
1873
  child = children[i], mask = child.__.mask;
1792
1874
  if (mask) {
1793
1875
  if (currentMask) {
1794
- maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
1876
+ maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
1795
1877
  maskCanvas = contentCanvas = null;
1796
1878
  }
1797
- if (mask === 'path' || mask === 'clipping-path') {
1798
- if (child.opacity < 1) {
1799
- currentMask = 'opacity-path';
1800
- maskOpacity = child.opacity;
1801
- if (!contentCanvas)
1802
- contentCanvas = getCanvas(canvas);
1803
- }
1804
- else {
1805
- currentMask = 'path';
1879
+ maskOpacity = child.__.opacity;
1880
+ usedGrayscaleAlpha = false;
1881
+ if (mask === "path" || mask === "clipping-path") {
1882
+ if (maskOpacity < 1) {
1883
+ currentMask = "opacity-path";
1884
+ if (!contentCanvas) contentCanvas = getCanvas(canvas);
1885
+ } else {
1886
+ currentMask = "path";
1806
1887
  canvas.save();
1807
1888
  }
1808
1889
  child.__clip(contentCanvas || canvas, options);
1809
- }
1810
- else {
1811
- currentMask = mask === 'grayscale' ? 'grayscale' : 'alpha';
1812
- if (!maskCanvas)
1813
- maskCanvas = getCanvas(canvas);
1814
- if (!contentCanvas)
1815
- contentCanvas = getCanvas(canvas);
1890
+ } else {
1891
+ currentMask = mask === "grayscale" ? "grayscale" : "alpha";
1892
+ if (!maskCanvas) maskCanvas = getCanvas(canvas);
1893
+ if (!contentCanvas) contentCanvas = getCanvas(canvas);
1816
1894
  child.__render(maskCanvas, options);
1817
1895
  }
1818
- if (!(mask === 'clipping' || mask === 'clipping-path'))
1819
- continue;
1820
- }
1821
- if (excludeRenderBounds(child, options))
1896
+ if (mask === "clipping" || mask === "clipping-path") excludeRenderBounds(child, options) || child.__render(canvas, options);
1822
1897
  continue;
1823
- child.__render(contentCanvas || canvas, options);
1898
+ }
1899
+ const childBlendMode = maskOpacity === 1 && child.__.__blendMode;
1900
+ if (childBlendMode) maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, false);
1901
+ excludeRenderBounds(child, options) || child.__render(contentCanvas || canvas, options);
1902
+ if (childBlendMode) maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, childBlendMode, false);
1824
1903
  }
1825
- maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity);
1904
+ maskEnd(this, currentMask, canvas, contentCanvas, maskCanvas, maskOpacity, undefined, true);
1826
1905
  };
1827
- function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity) {
1906
+
1907
+ function maskEnd(leaf, maskMode, canvas, contentCanvas, maskCanvas, maskOpacity, blendMode, recycle) {
1828
1908
  switch (maskMode) {
1829
- case 'grayscale':
1830
- maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
1831
- case 'alpha':
1832
- usePixelMask(leaf, canvas, contentCanvas, maskCanvas);
1833
- break;
1834
- case 'opacity-path':
1835
- copyContent(leaf, canvas, contentCanvas, maskOpacity);
1836
- break;
1837
- case 'path':
1838
- canvas.restore();
1909
+ case "grayscale":
1910
+ if (!usedGrayscaleAlpha) usedGrayscaleAlpha = true, maskCanvas.useGrayscaleAlpha(leaf.__nowWorld);
1911
+
1912
+ case "alpha":
1913
+ usePixelMask(leaf, canvas, contentCanvas, maskCanvas, blendMode, recycle);
1914
+ break;
1915
+
1916
+ case "opacity-path":
1917
+ copyContent(leaf, canvas, contentCanvas, maskOpacity, blendMode, recycle);
1918
+ break;
1919
+
1920
+ case "path":
1921
+ if (recycle) canvas.restore();
1839
1922
  }
1840
1923
  }
1924
+
1841
1925
  function getCanvas(canvas) {
1842
1926
  return canvas.getSameCanvas(false, true);
1843
1927
  }
1844
- function usePixelMask(leaf, canvas, content, mask) {
1928
+
1929
+ function usePixelMask(leaf, canvas, content, mask, blendMode, recycle) {
1845
1930
  const realBounds = leaf.__nowWorld;
1846
1931
  content.resetTransform();
1847
1932
  content.opacity = 1;
1848
1933
  content.useMask(mask, realBounds);
1849
- mask.recycle(realBounds);
1850
- copyContent(leaf, canvas, content, 1);
1934
+ if (recycle) mask.recycle(realBounds);
1935
+ copyContent(leaf, canvas, content, 1, blendMode, recycle);
1851
1936
  }
1852
- function copyContent(leaf, canvas, content, maskOpacity) {
1937
+
1938
+ function copyContent(leaf, canvas, content, maskOpacity, blendMode, recycle) {
1853
1939
  const realBounds = leaf.__nowWorld;
1854
1940
  canvas.resetTransform();
1855
1941
  canvas.opacity = maskOpacity;
1856
- canvas.copyWorld(content, realBounds);
1857
- content.recycle(realBounds);
1858
- }
1859
-
1860
- const money = '¥¥$€££¢¢';
1861
- const letter = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
1862
- const langBefore = '《(「〈『〖【〔{┌<‘“=' + money;
1863
- const langAfter = '》)」〉』〗】〕}┐>’”!?,、。:;‰';
1864
- const langSymbol = '≮≯≈≠=…';
1865
- const langBreak$1 = '—/~|┆·';
1866
- const beforeChar = '{[(<\'"' + langBefore;
1867
- const afterChar = '>)]}%!?,.:;\'"' + langAfter;
1868
- const symbolChar = afterChar + '_#~&*+\\=|' + langSymbol;
1869
- const breakChar = '- ' + langBreak$1;
1870
- const cjkRangeList = [
1871
- [0x4E00, 0x9FFF],
1872
- [0x3400, 0x4DBF],
1873
- [0x20000, 0x2A6DF],
1874
- [0x2A700, 0x2B73F],
1875
- [0x2B740, 0x2B81F],
1876
- [0x2B820, 0x2CEAF],
1877
- [0x2CEB0, 0x2EBEF],
1878
- [0x30000, 0x3134F],
1879
- [0x31350, 0x323AF],
1880
- [0x2E80, 0x2EFF],
1881
- [0x2F00, 0x2FDF],
1882
- [0x2FF0, 0x2FFF],
1883
- [0x3000, 0x303F],
1884
- [0x31C0, 0x31EF],
1885
- [0x3200, 0x32FF],
1886
- [0x3300, 0x33FF],
1887
- [0xF900, 0xFAFF],
1888
- [0xFE30, 0xFE4F],
1889
- [0x1F200, 0x1F2FF],
1890
- [0x2F800, 0x2FA1F],
1891
- ];
1892
- const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u${start.toString(16)}-\\u${end.toString(16)}]`).join('|'));
1942
+ canvas.copyWorld(content, realBounds, undefined, blendMode);
1943
+ recycle ? content.recycle(realBounds) : content.clearWorld(realBounds, true);
1944
+ }
1945
+
1946
+ const money = "¥¥$€££¢¢";
1947
+
1948
+ const letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
1949
+
1950
+ const langBefore = "《(「〈『〖【〔{┌<‘“=" + money;
1951
+
1952
+ const langAfter = "》)」〉』〗】〕}┐>’”!?,、。:;‰";
1953
+
1954
+ const langSymbol = "≮≯≈≠=…";
1955
+
1956
+ const langBreak$1 = "—/~|┆·";
1957
+
1958
+ const beforeChar = "{[(<'\"" + langBefore;
1959
+
1960
+ const afterChar = ">)]}%!?,.:;'\"" + langAfter;
1961
+
1962
+ const symbolChar = afterChar + "_#~&*+\\=|" + langSymbol;
1963
+
1964
+ const breakChar = "- " + langBreak$1;
1965
+
1966
+ 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 ] ];
1967
+
1968
+ const cjkReg = new RegExp(cjkRangeList.map(([start, end]) => `[\\u${start.toString(16)}-\\u${end.toString(16)}]`).join("|"));
1969
+
1893
1970
  function mapChar(str) {
1894
1971
  const map = {};
1895
- str.split('').forEach(char => map[char] = true);
1972
+ str.split("").forEach(char => map[char] = true);
1896
1973
  return map;
1897
1974
  }
1975
+
1898
1976
  const letterMap = mapChar(letter);
1977
+
1899
1978
  const beforeMap = mapChar(beforeChar);
1979
+
1900
1980
  const afterMap = mapChar(afterChar);
1981
+
1901
1982
  const symbolMap = mapChar(symbolChar);
1983
+
1902
1984
  const breakMap = mapChar(breakChar);
1985
+
1903
1986
  var CharType;
1904
- (function (CharType) {
1987
+
1988
+ (function(CharType) {
1905
1989
  CharType[CharType["Letter"] = 0] = "Letter";
1906
1990
  CharType[CharType["Single"] = 1] = "Single";
1907
1991
  CharType[CharType["Before"] = 2] = "Before";
@@ -1909,179 +1993,175 @@ var CharType;
1909
1993
  CharType[CharType["Symbol"] = 4] = "Symbol";
1910
1994
  CharType[CharType["Break"] = 5] = "Break";
1911
1995
  })(CharType || (CharType = {}));
1912
- const { Letter: Letter$1, Single: Single$1, Before: Before$1, After: After$1, Symbol: Symbol$1, Break: Break$1 } = CharType;
1996
+
1997
+ const {Letter: Letter$1, Single: Single$1, Before: Before$1, After: After$1, Symbol: Symbol$1, Break: Break$1} = CharType;
1998
+
1913
1999
  function getCharType(char) {
1914
2000
  if (letterMap[char]) {
1915
2001
  return Letter$1;
1916
- }
1917
- else if (breakMap[char]) {
2002
+ } else if (breakMap[char]) {
1918
2003
  return Break$1;
1919
- }
1920
- else if (beforeMap[char]) {
2004
+ } else if (beforeMap[char]) {
1921
2005
  return Before$1;
1922
- }
1923
- else if (afterMap[char]) {
2006
+ } else if (afterMap[char]) {
1924
2007
  return After$1;
1925
- }
1926
- else if (symbolMap[char]) {
2008
+ } else if (symbolMap[char]) {
1927
2009
  return Symbol$1;
1928
- }
1929
- else if (cjkReg.test(char)) {
2010
+ } else if (cjkReg.test(char)) {
1930
2011
  return Single$1;
1931
- }
1932
- else {
2012
+ } else {
1933
2013
  return Letter$1;
1934
2014
  }
1935
2015
  }
1936
2016
 
1937
2017
  const TextRowHelper = {
1938
2018
  trimRight(row) {
1939
- const { words } = row;
2019
+ const {words: words} = row;
1940
2020
  let trimRight = 0, len = words.length, char;
1941
2021
  for (let i = len - 1; i > -1; i--) {
1942
2022
  char = words[i].data[0];
1943
- if (char.char === ' ') {
2023
+ if (char.char === " ") {
1944
2024
  trimRight++;
1945
2025
  row.width -= char.width;
1946
- }
1947
- else {
2026
+ } else {
1948
2027
  break;
1949
2028
  }
1950
2029
  }
1951
- if (trimRight)
1952
- words.splice(len - trimRight, trimRight);
2030
+ if (trimRight) words.splice(len - trimRight, trimRight);
1953
2031
  }
1954
2032
  };
1955
2033
 
1956
2034
  function getTextCase(char, textCase, firstChar) {
1957
2035
  switch (textCase) {
1958
- case 'title':
1959
- return firstChar ? char.toUpperCase() : char;
1960
- case 'upper':
1961
- return char.toUpperCase();
1962
- case 'lower':
1963
- return char.toLowerCase();
1964
- default:
1965
- return char;
2036
+ case "title":
2037
+ return firstChar ? char.toUpperCase() : char;
2038
+
2039
+ case "upper":
2040
+ return char.toUpperCase();
2041
+
2042
+ case "lower":
2043
+ return char.toLowerCase();
2044
+
2045
+ default:
2046
+ return char;
1966
2047
  }
1967
2048
  }
1968
2049
 
1969
- const { trimRight } = TextRowHelper;
1970
- const { Letter, Single, Before, After, Symbol, Break } = CharType;
2050
+ const {trimRight: trimRight} = TextRowHelper;
2051
+
2052
+ const {Letter: Letter, Single: Single, Before: Before, After: After, Symbol: Symbol, Break: Break} = CharType;
2053
+
1971
2054
  let word, row, wordWidth, rowWidth, realWidth;
2055
+
1972
2056
  let char, charWidth, startCharSize, charSize, charType, lastCharType, langBreak, afterBreak, paraStart;
2057
+
1973
2058
  let textDrawData, rows = [], bounds, findMaxWidth;
2059
+
1974
2060
  function createRows(drawData, content, style) {
1975
2061
  textDrawData = drawData;
1976
2062
  rows = drawData.rows;
1977
2063
  bounds = drawData.bounds;
1978
2064
  findMaxWidth = !bounds.width && !style.autoSizeAlign;
1979
- const { __letterSpacing, paraIndent, textCase } = style;
1980
- const { canvas } = core.Platform;
1981
- const { width, height } = bounds;
1982
- const charMode = width || height || __letterSpacing || (textCase !== 'none');
2065
+ const {__letterSpacing: __letterSpacing, paraIndent: paraIndent, textCase: textCase} = style;
2066
+ const {canvas: canvas} = core.Platform;
2067
+ const {width: width, height: height} = bounds;
2068
+ const charMode = width || height || __letterSpacing || textCase !== "none";
1983
2069
  if (charMode) {
1984
- const wrap = style.textWrap !== 'none';
1985
- const breakAll = style.textWrap === 'break';
2070
+ const wrap = style.textWrap !== "none";
2071
+ const breakAll = style.textWrap === "break";
1986
2072
  paraStart = true;
1987
2073
  lastCharType = null;
1988
2074
  startCharSize = charWidth = charSize = wordWidth = rowWidth = 0;
1989
- word = { data: [] }, row = { words: [] };
1990
- if (__letterSpacing)
1991
- content = [...content];
2075
+ word = {
2076
+ data: []
2077
+ }, row = {
2078
+ words: []
2079
+ };
2080
+ if (__letterSpacing) content = [ ...content ];
1992
2081
  for (let i = 0, len = content.length; i < len; i++) {
1993
2082
  char = content[i];
1994
- if (char === '\n') {
1995
- if (wordWidth)
1996
- addWord();
2083
+ if (char === "\n") {
2084
+ if (wordWidth) addWord();
1997
2085
  row.paraEnd = true;
1998
2086
  addRow();
1999
2087
  paraStart = true;
2000
- }
2001
- else {
2088
+ } else {
2002
2089
  charType = getCharType(char);
2003
- if (charType === Letter && textCase !== 'none')
2004
- char = getTextCase(char, textCase, !wordWidth);
2090
+ if (charType === Letter && textCase !== "none") char = getTextCase(char, textCase, !wordWidth);
2005
2091
  charWidth = canvas.measureText(char).width;
2006
2092
  if (__letterSpacing) {
2007
- if (__letterSpacing < 0)
2008
- charSize = charWidth;
2093
+ if (__letterSpacing < 0) charSize = charWidth;
2009
2094
  charWidth += __letterSpacing;
2010
2095
  }
2011
- langBreak = (charType === Single && (lastCharType === Single || lastCharType === Letter)) || (lastCharType === Single && charType !== After);
2012
- afterBreak = ((charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After));
2096
+ langBreak = charType === Single && (lastCharType === Single || lastCharType === Letter) || lastCharType === Single && charType !== After;
2097
+ afterBreak = (charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After);
2013
2098
  realWidth = paraStart && paraIndent ? width - paraIndent : width;
2014
2099
  if (wrap && (width && rowWidth + wordWidth + charWidth > realWidth)) {
2015
2100
  if (breakAll) {
2016
- if (wordWidth)
2017
- addWord();
2018
- if (rowWidth)
2019
- addRow();
2020
- }
2021
- else {
2022
- if (!afterBreak)
2023
- afterBreak = charType === Letter && lastCharType == After;
2024
- if (langBreak || afterBreak || charType === Break || charType === Before || charType === Single || (wordWidth + charWidth > realWidth)) {
2025
- if (wordWidth)
2026
- addWord();
2027
- if (rowWidth)
2028
- addRow();
2029
- }
2030
- else {
2031
- if (rowWidth)
2032
- addRow();
2101
+ if (wordWidth) addWord();
2102
+ if (rowWidth) addRow();
2103
+ } else {
2104
+ if (!afterBreak) afterBreak = charType === Letter && lastCharType == After;
2105
+ if (langBreak || afterBreak || charType === Break || charType === Before || charType === Single || wordWidth + charWidth > realWidth) {
2106
+ if (wordWidth) addWord();
2107
+ if (rowWidth) addRow();
2108
+ } else {
2109
+ if (rowWidth) addRow();
2033
2110
  }
2034
2111
  }
2035
2112
  }
2036
- if (char === ' ' && paraStart !== true && (rowWidth + wordWidth) === 0) ;
2037
- else {
2113
+ if (char === " " && paraStart !== true && rowWidth + wordWidth === 0) ; else {
2038
2114
  if (charType === Break) {
2039
- if (char === ' ' && wordWidth)
2040
- addWord();
2115
+ if (char === " " && wordWidth) addWord();
2041
2116
  addChar(char, charWidth);
2042
2117
  addWord();
2043
- }
2044
- else if (langBreak || afterBreak) {
2045
- if (wordWidth)
2046
- addWord();
2118
+ } else if (langBreak || afterBreak) {
2119
+ if (wordWidth) addWord();
2047
2120
  addChar(char, charWidth);
2048
- }
2049
- else {
2121
+ } else {
2050
2122
  addChar(char, charWidth);
2051
2123
  }
2052
2124
  }
2053
2125
  lastCharType = charType;
2054
2126
  }
2055
2127
  }
2056
- if (wordWidth)
2057
- addWord();
2058
- if (rowWidth)
2059
- addRow();
2128
+ if (wordWidth) addWord();
2129
+ if (rowWidth) addRow();
2060
2130
  rows.length > 0 && (rows[rows.length - 1].paraEnd = true);
2061
- }
2062
- else {
2063
- content.split('\n').forEach(content => {
2131
+ } else {
2132
+ content.split("\n").forEach(content => {
2064
2133
  textDrawData.paraNumber++;
2065
2134
  rowWidth = canvas.measureText(content).width;
2066
- rows.push({ x: paraIndent || 0, text: content, width: rowWidth, paraStart: true });
2067
- if (findMaxWidth)
2068
- setMaxWidth();
2135
+ rows.push({
2136
+ x: paraIndent || 0,
2137
+ text: content,
2138
+ width: rowWidth,
2139
+ paraStart: true
2140
+ });
2141
+ if (findMaxWidth) setMaxWidth();
2069
2142
  });
2070
2143
  }
2071
2144
  }
2145
+
2072
2146
  function addChar(char, width) {
2073
- if (charSize && !startCharSize)
2074
- startCharSize = charSize;
2075
- word.data.push({ char, width });
2147
+ if (charSize && !startCharSize) startCharSize = charSize;
2148
+ word.data.push({
2149
+ char: char,
2150
+ width: width
2151
+ });
2076
2152
  wordWidth += width;
2077
2153
  }
2154
+
2078
2155
  function addWord() {
2079
2156
  rowWidth += wordWidth;
2080
2157
  word.width = wordWidth;
2081
2158
  row.words.push(word);
2082
- word = { data: [] };
2159
+ word = {
2160
+ data: []
2161
+ };
2083
2162
  wordWidth = 0;
2084
2163
  }
2164
+
2085
2165
  function addRow() {
2086
2166
  if (paraStart) {
2087
2167
  textDrawData.paraNumber++;
@@ -2094,52 +2174,53 @@ function addRow() {
2094
2174
  startCharSize = 0;
2095
2175
  }
2096
2176
  row.width = rowWidth;
2097
- if (bounds.width)
2098
- trimRight(row);
2099
- else if (findMaxWidth)
2100
- setMaxWidth();
2177
+ if (bounds.width) trimRight(row); else if (findMaxWidth) setMaxWidth();
2101
2178
  rows.push(row);
2102
- row = { words: [] };
2179
+ row = {
2180
+ words: []
2181
+ };
2103
2182
  rowWidth = 0;
2104
2183
  }
2184
+
2105
2185
  function setMaxWidth() {
2106
- if (rowWidth > (textDrawData.maxWidth || 0))
2107
- textDrawData.maxWidth = rowWidth;
2186
+ if (rowWidth > (textDrawData.maxWidth || 0)) textDrawData.maxWidth = rowWidth;
2108
2187
  }
2109
2188
 
2110
2189
  const CharMode = 0;
2190
+
2111
2191
  const WordMode = 1;
2192
+
2112
2193
  const TextMode = 2;
2194
+
2113
2195
  function layoutChar(drawData, style, width, _height) {
2114
- const { rows } = drawData;
2115
- const { textAlign, paraIndent, letterSpacing } = style;
2196
+ const {rows: rows} = drawData;
2197
+ const {textAlign: textAlign, paraIndent: paraIndent, letterSpacing: letterSpacing} = style;
2116
2198
  let charX, addWordWidth, indentWidth, mode, wordChar, wordsLength;
2117
2199
  rows.forEach(row => {
2118
2200
  if (row.words) {
2119
2201
  indentWidth = paraIndent && row.paraStart ? paraIndent : 0, wordsLength = row.words.length;
2120
- addWordWidth = (width && (textAlign === 'justify' || textAlign === 'both') && wordsLength > 1) ? (width - row.width - indentWidth) / (wordsLength - 1) : 0;
2121
- mode = (letterSpacing || row.isOverflow) ? CharMode : (addWordWidth > 0.01 ? WordMode : TextMode);
2122
- if (row.isOverflow && !letterSpacing)
2123
- row.textMode = true;
2202
+ addWordWidth = width && (textAlign === "justify" || textAlign === "both") && wordsLength > 1 ? (width - row.width - indentWidth) / (wordsLength - 1) : 0;
2203
+ mode = letterSpacing || row.isOverflow ? CharMode : addWordWidth > .01 ? WordMode : TextMode;
2204
+ if (row.isOverflow && !letterSpacing) row.textMode = true;
2124
2205
  if (mode === TextMode) {
2125
2206
  row.x += indentWidth;
2126
2207
  toTextChar$1(row);
2127
- }
2128
- else {
2208
+ } else {
2129
2209
  row.x += indentWidth;
2130
2210
  charX = row.x;
2131
2211
  row.data = [];
2132
2212
  row.words.forEach((word, index) => {
2133
2213
  if (mode === WordMode) {
2134
- wordChar = { char: '', x: charX };
2214
+ wordChar = {
2215
+ char: "",
2216
+ x: charX
2217
+ };
2135
2218
  charX = toWordChar(word.data, charX, wordChar);
2136
- if (row.isOverflow || wordChar.char !== ' ')
2137
- row.data.push(wordChar);
2138
- }
2139
- else {
2219
+ if (row.isOverflow || wordChar.char !== " ") row.data.push(wordChar);
2220
+ } else {
2140
2221
  charX = toChar(word.data, charX, row.data, row.isOverflow);
2141
2222
  }
2142
- if (addWordWidth && (!row.paraEnd || textAlign === 'both') && (index !== wordsLength - 1)) {
2223
+ if (addWordWidth && (!row.paraEnd || textAlign === "both") && index !== wordsLength - 1) {
2143
2224
  charX += addWordWidth;
2144
2225
  row.width += addWordWidth;
2145
2226
  }
@@ -2149,14 +2230,16 @@ function layoutChar(drawData, style, width, _height) {
2149
2230
  }
2150
2231
  });
2151
2232
  }
2233
+
2152
2234
  function toTextChar$1(row) {
2153
- row.text = '';
2235
+ row.text = "";
2154
2236
  row.words.forEach(word => {
2155
2237
  word.data.forEach(char => {
2156
2238
  row.text += char.char;
2157
2239
  });
2158
2240
  });
2159
2241
  }
2242
+
2160
2243
  function toWordChar(data, charX, wordChar) {
2161
2244
  data.forEach(char => {
2162
2245
  wordChar.char += char.char;
@@ -2164,9 +2247,10 @@ function toWordChar(data, charX, wordChar) {
2164
2247
  });
2165
2248
  return charX;
2166
2249
  }
2250
+
2167
2251
  function toChar(data, charX, rowData, isOverflow) {
2168
2252
  data.forEach(char => {
2169
- if (isOverflow || char.char !== ' ') {
2253
+ if (isOverflow || char.char !== " ") {
2170
2254
  char.x = charX;
2171
2255
  rowData.push(char);
2172
2256
  }
@@ -2176,38 +2260,39 @@ function toChar(data, charX, rowData, isOverflow) {
2176
2260
  }
2177
2261
 
2178
2262
  function layoutText(drawData, style) {
2179
- const { rows, bounds } = drawData, countRows = rows.length;
2180
- const { __lineHeight, __baseLine, __letterSpacing, __clipText, textAlign, verticalAlign, paraSpacing, autoSizeAlign } = style;
2181
- let { x, y, width, height } = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
2263
+ const {rows: rows, bounds: bounds} = drawData, countRows = rows.length;
2264
+ const {__lineHeight: __lineHeight, __baseLine: __baseLine, __letterSpacing: __letterSpacing, __clipText: __clipText, textAlign: textAlign, verticalAlign: verticalAlign, paraSpacing: paraSpacing, autoSizeAlign: autoSizeAlign} = style;
2265
+ let {x: x, y: y, width: width, height: height} = bounds, realHeight = __lineHeight * countRows + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0);
2182
2266
  let starY = __baseLine;
2183
2267
  if (__clipText && realHeight > height) {
2184
2268
  realHeight = Math.max(height, __lineHeight);
2185
- if (countRows > 1)
2186
- drawData.overflow = countRows;
2187
- }
2188
- else if (height || autoSizeAlign) {
2269
+ if (countRows > 1) drawData.overflow = countRows;
2270
+ } else if (height || autoSizeAlign) {
2189
2271
  switch (verticalAlign) {
2190
- case 'middle':
2191
- y += (height - realHeight) / 2;
2192
- break;
2193
- case 'bottom': y += (height - realHeight);
2272
+ case "middle":
2273
+ y += (height - realHeight) / 2;
2274
+ break;
2275
+
2276
+ case "bottom":
2277
+ y += height - realHeight;
2194
2278
  }
2195
2279
  }
2196
2280
  starY += y;
2197
- let row, rowX, rowWidth, layoutWidth = (width || autoSizeAlign) ? width : drawData.maxWidth;
2281
+ let row, rowX, rowWidth, layoutWidth = width || autoSizeAlign ? width : drawData.maxWidth;
2198
2282
  for (let i = 0, len = countRows; i < len; i++) {
2199
2283
  row = rows[i];
2200
2284
  row.x = x;
2201
- if (row.width < width || (row.width > width && !__clipText)) {
2285
+ if (row.width < width || row.width > width && !__clipText) {
2202
2286
  switch (textAlign) {
2203
- case 'center':
2204
- row.x += (layoutWidth - row.width) / 2;
2205
- break;
2206
- case 'right': row.x += layoutWidth - row.width;
2287
+ case "center":
2288
+ row.x += (layoutWidth - row.width) / 2;
2289
+ break;
2290
+
2291
+ case "right":
2292
+ row.x += layoutWidth - row.width;
2207
2293
  }
2208
2294
  }
2209
- if (row.paraStart && paraSpacing && i > 0)
2210
- starY += paraSpacing;
2295
+ if (row.paraStart && paraSpacing && i > 0) starY += paraSpacing;
2211
2296
  row.y = starY;
2212
2297
  starY += __lineHeight;
2213
2298
  if (drawData.overflow > i && starY > realHeight) {
@@ -2221,19 +2306,15 @@ function layoutText(drawData, style) {
2221
2306
  rowWidth = -row.width + style.fontSize + __letterSpacing;
2222
2307
  rowX -= rowWidth;
2223
2308
  rowWidth += style.fontSize;
2224
- }
2225
- else {
2309
+ } else {
2226
2310
  rowWidth -= __letterSpacing;
2227
2311
  }
2228
2312
  }
2229
- if (rowX < bounds.x)
2230
- bounds.x = rowX;
2231
- if (rowWidth > bounds.width)
2232
- bounds.width = rowWidth;
2313
+ if (rowX < bounds.x) bounds.x = rowX;
2314
+ if (rowWidth > bounds.width) bounds.width = rowWidth;
2233
2315
  if (__clipText && width && width < rowWidth) {
2234
2316
  row.isOverflow = true;
2235
- if (!drawData.overflow)
2236
- drawData.overflow = rows.length;
2317
+ if (!drawData.overflow) drawData.overflow = rows.length;
2237
2318
  }
2238
2319
  }
2239
2320
  bounds.y = y;
@@ -2241,20 +2322,16 @@ function layoutText(drawData, style) {
2241
2322
  }
2242
2323
 
2243
2324
  function clipText(drawData, style, x, width) {
2244
- if (!width)
2245
- return;
2246
- const { rows, overflow } = drawData;
2247
- let { textOverflow } = style;
2325
+ if (!width) return;
2326
+ const {rows: rows, overflow: overflow} = drawData;
2327
+ let {textOverflow: textOverflow} = style;
2248
2328
  rows.splice(overflow);
2249
- if (textOverflow && textOverflow !== 'show') {
2250
- if (textOverflow === 'hide')
2251
- textOverflow = '';
2252
- else if (textOverflow === 'ellipsis')
2253
- textOverflow = '...';
2329
+ if (textOverflow && textOverflow !== "show") {
2330
+ if (textOverflow === "hide") textOverflow = ""; else if (textOverflow === "ellipsis") textOverflow = "...";
2254
2331
  let char, charRight;
2255
2332
  const ellipsisWidth = textOverflow ? core.Platform.canvas.measureText(textOverflow).width : 0;
2256
2333
  const right = x + width - ellipsisWidth;
2257
- const list = style.textWrap === 'none' ? rows : [rows[overflow - 1]];
2334
+ const list = style.textWrap === "none" ? rows : [ rows[overflow - 1] ];
2258
2335
  list.forEach(row => {
2259
2336
  if (row.isOverflow && row.data) {
2260
2337
  let end = row.data.length - 1;
@@ -2263,8 +2340,7 @@ function clipText(drawData, style, x, width) {
2263
2340
  charRight = char.x + char.width;
2264
2341
  if (i === end && charRight < right) {
2265
2342
  break;
2266
- }
2267
- else if ((charRight < right && char.char !== ' ') || !i) {
2343
+ } else if (charRight < right && char.char !== " " || !i) {
2268
2344
  row.data.splice(i + 1);
2269
2345
  row.width -= char.width;
2270
2346
  break;
@@ -2272,15 +2348,18 @@ function clipText(drawData, style, x, width) {
2272
2348
  row.width -= char.width;
2273
2349
  }
2274
2350
  row.width += ellipsisWidth;
2275
- row.data.push({ char: textOverflow, x: charRight });
2276
- if (row.textMode)
2277
- toTextChar(row);
2351
+ row.data.push({
2352
+ char: textOverflow,
2353
+ x: charRight
2354
+ });
2355
+ if (row.textMode) toTextChar(row);
2278
2356
  }
2279
2357
  });
2280
2358
  }
2281
2359
  }
2360
+
2282
2361
  function toTextChar(row) {
2283
- row.text = '';
2362
+ row.text = "";
2284
2363
  row.data.forEach(char => {
2285
2364
  row.text += char.char;
2286
2365
  });
@@ -2289,137 +2368,151 @@ function toTextChar(row) {
2289
2368
 
2290
2369
  function decorationText(drawData, style) {
2291
2370
  let type;
2292
- const { fontSize, textDecoration } = style;
2371
+ const {fontSize: fontSize, textDecoration: textDecoration} = style;
2293
2372
  drawData.decorationHeight = fontSize / 11;
2294
- if (typeof textDecoration === 'object') {
2373
+ if (core.isObject(textDecoration)) {
2295
2374
  type = textDecoration.type;
2296
- if (textDecoration.color)
2297
- drawData.decorationColor = draw.ColorConvert.string(textDecoration.color);
2298
- }
2299
- else
2300
- type = textDecoration;
2375
+ if (textDecoration.color) drawData.decorationColor = draw.ColorConvert.string(textDecoration.color);
2376
+ } else type = textDecoration;
2301
2377
  switch (type) {
2302
- case 'under':
2303
- drawData.decorationY = [fontSize * 0.15];
2304
- break;
2305
- case 'delete':
2306
- drawData.decorationY = [-fontSize * 0.35];
2307
- break;
2308
- case 'under-delete':
2309
- drawData.decorationY = [fontSize * 0.15, -fontSize * 0.35];
2378
+ case "under":
2379
+ drawData.decorationY = [ fontSize * .15 ];
2380
+ break;
2381
+
2382
+ case "delete":
2383
+ drawData.decorationY = [ -fontSize * .35 ];
2384
+ break;
2385
+
2386
+ case "under-delete":
2387
+ drawData.decorationY = [ fontSize * .15, -fontSize * .35 ];
2310
2388
  }
2311
2389
  }
2312
2390
 
2313
- const { top, right, bottom, left } = core.Direction4;
2391
+ const {top: top, right: right, bottom: bottom, left: left} = core.Direction4;
2392
+
2314
2393
  function getDrawData(content, style) {
2315
- if (typeof content !== 'string')
2316
- content = String(content);
2394
+ if (!core.isString(content)) content = String(content);
2317
2395
  let x = 0, y = 0;
2318
- let width = style.__getInput('width') || 0;
2319
- let height = style.__getInput('height') || 0;
2320
- const { textDecoration, __font, __padding: padding } = style;
2396
+ let width = style.__getInput("width") || 0;
2397
+ let height = style.__getInput("height") || 0;
2398
+ const {textDecoration: textDecoration, __font: __font, __padding: padding} = style;
2321
2399
  if (padding) {
2322
- if (width)
2323
- x = padding[left], width -= (padding[right] + padding[left]);
2324
- else if (!style.autoSizeAlign)
2325
- x = padding[left];
2326
- if (height)
2327
- y = padding[top], height -= (padding[top] + padding[bottom]);
2328
- else if (!style.autoSizeAlign)
2329
- y = padding[top];
2400
+ if (width) x = padding[left], width -= padding[right] + padding[left]; else if (!style.autoSizeAlign) x = padding[left];
2401
+ if (height) y = padding[top], height -= padding[top] + padding[bottom]; else if (!style.autoSizeAlign) y = padding[top];
2330
2402
  }
2331
2403
  const drawData = {
2332
- bounds: { x, y, width, height },
2404
+ bounds: {
2405
+ x: x,
2406
+ y: y,
2407
+ width: width,
2408
+ height: height
2409
+ },
2333
2410
  rows: [],
2334
2411
  paraNumber: 0,
2335
2412
  font: core.Platform.canvas.font = __font
2336
2413
  };
2337
2414
  createRows(drawData, content, style);
2338
- if (padding)
2339
- padAutoText(padding, drawData, style, width, height);
2415
+ if (padding) padAutoText(padding, drawData, style, width, height);
2340
2416
  layoutText(drawData, style);
2341
2417
  layoutChar(drawData, style, width);
2342
- if (drawData.overflow)
2343
- clipText(drawData, style, x, width);
2344
- if (textDecoration !== 'none')
2345
- decorationText(drawData, style);
2418
+ if (drawData.overflow) clipText(drawData, style, x, width);
2419
+ if (textDecoration !== "none") decorationText(drawData, style);
2346
2420
  return drawData;
2347
2421
  }
2422
+
2348
2423
  function padAutoText(padding, drawData, style, width, height) {
2349
2424
  if (!width && style.autoSizeAlign) {
2350
2425
  switch (style.textAlign) {
2351
- case 'left':
2352
- offsetText(drawData, 'x', padding[left]);
2353
- break;
2354
- case 'right': offsetText(drawData, 'x', -padding[right]);
2426
+ case "left":
2427
+ offsetText(drawData, "x", padding[left]);
2428
+ break;
2429
+
2430
+ case "right":
2431
+ offsetText(drawData, "x", -padding[right]);
2355
2432
  }
2356
2433
  }
2357
2434
  if (!height && style.autoSizeAlign) {
2358
2435
  switch (style.verticalAlign) {
2359
- case 'top':
2360
- offsetText(drawData, 'y', padding[top]);
2361
- break;
2362
- case 'bottom': offsetText(drawData, 'y', -padding[bottom]);
2436
+ case "top":
2437
+ offsetText(drawData, "y", padding[top]);
2438
+ break;
2439
+
2440
+ case "bottom":
2441
+ offsetText(drawData, "y", -padding[bottom]);
2363
2442
  }
2364
2443
  }
2365
2444
  }
2445
+
2366
2446
  function offsetText(drawData, attrName, value) {
2367
- const { bounds, rows } = drawData;
2447
+ const {bounds: bounds, rows: rows} = drawData;
2368
2448
  bounds[attrName] += value;
2369
- for (let i = 0; i < rows.length; i++)
2370
- rows[i][attrName] += value;
2449
+ for (let i = 0; i < rows.length; i++) rows[i][attrName] += value;
2371
2450
  }
2372
2451
 
2373
2452
  const TextConvertModule = {
2374
- getDrawData
2453
+ getDrawData: getDrawData
2375
2454
  };
2376
2455
 
2377
2456
  function string(color, opacity) {
2378
- const doOpacity = typeof opacity === 'number' && opacity !== 1;
2379
- if (typeof color === 'string') {
2380
- if (doOpacity && draw.ColorConvert.object)
2381
- color = draw.ColorConvert.object(color);
2382
- else
2383
- return color;
2457
+ const doOpacity = core.isNumber(opacity) && opacity < 1;
2458
+ if (core.isString(color)) {
2459
+ if (doOpacity && draw.ColorConvert.object) color = draw.ColorConvert.object(color); else return color;
2384
2460
  }
2385
- let a = color.a === undefined ? 1 : color.a;
2386
- if (doOpacity)
2387
- a *= opacity;
2388
- const rgb = color.r + ',' + color.g + ',' + color.b;
2389
- return a === 1 ? 'rgb(' + rgb + ')' : 'rgba(' + rgb + ',' + a + ')';
2461
+ let a = core.isUndefined(color.a) ? 1 : color.a;
2462
+ if (doOpacity) a *= opacity;
2463
+ const rgb = color.r + "," + color.g + "," + color.b;
2464
+ return a === 1 ? "rgb(" + rgb + ")" : "rgba(" + rgb + "," + a + ")";
2390
2465
  }
2391
2466
 
2392
2467
  const ColorConvertModule = {
2393
- string
2468
+ string: string
2394
2469
  };
2395
2470
 
2396
2471
  Object.assign(draw.TextConvert, TextConvertModule);
2472
+
2397
2473
  Object.assign(draw.ColorConvert, ColorConvertModule);
2474
+
2398
2475
  Object.assign(draw.Paint, PaintModule);
2476
+
2399
2477
  Object.assign(draw.PaintImage, PaintImageModule);
2478
+
2400
2479
  Object.assign(draw.PaintGradient, PaintGradientModule);
2480
+
2401
2481
  Object.assign(draw.Effect, EffectModule);
2402
2482
 
2403
2483
  useCanvas();
2404
2484
 
2405
2485
  Object.defineProperty(exports, "LeaferImage", {
2406
2486
  enumerable: true,
2407
- get: function () { return core.LeaferImage; }
2487
+ get: function() {
2488
+ return core.LeaferImage;
2489
+ }
2408
2490
  });
2491
+
2409
2492
  exports.Layouter = Layouter;
2493
+
2410
2494
  exports.LeaferCanvas = LeaferCanvas;
2495
+
2411
2496
  exports.Renderer = Renderer;
2497
+
2412
2498
  exports.Watcher = Watcher;
2499
+
2413
2500
  exports.useCanvas = useCanvas;
2414
- Object.keys(core).forEach(function (k) {
2415
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
2501
+
2502
+ Object.keys(core).forEach(function(k) {
2503
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
2416
2504
  enumerable: true,
2417
- get: function () { return core[k]; }
2505
+ get: function() {
2506
+ return core[k];
2507
+ }
2418
2508
  });
2419
2509
  });
2420
- Object.keys(draw).forEach(function (k) {
2421
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
2510
+
2511
+ Object.keys(draw).forEach(function(k) {
2512
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
2422
2513
  enumerable: true,
2423
- get: function () { return draw[k]; }
2514
+ get: function() {
2515
+ return draw[k];
2516
+ }
2424
2517
  });
2425
2518
  });