import { Component, ComponentType, DependencyList, ErrorInfo, FC, ReactElement, ReactNode } from 'react'; import { StreamContextValue, StreamError, StreamEventHandler, StreamMetrics, StreamProviderProps } from './types'; /** * React context for streaming functionality. * @internal */ declare const StreamContext: import('react').Context; interface StreamErrorBoundaryProps { children: ReactNode; fallback?: ReactNode | ((error: StreamError, reset: () => void) => ReactNode); onError?: (error: StreamError) => void; } interface StreamErrorBoundaryState { hasError: boolean; error: StreamError | null; } /** * Error boundary specifically for stream-related errors. * * @description * Catches errors that occur during streaming and provides * graceful fallback rendering with recovery options. */ declare class StreamErrorBoundary extends Component { constructor(props: StreamErrorBoundaryProps); static getDerivedStateFromError(error: Error): StreamErrorBoundaryState; componentDidCatch(error: Error, errorInfo: ErrorInfo): void; render(): ReactNode; private handleReset; } /** * Detects if code is running in a server-side environment. */ declare function isServerEnvironment(): boolean; /** * Checks if the current environment supports streaming APIs. */ declare function isStreamingSupported(): boolean; /** * Provider component for the Dynamic HTML Streaming Engine. * * @description * StreamProvider initializes and manages the streaming engine, * providing context to child components for stream registration, * control, and monitoring. * * Features: * - Automatic engine lifecycle management * - Global error handling with error boundaries * - Metrics collection and reporting * - SSR-aware initialization * - Graceful degradation for unsupported environments * * @example * ```tsx * // Basic usage * * * * * // With configuration * errorReporter.capture(error)} * onMetricsUpdate={(metrics) => performanceMonitor.record(metrics)} * > * * * ``` */ export declare function StreamProvider({ children, config: configOverrides, debug, enableMetrics, onError, onMetricsUpdate, }: StreamProviderProps): ReactElement; /** * Hook to access the streaming context. * * @description * Provides access to all streaming functionality including * boundary registration, stream control, and metrics. * * @throws {Error} If used outside of a StreamProvider * * @example * ```tsx * function MyComponent() { * const stream = useStreamContext(); * * useEffect(() => { * stream.registerBoundary('my-content', { * priority: StreamPriority.High, * }); * * stream.startStream('my-content'); * * return () => stream.unregisterBoundary('my-content'); * }, [stream]); * * return
My streaming content
; * } * ``` */ export declare function useStreamContext(): StreamContextValue; /** * Hook to optionally access streaming context. * * @description * Similar to useStreamContext but returns null instead of * throwing if used outside a StreamProvider. Useful for * components that can work with or without streaming. * * @example * ```tsx * function OptionalStreamingComponent() { * const stream = useOptionalStreamContext(); * * if (!stream) { * return
Non-streaming fallback
; * } * * return
Streaming enabled!
; * } * ``` */ export declare function useOptionalStreamContext(): StreamContextValue | null; /** * Hook to check if streaming is available. * * @description * Returns a boolean indicating whether streaming features * are available in the current environment. * * @example * ```tsx * function StreamingFeature() { * const isAvailable = useStreamingAvailable(); * * if (!isAvailable) { * return ; * } * * return ; * } * ``` */ export declare function useStreamingAvailable(): boolean; /** * Hook to check if currently in SSR context. * * @description * Returns a boolean indicating whether the component * is currently rendering on the server. * * @example * ```tsx * function ServerAwareComponent() { * const isSSR = useIsSSR(); * * if (isSSR) { * return ; * } * * return ; * } * ``` */ export declare function useIsSSR(): boolean; /** * Hook to access current stream metrics. * * @description * Returns the current streaming metrics. The metrics are * updated reactively as streams progress. * * @example * ```tsx * function MetricsDashboard() { * const metrics = useStreamMetrics(); * * return ( *
*

Active streams: {metrics.activeStreams}

*

Total bytes: {metrics.totalBytesTransferred}

*

Buffer usage: {(metrics.bufferUtilization * 100).toFixed(1)}%

*
* ); * } * ``` */ export declare function useStreamMetrics(): StreamMetrics; /** * Hook to subscribe to stream events. * * @description * Subscribes to stream events and calls the handler * when events occur. Automatically unsubscribes on unmount. * * @param handler - Event handler function * @param deps - Dependencies array for the handler * * @example * ```tsx * function EventLogger() { * useStreamEvents((event) => { * console.log(`Stream event: ${event.type} for ${event.boundaryId}`); * }, []); * * return null; * } * ``` */ export declare function useStreamEvents(handler: StreamEventHandler, deps?: DependencyList): void; /** * Props injected by withStream HOC. */ export interface WithStreamProps { stream: StreamContextValue; } /** * Higher-order component for class components that need streaming access. * * @description * Wraps a class component and injects the stream context as a prop. * Prefer hooks for functional components. * * @example * ```tsx * interface MyComponentProps extends WithStreamProps { * title: string; * } * * class MyComponent extends Component { * componentDidMount() { * this.props.stream.registerBoundary('my-boundary', { * priority: StreamPriority.Normal, * }); * } * * render() { * return
{this.props.title}
; * } * } * * export default withStream(MyComponent); * ``` */ export declare function withStream

(WrappedComponent: ComponentType

): FC>; export { StreamContext, StreamErrorBoundary, isServerEnvironment, isStreamingSupported, };