setters.mjs 924 B

123456789101112131415161718192021222324252627
  1. import { motionValue } from 'motion-dom';
  2. import { resolveFinalValueInKeyframes } from '../../utils/resolve-value.mjs';
  3. import { resolveVariant } from './resolve-dynamic-variants.mjs';
  4. /**
  5. * Set VisualElement's MotionValue, creating a new MotionValue for it if
  6. * it doesn't exist.
  7. */
  8. function setMotionValue(visualElement, key, value) {
  9. if (visualElement.hasValue(key)) {
  10. visualElement.getValue(key).set(value);
  11. }
  12. else {
  13. visualElement.addValue(key, motionValue(value));
  14. }
  15. }
  16. function setTarget(visualElement, definition) {
  17. const resolved = resolveVariant(visualElement, definition);
  18. let { transitionEnd = {}, transition = {}, ...target } = resolved || {};
  19. target = { ...target, ...transitionEnd };
  20. for (const key in target) {
  21. const value = resolveFinalValueInKeyframes(target[key]);
  22. setMotionValue(visualElement, key, value);
  23. }
  24. }
  25. export { setTarget };