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 | 3x 11x 8x 4x 4x 1x 3x 8x 7x 7x 7x 3x 4x 3x 1x 4x 2x 2x 1x 1x 8x 8x 1x 1x 6x 111x 8x 8x 103x 111x 8x 6x 3x 3x 2x | /**
* Responsive Layout Utility Functions
*
* Helper functions for responsive layout calculations and touch target validation
*
* @module utils/responsiveLayout
* @category Mobile UI
* @korean 반응형레이아웃유틸
*/
/**
* Minimum touch target size according to iOS Human Interface Guidelines
*/
export const MIN_TOUCH_TARGET_SIZE = 44;
/**
* Validate if an element meets minimum touch target requirements
*
* @param width - Element width in pixels
* @param height - Element height in pixels
* @param minSize - Minimum size (default: 44px iOS guideline)
* @returns True if element meets minimum requirements
*
* @example
* ```typescript
* const isValid = isValidTouchTarget(50, 50); // true
* const isTooSmall = isValidTouchTarget(30, 30); // false
* ```
*/
export function isValidTouchTarget(
width: number,
height: number,
minSize: number = MIN_TOUCH_TARGET_SIZE
): boolean {
return width >= minSize && height >= minSize;
}
/**
* Calculate optimal font size for given viewport width
* Ensures minimum readable font sizes on mobile
*
* @param viewportWidth - Viewport width in pixels
* @param baseSize - Base font size for desktop (default: 16)
* @param minSize - Minimum font size for mobile (default: 14)
* @returns Calculated font size in pixels
*
* @example
* ```typescript
* const fontSize = calculateFontSize(375, 16, 14); // 14px for mobile
* const fontSize = calculateFontSize(1920, 16, 14); // 16px for desktop
* ```
*/
export function calculateFontSize(
viewportWidth: number,
baseSize: number = 16,
minSize: number = 14
): number {
if (viewportWidth < 768) {
// Mobile: use minimum size or scale down slightly
return Math.max(minSize, Math.floor(baseSize * 0.875));
} else if (viewportWidth < 1024) {
// Tablet: scale proportionally
return Math.max(minSize, Math.floor(baseSize * 0.9375));
}
// Desktop: use base size
return baseSize;
}
/**
* Calculate element position within safe area
* Ensures elements don't overlap notch or home indicator
*
* @param value - Position value in pixels
* @param safeAreaInset - Safe area inset for that edge
* @returns Adjusted position value
*
* @example
* ```typescript
* const top = calculateSafePosition(10, 44); // 54px (10 + 44)
* const bottom = calculateSafePosition(20, 34); // 54px (20 + 34)
* ```
*/
export function calculateSafePosition(
value: number,
safeAreaInset: number
): number {
return value + safeAreaInset;
}
/**
* Calculate optimal HUD height for given viewport
* Scales based on device type and orientation
*
* @param viewportWidth - Viewport width in pixels
* @param isLandscape - Whether in landscape orientation
* @returns HUD height in pixels
*
* @example
* ```typescript
* const hudHeight = calculateHUDHeight(375, false); // ~80px for mobile portrait
* const hudHeight = calculateHUDHeight(667, true); // ~60px for mobile landscape
* ```
*/
export function calculateHUDHeight(
viewportWidth: number,
isLandscape: boolean
): number {
const isMobile = viewportWidth < 768;
const isSmallMobile = viewportWidth <= 375; // Changed to <= to match 375px iPhone SE
if (isLandscape && isMobile) {
// Landscape: minimize HUD to maximize gameplay area
return isSmallMobile ? 60 : 70;
}
if (isMobile) {
// Portrait mobile: compact but readable
return isSmallMobile ? 80 : 95;
}
// Desktop/tablet: larger HUD with more information
return 120;
}
/**
* Calculate optimal control bar height for mobile
*
* @param isMobile - Whether on mobile device
* @param isLandscape - Whether in landscape orientation
* @returns Control bar height in pixels
*/
export function calculateControlsHeight(
isMobile: boolean,
isLandscape: boolean
): number {
if (!isMobile) {
return 0; // Desktop uses keyboard
}
if (isLandscape) {
return 100; // Minimal controls in landscape
}
return 130; // Full touch controls in portrait
}
/**
* Calculate spacing between HUD elements
* Ensures proper touch targets and visual hierarchy
*
* @param isMobile - Whether on mobile device
* @param density - Spacing density ('compact' | 'normal' | 'spacious')
* @returns Spacing value in pixels
*/
export function calculateSpacing(
isMobile: boolean,
density: 'compact' | 'normal' | 'spacious' = 'normal'
): number {
const baseSpacing = isMobile ? 8 : 12;
switch (density) {
case 'compact':
return Math.floor(baseSpacing * 0.75);
case 'spacious':
return Math.ceil(baseSpacing * 1.5);
case 'normal':
default:
return baseSpacing;
}
}
/**
* Calculate optimal progress bar dimensions
* Ensures bars are touch-friendly on mobile
*
* @param isMobile - Whether on mobile device
* @param type - Bar type ('health' | 'ki' | 'stamina')
* @returns Bar dimensions { width, height }
*/
export function calculateProgressBarSize(
isMobile: boolean,
type: 'health' | 'ki' | 'stamina'
): { width: number; height: number } {
if (isMobile) {
// Mobile: touch-friendly sizes
const height = type === 'health' ? 48 : 40; // Health bar larger
return {
width: 160,
height,
};
}
// Desktop: more detailed display
const height = type === 'health' ? 55 : 45;
return {
width: 220,
height,
};
}
/**
* Get optimal grid layout for trigram stance selector
*
* @param isMobile - Whether on mobile device
* @param isLandscape - Whether in landscape orientation
* @returns Grid configuration { columns, rows, gap }
*/
export function getStanceSelectorLayout(
isMobile: boolean,
isLandscape: boolean
): { columns: number; rows: number; gap: number } {
if (isMobile) {
if (isLandscape) {
// Landscape: horizontal layout
return { columns: 4, rows: 2, gap: 8 };
}
// Portrait: compact grid
return { columns: 4, rows: 2, gap: 10 };
}
// Desktop: spacious layout
return { columns: 4, rows: 2, gap: 15 };
}
|