Files
taboada-registros/frontend/theme.js
T
Collina Systems ee265c15e8 Rediseño visual de checada.html (piel cream) sobre theme.js
Reconstruye la pantalla de checada con el lenguaje visual del diseño
(paleta crema, tipografías Bricolage Grotesque/Figtree, íconos de línea,
logo de la Fundación) sin tocar la lógica ni el cableado al backend.

theme.js:
- Nuevo set "cream" (Logo, IconBadge, Card, Btn, Input, Aviso, Estado)
  que devuelve makeUI("checada"); añade paleta CREAM, fuentes de marca e
  íconos SVG (nfc, amanecer, luna, check, reloj, refresh, candado…).
- El camino panel/becario queda intacto (misma API COLORS/FONT); la
  fidelidad de estilos de esos dos flavors no cambia.

checada.html:
- Migra la vista a los componentes cream; Estado pasa de emoji a
  icon+tone. Los 13 estados del inventario se conservan y cada uno sigue
  disparándose por su MISMO code/parámetro (cerrado, TOKEN_*,
  BECARIO_NO_ACTIVO, CONFLICTO_TIPO, duplicada…). Endpoints, campos
  (t/tipo/concepto), toggle entrada/salida, gate de concepto y link a
  becario.html sin cambios. Sin marcos de iPhone ni barra de estado.

logo-taboada.png: logo de marca servido same-origin.
Dockerfile: hornea el logo en la imagen de producción.
2026-07-06 13:05:44 -06:00

313 lines
17 KiB
JavaScript

/*
* theme.js — base visual compartida de las tres pantallas (panel/becario/checada).
*
* Sin build step: se carga como <script src="theme.js"> DESPUÉS de React/ReactDOM
* y ANTES del <script type="text/babel"> de cada página. Expone window.Theme con:
* - COLORS paleta unificada (base común de los tres + primaryDark/accentBg del panel)
* - FONT stack tipográfico del sistema
* - SPACE escala de espaciado (para el rediseño)
* - RADIUS escala de radios
* - makeUI(flavor) → { Btn, Card, Input, Badge, Field, Estado }
*
* Los componentes viven UNA sola vez aquí; makeUI(flavor) los liga a las medidas
* exactas de cada página ('panel' escritorio, 'becario'/'checada' móvil) para que
* el resultado se vea idéntico al de hoy. El rediseño se hace tocando este archivo.
*/
window.Theme = (function () {
var 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",
};
var FONT = "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif";
var SPACE = { none: "0", xs: "4px", sm: "8px", md: "12px", lg: "16px", xl: "20px", "2xl": "24px", "3xl": "32px" };
var RADIUS = { sm: "8px", md: "10px", lg: "12px", xl: "14px", "2xl": "16px", pill: "999px" };
// ── Rediseño de checada: paleta crema + fuentes de marca (flavor 'checada') ──
// No afecta a panel/becario: sus componentes siguen usando COLORS/FONT.
var CREAM = {
bg: "#F3EBDD",
bgGradient: "radial-gradient(120% 80% at 50% -10%, #FBF5EA 0%, #F3EBDD 55%, #EFE5D3 100%)",
surface: "#FFFFFF", cardBorder: "#F0E8DA",
ink: "#2E2A24", inkSoft: "#8A8175", label: "#6E6559", placeholder: "#B4A99A", line: "#E4D9C6",
brand: "#16406B", primary: "#2E77B8", primaryDark: "#25689F",
green: "#2F8A63", greenDark: "#287854", amber: "#B7791F", danger: "#C0392B",
greenTint: "#E4F1E9", blueTint: "#E7F0F8", amberTint: "#FBF0DC", dangerTint: "#FBEBE8",
errBg: "#FBEBE8", errBorder: "#F3D3CC", errText: "#B4362A",
warnBg: "#FBF0DC", warnBorder: "#EFD9A8", warnText: "#8A5A12",
inputBorder: "#ECE3D4", inputBg: "#FBF8F2", track: "#EDE4D5", dashed: "#C7DBEC",
};
var FONT_TITLE = "'Bricolage Grotesque', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif";
var FONT_BODY = "'Figtree', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif";
// Vocabulario de tonos de Badge, unión de los dos que usaban panel y becario.
var TONES = {
chip: { bg: COLORS.chip, color: COLORS.inkSoft },
success: { bg: COLORS.successBg, color: COLORS.success },
warn: { bg: COLORS.warnBg, color: COLORS.warn },
danger: { bg: COLORS.dangerBg, color: COLORS.danger },
primary: { bg: COLORS.accentBg, color: COLORS.primaryDark },
pendiente: { bg: COLORS.warnBg, color: COLORS.warn },
activo: { bg: COLORS.successBg, color: COLORS.success },
baja: { bg: COLORS.chip, color: COLORS.inkSoft },
};
// Medidas exactas por página (reproducen el look actual, píxel por píxel).
var FLAVORS = {
panel: {
card: { radius: RADIUS.lg, pad: "20px", shadow: "0 1px 3px rgba(0,0,0,0.04)", mb: undefined },
input: { pad: "9px 11px", radius: RADIUS.sm, font: "14px" },
badge: { pad: "2px 9px", nowrap: true },
btn: {
block: false, weight: 600, radius: RADIUS.sm, disabledInk: true, transition: "opacity .15s",
sizes: { sm: { pad: "6px 12px", font: "13px" }, md: { pad: "10px 18px", font: "14px" } },
defaultSize: "md",
},
},
becario: {
card: { radius: RADIUS.xl, pad: "18px", shadow: undefined, mb: "14px" },
input: { pad: "12px 14px", radius: RADIUS.md, font: "16px" },
badge: { pad: "3px 10px", nowrap: false },
btn: {
block: true, weight: 700, radius: RADIUS.md, disabledInk: false, transition: undefined,
sizes: { md: { pad: "13px", font: "15px" } }, defaultSize: "md",
},
},
checada: {
card: { radius: RADIUS["2xl"], pad: "24px", shadow: undefined, mb: undefined },
input: { pad: "13px 14px", radius: RADIUS.md, font: "16px" },
badge: { pad: "3px 10px", nowrap: false },
btn: {
block: true, weight: 700, radius: RADIUS.md, disabledInk: false, transition: undefined,
sizes: { md: { pad: "14px", font: "16px" } }, defaultSize: "md",
},
},
};
function btnVariant(v) {
switch (v) {
case "success": return { bg: COLORS.success, color: "#fff", border: "none" };
case "danger": return { bg: COLORS.danger, color: "#fff", border: "none" };
case "ghost": return { bg: "transparent", color: COLORS.primary, border: "1px solid " + COLORS.border };
case "subtle": return { bg: COLORS.chip, color: COLORS.ink, border: "none" };
default: return { bg: COLORS.primary, color: "#fff", border: "none" };
}
}
// ── Íconos de línea del rediseño (name -> función(opts) -> <svg>) ──
// opts: { size, color, sw (stroke-width), style }. Sin dependencias externas.
function makeIcons(React) {
var h = React.createElement;
function ic(paths, o) {
o = o || {};
var kids = paths.map(function (p, i) { return h(p[0], Object.assign({ key: i }, p[1])); });
return h("svg", {
width: o.size || 28, height: o.size || 28, viewBox: "0 0 24 24", fill: "none",
stroke: o.color || "currentColor", strokeWidth: o.sw || 1.7,
strokeLinecap: "round", strokeLinejoin: "round", style: o.style,
}, kids);
}
return {
nfc: function (o) { return ic([["rect",{x:6,y:2.5,width:9,height:19,rx:2.5}],["path",{d:"M18 8a5 5 0 0 1 0 8"}],["path",{d:"M20.6 5.4a8.5 8.5 0 0 1 0 13.2"}]], o); },
sunrise: function (o) { return ic([["path",{d:"M12 2.6v2.6"}],["path",{d:"M4.7 8 6.3 9.6"}],["path",{d:"M19.3 8 17.7 9.6"}],["path",{d:"M2.4 15h3"}],["path",{d:"M18.6 15h3"}],["path",{d:"M8 15a4 4 0 0 1 8 0"}],["path",{d:"M1.6 19h20.8"}]], o); },
moon: function (o) { return ic([["path",{d:"M20 14.6A8 8 0 1 1 9.4 4a6.5 6.5 0 0 0 10.6 10.6z"}]], o); },
check: function (o) { return ic([["path",{d:"M21.6 11.1V12a9.6 9.6 0 1 1-5.7-8.8"}],["path",{d:"M8.6 11.5 12 15l9.6-9.6"}]], o); },
hourglass: function (o) { return ic([["path",{d:"M6.5 3h11"}],["path",{d:"M6.5 21h11"}],["path",{d:"M7.5 3v3.1a5 5 0 0 0 2.8 4.5L12 12l1.7-1.4A5 5 0 0 0 16.5 6.1V3"}],["path",{d:"M7.5 21v-3.1a5 5 0 0 1 2.8-4.5L12 12l1.7 1.4a5 5 0 0 1 2.5 4.5V21"}]], o); },
clock: function (o) { return ic([["circle",{cx:12,cy:12,r:8.6}],["path",{d:"M12 7.2V12l3.2 2"}]], o); },
refresh: function (o) { return ic([["path",{d:"M3.2 12a8.8 8.8 0 0 1 15.1-6.1L21 8"}],["path",{d:"M21 3.6V8h-4.4"}],["path",{d:"M20.8 12a8.8 8.8 0 0 1-15.1 6.1L3 16"}],["path",{d:"M3 20.4V16h4.4"}]], o); },
lock: function (o) { o = o || {}; return ic([["rect",{x:4.5,y:10.5,width:15,height:10.5,rx:3}],["path",{d:"M8 10.5V7a4 4 0 0 1 8 0v3.5"}],["circle",{cx:12,cy:15.6,r:1.4,fill:o.color||"currentColor",stroke:"none"}]], o); },
alertCircle: function (o) { return ic([["circle",{cx:12,cy:12,r:9.2}],["path",{d:"M12 7.6v5"}],["path",{d:"M12 16.2h.01"}]], o); },
alertTriangle: function (o) { return ic([["path",{d:"M12 3 2.6 20h18.8L12 3z"}],["path",{d:"M12 9.6v4"}],["path",{d:"M12 17h.01"}]], o); },
spinner: function (o) {
o = o || {};
return h("svg", { width: o.size || 18, height: o.size || 18, viewBox: "0 0 24 24", fill: "none",
style: Object.assign({ animation: "tb-spin .8s linear infinite" }, o.style || {}) },
[ h("circle", { key: 0, cx: 12, cy: 12, r: 9, stroke: o.track || "rgba(255,255,255,.35)", strokeWidth: 3 }),
h("path", { key: 1, d: "M21 12a9 9 0 0 0-9-9", stroke: o.color || "#fff", strokeWidth: 3, strokeLinecap: "round" }) ]);
},
};
}
// ── Set de componentes "cream" para el flavor 'checada' (rediseño visual) ──
// Devuelve su propia API (Logo, IconBadge, Card, Btn, Input, Aviso, Estado,
// palette, fonts, icons). Independiente del camino panel/becario.
function makeCream(React) {
var h = React.createElement;
var C = CREAM;
var fonts = { title: FONT_TITLE, body: FONT_BODY };
var icons = makeIcons(React);
// tone (string) -> stroke del glifo, tinte del círculo, color del título.
var STATE = {
green: { stroke: C.green, tint: C.greenTint, title: C.green },
blue: { stroke: C.primary, tint: C.blueTint, title: C.ink },
amber: { stroke: C.amber, tint: C.amberTint, title: C.amber },
danger: { stroke: C.danger, tint: C.dangerTint, title: C.danger },
};
function Logo(props) {
return h("img", { src: "logo-taboada.png", alt: "Fundación Taboada",
style: Object.assign({ height: "64px", width: "auto", display: "block" }, (props && props.style) || {}) });
}
function IconBadge(props) {
var t = STATE[props.tone] || STATE.blue;
var sz = props.size || 64;
var glyph = icons[props.icon] ? icons[props.icon]({ color: t.stroke, size: Math.round(sz * 0.47), sw: 1.7 }) : null;
return h("div", { style: { width: sz + "px", height: sz + "px", borderRadius: "50%", background: t.tint,
display: "flex", alignItems: "center", justifyContent: "center", margin: "0 auto 16px" } }, glyph);
}
function Card(props) {
return h("div", { style: Object.assign({
background: C.surface, border: "1px solid " + C.cardBorder, borderRadius: "26px",
padding: "24px", boxShadow: "0 20px 44px -28px rgba(33,28,22,.35)",
}, props.style || {}) }, props.children);
}
function Btn(props) {
var success = props.variant === "success";
var bg = success ? C.green : C.primary;
var shadow = success ? "0 12px 22px -10px rgba(47,138,99,.75)" : "0 12px 22px -10px rgba(46,119,184,.75)";
var disabled = props.disabled;
var style = {
width: "100%", boxSizing: "border-box", padding: "15px", border: "none", borderRadius: "16px",
background: disabled ? "#C6CFD8" : bg, color: disabled ? "#F4F8FC" : "#fff",
fontFamily: fonts.body, fontSize: "15px", fontWeight: 700,
cursor: disabled ? "not-allowed" : (props.loading ? "progress" : "pointer"),
boxShadow: disabled ? "none" : shadow,
display: "flex", alignItems: "center", justifyContent: "center", gap: "10px",
};
var kids = [];
if (props.loading) kids.push(h("span", { key: "s", style: { display: "inline-flex" } }, icons.spinner({ size: 18 })));
kids.push(h("span", { key: "t" }, props.children));
return h("button", { type: props.type || "button", onClick: props.onClick, disabled: disabled, style: style }, kids);
}
function Input(props) {
var rest = Object.assign({}, props); delete rest.style;
var style = Object.assign({
width: "100%", boxSizing: "border-box", padding: "14px 15px",
border: "1.5px solid " + C.inputBorder, borderRadius: "15px", background: C.inputBg,
fontFamily: fonts.body, fontSize: "15px", color: C.ink, outline: "none",
}, props.style || {});
return h("input", Object.assign(rest, { style: style }));
}
function Aviso(props) {
var warn = props.variant === "warn";
var box = warn
? { bg: C.warnBg, bd: C.warnBorder, text: C.warnText, ink: C.amber }
: { bg: C.errBg, bd: C.errBorder, text: C.errText, ink: C.danger };
var glyph = icons[props.icon] ? icons[props.icon]({ color: box.ink, size: 18, style: { flexShrink: 0 } }) : null;
return h("div", { style: { display: "flex", gap: "10px", alignItems: "flex-start",
background: box.bg, border: "1px solid " + box.bd, borderRadius: "14px", padding: "11px 13px", marginBottom: "14px" } },
[ glyph ? h("span", { key: "i", style: { display: "inline-flex", flexShrink: 0, marginTop: "1px" } }, glyph) : null,
h("span", { key: "t", style: { fontFamily: fonts.body, fontSize: "13px", fontWeight: 500, color: box.text, lineHeight: 1.45 } }, props.children) ]);
}
// Patrón ícono-en-círculo + título + mensaje (+ progreso / acción opcionales).
// props.tone: "green" | "blue" | "amber" | "danger"; props.icon: nombre en icons.
function Estado(props) {
var t = STATE[props.tone] || STATE.blue;
var cardStyle = { textAlign: "center", padding: "28px 24px" };
if (props.dashed) cardStyle.border = "1.5px dashed " + C.dashed;
var kids = [
h(IconBadge, { key: "i", icon: props.icon, tone: props.tone }),
h("h2", { key: "t", style: { margin: "0 0 8px", fontFamily: fonts.title, fontWeight: 600,
fontSize: "21px", color: t.title, letterSpacing: "-.01em", lineHeight: 1.2 } }, props.title),
];
if (props.sub) kids.push(h("p", { key: "s", style: { margin: 0, fontFamily: fonts.body,
fontWeight: 400, fontSize: "14px", color: C.inkSoft, lineHeight: 1.55 } }, props.sub));
if (typeof props.progress === "number") kids.push(
h("div", { key: "pg", style: { height: "8px", borderRadius: "99px", background: C.track, marginTop: "16px", overflow: "hidden" } },
h("div", { style: { height: "100%", width: Math.max(0, Math.min(100, props.progress)) + "%", borderRadius: "99px", background: C.green } })));
if (props.action) kids.push(h("div", { key: "a", style: { marginTop: "18px" } }, props.action));
return Card({ style: cardStyle, children: kids });
}
return { Logo: Logo, IconBadge: IconBadge, Card: Card, Btn: Btn, Input: Input,
Aviso: Aviso, Estado: Estado, palette: C, fonts: fonts, icons: icons };
}
function makeUI(flavor) {
var React = window.React;
var h = React.createElement;
if (flavor === "checada") return makeCream(React); // rediseño: set cream propio
var F = FLAVORS[flavor];
if (!F) throw new Error("Theme.makeUI: flavor desconocido '" + flavor + "'");
function Card(props) {
var base = {
background: COLORS.surface, border: "1px solid " + COLORS.border,
borderRadius: F.card.radius, padding: F.card.pad,
boxShadow: F.card.shadow, marginBottom: F.card.mb,
};
return h("div", { style: Object.assign(base, props.style || {}) }, props.children);
}
function Btn(props) {
var v = btnVariant(props.variant);
var size = F.btn.sizes[props.size || F.btn.defaultSize] || F.btn.sizes[F.btn.defaultSize];
var disabled = props.disabled;
var style = {
padding: size.pad, borderRadius: F.btn.radius,
background: disabled ? COLORS.border : v.bg,
color: disabled && F.btn.disabledInk ? COLORS.inkSoft : v.color,
border: v.border,
fontFamily: FONT, fontSize: size.font, fontWeight: F.btn.weight,
cursor: disabled ? "not-allowed" : "pointer",
transition: F.btn.transition,
};
if (F.btn.block) style.width = "100%";
return h("button", { type: props.type || "button", onClick: props.onClick, disabled: disabled, style: style }, props.children);
}
function Input(props) {
var rest = Object.assign({}, props);
delete rest.style;
var style = Object.assign({
width: "100%", padding: F.input.pad, borderRadius: F.input.radius,
border: "1px solid " + COLORS.border, fontSize: F.input.font,
fontFamily: FONT, color: COLORS.ink, boxSizing: "border-box", outline: "none",
}, props.style || {});
return h("input", Object.assign(rest, { style: style }));
}
function Badge(props) {
var t = TONES[props.tone] || TONES.chip;
var style = {
background: t.bg, color: t.color, padding: F.badge.pad,
borderRadius: RADIUS.pill, fontSize: "12px", fontWeight: 700,
};
if (F.badge.nowrap) style.whiteSpace = "nowrap";
return h("span", { style: style }, props.children);
}
function Field(props) {
return h("label", { style: { display: "block", marginBottom: "12px" } },
h("span", { style: { display: "block", fontSize: "13px", fontWeight: 600, color: COLORS.inkSoft, marginBottom: "5px" } }, props.label),
props.children
);
}
// Patrón ícono + título + mensaje (+ botón opcional) de las pantallas de estado.
// `tone` es un COLOR (no un tono de badge): tiñe el título.
function Estado(props) {
var kids = [
h("div", { key: "e", style: { fontSize: "44px", marginBottom: "8px" } }, props.emoji),
h("h2", { key: "t", style: { margin: "0 0 6px", color: props.tone || COLORS.ink, fontSize: "20px" } }, props.title),
];
if (props.sub) kids.push(h("p", { key: "s", style: { margin: 0, color: COLORS.inkSoft, fontSize: "14px", lineHeight: 1.5 } }, props.sub));
if (props.action) kids.push(h("div", { key: "a", style: { marginTop: "16px" } }, props.action));
return Card({ style: { textAlign: "center" }, children: kids });
}
return { Btn: Btn, Card: Card, Input: Input, Badge: Badge, Field: Field, Estado: Estado };
}
return { COLORS: COLORS, FONT: FONT, SPACE: SPACE, RADIUS: RADIUS, makeUI: makeUI };
})();