first commit
This commit is contained in:
21
node_modules/motion-utils/LICENSE.md
generated
vendored
Normal file
21
node_modules/motion-utils/LICENSE.md
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2024 [Motion](https://motion.dev) B.V.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
344
node_modules/motion-utils/dist/cjs/index.js
generated
vendored
Normal file
344
node_modules/motion-utils/dist/cjs/index.js
generated
vendored
Normal file
@@ -0,0 +1,344 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
function addUniqueItem(arr, item) {
|
||||
if (arr.indexOf(item) === -1)
|
||||
arr.push(item);
|
||||
}
|
||||
function removeItem(arr, item) {
|
||||
const index = arr.indexOf(item);
|
||||
if (index > -1)
|
||||
arr.splice(index, 1);
|
||||
}
|
||||
// Adapted from array-move
|
||||
function moveItem([...arr], fromIndex, toIndex) {
|
||||
const startIndex = fromIndex < 0 ? arr.length + fromIndex : fromIndex;
|
||||
if (startIndex >= 0 && startIndex < arr.length) {
|
||||
const endIndex = toIndex < 0 ? arr.length + toIndex : toIndex;
|
||||
const [item] = arr.splice(fromIndex, 1);
|
||||
arr.splice(endIndex, 0, item);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
const clamp = (min, max, v) => {
|
||||
if (v > max)
|
||||
return max;
|
||||
if (v < min)
|
||||
return min;
|
||||
return v;
|
||||
};
|
||||
|
||||
function formatErrorMessage(message, errorCode) {
|
||||
return errorCode
|
||||
? `${message}. For more information and steps for solving, visit https://motion.dev/troubleshooting/${errorCode}`
|
||||
: message;
|
||||
}
|
||||
|
||||
exports.warning = () => { };
|
||||
exports.invariant = () => { };
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
exports.warning = (check, message, errorCode) => {
|
||||
if (!check && typeof console !== "undefined") {
|
||||
console.warn(formatErrorMessage(message, errorCode));
|
||||
}
|
||||
};
|
||||
exports.invariant = (check, message, errorCode) => {
|
||||
if (!check) {
|
||||
throw new Error(formatErrorMessage(message, errorCode));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const MotionGlobalConfig = {};
|
||||
|
||||
/**
|
||||
* Check if value is a numerical string, ie a string that is purely a number eg "100" or "-100.1"
|
||||
*/
|
||||
const isNumericalString = (v) => /^-?(?:\d+(?:\.\d+)?|\.\d+)$/u.test(v);
|
||||
|
||||
function isObject(value) {
|
||||
return typeof value === "object" && value !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the value is a zero value string like "0px" or "0%"
|
||||
*/
|
||||
const isZeroValueString = (v) => /^0[^.\s]+$/u.test(v);
|
||||
|
||||
/*#__NO_SIDE_EFFECTS__*/
|
||||
function memo(callback) {
|
||||
let result;
|
||||
return () => {
|
||||
if (result === undefined)
|
||||
result = callback();
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
/*#__NO_SIDE_EFFECTS__*/
|
||||
const noop = (any) => any;
|
||||
|
||||
/**
|
||||
* Pipe
|
||||
* Compose other transformers to run linearily
|
||||
* pipe(min(20), max(40))
|
||||
* @param {...functions} transformers
|
||||
* @return {function}
|
||||
*/
|
||||
const combineFunctions = (a, b) => (v) => b(a(v));
|
||||
const pipe = (...transformers) => transformers.reduce(combineFunctions);
|
||||
|
||||
/*
|
||||
Progress within given range
|
||||
|
||||
Given a lower limit and an upper limit, we return the progress
|
||||
(expressed as a number 0-1) represented by the given value, and
|
||||
limit that progress to within 0-1.
|
||||
|
||||
@param [number]: Lower limit
|
||||
@param [number]: Upper limit
|
||||
@param [number]: Value to find progress within given range
|
||||
@return [number]: Progress of value within range as expressed 0-1
|
||||
*/
|
||||
/*#__NO_SIDE_EFFECTS__*/
|
||||
const progress = (from, to, value) => {
|
||||
const toFromDifference = to - from;
|
||||
return toFromDifference === 0 ? 1 : (value - from) / toFromDifference;
|
||||
};
|
||||
|
||||
class SubscriptionManager {
|
||||
constructor() {
|
||||
this.subscriptions = [];
|
||||
}
|
||||
add(handler) {
|
||||
addUniqueItem(this.subscriptions, handler);
|
||||
return () => removeItem(this.subscriptions, handler);
|
||||
}
|
||||
notify(a, b, c) {
|
||||
const numSubscriptions = this.subscriptions.length;
|
||||
if (!numSubscriptions)
|
||||
return;
|
||||
if (numSubscriptions === 1) {
|
||||
/**
|
||||
* If there's only a single handler we can just call it without invoking a loop.
|
||||
*/
|
||||
this.subscriptions[0](a, b, c);
|
||||
}
|
||||
else {
|
||||
for (let i = 0; i < numSubscriptions; i++) {
|
||||
/**
|
||||
* Check whether the handler exists before firing as it's possible
|
||||
* the subscriptions were modified during this loop running.
|
||||
*/
|
||||
const handler = this.subscriptions[i];
|
||||
handler && handler(a, b, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
getSize() {
|
||||
return this.subscriptions.length;
|
||||
}
|
||||
clear() {
|
||||
this.subscriptions.length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts seconds to milliseconds
|
||||
*
|
||||
* @param seconds - Time in seconds.
|
||||
* @return milliseconds - Converted time in milliseconds.
|
||||
*/
|
||||
/*#__NO_SIDE_EFFECTS__*/
|
||||
const secondsToMilliseconds = (seconds) => seconds * 1000;
|
||||
/*#__NO_SIDE_EFFECTS__*/
|
||||
const millisecondsToSeconds = (milliseconds) => milliseconds / 1000;
|
||||
|
||||
/*
|
||||
Convert velocity into velocity per second
|
||||
|
||||
@param [number]: Unit per frame
|
||||
@param [number]: Frame duration in ms
|
||||
*/
|
||||
function velocityPerSecond(velocity, frameDuration) {
|
||||
return frameDuration ? velocity * (1000 / frameDuration) : 0;
|
||||
}
|
||||
|
||||
const warned = new Set();
|
||||
function hasWarned(message) {
|
||||
return warned.has(message);
|
||||
}
|
||||
function warnOnce(condition, message, errorCode) {
|
||||
if (condition || warned.has(message))
|
||||
return;
|
||||
console.warn(formatErrorMessage(message, errorCode));
|
||||
warned.add(message);
|
||||
}
|
||||
|
||||
const wrap = (min, max, v) => {
|
||||
const rangeSize = max - min;
|
||||
return ((((v - min) % rangeSize) + rangeSize) % rangeSize) + min;
|
||||
};
|
||||
|
||||
/*
|
||||
Bezier function generator
|
||||
This has been modified from Gaëtan Renaudeau's BezierEasing
|
||||
https://github.com/gre/bezier-easing/blob/master/src/index.js
|
||||
https://github.com/gre/bezier-easing/blob/master/LICENSE
|
||||
|
||||
I've removed the newtonRaphsonIterate algo because in benchmarking it
|
||||
wasn't noticeably faster than binarySubdivision, indeed removing it
|
||||
usually improved times, depending on the curve.
|
||||
I also removed the lookup table, as for the added bundle size and loop we're
|
||||
only cutting ~4 or so subdivision iterations. I bumped the max iterations up
|
||||
to 12 to compensate and this still tended to be faster for no perceivable
|
||||
loss in accuracy.
|
||||
Usage
|
||||
const easeOut = cubicBezier(.17,.67,.83,.67);
|
||||
const x = easeOut(0.5); // returns 0.627...
|
||||
*/
|
||||
// Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
|
||||
const calcBezier = (t, a1, a2) => (((1.0 - 3.0 * a2 + 3.0 * a1) * t + (3.0 * a2 - 6.0 * a1)) * t + 3.0 * a1) *
|
||||
t;
|
||||
const subdivisionPrecision = 0.0000001;
|
||||
const subdivisionMaxIterations = 12;
|
||||
function binarySubdivide(x, lowerBound, upperBound, mX1, mX2) {
|
||||
let currentX;
|
||||
let currentT;
|
||||
let i = 0;
|
||||
do {
|
||||
currentT = lowerBound + (upperBound - lowerBound) / 2.0;
|
||||
currentX = calcBezier(currentT, mX1, mX2) - x;
|
||||
if (currentX > 0.0) {
|
||||
upperBound = currentT;
|
||||
}
|
||||
else {
|
||||
lowerBound = currentT;
|
||||
}
|
||||
} while (Math.abs(currentX) > subdivisionPrecision &&
|
||||
++i < subdivisionMaxIterations);
|
||||
return currentT;
|
||||
}
|
||||
function cubicBezier(mX1, mY1, mX2, mY2) {
|
||||
// If this is a linear gradient, return linear easing
|
||||
if (mX1 === mY1 && mX2 === mY2)
|
||||
return noop;
|
||||
const getTForX = (aX) => binarySubdivide(aX, 0, 1, mX1, mX2);
|
||||
// If animation is at start/end, return t without easing
|
||||
return (t) => t === 0 || t === 1 ? t : calcBezier(getTForX(t), mY1, mY2);
|
||||
}
|
||||
|
||||
// Accepts an easing function and returns a new one that outputs mirrored values for
|
||||
// the second half of the animation. Turns easeIn into easeInOut.
|
||||
const mirrorEasing = (easing) => (p) => p <= 0.5 ? easing(2 * p) / 2 : (2 - easing(2 * (1 - p))) / 2;
|
||||
|
||||
// Accepts an easing function and returns a new one that outputs reversed values.
|
||||
// Turns easeIn into easeOut.
|
||||
const reverseEasing = (easing) => (p) => 1 - easing(1 - p);
|
||||
|
||||
const backOut = /*@__PURE__*/ cubicBezier(0.33, 1.53, 0.69, 0.99);
|
||||
const backIn = /*@__PURE__*/ reverseEasing(backOut);
|
||||
const backInOut = /*@__PURE__*/ mirrorEasing(backIn);
|
||||
|
||||
const anticipate = (p) => (p *= 2) < 1 ? 0.5 * backIn(p) : 0.5 * (2 - Math.pow(2, -10 * (p - 1)));
|
||||
|
||||
const circIn = (p) => 1 - Math.sin(Math.acos(p));
|
||||
const circOut = reverseEasing(circIn);
|
||||
const circInOut = mirrorEasing(circIn);
|
||||
|
||||
const easeIn = /*@__PURE__*/ cubicBezier(0.42, 0, 1, 1);
|
||||
const easeOut = /*@__PURE__*/ cubicBezier(0, 0, 0.58, 1);
|
||||
const easeInOut = /*@__PURE__*/ cubicBezier(0.42, 0, 0.58, 1);
|
||||
|
||||
function steps(numSteps, direction = "end") {
|
||||
return (progress) => {
|
||||
progress =
|
||||
direction === "end"
|
||||
? Math.min(progress, 0.999)
|
||||
: Math.max(progress, 0.001);
|
||||
const expanded = progress * numSteps;
|
||||
const rounded = direction === "end" ? Math.floor(expanded) : Math.ceil(expanded);
|
||||
return clamp(0, 1, rounded / numSteps);
|
||||
};
|
||||
}
|
||||
|
||||
const isEasingArray = (ease) => {
|
||||
return Array.isArray(ease) && typeof ease[0] !== "number";
|
||||
};
|
||||
|
||||
function getEasingForSegment(easing, i) {
|
||||
return isEasingArray(easing) ? easing[wrap(0, easing.length, i)] : easing;
|
||||
}
|
||||
|
||||
const isBezierDefinition = (easing) => Array.isArray(easing) && typeof easing[0] === "number";
|
||||
|
||||
const easingLookup = {
|
||||
linear: noop,
|
||||
easeIn,
|
||||
easeInOut,
|
||||
easeOut,
|
||||
circIn,
|
||||
circInOut,
|
||||
circOut,
|
||||
backIn,
|
||||
backInOut,
|
||||
backOut,
|
||||
anticipate,
|
||||
};
|
||||
const isValidEasing = (easing) => {
|
||||
return typeof easing === "string";
|
||||
};
|
||||
const easingDefinitionToFunction = (definition) => {
|
||||
if (isBezierDefinition(definition)) {
|
||||
// If cubic bezier definition, create bezier curve
|
||||
exports.invariant(definition.length === 4, `Cubic bezier arrays must contain four numerical values.`, "cubic-bezier-length");
|
||||
const [x1, y1, x2, y2] = definition;
|
||||
return cubicBezier(x1, y1, x2, y2);
|
||||
}
|
||||
else if (isValidEasing(definition)) {
|
||||
// Else lookup from table
|
||||
exports.invariant(easingLookup[definition] !== undefined, `Invalid easing type '${definition}'`, "invalid-easing-type");
|
||||
return easingLookup[definition];
|
||||
}
|
||||
return definition;
|
||||
};
|
||||
|
||||
exports.MotionGlobalConfig = MotionGlobalConfig;
|
||||
exports.SubscriptionManager = SubscriptionManager;
|
||||
exports.addUniqueItem = addUniqueItem;
|
||||
exports.anticipate = anticipate;
|
||||
exports.backIn = backIn;
|
||||
exports.backInOut = backInOut;
|
||||
exports.backOut = backOut;
|
||||
exports.circIn = circIn;
|
||||
exports.circInOut = circInOut;
|
||||
exports.circOut = circOut;
|
||||
exports.clamp = clamp;
|
||||
exports.cubicBezier = cubicBezier;
|
||||
exports.easeIn = easeIn;
|
||||
exports.easeInOut = easeInOut;
|
||||
exports.easeOut = easeOut;
|
||||
exports.easingDefinitionToFunction = easingDefinitionToFunction;
|
||||
exports.getEasingForSegment = getEasingForSegment;
|
||||
exports.hasWarned = hasWarned;
|
||||
exports.isBezierDefinition = isBezierDefinition;
|
||||
exports.isEasingArray = isEasingArray;
|
||||
exports.isNumericalString = isNumericalString;
|
||||
exports.isObject = isObject;
|
||||
exports.isZeroValueString = isZeroValueString;
|
||||
exports.memo = memo;
|
||||
exports.millisecondsToSeconds = millisecondsToSeconds;
|
||||
exports.mirrorEasing = mirrorEasing;
|
||||
exports.moveItem = moveItem;
|
||||
exports.noop = noop;
|
||||
exports.pipe = pipe;
|
||||
exports.progress = progress;
|
||||
exports.removeItem = removeItem;
|
||||
exports.reverseEasing = reverseEasing;
|
||||
exports.secondsToMilliseconds = secondsToMilliseconds;
|
||||
exports.steps = steps;
|
||||
exports.velocityPerSecond = velocityPerSecond;
|
||||
exports.warnOnce = warnOnce;
|
||||
exports.wrap = wrap;
|
||||
21
node_modules/motion-utils/dist/es/array.mjs
generated
vendored
Normal file
21
node_modules/motion-utils/dist/es/array.mjs
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
function addUniqueItem(arr, item) {
|
||||
if (arr.indexOf(item) === -1)
|
||||
arr.push(item);
|
||||
}
|
||||
function removeItem(arr, item) {
|
||||
const index = arr.indexOf(item);
|
||||
if (index > -1)
|
||||
arr.splice(index, 1);
|
||||
}
|
||||
// Adapted from array-move
|
||||
function moveItem([...arr], fromIndex, toIndex) {
|
||||
const startIndex = fromIndex < 0 ? arr.length + fromIndex : fromIndex;
|
||||
if (startIndex >= 0 && startIndex < arr.length) {
|
||||
const endIndex = toIndex < 0 ? arr.length + toIndex : toIndex;
|
||||
const [item] = arr.splice(fromIndex, 1);
|
||||
arr.splice(endIndex, 0, item);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
export { addUniqueItem, moveItem, removeItem };
|
||||
9
node_modules/motion-utils/dist/es/clamp.mjs
generated
vendored
Normal file
9
node_modules/motion-utils/dist/es/clamp.mjs
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
const clamp = (min, max, v) => {
|
||||
if (v > max)
|
||||
return max;
|
||||
if (v < min)
|
||||
return min;
|
||||
return v;
|
||||
};
|
||||
|
||||
export { clamp };
|
||||
5
node_modules/motion-utils/dist/es/easing/anticipate.mjs
generated
vendored
Normal file
5
node_modules/motion-utils/dist/es/easing/anticipate.mjs
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { backIn } from './back.mjs';
|
||||
|
||||
const anticipate = (p) => (p *= 2) < 1 ? 0.5 * backIn(p) : 0.5 * (2 - Math.pow(2, -10 * (p - 1)));
|
||||
|
||||
export { anticipate };
|
||||
9
node_modules/motion-utils/dist/es/easing/back.mjs
generated
vendored
Normal file
9
node_modules/motion-utils/dist/es/easing/back.mjs
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { cubicBezier } from './cubic-bezier.mjs';
|
||||
import { mirrorEasing } from './modifiers/mirror.mjs';
|
||||
import { reverseEasing } from './modifiers/reverse.mjs';
|
||||
|
||||
const backOut = /*@__PURE__*/ cubicBezier(0.33, 1.53, 0.69, 0.99);
|
||||
const backIn = /*@__PURE__*/ reverseEasing(backOut);
|
||||
const backInOut = /*@__PURE__*/ mirrorEasing(backIn);
|
||||
|
||||
export { backIn, backInOut, backOut };
|
||||
8
node_modules/motion-utils/dist/es/easing/circ.mjs
generated
vendored
Normal file
8
node_modules/motion-utils/dist/es/easing/circ.mjs
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { mirrorEasing } from './modifiers/mirror.mjs';
|
||||
import { reverseEasing } from './modifiers/reverse.mjs';
|
||||
|
||||
const circIn = (p) => 1 - Math.sin(Math.acos(p));
|
||||
const circOut = reverseEasing(circIn);
|
||||
const circInOut = mirrorEasing(circIn);
|
||||
|
||||
export { circIn, circInOut, circOut };
|
||||
51
node_modules/motion-utils/dist/es/easing/cubic-bezier.mjs
generated
vendored
Normal file
51
node_modules/motion-utils/dist/es/easing/cubic-bezier.mjs
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
import { noop } from '../noop.mjs';
|
||||
|
||||
/*
|
||||
Bezier function generator
|
||||
This has been modified from Gaëtan Renaudeau's BezierEasing
|
||||
https://github.com/gre/bezier-easing/blob/master/src/index.js
|
||||
https://github.com/gre/bezier-easing/blob/master/LICENSE
|
||||
|
||||
I've removed the newtonRaphsonIterate algo because in benchmarking it
|
||||
wasn't noticeably faster than binarySubdivision, indeed removing it
|
||||
usually improved times, depending on the curve.
|
||||
I also removed the lookup table, as for the added bundle size and loop we're
|
||||
only cutting ~4 or so subdivision iterations. I bumped the max iterations up
|
||||
to 12 to compensate and this still tended to be faster for no perceivable
|
||||
loss in accuracy.
|
||||
Usage
|
||||
const easeOut = cubicBezier(.17,.67,.83,.67);
|
||||
const x = easeOut(0.5); // returns 0.627...
|
||||
*/
|
||||
// Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
|
||||
const calcBezier = (t, a1, a2) => (((1.0 - 3.0 * a2 + 3.0 * a1) * t + (3.0 * a2 - 6.0 * a1)) * t + 3.0 * a1) *
|
||||
t;
|
||||
const subdivisionPrecision = 0.0000001;
|
||||
const subdivisionMaxIterations = 12;
|
||||
function binarySubdivide(x, lowerBound, upperBound, mX1, mX2) {
|
||||
let currentX;
|
||||
let currentT;
|
||||
let i = 0;
|
||||
do {
|
||||
currentT = lowerBound + (upperBound - lowerBound) / 2.0;
|
||||
currentX = calcBezier(currentT, mX1, mX2) - x;
|
||||
if (currentX > 0.0) {
|
||||
upperBound = currentT;
|
||||
}
|
||||
else {
|
||||
lowerBound = currentT;
|
||||
}
|
||||
} while (Math.abs(currentX) > subdivisionPrecision &&
|
||||
++i < subdivisionMaxIterations);
|
||||
return currentT;
|
||||
}
|
||||
function cubicBezier(mX1, mY1, mX2, mY2) {
|
||||
// If this is a linear gradient, return linear easing
|
||||
if (mX1 === mY1 && mX2 === mY2)
|
||||
return noop;
|
||||
const getTForX = (aX) => binarySubdivide(aX, 0, 1, mX1, mX2);
|
||||
// If animation is at start/end, return t without easing
|
||||
return (t) => t === 0 || t === 1 ? t : calcBezier(getTForX(t), mY1, mY2);
|
||||
}
|
||||
|
||||
export { cubicBezier };
|
||||
7
node_modules/motion-utils/dist/es/easing/ease.mjs
generated
vendored
Normal file
7
node_modules/motion-utils/dist/es/easing/ease.mjs
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { cubicBezier } from './cubic-bezier.mjs';
|
||||
|
||||
const easeIn = /*@__PURE__*/ cubicBezier(0.42, 0, 1, 1);
|
||||
const easeOut = /*@__PURE__*/ cubicBezier(0, 0, 0.58, 1);
|
||||
const easeInOut = /*@__PURE__*/ cubicBezier(0.42, 0, 0.58, 1);
|
||||
|
||||
export { easeIn, easeInOut, easeOut };
|
||||
5
node_modules/motion-utils/dist/es/easing/modifiers/mirror.mjs
generated
vendored
Normal file
5
node_modules/motion-utils/dist/es/easing/modifiers/mirror.mjs
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
// Accepts an easing function and returns a new one that outputs mirrored values for
|
||||
// the second half of the animation. Turns easeIn into easeInOut.
|
||||
const mirrorEasing = (easing) => (p) => p <= 0.5 ? easing(2 * p) / 2 : (2 - easing(2 * (1 - p))) / 2;
|
||||
|
||||
export { mirrorEasing };
|
||||
5
node_modules/motion-utils/dist/es/easing/modifiers/reverse.mjs
generated
vendored
Normal file
5
node_modules/motion-utils/dist/es/easing/modifiers/reverse.mjs
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
// Accepts an easing function and returns a new one that outputs reversed values.
|
||||
// Turns easeIn into easeOut.
|
||||
const reverseEasing = (easing) => (p) => 1 - easing(1 - p);
|
||||
|
||||
export { reverseEasing };
|
||||
15
node_modules/motion-utils/dist/es/easing/steps.mjs
generated
vendored
Normal file
15
node_modules/motion-utils/dist/es/easing/steps.mjs
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import { clamp } from '../clamp.mjs';
|
||||
|
||||
function steps(numSteps, direction = "end") {
|
||||
return (progress) => {
|
||||
progress =
|
||||
direction === "end"
|
||||
? Math.min(progress, 0.999)
|
||||
: Math.max(progress, 0.001);
|
||||
const expanded = progress * numSteps;
|
||||
const rounded = direction === "end" ? Math.floor(expanded) : Math.ceil(expanded);
|
||||
return clamp(0, 1, rounded / numSteps);
|
||||
};
|
||||
}
|
||||
|
||||
export { steps };
|
||||
8
node_modules/motion-utils/dist/es/easing/utils/get-easing-for-segment.mjs
generated
vendored
Normal file
8
node_modules/motion-utils/dist/es/easing/utils/get-easing-for-segment.mjs
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { wrap } from '../../wrap.mjs';
|
||||
import { isEasingArray } from './is-easing-array.mjs';
|
||||
|
||||
function getEasingForSegment(easing, i) {
|
||||
return isEasingArray(easing) ? easing[wrap(0, easing.length, i)] : easing;
|
||||
}
|
||||
|
||||
export { getEasingForSegment };
|
||||
3
node_modules/motion-utils/dist/es/easing/utils/is-bezier-definition.mjs
generated
vendored
Normal file
3
node_modules/motion-utils/dist/es/easing/utils/is-bezier-definition.mjs
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
const isBezierDefinition = (easing) => Array.isArray(easing) && typeof easing[0] === "number";
|
||||
|
||||
export { isBezierDefinition };
|
||||
5
node_modules/motion-utils/dist/es/easing/utils/is-easing-array.mjs
generated
vendored
Normal file
5
node_modules/motion-utils/dist/es/easing/utils/is-easing-array.mjs
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
const isEasingArray = (ease) => {
|
||||
return Array.isArray(ease) && typeof ease[0] !== "number";
|
||||
};
|
||||
|
||||
export { isEasingArray };
|
||||
41
node_modules/motion-utils/dist/es/easing/utils/map.mjs
generated
vendored
Normal file
41
node_modules/motion-utils/dist/es/easing/utils/map.mjs
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
import { invariant } from '../../errors.mjs';
|
||||
import { noop } from '../../noop.mjs';
|
||||
import { anticipate } from '../anticipate.mjs';
|
||||
import { backIn, backInOut, backOut } from '../back.mjs';
|
||||
import { circIn, circInOut, circOut } from '../circ.mjs';
|
||||
import { cubicBezier } from '../cubic-bezier.mjs';
|
||||
import { easeIn, easeInOut, easeOut } from '../ease.mjs';
|
||||
import { isBezierDefinition } from './is-bezier-definition.mjs';
|
||||
|
||||
const easingLookup = {
|
||||
linear: noop,
|
||||
easeIn,
|
||||
easeInOut,
|
||||
easeOut,
|
||||
circIn,
|
||||
circInOut,
|
||||
circOut,
|
||||
backIn,
|
||||
backInOut,
|
||||
backOut,
|
||||
anticipate,
|
||||
};
|
||||
const isValidEasing = (easing) => {
|
||||
return typeof easing === "string";
|
||||
};
|
||||
const easingDefinitionToFunction = (definition) => {
|
||||
if (isBezierDefinition(definition)) {
|
||||
// If cubic bezier definition, create bezier curve
|
||||
invariant(definition.length === 4, `Cubic bezier arrays must contain four numerical values.`, "cubic-bezier-length");
|
||||
const [x1, y1, x2, y2] = definition;
|
||||
return cubicBezier(x1, y1, x2, y2);
|
||||
}
|
||||
else if (isValidEasing(definition)) {
|
||||
// Else lookup from table
|
||||
invariant(easingLookup[definition] !== undefined, `Invalid easing type '${definition}'`, "invalid-easing-type");
|
||||
return easingLookup[definition];
|
||||
}
|
||||
return definition;
|
||||
};
|
||||
|
||||
export { easingDefinitionToFunction };
|
||||
18
node_modules/motion-utils/dist/es/errors.mjs
generated
vendored
Normal file
18
node_modules/motion-utils/dist/es/errors.mjs
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import { formatErrorMessage } from './format-error-message.mjs';
|
||||
|
||||
let warning = () => { };
|
||||
let invariant = () => { };
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
warning = (check, message, errorCode) => {
|
||||
if (!check && typeof console !== "undefined") {
|
||||
console.warn(formatErrorMessage(message, errorCode));
|
||||
}
|
||||
};
|
||||
invariant = (check, message, errorCode) => {
|
||||
if (!check) {
|
||||
throw new Error(formatErrorMessage(message, errorCode));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export { invariant, warning };
|
||||
7
node_modules/motion-utils/dist/es/format-error-message.mjs
generated
vendored
Normal file
7
node_modules/motion-utils/dist/es/format-error-message.mjs
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
function formatErrorMessage(message, errorCode) {
|
||||
return errorCode
|
||||
? `${message}. For more information and steps for solving, visit https://motion.dev/troubleshooting/${errorCode}`
|
||||
: message;
|
||||
}
|
||||
|
||||
export { formatErrorMessage };
|
||||
3
node_modules/motion-utils/dist/es/global-config.mjs
generated
vendored
Normal file
3
node_modules/motion-utils/dist/es/global-config.mjs
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
const MotionGlobalConfig = {};
|
||||
|
||||
export { MotionGlobalConfig };
|
||||
28
node_modules/motion-utils/dist/es/index.mjs
generated
vendored
Normal file
28
node_modules/motion-utils/dist/es/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
export { addUniqueItem, moveItem, removeItem } from './array.mjs';
|
||||
export { clamp } from './clamp.mjs';
|
||||
export { invariant, warning } from './errors.mjs';
|
||||
export { MotionGlobalConfig } from './global-config.mjs';
|
||||
export { isNumericalString } from './is-numerical-string.mjs';
|
||||
export { isObject } from './is-object.mjs';
|
||||
export { isZeroValueString } from './is-zero-value-string.mjs';
|
||||
export { memo } from './memo.mjs';
|
||||
export { noop } from './noop.mjs';
|
||||
export { pipe } from './pipe.mjs';
|
||||
export { progress } from './progress.mjs';
|
||||
export { SubscriptionManager } from './subscription-manager.mjs';
|
||||
export { millisecondsToSeconds, secondsToMilliseconds } from './time-conversion.mjs';
|
||||
export { velocityPerSecond } from './velocity-per-second.mjs';
|
||||
export { hasWarned, warnOnce } from './warn-once.mjs';
|
||||
export { wrap } from './wrap.mjs';
|
||||
export { anticipate } from './easing/anticipate.mjs';
|
||||
export { backIn, backInOut, backOut } from './easing/back.mjs';
|
||||
export { circIn, circInOut, circOut } from './easing/circ.mjs';
|
||||
export { cubicBezier } from './easing/cubic-bezier.mjs';
|
||||
export { easeIn, easeInOut, easeOut } from './easing/ease.mjs';
|
||||
export { mirrorEasing } from './easing/modifiers/mirror.mjs';
|
||||
export { reverseEasing } from './easing/modifiers/reverse.mjs';
|
||||
export { steps } from './easing/steps.mjs';
|
||||
export { getEasingForSegment } from './easing/utils/get-easing-for-segment.mjs';
|
||||
export { isBezierDefinition } from './easing/utils/is-bezier-definition.mjs';
|
||||
export { isEasingArray } from './easing/utils/is-easing-array.mjs';
|
||||
export { easingDefinitionToFunction } from './easing/utils/map.mjs';
|
||||
6
node_modules/motion-utils/dist/es/is-numerical-string.mjs
generated
vendored
Normal file
6
node_modules/motion-utils/dist/es/is-numerical-string.mjs
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Check if value is a numerical string, ie a string that is purely a number eg "100" or "-100.1"
|
||||
*/
|
||||
const isNumericalString = (v) => /^-?(?:\d+(?:\.\d+)?|\.\d+)$/u.test(v);
|
||||
|
||||
export { isNumericalString };
|
||||
5
node_modules/motion-utils/dist/es/is-object.mjs
generated
vendored
Normal file
5
node_modules/motion-utils/dist/es/is-object.mjs
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
function isObject(value) {
|
||||
return typeof value === "object" && value !== null;
|
||||
}
|
||||
|
||||
export { isObject };
|
||||
6
node_modules/motion-utils/dist/es/is-zero-value-string.mjs
generated
vendored
Normal file
6
node_modules/motion-utils/dist/es/is-zero-value-string.mjs
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Check if the value is a zero value string like "0px" or "0%"
|
||||
*/
|
||||
const isZeroValueString = (v) => /^0[^.\s]+$/u.test(v);
|
||||
|
||||
export { isZeroValueString };
|
||||
11
node_modules/motion-utils/dist/es/memo.mjs
generated
vendored
Normal file
11
node_modules/motion-utils/dist/es/memo.mjs
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
/*#__NO_SIDE_EFFECTS__*/
|
||||
function memo(callback) {
|
||||
let result;
|
||||
return () => {
|
||||
if (result === undefined)
|
||||
result = callback();
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
export { memo };
|
||||
4
node_modules/motion-utils/dist/es/noop.mjs
generated
vendored
Normal file
4
node_modules/motion-utils/dist/es/noop.mjs
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
/*#__NO_SIDE_EFFECTS__*/
|
||||
const noop = (any) => any;
|
||||
|
||||
export { noop };
|
||||
11
node_modules/motion-utils/dist/es/pipe.mjs
generated
vendored
Normal file
11
node_modules/motion-utils/dist/es/pipe.mjs
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Pipe
|
||||
* Compose other transformers to run linearily
|
||||
* pipe(min(20), max(40))
|
||||
* @param {...functions} transformers
|
||||
* @return {function}
|
||||
*/
|
||||
const combineFunctions = (a, b) => (v) => b(a(v));
|
||||
const pipe = (...transformers) => transformers.reduce(combineFunctions);
|
||||
|
||||
export { pipe };
|
||||
19
node_modules/motion-utils/dist/es/progress.mjs
generated
vendored
Normal file
19
node_modules/motion-utils/dist/es/progress.mjs
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
Progress within given range
|
||||
|
||||
Given a lower limit and an upper limit, we return the progress
|
||||
(expressed as a number 0-1) represented by the given value, and
|
||||
limit that progress to within 0-1.
|
||||
|
||||
@param [number]: Lower limit
|
||||
@param [number]: Upper limit
|
||||
@param [number]: Value to find progress within given range
|
||||
@return [number]: Progress of value within range as expressed 0-1
|
||||
*/
|
||||
/*#__NO_SIDE_EFFECTS__*/
|
||||
const progress = (from, to, value) => {
|
||||
const toFromDifference = to - from;
|
||||
return toFromDifference === 0 ? 1 : (value - from) / toFromDifference;
|
||||
};
|
||||
|
||||
export { progress };
|
||||
40
node_modules/motion-utils/dist/es/subscription-manager.mjs
generated
vendored
Normal file
40
node_modules/motion-utils/dist/es/subscription-manager.mjs
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import { addUniqueItem, removeItem } from './array.mjs';
|
||||
|
||||
class SubscriptionManager {
|
||||
constructor() {
|
||||
this.subscriptions = [];
|
||||
}
|
||||
add(handler) {
|
||||
addUniqueItem(this.subscriptions, handler);
|
||||
return () => removeItem(this.subscriptions, handler);
|
||||
}
|
||||
notify(a, b, c) {
|
||||
const numSubscriptions = this.subscriptions.length;
|
||||
if (!numSubscriptions)
|
||||
return;
|
||||
if (numSubscriptions === 1) {
|
||||
/**
|
||||
* If there's only a single handler we can just call it without invoking a loop.
|
||||
*/
|
||||
this.subscriptions[0](a, b, c);
|
||||
}
|
||||
else {
|
||||
for (let i = 0; i < numSubscriptions; i++) {
|
||||
/**
|
||||
* Check whether the handler exists before firing as it's possible
|
||||
* the subscriptions were modified during this loop running.
|
||||
*/
|
||||
const handler = this.subscriptions[i];
|
||||
handler && handler(a, b, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
getSize() {
|
||||
return this.subscriptions.length;
|
||||
}
|
||||
clear() {
|
||||
this.subscriptions.length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
export { SubscriptionManager };
|
||||
12
node_modules/motion-utils/dist/es/time-conversion.mjs
generated
vendored
Normal file
12
node_modules/motion-utils/dist/es/time-conversion.mjs
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Converts seconds to milliseconds
|
||||
*
|
||||
* @param seconds - Time in seconds.
|
||||
* @return milliseconds - Converted time in milliseconds.
|
||||
*/
|
||||
/*#__NO_SIDE_EFFECTS__*/
|
||||
const secondsToMilliseconds = (seconds) => seconds * 1000;
|
||||
/*#__NO_SIDE_EFFECTS__*/
|
||||
const millisecondsToSeconds = (milliseconds) => milliseconds / 1000;
|
||||
|
||||
export { millisecondsToSeconds, secondsToMilliseconds };
|
||||
11
node_modules/motion-utils/dist/es/velocity-per-second.mjs
generated
vendored
Normal file
11
node_modules/motion-utils/dist/es/velocity-per-second.mjs
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
Convert velocity into velocity per second
|
||||
|
||||
@param [number]: Unit per frame
|
||||
@param [number]: Frame duration in ms
|
||||
*/
|
||||
function velocityPerSecond(velocity, frameDuration) {
|
||||
return frameDuration ? velocity * (1000 / frameDuration) : 0;
|
||||
}
|
||||
|
||||
export { velocityPerSecond };
|
||||
14
node_modules/motion-utils/dist/es/warn-once.mjs
generated
vendored
Normal file
14
node_modules/motion-utils/dist/es/warn-once.mjs
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import { formatErrorMessage } from './format-error-message.mjs';
|
||||
|
||||
const warned = new Set();
|
||||
function hasWarned(message) {
|
||||
return warned.has(message);
|
||||
}
|
||||
function warnOnce(condition, message, errorCode) {
|
||||
if (condition || warned.has(message))
|
||||
return;
|
||||
console.warn(formatErrorMessage(message, errorCode));
|
||||
warned.add(message);
|
||||
}
|
||||
|
||||
export { hasWarned, warnOnce };
|
||||
6
node_modules/motion-utils/dist/es/wrap.mjs
generated
vendored
Normal file
6
node_modules/motion-utils/dist/es/wrap.mjs
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
const wrap = (min, max, v) => {
|
||||
const rangeSize = max - min;
|
||||
return ((((v - min) % rangeSize) + rangeSize) % rangeSize) + min;
|
||||
};
|
||||
|
||||
export { wrap };
|
||||
140
node_modules/motion-utils/dist/index.d.ts
generated
vendored
Normal file
140
node_modules/motion-utils/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
declare function addUniqueItem<T>(arr: T[], item: T): void;
|
||||
declare function removeItem<T>(arr: T[], item: T): void;
|
||||
declare function moveItem<T>([...arr]: T[], fromIndex: number, toIndex: number): T[];
|
||||
|
||||
declare const clamp: (min: number, max: number, v: number) => number;
|
||||
|
||||
type DevMessage = (check: boolean, message: string, errorCode?: string) => void;
|
||||
declare let warning: DevMessage;
|
||||
declare let invariant: DevMessage;
|
||||
|
||||
declare const MotionGlobalConfig: {
|
||||
skipAnimations?: boolean;
|
||||
instantAnimations?: boolean;
|
||||
useManualTiming?: boolean;
|
||||
WillChange?: any;
|
||||
mix?: <T>(a: T, b: T) => (p: number) => T;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if value is a numerical string, ie a string that is purely a number eg "100" or "-100.1"
|
||||
*/
|
||||
declare const isNumericalString: (v: string) => boolean;
|
||||
|
||||
declare function isObject(value: unknown): value is object;
|
||||
|
||||
/**
|
||||
* Check if the value is a zero value string like "0px" or "0%"
|
||||
*/
|
||||
declare const isZeroValueString: (v: string) => boolean;
|
||||
|
||||
declare function memo<T extends any>(callback: () => T): () => T;
|
||||
|
||||
declare const noop: <T>(any: T) => T;
|
||||
|
||||
declare const pipe: (...transformers: Function[]) => Function;
|
||||
|
||||
declare const progress: (from: number, to: number, value: number) => number;
|
||||
|
||||
type GenericHandler = (...args: any) => void;
|
||||
declare class SubscriptionManager<Handler extends GenericHandler> {
|
||||
private subscriptions;
|
||||
add(handler: Handler): VoidFunction;
|
||||
notify(a?: Parameters<Handler>[0], b?: Parameters<Handler>[1], c?: Parameters<Handler>[2]): void;
|
||||
getSize(): number;
|
||||
clear(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts seconds to milliseconds
|
||||
*
|
||||
* @param seconds - Time in seconds.
|
||||
* @return milliseconds - Converted time in milliseconds.
|
||||
*/
|
||||
declare const secondsToMilliseconds: (seconds: number) => number;
|
||||
declare const millisecondsToSeconds: (milliseconds: number) => number;
|
||||
|
||||
declare function velocityPerSecond(velocity: number, frameDuration: number): number;
|
||||
|
||||
declare function hasWarned(message: string): boolean;
|
||||
declare function warnOnce(condition: boolean, message: string, errorCode?: string): void;
|
||||
|
||||
declare const wrap: (min: number, max: number, v: number) => number;
|
||||
|
||||
declare const anticipate: (p: number) => number;
|
||||
|
||||
declare const backOut: (t: number) => number;
|
||||
declare const backIn: EasingFunction;
|
||||
declare const backInOut: EasingFunction;
|
||||
|
||||
type EasingFunction = (v: number) => number;
|
||||
type EasingModifier = (easing: EasingFunction) => EasingFunction;
|
||||
type BezierDefinition = readonly [number, number, number, number];
|
||||
type EasingDefinition = BezierDefinition | "linear" | "easeIn" | "easeOut" | "easeInOut" | "circIn" | "circOut" | "circInOut" | "backIn" | "backOut" | "backInOut" | "anticipate";
|
||||
/**
|
||||
* The easing function to use. Set as one of:
|
||||
*
|
||||
* - The name of an in-built easing function.
|
||||
* - An array of four numbers to define a cubic bezier curve.
|
||||
* - An easing function, that accepts and returns a progress value between `0` and `1`.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
type Easing = EasingDefinition | EasingFunction;
|
||||
|
||||
declare const circIn: EasingFunction;
|
||||
declare const circOut: EasingFunction;
|
||||
declare const circInOut: EasingFunction;
|
||||
|
||||
declare function cubicBezier(mX1: number, mY1: number, mX2: number, mY2: number): (t: number) => number;
|
||||
|
||||
declare const easeIn: (t: number) => number;
|
||||
declare const easeOut: (t: number) => number;
|
||||
declare const easeInOut: (t: number) => number;
|
||||
|
||||
declare const mirrorEasing: EasingModifier;
|
||||
|
||||
declare const reverseEasing: EasingModifier;
|
||||
|
||||
type Direction = "start" | "end";
|
||||
declare function steps(numSteps: number, direction?: Direction): EasingFunction;
|
||||
|
||||
declare function getEasingForSegment(easing: Easing | Easing[], i: number): Easing;
|
||||
|
||||
declare const isBezierDefinition: (easing: Easing | Easing[]) => easing is BezierDefinition;
|
||||
|
||||
declare const isEasingArray: (ease: any) => ease is Easing[];
|
||||
|
||||
declare const easingDefinitionToFunction: (definition: Easing) => EasingFunction;
|
||||
|
||||
interface Point {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
interface Axis {
|
||||
min: number;
|
||||
max: number;
|
||||
}
|
||||
interface Box {
|
||||
x: Axis;
|
||||
y: Axis;
|
||||
}
|
||||
interface BoundingBox {
|
||||
top: number;
|
||||
right: number;
|
||||
bottom: number;
|
||||
left: number;
|
||||
}
|
||||
interface AxisDelta {
|
||||
translate: number;
|
||||
scale: number;
|
||||
origin: number;
|
||||
originPoint: number;
|
||||
}
|
||||
interface Delta {
|
||||
x: AxisDelta;
|
||||
y: AxisDelta;
|
||||
}
|
||||
type TransformPoint = (point: Point) => Point;
|
||||
|
||||
export { type Axis, type AxisDelta, type BezierDefinition, type BoundingBox, type Box, type Delta, type DevMessage, type Direction, type Easing, type EasingDefinition, type EasingFunction, type EasingModifier, MotionGlobalConfig, type Point, SubscriptionManager, type TransformPoint, addUniqueItem, anticipate, backIn, backInOut, backOut, circIn, circInOut, circOut, clamp, cubicBezier, easeIn, easeInOut, easeOut, easingDefinitionToFunction, getEasingForSegment, hasWarned, invariant, isBezierDefinition, isEasingArray, isNumericalString, isObject, isZeroValueString, memo, millisecondsToSeconds, mirrorEasing, moveItem, noop, pipe, progress, removeItem, reverseEasing, secondsToMilliseconds, steps, velocityPerSecond, warnOnce, warning, wrap };
|
||||
348
node_modules/motion-utils/dist/motion-utils.dev.js
generated
vendored
Normal file
348
node_modules/motion-utils/dist/motion-utils.dev.js
generated
vendored
Normal file
@@ -0,0 +1,348 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
||||
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MotionUtils = {}));
|
||||
})(this, (function (exports) { 'use strict';
|
||||
|
||||
function addUniqueItem(arr, item) {
|
||||
if (arr.indexOf(item) === -1)
|
||||
arr.push(item);
|
||||
}
|
||||
function removeItem(arr, item) {
|
||||
const index = arr.indexOf(item);
|
||||
if (index > -1)
|
||||
arr.splice(index, 1);
|
||||
}
|
||||
// Adapted from array-move
|
||||
function moveItem([...arr], fromIndex, toIndex) {
|
||||
const startIndex = fromIndex < 0 ? arr.length + fromIndex : fromIndex;
|
||||
if (startIndex >= 0 && startIndex < arr.length) {
|
||||
const endIndex = toIndex < 0 ? arr.length + toIndex : toIndex;
|
||||
const [item] = arr.splice(fromIndex, 1);
|
||||
arr.splice(endIndex, 0, item);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
const clamp = (min, max, v) => {
|
||||
if (v > max)
|
||||
return max;
|
||||
if (v < min)
|
||||
return min;
|
||||
return v;
|
||||
};
|
||||
|
||||
function formatErrorMessage(message, errorCode) {
|
||||
return errorCode
|
||||
? `${message}. For more information and steps for solving, visit https://motion.dev/troubleshooting/${errorCode}`
|
||||
: message;
|
||||
}
|
||||
|
||||
exports.warning = () => { };
|
||||
exports.invariant = () => { };
|
||||
{
|
||||
exports.warning = (check, message, errorCode) => {
|
||||
if (!check && typeof console !== "undefined") {
|
||||
console.warn(formatErrorMessage(message, errorCode));
|
||||
}
|
||||
};
|
||||
exports.invariant = (check, message, errorCode) => {
|
||||
if (!check) {
|
||||
throw new Error(formatErrorMessage(message, errorCode));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const MotionGlobalConfig = {};
|
||||
|
||||
/**
|
||||
* Check if value is a numerical string, ie a string that is purely a number eg "100" or "-100.1"
|
||||
*/
|
||||
const isNumericalString = (v) => /^-?(?:\d+(?:\.\d+)?|\.\d+)$/u.test(v);
|
||||
|
||||
function isObject(value) {
|
||||
return typeof value === "object" && value !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the value is a zero value string like "0px" or "0%"
|
||||
*/
|
||||
const isZeroValueString = (v) => /^0[^.\s]+$/u.test(v);
|
||||
|
||||
/*#__NO_SIDE_EFFECTS__*/
|
||||
function memo(callback) {
|
||||
let result;
|
||||
return () => {
|
||||
if (result === undefined)
|
||||
result = callback();
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
/*#__NO_SIDE_EFFECTS__*/
|
||||
const noop = (any) => any;
|
||||
|
||||
/**
|
||||
* Pipe
|
||||
* Compose other transformers to run linearily
|
||||
* pipe(min(20), max(40))
|
||||
* @param {...functions} transformers
|
||||
* @return {function}
|
||||
*/
|
||||
const combineFunctions = (a, b) => (v) => b(a(v));
|
||||
const pipe = (...transformers) => transformers.reduce(combineFunctions);
|
||||
|
||||
/*
|
||||
Progress within given range
|
||||
|
||||
Given a lower limit and an upper limit, we return the progress
|
||||
(expressed as a number 0-1) represented by the given value, and
|
||||
limit that progress to within 0-1.
|
||||
|
||||
@param [number]: Lower limit
|
||||
@param [number]: Upper limit
|
||||
@param [number]: Value to find progress within given range
|
||||
@return [number]: Progress of value within range as expressed 0-1
|
||||
*/
|
||||
/*#__NO_SIDE_EFFECTS__*/
|
||||
const progress = (from, to, value) => {
|
||||
const toFromDifference = to - from;
|
||||
return toFromDifference === 0 ? 1 : (value - from) / toFromDifference;
|
||||
};
|
||||
|
||||
class SubscriptionManager {
|
||||
constructor() {
|
||||
this.subscriptions = [];
|
||||
}
|
||||
add(handler) {
|
||||
addUniqueItem(this.subscriptions, handler);
|
||||
return () => removeItem(this.subscriptions, handler);
|
||||
}
|
||||
notify(a, b, c) {
|
||||
const numSubscriptions = this.subscriptions.length;
|
||||
if (!numSubscriptions)
|
||||
return;
|
||||
if (numSubscriptions === 1) {
|
||||
/**
|
||||
* If there's only a single handler we can just call it without invoking a loop.
|
||||
*/
|
||||
this.subscriptions[0](a, b, c);
|
||||
}
|
||||
else {
|
||||
for (let i = 0; i < numSubscriptions; i++) {
|
||||
/**
|
||||
* Check whether the handler exists before firing as it's possible
|
||||
* the subscriptions were modified during this loop running.
|
||||
*/
|
||||
const handler = this.subscriptions[i];
|
||||
handler && handler(a, b, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
getSize() {
|
||||
return this.subscriptions.length;
|
||||
}
|
||||
clear() {
|
||||
this.subscriptions.length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts seconds to milliseconds
|
||||
*
|
||||
* @param seconds - Time in seconds.
|
||||
* @return milliseconds - Converted time in milliseconds.
|
||||
*/
|
||||
/*#__NO_SIDE_EFFECTS__*/
|
||||
const secondsToMilliseconds = (seconds) => seconds * 1000;
|
||||
/*#__NO_SIDE_EFFECTS__*/
|
||||
const millisecondsToSeconds = (milliseconds) => milliseconds / 1000;
|
||||
|
||||
/*
|
||||
Convert velocity into velocity per second
|
||||
|
||||
@param [number]: Unit per frame
|
||||
@param [number]: Frame duration in ms
|
||||
*/
|
||||
function velocityPerSecond(velocity, frameDuration) {
|
||||
return frameDuration ? velocity * (1000 / frameDuration) : 0;
|
||||
}
|
||||
|
||||
const warned = new Set();
|
||||
function hasWarned(message) {
|
||||
return warned.has(message);
|
||||
}
|
||||
function warnOnce(condition, message, errorCode) {
|
||||
if (condition || warned.has(message))
|
||||
return;
|
||||
console.warn(formatErrorMessage(message, errorCode));
|
||||
warned.add(message);
|
||||
}
|
||||
|
||||
const wrap = (min, max, v) => {
|
||||
const rangeSize = max - min;
|
||||
return ((((v - min) % rangeSize) + rangeSize) % rangeSize) + min;
|
||||
};
|
||||
|
||||
/*
|
||||
Bezier function generator
|
||||
This has been modified from Gaëtan Renaudeau's BezierEasing
|
||||
https://github.com/gre/bezier-easing/blob/master/src/index.js
|
||||
https://github.com/gre/bezier-easing/blob/master/LICENSE
|
||||
|
||||
I've removed the newtonRaphsonIterate algo because in benchmarking it
|
||||
wasn't noticeably faster than binarySubdivision, indeed removing it
|
||||
usually improved times, depending on the curve.
|
||||
I also removed the lookup table, as for the added bundle size and loop we're
|
||||
only cutting ~4 or so subdivision iterations. I bumped the max iterations up
|
||||
to 12 to compensate and this still tended to be faster for no perceivable
|
||||
loss in accuracy.
|
||||
Usage
|
||||
const easeOut = cubicBezier(.17,.67,.83,.67);
|
||||
const x = easeOut(0.5); // returns 0.627...
|
||||
*/
|
||||
// Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
|
||||
const calcBezier = (t, a1, a2) => (((1.0 - 3.0 * a2 + 3.0 * a1) * t + (3.0 * a2 - 6.0 * a1)) * t + 3.0 * a1) *
|
||||
t;
|
||||
const subdivisionPrecision = 0.0000001;
|
||||
const subdivisionMaxIterations = 12;
|
||||
function binarySubdivide(x, lowerBound, upperBound, mX1, mX2) {
|
||||
let currentX;
|
||||
let currentT;
|
||||
let i = 0;
|
||||
do {
|
||||
currentT = lowerBound + (upperBound - lowerBound) / 2.0;
|
||||
currentX = calcBezier(currentT, mX1, mX2) - x;
|
||||
if (currentX > 0.0) {
|
||||
upperBound = currentT;
|
||||
}
|
||||
else {
|
||||
lowerBound = currentT;
|
||||
}
|
||||
} while (Math.abs(currentX) > subdivisionPrecision &&
|
||||
++i < subdivisionMaxIterations);
|
||||
return currentT;
|
||||
}
|
||||
function cubicBezier(mX1, mY1, mX2, mY2) {
|
||||
// If this is a linear gradient, return linear easing
|
||||
if (mX1 === mY1 && mX2 === mY2)
|
||||
return noop;
|
||||
const getTForX = (aX) => binarySubdivide(aX, 0, 1, mX1, mX2);
|
||||
// If animation is at start/end, return t without easing
|
||||
return (t) => t === 0 || t === 1 ? t : calcBezier(getTForX(t), mY1, mY2);
|
||||
}
|
||||
|
||||
// Accepts an easing function and returns a new one that outputs mirrored values for
|
||||
// the second half of the animation. Turns easeIn into easeInOut.
|
||||
const mirrorEasing = (easing) => (p) => p <= 0.5 ? easing(2 * p) / 2 : (2 - easing(2 * (1 - p))) / 2;
|
||||
|
||||
// Accepts an easing function and returns a new one that outputs reversed values.
|
||||
// Turns easeIn into easeOut.
|
||||
const reverseEasing = (easing) => (p) => 1 - easing(1 - p);
|
||||
|
||||
const backOut = /*@__PURE__*/ cubicBezier(0.33, 1.53, 0.69, 0.99);
|
||||
const backIn = /*@__PURE__*/ reverseEasing(backOut);
|
||||
const backInOut = /*@__PURE__*/ mirrorEasing(backIn);
|
||||
|
||||
const anticipate = (p) => (p *= 2) < 1 ? 0.5 * backIn(p) : 0.5 * (2 - Math.pow(2, -10 * (p - 1)));
|
||||
|
||||
const circIn = (p) => 1 - Math.sin(Math.acos(p));
|
||||
const circOut = reverseEasing(circIn);
|
||||
const circInOut = mirrorEasing(circIn);
|
||||
|
||||
const easeIn = /*@__PURE__*/ cubicBezier(0.42, 0, 1, 1);
|
||||
const easeOut = /*@__PURE__*/ cubicBezier(0, 0, 0.58, 1);
|
||||
const easeInOut = /*@__PURE__*/ cubicBezier(0.42, 0, 0.58, 1);
|
||||
|
||||
function steps(numSteps, direction = "end") {
|
||||
return (progress) => {
|
||||
progress =
|
||||
direction === "end"
|
||||
? Math.min(progress, 0.999)
|
||||
: Math.max(progress, 0.001);
|
||||
const expanded = progress * numSteps;
|
||||
const rounded = direction === "end" ? Math.floor(expanded) : Math.ceil(expanded);
|
||||
return clamp(0, 1, rounded / numSteps);
|
||||
};
|
||||
}
|
||||
|
||||
const isEasingArray = (ease) => {
|
||||
return Array.isArray(ease) && typeof ease[0] !== "number";
|
||||
};
|
||||
|
||||
function getEasingForSegment(easing, i) {
|
||||
return isEasingArray(easing) ? easing[wrap(0, easing.length, i)] : easing;
|
||||
}
|
||||
|
||||
const isBezierDefinition = (easing) => Array.isArray(easing) && typeof easing[0] === "number";
|
||||
|
||||
const easingLookup = {
|
||||
linear: noop,
|
||||
easeIn,
|
||||
easeInOut,
|
||||
easeOut,
|
||||
circIn,
|
||||
circInOut,
|
||||
circOut,
|
||||
backIn,
|
||||
backInOut,
|
||||
backOut,
|
||||
anticipate,
|
||||
};
|
||||
const isValidEasing = (easing) => {
|
||||
return typeof easing === "string";
|
||||
};
|
||||
const easingDefinitionToFunction = (definition) => {
|
||||
if (isBezierDefinition(definition)) {
|
||||
// If cubic bezier definition, create bezier curve
|
||||
exports.invariant(definition.length === 4, `Cubic bezier arrays must contain four numerical values.`, "cubic-bezier-length");
|
||||
const [x1, y1, x2, y2] = definition;
|
||||
return cubicBezier(x1, y1, x2, y2);
|
||||
}
|
||||
else if (isValidEasing(definition)) {
|
||||
// Else lookup from table
|
||||
exports.invariant(easingLookup[definition] !== undefined, `Invalid easing type '${definition}'`, "invalid-easing-type");
|
||||
return easingLookup[definition];
|
||||
}
|
||||
return definition;
|
||||
};
|
||||
|
||||
exports.MotionGlobalConfig = MotionGlobalConfig;
|
||||
exports.SubscriptionManager = SubscriptionManager;
|
||||
exports.addUniqueItem = addUniqueItem;
|
||||
exports.anticipate = anticipate;
|
||||
exports.backIn = backIn;
|
||||
exports.backInOut = backInOut;
|
||||
exports.backOut = backOut;
|
||||
exports.circIn = circIn;
|
||||
exports.circInOut = circInOut;
|
||||
exports.circOut = circOut;
|
||||
exports.clamp = clamp;
|
||||
exports.cubicBezier = cubicBezier;
|
||||
exports.easeIn = easeIn;
|
||||
exports.easeInOut = easeInOut;
|
||||
exports.easeOut = easeOut;
|
||||
exports.easingDefinitionToFunction = easingDefinitionToFunction;
|
||||
exports.getEasingForSegment = getEasingForSegment;
|
||||
exports.hasWarned = hasWarned;
|
||||
exports.isBezierDefinition = isBezierDefinition;
|
||||
exports.isEasingArray = isEasingArray;
|
||||
exports.isNumericalString = isNumericalString;
|
||||
exports.isObject = isObject;
|
||||
exports.isZeroValueString = isZeroValueString;
|
||||
exports.memo = memo;
|
||||
exports.millisecondsToSeconds = millisecondsToSeconds;
|
||||
exports.mirrorEasing = mirrorEasing;
|
||||
exports.moveItem = moveItem;
|
||||
exports.noop = noop;
|
||||
exports.pipe = pipe;
|
||||
exports.progress = progress;
|
||||
exports.removeItem = removeItem;
|
||||
exports.reverseEasing = reverseEasing;
|
||||
exports.secondsToMilliseconds = secondsToMilliseconds;
|
||||
exports.steps = steps;
|
||||
exports.velocityPerSecond = velocityPerSecond;
|
||||
exports.warnOnce = warnOnce;
|
||||
exports.wrap = wrap;
|
||||
|
||||
}));
|
||||
1
node_modules/motion-utils/dist/motion-utils.js
generated
vendored
Normal file
1
node_modules/motion-utils/dist/motion-utils.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).MotionUtils={})}(this,function(n){"use strict";function t(n,t){-1===n.indexOf(t)&&n.push(t)}function e(n,t){const e=n.indexOf(t);e>-1&&n.splice(e,1)}const i=(n,t,e)=>e>t?t:e<n?n:e;let s=()=>{};const o=n=>n,r=(n,t)=>e=>t(n(e));const c=new Set;const u=(n,t,e)=>{const i=t-n;return((e-n)%i+i)%i+n},a=(n,t,e)=>(((1-3*e+3*t)*n+(3*e-6*t))*n+3*t)*n;function f(n,t,e,i){if(n===t&&e===i)return o;const s=t=>function(n,t,e,i,s){let o,r,c=0;do{r=t+(e-t)/2,o=a(r,i,s)-n,o>0?e=r:t=r}while(Math.abs(o)>1e-7&&++c<12);return r}(t,0,1,n,e);return n=>0===n||1===n?n:a(s(n),t,i)}const l=n=>t=>t<=.5?n(2*t)/2:(2-n(2*(1-t)))/2,p=n=>t=>1-n(1-t),d=f(.33,1.53,.69,.99),h=p(d),g=l(h),b=n=>(n*=2)<1?.5*h(n):.5*(2-Math.pow(2,-10*(n-1))),m=n=>1-Math.sin(Math.acos(n)),O=p(m),y=l(m),I=f(.42,0,1,1),M=f(0,0,.58,1),v=f(.42,0,.58,1);const S=n=>Array.isArray(n)&&"number"!=typeof n[0];const w=n=>Array.isArray(n)&&"number"==typeof n[0],k={linear:o,easeIn:I,easeInOut:v,easeOut:M,circIn:m,circInOut:y,circOut:O,backIn:h,backInOut:g,backOut:d,anticipate:b};n.MotionGlobalConfig={},n.SubscriptionManager=class{constructor(){this.subscriptions=[]}add(n){return t(this.subscriptions,n),()=>e(this.subscriptions,n)}notify(n,t,e){const i=this.subscriptions.length;if(i)if(1===i)this.subscriptions[0](n,t,e);else for(let s=0;s<i;s++){const i=this.subscriptions[s];i&&i(n,t,e)}}getSize(){return this.subscriptions.length}clear(){this.subscriptions.length=0}},n.addUniqueItem=t,n.anticipate=b,n.backIn=h,n.backInOut=g,n.backOut=d,n.circIn=m,n.circInOut=y,n.circOut=O,n.clamp=i,n.cubicBezier=f,n.easeIn=I,n.easeInOut=v,n.easeOut=M,n.easingDefinitionToFunction=n=>{if(w(n)){n.length;const[t,e,i,s]=n;return f(t,e,i,s)}return"string"==typeof n?k[n]:n},n.getEasingForSegment=function(n,t){return S(n)?n[u(0,n.length,t)]:n},n.hasWarned=function(n){return c.has(n)},n.invariant=s,n.isBezierDefinition=w,n.isEasingArray=S,n.isNumericalString=n=>/^-?(?:\d+(?:\.\d+)?|\.\d+)$/u.test(n),n.isObject=function(n){return"object"==typeof n&&null!==n},n.isZeroValueString=n=>/^0[^.\s]+$/u.test(n),n.memo=function(n){let t;return()=>(void 0===t&&(t=n()),t)},n.millisecondsToSeconds=n=>n/1e3,n.mirrorEasing=l,n.moveItem=function([...n],t,e){const i=t<0?n.length+t:t;if(i>=0&&i<n.length){const i=e<0?n.length+e:e,[s]=n.splice(t,1);n.splice(i,0,s)}return n},n.noop=o,n.pipe=(...n)=>n.reduce(r),n.progress=(n,t,e)=>{const i=t-n;return 0===i?1:(e-n)/i},n.removeItem=e,n.reverseEasing=p,n.secondsToMilliseconds=n=>1e3*n,n.steps=function(n,t="end"){return e=>{const s=(e="end"===t?Math.min(e,.999):Math.max(e,.001))*n,o="end"===t?Math.floor(s):Math.ceil(s);return i(0,1,o/n)}},n.velocityPerSecond=function(n,t){return t?n*(1e3/t):0},n.warnOnce=function(n,t,e){n||c.has(t)||(console.warn(function(n,t){return t?`${n}. For more information and steps for solving, visit https://motion.dev/troubleshooting/${t}`:n}(t,e)),c.add(t))},n.warning=()=>{},n.wrap=u});
|
||||
26
node_modules/motion-utils/package.json
generated
vendored
Normal file
26
node_modules/motion-utils/package.json
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "motion-utils",
|
||||
"version": "12.23.6",
|
||||
"author": "Matt Perry",
|
||||
"license": "MIT",
|
||||
"repository": "https://github.com/motiondivision/motion",
|
||||
"main": "./dist/cjs/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"module": "./dist/es/index.mjs",
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"require": "./dist/cjs/index.js",
|
||||
"import": "./dist/es/index.mjs",
|
||||
"default": "./dist/cjs/index.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rm -rf types dist lib",
|
||||
"build": "yarn clean && tsc -p . && rollup -c",
|
||||
"dev": "concurrently -c blue,red -n tsc,rollup --kill-others \"tsc --watch -p . --preserveWatchOutput\" \"rollup --config --watch --no-watch.clearScreen\"",
|
||||
"test": "jest --config jest.config.json --max-workers=2"
|
||||
},
|
||||
"gitHead": "74a4413a8f545898109a0cf6aa4f763643972974"
|
||||
}
|
||||
Reference in New Issue
Block a user