driver-frameloop.mjs 543 B

12345678910111213141516
  1. import { frame, cancelFrame, frameData, time } from 'motion-dom';
  2. const frameloopDriver = (update) => {
  3. const passTimestamp = ({ timestamp }) => update(timestamp);
  4. return {
  5. start: () => frame.update(passTimestamp, true),
  6. stop: () => cancelFrame(passTimestamp),
  7. /**
  8. * If we're processing this frame we can use the
  9. * framelocked timestamp to keep things in sync.
  10. */
  11. now: () => (frameData.isProcessing ? frameData.timestamp : time.now()),
  12. };
  13. };
  14. export { frameloopDriver };