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/// [`makeover_geometry::compactness_css`] closes the file, unlayered: row
167/// packing is a reader's choice, not a capability or a width, so its override
168/// must beat the `--row-block` default the density block wrote.
169///
170/// # Panics
171///
172/// If the file cannot be written.
173pub fn geometry_css(path: impl AsRef<Path>, explicit_touch: Option<&str>) {
174 let mut css = String::from(
175 "/* Generated by makeover-webview from makeover-geometry. Do not edit.\n \
176 Spacing is named by relationship, not by size. Touch density is a\n \
177 capability question: a narrow desktop window still has a pointer, a\n \
178 full-width tablet still has a finger. Window width is the separate\n \
179 question below it: on a compact window the two shells tighten. */\n",
180 );
181 css.push_str(&makeover_geometry::density_css(explicit_touch));
182 css.push('\n');
183 css.push_str(&makeover_geometry::size_class_css());
184 css.push('\n');
185 css.push_str(&makeover_geometry::compactness_css());
186 write_if_changed(path.as_ref(), &css, "geometry css");
187}
188
189/// Write `makeover-timing`'s time axis, and the motion-off block that rides
190/// with it, to `path`.
191///
192/// The third generated axis, and it arrives the same way the spacing one does:
193/// a consumer that calls this gets `--timing-*`, `--motion-fade` and
194/// `--cadence-activity` without stating a number anywhere. All this adds is the
195/// banner and the write; `makeover_timing::timing_css` is the whole file and
196/// already wraps itself in [`makeover_geometry::CSS_LAYER`].
197///
198/// # Its own file, for the reason geometry has its own file
199///
200/// One generated file per crate, named for the axis it carries. Time is not a
201/// narrower claim about space the way size class is about density, so folding
202/// it into `geometry.css` would leave a file whose banner names one crate and
203/// whose contents come from two. The cost is a fourth `<link>` in the consumer,
204/// which is the cost the family already pays three times.
205///
206/// # The `prefers-reduced-motion` block is not optional
207///
208/// `makeover_timing::timing_css` emits the `:root` values and then a media
209/// block overriding two of them. Both land here, in that order, because they
210/// are one statement: a sheet carrying only the values animates at every rung
211/// for a reader who asked it not to, and does it silently.
212///
213/// # Panics
214///
215/// If the file cannot be written.
216pub fn timing_css(path: impl AsRef<Path>) {
217 let mut css = String::from(
218 "/* Generated by makeover-webview from makeover-timing. Do not edit.\n \
219 A duration is named by what it is waiting for; the number follows.\n \
220 Three axes: how long a state lasts, how long a change takes, and how\n \
221 often a repeating mark repeats. The reduced-motion block below zeroes\n \
222 the last two and leaves the waits alone. A reader asking for less\n \
223 motion has not asked for a notice to leave early. */\n",
224 );
225 css.push_str(&makeover_timing::timing_css());
226 write_if_changed(path.as_ref(), &css, "timing css");
227}
228
229/// Write the house typography layer to `path`: the two `@font-face` rules and
230/// the two tokens they back.
231///
232/// `font_url` is the directory the consumer serves its fonts from, without a
233/// trailing slash: `/static/fonts` on the MNW server, `fonts` for a Tauri
234/// frontend loading relative to its index.
235///
236/// Generated rather than hand-written for the same reason the spacing layer is:
237/// the facts are the crates' and stating them per app is how three apps came to
238/// hold three different answers to `--font-mono`. It is a separate file from
239/// the layout stylesheet because `@font-face` rules take no part in the
240/// cascade and a consumer may need to load them ahead of a layer order it
241/// declares elsewhere.
242///
243/// # The consumer still has to put the faces there
244///
245/// This writes the CSS that fetches `QuasiMono.woff2` and `QuasiBody.woff2`; it
246/// does not write the fonts. It cannot: they are cut by `quasi-type`, which is
247/// `publish = false`, and this crate is on crates.io. A consumer takes
248/// quasi-type as a git dependency in its own `build.rs` and calls
249/// `quasi_type::cut`, the way `shop-font` does, writing each slot's woff2 under
250/// [`makeover::WEBFONT_MONO_FILE`] and [`makeover::WEBFONT_SANS_FILE`].
251///
252/// # Panics
253///
254/// If the file cannot be written.
255pub fn typography_css(path: impl AsRef<Path>, font_url: &str) {
256 typography_css_from(path, &makeover::Typography::house(font_url));
257}
258
259/// [`typography_css`], for a product that overrides a slot.
260///
261/// Layer 0 of the font model. A product with a brand face declares it here,
262/// once, and the generated sheet carries both the `@font-face` and the token,
263/// which replaces the hand-maintained `@font-face` block plus a
264/// `--font-heading` nothing else in the tree knew about:
265///
266/// ```no_run
267/// use makeover_webview::build::{FontFace, FontOverride, FontSlot, Typography};
268///
269/// makeover_webview::build::typography_css_from(
270/// "static/typography.css",
271/// &Typography::house("/static/fonts").with_override(
272/// FontOverride::new(FontSlot::Display, "\"Young Serif\", serif")
273/// .with_face(FontFace::new("Young Serif", ["ysrf.woff2", "ysrf.ttf"])),
274/// ),
275/// );
276/// ```
277///
278/// The product still ships the face itself, exactly as it does for the house
279/// two: this writes the CSS that fetches it and cannot produce a font.
280///
281/// # Panics
282///
283/// If the file cannot be written.
284pub fn typography_css_from(path: impl AsRef<Path>, typography: &makeover::Typography) {
285 let mut css = String::from(
286 "/* Generated by makeover-webview from makeover. Do not edit.\n \
287 Two needs, two names, then a system generic. The faces are cut by\n \
288 quasi-type from Atkinson Hyperlegible plus the house glyph set, and\n \
289 both are variable over wght 200-800 in one file, which is why the\n \
290 @font-face rules name the range. The mono face opens at ExtraLight.\n \
291 A third token here is this product's own brand face, declared as an\n \
292 override in its build script. */\n\n",
293 );
294 css.push_str(&typography.css());
295 write_if_changed(path.as_ref(), &css, "typography css");
296}
297
298/// All the generated files at the layout every Tauri consumer already uses:
299/// `themes/` beside the manifest, and
300/// `frontend/css/{geometry,timing,layout,typography}.css` under it.
301///
302/// Pass `env!("CARGO_MANIFEST_DIR")`. Consumers that want different paths call
303/// [`themes`], [`layout_css`] and [`typography_css`] directly.
304///
305/// The font URL is `../fonts`. A `url()` in a stylesheet resolves against the
306/// stylesheet rather than the page, so from `frontend/css/typography.css` that
307/// is `frontend/fonts`: the one layout a Tauri app has, since its frontend is
308/// served from its own directory.
309///
310/// # Panics
311///
312/// If any file cannot be written.
313pub fn tauri_frontend(
314 manifest_dir: impl AsRef<Path>,
315 opts: &crate::Emit,
316 explicit_touch: Option<&str>,
317) {
318 tauri_frontend_with(
319 manifest_dir,
320 opts,
321 explicit_touch,
322 &makeover::Typography::house("../fonts"),
323 );
324}
325
326/// [`tauri_frontend`], for a product that overrides a font slot.
327///
328/// Separate rather than a fourth parameter, so an app with no font override
329/// does not have to name the house typography.
330///
331/// The base URL is the caller's: pass `Typography::house("../fonts")` unless
332/// the app serves fonts from somewhere other than the one layout a Tauri
333/// frontend has.
334///
335/// # Panics
336///
337/// If any file cannot be written.
338pub fn tauri_frontend_with(
339 manifest_dir: impl AsRef<Path>,
340 opts: &crate::Emit,
341 explicit_touch: Option<&str>,
342 typography: &makeover::Typography,
343) {
344 let root = manifest_dir.as_ref();
345 let css = root.join("frontend").join("css");
346 themes(root.join("themes"));
347 geometry_css(css.join("geometry.css"), explicit_touch);
348 // Beside geometry rather than after layout: both are value files the
349 // component sheet reads, and a consumer's `<link>` order follows this one.
350 timing_css(css.join("timing.css"));
351 layout_css(css.join("layout.css"), opts);
352 typography_css_from(css.join("typography.css"), typography);
353}
354
355#[cfg(test)]
356mod tests {
357 use super::*;
358
359 /// A scratch directory keyed by process id, so a parallel test run does
360 /// not collide. No timestamp: the pid is enough and is deterministic
361 /// within a run.
362 fn scratch(name: &str) -> std::path::PathBuf {
363 let dir = std::env::temp_dir().join(format!(
364 "makeover-webview-build-{}-{name}",
365 std::process::id()
366 ));
367 let _ = std::fs::remove_dir_all(&dir);
368 std::fs::create_dir_all(&dir).expect("create scratch");
369 dir
370 }
371
372 #[test]
373 fn themes_are_written_one_file_per_id() {
374 let dir = scratch("themes");
375 themes(&dir);
376 // `.toml` only: the run also writes the manifest, which is not a theme.
377 let count = std::fs::read_dir(&dir)
378 .unwrap()
379 .flatten()
380 .filter(|entry| entry.path().extension().is_some_and(|ext| ext == "toml"))
381 .count();
382 assert_eq!(count, makeover::embedded_themes().count());
383 assert!(count > 0, "makeover ships no themes?");
384 }
385
386 #[test]
387 fn a_theme_removed_upstream_does_not_linger() {
388 // The detail that makes this worth sharing rather than retyping. A
389 // previous run generated `gone-upstream.toml` and recorded it in the
390 // manifest; this run no longer ships it, so the recorded entry is what
391 // marks the file stale.
392 let dir = scratch("stale");
393 std::fs::write(dir.join("gone-upstream.toml"), "# stale").unwrap();
394 std::fs::write(dir.join(THEMES_MANIFEST), "gone-upstream\n").unwrap();
395 themes(&dir);
396 assert!(!dir.join("gone-upstream.toml").exists());
397 }
398
399 #[test]
400 fn a_foreign_toml_that_was_not_generated_survives() {
401 // The manifest is the boundary: a `.toml` the consumer placed here was
402 // never generated by `themes`, so a rebuild must not clear it the way
403 // the old by-stem sweep did.
404 let dir = scratch("foreign");
405 std::fs::write(dir.join("user-custom.toml"), "# mine").unwrap();
406 themes(&dir);
407 assert!(dir.join("user-custom.toml").exists());
408 }
409
410 #[test]
411 fn a_second_run_touches_nothing() {
412 // The property the whole write-if-changed pass exists for: a build
413 // script that rewrites its own outputs invalidates itself, and cargo
414 // then reruns it on every build whatever changed. Asserted on mtime
415 // rather than on content, because content was always correct; it was
416 // the mtime that was the bug.
417 let dir = scratch("idempotent");
418 themes(&dir);
419 let before: Vec<_> = std::fs::read_dir(&dir)
420 .unwrap()
421 .flatten()
422 .map(|e| (e.path(), e.metadata().unwrap().modified().unwrap()))
423 .collect();
424 assert!(!before.is_empty(), "themes() wrote nothing to compare");
425
426 themes(&dir);
427 for (path, was) in before {
428 let now = std::fs::metadata(&path).unwrap().modified().unwrap();
429 assert_eq!(
430 was,
431 now,
432 "{} was rewritten by a second run with nothing changed",
433 path.display()
434 );
435 }
436 }
437
438 #[test]
439 fn a_generated_output_is_named_with_rerun_if_changed() {
440 // A deleted output, or a gitignored `themes/` emptied by `git clean
441 // -X`, has to be regenerated on the next build. That only happens if
442 // every write names its path with `rerun-if-changed`, which cargo
443 // treats as an input: a path newer than the script's last output, or
444 // gone, reruns it. Observed through a child process because the test
445 // harness owns this process's stdout and swallows a `println!`.
446 let exe = std::env::current_exe().expect("test binary path");
447 let child = std::process::Command::new(exe)
448 .args(["--nocapture", "emit_rerun_directive_child"])
449 .env("MAKEOVER_EMIT_RERUN", "1")
450 .output()
451 .expect("spawn child");
452 assert!(child.status.success(), "child failed: {child:?}");
453 let stdout = String::from_utf8_lossy(&child.stdout);
454 assert!(
455 stdout.contains("cargo::rerun-if-changed="),
456 "write_if_changed named no output with rerun-if-changed:\n{stdout}"
457 );
458 }
459
460 /// The child for [`a_generated_output_is_named_with_rerun_if_changed`]:
461 /// a silent no-op unless the parent set the trigger, so the ordinary suite
462 /// run does not write files or print directives.
463 #[test]
464 fn emit_rerun_directive_child() {
465 if std::env::var_os("MAKEOVER_EMIT_RERUN").is_none() {
466 return;
467 }
468 layout_css(
469 scratch("rerun-directive").join("layout.css"),
470 &crate::Emit::default(),
471 );
472 }
473
474 #[test]
475 fn a_non_theme_file_is_left_alone() {
476 // Only .toml is cleared, so a README or a .gitignore in the bundle
477 // directory survives a rebuild.
478 let dir = scratch("keep");
479 std::fs::write(dir.join("README.md"), "not a theme").unwrap();
480 themes(&dir);
481 assert!(dir.join("README.md").exists());
482 }
483
484 #[test]
485 fn the_stylesheet_lands_and_names_no_colour() {
486 let dir = scratch("css");
487 let path = dir.join("layout.css");
488 layout_css(&path, &crate::Emit::default());
489 let css = std::fs::read_to_string(&path).unwrap();
490 assert!(css.contains("--bevel-raised"));
491 assert!(
492 !css.contains('#'),
493 "a colour literal reached a build output"
494 );
495 }
496
497 #[test]
498 fn the_typography_file_declares_the_faces_before_the_tokens_that_name_them() {
499 // The vocabulary itself is tested in makeover. What is this crate's
500 // job is that both halves reach one file, in an order that works: a
501 // `@font-face` may follow its use in the cascade, but reading the file
502 // is how anyone finds out a face is fetched at all.
503 let dir = scratch("typography");
504 let path = dir.join("typography.css");
505 typography_css(&path, "/static/fonts");
506 let css = std::fs::read_to_string(&path).unwrap();
507
508 assert!(css.starts_with("/* Generated by makeover-webview"));
509 assert!(
510 css.find("@font-face").unwrap() < css.find(":root").unwrap(),
511 "the tokens come first, so the file reads as a stack with no ground"
512 );
513 assert!(css.contains("url(\"/static/fonts/QuasiMono.woff2\")"));
514 assert!(css.contains("--font-sans: \"Quasi Body\", sans-serif;"));
515
516 // Not a cascade layer. `@font-face` takes no part in the cascade and a
517 // consumer may need these rules ahead of a layer order it declares
518 // elsewhere, so wrapping this file in one would be a silent trap.
519 assert!(!css.contains("@layer"));
520 }
521
522 #[test]
523 fn an_overridden_slot_reaches_the_same_file_as_the_house_two() {
524 // Layer 0's whole point: the brand face stops being a hand-maintained
525 // `@font-face` in the app's own stylesheet and becomes a line in the
526 // generated one, beside the slots it sits next to.
527 let dir = scratch("typography-override");
528 let path = dir.join("typography.css");
529 typography_css_from(
530 &path,
531 &Typography::house("/static/fonts").with_override(
532 FontOverride::new(FontSlot::Display, "\"Young Serif\", serif")
533 .with_face(FontFace::new("Young Serif", ["ysrf.woff2", "ysrf.ttf"])),
534 ),
535 );
536 let css = std::fs::read_to_string(&path).unwrap();
537
538 // `@font-face {`, not `@font-face`: the header comment names the
539 // at-rule too, and counting that would make this pass for the wrong
540 // reason the day the comment is reworded.
541 assert_eq!(css.matches("@font-face {").count(), 3);
542 assert!(css.contains("--font-display: \"Young Serif\", serif;"));
543 assert!(css.contains("--font-mono: \"Quasi Mono\", monospace;"));
544 assert!(css.contains("url(\"/static/fonts/ysrf.ttf\") format(\"truetype\")"));
545 assert!(!css.contains("@layer"));
546 }
547
548 #[test]
549 fn the_default_tauri_layout_is_the_house_layer_and_nothing_else() {
550 // `tauri_frontend` delegating through `tauri_frontend_with` must not
551 // change a byte for the three consumers already calling it.
552 let dir = scratch("tauri-default");
553 let plain = dir.join("plain.css");
554 let house = dir.join("house.css");
555 typography_css(&plain, "../fonts");
556 typography_css_from(&house, &Typography::house("../fonts"));
557 assert_eq!(
558 std::fs::read_to_string(&plain).unwrap(),
559 std::fs::read_to_string(&house).unwrap()
560 );
561 }
562
563 #[test]
564 fn the_geometry_file_carries_the_crates_policy_and_a_banner() {
565 // The policy itself is tested in makeover-geometry. What is this
566 // crate's job is that the banner is there and the policy reached the
567 // file at all.
568 let dir = scratch("geometry");
569 let path = dir.join("geometry.css");
570 geometry_css(&path, Some(".ui-mode-mobile"));
571 let css = std::fs::read_to_string(&path).unwrap();
572 assert!(css.starts_with("/* Generated by makeover-webview"));
573 assert!(css.contains(&format!(
574 "@media {}",
575 makeover_geometry::Density::Touch.media_condition()
576 )));
577 assert!(css.contains(".ui-mode-mobile"));
578 // The width axis rides along, and only the shells are in it: a gap
579 // between two controls in a width query is the bug size_class_css
580 // exists to keep out.
581 assert!(css.contains("--gap-pane"), "no compact shell override");
582 let compact = css
583 .split(&format!(
584 "@media {}",
585 makeover_geometry::SizeClass::Compact.media_condition()
586 ))
587 .nth(1)
588 .expect("compact block");
589 assert!(
590 !compact.contains("--gap-peer"),
591 "a control gap crept into a width query"
592 );
593 // Row packing rides along, unlayered: the reader's compact override
594 // must beat the `--row-block` default the density block wrote.
595 assert!(
596 css.contains(&format!(
597 ":root[{}=\"{}\"]",
598 makeover_geometry::COMPACTNESS_ATTRIBUTE,
599 makeover_geometry::Compactness::Compact.attribute_value()
600 )),
601 "no compact row-packing override"
602 );
603 }
604
605 #[test]
606 fn the_timing_file_carries_the_values_and_the_block_that_overrides_them() {
607 // The rungs themselves are tested in makeover-timing. What is this
608 // crate's to get wrong is dropping half the file: the values are
609 // useless noise without the media block, and the media block on its
610 // own overrides nothing.
611 let dir = scratch("timing");
612 let path = dir.join("timing.css");
613 timing_css(&path);
614 let css = std::fs::read_to_string(&path).unwrap();
615 assert!(css.starts_with("/* Generated by makeover-webview"));
616 // One token per axis, so a crate that grows a fourth axis and is not
617 // emitted here fails somewhere other than on screen.
618 assert!(css.contains("--timing-dismiss"), "no intent tokens");
619 assert!(css.contains("--motion-fade"), "no motion token");
620 assert!(css.contains("--cadence-activity"), "no cadence token");
621 assert!(
622 css.contains("@media (prefers-reduced-motion: reduce)"),
623 "the values shipped without the block that turns them off"
624 );
625 // The block comes after the values it overrides. Same specificity,
626 // so the order is the whole of the win.
627 assert!(
628 css.find(":root").unwrap() < css.find("prefers-reduced-motion").unwrap(),
629 "the motion-off block cannot override values declared after it"
630 );
631 // Inside the family's layer, like every other generated sheet:
632 // unlayered declarations outrank every named layer, so a generated
633 // file outside it beats the app's own overrides.
634 assert!(css.contains(makeover_geometry::CSS_LAYER));
635 }
636
637 #[test]
638 fn the_tauri_layout_puts_all_four_where_the_apps_look() {
639 let root = scratch("tauri");
640 std::fs::create_dir_all(root.join("frontend").join("css")).unwrap();
641 tauri_frontend(&root, &crate::Emit::default(), None);
642 let css = root.join("frontend").join("css");
643 for file in ["geometry.css", "timing.css", "layout.css", "typography.css"] {
644 assert!(css.join(file).exists(), "{file} was not written");
645 }
646 assert!(root.join("themes").is_dir());
647 }
648}