export type SystemValue = 'connectivity' | 'quality' | 'battery' | 'device' | 'cpu' | 'gpu' | 'performance' | 'resource' | 'paint' | 'navigation' | 'layout-shift' | 'lcp' | 'longtask' | 'memory-usage' | 'fps' | 'window' | 'screen'; export type MemoryFormat = 'bytes' | 'KB' | 'MB' | 'GB'; export type MemoryHumanData = { used: number; total: number; limit: number; }; export type MemoryUsage = { /** * - The amount of memory currently being used by the JS heap in bytes. */ usedJSHeapSize: number; /** * - The total amount of memory currently allocated for the JS heap in bytes. */ totalJSHeapSize: number; /** * - The maximum amount of memory that can be allocated for the JS heap in bytes. */ jsHeapSizeLimit: number; /** * - Indicates if the Memory API is available. */ enabled: boolean; }; export type MonitorOptions = { /** * - Maximum number of resource metrics to store. Use -1 for infinite. */ resourceLimit?: number; /** * - List of systems to enable. If empty, all are enabled. */ systems?: SystemValue[]; /** * - Interval in milliseconds for memory polling. */ memoryIntervalMs?: number; /** * - Interval in miliseconds for fps polling. */ fpsIntervalMs?: number; }; export type ConnectivityStatus = { /** * - Indicates if the browser is currently connected to a network. */ isOnline: boolean; }; export type ConnectionQuality = { /** * - Effective bandwidth estimate in Mbps. */ downlink: number; /** * - Estimated round-trip time in ms. */ rtt: number; /** * - Effective connection type (e.g., '4g'). */ effectiveType: string; /** * - Whether the user has enabled data saver mode. */ saveData: boolean; /** * - Indicates whether the Network Information API is available. */ enabled: boolean; }; export type BatteryStatus = { /** * - Battery charge level (0 to 1). */ level: number; /** * - Whether the device is currently charging. */ charging: boolean; /** * - Time until full charge in seconds. */ chargingTime: number; /** * - Time until empty in seconds. */ dischargingTime: number; /** * - Indicates if the Battery Status API is available. */ enabled: boolean; }; export type GPUInfo = { /** * - The GPU manufacturer. */ vendor: string; /** * - The specific GPU model name. */ renderer: string; }; export type CPUInfo = { /** * - The number of logical processing cores. */ logicalCores: number; }; export type DeviceMetrics = { /** * - Approximate amount of device memory in GB. */ memory: number; /** * - CPU-related metrics. */ cpu: CPUInfo; /** * - GPU-related metrics. */ gpu: GPUInfo; /** * - Indicates if the requested device information was successfully retrieved. */ enabled: boolean; }; export type ResourceMetric = { /** * - The URL of the resource. */ name: string; /** * - Time taken to load the resource in ms. */ duration: number; /** * - The type of performance entry (e.g., 'resource'). */ entryType: string; }; export type PaintMetrics = { /** * - Time when the first pixel was painted. */ firstPaint: number; /** * - Time when the first content was painted. */ firstContentfulPaint: number; }; export type NavigationMetrics = { /** * - Time to first byte in ms. */ ttfb: number; /** * - Time until DOMContentLoaded in ms. */ domContentLoaded: number; /** * - Time until load event in ms. */ loadEvent: number; }; export type FrameRateMetrics = { /** * - The current frames per second. */ fps: number; /** * - The timestamp of the last measurement. */ timestamp: number; }; export type PerformanceMetrics = { /** * - Paint timing metrics. */ paint: PaintMetrics; /** * - Navigation timing metrics. */ navigation: NavigationMetrics | null; /** * - Cumulative Layout Shift (CLS) value. */ layoutShift: number; /** * - Largest Contentful Paint (LCP) value in ms. */ lcp: number; /** * - Array of durations of long tasks in ms. */ longTasks: number[]; /** * - Current frame rate metrics. */ fps: Readonly; }; export type WindowMetrics = { /** * - The width of the viewport in pixels. */ width: number; /** * - The height of the viewport in pixels. */ height: number; /** * - The device pixel ratio. */ devicePixelRatio: number; }; export type ScreenMetrics = { /** * - The screen width in pixels. */ width: number; /** * - The screen height in pixels. */ height: number; /** * - The available screen width in pixels (excluding OS taskbars). */ availWidth: number; /** * - The available screen height in pixels (excluding OS taskbars). */ availHeight: number; /** * - The color depth of the screen in bits. */ colorDepth: number; /** * - The pixel depth of the screen in bits. */ pixelDepth: number; /** * - The orientation of the screen (e.g., 'landscape-primary'). */ orientation: string; }; export type NetworkEvent = { /** * - Current online/offline status. */ connectivity: Readonly; /** * - Current network quality metrics. */ quality: Readonly; /** * - Current battery status. */ battery: Readonly; /** * - Current device hardware metrics. */ device: Readonly; /** * - Comprehensive performance metrics. */ performance: Readonly; /** * - Recent resource loading metrics. */ resources: Readonly; /** * - Current JavaScript heap memory metrics. */ memoryUsage: Readonly; /** * - Current viewport dimensions. */ windowMetrics: Readonly; /** * - Current screen/monitor properties. */ screenMetrics: Readonly; event?: Event; }; export type NetworkCallback = (data: NetworkEvent) => void; export type TinyBrowserMonitorEvents = { /** * - Emitted when the window is resized. */ WindowResize: (metrics: Readonly) => void; /** * - Emitted with the latest FPS sample. */ FPS: (metrics: Readonly) => void; /** * - Emitted when the battery status changes. */ BatteryUpdated: (status: Readonly) => void; /** * - Emitted when the memory usage is sampled. */ MemoryUsage: (usage: Readonly) => void; /** * - Emitted when a resource is added. */ ResourceAdded: (oldItem: ResourceMetric | undefined, newItem: ResourceMetric) => void; /** * - Emitted when a resource is removed. */ ResourceDeleted: (oldItem: ResourceMetric | undefined, newItem: ResourceMetric) => void; /** * - Emitted when a resource is edited. */ ResourceEdited: (oldItem: ResourceMetric | undefined, newItem: ResourceMetric) => void; /** * - Emitted when paint metrics change. */ PaintUpdated: (paint: Readonly) => void; /** * - Emitted when navigation metrics change. */ NavigationUpdated: (navigation: Partial) => void; /** * - Emitted when the layout shift changes. */ LayoutShiftUpdated: (data: { layoutShift: number; }) => void; /** * - Emitted when the LCP value changes. */ LcpUpdated: (data: { lcp: number; }) => void; /** * - Emitted when long tasks are recorded. */ LongTaskUpdated: (data: { lcp: number[]; }) => void; /** * - Emitted when connectivity changes. */ ConnectivityUpdated: (status: Readonly) => void; /** * - Emitted with the full network report. */ NetworkUpdated: (data: NetworkEvent) => void; /** * - Emitted when the monitor is destroyed. */ Destroyed: () => void; }; /** * Defines the valid identifiers for the various monitoring systems available. * @typedef {'connectivity'|'quality'|'battery'|'device'|'cpu'|'gpu'|'performance'|'resource'|'paint'|'navigation'|'layout-shift'|'lcp'|'longtask'|'memory-usage'|'fps'|'window'|'screen'} SystemValue */ /** * Represents the valid units for memory formatting. * @typedef {'bytes'|'KB'|'MB'|'GB'} MemoryFormat */ /** * Represents memory usage data formatted into human-readable units. * @typedef {{ used: number; total: number; limit: number; }} MemoryHumanData */ /** * Represents the JavaScript heap memory usage. * @typedef {Object} MemoryUsage * @property {number} usedJSHeapSize - The amount of memory currently being used by the JS heap in bytes. * @property {number} totalJSHeapSize - The total amount of memory currently allocated for the JS heap in bytes. * @property {number} jsHeapSizeLimit - The maximum amount of memory that can be allocated for the JS heap in bytes. * @property {boolean} enabled - Indicates if the Memory API is available. */ /** * Configuration options used to initialize the TinyBrowserMonitor instance. * @typedef {Object} MonitorOptions * @property {number} [resourceLimit=1000] - Maximum number of resource metrics to store. Use -1 for infinite. * @property {SystemValue[]} [systems] - List of systems to enable. If empty, all are enabled. * @property {number} [memoryIntervalMs=100] - Interval in milliseconds for memory polling. * @property {number} [fpsIntervalMs=1000] - Interval in miliseconds for fps polling. */ /** * Represents the current connectivity status of the network connection. * @typedef {Object} ConnectivityStatus * @property {boolean} isOnline - Indicates if the browser is currently connected to a network. */ /** * Represents the qualitative metrics of the current network connection. * @typedef {Object} ConnectionQuality * @property {number} downlink - Effective bandwidth estimate in Mbps. * @property {number} rtt - Estimated round-trip time in ms. * @property {string} effectiveType - Effective connection type (e.g., '4g'). * @property {boolean} saveData - Whether the user has enabled data saver mode. * @property {boolean} enabled - Indicates whether the Network Information API is available. */ /** * Represents the current state and availability of the device's battery information. * @typedef {Object} BatteryStatus * @property {number} level - Battery charge level (0 to 1). * @property {boolean} charging - Whether the device is currently charging. * @property {number} chargingTime - Time until full charge in seconds. * @property {number} dischargingTime - Time until empty in seconds. * @property {boolean} enabled - Indicates if the Battery Status API is available. */ /** * Represents the hardware-specific metrics of the user's device. * @typedef {Object} GPUInfo * @property {string} vendor - The GPU manufacturer. * @property {string} renderer - The specific GPU model name. */ /** * Represents the CPU-related metrics of the user's device. * @typedef {Object} CPUInfo * @property {number} logicalCores - The number of logical processing cores. */ /** * Represents the hardware-specific metrics of the user's device. * @typedef {Object} DeviceMetrics * @property {number} memory - Approximate amount of device memory in GB. * @property {CPUInfo} cpu - CPU-related metrics. * @property {GPUInfo} gpu - GPU-related metrics. * @property {boolean} enabled - Indicates if the requested device information was successfully retrieved. */ /** * Represents the performance metrics of a single loaded resource. * @typedef {Object} ResourceMetric * @property {string} name - The URL of the resource. * @property {number} duration - Time taken to load the resource in ms. * @property {string} entryType - The type of performance entry (e.g., 'resource'). */ /** * Represents the timing data related to browser paint events. * @typedef {Object} PaintMetrics * @property {number} firstPaint - Time when the first pixel was painted. * @property {number} firstContentfulPaint - Time when the first content was painted. */ /** * Represents the performance timing metrics related to page navigation. * @typedef {Object} NavigationMetrics * @property {number} ttfb - Time to first byte in ms. * @property {number} domContentLoaded - Time until DOMContentLoaded in ms. * @property {number} loadEvent - Time until load event in ms. */ /** * Represents the rendering performance in frames per second. * @typedef {Object} FrameRateMetrics * @property {number} fps - The current frames per second. * @property {number} timestamp - The timestamp of the last measurement. */ /** * Aggregates various performance and timing metrics into a single object. * @typedef {Object} PerformanceMetrics * @property {PaintMetrics} paint - Paint timing metrics. * @property {NavigationMetrics|null} navigation - Navigation timing metrics. * @property {number} layoutShift - Cumulative Layout Shift (CLS) value. * @property {number} lcp - Largest Contentful Paint (LCP) value in ms. * @property {number[]} longTasks - Array of durations of long tasks in ms. * @property {Readonly} fps - Current frame rate metrics. */ /** * Represents the dimensions and pixel ratio of the browser viewport. * @typedef {Object} WindowMetrics * @property {number} width - The width of the viewport in pixels. * @property {number} height - The height of the viewport in pixels. * @property {number} devicePixelRatio - The device pixel ratio. */ /** * Represents the physical screen/monitor properties. * @typedef {Object} ScreenMetrics * @property {number} width - The screen width in pixels. * @property {number} height - The screen height in pixels. * @property {number} availWidth - The available screen width in pixels (excluding OS taskbars). * @property {number} availHeight - The available screen height in pixels (excluding OS taskbars). * @property {number} colorDepth - The color depth of the screen in bits. * @property {number} pixelDepth - The pixel depth of the screen in bits. * @property {string} orientation - The orientation of the screen (e.g., 'landscape-primary'). */ /** * Represents a comprehensive report containing connectivity status, connection quality, recent resource performance metrics, and memory usage. * @typedef {Object} NetworkEvent * @property {Readonly} connectivity - Current online/offline status. * @property {Readonly} quality - Current network quality metrics. * @property {Readonly} battery - Current battery status. * @property {Readonly} device - Current device hardware metrics. * @property {Readonly} performance - Comprehensive performance metrics. * @property {Readonly} resources - Recent resource loading metrics. * @property {Readonly} memoryUsage - Current JavaScript heap memory metrics. * @property {Readonly} windowMetrics - Current viewport dimensions. * @property {Readonly} screenMetrics - Current screen/monitor properties. * @property {Event} [event] */ /** * A callback function signature for receiving network updates. * @typedef {(data: NetworkEvent) => void} NetworkCallback */ /** * Event map for {@link TinyBrowserMonitor}. * @typedef {Object} TinyBrowserMonitorEvents * @property {(metrics: Readonly) => void} WindowResize - Emitted when the window is resized. * @property {(metrics: Readonly) => void} FPS - Emitted with the latest FPS sample. * @property {(status: Readonly) => void} BatteryUpdated - Emitted when the battery status changes. * @property {(usage: Readonly) => void} MemoryUsage - Emitted when the memory usage is sampled. * @property {(oldItem: ResourceMetric|undefined, newItem: ResourceMetric) => void} ResourceAdded - Emitted when a resource is added. * @property {(oldItem: ResourceMetric|undefined, newItem: ResourceMetric) => void} ResourceDeleted - Emitted when a resource is removed. * @property {(oldItem: ResourceMetric|undefined, newItem: ResourceMetric) => void} ResourceEdited - Emitted when a resource is edited. * @property {(paint: Readonly) => void} PaintUpdated - Emitted when paint metrics change. * @property {(navigation: Partial) => void} NavigationUpdated - Emitted when navigation metrics change. * @property {(data: { layoutShift: number }) => void} LayoutShiftUpdated - Emitted when the layout shift changes. * @property {(data: { lcp: number }) => void} LcpUpdated - Emitted when the LCP value changes. * @property {(data: { lcp: number[] }) => void} LongTaskUpdated - Emitted when long tasks are recorded. * @property {(status: Readonly) => void} ConnectivityUpdated - Emitted when connectivity changes. * @property {(data: NetworkEvent) => void} NetworkUpdated - Emitted with the full network report. * @property {() => void} Destroyed - Emitted when the monitor is destroyed. */ /** @type {new (options?: MonitorOptions) => import('../../jsdoc/EventEmitter.mjs').ICustomEventEmitter} */ declare const TypedEventEmitter: new (options?: MonitorOptions) => import('../../jsdoc/EventEmitter.mjs').ICustomEventEmitter; /** * An advanced monitor that tracks connectivity, connection quality, battery, * device constraints, and comprehensive performance metrics. */ declare class TinyBrowserMonitor extends TypedEventEmitter { #private; /** * Retrieves a read-only copy of the valid system identifiers. * @returns {Readonly} A read-only array of valid system values. */ static get VALID_SYSTEMS(): Readonly; /** * Creates an instance of TinyBrowserMonitor. * @param {MonitorOptions} [options={}] - Configuration options. * @throws {TypeError} If the provided resourceLimit is invalid, memoryIntervalMs is invalid, or systems is not an array. * @throws {TypeError} If any provided system is not a valid SystemValue. */ constructor(options?: MonitorOptions); /** * Indicates whether the monitor has been destroyed. * @returns {boolean} True if the monitor has been destroyed, false otherwise. */ get isDestroyed(): boolean; /** * Returns the current connectivity status. * @returns {Readonly} A deep clone of the connectivity status. */ get connectivity(): Readonly; /** * Returns the current connection quality metrics. * @returns {Readonly} A deep clone of the quality metrics. */ get quality(): Readonly; /** * Returns the collection of recent resource loading metrics. * @returns {Readonly} A deep freeze of the resources array. */ get resources(): Readonly; /** * Returns the current battery status. * @returns {Readonly} A deep clone of the battery status. */ get battery(): Readonly; /** * Returns the current viewport dimensions. * @returns {Readonly} A deep clone of the window metrics. */ get windowMetrics(): Readonly; /** * Returns the current screen/monitor properties. * @returns {Readonly} A deep clone of the screen metrics. */ get screenMetrics(): Readonly; /** * Returns the current device hardware metrics. * @returns {Readonly} A deep clone of the device metrics. */ get device(): Readonly; /** * Returns the current frame rate metrics. * @type {FrameRateMetrics} */ get fps(): FrameRateMetrics; /** * Returns the current performance metrics. * @returns {Readonly} A deep clone of the performance metrics. */ get performance(): Readonly; /** * Returns the current JavaScript heap memory usage. * @type {MemoryUsage} */ get memoryUsage(): MemoryUsage; /** * Returns an array of all currently enabled systems. * @returns {Readonly} A read-only array of enabled system identifiers. */ get enabledSystems(): Readonly; /** * Checks if a specific system is currently enabled. * @param {SystemValue} system - The identifier of the system to check. * @returns {boolean} True if the system is enabled, false otherwise. * @throws {TypeError} If the provided system is not a string. */ has(system: SystemValue): boolean; /** * Returns the number of currently enabled systems. * @returns {number} The count of enabled systems. */ get size(): number; /** * Formats the current memory usage metrics into a human-readable string. * @param {MemoryFormat} format - The desired unit for the output. * @param {MemoryUsage} [memoryUsage=this.#memoryUsage] - The memory usage object. * @returns {MemoryHumanData} A formatted string containing used, total, and limit memory. * @throws {TypeError} If the provided format is invalid or if memoryUsage is malformed. */ getFormattedMemoryUsage(format: MemoryFormat, memoryUsage?: MemoryUsage): MemoryHumanData; /** * Removes all listeners and observers to prevent memory leaks. */ destroy(): void; } export default TinyBrowserMonitor; //# sourceMappingURL=TinyBrowserMonitor.d.mts.map