WillChangeMotionValue.mjs 600 B

12345678910111213141516171819202122
  1. import { MotionValue } from 'motion-dom';
  2. import { addUniqueItem } from 'motion-utils';
  3. import { getWillChangeName } from './get-will-change-name.mjs';
  4. class WillChangeMotionValue extends MotionValue {
  5. constructor() {
  6. super(...arguments);
  7. this.values = [];
  8. }
  9. add(name) {
  10. const styleName = getWillChangeName(name);
  11. if (styleName) {
  12. addUniqueItem(this.values, styleName);
  13. this.update();
  14. }
  15. }
  16. update() {
  17. this.set(this.values.length ? this.values.join(", ") : "auto");
  18. }
  19. }
  20. export { WillChangeMotionValue };