@leafer-draw/worker 1.9.12 → 1.10.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/worker.js CHANGED
@@ -1,42 +1,5 @@
1
1
  var LeaferUI = function(exports) {
2
2
  "use strict";
3
- const Platform = {
4
- toURL(text, fileType) {
5
- let url = encodeURIComponent(text);
6
- if (fileType === "text") url = "data:text/plain;charset=utf-8," + url; else if (fileType === "svg") url = "data:image/svg+xml," + url;
7
- return url;
8
- },
9
- image: {
10
- hitCanvasSize: 100,
11
- maxCacheSize: 2560 * 1600,
12
- maxPatternSize: 4096 * 2160,
13
- crossOrigin: "anonymous",
14
- getRealURL(url) {
15
- const {prefix: prefix, suffix: suffix} = Platform.image;
16
- if (suffix && !url.startsWith("data:") && !url.startsWith("blob:")) url += (url.includes("?") ? "&" : "?") + suffix;
17
- if (prefix && url[0] === "/") url = prefix + url;
18
- return url;
19
- }
20
- }
21
- };
22
- const IncrementId = {
23
- RUNTIME: "runtime",
24
- LEAF: "leaf",
25
- TASK: "task",
26
- CNAVAS: "canvas",
27
- IMAGE: "image",
28
- types: {},
29
- create(typeName) {
30
- const {types: types} = I$1;
31
- if (types[typeName]) {
32
- return types[typeName]++;
33
- } else {
34
- types[typeName] = 1;
35
- return 0;
36
- }
37
- }
38
- };
39
- const I$1 = IncrementId;
40
3
  exports.Answer = void 0;
41
4
  (function(Answer) {
42
5
  Answer[Answer["No"] = 0] = "No";
@@ -229,8 +192,74 @@ var LeaferUI = function(exports) {
229
192
  this.__input = this.__middle = null;
230
193
  }
231
194
  }
195
+ const {floor: floor$2, max: max$4} = Math;
196
+ const Platform = {
197
+ toURL(text, fileType) {
198
+ let url = encodeURIComponent(text);
199
+ if (fileType === "text") url = "data:text/plain;charset=utf-8," + url; else if (fileType === "svg") url = "data:image/svg+xml," + url;
200
+ return url;
201
+ },
202
+ image: {
203
+ hitCanvasSize: 100,
204
+ maxCacheSize: 2560 * 1600,
205
+ maxPatternSize: 4096 * 2160,
206
+ crossOrigin: "anonymous",
207
+ isLarge(size, scaleX, scaleY, largeSize) {
208
+ return size.width * size.height * (scaleX ? scaleX * scaleY : 1) > (largeSize || image$1.maxCacheSize);
209
+ },
210
+ isSuperLarge(size, scaleX, scaleY) {
211
+ return image$1.isLarge(size, scaleX, scaleY, image$1.maxPatternSize);
212
+ },
213
+ getRealURL(url) {
214
+ const {prefix: prefix, suffix: suffix} = Platform.image;
215
+ if (suffix && !url.startsWith("data:") && !url.startsWith("blob:")) url += (url.includes("?") ? "&" : "?") + suffix;
216
+ if (prefix && url[0] === "/") url = prefix + url;
217
+ return url;
218
+ },
219
+ resize(image, width, height, xGap, yGap, clip, smooth, opacity, _filters) {
220
+ const canvas = Platform.origin.createCanvas(max$4(floor$2(width + (xGap || 0)), 1), max$4(floor$2(height + (yGap || 0)), 1));
221
+ const ctx = canvas.getContext("2d");
222
+ if (opacity) ctx.globalAlpha = opacity;
223
+ ctx.imageSmoothingEnabled = smooth === false ? false : true;
224
+ if (clip) {
225
+ const scaleX = width / clip.width, scaleY = height / clip.height;
226
+ ctx.setTransform(scaleX, 0, 0, scaleY, -clip.x * scaleX, -clip.y * scaleY);
227
+ ctx.drawImage(image, 0, 0, image.width, image.height);
228
+ } else ctx.drawImage(image, 0, 0, width, height);
229
+ return canvas;
230
+ },
231
+ setPatternTransform(pattern, transform, paint) {
232
+ try {
233
+ if (transform && pattern.setTransform) {
234
+ pattern.setTransform(transform);
235
+ transform = undefined;
236
+ }
237
+ } catch (_a) {}
238
+ if (paint) DataHelper.stintSet(paint, "transform", transform);
239
+ }
240
+ }
241
+ };
242
+ const {image: image$1} = Platform;
243
+ const IncrementId = {
244
+ RUNTIME: "runtime",
245
+ LEAF: "leaf",
246
+ TASK: "task",
247
+ CNAVAS: "canvas",
248
+ IMAGE: "image",
249
+ types: {},
250
+ create(typeName) {
251
+ const {types: types} = I$1;
252
+ if (types[typeName]) {
253
+ return types[typeName]++;
254
+ } else {
255
+ types[typeName] = 1;
256
+ return 0;
257
+ }
258
+ }
259
+ };
260
+ const I$1 = IncrementId;
232
261
  let tempA, tempB, tempTo;
233
- const {max: max$4} = Math, tempFour = [ 0, 0, 0, 0 ];
262
+ const {max: max$3} = Math, tempFour = [ 0, 0, 0, 0 ];
234
263
  const FourNumberHelper = {
235
264
  zero: [ ...tempFour ],
236
265
  tempFour: tempFour,
@@ -281,9 +310,9 @@ var LeaferUI = function(exports) {
281
310
  return data;
282
311
  },
283
312
  max(t, other, change) {
284
- if (isNumber(t) && isNumber(other)) return max$4(t, other);
313
+ if (isNumber(t) && isNumber(other)) return max$3(t, other);
285
314
  toTempAB(t, other, change);
286
- return set$2(tempTo, max$4(tempA[0], tempB[0]), max$4(tempA[1], tempB[1]), max$4(tempA[2], tempB[2]), max$4(tempA[3], tempB[3]));
315
+ return set$2(tempTo, max$3(tempA[0], tempB[0]), max$3(tempA[1], tempB[1]), max$3(tempA[2], tempB[2]), max$3(tempA[3], tempB[3]));
287
316
  },
288
317
  add(t, other, change) {
289
318
  if (isNumber(t) && isNumber(other)) return t + other;
@@ -298,7 +327,7 @@ var LeaferUI = function(exports) {
298
327
  }
299
328
  };
300
329
  const {set: set$2, get: get$5, setTemp: setTemp, toTempAB: toTempAB} = FourNumberHelper;
301
- const {round: round$3, pow: pow$1, PI: PI$3} = Math;
330
+ const {round: round$3, pow: pow$1, max: max$2, floor: floor$1, PI: PI$3} = Math;
302
331
  const MathHelper = {
303
332
  within(value, min, max) {
304
333
  if (isObject(min)) max = min.max, min = min.min;
@@ -350,6 +379,9 @@ var LeaferUI = function(exports) {
350
379
  scaleData.scaleY = scale.y;
351
380
  }
352
381
  },
382
+ getFloorScale(num, min = 1) {
383
+ return max$2(floor$1(num), min) / num;
384
+ },
353
385
  randInt: randInt,
354
386
  randColor(opacity) {
355
387
  return `rgba(${randInt(255)},${randInt(255)},${randInt(255)},${opacity || 1})`;
@@ -1141,7 +1173,7 @@ var LeaferUI = function(exports) {
1141
1173
  const {tempPointBounds: tempPointBounds$1, setPoint: setPoint$2, addPoint: addPoint$2, toBounds: toBounds$2} = TwoPointBoundsHelper;
1142
1174
  const {toOuterPoint: toOuterPoint$2} = MatrixHelper;
1143
1175
  const {float: float, fourNumber: fourNumber} = MathHelper;
1144
- const {floor: floor$2, ceil: ceil$2} = Math;
1176
+ const {floor: floor, ceil: ceil$1} = Math;
1145
1177
  let right$1, bottom$1, boundsRight, boundsBottom;
1146
1178
  const point = {};
1147
1179
  const toPoint$4 = {};
@@ -1228,20 +1260,20 @@ var LeaferUI = function(exports) {
1228
1260
  toOuterOf(t, matrix, to) {
1229
1261
  to || (to = t);
1230
1262
  if (matrix.b === 0 && matrix.c === 0) {
1231
- const {a: a, d: d} = matrix;
1263
+ const {a: a, d: d, e: e, f: f} = matrix;
1232
1264
  if (a > 0) {
1233
1265
  to.width = t.width * a;
1234
- to.x = matrix.e + t.x * a;
1266
+ to.x = e + t.x * a;
1235
1267
  } else {
1236
1268
  to.width = t.width * -a;
1237
- to.x = matrix.e + t.x * a - to.width;
1269
+ to.x = e + t.x * a - to.width;
1238
1270
  }
1239
1271
  if (d > 0) {
1240
1272
  to.height = t.height * d;
1241
- to.y = matrix.f + t.y * d;
1273
+ to.y = f + t.y * d;
1242
1274
  } else {
1243
1275
  to.height = t.height * -d;
1244
- to.y = matrix.f + t.y * d - to.height;
1276
+ to.y = f + t.y * d - to.height;
1245
1277
  }
1246
1278
  } else {
1247
1279
  point.x = t.x;
@@ -1293,10 +1325,10 @@ var LeaferUI = function(exports) {
1293
1325
  },
1294
1326
  ceil(t) {
1295
1327
  const {x: x, y: y} = t;
1296
- t.x = floor$2(t.x);
1297
- t.y = floor$2(t.y);
1298
- t.width = x > t.x ? ceil$2(t.width + x - t.x) : ceil$2(t.width);
1299
- t.height = y > t.y ? ceil$2(t.height + y - t.y) : ceil$2(t.height);
1328
+ t.x = floor(t.x);
1329
+ t.y = floor(t.y);
1330
+ t.width = x > t.x ? ceil$1(t.width + x - t.x) : ceil$1(t.width);
1331
+ t.height = y > t.y ? ceil$1(t.height + y - t.y) : ceil$1(t.height);
1300
1332
  },
1301
1333
  unsign(t) {
1302
1334
  if (t.width < 0) {
@@ -2417,7 +2449,7 @@ var LeaferUI = function(exports) {
2417
2449
  data[0] ? drawer.arcTo(x, y, right, y, data[0]) : drawer.lineTo(x, y);
2418
2450
  }
2419
2451
  };
2420
- const {sin: sin$3, cos: cos$3, hypot: hypot, atan2: atan2$1, ceil: ceil$1, abs: abs$3, PI: PI$2, sqrt: sqrt$1, pow: pow} = Math;
2452
+ const {sin: sin$3, cos: cos$3, hypot: hypot, atan2: atan2$1, ceil: ceil, abs: abs$3, PI: PI$2, sqrt: sqrt$1, pow: pow} = Math;
2421
2453
  const {setPoint: setPoint$1, addPoint: addPoint$1} = TwoPointBoundsHelper;
2422
2454
  const {set: set$1, toNumberPoints: toNumberPoints} = PointHelper;
2423
2455
  const {M: M$5, L: L$6, C: C$4, Q: Q$4, Z: Z$5} = PathCommandMap;
@@ -2520,7 +2552,7 @@ var LeaferUI = function(exports) {
2520
2552
  let totalRadian = endRadian - startRadian;
2521
2553
  if (totalRadian < 0) totalRadian += PI2; else if (totalRadian > PI2) totalRadian -= PI2;
2522
2554
  if (anticlockwise) totalRadian -= PI2;
2523
- const parts = ceil$1(abs$3(totalRadian / PI_2));
2555
+ const parts = ceil(abs$3(totalRadian / PI_2));
2524
2556
  const partRadian = totalRadian / parts;
2525
2557
  const partRadian4Sin = sin$3(partRadian / 4);
2526
2558
  const control = 8 / 3 * partRadian4Sin * partRadian4Sin / sin$3(partRadian / 2);
@@ -3480,7 +3512,9 @@ var LeaferUI = function(exports) {
3480
3512
  run() {
3481
3513
  return __awaiter(this, void 0, void 0, function*() {
3482
3514
  try {
3483
- if (this.task && !this.isComplete && this.parent.running) yield this.task();
3515
+ if (this.isComplete) return;
3516
+ if (this.canUse && !this.canUse()) return this.cancel();
3517
+ if (this.task && this.parent.running) yield this.task();
3484
3518
  } catch (error) {
3485
3519
  debug$8.error(error);
3486
3520
  }
@@ -3488,8 +3522,7 @@ var LeaferUI = function(exports) {
3488
3522
  }
3489
3523
  complete() {
3490
3524
  this.isComplete = true;
3491
- this.parent = null;
3492
- this.task = null;
3525
+ this.parent = this.task = this.canUse = null;
3493
3526
  }
3494
3527
  cancel() {
3495
3528
  this.isCancel = true;
@@ -3531,7 +3564,7 @@ var LeaferUI = function(exports) {
3531
3564
  if (config) DataHelper.assign(this.config, config);
3532
3565
  this.empty();
3533
3566
  }
3534
- add(taskCallback, options) {
3567
+ add(taskCallback, options, canUse) {
3535
3568
  let start, parallel, time, delay;
3536
3569
  const task = new TaskItem(taskCallback);
3537
3570
  task.parent = this;
@@ -3542,9 +3575,11 @@ var LeaferUI = function(exports) {
3542
3575
  start = options.start;
3543
3576
  time = options.time;
3544
3577
  delay = options.delay;
3578
+ if (!canUse) canUse = options.canUse;
3545
3579
  }
3546
3580
  if (time) task.time = time;
3547
3581
  if (parallel === false) task.parallel = false;
3582
+ if (canUse) task.canUse = canUse;
3548
3583
  if (isUndefined(delay)) {
3549
3584
  this.push(task, start);
3550
3585
  } else {
@@ -3614,15 +3649,10 @@ var LeaferUI = function(exports) {
3614
3649
  this.timer = setTimeout(() => this.nextTask());
3615
3650
  return;
3616
3651
  }
3617
- if (task.isCancel) {
3618
- this.index++;
3619
- this.runTask();
3620
- return;
3621
- }
3622
3652
  task.run().then(() => {
3623
3653
  this.onTask(task);
3624
3654
  this.index++;
3625
- this.nextTask();
3655
+ task.isCancel ? this.runTask() : this.nextTask();
3626
3656
  }).catch(error => {
3627
3657
  this.onError(error);
3628
3658
  });
@@ -3791,7 +3821,6 @@ var LeaferUI = function(exports) {
3791
3821
  };
3792
3822
  const I = ImageManager;
3793
3823
  const {IMAGE: IMAGE, create: create$1} = IncrementId;
3794
- const {floor: floor$1, max: max$3} = Math;
3795
3824
  class LeaferImage {
3796
3825
  get url() {
3797
3826
  return this.config.url;
@@ -3816,10 +3845,9 @@ var LeaferUI = function(exports) {
3816
3845
  load(onSuccess, onError) {
3817
3846
  if (!this.loading) {
3818
3847
  this.loading = true;
3819
- let {loadImage: loadImage, loadImageWithProgress: loadImageWithProgress} = Platform.origin, onProgress = this.config.showProgress && loadImageWithProgress && this.onProgress.bind(this);
3820
- if (onProgress) loadImage = loadImageWithProgress;
3848
+ const {crossOrigin: crossOrigin} = this.config;
3821
3849
  Resource.tasker.add(() => __awaiter(this, void 0, void 0, function*() {
3822
- return yield loadImage(this.url, onProgress).then(img => this.setView(img)).catch(e => {
3850
+ return yield Platform.origin.loadImage(this.url, isUndefined(crossOrigin) ? Platform.image.crossOrigin : crossOrigin, this).then(img => this.setView(img)).catch(e => {
3823
3851
  this.error = e;
3824
3852
  this.onComplete(false);
3825
3853
  });
@@ -3845,9 +3873,6 @@ var LeaferUI = function(exports) {
3845
3873
  this.view = img;
3846
3874
  this.onComplete(true);
3847
3875
  }
3848
- onProgress(progress) {
3849
- this.progress = progress;
3850
- }
3851
3876
  onComplete(isSuccess) {
3852
3877
  let odd;
3853
3878
  this.waitComplete.forEach((item, index) => {
@@ -3866,7 +3891,7 @@ var LeaferUI = function(exports) {
3866
3891
  getFull(_filters) {
3867
3892
  return this.view;
3868
3893
  }
3869
- getCanvas(width, height, opacity, _filters, xGap, yGap, smooth) {
3894
+ getCanvas(width, height, opacity, filters, xGap, yGap, smooth) {
3870
3895
  width || (width = this.width);
3871
3896
  height || (height = this.height);
3872
3897
  if (this.cache) {
@@ -3879,11 +3904,7 @@ var LeaferUI = function(exports) {
3879
3904
  }
3880
3905
  if (data) return data;
3881
3906
  }
3882
- const canvas = Platform.origin.createCanvas(max$3(floor$1(width + (xGap || 0)), 1), max$3(floor$1(height + (yGap || 0)), 1));
3883
- const ctx = canvas.getContext("2d");
3884
- if (opacity) ctx.globalAlpha = opacity;
3885
- ctx.imageSmoothingEnabled = smooth === false ? false : true;
3886
- ctx.drawImage(this.view, 0, 0, width, height);
3907
+ const canvas = Platform.image.resize(this.view, width, height, xGap, yGap, undefined, smooth, opacity, filters);
3887
3908
  this.cache = this.use > 1 ? {
3888
3909
  data: canvas,
3889
3910
  params: arguments
@@ -3892,13 +3913,7 @@ var LeaferUI = function(exports) {
3892
3913
  }
3893
3914
  getPattern(canvas, repeat, transform, paint) {
3894
3915
  const pattern = Platform.canvas.createPattern(canvas, repeat);
3895
- try {
3896
- if (transform && pattern.setTransform) {
3897
- pattern.setTransform(transform);
3898
- transform = undefined;
3899
- }
3900
- } catch (_a) {}
3901
- if (paint) DataHelper.stintSet(paint, "transform", transform);
3916
+ Platform.image.setPatternTransform(pattern, transform, paint);
3902
3917
  return pattern;
3903
3918
  }
3904
3919
  destroy() {
@@ -5424,12 +5439,12 @@ var LeaferUI = function(exports) {
5424
5439
  const {toBounds: toBounds} = PathBounds;
5425
5440
  const LeafBounds = {
5426
5441
  __updateWorldBounds() {
5427
- const layout = this.__layout;
5428
- toOuterOf$2(layout.renderBounds, this.__world, this.__world);
5429
- if (layout.resized) {
5430
- if (layout.resized === "inner") this.__onUpdateSize();
5442
+ const {__layout: __layout, __world: __world} = this;
5443
+ toOuterOf$2(__layout.renderBounds, __world, __world);
5444
+ if (__layout.resized) {
5445
+ if (__layout.resized === "inner") this.__onUpdateSize();
5431
5446
  if (this.__hasLocalEvent) BoundsEvent.emitLocal(this);
5432
- layout.resized = undefined;
5447
+ __layout.resized = undefined;
5433
5448
  }
5434
5449
  if (this.__hasWorldEvent) BoundsEvent.emitWorld(this);
5435
5450
  },
@@ -5621,7 +5636,7 @@ var LeaferUI = function(exports) {
5621
5636
  };
5622
5637
  const tempScaleData$1 = {};
5623
5638
  const {LEAF: LEAF, create: create} = IncrementId;
5624
- const {stintSet: stintSet$3} = DataHelper;
5639
+ const {stintSet: stintSet$4} = DataHelper;
5625
5640
  const {toInnerPoint: toInnerPoint, toOuterPoint: toOuterPoint, multiplyParent: multiplyParent$1} = MatrixHelper;
5626
5641
  const {toOuterOf: toOuterOf$1} = BoundsHelper;
5627
5642
  const {copy: copy$2, move: move$2} = PointHelper;
@@ -5899,8 +5914,8 @@ var LeaferUI = function(exports) {
5899
5914
  const cameraWorld = this.__cameraWorld, world = this.__world;
5900
5915
  multiplyParent$1(world, options.matrix, cameraWorld, undefined, world);
5901
5916
  toOuterOf$1(this.__layout.renderBounds, cameraWorld, cameraWorld);
5902
- stintSet$3(cameraWorld, "half", world.half);
5903
- stintSet$3(cameraWorld, "ignorePixelSnap", world.ignorePixelSnap);
5917
+ stintSet$4(cameraWorld, "half", world.half);
5918
+ stintSet$4(cameraWorld, "ignorePixelSnap", world.ignorePixelSnap);
5904
5919
  return cameraWorld;
5905
5920
  } else {
5906
5921
  return this.__world;
@@ -6413,7 +6428,7 @@ var LeaferUI = function(exports) {
6413
6428
  this.levelMap = null;
6414
6429
  }
6415
6430
  }
6416
- const version = "1.9.12";
6431
+ const version = "1.10.1";
6417
6432
  class LeaferCanvas extends LeaferCanvasBase {
6418
6433
  get allowBackgroundColor() {
6419
6434
  return true;
@@ -7135,7 +7150,7 @@ var LeaferUI = function(exports) {
7135
7150
  }
7136
7151
  };
7137
7152
  const {parse: parse, objectToCanvasData: objectToCanvasData} = PathConvert;
7138
- const {stintSet: stintSet$2} = DataHelper, {hasTransparent: hasTransparent$2} = ColorConvert;
7153
+ const {stintSet: stintSet$3} = DataHelper, {hasTransparent: hasTransparent$2} = ColorConvert;
7139
7154
  const emptyPaint = {};
7140
7155
  const debug$1 = Debug.get("UIData");
7141
7156
  class UIData extends LeafData {
@@ -7199,7 +7214,7 @@ var LeaferUI = function(exports) {
7199
7214
  setFill(value) {
7200
7215
  if (this.__naturalWidth) this.__removeNaturalSize();
7201
7216
  if (isString(value) || !value) {
7202
- stintSet$2(this, "__isTransparentFill", hasTransparent$2(value));
7217
+ stintSet$3(this, "__isTransparentFill", hasTransparent$2(value));
7203
7218
  this.__isFills && this.__removePaint("fill", true);
7204
7219
  this._fill = value;
7205
7220
  } else if (isObject(value)) {
@@ -7208,7 +7223,7 @@ var LeaferUI = function(exports) {
7208
7223
  }
7209
7224
  setStroke(value) {
7210
7225
  if (isString(value) || !value) {
7211
- stintSet$2(this, "__isTransparentStroke", hasTransparent$2(value));
7226
+ stintSet$3(this, "__isTransparentStroke", hasTransparent$2(value));
7212
7227
  this.__isStrokes && this.__removePaint("stroke", true);
7213
7228
  this._stroke = value;
7214
7229
  } else if (isObject(value)) {
@@ -7266,11 +7281,11 @@ var LeaferUI = function(exports) {
7266
7281
  if (removeInput) this.__removeInput(attrName);
7267
7282
  PaintImage.recycleImage(attrName, this);
7268
7283
  if (attrName === "fill") {
7269
- stintSet$2(this, "__isAlphaPixelFill", undefined);
7284
+ stintSet$3(this, "__isAlphaPixelFill", undefined);
7270
7285
  this._fill = this.__isFills = undefined;
7271
7286
  } else {
7272
- stintSet$2(this, "__isAlphaPixelStroke", undefined);
7273
- stintSet$2(this, "__hasMultiStrokeStyle", undefined);
7287
+ stintSet$3(this, "__isAlphaPixelStroke", undefined);
7288
+ stintSet$3(this, "__hasMultiStrokeStyle", undefined);
7274
7289
  this._stroke = this.__isStrokes = undefined;
7275
7290
  }
7276
7291
  }
@@ -7402,7 +7417,7 @@ var LeaferUI = function(exports) {
7402
7417
  return data;
7403
7418
  }
7404
7419
  }
7405
- const {max: max$2, add: add$1} = FourNumberHelper;
7420
+ const {max: max$1, add: add$1} = FourNumberHelper;
7406
7421
  const UIBounds = {
7407
7422
  __updateStrokeSpread() {
7408
7423
  let spread = 0, boxSpread = 0;
@@ -7417,7 +7432,7 @@ var LeaferUI = function(exports) {
7417
7432
  }
7418
7433
  if (data.__useArrow) spread += strokeWidth * 5;
7419
7434
  if (box) {
7420
- spread = max$2(spread, box.__layout.strokeSpread = box.__updateStrokeSpread());
7435
+ spread = max$1(spread, box.__layout.strokeSpread = box.__updateStrokeSpread());
7421
7436
  boxSpread = Math.max(boxSpread, box.__layout.strokeBoxSpread);
7422
7437
  }
7423
7438
  this.__layout.strokeBoxSpread = boxSpread;
@@ -7427,33 +7442,33 @@ var LeaferUI = function(exports) {
7427
7442
  let spread = 0;
7428
7443
  const {shadow: shadow, innerShadow: innerShadow, blur: blur, backgroundBlur: backgroundBlur, filter: filter, renderSpread: renderSpread} = this.__, {strokeSpread: strokeSpread} = this.__layout, box = this.__box;
7429
7444
  if (shadow) spread = Effect.getShadowRenderSpread(this, shadow);
7430
- if (blur) spread = max$2(spread, blur);
7445
+ if (blur) spread = max$1(spread, blur);
7431
7446
  if (filter) spread = add$1(spread, Filter.getSpread(filter));
7432
7447
  if (renderSpread) spread = add$1(spread, renderSpread);
7433
7448
  if (strokeSpread) spread = add$1(spread, strokeSpread);
7434
7449
  let shapeSpread = spread;
7435
- if (innerShadow) shapeSpread = max$2(shapeSpread, Effect.getInnerShadowSpread(this, innerShadow));
7436
- if (backgroundBlur) shapeSpread = max$2(shapeSpread, backgroundBlur);
7450
+ if (innerShadow) shapeSpread = max$1(shapeSpread, Effect.getInnerShadowSpread(this, innerShadow));
7451
+ if (backgroundBlur) shapeSpread = max$1(shapeSpread, backgroundBlur);
7437
7452
  this.__layout.renderShapeSpread = shapeSpread;
7438
- return box ? max$2(box.__updateRenderSpread(), spread) : spread;
7453
+ return box ? max$1(box.__updateRenderSpread(), spread) : spread;
7439
7454
  }
7440
7455
  };
7441
- const {stintSet: stintSet$1} = DataHelper;
7456
+ const {stintSet: stintSet$2} = DataHelper;
7442
7457
  const UIRender = {
7443
7458
  __updateChange() {
7444
7459
  const data = this.__;
7445
7460
  if (data.__useStroke) {
7446
7461
  const useStroke = data.__useStroke = !!(data.stroke && data.strokeWidth);
7447
- stintSet$1(this.__world, "half", useStroke && data.strokeAlign === "center" && data.strokeWidth % 2);
7448
- stintSet$1(data, "__fillAfterStroke", useStroke && data.strokeAlign === "outside" && data.fill && !data.__isTransparentFill);
7462
+ stintSet$2(this.__world, "half", useStroke && data.strokeAlign === "center" && data.strokeWidth % 2);
7463
+ stintSet$2(data, "__fillAfterStroke", useStroke && data.strokeAlign === "outside" && data.fill && !data.__isTransparentFill);
7449
7464
  }
7450
7465
  if (data.__useEffect) {
7451
7466
  const {shadow: shadow, fill: fill, stroke: stroke} = data, otherEffect = data.innerShadow || data.blur || data.backgroundBlur || data.filter;
7452
- stintSet$1(data, "__isFastShadow", shadow && !otherEffect && shadow.length < 2 && !shadow[0].spread && !Effect.isTransformShadow(shadow[0]) && fill && !data.__isTransparentFill && !(isArray(fill) && fill.length > 1) && (this.useFastShadow || !stroke || stroke && data.strokeAlign === "inside"));
7467
+ stintSet$2(data, "__isFastShadow", shadow && !otherEffect && shadow.length < 2 && !shadow[0].spread && !Effect.isTransformShadow(shadow[0]) && fill && !data.__isTransparentFill && !(isArray(fill) && fill.length > 1) && (this.useFastShadow || !stroke || stroke && data.strokeAlign === "inside"));
7453
7468
  data.__useEffect = !!(shadow || otherEffect);
7454
7469
  }
7455
7470
  data.__checkSingle();
7456
- stintSet$1(data, "__complex", data.__isFills || data.__isStrokes || data.cornerRadius || data.__useEffect);
7471
+ stintSet$2(data, "__complex", data.__isFills || data.__isStrokes || data.cornerRadius || data.__useEffect);
7457
7472
  },
7458
7473
  __drawFast(canvas, options) {
7459
7474
  drawFast(this, canvas, options);
@@ -7469,24 +7484,24 @@ var LeaferUI = function(exports) {
7469
7484
  this.__nowWorld = this.__getNowWorld(options);
7470
7485
  const {shadow: shadow, innerShadow: innerShadow, filter: filter} = data;
7471
7486
  if (shadow) Effect.shadow(this, canvas, shape);
7472
- if (__fillAfterStroke) data.__isStrokes ? Paint.strokes(stroke, this, canvas) : Paint.stroke(stroke, this, canvas);
7473
- if (fill) data.__isFills ? Paint.fills(fill, this, canvas) : Paint.fill(fill, this, canvas);
7487
+ if (__fillAfterStroke) data.__isStrokes ? Paint.strokes(stroke, this, canvas, options) : Paint.stroke(stroke, this, canvas, options);
7488
+ if (fill) data.__isFills ? Paint.fills(fill, this, canvas, options) : Paint.fill(fill, this, canvas, options);
7474
7489
  if (__drawAfterFill) this.__drawAfterFill(canvas, options);
7475
7490
  if (innerShadow) Effect.innerShadow(this, canvas, shape);
7476
- if (stroke && !__fillAfterStroke) data.__isStrokes ? Paint.strokes(stroke, this, canvas) : Paint.stroke(stroke, this, canvas);
7491
+ if (stroke && !__fillAfterStroke) data.__isStrokes ? Paint.strokes(stroke, this, canvas, options) : Paint.stroke(stroke, this, canvas, options);
7477
7492
  if (filter) Filter.apply(filter, this, this.__nowWorld, canvas, originCanvas, shape);
7478
7493
  if (shape.worldCanvas) shape.worldCanvas.recycle();
7479
7494
  shape.canvas.recycle();
7480
7495
  } else {
7481
- if (__fillAfterStroke) data.__isStrokes ? Paint.strokes(stroke, this, canvas) : Paint.stroke(stroke, this, canvas);
7496
+ if (__fillAfterStroke) data.__isStrokes ? Paint.strokes(stroke, this, canvas, options) : Paint.stroke(stroke, this, canvas, options);
7482
7497
  if (__isFastShadow) {
7483
7498
  const shadow = data.shadow[0], {scaleX: scaleX, scaleY: scaleY} = this.getRenderScaleData(true, shadow.scaleFixed);
7484
7499
  canvas.save(), canvas.setWorldShadow(shadow.x * scaleX, shadow.y * scaleY, shadow.blur * scaleX, ColorConvert.string(shadow.color));
7485
7500
  }
7486
- if (fill) data.__isFills ? Paint.fills(fill, this, canvas) : Paint.fill(fill, this, canvas);
7501
+ if (fill) data.__isFills ? Paint.fills(fill, this, canvas, options) : Paint.fill(fill, this, canvas, options);
7487
7502
  if (__isFastShadow) canvas.restore();
7488
7503
  if (__drawAfterFill) this.__drawAfterFill(canvas, options);
7489
- if (stroke && !__fillAfterStroke) data.__isStrokes ? Paint.strokes(stroke, this, canvas) : Paint.stroke(stroke, this, canvas);
7504
+ if (stroke && !__fillAfterStroke) data.__isStrokes ? Paint.strokes(stroke, this, canvas, options) : Paint.stroke(stroke, this, canvas, options);
7490
7505
  }
7491
7506
  } else {
7492
7507
  if (data.__pathInputed) drawFast(this, canvas, options); else this.__drawFast(canvas, options);
@@ -7495,9 +7510,9 @@ var LeaferUI = function(exports) {
7495
7510
  __drawShape(canvas, options) {
7496
7511
  this.__drawRenderPath(canvas);
7497
7512
  const data = this.__, {fill: fill, stroke: stroke} = data;
7498
- if (fill && !options.ignoreFill) data.__isAlphaPixelFill ? Paint.fills(fill, this, canvas) : Paint.fill("#000000", this, canvas);
7513
+ if (fill && !options.ignoreFill) data.__isAlphaPixelFill ? Paint.fills(fill, this, canvas, options) : Paint.fill("#000000", this, canvas, options);
7499
7514
  if (data.__isCanvas) this.__drawAfterFill(canvas, options);
7500
- if (stroke && !options.ignoreStroke) data.__isAlphaPixelStroke ? Paint.strokes(stroke, this, canvas) : Paint.stroke("#000000", this, canvas);
7515
+ if (stroke && !options.ignoreStroke) data.__isAlphaPixelStroke ? Paint.strokes(stroke, this, canvas, options) : Paint.stroke("#000000", this, canvas, options);
7501
7516
  },
7502
7517
  __drawAfterFill(canvas, options) {
7503
7518
  if (this.__.__clipAfterFill) {
@@ -7511,10 +7526,10 @@ var LeaferUI = function(exports) {
7511
7526
  function drawFast(ui, canvas, options) {
7512
7527
  const {fill: fill, stroke: stroke, __drawAfterFill: __drawAfterFill, __fillAfterStroke: __fillAfterStroke} = ui.__;
7513
7528
  ui.__drawRenderPath(canvas);
7514
- if (__fillAfterStroke) Paint.stroke(stroke, ui, canvas);
7515
- if (fill) Paint.fill(fill, ui, canvas);
7529
+ if (__fillAfterStroke) Paint.stroke(stroke, ui, canvas, options);
7530
+ if (fill) Paint.fill(fill, ui, canvas, options);
7516
7531
  if (__drawAfterFill) ui.__drawAfterFill(canvas, options);
7517
- if (stroke && !__fillAfterStroke) Paint.stroke(stroke, ui, canvas);
7532
+ if (stroke && !__fillAfterStroke) Paint.stroke(stroke, ui, canvas, options);
7518
7533
  }
7519
7534
  const RectRender = {
7520
7535
  __drawFast(canvas, options) {
@@ -7649,8 +7664,8 @@ var LeaferUI = function(exports) {
7649
7664
  drawer.roundRect(x, y, width, height, isNumber(cornerRadius) ? [ cornerRadius ] : cornerRadius);
7650
7665
  } else drawer.rect(x, y, width, height);
7651
7666
  }
7652
- drawImagePlaceholder(canvas, _image) {
7653
- Paint.fill(this.__.placeholderColor, this, canvas);
7667
+ drawImagePlaceholder(_paint, canvas, renderOptions) {
7668
+ Paint.fill(this.__.placeholderColor, this, canvas, renderOptions);
7654
7669
  }
7655
7670
  animate(keyframe, _options, _type, _isTemp) {
7656
7671
  this.set(keyframe);
@@ -8513,7 +8528,7 @@ var LeaferUI = function(exports) {
8513
8528
  __decorate([ dataType(false) ], exports.Canvas.prototype, "safeResize", void 0);
8514
8529
  __decorate([ resizeType() ], exports.Canvas.prototype, "contextSettings", void 0);
8515
8530
  exports.Canvas = __decorate([ registerUI() ], exports.Canvas);
8516
- const {copyAndSpread: copyAndSpread$1, includes: includes, spread: spread, setList: setList} = BoundsHelper;
8531
+ const {copyAndSpread: copyAndSpread$1, includes: includes, spread: spread, setList: setList} = BoundsHelper, {stintSet: stintSet$1} = DataHelper;
8517
8532
  exports.Text = class Text extends exports.UI {
8518
8533
  get __tag() {
8519
8534
  return "Text";
@@ -8524,13 +8539,14 @@ var LeaferUI = function(exports) {
8524
8539
  }
8525
8540
  __updateTextDrawData() {
8526
8541
  const data = this.__;
8527
- const {lineHeight: lineHeight, letterSpacing: letterSpacing, fontFamily: fontFamily, fontSize: fontSize, fontWeight: fontWeight, italic: italic, textCase: textCase, textOverflow: textOverflow, padding: padding} = data;
8542
+ const {lineHeight: lineHeight, letterSpacing: letterSpacing, fontFamily: fontFamily, fontSize: fontSize, fontWeight: fontWeight, italic: italic, textCase: textCase, textOverflow: textOverflow, padding: padding, width: width, height: height} = data;
8528
8543
  data.__lineHeight = UnitConvert.number(lineHeight, fontSize);
8529
8544
  data.__letterSpacing = UnitConvert.number(letterSpacing, fontSize);
8530
- data.__padding = padding ? MathHelper.fourNumber(padding) : undefined;
8531
8545
  data.__baseLine = data.__lineHeight - (data.__lineHeight - fontSize * .7) / 2;
8532
8546
  data.__font = `${italic ? "italic " : ""}${textCase === "small-caps" ? "small-caps " : ""}${fontWeight !== "normal" ? fontWeight + " " : ""}${fontSize || 12}px ${fontFamily || "caption"}`;
8533
- data.__clipText = textOverflow !== "show" && !data.__autoSize;
8547
+ stintSet$1(data, "__padding", padding && MathHelper.fourNumber(padding));
8548
+ stintSet$1(data, "__clipText", textOverflow !== "show" && !data.__autoSize);
8549
+ stintSet$1(data, "__isCharMode", width || height || data.__letterSpacing || textCase !== "none");
8534
8550
  data.__textDrawData = TextConvert.getDrawData((data.__isPlacehold = data.placeholder && data.text === "") ? data.placeholder : data.text, this.__);
8535
8551
  }
8536
8552
  __updateBoxBounds() {
@@ -8702,95 +8718,151 @@ var LeaferUI = function(exports) {
8702
8718
  });
8703
8719
  };
8704
8720
  }
8705
- function fillText(ui, canvas) {
8706
- const data = ui.__, {rows: rows, decorationY: decorationY} = data.__textDrawData;
8707
- if (data.__isPlacehold && data.placeholderColor) canvas.fillStyle = data.placeholderColor;
8708
- let row;
8709
- for (let i = 0, len = rows.length; i < len; i++) {
8710
- row = rows[i];
8711
- if (row.text) canvas.fillText(row.text, row.x, row.y); else if (row.data) row.data.forEach(charData => {
8712
- canvas.fillText(charData.char, charData.x, row.y);
8713
- });
8714
- }
8715
- if (decorationY) {
8716
- const {decorationColor: decorationColor, decorationHeight: decorationHeight} = data.__textDrawData;
8717
- if (decorationColor) canvas.fillStyle = decorationColor;
8718
- rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
8719
- }
8720
- }
8721
- function fill(fill, ui, canvas) {
8721
+ function fill(fill, ui, canvas, renderOptions) {
8722
8722
  canvas.fillStyle = fill;
8723
- fillPathOrText(ui, canvas);
8723
+ fillPathOrText(ui, canvas, renderOptions);
8724
8724
  }
8725
- function fills(fills, ui, canvas) {
8726
- let item;
8725
+ function fills(fills, ui, canvas, renderOptions) {
8726
+ let item, originPaint, countImage;
8727
8727
  for (let i = 0, len = fills.length; i < len; i++) {
8728
- item = fills[i];
8728
+ item = fills[i], originPaint = item.originPaint;
8729
8729
  if (item.image) {
8730
- if (PaintImage.checkImage(ui, canvas, item, !ui.__.__font)) continue;
8730
+ countImage ? countImage++ : countImage = 1;
8731
+ if (PaintImage.checkImage(item, !ui.__.__font, ui, canvas, renderOptions)) continue;
8731
8732
  if (!item.style) {
8732
- if (!i && item.image.isPlacehold) ui.drawImagePlaceholder(canvas, item.image);
8733
+ if (countImage === 1 && item.image.isPlacehold) ui.drawImagePlaceholder(item, canvas, renderOptions);
8733
8734
  continue;
8734
8735
  }
8735
8736
  }
8736
8737
  canvas.fillStyle = item.style;
8737
- if (item.transform || item.scaleFixed) {
8738
+ if (item.transform || originPaint.scaleFixed) {
8738
8739
  canvas.save();
8739
8740
  if (item.transform) canvas.transform(item.transform);
8740
- if (item.scaleFixed) {
8741
+ if (originPaint.scaleFixed) {
8741
8742
  const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true);
8742
- if (item.scaleFixed === true || item.scaleFixed === "zoom-in" && scaleX > 1 && scaleY > 1) canvas.scale(1 / scaleX, 1 / scaleY);
8743
+ if (originPaint.scaleFixed === true || originPaint.scaleFixed === "zoom-in" && scaleX > 1 && scaleY > 1) canvas.scale(1 / scaleX, 1 / scaleY);
8743
8744
  }
8744
- if (item.blendMode) canvas.blendMode = item.blendMode;
8745
- fillPathOrText(ui, canvas);
8745
+ if (originPaint.blendMode) canvas.blendMode = originPaint.blendMode;
8746
+ fillPathOrText(ui, canvas, renderOptions);
8746
8747
  canvas.restore();
8747
8748
  } else {
8748
- if (item.blendMode) {
8749
- canvas.saveBlendMode(item.blendMode);
8750
- fillPathOrText(ui, canvas);
8749
+ if (originPaint.blendMode) {
8750
+ canvas.saveBlendMode(originPaint.blendMode);
8751
+ fillPathOrText(ui, canvas, renderOptions);
8751
8752
  canvas.restoreBlendMode();
8752
- } else fillPathOrText(ui, canvas);
8753
+ } else fillPathOrText(ui, canvas, renderOptions);
8754
+ }
8755
+ }
8756
+ }
8757
+ function fillPathOrText(ui, canvas, renderOptions) {
8758
+ ui.__.__font ? Paint.fillText(ui, canvas, renderOptions) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
8759
+ }
8760
+ function fillText(ui, canvas, _renderOptions) {
8761
+ const data = ui.__, {rows: rows, decorationY: decorationY} = data.__textDrawData;
8762
+ if (data.__isPlacehold && data.placeholderColor) canvas.fillStyle = data.placeholderColor;
8763
+ let row;
8764
+ for (let i = 0, len = rows.length; i < len; i++) {
8765
+ row = rows[i];
8766
+ if (row.text) canvas.fillText(row.text, row.x, row.y); else if (row.data) row.data.forEach(charData => {
8767
+ canvas.fillText(charData.char, charData.x, row.y);
8768
+ });
8769
+ }
8770
+ if (decorationY) {
8771
+ const {decorationColor: decorationColor, decorationHeight: decorationHeight} = data.__textDrawData;
8772
+ if (decorationColor) canvas.fillStyle = decorationColor;
8773
+ rows.forEach(row => decorationY.forEach(value => canvas.fillRect(row.x, row.y + value, row.width, decorationHeight)));
8774
+ }
8775
+ }
8776
+ function stroke(stroke, ui, canvas, renderOptions) {
8777
+ const data = ui.__;
8778
+ if (!data.__strokeWidth) return;
8779
+ if (data.__font) {
8780
+ Paint.strokeText(stroke, ui, canvas, renderOptions);
8781
+ } else {
8782
+ switch (data.strokeAlign) {
8783
+ case "center":
8784
+ drawCenter$1(stroke, 1, ui, canvas, renderOptions);
8785
+ break;
8786
+
8787
+ case "inside":
8788
+ drawInside(stroke, ui, canvas, renderOptions);
8789
+ break;
8790
+
8791
+ case "outside":
8792
+ drawOutside(stroke, ui, canvas, renderOptions);
8793
+ break;
8753
8794
  }
8754
8795
  }
8755
8796
  }
8756
- function fillPathOrText(ui, canvas) {
8757
- ui.__.__font ? fillText(ui, canvas) : ui.__.windingRule ? canvas.fill(ui.__.windingRule) : canvas.fill();
8797
+ function strokes(strokes, ui, canvas, renderOptions) {
8798
+ Paint.stroke(strokes, ui, canvas, renderOptions);
8799
+ }
8800
+ function drawCenter$1(stroke, strokeWidthScale, ui, canvas, renderOptions) {
8801
+ const data = ui.__;
8802
+ if (isObject(stroke)) {
8803
+ Paint.drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas, renderOptions);
8804
+ } else {
8805
+ canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
8806
+ canvas.stroke();
8807
+ }
8808
+ if (data.__useArrow) Paint.strokeArrow(stroke, ui, canvas, renderOptions);
8809
+ }
8810
+ function drawInside(stroke, ui, canvas, renderOptions) {
8811
+ canvas.save();
8812
+ canvas.clipUI(ui);
8813
+ drawCenter$1(stroke, 2, ui, canvas, renderOptions);
8814
+ canvas.restore();
8815
+ }
8816
+ function drawOutside(stroke, ui, canvas, renderOptions) {
8817
+ const data = ui.__;
8818
+ if (data.__fillAfterStroke) {
8819
+ drawCenter$1(stroke, 2, ui, canvas, renderOptions);
8820
+ } else {
8821
+ const {renderBounds: renderBounds} = ui.__layout;
8822
+ const out = canvas.getSameCanvas(true, true);
8823
+ ui.__drawRenderPath(out);
8824
+ drawCenter$1(stroke, 2, ui, out, renderOptions);
8825
+ out.clipUI(data);
8826
+ out.clearWorld(renderBounds);
8827
+ LeafHelper.copyCanvasByWorld(ui, canvas, out);
8828
+ out.recycle(ui.__nowWorld);
8829
+ }
8758
8830
  }
8759
- function strokeText(stroke, ui, canvas) {
8831
+ function strokeText(stroke, ui, canvas, renderOptions) {
8760
8832
  switch (ui.__.strokeAlign) {
8761
8833
  case "center":
8762
- drawCenter$1(stroke, 1, ui, canvas);
8834
+ drawCenter(stroke, 1, ui, canvas, renderOptions);
8763
8835
  break;
8764
8836
 
8765
8837
  case "inside":
8766
- drawAlign(stroke, "inside", ui, canvas);
8838
+ drawAlign(stroke, "inside", ui, canvas, renderOptions);
8767
8839
  break;
8768
8840
 
8769
8841
  case "outside":
8770
- ui.__.__fillAfterStroke ? drawCenter$1(stroke, 2, ui, canvas) : drawAlign(stroke, "outside", ui, canvas);
8842
+ ui.__.__fillAfterStroke ? drawCenter(stroke, 2, ui, canvas, renderOptions) : drawAlign(stroke, "outside", ui, canvas, renderOptions);
8771
8843
  break;
8772
8844
  }
8773
8845
  }
8774
- function drawCenter$1(stroke, strokeWidthScale, ui, canvas) {
8846
+ function drawCenter(stroke, strokeWidthScale, ui, canvas, renderOptions) {
8775
8847
  const data = ui.__;
8776
8848
  if (isObject(stroke)) {
8777
- drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas);
8849
+ Paint.drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas, renderOptions);
8778
8850
  } else {
8779
8851
  canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
8780
- drawTextStroke(ui, canvas);
8852
+ Paint.drawTextStroke(ui, canvas, renderOptions);
8781
8853
  }
8782
8854
  }
8783
- function drawAlign(stroke, align, ui, canvas) {
8855
+ function drawAlign(stroke, align, ui, canvas, renderOptions) {
8784
8856
  const out = canvas.getSameCanvas(true, true);
8785
8857
  out.font = ui.__.__font;
8786
- drawCenter$1(stroke, 2, ui, out);
8858
+ drawCenter(stroke, 2, ui, out, renderOptions);
8787
8859
  out.blendMode = align === "outside" ? "destination-out" : "destination-in";
8788
- fillText(ui, out);
8860
+ Paint.fillText(ui, out, renderOptions);
8789
8861
  out.blendMode = "normal";
8790
8862
  LeafHelper.copyCanvasByWorld(ui, canvas, out);
8791
8863
  out.recycle(ui.__nowWorld);
8792
8864
  }
8793
- function drawTextStroke(ui, canvas) {
8865
+ function drawTextStroke(ui, canvas, _renderOptions) {
8794
8866
  let row, data = ui.__.__textDrawData;
8795
8867
  const {rows: rows, decorationY: decorationY} = data;
8796
8868
  for (let i = 0, len = rows.length; i < len; i++) {
@@ -8804,83 +8876,28 @@ var LeaferUI = function(exports) {
8804
8876
  rows.forEach(row => decorationY.forEach(value => canvas.strokeRect(row.x, row.y + value, row.width, decorationHeight)));
8805
8877
  }
8806
8878
  }
8807
- function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas) {
8879
+ function drawStrokesStyle(strokes, strokeWidthScale, isText, ui, canvas, renderOptions) {
8808
8880
  let item;
8809
8881
  const data = ui.__, {__hasMultiStrokeStyle: __hasMultiStrokeStyle} = data;
8810
8882
  __hasMultiStrokeStyle || canvas.setStroke(undefined, data.__strokeWidth * strokeWidthScale, data);
8811
8883
  for (let i = 0, len = strokes.length; i < len; i++) {
8812
8884
  item = strokes[i];
8813
- if (item.image && PaintImage.checkImage(ui, canvas, item, false)) continue;
8885
+ if (item.image && PaintImage.checkImage(item, false, ui, canvas, renderOptions)) continue;
8814
8886
  if (item.style) {
8815
8887
  if (__hasMultiStrokeStyle) {
8816
8888
  const {strokeStyle: strokeStyle} = item;
8817
8889
  strokeStyle ? canvas.setStroke(item.style, data.__getRealStrokeWidth(strokeStyle) * strokeWidthScale, data, strokeStyle) : canvas.setStroke(item.style, data.__strokeWidth * strokeWidthScale, data);
8818
8890
  } else canvas.strokeStyle = item.style;
8819
- if (item.blendMode) {
8820
- canvas.saveBlendMode(item.blendMode);
8821
- isText ? drawTextStroke(ui, canvas) : canvas.stroke();
8891
+ if (item.originPaint.blendMode) {
8892
+ canvas.saveBlendMode(item.originPaint.blendMode);
8893
+ isText ? Paint.drawTextStroke(ui, canvas, renderOptions) : canvas.stroke();
8822
8894
  canvas.restoreBlendMode();
8823
8895
  } else {
8824
- isText ? drawTextStroke(ui, canvas) : canvas.stroke();
8896
+ isText ? Paint.drawTextStroke(ui, canvas, renderOptions) : canvas.stroke();
8825
8897
  }
8826
8898
  }
8827
8899
  }
8828
8900
  }
8829
- function stroke(stroke, ui, canvas) {
8830
- const data = ui.__;
8831
- if (!data.__strokeWidth) return;
8832
- if (data.__font) {
8833
- strokeText(stroke, ui, canvas);
8834
- } else {
8835
- switch (data.strokeAlign) {
8836
- case "center":
8837
- drawCenter(stroke, 1, ui, canvas);
8838
- break;
8839
-
8840
- case "inside":
8841
- drawInside(stroke, ui, canvas);
8842
- break;
8843
-
8844
- case "outside":
8845
- drawOutside(stroke, ui, canvas);
8846
- break;
8847
- }
8848
- }
8849
- }
8850
- function strokes(strokes, ui, canvas) {
8851
- stroke(strokes, ui, canvas);
8852
- }
8853
- function drawCenter(stroke, strokeWidthScale, ui, canvas) {
8854
- const data = ui.__;
8855
- if (isObject(stroke)) {
8856
- drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas);
8857
- } else {
8858
- canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data);
8859
- canvas.stroke();
8860
- }
8861
- if (data.__useArrow) Paint.strokeArrow(stroke, ui, canvas);
8862
- }
8863
- function drawInside(stroke, ui, canvas) {
8864
- canvas.save();
8865
- canvas.clipUI(ui);
8866
- drawCenter(stroke, 2, ui, canvas);
8867
- canvas.restore();
8868
- }
8869
- function drawOutside(stroke, ui, canvas) {
8870
- const data = ui.__;
8871
- if (data.__fillAfterStroke) {
8872
- drawCenter(stroke, 2, ui, canvas);
8873
- } else {
8874
- const {renderBounds: renderBounds} = ui.__layout;
8875
- const out = canvas.getSameCanvas(true, true);
8876
- ui.__drawRenderPath(out);
8877
- drawCenter(stroke, 2, ui, out);
8878
- out.clipUI(data);
8879
- out.clearWorld(renderBounds);
8880
- LeafHelper.copyCanvasByWorld(ui, canvas, out);
8881
- out.recycle(ui.__nowWorld);
8882
- }
8883
- }
8884
8901
  const {getSpread: getSpread, copyAndSpread: copyAndSpread, toOuterOf: toOuterOf, getOuterOf: getOuterOf, getByMove: getByMove, move: move$1, getIntersectData: getIntersectData} = BoundsHelper;
8885
8902
  const tempBounds$1 = {};
8886
8903
  function shape(ui, current, options) {
@@ -8963,61 +8980,62 @@ var LeaferUI = function(exports) {
8963
8980
  if (leafPaints.some(item => item.image)) isAlphaPixel = true;
8964
8981
  isTransparent = true;
8965
8982
  }
8966
- }
8967
- if (attrName === "fill") {
8968
- stintSet(data, "__isAlphaPixelFill", isAlphaPixel);
8969
- stintSet(data, "__isTransparentFill", isTransparent);
8983
+ if (attrName === "fill") {
8984
+ stintSet(data, "__isAlphaPixelFill", isAlphaPixel);
8985
+ stintSet(data, "__isTransparentFill", isTransparent);
8986
+ } else {
8987
+ stintSet(data, "__isAlphaPixelStroke", isAlphaPixel);
8988
+ stintSet(data, "__isTransparentStroke", isTransparent);
8989
+ stintSet(data, "__hasMultiStrokeStyle", maxChildStrokeWidth);
8990
+ }
8970
8991
  } else {
8971
- stintSet(data, "__isAlphaPixelStroke", isAlphaPixel);
8972
- stintSet(data, "__isTransparentStroke", isTransparent);
8973
- stintSet(data, "__hasMultiStrokeStyle", maxChildStrokeWidth);
8992
+ data.__removePaint(attrName, false);
8974
8993
  }
8975
8994
  }
8976
8995
  function getLeafPaint(attrName, paint, ui) {
8977
8996
  if (!isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined;
8978
- let data;
8997
+ let leafPaint;
8979
8998
  const {boxBounds: boxBounds} = ui.__layout;
8980
8999
  switch (paint.type) {
8981
9000
  case "image":
8982
- data = PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
9001
+ leafPaint = PaintImage.image(ui, attrName, paint, boxBounds, !recycleMap || !recycleMap[paint.url]);
8983
9002
  break;
8984
9003
 
8985
9004
  case "linear":
8986
- data = PaintGradient.linearGradient(paint, boxBounds);
9005
+ leafPaint = PaintGradient.linearGradient(paint, boxBounds);
8987
9006
  break;
8988
9007
 
8989
9008
  case "radial":
8990
- data = PaintGradient.radialGradient(paint, boxBounds);
9009
+ leafPaint = PaintGradient.radialGradient(paint, boxBounds);
8991
9010
  break;
8992
9011
 
8993
9012
  case "angular":
8994
- data = PaintGradient.conicGradient(paint, boxBounds);
9013
+ leafPaint = PaintGradient.conicGradient(paint, boxBounds);
8995
9014
  break;
8996
9015
 
8997
9016
  case "solid":
8998
9017
  const {type: type, color: color, opacity: opacity} = paint;
8999
- data = {
9018
+ leafPaint = {
9000
9019
  type: type,
9001
9020
  style: ColorConvert.string(color, opacity)
9002
9021
  };
9003
9022
  break;
9004
9023
 
9005
9024
  default:
9006
- if (!isUndefined(paint.r)) data = {
9025
+ if (!isUndefined(paint.r)) leafPaint = {
9007
9026
  type: "solid",
9008
9027
  style: ColorConvert.string(paint)
9009
9028
  };
9010
9029
  }
9011
- if (data) {
9012
- if (isString(data.style) && hasTransparent$1(data.style)) data.isTransparent = true;
9030
+ if (leafPaint) {
9031
+ leafPaint.originPaint = paint;
9032
+ if (isString(leafPaint.style) && hasTransparent$1(leafPaint.style)) leafPaint.isTransparent = true;
9013
9033
  if (paint.style) {
9014
9034
  if (paint.style.strokeWidth === 0) return undefined;
9015
- data.strokeStyle = paint.style;
9035
+ leafPaint.strokeStyle = paint.style;
9016
9036
  }
9017
- if (paint.editing) data.editing = paint.editing;
9018
- if (paint.blendMode) data.blendMode = paint.blendMode;
9019
9037
  }
9020
- return data;
9038
+ return leafPaint;
9021
9039
  }
9022
9040
  const PaintModule = {
9023
9041
  compute: compute,
@@ -9029,94 +9047,118 @@ var LeaferUI = function(exports) {
9029
9047
  strokes: strokes,
9030
9048
  strokeText: strokeText,
9031
9049
  drawTextStroke: drawTextStroke,
9050
+ drawStrokesStyle: drawStrokesStyle,
9032
9051
  shape: shape
9033
9052
  };
9034
- let origin = {}, tempMatrix$1 = getMatrixData();
9035
- const {get: get$3, set: set, rotateOfOuter: rotateOfOuter$1, translate: translate$1, scaleOfOuter: scaleOfOuter$1, multiplyParent: multiplyParent, scale: scaleHelper, rotate: rotate, skew: skewHelper} = MatrixHelper;
9036
- function stretchMode(data, box, scaleX, scaleY) {
9037
- const transform = get$3();
9038
- translate$1(transform, box.x, box.y);
9039
- if (scaleX) scaleHelper(transform, scaleX, scaleY);
9040
- data.transform = transform;
9041
- }
9042
- function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
9043
- const transform = get$3();
9044
- translate$1(transform, box.x + x, box.y + y);
9045
- scaleHelper(transform, scaleX, scaleY);
9046
- if (rotation) rotateOfOuter$1(transform, {
9047
- x: box.x + box.width / 2,
9048
- y: box.y + box.height / 2
9049
- }, rotation);
9050
- data.transform = transform;
9051
- }
9052
- function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipScaleX, clipScaleY) {
9053
- const transform = get$3();
9054
- layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
9055
- if (clipScaleX) {
9056
- if (rotation || skew) {
9057
- set(tempMatrix$1);
9058
- scaleOfOuter$1(tempMatrix$1, box, clipScaleX, clipScaleY);
9059
- multiplyParent(transform, tempMatrix$1);
9060
- } else scaleOfOuter$1(transform, box, clipScaleX, clipScaleY);
9053
+ let cache, box = new Bounds;
9054
+ const {isSame: isSame} = BoundsHelper;
9055
+ function image(ui, attrName, paint, boxBounds, firstUse) {
9056
+ let leafPaint, event;
9057
+ const image = ImageManager.get(paint);
9058
+ if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
9059
+ leafPaint = cache.leafPaint;
9060
+ } else {
9061
+ leafPaint = {
9062
+ type: paint.type,
9063
+ image: image
9064
+ };
9065
+ if (image.hasAlphaPixel) leafPaint.isTransparent = true;
9066
+ cache = image.use > 1 ? {
9067
+ leafPaint: leafPaint,
9068
+ paint: paint,
9069
+ boxBounds: box.set(boxBounds)
9070
+ } : null;
9061
9071
  }
9062
- data.transform = transform;
9063
- }
9064
- function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, skew, align, freeTransform) {
9065
- const transform = get$3();
9066
- if (freeTransform) {
9067
- layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
9072
+ if (firstUse || image.loading) event = {
9073
+ image: image,
9074
+ attrName: attrName,
9075
+ attrValue: paint
9076
+ };
9077
+ if (image.ready) {
9078
+ checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds);
9079
+ if (firstUse) {
9080
+ onLoad(ui, event);
9081
+ onLoadSuccess(ui, event);
9082
+ }
9083
+ } else if (image.error) {
9084
+ if (firstUse) onLoadError(ui, event, image.error);
9068
9085
  } else {
9069
- if (rotation) {
9070
- if (align === "center") {
9071
- rotateOfOuter$1(transform, {
9072
- x: width / 2,
9073
- y: height / 2
9074
- }, rotation);
9075
- } else {
9076
- rotate(transform, rotation);
9077
- switch (rotation) {
9078
- case 90:
9079
- translate$1(transform, height, 0);
9080
- break;
9081
-
9082
- case 180:
9083
- translate$1(transform, width, height);
9084
- break;
9085
-
9086
- case 270:
9087
- translate$1(transform, 0, width);
9088
- break;
9086
+ if (firstUse) {
9087
+ ignoreRender(ui, true);
9088
+ onLoad(ui, event);
9089
+ }
9090
+ leafPaint.loadId = image.load(() => {
9091
+ ignoreRender(ui, false);
9092
+ if (!ui.destroyed) {
9093
+ if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds)) {
9094
+ if (image.hasAlphaPixel) ui.__layout.hitCanvasChanged = true;
9095
+ ui.forceUpdate("surface");
9089
9096
  }
9097
+ onLoadSuccess(ui, event);
9090
9098
  }
9099
+ leafPaint.loadId = undefined;
9100
+ }, error => {
9101
+ ignoreRender(ui, false);
9102
+ onLoadError(ui, event, error);
9103
+ leafPaint.loadId = undefined;
9104
+ });
9105
+ if (ui.placeholderColor) {
9106
+ if (!ui.placeholderDelay) image.isPlacehold = true; else setTimeout(() => {
9107
+ if (!image.ready) {
9108
+ image.isPlacehold = true;
9109
+ ui.forceUpdate("surface");
9110
+ }
9111
+ }, ui.placeholderDelay);
9091
9112
  }
9092
- origin.x = box.x + x;
9093
- origin.y = box.y + y;
9094
- translate$1(transform, origin.x, origin.y);
9095
- if (scaleX) scaleOfOuter$1(transform, origin, scaleX, scaleY);
9096
9113
  }
9097
- data.transform = transform;
9114
+ return leafPaint;
9098
9115
  }
9099
- function layout(transform, box, x, y, scaleX, scaleY, rotation, skew) {
9100
- if (rotation) rotate(transform, rotation);
9101
- if (skew) skewHelper(transform, skew.x, skew.y);
9102
- if (scaleX) scaleHelper(transform, scaleX, scaleY);
9103
- translate$1(transform, box.x + x, box.y + y);
9116
+ function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
9117
+ if (attrName === "fill" && !ui.__.__naturalWidth) {
9118
+ const data = ui.__;
9119
+ data.__naturalWidth = image.width / data.pixelRatio;
9120
+ data.__naturalHeight = image.height / data.pixelRatio;
9121
+ if (data.__autoSide) {
9122
+ ui.forceUpdate("width");
9123
+ if (ui.__proxyData) {
9124
+ ui.setProxyAttr("width", data.width);
9125
+ ui.setProxyAttr("height", data.height);
9126
+ }
9127
+ return false;
9128
+ }
9129
+ }
9130
+ if (!leafPaint.data) PaintImage.createData(leafPaint, image, paint, boxBounds);
9131
+ return true;
9132
+ }
9133
+ function onLoad(ui, event) {
9134
+ emit(ui, ImageEvent.LOAD, event);
9135
+ }
9136
+ function onLoadSuccess(ui, event) {
9137
+ emit(ui, ImageEvent.LOADED, event);
9138
+ }
9139
+ function onLoadError(ui, event, error) {
9140
+ event.error = error;
9141
+ ui.forceUpdate("surface");
9142
+ emit(ui, ImageEvent.ERROR, event);
9143
+ }
9144
+ function emit(ui, type, data) {
9145
+ if (ui.hasEvent(type)) ui.emitEvent(new ImageEvent(type, data));
9146
+ }
9147
+ function ignoreRender(ui, value) {
9148
+ const {leafer: leafer} = ui;
9149
+ if (leafer && leafer.viewReady) leafer.renderer.ignore = value;
9104
9150
  }
9105
- const {get: get$2, translate: translate} = MatrixHelper;
9151
+ const {get: get$3, translate: translate$1} = MatrixHelper;
9106
9152
  const tempBox = new Bounds;
9107
9153
  const tempScaleData = {};
9108
9154
  const tempImage = {};
9109
9155
  function createData(leafPaint, image, paint, box) {
9110
- const {changeful: changeful, sync: sync, scaleFixed: scaleFixed} = paint;
9111
- if (changeful) leafPaint.changeful = changeful;
9112
- if (sync) leafPaint.sync = sync;
9113
- if (scaleFixed) leafPaint.scaleFixed = scaleFixed;
9114
- leafPaint.data = getPatternData(paint, box, image);
9156
+ leafPaint.data = PaintImage.getPatternData(paint, box, image);
9115
9157
  }
9116
9158
  function getPatternData(paint, box, image) {
9117
9159
  if (paint.padding) box = tempBox.set(box).shrink(paint.padding);
9118
9160
  if (paint.mode === "strench") paint.mode = "stretch";
9119
- let {width: width, height: height} = image;
9161
+ const {width: width, height: height} = image;
9120
9162
  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;
9121
9163
  const sameBox = box.width === width && box.height === height;
9122
9164
  const data = {
@@ -9147,8 +9189,8 @@ var LeaferUI = function(exports) {
9147
9189
  case "stretch":
9148
9190
  if (!sameBox) {
9149
9191
  scaleX = box.width / width, scaleY = box.height / height;
9150
- stretchMode(data, box, scaleX, scaleY);
9151
- }
9192
+ PaintImage.stretchMode(data, box, scaleX, scaleY);
9193
+ } else if (scaleX) scaleX = scaleY = undefined;
9152
9194
  break;
9153
9195
 
9154
9196
  case "normal":
@@ -9156,13 +9198,13 @@ var LeaferUI = function(exports) {
9156
9198
  if (tempImage.x || tempImage.y || scaleX || clipSize || rotation || skew) {
9157
9199
  let clipScaleX, clipScaleY;
9158
9200
  if (clipSize) clipScaleX = box.width / clipSize.width, clipScaleY = box.height / clipSize.height;
9159
- clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, clipScaleX, clipScaleY);
9201
+ PaintImage.clipMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, clipScaleX, clipScaleY);
9160
9202
  if (clipScaleX) scaleX = scaleX ? scaleX * clipScaleX : clipScaleX, scaleY = scaleY ? scaleY * clipScaleY : clipScaleY;
9161
9203
  }
9162
9204
  break;
9163
9205
 
9164
9206
  case "repeat":
9165
- if (!sameBox || scaleX || rotation || skew) repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform);
9207
+ if (!sameBox || scaleX || rotation || skew) PaintImage.repeatMode(data, box, width, height, tempImage.x, tempImage.y, scaleX, scaleY, rotation, skew, align, paint.freeTransform);
9166
9208
  if (!repeat) data.repeat = "repeat";
9167
9209
  const count = isObject(repeat);
9168
9210
  if (gap || count) data.gap = getGapData(gap, count && repeat, tempImage.width, tempImage.height, box);
@@ -9171,18 +9213,16 @@ var LeaferUI = function(exports) {
9171
9213
  case "fit":
9172
9214
  case "cover":
9173
9215
  default:
9174
- if (scaleX) fillOrFitMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
9216
+ if (scaleX) PaintImage.fillOrFitMode(data, box, tempImage.x, tempImage.y, scaleX, scaleY, rotation);
9175
9217
  }
9176
9218
  if (!data.transform) {
9177
- if (box.x || box.y) translate(data.transform = get$2(), box.x, box.y);
9219
+ if (box.x || box.y) translate$1(data.transform = get$3(), box.x, box.y);
9178
9220
  }
9179
- data.width = width;
9180
- data.height = height;
9181
9221
  if (scaleX) {
9182
9222
  data.scaleX = scaleX;
9183
9223
  data.scaleY = scaleY;
9184
9224
  }
9185
- if (opacity) data.opacity = opacity;
9225
+ if (opacity && opacity < 1) data.opacity = opacity;
9186
9226
  if (filters) data.filters = filters;
9187
9227
  if (repeat) data.repeat = isString(repeat) ? repeat === "x" ? "repeat-x" : "repeat-y" : "repeat";
9188
9228
  return data;
@@ -9201,221 +9241,180 @@ var LeaferUI = function(exports) {
9201
9241
  const value = auto ? remain / ((rows || Math.floor(totalSize / size)) - 1) : gap;
9202
9242
  return gap === "auto" ? value < 0 ? 0 : value : value;
9203
9243
  }
9204
- let cache, box = new Bounds;
9205
- const {isSame: isSame} = BoundsHelper;
9206
- function image(ui, attrName, paint, boxBounds, firstUse) {
9207
- let leafPaint, event;
9208
- const image = ImageManager.get(paint);
9209
- if (cache && paint === cache.paint && isSame(boxBounds, cache.boxBounds)) {
9210
- leafPaint = cache.leafPaint;
9211
- } else {
9212
- leafPaint = {
9213
- type: paint.type,
9214
- image: image
9215
- };
9216
- if (image.hasAlphaPixel) leafPaint.isTransparent = true;
9217
- cache = image.use > 1 ? {
9218
- leafPaint: leafPaint,
9219
- paint: paint,
9220
- boxBounds: box.set(boxBounds)
9221
- } : null;
9244
+ let origin = {}, tempMatrix$1 = getMatrixData();
9245
+ const {get: get$2, set: set, rotateOfOuter: rotateOfOuter$1, translate: translate, scaleOfOuter: scaleOfOuter$1, multiplyParent: multiplyParent, scale: scaleHelper, rotate: rotate, skew: skewHelper} = MatrixHelper;
9246
+ function stretchMode(data, box, scaleX, scaleY) {
9247
+ const transform = get$2(), {x: x, y: y} = box;
9248
+ if (x || y) translate(transform, x, y); else transform.onlyScale = true;
9249
+ scaleHelper(transform, scaleX, scaleY);
9250
+ data.transform = transform;
9251
+ }
9252
+ function fillOrFitMode(data, box, x, y, scaleX, scaleY, rotation) {
9253
+ const transform = get$2();
9254
+ translate(transform, box.x + x, box.y + y);
9255
+ scaleHelper(transform, scaleX, scaleY);
9256
+ if (rotation) rotateOfOuter$1(transform, {
9257
+ x: box.x + box.width / 2,
9258
+ y: box.y + box.height / 2
9259
+ }, rotation);
9260
+ data.transform = transform;
9261
+ }
9262
+ function clipMode(data, box, x, y, scaleX, scaleY, rotation, skew, clipScaleX, clipScaleY) {
9263
+ const transform = get$2();
9264
+ layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
9265
+ if (clipScaleX) {
9266
+ if (rotation || skew) {
9267
+ set(tempMatrix$1);
9268
+ scaleOfOuter$1(tempMatrix$1, box, clipScaleX, clipScaleY);
9269
+ multiplyParent(transform, tempMatrix$1);
9270
+ } else scaleOfOuter$1(transform, box, clipScaleX, clipScaleY);
9222
9271
  }
9223
- if (firstUse || image.loading) event = {
9224
- image: image,
9225
- attrName: attrName,
9226
- attrValue: paint
9227
- };
9228
- if (image.ready) {
9229
- checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds);
9230
- if (firstUse) {
9231
- onLoad(ui, event);
9232
- onLoadSuccess(ui, event);
9233
- }
9234
- } else if (image.error) {
9235
- if (firstUse) onLoadError(ui, event, image.error);
9272
+ data.transform = transform;
9273
+ }
9274
+ function repeatMode(data, box, width, height, x, y, scaleX, scaleY, rotation, skew, align, freeTransform) {
9275
+ const transform = get$2();
9276
+ if (freeTransform) {
9277
+ layout(transform, box, x, y, scaleX, scaleY, rotation, skew);
9236
9278
  } else {
9237
- if (firstUse) {
9238
- ignoreRender(ui, true);
9239
- onLoad(ui, event);
9240
- }
9241
- leafPaint.loadId = image.load(() => {
9242
- ignoreRender(ui, false);
9243
- if (!ui.destroyed) {
9244
- if (checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds)) {
9245
- if (image.hasAlphaPixel) ui.__layout.hitCanvasChanged = true;
9246
- ui.forceUpdate("surface");
9279
+ if (rotation) {
9280
+ if (align === "center") {
9281
+ rotateOfOuter$1(transform, {
9282
+ x: width / 2,
9283
+ y: height / 2
9284
+ }, rotation);
9285
+ } else {
9286
+ rotate(transform, rotation);
9287
+ switch (rotation) {
9288
+ case 90:
9289
+ translate(transform, height, 0);
9290
+ break;
9291
+
9292
+ case 180:
9293
+ translate(transform, width, height);
9294
+ break;
9295
+
9296
+ case 270:
9297
+ translate(transform, 0, width);
9298
+ break;
9247
9299
  }
9248
- onLoadSuccess(ui, event);
9249
9300
  }
9250
- leafPaint.loadId = undefined;
9251
- }, error => {
9252
- ignoreRender(ui, false);
9253
- onLoadError(ui, event, error);
9254
- leafPaint.loadId = undefined;
9255
- });
9256
- if (ui.placeholderColor) {
9257
- if (!ui.placeholderDelay) image.isPlacehold = true; else setTimeout(() => {
9258
- if (!image.ready) {
9259
- image.isPlacehold = true;
9260
- ui.forceUpdate("surface");
9261
- }
9262
- }, ui.placeholderDelay);
9263
- }
9264
- }
9265
- return leafPaint;
9266
- }
9267
- function checkSizeAndCreateData(ui, attrName, paint, image, leafPaint, boxBounds) {
9268
- if (attrName === "fill" && !ui.__.__naturalWidth) {
9269
- const data = ui.__;
9270
- data.__naturalWidth = image.width / data.pixelRatio;
9271
- data.__naturalHeight = image.height / data.pixelRatio;
9272
- if (data.__autoSide) {
9273
- ui.forceUpdate("width");
9274
- if (ui.__proxyData) {
9275
- ui.setProxyAttr("width", data.width);
9276
- ui.setProxyAttr("height", data.height);
9277
- }
9278
- return false;
9279
9301
  }
9302
+ origin.x = box.x + x;
9303
+ origin.y = box.y + y;
9304
+ translate(transform, origin.x, origin.y);
9305
+ if (scaleX) scaleOfOuter$1(transform, origin, scaleX, scaleY);
9280
9306
  }
9281
- if (!leafPaint.data) createData(leafPaint, image, paint, boxBounds);
9282
- return true;
9283
- }
9284
- function onLoad(ui, event) {
9285
- emit(ui, ImageEvent.LOAD, event);
9286
- }
9287
- function onLoadSuccess(ui, event) {
9288
- emit(ui, ImageEvent.LOADED, event);
9289
- }
9290
- function onLoadError(ui, event, error) {
9291
- event.error = error;
9292
- ui.forceUpdate("surface");
9293
- emit(ui, ImageEvent.ERROR, event);
9294
- }
9295
- function emit(ui, type, data) {
9296
- if (ui.hasEvent(type)) ui.emitEvent(new ImageEvent(type, data));
9307
+ data.transform = transform;
9297
9308
  }
9298
- function ignoreRender(ui, value) {
9299
- const {leafer: leafer} = ui;
9300
- if (leafer && leafer.viewReady) leafer.renderer.ignore = value;
9309
+ function layout(transform, box, x, y, scaleX, scaleY, rotation, skew) {
9310
+ if (rotation) rotate(transform, rotation);
9311
+ if (skew) skewHelper(transform, skew.x, skew.y);
9312
+ if (scaleX) scaleHelper(transform, scaleX, scaleY);
9313
+ translate(transform, box.x + x, box.y + y);
9301
9314
  }
9302
9315
  const {get: get$1, scale: scale, copy: copy$1} = MatrixHelper;
9303
- const {floor: floor, ceil: ceil, max: max$1, abs: abs$1} = Math;
9304
- function createPattern(ui, paint, pixelRatio) {
9305
- let {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
9306
- const id = scaleX + "-" + scaleY + "-" + pixelRatio;
9316
+ const {getFloorScale: getFloorScale} = MathHelper, {abs: abs$1} = Math;
9317
+ function createPatternTask(paint, ui, canvas, renderOptions) {
9318
+ if (!paint.patternTask) {
9319
+ paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function*() {
9320
+ paint.patternTask = null;
9321
+ if (canvas.bounds.hit(ui.__nowWorld)) PaintImage.createPattern(paint, ui, canvas, renderOptions);
9322
+ ui.forceUpdate("surface");
9323
+ }), 300);
9324
+ }
9325
+ }
9326
+ function createPattern(paint, ui, canvas, renderOptions) {
9327
+ let {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions), id = scaleX + "-" + scaleY;
9307
9328
  if (paint.patternId !== id && !ui.destroyed) {
9308
- const {image: image, data: data} = paint;
9309
- let imageScale, imageMatrix, {width: width, height: height, scaleX: sx, scaleY: sy, transform: transform, repeat: repeat, gap: gap} = data;
9310
- scaleX *= pixelRatio;
9311
- scaleY *= pixelRatio;
9312
- if (sx) {
9313
- sx = abs$1(sx);
9314
- sy = abs$1(sy);
9315
- imageMatrix = get$1();
9316
- copy$1(imageMatrix, transform);
9317
- scale(imageMatrix, 1 / sx, 1 / sy);
9318
- scaleX *= sx;
9319
- scaleY *= sy;
9320
- }
9321
- width *= scaleX;
9322
- height *= scaleY;
9323
- const size = width * height;
9324
- if (!repeat) {
9325
- if (size > Platform.image.maxCacheSize) return false;
9326
- }
9327
- let maxSize = Platform.image.maxPatternSize;
9328
- if (image.isSVG) {
9329
- const ws = width / image.width;
9330
- if (ws > 1) imageScale = ws / ceil(ws);
9331
- } else {
9332
- const imageSize = image.width * image.height;
9333
- if (maxSize > imageSize) maxSize = imageSize;
9334
- }
9335
- if (size > maxSize) imageScale = Math.sqrt(size / maxSize);
9336
- if (imageScale) {
9337
- scaleX /= imageScale;
9338
- scaleY /= imageScale;
9339
- width /= imageScale;
9340
- height /= imageScale;
9341
- }
9342
- if (sx) {
9343
- scaleX /= sx;
9344
- scaleY /= sy;
9345
- }
9346
- const xGap = gap && gap.x * scaleX;
9347
- const yGap = gap && gap.y * scaleY;
9348
- if (transform || scaleX !== 1 || scaleY !== 1) {
9349
- const canvasWidth = width + (xGap || 0);
9350
- const canvasHeight = height + (yGap || 0);
9351
- scaleX /= canvasWidth / max$1(floor(canvasWidth), 1);
9352
- scaleY /= canvasHeight / max$1(floor(canvasHeight), 1);
9353
- if (!imageMatrix) {
9329
+ if (!(Platform.image.isLarge(paint.image, scaleX, scaleY) && !paint.data.repeat)) {
9330
+ const {image: image, data: data} = paint, {transform: transform, gap: gap} = data, fixScale = PaintImage.getPatternFixScale(paint, scaleX, scaleY);
9331
+ let imageMatrix, xGap, yGap, {width: width, height: height} = image;
9332
+ if (fixScale) scaleX *= fixScale, scaleY *= fixScale;
9333
+ width *= scaleX;
9334
+ height *= scaleY;
9335
+ if (gap) {
9336
+ xGap = gap.x * scaleX / abs$1(data.scaleX || 1);
9337
+ yGap = gap.y * scaleY / abs$1(data.scaleY || 1);
9338
+ }
9339
+ if (transform || scaleX !== 1 || scaleY !== 1) {
9340
+ scaleX *= getFloorScale(width + (xGap || 0));
9341
+ scaleY *= getFloorScale(height + (yGap || 0));
9354
9342
  imageMatrix = get$1();
9355
9343
  if (transform) copy$1(imageMatrix, transform);
9344
+ scale(imageMatrix, 1 / scaleX, 1 / scaleY);
9356
9345
  }
9357
- scale(imageMatrix, 1 / scaleX, 1 / scaleY);
9346
+ const imageCanvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap, ui.leafer && ui.leafer.config.smooth);
9347
+ const pattern = image.getPattern(imageCanvas, data.repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
9348
+ paint.style = pattern;
9349
+ paint.patternId = id;
9358
9350
  }
9359
- const canvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap, ui.leafer && ui.leafer.config.smooth);
9360
- const pattern = image.getPattern(canvas, repeat || (Platform.origin.noRepeat || "no-repeat"), imageMatrix, paint);
9361
- paint.style = pattern;
9362
- paint.patternId = id;
9363
- return true;
9351
+ }
9352
+ }
9353
+ function getPatternFixScale(paint, imageScaleX, imageScaleY) {
9354
+ const {image: image} = paint;
9355
+ let fixScale, maxSize = Platform.image.maxPatternSize, imageSize = image.width * image.height;
9356
+ if (image.isSVG) {
9357
+ if (imageScaleX > 1) fixScale = Math.ceil(imageScaleX) / imageScaleX;
9364
9358
  } else {
9365
- return false;
9359
+ if (maxSize > imageSize) maxSize = imageSize;
9366
9360
  }
9361
+ if ((imageSize *= imageScaleX * imageScaleY) > maxSize) fixScale = Math.sqrt(maxSize / imageSize);
9362
+ return fixScale;
9367
9363
  }
9368
- function checkImage(ui, canvas, paint, allowDraw) {
9369
- const {scaleX: scaleX, scaleY: scaleY} = ui.getRenderScaleData(true, paint.scaleFixed);
9370
- const {pixelRatio: pixelRatio} = canvas, {data: data} = paint;
9371
- if (!data || paint.patternId === scaleX + "-" + scaleY + "-" + pixelRatio && !Export.running) {
9364
+ function checkImage(paint, drawImage, ui, canvas, renderOptions) {
9365
+ const {scaleX: scaleX, scaleY: scaleY} = PaintImage.getImageRenderScaleData(paint, ui, canvas, renderOptions);
9366
+ const {image: image, data: data, originPaint: originPaint} = paint, {exporting: exporting} = renderOptions;
9367
+ if (!data || paint.patternId === scaleX + "-" + scaleY && !exporting) {
9372
9368
  return false;
9373
9369
  } else {
9374
- if (allowDraw) {
9370
+ if (drawImage) {
9375
9371
  if (data.repeat) {
9376
- allowDraw = false;
9377
- } else if (!(paint.changeful || Platform.name === "miniapp" && ResizeEvent.isResizing(ui) || Export.running)) {
9378
- let {width: width, height: height} = data;
9379
- width *= scaleX * pixelRatio;
9380
- height *= scaleY * pixelRatio;
9381
- if (data.scaleX) {
9382
- width *= data.scaleX;
9383
- height *= data.scaleY;
9384
- }
9385
- allowDraw = width * height > Platform.image.maxCacheSize;
9372
+ drawImage = false;
9373
+ } else if (!(originPaint.changeful || Platform.name === "miniapp" && ResizeEvent.isResizing(ui) || exporting)) {
9374
+ drawImage = Platform.image.isLarge(image, scaleX, scaleY);
9386
9375
  }
9387
9376
  }
9388
- if (allowDraw) {
9377
+ if (drawImage) {
9389
9378
  if (ui.__.__isFastShadow) {
9390
9379
  canvas.fillStyle = paint.style || "#000";
9391
9380
  canvas.fill();
9392
9381
  }
9393
- drawImage(ui, canvas, paint, data);
9382
+ PaintImage.drawImage(paint, scaleX, scaleY, ui, canvas, renderOptions);
9394
9383
  return true;
9395
9384
  } else {
9396
- if (!paint.style || paint.sync || Export.running) {
9397
- createPattern(ui, paint, pixelRatio);
9398
- } else {
9399
- if (!paint.patternTask) {
9400
- paint.patternTask = ImageManager.patternTasker.add(() => __awaiter(this, void 0, void 0, function*() {
9401
- paint.patternTask = null;
9402
- if (canvas.bounds.hit(ui.__nowWorld)) createPattern(ui, paint, pixelRatio);
9403
- ui.forceUpdate("surface");
9404
- }), 300);
9405
- }
9406
- }
9385
+ if (!paint.style || originPaint.sync || exporting) PaintImage.createPattern(paint, ui, canvas, renderOptions); else PaintImage.createPatternTask(paint, ui, canvas, renderOptions);
9407
9386
  return false;
9408
9387
  }
9409
9388
  }
9410
9389
  }
9411
- function drawImage(ui, canvas, paint, data) {
9412
- canvas.save();
9413
- canvas.clipUI(ui);
9414
- if (paint.blendMode) canvas.blendMode = paint.blendMode;
9415
- if (data.opacity) canvas.opacity *= data.opacity;
9416
- if (data.transform) canvas.transform(data.transform);
9417
- canvas.drawImage(paint.image.getFull(data.filters), 0, 0, data.width, data.height);
9418
- canvas.restore();
9390
+ function drawImage(paint, _imageScaleX, _imageScaleY, ui, canvas, _renderOptions) {
9391
+ const {data: data, image: image} = paint, {blendMode: blendMode} = paint.originPaint, {opacity: opacity, transform: transform} = data, view = image.getFull(data.filters), u = ui.__;
9392
+ let {width: width, height: height} = image, clipUI;
9393
+ if ((clipUI = transform && !transform.onlyScale || u.path || u.cornerRadius) || opacity || blendMode) {
9394
+ canvas.save();
9395
+ clipUI && canvas.clipUI(ui);
9396
+ blendMode && (canvas.blendMode = blendMode);
9397
+ opacity && (canvas.opacity *= opacity);
9398
+ transform && canvas.transform(transform);
9399
+ canvas.drawImage(view, 0, 0, width, height);
9400
+ canvas.restore();
9401
+ } else {
9402
+ if (data.scaleX) width *= data.scaleX, height *= data.scaleY;
9403
+ canvas.drawImage(view, 0, 0, width, height);
9404
+ }
9405
+ }
9406
+ function getImageRenderScaleData(paint, ui, canvas, _renderOptions) {
9407
+ const scaleData = ui.getRenderScaleData(true, paint.originPaint.scaleFixed), {data: data} = paint;
9408
+ if (canvas) {
9409
+ const {pixelRatio: pixelRatio} = canvas;
9410
+ scaleData.scaleX *= pixelRatio;
9411
+ scaleData.scaleY *= pixelRatio;
9412
+ }
9413
+ if (data && data.scaleX) {
9414
+ scaleData.scaleX *= Math.abs(data.scaleX);
9415
+ scaleData.scaleY *= Math.abs(data.scaleY);
9416
+ }
9417
+ return scaleData;
9419
9418
  }
9420
9419
  function recycleImage(attrName, data) {
9421
9420
  const paints = data["_" + attrName];
@@ -9445,8 +9444,12 @@ var LeaferUI = function(exports) {
9445
9444
  const PaintImageModule = {
9446
9445
  image: image,
9447
9446
  checkImage: checkImage,
9448
- createPattern: createPattern,
9447
+ drawImage: drawImage,
9448
+ getImageRenderScaleData: getImageRenderScaleData,
9449
9449
  recycleImage: recycleImage,
9450
+ createPatternTask: createPatternTask,
9451
+ createPattern: createPattern,
9452
+ getPatternFixScale: getPatternFixScale,
9450
9453
  createData: createData,
9451
9454
  getPatternData: getPatternData,
9452
9455
  stretchMode: stretchMode,
@@ -9833,10 +9836,8 @@ var LeaferUI = function(exports) {
9833
9836
  bounds = drawData.bounds;
9834
9837
  findMaxWidth = !bounds.width && !style.autoSizeAlign;
9835
9838
  const {__letterSpacing: __letterSpacing, paraIndent: paraIndent, textCase: textCase} = style;
9836
- const {canvas: canvas} = Platform;
9837
- const {width: width, height: height} = bounds;
9838
- const charMode = width || height || __letterSpacing || textCase !== "none";
9839
- if (charMode) {
9839
+ const {canvas: canvas} = Platform, {width: width} = bounds;
9840
+ if (style.__isCharMode) {
9840
9841
  const wrap = style.textWrap !== "none";
9841
9842
  const breakAll = style.textWrap === "break";
9842
9843
  paraStart = true;
@@ -9957,12 +9958,19 @@ var LeaferUI = function(exports) {
9957
9958
  function layoutChar(drawData, style, width, _height) {
9958
9959
  const {rows: rows} = drawData;
9959
9960
  const {textAlign: textAlign, paraIndent: paraIndent, letterSpacing: letterSpacing} = style;
9960
- let charX, addWordWidth, indentWidth, mode, wordChar, wordsLength;
9961
+ const justifyLast = width && textAlign.includes("both");
9962
+ const justify = justifyLast || width && textAlign.includes("justify");
9963
+ const justifyLetter = justify && textAlign.includes("letter");
9964
+ let charX, remainingWidth, addWordWidth, addLetterWidth, indentWidth, mode, wordChar, wordsLength, isLastWord, canJustify;
9961
9965
  rows.forEach(row => {
9962
9966
  if (row.words) {
9963
9967
  indentWidth = paraIndent && row.paraStart ? paraIndent : 0, wordsLength = row.words.length;
9964
- addWordWidth = width && (textAlign === "justify" || textAlign === "both") && wordsLength > 1 ? (width - row.width - indentWidth) / (wordsLength - 1) : 0;
9965
- mode = letterSpacing || row.isOverflow ? CharMode : addWordWidth > .01 ? WordMode : TextMode;
9968
+ if (justify) {
9969
+ canJustify = !row.paraEnd || justifyLast;
9970
+ remainingWidth = width - row.width - indentWidth;
9971
+ if (justifyLetter) addLetterWidth = remainingWidth / (row.words.reduce((total, item) => total + item.data.length, 0) - 1); else addWordWidth = wordsLength > 1 ? remainingWidth / (wordsLength - 1) : 0;
9972
+ }
9973
+ mode = letterSpacing || row.isOverflow || justifyLetter ? CharMode : addWordWidth ? WordMode : TextMode;
9966
9974
  if (row.isOverflow && !letterSpacing) row.textMode = true;
9967
9975
  if (mode === TextMode) {
9968
9976
  row.x += indentWidth;
@@ -9980,11 +9988,15 @@ var LeaferUI = function(exports) {
9980
9988
  charX = toWordChar(word.data, charX, wordChar);
9981
9989
  if (row.isOverflow || wordChar.char !== " ") row.data.push(wordChar);
9982
9990
  } else {
9983
- charX = toChar(word.data, charX, row.data, row.isOverflow);
9991
+ charX = toChar(word.data, charX, row.data, row.isOverflow, canJustify && addLetterWidth);
9984
9992
  }
9985
- if (addWordWidth && (!row.paraEnd || textAlign === "both") && index !== wordsLength - 1) {
9986
- charX += addWordWidth;
9987
- row.width += addWordWidth;
9993
+ if (canJustify) {
9994
+ isLastWord = index === wordsLength - 1;
9995
+ if (addWordWidth) {
9996
+ if (!isLastWord) charX += addWordWidth, row.width += addWordWidth;
9997
+ } else if (addLetterWidth) {
9998
+ row.width += addLetterWidth * (word.data.length - (isLastWord ? 1 : 0));
9999
+ }
9988
10000
  }
9989
10001
  });
9990
10002
  }
@@ -10007,13 +10019,14 @@ var LeaferUI = function(exports) {
10007
10019
  });
10008
10020
  return charX;
10009
10021
  }
10010
- function toChar(data, charX, rowData, isOverflow) {
10022
+ function toChar(data, charX, rowData, isOverflow, addLetterWidth) {
10011
10023
  data.forEach(char => {
10012
10024
  if (isOverflow || char.char !== " ") {
10013
10025
  char.x = charX;
10014
10026
  rowData.push(char);
10015
10027
  }
10016
10028
  charX += char.width;
10029
+ addLetterWidth && (charX += addLetterWidth);
10017
10030
  });
10018
10031
  return charX;
10019
10032
  }
@@ -10149,10 +10162,10 @@ var LeaferUI = function(exports) {
10149
10162
  let x = 0, y = 0;
10150
10163
  let width = style.__getInput("width") || 0;
10151
10164
  let height = style.__getInput("height") || 0;
10152
- const {textDecoration: textDecoration, __font: __font, __padding: padding} = style;
10165
+ const {__padding: padding} = style;
10153
10166
  if (padding) {
10154
- if (width) x = padding[left], width -= padding[right] + padding[left]; else if (!style.autoSizeAlign) x = padding[left];
10155
- if (height) y = padding[top], height -= padding[top] + padding[bottom]; else if (!style.autoSizeAlign) y = padding[top];
10167
+ if (width) x = padding[left], width -= padding[right] + padding[left], !width && (width = .01); else if (!style.autoSizeAlign) x = padding[left];
10168
+ if (height) y = padding[top], height -= padding[top] + padding[bottom], !height && (height = .01); else if (!style.autoSizeAlign) y = padding[top];
10156
10169
  }
10157
10170
  const drawData = {
10158
10171
  bounds: {
@@ -10163,14 +10176,14 @@ var LeaferUI = function(exports) {
10163
10176
  },
10164
10177
  rows: [],
10165
10178
  paraNumber: 0,
10166
- font: Platform.canvas.font = __font
10179
+ font: Platform.canvas.font = style.__font
10167
10180
  };
10168
10181
  createRows(drawData, content, style);
10169
10182
  if (padding) padAutoText(padding, drawData, style, width, height);
10170
10183
  layoutText(drawData, style);
10171
- layoutChar(drawData, style, width);
10184
+ if (style.__isCharMode) layoutChar(drawData, style, width);
10172
10185
  if (drawData.overflow) clipText(drawData, style, x, width);
10173
- if (textDecoration !== "none") decorationText(drawData, style);
10186
+ if (style.textDecoration !== "none") decorationText(drawData, style);
10174
10187
  return drawData;
10175
10188
  }
10176
10189
  function padAutoText(padding, drawData, style, width, height) {