PageSourceSearch

https://eulaw.ai/prepaint/landing-theme.js

js eulaw.ai collected 2026-10-05 12:55:00 UTC 2,052 bytes, 43 lines download raw bytes

1/* Marketing theme, applied before the page paints.
2
3   IN <body>, NOT <svelte:head>, and that is the whole point.
4
5   This used to live in routes/+layout.svelte's <svelte:head>, where it
6   could never work: scripts in <head> run while document.body is still
7   null, so `document.body.classList.add(...)` threw a TypeError on every
8   single load. The surrounding try/catch — there for private-mode
9   localStorage — swallowed it silently, so nothing ever surfaced. The
10   light theme was actually being applied by each page's own onMount, and
11   when that per-page code was removed the theme stopped sticking: pick
12   light, refresh, and the page came back dark.
13
14   Note the /app stamp above sets data-theme on document.documentElement,
15   which DOES exist in <head>. That is why the app never had this bug and
16   the marketing site did.
17
18   Here, one line into <body>, document.body exists and nothing has
19   painted yet — so the class lands with no flash.
20
21   Every marketing page is light unless the visitor chose dark;
22   toggleTheme in lib/script/site.js writes that choice. /app is excluded:
23   this is the shell for every route, and body.light-landing carries the
24   marketing site's light overrides, which would repaint the app. */
25(function () {
26  try {
27    // Strip the optional /da prefix so the Danish pages get the same
28    // defaults as their English counterparts.
29    const tPath = window.location.pathname.replace(/^\/da(?=\/|$)/, '') || '/';
30    if (/^\/(app|chat)(\/|$)/.test(tPath)) return;
31    // Light-only pages ignore a saved dark choice. Same test as
32    // isLightOnlyPath() in src/lib/theme.js; change both together.
33    if (/^\/(?:da(?:\/(?:hr|jura|ledelse|okonomi|public-affairs|pris))?\/?)?$/.test(window.location.pathname)) {
34      document.body.classList.add('light-landing');
35      return;
36    }
37    if (localStorage.getItem('eulaw_landing_theme') !== 'dark') {
38      document.body.classList.add('light-landing');
39    }
40  } catch (e) {
41    /* private mode / storage disabled — take the default */
42  }
43})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.