Hammer.js is a library for recognizing touch gestures in web applications. It functions as a unified interface that translates raw pointer, mouse, and touch inputs into a consistent stream of interaction data, allowing developers to detect patterns such as taps, swipes, and pans across different browsers and hardware.
The library distinguishes itself through a modular architecture that uses configurable logic blocks to evaluate input streams against specific mathematical thresholds. It maintains an internal registry of active touch points to track complex multi-finger movements like pinching and rotating, while a state machine manages the lifecycle of these interactions to determine when a gesture is successfully completed.
Beyond standard interactions, the library supports custom gesture handling and event delegation through the document object model. It provides a comprehensive set of event handlers that abstract away inconsistent input behaviors, enabling the creation of responsive interfaces that interpret finger movements on touch-enabled devices.