Files
inbraille/public/modules/braille_data.js
T
Lucas RayanandClaude Opus 5.5 07aaf8e1a7
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
feat: novo site e interface; tradução Braille no navegador (1.4.0)
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>
2026-11-15 19:51:53 -03:00

84 lines
7.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Tabelas de Braille (porte fiel de src/domain/alphabets.py, braille_codes.py e chinese_braille.py).
// Somente dados e funcoes puras de tabela; a logica fica em translator.js.
// NOTA: as tabelas sao copias literais dos dados originais (inclusive o ":'" fundido da lista
// norte-americana) para que a saida seja byte a byte identica a do servidor Python.
export const BRAZILIAN = {
normal: ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "á", "é", "í", "ó", "ú", "à", "â", "ê", "ô", "ã", "õ", "ç", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "!", "?", ".", ",", ";", ":", "(", ")", "[", "]", "-", "+", "/", "*", "&", "$", "%", "=", "<", ">"],
braille: ["⠁", "⠃", "⠉", "⠙", "⠑", "⠋", "⠛", "⠓", "⠊", "⠚", "⠅", "⠇", "⠍", "⠝", "⠕", "⠏", "⠟", "⠗", "⠎", "⠞", "⠥", "⠧", "⠺", "⠭", "⠽", "⠵", "⠷", "⠿", "⠌", "⠬", "⠾", "⠫", "⠡", "⠣", "⠹", "⠜", "⠪", "⠯", "⠚", "⠁", "⠃", "⠉", "⠙", "⠑", "⠋", "⠛", "⠓", "⠊", "⠖", "⠢", "⠄", "⠂", "⠆", "⠒", "⠣⠄", "⠄⠜", "⠷⠄", "⠄⠾", "⠤", "⠖", "⠠⠂", "⠔", "⠯", "⠰", "⠸⠴", "⠶", "⠪", "⠕"],
};
export const NORTH_AMERICAN = {
normal: ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "!", "?", "&", "$", "#", "@", "%", "(", ")", "[", "]", "_", "+", "-", "*", "/", "\\", "=", "<", ">", ".", ",", ";", ":'", "\""],
braille: ["⠁", "⠃", "⠉", "⠙", "⠑", "⠋", "⠛", "⠓", "⠊", "⠚", "⠅", "⠇", "⠍", "⠝", "⠕", "⠏", "⠟", "⠗", "⠎", "⠞", "⠥", "⠧", "⠺", "⠭", "⠽", "⠵", "⠴", "⠂", "⠆", "⠒", "⠲", "⠢", "⠖", "⠶", "⠦", "⠔", "⠮", "⠹", "⠯", "⠫", "⠼", "⠈", "⠩", "⠷", "⠾", "⠪", "⠻", "⠸", "⠬", "⠤", "⠡", "⠌", "⠳", "⠿", "⠣", "⠜", "⠨", "⠠", "⠰", "⠱", "⠄", "⠐"],
};
// Codigo de 6 pontos (dot1..dot6) de cada celula Braille.
export const BRAILLE_CODES = new Map([["⠁", "100000"], ["⠃", "110000"], ["⠉", "100100"], ["⠙", "100110"], ["⠑", "100010"], ["⠋", "110100"], ["⠛", "110110"], ["⠓", "110010"], ["⠊", "010100"], ["⠚", "010110"], ["⠅", "101000"], ["⠇", "111000"], ["⠍", "101100"], ["⠝", "101110"], ["⠕", "101010"], ["⠏", "111100"], ["⠟", "111110"], ["⠗", "111010"], ["⠎", "011100"], ["⠞", "011110"], ["⠥", "101001"], ["⠧", "111001"], ["⠺", "010111"], ["⠭", "101101"], ["⠽", "101111"], ["⠵", "101011"], ["⠴", "001011"], ["⠂", "010000"], ["⠆", "011000"], ["⠒", "010010"], ["⠲", "010011"], ["⠢", "010001"], ["⠖", "011010"], ["⠶", "011011"], ["⠦", "011001"], ["⠔", "001010"], ["⠮", "011101"], ["⠹", "100111"], ["⠯", "111101"], ["⠫", "110101"], ["⠼", "001111"], ["⠈", "000100"], ["⠩", "100101"], ["⠷", "111011"], ["⠾", "011111"], ["⠪", "010101"], ["⠻", "110111"], ["⠸", "000111"], ["⠬", "001101"], ["⠤", "001001"], ["⠡", "100001"], ["⠌", "001100"], ["⠿", "111111"], ["⠣", "110001"], ["⠜", "001110"], ["⠨", "000101"], ["⠠", "000001"], ["⠰", "000011"], ["⠱", "100011"], ["⠄", "001000"], ["⠐", "000010"], ["⣄", "011001"]]);
export function codeFor(character) {
const mapped = BRAILLE_CODES.get(character);
if (mapped !== undefined) return mapped;
const value = character.codePointAt(0) - 0x2800;
let out = "";
for (let bit = 0; bit < 6; bit++) out += (value >> bit) & 1 ? "1" : "0";
return out;
}
// ---- Braille chines (mandarim) ----
// Fonte: Australian Braille Authority, "Chinese (Mandarin) and UEB" (maio de 2024).
// Uma silaba = inicial + final + tom. Padroes de pontos 1-6 viram celulas Unicode via cell().
// Maps preservam a ordem de insercao (importante para "mantem a primeira grafia").
export function cell(dots) {
let value = 0;
for (const dot of dots) value |= 1 << (parseInt(dot, 10) - 1);
return String.fromCodePoint(0x2800 + value);
}
export const BLANK = cell("");
const INITIAL_DOTS = new Map([["b", "12"], ["p", "1234"], ["m", "134"], ["f", "124"], ["d", "145"], ["t", "2345"], ["n", "1345"], ["l", "123"], ["g", "1245"], ["j", "1245"], ["k", "13"], ["q", "13"], ["h", "125"], ["x", "125"], ["zh", "34"], ["ch", "12345"], ["sh", "156"], ["r", "245"], ["z", "1356"], ["c", "14"], ["s", "234"]]);
const FINAL_DOTS = new Map([["a", "35"], ["o", "26"], ["e", "26"], ["i", "24"], ["yi", "24"], ["u", "136"], ["wu", "136"], ["ü", "346"], ["yu", "346"], ["v", "346"], ["er", "1235"], ["ai", "246"], ["ao", "235"], ["ei", "2346"], ["ou", "12356"], ["ia", "1246"], ["ya", "1246"], ["iao", "345"], ["yao", "345"], ["ie", "15"], ["ye", "15"], ["iu", "1256"], ["you", "1256"], ["ua", "123456"], ["wa", "123456"], ["uai", "13456"], ["wai", "13456"], ["ui", "2456"], ["wei", "2456"], ["uo", "135"], ["wo", "135"], ["üe", "23456"], ["yue", "23456"], ["ve", "23456"], ["an", "1236"], ["ang", "236"], ["en", "356"], ["eng", "3456"], ["ian", "146"], ["yan", "146"], ["iang", "1346"], ["yang", "1346"], ["in", "126"], ["yin", "126"], ["ing", "16"], ["ying", "16"], ["uan", "12456"], ["wan", "12456"], ["uang", "2356"], ["wang", "2356"], ["un", "25"], ["wen", "25"], ["ong", "256"], ["weng", "256"], ["üan", "12346"], ["yuan", "12346"], ["van", "12346"], ["ün", "456"], ["yun", "456"], ["vn", "456"], ["iong", "1456"], ["yong", "1456"]]);
const TONE_DOTS = new Map([["1", "1"], ["2", "2"], ["3", "3"], ["4", "23"]]);
const PUNCTUATION_DOTS = new Map([[",", ["5"]], [",", ["5"]], ["、", ["4"]], [";", ["56"]], [";", ["56"]], [":", ["36"]], [":", ["36"]], [".", ["5", "23"]], ["。", ["5", "23"]], ["?", ["5", "3"]], ["?", ["5", "3"]], ["!", ["56", "2"]], ["!", ["56", "2"]], ["-", ["36"]], ["…", ["5", "5", "5"]]]);
export const BUZZING_INITIALS = ["zh", "ch", "sh", "r", "z", "c", "s"];
export const YU_INITIALS = ["j", "q", "x"];
export const ACCENTS = new Map([["ā", ["a", "1"]], ["á", ["a", "2"]], ["ǎ", ["a", "3"]], ["à", ["a", "4"]], ["ō", ["o", "1"]], ["ó", ["o", "2"]], ["ǒ", ["o", "3"]], ["ò", ["o", "4"]], ["ē", ["e", "1"]], ["é", ["e", "2"]], ["ě", ["e", "3"]], ["è", ["e", "4"]], ["ī", ["i", "1"]], ["í", ["i", "2"]], ["ǐ", ["i", "3"]], ["ì", ["i", "4"]], ["ū", ["u", "1"]], ["ú", ["u", "2"]], ["ǔ", ["u", "3"]], ["ù", ["u", "4"]], ["ǖ", ["ü", "1"]], ["ǘ", ["ü", "2"]], ["ǚ", ["ü", "3"]], ["ǜ", ["ü", "4"]], ["ü", ["ü", ""]]]);
function mapValues(map, fn) {
const out = new Map();
for (const [k, v] of map) out.set(k, fn(v));
return out;
}
export const INITIAL_CELLS = mapValues(INITIAL_DOTS, cell);
export const FINAL_CELLS = mapValues(FINAL_DOTS, cell);
export const TONE_CELLS = mapValues(TONE_DOTS, cell);
export const PUNCTUATION_CELLS = mapValues(PUNCTUATION_DOTS, (cells) => cells.map(cell).join(""));
// Reverso celula -> grafia, mantendo a primeira grafia (setdefault do Python).
function first(map) {
const reverse = new Map();
for (const [spelling, c] of map) if (!reverse.has(c)) reverse.set(c, spelling);
return reverse;
}
export const INITIAL_BY_CELL = first(INITIAL_CELLS);
export const FINAL_BY_CELL = first(FINAL_CELLS);
// Final sem inicial usa a grafia isolada com y/w.
export const FINAL_STANDALONE_BY_CELL = new Map();
for (const [spelling, c] of FINAL_CELLS) {
if ("yw".includes(spelling[0]) && !FINAL_STANDALONE_BY_CELL.has(c)) FINAL_STANDALONE_BY_CELL.set(c, spelling);
}
for (const [c, plain] of FINAL_BY_CELL) {
if (!FINAL_STANDALONE_BY_CELL.has(c)) FINAL_STANDALONE_BY_CELL.set(c, plain);
}
export const TONE_BY_CELL = new Map();
for (const [tone, c] of TONE_CELLS) TONE_BY_CELL.set(c, tone);
export const PUNCTUATION_BY_CELL = new Map();
for (const [ch, cells] of PUNCTUATION_DOTS) PUNCTUATION_BY_CELL.set(cells.map(cell).join(""), ch);