{"name":"framesync","license":"MIT","version":"6.1.0","description":"A frame-synced render loop for JavaScript","author":{"name":"Matt Perry"},"homepage":"https://popmotion.io","main":"dist/framesync.cjs.js","types":"lib/index.d.ts","module":"dist/es/index.mjs","jsnext:main":"dist/es/index.mjs","unpkg":"./dist/framesync.min.js","exports":{".":{"import":"./dist/es/index.mjs","require":"./dist/framesync.cjs.js","default":"./dist/framesync.cjs.js"},"./package.json":"./package.json"},"scripts":{"build":"tsc -p . && rollup -c && yarn measure","watch":"rollup -c -w","lint":"tslint -c tslint.json 'src/**/*.{ts}'","test":"jest","measure":"gzip -c dist/framesync.min.js | wc -c","prepublishOnly":"npm run test && npm run build"},"repository":{"type":"git","url":"git+https://github.com/Popmotion/popmotion.git"},"keywords":["animation","raf"],"bugs":{"url":"https://github.com/Popmotion/popmotion/issues"},"jest":{"moduleFileExtensions":["ts","js"],"transform":{"\\.(ts)$":"../../../node_modules/ts-jest/preprocessor.js"},"testRegex":"/_tests/.*\\.(ts|js)$","rootDir":"src"},"prettier":{"printWidth":80,"tabWidth":4,"semi":false,"trailingComma":"es5"},"dependencies":{"tslib":"^2.3.1"},"gitHead":"71d25a869097c0af885e27a62b30750038cfac7e","_id":"framesync@6.1.0","_nodeVersion":"17.0.1","_npmVersion":"8.1.0","dist":{"integrity":"sha512-aBX+hdWAvwiJYeQlFLY2533VxeL6OEu71CAgV4GGKksrj6+dE6i7K86WSSiRBEARCoJn5bFqffhg4l07eA27tg==","shasum":"b22cf9afba52a9a895668b09e033b6a61e901c41","tarball":"http://registry-npm.ywwl.com/framesync/download/framesync-6.1.0.tgz","fileCount":24,"unpackedSize":39611,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhnkXmCRA9TVsSAnZWagAA+RMP/jAjhmNGVpn8W3qMR21a\nFxNmNsFh3ZygMThtc3lzNSzidJtl9ieTnavjsJOsRAQpLlnpGmwSgjYEmktq\nA092CV2bjyIf+zw0AAa/NsVxgyuS1BBVIMf3OV+v3SoTcbQo8A2K3pToqXA+\nLioJb2a7nit0EYwf7YE2vtaI6Y89t0Xkgay0FW9TEfdZ82cuaxzdNjOqgx/X\naDpi4FjvZ5qt5vuX2wTZ8Tf4KEjIvrlsPB3w1LQXLP17QFVXii5Qx+LBZ/i2\nMIoV1liwf9WpaXQ0a8Ljy4JbgRzx5LiiIdIN2Yl6iTPZlPDJaFOymQcyer/H\nzCqJYzghXLzzMNg7yJBFPWZ+Vqmu7aGnx3KULQZh+/HqAfc7dDcEA04oqvBC\nsr1QiFsqLzn6I8hO3u9Vm4F0Ceha+dnVmKwdR5DG/UM7EChtBIgfTj10qFtg\n8zDmtq0pV2t4MokfTlg8NfAwBmcM6GiVOUevdgnJPdZKXGeHHptNPpnatqmc\ng/vNXk/SPW6IiA+zL5mP4RGNirSLOawtjOwUq6KVp7PbnnEUCAlG1vxauzM2\nCb5tLGFSPyVhqXypIQZwDsG6cj6uDmMNmGA68UJOpI6mP8xYpCnyoiwJRTMM\nadqk1GPmsl+sjH1+rIyQgciH8Os0kWE9fXow8dRIzZfPDhUsAgHB7yq1TgGV\n+rII\r\n=0+oe\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDKG8WWDKjHfdcj31j8vhYyGP2C4mM0qtarLn2uoXwMngIhAMyZtA2HGFfbqE0shuqKfN8V3W7twTAD/rHvjVJnOSHe"}],"size":9525,"noattachment":false,"key":"/framesync/-/framesync-6.1.0.tgz"},"_npmUser":{"name":"popmotion","email":"mattgperry@gmail.com"},"directories":{},"maintainers":[{"name":"popmotion","email":"mattgperry@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/framesync_6.1.0_1637762534833_0.9367565582403898"},"_hasShrinkwrap":false,"readme":"# Framesync\n\nA tiny frame scheduler for performantly batching reads, updates and renders.\n\nSegregating actions that read and write to the DOM will avoid [layout thrashing](https://developers.google.com/web/fundamentals/performance/rendering/avoid-large-complex-layouts-and-layout-thrashing).\n\nIt's also a way of ensuring order of execution across a frame. For instance, [Framer Motion](https://github.com/framer/motion) batches animations on the `update` step, and renders on the `render` step, allowing independent animation of `transform` properties.\n\n## Install\n\n```bash\nnpm install framesync\n```\n\n## Usage\n\nFramesync splits a frame into discrete `read`, `update`, `preRender`, `render` and `postRender` steps.\n\n### Scheduling functions\n\nFunctions can be scheduled to different parts of the render loop with `sync`.\n\n```javascript\nimport sync from 'framesync';\n```\n\nIt provides four functions, one for scheduling a function to run on each part of the frame:\n\n```javascript\nsync.update(() => {});\n```\n\n### Frame data\n\nEach function is provided data about the current frame:\n\n```javascript\nsync.update(({ delta, timestamp }) => {});\n```\n\n- `delta`: Time since last frame (in milliseconds)\n- `timestamp`: Timestamp of the current frame.\n\nThis object is recycled across frames, so values should be destructured if intended to be used asynchronously.\n\n### Keep alive\n\nWe can run a function as an ongoing process by passing `true` as the second parameter:\n\n```javascript\nlet count = 0;\n\nsync.update(() => count++, true);\n```\n\nThis will keep the process running until it's actively cancelled.\n\n### Run immediately\n\nThe third parameter, `immediate`, can be used to sync a function on the **current frame step**.\n\nBy default, Framesync will schedule functions to run the next time that frame step is fired:\n\n```javascript\nsync.update(({ timestamp }) => {\n  // The following function will run on the subsequent frame:\n  sync.update((frame) => frame.timestamp !== timestamp);\n});\n```\n\nBy setting `immediate` to `true`, we can add this at the end of the current step:\n\n```javascript\nsync.update(({ timestamp }) => {\n  // The following function will run on the **current** frame:\n  sync.update(\n    (frame) => frame.timestamp === timestamp,\n    false,\n    true\n  );\n});\n```\n\n### Cancelling\n\nSynced processes can be cancelled with the `cancelSync` function:\n\n```javascript\nimport sync, { cancelSync } from 'framesync';\n\nlet count = 0;\n\nconst process = sync.render(() => {\n  count++;\n  if (count >= 10) cancelSync.render(process);\n}, true);\n```\n","publish_time":1637762534964,"_cnpm_publish_time":1637762534964,"dist-tags":{"latest":"6.1.2","rc":"6.0.0-rc.1"}}