first commit
This commit is contained in:
26
node_modules/motion-dom/dist/es/animation/utils/WithPromise.mjs
generated
vendored
Normal file
26
node_modules/motion-dom/dist/es/animation/utils/WithPromise.mjs
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
class WithPromise {
|
||||
constructor() {
|
||||
this.updateFinished();
|
||||
}
|
||||
get finished() {
|
||||
return this._finished;
|
||||
}
|
||||
updateFinished() {
|
||||
this._finished = new Promise((resolve) => {
|
||||
this.resolve = resolve;
|
||||
});
|
||||
}
|
||||
notifyFinished() {
|
||||
this.resolve();
|
||||
}
|
||||
/**
|
||||
* Allows the animation to be awaited.
|
||||
*
|
||||
* @deprecated Use `finished` instead.
|
||||
*/
|
||||
then(onResolve, onReject) {
|
||||
return this.finished.then(onResolve, onReject);
|
||||
}
|
||||
}
|
||||
|
||||
export { WithPromise };
|
||||
9
node_modules/motion-dom/dist/es/animation/utils/active-animations.mjs
generated
vendored
Normal file
9
node_modules/motion-dom/dist/es/animation/utils/active-animations.mjs
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
const animationMaps = new WeakMap();
|
||||
const animationMapKey = (name, pseudoElement = "") => `${name}:${pseudoElement}`;
|
||||
function getAnimationMap(element) {
|
||||
const map = animationMaps.get(element) || new Map();
|
||||
animationMaps.set(element, map);
|
||||
return map;
|
||||
}
|
||||
|
||||
export { animationMapKey, getAnimationMap };
|
||||
42
node_modules/motion-dom/dist/es/animation/utils/can-animate.mjs
generated
vendored
Normal file
42
node_modules/motion-dom/dist/es/animation/utils/can-animate.mjs
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
import { warning } from 'motion-utils';
|
||||
import { isGenerator } from '../generators/utils/is-generator.mjs';
|
||||
import { isAnimatable } from './is-animatable.mjs';
|
||||
|
||||
function hasKeyframesChanged(keyframes) {
|
||||
const current = keyframes[0];
|
||||
if (keyframes.length === 1)
|
||||
return true;
|
||||
for (let i = 0; i < keyframes.length; i++) {
|
||||
if (keyframes[i] !== current)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
function canAnimate(keyframes, name, type, velocity) {
|
||||
/**
|
||||
* Check if we're able to animate between the start and end keyframes,
|
||||
* and throw a warning if we're attempting to animate between one that's
|
||||
* animatable and another that isn't.
|
||||
*/
|
||||
const originKeyframe = keyframes[0];
|
||||
if (originKeyframe === null)
|
||||
return false;
|
||||
/**
|
||||
* These aren't traditionally animatable but we do support them.
|
||||
* In future we could look into making this more generic or replacing
|
||||
* this function with mix() === mixImmediate
|
||||
*/
|
||||
if (name === "display" || name === "visibility")
|
||||
return true;
|
||||
const targetKeyframe = keyframes[keyframes.length - 1];
|
||||
const isOriginAnimatable = isAnimatable(originKeyframe, name);
|
||||
const isTargetAnimatable = isAnimatable(targetKeyframe, name);
|
||||
warning(isOriginAnimatable === isTargetAnimatable, `You are trying to animate ${name} from "${originKeyframe}" to "${targetKeyframe}". "${isOriginAnimatable ? targetKeyframe : originKeyframe}" is not an animatable value.`, "value-not-animatable");
|
||||
// Always skip if any of these are true
|
||||
if (!isOriginAnimatable || !isTargetAnimatable) {
|
||||
return false;
|
||||
}
|
||||
return (hasKeyframesChanged(keyframes) ||
|
||||
((type === "spring" || isGenerator(type)) && velocity));
|
||||
}
|
||||
|
||||
export { canAnimate };
|
||||
41
node_modules/motion-dom/dist/es/animation/utils/css-variables-conversion.mjs
generated
vendored
Normal file
41
node_modules/motion-dom/dist/es/animation/utils/css-variables-conversion.mjs
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
import { invariant, isNumericalString } from 'motion-utils';
|
||||
import { isCSSVariableToken } from './is-css-variable.mjs';
|
||||
|
||||
/**
|
||||
* Parse Framer's special CSS variable format into a CSS token and a fallback.
|
||||
*
|
||||
* ```
|
||||
* `var(--foo, #fff)` => [`--foo`, '#fff']
|
||||
* ```
|
||||
*
|
||||
* @param current
|
||||
*/
|
||||
const splitCSSVariableRegex =
|
||||
// eslint-disable-next-line redos-detector/no-unsafe-regex -- false positive, as it can match a lot of words
|
||||
/^var\(--(?:([\w-]+)|([\w-]+), ?([a-zA-Z\d ()%#.,-]+))\)/u;
|
||||
function parseCSSVariable(current) {
|
||||
const match = splitCSSVariableRegex.exec(current);
|
||||
if (!match)
|
||||
return [,];
|
||||
const [, token1, token2, fallback] = match;
|
||||
return [`--${token1 ?? token2}`, fallback];
|
||||
}
|
||||
const maxDepth = 4;
|
||||
function getVariableValue(current, element, depth = 1) {
|
||||
invariant(depth <= maxDepth, `Max CSS variable fallback depth detected in property "${current}". This may indicate a circular fallback dependency.`, "max-css-var-depth");
|
||||
const [token, fallback] = parseCSSVariable(current);
|
||||
// No CSS variable detected
|
||||
if (!token)
|
||||
return;
|
||||
// Attempt to read this CSS variable off the element
|
||||
const resolved = window.getComputedStyle(element).getPropertyValue(token);
|
||||
if (resolved) {
|
||||
const trimmed = resolved.trim();
|
||||
return isNumericalString(trimmed) ? parseFloat(trimmed) : trimmed;
|
||||
}
|
||||
return isCSSVariableToken(fallback)
|
||||
? getVariableValue(fallback, element, depth + 1)
|
||||
: fallback;
|
||||
}
|
||||
|
||||
export { getVariableValue, parseCSSVariable };
|
||||
7
node_modules/motion-dom/dist/es/animation/utils/get-value-transition.mjs
generated
vendored
Normal file
7
node_modules/motion-dom/dist/es/animation/utils/get-value-transition.mjs
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
function getValueTransition(transition, key) {
|
||||
return (transition?.[key] ??
|
||||
transition?.["default"] ??
|
||||
transition);
|
||||
}
|
||||
|
||||
export { getValueTransition };
|
||||
30
node_modules/motion-dom/dist/es/animation/utils/is-animatable.mjs
generated
vendored
Normal file
30
node_modules/motion-dom/dist/es/animation/utils/is-animatable.mjs
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import { complex } from '../../value/types/complex/index.mjs';
|
||||
|
||||
/**
|
||||
* Check if a value is animatable. Examples:
|
||||
*
|
||||
* ✅: 100, "100px", "#fff"
|
||||
* ❌: "block", "url(2.jpg)"
|
||||
* @param value
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
const isAnimatable = (value, name) => {
|
||||
// If the list of keys that might be non-animatable grows, replace with Set
|
||||
if (name === "zIndex")
|
||||
return false;
|
||||
// If it's a number or a keyframes array, we can animate it. We might at some point
|
||||
// need to do a deep isAnimatable check of keyframes, or let Popmotion handle this,
|
||||
// but for now lets leave it like this for performance reasons
|
||||
if (typeof value === "number" || Array.isArray(value))
|
||||
return true;
|
||||
if (typeof value === "string" && // It's animatable if we have a string
|
||||
(complex.test(value) || value === "0") && // And it contains numbers and/or colors
|
||||
!value.startsWith("url(") // Unless it starts with "url("
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
export { isAnimatable };
|
||||
15
node_modules/motion-dom/dist/es/animation/utils/is-css-variable.mjs
generated
vendored
Normal file
15
node_modules/motion-dom/dist/es/animation/utils/is-css-variable.mjs
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
const checkStringStartsWith = (token) => (key) => typeof key === "string" && key.startsWith(token);
|
||||
const isCSSVariableName =
|
||||
/*@__PURE__*/ checkStringStartsWith("--");
|
||||
const startsAsVariableToken =
|
||||
/*@__PURE__*/ checkStringStartsWith("var(--");
|
||||
const isCSSVariableToken = (value) => {
|
||||
const startsWithToken = startsAsVariableToken(value);
|
||||
if (!startsWithToken)
|
||||
return false;
|
||||
// Ensure any comments are stripped from the value as this can harm performance of the regex.
|
||||
return singleCssVariableRegex.test(value.split("/*")[0].trim());
|
||||
};
|
||||
const singleCssVariableRegex = /var\(--(?:[\w-]+\s*|[\w-]+\s*,(?:\s*[^)(\s]|\s*\((?:[^)(]|\([^)(]*\))*\))+\s*)\)$/iu;
|
||||
|
||||
export { isCSSVariableName, isCSSVariableToken };
|
||||
6
node_modules/motion-dom/dist/es/animation/utils/make-animation-instant.mjs
generated
vendored
Normal file
6
node_modules/motion-dom/dist/es/animation/utils/make-animation-instant.mjs
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
function makeAnimationInstant(options) {
|
||||
options.duration = 0;
|
||||
options.type = "keyframes";
|
||||
}
|
||||
|
||||
export { makeAnimationInstant };
|
||||
18
node_modules/motion-dom/dist/es/animation/utils/replace-transition-type.mjs
generated
vendored
Normal file
18
node_modules/motion-dom/dist/es/animation/utils/replace-transition-type.mjs
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import { inertia } from '../generators/inertia.mjs';
|
||||
import { keyframes } from '../generators/keyframes.mjs';
|
||||
import { spring } from '../generators/spring/index.mjs';
|
||||
|
||||
const transitionTypeMap = {
|
||||
decay: inertia,
|
||||
inertia,
|
||||
tween: keyframes,
|
||||
keyframes: keyframes,
|
||||
spring,
|
||||
};
|
||||
function replaceTransitionType(transition) {
|
||||
if (typeof transition.type === "string") {
|
||||
transition.type = transitionTypeMap[transition.type];
|
||||
}
|
||||
}
|
||||
|
||||
export { replaceTransitionType };
|
||||
Reference in New Issue
Block a user