CI / Trivy (dependências, segredos e configuração) (push) Successful in 1m2s
CI / Testes e imagem Docker (linux/arm64) (push) Successful in 4m24s
Release / Plano (reaproveitar a imagem?) (push) Successful in 5s
Release / ci (push) Skipped
Release / Publica a imagem (linux/arm64) (push) Successful in 18s
Release / Cria a release no Gitea (push) Successful in 4s
Interface reescrita (design próprio, tema claro/escuro, a11y WCAG 2.2 AA), seções do site e artigo IDEIA @ CSBC 2025. Tradutor portado para JS com paridade 100% contra o Python; sem Tailwind nem axios. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
405 lines
18 KiB
JavaScript
405 lines
18 KiB
JavaScript
import { state } from './modules/state.js';
|
|
import { setLanguage } from './modules/i18n.js';
|
|
import { initConverterDOM, switchConversionMode, updateCharCount, updateActionStates, copyOutput, saveOutput, convert, clearInput } from './modules/converter.js';
|
|
import { announce } from './modules/ui.js';
|
|
import { getTranslation } from './modules/i18n.js';
|
|
import { initStlDOM, updateParameters, applyPointsOnlyState, updateInputs, generateSTL, downloadSTL, toggleAdvancedOptions, triggerRealtimePreview, openAdvancedOptionsOnDesktop } from './modules/stl.js';
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
// Gather all DOM elements
|
|
const elements = {
|
|
text_to_braille_tab: document.querySelector("#text_to_braille_tab"),
|
|
braille_to_text_tab: document.querySelector("#braille_to_text_tab"),
|
|
warning: document.querySelector("#warning"),
|
|
input_textbox: document.querySelector('#input_text'),
|
|
input_label: document.querySelector('#input_label'),
|
|
char_count: document.querySelector('#char_count'),
|
|
output_textbox: document.querySelector('#output_text'),
|
|
output_label: document.querySelector('#output_label'),
|
|
copy_button: document.querySelector('#copy_button'),
|
|
save_button: document.querySelector('#save_button'),
|
|
convert_button: document.querySelector('#convert_button'),
|
|
stl_button: document.querySelector('#stl_button'),
|
|
stl_preview: document.querySelector('#stl_preview'),
|
|
download_stl_button: document.querySelector('#download_stl_button'),
|
|
advanced_options: document.querySelector("#advanced_options"),
|
|
advanced_options_arrow: document.querySelector("#advanced_options_arrow"),
|
|
advanced_options_toggle: document.querySelector("#advanced_options_toggle"),
|
|
output_plate_width: document.querySelector("#plate_width"),
|
|
input_resolution: document.querySelector("#input_resolution"),
|
|
input_plate_thickness: document.querySelector("#input_plate_thickness"),
|
|
input_separate_plates: document.querySelector("#input_separate_plates"),
|
|
input_symbols_per_line: document.querySelector("#input_symbols_per_line"),
|
|
select_text_alignment: document.querySelector("#select_text_alignment"),
|
|
input_rounded: document.querySelector("#input_rounded"),
|
|
input_points_only: document.querySelector("#input_points_only")
|
|
};
|
|
|
|
// Initialize modules with DOM references
|
|
initConverterDOM(elements);
|
|
initStlDOM(elements);
|
|
|
|
// Initial value setup
|
|
if (elements.input_resolution) elements.input_resolution.value = state.resolution;
|
|
if (elements.input_plate_thickness) elements.input_plate_thickness.value = state.plate_thickness;
|
|
if (elements.input_separate_plates) elements.input_separate_plates.checked = !state.unique_plate;
|
|
if (elements.input_symbols_per_line) elements.input_symbols_per_line.value = state.symbols_per_line;
|
|
if (elements.select_text_alignment) elements.select_text_alignment.value = state.text_alignment;
|
|
if (elements.input_rounded) elements.input_rounded.checked = state.rounded;
|
|
if (elements.input_points_only) elements.input_points_only.checked = state.points_only;
|
|
if (elements.output_plate_width) elements.output_plate_width.innerHTML = state.plate_width.toFixed(1);
|
|
applyPointsOnlyState();
|
|
openAdvancedOptionsOnDesktop();
|
|
updateActionStates();
|
|
|
|
// Event listeners registration
|
|
if (elements.text_to_braille_tab) {
|
|
elements.text_to_braille_tab.addEventListener("click", () => switchConversionMode("text-to-braille"));
|
|
}
|
|
if (elements.braille_to_text_tab) {
|
|
elements.braille_to_text_tab.addEventListener("click", () => switchConversionMode("braille-to-text"));
|
|
}
|
|
let liveTypeDebounce = null;
|
|
if (elements.input_textbox) {
|
|
elements.input_textbox.addEventListener("input", () => {
|
|
updateCharCount();
|
|
if (elements.stl_preview && !elements.stl_preview.classList.contains("hidden")) {
|
|
clearTimeout(liveTypeDebounce);
|
|
liveTypeDebounce = setTimeout(async () => {
|
|
if (state.conversion_mode === "text-to-braille") {
|
|
await convert();
|
|
} else {
|
|
triggerRealtimePreview(60);
|
|
}
|
|
}, 250);
|
|
}
|
|
});
|
|
}
|
|
if (elements.output_textbox) {
|
|
elements.output_textbox.addEventListener("input", () => {
|
|
updateActionStates();
|
|
triggerRealtimePreview(60);
|
|
});
|
|
}
|
|
const alphabetRadios = document.querySelectorAll('input[name="alphabet"]');
|
|
alphabetRadios.forEach(radio => {
|
|
radio.addEventListener("change", () => {
|
|
if (elements.stl_preview && !elements.stl_preview.classList.contains("hidden")) {
|
|
convert();
|
|
}
|
|
});
|
|
});
|
|
if (elements.copy_button) {
|
|
elements.copy_button.addEventListener("click", copyOutput);
|
|
}
|
|
if (elements.save_button) {
|
|
elements.save_button.addEventListener("click", saveOutput);
|
|
}
|
|
if (elements.convert_button) {
|
|
elements.convert_button.addEventListener("click", convert);
|
|
}
|
|
if (elements.stl_button) {
|
|
elements.stl_button.addEventListener("click", generateSTL);
|
|
}
|
|
if (elements.download_stl_button) {
|
|
elements.download_stl_button.addEventListener("click", downloadSTL);
|
|
}
|
|
if (elements.advanced_options_toggle) {
|
|
elements.advanced_options_toggle.addEventListener("click", toggleAdvancedOptions);
|
|
}
|
|
|
|
if (elements.input_resolution) {
|
|
elements.input_resolution.addEventListener("input", updateParameters);
|
|
}
|
|
if (elements.input_plate_thickness) {
|
|
elements.input_plate_thickness.addEventListener("input", updateParameters);
|
|
}
|
|
if (elements.input_separate_plates) {
|
|
elements.input_separate_plates.addEventListener("input", updateParameters);
|
|
}
|
|
if (elements.input_symbols_per_line) {
|
|
elements.input_symbols_per_line.addEventListener("input", updateParameters);
|
|
elements.input_symbols_per_line.addEventListener("change", () => {
|
|
if (elements.output_textbox) elements.output_textbox.value = "";
|
|
updateActionStates();
|
|
});
|
|
}
|
|
if (elements.select_text_alignment) {
|
|
elements.select_text_alignment.addEventListener("input", updateParameters);
|
|
}
|
|
if (elements.input_rounded) {
|
|
elements.input_rounded.addEventListener("input", updateParameters);
|
|
}
|
|
if (elements.input_points_only) {
|
|
elements.input_points_only.addEventListener("input", () => {
|
|
updateParameters();
|
|
applyPointsOnlyState();
|
|
});
|
|
}
|
|
|
|
if (elements.input_resolution) elements.input_resolution.addEventListener("blur", updateInputs);
|
|
if (elements.input_plate_thickness) elements.input_plate_thickness.addEventListener("blur", updateInputs);
|
|
if (elements.input_separate_plates) elements.input_separate_plates.addEventListener("blur", updateInputs);
|
|
if (elements.input_symbols_per_line) {
|
|
elements.input_symbols_per_line.addEventListener("blur", () => {
|
|
updateInputs();
|
|
if (elements.output_textbox) elements.output_textbox.value = "";
|
|
updateActionStates();
|
|
});
|
|
}
|
|
if (elements.select_text_alignment) elements.select_text_alignment.addEventListener("blur", updateInputs);
|
|
if (elements.input_rounded) elements.input_rounded.addEventListener("blur", updateInputs);
|
|
|
|
// Helper to switch language and update dependent components
|
|
function changeLanguage(lang, callback) {
|
|
setLanguage(lang, () => {
|
|
switchConversionMode();
|
|
updateInputs();
|
|
if (callback) callback();
|
|
});
|
|
}
|
|
|
|
// Language switcher click handlers
|
|
document.querySelectorAll("#lang_dropdown button[data-lang]").forEach(button => {
|
|
button.addEventListener("click", (e) => {
|
|
const selectedLang = e.currentTarget.getAttribute("data-lang");
|
|
|
|
changeLanguage(selectedLang, () => {
|
|
syncThemeUI();
|
|
let newPath = "/";
|
|
if (selectedLang === "en") newPath = "/en";
|
|
else if (selectedLang === "zh") newPath = "/zh";
|
|
|
|
window.history.pushState(null, "", newPath);
|
|
});
|
|
});
|
|
});
|
|
|
|
// Clear button listener
|
|
const clearBtn = document.querySelector("#clear_button");
|
|
if (clearBtn) {
|
|
clearBtn.addEventListener("click", clearInput);
|
|
}
|
|
|
|
// Alphabet radio listener
|
|
document.querySelectorAll('input[name="alphabet"]').forEach(radio => {
|
|
radio.addEventListener("change", () => switchConversionMode());
|
|
});
|
|
|
|
|
|
// ---------- Roving-tabindex tablists (APG) ----------
|
|
function setupTablist(tabs, onActivate) {
|
|
tabs = tabs.filter(Boolean);
|
|
if (tabs.length < 2) return;
|
|
tabs.forEach((tab, i) => {
|
|
tab.addEventListener("keydown", (e) => {
|
|
let next = null;
|
|
if (e.key === "ArrowRight" || e.key === "ArrowDown") next = (i + 1) % tabs.length;
|
|
else if (e.key === "ArrowLeft" || e.key === "ArrowUp") next = (i - 1 + tabs.length) % tabs.length;
|
|
else if (e.key === "Home") next = 0;
|
|
else if (e.key === "End") next = tabs.length - 1;
|
|
if (next === null) return;
|
|
e.preventDefault();
|
|
tabs[next].focus();
|
|
onActivate(tabs[next]);
|
|
});
|
|
});
|
|
}
|
|
setupTablist([elements.text_to_braille_tab, elements.braille_to_text_tab], (tab) => tab.click());
|
|
|
|
// Citation tabs (BibTeX / ABNT)
|
|
const citeTabs = [document.getElementById("cite_tab_bibtex"), document.getElementById("cite_tab_abnt")];
|
|
function selectCiteTab(tab) {
|
|
citeTabs.forEach(t => {
|
|
if (!t) return;
|
|
const on = t === tab;
|
|
t.setAttribute("aria-selected", String(on));
|
|
t.setAttribute("tabindex", on ? "0" : "-1");
|
|
t.classList.toggle("tab-active", on);
|
|
const panel = document.getElementById(t.getAttribute("aria-controls"));
|
|
if (panel) panel.classList.toggle("hidden", !on);
|
|
});
|
|
}
|
|
citeTabs.forEach(t => t && t.addEventListener("click", () => selectCiteTab(t)));
|
|
setupTablist(citeTabs, selectCiteTab);
|
|
|
|
// ---------- Keyboard shortcuts ----------
|
|
if (elements.input_textbox) {
|
|
elements.input_textbox.addEventListener("keydown", (e) => {
|
|
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
e.preventDefault();
|
|
convert();
|
|
}
|
|
});
|
|
}
|
|
const langDropdown = document.getElementById("lang_dropdown");
|
|
document.addEventListener("keydown", (e) => {
|
|
if (e.key !== "Escape") return;
|
|
if (langDropdown && langDropdown.hasAttribute("open")) {
|
|
langDropdown.removeAttribute("open");
|
|
const summary = langDropdown.querySelector("summary");
|
|
if (summary) summary.focus();
|
|
}
|
|
closeNav(true);
|
|
});
|
|
document.addEventListener("click", (e) => {
|
|
if (langDropdown && langDropdown.hasAttribute("open") && !langDropdown.contains(e.target)) {
|
|
langDropdown.removeAttribute("open");
|
|
}
|
|
});
|
|
|
|
// ---------- Theme ----------
|
|
const themeToggle = document.getElementById("theme_toggle");
|
|
const prefersDark = window.matchMedia ? window.matchMedia("(prefers-color-scheme: dark)") : null;
|
|
function isDarkEffective() {
|
|
const t = document.documentElement.dataset.theme;
|
|
if (t === "dark") return true;
|
|
if (t === "light") return false;
|
|
return !!(prefersDark && prefersDark.matches);
|
|
}
|
|
function syncThemeUI() {
|
|
const dark = isDarkEffective();
|
|
if (typeof window.setPreviewTheme === "function") window.setPreviewTheme(dark);
|
|
if (!themeToggle) return;
|
|
themeToggle.setAttribute("aria-pressed", String(dark));
|
|
const icon = themeToggle.querySelector("i");
|
|
if (icon) icon.className = dark ? "fas fa-sun" : "fas fa-moon";
|
|
const label = getTranslation(dark ? "theme_light" : "theme_dark");
|
|
if (label) themeToggle.setAttribute("title", label);
|
|
}
|
|
if (themeToggle) {
|
|
themeToggle.addEventListener("click", () => {
|
|
const next = isDarkEffective() ? "light" : "dark";
|
|
document.documentElement.dataset.theme = next;
|
|
try { localStorage.setItem("inbraille-theme", next); } catch (e) { /* ignore */ }
|
|
syncThemeUI();
|
|
});
|
|
}
|
|
if (prefersDark && prefersDark.addEventListener) prefersDark.addEventListener("change", syncThemeUI);
|
|
syncThemeUI();
|
|
// preview.js is a module and may load after this one
|
|
window.addEventListener("load", syncThemeUI);
|
|
|
|
// ---------- Mobile nav ----------
|
|
const navToggle = document.getElementById("nav_toggle");
|
|
const siteNav = document.getElementById("site_nav");
|
|
const siteHeader = document.querySelector(".site-header") || document.querySelector("header");
|
|
function closeNav(returnFocus) {
|
|
if (!navToggle || navToggle.getAttribute("aria-expanded") !== "true") return;
|
|
navToggle.setAttribute("aria-expanded", "false");
|
|
if (siteHeader) siteHeader.classList.remove("nav-open");
|
|
if (returnFocus) navToggle.focus();
|
|
}
|
|
if (navToggle) {
|
|
navToggle.addEventListener("click", () => {
|
|
const open = navToggle.getAttribute("aria-expanded") !== "true";
|
|
navToggle.setAttribute("aria-expanded", String(open));
|
|
if (siteHeader) siteHeader.classList.toggle("nav-open", open);
|
|
});
|
|
}
|
|
if (siteNav) {
|
|
siteNav.querySelectorAll("a").forEach(a => a.addEventListener("click", () => closeNav(false)));
|
|
}
|
|
|
|
// ---------- Citation copy ----------
|
|
function setupCopy(buttonId, blockId) {
|
|
const btn = document.getElementById(buttonId);
|
|
const block = document.getElementById(blockId);
|
|
if (!btn || !block) return;
|
|
btn.addEventListener("click", async () => {
|
|
const text = block.textContent.trim();
|
|
let ok = false;
|
|
try {
|
|
if (navigator.clipboard) { await navigator.clipboard.writeText(text); ok = true; }
|
|
} catch (e) { /* fall through */ }
|
|
if (!ok) {
|
|
try {
|
|
const ta = document.createElement("textarea");
|
|
ta.value = text;
|
|
ta.setAttribute("readonly", "");
|
|
ta.style.position = "fixed";
|
|
ta.style.opacity = "0";
|
|
document.body.appendChild(ta);
|
|
ta.select();
|
|
ok = document.execCommand("copy");
|
|
document.body.removeChild(ta);
|
|
} catch (e) { ok = false; }
|
|
}
|
|
if (!ok) return;
|
|
const label = btn.querySelector("[data-i18n]") || btn;
|
|
const original = label.textContent;
|
|
const copied = getTranslation("paper_copied") || "Copied";
|
|
label.textContent = copied;
|
|
announce(copied);
|
|
setTimeout(() => { label.textContent = getTranslation(label.getAttribute("data-i18n")) || original; }, 2000);
|
|
});
|
|
}
|
|
setupCopy("copy_bibtex", "bibtex_block");
|
|
setupCopy("copy_abnt", "abnt_block");
|
|
|
|
// ---------- Reveal on scroll + active nav link ----------
|
|
const reduceMotion = window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
const revealEls = document.querySelectorAll(".reveal");
|
|
if (revealEls.length) {
|
|
if (reduceMotion || !("IntersectionObserver" in window)) {
|
|
revealEls.forEach(el => el.classList.add("is-visible"));
|
|
} else {
|
|
const showAll = () => revealEls.forEach(el => el.classList.add("is-visible"));
|
|
const io = new IntersectionObserver((entries) => {
|
|
entries.forEach(entry => {
|
|
if (entry.isIntersecting) {
|
|
entry.target.classList.add("is-visible");
|
|
io.unobserve(entry.target);
|
|
}
|
|
});
|
|
}, { rootMargin: "0px 0px 15% 0px", threshold: 0 });
|
|
revealEls.forEach(el => io.observe(el));
|
|
// Rede de segurança: nunca deixar conteúdo escondido
|
|
setTimeout(showAll, 1500);
|
|
window.addEventListener("beforeprint", showAll);
|
|
window.addEventListener("hashchange", showAll);
|
|
}
|
|
}
|
|
if (siteNav && "IntersectionObserver" in window) {
|
|
const links = Array.from(siteNav.querySelectorAll('a[href^="#"]'));
|
|
const map = new Map();
|
|
links.forEach(a => {
|
|
const sec = document.getElementById(a.getAttribute("href").slice(1));
|
|
if (sec) map.set(sec, a);
|
|
});
|
|
const navIo = new IntersectionObserver((entries) => {
|
|
entries.forEach(entry => {
|
|
if (!entry.isIntersecting) return;
|
|
links.forEach(a => a.removeAttribute("aria-current"));
|
|
const a = map.get(entry.target);
|
|
if (a) a.setAttribute("aria-current", "true");
|
|
});
|
|
}, { rootMargin: "-35% 0px -60% 0px" });
|
|
map.forEach((_, sec) => navIo.observe(sec));
|
|
}
|
|
|
|
// Skip link / CTA to the converter: move focus to it
|
|
document.querySelectorAll('a[href="#conversor"]').forEach(a => {
|
|
a.addEventListener("click", () => {
|
|
const target = document.getElementById("conversor");
|
|
if (target) setTimeout(() => target.focus({ preventScroll: true }), 0);
|
|
});
|
|
});
|
|
|
|
// Determine and set initial language and default alphabet
|
|
const path = window.location.pathname;
|
|
let initialLang = "pt-BR";
|
|
if (path.startsWith("/en")) {
|
|
initialLang = "en";
|
|
const radio = document.getElementById("north-american");
|
|
if (radio) radio.checked = true;
|
|
} else if (path.startsWith("/zh")) {
|
|
initialLang = "zh";
|
|
const radio = document.getElementById("chinese");
|
|
if (radio) radio.checked = true;
|
|
} else {
|
|
const radio = document.getElementById("brazilian");
|
|
if (radio) radio.checked = true;
|
|
}
|
|
changeLanguage(initialLang, syncThemeUI);
|
|
}); |