import SwiftUI import UIKit // MARK: - 색상 팔레트 (다크 전용) extension Color { init(hex: UInt32) { self.init( .sRGB, red: Double((hex >> 16) & 0xFF) / 255, green: Double((hex >> 8) & 0xFF) / 255, blue: Double(hex & 0xFF) / 255 ) } } enum Theme { static let bg = Color(hex: 0x0B0E13) static let surface = Color(hex: 0x161B25) static let surfaceHi = Color(hex: 0x202836) static let stroke = Color.white.opacity(0.07) static let accent = Color(hex: 0x3BE39F) static let accentSoft = Color(hex: 0x3BE39F).opacity(0.14) static let onAccent = Color(hex: 0x07281B) static let danger = Color(hex: 0xFF7A7A) static let warn = Color(hex: 0xFFC94D) static let sunday = Color(hex: 0xFF8A80) static let saturday = Color(hex: 0x7EB6FF) static let textPrimary = Color(hex: 0xF3F6FA) static let textSecondary = Color(hex: 0x8D99AD) static let accentGradient = LinearGradient( colors: [Color(hex: 0x5CF0B6), Color(hex: 0x1FC98B)], startPoint: .topLeading, endPoint: .bottomTrailing ) } // MARK: - 공용 스타일 struct CardBackground: ViewModifier { var cornerRadius: CGFloat = 18 func body(content: Content) -> some View { content .background( RoundedRectangle(cornerRadius: cornerRadius, style: .continuous) .fill(Theme.surface) .overlay( RoundedRectangle(cornerRadius: cornerRadius, style: .continuous) .strokeBorder(Theme.stroke, lineWidth: 1) ) ) } } extension View { func cardStyle(cornerRadius: CGFloat = 18) -> some View { modifier(CardBackground(cornerRadius: cornerRadius)) } } // MARK: - 햅틱 enum Haptics { static func success() { UINotificationFeedbackGenerator().notificationOccurred(.success) } static func warning() { UINotificationFeedbackGenerator().notificationOccurred(.warning) } static func tap() { UIImpactFeedbackGenerator(style: .light).impactOccurred() } static func shutter() { UIImpactFeedbackGenerator(style: .medium).impactOccurred() } } // MARK: - 달력 유틸 enum KoreanCalendar { static let calendar: Calendar = { var c = Calendar(identifier: .gregorian) c.locale = Locale(identifier: "ko_KR") return c }() static let weekdaySymbols = ["일", "월", "화", "수", "목", "금", "토"] /// 해당 월의 그리드 셀 배열. 앞쪽 빈칸은 nil, 이후 1...말일. static func gridDays(year: Int, month: Int) -> [Int?] { let comps = DateComponents(year: year, month: month, day: 1) guard let first = calendar.date(from: comps), let range = calendar.range(of: .day, in: .month, for: first) else { return [] } let firstWeekday = calendar.component(.weekday, from: first) let leading = (firstWeekday - calendar.firstWeekday + 7) % 7 return Array(repeating: nil, count: leading) + range.map { $0 } } static func date(year: Int, month: Int, day: Int) -> Date? { calendar.date(from: DateComponents(year: year, month: month, day: day)) } static func isToday(year: Int, month: Int, day: Int) -> Bool { let t = calendar.dateComponents([.year, .month, .day], from: .now) return t.year == year && t.month == month && t.day == day } /// 오늘부터 해당 날짜까지 남은 일수 (음수면 지난 날짜) static func daysFromToday(to date: Date) -> Int { let today = calendar.startOfDay(for: .now) let target = calendar.startOfDay(for: date) return calendar.dateComponents([.day], from: today, to: target).day ?? 0 } static func weekdayColor(columnIndex: Int) -> Color { switch columnIndex { case 0: return Theme.sunday case 6: return Theme.saturday default: return Theme.textSecondary } } } // MARK: - 이미지 유틸 extension UIImage { func downscaled(maxDimension: CGFloat) -> UIImage { let longest = max(size.width, size.height) guard longest > maxDimension, longest > 0 else { return self } let ratio = maxDimension / longest let newSize = CGSize(width: size.width * ratio, height: size.height * ratio) let format = UIGraphicsImageRendererFormat.default() format.scale = 1 return UIGraphicsImageRenderer(size: newSize, format: format).image { _ in draw(in: CGRect(origin: .zero, size: newSize)) } } }