function useScrollToIndex(positioner, options) {
    var _latestOptions$curren

    var _options$align = options.align,
      align = _options$align === void 0 ? 'top' : _options$align,
      _options$element = options.element,
      element =
        _options$element === void 0
          ? typeof window !== 'undefined' && window
          : _options$element,
      _options$offset = options.offset,
      offset = _options$offset === void 0 ? 0 : _options$offset,
      _options$height = options.height,
      height =
        _options$height === void 0
          ? typeof window !== 'undefined'
            ? window.innerHeight
            : 0
          : _options$height
    var latestOptions = useLatest$4({
      positioner: positioner,
      element: element,
      align: align,
      offset: offset,
      height: height,
    })
    var getTarget = React.useRef(function () {
      var latestElement = latestOptions.current.element
      return latestElement && 'current' in latestElement
        ? latestElement.current
        : latestElement
    }).current

    var _React$useReducer = React.useReducer(function (state, action) {
        var nextState = {
          position: state.position,
          index: state.index,
          prevTop: state.prevTop,
        }
        /* istanbul ignore next */

        if (action.type === 'scrollToIndex') {
          var _action$value

          return {
            position: latestOptions.current.positioner.get(
              (_action$value = action.value) !== null &&
                _action$value !== void 0
                ? _action$value
                : -1
            ),
            index: action.value,
            prevTop: void 0,
          }
        } else if (action.type === 'setPosition') {
          nextState.position = action.value
        } else if (action.type === 'setPrevTop') {
          nextState.prevTop = action.value
        } else if (action.type === 'reset') {
          return defaultState
        }

        return nextState
      }, defaultState),
      state = _React$useReducer[0],
      dispatch = _React$useReducer[1]

    var throttledDispatch = useThrottleCallback(dispatch, 15) // If we find the position along the way we can immediately take off
    // to the correct spot.

    useEvent$2(getTarget(), 'scroll', function () {
      if (!state.position && state.index) {
        var position = latestOptions.current.positioner.get(state.index)

        if (position) {
          dispatch({
            type: 'setPosition',
            value: position,
          })
        }
      }
    }) // If the top changes out from under us in the case of dynamic cells, we
    // want to keep following it.

    var currentTop =
      state.index !== void 0 &&
      ((_latestOptions$curren = latestOptions.current.positioner.get(
        state.index
      )) === null || _latestOptions$curren === void 0
        ? void 0
        : _latestOptions$curren.top)
    React.useEffect(
      function () {
        var target = getTarget()
        if (!target) return
        var _latestOptions$curren2 = latestOptions.current,
          height = _latestOptions$curren2.height,
          align = _latestOptions$curren2.align,
          offset = _latestOptions$curren2.offset,
          positioner = _latestOptions$curren2.positioner

        if (state.position) {
          var scrollTop = state.position.top

          if (align === 'bottom') {
            scrollTop = scrollTop - height + state.position.height
          } else if (align === 'center') {
            scrollTop -= (height - state.position.height) / 2
          }

          target.scrollTo(0, Math.max(0, (scrollTop += offset))) // Resets state after 400ms, an arbitrary time I determined to be
          // still visually pleasing if there is a slow network reply in dynamic
          // cells

          var didUnsubscribe = false
          var timeout = setTimeout(function () {
            return (
              !didUnsubscribe &&
              dispatch({
                type: 'reset',
              })
            )
          }, 400)
          return function () {
            didUnsubscribe = true
            clearTimeout(timeout)
          }
        } else if (state.index !== void 0) {
          // Estimates the top based upon the average height of current cells
          var estimatedTop =
            (positioner.shortestColumn() / positioner.size()) * state.index
          if (state.prevTop)
            estimatedTop = Math.max(estimatedTop, state.prevTop + height)
          target.scrollTo(0, estimatedTop)
          throttledDispatch({
            type: 'setPrevTop',
            value: estimatedTop,
          })
        }
      },
      [currentTop, state, latestOptions, getTarget, throttledDispatch]
    )
    return React.useRef(function (index) {
      dispatch({
        type: 'scrollToIndex',
        value: index,
      })
    }).current
  }
/**
   * A hook that creates a callback for scrolling to a specific index in
   * the "items" array.
   *
   * @param positioner A positioner created by the `usePositioner()` hook
   * @param options Configuration options
   */
A hook that creates a callback for scrolling to a specific index in
the "items" array.

@param positioner A positioner created by the `usePositioner()` hook
@param options Configuration options
A hook that creates a callback for scrolling to a specific index in the " items " array . @param positioner A positioner created by the ` usePositioner () ` hook @param options Configuration options
function useScrollToIndex(positioner, options) {
    var _latestOptions$curren
    var _options$align = options.align,
      align = _options$align === void 0 ? 'top' : _options$align,
      _options$element = options.element,
      element =
        _options$element === void 0
          ? typeof window !== 'undefined' && window
          : _options$element,
      _options$offset = options.offset,
      offset = _options$offset === void 0 ? 0 : _options$offset,
      _options$height = options.height,
      height =
        _options$height === void 0
          ? typeof window !== 'undefined'
            ? window.innerHeight
            : 0
          : _options$height
    var latestOptions = useLatest$4({
      positioner: positioner,
      element: element,
      align: align,
      offset: offset,
      height: height,
    })
    var getTarget = React.useRef(function () {
      var latestElement = latestOptions.current.element
      return latestElement && 'current' in latestElement
        ? latestElement.current
        : latestElement
    }).current
    var _React$useReducer = React.useReducer(function (state, action) {
        var nextState = {
          position: state.position,
          index: state.index,
          prevTop: state.prevTop,
        }
        if (action.type === 'scrollToIndex') {
          var _action$value
          return {
            position: latestOptions.current.positioner.get(
              (_action$value = action.value) !== null &&
                _action$value !== void 0
                ? _action$value
                : -1
            ),
            index: action.value,
            prevTop: void 0,
          }
        } else if (action.type === 'setPosition') {
          nextState.position = action.value
        } else if (action.type === 'setPrevTop') {
          nextState.prevTop = action.value
        } else if (action.type === 'reset') {
          return defaultState
        }
        return nextState
      }, defaultState),
      state = _React$useReducer[0],
      dispatch = _React$useReducer[1]
    var throttledDispatch = useThrottleCallback(dispatch, 15) 
    useEvent$2(getTarget(), 'scroll', function () {
      if (!state.position && state.index) {
        var position = latestOptions.current.positioner.get(state.index)
        if (position) {
          dispatch({
            type: 'setPosition',
            value: position,
          })
        }
      }
    }) 
    var currentTop =
      state.index !== void 0 &&
      ((_latestOptions$curren = latestOptions.current.positioner.get(
        state.index
      )) === null || _latestOptions$curren === void 0
        ? void 0
        : _latestOptions$curren.top)
    React.useEffect(
      function () {
        var target = getTarget()
        if (!target) return
        var _latestOptions$curren2 = latestOptions.current,
          height = _latestOptions$curren2.height,
          align = _latestOptions$curren2.align,
          offset = _latestOptions$curren2.offset,
          positioner = _latestOptions$curren2.positioner
        if (state.position) {
          var scrollTop = state.position.top
          if (align === 'bottom') {
            scrollTop = scrollTop - height + state.position.height
          } else if (align === 'center') {
            scrollTop -= (height - state.position.height) / 2
          }
          target.scrollTo(0, Math.max(0, (scrollTop += offset))) 
          var didUnsubscribe = false
          var timeout = setTimeout(function () {
            return (
              !didUnsubscribe &&
              dispatch({
                type: 'reset',
              })
            )
          }, 400)
          return function () {
            didUnsubscribe = true
            clearTimeout(timeout)
          }
        } else if (state.index !== void 0) {
          var estimatedTop =
            (positioner.shortestColumn() / positioner.size()) * state.index
          if (state.prevTop)
            estimatedTop = Math.max(estimatedTop, state.prevTop + height)
          target.scrollTo(0, estimatedTop)
          throttledDispatch({
            type: 'setPrevTop',
            value: estimatedTop,
          })
        }
      },
      [currentTop, state, latestOptions, getTarget, throttledDispatch]
    )
    return React.useRef(function (index) {
      dispatch({
        type: 'scrollToIndex',
        value: index,
      })
    }).current
  }
function useScrollToIndex ( positioner , options ) { var _latestOptions$curren var _options$align = options . align , align = _options$align === void 0 ? 'top' : _options$align , _options$element = options . element , element = _options$element === void 0 ? typeof window !== 'undefined' && window : _options$element , _options$offset = options . offset , offset = _options$offset === void 0 ? 0 : _options$offset , _options$height = options . height , height = _options$height === void 0 ? typeof window !== 'undefined' ? window . innerHeight : 0 : _options$height var latestOptions = useLatest$4 ( { positioner : positioner , element : element , align : align , offset : offset , height : height , } ) var getTarget = React . useRef ( function ( ) { var latestElement = latestOptions . current . element return latestElement && 'current' in latestElement ? latestElement . current : latestElement } ) . current var _React$useReducer = React . useReducer ( function ( state , action ) { var nextState = { position : state . position , index : state . index , prevTop : state . prevTop , } if ( action . type === 'scrollToIndex' ) { var _action$value return { position : latestOptions . current . positioner . get ( ( _action$value = action . value ) !== null && _action$value !== void 0 ? _action$value : - 1 ) , index : action . value , prevTop : void 0 , } } else if ( action . type === 'setPosition' ) { nextState . position = action . value } else if ( action . type === 'setPrevTop' ) { nextState . prevTop = action . value } else if ( action . type === 'reset' ) { return defaultState } return nextState } , defaultState ) , state = _React$useReducer [ 0 ] , dispatch = _React$useReducer [ 1 ] var throttledDispatch = useThrottleCallback ( dispatch , 15 ) useEvent$2 ( getTarget ( ) , 'scroll' , function ( ) { if ( ! state . position && state . index ) { var position = latestOptions . current . positioner . get ( state . index ) if ( position ) { dispatch ( { type : 'setPosition' , value : position , } ) } } } ) var currentTop = state . index !== void 0 && ( ( _latestOptions$curren = latestOptions . current . positioner . get ( state . index ) ) === null || _latestOptions$curren === void 0 ? void 0 : _latestOptions$curren . top ) React . useEffect ( function ( ) { var target = getTarget ( ) if ( ! target ) return var _latestOptions$curren2 = latestOptions . current , height = _latestOptions$curren2 . height , align = _latestOptions$curren2 . align , offset = _latestOptions$curren2 . offset , positioner = _latestOptions$curren2 . positioner if ( state . position ) { var scrollTop = state . position . top if ( align === 'bottom' ) { scrollTop = scrollTop - height + state . position . height } else if ( align === 'center' ) { scrollTop -= ( height - state . position . height ) / 2 } target . scrollTo ( 0 , Math . max ( 0 , ( scrollTop += offset ) ) ) var didUnsubscribe = false var timeout = setTimeout ( function ( ) { return ( ! didUnsubscribe && dispatch ( { type : 'reset' , } ) ) } , 400 ) return function ( ) { didUnsubscribe = true clearTimeout ( timeout ) } } else if ( state . index !== void 0 ) { var estimatedTop = ( positioner . shortestColumn ( ) / positioner . size ( ) ) * state . index if ( state . prevTop ) estimatedTop = Math . max ( estimatedTop , state . prevTop + height ) target . scrollTo ( 0 , estimatedTop ) throttledDispatch ( { type : 'setPrevTop' , value : estimatedTop , } ) } } , [ currentTop , state , latestOptions , getTarget , throttledDispatch ] ) return React . useRef ( function ( index ) { dispatch ( { type : 'scrollToIndex' , value : index , } ) } ) . current }
A hook that creates a callback for scrolling to a specific index in
 the "items" array.
A hook that creates a callback for scrolling to a specific index in the " items " array .
/* istanbul ignore next */ // If we find the position along the way we can immediately take off // to the correct spot. // If the top changes out from under us in the case of dynamic cells, we // want to keep following it. // Resets state after 400ms, an arbitrary time I determined to be // still visually pleasing if there is a slow network reply in dynamic // cells // Estimates the top based upon the average height of current cells