(function() {
  var useState = React.useState;
  var useEffect = React.useEffect;
  var useRef = React.useRef;

  function useScrollMorph(threshold) {
    threshold = threshold != null ? threshold : 24;
    var _scrolled = useState(false);
    var scrolled = _scrolled[0], setScrolled = _scrolled[1];
    var _progress = useState(0);
    var progress = _progress[0], setProgress = _progress[1];
    var ref = useRef(null);

    useEffect(function() {
      function onScroll() {
        var y = window.scrollY || document.documentElement.scrollTop || 0;
        setScrolled(y > threshold);
        setProgress(Math.min(1, y / (threshold * 4)));
      }
      onScroll();
      window.addEventListener('scroll', onScroll, { passive: true });
      return function() { window.removeEventListener('scroll', onScroll); };
    }, [threshold]);

    return { ref: ref, scrolled: scrolled, progress: progress };
  }

  window.useScrollMorph = useScrollMorph;
})();
