import React, { useState, useEffect, useRef } from 'react'; import './botaoacessibilidade.css'; // Importando o CSS import { setTheme } from '../assets/static/js/components/dark'; function BotaoAcessibilidade() { const [isMenuOpen, setIsMenuOpen] = useState(false); const [isReadOnHoverActive, setIsReadOnHoverActive] = useState(false); const [isDarkMode, setIsDarkMode] = useState(false); const lastSpokenTargetRef = useRef(null); useEffect(() => { setTheme(isDarkMode ? "dark" : "light", true); }, [isDarkMode]); useEffect(() => { if (!isReadOnHoverActive) { window.speechSynthesis.cancel(); return; } const handleMouseOver = (event) => { const target = event.target; if (target && target !== lastSpokenTargetRef.current && target.innerText) { const text = target.innerText.trim(); if (text.length > 0 && ['P', 'H1', 'H2', 'H3', 'BUTTON', 'A', 'LI', 'LABEL'].includes(target.tagName)) { lastSpokenTargetRef.current = target; window.speechSynthesis.cancel(); const utterance = new SpeechSynthesisUtterance(text); utterance.lang = 'pt-BR'; window.speechSynthesis.speak(utterance); } } }; document.body.addEventListener('mouseover', handleMouseOver); return () => { document.body.removeEventListener('mouseover', handleMouseOver); window.speechSynthesis.cancel(); }; }, [isReadOnHoverActive]); const handleVlibrasClick = () => { const originalVlibrasButton = document.querySelector('[vw-access-button]'); if (originalVlibrasButton) { originalVlibrasButton.click(); } else { alert("O Vlibras não pôde ser ativado."); } setIsMenuOpen(false); }; const handleReadAloud = () => { const selectedText = window.getSelection().toString().trim(); if (selectedText) { window.speechSynthesis.cancel(); const utterance = new SpeechSynthesisUtterance(selectedText); utterance.lang = 'pt-BR'; window.speechSynthesis.speak(utterance); } else { alert("Por favor, selecione um texto para ler em voz alta."); } setIsMenuOpen(false); }; return (
Acessibilidade
); } export default BotaoAcessibilidade;