{"version":3,"file":"create-router.mjs","sources":["../../../src/lib/routing/create-router.tsx"],"sourcesContent":["/**\n * @file Unified Router Factory\n * @description Creates type-safe router with auto-discovery, prefetching, and feature integration\n */\n\n/* eslint-disable react-refresh/only-export-components */\n\nimport {\n  createBrowserRouter,\n  type RouteObject,\n  useRouteError,\n  isRouteErrorResponse,\n} from 'react-router-dom';\nimport React, { Suspense, type ReactNode, type ComponentType } from 'react';\nimport type { CreateRouterOptions, RouteModule } from './types';\n\n// =============================================================================\n// Default Fallback Components\n// =============================================================================\n\n/**\n * Default loading spinner component\n */\nfunction DefaultLoading(): ReactNode {\n  return (\n    <div\n      style={{\n        display: 'flex',\n        alignItems: 'center',\n        justifyContent: 'center',\n        minHeight: '100vh',\n        backgroundColor: '#f9fafb',\n      }}\n    >\n      <div\n        style={{\n          width: '40px',\n          height: '40px',\n          border: '3px solid #e5e7eb',\n          borderTopColor: '#3b82f6',\n          borderRadius: '50%',\n          animation: 'spin 1s linear infinite',\n        }}\n      />\n      <style>{`\n        @keyframes spin {\n          to { transform: rotate(360deg); }\n        }\n      `}</style>\n    </div>\n  );\n}\n\n/**\n * Default error fallback component\n */\nfunction DefaultError(): ReactNode {\n  const error = useRouteError();\n\n  let errorMessage = 'An unexpected error occurred';\n  let errorStatus = 500;\n\n  if (isRouteErrorResponse(error)) {\n    const errorData = error.data as { message?: string } | undefined;\n    errorMessage = error.statusText ?? errorData?.message ?? errorMessage;\n    errorStatus = error.status;\n  } else if (error instanceof Error) {\n    errorMessage = error.message;\n  }\n\n  return (\n    <div\n      role=\"alert\"\n      style={{\n        display: 'flex',\n        flexDirection: 'column',\n        alignItems: 'center',\n        justifyContent: 'center',\n        minHeight: '50vh',\n        padding: '2rem',\n        textAlign: 'center',\n        backgroundColor: '#fef2f2',\n      }}\n    >\n      <div\n        style={{\n          width: '64px',\n          height: '64px',\n          marginBottom: '1.5rem',\n          borderRadius: '50%',\n          backgroundColor: '#fee2e2',\n          display: 'flex',\n          alignItems: 'center',\n          justifyContent: 'center',\n        }}\n      >\n        <svg\n          width=\"32\"\n          height=\"32\"\n          viewBox=\"0 0 24 24\"\n          fill=\"none\"\n          stroke=\"#dc2626\"\n          strokeWidth=\"2\"\n        >\n          <circle cx=\"12\" cy=\"12\" r=\"10\" />\n          <line x1=\"12\" y1=\"8\" x2=\"12\" y2=\"12\" />\n          <line x1=\"12\" y1=\"16\" x2=\"12.01\" y2=\"16\" />\n        </svg>\n      </div>\n      <h1\n        style={{\n          fontSize: '1.5rem',\n          fontWeight: 'bold',\n          color: '#dc2626',\n          marginBottom: '0.5rem',\n        }}\n      >\n        {errorStatus === 404 ? 'Page Not Found' : 'Something went wrong'}\n      </h1>\n      <p style={{ color: '#6b7280', marginBottom: '1.5rem', maxWidth: '400px' }}>{errorMessage}</p>\n      <div style={{ display: 'flex', gap: '0.75rem' }}>\n        <button\n          onClick={() => window.history.back()}\n          style={{\n            padding: '0.625rem 1.25rem',\n            backgroundColor: 'white',\n            color: '#374151',\n            border: '1px solid #d1d5db',\n            borderRadius: '0.375rem',\n            cursor: 'pointer',\n            fontSize: '0.875rem',\n            fontWeight: '500',\n          }}\n        >\n          Go Back\n        </button>\n        <button\n          onClick={() => (window.location.href = '/')}\n          style={{\n            padding: '0.625rem 1.25rem',\n            backgroundColor: '#3b82f6',\n            color: 'white',\n            border: 'none',\n            borderRadius: '0.375rem',\n            cursor: 'pointer',\n            fontSize: '0.875rem',\n            fontWeight: '500',\n          }}\n        >\n          Go Home\n        </button>\n      </div>\n    </div>\n  );\n}\n\n/**\n * Default 404 Not Found component\n */\nfunction DefaultNotFound(): ReactNode {\n  return (\n    <div\n      style={{\n        display: 'flex',\n        flexDirection: 'column',\n        alignItems: 'center',\n        justifyContent: 'center',\n        minHeight: '80vh',\n        padding: '2rem',\n        textAlign: 'center',\n      }}\n    >\n      <div\n        style={{\n          fontSize: '8rem',\n          fontWeight: 'bold',\n          color: '#e5e7eb',\n          lineHeight: 1,\n        }}\n      >\n        404\n      </div>\n      <h1\n        style={{\n          fontSize: '1.5rem',\n          fontWeight: 'bold',\n          color: '#111827',\n          marginTop: '1rem',\n        }}\n      >\n        Page not found\n      </h1>\n      <p style={{ color: '#6b7280', marginTop: '0.5rem', maxWidth: '400px' }}>\n        Sorry, we couldn&apos;t find the page you&apos;re looking for.\n      </p>\n      <button\n        onClick={() => (window.location.href = '/')}\n        style={{\n          marginTop: '1.5rem',\n          padding: '0.625rem 1.25rem',\n          backgroundColor: '#3b82f6',\n          color: 'white',\n          border: 'none',\n          borderRadius: '0.375rem',\n          cursor: 'pointer',\n          fontSize: '0.875rem',\n          fontWeight: '500',\n        }}\n      >\n        Go Home\n      </button>\n    </div>\n  );\n}\n\n// =============================================================================\n// Suspense Wrapper\n// =============================================================================\n\n/**\n * Wrap a lazy component with Suspense\n */\nfunction withSuspense(\n  Component: React.LazyExoticComponent<ComponentType<unknown>>,\n  fallback: ReactNode\n): ReactNode {\n  return (\n    <Suspense fallback={fallback}>\n      <Component />\n    </Suspense>\n  );\n}\n\n// =============================================================================\n// Prefetching\n// =============================================================================\n\ninterface PrefetchState {\n  prefetched: Set<string>;\n  timeouts: Map<string, ReturnType<typeof setTimeout>>;\n}\n\nconst prefetchState: PrefetchState = {\n  prefetched: new Set(),\n  timeouts: new Map(),\n};\n\n/**\n * Set up route prefetching on link hover/focus\n */\nfunction setupPrefetching(\n  preloadMap: Record<string, () => Promise<unknown>>,\n  options: {\n    delay: number;\n    onHover: boolean;\n    onFocus: boolean;\n  }\n): () => void {\n  const { delay, onHover, onFocus } = options;\n\n  function handleInteraction(event: Event): void {\n    const target = event.target as HTMLElement;\n    const link = target.closest('a[href]');\n\n    if (!link) return;\n\n    const href = link.getAttribute('href');\n    if (href == null || href === '' || href.startsWith('http') || href.startsWith('mailto:'))\n      return;\n\n    // Check if already prefetched\n    if (prefetchState.prefetched.has(href)) return;\n\n    // Find matching preload function\n    const routeKey = Object.keys(preloadMap).find((key) => {\n      // Simple path matching\n      const pattern = key\n        .replace(/BY_/g, ':')\n        .replace(/_OPT/g, '?')\n        .replace(/_/g, '/')\n        .toLowerCase();\n      return href === `/${pattern}` || href === pattern;\n    });\n\n    if (routeKey != null && routeKey !== '' && preloadMap[routeKey]) {\n      // Cancel any existing timeout\n      const existingTimeout = prefetchState.timeouts.get(href);\n      if (existingTimeout) {\n        clearTimeout(existingTimeout);\n      }\n\n      // Set up delayed prefetch\n      const timeout = setTimeout(() => {\n        const preloader = preloadMap[routeKey];\n        if (preloader) {\n          preloader()\n            .then(() => {\n              prefetchState.prefetched.add(href);\n            })\n            .catch(() => {\n              // Ignore prefetch errors\n            });\n        }\n      }, delay);\n\n      prefetchState.timeouts.set(href, timeout);\n    }\n  }\n\n  function handleLeave(event: Event): void {\n    const target = event.target as HTMLElement;\n    const link = target.closest('a[href]');\n\n    if (!link) return;\n\n    const href = link.getAttribute('href');\n    if (href === null || href === undefined || href === '') return;\n\n    // Cancel pending prefetch\n    const timeout = prefetchState.timeouts.get(href);\n    if (timeout) {\n      clearTimeout(timeout);\n      prefetchState.timeouts.delete(href);\n    }\n  }\n\n  // Add event listeners\n  if (onHover) {\n    document.addEventListener('mouseover', handleInteraction);\n    document.addEventListener('mouseout', handleLeave);\n  }\n\n  if (onFocus) {\n    document.addEventListener('focusin', handleInteraction);\n    document.addEventListener('focusout', handleLeave);\n  }\n\n  // Return cleanup function\n  return () => {\n    if (onHover) {\n      document.removeEventListener('mouseover', handleInteraction);\n      document.removeEventListener('mouseout', handleLeave);\n    }\n    if (onFocus) {\n      document.removeEventListener('focusin', handleInteraction);\n      document.removeEventListener('focusout', handleLeave);\n    }\n\n    // Clear all pending timeouts\n    for (const timeout of prefetchState.timeouts.values()) {\n      clearTimeout(timeout);\n    }\n    prefetchState.timeouts.clear();\n  };\n}\n\n// =============================================================================\n// Router Factory\n// =============================================================================\n\n/**\n * Route configuration for creating the router\n */\nexport interface RouteConfig {\n  /** Route path pattern */\n  path: string;\n  /** Dynamic import function for the route component */\n  importFn: () => Promise<RouteModule>;\n  /** Whether this is an index route */\n  index?: boolean;\n  /** Whether this is a layout route */\n  isLayout?: boolean;\n  /** Child routes */\n  children?: RouteConfig[];\n}\n\n/**\n * Create a router from route configurations\n */\nexport function createRouter(\n  routes: RouteConfig[],\n  options: CreateRouterOptions = {}\n): ReturnType<typeof createBrowserRouter> {\n  const {\n    errorElement,\n    loadingFallback = <DefaultLoading />,\n    basename,\n    prefetchOnHover = true,\n    prefetchOnFocus = false,\n    prefetchDelay = 100,\n  } = options;\n\n  // Build route objects\n  const routeObjects = buildRouteObjects(routes, {\n    errorElement: errorElement ?? <DefaultError />,\n    loadingFallback,\n  });\n\n  // Add catch-all 404 route\n  routeObjects.push({\n    path: '*',\n    element: <DefaultNotFound />,\n  });\n\n  // Create browser router\n  const router = createBrowserRouter(routeObjects, { basename });\n\n  // Set up prefetching if enabled\n  if ((prefetchOnHover || prefetchOnFocus) && typeof window !== 'undefined') {\n    const preloadMap = buildPreloadMap(routes);\n    setupPrefetching(preloadMap, {\n      delay: prefetchDelay,\n      onHover: prefetchOnHover,\n      onFocus: prefetchOnFocus,\n    });\n  }\n\n  return router;\n}\n\n/**\n * Build RouteObject array from route configurations\n */\nfunction buildRouteObjects(\n  routes: RouteConfig[],\n  options: {\n    errorElement: ReactNode;\n    loadingFallback: ReactNode;\n  }\n): RouteObject[] {\n  return routes.map((route) => {\n    const routeObj: RouteObject = {\n      errorElement: options.errorElement,\n    };\n\n    if (route.index === true) {\n      (routeObj as RouteObject & { index?: boolean }).index = true;\n    } else if (route.path !== undefined && route.path !== null) {\n      // Remove leading slash for nested routes\n      const cleanPath = route.path.replace(/^\\//, '');\n      routeObj.path = cleanPath || undefined;\n    }\n\n    // Use React Router's lazy loading\n    routeObj.lazy = async () => {\n      const module = await route.importFn();\n      return {\n        Component: module.default,\n        loader: module.loader,\n        action: module.action,\n        handle: module.handle,\n      };\n    };\n\n    // Build children recursively\n    if (route.children && route.children.length > 0) {\n      routeObj.children = buildRouteObjects(route.children, options);\n    }\n\n    return routeObj;\n  });\n}\n\n/**\n * Build preload map from route configurations\n */\nfunction buildPreloadMap(\n  routes: RouteConfig[],\n  prefix: string = ''\n): Record<string, () => Promise<unknown>> {\n  const preloadMap: Record<string, () => Promise<unknown>> = {};\n\n  for (const route of routes) {\n    const fullPath = prefix + (route.path || '');\n    const key = generatePreloadKey(fullPath);\n\n    preloadMap[key] = route.importFn;\n\n    if (route.children) {\n      const childMap = buildPreloadMap(route.children, `${fullPath}/`);\n      Object.assign(preloadMap, childMap);\n    }\n  }\n\n  return preloadMap;\n}\n\n/**\n * Generate a preload key from a path\n */\nfunction generatePreloadKey(path: string): string {\n  return (\n    path\n      .replace(/^\\//, '')\n      .replace(/\\//g, '_')\n      .replace(/:/g, 'BY_')\n      .replace(/\\?/g, '_OPT')\n      .toUpperCase() || 'INDEX'\n  );\n}\n\n// =============================================================================\n// Simple Router Factory (for manual route definition)\n// =============================================================================\n\n/**\n * Create a simple router from manual route definitions\n *\n * This is a simpler alternative to the full auto-discovery system\n * for projects that prefer explicit route configuration.\n */\nexport function createSimpleRouter(\n  routeTree: RouteObject[],\n  options: Omit<CreateRouterOptions, 'includeFeatures'> = {}\n): ReturnType<typeof createBrowserRouter> {\n  const { errorElement = <DefaultError />, basename } = options;\n\n  // Wrap routes with error element\n  const wrappedRoutes = routeTree.map((route) => ({\n    ...route,\n    errorElement: route.errorElement ?? errorElement,\n  }));\n\n  return createBrowserRouter(wrappedRoutes, { basename });\n}\n\n// =============================================================================\n// Exports\n// =============================================================================\n\nexport { DefaultLoading, DefaultError, DefaultNotFound, withSuspense, setupPrefetching };\n"],"names":["DefaultLoading","jsxs","jsx","DefaultError","error","useRouteError","errorMessage","errorStatus","isRouteErrorResponse","errorData","DefaultNotFound","withSuspense","Component","fallback","Suspense","prefetchState","setupPrefetching","preloadMap","options","delay","onHover","onFocus","handleInteraction","event","link","href","routeKey","key","pattern","existingTimeout","timeout","preloader","handleLeave","createRouter","routes","errorElement","loadingFallback","basename","prefetchOnHover","prefetchOnFocus","prefetchDelay","routeObjects","buildRouteObjects","router","createBrowserRouter","buildPreloadMap","route","routeObj","cleanPath","module","prefix","fullPath","generatePreloadKey","childMap","path","createSimpleRouter","routeTree","wrappedRoutes"],"mappings":";;;AAuBA,SAASA,IAA4B;AACnC,SACE,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,OAAO;AAAA,QACL,SAAS;AAAA,QACT,YAAY;AAAA,QACZ,gBAAgB;AAAA,QAChB,WAAW;AAAA,QACX,iBAAiB;AAAA,MAAA;AAAA,MAGnB,UAAA;AAAA,QAAA,gBAAAC;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,OAAO;AAAA,cACL,OAAO;AAAA,cACP,QAAQ;AAAA,cACR,QAAQ;AAAA,cACR,gBAAgB;AAAA,cAChB,cAAc;AAAA,cACd,WAAW;AAAA,YAAA;AAAA,UACb;AAAA,QAAA;AAAA,0BAED,SAAA,EAAO,UAAA;AAAA;AAAA;AAAA;AAAA,QAAA,CAIN;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGR;AAKA,SAASC,IAA0B;AACjC,QAAMC,IAAQC,EAAA;AAEd,MAAIC,IAAe,gCACfC,IAAc;AAElB,MAAIC,EAAqBJ,CAAK,GAAG;AAC/B,UAAMK,IAAYL,EAAM;AACxB,IAAAE,IAAeF,EAAM,cAAcK,GAAW,WAAWH,GACzDC,IAAcH,EAAM;AAAA,EACtB,MAAA,CAAWA,aAAiB,UAC1BE,IAAeF,EAAM;AAGvB,SACE,gBAAAH;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,MAAK;AAAA,MACL,OAAO;AAAA,QACL,SAAS;AAAA,QACT,eAAe;AAAA,QACf,YAAY;AAAA,QACZ,gBAAgB;AAAA,QAChB,WAAW;AAAA,QACX,SAAS;AAAA,QACT,WAAW;AAAA,QACX,iBAAiB;AAAA,MAAA;AAAA,MAGnB,UAAA;AAAA,QAAA,gBAAAC;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,OAAO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