import { KeyboardKeys } from '../core';
/** Closes the popper if 'Escape' is pressed. Tippy plugin. */
export const closeOnEscPlugin = {
    name: 'closeOnEsc',
    defaultValue: true,
    fn({ hide }) {
        function onKeyDown(e) {
            if (e.key === 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. */
export const 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