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 | 301x 301x 301x 3x | /**
* Mobile UI utilities for responsive touch-optimized interfaces
*
* Provides helpers for touch target sizing, responsive font scaling,
* and mobile-specific layout calculations following iOS/Android guidelines.
*
* PRIORITY: High-end mobile devices (Super HD, 2K+) are top priority and get:
* - Enhanced touch targets (56px vs 48px)
* - Larger Korean fonts (+10% for better readability)
* - Optimized spacing and layout
* - Full feature parity with desktop
*
* Supported Devices (Priority Order):
* 1. Super HD Mobile (≥768px): Motorola Edge 60 Pro, Galaxy S-series
* 2. Standard Mobile (375-767px): iPhone 12/13/14, standard Android
* 3. Small Mobile (<375px): iPhone SE, budget devices
*
* @module utils/mobileUIUtils
* @category Mobile Utilities
* @korean 모바일UI유틸리티
*/
import { UI_DIMENSIONS, SPACING } from "../types/constants/ui";
import {
KOREAN_MOBILE_FONT_SIZES,
getKoreanFontSize,
} from "../types/constants/typography";
/**
* Viewport size category for responsive design
*
* @category Mobile UI
* @korean 뷰포트크기범주
*/
export type ViewportSize = "xs" | "sm" | "md" | "lg" | "xl";
/**
* Touch target size configuration
*
* @category Mobile UI
* @korean 터치타겟크기설정
*/
export interface TouchTargetSize {
readonly minWidth: number;
readonly minHeight: number;
readonly padding: number;
readonly spacing: number;
}
/**
* Get viewport size category from width
*
* PRIORITY: High-end mobile devices (Super HD, 2K+) are treated as 'md' for optimal layout
*
* @param width - Viewport width in pixels
* @returns Viewport size category
*
* @example
* ```typescript
* getViewportSize(375); // 'xs' (iPhone SE)
* getViewportSize(768); // 'sm' (Standard phones, high-end mobiles start here)
* getViewportSize(2712); // 'md' (Motorola Edge 60 Pro Super HD)
* getViewportSize(1200); // 'lg' (Desktop)
* ```
*
* @public
* @korean 뷰포트크기얻기
*/
export function getViewportSize(width: number): ViewportSize {
if (width < 375) return "xs"; // Extra small phones
if (width < 768) return "sm"; // Standard phones
if (width < 1024) return "md"; // High-end mobile (Super HD), tablets
if (width < 1440) return "lg"; // Small desktop
return "xl"; // Large desktop
}
/**
* Get touch-optimized button size configuration
* Ensures minimum 48px touch targets per iOS/Android guidelines
*
* PRIORITY: High-end mobile devices (Super HD, 2K+) get enhanced touch targets (56px)
* for better precision on high-resolution displays
*
* @param isMobile - Whether on mobile device
* @param viewportWidth - Optional viewport width for fine-tuning
* @returns Touch target size configuration
*
* @example
* ```typescript
* const buttonSize = getTouchTargetSize(true, 375);
* // { minWidth: 48, minHeight: 48, padding: 12, spacing: 8 }
*
* const superHDButtonSize = getTouchTargetSize(true, 2712);
* // { minWidth: 56, minHeight: 56, padding: 16, spacing: 12 }
* ```
*
* @public
* @korean 터치타겟크기얻기
*/
export function getTouchTargetSize(
isMobile: boolean,
viewportWidth?: number
): TouchTargetSize {
if (!isMobile) {
return {
minWidth: 120,
minHeight: 44,
padding: SPACING.MD,
spacing: SPACING.MD,
};
}
const width = viewportWidth ?? 375;
const isExtraSmall = width < 360;
const isSuperHD = width >= 768; // High-end mobile (Motorola Edge 60 Pro, etc.)
// Super HD devices get enhanced touch targets for better precision
if (isSuperHD) {
return {
minWidth: UI_DIMENSIONS.TOUCH_TARGET_COMFORTABLE,
minHeight: UI_DIMENSIONS.TOUCH_TARGET_COMFORTABLE,
padding: SPACING.MD,
spacing: SPACING.COMPACT,
};
}
return {
minWidth: UI_DIMENSIONS.TOUCH_TARGET_MIN,
minHeight: UI_DIMENSIONS.TOUCH_TARGET_MIN,
padding: isExtraSmall ? SPACING.SM : SPACING.COMPACT,
spacing: UI_DIMENSIONS.TOUCH_TARGET_SPACING,
};
}
/**
* Get responsive Korean font size for mobile
* Ensures minimum 16px for body text on mobile
*
* PRIORITY: High-end mobile (Super HD, 2K+) get enhanced font sizes for better readability
*
* @param size - Size category ('SMALL', 'MEDIUM', 'LARGE')
* @param viewportWidth - Viewport width in pixels
* @returns Font size in pixels
*
* @example
* ```typescript
* getMobileKoreanFontSize('SMALL', 375); // 16
* getMobileKoreanFontSize('MEDIUM', 410); // 18
* getMobileKoreanFontSize('MEDIUM', 2712); // 20 (Super HD enhanced)
* getMobileKoreanFontSize('LARGE', 768); // 24
* ```
*
* @public
* @korean 모바일한글글꼴크기얻기
*/
export function getMobileKoreanFontSize(
size: keyof typeof KOREAN_MOBILE_FONT_SIZES,
viewportWidth: number
): number {
const fontSize = getKoreanFontSize(size, viewportWidth);
// Super HD mobile devices (≥768px) get enhanced font sizes
// for better readability on high-resolution displays
Iif (viewportWidth >= 768) {
return Math.ceil(fontSize * 1.1); // 10% larger for Super HD
}
return fontSize;
}
/**
* Get responsive spacing value
* Scales spacing based on viewport size
*
* @param baseSpacing - Base spacing value from SPACING constant
* @param isMobile - Whether on mobile device
* @returns Scaled spacing in pixels
*
* @example
* ```typescript
* getResponsiveSpacing(SPACING.MD, true); // 12 (COMPACT on mobile)
* getResponsiveSpacing(SPACING.MD, false); // 16 (original)
* ```
*
* @public
* @korean 반응형간격얻기
*/
export function getResponsiveSpacing(
baseSpacing: number,
isMobile: boolean
): number {
return isMobile ? Math.max(SPACING.SM, baseSpacing * 0.75) : baseSpacing;
}
/**
* Calculate responsive panel width
* Ensures panels fit within viewport with proper margins
*
* @param viewportWidth - Viewport width in pixels
* @param isMobile - Whether on mobile device
* @param minMargin - Minimum margin on each side (default: 20px)
* @returns Panel width in pixels
*
* @example
* ```typescript
* getResponsivePanelWidth(375, true); // ~335px (375 - 40 margin)
* getResponsivePanelWidth(1200, false); // ~400px (max width applied)
* ```
*
* @public
* @korean 반응형패널폭얻기
*/
export function getResponsivePanelWidth(
viewportWidth: number,
isMobile: boolean,
minMargin = 20
): number {
if (!isMobile) {
return Math.min(400, viewportWidth - minMargin * 2);
}
// Mobile: use most of screen width
return Math.min(viewportWidth - minMargin * 2, 360);
}
/**
* Check if viewport is in landscape orientation
*
* @param viewportWidth - Viewport width in pixels
* @param viewportHeight - Viewport height in pixels
* @returns Whether in landscape orientation
*
* @example
* ```typescript
* isLandscape(812, 375); // true (iPhone X landscape)
* isLandscape(375, 812); // false (iPhone X portrait)
* ```
*
* @public
* @korean 가로모드여부
*/
export function isLandscape(
viewportWidth: number,
viewportHeight: number
): boolean {
return viewportWidth > viewportHeight;
}
/**
* Get responsive button styles for touch optimization
*
* @param isMobile - Whether on mobile device
* @param viewportWidth - Optional viewport width
* @returns CSS properties for button
*
* @example
* ```typescript
* const buttonStyles = getResponsiveButtonStyles(true, 375);
* // {
* // minWidth: '48px',
* // minHeight: '48px',
* // padding: '12px',
* // fontSize: '16px',
* // ...
* // }
* ```
*
* @public
* @korean 반응형버튼스타일얻기
*/
export function getResponsiveButtonStyles(
isMobile: boolean,
viewportWidth?: number
): React.CSSProperties {
const touchTarget = getTouchTargetSize(isMobile, viewportWidth);
const fontSize = isMobile
? getMobileKoreanFontSize("SMALL", viewportWidth ?? 375)
: 16;
return {
minWidth: `${touchTarget.minWidth}px`,
minHeight: `${touchTarget.minHeight}px`,
padding: `${touchTarget.padding}px`,
fontSize: `${fontSize}px`,
lineHeight: "1.4",
cursor: "pointer",
userSelect: "none",
WebkitTapHighlightColor: "transparent",
};
}
/**
* Get responsive text styles with proper Korean font sizing
*
* @param size - Font size category
* @param isMobile - Whether on mobile device
* @param viewportWidth - Viewport width in pixels
* @returns CSS properties for text
*
* @example
* ```typescript
* const textStyles = getResponsiveTextStyles('MEDIUM', true, 375);
* // {
* // fontSize: '18px',
* // lineHeight: '1.5',
* // letterSpacing: '0.02em',
* // }
* ```
*
* @public
* @korean 반응형텍스트스타일얻기
*/
export function getResponsiveTextStyles(
size: keyof typeof KOREAN_MOBILE_FONT_SIZES,
isMobile: boolean,
viewportWidth: number
): React.CSSProperties {
const fontSize = isMobile
? getMobileKoreanFontSize(size, viewportWidth)
: KOREAN_MOBILE_FONT_SIZES[size].regular;
return {
fontSize: `${fontSize}px`,
lineHeight: isMobile ? "1.5" : "1.4",
letterSpacing: "0.02em",
};
}
/**
* Calculate minimum spacing between interactive elements
* Ensures adequate spacing for touch accuracy
*
* @param isMobile - Whether on mobile device
* @returns Minimum spacing in pixels
*
* @example
* ```typescript
* getMinimumInteractiveSpacing(true); // 8px (mobile)
* getMinimumInteractiveSpacing(false); // 12px (desktop)
* ```
*
* @public
* @korean 최소상호작용간격얻기
*/
export function getMinimumInteractiveSpacing(isMobile: boolean): number {
return isMobile
? UI_DIMENSIONS.TOUCH_TARGET_SPACING
: SPACING.COMPACT;
}
/**
* Viewport detection utilities
*
* PRIORITY: High-end mobile devices (Super HD, 2K+) are explicitly supported
*
* @category Mobile UI
* @korean 뷰포트감지
*/
export const ViewportDetection = {
/**
* Check if iPhone SE or similar small device
* @korean iPhone SE여부
*/
isSmallMobile: (width: number) => width <= 375,
/**
* Check if standard mobile device (excluding high-end)
* @korean 표준모바일여부
*/
isMobile: (width: number) => width < 768,
/**
* Check if high-end mobile device (Super HD, 2K+)
* Uses height + DPR to distinguish phones from tablets
* High-end phones: short side 400-600px, long side >=800px, DPR >=2
* @korean 고급모바일여부
*/
isSuperHDMobile: (width: number, height: number = window.innerHeight) => {
const shortSide = Math.min(width, height);
const longSide = Math.max(width, height);
const dpr = window.devicePixelRatio || 1;
return shortSide >= 400 && shortSide <= 600 && longSide >= 800 && dpr >= 2;
},
/**
* Check if tablet device
* @korean 태블릿여부
*/
isTablet: (width: number) => width >= 768 && width < 1024,
/**
* Check if desktop device
* @korean 데스크톱여부
*/
isDesktop: (width: number) => width >= 1024,
/**
* Check if device has notch (iPhone X+)
* @korean 노치여부
*/
hasNotch: (width: number, height: number) =>
(width === 375 && height === 812) || // iPhone X, XS, 11 Pro
(width === 414 && height === 896) || // iPhone XR, XS Max, 11, 11 Pro Max
(width === 390 && height === 844) || // iPhone 12, 12 Pro, 13, 13 Pro, 14
(width === 393 && height === 852) || // iPhone 14 Pro
(width === 428 && height === 926), // iPhone 12/13/14 Pro Max
} as const;
|