function reveal(doc, toggle) {
const input = doc.getElementById(toggle.getAttribute('aria-controls'));
if (!input) return false;
const shown = input.type === 'password';
input.type = shown ? 'text' : 'password';
toggle.setAttribute('aria-pressed', String(shown));
const label = toggle.getAttribute(shown ? 'data-hide-label' : 'data-show-label');
if (label) toggle.setAttribute('aria-label', label);
return shown;
}
function install(doc) {
doc.addEventListener('click', (e) => {
const toggle = e.target.closest && e.target.closest('[data-password-toggle]');
if (toggle) reveal(doc, toggle);
});
}
if (typeof document !== 'undefined') {
install(document);
}
if (typeof module !== 'undefined' && module.exports) {
module.exports = { install, reveal };
}