Cotton code
416 lines · 15.6 KB · RustRaw
//! The Cotton palettes, as DATA — and nothing else.//!//! A palette is a record of colours and it imports nothing: a program that//! wants only these thirteen has no business dragging a derivation graph in//! with them.//!//! **There is ONE palette the app wears, and it is light.** The appearance axis//! is gone: no theme choice, no dark mode, no system-appearance switch — so a//! colorset carries one value and `PAPER` is what every screen resolves to.//! [`GRAPHITE`] survives beside it as the BRAND's fixed charcoal — the ground//! the logo is set on, the app-icon tile, and the Android keyboard's paint —//! read as authored VALUES by the two or three surfaces that want it. It is//! not an appearance, it is never chosen, and nothing resolves to it.//!//! The palette values are raw display-P3 screenshot bytes (±a few points per//! channel vs sRGB) — shipped as sampled//! (`docs/research/bear/palettes.json` + `GROUND-TRUTH.md`).//! These hexes ARE the source of truth (pixel-sampled Bear ground truth), and//! the name strings are registry ids, never user copy.//!//! [`PaletteSlot`], [`StatusSlot`] and [`SidebarSlot`] make the thirteen, the//! six and the five an enumerable axis, so the//! renderer that writes Swift walks a list the compiler holds total instead of//! a hand-kept array of key names sitting in the generator./// The thirteen base slots a palette author writes (spec §1.1).////// Everything else a screen needs (pressed states, progress-segment tints,/// skeleton tones) is DERIVED from these — never authored per palette. The/// `as_str` spelling is the name a Swift accessor and an asset catalogue/// carry, which is why it is camelCase rather than this crate's usual snake.#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]pub enum PaletteSlot {    /// The page/screen background (lists, editor).    Ground,    /// Recessed grouped-page ground (Settings behind cards; search dim wash).    GroundMuted,    /// Cards, sheets, popovers, nav circles, the settings cards.    GroundElevated,    /// Titles, primary text. MAY be tinted toward the accent family (the    /// charcoal palette's steel-blue titles) — authored, never derived.    Ink,    /// Body/editor text.    InkBody,    /// Previews, values, secondary labels — and the checkbox stroke.    InkSecondary,    /// Dates, captions, section labels, placeholder.    InkTertiary,    /// Separators, card dividers.    Hairline,    /// THE interactive colour: FAB, toggles-on, links, selection ring, active    /// states. One accent, and it is the app's red.    Accent,    /// Glyphs painted on accent (the FAB pencil = white).    AccentContrast,    /// Code-chip / neutral-chip background.    ChipGround,    /// Text-highlight marker ground (the gallery-card chip; a future    /// search-match ground is a separate, yellower concern).    Highlight,    /// Text selection / pressed-row wash. Not captured in ground truth —    /// canonical: accent at 18% alpha (`#RRGGBBAA`), marked approximate in the    /// spec. The only slot allowed an alpha byte.    Selection,}impl PaletteSlot {    /// In the order the record declares them — the order the Swift accessors,    /// the value type and the asset catalogue are all written in.    pub const ALL: [PaletteSlot; 13] = [        PaletteSlot::Ground,        PaletteSlot::GroundMuted,        PaletteSlot::GroundElevated,        PaletteSlot::Ink,        PaletteSlot::InkBody,        PaletteSlot::InkSecondary,        PaletteSlot::InkTertiary,        PaletteSlot::Hairline,        PaletteSlot::Accent,        PaletteSlot::AccentContrast,        PaletteSlot::ChipGround,        PaletteSlot::Highlight,        PaletteSlot::Selection,    ];    pub const fn as_str(self) -> &'static str {        match self {            PaletteSlot::Ground => "ground",            PaletteSlot::GroundMuted => "groundMuted",            PaletteSlot::GroundElevated => "groundElevated",            PaletteSlot::Ink => "ink",            PaletteSlot::InkBody => "inkBody",            PaletteSlot::InkSecondary => "inkSecondary",            PaletteSlot::InkTertiary => "inkTertiary",            PaletteSlot::Hairline => "hairline",            PaletteSlot::Accent => "accent",            PaletteSlot::AccentContrast => "accentContrast",            PaletteSlot::ChipGround => "chipGround",            PaletteSlot::Highlight => "highlight",            PaletteSlot::Selection => "selection",        }    }}/// The six status roles.#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]pub enum StatusSlot {    Success,    SuccessLight,    Error,    ErrorLight,    Warning,    WarningLight,}impl StatusSlot {    pub const ALL: [StatusSlot; 6] = [        StatusSlot::Success,        StatusSlot::SuccessLight,        StatusSlot::Error,        StatusSlot::ErrorLight,        StatusSlot::Warning,        StatusSlot::WarningLight,    ];    pub const fn as_str(self) -> &'static str {        match self {            StatusSlot::Success => "success",            StatusSlot::SuccessLight => "successLight",            StatusSlot::Error => "error",            StatusSlot::ErrorLight => "errorLight",            StatusSlot::Warning => "warning",            StatusSlot::WarningLight => "warningLight",        }    }    /// The asset name a status role carries — namespaced so `error` cannot    /// collide with a base slot in one flat catalogue.    pub const fn asset_name(self) -> &'static str {        match self {            StatusSlot::Success => "statusSuccess",            StatusSlot::SuccessLight => "statusSuccessLight",            StatusSlot::Error => "statusError",            StatusSlot::ErrorLight => "statusErrorLight",            StatusSlot::Warning => "statusWarning",            StatusSlot::WarningLight => "statusWarningLight",        }    }}/// **The Mac window's sidebar, charcoal** — five roles, and the only charcoal/// the app itself paints (Mac redesign spec §3).////// The sidebar is chrome, so it is dark for contrast: the eye knows where the/// content is because the content is the paper to its right. These are not an/// appearance — the app stays light, nothing resolves to them by trait — they/// are read as VALUES by `Boot/HomeSidebar.swift` alone.////// Every value is OPAQUE, pre-blended over the sidebar's own ground: the/// sidebar is the only thing they are ever painted on, and an alpha byte would/// be a second role allowed one (`Selection` is the only slot that is).#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]pub enum SidebarSlot {    /// The column's ground — the brand graphite.    Ground,    /// Project names, row labels.    Ink,    /// Settings, This Mac, counts, the search placeholder.    InkMuted,    /// The selected tool row's fill.    Selection,    /// The column's right edge — darker than the ground, never a shadow.    Hairline,}impl SidebarSlot {    pub const ALL: [SidebarSlot; 5] = [        SidebarSlot::Ground,        SidebarSlot::Ink,        SidebarSlot::InkMuted,        SidebarSlot::Selection,        SidebarSlot::Hairline,    ];    pub const fn as_str(self) -> &'static str {        match self {            SidebarSlot::Ground => "ground",            SidebarSlot::Ink => "ink",            SidebarSlot::InkMuted => "inkMuted",            SidebarSlot::Selection => "selection",            SidebarSlot::Hairline => "hairline",        }    }    /// Namespaced, as the status roles are, so `ink` cannot collide with a    /// base slot in one flat catalogue.    pub const fn asset_name(self) -> &'static str {        match self {            SidebarSlot::Ground => "sidebarGround",            SidebarSlot::Ink => "sidebarInk",            SidebarSlot::InkMuted => "sidebarInkMuted",            SidebarSlot::Selection => "sidebarSelection",            SidebarSlot::Hairline => "sidebarHairline",        }    }}/// One palette: the thirteen slots, plus identity.#[derive(Debug, Clone, Copy, PartialEq, Eq)]pub struct Palette {    /// Stable registry id. Never user copy.    pub name: &'static str,    pub ground: &'static str,    pub ground_muted: &'static str,    pub ground_elevated: &'static str,    pub ink: &'static str,    pub ink_body: &'static str,    pub ink_secondary: &'static str,    pub ink_tertiary: &'static str,    pub hairline: &'static str,    pub accent: &'static str,    pub accent_contrast: &'static str,    pub chip_ground: &'static str,    pub highlight: &'static str,    pub selection: &'static str,}impl Palette {    /// The hex a slot holds. Total over [`PaletteSlot`], which is what a    /// renderer walks — the TypeScript indexed the record by a string and    /// could be handed a name no palette has.    pub const fn slot(&self, slot: PaletteSlot) -> &'static str {        match slot {            PaletteSlot::Ground => self.ground,            PaletteSlot::GroundMuted => self.ground_muted,            PaletteSlot::GroundElevated => self.ground_elevated,            PaletteSlot::Ink => self.ink,            PaletteSlot::InkBody => self.ink_body,            PaletteSlot::InkSecondary => self.ink_secondary,            PaletteSlot::InkTertiary => self.ink_tertiary,            PaletteSlot::Hairline => self.hairline,            PaletteSlot::Accent => self.accent,            PaletteSlot::AccentContrast => self.accent_contrast,            PaletteSlot::ChipGround => self.chip_ground,            PaletteSlot::Highlight => self.highlight,            PaletteSlot::Selection => self.selection,        }    }}/// The six status colours.#[derive(Debug, Clone, Copy, PartialEq, Eq)]pub struct Status {    pub success: &'static str,    pub success_light: &'static str,    pub error: &'static str,    pub error_light: &'static str,    pub warning: &'static str,    pub warning_light: &'static str,}impl Status {    /// The hex a status role holds. Total over [`StatusSlot`].    pub const fn slot(&self, slot: StatusSlot) -> &'static str {        match slot {            StatusSlot::Success => self.success,            StatusSlot::SuccessLight => self.success_light,            StatusSlot::Error => self.error,            StatusSlot::ErrorLight => self.error_light,            StatusSlot::Warning => self.warning,            StatusSlot::WarningLight => self.warning_light,        }    }}/// The five sidebar colours.#[derive(Debug, Clone, Copy, PartialEq, Eq)]pub struct Sidebar {    pub ground: &'static str,    pub ink: &'static str,    pub ink_muted: &'static str,    pub selection: &'static str,    pub hairline: &'static str,}impl Sidebar {    /// The hex a sidebar role holds. Total over [`SidebarSlot`].    pub const fn slot(&self, slot: SidebarSlot) -> &'static str {        match slot {            SidebarSlot::Ground => self.ground,            SidebarSlot::Ink => self.ink,            SidebarSlot::InkMuted => self.ink_muted,            SidebarSlot::Selection => self.selection,            SidebarSlot::Hairline => self.hairline,        }    }}/// **The app's palette, and the only one it wears.** Red-Graphite-derived/// (spec §1.4), pixel-sampled from Bear 2.9.1 (`palettes.json`/// `light_red_graphite_in_app`). Every colorset is this palette's value.pub const PAPER: Palette = Palette {    name: "cotton",    ground: "#FFFFFF",    // THE PAGE THE PAPER LIES ON — the redesign pictures' warm plaster, read    // off the bare ground of 03, 11 and 15 (≈238,226,212 … 240,229,218). It is    // the colour of every page the app draws: the phone's plaster tile is grey    // RELIEF laid over this with `.overlay`, which leaves the mean where the    // token puts it (`PageGroundFill`, `scripts/gen-caps/export_caps.py`), and    // the Mac and the keyboard draw it flat. Bear's cool `#F3F5F7` retired    // 2026-09-15 (kit-tone).    ground_muted: "#EEE3D6",    ground_elevated: "#FFFFFF",    ink: "#444444",    ink_body: "#444444",    ink_secondary: "#888888",    ink_tertiary: "#ABABAB",    hairline: "#E2E2E2",    accent: "#C6534B",    accent_contrast: "#FFFFFF",    chip_ground: "#F2F2F2",    // The TEXT-HIGHLIGHT marker ground — the Red Graphite gallery card's    // sampled chip (palettes.json themes_gallery_cards). Bear's SEARCH-match    // yellow (#FEFA78,    // light_red_graphite_in_app) is a different element; it returns as its    // own value if search highlighting ever ships (aesthetic-foundation    // amendment §5 — the v8 yellow specimen is the pin's "doesn't look good").    highlight: "#D9F7A6",    // accent @ 18% — canonical, ground truth missing    selection: "#C6534B2E",};/// **The brand's fixed charcoal — not an appearance and not a choice.**////// Nothing resolves to this palette: it is read as authored VALUES by the/// handful of surfaces that are charcoal by design whatever the app is doing —/// the ground the logo is set on (`design/mark.rs`), the app-icon tile/// (`apps/cotton/scripts/derive-icons.ts`), and the Android input method's/// paint (`cotton-gen`'s Kotlin palette), which is drawn inside whatever app/// the person is typing in and has never followed this app's colours.////// Dark-Graphite-derived (spec §1.4), pixel-sampled from Bear 2.9.1/// (`palettes.json` `dark_dark_graphite_in_app`). Note the steel-BLUE ink —/// titles tint toward the accent family while chrome stays neutral.pub const GRAPHITE: Palette = Palette {    name: "cotton-graphite",    ground: "#1D1E1E",    ground_muted: "#232425",    ground_elevated: "#2E2F30",    ink: "#CFDAE4",    ink_body: "#DFE0E0",    ink_secondary: "#A2A3A4",    ink_tertiary: "#7A7B7C",    hairline: "#3E3F40",    accent: "#5FA1DF",    accent_contrast: "#FFFFFF",    chip_ground: "#2A2B2C",    highlight: "#2E4053",    // accent @ 18% — canonical, ground truth missing    selection: "#5FA1DF2E",};/// Status colours have no Bear equivalent (§ Stage-2 brief) — quiet values/// that sit on the app's grounds. The `*Light` roles are the tinted chip a/// coloured label sits on.pub const STATUS: Status = Status {    success: "#4F7D5C",    success_light: "#E8F1EB",    error: "#B0453D",    error_light: "#F8EAE8",    warning: "#A06C1C",    warning_light: "#F7EFDC",};/// The sidebar's charcoal. The ground is [`GRAPHITE`]'s; the inks are the/// paper's cream (`#F0E5D8`, `PaperDye.cream`) laid over that ground at a/// fixed strength and written down as the opaque result, so what is authored/// is what is drawn: ink 88 %, muted ink 55 %, the selection 12 %. The edge is/// a step DARKER than the ground, which is how a dark column ends against/// paper without a shadow.pub const SIDEBAR: Sidebar = Sidebar {    ground: "#1D1E1E",    // cream @ 88 % over the ground    ink: "#D7CDC2",    // cream @ 55 % over the ground    ink_muted: "#918B84",    // cream @ 12 % over the ground    selection: "#363634",    hairline: "#111212",};/// Every colorset a catalogue holds: the asset name, and its ONE authored hex./// The base slots first, in declared order, then the status roles under their/// namespaced names, then the sidebar's — the order the phone's catalogue and the palette's/// accessors are generated in.////// One hex per name, because the app has one appearance. A colorset with a/// second `luminosity` entry is what let the operating system repaint the app,/// and that is what was removed.pub fn colorsets() -> Vec<(&'static str, &'static str)> {    let mut out: Vec<(&'static str, &'static str)> = Vec::new();    for slot in PaletteSlot::ALL {        out.push((slot.as_str(), PAPER.slot(slot)));    }    for slot in StatusSlot::ALL {        out.push((slot.asset_name(), STATUS.slot(slot)));    }    for slot in SidebarSlot::ALL {        out.push((slot.asset_name(), SIDEBAR.slot(slot)));    }    out}#[cfg(test)]#[path = "palette_tests.rs"]mod tests;