@react-spring/core
Advanced tools
Comparing version 9.5.2 to 9.5.3
@@ -1,2 +0,2 @@ | ||
import { Remap } from '@react-spring/types'; | ||
import { Lookup, Remap } from '@react-spring/types'; | ||
import { ControllerUpdate, PickAnimated, SpringValues } from '../types'; | ||
@@ -8,3 +8,3 @@ import { Valid } from '../types/common'; | ||
*/ | ||
export declare type UseSpringProps<Props extends object = any> = unknown & PickAnimated<Props> extends infer State ? Remap<ControllerUpdate<State> & { | ||
export declare type UseSpringProps<Props extends object = any> = unknown & PickAnimated<Props> extends infer State extends Lookup<any> ? Remap<ControllerUpdate<State> & { | ||
/** | ||
@@ -21,3 +21,3 @@ * Used to access the imperative API. | ||
*/ | ||
export declare function useSpring<Props extends object>(props: Function | (() => (Props & Valid<Props, UseSpringProps<Props>>) | UseSpringProps), deps?: readonly any[] | undefined): PickAnimated<Props> extends infer State ? [SpringValues<State>, SpringRef<State>] : never; | ||
export declare function useSpring<Props extends object>(props: Function | (() => (Props & Valid<Props, UseSpringProps<Props>>) | UseSpringProps), deps?: readonly any[] | undefined): PickAnimated<Props> extends infer State extends Lookup<any> ? [SpringValues<State>, SpringRef<State>] : never; | ||
/** | ||
@@ -30,2 +30,2 @@ * Updated on every render, with state inferred from forward props. | ||
*/ | ||
export declare function useSpring<Props extends object>(props: (Props & Valid<Props, UseSpringProps<Props>>) | UseSpringProps, deps: readonly any[] | undefined): PickAnimated<Props> extends infer State ? [SpringValues<State>, SpringRef<State>] : never; | ||
export declare function useSpring<Props extends object>(props: (Props & Valid<Props, UseSpringProps<Props>>) | UseSpringProps, deps: readonly any[] | undefined): PickAnimated<Props> extends infer State extends Lookup<any> ? [SpringValues<State>, SpringRef<State>] : never; |
@@ -15,3 +15,3 @@ import { Lookup } from '@react-spring/types'; | ||
*/ | ||
export declare function useSprings<Props extends UseSpringProps>(length: number, props: (i: number, ctrl: Controller) => Props, deps?: readonly any[]): PickAnimated<Props> extends infer State ? [SpringValues<State>[], SpringRefType<State>] : never; | ||
export declare function useSprings<Props extends UseSpringProps>(length: number, props: (i: number, ctrl: Controller) => Props, deps?: readonly any[]): PickAnimated<Props> extends infer State extends Lookup<any> ? [SpringValues<State>[], SpringRefType<State>] : never; | ||
/** | ||
@@ -24,2 +24,2 @@ * Animations are updated on re-render. | ||
*/ | ||
export declare function useSprings<Props extends UseSpringsProps>(length: number, props: Props[] & UseSpringsProps<PickAnimated<Props>>[], deps: readonly any[] | undefined): PickAnimated<Props> extends infer State ? [SpringValues<State>[], SpringRefType<State>] : never; | ||
export declare function useSprings<Props extends UseSpringsProps>(length: number, props: Props[] & UseSpringsProps<PickAnimated<Props>>[], deps: readonly any[] | undefined): PickAnimated<Props> extends infer State extends Lookup<any> ? [SpringValues<State>[], SpringRefType<State>] : never; |
@@ -0,1 +1,2 @@ | ||
import { Lookup } from '@react-spring/types'; | ||
import { Valid } from '../types/common'; | ||
@@ -7,4 +8,4 @@ import { PickAnimated, SpringValues } from '../types'; | ||
export declare type UseTrailProps<Props extends object = any> = UseSpringProps<Props>; | ||
export declare function useTrail<Props extends object>(length: number, props: (i: number, ctrl: Controller) => UseTrailProps | (Props & Valid<Props, UseTrailProps<Props>>), deps?: readonly any[]): PickAnimated<Props> extends infer State ? [SpringValues<State>[], SpringRef<State>] : never; | ||
export declare function useTrail<Props extends object>(length: number, props: (i: number, ctrl: Controller) => UseTrailProps | (Props & Valid<Props, UseTrailProps<Props>>), deps?: readonly any[]): PickAnimated<Props> extends infer State extends Lookup<any> ? [SpringValues<State>[], SpringRef<State>] : never; | ||
export declare function useTrail<Props extends object>(length: number, props: UseTrailProps | (Props & Valid<Props, UseTrailProps<Props>>)): SpringValues<PickAnimated<Props>>[]; | ||
export declare function useTrail<Props extends object>(length: number, props: UseTrailProps | (Props & Valid<Props, UseTrailProps<Props>>), deps: readonly any[]): PickAnimated<Props> extends infer State ? [SpringValues<State>[], SpringRef<State>] : never; | ||
export declare function useTrail<Props extends object>(length: number, props: UseTrailProps | (Props & Valid<Props, UseTrailProps<Props>>), deps: readonly any[]): PickAnimated<Props> extends infer State extends Lookup<any> ? [SpringValues<State>[], SpringRef<State>] : never; |
@@ -1,7 +0,7 @@ | ||
import { OneOrMore } from '@react-spring/types'; | ||
import { Lookup, OneOrMore } from '@react-spring/types'; | ||
import { PickAnimated, TransitionFn, UseTransitionProps } from '../types'; | ||
import { Valid } from '../types/common'; | ||
import type { SpringRef as SpringRefType } from '../SpringRef'; | ||
export declare function useTransition<Item, Props extends object>(data: OneOrMore<Item>, props: () => UseTransitionProps<Item> | (Props & Valid<Props, UseTransitionProps<Item>>), deps?: any[]): PickAnimated<Props> extends infer State ? [TransitionFn<Item, PickAnimated<Props>>, SpringRefType<State>] : never; | ||
export declare function useTransition<Item, Props extends object>(data: OneOrMore<Item>, props: () => UseTransitionProps<Item> | (Props & Valid<Props, UseTransitionProps<Item>>), deps?: any[]): PickAnimated<Props> extends infer State extends Lookup ? [TransitionFn<Item, PickAnimated<Props>>, SpringRefType<State>] : never; | ||
export declare function useTransition<Item, Props extends object>(data: OneOrMore<Item>, props: UseTransitionProps<Item> | (Props & Valid<Props, UseTransitionProps<Item>>)): TransitionFn<Item, PickAnimated<Props>>; | ||
export declare function useTransition<Item, Props extends object>(data: OneOrMore<Item>, props: UseTransitionProps<Item> | (Props & Valid<Props, UseTransitionProps<Item>>), deps: any[] | undefined): PickAnimated<Props> extends infer State ? [TransitionFn<Item, State>, SpringRefType<State>] : never; | ||
export declare function useTransition<Item, Props extends object>(data: OneOrMore<Item>, props: UseTransitionProps<Item> | (Props & Valid<Props, UseTransitionProps<Item>>), deps: any[] | undefined): PickAnimated<Props> extends infer State extends Lookup ? [TransitionFn<Item, State>, SpringRefType<State>] : never; |
@@ -75,3 +75,3 @@ import { FluidProps, FluidValue } from '@react-spring/shared'; | ||
/** A set of values for a `Controller` to animate from/to. */ | ||
export declare type GoalValues<T extends Lookup> = FluidProps<T> extends infer Props ? { | ||
export declare type GoalValues<T> = FluidProps<T> extends infer Props ? { | ||
[P in keyof Props]?: Props[P] | null; | ||
@@ -78,0 +78,0 @@ } : never; |
@@ -1,2 +0,2 @@ | ||
import { eachProp, is, toArray, isAnimatedString, Globals, getFluidValue, useIsomorphicLayoutEffect, each, raf, flush, FluidValue, deprecateInterpolate, callFluidObservers, frameLoop, hasFluidValue, flushCalls, isEqual, getFluidObservers, addFluidObserver, removeFluidObserver, noop, useMemoOne, deprecateDirectCall, useForceUpdate, usePrev, useOnce, createInterpolator, createStringInterpolator } from '@react-spring/shared'; | ||
import { eachProp, is, toArray, getFluidValue, isAnimatedString, Globals, useIsomorphicLayoutEffect, each, raf, flush, FluidValue, deprecateInterpolate, callFluidObservers, frameLoop, hasFluidValue, flushCalls, isEqual, getFluidObservers, addFluidObserver, removeFluidObserver, noop, useMemoOne, deprecateDirectCall, useForceUpdate, usePrev, useOnce, createInterpolator, createStringInterpolator } from '@react-spring/shared'; | ||
export { Globals, createInterpolator, useIsomorphicLayoutEffect, useReducedMotion } from '@react-spring/shared'; | ||
@@ -10,3 +10,3 @@ import * as React from 'react'; | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
_extends = Object.assign ? Object.assign.bind() : function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
@@ -24,3 +24,2 @@ var source = arguments[i]; | ||
}; | ||
return _extends.apply(this, arguments); | ||
@@ -549,4 +548,4 @@ } | ||
} else { | ||
animating = Promise.resolve(to(animate, target.stop.bind(target))); | ||
} | ||
animating = Promise.resolve(to(animate, target.stop.bind(target))); | ||
} | ||
@@ -780,2 +779,3 @@ await Promise.all([animating.then(preventBail), bailPromise]); | ||
let velocity; | ||
const precision = config.precision || (from == to ? 0.005 : Math.min(1, Math.abs(to - from) * 0.001)); | ||
@@ -804,47 +804,46 @@ if (!is.und(config.duration)) { | ||
} else if (config.decay) { | ||
const decay = config.decay === true ? 0.998 : config.decay; | ||
const e = Math.exp(-(1 - decay) * elapsed); | ||
position = from + v0 / (1 - decay) * (1 - e); | ||
finished = Math.abs(node.lastPosition - position) < 0.1; | ||
velocity = v0 * e; | ||
} else { | ||
velocity = node.lastVelocity == null ? v0 : node.lastVelocity; | ||
const precision = config.precision || (from == to ? 0.005 : Math.min(1, Math.abs(to - from) * 0.001)); | ||
const restVelocity = config.restVelocity || precision / 10; | ||
const bounceFactor = config.clamp ? 0 : config.bounce; | ||
const canBounce = !is.und(bounceFactor); | ||
const isGrowing = from == to ? node.v0 > 0 : from < to; | ||
let isMoving; | ||
let isBouncing = false; | ||
const step = 1; | ||
const numSteps = Math.ceil(dt / step); | ||
const decay = config.decay === true ? 0.998 : config.decay; | ||
const e = Math.exp(-(1 - decay) * elapsed); | ||
position = from + v0 / (1 - decay) * (1 - e); | ||
finished = Math.abs(node.lastPosition - position) <= precision; | ||
velocity = v0 * e; | ||
} else { | ||
velocity = node.lastVelocity == null ? v0 : node.lastVelocity; | ||
const restVelocity = config.restVelocity || precision / 10; | ||
const bounceFactor = config.clamp ? 0 : config.bounce; | ||
const canBounce = !is.und(bounceFactor); | ||
const isGrowing = from == to ? node.v0 > 0 : from < to; | ||
let isMoving; | ||
let isBouncing = false; | ||
const step = 1; | ||
const numSteps = Math.ceil(dt / step); | ||
for (let n = 0; n < numSteps; ++n) { | ||
isMoving = Math.abs(velocity) > restVelocity; | ||
for (let n = 0; n < numSteps; ++n) { | ||
isMoving = Math.abs(velocity) > restVelocity; | ||
if (!isMoving) { | ||
finished = Math.abs(to - position) <= precision; | ||
if (!isMoving) { | ||
finished = Math.abs(to - position) <= precision; | ||
if (finished) { | ||
break; | ||
} | ||
} | ||
if (finished) { | ||
break; | ||
} | ||
} | ||
if (canBounce) { | ||
isBouncing = position == to || position > to == isGrowing; | ||
if (canBounce) { | ||
isBouncing = position == to || position > to == isGrowing; | ||
if (isBouncing) { | ||
velocity = -velocity * bounceFactor; | ||
position = to; | ||
} | ||
} | ||
const springForce = -config.tension * 0.000001 * (position - to); | ||
const dampingForce = -config.friction * 0.001 * velocity; | ||
const acceleration = (springForce + dampingForce) / config.mass; | ||
velocity = velocity + acceleration * step; | ||
position = position + velocity * step; | ||
if (isBouncing) { | ||
velocity = -velocity * bounceFactor; | ||
position = to; | ||
} | ||
} | ||
const springForce = -config.tension * 0.000001 * (position - to); | ||
const dampingForce = -config.friction * 0.001 * velocity; | ||
const acceleration = (springForce + dampingForce) / config.mass; | ||
velocity = velocity + acceleration * step; | ||
position = position + velocity * step; | ||
} | ||
} | ||
node.lastVelocity = velocity; | ||
@@ -1016,4 +1015,4 @@ | ||
} else if (!getAnimated(this)) { | ||
this._set(to); | ||
} | ||
this._set(to); | ||
} | ||
} | ||
@@ -1191,4 +1190,4 @@ | ||
} else if (!started) { | ||
this._stop(prevTo); | ||
} | ||
this._stop(prevTo); | ||
} | ||
} | ||
@@ -1227,4 +1226,4 @@ | ||
} else { | ||
anim.onStart == null ? void 0 : anim.onStart(result, this); | ||
} | ||
anim.onStart == null ? void 0 : anim.onStart(result, this); | ||
} | ||
}); | ||
@@ -1241,8 +1240,8 @@ } | ||
} else if (started) { | ||
this._start(); | ||
} else if (isAnimating(this) && !hasToChanged) { | ||
this._pendingCalls.add(resolve); | ||
} else { | ||
resolve(getNoopResult(value)); | ||
} | ||
this._start(); | ||
} else if (isAnimating(this) && !hasToChanged) { | ||
this._pendingCalls.add(resolve); | ||
} else { | ||
resolve(getNoopResult(value)); | ||
} | ||
} | ||
@@ -1677,32 +1676,32 @@ | ||
} else { | ||
each(BATCHED_EVENTS, key => { | ||
const handler = props[key]; | ||
each(BATCHED_EVENTS, key => { | ||
const handler = props[key]; | ||
if (is.fun(handler)) { | ||
const queue = ctrl['_events'][key]; | ||
if (is.fun(handler)) { | ||
const queue = ctrl['_events'][key]; | ||
props[key] = ({ | ||
finished, | ||
cancelled | ||
}) => { | ||
const result = queue.get(handler); | ||
props[key] = ({ | ||
finished, | ||
cancelled | ||
}) => { | ||
const result = queue.get(handler); | ||
if (result) { | ||
if (!finished) result.finished = false; | ||
if (cancelled) result.cancelled = true; | ||
} else { | ||
queue.set(handler, { | ||
value: null, | ||
finished: finished || false, | ||
cancelled: cancelled || false | ||
}); | ||
} | ||
}; | ||
if (result) { | ||
if (!finished) result.finished = false; | ||
if (cancelled) result.cancelled = true; | ||
} else { | ||
queue.set(handler, { | ||
value: null, | ||
finished: finished || false, | ||
cancelled: cancelled || false | ||
}); | ||
} | ||
}; | ||
if (defaults) { | ||
defaults[key] = props[key]; | ||
} | ||
if (defaults) { | ||
defaults[key] = props[key]; | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
@@ -1715,4 +1714,4 @@ const state = ctrl['_state']; | ||
} else if (state.paused) { | ||
props.pause = true; | ||
} | ||
props.pause = true; | ||
} | ||
@@ -2558,6 +2557,6 @@ const promises = (keys || Object.keys(ctrl.springs)).map(key => ctrl.springs[key].start(props)); | ||
} else if (event.type == 'idle') { | ||
this._active.delete(event.parent); | ||
} else if (event.type == 'priority') { | ||
this.priority = toArray(this.source).reduce((highest, parent) => Math.max(highest, (isFrameValue(parent) ? parent.priority : 0) + 1), 0); | ||
} | ||
this._active.delete(event.parent); | ||
} else if (event.type == 'priority') { | ||
this.priority = toArray(this.source).reduce((highest, parent) => Math.max(highest, (isFrameValue(parent) ? parent.priority : 0) + 1), 0); | ||
} | ||
} | ||
@@ -2564,0 +2563,0 @@ |
{ | ||
"name": "@react-spring/core", | ||
"version": "9.5.2", | ||
"version": "9.5.3", | ||
"main": "dist/react-spring-core.cjs.js", | ||
@@ -34,10 +34,10 @@ "module": "dist/react-spring-core.esm.js", | ||
"dependencies": { | ||
"@react-spring/animated": "~9.5.2", | ||
"@react-spring/rafz": "~9.5.2", | ||
"@react-spring/shared": "~9.5.2", | ||
"@react-spring/types": "~9.5.2" | ||
"@react-spring/animated": "~9.5.3", | ||
"@react-spring/rafz": "~9.5.3", | ||
"@react-spring/shared": "~9.5.3", | ||
"@react-spring/types": "~9.5.3" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.8.0 || >=17.0.0 || >=18.0.0" | ||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
263976
8122
1
Updated@react-spring/rafz@~9.5.3
Updated@react-spring/shared@~9.5.3
Updated@react-spring/types@~9.5.3