"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.matchWidthModifier = exports.closeOnEscPlugin = void 0;
const core_1 = require("../core");
/** Closes the popper if 'Escape' is pressed. Tippy plugin. */
exports.closeOnEscPlugin = {
    name: 'closeOnEsc',
    defaultValue: true,
    fn({ hide }) {
        function onKeyDown(e) {
            if (e.key === core_1.KeyboardKeys.Escape)
                hide();
        }
        return {
            onHide() {
                document.removeEventListener('keydown', onKeyDown);
            },
            onShow() {
                document.addEventListener('keydown', onKeyDown);
            },
        };
    },
};
/** Sets popper width to be the same as reference. Updates on resize, etc. Popper modifier. */
exports.matchWidthModifier = {
    name: 'matchWidth',
    enabled: true,
    phase: 'beforeWrite',
    requires: ['computeStyles'],
    fn: ({ state }) => {
        state.styles.popper.width = `${state.rects.reference.width}px`;
    },
    effect: ({ state }) => () => {
        const reference = state.elements.reference;
        state.elements.popper.style.width = `${reference.offsetWidth}px`;
    },
};
//# sourceMappingURL=consts.js.map