const cache = [];
function copyTouch({ identifier, pageX, pageY }) {
    return { identifier, pageX, pageY };
}
function getTouchById(id) {
    for (let i = 0; i < cache.length; i++) {
        const { identifier } = cache[i];
        if (id === identifier) {
            return i;
        }
    }
    return -1;
}
export function add(event) {
    const touches = event.changedTouches;
    for (let i = 0; i < touches.length; i++) {
        cache.push(copyTouch(touches[i]));
    }
}
export function move(event) {
    if (event.cancelable) {
        event.preventDefault();
    }
    const touches = event.changedTouches;
    const result = [];
    for (let i = 0; i < touches.length; i++) {
        const touch = touches[i];
        const index = getTouchById(touch.identifier);
        if (index === -1) {
            continue;
        }
        const copy = copyTouch(touch);
        const { pageX: opx, pageY: opy } = cache[index];
        const { identifier, pageX, pageY } = copy;
        cache.splice(index, 1, copy);
        result.push({
            identifier,
            dx: -(pageX - opx),
            dy: -(pageY - opy),
        });
    }
    return result;
}
export function end(event) {
    const touches = event.changedTouches;
    for (let i = 0; i < touches.length; i++) {
        const touch = touches[i];
        const index = getTouchById(touch.identifier);
        if (index === -1) {
            continue;
        }
        cache.splice(index, 1);
    }
}
//# sourceMappingURL=TouchSupport.js.map