Skip to content

Commit b013fe0

Browse files
committed
2.1.0 - exact 0% and 100% values
1 parent 3e0df94 commit b013fe0

File tree

5 files changed

+20
-6
lines changed

5 files changed

+20
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
build
22
coverage
33
node_modules
4+
npm-debug.log

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ coverage
22
src
33
node_modules
44
build/__tests__
5+
npm-debug.log

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "css-spring",
3-
"version": "2.0.1",
3+
"version": "2.1.0",
44
"description": "Generates values for physics based css-keyframe animations",
55
"main": "build/index.js",
66
"repository": {

src/__tests__/__snapshots__/index.test.js.snap

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
exports[`css-spring matches snapshots 1`] = `
22
Object {
3+
"0%": Object {
4+
"opacity": 0,
5+
},
36
"1%": Object {
47
"opacity": 0.017,
58
},
@@ -305,14 +308,17 @@ Object {
305308

306309
exports[`css-spring matches snapshots 2`] = `
307310
Object {
311+
"0%": Object {
312+
"padding-left": -50,
313+
},
308314
"1%": Object {
309315
"padding-left": -48.2,
310316
},
311317
"10%": Object {
312318
"padding-left": 10.30039,
313319
},
314320
"100%": Object {
315-
"padding-left": 49.85832,
321+
"padding-left": 50,
316322
},
317323
"11%": Object {
318324
"padding-left": 17.8614,
@@ -610,6 +616,10 @@ Object {
610616

611617
exports[`css-spring matches snapshots 3`] = `
612618
Object {
619+
"0%": Object {
620+
"margin-right": 0,
621+
"padding-left": -50,
622+
},
613623
"1%": Object {
614624
"margin-right": 1.524,
615625
"padding-left": -48.8,
@@ -619,8 +629,8 @@ Object {
619629
"padding-left": -9.7,
620630
},
621631
"100%": Object {
622-
"margin-right": 126.998,
623-
"padding-left": 49.999,
632+
"margin-right": 127,
633+
"padding-left": 50,
624634
},
625635
"11%": Object {
626636
"margin-right": 57.971,

src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@ export const getKeyframes = (startProps, targetProps, options = {}) => {
2020
presets[options.preset] || {}
2121
)
2222

23-
const steps = {}
2423
const cache = initCache(startProps, targetProps)
24+
const steps = { '0%': Object.keys(cache).reduce((accu, key) => {
25+
return Object.assign(accu, { [key]: cache[key].start })
26+
}, {})}
2527

2628
for (let i = 1; i < 101; i += 1) {
2729
const props = {}
2830
Object.keys(cache).forEach((key) => {
2931
const prop = cache[key]
3032
const [value, velocity] = stepper(0.01, prop.cache.value, prop.cache.velocity, parseFloat(prop.target), stiffness, damping)
3133
prop.cache = { value, velocity }
32-
props[key] = +prop.cache.value.toFixed(precision)
34+
props[key] = +(i === 100 ? prop.target : prop.cache.value).toFixed(precision)
3335
})
3436
steps[`${i}%`] = props
3537
}

0 commit comments

Comments
 (0)