@number-flow/react 0.1.1 → 0.1.3
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/README.md +1 -1
- package/dist/framer-motion.d.mts +5 -3
- package/dist/framer-motion.d.ts +5 -3
- package/dist/framer-motion.js +72 -14
- package/dist/framer-motion.mjs +59 -19
- package/dist/index.d.mts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +17 -2
- package/dist/index.mjs +16 -2
- package/package.json +4 -4
package/README.md
CHANGED
package/dist/framer-motion.d.mts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { Transition } from 'framer-motion';
|
|
1
|
+
import { Easing, Transition } from 'framer-motion';
|
|
2
2
|
|
|
3
|
-
declare
|
|
3
|
+
declare function toEase(_easing: string): Easing;
|
|
4
|
+
declare function toTransition(timing: EffectTiming): Transition;
|
|
5
|
+
declare function useTiming(timing: EffectTiming): Transition;
|
|
4
6
|
|
|
5
|
-
export {
|
|
7
|
+
export { toEase, toTransition, useTiming };
|
package/dist/framer-motion.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { Transition } from 'framer-motion';
|
|
1
|
+
import { Easing, Transition } from 'framer-motion';
|
|
2
2
|
|
|
3
|
-
declare
|
|
3
|
+
declare function toEase(_easing: string): Easing;
|
|
4
|
+
declare function toTransition(timing: EffectTiming): Transition;
|
|
5
|
+
declare function useTiming(timing: EffectTiming): Transition;
|
|
4
6
|
|
|
5
|
-
export {
|
|
7
|
+
export { toEase, toTransition, useTiming };
|
package/dist/framer-motion.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,28 +17,84 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/framer-motion.ts
|
|
21
31
|
var framer_motion_exports = {};
|
|
22
32
|
__export(framer_motion_exports, {
|
|
23
|
-
|
|
33
|
+
toEase: () => toEase,
|
|
34
|
+
toTransition: () => toTransition,
|
|
35
|
+
useTiming: () => useTiming
|
|
24
36
|
});
|
|
25
37
|
module.exports = __toCommonJS(framer_motion_exports);
|
|
26
|
-
var
|
|
38
|
+
var React = __toESM(require("react"));
|
|
27
39
|
var import_framer_motion = require("framer-motion");
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
ease
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
var bezierRegExp = /^cubic-bezier\((.*?),(.*?),(.*?),(.*?)\)$/;
|
|
41
|
+
var linearRegExp = /^linear\((.*?)\)$/;
|
|
42
|
+
function toEase(_easing) {
|
|
43
|
+
const easing = _easing.trim();
|
|
44
|
+
if (easing === "linear") return easing;
|
|
45
|
+
if (easing === "ease-in") return "easeIn";
|
|
46
|
+
if (easing === "ease-out") return "easeOut";
|
|
47
|
+
if (easing === "ease-in-out") return "easeInOut";
|
|
48
|
+
const bezierMatch = easing.match(bezierRegExp);
|
|
49
|
+
if (bezierMatch) {
|
|
50
|
+
return bezierMatch.slice(1).map(parseFloat);
|
|
51
|
+
}
|
|
52
|
+
const linearMatch = easing.match(linearRegExp);
|
|
53
|
+
const linearExpr = linearMatch?.[1];
|
|
54
|
+
if (linearExpr) {
|
|
55
|
+
const points = linearExpr.split(",");
|
|
56
|
+
const times = [];
|
|
57
|
+
const values = [];
|
|
58
|
+
try {
|
|
59
|
+
points.forEach((point, i) => {
|
|
60
|
+
const [p1, p2] = point.trim().split(/\s+/);
|
|
61
|
+
if (p1?.includes("%")) {
|
|
62
|
+
times.push(parseFloat(p1) / 100);
|
|
63
|
+
values.push(parseFloat(p2));
|
|
64
|
+
} else if (p2?.includes("%")) {
|
|
65
|
+
times.push(parseFloat(p2) / 100);
|
|
66
|
+
values.push(parseFloat(p1));
|
|
67
|
+
} else {
|
|
68
|
+
times.push(i / (points.length - 1));
|
|
69
|
+
values.push(parseFloat(p1));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
} catch {
|
|
73
|
+
throw new Error(`Cannot parse linear() expression: ${easing}`);
|
|
74
|
+
}
|
|
75
|
+
return (0, import_framer_motion.transform)(times, values);
|
|
76
|
+
}
|
|
77
|
+
throw new Error(`Cannot convert ${easing} to a Framer Motion easing`);
|
|
78
|
+
}
|
|
79
|
+
function toTransition(timing) {
|
|
80
|
+
const { duration = 0, delay = 0, easing = "ease" } = timing;
|
|
81
|
+
if (typeof duration != "number") throw new Error("Duration must be a number");
|
|
82
|
+
return {
|
|
83
|
+
duration: duration / 1e3,
|
|
84
|
+
delay: delay / 1e3,
|
|
85
|
+
ease: toEase(easing)
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function useTiming(timing) {
|
|
89
|
+
const [ret, setRet] = React.useState(toTransition(timing));
|
|
90
|
+
React.useEffect(() => {
|
|
91
|
+
setRet(toTransition(timing));
|
|
92
|
+
}, [timing]);
|
|
93
|
+
return ret;
|
|
94
|
+
}
|
|
39
95
|
// Annotate the CommonJS export names for ESM import in node:
|
|
40
96
|
0 && (module.exports = {
|
|
41
|
-
|
|
97
|
+
toEase,
|
|
98
|
+
toTransition,
|
|
99
|
+
useTiming
|
|
42
100
|
});
|
package/dist/framer-motion.mjs
CHANGED
|
@@ -1,23 +1,63 @@
|
|
|
1
1
|
// src/framer-motion.ts
|
|
2
|
-
import
|
|
3
|
-
supportsLinear,
|
|
4
|
-
defaultXTimingFallbackPoints,
|
|
5
|
-
defaultXTimingFallbackDuration,
|
|
6
|
-
defaultXTimingLinearDuration,
|
|
7
|
-
defaultXTimingLinearPoints
|
|
8
|
-
} from "number-flow";
|
|
2
|
+
import * as React from "react";
|
|
9
3
|
import { transform } from "framer-motion";
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
ease
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
4
|
+
var bezierRegExp = /^cubic-bezier\((.*?),(.*?),(.*?),(.*?)\)$/;
|
|
5
|
+
var linearRegExp = /^linear\((.*?)\)$/;
|
|
6
|
+
function toEase(_easing) {
|
|
7
|
+
const easing = _easing.trim();
|
|
8
|
+
if (easing === "linear") return easing;
|
|
9
|
+
if (easing === "ease-in") return "easeIn";
|
|
10
|
+
if (easing === "ease-out") return "easeOut";
|
|
11
|
+
if (easing === "ease-in-out") return "easeInOut";
|
|
12
|
+
const bezierMatch = easing.match(bezierRegExp);
|
|
13
|
+
if (bezierMatch) {
|
|
14
|
+
return bezierMatch.slice(1).map(parseFloat);
|
|
15
|
+
}
|
|
16
|
+
const linearMatch = easing.match(linearRegExp);
|
|
17
|
+
const linearExpr = linearMatch?.[1];
|
|
18
|
+
if (linearExpr) {
|
|
19
|
+
const points = linearExpr.split(",");
|
|
20
|
+
const times = [];
|
|
21
|
+
const values = [];
|
|
22
|
+
try {
|
|
23
|
+
points.forEach((point, i) => {
|
|
24
|
+
const [p1, p2] = point.trim().split(/\s+/);
|
|
25
|
+
if (p1?.includes("%")) {
|
|
26
|
+
times.push(parseFloat(p1) / 100);
|
|
27
|
+
values.push(parseFloat(p2));
|
|
28
|
+
} else if (p2?.includes("%")) {
|
|
29
|
+
times.push(parseFloat(p2) / 100);
|
|
30
|
+
values.push(parseFloat(p1));
|
|
31
|
+
} else {
|
|
32
|
+
times.push(i / (points.length - 1));
|
|
33
|
+
values.push(parseFloat(p1));
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
} catch {
|
|
37
|
+
throw new Error(`Cannot parse linear() expression: ${easing}`);
|
|
38
|
+
}
|
|
39
|
+
return transform(times, values);
|
|
40
|
+
}
|
|
41
|
+
throw new Error(`Cannot convert ${easing} to a Framer Motion easing`);
|
|
42
|
+
}
|
|
43
|
+
function toTransition(timing) {
|
|
44
|
+
const { duration = 0, delay = 0, easing = "ease" } = timing;
|
|
45
|
+
if (typeof duration != "number") throw new Error("Duration must be a number");
|
|
46
|
+
return {
|
|
47
|
+
duration: duration / 1e3,
|
|
48
|
+
delay: delay / 1e3,
|
|
49
|
+
ease: toEase(easing)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function useTiming(timing) {
|
|
53
|
+
const [ret, setRet] = React.useState(toTransition(timing));
|
|
54
|
+
React.useEffect(() => {
|
|
55
|
+
setRet(toTransition(timing));
|
|
56
|
+
}, [timing]);
|
|
57
|
+
return ret;
|
|
58
|
+
}
|
|
21
59
|
export {
|
|
22
|
-
|
|
60
|
+
toEase,
|
|
61
|
+
toTransition,
|
|
62
|
+
useTiming
|
|
23
63
|
};
|
package/dist/index.d.mts
CHANGED
|
@@ -28,4 +28,12 @@ declare const NumberFlow: React.ForwardRefExoticComponent<React.HTMLAttributes<N
|
|
|
28
28
|
yTiming?: (typeof NumberFlowElement)["prototype"]["yTiming"];
|
|
29
29
|
} & React.RefAttributes<NumberFlowElement>>;
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
declare function useSupportsLinear(): boolean;
|
|
32
|
+
type LinearEasing = `linear(${string})`;
|
|
33
|
+
type LinearTiming = EffectTiming & {
|
|
34
|
+
easing: LinearEasing;
|
|
35
|
+
};
|
|
36
|
+
declare function useLinear(linear: LinearEasing, fallback: string): string;
|
|
37
|
+
declare function useLinear(linear: LinearTiming, fallback: EffectTiming): EffectTiming;
|
|
38
|
+
|
|
39
|
+
export { NumberFlowElement, type NumberFlowProps, NumberFlow as default, useLinear, useSupportsLinear };
|
package/dist/index.d.ts
CHANGED
|
@@ -28,4 +28,12 @@ declare const NumberFlow: React.ForwardRefExoticComponent<React.HTMLAttributes<N
|
|
|
28
28
|
yTiming?: (typeof NumberFlowElement)["prototype"]["yTiming"];
|
|
29
29
|
} & React.RefAttributes<NumberFlowElement>>;
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
declare function useSupportsLinear(): boolean;
|
|
32
|
+
type LinearEasing = `linear(${string})`;
|
|
33
|
+
type LinearTiming = EffectTiming & {
|
|
34
|
+
easing: LinearEasing;
|
|
35
|
+
};
|
|
36
|
+
declare function useLinear(linear: LinearEasing, fallback: string): string;
|
|
37
|
+
declare function useLinear(linear: LinearTiming, fallback: EffectTiming): EffectTiming;
|
|
38
|
+
|
|
39
|
+
export { NumberFlowElement, type NumberFlowProps, NumberFlow as default, useLinear, useSupportsLinear };
|
package/dist/index.js
CHANGED
|
@@ -34,7 +34,9 @@ __export(src_exports, {
|
|
|
34
34
|
NumberFlowElement: () => NumberFlowElement,
|
|
35
35
|
default: () => src_default,
|
|
36
36
|
defaultXTiming: () => import_number_flow2.defaultXTiming,
|
|
37
|
-
defaultYTiming: () => import_number_flow2.defaultYTiming
|
|
37
|
+
defaultYTiming: () => import_number_flow2.defaultYTiming,
|
|
38
|
+
useLinear: () => useLinear,
|
|
39
|
+
useSupportsLinear: () => useSupportsLinear
|
|
38
40
|
});
|
|
39
41
|
module.exports = __toCommonJS(src_exports);
|
|
40
42
|
var React = __toESM(require("react"));
|
|
@@ -122,9 +124,22 @@ var NumberFlow = React.forwardRef(function NumberFlow2({ value, locales, format,
|
|
|
122
124
|
return /* @__PURE__ */ React.createElement(NumberFlowPriv, { ...props, parts, innerRef: ref });
|
|
123
125
|
});
|
|
124
126
|
var src_default = NumberFlow;
|
|
127
|
+
function useSupportsLinear() {
|
|
128
|
+
const [supported, setSupported] = React.useState(false);
|
|
129
|
+
React.useEffect(() => {
|
|
130
|
+
setSupported(import_number_flow.supportsLinear);
|
|
131
|
+
}, []);
|
|
132
|
+
return supported;
|
|
133
|
+
}
|
|
134
|
+
function useLinear(linear, fallback) {
|
|
135
|
+
const supported = useSupportsLinear();
|
|
136
|
+
return supported ? linear : fallback;
|
|
137
|
+
}
|
|
125
138
|
// Annotate the CommonJS export names for ESM import in node:
|
|
126
139
|
0 && (module.exports = {
|
|
127
140
|
NumberFlowElement,
|
|
128
141
|
defaultXTiming,
|
|
129
|
-
defaultYTiming
|
|
142
|
+
defaultYTiming,
|
|
143
|
+
useLinear,
|
|
144
|
+
useSupportsLinear
|
|
130
145
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
SlottedTag,
|
|
7
7
|
slottedStyles,
|
|
8
8
|
partitionParts,
|
|
9
|
-
NumberFlowLite
|
|
9
|
+
NumberFlowLite,
|
|
10
|
+
supportsLinear
|
|
10
11
|
} from "number-flow";
|
|
11
12
|
import { defaultXTiming, defaultYTiming } from "number-flow";
|
|
12
13
|
var OBSERVED_ATTRIBUTES = ["parts"];
|
|
@@ -91,9 +92,22 @@ var NumberFlow = React.forwardRef(function NumberFlow2({ value, locales, format,
|
|
|
91
92
|
return /* @__PURE__ */ React.createElement(NumberFlowPriv, { ...props, parts, innerRef: ref });
|
|
92
93
|
});
|
|
93
94
|
var src_default = NumberFlow;
|
|
95
|
+
function useSupportsLinear() {
|
|
96
|
+
const [supported, setSupported] = React.useState(false);
|
|
97
|
+
React.useEffect(() => {
|
|
98
|
+
setSupported(supportsLinear);
|
|
99
|
+
}, []);
|
|
100
|
+
return supported;
|
|
101
|
+
}
|
|
102
|
+
function useLinear(linear, fallback) {
|
|
103
|
+
const supported = useSupportsLinear();
|
|
104
|
+
return supported ? linear : fallback;
|
|
105
|
+
}
|
|
94
106
|
export {
|
|
95
107
|
NumberFlowElement,
|
|
96
108
|
src_default as default,
|
|
97
109
|
defaultXTiming,
|
|
98
|
-
defaultYTiming
|
|
110
|
+
defaultYTiming,
|
|
111
|
+
useLinear,
|
|
112
|
+
useSupportsLinear
|
|
99
113
|
};
|
package/package.json
CHANGED
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.3",
|
|
7
7
|
"author": {
|
|
8
8
|
"name": "Maxwell Barvian",
|
|
9
9
|
"email": "max@barvian.me",
|
|
10
10
|
"url": "https://barvian.me"
|
|
11
11
|
},
|
|
12
|
-
"description": "A
|
|
12
|
+
"description": "A component to transition and format numbers.",
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"homepage": "https://number-flow.barvian.me
|
|
14
|
+
"homepage": "https://number-flow.barvian.me",
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
17
17
|
"url": "https://github.com/barvian/number-flow",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"esm-env": "^1.0.0",
|
|
62
|
-
"number-flow": "0.2.
|
|
62
|
+
"number-flow": "0.2.3"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@types/react": "^18.3.3",
|