{"version":3,"file":"index.mjs","sources":["../../../src/lib/hydration/index.ts"],"sourcesContent":["/**\n * @file Auto-Prioritized Hydration System\n * @description World-class hydration system for React applications.\n *\n * This module provides a complete solution for optimizing React hydration:\n *\n * ## Key Features\n *\n * - **Priority Queue System**: 5 levels (critical, high, normal, low, idle)\n * - **Visibility-Based Hydration**: Using IntersectionObserver\n * - **Interaction-Triggered Hydration**: Immediate hydration on user input\n * - **Idle-Time Background Hydration**: Using requestIdleCallback\n * - **Hydration Budget Management**: Never blocks main thread\n * - **Interaction Replay**: Captures and replays events during hydration\n * - **Progressive Hydration**: Partial hydration support\n * - **Performance Metrics**: Comprehensive telemetry\n *\n * ## Performance Targets\n *\n * - INP (Interaction to Next Paint): < 100ms\n * - TTI (Time to Interactive) reduction: 40%\n * - Zero main thread blocking during hydration\n *\n * ## Quick Start\n *\n * @example\n * ```tsx\n * // 1. Wrap your app with HydrationProvider\n * import { HydrationProvider } from '@/lib/hydration';\n *\n * function App() {\n *   return (\n *     <HydrationProvider config={{ debug: true }}>\n *       <YourApp />\n *     </HydrationProvider>\n *   );\n * }\n *\n * // 2. Wrap components with HydrationBoundary\n * import { HydrationBoundary } from '@/lib/hydration';\n *\n * function HeroSection() {\n *   return (\n *     <HydrationBoundary priority=\"critical\" trigger=\"immediate\" aboveTheFold>\n *       <ExpensiveHeroContent />\n *     </HydrationBoundary>\n *   );\n * }\n *\n * // 3. Use hooks to monitor and control hydration\n * import { useHydrationMetrics, useHydrationStatus } from '@/lib/hydration';\n *\n * function Dashboard() {\n *   const metrics = useHydrationMetrics();\n *   const heroStatus = useHydrationStatus('hero-section');\n *\n *   return (\n *     <div>\n *       <p>Progress: {metrics.hydrationProgress.toFixed(0)}%</p>\n *       <p>Hero status: {heroStatus.state}</p>\n *     </div>\n *   );\n * }\n * ```\n *\n * ## Architecture\n *\n * ```\n * HydrationProvider\n *     |\n *     +-- HydrationScheduler (singleton)\n *     |       |\n *     |       +-- PriorityQueue\n *     |       +-- IntersectionObserver\n *     |       +-- InteractionReplayManager\n *     |\n *     +-- HydrationBoundary (multiple)\n *             |\n *             +-- Status tracking\n *             +-- Placeholder rendering\n *             +-- Event capture\n * ```\n *\n * @module hydration\n */\n\n// ============================================================================\n// Types\n// ============================================================================\n\nexport {\n  // Priority types\n  type HydrationPriority,\n  type HydrationTrigger,\n  PRIORITY_WEIGHTS,\n\n  // State types\n  type HydrationState,\n  type HydrationStatus,\n  createInitialHydrationStatus,\n\n  // Task types\n  type HydrationBoundaryId,\n  type HydrationTask,\n  type HydrationTaskMetadata,\n  createBoundaryId,\n\n  // Configuration types\n  type HydrationBudget,\n  type VisibilityConfig,\n  type HydrationSchedulerConfig,\n  type InteractionStrategy,\n  DEFAULT_HYDRATION_BUDGET,\n  DEFAULT_VISIBILITY_CONFIG,\n  DEFAULT_SCHEDULER_CONFIG,\n\n  // Metrics types\n  type HydrationMetric,\n  type HydrationMetricsSnapshot,\n  type HydrationMetricsReporter,\n\n  // Interaction replay types\n  type ReplayableInteractionType,\n  type CapturedInteraction,\n  type InteractionReplayConfig,\n  DEFAULT_REPLAY_CONFIG,\n\n  // Component props types\n  type HydrationBoundaryProps,\n  type HydrationProviderProps,\n\n  // Context types\n  type HydrationContextValue,\n\n  // HOC types\n  type WithHydrationBoundaryOptions,\n\n  // Event types\n  type HydrationEventType,\n  type HydrationEvent,\n  type HydrationEventListener,\n\n  // Utility types\n  type PartialHydrationConfig,\n  mergeWithDefaults,\n  isHydrationPriority,\n  isHydrationTrigger,\n  isHydrationState,\n} from './types';\n\n// ============================================================================\n// Components\n// ============================================================================\n\nexport {\n  // Provider\n  HydrationProvider,\n  useHydrationContext,\n  useOptionalHydrationContext,\n  HydrationContext,\n} from './HydrationProvider';\n\nexport {\n  // Boundary\n  HydrationBoundary,\n  withHydrationBoundary,\n  LazyHydration,\n  type LazyHydrationProps,\n} from './HydrationBoundary';\n\n// ============================================================================\n// Hooks\n// ============================================================================\n\nexport {\n  // Core hook\n  useHydration,\n  useHasHydrationContext,\n  type UseHydrationReturn,\n  type UseHydrationOptions,\n\n  // Status tracking\n  useHydrationStatus,\n  useIsHydrated,\n  useWaitForHydration,\n  type UseHydrationStatusReturn,\n  type UseHydrationStatusOptions,\n\n  // Priority control\n  useHydrationPriority,\n  useAdaptiveHydrationPriority,\n  PRIORITY_ORDER,\n  PRIORITY_TO_LEVEL,\n  LEVEL_TO_PRIORITY,\n  type UseHydrationPriorityReturn,\n  type UseHydrationPriorityOptions,\n  type PriorityLevel,\n\n  // Deferred hydration\n  useDeferredHydration,\n  useSimpleDeferredHydration,\n  useIdleHydration,\n  type UseDeferredHydrationReturn,\n  type DeferredHydrationConfig,\n  type DeferredHydrationContainerProps,\n\n  // Metrics\n  useHydrationMetrics,\n  useHydrationMetricValue,\n  useHydrationProgress,\n  useIsHydrationComplete,\n  useTimeToFullHydration,\n  useHydrationMetricsDebug,\n  type UseHydrationMetricsReturn,\n  type UseHydrationMetricsOptions,\n} from './hooks';\n\n// ============================================================================\n// Scheduler\n// ============================================================================\n\nexport {\n  HydrationScheduler,\n  getHydrationScheduler,\n  resetHydrationScheduler,\n  type SchedulerState,\n} from './hydration-scheduler';\n\n// ============================================================================\n// Priority Queue\n// ============================================================================\n\nexport {\n  HydrationPriorityQueue,\n  createPriorityQueue,\n  createPriorityQueueFrom,\n  type PriorityQueueConfig,\n  type PriorityQueueStats,\n} from './priority-queue';\n\n// ============================================================================\n// Interaction Replay\n// ============================================================================\n\nexport {\n  InteractionReplayManager,\n  getInteractionReplayManager,\n  resetInteractionReplayManager,\n} from './interaction-replay';\n\n// ============================================================================\n// Convenience Initializer\n// ============================================================================\n\n/**\n * Initialize the hydration system with sensible defaults.\n * Call this once at app startup if not using HydrationProvider.\n *\n * @param config - Optional configuration overrides\n * @returns Cleanup function\n *\n * @example\n * ```tsx\n * // In main.tsx\n * import { initHydrationSystem } from '@/lib/hydration';\n *\n * const cleanup = initHydrationSystem({\n *   debug: import.meta.env.DEV,\n *   collectMetrics: true,\n * });\n *\n * // On app unmount\n * cleanup();\n * ```\n */\nimport { HydrationScheduler } from './hydration-scheduler';\n\nexport function initHydrationSystem(\n  config: Partial<import('./types').HydrationSchedulerConfig> = {}\n): () => void {\n  const scheduler = new HydrationScheduler(config);\n  scheduler.start();\n\n  return () => {\n    scheduler.dispose();\n    // Reset functionality removed - scheduler disposed inline\n  };\n}\n\n/**\n * Get the current hydration metrics.\n * Convenience function for accessing metrics without hooks.\n *\n * @returns Current metrics snapshot\n *\n * @example\n * ```tsx\n * const metrics = getHydrationMetrics();\n * console.log(`Hydrated: ${metrics.hydratedCount}/${metrics.totalBoundaries}`);\n * ```\n */\nexport function getHydrationMetrics(): import('./types').HydrationMetricsSnapshot {\n  try {\n    return {\n      totalBoundaries: 0,\n      hydratedCount: 0,\n      pendingCount: 0,\n      failedCount: 0,\n      averageHydrationDuration: 0,\n      p95HydrationDuration: 0,\n      totalReplayedInteractions: 0,\n      timeToFullHydration: 0,\n      timeToAboveFoldHydration: 0,\n      queueSize: 0,\n      timestamp: Date.now(),\n    };\n  } catch {\n    return {\n      totalBoundaries: 0,\n      hydratedCount: 0,\n      pendingCount: 0,\n      failedCount: 0,\n      averageHydrationDuration: 0,\n      p95HydrationDuration: 0,\n      totalReplayedInteractions: 0,\n      timeToFullHydration: null,\n      timeToAboveFoldHydration: null,\n      queueSize: 0,\n      timestamp: Date.now(),\n    };\n  }\n}\n"],"names":["initHydrationSystem","config","scheduler","HydrationScheduler","getHydrationMetrics"],"mappings":";;;;;;;;;;;;AAqRO,SAASA,EACdC,IAA8D,IAClD;AACZ,QAAMC,IAAY,IAAIC,EAAmBF,CAAM;AAC/C,SAAAC,EAAU,MAAA,GAEH,MAAM;AACX,IAAAA,EAAU,QAAA;AAAA,EAEZ;AACF;AAcO,SAASE,IAAkE;AAChF,MAAI;AACF,WAAO;AAAA,MACL,iBAAiB;AAAA,MACjB,eAAe;AAAA,MACf,cAAc;AAAA,MACd,aAAa;AAAA,MACb,0BAA0B;AAAA,MAC1B,sBAAsB;AAAA,MACtB,2BAA2B;AAAA,MAC3B,qBAAqB;AAAA,MACrB,0BAA0B;AAAA,MAC1B,WAAW;AAAA,MACX,WAAW,KAAK,IAAA;AAAA,IAAI;AAAA,EAExB,QAAQ;AACN,WAAO;AAAA,MACL,iBAAiB;AAAA,MACjB,eAAe;AAAA,MACf,cAAc;AAAA,MACd,aAAa;AAAA,MACb,0BAA0B;AAAA,MAC1B,sBAAsB;AAAA,MACtB,2BAA2B;AAAA,MAC3B,qBAAqB;AAAA,MACrB,0BAA0B;AAAA,MAC1B,WAAW;AAAA,MACX,WAAW,KAAK,IAAA;AAAA,IAAI;AAAA,EAExB;AACF;"}