MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / normalizeSpringConfig

Function normalizeSpringConfig

packages/core/src/animation/spring.ts:29–64  ·  view source on GitHub ↗
(config: SpringConfig | undefined)

Source from the content-addressed store, hash-verified

27});
28
29export function normalizeSpringConfig(config: SpringConfig | undefined): NormalizedSpringConfig {
30 if (!config) return DEFAULT_SPRING_CONFIG;
31 const stiffness =
32 typeof config.stiffness === "number" && Number.isFinite(config.stiffness)
33 ? Math.max(0, config.stiffness)
34 : DEFAULT_SPRING_CONFIG.stiffness;
35 const damping =
36 typeof config.damping === "number" && Number.isFinite(config.damping)
37 ? Math.max(0, config.damping)
38 : DEFAULT_SPRING_CONFIG.damping;
39 const mass =
40 typeof config.mass === "number" && Number.isFinite(config.mass)
41 ? Math.max(0.0001, config.mass)
42 : DEFAULT_SPRING_CONFIG.mass;
43 const restDelta =
44 typeof config.restDelta === "number" && Number.isFinite(config.restDelta)
45 ? Math.max(0, config.restDelta)
46 : DEFAULT_SPRING_CONFIG.restDelta;
47 const restSpeed =
48 typeof config.restSpeed === "number" && Number.isFinite(config.restSpeed)
49 ? Math.max(0, config.restSpeed)
50 : DEFAULT_SPRING_CONFIG.restSpeed;
51 const maxDeltaMs =
52 typeof config.maxDeltaMs === "number" && Number.isFinite(config.maxDeltaMs)
53 ? Math.max(1, Math.trunc(config.maxDeltaMs))
54 : DEFAULT_SPRING_CONFIG.maxDeltaMs;
55
56 return Object.freeze({
57 stiffness,
58 damping,
59 mass,
60 restDelta,
61 restSpeed,
62 maxDeltaMs,
63 });
64}
65
66export function isSpringAtRest(
67 value: number,

Callers 3

useSpringFunction · 0.85
useAnimatedValueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected