Files
Webklar.com/node_modules/framer-motion/dist/es/render/utils/setters.mjs
Basilosaurusrex f027651f9b main repo
2025-11-24 18:09:40 +01:00

32 lines
1.1 KiB
JavaScript

import { motionValue } from 'motion-dom';
import { isKeyframesTarget } from '../../animation/utils/is-keyframes-target.mjs';
import { resolveVariant } from './resolve-dynamic-variants.mjs';
/**
* Set VisualElement's MotionValue, creating a new MotionValue for it if
* it doesn't exist.
*/
function setMotionValue(visualElement, key, value) {
if (visualElement.hasValue(key)) {
visualElement.getValue(key).set(value);
}
else {
visualElement.addValue(key, motionValue(value));
}
}
function resolveFinalValueInKeyframes(v) {
// TODO maybe throw if v.length - 1 is placeholder token?
return isKeyframesTarget(v) ? v[v.length - 1] || 0 : v;
}
function setTarget(visualElement, definition) {
const resolved = resolveVariant(visualElement, definition);
let { transitionEnd = {}, transition = {}, ...target } = resolved || {};
target = { ...target, ...transitionEnd };
for (const key in target) {
const value = resolveFinalValueInKeyframes(target[key]);
setMotionValue(visualElement, key, value);
}
}
export { setTarget };