const GOING_IN = 'in'
const GOING_OUT = 'out'

const going = visibilityRatio => visibilityRatio > 0 ? GOING_IN : GOING_OUT

const DIRECTION_TOP = 'top'
const DIRECTION_RIGHT = 'right'
const DIRECTION_BOTTOM = 'bottom'
const DIRECTION_LEFT = 'left'

const direction = (boundingClientRect, oldBoundingClientRect) => {
  if (boundingClientRect.y < oldBoundingClientRect.y) return DIRECTION_TOP
  if (boundingClientRect.x > oldBoundingClientRect.x) return DIRECTION_RIGHT
  if (boundingClientRect.y > oldBoundingClientRect.y) return DIRECTION_BOTTOM
  if (boundingClientRect.x < oldBoundingClientRect.x) return DIRECTION_LEFT
}

const extractWaypointData = node => node._waypointData

const extractOldBoundingClientRect = (node, defaultBoundingClientRect) => {
  const nodeData = extractWaypointData(node)
  return typeof nodeData !== 'undefined' ? nodeData : defaultBoundingClientRect
}

const mapEntry = entry => {
  const { boundingClientRect, intersectionRatio, target } = entry
  const oldBoundingClientRect = extractOldBoundingClientRect(target, boundingClientRect)

  // save current rect
  target._waypointData = boundingClientRect

  return {
    el: target,
    going: going(intersectionRatio),
    direction: direction(boundingClientRect, oldBoundingClientRect),
    _entry: entry
  }
}

export {
  going,
  GOING_IN,
  GOING_OUT,
  direction,
  DIRECTION_TOP,
  DIRECTION_RIGHT,
  DIRECTION_BOTTOM,
  DIRECTION_LEFT,
  mapEntry
}

@@ -311,20 +311,26 @@
  =%3E %7B%0A  
-if (
+const y = 
 bounding
@@ -342,22 +342,20 @@
 tRect.y 
-%3C oldB
+%7C%7C b
 oundingC
@@ -368,116 +368,159 @@
 ect.
-y) return DIRECTION_TOP%0A  if (boundingClientRect.x %3E oldBoundingClientRect.x) return DIRECTION_RIGHT%0A  if (b
+top%0A  const x = boundingClientRect.x %7C%7C boundingClientRect.left%0A  const oldY = oldBoundingClientRect.y %7C%7C oldBoundingClientRect.top%0A  const oldX = oldB
 ound
@@ -537,11 +537,12 @@
 ect.
-y %3E
+x %7C%7C
  old
@@ -560,17 +560,35 @@
 entRect.
-y
+left%0A  if (y %3C oldY
 ) return
@@ -602,67 +602,105 @@
 ION_
-BOT
 TO
-M
+P
 %0A  if (
-boundingClientRect.x %3C oldBoundingClientRect.x
+x %3E oldX) return DIRECTION_RIGHT%0A  if (y %3E oldY) return DIRECTION_BOTTOM%0A  if (x %3C oldX
 ) re

Update waypointInterface.js (#14)