const EMPTY_SET = new Set();
const EMPTY_BUTTON_SET = new Set();
export class InputSnapshot {
    keys;
    pointer;
    gamepads;
    previousKeys;
    constructor(options = {}) {
        this.keys = new Set(options.keys ?? EMPTY_SET);
        this.previousKeys = new Set(options.previousKeys ?? EMPTY_SET);
        this.gamepads = Object.freeze([...(options.gamepads ?? [])]);
        const previousButtons = options.previousPointerButtons ?? EMPTY_BUTTON_SET;
        const currentButtons = new Set(options.pointer?.buttons?.keys() ?? []);
        const buttons = new Map();
        for (const button of new Set([...previousButtons, ...currentButtons])) {
            const down = currentButtons.has(button);
            const wasDown = previousButtons.has(button);
            buttons.set(button, Object.freeze({ down, pressed: down && !wasDown, released: !down && wasDown }));
        }
        this.pointer = Object.freeze({
            x: options.pointer?.x ?? 0,
            y: options.pointer?.y ?? 0,
            deltaX: options.pointer?.deltaX ?? 0,
            deltaY: options.pointer?.deltaY ?? 0,
            wheelX: options.pointer?.wheelX ?? 0,
            wheelY: options.pointer?.wheelY ?? 0,
            buttons,
            touches: Object.freeze([...(options.pointer?.touches ?? [])])
        });
    }
    key(code) {
        const down = this.keys.has(code);
        const wasDown = this.previousKeys.has(code);
        return Object.freeze({ down, pressed: down && !wasDown, released: !down && wasDown });
    }
    button(button) {
        return this.pointer.buttons.get(button) ?? Object.freeze({ down: false, pressed: false, released: false });
    }
    gamepadButton(gamepadIndex, buttonIndex) {
        return (this.gamepads.find((gamepad) => gamepad.index === gamepadIndex)?.buttons[buttonIndex] ??
            Object.freeze({ down: false, pressed: false, released: false }));
    }
}
//# sourceMappingURL=InputSnapshot.js.map