/** * Trump card drawn in SVG. Big corner index for readability on PC and phones. Number cards and the back are drawn here; * J/Q/K and the two jokers show real card artwork by Dmitry Fomin (Wikimedia Commons, CC0 — ./court/ATTRIBUTION.txt), * bundled from our own origin as small WebP files that load only when such a card is on screen. */ import type { CSSProperties } from 'react'; /** Credit for the court/joker artwork (CC0 needs none, but we say thanks); shown in the rules of the games using these cards. */ export const PLAYING_CARD_CREDIT = '트럼프 그림카드(J·Q·K)·조커 그림: Dmitry Fomin — Wikimedia Commons "SVG English pattern playing cards", "Atlas deck joker", CC0 1.0(퍼블릭 도메인). 그림 부분만 잘라 작게 줄여 썼어요.'; /** * URL of the court/joker picture ("JS".."KC", "X1" black joker, "X2" red joker). Vite turns this pattern into hashed * /assets/ files; in tests it is just a file URL. */ export const courtSrc = (id: string): string => new URL(`./court/${id}.webp`, import.meta.url).href; const SUIT_SYMBOL: Record = { S: '♠', H: '♥', D: '◆', C: '♣' }; const SUIT_KO: Record = { S: '스페이드', H: '하트', D: '다이아', C: '클로버' }; const RANK_LABEL: Record = { T: '10', J: 'J', Q: 'Q', K: 'K', A: 'A' }; const FACE_KO: Record = { J: '잭', Q: '퀸', K: '킹', A: '에이스' }; export type CardSize = 'sm' | 'md' | 'lg'; const WIDTH: Record = { sm: 44, md: 64, lg: 88 }; export interface PlayingCardProps { /** e.g. "AS", "TD", "X1" (joker). null = face down. */ card: string | null; size?: CardSize; /** Exact width in px (overrides `size`). */ width?: number; selected?: boolean; dimmed?: boolean; highlight?: boolean; onClick?: () => void; title?: string; style?: CSSProperties; /** Colour-blind friendly: 4-colour suits. */ fourColor?: boolean; } export function cardAria(card: string | null): string { if (!card) return '뒤집힌 카드'; if (card.startsWith('X')) return '조커'; const r = card[0]!; return `${SUIT_KO[card[1]!]} ${FACE_KO[r] ?? RANK_LABEL[r] ?? r}`; } export function PlayingCard({ card, size = 'md', width, selected, dimmed, highlight, onClick, title, style, fourColor }: PlayingCardProps) { const w = width ?? WIDTH[size]; const h = Math.round(w * 1.4); const lift = selected ? -Math.round(w * 0.22) : 0; const common: CSSProperties = { width: w, height: h, flex: 'none', transform: `translateY(${lift}px)`, transition: 'transform 0.12s ease', cursor: onClick ? 'pointer' : 'default', opacity: dimmed ? 0.45 : 1, filter: highlight ? 'drop-shadow(0 0 6px #f59e0b)' : 'drop-shadow(0 1px 2px rgba(0,0,0,0.25))', ...style, }; const Tag = onClick ? 'button' : 'span'; const btnReset: CSSProperties = onClick ? { padding: 0, border: 0, background: 'none' } : {}; if (!card) { return ( ); } const joker = card.startsWith('X'); const suit = card[1]!; const rank = card[0]!; const color = joker ? card === 'X1' ? '#111827' : '#dc2626' : fourColor ? { S: '#111827', H: '#dc2626', D: '#2563eb', C: '#15803d' }[suit]! : suit === 'H' || suit === 'D' ? '#dc2626' : '#111827'; const label = joker ? '★' : (RANK_LABEL[rank] ?? rank); const sym = joker ? '' : SUIT_SYMBOL[suit]; return ( {joker ? ( ) : 'JQK'.includes(rank) ? ( <> {/* picture frame like a real court card, with a notch at top-left so the big index stays readable */} ) : ( {sym} )} {label} {sym} ); }