The `raf` package provides a `requestAnimationFrame` polyfill, making the browser animation API available in non-browser environments like Node.js and ensuring broader compatibility across older browser versions. The current stable version is 3.4.1. It maintains a simple, direct API for scheduling animation callbacks, distinct from event emitter or stream-based approaches which were moved to the separate `raf-stream` package in versions prior to 1.0.0. Its primary differentiator is its lightweight nature and dedicated support for Node.js environments without relying on heavy browser emulation. Release cadence is infrequent, typical for a stable polyfill, with updates primarily addressing compatibility issues or minor bug fixes, rather than introducing new features. This package is a foundational utility for cross-environment animation loops.
npm install rafVerified import paths — ran on the pinned version, not inferred.
Demonstrates a basic animation loop using `raf` to schedule a function (`animate`) to run on subsequent animation frames, logging progress until a predefined frame limit is reached.
If your application relied on the stream or event emitter API of `raf`, you must migrate to using the `raf-stream` package instead, or reimplement the streaming logic using the core `raf` function directly.
Determine whether you need to polyfill the global environment or simply use the `raf` function as a local import. Use `import 'raf/polyfill';` for global polyfilling or `raf.polyfill()` for explicit control over the target object.
Ensure you are using the correct method for your build system or runtime environment. Use `require('raf')` or `import raf from 'raf'` for modules, and rely on `window.raf` after including the UMD bundle via a script tag.If you are only polyfilling the global scope, access the function via `window.requestAnimationFrame` (or `global.requestAnimationFrame` in Node). If you intend to use `raf` as a local function, ensure you explicitly `import raf from 'raf';` or `const raf = require('raf');`.In Node.js, ensure `require('raf/polyfill');` or `import 'raf/polyfill';` is executed early in your application's lifecycle to polyfill `global.requestAnimationFrame`. Alternatively, use the `raf` function returned by `require('raf')` directly without relying on global `window`.No dependency data recorded yet.