motion
Version:
The Motion library for the web
52 lines (47 loc) • 1.75 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var stopAnimation = require('./stop-animation.cjs.js');
var time = require('./time.cjs.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.stopAnimation);
default:
return () => target.animations.forEach((animation) => animation[key]());
}
},
set: (target, key, value) => {
switch (key) {
case "currentTime":
value = time.ms(value);
case "currentTime":
case "playbackRate":
for (let i = 0; i < target.animations.length; i++) {
target.animations[i][key] = value;
}
return true;
}
return false;
},
};
exports.controls = controls;
exports.createAnimationControls = createAnimationControls;