sirius/js/theme.js
Local Dev 4d9fa1c026 site-sirius-x: content stays centred; drop the sidenav padding-left shift
Every Sirius.X page had a leftover
  @media (min-width: 721px) { header.hero, .wrap { padding-left: calc(var(--sn-w) + 1.2rem) } }
that shifted the whole reading column right by the sidebar width. On a
1400px viewport that pushed the "Names on the chain" hero and every
section off-axis — the search input, the Try it cards, the Pantheon
grid all sat right of centre while the sidebar hogged the empty left
gutter. The sidenav is a pointer-events:none overlay at opacity 0.35
now, so text peeking under the semi-transparent rail is by design;
padding the content away from it defeats the whole point of an
overlay design and creates the shifted-body layout the user flagged
in the screenshot.

Removed on index, tld, docs, admin, brand and theseus/. Content
returns to the middle of the viewport regardless of sidebar width.
2026-09-22 01:10:05 +02:00

104 lines
5.5 KiB
JavaScript

// Sirius.X font picker — reader chooses between Fraunces (Silent Mode
// family — editorial serif, default) and Ubuntu (Bitcoin Cash brand
// font — humanist sans). Persisted in localStorage under 'sirius-font'.
//
// The runtime attribute goes on <html> — pages that want to opt out
// simply omit the include. The actual font-swap CSS is defined per
// page (in each page's <style> block) so it can override the page's
// own font-family declarations at high specificity; this script only
// toggles the attribute and paints the picker UI.
(function () {
var KEY = "sirius-font";
var saved = null;
try { saved = localStorage.getItem(KEY); } catch (e) { /* private mode */ }
var initial = saved === "ubuntu" ? "ubuntu" : "fraunces";
if (initial === "ubuntu") document.documentElement.setAttribute("data-font-cmp", "ubuntu");
// Inject the picker's own base + positioning styles once, so pages
// that never declared `.font-picker` in their stylesheet still render
// the widget correctly (previously the toggle appeared as raw browser
// buttons on pages that forgot to copy the CSS block). The styles are
// scoped to `.font-picker-float` so pages that DO define their own
// `.font-picker` styling win via source-order (this block runs first).
(function ensureStyles() {
if (document.getElementById("sirius-font-picker-style")) return;
var css =
// Every dimension is reset explicitly (bottom/left/height/width auto,
// margin 0, line-height 1) so this block wins over any per-page
// `.font-picker`/`.font-picker-float` styling — earlier pages declared
// .font-picker-float with bottom:20px, which combined with top:56px
// stretched the pill down the full viewport height.
".font-picker-float{" +
"position:fixed !important;top:56px !important;right:20px !important;" +
"bottom:auto !important;left:auto !important;" +
"height:auto !important;width:auto !important;margin:0 !important;" +
"z-index:30 !important;" +
"display:inline-flex !important;align-items:center;gap:2px;padding:2px !important;" +
"background:rgba(11,14,20,.82) !important;border:1px solid rgba(255,255,255,.08) !important;" +
"border-radius:999px !important;backdrop-filter:blur(10px);" +
"box-shadow:0 6px 20px rgba(0,0,0,.35);" +
"font-family:'JetBrains Mono',ui-monospace,monospace !important;" +
"font-size:10px !important;line-height:1 !important;" +
"letter-spacing:.12em !important;text-transform:uppercase !important" +
"}" +
".font-picker-float button{" +
"background:transparent !important;border:none !important;color:#6a7488 !important;" +
"padding:4px 10px !important;margin:0 !important;border-radius:999px !important;cursor:pointer;" +
"font-family:inherit !important;font-size:inherit !important;line-height:1 !important;" +
"letter-spacing:inherit !important;" +
"text-transform:inherit !important;transition:color .12s" +
"}" +
".font-picker-float button:hover{color:#f1f4fa !important}" +
".font-picker-float button.active{background:#d6ff3d !important;color:#050810 !important;font-weight:600 !important}" +
// On mobile the pill stays in the top-right — earlier it flipped to
// bottom-right so it wouldn't crowd narrow nav layouts, but the mobile
// sidenav now lives at the bottom edge and the two collided. Keep the
// toggle where readers already know to look; just tighten the offset a
// touch so it sits against the corner.
"@media (max-width:520px){.font-picker-float{top:12px !important;right:12px !important;bottom:auto !important}}";
var el = document.createElement("style");
el.id = "sirius-font-picker-style";
el.textContent = css;
document.head.appendChild(el);
})();
// Mount the picker as a floating pill in the page's top-right corner,
// just under the sticky nav's sign-in button. Was previously injected
// inline in the topnav; that placement crowded the nav on narrow
// viewports and left users hunting for the toggle. A fixed-position
// widget keeps the choice equally reachable on every page — including
// ones without a topnav — and does not participate in nav layout.
function paintPicker() {
var mount = document.createElement("div");
mount.className = "font-picker font-picker-float";
mount.setAttribute("role", "group");
mount.setAttribute("aria-label", "Reading font");
mount.innerHTML =
'<button data-font="fraunces" title="Silent Mode family (Fraunces)">Fraunces</button>' +
'<button data-font="ubuntu" title="Bitcoin Cash brand font (Ubuntu)">Ubuntu</button>';
document.body.appendChild(mount);
var btns = mount.querySelectorAll("button");
function refresh(v) {
for (var i = 0; i < btns.length; i++) {
btns[i].classList.toggle("active", btns[i].dataset.font === v);
}
}
refresh(initial);
for (var i = 0; i < btns.length; i++) {
btns[i].addEventListener("click", function (e) {
var v = e.currentTarget.dataset.font;
if (v === "ubuntu") document.documentElement.setAttribute("data-font-cmp", "ubuntu");
else document.documentElement.removeAttribute("data-font-cmp");
try { localStorage.setItem(KEY, v); } catch (e2) { /* ignore */ }
refresh(v);
});
}
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", paintPicker);
} else {
paintPicker();
}
})();