add-will-change.mjs 718 B

1234567891011121314151617181920
  1. import { MotionGlobalConfig } from 'motion-utils';
  2. import { isWillChangeMotionValue } from './is.mjs';
  3. function addValueToWillChange(visualElement, key) {
  4. const willChange = visualElement.getValue("willChange");
  5. /**
  6. * It could be that a user has set willChange to a regular MotionValue,
  7. * in which case we can't add the value to it.
  8. */
  9. if (isWillChangeMotionValue(willChange)) {
  10. return willChange.add(key);
  11. }
  12. else if (!willChange && MotionGlobalConfig.WillChange) {
  13. const newWillChange = new MotionGlobalConfig.WillChange("auto");
  14. visualElement.addValue("willChange", newWillChange);
  15. newWillChange.add(key);
  16. }
  17. }
  18. export { addValueToWillChange };