svelte-motion
Version:
Svelte animation library based on the React library framer-motion.
74 lines (71 loc) • 2.05 kB
JavaScript
/**
based on framer-motion@4.1.15,
Copyright (c) 2018 Framer B.V.
*/
import { noop } from '../noop.js';
/**
* Bounding boxes tend to be defined as top, left, right, bottom. For various operations
* it's easier to consider each axis individually. This function returns a bounding box
* as a map of single-axis min/max values.
*/
function convertBoundingBoxToAxisBox(_a) {
var top = _a.top, left = _a.left, right = _a.right, bottom = _a.bottom;
return {
x: { min: left, max: right },
y: { min: top, max: bottom },
};
}
function convertAxisBoxToBoundingBox(_a) {
var x = _a.x, y = _a.y;
return {
top: y.min,
bottom: y.max,
left: x.min,
right: x.max,
};
}
/**
* Applies a TransformPoint function to a bounding box. TransformPoint is usually a function
* provided by Framer to allow measured points to be corrected for device scaling. This is used
* when measuring DOM elements and DOM event points.
*/
function transformBoundingBox(_a, transformPoint) {
var top = _a.top, left = _a.left, bottom = _a.bottom, right = _a.right;
if (transformPoint === void 0) { transformPoint = noop; }
var topLeft = transformPoint({ x: left, y: top });
var bottomRight = transformPoint({ x: right, y: bottom });
return {
top: topLeft.y,
left: topLeft.x,
bottom: bottomRight.y,
right: bottomRight.x,
};
}
/**
* Create an empty axis box of zero size
*/
function axisBox() {
return { x: { min: 0, max: 1 }, y: { min: 0, max: 1 } };
}
function copyAxisBox(box) {
return {
x: Object.assign({}, box.x),
y: Object.assign({}, box.y),
};
}
/**
* Create an empty box delta
*/
var zeroDelta = {
translate: 0,
scale: 1,
origin: 0,
originPoint: 0,
};
function delta() {
return {
x: Object.assign({}, zeroDelta),
y: Object.assign({}, zeroDelta),
};
}
export { axisBox, convertAxisBoxToBoundingBox, convertBoundingBoxToAxisBox, copyAxisBox, delta, transformBoundingBox };