{"version":3,"file":"index.mjs","sources":["../../../../src/lib/performance/hooks/index.ts"],"sourcesContent":["/**\n * @file Performance Hooks Barrel Export\n * @description Centralized exports for all performance-related React hooks.\n *\n * This module provides a comprehensive set of hooks for monitoring and optimizing\n * React application performance, including:\n *\n * - Budget awareness and enforcement\n * - Render metrics and optimization\n * - Long task detection\n * - Memory pressure monitoring\n * - Network quality adaptation\n *\n * @example\n * ```typescript\n * import {\n *   usePerformanceBudget,\n *   useRenderMetrics,\n *   useLongTaskDetector,\n *   useMemoryPressure,\n *   useNetworkQuality,\n * } from '@/lib/performance/hooks';\n * ```\n */\n\n// ============================================================================\n// Performance Budget Hooks\n// ============================================================================\n\nexport {\n  usePerformanceBudget,\n  useBudgetStatus,\n  useDegradedMode,\n  useBudgetConditional,\n  type UsePerformanceBudgetOptions,\n  type UsePerformanceBudgetReturn,\n  type BudgetStatus,\n} from './usePerformanceBudget';\n\n// ============================================================================\n// Render Metrics Hooks\n// ============================================================================\n\nexport {\n  useRenderMetrics,\n  useRenderPhaseMetrics,\n  useRenderProfiler,\n  useWastedRenderDetector,\n  type UseRenderMetricsOptions,\n  type UseRenderMetricsReturn,\n  type RenderMetrics,\n} from './useRenderMetrics';\n\n// ============================================================================\n// Long Task Detection Hooks\n// ============================================================================\n\nexport {\n  useLongTaskDetector,\n  useDeferredRender,\n  useBlockingTimeTracker,\n  useYieldToMain,\n  type UseLongTaskDetectorOptions,\n  type UseLongTaskDetectorReturn,\n  type LongTaskStats,\n} from './useLongTaskDetector';\n\n// ============================================================================\n// Memory Pressure Hooks\n// ============================================================================\n\nexport {\n  useMemoryPressure,\n  useMemoryCleanup,\n  useMemoryAwareCache,\n  useComponentMemoryImpact,\n  type UseMemoryPressureOptions,\n  type UseMemoryPressureReturn,\n  type MemoryPressureLevel,\n  type MemorySnapshot,\n  type MemoryTrend,\n} from './useMemoryPressure';\n\n// ============================================================================\n// Network Quality Hooks\n// ============================================================================\n\nexport {\n  useNetworkQuality,\n  useAdaptiveImageQuality,\n  useNetworkConditional,\n  useNetworkAwareLazyLoad,\n  useRequestPerformance,\n  useNetworkStatusIndicator,\n  usePreconnect,\n  type UseNetworkQualityOptions,\n  type UseNetworkQualityReturn,\n  type AdaptiveLoadingStrategy,\n} from './useNetworkQuality';\n\n// ============================================================================\n// Composite Hooks\n// ============================================================================\n\n/**\n * Combined performance awareness hook\n *\n * Provides a unified interface for all performance metrics, useful for\n * components that need comprehensive performance awareness.\n *\n * @example\n * ```tsx\n * function PerformanceAwareComponent() {\n *   const perf = usePerformanceAwareness();\n *\n *   if (perf.shouldReduceComplexity) {\n *     return <SimplifiedVersion />;\n *   }\n *\n *   return <FullVersion />;\n * }\n * ```\n */\nexport function usePerformanceAwareness(): {\n  /** Should reduce rendering complexity */\n  shouldReduceComplexity: boolean;\n  /** Should defer non-critical work */\n  shouldDefer: boolean;\n  /** Is system under pressure */\n  isUnderPressure: boolean;\n  /** Overall health score (0-100) */\n  healthScore: number;\n  /** Current constraints */\n  constraints: {\n    memory: 'normal' | 'warning' | 'critical';\n    network: 'fast' | 'moderate' | 'slow';\n    mainThread: 'free' | 'busy' | 'blocked';\n  };\n} {\n  const { pressure: memoryPressure, shouldReduceMemory } = useMemoryPressure();\n  const { isBlocked, isHighBlocking } = useLongTaskDetector();\n  const { isSlowConnection, score: networkScore } = useNetworkQuality();\n  const { hasViolations, healthScore: budgetHealth } = usePerformanceBudget();\n\n  const shouldReduceComplexity =\n    shouldReduceMemory || isHighBlocking || isSlowConnection || hasViolations;\n\n  const shouldDefer = isBlocked || memoryPressure === 'critical';\n\n  const isUnderPressure = memoryPressure !== 'normal' || isHighBlocking || hasViolations;\n\n  let memoryScore = 0;\n  if (memoryPressure === 'normal') {\n    memoryScore = 100;\n  } else if (memoryPressure === 'warning') {\n    memoryScore = 50;\n  }\n  const healthScore = Math.round((budgetHealth + networkScore + memoryScore) / 3);\n\n  const memoryConstraint = memoryPressure;\n  let networkConstraint: 'fast' | 'moderate' | 'slow';\n  if (networkScore >= 70) {\n    networkConstraint = 'fast';\n  } else if (networkScore >= 40) {\n    networkConstraint = 'moderate';\n  } else {\n    networkConstraint = 'slow';\n  }\n  let mainThreadConstraint: 'free' | 'busy' | 'blocked';\n  if (isBlocked) {\n    mainThreadConstraint = 'blocked';\n  } else if (isHighBlocking) {\n    mainThreadConstraint = 'busy';\n  } else {\n    mainThreadConstraint = 'free';\n  }\n\n  return {\n    shouldReduceComplexity,\n    shouldDefer,\n    isUnderPressure,\n    healthScore,\n    constraints: {\n      memory: memoryConstraint,\n      network: networkConstraint,\n      mainThread: mainThreadConstraint,\n    },\n  };\n}\n\n/**\n * Hook for adaptive component rendering\n *\n * Returns the appropriate version of content based on current performance constraints.\n *\n * @example\n * ```tsx\n * function AdaptiveList({ items }) {\n *   const renderItem = useAdaptiveRender(\n *     (item) => <RichListItem item={item} />,      // Full\n *     (item) => <SimpleListItem item={item} />,   // Reduced\n *     (item) => <SkeletonItem />                  // Minimal\n *   );\n *\n *   return items.map(renderItem);\n * }\n * ```\n */\nexport function useAdaptiveRender<T, R>(\n  fullRender: (item: T) => R,\n  reducedRender: (item: T) => R,\n  minimalRender: (item: T) => R\n): (item: T) => R {\n  const { constraints } = usePerformanceAwareness();\n\n  if (\n    constraints.memory === 'critical' ||\n    constraints.mainThread === 'blocked' ||\n    constraints.network === 'slow'\n  ) {\n    return minimalRender;\n  }\n\n  if (\n    constraints.memory === 'warning' ||\n    constraints.mainThread === 'busy' ||\n    constraints.network === 'moderate'\n  ) {\n    return reducedRender;\n  }\n\n  return fullRender;\n}\n\n// ============================================================================\n// Optimized Performance Hooks (Agent 7 PhD-Level Additions)\n// ============================================================================\n\nexport {\n  // Hooks\n  useOptimizedRender,\n  useLazyFeature,\n  useProgressiveLoad,\n  // Utilities\n  clearFeatureCache,\n  preloadFeature,\n  // Types\n  type RenderPriority,\n  type LazyFeatureStatus,\n  type ProgressiveLoadPhase,\n  type NetworkQuality as ProgressiveNetworkQuality,\n  type UseOptimizedRenderOptions,\n  type UseOptimizedRenderReturn,\n  type UseLazyFeatureOptions,\n  type UseLazyFeatureReturn,\n  type UseProgressiveLoadOptions,\n  type UseProgressiveLoadReturn,\n} from './useOptimizedHooks';\n\n// Import hooks for composite hook implementation\nimport { useMemoryPressure } from './useMemoryPressure';\nimport { useLongTaskDetector } from './useLongTaskDetector';\nimport { useNetworkQuality } from './useNetworkQuality';\nimport { usePerformanceBudget } from './usePerformanceBudget';\n"],"names":["usePerformanceAwareness","memoryPressure","shouldReduceMemory","useMemoryPressure","isBlocked","isHighBlocking","useLongTaskDetector","isSlowConnection","networkScore","useNetworkQuality","hasViolations","budgetHealth","usePerformanceBudget","shouldReduceComplexity","shouldDefer","isUnderPressure","memoryScore","healthScore","memoryConstraint","networkConstraint","mainThreadConstraint","useAdaptiveRender","fullRender","reducedRender","minimalRender","constraints"],"mappings":";;;;;;;;AA2HO,SAASA,IAed;AACA,QAAM,EAAE,UAAUC,GAAgB,oBAAAC,EAAA,IAAuBC,EAAAA,GACnD,EAAE,WAAAC,GAAW,gBAAAC,EAAA,IAAmBC,EAAAA,GAChC,EAAE,kBAAAC,GAAkB,OAAOC,EAAA,IAAiBC,EAAAA,GAC5C,EAAE,eAAAC,GAAe,aAAaC,EAAA,IAAiBC,EAAAA,GAE/CC,IACJX,KAAsBG,KAAkBE,KAAoBG,GAExDI,IAAcV,KAAaH,MAAmB,YAE9Cc,IAAkBd,MAAmB,YAAYI,KAAkBK;AAEzE,MAAIM,IAAc;AAClB,EAAIf,MAAmB,WACrBe,IAAc,MACLf,MAAmB,cAC5Be,IAAc;AAEhB,QAAMC,IAAc,KAAK,OAAON,IAAeH,IAAeQ,KAAe,CAAC,GAExEE,IAAmBjB;AACzB,MAAIkB;AACJ,EAAIX,KAAgB,KAClBW,IAAoB,SACXX,KAAgB,KACzBW,IAAoB,aAEpBA,IAAoB;AAEtB,MAAIC;AACJ,SAAIhB,IACFgB,IAAuB,YACdf,IACTe,IAAuB,SAEvBA,IAAuB,QAGlB;AAAA,IACL,wBAAAP;AAAA,IACA,aAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,aAAAE;AAAA,IACA,aAAa;AAAA,MACX,QAAQC;AAAA,MACR,SAASC;AAAA,MACT,YAAYC;AAAA,IAAA;AAAA,EACd;AAEJ;AAoBO,SAASC,EACdC,GACAC,GACAC,GACgB;AAChB,QAAM,EAAE,aAAAC,EAAA,IAAgBzB,EAAA;AAExB,SACEyB,EAAY,WAAW,cACvBA,EAAY,eAAe,aAC3BA,EAAY,YAAY,SAEjBD,IAIPC,EAAY,WAAW,aACvBA,EAAY,eAAe,UAC3BA,EAAY,YAAY,aAEjBF,IAGFD;AACT;"}