@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.esm.js CHANGED
@@ -207,59 +207,6 @@ class LeafData {
207
207
  }
208
208
  }
209
209
 
210
- const {floor: floor$2, max: max$2} = Math;
211
-
212
- const Platform = {
213
- toURL(text, fileType) {
214
- let url = encodeURIComponent(text);
215
- if (fileType === "text") url = "data:text/plain;charset=utf-8," + url; else if (fileType === "svg") url = "data:image/svg+xml," + url;
216
- return url;
217
- },
218
- image: {
219
- hitCanvasSize: 100,
220
- maxCacheSize: 2560 * 1600,
221
- maxPatternSize: 4096 * 2160,
222
- crossOrigin: "anonymous",
223
- isLarge(size, scaleX, scaleY, largeSize) {
224
- return size.width * size.height * (scaleX ? scaleX * scaleY : 1) > (largeSize || image.maxCacheSize);
225
- },
226
- isSuperLarge(size, scaleX, scaleY) {
227
- return image.isLarge(size, scaleX, scaleY, image.maxPatternSize);
228
- },
229
- getRealURL(url) {
230
- const {prefix: prefix, suffix: suffix} = Platform.image;
231
- if (suffix && !url.startsWith("data:") && !url.startsWith("blob:")) url += (url.includes("?") ? "&" : "?") + suffix;
232
- if (prefix && url[0] === "/") url = prefix + url;
233
- return url;
234
- },
235
- resize(image, width, height, xGap, yGap, clip, smooth, opacity, _filters) {
236
- const canvas = Platform.origin.createCanvas(max$2(floor$2(width + (xGap || 0)), 1), max$2(floor$2(height + (yGap || 0)), 1));
237
- const ctx = canvas.getContext("2d");
238
- if (opacity) ctx.globalAlpha = opacity;
239
- ctx.imageSmoothingEnabled = smooth === false ? false : true;
240
- if (image) {
241
- if (clip) {
242
- const scaleX = width / clip.width, scaleY = height / clip.height;
243
- ctx.setTransform(scaleX, 0, 0, scaleY, -clip.x * scaleX, -clip.y * scaleY);
244
- ctx.drawImage(image, 0, 0, image.width, image.height);
245
- } else ctx.drawImage(image, 0, 0, width, height);
246
- }
247
- return canvas;
248
- },
249
- setPatternTransform(pattern, transform, paint) {
250
- try {
251
- if (transform && pattern.setTransform) {
252
- pattern.setTransform(transform);
253
- transform = undefined;
254
- }
255
- } catch (_a) {}
256
- if (paint) DataHelper.stintSet(paint, "transform", transform);
257
- }
258
- }
259
- };
260
-
261
- const {image: image} = Platform;
262
-
263
210
  const IncrementId = {
264
211
  RUNTIME: "runtime",
265
212
  LEAF: "leaf",
@@ -282,7 +229,7 @@ const I$1 = IncrementId;
282
229
 
283
230
  let tempA, tempB, tempTo;
284
231
 
285
- const {max: max$1} = Math, tempFour = [ 0, 0, 0, 0 ];
232
+ const {max: max$2} = Math, tempFour = [ 0, 0, 0, 0 ];
286
233
 
287
234
  const FourNumberHelper = {
288
235
  zero: [ ...tempFour ],
@@ -334,9 +281,9 @@ const FourNumberHelper = {
334
281
  return data;
335
282
  },
336
283
  max(t, other, change) {
337
- if (isNumber(t) && isNumber(other)) return max$1(t, other);
284
+ if (isNumber(t) && isNumber(other)) return max$2(t, other);
338
285
  toTempAB(t, other, change);
339
- 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]));
286
+ 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]));
340
287
  },
341
288
  add(t, other, change) {
342
289
  if (isNumber(t) && isNumber(other)) return t + other;
@@ -353,7 +300,7 @@ const FourNumberHelper = {
353
300
 
354
301
  const {set: set$1, get: get$1, setTemp: setTemp, toTempAB: toTempAB} = FourNumberHelper;
355
302
 
356
- const {round: round$3, pow: pow$1, max: max, floor: floor$1, PI: PI$1} = Math;
303
+ const {round: round$3, pow: pow$1, max: max$1, floor: floor$2, PI: PI$1} = Math;
357
304
 
358
305
  const MathHelper = {
359
306
  within(value, min, max) {
@@ -407,7 +354,7 @@ const MathHelper = {
407
354
  }
408
355
  },
409
356
  getFloorScale(num, min = 1) {
410
- return max(floor$1(num), min) / num;
357
+ return max$1(floor$2(num), min) / num;
411
358
  },
412
359
  randInt: randInt,
413
360
  randColor(opacity) {
@@ -1252,7 +1199,7 @@ const {toOuterPoint: toOuterPoint$2} = MatrixHelper;
1252
1199
 
1253
1200
  const {float: float, fourNumber: fourNumber} = MathHelper;
1254
1201
 
1255
- const {floor: floor, ceil: ceil$1} = Math;
1202
+ const {floor: floor$1, ceil: ceil$1} = Math;
1256
1203
 
1257
1204
  let right, bottom, boundsRight, boundsBottom;
1258
1205
 
@@ -1409,8 +1356,8 @@ const BoundsHelper = {
1409
1356
  },
1410
1357
  ceil(t) {
1411
1358
  const {x: x, y: y} = t;
1412
- t.x = floor(t.x);
1413
- t.y = floor(t.y);
1359
+ t.x = floor$1(t.x);
1360
+ t.y = floor$1(t.y);
1414
1361
  t.width = x > t.x ? ceil$1(t.width + x - t.x) : ceil$1(t.width);
1415
1362
  t.height = y > t.y ? ceil$1(t.height + y - t.y) : ceil$1(t.height);
1416
1363
  },
@@ -1542,6 +1489,9 @@ const BoundsHelper = {
1542
1489
  isEmpty(t) {
1543
1490
  return t.x === 0 && t.y === 0 && t.width === 0 && t.height === 0;
1544
1491
  },
1492
+ hasSize(t) {
1493
+ return t.width && t.height;
1494
+ },
1545
1495
  reset(t) {
1546
1496
  B.set(t);
1547
1497
  }
@@ -1718,6 +1668,12 @@ class AutoBounds {
1718
1668
  }
1719
1669
  }
1720
1670
 
1671
+ const UnitConvertHelper = {
1672
+ number(value, percentRefer) {
1673
+ return isObject(value) ? value.type === "percent" ? value.value * percentRefer : value.value : value;
1674
+ }
1675
+ };
1676
+
1721
1677
  const StringNumberMap = {
1722
1678
  0: 1,
1723
1679
  1: 1,
@@ -1734,6 +1690,69 @@ const StringNumberMap = {
1734
1690
  E: 1
1735
1691
  };
1736
1692
 
1693
+ const {floor: floor, max: max} = Math;
1694
+
1695
+ const Platform = {
1696
+ toURL(text, fileType) {
1697
+ let url = encodeURIComponent(text);
1698
+ if (fileType === "text") url = "data:text/plain;charset=utf-8," + url; else if (fileType === "svg") url = "data:image/svg+xml," + url;
1699
+ return url;
1700
+ },
1701
+ image: {
1702
+ hitCanvasSize: 100,
1703
+ maxCacheSize: 2560 * 1600,
1704
+ maxPatternSize: 4096 * 2160,
1705
+ crossOrigin: "anonymous",
1706
+ isLarge(size, scaleX, scaleY, largeSize) {
1707
+ return size.width * size.height * (scaleX ? scaleX * scaleY : 1) > (largeSize || image.maxCacheSize);
1708
+ },
1709
+ isSuperLarge(size, scaleX, scaleY) {
1710
+ return image.isLarge(size, scaleX, scaleY, image.maxPatternSize);
1711
+ },
1712
+ getRealURL(url) {
1713
+ const {prefix: prefix, suffix: suffix} = image;
1714
+ if (suffix && !url.startsWith("data:") && !url.startsWith("blob:")) url += (url.includes("?") ? "&" : "?") + suffix;
1715
+ if (prefix && url[0] === "/") url = prefix + url;
1716
+ return url;
1717
+ },
1718
+ resize(view, width, height, xGap, yGap, clip, smooth, opacity, _filters, interlace) {
1719
+ const realWidth = max(floor(width + (xGap || 0)), 1), realHeight = max(floor(height + (yGap || 0)), 1);
1720
+ let interlaceX, interlaceY, interlaceOffset;
1721
+ if (interlace && (interlaceOffset = UnitConvertHelper.number(interlace.offset, interlace.type === "x" ? width : height))) interlace.type === "x" ? interlaceX = true : interlaceY = true;
1722
+ const canvas = Platform.origin.createCanvas(interlaceY ? realWidth * 2 : realWidth, interlaceX ? realHeight * 2 : realHeight);
1723
+ const ctx = canvas.getContext("2d");
1724
+ if (opacity) ctx.globalAlpha = opacity;
1725
+ ctx.imageSmoothingEnabled = smooth === false ? false : true;
1726
+ if (image.canUse(view)) {
1727
+ if (clip) {
1728
+ const scaleX = width / clip.width, scaleY = height / clip.height;
1729
+ ctx.setTransform(scaleX, 0, 0, scaleY, -clip.x * scaleX, -clip.y * scaleY);
1730
+ ctx.drawImage(view, 0, 0, view.width, view.height);
1731
+ } else ctx.drawImage(view, 0, 0, width, height);
1732
+ if (interlaceOffset) {
1733
+ ctx.drawImage(canvas, 0, 0, realWidth, realHeight, interlaceX ? interlaceOffset - realWidth : realWidth, interlaceX ? realHeight : interlaceOffset - realHeight, realWidth, realHeight);
1734
+ ctx.drawImage(canvas, 0, 0, realWidth, realHeight, interlaceX ? interlaceOffset : realWidth, interlaceX ? realHeight : interlaceOffset, realWidth, realHeight);
1735
+ }
1736
+ }
1737
+ return canvas;
1738
+ },
1739
+ canUse(view) {
1740
+ return view && view.width && !view.__closed;
1741
+ },
1742
+ setPatternTransform(pattern, transform, paint) {
1743
+ try {
1744
+ if (transform && pattern.setTransform) {
1745
+ pattern.setTransform(transform);
1746
+ transform = undefined;
1747
+ }
1748
+ } catch (_a) {}
1749
+ if (paint) DataHelper.stintSet(paint, "transform", transform);
1750
+ }
1751
+ }
1752
+ };
1753
+
1754
+ const {image: image} = Platform;
1755
+
1737
1756
  const {randColor: randColor} = MathHelper;
1738
1757
 
1739
1758
  class Debug {
@@ -3289,10 +3308,10 @@ const PathCommandDataHelper = {
3289
3308
  data.push(O$2, x, y, radius, startAngle, endAngle, anticlockwise ? 1 : 0);
3290
3309
  }
3291
3310
  },
3292
- arcTo(data, x1, y1, x2, y2, radius, lastX, lastY) {
3311
+ arcTo(data, x1, y1, x2, y2, radius, lastX, lastY, fullRadius) {
3293
3312
  if (!isUndefined(lastX)) {
3294
- const d = getMinDistanceFrom(lastX, lastY, x1, y1, x2, y2);
3295
- radius = min(radius, min(d / 2, d / 2 * abs(tan(getRadianFrom(lastX, lastY, x1, y1, x2, y2) / 2))));
3313
+ const r = getMinDistanceFrom(lastX, lastY, x1, y1, x2, y2) / (fullRadius ? 1 : 2);
3314
+ radius = min(radius, min(r, r * abs(tan(getRadianFrom(lastX, lastY, x1, y1, x2, y2) / 2))));
3296
3315
  }
3297
3316
  data.push(U$2, x1, y1, x2, y2, radius);
3298
3317
  },
@@ -3636,7 +3655,7 @@ const PathCorner = {
3636
3655
  let command, lastCommand, commandLen;
3637
3656
  let i = 0, x = 0, y = 0, startX = 0, startY = 0, secondX = 0, secondY = 0, lastX = 0, lastY = 0;
3638
3657
  if (isArray(cornerRadius)) cornerRadius = cornerRadius[0] || 0;
3639
- const len = data.length;
3658
+ const len = data.length, three = len === 9;
3640
3659
  const smooth = [];
3641
3660
  while (i < len) {
3642
3661
  command = data[i];
@@ -3648,7 +3667,7 @@ const PathCorner = {
3648
3667
  if (data[i] === L$1) {
3649
3668
  secondX = data[i + 1];
3650
3669
  secondY = data[i + 2];
3651
- smooth.push(M, getCenterX(startX, secondX), getCenterY(startY, secondY));
3670
+ three ? smooth.push(M, startX, startY) : smooth.push(M, getCenterX(startX, secondX), getCenterY(startY, secondY));
3652
3671
  } else {
3653
3672
  smooth.push(M, startX, startY);
3654
3673
  }
@@ -3660,11 +3679,11 @@ const PathCorner = {
3660
3679
  i += 3;
3661
3680
  switch (data[i]) {
3662
3681
  case L$1:
3663
- arcTo(smooth, x, y, data[i + 1], data[i + 2], cornerRadius, lastX, lastY);
3682
+ arcTo(smooth, x, y, data[i + 1], data[i + 2], cornerRadius, lastX, lastY, three);
3664
3683
  break;
3665
3684
 
3666
3685
  case Z:
3667
- arcTo(smooth, x, y, startX, startY, cornerRadius, lastX, lastY);
3686
+ arcTo(smooth, x, y, startX, startY, cornerRadius, lastX, lastY, three);
3668
3687
  break;
3669
3688
 
3670
3689
  default:
@@ -3676,7 +3695,7 @@ const PathCorner = {
3676
3695
 
3677
3696
  case Z:
3678
3697
  if (lastCommand !== Z) {
3679
- arcTo(smooth, startX, startY, secondX, secondY, cornerRadius, lastX, lastY);
3698
+ arcTo(smooth, startX, startY, secondX, secondY, cornerRadius, lastX, lastY, three);
3680
3699
  smooth.push(Z);
3681
3700
  }
3682
3701
  i += 1;
@@ -3776,9 +3795,10 @@ class TaskItem {
3776
3795
  run() {
3777
3796
  return __awaiter(this, void 0, void 0, function*() {
3778
3797
  try {
3779
- if (this.isComplete) return;
3798
+ if (this.isComplete || this.runing) return;
3799
+ this.runing = true;
3780
3800
  if (this.canUse && !this.canUse()) return this.cancel();
3781
- if (this.task && this.parent.running) yield this.task();
3801
+ if (this.task) yield this.task();
3782
3802
  } catch (error) {
3783
3803
  debug$4.error(error);
3784
3804
  }
@@ -3894,7 +3914,7 @@ class TaskProcessor {
3894
3914
  stop() {
3895
3915
  this.isComplete = true;
3896
3916
  this.list.forEach(task => {
3897
- if (!task.isComplete) task.cancel();
3917
+ if (!task.isComplete) task.run();
3898
3918
  });
3899
3919
  this.pause();
3900
3920
  this.empty();
@@ -4184,7 +4204,7 @@ class LeaferImage {
4184
4204
  getFull(_filters) {
4185
4205
  return this.view;
4186
4206
  }
4187
- getCanvas(width, height, opacity, filters, xGap, yGap, smooth) {
4207
+ getCanvas(width, height, opacity, filters, xGap, yGap, smooth, interlace) {
4188
4208
  width || (width = this.width);
4189
4209
  height || (height = this.height);
4190
4210
  if (this.cache) {
@@ -4197,7 +4217,7 @@ class LeaferImage {
4197
4217
  }
4198
4218
  if (data) return data;
4199
4219
  }
4200
- const canvas = Platform.image.resize(this.view, width, height, xGap, yGap, undefined, smooth, opacity, filters);
4220
+ const canvas = Platform.image.resize(this.view, width, height, xGap, yGap, undefined, smooth, opacity, filters, interlace);
4201
4221
  this.cache = this.use > 1 ? {
4202
4222
  data: canvas,
4203
4223
  params: arguments
@@ -6089,7 +6109,7 @@ const LeafRender = {
6089
6109
  }
6090
6110
  };
6091
6111
 
6092
- const {excludeRenderBounds: excludeRenderBounds} = LeafBoundsHelper;
6112
+ const {excludeRenderBounds: excludeRenderBounds} = LeafBoundsHelper, {hasSize: hasSize} = BoundsHelper;
6093
6113
 
6094
6114
  const BranchRender = {
6095
6115
  __updateChange() {
@@ -6101,8 +6121,8 @@ const BranchRender = {
6101
6121
  this.__.__checkSingle();
6102
6122
  },
6103
6123
  __render(canvas, options) {
6104
- this.__nowWorld = this.__getNowWorld(options);
6105
- if (this.__worldOpacity) {
6124
+ const nowWorld = this.__nowWorld = this.__getNowWorld(options);
6125
+ if (this.__worldOpacity && hasSize(nowWorld)) {
6106
6126
  const data = this.__;
6107
6127
  if (data.__useDim) {
6108
6128
  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);
@@ -6111,7 +6131,6 @@ const BranchRender = {
6111
6131
  if (data.eraser === "path") return this.__renderEraser(canvas, options);
6112
6132
  const tempCanvas = canvas.getSameCanvas(false, true);
6113
6133
  this.__renderBranch(tempCanvas, options);
6114
- const nowWorld = this.__nowWorld;
6115
6134
  canvas.opacity = options.dimOpacity ? data.opacity * options.dimOpacity : data.opacity;
6116
6135
  canvas.copyWorldByReset(tempCanvas, nowWorld, nowWorld, data.__blendMode, true);
6117
6136
  tempCanvas.recycle(nowWorld);
@@ -6951,6 +6970,6 @@ class LeafLevelList {
6951
6970
  }
6952
6971
  }
6953
6972
 
6954
- const version = "1.12.4";
6973
+ const version = "2.0.1";
6955
6974
 
6956
- export { AlignHelper, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsEvent, BoundsHelper, Branch, BranchHelper, BranchRender, CanvasManager, ChildEvent, Creator, DataHelper, Debug, Direction4, Direction9, EllipseHelper, Event, EventCreator, Eventer, FileHelper, FourNumberHelper, ImageEvent, ImageManager, IncrementId, LayoutEvent, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, LeaferCanvasBase, LeaferEvent, LeaferImage, MathHelper, Matrix, MatrixHelper, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, PathBounds, PathCommandDataHelper, PathCommandMap, PathCommandNodeHelper, PathConvert, PathCorner, PathCreator, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Platform, Plugin, Point, PointHelper, PropertyEvent, RectHelper, RenderEvent, ResizeEvent, Resource, Run, StringNumberMap, TaskItem, TaskProcessor, TwoPointBoundsHelper, UICreator, WaitHelper, WatchEvent, affectRenderBoundsType, affectStrokeBoundsType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, createDescriptor, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, dimType, doBoundsType, doStrokeType, emptyData, eraserType, extraPropertyEventMap, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, isArray, isData, isEmptyData, isFinite, isNull, isNumber, isObject, isString, isUndefined, layoutProcessor, leaferTransformAttrMap, maskType, naturalBoundsType, opacityType, path, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, scrollType, sortType, strokeType, surfaceType, tempBounds, tempMatrix, tempPoint$2 as tempPoint, tryToNumber, useModule, version, visibleType };
6975
+ export { AlignHelper, Answer, AroundHelper, AutoBounds, BezierHelper, Bounds, BoundsEvent, BoundsHelper, Branch, BranchHelper, BranchRender, CanvasManager, ChildEvent, Creator, DataHelper, Debug, Direction4, Direction9, EllipseHelper, Event, EventCreator, Eventer, FileHelper, FourNumberHelper, ImageEvent, ImageManager, IncrementId, LayoutEvent, Leaf, LeafBounds, LeafBoundsHelper, LeafData, LeafDataProxy, LeafEventer, LeafHelper, LeafLayout, LeafLevelList, LeafList, LeafMatrix, LeafRender, LeaferCanvasBase, LeaferEvent, LeaferImage, MathHelper, Matrix, MatrixHelper, NeedConvertToCanvasCommandMap, OneRadian, PI2, PI_2, PathBounds, PathCommandDataHelper, PathCommandMap, PathCommandNodeHelper, PathConvert, PathCorner, PathCreator, PathDrawer, PathHelper, PathNumberCommandLengthMap, PathNumberCommandMap, Platform, Plugin, Point, PointHelper, PropertyEvent, RectHelper, RenderEvent, ResizeEvent, Resource, Run, StringNumberMap, TaskItem, TaskProcessor, TwoPointBoundsHelper, UICreator, UnitConvertHelper, WaitHelper, WatchEvent, affectRenderBoundsType, affectStrokeBoundsType, attr, autoLayoutType, boundsType, canvasPatch, canvasSizeAttrs, createDescriptor, cursorType, dataProcessor, dataType, decorateLeafAttr, defineDataProcessor, defineKey, defineLeafAttr, dimType, doBoundsType, doStrokeType, emptyData, eraserType, extraPropertyEventMap, getBoundsData, getDescriptor, getMatrixData, getPointData, hitType, isArray, isData, isEmptyData, isFinite, isNull, isNumber, isObject, isString, isUndefined, layoutProcessor, leaferTransformAttrMap, maskType, naturalBoundsType, opacityType, path, pathInputType, pathType, pen, positionType, registerUI, registerUIEvent, rewrite, rewriteAble, rotationType, scaleType, scrollType, sortType, strokeType, surfaceType, tempBounds, tempMatrix, tempPoint$2 as tempPoint, tryToNumber, useModule, version, visibleType };