// NOTES' LOOK (assets/design/notes/DECISIONS.md "Look"): the theme standing// on this phone for light and dark, and the faces Notes is set in (Figtree for// the words, JetBrains Mono for code). The themes and the choice are the// core's (`notes.themes`, `notes.settings`, CONTRACT.md §10): what// `notes.settings` last answered stands, and is kept on this phone so the next// launch's first frame (every shell card, the gate, the sign-in sheet, the// splash: `AppLook`) already stands in it, before the core has answered.// Before the first answer ever, the launch screen's own ground stands.#if os(iOS)importCottonKitimportCottonWritingimportSwiftUIimport UIKitenumNotesLook {/// The theme standing now for the dark appearance or the light: read through `NotesStanding`, so a/// screen drawn in it draws again when it changes. @MainActor staticfunc standing(dark: Bool) -> WritingTheme {let standing = NotesStanding.sharedreturnWritingTheme(id: dark ? standing.darkId : standing.lightId, name: "", dark: dark, colours: dark ? standing.dark : standing.light) }/// The core's face id as Notes draws it: its `sans` is Figtree, carried by Notes alone; Look's faces/// (shared/DECISIONS.md "Look") are the bundled `LookFonts`: `serif` Literata, `typewriter` Courier Prime,/// `hyperlegible` Atkinson Hyperlegible Next, `dyslexic` OpenDyslexic.staticfunc face(_ id: String) -> String {switch id {case"sans": WritingFonts.hasFigtree ? "figtree" : idcase"serif": WritingFonts.carries("literata") ? "literata" : idcase"typewriter": "courier"case"hyperlegible": "atkinson"case"dyslexic": "opendyslexic"default: id } }}/// The look `notes.settings` last answered, watched: a screen that reads it draws again when it changes.@MainActor@ObservablefinalclassNotesStanding {staticlet shared = NotesStanding()private(set) var lightId: Stringprivate(set) var darkId: Stringprivate(set) var light: WritingTheme.Coloursprivate(set) var dark: WritingTheme.Coloursprivate(set) var hideMarks: Bool/// What is kept for the next launch: the core's last answer, as it said it.privatestructKept: Codable {var lightId: Stringvar darkId: Stringvar light: WritingTheme.Coloursvar dark: WritingTheme.Coloursvar hideMarks: Bool }privatestaticlet key = "notes-look.standing"privateinit() {let defaults = UserDefaults.standard// What earlier builds kept on the phone before the core carried the look: gone.for old in ["light", "dark", "hideMarks", "paragraph", "pinnedNotes", "pinnedTags"] { defaults.removeObject(forKey: "notes-look.\(old)") }for name in defaults.dictionaryRepresentation().keys where name.hasPrefix("notes-look.width:") { defaults.removeObject(forKey: name) }iflet data = defaults.data(forKey: Self.key), let kept = try? JSONDecoder().decode(Kept.self, from: data) { lightId = kept.lightId darkId = kept.darkId light = kept.light dark = kept.dark hideMarks = kept.hideMarks } else { lightId = "" darkId = "" light = Self.launch(dark: false) dark = Self.launch(dark: true) hideMarks = true } }/// The core's answer taken: it stands now, and is kept for the next launch's first frame.func take(_ chosen: NotesSettingsChosen) { lightId = chosen.lightTheme darkId = chosen.darkTheme light = chosen.light dark = chosen.dark hideMarks = chosen.hideMarkslet kept = Kept(lightId: lightId, darkId: darkId, light: light, dark: dark, hideMarks: hideMarks)iflet data = try? JSONEncoder().encode(kept) { UserDefaults.standard.set(data, forKey: Self.key) } }/// Before the core's first answer ever: the launch screen's ground (`LaunchGround`), in the system's ink.privatestaticfunc launch(dark: Bool) -> WritingTheme.Colours {let traits = UITraitCollection(userInterfaceStyle: dark ? .dark : .light)func hex(_ colour: UIColor?) -> String {var r: CGFloat = 0, g: CGFloat = 0, b: CGFloat = 0, a: CGFloat = 0 (colour ?? .systemBackground).resolvedColor(with: traits).getRed(&r, green: &g, blue: &b, alpha: &a)returnString(format: "#%02X%02X%02X", Int(r * 255), Int(g * 255), Int(b * 255)) }let ground = hex(UIColor(named: "LaunchGround") ?? .systemBackground)returnWritingTheme.Colours(ground: ground, text: hex(.label), heading: hex(.label), secondary: hex(.secondaryLabel), accent: hex(.tintColor), rule: hex(.separator), highlight: hex(.systemYellow), codeGround: hex(.secondarySystemBackground), selection: hex(.systemGray4), link: hex(.label), danger: hex(.systemRed)) }}#endif#if os(iOS)extensionNotesLook {/// THE APP LOOK Notes sets (research.md A5): the shell's own pieces inside Notes (the sealed-key and/// recovery cards, the sign-in ask, the unlock request, the read-only card, the sign-in sheet, the gate,/// the toasts) draw the app look the root hands them (`\.vaultLook`), as they do in Vault and Health. Notes/// answers it from its standing theme, light and dark, in Figtree and JetBrains Mono, so every one of them/// follows Notes' theme from the first frame, before the core has said anything. @MainActor staticvar appLook: VaultLook {let standing = NotesStanding.sharedfunc inks(_ c: WritingTheme.Colours, dark: Bool) -> AppLookInks {AppLookInks(ground: c.ground, field: c.codeGround, rule: c.rule, text: c.text, secondary: c.secondary, accent: c.accent, onAccent: c.ground, danger: c.danger ?? c.accent, safe: dark ? "#7FBF8E" : "#3E7D4F", scrim: dark ? "#0000008A" : "#00000047") }returnVaultLook.app(light: inks(standing.light, dark: false), dark: inks(standing.dark, dark: true), text: .figtree, display: .figtree, mono: .jetbrains) }}#endif