@leafer/core 1.5.0 → 1.5.2

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
@@ -118,8 +118,9 @@ const MathHelper = {
118
118
  if (!scaleData)
119
119
  scaleData = {};
120
120
  if (size) {
121
- scaleData.scaleX = (typeof size === 'number' ? size : size.width) / originSize.width;
122
- scaleData.scaleY = (typeof size === 'number' ? size : size.height) / originSize.height;
121
+ const scaleX = (typeof size === 'number' ? size : size.width || 0) / originSize.width, scaleY = (typeof size === 'number' ? size : size.height || 0) / originSize.height;
122
+ scaleData.scaleX = scaleX || scaleY || 1;
123
+ scaleData.scaleY = scaleY || scaleX || 1;
123
124
  }
124
125
  else if (scale)
125
126
  MathHelper.assignScale(scaleData, scale);
@@ -1692,6 +1693,9 @@ const emptyData = {};
1692
1693
  function isNull(value) {
1693
1694
  return value === undefined || value === null;
1694
1695
  }
1696
+ function isEmptyData(value) {
1697
+ return JSON.stringify(value) === '{}';
1698
+ }
1695
1699
 
1696
1700
  /******************************************************************************
1697
1701
  Copyright (c) Microsoft Corporation.
@@ -2031,13 +2035,11 @@ class LeaferCanvasBase extends Canvas {
2031
2035
  this.worldTransform = {};
2032
2036
  if (!config)
2033
2037
  config = minSize;
2034
- if (!config.pixelRatio)
2035
- config.pixelRatio = Platform.devicePixelRatio;
2036
2038
  this.manager = manager;
2037
2039
  this.innerId = IncrementId.create(IncrementId.CNAVAS);
2038
2040
  const { width, height, pixelRatio } = config;
2039
2041
  this.autoLayout = !width || !height;
2040
- this.size.pixelRatio = pixelRatio;
2042
+ this.size.pixelRatio = pixelRatio | Platform.devicePixelRatio;
2041
2043
  this.config = config;
2042
2044
  this.init();
2043
2045
  }
@@ -2234,7 +2236,7 @@ class LeaferCanvasBase extends Canvas {
2234
2236
  tempBounds.ceil();
2235
2237
  }
2236
2238
  isSameSize(size) {
2237
- return this.width === size.width && this.height === size.height && this.pixelRatio === size.pixelRatio;
2239
+ return this.width === size.width && this.height === size.height && (!size.pixelRatio || this.pixelRatio === size.pixelRatio);
2238
2240
  }
2239
2241
  getSameCanvas(useSameWorldTransform, useSameSmooth) {
2240
2242
  const canvas = this.manager ? this.manager.get(this.size) : Creator.canvas(Object.assign({}, this.size));
@@ -2349,7 +2351,7 @@ const RectHelper = {
2349
2351
  const { sin: sin$1, cos: cos$1, atan2: atan2$1, ceil, abs: abs$1, PI, sqrt: sqrt$1, pow } = Math;
2350
2352
  const { setPoint: setPoint$1, addPoint: addPoint$1 } = TwoPointBoundsHelper;
2351
2353
  const { set, toNumberPoints } = PointHelper;
2352
- const { M: M$5, L: L$6, C: C$5, Q: Q$4, Z: Z$5 } = PathCommandMap;
2354
+ const { M: M$5, L: L$6, C: C$4, Q: Q$4, Z: Z$5 } = PathCommandMap;
2353
2355
  const tempPoint$1 = {};
2354
2356
  const BezierHelper = {
2355
2357
  points(data, originPoints, curve, close) {
@@ -2384,7 +2386,7 @@ const BezierHelper = {
2384
2386
  data.push(Q$4, c1X, c1Y, bX, bY);
2385
2387
  }
2386
2388
  else {
2387
- data.push(C$5, c2X, c2Y, c1X, c1Y, bX, bY);
2389
+ data.push(C$4, c2X, c2Y, c1X, c1Y, bX, bY);
2388
2390
  }
2389
2391
  c2X = bX + cb * cX;
2390
2392
  c2Y = bY + cb * cY;
@@ -2489,7 +2491,7 @@ const BezierHelper = {
2489
2491
  x2 = cx + x + control * (rotationCos * radiusX * endSin + rotationSin * radiusY * endCos);
2490
2492
  y2 = cy + y + control * (rotationSin * radiusX * endSin - rotationCos * radiusY * endCos);
2491
2493
  if (data)
2492
- data.push(C$5, x1, y1, x2, y2, cx + x, cy + y);
2494
+ data.push(C$4, x1, y1, x2, y2, cx + x, cy + y);
2493
2495
  if (setPointBounds)
2494
2496
  toTwoPointBounds$1(cx + startX, cy + startY, x1, y1, x2, y2, cx + x, cy + y, setPointBounds, true);
2495
2497
  startX = x;
@@ -2503,7 +2505,7 @@ const BezierHelper = {
2503
2505
  set(setEndPoint, cx + x, cy + y);
2504
2506
  },
2505
2507
  quadraticCurveTo(data, fromX, fromY, x1, y1, toX, toY) {
2506
- data.push(C$5, (fromX + 2 * x1) / 3, (fromY + 2 * y1) / 3, (toX + 2 * x1) / 3, (toY + 2 * y1) / 3, toX, toY);
2508
+ data.push(C$4, (fromX + 2 * x1) / 3, (fromY + 2 * y1) / 3, (toX + 2 * x1) / 3, (toY + 2 * y1) / 3, toX, toY);
2507
2509
  },
2508
2510
  toTwoPointBoundsByQuadraticCurve(fromX, fromY, x1, y1, toX, toY, pointBounds, addMode) {
2509
2511
  toTwoPointBounds$1(fromX, fromY, (fromX + 2 * x1) / 3, (fromY + 2 * y1) / 3, (toX + 2 * x1) / 3, (toY + 2 * y1) / 3, toX, toY, pointBounds, addMode);
@@ -2611,7 +2613,7 @@ const EllipseHelper = {
2611
2613
  }
2612
2614
  };
2613
2615
 
2614
- const { M: M$4, m, L: L$5, l, H, h, V, v, C: C$4, c, S, s, Q: Q$3, q, T, t, A, a, Z: Z$4, z, N: N$3, D: D$3, X: X$3, G: G$3, F: F$4, O: O$3, P: P$3, U: U$3 } = PathCommandMap;
2616
+ const { M: M$4, m, L: L$5, l, H, h, V, v, C: C$3, c, S, s, Q: Q$3, q, T, t, A, a, Z: Z$4, z, N: N$3, D: D$3, X: X$3, G: G$3, F: F$4, O: O$3, P: P$3, U: U$3 } = PathCommandMap;
2615
2617
  const { rect: rect$1, roundRect: roundRect$2, arcTo: arcTo$3, arc: arc$3, ellipse: ellipse$3, quadraticCurveTo: quadraticCurveTo$1 } = BezierHelper;
2616
2618
  const { ellipticalArc } = EllipseHelper;
2617
2619
  const debug$7 = Debug.get('PathConvert');
@@ -2739,14 +2741,14 @@ const PathConvert = {
2739
2741
  old[i + 4] += y;
2740
2742
  command = S;
2741
2743
  case S:
2742
- smooth = (lastCommand === C$4) || (lastCommand === S);
2744
+ smooth = (lastCommand === C$3) || (lastCommand === S);
2743
2745
  x1 = smooth ? (x * 2 - controlX) : old[i + 1];
2744
2746
  y1 = smooth ? (y * 2 - controlY) : old[i + 2];
2745
2747
  controlX = old[i + 1];
2746
2748
  controlY = old[i + 2];
2747
2749
  x = old[i + 3];
2748
2750
  y = old[i + 4];
2749
- data.push(C$4, x1, y1, controlX, controlY, x, y);
2751
+ data.push(C$3, x1, y1, controlX, controlY, x, y);
2750
2752
  i += 5;
2751
2753
  break;
2752
2754
  case c:
@@ -2756,13 +2758,13 @@ const PathConvert = {
2756
2758
  old[i + 4] += y;
2757
2759
  old[i + 5] += x;
2758
2760
  old[i + 6] += y;
2759
- command = C$4;
2760
- case C$4:
2761
+ command = C$3;
2762
+ case C$3:
2761
2763
  controlX = old[i + 3];
2762
2764
  controlY = old[i + 4];
2763
2765
  x = old[i + 5];
2764
2766
  y = old[i + 6];
2765
- data.push(C$4, old[i + 1], old[i + 2], controlX, controlY, x, y);
2767
+ data.push(C$3, old[i + 1], old[i + 2], controlX, controlY, x, y);
2766
2768
  i += 7;
2767
2769
  break;
2768
2770
  case t:
@@ -2873,7 +2875,7 @@ const PathConvert = {
2873
2875
  data.push(L$5, item.x, item.y);
2874
2876
  break;
2875
2877
  case 'C':
2876
- data.push(C$4, item.x1, item.y1, item.x2, item.y2, item.x, item.y);
2878
+ data.push(C$3, item.x1, item.y1, item.x2, item.y2, item.x, item.y);
2877
2879
  break;
2878
2880
  case 'Q':
2879
2881
  data.push(Q$3, item.x1, item.y1, item.x, item.y);
@@ -2900,7 +2902,7 @@ const PathConvert = {
2900
2902
  };
2901
2903
  const { current, pushData, copyData } = PathConvert;
2902
2904
 
2903
- const { M: M$3, L: L$4, C: C$3, Q: Q$2, Z: Z$3, N: N$2, D: D$2, X: X$2, G: G$2, F: F$3, O: O$2, P: P$2, U: U$2 } = PathCommandMap;
2905
+ const { M: M$3, L: L$4, C: C$2, Q: Q$2, Z: Z$3, N: N$2, D: D$2, X: X$2, G: G$2, F: F$3, O: O$2, P: P$2, U: U$2 } = PathCommandMap;
2904
2906
  const { getMinDistanceFrom, getRadianFrom } = PointHelper;
2905
2907
  const { tan, min, abs } = Math;
2906
2908
  const startPoint = {};
@@ -2915,7 +2917,7 @@ const PathCommandDataHelper = {
2915
2917
  data.push(L$4, x, y);
2916
2918
  },
2917
2919
  bezierCurveTo(data, x1, y1, x2, y2, x, y) {
2918
- data.push(C$3, x1, y1, x2, y2, x, y);
2920
+ data.push(C$2, x1, y1, x2, y2, x, y);
2919
2921
  },
2920
2922
  quadraticCurveTo(data, x1, y1, x, y) {
2921
2923
  data.push(Q$2, x1, y1, x, y);
@@ -3077,7 +3079,7 @@ class PathCreator {
3077
3079
  paint() { }
3078
3080
  }
3079
3081
 
3080
- const { M: M$2, L: L$3, C: C$2, Q: Q$1, Z: Z$2, N: N$1, D: D$1, X: X$1, G: G$1, F: F$2, O: O$1, P: P$1, U: U$1 } = PathCommandMap;
3082
+ const { M: M$2, L: L$3, C: C$1, Q: Q$1, Z: Z$2, N: N$1, D: D$1, X: X$1, G: G$1, F: F$2, O: O$1, P: P$1, U: U$1 } = PathCommandMap;
3081
3083
  const debug$6 = Debug.get('PathDrawer');
3082
3084
  const PathDrawer = {
3083
3085
  drawPathByData(drawer, data) {
@@ -3096,7 +3098,7 @@ const PathDrawer = {
3096
3098
  drawer.lineTo(data[i + 1], data[i + 2]);
3097
3099
  i += 3;
3098
3100
  break;
3099
- case C$2:
3101
+ case C$1:
3100
3102
  drawer.bezierCurveTo(data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5], data[i + 6]);
3101
3103
  i += 7;
3102
3104
  break;
@@ -3148,7 +3150,7 @@ const PathDrawer = {
3148
3150
  }
3149
3151
  };
3150
3152
 
3151
- const { M: M$1, L: L$2, C: C$1, Q, Z: Z$1, N, D, X, G, F: F$1, O, P, U } = PathCommandMap;
3153
+ const { M: M$1, L: L$2, C, Q, Z: Z$1, N, D, X, G, F: F$1, O, P, U } = PathCommandMap;
3152
3154
  const { toTwoPointBounds, toTwoPointBoundsByQuadraticCurve, arcTo: arcTo$1, arc, ellipse } = BezierHelper;
3153
3155
  const { addPointBounds, copy: copy$4, addPoint, setPoint, addBounds, toBounds: toBounds$1 } = TwoPointBoundsHelper;
3154
3156
  const debug$5 = Debug.get('PathBounds');
@@ -3169,7 +3171,7 @@ const PathBounds = {
3169
3171
  while (i < len) {
3170
3172
  command = data[i];
3171
3173
  if (i === 0) {
3172
- if (command === Z$1 || command === C$1 || command === Q) {
3174
+ if (command === Z$1 || command === C || command === Q) {
3173
3175
  setPoint(setPointBounds, x, y);
3174
3176
  }
3175
3177
  else {
@@ -3184,7 +3186,7 @@ const PathBounds = {
3184
3186
  addPoint(setPointBounds, x, y);
3185
3187
  i += 3;
3186
3188
  break;
3187
- case C$1:
3189
+ case C:
3188
3190
  toX = data[i + 5];
3189
3191
  toY = data[i + 6];
3190
3192
  toTwoPointBounds(x, y, data[i + 1], data[i + 2], data[i + 3], data[i + 4], toX, toY, tempPointBounds);
@@ -3266,12 +3268,12 @@ const PathBounds = {
3266
3268
  }
3267
3269
  };
3268
3270
 
3269
- const { M, L: L$1, C, Z } = PathCommandMap;
3271
+ const { M, L: L$1, Z } = PathCommandMap;
3270
3272
  const { getCenterX, getCenterY } = PointHelper;
3271
3273
  const { arcTo } = PathCommandDataHelper;
3272
3274
  const PathCorner = {
3273
3275
  smooth(data, cornerRadius, _cornerSmoothing) {
3274
- let command;
3276
+ let command, commandLen;
3275
3277
  let i = 0, x = 0, y = 0, startX = 0, startY = 0, secondX = 0, secondY = 0, lastX = 0, lastY = 0;
3276
3278
  const len = data.length;
3277
3279
  const smooth = [];
@@ -3308,15 +3310,16 @@ const PathCorner = {
3308
3310
  lastX = x;
3309
3311
  lastY = y;
3310
3312
  break;
3311
- case C:
3312
- smooth.push(C, data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5], data[i + 6]);
3313
- i += 7;
3314
- break;
3315
3313
  case Z:
3316
3314
  arcTo(smooth, startX, startY, secondX, secondY, cornerRadius, lastX, lastY);
3317
3315
  smooth.push(Z);
3318
3316
  i += 1;
3319
3317
  break;
3318
+ default:
3319
+ commandLen = PathNumberCommandLengthMap[command];
3320
+ for (let j = 0; j < commandLen; j++)
3321
+ smooth.push(data[i + j]);
3322
+ i += commandLen;
3320
3323
  }
3321
3324
  }
3322
3325
  if (command !== Z) {
@@ -4075,33 +4078,45 @@ function defineDataProcessor(target, key, defaultValue) {
4075
4078
  else if (typeof defaultValue === 'function') {
4076
4079
  property.get = function () {
4077
4080
  let v = this[computedKey];
4078
- if (v === undefined)
4079
- this[computedKey] = v = defaultValue(this.__leaf);
4080
- return v;
4081
+ return v === undefined ? defaultValue(this.__leaf) : v;
4082
+ };
4083
+ }
4084
+ else if (typeof defaultValue === 'object') {
4085
+ const isEmpty = isEmptyData(defaultValue);
4086
+ property.get = function () {
4087
+ let v = this[computedKey];
4088
+ return v === undefined ? this[computedKey] = isEmpty ? {} : DataHelper.clone(defaultValue) : v;
4081
4089
  };
4082
4090
  }
4091
+ const isBox = target.isBranchLeaf;
4083
4092
  if (key === 'width') {
4084
4093
  property.get = function () {
4085
4094
  const v = this[computedKey];
4086
4095
  if (v === undefined) {
4087
- const t = this;
4088
- return t._height && t.__naturalWidth && t.__useNaturalRatio ? t._height * t.__naturalWidth / t.__naturalHeight : t.__naturalWidth || defaultValue;
4096
+ const t = this, naturalWidth = t.__naturalWidth, leaf = t.__leaf;
4097
+ if (!defaultValue || leaf.pathInputed)
4098
+ return leaf.boxBounds.width;
4099
+ if (naturalWidth)
4100
+ return t._height && t.__useNaturalRatio ? t._height * naturalWidth / t.__naturalHeight : naturalWidth;
4101
+ return (isBox && leaf.children.length) ? leaf.boxBounds.width : defaultValue;
4089
4102
  }
4090
- else {
4103
+ else
4091
4104
  return v;
4092
- }
4093
4105
  };
4094
4106
  }
4095
4107
  else if (key === 'height') {
4096
4108
  property.get = function () {
4097
4109
  const v = this[computedKey];
4098
4110
  if (v === undefined) {
4099
- const t = this;
4100
- return t._width && t.__naturalHeight && t.__useNaturalRatio ? t._width * t.__naturalHeight / t.__naturalWidth : t.__naturalHeight || defaultValue;
4111
+ const t = this, naturalHeight = t.__naturalHeight, leaf = t.__leaf;
4112
+ if (!defaultValue || leaf.pathInputed)
4113
+ return leaf.boxBounds.height;
4114
+ if (naturalHeight)
4115
+ return t._width && t.__useNaturalRatio ? t._width * naturalHeight / t.__naturalWidth : naturalHeight;
4116
+ return (isBox && leaf.children.length) ? leaf.boxBounds.height : defaultValue;
4101
4117
  }
4102
- else {
4118
+ else
4103
4119
  return v;
4104
- }
4105
4120
  };
4106
4121
  }
4107
4122
  let descriptor, find = data;
@@ -4528,7 +4543,12 @@ class LeafLayout {
4528
4543
  while (root.parent && !root.parent.leafer) {
4529
4544
  root = root.parent;
4530
4545
  }
4531
- Platform.layout(root);
4546
+ const r = root;
4547
+ if (r.__fullLayouting)
4548
+ return;
4549
+ r.__fullLayouting = true;
4550
+ Platform.layout(r);
4551
+ delete r.__fullLayouting;
4532
4552
  }
4533
4553
  }
4534
4554
  getTransform(relative = 'world') {
@@ -6053,7 +6073,7 @@ class LeafLevelList {
6053
6073
  }
6054
6074
  }
6055
6075
 
6056
- const version = "1.5.0";
6076
+ const version = "1.5.2";
6057
6077
 
6058
6078
  exports.AlignHelper = AlignHelper;
6059
6079
  exports.AroundHelper = AroundHelper;
@@ -6148,6 +6168,7 @@ exports.getDescriptor = getDescriptor;
6148
6168
  exports.getMatrixData = getMatrixData;
6149
6169
  exports.getPointData = getPointData;
6150
6170
  exports.hitType = hitType;
6171
+ exports.isEmptyData = isEmptyData;
6151
6172
  exports.isNull = isNull;
6152
6173
  exports.layoutProcessor = layoutProcessor;
6153
6174
  exports.maskType = maskType;