main repo

This commit is contained in:
Basilosaurusrex
2025-11-24 18:09:40 +01:00
parent b636ee5e70
commit f027651f9b
34146 changed files with 4436636 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
import { MotionValue, transformProps, acceleratedValues } from 'motion-dom';
class WillChangeMotionValue extends MotionValue {
constructor() {
super(...arguments);
this.isEnabled = false;
}
add(name) {
if (transformProps.has(name) || acceleratedValues.has(name)) {
this.isEnabled = true;
this.update();
}
}
update() {
this.set(this.isEnabled ? "transform" : "auto");
}
}
export { WillChangeMotionValue };

View File

@@ -0,0 +1,20 @@
import { MotionGlobalConfig } from 'motion-utils';
import { isWillChangeMotionValue } from './is.mjs';
function addValueToWillChange(visualElement, key) {
const willChange = visualElement.getValue("willChange");
/**
* It could be that a user has set willChange to a regular MotionValue,
* in which case we can't add the value to it.
*/
if (isWillChangeMotionValue(willChange)) {
return willChange.add(key);
}
else if (!willChange && MotionGlobalConfig.WillChange) {
const newWillChange = new MotionGlobalConfig.WillChange("auto");
visualElement.addValue("willChange", newWillChange);
newWillChange.add(key);
}
}
export { addValueToWillChange };

View File

@@ -0,0 +1,9 @@
"use client";
import { useConstant } from '../../utils/use-constant.mjs';
import { WillChangeMotionValue } from './WillChangeMotionValue.mjs';
function useWillChange() {
return useConstant(() => new WillChangeMotionValue("auto"));
}
export { useWillChange };

View File

@@ -0,0 +1,7 @@
import { isMotionValue } from 'motion-dom';
function isWillChangeMotionValue(value) {
return Boolean(isMotionValue(value) && value.add);
}
export { isWillChangeMotionValue };