Colour presets trimmed to a few, plus any hue for accent and background
Browse files at this commitcd71b21b17e3e466995b98e0398eab6d44edbdbbParent: cf9a9cc- feat
- colour presets trimmed to a few, plus any hue for accent and background
11 changed files +1047 -909
- crates/forge-core/migrations/0065_hue_colours.sql +79 -0
- crates/forge-core/src/store/migrate.rs +1 -0
- crates/forge-core/src/store/ui_prefs.rs +7 -7
- crates/forge-web/src/accent.rs +315 -92
- crates/forge-web/src/accent_palette.rs +108 -748
- crates/forge-web/src/custom_colour.rs +405 -0
- crates/forge-web/src/i18n/accents.rs +4 -48
- crates/forge-web/src/main.rs +1 -0
- crates/forge-web/src/pages/assets.rs +87 -2
- crates/forge-web/src/pages/settings_live.rs +12 -6
- crates/forge-web/src/views/mod.rs +28 -6
crates/forge-core/migrations/0065_hue_colours.sqladded+79 -0
| @@ -0,0 +1,79 @@ | |||
| 1 | +-- The colour presets are trimmed to a few, and a free hue takes their place. `ember` is renamed | ||
| 2 | +-- `spark`, which keeps its colours. Every other removed accent or base becomes a `hue-N` id, N | ||
| 3 | +-- being the rounded OKLCH hue of the colour it had, so a user keeps roughly the same colour. | ||
| 4 | +-- The ids are literal, since the web layer no longer carries the removed palettes. Applied by | ||
| 5 | +-- store/migrate.rs. | ||
| 6 | + | ||
| 7 | +UPDATE users SET accent = CASE accent | ||
| 8 | + WHEN 'ember' THEN 'spark' | ||
| 9 | + WHEN 'ochre' THEN 'hue-55' | ||
| 10 | + WHEN 'slate' THEN 'hue-252' | ||
| 11 | + WHEN 'teal' THEN 'hue-196' | ||
| 12 | + WHEN 'moss' THEN 'hue-123' | ||
| 13 | + WHEN 'indigo' THEN 'hue-275' | ||
| 14 | + WHEN 'amber' THEN 'hue-80' | ||
| 15 | + WHEN 'clay' THEN 'hue-38' | ||
| 16 | + WHEN 'berry' THEN 'hue-347' | ||
| 17 | + WHEN 'crimson' THEN 'hue-19' | ||
| 18 | + WHEN 'coral' THEN 'hue-30' | ||
| 19 | + WHEN 'lime' THEN 'hue-125' | ||
| 20 | + WHEN 'mint' THEN 'hue-167' | ||
| 21 | + WHEN 'cyan' THEN 'hue-219' | ||
| 22 | + WHEN 'sky' THEN 'hue-247' | ||
| 23 | + WHEN 'violet' THEN 'hue-293' | ||
| 24 | + WHEN 'fuchsia' THEN 'hue-324' | ||
| 25 | + ELSE accent | ||
| 26 | +END | ||
| 27 | +WHERE accent IN ( | ||
| 28 | + 'ember', 'ochre', 'slate', 'teal', 'moss', 'indigo', 'amber', 'clay', 'berry', 'crimson', | ||
| 29 | + 'coral', 'lime', 'mint', 'cyan', 'sky', 'violet', 'fuchsia' | ||
| 30 | +); | ||
| 31 | + | ||
| 32 | +UPDATE users SET accent_dark = CASE accent_dark | ||
| 33 | + WHEN 'ember' THEN 'spark' | ||
| 34 | + WHEN 'ochre' THEN 'hue-55' | ||
| 35 | + WHEN 'slate' THEN 'hue-252' | ||
| 36 | + WHEN 'teal' THEN 'hue-196' | ||
| 37 | + WHEN 'moss' THEN 'hue-123' | ||
| 38 | + WHEN 'indigo' THEN 'hue-275' | ||
| 39 | + WHEN 'amber' THEN 'hue-80' | ||
| 40 | + WHEN 'clay' THEN 'hue-38' | ||
| 41 | + WHEN 'berry' THEN 'hue-347' | ||
| 42 | + WHEN 'crimson' THEN 'hue-19' | ||
| 43 | + WHEN 'coral' THEN 'hue-30' | ||
| 44 | + WHEN 'lime' THEN 'hue-125' | ||
| 45 | + WHEN 'mint' THEN 'hue-167' | ||
| 46 | + WHEN 'cyan' THEN 'hue-219' | ||
| 47 | + WHEN 'sky' THEN 'hue-247' | ||
| 48 | + WHEN 'violet' THEN 'hue-293' | ||
| 49 | + WHEN 'fuchsia' THEN 'hue-324' | ||
| 50 | + ELSE accent_dark | ||
| 51 | +END | ||
| 52 | +WHERE accent_dark IN ( | ||
| 53 | + 'ember', 'ochre', 'slate', 'teal', 'moss', 'indigo', 'amber', 'clay', 'berry', 'crimson', | ||
| 54 | + 'coral', 'lime', 'mint', 'cyan', 'sky', 'violet', 'fuchsia' | ||
| 55 | +); | ||
| 56 | + | ||
| 57 | +UPDATE users SET base_light = CASE base_light | ||
| 58 | + WHEN 'stone' THEN 'hue-106' | ||
| 59 | + WHEN 'sand' THEN 'hue-85' | ||
| 60 | + WHEN 'mist' THEN 'hue-248' | ||
| 61 | + WHEN 'dune' THEN 'hue-81' | ||
| 62 | + WHEN 'lilac' THEN 'hue-299' | ||
| 63 | + WHEN 'blush' THEN 'hue-2' | ||
| 64 | + WHEN 'pine' THEN 'hue-178' | ||
| 65 | + ELSE base_light | ||
| 66 | +END | ||
| 67 | +WHERE base_light IN ('stone', 'sand', 'mist', 'dune', 'lilac', 'blush', 'pine'); | ||
| 68 | + | ||
| 69 | +UPDATE users SET base_dark = CASE base_dark | ||
| 70 | + WHEN 'stone' THEN 'hue-106' | ||
| 71 | + WHEN 'sand' THEN 'hue-85' | ||
| 72 | + WHEN 'mist' THEN 'hue-248' | ||
| 73 | + WHEN 'dune' THEN 'hue-81' | ||
| 74 | + WHEN 'lilac' THEN 'hue-299' | ||
| 75 | + WHEN 'blush' THEN 'hue-2' | ||
| 76 | + WHEN 'pine' THEN 'hue-178' | ||
| 77 | + ELSE base_dark | ||
| 78 | +END | ||
| 79 | +WHERE base_dark IN ('stone', 'sand', 'mist', 'dune', 'lilac', 'blush', 'pine'); | ||
crates/forge-core/src/store/migrate.rsmodified+1 -0
| @@ -104,6 +104,7 @@ pub const MIGRATIONS: &[(u32, &str)] = &[ | |||
| 104 | (62, include_str!("../../migrations/0062_oci.sql")), | 104 | (62, include_str!("../../migrations/0062_oci.sql")), |
| 105 | (63, include_str!("../../migrations/0063_web_push.sql")), | 105 | (63, include_str!("../../migrations/0063_web_push.sql")), |
| 106 | (64, include_str!("../../migrations/0064_merge_queue.sql")), | 106 | (64, include_str!("../../migrations/0064_merge_queue.sql")), |
| 107 | + (65, include_str!("../../migrations/0065_hue_colours.sql")), | ||
| 107 | ]; | 108 | ]; |
| 108 | 109 | ||
| 109 | /// The highest migration version this binary knows about. | 110 | /// The highest migration version this binary knows about. |
crates/forge-core/src/store/ui_prefs.rsmodified+7 -7
| @@ -250,7 +250,7 @@ mod tests { | |||
| 250 | assert_eq!(user.base_dark, DEFAULT_BASE); | 250 | assert_eq!(user.base_dark, DEFAULT_BASE); |
| 251 | 251 | ||
| 252 | store | 252 | store |
| 253 | - .set_colours(&user.id, "ocean", "rose", "stone", "ink") | 253 | + .set_colours(&user.id, "ocean", "rose", "graphite", "ink") |
| 254 | .await | 254 | .await |
| 255 | .unwrap(); | 255 | .unwrap(); |
| 256 | let stored = store.user_by_id(&user.id).await.unwrap().unwrap(); | 256 | let stored = store.user_by_id(&user.id).await.unwrap().unwrap(); |
| @@ -261,12 +261,12 @@ mod tests { | |||
| 261 | stored.base_light.as_str(), | 261 | stored.base_light.as_str(), |
| 262 | stored.base_dark.as_str() | 262 | stored.base_dark.as_str() |
| 263 | ), | 263 | ), |
| 264 | - ("ocean", "rose", "stone", "ink") | 264 | + ("ocean", "rose", "graphite", "ink") |
| 265 | ); | 265 | ); |
| 266 | 266 | ||
| 267 | assert!( | 267 | assert!( |
| 268 | store | 268 | store |
| 269 | - .set_colours(&user.id, "ocean", "Rose", "stone", "ink") | 269 | + .set_colours(&user.id, "ocean", "Rose", "graphite", "ink") |
| 270 | .await | 270 | .await |
| 271 | .is_err() | 271 | .is_err() |
| 272 | ); | 272 | ); |
| @@ -278,7 +278,7 @@ mod tests { | |||
| 278 | ); | 278 | ); |
| 279 | assert!( | 279 | assert!( |
| 280 | store | 280 | store |
| 281 | - .set_colours(&user.id, "ocean", "rose", "stone", "") | 281 | + .set_colours(&user.id, "ocean", "rose", "graphite", "") |
| 282 | .await | 282 | .await |
| 283 | .is_err() | 283 | .is_err() |
| 284 | ); | 284 | ); |
| @@ -290,7 +290,7 @@ mod tests { | |||
| 290 | still.base_light.as_str(), | 290 | still.base_light.as_str(), |
| 291 | still.base_dark.as_str() | 291 | still.base_dark.as_str() |
| 292 | ), | 292 | ), |
| 293 | - ("ocean", "rose", "stone", "ink") | 293 | + ("ocean", "rose", "graphite", "ink") |
| 294 | ); | 294 | ); |
| 295 | } | 295 | } |
| 296 | 296 | ||
| @@ -348,7 +348,7 @@ mod tests { | |||
| 348 | .await | 348 | .await |
| 349 | .unwrap(); | 349 | .unwrap(); |
| 350 | store | 350 | store |
| 351 | - .set_colours(&user.id, "sage", "sage", "mist", "ink") | 351 | + .set_colours(&user.id, "sage", "sage", "dusk", "ink") |
| 352 | .await | 352 | .await |
| 353 | .unwrap(); | 353 | .unwrap(); |
| 354 | 354 | ||
| @@ -356,7 +356,7 @@ mod tests { | |||
| 356 | let stored = store.user_by_id(&user.id).await.unwrap().unwrap(); | 356 | let stored = store.user_by_id(&user.id).await.unwrap().unwrap(); |
| 357 | assert_eq!(stored.accent, "ocean"); | 357 | assert_eq!(stored.accent, "ocean"); |
| 358 | assert_eq!(stored.accent_dark, "ocean"); | 358 | assert_eq!(stored.accent_dark, "ocean"); |
| 359 | - assert_eq!(stored.base_light, "mist"); | 359 | + assert_eq!(stored.base_light, "dusk"); |
| 360 | assert_eq!(stored.base_dark, "ink"); | 360 | assert_eq!(stored.base_dark, "ink"); |
| 361 | } | 361 | } |
| 362 | 362 | ||
crates/forge-web/src/accent.rsmodified+315 -92
| @@ -1,10 +1,13 @@ | |||
| 1 | -//! Accent colour and base: which palette and which neutral set a viewer sees. The values live in | 1 | +//! Accent colour and base: which palette and which neutral set a viewer sees. The presets live in |
| 2 | -//! `accent_palette.rs`, which `build.rs` also turns into the stylesheet. This module only resolves | 2 | +//! `accent_palette.rs`, which `build.rs` also turns into the stylesheet. A `hue-N` id stands for a |
| 3 | -//! stored ids and checks which ids forge offers. | 3 | +//! colour of any hue, built by `custom_colour.rs`. This module resolves stored ids and checks which |
| 4 | +//! ids forge offers. | ||
| 4 | 5 | ||
| 5 | use crate::accent_palette::{BASE_DEFAULT, BASES, Base, DEFAULT, PALETTES, Palette}; | 6 | use crate::accent_palette::{BASE_DEFAULT, BASES, Base, DEFAULT, PALETTES, Palette}; |
| 7 | +use crate::custom_colour; | ||
| 6 | 8 | ||
| 7 | -/// The palette for a stored id. An unknown or removed id falls back to the default. | 9 | +/// The preset palette for a stored id. An unknown or removed id, and a `hue-N` id, fall back to the |
| 10 | +/// default. A page shows `accent_id` instead, which keeps a hue. | ||
| 8 | pub fn resolve(stored: &str) -> &'static Palette { | 11 | pub fn resolve(stored: &str) -> &'static Palette { |
| 9 | PALETTES | 12 | PALETTES |
| 10 | .iter() | 13 | .iter() |
| @@ -12,17 +15,25 @@ pub fn resolve(stored: &str) -> &'static Palette { | |||
| 12 | .unwrap_or_else(default_palette) | 15 | .unwrap_or_else(default_palette) |
| 13 | } | 16 | } |
| 14 | 17 | ||
| 15 | -/// True when forge offers this id. | 18 | +/// The accent id a page shows for a stored one: the id itself when forge offers it (a preset or a |
| 19 | +/// hue), otherwise the default. | ||
| 20 | +pub fn accent_id(stored: &str) -> &str { | ||
| 21 | + if is_offered(stored) { stored } else { DEFAULT } | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +/// True when forge offers this accent id: a preset, or a `hue-N` id. | ||
| 16 | pub fn is_offered(id: &str) -> bool { | 25 | pub fn is_offered(id: &str) -> bool { |
| 17 | - PALETTES.iter().any(|p| p.id == id) | 26 | + PALETTES.iter().any(|p| p.id == id) || hue_of(id).is_some() |
| 18 | } | 27 | } |
| 19 | 28 | ||
| 20 | -/// Every offered id, in the order the picker lists them. | 29 | +/// Every preset accent id, in the order the picker lists them. Hues are not listed: the picker |
| 30 | +/// offers a free choice for them. | ||
| 21 | pub fn ids() -> impl Iterator<Item = &'static str> { | 31 | pub fn ids() -> impl Iterator<Item = &'static str> { |
| 22 | PALETTES.iter().map(|p| p.id) | 32 | PALETTES.iter().map(|p| p.id) |
| 23 | } | 33 | } |
| 24 | 34 | ||
| 25 | -/// The base for a stored id. An unknown or removed id falls back to the default. | 35 | +/// The preset base for a stored id. An unknown or removed id, and a `hue-N` id, fall back to the |
| 36 | +/// default. A page shows `base_id` instead, which keeps a hue. | ||
| 26 | pub fn resolve_base(stored: &str) -> &'static Base { | 37 | pub fn resolve_base(stored: &str) -> &'static Base { |
| 27 | BASES | 38 | BASES |
| 28 | .iter() | 39 | .iter() |
| @@ -30,16 +41,107 @@ pub fn resolve_base(stored: &str) -> &'static Base { | |||
| 30 | .unwrap_or_else(default_base) | 41 | .unwrap_or_else(default_base) |
| 31 | } | 42 | } |
| 32 | 43 | ||
| 33 | -/// True when forge offers this base id. | 44 | +/// The base id a page shows for a stored one: the id itself when forge offers it (a preset or a |
| 45 | +/// hue), otherwise the default. | ||
| 46 | +pub fn base_id(stored: &str) -> &str { | ||
| 47 | + if is_offered_base(stored) { | ||
| 48 | + stored | ||
| 49 | + } else { | ||
| 50 | + BASE_DEFAULT | ||
| 51 | + } | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +/// True when forge offers this base id: a preset, or a `hue-N` id. | ||
| 34 | pub fn is_offered_base(id: &str) -> bool { | 55 | pub fn is_offered_base(id: &str) -> bool { |
| 35 | - BASES.iter().any(|b| b.id == id) | 56 | + BASES.iter().any(|b| b.id == id) || hue_of(id).is_some() |
| 36 | } | 57 | } |
| 37 | 58 | ||
| 38 | -/// Every offered base id, in the order the picker lists them. | 59 | +/// Every preset base id, in the order the picker lists them. Hues are not listed. |
| 39 | pub fn base_ids() -> impl Iterator<Item = &'static str> { | 60 | pub fn base_ids() -> impl Iterator<Item = &'static str> { |
| 40 | BASES.iter().map(|b| b.id) | 61 | BASES.iter().map(|b| b.id) |
| 41 | } | 62 | } |
| 42 | 63 | ||
| 64 | +/// The hue N of a `hue-N` id: an integer `0..=359` with no leading zeros (except `hue-0`). Any | ||
| 65 | +/// other id is None. | ||
| 66 | +pub fn hue_of(id: &str) -> Option<u16> { | ||
| 67 | + let digits = id.strip_prefix("hue-")?; | ||
| 68 | + let canonical = digits == "0" || (!digits.is_empty() && !digits.starts_with('0')); | ||
| 69 | + if !canonical || digits.len() > 3 || !digits.bytes().all(|b| b.is_ascii_digit()) { | ||
| 70 | + return None; | ||
| 71 | + } | ||
| 72 | + digits.parse::<u16>().ok().filter(|hue| *hue < 360) | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +/// The OKLCH hue, in degrees, of a preset accent's light colour. None for an id that is not a | ||
| 76 | +/// preset. | ||
| 77 | +#[allow(dead_code)] // The settings picker places its knob with this. | ||
| 78 | +pub fn preset_accent_hue(id: &str) -> Option<u16> { | ||
| 79 | + PALETTES | ||
| 80 | + .iter() | ||
| 81 | + .find(|p| p.id == id) | ||
| 82 | + .map(|p| custom_colour::hex_hue(p.light.accent)) | ||
| 83 | +} | ||
| 84 | + | ||
| 85 | +/// The OKLCH hue, in degrees, of a preset base's light background. A near-neutral base has no | ||
| 86 | +/// strong hue, so this only places the picker's knob. None for an id that is not a preset. | ||
| 87 | +#[allow(dead_code)] // The settings picker places its knob with this. | ||
| 88 | +pub fn preset_base_hue(id: &str) -> Option<u16> { | ||
| 89 | + BASES | ||
| 90 | + .iter() | ||
| 91 | + .find(|b| b.id == id) | ||
| 92 | + .map(|b| custom_colour::hex_hue(b.light.bg)) | ||
| 93 | +} | ||
| 94 | + | ||
| 95 | +/// The `#RRGGBB` the picker shows for an accent id in one theme: the accent itself. A `hue-N` id | ||
| 96 | +/// gets the accent built for its hue; an id forge does not offer gets the default's. | ||
| 97 | +#[allow(dead_code)] // The settings picker shows its chips with this. | ||
| 98 | +pub fn swatch(id: &str, dark: bool) -> String { | ||
| 99 | + match hue_of(id) { | ||
| 100 | + Some(hue) => custom_colour::accent_tokens(hue, dark).accent, | ||
| 101 | + None => { | ||
| 102 | + let palette = resolve(id); | ||
| 103 | + let tokens = if dark { &palette.dark } else { &palette.light }; | ||
| 104 | + tokens.accent.to_owned() | ||
| 105 | + } | ||
| 106 | + } | ||
| 107 | +} | ||
| 108 | + | ||
| 109 | +/// The background and text colours the picker shows for a base id in one theme. A `hue-N` id gets | ||
| 110 | +/// the base built for its hue; an id forge does not offer gets the default's. | ||
| 111 | +#[allow(dead_code)] // The settings picker shows its chips with this. | ||
| 112 | +pub fn base_swatch(id: &str, dark: bool) -> (String, String) { | ||
| 113 | + match hue_of(id) { | ||
| 114 | + Some(hue) => { | ||
| 115 | + let tokens = custom_colour::base_tokens(hue, dark); | ||
| 116 | + (tokens.bg, tokens.text) | ||
| 117 | + } | ||
| 118 | + None => { | ||
| 119 | + let base = resolve_base(id); | ||
| 120 | + let tokens = if dark { &base.dark } else { &base.light }; | ||
| 121 | + (tokens.bg.to_owned(), tokens.text.to_owned()) | ||
| 122 | + } | ||
| 123 | + } | ||
| 124 | +} | ||
| 125 | + | ||
| 126 | +/// The link to the stylesheet that styles the custom ids of one page, or None when none of the four | ||
| 127 | +/// is a hue (the presets are styled by the main stylesheet). The ids go in as given, so pass the | ||
| 128 | +/// ids a page shows (see `accent_id` and `base_id`). | ||
| 129 | +pub fn custom_css_href( | ||
| 130 | + accent_light: &str, | ||
| 131 | + accent_dark: &str, | ||
| 132 | + base_light: &str, | ||
| 133 | + base_dark: &str, | ||
| 134 | +) -> Option<String> { | ||
| 135 | + let any_hue = [accent_light, accent_dark, base_light, base_dark] | ||
| 136 | + .iter() | ||
| 137 | + .any(|id| hue_of(id).is_some()); | ||
| 138 | + any_hue.then(|| { | ||
| 139 | + format!( | ||
| 140 | + "/theme/custom.css?al={accent_light}&ad={accent_dark}&bl={base_light}&bd={base_dark}" | ||
| 141 | + ) | ||
| 142 | + }) | ||
| 143 | +} | ||
| 144 | + | ||
| 43 | fn default_palette() -> &'static Palette { | 145 | fn default_palette() -> &'static Palette { |
| 44 | PALETTES | 146 | PALETTES |
| 45 | .iter() | 147 | .iter() |
| @@ -59,26 +161,15 @@ mod tests { | |||
| 59 | use std::collections::HashSet; | 161 | use std::collections::HashSet; |
| 60 | 162 | ||
| 61 | use super::*; | 163 | use super::*; |
| 62 | - use crate::accent_palette::{BASE_TOKEN_VARS, TOKEN_VARS}; | 164 | + use crate::accent_palette::{BASE_TOKEN_VARS, BaseTokens, TOKEN_VARS, Tokens}; |
| 63 | - | 165 | + use crate::custom_colour::{ |
| 64 | - /// WCAG relative luminance of a `#RRGGBB` colour. | 166 | + OwnedBaseTokens, OwnedTokens, accent_tokens, base_tokens, contrast_ratio, |
| 65 | - fn luminance(hex: &str) -> f64 { | 167 | + }; |
| 66 | - let channel = |i: usize| { | ||
| 67 | - let v = f64::from(u8::from_str_radix(&hex[i..i + 2], 16).expect("hex")) / 255.0; | ||
| 68 | - if v <= 0.03928 { | ||
| 69 | - v / 12.92 | ||
| 70 | - } else { | ||
| 71 | - ((v + 0.055) / 1.055).powf(2.4) | ||
| 72 | - } | ||
| 73 | - }; | ||
| 74 | - 0.2126 * channel(1) + 0.7152 * channel(3) + 0.0722 * channel(5) | ||
| 75 | - } | ||
| 76 | 168 | ||
| 77 | - /// WCAG contrast ratio between two colours. | 169 | + /// One accent's light and dark colours, as owned strings. Presets and hues go through the same |
| 78 | - fn contrast(a: &str, b: &str) -> f64 { | 170 | + /// checks this way. |
| 79 | - let (x, y) = (luminance(a), luminance(b)); | 171 | + type AccentSet = (String, OwnedTokens, OwnedTokens); |
| 80 | - (x.max(y) + 0.05) / (x.min(y) + 0.05) | 172 | + type BaseSet = (String, OwnedBaseTokens, OwnedBaseTokens); |
| 81 | - } | ||
| 82 | 173 | ||
| 83 | fn is_hex_colour(value: &str) -> bool { | 174 | fn is_hex_colour(value: &str) -> bool { |
| 84 | value.len() == 7 | 175 | value.len() == 7 |
| @@ -86,6 +177,72 @@ mod tests { | |||
| 86 | && value[1..].bytes().all(|b| b.is_ascii_hexdigit()) | 177 | && value[1..].bytes().all(|b| b.is_ascii_hexdigit()) |
| 87 | } | 178 | } |
| 88 | 179 | ||
| 180 | + fn owned_tokens(t: &Tokens) -> OwnedTokens { | ||
| 181 | + OwnedTokens { | ||
| 182 | + accent: t.accent.to_owned(), | ||
| 183 | + accent_ink: t.accent_ink.to_owned(), | ||
| 184 | + accent_soft: t.accent_soft.to_owned(), | ||
| 185 | + accent_text: t.accent_text.to_owned(), | ||
| 186 | + focus: t.focus.to_owned(), | ||
| 187 | + public_bg: t.public_bg.to_owned(), | ||
| 188 | + public_text: t.public_text.to_owned(), | ||
| 189 | + note: t.note.to_owned(), | ||
| 190 | + hunk_bg: t.hunk_bg.to_owned(), | ||
| 191 | + hunk_text: t.hunk_text.to_owned(), | ||
| 192 | + } | ||
| 193 | + } | ||
| 194 | + | ||
| 195 | + fn owned_base(t: &BaseTokens) -> OwnedBaseTokens { | ||
| 196 | + OwnedBaseTokens { | ||
| 197 | + bg: t.bg.to_owned(), | ||
| 198 | + surface: t.surface.to_owned(), | ||
| 199 | + surface_2: t.surface_2.to_owned(), | ||
| 200 | + text: t.text.to_owned(), | ||
| 201 | + text_2: t.text_2.to_owned(), | ||
| 202 | + muted: t.muted.to_owned(), | ||
| 203 | + border: t.border.to_owned(), | ||
| 204 | + border_strong: t.border_strong.to_owned(), | ||
| 205 | + code_bg: t.code_bg.to_owned(), | ||
| 206 | + private_bg: t.private_bg.to_owned(), | ||
| 207 | + private_text: t.private_text.to_owned(), | ||
| 208 | + ln_text: t.ln_text.to_owned(), | ||
| 209 | + } | ||
| 210 | + } | ||
| 211 | + | ||
| 212 | + /// Every accent the picker can offer: the presets, then the 360 hues. | ||
| 213 | + fn all_accents() -> Vec<AccentSet> { | ||
| 214 | + let presets = PALETTES.iter().map(|p| { | ||
| 215 | + ( | ||
| 216 | + p.id.to_owned(), | ||
| 217 | + owned_tokens(&p.light), | ||
| 218 | + owned_tokens(&p.dark), | ||
| 219 | + ) | ||
| 220 | + }); | ||
| 221 | + let hues = (0..360u16).map(|hue| { | ||
| 222 | + ( | ||
| 223 | + format!("hue-{hue}"), | ||
| 224 | + accent_tokens(hue, false), | ||
| 225 | + accent_tokens(hue, true), | ||
| 226 | + ) | ||
| 227 | + }); | ||
| 228 | + presets.chain(hues).collect() | ||
| 229 | + } | ||
| 230 | + | ||
| 231 | + /// Every base the picker can offer: the presets, then the 360 hues. | ||
| 232 | + fn all_bases() -> Vec<BaseSet> { | ||
| 233 | + let presets = BASES | ||
| 234 | + .iter() | ||
| 235 | + .map(|b| (b.id.to_owned(), owned_base(&b.light), owned_base(&b.dark))); | ||
| 236 | + let hues = (0..360u16).map(|hue| { | ||
| 237 | + ( | ||
| 238 | + format!("hue-{hue}"), | ||
| 239 | + base_tokens(hue, false), | ||
| 240 | + base_tokens(hue, true), | ||
| 241 | + ) | ||
| 242 | + }); | ||
| 243 | + presets.chain(hues).collect() | ||
| 244 | + } | ||
| 245 | + | ||
| 89 | #[test] | 246 | #[test] |
| 90 | fn ids_are_slugs_unique_and_the_default_comes_first() { | 247 | fn ids_are_slugs_unique_and_the_default_comes_first() { |
| 91 | assert_eq!(PALETTES[0].id, DEFAULT); | 248 | assert_eq!(PALETTES[0].id, DEFAULT); |
| @@ -134,79 +291,126 @@ mod tests { | |||
| 134 | } | 291 | } |
| 135 | } | 292 | } |
| 136 | 293 | ||
| 294 | + #[test] | ||
| 295 | + fn the_presets_are_offered_in_picker_order() { | ||
| 296 | + assert_eq!( | ||
| 297 | + ids().collect::<Vec<_>>(), | ||
| 298 | + ["sage", "spark", "ocean", "plum", "rose", "gold"] | ||
| 299 | + ); | ||
| 300 | + assert_eq!( | ||
| 301 | + base_ids().collect::<Vec<_>>(), | ||
| 302 | + ["fern", "spark", "graphite", "dusk", "ink"] | ||
| 303 | + ); | ||
| 304 | + } | ||
| 305 | + | ||
| 306 | + #[test] | ||
| 307 | + fn removed_ids_are_not_offered() { | ||
| 308 | + for id in ["ember", "ochre", "teal", "Sage", "sage ", "terracotta"] { | ||
| 309 | + assert!(!is_offered(id), "{id}"); | ||
| 310 | + } | ||
| 311 | + for id in ["stone", "mist", "Fern", "dune", "slate-blue"] { | ||
| 312 | + assert!(!is_offered_base(id), "{id}"); | ||
| 313 | + } | ||
| 314 | + } | ||
| 315 | + | ||
| 137 | #[test] | 316 | #[test] |
| 138 | fn unknown_and_removed_ids_fall_back_to_the_default() { | 317 | fn unknown_and_removed_ids_fall_back_to_the_default() { |
| 139 | assert_eq!(resolve("ocean").id, "ocean"); | 318 | assert_eq!(resolve("ocean").id, "ocean"); |
| 140 | assert_eq!(resolve("removed-palette").id, DEFAULT); | 319 | assert_eq!(resolve("removed-palette").id, DEFAULT); |
| 141 | assert_eq!(resolve("").id, DEFAULT); | 320 | assert_eq!(resolve("").id, DEFAULT); |
| 321 | + assert_eq!(accent_id("ocean"), "ocean"); | ||
| 322 | + assert_eq!(accent_id("ember"), DEFAULT); | ||
| 323 | + assert_eq!(accent_id(""), DEFAULT); | ||
| 142 | assert!(is_offered("plum")); | 324 | assert!(is_offered("plum")); |
| 143 | assert!(!is_offered("removed-palette")); | 325 | assert!(!is_offered("removed-palette")); |
| 326 | + assert_eq!(resolve_base("ink").id, "ink"); | ||
| 327 | + assert_eq!(resolve_base("removed-base").id, BASE_DEFAULT); | ||
| 328 | + assert_eq!(base_id("mist"), BASE_DEFAULT); | ||
| 329 | + assert_eq!(base_id("graphite"), "graphite"); | ||
| 144 | } | 330 | } |
| 145 | 331 | ||
| 146 | #[test] | 332 | #[test] |
| 147 | - fn the_newer_accents_are_offered_by_their_exact_id() { | 333 | + fn hue_ids_are_canonical_numbers_below_360() { |
| 148 | - for id in [ | 334 | + for (id, hue) in [ |
| 149 | - "teal", "moss", "indigo", "amber", "clay", "berry", "ember", "crimson", "coral", | 335 | + ("hue-0", 0), |
| 150 | - "gold", "lime", "mint", "cyan", "sky", "violet", "fuchsia", | 336 | + ("hue-7", 7), |
| 337 | + ("hue-42", 42), | ||
| 338 | + ("hue-215", 215), | ||
| 339 | + ("hue-359", 359), | ||
| 151 | ] { | 340 | ] { |
| 341 | + assert_eq!(hue_of(id), Some(hue), "{id}"); | ||
| 152 | assert!(is_offered(id), "{id}"); | 342 | assert!(is_offered(id), "{id}"); |
| 153 | - assert_eq!(resolve(id).id, id); | 343 | + assert!(is_offered_base(id), "{id}"); |
| 344 | + assert_eq!(accent_id(id), id); | ||
| 345 | + assert_eq!(base_id(id), id); | ||
| 154 | } | 346 | } |
| 155 | for id in [ | 347 | for id in [ |
| 156 | - "Teal", | 348 | + "hue-", "hue-360", "hue-01", "hue-00", "hue-1000", "hue--1", "hue-+5", "hue-5 ", |
| 157 | - "teal ", | 349 | + "Hue-5", "hue-5.0", "hue5", "hue_5", "hue-0x1", |
| 158 | - "terracotta", | ||
| 159 | - "clay-2", | ||
| 160 | - "Ember", | ||
| 161 | - "Crimson", | ||
| 162 | - "rust", | ||
| 163 | ] { | 350 | ] { |
| 351 | + assert_eq!(hue_of(id), None, "{id}"); | ||
| 164 | assert!(!is_offered(id), "{id}"); | 352 | assert!(!is_offered(id), "{id}"); |
| 353 | + assert!(!is_offered_base(id), "{id}"); | ||
| 165 | } | 354 | } |
| 166 | - assert_eq!(ids().count(), 22); | 355 | + // A hue is not a preset, so the preset lookup still falls back to the default. |
| 356 | + assert_eq!(resolve("hue-215").id, DEFAULT); | ||
| 357 | + assert_eq!(resolve_base("hue-215").id, BASE_DEFAULT); | ||
| 167 | } | 358 | } |
| 168 | 359 | ||
| 169 | #[test] | 360 | #[test] |
| 170 | - fn the_newer_backgrounds_are_offered_by_their_exact_id() { | 361 | + fn preset_hues_come_from_the_colour() { |
| 171 | - for id in ["dune", "lilac", "dusk", "blush", "graphite", "pine"] { | 362 | + assert_eq!(preset_accent_hue("sage"), Some(149)); |
| 172 | - assert!(is_offered_base(id), "{id}"); | 363 | + assert_eq!(preset_accent_hue("ocean"), Some(240)); |
| 173 | - assert_eq!(resolve_base(id).id, id); | 364 | + assert_eq!(preset_accent_hue("spark"), Some(38)); |
| 174 | - } | 365 | + assert_eq!(preset_accent_hue("fern"), None); |
| 175 | - for id in ["Dune", "dusk ", "slate-blue", "Pine"] { | 366 | + assert_eq!(preset_accent_hue("hue-5"), None); |
| 176 | - assert!(!is_offered_base(id), "{id}"); | 367 | + assert!(preset_base_hue("fern").is_some()); |
| 177 | - } | 368 | + assert!(preset_base_hue("spark").is_some()); |
| 178 | - assert_eq!(base_ids().count(), 11); | 369 | + assert_eq!(preset_base_hue("sage"), None); |
| 179 | } | 370 | } |
| 180 | 371 | ||
| 181 | #[test] | 372 | #[test] |
| 182 | - fn unknown_and_removed_base_ids_fall_back_to_the_default() { | 373 | + fn swatches_show_the_accent_and_the_base_for_presets_and_hues() { |
| 183 | - assert_eq!(resolve_base("ink").id, "ink"); | 374 | + assert_eq!(swatch("sage", false), "#5E7D63"); |
| 184 | - assert_eq!(resolve_base("removed-base").id, BASE_DEFAULT); | 375 | + assert_eq!(swatch("sage", true), "#9DBEA2"); |
| 185 | - assert_eq!(resolve_base("").id, BASE_DEFAULT); | 376 | + assert_eq!(swatch("hue-215", false), accent_tokens(215, false).accent); |
| 186 | - assert!(is_offered_base("mist")); | 377 | + assert_eq!(swatch("hue-215", true), accent_tokens(215, true).accent); |
| 187 | - assert!(!is_offered_base("removed-base")); | 378 | + assert_eq!(swatch("ember", false), swatch("sage", false)); |
| 379 | + let (bg, text) = base_swatch("fern", false); | ||
| 380 | + assert_eq!((bg.as_str(), text.as_str()), ("#F6F8F5", "#1E2420")); | ||
| 381 | + let (bg, text) = base_swatch("hue-215", true); | ||
| 382 | + assert_eq!(bg, base_tokens(215, true).bg); | ||
| 383 | + assert_eq!(text, base_tokens(215, true).text); | ||
| 384 | + } | ||
| 385 | + | ||
| 386 | + #[test] | ||
| 387 | + fn the_custom_stylesheet_is_linked_only_when_a_hue_is_chosen() { | ||
| 388 | + assert_eq!(custom_css_href("sage", "plum", "fern", "ink"), None); | ||
| 389 | + assert_eq!( | ||
| 390 | + custom_css_href("hue-215", "plum", "fern", "hue-7").as_deref(), | ||
| 391 | + Some("/theme/custom.css?al=hue-215&ad=plum&bl=fern&bd=hue-7") | ||
| 392 | + ); | ||
| 393 | + assert_eq!( | ||
| 394 | + custom_css_href("sage", "sage", "spark", "hue-0").as_deref(), | ||
| 395 | + Some("/theme/custom.css?al=sage&ad=sage&bl=spark&bd=hue-0") | ||
| 396 | + ); | ||
| 188 | } | 397 | } |
| 189 | 398 | ||
| 190 | #[test] | 399 | #[test] |
| 191 | fn every_accent_keeps_its_own_text_readable() { | 400 | fn every_accent_keeps_its_own_text_readable() { |
| 192 | - for p in PALETTES { | 401 | + for (id, light, dark) in all_accents() { |
| 193 | - let check = |what: &str, ratio: f64, min: f64| { | 402 | + for (theme, t) in [("light", &light), ("dark", &dark)] { |
| 194 | - assert!(ratio >= min, "{} {what}: {ratio:.2} < {min}", p.id); | 403 | + let check = |what: &str, ratio: f64, min: f64| { |
| 195 | - }; | 404 | + assert!(ratio >= min, "{id} {theme} {what}: {ratio:.2} < {min}"); |
| 196 | - check( | 405 | + }; |
| 197 | - "accent_text on accent (light)", | 406 | + check( |
| 198 | - contrast(p.light.accent_text, p.light.accent), | 407 | + "accent_text on accent", |
| 199 | - 4.5, | 408 | + contrast_ratio(&t.accent_text, &t.accent), |
| 200 | - ); | 409 | + 4.5, |
| 201 | - check( | 410 | + ); |
| 202 | - "accent_text on accent (dark)", | ||
| 203 | - contrast(p.dark.accent_text, p.dark.accent), | ||
| 204 | - 4.5, | ||
| 205 | - ); | ||
| 206 | - for t in [&p.light, &p.dark] { | ||
| 207 | check( | 411 | check( |
| 208 | "public_text on public_bg", | 412 | "public_text on public_bg", |
| 209 | - contrast(t.public_text, t.public_bg), | 413 | + contrast_ratio(&t.public_text, &t.public_bg), |
| 210 | 4.5, | 414 | 4.5, |
| 211 | ); | 415 | ); |
| 212 | } | 416 | } |
| @@ -215,41 +419,60 @@ mod tests { | |||
| 215 | 419 | ||
| 216 | #[test] | 420 | #[test] |
| 217 | fn every_base_with_every_accent_meets_the_contrast_targets() { | 421 | fn every_base_with_every_accent_meets_the_contrast_targets() { |
| 218 | - for base in BASES { | 422 | + let accents = all_accents(); |
| 219 | - for p in PALETTES { | 423 | + for (base_id, base_light, base_dark) in all_bases() { |
| 424 | + for (accent_id, accent_light, accent_dark) in &accents { | ||
| 220 | let themes = [ | 425 | let themes = [ |
| 221 | - ("light", &base.light, &p.light), | 426 | + ("light", &base_light, accent_light), |
| 222 | - ("dark", &base.dark, &p.dark), | 427 | + ("dark", &base_dark, accent_dark), |
| 223 | ]; | 428 | ]; |
| 224 | for (theme, b, t) in themes { | 429 | for (theme, b, t) in themes { |
| 225 | - let who = format!("{} with {} ({theme})", base.id, p.id); | ||
| 226 | let check = |what: &str, ratio: f64, min: f64| { | 430 | let check = |what: &str, ratio: f64, min: f64| { |
| 227 | - assert!(ratio >= min, "{who} {what}: {ratio:.2} < {min}"); | 431 | + assert!( |
| 432 | + ratio >= min, | ||
| 433 | + "{base_id} with {accent_id} ({theme}) {what}: {ratio:.2} < {min}" | ||
| 434 | + ); | ||
| 228 | }; | 435 | }; |
| 229 | - check("text on bg", contrast(b.text, b.bg), 7.0); | 436 | + check("text on bg", contrast_ratio(&b.text, &b.bg), 7.0); |
| 230 | - check("text on surface", contrast(b.text, b.surface), 7.0); | 437 | + check("text on surface", contrast_ratio(&b.text, &b.surface), 7.0); |
| 231 | - check("text_2 on bg", contrast(b.text_2, b.bg), 4.5); | 438 | + check("text_2 on bg", contrast_ratio(&b.text_2, &b.bg), 4.5); |
| 232 | - check("text_2 on surface", contrast(b.text_2, b.surface), 4.5); | 439 | + check( |
| 233 | - check("muted on bg", contrast(b.muted, b.bg), 4.5); | 440 | + "text_2 on surface", |
| 234 | - check("muted on surface", contrast(b.muted, b.surface), 4.5); | 441 | + contrast_ratio(&b.text_2, &b.surface), |
| 235 | - check("ln_text on code_bg", contrast(b.ln_text, b.code_bg), 4.5); | 442 | + 4.5, |
| 443 | + ); | ||
| 444 | + check("muted on bg", contrast_ratio(&b.muted, &b.bg), 4.5); | ||
| 445 | + check( | ||
| 446 | + "muted on surface", | ||
| 447 | + contrast_ratio(&b.muted, &b.surface), | ||
| 448 | + 4.5, | ||
| 449 | + ); | ||
| 450 | + check( | ||
| 451 | + "ln_text on code_bg", | ||
| 452 | + contrast_ratio(&b.ln_text, &b.code_bg), | ||
| 453 | + 4.5, | ||
| 454 | + ); | ||
| 236 | check( | 455 | check( |
| 237 | "private_text on private_bg", | 456 | "private_text on private_bg", |
| 238 | - contrast(b.private_text, b.private_bg), | 457 | + contrast_ratio(&b.private_text, &b.private_bg), |
| 458 | + 4.5, | ||
| 459 | + ); | ||
| 460 | + check( | ||
| 461 | + "accent_ink on bg", | ||
| 462 | + contrast_ratio(&t.accent_ink, &b.bg), | ||
| 239 | 4.5, | 463 | 4.5, |
| 240 | ); | 464 | ); |
| 241 | - check("accent_ink on bg", contrast(t.accent_ink, b.bg), 4.5); | ||
| 242 | check( | 465 | check( |
| 243 | "accent_ink on surface", | 466 | "accent_ink on surface", |
| 244 | - contrast(t.accent_ink, b.surface), | 467 | + contrast_ratio(&t.accent_ink, &b.surface), |
| 245 | 4.5, | 468 | 4.5, |
| 246 | ); | 469 | ); |
| 247 | check( | 470 | check( |
| 248 | "accent_ink on accent_soft", | 471 | "accent_ink on accent_soft", |
| 249 | - contrast(t.accent_ink, t.accent_soft), | 472 | + contrast_ratio(&t.accent_ink, &t.accent_soft), |
| 250 | 4.5, | 473 | 4.5, |
| 251 | ); | 474 | ); |
| 252 | - check("focus on bg", contrast(t.focus, b.bg), 3.0); | 475 | + check("focus on bg", contrast_ratio(&t.focus, &b.bg), 3.0); |
| 253 | } | 476 | } |
| 254 | } | 477 | } |
| 255 | } | 478 | } |
crates/forge-web/src/accent_palette.rsmodified+108 -748
| @@ -111,6 +111,34 @@ pub const PALETTES: &[Palette] = &[ | |||
| 111 | hunk_text: "#9DBEA2", | 111 | hunk_text: "#9DBEA2", |
| 112 | }, | 112 | }, |
| 113 | }, | 113 | }, |
| 114 | + // Forge-spark orange: hot metal, the most saturated accent on offer. | ||
| 115 | + Palette { | ||
| 116 | + id: "spark", | ||
| 117 | + light: Tokens { | ||
| 118 | + accent: "#C2410C", | ||
| 119 | + accent_ink: "#9A3412", | ||
| 120 | + accent_soft: "#FCEBE0", | ||
| 121 | + accent_text: "#FFFFFF", | ||
| 122 | + focus: "#9A3412", | ||
| 123 | + public_bg: "#FCEBE0", | ||
| 124 | + public_text: "#9A3412", | ||
| 125 | + note: "#9A3412", | ||
| 126 | + hunk_bg: "#FDF4EF", | ||
| 127 | + hunk_text: "#8F3110", | ||
| 128 | + }, | ||
| 129 | + dark: Tokens { | ||
| 130 | + accent: "#FB923C", | ||
| 131 | + accent_ink: "#FDBA74", | ||
| 132 | + accent_soft: "#3A2010", | ||
| 133 | + accent_text: "#1C0D04", | ||
| 134 | + focus: "#FB923C", | ||
| 135 | + public_bg: "#3A2010", | ||
| 136 | + public_text: "#FDBA74", | ||
| 137 | + note: "#FDBA74", | ||
| 138 | + hunk_bg: "#2A1A0F", | ||
| 139 | + hunk_text: "#FB923C", | ||
| 140 | + }, | ||
| 141 | + }, | ||
| 114 | // Blue, clear and cool. | 142 | // Blue, clear and cool. |
| 115 | Palette { | 143 | Palette { |
| 116 | id: "ocean", | 144 | id: "ocean", |
| @@ -195,315 +223,7 @@ pub const PALETTES: &[Palette] = &[ | |||
| 195 | hunk_text: "#E79DAD", | 223 | hunk_text: "#E79DAD", |
| 196 | }, | 224 | }, |
| 197 | }, | 225 | }, |
| 198 | - // Clay brown, warmer and earthier than the warning amber. | 226 | + // Bright yellow, leaning to lemon, so it takes dark text. |
| 199 | - Palette { | ||
| 200 | - id: "ochre", | ||
| 201 | - light: Tokens { | ||
| 202 | - accent: "#93684B", | ||
| 203 | - accent_ink: "#7A5338", | ||
| 204 | - accent_soft: "#F5E6DD", | ||
| 205 | - accent_text: "#FFFFFF", | ||
| 206 | - focus: "#7A5338", | ||
| 207 | - public_bg: "#F5E6DD", | ||
| 208 | - public_text: "#7A5338", | ||
| 209 | - note: "#7A5338", | ||
| 210 | - hunk_bg: "#F6EEE8", | ||
| 211 | - hunk_text: "#724B30", | ||
| 212 | - }, | ||
| 213 | - dark: Tokens { | ||
| 214 | - accent: "#D8A98A", | ||
| 215 | - accent_ink: "#E4BCA1", | ||
| 216 | - accent_soft: "#39281D", | ||
| 217 | - accent_text: "#170D07", | ||
| 218 | - focus: "#D8A98A", | ||
| 219 | - public_bg: "#39281D", | ||
| 220 | - public_text: "#E4BCA1", | ||
| 221 | - note: "#E4BCA1", | ||
| 222 | - hunk_bg: "#2C211A", | ||
| 223 | - hunk_text: "#D8A98A", | ||
| 224 | - }, | ||
| 225 | - }, | ||
| 226 | - // Blue-grey graphite, nearly neutral. | ||
| 227 | - Palette { | ||
| 228 | - id: "slate", | ||
| 229 | - light: Tokens { | ||
| 230 | - accent: "#657383", | ||
| 231 | - accent_ink: "#505E6C", | ||
| 232 | - accent_soft: "#E0EBF7", | ||
| 233 | - accent_text: "#FFFFFF", | ||
| 234 | - focus: "#505E6C", | ||
| 235 | - public_bg: "#E0EBF7", | ||
| 236 | - public_text: "#505E6C", | ||
| 237 | - note: "#505E6C", | ||
| 238 | - hunk_bg: "#EAF0F7", | ||
| 239 | - hunk_text: "#485563", | ||
| 240 | - }, | ||
| 241 | - dark: Tokens { | ||
| 242 | - accent: "#A4B4C4", | ||
| 243 | - accent_ink: "#B8C6D5", | ||
| 244 | - accent_soft: "#272D33", | ||
| 245 | - accent_text: "#0C1013", | ||
| 246 | - focus: "#A4B4C4", | ||
| 247 | - public_bg: "#272D33", | ||
| 248 | - public_text: "#B8C6D5", | ||
| 249 | - note: "#B8C6D5", | ||
| 250 | - hunk_bg: "#212428", | ||
| 251 | - hunk_text: "#A4B4C4", | ||
| 252 | - }, | ||
| 253 | - }, | ||
| 254 | - // Teal, a muted blue-green. | ||
| 255 | - Palette { | ||
| 256 | - id: "teal", | ||
| 257 | - light: Tokens { | ||
| 258 | - accent: "#437C7C", | ||
| 259 | - accent_ink: "#396A6A", | ||
| 260 | - accent_soft: "#E7F0F0", | ||
| 261 | - accent_text: "#FFFFFF", | ||
| 262 | - focus: "#396A6A", | ||
| 263 | - public_bg: "#E7F0F0", | ||
| 264 | - public_text: "#396A6A", | ||
| 265 | - note: "#396A6A", | ||
| 266 | - hunk_bg: "#F1F6F6", | ||
| 267 | - hunk_text: "#366464", | ||
| 268 | - }, | ||
| 269 | - dark: Tokens { | ||
| 270 | - accent: "#4B8B8B", | ||
| 271 | - accent_ink: "#58A4A4", | ||
| 272 | - accent_soft: "#213030", | ||
| 273 | - accent_text: "#0F1515", | ||
| 274 | - focus: "#4B8B8B", | ||
| 275 | - public_bg: "#213030", | ||
| 276 | - public_text: "#58A4A4", | ||
| 277 | - note: "#58A4A4", | ||
| 278 | - hunk_bg: "#1A2323", | ||
| 279 | - hunk_text: "#58A4A4", | ||
| 280 | - }, | ||
| 281 | - }, | ||
| 282 | - // Olive green, earthier than Sage. | ||
| 283 | - Palette { | ||
| 284 | - id: "moss", | ||
| 285 | - light: Tokens { | ||
| 286 | - accent: "#697947", | ||
| 287 | - accent_ink: "#59673D", | ||
| 288 | - accent_soft: "#EDF0E8", | ||
| 289 | - accent_text: "#FFFFFF", | ||
| 290 | - focus: "#59673D", | ||
| 291 | - public_bg: "#EDF0E8", | ||
| 292 | - public_text: "#59673D", | ||
| 293 | - note: "#59673D", | ||
| 294 | - hunk_bg: "#F4F5F2", | ||
| 295 | - hunk_text: "#546139", | ||
| 296 | - }, | ||
| 297 | - dark: Tokens { | ||
| 298 | - accent: "#758850", | ||
| 299 | - accent_ink: "#8AA05E", | ||
| 300 | - accent_soft: "#2B2F22", | ||
| 301 | - accent_text: "#131410", | ||
| 302 | - focus: "#758850", | ||
| 303 | - public_bg: "#2B2F22", | ||
| 304 | - public_text: "#8AA05E", | ||
| 305 | - note: "#8AA05E", | ||
| 306 | - hunk_bg: "#20231B", | ||
| 307 | - hunk_text: "#8AA05E", | ||
| 308 | - }, | ||
| 309 | - }, | ||
| 310 | - // Soft indigo, cooler than Plum. | ||
| 311 | - Palette { | ||
| 312 | - id: "indigo", | ||
| 313 | - light: Tokens { | ||
| 314 | - accent: "#646FB3", | ||
| 315 | - accent_ink: "#515DA5", | ||
| 316 | - accent_soft: "#E7E8F1", | ||
| 317 | - accent_text: "#FFFFFF", | ||
| 318 | - focus: "#515DA5", | ||
| 319 | - public_bg: "#E7E8F1", | ||
| 320 | - public_text: "#515DA5", | ||
| 321 | - note: "#515DA5", | ||
| 322 | - hunk_bg: "#F1F2F6", | ||
| 323 | - hunk_text: "#4E599F", | ||
| 324 | - }, | ||
| 325 | - dark: Tokens { | ||
| 326 | - accent: "#717BB9", | ||
| 327 | - accent_ink: "#858EC3", | ||
| 328 | - accent_soft: "#202331", | ||
| 329 | - accent_text: "#0F1015", | ||
| 330 | - focus: "#717BB9", | ||
| 331 | - public_bg: "#202331", | ||
| 332 | - public_text: "#858EC3", | ||
| 333 | - note: "#858EC3", | ||
| 334 | - hunk_bg: "#191B24", | ||
| 335 | - hunk_text: "#858EC3", | ||
| 336 | - }, | ||
| 337 | - }, | ||
| 338 | - // Golden amber, warm and muted. | ||
| 339 | - Palette { | ||
| 340 | - id: "amber", | ||
| 341 | - light: Tokens { | ||
| 342 | - accent: "#936D22", | ||
| 343 | - accent_ink: "#7D5D1D", | ||
| 344 | - accent_soft: "#F5EFE2", | ||
| 345 | - accent_text: "#FFFFFF", | ||
| 346 | - focus: "#7D5D1D", | ||
| 347 | - public_bg: "#F5EFE2", | ||
| 348 | - public_text: "#7D5D1D", | ||
| 349 | - note: "#7D5D1D", | ||
| 350 | - hunk_bg: "#F8F5EF", | ||
| 351 | - hunk_text: "#75571B", | ||
| 352 | - }, | ||
| 353 | - dark: Tokens { | ||
| 354 | - accent: "#A37A26", | ||
| 355 | - accent_ink: "#C3912E", | ||
| 356 | - accent_soft: "#382E1A", | ||
| 357 | - accent_text: "#17140C", | ||
| 358 | - focus: "#A37A26", | ||
| 359 | - public_bg: "#382E1A", | ||
| 360 | - public_text: "#C3912E", | ||
| 361 | - note: "#C3912E", | ||
| 362 | - hunk_bg: "#282215", | ||
| 363 | - hunk_text: "#C3912E", | ||
| 364 | - }, | ||
| 365 | - }, | ||
| 366 | - // Terracotta, a warm red-orange clay. | ||
| 367 | - Palette { | ||
| 368 | - id: "clay", | ||
| 369 | - light: Tokens { | ||
| 370 | - accent: "#AC5E46", | ||
| 371 | - accent_ink: "#93503C", | ||
| 372 | - accent_soft: "#F2E8E5", | ||
| 373 | - accent_text: "#FFFFFF", | ||
| 374 | - focus: "#93503C", | ||
| 375 | - public_bg: "#F2E8E5", | ||
| 376 | - public_text: "#93503C", | ||
| 377 | - note: "#93503C", | ||
| 378 | - hunk_bg: "#F6F2F1", | ||
| 379 | - hunk_text: "#8C4C39", | ||
| 380 | - }, | ||
| 381 | - dark: Tokens { | ||
| 382 | - accent: "#B96A53", | ||
| 383 | - accent_ink: "#C3806B", | ||
| 384 | - accent_soft: "#33231F", | ||
| 385 | - accent_text: "#16100E", | ||
| 386 | - focus: "#B96A53", | ||
| 387 | - public_bg: "#33231F", | ||
| 388 | - public_text: "#C3806B", | ||
| 389 | - note: "#C3806B", | ||
| 390 | - hunk_bg: "#251B18", | ||
| 391 | - hunk_text: "#C3806B", | ||
| 392 | - }, | ||
| 393 | - }, | ||
| 394 | - // Deep berry, richer than Rose. | ||
| 395 | - Palette { | ||
| 396 | - id: "berry", | ||
| 397 | - light: Tokens { | ||
| 398 | - accent: "#AC5787", | ||
| 399 | - accent_ink: "#944973", | ||
| 400 | - accent_soft: "#F1E7ED", | ||
| 401 | - accent_text: "#FFFFFF", | ||
| 402 | - focus: "#944973", | ||
| 403 | - public_bg: "#F1E7ED", | ||
| 404 | - public_text: "#944973", | ||
| 405 | - note: "#944973", | ||
| 406 | - hunk_bg: "#F6F1F4", | ||
| 407 | - hunk_text: "#8D466E", | ||
| 408 | - }, | ||
| 409 | - dark: Tokens { | ||
| 410 | - accent: "#B36692", | ||
| 411 | - accent_ink: "#BF7CA2", | ||
| 412 | - accent_soft: "#31202A", | ||
| 413 | - accent_text: "#150F12", | ||
| 414 | - focus: "#B36692", | ||
| 415 | - public_bg: "#31202A", | ||
| 416 | - public_text: "#BF7CA2", | ||
| 417 | - note: "#BF7CA2", | ||
| 418 | - hunk_bg: "#24191F", | ||
| 419 | - hunk_text: "#BF7CA2", | ||
| 420 | - }, | ||
| 421 | - }, | ||
| 422 | - // Forge-spark orange: hot metal, the most saturated accent on offer. | ||
| 423 | - Palette { | ||
| 424 | - id: "ember", | ||
| 425 | - light: Tokens { | ||
| 426 | - accent: "#C2410C", | ||
| 427 | - accent_ink: "#9A3412", | ||
| 428 | - accent_soft: "#FCEBE0", | ||
| 429 | - accent_text: "#FFFFFF", | ||
| 430 | - focus: "#9A3412", | ||
| 431 | - public_bg: "#FCEBE0", | ||
| 432 | - public_text: "#9A3412", | ||
| 433 | - note: "#9A3412", | ||
| 434 | - hunk_bg: "#FDF4EF", | ||
| 435 | - hunk_text: "#8F3110", | ||
| 436 | - }, | ||
| 437 | - dark: Tokens { | ||
| 438 | - accent: "#FB923C", | ||
| 439 | - accent_ink: "#FDBA74", | ||
| 440 | - accent_soft: "#3A2010", | ||
| 441 | - accent_text: "#1C0D04", | ||
| 442 | - focus: "#FB923C", | ||
| 443 | - public_bg: "#3A2010", | ||
| 444 | - public_text: "#FDBA74", | ||
| 445 | - note: "#FDBA74", | ||
| 446 | - hunk_bg: "#2A1A0F", | ||
| 447 | - hunk_text: "#FB923C", | ||
| 448 | - }, | ||
| 449 | - }, | ||
| 450 | - // Red, pure and saturated, a clear step past Rose and Berry. | ||
| 451 | - Palette { | ||
| 452 | - id: "crimson", | ||
| 453 | - light: Tokens { | ||
| 454 | - accent: "#B3263A", | ||
| 455 | - accent_ink: "#9E1C2E", | ||
| 456 | - accent_soft: "#F8E3E6", | ||
| 457 | - accent_text: "#FFFFFF", | ||
| 458 | - focus: "#9E1C2E", | ||
| 459 | - public_bg: "#F8E3E6", | ||
| 460 | - public_text: "#9E1C2E", | ||
| 461 | - note: "#9E1C2E", | ||
| 462 | - hunk_bg: "#FBF1F2", | ||
| 463 | - hunk_text: "#9E1C2E", | ||
| 464 | - }, | ||
| 465 | - dark: Tokens { | ||
| 466 | - accent: "#F0707F", | ||
| 467 | - accent_ink: "#FFA3AE", | ||
| 468 | - accent_soft: "#3A1419", | ||
| 469 | - accent_text: "#2A0A0E", | ||
| 470 | - focus: "#F0707F", | ||
| 471 | - public_bg: "#3A1419", | ||
| 472 | - public_text: "#FFA3AE", | ||
| 473 | - note: "#FFA3AE", | ||
| 474 | - hunk_bg: "#2A1417", | ||
| 475 | - hunk_text: "#F0707F", | ||
| 476 | - }, | ||
| 477 | - }, | ||
| 478 | - // Salmon-orange, brighter and lighter than Clay. | ||
| 479 | - Palette { | ||
| 480 | - id: "coral", | ||
| 481 | - light: Tokens { | ||
| 482 | - accent: "#C4493A", | ||
| 483 | - accent_ink: "#B0402F", | ||
| 484 | - accent_soft: "#FBE6E1", | ||
| 485 | - accent_text: "#FFFFFF", | ||
| 486 | - focus: "#B0402F", | ||
| 487 | - public_bg: "#FBE6E1", | ||
| 488 | - public_text: "#B0402F", | ||
| 489 | - note: "#B0402F", | ||
| 490 | - hunk_bg: "#FDF3F0", | ||
| 491 | - hunk_text: "#B0402F", | ||
| 492 | - }, | ||
| 493 | - dark: Tokens { | ||
| 494 | - accent: "#FF8A7A", | ||
| 495 | - accent_ink: "#FFADA0", | ||
| 496 | - accent_soft: "#3A1B15", | ||
| 497 | - accent_text: "#2A0C08", | ||
| 498 | - focus: "#FF8A7A", | ||
| 499 | - public_bg: "#3A1B15", | ||
| 500 | - public_text: "#FFADA0", | ||
| 501 | - note: "#FFADA0", | ||
| 502 | - hunk_bg: "#2C1511", | ||
| 503 | - hunk_text: "#FF8A7A", | ||
| 504 | - }, | ||
| 505 | - }, | ||
| 506 | - // Bright yellow, lighter and more lemon than Amber, so it takes dark text. | ||
| 507 | Palette { | 227 | Palette { |
| 508 | id: "gold", | 228 | id: "gold", |
| 509 | light: Tokens { | 229 | light: Tokens { |
| @@ -531,174 +251,6 @@ pub const PALETTES: &[Palette] = &[ | |||
| 531 | hunk_text: "#E8BC4A", | 251 | hunk_text: "#E8BC4A", |
| 532 | }, | 252 | }, |
| 533 | }, | 253 | }, |
| 534 | - // Yellow-green, a fresh step brighter than Moss. | ||
| 535 | - Palette { | ||
| 536 | - id: "lime", | ||
| 537 | - light: Tokens { | ||
| 538 | - accent: "#5C7A00", | ||
| 539 | - accent_ink: "#4F6A00", | ||
| 540 | - accent_soft: "#EEF5DC", | ||
| 541 | - accent_text: "#FFFFFF", | ||
| 542 | - focus: "#4F6A00", | ||
| 543 | - public_bg: "#EEF5DC", | ||
| 544 | - public_text: "#4F6A00", | ||
| 545 | - note: "#4F6A00", | ||
| 546 | - hunk_bg: "#F6FAEC", | ||
| 547 | - hunk_text: "#4F6A00", | ||
| 548 | - }, | ||
| 549 | - dark: Tokens { | ||
| 550 | - accent: "#A3D130", | ||
| 551 | - accent_ink: "#C2E664", | ||
| 552 | - accent_soft: "#263311", | ||
| 553 | - accent_text: "#141A03", | ||
| 554 | - focus: "#A3D130", | ||
| 555 | - public_bg: "#263311", | ||
| 556 | - public_text: "#C2E664", | ||
| 557 | - note: "#C2E664", | ||
| 558 | - hunk_bg: "#1C2510", | ||
| 559 | - hunk_text: "#A3D130", | ||
| 560 | - }, | ||
| 561 | - }, | ||
| 562 | - // Soft green-cyan, lighter and cooler than Sage. | ||
| 563 | - Palette { | ||
| 564 | - id: "mint", | ||
| 565 | - light: Tokens { | ||
| 566 | - accent: "#2E7D62", | ||
| 567 | - accent_ink: "#22664F", | ||
| 568 | - accent_soft: "#E0F4EC", | ||
| 569 | - accent_text: "#FFFFFF", | ||
| 570 | - focus: "#22664F", | ||
| 571 | - public_bg: "#E0F4EC", | ||
| 572 | - public_text: "#22664F", | ||
| 573 | - note: "#22664F", | ||
| 574 | - hunk_bg: "#EFF9F5", | ||
| 575 | - hunk_text: "#22664F", | ||
| 576 | - }, | ||
| 577 | - dark: Tokens { | ||
| 578 | - accent: "#6FD3AE", | ||
| 579 | - accent_ink: "#9BE6CA", | ||
| 580 | - accent_soft: "#14332A", | ||
| 581 | - accent_text: "#0A1F17", | ||
| 582 | - focus: "#6FD3AE", | ||
| 583 | - public_bg: "#14332A", | ||
| 584 | - public_text: "#9BE6CA", | ||
| 585 | - note: "#9BE6CA", | ||
| 586 | - hunk_bg: "#10251F", | ||
| 587 | - hunk_text: "#6FD3AE", | ||
| 588 | - }, | ||
| 589 | - }, | ||
| 590 | - // Bright blue-green, clearer than Teal. | ||
| 591 | - Palette { | ||
| 592 | - id: "cyan", | ||
| 593 | - light: Tokens { | ||
| 594 | - accent: "#00728A", | ||
| 595 | - accent_ink: "#00677D", | ||
| 596 | - accent_soft: "#DDF3F6", | ||
| 597 | - accent_text: "#FFFFFF", | ||
| 598 | - focus: "#00677D", | ||
| 599 | - public_bg: "#DDF3F6", | ||
| 600 | - public_text: "#00677D", | ||
| 601 | - note: "#00677D", | ||
| 602 | - hunk_bg: "#EEF9FB", | ||
| 603 | - hunk_text: "#00677D", | ||
| 604 | - }, | ||
| 605 | - dark: Tokens { | ||
| 606 | - accent: "#4DD0E1", | ||
| 607 | - accent_ink: "#8BE4F0", | ||
| 608 | - accent_soft: "#0E3036", | ||
| 609 | - accent_text: "#03181B", | ||
| 610 | - focus: "#4DD0E1", | ||
| 611 | - public_bg: "#0E3036", | ||
| 612 | - public_text: "#8BE4F0", | ||
| 613 | - note: "#8BE4F0", | ||
| 614 | - hunk_bg: "#0B2327", | ||
| 615 | - hunk_text: "#4DD0E1", | ||
| 616 | - }, | ||
| 617 | - }, | ||
| 618 | - // Clear sky blue, brighter than Ocean. | ||
| 619 | - Palette { | ||
| 620 | - id: "sky", | ||
| 621 | - light: Tokens { | ||
| 622 | - accent: "#1A6FB0", | ||
| 623 | - accent_ink: "#1A64A0", | ||
| 624 | - accent_soft: "#E1EFFA", | ||
| 625 | - accent_text: "#FFFFFF", | ||
| 626 | - focus: "#1A64A0", | ||
| 627 | - public_bg: "#E1EFFA", | ||
| 628 | - public_text: "#1A64A0", | ||
| 629 | - note: "#1A64A0", | ||
| 630 | - hunk_bg: "#EFF6FC", | ||
| 631 | - hunk_text: "#1A64A0", | ||
| 632 | - }, | ||
| 633 | - dark: Tokens { | ||
| 634 | - accent: "#7CC4F0", | ||
| 635 | - accent_ink: "#A6D8F7", | ||
| 636 | - accent_soft: "#13293A", | ||
| 637 | - accent_text: "#061826", | ||
| 638 | - focus: "#7CC4F0", | ||
| 639 | - public_bg: "#13293A", | ||
| 640 | - public_text: "#A6D8F7", | ||
| 641 | - note: "#A6D8F7", | ||
| 642 | - hunk_bg: "#0F202D", | ||
| 643 | - hunk_text: "#7CC4F0", | ||
| 644 | - }, | ||
| 645 | - }, | ||
| 646 | - // Vivid blue-purple, more saturated than Indigo. | ||
| 647 | - Palette { | ||
| 648 | - id: "violet", | ||
| 649 | - light: Tokens { | ||
| 650 | - accent: "#7C3AED", | ||
| 651 | - accent_ink: "#6D34C9", | ||
| 652 | - accent_soft: "#EEE7FC", | ||
| 653 | - accent_text: "#FFFFFF", | ||
| 654 | - focus: "#6D34C9", | ||
| 655 | - public_bg: "#EEE7FC", | ||
| 656 | - public_text: "#6D34C9", | ||
| 657 | - note: "#6D34C9", | ||
| 658 | - hunk_bg: "#F6F2FD", | ||
| 659 | - hunk_text: "#6D34C9", | ||
| 660 | - }, | ||
| 661 | - dark: Tokens { | ||
| 662 | - accent: "#B794F6", | ||
| 663 | - accent_ink: "#CDB5FA", | ||
| 664 | - accent_soft: "#2A1F45", | ||
| 665 | - accent_text: "#15092E", | ||
| 666 | - focus: "#B794F6", | ||
| 667 | - public_bg: "#2A1F45", | ||
| 668 | - public_text: "#CDB5FA", | ||
| 669 | - note: "#CDB5FA", | ||
| 670 | - hunk_bg: "#201832", | ||
| 671 | - hunk_text: "#B794F6", | ||
| 672 | - }, | ||
| 673 | - }, | ||
| 674 | - // Hot magenta-pink, the brightest purple-pink on offer. | ||
| 675 | - Palette { | ||
| 676 | - id: "fuchsia", | ||
| 677 | - light: Tokens { | ||
| 678 | - accent: "#A21CAF", | ||
| 679 | - accent_ink: "#8F1A9A", | ||
| 680 | - accent_soft: "#F8E3F5", | ||
| 681 | - accent_text: "#FFFFFF", | ||
| 682 | - focus: "#8F1A9A", | ||
| 683 | - public_bg: "#F8E3F5", | ||
| 684 | - public_text: "#8F1A9A", | ||
| 685 | - note: "#8F1A9A", | ||
| 686 | - hunk_bg: "#FBF1FA", | ||
| 687 | - hunk_text: "#8F1A9A", | ||
| 688 | - }, | ||
| 689 | - dark: Tokens { | ||
| 690 | - accent: "#E879F9", | ||
| 691 | - accent_ink: "#F2A6FB", | ||
| 692 | - accent_soft: "#3A1638", | ||
| 693 | - accent_text: "#2A0530", | ||
| 694 | - focus: "#E879F9", | ||
| 695 | - public_bg: "#3A1638", | ||
| 696 | - public_text: "#F2A6FB", | ||
| 697 | - note: "#F2A6FB", | ||
| 698 | - hunk_bg: "#2C1229", | ||
| 699 | - hunk_text: "#E879F9", | ||
| 700 | - }, | ||
| 701 | - }, | ||
| 702 | ]; | 254 | ]; |
| 703 | 255 | ||
| 704 | /// The neutral colour tokens one base sets in one theme. The values are CSS colours; | 256 | /// The neutral colour tokens one base sets in one theme. The values are CSS colours; |
| @@ -823,199 +375,71 @@ pub const BASES: &[Base] = &[ | |||
| 823 | ln_text: "#97A198", | 375 | ln_text: "#97A198", |
| 824 | }, | 376 | }, |
| 825 | }, | 377 | }, |
| 826 | - // Stone: pure neutral grey. | 378 | + // Spark: warm neutrals tinted toward the Forge-spark orange, hue about 45 degrees. |
| 827 | Base { | 379 | Base { |
| 828 | - id: "stone", | 380 | + id: "spark", |
| 829 | light: BaseTokens { | 381 | light: BaseTokens { |
| 830 | - bg: "#F5F5F4", | 382 | + bg: "#FDF3EF", |
| 831 | surface: "#FFFFFF", | 383 | surface: "#FFFFFF", |
| 832 | - surface_2: "#EDEDEB", | 384 | + surface_2: "#F4EAE6", |
| 833 | - text: "#1C1C1B", | 385 | + text: "#221B18", |
| 834 | - text_2: "#3D3D3B", | 386 | + text_2: "#3B3430", |
| 835 | - muted: "#6B6B68", | 387 | + muted: "#6F6763", |
| 836 | - border: "#DEDEDB", | 388 | + border: "#E2D8D4", |
| 837 | - border_strong: "#C6C6C2", | 389 | + border_strong: "#CBC2BE", |
| 838 | - code_bg: "#EDEDEB", | 390 | + code_bg: "#F4EAE6", |
| 839 | - private_bg: "#EDEDEB", | 391 | + private_bg: "#F4EAE6", |
| 840 | - private_text: "#3D3D3B", | 392 | + private_text: "#3B3430", |
| 841 | - ln_text: "#6B6B68", | 393 | + ln_text: "#69615E", |
| 842 | - }, | ||
| 843 | - dark: BaseTokens { | ||
| 844 | - bg: "#131313", | ||
| 845 | - surface: "#1A1A1A", | ||
| 846 | - surface_2: "#212121", | ||
| 847 | - text: "#E6E6E4", | ||
| 848 | - text_2: "#C7C7C4", | ||
| 849 | - muted: "#9A9A96", | ||
| 850 | - border: "#2C2C2B", | ||
| 851 | - border_strong: "#3C3C3A", | ||
| 852 | - code_bg: "#212121", | ||
| 853 | - private_bg: "#212121", | ||
| 854 | - private_text: "#C7C7C4", | ||
| 855 | - ln_text: "#9A9A96", | ||
| 856 | - }, | ||
| 857 | - }, | ||
| 858 | - // Sand: warm paper and warm ink. | ||
| 859 | - Base { | ||
| 860 | - id: "sand", | ||
| 861 | - light: BaseTokens { | ||
| 862 | - bg: "#F8F5EF", | ||
| 863 | - surface: "#FFFDF9", | ||
| 864 | - surface_2: "#F0EBE1", | ||
| 865 | - text: "#2A2620", | ||
| 866 | - text_2: "#4A443B", | ||
| 867 | - muted: "#716A5E", | ||
| 868 | - border: "#E2DBCF", | ||
| 869 | - border_strong: "#CBC2B3", | ||
| 870 | - code_bg: "#F0EBE1", | ||
| 871 | - private_bg: "#F0EBE1", | ||
| 872 | - private_text: "#4A443B", | ||
| 873 | - ln_text: "#6B6457", | ||
| 874 | }, | 394 | }, |
| 875 | dark: BaseTokens { | 395 | dark: BaseTokens { |
| 876 | - bg: "#171511", | 396 | + bg: "#19120F", |
| 877 | - surface: "#1E1B16", | 397 | + surface: "#211A17", |
| 878 | - surface_2: "#26221C", | 398 | + surface_2: "#29221F", |
| 879 | - text: "#E9E4DA", | 399 | + text: "#EFE6E1", |
| 880 | - text_2: "#CBC5B9", | 400 | + text_2: "#CBC2BE", |
| 881 | - muted: "#A29B8D", | 401 | + muted: "#A59C98", |
| 882 | - border: "#342F27", | 402 | + border: "#332C29", |
| 883 | - border_strong: "#463F35", | 403 | + border_strong: "#48403D", |
| 884 | - code_bg: "#26221C", | 404 | + code_bg: "#29221F", |
| 885 | - private_bg: "#26221C", | 405 | + private_bg: "#29221F", |
| 886 | - private_text: "#CBC5B9", | 406 | + private_text: "#CBC2BE", |
| 887 | - ln_text: "#A29B8D", | 407 | + ln_text: "#A59C98", |
| 888 | - }, | 408 | + }, |
| 889 | - }, | 409 | + }, |
| 890 | - // Mist: cool blue-grey. | 410 | + // Graphite: a cool neutral grey, flatter than the warmer neutrals. |
| 891 | Base { | 411 | Base { |
| 892 | - id: "mist", | 412 | + id: "graphite", |
| 893 | - light: BaseTokens { | ||
| 894 | - bg: "#F3F6F9", | ||
| 895 | - surface: "#FFFFFF", | ||
| 896 | - surface_2: "#E9EEF3", | ||
| 897 | - text: "#1B2430", | ||
| 898 | - text_2: "#384352", | ||
| 899 | - muted: "#66717F", | ||
| 900 | - border: "#D9E0E8", | ||
| 901 | - border_strong: "#C2CCD8", | ||
| 902 | - code_bg: "#E9EEF3", | ||
| 903 | - private_bg: "#E9EEF3", | ||
| 904 | - private_text: "#384352", | ||
| 905 | - ln_text: "#5E6977", | ||
| 906 | - }, | ||
| 907 | - dark: BaseTokens { | ||
| 908 | - bg: "#11161C", | ||
| 909 | - surface: "#182029", | ||
| 910 | - surface_2: "#1E2834", | ||
| 911 | - text: "#E2E8EF", | ||
| 912 | - text_2: "#C3CCD7", | ||
| 913 | - muted: "#949FAD", | ||
| 914 | - border: "#28323E", | ||
| 915 | - border_strong: "#37424F", | ||
| 916 | - code_bg: "#1E2834", | ||
| 917 | - private_bg: "#1E2834", | ||
| 918 | - private_text: "#C3CCD7", | ||
| 919 | - ln_text: "#949FAD", | ||
| 920 | - }, | ||
| 921 | - }, | ||
| 922 | - // Ink: crisp white in light, near-black in dark. | ||
| 923 | - Base { | ||
| 924 | - id: "ink", | ||
| 925 | - light: BaseTokens { | ||
| 926 | - bg: "#FCFCFB", | ||
| 927 | - surface: "#FFFFFF", | ||
| 928 | - surface_2: "#F2F2F0", | ||
| 929 | - text: "#111111", | ||
| 930 | - text_2: "#333333", | ||
| 931 | - muted: "#5F5F5C", | ||
| 932 | - border: "#E3E3E0", | ||
| 933 | - border_strong: "#C9C9C5", | ||
| 934 | - code_bg: "#F2F2F0", | ||
| 935 | - private_bg: "#F2F2F0", | ||
| 936 | - private_text: "#333333", | ||
| 937 | - ln_text: "#5F5F5C", | ||
| 938 | - }, | ||
| 939 | - dark: BaseTokens { | ||
| 940 | - bg: "#000000", | ||
| 941 | - surface: "#0B0B0B", | ||
| 942 | - surface_2: "#141414", | ||
| 943 | - text: "#F2F2F0", | ||
| 944 | - text_2: "#CFCFCC", | ||
| 945 | - muted: "#9C9C98", | ||
| 946 | - border: "#242424", | ||
| 947 | - border_strong: "#353535", | ||
| 948 | - code_bg: "#141414", | ||
| 949 | - private_bg: "#141414", | ||
| 950 | - private_text: "#CFCFCC", | ||
| 951 | - ln_text: "#9C9C98", | ||
| 952 | - }, | ||
| 953 | - }, | ||
| 954 | - // Dune: warm beige, a step warmer and browner than Sand. | ||
| 955 | - Base { | ||
| 956 | - id: "dune", | ||
| 957 | - light: BaseTokens { | ||
| 958 | - bg: "#F4EBDC", | ||
| 959 | - surface: "#FCF8F1", | ||
| 960 | - surface_2: "#EDE3D1", | ||
| 961 | - text: "#2B2318", | ||
| 962 | - text_2: "#473F31", | ||
| 963 | - muted: "#6F6550", | ||
| 964 | - border: "#E0D5C1", | ||
| 965 | - border_strong: "#C9BBA2", | ||
| 966 | - code_bg: "#EDE3D1", | ||
| 967 | - private_bg: "#EDE3D1", | ||
| 968 | - private_text: "#473F31", | ||
| 969 | - ln_text: "#6A5F4C", | ||
| 970 | - }, | ||
| 971 | - dark: BaseTokens { | ||
| 972 | - bg: "#17120B", | ||
| 973 | - surface: "#1F1912", | ||
| 974 | - surface_2: "#28211A", | ||
| 975 | - text: "#EEE6D8", | ||
| 976 | - text_2: "#D0C7B6", | ||
| 977 | - muted: "#A39A88", | ||
| 978 | - border: "#362E24", | ||
| 979 | - border_strong: "#483E31", | ||
| 980 | - code_bg: "#28211A", | ||
| 981 | - private_bg: "#28211A", | ||
| 982 | - private_text: "#D0C7B6", | ||
| 983 | - ln_text: "#A39A88", | ||
| 984 | - }, | ||
| 985 | - }, | ||
| 986 | - // Lilac: a soft cool violet tint. | ||
| 987 | - Base { | ||
| 988 | - id: "lilac", | ||
| 989 | light: BaseTokens { | 413 | light: BaseTokens { |
| 990 | - bg: "#F5F3FA", | 414 | + bg: "#E9EAEC", |
| 991 | - surface: "#FFFFFF", | 415 | + surface: "#F9FAFB", |
| 992 | - surface_2: "#ECE9F5", | 416 | + surface_2: "#DCDEE2", |
| 993 | - text: "#1F1B2C", | 417 | + text: "#17191C", |
| 994 | - text_2: "#3B3650", | 418 | + text_2: "#33373D", |
| 995 | - muted: "#686180", | 419 | + muted: "#5C626B", |
| 996 | - border: "#DCD7EA", | 420 | + border: "#CFD3D9", |
| 997 | - border_strong: "#C3BCD9", | 421 | + border_strong: "#B5BBC3", |
| 998 | - code_bg: "#ECE9F5", | 422 | + code_bg: "#DCDEE2", |
| 999 | - private_bg: "#ECE9F5", | 423 | + private_bg: "#DCDEE2", |
| 1000 | - private_text: "#3B3650", | 424 | + private_text: "#33373D", |
| 1001 | - ln_text: "#625B77", | 425 | + ln_text: "#545A63", |
| 1002 | }, | 426 | }, |
| 1003 | dark: BaseTokens { | 427 | dark: BaseTokens { |
| 1004 | - bg: "#12101A", | 428 | + bg: "#1A1B1E", |
| 1005 | - surface: "#1A1725", | 429 | + surface: "#222428", |
| 1006 | - surface_2: "#221E2E", | 430 | + surface_2: "#2B2D32", |
| 1007 | - text: "#E7E4F0", | 431 | + text: "#E6E8EB", |
| 1008 | - text_2: "#C9C4D8", | 432 | + text_2: "#C8CCD2", |
| 1009 | - muted: "#9E97B0", | 433 | + muted: "#9499A2", |
| 1010 | - border: "#2C2739", | 434 | + border: "#33363C", |
| 1011 | - border_strong: "#3C3650", | 435 | + border_strong: "#44484F", |
| 1012 | - code_bg: "#221E2E", | 436 | + code_bg: "#2B2D32", |
| 1013 | - private_bg: "#221E2E", | 437 | + private_bg: "#2B2D32", |
| 1014 | - private_text: "#C9C4D8", | 438 | + private_text: "#C8CCD2", |
| 1015 | - ln_text: "#9E97B0", | 439 | + ln_text: "#9499A2", |
| 1016 | }, | 440 | }, |
| 1017 | }, | 441 | }, |
| 1018 | - // Dusk: cool blue-grey, deeper and bluer than Mist. | 442 | + // Dusk: cool blue-grey, a deeper blue-tinted neutral. |
| 1019 | Base { | 443 | Base { |
| 1020 | id: "dusk", | 444 | id: "dusk", |
| 1021 | light: BaseTokens { | 445 | light: BaseTokens { |
| @@ -1047,100 +471,36 @@ pub const BASES: &[Base] = &[ | |||
| 1047 | ln_text: "#8F9BB0", | 471 | ln_text: "#8F9BB0", |
| 1048 | }, | 472 | }, |
| 1049 | }, | 473 | }, |
| 1050 | - // Blush: a soft warm pink tint, the only pink page on offer. | 474 | + // Ink: crisp white in light, near-black in dark. |
| 1051 | - Base { | ||
| 1052 | - id: "blush", | ||
| 1053 | - light: BaseTokens { | ||
| 1054 | - bg: "#FAF1F3", | ||
| 1055 | - surface: "#FFFFFF", | ||
| 1056 | - surface_2: "#F2E4E8", | ||
| 1057 | - text: "#2D1A20", | ||
| 1058 | - text_2: "#4A2F38", | ||
| 1059 | - muted: "#76606A", | ||
| 1060 | - border: "#E6D5DA", | ||
| 1061 | - border_strong: "#CFBAC1", | ||
| 1062 | - code_bg: "#F2E4E8", | ||
| 1063 | - private_bg: "#F2E4E8", | ||
| 1064 | - private_text: "#4A2F38", | ||
| 1065 | - ln_text: "#6C5660", | ||
| 1066 | - }, | ||
| 1067 | - dark: BaseTokens { | ||
| 1068 | - bg: "#150F12", | ||
| 1069 | - surface: "#1D1519", | ||
| 1070 | - surface_2: "#261C21", | ||
| 1071 | - text: "#F0E4E8", | ||
| 1072 | - text_2: "#D3C3C9", | ||
| 1073 | - muted: "#A3929A", | ||
| 1074 | - border: "#35282E", | ||
| 1075 | - border_strong: "#473840", | ||
| 1076 | - code_bg: "#261C21", | ||
| 1077 | - private_bg: "#261C21", | ||
| 1078 | - private_text: "#D3C3C9", | ||
| 1079 | - ln_text: "#A3929A", | ||
| 1080 | - }, | ||
| 1081 | - }, | ||
| 1082 | - // Graphite: a cool neutral grey, darker and flatter than Stone. | ||
| 1083 | - Base { | ||
| 1084 | - id: "graphite", | ||
| 1085 | - light: BaseTokens { | ||
| 1086 | - bg: "#E9EAEC", | ||
| 1087 | - surface: "#F9FAFB", | ||
| 1088 | - surface_2: "#DCDEE2", | ||
| 1089 | - text: "#17191C", | ||
| 1090 | - text_2: "#33373D", | ||
| 1091 | - muted: "#5C626B", | ||
| 1092 | - border: "#CFD3D9", | ||
| 1093 | - border_strong: "#B5BBC3", | ||
| 1094 | - code_bg: "#DCDEE2", | ||
| 1095 | - private_bg: "#DCDEE2", | ||
| 1096 | - private_text: "#33373D", | ||
| 1097 | - ln_text: "#545A63", | ||
| 1098 | - }, | ||
| 1099 | - dark: BaseTokens { | ||
| 1100 | - bg: "#1A1B1E", | ||
| 1101 | - surface: "#222428", | ||
| 1102 | - surface_2: "#2B2D32", | ||
| 1103 | - text: "#E6E8EB", | ||
| 1104 | - text_2: "#C8CCD2", | ||
| 1105 | - muted: "#9499A2", | ||
| 1106 | - border: "#33363C", | ||
| 1107 | - border_strong: "#44484F", | ||
| 1108 | - code_bg: "#2B2D32", | ||
| 1109 | - private_bg: "#2B2D32", | ||
| 1110 | - private_text: "#C8CCD2", | ||
| 1111 | - ln_text: "#9499A2", | ||
| 1112 | - }, | ||
| 1113 | - }, | ||
| 1114 | - // Pine: a teal-green tint, clearly bluer than Fern. | ||
| 1115 | Base { | 475 | Base { |
| 1116 | - id: "pine", | 476 | + id: "ink", |
| 1117 | light: BaseTokens { | 477 | light: BaseTokens { |
| 1118 | - bg: "#E8F3F0", | 478 | + bg: "#FCFCFB", |
| 1119 | surface: "#FFFFFF", | 479 | surface: "#FFFFFF", |
| 1120 | - surface_2: "#DAEAE5", | 480 | + surface_2: "#F2F2F0", |
| 1121 | - text: "#13211E", | 481 | + text: "#111111", |
| 1122 | - text_2: "#2E403C", | 482 | + text_2: "#333333", |
| 1123 | - muted: "#5A6E69", | 483 | + muted: "#5F5F5C", |
| 1124 | - border: "#CCE0DA", | 484 | + border: "#E3E3E0", |
| 1125 | - border_strong: "#B3CCC4", | 485 | + border_strong: "#C9C9C5", |
| 1126 | - code_bg: "#DAEAE5", | 486 | + code_bg: "#F2F2F0", |
| 1127 | - private_bg: "#DAEAE5", | 487 | + private_bg: "#F2F2F0", |
| 1128 | - private_text: "#2E403C", | 488 | + private_text: "#333333", |
| 1129 | - ln_text: "#52675F", | 489 | + ln_text: "#5F5F5C", |
| 1130 | }, | 490 | }, |
| 1131 | dark: BaseTokens { | 491 | dark: BaseTokens { |
| 1132 | - bg: "#0A1614", | 492 | + bg: "#000000", |
| 1133 | - surface: "#11211E", | 493 | + surface: "#0B0B0B", |
| 1134 | - surface_2: "#182C28", | 494 | + surface_2: "#141414", |
| 1135 | - text: "#DDEEE9", | 495 | + text: "#F2F2F0", |
| 1136 | - text_2: "#BAD2CB", | 496 | + text_2: "#CFCFCC", |
| 1137 | - muted: "#8AA59E", | 497 | + muted: "#9C9C98", |
| 1138 | - border: "#213A34", | 498 | + border: "#242424", |
| 1139 | - border_strong: "#2F4C45", | 499 | + border_strong: "#353535", |
| 1140 | - code_bg: "#182C28", | 500 | + code_bg: "#141414", |
| 1141 | - private_bg: "#182C28", | 501 | + private_bg: "#141414", |
| 1142 | - private_text: "#BAD2CB", | 502 | + private_text: "#CFCFCC", |
| 1143 | - ln_text: "#8AA59E", | 503 | + ln_text: "#9C9C98", |
| 1144 | }, | 504 | }, |
| 1145 | }, | 505 | }, |
| 1146 | ]; | 506 | ]; |
crates/forge-web/src/custom_colour.rsadded+405 -0
| @@ -0,0 +1,405 @@ | |||
| 1 | +//! Colours for any hue. A stored `hue-N` id (see `accent::hue_of`) is not a row of | ||
| 2 | +//! `accent_palette.rs`: its colours are built here from the OKLCH hue N, in the same roles a preset | ||
| 3 | +//! has. The accent sits at one lightness and chroma, with black or white text by contrast. The | ||
| 4 | +//! background is a neutral with a little chroma toward the hue. `stylesheet` writes the rules that | ||
| 5 | +//! apply them, in the shape `build.rs` writes for the presets. | ||
| 6 | + | ||
| 7 | +/// The colours of one accent in one theme: the fields of `accent_palette::Tokens`, owned, because a | ||
| 8 | +/// hue is built at run time. | ||
| 9 | +#[derive(Debug, Clone)] | ||
| 10 | +pub struct OwnedTokens { | ||
| 11 | + pub accent: String, | ||
| 12 | + pub accent_ink: String, | ||
| 13 | + pub accent_soft: String, | ||
| 14 | + pub accent_text: String, | ||
| 15 | + pub focus: String, | ||
| 16 | + pub public_bg: String, | ||
| 17 | + pub public_text: String, | ||
| 18 | + pub note: String, | ||
| 19 | + pub hunk_bg: String, | ||
| 20 | + pub hunk_text: String, | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +impl OwnedTokens { | ||
| 24 | + /// The `(property, value)` pairs, in the order of `accent_palette::TOKEN_VARS`. | ||
| 25 | + pub fn decls(&self) -> Vec<(&'static str, &str)> { | ||
| 26 | + vec![ | ||
| 27 | + ("--accent", self.accent.as_str()), | ||
| 28 | + ("--accent-ink", self.accent_ink.as_str()), | ||
| 29 | + ("--accent-soft", self.accent_soft.as_str()), | ||
| 30 | + ("--accent-text", self.accent_text.as_str()), | ||
| 31 | + ("--focus", self.focus.as_str()), | ||
| 32 | + ("--public-bg", self.public_bg.as_str()), | ||
| 33 | + ("--public-text", self.public_text.as_str()), | ||
| 34 | + ("--note", self.note.as_str()), | ||
| 35 | + ("--hunk-bg", self.hunk_bg.as_str()), | ||
| 36 | + ("--hunk-text", self.hunk_text.as_str()), | ||
| 37 | + ] | ||
| 38 | + } | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +/// The neutral colours of one base in one theme: the fields of `accent_palette::BaseTokens`, owned. | ||
| 42 | +#[derive(Debug, Clone)] | ||
| 43 | +pub struct OwnedBaseTokens { | ||
| 44 | + pub bg: String, | ||
| 45 | + pub surface: String, | ||
| 46 | + pub surface_2: String, | ||
| 47 | + pub text: String, | ||
| 48 | + pub text_2: String, | ||
| 49 | + pub muted: String, | ||
| 50 | + pub border: String, | ||
| 51 | + pub border_strong: String, | ||
| 52 | + pub code_bg: String, | ||
| 53 | + pub private_bg: String, | ||
| 54 | + pub private_text: String, | ||
| 55 | + pub ln_text: String, | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +impl OwnedBaseTokens { | ||
| 59 | + /// The `(property, value)` pairs, in the order of `accent_palette::BASE_TOKEN_VARS`. | ||
| 60 | + pub fn decls(&self) -> Vec<(&'static str, &str)> { | ||
| 61 | + vec![ | ||
| 62 | + ("--bg", self.bg.as_str()), | ||
| 63 | + ("--surface", self.surface.as_str()), | ||
| 64 | + ("--surface-2", self.surface_2.as_str()), | ||
| 65 | + ("--text", self.text.as_str()), | ||
| 66 | + ("--text-2", self.text_2.as_str()), | ||
| 67 | + ("--muted", self.muted.as_str()), | ||
| 68 | + ("--border", self.border.as_str()), | ||
| 69 | + ("--border-strong", self.border_strong.as_str()), | ||
| 70 | + ("--code-bg", self.code_bg.as_str()), | ||
| 71 | + ("--private-bg", self.private_bg.as_str()), | ||
| 72 | + ("--private-text", self.private_text.as_str()), | ||
| 73 | + ("--ln-text", self.ln_text.as_str()), | ||
| 74 | + ] | ||
| 75 | + } | ||
| 76 | +} | ||
| 77 | + | ||
| 78 | +/// Chroma of the neutrals: small, like the bases on offer. | ||
| 79 | +const NEUTRAL_CHROMA: f64 = 0.012; | ||
| 80 | + | ||
| 81 | +/// Slack for float error when testing whether a colour is inside sRGB. | ||
| 82 | +const GAMUT_EPS: f64 = 1e-6; | ||
| 83 | + | ||
| 84 | +/// The accent colours for a hue, in one theme. Light: a mid accent with its ink darker than it. | ||
| 85 | +/// Dark: a light accent with its ink lighter than it, on a dark soft tint. | ||
| 86 | +pub fn accent_tokens(hue: u16, dark: bool) -> OwnedTokens { | ||
| 87 | + let h = f64::from(hue); | ||
| 88 | + let (accent, ink, soft, hunk_bg) = if dark { | ||
| 89 | + ( | ||
| 90 | + colour(0.75, 0.11, h), | ||
| 91 | + colour(0.84, 0.09, h), | ||
| 92 | + colour(0.27, 0.04, h), | ||
| 93 | + colour(0.22, 0.03, h), | ||
| 94 | + ) | ||
| 95 | + } else { | ||
| 96 | + ( | ||
| 97 | + colour(0.52, 0.12, h), | ||
| 98 | + colour(0.46, 0.12, h), | ||
| 99 | + colour(0.95, 0.025, h), | ||
| 100 | + colour(0.975, 0.012, h), | ||
| 101 | + ) | ||
| 102 | + }; | ||
| 103 | + OwnedTokens { | ||
| 104 | + accent_text: text_on(&accent), | ||
| 105 | + focus: if dark { accent.clone() } else { ink.clone() }, | ||
| 106 | + hunk_text: if dark { | ||
| 107 | + accent.clone() | ||
| 108 | + } else { | ||
| 109 | + colour(0.44, 0.10, h) | ||
| 110 | + }, | ||
| 111 | + public_bg: soft.clone(), | ||
| 112 | + public_text: ink.clone(), | ||
| 113 | + note: ink.clone(), | ||
| 114 | + accent_ink: ink, | ||
| 115 | + accent_soft: soft, | ||
| 116 | + hunk_bg, | ||
| 117 | + accent, | ||
| 118 | + } | ||
| 119 | +} | ||
| 120 | + | ||
| 121 | +/// The neutral colours for a hue, in one theme. Each is a tint of the hue at `NEUTRAL_CHROMA`, at | ||
| 122 | +/// the lightness the presets use for that role. | ||
| 123 | +pub fn base_tokens(hue: u16, dark: bool) -> OwnedBaseTokens { | ||
| 124 | + let h = f64::from(hue); | ||
| 125 | + let n = |l: f64| colour(l, NEUTRAL_CHROMA, h); | ||
| 126 | + if dark { | ||
| 127 | + let surface_2 = n(0.26); | ||
| 128 | + let text_2 = n(0.82); | ||
| 129 | + OwnedBaseTokens { | ||
| 130 | + bg: n(0.19), | ||
| 131 | + surface: n(0.225), | ||
| 132 | + text: n(0.93), | ||
| 133 | + muted: n(0.70), | ||
| 134 | + border: n(0.30), | ||
| 135 | + border_strong: n(0.38), | ||
| 136 | + code_bg: surface_2.clone(), | ||
| 137 | + private_bg: surface_2.clone(), | ||
| 138 | + surface_2, | ||
| 139 | + private_text: text_2.clone(), | ||
| 140 | + text_2, | ||
| 141 | + ln_text: n(0.70), | ||
| 142 | + } | ||
| 143 | + } else { | ||
| 144 | + let surface_2 = n(0.945); | ||
| 145 | + let text_2 = n(0.33); | ||
| 146 | + OwnedBaseTokens { | ||
| 147 | + bg: n(0.972), | ||
| 148 | + surface: "#FFFFFF".to_owned(), | ||
| 149 | + text: n(0.23), | ||
| 150 | + muted: n(0.52), | ||
| 151 | + border: n(0.89), | ||
| 152 | + border_strong: n(0.82), | ||
| 153 | + code_bg: surface_2.clone(), | ||
| 154 | + private_bg: surface_2.clone(), | ||
| 155 | + surface_2, | ||
| 156 | + private_text: text_2.clone(), | ||
| 157 | + text_2, | ||
| 158 | + ln_text: n(0.50), | ||
| 159 | + } | ||
| 160 | + } | ||
| 161 | +} | ||
| 162 | + | ||
| 163 | +/// The `#RRGGBB` of an OKLCH colour (lightness 0..1, chroma, hue in degrees). Chroma is cut back | ||
| 164 | +/// until the colour fits sRGB, so the lightness and the hue hold. | ||
| 165 | +pub fn colour(lightness: f64, chroma: f64, hue: f64) -> String { | ||
| 166 | + let c = fit_chroma(lightness, chroma, hue); | ||
| 167 | + let [r, g, b] = oklch_to_linear(lightness, c, hue) | ||
| 168 | + .map(|v| (encode(v.clamp(0.0, 1.0)) * 255.0).round() as u8); | ||
| 169 | + format!("#{r:02X}{g:02X}{b:02X}") | ||
| 170 | +} | ||
| 171 | + | ||
| 172 | +/// The OKLCH hue of a `#RRGGBB` colour, rounded to a whole degree in `0..360`. | ||
| 173 | +#[allow(dead_code)] // Used by the preset hues, which the settings picker reads. | ||
| 174 | +pub fn hex_hue(hex: &str) -> u16 { | ||
| 175 | + let (_, _, hue) = linear_to_oklch(hex_linear(hex)); | ||
| 176 | + (hue.round() as u16) % 360 | ||
| 177 | +} | ||
| 178 | + | ||
| 179 | +/// The WCAG contrast ratio between two `#RRGGBB` colours. | ||
| 180 | +pub fn contrast_ratio(a: &str, b: &str) -> f64 { | ||
| 181 | + let (x, y) = (relative_luminance(a), relative_luminance(b)); | ||
| 182 | + (x.max(y) + 0.05) / (x.min(y) + 0.05) | ||
| 183 | +} | ||
| 184 | + | ||
| 185 | +/// The rules for the custom ids of one stylesheet: each argument is the hue of an accent or base | ||
| 186 | +/// id (`None` for a preset, which `build.rs` already styles). They mirror `build.rs`: the light | ||
| 187 | +/// tokens go on the light attribute, the dark tokens on the dark attribute in both dark states. | ||
| 188 | +pub fn stylesheet( | ||
| 189 | + accent_light: Option<u16>, | ||
| 190 | + accent_dark: Option<u16>, | ||
| 191 | + base_light: Option<u16>, | ||
| 192 | + base_dark: Option<u16>, | ||
| 193 | +) -> String { | ||
| 194 | + let mut css = String::new(); | ||
| 195 | + if let Some(hue) = accent_light { | ||
| 196 | + let selector = format!(":root[data-accent-light=\"hue-{hue}\"]"); | ||
| 197 | + rule(&mut css, "", &selector, &accent_tokens(hue, false).decls()); | ||
| 198 | + } | ||
| 199 | + if let Some(hue) = accent_dark { | ||
| 200 | + let selector = format!(":root[data-accent-dark=\"hue-{hue}\"]"); | ||
| 201 | + dark_rules(&mut css, &selector, &accent_tokens(hue, true).decls()); | ||
| 202 | + } | ||
| 203 | + if let Some(hue) = base_light { | ||
| 204 | + let selector = format!(":root[data-base-light=\"hue-{hue}\"]"); | ||
| 205 | + rule(&mut css, "", &selector, &base_tokens(hue, false).decls()); | ||
| 206 | + } | ||
| 207 | + if let Some(hue) = base_dark { | ||
| 208 | + let selector = format!(":root[data-base-dark=\"hue-{hue}\"]"); | ||
| 209 | + dark_rules(&mut css, &selector, &base_tokens(hue, true).decls()); | ||
| 210 | + } | ||
| 211 | + css | ||
| 212 | +} | ||
| 213 | + | ||
| 214 | +/// Appends `selector { … }` with one `--token: value;` line per declaration. `indent` is 0 or 2. | ||
| 215 | +fn rule(css: &mut String, indent: &str, selector: &str, decls: &[(&str, &str)]) { | ||
| 216 | + css.push_str(&format!("{indent}{selector} {{\n")); | ||
| 217 | + for (name, value) in decls { | ||
| 218 | + css.push_str(&format!("{indent} {name}: {value};\n")); | ||
| 219 | + } | ||
| 220 | + css.push_str(&format!("{indent}}}\n")); | ||
| 221 | +} | ||
| 222 | + | ||
| 223 | +/// The dark rules for one choice: by the OS, and by `data-theme`. The `:not` and the second | ||
| 224 | +/// attribute add specificity, so they win over the light rule whatever the light choice is. | ||
| 225 | +fn dark_rules(css: &mut String, selector: &str, decls: &[(&str, &str)]) { | ||
| 226 | + css.push_str("@media (prefers-color-scheme: dark) {\n"); | ||
| 227 | + rule( | ||
| 228 | + css, | ||
| 229 | + " ", | ||
| 230 | + &format!("{selector}:not([data-theme=\"light\"])"), | ||
| 231 | + decls, | ||
| 232 | + ); | ||
| 233 | + css.push_str("}\n"); | ||
| 234 | + rule(css, "", &format!("{selector}[data-theme=\"dark\"]"), decls); | ||
| 235 | +} | ||
| 236 | + | ||
| 237 | +/// The text colour on a fill: white or near-black, whichever reads better. | ||
| 238 | +fn text_on(fill: &str) -> String { | ||
| 239 | + const WHITE: &str = "#FFFFFF"; | ||
| 240 | + const INK: &str = "#111111"; | ||
| 241 | + if contrast_ratio(WHITE, fill) >= contrast_ratio(INK, fill) { | ||
| 242 | + WHITE.to_owned() | ||
| 243 | + } else { | ||
| 244 | + INK.to_owned() | ||
| 245 | + } | ||
| 246 | +} | ||
| 247 | + | ||
| 248 | +/// The largest chroma up to `chroma` that fits sRGB at this lightness and hue. | ||
| 249 | +fn fit_chroma(lightness: f64, chroma: f64, hue: f64) -> f64 { | ||
| 250 | + if in_gamut(lightness, chroma, hue) { | ||
| 251 | + return chroma; | ||
| 252 | + } | ||
| 253 | + let (mut low, mut high) = (0.0, chroma); | ||
| 254 | + for _ in 0..32 { | ||
| 255 | + let mid = (low + high) / 2.0; | ||
| 256 | + if in_gamut(lightness, mid, hue) { | ||
| 257 | + low = mid; | ||
| 258 | + } else { | ||
| 259 | + high = mid; | ||
| 260 | + } | ||
| 261 | + } | ||
| 262 | + low | ||
| 263 | +} | ||
| 264 | + | ||
| 265 | +fn in_gamut(lightness: f64, chroma: f64, hue: f64) -> bool { | ||
| 266 | + oklch_to_linear(lightness, chroma, hue) | ||
| 267 | + .iter() | ||
| 268 | + .all(|v| (-GAMUT_EPS..=1.0 + GAMUT_EPS).contains(v)) | ||
| 269 | +} | ||
| 270 | + | ||
| 271 | +/// OKLCH to linear sRGB. A channel can fall outside `0..=1` when the colour is out of gamut. | ||
| 272 | +fn oklch_to_linear(lightness: f64, chroma: f64, hue: f64) -> [f64; 3] { | ||
| 273 | + let (sin, cos) = hue.to_radians().sin_cos(); | ||
| 274 | + let a = chroma * cos; | ||
| 275 | + let b = chroma * sin; | ||
| 276 | + let l = lightness + 0.396_337_777_4 * a + 0.215_803_757_3 * b; | ||
| 277 | + let m = lightness - 0.105_561_345_8 * a - 0.063_854_172_8 * b; | ||
| 278 | + let s = lightness - 0.089_484_177_5 * a - 1.291_485_548 * b; | ||
| 279 | + let (l, m, s) = (l * l * l, m * m * m, s * s * s); | ||
| 280 | + [ | ||
| 281 | + 4.076_741_662_1 * l - 3.307_711_591_3 * m + 0.230_969_929_2 * s, | ||
| 282 | + -1.268_438_004_6 * l + 2.609_757_401_1 * m - 0.341_319_396_5 * s, | ||
| 283 | + -0.004_196_086_3 * l - 0.703_418_614_7 * m + 1.707_614_701 * s, | ||
| 284 | + ] | ||
| 285 | +} | ||
| 286 | + | ||
| 287 | +/// Linear sRGB to OKLCH: lightness, chroma and hue in degrees. | ||
| 288 | +#[allow(dead_code)] // Used by `hex_hue`, which the settings picker reads through the preset hues. | ||
| 289 | +fn linear_to_oklch([r, g, b]: [f64; 3]) -> (f64, f64, f64) { | ||
| 290 | + let l = (0.412_221_470_8 * r + 0.536_332_536_3 * g + 0.051_445_992_9 * b).cbrt(); | ||
| 291 | + let m = (0.211_903_498_2 * r + 0.680_699_545_1 * g + 0.107_396_956_6 * b).cbrt(); | ||
| 292 | + let s = (0.088_302_461_9 * r + 0.281_718_837_6 * g + 0.629_978_700_5 * b).cbrt(); | ||
| 293 | + let lightness = 0.210_454_255_3 * l + 0.793_617_785 * m - 0.004_072_046_8 * s; | ||
| 294 | + let a = 1.977_998_495_1 * l - 2.428_592_205 * m + 0.450_593_709_9 * s; | ||
| 295 | + let b = 0.025_904_037_1 * l + 0.782_771_766_2 * m - 0.808_675_766 * s; | ||
| 296 | + ( | ||
| 297 | + lightness, | ||
| 298 | + a.hypot(b), | ||
| 299 | + b.atan2(a).to_degrees().rem_euclid(360.0), | ||
| 300 | + ) | ||
| 301 | +} | ||
| 302 | + | ||
| 303 | +fn relative_luminance(hex: &str) -> f64 { | ||
| 304 | + let [r, g, b] = hex_linear(hex); | ||
| 305 | + 0.2126 * r + 0.7152 * g + 0.0722 * b | ||
| 306 | +} | ||
| 307 | + | ||
| 308 | +/// The linear sRGB channels of a `#RRGGBB` colour. Our own colours only, so a bad one is a bug. | ||
| 309 | +fn hex_linear(hex: &str) -> [f64; 3] { | ||
| 310 | + let channel = |i: usize| { | ||
| 311 | + let byte = u8::from_str_radix(&hex[i..i + 2], 16).expect("a #RRGGBB colour"); | ||
| 312 | + decode(f64::from(byte) / 255.0) | ||
| 313 | + }; | ||
| 314 | + [channel(1), channel(3), channel(5)] | ||
| 315 | +} | ||
| 316 | + | ||
| 317 | +/// sRGB transfer function, encoded value to linear light. | ||
| 318 | +fn decode(v: f64) -> f64 { | ||
| 319 | + if v <= 0.040_45 { | ||
| 320 | + v / 12.92 | ||
| 321 | + } else { | ||
| 322 | + ((v + 0.055) / 1.055).powf(2.4) | ||
| 323 | + } | ||
| 324 | +} | ||
| 325 | + | ||
| 326 | +/// Linear light to the sRGB encoded value. | ||
| 327 | +fn encode(v: f64) -> f64 { | ||
| 328 | + if v <= 0.003_130_8 { | ||
| 329 | + 12.92 * v | ||
| 330 | + } else { | ||
| 331 | + 1.055 * v.powf(1.0 / 2.4) - 0.055 | ||
| 332 | + } | ||
| 333 | +} | ||
| 334 | + | ||
| 335 | +#[cfg(test)] | ||
| 336 | +mod tests { | ||
| 337 | + use super::*; | ||
| 338 | + use crate::accent_palette::{BASE_TOKEN_VARS, TOKEN_VARS}; | ||
| 339 | + | ||
| 340 | + fn is_hex_colour(value: &str) -> bool { | ||
| 341 | + value.len() == 7 | ||
| 342 | + && value.starts_with('#') | ||
| 343 | + && value[1..].bytes().all(|b| b.is_ascii_hexdigit()) | ||
| 344 | + } | ||
| 345 | + | ||
| 346 | + #[test] | ||
| 347 | + fn the_extremes_are_exact() { | ||
| 348 | + assert_eq!(colour(1.0, 0.0, 0.0), "#FFFFFF"); | ||
| 349 | + assert_eq!(colour(0.0, 0.0, 0.0), "#000000"); | ||
| 350 | + } | ||
| 351 | + | ||
| 352 | + #[test] | ||
| 353 | + fn a_preset_hue_reads_back_from_its_colour() { | ||
| 354 | + // Sage is about 149 degrees; Ocean about 240. | ||
| 355 | + assert_eq!(hex_hue("#5E7D63"), 149); | ||
| 356 | + assert_eq!(hex_hue("#467799"), 240); | ||
| 357 | + } | ||
| 358 | + | ||
| 359 | + #[test] | ||
| 360 | + fn every_hue_gives_hex_colours_with_the_right_token_names() { | ||
| 361 | + for hue in 0..360 { | ||
| 362 | + for dark in [false, true] { | ||
| 363 | + let accent = accent_tokens(hue, dark); | ||
| 364 | + let names: Vec<&str> = accent.decls().iter().map(|(n, _)| *n).collect(); | ||
| 365 | + let expected: Vec<&str> = TOKEN_VARS.iter().map(|t| t.name).collect(); | ||
| 366 | + assert_eq!(names, expected); | ||
| 367 | + for (name, value) in accent.decls() { | ||
| 368 | + assert!(is_hex_colour(value), "{hue} {dark} {name}: {value}"); | ||
| 369 | + } | ||
| 370 | + let base = base_tokens(hue, dark); | ||
| 371 | + let names: Vec<&str> = base.decls().iter().map(|(n, _)| *n).collect(); | ||
| 372 | + let expected: Vec<&str> = BASE_TOKEN_VARS.iter().map(|t| t.name).collect(); | ||
| 373 | + assert_eq!(names, expected); | ||
| 374 | + for (name, value) in base.decls() { | ||
| 375 | + assert!(is_hex_colour(value), "{hue} {dark} {name}: {value}"); | ||
| 376 | + } | ||
| 377 | + } | ||
| 378 | + } | ||
| 379 | + } | ||
| 380 | + | ||
| 381 | + #[test] | ||
| 382 | + fn the_stylesheet_keys_each_rule_on_its_hue() { | ||
| 383 | + let css = stylesheet(Some(215), Some(215), None, Some(7)); | ||
| 384 | + assert!( | ||
| 385 | + css.contains(":root[data-accent-light=\"hue-215\"] {\n --accent: #"), | ||
| 386 | + "{css}" | ||
| 387 | + ); | ||
| 388 | + assert!( | ||
| 389 | + css.contains( | ||
| 390 | + "@media (prefers-color-scheme: dark) {\n :root[data-accent-dark=\"hue-215\"]:not([data-theme=\"light\"]) {" | ||
| 391 | + ), | ||
| 392 | + "{css}" | ||
| 393 | + ); | ||
| 394 | + assert!( | ||
| 395 | + css.contains(":root[data-accent-dark=\"hue-215\"][data-theme=\"dark\"] {"), | ||
| 396 | + "{css}" | ||
| 397 | + ); | ||
| 398 | + assert!( | ||
| 399 | + css.contains(":root[data-base-dark=\"hue-7\"][data-theme=\"dark\"] {"), | ||
| 400 | + "{css}" | ||
| 401 | + ); | ||
| 402 | + assert!(!css.contains("data-base-light"), "{css}"); | ||
| 403 | + assert!(stylesheet(None, None, None, None).is_empty()); | ||
| 404 | + } | ||
| 405 | +} | ||
crates/forge-web/src/i18n/accents.rsmodified+4 -48
| @@ -9,48 +9,16 @@ pub fn accent_name(lang: Lang, id: &str) -> &'static str { | |||
| 9 | match (id, lang) { | 9 | match (id, lang) { |
| 10 | ("sage", Lang::En) => "Sage", | 10 | ("sage", Lang::En) => "Sage", |
| 11 | ("sage", Lang::Tr) => "Adaçayı", | 11 | ("sage", Lang::Tr) => "Adaçayı", |
| 12 | + ("spark", Lang::En) => "Spark", | ||
| 13 | + ("spark", Lang::Tr) => "Kıvılcım", | ||
| 12 | ("ocean", Lang::En) => "Ocean", | 14 | ("ocean", Lang::En) => "Ocean", |
| 13 | ("ocean", Lang::Tr) => "Okyanus", | 15 | ("ocean", Lang::Tr) => "Okyanus", |
| 14 | ("plum", Lang::En) => "Plum", | 16 | ("plum", Lang::En) => "Plum", |
| 15 | ("plum", Lang::Tr) => "Erik", | 17 | ("plum", Lang::Tr) => "Erik", |
| 16 | ("rose", Lang::En) => "Rose", | 18 | ("rose", Lang::En) => "Rose", |
| 17 | ("rose", Lang::Tr) => "Gül", | 19 | ("rose", Lang::Tr) => "Gül", |
| 18 | - ("ochre", Lang::En) => "Ochre", | ||
| 19 | - ("ochre", Lang::Tr) => "Toprak", | ||
| 20 | - ("slate", Lang::En) => "Slate", | ||
| 21 | - ("slate", Lang::Tr) => "Arduvaz", | ||
| 22 | - ("teal", Lang::En) => "Teal", | ||
| 23 | - ("teal", Lang::Tr) => "Camgöbeği", | ||
| 24 | - ("moss", Lang::En) => "Moss", | ||
| 25 | - ("moss", Lang::Tr) => "Yosun", | ||
| 26 | - ("indigo", Lang::En) => "Indigo", | ||
| 27 | - ("indigo", Lang::Tr) => "Çivit", | ||
| 28 | - ("amber", Lang::En) => "Amber", | ||
| 29 | - ("amber", Lang::Tr) => "Kehribar", | ||
| 30 | - ("clay", Lang::En) => "Clay", | ||
| 31 | - ("clay", Lang::Tr) => "Kil", | ||
| 32 | - ("berry", Lang::En) => "Berry", | ||
| 33 | - ("berry", Lang::Tr) => "Böğürtlen", | ||
| 34 | - ("ember", Lang::En) => "Ember", | ||
| 35 | - ("ember", Lang::Tr) => "Kor", | ||
| 36 | - ("crimson", Lang::En) => "Crimson", | ||
| 37 | - ("crimson", Lang::Tr) => "Kızıl", | ||
| 38 | - ("coral", Lang::En) => "Coral", | ||
| 39 | - ("coral", Lang::Tr) => "Mercan", | ||
| 40 | ("gold", Lang::En) => "Gold", | 20 | ("gold", Lang::En) => "Gold", |
| 41 | ("gold", Lang::Tr) => "Altın", | 21 | ("gold", Lang::Tr) => "Altın", |
| 42 | - ("lime", Lang::En) => "Lime", | ||
| 43 | - ("lime", Lang::Tr) => "Misket", | ||
| 44 | - ("mint", Lang::En) => "Mint", | ||
| 45 | - ("mint", Lang::Tr) => "Nane", | ||
| 46 | - ("cyan", Lang::En) => "Cyan", | ||
| 47 | - ("cyan", Lang::Tr) => "Turkuaz", | ||
| 48 | - ("sky", Lang::En) => "Sky", | ||
| 49 | - ("sky", Lang::Tr) => "Gökyüzü", | ||
| 50 | - ("violet", Lang::En) => "Violet", | ||
| 51 | - ("violet", Lang::Tr) => "Menekşe", | ||
| 52 | - ("fuchsia", Lang::En) => "Fuchsia", | ||
| 53 | - ("fuchsia", Lang::Tr) => "Fuşya", | ||
| 54 | _ => "", | 22 | _ => "", |
| 55 | } | 23 | } |
| 56 | } | 24 | } |
| @@ -61,26 +29,14 @@ pub fn base_name(lang: Lang, id: &str) -> &'static str { | |||
| 61 | match (id, lang) { | 29 | match (id, lang) { |
| 62 | ("fern", Lang::En) => "Fern", | 30 | ("fern", Lang::En) => "Fern", |
| 63 | ("fern", Lang::Tr) => "Eğrelti", | 31 | ("fern", Lang::Tr) => "Eğrelti", |
| 64 | - ("stone", Lang::En) => "Stone", | 32 | + ("spark", Lang::En) => "Spark", |
| 65 | - ("stone", Lang::Tr) => "Taş", | 33 | + ("spark", Lang::Tr) => "Kıvılcım", |
| 66 | - ("sand", Lang::En) => "Sand", | ||
| 67 | - ("sand", Lang::Tr) => "Kum", | ||
| 68 | - ("mist", Lang::En) => "Mist", | ||
| 69 | - ("mist", Lang::Tr) => "Sis", | ||
| 70 | ("ink", Lang::En) => "Ink", | 34 | ("ink", Lang::En) => "Ink", |
| 71 | ("ink", Lang::Tr) => "Mürekkep", | 35 | ("ink", Lang::Tr) => "Mürekkep", |
| 72 | - ("dune", Lang::En) => "Dune", | ||
| 73 | - ("dune", Lang::Tr) => "Kumul", | ||
| 74 | - ("lilac", Lang::En) => "Lilac", | ||
| 75 | - ("lilac", Lang::Tr) => "Leylak", | ||
| 76 | ("dusk", Lang::En) => "Dusk", | 36 | ("dusk", Lang::En) => "Dusk", |
| 77 | ("dusk", Lang::Tr) => "Alacakaranlık", | 37 | ("dusk", Lang::Tr) => "Alacakaranlık", |
| 78 | - ("blush", Lang::En) => "Blush", | ||
| 79 | - ("blush", Lang::Tr) => "Pudra", | ||
| 80 | ("graphite", Lang::En) => "Graphite", | 38 | ("graphite", Lang::En) => "Graphite", |
| 81 | ("graphite", Lang::Tr) => "Grafit", | 39 | ("graphite", Lang::Tr) => "Grafit", |
| 82 | - ("pine", Lang::En) => "Pine", | ||
| 83 | - ("pine", Lang::Tr) => "Çam", | ||
| 84 | _ => "", | 40 | _ => "", |
| 85 | } | 41 | } |
| 86 | } | 42 | } |
crates/forge-web/src/main.rsmodified+1 -0
| @@ -24,6 +24,7 @@ mod boot; | |||
| 24 | mod ci; | 24 | mod ci; |
| 25 | mod client_ip; | 25 | mod client_ip; |
| 26 | mod compression; | 26 | mod compression; |
| 27 | +mod custom_colour; | ||
| 27 | mod exporter; | 28 | mod exporter; |
| 28 | mod git_auth; | 29 | mod git_auth; |
| 29 | mod git_http; | 30 | mod git_http; |
crates/forge-web/src/pages/assets.rsmodified+87 -2
| @@ -1,13 +1,17 @@ | |||
| 1 | -//! Serves the compiled stylesheet (build.rs output) at `/assets/main.css`, and the syntax | 1 | +//! Serves the compiled stylesheet (build.rs output) at `/assets/main.css`, the syntax |
| 2 | -//! highlighting classes at `/assets/highlight.css`. | 2 | +//! highlighting classes at `/assets/highlight.css`, and the colours of the hue choices at |
| 3 | +//! `/theme/custom.css`. | ||
| 3 | 4 | ||
| 4 | use std::sync::OnceLock; | 5 | use std::sync::OnceLock; |
| 5 | 6 | ||
| 6 | use topcoat::Result; | 7 | use topcoat::Result; |
| 7 | use topcoat::context::Cx; | 8 | use topcoat::context::Cx; |
| 9 | +use topcoat::router::request::uri; | ||
| 8 | use topcoat::router::response::Response; | 10 | use topcoat::router::response::Response; |
| 9 | use topcoat::router::{HeaderMap, StatusCode, header, route}; | 11 | use topcoat::router::{HeaderMap, StatusCode, header, route}; |
| 10 | 12 | ||
| 13 | +use crate::accent; | ||
| 14 | +use crate::custom_colour; | ||
| 11 | use crate::render::highlight::highlight_css; | 15 | use crate::render::highlight::highlight_css; |
| 12 | 16 | ||
| 13 | const CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/main.css")); | 17 | const CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/main.css")); |
| @@ -81,6 +85,43 @@ async fn highlight_css_route() -> Result<(StatusCode, HeaderMap, &'static str)> | |||
| 81 | Ok((StatusCode::OK, headers, highlight_css_text())) | 85 | Ok((StatusCode::OK, headers, highlight_css_text())) |
| 82 | } | 86 | } |
| 83 | 87 | ||
| 88 | +/// The colours of the hue choices on one page. The query names the four choices: `al` and `ad` for | ||
| 89 | +/// the accent (light and dark), `bl` and `bd` for the base. A `hue-N` id makes its rules, and any | ||
| 90 | +/// other value is ignored, so a bad link gets an empty stylesheet. The query sets the whole content, | ||
| 91 | +/// so the response is immutable like the others. | ||
| 92 | +#[route(GET "/theme/custom.css")] | ||
| 93 | +async fn custom_css_route(cx: &Cx) -> Result<(StatusCode, HeaderMap, String)> { | ||
| 94 | + let mut hues: [Option<u16>; 4] = [None; 4]; | ||
| 95 | + if let Some(query) = uri(cx).query() { | ||
| 96 | + for (key, value) in form_urlencoded::parse(query.as_bytes()) { | ||
| 97 | + let slot = match key.as_ref() { | ||
| 98 | + "al" => 0, | ||
| 99 | + "ad" => 1, | ||
| 100 | + "bl" => 2, | ||
| 101 | + "bd" => 3, | ||
| 102 | + _ => continue, | ||
| 103 | + }; | ||
| 104 | + hues[slot] = accent::hue_of(&value); | ||
| 105 | + } | ||
| 106 | + } | ||
| 107 | + let [accent_light, accent_dark, base_light, base_dark] = hues; | ||
| 108 | + let css = custom_colour::stylesheet(accent_light, accent_dark, base_light, base_dark); | ||
| 109 | + let mut headers = HeaderMap::new(); | ||
| 110 | + headers.insert( | ||
| 111 | + header::CONTENT_TYPE, | ||
| 112 | + "text/css; charset=utf-8" | ||
| 113 | + .parse() | ||
| 114 | + .expect("static header value"), | ||
| 115 | + ); | ||
| 116 | + headers.insert( | ||
| 117 | + header::CACHE_CONTROL, | ||
| 118 | + "public, max-age=31536000, immutable" | ||
| 119 | + .parse() | ||
| 120 | + .expect("static header value"), | ||
| 121 | + ); | ||
| 122 | + Ok((StatusCode::OK, headers, css)) | ||
| 123 | +} | ||
| 124 | + | ||
| 84 | // The offline page (shown by the service worker when a page load finds the server down) and its | 125 | // The offline page (shown by the service worker when a page load finds the server down) and its |
| 85 | // script. Not hashed and not immutable: the service worker fetches them again on each update. | 126 | // script. Not hashed and not immutable: the service worker fetches them again on each update. |
| 86 | const OFFLINE_HTML: &str = include_str!("../../assets/offline.html"); | 127 | const OFFLINE_HTML: &str = include_str!("../../assets/offline.html"); |
| @@ -391,4 +432,48 @@ mod tests { | |||
| 391 | let body = to_bytes(res.into_body(), usize::MAX).await.unwrap(); | 432 | let body = to_bytes(res.into_body(), usize::MAX).await.unwrap(); |
| 392 | assert!(!body.is_empty()); | 433 | assert!(!body.is_empty()); |
| 393 | } | 434 | } |
| 435 | + | ||
| 436 | + #[tokio::test] | ||
| 437 | + async fn custom_css_keys_the_hue_choices_and_ignores_the_rest() { | ||
| 438 | + let router: Router = Router::builder().discover().cookies().build(); | ||
| 439 | + let req = Request::builder() | ||
| 440 | + .method("GET") | ||
| 441 | + .uri("/theme/custom.css?al=hue-215&ad=plum&bl=hue-7&bd=hue-360") | ||
| 442 | + .body(Body::empty()) | ||
| 443 | + .unwrap(); | ||
| 444 | + let res = router.handle(req).await; | ||
| 445 | + assert_eq!(res.status(), 200); | ||
| 446 | + assert_eq!(res.headers()["content-type"], "text/css; charset=utf-8"); | ||
| 447 | + assert!( | ||
| 448 | + res.headers()["cache-control"] | ||
| 449 | + .to_str() | ||
| 450 | + .unwrap() | ||
| 451 | + .contains("immutable") | ||
| 452 | + ); | ||
| 453 | + let body = to_bytes(res.into_body(), usize::MAX).await.unwrap(); | ||
| 454 | + let css = String::from_utf8(body.to_vec()).unwrap(); | ||
| 455 | + assert!( | ||
| 456 | + css.contains(":root[data-accent-light=\"hue-215\"] {"), | ||
| 457 | + "{css}" | ||
| 458 | + ); | ||
| 459 | + assert!(css.contains(":root[data-base-light=\"hue-7\"] {"), "{css}"); | ||
| 460 | + assert!(!css.contains("plum"), "{css}"); | ||
| 461 | + assert!(!css.contains("hue-360"), "{css}"); | ||
| 462 | + } | ||
| 463 | + | ||
| 464 | + #[tokio::test] | ||
| 465 | + async fn custom_css_with_no_hue_is_empty_and_never_an_error() { | ||
| 466 | + let router: Router = Router::builder().discover().cookies().build(); | ||
| 467 | + for uri in ["/theme/custom.css", "/theme/custom.css?al=hue-x&bd=%00"] { | ||
| 468 | + let req = Request::builder() | ||
| 469 | + .method("GET") | ||
| 470 | + .uri(uri) | ||
| 471 | + .body(Body::empty()) | ||
| 472 | + .unwrap(); | ||
| 473 | + let res = router.handle(req).await; | ||
| 474 | + assert_eq!(res.status(), 200, "{uri}"); | ||
| 475 | + let body = to_bytes(res.into_body(), usize::MAX).await.unwrap(); | ||
| 476 | + assert!(body.is_empty(), "{uri}"); | ||
| 477 | + } | ||
| 478 | + } | ||
| 394 | } | 479 | } |
crates/forge-web/src/pages/settings_live.rsmodified+12 -6
| @@ -54,7 +54,9 @@ async fn settings_events(cx: &Cx) -> Result<Response> { | |||
| 54 | 54 | ||
| 55 | /// The appearance of a user's `<html>` as `name=value` pairs joined by `;`. An empty value means | 55 | /// The appearance of a user's `<html>` as `name=value` pairs joined by `;`. An empty value means |
| 56 | /// the attribute is removed (the automatic theme). It mirrors the attributes `views::shell` sets, so | 56 | /// the attribute is removed (the automatic theme). It mirrors the attributes `views::shell` sets, so |
| 57 | -/// a tab that applies it shows what a fresh load of the page would show. | 57 | +/// a tab that applies it shows what a fresh load of the page would show. The last pair, `custom_css`, |
| 58 | +/// is the stylesheet of the hue choices (empty for presets only); `nav.js` applies only `data-*` | ||
| 59 | +/// pairs, so it reads this one itself. | ||
| 58 | /// The account state the alive stream compares: the appearance (see below) and the language | 60 | /// The account state the alive stream compares: the appearance (see below) and the language |
| 59 | /// preference, which changes the page text rather than its attributes. | 61 | /// preference, which changes the page text rather than its attributes. |
| 60 | pub async fn account_state(state: &AppState, user_id: &str) -> Result<(String, String)> { | 62 | pub async fn account_state(state: &AppState, user_id: &str) -> Result<(String, String)> { |
| @@ -70,12 +72,16 @@ pub async fn account_state(state: &AppState, user_id: &str) -> Result<(String, S | |||
| 70 | } else { | 72 | } else { |
| 71 | "left" | 73 | "left" |
| 72 | }; | 74 | }; |
| 75 | + let accent_light = crate::accent::accent_id(&user.accent); | ||
| 76 | + let accent_dark = crate::accent::accent_id(&user.accent_dark); | ||
| 77 | + let base_light = crate::accent::base_id(&user.base_light); | ||
| 78 | + let base_dark = crate::accent::base_id(&user.base_dark); | ||
| 79 | + // The stylesheet of the hue choices, empty when there is none (see `views::shell`). | ||
| 80 | + let custom_css = | ||
| 81 | + crate::accent::custom_css_href(accent_light, accent_dark, base_light, base_dark) | ||
| 82 | + .unwrap_or_default(); | ||
| 73 | let appearance = format!( | 83 | let appearance = format!( |
| 74 | - "data-theme={theme};data-accent-light={};data-accent-dark={};data-base-light={};data-base-dark={};data-sidebar={sidebar}", | 84 | + "data-theme={theme};data-accent-light={accent_light};data-accent-dark={accent_dark};data-base-light={base_light};data-base-dark={base_dark};data-sidebar={sidebar};custom_css={custom_css}", |
| 75 | - crate::accent::resolve(&user.accent).id, | ||
| 76 | - crate::accent::resolve(&user.accent_dark).id, | ||
| 77 | - crate::accent::resolve_base(&user.base_light).id, | ||
| 78 | - crate::accent::resolve_base(&user.base_dark).id, | ||
| 79 | ); | 85 | ); |
| 80 | Ok((appearance, user.language.clone())) | 86 | Ok((appearance, user.language.clone())) |
| 81 | } | 87 | } |
crates/forge-web/src/views/mod.rsmodified+28 -6
| @@ -211,10 +211,18 @@ pub async fn shell( | |||
| 211 | crate::accent_palette::BASE_DEFAULT, | 211 | crate::accent_palette::BASE_DEFAULT, |
| 212 | ), | 212 | ), |
| 213 | }; | 213 | }; |
| 214 | - let accent_light_id = crate::accent::resolve(stored_accent_light).id; | 214 | + // A `hue-N` choice passes through as itself; an id forge does not offer shows the default. |
| 215 | - let accent_dark_id = crate::accent::resolve(stored_accent_dark).id; | 215 | + let accent_light_id = crate::accent::accent_id(stored_accent_light); |
| 216 | - let base_light_id = crate::accent::resolve_base(stored_base_light).id; | 216 | + let accent_dark_id = crate::accent::accent_id(stored_accent_dark); |
| 217 | - let base_dark_id = crate::accent::resolve_base(stored_base_dark).id; | 217 | + let base_light_id = crate::accent::base_id(stored_base_light); |
| 218 | + let base_dark_id = crate::accent::base_id(stored_base_dark); | ||
| 219 | + // The stylesheet that styles the hue choices, when there is one. The presets need none. | ||
| 220 | + let custom_css = crate::accent::custom_css_href( | ||
| 221 | + accent_light_id, | ||
| 222 | + accent_dark_id, | ||
| 223 | + base_light_id, | ||
| 224 | + base_dark_id, | ||
| 225 | + ); | ||
| 218 | // The side of the shell sidebar: `right` only when stored so, `left` otherwise. | 226 | // The side of the shell sidebar: `right` only when stored so, `left` otherwise. |
| 219 | let sidebar_side = match viewer { | 227 | let sidebar_side = match viewer { |
| 220 | Some((user, _)) if user.sidebar_side == "right" => "right", | 228 | Some((user, _)) if user.sidebar_side == "right" => "right", |
| @@ -261,6 +269,9 @@ pub async fn shell( | |||
| 261 | <title>(full_title)</title> | 269 | <title>(full_title)</title> |
| 262 | <link rel="preload" as="font" type="font/woff2" crossorigin="anonymous" href=(FIGTREE_PRELOAD_HREF)> | 270 | <link rel="preload" as="font" type="font/woff2" crossorigin="anonymous" href=(FIGTREE_PRELOAD_HREF)> |
| 263 | <link rel="stylesheet" href=(STYLESHEET_HREF)> | 271 | <link rel="stylesheet" href=(STYLESHEET_HREF)> |
| 272 | + if let Some(href) = &custom_css { | ||
| 273 | + <link rel="stylesheet" href=(href)> | ||
| 274 | + } | ||
| 264 | <link rel="stylesheet" href=(highlight_href())> | 275 | <link rel="stylesheet" href=(highlight_href())> |
| 265 | if let Some(href) = extra_stylesheet { | 276 | if let Some(href) = extra_stylesheet { |
| 266 | <link rel="stylesheet" href=(href)> | 277 | <link rel="stylesheet" href=(href)> |
| @@ -1370,11 +1381,11 @@ mod shell_tests { | |||
| 1370 | 1381 | ||
| 1371 | #[tokio::test] | 1382 | #[tokio::test] |
| 1372 | async fn the_html_tag_carries_the_viewers_colours() { | 1383 | async fn the_html_tag_carries_the_viewers_colours() { |
| 1373 | - let tag = html_tag_for_colours(["ocean", "plum", "ink", "mist"]).await; | 1384 | + let tag = html_tag_for_colours(["ocean", "plum", "ink", "dusk"]).await; |
| 1374 | assert!(tag.contains("data-accent-light=\"ocean\""), "{tag}"); | 1385 | assert!(tag.contains("data-accent-light=\"ocean\""), "{tag}"); |
| 1375 | assert!(tag.contains("data-accent-dark=\"plum\""), "{tag}"); | 1386 | assert!(tag.contains("data-accent-dark=\"plum\""), "{tag}"); |
| 1376 | assert!(tag.contains("data-base-light=\"ink\""), "{tag}"); | 1387 | assert!(tag.contains("data-base-light=\"ink\""), "{tag}"); |
| 1377 | - assert!(tag.contains("data-base-dark=\"mist\""), "{tag}"); | 1388 | + assert!(tag.contains("data-base-dark=\"dusk\""), "{tag}"); |
| 1378 | assert!(!tag.contains("data-accent="), "{tag}"); | 1389 | assert!(!tag.contains("data-accent="), "{tag}"); |
| 1379 | // Stored ids that are no longer offered fall back to the defaults, never to nothing. | 1390 | // Stored ids that are no longer offered fall back to the defaults, never to nothing. |
| 1380 | let removed = html_tag_for_colours(["removed-palette", "removed-palette", "x", "x"]).await; | 1391 | let removed = html_tag_for_colours(["removed-palette", "removed-palette", "x", "x"]).await; |
| @@ -1382,6 +1393,17 @@ mod shell_tests { | |||
| 1382 | assert!(removed.contains("data-accent-dark=\"sage\""), "{removed}"); | 1393 | assert!(removed.contains("data-accent-dark=\"sage\""), "{removed}"); |
| 1383 | assert!(removed.contains("data-base-light=\"fern\""), "{removed}"); | 1394 | assert!(removed.contains("data-base-light=\"fern\""), "{removed}"); |
| 1384 | assert!(removed.contains("data-base-dark=\"fern\""), "{removed}"); | 1395 | assert!(removed.contains("data-base-dark=\"fern\""), "{removed}"); |
| 1396 | + // A removed preset (`ochre`, `mist`) falls back too, and a hue passes through as itself. | ||
| 1397 | + let retired = html_tag_for_colours(["ochre", "ember", "mist", "stone"]).await; | ||
| 1398 | + assert!(retired.contains("data-accent-light=\"sage\""), "{retired}"); | ||
| 1399 | + assert!(retired.contains("data-accent-dark=\"sage\""), "{retired}"); | ||
| 1400 | + assert!(retired.contains("data-base-light=\"fern\""), "{retired}"); | ||
| 1401 | + assert!(retired.contains("data-base-dark=\"fern\""), "{retired}"); | ||
| 1402 | + let hued = html_tag_for_colours(["hue-215", "hue-7", "hue-300", "spark"]).await; | ||
| 1403 | + assert!(hued.contains("data-accent-light=\"hue-215\""), "{hued}"); | ||
| 1404 | + assert!(hued.contains("data-accent-dark=\"hue-7\""), "{hued}"); | ||
| 1405 | + assert!(hued.contains("data-base-light=\"hue-300\""), "{hued}"); | ||
| 1406 | + assert!(hued.contains("data-base-dark=\"spark\""), "{hued}"); | ||
| 1385 | } | 1407 | } |
| 1386 | 1408 | ||
| 1387 | #[tokio::test] | 1409 | #[tokio::test] |