physics-animator 0.14.0 → 0.15.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/README.md CHANGED
@@ -24,7 +24,7 @@ useSpringValue(
24
24
  Or via state
25
25
 
26
26
  ```tsx
27
- const opacity = useSpringState({ initial: 0, target: 1, duration_s: 0.8 })
27
+ const { state: opacity, setTarget } = useSpringState({ initial: 0, duration_s: 0.8 })
28
28
 
29
29
  return <div style={{ opacity }} />
30
30
  ```
@@ -11,6 +11,11 @@ const useSpringValue_js_1 = require("./useSpringValue.js");
11
11
  */
12
12
  function useSpringState(options) {
13
13
  const [state, setState] = (0, react_1.useState)(options.initial);
14
- (0, useSpringValue_js_1.useSpringValue)(options, setState);
15
- return state;
14
+ const [target, setTarget] = (0, react_1.useState)(options.initial);
15
+ (0, useSpringValue_js_1.useSpringValue)({
16
+ ...options,
17
+ initial: options.initial,
18
+ target
19
+ }, setState);
20
+ return { state, target, setTarget };
16
21
  }
@@ -8,6 +8,11 @@ import { useSpringValue } from "./useSpringValue.js";
8
8
  */
9
9
  export function useSpringState(options) {
10
10
  const [state, setState] = useState(options.initial);
11
- useSpringValue(options, setState);
12
- return state;
11
+ const [target, setTarget] = useState(options.initial);
12
+ useSpringValue({
13
+ ...options,
14
+ initial: options.initial,
15
+ target
16
+ }, setState);
17
+ return { state, target, setTarget };
13
18
  }
@@ -1,5 +1,6 @@
1
1
  import { Animator } from "../Animator.js";
2
2
  import { SpringParameters } from "../animators/SpringAnimator.js";
3
+ type WidenNumber<T> = T extends number ? number : T;
3
4
  /**
4
5
  * A value that animates to a target value using a spring animation.
5
6
  * This **will** cause a re-render when the value changes.
@@ -11,5 +12,9 @@ export declare function useSpringState<T extends number | number[] | {
11
12
  }>(options: {
12
13
  animator?: Animator;
13
14
  initial: T;
14
- target: T;
15
- } & SpringParameters): T;
15
+ } & SpringParameters): {
16
+ readonly state: WidenNumber<T>;
17
+ readonly target: WidenNumber<T>;
18
+ readonly setTarget: import("react").Dispatch<import("react").SetStateAction<WidenNumber<T>>>;
19
+ };
20
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "physics-animator",
3
- "version": "0.14.0",
3
+ "version": "0.15.1",
4
4
  "author": "haxiomic (George Corney)",
5
5
  "license": "MIT",
6
6
  "description": "A TypeScript animation system grounded in physics with three.js and react support.",