@marianmeres/stuic 3.125.1 → 3.126.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,11 +27,20 @@
27
27
  -->
28
28
  <svelte:head>
29
29
  <script>
30
- const KEY = window.__COLOR_SCHEME_KEY__ ?? "stuic-color-scheme";
31
- const cls = window.document.documentElement.classList;
32
- const v = localStorage.getItem(KEY);
33
- if (v === "dark") cls.add("dark");
34
- else if (v === "light") cls.remove("dark");
35
- // else: no stored preference leave the SSR'd class alone.
30
+ // Block-scoped on purpose: a classic <script>'s top-level const/let lands
31
+ // in the page's global lexical scope and persists even after the node is
32
+ // removed. If this body ever runs a second time in the same realm — e.g.
33
+ // Svelte re-inserting <svelte:head> while recovering from a hydration
34
+ // mismatch an unscoped `const KEY` throws "Identifier 'KEY' has already
35
+ // been declared" and aborts hydration. The braces make re-execution a
36
+ // harmless no-op (and keep KEY/cls/v out of the global namespace). Do not unwrap.
37
+ {
38
+ const KEY = window.__COLOR_SCHEME_KEY__ ?? "stuic-color-scheme";
39
+ const cls = window.document.documentElement.classList;
40
+ const v = localStorage.getItem(KEY);
41
+ if (v === "dark") cls.add("dark");
42
+ else if (v === "light") cls.remove("dark");
43
+ // else: no stored preference — leave the SSR'd class alone.
44
+ }
36
45
  </script>
37
46
  </svelte:head>
@@ -24,12 +24,21 @@
24
24
  -->
25
25
  <svelte:head>
26
26
  <script>
27
- const KEY = window.__COLOR_SCHEME_KEY__ ?? "stuic-color-scheme";
28
- const cls = window.document.documentElement.classList;
29
- if (KEY in localStorage) {
30
- localStorage.getItem(KEY) === "dark" ? cls.add("dark") : cls.remove("dark");
31
- } else if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
32
- cls.add("dark");
27
+ // Block-scoped on purpose: a classic <script>'s top-level const/let lands
28
+ // in the page's global lexical scope and persists even after the node is
29
+ // removed. If this body ever runs a second time in the same realm — e.g.
30
+ // Svelte re-inserting <svelte:head> while recovering from a hydration
31
+ // mismatch an unscoped `const KEY` throws "Identifier 'KEY' has already
32
+ // been declared" and aborts hydration. The braces make re-execution a
33
+ // harmless no-op (and keep KEY/cls out of the global namespace). Do not unwrap.
34
+ {
35
+ const KEY = window.__COLOR_SCHEME_KEY__ ?? "stuic-color-scheme";
36
+ const cls = window.document.documentElement.classList;
37
+ if (KEY in localStorage) {
38
+ localStorage.getItem(KEY) === "dark" ? cls.add("dark") : cls.remove("dark");
39
+ } else if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
40
+ cls.add("dark");
41
+ }
33
42
  }
34
43
  </script>
35
44
  </svelte:head>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/stuic",
3
- "version": "3.125.1",
3
+ "version": "3.126.0",
4
4
  "packageManager": "pnpm@11.5.0",
5
5
  "scripts": {
6
6
  "dev": "vite dev",