var TouchCollection = /** @class */ (function () {
    function TouchCollection() {
        this.touches = new Map();
    }
    TouchCollection.prototype.getTouches = function () {
        return Array.from(this.touches.values());
    };
    TouchCollection.prototype.getTouchCount = function () {
        return this.touches.size;
    };
    TouchCollection.prototype.clear = function () {
        this.touches.clear();
    };
    TouchCollection.prototype.buildFakeTouchEvent = function (event) {
        var currentTouches = this.getTouches();
        var fakeEvent = {
            preventDefault: function () { return event.preventDefault(); },
            stopPropagation: function () { return event.stopPropagation(); },
            touches: Object.assign(currentTouches, {
                item: function (index) { return currentTouches[index]; }
            })
        };
        return fakeEvent;
    };
    TouchCollection.prototype.handlePointerDown = function (event) {
        if (this.isHandleable(event)) {
            return this.addOrUpdateTouch(event);
        }
    };
    TouchCollection.prototype.handlePointerMove = function (event) {
        return this.handlePointerDown(event);
    };
    TouchCollection.prototype.handlePointerUp = function (event) {
        this.touches.delete(event.pointerId);
    };
    TouchCollection.prototype.handleEvent = function (event) {
        if (event.pointerType !== "touch") {
            return;
        }
        switch (event.type) {
            case "pointerdown":
                this.handlePointerDown(event);
                break;
            case "pointermove":
                this.handlePointerMove(event);
                break;
            case "lostpointercapture":
            case "pointerleave":
            case "pointercancel":
            case "pointerout":
            case "pointerup":
                this.handlePointerUp(event);
                break;
        }
    };
    TouchCollection.prototype.isHandleable = function (event) {
        return event.pointerType === "touch";
    };
    TouchCollection.prototype.addOrUpdateTouch = function (event) {
        var touch;
        if ((touch = this.touches.get(event.pointerId))) {
            touch.clientX = event.clientX;
            touch.clientY = event.clientY;
            touch.pageX = event.pageX;
            touch.pageY = event.pageY;
            return;
        }
        this.touches.set(event.pointerId, {
            clientX: event.clientX,
            clientY: event.clientY,
            pageX: event.pageX,
            pageY: event.pageY,
            identifier: event.pointerId
        });
    };
    return TouchCollection;
}());
export { TouchCollection };
