| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
#![forbid(unsafe_code)] |
| 43 |
|
| 44 |
pub mod drift; |
| 45 |
|
| 46 |
use std::path::Path; |
| 47 |
|
| 48 |
pub use drift::{ |
| 49 |
check_breakpoints, check_breakpoints_files, check_touch_density, check_vocabulary, |
| 50 |
check_vocabulary_files, check_vocabulary_use, |
| 51 |
}; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
pub use makeover_webview::Emit; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
pub use makeover::{WEBFONT_MONO_FILE, WEBFONT_SANS_FILE}; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
pub fn themes(dir: impl AsRef<Path>) { |
| 78 |
let dir = dir.as_ref(); |
| 79 |
std::fs::create_dir_all(dir).expect("create themes dir"); |
| 80 |
|
| 81 |
for entry in std::fs::read_dir(dir).expect("read themes dir").flatten() { |
| 82 |
let path = entry.path(); |
| 83 |
if path.extension().is_some_and(|e| e == "toml") { |
| 84 |
std::fs::remove_file(&path).expect("remove stale theme"); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
for (id, source) in makeover::embedded_themes() { |
| 89 |
std::fs::write(dir.join(format!("{id}.toml")), source).expect("write theme"); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
pub fn layout_css(path: impl AsRef<Path>, opts: &makeover_webview::Emit) { |
| 104 |
std::fs::write(path, makeover_webview::stylesheet(opts)).expect("write layout css"); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
pub fn geometry_css(path: impl AsRef<Path>, explicit_touch: Option<&str>) { |
| 128 |
let mut css = String::from( |
| 129 |
"/* Generated by makeover-build from makeover-geometry. Do not edit.\n \ |
| 130 |
Spacing is named by relationship, not by size. Touch density is a\n \ |
| 131 |
capability question: a narrow desktop window still has a pointer, a\n \ |
| 132 |
full-width tablet still has a finger. Window width is the separate\n \ |
| 133 |
question below it: on a compact window the two shells tighten. */\n", |
| 134 |
); |
| 135 |
css.push_str(&makeover_geometry::density_css(explicit_touch)); |
| 136 |
css.push('\n'); |
| 137 |
css.push_str(&makeover_geometry::size_class_css()); |
| 138 |
std::fs::write(path, css).expect("write geometry css"); |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
pub fn typography_css(path: impl AsRef<Path>, font_url: &str) { |
| 168 |
let mut css = String::from( |
| 169 |
"/* Generated by makeover-build from makeover. Do not edit.\n \ |
| 170 |
Two needs, two names, then a system generic. The faces are cut by\n \ |
| 171 |
quasi-type from Atkinson Hyperlegible plus the house glyph set, and\n \ |
| 172 |
both are variable over wght 200-800 in one file, which is why the\n \ |
| 173 |
@font-face rules name the range. The mono face opens at ExtraLight. */\n\n", |
| 174 |
); |
| 175 |
css.push_str(&makeover::font_face_css(font_url)); |
| 176 |
css.push_str(&makeover::typography_css_vars()); |
| 177 |
std::fs::write(path, css).expect("write typography css"); |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
pub fn tauri_frontend( |
| 194 |
manifest_dir: impl AsRef<Path>, |
| 195 |
opts: &makeover_webview::Emit, |
| 196 |
explicit_touch: Option<&str>, |
| 197 |
) { |
| 198 |
let root = manifest_dir.as_ref(); |
| 199 |
let css = root.join("frontend").join("css"); |
| 200 |
themes(root.join("themes")); |
| 201 |
geometry_css(css.join("geometry.css"), explicit_touch); |
| 202 |
layout_css(css.join("layout.css"), opts); |
| 203 |
typography_css(css.join("typography.css"), "../fonts"); |
| 204 |
} |
| 205 |
|
| 206 |
#[cfg(test)] |
| 207 |
mod tests { |
| 208 |
use super::*; |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
fn scratch(name: &str) -> std::path::PathBuf { |
| 214 |
let dir = |
| 215 |
std::env::temp_dir().join(format!("makeover-build-{}-{name}", std::process::id())); |
| 216 |
let _ = std::fs::remove_dir_all(&dir); |
| 217 |
std::fs::create_dir_all(&dir).expect("create scratch"); |
| 218 |
dir |
| 219 |
} |
| 220 |
|
| 221 |
#[test] |
| 222 |
fn themes_are_written_one_file_per_id() { |
| 223 |
let dir = scratch("themes"); |
| 224 |
themes(&dir); |
| 225 |
let count = std::fs::read_dir(&dir).unwrap().count(); |
| 226 |
assert_eq!(count, makeover::embedded_themes().count()); |
| 227 |
assert!(count > 0, "makeover ships no themes?"); |
| 228 |
} |
| 229 |
|
| 230 |
#[test] |
| 231 |
fn a_theme_removed_upstream_does_not_linger() { |
| 232 |
|
| 233 |
let dir = scratch("stale"); |
| 234 |
std::fs::write(dir.join("gone-upstream.toml"), "# stale").unwrap(); |
| 235 |
themes(&dir); |
| 236 |
assert!(!dir.join("gone-upstream.toml").exists()); |
| 237 |
} |
| 238 |
|
| 239 |
#[test] |
| 240 |
fn a_non_theme_file_is_left_alone() { |
| 241 |
|
| 242 |
|
| 243 |
let dir = scratch("keep"); |
| 244 |
std::fs::write(dir.join("README.md"), "not a theme").unwrap(); |
| 245 |
themes(&dir); |
| 246 |
assert!(dir.join("README.md").exists()); |
| 247 |
} |
| 248 |
|
| 249 |
#[test] |
| 250 |
fn the_stylesheet_lands_and_names_no_colour() { |
| 251 |
let dir = scratch("css"); |
| 252 |
let path = dir.join("layout.css"); |
| 253 |
layout_css(&path, &makeover_webview::Emit::default()); |
| 254 |
let css = std::fs::read_to_string(&path).unwrap(); |
| 255 |
assert!(css.contains("--bevel-raised")); |
| 256 |
assert!( |
| 257 |
!css.contains('#'), |
| 258 |
"a colour literal reached a build output" |
| 259 |
); |
| 260 |
} |
| 261 |
|
| 262 |
#[test] |
| 263 |
fn the_typography_file_declares_the_faces_before_the_tokens_that_name_them() { |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
let dir = scratch("typography"); |
| 269 |
let path = dir.join("typography.css"); |
| 270 |
typography_css(&path, "/static/fonts"); |
| 271 |
let css = std::fs::read_to_string(&path).unwrap(); |
| 272 |
|
| 273 |
assert!(css.starts_with("/* Generated by makeover-build")); |
| 274 |
assert!( |
| 275 |
css.find("@font-face").unwrap() < css.find(":root").unwrap(), |
| 276 |
"the tokens come first, so the file reads as a stack with no ground" |
| 277 |
); |
| 278 |
assert!(css.contains("url(\"/static/fonts/QuasiMono.woff2\")")); |
| 279 |
assert!(css.contains("--font-sans: \"Quasi Body\", sans-serif;")); |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
assert!(!css.contains("@layer")); |
| 285 |
} |
| 286 |
|
| 287 |
#[test] |
| 288 |
fn the_geometry_file_carries_the_crates_policy_and_a_banner() { |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
let dir = scratch("geometry"); |
| 293 |
let path = dir.join("geometry.css"); |
| 294 |
geometry_css(&path, Some(".ui-mode-mobile")); |
| 295 |
let css = std::fs::read_to_string(&path).unwrap(); |
| 296 |
assert!(css.starts_with("/* Generated by makeover-build")); |
| 297 |
assert!(css.contains("@media (hover: none), (pointer: coarse)")); |
| 298 |
assert!(css.contains(".ui-mode-mobile")); |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
assert!(css.contains("--gap-pane"), "no compact shell override"); |
| 303 |
let compact = css |
| 304 |
.split("@media (max-width") |
| 305 |
.nth(1) |
| 306 |
.expect("compact block"); |
| 307 |
assert!( |
| 308 |
!compact.contains("--gap-peer"), |
| 309 |
"a control gap crept into a width query" |
| 310 |
); |
| 311 |
} |
| 312 |
|
| 313 |
#[test] |
| 314 |
fn the_tauri_layout_puts_all_three_where_the_apps_look() { |
| 315 |
let root = scratch("tauri"); |
| 316 |
std::fs::create_dir_all(root.join("frontend").join("css")).unwrap(); |
| 317 |
tauri_frontend(&root, &makeover_webview::Emit::default(), None); |
| 318 |
assert!( |
| 319 |
root.join("frontend") |
| 320 |
.join("css") |
| 321 |
.join("geometry.css") |
| 322 |
.exists() |
| 323 |
); |
| 324 |
assert!( |
| 325 |
root.join("frontend") |
| 326 |
.join("css") |
| 327 |
.join("layout.css") |
| 328 |
.exists() |
| 329 |
); |
| 330 |
assert!(root.join("themes").is_dir()); |
| 331 |
} |
| 332 |
} |
| 333 |
|