返回 presentation-ai
utils.ts
1 /**
2 * Shared utility functions for PPT export
3 */
4
5 /**
6 * Get optimal pixelRatio for image capture based on device capability
7 * Uses 2x for low-end devices to reduce memory usage and improve performance
8 * Uses 3x for high-end devices for best quality
9 */
10 export function getOptimalPixelRatio(): number {
11 // Check device memory (Chrome/Edge only)
12 const deviceMemory = (navigator as { deviceMemory?: number }).deviceMemory;
13 if (deviceMemory && deviceMemory <= 4) {
14 return 2; // Low memory device
15 }
16
17 // Check CPU cores
18 const hardwareConcurrency = navigator.hardwareConcurrency;
19 if (hardwareConcurrency && hardwareConcurrency <= 4) {
20 return 2; // Limited CPU
21 }
22
23 return 3; // High-end device
24 }
25
25 lines TYPESCRIPT