Bringt cards-native auf 0 SwiftLint-Violations bei 75 Files. Build-Status
unverändert grün (xcodebuild iOS Debug).
.swiftlint.yml
- identifier_name excludes erweitert um math/index-Konventionen
(i, j, n, m, x, y, w, h, r, g, b, a, c, d, s, f, p, q, t, l) —
in algorithmischem Code klarer als verbose
- opening_brace disabled — kollidiert mit SwiftFormats
wrapMultilineStatementBraces (SwiftFormat ist im Pre-Commit-Hook
und gewinnt)
Code-Modernisierungen (real, nicht nur Annotations)
- Cloze.swift: regex-Tuple bekommt `swiftlint:disable large_tuple`-
Region — Regex-Output-Type ist Builder-bedingt nicht reduzierbar
- Media.swift: `data(using: .utf8)` → `Data(s.utf8)` (non-failable),
`String(data:as:)` → `String(bytes:encoding:)`
- CardsTheme.swift: HSL-Wert-Typ statt anonymes 3-Tupel —
konkretere Call-Sites, kein `large_tuple`-Warning mehr
- MediaCache.swift: `CacheEntry`-Struct statt 3-Tupel im Prune-Pfad
- GradeQueue / MediaCache / StudySession / MarketplaceStore: OSLog-
Interpolations auf lokale Variablen ziehen — fixt Swift-6-Strict-
Concurrency-Fail bei Actor-isolated-Property-Zugriff aus
@Sendable-Autoclosure
- DeckMutations.swift, MarketplaceModeration.swift: verschachtelte
VersionInfo-Sub-Types auf Top-Level (`PullUpdateVersion`,
`OwnedMarketplaceVersion`) — fixt `nesting`-Warning
- Tests/UnitTests/*.swift: alle `""".data(using: .utf8)!` migriert auf
`Data("""…""".utf8)`; force-cast `as!` in MutationEncodingTests
durch guard-let + throw ersetzt
Pragmatische Disables (mit Doc-Comment-Begründung)
- DeckEditorView / MarketplacePublishView / DeckDetailView /
PublicDeckView / DeckListView / CardEditorView / CardsAPI:
`swiftlint:disable type_body_length` (+ teilweise file_length)
als Region-Disable mit `enable` nach dem Struct. Begründung im
Doc-Comment: Multi-State-Maschinen mit shared Toolbar + Sheets;
Aufspalten würde nur @Binding-Plumbing produzieren
Auto-Format-Aufräumung
- Redundante `Sendable`-Conformance entfernt (Swift 6 leitet das
bei Wert-Typen mit Sendable-Mitgliedern automatisch ab)
- EnvironmentValues nutzt jetzt @Entry-Macro statt manueller
EnvironmentKey-Boilerplate
- Brace-Reformatting + Import-Sortierung auf allen 75 Files
Ergebnis: 80 Warnings + 3 Errors → 0 / 0.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
156 lines
6 KiB
Swift
156 lines
6 KiB
Swift
import SwiftUI
|
|
|
|
/// Rendert die Karten-Inhalte je nach `CardType`. Front-/Back-Seite
|
|
/// werden über `isFlipped` gesteuert.
|
|
///
|
|
/// β-2 deckt `basic`, `basic-reverse`, `cloze` ab. Restliche Typen
|
|
/// zeigen einen Placeholder mit Hinweis auf die kommende Phase.
|
|
struct CardRenderer: View {
|
|
let card: ReviewCard
|
|
let subIndex: Int
|
|
let isFlipped: Bool
|
|
|
|
var body: some View {
|
|
Group {
|
|
switch card.type {
|
|
case .basic:
|
|
basicView(front: "front", back: "back")
|
|
case .basicReverse:
|
|
// sub_index 0 = front→back, sub_index 1 = back→front
|
|
if subIndex == 0 {
|
|
basicView(front: "front", back: "back")
|
|
} else {
|
|
basicView(front: "back", back: "front")
|
|
}
|
|
case .cloze:
|
|
clozeView
|
|
case .imageOcclusion:
|
|
imageOcclusionView
|
|
case .audioFront:
|
|
audioFrontView
|
|
case .multipleChoice:
|
|
MultipleChoiceCardView(card: card, isFlipped: isFlipped)
|
|
case .typing:
|
|
TypingCardView(card: card, isFlipped: isFlipped)
|
|
}
|
|
}
|
|
.padding(24)
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
}
|
|
|
|
private func basicView(front frontKey: String, back backKey: String) -> some View {
|
|
VStack(spacing: 16) {
|
|
text(card.fields[frontKey] ?? "")
|
|
.font(.title2)
|
|
.foregroundStyle(CardsTheme.foreground)
|
|
if isFlipped {
|
|
Divider().background(CardsTheme.border)
|
|
text(card.fields[backKey] ?? "")
|
|
.font(.title3)
|
|
.foregroundStyle(CardsTheme.mutedForeground)
|
|
}
|
|
}
|
|
}
|
|
|
|
@ViewBuilder
|
|
private var clozeView: some View {
|
|
let raw = card.fields["text"] ?? ""
|
|
let clusterId = Cloze.clusterId(for: raw, subIndex: subIndex) ?? 1
|
|
let rendered = isFlipped
|
|
? Cloze.renderAnswer(raw, activeClusterId: clusterId)
|
|
: Cloze.renderPrompt(raw, activeClusterId: clusterId)
|
|
VStack(spacing: 12) {
|
|
text(rendered)
|
|
.font(.title3)
|
|
.foregroundStyle(CardsTheme.foreground)
|
|
}
|
|
}
|
|
|
|
@ViewBuilder
|
|
private var imageOcclusionView: some View {
|
|
let imageRef = card.fields["image_ref"] ?? ""
|
|
let maskJSON = card.fields["mask_regions"] ?? "[]"
|
|
let regions = MaskRegions.parse(maskJSON)
|
|
let activeRegion = regions.indices.contains(subIndex) ? regions[subIndex] : nil
|
|
|
|
VStack(spacing: 12) {
|
|
GeometryReader { geo in
|
|
ZStack(alignment: .topLeading) {
|
|
RemoteImage(mediaId: imageRef, contentMode: .fit)
|
|
.frame(width: geo.size.width, height: geo.size.height)
|
|
ForEach(regions) { region in
|
|
let isActive = region.id == activeRegion?.id
|
|
// Front: aktive Maske opak, andere transparent.
|
|
// Back: alle Masken transparent (Bild komplett sichtbar).
|
|
if !isFlipped, isActive {
|
|
Rectangle()
|
|
.fill(CardsTheme.primary.opacity(0.92))
|
|
.frame(
|
|
width: region.w * geo.size.width,
|
|
height: region.h * geo.size.height
|
|
)
|
|
.offset(x: region.x * geo.size.width, y: region.y * geo.size.height)
|
|
.overlay(
|
|
Text(region.label?.isEmpty == false ? region.label! : "?")
|
|
.font(.caption.weight(.bold))
|
|
.foregroundStyle(CardsTheme.primaryForeground)
|
|
.offset(x: region.x * geo.size.width, y: region.y * geo.size.height),
|
|
alignment: .topLeading
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.aspectRatio(4 / 3, contentMode: .fit)
|
|
|
|
if isFlipped, let label = activeRegion?.label, !label.isEmpty {
|
|
Text(label)
|
|
.font(.title3.weight(.semibold))
|
|
.foregroundStyle(CardsTheme.primary)
|
|
}
|
|
if let note = card.fields["note"], !note.isEmpty {
|
|
Text(note)
|
|
.font(.caption)
|
|
.foregroundStyle(CardsTheme.mutedForeground)
|
|
}
|
|
}
|
|
}
|
|
|
|
@ViewBuilder
|
|
private var audioFrontView: some View {
|
|
let audioRef = card.fields["audio_ref"] ?? ""
|
|
VStack(spacing: 16) {
|
|
AudioPlayerButton(mediaId: audioRef)
|
|
if isFlipped {
|
|
Divider().background(CardsTheme.border)
|
|
text(card.fields["back"] ?? "")
|
|
.font(.title3)
|
|
.foregroundStyle(CardsTheme.foreground)
|
|
}
|
|
}
|
|
}
|
|
|
|
private var placeholderView: some View {
|
|
VStack(spacing: 8) {
|
|
Image(systemName: "questionmark.square.dashed")
|
|
.font(.largeTitle)
|
|
.foregroundStyle(CardsTheme.mutedForeground)
|
|
Text("Card-Type »\(card.type.rawValue)« kommt in einer späteren Phase")
|
|
.font(.caption)
|
|
.multilineTextAlignment(.center)
|
|
.foregroundStyle(CardsTheme.mutedForeground)
|
|
}
|
|
}
|
|
|
|
/// Markdown-Bold (`**...**`) wird auf SwiftUI's AttributedString gemappt.
|
|
private func text(_ markdown: String) -> some View {
|
|
let attributed = (try? AttributedString(
|
|
markdown: markdown,
|
|
options: AttributedString.MarkdownParsingOptions(
|
|
interpretedSyntax: .inlineOnlyPreservingWhitespace
|
|
)
|
|
)) ?? AttributedString(markdown)
|
|
return Text(attributed)
|
|
.multilineTextAlignment(.center)
|
|
}
|
|
}
|