Skip to content

Commit

Permalink
Set up prettier, husky, and eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyckahn committed Aug 4, 2018
1 parent fb8187a commit 88a8867
Show file tree
Hide file tree
Showing 11 changed files with 823 additions and 541 deletions.
25 changes: 25 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,25 @@
{
"env": {
"browser": true,
"commonjs": true,
"es6": true
},
"extends": ["eslint:recommended", "prettier"],
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": ["prettier"],
"rules": {
"linebreak-style": ["error", "unix"],
"semi": ["error", "always"],
"valid-jsdoc": [
"error",
{
"requireReturn": false,
"requireReturnDescription": false,
"requireParamDescription": false
}
]
}
}
4 changes: 4 additions & 0 deletions .prettierrc
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "es5"
}
12 changes: 10 additions & 2 deletions package.json
Expand Up @@ -16,12 +16,17 @@
"babel-preset-es2015": "^6.22.0",
"bluebird": "^3.5.0",
"concurrently": "^3.5.0",
"eslint": "^5.2.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-prettier": "^2.6.2",
"gh-pages": "^0.12.0",
"husky": "^0.14.3",
"jsdoc": "^3.4.3",
"jshint": "^2.9.4",
"live-server": "^1.2.0",
"mocha": "^3.2.0",
"nodemon": "^1.11.0",
"prettier": "^1.14.0",
"pretty-quick": "^1.6.0",
"webpack": "2.5.1",
"webpack-dev-server": "2.4.5"
},
Expand All @@ -34,9 +39,12 @@
"doc:view": "live-server dist/doc --port=9124",
"doc:watch": "nodemon --exec \"npm run doc\" --watch src --watch ./ --ext js,md --ignore dist",
"doc:live": "concurrently --kill-others \"npm run doc:watch\" \"npm run doc:view\"",
"lint": "jshint src",
"lint": "eslint src test webpack.*",
"deploy": "npm run build && npm run doc && gh-pages -d dist -b gh-pages",
"precommit": "pretty-quick --staged && npm test && npm run lint",
"prepush": "npm test && npm run lint",
"preversion": "npm run lint && npm test",
"prettier": "prettier '{src,test}/**/*.js' webpack.* --write",
"postversion": "git push && git push --tags && npm run deploy && npm publish"
},
"files": [
Expand Down
43 changes: 26 additions & 17 deletions src/bezier.js
Expand Up @@ -41,10 +41,22 @@ import assign from 'object-assign';
// port of webkit cubic bezier handling by http://www.netzgesta.de/dev/

/**
* @param {number} t
* @param {number} p1x
* @param {number} p1y
* @param {number} p2x
* @param {number} p2y
* @param {number} duration
* @returns {Function}
* @private
*/
function cubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration) {
let ax = 0, bx = 0, cx = 0, ay = 0, by = 0, cy = 0;
let ax = 0,
bx = 0,
cx = 0,
ay = 0,
by = 0,
cy = 0;

const sampleCurveX = t => ((ax * t + bx) * t + cx) * t;

Expand All @@ -54,7 +66,7 @@ function cubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration) {

const solveEpsilon = duration => 1 / (200 * duration);

const fabs = n => n >= 0 ? n : 0 - n;
const fabs = n => (n >= 0 ? n : 0 - n);

const solveCurveX = (x, epsilon) => {
let t0, t1, t2, x2, d2, i;
Expand Down Expand Up @@ -120,7 +132,7 @@ function cubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration) {
// End ported code

/**
* getCubicBezierTransition(x1, y1, x2, y2) -> Function
* GetCubicBezierTransition(x1, y1, x2, y2) -> Function.
*
* Generates a transition easing function that is compatible
* with WebKit's CSS transitions `-webkit-transition-timing-function`
Expand All @@ -133,13 +145,11 @@ function cubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration) {
* @param {number} y1
* @param {number} x2
* @param {number} y2
* @return {function}
* @return {Function}
* @private
*/
const getCubicBezierTransition = (x1, y1, x2, y2) =>
pos =>
cubicBezierAtTime(pos, x1, y1, x2, y2, 1);

const getCubicBezierTransition = (x1, y1, x2, y2) => pos =>
cubicBezierAtTime(pos, x1, y1, x2, y2, 1);

/**
* Create a Bezier easing function and attach it to {@link
Expand All @@ -157,21 +167,20 @@ const getCubicBezierTransition = (x1, y1, x2, y2) =>
* attached to {@link shifty.Tweenable.formulas}.
*/
export const setBezierFunction = (name, x1, y1, x2, y2) =>
Tweenable.formulas[name] =
assign(getCubicBezierTransition(x1, y1, x2, y2), {
displayName: name,
x1,
y1,
x2,
y2
});
(Tweenable.formulas[name] = assign(getCubicBezierTransition(x1, y1, x2, y2), {
displayName: name,
x1,
y1,
x2,
y2,
}));

/**
* `delete` an easing function from {@link shifty.Tweenable.formulas}. Be
* careful with this method, as it `delete`s whatever easing formula matches
* `name` (which means you can delete standard Shifty easing functions).
* @method shifty.unsetBezierFunction
* @param {string} name The name of the easing function to delete.
* @return {Boolean} Whether or not the functions was `delete`d.
* @return {boolean} Whether or not the functions was `delete`d.
*/
export const unsetBezierFunction = name => delete Tweenable.formulas[name];
104 changes: 50 additions & 54 deletions src/easing-functions.js
Expand Up @@ -36,53 +36,48 @@
* @type {Object.<shifty.easingFunction>}
* @static
*/

export const linear = pos => pos;

export const easeInQuad = pos => Math.pow(pos, 2);

export const easeOutQuad = pos => -(Math.pow((pos - 1), 2) - 1);
export const easeOutQuad = pos => -(Math.pow(pos - 1, 2) - 1);

export const easeInOutQuad = pos =>
(pos /= 0.5) < 1 ?
0.5 * Math.pow(pos,2) :
-0.5 * ((pos -= 2) * pos - 2);
(pos /= 0.5) < 1 ? 0.5 * Math.pow(pos, 2) : -0.5 * ((pos -= 2) * pos - 2);

export const easeInCubic = pos => Math.pow(pos, 3);

export const easeOutCubic = pos => Math.pow((pos - 1), 3) + 1;
export const easeOutCubic = pos => Math.pow(pos - 1, 3) + 1;

export const easeInOutCubic = pos =>
(pos /= 0.5) < 1 ?
0.5 * Math.pow(pos,3) :
0.5 * (Math.pow((pos - 2),3) + 2);
(pos /= 0.5) < 1 ? 0.5 * Math.pow(pos, 3) : 0.5 * (Math.pow(pos - 2, 3) + 2);

export const easeInQuart = pos => Math.pow(pos, 4);

export const easeOutQuart = pos => -(Math.pow((pos - 1), 4) - 1);
export const easeOutQuart = pos => -(Math.pow(pos - 1, 4) - 1);

export const easeInOutQuart = pos =>
(pos /= 0.5) < 1 ?
0.5 * Math.pow(pos,4) :
-0.5 * ((pos -= 2) * Math.pow(pos,3) - 2);
(pos /= 0.5) < 1
? 0.5 * Math.pow(pos, 4)
: -0.5 * ((pos -= 2) * Math.pow(pos, 3) - 2);

export const easeInQuint = pos => Math.pow(pos, 5);

export const easeOutQuint = pos => Math.pow((pos - 1), 5) + 1;
export const easeOutQuint = pos => Math.pow(pos - 1, 5) + 1;

export const easeInOutQuint = pos =>
(pos /= 0.5) < 1 ?
0.5 * Math.pow(pos,5) :
0.5 * (Math.pow((pos - 2),5) + 2);
(pos /= 0.5) < 1 ? 0.5 * Math.pow(pos, 5) : 0.5 * (Math.pow(pos - 2, 5) + 2);

export const easeInSine = pos => -Math.cos(pos * (Math.PI / 2)) + 1;

export const easeOutSine = pos => Math.sin(pos * (Math.PI / 2));

export const easeInOutSine = pos => -0.5 * (Math.cos(Math.PI * pos) - 1);

export const easeInExpo = pos => (pos === 0) ? 0 : Math.pow(2, 10 * (pos - 1));
export const easeInExpo = pos => (pos === 0 ? 0 : Math.pow(2, 10 * (pos - 1)));

export const easeOutExpo = pos => (pos === 1) ? 1 : -Math.pow(2, -10 * pos) + 1;
export const easeOutExpo = pos => (pos === 1 ? 1 : -Math.pow(2, -10 * pos) + 1);

export const easeInOutExpo = pos => {
if (pos === 0) {
Expand All @@ -94,30 +89,30 @@ export const easeInOutExpo = pos => {
}

if ((pos /= 0.5) < 1) {
return 0.5 * Math.pow(2,10 * (pos - 1));
return 0.5 * Math.pow(2, 10 * (pos - 1));
}

return 0.5 * (-Math.pow(2, -10 * --pos) + 2);
};

export const easeInCirc = pos => -(Math.sqrt(1 - (pos * pos)) - 1);
export const easeInCirc = pos => -(Math.sqrt(1 - pos * pos) - 1);

export const easeOutCirc = pos => Math.sqrt(1 - Math.pow((pos - 1), 2));
export const easeOutCirc = pos => Math.sqrt(1 - Math.pow(pos - 1, 2));

export const easeInOutCirc = pos =>
((pos /= 0.5) < 1) ?
-0.5 * (Math.sqrt(1 - pos * pos) - 1) :
0.5 * (Math.sqrt(1 - (pos -= 2) * pos) + 1);
(pos /= 0.5) < 1
? -0.5 * (Math.sqrt(1 - pos * pos) - 1)
: 0.5 * (Math.sqrt(1 - (pos -= 2) * pos) + 1);

export const easeOutBounce = pos => {
if (pos < (1 / 2.75)) {
return (7.5625 * pos * pos);
} else if (pos < (2 / 2.75)) {
return (7.5625 * (pos -= (1.5 / 2.75)) * pos + 0.75);
} else if (pos < (2.5 / 2.75)) {
return (7.5625 * (pos -= (2.25 / 2.75)) * pos + 0.9375);
if (pos < 1 / 2.75) {
return 7.5625 * pos * pos;
} else if (pos < 2 / 2.75) {
return 7.5625 * (pos -= 1.5 / 2.75) * pos + 0.75;
} else if (pos < 2.5 / 2.75) {
return 7.5625 * (pos -= 2.25 / 2.75) * pos + 0.9375;
} else {
return (7.5625 * (pos -= (2.625 / 2.75)) * pos + 0.984375);
return 7.5625 * (pos -= 2.625 / 2.75) * pos + 0.984375;
}
};

Expand All @@ -134,19 +129,20 @@ export const easeOutBack = pos => {
export const easeInOutBack = pos => {
let s = 1.70158;
if ((pos /= 0.5) < 1) {
return 0.5 * (pos * pos * (((s *= (1.525)) + 1) * pos - s));
return 0.5 * (pos * pos * (((s *= 1.525) + 1) * pos - s));
}
return 0.5 * ((pos -= 2) * pos * (((s *= (1.525)) + 1) * pos + s) + 2);
return 0.5 * ((pos -= 2) * pos * (((s *= 1.525) + 1) * pos + s) + 2);
};

export const elastic = pos =>
-1 * Math.pow(4,-8 * pos) * Math.sin((pos * 6 - 1) * (2 * Math.PI) / 2) + 1;
-1 * Math.pow(4, -8 * pos) * Math.sin(((pos * 6 - 1) * (2 * Math.PI)) / 2) +
1;

export const swingFromTo = pos => {
let s = 1.70158;
return ((pos /= 0.5) < 1) ?
0.5 * (pos * pos * (((s *= (1.525)) + 1) * pos - s)) :
0.5 * ((pos -= 2) * pos * (((s *= (1.525)) + 1) * pos + s) + 2);
return (pos /= 0.5) < 1
? 0.5 * (pos * pos * (((s *= 1.525) + 1) * pos - s))
: 0.5 * ((pos -= 2) * pos * (((s *= 1.525) + 1) * pos + s) + 2);
};

export const swingFrom = pos => {
Expand All @@ -160,33 +156,33 @@ export const swingTo = pos => {
};

export const bounce = pos => {
if (pos < (1 / 2.75)) {
return (7.5625 * pos * pos);
} else if (pos < (2 / 2.75)) {
return (7.5625 * (pos -= (1.5 / 2.75)) * pos + 0.75);
} else if (pos < (2.5 / 2.75)) {
return (7.5625 * (pos -= (2.25 / 2.75)) * pos + 0.9375);
if (pos < 1 / 2.75) {
return 7.5625 * pos * pos;
} else if (pos < 2 / 2.75) {
return 7.5625 * (pos -= 1.5 / 2.75) * pos + 0.75;
} else if (pos < 2.5 / 2.75) {
return 7.5625 * (pos -= 2.25 / 2.75) * pos + 0.9375;
} else {
return (7.5625 * (pos -= (2.625 / 2.75)) * pos + 0.984375);
return 7.5625 * (pos -= 2.625 / 2.75) * pos + 0.984375;
}
};

export const bouncePast = pos => {
if (pos < (1 / 2.75)) {
return (7.5625 * pos * pos);
} else if (pos < (2 / 2.75)) {
return 2 - (7.5625 * (pos -= (1.5 / 2.75)) * pos + 0.75);
} else if (pos < (2.5 / 2.75)) {
return 2 - (7.5625 * (pos -= (2.25 / 2.75)) * pos + 0.9375);
if (pos < 1 / 2.75) {
return 7.5625 * pos * pos;
} else if (pos < 2 / 2.75) {
return 2 - (7.5625 * (pos -= 1.5 / 2.75) * pos + 0.75);
} else if (pos < 2.5 / 2.75) {
return 2 - (7.5625 * (pos -= 2.25 / 2.75) * pos + 0.9375);
} else {
return 2 - (7.5625 * (pos -= (2.625 / 2.75)) * pos + 0.984375);
return 2 - (7.5625 * (pos -= 2.625 / 2.75) * pos + 0.984375);
}
};

export const easeFromTo = pos =>
((pos /= 0.5) < 1) ?
0.5 * Math.pow(pos,4) :
-0.5 * ((pos -= 2) * Math.pow(pos,3) - 2);
(pos /= 0.5) < 1
? 0.5 * Math.pow(pos, 4)
: -0.5 * ((pos -= 2) * Math.pow(pos, 3) - 2);

export const easeFrom = pos => Math.pow(pos, 4);

Expand Down
17 changes: 11 additions & 6 deletions src/interpolate.js
Expand Up @@ -11,7 +11,7 @@ mockTweenable._filterArgs = [];
* specific frame of animation that {@link shifty.Tweenable#tween} does many times
* over the course of a full tween.
*
* import { interpolate } from 'shifty';
* import { interpolate } from 'shifty';.
*
* const interpolatedValues = interpolate({
* width: '100px',
Expand Down Expand Up @@ -45,9 +45,7 @@ mockTweenable._filterArgs = [];
* increase all valid values of `position` to numbers between `0` and `1.5`.
* @return {Object}
*/
export const interpolate =
(from, to, position, easing, delay = 0) => {

export const interpolate = (from, to, position, easing, delay = 0) => {
const current = clone(from);
const easingObject = composeEasingObject(from, easing);

Expand All @@ -58,8 +56,15 @@ export const interpolate =
mockTweenable._applyFilter('tweenCreated');
mockTweenable._applyFilter('beforeTween');

const interpolatedValues =
tweenProps(position, current, from, to, 1, delay, easingObject);
const interpolatedValues = tweenProps(
position,
current,
from,
to,
1,
delay,
easingObject
);

// Transform data in interpolatedValues back into its original format
mockTweenable._applyFilter('afterTween');
Expand Down

0 comments on commit 88a8867

Please sign in to comment.