makeover_webview/build.rs
1//! Build-script support: the generated files every webview consumer
2//! materialises from its `build.rs`, and the checks that keep its hand-written
3//! frontend agreeing with them.
4//!
5//! Behind the `build` feature, so a runtime consumer of the renderer does not
6//! link `makeover`'s theme set. A consumer takes this crate twice: as a
7//! dependency for the markup and as a build-dependency with `features =
8//! ["build"]` for these files. `links` holds both to one version.
9//!
10//! Every consumer materialises the same generated files from a `build.rs`.
11//! This is that code, once.
12//!
13//! # Density
14//!
15//! [`geometry_css`] keys the touch preset on capability: touch hangs off "not
16//! a fine, hovering pointer" and never off a user-agent string or a
17//! breakpoint. An app with a manual override passes the selector it sets to
18//! `explicit_touch`.
19//!
20//! # Why these files are generated rather than checked in
21//!
22//! Tauri's resource globs are read by its CLI against the crate directory, so
23//! they cannot point into a registry checkout or `OUT_DIR`. Materialising into
24//! the crate keeps the source crate authoritative without vendoring a second
25//! copy that drifts. Every path written here is expected to be gitignored.
26//!
27//! # The other half: what is checked rather than written
28//!
29//! A consumer's frontend is not all generated. The stylesheet and the scripts
30//! are hand-written and state some of the same facts the generated files ask
31//! the crates for, so they can drift where a generated file cannot. [`drift`]
32//! holds the checks that keep them honest, and they are assertions rather than
33//! substitutions on purpose: a file that has to be generated to be correct
34//! stops being readable on its own.
35
36pub mod drift;
37
38use std::path::Path;
39
40pub use drift::{Allow, Breakpoints, Vocabulary, check_touch_density, check_vocabulary_use};
41
42/// The filenames [`typography_css`]'s `@font-face` rules fetch.
43///
44/// Re-exported so a consumer's `build.rs` needs no second dependency, and
45/// load-bearing for a further reason: the consumer's own build script writes those two files, so the emitter
46/// and the writer have to agree on the name. Through this they agree on a
47/// constant rather than on a string typed in two repositories.
48pub use makeover::{WEBFONT_MONO_FILE, WEBFONT_SANS_FILE};
49
50/// Layer 0 of the font model, re-exported for the same one-dependency reason.
51///
52/// A build script composing an override needs all four names and has no other
53/// reason to depend on `makeover` directly.
54pub use makeover::{FontFace, FontOverride, FontSlot, Typography};
55
56/// Write only when the bytes differ, so a generated file does not invalidate
57/// the build script that generated it.
58///
59/// Every emitter here writes into a directory the drift checks also read, and
60/// cargo compares a watched file's mtime against the build script's own
61/// `output`. An unconditional write moves that mtime on every run, so every run
62/// becomes the reason for the next one and the script runs on every build.
63///
64/// A read before each write costs microseconds, and the common
65/// case is that nothing changed: these files are a pure function of the crate
66/// version and the `Emit` options.
67fn write_if_changed(path: &Path, contents: &str, what: &str) {
68 // Cargo reruns a build script when a path it named with `rerun-if-changed`
69 // is newer than the script's last output, or has been deleted. Naming the
70 // output is what brings a generated file back after a hand deletion or a
71 // `git clean -X` over a gitignored `themes/`; without it the file stays
72 // gone until an unrelated edit reruns this script. Safe to name because
73 // the write below happens only on a byte difference, so a run with nothing
74 // changed moves no mtime and cannot invalidate itself through this.
75 println!("cargo::rerun-if-changed={}", path.display());
76 if std::fs::read_to_string(path).is_ok_and(|existing| existing == contents) {
77 return;
78 }
79 std::fs::write(path, contents).unwrap_or_else(|error| panic!("write {what}: {error}"));
80}
81
82/// The name of the file [`themes`] writes to record which themes it generated.
83///
84/// Read on the next run to tell a theme this run no longer ships from a
85/// `.toml` the consumer wrote into the same directory, which this crate has no
86/// business deleting. Not a `.toml`, so it never reads as a theme itself.
87const THEMES_MANIFEST: &str = ".makeover-themes";
88
89/// Write the themes `makeover` ships into `dir`, as `<id>.toml`.
90///
91/// Removes only the `.toml` files a previous run of this function generated
92/// and upstream no longer ships, so a theme removed or renamed upstream does
93/// not linger in the bundle from a previous build. A foreign `.toml` the
94/// consumer placed in the same directory is not recorded and is left alone;
95/// clearing by stem deleted a file this crate never wrote. Omitting the
96/// cleanup shows up as a theme that will not go away.
97///
98/// # Panics
99///
100/// If the directory cannot be created, read, or written. A build script has
101/// nowhere useful to return an error to, and a half-materialised theme set is
102/// worse than a failed build.
103pub fn themes(dir: impl AsRef<Path>) {
104 let dir = dir.as_ref();
105 std::fs::create_dir_all(dir).expect("create themes dir");
106
107 let shipped: std::collections::BTreeSet<String> = makeover::embedded_themes()
108 .map(|(id, _)| id.to_string())
109 .collect();
110
111 // Only what upstream no longer ships, and only what a previous run of this
112 // function wrote: the manifest is the boundary between our generated
113 // output and a consumer's own file. Clearing the directory first and
114 // writing every theme back was the same thing by result and not by mtime:
115 // it left `write_if_changed` nothing to compare against, so every build
116 // rewrote every theme and the script invalidated itself through them.
117 let manifest = dir.join(THEMES_MANIFEST);
118 if let Ok(previous) = std::fs::read_to_string(&manifest) {
119 for stem in previous.lines().filter(|line| !line.is_empty()) {
120 if !shipped.contains(stem) {
121 std::fs::remove_file(dir.join(format!("{stem}.toml"))).expect("remove stale theme");
122 }
123 }
124 }
125
126 for (id, source) in makeover::embedded_themes() {
127 write_if_changed(&dir.join(format!("{id}.toml")), source, "theme");
128 }
129
130 // Written last, so it names only what this run actually produced. The
131 // `write_if_changed` keeps it as stable as the themes it lists, which is
132 // the same idempotency the theme files themselves get.
133 let body = shipped.iter().cloned().collect::<Vec<_>>().join("\n");
134 write_if_changed(&manifest, &body, "themes manifest");
135}
136
137/// Write `makeover-webview`'s component stylesheet to `path`.
138///
139/// Baked at build time rather than applied from JS the way the intent layer
140/// is, because composition never changes at runtime: no theme may reach it, so
141/// there is nothing to re-apply and no second pass over `:root` to pay for on
142/// load.
143///
144/// # Panics
145///
146/// If the file cannot be written.
147pub fn layout_css(path: impl AsRef<Path>, opts: &crate::Emit) {
148 write_if_changed(path.as_ref(), &crate::stylesheet(opts), "layout css");
149}
150
151/// Write `makeover-geometry`'s spacing layer, with its canonical density
152/// selection, to `path`.
153///
154/// The policy is the crate's, not this one's: touch hangs off
155/// the negation of a fine, hovering pointer because density is a capability rather
156/// than a device or a width, and `explicit_touch` names a selector an app sets
157/// when the user has chosen. See [`makeover_geometry::density_css`]. All this
158/// adds is the generated-file banner and the write.
159///
160/// Both spacing axes land here, in the order the crate defines them.
161/// [`makeover_geometry::size_class_css`] follows the density block because it
162/// is the narrower claim: density says what is pointing at the screen, size
163/// class says how much screen there is, and on a compact window the two shells
164/// tighten regardless of which density selected them.
165///
166/// # Panics
167///
168/// If the file cannot be written.
169pub fn geometry_css(path: impl AsRef<Path>, explicit_touch: Option<&str>) {
170 let mut css = String::from(
171 "/* Generated by makeover-webview from makeover-geometry. Do not edit.\n \
172 Spacing is named by relationship, not by size. Touch density is a\n \
173 capability question: a narrow desktop window still has a pointer, a\n \
174 full-width tablet still has a finger. Window width is the separate\n \
175 question below it: on a compact window the two shells tighten. */\n",
176 );
177 css.push_str(&makeover_geometry::density_css(explicit_touch));
178 css.push('\n');
179 css.push_str(&makeover_geometry::size_class_css());
180 write_if_changed(path.as_ref(), &css, "geometry css");
181}
182
183/// Write `makeover-timing`'s time axis, and the motion-off block that rides
184/// with it, to `path`.
185///
186/// The third generated axis, and it arrives the same way the spacing one does:
187/// a consumer that calls this gets `--timing-*`, `--motion-fade` and
188/// `--cadence-activity` without stating a number anywhere. All this adds is the
189/// banner and the write; `makeover_timing::timing_css` is the whole file and
190/// already wraps itself in [`makeover_geometry::CSS_LAYER`].
191///
192/// # Its own file, for the reason geometry has its own file
193///
194/// One generated file per crate, named for the axis it carries. Time is not a
195/// narrower claim about space the way size class is about density, so folding
196/// it into `geometry.css` would leave a file whose banner names one crate and
197/// whose contents come from two. The cost is a fourth `<link>` in the consumer,
198/// which is the cost the family already pays three times.
199///
200/// # The `prefers-reduced-motion` block is not optional
201///
202/// `makeover_timing::timing_css` emits the `:root` values and then a media
203/// block overriding two of them. Both land here, in that order, because they
204/// are one statement: a sheet carrying only the values animates at every rung
205/// for a reader who asked it not to, and does it silently.
206///
207/// # Panics
208///
209/// If the file cannot be written.
210pub fn timing_css(path: impl AsRef<Path>) {
211 let mut css = String::from(
212 "/* Generated by makeover-webview from makeover-timing. Do not edit.\n \
213 A duration is named by what it is waiting for; the number follows.\n \
214 Three axes: how long a state lasts, how long a change takes, and how\n \
215 often a repeating mark repeats. The reduced-motion block below zeroes\n \
216 the last two and leaves the waits alone. A reader asking for less\n \
217 motion has not asked for a notice to leave early. */\n",
218 );
219 css.push_str(&makeover_timing::timing_css());
220 write_if_changed(path.as_ref(), &css, "timing css");
221}
222
223/// Write the house typography layer to `path`: the two `@font-face` rules and
224/// the two tokens they back.
225///
226/// `font_url` is the directory the consumer serves its fonts from, without a
227/// trailing slash: `/static/fonts` on the MNW server, `fonts` for a Tauri
228/// frontend loading relative to its index.
229///
230/// Generated rather than hand-written for the same reason the spacing layer is:
231/// the facts are the crates' and stating them per app is how three apps came to
232/// hold three different answers to `--font-mono`. It is a separate file from
233/// the layout stylesheet because `@font-face` rules take no part in the
234/// cascade and a consumer may need to load them ahead of a layer order it
235/// declares elsewhere.
236///
237/// # The consumer still has to put the faces there
238///
239/// This writes the CSS that fetches `QuasiMono.woff2` and `QuasiBody.woff2`; it
240/// does not write the fonts. It cannot: they are cut by `quasi-type`, which is
241/// `publish = false`, and this crate is on crates.io. A consumer takes
242/// quasi-type as a git dependency in its own `build.rs` and calls
243/// `quasi_type::cut`, the way `shop-font` does, writing each slot's woff2 under
244/// [`makeover::WEBFONT_MONO_FILE`] and [`makeover::WEBFONT_SANS_FILE`].
245///
246/// # Panics
247///
248/// If the file cannot be written.
249pub fn typography_css(path: impl AsRef<Path>, font_url: &str) {
250 typography_css_from(path, &makeover::Typography::house(font_url));
251}
252
253/// [`typography_css`], for a product that overrides a slot.
254///
255/// Layer 0 of the font model. A product with a brand face declares it here,
256/// once, and the generated sheet carries both the `@font-face` and the token,
257/// which replaces the hand-maintained `@font-face` block plus a
258/// `--font-heading` nothing else in the tree knew about:
259///
260/// ```no_run
261/// use makeover_webview::build::{FontFace, FontOverride, FontSlot, Typography};
262///
263/// makeover_webview::build::typography_css_from(
264/// "static/typography.css",
265/// &Typography::house("/static/fonts").with_override(
266/// FontOverride::new(FontSlot::Display, "\"Young Serif\", serif")
267/// .with_face(FontFace::new("Young Serif", ["ysrf.woff2", "ysrf.ttf"])),
268/// ),
269/// );
270/// ```
271///
272/// The product still ships the face itself, exactly as it does for the house
273/// two: this writes the CSS that fetches it and cannot produce a font.
274///
275/// # Panics
276///
277/// If the file cannot be written.
278pub fn typography_css_from(path: impl AsRef<Path>, typography: &makeover::Typography) {
279 let mut css = String::from(
280 "/* Generated by makeover-webview from makeover. Do not edit.\n \
281 Two needs, two names, then a system generic. The faces are cut by\n \
282 quasi-type from Atkinson Hyperlegible plus the house glyph set, and\n \
283 both are variable over wght 200-800 in one file, which is why the\n \
284 @font-face rules name the range. The mono face opens at ExtraLight.\n \
285 A third token here is this product's own brand face, declared as an\n \
286 override in its build script. */\n\n",
287 );
288 css.push_str(&typography.css());
289 write_if_changed(path.as_ref(), &css, "typography css");
290}
291
292/// All the generated files at the layout every Tauri consumer already uses:
293/// `themes/` beside the manifest, and
294/// `frontend/css/{geometry,timing,layout,typography}.css` under it.
295///
296/// Pass `env!("CARGO_MANIFEST_DIR")`. Consumers that want different paths call
297/// [`themes`], [`layout_css`] and [`typography_css`] directly.
298///
299/// The font URL is `../fonts`. A `url()` in a stylesheet resolves against the
300/// stylesheet rather than the page, so from `frontend/css/typography.css` that
301/// is `frontend/fonts`: the one layout a Tauri app has, since its frontend is
302/// served from its own directory.
303///
304/// # Panics
305///
306/// If any file cannot be written.
307pub fn tauri_frontend(
308 manifest_dir: impl AsRef<Path>,
309 opts: &crate::Emit,
310 explicit_touch: Option<&str>,
311) {
312 tauri_frontend_with(
313 manifest_dir,
314 opts,
315 explicit_touch,
316 &makeover::Typography::house("../fonts"),
317 );
318}
319
320/// [`tauri_frontend`], for a product that overrides a font slot.
321///
322/// Separate rather than a fourth parameter, so an app with no font override
323/// does not have to name the house typography.
324///
325/// The base URL is the caller's: pass `Typography::house("../fonts")` unless
326/// the app serves fonts from somewhere other than the one layout a Tauri
327/// frontend has.
328///
329/// # Panics
330///
331/// If any file cannot be written.
332pub fn tauri_frontend_with(
333 manifest_dir: impl AsRef<Path>,
334 opts: &crate::Emit,
335 explicit_touch: Option<&str>,
336 typography: &makeover::Typography,
337) {
338 let root = manifest_dir.as_ref();
339 let css = root.join("frontend").join("css");
340 themes(root.join("themes"));
341 geometry_css(css.join("geometry.css"), explicit_touch);
342 // Beside geometry rather than after layout: both are value files the
343 // component sheet reads, and a consumer's `<link>` order follows this one.
344 timing_css(css.join("timing.css"));
345 layout_css(css.join("layout.css"), opts);
346 typography_css_from(css.join("typography.css"), typography);
347}
348
349#[cfg(test)]
350mod tests {
351 use super::*;
352
353 /// A scratch directory keyed by process id, so a parallel test run does
354 /// not collide. No timestamp: the pid is enough and is deterministic
355 /// within a run.
356 fn scratch(name: &str) -> std::path::PathBuf {
357 let dir = std::env::temp_dir().join(format!(
358 "makeover-webview-build-{}-{name}",
359 std::process::id()
360 ));
361 let _ = std::fs::remove_dir_all(&dir);
362 std::fs::create_dir_all(&dir).expect("create scratch");
363 dir
364 }
365
366 #[test]
367 fn themes_are_written_one_file_per_id() {
368 let dir = scratch("themes");
369 themes(&dir);
370 // `.toml` only: the run also writes the manifest, which is not a theme.
371 let count = std::fs::read_dir(&dir)
372 .unwrap()
373 .flatten()
374 .filter(|entry| entry.path().extension().is_some_and(|ext| ext == "toml"))
375 .count();
376 assert_eq!(count, makeover::embedded_themes().count());
377 assert!(count > 0, "makeover ships no themes?");
378 }
379
380 #[test]
381 fn a_theme_removed_upstream_does_not_linger() {
382 // The detail that makes this worth sharing rather than retyping. A
383 // previous run generated `gone-upstream.toml` and recorded it in the
384 // manifest; this run no longer ships it, so the recorded entry is what
385 // marks the file stale.
386 let dir = scratch("stale");
387 std::fs::write(dir.join("gone-upstream.toml"), "# stale").unwrap();
388 std::fs::write(dir.join(THEMES_MANIFEST), "gone-upstream\n").unwrap();
389 themes(&dir);
390 assert!(!dir.join("gone-upstream.toml").exists());
391 }
392
393 #[test]
394 fn a_foreign_toml_that_was_not_generated_survives() {
395 // The manifest is the boundary: a `.toml` the consumer placed here was
396 // never generated by `themes`, so a rebuild must not clear it the way
397 // the old by-stem sweep did.
398 let dir = scratch("foreign");
399 std::fs::write(dir.join("user-custom.toml"), "# mine").unwrap();
400 themes(&dir);
401 assert!(dir.join("user-custom.toml").exists());
402 }
403
404 #[test]
405 fn a_second_run_touches_nothing() {
406 // The property the whole write-if-changed pass exists for: a build
407 // script that rewrites its own outputs invalidates itself, and cargo
408 // then reruns it on every build whatever changed. Asserted on mtime
409 // rather than on content, because content was always correct; it was
410 // the mtime that was the bug.
411 let dir = scratch("idempotent");
412 themes(&dir);
413 let before: Vec<_> = std::fs::read_dir(&dir)
414 .unwrap()
415 .flatten()
416 .map(|e| (e.path(), e.metadata().unwrap().modified().unwrap()))
417 .collect();
418 assert!(!before.is_empty(), "themes() wrote nothing to compare");
419
420 themes(&dir);
421 for (path, was) in before {
422 let now = std::fs::metadata(&path).unwrap().modified().unwrap();
423 assert_eq!(
424 was,
425 now,
426 "{} was rewritten by a second run with nothing changed",
427 path.display()
428 );
429 }
430 }
431
432 #[test]
433 fn a_generated_output_is_named_with_rerun_if_changed() {
434 // A deleted output, or a gitignored `themes/` emptied by `git clean
435 // -X`, has to be regenerated on the next build. That only happens if
436 // every write names its path with `rerun-if-changed`, which cargo
437 // treats as an input: a path newer than the script's last output, or
438 // gone, reruns it. Observed through a child process because the test
439 // harness owns this process's stdout and swallows a `println!`.
440 let exe = std::env::current_exe().expect("test binary path");
441 let child = std::process::Command::new(exe)
442 .args(["--nocapture", "emit_rerun_directive_child"])
443 .env("MAKEOVER_EMIT_RERUN", "1")
444 .output()
445 .expect("spawn child");
446 assert!(child.status.success(), "child failed: {child:?}");
447 let stdout = String::from_utf8_lossy(&child.stdout);
448 assert!(
449 stdout.contains("cargo::rerun-if-changed="),
450 "write_if_changed named no output with rerun-if-changed:\n{stdout}"
451 );
452 }
453
454 /// The child for [`a_generated_output_is_named_with_rerun_if_changed`]:
455 /// a silent no-op unless the parent set the trigger, so the ordinary suite
456 /// run does not write files or print directives.
457 #[test]
458 fn emit_rerun_directive_child() {
459 if std::env::var_os("MAKEOVER_EMIT_RERUN").is_none() {
460 return;
461 }
462 layout_css(
463 scratch("rerun-directive").join("layout.css"),
464 &crate::Emit::default(),
465 );
466 }
467
468 #[test]
469 fn a_non_theme_file_is_left_alone() {
470 // Only .toml is cleared, so a README or a .gitignore in the bundle
471 // directory survives a rebuild.
472 let dir = scratch("keep");
473 std::fs::write(dir.join("README.md"), "not a theme").unwrap();
474 themes(&dir);
475 assert!(dir.join("README.md").exists());
476 }
477
478 #[test]
479 fn the_stylesheet_lands_and_names_no_colour() {
480 let dir = scratch("css");
481 let path = dir.join("layout.css");
482 layout_css(&path, &crate::Emit::default());
483 let css = std::fs::read_to_string(&path).unwrap();
484 assert!(css.contains("--bevel-raised"));
485 assert!(
486 !css.contains('#'),
487 "a colour literal reached a build output"
488 );
489 }
490
491 #[test]
492 fn the_typography_file_declares_the_faces_before_the_tokens_that_name_them() {
493 // The vocabulary itself is tested in makeover. What is this crate's
494 // job is that both halves reach one file, in an order that works: a
495 // `@font-face` may follow its use in the cascade, but reading the file
496 // is how anyone finds out a face is fetched at all.
497 let dir = scratch("typography");
498 let path = dir.join("typography.css");
499 typography_css(&path, "/static/fonts");
500 let css = std::fs::read_to_string(&path).unwrap();
501
502 assert!(css.starts_with("/* Generated by makeover-webview"));
503 assert!(
504 css.find("@font-face").unwrap() < css.find(":root").unwrap(),
505 "the tokens come first, so the file reads as a stack with no ground"
506 );
507 assert!(css.contains("url(\"/static/fonts/QuasiMono.woff2\")"));
508 assert!(css.contains("--font-sans: \"Quasi Body\", sans-serif;"));
509
510 // Not a cascade layer. `@font-face` takes no part in the cascade and a
511 // consumer may need these rules ahead of a layer order it declares
512 // elsewhere, so wrapping this file in one would be a silent trap.
513 assert!(!css.contains("@layer"));
514 }
515
516 #[test]
517 fn an_overridden_slot_reaches_the_same_file_as_the_house_two() {
518 // Layer 0's whole point: the brand face stops being a hand-maintained
519 // `@font-face` in the app's own stylesheet and becomes a line in the
520 // generated one, beside the slots it sits next to.
521 let dir = scratch("typography-override");
522 let path = dir.join("typography.css");
523 typography_css_from(
524 &path,
525 &Typography::house("/static/fonts").with_override(
526 FontOverride::new(FontSlot::Display, "\"Young Serif\", serif")
527 .with_face(FontFace::new("Young Serif", ["ysrf.woff2", "ysrf.ttf"])),
528 ),
529 );
530 let css = std::fs::read_to_string(&path).unwrap();
531
532 // `@font-face {`, not `@font-face`: the header comment names the
533 // at-rule too, and counting that would make this pass for the wrong
534 // reason the day the comment is reworded.
535 assert_eq!(css.matches("@font-face {").count(), 3);
536 assert!(css.contains("--font-display: \"Young Serif\", serif;"));
537 assert!(css.contains("--font-mono: \"Quasi Mono\", monospace;"));
538 assert!(css.contains("url(\"/static/fonts/ysrf.ttf\") format(\"truetype\")"));
539 assert!(!css.contains("@layer"));
540 }
541
542 #[test]
543 fn the_default_tauri_layout_is_the_house_layer_and_nothing_else() {
544 // `tauri_frontend` delegating through `tauri_frontend_with` must not
545 // change a byte for the three consumers already calling it.
546 let dir = scratch("tauri-default");
547 let plain = dir.join("plain.css");
548 let house = dir.join("house.css");
549 typography_css(&plain, "../fonts");
550 typography_css_from(&house, &Typography::house("../fonts"));
551 assert_eq!(
552 std::fs::read_to_string(&plain).unwrap(),
553 std::fs::read_to_string(&house).unwrap()
554 );
555 }
556
557 #[test]
558 fn the_geometry_file_carries_the_crates_policy_and_a_banner() {
559 // The policy itself is tested in makeover-geometry. What is this
560 // crate's job is that the banner is there and the policy reached the
561 // file at all.
562 let dir = scratch("geometry");
563 let path = dir.join("geometry.css");
564 geometry_css(&path, Some(".ui-mode-mobile"));
565 let css = std::fs::read_to_string(&path).unwrap();
566 assert!(css.starts_with("/* Generated by makeover-webview"));
567 assert!(css.contains(&format!(
568 "@media {}",
569 makeover_geometry::Density::Touch.media_condition()
570 )));
571 assert!(css.contains(".ui-mode-mobile"));
572 // The width axis rides along, and only the shells are in it: a gap
573 // between two controls in a width query is the bug size_class_css
574 // exists to keep out.
575 assert!(css.contains("--gap-pane"), "no compact shell override");
576 let compact = css
577 .split(&format!(
578 "@media {}",
579 makeover_geometry::SizeClass::Compact.media_condition()
580 ))
581 .nth(1)
582 .expect("compact block");
583 assert!(
584 !compact.contains("--gap-peer"),
585 "a control gap crept into a width query"
586 );
587 }
588
589 #[test]
590 fn the_timing_file_carries_the_values_and_the_block_that_overrides_them() {
591 // The rungs themselves are tested in makeover-timing. What is this
592 // crate's to get wrong is dropping half the file: the values are
593 // useless noise without the media block, and the media block on its
594 // own overrides nothing.
595 let dir = scratch("timing");
596 let path = dir.join("timing.css");
597 timing_css(&path);
598 let css = std::fs::read_to_string(&path).unwrap();
599 assert!(css.starts_with("/* Generated by makeover-webview"));
600 // One token per axis, so a crate that grows a fourth axis and is not
601 // emitted here fails somewhere other than on screen.
602 assert!(css.contains("--timing-dismiss"), "no intent tokens");
603 assert!(css.contains("--motion-fade"), "no motion token");
604 assert!(css.contains("--cadence-activity"), "no cadence token");
605 assert!(
606 css.contains("@media (prefers-reduced-motion: reduce)"),
607 "the values shipped without the block that turns them off"
608 );
609 // The block comes after the values it overrides. Same specificity,
610 // so the order is the whole of the win.
611 assert!(
612 css.find(":root").unwrap() < css.find("prefers-reduced-motion").unwrap(),
613 "the motion-off block cannot override values declared after it"
614 );
615 // Inside the family's layer, like every other generated sheet:
616 // unlayered declarations outrank every named layer, so a generated
617 // file outside it beats the app's own overrides.
618 assert!(css.contains(makeover_geometry::CSS_LAYER));
619 }
620
621 #[test]
622 fn the_tauri_layout_puts_all_four_where_the_apps_look() {
623 let root = scratch("tauri");
624 std::fs::create_dir_all(root.join("frontend").join("css")).unwrap();
625 tauri_frontend(&root, &crate::Emit::default(), None);
626 let css = root.join("frontend").join("css");
627 for file in ["geometry.css", "timing.css", "layout.css", "typography.css"] {
628 assert!(css.join(file).exists(), "{file} was not written");
629 }
630 assert!(root.join("themes").is_dir());
631 }
632}