@tamagui/cubic-bezier-animator 1.114.4 → 1.115.0
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.
|
@@ -3,15 +3,21 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
15
21
|
var cubicBezier_exports = {};
|
|
16
22
|
__export(cubicBezier_exports, {
|
|
17
23
|
bezier: () => bezier
|
|
@@ -34,17 +40,16 @@ function getSlope(aT, aA1, aA2) {
|
|
|
34
40
|
return 3 * A(aA1, aA2) * aT * aT + 2 * B(aA1, aA2) * aT + C(aA1);
|
|
35
41
|
}
|
|
36
42
|
function binarySubdivide(aX, aA, aB, mX1, mX2) {
|
|
37
|
-
let currentX,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
while (Math.abs(currentX) > 1e-7 && ++i < 10);
|
|
43
|
+
let currentX,
|
|
44
|
+
currentT,
|
|
45
|
+
i = 0;
|
|
46
|
+
do currentT = aA + (aB - aA) / 2, currentX = calcBezier(currentT, mX1, mX2) - aX, currentX > 0 ? aB = currentT : aA = currentT; while (Math.abs(currentX) > 1e-7 && ++i < 10);
|
|
41
47
|
return currentT;
|
|
42
48
|
}
|
|
43
49
|
function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
|
|
44
50
|
for (let i = 0; i < 4; ++i) {
|
|
45
51
|
const currentSlope = getSlope(aGuessT, mX1, mX2);
|
|
46
|
-
if (currentSlope === 0)
|
|
47
|
-
return aGuessT;
|
|
52
|
+
if (currentSlope === 0) return aGuessT;
|
|
48
53
|
const currentX = calcBezier(aGuessT, mX1, mX2) - aX;
|
|
49
54
|
aGuessT -= currentX / currentSlope;
|
|
50
55
|
}
|
|
@@ -54,24 +59,22 @@ function LinearEasing(x) {
|
|
|
54
59
|
return x;
|
|
55
60
|
}
|
|
56
61
|
function bezier(mX1, mY1, mX2, mY2) {
|
|
57
|
-
if (!(0 <= mX1 && mX1 <= 1 && 0 <= mX2 && mX2 <= 1))
|
|
58
|
-
|
|
59
|
-
if (mX1 === mY1 && mX2 === mY2)
|
|
60
|
-
return LinearEasing;
|
|
62
|
+
if (!(0 <= mX1 && mX1 <= 1 && 0 <= mX2 && mX2 <= 1)) throw new Error("bezier x values must be in [0, 1] range");
|
|
63
|
+
if (mX1 === mY1 && mX2 === mY2) return LinearEasing;
|
|
61
64
|
const sampleValues = float32ArraySupported ? new Float32Array(11) : new Array(11);
|
|
62
|
-
for (let i = 0; i < 11; ++i)
|
|
63
|
-
sampleValues[i] = calcBezier(i * 0.1, mX1, mX2);
|
|
65
|
+
for (let i = 0; i < 11; ++i) sampleValues[i] = calcBezier(i * 0.1, mX1, mX2);
|
|
64
66
|
function getTForX(aX) {
|
|
65
|
-
let intervalStart = 0,
|
|
67
|
+
let intervalStart = 0,
|
|
68
|
+
currentSample = 1;
|
|
66
69
|
const lastSample = 10;
|
|
67
|
-
for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample)
|
|
68
|
-
intervalStart += 0.1;
|
|
70
|
+
for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) intervalStart += 0.1;
|
|
69
71
|
--currentSample;
|
|
70
|
-
const dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]),
|
|
72
|
+
const dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]),
|
|
73
|
+
guessForT = intervalStart + dist * 0.1,
|
|
74
|
+
initialSlope = getSlope(guessForT, mX1, mX2);
|
|
71
75
|
return initialSlope >= 1e-3 ? newtonRaphsonIterate(aX, guessForT, mX1, mX2) : initialSlope === 0 ? guessForT : binarySubdivide(aX, intervalStart, intervalStart + 0.1, mX1, mX2);
|
|
72
76
|
}
|
|
73
|
-
return function(x) {
|
|
77
|
+
return function (x) {
|
|
74
78
|
return x === 0 || x === 1 ? x : calcBezier(getTForX(x), mY1, mY2);
|
|
75
79
|
};
|
|
76
|
-
}
|
|
77
|
-
//# sourceMappingURL=cubicBezier.js.map
|
|
80
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
animate: () => animate
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
var import_cubicBezier = require("./cubicBezier.cjs");
|
|
27
|
+
function animate(param) {
|
|
28
|
+
let start = null;
|
|
29
|
+
const easing = param.cubicBezier ? (0, import_cubicBezier.bezier)(...param.cubicBezier) : v => v,
|
|
30
|
+
{
|
|
31
|
+
x: fromX,
|
|
32
|
+
y: fromY,
|
|
33
|
+
scaleX: fromScaleX,
|
|
34
|
+
scaleY: fromScaleY
|
|
35
|
+
} = param.from,
|
|
36
|
+
{
|
|
37
|
+
x: toX,
|
|
38
|
+
y: toY,
|
|
39
|
+
scaleX: toScaleX,
|
|
40
|
+
scaleY: toScaleY
|
|
41
|
+
} = param.to;
|
|
42
|
+
function frame(timestamp) {
|
|
43
|
+
start || (start = timestamp);
|
|
44
|
+
const progress = timestamp - start,
|
|
45
|
+
x = toX !== void 0 ? fromX + (toX - fromX) * easing(progress / param.duration) : void 0,
|
|
46
|
+
y = toY !== void 0 ? fromY + (toY - fromY) * easing(progress / param.duration) : void 0,
|
|
47
|
+
scaleX = toScaleX !== void 0 ? fromScaleX + (toScaleX - fromScaleX) * easing(progress / param.duration) : void 0,
|
|
48
|
+
scaleY = toScaleY !== void 0 ? fromScaleY + (toScaleY - fromScaleY) * easing(progress / param.duration) : void 0;
|
|
49
|
+
param.onUpdate({
|
|
50
|
+
x,
|
|
51
|
+
y,
|
|
52
|
+
scaleX,
|
|
53
|
+
scaleY
|
|
54
|
+
}), progress < param.duration && requestAnimationFrame(frame);
|
|
55
|
+
}
|
|
56
|
+
requestAnimationFrame(frame);
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/cubic-bezier-animator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.115.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"source": "src/index.tsx",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"clean:build": "tamagui-build clean:build"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@tamagui/build": "1.
|
|
24
|
+
"@tamagui/build": "1.115.0"
|
|
25
25
|
},
|
|
26
26
|
"exports": {
|
|
27
27
|
"./package.json": "./package.json",
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
"react-native": "./dist/cjs/index.native.js",
|
|
31
31
|
"types": "./types/index.d.ts",
|
|
32
32
|
"import": "./dist/esm/index.mjs",
|
|
33
|
-
"require": "./dist/cjs/index.
|
|
33
|
+
"require": "./dist/cjs/index.cjs",
|
|
34
|
+
"default": "./dist/cjs/index.native.js"
|
|
34
35
|
}
|
|
35
36
|
},
|
|
36
37
|
"publishConfig": {
|
package/dist/cjs/index.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
-
for (let key of __getOwnPropNames(from))
|
|
11
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
-
var src_exports = {};
|
|
16
|
-
__export(src_exports, {
|
|
17
|
-
animate: () => animate
|
|
18
|
-
});
|
|
19
|
-
module.exports = __toCommonJS(src_exports);
|
|
20
|
-
var import_cubicBezier = require("./cubicBezier");
|
|
21
|
-
function animate(param) {
|
|
22
|
-
let start = null;
|
|
23
|
-
const easing = param.cubicBezier ? (0, import_cubicBezier.bezier)(...param.cubicBezier) : (v) => v, { x: fromX, y: fromY, scaleX: fromScaleX, scaleY: fromScaleY } = param.from, { x: toX, y: toY, scaleX: toScaleX, scaleY: toScaleY } = param.to;
|
|
24
|
-
function frame(timestamp) {
|
|
25
|
-
start || (start = timestamp);
|
|
26
|
-
const progress = timestamp - start, x = toX !== void 0 ? fromX + (toX - fromX) * easing(progress / param.duration) : void 0, y = toY !== void 0 ? fromY + (toY - fromY) * easing(progress / param.duration) : void 0, scaleX = toScaleX !== void 0 ? fromScaleX + (toScaleX - fromScaleX) * easing(progress / param.duration) : void 0, scaleY = toScaleY !== void 0 ? fromScaleY + (toScaleY - fromScaleY) * easing(progress / param.duration) : void 0;
|
|
27
|
-
param.onUpdate({ x, y, scaleX, scaleY }), progress < param.duration && requestAnimationFrame(frame);
|
|
28
|
-
}
|
|
29
|
-
requestAnimationFrame(frame);
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=index.js.map
|
|
File without changes
|
|
File without changes
|