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