// Keeps the CSS custom property --scroll-y on :root in sync with window.scrollY. // CSS handles all scroll-linked animation math from there. let rafPending = false; function updateScrollVariables() { // Unitless: Firefox does not coerce in calc(), so the // whole scroll pipeline stays in number space end-to-end. document.documentElement.style.setProperty("--scroll-y", window.scrollY); rafPending = false; } // Coalesce N scroll/resize events per frame into one rAF-timed DOM write. // Dropping intermediate events is safe — rAF reads the latest scrollY on fire. function handleScrollEvent() { if (rafPending) return; rafPending = true; requestAnimationFrame(updateScrollVariables); } // Initial sync write so --scroll-y reflects reality before first paint; // hash-nav and restored scroll positions would otherwise flash unscrolled. updateScrollVariables(); // scroll: passive so the browser doesn't wait on us before scrolling. // resize events aren't cancellable, so the hint is unnecessary there. window.addEventListener("scroll", handleScrollEvent, { passive: true }); window.addEventListener("resize", handleScrollEvent); // Popover API shim if (!("popover" in HTMLElement.prototype)) { // load fallback behavior, or use your old menu code }; CustomElementRegistry.prototype.apply = function(tag, component) { if (!(!!component.constructor && component.toString().substring(0,5) == "class")) { return }; if (this.get(tag)) { return }; if (this.getName(component)) { return }; try { this.define(tag, component) } catch(err) { console.debug(`component ${component.name} already registered as <${tag}>`); }; };