@lolyjs/core 0.2.0-alpha.8 → 0.3.0-alpha.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.
Files changed (57) hide show
  1. package/README.md +1593 -762
  2. package/dist/{bootstrap-DgvWWDim.d.mts → bootstrap-BfGTMUkj.d.mts} +12 -0
  3. package/dist/{bootstrap-DgvWWDim.d.ts → bootstrap-BfGTMUkj.d.ts} +12 -0
  4. package/dist/cli.cjs +16397 -2601
  5. package/dist/cli.cjs.map +1 -1
  6. package/dist/cli.mjs +19096 -0
  7. package/dist/cli.mjs.map +1 -0
  8. package/dist/index.cjs +17419 -3204
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.mts +323 -56
  11. package/dist/index.d.ts +323 -56
  12. package/dist/index.mjs +20236 -0
  13. package/dist/index.mjs.map +1 -0
  14. package/dist/index.types-Duhjyfit.d.mts +280 -0
  15. package/dist/index.types-Duhjyfit.d.ts +280 -0
  16. package/dist/react/cache.cjs +82 -32
  17. package/dist/react/cache.cjs.map +1 -1
  18. package/dist/react/cache.d.mts +29 -21
  19. package/dist/react/cache.d.ts +29 -21
  20. package/dist/react/{cache.js → cache.mjs} +84 -34
  21. package/dist/react/cache.mjs.map +1 -0
  22. package/dist/react/components.cjs +11 -12
  23. package/dist/react/components.cjs.map +1 -1
  24. package/dist/react/{components.js → components.mjs} +12 -13
  25. package/dist/react/components.mjs.map +1 -0
  26. package/dist/react/hooks.cjs +28 -54
  27. package/dist/react/hooks.cjs.map +1 -1
  28. package/dist/react/hooks.d.mts +1 -24
  29. package/dist/react/hooks.d.ts +1 -24
  30. package/dist/react/{hooks.js → hooks.mjs} +27 -52
  31. package/dist/react/hooks.mjs.map +1 -0
  32. package/dist/react/sockets.cjs +5 -6
  33. package/dist/react/sockets.cjs.map +1 -1
  34. package/dist/react/sockets.mjs +21 -0
  35. package/dist/react/sockets.mjs.map +1 -0
  36. package/dist/react/themes.cjs +61 -18
  37. package/dist/react/themes.cjs.map +1 -1
  38. package/dist/react/{themes.js → themes.mjs} +64 -21
  39. package/dist/react/themes.mjs.map +1 -0
  40. package/dist/runtime.cjs +465 -117
  41. package/dist/runtime.cjs.map +1 -1
  42. package/dist/runtime.d.mts +2 -2
  43. package/dist/runtime.d.ts +2 -2
  44. package/dist/{runtime.js → runtime.mjs} +466 -118
  45. package/dist/runtime.mjs.map +1 -0
  46. package/package.json +26 -19
  47. package/dist/cli.js +0 -5291
  48. package/dist/cli.js.map +0 -1
  49. package/dist/index.js +0 -6015
  50. package/dist/index.js.map +0 -1
  51. package/dist/react/cache.js.map +0 -1
  52. package/dist/react/components.js.map +0 -1
  53. package/dist/react/hooks.js.map +0 -1
  54. package/dist/react/sockets.js +0 -22
  55. package/dist/react/sockets.js.map +0 -1
  56. package/dist/react/themes.js.map +0 -1
  57. package/dist/runtime.js.map +0 -1
@@ -1,59 +1,35 @@
1
1
  // modules/react/hooks/useBroadcastChannel/index.tsx
2
- import { useEffect, useState } from "react";
2
+ import { useEffect, useState, useRef, useCallback } from "react";
3
3
  var useBroadcastChannel = (channelName) => {
4
4
  const [message, setMessage] = useState(null);
5
- const channel = new BroadcastChannel(channelName);
5
+ const channelRef = useRef(null);
6
6
  useEffect(() => {
7
+ if (!channelRef.current && typeof window !== "undefined") {
8
+ channelRef.current = new BroadcastChannel(channelName);
9
+ }
10
+ const channel = channelRef.current;
11
+ if (!channel) return;
7
12
  const handleMessage = (event) => {
8
13
  setMessage(event.data);
9
14
  };
10
15
  channel.onmessage = handleMessage;
11
16
  return () => {
12
- channel.close();
13
- };
14
- }, [channel]);
15
- const sendMessage = (msg) => {
16
- channel.postMessage(msg);
17
- };
18
- return { message, sendMessage };
19
- };
20
-
21
- // modules/react/hooks/usePageProps/index.ts
22
- import { useEffect as useEffect2, useState as useState2 } from "react";
23
- function usePageProps() {
24
- const [state, setState] = useState2(() => {
25
- if (typeof window !== "undefined" && window?.__FW_DATA__) {
26
- const data = window.__FW_DATA__;
27
- return {
28
- params: data.params || {},
29
- props: data.props || {}
30
- };
31
- }
32
- return {
33
- params: {},
34
- props: {}
35
- };
36
- });
37
- useEffect2(() => {
38
- const handleDataRefresh = () => {
39
- if (window?.__FW_DATA__) {
40
- const data = window.__FW_DATA__;
41
- setState({
42
- params: data.params || {},
43
- props: data.props || {}
44
- });
17
+ if (channelRef.current) {
18
+ channelRef.current.close();
19
+ channelRef.current = null;
45
20
  }
46
21
  };
47
- window.addEventListener("fw-data-refresh", handleDataRefresh);
48
- return () => {
49
- window.removeEventListener("fw-data-refresh", handleDataRefresh);
50
- };
22
+ }, [channelName]);
23
+ const sendMessage = useCallback((msg) => {
24
+ if (channelRef.current) {
25
+ channelRef.current.postMessage(msg);
26
+ }
51
27
  }, []);
52
- return { params: state.params, props: state.props };
53
- }
28
+ return { message, sendMessage };
29
+ };
54
30
 
55
31
  // modules/react/hooks/useRouter/index.ts
56
- import { useState as useState3, useEffect as useEffect3, useCallback, useContext as useContext2, useRef } from "react";
32
+ import { useState as useState2, useEffect as useEffect2, useCallback as useCallback2, useContext as useContext2, useRef as useRef2 } from "react";
57
33
 
58
34
  // modules/runtime/client/RouterContext.tsx
59
35
  import { createContext, useContext } from "react";
@@ -82,11 +58,11 @@ function getRouterData() {
82
58
  function useRouter() {
83
59
  const context = useContext2(RouterContext);
84
60
  const navigate = context?.navigate;
85
- const navigateRef = useRef(navigate);
86
- useEffect3(() => {
61
+ const navigateRef = useRef2(navigate);
62
+ useEffect2(() => {
87
63
  navigateRef.current = navigate;
88
64
  }, [navigate]);
89
- const [routeData, setRouteData] = useState3(() => {
65
+ const [routeData, setRouteData] = useState2(() => {
90
66
  if (typeof window === "undefined") {
91
67
  return {
92
68
  pathname: "",
@@ -106,7 +82,7 @@ function useRouter() {
106
82
  params: routerData?.params || data?.params || {}
107
83
  };
108
84
  });
109
- useEffect3(() => {
85
+ useEffect2(() => {
110
86
  if (typeof window === "undefined") return;
111
87
  const handleDataRefresh = () => {
112
88
  const data = getWindowData();
@@ -134,7 +110,7 @@ function useRouter() {
134
110
  window.removeEventListener("popstate", handlePopState);
135
111
  };
136
112
  }, []);
137
- const push = useCallback(
113
+ const push = useCallback2(
138
114
  async (url, options) => {
139
115
  const fullUrl = url.startsWith("/") ? url : `/${url}`;
140
116
  const getCurrentNavigate = () => {
@@ -170,7 +146,7 @@ function useRouter() {
170
146
  [navigate]
171
147
  // Include navigate in dependencies so it updates when context becomes available
172
148
  );
173
- const replace = useCallback(
149
+ const replace = useCallback2(
174
150
  async (url, options) => {
175
151
  const fullUrl = url.startsWith("/") ? url : `/${url}`;
176
152
  const getCurrentNavigate = () => {
@@ -201,12 +177,12 @@ function useRouter() {
201
177
  },
202
178
  [navigate]
203
179
  );
204
- const back = useCallback(() => {
180
+ const back = useCallback2(() => {
205
181
  if (typeof window !== "undefined") {
206
182
  window.history.back();
207
183
  }
208
184
  }, []);
209
- const refresh = useCallback(async () => {
185
+ const refresh = useCallback2(async () => {
210
186
  const currentUrl = typeof window !== "undefined" ? window.location.pathname + window.location.search : routeData.pathname;
211
187
  const getCurrentNavigate = () => {
212
188
  if (navigateRef.current) return navigateRef.current;
@@ -259,7 +235,6 @@ function parseQueryString(search) {
259
235
  }
260
236
  export {
261
237
  useBroadcastChannel,
262
- usePageProps,
263
238
  useRouter
264
239
  };
265
- //# sourceMappingURL=hooks.js.map
240
+ //# sourceMappingURL=hooks.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../modules/react/hooks/useBroadcastChannel/index.tsx","../../modules/react/hooks/useRouter/index.ts","../../modules/runtime/client/RouterContext.tsx","../../modules/runtime/client/constants.ts","../../modules/runtime/client/window-data.ts"],"sourcesContent":["import React, { useEffect, useState, useRef, useCallback } from \"react\";\r\n\r\nexport const useBroadcastChannel = (channelName: string) => {\r\n const [message, setMessage] = useState(null);\r\n const channelRef = useRef<BroadcastChannel | null>(null);\r\n\r\n useEffect(() => {\r\n // Create channel only once, inside useEffect\r\n if (!channelRef.current && typeof window !== \"undefined\") {\r\n channelRef.current = new BroadcastChannel(channelName);\r\n }\r\n\r\n const channel = channelRef.current;\r\n if (!channel) return;\r\n\r\n const handleMessage = (event: MessageEvent) => {\r\n setMessage(event.data);\r\n };\r\n\r\n channel.onmessage = handleMessage;\r\n\r\n // Clean up the channel when the component unmounts\r\n return () => {\r\n if (channelRef.current) {\r\n channelRef.current.close();\r\n channelRef.current = null;\r\n }\r\n };\r\n }, [channelName]);\r\n\r\n const sendMessage = useCallback((msg: unknown) => {\r\n if (channelRef.current) {\r\n channelRef.current.postMessage(msg);\r\n }\r\n }, []);\r\n\r\n return { message, sendMessage };\r\n};\r\n","import { useState, useEffect, useCallback, useContext, useRef } from \"react\";\r\nimport { RouterContext } from \"../../../runtime/client/RouterContext\";\r\nimport { getWindowData, getRouterData } from \"../../../runtime/client/window-data\";\r\nimport { ROUTER_NAVIGATE_KEY } from \"../../../runtime/client/constants\";\r\n\r\nexport interface Router {\r\n /**\r\n * Navigate to a new route.\r\n * @param url - The URL to navigate to (e.g., \"/about\" or \"/blog/[slug]\" with params)\r\n * @param options - Navigation options\r\n */\r\n push: (url: string, options?: { revalidate?: boolean }) => Promise<void>;\r\n \r\n /**\r\n * Replace the current route without adding to history.\r\n * @param url - The URL to navigate to\r\n * @param options - Navigation options\r\n */\r\n replace: (url: string, options?: { revalidate?: boolean }) => Promise<void>;\r\n \r\n /**\r\n * Go back in the browser history.\r\n */\r\n back: () => void;\r\n \r\n /**\r\n * Refresh the current route data by revalidating.\r\n */\r\n refresh: () => Promise<void>;\r\n \r\n /**\r\n * Current pathname (e.g., \"/blog/my-post\")\r\n */\r\n pathname: string;\r\n \r\n /**\r\n * Query parameters from the URL (e.g., ?id=123&name=test)\r\n * Alias for searchParams for backward compatibility\r\n */\r\n query: Record<string, string>;\r\n \r\n /**\r\n * Search parameters from the URL (e.g., ?id=123&name=test)\r\n */\r\n searchParams: Record<string, unknown>;\r\n \r\n /**\r\n * Dynamic route parameters (e.g., { slug: \"my-post\" } for /blog/[slug])\r\n */\r\n params: Record<string, string>;\r\n}\r\n\r\n/**\r\n * Hook to access router functionality and current route information.\r\n * \r\n * Provides methods to navigate programmatically and access current route data.\r\n * \r\n * @returns Router object with navigation methods and route information\r\n * \r\n * @example\r\n * ```tsx\r\n * function MyComponent() {\r\n * const router = useRouter();\r\n * \r\n * const handleClick = () => {\r\n * router.push(\"/about\");\r\n * };\r\n * \r\n * return (\r\n * <div>\r\n * <p>Current path: {router.pathname}</p>\r\n * <p>Params: {JSON.stringify(router.params)}</p>\r\n * <button onClick={handleClick}>Go to About</button>\r\n * </div>\r\n * );\r\n * }\r\n * ```\r\n * \r\n * @example\r\n * ```tsx\r\n * // Navigate with dynamic params\r\n * router.push(\"/blog/my-post\");\r\n * \r\n * // Replace current route\r\n * router.replace(\"/login\");\r\n * \r\n * // Refresh current route data\r\n * await router.refresh();\r\n * ```\r\n */\r\nexport function useRouter(): Router {\r\n // Try to get context, but don't throw if it's not available (SSR)\r\n const context = useContext(RouterContext);\r\n const navigate = context?.navigate;\r\n \r\n // Use a ref to store navigate so we can access it in callbacks even if context updates\r\n // Initialize with current navigate value\r\n const navigateRef = useRef(navigate);\r\n \r\n // Update ref when navigate changes (this ensures we always have the latest value)\r\n useEffect(() => {\r\n navigateRef.current = navigate;\r\n }, [navigate]);\r\n \r\n const [routeData, setRouteData] = useState(() => {\r\n // During SSR, return empty/default values\r\n if (typeof window === \"undefined\") {\r\n return {\r\n pathname: \"\",\r\n query: {},\r\n searchParams: {},\r\n params: {},\r\n };\r\n }\r\n \r\n // On client, get data from window\r\n const data = getWindowData();\r\n const routerData = getRouterData();\r\n \r\n // Parse search params from URL if routerData is not available\r\n const searchParams = routerData?.searchParams || parseQueryString(window.location.search);\r\n \r\n return {\r\n pathname: routerData?.pathname || data?.pathname || window.location.pathname,\r\n query: searchParams as Record<string, string>, // For backward compatibility\r\n searchParams: searchParams,\r\n params: routerData?.params || data?.params || {},\r\n };\r\n });\r\n\r\n // Listen for route changes (only on client)\r\n useEffect(() => {\r\n if (typeof window === \"undefined\") return;\r\n \r\n const handleDataRefresh = () => {\r\n const data = getWindowData();\r\n const routerData = getRouterData();\r\n const currentPathname = window.location.pathname;\r\n const currentSearch = window.location.search;\r\n \r\n const searchParams = routerData?.searchParams || parseQueryString(currentSearch);\r\n \r\n setRouteData({\r\n pathname: routerData?.pathname || data?.pathname || currentPathname,\r\n query: searchParams as Record<string, string>, // For backward compatibility\r\n searchParams: searchParams,\r\n params: routerData?.params || data?.params || {},\r\n });\r\n };\r\n\r\n // Listen for navigation events\r\n window.addEventListener(\"fw-data-refresh\", handleDataRefresh);\r\n window.addEventListener(\"fw-router-data-refresh\", handleDataRefresh);\r\n \r\n // Also listen for popstate (browser back/forward)\r\n const handlePopState = () => {\r\n handleDataRefresh();\r\n };\r\n window.addEventListener(\"popstate\", handlePopState);\r\n\r\n return () => {\r\n window.removeEventListener(\"fw-data-refresh\", handleDataRefresh);\r\n window.removeEventListener(\"fw-router-data-refresh\", handleDataRefresh);\r\n window.removeEventListener(\"popstate\", handlePopState);\r\n };\r\n }, []);\r\n\r\n const push = useCallback(\r\n async (url: string, options?: { revalidate?: boolean }) => {\r\n const fullUrl = url.startsWith(\"/\") ? url : `/${url}`;\r\n \r\n /**\r\n * SOLUTION: Multi-source navigate function resolution\r\n * \r\n * During React hydration, RouterContext may not be available immediately.\r\n * We try three sources in order:\r\n * 1. navigateRef.current - Most up-to-date, updated via useEffect\r\n * 2. navigate from context - Direct context access\r\n * 3. window.__LOLY_ROUTER_NAVIGATE__ - Global fallback exposed by AppShell\r\n * \r\n * This ensures SPA navigation works even during hydration timing issues.\r\n */\r\n const getCurrentNavigate = () => {\r\n if (navigateRef.current) return navigateRef.current;\r\n if (navigate) return navigate;\r\n if (typeof window !== \"undefined\" && (window as any)[ROUTER_NAVIGATE_KEY]) {\r\n return (window as any)[ROUTER_NAVIGATE_KEY];\r\n }\r\n return null;\r\n };\r\n \r\n let currentNavigate = getCurrentNavigate();\r\n \r\n if (typeof window === \"undefined\") {\r\n return; // SSR\r\n }\r\n \r\n // Wait for context during hydration (up to 100ms)\r\n if (!currentNavigate) {\r\n for (let i = 0; i < 10; i++) {\r\n await new Promise(resolve => setTimeout(resolve, 10));\r\n currentNavigate = getCurrentNavigate();\r\n if (currentNavigate) break;\r\n }\r\n }\r\n \r\n // Final fallback: full page reload if navigate is still unavailable\r\n if (!currentNavigate) {\r\n window.location.href = fullUrl;\r\n return;\r\n }\r\n \r\n // Check if we're already on this URL (same as link handler)\r\n const currentUrl = window.location.pathname + window.location.search;\r\n if (fullUrl === currentUrl) {\r\n return; // Already on this route, no need to navigate\r\n }\r\n \r\n // Update URL in browser history (same as link handler does)\r\n // This is done BEFORE navigation to match link behavior\r\n window.history.pushState({}, \"\", fullUrl);\r\n \r\n // Navigate using SPA navigation (same as link handler)\r\n // If navigation fails, navigate() will handle the reload internally\r\n await currentNavigate(fullUrl, options);\r\n },\r\n [navigate] // Include navigate in dependencies so it updates when context becomes available\r\n );\r\n\r\n const replace = useCallback(\r\n async (url: string, options?: { revalidate?: boolean }) => {\r\n const fullUrl = url.startsWith(\"/\") ? url : `/${url}`;\r\n \r\n const getCurrentNavigate = () => {\r\n if (navigateRef.current) return navigateRef.current;\r\n if (navigate) return navigate;\r\n if (typeof window !== \"undefined\" && (window as any)[ROUTER_NAVIGATE_KEY]) {\r\n return (window as any)[ROUTER_NAVIGATE_KEY];\r\n }\r\n return null;\r\n };\r\n \r\n let currentNavigate = getCurrentNavigate();\r\n \r\n if (typeof window === \"undefined\") {\r\n return;\r\n }\r\n \r\n if (!currentNavigate) {\r\n for (let i = 0; i < 10; i++) {\r\n await new Promise(resolve => setTimeout(resolve, 10));\r\n currentNavigate = getCurrentNavigate();\r\n if (currentNavigate) break;\r\n }\r\n }\r\n \r\n if (!currentNavigate) {\r\n window.location.replace(fullUrl);\r\n return;\r\n }\r\n \r\n // Update URL in browser history using replace (doesn't add to history)\r\n window.history.replaceState({}, \"\", fullUrl);\r\n \r\n // Navigate using SPA navigation\r\n await currentNavigate(fullUrl, options);\r\n },\r\n [navigate]\r\n );\r\n\r\n const back = useCallback(() => {\r\n if (typeof window !== \"undefined\") {\r\n window.history.back();\r\n }\r\n }, []);\r\n\r\n const refresh = useCallback(async () => {\r\n const currentUrl = typeof window !== \"undefined\" \r\n ? window.location.pathname + window.location.search \r\n : routeData.pathname;\r\n \r\n const getCurrentNavigate = () => {\r\n if (navigateRef.current) return navigateRef.current;\r\n if (navigate) return navigate;\r\n if (typeof window !== \"undefined\" && (window as any)[ROUTER_NAVIGATE_KEY]) {\r\n return (window as any)[ROUTER_NAVIGATE_KEY];\r\n }\r\n return null;\r\n };\r\n \r\n let currentNavigate = getCurrentNavigate();\r\n \r\n if (typeof window === \"undefined\") {\r\n return;\r\n }\r\n \r\n if (!currentNavigate) {\r\n for (let i = 0; i < 10; i++) {\r\n await new Promise(resolve => setTimeout(resolve, 10));\r\n currentNavigate = getCurrentNavigate();\r\n if (currentNavigate) break;\r\n }\r\n }\r\n \r\n if (!currentNavigate) {\r\n window.location.reload();\r\n return;\r\n }\r\n \r\n await currentNavigate(currentUrl, { revalidate: true });\r\n }, [navigate, routeData.pathname]);\r\n\r\n return {\r\n push,\r\n replace,\r\n back,\r\n refresh,\r\n pathname: routeData.pathname,\r\n query: routeData.query,\r\n searchParams: routeData.searchParams,\r\n params: routeData.params,\r\n };\r\n}\r\n\r\n/**\r\n * Parse query string into an object.\r\n * @param search - Query string (e.g., \"?id=123&name=test\")\r\n * @returns Object with query parameters\r\n */\r\nfunction parseQueryString(search: string): Record<string, string> {\r\n const params: Record<string, string> = {};\r\n if (!search || search.length === 0) return params;\r\n \r\n const queryString = search.startsWith(\"?\") ? search.slice(1) : search;\r\n const pairs = queryString.split(\"&\");\r\n \r\n for (const pair of pairs) {\r\n const [key, value] = pair.split(\"=\");\r\n if (key) {\r\n params[decodeURIComponent(key)] = value ? decodeURIComponent(value) : \"\";\r\n }\r\n }\r\n \r\n return params;\r\n}\r\n","import { createContext, useContext } from \"react\";\r\n\r\nexport type NavigateFunction = (\r\n url: string,\r\n options?: { revalidate?: boolean; replace?: boolean }\r\n) => Promise<void>;\r\n\r\nexport interface RouterContextValue {\r\n navigate: NavigateFunction;\r\n}\r\n\r\nexport const RouterContext = createContext<RouterContextValue | null>(null);\r\n\r\nexport function useRouterContext(): RouterContextValue {\r\n const context = useContext(RouterContext);\r\n if (!context) {\r\n throw new Error(\r\n \"useRouter must be used within a RouterProvider. Make sure you're using it inside a Loly app.\"\r\n );\r\n }\r\n return context;\r\n}\r\n","// Client-side constants (hardcoded to avoid alias resolution issues in Rspack)\r\nexport const WINDOW_DATA_KEY = \"__FW_DATA__\";\r\nexport const ROUTER_DATA_KEY = \"__LOLY_ROUTER_DATA__\";\r\nexport const APP_CONTAINER_ID = \"__app\";\r\n// Global key for navigate function fallback (exposed by AppShell for hydration timing issues)\r\nexport const ROUTER_NAVIGATE_KEY = \"__LOLY_ROUTER_NAVIGATE__\";\r\n\r\n","import { WINDOW_DATA_KEY, ROUTER_DATA_KEY } from \"./constants\";\nimport type { InitialData, RouterData } from \"./types\";\n\nconst LAYOUT_PROPS_KEY = \"__FW_LAYOUT_PROPS__\";\n\nexport function getWindowData(): InitialData | null {\n if (typeof window === \"undefined\") {\n return null;\n }\n return (window[WINDOW_DATA_KEY] as InitialData | undefined) ?? null;\n}\n\n/**\n * Gets preserved layout props from window storage.\n * Layout props are preserved across SPA navigations when layout hooks are skipped.\n */\nexport function getPreservedLayoutProps(): Record<string, any> | null {\n if (typeof window === \"undefined\") {\n return null;\n }\n return ((window as any)[LAYOUT_PROPS_KEY] as Record<string, any> | undefined) ?? null;\n}\n\n/**\n * Sets preserved layout props in window storage.\n * These props are used when layout hooks are skipped in SPA navigation.\n */\nexport function setPreservedLayoutProps(props: Record<string, any> | null): void {\n if (typeof window === \"undefined\") {\n return;\n }\n if (props === null) {\n delete (window as any)[LAYOUT_PROPS_KEY];\n } else {\n (window as any)[LAYOUT_PROPS_KEY] = props;\n }\n}\n\nexport function getRouterData(): RouterData | null {\n if (typeof window === \"undefined\") {\n return null;\n }\n return (window[ROUTER_DATA_KEY] as RouterData | undefined) ?? null;\n}\n\nexport function setWindowData(data: InitialData): void {\n window[WINDOW_DATA_KEY] = data;\n \n // Dispatch event for components to listen to (e.g. ThemeProvider)\n // This ensures components update when navigating in SPA mode\n if (typeof window !== \"undefined\") {\n window.dispatchEvent(\n new CustomEvent(\"fw-data-refresh\", {\n detail: { data },\n })\n );\n }\n}\n\nexport function setRouterData(data: RouterData): void {\n window[ROUTER_DATA_KEY] = data;\n \n // Dispatch event for router data updates\n if (typeof window !== \"undefined\") {\n window.dispatchEvent(\n new CustomEvent(\"fw-router-data-refresh\", {\n detail: { data },\n })\n );\n }\n}\n\nexport function getCurrentTheme(): string | null {\n return getWindowData()?.theme ?? null;\n}\n\n"],"mappings":";AAAA,SAAgB,WAAW,UAAU,QAAQ,mBAAmB;AAEzD,IAAM,sBAAsB,CAAC,gBAAwB;AAC1D,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,IAAI;AAC3C,QAAM,aAAa,OAAgC,IAAI;AAEvD,YAAU,MAAM;AAEd,QAAI,CAAC,WAAW,WAAW,OAAO,WAAW,aAAa;AACxD,iBAAW,UAAU,IAAI,iBAAiB,WAAW;AAAA,IACvD;AAEA,UAAM,UAAU,WAAW;AAC3B,QAAI,CAAC,QAAS;AAEd,UAAM,gBAAgB,CAAC,UAAwB;AAC7C,iBAAW,MAAM,IAAI;AAAA,IACvB;AAEA,YAAQ,YAAY;AAGpB,WAAO,MAAM;AACX,UAAI,WAAW,SAAS;AACtB,mBAAW,QAAQ,MAAM;AACzB,mBAAW,UAAU;AAAA,MACvB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,WAAW,CAAC;AAEhB,QAAM,cAAc,YAAY,CAAC,QAAiB;AAChD,QAAI,WAAW,SAAS;AACtB,iBAAW,QAAQ,YAAY,GAAG;AAAA,IACpC;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAA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B,GAAG,CAAC,IAAI,QAAQ,mBAAmB,KAAK,IAAI;AAAA,IACxE;AAAA,EACF;AAEA,SAAO;AACT;","names":["useState","useEffect","useCallback","useContext","useRef","useContext","useRef","useEffect","useState","useCallback"]}
@@ -25,14 +25,13 @@ __export(sockets_exports, {
25
25
  module.exports = __toCommonJS(sockets_exports);
26
26
  var import_socket = require("socket.io-client");
27
27
  var lolySocket = (namespace, opts) => {
28
- const wsBaseUrl = process.env.PUBLIC_WS_BASE_URL;
29
- const baseUrl = wsBaseUrl && wsBaseUrl.trim() !== "" ? wsBaseUrl : window.location.origin;
30
- if (!wsBaseUrl || wsBaseUrl.trim() === "") {
31
- console.warn("[loly:socket] PUBLIC_WS_BASE_URL is not set, using window.location.origin.");
28
+ if (typeof window === "undefined") {
29
+ throw new Error(
30
+ "[loly:socket] lolySocket can only be called on the client side."
31
+ );
32
32
  }
33
33
  const normalizedNamespace = namespace.startsWith("/") ? namespace : `/${namespace}`;
34
- const fullUrl = `${baseUrl}${normalizedNamespace}`;
35
- const socket = (0, import_socket.io)(fullUrl, {
34
+ const socket = (0, import_socket.io)(normalizedNamespace, {
36
35
  path: "/wss",
37
36
  transports: ["websocket", "polling"],
38
37
  autoConnect: true,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../modules/react/sockets/index.ts"],"sourcesContent":["import { io, ManagerOptions, Socket, SocketOptions } from \"socket.io-client\";\r\n\r\n/**\r\n * Creates a Socket.IO client connection to a specific namespace.\r\n * \r\n * This helper function simplifies Socket.IO client setup by handling:\r\n * - Namespace normalization (ensures leading slash)\r\n * - Base URL resolution (from environment or current origin)\r\n * - Default Socket.IO configuration (path: '/wss', transports: ['websocket', 'polling'])\r\n * \r\n * @param namespace - The namespace to connect to (e.g., '/chat' or 'chat').\r\n * The namespace will be normalized to always start with '/'.\r\n * Must match the namespace pattern defined in your server's WSS routes.\r\n * @param opts - Optional Socket.IO client options that will override the defaults.\r\n * \r\n * @returns A Socket.IO client instance connected to the specified namespace.\r\n * \r\n * @example\r\n * ```ts\r\n * const socket = lolySocket('/chat');\r\n * socket.on('message', (data) => {\r\n * console.log('Received:', data);\r\n * });\r\n * socket.emit('message', { text: 'Hello' });\r\n * ```\r\n */\r\nexport const lolySocket = (\r\n namespace: string,\r\n opts?: Partial<ManagerOptions & SocketOptions>\r\n): Socket => {\r\n // @ts-ignore - process.env.PUBLIC_WS_BASE_URL is replaced by DefinePlugin at build time with literal value\r\n // DefinePlugin replaces process.env.PUBLIC_WS_BASE_URL with the actual value (or empty string if not set)\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n const wsBaseUrl: string | undefined = (process as any).env.PUBLIC_WS_BASE_URL;\r\n const baseUrl = (wsBaseUrl && wsBaseUrl.trim() !== \"\") ? wsBaseUrl : window.location.origin;\r\n\r\n if (!wsBaseUrl || wsBaseUrl.trim() === \"\") {\r\n console.warn(\"[loly:socket] PUBLIC_WS_BASE_URL is not set, using window.location.origin.\");\r\n }\r\n\r\n // Normalize namespace to always start with '/'\r\n const normalizedNamespace = namespace.startsWith(\"/\") ? namespace : `/${namespace}`;\r\n\r\n // In Socket.IO, when using a custom path, the namespace is specified in the URL:\r\n // baseUrl + namespace. The path '/wss' is the HTTP route where Socket.IO listens.\r\n const fullUrl = `${baseUrl}${normalizedNamespace}`;\r\n\r\n const socket = io(fullUrl, {\r\n path: \"/wss\",\r\n transports: [\"websocket\", \"polling\"],\r\n autoConnect: true,\r\n ...opts,\r\n });\r\n\r\n return socket;\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0D;AA0BnD,IAAM,aAAa,CACxB,WACA,SACW;AAIX,QAAM,YAAiC,QAAgB,IAAI;AAC3D,QAAM,UAAW,aAAa,UAAU,KAAK,MAAM,KAAM,YAAY,OAAO,SAAS;AAErF,MAAI,CAAC,aAAa,UAAU,KAAK,MAAM,IAAI;AACzC,YAAQ,KAAK,4EAA4E;AAAA,EAC3F;AAGA,QAAM,sBAAsB,UAAU,WAAW,GAAG,IAAI,YAAY,IAAI,SAAS;AAIjF,QAAM,UAAU,GAAG,OAAO,GAAG,mBAAmB;AAEhD,QAAM,aAAS,kBAAG,SAAS;AAAA,IACzB,MAAM;AAAA,IACN,YAAY,CAAC,aAAa,SAAS;AAAA,IACnC,aAAa;AAAA,IACb,GAAG;AAAA,EACL,CAAC;AAED,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../modules/react/sockets/index.ts"],"sourcesContent":["import { io, ManagerOptions, Socket, SocketOptions } from \"socket.io-client\";\r\n\r\n/**\r\n * Creates a Socket.IO client connection to a specific namespace.\r\n * \r\n * This helper function simplifies Socket.IO client setup by handling:\r\n * - Namespace normalization (ensures leading slash)\r\n * - Base URL resolution (from environment or current origin)\r\n * - Default Socket.IO configuration (path: '/wss', transports: ['websocket', 'polling'])\r\n * \r\n * @param namespace - The namespace to connect to (e.g., '/chat' or 'chat').\r\n * The namespace will be normalized to always start with '/'.\r\n * Must match the namespace pattern defined in your server's WSS routes.\r\n * @param opts - Optional Socket.IO client options that will override the defaults.\r\n * \r\n * @returns A Socket.IO client instance connected to the specified namespace.\r\n * \r\n * @example\r\n * ```ts\r\n * const socket = lolySocket('/chat');\r\n * socket.on('message', (data) => {\r\n * console.log('Received:', data);\r\n * });\r\n * socket.emit('message', { text: 'Hello' });\r\n * ```\r\n */\r\nexport const lolySocket = (\r\n namespace: string,\r\n opts?: Partial<ManagerOptions & SocketOptions>\r\n): Socket => {\r\n // Simplified: Always use the current origin in the browser\r\n // Socket.IO handles the namespace automatically\r\n if (typeof window === \"undefined\") {\r\n throw new Error(\r\n \"[loly:socket] lolySocket can only be called on the client side.\"\r\n );\r\n }\r\n\r\n const normalizedNamespace = namespace.startsWith(\"/\") ? namespace : `/${namespace}`;\r\n \r\n // Socket.IO: io(namespace, { path: '/wss' })\r\n // Socket.IO uses window.location.origin automatically\r\n // The path '/wss' is the Socket.IO engine endpoint\r\n // The namespace is handled in the handshake\r\n\r\n const socket = io(normalizedNamespace, {\r\n path: \"/wss\",\r\n transports: [\"websocket\", \"polling\"],\r\n autoConnect: true,\r\n ...opts,\r\n });\r\n\r\n return socket;\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0D;AA0BnD,IAAM,aAAa,CACxB,WACA,SACW;AAGX,MAAI,OAAO,WAAW,aAAa;AACjC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,sBAAsB,UAAU,WAAW,GAAG,IAAI,YAAY,IAAI,SAAS;AAOjF,QAAM,aAAS,kBAAG,qBAAqB;AAAA,IACrC,MAAM;AAAA,IACN,YAAY,CAAC,aAAa,SAAS;AAAA,IACnC,aAAa;AAAA,IACb,GAAG;AAAA,EACL,CAAC;AAED,SAAO;AACT;","names":[]}
@@ -0,0 +1,21 @@
1
+ // modules/react/sockets/index.ts
2
+ import { io } from "socket.io-client";
3
+ var lolySocket = (namespace, opts) => {
4
+ if (typeof window === "undefined") {
5
+ throw new Error(
6
+ "[loly:socket] lolySocket can only be called on the client side."
7
+ );
8
+ }
9
+ const normalizedNamespace = namespace.startsWith("/") ? namespace : `/${namespace}`;
10
+ const socket = io(normalizedNamespace, {
11
+ path: "/wss",
12
+ transports: ["websocket", "polling"],
13
+ autoConnect: true,
14
+ ...opts
15
+ });
16
+ return socket;
17
+ };
18
+ export {
19
+ lolySocket
20
+ };
21
+ //# sourceMappingURL=sockets.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../modules/react/sockets/index.ts"],"sourcesContent":["import { io, ManagerOptions, Socket, SocketOptions } from \"socket.io-client\";\r\n\r\n/**\r\n * Creates a Socket.IO client connection to a specific namespace.\r\n * \r\n * This helper function simplifies Socket.IO client setup by handling:\r\n * - Namespace normalization (ensures leading slash)\r\n * - Base URL resolution (from environment or current origin)\r\n * - Default Socket.IO configuration (path: '/wss', transports: ['websocket', 'polling'])\r\n * \r\n * @param namespace - The namespace to connect to (e.g., '/chat' or 'chat').\r\n * The namespace will be normalized to always start with '/'.\r\n * Must match the namespace pattern defined in your server's WSS routes.\r\n * @param opts - Optional Socket.IO client options that will override the defaults.\r\n * \r\n * @returns A Socket.IO client instance connected to the specified namespace.\r\n * \r\n * @example\r\n * ```ts\r\n * const socket = lolySocket('/chat');\r\n * socket.on('message', (data) => {\r\n * console.log('Received:', data);\r\n * });\r\n * socket.emit('message', { text: 'Hello' });\r\n * ```\r\n */\r\nexport const lolySocket = (\r\n namespace: string,\r\n opts?: Partial<ManagerOptions & SocketOptions>\r\n): Socket => {\r\n // Simplified: Always use the current origin in the browser\r\n // Socket.IO handles the namespace automatically\r\n if (typeof window === \"undefined\") {\r\n throw new Error(\r\n \"[loly:socket] lolySocket can only be called on the client side.\"\r\n );\r\n }\r\n\r\n const normalizedNamespace = namespace.startsWith(\"/\") ? namespace : `/${namespace}`;\r\n \r\n // Socket.IO: io(namespace, { path: '/wss' })\r\n // Socket.IO uses window.location.origin automatically\r\n // The path '/wss' is the Socket.IO engine endpoint\r\n // The namespace is handled in the handshake\r\n\r\n const socket = io(normalizedNamespace, {\r\n path: \"/wss\",\r\n transports: [\"websocket\", \"polling\"],\r\n autoConnect: true,\r\n ...opts,\r\n });\r\n\r\n return socket;\r\n};\r\n"],"mappings":";AAAA,SAAS,UAAiD;AA0BnD,IAAM,aAAa,CACxB,WACA,SACW;AAGX,MAAI,OAAO,WAAW,aAAa;AACjC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,sBAAsB,UAAU,WAAW,GAAG,IAAI,YAAY,IAAI,SAAS;AAOjF,QAAM,SAAS,GAAG,qBAAqB;AAAA,IACrC,MAAM;AAAA,IACN,YAAY,CAAC,aAAa,SAAS;AAAA,IACnC,aAAa;AAAA,IACb,GAAG;AAAA,EACL,CAAC;AAED,SAAO;AACT;","names":[]}
@@ -32,19 +32,29 @@ var import_react2 = require("react");
32
32
  var import_react = require("react");
33
33
  var useBroadcastChannel = (channelName) => {
34
34
  const [message, setMessage] = (0, import_react.useState)(null);
35
- const channel = new BroadcastChannel(channelName);
35
+ const channelRef = (0, import_react.useRef)(null);
36
36
  (0, import_react.useEffect)(() => {
37
+ if (!channelRef.current && typeof window !== "undefined") {
38
+ channelRef.current = new BroadcastChannel(channelName);
39
+ }
40
+ const channel = channelRef.current;
41
+ if (!channel) return;
37
42
  const handleMessage = (event) => {
38
43
  setMessage(event.data);
39
44
  };
40
45
  channel.onmessage = handleMessage;
41
46
  return () => {
42
- channel.close();
47
+ if (channelRef.current) {
48
+ channelRef.current.close();
49
+ channelRef.current = null;
50
+ }
43
51
  };
44
- }, [channel]);
45
- const sendMessage = (msg) => {
46
- channel.postMessage(msg);
47
- };
52
+ }, [channelName]);
53
+ const sendMessage = (0, import_react.useCallback)((msg) => {
54
+ if (channelRef.current) {
55
+ channelRef.current.postMessage(msg);
56
+ }
57
+ }, []);
48
58
  return { message, sendMessage };
49
59
  };
50
60
 
@@ -66,6 +76,7 @@ var ThemeProvider = ({
66
76
  initialTheme
67
77
  }) => {
68
78
  const { message: themeMessage, sendMessage } = useBroadcastChannel("theme_channel");
79
+ const lastSentRef = (0, import_react2.useRef)(null);
69
80
  const [theme, setTheme] = (0, import_react2.useState)(() => {
70
81
  if (initialTheme) return initialTheme;
71
82
  if (typeof window !== "undefined") {
@@ -80,10 +91,29 @@ var ThemeProvider = ({
80
91
  });
81
92
  (0, import_react2.useEffect)(() => {
82
93
  if (!themeMessage) return;
83
- if (themeMessage !== theme) {
84
- setTheme(themeMessage);
94
+ if (themeMessage === lastSentRef.current) {
95
+ lastSentRef.current = null;
96
+ return;
85
97
  }
86
- }, [themeMessage, theme]);
98
+ setTheme((currentTheme) => {
99
+ if (themeMessage !== currentTheme) {
100
+ if (typeof document !== "undefined") {
101
+ document.cookie = `theme=${themeMessage}; path=/; max-age=31536000`;
102
+ }
103
+ if (typeof window !== "undefined") {
104
+ if (!window.__FW_DATA__) {
105
+ window.__FW_DATA__ = {};
106
+ }
107
+ window.__FW_DATA__ = {
108
+ ...window.__FW_DATA__,
109
+ theme: themeMessage
110
+ };
111
+ }
112
+ return themeMessage;
113
+ }
114
+ return currentTheme;
115
+ });
116
+ }, [themeMessage]);
87
117
  (0, import_react2.useEffect)(() => {
88
118
  const handleDataRefresh = () => {
89
119
  if (typeof window !== "undefined") {
@@ -98,13 +128,15 @@ var ThemeProvider = ({
98
128
  }
99
129
  }
100
130
  };
101
- window.addEventListener("fw-data-refresh", handleDataRefresh);
102
- return () => {
103
- window.removeEventListener("fw-data-refresh", handleDataRefresh);
104
- };
131
+ if (typeof window !== "undefined") {
132
+ window.addEventListener("fw-data-refresh", handleDataRefresh);
133
+ return () => {
134
+ window.removeEventListener("fw-data-refresh", handleDataRefresh);
135
+ };
136
+ }
105
137
  }, []);
106
138
  (0, import_react2.useEffect)(() => {
107
- if (initialTheme) {
139
+ if (initialTheme && initialTheme !== theme) {
108
140
  setTheme(initialTheme);
109
141
  }
110
142
  }, [initialTheme]);
@@ -120,17 +152,28 @@ var ThemeProvider = ({
120
152
  if (body.className !== newClassName) {
121
153
  body.className = newClassName;
122
154
  }
123
- sendMessage(theme);
124
- }, [theme, sendMessage]);
155
+ }, [theme]);
125
156
  const handleThemeChange = (newTheme) => {
126
157
  setTheme(newTheme);
127
- document.cookie = `theme=${newTheme}; path=/; max-age=31536000`;
128
- if (typeof window !== "undefined" && window.__FW_DATA__) {
158
+ if (typeof document !== "undefined") {
159
+ document.cookie = `theme=${newTheme}; path=/; max-age=31536000`;
160
+ }
161
+ if (typeof window !== "undefined") {
162
+ if (!window.__FW_DATA__) {
163
+ window.__FW_DATA__ = {};
164
+ }
129
165
  window.__FW_DATA__ = {
130
166
  ...window.__FW_DATA__,
131
167
  theme: newTheme
132
168
  };
133
169
  }
170
+ lastSentRef.current = newTheme;
171
+ sendMessage(newTheme);
172
+ setTimeout(() => {
173
+ if (lastSentRef.current === newTheme) {
174
+ lastSentRef.current = null;
175
+ }
176
+ }, 500);
134
177
  };
135
178
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ThemeContext.Provider, { value: { theme, handleThemeChange }, children });
136
179
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../modules/react/themes/index.ts","../../modules/react/themes/theme-provider/index.tsx","../../modules/react/hooks/useBroadcastChannel/index.tsx"],"sourcesContent":["export {\r\n ThemeProvider,\r\n useTheme\r\n} from './theme-provider';","import React, { createContext, useContext, useState, useEffect } from \"react\";\r\nimport { useBroadcastChannel } from \"../../hooks/useBroadcastChannel\";\r\n\r\nconst ThemeContext = createContext<{\r\n theme: string;\r\n handleThemeChange: (theme: string) => void;\r\n}>({ theme: \"light\", handleThemeChange: () => {} });\r\n\r\n// Helper function to get cookie value\r\nfunction getCookie(name: string): string | null {\r\n if (typeof document === \"undefined\") return null;\r\n const value = `; ${document.cookie}`;\r\n const parts = value.split(`; ${name}=`);\r\n if (parts.length === 2) {\r\n return parts.pop()?.split(\";\").shift() || null;\r\n }\r\n return null;\r\n}\r\n\r\nexport const ThemeProvider = ({ \r\n children,\r\n initialTheme \r\n}: { \r\n children: React.ReactNode;\r\n initialTheme?: string;\r\n}) => {\r\n const { message: themeMessage, sendMessage } = useBroadcastChannel('theme_channel');\r\n\r\n // Initialize theme consistently between server and client\r\n // The server renders with initialTheme, and we must use the same value on client\r\n // to avoid hydration mismatch. Priority: initialTheme prop > window.__FW_DATA__ > cookie > default\r\n const [theme, setTheme] = useState<string>(() => {\r\n // 1. Use prop if provided (this should match what server rendered)\r\n if (initialTheme) return initialTheme;\r\n \r\n // 2. On client, use window.__FW_DATA__ from SSR (this is set before hydration)\r\n // This ensures consistency between server and client\r\n if (typeof window !== \"undefined\") {\r\n const windowData = (window as any).__FW_DATA__;\r\n if (windowData?.theme) return windowData.theme;\r\n }\r\n \r\n // 3. Fallback to cookie (only if window.__FW_DATA__ not available yet)\r\n if (typeof window !== \"undefined\") {\r\n const cookieTheme = getCookie(\"theme\");\r\n if (cookieTheme) return cookieTheme;\r\n }\r\n \r\n // Default fallback\r\n return \"light\";\r\n });\r\n\r\n // Listen for theme changes from broadcast channel (other tabs/windows)\r\n useEffect(() => {\r\n if (!themeMessage) return;\r\n if (themeMessage !== theme) {\r\n setTheme(themeMessage);\r\n }\r\n }, [themeMessage, theme]);\r\n\r\n // Listen for theme changes from window.__FW_DATA__ during SPA navigation\r\n useEffect(() => {\r\n const handleDataRefresh = () => {\r\n if (typeof window !== \"undefined\") {\r\n const windowData = (window as any).__FW_DATA__;\r\n if (windowData?.theme) {\r\n // Use functional update to avoid stale closure\r\n setTheme((currentTheme) => {\r\n if (windowData.theme !== currentTheme) {\r\n return windowData.theme;\r\n }\r\n return currentTheme;\r\n });\r\n }\r\n }\r\n };\r\n\r\n window.addEventListener(\"fw-data-refresh\", handleDataRefresh);\r\n\r\n return () => {\r\n window.removeEventListener(\"fw-data-refresh\", handleDataRefresh);\r\n };\r\n }, []);\r\n\r\n // Update theme when initialTheme prop changes (e.g., during SPA navigation)\r\n // This is the primary way theme updates during SPA navigation when layout re-renders\r\n useEffect(() => {\r\n if (initialTheme) {\r\n // Always update if initialTheme is provided, even if it's the same\r\n // This ensures theme syncs correctly during SPA navigation\r\n setTheme(initialTheme);\r\n }\r\n }, [initialTheme]);\r\n\r\n // Update body class when theme changes (skip during initial hydration to avoid mismatch)\r\n useEffect(() => {\r\n if (typeof document === \"undefined\") return;\r\n\r\n const body = document.body;\r\n const currentClasses = body.className.split(\" \").filter(Boolean);\r\n \r\n // Remove old theme classes (light, dark, etc.)\r\n const themeClasses = [\"light\", \"dark\"];\r\n const filteredClasses = currentClasses.filter(\r\n (cls) => !themeClasses.includes(cls)\r\n );\r\n \r\n // Add new theme class\r\n const newClassName = [...filteredClasses, theme].filter(Boolean).join(\" \");\r\n \r\n // Only update if different to avoid unnecessary DOM updates\r\n if (body.className !== newClassName) {\r\n body.className = newClassName;\r\n }\r\n\r\n sendMessage(theme);\r\n }, [theme, sendMessage]);\r\n\r\n const handleThemeChange = (newTheme: string) => {\r\n setTheme(newTheme);\r\n\r\n // Set theme cookie\r\n document.cookie = `theme=${newTheme}; path=/; max-age=31536000`; // 1 year expiry\r\n\r\n // Update window.__FW_DATA__.theme so getCurrentTheme() returns the correct value during navigation\r\n if (typeof window !== \"undefined\" && (window as any).__FW_DATA__) {\r\n (window as any).__FW_DATA__ = {\r\n ...(window as any).__FW_DATA__,\r\n theme: newTheme,\r\n };\r\n }\r\n };\r\n\r\n return (\r\n <ThemeContext.Provider value={{ theme, handleThemeChange }}>\r\n {children}\r\n </ThemeContext.Provider>\r\n );\r\n};\r\n\r\nexport const useTheme = () => {\r\n return useContext(ThemeContext);\r\n};\r\n","import React, { useEffect, useState } from \"react\";\r\n\r\nexport const useBroadcastChannel = (channelName: string) => {\r\n const [message, setMessage] = useState(null);\r\n const channel = new BroadcastChannel(channelName);\r\n\r\n useEffect(() => {\r\n const handleMessage = (event: MessageEvent) => {\r\n setMessage(event.data);\r\n };\r\n\r\n channel.onmessage = handleMessage;\r\n\r\n // Clean up the channel when the component unmounts\r\n return () => {\r\n channel.close();\r\n };\r\n }, [channel]);\r\n\r\n const sendMessage = (msg: unknown) => {\r\n channel.postMessage(msg);\r\n };\r\n\r\n return { message, sendMessage };\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAAsE;;;ACAtE,mBAA2C;AAEpC,IAAM,sBAAsB,CAAC,gBAAwB;AAC1D,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAS,IAAI;AAC3C,QAAM,UAAU,IAAI,iBAAiB,WAAW;AAEhD,8BAAU,MAAM;AACd,UAAM,gBAAgB,CAAC,UAAwB;AAC7C,iBAAW,MAAM,IAAI;AAAA,IACvB;AAEA,YAAQ,YAAY;AAGpB,WAAO,MAAM;AACX,cAAQ,MAAM;AAAA,IAChB;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AAEZ,QAA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,YACpB;AACA,mBAAO;AAAA,UACT,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAEA,WAAO,iBAAiB,mBAAmB,iBAAiB;AAE5D,WAAO,MAAM;AACX,aAAO,oBAAoB,mBAAmB,iBAAiB;AAAA,IACjE;AAAA,EACF,GAAG,CAAC,CAAC;AAIL,+BAAU,MAAM;AACd,QAAI,cAAc;AAGhB,eAAS,YAAY;AAAA,IACvB;AAAA,EACF,GAAG,CAAC,YAAY,CAAC;AAGjB,+BAAU,MAAM;AACd,QAAI,OAAO,aAAa,YAAa;AAErC,UAAM,OAAO,SAAS;AACtB,UAAM,iBAAiB,KAAK,UAAU,MAAM,GAAG,EAAE,OAAO,OAAO;AAG/D,UAAM,eAAe,CAAC,SAAS,MAAM;AACrC,UAAM,kBAAkB,eAAe;AAAA,MACrC,CAAC,QAAQ,CAAC,aAAa,SAAS,GAAG;AAAA,IACrC;AAGA,UAAM,eAAe,CAAC,GAAG,iBAAiB,KAAK,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG;AAGzE,QAAI,KAAK,cAAc,cAAc;AACnC,WAAK,YAAY;AAAA,IACnB;AAEA,gBAAY,KAAK;AAAA,EACnB,GAAG,CAAC,OAAO,WAAW,CAAC;AAEvB,QAAM,oBAAoB,CAAC,aAAqB;AAC9C,aAAS,QAAQ;AAGjB,aAAS,SAAS,SAAS,QAAQ;AAGnC,QAAI,OAAO,WAAW,eAAgB,OAAe,aAAa;AAChE,MAAC,OAAe,cAAc;AAAA,QAC5B,GAAI,OAAe;AAAA,QACnB,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AAEA,SACE,4CAAC,aAAa,UAAb,EAAsB,OAAO,EAAE,OAAO,kBAAkB,GACtD,UACH;AAEJ;AAEO,IAAM,WAAW,MAAM;AAC5B,aAAO,0BAAW,YAAY;AAChC;","names":["import_react"]}
1
+ {"version":3,"sources":["../../modules/react/themes/index.ts","../../modules/react/themes/theme-provider/index.tsx","../../modules/react/hooks/useBroadcastChannel/index.tsx"],"sourcesContent":["export {\r\n ThemeProvider,\r\n useTheme\r\n} from './theme-provider';","import React, { createContext, useContext, useState, useEffect, useRef } from \"react\";\r\nimport { useBroadcastChannel } from \"../../hooks/useBroadcastChannel\";\r\n\r\nconst ThemeContext = createContext<{\r\n theme: string;\r\n handleThemeChange: (theme: string) => void;\r\n}>({ theme: \"light\", handleThemeChange: () => {} });\r\n\r\n// Helper function to get cookie value\r\nfunction getCookie(name: string): string | null {\r\n if (typeof document === \"undefined\") return null;\r\n const value = `; ${document.cookie}`;\r\n const parts = value.split(`; ${name}=`);\r\n if (parts.length === 2) {\r\n return parts.pop()?.split(\";\").shift() || null;\r\n }\r\n return null;\r\n}\r\n\r\nexport const ThemeProvider = ({ \r\n children,\r\n initialTheme \r\n}: { \r\n children: React.ReactNode;\r\n initialTheme?: string;\r\n}) => {\r\n const { message: themeMessage, sendMessage } = useBroadcastChannel('theme_channel');\r\n \r\n // Track what we last sent to avoid loops\r\n const lastSentRef = useRef<string | null>(null);\r\n\r\n // Initialize theme consistently between server and client\r\n const [theme, setTheme] = useState<string>(() => {\r\n if (initialTheme) return initialTheme;\r\n \r\n if (typeof window !== \"undefined\") {\r\n const windowData = (window as any).__FW_DATA__;\r\n if (windowData?.theme) return windowData.theme;\r\n }\r\n \r\n if (typeof window !== \"undefined\") {\r\n const cookieTheme = getCookie(\"theme\");\r\n if (cookieTheme) return cookieTheme;\r\n }\r\n \r\n return \"light\";\r\n });\r\n\r\n // Handle messages from broadcast channel (other tabs)\r\n // This effect ONLY responds to themeMessage changes, not theme changes\r\n useEffect(() => {\r\n if (!themeMessage) return;\r\n \r\n // Ignore if this is a message we just sent\r\n if (themeMessage === lastSentRef.current) {\r\n lastSentRef.current = null;\r\n return;\r\n }\r\n \r\n // Only update if different from current theme\r\n setTheme((currentTheme) => {\r\n if (themeMessage !== currentTheme) {\r\n // Update cookie\r\n if (typeof document !== \"undefined\") {\r\n document.cookie = `theme=${themeMessage}; path=/; max-age=31536000`;\r\n }\r\n \r\n // Update window data\r\n if (typeof window !== \"undefined\") {\r\n if (!(window as any).__FW_DATA__) {\r\n (window as any).__FW_DATA__ = {};\r\n }\r\n (window as any).__FW_DATA__ = {\r\n ...(window as any).__FW_DATA__,\r\n theme: themeMessage,\r\n };\r\n }\r\n \r\n return themeMessage;\r\n }\r\n return currentTheme;\r\n });\r\n }, [themeMessage]); // Only depend on themeMessage, NOT theme!\r\n\r\n // Handle window.__FW_DATA__ changes during SPA navigation\r\n useEffect(() => {\r\n const handleDataRefresh = () => {\r\n if (typeof window !== \"undefined\") {\r\n const windowData = (window as any).__FW_DATA__;\r\n if (windowData?.theme) {\r\n setTheme((currentTheme) => {\r\n if (windowData.theme !== currentTheme) {\r\n return windowData.theme;\r\n }\r\n return currentTheme;\r\n });\r\n }\r\n }\r\n };\r\n\r\n if (typeof window !== \"undefined\") {\r\n window.addEventListener(\"fw-data-refresh\", handleDataRefresh);\r\n return () => {\r\n window.removeEventListener(\"fw-data-refresh\", handleDataRefresh);\r\n };\r\n }\r\n }, []); // No dependencies - event listener doesn't need theme\r\n\r\n // Handle initialTheme prop changes\r\n useEffect(() => {\r\n if (initialTheme && initialTheme !== theme) {\r\n setTheme(initialTheme);\r\n }\r\n }, [initialTheme]); // Only depend on initialTheme, not theme\r\n\r\n // Update body class when theme changes\r\n useEffect(() => {\r\n if (typeof document === \"undefined\") return;\r\n\r\n const body = document.body;\r\n const currentClasses = body.className.split(\" \").filter(Boolean);\r\n const themeClasses = [\"light\", \"dark\"];\r\n const filteredClasses = currentClasses.filter(\r\n (cls) => !themeClasses.includes(cls)\r\n );\r\n const newClassName = [...filteredClasses, theme].filter(Boolean).join(\" \");\r\n \r\n if (body.className !== newClassName) {\r\n body.className = newClassName;\r\n }\r\n }, [theme]);\r\n\r\n const handleThemeChange = (newTheme: string) => {\r\n // Update state immediately\r\n setTheme(newTheme);\r\n\r\n // Update cookie\r\n if (typeof document !== \"undefined\") {\r\n document.cookie = `theme=${newTheme}; path=/; max-age=31536000`;\r\n }\r\n\r\n // Update window data\r\n if (typeof window !== \"undefined\") {\r\n if (!(window as any).__FW_DATA__) {\r\n (window as any).__FW_DATA__ = {};\r\n }\r\n (window as any).__FW_DATA__ = {\r\n ...(window as any).__FW_DATA__,\r\n theme: newTheme,\r\n };\r\n }\r\n \r\n // Mark this as the last value we sent\r\n lastSentRef.current = newTheme;\r\n \r\n // Broadcast to other tabs\r\n sendMessage(newTheme);\r\n \r\n // Clear the ref after a delay\r\n setTimeout(() => {\r\n if (lastSentRef.current === newTheme) {\r\n lastSentRef.current = null;\r\n }\r\n }, 500);\r\n };\r\n\r\n return (\r\n <ThemeContext.Provider value={{ theme, handleThemeChange }}>\r\n {children}\r\n </ThemeContext.Provider>\r\n );\r\n};\r\n\r\nexport const useTheme = () => {\r\n return useContext(ThemeContext);\r\n};\r\n","import React, { useEffect, useState, useRef, useCallback } from \"react\";\r\n\r\nexport const useBroadcastChannel = (channelName: string) => {\r\n const [message, setMessage] = useState(null);\r\n const channelRef = useRef<BroadcastChannel | null>(null);\r\n\r\n useEffect(() => {\r\n // Create channel only once, inside useEffect\r\n if (!channelRef.current && typeof window !== \"undefined\") {\r\n channelRef.current = new BroadcastChannel(channelName);\r\n }\r\n\r\n const channel = channelRef.current;\r\n if (!channel) return;\r\n\r\n const handleMessage = (event: MessageEvent) => {\r\n setMessage(event.data);\r\n };\r\n\r\n channel.onmessage = handleMessage;\r\n\r\n // Clean up the channel when the component unmounts\r\n return () => {\r\n if (channelRef.current) {\r\n channelRef.current.close();\r\n channelRef.current = null;\r\n }\r\n };\r\n }, [channelName]);\r\n\r\n const sendMessage = useCallback((msg: unknown) => {\r\n if (channelRef.current) {\r\n channelRef.current.postMessage(msg);\r\n }\r\n }, []);\r\n\r\n return { message, sendMessage };\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAA8E;;;ACA9E,mBAAgE;AAE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/themes/theme-provider/index.tsx
2
- import { createContext, useContext, useState as useState2, useEffect as useEffect2 } from "react";
2
+ import { createContext, useContext, useState as useState2, useEffect as useEffect2, useRef as useRef2 } from "react";
3
3
 
4
4
  // modules/react/hooks/useBroadcastChannel/index.tsx
5
- import { useEffect, useState } from "react";
5
+ import { useEffect, useState, useRef, useCallback } from "react";
6
6
  var useBroadcastChannel = (channelName) => {
7
7
  const [message, setMessage] = useState(null);
8
- const channel = new BroadcastChannel(channelName);
8
+ const channelRef = useRef(null);
9
9
  useEffect(() => {
10
+ if (!channelRef.current && typeof window !== "undefined") {
11
+ channelRef.current = new BroadcastChannel(channelName);
12
+ }
13
+ const channel = channelRef.current;
14
+ if (!channel) return;
10
15
  const handleMessage = (event) => {
11
16
  setMessage(event.data);
12
17
  };
13
18
  channel.onmessage = handleMessage;
14
19
  return () => {
15
- channel.close();
20
+ if (channelRef.current) {
21
+ channelRef.current.close();
22
+ channelRef.current = null;
23
+ }
16
24
  };
17
- }, [channel]);
18
- const sendMessage = (msg) => {
19
- channel.postMessage(msg);
20
- };
25
+ }, [channelName]);
26
+ const sendMessage = useCallback((msg) => {
27
+ if (channelRef.current) {
28
+ channelRef.current.postMessage(msg);
29
+ }
30
+ }, []);
21
31
  return { message, sendMessage };
22
32
  };
23
33
 
@@ -39,6 +49,7 @@ var ThemeProvider = ({
39
49
  initialTheme
40
50
  }) => {
41
51
  const { message: themeMessage, sendMessage } = useBroadcastChannel("theme_channel");
52
+ const lastSentRef = useRef2(null);
42
53
  const [theme, setTheme] = useState2(() => {
43
54
  if (initialTheme) return initialTheme;
44
55
  if (typeof window !== "undefined") {
@@ -53,10 +64,29 @@ var ThemeProvider = ({
53
64
  });
54
65
  useEffect2(() => {
55
66
  if (!themeMessage) return;
56
- if (themeMessage !== theme) {
57
- setTheme(themeMessage);
67
+ if (themeMessage === lastSentRef.current) {
68
+ lastSentRef.current = null;
69
+ return;
58
70
  }
59
- }, [themeMessage, theme]);
71
+ setTheme((currentTheme) => {
72
+ if (themeMessage !== currentTheme) {
73
+ if (typeof document !== "undefined") {
74
+ document.cookie = `theme=${themeMessage}; path=/; max-age=31536000`;
75
+ }
76
+ if (typeof window !== "undefined") {
77
+ if (!window.__FW_DATA__) {
78
+ window.__FW_DATA__ = {};
79
+ }
80
+ window.__FW_DATA__ = {
81
+ ...window.__FW_DATA__,
82
+ theme: themeMessage
83
+ };
84
+ }
85
+ return themeMessage;
86
+ }
87
+ return currentTheme;
88
+ });
89
+ }, [themeMessage]);
60
90
  useEffect2(() => {
61
91
  const handleDataRefresh = () => {
62
92
  if (typeof window !== "undefined") {
@@ -71,13 +101,15 @@ var ThemeProvider = ({
71
101
  }
72
102
  }
73
103
  };
74
- window.addEventListener("fw-data-refresh", handleDataRefresh);
75
- return () => {
76
- window.removeEventListener("fw-data-refresh", handleDataRefresh);
77
- };
104
+ if (typeof window !== "undefined") {
105
+ window.addEventListener("fw-data-refresh", handleDataRefresh);
106
+ return () => {
107
+ window.removeEventListener("fw-data-refresh", handleDataRefresh);
108
+ };
109
+ }
78
110
  }, []);
79
111
  useEffect2(() => {
80
- if (initialTheme) {
112
+ if (initialTheme && initialTheme !== theme) {
81
113
  setTheme(initialTheme);
82
114
  }
83
115
  }, [initialTheme]);
@@ -93,17 +125,28 @@ var ThemeProvider = ({
93
125
  if (body.className !== newClassName) {
94
126
  body.className = newClassName;
95
127
  }
96
- sendMessage(theme);
97
- }, [theme, sendMessage]);
128
+ }, [theme]);
98
129
  const handleThemeChange = (newTheme) => {
99
130
  setTheme(newTheme);
100
- document.cookie = `theme=${newTheme}; path=/; max-age=31536000`;
101
- if (typeof window !== "undefined" && window.__FW_DATA__) {
131
+ if (typeof document !== "undefined") {
132
+ document.cookie = `theme=${newTheme}; path=/; max-age=31536000`;
133
+ }
134
+ if (typeof window !== "undefined") {
135
+ if (!window.__FW_DATA__) {
136
+ window.__FW_DATA__ = {};
137
+ }
102
138
  window.__FW_DATA__ = {
103
139
  ...window.__FW_DATA__,
104
140
  theme: newTheme
105
141
  };
106
142
  }
143
+ lastSentRef.current = newTheme;
144
+ sendMessage(newTheme);
145
+ setTimeout(() => {
146
+ if (lastSentRef.current === newTheme) {
147
+ lastSentRef.current = null;
148
+ }
149
+ }, 500);
107
150
  };
108
151
  return /* @__PURE__ */ jsx(ThemeContext.Provider, { value: { theme, handleThemeChange }, children });
109
152
  };
@@ -114,4 +157,4 @@ export {
114
157
  ThemeProvider,
115
158
  useTheme
116
159
  };
117
- //# sourceMappingURL=themes.js.map
160
+ //# sourceMappingURL=themes.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../modules/react/themes/theme-provider/index.tsx","../../modules/react/hooks/useBroadcastChannel/index.tsx"],"sourcesContent":["import React, { createContext, useContext, useState, useEffect, useRef } from \"react\";\r\nimport { useBroadcastChannel } from \"../../hooks/useBroadcastChannel\";\r\n\r\nconst ThemeContext = createContext<{\r\n theme: string;\r\n handleThemeChange: (theme: string) => void;\r\n}>({ theme: \"light\", handleThemeChange: () => {} });\r\n\r\n// Helper function to get cookie value\r\nfunction getCookie(name: string): string | null {\r\n if (typeof document === \"undefined\") return null;\r\n const value = `; ${document.cookie}`;\r\n const parts = value.split(`; ${name}=`);\r\n if (parts.length === 2) {\r\n return parts.pop()?.split(\";\").shift() || null;\r\n }\r\n return null;\r\n}\r\n\r\nexport const ThemeProvider = ({ \r\n children,\r\n initialTheme \r\n}: { \r\n children: React.ReactNode;\r\n initialTheme?: string;\r\n}) => {\r\n const { message: themeMessage, sendMessage } = useBroadcastChannel('theme_channel');\r\n \r\n // Track what we last sent to avoid loops\r\n const lastSentRef = useRef<string | null>(null);\r\n\r\n // Initialize theme consistently between server and client\r\n const [theme, setTheme] = useState<string>(() => {\r\n if (initialTheme) return initialTheme;\r\n \r\n if (typeof window !== \"undefined\") {\r\n const windowData = (window as any).__FW_DATA__;\r\n if (windowData?.theme) return windowData.theme;\r\n }\r\n \r\n if (typeof window !== \"undefined\") {\r\n const cookieTheme = getCookie(\"theme\");\r\n if (cookieTheme) return cookieTheme;\r\n }\r\n \r\n return \"light\";\r\n });\r\n\r\n // Handle messages from broadcast channel (other tabs)\r\n // This effect ONLY responds to themeMessage changes, not theme changes\r\n useEffect(() => {\r\n if (!themeMessage) return;\r\n \r\n // Ignore if this is a message we just sent\r\n if (themeMessage === lastSentRef.current) {\r\n lastSentRef.current = null;\r\n return;\r\n }\r\n \r\n // Only update if different from current theme\r\n setTheme((currentTheme) => {\r\n if (themeMessage !== currentTheme) {\r\n // Update cookie\r\n if (typeof document !== \"undefined\") {\r\n document.cookie = `theme=${themeMessage}; path=/; max-age=31536000`;\r\n }\r\n \r\n // Update window data\r\n if (typeof window !== \"undefined\") {\r\n if (!(window as any).__FW_DATA__) {\r\n (window as any).__FW_DATA__ = {};\r\n }\r\n (window as any).__FW_DATA__ = {\r\n ...(window as any).__FW_DATA__,\r\n theme: themeMessage,\r\n };\r\n }\r\n \r\n return themeMessage;\r\n }\r\n return currentTheme;\r\n });\r\n }, [themeMessage]); // Only depend on themeMessage, NOT theme!\r\n\r\n // Handle window.__FW_DATA__ changes during SPA navigation\r\n useEffect(() => {\r\n const handleDataRefresh = () => {\r\n if (typeof window !== \"undefined\") {\r\n const windowData = (window as any).__FW_DATA__;\r\n if (windowData?.theme) {\r\n setTheme((currentTheme) => {\r\n if (windowData.theme !== currentTheme) {\r\n return windowData.theme;\r\n }\r\n return currentTheme;\r\n });\r\n }\r\n }\r\n };\r\n\r\n if (typeof window !== \"undefined\") {\r\n window.addEventListener(\"fw-data-refresh\", handleDataRefresh);\r\n return () => {\r\n window.removeEventListener(\"fw-data-refresh\", handleDataRefresh);\r\n };\r\n }\r\n }, []); // No dependencies - event listener doesn't need theme\r\n\r\n // Handle initialTheme prop changes\r\n useEffect(() => {\r\n if (initialTheme && initialTheme !== theme) {\r\n setTheme(initialTheme);\r\n }\r\n }, [initialTheme]); // Only depend on initialTheme, not theme\r\n\r\n // Update body class when theme changes\r\n useEffect(() => {\r\n if (typeof document === \"undefined\") return;\r\n\r\n const body = document.body;\r\n const currentClasses = body.className.split(\" \").filter(Boolean);\r\n const themeClasses = [\"light\", \"dark\"];\r\n const filteredClasses = currentClasses.filter(\r\n (cls) => !themeClasses.includes(cls)\r\n );\r\n const newClassName = [...filteredClasses, theme].filter(Boolean).join(\" \");\r\n \r\n if (body.className !== newClassName) {\r\n body.className = newClassName;\r\n }\r\n }, [theme]);\r\n\r\n const handleThemeChange = (newTheme: string) => {\r\n // Update state immediately\r\n setTheme(newTheme);\r\n\r\n // Update cookie\r\n if (typeof document !== \"undefined\") {\r\n document.cookie = `theme=${newTheme}; path=/; max-age=31536000`;\r\n }\r\n\r\n // Update window data\r\n if (typeof window !== \"undefined\") {\r\n if (!(window as any).__FW_DATA__) {\r\n (window as any).__FW_DATA__ = {};\r\n }\r\n (window as any).__FW_DATA__ = {\r\n ...(window as any).__FW_DATA__,\r\n theme: newTheme,\r\n };\r\n }\r\n \r\n // Mark this as the last value we sent\r\n lastSentRef.current = newTheme;\r\n \r\n // Broadcast to other tabs\r\n sendMessage(newTheme);\r\n \r\n // Clear the ref after a delay\r\n setTimeout(() => {\r\n if (lastSentRef.current === newTheme) {\r\n lastSentRef.current = null;\r\n }\r\n }, 500);\r\n };\r\n\r\n return (\r\n <ThemeContext.Provider value={{ theme, handleThemeChange }}>\r\n {children}\r\n </ThemeContext.Provider>\r\n );\r\n};\r\n\r\nexport const useTheme = () => {\r\n return useContext(ThemeContext);\r\n};\r\n","import React, { useEffect, useState, useRef, useCallback } from \"react\";\r\n\r\nexport const useBroadcastChannel = (channelName: string) => {\r\n const [message, setMessage] = useState(null);\r\n const channelRef = useRef<BroadcastChannel | null>(null);\r\n\r\n useEffect(() => {\r\n // Create channel only once, inside useEffect\r\n if (!channelRef.current && typeof window !== \"undefined\") {\r\n channelRef.current = new BroadcastChannel(channelName);\r\n }\r\n\r\n const channel = channelRef.current;\r\n if (!channel) return;\r\n\r\n const handleMessage = (event: MessageEvent) => {\r\n setMessage(event.data);\r\n };\r\n\r\n channel.onmessage = handleMessage;\r\n\r\n // Clean up the channel when the component unmounts\r\n return () => {\r\n if (channelRef.current) {\r\n channelRef.current.close();\r\n channelRef.current = null;\r\n }\r\n };\r\n }, [channelName]);\r\n\r\n const sendMessage = useCallback((msg: unknown) => {\r\n if (channelRef.current) {\r\n channelRef.current.postMessage(msg);\r\n }\r\n }, []);\r\n\r\n return { message, sendMessage };\r\n};\r\n"],"mappings":";AAAA,SAAgB,eAAe,YAAY,YAAAA,WAAU,aAAAC,YAAW,UAAAC,eAAc;;;ACA9E,SAAgB,WAAW,UAAU,QAAQ,mBAAmB;AAEzD,IAAM,sBAAsB,CAAC,gBAAwB;AAC1D,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,IAAI;AAC3C,QAAM,aAAa,OAAgC,IAAI;AAEvD,YAAU,MAAM;AAEd,QAAI,CAAC,WAAW,WAAW,OAAO,WAAW,aAAa;AACxD,iBAAW,UAAU,IAAI,iBAAiB,WAAW;AAAA,IACvD;AAEA,UAAM,UAAU,WAAW;AAC3B,QAAI,CAAC,QAAS;AAEd,UAAM,gBAAgB,CAAC,UAAwB;AAC7C,iBAAW,MAAM,IAAI;AAAA,IACvB;AAEA,YAAQ,YAAY;AAGpB,WAAO,MAAM;AACX,UAAI,WAAW,SAAS;AACtB,mBAAW,QAAQ,MAAM;AACzB,mBAAW,UAAU;AAAA,MACvB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,WAAW,CAAC;AAEhB,QAAM,cAAc,YAAY,CAAC,QAAiB;AAChD,QAAI,WAAW,SAAS;AACtB,iBAAW,QAAQ,YAAY,GAAG;AAAA,IACpC;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO,EAAE,SAAS,YAAY;AAChC;;;ADkII;AApKJ,IAAM,eAAe,cAGlB,EAAE,OAAO,SAAS,mBAAmB,MAAM;AAAC,EAAE,CAAC;AAGlD,SAAS,UAAU,MAA6B;AAC9C,MAAI,OAAO,aAAa,YAAa,QAAO;AAC5C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