{
const unido = fim > inicio || (fim === inicio && (incluiFim || incluiInicio));
const A = `[0, ${fim}${incluiFim ? "]" : ")"}`;
const B = `${incluiInicio ? "[" : "("}${inicio}, 8]`;
const uniao = unido ? "[0, 8]" : `${A} ∪ ${B}`;
const painel = document.createElement("section");
painel.setAttribute("aria-label", "Resultado da exploração");
const resultado = document.createElement("div");
resultado.setAttribute("aria-live", "polite");
resultado.setAttribute("aria-atomic", "true");
const expressao = document.createElement("p");
expressao.textContent = `A = ${A} · B = ${B} · A ∪ B = ${uniao}`;
const explicacao = document.createElement("p");
if (unido) explicacao.textContent = "A união é um único intervalo. Todos os pontos entre 0 e 8 estão incluídos.";
else if (fim === inicio) explicacao.textContent = `O ponto ${fim} ficou de fora. A união tem uma lacuna de um ponto.`;
else explicacao.textContent = `Os pontos entre ${fim} e ${inicio} ficaram de fora. A união tem duas partes.`;
resultado.append(expressao, explicacao);
painel.append(resultado);
const svgNS = "http://www.w3.org/2000/svg";
const add = (parent, name, attrs, text) => {
const node = document.createElementNS(svgNS, name);
for (const [key, value] of Object.entries(attrs)) node.setAttribute(key, value);
if (text !== undefined) node.textContent = text;
parent.append(node);
return node;
};
const svg = add(painel, "svg", {viewBox: "0 0 420 166", width: "100%", "aria-hidden": "true"});
const x = n => 66 + n * 40;
const reta = (label, y) => {
add(svg, "text", {x: 4, y: y + 5, fill: "#183f35", "font-size": 15}, label);
add(svg, "line", {x1: x(0) - 10, x2: x(8) + 10, y1: y, y2: y, stroke: "#809187"});
for (let n = 0; n <= 8; n++) {
add(svg, "line", {x1: x(n), x2: x(n), y1: y - 3, y2: y + 3, stroke: "#809187"});
}
};
const trecho = (y, desde, ate, fechadoDesde, fechadoAte, cor) => {
add(svg, "line", {x1: x(desde), x2: x(ate), y1: y, y2: y, stroke: cor, "stroke-width": 4});
for (const [extremo, fechado] of [[desde, fechadoDesde], [ate, fechadoAte]]) {
add(svg, "circle", {cx: x(extremo), cy: y, r: 5, fill: fechado ? cor : "white", stroke: cor, "stroke-width": 2});
}
};
reta("A", 25);
reta("B", 70);
reta("A ∪ B", 115);
trecho(25, 0, fim, true, incluiFim, "#225b49");
trecho(70, inicio, 8, incluiInicio, true, "#28589e");
if (unido) trecho(115, 0, 8, true, true, "#225b49");
else {
trecho(115, 0, fim, true, incluiFim, "#225b49");
trecho(115, inicio, 8, incluiInicio, true, "#225b49");
}
for (let n = 0; n <= 8; n++) {
add(svg, "text", {x: x(n), y: 148, fill: "#183f35", "font-size": 14, "text-anchor": "middle"}, n);
}
painel.setAttribute("data-trilhas-exploracao-pronta", "");
return painel;
}