@leafer-draw/miniapp 1.8.0 → 1.9.1

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