/* App: router por hash, Tweaks, banner de cookies, montaje. */
(function () {
const { useState, useEffect } = React;
const ACCENTS = {
"#FF7A6B": { deep: "#F0604F", tint: "#FFE7E2", rgb: "255, 122, 107" },
"#F5B342": { deep: "#E09A1F", tint: "#FDF1DC", rgb: "245, 179, 66" },
"#7CC4E8": { deep: "#3F9FD0", tint: "#E6F4FB", rgb: "124, 196, 232" },
};
const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
"accent": "#FF7A6B",
"heroVariant": "A",
"heroScale": 100,
"featuredCount": 6,
"anim": 6
}/*EDITMODE-END*/;
function applyTweaks(t) {
const root = document.documentElement.style;
const a = ACCENTS[t.accent] || ACCENTS["#FF7A6B"];
root.setProperty("--accent", t.accent);
root.setProperty("--accent-deep", a.deep);
root.setProperty("--accent-tint", a.tint);
root.setProperty("--accent-shadow", a.rgb);
root.setProperty("--hero-scale", String(t.heroScale / 100));
root.setProperty("--anim", String(Math.round((t.anim / 6) * 100) / 100));
}
/* ----------------------------------------------------------- mini-thumbs hero */
const HERO_THUMBS = {
A: ,
B: ,
C: ,
};
function HeroTweak({ value, onChange }) {
return (
{["A", "B", "C"].map(k => (
))}
);
}
/* ----------------------------------------------------------------- cookies */
function Cookie() {
const [show, setShow] = useState(false);
useEffect(() => {
if (!localStorage.getItem("fun_cookie")) { const t = setTimeout(() => setShow(true), 1200); return () => clearTimeout(t); }
}, []);
const close = (v) => { localStorage.setItem("fun_cookie", v); setShow(false); };
return (
Usamos cookies para entender qué libros gustan más. Puedes aceptarlas o seguir solo con las necesarias.
);
}
/* ------------------------------------------------------------------- router */
function useHashRoute() {
const get = () => (window.location.hash.replace(/^#\/?/, "") || "home");
const [route, setRoute] = useState(get());
useEffect(() => {
const f = () => { setRoute(get()); window.scrollTo(0, 0); };
window.addEventListener("hashchange", f);
return () => window.removeEventListener("hashchange", f);
}, []);
const navigate = (to) => {
if (("#/" + to) === window.location.hash) { window.scrollTo({ top: 0, behavior: "smooth" }); return; }
window.location.hash = "#/" + to;
};
return [route, navigate];
}
function App() {
const [t, setTweak] = useTweaks(TWEAK_DEFAULTS);
const [route, navigate] = useHashRoute();
useEffect(() => { applyTweaks(t); }, [t.accent, t.heroScale, t.anim]);
const [head, ...rest] = route.split("/");
let page;
if (head === "libros") page = ;
else if (head === "libro") page = ;
else if (head === "sobre") page = ;
else if (head === "contacto") page = ;
else if (head === "privacidad") page = ;
else page = ;
return (
<>
{page}
{ setTweak("heroVariant", v); if (route.split("/")[0] !== "home") navigate("home"); }} />
setTweak("heroScale", v)} />
setTweak("accent", v)} />
setTweak("featuredCount", v)} />
setTweak("anim", v)} />
>
);
}
window.FunApp = App;
})();