Skip to content

Commit

Permalink
fix: fix off-by-one errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen committed Nov 14, 2021
1 parent 7bf5a1c commit eb1081f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
38 changes: 30 additions & 8 deletions src/fsm-transitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ export default {
to: states.FINISH,
when: (d) => [
d.isSideInnerFitsPath === true,
d.viewportTop + d.sideInnerHeight >= d.finishPoint
d.viewportTop + d.sideInnerHeight > d.finishPoint
]
},
{
to: states.BOTTOM_FIXED,
when: (d) => [
d.isSideInnerFitsPath === true,
d.isSideInnerFitsViewport === false,
d.viewportBottom >= d.sideInnerBottom + d.bottomSpacing
d.viewportBottom > d.sideInnerBottom + d.bottomSpacing
],
},
{
to: states.TOP_FIXED,
when: (d) => [
d.isSideInnerFitsPath === true,
d.isSideInnerFitsViewport === true,
d.viewportTop >= d.startPoint - d.topSpacing
d.viewportTop > d.startPoint - d.topSpacing
]
}
],
Expand All @@ -38,7 +38,7 @@ export default {
},
{
to: states.FINISH,
when: (d) => [d.sideInnerBottom >= d.finishPoint]
when: (d) => [d.sideInnerBottom > d.finishPoint]
},
{
to: states.UNFIXED,
Expand All @@ -54,9 +54,20 @@ export default {
to: states.START,
when: (d) => [d.isSideInnerFitsPath === false],
},
{
to: states.START,
when: (d) => [d.viewportTop <= d.startPoint - d.topSpacing]
},
{
to: states.FINISH,
when: (d) => [d.viewportTop + d.sideInnerHeight > d.finishPoint]
},
{
to: states.TOP_FIXED,
when: (d) => [d.viewportTop <= d.sideInnerTop - d.topSpacing]
when: (d) => [
d.scrollDirection === 'up',
d.viewportTop <= d.sideInnerTop - d.topSpacing
]
},
{
to: states.TOP_FIXED,
Expand All @@ -69,7 +80,7 @@ export default {
to: states.BOTTOM_FIXED,
when: (d) => [
d.isSideInnerFitsViewport === false,
d.viewportBottom >= d.sideInnerBottom + d.bottomSpacing
d.viewportBottom > d.sideInnerBottom + d.bottomSpacing
]
}
],
Expand All @@ -79,6 +90,13 @@ export default {
to: states.START,
when: (d) => [d.isSideInnerFitsPath === false],
},
{
to: states.START,
when: (d) => [
d.isSideInnerFitsPath === true,
d.sideInnerTop <= d.startPoint - d.topSpacing
]
},
{
to: states.UNFIXED,
when: (d) => [d.scrollDirection === 'up']
Expand All @@ -89,7 +107,7 @@ export default {
},
{
to: states.FINISH,
when: (d) => [d.sideInnerBottom >= d.finishPoint]
when: (d) => [d.sideInnerBottom > d.finishPoint]
}
],

Expand All @@ -98,11 +116,15 @@ export default {
to: states.START,
when: (d) => [d.isSideInnerFitsPath === false],
},
{
to: states.START,
when: (d) => [d.viewportTop <= d.startPoint - d.topSpacing]
},
{
to: states.BOTTOM_FIXED,
when: (d) => [
d.sideInnerBottom + d.bottomSpacing <= d.finishPoint,
d.viewportBottom <= d.finishPoint
d.viewportBottom < d.finishPoint
]
},
{
Expand Down
1 change: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function FloatSidebar(options) {

updateSideOuterHeight(prevDimensions, dimensions);
},

{
$viewport,
$sideOuter,
Expand Down

0 comments on commit eb1081f

Please sign in to comment.