krz/daybyday

iOS learning games for young children: days, months, seasons, numbers, letters, animals and more. education ios kids swift https://krz.sh/apps/daybyday/

Commit 753b20e234

753b20e2347ec94c9abbdef192d219a76993b3b1

parent: d032beeaa4

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-22 22:10 UTC

Add Qlty config; share card shell and grid across categories

- TapCard holds the rounded card, highlight, tap bounce, and
  accessibility every category card repeated; SymbolLabel the
  symbol-over-name content five of them shared.
- CardGrid replaces eleven copies of the ScrollView/LazyVGrid screen.
  Renders of every card and screen are pixel-identical before and after.
- render-voice-elevenlabs.py: plan and remove_stale split out of main.
- Qlty: switch statements excluded from Swift duplication (enum lookup
  tables), return_statements and file_complexity disabled.

Layout: unified · split

.qlty/.gitignore added +7
@@ -0,0 +1,7 @@
1*
2!configs
3!configs/**
4!hooks
5!hooks/**
6!qlty.toml
7!.gitignore
.qlty/qlty.toml added +49
@@ -0,0 +1,49 @@
1config_version = "0"
2
3exclude_patterns = [
4 "**/vendor/**",
5 "**/node_modules/**",
6 "**/testdata/**",
7 "**/dist/**",
8 "**/.build/**",
9 "**/build/**",
10 "**/*.min.*",
11 "**/generated/**",
12 ".claude/**",
13 "**/Pods/**",
14]
15
16test_patterns = [
17 "**/test/**",
18 "**/tests/**",
19 "**/Tests/**",
20 "**/*_test.*",
21 "**/test_*.*",
22 "**/*.test.*",
23 "**/*Tests.swift",
24 "e2e/**",
25]
26
27[[source]]
28name = "default"
29default = true
30
31[[plugin]]
32name = "osv-scanner"
33
34[[plugin]]
35name = "trufflehog"
36
37# Early returns are guard clauses, which keep the happy path unindented.
38[smells.return_statements]
39enabled = false
40
41# Total file complexity is the sum of its functions, which function_complexity
42# already checks.
43[smells.file_complexity]
44enabled = false
45
46# Exhaustive switch-over-enum lookup tables (name, symbol, color per case)
47# share shape but not content.
48[language.swift.smells.duplication]
49filter_patterns = ["(import_declaration _)", "(switch_statement _)"]
AlphabetView.swift +2 −12
@@ -8,19 +8,9 @@ import SwiftUI
8/// Displays all 26 letters A–Z as large, tappable cards in a scrollable grid. 8/// Displays all 26 letters A–Z as large, tappable cards in a scrollable grid.
9/// Uses a smaller minimum size to fit more letters across the screen. 9/// Uses a smaller minimum size to fit more letters across the screen.
10struct AlphabetView: View { 10struct AlphabetView: View {
11 private let columns = [
12 GridItem(.adaptive(minimum: 140, maximum: 300), spacing: 20)
13 ]
14
15 var body: some View { 11 var body: some View {
16 ScrollView { 12 CardGrid(items: LearnLetter.allCases, column: GridItem(.adaptive(minimum: 140, maximum: 300), spacing: 20), spacing: 20, minHeight: 160) { letter in
17 LazyVGrid(columns: columns, spacing: 20) { 13 LetterCard(letter: letter)
18 ForEach(LearnLetter.allCases) { letter in
19 LetterCard(letter: letter)
20 .frame(minHeight: 160)
21 }
22 }
23 .padding(32)
24 } 14 }
25 .onDisappear { CardVoice.shared.cancel() } 15 .onDisappear { CardVoice.shared.cancel() }
26 } 16 }
AnimalCard.swift +3 −20
@@ -9,14 +9,11 @@ import SwiftUI
9/// Tapping the card plays a bounce animation and speaks the animal name aloud. 9/// Tapping the card plays a bounce animation and speaks the animal name aloud.
10struct AnimalCard: View { 10struct AnimalCard: View {
11 let animal: LearnAnimal 11 let animal: LearnAnimal
12 @State private var isTapped = false
13 12
14 var body: some View { 13 var body: some View {
15 ZStack { 14 TapCard(color: animal.color, label: animal.name) {
16 RoundedRectangle(cornerRadius: 32, style: .continuous) 15 CardVoice.shared.say(animal.cardLine, after: animal.sound)
17 .fill(animal.color) 16 } content: {
18 .shadow(color: animal.color.opacity(0.4), radius: 8, y: 4)
19
20 VStack(spacing: 16) { 17 VStack(spacing: 16) {
21 AnimalIcon(animal: animal) 18 AnimalIcon(animal: animal)
22 .font(.system(size: 64)) 19 .font(.system(size: 64))
@@ -29,20 +26,6 @@ struct AnimalCard: View {
29 } 26 }
30 .padding(16) 27 .padding(16)
31 } 28 }
32 .scaleEffect(isTapped ? 1.12 : 1.0)
33 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
34 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
35 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
36 .onTapGesture {
37 isTapped = true
38 CardVoice.shared.say(animal.cardLine, after: animal.sound)
39 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
40 isTapped = false
41 }
42 }
43 .accessibilityElement(children: .ignore)
44 .accessibilityLabel(animal.name)
45 .accessibilityAddTraits(.isButton)
46 } 29 }
47} 30}
48 31
AnimalsView.swift +2 −12
@@ -8,19 +8,9 @@ import SwiftUI
8/// Displays 12 animals as large, tappable cards in a scrollable grid. 8/// Displays 12 animals as large, tappable cards in a scrollable grid.
9/// Adapts between 1 and 2 columns depending on available width. 9/// Adapts between 1 and 2 columns depending on available width.
10struct AnimalsView: View { 10struct AnimalsView: View {
11 private let columns = [
12 GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24)
13 ]
14
15 var body: some View { 11 var body: some View {
16 ScrollView { 12 CardGrid(items: LearnAnimal.allCases) { animal in
17 LazyVGrid(columns: columns, spacing: 24) { 13 AnimalCard(animal: animal)
18 ForEach(LearnAnimal.allCases) { animal in
19 AnimalCard(animal: animal)
20 .frame(minHeight: 200)
21 }
22 }
23 .padding(32)
24 } 14 }
25 .onDisappear { CardVoice.shared.cancel() } 15 .onDisappear { CardVoice.shared.cancel() }
26 } 16 }
BodyPartCard.swift +3 −30
@@ -9,40 +9,13 @@ import SwiftUI
9/// Tapping the card plays a bounce animation and speaks the body part name aloud. 9/// Tapping the card plays a bounce animation and speaks the body part name aloud.
10struct BodyPartCard: View { 10struct BodyPartCard: View {
11 let bodyPart: LearnBodyPart 11 let bodyPart: LearnBodyPart
12 @State private var isTapped = false
13 12
14 var body: some View { 13 var body: some View {
15 ZStack { 14 TapCard(color: bodyPart.color, label: bodyPart.name) {
16 RoundedRectangle(cornerRadius: 32, style: .continuous)
17 .fill(bodyPart.color)
18 .shadow(color: bodyPart.color.opacity(0.4), radius: 8, y: 4)
19
20 VStack(spacing: 16) {
21 Image(systemName: bodyPart.symbol)
22 .font(.system(size: 64))
23 .foregroundStyle(.white)
24 .symbolRenderingMode(.hierarchical)
25
26 Text(bodyPart.name)
27 .font(.heading(32))
28 .foregroundStyle(.white)
29 }
30 .padding(16)
31 }
32 .scaleEffect(isTapped ? 1.12 : 1.0)
33 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
34 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
35 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
36 .onTapGesture {
37 isTapped = true
38 SpeechSynthesizer.shared.speak(bodyPart.name) 15 SpeechSynthesizer.shared.speak(bodyPart.name)
39 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { 16 } content: {
40 isTapped = false 17 SymbolLabel(symbol: bodyPart.symbol, name: bodyPart.name)
41 }
42 } 18 }
43 .accessibilityElement(children: .ignore)
44 .accessibilityLabel(bodyPart.name)
45 .accessibilityAddTraits(.isButton)
46 } 19 }
47} 20}
48 21
BodyPartsView.swift +2 −12
@@ -7,19 +7,9 @@ import SwiftUI
7 7
8/// Displays all 12 body parts as large, tappable cards in a scrollable grid. 8/// Displays all 12 body parts as large, tappable cards in a scrollable grid.
9struct BodyPartsView: View { 9struct BodyPartsView: View {
10 private let columns = [
11 GridItem(.adaptive(minimum: 280), spacing: 24)
12 ]
13
14 var body: some View { 10 var body: some View {
15 ScrollView { 11 CardGrid(items: LearnBodyPart.allCases, column: .narrowCards) { part in
16 LazyVGrid(columns: columns, spacing: 24) { 12 BodyPartCard(bodyPart: part)
17 ForEach(LearnBodyPart.allCases) { part in
18 BodyPartCard(bodyPart: part)
19 .frame(minHeight: 200)
20 }
21 }
22 .padding(32)
23 } 13 }
24 } 14 }
25} 15}
ColorCard.swift +3 −20
@@ -8,32 +8,15 @@ import SwiftUI
8/// A single large card filled with a color. Tapping speaks the color name aloud. 8/// A single large card filled with a color. Tapping speaks the color name aloud.
9struct ColorCard: View { 9struct ColorCard: View {
10 let learnColor: LearnColor 10 let learnColor: LearnColor
11 @State private var isTapped = false
12 11
13 var body: some View { 12 var body: some View {
14 ZStack { 13 TapCard(color: learnColor.color, label: learnColor.name) {
15 RoundedRectangle(cornerRadius: 32, style: .continuous) 14 SpeechSynthesizer.shared.speak(learnColor.name)
16 .fill(learnColor.color) 15 } content: {
17 .shadow(color: learnColor.color.opacity(0.4), radius: 8, y: 4)
18
19 Text(learnColor.name) 16 Text(learnColor.name)
20 .font(.heading(36)) 17 .font(.heading(36))
21 .foregroundStyle(learnColor.labelColor) 18 .foregroundStyle(learnColor.labelColor)
22 } 19 }
23 .scaleEffect(isTapped ? 1.12 : 1.0)
24 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
25 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
26 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
27 .onTapGesture {
28 isTapped = true
29 SpeechSynthesizer.shared.speak(learnColor.name)
30 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
31 isTapped = false
32 }
33 }
34 .accessibilityElement(children: .ignore)
35 .accessibilityLabel(learnColor.name)
36 .accessibilityAddTraits(.isButton)
37 } 20 }
38} 21}
39 22
ColorsView.swift +2 −12
@@ -8,19 +8,9 @@ import SwiftUI
8/// Displays 10 colors as large, tappable cards in a scrollable grid. 8/// Displays 10 colors as large, tappable cards in a scrollable grid.
9/// Adapts between 1 and 2 columns depending on available width. 9/// Adapts between 1 and 2 columns depending on available width.
10struct ColorsView: View { 10struct ColorsView: View {
11 private let columns = [
12 GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24)
13 ]
14
15 var body: some View { 11 var body: some View {
16 ScrollView { 12 CardGrid(items: LearnColor.allCases) { color in
17 LazyVGrid(columns: columns, spacing: 24) { 13 ColorCard(learnColor: color)
18 ForEach(LearnColor.allCases) { color in
19 ColorCard(learnColor: color)
20 .frame(minHeight: 200)
21 }
22 }
23 .padding(32)
24 } 14 }
25 } 15 }
26} 16}
DayByDay/CardGrid.swift added +46
@@ -0,0 +1,46 @@
1//
2// CardGrid.swift
3// DayByDay
4//
5
6import SwiftUI
7
8/// Large, tappable cards in a scrollable adaptive grid.
9struct CardGrid<Item: Identifiable, Card: View, Header: View>: View {
10 let items: [Item]
11 var column = GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24)
12 var spacing: CGFloat = 24
13 var minHeight: CGFloat = 200
14 @ViewBuilder var header: () -> Header
15 @ViewBuilder let card: (Item) -> Card
16
17 var body: some View {
18 ScrollView {
19 header()
20 LazyVGrid(columns: [column], spacing: spacing) {
21 ForEach(items) { item in
22 card(item)
23 .frame(minHeight: minHeight)
24 }
25 }
26 .padding(32)
27 }
28 }
29}
30
31extension CardGrid where Header == EmptyView {
32 init(
33 items: [Item],
34 column: GridItem = GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24),
35 spacing: CGFloat = 24,
36 minHeight: CGFloat = 200,
37 @ViewBuilder card: @escaping (Item) -> Card
38 ) {
39 self.init(items: items, column: column, spacing: spacing, minHeight: minHeight, header: { EmptyView() }, card: card)
40 }
41}
42
43extension GridItem {
44 /// Columns for cards with longer names, which need a narrower minimum to fit two across.
45 static let narrowCards = GridItem(.adaptive(minimum: 280), spacing: 24)
46}
DayByDay/DayCard.swift +9 −47
@@ -12,35 +12,17 @@ struct DayCard: View {
12 let day: DayOfWeek 12 let day: DayOfWeek
13 var isHighlighted = false 13 var isHighlighted = false
14 var picture: DayPictureKind? = nil 14 var picture: DayPictureKind? = nil
15 @State private var isTapped = false
16
17 private var cardScale: CGFloat {
18 if isTapped { return 1.12 }
19 if isHighlighted { return 1.04 }
20 return 1.0
21 }
22 15
23 var body: some View { 16 var body: some View {
24 ZStack { 17 TapCard(
25 RoundedRectangle(cornerRadius: 32, style: .continuous) 18 color: day.color,
26 .fill(day.color) 19 label: picture.map { "\(day.name), \($0.name)" } ?? day.name,
27 .shadow(color: day.color.opacity(0.4), radius: 8, y: 4) 20 isHighlighted: isHighlighted
28 // Glow on the card only: on the label it would lower the contrast. 21 ) {
29 .shadow(color: isHighlighted ? .white.opacity(0.8) : .clear, radius: 12) 22 CardVoice.shared.say(Lines.dayCard(day, picture: picture), after: nil)
30 23 } content: {
31 VStack(spacing: 16) { 24 SymbolLabel(symbol: day.symbol, name: day.name)
32 Image(systemName: day.symbol) 25 } badge: {
33 .font(.system(size: 64))
34 .foregroundStyle(.white)
35 .symbolRenderingMode(.hierarchical)
36
37 Text(day.name)
38 .font(.heading(32))
39 .foregroundStyle(.white)
40 }
41 .padding(16)
42 }
43 .overlay(alignment: .topTrailing) {
44 if let picture { 26 if let picture {
45 Image(systemName: picture.symbol) 27 Image(systemName: picture.symbol)
46 .font(.system(size: 30, weight: .bold)) 28 .font(.system(size: 30, weight: .bold))
@@ -51,26 +33,6 @@ struct DayCard: View {
51 .accessibilityHidden(true) 33 .accessibilityHidden(true)
52 } 34 }
53 } 35 }
54 .overlay {
55 if isHighlighted {
56 RoundedRectangle(cornerRadius: 32, style: .continuous)
57 .strokeBorder(.white, lineWidth: 5)
58 }
59 }
60 .scaleEffect(cardScale)
61 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
62 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
63 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
64 .onTapGesture {
65 isTapped = true
66 CardVoice.shared.say(Lines.dayCard(day, picture: picture), after: nil)
67 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
68 isTapped = false
69 }
70 }
71 .accessibilityElement(children: .ignore)
72 .accessibilityLabel(picture.map { "\(day.name), \($0.name)" } ?? day.name)
73 .accessibilityAddTraits(.isButton)
74 } 36 }
75} 37}
76 38
DayByDay/DaysOfWeekView.swift +2 −12
@@ -11,19 +11,9 @@ import SwiftUI
11struct DaysOfWeekView: View { 11struct DaysOfWeekView: View {
12 @Environment(ProfileSession.self) private var session 12 @Environment(ProfileSession.self) private var session
13 13
14 private let columns = [
15 GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24)
16 ]
17
18 var body: some View { 14 var body: some View {
19 ScrollView { 15 CardGrid(items: DayOfWeek.allCases) { day in
20 LazyVGrid(columns: columns, spacing: 24) { 16 DayCard(day: day, isHighlighted: day == .current, picture: picture(on: day))
21 ForEach(DayOfWeek.allCases) { day in
22 DayCard(day: day, isHighlighted: day == .current, picture: picture(on: day))
23 .frame(minHeight: 200)
24 }
25 }
26 .padding(32)
27 } 17 }
28 .onDisappear { CardVoice.shared.cancel() } 18 .onDisappear { CardVoice.shared.cancel() }
29 } 19 }
DayByDay/MonthCard.swift +3 −44
@@ -10,54 +10,13 @@ import SwiftUI
10struct MonthCard: View { 10struct MonthCard: View {
11 let month: MonthOfYear 11 let month: MonthOfYear
12 var isHighlighted = false 12 var isHighlighted = false
13 @State private var isTapped = false
14
15 private var cardScale: CGFloat {
16 if isTapped { return 1.12 }
17 if isHighlighted { return 1.04 }
18 return 1.0
19 }
20 13
21 var body: some View { 14 var body: some View {
22 ZStack { 15 TapCard(color: month.color, label: month.name, isHighlighted: isHighlighted) {
23 RoundedRectangle(cornerRadius: 32, style: .continuous)
24 .fill(month.color)
25 .shadow(color: month.color.opacity(0.4), radius: 8, y: 4)
26 // Glow on the card only: on the label it would lower the contrast.
27 .shadow(color: isHighlighted ? .white.opacity(0.8) : .clear, radius: 12)
28
29 VStack(spacing: 16) {
30 Image(systemName: month.symbol)
31 .font(.system(size: 64))
32 .foregroundStyle(.white)
33 .symbolRenderingMode(.hierarchical)
34
35 Text(month.name)
36 .font(.heading(32))
37 .foregroundStyle(.white)
38 }
39 .padding(16)
40 }
41 .overlay {
42 if isHighlighted {
43 RoundedRectangle(cornerRadius: 32, style: .continuous)
44 .strokeBorder(.white, lineWidth: 5)
45 }
46 }
47 .scaleEffect(cardScale)
48 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
49 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
50 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
51 .onTapGesture {
52 isTapped = true
53 SpeechSynthesizer.shared.speak(month.name) 16 SpeechSynthesizer.shared.speak(month.name)
54 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { 17 } content: {
55 isTapped = false 18 SymbolLabel(symbol: month.symbol, name: month.name)
56 }
57 } 19 }
58 .accessibilityElement(children: .ignore)
59 .accessibilityLabel(month.name)
60 .accessibilityAddTraits(.isButton)
61 } 20 }
62} 21}
63 22
DayByDay/MonthsOfYearView.swift +2 −12
@@ -8,19 +8,9 @@ import SwiftUI
8/// Displays all twelve months as large, tappable cards in a scrollable grid. 8/// Displays all twelve months as large, tappable cards in a scrollable grid.
9/// Adapts between 1 and 2 columns depending on available width. 9/// Adapts between 1 and 2 columns depending on available width.
10struct MonthsOfYearView: View { 10struct MonthsOfYearView: View {
11 private let columns = [
12 GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24)
13 ]
14
15 var body: some View { 11 var body: some View {
16 ScrollView { 12 CardGrid(items: MonthOfYear.allCases) { month in
17 LazyVGrid(columns: columns, spacing: 24) { 13 MonthCard(month: month, isHighlighted: month == .current)
18 ForEach(MonthOfYear.allCases) { month in
19 MonthCard(month: month, isHighlighted: month == .current)
20 .frame(minHeight: 200)
21 }
22 }
23 .padding(32)
24 } 14 }
25 } 15 }
26} 16}
DayByDay/SeasonCard.swift +3 −44
@@ -10,54 +10,13 @@ import SwiftUI
10struct SeasonCard: View { 10struct SeasonCard: View {
11 let season: Season 11 let season: Season
12 var isHighlighted = false 12 var isHighlighted = false
13 @State private var isTapped = false
14
15 private var cardScale: CGFloat {
16 if isTapped { return 1.12 }
17 if isHighlighted { return 1.04 }
18 return 1.0
19 }
20 13
21 var body: some View { 14 var body: some View {
22 ZStack { 15 TapCard(color: season.color, label: season.name, isHighlighted: isHighlighted) {
23 RoundedRectangle(cornerRadius: 32, style: .continuous)
24 .fill(season.color)
25 .shadow(color: season.color.opacity(0.4), radius: 8, y: 4)
26 // Glow on the card only: on the label it would lower the contrast.
27 .shadow(color: isHighlighted ? .white.opacity(0.8) : .clear, radius: 12)
28
29 VStack(spacing: 16) {
30 Image(systemName: season.symbol)
31 .font(.system(size: 64))
32 .foregroundStyle(.white)
33 .symbolRenderingMode(.hierarchical)
34
35 Text(season.name)
36 .font(.heading(32))
37 .foregroundStyle(.white)
38 }
39 .padding(16)
40 }
41 .overlay {
42 if isHighlighted {
43 RoundedRectangle(cornerRadius: 32, style: .continuous)
44 .strokeBorder(.white, lineWidth: 5)
45 }
46 }
47 .scaleEffect(cardScale)
48 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
49 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
50 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
51 .onTapGesture {
52 isTapped = true
53 SpeechSynthesizer.shared.speak(season.name) 16 SpeechSynthesizer.shared.speak(season.name)
54 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { 17 } content: {
55 isTapped = false 18 SymbolLabel(symbol: season.symbol, name: season.name)
56 }
57 } 19 }
58 .accessibilityElement(children: .ignore)
59 .accessibilityLabel(season.name)
60 .accessibilityAddTraits(.isButton)
61 } 20 }
62} 21}
63 22
DayByDay/SeasonsView.swift +2 −12
@@ -8,19 +8,9 @@ import SwiftUI
8/// Displays all four seasons as large, tappable cards in a scrollable grid. 8/// Displays all four seasons as large, tappable cards in a scrollable grid.
9/// Adapts between 1 and 2 columns depending on available width. 9/// Adapts between 1 and 2 columns depending on available width.
10struct SeasonsView: View { 10struct SeasonsView: View {
11 private let columns = [
12 GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24)
13 ]
14
15 var body: some View { 11 var body: some View {
16 ScrollView { 12 CardGrid(items: Season.allCases) { season in
17 LazyVGrid(columns: columns, spacing: 24) { 13 SeasonCard(season: season, isHighlighted: season == .current)
18 ForEach(Season.allCases) { season in
19 SeasonCard(season: season, isHighlighted: season == .current)
20 .frame(minHeight: 200)
21 }
22 }
23 .padding(32)
24 } 14 }
25 } 15 }
26} 16}
DayByDay/TapCard.swift added +90
@@ -0,0 +1,90 @@
1//
2// TapCard.swift
3// DayByDay
4//
5
6import SwiftUI
7
8/// The rounded, colored card shared by every learning category.
9/// Tapping it plays a bounce animation and runs `onTap`, which speaks the card.
10/// A highlighted card (today's day, month, or season) is enlarged, glows, and has a white border.
11struct TapCard<Content: View, Badge: View>: View {
12 let color: Color
13 let label: String
14 var isHighlighted = false
15 let onTap: () -> Void
16 @ViewBuilder let content: () -> Content
17 @ViewBuilder var badge: () -> Badge
18 @State private var isTapped = false
19
20 private var cardScale: CGFloat {
21 if isTapped { return 1.12 }
22 if isHighlighted { return 1.04 }
23 return 1.0
24 }
25
26 var body: some View {
27 ZStack {
28 RoundedRectangle(cornerRadius: 32, style: .continuous)
29 .fill(color)
30 .shadow(color: color.opacity(0.4), radius: 8, y: 4)
31 // Glow on the card only: on the label it would lower the contrast.
32 .shadow(color: isHighlighted ? .white.opacity(0.8) : .clear, radius: 12)
33
34 content()
35 }
36 .overlay(alignment: .topTrailing) { badge() }
37 .overlay {
38 if isHighlighted {
39 RoundedRectangle(cornerRadius: 32, style: .continuous)
40 .strokeBorder(.white, lineWidth: 5)
41 }
42 }
43 .scaleEffect(cardScale)
44 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
45 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
46 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
47 .onTapGesture {
48 isTapped = true
49 onTap()
50 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
51 isTapped = false
52 }
53 }
54 .accessibilityElement(children: .ignore)
55 .accessibilityLabel(label)
56 .accessibilityAddTraits(.isButton)
57 }
58}
59
60extension TapCard where Badge == EmptyView {
61 init(
62 color: Color,
63 label: String,
64 isHighlighted: Bool = false,
65 onTap: @escaping () -> Void,
66 @ViewBuilder content: @escaping () -> Content
67 ) {
68 self.init(color: color, label: label, isHighlighted: isHighlighted, onTap: onTap, content: content, badge: { EmptyView() })
69 }
70}
71
72/// An SF Symbol above a name, the content of most category cards.
73struct SymbolLabel: View {
74 let symbol: String
75 let name: String
76
77 var body: some View {
78 VStack(spacing: 16) {
79 Image(systemName: symbol)
80 .font(.system(size: 64))
81 .foregroundStyle(.white)
82 .symbolRenderingMode(.hierarchical)
83
84 Text(name)
85 .font(.heading(32))
86 .foregroundStyle(.white)
87 }
88 .padding(16)
89 }
90}
FoodCard.swift +3 −21
@@ -10,14 +10,11 @@ import SwiftUI
10/// Each food displays its emoji at large size for instant recognition. 10/// Each food displays its emoji at large size for instant recognition.
11struct FoodCard: View { 11struct FoodCard: View {
12 let food: LearnFood 12 let food: LearnFood
13 @State private var isTapped = false
14 13
15 var body: some View { 14 var body: some View {
16 ZStack { 15 TapCard(color: food.color, label: food.name) {
17 RoundedRectangle(cornerRadius: 32, style: .continuous) 16 SpeechSynthesizer.shared.speak(food.name)
18 .fill(food.color) 17 } content: {
19 .shadow(color: food.color.opacity(0.4), radius: 8, y: 4)
20
21 VStack(spacing: 16) { 18 VStack(spacing: 16) {
22 Text(food.emoji) 19 Text(food.emoji)
23 .font(.system(size: 72)) 20 .font(.system(size: 72))
@@ -28,22 +25,7 @@ struct FoodCard: View {
28 } 25 }
29 .padding(16) 26 .padding(16)
30 } 27 }
31 .scaleEffect(isTapped ? 1.12 : 1.0)
32 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
33 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
34 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
35 .onTapGesture {
36 isTapped = true
37 SpeechSynthesizer.shared.speak(food.name)
38 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
39 isTapped = false
40 }
41 }
42 .accessibilityElement(children: .ignore)
43 .accessibilityLabel(food.name)
44 .accessibilityAddTraits(.isButton)
45 } 28 }
46
47} 29}
48 30
49// MARK: - Food model 31// MARK: - Food model
FoodView.swift +2 −12
@@ -7,19 +7,9 @@ import SwiftUI
7 7
8/// Displays all 12 fruits and vegetables as large, tappable cards in a scrollable grid. 8/// Displays all 12 fruits and vegetables as large, tappable cards in a scrollable grid.
9struct FoodView: View { 9struct FoodView: View {
10 private let columns = [
11 GridItem(.adaptive(minimum: 280), spacing: 24)
12 ]
13
14 var body: some View { 10 var body: some View {
15 ScrollView { 11 CardGrid(items: LearnFood.allCases, column: .narrowCards) { food in
16 LazyVGrid(columns: columns, spacing: 24) { 12 FoodCard(food: food)
17 ForEach(LearnFood.allCases) { food in
18 FoodCard(food: food)
19 .frame(minHeight: 200)
20 }
21 }
22 .padding(32)
23 } 13 }
24 } 14 }
25} 15}
LetterCard.swift +3 −20
@@ -9,32 +9,15 @@ import SwiftUI
9/// Tapping the card plays a bounce animation and speaks the letter aloud. 9/// Tapping the card plays a bounce animation and speaks the letter aloud.
10struct LetterCard: View { 10struct LetterCard: View {
11 let letter: LearnLetter 11 let letter: LearnLetter
12 @State private var isTapped = false
13 12
14 var body: some View { 13 var body: some View {
15 ZStack { 14 TapCard(color: letter.color, label: letter.spokenName) {
16 RoundedRectangle(cornerRadius: 32, style: .continuous) 15 CardVoice.shared.say(letter.cardLine, after: nil)
17 .fill(letter.color) 16 } content: {
18 .shadow(color: letter.color.opacity(0.4), radius: 8, y: 4)
19
20 Text(letter.character) 17 Text(letter.character)
21 .font(.heading(64, weight: .heavy)) 18 .font(.heading(64, weight: .heavy))
22 .foregroundStyle(.white) 19 .foregroundStyle(.white)
23 } 20 }
24 .scaleEffect(isTapped ? 1.12 : 1.0)
25 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
26 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
27 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
28 .onTapGesture {
29 isTapped = true
30 CardVoice.shared.say(letter.cardLine, after: nil)
31 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
32 isTapped = false
33 }
34 }
35 .accessibilityElement(children: .ignore)
36 .accessibilityLabel(letter.spokenName)
37 .accessibilityAddTraits(.isButton)
38 } 21 }
39} 22}
40 23
NumberCard.swift +3 −34
@@ -10,22 +10,11 @@ import SwiftUI
10struct NumberCard: View { 10struct NumberCard: View {
11 let number: LearnNumber 11 let number: LearnNumber
12 var isHighlighted = false 12 var isHighlighted = false
13 @State private var isTapped = false
14
15 private var cardScale: CGFloat {
16 if isTapped { return 1.12 }
17 if isHighlighted { return 1.04 }
18 return 1.0
19 }
20 13
21 var body: some View { 14 var body: some View {
22 ZStack { 15 TapCard(color: number.color, label: number.name, isHighlighted: isHighlighted) {
23 RoundedRectangle(cornerRadius: 32, style: .continuous) 16 SpeechSynthesizer.shared.speak(number.name)
24 .fill(number.color) 17 } content: {
25 .shadow(color: number.color.opacity(0.4), radius: 8, y: 4)
26 // Glow on the card only: on the label it would lower the contrast.
27 .shadow(color: isHighlighted ? .white.opacity(0.8) : .clear, radius: 12)
28
29 VStack(spacing: 10) { 18 VStack(spacing: 10) {
30 Text("\(number.numeral)") 19 Text("\(number.numeral)")
31 .font(.heading(60, weight: .heavy)) 20 .font(.heading(60, weight: .heavy))
@@ -41,26 +30,6 @@ struct NumberCard: View {
41 } 30 }
42 .padding(16) 31 .padding(16)
43 } 32 }
44 .overlay {
45 if isHighlighted {
46 RoundedRectangle(cornerRadius: 32, style: .continuous)
47 .strokeBorder(.white, lineWidth: 5)
48 }
49 }
50 .scaleEffect(cardScale)
51 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
52 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
53 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
54 .onTapGesture {
55 isTapped = true
56 SpeechSynthesizer.shared.speak(number.name)
57 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
58 isTapped = false
59 }
60 }
61 .accessibilityElement(children: .ignore)
62 .accessibilityLabel(number.name)
63 .accessibilityAddTraits(.isButton)
64 } 33 }
65} 34}
66 35
NumbersView.swift +2 −15
@@ -8,22 +8,9 @@ import SwiftUI
8/// Displays numbers 1–10 as large, tappable cards in a scrollable grid. 8/// Displays numbers 1–10 as large, tappable cards in a scrollable grid.
9/// Adapts between 1 and 2 columns depending on available width. 9/// Adapts between 1 and 2 columns depending on available width.
10struct NumbersView: View { 10struct NumbersView: View {
11 private let columns = [
12 GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24)
13 ]
14
15 var body: some View { 11 var body: some View {
16 ScrollView { 12 CardGrid(items: LearnNumber.allCases) { number in
17 LazyVGrid(columns: columns, spacing: 24) { 13 NumberCard(number: number, isHighlighted: number == .current)
18 ForEach(LearnNumber.allCases) { number in
19 NumberCard(
20 number: number,
21 isHighlighted: number == .current
22 )
23 .frame(minHeight: 200)
24 }
25 }
26 .padding(32)
27 } 14 }
28 } 15 }
29} 16}
ShapeCard.swift +3 −20
@@ -9,14 +9,11 @@ import SwiftUI
9/// Tapping the card plays a bounce animation and speaks the shape name aloud. 9/// Tapping the card plays a bounce animation and speaks the shape name aloud.
10struct ShapeCard: View { 10struct ShapeCard: View {
11 let shape: LearnShape 11 let shape: LearnShape
12 @State private var isTapped = false
13 12
14 var body: some View { 13 var body: some View {
15 ZStack { 14 TapCard(color: shape.color, label: shape.name) {
16 RoundedRectangle(cornerRadius: 32, style: .continuous) 15 SpeechSynthesizer.shared.speak(shape.name)
17 .fill(shape.color) 16 } content: {
18 .shadow(color: shape.color.opacity(0.4), radius: 8, y: 4)
19
20 VStack(spacing: 16) { 17 VStack(spacing: 16) {
21 shape.shapeView 18 shape.shapeView
22 .frame(width: 80, height: 80) 19 .frame(width: 80, height: 80)
@@ -28,20 +25,6 @@ struct ShapeCard: View {
28 } 25 }
29 .padding(16) 26 .padding(16)
30 } 27 }
31 .scaleEffect(isTapped ? 1.12 : 1.0)
32 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
33 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
34 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
35 .onTapGesture {
36 isTapped = true
37 SpeechSynthesizer.shared.speak(shape.name)
38 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
39 isTapped = false
40 }
41 }
42 .accessibilityElement(children: .ignore)
43 .accessibilityLabel(shape.name)
44 .accessibilityAddTraits(.isButton)
45 } 28 }
46} 29}
47 30
ShapesView.swift +2 −12
@@ -8,19 +8,9 @@ import SwiftUI
8/// Displays 8 shapes as large, tappable cards in a scrollable grid. 8/// Displays 8 shapes as large, tappable cards in a scrollable grid.
9/// Adapts between 1 and 2 columns depending on available width. 9/// Adapts between 1 and 2 columns depending on available width.
10struct ShapesView: View { 10struct ShapesView: View {
11 private let columns = [
12 GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24)
13 ]
14
15 var body: some View { 11 var body: some View {
16 ScrollView { 12 CardGrid(items: LearnShape.allCases) { shape in
17 LazyVGrid(columns: columns, spacing: 24) { 13 ShapeCard(shape: shape)
18 ForEach(LearnShape.allCases) { shape in
19 ShapeCard(shape: shape)
20 .frame(minHeight: 200)
21 }
22 }
23 .padding(32)
24 } 14 }
25 } 15 }
26} 16}
WeatherCard.swift +3 −30
@@ -9,40 +9,13 @@ import SwiftUI
9/// Tapping the card plays a bounce animation and speaks the weather name aloud. 9/// Tapping the card plays a bounce animation and speaks the weather name aloud.
10struct WeatherCard: View { 10struct WeatherCard: View {
11 let weather: LearnWeather 11 let weather: LearnWeather
12 @State private var isTapped = false
13 12
14 var body: some View { 13 var body: some View {
15 ZStack { 14 TapCard(color: weather.color, label: weather.name) {
16 RoundedRectangle(cornerRadius: 32, style: .continuous)
17 .fill(weather.color)
18 .shadow(color: weather.color.opacity(0.4), radius: 8, y: 4)
19
20 VStack(spacing: 16) {
21 Image(systemName: weather.symbol)
22 .font(.system(size: 64))
23 .foregroundStyle(.white)
24 .symbolRenderingMode(.hierarchical)
25
26 Text(weather.name)
27 .font(.heading(32))
28 .foregroundStyle(.white)
29 }
30 .padding(16)
31 }
32 .scaleEffect(isTapped ? 1.12 : 1.0)
33 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
34 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
35 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
36 .onTapGesture {
37 isTapped = true
38 SpeechSynthesizer.shared.speak(weather.name) 15 SpeechSynthesizer.shared.speak(weather.name)
39 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { 16 } content: {
40 isTapped = false 17 SymbolLabel(symbol: weather.symbol, name: weather.name)
41 }
42 } 18 }
43 .accessibilityElement(children: .ignore)
44 .accessibilityLabel(weather.name)
45 .accessibilityAddTraits(.isButton)
46 } 19 }
47} 20}
48 21
WeatherView.swift +3 −13
@@ -8,16 +8,12 @@ import SwiftUI
8/// Displays all 8 weather types as large, tappable cards in a scrollable grid. 8/// Displays all 8 weather types as large, tappable cards in a scrollable grid.
9/// Shaking the device, or tapping the rain button, makes it rain. 9/// Shaking the device, or tapping the rain button, makes it rain.
10struct WeatherView: View { 10struct WeatherView: View {
11 private let columns = [
12 GridItem(.adaptive(minimum: 280), spacing: 24)
13 ]
14
15 @State private var raining = false 11 @State private var raining = false
16 /// Bumped when the screen goes away, so a pending stop does nothing. 12 /// Bumped when the screen goes away, so a pending stop does nothing.
17 @State private var generation = 0 13 @State private var generation = 0
18 14
19 var body: some View { 15 var body: some View {
20 ScrollView { 16 CardGrid(items: LearnWeather.allCases, column: .narrowCards) {
21 Button(action: rain) { 17 Button(action: rain) {
22 Label("Shake for rain!", systemImage: "cloud.rain.fill") 18 Label("Shake for rain!", systemImage: "cloud.rain.fill")
23 .font(.heading(22)) 19 .font(.heading(22))
@@ -27,14 +23,8 @@ struct WeatherView: View {
27 } 23 }
28 .buttonStyle(.plain) 24 .buttonStyle(.plain)
29 .padding(.top, 16) 25 .padding(.top, 16)
30 26 } card: { weather in
31 LazyVGrid(columns: columns, spacing: 24) { 27 WeatherCard(weather: weather)
32 ForEach(LearnWeather.allCases) { weather in
33 WeatherCard(weather: weather)
34 .frame(minHeight: 200)
35 }
36 }
37 .padding(32)
38 } 28 }
39 .overlay { RainOverlay(isActive: raining) } 29 .overlay { RainOverlay(isActive: raining) }
40 .onShake(rain) 30 .onShake(rain)
scripts/render-voice-elevenlabs.py +21 −12
@@ -120,6 +120,25 @@ def encode(audio: array.array, out: Path) -> None:
120 str(wav), str(out)], check=True) 120 str(wav), str(out)], check=True)
121 121
122 122
123def plan(lines: list, old: dict, out: Path, redo: list) -> tuple[list, list]:
124 """Splits lines into manifest entries to keep and (text, seed) pairs to render."""
125 kept, todo = [], []
126 for text in lines:
127 entry = old.get(text)
128 if entry and text not in redo and entry.get("engine") == MODEL and (out / entry["file"]).exists():
129 kept.append(entry)
130 else:
131 seed = entry["seed"] + 1 if entry and text in redo else 0
132 todo.append((text, seed))
133 return kept, todo
134
135
136def remove_stale(out: Path, keep: set) -> None:
137 for stale in [*out.glob("*.aac"), *out.glob("*.m4a")]:
138 if stale.name not in keep:
139 stale.unlink()
140
141
123def main() -> None: 142def main() -> None:
124 parser = argparse.ArgumentParser() 143 parser = argparse.ArgumentParser()
125 parser.add_argument("lines", type=Path) 144 parser.add_argument("lines", type=Path)
@@ -142,14 +161,7 @@ def main() -> None:
142 manifest_path = args.out / "voice-manifest.json" 161 manifest_path = args.out / "voice-manifest.json"
143 old = {e["text"]: e for e in json.loads(manifest_path.read_text())} if manifest_path.exists() else {} 162 old = {e["text"]: e for e in json.loads(manifest_path.read_text())} if manifest_path.exists() else {}
144 163
145 kept, todo = [], [] 164 kept, todo = plan(lines, old, args.out, args.redo)
146 for text in lines:
147 entry = old.get(text)
148 if entry and text not in args.redo and entry.get("engine") == MODEL and (args.out / entry["file"]).exists():
149 kept.append(entry)
150 else:
151 seed = entry["seed"] + 1 if entry and text in args.redo else 0
152 todo.append((text, seed))
153 165
154 def job(item): 166 def job(item):
155 text, seed = item 167 text, seed = item
@@ -167,10 +179,7 @@ def main() -> None:
167 write_manifest(manifest_path, kept + done + [e for t, e in old.items() if t not in fresh and e not in kept]) 179 write_manifest(manifest_path, kept + done + [e for t, e in old.items() if t not in fresh and e not in kept])
168 180
169 entries = kept + done 181 entries = kept + done
170 keep = {e["file"] for e in entries} 182 remove_stale(args.out, {e["file"] for e in entries})
171 for stale in [*args.out.glob("*.aac"), *args.out.glob("*.m4a")]:
172 if stale.name not in keep:
173 stale.unlink()
174 write_manifest(manifest_path, entries) 183 write_manifest(manifest_path, entries)
175 print(f"{len(done)} rendered, {len(kept)} kept") 184 print(f"{len(done)} rendered, {len(kept)} kept")
176 185