| 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 |
pub use makeover::{FontFace, FontOverride, FontSlot, Typography}; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
pub fn themes(dir: impl AsRef<Path>) { |
| 83 |
let dir = dir.as_ref(); |
| 84 |
std::fs::create_dir_all(dir).expect("create themes dir"); |
| 85 |
|
| 86 |
for entry in std::fs::read_dir(dir).expect("read themes dir").flatten() { |
| 87 |
let path = entry.path(); |
| 88 |
if path.extension().is_some_and(|e| e == "toml") { |
| 89 |
std::fs::remove_file(&path).expect("remove stale theme"); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
for (id, source) in makeover::embedded_themes() { |
| 94 |
std::fs::write(dir.join(format!("{id}.toml")), source).expect("write theme"); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
pub fn layout_css(path: impl AsRef<Path>, opts: &makeover_webview::Emit) { |
| 109 |
std::fs::write(path, makeover_webview::stylesheet(opts)).expect("write layout css"); |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
pub fn geometry_css(path: impl AsRef<Path>, explicit_touch: Option<&str>) { |
| 131 |
let mut css = String::from( |
| 132 |
"/* Generated by makeover-build from makeover-geometry. Do not edit.\n \ |
| 133 |
Spacing is named by relationship, not by size. Touch density is a\n \ |
| 134 |
capability question: a narrow desktop window still has a pointer, a\n \ |
| 135 |
full-width tablet still has a finger. Window width is the separate\n \ |
| 136 |
question below it: on a compact window the two shells tighten. */\n", |
| 137 |
); |
| 138 |
css.push_str(&makeover_geometry::density_css(explicit_touch)); |
| 139 |
css.push('\n'); |
| 140 |
css.push_str(&makeover_geometry::size_class_css()); |
| 141 |
std::fs::write(path, css).expect("write geometry css"); |
| 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 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
pub fn timing_css(path: impl AsRef<Path>) { |
| 172 |
let mut css = String::from( |
| 173 |
"/* Generated by makeover-build from makeover-timing. Do not edit.\n \ |
| 174 |
A duration is named by what it is waiting for; the number follows.\n \ |
| 175 |
Three axes: how long a state lasts, how long a change takes, and how\n \ |
| 176 |
often a repeating mark repeats. The reduced-motion block below zeroes\n \ |
| 177 |
the last two and leaves the waits alone. A reader asking for less\n \ |
| 178 |
motion has not asked for a notice to leave early. */\n", |
| 179 |
); |
| 180 |
css.push_str(&makeover_timing::timing_css()); |
| 181 |
std::fs::write(path, css).expect("write timing css"); |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
pub fn typography_css(path: impl AsRef<Path>, font_url: &str) { |
| 211 |
typography_css_from(path, &makeover::Typography::house(font_url)); |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
pub fn typography_css_from(path: impl AsRef<Path>, typography: &makeover::Typography) { |
| 240 |
let mut css = String::from( |
| 241 |
"/* Generated by makeover-build from makeover. Do not edit.\n \ |
| 242 |
Two needs, two names, then a system generic. The faces are cut by\n \ |
| 243 |
quasi-type from Atkinson Hyperlegible plus the house glyph set, and\n \ |
| 244 |
both are variable over wght 200-800 in one file, which is why the\n \ |
| 245 |
@font-face rules name the range. The mono face opens at ExtraLight.\n \ |
| 246 |
A third token here is this product's own brand face, declared as an\n \ |
| 247 |
override in its build script. */\n\n", |
| 248 |
); |
| 249 |
css.push_str(&typography.css()); |
| 250 |
std::fs::write(path, css).expect("write typography css"); |
| 251 |
} |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
pub fn tauri_frontend( |
| 267 |
manifest_dir: impl AsRef<Path>, |
| 268 |
opts: &makeover_webview::Emit, |
| 269 |
explicit_touch: Option<&str>, |
| 270 |
) { |
| 271 |
tauri_frontend_with( |
| 272 |
manifest_dir, |
| 273 |
opts, |
| 274 |
explicit_touch, |
| 275 |
&makeover::Typography::house("../fonts"), |
| 276 |
); |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
pub fn tauri_frontend_with( |
| 295 |
manifest_dir: impl AsRef<Path>, |
| 296 |
opts: &makeover_webview::Emit, |
| 297 |
explicit_touch: Option<&str>, |
| 298 |
typography: &makeover::Typography, |
| 299 |
) { |
| 300 |
let root = manifest_dir.as_ref(); |
| 301 |
let css = root.join("frontend").join("css"); |
| 302 |
themes(root.join("themes")); |
| 303 |
geometry_css(css.join("geometry.css"), explicit_touch); |
| 304 |
|
| 305 |
|
| 306 |
timing_css(css.join("timing.css")); |
| 307 |
layout_css(css.join("layout.css"), opts); |
| 308 |
typography_css_from(css.join("typography.css"), typography); |
| 309 |
} |
| 310 |
|
| 311 |
#[cfg(test)] |
| 312 |
mod tests { |
| 313 |
use super::*; |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
fn scratch(name: &str) -> std::path::PathBuf { |
| 319 |
let dir = |
| 320 |
std::env::temp_dir().join(format!("makeover-build-{}-{name}", std::process::id())); |
| 321 |
let _ = std::fs::remove_dir_all(&dir); |
| 322 |
std::fs::create_dir_all(&dir).expect("create scratch"); |
| 323 |
dir |
| 324 |
} |
| 325 |
|
| 326 |
#[test] |
| 327 |
fn themes_are_written_one_file_per_id() { |
| 328 |
let dir = scratch("themes"); |
| 329 |
themes(&dir); |
| 330 |
let count = std::fs::read_dir(&dir).unwrap().count(); |
| 331 |
assert_eq!(count, makeover::embedded_themes().count()); |
| 332 |
assert!(count > 0, "makeover ships no themes?"); |
| 333 |
} |
| 334 |
|
| 335 |
#[test] |
| 336 |
fn a_theme_removed_upstream_does_not_linger() { |
| 337 |
|
| 338 |
let dir = scratch("stale"); |
| 339 |
std::fs::write(dir.join("gone-upstream.toml"), "# stale").unwrap(); |
| 340 |
themes(&dir); |
| 341 |
assert!(!dir.join("gone-upstream.toml").exists()); |
| 342 |
} |
| 343 |
|
| 344 |
#[test] |
| 345 |
fn a_non_theme_file_is_left_alone() { |
| 346 |
|
| 347 |
|
| 348 |
let dir = scratch("keep"); |
| 349 |
std::fs::write(dir.join("README.md"), "not a theme").unwrap(); |
| 350 |
themes(&dir); |
| 351 |
assert!(dir.join("README.md").exists()); |
| 352 |
} |
| 353 |
|
| 354 |
#[test] |
| 355 |
fn the_stylesheet_lands_and_names_no_colour() { |
| 356 |
let dir = scratch("css"); |
| 357 |
let path = dir.join("layout.css"); |
| 358 |
layout_css(&path, &makeover_webview::Emit::default()); |
| 359 |
let css = std::fs::read_to_string(&path).unwrap(); |
| 360 |
assert!(css.contains("--bevel-raised")); |
| 361 |
assert!( |
| 362 |
!css.contains('#'), |
| 363 |
"a colour literal reached a build output" |
| 364 |
); |
| 365 |
} |
| 366 |
|
| 367 |
#[test] |
| 368 |
fn the_typography_file_declares_the_faces_before_the_tokens_that_name_them() { |
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
let dir = scratch("typography"); |
| 374 |
let path = dir.join("typography.css"); |
| 375 |
typography_css(&path, "/static/fonts"); |
| 376 |
let css = std::fs::read_to_string(&path).unwrap(); |
| 377 |
|
| 378 |
assert!(css.starts_with("/* Generated by makeover-build")); |
| 379 |
assert!( |
| 380 |
css.find("@font-face").unwrap() < css.find(":root").unwrap(), |
| 381 |
"the tokens come first, so the file reads as a stack with no ground" |
| 382 |
); |
| 383 |
assert!(css.contains("url(\"/static/fonts/QuasiMono.woff2\")")); |
| 384 |
assert!(css.contains("--font-sans: \"Quasi Body\", sans-serif;")); |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
assert!(!css.contains("@layer")); |
| 390 |
} |
| 391 |
|
| 392 |
#[test] |
| 393 |
fn an_overridden_slot_reaches_the_same_file_as_the_house_two() { |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
let dir = scratch("typography-override"); |
| 398 |
let path = dir.join("typography.css"); |
| 399 |
typography_css_from( |
| 400 |
&path, |
| 401 |
&Typography::house("/static/fonts").with_override( |
| 402 |
FontOverride::new(FontSlot::Display, "\"Young Serif\", serif") |
| 403 |
.with_face(FontFace::new("Young Serif", ["ysrf.woff2", "ysrf.ttf"])), |
| 404 |
), |
| 405 |
); |
| 406 |
let css = std::fs::read_to_string(&path).unwrap(); |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
assert_eq!(css.matches("@font-face {").count(), 3); |
| 412 |
assert!(css.contains("--font-display: \"Young Serif\", serif;")); |
| 413 |
assert!(css.contains("--font-mono: \"Quasi Mono\", monospace;")); |
| 414 |
assert!(css.contains("url(\"/static/fonts/ysrf.ttf\") format(\"truetype\")")); |
| 415 |
assert!(!css.contains("@layer")); |
| 416 |
} |
| 417 |
|
| 418 |
#[test] |
| 419 |
fn the_default_tauri_layout_is_the_house_layer_and_nothing_else() { |
| 420 |
|
| 421 |
|
| 422 |
let dir = scratch("tauri-default"); |
| 423 |
let plain = dir.join("plain.css"); |
| 424 |
let house = dir.join("house.css"); |
| 425 |
typography_css(&plain, "../fonts"); |
| 426 |
typography_css_from(&house, &Typography::house("../fonts")); |
| 427 |
assert_eq!( |
| 428 |
std::fs::read_to_string(&plain).unwrap(), |
| 429 |
std::fs::read_to_string(&house).unwrap() |
| 430 |
); |
| 431 |
} |
| 432 |
|
| 433 |
#[test] |
| 434 |
fn the_geometry_file_carries_the_crates_policy_and_a_banner() { |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
let dir = scratch("geometry"); |
| 439 |
let path = dir.join("geometry.css"); |
| 440 |
geometry_css(&path, Some(".ui-mode-mobile")); |
| 441 |
let css = std::fs::read_to_string(&path).unwrap(); |
| 442 |
assert!(css.starts_with("/* Generated by makeover-build")); |
| 443 |
assert!(css.contains("@media (hover: none), (pointer: coarse)")); |
| 444 |
assert!(css.contains(".ui-mode-mobile")); |
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
assert!(css.contains("--gap-pane"), "no compact shell override"); |
| 449 |
let compact = css |
| 450 |
.split("@media (max-width") |
| 451 |
.nth(1) |
| 452 |
.expect("compact block"); |
| 453 |
assert!( |
| 454 |
!compact.contains("--gap-peer"), |
| 455 |
"a control gap crept into a width query" |
| 456 |
); |
| 457 |
} |
| 458 |
|
| 459 |
#[test] |
| 460 |
fn the_timing_file_carries_the_values_and_the_block_that_overrides_them() { |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
let dir = scratch("timing"); |
| 466 |
let path = dir.join("timing.css"); |
| 467 |
timing_css(&path); |
| 468 |
let css = std::fs::read_to_string(&path).unwrap(); |
| 469 |
assert!(css.starts_with("/* Generated by makeover-build")); |
| 470 |
|
| 471 |
|
| 472 |
assert!(css.contains("--timing-dismiss"), "no intent tokens"); |
| 473 |
assert!(css.contains("--motion-fade"), "no motion token"); |
| 474 |
assert!(css.contains("--cadence-activity"), "no cadence token"); |
| 475 |
assert!( |
| 476 |
css.contains("@media (prefers-reduced-motion: reduce)"), |
| 477 |
"the values shipped without the block that turns them off" |
| 478 |
); |
| 479 |
|
| 480 |
|
| 481 |
assert!( |
| 482 |
css.find(":root").unwrap() < css.find("prefers-reduced-motion").unwrap(), |
| 483 |
"the motion-off block cannot override values declared after it" |
| 484 |
); |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
assert!(css.contains(makeover_geometry::CSS_LAYER)); |
| 489 |
} |
| 490 |
|
| 491 |
#[test] |
| 492 |
fn the_tauri_layout_puts_all_four_where_the_apps_look() { |
| 493 |
let root = scratch("tauri"); |
| 494 |
std::fs::create_dir_all(root.join("frontend").join("css")).unwrap(); |
| 495 |
tauri_frontend(&root, &makeover_webview::Emit::default(), None); |
| 496 |
let css = root.join("frontend").join("css"); |
| 497 |
for file in ["geometry.css", "timing.css", "layout.css", "typography.css"] { |
| 498 |
assert!(css.join(file).exists(), "{file} was not written"); |
| 499 |
} |
| 500 |
assert!(root.join("themes").is_dir()); |
| 501 |
} |
| 502 |
} |
| 503 |
|