visual-element.mjs 1.1 KB

1234567891011121314151617181920212223242526
  1. import { resolveVariant } from '../../render/utils/resolve-dynamic-variants.mjs';
  2. import { animateTarget } from './visual-element-target.mjs';
  3. import { animateVariant } from './visual-element-variant.mjs';
  4. function animateVisualElement(visualElement, definition, options = {}) {
  5. visualElement.notify("AnimationStart", definition);
  6. let animation;
  7. if (Array.isArray(definition)) {
  8. const animations = definition.map((variant) => animateVariant(visualElement, variant, options));
  9. animation = Promise.all(animations);
  10. }
  11. else if (typeof definition === "string") {
  12. animation = animateVariant(visualElement, definition, options);
  13. }
  14. else {
  15. const resolvedDefinition = typeof definition === "function"
  16. ? resolveVariant(visualElement, definition, options.custom)
  17. : definition;
  18. animation = Promise.all(animateTarget(visualElement, resolvedDefinition, options));
  19. }
  20. return animation.then(() => {
  21. visualElement.notify("AnimationComplete", definition);
  22. });
  23. }
  24. export { animateVisualElement };