@leafer/core 1.12.4 → 2.0.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/lib/core.cjs CHANGED
@@ -209,59 +209,6 @@ class LeafData {
209
209
  }
210
210
  }
211
211
 
212
- const {floor: floor$2, max: max$2} = Math;
213
-
214
- const Platform = {
215
- toURL(text, fileType) {
216
- let url = encodeURIComponent(text);
217
- if (fileType === "text") url = "data:text/plain;charset=utf-8," + url; else if (fileType === "svg") url = "data:image/svg+xml," + url;
218
- return url;
219
- },
220
- image: {
221
- hitCanvasSize: 100,
222
- maxCacheSize: 2560 * 1600,
223
- maxPatternSize: 4096 * 2160,
224
- crossOrigin: "anonymous",
225
- isLarge(size, scaleX, scaleY, largeSize) {
226
- return size.width * size.height * (scaleX ? scaleX * scaleY : 1) > (largeSize || image.maxCacheSize);
227
- },
228
- isSuperLarge(size, scaleX, scaleY) {
229
- return image.isLarge(size, scaleX, scaleY, image.maxPatternSize);
230
- },
231
- getRealURL(url) {
232
- const {prefix: prefix, suffix: suffix} = Platform.image;
233
- if (suffix && !url.startsWith("data:") && !url.startsWith("blob:")) url += (url.includes("?") ? "&" : "?") + suffix;
234
- if (prefix && url[0] === "/") url = prefix + url;
235
- return url;
236
- },
237
- resize(image, width, height, xGap, yGap, clip, smooth, opacity, _filters) {
238
- const canvas = Platform.origin.createCanvas(max$2(floor$2(width + (xGap || 0)), 1), max$2(floor$2(height + (yGap || 0)), 1));
239
- const ctx = canvas.getContext("2d");
240
- if (opacity) ctx.globalAlpha = opacity;
241
- ctx.imageSmoothingEnabled = smooth === false ? false : true;
242
- if (image) {
243
- if (clip) {
244
- const scaleX = width / clip.width, scaleY = height / clip.height;
245
- ctx.setTransform(scaleX, 0, 0, scaleY, -clip.x * scaleX, -clip.y * scaleY);
246
- ctx.drawImage(image, 0, 0, image.width, image.height);
247
- } else ctx.drawImage(image, 0, 0, width, height);
248
- }
249
- return canvas;
250
- },
251
- setPatternTransform(pattern, transform, paint) {
252
- try {
253
- if (transform && pattern.setTransform) {
254
- pattern.setTransform(transform);
255
- transform = undefined;
256
- }
257
- } catch (_a) {}
258
- if (paint) DataHelper.stintSet(paint, "transform", transform);
259
- }
260
- }
261
- };
262
-
263
- const {image: image} = Platform;
264
-
265
212
  const IncrementId = {
266
213
  RUNTIME: "runtime",
267
214
  LEAF: "leaf",
@@ -284,7 +231,7 @@ const I$1 = IncrementId;
284
231
 
285
232
  let tempA, tempB, tempTo;
286
233
 
287
- const {max: max$1} = Math, tempFour = [ 0, 0, 0, 0 ];
234
+ const {max: max$2} = Math, tempFour = [ 0, 0, 0, 0 ];
288
235
 
289
236
  const FourNumberHelper = {
290
237
  zero: [ ...tempFour ],
@@ -336,9 +283,9 @@ const FourNumberHelper = {
336
283
  return data;
337
284
  },
338
285
  max(t, other, change) {
339
- if (isNumber(t) && isNumber(other)) return max$1(t, other);
286
+ if (isNumber(t) && isNumber(other)) return max$2(t, other);
340
287
  toTempAB(t, other, change);
341
- return set$1(tempTo, max$1(tempA[0], tempB[0]), max$1(tempA[1], tempB[1]), max$1(tempA[2], tempB[2]), max$1(tempA[3], tempB[3]));
288
+ return set$1(tempTo, max$2(tempA[0], tempB[0]), max$2(tempA[1], tempB[1]), max$2(tempA[2], tempB[2]), max$2(tempA[3], tempB[3]));
342
289
  },
343
290
  add(t, other, change) {
344
291
  if (isNumber(t) && isNumber(other)) return t + other;
@@ -355,7 +302,7 @@ const FourNumberHelper = {
355
302
 
356
303
  const {set: set$1, get: get$1, setTemp: setTemp, toTempAB: toTempAB} = FourNumberHelper;
357
304
 
358
- const {round: round$3, pow: pow$1, max: max, floor: floor$1, PI: PI$1} = Math;
305
+ const {round: round$3, pow: pow$1, max: max$1, floor: floor$2, PI: PI$1} = Math;
359
306
 
360
307
  const MathHelper = {
361
308
  within(value, min, max) {
@@ -409,7 +356,7 @@ const MathHelper = {
409
356
  }
410
357
  },
411
358
  getFloorScale(num, min = 1) {
412
- return max(floor$1(num), min) / num;
359
+ return max$1(floor$2(num), min) / num;
413
360
  },
414
361
  randInt: randInt,
415
362
  randColor(opacity) {
@@ -1254,7 +1201,7 @@ const {toOuterPoint: toOuterPoint$2} = MatrixHelper;
1254
1201
 
1255
1202
  const {float: float, fourNumber: fourNumber} = MathHelper;
1256
1203
 
1257
- const {floor: floor, ceil: ceil$1} = Math;
1204
+ const {floor: floor$1, ceil: ceil$1} = Math;
1258
1205
 
1259
1206
  let right, bottom, boundsRight, boundsBottom;
1260
1207
 
@@ -1411,8 +1358,8 @@ const BoundsHelper = {
1411
1358
  },
1412
1359
  ceil(t) {
1413
1360
  const {x: x, y: y} = t;
1414
- t.x = floor(t.x);
1415
- t.y = floor(t.y);
1361
+ t.x = floor$1(t.x);
1362
+ t.y = floor$1(t.y);
1416
1363
  t.width = x > t.x ? ceil$1(t.width + x - t.x) : ceil$1(t.width);
1417
1364
  t.height = y > t.y ? ceil$1(t.height + y - t.y) : ceil$1(t.height);
1418
1365
  },
@@ -1544,6 +1491,9 @@ const BoundsHelper = {
1544
1491
  isEmpty(t) {
1545
1492
  return t.x === 0 && t.y === 0 && t.width === 0 && t.height === 0;
1546
1493
  },
1494
+ hasSize(t) {
1495
+ return t.width && t.height;
1496
+ },
1547
1497
  reset(t) {
1548
1498
  B.set(t);
1549
1499
  }
@@ -1720,6 +1670,12 @@ class AutoBounds {
1720
1670
  }
1721
1671
  }
1722
1672
 
1673
+ const UnitConvertHelper = {
1674
+ number(value, percentRefer) {
1675
+ return isObject(value) ? value.type === "percent" ? value.value * percentRefer : value.value : value;
1676
+ }
1677
+ };
1678
+
1723
1679
  const StringNumberMap = {
1724
1680
  0: 1,
1725
1681
  1: 1,
@@ -1736,6 +1692,69 @@ const StringNumberMap = {
1736
1692
  E: 1
1737
1693
  };
1738
1694
 
1695
+ const {floor: floor, max: max} = Math;
1696
+
1697
+ const Platform = {
1698
+ toURL(text, fileType) {
1699
+ let url = encodeURIComponent(text);
1700
+ if (fileType === "text") url = "data:text/plain;charset=utf-8," + url; else if (fileType === "svg") url = "data:image/svg+xml," + url;
1701
+ return url;
1702
+ },
1703
+ image: {
1704
+ hitCanvasSize: 100,
1705
+ maxCacheSize: 2560 * 1600,
1706
+ maxPatternSize: 4096 * 2160,
1707
+ crossOrigin: "anonymous",
1708
+ isLarge(size, scaleX, scaleY, largeSize) {
1709
+ return size.width * size.height * (scaleX ? scaleX * scaleY : 1) > (largeSize || image.maxCacheSize);
1710
+ },
1711
+ isSuperLarge(size, scaleX, scaleY) {
1712
+ return image.isLarge(size, scaleX, scaleY, image.maxPatternSize);
1713
+ },
1714
+ getRealURL(url) {
1715
+ const {prefix: prefix, suffix: suffix} = image;
1716
+ if (suffix && !url.startsWith("data:") && !url.startsWith("blob:")) url += (url.includes("?") ? "&" : "?") + suffix;
1717
+ if (prefix && url[0] === "/") url = prefix + url;
1718
+ return url;
1719
+ },
1720
+ resize(view, width, height, xGap, yGap, clip, smooth, opacity, _filters, interlace) {
1721
+ const realWidth = max(floor(width + (xGap || 0)), 1), realHeight = max(floor(height + (yGap || 0)), 1);
1722
+ let interlaceX, interlaceY, interlaceOffset;
1723
+ if (interlace && (interlaceOffset = UnitConvertHelper.number(interlace.offset, interlace.type === "x" ? width : height))) interlace.type === "x" ? interlaceX = true : interlaceY = true;
1724
+ const canvas = Platform.origin.createCanvas(interlaceY ? realWidth * 2 : realWidth, interlaceX ? realHeight * 2 : realHeight);
1725
+ const ctx = canvas.getContext("2d");
1726
+ if (opacity) ctx.globalAlpha = opacity;
1727
+ ctx.imageSmoothingEnabled = smooth === false ? false : true;
1728
+ if (image.canUse(view)) {
1729
+ if (clip) {
1730
+ const scaleX = width / clip.width, scaleY = height / clip.height;
1731
+ ctx.setTransform(scaleX, 0, 0, scaleY, -clip.x * scaleX, -clip.y * scaleY);
1732
+ ctx.drawImage(view, 0, 0, view.width, view.height);
1733
+ } else ctx.drawImage(view, 0, 0, width, height);
1734
+ if (interlaceOffset) {
1735
+ ctx.drawImage(canvas, 0, 0, realWidth, realHeight, interlaceX ? interlaceOffset - realWidth : realWidth, interlaceX ? realHeight : interlaceOffset - realHeight, realWidth, realHeight);
1736
+ ctx.drawImage(canvas, 0, 0, realWidth, realHeight, interlaceX ? interlaceOffset : realWidth, interlaceX ? realHeight : interlaceOffset, realWidth, realHeight);
1737
+ }
1738
+ }
1739
+ return canvas;
1740
+ },
1741
+ canUse(view) {
1742
+ return view && view.width && !view.__closed;
1743
+ },
1744
+ setPatternTransform(pattern, transform, paint) {
1745
+ try {
1746
+ if (transform && pattern.setTransform) {
1747
+ pattern.setTransform(transform);
1748
+ transform = undefined;
1749
+ }
1750
+ } catch (_a) {}
1751
+ if (paint) DataHelper.stintSet(paint, "transform", transform);
1752
+ }
1753
+ }
1754
+ };
1755
+
1756
+ const {image: image} = Platform;
1757
+
1739
1758
  const {randColor: randColor} = MathHelper;
1740
1759
 
1741
1760
  class Debug {
@@ -3291,10 +3310,10 @@ const PathCommandDataHelper = {
3291
3310
  data.push(O$2, x, y, radius, startAngle, endAngle, anticlockwise ? 1 : 0);
3292
3311
  }
3293
3312
  },
3294
- arcTo(data, x1, y1, x2, y2, radius, lastX, lastY) {
3313
+ arcTo(data, x1, y1, x2, y2, radius, lastX, lastY, fullRadius) {
3295
3314
  if (!isUndefined(lastX)) {
3296
- const d = getMinDistanceFrom(lastX, lastY, x1, y1, x2, y2);
3297
- radius = min(radius, min(d / 2, d / 2 * abs(tan(getRadianFrom(lastX, lastY, x1, y1, x2, y2) / 2))));
3315
+ const r = getMinDistanceFrom(lastX, lastY, x1, y1, x2, y2) / (fullRadius ? 1 : 2);
3316
+ radius = min(radius, min(r, r * abs(tan(getRadianFrom(lastX, lastY, x1, y1, x2, y2) / 2))));
3298
3317
  }
3299
3318
  data.push(U$2, x1, y1, x2, y2, radius);
3300
3319
  },
@@ -3638,7 +3657,7 @@ const PathCorner = {
3638
3657
  let command, lastCommand, commandLen;
3639
3658
  let i = 0, x = 0, y = 0, startX = 0, startY = 0, secondX = 0, secondY = 0, lastX = 0, lastY = 0;
3640
3659
  if (isArray(cornerRadius)) cornerRadius = cornerRadius[0] || 0;
3641
- const len = data.length;
3660
+ const len = data.length, three = len === 9;
3642
3661
  const smooth = [];
3643
3662
  while (i < len) {
3644
3663
  command = data[i];
@@ -3650,7 +3669,7 @@ const PathCorner = {
3650
3669
  if (data[i] === L$1) {
3651
3670
  secondX = data[i + 1];
3652
3671
  secondY = data[i + 2];
3653
- smooth.push(M, getCenterX(startX, secondX), getCenterY(startY, secondY));
3672
+ three ? smooth.push(M, startX, startY) : smooth.push(M, getCenterX(startX, secondX), getCenterY(startY, secondY));
3654
3673
  } else {
3655
3674
  smooth.push(M, startX, startY);
3656
3675
  }
@@ -3662,11 +3681,11 @@ const PathCorner = {
3662
3681
  i += 3;
3663
3682
  switch (data[i]) {
3664
3683
  case L$1:
3665
- arcTo(smooth, x, y, data[i + 1], data[i + 2], cornerRadius, lastX, lastY);
3684
+ arcTo(smooth, x, y, data[i + 1], data[i + 2], cornerRadius, lastX, lastY, three);
3666
3685
  break;
3667
3686
 
3668
3687
  case Z:
3669
- arcTo(smooth, x, y, startX, startY, cornerRadius, lastX, lastY);
3688
+ arcTo(smooth, x, y, startX, startY, cornerRadius, lastX, lastY, three);
3670
3689
  break;
3671
3690
 
3672
3691
  default:
@@ -3678,7 +3697,7 @@ const PathCorner = {
3678
3697
 
3679
3698
  case Z:
3680
3699
  if (lastCommand !== Z) {
3681
- arcTo(smooth, startX, startY, secondX, secondY, cornerRadius, lastX, lastY);
3700
+ arcTo(smooth, startX, startY, secondX, secondY, cornerRadius, lastX, lastY, three);
3682
3701
  smooth.push(Z);
3683
3702
  }
3684
3703
  i += 1;
@@ -3778,9 +3797,10 @@ class TaskItem {
3778
3797
  run() {
3779
3798
  return __awaiter(this, void 0, void 0, function*() {
3780
3799
  try {
3781
- if (this.isComplete) return;
3800
+ if (this.isComplete || this.runing) return;
3801
+ this.runing = true;
3782
3802
  if (this.canUse && !this.canUse()) return this.cancel();
3783
- if (this.task && this.parent.running) yield this.task();
3803
+ if (this.task) yield this.task();
3784
3804
  } catch (error) {
3785
3805
  debug$4.error(error);
3786
3806
  }
@@ -3896,7 +3916,7 @@ class TaskProcessor {
3896
3916
  stop() {
3897
3917
  this.isComplete = true;
3898
3918
  this.list.forEach(task => {
3899
- if (!task.isComplete) task.cancel();
3919
+ if (!task.isComplete) task.run();
3900
3920
  });
3901
3921
  this.pause();
3902
3922
  this.empty();
@@ -4186,7 +4206,7 @@ class LeaferImage {
4186
4206
  getFull(_filters) {
4187
4207
  return this.view;
4188
4208
  }
4189
- getCanvas(width, height, opacity, filters, xGap, yGap, smooth) {
4209
+ getCanvas(width, height, opacity, filters, xGap, yGap, smooth, interlace) {
4190
4210
  width || (width = this.width);
4191
4211
  height || (height = this.height);
4192
4212
  if (this.cache) {
@@ -4199,7 +4219,7 @@ class LeaferImage {
4199
4219
  }
4200
4220
  if (data) return data;
4201
4221
  }
4202
- const canvas = Platform.image.resize(this.view, width, height, xGap, yGap, undefined, smooth, opacity, filters);
4222
+ const canvas = Platform.image.resize(this.view, width, height, xGap, yGap, undefined, smooth, opacity, filters, interlace);
4203
4223
  this.cache = this.use > 1 ? {
4204
4224
  data: canvas,
4205
4225
  params: arguments
@@ -6091,7 +6111,7 @@ const LeafRender = {
6091
6111
  }
6092
6112
  };
6093
6113
 
6094
- const {excludeRenderBounds: excludeRenderBounds} = LeafBoundsHelper;
6114
+ const {excludeRenderBounds: excludeRenderBounds} = LeafBoundsHelper, {hasSize: hasSize} = BoundsHelper;
6095
6115
 
6096
6116
  const BranchRender = {
6097
6117
  __updateChange() {
@@ -6103,8 +6123,8 @@ const BranchRender = {
6103
6123
  this.__.__checkSingle();
6104
6124
  },
6105
6125
  __render(canvas, options) {
6106
- this.__nowWorld = this.__getNowWorld(options);
6107
- if (this.__worldOpacity) {
6126
+ const nowWorld = this.__nowWorld = this.__getNowWorld(options);
6127
+ if (this.__worldOpacity && hasSize(nowWorld)) {
6108
6128
  const data = this.__;
6109
6129
  if (data.__useDim) {
6110
6130
  if (data.dim) options.dimOpacity = data.dim === true ? .2 : data.dim; else if (data.bright && !options.topRendering) return options.topList.add(this); else if (data.dimskip) options.dimOpacity && (options.dimOpacity = 0);
@@ -6113,7 +6133,6 @@ const BranchRender = {
6113
6133
  if (data.eraser === "path") return this.__renderEraser(canvas, options);
6114
6134
  const tempCanvas = canvas.getSameCanvas(false, true);
6115
6135
  this.__renderBranch(tempCanvas, options);
6116
- const nowWorld = this.__nowWorld;
6117
6136
  canvas.opacity = options.dimOpacity ? data.opacity * options.dimOpacity : data.opacity;
6118
6137
  canvas.copyWorldByReset(tempCanvas, nowWorld, nowWorld, data.__blendMode, true);
6119
6138
  tempCanvas.recycle(nowWorld);
@@ -6953,7 +6972,7 @@ class LeafLevelList {
6953
6972
  }
6954
6973
  }
6955
6974
 
6956
- const version = "1.12.4";
6975
+ const version = "2.0.1";
6957
6976
 
6958
6977
  exports.AlignHelper = AlignHelper;
6959
6978
 
@@ -7097,6 +7116,8 @@ exports.TwoPointBoundsHelper = TwoPointBoundsHelper;
7097
7116
 
7098
7117
  exports.UICreator = UICreator;
7099
7118
 
7119
+ exports.UnitConvertHelper = UnitConvertHelper;
7120
+
7100
7121
  exports.WaitHelper = WaitHelper;
7101
7122
 
7102
7123
  exports.WatchEvent = WatchEvent;