mycode/myApp/HaruDanim/Shared/DiaryModels.swift
songyc macbook e6b721e368 feat(diary): 도형·텍스트 상자 UX 2차 개편 — 종류별 모양 손잡이·스냅·제자리 텍스트 입력
실사용 보고: 도형이 고정 비율 손잡이 하나뿐이라 모양을 다듬을 수 없고,
텍스트는 시트에 입력하는 방식이 일반 노트 앱과 동떨어져 있었다.

- 종류별 모양 손잡이 (드래그는 페이지 좌표계로 받아 실시간 회전에도 안정):
  · 사각형: 꼭짓점 4개 — 끈 모서리만 움직이고 반대편 고정
  · 원: 상하좌우 4개 — 늘리고 눌러 타원 만들기
  · 선·화살표: 양 끝점 — 반대 끝 고정한 채 길이+방향 동시 조절
  · 사진·텍스트: 우하단 1개 (사진은 원본 비율 유지)
- 정사각형·정원 스냅: |가로-세로| ≤ 10pt면 딱 맞추고 손잡이·테두리
  노란색 강조 + 햅틱. 핀치는 모양 비율 그대로 균등 스케일
- 텍스트 상자 제자리 입력: 선택된 상자를 탭하면 그 자리에서 키보드
  입력·줄바꿈 (생성 직후에도 바로 입력). '글 수정' 시트는 '스타일'
  시트로 재편 — 테두리 켬/끔 + 독립 테두리 색(borderColorHex,
  빈 값 = 글자 색) + 굵기
- borderColorHex 필드 추가 (기본값 — CloudKit·구버전 안전)
- 검증 인자 -diaryTextEdit 추가, 도움말 갱신 + en/ja 번역
- 검증: Debug/Store 빌드, 아이패드 심 손잡이 배치·회전 정합·제자리
  편집 렌더 확인, 카탈로그 missing·stale 0

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NNxA172hNDRpDsJ2qztKPf
2026-08-03 12:49:03 +09:00

238 lines
8.6 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// DiaryModels.swift
// Haru_Danim
//
// () iPad .
// ( ) DiaryEntry :
// - (): ( ) + (+ / )
// - : PencilKit ( ) + /
// CloudKit ( , to-many optional storage + computed ) .
//
import Foundation
import SwiftData
@Model
final class DiaryEntry {
var uuid: UUID = UUID()
/// (DayMath.dayKey )
var dayKey: Date = Date()
/// ( , = )
var moodEmoji: String = ""
/// ( , nil = )
@Attribute(.externalStorage)
var moodImageData: Data? = nil
/// ID (EKEvent.eventIdentifier).
/// .
var calendarEventIDs: [String] = []
/// uuid ( ).
/// , .
var hiddenActionIDs: [String] = []
/// ' ' uuid ( ).
/// CloudKit (§3) .
var hiddenGoalIDs: [String] = []
var createdAt: Date = Date()
var updatedAt: Date = Date()
@Relationship(deleteRule: .cascade, inverse: \DiaryTodo.entry)
var todosStorage: [DiaryTodo]? = []
@Relationship(deleteRule: .cascade, inverse: \DiaryPage.entry)
var pagesStorage: [DiaryPage]? = []
init(dayKey: Date) {
self.dayKey = dayKey
}
var todos: [DiaryTodo] {
get { (todosStorage ?? []).sorted { $0.sortOrder < $1.sortOrder } }
set { todosStorage = newValue }
}
var pages: [DiaryPage] {
get { (pagesStorage ?? []).sorted { $0.index < $1.index } }
set { pagesStorage = newValue }
}
/// : ""
var hasContent: Bool {
!moodEmoji.isEmpty || moodImageData != nil
|| !(todosStorage ?? []).isEmpty
|| (pagesStorage ?? []).contains { $0.hasContent }
}
}
/// ( )
@Model
final class DiaryTodo {
var uuid: UUID = UUID()
var text: String = ""
var isDone: Bool = false
var sortOrder: Int = 0
var entry: DiaryEntry?
init(text: String = "", sortOrder: Int = 0) {
self.text = text
self.sortOrder = sortOrder
}
}
///
@Model
final class DiaryPage {
var uuid: UUID = UUID()
/// (0 = )
var index: Int = 0
/// true = , false =
var lined: Bool = false
/// (pt, 768×1024 )
var lineSpacing: Double = 44
/// (DiaryTemplate.uuid , = ).
/// uuid (/) .
var templateID: String = ""
/// PDF (0)
var templatePageIndex: Int = 0
/// PKDrawing.dataRepresentation()
@Attribute(.externalStorage)
var drawingData: Data = Data()
var entry: DiaryEntry?
@Relationship(deleteRule: .cascade, inverse: \DiaryPageItem.page)
var itemsStorage: [DiaryPageItem]? = []
init(index: Int) {
self.index = index
}
var items: [DiaryPageItem] {
get { (itemsStorage ?? []).sorted { $0.createdAt < $1.createdAt } }
set { itemsStorage = newValue }
}
var hasContent: Bool {
// ( )
!drawingData.isEmpty || !(itemsStorage ?? []).isEmpty || !templateID.isEmpty
}
}
// MARK: - ( )
/// .
/// PDF ** 1** (pageCount ),
/// · . 1 .
@Model
final class DiaryTemplate {
var uuid: UUID = UUID()
var name: String = ""
/// DiaryTemplateKind rawValue
var kindRaw: String = DiaryTemplateKind.pdf.rawValue
/// (PDF )
@Attribute(.externalStorage)
var data: Data = Data()
/// ( )
@Attribute(.externalStorage)
var thumbnailData: Data? = nil
/// ( = 1, PDF = )
var pageCount: Int = 1
var createdAt: Date = Date()
init(name: String, kind: DiaryTemplateKind) {
self.name = name
self.kindRaw = kind.rawValue
}
var kind: DiaryTemplateKind {
get { DiaryTemplateKind(rawValue: kindRaw) ?? .pdf }
set { kindRaw = newValue.rawValue }
}
}
nonisolated enum DiaryTemplateKind: String, CaseIterable {
case pdf
case image
}
/// (, )
@Model
final class DiaryPageItem {
var uuid: UUID = UUID()
/// DiaryItemKind rawValue
var kindRaw: String = DiaryItemKind.photo.rawValue
///
@Attribute(.externalStorage)
var imageData: Data? = nil
/// ( )
var text: String = ""
/// · (hex)
var colorHex: String = "#2F6B4F"
/// (0...1)
var centerX: Double = 0.5
var centerY: Double = 0.3
///
var widthRatio: Double = 0.35
/// "" (widthRatio ).
/// 0 = (defaultAspect) ( · ).
/// .
var heightRatio: Double = 0
var rotationDegrees: Double = 0
/// · (pt). 0 =
var lineWidth: Double = 0
/// · ( )
var filled: Bool = false
/// (pt). = 10
var cornerRadius: Double = -1
/// (pt). 0 = 24
var fontSize: Double = 0
///
var textBold: Bool = false
/// "" = , "center", "trailing"
var textAlignRaw: String = ""
///
var textBorder: Bool = false
/// (hex). =
var borderColorHex: String = ""
var createdAt: Date = Date()
var page: DiaryPage?
init(kind: DiaryItemKind) {
self.kindRaw = kind.rawValue
}
var kind: DiaryItemKind {
get { DiaryItemKind(rawValue: kindRaw) ?? .photo }
set { kindRaw = newValue.rawValue }
}
}
nonisolated enum DiaryItemKind: String, CaseIterable {
case photo
case rectangle
case ellipse
case arrow
case line
case text
/// (widthRatio )
var defaultAspect: Double {
switch self {
case .photo: return 1
case .rectangle: return 0.7
case .ellipse: return 0.7
case .arrow: return 0.35
case .line: return 0.1
case .text: return 0.4
}
}
/// lineWidth (0) ( )
var defaultLineWidth: Double {
switch self {
case .arrow: return 6
case .text: return 2
default: return 5
}
}
}