Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 | import type { ReactNode } from "react";
// Re-export types from @usefy/use-memory-monitor
export type {
MemoryInfo,
MemoryWarning,
MemoryCritical,
LeakAnalysis,
MemorySnapshot,
SnapshotDiff,
Severity,
Trend,
SupportLevel,
FormattedMemory,
AvailableMetric,
} from "@usefy/use-memory-monitor";
/**
* Panel visibility mode
* - 'development': Show UI only in development
* - 'production': Show UI only in production
* - 'always': Always show UI
* - 'headless': No UI, but monitoring runs (for production callbacks)
* - 'never': No UI and no monitoring (completely disabled)
*/
export type PanelMode = "development" | "production" | "always" | "headless" | "never";
/**
* Panel position
*/
export type PanelPosition = "right" | "left";
/**
* Theme setting
*/
export type ThemeSetting = "light" | "dark" | "system";
/**
* Active tab in the panel
*/
export type PanelTab = "overview" | "history" | "snapshots" | "settings";
/**
* Leak detection sensitivity
*/
export type LeakSensitivity = "low" | "medium" | "high";
/**
* Trigger button position
*/
export interface TriggerPosition {
top?: number | string;
bottom?: number | string;
right?: number | string;
left?: number | string;
}
/**
* Snapshot schedule interval options
*/
export type SnapshotScheduleInterval =
| "off" // Disabled
| "1sec" // Every 1 second (for testing)
| "10sec" // Every 10 seconds (for testing)
| "1min" // Every 1 minute
| "5min" // Every 5 minutes
| "10min" // Every 10 minutes
| "30min" // Every 30 minutes
| "1hour" // Every 1 hour
| "6hour" // Every 6 hours
| "24hour"; // Every 24 hours
/**
* Snapshot settings
*/
export interface SnapshotSettings {
/** Maximum number of snapshots to store (1-50) */
maxSnapshots: number;
/** Automatic snapshot schedule interval */
scheduleInterval: SnapshotScheduleInterval;
/** Auto-delete oldest snapshot when max reached */
autoDeleteOldest: boolean;
}
/**
* Panel settings that can be persisted
*/
export interface PanelSettings {
/** Warning threshold percentage (0-100) */
warningThreshold: number;
/** Critical threshold percentage (0-100) */
criticalThreshold: number;
/** Auto-GC threshold percentage (0-100), null to disable */
autoGCThreshold: number | null;
/** Enable auto-GC feature */
enableAutoGC: boolean;
/** Polling interval in milliseconds */
interval: number;
/** Theme setting */
theme: ThemeSetting;
/** Panel width in pixels */
panelWidth: number;
/** Snapshot configuration */
snapshot: SnapshotSettings;
/** History buffer size for memory trend (10-200) */
historySize: number;
}
/**
* Panel UI state
*/
export interface PanelState {
/** Whether the panel is open */
isOpen: boolean;
/** Currently active tab */
activeTab: PanelTab;
/** List of expanded section IDs */
expandedSections: string[];
}
/**
* Leak probability contributing factors
*/
export interface LeakProbabilityFactors {
/** Contribution from memory growth slope (0-30) */
slopeContribution: number;
/** Contribution from regression fit quality (0-20) */
rSquaredContribution: number;
/** Contribution from GC ineffectiveness (0-25) */
gcContribution: number;
/** Contribution from observation duration (0-15) */
timeContribution: number;
/** Contribution from baseline growth (0-10) */
baselineContribution: number;
}
/**
* GC analysis data captured at snapshot time
*/
export interface SnapshotGCAnalysis {
/** Number of GC events detected */
gcEventCount: number;
/** Average memory recovery ratio (0-1) */
avgRecoveryRatio: number;
/** Whether GC is effective (recovering significant memory) */
isGCEffective: boolean;
}
/**
* Baseline analysis data captured at snapshot time
*/
export interface SnapshotBaselineAnalysis {
/** Established baseline heap (post-GC minimum) in bytes */
baselineHeap: number;
/** Growth ratio from baseline (0-1) */
growthRatio: number;
/** Whether growth is significant (above threshold) */
isSignificantGrowth: boolean;
}
/**
* Analysis context captured at the time of snapshot
* Contains memory analysis state for comprehensive reporting
*/
export interface SnapshotAnalysisContext {
// === Core Analysis ===
/** Memory trend at snapshot time */
trend: "stable" | "increasing" | "decreasing";
/** Leak probability at snapshot time (0-100) */
leakProbability: number;
/** Severity level at snapshot time */
severity: "normal" | "warning" | "critical";
/** Usage percentage at snapshot time (0-100) */
usagePercentage: number;
// === Leak Factor Analysis (optional) ===
/** Breakdown of leak probability contributing factors */
leakFactors?: LeakProbabilityFactors;
// === GC Analysis (optional) ===
/** Garbage collection analysis data */
gcAnalysis?: SnapshotGCAnalysis;
// === Baseline Analysis (optional) ===
/** Baseline memory analysis data */
baselineAnalysis?: SnapshotBaselineAnalysis;
// === Quality Metrics (optional) ===
/** Confidence level of the analysis (0-100) */
confidence?: number;
/** R-squared value from regression analysis (0-1) */
rSquared?: number;
/** Average memory growth rate in bytes per sample */
averageGrowth?: number;
}
/**
* Snapshot with additional metadata
*/
export interface PanelSnapshot {
id: string;
label: string;
timestamp: number;
heapUsed: number;
heapTotal: number;
heapLimit: number;
domNodes?: number;
eventListeners?: number;
notes?: string;
/** Whether this snapshot was created automatically by scheduler */
isAuto?: boolean;
/** Analysis context captured at the time of snapshot */
analysisContext?: SnapshotAnalysisContext;
}
/**
* Auto-GC event data
*/
export interface AutoGCEventData {
threshold: number;
usage: number;
timestamp: number;
}
/**
* Memory warning callback data
*/
export interface MemoryWarningData {
memory: {
heapUsed: number;
heapTotal: number;
heapLimit: number;
timestamp: number;
};
usagePercentage: number;
threshold: number;
timestamp: number;
}
/**
* Memory critical callback data
*/
export interface MemoryCriticalData {
memory: {
heapUsed: number;
heapTotal: number;
heapLimit: number;
timestamp: number;
};
usagePercentage: number;
threshold: number;
timestamp: number;
}
/**
* Leak analysis data
*/
export interface LeakAnalysisData {
isLeaking: boolean;
probability: number;
trend: "increasing" | "decreasing" | "stable";
recommendation?: string;
}
/**
* Props for MemoryMonitor component
*/
export interface MemoryMonitorProps {
// === Core Configuration ===
/**
* Panel visibility mode
* - 'development': Show UI only in development (default)
* - 'production': Show UI only in production
* - 'always': Always show UI
* - 'headless': No UI, but monitoring runs with callbacks (ideal for production)
* - 'never': No UI and no monitoring (completely disabled)
* @default 'development'
*/
mode?: PanelMode;
/**
* Initial panel open state
* @default false
*/
defaultOpen?: boolean;
/**
* Position of the panel
* @default 'right'
*/
position?: PanelPosition;
/**
* Z-index for the panel
* @default 9999
*/
zIndex?: number;
// === Monitoring Options ===
/**
* Polling interval in milliseconds
* @default 1000
*/
interval?: number;
/**
* Enable memory history tracking
* @default true
*/
enableHistory?: boolean;
/**
* History buffer size
* @default 50
*/
historySize?: number;
/**
* Track DOM node count
* @default true
*/
trackDOMNodes?: boolean;
/**
* Track event listeners (estimated)
* @default true
*/
trackEventListeners?: boolean;
// === Threshold Configuration ===
/**
* Warning threshold percentage (0-100)
* @default 70
*/
warningThreshold?: number;
/**
* Critical threshold percentage (0-100)
* @default 90
*/
criticalThreshold?: number;
/**
* Auto-GC threshold percentage (0-100), null to disable
* @default null
*/
autoGCThreshold?: number | null;
/**
* Enable auto-GC feature
* @default false
*/
enableAutoGC?: boolean;
// === Leak Detection ===
/**
* Enable memory leak detection
* @default true
*/
enableLeakDetection?: boolean;
/**
* Leak detection sensitivity
* @default 'medium'
*/
leakSensitivity?: LeakSensitivity;
// === UI Customization ===
/**
* Custom trigger button content
*/
triggerContent?: ReactNode;
/**
* Trigger button position
* @default { bottom: 20, right: 20 }
*/
triggerPosition?: TriggerPosition;
/**
* Initial panel width
* @default 400
*/
defaultWidth?: number;
/**
* Minimum panel width
* @default 320
*/
minWidth?: number;
/**
* Maximum panel width
* @default 600
*/
maxWidth?: number;
/**
* Theme override
* @default 'system'
*/
theme?: ThemeSetting;
/**
* Custom class name for panel
*/
className?: string;
/**
* Show trigger button
* @default true
*/
showTrigger?: boolean;
// === Callbacks ===
/**
* Called when panel opens/closes
*/
onOpenChange?: (open: boolean) => void;
/**
* Called on memory warning
*/
onWarning?: (data: MemoryWarningData) => void;
/**
* Called on critical memory
*/
onCritical?: (data: MemoryCriticalData) => void;
/**
* Called when leak is detected
*/
onLeakDetected?: (analysis: LeakAnalysisData) => void;
/**
* Called when auto-GC is triggered
*/
onAutoGC?: (data: AutoGCEventData) => void;
/**
* Called on each memory update
*/
onUpdate?: (memory: {
heapUsed: number;
heapTotal: number;
heapLimit: number;
timestamp: number;
}) => void;
// === Advanced ===
/**
* Keyboard shortcut to toggle panel
* @default 'ctrl+shift+m'
*/
shortcut?: string;
/**
* Enable session persistence
* @default true
*/
persistSettings?: boolean;
/**
* Storage key for persistence
* @default 'memory-monitor-panel-settings'
*/
storageKey?: string;
/**
* Disable all features in production
* @default false
*/
disableInProduction?: boolean;
}
/**
* Headless hook options
*/
export interface MemoryMonitorHeadlessOptions {
/**
* Polling interval in milliseconds
* @default 1000
*/
interval?: number;
/**
* Enable memory history tracking
* @default false
*/
enableHistory?: boolean;
/**
* History buffer size
* @default 50
*/
historySize?: number;
/**
* Warning threshold percentage (0-100)
* @default 70
*/
warningThreshold?: number;
/**
* Critical threshold percentage (0-100)
* @default 90
*/
criticalThreshold?: number;
/**
* Auto-GC threshold percentage (0-100), null to disable
* @default null
*/
autoGCThreshold?: number | null;
/**
* Enable auto-GC feature
* @default false
*/
enableAutoGC?: boolean;
/**
* Enable memory leak detection
* @default false
*/
enableLeakDetection?: boolean;
/**
* Leak detection sensitivity
* @default 'medium'
*/
leakSensitivity?: LeakSensitivity;
/**
* Called on memory warning
*/
onWarning?: (data: MemoryWarningData) => void;
/**
* Called on critical memory
*/
onCritical?: (data: MemoryCriticalData) => void;
/**
* Called when leak is detected
*/
onLeakDetected?: (analysis: LeakAnalysisData) => void;
/**
* Called when auto-GC is triggered
*/
onAutoGC?: (data: AutoGCEventData) => void;
}
/**
* Return type for headless hook
*/
export interface MemoryMonitorHeadlessReturn {
/** Current memory info */
memory: {
heapUsed: number;
heapTotal: number;
heapLimit: number;
timestamp: number;
} | null;
/** Usage percentage (heapUsed / heapLimit * 100) */
usagePercentage: number | null;
/** Current severity level */
severity: "normal" | "warning" | "critical";
/** Whether memory leak is detected */
isLeakDetected: boolean;
/** Leak probability (0-100) */
leakProbability: number;
/** Memory trend */
trend: "increasing" | "decreasing" | "stable";
/** Request garbage collection hint */
requestGC: () => void;
/** Whether browser supports memory monitoring */
isSupported: boolean;
}
|