bouncr
v0.1.0
Published
Framework-agnostic rubber-band gesture physics for PWAs and web apps.
Downloads
88
Maintainers
Readme
bouncr
Framework-agnostic rubber-band gesture physics for PWAs and web apps. Built with TypeScript, zero runtime dependencies.
Install
npm install bouncrQuick Start
import { createRubberBand } from 'bouncr';
const el = document.getElementById('pull-surface') as HTMLElement;
const rubberBand = createRubberBand(el, {
thresholds: { down: 110 },
effects: { haptics: true },
callbacks: {
onThresholdEnter: ({ direction, progress }) => {
console.log('threshold reached', direction, progress);
},
onAction: () => {
console.log('trigger refresh');
}
}
});
// later
rubberBand.destroy();Features
- Logarithmic resistance (
R * ln(1 + d / R)) - Directional gesture support (
down,up,left,right) - Threshold enter/exit hooks
- Optional haptic notch (
navigator.vibrate(10)) - Interpolated progress and opacity values
- Snap-back animation presets
Scripts
npm run devwatch build withtsupnpm run buildproduction buildnpm run testrun unit testsnpm run lintlint TypeScript filesnpm run typecheckstrict type checking
API
createRubberBand(element, config?)
Returns a controller:
destroy()remove listeners and stop updatesreset()clear transform and internal statesetConfig(partial)update runtime configgetState()snapshot of current gesture state
See src/types.ts for full type definitions.
