@alepha/react 0.13.7 → 0.13.8

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["frames: StackFrame[]","styles: Record<string, CSSProperties>","subs: Function[]","state","ErrorBoundary","ErrorViewer","envSchema","pages: ConcretePageRoute[]","NestedView","context: Record<string, any>","stack: Array<RouterStackItem>","route","config: Record<string, any>","context","element: ReactNode | Redirection | undefined","ErrorViewer","ClientOnly","children","envSchema","target: PageRoute | undefined","element","hydrationData: ReactHydrationState","query: Record<string, string>","previous: PreviousLayerData[]","query: Record<string, string>","error","schema","options: UseActiveOptions","queryParams"],"sources":["../../src/core/services/ReactPageService.ts","../../src/core/primitives/$page.ts","../../src/core/components/ClientOnly.tsx","../../src/core/components/ErrorViewer.tsx","../../src/core/contexts/RouterLayerContext.ts","../../src/core/errors/Redirection.ts","../../src/core/contexts/AlephaContext.ts","../../src/core/hooks/useAlepha.ts","../../src/core/hooks/useEvents.ts","../../src/core/hooks/useStore.ts","../../src/core/hooks/useRouterState.ts","../../src/core/components/ErrorBoundary.tsx","../../src/core/components/NestedView.tsx","../../src/core/components/NotFound.tsx","../../src/core/providers/ReactPageProvider.ts","../../src/core/providers/ReactServerProvider.ts","../../src/core/services/ReactPageServerService.ts","../../src/core/providers/ReactBrowserRouterProvider.ts","../../src/core/providers/ReactBrowserProvider.ts","../../src/core/services/ReactRouter.ts","../../src/core/hooks/useInject.ts","../../src/core/hooks/useAction.ts","../../src/core/hooks/useClient.ts","../../src/core/hooks/useSchema.ts","../../src/core/hooks/useRouter.ts","../../src/core/components/Link.tsx","../../src/core/hooks/useActive.ts","../../src/core/hooks/useQueryParams.ts","../../src/core/index.ts"],"sourcesContent":["import { AlephaError } from \"alepha\";\nimport type {\n PagePrimitiveRenderOptions,\n PagePrimitiveRenderResult,\n} from \"../primitives/$page.ts\";\n\nexport class ReactPageService {\n public fetch(\n pathname: string,\n options: PagePrimitiveRenderOptions = {},\n ): Promise<{\n html: string;\n response: Response;\n }> {\n throw new AlephaError(\"Fetch is not available for this environment.\");\n }\n\n public render(\n name: string,\n options: PagePrimitiveRenderOptions = {},\n ): Promise<PagePrimitiveRenderResult> {\n throw new AlephaError(\"Render is not available for this environment.\");\n }\n}\n","import {\n $inject,\n type Async,\n createPrimitive,\n Primitive,\n KIND,\n type Static,\n type TSchema,\n} from \"alepha\";\nimport type { ServerRequest } from \"alepha/server\";\nimport type { ServerRouteCache } from \"alepha/server/cache\";\nimport type { FC, ReactNode } from \"react\";\nimport type { ClientOnlyProps } from \"../components/ClientOnly.tsx\";\nimport type { Redirection } from \"../errors/Redirection.ts\";\nimport type { ReactRouterState } from \"../providers/ReactPageProvider.ts\";\nimport { ReactPageService } from \"../services/ReactPageService.ts\";\n\n/**\n * Main primitive for defining a React route in the application.\n *\n * The $page primitive is the core building block for creating type-safe, SSR-enabled React routes.\n * It provides a declarative way to define pages with powerful features:\n *\n * **Routing & Navigation**\n * - URL pattern matching with parameters (e.g., `/users/:id`)\n * - Nested routing with parent-child relationships\n * - Type-safe URL parameter and query string validation\n *\n * **Data Loading**\n * - Server-side data fetching with the `resolve` function\n * - Automatic serialization and hydration for SSR\n * - Access to request context, URL params, and parent data\n *\n * **Component Loading**\n * - Direct component rendering or lazy loading for code splitting\n * - Client-only rendering when browser APIs are needed\n * - Automatic fallback handling during hydration\n *\n * **Performance Optimization**\n * - Static generation for pre-rendered pages at build time\n * - Server-side caching with configurable TTL and providers\n * - Code splitting through lazy component loading\n *\n * **Error Handling**\n * - Custom error handlers with support for redirects\n * - Hierarchical error handling (child → parent)\n * - HTTP status code handling (404, 401, etc.)\n *\n * **Page Animations**\n * - CSS-based enter/exit animations\n * - Dynamic animations based on page state\n * - Custom timing and easing functions\n *\n * **Lifecycle Management**\n * - Server response hooks for headers and status codes\n * - Page leave handlers for cleanup (browser only)\n * - Permission-based access control\n *\n * @example Simple page with data fetching\n * ```typescript\n * const userProfile = $page({\n * path: \"/users/:id\",\n * schema: {\n * params: t.object({ id: t.integer() }),\n * query: t.object({ tab: t.optional(t.text()) })\n * },\n * resolve: async ({ params }) => {\n * const user = await userApi.getUser(params.id);\n * return { user };\n * },\n * lazy: () => import(\"./UserProfile.tsx\")\n * });\n * ```\n *\n * @example Nested routing with error handling\n * ```typescript\n * const projectSection = $page({\n * path: \"/projects/:id\",\n * children: () => [projectBoard, projectSettings],\n * resolve: async ({ params }) => {\n * const project = await projectApi.get(params.id);\n * return { project };\n * },\n * errorHandler: (error) => {\n * if (HttpError.is(error, 404)) {\n * return <ProjectNotFound />;\n * }\n * }\n * });\n * ```\n *\n * @example Static generation with caching\n * ```typescript\n * const blogPost = $page({\n * path: \"/blog/:slug\",\n * static: {\n * entries: posts.map(p => ({ params: { slug: p.slug } }))\n * },\n * resolve: async ({ params }) => {\n * const post = await loadPost(params.slug);\n * return { post };\n * }\n * });\n * ```\n */\nexport const $page = <\n TConfig extends PageConfigSchema = PageConfigSchema,\n TProps extends object = TPropsDefault,\n TPropsParent extends object = TPropsParentDefault,\n>(\n options: PagePrimitiveOptions<TConfig, TProps, TPropsParent>,\n): PagePrimitive<TConfig, TProps, TPropsParent> => {\n return createPrimitive(\n PagePrimitive<TConfig, TProps, TPropsParent>,\n options,\n );\n};\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface PagePrimitiveOptions<\n TConfig extends PageConfigSchema = PageConfigSchema,\n TProps extends object = TPropsDefault,\n TPropsParent extends object = TPropsParentDefault,\n> {\n /**\n * Identifier name for the page. Must be unique.\n *\n * @default Primitive key\n */\n name?: string;\n\n /**\n * Add a pathname to the page.\n *\n * Pathname can contain parameters, like `/post/:slug`.\n *\n * @default \"\"\n */\n path?: string;\n\n /**\n * Add an input schema to define:\n * - `params`: parameters from the pathname.\n * - `query`: query parameters from the URL.\n */\n schema?: TConfig;\n\n /**\n * Load data before rendering the page.\n *\n * This function receives\n * - the request context (params, query, etc.)\n * - the parent props (if page has a parent)\n *\n * > In SSR, the returned data will be serialized and sent to the client, then reused during the client-side hydration.\n *\n * Resolve can be stopped by throwing an error, which will be handled by the `errorHandler` function.\n * It's common to throw a `NotFoundError` to display a 404 page.\n *\n * RedirectError can be thrown to redirect the user to another page.\n */\n resolve?: (context: PageResolve<TConfig, TPropsParent>) => Async<TProps>;\n\n /**\n * Default props to pass to the component when rendering the page.\n *\n * Resolved props from the `resolve` function will override these default props.\n */\n props?: () => Partial<TProps>;\n\n /**\n * The component to render when the page is loaded.\n *\n * If `lazy` is defined, this will be ignored.\n * Prefer using `lazy` to improve the initial loading time.\n */\n component?: FC<TProps & TPropsParent>;\n\n /**\n * Lazy load the component when the page is loaded.\n *\n * It's recommended to use this for components to improve the initial loading time\n * and enable code-splitting.\n */\n lazy?: () => Promise<{ default: FC<TProps & TPropsParent> }>;\n\n /**\n * Attach child pages to create nested routes.\n * This will make the page a parent route.\n */\n children?: Array<PagePrimitive> | (() => Array<PagePrimitive>);\n\n /**\n * Define a parent page for nested routing.\n */\n parent?: PagePrimitive<PageConfigSchema, TPropsParent, any>;\n\n /**\n * Function to determine if the page can be accessed.\n *\n * If it returns false, the page will not be accessible and a 403 Forbidden error will be returned.\n * This function can be used to implement permission-based access control.\n */\n can?: () => boolean;\n\n /**\n * Catch any error from the `resolve` function or during `rendering`.\n *\n * Expected to return one of the following:\n * - a ReactNode to render an error page\n * - a Redirection to redirect the user\n * - undefined to let the error propagate\n *\n * If not defined, the error will be thrown and handled by the server or client error handler.\n * If a leaf $page does not define an error handler, the error can be caught by parent pages.\n *\n * @example Catch a 404 from API and render a custom not found component:\n * ```ts\n * resolve: async ({ params, query }) => {\n * api.fetch(\"/api/resource\", { params, query });\n * },\n * errorHandler: (error, context) => {\n * if (HttpError.is(error, 404)) {\n * return <ResourceNotFound />;\n * }\n * }\n * ```\n *\n * @example Catch an 401 error and redirect the user to the login page:\n * ```ts\n * resolve: async ({ params, query }) => {\n * // but the user is not authenticated\n * api.fetch(\"/api/resource\", { params, query });\n * },\n * errorHandler: (error, context) => {\n * if (HttpError.is(error, 401)) {\n * // throwing a Redirection is also valid!\n * return new Redirection(\"/login\");\n * }\n * }\n * ```\n */\n errorHandler?: ErrorHandler;\n\n /**\n * If true, the page will be considered as a static page, immutable and cacheable.\n * Replace boolean by an object to define static entries. (e.g. list of params/query)\n *\n * Browser-side: it only works with `alepha/vite`, which can pre-render the page at build time.\n *\n * Server-side: It will act as timeless cached page. You can use `cache` to configure the cache behavior.\n */\n static?:\n | boolean\n | {\n entries?: Array<Partial<PageRequestConfig<TConfig>>>;\n };\n\n cache?: ServerRouteCache;\n\n /**\n * If true, force the page to be rendered only on the client-side (browser).\n * It uses the `<ClientOnly/>` component to render the page.\n */\n client?: boolean | ClientOnlyProps;\n\n /**\n * Called before the server response is sent to the client. (server only)\n */\n onServerResponse?: (request: ServerRequest) => unknown;\n\n /**\n * Called when user leaves the page. (browser only)\n */\n onLeave?: () => void;\n\n /**\n * @experimental\n *\n * Add a css animation when the page is loaded or unloaded.\n * It uses CSS animations, so you need to define the keyframes in your CSS.\n *\n * @example Simple animation name\n * ```ts\n * animation: \"fadeIn\"\n * ```\n *\n * CSS example:\n * ```css\n * @keyframes fadeIn {\n * from { opacity: 0; }\n * to { opacity: 1; }\n * }\n * ```\n *\n * @example Detailed animation\n * ```ts\n * animation: {\n * enter: { name: \"fadeIn\", duration: 300 },\n * exit: { name: \"fadeOut\", duration: 200, timing: \"ease-in-out\" },\n * }\n * ```\n *\n * @example Only exit animation\n * ```ts\n * animation: {\n * exit: \"fadeOut\"\n * }\n * ```\n *\n * @example With custom timing function\n * ```ts\n * animation: {\n * enter: { name: \"fadeIn\", duration: 300, timing: \"cubic-bezier(0.4, 0, 0.2, 1)\" },\n * exit: { name: \"fadeOut\", duration: 200, timing: \"ease-in-out\" },\n * }\n * ```\n */\n animation?: PageAnimation;\n}\n\nexport type ErrorHandler = (\n error: Error,\n state: ReactRouterState,\n) => ReactNode | Redirection | undefined;\n\nexport class PagePrimitive<\n TConfig extends PageConfigSchema = PageConfigSchema,\n TProps extends object = TPropsDefault,\n TPropsParent extends object = TPropsParentDefault,\n> extends Primitive<PagePrimitiveOptions<TConfig, TProps, TPropsParent>> {\n protected readonly reactPageService = $inject(ReactPageService);\n\n protected onInit() {\n if (this.options.static) {\n this.options.cache ??= {\n store: {\n provider: \"memory\",\n ttl: [1, \"week\"],\n },\n };\n }\n }\n\n public get name(): string {\n return this.options.name ?? this.config.propertyKey;\n }\n\n /**\n * For testing or build purposes.\n *\n * This will render the page (HTML layout included or not) and return the HTML + context.\n * Only valid for server-side rendering, it will throw an error if called on the client-side.\n */\n public async render(\n options?: PagePrimitiveRenderOptions,\n ): Promise<PagePrimitiveRenderResult> {\n return this.reactPageService.render(this.name, options);\n }\n\n public async fetch(options?: PagePrimitiveRenderOptions): Promise<{\n html: string;\n response: Response;\n }> {\n return this.reactPageService.fetch(this.options.path || \"\", options);\n }\n\n public match(url: string): boolean {\n // TODO: Implement a way to match the URL against the pathname\n return false;\n }\n\n public pathname(config: any) {\n // TODO: Implement a way to generate the pathname based on the config\n return this.options.path || \"\";\n }\n}\n\n$page[KIND] = PagePrimitive;\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface PageConfigSchema {\n query?: TSchema;\n params?: TSchema;\n}\n\nexport type TPropsDefault = any;\n\nexport type TPropsParentDefault = {};\n\nexport interface PagePrimitiveRenderOptions {\n params?: Record<string, string>;\n query?: Record<string, string>;\n\n /**\n * If true, the HTML layout will be included in the response.\n * If false, only the page content will be returned.\n *\n * @default true\n */\n html?: boolean;\n hydration?: boolean;\n}\n\nexport interface PagePrimitiveRenderResult {\n html: string;\n state: ReactRouterState;\n redirect?: string;\n}\n\nexport interface PageRequestConfig<\n TConfig extends PageConfigSchema = PageConfigSchema,\n> {\n params: TConfig[\"params\"] extends TSchema\n ? Static<TConfig[\"params\"]>\n : Record<string, string>;\n\n query: TConfig[\"query\"] extends TSchema\n ? Static<TConfig[\"query\"]>\n : Record<string, string>;\n}\n\nexport type PageResolve<\n TConfig extends PageConfigSchema = PageConfigSchema,\n TPropsParent extends object = TPropsParentDefault,\n> = PageRequestConfig<TConfig> &\n TPropsParent &\n Omit<ReactRouterState, \"layers\" | \"onError\">;\n\nexport type PageAnimation =\n | PageAnimationObject\n | ((state: ReactRouterState) => PageAnimationObject | undefined);\n\ntype PageAnimationObject =\n | CssAnimationName\n | {\n enter?: CssAnimation | CssAnimationName;\n exit?: CssAnimation | CssAnimationName;\n };\n\ntype CssAnimationName = string;\n\ntype CssAnimation = {\n name: string;\n duration?: number;\n timing?: string;\n};\n","import {\n type PropsWithChildren,\n type ReactNode,\n useEffect,\n useState,\n} from \"react\";\n\nexport interface ClientOnlyProps {\n fallback?: ReactNode;\n disabled?: boolean;\n}\n\n/**\n * A small utility component that renders its children only on the client side.\n *\n * Optionally, you can provide a fallback React node that will be rendered.\n *\n * You should use this component when\n * - you have code that relies on browser-specific APIs\n * - you want to avoid server-side rendering for a specific part of your application\n * - you want to prevent pre-rendering of a component\n */\nconst ClientOnly = (props: PropsWithChildren<ClientOnlyProps>) => {\n const [mounted, setMounted] = useState(false);\n\n useEffect(() => setMounted(true), []);\n\n if (props.disabled) {\n return props.children;\n }\n\n return mounted ? props.children : props.fallback;\n};\n\nexport default ClientOnly;\n","import type { Alepha } from \"alepha\";\nimport { type CSSProperties, useState } from \"react\";\n\ninterface ErrorViewerProps {\n error: Error;\n alepha: Alepha;\n}\n\ninterface StackFrame {\n fn: string;\n file: string;\n line: string;\n col: string;\n raw: string;\n}\n\n/**\n * Error viewer component that displays error details in development mode\n */\nconst ErrorViewer = ({ error, alepha }: ErrorViewerProps) => {\n const [expanded, setExpanded] = useState(false);\n const isProduction = alepha.isProduction();\n\n if (isProduction) {\n return <ErrorViewerProduction />;\n }\n\n const frames = parseStackTrace(error.stack);\n const visibleFrames = expanded ? frames : frames.slice(0, 6);\n const hiddenCount = frames.length - 6;\n\n return (\n <div style={styles.overlay}>\n <div style={styles.container}>\n <Header error={error} />\n <StackTraceSection\n frames={frames}\n visibleFrames={visibleFrames}\n expanded={expanded}\n hiddenCount={hiddenCount}\n onToggle={() => setExpanded(!expanded)}\n />\n </div>\n </div>\n );\n};\n\nexport default ErrorViewer;\n\n/**\n * Parse stack trace string into structured frames\n */\nfunction parseStackTrace(stack?: string): StackFrame[] {\n if (!stack) return [];\n\n const lines = stack.split(\"\\n\").slice(1);\n const frames: StackFrame[] = [];\n\n for (const line of lines) {\n const trimmed = line.trim();\n if (!trimmed.startsWith(\"at \")) continue;\n\n const frame = parseStackLine(trimmed);\n if (frame) frames.push(frame);\n }\n\n return frames;\n}\n\n/**\n * Parse a single stack trace line into a structured frame\n */\nfunction parseStackLine(line: string): StackFrame | null {\n const withFn = line.match(/^at\\s+(.+?)\\s+\\((.+):(\\d+):(\\d+)\\)$/);\n if (withFn) {\n return {\n fn: withFn[1],\n file: withFn[2],\n line: withFn[3],\n col: withFn[4],\n raw: line,\n };\n }\n\n const withoutFn = line.match(/^at\\s+(.+):(\\d+):(\\d+)$/);\n if (withoutFn) {\n return {\n fn: \"<anonymous>\",\n file: withoutFn[1],\n line: withoutFn[2],\n col: withoutFn[3],\n raw: line,\n };\n }\n\n return { fn: \"\", file: line.replace(/^at\\s+/, \"\"), line: \"\", col: \"\", raw: line };\n}\n\n/**\n * Copy text to clipboard\n */\nfunction copyToClipboard(text: string): void {\n navigator.clipboard.writeText(text).catch((err) => {\n console.error(\"Clipboard error:\", err);\n });\n}\n\n/**\n * Header section with error type and message\n */\nfunction Header({ error }: { error: Error }) {\n const [copied, setCopied] = useState(false);\n\n const handleCopy = () => {\n copyToClipboard(error.stack || error.message);\n setCopied(true);\n setTimeout(() => setCopied(false), 2000);\n };\n\n return (\n <div style={styles.header}>\n <div style={styles.headerTop}>\n <div style={styles.badge}>{error.name}</div>\n <button type=\"button\" onClick={handleCopy} style={styles.copyBtn}>\n {copied ? \"Copied\" : \"Copy Stack\"}\n </button>\n </div>\n <h1 style={styles.message}>{error.message}</h1>\n </div>\n );\n}\n\n/**\n * Stack trace section with expandable frames\n */\nfunction StackTraceSection({\n frames,\n visibleFrames,\n expanded,\n hiddenCount,\n onToggle,\n}: {\n frames: StackFrame[];\n visibleFrames: StackFrame[];\n expanded: boolean;\n hiddenCount: number;\n onToggle: () => void;\n}) {\n if (frames.length === 0) return null;\n\n return (\n <div style={styles.stackSection}>\n <div style={styles.stackHeader}>Call Stack</div>\n <div style={styles.frameList}>\n {visibleFrames.map((frame, i) => (\n <StackFrameRow key={i} frame={frame} index={i} />\n ))}\n {!expanded && hiddenCount > 0 && (\n <button type=\"button\" onClick={onToggle} style={styles.expandBtn}>\n Show {hiddenCount} more frames\n </button>\n )}\n {expanded && hiddenCount > 0 && (\n <button type=\"button\" onClick={onToggle} style={styles.expandBtn}>\n Show less\n </button>\n )}\n </div>\n </div>\n );\n}\n\n/**\n * Single stack frame row\n */\nfunction StackFrameRow({ frame, index }: { frame: StackFrame; index: number }) {\n const isFirst = index === 0;\n const fileName = frame.file.split(\"/\").pop() || frame.file;\n const dirPath = frame.file.substring(0, frame.file.length - fileName.length);\n\n return (\n <div\n style={{\n ...styles.frame,\n ...(isFirst ? styles.frameFirst : {}),\n }}\n >\n <div style={styles.frameIndex}>{index + 1}</div>\n <div style={styles.frameContent}>\n {frame.fn && (\n <div style={styles.fnName}>\n {frame.fn}\n </div>\n )}\n <div style={styles.filePath}>\n <span style={styles.dirPath}>{dirPath}</span>\n <span style={styles.fileName}>{fileName}</span>\n {frame.line && (\n <span style={styles.lineCol}>\n :{frame.line}:{frame.col}\n </span>\n )}\n </div>\n </div>\n </div>\n );\n}\n\n/**\n * Production error view - minimal information\n */\nfunction ErrorViewerProduction() {\n return (\n <div style={styles.overlay}>\n <div style={styles.prodContainer}>\n <div style={styles.prodIcon}>!</div>\n <h1 style={styles.prodTitle}>Application Error</h1>\n <p style={styles.prodMessage}>\n An unexpected error occurred. Please try again later.\n </p>\n <button\n type=\"button\"\n onClick={() => window.location.reload()}\n style={styles.prodButton}\n >\n Reload Page\n </button>\n </div>\n </div>\n );\n}\n\nconst styles: Record<string, CSSProperties> = {\n overlay: {\n position: \"fixed\",\n inset: 0,\n backgroundColor: \"rgba(0, 0, 0, 0.8)\",\n display: \"flex\",\n alignItems: \"flex-start\",\n justifyContent: \"center\",\n padding: \"40px 20px\",\n overflow: \"auto\",\n fontFamily:\n '-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif',\n zIndex: 99999,\n },\n container: {\n width: \"100%\",\n maxWidth: \"960px\",\n backgroundColor: \"#1a1a1a\",\n borderRadius: \"12px\",\n overflow: \"hidden\",\n boxShadow: \"0 25px 50px -12px rgba(0, 0, 0, 0.5)\",\n },\n header: {\n padding: \"24px 28px\",\n borderBottom: \"1px solid #333\",\n background: \"linear-gradient(to bottom, #1f1f1f, #1a1a1a)\",\n },\n headerTop: {\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"space-between\",\n marginBottom: \"16px\",\n },\n badge: {\n display: \"inline-block\",\n padding: \"6px 12px\",\n backgroundColor: \"#dc2626\",\n color: \"#fff\",\n fontSize: \"12px\",\n fontWeight: 600,\n borderRadius: \"6px\",\n letterSpacing: \"0.025em\",\n },\n copyBtn: {\n padding: \"8px 16px\",\n backgroundColor: \"transparent\",\n color: \"#888\",\n fontSize: \"13px\",\n fontWeight: 500,\n border: \"1px solid #444\",\n borderRadius: \"6px\",\n cursor: \"pointer\",\n transition: \"all 0.15s\",\n },\n message: {\n margin: 0,\n fontSize: \"20px\",\n fontWeight: 500,\n color: \"#fff\",\n lineHeight: 1.5,\n wordBreak: \"break-word\",\n },\n stackSection: {\n padding: \"0\",\n },\n stackHeader: {\n padding: \"16px 28px\",\n fontSize: \"11px\",\n fontWeight: 600,\n color: \"#666\",\n textTransform: \"uppercase\",\n letterSpacing: \"0.1em\",\n borderBottom: \"1px solid #2a2a2a\",\n },\n frameList: {\n display: \"flex\",\n flexDirection: \"column\",\n },\n frame: {\n display: \"flex\",\n alignItems: \"flex-start\",\n padding: \"14px 28px\",\n borderBottom: \"1px solid #252525\",\n transition: \"background-color 0.15s\",\n },\n frameFirst: {\n backgroundColor: \"rgba(220, 38, 38, 0.1)\",\n },\n frameIndex: {\n width: \"28px\",\n flexShrink: 0,\n fontSize: \"12px\",\n fontWeight: 500,\n color: \"#555\",\n fontFamily: \"monospace\",\n },\n frameContent: {\n flex: 1,\n minWidth: 0,\n },\n fnName: {\n fontSize: \"14px\",\n fontWeight: 500,\n color: \"#e5e5e5\",\n marginBottom: \"4px\",\n fontFamily:\n 'ui-monospace, SFMono-Regular, \"SF Mono\", Menlo, Consolas, monospace',\n },\n filePath: {\n fontSize: \"13px\",\n color: \"#888\",\n fontFamily:\n 'ui-monospace, SFMono-Regular, \"SF Mono\", Menlo, Consolas, monospace',\n wordBreak: \"break-all\",\n },\n dirPath: {\n color: \"#555\",\n },\n fileName: {\n color: \"#0ea5e9\",\n },\n lineCol: {\n color: \"#eab308\",\n },\n expandBtn: {\n padding: \"16px 28px\",\n backgroundColor: \"transparent\",\n color: \"#666\",\n fontSize: \"13px\",\n fontWeight: 500,\n border: \"none\",\n borderTop: \"1px solid #252525\",\n cursor: \"pointer\",\n textAlign: \"left\",\n transition: \"all 0.15s\",\n },\n prodContainer: {\n textAlign: \"center\",\n padding: \"60px 40px\",\n backgroundColor: \"#1a1a1a\",\n borderRadius: \"12px\",\n maxWidth: \"400px\",\n },\n prodIcon: {\n width: \"64px\",\n height: \"64px\",\n margin: \"0 auto 24px\",\n backgroundColor: \"#dc2626\",\n borderRadius: \"50%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n fontSize: \"32px\",\n fontWeight: 700,\n color: \"#fff\",\n },\n prodTitle: {\n margin: \"0 0 12px\",\n fontSize: \"24px\",\n fontWeight: 600,\n color: \"#fff\",\n },\n prodMessage: {\n margin: \"0 0 28px\",\n fontSize: \"15px\",\n color: \"#888\",\n lineHeight: 1.6,\n },\n prodButton: {\n padding: \"12px 24px\",\n backgroundColor: \"#fff\",\n color: \"#000\",\n fontSize: \"14px\",\n fontWeight: 600,\n border: \"none\",\n borderRadius: \"8px\",\n cursor: \"pointer\",\n },\n};\n","import { createContext } from \"react\";\nimport type { ErrorHandler } from \"../primitives/$page.ts\";\n\nexport interface RouterLayerContextValue {\n index: number;\n path: string;\n onError: ErrorHandler;\n}\n\nexport const RouterLayerContext = createContext<\n RouterLayerContextValue | undefined\n>(undefined);\n","/**\n * Used for Redirection during the page loading.\n *\n * Depends on the context, it can be thrown or just returned.\n */\nexport class Redirection extends Error {\n public readonly redirect: string;\n\n constructor(redirect: string) {\n super(\"Redirection\");\n this.redirect = redirect;\n }\n}\n","import type { Alepha } from \"alepha\";\nimport { createContext } from \"react\";\n\nexport const AlephaContext = createContext<Alepha | undefined>(undefined);\n","import { type Alepha, AlephaError } from \"alepha\";\nimport { useContext } from \"react\";\nimport { AlephaContext } from \"../contexts/AlephaContext.ts\";\n\n/**\n * Main Alepha hook.\n *\n * It provides access to the Alepha instance within a React component.\n *\n * With Alepha, you can access the core functionalities of the framework:\n *\n * - alepha.state() for state management\n * - alepha.inject() for dependency injection\n * - alepha.events.emit() for event handling\n * etc...\n */\nexport const useAlepha = (): Alepha => {\n const alepha = useContext(AlephaContext);\n if (!alepha) {\n throw new AlephaError(\n \"Hook 'useAlepha()' must be used within an AlephaContext.Provider\",\n );\n }\n\n return alepha;\n};\n","import type { Async, Hook, Hooks } from \"alepha\";\nimport { type DependencyList, useEffect } from \"react\";\nimport { useAlepha } from \"./useAlepha.ts\";\n\n/**\n * Allow subscribing to multiple Alepha events. See {@link Hooks} for available events.\n *\n * useEvents is fully typed to ensure correct event callback signatures.\n *\n * @example\n * ```tsx\n * useEvents(\n * {\n * \"react:transition:begin\": (ev) => {\n * console.log(\"Transition began to:\", ev.to);\n * },\n * \"react:transition:error\": {\n * priority: \"first\",\n * callback: (ev) => {\n * console.error(\"Transition error:\", ev.error);\n * },\n * },\n * },\n * [],\n * );\n * ```\n */\nexport const useEvents = (opts: UseEvents, deps: DependencyList) => {\n const alepha = useAlepha();\n\n useEffect(() => {\n if (!alepha.isBrowser()) {\n return;\n }\n\n const subs: Function[] = [];\n for (const [name, hook] of Object.entries(opts)) {\n subs.push(alepha.events.on(name as any, hook as any));\n }\n\n return () => {\n for (const clear of subs) {\n clear();\n }\n };\n }, deps);\n};\n\ntype UseEvents = {\n [T in keyof Hooks]?: Hook<T> | ((payload: Hooks[T]) => Async<void>);\n};\n","import type { State, Static, TAtomObject } from \"alepha\";\nimport { Atom } from \"alepha\";\nimport { useEffect, useMemo, useState } from \"react\";\nimport { useAlepha } from \"./useAlepha.ts\";\n\n/**\n * Hook to access and mutate the Alepha state.\n */\nfunction useStore<T extends TAtomObject>(\n target: Atom<T>,\n defaultValue?: Static<T>,\n): UseStoreReturn<Static<T>>;\nfunction useStore<Key extends keyof State>(\n target: Key,\n defaultValue?: State[Key],\n): UseStoreReturn<State[Key]>;\nfunction useStore(target: any, defaultValue?: any): any {\n const alepha = useAlepha();\n\n useMemo(() => {\n if (defaultValue != null && alepha.store.get(target) == null) {\n alepha.store.set(target, defaultValue);\n }\n }, [defaultValue]);\n\n const [state, setState] = useState(alepha.store.get(target));\n\n useEffect(() => {\n if (!alepha.isBrowser()) {\n return;\n }\n\n const key = target instanceof Atom ? target.key : target;\n\n return alepha.events.on(\"state:mutate\", (ev) => {\n if (ev.key === key) {\n setState(ev.value);\n }\n });\n }, []);\n\n return [\n state,\n (value: any) => {\n alepha.store.set(target, value);\n },\n ] as const;\n}\n\nexport type UseStoreReturn<T> = [T, (value: T) => void];\n\nexport { useStore };\n","import { AlephaError } from \"alepha\";\nimport type { ReactRouterState } from \"../providers/ReactPageProvider.ts\";\nimport { useStore } from \"./useStore.ts\";\n\nexport const useRouterState = (): ReactRouterState => {\n const [state] = useStore(\"alepha.react.router.state\");\n if (!state) {\n throw new AlephaError(\"Missing react router state\");\n }\n return state;\n};\n","import React, {\n type ErrorInfo,\n type PropsWithChildren,\n type ReactNode,\n} from \"react\";\n\n/**\n * Props for the ErrorBoundary component.\n */\nexport interface ErrorBoundaryProps {\n /**\n * Fallback React node to render when an error is caught.\n * If not provided, a default error message will be shown.\n */\n fallback: (error: Error) => ReactNode;\n\n /**\n * Optional callback that receives the error and error info.\n * Use this to log errors to a monitoring service.\n */\n onError?: (error: Error, info: ErrorInfo) => void;\n}\n\n/**\n * State of the ErrorBoundary component.\n */\ninterface ErrorBoundaryState {\n error?: Error;\n}\n\n/**\n * A reusable error boundary for catching rendering errors\n * in any part of the React component tree.\n */\nexport class ErrorBoundary extends React.Component<\n PropsWithChildren<ErrorBoundaryProps>,\n ErrorBoundaryState\n> {\n constructor(props: ErrorBoundaryProps) {\n super(props);\n this.state = {};\n }\n\n /**\n * Update state so the next render shows the fallback UI.\n */\n static getDerivedStateFromError(error: Error): ErrorBoundaryState {\n return {\n error,\n };\n }\n\n /**\n * Lifecycle method called when an error is caught.\n * You can log the error or perform side effects here.\n */\n componentDidCatch(error: Error, info: ErrorInfo): void {\n if (this.props.onError) {\n this.props.onError(error, info);\n }\n }\n\n render(): ReactNode {\n if (this.state.error) {\n return this.props.fallback(this.state.error);\n }\n\n return this.props.children;\n }\n}\n\nexport default ErrorBoundary;\n","import { memo, type ReactNode, use, useRef, useState } from \"react\";\nimport { RouterLayerContext } from \"../contexts/RouterLayerContext.ts\";\nimport type { ErrorHandler, PageAnimation } from \"../primitives/$page.ts\";\nimport { Redirection } from \"../errors/Redirection.ts\";\nimport { useEvents } from \"../hooks/useEvents.ts\";\nimport { useRouterState } from \"../hooks/useRouterState.ts\";\nimport type { ReactRouterState } from \"../providers/ReactPageProvider.ts\";\nimport ErrorBoundary from \"./ErrorBoundary.tsx\";\nimport ErrorViewer from \"./ErrorViewer.tsx\";\nimport { useAlepha } from \"../hooks/useAlepha.ts\";\n\nexport interface NestedViewProps {\n children?: ReactNode;\n errorBoundary?: false | ((error: Error) => ReactNode);\n}\n\n/**\n * A component that renders the current view of the nested router layer.\n *\n * To be simple, it renders the `element` of the current child page of a parent page.\n *\n * @example\n * ```tsx\n * import { NestedView } from \"@alepha/react\";\n *\n * class App {\n * parent = $page({\n * component: () => <NestedView />,\n * });\n *\n * child = $page({\n * parent: this.root,\n * component: () => <div>Child Page</div>,\n * });\n * }\n * ```\n */\nconst NestedView = (props: NestedViewProps) => {\n const routerLayer = use(RouterLayerContext);\n const index = routerLayer?.index ?? 0;\n const onError = routerLayer?.onError;\n const state = useRouterState();\n const alepha = useAlepha();\n\n const [view, setView] = useState<ReactNode | undefined>(\n state.layers[index]?.element,\n );\n\n const [animation, setAnimation] = useState(\"\");\n const animationExitDuration = useRef<number>(0);\n const animationExitNow = useRef<number>(0);\n\n useEvents(\n {\n \"react:transition:begin\": async ({ previous, state }) => {\n // --------- Animations Begin ---------\n const layer = previous.layers[index];\n if (!layer) {\n return;\n }\n\n if (`${state.url.pathname}/`.startsWith(`${layer.path}/`)) {\n return;\n }\n\n const animationExit = parseAnimation(\n layer.route?.animation,\n state,\n \"exit\",\n );\n\n if (animationExit) {\n const duration = animationExit.duration || 200;\n animationExitNow.current = Date.now();\n animationExitDuration.current = duration;\n setAnimation(animationExit.animation);\n } else {\n animationExitNow.current = 0;\n animationExitDuration.current = 0;\n setAnimation(\"\");\n }\n // --------- Animations End ---------\n },\n \"react:transition:end\": async ({ state }) => {\n const layer = state.layers[index];\n\n // --------- Animations Begin ---------\n if (animationExitNow.current) {\n const duration = animationExitDuration.current;\n const diff = Date.now() - animationExitNow.current;\n if (diff < duration) {\n await new Promise((resolve) =>\n setTimeout(resolve, duration - diff),\n );\n }\n }\n // --------- Animations End ---------\n\n if (!layer?.cache) {\n setView(layer?.element);\n\n // --------- Animations Begin ---------\n const animationEnter = parseAnimation(\n layer?.route?.animation,\n state,\n \"enter\",\n );\n\n if (animationEnter) {\n setAnimation(animationEnter.animation);\n } else {\n setAnimation(\"\");\n }\n // --------- Animations End ---------\n }\n },\n },\n [],\n );\n\n let element = view ?? props.children ?? null;\n\n // --------- Animations Begin ---------\n if (animation) {\n element = (\n <div\n style={{\n display: \"flex\",\n flex: 1,\n height: \"100%\",\n width: \"100%\",\n position: \"relative\",\n overflow: \"hidden\",\n }}\n >\n <div\n style={{ height: \"100%\", width: \"100%\", display: \"flex\", animation }}\n >\n {element}\n </div>\n </div>\n );\n }\n // --------- Animations End ---------\n\n if (props.errorBoundary === false) {\n return <>{element}</>;\n }\n\n if (props.errorBoundary) {\n return (\n <ErrorBoundary fallback={props.errorBoundary}>{element}</ErrorBoundary>\n );\n }\n\n const fallback = (error: Error) => {\n const result = onError?.(error, state) ?? <ErrorViewer error={error} alepha={alepha}/>;\n if (result instanceof Redirection) {\n return \"Redirection inside ErrorBoundary is not allowed.\";\n }\n return result as ReactNode;\n }\n\n return (\n <ErrorBoundary fallback={fallback}>\n {element}\n </ErrorBoundary>\n );\n};\n\nexport default memo(NestedView);\n\nfunction parseAnimation(\n animationLike: PageAnimation | undefined,\n state: ReactRouterState,\n type: \"enter\" | \"exit\" = \"enter\",\n):\n | {\n duration: number;\n animation: string;\n }\n | undefined {\n if (!animationLike) {\n return undefined;\n }\n\n const DEFAULT_DURATION = 300;\n\n const animation =\n typeof animationLike === \"function\" ? animationLike(state) : animationLike;\n\n if (typeof animation === \"string\") {\n if (type === \"exit\") {\n return;\n }\n return {\n duration: DEFAULT_DURATION,\n animation: `${DEFAULT_DURATION}ms ${animation}`,\n };\n }\n\n if (typeof animation === \"object\") {\n const anim = animation[type];\n const duration =\n typeof anim === \"object\"\n ? (anim.duration ?? DEFAULT_DURATION)\n : DEFAULT_DURATION;\n const name = typeof anim === \"object\" ? anim.name : anim;\n\n if (type === \"exit\") {\n const timing = typeof anim === \"object\" ? (anim.timing ?? \"\") : \"\";\n return {\n duration,\n animation: `${duration}ms ${timing} ${name}`,\n };\n }\n\n const timing = typeof anim === \"object\" ? (anim.timing ?? \"\") : \"\";\n\n return {\n duration,\n animation: `${duration}ms ${timing} ${name}`,\n };\n }\n\n return undefined;\n}\n","import type { CSSProperties } from \"react\";\n\nexport default function NotFoundPage(props: { style?: CSSProperties }) {\n return (\n <div\n style={{\n width: \"100%\",\n minHeight: \"90vh\",\n boxSizing: \"border-box\",\n display: \"flex\",\n flexDirection: \"column\",\n justifyContent: \"center\",\n alignItems: \"center\",\n textAlign: \"center\",\n fontFamily:\n 'system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif',\n padding: \"2rem\",\n ...props.style,\n }}\n >\n <div style={{ fontSize: \"6rem\", fontWeight: 200, lineHeight: 1 }}>404</div>\n <div style={{ fontSize: \"0.875rem\", marginTop: \"1rem\", opacity: 0.6 }}>\n Page not found\n </div>\n </div>\n );\n}\n","import {\n $env,\n $hook,\n $inject,\n Alepha,\n AlephaError,\n type Static,\n type TSchema,\n t,\n} from \"alepha\";\nimport { $logger } from \"alepha/logger\";\nimport { createElement, type ReactNode, StrictMode } from \"react\";\nimport ClientOnly from \"../components/ClientOnly.tsx\";\nimport ErrorViewer from \"../components/ErrorViewer.tsx\";\nimport NestedView from \"../components/NestedView.tsx\";\nimport NotFoundPage from \"../components/NotFound.tsx\";\nimport { AlephaContext } from \"../contexts/AlephaContext.ts\";\nimport { RouterLayerContext } from \"../contexts/RouterLayerContext.ts\";\nimport {\n $page,\n type ErrorHandler,\n type PagePrimitive,\n type PagePrimitiveOptions,\n} from \"../primitives/$page.ts\";\nimport { Redirection } from \"../errors/Redirection.ts\";\n\nconst envSchema = t.object({\n REACT_STRICT_MODE: t.boolean({ default: true }),\n});\n\ndeclare module \"alepha\" {\n export interface Env extends Partial<Static<typeof envSchema>> {}\n}\n\nexport class ReactPageProvider {\n protected readonly log = $logger();\n protected readonly env = $env(envSchema);\n protected readonly alepha = $inject(Alepha);\n protected readonly pages: PageRoute[] = [];\n\n public getPages(): PageRoute[] {\n return this.pages;\n }\n\n public getConcretePages(): ConcretePageRoute[] {\n const pages: ConcretePageRoute[] = [];\n for (const page of this.pages) {\n if (page.children && page.children.length > 0) {\n continue;\n }\n\n // check if the page has dynamic params\n const fullPath = this.pathname(page.name);\n if (fullPath.includes(\":\") || fullPath.includes(\"*\")) {\n if (typeof page.static === \"object\") {\n const entries = page.static.entries;\n if (entries && entries.length > 0) {\n for (const entry of entries) {\n const params = entry.params as Record<string, string>;\n const path = this.compile(page.path ?? \"\", params);\n if (!path.includes(\":\") && !path.includes(\"*\")) {\n pages.push({\n ...page,\n name: params[Object.keys(params)[0]],\n staticName: page.name,\n path,\n ...entry,\n });\n }\n }\n }\n }\n\n continue;\n }\n\n pages.push(page);\n }\n return pages;\n }\n\n public page(name: string): PageRoute {\n for (const page of this.pages) {\n if (page.name === name) {\n return page;\n }\n }\n\n throw new AlephaError(`Page '${name}' not found`);\n }\n\n public pathname(\n name: string,\n options: {\n params?: Record<string, string>;\n query?: Record<string, string>;\n } = {},\n ) {\n const page = this.page(name);\n if (!page) {\n throw new Error(`Page ${name} not found`);\n }\n\n let url = page.path ?? \"\";\n let parent = page.parent;\n while (parent) {\n url = `${parent.path ?? \"\"}/${url}`;\n parent = parent.parent;\n }\n\n url = this.compile(url, options.params ?? {});\n\n if (options.query) {\n const query = new URLSearchParams(options.query);\n if (query.toString()) {\n url += `?${query.toString()}`;\n }\n }\n\n return url.replace(/\\/\\/+/g, \"/\") || \"/\";\n }\n\n public url(\n name: string,\n options: { params?: Record<string, string>; host?: string } = {},\n ): URL {\n return new URL(\n this.pathname(name, options),\n // use provided base or default to http://localhost\n options.host ?? `http://localhost`,\n );\n }\n\n public root(state: ReactRouterState): ReactNode {\n const root = createElement(\n AlephaContext.Provider,\n { value: this.alepha },\n createElement(NestedView, {}, state.layers[0]?.element),\n );\n\n if (this.env.REACT_STRICT_MODE) {\n return createElement(StrictMode, {}, root);\n }\n\n return root;\n }\n\n protected convertStringObjectToObject = (\n schema?: TSchema,\n value?: any,\n ): any => {\n if (t.schema.isObject(schema) && typeof value === \"object\") {\n for (const key in schema.properties) {\n if (\n t.schema.isObject(schema.properties[key]) &&\n typeof value[key] === \"string\"\n ) {\n try {\n value[key] = this.alepha.codec.decode(\n schema.properties[key],\n decodeURIComponent(value[key]),\n );\n } catch (e) {\n // ignore\n }\n }\n }\n }\n return value;\n };\n\n /**\n * Create a new RouterState based on a given route and request.\n * This method resolves the layers for the route, applying any query and params schemas defined in the route.\n * It also handles errors and redirects.\n */\n public async createLayers(\n route: PageRoute,\n state: ReactRouterState,\n previous: PreviousLayerData[] = [],\n ): Promise<CreateLayersResult> {\n let context: Record<string, any> = {}; // all props\n const stack: Array<RouterStackItem> = [{ route }]; // stack of routes\n\n let parent = route.parent;\n while (parent) {\n stack.unshift({ route: parent });\n parent = parent.parent;\n }\n\n let forceRefresh = false;\n\n for (let i = 0; i < stack.length; i++) {\n const it = stack[i];\n const route = it.route;\n const config: Record<string, any> = {};\n\n try {\n this.convertStringObjectToObject(route.schema?.query, state.query);\n config.query = route.schema?.query\n ? this.alepha.codec.decode(route.schema.query, state.query)\n : {};\n } catch (e) {\n it.error = e as Error;\n break;\n }\n\n try {\n config.params = route.schema?.params\n ? this.alepha.codec.decode(route.schema.params, state.params)\n : {};\n } catch (e) {\n it.error = e as Error;\n break;\n }\n\n // save config\n it.config = {\n ...config,\n };\n\n // check if previous layer is the same, reuse if possible\n if (previous?.[i] && !forceRefresh && previous[i].name === route.name) {\n const url = (str?: string) => (str ? str.replace(/\\/\\/+/g, \"/\") : \"/\");\n\n const prev = JSON.stringify({\n part: url(previous[i].part),\n params: previous[i].config?.params ?? {},\n });\n\n const curr = JSON.stringify({\n part: url(route.path),\n params: config.params ?? {},\n });\n\n if (prev === curr) {\n // part is the same, reuse previous layer\n it.props = previous[i].props;\n it.error = previous[i].error;\n it.cache = true;\n context = {\n ...context,\n ...it.props,\n };\n continue;\n }\n\n // part is different, force refresh of next layers\n forceRefresh = true;\n }\n\n // no resolve, render a basic view by default\n if (!route.resolve) {\n continue;\n }\n\n try {\n const args = Object.create(state);\n Object.assign(args, config, context);\n const props = (await route.resolve?.(args)) ?? {};\n\n // save props\n it.props = {\n ...props,\n };\n\n // add props to context\n context = {\n ...context,\n ...props,\n };\n } catch (e) {\n // check if we need to redirect\n if (e instanceof Redirection) {\n return {\n redirect: e.redirect,\n };\n }\n\n this.log.error(\"Page resolver has failed\", e);\n\n it.error = e as Error;\n break;\n }\n }\n\n let acc = \"\";\n for (let i = 0; i < stack.length; i++) {\n const it = stack[i];\n const props = it.props ?? {};\n\n const params = { ...it.config?.params };\n for (const key of Object.keys(params)) {\n params[key] = String(params[key]);\n }\n\n acc += \"/\";\n acc += it.route.path ? this.compile(it.route.path, params) : \"\";\n const path = acc.replace(/\\/+/, \"/\");\n const localErrorHandler = this.getErrorHandler(it.route);\n if (localErrorHandler) {\n const onErrorParent = state.onError;\n state.onError = (error, context) => {\n const result = localErrorHandler(error, context);\n // if nothing happen, call the parent\n if (result === undefined) {\n return onErrorParent(error, context);\n }\n return result;\n };\n }\n\n // normal use case\n if (!it.error) {\n try {\n const element = await this.createElement(it.route, {\n // default props attached to page\n ...(it.route.props ? it.route.props() : {}),\n // resolved props\n ...props,\n // context props (from previous layers)\n ...context,\n });\n\n state.layers.push({\n name: it.route.name,\n props,\n part: it.route.path,\n config: it.config,\n element: this.renderView(i + 1, path, element, it.route),\n index: i + 1,\n path,\n route: it.route,\n cache: it.cache,\n });\n } catch (e) {\n it.error = e as Error;\n }\n }\n\n // handler has thrown an error, render an error view\n if (it.error) {\n try {\n let element: ReactNode | Redirection | undefined =\n await state.onError(it.error, state);\n\n if (element === undefined) {\n throw it.error;\n }\n\n if (element instanceof Redirection) {\n return {\n redirect: element.redirect,\n };\n }\n\n if (element === null) {\n element = this.renderError(it.error);\n }\n\n state.layers.push({\n props,\n error: it.error,\n name: it.route.name,\n part: it.route.path,\n config: it.config,\n element: this.renderView(i + 1, path, element, it.route),\n index: i + 1,\n path,\n route: it.route,\n });\n break;\n } catch (e) {\n if (e instanceof Redirection) {\n return {\n redirect: e.redirect,\n };\n }\n throw e;\n }\n }\n }\n\n return { state };\n }\n\n protected getErrorHandler(route: PageRoute): ErrorHandler | undefined {\n if (route.errorHandler) return route.errorHandler;\n let parent = route.parent;\n while (parent) {\n if (parent.errorHandler) return parent.errorHandler;\n parent = parent.parent;\n }\n }\n\n protected async createElement(\n page: PageRoute,\n props: Record<string, any>,\n ): Promise<ReactNode> {\n if (page.lazy && page.component) {\n this.log.warn(\n `Page ${page.name} has both lazy and component options, lazy will be used`,\n );\n }\n\n if (page.lazy) {\n const component = await page.lazy(); // load component\n return createElement(component.default, props);\n }\n\n if (page.component) {\n return createElement(page.component, props);\n }\n\n return undefined;\n }\n\n public renderError(error: Error): ReactNode {\n return createElement(ErrorViewer, { error, alepha: this.alepha });\n }\n\n public renderEmptyView(): ReactNode {\n return createElement(NestedView, {});\n }\n\n public href(\n page: { options: { name?: string } },\n params: Record<string, any> = {},\n ): string {\n const found = this.pages.find((it) => it.name === page.options.name);\n if (!found) {\n throw new AlephaError(`Page ${page.options.name} not found`);\n }\n\n let url = found.path ?? \"\";\n let parent = found.parent;\n while (parent) {\n url = `${parent.path ?? \"\"}/${url}`;\n parent = parent.parent;\n }\n\n url = this.compile(url, params);\n\n return url.replace(/\\/\\/+/g, \"/\") || \"/\";\n }\n\n public compile(path: string, params: Record<string, string> = {}) {\n for (const [key, value] of Object.entries(params)) {\n path = path.replace(`:${key}`, value);\n }\n return path;\n }\n\n protected renderView(\n index: number,\n path: string,\n view: ReactNode | undefined,\n page: PageRoute,\n ): ReactNode {\n view ??= this.renderEmptyView();\n\n const element = page.client\n ? createElement(\n ClientOnly,\n typeof page.client === \"object\" ? page.client : {},\n view,\n )\n : view;\n\n return createElement(\n RouterLayerContext.Provider,\n {\n value: {\n index,\n path,\n onError: this.getErrorHandler(page) ?? ((error) => this.renderError(error)),\n },\n },\n element,\n );\n }\n\n protected readonly configure = $hook({\n on: \"configure\",\n handler: () => {\n let hasNotFoundHandler = false;\n const pages = this.alepha.primitives($page);\n\n const hasParent = (it: PagePrimitive) => {\n if (it.options.parent) {\n return true;\n }\n\n for (const page of pages) {\n const children = page.options.children\n ? Array.isArray(page.options.children)\n ? page.options.children\n : page.options.children()\n : [];\n if (children.includes(it)) {\n return true;\n }\n }\n };\n\n for (const page of pages) {\n if (page.options.path === \"/*\") {\n hasNotFoundHandler = true;\n }\n\n // skip children, we only want root pages\n if (hasParent(page)) {\n continue;\n }\n\n this.add(this.map(pages, page));\n }\n\n if (!hasNotFoundHandler && pages.length > 0) {\n // add a default 404 page if not already defined\n this.add({\n path: \"/*\",\n name: \"notFound\",\n cache: true,\n component: NotFoundPage,\n onServerResponse: ({ reply }) => {\n reply.status = 404;\n },\n });\n }\n },\n });\n\n protected map(\n pages: Array<PagePrimitive>,\n target: PagePrimitive,\n ): PageRouteEntry {\n const children = target.options.children\n ? Array.isArray(target.options.children)\n ? target.options.children\n : target.options.children()\n : [];\n\n const getChildrenFromParent = (it: PagePrimitive): PagePrimitive[] => {\n const children = [];\n for (const page of pages) {\n if (page.options.parent === it) {\n children.push(page);\n }\n }\n return children;\n };\n\n children.push(...getChildrenFromParent(target));\n\n return {\n ...target.options,\n name: target.name,\n parent: undefined,\n children: children.map((it) => this.map(pages, it)),\n } as PageRoute;\n }\n\n public add(entry: PageRouteEntry) {\n if (this.alepha.isReady()) {\n throw new AlephaError(\"Router is already initialized\");\n }\n\n entry.name ??= this.nextId();\n const page = entry as PageRoute;\n\n page.match = this.createMatch(page);\n this.pages.push(page);\n\n if (page.children) {\n for (const child of page.children) {\n (child as PageRoute).parent = page;\n this.add(child);\n }\n }\n }\n\n protected createMatch(page: PageRoute): string {\n let url = page.path ?? \"/\";\n let target = page.parent;\n while (target) {\n url = `${target.path ?? \"\"}/${url}`;\n target = target.parent;\n }\n\n let path = url.replace(/\\/\\/+/g, \"/\");\n\n if (path.endsWith(\"/\") && path !== \"/\") {\n // remove trailing slash\n path = path.slice(0, -1);\n }\n\n return path;\n }\n\n protected _next = 0;\n\n protected nextId(): string {\n this._next += 1;\n return `P${this._next}`;\n }\n}\n\nexport const isPageRoute = (it: any): it is PageRoute => {\n return (\n it &&\n typeof it === \"object\" &&\n typeof it.path === \"string\" &&\n typeof it.page === \"object\"\n );\n};\n\nexport interface PageRouteEntry\n extends Omit<PagePrimitiveOptions, \"children\" | \"parent\"> {\n children?: PageRouteEntry[];\n}\n\nexport interface ConcretePageRoute extends PageRoute {\n /**\n * When exported, static routes can be split into multiple pages with different params.\n * We replace 'name' by the new name for each static entry, and old 'name' becomes 'staticName'.\n */\n staticName?: string;\n\n params?: Record<string, string>;\n}\n\nexport interface PageRoute extends PageRouteEntry {\n type: \"page\";\n name: string;\n parent?: PageRoute;\n match: string;\n}\n\nexport interface Layer {\n config?: {\n query?: Record<string, any>;\n params?: Record<string, any>;\n // stack of resolved props\n context?: Record<string, any>;\n };\n\n name: string;\n props?: Record<string, any>;\n error?: Error;\n part?: string;\n element: ReactNode;\n index: number;\n path: string;\n route?: PageRoute;\n cache?: boolean;\n}\n\nexport type PreviousLayerData = Omit<Layer, \"element\" | \"index\" | \"path\">;\n\nexport interface AnchorProps {\n href: string;\n onClick: (ev?: any) => any;\n}\n\nexport interface ReactRouterState {\n /**\n * Stack of layers for the current page.\n */\n layers: Array<Layer>;\n\n /**\n * URL of the current page.\n */\n url: URL;\n\n /**\n * Error handler for the current page.\n */\n onError: ErrorHandler;\n\n /**\n * Params extracted from the URL for the current page.\n */\n params: Record<string, any>;\n\n /**\n * Query parameters extracted from the URL for the current page.\n */\n query: Record<string, string>;\n\n /**\n * Optional meta information associated with the current page.\n */\n meta: Record<string, any>;\n\n //\n name?: string;\n}\n\nexport interface RouterStackItem {\n route: PageRoute;\n config?: Record<string, any>;\n props?: Record<string, any>;\n error?: Error;\n cache?: boolean;\n}\n\nexport interface TransitionOptions {\n previous?: PreviousLayerData[];\n}\n\nexport interface CreateLayersResult {\n redirect?: string;\n state?: ReactRouterState;\n}\n","import { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport {\n $atom,\n $env,\n $hook,\n $inject,\n $use,\n Alepha,\n AlephaError,\n type Static,\n t,\n} from \"alepha\";\nimport { $logger } from \"alepha/logger\";\nimport {\n type ServerHandler,\n ServerProvider,\n ServerRouterProvider,\n ServerTimingProvider,\n} from \"alepha/server\";\nimport { ServerLinksProvider } from \"alepha/server/links\";\nimport { ServerStaticProvider } from \"alepha/server/static\";\nimport { renderToString } from \"react-dom/server\";\nimport {\n $page,\n type PagePrimitiveRenderOptions,\n type PagePrimitiveRenderResult,\n} from \"../primitives/$page.ts\";\nimport { Redirection } from \"../errors/Redirection.ts\";\nimport type { ReactHydrationState } from \"./ReactBrowserProvider.ts\";\nimport {\n type PageRoute,\n ReactPageProvider,\n type ReactRouterState,\n} from \"./ReactPageProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nconst envSchema = t.object({\n REACT_SSR_ENABLED: t.optional(t.boolean()),\n REACT_ROOT_ID: t.text({ default: \"root\" }), // TODO: move to ReactPageProvider.options?\n});\n\ndeclare module \"alepha\" {\n interface Env extends Partial<Static<typeof envSchema>> {}\n interface State {\n \"alepha.react.server.ssr\"?: boolean;\n \"alepha.react.server.template\"?: string;\n }\n}\n\n/**\n * React server provider configuration atom\n */\nexport const reactServerOptions = $atom({\n name: \"alepha.react.server.options\",\n schema: t.object({\n publicDir: t.string(),\n staticServer: t.object({\n disabled: t.boolean(),\n path: t.string({\n description: \"URL path where static files will be served.\",\n }),\n }),\n }),\n default: {\n publicDir: \"public\",\n staticServer: {\n disabled: false,\n path: \"/\",\n },\n },\n});\n\nexport type ReactServerProviderOptions = Static<\n typeof reactServerOptions.schema\n>;\n\ndeclare module \"alepha\" {\n interface State {\n [reactServerOptions.key]: ReactServerProviderOptions;\n }\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport class ReactServerProvider {\n protected readonly log = $logger();\n protected readonly alepha = $inject(Alepha);\n protected readonly env = $env(envSchema);\n protected readonly pageApi = $inject(ReactPageProvider);\n protected readonly serverProvider = $inject(ServerProvider);\n protected readonly serverStaticProvider = $inject(ServerStaticProvider);\n protected readonly serverRouterProvider = $inject(ServerRouterProvider);\n protected readonly serverTimingProvider = $inject(ServerTimingProvider);\n\n public readonly ROOT_DIV_REGEX = new RegExp(\n `<div([^>]*)\\\\s+id=[\"']${this.env.REACT_ROOT_ID}[\"']([^>]*)>(.*?)<\\\\/div>`,\n \"is\",\n );\n protected preprocessedTemplate: PreprocessedTemplate | null = null;\n\n protected readonly options = $use(reactServerOptions);\n\n /**\n * Configure the React server provider.\n */\n public readonly onConfigure = $hook({\n on: \"configure\",\n handler: async () => {\n const pages = this.alepha.primitives($page);\n\n const ssrEnabled =\n pages.length > 0 && this.env.REACT_SSR_ENABLED !== false;\n\n this.alepha.store.set(\"alepha.react.server.ssr\", ssrEnabled);\n\n // development mode\n if (this.alepha.isViteDev()) {\n await this.configureVite(ssrEnabled);\n return;\n }\n\n // production mode\n let root = \"\";\n\n // non-serverless mode only -> serve static files\n if (!this.alepha.isServerless()) {\n root = this.getPublicDirectory();\n if (!root) {\n this.log.warn(\n \"Missing static files, static file server will be disabled\",\n );\n } else {\n this.log.debug(`Using static files from: ${root}`);\n await this.configureStaticServer(root);\n }\n }\n\n if (ssrEnabled) {\n await this.registerPages(async () => this.template);\n this.log.info(\"SSR OK\");\n return;\n }\n\n // no SSR enabled, serve index.html for all unmatched routes\n this.log.info(\"SSR is disabled, use History API fallback\");\n this.serverRouterProvider.createRoute({\n path: \"*\",\n handler: async ({ url, reply }) => {\n if (url.pathname.includes(\".\")) {\n // If the request is for a file (e.g., /style.css), do not fallback\n reply.headers[\"content-type\"] = \"text/plain\";\n reply.body = \"Not Found\";\n reply.status = 404;\n return;\n }\n\n reply.headers[\"content-type\"] = \"text/html\";\n\n // serve index.html for all unmatched routes\n return this.template;\n },\n });\n },\n });\n\n public get template() {\n return (\n this.alepha.store.get(\"alepha.react.server.template\") ??\n \"<!DOCTYPE html><html lang='en'><head></head><body></body></html>\"\n );\n }\n\n protected async registerPages(templateLoader: TemplateLoader) {\n // Preprocess template once\n const template = await templateLoader();\n if (template) {\n this.preprocessedTemplate = this.preprocessTemplate(template);\n }\n\n for (const page of this.pageApi.getPages()) {\n if (page.component || page.lazy) {\n this.log.debug(`+ ${page.match} -> ${page.name}`);\n\n this.serverRouterProvider.createRoute({\n ...page,\n schema: undefined, // schema is handled by the page primitive provider for now (shared by browser and server)\n method: \"GET\",\n path: page.match,\n handler: this.createHandler(page, templateLoader),\n });\n }\n }\n }\n\n /**\n * Get the public directory path where static files are located.\n */\n protected getPublicDirectory(): string {\n const maybe = [\n join(process.cwd(), `dist/${this.options.publicDir}`),\n join(process.cwd(), this.options.publicDir),\n ];\n\n for (const it of maybe) {\n if (existsSync(it)) {\n return it;\n }\n }\n\n return \"\";\n }\n\n /**\n * Configure the static file server to serve files from the given root directory.\n */\n protected async configureStaticServer(root: string) {\n await this.serverStaticProvider.createStaticServer({\n root,\n cacheControl: {\n maxAge: 3600,\n immutable: true,\n },\n ...this.options.staticServer,\n });\n }\n\n /**\n * Configure Vite for SSR.\n */\n protected async configureVite(ssrEnabled: boolean) {\n if (!ssrEnabled) {\n // do nothing, vite will handle everything for us\n return;\n }\n\n this.log.info(\"SSR (dev) OK\");\n\n const url = `http://${process.env.SERVER_HOST}:${process.env.SERVER_PORT}`;\n\n await this.registerPages(() =>\n fetch(`${url}/index.html`)\n .then((it) => it.text())\n .catch(() => undefined),\n );\n }\n\n /**\n * For testing purposes, creates a render function that can be used.\n */\n public async render(\n name: string,\n options: PagePrimitiveRenderOptions = {},\n ): Promise<PagePrimitiveRenderResult> {\n const page = this.pageApi.page(name);\n const url = new URL(this.pageApi.url(name, options));\n const entry: Partial<ReactRouterState> = {\n url,\n params: options.params ?? {},\n query: options.query ?? {},\n onError: () => null,\n layers: [],\n meta: {},\n };\n const state = entry as ReactRouterState;\n\n this.log.trace(\"Rendering\", {\n url,\n });\n\n await this.alepha.events.emit(\"react:server:render:begin\", {\n state,\n });\n\n const { redirect } = await this.pageApi.createLayers(\n page,\n state as ReactRouterState,\n );\n\n if (redirect) {\n return { state, html: \"\", redirect };\n }\n\n if (!options.html) {\n this.alepha.store.set(\"alepha.react.router.state\", state);\n\n return {\n state,\n html: renderToString(this.pageApi.root(state)),\n };\n }\n\n const template = this.template ?? \"\";\n const html = this.renderToHtml(template, state, options.hydration);\n\n if (html instanceof Redirection) {\n return { state, html: \"\", redirect };\n }\n\n const result = {\n state,\n html,\n };\n\n await this.alepha.events.emit(\"react:server:render:end\", result);\n\n return result;\n }\n\n protected createHandler(\n route: PageRoute,\n templateLoader: TemplateLoader,\n ): ServerHandler {\n return async (serverRequest) => {\n const { url, reply, query, params } = serverRequest;\n const template = await templateLoader();\n if (!template) {\n throw new AlephaError(\"Missing template for SSR rendering\");\n }\n\n this.log.trace(\"Rendering page\", {\n name: route.name,\n });\n\n const entry: Partial<ReactRouterState> = {\n url,\n params,\n query,\n onError: () => null,\n layers: [],\n };\n\n const state = entry as ReactRouterState;\n\n state.name = route.name;\n\n if (this.alepha.has(ServerLinksProvider)) {\n this.alepha.store.set(\n \"alepha.server.request.apiLinks\",\n await this.alepha.inject(ServerLinksProvider).getUserApiLinks({\n user: (serverRequest as any).user, // TODO: fix type\n authorization: serverRequest.headers.authorization,\n }),\n );\n }\n\n let target: PageRoute | undefined = route; // TODO: move to PagePrimitiveProvider\n while (target) {\n if (route.can && !route.can()) {\n this.log.warn(\n `Access to page '${route.name}' is forbidden by can() check`,\n )\n // if the page is not accessible, return 403\n reply.status = 403;\n reply.headers[\"content-type\"] = \"text/plain\";\n return \"Forbidden\";\n }\n target = target.parent;\n }\n\n // TODO: SSR strategies\n // - only when googlebot\n // - only child pages\n // if (page.client) {\n // \t// if the page is a client-only page, return 404\n // \treply.status = 200;\n // \treply.headers[\"content-type\"] = \"text/html\";\n // \treply.body = template;\n // \treturn;\n // }\n\n await this.alepha.events.emit(\"react:server:render:begin\", {\n request: serverRequest,\n state,\n });\n\n this.serverTimingProvider.beginTiming(\"createLayers\");\n\n const { redirect } = await this.pageApi.createLayers(route, state);\n\n this.serverTimingProvider.endTiming(\"createLayers\");\n\n if (redirect) {\n this.log.debug(\"Resolver resulted in redirection\", {\n redirect,\n });\n return reply.redirect(redirect);\n }\n\n reply.headers[\"content-type\"] = \"text/html\";\n\n // by default, disable caching for SSR responses\n // some plugins may override this\n reply.headers[\"cache-control\"] =\n \"no-store, no-cache, must-revalidate, proxy-revalidate\";\n reply.headers.pragma = \"no-cache\";\n reply.headers.expires = \"0\";\n\n const html = this.renderToHtml(template, state);\n if (html instanceof Redirection) {\n reply.redirect(\n typeof html.redirect === \"string\"\n ? html.redirect\n : this.pageApi.href(html.redirect),\n );\n this.log.debug(\"Rendering resulted in redirection\", {\n redirect: html.redirect,\n });\n return;\n }\n\n this.log.trace(\"Page rendered to HTML successfully\");\n\n const event = {\n request: serverRequest,\n state,\n html,\n };\n\n await this.alepha.events.emit(\"react:server:render:end\", event);\n\n route.onServerResponse?.(serverRequest);\n\n this.log.trace(\"Page rendered\", {\n name: route.name,\n });\n\n return event.html;\n };\n }\n\n public renderToHtml(\n template: string,\n state: ReactRouterState,\n hydration = true,\n ): string | Redirection {\n const element = this.pageApi.root(state);\n\n // attach react router state to the http request context\n this.alepha.store.set(\"alepha.react.router.state\", state);\n\n this.serverTimingProvider.beginTiming(\"renderToString\");\n let app = \"\";\n try {\n app = renderToString(element);\n } catch (error) {\n this.log.error(\n \"renderToString has failed, fallback to error handler\",\n error,\n );\n const element = state.onError(error as Error, state);\n if (element instanceof Redirection) {\n // if the error is a redirection, return the redirection URL\n return element;\n }\n\n app = renderToString(element);\n this.log.debug(\"Error handled successfully with fallback\");\n }\n this.serverTimingProvider.endTiming(\"renderToString\");\n\n const response = {\n html: template,\n };\n\n if (hydration) {\n const { request, context, ...store } =\n this.alepha.context.als?.getStore() ?? {}; /// TODO: als must be protected, find a way to iterate on alepha.state\n\n const hydrationData: ReactHydrationState = {\n ...store,\n // map react.router.state to the hydration state\n \"alepha.react.router.state\": undefined,\n layers: state.layers.map((it) => ({\n ...it,\n error: it.error\n ? {\n ...it.error,\n name: it.error.name,\n message: it.error.message,\n stack: !this.alepha.isProduction() ? it.error.stack : undefined,\n }\n : undefined,\n index: undefined,\n path: undefined,\n element: undefined,\n route: undefined,\n })),\n };\n\n // create hydration data\n const script = `<script>window.__ssr=${JSON.stringify(hydrationData)}</script>`;\n\n // inject app into template\n this.fillTemplate(response, app, script);\n }\n\n return response.html;\n }\n\n protected preprocessTemplate(template: string): PreprocessedTemplate {\n // Find the body close tag for script injection\n const bodyCloseMatch = template.match(/<\\/body>/i);\n const bodyCloseIndex = bodyCloseMatch?.index ?? template.length;\n\n const beforeScript = template.substring(0, bodyCloseIndex);\n const afterScript = template.substring(bodyCloseIndex);\n\n // Check if there's an existing root div\n const rootDivMatch = beforeScript.match(this.ROOT_DIV_REGEX);\n\n if (rootDivMatch) {\n // Split around the existing root div content\n const beforeDiv = beforeScript.substring(0, rootDivMatch.index!);\n const afterDivStart = rootDivMatch.index! + rootDivMatch[0].length;\n const afterDiv = beforeScript.substring(afterDivStart);\n\n const beforeApp = `${beforeDiv}<div${rootDivMatch[1]} id=\"${this.env.REACT_ROOT_ID}\"${rootDivMatch[2]}>`;\n const afterApp = `</div>${afterDiv}`;\n\n return { beforeApp, afterApp, beforeScript: \"\", afterScript };\n }\n\n // No existing root div, find body tag to inject new div\n const bodyMatch = beforeScript.match(/<body([^>]*)>/i);\n if (bodyMatch) {\n const beforeBody = beforeScript.substring(\n 0,\n bodyMatch.index! + bodyMatch[0].length,\n );\n const afterBody = beforeScript.substring(\n bodyMatch.index! + bodyMatch[0].length,\n );\n\n const beforeApp = `${beforeBody}<div id=\"${this.env.REACT_ROOT_ID}\">`;\n const afterApp = `</div>${afterBody}`;\n\n return { beforeApp, afterApp, beforeScript: \"\", afterScript };\n }\n\n // Fallback: no body tag found, just wrap everything\n return {\n beforeApp: `<div id=\"${this.env.REACT_ROOT_ID}\">`,\n afterApp: `</div>`,\n beforeScript,\n afterScript,\n };\n }\n\n protected fillTemplate(\n response: { html: string },\n app: string,\n script: string,\n ) {\n if (!this.preprocessedTemplate) {\n // Fallback to old logic if preprocessing failed\n this.preprocessedTemplate = this.preprocessTemplate(response.html);\n }\n\n // Pure concatenation - no regex replacements needed\n response.html =\n this.preprocessedTemplate.beforeApp +\n app +\n this.preprocessedTemplate.afterApp +\n script +\n this.preprocessedTemplate.afterScript;\n }\n}\n\ntype TemplateLoader = () => Promise<string | undefined>;\n\ninterface PreprocessedTemplate {\n beforeApp: string;\n afterApp: string;\n beforeScript: string;\n afterScript: string;\n}\n","import { $inject, AlephaError } from \"alepha\";\nimport { ServerProvider } from \"alepha/server\";\nimport type {\n PagePrimitiveRenderOptions,\n PagePrimitiveRenderResult,\n} from \"../primitives/$page.ts\";\nimport { ReactServerProvider } from \"../providers/ReactServerProvider.ts\";\nimport { ReactPageService } from \"./ReactPageService.ts\";\n\nexport class ReactPageServerService extends ReactPageService {\n protected readonly reactServerProvider = $inject(ReactServerProvider);\n protected readonly serverProvider = $inject(ServerProvider);\n\n public async render(\n name: string,\n options: PagePrimitiveRenderOptions = {},\n ): Promise<PagePrimitiveRenderResult> {\n return this.reactServerProvider.render(name, options);\n }\n\n public async fetch(\n pathname: string,\n options: PagePrimitiveRenderOptions = {},\n ): Promise<{\n html: string;\n response: Response;\n }> {\n const response = await fetch(`${this.serverProvider.hostname}/${pathname}`);\n\n const html = await response.text();\n if (options?.html) {\n return { html, response };\n }\n\n // take only text inside the root div\n const match = html.match(this.reactServerProvider.ROOT_DIV_REGEX);\n if (match) {\n return { html: match[3], response };\n }\n\n throw new AlephaError(\"Invalid HTML response\");\n }\n}\n","import { $hook, $inject, Alepha } from \"alepha\";\nimport { $logger } from \"alepha/logger\";\nimport { type Route, RouterProvider } from \"alepha/router\";\nimport { createElement, type ReactNode } from \"react\";\nimport NotFoundPage from \"../components/NotFound.tsx\";\nimport {\n isPageRoute,\n type PageRoute,\n type PageRouteEntry,\n type PreviousLayerData,\n ReactPageProvider,\n type ReactRouterState,\n} from \"./ReactPageProvider.ts\";\n\nexport interface BrowserRoute extends Route {\n page: PageRoute;\n}\n\nexport class ReactBrowserRouterProvider extends RouterProvider<BrowserRoute> {\n protected readonly log = $logger();\n protected readonly alepha = $inject(Alepha);\n protected readonly pageApi = $inject(ReactPageProvider);\n\n public add(entry: PageRouteEntry) {\n this.pageApi.add(entry);\n }\n\n protected readonly configure = $hook({\n on: \"configure\",\n handler: async () => {\n for (const page of this.pageApi.getPages()) {\n // mount only if a view is provided\n if (page.component || page.lazy) {\n this.push({\n path: page.match,\n page,\n });\n }\n }\n },\n });\n\n public async transition(\n url: URL,\n previous: PreviousLayerData[] = [],\n meta = {},\n ): Promise<string | void> {\n const { pathname, search } = url;\n\n const entry: Partial<ReactRouterState> = {\n url,\n query: {},\n params: {},\n layers: [],\n onError: () => null,\n meta,\n };\n\n const state = entry as ReactRouterState;\n\n // Emit both action and transition events\n await this.alepha.events.emit(\"react:action:begin\", {\n type: \"transition\",\n });\n await this.alepha.events.emit(\"react:transition:begin\", {\n previous: this.alepha.store.get(\"alepha.react.router.state\")!,\n state,\n });\n\n try {\n const { route, params } = this.match(pathname);\n\n const query: Record<string, string> = {};\n if (search) {\n for (const [key, value] of new URLSearchParams(search).entries()) {\n query[key] = String(value);\n }\n }\n\n state.name = route?.page.name;\n state.query = query;\n state.params = params ?? {};\n\n if (isPageRoute(route)) {\n const { redirect } = await this.pageApi.createLayers(\n route.page,\n state,\n previous,\n );\n if (redirect) {\n return redirect;\n }\n }\n\n if (state.layers.length === 0) {\n state.layers.push({\n name: \"not-found\",\n element: createElement(NotFoundPage),\n index: 0,\n path: \"/\",\n });\n }\n\n await this.alepha.events.emit(\"react:action:success\", {\n type: \"transition\",\n });\n await this.alepha.events.emit(\"react:transition:success\", { state });\n } catch (e) {\n this.log.error(\"Transition has failed\", e);\n state.layers = [\n {\n name: \"error\",\n element: this.pageApi.renderError(e as Error),\n index: 0,\n path: \"/\",\n },\n ];\n\n await this.alepha.events.emit(\"react:action:error\", {\n type: \"transition\",\n error: e as Error,\n });\n await this.alepha.events.emit(\"react:transition:error\", {\n error: e as Error,\n state,\n });\n }\n\n // [feature]: local hook for leaving a page\n if (previous) {\n for (let i = 0; i < previous.length; i++) {\n const layer = previous[i];\n if (state.layers[i]?.name !== layer.name) {\n this.pageApi.page(layer.name)?.onLeave?.();\n }\n }\n }\n\n this.alepha.store.set(\"alepha.react.router.state\", state);\n\n await this.alepha.events.emit(\"react:action:end\", {\n type: \"transition\",\n });\n await this.alepha.events.emit(\"react:transition:end\", {\n state,\n });\n }\n\n public root(state: ReactRouterState): ReactNode {\n return this.pageApi.root(state);\n }\n}\n","import {\n $atom,\n $env,\n $hook,\n $inject,\n $use,\n Alepha,\n type State,\n type Static,\n t,\n} from \"alepha\";\nimport { DateTimeProvider } from \"alepha/datetime\";\nimport { $logger } from \"alepha/logger\";\nimport { LinkProvider } from \"alepha/server/links\";\nimport { ReactBrowserRouterProvider } from \"./ReactBrowserRouterProvider.ts\";\nimport type {\n PreviousLayerData,\n ReactRouterState,\n TransitionOptions,\n} from \"./ReactPageProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nconst envSchema = t.object({\n REACT_ROOT_ID: t.text({ default: \"root\" }),\n});\n\ndeclare module \"alepha\" {\n interface Env extends Partial<Static<typeof envSchema>> {}\n}\n\n/**\n * React browser renderer configuration atom\n */\nexport const reactBrowserOptions = $atom({\n name: \"alepha.react.browser.options\",\n schema: t.object({\n scrollRestoration: t.enum([\"top\", \"manual\"]),\n }),\n default: {\n scrollRestoration: \"top\" as const,\n },\n});\n\nexport type ReactBrowserRendererOptions = Static<\n typeof reactBrowserOptions.schema\n>;\n\ndeclare module \"alepha\" {\n interface State {\n [reactBrowserOptions.key]: ReactBrowserRendererOptions;\n }\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport class ReactBrowserProvider {\n protected readonly env = $env(envSchema);\n protected readonly log = $logger();\n protected readonly client = $inject(LinkProvider);\n protected readonly alepha = $inject(Alepha);\n protected readonly router = $inject(ReactBrowserRouterProvider);\n protected readonly dateTimeProvider = $inject(DateTimeProvider);\n\n protected readonly options = $use(reactBrowserOptions);\n\n protected getRootElement() {\n const root = this.document.getElementById(this.env.REACT_ROOT_ID);\n if (root) {\n return root;\n }\n\n const div = this.document.createElement(\"div\");\n div.id = this.env.REACT_ROOT_ID;\n\n this.document.body.prepend(div);\n\n return div;\n }\n\n public transitioning?: {\n to: string;\n from?: string;\n };\n\n public get state(): ReactRouterState {\n return this.alepha.store.get(\"alepha.react.router.state\")!;\n }\n\n /**\n * Accessor for Document DOM API.\n */\n public get document() {\n return window.document;\n }\n\n /**\n * Accessor for History DOM API.\n */\n public get history() {\n return window.history;\n }\n\n /**\n * Accessor for Location DOM API.\n */\n public get location() {\n return window.location;\n }\n\n public get base() {\n const base = import.meta.env?.BASE_URL;\n if (!base || base === \"/\") {\n return \"\";\n }\n\n return base;\n }\n\n public get url(): string {\n const url = this.location.pathname + this.location.search;\n if (this.base) {\n return url.replace(this.base, \"\");\n }\n return url;\n }\n\n public pushState(path: string, replace?: boolean) {\n const url = this.base + path;\n\n if (replace) {\n this.history.replaceState({}, \"\", url);\n } else {\n this.history.pushState({}, \"\", url);\n }\n }\n\n public async invalidate(props?: Record<string, any>) {\n const previous: PreviousLayerData[] = [];\n\n this.log.trace(\"Invalidating layers\");\n\n if (props) {\n const [key] = Object.keys(props);\n const value = props[key];\n\n for (const layer of this.state.layers) {\n if (layer.props?.[key]) {\n previous.push({\n ...layer,\n props: {\n ...layer.props,\n [key]: value,\n },\n });\n break;\n }\n previous.push(layer);\n }\n }\n\n await this.render({ previous });\n }\n\n public async go(url: string, options: RouterGoOptions = {}): Promise<void> {\n this.log.trace(`Going to ${url}`, {\n url,\n options,\n });\n\n await this.render({\n url,\n previous: options.force ? [] : this.state.layers,\n meta: options.meta,\n });\n\n // when redirecting in browser\n if (this.state.url.pathname + this.state.url.search !== url) {\n this.pushState(this.state.url.pathname + this.state.url.search);\n return;\n }\n\n this.pushState(url, options.replace);\n }\n\n protected async render(options: RouterRenderOptions = {}): Promise<void> {\n const previous = options.previous ?? this.state.layers;\n const url = options.url ?? this.url;\n const start = this.dateTimeProvider.now();\n\n this.transitioning = {\n to: url,\n from: this.state?.url.pathname,\n };\n\n this.log.debug(\"Transitioning...\", {\n to: url,\n });\n\n const redirect = await this.router.transition(\n new URL(`http://localhost${url}`),\n previous,\n options.meta,\n );\n\n if (redirect) {\n this.log.info(\"Redirecting to\", {\n redirect,\n });\n\n // if redirect is an absolute URL, use window.location.href (full page reload)\n if (redirect.startsWith(\"http\")) {\n window.location.href = redirect;\n } else {\n // if redirect is a relative URL, use render() (single page app)\n return await this.render({ url: redirect });\n }\n }\n\n const ms = this.dateTimeProvider.now().diff(start);\n this.log.info(`Transition OK [${ms}ms]`, this.transitioning);\n\n this.transitioning = undefined;\n }\n\n /**\n * Get embedded layers from the server.\n */\n protected getHydrationState(): ReactHydrationState | undefined {\n try {\n if (\"__ssr\" in window && typeof window.__ssr === \"object\") {\n return window.__ssr as ReactHydrationState;\n }\n } catch (error) {\n console.error(error);\n }\n }\n\n // -------------------------------------------------------------------------------------------------------------------\n\n protected readonly onTransitionEnd = $hook({\n on: \"react:transition:end\",\n handler: () => {\n if (\n this.options.scrollRestoration === \"top\" &&\n typeof window !== \"undefined\" &&\n !this.alepha.isTest()\n ) {\n this.log.trace(\"Restoring scroll position to top\");\n window.scrollTo(0, 0);\n }\n },\n });\n\n public readonly ready = $hook({\n on: \"ready\",\n handler: async () => {\n const hydration = this.getHydrationState();\n const previous = hydration?.layers ?? [];\n\n if (hydration) {\n // low budget, but works for now\n for (const [key, value] of Object.entries(hydration)) {\n if (key !== \"layers\") {\n this.alepha.store.set(key as keyof State, value);\n }\n }\n }\n\n await this.render({ previous });\n\n const element = this.router.root(this.state);\n\n await this.alepha.events.emit(\"react:browser:render\", {\n element,\n root: this.getRootElement(),\n hydration,\n state: this.state,\n });\n\n window.addEventListener(\"popstate\", () => {\n // when you update silently queryParams or hash, skip rendering\n // if you want to force a rendering, use #go()\n if (this.base + this.state.url.pathname === this.location.pathname) {\n return;\n }\n\n this.log.debug(\"Popstate event triggered - rendering new state\", {\n url: this.location.pathname + this.location.search,\n });\n\n this.render();\n });\n },\n });\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface RouterGoOptions {\n replace?: boolean;\n match?: TransitionOptions;\n params?: Record<string, string>;\n query?: Record<string, string>;\n meta?: Record<string, any>;\n\n /**\n * Recreate the whole page, ignoring the current state.\n */\n force?: boolean;\n}\n\nexport type ReactHydrationState = {\n layers?: Array<PreviousLayerData>;\n} & {\n [key: string]: any;\n};\n\nexport interface RouterRenderOptions {\n url?: string;\n previous?: PreviousLayerData[];\n meta?: Record<string, any>;\n}\n","import { $inject, Alepha } from \"alepha\";\nimport type { PagePrimitive } from \"../primitives/$page.ts\";\nimport {\n ReactBrowserProvider,\n type RouterGoOptions,\n} from \"../providers/ReactBrowserProvider.ts\";\nimport {\n type AnchorProps,\n ReactPageProvider,\n type ReactRouterState,\n} from \"../providers/ReactPageProvider.ts\";\n\nexport class ReactRouter<T extends object> {\n protected readonly alepha = $inject(Alepha);\n protected readonly pageApi = $inject(ReactPageProvider);\n\n public get state(): ReactRouterState {\n return this.alepha.store.get(\"alepha.react.router.state\")!;\n }\n\n public get pages() {\n return this.pageApi.getPages();\n }\n\n public get concretePages() {\n return this.pageApi.getConcretePages();\n }\n\n public get browser(): ReactBrowserProvider | undefined {\n if (this.alepha.isBrowser()) {\n return this.alepha.inject(ReactBrowserProvider);\n }\n // server-side\n return undefined;\n }\n\n public isActive(\n href: string,\n options: {\n startWith?: boolean;\n } = {},\n ): boolean {\n const current = this.state.url.pathname;\n let isActive =\n current === href || current === `${href}/` || `${current}/` === href;\n\n if (options.startWith && !isActive) {\n isActive = current.startsWith(href);\n }\n\n return isActive;\n }\n\n public node(\n name: keyof VirtualRouter<T> | string,\n config: {\n params?: Record<string, any>;\n query?: Record<string, any>;\n } = {},\n ) {\n const page = this.pageApi.page(name as string);\n return {\n ...page,\n label: page.label ?? page.name,\n href: this.path(name, config),\n children: undefined,\n }\n }\n\n public path(\n name: keyof VirtualRouter<T> | string,\n config: {\n params?: Record<string, any>;\n query?: Record<string, any>;\n } = {},\n ): string {\n return this.pageApi.pathname(name as string, {\n params: {\n ...this.state?.params,\n ...config.params,\n },\n query: config.query,\n });\n }\n\n /**\n * Reload the current page.\n * This is equivalent to calling `go()` with the current pathname and search.\n */\n public async reload() {\n if (!this.browser) {\n return;\n }\n\n await this.go(this.location.pathname + this.location.search, {\n replace: true,\n force: true,\n });\n }\n\n public getURL(): URL {\n if (!this.browser) {\n return this.state.url;\n }\n\n return new URL(this.location.href);\n }\n\n public get location(): Location {\n if (!this.browser) {\n throw new Error(\"Browser is required\");\n }\n\n return this.browser.location;\n }\n\n public get current(): ReactRouterState {\n return this.state;\n }\n\n public get pathname(): string {\n return this.state.url.pathname;\n }\n\n public get query(): Record<string, string> {\n const query: Record<string, string> = {};\n\n for (const [key, value] of new URLSearchParams(\n this.state.url.search,\n ).entries()) {\n query[key] = String(value);\n }\n\n return query;\n }\n\n public async back() {\n this.browser?.history.back();\n }\n\n public async forward() {\n this.browser?.history.forward();\n }\n\n public async invalidate(props?: Record<string, any>) {\n await this.browser?.invalidate(props);\n }\n\n public async go(path: string, options?: RouterGoOptions): Promise<void>;\n public async go(\n path: keyof VirtualRouter<T>,\n options?: RouterGoOptions,\n ): Promise<void>;\n public async go(\n path: string | keyof VirtualRouter<T>,\n options?: RouterGoOptions,\n ): Promise<void> {\n for (const page of this.pages) {\n if (page.name === path) {\n await this.browser?.go(\n this.path(path as keyof VirtualRouter<T>, options),\n options,\n );\n return;\n }\n }\n\n await this.browser?.go(path as string, options);\n }\n\n public anchor(path: string, options?: RouterGoOptions): AnchorProps;\n public anchor(\n path: keyof VirtualRouter<T>,\n options?: RouterGoOptions,\n ): AnchorProps;\n public anchor(\n path: string | keyof VirtualRouter<T>,\n options: RouterGoOptions = {},\n ): AnchorProps {\n let href = path as string;\n\n for (const page of this.pages) {\n if (page.name === path) {\n href = this.path(path as keyof VirtualRouter<T>, options);\n break;\n }\n }\n\n return {\n href: this.base(href),\n onClick: (ev: any) => {\n ev.stopPropagation();\n ev.preventDefault();\n\n this.go(href, options).catch(console.error);\n },\n };\n }\n\n public base(path: string): string {\n const base = import.meta.env?.BASE_URL;\n if (!base || base === \"/\") {\n return path;\n }\n\n return base + path;\n }\n\n /**\n * Set query params.\n *\n * @param record\n * @param options\n */\n public setQueryParams(\n record:\n | Record<string, any>\n | ((queryParams: Record<string, any>) => Record<string, any>),\n options: {\n /**\n * If true, this will add a new entry to the history stack.\n */\n push?: boolean;\n } = {},\n ) {\n const func = typeof record === \"function\" ? record : () => record;\n const search = new URLSearchParams(func(this.query)).toString();\n const state = search ? `${this.pathname}?${search}` : this.pathname;\n\n if (options.push) {\n window.history.pushState({}, \"\", state);\n } else {\n window.history.replaceState({}, \"\", state);\n }\n }\n}\n\nexport type VirtualRouter<T> = {\n [K in keyof T as T[K] extends PagePrimitive ? K : never]: T[K];\n};\n","import type { Service } from \"alepha\";\nimport { useMemo } from \"react\";\nimport { useAlepha } from \"./useAlepha.ts\";\n\n/**\n * Hook to inject a service instance.\n * It's a wrapper of `useAlepha().inject(service)` with a memoization.\n */\nexport const useInject = <T extends object>(service: Service<T>): T => {\n const alepha = useAlepha();\n return useMemo(() => alepha.inject(service), []);\n};\n","import {\n DateTimeProvider,\n type DurationLike,\n type Interval,\n type Timeout,\n} from \"alepha/datetime\";\nimport {\n type DependencyList,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport { useAlepha } from \"./useAlepha.ts\";\nimport { useInject } from \"./useInject.ts\";\nimport type { Async } from \"alepha\";\n\n/**\n * Hook for handling async actions with automatic error handling and event emission.\n *\n * By default, prevents concurrent executions - if an action is running and you call it again,\n * the second call will be ignored. Use `debounce` option to delay execution instead.\n *\n * Emits lifecycle events:\n * - `react:action:begin` - When action starts\n * - `react:action:success` - When action completes successfully\n * - `react:action:error` - When action throws an error\n * - `react:action:end` - Always emitted at the end\n *\n * @example Basic usage\n * ```tsx\n * const action = useAction({\n * handler: async (data) => {\n * await api.save(data);\n * }\n * }, []);\n *\n * <button onClick={() => action.run(data)} disabled={action.loading}>\n * Save\n * </button>\n * ```\n *\n * @example With debounce (search input)\n * ```tsx\n * const search = useAction({\n * handler: async (query: string) => {\n * await api.search(query);\n * },\n * debounce: 300 // Wait 300ms after last call\n * }, []);\n *\n * <input onChange={(e) => search.run(e.target.value)} />\n * ```\n *\n * @example Run on component mount\n * ```tsx\n * const fetchData = useAction({\n * handler: async () => {\n * const data = await api.getData();\n * return data;\n * },\n * runOnInit: true // Runs once when component mounts\n * }, []);\n * ```\n *\n * @example Run periodically (polling)\n * ```tsx\n * const pollStatus = useAction({\n * handler: async () => {\n * const status = await api.getStatus();\n * return status;\n * },\n * runEvery: 5000 // Run every 5 seconds\n * }, []);\n *\n * // Or with duration tuple\n * const pollStatus = useAction({\n * handler: async () => {\n * const status = await api.getStatus();\n * return status;\n * },\n * runEvery: [30, 'seconds'] // Run every 30 seconds\n * }, []);\n * ```\n *\n * @example With AbortController\n * ```tsx\n * const fetch = useAction({\n * handler: async (url, { signal }) => {\n * const response = await fetch(url, { signal });\n * return response.json();\n * }\n * }, []);\n * // Automatically cancelled on unmount or when new request starts\n * ```\n *\n * @example With error handling\n * ```tsx\n * const deleteAction = useAction({\n * handler: async (id: string) => {\n * await api.delete(id);\n * },\n * onError: (error) => {\n * if (error.code === 'NOT_FOUND') {\n * // Custom error handling\n * }\n * }\n * }, []);\n *\n * {deleteAction.error && <div>Error: {deleteAction.error.message}</div>}\n * ```\n *\n * @example Global error handling\n * ```tsx\n * // In your root app setup\n * alepha.events.on(\"react:action:error\", ({ error }) => {\n * toast.danger(error.message);\n * Sentry.captureException(error);\n * });\n * ```\n */\nexport function useAction<Args extends any[], Result = void>(\n options: UseActionOptions<Args, Result>,\n deps: DependencyList,\n): UseActionReturn<Args, Result> {\n const alepha = useAlepha();\n const dateTimeProvider = useInject(DateTimeProvider);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n const isExecutingRef = useRef(false);\n const debounceTimerRef = useRef<Timeout | undefined>(undefined);\n const abortControllerRef = useRef<AbortController | undefined>(undefined);\n const isMountedRef = useRef(true);\n const intervalRef = useRef<Interval | undefined>(undefined);\n\n // Cleanup on unmount\n useEffect(() => {\n return () => {\n isMountedRef.current = false;\n\n // clear debounce timer\n if (debounceTimerRef.current) {\n dateTimeProvider.clearTimeout(debounceTimerRef.current);\n debounceTimerRef.current = undefined;\n }\n\n // clear interval\n if (intervalRef.current) {\n dateTimeProvider.clearInterval(intervalRef.current);\n intervalRef.current = undefined;\n }\n\n // abort in-flight request\n if (abortControllerRef.current) {\n abortControllerRef.current.abort();\n abortControllerRef.current = undefined;\n }\n };\n }, []);\n\n const executeAction = useCallback(\n async (...args: Args): Promise<Result | undefined> => {\n // Prevent concurrent executions\n if (isExecutingRef.current) {\n return;\n }\n\n // Abort previous request if still running\n if (abortControllerRef.current) {\n abortControllerRef.current.abort();\n }\n\n // Create new AbortController for this request\n const abortController = new AbortController();\n abortControllerRef.current = abortController;\n\n isExecutingRef.current = true;\n setLoading(true);\n setError(undefined);\n\n await alepha.events.emit(\"react:action:begin\", {\n type: \"custom\",\n id: options.id,\n });\n\n try {\n // Pass abort signal as last argument to handler\n const result = await options.handler(...args, {\n signal: abortController.signal,\n } as any);\n\n // Only update state if still mounted and not aborted\n if (!isMountedRef.current || abortController.signal.aborted) {\n return;\n }\n\n await alepha.events.emit(\"react:action:success\", {\n type: \"custom\",\n id: options.id,\n });\n\n if (options.onSuccess) {\n await options.onSuccess(result);\n }\n\n return result;\n } catch (err) {\n // Ignore abort errors\n if (err instanceof Error && err.name === \"AbortError\") {\n return;\n }\n\n // Only update state if still mounted\n if (!isMountedRef.current) {\n return;\n }\n\n const error = err as Error;\n setError(error);\n\n await alepha.events.emit(\"react:action:error\", {\n type: \"custom\",\n id: options.id,\n error,\n });\n\n if (options.onError) {\n await options.onError(error);\n } else {\n // Re-throw if no custom error handler\n throw error;\n }\n } finally {\n isExecutingRef.current = false;\n setLoading(false);\n\n await alepha.events.emit(\"react:action:end\", {\n type: \"custom\",\n id: options.id,\n });\n\n // Clean up abort controller\n if (abortControllerRef.current === abortController) {\n abortControllerRef.current = undefined;\n }\n }\n },\n [...deps, options.id, options.onError, options.onSuccess],\n );\n\n const handler = useCallback(\n async (...args: Args): Promise<Result | undefined> => {\n if (options.debounce) {\n // clear existing timer\n if (debounceTimerRef.current) {\n dateTimeProvider.clearTimeout(debounceTimerRef.current);\n }\n\n // Set new timer\n return new Promise((resolve) => {\n debounceTimerRef.current = dateTimeProvider.createTimeout(\n async () => {\n const result = await executeAction(...args);\n resolve(result);\n },\n options.debounce ?? 0,\n );\n });\n }\n\n return executeAction(...args);\n },\n [executeAction, options.debounce],\n );\n\n const cancel = useCallback(() => {\n // clear debounce timer\n if (debounceTimerRef.current) {\n dateTimeProvider.clearTimeout(debounceTimerRef.current);\n debounceTimerRef.current = undefined;\n }\n\n // abort in-flight request\n if (abortControllerRef.current) {\n abortControllerRef.current.abort();\n abortControllerRef.current = undefined;\n }\n\n // reset state\n if (isMountedRef.current) {\n isExecutingRef.current = false;\n setLoading(false);\n }\n }, []);\n\n // Run action on mount if runOnInit is true\n useEffect(() => {\n if (options.runOnInit) {\n handler(...([] as any));\n }\n }, deps);\n\n // Run action periodically if runEvery is specified\n useEffect(() => {\n if (!options.runEvery) {\n return;\n }\n\n // Set up interval\n intervalRef.current = dateTimeProvider.createInterval(\n () => handler(...([] as any)),\n options.runEvery,\n true,\n );\n\n // cleanup on unmount or when runEvery changes\n return () => {\n if (intervalRef.current) {\n dateTimeProvider.clearInterval(intervalRef.current);\n intervalRef.current = undefined;\n }\n };\n }, [handler, options.runEvery]);\n\n return {\n run: handler,\n loading,\n error,\n cancel,\n };\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * Context object passed as the last argument to action handlers.\n * Contains an AbortSignal that can be used to cancel the request.\n */\nexport interface ActionContext {\n /**\n * AbortSignal that can be passed to fetch or other async operations.\n * The signal will be aborted when:\n * - The component unmounts\n * - A new action is triggered (cancels previous)\n * - The cancel() method is called\n *\n * @example\n * ```tsx\n * const action = useAction({\n * handler: async (url, { signal }) => {\n * const response = await fetch(url, { signal });\n * return response.json();\n * }\n * }, []);\n * ```\n */\n signal: AbortSignal;\n}\n\nexport interface UseActionOptions<Args extends any[] = any[], Result = any> {\n /**\n * The async action handler function.\n * Receives the action arguments plus an ActionContext as the last parameter.\n */\n handler: (...args: [...Args, ActionContext]) => Async<Result>;\n\n /**\n * Custom error handler. If provided, prevents default error re-throw.\n */\n onError?: (error: Error) => void | Promise<void>;\n\n /**\n * Custom success handler.\n */\n onSuccess?: (result: Result) => void | Promise<void>;\n\n /**\n * Optional identifier for this action (useful for debugging/analytics)\n */\n id?: string;\n\n name?: string;\n\n /**\n * Debounce delay in milliseconds. If specified, the action will only execute\n * after the specified delay has passed since the last call. Useful for search inputs\n * or other high-frequency events.\n *\n * @example\n * ```tsx\n * // Execute search 300ms after user stops typing\n * const search = useAction({ handler: search, debounce: 300 }, [])\n * ```\n */\n debounce?: number;\n\n /**\n * If true, the action will be executed once when the component mounts.\n *\n * @example\n * ```tsx\n * const fetchData = useAction({\n * handler: async () => await api.getData(),\n * runOnInit: true\n * }, []);\n * ```\n */\n runOnInit?: boolean;\n\n /**\n * If specified, the action will be executed periodically at the given interval.\n * The interval is specified as a DurationLike value (number in ms, Duration object, or [number, unit] tuple).\n *\n * @example\n * ```tsx\n * // Run every 5 seconds\n * const poll = useAction({\n * handler: async () => await api.poll(),\n * runEvery: 5000\n * }, []);\n * ```\n *\n * @example\n * ```tsx\n * // Run every 1 minute\n * const poll = useAction({\n * handler: async () => await api.poll(),\n * runEvery: [1, 'minute']\n * }, []);\n * ```\n */\n runEvery?: DurationLike;\n}\n\nexport interface UseActionReturn<Args extends any[], Result> {\n /**\n * Execute the action with the provided arguments.\n *\n * @example\n * ```tsx\n * const action = useAction({ handler: async (data) => { ... } }, []);\n * action.run(data);\n * ```\n */\n run: (...args: Args) => Promise<Result | undefined>;\n\n /**\n * Loading state - true when action is executing.\n */\n loading: boolean;\n\n /**\n * Error state - contains error if action failed, undefined otherwise.\n */\n error?: Error;\n\n /**\n * Cancel any pending debounced action or abort the current in-flight request.\n *\n * @example\n * ```tsx\n * const action = useAction({ ... }, []);\n *\n * <button onClick={action.cancel} disabled={!action.loading}>\n * Cancel\n * </button>\n * ```\n */\n cancel: () => void;\n}\n","import {\n type ClientScope,\n type HttpVirtualClient,\n LinkProvider,\n} from \"alepha/server/links\";\nimport { useInject } from \"./useInject.ts\";\n\n/**\n * Hook to get a virtual client for the specified scope.\n *\n * It's the React-hook version of `$client()`, from `AlephaServerLinks` module.\n */\nexport const useClient = <T extends object>(\n scope?: ClientScope,\n): HttpVirtualClient<T> => {\n return useInject(LinkProvider).client<T>(scope);\n};\n","import type { Alepha } from \"alepha\";\nimport {\n type FetchOptions,\n HttpClient,\n type RequestConfigSchema,\n} from \"alepha/server\";\nimport { LinkProvider, type VirtualAction } from \"alepha/server/links\";\nimport { useEffect, useState } from \"react\";\nimport { useAlepha } from \"./useAlepha.ts\";\nimport { useInject } from \"./useInject.ts\";\n\nexport const useSchema = <TConfig extends RequestConfigSchema>(\n action: VirtualAction<TConfig>,\n): UseSchemaReturn<TConfig> => {\n const name = action.name;\n const alepha = useAlepha();\n const httpClient = useInject(HttpClient);\n const [schema, setSchema] = useState<UseSchemaReturn<TConfig>>(\n ssrSchemaLoading(alepha, name) as UseSchemaReturn<TConfig>,\n );\n\n useEffect(() => {\n if (!schema.loading) {\n return;\n }\n\n const opts: FetchOptions = {\n localCache: true,\n };\n\n httpClient\n .fetch(`${LinkProvider.path.apiLinks}/${name}/schema`, opts)\n .then((it) => setSchema(it.data as UseSchemaReturn<TConfig>));\n }, [name]);\n\n return schema;\n};\n\nexport type UseSchemaReturn<TConfig extends RequestConfigSchema> = TConfig & {\n loading: boolean;\n};\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * Get an action schema during server-side rendering (SSR) or client-side rendering (CSR).\n */\nexport const ssrSchemaLoading = (alepha: Alepha, name: string) => {\n // server-side rendering (SSR) context\n if (!alepha.isBrowser()) {\n // get user links\n const linkProvider = alepha.inject(LinkProvider);\n\n // check if user can access the link\n const can = linkProvider\n .getServerLinks()\n .find((link) => link.name === name);\n\n // yes!\n if (can) {\n // user-links have no schema, so we need to get it from the provider\n const schema = linkProvider.links.find((it) => it.name === name)?.schema;\n\n // oh, we have a schema!\n if (schema) {\n // attach to user link, it will be used in the client during hydration\n can.schema = schema;\n return schema;\n }\n }\n\n return { loading: true };\n }\n\n // browser side rendering (CSR) context\n // check if we have the schema already loaded\n const schema = alepha\n .inject(LinkProvider)\n .links.find((it) => it.name === name)?.schema;\n\n // yes!\n if (schema) {\n return schema;\n }\n\n // no, we need to load it\n return { loading: true };\n};\n","import { ReactRouter } from \"../services/ReactRouter.ts\";\nimport { useInject } from \"./useInject.ts\";\n\n/**\n * Use this hook to access the React Router instance.\n *\n * You can add a type parameter to specify the type of your application.\n * This will allow you to use the router in a typesafe way.\n *\n * @example\n * class App {\n * home = $page();\n * }\n *\n * const router = useRouter<App>();\n * router.go(\"home\"); // typesafe\n */\nexport const useRouter = <T extends object = any>(): ReactRouter<T> => {\n return useInject(ReactRouter<T>);\n};\n","import type { AnchorHTMLAttributes } from \"react\";\nimport { useRouter } from \"../hooks/useRouter.ts\";\n\nexport interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {\n href: string;\n}\n\nconst Link = (props: LinkProps) => {\n const router = useRouter();\n\n return (\n <a {...props} {...router.anchor(props.href)}>\n {props.children}\n </a>\n );\n};\n\nexport default Link;\n","import { useState } from \"react\";\nimport type { AnchorProps } from \"../providers/ReactPageProvider.ts\";\nimport { useRouter } from \"./useRouter.ts\";\nimport { useRouterState } from \"./useRouterState.ts\";\n\nexport interface UseActiveOptions {\n href: string;\n startWith?: boolean;\n}\n\nexport const useActive = (args: string | UseActiveOptions): UseActiveHook => {\n const router = useRouter();\n const [isPending, setPending] = useState(false);\n const state = useRouterState();\n const current = state.url.pathname;\n\n const options: UseActiveOptions =\n typeof args === \"string\" ? { href: args } : { ...args, href: args.href };\n const href = options.href;\n const isActive = router.isActive(href, options);\n\n return {\n isPending,\n isActive,\n anchorProps: {\n href: router.base(href),\n onClick: async (ev?: any) => {\n ev?.stopPropagation();\n ev?.preventDefault();\n if (isActive) return;\n if (isPending) return;\n\n setPending(true);\n try {\n await router.go(href);\n } finally {\n setPending(false);\n }\n },\n },\n };\n};\n\nexport interface UseActiveHook {\n isActive: boolean;\n anchorProps: AnchorProps;\n isPending: boolean;\n}\n","import type { Alepha, Static, TObject } from \"alepha\";\nimport { useEffect, useState } from \"react\";\nimport { useAlepha } from \"./useAlepha.ts\";\nimport { useRouter } from \"./useRouter.ts\";\n\n/**\n * Not well tested. Use with caution.\n */\nexport const useQueryParams = <T extends TObject>(\n schema: T,\n options: UseQueryParamsHookOptions = {},\n): [Partial<Static<T>>, (data: Static<T>) => void] => {\n const alepha = useAlepha();\n\n const key = options.key ?? \"q\";\n const router = useRouter();\n const querystring = router.query[key];\n\n const [queryParams = {}, setQueryParams] = useState<Static<T> | undefined>(\n decode(alepha, schema, router.query[key]),\n );\n\n useEffect(() => {\n setQueryParams(decode(alepha, schema, querystring));\n }, [querystring]);\n\n return [\n queryParams,\n (queryParams: Static<T>) => {\n setQueryParams(queryParams);\n router.setQueryParams((data) => {\n return { ...data, [key]: encode(alepha, schema, queryParams) };\n });\n },\n ];\n};\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface UseQueryParamsHookOptions {\n format?: \"base64\" | \"querystring\";\n key?: string;\n push?: boolean;\n}\n\nconst encode = (alepha: Alepha, schema: TObject, data: any) => {\n return btoa(JSON.stringify(alepha.codec.decode(schema, data)));\n};\n\nconst decode = <T extends TObject>(\n alepha: Alepha,\n schema: T,\n data: any,\n): Static<T> | undefined => {\n try {\n return alepha.codec.decode(\n schema,\n JSON.parse(atob(decodeURIComponent(data))),\n );\n } catch {\n return;\n }\n};\n","import { $module } from \"alepha\";\nimport { AlephaDateTime } from \"alepha/datetime\";\nimport { AlephaServer, type ServerRequest } from \"alepha/server\";\nimport { AlephaServerCache } from \"alepha/server/cache\";\nimport { AlephaServerLinks } from \"alepha/server/links\";\nimport type { ReactNode } from \"react\";\nimport { $page, type PageAnimation } from \"./primitives/$page.ts\";\nimport type { ReactHydrationState } from \"./providers/ReactBrowserProvider.ts\";\nimport {\n ReactPageProvider,\n type ReactRouterState,\n} from \"./providers/ReactPageProvider.ts\";\nimport { ReactServerProvider } from \"./providers/ReactServerProvider.ts\";\nimport { ReactPageServerService } from \"./services/ReactPageServerService.ts\";\nimport { ReactPageService } from \"./services/ReactPageService.ts\";\nimport { ReactRouter } from \"./services/ReactRouter.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport * from \"./index.shared.ts\";\nexport * from \"./index.shared-router.ts\";\nexport * from \"./providers/ReactBrowserProvider.ts\";\nexport * from \"./providers/ReactPageProvider.ts\";\nexport * from \"./providers/ReactServerProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\ndeclare module \"alepha\" {\n interface State {\n \"alepha.react.router.state\"?: ReactRouterState;\n }\n\n interface Hooks {\n /**\n * Fires when the React application is starting to be rendered on the server.\n */\n \"react:server:render:begin\": {\n request?: ServerRequest;\n state: ReactRouterState;\n };\n /**\n * Fires when the React application has been rendered on the server.\n */\n \"react:server:render:end\": {\n request?: ServerRequest;\n state: ReactRouterState;\n html: string;\n };\n // -----------------------------------------------------------------------------------------------------------------\n /**\n * Fires when the React application is being rendered on the browser.\n */\n \"react:browser:render\": {\n root: HTMLElement;\n element: ReactNode;\n state: ReactRouterState;\n hydration?: ReactHydrationState;\n };\n // -----------------------------------------------------------------------------------------------------------------\n // TOP LEVEL: All user actions (forms, transitions, custom actions)\n /**\n * Fires when a user action is starting.\n * Action can be a form submission, a route transition, or a custom action.\n */\n \"react:action:begin\": {\n type: string;\n id?: string;\n };\n /**\n * Fires when a user action has succeeded.\n * Action can be a form submission, a route transition, or a custom action.\n */\n \"react:action:success\": {\n type: string;\n id?: string;\n };\n /**\n * Fires when a user action has failed.\n * Action can be a form submission, a route transition, or a custom action.\n */\n \"react:action:error\": {\n type: string;\n id?: string;\n error: Error;\n };\n /**\n * Fires when a user action has completed, regardless of success or failure.\n * Action can be a form submission, a route transition, or a custom action.\n */\n \"react:action:end\": {\n type: string;\n id?: string;\n };\n // -----------------------------------------------------------------------------------------------------------------\n // SPECIFIC: Route transitions\n /**\n * Fires when a route transition is starting.\n */\n \"react:transition:begin\": {\n previous: ReactRouterState;\n state: ReactRouterState;\n animation?: PageAnimation;\n };\n /**\n * Fires when a route transition has succeeded.\n */\n \"react:transition:success\": {\n state: ReactRouterState;\n };\n /**\n * Fires when a route transition has failed.\n */\n \"react:transition:error\": {\n state: ReactRouterState;\n error: Error;\n };\n /**\n * Fires when a route transition has completed, regardless of success or failure.\n */\n \"react:transition:end\": {\n state: ReactRouterState;\n };\n }\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * Provides full-stack React development with declarative routing, server-side rendering, and client-side hydration.\n *\n * The React module enables building modern React applications using the `$page` primitive on class properties.\n * It delivers seamless server-side rendering, automatic code splitting, and client-side navigation with full\n * type safety and schema validation for route parameters and data.\n *\n * @see {@link $page}\n * @module alepha.react\n */\nexport const AlephaReact = $module({\n name: \"alepha.react\",\n primitives: [$page],\n services: [\n ReactServerProvider,\n ReactPageProvider,\n ReactRouter,\n ReactPageService,\n ReactPageServerService,\n ],\n register: (alepha) =>\n alepha\n .with(AlephaDateTime)\n .with(AlephaServer)\n .with(AlephaServerCache)\n .with(AlephaServerLinks)\n .with({\n provide: ReactPageService,\n use: ReactPageServerService,\n })\n .with(ReactServerProvider)\n .with(ReactPageProvider)\n .with(ReactRouter),\n});\n"],"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AM,OAClB,QACA,KAAK,MAAM,KAAK,mBAAmB,KAAK,CAAC,CAAC,CAC3C;SACK;AACN;;;;;;;;;;;;;;;;AC6EJ,MAAa,cAAc,QAAQ;CACjC,MAAM;CACN,YAAY,CAAC,MAAM;CACnB,UAAU;EACR;EACA;EACA;EACA;EACA;EACD;CACD,WAAW,WACT,OACG,KAAK,eAAe,CACpB,KAAK,aAAa,CAClB,KAAK,kBAAkB,CACvB,KAAK,kBAAkB,CACvB,KAAK;EACJ,SAAS;EACT,KAAK;EACN,CAAC,CACD,KAAK,oBAAoB,CACzB,KAAK,kBAAkB,CACvB,KAAK,YAAY;CACvB,CAAC"}
1
+ {"version":3,"file":"index.js","names":["frames: StackFrame[]","styles: Record<string, CSSProperties>","subs: Function[]","state","ErrorBoundary","ErrorViewer","envSchema","pages: ConcretePageRoute[]","NestedView","context: Record<string, any>","stack: Array<RouterStackItem>","route","config: Record<string, any>","context","element: ReactNode | Redirection | undefined","ErrorViewer","ClientOnly","children","envSchema","target: PageRoute | undefined","element","hydrationData: ReactHydrationState","query: Record<string, string>","previous: PreviousLayerData[]","query: Record<string, string>","error","schema","options: UseActiveOptions","queryParams"],"sources":["../../src/core/services/ReactPageService.ts","../../src/core/primitives/$page.ts","../../src/core/components/ClientOnly.tsx","../../src/core/components/ErrorViewer.tsx","../../src/core/contexts/RouterLayerContext.ts","../../src/core/errors/Redirection.ts","../../src/core/contexts/AlephaContext.ts","../../src/core/hooks/useAlepha.ts","../../src/core/hooks/useEvents.ts","../../src/core/hooks/useStore.ts","../../src/core/hooks/useRouterState.ts","../../src/core/components/ErrorBoundary.tsx","../../src/core/components/NestedView.tsx","../../src/core/components/NotFound.tsx","../../src/core/providers/ReactPageProvider.ts","../../src/core/providers/ReactServerProvider.ts","../../src/core/services/ReactPageServerService.ts","../../src/core/providers/ReactBrowserRouterProvider.ts","../../src/core/providers/ReactBrowserProvider.ts","../../src/core/services/ReactRouter.ts","../../src/core/contexts/AlephaProvider.tsx","../../src/core/hooks/useInject.ts","../../src/core/hooks/useAction.ts","../../src/core/hooks/useClient.ts","../../src/core/hooks/useSchema.ts","../../src/core/hooks/useRouter.ts","../../src/core/components/Link.tsx","../../src/core/hooks/useActive.ts","../../src/core/hooks/useQueryParams.ts","../../src/core/index.ts"],"sourcesContent":["import { AlephaError } from \"alepha\";\nimport type {\n PagePrimitiveRenderOptions,\n PagePrimitiveRenderResult,\n} from \"../primitives/$page.ts\";\n\nexport class ReactPageService {\n public fetch(\n pathname: string,\n options: PagePrimitiveRenderOptions = {},\n ): Promise<{\n html: string;\n response: Response;\n }> {\n throw new AlephaError(\"Fetch is not available for this environment.\");\n }\n\n public render(\n name: string,\n options: PagePrimitiveRenderOptions = {},\n ): Promise<PagePrimitiveRenderResult> {\n throw new AlephaError(\"Render is not available for this environment.\");\n }\n}\n","import {\n $inject,\n type Async,\n createPrimitive,\n Primitive,\n KIND,\n type Static,\n type TSchema,\n} from \"alepha\";\nimport type { ServerRequest } from \"alepha/server\";\nimport type { ServerRouteCache } from \"alepha/server/cache\";\nimport type { FC, ReactNode } from \"react\";\nimport type { ClientOnlyProps } from \"../components/ClientOnly.tsx\";\nimport type { Redirection } from \"../errors/Redirection.ts\";\nimport type { ReactRouterState } from \"../providers/ReactPageProvider.ts\";\nimport { ReactPageService } from \"../services/ReactPageService.ts\";\n\n/**\n * Main primitive for defining a React route in the application.\n *\n * The $page primitive is the core building block for creating type-safe, SSR-enabled React routes.\n * It provides a declarative way to define pages with powerful features:\n *\n * **Routing & Navigation**\n * - URL pattern matching with parameters (e.g., `/users/:id`)\n * - Nested routing with parent-child relationships\n * - Type-safe URL parameter and query string validation\n *\n * **Data Loading**\n * - Server-side data fetching with the `resolve` function\n * - Automatic serialization and hydration for SSR\n * - Access to request context, URL params, and parent data\n *\n * **Component Loading**\n * - Direct component rendering or lazy loading for code splitting\n * - Client-only rendering when browser APIs are needed\n * - Automatic fallback handling during hydration\n *\n * **Performance Optimization**\n * - Static generation for pre-rendered pages at build time\n * - Server-side caching with configurable TTL and providers\n * - Code splitting through lazy component loading\n *\n * **Error Handling**\n * - Custom error handlers with support for redirects\n * - Hierarchical error handling (child → parent)\n * - HTTP status code handling (404, 401, etc.)\n *\n * **Page Animations**\n * - CSS-based enter/exit animations\n * - Dynamic animations based on page state\n * - Custom timing and easing functions\n *\n * **Lifecycle Management**\n * - Server response hooks for headers and status codes\n * - Page leave handlers for cleanup (browser only)\n * - Permission-based access control\n *\n * @example Simple page with data fetching\n * ```typescript\n * const userProfile = $page({\n * path: \"/users/:id\",\n * schema: {\n * params: t.object({ id: t.integer() }),\n * query: t.object({ tab: t.optional(t.text()) })\n * },\n * resolve: async ({ params }) => {\n * const user = await userApi.getUser(params.id);\n * return { user };\n * },\n * lazy: () => import(\"./UserProfile.tsx\")\n * });\n * ```\n *\n * @example Nested routing with error handling\n * ```typescript\n * const projectSection = $page({\n * path: \"/projects/:id\",\n * children: () => [projectBoard, projectSettings],\n * resolve: async ({ params }) => {\n * const project = await projectApi.get(params.id);\n * return { project };\n * },\n * errorHandler: (error) => {\n * if (HttpError.is(error, 404)) {\n * return <ProjectNotFound />;\n * }\n * }\n * });\n * ```\n *\n * @example Static generation with caching\n * ```typescript\n * const blogPost = $page({\n * path: \"/blog/:slug\",\n * static: {\n * entries: posts.map(p => ({ params: { slug: p.slug } }))\n * },\n * resolve: async ({ params }) => {\n * const post = await loadPost(params.slug);\n * return { post };\n * }\n * });\n * ```\n */\nexport const $page = <\n TConfig extends PageConfigSchema = PageConfigSchema,\n TProps extends object = TPropsDefault,\n TPropsParent extends object = TPropsParentDefault,\n>(\n options: PagePrimitiveOptions<TConfig, TProps, TPropsParent>,\n): PagePrimitive<TConfig, TProps, TPropsParent> => {\n return createPrimitive(\n PagePrimitive<TConfig, TProps, TPropsParent>,\n options,\n );\n};\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface PagePrimitiveOptions<\n TConfig extends PageConfigSchema = PageConfigSchema,\n TProps extends object = TPropsDefault,\n TPropsParent extends object = TPropsParentDefault,\n> {\n /**\n * Identifier name for the page. Must be unique.\n *\n * @default Primitive key\n */\n name?: string;\n\n /**\n * Add a pathname to the page.\n *\n * Pathname can contain parameters, like `/post/:slug`.\n *\n * @default \"\"\n */\n path?: string;\n\n /**\n * Add an input schema to define:\n * - `params`: parameters from the pathname.\n * - `query`: query parameters from the URL.\n */\n schema?: TConfig;\n\n /**\n * Load data before rendering the page.\n *\n * This function receives\n * - the request context (params, query, etc.)\n * - the parent props (if page has a parent)\n *\n * > In SSR, the returned data will be serialized and sent to the client, then reused during the client-side hydration.\n *\n * Resolve can be stopped by throwing an error, which will be handled by the `errorHandler` function.\n * It's common to throw a `NotFoundError` to display a 404 page.\n *\n * RedirectError can be thrown to redirect the user to another page.\n */\n resolve?: (context: PageResolve<TConfig, TPropsParent>) => Async<TProps>;\n\n /**\n * Default props to pass to the component when rendering the page.\n *\n * Resolved props from the `resolve` function will override these default props.\n */\n props?: () => Partial<TProps>;\n\n /**\n * The component to render when the page is loaded.\n *\n * If `lazy` is defined, this will be ignored.\n * Prefer using `lazy` to improve the initial loading time.\n */\n component?: FC<TProps & TPropsParent>;\n\n /**\n * Lazy load the component when the page is loaded.\n *\n * It's recommended to use this for components to improve the initial loading time\n * and enable code-splitting.\n */\n lazy?: () => Promise<{ default: FC<TProps & TPropsParent> }>;\n\n /**\n * Attach child pages to create nested routes.\n * This will make the page a parent route.\n */\n children?: Array<PagePrimitive> | (() => Array<PagePrimitive>);\n\n /**\n * Define a parent page for nested routing.\n */\n parent?: PagePrimitive<PageConfigSchema, TPropsParent, any>;\n\n /**\n * Function to determine if the page can be accessed.\n *\n * If it returns false, the page will not be accessible and a 403 Forbidden error will be returned.\n * This function can be used to implement permission-based access control.\n */\n can?: () => boolean;\n\n /**\n * Catch any error from the `resolve` function or during `rendering`.\n *\n * Expected to return one of the following:\n * - a ReactNode to render an error page\n * - a Redirection to redirect the user\n * - undefined to let the error propagate\n *\n * If not defined, the error will be thrown and handled by the server or client error handler.\n * If a leaf $page does not define an error handler, the error can be caught by parent pages.\n *\n * @example Catch a 404 from API and render a custom not found component:\n * ```ts\n * resolve: async ({ params, query }) => {\n * api.fetch(\"/api/resource\", { params, query });\n * },\n * errorHandler: (error, context) => {\n * if (HttpError.is(error, 404)) {\n * return <ResourceNotFound />;\n * }\n * }\n * ```\n *\n * @example Catch an 401 error and redirect the user to the login page:\n * ```ts\n * resolve: async ({ params, query }) => {\n * // but the user is not authenticated\n * api.fetch(\"/api/resource\", { params, query });\n * },\n * errorHandler: (error, context) => {\n * if (HttpError.is(error, 401)) {\n * // throwing a Redirection is also valid!\n * return new Redirection(\"/login\");\n * }\n * }\n * ```\n */\n errorHandler?: ErrorHandler;\n\n /**\n * If true, the page will be considered as a static page, immutable and cacheable.\n * Replace boolean by an object to define static entries. (e.g. list of params/query)\n *\n * Browser-side: it only works with `alepha/vite`, which can pre-render the page at build time.\n *\n * Server-side: It will act as timeless cached page. You can use `cache` to configure the cache behavior.\n */\n static?:\n | boolean\n | {\n entries?: Array<Partial<PageRequestConfig<TConfig>>>;\n };\n\n cache?: ServerRouteCache;\n\n /**\n * If true, force the page to be rendered only on the client-side (browser).\n * It uses the `<ClientOnly/>` component to render the page.\n */\n client?: boolean | ClientOnlyProps;\n\n /**\n * Called before the server response is sent to the client. (server only)\n */\n onServerResponse?: (request: ServerRequest) => unknown;\n\n /**\n * Called when user leaves the page. (browser only)\n */\n onLeave?: () => void;\n\n /**\n * @experimental\n *\n * Add a css animation when the page is loaded or unloaded.\n * It uses CSS animations, so you need to define the keyframes in your CSS.\n *\n * @example Simple animation name\n * ```ts\n * animation: \"fadeIn\"\n * ```\n *\n * CSS example:\n * ```css\n * @keyframes fadeIn {\n * from { opacity: 0; }\n * to { opacity: 1; }\n * }\n * ```\n *\n * @example Detailed animation\n * ```ts\n * animation: {\n * enter: { name: \"fadeIn\", duration: 300 },\n * exit: { name: \"fadeOut\", duration: 200, timing: \"ease-in-out\" },\n * }\n * ```\n *\n * @example Only exit animation\n * ```ts\n * animation: {\n * exit: \"fadeOut\"\n * }\n * ```\n *\n * @example With custom timing function\n * ```ts\n * animation: {\n * enter: { name: \"fadeIn\", duration: 300, timing: \"cubic-bezier(0.4, 0, 0.2, 1)\" },\n * exit: { name: \"fadeOut\", duration: 200, timing: \"ease-in-out\" },\n * }\n * ```\n */\n animation?: PageAnimation;\n}\n\nexport type ErrorHandler = (\n error: Error,\n state: ReactRouterState,\n) => ReactNode | Redirection | undefined;\n\nexport class PagePrimitive<\n TConfig extends PageConfigSchema = PageConfigSchema,\n TProps extends object = TPropsDefault,\n TPropsParent extends object = TPropsParentDefault,\n> extends Primitive<PagePrimitiveOptions<TConfig, TProps, TPropsParent>> {\n protected readonly reactPageService = $inject(ReactPageService);\n\n protected onInit() {\n if (this.options.static) {\n this.options.cache ??= {\n store: {\n provider: \"memory\",\n ttl: [1, \"week\"],\n },\n };\n }\n }\n\n public get name(): string {\n return this.options.name ?? this.config.propertyKey;\n }\n\n /**\n * For testing or build purposes.\n *\n * This will render the page (HTML layout included or not) and return the HTML + context.\n * Only valid for server-side rendering, it will throw an error if called on the client-side.\n */\n public async render(\n options?: PagePrimitiveRenderOptions,\n ): Promise<PagePrimitiveRenderResult> {\n return this.reactPageService.render(this.name, options);\n }\n\n public async fetch(options?: PagePrimitiveRenderOptions): Promise<{\n html: string;\n response: Response;\n }> {\n return this.reactPageService.fetch(this.options.path || \"\", options);\n }\n\n public match(url: string): boolean {\n // TODO: Implement a way to match the URL against the pathname\n return false;\n }\n\n public pathname(config: any) {\n // TODO: Implement a way to generate the pathname based on the config\n return this.options.path || \"\";\n }\n}\n\n$page[KIND] = PagePrimitive;\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface PageConfigSchema {\n query?: TSchema;\n params?: TSchema;\n}\n\nexport type TPropsDefault = any;\n\nexport type TPropsParentDefault = {};\n\nexport interface PagePrimitiveRenderOptions {\n params?: Record<string, string>;\n query?: Record<string, string>;\n\n /**\n * If true, the HTML layout will be included in the response.\n * If false, only the page content will be returned.\n *\n * @default true\n */\n html?: boolean;\n hydration?: boolean;\n}\n\nexport interface PagePrimitiveRenderResult {\n html: string;\n state: ReactRouterState;\n redirect?: string;\n}\n\nexport interface PageRequestConfig<\n TConfig extends PageConfigSchema = PageConfigSchema,\n> {\n params: TConfig[\"params\"] extends TSchema\n ? Static<TConfig[\"params\"]>\n : Record<string, string>;\n\n query: TConfig[\"query\"] extends TSchema\n ? Static<TConfig[\"query\"]>\n : Record<string, string>;\n}\n\nexport type PageResolve<\n TConfig extends PageConfigSchema = PageConfigSchema,\n TPropsParent extends object = TPropsParentDefault,\n> = PageRequestConfig<TConfig> &\n TPropsParent &\n Omit<ReactRouterState, \"layers\" | \"onError\">;\n\nexport type PageAnimation =\n | PageAnimationObject\n | ((state: ReactRouterState) => PageAnimationObject | undefined);\n\ntype PageAnimationObject =\n | CssAnimationName\n | {\n enter?: CssAnimation | CssAnimationName;\n exit?: CssAnimation | CssAnimationName;\n };\n\ntype CssAnimationName = string;\n\ntype CssAnimation = {\n name: string;\n duration?: number;\n timing?: string;\n};\n","import {\n type PropsWithChildren,\n type ReactNode,\n useEffect,\n useState,\n} from \"react\";\n\nexport interface ClientOnlyProps {\n fallback?: ReactNode;\n disabled?: boolean;\n}\n\n/**\n * A small utility component that renders its children only on the client side.\n *\n * Optionally, you can provide a fallback React node that will be rendered.\n *\n * You should use this component when\n * - you have code that relies on browser-specific APIs\n * - you want to avoid server-side rendering for a specific part of your application\n * - you want to prevent pre-rendering of a component\n */\nconst ClientOnly = (props: PropsWithChildren<ClientOnlyProps>) => {\n const [mounted, setMounted] = useState(false);\n\n useEffect(() => setMounted(true), []);\n\n if (props.disabled) {\n return props.children;\n }\n\n return mounted ? props.children : props.fallback;\n};\n\nexport default ClientOnly;\n","import type { Alepha } from \"alepha\";\nimport { type CSSProperties, useState } from \"react\";\n\ninterface ErrorViewerProps {\n error: Error;\n alepha: Alepha;\n}\n\ninterface StackFrame {\n fn: string;\n file: string;\n line: string;\n col: string;\n raw: string;\n}\n\n/**\n * Error viewer component that displays error details in development mode\n */\nconst ErrorViewer = ({ error, alepha }: ErrorViewerProps) => {\n const [expanded, setExpanded] = useState(false);\n const isProduction = alepha.isProduction();\n\n if (isProduction) {\n return <ErrorViewerProduction />;\n }\n\n const frames = parseStackTrace(error.stack);\n const visibleFrames = expanded ? frames : frames.slice(0, 6);\n const hiddenCount = frames.length - 6;\n\n return (\n <div style={styles.overlay}>\n <div style={styles.container}>\n <Header error={error} />\n <StackTraceSection\n frames={frames}\n visibleFrames={visibleFrames}\n expanded={expanded}\n hiddenCount={hiddenCount}\n onToggle={() => setExpanded(!expanded)}\n />\n </div>\n </div>\n );\n};\n\nexport default ErrorViewer;\n\n/**\n * Parse stack trace string into structured frames\n */\nfunction parseStackTrace(stack?: string): StackFrame[] {\n if (!stack) return [];\n\n const lines = stack.split(\"\\n\").slice(1);\n const frames: StackFrame[] = [];\n\n for (const line of lines) {\n const trimmed = line.trim();\n if (!trimmed.startsWith(\"at \")) continue;\n\n const frame = parseStackLine(trimmed);\n if (frame) frames.push(frame);\n }\n\n return frames;\n}\n\n/**\n * Parse a single stack trace line into a structured frame\n */\nfunction parseStackLine(line: string): StackFrame | null {\n const withFn = line.match(/^at\\s+(.+?)\\s+\\((.+):(\\d+):(\\d+)\\)$/);\n if (withFn) {\n return {\n fn: withFn[1],\n file: withFn[2],\n line: withFn[3],\n col: withFn[4],\n raw: line,\n };\n }\n\n const withoutFn = line.match(/^at\\s+(.+):(\\d+):(\\d+)$/);\n if (withoutFn) {\n return {\n fn: \"<anonymous>\",\n file: withoutFn[1],\n line: withoutFn[2],\n col: withoutFn[3],\n raw: line,\n };\n }\n\n return { fn: \"\", file: line.replace(/^at\\s+/, \"\"), line: \"\", col: \"\", raw: line };\n}\n\n/**\n * Copy text to clipboard\n */\nfunction copyToClipboard(text: string): void {\n navigator.clipboard.writeText(text).catch((err) => {\n console.error(\"Clipboard error:\", err);\n });\n}\n\n/**\n * Header section with error type and message\n */\nfunction Header({ error }: { error: Error }) {\n const [copied, setCopied] = useState(false);\n\n const handleCopy = () => {\n copyToClipboard(error.stack || error.message);\n setCopied(true);\n setTimeout(() => setCopied(false), 2000);\n };\n\n return (\n <div style={styles.header}>\n <div style={styles.headerTop}>\n <div style={styles.badge}>{error.name}</div>\n <button type=\"button\" onClick={handleCopy} style={styles.copyBtn}>\n {copied ? \"Copied\" : \"Copy Stack\"}\n </button>\n </div>\n <h1 style={styles.message}>{error.message}</h1>\n </div>\n );\n}\n\n/**\n * Stack trace section with expandable frames\n */\nfunction StackTraceSection({\n frames,\n visibleFrames,\n expanded,\n hiddenCount,\n onToggle,\n}: {\n frames: StackFrame[];\n visibleFrames: StackFrame[];\n expanded: boolean;\n hiddenCount: number;\n onToggle: () => void;\n}) {\n if (frames.length === 0) return null;\n\n return (\n <div style={styles.stackSection}>\n <div style={styles.stackHeader}>Call Stack</div>\n <div style={styles.frameList}>\n {visibleFrames.map((frame, i) => (\n <StackFrameRow key={i} frame={frame} index={i} />\n ))}\n {!expanded && hiddenCount > 0 && (\n <button type=\"button\" onClick={onToggle} style={styles.expandBtn}>\n Show {hiddenCount} more frames\n </button>\n )}\n {expanded && hiddenCount > 0 && (\n <button type=\"button\" onClick={onToggle} style={styles.expandBtn}>\n Show less\n </button>\n )}\n </div>\n </div>\n );\n}\n\n/**\n * Single stack frame row\n */\nfunction StackFrameRow({ frame, index }: { frame: StackFrame; index: number }) {\n const isFirst = index === 0;\n const fileName = frame.file.split(\"/\").pop() || frame.file;\n const dirPath = frame.file.substring(0, frame.file.length - fileName.length);\n\n return (\n <div\n style={{\n ...styles.frame,\n ...(isFirst ? styles.frameFirst : {}),\n }}\n >\n <div style={styles.frameIndex}>{index + 1}</div>\n <div style={styles.frameContent}>\n {frame.fn && (\n <div style={styles.fnName}>\n {frame.fn}\n </div>\n )}\n <div style={styles.filePath}>\n <span style={styles.dirPath}>{dirPath}</span>\n <span style={styles.fileName}>{fileName}</span>\n {frame.line && (\n <span style={styles.lineCol}>\n :{frame.line}:{frame.col}\n </span>\n )}\n </div>\n </div>\n </div>\n );\n}\n\n/**\n * Production error view - minimal information\n */\nfunction ErrorViewerProduction() {\n return (\n <div style={styles.overlay}>\n <div style={styles.prodContainer}>\n <div style={styles.prodIcon}>!</div>\n <h1 style={styles.prodTitle}>Application Error</h1>\n <p style={styles.prodMessage}>\n An unexpected error occurred. Please try again later.\n </p>\n <button\n type=\"button\"\n onClick={() => window.location.reload()}\n style={styles.prodButton}\n >\n Reload Page\n </button>\n </div>\n </div>\n );\n}\n\nconst styles: Record<string, CSSProperties> = {\n overlay: {\n position: \"fixed\",\n inset: 0,\n backgroundColor: \"rgba(0, 0, 0, 0.8)\",\n display: \"flex\",\n alignItems: \"flex-start\",\n justifyContent: \"center\",\n padding: \"40px 20px\",\n overflow: \"auto\",\n fontFamily:\n '-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif',\n zIndex: 99999,\n },\n container: {\n width: \"100%\",\n maxWidth: \"960px\",\n backgroundColor: \"#1a1a1a\",\n borderRadius: \"12px\",\n overflow: \"hidden\",\n boxShadow: \"0 25px 50px -12px rgba(0, 0, 0, 0.5)\",\n },\n header: {\n padding: \"24px 28px\",\n borderBottom: \"1px solid #333\",\n background: \"linear-gradient(to bottom, #1f1f1f, #1a1a1a)\",\n },\n headerTop: {\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"space-between\",\n marginBottom: \"16px\",\n },\n badge: {\n display: \"inline-block\",\n padding: \"6px 12px\",\n backgroundColor: \"#dc2626\",\n color: \"#fff\",\n fontSize: \"12px\",\n fontWeight: 600,\n borderRadius: \"6px\",\n letterSpacing: \"0.025em\",\n },\n copyBtn: {\n padding: \"8px 16px\",\n backgroundColor: \"transparent\",\n color: \"#888\",\n fontSize: \"13px\",\n fontWeight: 500,\n border: \"1px solid #444\",\n borderRadius: \"6px\",\n cursor: \"pointer\",\n transition: \"all 0.15s\",\n },\n message: {\n margin: 0,\n fontSize: \"20px\",\n fontWeight: 500,\n color: \"#fff\",\n lineHeight: 1.5,\n wordBreak: \"break-word\",\n },\n stackSection: {\n padding: \"0\",\n },\n stackHeader: {\n padding: \"16px 28px\",\n fontSize: \"11px\",\n fontWeight: 600,\n color: \"#666\",\n textTransform: \"uppercase\",\n letterSpacing: \"0.1em\",\n borderBottom: \"1px solid #2a2a2a\",\n },\n frameList: {\n display: \"flex\",\n flexDirection: \"column\",\n },\n frame: {\n display: \"flex\",\n alignItems: \"flex-start\",\n padding: \"14px 28px\",\n borderBottom: \"1px solid #252525\",\n transition: \"background-color 0.15s\",\n },\n frameFirst: {\n backgroundColor: \"rgba(220, 38, 38, 0.1)\",\n },\n frameIndex: {\n width: \"28px\",\n flexShrink: 0,\n fontSize: \"12px\",\n fontWeight: 500,\n color: \"#555\",\n fontFamily: \"monospace\",\n },\n frameContent: {\n flex: 1,\n minWidth: 0,\n },\n fnName: {\n fontSize: \"14px\",\n fontWeight: 500,\n color: \"#e5e5e5\",\n marginBottom: \"4px\",\n fontFamily:\n 'ui-monospace, SFMono-Regular, \"SF Mono\", Menlo, Consolas, monospace',\n },\n filePath: {\n fontSize: \"13px\",\n color: \"#888\",\n fontFamily:\n 'ui-monospace, SFMono-Regular, \"SF Mono\", Menlo, Consolas, monospace',\n wordBreak: \"break-all\",\n },\n dirPath: {\n color: \"#555\",\n },\n fileName: {\n color: \"#0ea5e9\",\n },\n lineCol: {\n color: \"#eab308\",\n },\n expandBtn: {\n padding: \"16px 28px\",\n backgroundColor: \"transparent\",\n color: \"#666\",\n fontSize: \"13px\",\n fontWeight: 500,\n border: \"none\",\n borderTop: \"1px solid #252525\",\n cursor: \"pointer\",\n textAlign: \"left\",\n transition: \"all 0.15s\",\n },\n prodContainer: {\n textAlign: \"center\",\n padding: \"60px 40px\",\n backgroundColor: \"#1a1a1a\",\n borderRadius: \"12px\",\n maxWidth: \"400px\",\n },\n prodIcon: {\n width: \"64px\",\n height: \"64px\",\n margin: \"0 auto 24px\",\n backgroundColor: \"#dc2626\",\n borderRadius: \"50%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n fontSize: \"32px\",\n fontWeight: 700,\n color: \"#fff\",\n },\n prodTitle: {\n margin: \"0 0 12px\",\n fontSize: \"24px\",\n fontWeight: 600,\n color: \"#fff\",\n },\n prodMessage: {\n margin: \"0 0 28px\",\n fontSize: \"15px\",\n color: \"#888\",\n lineHeight: 1.6,\n },\n prodButton: {\n padding: \"12px 24px\",\n backgroundColor: \"#fff\",\n color: \"#000\",\n fontSize: \"14px\",\n fontWeight: 600,\n border: \"none\",\n borderRadius: \"8px\",\n cursor: \"pointer\",\n },\n};\n","import { createContext } from \"react\";\nimport type { ErrorHandler } from \"../primitives/$page.ts\";\n\nexport interface RouterLayerContextValue {\n index: number;\n path: string;\n onError: ErrorHandler;\n}\n\nexport const RouterLayerContext = createContext<\n RouterLayerContextValue | undefined\n>(undefined);\n","/**\n * Used for Redirection during the page loading.\n *\n * Depends on the context, it can be thrown or just returned.\n */\nexport class Redirection extends Error {\n public readonly redirect: string;\n\n constructor(redirect: string) {\n super(\"Redirection\");\n this.redirect = redirect;\n }\n}\n","import type { Alepha } from \"alepha\";\nimport { createContext } from \"react\";\n\nexport const AlephaContext = createContext<Alepha | undefined>(undefined);\n","import { type Alepha, AlephaError } from \"alepha\";\nimport { useContext } from \"react\";\nimport { AlephaContext } from \"../contexts/AlephaContext.ts\";\n\n/**\n * Main Alepha hook.\n *\n * It provides access to the Alepha instance within a React component.\n *\n * With Alepha, you can access the core functionalities of the framework:\n *\n * - alepha.state() for state management\n * - alepha.inject() for dependency injection\n * - alepha.events.emit() for event handling\n * etc...\n */\nexport const useAlepha = (): Alepha => {\n const alepha = useContext(AlephaContext);\n if (!alepha) {\n throw new AlephaError(\n \"Hook 'useAlepha()' must be used within an AlephaContext.Provider\",\n );\n }\n\n return alepha;\n};\n","import type { Async, Hook, Hooks } from \"alepha\";\nimport { type DependencyList, useEffect } from \"react\";\nimport { useAlepha } from \"./useAlepha.ts\";\n\n/**\n * Allow subscribing to multiple Alepha events. See {@link Hooks} for available events.\n *\n * useEvents is fully typed to ensure correct event callback signatures.\n *\n * @example\n * ```tsx\n * useEvents(\n * {\n * \"react:transition:begin\": (ev) => {\n * console.log(\"Transition began to:\", ev.to);\n * },\n * \"react:transition:error\": {\n * priority: \"first\",\n * callback: (ev) => {\n * console.error(\"Transition error:\", ev.error);\n * },\n * },\n * },\n * [],\n * );\n * ```\n */\nexport const useEvents = (opts: UseEvents, deps: DependencyList) => {\n const alepha = useAlepha();\n\n useEffect(() => {\n if (!alepha.isBrowser()) {\n return;\n }\n\n const subs: Function[] = [];\n for (const [name, hook] of Object.entries(opts)) {\n subs.push(alepha.events.on(name as any, hook as any));\n }\n\n return () => {\n for (const clear of subs) {\n clear();\n }\n };\n }, deps);\n};\n\ntype UseEvents = {\n [T in keyof Hooks]?: Hook<T> | ((payload: Hooks[T]) => Async<void>);\n};\n","import type { State, Static, TAtomObject } from \"alepha\";\nimport { Atom } from \"alepha\";\nimport { useEffect, useMemo, useState } from \"react\";\nimport { useAlepha } from \"./useAlepha.ts\";\n\n/**\n * Hook to access and mutate the Alepha state.\n */\nfunction useStore<T extends TAtomObject>(\n target: Atom<T>,\n defaultValue?: Static<T>,\n): UseStoreReturn<Static<T>>;\nfunction useStore<Key extends keyof State>(\n target: Key,\n defaultValue?: State[Key],\n): UseStoreReturn<State[Key]>;\nfunction useStore(target: any, defaultValue?: any): any {\n const alepha = useAlepha();\n\n useMemo(() => {\n if (defaultValue != null && alepha.store.get(target) == null) {\n alepha.store.set(target, defaultValue);\n }\n }, [defaultValue]);\n\n const [state, setState] = useState(alepha.store.get(target));\n\n useEffect(() => {\n if (!alepha.isBrowser()) {\n return;\n }\n\n const key = target instanceof Atom ? target.key : target;\n\n return alepha.events.on(\"state:mutate\", (ev) => {\n if (ev.key === key) {\n setState(ev.value);\n }\n });\n }, []);\n\n return [\n state,\n (value: any) => {\n alepha.store.set(target, value);\n },\n ] as const;\n}\n\nexport type UseStoreReturn<T> = [T, (value: T) => void];\n\nexport { useStore };\n","import { AlephaError } from \"alepha\";\nimport type { ReactRouterState } from \"../providers/ReactPageProvider.ts\";\nimport { useStore } from \"./useStore.ts\";\n\nexport const useRouterState = (): ReactRouterState => {\n const [state] = useStore(\"alepha.react.router.state\");\n if (!state) {\n throw new AlephaError(\"Missing react router state\");\n }\n return state;\n};\n","import React, {\n type ErrorInfo,\n type PropsWithChildren,\n type ReactNode,\n} from \"react\";\n\n/**\n * Props for the ErrorBoundary component.\n */\nexport interface ErrorBoundaryProps {\n /**\n * Fallback React node to render when an error is caught.\n * If not provided, a default error message will be shown.\n */\n fallback: (error: Error) => ReactNode;\n\n /**\n * Optional callback that receives the error and error info.\n * Use this to log errors to a monitoring service.\n */\n onError?: (error: Error, info: ErrorInfo) => void;\n}\n\n/**\n * State of the ErrorBoundary component.\n */\ninterface ErrorBoundaryState {\n error?: Error;\n}\n\n/**\n * A reusable error boundary for catching rendering errors\n * in any part of the React component tree.\n */\nexport class ErrorBoundary extends React.Component<\n PropsWithChildren<ErrorBoundaryProps>,\n ErrorBoundaryState\n> {\n constructor(props: ErrorBoundaryProps) {\n super(props);\n this.state = {};\n }\n\n /**\n * Update state so the next render shows the fallback UI.\n */\n static getDerivedStateFromError(error: Error): ErrorBoundaryState {\n return {\n error,\n };\n }\n\n /**\n * Lifecycle method called when an error is caught.\n * You can log the error or perform side effects here.\n */\n componentDidCatch(error: Error, info: ErrorInfo): void {\n if (this.props.onError) {\n this.props.onError(error, info);\n }\n }\n\n render(): ReactNode {\n if (this.state.error) {\n return this.props.fallback(this.state.error);\n }\n\n return this.props.children;\n }\n}\n\nexport default ErrorBoundary;\n","import { memo, type ReactNode, use, useRef, useState } from \"react\";\nimport { RouterLayerContext } from \"../contexts/RouterLayerContext.ts\";\nimport type { ErrorHandler, PageAnimation } from \"../primitives/$page.ts\";\nimport { Redirection } from \"../errors/Redirection.ts\";\nimport { useEvents } from \"../hooks/useEvents.ts\";\nimport { useRouterState } from \"../hooks/useRouterState.ts\";\nimport type { ReactRouterState } from \"../providers/ReactPageProvider.ts\";\nimport ErrorBoundary from \"./ErrorBoundary.tsx\";\nimport ErrorViewer from \"./ErrorViewer.tsx\";\nimport { useAlepha } from \"../hooks/useAlepha.ts\";\n\nexport interface NestedViewProps {\n children?: ReactNode;\n errorBoundary?: false | ((error: Error) => ReactNode);\n}\n\n/**\n * A component that renders the current view of the nested router layer.\n *\n * To be simple, it renders the `element` of the current child page of a parent page.\n *\n * @example\n * ```tsx\n * import { NestedView } from \"@alepha/react\";\n *\n * class App {\n * parent = $page({\n * component: () => <NestedView />,\n * });\n *\n * child = $page({\n * parent: this.root,\n * component: () => <div>Child Page</div>,\n * });\n * }\n * ```\n */\nconst NestedView = (props: NestedViewProps) => {\n const routerLayer = use(RouterLayerContext);\n const index = routerLayer?.index ?? 0;\n const onError = routerLayer?.onError;\n const state = useRouterState();\n const alepha = useAlepha();\n\n const [view, setView] = useState<ReactNode | undefined>(\n state.layers[index]?.element,\n );\n\n const [animation, setAnimation] = useState(\"\");\n const animationExitDuration = useRef<number>(0);\n const animationExitNow = useRef<number>(0);\n\n useEvents(\n {\n \"react:transition:begin\": async ({ previous, state }) => {\n // --------- Animations Begin ---------\n const layer = previous.layers[index];\n if (!layer) {\n return;\n }\n\n if (`${state.url.pathname}/`.startsWith(`${layer.path}/`)) {\n return;\n }\n\n const animationExit = parseAnimation(\n layer.route?.animation,\n state,\n \"exit\",\n );\n\n if (animationExit) {\n const duration = animationExit.duration || 200;\n animationExitNow.current = Date.now();\n animationExitDuration.current = duration;\n setAnimation(animationExit.animation);\n } else {\n animationExitNow.current = 0;\n animationExitDuration.current = 0;\n setAnimation(\"\");\n }\n // --------- Animations End ---------\n },\n \"react:transition:end\": async ({ state }) => {\n const layer = state.layers[index];\n\n // --------- Animations Begin ---------\n if (animationExitNow.current) {\n const duration = animationExitDuration.current;\n const diff = Date.now() - animationExitNow.current;\n if (diff < duration) {\n await new Promise((resolve) =>\n setTimeout(resolve, duration - diff),\n );\n }\n }\n // --------- Animations End ---------\n\n if (!layer?.cache) {\n setView(layer?.element);\n\n // --------- Animations Begin ---------\n const animationEnter = parseAnimation(\n layer?.route?.animation,\n state,\n \"enter\",\n );\n\n if (animationEnter) {\n setAnimation(animationEnter.animation);\n } else {\n setAnimation(\"\");\n }\n // --------- Animations End ---------\n }\n },\n },\n [],\n );\n\n let element = view ?? props.children ?? null;\n\n // --------- Animations Begin ---------\n if (animation) {\n element = (\n <div\n style={{\n display: \"flex\",\n flex: 1,\n height: \"100%\",\n width: \"100%\",\n position: \"relative\",\n overflow: \"hidden\",\n }}\n >\n <div\n style={{ height: \"100%\", width: \"100%\", display: \"flex\", animation }}\n >\n {element}\n </div>\n </div>\n );\n }\n // --------- Animations End ---------\n\n if (props.errorBoundary === false) {\n return <>{element}</>;\n }\n\n if (props.errorBoundary) {\n return (\n <ErrorBoundary fallback={props.errorBoundary}>{element}</ErrorBoundary>\n );\n }\n\n const fallback = (error: Error) => {\n const result = onError?.(error, state) ?? <ErrorViewer error={error} alepha={alepha}/>;\n if (result instanceof Redirection) {\n return \"Redirection inside ErrorBoundary is not allowed.\";\n }\n return result as ReactNode;\n }\n\n return (\n <ErrorBoundary fallback={fallback}>\n {element}\n </ErrorBoundary>\n );\n};\n\nexport default memo(NestedView);\n\nfunction parseAnimation(\n animationLike: PageAnimation | undefined,\n state: ReactRouterState,\n type: \"enter\" | \"exit\" = \"enter\",\n):\n | {\n duration: number;\n animation: string;\n }\n | undefined {\n if (!animationLike) {\n return undefined;\n }\n\n const DEFAULT_DURATION = 300;\n\n const animation =\n typeof animationLike === \"function\" ? animationLike(state) : animationLike;\n\n if (typeof animation === \"string\") {\n if (type === \"exit\") {\n return;\n }\n return {\n duration: DEFAULT_DURATION,\n animation: `${DEFAULT_DURATION}ms ${animation}`,\n };\n }\n\n if (typeof animation === \"object\") {\n const anim = animation[type];\n const duration =\n typeof anim === \"object\"\n ? (anim.duration ?? DEFAULT_DURATION)\n : DEFAULT_DURATION;\n const name = typeof anim === \"object\" ? anim.name : anim;\n\n if (type === \"exit\") {\n const timing = typeof anim === \"object\" ? (anim.timing ?? \"\") : \"\";\n return {\n duration,\n animation: `${duration}ms ${timing} ${name}`,\n };\n }\n\n const timing = typeof anim === \"object\" ? (anim.timing ?? \"\") : \"\";\n\n return {\n duration,\n animation: `${duration}ms ${timing} ${name}`,\n };\n }\n\n return undefined;\n}\n","import type { CSSProperties } from \"react\";\n\nexport default function NotFoundPage(props: { style?: CSSProperties }) {\n return (\n <div\n style={{\n width: \"100%\",\n minHeight: \"90vh\",\n boxSizing: \"border-box\",\n display: \"flex\",\n flexDirection: \"column\",\n justifyContent: \"center\",\n alignItems: \"center\",\n textAlign: \"center\",\n fontFamily:\n 'system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif',\n padding: \"2rem\",\n ...props.style,\n }}\n >\n <div style={{ fontSize: \"6rem\", fontWeight: 200, lineHeight: 1 }}>404</div>\n <div style={{ fontSize: \"0.875rem\", marginTop: \"1rem\", opacity: 0.6 }}>\n Page not found\n </div>\n </div>\n );\n}\n","import {\n $env,\n $hook,\n $inject,\n Alepha,\n AlephaError,\n type Static,\n type TSchema,\n t,\n} from \"alepha\";\nimport { $logger } from \"alepha/logger\";\nimport { createElement, type ReactNode, StrictMode } from \"react\";\nimport ClientOnly from \"../components/ClientOnly.tsx\";\nimport ErrorViewer from \"../components/ErrorViewer.tsx\";\nimport NestedView from \"../components/NestedView.tsx\";\nimport NotFoundPage from \"../components/NotFound.tsx\";\nimport { AlephaContext } from \"../contexts/AlephaContext.ts\";\nimport { RouterLayerContext } from \"../contexts/RouterLayerContext.ts\";\nimport {\n $page,\n type ErrorHandler,\n type PagePrimitive,\n type PagePrimitiveOptions,\n} from \"../primitives/$page.ts\";\nimport { Redirection } from \"../errors/Redirection.ts\";\n\nconst envSchema = t.object({\n REACT_STRICT_MODE: t.boolean({ default: true }),\n});\n\ndeclare module \"alepha\" {\n export interface Env extends Partial<Static<typeof envSchema>> {}\n}\n\nexport class ReactPageProvider {\n protected readonly log = $logger();\n protected readonly env = $env(envSchema);\n protected readonly alepha = $inject(Alepha);\n protected readonly pages: PageRoute[] = [];\n\n public getPages(): PageRoute[] {\n return this.pages;\n }\n\n public getConcretePages(): ConcretePageRoute[] {\n const pages: ConcretePageRoute[] = [];\n for (const page of this.pages) {\n if (page.children && page.children.length > 0) {\n continue;\n }\n\n // check if the page has dynamic params\n const fullPath = this.pathname(page.name);\n if (fullPath.includes(\":\") || fullPath.includes(\"*\")) {\n if (typeof page.static === \"object\") {\n const entries = page.static.entries;\n if (entries && entries.length > 0) {\n for (const entry of entries) {\n const params = entry.params as Record<string, string>;\n const path = this.compile(page.path ?? \"\", params);\n if (!path.includes(\":\") && !path.includes(\"*\")) {\n pages.push({\n ...page,\n name: params[Object.keys(params)[0]],\n staticName: page.name,\n path,\n ...entry,\n });\n }\n }\n }\n }\n\n continue;\n }\n\n pages.push(page);\n }\n return pages;\n }\n\n public page(name: string): PageRoute {\n for (const page of this.pages) {\n if (page.name === name) {\n return page;\n }\n }\n\n throw new AlephaError(`Page '${name}' not found`);\n }\n\n public pathname(\n name: string,\n options: {\n params?: Record<string, string>;\n query?: Record<string, string>;\n } = {},\n ) {\n const page = this.page(name);\n if (!page) {\n throw new Error(`Page ${name} not found`);\n }\n\n let url = page.path ?? \"\";\n let parent = page.parent;\n while (parent) {\n url = `${parent.path ?? \"\"}/${url}`;\n parent = parent.parent;\n }\n\n url = this.compile(url, options.params ?? {});\n\n if (options.query) {\n const query = new URLSearchParams(options.query);\n if (query.toString()) {\n url += `?${query.toString()}`;\n }\n }\n\n return url.replace(/\\/\\/+/g, \"/\") || \"/\";\n }\n\n public url(\n name: string,\n options: { params?: Record<string, string>; host?: string } = {},\n ): URL {\n return new URL(\n this.pathname(name, options),\n // use provided base or default to http://localhost\n options.host ?? `http://localhost`,\n );\n }\n\n public root(state: ReactRouterState): ReactNode {\n const root = createElement(\n AlephaContext.Provider,\n { value: this.alepha },\n createElement(NestedView, {}, state.layers[0]?.element),\n );\n\n if (this.env.REACT_STRICT_MODE) {\n return createElement(StrictMode, {}, root);\n }\n\n return root;\n }\n\n protected convertStringObjectToObject = (\n schema?: TSchema,\n value?: any,\n ): any => {\n if (t.schema.isObject(schema) && typeof value === \"object\") {\n for (const key in schema.properties) {\n if (\n t.schema.isObject(schema.properties[key]) &&\n typeof value[key] === \"string\"\n ) {\n try {\n value[key] = this.alepha.codec.decode(\n schema.properties[key],\n decodeURIComponent(value[key]),\n );\n } catch (e) {\n // ignore\n }\n }\n }\n }\n return value;\n };\n\n /**\n * Create a new RouterState based on a given route and request.\n * This method resolves the layers for the route, applying any query and params schemas defined in the route.\n * It also handles errors and redirects.\n */\n public async createLayers(\n route: PageRoute,\n state: ReactRouterState,\n previous: PreviousLayerData[] = [],\n ): Promise<CreateLayersResult> {\n let context: Record<string, any> = {}; // all props\n const stack: Array<RouterStackItem> = [{ route }]; // stack of routes\n\n let parent = route.parent;\n while (parent) {\n stack.unshift({ route: parent });\n parent = parent.parent;\n }\n\n let forceRefresh = false;\n\n for (let i = 0; i < stack.length; i++) {\n const it = stack[i];\n const route = it.route;\n const config: Record<string, any> = {};\n\n try {\n this.convertStringObjectToObject(route.schema?.query, state.query);\n config.query = route.schema?.query\n ? this.alepha.codec.decode(route.schema.query, state.query)\n : {};\n } catch (e) {\n it.error = e as Error;\n break;\n }\n\n try {\n config.params = route.schema?.params\n ? this.alepha.codec.decode(route.schema.params, state.params)\n : {};\n } catch (e) {\n it.error = e as Error;\n break;\n }\n\n // save config\n it.config = {\n ...config,\n };\n\n // check if previous layer is the same, reuse if possible\n if (previous?.[i] && !forceRefresh && previous[i].name === route.name) {\n const url = (str?: string) => (str ? str.replace(/\\/\\/+/g, \"/\") : \"/\");\n\n const prev = JSON.stringify({\n part: url(previous[i].part),\n params: previous[i].config?.params ?? {},\n });\n\n const curr = JSON.stringify({\n part: url(route.path),\n params: config.params ?? {},\n });\n\n if (prev === curr) {\n // part is the same, reuse previous layer\n it.props = previous[i].props;\n it.error = previous[i].error;\n it.cache = true;\n context = {\n ...context,\n ...it.props,\n };\n continue;\n }\n\n // part is different, force refresh of next layers\n forceRefresh = true;\n }\n\n // no resolve, render a basic view by default\n if (!route.resolve) {\n continue;\n }\n\n try {\n const args = Object.create(state);\n Object.assign(args, config, context);\n const props = (await route.resolve?.(args)) ?? {};\n\n // save props\n it.props = {\n ...props,\n };\n\n // add props to context\n context = {\n ...context,\n ...props,\n };\n } catch (e) {\n // check if we need to redirect\n if (e instanceof Redirection) {\n return {\n redirect: e.redirect,\n };\n }\n\n this.log.error(\"Page resolver has failed\", e);\n\n it.error = e as Error;\n break;\n }\n }\n\n let acc = \"\";\n for (let i = 0; i < stack.length; i++) {\n const it = stack[i];\n const props = it.props ?? {};\n\n const params = { ...it.config?.params };\n for (const key of Object.keys(params)) {\n params[key] = String(params[key]);\n }\n\n acc += \"/\";\n acc += it.route.path ? this.compile(it.route.path, params) : \"\";\n const path = acc.replace(/\\/+/, \"/\");\n const localErrorHandler = this.getErrorHandler(it.route);\n if (localErrorHandler) {\n const onErrorParent = state.onError;\n state.onError = (error, context) => {\n const result = localErrorHandler(error, context);\n // if nothing happen, call the parent\n if (result === undefined) {\n return onErrorParent(error, context);\n }\n return result;\n };\n }\n\n // normal use case\n if (!it.error) {\n try {\n const element = await this.createElement(it.route, {\n // default props attached to page\n ...(it.route.props ? it.route.props() : {}),\n // resolved props\n ...props,\n // context props (from previous layers)\n ...context,\n });\n\n state.layers.push({\n name: it.route.name,\n props,\n part: it.route.path,\n config: it.config,\n element: this.renderView(i + 1, path, element, it.route),\n index: i + 1,\n path,\n route: it.route,\n cache: it.cache,\n });\n } catch (e) {\n it.error = e as Error;\n }\n }\n\n // handler has thrown an error, render an error view\n if (it.error) {\n try {\n let element: ReactNode | Redirection | undefined =\n await state.onError(it.error, state);\n\n if (element === undefined) {\n throw it.error;\n }\n\n if (element instanceof Redirection) {\n return {\n redirect: element.redirect,\n };\n }\n\n if (element === null) {\n element = this.renderError(it.error);\n }\n\n state.layers.push({\n props,\n error: it.error,\n name: it.route.name,\n part: it.route.path,\n config: it.config,\n element: this.renderView(i + 1, path, element, it.route),\n index: i + 1,\n path,\n route: it.route,\n });\n break;\n } catch (e) {\n if (e instanceof Redirection) {\n return {\n redirect: e.redirect,\n };\n }\n throw e;\n }\n }\n }\n\n return { state };\n }\n\n protected getErrorHandler(route: PageRoute): ErrorHandler | undefined {\n if (route.errorHandler) return route.errorHandler;\n let parent = route.parent;\n while (parent) {\n if (parent.errorHandler) return parent.errorHandler;\n parent = parent.parent;\n }\n }\n\n protected async createElement(\n page: PageRoute,\n props: Record<string, any>,\n ): Promise<ReactNode> {\n if (page.lazy && page.component) {\n this.log.warn(\n `Page ${page.name} has both lazy and component options, lazy will be used`,\n );\n }\n\n if (page.lazy) {\n const component = await page.lazy(); // load component\n return createElement(component.default, props);\n }\n\n if (page.component) {\n return createElement(page.component, props);\n }\n\n return undefined;\n }\n\n public renderError(error: Error): ReactNode {\n return createElement(ErrorViewer, { error, alepha: this.alepha });\n }\n\n public renderEmptyView(): ReactNode {\n return createElement(NestedView, {});\n }\n\n public href(\n page: { options: { name?: string } },\n params: Record<string, any> = {},\n ): string {\n const found = this.pages.find((it) => it.name === page.options.name);\n if (!found) {\n throw new AlephaError(`Page ${page.options.name} not found`);\n }\n\n let url = found.path ?? \"\";\n let parent = found.parent;\n while (parent) {\n url = `${parent.path ?? \"\"}/${url}`;\n parent = parent.parent;\n }\n\n url = this.compile(url, params);\n\n return url.replace(/\\/\\/+/g, \"/\") || \"/\";\n }\n\n public compile(path: string, params: Record<string, string> = {}) {\n for (const [key, value] of Object.entries(params)) {\n path = path.replace(`:${key}`, value);\n }\n return path;\n }\n\n protected renderView(\n index: number,\n path: string,\n view: ReactNode | undefined,\n page: PageRoute,\n ): ReactNode {\n view ??= this.renderEmptyView();\n\n const element = page.client\n ? createElement(\n ClientOnly,\n typeof page.client === \"object\" ? page.client : {},\n view,\n )\n : view;\n\n return createElement(\n RouterLayerContext.Provider,\n {\n value: {\n index,\n path,\n onError: this.getErrorHandler(page) ?? ((error) => this.renderError(error)),\n },\n },\n element,\n );\n }\n\n protected readonly configure = $hook({\n on: \"configure\",\n handler: () => {\n let hasNotFoundHandler = false;\n const pages = this.alepha.primitives($page);\n\n const hasParent = (it: PagePrimitive) => {\n if (it.options.parent) {\n return true;\n }\n\n for (const page of pages) {\n const children = page.options.children\n ? Array.isArray(page.options.children)\n ? page.options.children\n : page.options.children()\n : [];\n if (children.includes(it)) {\n return true;\n }\n }\n };\n\n for (const page of pages) {\n if (page.options.path === \"/*\") {\n hasNotFoundHandler = true;\n }\n\n // skip children, we only want root pages\n if (hasParent(page)) {\n continue;\n }\n\n this.add(this.map(pages, page));\n }\n\n if (!hasNotFoundHandler && pages.length > 0) {\n // add a default 404 page if not already defined\n this.add({\n path: \"/*\",\n name: \"notFound\",\n cache: true,\n component: NotFoundPage,\n onServerResponse: ({ reply }) => {\n reply.status = 404;\n },\n });\n }\n },\n });\n\n protected map(\n pages: Array<PagePrimitive>,\n target: PagePrimitive,\n ): PageRouteEntry {\n const children = target.options.children\n ? Array.isArray(target.options.children)\n ? target.options.children\n : target.options.children()\n : [];\n\n const getChildrenFromParent = (it: PagePrimitive): PagePrimitive[] => {\n const children = [];\n for (const page of pages) {\n if (page.options.parent === it) {\n children.push(page);\n }\n }\n return children;\n };\n\n children.push(...getChildrenFromParent(target));\n\n return {\n ...target.options,\n name: target.name,\n parent: undefined,\n children: children.map((it) => this.map(pages, it)),\n } as PageRoute;\n }\n\n public add(entry: PageRouteEntry) {\n if (this.alepha.isReady()) {\n throw new AlephaError(\"Router is already initialized\");\n }\n\n entry.name ??= this.nextId();\n const page = entry as PageRoute;\n\n page.match = this.createMatch(page);\n this.pages.push(page);\n\n if (page.children) {\n for (const child of page.children) {\n (child as PageRoute).parent = page;\n this.add(child);\n }\n }\n }\n\n protected createMatch(page: PageRoute): string {\n let url = page.path ?? \"/\";\n let target = page.parent;\n while (target) {\n url = `${target.path ?? \"\"}/${url}`;\n target = target.parent;\n }\n\n let path = url.replace(/\\/\\/+/g, \"/\");\n\n if (path.endsWith(\"/\") && path !== \"/\") {\n // remove trailing slash\n path = path.slice(0, -1);\n }\n\n return path;\n }\n\n protected _next = 0;\n\n protected nextId(): string {\n this._next += 1;\n return `P${this._next}`;\n }\n}\n\nexport const isPageRoute = (it: any): it is PageRoute => {\n return (\n it &&\n typeof it === \"object\" &&\n typeof it.path === \"string\" &&\n typeof it.page === \"object\"\n );\n};\n\nexport interface PageRouteEntry\n extends Omit<PagePrimitiveOptions, \"children\" | \"parent\"> {\n children?: PageRouteEntry[];\n}\n\nexport interface ConcretePageRoute extends PageRoute {\n /**\n * When exported, static routes can be split into multiple pages with different params.\n * We replace 'name' by the new name for each static entry, and old 'name' becomes 'staticName'.\n */\n staticName?: string;\n\n params?: Record<string, string>;\n}\n\nexport interface PageRoute extends PageRouteEntry {\n type: \"page\";\n name: string;\n parent?: PageRoute;\n match: string;\n}\n\nexport interface Layer {\n config?: {\n query?: Record<string, any>;\n params?: Record<string, any>;\n // stack of resolved props\n context?: Record<string, any>;\n };\n\n name: string;\n props?: Record<string, any>;\n error?: Error;\n part?: string;\n element: ReactNode;\n index: number;\n path: string;\n route?: PageRoute;\n cache?: boolean;\n}\n\nexport type PreviousLayerData = Omit<Layer, \"element\" | \"index\" | \"path\">;\n\nexport interface AnchorProps {\n href: string;\n onClick: (ev?: any) => any;\n}\n\nexport interface ReactRouterState {\n /**\n * Stack of layers for the current page.\n */\n layers: Array<Layer>;\n\n /**\n * URL of the current page.\n */\n url: URL;\n\n /**\n * Error handler for the current page.\n */\n onError: ErrorHandler;\n\n /**\n * Params extracted from the URL for the current page.\n */\n params: Record<string, any>;\n\n /**\n * Query parameters extracted from the URL for the current page.\n */\n query: Record<string, string>;\n\n /**\n * Optional meta information associated with the current page.\n */\n meta: Record<string, any>;\n\n //\n name?: string;\n}\n\nexport interface RouterStackItem {\n route: PageRoute;\n config?: Record<string, any>;\n props?: Record<string, any>;\n error?: Error;\n cache?: boolean;\n}\n\nexport interface TransitionOptions {\n previous?: PreviousLayerData[];\n}\n\nexport interface CreateLayersResult {\n redirect?: string;\n state?: ReactRouterState;\n}\n","import { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport {\n $atom,\n $env,\n $hook,\n $inject,\n $use,\n Alepha,\n AlephaError,\n type Static,\n t,\n} from \"alepha\";\nimport { $logger } from \"alepha/logger\";\nimport {\n type ServerHandler,\n ServerProvider,\n ServerRouterProvider,\n ServerTimingProvider,\n} from \"alepha/server\";\nimport { ServerLinksProvider } from \"alepha/server/links\";\nimport { ServerStaticProvider } from \"alepha/server/static\";\nimport { renderToString } from \"react-dom/server\";\nimport {\n $page,\n type PagePrimitiveRenderOptions,\n type PagePrimitiveRenderResult,\n} from \"../primitives/$page.ts\";\nimport { Redirection } from \"../errors/Redirection.ts\";\nimport type { ReactHydrationState } from \"./ReactBrowserProvider.ts\";\nimport {\n type PageRoute,\n ReactPageProvider,\n type ReactRouterState,\n} from \"./ReactPageProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nconst envSchema = t.object({\n REACT_SSR_ENABLED: t.optional(t.boolean()),\n REACT_ROOT_ID: t.text({ default: \"root\" }), // TODO: move to ReactPageProvider.options?\n});\n\ndeclare module \"alepha\" {\n interface Env extends Partial<Static<typeof envSchema>> {}\n interface State {\n \"alepha.react.server.ssr\"?: boolean;\n \"alepha.react.server.template\"?: string;\n }\n}\n\n/**\n * React server provider configuration atom\n */\nexport const reactServerOptions = $atom({\n name: \"alepha.react.server.options\",\n schema: t.object({\n publicDir: t.string(),\n staticServer: t.object({\n disabled: t.boolean(),\n path: t.string({\n description: \"URL path where static files will be served.\",\n }),\n }),\n }),\n default: {\n publicDir: \"public\",\n staticServer: {\n disabled: false,\n path: \"/\",\n },\n },\n});\n\nexport type ReactServerProviderOptions = Static<\n typeof reactServerOptions.schema\n>;\n\ndeclare module \"alepha\" {\n interface State {\n [reactServerOptions.key]: ReactServerProviderOptions;\n }\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport class ReactServerProvider {\n protected readonly log = $logger();\n protected readonly alepha = $inject(Alepha);\n protected readonly env = $env(envSchema);\n protected readonly pageApi = $inject(ReactPageProvider);\n protected readonly serverProvider = $inject(ServerProvider);\n protected readonly serverStaticProvider = $inject(ServerStaticProvider);\n protected readonly serverRouterProvider = $inject(ServerRouterProvider);\n protected readonly serverTimingProvider = $inject(ServerTimingProvider);\n\n public readonly ROOT_DIV_REGEX = new RegExp(\n `<div([^>]*)\\\\s+id=[\"']${this.env.REACT_ROOT_ID}[\"']([^>]*)>(.*?)<\\\\/div>`,\n \"is\",\n );\n protected preprocessedTemplate: PreprocessedTemplate | null = null;\n\n protected readonly options = $use(reactServerOptions);\n\n /**\n * Configure the React server provider.\n */\n public readonly onConfigure = $hook({\n on: \"configure\",\n handler: async () => {\n const pages = this.alepha.primitives($page);\n\n const ssrEnabled =\n pages.length > 0 && this.env.REACT_SSR_ENABLED !== false;\n\n this.alepha.store.set(\"alepha.react.server.ssr\", ssrEnabled);\n\n // development mode\n if (this.alepha.isViteDev()) {\n await this.configureVite(ssrEnabled);\n return;\n }\n\n // production mode\n let root = \"\";\n\n // non-serverless mode only -> serve static files\n if (!this.alepha.isServerless()) {\n root = this.getPublicDirectory();\n if (!root) {\n this.log.warn(\n \"Missing static files, static file server will be disabled\",\n );\n } else {\n this.log.debug(`Using static files from: ${root}`);\n await this.configureStaticServer(root);\n }\n }\n\n if (ssrEnabled) {\n await this.registerPages(async () => this.template);\n this.log.info(\"SSR OK\");\n return;\n }\n\n // no SSR enabled, serve index.html for all unmatched routes\n this.log.info(\"SSR is disabled, use History API fallback\");\n this.serverRouterProvider.createRoute({\n path: \"*\",\n handler: async ({ url, reply }) => {\n if (url.pathname.includes(\".\")) {\n // If the request is for a file (e.g., /style.css), do not fallback\n reply.headers[\"content-type\"] = \"text/plain\";\n reply.body = \"Not Found\";\n reply.status = 404;\n return;\n }\n\n reply.headers[\"content-type\"] = \"text/html\";\n\n // serve index.html for all unmatched routes\n return this.template;\n },\n });\n },\n });\n\n public get template() {\n return (\n this.alepha.store.get(\"alepha.react.server.template\") ??\n \"<!DOCTYPE html><html lang='en'><head></head><body></body></html>\"\n );\n }\n\n protected async registerPages(templateLoader: TemplateLoader) {\n // Preprocess template once\n const template = await templateLoader();\n if (template) {\n this.preprocessedTemplate = this.preprocessTemplate(template);\n }\n\n for (const page of this.pageApi.getPages()) {\n if (page.component || page.lazy) {\n this.log.debug(`+ ${page.match} -> ${page.name}`);\n\n this.serverRouterProvider.createRoute({\n ...page,\n schema: undefined, // schema is handled by the page primitive provider for now (shared by browser and server)\n method: \"GET\",\n path: page.match,\n handler: this.createHandler(page, templateLoader),\n });\n }\n }\n }\n\n /**\n * Get the public directory path where static files are located.\n */\n protected getPublicDirectory(): string {\n const maybe = [\n join(process.cwd(), `dist/${this.options.publicDir}`),\n join(process.cwd(), this.options.publicDir),\n ];\n\n for (const it of maybe) {\n if (existsSync(it)) {\n return it;\n }\n }\n\n return \"\";\n }\n\n /**\n * Configure the static file server to serve files from the given root directory.\n */\n protected async configureStaticServer(root: string) {\n await this.serverStaticProvider.createStaticServer({\n root,\n cacheControl: {\n maxAge: 3600,\n immutable: true,\n },\n ...this.options.staticServer,\n });\n }\n\n /**\n * Configure Vite for SSR.\n */\n protected async configureVite(ssrEnabled: boolean) {\n if (!ssrEnabled) {\n // do nothing, vite will handle everything for us\n return;\n }\n\n this.log.info(\"SSR (dev) OK\");\n\n const url = `http://${process.env.SERVER_HOST}:${process.env.SERVER_PORT}`;\n\n await this.registerPages(() =>\n fetch(`${url}/index.html`)\n .then((it) => it.text())\n .catch(() => undefined),\n );\n }\n\n /**\n * For testing purposes, creates a render function that can be used.\n */\n public async render(\n name: string,\n options: PagePrimitiveRenderOptions = {},\n ): Promise<PagePrimitiveRenderResult> {\n const page = this.pageApi.page(name);\n const url = new URL(this.pageApi.url(name, options));\n const entry: Partial<ReactRouterState> = {\n url,\n params: options.params ?? {},\n query: options.query ?? {},\n onError: () => null,\n layers: [],\n meta: {},\n };\n const state = entry as ReactRouterState;\n\n this.log.trace(\"Rendering\", {\n url,\n });\n\n await this.alepha.events.emit(\"react:server:render:begin\", {\n state,\n });\n\n const { redirect } = await this.pageApi.createLayers(\n page,\n state as ReactRouterState,\n );\n\n if (redirect) {\n return { state, html: \"\", redirect };\n }\n\n if (!options.html) {\n this.alepha.store.set(\"alepha.react.router.state\", state);\n\n return {\n state,\n html: renderToString(this.pageApi.root(state)),\n };\n }\n\n const template = this.template ?? \"\";\n const html = this.renderToHtml(template, state, options.hydration);\n\n if (html instanceof Redirection) {\n return { state, html: \"\", redirect };\n }\n\n const result = {\n state,\n html,\n };\n\n await this.alepha.events.emit(\"react:server:render:end\", result);\n\n return result;\n }\n\n protected createHandler(\n route: PageRoute,\n templateLoader: TemplateLoader,\n ): ServerHandler {\n return async (serverRequest) => {\n const { url, reply, query, params } = serverRequest;\n const template = await templateLoader();\n if (!template) {\n throw new AlephaError(\"Missing template for SSR rendering\");\n }\n\n this.log.trace(\"Rendering page\", {\n name: route.name,\n });\n\n const entry: Partial<ReactRouterState> = {\n url,\n params,\n query,\n onError: () => null,\n layers: [],\n };\n\n const state = entry as ReactRouterState;\n\n state.name = route.name;\n\n if (this.alepha.has(ServerLinksProvider)) {\n this.alepha.store.set(\n \"alepha.server.request.apiLinks\",\n await this.alepha.inject(ServerLinksProvider).getUserApiLinks({\n user: (serverRequest as any).user, // TODO: fix type\n authorization: serverRequest.headers.authorization,\n }),\n );\n }\n\n let target: PageRoute | undefined = route; // TODO: move to PagePrimitiveProvider\n while (target) {\n if (route.can && !route.can()) {\n this.log.warn(\n `Access to page '${route.name}' is forbidden by can() check`,\n )\n // if the page is not accessible, return 403\n reply.status = 403;\n reply.headers[\"content-type\"] = \"text/plain\";\n return \"Forbidden\";\n }\n target = target.parent;\n }\n\n // TODO: SSR strategies\n // - only when googlebot\n // - only child pages\n // if (page.client) {\n // \t// if the page is a client-only page, return 404\n // \treply.status = 200;\n // \treply.headers[\"content-type\"] = \"text/html\";\n // \treply.body = template;\n // \treturn;\n // }\n\n await this.alepha.events.emit(\"react:server:render:begin\", {\n request: serverRequest,\n state,\n });\n\n this.serverTimingProvider.beginTiming(\"createLayers\");\n\n const { redirect } = await this.pageApi.createLayers(route, state);\n\n this.serverTimingProvider.endTiming(\"createLayers\");\n\n if (redirect) {\n this.log.debug(\"Resolver resulted in redirection\", {\n redirect,\n });\n return reply.redirect(redirect);\n }\n\n reply.headers[\"content-type\"] = \"text/html\";\n\n // by default, disable caching for SSR responses\n // some plugins may override this\n reply.headers[\"cache-control\"] =\n \"no-store, no-cache, must-revalidate, proxy-revalidate\";\n reply.headers.pragma = \"no-cache\";\n reply.headers.expires = \"0\";\n\n const html = this.renderToHtml(template, state);\n if (html instanceof Redirection) {\n reply.redirect(\n typeof html.redirect === \"string\"\n ? html.redirect\n : this.pageApi.href(html.redirect),\n );\n this.log.debug(\"Rendering resulted in redirection\", {\n redirect: html.redirect,\n });\n return;\n }\n\n this.log.trace(\"Page rendered to HTML successfully\");\n\n const event = {\n request: serverRequest,\n state,\n html,\n };\n\n await this.alepha.events.emit(\"react:server:render:end\", event);\n\n route.onServerResponse?.(serverRequest);\n\n this.log.trace(\"Page rendered\", {\n name: route.name,\n });\n\n return event.html;\n };\n }\n\n public renderToHtml(\n template: string,\n state: ReactRouterState,\n hydration = true,\n ): string | Redirection {\n const element = this.pageApi.root(state);\n\n // attach react router state to the http request context\n this.alepha.store.set(\"alepha.react.router.state\", state);\n\n this.serverTimingProvider.beginTiming(\"renderToString\");\n let app = \"\";\n try {\n app = renderToString(element);\n } catch (error) {\n this.log.error(\n \"renderToString has failed, fallback to error handler\",\n error,\n );\n const element = state.onError(error as Error, state);\n if (element instanceof Redirection) {\n // if the error is a redirection, return the redirection URL\n return element;\n }\n\n app = renderToString(element);\n this.log.debug(\"Error handled successfully with fallback\");\n }\n this.serverTimingProvider.endTiming(\"renderToString\");\n\n const response = {\n html: template,\n };\n\n if (hydration) {\n const { request, context, ...store } =\n this.alepha.context.als?.getStore() ?? {}; /// TODO: als must be protected, find a way to iterate on alepha.state\n\n const hydrationData: ReactHydrationState = {\n ...store,\n // map react.router.state to the hydration state\n \"alepha.react.router.state\": undefined,\n layers: state.layers.map((it) => ({\n ...it,\n error: it.error\n ? {\n ...it.error,\n name: it.error.name,\n message: it.error.message,\n stack: !this.alepha.isProduction() ? it.error.stack : undefined,\n }\n : undefined,\n index: undefined,\n path: undefined,\n element: undefined,\n route: undefined,\n })),\n };\n\n // create hydration data\n const script = `<script>window.__ssr=${JSON.stringify(hydrationData)}</script>`;\n\n // inject app into template\n this.fillTemplate(response, app, script);\n }\n\n return response.html;\n }\n\n protected preprocessTemplate(template: string): PreprocessedTemplate {\n // Find the body close tag for script injection\n const bodyCloseMatch = template.match(/<\\/body>/i);\n const bodyCloseIndex = bodyCloseMatch?.index ?? template.length;\n\n const beforeScript = template.substring(0, bodyCloseIndex);\n const afterScript = template.substring(bodyCloseIndex);\n\n // Check if there's an existing root div\n const rootDivMatch = beforeScript.match(this.ROOT_DIV_REGEX);\n\n if (rootDivMatch) {\n // Split around the existing root div content\n const beforeDiv = beforeScript.substring(0, rootDivMatch.index!);\n const afterDivStart = rootDivMatch.index! + rootDivMatch[0].length;\n const afterDiv = beforeScript.substring(afterDivStart);\n\n const beforeApp = `${beforeDiv}<div${rootDivMatch[1]} id=\"${this.env.REACT_ROOT_ID}\"${rootDivMatch[2]}>`;\n const afterApp = `</div>${afterDiv}`;\n\n return { beforeApp, afterApp, beforeScript: \"\", afterScript };\n }\n\n // No existing root div, find body tag to inject new div\n const bodyMatch = beforeScript.match(/<body([^>]*)>/i);\n if (bodyMatch) {\n const beforeBody = beforeScript.substring(\n 0,\n bodyMatch.index! + bodyMatch[0].length,\n );\n const afterBody = beforeScript.substring(\n bodyMatch.index! + bodyMatch[0].length,\n );\n\n const beforeApp = `${beforeBody}<div id=\"${this.env.REACT_ROOT_ID}\">`;\n const afterApp = `</div>${afterBody}`;\n\n return { beforeApp, afterApp, beforeScript: \"\", afterScript };\n }\n\n // Fallback: no body tag found, just wrap everything\n return {\n beforeApp: `<div id=\"${this.env.REACT_ROOT_ID}\">`,\n afterApp: `</div>`,\n beforeScript,\n afterScript,\n };\n }\n\n protected fillTemplate(\n response: { html: string },\n app: string,\n script: string,\n ) {\n if (!this.preprocessedTemplate) {\n // Fallback to old logic if preprocessing failed\n this.preprocessedTemplate = this.preprocessTemplate(response.html);\n }\n\n // Pure concatenation - no regex replacements needed\n response.html =\n this.preprocessedTemplate.beforeApp +\n app +\n this.preprocessedTemplate.afterApp +\n script +\n this.preprocessedTemplate.afterScript;\n }\n}\n\ntype TemplateLoader = () => Promise<string | undefined>;\n\ninterface PreprocessedTemplate {\n beforeApp: string;\n afterApp: string;\n beforeScript: string;\n afterScript: string;\n}\n","import { $inject, AlephaError } from \"alepha\";\nimport { ServerProvider } from \"alepha/server\";\nimport type {\n PagePrimitiveRenderOptions,\n PagePrimitiveRenderResult,\n} from \"../primitives/$page.ts\";\nimport { ReactServerProvider } from \"../providers/ReactServerProvider.ts\";\nimport { ReactPageService } from \"./ReactPageService.ts\";\n\nexport class ReactPageServerService extends ReactPageService {\n protected readonly reactServerProvider = $inject(ReactServerProvider);\n protected readonly serverProvider = $inject(ServerProvider);\n\n public async render(\n name: string,\n options: PagePrimitiveRenderOptions = {},\n ): Promise<PagePrimitiveRenderResult> {\n return this.reactServerProvider.render(name, options);\n }\n\n public async fetch(\n pathname: string,\n options: PagePrimitiveRenderOptions = {},\n ): Promise<{\n html: string;\n response: Response;\n }> {\n const response = await fetch(`${this.serverProvider.hostname}/${pathname}`);\n\n const html = await response.text();\n if (options?.html) {\n return { html, response };\n }\n\n // take only text inside the root div\n const match = html.match(this.reactServerProvider.ROOT_DIV_REGEX);\n if (match) {\n return { html: match[3], response };\n }\n\n throw new AlephaError(\"Invalid HTML response\");\n }\n}\n","import { $hook, $inject, Alepha } from \"alepha\";\nimport { $logger } from \"alepha/logger\";\nimport { type Route, RouterProvider } from \"alepha/router\";\nimport { createElement, type ReactNode } from \"react\";\nimport NotFoundPage from \"../components/NotFound.tsx\";\nimport {\n isPageRoute,\n type PageRoute,\n type PageRouteEntry,\n type PreviousLayerData,\n ReactPageProvider,\n type ReactRouterState,\n} from \"./ReactPageProvider.ts\";\n\nexport interface BrowserRoute extends Route {\n page: PageRoute;\n}\n\nexport class ReactBrowserRouterProvider extends RouterProvider<BrowserRoute> {\n protected readonly log = $logger();\n protected readonly alepha = $inject(Alepha);\n protected readonly pageApi = $inject(ReactPageProvider);\n\n public add(entry: PageRouteEntry) {\n this.pageApi.add(entry);\n }\n\n protected readonly configure = $hook({\n on: \"configure\",\n handler: async () => {\n for (const page of this.pageApi.getPages()) {\n // mount only if a view is provided\n if (page.component || page.lazy) {\n this.push({\n path: page.match,\n page,\n });\n }\n }\n },\n });\n\n public async transition(\n url: URL,\n previous: PreviousLayerData[] = [],\n meta = {},\n ): Promise<string | void> {\n const { pathname, search } = url;\n\n const entry: Partial<ReactRouterState> = {\n url,\n query: {},\n params: {},\n layers: [],\n onError: () => null,\n meta,\n };\n\n const state = entry as ReactRouterState;\n\n // Emit both action and transition events\n await this.alepha.events.emit(\"react:action:begin\", {\n type: \"transition\",\n });\n await this.alepha.events.emit(\"react:transition:begin\", {\n previous: this.alepha.store.get(\"alepha.react.router.state\")!,\n state,\n });\n\n try {\n const { route, params } = this.match(pathname);\n\n const query: Record<string, string> = {};\n if (search) {\n for (const [key, value] of new URLSearchParams(search).entries()) {\n query[key] = String(value);\n }\n }\n\n state.name = route?.page.name;\n state.query = query;\n state.params = params ?? {};\n\n if (isPageRoute(route)) {\n const { redirect } = await this.pageApi.createLayers(\n route.page,\n state,\n previous,\n );\n if (redirect) {\n return redirect;\n }\n }\n\n if (state.layers.length === 0) {\n state.layers.push({\n name: \"not-found\",\n element: createElement(NotFoundPage),\n index: 0,\n path: \"/\",\n });\n }\n\n await this.alepha.events.emit(\"react:action:success\", {\n type: \"transition\",\n });\n await this.alepha.events.emit(\"react:transition:success\", { state });\n } catch (e) {\n this.log.error(\"Transition has failed\", e);\n state.layers = [\n {\n name: \"error\",\n element: this.pageApi.renderError(e as Error),\n index: 0,\n path: \"/\",\n },\n ];\n\n await this.alepha.events.emit(\"react:action:error\", {\n type: \"transition\",\n error: e as Error,\n });\n await this.alepha.events.emit(\"react:transition:error\", {\n error: e as Error,\n state,\n });\n }\n\n // [feature]: local hook for leaving a page\n if (previous) {\n for (let i = 0; i < previous.length; i++) {\n const layer = previous[i];\n if (state.layers[i]?.name !== layer.name) {\n this.pageApi.page(layer.name)?.onLeave?.();\n }\n }\n }\n\n this.alepha.store.set(\"alepha.react.router.state\", state);\n\n await this.alepha.events.emit(\"react:action:end\", {\n type: \"transition\",\n });\n await this.alepha.events.emit(\"react:transition:end\", {\n state,\n });\n }\n\n public root(state: ReactRouterState): ReactNode {\n return this.pageApi.root(state);\n }\n}\n","import {\n $atom,\n $env,\n $hook,\n $inject,\n $use,\n Alepha,\n type State,\n type Static,\n t,\n} from \"alepha\";\nimport { DateTimeProvider } from \"alepha/datetime\";\nimport { $logger } from \"alepha/logger\";\nimport { LinkProvider } from \"alepha/server/links\";\nimport { ReactBrowserRouterProvider } from \"./ReactBrowserRouterProvider.ts\";\nimport type {\n PreviousLayerData,\n ReactRouterState,\n TransitionOptions,\n} from \"./ReactPageProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nconst envSchema = t.object({\n REACT_ROOT_ID: t.text({ default: \"root\" }),\n});\n\ndeclare module \"alepha\" {\n interface Env extends Partial<Static<typeof envSchema>> {}\n}\n\n/**\n * React browser renderer configuration atom\n */\nexport const reactBrowserOptions = $atom({\n name: \"alepha.react.browser.options\",\n schema: t.object({\n scrollRestoration: t.enum([\"top\", \"manual\"]),\n }),\n default: {\n scrollRestoration: \"top\" as const,\n },\n});\n\nexport type ReactBrowserRendererOptions = Static<\n typeof reactBrowserOptions.schema\n>;\n\ndeclare module \"alepha\" {\n interface State {\n [reactBrowserOptions.key]: ReactBrowserRendererOptions;\n }\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport class ReactBrowserProvider {\n protected readonly env = $env(envSchema);\n protected readonly log = $logger();\n protected readonly client = $inject(LinkProvider);\n protected readonly alepha = $inject(Alepha);\n protected readonly router = $inject(ReactBrowserRouterProvider);\n protected readonly dateTimeProvider = $inject(DateTimeProvider);\n\n protected readonly options = $use(reactBrowserOptions);\n\n protected getRootElement() {\n const root = this.document.getElementById(this.env.REACT_ROOT_ID);\n if (root) {\n return root;\n }\n\n const div = this.document.createElement(\"div\");\n div.id = this.env.REACT_ROOT_ID;\n\n this.document.body.prepend(div);\n\n return div;\n }\n\n public transitioning?: {\n to: string;\n from?: string;\n };\n\n public get state(): ReactRouterState {\n return this.alepha.store.get(\"alepha.react.router.state\")!;\n }\n\n /**\n * Accessor for Document DOM API.\n */\n public get document() {\n return window.document;\n }\n\n /**\n * Accessor for History DOM API.\n */\n public get history() {\n return window.history;\n }\n\n /**\n * Accessor for Location DOM API.\n */\n public get location() {\n return window.location;\n }\n\n public get base() {\n const base = import.meta.env?.BASE_URL;\n if (!base || base === \"/\") {\n return \"\";\n }\n\n return base;\n }\n\n public get url(): string {\n const url = this.location.pathname + this.location.search;\n if (this.base) {\n return url.replace(this.base, \"\");\n }\n return url;\n }\n\n public pushState(path: string, replace?: boolean) {\n const url = this.base + path;\n\n if (replace) {\n this.history.replaceState({}, \"\", url);\n } else {\n this.history.pushState({}, \"\", url);\n }\n }\n\n public async invalidate(props?: Record<string, any>) {\n const previous: PreviousLayerData[] = [];\n\n this.log.trace(\"Invalidating layers\");\n\n if (props) {\n const [key] = Object.keys(props);\n const value = props[key];\n\n for (const layer of this.state.layers) {\n if (layer.props?.[key]) {\n previous.push({\n ...layer,\n props: {\n ...layer.props,\n [key]: value,\n },\n });\n break;\n }\n previous.push(layer);\n }\n }\n\n await this.render({ previous });\n }\n\n public async go(url: string, options: RouterGoOptions = {}): Promise<void> {\n this.log.trace(`Going to ${url}`, {\n url,\n options,\n });\n\n await this.render({\n url,\n previous: options.force ? [] : this.state.layers,\n meta: options.meta,\n });\n\n // when redirecting in browser\n if (this.state.url.pathname + this.state.url.search !== url) {\n this.pushState(this.state.url.pathname + this.state.url.search);\n return;\n }\n\n this.pushState(url, options.replace);\n }\n\n protected async render(options: RouterRenderOptions = {}): Promise<void> {\n const previous = options.previous ?? this.state.layers;\n const url = options.url ?? this.url;\n const start = this.dateTimeProvider.now();\n\n this.transitioning = {\n to: url,\n from: this.state?.url.pathname,\n };\n\n this.log.debug(\"Transitioning...\", {\n to: url,\n });\n\n const redirect = await this.router.transition(\n new URL(`http://localhost${url}`),\n previous,\n options.meta,\n );\n\n if (redirect) {\n this.log.info(\"Redirecting to\", {\n redirect,\n });\n\n // if redirect is an absolute URL, use window.location.href (full page reload)\n if (redirect.startsWith(\"http\")) {\n window.location.href = redirect;\n } else {\n // if redirect is a relative URL, use render() (single page app)\n return await this.render({ url: redirect });\n }\n }\n\n const ms = this.dateTimeProvider.now().diff(start);\n this.log.info(`Transition OK [${ms}ms]`, this.transitioning);\n\n this.transitioning = undefined;\n }\n\n /**\n * Get embedded layers from the server.\n */\n protected getHydrationState(): ReactHydrationState | undefined {\n try {\n if (\"__ssr\" in window && typeof window.__ssr === \"object\") {\n return window.__ssr as ReactHydrationState;\n }\n } catch (error) {\n console.error(error);\n }\n }\n\n // -------------------------------------------------------------------------------------------------------------------\n\n protected readonly onTransitionEnd = $hook({\n on: \"react:transition:end\",\n handler: () => {\n if (\n this.options.scrollRestoration === \"top\" &&\n typeof window !== \"undefined\" &&\n !this.alepha.isTest()\n ) {\n this.log.trace(\"Restoring scroll position to top\");\n window.scrollTo(0, 0);\n }\n },\n });\n\n public readonly ready = $hook({\n on: \"ready\",\n handler: async () => {\n const hydration = this.getHydrationState();\n const previous = hydration?.layers ?? [];\n\n if (hydration) {\n // low budget, but works for now\n for (const [key, value] of Object.entries(hydration)) {\n if (key !== \"layers\") {\n this.alepha.store.set(key as keyof State, value);\n }\n }\n }\n\n await this.render({ previous });\n\n const element = this.router.root(this.state);\n\n await this.alepha.events.emit(\"react:browser:render\", {\n element,\n root: this.getRootElement(),\n hydration,\n state: this.state,\n });\n\n window.addEventListener(\"popstate\", () => {\n // when you update silently queryParams or hash, skip rendering\n // if you want to force a rendering, use #go()\n if (this.base + this.state.url.pathname === this.location.pathname) {\n return;\n }\n\n this.log.debug(\"Popstate event triggered - rendering new state\", {\n url: this.location.pathname + this.location.search,\n });\n\n this.render();\n });\n },\n });\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface RouterGoOptions {\n replace?: boolean;\n match?: TransitionOptions;\n params?: Record<string, string>;\n query?: Record<string, string>;\n meta?: Record<string, any>;\n\n /**\n * Recreate the whole page, ignoring the current state.\n */\n force?: boolean;\n}\n\nexport type ReactHydrationState = {\n layers?: Array<PreviousLayerData>;\n} & {\n [key: string]: any;\n};\n\nexport interface RouterRenderOptions {\n url?: string;\n previous?: PreviousLayerData[];\n meta?: Record<string, any>;\n}\n","import { $inject, Alepha } from \"alepha\";\nimport type { PagePrimitive } from \"../primitives/$page.ts\";\nimport {\n ReactBrowserProvider,\n type RouterGoOptions,\n} from \"../providers/ReactBrowserProvider.ts\";\nimport {\n type AnchorProps,\n ReactPageProvider,\n type ReactRouterState,\n} from \"../providers/ReactPageProvider.ts\";\n\nexport class ReactRouter<T extends object> {\n protected readonly alepha = $inject(Alepha);\n protected readonly pageApi = $inject(ReactPageProvider);\n\n public get state(): ReactRouterState {\n return this.alepha.store.get(\"alepha.react.router.state\")!;\n }\n\n public get pages() {\n return this.pageApi.getPages();\n }\n\n public get concretePages() {\n return this.pageApi.getConcretePages();\n }\n\n public get browser(): ReactBrowserProvider | undefined {\n if (this.alepha.isBrowser()) {\n return this.alepha.inject(ReactBrowserProvider);\n }\n // server-side\n return undefined;\n }\n\n public isActive(\n href: string,\n options: {\n startWith?: boolean;\n } = {},\n ): boolean {\n const current = this.state.url.pathname;\n let isActive =\n current === href || current === `${href}/` || `${current}/` === href;\n\n if (options.startWith && !isActive) {\n isActive = current.startsWith(href);\n }\n\n return isActive;\n }\n\n public node(\n name: keyof VirtualRouter<T> | string,\n config: {\n params?: Record<string, any>;\n query?: Record<string, any>;\n } = {},\n ) {\n const page = this.pageApi.page(name as string);\n return {\n ...page,\n label: page.label ?? page.name,\n href: this.path(name, config),\n children: undefined,\n }\n }\n\n public path(\n name: keyof VirtualRouter<T> | string,\n config: {\n params?: Record<string, any>;\n query?: Record<string, any>;\n } = {},\n ): string {\n return this.pageApi.pathname(name as string, {\n params: {\n ...this.state?.params,\n ...config.params,\n },\n query: config.query,\n });\n }\n\n /**\n * Reload the current page.\n * This is equivalent to calling `go()` with the current pathname and search.\n */\n public async reload() {\n if (!this.browser) {\n return;\n }\n\n await this.go(this.location.pathname + this.location.search, {\n replace: true,\n force: true,\n });\n }\n\n public getURL(): URL {\n if (!this.browser) {\n return this.state.url;\n }\n\n return new URL(this.location.href);\n }\n\n public get location(): Location {\n if (!this.browser) {\n throw new Error(\"Browser is required\");\n }\n\n return this.browser.location;\n }\n\n public get current(): ReactRouterState {\n return this.state;\n }\n\n public get pathname(): string {\n return this.state.url.pathname;\n }\n\n public get query(): Record<string, string> {\n const query: Record<string, string> = {};\n\n for (const [key, value] of new URLSearchParams(\n this.state.url.search,\n ).entries()) {\n query[key] = String(value);\n }\n\n return query;\n }\n\n public async back() {\n this.browser?.history.back();\n }\n\n public async forward() {\n this.browser?.history.forward();\n }\n\n public async invalidate(props?: Record<string, any>) {\n await this.browser?.invalidate(props);\n }\n\n public async go(path: string, options?: RouterGoOptions): Promise<void>;\n public async go(\n path: keyof VirtualRouter<T>,\n options?: RouterGoOptions,\n ): Promise<void>;\n public async go(\n path: string | keyof VirtualRouter<T>,\n options?: RouterGoOptions,\n ): Promise<void> {\n for (const page of this.pages) {\n if (page.name === path) {\n await this.browser?.go(\n this.path(path as keyof VirtualRouter<T>, options),\n options,\n );\n return;\n }\n }\n\n await this.browser?.go(path as string, options);\n }\n\n public anchor(path: string, options?: RouterGoOptions): AnchorProps;\n public anchor(\n path: keyof VirtualRouter<T>,\n options?: RouterGoOptions,\n ): AnchorProps;\n public anchor(\n path: string | keyof VirtualRouter<T>,\n options: RouterGoOptions = {},\n ): AnchorProps {\n let href = path as string;\n\n for (const page of this.pages) {\n if (page.name === path) {\n href = this.path(path as keyof VirtualRouter<T>, options);\n break;\n }\n }\n\n return {\n href: this.base(href),\n onClick: (ev: any) => {\n ev.stopPropagation();\n ev.preventDefault();\n\n this.go(href, options).catch(console.error);\n },\n };\n }\n\n public base(path: string): string {\n const base = import.meta.env?.BASE_URL;\n if (!base || base === \"/\") {\n return path;\n }\n\n return base + path;\n }\n\n /**\n * Set query params.\n *\n * @param record\n * @param options\n */\n public setQueryParams(\n record:\n | Record<string, any>\n | ((queryParams: Record<string, any>) => Record<string, any>),\n options: {\n /**\n * If true, this will add a new entry to the history stack.\n */\n push?: boolean;\n } = {},\n ) {\n const func = typeof record === \"function\" ? record : () => record;\n const search = new URLSearchParams(func(this.query)).toString();\n const state = search ? `${this.pathname}?${search}` : this.pathname;\n\n if (options.push) {\n window.history.pushState({}, \"\", state);\n } else {\n window.history.replaceState({}, \"\", state);\n }\n }\n}\n\nexport type VirtualRouter<T> = {\n [K in keyof T as T[K] extends PagePrimitive ? K : never]: T[K];\n};\n","import { Alepha } from \"alepha\";\nimport { type ReactNode, useEffect, useMemo, useState } from \"react\";\nimport { AlephaContext } from \"./AlephaContext.ts\";\n\nexport interface AlephaProviderProps {\n children: ReactNode;\n onError: (error: Error) => ReactNode;\n onLoading: () => ReactNode;\n}\n\n/**\n * AlephaProvider component to initialize and provide Alepha instance to the app.\n * This isn't recommended for apps using alepha/react/router, as Router will handle this for you.\n */\nexport const AlephaProvider = (props: AlephaProviderProps) => {\n const alepha = useMemo(() => Alepha.create(), []);\n\n const [started, setStarted] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n\n useEffect(() => {\n alepha\n .start()\n .then(() => setStarted(true))\n .catch((err) => setError(err));\n }, [alepha]);\n\n if (error) {\n return props.onError(error);\n }\n\n if (!started) {\n return props.onLoading();\n }\n\n return (\n <AlephaContext.Provider value={alepha}>\n {props.children}\n </AlephaContext.Provider>\n );\n};\n","import type { Service } from \"alepha\";\nimport { useMemo } from \"react\";\nimport { useAlepha } from \"./useAlepha.ts\";\n\n/**\n * Hook to inject a service instance.\n * It's a wrapper of `useAlepha().inject(service)` with a memoization.\n */\nexport const useInject = <T extends object>(service: Service<T>): T => {\n const alepha = useAlepha();\n return useMemo(() => alepha.inject(service), []);\n};\n","import {\n DateTimeProvider,\n type DurationLike,\n type Interval,\n type Timeout,\n} from \"alepha/datetime\";\nimport {\n type DependencyList,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from \"react\";\nimport { useAlepha } from \"./useAlepha.ts\";\nimport { useInject } from \"./useInject.ts\";\nimport type { Async } from \"alepha\";\n\n/**\n * Hook for handling async actions with automatic error handling and event emission.\n *\n * By default, prevents concurrent executions - if an action is running and you call it again,\n * the second call will be ignored. Use `debounce` option to delay execution instead.\n *\n * Emits lifecycle events:\n * - `react:action:begin` - When action starts\n * - `react:action:success` - When action completes successfully\n * - `react:action:error` - When action throws an error\n * - `react:action:end` - Always emitted at the end\n *\n * @example Basic usage\n * ```tsx\n * const action = useAction({\n * handler: async (data) => {\n * await api.save(data);\n * }\n * }, []);\n *\n * <button onClick={() => action.run(data)} disabled={action.loading}>\n * Save\n * </button>\n * ```\n *\n * @example With debounce (search input)\n * ```tsx\n * const search = useAction({\n * handler: async (query: string) => {\n * await api.search(query);\n * },\n * debounce: 300 // Wait 300ms after last call\n * }, []);\n *\n * <input onChange={(e) => search.run(e.target.value)} />\n * ```\n *\n * @example Run on component mount\n * ```tsx\n * const fetchData = useAction({\n * handler: async () => {\n * const data = await api.getData();\n * return data;\n * },\n * runOnInit: true // Runs once when component mounts\n * }, []);\n * ```\n *\n * @example Run periodically (polling)\n * ```tsx\n * const pollStatus = useAction({\n * handler: async () => {\n * const status = await api.getStatus();\n * return status;\n * },\n * runEvery: 5000 // Run every 5 seconds\n * }, []);\n *\n * // Or with duration tuple\n * const pollStatus = useAction({\n * handler: async () => {\n * const status = await api.getStatus();\n * return status;\n * },\n * runEvery: [30, 'seconds'] // Run every 30 seconds\n * }, []);\n * ```\n *\n * @example With AbortController\n * ```tsx\n * const fetch = useAction({\n * handler: async (url, { signal }) => {\n * const response = await fetch(url, { signal });\n * return response.json();\n * }\n * }, []);\n * // Automatically cancelled on unmount or when new request starts\n * ```\n *\n * @example With error handling\n * ```tsx\n * const deleteAction = useAction({\n * handler: async (id: string) => {\n * await api.delete(id);\n * },\n * onError: (error) => {\n * if (error.code === 'NOT_FOUND') {\n * // Custom error handling\n * }\n * }\n * }, []);\n *\n * {deleteAction.error && <div>Error: {deleteAction.error.message}</div>}\n * ```\n *\n * @example Global error handling\n * ```tsx\n * // In your root app setup\n * alepha.events.on(\"react:action:error\", ({ error }) => {\n * toast.danger(error.message);\n * Sentry.captureException(error);\n * });\n * ```\n */\nexport function useAction<Args extends any[], Result = void>(\n options: UseActionOptions<Args, Result>,\n deps: DependencyList,\n): UseActionReturn<Args, Result> {\n const alepha = useAlepha();\n const dateTimeProvider = useInject(DateTimeProvider);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState<Error | undefined>();\n const isExecutingRef = useRef(false);\n const debounceTimerRef = useRef<Timeout | undefined>(undefined);\n const abortControllerRef = useRef<AbortController | undefined>(undefined);\n const isMountedRef = useRef(true);\n const intervalRef = useRef<Interval | undefined>(undefined);\n\n // Cleanup on unmount\n useEffect(() => {\n return () => {\n isMountedRef.current = false;\n\n // clear debounce timer\n if (debounceTimerRef.current) {\n dateTimeProvider.clearTimeout(debounceTimerRef.current);\n debounceTimerRef.current = undefined;\n }\n\n // clear interval\n if (intervalRef.current) {\n dateTimeProvider.clearInterval(intervalRef.current);\n intervalRef.current = undefined;\n }\n\n // abort in-flight request\n if (abortControllerRef.current) {\n abortControllerRef.current.abort();\n abortControllerRef.current = undefined;\n }\n };\n }, []);\n\n const executeAction = useCallback(\n async (...args: Args): Promise<Result | undefined> => {\n // Prevent concurrent executions\n if (isExecutingRef.current) {\n return;\n }\n\n // Abort previous request if still running\n if (abortControllerRef.current) {\n abortControllerRef.current.abort();\n }\n\n // Create new AbortController for this request\n const abortController = new AbortController();\n abortControllerRef.current = abortController;\n\n isExecutingRef.current = true;\n setLoading(true);\n setError(undefined);\n\n await alepha.events.emit(\"react:action:begin\", {\n type: \"custom\",\n id: options.id,\n });\n\n try {\n // Pass abort signal as last argument to handler\n const result = await options.handler(...args, {\n signal: abortController.signal,\n } as any);\n\n // Only update state if still mounted and not aborted\n if (!isMountedRef.current || abortController.signal.aborted) {\n return;\n }\n\n await alepha.events.emit(\"react:action:success\", {\n type: \"custom\",\n id: options.id,\n });\n\n if (options.onSuccess) {\n await options.onSuccess(result);\n }\n\n return result;\n } catch (err) {\n // Ignore abort errors\n if (err instanceof Error && err.name === \"AbortError\") {\n return;\n }\n\n // Only update state if still mounted\n if (!isMountedRef.current) {\n return;\n }\n\n const error = err as Error;\n setError(error);\n\n await alepha.events.emit(\"react:action:error\", {\n type: \"custom\",\n id: options.id,\n error,\n });\n\n if (options.onError) {\n await options.onError(error);\n } else {\n // Re-throw if no custom error handler\n throw error;\n }\n } finally {\n isExecutingRef.current = false;\n setLoading(false);\n\n await alepha.events.emit(\"react:action:end\", {\n type: \"custom\",\n id: options.id,\n });\n\n // Clean up abort controller\n if (abortControllerRef.current === abortController) {\n abortControllerRef.current = undefined;\n }\n }\n },\n [...deps, options.id, options.onError, options.onSuccess],\n );\n\n const handler = useCallback(\n async (...args: Args): Promise<Result | undefined> => {\n if (options.debounce) {\n // clear existing timer\n if (debounceTimerRef.current) {\n dateTimeProvider.clearTimeout(debounceTimerRef.current);\n }\n\n // Set new timer\n return new Promise((resolve) => {\n debounceTimerRef.current = dateTimeProvider.createTimeout(\n async () => {\n const result = await executeAction(...args);\n resolve(result);\n },\n options.debounce ?? 0,\n );\n });\n }\n\n return executeAction(...args);\n },\n [executeAction, options.debounce],\n );\n\n const cancel = useCallback(() => {\n // clear debounce timer\n if (debounceTimerRef.current) {\n dateTimeProvider.clearTimeout(debounceTimerRef.current);\n debounceTimerRef.current = undefined;\n }\n\n // abort in-flight request\n if (abortControllerRef.current) {\n abortControllerRef.current.abort();\n abortControllerRef.current = undefined;\n }\n\n // reset state\n if (isMountedRef.current) {\n isExecutingRef.current = false;\n setLoading(false);\n }\n }, []);\n\n // Run action on mount if runOnInit is true\n useEffect(() => {\n if (options.runOnInit) {\n handler(...([] as any));\n }\n }, deps);\n\n // Run action periodically if runEvery is specified\n useEffect(() => {\n if (!options.runEvery) {\n return;\n }\n\n // Set up interval\n intervalRef.current = dateTimeProvider.createInterval(\n () => handler(...([] as any)),\n options.runEvery,\n true,\n );\n\n // cleanup on unmount or when runEvery changes\n return () => {\n if (intervalRef.current) {\n dateTimeProvider.clearInterval(intervalRef.current);\n intervalRef.current = undefined;\n }\n };\n }, [handler, options.runEvery]);\n\n return {\n run: handler,\n loading,\n error,\n cancel,\n };\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * Context object passed as the last argument to action handlers.\n * Contains an AbortSignal that can be used to cancel the request.\n */\nexport interface ActionContext {\n /**\n * AbortSignal that can be passed to fetch or other async operations.\n * The signal will be aborted when:\n * - The component unmounts\n * - A new action is triggered (cancels previous)\n * - The cancel() method is called\n *\n * @example\n * ```tsx\n * const action = useAction({\n * handler: async (url, { signal }) => {\n * const response = await fetch(url, { signal });\n * return response.json();\n * }\n * }, []);\n * ```\n */\n signal: AbortSignal;\n}\n\nexport interface UseActionOptions<Args extends any[] = any[], Result = any> {\n /**\n * The async action handler function.\n * Receives the action arguments plus an ActionContext as the last parameter.\n */\n handler: (...args: [...Args, ActionContext]) => Async<Result>;\n\n /**\n * Custom error handler. If provided, prevents default error re-throw.\n */\n onError?: (error: Error) => void | Promise<void>;\n\n /**\n * Custom success handler.\n */\n onSuccess?: (result: Result) => void | Promise<void>;\n\n /**\n * Optional identifier for this action (useful for debugging/analytics)\n */\n id?: string;\n\n name?: string;\n\n /**\n * Debounce delay in milliseconds. If specified, the action will only execute\n * after the specified delay has passed since the last call. Useful for search inputs\n * or other high-frequency events.\n *\n * @example\n * ```tsx\n * // Execute search 300ms after user stops typing\n * const search = useAction({ handler: search, debounce: 300 }, [])\n * ```\n */\n debounce?: number;\n\n /**\n * If true, the action will be executed once when the component mounts.\n *\n * @example\n * ```tsx\n * const fetchData = useAction({\n * handler: async () => await api.getData(),\n * runOnInit: true\n * }, []);\n * ```\n */\n runOnInit?: boolean;\n\n /**\n * If specified, the action will be executed periodically at the given interval.\n * The interval is specified as a DurationLike value (number in ms, Duration object, or [number, unit] tuple).\n *\n * @example\n * ```tsx\n * // Run every 5 seconds\n * const poll = useAction({\n * handler: async () => await api.poll(),\n * runEvery: 5000\n * }, []);\n * ```\n *\n * @example\n * ```tsx\n * // Run every 1 minute\n * const poll = useAction({\n * handler: async () => await api.poll(),\n * runEvery: [1, 'minute']\n * }, []);\n * ```\n */\n runEvery?: DurationLike;\n}\n\nexport interface UseActionReturn<Args extends any[], Result> {\n /**\n * Execute the action with the provided arguments.\n *\n * @example\n * ```tsx\n * const action = useAction({ handler: async (data) => { ... } }, []);\n * action.run(data);\n * ```\n */\n run: (...args: Args) => Promise<Result | undefined>;\n\n /**\n * Loading state - true when action is executing.\n */\n loading: boolean;\n\n /**\n * Error state - contains error if action failed, undefined otherwise.\n */\n error?: Error;\n\n /**\n * Cancel any pending debounced action or abort the current in-flight request.\n *\n * @example\n * ```tsx\n * const action = useAction({ ... }, []);\n *\n * <button onClick={action.cancel} disabled={!action.loading}>\n * Cancel\n * </button>\n * ```\n */\n cancel: () => void;\n}\n","import {\n type ClientScope,\n type HttpVirtualClient,\n LinkProvider,\n} from \"alepha/server/links\";\nimport { useInject } from \"./useInject.ts\";\n\n/**\n * Hook to get a virtual client for the specified scope.\n *\n * It's the React-hook version of `$client()`, from `AlephaServerLinks` module.\n */\nexport const useClient = <T extends object>(\n scope?: ClientScope,\n): HttpVirtualClient<T> => {\n return useInject(LinkProvider).client<T>(scope);\n};\n","import type { Alepha } from \"alepha\";\nimport {\n type FetchOptions,\n HttpClient,\n type RequestConfigSchema,\n} from \"alepha/server\";\nimport { LinkProvider, type VirtualAction } from \"alepha/server/links\";\nimport { useEffect, useState } from \"react\";\nimport { useAlepha } from \"./useAlepha.ts\";\nimport { useInject } from \"./useInject.ts\";\n\nexport const useSchema = <TConfig extends RequestConfigSchema>(\n action: VirtualAction<TConfig>,\n): UseSchemaReturn<TConfig> => {\n const name = action.name;\n const alepha = useAlepha();\n const httpClient = useInject(HttpClient);\n const [schema, setSchema] = useState<UseSchemaReturn<TConfig>>(\n ssrSchemaLoading(alepha, name) as UseSchemaReturn<TConfig>,\n );\n\n useEffect(() => {\n if (!schema.loading) {\n return;\n }\n\n const opts: FetchOptions = {\n localCache: true,\n };\n\n httpClient\n .fetch(`${LinkProvider.path.apiLinks}/${name}/schema`, opts)\n .then((it) => setSchema(it.data as UseSchemaReturn<TConfig>));\n }, [name]);\n\n return schema;\n};\n\nexport type UseSchemaReturn<TConfig extends RequestConfigSchema> = TConfig & {\n loading: boolean;\n};\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * Get an action schema during server-side rendering (SSR) or client-side rendering (CSR).\n */\nexport const ssrSchemaLoading = (alepha: Alepha, name: string) => {\n // server-side rendering (SSR) context\n if (!alepha.isBrowser()) {\n // get user links\n const linkProvider = alepha.inject(LinkProvider);\n\n // check if user can access the link\n const can = linkProvider\n .getServerLinks()\n .find((link) => link.name === name);\n\n // yes!\n if (can) {\n // user-links have no schema, so we need to get it from the provider\n const schema = linkProvider.links.find((it) => it.name === name)?.schema;\n\n // oh, we have a schema!\n if (schema) {\n // attach to user link, it will be used in the client during hydration\n can.schema = schema;\n return schema;\n }\n }\n\n return { loading: true };\n }\n\n // browser side rendering (CSR) context\n // check if we have the schema already loaded\n const schema = alepha\n .inject(LinkProvider)\n .links.find((it) => it.name === name)?.schema;\n\n // yes!\n if (schema) {\n return schema;\n }\n\n // no, we need to load it\n return { loading: true };\n};\n","import { ReactRouter } from \"../services/ReactRouter.ts\";\nimport { useInject } from \"./useInject.ts\";\n\n/**\n * Use this hook to access the React Router instance.\n *\n * You can add a type parameter to specify the type of your application.\n * This will allow you to use the router in a typesafe way.\n *\n * @example\n * class App {\n * home = $page();\n * }\n *\n * const router = useRouter<App>();\n * router.go(\"home\"); // typesafe\n */\nexport const useRouter = <T extends object = any>(): ReactRouter<T> => {\n return useInject(ReactRouter<T>);\n};\n","import type { AnchorHTMLAttributes } from \"react\";\nimport { useRouter } from \"../hooks/useRouter.ts\";\n\nexport interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {\n href: string;\n}\n\nconst Link = (props: LinkProps) => {\n const router = useRouter();\n\n return (\n <a {...props} {...router.anchor(props.href)}>\n {props.children}\n </a>\n );\n};\n\nexport default Link;\n","import { useState } from \"react\";\nimport type { AnchorProps } from \"../providers/ReactPageProvider.ts\";\nimport { useRouter } from \"./useRouter.ts\";\nimport { useRouterState } from \"./useRouterState.ts\";\n\nexport interface UseActiveOptions {\n href: string;\n startWith?: boolean;\n}\n\nexport const useActive = (args: string | UseActiveOptions): UseActiveHook => {\n const router = useRouter();\n const [isPending, setPending] = useState(false);\n const state = useRouterState();\n const current = state.url.pathname;\n\n const options: UseActiveOptions =\n typeof args === \"string\" ? { href: args } : { ...args, href: args.href };\n const href = options.href;\n const isActive = router.isActive(href, options);\n\n return {\n isPending,\n isActive,\n anchorProps: {\n href: router.base(href),\n onClick: async (ev?: any) => {\n ev?.stopPropagation();\n ev?.preventDefault();\n if (isActive) return;\n if (isPending) return;\n\n setPending(true);\n try {\n await router.go(href);\n } finally {\n setPending(false);\n }\n },\n },\n };\n};\n\nexport interface UseActiveHook {\n isActive: boolean;\n anchorProps: AnchorProps;\n isPending: boolean;\n}\n","import type { Alepha, Static, TObject } from \"alepha\";\nimport { useEffect, useState } from \"react\";\nimport { useAlepha } from \"./useAlepha.ts\";\nimport { useRouter } from \"./useRouter.ts\";\n\n/**\n * Not well tested. Use with caution.\n */\nexport const useQueryParams = <T extends TObject>(\n schema: T,\n options: UseQueryParamsHookOptions = {},\n): [Partial<Static<T>>, (data: Static<T>) => void] => {\n const alepha = useAlepha();\n\n const key = options.key ?? \"q\";\n const router = useRouter();\n const querystring = router.query[key];\n\n const [queryParams = {}, setQueryParams] = useState<Static<T> | undefined>(\n decode(alepha, schema, router.query[key]),\n );\n\n useEffect(() => {\n setQueryParams(decode(alepha, schema, querystring));\n }, [querystring]);\n\n return [\n queryParams,\n (queryParams: Static<T>) => {\n setQueryParams(queryParams);\n router.setQueryParams((data) => {\n return { ...data, [key]: encode(alepha, schema, queryParams) };\n });\n },\n ];\n};\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface UseQueryParamsHookOptions {\n format?: \"base64\" | \"querystring\";\n key?: string;\n push?: boolean;\n}\n\nconst encode = (alepha: Alepha, schema: TObject, data: any) => {\n return btoa(JSON.stringify(alepha.codec.decode(schema, data)));\n};\n\nconst decode = <T extends TObject>(\n alepha: Alepha,\n schema: T,\n data: any,\n): Static<T> | undefined => {\n try {\n return alepha.codec.decode(\n schema,\n JSON.parse(atob(decodeURIComponent(data))),\n );\n } catch {\n return;\n }\n};\n","import { $module } from \"alepha\";\nimport { AlephaDateTime } from \"alepha/datetime\";\nimport { AlephaServer, type ServerRequest } from \"alepha/server\";\nimport { AlephaServerCache } from \"alepha/server/cache\";\nimport { AlephaServerLinks } from \"alepha/server/links\";\nimport type { ReactNode } from \"react\";\nimport { $page, type PageAnimation } from \"./primitives/$page.ts\";\nimport type { ReactHydrationState } from \"./providers/ReactBrowserProvider.ts\";\nimport {\n ReactPageProvider,\n type ReactRouterState,\n} from \"./providers/ReactPageProvider.ts\";\nimport { ReactServerProvider } from \"./providers/ReactServerProvider.ts\";\nimport { ReactPageServerService } from \"./services/ReactPageServerService.ts\";\nimport { ReactPageService } from \"./services/ReactPageService.ts\";\nimport { ReactRouter } from \"./services/ReactRouter.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport * from \"./index.shared.ts\";\nexport * from \"./index.shared-router.ts\";\nexport * from \"./providers/ReactBrowserProvider.ts\";\nexport * from \"./providers/ReactPageProvider.ts\";\nexport * from \"./providers/ReactServerProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\ndeclare module \"alepha\" {\n interface State {\n \"alepha.react.router.state\"?: ReactRouterState;\n }\n\n interface Hooks {\n /**\n * Fires when the React application is starting to be rendered on the server.\n */\n \"react:server:render:begin\": {\n request?: ServerRequest;\n state: ReactRouterState;\n };\n /**\n * Fires when the React application has been rendered on the server.\n */\n \"react:server:render:end\": {\n request?: ServerRequest;\n state: ReactRouterState;\n html: string;\n };\n // -----------------------------------------------------------------------------------------------------------------\n /**\n * Fires when the React application is being rendered on the browser.\n */\n \"react:browser:render\": {\n root: HTMLElement;\n element: ReactNode;\n state: ReactRouterState;\n hydration?: ReactHydrationState;\n };\n // -----------------------------------------------------------------------------------------------------------------\n // TOP LEVEL: All user actions (forms, transitions, custom actions)\n /**\n * Fires when a user action is starting.\n * Action can be a form submission, a route transition, or a custom action.\n */\n \"react:action:begin\": {\n type: string;\n id?: string;\n };\n /**\n * Fires when a user action has succeeded.\n * Action can be a form submission, a route transition, or a custom action.\n */\n \"react:action:success\": {\n type: string;\n id?: string;\n };\n /**\n * Fires when a user action has failed.\n * Action can be a form submission, a route transition, or a custom action.\n */\n \"react:action:error\": {\n type: string;\n id?: string;\n error: Error;\n };\n /**\n * Fires when a user action has completed, regardless of success or failure.\n * Action can be a form submission, a route transition, or a custom action.\n */\n \"react:action:end\": {\n type: string;\n id?: string;\n };\n // -----------------------------------------------------------------------------------------------------------------\n // SPECIFIC: Route transitions\n /**\n * Fires when a route transition is starting.\n */\n \"react:transition:begin\": {\n previous: ReactRouterState;\n state: ReactRouterState;\n animation?: PageAnimation;\n };\n /**\n * Fires when a route transition has succeeded.\n */\n \"react:transition:success\": {\n state: ReactRouterState;\n };\n /**\n * Fires when a route transition has failed.\n */\n \"react:transition:error\": {\n state: ReactRouterState;\n error: Error;\n };\n /**\n * Fires when a route transition has completed, regardless of success or failure.\n */\n \"react:transition:end\": {\n state: ReactRouterState;\n };\n }\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\n/**\n * Provides full-stack React development with declarative routing, server-side rendering, and client-side hydration.\n *\n * The React module enables building modern React applications using the `$page` primitive on class properties.\n * It delivers seamless server-side rendering, automatic code splitting, and client-side navigation with full\n * type safety and schema validation for route parameters and data.\n *\n * @see {@link $page}\n * @module alepha.react\n */\nexport const AlephaReact = $module({\n name: \"alepha.react\",\n primitives: [$page],\n services: [\n ReactServerProvider,\n ReactPageProvider,\n ReactRouter,\n ReactPageService,\n ReactPageServerService,\n ],\n register: (alepha) =>\n alepha\n .with(AlephaDateTime)\n .with(AlephaServer)\n .with(AlephaServerCache)\n .with(AlephaServerLinks)\n .with({\n provide: ReactPageService,\n use: ReactPageServerService,\n })\n .with(ReactServerProvider)\n .with(ReactPageProvider)\n .with(ReactRouter),\n});\n"],"mappings":";;;;;;;;;;;;;;;AAMA,IAAa,mBAAb,MAA8B;CAC5B,AAAO,MACL,UACA,UAAsC,EAAE,EAIvC;AACD,QAAM,IAAI,YAAY,+CAA+C;;CAGvE,AAAO,OACL,MACA,UAAsC,EAAE,EACJ;AACpC,QAAM,IAAI,YAAY,gDAAgD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACoF1E,MAAa,SAKX,YACiD;AACjD,QAAO,gBACL,eACA,QACD;;A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