android-skills 0.0.0-stage → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +276 -2
  3. package/android-ui-minimal/SKILL.md +98 -0
  4. package/android-ui-minimal/references/anti-slop-checklist.md +61 -0
  5. package/android-ui-minimal/references/clarifying-questions.md +55 -0
  6. package/android-ui-minimal/references/color-and-contrast.md +104 -0
  7. package/android-ui-minimal/references/compose-patterns.md +120 -0
  8. package/android-ui-minimal/references/reconstruction-workflow.md +74 -0
  9. package/android-ui-minimal/references/typography-spacing.md +93 -0
  10. package/android-ui-minimal/scripts/contrast.py +68 -0
  11. package/android-ui-minimal/scripts/gen_tokens.py +165 -0
  12. package/android-ui-minimal/scripts/lint_ui.py +189 -0
  13. package/android-ui-security-review/SKILL.md +93 -0
  14. package/android-ui-security-review/references/checklist.md +95 -0
  15. package/android-ui-security-review/references/components-intents.md +74 -0
  16. package/android-ui-security-review/references/compose-risks.md +86 -0
  17. package/android-ui-security-review/references/input-and-state.md +77 -0
  18. package/android-ui-security-review/references/network-storage.md +87 -0
  19. package/android-ui-security-review/references/report-template.md +71 -0
  20. package/android-ui-security-review/references/sensitive-data-ui.md +73 -0
  21. package/android-ui-security-review/references/webview.md +105 -0
  22. package/android-ui-security-review/scripts/scan.py +411 -0
  23. package/bin/android-skills.js +47 -0
  24. package/install.py +337 -0
  25. package/opencode/commands/ui-minimal.md +9 -0
  26. package/opencode/commands/ui-security.md +9 -0
  27. package/package.json +43 -4
@@ -0,0 +1,120 @@
1
+ # Pola Compose (dan padanan XML)
2
+
3
+ ## Struktur file
4
+
5
+ ```
6
+ ui/
7
+ theme/Color.kt Type.kt Theme.kt Spacing.kt
8
+ components/ (komponen kecil yang dipakai ulang)
9
+ screen/<nama>/ <Nama>Screen.kt <Nama>ViewModel.kt <Nama>UiState.kt
10
+ ```
11
+
12
+ Aturan: satu composable layar menerima `state` dan `onEvent` (state hoisting). Tidak ada akses repository atau network di dalam composable.
13
+
14
+ ## Kerangka layar
15
+
16
+ ```kotlin
17
+ @Composable
18
+ fun NotesScreen(
19
+ state: NotesUiState,
20
+ onEvent: (NotesEvent) -> Unit,
21
+ modifier: Modifier = Modifier,
22
+ ) {
23
+ Scaffold(
24
+ modifier = modifier,
25
+ topBar = { NotesTopBar(onSearch = { onEvent(NotesEvent.OpenSearch) }) },
26
+ containerColor = MaterialTheme.colorScheme.background,
27
+ ) { inner ->
28
+ when (state) {
29
+ NotesUiState.Loading -> LoadingBox(Modifier.padding(inner))
30
+ is NotesUiState.Error -> ErrorBox(state.message, { onEvent(NotesEvent.Retry) }, Modifier.padding(inner))
31
+ is NotesUiState.Content ->
32
+ if (state.items.isEmpty()) EmptyBox("Belum ada catatan", Modifier.padding(inner))
33
+ else NotesList(state.items, { onEvent(NotesEvent.Open(it)) }, Modifier.padding(inner))
34
+ }
35
+ }
36
+ }
37
+ ```
38
+
39
+ ## Baris list polos (tanpa card)
40
+
41
+ ```kotlin
42
+ @Composable
43
+ fun NoteRow(title: String, subtitle: String, onClick: () -> Unit) {
44
+ Column(
45
+ Modifier
46
+ .fillMaxWidth()
47
+ .clickable(onClick = onClick)
48
+ .heightIn(min = 56.dp)
49
+ .padding(horizontal = Space.lg, vertical = Space.md),
50
+ verticalArrangement = Arrangement.spacedBy(Space.xs),
51
+ ) {
52
+ Text(title, style = MaterialTheme.typography.titleMedium, maxLines = 1, overflow = TextOverflow.Ellipsis)
53
+ Text(subtitle, style = MaterialTheme.typography.bodyMedium,
54
+ color = MaterialTheme.colorScheme.onSurfaceVariant, maxLines = 2, overflow = TextOverflow.Ellipsis)
55
+ }
56
+ }
57
+ ```
58
+
59
+ Divider: `HorizontalDivider(color = MaterialTheme.colorScheme.outlineVariant)` dengan inset 16dp.
60
+
61
+ ## Tombol
62
+
63
+ - Aksi utama: `Button` (satu per layar).
64
+ - Sekunder: `OutlinedButton` atau `TextButton`.
65
+ - Tinggi minimum 48dp. Lebar penuh hanya untuk aksi utama di form atau bottom bar.
66
+
67
+ ## Edge-to-edge dan insets
68
+
69
+ ```kotlin
70
+ // Activity
71
+ enableEdgeToEdge()
72
+ // Scaffold sudah memberi inner padding. Untuk konten manual:
73
+ Modifier.windowInsetsPadding(WindowInsets.safeDrawing)
74
+ ```
75
+
76
+ Gunakan `imePadding()` untuk layar berisi field.
77
+
78
+ ## Preview wajib
79
+
80
+ ```kotlin
81
+ @Preview(name = "Terang") @Composable private fun P1() = AppTheme(darkTheme = false) { NotesScreen(sampleState, {}) }
82
+ @Preview(name = "Gelap", uiMode = UI_MODE_NIGHT_YES) @Composable private fun P2() = AppTheme(darkTheme = true) { NotesScreen(sampleState, {}) }
83
+ @Preview(name = "Font besar", fontScale = 1.5f) @Composable private fun P3() = AppTheme { NotesScreen(sampleState, {}) }
84
+ ```
85
+
86
+ ## Aksesibilitas
87
+
88
+ ```kotlin
89
+ Icon(Icons.Outlined.Delete, contentDescription = "Hapus catatan")
90
+ Modifier.semantics { heading() } // judul seksi
91
+ Modifier.clearAndSetSemantics { } // dekoratif
92
+ Modifier.minimumInteractiveComponentSize() // target 48dp
93
+ ```
94
+
95
+ ## Performa dasar
96
+
97
+ - `remember` untuk objek mahal, `derivedStateOf` untuk state turunan.
98
+ - Parameter lambda stabil. Hindari membuat objek baru di setiap rekomposisi di dalam list.
99
+ - `LazyColumn(key = { it.id }, contentType = { ... })`.
100
+ - Gambar: Coil dengan ukuran tetap agar tidak melompat.
101
+
102
+ ## Padanan XML Views
103
+
104
+ | Compose | XML |
105
+ |---|---|
106
+ | `MaterialTheme.colorScheme.*` | Atribut tema `?attr/colorSurface`, `?attr/colorOnSurface` |
107
+ | `Space.lg` | `@dimen/space_lg` (di `dimens.xml`) |
108
+ | `typography.titleMedium` | `?attr/textAppearanceTitleMedium` |
109
+ | `Scaffold` | `CoordinatorLayout` + `MaterialToolbar` |
110
+ | `LazyColumn` | `RecyclerView` + `ListAdapter` + `DiffUtil` |
111
+
112
+ Jangan menaruh warna hex di layout XML. Definisikan di `colors.xml` dan `values-night/colors.xml`, rujuk lewat atribut tema.
113
+
114
+ ## Yang tidak boleh dilakukan
115
+
116
+ - `Color(0xFF...)` di dalam layar.
117
+ - `fontSize = 15.sp` ad hoc.
118
+ - `Modifier.padding(13.dp)` angka di luar skala.
119
+ - Memanggil `viewModel()` di dalam komponen kecil yang dipakai ulang.
120
+ - Menyembunyikan konten penting di balik gestur tanpa alternatif.
@@ -0,0 +1,74 @@
1
+ # Alur rekonstruksi UI
2
+
3
+ Dipakai saat user memberi screenshot, layar lama, atau deskripsi dan meminta dibuat ulang lebih bersih.
4
+
5
+ ## 1. Inventarisasi
6
+
7
+ Tulis daftar apa yang ada di layar, tanpa menilai:
8
+ - Elemen (judul, daftar, field, tombol, navigasi)
9
+ - Data yang ditampilkan
10
+ - Aksi yang bisa dilakukan
11
+ - State yang terlihat (kosong, loading, error, terpilih)
12
+
13
+ Jika dari screenshot, sebutkan hal yang tidak bisa dipastikan (font, ukuran asli, warna tepat) dan tanyakan jika penting.
14
+
15
+ ## 2. Tetapkan hierarki
16
+
17
+ Jawab tiga hal:
18
+ 1. Apa satu tujuan utama layar ini?
19
+ 2. Apa satu aksi utama?
20
+ 3. Apa yang bisa dibuang atau dipindahkan ke layar lain?
21
+
22
+ Elemen yang tidak menjawab tiga pertanyaan itu adalah kandidat dihapus atau diturunkan.
23
+
24
+ ## 3. Petakan ke token
25
+
26
+ Ganti setiap nilai acak dengan token:
27
+ - Warna: pilih peran terdekat (`surface`, `onSurfaceVariant`, `primary`).
28
+ - Spacing: bulatkan ke skala 4dp.
29
+ - Tipografi: pilih style terdekat dari skala.
30
+ - Radius: pilih dari tiga level.
31
+
32
+ Catat pemetaan yang mengubah tampilan secara berarti untuk dilaporkan.
33
+
34
+ ## 4. Sederhanakan
35
+
36
+ Urutan pemangkasan:
37
+ 1. Hapus dekorasi tanpa fungsi (gradien, bayangan berlapis, ikon hiasan).
38
+ 2. Gabungkan container bersarang (card dalam card).
39
+ 3. Samakan alignment ke satu tepi kiri.
40
+ 4. Kurangi jumlah gaya teks.
41
+ 5. Kurangi jumlah warna ke satu aksen + netral.
42
+
43
+ ## 5. Bangun
44
+
45
+ Ikuti `compose-patterns.md`. Mulai dari state dan event, lalu komposisi, lalu preview.
46
+
47
+ ## 6. Verifikasi
48
+
49
+ - Preview terang, gelap, font scale 1.5, lebar 360dp.
50
+ - `python3 scripts/lint_ui.py <path>`.
51
+ - Kontras pasangan warna utama.
52
+ - Checklist di `anti-slop-checklist.md`.
53
+
54
+ ## 7. Laporan
55
+
56
+ Format singkat:
57
+
58
+ ```
59
+ Selesai: <layar>
60
+ Keputusan: <aksen, struktur daftar, dll>
61
+ Diubah: <file>
62
+ Sengaja tidak dilakukan: <hal yang tidak diubah dan alasannya>
63
+ Perlu konfirmasi: <jika ada>
64
+ ```
65
+
66
+ ## Menjaga perilaku
67
+
68
+ Rekonstruksi tidak boleh mengubah perilaku. Pertahankan:
69
+ - Nama dan tanda tangan fungsi publik yang dipanggil dari luar layar
70
+ - Navigasi dan argumen route
71
+ - ID untuk test (`testTag`, `android:id`) jika sudah dipakai
72
+ - Teks yang dirujuk test atau localization (ubah lewat `strings.xml`, jangan hardcode)
73
+
74
+ Jika harus mengubahnya, sebutkan secara eksplisit di laporan.
@@ -0,0 +1,93 @@
1
+ # Tipografi, spacing, radius, elevasi
2
+
3
+ ## Spacing (kelipatan 4dp)
4
+
5
+ | Token | Nilai | Pemakaian |
6
+ |---|---|---|
7
+ | `xs` | 4dp | Jarak ikon ke label, antar baris teks rapat |
8
+ | `sm` | 8dp | Jarak dalam komponen |
9
+ | `md` | 12dp | Padding vertikal baris list |
10
+ | `lg` | 16dp | Margin layar, jarak antar grup kecil |
11
+ | `xl` | 24dp | Jarak antar seksi |
12
+ | `xxl` | 32dp | Jarak seksi besar, ruang atas header |
13
+ | `touch` | 48dp | Tinggi minimum target sentuh |
14
+
15
+ Margin horizontal layar: 16dp di ponsel, 24dp di tablet kecil. Konsisten di seluruh aplikasi.
16
+
17
+ ```kotlin
18
+ object Space {
19
+ val xs = 4.dp; val sm = 8.dp; val md = 12.dp
20
+ val lg = 16.dp; val xl = 24.dp; val xxl = 32.dp
21
+ }
22
+ ```
23
+
24
+ Aturan ritme: jarak di dalam grup lebih kecil dari jarak antar grup. Jika semua jarak sama, hierarki hilang.
25
+
26
+ ## Tipografi
27
+
28
+ Pakai skala Material 3 lewat `MaterialTheme.typography`. Jangan membuat ukuran baru di layar.
29
+
30
+ | Peran | Style | Catatan |
31
+ |---|---|---|
32
+ | Judul layar | `titleLarge` | Satu per layar |
33
+ | Judul seksi | `titleMedium` | Weight medium |
34
+ | Body | `bodyLarge` / `bodyMedium` | Weight regular |
35
+ | Keterangan | `bodySmall` | `onSurfaceVariant` |
36
+ | Tombol | `labelLarge` | |
37
+
38
+ Aturan:
39
+ - Maksimal dua weight per layar (regular dan medium, atau regular dan semibold).
40
+ - Jangan memakai huruf kapital semua untuk teks panjang. Judul pendek saja, dan hindari `letterSpacing` agresif.
41
+ - Panjang baris nyaman 40-75 karakter. Di tablet batasi lebar konten (`widthIn(max = 640.dp)`).
42
+ - Tinggi baris (line height) 1.4 sampai 1.6 untuk body.
43
+ - Font: default sistem sudah baik. Satu keluarga font kustom maksimal, dimuat lewat resource font, bukan dari URL tanpa verifikasi.
44
+ - Angka tabular (`fontFeatureSettings = "tnum"`) untuk kolom angka agar sejajar.
45
+
46
+ ## Radius
47
+
48
+ Pilih satu skala dan pakai konsisten:
49
+
50
+ | Token | Nilai | Pemakaian |
51
+ |---|---|---|
52
+ | `small` | 8dp | Chip, field |
53
+ | `medium` | 12dp | Card, dialog kecil |
54
+ | `large` | 16dp | Bottom sheet |
55
+
56
+ Jangan pakai radius besar seragam (24dp+) di semua elemen. Itu cepat terbaca sebagai template.
57
+
58
+ ## Elevasi dan batas
59
+
60
+ Urutan preferensi untuk memisahkan elemen:
61
+ 1. Spasi
62
+ 2. Perbedaan tonal (`surfaceContainer`)
63
+ 3. Garis 1dp `outlineVariant`
64
+ 4. Bayangan (hanya untuk elemen yang benar-benar melayang: FAB, menu, dialog)
65
+
66
+ Tanpa bayangan berlapis, tanpa glow, tanpa border tebal berwarna.
67
+
68
+ ## Ikon
69
+
70
+ - Satu set (Material Symbols atau `Icons.Outlined`). Jangan campur gaya filled dan outlined sembarangan.
71
+ - Ukuran 24dp standar, 20dp untuk inline dengan teks.
72
+ - Ikon tanpa label hanya untuk aksi yang sangat umum (kembali, tutup, cari).
73
+
74
+ ## Daftar (list)
75
+
76
+ - Baris polos dengan divider tipis atau spasi cukup untuk daftar homogen.
77
+ - Card hanya jika tiap item berisi beberapa bagian dan perlu aksi sendiri.
78
+ - Leading visual (avatar, ikon) hanya jika mengidentifikasi item. Bukan dekorasi.
79
+ - Gunakan `key` stabil di `LazyColumn`.
80
+
81
+ ## Form
82
+
83
+ - Label selalu terlihat (bukan hanya placeholder).
84
+ - Pesan error di bawah field, jelas, dengan teks.
85
+ - Satu tombol utama. Aksi sekunder berupa tombol teks.
86
+ - Atur `KeyboardOptions` sesuai isi (email, angka, password) dan `imeAction`.
87
+
88
+ ## Empty, loading, error
89
+
90
+ Tiga state ini wajib ada untuk setiap layar berdata:
91
+ - Empty: satu kalimat penjelas + satu aksi jika relevan. Tanpa ilustrasi dekoratif.
92
+ - Loading: indikator sederhana atau skeleton netral. Jangan blokir seluruh layar jika sebagian data sudah ada.
93
+ - Error: apa yang gagal dan apa yang bisa dilakukan (coba lagi).
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env python3
2
+ """Kalkulator kontras WCAG 2.2.
3
+
4
+ Pemakaian:
5
+ python3 contrast.py <fg> <bg> [<fg2> <bg2> ...]
6
+
7
+ Warna: #RGB, #RRGGBB, 0xFFRRGGBB, atau AARRGGBB (urutan Android).
8
+ Jika fg punya alpha, dicampur di atas bg sebelum dihitung.
9
+ Kode keluar 1 jika ada pasangan yang gagal AA teks normal (4.5:1).
10
+ """
11
+ import sys
12
+
13
+
14
+ def parse(s):
15
+ h = s.strip().lstrip("#")
16
+ if h.lower().startswith("0x"):
17
+ h = h[2:]
18
+ if len(h) == 3:
19
+ h = "".join(c * 2 for c in h)
20
+ if len(h) == 6:
21
+ h = "FF" + h
22
+ if len(h) != 8:
23
+ raise ValueError(f"format warna tidak dikenal: {s}")
24
+ a = int(h[0:2], 16) / 255
25
+ return a, tuple(int(h[i:i + 2], 16) for i in (2, 4, 6))
26
+
27
+
28
+ def blend(fg, a, bg):
29
+ return tuple(round(f * a + b * (1 - a)) for f, b in zip(fg, bg))
30
+
31
+
32
+ def lin(c):
33
+ c /= 255
34
+ return c / 12.92 if c <= 0.03928 else ((c + 0.055) / 1.055) ** 2.4
35
+
36
+
37
+ def lum(rgb):
38
+ r, g, b = map(lin, rgb)
39
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b
40
+
41
+
42
+ def ratio(fg, bg):
43
+ hi, lo = sorted((lum(fg), lum(bg)), reverse=True)
44
+ return (hi + 0.05) / (lo + 0.05)
45
+
46
+
47
+ def main(argv):
48
+ if len(argv) < 2 or len(argv) % 2:
49
+ print(__doc__)
50
+ return 2
51
+ failed = False
52
+ for i in range(0, len(argv), 2):
53
+ a, fg = parse(argv[i])
54
+ _, bg = parse(argv[i + 1])
55
+ eff = blend(fg, a, bg) if a < 1 else fg
56
+ r = ratio(eff, bg)
57
+ aa = r >= 4.5
58
+ large = r >= 3.0
59
+ aaa = r >= 7.0
60
+ failed |= not aa
61
+ print(f"{argv[i]:>12} on {argv[i + 1]:<12} {r:5.2f}:1 "
62
+ f"teks normal AA {'lulus' if aa else 'GAGAL'} | "
63
+ f"teks besar/komponen {'lulus' if large else 'GAGAL'} | AAA {'lulus' if aaa else 'tidak'}")
64
+ return 1 if failed else 0
65
+
66
+
67
+ if __name__ == "__main__":
68
+ sys.exit(main(sys.argv[1:]))
@@ -0,0 +1,165 @@
1
+ #!/usr/bin/env python3
2
+ """Pembuat token warna dari satu warna aksen.
3
+
4
+ Menghasilkan Color.kt dan Theme.kt (Compose, Material 3) dengan netral
5
+ terang dan gelap yang sedikit bernuansa aksen, lalu memverifikasi kontras.
6
+
7
+ Pemakaian:
8
+ python3 gen_tokens.py "#3B5BA9" [--package com.contoh.app] [--out app/src/main/java/com/contoh/app/ui/theme]
9
+
10
+ Tanpa --out, hasil dicetak ke stdout.
11
+ """
12
+ import argparse
13
+ import colorsys
14
+ import os
15
+ import sys
16
+
17
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
18
+ from contrast import parse, ratio # noqa: E402
19
+
20
+
21
+ def to_hls(rgb):
22
+ return colorsys.rgb_to_hls(*[x / 255 for x in rgb])
23
+
24
+
25
+ def from_hls(h, l, s):
26
+ return tuple(round(x * 255) for x in colorsys.hls_to_rgb(h, min(max(l, 0), 1), min(max(s, 0), 1)))
27
+
28
+
29
+ def kt(rgb):
30
+ return "0xFF%02X%02X%02X" % rgb
31
+
32
+
33
+ def build(accent_hex):
34
+ _, acc = parse(accent_hex)
35
+ h, l, s = to_hls(acc)
36
+ s = min(s, 0.6)
37
+
38
+ def neutral(light, sat=0.05):
39
+ return from_hls(h, light, sat)
40
+
41
+ light = {
42
+ "background": neutral(0.965), "surface": neutral(0.995, 0.02),
43
+ "surfaceVariant": neutral(0.93), "outlineVariant": neutral(0.85),
44
+ "onSurface": neutral(0.11, 0.06), "onSurfaceVariant": neutral(0.36, 0.05),
45
+ }
46
+ dark = {
47
+ "background": neutral(0.07), "surface": neutral(0.10),
48
+ "surfaceVariant": neutral(0.14), "outlineVariant": neutral(0.24),
49
+ "onSurface": neutral(0.91, 0.04), "onSurfaceVariant": neutral(0.67, 0.04),
50
+ }
51
+
52
+ pl = l
53
+ p_light = from_hls(h, pl, s)
54
+ while ratio(p_light, light["background"]) < 4.5 and pl > 0.05:
55
+ pl -= 0.02
56
+ p_light = from_hls(h, pl, s)
57
+
58
+ pd = max(l, 0.70)
59
+ p_dark = from_hls(h, pd, min(s, 0.65))
60
+ while ratio(p_dark, dark["background"]) < 4.5 and pd < 0.95:
61
+ pd += 0.02
62
+ p_dark = from_hls(h, pd, min(s, 0.65))
63
+
64
+ ink = (0x10, 0x14, 0x18)
65
+ white = (255, 255, 255)
66
+
67
+ def on(c):
68
+ return white if ratio(white, c) >= ratio(ink, c) else ink
69
+
70
+ light.update(primary=p_light, onPrimary=on(p_light), error=(0xB3, 0x26, 0x1E), onError=white)
71
+ dark.update(primary=p_dark, onPrimary=on(p_dark), error=(0xF2, 0xB8, 0xB5), onError=(0x60, 0x14, 0x10))
72
+ return light, dark
73
+
74
+
75
+ def checks(light, dark):
76
+ pairs = [("onSurface", "background"), ("onSurface", "surface"),
77
+ ("onSurfaceVariant", "background"), ("onSurfaceVariant", "surface"),
78
+ ("onPrimary", "primary"), ("primary", "background"), ("error", "background")]
79
+ rows, ok = [], True
80
+ for name, scheme in (("terang", light), ("gelap", dark)):
81
+ for fg, bg in pairs:
82
+ r = ratio(scheme[fg], scheme[bg])
83
+ need = 3.0 if fg == "primary" else 4.5
84
+ good = r >= need
85
+ ok &= good
86
+ rows.append(f"{name:6} {fg:17} / {bg:11} {r:5.2f}:1 {'ok' if good else 'GAGAL (butuh ' + str(need) + ')'}")
87
+ return rows, ok
88
+
89
+
90
+ def color_kt(pkg, light, dark):
91
+ out = [f"package {pkg}.ui.theme", "", "import androidx.compose.ui.graphics.Color", ""]
92
+ for prefix, sch in (("Light", light), ("Dark", dark)):
93
+ for k, v in sch.items():
94
+ out.append(f"internal val {prefix}{k[0].upper() + k[1:]} = Color({kt(v)})")
95
+ out.append("")
96
+ return "\n".join(out)
97
+
98
+
99
+ def scheme_kt(prefix, sch, fn):
100
+ names = ["primary", "onPrimary", "background", "surface", "surfaceVariant",
101
+ "outlineVariant", "onSurface", "onSurfaceVariant", "error", "onError"]
102
+ lines = [f"private val {prefix}Colors = {fn}("]
103
+ for n in names:
104
+ lines.append(f" {n} = {prefix}{n[0].upper() + n[1:]},")
105
+ lines.append(" onBackground = %sOnSurface," % prefix)
106
+ lines.append(" outline = %sOutlineVariant," % prefix)
107
+ lines.append(")")
108
+ return "\n".join(lines)
109
+
110
+
111
+ def theme_kt(pkg):
112
+ return f"""package {pkg}.ui.theme
113
+
114
+ import androidx.compose.foundation.isSystemInDarkTheme
115
+ import androidx.compose.material3.MaterialTheme
116
+ import androidx.compose.material3.darkColorScheme
117
+ import androidx.compose.material3.lightColorScheme
118
+ import androidx.compose.runtime.Composable
119
+
120
+ {scheme_kt("Light", None, "lightColorScheme")}
121
+
122
+ {scheme_kt("Dark", None, "darkColorScheme")}
123
+
124
+ @Composable
125
+ fun AppTheme(
126
+ darkTheme: Boolean = isSystemInDarkTheme(),
127
+ content: @Composable () -> Unit,
128
+ ) {{
129
+ MaterialTheme(
130
+ colorScheme = if (darkTheme) DarkColors else LightColors,
131
+ content = content,
132
+ )
133
+ }}
134
+ """
135
+
136
+
137
+ def main():
138
+ ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
139
+ ap.add_argument("accent")
140
+ ap.add_argument("--package", default="com.example.app")
141
+ ap.add_argument("--out")
142
+ a = ap.parse_args()
143
+
144
+ light, dark = build(a.accent)
145
+ rows, ok = checks(light, dark)
146
+ ck, th = color_kt(a.package, light, dark), theme_kt(a.package)
147
+
148
+ if a.out:
149
+ os.makedirs(a.out, exist_ok=True)
150
+ for name, body in (("Color.kt", ck), ("Theme.kt", th)):
151
+ with open(os.path.join(a.out, name), "w", encoding="utf-8") as fh:
152
+ fh.write(body)
153
+ print(f"Ditulis: {a.out}/Color.kt, Theme.kt")
154
+ else:
155
+ print("// ===== Color.kt =====\n" + ck + "\n// ===== Theme.kt =====\n" + th)
156
+
157
+ print("\nVerifikasi kontras:", file=sys.stderr)
158
+ print("\n".join(rows), file=sys.stderr)
159
+ if not ok:
160
+ print("\nAda pasangan yang gagal. Sesuaikan aksen atau netral.", file=sys.stderr)
161
+ sys.exit(0 if ok else 1)
162
+
163
+
164
+ if __name__ == "__main__":
165
+ main()