type DragForceProps = { isDragging : boolean ; dragPosition : number ; nativePosition : number ; velocityX : number ; } ; export function applyDragForce ( { isDragging , dragPosition , nativePosition , velocityX } ) { if ( ! isDragging ) return velocityX ; const dragVelocity = dragPosition - nativePosition ; const dragForce = dragVelocity - velocityX ; return velocityX + dragForce ; } type BoundForceProps = { bound : number ; edge : 'left' | 'right' ; nativePosition : number ; friction : number ; velocityX : number ; } ; export function applyBoundForce ( { bound , edge , nativePosition , friction , velocityX } ) { const edgeFriction = friction - 0.08 ; const distance = bound - nativePosition ; let force = distance * ( 1 - edgeFriction ) ; const rest = nativePosition + ( velocityX + force ) / ( 1 - edgeFriction ) ; if ( ( edge === 'right' && rest > bound ) || ( edge === 'left' && rest < bound ) ) { return velocityX + force ; } else { force = distance * ( 1 - edgeFriction ) - velocityX ; return velocityX + force ; } }