UNPKG

motion

Version:

The Motion library for the web

47 lines (44 loc) 1.61 kB
import { stopAnimation } from './stop-animation.es.js'; import { ms } from './time.es.js'; function createAnimationControls(animations) { // TODO Duplication with animate const state = { animations, finished: Promise.all(animations.map((animation) => animation.finished)), }; return new Proxy(state, controls); } const controls = { get: (target, key) => { var _a, _b; switch (key) { case "finished": return target.finished; case "currentTime": // TODO Find first active animation const duration = ((_a = target.animations[0]) === null || _a === void 0 ? void 0 : _a[key]) || 0; return duration ? duration / 1000 : 0; case "playbackRate": // TODO Find first active animation return (_b = target.animations[0]) === null || _b === void 0 ? void 0 : _b[key]; case "stop": return () => target.animations.forEach(stopAnimation); default: return () => target.animations.forEach((animation) => animation[key]()); } }, set: (target, key, value) => { switch (key) { case "currentTime": value = ms(value); case "currentTime": case "playbackRate": for (let i = 0; i < target.animations.length; i++) { target.animations[i][key] = value; } return true; } return false; }, }; export { controls, createAnimationControls };