"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.listenTouchEnd = exports.makeTouchEndListener = void 0;
function makeTouchEndListener(listener) {
    return (component) => {
        return listenTouchEnd(component, listener);
    };
}
exports.makeTouchEndListener = makeTouchEndListener;
function listenTouchEnd(component, listener) {
    const { $element } = component;
    const touchEndListener = (_event) => {
        // log('touchend')
        const { $context } = component;
        const { $x, $y, $sx, $sy } = $context;
        const { changedTouches, touches } = _event;
        const event = [];
        for (let i = 0; i < touches.length; i++) {
            const touch = touches[i];
            const { clientX, clientY } = touch;
            event.push({
                clientX: (clientX - $x) / $sx,
                clientY: (clientY - $y) / $sy,
                screenX: clientX,
                screenY: clientY,
            });
        }
        listener(event, _event);
    };
    $element.addEventListener('touchend', touchEndListener, { passive: false });
    return () => {
        $element.removeEventListener('touchend', touchEndListener);
    };
}
exports.listenTouchEnd = listenTouchEnd;
//# sourceMappingURL=touchend.js.map