import { Fun, Optional } from '@ephox/katamari';
import { nuState } from '../../behaviour/common/BehaviourState';
// NOTE: mode refers to the way that information is retrieved from
// the user interaction. It can be things like MouseData, TouchData etc.
const init = () => {
    // Dragging operates on the difference between the previous user
    // interaction and the next user interaction. Therefore, we store
    // the previous interaction so that we can compare it.
    let previous = Optional.none();
    // Dragging requires calculating the bounds, so we store that data initially
    // to reduce the amount of computation each mouse movement
    let startData = Optional.none();
    const reset = () => {
        previous = Optional.none();
        startData = Optional.none();
    };
    // Return position delta between previous position and nu position,
    // or None if this is the first. Set the previous position to nu.
    const calculateDelta = (mode, nu) => {
        const result = previous.map((old) => mode.getDelta(old, nu));
        previous = Optional.some(nu);
        return result;
    };
    // NOTE: This dragEvent is the DOM touch event or mouse event
    const update = (mode, dragEvent) => mode.getData(dragEvent).bind((nuData) => calculateDelta(mode, nuData));
    const setStartData = (data) => {
        startData = Optional.some(data);
    };
    const getStartData = () => startData;
    const readState = Fun.constant({});
    return nuState({
        readState,
        reset,
        update,
        getStartData,
        setStartData
    });
};
export { init };
//# sourceMappingURL=DragState.js.map