From 743440968b9f6d4348575446e2a32303d7d8f388 Mon Sep 17 00:00:00 2001 From: Collina Systems Date: Sun, 5 Jul 2026 14:28:34 -0600 Subject: [PATCH] refactor(frontend): extrae el lenguaje visual duplicado a theme.js compartido MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sin cambio visual ni de comportamiento — solo elimina la triplicación. - theme.js expone COLORS (unificada), FONT, SPACE, RADIUS y makeUI(flavor) con los componentes compartidos Btn/Card/Input/Badge/Field/Estado - 'flavor' (panel/becario/checada) reproduce las medidas exactas de cada página (escritorio vs móvil) para que se vea idéntico a hoy - los tres HTML cargan theme.js y usan makeUI en vez de sus defs locales; checada renombra su componente Big → Estado (compartido) - Dockerfile hornea theme.js para producción Verificado headless: transpila, monta sin throw y reproduce los estilos originales píxel por píxel (react-dom/server + asserts de estilo). --- backend/Dockerfile | 2 +- frontend/becario.html | 32 ++------- frontend/checada.html | 51 ++++---------- frontend/panel.html | 55 ++------------- frontend/theme.js | 159 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 183 insertions(+), 116 deletions(-) create mode 100644 frontend/theme.js diff --git a/backend/Dockerfile b/backend/Dockerfile index bd9f1e0..b501298 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -21,7 +21,7 @@ COPY --chown=node:node backend/src ./src # stat/leer los archivos; copiar con `--chmod=644 … /dir/` deja el propio # directorio en 0644 y nginx falla con "Permission denied". Por eso se fijan # los permisos explícitamente después del COPY. -COPY frontend/checada.html frontend/panel.html frontend/becario.html /usr/share/nginx/html/ +COPY frontend/checada.html frontend/panel.html frontend/becario.html frontend/theme.js /usr/share/nginx/html/ RUN chmod 755 /usr/share/nginx/html && chmod 644 /usr/share/nginx/html/*.html COPY --chmod=644 backend/nginx-default.conf /etc/nginx/http.d/default.conf COPY --chmod=755 backend/docker-entrypoint.sh /docker-entrypoint.sh diff --git a/frontend/becario.html b/frontend/becario.html index e708c4e..6924582 100644 --- a/frontend/becario.html +++ b/frontend/becario.html @@ -7,6 +7,7 @@ +
@@ -29,12 +30,9 @@ async function apiFetch(path, options = {}) { return data; } -const COLORS = { - bg: "#EEF1F4", surface: "#FFFFFF", ink: "#1F2933", inkSoft: "#616E7C", - border: "#DDE2E7", primary: "#2A6FB0", success: "#2E7D5B", successBg: "#E7F3EC", - warn: "#B7791F", warnBg: "#FBF2E1", danger: "#C0392B", dangerBg: "#FBEBE9", chip: "#F0F2F5", -}; -const FONT = "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif"; +// Base visual compartida (theme.js), ligada al flavor 'becario'. +const { COLORS, FONT, SPACE, RADIUS, makeUI } = Theme; +const { Btn, Card, Input, Badge, Field, Estado } = makeUI("becario"); function fmtDT(iso) { if (!iso) return "—"; @@ -45,28 +43,6 @@ function fmtDT(iso) { const fmtHoras = (h) => `${(h ?? 0).toLocaleString("es-MX", { maximumFractionDigits: 1 })} h`; function localToIso(v) { return v ? new Date(v).toISOString() : null; } -const inputStyle = { - width: "100%", padding: "12px 14px", borderRadius: "10px", border: `1px solid ${COLORS.border}`, - fontSize: "16px", fontFamily: FONT, color: COLORS.ink, boxSizing: "border-box", outline: "none", -}; -const Input = (p) => ; -const Btn = ({ children, onClick, variant = "primary", disabled, type = "button" }) => { - const V = { primary: COLORS.primary, success: COLORS.success, ghost: "transparent", danger: COLORS.danger }[variant]; - const ghost = variant === "ghost"; - return ; -}; -const Card = ({ children, style }) => ( -
{children}
-); -const Badge = ({ children, tone }) => { - const T = { pendiente: [COLORS.warnBg, COLORS.warn], activo: [COLORS.successBg, COLORS.success], baja: [COLORS.chip, COLORS.inkSoft] }[tone] || [COLORS.chip, COLORS.inkSoft]; - return {children}; -}; const ErrorBar = ({ error, onClose }) => !error ? null : (
⚠ {error}✕ diff --git a/frontend/checada.html b/frontend/checada.html index c8eadf4..bce24f4 100644 --- a/frontend/checada.html +++ b/frontend/checada.html @@ -7,12 +7,17 @@ +
+
@@ -36,13 +37,9 @@ async function apiFetch(path, options = {}) { return data; } -const COLORS = { - bg: "#EEF1F4", surface: "#FFFFFF", ink: "#1F2933", inkSoft: "#616E7C", - border: "#DDE2E7", primary: "#2A6FB0", primaryDark: "#1E4E7E", - success: "#2E7D5B", successBg: "#E7F3EC", warn: "#B7791F", warnBg: "#FBF2E1", - danger: "#C0392B", dangerBg: "#FBEBE9", chip: "#F0F2F5", accentBg: "#EAF2FA", -}; -const FONT = "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif"; +// Base visual compartida (theme.js), ligada al flavor 'panel'. +const { COLORS, FONT, SPACE, RADIUS, makeUI } = Theme; +const { Btn, Card, Input, Badge, Field, Estado } = makeUI("panel"); // ── Formato (presentación en America/Mexico_City, §7) ── function fmtDT(iso) { @@ -61,49 +58,7 @@ function isoToLocal(iso) { } function localToIso(v) { return v ? new Date(v).toISOString() : null; } -// ═══════════════════ UI primitivos ═══════════════════ -const Btn = ({ children, onClick, variant = "primary", disabled, size = "md", type = "button" }) => { - const V = { - primary: { bg: COLORS.primary, c: "#fff", bd: "none" }, - success: { bg: COLORS.success, c: "#fff", bd: "none" }, - danger: { bg: COLORS.danger, c: "#fff", bd: "none" }, - ghost: { bg: "transparent", c: COLORS.primary, bd: `1px solid ${COLORS.border}` }, - subtle: { bg: COLORS.chip, c: COLORS.ink, bd: "none" }, - }[variant]; - const pad = size === "sm" ? "6px 12px" : "10px 18px"; - return ( - - ); -}; -const Card = ({ children, style }) => ( -
{children}
-); -const Field = ({ label, children }) => ( - -); -const inputStyle = { - width: "100%", padding: "9px 11px", borderRadius: "8px", border: `1px solid ${COLORS.border}`, - fontSize: "14px", fontFamily: FONT, color: COLORS.ink, boxSizing: "border-box", outline: "none", -}; -const Input = (p) => ; -const Badge = ({ children, tone = "chip" }) => { - const T = { - chip: { bg: COLORS.chip, c: COLORS.inkSoft }, success: { bg: COLORS.successBg, c: COLORS.success }, - warn: { bg: COLORS.warnBg, c: COLORS.warn }, danger: { bg: COLORS.dangerBg, c: COLORS.danger }, - primary: { bg: COLORS.accentBg, c: COLORS.primaryDark }, - }[tone]; - return {children}; -}; +// ErrorBar y los helpers de tono son locales del panel (no compartidos). const ErrorBar = ({ error, onClose }) => !error ? null : (
diff --git a/frontend/theme.js b/frontend/theme.js new file mode 100644 index 0000000..d470a5a --- /dev/null +++ b/frontend/theme.js @@ -0,0 +1,159 @@ +/* + * theme.js — base visual compartida de las tres pantallas (panel/becario/checada). + * + * Sin build step: se carga como