diff --git a/src/pages/api.astro b/src/pages/api.astro index c56f5da..86fad91 100644 --- a/src/pages/api.astro +++ b/src/pages/api.astro @@ -98,6 +98,14 @@ const specJson = JSON.stringify(specObject); } catch (_e) {} apply(resolve(value === 'auto' ? '' : value)); }; + // Read-only sibling of __warpApplyTheme: returns the resolved + // 'dark' | 'light' value without touching the DOM or localStorage. + // Used by the body-top inline script to apply the body class as + // soon as
is parsed, and by Scalar's config sync script + // to compute `cfg.darkMode` independently of body-class state. + window.__warpResolveTheme = function () { + return resolve(read()); + }; // Re-resolve when the system preference changes, but only if // we're following it (stored value is empty / unknown). prefersDark.addEventListener('change', function () { @@ -128,8 +136,48 @@ const specJson = JSON.stringify(specObject); else document.addEventListener('DOMContentLoaded', startMirror); })(); + +