{"name":"rafz","version":"0.2.0-1","description":"requestAnimationFrame for libraries","author":{"name":"Alec Larson"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/alloc/rafz.git"},"main":"cjs/raf.js","module":"esm/raf.js","scripts":{"build":"tsc -p . --outDir esm && tsc -p . --module commonjs --outDir cjs","prepare":"yarn build && node scripts/prepare","test":"jest"},"dependencies":{"react-batched-updates":"^1.0.0"},"devDependencies":{"@cush/exec":"^1.7.1","@types/jest":"^26.0.22","esbuild":"^0.11.3","esbuild-jest":"npm:@alloc/esbuild-jest@^0.3.5","jest":"^26.6.3","prettier":"^2.2.1","saxon":"^0.2.11","typescript":"^4.0.0"},"keywords":["raf","requestAnimationFrame","frameloop","animation","tiny"],"readme":"# rafz\n\nCoordinate `requestAnimationFrame` calls across your app and/or libraries.\n\n* < 700 bytes min+gzip\n* Timeout support\n* Batching support (eg: `ReactDOM.unstable_batchedUpdates`)\n* Uncaught errors are isolated\n* Runs continuously (to reduce frame skips)\n\n&nbsp;\n\n## API\n\n```ts\nimport { raf } from 'rafz'\n\n// Schedule an update\nraf(dt => {})\n\n// Start an update loop\nraf(dt => true)\n\n// Cancel an update\nraf.cancel(fn)\n\n// Schedule a mutation\nraf.write(() => {})\n\n// Before any updates\nraf.onStart(() => {})\n\n// Before any mutations\nraf.onFrame(() => {})\n\n// After any mutations\nraf.onFinish(() => {})\n\n// Set a timeout that runs on nearest frame\nraf.setTimeout(() => {}, 1000)\n\n// Use a polyfill\nraf.use(require('@essentials/raf').raf)\n\n// Get the current time\nraf.now() // => number\n```\n\n&nbsp;\n\n## Notes\n\n* Functions can only be scheduled once per queue per frame.\n* Thus, trying to schedule a function twice is a no-op.\n* The `update` phase is for updating JS state (eg: advancing an animation).\n* The `write` phase is for updating native state (eg: mutating the DOM).\n* [Reading] is allowed any time before the `write` phase.\n* Writing is allowed any time after the `onFrame` phase.\n* Timeout handlers run first on each frame.\n* Any handler (except timeouts) can return `true` to run again next frame.\n* The `raf.cancel` function only works with `raf` handlers.\n* Use `raf.sync` to disable scheduling in its callback.\n* Override `raf.batchedUpdates` to avoid excessive re-rendering in React.\n\n[Reading]: https://gist.github.com/paulirish/5d52fb081b3570c81e3a\n\n&nbsp;\n\n## `raf.throttle`\n\nWrap a function to limit its execution to once per frame. If called more than once\nin a single frame, the last arguments are used.\n\n```ts\nlet log = raf.throttle(console.log)\n\nlog(1)\nlog(2) // nothing logged yet\n\nraf.onStart(() => {\n  // \"2\" is logged by now\n})\n\n// Cancel a pending call.\nlog.cancel()\n\n// Access the wrapped function.\nlog.handler\n```\n\n&nbsp;\n\n## Used by\n\n- [react-spring](https://github.com/pmndrs/react-spring)\n- [react-three-fiber](https://github.com/pmndrs/react-three-fiber)\n- [use-element-size](https://github.com/alloc/use-element-size)\n\n&nbsp;\n\n## Prior art\n\n- [fastdom](https://github.com/wilsonpage/fastdom)\n- [framesync](https://github.com/Popmotion/popmotion/tree/master/packages/framesync)\n","readmeFilename":"README.md","gitHead":"6524a5bdd2d9e4a6477023a3ed700acd8e9032cb","bugs":{"url":"https://github.com/alloc/rafz/issues"},"homepage":"https://github.com/alloc/rafz#readme","_id":"rafz@0.2.0-1","_nodeVersion":"16.5.0","_npmVersion":"7.19.1","dist":{"integrity":"sha512-jEnkvs3uezHEqwD/v0der8xrhCtH06Cxl/k4hASdx2aJbDBRDC9KtkZ9T3e+mqFpeBAVRyhqzxd9OlgbFaTiCQ==","shasum":"8982c3bb290f770be59509bea99085cc9b68590e","tarball":"http://registry-npm.ywwl.com/rafz/download/rafz-0.2.0-1.tgz","fileCount":69,"unpackedSize":64804,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhGADiCRA9TVsSAnZWagAAuv4P/1ZnS94qfzq6XRz4dqx8\nBtmu2bMRm2MfQqKBcOjAQiTPpPiW5pfZI3YEkhUvMm63W9ShxufM7ZsNtkLv\njDzb/7pMuhzFIzKJj0Q2Wt9lxKMY47pia/CkYPV/Qzrm1PLknnvP0sbQ8RzM\npQ7m4RSdnuGz7vTg7Kz2SMbNzIvYSVKfANYFQddWEQqJLvS5qBvToMrSrrvo\n4gogGwscAw0E2u4R5AxSXGHEpmT8uQ91AFtCoLNwVJbEegdkx/MLrFuedVOy\nhARVWZMNzfHzhOIFRUgpT9zlwOxyVNVHuyFjQD0fEYkkvyBtaI4UwJKDk4+Q\nQcT7vytp5hkLkJ/ypIh4q1mADdTtJWDRJ5xOeen/QVfQfsws1SY1ABd8WzMV\nauQ/QYVA/mINULBVkOi1ng2ugBANOyV0OydgHSLrXfB/SAv4OtJzhYEekUaK\n65QUdETnR7e136C9M8vhNzCYGwgf6PjivH8x/aI1amgsWVMMRDG7qEacLaBQ\ng0TdgsEoBcsIvClwS5MBqMA763yNjpGBltuSKgEn9KLP/yw1SPhc6n3L/giO\nhXfeXBbO52nx0fz1X+WuIYYrS7LOaHEbxiqpfLSh1wfod9sjBCooZLDJyHRX\nm82KIT2nMxr0eK01KKzwKi6xcAi/Dg2CPyQEUOm7Ijo5X1OLGKB6aF+cHLOJ\nUSJ/\r\n=9CHc\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDKmgHUZEMXj4qhPlXqwBHFd84DFPzIUxWyPPtmwszxagIhAMfd7OIUPPLF1HeWRykQdc1u3aFR2qkIWC9AI/HI0339"}],"size":14189,"noattachment":false,"key":"/rafz/-/rafz-0.2.0-1.tgz"},"_npmUser":{"name":"aleclarson","email":"aleclarson@protonmail.com"},"directories":{},"maintainers":[{"name":"aleclarson","email":"aleclarson@protonmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rafz_0.2.0-1_1628963041970_0.6788101863327407"},"_hasShrinkwrap":false,"publish_time":1628963042095,"_cnpm_publish_time":1628963042095,"dist-tags":{"latest":"0.1.14","next":"0.3.0-0"}}