htmx-router 2.2.4 → 2.2.5

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.
@@ -14,18 +14,19 @@ function ClientMounter() {
14
14
  return current;
15
15
  },
16
16
  apply: () => document.documentElement.setAttribute('data-theme', theme.get()),
17
- set: (next) => {
18
- localStorage.setItem("theme", next);
17
+ set: (value, sync = true) => {
18
+ localStorage.setItem("theme", value);
19
19
  theme.apply();
20
- channel.postMessage({ type: 'set', theme: next });
20
+ if (sync)
21
+ channel.postMessage({ type: 'set', theme: value });
21
22
  return theme;
22
23
  },
23
24
  toggle: () => {
24
- const next = theme.get() === 'dark' ? 'light' : 'dark';
25
- localStorage.setItem("theme", next);
25
+ const value = theme.get() === 'dark' ? 'light' : 'dark';
26
+ localStorage.setItem("theme", value);
26
27
  theme.apply();
27
- channel.postMessage({ type: 'set', theme: next });
28
- return theme;
28
+ channel.postMessage({ type: 'set', theme: value });
29
+ return value;
29
30
  }
30
31
  };
31
32
  const channel = new BroadcastChannel('hx-theme');
@@ -34,12 +35,9 @@ function ClientMounter() {
34
35
  return;
35
36
  const next = event.data.theme;
36
37
  if (next === 'light')
37
- localStorage.setItem("theme", 'light');
38
+ theme.set('light', false);
38
39
  if (next === 'dark')
39
- localStorage.setItem("theme", 'dark');
40
- else
41
- return; // no-op on unrecognised
42
- theme.apply();
40
+ theme.set('dark', false);
43
41
  });
44
42
  /**
45
43
  * based on https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "htmx-router",
3
- "version": "2.2.4",
3
+ "version": "2.2.5",
4
4
  "description": "A lightweight SSR framework with server+client islands",
5
5
  "keywords": [ "htmx", "router", "client islands", "ssr", "vite" ],
6
6
  "type": "module",