@leafer/core 1.5.1 → 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 +61 -36
- package/lib/core.cjs.map +1 -1
- package/lib/core.esm.js +61 -37
- package/lib/core.esm.js.map +1 -1
- package/lib/core.esm.min.js +1 -1
- package/lib/core.esm.min.js.map +1 -1
- package/lib/core.min.cjs +1 -1
- package/lib/core.min.cjs.map +1 -1
- package/package.json +17 -17
- package/src/index.ts +1 -1
- package/types/index.d.ts +1 -1
package/lib/core.cjs
CHANGED
|
@@ -118,8 +118,9 @@ const MathHelper = {
|
|
|
118
118
|
if (!scaleData)
|
|
119
119
|
scaleData = {};
|
|
120
120
|
if (size) {
|
|
121
|
-
|
|
122
|
-
scaleData.
|
|
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.
|
|
@@ -2347,7 +2351,7 @@ const RectHelper = {
|
|
|
2347
2351
|
const { sin: sin$1, cos: cos$1, atan2: atan2$1, ceil, abs: abs$1, PI, sqrt: sqrt$1, pow } = Math;
|
|
2348
2352
|
const { setPoint: setPoint$1, addPoint: addPoint$1 } = TwoPointBoundsHelper;
|
|
2349
2353
|
const { set, toNumberPoints } = PointHelper;
|
|
2350
|
-
const { M: M$5, L: L$6, C: C$
|
|
2354
|
+
const { M: M$5, L: L$6, C: C$4, Q: Q$4, Z: Z$5 } = PathCommandMap;
|
|
2351
2355
|
const tempPoint$1 = {};
|
|
2352
2356
|
const BezierHelper = {
|
|
2353
2357
|
points(data, originPoints, curve, close) {
|
|
@@ -2382,7 +2386,7 @@ const BezierHelper = {
|
|
|
2382
2386
|
data.push(Q$4, c1X, c1Y, bX, bY);
|
|
2383
2387
|
}
|
|
2384
2388
|
else {
|
|
2385
|
-
data.push(C$
|
|
2389
|
+
data.push(C$4, c2X, c2Y, c1X, c1Y, bX, bY);
|
|
2386
2390
|
}
|
|
2387
2391
|
c2X = bX + cb * cX;
|
|
2388
2392
|
c2Y = bY + cb * cY;
|
|
@@ -2487,7 +2491,7 @@ const BezierHelper = {
|
|
|
2487
2491
|
x2 = cx + x + control * (rotationCos * radiusX * endSin + rotationSin * radiusY * endCos);
|
|
2488
2492
|
y2 = cy + y + control * (rotationSin * radiusX * endSin - rotationCos * radiusY * endCos);
|
|
2489
2493
|
if (data)
|
|
2490
|
-
data.push(C$
|
|
2494
|
+
data.push(C$4, x1, y1, x2, y2, cx + x, cy + y);
|
|
2491
2495
|
if (setPointBounds)
|
|
2492
2496
|
toTwoPointBounds$1(cx + startX, cy + startY, x1, y1, x2, y2, cx + x, cy + y, setPointBounds, true);
|
|
2493
2497
|
startX = x;
|
|
@@ -2501,7 +2505,7 @@ const BezierHelper = {
|
|
|
2501
2505
|
set(setEndPoint, cx + x, cy + y);
|
|
2502
2506
|
},
|
|
2503
2507
|
quadraticCurveTo(data, fromX, fromY, x1, y1, toX, toY) {
|
|
2504
|
-
data.push(C$
|
|
2508
|
+
data.push(C$4, (fromX + 2 * x1) / 3, (fromY + 2 * y1) / 3, (toX + 2 * x1) / 3, (toY + 2 * y1) / 3, toX, toY);
|
|
2505
2509
|
},
|
|
2506
2510
|
toTwoPointBoundsByQuadraticCurve(fromX, fromY, x1, y1, toX, toY, pointBounds, addMode) {
|
|
2507
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);
|
|
@@ -2609,7 +2613,7 @@ const EllipseHelper = {
|
|
|
2609
2613
|
}
|
|
2610
2614
|
};
|
|
2611
2615
|
|
|
2612
|
-
const { M: M$4, m, L: L$5, l, H, h, V, v, C: C$
|
|
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;
|
|
2613
2617
|
const { rect: rect$1, roundRect: roundRect$2, arcTo: arcTo$3, arc: arc$3, ellipse: ellipse$3, quadraticCurveTo: quadraticCurveTo$1 } = BezierHelper;
|
|
2614
2618
|
const { ellipticalArc } = EllipseHelper;
|
|
2615
2619
|
const debug$7 = Debug.get('PathConvert');
|
|
@@ -2737,14 +2741,14 @@ const PathConvert = {
|
|
|
2737
2741
|
old[i + 4] += y;
|
|
2738
2742
|
command = S;
|
|
2739
2743
|
case S:
|
|
2740
|
-
smooth = (lastCommand === C$
|
|
2744
|
+
smooth = (lastCommand === C$3) || (lastCommand === S);
|
|
2741
2745
|
x1 = smooth ? (x * 2 - controlX) : old[i + 1];
|
|
2742
2746
|
y1 = smooth ? (y * 2 - controlY) : old[i + 2];
|
|
2743
2747
|
controlX = old[i + 1];
|
|
2744
2748
|
controlY = old[i + 2];
|
|
2745
2749
|
x = old[i + 3];
|
|
2746
2750
|
y = old[i + 4];
|
|
2747
|
-
data.push(C$
|
|
2751
|
+
data.push(C$3, x1, y1, controlX, controlY, x, y);
|
|
2748
2752
|
i += 5;
|
|
2749
2753
|
break;
|
|
2750
2754
|
case c:
|
|
@@ -2754,13 +2758,13 @@ const PathConvert = {
|
|
|
2754
2758
|
old[i + 4] += y;
|
|
2755
2759
|
old[i + 5] += x;
|
|
2756
2760
|
old[i + 6] += y;
|
|
2757
|
-
command = C$
|
|
2758
|
-
case C$
|
|
2761
|
+
command = C$3;
|
|
2762
|
+
case C$3:
|
|
2759
2763
|
controlX = old[i + 3];
|
|
2760
2764
|
controlY = old[i + 4];
|
|
2761
2765
|
x = old[i + 5];
|
|
2762
2766
|
y = old[i + 6];
|
|
2763
|
-
data.push(C$
|
|
2767
|
+
data.push(C$3, old[i + 1], old[i + 2], controlX, controlY, x, y);
|
|
2764
2768
|
i += 7;
|
|
2765
2769
|
break;
|
|
2766
2770
|
case t:
|
|
@@ -2871,7 +2875,7 @@ const PathConvert = {
|
|
|
2871
2875
|
data.push(L$5, item.x, item.y);
|
|
2872
2876
|
break;
|
|
2873
2877
|
case 'C':
|
|
2874
|
-
data.push(C$
|
|
2878
|
+
data.push(C$3, item.x1, item.y1, item.x2, item.y2, item.x, item.y);
|
|
2875
2879
|
break;
|
|
2876
2880
|
case 'Q':
|
|
2877
2881
|
data.push(Q$3, item.x1, item.y1, item.x, item.y);
|
|
@@ -2898,7 +2902,7 @@ const PathConvert = {
|
|
|
2898
2902
|
};
|
|
2899
2903
|
const { current, pushData, copyData } = PathConvert;
|
|
2900
2904
|
|
|
2901
|
-
const { M: M$3, L: L$4, C: C$
|
|
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;
|
|
2902
2906
|
const { getMinDistanceFrom, getRadianFrom } = PointHelper;
|
|
2903
2907
|
const { tan, min, abs } = Math;
|
|
2904
2908
|
const startPoint = {};
|
|
@@ -2913,7 +2917,7 @@ const PathCommandDataHelper = {
|
|
|
2913
2917
|
data.push(L$4, x, y);
|
|
2914
2918
|
},
|
|
2915
2919
|
bezierCurveTo(data, x1, y1, x2, y2, x, y) {
|
|
2916
|
-
data.push(C$
|
|
2920
|
+
data.push(C$2, x1, y1, x2, y2, x, y);
|
|
2917
2921
|
},
|
|
2918
2922
|
quadraticCurveTo(data, x1, y1, x, y) {
|
|
2919
2923
|
data.push(Q$2, x1, y1, x, y);
|
|
@@ -3075,7 +3079,7 @@ class PathCreator {
|
|
|
3075
3079
|
paint() { }
|
|
3076
3080
|
}
|
|
3077
3081
|
|
|
3078
|
-
const { M: M$2, L: L$3, C: C$
|
|
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;
|
|
3079
3083
|
const debug$6 = Debug.get('PathDrawer');
|
|
3080
3084
|
const PathDrawer = {
|
|
3081
3085
|
drawPathByData(drawer, data) {
|
|
@@ -3094,7 +3098,7 @@ const PathDrawer = {
|
|
|
3094
3098
|
drawer.lineTo(data[i + 1], data[i + 2]);
|
|
3095
3099
|
i += 3;
|
|
3096
3100
|
break;
|
|
3097
|
-
case C$
|
|
3101
|
+
case C$1:
|
|
3098
3102
|
drawer.bezierCurveTo(data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5], data[i + 6]);
|
|
3099
3103
|
i += 7;
|
|
3100
3104
|
break;
|
|
@@ -3146,7 +3150,7 @@ const PathDrawer = {
|
|
|
3146
3150
|
}
|
|
3147
3151
|
};
|
|
3148
3152
|
|
|
3149
|
-
const { M: M$1, L: L$2, C
|
|
3153
|
+
const { M: M$1, L: L$2, C, Q, Z: Z$1, N, D, X, G, F: F$1, O, P, U } = PathCommandMap;
|
|
3150
3154
|
const { toTwoPointBounds, toTwoPointBoundsByQuadraticCurve, arcTo: arcTo$1, arc, ellipse } = BezierHelper;
|
|
3151
3155
|
const { addPointBounds, copy: copy$4, addPoint, setPoint, addBounds, toBounds: toBounds$1 } = TwoPointBoundsHelper;
|
|
3152
3156
|
const debug$5 = Debug.get('PathBounds');
|
|
@@ -3167,7 +3171,7 @@ const PathBounds = {
|
|
|
3167
3171
|
while (i < len) {
|
|
3168
3172
|
command = data[i];
|
|
3169
3173
|
if (i === 0) {
|
|
3170
|
-
if (command === Z$1 || command === C
|
|
3174
|
+
if (command === Z$1 || command === C || command === Q) {
|
|
3171
3175
|
setPoint(setPointBounds, x, y);
|
|
3172
3176
|
}
|
|
3173
3177
|
else {
|
|
@@ -3182,7 +3186,7 @@ const PathBounds = {
|
|
|
3182
3186
|
addPoint(setPointBounds, x, y);
|
|
3183
3187
|
i += 3;
|
|
3184
3188
|
break;
|
|
3185
|
-
case C
|
|
3189
|
+
case C:
|
|
3186
3190
|
toX = data[i + 5];
|
|
3187
3191
|
toY = data[i + 6];
|
|
3188
3192
|
toTwoPointBounds(x, y, data[i + 1], data[i + 2], data[i + 3], data[i + 4], toX, toY, tempPointBounds);
|
|
@@ -3264,12 +3268,12 @@ const PathBounds = {
|
|
|
3264
3268
|
}
|
|
3265
3269
|
};
|
|
3266
3270
|
|
|
3267
|
-
const { M, L: L$1,
|
|
3271
|
+
const { M, L: L$1, Z } = PathCommandMap;
|
|
3268
3272
|
const { getCenterX, getCenterY } = PointHelper;
|
|
3269
3273
|
const { arcTo } = PathCommandDataHelper;
|
|
3270
3274
|
const PathCorner = {
|
|
3271
3275
|
smooth(data, cornerRadius, _cornerSmoothing) {
|
|
3272
|
-
let command;
|
|
3276
|
+
let command, commandLen;
|
|
3273
3277
|
let i = 0, x = 0, y = 0, startX = 0, startY = 0, secondX = 0, secondY = 0, lastX = 0, lastY = 0;
|
|
3274
3278
|
const len = data.length;
|
|
3275
3279
|
const smooth = [];
|
|
@@ -3306,15 +3310,16 @@ const PathCorner = {
|
|
|
3306
3310
|
lastX = x;
|
|
3307
3311
|
lastY = y;
|
|
3308
3312
|
break;
|
|
3309
|
-
case C:
|
|
3310
|
-
smooth.push(C, data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5], data[i + 6]);
|
|
3311
|
-
i += 7;
|
|
3312
|
-
break;
|
|
3313
3313
|
case Z:
|
|
3314
3314
|
arcTo(smooth, startX, startY, secondX, secondY, cornerRadius, lastX, lastY);
|
|
3315
3315
|
smooth.push(Z);
|
|
3316
3316
|
i += 1;
|
|
3317
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;
|
|
3318
3323
|
}
|
|
3319
3324
|
}
|
|
3320
3325
|
if (command !== Z) {
|
|
@@ -4076,28 +4081,42 @@ function defineDataProcessor(target, key, defaultValue) {
|
|
|
4076
4081
|
return v === undefined ? defaultValue(this.__leaf) : v;
|
|
4077
4082
|
};
|
|
4078
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;
|
|
4089
|
+
};
|
|
4090
|
+
}
|
|
4091
|
+
const isBox = target.isBranchLeaf;
|
|
4079
4092
|
if (key === 'width') {
|
|
4080
4093
|
property.get = function () {
|
|
4081
4094
|
const v = this[computedKey];
|
|
4082
4095
|
if (v === undefined) {
|
|
4083
|
-
const t = this;
|
|
4084
|
-
|
|
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;
|
|
4085
4102
|
}
|
|
4086
|
-
else
|
|
4103
|
+
else
|
|
4087
4104
|
return v;
|
|
4088
|
-
}
|
|
4089
4105
|
};
|
|
4090
4106
|
}
|
|
4091
4107
|
else if (key === 'height') {
|
|
4092
4108
|
property.get = function () {
|
|
4093
4109
|
const v = this[computedKey];
|
|
4094
4110
|
if (v === undefined) {
|
|
4095
|
-
const t = this;
|
|
4096
|
-
|
|
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;
|
|
4097
4117
|
}
|
|
4098
|
-
else
|
|
4118
|
+
else
|
|
4099
4119
|
return v;
|
|
4100
|
-
}
|
|
4101
4120
|
};
|
|
4102
4121
|
}
|
|
4103
4122
|
let descriptor, find = data;
|
|
@@ -4524,7 +4543,12 @@ class LeafLayout {
|
|
|
4524
4543
|
while (root.parent && !root.parent.leafer) {
|
|
4525
4544
|
root = root.parent;
|
|
4526
4545
|
}
|
|
4527
|
-
|
|
4546
|
+
const r = root;
|
|
4547
|
+
if (r.__fullLayouting)
|
|
4548
|
+
return;
|
|
4549
|
+
r.__fullLayouting = true;
|
|
4550
|
+
Platform.layout(r);
|
|
4551
|
+
delete r.__fullLayouting;
|
|
4528
4552
|
}
|
|
4529
4553
|
}
|
|
4530
4554
|
getTransform(relative = 'world') {
|
|
@@ -6049,7 +6073,7 @@ class LeafLevelList {
|
|
|
6049
6073
|
}
|
|
6050
6074
|
}
|
|
6051
6075
|
|
|
6052
|
-
const version = "1.5.
|
|
6076
|
+
const version = "1.5.2";
|
|
6053
6077
|
|
|
6054
6078
|
exports.AlignHelper = AlignHelper;
|
|
6055
6079
|
exports.AroundHelper = AroundHelper;
|
|
@@ -6144,6 +6168,7 @@ exports.getDescriptor = getDescriptor;
|
|
|
6144
6168
|
exports.getMatrixData = getMatrixData;
|
|
6145
6169
|
exports.getPointData = getPointData;
|
|
6146
6170
|
exports.hitType = hitType;
|
|
6171
|
+
exports.isEmptyData = isEmptyData;
|
|
6147
6172
|
exports.isNull = isNull;
|
|
6148
6173
|
exports.layoutProcessor = layoutProcessor;
|
|
6149
6174
|
exports.maskType = maskType;
|