$ show locomotivemtl/locomotive-scroll
This is the Locomotive Scroll library (v5), a lightweight JavaScript library for smooth scrolling, parallax effects, viewport detection, and progress tracking on the web. It is built on top of Lenis and uses dual Intersection Observers for performance. The repository is a monorepo containing the core library package (`packages/lib`), a demo site (Astro), a documentation site (Docusaurus), and a landing page (Eleventy/GSAP). The library exposes a data-attribute-driven API (`data-scroll`, `data-scroll-speed`, etc.) and a `LocomotiveScroll` class with lifecycle methods. The architecture is well-structured with clean separation of concerns: Core orchestration, IO wrapper, per-element scroll tracking, and utility math functions. The library is TypeScript-first and outputs multiple module formats (ESM, CJS, UMD). While the core is solid, there are signs of technical drift (older TypeScript version, some duplicated utilities across packages, and a bundle including full Lenis source). The demo and landing page sites are more complex and tightly coupled to GSAP, but the core library is reusable as an npm package.
The LLM identified 2 files worth highlighting for reuse:
A thin, clean wrapper around the Intersection Observer API that handles setup, teardown, and callback dispatching for scroll-based visibility detection. It encapsulates the complexity of creating and reusing IO instances with configurable root margins, and provides a simple interface for registering and unregistering elements. This pattern is reusable in any project that needs to detect element visibility or trigger animations on scroll.
A set of small, pure utility functions (clamp, mapRange, normalize, closestNumber) implemented in TypeScript with generic type signatures. These are standard but implemented cleanly and can be extracted into any project requiring numeric interpolation or range mapping. They demonstrate good function design with type safety and no external dependencies.