All files / utils koreanThemeHelpers.ts

97.36% Statements 37/38
96.55% Branches 28/29
100% Functions 7/7
97.36% Lines 37/38

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                                                                                                                                158x                                                                         230x   227x   1x   1x   1x                                                                       14x                                                       14x   14x       14x 14x 14x 14x   14x 1x 1x 13x 1x 1x 1x     14x                                                                                             227x 227x 227x         227x 2x 2x         2x     225x                                         10x                   10x                                         4x                         4x                                                                             8x 8x 8x   8x                    
/**
 * Korean Theme Helper Utilities for HTML Overlays
 * 
 * Provides consistent Korean martial arts cyberpunk theming across all HTML overlay components.
 * These utilities ensure color consistency, bilingual text formatting, and responsive spacing.
 * 
 * @module utils/koreanThemeHelpers
 * @category UI Utilities
 * @korean 한국테마도우미
 */
 
import {
  KOREAN_COLORS,
  FONT_FAMILY,
} from "../types/constants";
import {
  SPACING,
  BORDER_RADIUS,
} from "../types/constants/ui";
import { hexToRgbaString } from "./colorUtils";
 
/**
 * Bilingual text format options
 * @korean 이중언어형식
 */
export type BilingualFormat = "pipe" | "parentheses" | "bracket" | "slash";
 
/**
 * Button variant types for Korean theme
 * @korean 버튼변형
 */
export type KoreanButtonVariant =
  | "primary"
  | "secondary"
  | "danger"
  | "success"
  | "warning";
 
/**
 * Responsive spacing size
 * @korean 반응형간격크기
 */
export type SpacingSize = "xs" | "sm" | "md" | "lg" | "xl" | "xxl";
 
/**
 * Base styles for all Korean-themed overlays
 * 
 * Provides consistent dark background with cyan/gold accents
 * 
 * @param opacity - Background opacity (0-1), default 0.9
 * @returns React.CSSProperties object with Korean theme
 * 
 * @example
 * ```tsx
 * <div style={getKoreanOverlayBaseStyles(0.95)}>
 *   Content
 * </div>
 * ```
 * 
 * @korean 한국오버레이기본스타일얻기
 */
export function getKoreanOverlayBaseStyles(
  opacity: number = 0.9
): React.CSSProperties {
  return {
    backgroundColor: hexToRgbaString(KOREAN_COLORS.UI_BACKGROUND_DARK, opacity),
    border: `2px solid ${hexToRgbaString(KOREAN_COLORS.PRIMARY_CYAN, 0.8)}`,
    borderRadius: `${BORDER_RADIUS.MD}px`,
    fontFamily: FONT_FAMILY.KOREAN,
    color: hexToRgbaString(KOREAN_COLORS.TEXT_PRIMARY),
    boxShadow: `0 4px 20px ${hexToRgbaString(KOREAN_COLORS.BLACK_SOLID, 0.5)}`,
  };
}
 
/**
 * Format bilingual text with Korean and English
 * 
 * Supports multiple formatting styles:
 * - pipe: "한글 | English"
 * - parentheses: "한글 (English)"
 * - bracket: "한글 [English]"
 * - slash: "한글 / English"
 * 
 * @param korean - Korean text
 * @param english - English text
 * @param format - Format style, default "pipe"
 * @returns Formatted bilingual string
 * 
 * @example
 * ```tsx
 * formatBilingualText('공격', 'Attack', 'pipe') // "공격 | Attack"
 * formatBilingualText('방어', 'Defense', 'parentheses') // "방어 (Defense)"
 * ```
 * 
 * @korean 이중언어텍스트형식화
 */
export function formatBilingualText(
  korean: string,
  english: string,
  format: BilingualFormat = "pipe"
): string {
  switch (format) {
    case "pipe":
      return `${korean} | ${english}`;
    case "parentheses":
      return `${korean} (${english})`;
    case "bracket":
      return `${korean} [${english}]`;
    case "slash":
      return `${korean} / ${english}`;
    default:
      return `${korean} | ${english}`;
  }
}
 
/**
 * Get Korean button styles with variant support
 * 
 * Returns consistent button styling based on variant:
 * - primary: Cyan border, gold text
 * - secondary: Gold border, white text
 * - danger: Red border, red text
 * - success: Green border, green text
 * - warning: Orange border, orange text
 * 
 * @param variant - Button variant type
 * @param isHovered - Whether button is hovered
 * @param isPressed - Whether button is pressed
 * @returns React.CSSProperties for button
 * 
 * @example
 * ```tsx
 * <button style={getKoreanButtonStyles('primary', isHovered, isPressed)}>
 *   {formatBilingualText('확인', 'Confirm')}
 * </button>
 * ```
 * 
 * @korean 한국버튼스타일얻기
 */
export function getKoreanButtonStyles(
  variant: KoreanButtonVariant = "primary",
  isHovered: boolean = false,
  isPressed: boolean = false
): React.CSSProperties {
  // Variant-specific colors
  const variantColors = {
    primary: {
      border: KOREAN_COLORS.PRIMARY_CYAN,
      text: KOREAN_COLORS.ACCENT_GOLD,
      hoverBg: KOREAN_COLORS.PRIMARY_CYAN,
    },
    secondary: {
      border: KOREAN_COLORS.ACCENT_GOLD,
      text: KOREAN_COLORS.TEXT_PRIMARY,
      hoverBg: KOREAN_COLORS.ACCENT_GOLD,
    },
    danger: {
      border: KOREAN_COLORS.ACCENT_RED,
      text: KOREAN_COLORS.ACCENT_RED,
      hoverBg: KOREAN_COLORS.ACCENT_RED,
    },
    success: {
      border: KOREAN_COLORS.ACCENT_GREEN,
      text: KOREAN_COLORS.ACCENT_GREEN,
      hoverBg: KOREAN_COLORS.ACCENT_GREEN,
    },
    warning: {
      border: KOREAN_COLORS.WARNING_ORANGE,
      text: KOREAN_COLORS.WARNING_ORANGE,
      hoverBg: KOREAN_COLORS.WARNING_ORANGE,
    },
  };
 
  const colors = variantColors[variant];
 
  let backgroundColor = hexToRgbaString(
    KOREAN_COLORS.UI_BACKGROUND_MEDIUM,
    0.9
  );
  let borderColor = hexToRgbaString(colors.border, 0.8);
  const textColor = hexToRgbaString(colors.text);
  let boxShadow = "none";
  let transform = "scale(1)";
 
  if (isPressed) {
    backgroundColor = hexToRgbaString(colors.hoverBg, 0.2);
    transform = "scale(0.98)";
  } else if (isHovered) {
    backgroundColor = hexToRgbaString(colors.hoverBg, 0.1);
    borderColor = hexToRgbaString(colors.border, 1.0);
    boxShadow = `0 0 10px ${hexToRgbaString(colors.border, 0.5)}`;
  }
 
  return {
    backgroundColor,
    border: `2px solid ${borderColor}`,
    borderRadius: `${BORDER_RADIUS.SM}px`,
    color: textColor,
    fontFamily: FONT_FAMILY.KOREAN,
    fontWeight: "bold",
    padding: `${SPACING.SM}px ${SPACING.MD}px`,
    cursor: "pointer",
    transition: "all 0.2s ease",
    userSelect: "none",
    WebkitUserSelect: "none",
    boxShadow,
    transform,
    textShadow: `0 2px 4px ${hexToRgbaString(KOREAN_COLORS.BLACK_SOLID, 0.5)}`,
  };
}
 
/**
 * Get responsive spacing value
 * 
 * Returns SPACING constant value for consistent spacing across components.
 * Optionally scales for mobile devices.
 * 
 * **IMPORTANT**: This function accepts lowercase size parameters ('xs', 'sm', 'md', etc.)
 * to provide a more intuitive API, then internally converts to uppercase to match
 * SPACING constant keys ('XS', 'SM', 'MD', etc.). This design choice prioritizes
 * developer experience while maintaining compatibility with the SPACING constants.
 * 
 * @param size - Spacing size constant ('xs', 'sm', 'md', 'lg', 'xl', 'xxl')
 * @param isMobile - Whether to apply mobile scaling (87.5% for mobile devices)
 * @returns Spacing value in pixels
 * 
 * @example
 * ```tsx
 * const padding = getResponsiveSpacing('md', isMobile); // 16px desktop, 14px mobile
 * <div style={{ padding: `${padding}px` }}>Content</div>
 * ```
 * 
 * @korean 반응형간격얻기
 */
export function getResponsiveSpacing(
  size: SpacingSize,
  isMobile: boolean = false
): number {
  // Convert lowercase API parameter to uppercase SPACING constant key
  // This provides a more ergonomic API while maintaining internal consistency
  const spacingKey = size.toUpperCase() as keyof typeof SPACING;
  const spacingValue = SPACING[spacingKey];
  const mobileScale = 0.875; // 87.5% for mobile
 
  // Runtime validation: While TypeScript prevents invalid sizes at compile time,
  // this check provides safety for JavaScript consumers and edge cases where
  // type assertions bypass TypeScript checks (e.g., 'as any', dynamic values)
  if (spacingValue === undefined) {
    const fallback = SPACING.MD;
    console.warn(
      `[koreanThemeHelpers:getResponsiveSpacing] Invalid spacing size "${String(
        size
      )}" provided. Falling back to "MD".`
    );
    return isMobile ? Math.round(fallback * mobileScale) : fallback;
  }
 
  return isMobile ? Math.round(spacingValue * mobileScale) : spacingValue;
}
 
/**
 * Get trigram symbol by name
 * 
 * Returns Unicode trigram symbol for visual embellishment
 * 
 * @param name - Trigram name in Korean
 * @returns Unicode trigram symbol
 * 
 * @example
 * ```tsx
 * <div>{getTrigramSymbol('건')} 건 (Heaven)</div>
 * ```
 * 
 * @korean 팔괘기호얻기
 */
export function getTrigramSymbol(
  name: "건" | "태" | "리" | "진" | "손" | "감" | "간" | "곤"
): string {
  const symbols = {
    건: "☰", // Heaven - 乾
    태: "☱", // Lake - 兌
    리: "☲", // Fire - 離
    진: "☳", // Thunder - 震
    손: "☴", // Wind - 巽
    감: "☵", // Water - 坎
    간: "☶", // Mountain - 艮
    곤: "☷", // Earth - 坤
  };
  return symbols[name];
}
 
/**
 * Get Korean color name for documentation
 * 
 * Maps hex color to Korean color name for better documentation
 * 
 * @param hexColor - Hex color value from KOREAN_COLORS
 * @returns Korean name and English translation
 * 
 * @internal Used primarily for JSDoc documentation
 * @korean 한국색상이름얻기
 */
export function getKoreanColorName(hexColor: number): {
  korean: string;
  english: string;
} {
  const colorNames: Record<
    number,
    { korean: string; english: string }
  > = {
    [KOREAN_COLORS.PRIMARY_CYAN]: { korean: "청록", english: "Cyan" },
    [KOREAN_COLORS.ACCENT_GOLD]: { korean: "금색", english: "Gold" },
    [KOREAN_COLORS.ACCENT_RED]: { korean: "빨강", english: "Red" },
    [KOREAN_COLORS.ACCENT_GREEN]: { korean: "초록", english: "Green" },
    [KOREAN_COLORS.WARNING_ORANGE]: { korean: "주황", english: "Orange" },
    [KOREAN_COLORS.TEXT_PRIMARY]: { korean: "흰색", english: "White" },
    [KOREAN_COLORS.UI_BACKGROUND_DARK]: {
      korean: "어두운배경",
      english: "Dark Background",
    },
  };
 
  return (
    colorNames[hexColor] ?? { korean: "알수없음", english: "Unknown" }
  );
}
 
/**
 * Format stat row with bilingual labels
 * 
 * Creates consistent stat row styling for training/combat statistics
 * 
 * @param korean - Korean label
 * @param english - English label
 * @param value - Stat value
 * @param valueColor - Hex color for value text
 * @param isMobile - Mobile responsive mode
 * @returns Stat row configuration object for React rendering
 * 
 * @example
 * ```tsx
 * const statConfig = formatStatRow('점수', 'Score', 1500, KOREAN_COLORS.ACCENT_GOLD, false);
 * ```
 * 
 * @korean 통계행형식화
 */
export function formatStatRow(
  korean: string,
  english: string,
  value: string | number,
  valueColor: number,
  isMobile: boolean
): {
  korean: string;
  english: string;
  value: string | number;
  valueColor: number;
  labelSize: string;
  subLabelSize: string;
  valueSize: string;
} {
  const labelSize = isMobile ? "11px" : "12px";
  const subLabelSize = isMobile ? "8px" : "9px";
  const valueSize = isMobile ? "16px" : "18px";
 
  return {
    korean,
    english,
    value,
    valueColor,
    labelSize,
    subLabelSize,
    valueSize,
  };
}