import { RefObject } from 'react'; import { HydrationPriority, HydrationBoundaryId } from '../types'; /** * Priority level as a numeric value (0 = highest, 4 = lowest). */ export type PriorityLevel = 0 | 1 | 2 | 3 | 4; /** * Return type for the useHydrationPriority hook. */ export interface UseHydrationPriorityReturn { /** * Current priority level as a string. */ readonly priority: HydrationPriority; /** * Current priority as a numeric value (0 = highest, 4 = lowest). */ readonly priorityLevel: PriorityLevel; /** * Sets the priority to a specific level. * * @param priority - New priority level */ readonly setPriority: (priority: HydrationPriority) => void; /** * Increases priority by one level (towards critical). * No-op if already at critical priority. */ readonly boost: () => void; /** * Decreases priority by one level (towards idle). * No-op if already at idle priority. */ readonly reduce: () => void; /** * Sets priority to critical (highest). */ readonly makeCritical: () => void; /** * Sets priority to idle (lowest). */ readonly makeIdle: () => void; /** * Resets priority to the original/default level. */ readonly reset: () => void; /** * The original priority before any changes. */ readonly originalPriority: HydrationPriority; } /** * Options for the useHydrationPriority hook. */ export interface UseHydrationPriorityOptions { /** * Initial priority level if boundary is not yet registered. * * @default 'normal' */ readonly defaultPriority?: HydrationPriority; /** * Whether to persist priority changes across renders. * * @default true */ readonly persist?: boolean; } /** * Priority levels ordered from highest to lowest. */ declare const PRIORITY_ORDER: readonly HydrationPriority[]; /** * Maps priority strings to numeric levels. */ declare const PRIORITY_TO_LEVEL: Record; /** * Maps numeric levels to priority strings. */ declare const LEVEL_TO_PRIORITY: Record; /** * Hook for dynamically controlling hydration priority. * * Enables runtime adjustment of hydration priorities based on * user behavior or application state. * * @param boundaryId - ID of the boundary to control * @param options - Hook options * @returns Priority control interface * * @example * ```tsx * // Basic priority control * function PriorityControls({ boundaryId }: { boundaryId: string }) { * const { priority, boost, reduce, makeCritical, makeIdle } = useHydrationPriority(boundaryId); * * return ( *
* Priority: {priority} * * * * *
* ); * } * * // Automatic priority based on visibility * function VisibilityAwarePriority({ boundaryId }: { boundaryId: string }) { * const containerRef = useRef(null); * const { setPriority } = useHydrationPriority(boundaryId); * * useEffect(() => { * const observer = new IntersectionObserver( * ([entry]) => { * if (entry.isIntersecting) { * setPriority(entry.intersectionRatio > 0.5 ? 'high' : 'normal'); * } else { * setPriority('low'); * } * }, * { threshold: [0, 0.5, 1] } * ); * * if (containerRef.current) { * observer.observe(containerRef.current); * } * * return () => observer.disconnect(); * }, [setPriority]); * * return
...
; * } * ``` */ export declare function useHydrationPriority(boundaryId: string | HydrationBoundaryId, options?: UseHydrationPriorityOptions): UseHydrationPriorityReturn; /** * Hook for adaptive priority based on user engagement signals. * * Automatically adjusts priority based on: * - Hover: Boosts priority * - Focus: Boosts priority * - Visibility: Adjusts based on viewport intersection * * @param boundaryId - ID of the boundary to control * @param elementRef - React ref to the element to observe * @returns Priority control interface * * @example * ```tsx * function AdaptiveComponent({ boundaryId }: { boundaryId: string }) { * const containerRef = useRef(null); * const { priority } = useAdaptiveHydrationPriority(boundaryId, containerRef); * * return ( *
* Auto-adjusted priority: {priority} *
* ); * } * ``` */ export declare function useAdaptiveHydrationPriority(boundaryId: string | HydrationBoundaryId, elementRef: RefObject): UseHydrationPriorityReturn; export { PRIORITY_ORDER, PRIORITY_TO_LEVEL, LEVEL_TO_PRIORITY };