{"version":3,"file":"generic.cjs","sources":["../../../lib/vowel/platforms/generic/index.ts"],"sourcesContent":["/**\n * Generic Controlled Navigation Platform Adapter\n * Works with any website that has a sitemap\n * \n * Features:\n * - Sitemap-based route discovery\n * - Cross-tab navigation control\n * - AI-powered DOM interaction\n * - Theme-agnostic element search\n * \n * @module @vowel.to/client/platforms/generic\n * \n * @example\n * ```ts\n * import { initializeControlledNavigation } from '@vowel.to/client/platforms/generic';\n * import { Vowel } from '@vowel.to/client';\n * \n * const { router, routes } = await initializeControlledNavigation({\n *   storeUrl: 'https://example.com'\n * });\n * \n * const vowel = new Vowel({\n *   appId: 'your-app-id',\n *   router,\n *   routes\n * });\n * ```\n */\n\n// Router\nexport { ControlledNavigationRouter } from './router';\nexport type { ControlledNavigationRouterOptions } from './router';\n\n// Routes\nexport { GenericRouteGenerator, GenericUrlCategorizer } from './routes';\nexport type { IUrlCategorizer } from './routes';\n\n// Sitemap\nexport { SitemapParser } from './sitemap';\nexport type { SitemapData, SitemapEntry, UrlEntry } from './sitemap';\n\n// Navigation listener for cross-tab communication\nexport { initializeNavigationListener } from './navigation-listener';\n\n// Automation listener for cross-tab DOM interaction\nexport { \n  initializeAutomationListener,\n  autoInitializeAutomationListener \n} from './automation-listener';\n\n// DOM Tools\nexport { FuzzyDOMSearcher } from './dom-search';\nexport type { \n  LevenshteinSearchOptions, \n  SearchResultElement, \n  DOMSearchResults \n} from './dom-search';\n\nexport { DOMManipulator } from './dom-tools';\n\n// Snapshot\nexport { snapshotForAI, generateAriaTree } from './snapshot';\nexport type { \n  AriaNode, \n  AriaSnapshot, \n  AriaTreeOptions \n} from './snapshot';\n\n// Types\nexport type { \n  ControlledNavigationOptions,\n  ControlledNavigationResult,\n  UrlCategory\n} from './types';\n\n// Import for helper function\nimport { ControlledNavigationRouter } from './router';\nimport { GenericRouteGenerator } from './routes';\nimport type { ControlledNavigationOptions, ControlledNavigationResult } from './types';\n\n/**\n * Helper function to initialize a complete controlled navigation setup\n * Sets up router, discovers routes from sitemap\n * Fault-tolerant: always returns valid routes, falling back to basic routes if discovery fails\n * \n * @param options - Configuration options\n * @returns Initialized router and routes\n * \n * @example\n * ```ts\n * import { initializeControlledNavigation } from '@vowel.to/client/platforms/generic';\n * import { Vowel } from '@vowel.to/client';\n * \n * const { router, routes } = await initializeControlledNavigation({\n *   storeUrl: 'https://example.com'\n * });\n * \n * const vowel = new Vowel({\n *   appId: 'your-app-id',\n *   router,\n *   routes\n * });\n * ```\n */\nexport async function initializeControlledNavigation(\n  options: ControlledNavigationOptions = {}\n): Promise<ControlledNavigationResult> {\n  const { storeUrl, useFallbackRoutes = false, channelName, config } = options;\n  \n  const router = new ControlledNavigationRouter({\n    channelName,\n    config\n  });\n  \n  const generator = new GenericRouteGenerator();\n\n  let routes;\n\n  try {\n    const baseUrl = storeUrl || (typeof window !== 'undefined' ? window.location.origin : '');\n    \n    if (useFallbackRoutes) {\n      console.log(\"📋 Using fallback routes (sitemap discovery disabled)\");\n      routes = generator['getFallbackRoutes'](); // Access protected method\n    } else {\n      console.log(\"🔍 Attempting to discover routes from sitemap...\");\n      routes = await generator.generateRoutes(baseUrl);\n      \n      if (routes.length === 0) {\n        console.warn(\"⚠️ No routes were discovered\");\n      } else {\n        console.log(`✅ Successfully loaded ${routes.length} routes`);\n      }\n    }\n  } catch (error) {\n    console.error(\"❌ Route generation failed completely:\", error);\n    // Provide a minimal set of routes as a last resort\n    routes = [{\n      path: \"/\",\n      description: \"Homepage\",\n      metadata: { type: \"home\", priority: \"highest\" },\n    }];\n  }\n\n  router.setRoutes(routes);\n\n  return {\n    router,\n    routes,\n  };\n}\n\n"],"names":["router","ControlledNavigationRouter","GenericRouteGenerator"],"mappings":";;;;;;;;AAwGA,eAAsB,8BAAA,CACpB,OAAA,GAAuC,EAAC,EACH;AACrC,EAAA,MAAM,EAAE,QAAA,EAAU,iBAAA,GAAoB,KAAA,EAAO,WAAA,EAAa,QAAO,GAAI,OAAA;AAErE,EAAA,MAAMA,QAAA,GAA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