rafu is a lightweight JavaScript utility that provides a `requestAnimationFrame` shim and enhanced animation scheduling capabilities. It ensures that animations run smoothly and efficiently across different browser environments by offering a robust fallback for `requestAnimationFrame` where native support might be missing or prefixed. Beyond merely polyfilling, rafu includes a `throttled` utility for synchronizing function calls with the browser's repaint cycle, which is crucial for performance-sensitive tasks like scroll handling, resize events, or continuous input processing. The package is currently at version 1.2.0, with its latest update introducing explicit cancellation methods for both direct `rafu` calls and functions created with `rafu.throttled`. Its minimal footprint and focused functionality make it a straightforward choice for projects needing basic `requestAnimationFrame` management without introducing heavy dependencies.
npm install rafuVerified import paths — ran on the pinned version, not inferred.
Demonstrates scheduling a simple animation loop with `rafu` and throttling a scroll event handler using `rafu.throttled`.
Always test thoroughly in target browser environments. For very specific edge cases, manual feature detection might be necessary.
Always store the handle returned by `rafu()` and `rafu.throttled()` (if it returns a handle or a cancellable function), and call `rafu.cancel()` or the throttled function's `cancel()` method when the animation or effect is no longer needed.
Ensure `rafu` is loaded early in your application's lifecycle, or be aware of other `requestAnimationFrame` polyfills in your dependency tree. Consider only using one source for `requestAnimationFrame` polyfilling.
Ensure you are using the correct import syntax for your module system: `import rafu from 'rafu';` for ESM, or `const rafu = require('rafu');` for CommonJS (if supported). Double-check the package.json `exports` field if present.Verify that `rafu` is imported as the default export: `import rafu from 'rafu';`. The `cancel` method is a property of this default export.
Ensure `rafu` is imported as the default export (`import rafu from 'rafu';`), then access the utility as `rafu.throttled(yourFunction);`. The `throttled` method is a property of the default `rafu` export.
No dependency data recorded yet.