makeover-webview 0.130.0

The webview renderer for makeover-layout. Emits CSS, and is the one renderer that needs no palette: var() is the late binding, so resolution stays with the browser. With the build feature, writes a consumer's generated frontend files and checks the hand-written ones against them.
Documentation
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
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
211
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
//! Build-script support: the generated files every webview consumer
//! materialises from its `build.rs`, and the checks that keep its hand-written
//! frontend agreeing with them.
//!
//! Behind the `build` feature. A consumer takes this crate twice: as a
//! dependency for the markup and as a build-dependency with `features =
//! ["build"]` for these files. `links` holds both to one version.
//!
//! # Density
//!
//! [`geometry_css`] keys the touch preset on capability: touch hangs off "not
//! a fine, hovering pointer" and never off a user-agent string or a
//! breakpoint. An app with a manual override passes the selector it sets to
//! `explicit_touch`.
//!
//! # Where the files land
//!
//! Every emitter writes into the consumer's own crate directory, at the path
//! it is given. The consumer gitignores every path written here.
//!
//! # What is checked rather than written
//!
//! [`drift`] holds the checks over the consumer's hand-written stylesheet and
//! scripts. They assert and panic; none of them rewrites a file.

pub mod drift;

use std::path::Path;

pub use drift::{Allow, Breakpoints, Vocabulary, check_touch_density, check_vocabulary_use};

/// The filenames [`typography_css`]'s `@font-face` rules fetch. A consumer's
/// build script writes its font files under these names.
pub use makeover::{WEBFONT_MONO_FILE, WEBFONT_SANS_FILE};

/// Layer 0 of the font model, re-exported for a build script composing an
/// override.
pub use makeover::{FontFace, FontOverride, FontSlot, Typography};

/// Write only when the bytes differ, and name `path` with
/// `rerun-if-changed`. A run that changes nothing moves no mtime.
fn write_if_changed(path: &Path, contents: &str, what: &str) {
    // Cargo reruns a build script when a path it named with `rerun-if-changed`
    // is newer than the script's last output, or has been deleted. Naming the
    // output is what brings a generated file back after a hand deletion or a
    // `git clean -X` over a gitignored `themes/`; without it the file stays
    // gone until an unrelated edit reruns this script. Safe to name because
    // the write below happens only on a byte difference, so a run with nothing
    // changed moves no mtime and cannot invalidate itself through this.
    rerun(path);
    if std::fs::read_to_string(path).is_ok_and(|existing| existing == contents) {
        return;
    }
    std::fs::write(path, contents).unwrap_or_else(|error| panic!("write {what}: {error}"));
}

/// Name `path` for cargo to rerun the build script when it changes.
fn rerun(path: &Path) {
    println!("cargo::rerun-if-changed={}", path.display());
}

/// The name of the file [`themes`] writes to record which themes it generated.
///
/// Read on the next run to tell a theme this run no longer ships from a
/// `.toml` the consumer wrote into the same directory, which is left alone.
/// Not a `.toml`, so it never reads as a theme itself.
const THEMES_MANIFEST: &str = ".makeover-themes";

/// Write the themes `makeover` ships into `dir`, as `<id>.toml`.
///
/// Removes only the `.toml` files a previous run of this function generated
/// and upstream no longer ships, so a theme removed or renamed upstream does
/// not linger in the bundle from a previous build. A foreign `.toml` the
/// consumer placed in the same directory is not recorded and is left alone.
///
/// # Panics
///
/// If the directory cannot be created, read, or written, or a stale theme
/// cannot be removed.
pub fn themes(dir: impl AsRef<Path>) {
    let dir = dir.as_ref();
    std::fs::create_dir_all(dir).expect("create themes dir");

    let shipped: std::collections::BTreeSet<String> = makeover::embedded_themes()
        .map(|(id, _)| id.to_string())
        .collect();

    // Only what upstream no longer ships, and only what a previous run of this
    // function wrote: the manifest is the boundary between our generated
    // output and a consumer's own file. Clearing the directory first and
    // writing every theme back was the same thing by result and not by mtime:
    // it left `write_if_changed` nothing to compare against, so every build
    // rewrote every theme and the script invalidated itself through them.
    let manifest = dir.join(THEMES_MANIFEST);
    if let Ok(previous) = std::fs::read_to_string(&manifest) {
        for stem in previous.lines().filter(|line| !line.is_empty()) {
            // Already gone is the state this sweep is after.
            if !shipped.contains(stem)
                && let Err(e) = std::fs::remove_file(dir.join(format!("{stem}.toml")))
                && e.kind() != std::io::ErrorKind::NotFound
            {
                panic!("remove stale theme {stem}: {e}");
            }
        }
    }

    for (id, source) in makeover::embedded_themes() {
        write_if_changed(&dir.join(format!("{id}.toml")), source, "theme");
    }

    // Written last, so it names only what this run actually produced. The
    // `write_if_changed` keeps it as stable as the themes it lists, which is
    // the same idempotency the theme files themselves get.
    let body = shipped.iter().cloned().collect::<Vec<_>>().join("\n");
    write_if_changed(&manifest, &body, "themes manifest");
}

/// Write `makeover-webview`'s component stylesheet, [`crate::stylesheet`]
/// for `opts`, to `path`.
///
/// # Panics
///
/// If the file cannot be written.
pub fn layout_css(path: impl AsRef<Path>, opts: &crate::Emit) {
    write_if_changed(path.as_ref(), &crate::stylesheet(opts), "layout css");
}

/// Write `makeover-geometry`'s spacing layer, with its canonical density
/// selection, to `path`.
///
/// The policy is `makeover-geometry`'s: touch hangs off the negation of a
/// fine, hovering pointer, and `explicit_touch` names a selector an app sets
/// when the user has chosen. See [`makeover_geometry::density_css`]. This adds
/// the generated-file banner and the write.
///
/// The file is, in order: [`makeover_geometry::density_css`],
/// [`makeover_geometry::size_class_css`], which tightens the two shells on a
/// compact window whichever density selected them, and
/// [`makeover_geometry::compactness_css`], unlayered, so its row-packing
/// override beats the `--row-block` default the density block wrote.
///
/// # Panics
///
/// If the file cannot be written.
pub fn geometry_css(path: impl AsRef<Path>, explicit_touch: Option<&str>) {
    let mut css = String::from(
        "/* Generated by makeover-webview 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());
    css.push('\n');
    css.push_str(&makeover_geometry::compactness_css());
    write_if_changed(path.as_ref(), &css, "geometry css");
}

/// Write `makeover-timing`'s time axis, and the motion-off block that rides
/// with it, to `path`.
///
/// The file declares `--timing-*`, `--motion-*` and `--cadence-*`. This adds
/// the banner and the write; `makeover_timing::timing_css` is the whole file
/// and wraps itself in [`makeover_geometry::CSS_LAYER`].
///
/// # The `prefers-reduced-motion` block
///
/// `makeover_timing::timing_css` emits the `:root` values and then a media
/// block zeroing every motion and cadence (`--motion-fade`, `--motion-quick`,
/// `--cadence-activity`). Both land here, in that order.
///
/// # Panics
///
/// If the file cannot be written.
pub fn timing_css(path: impl AsRef<Path>) {
    let mut css = String::from(
        "/* Generated by makeover-webview from makeover-timing. Do not edit.\n   \
         A duration is named by what it is waiting for; the number follows.\n   \
         Three axes: how long a state lasts, how long a change takes, and how\n   \
         often a repeating mark repeats. The reduced-motion block below zeroes\n   \
         the last two and leaves the waits alone. A reader asking for less\n   \
         motion has not asked for a notice to leave early. */\n",
    );
    css.push_str(&makeover_timing::timing_css());
    write_if_changed(path.as_ref(), &css, "timing css");
}

/// Write the house typography layer to `path`: the two `@font-face` rules and
/// the two tokens they back.
///
/// `font_url` is the directory the fonts are fetched from, without a trailing
/// slash, as a `url()` resolves it: against the generated stylesheet, not the
/// page. `/static/fonts` on the MNW server; `../fonts` for a Tauri frontend
/// writing this file to `frontend/css/typography.css` with its fonts in
/// `frontend/fonts`, which is what [`tauri_frontend`] passes.
///
/// The file declares no `@layer`.
///
/// # The consumer still has to put the faces there
///
/// This writes the CSS that fetches `QuasiMono.woff2` and `QuasiBody.woff2`;
/// it does not write the fonts. A consumer cuts them with `quasi-type` (a git
/// dependency, `quasi_type::cut`) in its own `build.rs`, writing each slot's
/// woff2 under [`makeover::WEBFONT_MONO_FILE`] and
/// [`makeover::WEBFONT_SANS_FILE`].
///
/// # Panics
///
/// If the file cannot be written.
pub fn typography_css(path: impl AsRef<Path>, font_url: &str) {
    typography_css_from(path, &makeover::Typography::house(font_url));
}

/// [`typography_css`], for a product that overrides a slot.
///
/// Layer 0 of the font model. A product with a brand face declares it here,
/// and the generated sheet carries both the `@font-face` and the token:
///
/// ```no_run
/// use makeover_webview::build::{FontFace, FontOverride, FontSlot, Typography};
///
/// makeover_webview::build::typography_css_from(
///     "static/typography.css",
///     &Typography::house("/static/fonts").with_override(
///         FontOverride::new(FontSlot::Display, "\"Young Serif\", serif")
///             .with_face(FontFace::new("Young Serif", ["ysrf.woff2", "ysrf.ttf"])),
///     ),
/// );
/// ```
///
/// The product still ships the face file itself; this writes the CSS that
/// fetches it.
///
/// # Panics
///
/// If the file cannot be written.
pub fn typography_css_from(path: impl AsRef<Path>, typography: &makeover::Typography) {
    let mut css = String::from(
        "/* Generated by makeover-webview 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());
    write_if_changed(path.as_ref(), &css, "typography css");
}

/// All the generated files at the Tauri layout: `themes/` beside the
/// manifest, and `frontend/css/{geometry,timing,layout,typography}.css` under
/// it.
///
/// Pass `env!("CARGO_MANIFEST_DIR")`. A consumer that wants different paths
/// calls [`themes`], [`geometry_css`], [`timing_css`], [`layout_css`] and
/// [`typography_css`] directly.
///
/// The font URL is `../fonts`: a `url()` resolves against the stylesheet, so
/// from `frontend/css/typography.css` that is `frontend/fonts`.
///
/// # Panics
///
/// If any file cannot be written.
pub fn tauri_frontend(
    manifest_dir: impl AsRef<Path>,
    opts: &crate::Emit,
    explicit_touch: Option<&str>,
) {
    tauri_frontend_with(
        manifest_dir,
        opts,
        explicit_touch,
        &makeover::Typography::house("../fonts"),
    );
}

/// [`tauri_frontend`], for a product that overrides a font slot.
///
/// The base URL is the caller's: `Typography::house("../fonts")` is what
/// [`tauri_frontend`] passes.
///
/// # Panics
///
/// If any file cannot be written.
pub fn tauri_frontend_with(
    manifest_dir: impl AsRef<Path>,
    opts: &crate::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);
    // Beside geometry rather than after layout: both are value files the
    // component sheet reads, and a consumer's `<link>` order follows this one.
    timing_css(css.join("timing.css"));
    layout_css(css.join("layout.css"), opts);
    typography_css_from(css.join("typography.css"), typography);
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::test_support::scratch;

    #[test]
    fn themes_are_written_one_file_per_id() {
        let dir = scratch("themes");
        themes(&dir);
        // `.toml` only: the run also writes the manifest, which is not a theme.
        let count = std::fs::read_dir(&dir)
            .unwrap()
            .flatten()
            .filter(|entry| entry.path().extension().is_some_and(|ext| ext == "toml"))
            .count();
        assert_eq!(count, makeover::embedded_themes().count());
        assert!(count > 0, "makeover ships no themes?");
    }

    #[test]
    fn a_theme_removed_upstream_does_not_linger() {
        // The detail that makes this worth sharing rather than retyping. A
        // previous run generated `gone-upstream.toml` and recorded it in the
        // manifest; this run no longer ships it, so the recorded entry is what
        // marks the file stale.
        let dir = scratch("stale");
        std::fs::write(dir.join("gone-upstream.toml"), "# stale").unwrap();
        std::fs::write(dir.join(THEMES_MANIFEST), "gone-upstream\n").unwrap();
        themes(&dir);
        assert!(!dir.join("gone-upstream.toml").exists());
    }

    #[test]
    fn repro_themes_stale_removal_panics_on_missing_file() {
        // The manifest names a theme upstream dropped whose file is already
        // gone: the file being absent is the end state the sweep wants.
        let dir = scratch("stale-gone");
        std::fs::write(dir.join(THEMES_MANIFEST), "gone-upstream\n").unwrap();
        themes(&dir);
        let manifest = std::fs::read_to_string(dir.join(THEMES_MANIFEST)).unwrap();
        assert!(!manifest.lines().any(|line| line == "gone-upstream"));
    }

    #[test]
    fn a_foreign_toml_that_was_not_generated_survives() {
        // The manifest is the boundary: a `.toml` the consumer placed here was
        // never generated by `themes`, so a rebuild must not clear it the way
        // the old by-stem sweep did.
        let dir = scratch("foreign");
        std::fs::write(dir.join("user-custom.toml"), "# mine").unwrap();
        themes(&dir);
        assert!(dir.join("user-custom.toml").exists());
    }

    #[test]
    fn a_second_run_touches_nothing() {
        // The property the whole write-if-changed pass exists for: a build
        // script that rewrites its own outputs invalidates itself, and cargo
        // then reruns it on every build whatever changed. Asserted on mtime
        // rather than on content, because content was always correct; it was
        // the mtime that was the bug.
        let dir = scratch("idempotent");
        themes(&dir);
        let before: Vec<_> = std::fs::read_dir(&dir)
            .unwrap()
            .flatten()
            .map(|e| (e.path(), e.metadata().unwrap().modified().unwrap()))
            .collect();
        assert!(!before.is_empty(), "themes() wrote nothing to compare");

        themes(&dir);
        for (path, was) in before {
            let now = std::fs::metadata(&path).unwrap().modified().unwrap();
            assert_eq!(
                was,
                now,
                "{} was rewritten by a second run with nothing changed",
                path.display()
            );
        }
    }

    #[test]
    fn a_generated_output_is_named_with_rerun_if_changed() {
        // A deleted output, or a gitignored `themes/` emptied by `git clean
        // -X`, has to be regenerated on the next build. That only happens if
        // every write names its path with `rerun-if-changed`, which cargo
        // treats as an input: a path newer than the script's last output, or
        // gone, reruns it. Observed through a child process because the test
        // harness owns this process's stdout and swallows a `println!`.
        let exe = std::env::current_exe().expect("test binary path");
        let child = std::process::Command::new(exe)
            .args(["--nocapture", "emit_rerun_directive_child"])
            .env("MAKEOVER_EMIT_RERUN", "1")
            .output()
            .expect("spawn child");
        assert!(child.status.success(), "child failed: {child:?}");
        let stdout = String::from_utf8_lossy(&child.stdout);
        assert!(
            stdout.contains("cargo::rerun-if-changed="),
            "write_if_changed named no output with rerun-if-changed:\n{stdout}"
        );
    }

    /// The child for [`a_generated_output_is_named_with_rerun_if_changed`]:
    /// a silent no-op unless the parent set the trigger, so the ordinary suite
    /// run does not write files or print directives.
    #[test]
    fn emit_rerun_directive_child() {
        if std::env::var_os("MAKEOVER_EMIT_RERUN").is_none() {
            return;
        }
        layout_css(
            scratch("rerun-directive").join("layout.css"),
            &crate::Emit::default(),
        );
    }

    #[test]
    fn a_non_theme_file_is_left_alone() {
        // Only .toml is cleared, so a README or a .gitignore in the bundle
        // directory survives a rebuild.
        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, &crate::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() {
        // The vocabulary itself is tested in makeover. What is this crate's
        // job is that both halves reach one file, in an order that works: a
        // `@font-face` may follow its use in the cascade, but reading the file
        // is how anyone finds out a face is fetched at all.
        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-webview"));
        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;"));

        // Not a cascade layer. `@font-face` takes no part in the cascade and a
        // consumer may need these rules ahead of a layer order it declares
        // elsewhere, so wrapping this file in one would be a silent trap.
        assert!(!css.contains("@layer"));
    }

    #[test]
    fn an_overridden_slot_reaches_the_same_file_as_the_house_two() {
        // Layer 0's whole point: the brand face stops being a hand-maintained
        // `@font-face` in the app's own stylesheet and becomes a line in the
        // generated one, beside the slots it sits next to.
        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();

        // `@font-face {`, not `@font-face`: the header comment names the
        // at-rule too, and counting that would make this pass for the wrong
        // reason the day the comment is reworded.
        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() {
        // `tauri_frontend` delegating through `tauri_frontend_with` must not
        // change a byte for the three consumers already calling it.
        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() {
        // The policy itself is tested in makeover-geometry. What is this
        // crate's job is that the banner is there and the policy reached the
        // file at all.
        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-webview"));
        assert!(css.contains(&format!(
            "@media {}",
            makeover_geometry::Density::Touch.media_condition()
        )));
        assert!(css.contains(".ui-mode-mobile"));
        // The width axis rides along, and only the shells are in it: a gap
        // between two controls in a width query is the bug size_class_css
        // exists to keep out.
        assert!(css.contains("--gap-pane"), "no compact shell override");
        let compact = css
            .split(&format!(
                "@media {}",
                makeover_geometry::SizeClass::Compact.media_condition()
            ))
            .nth(1)
            .expect("compact block");
        assert!(
            !compact.contains("--gap-peer"),
            "a control gap crept into a width query"
        );
        // Row packing rides along, unlayered: the reader's compact override
        // must beat the `--row-block` default the density block wrote.
        assert!(
            css.contains(&format!(
                ":root[{}=\"{}\"]",
                makeover_geometry::COMPACTNESS_ATTRIBUTE,
                makeover_geometry::Compactness::Compact.attribute_value()
            )),
            "no compact row-packing override"
        );
    }

    #[test]
    fn the_timing_file_carries_the_values_and_the_block_that_overrides_them() {
        // The rungs themselves are tested in makeover-timing. What is this
        // crate's to get wrong is dropping half the file: the values are
        // useless noise without the media block, and the media block on its
        // own overrides nothing.
        let dir = scratch("timing");
        let path = dir.join("timing.css");
        timing_css(&path);
        let css = std::fs::read_to_string(&path).unwrap();
        assert!(css.starts_with("/* Generated by makeover-webview"));
        // One token per axis, so a crate that grows a fourth axis and is not
        // emitted here fails somewhere other than on screen.
        assert!(css.contains("--timing-dismiss"), "no intent tokens");
        assert!(css.contains("--motion-fade"), "no motion token");
        assert!(css.contains("--cadence-activity"), "no cadence token");
        assert!(
            css.contains("@media (prefers-reduced-motion: reduce)"),
            "the values shipped without the block that turns them off"
        );
        // The block comes after the values it overrides. Same specificity,
        // so the order is the whole of the win.
        assert!(
            css.find(":root").unwrap() < css.find("prefers-reduced-motion").unwrap(),
            "the motion-off block cannot override values declared after it"
        );
        // Inside the family's layer, like every other generated sheet:
        // unlayered declarations outrank every named layer, so a generated
        // file outside it beats the app's own overrides.
        assert!(css.contains(makeover_geometry::CSS_LAYER));
    }

    #[test]
    fn the_tauri_layout_puts_all_four_where_the_apps_look() {
        let root = scratch("tauri");
        std::fs::create_dir_all(root.join("frontend").join("css")).unwrap();
        tauri_frontend(&root, &crate::Emit::default(), None);
        let css = root.join("frontend").join("css");
        for file in ["geometry.css", "timing.css", "layout.css", "typography.css"] {
            assert!(css.join(file).exists(), "{file} was not written");
        }
        assert!(root.join("themes").is_dir());
    }
}