#![forbid(unsafe_code)]
pub mod drift;
use std::path::Path;
pub use drift::{
check_breakpoints, check_breakpoints_files, check_touch_density, check_vocabulary,
check_vocabulary_files, check_vocabulary_use,
};
pub use makeover_webview::Emit;
pub use makeover::{WEBFONT_MONO_FILE, WEBFONT_SANS_FILE};
pub use makeover::{FontFace, FontOverride, FontSlot, Typography};
pub fn themes(dir: impl AsRef<Path>) {
let dir = dir.as_ref();
std::fs::create_dir_all(dir).expect("create themes dir");
for entry in std::fs::read_dir(dir).expect("read themes dir").flatten() {
let path = entry.path();
if path.extension().is_some_and(|e| e == "toml") {
std::fs::remove_file(&path).expect("remove stale theme");
}
}
for (id, source) in makeover::embedded_themes() {
std::fs::write(dir.join(format!("{id}.toml")), source).expect("write theme");
}
}
pub fn layout_css(path: impl AsRef<Path>, opts: &makeover_webview::Emit) {
std::fs::write(path, makeover_webview::stylesheet(opts)).expect("write layout css");
}
pub fn geometry_css(path: impl AsRef<Path>, explicit_touch: Option<&str>) {
let mut css = String::from(
"/* Generated by makeover-build from makeover-geometry. Do not edit.\n \
Spacing is named by relationship, not by size. Touch density is a\n \
capability question: a narrow desktop window still has a pointer, a\n \
full-width tablet still has a finger. Window width is the separate\n \
question below it: on a compact window the two shells tighten. */\n",
);
css.push_str(&makeover_geometry::density_css(explicit_touch));
css.push('\n');
css.push_str(&makeover_geometry::size_class_css());
std::fs::write(path, css).expect("write geometry css");
}
pub fn typography_css(path: impl AsRef<Path>, font_url: &str) {
typography_css_from(path, &makeover::Typography::house(font_url));
}
pub fn typography_css_from(path: impl AsRef<Path>, typography: &makeover::Typography) {
let mut css = String::from(
"/* Generated by makeover-build from makeover. Do not edit.\n \
Two needs, two names, then a system generic. The faces are cut by\n \
quasi-type from Atkinson Hyperlegible plus the house glyph set, and\n \
both are variable over wght 200-800 in one file, which is why the\n \
@font-face rules name the range. The mono face opens at ExtraLight.\n \
A third token here is this product's own brand face, declared as an\n \
override in its build script. */\n\n",
);
css.push_str(&typography.css());
std::fs::write(path, css).expect("write typography css");
}
pub fn tauri_frontend(
manifest_dir: impl AsRef<Path>,
opts: &makeover_webview::Emit,
explicit_touch: Option<&str>,
) {
tauri_frontend_with(
manifest_dir,
opts,
explicit_touch,
&makeover::Typography::house("../fonts"),
);
}
pub fn tauri_frontend_with(
manifest_dir: impl AsRef<Path>,
opts: &makeover_webview::Emit,
explicit_touch: Option<&str>,
typography: &makeover::Typography,
) {
let root = manifest_dir.as_ref();
let css = root.join("frontend").join("css");
themes(root.join("themes"));
geometry_css(css.join("geometry.css"), explicit_touch);
layout_css(css.join("layout.css"), opts);
typography_css_from(css.join("typography.css"), typography);
}
#[cfg(test)]
mod tests {
use super::*;
fn scratch(name: &str) -> std::path::PathBuf {
let dir =
std::env::temp_dir().join(format!("makeover-build-{}-{name}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).expect("create scratch");
dir
}
#[test]
fn themes_are_written_one_file_per_id() {
let dir = scratch("themes");
themes(&dir);
let count = std::fs::read_dir(&dir).unwrap().count();
assert_eq!(count, makeover::embedded_themes().count());
assert!(count > 0, "makeover ships no themes?");
}
#[test]
fn a_theme_removed_upstream_does_not_linger() {
let dir = scratch("stale");
std::fs::write(dir.join("gone-upstream.toml"), "# stale").unwrap();
themes(&dir);
assert!(!dir.join("gone-upstream.toml").exists());
}
#[test]
fn a_non_theme_file_is_left_alone() {
let dir = scratch("keep");
std::fs::write(dir.join("README.md"), "not a theme").unwrap();
themes(&dir);
assert!(dir.join("README.md").exists());
}
#[test]
fn the_stylesheet_lands_and_names_no_colour() {
let dir = scratch("css");
let path = dir.join("layout.css");
layout_css(&path, &makeover_webview::Emit::default());
let css = std::fs::read_to_string(&path).unwrap();
assert!(css.contains("--bevel-raised"));
assert!(
!css.contains('#'),
"a colour literal reached a build output"
);
}
#[test]
fn the_typography_file_declares_the_faces_before_the_tokens_that_name_them() {
let dir = scratch("typography");
let path = dir.join("typography.css");
typography_css(&path, "/static/fonts");
let css = std::fs::read_to_string(&path).unwrap();
assert!(css.starts_with("/* Generated by makeover-build"));
assert!(
css.find("@font-face").unwrap() < css.find(":root").unwrap(),
"the tokens come first, so the file reads as a stack with no ground"
);
assert!(css.contains("url(\"/static/fonts/QuasiMono.woff2\")"));
assert!(css.contains("--font-sans: \"Quasi Body\", sans-serif;"));
assert!(!css.contains("@layer"));
}
#[test]
fn an_overridden_slot_reaches_the_same_file_as_the_house_two() {
let dir = scratch("typography-override");
let path = dir.join("typography.css");
typography_css_from(
&path,
&Typography::house("/static/fonts").with_override(
FontOverride::new(FontSlot::Display, "\"Young Serif\", serif")
.with_face(FontFace::new("Young Serif", ["ysrf.woff2", "ysrf.ttf"])),
),
);
let css = std::fs::read_to_string(&path).unwrap();
assert_eq!(css.matches("@font-face {").count(), 3);
assert!(css.contains("--font-display: \"Young Serif\", serif;"));
assert!(css.contains("--font-mono: \"Quasi Mono\", monospace;"));
assert!(css.contains("url(\"/static/fonts/ysrf.ttf\") format(\"truetype\")"));
assert!(!css.contains("@layer"));
}
#[test]
fn the_default_tauri_layout_is_the_house_layer_and_nothing_else() {
let dir = scratch("tauri-default");
let plain = dir.join("plain.css");
let house = dir.join("house.css");
typography_css(&plain, "../fonts");
typography_css_from(&house, &Typography::house("../fonts"));
assert_eq!(
std::fs::read_to_string(&plain).unwrap(),
std::fs::read_to_string(&house).unwrap()
);
}
#[test]
fn the_geometry_file_carries_the_crates_policy_and_a_banner() {
let dir = scratch("geometry");
let path = dir.join("geometry.css");
geometry_css(&path, Some(".ui-mode-mobile"));
let css = std::fs::read_to_string(&path).unwrap();
assert!(css.starts_with("/* Generated by makeover-build"));
assert!(css.contains("@media (hover: none), (pointer: coarse)"));
assert!(css.contains(".ui-mode-mobile"));
assert!(css.contains("--gap-pane"), "no compact shell override");
let compact = css
.split("@media (max-width")
.nth(1)
.expect("compact block");
assert!(
!compact.contains("--gap-peer"),
"a control gap crept into a width query"
);
}
#[test]
fn the_tauri_layout_puts_all_three_where_the_apps_look() {
let root = scratch("tauri");
std::fs::create_dir_all(root.join("frontend").join("css")).unwrap();
tauri_frontend(&root, &makeover_webview::Emit::default(), None);
assert!(
root.join("frontend")
.join("css")
.join("geometry.css")
.exists()
);
assert!(
root.join("frontend")
.join("css")
.join("layout.css")
.exists()
);
assert!(root.join("themes").is_dir());
}
}