Színkorrekciók
This commit is contained in:
Generated
Vendored
+19
@@ -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 };
|
||||
+20
@@ -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 };
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import { useConstant } from '../../utils/use-constant.mjs';
|
||||
import { WillChangeMotionValue } from './WillChangeMotionValue.mjs';
|
||||
|
||||
function useWillChange() {
|
||||
return useConstant(() => new WillChangeMotionValue("auto"));
|
||||
}
|
||||
|
||||
export { useWillChange };
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { isMotionValue } from 'motion-dom';
|
||||
|
||||
function isWillChangeMotionValue(value) {
|
||||
return Boolean(isMotionValue(value) && value.add);
|
||||
}
|
||||
|
||||
export { isWillChangeMotionValue };
|
||||
Reference in New Issue
Block a user