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 | 7x 7x 7x 7x 35x 195x 35x 5x 30x 6x 24x 35x 17x 18x 6x 12x 7x 5x 1x 1x 1x 4x 1x 3x 35x 28x 7x 7x 7x 7x 7x 7x 3x 3x 3x 3x 3x 3x 3x 3x 3x 7x 7x 7x 1x 1x 1x 1x 126x 126x 126x 126x 91x 35x 35x 35x 35x 35x 35x 126x 16x 16x 16x 19x 7x 7x 7x 12x 2x 2x 2x 10x 4x 4x 4x 6x 6x 6x 35x 35x 35x 35x 35x 35x 3x 3x 86x 86x 3x 83x 82x 1x 1x 16x 16x 3x 3x 3x 3x 3x 2x 1x 1x 1x 13x 1x 12x | /**
* Device Detection Utility
*
* Provides robust mobile device detection combining:
* - User-agent string analysis
* - Screen size detection
* - Touch capability detection
*
* This ensures mobile controls are shown on all mobile devices,
* including high-resolution phones that exceed typical mobile breakpoints.
*
* @module utils/deviceDetection
* @category Mobile
* @korean 기기감지유틸리티
*/
/**
* Device type classification
*/
export enum DeviceType {
/** Desktop computer or laptop */
DESKTOP = 'desktop',
/** Mobile phone (iOS, Android, etc.) */
MOBILE = 'mobile',
/** Tablet device (iPad, Android tablets) */
TABLET = 'tablet',
}
/**
* Platform detection results
*/
export interface PlatformInfo {
/** Operating system type */
readonly os: 'ios' | 'android' | 'windows' | 'macos' | 'linux' | 'unknown';
/** Device type classification */
readonly deviceType: DeviceType;
/** Whether device has touch capability */
readonly hasTouch: boolean;
/** Whether device is mobile phone */
readonly isMobile: boolean;
/** Whether device is tablet */
readonly isTablet: boolean;
/** Whether device is desktop */
readonly isDesktop: boolean;
/** Screen width in pixels */
readonly screenWidth: number;
/** Screen height in pixels */
readonly screenHeight: number;
}
/**
* Detect if user-agent indicates a mobile device
* Checks for common mobile device identifiers in user-agent string
*
* @param userAgent - Browser user-agent string
* @returns True if user-agent indicates mobile device
*/
function isMobileUserAgent(userAgent: string): boolean {
const mobileKeywords = [
'Android',
'webOS',
'iPhone',
// 'iPad' is handled separately in isTabletUserAgent
'iPod',
'BlackBerry',
'IEMobile',
'Opera Mini',
'Mobile',
'mobile',
];
return mobileKeywords.some(keyword => userAgent.includes(keyword));
}
/**
* Detect if user-agent indicates a tablet device
*
* @param userAgent - Browser user-agent string
* @returns True if user-agent indicates tablet
*/
function isTabletUserAgent(userAgent: string): boolean {
// iPad is always a tablet
if (userAgent.includes('iPad')) {
return true;
}
// Android tablets typically include "Tablet" or have Mobile absent
if (userAgent.includes('Android')) {
return userAgent.includes('Tablet') || !userAgent.includes('Mobile');
}
return false;
}
/**
* Detect operating system from user-agent
*
* @param userAgent - Browser user-agent string
* @returns Operating system identifier
*/
function detectOS(userAgent: string): PlatformInfo['os'] {
if (userAgent.includes('iPhone') || userAgent.includes('iPad') || userAgent.includes('iPod')) {
return 'ios';
}
if (userAgent.includes('Android')) {
return 'android';
}
if (userAgent.includes('Windows')) {
return 'windows';
}
if (userAgent.includes('Mac')) {
// Handle iPadOS 13+ in desktop mode, which reports a Mac-like user agent
// e.g. "Macintosh; Intel Mac OS X" but still has touch support
const isLikelyIPadOSDesktop =
typeof navigator !== 'undefined' &&
typeof navigator.maxTouchPoints === 'number' &&
navigator.maxTouchPoints > 1 &&
userAgent.includes('Macintosh');
Iif (isLikelyIPadOSDesktop) {
return 'ios';
}
return 'macos';
}
if (userAgent.includes('Linux')) {
return 'linux';
}
return 'unknown';
}
/**
* Detect if device has touch capability
* Uses multiple methods for reliability
*
* @returns True if touch is supported
*/
function hasTouchSupport(): boolean {
// Check for touch events support
if ('ontouchstart' in window) {
return true;
}
// Check for touch points (must be defined and > 0)
Iif (typeof navigator !== 'undefined' &&
typeof navigator.maxTouchPoints !== 'undefined' &&
navigator.maxTouchPoints > 0) {
return true;
}
// Check for pointer events with touch
Iif (typeof window !== 'undefined' &&
window.matchMedia &&
window.matchMedia('(pointer: coarse)').matches) {
return true;
}
return false;
}
/**
* Mobile screen size breakpoint
* Devices with width <= this value are considered mobile by size
*/
export const MOBILE_BREAKPOINT = 768;
/**
* Tablet screen size breakpoint
* Devices with width > MOBILE_BREAKPOINT and <= TABLET_BREAKPOINT are tablets
*/
export const TABLET_BREAKPOINT = 1024;
/**
* Cached CSS environment variable insets
*/
let cachedCSSEnvInsets: { top: number; bottom: number } | null = null;
/**
* Read CSS environment variables for safe area insets
* Results are cached as they don't change during a session
*/
function readCSSEnvInsets(): { top: number; bottom: number } | null {
Iif (cachedCSSEnvInsets !== null) {
return cachedCSSEnvInsets;
}
Eif (typeof window !== 'undefined' && typeof getComputedStyle === 'function') {
try {
const root = document.documentElement;
const style = getComputedStyle(root);
const topEnv = style.getPropertyValue('env(safe-area-inset-top)');
const bottomEnv = style.getPropertyValue('env(safe-area-inset-bottom)');
Iif (topEnv || bottomEnv) {
const result = {
top: parseInt(topEnv || '0', 10) || 0,
bottom: parseInt(bottomEnv || '0', 10) || 0,
};
cachedCSSEnvInsets = result;
return result;
}
} catch (error) {
// Fall through to null
}
}
return null;
}
/**
* Cached platform information to avoid re-parsing user-agent on every call
*/
let cachedPlatform: PlatformInfo | null = null;
let cachedScreenWidth = 0;
let cachedScreenHeight = 0;
/**
* Clear the cached platform information
* Useful when window is resized or device emulation changes
* Also clears CSS environment variable cache
*
* @public
*/
export function clearPlatformCache(): void {
cachedPlatform = null;
cachedScreenWidth = 0;
cachedScreenHeight = 0;
cachedCSSEnvInsets = null;
}
/**
* Detect device type and platform information
*
* Combines multiple detection methods for reliability:
* 1. User-agent string analysis (most reliable for device type)
* 2. Screen dimensions
* 3. Touch capability
*
* This ensures mobile controls are shown on:
* - Standard mobile phones (< 768px width)
* - High-resolution phones (>= 768px width but mobile user-agent)
* - Tablets (user preference via touch support)
*
* Results are cached to avoid re-parsing user-agent on every call.
* Cache is invalidated when screen dimensions change.
*
* @returns Complete platform information
*
* @example
* ```typescript
* const platform = detectPlatform();
*
* if (platform.isMobile) {
* // Show mobile controls
* return <MobileControls />;
* }
* ```
*
* @public
* @korean 플랫폼감지
*/
export function detectPlatform(): PlatformInfo {
const userAgent = typeof navigator !== 'undefined' ? navigator.userAgent : '';
const screenWidth = typeof window !== 'undefined' ? window.innerWidth : 1920;
const screenHeight = typeof window !== 'undefined' ? window.innerHeight : 1080;
// Return cached result if screen dimensions haven't changed
if (cachedPlatform !== null &&
cachedScreenWidth === screenWidth &&
cachedScreenHeight === screenHeight) {
return cachedPlatform;
}
// Detect OS
const os = detectOS(userAgent);
// Detect touch capability
const hasTouch = hasTouchSupport();
// Detect if mobile by user-agent (most reliable method)
const isMobileUA = isMobileUserAgent(userAgent);
// Detect if tablet by user-agent
const isTabletUA = isTabletUserAgent(userAgent);
// Detect by screen size (fallback method)
const isMobileBySize = screenWidth <= MOBILE_BREAKPOINT;
const isTabletBySize = screenWidth > MOBILE_BREAKPOINT && screenWidth <= TABLET_BREAKPOINT;
// Determine device type
// Priority: User-agent > Screen size
let deviceType: DeviceType;
let isMobile: boolean;
let isTablet: boolean;
if (isMobileUA && !isTabletUA) {
// User-agent indicates phone
deviceType = DeviceType.MOBILE;
isMobile = true;
isTablet = false;
} else if (isTabletUA) {
// User-agent indicates tablet
deviceType = DeviceType.TABLET;
isMobile = false;
isTablet = true;
} else if (isMobileBySize) {
// Small screen, assume mobile
deviceType = DeviceType.MOBILE;
isMobile = true;
isTablet = false;
} else if (isTabletBySize && hasTouch) {
// Medium screen with touch, assume tablet
deviceType = DeviceType.TABLET;
isMobile = false;
isTablet = true;
} else {
// Desktop
deviceType = DeviceType.DESKTOP;
isMobile = false;
isTablet = false;
}
const isDesktop = deviceType === DeviceType.DESKTOP;
const result: PlatformInfo = {
os,
deviceType,
hasTouch,
isMobile,
isTablet,
isDesktop,
screenWidth,
screenHeight,
};
// Cache the result along with screen dimensions
cachedPlatform = result;
cachedScreenWidth = screenWidth;
cachedScreenHeight = screenHeight;
return result;
}
/**
* Simple mobile check for backward compatibility
* Returns true for both mobile phones and tablets
*
* @returns True if device is mobile or tablet
*
* @public
* @korean 모바일확인
*/
export function isMobileDevice(): boolean {
const platform = detectPlatform();
return platform.isMobile || platform.isTablet;
}
/**
* Check if device should use mobile controls
* Takes into account device type, screen size, and touch capability
*
* @returns True if mobile controls should be shown
*
* @public
* @korean 모바일컨트롤사용
*/
export function shouldUseMobileControls(): boolean {
const platform = detectPlatform();
// Always use mobile controls on phones
if (platform.isMobile) {
return true;
}
// Use mobile controls on tablets (better touch experience)
if (platform.isTablet) {
return true;
}
// Use mobile controls on small desktop screens with touch
Iif (platform.screenWidth <= MOBILE_BREAKPOINT && platform.hasTouch) {
return true;
}
return false;
}
/**
* Get safe area insets for device
* Returns appropriate values based on device type and OS
*
* For iOS devices, attempts to detect if device has a notch by checking
* screen dimensions. Falls back to CSS environment variables if available.
*
* @returns Safe area insets in pixels
*
* @public
* @korean 안전영역인셋
*/
export function getSafeAreaInsets() {
const platform = detectPlatform();
// iOS devices - distinguish between notched and non-notched
if (platform.os === 'ios' && platform.isMobile) {
// Try to read CSS environment variables first (most accurate)
const cssEnvInsets = readCSSEnvInsets();
Iif (cssEnvInsets) {
return {
top: cssEnvInsets.top,
bottom: cssEnvInsets.bottom,
left: 0,
right: 0,
};
}
// Detect orientation
const isLandscape = platform.screenWidth > platform.screenHeight;
// Heuristic: iPhone X and later have notches and specific screen dimensions
// iPhone X/XS/11 Pro: 375x812, iPhone XR/11: 414x896, iPhone 12/13/14: 390x844, etc.
// Only devices with height >= 812 (portrait) or width >= 812 (landscape) have notches
const hasNotch = platform.screenHeight >= 812 || platform.screenWidth >= 812;
if (hasNotch) {
if (isLandscape) {
// In landscape, notch is on the side
return {
top: 0,
bottom: 21, // Home indicator
left: 44, // Notch side
right: 44, // Opposite side for symmetry
};
} else {
// In portrait, notch is at top
return {
top: 44,
bottom: 34,
left: 0,
right: 0,
};
}
} else {
// Older iPhones without notch (iPhone 8, SE, etc.)
return {
top: 20, // Status bar height
bottom: 0,
left: 0,
right: 0,
};
}
}
// Android devices (standard status bar)
if (platform.os === 'android' && platform.isMobile) {
return {
top: 24,
bottom: 0,
left: 0,
right: 0,
};
}
// Tablets and desktop - no safe area needed
return {
top: 0,
bottom: 0,
left: 0,
right: 0,
};
}
|